@inweb/viewer-visualize 25.8.15 → 25.8.19

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.
@@ -62,7 +62,7 @@ const OVERLAY_VIEW_NAME = "$OVERLAY_VIEW_NAME";
62
62
  const isExist = (value) => value !== undefined && value !== null;
63
63
 
64
64
  /**
65
- * The `Client.js` library class that provides methods to integrate with the
65
+ * 3D viewer powered by
66
66
  * {@link https://cloud.opendesign.com/docs/index.html#/visualizejs | VisualizeJS} library.
67
67
  */
68
68
 
@@ -98,19 +98,17 @@ export class Viewer
98
98
  public client: Client | undefined;
99
99
 
100
100
  /**
101
- * @param client - The `Client` instance that provides access to a server. Do not specify
102
- * `Client` if you need a standalone viewer instance without access to server models.
101
+ * @param client - The `Client` instance that provides access to a Open Cloud Server. Do not
102
+ * specify `Client` if you need a standalone viewer instance to view `VSFX` files from the
103
+ * web or from local computer.
103
104
  * @param params - An object containing viewer configuration parameters.
104
105
  * @param params.visualizeJsUrl - `VisualizeJS` library URL. Set this URL to use your own
105
- * library instance, or leave it undefined or blank to use the default URL defined by
106
- * `Client.js` you are using.
107
- *
108
- * _Note: Your own `VisualizeJS` library version must match the version of the `Client.js`
109
- * you are using._
106
+ * library instance, or specify `undefined` or blank to use the default URL defined by
107
+ * `Viewer.visualize` library you are using.
110
108
  * @param params.enableAutoUpdate - Enable auto-update of the viewer after any changes. If
111
- * the auto-update is disabled, you need to register the `update` event handler and update
112
- * the viewer and the active dragger manually. Default is `true`.
113
- * @param params.markupType - Specifies type of the markup core: `Visualize` (deprecated) or
109
+ * the auto-update is disabled, you need to register an `update` event handler and update
110
+ * the `VisualizeJS` viewer and active dragger manually. Default is `true`.
111
+ * @param params.markupType - The type of the markup core: `Visualize` (deprecated) or
114
112
  * `Konva`. Default is `Konva`.
115
113
  */
116
114
  constructor(
@@ -157,7 +155,7 @@ export class Viewer
157
155
  /**
158
156
  * Viewer options.
159
157
  */
160
- get options(): Options {
158
+ get options(): IOptions {
161
159
  return this._options;
162
160
  }
163
161
 
@@ -171,7 +169,7 @@ export class Viewer
171
169
  }
172
170
 
173
171
  /**
174
- * 2D markup core.
172
+ * 2D markup core instance used to create markups.
175
173
  *
176
174
  * @readonly
177
175
  */
@@ -180,11 +178,12 @@ export class Viewer
180
178
  }
181
179
 
182
180
  /**
183
- * Change the viewer configuration parameters.
181
+ * Changes the viewer parameters.
184
182
  *
185
- * @param params - An object containing new configuration parameters.
183
+ * @param params - An object containing new parameters.
186
184
  * @param params.visualizeJsUrl - `VisualizeJS` library URL. Set this URL to use your own
187
- * library instance or leave it blank to use the default URL defined by `Client.js`.
185
+ * library instance or specify `undefined` or blank to use the default URL defined by
186
+ * `Viewer.visualize` library you are using.
188
187
  */
189
188
  configure(params: { visualizeJsUrl?: string }): this {
190
189
  this._visualizeJsUrl = params.visualizeJsUrl || "VISUALIZE_JS_URL";
@@ -192,7 +191,7 @@ export class Viewer
192
191
  }
193
192
 
194
193
  /**
195
- * Load `VisualizeJS` module and initialize it with the specified canvas. Call
194
+ * Loads the `VisualizeJS` module and initialize it with the specified canvas. Call
196
195
  * {@link dispose | dispose()} to release allocated resources.
197
196
  *
198
197
  * Fires:
@@ -264,8 +263,8 @@ export class Viewer
264
263
  }
265
264
 
266
265
  /**
267
- * Releases all resources allocated by this `Viewer` instance. Call this method before
268
- * release the `Viewer` instance.
266
+ * Releases all resources allocated by this viewer instance. Call this method before release
267
+ * the `Viewer` instance.
269
268
  */
270
269
  dispose(): this {
271
270
  this.cancel();
@@ -301,7 +300,7 @@ export class Viewer
301
300
  }
302
301
 
303
302
  /**
304
- * Returns `true` if `VisualizeJS` module has been loaded andinitialized.
303
+ * Returns `true` if `VisualizeJS` module has been loaded and initialized.
305
304
  */
306
305
  isInitialized(): boolean {
307
306
  return !!this.visualizeJs;
@@ -345,8 +344,10 @@ export class Viewer
345
344
  }
346
345
 
347
346
  /**
348
- * Updates the viewer. Do nothing if the auto-update mode is disabled in the constructor (use
349
- * the `update` event to update viewer manually).
347
+ * Updates the viewer.
348
+ *
349
+ * Do nothing if the auto-update mode is disabled in the constructor. In this case, register
350
+ * an `update` event handler and update the `Visualize` viewer and active dragger manually.
350
351
  *
351
352
  * Fires:
352
353
  *
@@ -367,21 +368,15 @@ export class Viewer
367
368
  this.emitEvent({ type: "update", data: force });
368
369
  }
369
370
 
370
- /**
371
- * Update with internal schedule, need after change operation when have long update for
372
- * update without lock UI
373
- *
374
- * @param maxScheduleUpdateTimeInMs - Maximum time for one update, by default 30 ms
375
- * @param maxScheduleUpdateCount - Maximum count of schedule update
376
- * @returns return void Promise
377
- */
378
-
379
371
  private scheduleUpdateAsync(maxScheduleUpdateTimeInMs = 50): Promise<void> {
380
372
  return new Promise<void>((resolve, reject) => {
381
373
  setTimeout(() => {
382
374
  try {
383
- this.visViewer()?.update(maxScheduleUpdateTimeInMs);
384
- this.activeDragger()?.updatePreview();
375
+ if (this._enableAutoUpdate) {
376
+ this.visViewer()?.update(maxScheduleUpdateTimeInMs);
377
+ this.activeDragger()?.updatePreview();
378
+ }
379
+ this.emitEvent({ type: "update", data: false });
385
380
  resolve();
386
381
  } catch (e) {
387
382
  console.error(e);
@@ -391,6 +386,20 @@ export class Viewer
391
386
  });
392
387
  }
393
388
 
389
+ /**
390
+ * Updates the viewer asynchronously without locking the user interface. Used to update the
391
+ * viewer after changes that require a long rendering time.
392
+ *
393
+ * Do nothing if the auto-update mode is disabled in the constructor. In this case, register
394
+ * an `update` event handler and update the `VisualizeJS` viewer and active dragger manually.
395
+ *
396
+ * Fires:
397
+ *
398
+ * - {@link UpdateEvent | update}
399
+ *
400
+ * @param maxScheduleUpdateTimeInMs - Maximum time for one update, default 30 ms.
401
+ * @param maxScheduleUpdateCount - Maximum count of scheduled updates.
402
+ */
394
403
  async updateAsync(maxScheduleUpdateTimeInMs = 50, maxScheduleUpdateCount = 50): Promise<void> {
395
404
  this._isRunAsyncUpdate = true;
396
405
  const device = this.visViewer().getActiveDevice();
@@ -611,7 +620,7 @@ export class Viewer
611
620
  }
612
621
 
613
622
  /**
614
- * List of names of available draggers:
623
+ * List of names of registered draggers. By default, the following draggers are registered:
615
624
  *
616
625
  * - `Line`
617
626
  * - `Text`
@@ -633,7 +642,8 @@ export class Viewer
633
642
  }
634
643
 
635
644
  /**
636
- * Register dragger on draggerFactory.
645
+ * Registers a dragger for the viewer. Dragger is an object that received mouse/keyboard
646
+ * events and does something to the viewer.
637
647
  *
638
648
  * @param name - Dragger name.
639
649
  * @param dragger - Dragger class.
@@ -650,7 +660,7 @@ export class Viewer
650
660
  }
651
661
 
652
662
  /**
653
- * Set active dragger. `Viewer` must be initialized before enable dragger or exception is thrown.
663
+ * Changes the active dragger. Viewer must be initialized before enable dragger or exception is thrown.
654
664
  *
655
665
  * Fires:
656
666
  *
@@ -688,7 +698,7 @@ export class Viewer
688
698
  }
689
699
 
690
700
  /**
691
- * Reset the state of the active dragger.
701
+ * Resets the state of the active dragger.
692
702
  */
693
703
  resetActiveDragger(): void {
694
704
  const dragger = this._activeDragger;
@@ -699,7 +709,7 @@ export class Viewer
699
709
  }
700
710
 
701
711
  /**
702
- * Remove all cutting planes.
712
+ * Removes all cutting planes.
703
713
  */
704
714
  clearSlices(): void {
705
715
  if (!this.visualizeJs) return;
@@ -713,7 +723,7 @@ export class Viewer
713
723
  }
714
724
 
715
725
  /**
716
- * Clear overlay view.
726
+ * Clears the overlay view.
717
727
  */
718
728
  clearOverlay(): void {
719
729
  if (!this.visualizeJs) return;
@@ -723,7 +733,7 @@ export class Viewer
723
733
  }
724
734
 
725
735
  /**
726
- * Create overlay view.
736
+ * Creates an overlay view. Overlay view is used to draw cutting planes and `Visualize` markups.
727
737
  */
728
738
  syncOverlay(): any {
729
739
  if (!this.visualizeJs) return;
@@ -758,7 +768,7 @@ export class Viewer
758
768
  }
759
769
 
760
770
  /**
761
- * Returns `true` if current drawing is 3D drawing.
771
+ * Returns `true` if current model is 3D model.
762
772
  */
763
773
  is3D(): boolean {
764
774
  if (!this.visualizeJs) return false;
@@ -776,12 +786,16 @@ export class Viewer
776
786
  screenToWorld(position: { x: number; y: number }): { x: number; y: number; z: number } {
777
787
  if (!this.visualizeJs) return { x: position.x, y: position.y, z: 0 };
778
788
 
779
- const worldPoint = this.visViewer().screenToWorld(
789
+ const activeView = this.visViewer().activeView;
790
+ const worldPoint = activeView.transformScreenToWorld(
780
791
  position.x * window.devicePixelRatio,
781
792
  position.y * window.devicePixelRatio
782
793
  );
794
+
783
795
  const result = { x: worldPoint[0], y: worldPoint[1], z: worldPoint[2] };
784
796
 
797
+ activeView.delete();
798
+
785
799
  return result;
786
800
  }
787
801
 
@@ -789,15 +803,10 @@ export class Viewer
789
803
  if (!this.visualizeJs) return { x: position.x, y: position.y };
790
804
 
791
805
  const activeView = this.visViewer().activeView;
792
- const worldMatrix = activeView.worldToDeviceMatrix;
793
- const worldPoint = this.visLib().Point3d.createFromArray([position.x, position.y, position.z]);
806
+ const devicePoint = activeView.transformWorldToScreen(position.x, position.y, position.z);
794
807
 
795
- const devicePoint = worldPoint.transformBy(worldMatrix);
796
- const result = { x: devicePoint.x / window.devicePixelRatio, y: devicePoint.y / window.devicePixelRatio };
808
+ const result = { x: devicePoint[0] / window.devicePixelRatio, y: devicePoint[1] / window.devicePixelRatio };
797
809
 
798
- devicePoint.delete();
799
- worldPoint.delete();
800
- worldMatrix.delete();
801
810
  activeView.delete();
802
811
 
803
812
  return result;
@@ -822,16 +831,14 @@ export class Viewer
822
831
  }
823
832
 
824
833
  /**
825
- * Returns a list of original handles for the selected entities.
834
+ * Returns a list of original handles for the selected objects.
826
835
  */
827
836
  getSelected(): string[] {
828
837
  return this.executeCommand("getSelected");
829
838
  }
830
839
 
831
840
  /**
832
- * Select model entities by original handles that are obtained using
833
- * {@link File.getProperties | File.getProperties()} or
834
- * {@link File.searchProperties | File.searchProperties()} methods.
841
+ * Selects the model objects by original handles that are obtained using `File.searchProperties()`.
835
842
  *
836
843
  * Fires:
837
844
  *
@@ -843,13 +850,8 @@ export class Viewer
843
850
  this.executeCommand("setSelected", handles);
844
851
  }
845
852
 
846
- /**
847
- * Load model references into the viewer. References are images, fonts, or any other files to
848
- * correct rendering of the model.
849
- *
850
- * @param model - Instance of model with references. If a `File` instance is specified
851
- * instead of a model, the file references will be loaded.
852
- */
853
+ // Internal loading routines
854
+
853
855
  async loadReferences(model: Model | File | Assembly): Promise<this> {
854
856
  if (!this.visualizeJs) return this;
855
857
  if (!this.client) return this;
@@ -874,8 +876,6 @@ export class Viewer
874
876
  return this;
875
877
  }
876
878
 
877
- // Internal loading routines
878
-
879
879
  applyModelTransformMatrix(model: Model | Assembly) {
880
880
  this.executeCommand("applyModelTransform", model);
881
881
  }
@@ -899,7 +899,7 @@ export class Viewer
899
899
  }
900
900
 
901
901
  /**
902
- * Loads a model of a file or assembly into the viewer.
902
+ * Loads a model/file/assembly into the viewer.
903
903
  *
904
904
  * This method requires a {@link Client} instance to work. For standalone viewer instance use
905
905
  * {@link openVsfFile | openVsfFile()} or {@link openVsfxFile | openVsfxFile()}.
@@ -934,7 +934,7 @@ export class Viewer
934
934
  if (!model) throw new Error("No default model found");
935
935
 
936
936
  const overrideOptions = new Options();
937
- overrideOptions.data = this.options.data;
937
+ overrideOptions.data = this._options.data;
938
938
  if (file.type === ".rcs" && !overrideOptions.enablePartialMode) {
939
939
  console.log("Partial load mode is forced for RCS file");
940
940
  overrideOptions.enablePartialMode = true;
@@ -955,7 +955,7 @@ export class Viewer
955
955
  }
956
956
 
957
957
  /**
958
- * Loads a VSF file into the viewer.
958
+ * Loads a `VSF` file into the viewer.
959
959
  *
960
960
  * Fires:
961
961
  *
@@ -1001,7 +1001,7 @@ export class Viewer
1001
1001
  }
1002
1002
 
1003
1003
  /**
1004
- * Loads a VSFX file into the viewer.
1004
+ * Loads a `VSFX` file into the viewer.
1005
1005
  *
1006
1006
  * Fires:
1007
1007
  *
@@ -1065,7 +1065,7 @@ export class Viewer
1065
1065
  }
1066
1066
 
1067
1067
  /**
1068
- * Unloads the model and clears the viewer.
1068
+ * Unloads the model and clears the viewer and markups.
1069
1069
  */
1070
1070
  clear(): this {
1071
1071
  if (!this.visualizeJs) return this;
@@ -1088,16 +1088,18 @@ export class Viewer
1088
1088
  }
1089
1089
 
1090
1090
  /**
1091
- * Get markup color.
1092
- *
1093
- * @returns Color with `RGB` values.
1091
+ * Returns the color of new markup objects.
1094
1092
  */
1095
1093
  getMarkupColor(): { r: number; g: number; b: number } {
1096
1094
  return this._markup.getMarkupColor();
1097
1095
  }
1098
1096
 
1099
1097
  /**
1100
- * Set markup color.
1098
+ * Sets the color of new markup objects.
1099
+ *
1100
+ * Fires:
1101
+ *
1102
+ * - {@link ChangeMarkupColorEvent | changemarkupcolor}
1101
1103
  *
1102
1104
  * @param r - `Red` part of color.
1103
1105
  * @param g - `Green` part of color.
@@ -1110,7 +1112,7 @@ export class Viewer
1110
1112
  }
1111
1113
 
1112
1114
  /**
1113
- * Colorize all markup entities with the specified color.
1115
+ * Colors all markup objects with the specified color.
1114
1116
  *
1115
1117
  * @param r - `Red` part of color.
1116
1118
  * @param g - `Green` part of color.
@@ -1121,7 +1123,7 @@ export class Viewer
1121
1123
  }
1122
1124
 
1123
1125
  /**
1124
- * Colorize all selected markup entities with the specified color.
1126
+ * Colors selected markup objects with the specified color.
1125
1127
  *
1126
1128
  * @param r - `Red` part of color.
1127
1129
  * @param g - `Green` part of color.
@@ -1132,7 +1134,7 @@ export class Viewer
1132
1134
  }
1133
1135
 
1134
1136
  /**
1135
- * Add an empty markup entity to the overlay.
1137
+ * Adds an empty `Visualize` markup entity to the overlay.
1136
1138
  */
1137
1139
  addMarkupEntity(entityName: string) {
1138
1140
  if (!this.visualizeJs) return null;
@@ -1155,8 +1157,9 @@ export class Viewer
1155
1157
  }
1156
1158
 
1157
1159
  /**
1158
- * Draw a viewpoint. To get a list of available model viewpoints, use the
1159
- * `Model.getViewpoints()` or `File.getViewpoints()` or `Assembly.getViewpoints()`.
1160
+ * Sets the viewer state to the specified viewpoint.
1161
+ *
1162
+ * To get a list of available model viewpoints, use the `File.getViewpoints()`.
1160
1163
  *
1161
1164
  * @param viewpoint - Viewpoint data.
1162
1165
  */
@@ -1167,8 +1170,9 @@ export class Viewer
1167
1170
  }
1168
1171
 
1169
1172
  /**
1170
- * Create a viewpoint. To add a viewpoint to the list of model viewpoints, use the
1171
- * `Model.saveViewpoint()` or `File.saveViewpoint()` or . `Assembly.saveViewpoint()`.
1173
+ * Saves the viewer state at the viewpoint.
1174
+ *
1175
+ * To save a viewpoint to a model on the server, use the `File.saveViewpoint()`.
1172
1176
  */
1173
1177
  createViewpoint(): IViewpoint {
1174
1178
  const vp = this._markup.getViewpoint();