@inweb/viewer-visualize 25.3.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +63 -0
  3. package/dist/viewer-visualize.js +16982 -0
  4. package/dist/viewer-visualize.js.map +1 -0
  5. package/dist/viewer-visualize.min.js +1 -0
  6. package/dist/viewer-visualize.module.js +5267 -0
  7. package/dist/viewer-visualize.module.js.map +1 -0
  8. package/lib/Viewer/Commands/ApplyModelTransform.d.ts +1 -0
  9. package/lib/Viewer/Commands/ClearMarkup.d.ts +1 -0
  10. package/lib/Viewer/Commands/ClearSlices.d.ts +1 -0
  11. package/lib/Viewer/Commands/CreatePreview.d.ts +1 -0
  12. package/lib/Viewer/Commands/Explode.d.ts +1 -0
  13. package/lib/Viewer/Commands/GetDefaultViewPositions.d.ts +1 -0
  14. package/lib/Viewer/Commands/GetModels.d.ts +1 -0
  15. package/lib/Viewer/Commands/GetSelected.d.ts +1 -0
  16. package/lib/Viewer/Commands/HideSelected.d.ts +1 -0
  17. package/lib/Viewer/Commands/IsolateSelected.d.ts +1 -0
  18. package/lib/Viewer/Commands/RegenerateAll.d.ts +1 -0
  19. package/lib/Viewer/Commands/ResetView.d.ts +1 -0
  20. package/lib/Viewer/Commands/SelectModel.d.ts +1 -0
  21. package/lib/Viewer/Commands/SetActiveDragger.d.ts +1 -0
  22. package/lib/Viewer/Commands/SetDefaultViewPosition.d.ts +1 -0
  23. package/lib/Viewer/Commands/SetMarkupColor.d.ts +1 -0
  24. package/lib/Viewer/Commands/SetSelected.d.ts +1 -0
  25. package/lib/Viewer/Commands/ShowAll.d.ts +1 -0
  26. package/lib/Viewer/Commands/Unselect.d.ts +1 -0
  27. package/lib/Viewer/Commands/ZoomToExtents.d.ts +1 -0
  28. package/lib/Viewer/Commands/ZoomToObjects.d.ts +1 -0
  29. package/lib/Viewer/Commands/ZoomToSelected.d.ts +1 -0
  30. package/lib/Viewer/Commands/index.d.ts +22 -0
  31. package/lib/Viewer/Draggers/Actions/OrbitAction.d.ts +21 -0
  32. package/lib/Viewer/Draggers/Actions/PanAction.d.ts +17 -0
  33. package/lib/Viewer/Draggers/Actions/ZoomAction.d.ts +7 -0
  34. package/lib/Viewer/Draggers/Common/Geometry.d.ts +114 -0
  35. package/lib/Viewer/Draggers/Common/GestureManager.d.ts +40 -0
  36. package/lib/Viewer/Draggers/Common/OdBaseDragger.d.ts +53 -0
  37. package/lib/Viewer/Draggers/Common/OdaGeAction.d.ts +29 -0
  38. package/lib/Viewer/Draggers/MeasureLineDragger/MeasureLineItem.d.ts +30 -0
  39. package/lib/Viewer/Draggers/MeasureLineDragger/MeasureUtils.d.ts +19 -0
  40. package/lib/Viewer/Draggers/MeasureLineDragger/index.d.ts +23 -0
  41. package/lib/Viewer/Draggers/OdBaseCuttingPlaneDragger.d.ts +26 -0
  42. package/lib/Viewer/Draggers/OdCuttingPlaneXAxisDragger.d.ts +7 -0
  43. package/lib/Viewer/Draggers/OdCuttingPlaneYAxisDragger.d.ts +7 -0
  44. package/lib/Viewer/Draggers/OdCuttingPlaneZAxisDragger.d.ts +7 -0
  45. package/lib/Viewer/Draggers/OdOrbitDragger.d.ts +14 -0
  46. package/lib/Viewer/Draggers/OdPanDragger.d.ts +11 -0
  47. package/lib/Viewer/Draggers/OdZoomDragger.d.ts +11 -0
  48. package/lib/Viewer/Draggers/OdZoomWheelDragger.d.ts +10 -0
  49. package/lib/Viewer/Draggers/OdZoomWindowDragger/OdSelectionFrame.d.ts +18 -0
  50. package/lib/Viewer/Draggers/OdZoomWindowDragger/index.d.ts +13 -0
  51. package/lib/Viewer/Draggers/OdaLineDragger.d.ts +14 -0
  52. package/lib/Viewer/Draggers/OdaTextDragger.d.ts +15 -0
  53. package/lib/Viewer/Draggers/OdaWalkDragger.d.ts +29 -0
  54. package/lib/Viewer/Draggers/OrbitAroundBuildingDragger.d.ts +18 -0
  55. package/lib/Viewer/Loaders/BaseLoader.d.ts +10 -0
  56. package/lib/Viewer/Loaders/LoaderFactory.d.ts +10 -0
  57. package/lib/Viewer/Loaders/TCSLoader.d.ts +4 -0
  58. package/lib/Viewer/Loaders/UpdaterController.d.ts +14 -0
  59. package/lib/Viewer/Loaders/VsfXLoader.d.ts +4 -0
  60. package/lib/Viewer/Loaders/VsfXPartialLoader.d.ts +4 -0
  61. package/lib/Viewer/Loaders/VsfXStreamingLoader.d.ts +4 -0
  62. package/lib/Viewer/Markup/Api/IMarkupArrow.d.ts +21 -0
  63. package/lib/Viewer/Markup/Api/IMarkupCloud.d.ts +14 -0
  64. package/lib/Viewer/Markup/Api/IMarkupColorable.d.ts +4 -0
  65. package/lib/Viewer/Markup/Api/IMarkupEllipse.d.ts +14 -0
  66. package/lib/Viewer/Markup/Api/IMarkupImage.d.ts +14 -0
  67. package/lib/Viewer/Markup/Api/IMarkupLine.d.ts +12 -0
  68. package/lib/Viewer/Markup/Api/IMarkupObject.d.ts +11 -0
  69. package/lib/Viewer/Markup/Api/IMarkupRectangle.d.ts +14 -0
  70. package/lib/Viewer/Markup/Api/IMarkupText.d.ts +12 -0
  71. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaArrow.d.ts +46 -0
  72. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaCloud.d.ts +35 -0
  73. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaEllipse.d.ts +40 -0
  74. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaImage.d.ts +36 -0
  75. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaLine.d.ts +36 -0
  76. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaRectangle.d.ts +38 -0
  77. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaText.d.ts +37 -0
  78. package/lib/Viewer/Markup/IMarkup.d.ts +39 -0
  79. package/lib/Viewer/Markup/Impl/Konva/KonvaMarkup.d.ts +70 -0
  80. package/lib/Viewer/Markup/Impl/Konva/MarkupColor.d.ts +18 -0
  81. package/lib/Viewer/Markup/Impl/Visualize/VisualizeMarkup.d.ts +33 -0
  82. package/lib/Viewer/Markup/MarkupFactory.d.ts +6 -0
  83. package/lib/Viewer/Viewer.d.ts +346 -0
  84. package/lib/Viewer/utils.d.ts +3 -0
  85. package/lib/index.d.ts +3 -0
  86. package/package.json +44 -0
  87. package/src/Viewer/Commands/ApplyModelTransform.ts +69 -0
  88. package/src/Viewer/Commands/ClearMarkup.ts +28 -0
  89. package/src/Viewer/Commands/ClearSlices.ts +27 -0
  90. package/src/Viewer/Commands/CreatePreview.ts +33 -0
  91. package/src/Viewer/Commands/Explode.ts +38 -0
  92. package/src/Viewer/Commands/GetDefaultViewPositions.ts +36 -0
  93. package/src/Viewer/Commands/GetModels.ts +43 -0
  94. package/src/Viewer/Commands/GetSelected.ts +58 -0
  95. package/src/Viewer/Commands/HideSelected.ts +37 -0
  96. package/src/Viewer/Commands/IsolateSelected.ts +37 -0
  97. package/src/Viewer/Commands/RegenerateAll.ts +37 -0
  98. package/src/Viewer/Commands/ResetView.ts +43 -0
  99. package/src/Viewer/Commands/SelectModel.ts +52 -0
  100. package/src/Viewer/Commands/SetActiveDragger.ts +29 -0
  101. package/src/Viewer/Commands/SetDefaultViewPosition.ts +50 -0
  102. package/src/Viewer/Commands/SetMarkupColor.ts +29 -0
  103. package/src/Viewer/Commands/SetSelected.ts +47 -0
  104. package/src/Viewer/Commands/ShowAll.ts +37 -0
  105. package/src/Viewer/Commands/Unselect.ts +37 -0
  106. package/src/Viewer/Commands/ZoomToExtents.ts +43 -0
  107. package/src/Viewer/Commands/ZoomToObjects.ts +47 -0
  108. package/src/Viewer/Commands/ZoomToSelected.ts +39 -0
  109. package/src/Viewer/Commands/index.ts +45 -0
  110. package/src/Viewer/Draggers/Actions/OrbitAction.ts +250 -0
  111. package/src/Viewer/Draggers/Actions/PanAction.ts +102 -0
  112. package/src/Viewer/Draggers/Actions/ZoomAction.ts +45 -0
  113. package/src/Viewer/Draggers/Common/Geometry.ts +152 -0
  114. package/src/Viewer/Draggers/Common/GestureManager.ts +263 -0
  115. package/src/Viewer/Draggers/Common/OdBaseDragger.ts +270 -0
  116. package/src/Viewer/Draggers/Common/OdaGeAction.ts +146 -0
  117. package/src/Viewer/Draggers/MeasureLineDragger/MeasureLineItem.ts +248 -0
  118. package/src/Viewer/Draggers/MeasureLineDragger/MeasureUtils.ts +182 -0
  119. package/src/Viewer/Draggers/MeasureLineDragger/index.ts +166 -0
  120. package/src/Viewer/Draggers/OdBaseCuttingPlaneDragger.ts +182 -0
  121. package/src/Viewer/Draggers/OdCuttingPlaneXAxisDragger.ts +53 -0
  122. package/src/Viewer/Draggers/OdCuttingPlaneYAxisDragger.ts +53 -0
  123. package/src/Viewer/Draggers/OdCuttingPlaneZAxisDragger.ts +53 -0
  124. package/src/Viewer/Draggers/OdOrbitDragger.ts +70 -0
  125. package/src/Viewer/Draggers/OdPanDragger.ts +62 -0
  126. package/src/Viewer/Draggers/OdZoomDragger.ts +59 -0
  127. package/src/Viewer/Draggers/OdZoomWheelDragger.ts +103 -0
  128. package/src/Viewer/Draggers/OdZoomWindowDragger/OdSelectionFrame.ts +123 -0
  129. package/src/Viewer/Draggers/OdZoomWindowDragger/index.ts +75 -0
  130. package/src/Viewer/Draggers/OdaLineDragger.ts +80 -0
  131. package/src/Viewer/Draggers/OdaTextDragger.ts +118 -0
  132. package/src/Viewer/Draggers/OdaWalkDragger.ts +278 -0
  133. package/src/Viewer/Draggers/OrbitAroundBuildingDragger.ts +184 -0
  134. package/src/Viewer/Loaders/BaseLoader.ts +40 -0
  135. package/src/Viewer/Loaders/LoaderFactory.ts +48 -0
  136. package/src/Viewer/Loaders/TCSLoader.ts +82 -0
  137. package/src/Viewer/Loaders/UpdaterController.ts +36 -0
  138. package/src/Viewer/Loaders/VsfXLoader.ts +65 -0
  139. package/src/Viewer/Loaders/VsfXPartialLoader.ts +208 -0
  140. package/src/Viewer/Loaders/VsfXStreamingLoader.ts +87 -0
  141. package/src/Viewer/Markup/Api/IMarkupArrow.ts +12 -0
  142. package/src/Viewer/Markup/Api/IMarkupCloud.ts +15 -0
  143. package/src/Viewer/Markup/Api/IMarkupColorable.ts +4 -0
  144. package/src/Viewer/Markup/Api/IMarkupEllipse.ts +15 -0
  145. package/src/Viewer/Markup/Api/IMarkupImage.ts +15 -0
  146. package/src/Viewer/Markup/Api/IMarkupLine.ts +13 -0
  147. package/src/Viewer/Markup/Api/IMarkupObject.ts +15 -0
  148. package/src/Viewer/Markup/Api/IMarkupRectangle.ts +15 -0
  149. package/src/Viewer/Markup/Api/IMarkupText.ts +12 -0
  150. package/src/Viewer/Markup/Api/Impl/Konva/KonvaArrow.ts +117 -0
  151. package/src/Viewer/Markup/Api/Impl/Konva/KonvaCloud.ts +208 -0
  152. package/src/Viewer/Markup/Api/Impl/Konva/KonvaEllipse.ts +118 -0
  153. package/src/Viewer/Markup/Api/Impl/Konva/KonvaImage.ts +123 -0
  154. package/src/Viewer/Markup/Api/Impl/Konva/KonvaLine.ts +131 -0
  155. package/src/Viewer/Markup/Api/Impl/Konva/KonvaRectangle.ts +119 -0
  156. package/src/Viewer/Markup/Api/Impl/Konva/KonvaText.ts +110 -0
  157. package/src/Viewer/Markup/IMarkup.ts +42 -0
  158. package/src/Viewer/Markup/Impl/Konva/KonvaMarkup.ts +1144 -0
  159. package/src/Viewer/Markup/Impl/Konva/MarkupColor.ts +39 -0
  160. package/src/Viewer/Markup/Impl/Visualize/VisualizeMarkup.ts +229 -0
  161. package/src/Viewer/Markup/MarkupFactory.ts +32 -0
  162. package/src/Viewer/Viewer.ts +1183 -0
  163. package/src/Viewer/utils.ts +74 -0
  164. package/src/index.ts +26 -0
@@ -0,0 +1,248 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2002-2021, Open Design Alliance (the "Alliance").
3
+ // All rights reserved.
4
+ //
5
+ // This software and its documentation and related materials are owned by
6
+ // the Alliance. The software may only be incorporated into application
7
+ // programs owned by members of the Alliance, subject to a signed
8
+ // Membership Agreement and Supplemental Software License Agreement with the
9
+ // Alliance. The structure and organization of this software are the valuable
10
+ // trade secrets of the Alliance and its suppliers. The software is also
11
+ // protected by copyright law and international treaty provisions. Application
12
+ // programs incorporating this software must include the following statement
13
+ // with their copyright notices:
14
+ //
15
+ // This application incorporates Open Design Alliance software pursuant to a
16
+ // license agreement with Open Design Alliance.
17
+ // Open Design Alliance Copyright (C) 2002-2021 by Open Design Alliance.
18
+ // All rights reserved.
19
+ //
20
+ // By use of this software, its documentation or related materials, you
21
+ // acknowledge and accept the above terms.
22
+ ///////////////////////////////////////////////////////////////////////////////
23
+ import * as utils from "./MeasureUtils";
24
+
25
+ export class MeasureLineItem {
26
+ protected htmlElemStartPoint: HTMLElement;
27
+ protected htmlElemEndPoint: HTMLElement;
28
+ protected htmlElemLine: HTMLElement;
29
+ protected htmlElemTitle: HTMLElement;
30
+ protected startPoint: number[];
31
+ protected endPoint: number[];
32
+ protected unit: string;
33
+ protected scale: number;
34
+ protected size: number;
35
+ protected style: CSSStyleDeclaration;
36
+ protected viewer: any;
37
+ protected moduleInstance: any;
38
+ protected targetElement: HTMLElement;
39
+ protected isFinishDraw: boolean;
40
+
41
+ public lineThickness: number;
42
+
43
+ constructor(targetElement: HTMLElement, viewer: any, moduleInstance: any) {
44
+ this.htmlElemStartPoint = null;
45
+ this.htmlElemEndPoint = null;
46
+ this.htmlElemLine = null;
47
+ this.htmlElemTitle = null;
48
+
49
+ this.startPoint = null;
50
+ this.endPoint = null;
51
+
52
+ this.unit = "";
53
+ this.scale = 1.0;
54
+ this.size = 10.0;
55
+ this.lineThickness = 2;
56
+
57
+ this.style = {
58
+ border: "2px solid #FFFFFF",
59
+ background: "#009bff",
60
+ color: "white",
61
+ boxShadow: "0 0 10px rgba(0,0,0,0.5)",
62
+ } as CSSStyleDeclaration;
63
+
64
+ this.htmlElemStartPoint = utils.createHtmlElementIfNeed(this.htmlElemStartPoint, targetElement, "ruler-start");
65
+ this.htmlElemEndPoint = utils.createHtmlElementIfNeed(this.htmlElemEndPoint, targetElement, "ruler-end");
66
+ this.htmlElemLine = utils.createHtmlElementIfNeed(this.htmlElemLine, targetElement, "ruler-line");
67
+ this.htmlElemTitle = utils.createHtmlElementIfNeed(this.htmlElemTitle, targetElement, "ruler-value");
68
+
69
+ this.viewer = viewer;
70
+ this.moduleInstance = moduleInstance;
71
+ this.targetElement = targetElement;
72
+ this.isFinishDraw = false;
73
+ }
74
+
75
+ drawMeasureLine(): void {
76
+ const pointSize = this.size;
77
+ const rect = this.moduleInstance.canvas.getBoundingClientRect();
78
+
79
+ // draw start point
80
+ if (this.startPoint) {
81
+ this.htmlElemStartPoint = utils.createHtmlElementIfNeed(
82
+ this.htmlElemStartPoint,
83
+ this.targetElement,
84
+ "ruler-start"
85
+ );
86
+
87
+ const pScreenStart = utils.worldToScreen(this.startPoint, this.moduleInstance, this.viewer);
88
+ if (utils.isInsideRect(pScreenStart, rect.width, rect.height)) {
89
+ this.htmlElemStartPoint.style.display = "block";
90
+ this.htmlElemStartPoint.style.cursor = "pointer";
91
+ this.htmlElemStartPoint.style.position = "absolute";
92
+ this.htmlElemStartPoint.style.top = `${pScreenStart.y - pointSize / 2}px`;
93
+ this.htmlElemStartPoint.style.left = `${pScreenStart.x - pointSize / 2}px`;
94
+ this.htmlElemStartPoint.style.borderRadius = `${pointSize}px`;
95
+ this.htmlElemStartPoint.style.border = this.style.border;
96
+ this.htmlElemStartPoint.style.background = this.style.background;
97
+ this.htmlElemStartPoint.style.zIndex = "2";
98
+ this.htmlElemStartPoint.style.width = `${pointSize}px`;
99
+ this.htmlElemStartPoint.style.height = `${pointSize}px`;
100
+ this.htmlElemStartPoint.style.boxShadow = this.style.boxShadow;
101
+ } else {
102
+ this.htmlElemStartPoint.style.display = "none";
103
+ }
104
+ }
105
+
106
+ // draw end point
107
+ if (this.endPoint && this.isFinishDraw) {
108
+ this.htmlElemEndPoint = utils.createHtmlElementIfNeed(this.htmlElemEndPoint, this.targetElement, "ruler-end");
109
+
110
+ const pScreenEnd = utils.worldToScreen(this.endPoint, this.moduleInstance, this.viewer);
111
+
112
+ if (utils.isInsideRect(pScreenEnd, rect.width, rect.height)) {
113
+ this.htmlElemEndPoint.style.display = "block";
114
+ this.htmlElemEndPoint.style.cursor = "pointer";
115
+ this.htmlElemEndPoint.style.position = "absolute";
116
+ this.htmlElemEndPoint.style.top = `${pScreenEnd.y - pointSize / 2}px`;
117
+ this.htmlElemEndPoint.style.left = `${pScreenEnd.x - pointSize / 2}px`;
118
+ this.htmlElemEndPoint.style.borderRadius = `${pointSize}px`;
119
+ this.htmlElemEndPoint.style.border = this.style.border;
120
+ this.htmlElemEndPoint.style.background = this.style.background;
121
+ this.htmlElemEndPoint.style.zIndex = "2";
122
+ this.htmlElemEndPoint.style.width = `${pointSize}px`;
123
+ this.htmlElemEndPoint.style.height = `${pointSize}px`;
124
+ this.htmlElemEndPoint.style.boxShadow = this.style.boxShadow;
125
+ } else {
126
+ this.htmlElemEndPoint.style.display = "none";
127
+ }
128
+ }
129
+
130
+ if (this.endPoint && this.startPoint) {
131
+ const point1 = utils.worldToScreen(this.startPoint, this.moduleInstance, this.viewer);
132
+ const point2 = utils.worldToScreen(this.endPoint, this.moduleInstance, this.viewer);
133
+
134
+ const { p1, p2, angle, width } = utils.getDataForDrawLineWithFixed(point1, point2, rect.width, rect.height);
135
+
136
+ const dx = p2.x - p1.x;
137
+ const dy = p2.y - p1.y;
138
+
139
+ const height = this.lineThickness;
140
+ if (utils.isInsideRect(p1, rect.width, rect.height) && utils.isInsideRect(p2, rect.width, rect.height)) {
141
+ this.htmlElemLine = utils.createHtmlElementIfNeed(this.htmlElemLine, this.targetElement, "ruler-line");
142
+ this.htmlElemLine.style.display = "block";
143
+ this.htmlElemLine.style.cursor = "pointer";
144
+ this.htmlElemLine.style.position = "absolute";
145
+ this.htmlElemLine.style.top = `${p1.y}px`;
146
+ this.htmlElemLine.style.left = `${p1.x}px`;
147
+ this.htmlElemLine.style.width = `${width}px`;
148
+ this.htmlElemLine.style.transform = `rotate(${angle}deg)`;
149
+ this.htmlElemLine.style.transformOrigin = `0px ${height / 2}px`;
150
+ this.htmlElemLine.style.boxShadow = this.style.boxShadow;
151
+ this.htmlElemLine.style.border = "none";
152
+ this.htmlElemLine.style.background = this.style.background;
153
+ this.htmlElemLine.style.zIndex = "1";
154
+ this.htmlElemLine.style.height = `${height}px`;
155
+
156
+ const distance = `${this.getDistance()} ${this.unit}`;
157
+
158
+ const pX = p1.x + dx / 2;
159
+ const pY = p1.y + dy / 2;
160
+
161
+ const widthTitle = distance.length * 10;
162
+
163
+ this.htmlElemTitle = utils.createHtmlElementIfNeed(this.htmlElemTitle, this.targetElement, "ruler-value");
164
+ this.htmlElemTitle.style.display = "block";
165
+ this.htmlElemTitle.style.cursor = "pointer";
166
+ this.htmlElemTitle.style.font = "10px";
167
+ this.htmlElemTitle.style.color = "white";
168
+ this.htmlElemTitle.style.position = "Absolute";
169
+ this.htmlElemTitle.style.top = `${pY}px`;
170
+ this.htmlElemTitle.style.left = `${pX - widthTitle / 2}px`;
171
+ this.htmlElemTitle.style.width = `${widthTitle}px`;
172
+ this.htmlElemTitle.style.transformOrigin = "0px 0px";
173
+ this.htmlElemTitle.style.borderRadius = "5px";
174
+ this.htmlElemTitle.style.boxShadow = this.style.boxShadow;
175
+ this.htmlElemTitle.style.border = "none";
176
+ this.htmlElemTitle.style.background = this.style.background;
177
+ this.htmlElemTitle.style.zIndex = "3";
178
+ this.htmlElemTitle.style.padding = "2px";
179
+ this.htmlElemTitle.style.textAlign = "center";
180
+ this.htmlElemTitle.innerHTML = `${distance}`;
181
+ } else {
182
+ this.htmlElemLine.style.display = "none";
183
+ this.htmlElemTitle.style.display = "none";
184
+ }
185
+ }
186
+ }
187
+
188
+ getDistance(): number {
189
+ return utils.getDistance(this.startPoint, this.endPoint, this.moduleInstance) / this.scale;
190
+ }
191
+
192
+ setStartPoint(gePoint: number[]): void {
193
+ this.startPoint = gePoint;
194
+ this.drawMeasureLine();
195
+ }
196
+
197
+ setEndPoint(gePoint: number[], isFinish: boolean): void {
198
+ this.isFinishDraw = isFinish === undefined ? true : isFinish;
199
+ this.endPoint = gePoint;
200
+ this.drawMeasureLine();
201
+ }
202
+
203
+ update(): void {
204
+ this.drawMeasureLine();
205
+ }
206
+
207
+ setSize(size: number): void {
208
+ this.size = size;
209
+ this.drawMeasureLine();
210
+ }
211
+
212
+ clear(): void {
213
+ this.endPoint = null;
214
+ this.startPoint = null;
215
+ this.htmlElemStartPoint = utils.destroyHtmlElement(this.htmlElemStartPoint, this.targetElement);
216
+ this.htmlElemEndPoint = utils.destroyHtmlElement(this.htmlElemEndPoint, this.targetElement);
217
+ this.htmlElemLine = utils.destroyHtmlElement(this.htmlElemLine, this.targetElement);
218
+ this.htmlElemTitle = utils.destroyHtmlElement(this.htmlElemTitle, this.targetElement);
219
+ }
220
+
221
+ setUnit(unit: string): void {
222
+ this.unit = unit;
223
+ this.drawMeasureLine();
224
+ }
225
+
226
+ setConversionFactor(scale: number): void {
227
+ this.scale = scale;
228
+ this.drawMeasureLine();
229
+ }
230
+
231
+ setStyle(style: CSSStyleDeclaration): void {
232
+ this.style = style;
233
+ this.drawMeasureLine();
234
+ }
235
+
236
+ setSelectionReactor(reactor: any): void {
237
+ utils.onSetCallback(this.htmlElemStartPoint, reactor ? reactor.onStartPoint : null);
238
+ utils.onSetCallback(this.htmlElemEndPoint, reactor ? reactor.onEndPoint : null);
239
+ utils.onSetCallback(this.htmlElemTitle, reactor ? reactor.onTitle : null);
240
+ }
241
+
242
+ setSelectability(enable: boolean): void {
243
+ utils.onSetSelectivity(this.htmlElemStartPoint, enable);
244
+ utils.onSetSelectivity(this.htmlElemEndPoint, enable);
245
+ utils.onSetSelectivity(this.htmlElemLine, enable);
246
+ utils.onSetSelectivity(this.htmlElemTitle, enable);
247
+ }
248
+ }
@@ -0,0 +1,182 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2002-2021, Open Design Alliance (the "Alliance").
3
+ // All rights reserved.
4
+ //
5
+ // This software and its documentation and related materials are owned by
6
+ // the Alliance. The software may only be incorporated into application
7
+ // programs owned by members of the Alliance, subject to a signed
8
+ // Membership Agreement and Supplemental Software License Agreement with the
9
+ // Alliance. The structure and organization of this software are the valuable
10
+ // trade secrets of the Alliance and its suppliers. The software is also
11
+ // protected by copyright law and international treaty provisions. Application
12
+ // programs incorporating this software must include the following statement
13
+ // with their copyright notices:
14
+ //
15
+ // This application incorporates Open Design Alliance software pursuant to a
16
+ // license agreement with Open Design Alliance.
17
+ // Open Design Alliance Copyright (C) 2002-2021 by Open Design Alliance.
18
+ // All rights reserved.
19
+ //
20
+ // By use of this software, its documentation or related materials, you
21
+ // acknowledge and accept the above terms.
22
+ ///////////////////////////////////////////////////////////////////////////////
23
+ import { Point2d } from "../Common/Geometry";
24
+
25
+ export function createHtmlElementIfNeed(
26
+ element: HTMLElement,
27
+ targetElement: HTMLElement,
28
+ dataTestId: string
29
+ ): HTMLElement {
30
+ if (!element) {
31
+ element = document.createElement("div");
32
+ element.setAttribute("data-testid", dataTestId);
33
+
34
+ targetElement.appendChild(element);
35
+ }
36
+ return element;
37
+ }
38
+
39
+ export function destroyHtmlElement(element: HTMLElement, targetElement: HTMLElement) {
40
+ if (element) {
41
+ targetElement.removeChild(element);
42
+ }
43
+ return null;
44
+ }
45
+
46
+ export function worldToScreen(gePoint: number[], moduleInstance, viewer): Point2d {
47
+ const worldPoint = moduleInstance.Point3d.createFromArray(gePoint);
48
+ const avp = viewer.activeView;
49
+ const mtx = avp.worldToDeviceMatrix;
50
+
51
+ const devicePoint = worldPoint.transformBy(mtx);
52
+
53
+ const res = { x: devicePoint.x / window.devicePixelRatio, y: devicePoint.y / window.devicePixelRatio };
54
+
55
+ mtx.delete();
56
+ worldPoint.delete();
57
+ devicePoint.delete();
58
+ avp.delete();
59
+ return res;
60
+ }
61
+
62
+ export function getDistance(gePoint1: number[], gePoint2: number[], moduleInstance: any) {
63
+ const tvPoint1 = moduleInstance.Point3d.createFromArray(gePoint1);
64
+ const tvPoint2 = moduleInstance.Point3d.createFromArray(gePoint2);
65
+
66
+ const distance = tvPoint1.distanceTo(tvPoint2).toFixed(2);
67
+
68
+ tvPoint1.delete();
69
+ tvPoint2.delete();
70
+
71
+ return distance;
72
+ }
73
+
74
+ export function getAngle(geStart: number[], geOrigin: number[], geEnd: number[], moduleInstance: any): number {
75
+ const tvStart = moduleInstance.Point3d.createFromArray(geStart);
76
+ const tvOrigin = moduleInstance.Point3d.createFromArray(geOrigin);
77
+ const tvEnd = moduleInstance.Point3d.createFromArray(geEnd);
78
+
79
+ const s1 = tvStart.sub(tvOrigin);
80
+ const s2 = tvEnd.sub(tvOrigin);
81
+
82
+ const v1 = s1.asVector();
83
+ const v2 = s2.asVector();
84
+
85
+ const angle = (180 * v1.angleTo(v2)) / Math.PI;
86
+
87
+ return angle;
88
+ }
89
+
90
+ export function getDataForDrawLine(p1: Point2d, p2: Point2d) {
91
+ const dx = p2.x - p1.x;
92
+ const dy = p2.y - p1.y;
93
+ let angle = (180 * Math.atan(dy / dx)) / Math.PI;
94
+ if (dx < 0) {
95
+ angle -= 180;
96
+ }
97
+ const width = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
98
+ return { angle, width };
99
+ }
100
+
101
+ function normalizeFloat(value: number): number {
102
+ return value < 0 ? Math.ceil(value) : Math.floor(value);
103
+ }
104
+
105
+ const lineSegmentsIntersect = (p1: Point2d, p2: Point2d, p3: Point2d, p4: Point2d): false | Point2d => {
106
+ const a_dx = p2.x - p1.x;
107
+ const a_dy = p2.y - p1.y;
108
+ const b_dx = p4.x - p3.x;
109
+ const b_dy = p4.y - p3.y;
110
+ const s = (-a_dy * (p1.x - p3.x) + a_dx * (p1.y - p3.y)) / (-b_dx * a_dy + a_dx * b_dy);
111
+ const t = (+b_dx * (p1.y - p3.y) - b_dy * (p1.x - p3.x)) / (-b_dx * a_dy + a_dx * b_dy);
112
+ return s >= 0 && s <= 1 && t >= 0 && t <= 1
113
+ ? {
114
+ x: normalizeFloat(p1.x + t * a_dx),
115
+ y: normalizeFloat(p1.y + t * a_dy),
116
+ }
117
+ : false;
118
+ };
119
+
120
+ function checkSegmentsIntersect(p1: Point2d, p2: Point2d, p3: Point2d, p4: Point2d, res: Point2d[]): void {
121
+ const r = lineSegmentsIntersect(p1, p2, p3, p4);
122
+ if (r) {
123
+ res.push(r);
124
+ }
125
+ }
126
+
127
+ export function isInsideRect(p: Point2d, width: number, height: number): boolean {
128
+ return p.x <= width && p.x >= 0 && p.y <= height && p.y >= 0;
129
+ }
130
+
131
+ export function getDataForDrawLineWithFixed(p1: Point2d, p2: Point2d, width: number, height: number) {
132
+ const pLU = { x: 0, y: 0 };
133
+ const pRU = { x: width, y: 0 };
134
+
135
+ const pLB = { x: 0, y: height };
136
+ const pRB = { x: width, y: height };
137
+
138
+ const intersects: Point2d[] = [];
139
+
140
+ checkSegmentsIntersect(p1, p2, pLU, pRU, intersects);
141
+ checkSegmentsIntersect(p1, p2, pLU, pLB, intersects);
142
+ checkSegmentsIntersect(p1, p2, pLB, pRB, intersects);
143
+ checkSegmentsIntersect(p1, p2, pRB, pRU, intersects);
144
+
145
+ let fixedP1: Point2d = null;
146
+ let fixedP2: Point2d = null;
147
+
148
+ if (intersects.length === 0) {
149
+ fixedP1 = p1;
150
+ fixedP2 = p2;
151
+ } else if (intersects.length === 1) {
152
+ if (isInsideRect(p1, width, height)) {
153
+ fixedP1 = p1;
154
+ fixedP2 = intersects[0];
155
+ } else {
156
+ fixedP1 = intersects[0];
157
+ fixedP2 = p2;
158
+ }
159
+ } else {
160
+ fixedP1 = intersects[0];
161
+ fixedP2 = intersects[1];
162
+ }
163
+
164
+ const dx = fixedP2.x - fixedP1.x;
165
+ const dy = fixedP2.y - fixedP1.y;
166
+ let angle = (180 * Math.atan(dy / dx)) / Math.PI;
167
+ if (dx < 0) {
168
+ angle -= 180;
169
+ }
170
+ const size = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
171
+ return { angle, width: size, p1: fixedP1, p2: fixedP2 };
172
+ }
173
+
174
+ export function onSetCallback(element: HTMLElement, cb: () => void): void {
175
+ if (element) {
176
+ element.onclick = cb ? () => cb() : () => {};
177
+ }
178
+ }
179
+
180
+ export function onSetSelectivity(element: HTMLElement, enable: boolean): void {
181
+ element.style.pointerEvents = enable ? "auto" : "none";
182
+ }
@@ -0,0 +1,166 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2002-2021, Open Design Alliance (the "Alliance").
3
+ // All rights reserved.
4
+ //
5
+ // This software and its documentation and related materials are owned by
6
+ // the Alliance. The software may only be incorporated into application
7
+ // programs owned by members of the Alliance, subject to a signed
8
+ // Membership Agreement and Supplemental Software License Agreement with the
9
+ // Alliance. The structure and organization of this software are the valuable
10
+ // trade secrets of the Alliance and its suppliers. The software is also
11
+ // protected by copyright law and international treaty provisions. Application
12
+ // programs incorporating this software must include the following statement
13
+ // with their copyright notices:
14
+ //
15
+ // This application incorporates Open Design Alliance software pursuant to a
16
+ // license agreement with Open Design Alliance.
17
+ // Open Design Alliance Copyright (C) 2002-2021 by Open Design Alliance.
18
+ // All rights reserved.
19
+ //
20
+ // By use of this software, its documentation or related materials, you
21
+ // acknowledge and accept the above terms.
22
+ ///////////////////////////////////////////////////////////////////////////////
23
+ import { Viewer } from "../../Viewer";
24
+ import { OdBaseDragger } from "../Common/OdBaseDragger";
25
+ import { MeasureLineItem } from "./MeasureLineItem";
26
+
27
+ function renameUnit(table, unit) {
28
+ return table[unit] || unit;
29
+ }
30
+
31
+ export class MeasureLineDragger extends OdBaseDragger {
32
+ protected lineThickness: number;
33
+ protected gripingRadius: number;
34
+ protected firstPoint: number[];
35
+ protected secondPoint: number[];
36
+ protected renameUnitTable: any;
37
+ protected items: MeasureLineItem[];
38
+ protected m_overlayElement: HTMLElement;
39
+ protected previewMeasureLine: MeasureLineItem;
40
+
41
+ constructor(subject: Viewer) {
42
+ super(subject);
43
+ this.lineThickness = 2;
44
+ this.press = false;
45
+ this.gripingRadius = 5.0;
46
+ this.firstPoint = null;
47
+ this.secondPoint = null;
48
+
49
+ this.renameUnitTable = {
50
+ Millimeters: "mm",
51
+ Centimeters: "cm",
52
+ Meters: "m",
53
+ Feet: "ft",
54
+ Inches: "in",
55
+ Yards: "yd",
56
+ Kilometers: "km",
57
+ Miles: "mi",
58
+ Micrometers: "µm",
59
+ MicroInches: "µin",
60
+ Undefined: " ",
61
+ };
62
+
63
+ this.items = [];
64
+
65
+ this.canvasEvents.push("resize");
66
+ }
67
+
68
+ override initialize(): void {
69
+ super.initialize();
70
+
71
+ this.m_overlayElement = document.createElement("div");
72
+ this.m_overlayElement.style.background = "rgba(0,0,0,0)";
73
+ this.m_overlayElement.style.position = "fixed";
74
+ this.m_overlayElement.style.zIndex = "1";
75
+ this.m_overlayElement.style.pointerEvents = "none";
76
+ document.body.appendChild(this.m_overlayElement);
77
+
78
+ this.resize();
79
+ }
80
+
81
+ override dispose(): void {
82
+ super.dispose();
83
+ this.m_overlayElement.remove();
84
+ }
85
+
86
+ override updatePreview(): void {
87
+ this.items.forEach((item) => item.update());
88
+ }
89
+
90
+ resize(): void {
91
+ const rect = this.m_module.canvas.getBoundingClientRect();
92
+
93
+ this.m_overlayElement.style.top = `${rect.top}px`;
94
+ this.m_overlayElement.style.left = `${rect.left}px`;
95
+ this.m_overlayElement.style.width = `${rect.width}px`;
96
+ this.m_overlayElement.style.height = `${rect.height}px`;
97
+ }
98
+
99
+ getSnapPointRadius(): number {
100
+ const view = this.getViewer().activeView;
101
+ const corners = view.viewDcCorners();
102
+
103
+ const pt1 = corners.lowerLeft;
104
+ const pt2 = corners.upperRight;
105
+
106
+ pt2[0] -= pt1[0];
107
+ pt2[1] -= pt1[1];
108
+
109
+ return Math.min(pt2[0], pt2[1]) / 120;
110
+ }
111
+
112
+ override drag(x: number, y: number): void {
113
+ this.createNewMeasureIfNeed();
114
+ const point = this.getViewer().getSnapPoint(x, y, this.gripingRadius);
115
+
116
+ if (this.isDragging) {
117
+ if (point) {
118
+ if (this.firstPoint) {
119
+ this.secondPoint = point;
120
+ this.previewMeasureLine.setStartPoint(this.firstPoint);
121
+ this.previewMeasureLine.setEndPoint(this.secondPoint, true);
122
+ } else {
123
+ this.firstPoint = point;
124
+ this.previewMeasureLine.setStartPoint(this.firstPoint);
125
+ }
126
+ } else {
127
+ this.secondPoint = null;
128
+ this.previewMeasureLine.clear();
129
+ this.previewMeasureLine.setStartPoint(this.firstPoint);
130
+ this.previewMeasureLine.setEndPoint(this.getViewer().screenToWorld(x, y), false);
131
+ }
132
+ } else {
133
+ if (point) {
134
+ this.previewMeasureLine.setStartPoint(point);
135
+ } else {
136
+ this.previewMeasureLine.clear();
137
+ }
138
+ }
139
+ }
140
+
141
+ override end(): void {
142
+ if (this.firstPoint && this.secondPoint) {
143
+ const newLineMeasure = this.createMeasureLine();
144
+ newLineMeasure.setStartPoint(this.firstPoint);
145
+ newLineMeasure.setEndPoint(this.secondPoint, true);
146
+ }
147
+ this.firstPoint = null;
148
+ this.secondPoint = null;
149
+ this.previewMeasureLine.clear();
150
+ }
151
+
152
+ createNewMeasureIfNeed(): void {
153
+ if (!this.previewMeasureLine) {
154
+ this.previewMeasureLine = this.createMeasureLine();
155
+ }
156
+ }
157
+
158
+ createMeasureLine(): MeasureLineItem {
159
+ const viewer = this.m_module.getViewer();
160
+ const item = new MeasureLineItem(this.m_overlayElement, viewer, this.m_module);
161
+ item.lineThickness = this.lineThickness || item.lineThickness;
162
+ item.setUnit(renameUnit(this.renameUnitTable, viewer.getUnit()));
163
+ this.items.push(item);
164
+ return item;
165
+ }
166
+ }