@inweb/client 25.2.2

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 (218) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +70 -0
  3. package/dist/client.js +21126 -0
  4. package/dist/client.js.map +1 -0
  5. package/dist/client.min.js +1 -0
  6. package/dist/client.module.js +7151 -0
  7. package/dist/client.module.js.map +1 -0
  8. package/lib/Api/Assembly.d.ts +339 -0
  9. package/lib/Api/ClashTest.d.ts +176 -0
  10. package/lib/Api/Client.d.ts +452 -0
  11. package/lib/Api/ClientEvents.d.ts +29 -0
  12. package/lib/Api/File.d.ts +568 -0
  13. package/lib/Api/HttpClient.d.ts +13 -0
  14. package/lib/Api/IAssembly.d.ts +14 -0
  15. package/lib/Api/IFile.d.ts +46 -0
  16. package/lib/Api/IHttpClient.d.ts +11 -0
  17. package/lib/Api/IUser.d.ts +11 -0
  18. package/lib/Api/Job.d.ts +142 -0
  19. package/lib/Api/Member.d.ts +85 -0
  20. package/lib/Api/Model.d.ts +147 -0
  21. package/lib/Api/Permission.d.ts +93 -0
  22. package/lib/Api/Project.d.ts +247 -0
  23. package/lib/Api/Role.d.ts +82 -0
  24. package/lib/Api/User.d.ts +197 -0
  25. package/lib/Api/impl/FetchError.d.ts +18 -0
  26. package/lib/Api/impl/Utils.d.ts +33 -0
  27. package/lib/Api/impl/http.d.ts +67 -0
  28. package/lib/ConvetMath.d.ts +29 -0
  29. package/lib/Viewer/CanvasEvents.d.ts +2 -0
  30. package/lib/Viewer/Commands/ApplyModelTransform.d.ts +2 -0
  31. package/lib/Viewer/Commands/ClearMarkup.d.ts +2 -0
  32. package/lib/Viewer/Commands/ClearSlices.d.ts +2 -0
  33. package/lib/Viewer/Commands/CreatePreview.d.ts +2 -0
  34. package/lib/Viewer/Commands/Explode.d.ts +2 -0
  35. package/lib/Viewer/Commands/GetDefaultViewPositions.d.ts +2 -0
  36. package/lib/Viewer/Commands/GetModels.d.ts +2 -0
  37. package/lib/Viewer/Commands/GetSelected.d.ts +2 -0
  38. package/lib/Viewer/Commands/HideSelected.d.ts +2 -0
  39. package/lib/Viewer/Commands/IsolateSelected.d.ts +2 -0
  40. package/lib/Viewer/Commands/RegenerateAll.d.ts +2 -0
  41. package/lib/Viewer/Commands/ResetView.d.ts +2 -0
  42. package/lib/Viewer/Commands/SelectModel.d.ts +2 -0
  43. package/lib/Viewer/Commands/SetActiveDragger.d.ts +2 -0
  44. package/lib/Viewer/Commands/SetDefaultViewPosition.d.ts +2 -0
  45. package/lib/Viewer/Commands/SetMarkupColor.d.ts +2 -0
  46. package/lib/Viewer/Commands/SetSelected.d.ts +2 -0
  47. package/lib/Viewer/Commands/ShowAll.d.ts +2 -0
  48. package/lib/Viewer/Commands/Unselect.d.ts +2 -0
  49. package/lib/Viewer/Commands/ZoomToExtents.d.ts +2 -0
  50. package/lib/Viewer/Commands/ZoomToObjects.d.ts +2 -0
  51. package/lib/Viewer/Commands/ZoomToSelected.d.ts +2 -0
  52. package/lib/Viewer/Commands.d.ts +3 -0
  53. package/lib/Viewer/Draggers/Actions/OrbitAction.d.ts +22 -0
  54. package/lib/Viewer/Draggers/Actions/PanAction.d.ts +18 -0
  55. package/lib/Viewer/Draggers/Actions/ZoomAction.d.ts +8 -0
  56. package/lib/Viewer/Draggers/Common/Geometry.d.ts +115 -0
  57. package/lib/Viewer/Draggers/Common/GestureManager.d.ts +41 -0
  58. package/lib/Viewer/Draggers/Common/OdBaseDragger.d.ts +54 -0
  59. package/lib/Viewer/Draggers/Common/OdaGeAction.d.ts +30 -0
  60. package/lib/Viewer/Draggers/MeasureLineDragger/MeasureLineItem.d.ts +31 -0
  61. package/lib/Viewer/Draggers/MeasureLineDragger/MeasureUtils.d.ts +20 -0
  62. package/lib/Viewer/Draggers/MeasureLineDragger/index.d.ts +24 -0
  63. package/lib/Viewer/Draggers/OdBaseCuttingPlaneDragger.d.ts +27 -0
  64. package/lib/Viewer/Draggers/OdCuttingPlaneXAxisDragger.d.ts +8 -0
  65. package/lib/Viewer/Draggers/OdCuttingPlaneYAxisDragger.d.ts +8 -0
  66. package/lib/Viewer/Draggers/OdCuttingPlaneZAxisDragger.d.ts +8 -0
  67. package/lib/Viewer/Draggers/OdOrbitDragger.d.ts +15 -0
  68. package/lib/Viewer/Draggers/OdPanDragger.d.ts +12 -0
  69. package/lib/Viewer/Draggers/OdZoomDragger.d.ts +12 -0
  70. package/lib/Viewer/Draggers/OdZoomWheelDragger.d.ts +11 -0
  71. package/lib/Viewer/Draggers/OdZoomWindowDragger/OdSelectionFrame.d.ts +19 -0
  72. package/lib/Viewer/Draggers/OdZoomWindowDragger/index.d.ts +14 -0
  73. package/lib/Viewer/Draggers/OdaLineDragger.d.ts +15 -0
  74. package/lib/Viewer/Draggers/OdaTextDragger.d.ts +16 -0
  75. package/lib/Viewer/Draggers/OdaWalkDragger.d.ts +30 -0
  76. package/lib/Viewer/Draggers/OrbitAroundBuildingDragger.d.ts +19 -0
  77. package/lib/Viewer/EventEmitter2.d.ts +54 -0
  78. package/lib/Viewer/ICommands.d.ts +25 -0
  79. package/lib/Viewer/IEventEmitter2.d.ts +13 -0
  80. package/lib/Viewer/IViewer.d.ts +27 -0
  81. package/lib/Viewer/Loaders/BaseLoader.d.ts +11 -0
  82. package/lib/Viewer/Loaders/LoaderFactory.d.ts +10 -0
  83. package/lib/Viewer/Loaders/TCSLoader.d.ts +5 -0
  84. package/lib/Viewer/Loaders/UpdaterController.d.ts +15 -0
  85. package/lib/Viewer/Loaders/VsfXLoader.d.ts +5 -0
  86. package/lib/Viewer/Loaders/VsfXPartialLoader.d.ts +5 -0
  87. package/lib/Viewer/Markup/Api/IMarkupArrow.d.ts +12 -0
  88. package/lib/Viewer/Markup/Api/IMarkupColorable.d.ts +5 -0
  89. package/lib/Viewer/Markup/Api/IMarkupEllipse.d.ts +15 -0
  90. package/lib/Viewer/Markup/Api/IMarkupImage.d.ts +15 -0
  91. package/lib/Viewer/Markup/Api/IMarkupLine.d.ts +11 -0
  92. package/lib/Viewer/Markup/Api/IMarkupObject.d.ts +12 -0
  93. package/lib/Viewer/Markup/Api/IMarkupRectangle.d.ts +15 -0
  94. package/lib/Viewer/Markup/Api/IMarkupText.d.ts +13 -0
  95. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaArrow.d.ts +32 -0
  96. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaEllipse.d.ts +40 -0
  97. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaImage.d.ts +36 -0
  98. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaLine.d.ts +32 -0
  99. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaRectangle.d.ts +38 -0
  100. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaText.d.ts +37 -0
  101. package/lib/Viewer/Markup/IMarkup.d.ts +38 -0
  102. package/lib/Viewer/Markup/Impl/Konva/KonvaMarkup.d.ts +63 -0
  103. package/lib/Viewer/Markup/Impl/Konva/MarkupColor.d.ts +19 -0
  104. package/lib/Viewer/Markup/Impl/Visualize/VisualizeMarkup.d.ts +33 -0
  105. package/lib/Viewer/Markup/MarkupFactory.d.ts +7 -0
  106. package/lib/Viewer/Options.d.ts +228 -0
  107. package/lib/Viewer/OptionsEvents.d.ts +26 -0
  108. package/lib/Viewer/Viewer.d.ts +353 -0
  109. package/lib/Viewer/ViewerCommands.d.ts +23 -0
  110. package/lib/Viewer/ViewerEvents.d.ts +601 -0
  111. package/lib/Viewer/utils.d.ts +4 -0
  112. package/lib/index.d.ts +24 -0
  113. package/package.json +32 -0
  114. package/src/Api/Assembly.ts +678 -0
  115. package/src/Api/ClashTest.ts +290 -0
  116. package/src/Api/Client.ts +816 -0
  117. package/src/Api/ClientEvents.ts +31 -0
  118. package/src/Api/File.ts +962 -0
  119. package/src/Api/HttpClient.ts +73 -0
  120. package/src/Api/IAssembly.ts +37 -0
  121. package/src/Api/IFile.ts +74 -0
  122. package/src/Api/IHttpClient.ts +50 -0
  123. package/src/Api/IUser.ts +33 -0
  124. package/src/Api/Job.ts +253 -0
  125. package/src/Api/Member.ts +161 -0
  126. package/src/Api/Model.ts +259 -0
  127. package/src/Api/Permission.ts +173 -0
  128. package/src/Api/Project.ts +479 -0
  129. package/src/Api/Role.ts +158 -0
  130. package/src/Api/User.ts +357 -0
  131. package/src/Api/impl/FetchError.ts +48 -0
  132. package/src/Api/impl/Utils.ts +367 -0
  133. package/src/Api/impl/http.ts +92 -0
  134. package/src/ConvetMath.ts +372 -0
  135. package/src/Viewer/CanvasEvents.ts +41 -0
  136. package/src/Viewer/Commands/ApplyModelTransform.ts +70 -0
  137. package/src/Viewer/Commands/ClearMarkup.ts +28 -0
  138. package/src/Viewer/Commands/ClearSlices.ts +27 -0
  139. package/src/Viewer/Commands/CreatePreview.ts +33 -0
  140. package/src/Viewer/Commands/Explode.ts +38 -0
  141. package/src/Viewer/Commands/GetDefaultViewPositions.ts +36 -0
  142. package/src/Viewer/Commands/GetModels.ts +43 -0
  143. package/src/Viewer/Commands/GetSelected.ts +58 -0
  144. package/src/Viewer/Commands/HideSelected.ts +37 -0
  145. package/src/Viewer/Commands/IsolateSelected.ts +37 -0
  146. package/src/Viewer/Commands/RegenerateAll.ts +37 -0
  147. package/src/Viewer/Commands/ResetView.ts +43 -0
  148. package/src/Viewer/Commands/SelectModel.ts +52 -0
  149. package/src/Viewer/Commands/SetActiveDragger.ts +29 -0
  150. package/src/Viewer/Commands/SetDefaultViewPosition.ts +50 -0
  151. package/src/Viewer/Commands/SetMarkupColor.ts +29 -0
  152. package/src/Viewer/Commands/SetSelected.ts +47 -0
  153. package/src/Viewer/Commands/ShowAll.ts +37 -0
  154. package/src/Viewer/Commands/Unselect.ts +37 -0
  155. package/src/Viewer/Commands/ZoomToExtents.ts +43 -0
  156. package/src/Viewer/Commands/ZoomToObjects.ts +47 -0
  157. package/src/Viewer/Commands/ZoomToSelected.ts +39 -0
  158. package/src/Viewer/Commands.ts +81 -0
  159. package/src/Viewer/Draggers/Actions/OrbitAction.ts +250 -0
  160. package/src/Viewer/Draggers/Actions/PanAction.ts +102 -0
  161. package/src/Viewer/Draggers/Actions/ZoomAction.ts +45 -0
  162. package/src/Viewer/Draggers/Common/Geometry.ts +152 -0
  163. package/src/Viewer/Draggers/Common/GestureManager.ts +263 -0
  164. package/src/Viewer/Draggers/Common/OdBaseDragger.ts +270 -0
  165. package/src/Viewer/Draggers/Common/OdaGeAction.ts +146 -0
  166. package/src/Viewer/Draggers/MeasureLineDragger/MeasureLineItem.ts +248 -0
  167. package/src/Viewer/Draggers/MeasureLineDragger/MeasureUtils.ts +182 -0
  168. package/src/Viewer/Draggers/MeasureLineDragger/index.ts +166 -0
  169. package/src/Viewer/Draggers/OdBaseCuttingPlaneDragger.ts +182 -0
  170. package/src/Viewer/Draggers/OdCuttingPlaneXAxisDragger.ts +53 -0
  171. package/src/Viewer/Draggers/OdCuttingPlaneYAxisDragger.ts +53 -0
  172. package/src/Viewer/Draggers/OdCuttingPlaneZAxisDragger.ts +53 -0
  173. package/src/Viewer/Draggers/OdOrbitDragger.ts +70 -0
  174. package/src/Viewer/Draggers/OdPanDragger.ts +62 -0
  175. package/src/Viewer/Draggers/OdZoomDragger.ts +59 -0
  176. package/src/Viewer/Draggers/OdZoomWheelDragger.ts +103 -0
  177. package/src/Viewer/Draggers/OdZoomWindowDragger/OdSelectionFrame.ts +123 -0
  178. package/src/Viewer/Draggers/OdZoomWindowDragger/index.ts +75 -0
  179. package/src/Viewer/Draggers/OdaLineDragger.ts +80 -0
  180. package/src/Viewer/Draggers/OdaTextDragger.ts +118 -0
  181. package/src/Viewer/Draggers/OdaWalkDragger.ts +278 -0
  182. package/src/Viewer/Draggers/OrbitAroundBuildingDragger.ts +184 -0
  183. package/src/Viewer/EventEmitter2.ts +116 -0
  184. package/src/Viewer/ICommands.ts +53 -0
  185. package/src/Viewer/IEventEmitter2.ts +36 -0
  186. package/src/Viewer/IViewer.ts +55 -0
  187. package/src/Viewer/Loaders/BaseLoader.ts +40 -0
  188. package/src/Viewer/Loaders/LoaderFactory.ts +44 -0
  189. package/src/Viewer/Loaders/TCSLoader.ts +82 -0
  190. package/src/Viewer/Loaders/UpdaterController.ts +36 -0
  191. package/src/Viewer/Loaders/VsfXLoader.ts +87 -0
  192. package/src/Viewer/Loaders/VsfXPartialLoader.ts +208 -0
  193. package/src/Viewer/Markup/Api/IMarkupArrow.ts +15 -0
  194. package/src/Viewer/Markup/Api/IMarkupColorable.ts +4 -0
  195. package/src/Viewer/Markup/Api/IMarkupEllipse.ts +15 -0
  196. package/src/Viewer/Markup/Api/IMarkupImage.ts +15 -0
  197. package/src/Viewer/Markup/Api/IMarkupLine.ts +10 -0
  198. package/src/Viewer/Markup/Api/IMarkupObject.ts +15 -0
  199. package/src/Viewer/Markup/Api/IMarkupRectangle.ts +15 -0
  200. package/src/Viewer/Markup/Api/IMarkupText.ts +12 -0
  201. package/src/Viewer/Markup/Api/Impl/Konva/KonvaArrow.ts +119 -0
  202. package/src/Viewer/Markup/Api/Impl/Konva/KonvaEllipse.ts +113 -0
  203. package/src/Viewer/Markup/Api/Impl/Konva/KonvaImage.ts +121 -0
  204. package/src/Viewer/Markup/Api/Impl/Konva/KonvaLine.ts +99 -0
  205. package/src/Viewer/Markup/Api/Impl/Konva/KonvaRectangle.ts +113 -0
  206. package/src/Viewer/Markup/Api/Impl/Konva/KonvaText.ts +104 -0
  207. package/src/Viewer/Markup/IMarkup.ts +39 -0
  208. package/src/Viewer/Markup/Impl/Konva/KonvaMarkup.ts +872 -0
  209. package/src/Viewer/Markup/Impl/Konva/MarkupColor.ts +39 -0
  210. package/src/Viewer/Markup/Impl/Visualize/VisualizeMarkup.ts +273 -0
  211. package/src/Viewer/Markup/MarkupFactory.ts +32 -0
  212. package/src/Viewer/Options.ts +502 -0
  213. package/src/Viewer/OptionsEvents.ts +28 -0
  214. package/src/Viewer/Viewer.ts +1109 -0
  215. package/src/Viewer/ViewerCommands.ts +45 -0
  216. package/src/Viewer/ViewerEvents.ts +700 -0
  217. package/src/Viewer/utils.ts +74 -0
  218. package/src/index.ts +48 -0
@@ -0,0 +1,146 @@
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 { Matrix3d, OdTvPlane, Point3d, Vector3d } from "./Geometry";
24
+
25
+ export type ViewParams = {
26
+ position: number[];
27
+ target: number[];
28
+ upVector: number[];
29
+ viewFieldWidth: number;
30
+ viewFieldHeight: number;
31
+ perspective: boolean;
32
+ };
33
+
34
+ export class OdaGeAction {
35
+ protected m_module;
36
+
37
+ constructor(module: any) {
38
+ this.m_module = module;
39
+ }
40
+
41
+ protected getViewer(): any {
42
+ return this.m_module.getViewer();
43
+ }
44
+
45
+ protected getModel(): any {
46
+ return this.getViewer().getMarkupModel();
47
+ }
48
+
49
+ protected copyPoint(point: Point3d): Point3d {
50
+ const p: Point3d = new this.m_module.Point3d();
51
+ p.set(point.x, point.y, point.z);
52
+ return p;
53
+ }
54
+
55
+ protected createVector3d(): Vector3d {
56
+ return new this.m_module.Vector3d();
57
+ }
58
+
59
+ protected createPoint3d(): Point3d {
60
+ return new this.m_module.Point3d();
61
+ }
62
+
63
+ protected createMatrix3d(): Matrix3d {
64
+ return new this.m_module.Matrix3d();
65
+ }
66
+
67
+ protected createPlane(): OdTvPlane {
68
+ return new this.m_module.OdTvPlane();
69
+ }
70
+
71
+ protected toVector(geVector): Vector3d {
72
+ return this.m_module.Vector3d.createFromArray(geVector);
73
+ }
74
+
75
+ protected toGeVector(v: Vector3d): number[] {
76
+ return [v.x, v.y, v.z];
77
+ }
78
+
79
+ protected toGePoint(point: Point3d): number[] {
80
+ return [point.x, point.y, point.z];
81
+ }
82
+
83
+ protected toPoint(gePoint: number[]): Point3d {
84
+ return this.m_module.Point3d.createFromArray(gePoint);
85
+ }
86
+
87
+ protected screenToWorld(x: number, y: number): Point3d {
88
+ return this.toPoint(this.m_module.getViewer().screenToWorld(x, y));
89
+ }
90
+
91
+ protected toDoubleArray(points: Point3d[]): number[] {
92
+ const p: number[] = [];
93
+ for (let i = 0; i < points.length; i++) {
94
+ p.push(points[i].x);
95
+ p.push(points[i].y);
96
+ p.push(points[i].z);
97
+ }
98
+ return p;
99
+ }
100
+
101
+ protected correctCameraTarget(): void {
102
+ const params = this.getViewParams();
103
+ const ext = this.m_module.getViewer().getActiveExtents();
104
+ const { min, max } = ext;
105
+ const target = this.toPoint(params.target);
106
+
107
+ const contains =
108
+ target.x >= min.x &&
109
+ target.y >= min.y &&
110
+ target.z >= min.z &&
111
+ target.x <= max.x &&
112
+ target.y <= max.y &&
113
+ target.z <= max.z;
114
+ if (!contains) {
115
+ params.target = ext.center();
116
+ this.setViewParams(params);
117
+ }
118
+ }
119
+
120
+ protected setViewParams = (params: ViewParams) => {
121
+ const extView = this.m_module.getViewer().getActiveTvExtendedView();
122
+ extView.setView(
123
+ params.position,
124
+ params.target,
125
+ params.upVector,
126
+ params.viewFieldWidth,
127
+ params.viewFieldHeight,
128
+ params.perspective
129
+ );
130
+ extView.delete?.();
131
+ };
132
+
133
+ protected getViewParams = () => {
134
+ const view = this.m_module.getViewer().activeView;
135
+ const obj = {
136
+ position: view.viewPosition,
137
+ target: view.viewTarget,
138
+ upVector: view.upVector,
139
+ viewFieldWidth: view.viewFieldWidth,
140
+ viewFieldHeight: view.viewFieldHeight,
141
+ perspective: view.perspective,
142
+ } as ViewParams;
143
+ view.delete?.();
144
+ return obj;
145
+ };
146
+ }
@@ -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
+ }