@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,184 @@
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
+ /* eslint-disable no-unused-vars */
24
+ import { Viewer } from "../Viewer";
25
+ import { Point2d } from "./Common/Geometry";
26
+ import { ViewParams } from "./Common/OdaGeAction";
27
+ import { OdBaseDragger } from "./Common/OdBaseDragger";
28
+
29
+ export class OrbitAroundBuildingDragger extends OdBaseDragger {
30
+ protected maxPolarAngle: number;
31
+ protected minPolarAngle: number;
32
+ protected m_viewCenter: any;
33
+ protected m_startPoint: Point2d;
34
+ protected startCameraParams: ViewParams;
35
+ protected m_delta: number;
36
+
37
+ constructor(viewer: Viewer) {
38
+ super(viewer);
39
+ this.autoSelect = true;
40
+ this.press = false;
41
+ this.maxPolarAngle = Math.PI / 2;
42
+ this.minPolarAngle = 0; // radians
43
+ }
44
+
45
+ override start(x: number, y: number): void {
46
+ this.press = true;
47
+
48
+ this.m_viewCenter = this.getCenter();
49
+ this.m_startPoint = { x, y };
50
+
51
+ const view = this.getViewer().activeView;
52
+
53
+ this.startCameraParams = this.getViewParams();
54
+
55
+ const corners = view.vportRect;
56
+
57
+ this.m_delta = Math.max(corners[1] - corners[0], corners[2] - corners[3]);
58
+
59
+ this.beginInteractivity();
60
+ }
61
+
62
+ setDefaultViewParams(): void {
63
+ this.setViewParams(this.startCameraParams);
64
+ }
65
+
66
+ override drag(x: number, y: number, dltX: number, dltY: number): void {
67
+ if (this.press) {
68
+ let dX = x - this.m_startPoint.x;
69
+ let dY = y - this.m_startPoint.y;
70
+
71
+ dX *= Math.PI / this.m_delta;
72
+ dY *= Math.PI / this.m_delta;
73
+
74
+ this.setDefaultViewParams();
75
+
76
+ const { Vector3d, Matrix3d } = this.m_module;
77
+
78
+ const target = Vector3d.createFromArray(this.startCameraParams.target);
79
+ const offset = Vector3d.createFromArray(this.startCameraParams.position).sub(target);
80
+ const dir = offset.normalize();
81
+
82
+ const zMatrix = new Matrix3d();
83
+ zMatrix.setToIdentity();
84
+ const xMatrix = new Matrix3d();
85
+ xMatrix.setToIdentity();
86
+
87
+ // ---- restore start rotation ----
88
+
89
+ const yAxis = Vector3d.createFromArray([dir.x, dir.y, dir.z]);
90
+ const zAxis = Vector3d.createFromArray(this.startCameraParams.upVector);
91
+ const xAxis = yAxis.crossProduct(zAxis);
92
+
93
+ // ----------- zAxis rotation restore -----------
94
+ let xyDir = Vector3d.createFromArray([yAxis.x, yAxis.y, 0]);
95
+
96
+ if (xyDir.length() <= 0.00001) {
97
+ xyDir.set(-xAxis.y, xAxis.x, 0);
98
+ } else {
99
+ xyDir = xyDir.normalize();
100
+ }
101
+ const xyAngle =
102
+ Math.sign(xyDir.dotProduct(Vector3d.createFromArray([-1, 0, 0]))) *
103
+ xyDir.angleTo(Vector3d.createFromArray([0, 1, 0]));
104
+ dX -= xyAngle;
105
+ // ----------- zAxis rotation restore -----------
106
+
107
+ // ----------- xAxis rotation restore -----------
108
+ let yzDir = Vector3d.createFromArray([dir.x, dir.y, 0]);
109
+ let yzAngle = 0;
110
+ if (yzDir.length() <= 0.00001) {
111
+ yzAngle = (-dir.z * Math.PI) / 2;
112
+ } else {
113
+ yzDir = yzDir.normalize();
114
+ yzAngle = -yzDir.angleTo(dir);
115
+ }
116
+ dY -= yzAngle;
117
+ // ----------- xAxis rotation restore -----------
118
+
119
+ // ---- restore start rotation ----
120
+
121
+ zMatrix.setToRotation(-dX, [0, 0, 1], [0, 0, 0]);
122
+
123
+ const xAngle = Math.max(this.minPolarAngle, Math.min(this.maxPolarAngle, dY));
124
+ xMatrix.setToRotation(xAngle, [1, 0, 0], [0, 0, 0]);
125
+
126
+ const endMatrix = zMatrix.postMultBy(xMatrix);
127
+
128
+ let pos = Vector3d.createFromArray([0, 1, 0]).transformBy(endMatrix);
129
+ const up = Vector3d.createFromArray([0, 0, 1]).transformBy(endMatrix);
130
+
131
+ pos.setLength(offset.length());
132
+ pos = target.add(pos);
133
+
134
+ const current = this.getViewParams();
135
+
136
+ current.position = pos.toArray();
137
+ current.upVector = up.toArray();
138
+
139
+ this.setViewParams(current);
140
+ }
141
+ }
142
+
143
+ override end(): void {
144
+ this.press = false;
145
+ this.endInteractivity();
146
+ }
147
+
148
+ getCenter(): any {
149
+ const viewer = this.getViewer();
150
+
151
+ let ext = viewer.getActiveExtents();
152
+
153
+ const pSet = viewer.getSelected();
154
+ if (!pSet.isNull() && pSet.numItems() !== 0) {
155
+ const itr = pSet.getIterator();
156
+ const entId = itr.getEntity();
157
+
158
+ if (entId.getType() === 1) {
159
+ const obj = entId.openObject();
160
+
161
+ ext.delete();
162
+ ext = obj.getExtents();
163
+
164
+ obj.delete();
165
+ } else if (entId.getType() === 2) {
166
+ const obj = entId.openObjectAsInsert();
167
+ const extTuple = obj.getExtents();
168
+
169
+ ext.delete();
170
+ ext = extTuple.ext;
171
+
172
+ extTuple.delete();
173
+ obj.delete();
174
+ }
175
+
176
+ itr.delete();
177
+ }
178
+
179
+ const center = ext.center();
180
+
181
+ ext.delete();
182
+ return center;
183
+ }
184
+ }
@@ -0,0 +1,40 @@
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
+
24
+ import { Model } from "@inweb/client";
25
+ import { OptionsData } from "@inweb/viewer-core";
26
+ import { Viewer } from "../Viewer";
27
+
28
+ export class BaseLoader {
29
+ protected viewer: Viewer;
30
+ protected model: Model;
31
+ protected options: OptionsData;
32
+
33
+ constructor(viewer: Viewer, model: Model, options: OptionsData) {
34
+ this.viewer = viewer;
35
+ this.model = model;
36
+ this.options = options;
37
+ }
38
+
39
+ async load(): Promise<void> {}
40
+ }
@@ -0,0 +1,48 @@
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
+
24
+ import { Model } from "@inweb/client";
25
+ import { OptionsData } from "@inweb/viewer-core";
26
+
27
+ import { TCSLoader } from "./TCSLoader";
28
+ import { VsfXStreamingLoader } from "./VsfXStreamingLoader";
29
+ import { VsfXPartialLoader } from "./VsfXPartialLoader";
30
+ import { Viewer } from "../Viewer";
31
+ import { VsfXLoader } from "./VsfXLoader";
32
+
33
+ export class LoaderFactory {
34
+ create(viewer: Viewer, model: Model, options: OptionsData) {
35
+ const geometryType = model.database.split(".").pop();
36
+
37
+ if (model.geometry.length === 0 && geometryType === "vsfx") {
38
+ if (!options.enableStreamingMode) return new VsfXLoader(viewer, model, options);
39
+ else if (options.enablePartialMode) return new VsfXPartialLoader(viewer, model, options);
40
+ else return new VsfXStreamingLoader(viewer, model, options);
41
+ }
42
+
43
+ if (geometryType === "data") {
44
+ return new TCSLoader(viewer, model, options);
45
+ }
46
+ throw new Error(`Unknown geometry type: ${geometryType}`);
47
+ }
48
+ }
@@ -0,0 +1,82 @@
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
+
24
+ import { BaseLoader } from "./BaseLoader";
25
+
26
+ export class TCSLoader extends BaseLoader {
27
+ override async load(): Promise<void> {
28
+ if (!this.viewer.visualizeJs) return;
29
+
30
+ const visLib = this.viewer.visLib();
31
+ const visViewer = visLib.getViewer();
32
+ const abortController = new AbortController();
33
+
34
+ const listFileForDownload = [this.model.database, ...this.model.geometry];
35
+ const chunksProgress = listFileForDownload.map(() => 0);
36
+
37
+ const calcProgress = (index, progress) => {
38
+ chunksProgress[index] = progress;
39
+ const fileProgress = chunksProgress.reduce((acc, progress) => (acc += progress)) / (chunksProgress.length || 1);
40
+ this.viewer.emitEvent({ type: "geometryprogress", data: fileProgress, model: this.model });
41
+ };
42
+
43
+ this.viewer._abortController = abortController;
44
+
45
+ try {
46
+ this.viewer.emitEvent({ type: "geometrystart", model: this.model });
47
+
48
+ for (let i = 0; i < listFileForDownload.length; i++) {
49
+ const chunk = listFileForDownload[i];
50
+
51
+ const progressCb = (progress) => calcProgress(i, progress);
52
+ const arrayBuffer = await this.model.downloadResource(chunk, progressCb, abortController.signal);
53
+
54
+ if (abortController.signal.aborted) {
55
+ await Promise.reject(new Error(`Open model aborted ${this.model.name}`));
56
+ }
57
+
58
+ visViewer.parseStream(new Uint8Array(arrayBuffer));
59
+ this.viewer.update();
60
+
61
+ const data = new Uint8Array(arrayBuffer);
62
+
63
+ if (i === 0) {
64
+ this.viewer.update(true);
65
+
66
+ this.viewer.syncOpenCloudVisualStyle(false);
67
+ this.viewer.syncOptions();
68
+ this.viewer.resize();
69
+
70
+ this.viewer.emitEvent({ type: "databasechunk", data, model: this.model });
71
+ } else {
72
+ this.viewer.emitEvent({ type: "geometrychunk", data, model: this.model });
73
+ }
74
+ }
75
+
76
+ this.viewer.emitEvent({ type: "geometryend", model: this.model });
77
+ } catch (error) {
78
+ this.viewer.emitEvent({ type: "geometryerror", data: error, model: this.model });
79
+ throw error;
80
+ }
81
+ }
82
+ }
@@ -0,0 +1,36 @@
1
+ import { Viewer } from "../Viewer";
2
+
3
+ const DELAY_TIME_MULTIPLEXER = 2.0;
4
+ const START_UPDATE_TIME = 1000;
5
+
6
+ export enum UpdateType {
7
+ kDelay,
8
+ kNormal,
9
+ kForce,
10
+ }
11
+
12
+ export class UpdaterController {
13
+ private lastUpdate: number;
14
+ private viewer: Viewer;
15
+ public delayUpdateTime: number;
16
+
17
+ constructor() {
18
+ this.delayUpdateTime = START_UPDATE_TIME;
19
+ }
20
+
21
+ initialize(viewer: Viewer) {
22
+ this.viewer = viewer;
23
+ this.lastUpdate = performance.now();
24
+ }
25
+
26
+ update(type: UpdateType) {
27
+ const isNeedUpdate = type !== UpdateType.kDelay || performance.now() - this.lastUpdate >= this.delayUpdateTime;
28
+ const isForce = type === UpdateType.kForce;
29
+
30
+ if (isNeedUpdate) {
31
+ this.viewer.update(isForce);
32
+ this.lastUpdate = performance.now();
33
+ this.delayUpdateTime *= DELAY_TIME_MULTIPLEXER;
34
+ }
35
+ }
36
+ }
@@ -0,0 +1,65 @@
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
+
24
+ import { BaseLoader } from "./BaseLoader";
25
+
26
+ export class VsfXLoader extends BaseLoader {
27
+ override async load(): Promise<void> {
28
+ if (!this.viewer.visualizeJs) return;
29
+
30
+ const visLib = this.viewer.visLib();
31
+ const visViewer = visLib.getViewer();
32
+ const abortController = new AbortController();
33
+
34
+ this.viewer._abortController = abortController;
35
+
36
+ console.time("File load time");
37
+ try {
38
+ this.viewer.emitEvent({ type: "geometrystart", model: this.model });
39
+
40
+ const progressCb = (progress) =>
41
+ this.viewer.emitEvent({ type: "geometryprogress", data: progress, model: this.model });
42
+ const arrayBuffer = await this.model.downloadResource(this.model.database, progressCb, abortController.signal);
43
+
44
+ if (abortController.signal.aborted) {
45
+ await Promise.reject(new Error(`Open model aborted ${this.model.name}`));
46
+ }
47
+
48
+ if (this.viewer.visualizeJs) {
49
+ visViewer.parseVsfx(new Uint8Array(arrayBuffer));
50
+ this.viewer.update(true);
51
+
52
+ this.viewer.syncOpenCloudVisualStyle(false);
53
+ this.viewer.syncOptions();
54
+ this.viewer.resize();
55
+ }
56
+
57
+ console.timeEnd("File load time");
58
+
59
+ this.viewer.emitEvent({ type: "geometryend", model: this.model });
60
+ } catch (error) {
61
+ this.viewer.emitEvent({ type: "geometryerror", data: error, model: this.model });
62
+ throw error;
63
+ }
64
+ }
65
+ }
@@ -0,0 +1,208 @@
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
+
24
+ import { BaseLoader } from "./BaseLoader";
25
+ import { UpdaterController, UpdateType } from "./UpdaterController";
26
+
27
+ export class VsfXPartialLoader extends BaseLoader {
28
+ override async load(): Promise<void> {
29
+ if (!this.viewer.visualizeJs) return;
30
+
31
+ const visLib = this.viewer.visLib();
32
+ const visViewer = visLib.getViewer();
33
+ const abortController = new AbortController();
34
+ const abortControllerForRequestMap = new Map();
35
+ let servicePartAborted = false;
36
+
37
+ const pendingRequestsMap = new Map();
38
+ const PENDING_REQUESTS_SIZE = 50;
39
+ const PENDING_REQUESTS_TIMEOUT = 250;
40
+ let pendingRequestsTimerId = 0;
41
+ const pendingRequestsAbortHandler = () => clearTimeout(pendingRequestsTimerId);
42
+
43
+ const pendingRequestsAbortController = new AbortController();
44
+ abortControllerForRequestMap.set(0, pendingRequestsAbortController);
45
+
46
+ const updaterController = new UpdaterController();
47
+ updaterController.initialize(this.viewer);
48
+
49
+ this.viewer._abortController = abortController;
50
+ this.viewer._abortControllerForRequestMap = abortControllerForRequestMap;
51
+
52
+ visViewer.memoryLimit = this.options.memoryLimit;
53
+
54
+ const requestLoadHandler = (progress, data, requestId) => {
55
+ if (!this.viewer.visualizeJs) return;
56
+
57
+ const state = visViewer.parseVsfxInPartialMode(requestId, data);
58
+ updaterController.update(UpdateType.kDelay);
59
+
60
+ this.viewer.emitEvent({ type: "geometryprogress", data: progress, model: this.model });
61
+
62
+ if (state) {
63
+ updaterController.update(UpdateType.kForce);
64
+
65
+ this.viewer.syncOpenCloudVisualStyle(false);
66
+ this.viewer.syncOptions();
67
+ this.viewer.resize();
68
+
69
+ this.viewer.emitEvent({ type: "databasechunk", data, model: this.model });
70
+ } else {
71
+ this.viewer.emitEvent({ type: "geometrychunk", data, model: this.model });
72
+ }
73
+ };
74
+
75
+ const downloadPartOfFile = async (requestId, records, dataId, isMultipleParts = false) => {
76
+ const abortCtrl = new AbortController();
77
+ abortControllerForRequestMap.set(requestId, abortCtrl);
78
+ try {
79
+ await this.model.downloadFileRange(requestId, records, dataId, requestLoadHandler, abortCtrl.signal);
80
+ } catch (error) {
81
+ this.viewer.emitEvent({ type: "geometryerror", data: error, model: this.model });
82
+ } finally {
83
+ const requests = isMultipleParts ? [...new Set(records.map((item) => item.reqId))] : [requestId];
84
+ requests.forEach((requestId) => visViewer.onRequestResponseComplete(requestId));
85
+ abortControllerForRequestMap.delete(requestId);
86
+ updaterController.update(UpdateType.kNormal);
87
+ }
88
+ };
89
+
90
+ const recordsToArray = (requestId, records) => {
91
+ const res = [];
92
+ for (let i = 0; i < records.size(); i++) {
93
+ const record = records.get(i);
94
+ res.push({
95
+ reqId: requestId,
96
+ begin: record.begin,
97
+ end: record.end,
98
+ size: parseInt(record.end, 10) - parseInt(record.begin, 10),
99
+ });
100
+ record.delete();
101
+ }
102
+ return res;
103
+ };
104
+
105
+ const objectHandler = {
106
+ onServicePartReceived: (bHasIndex) => {
107
+ if (bHasIndex) {
108
+ servicePartAborted = true;
109
+ abortController.abort();
110
+ }
111
+ },
112
+
113
+ onRequest: (requestId, records) => {
114
+ downloadPartOfFile(requestId, records, this.model.database);
115
+ },
116
+
117
+ onFullLoaded: () => {
118
+ updaterController.update(UpdateType.kNormal);
119
+ console.timeEnd("File load time");
120
+ },
121
+
122
+ onRequestResponseParsed: (requestId) => {
123
+ abortControllerForRequestMap.delete(requestId);
124
+ updaterController.update(UpdateType.kNormal);
125
+ },
126
+
127
+ onRequestAborted: (requestId) => {
128
+ const abortCtrl = abortControllerForRequestMap.get(requestId);
129
+ if (abortCtrl) abortCtrl.abort();
130
+ },
131
+
132
+ onRequestResourceFile: async (requestId, _, records) => {
133
+ const dataId = `${this.model.fileId}${this.model.file.type}`;
134
+
135
+ let pendingRequests = [];
136
+ let recNumber = 0;
137
+ const pendingRequestsRecord = pendingRequestsMap.get(dataId);
138
+ if (pendingRequestsRecord) {
139
+ pendingRequests = pendingRequestsRecord.array;
140
+ recNumber = pendingRequestsRecord.number;
141
+ }
142
+
143
+ // first several records of each file are processed without grouping (they usually require to be processed sequentially)
144
+ if (recNumber < 6) {
145
+ pendingRequestsMap.set(dataId, { array: pendingRequests, number: recNumber + 1 });
146
+ await downloadPartOfFile(requestId, records, dataId);
147
+ return;
148
+ }
149
+
150
+ // group requests to each file to launch a combined server request
151
+ if (pendingRequests.length >= PENDING_REQUESTS_SIZE) {
152
+ if (pendingRequestsTimerId) {
153
+ window.clearTimeout(pendingRequestsTimerId);
154
+ pendingRequestsTimerId = 0;
155
+ }
156
+
157
+ downloadPartOfFile(requestId, pendingRequests, dataId, true);
158
+ pendingRequests = [...recordsToArray(requestId, records)];
159
+ } else {
160
+ pendingRequests = [...pendingRequests, ...recordsToArray(requestId, records)];
161
+ }
162
+
163
+ pendingRequestsMap.set(dataId, { array: pendingRequests, number: recNumber + 1 });
164
+
165
+ // set timeout to wait for the new requests, after that process the remaining requests
166
+ if (pendingRequestsTimerId === 0) {
167
+ pendingRequestsTimerId = window.setTimeout(() => {
168
+ pendingRequestsAbortController.signal.removeEventListener("abort", pendingRequestsAbortHandler);
169
+ pendingRequestsTimerId = 0;
170
+
171
+ pendingRequestsMap.forEach((requestsRecord, keyFileName) => {
172
+ const array = requestsRecord.array;
173
+ if (array.length > 0) {
174
+ downloadPartOfFile(requestId, array, keyFileName, true);
175
+ pendingRequestsMap.set(keyFileName, { array: [], number: requestsRecord.number + 1 });
176
+ }
177
+ });
178
+ }, PENDING_REQUESTS_TIMEOUT);
179
+
180
+ pendingRequestsAbortController.signal.addEventListener("abort", pendingRequestsAbortHandler, { once: true });
181
+ }
182
+ },
183
+ };
184
+
185
+ visViewer.attachPartialResolver(objectHandler);
186
+
187
+ console.time("File load time");
188
+ try {
189
+ this.viewer.emitEvent({ type: "geometrystart", model: this.model });
190
+
191
+ await this.model
192
+ .downloadFileRange(0, null, this.model.database, requestLoadHandler, abortController.signal)
193
+ .catch((error) => {
194
+ if (!servicePartAborted) throw error;
195
+ });
196
+
197
+ this.viewer.emitEvent({ type: "geometryend", model: this.model });
198
+ } catch (error) {
199
+ if (pendingRequestsTimerId) {
200
+ window.clearTimeout(pendingRequestsTimerId);
201
+ pendingRequestsTimerId = 0;
202
+ }
203
+
204
+ this.viewer.emitEvent({ type: "geometryerror", data: error, model: this.model });
205
+ throw error;
206
+ }
207
+ }
208
+ }