@inweb/viewer-core 27.4.7 → 27.6.0

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.
@@ -21,14 +21,14 @@
21
21
  // acknowledge and accept the above terms.
22
22
  ///////////////////////////////////////////////////////////////////////////////
23
23
 
24
- import { EventEmitter2 } from "@inweb/eventemitter2";
24
+ import { IEventEmitter } from "@inweb/eventemitter2";
25
25
  import { CameraMode, defaultOptions, IOptions, RGB } from "./IOptions";
26
26
 
27
27
  export class Options implements IOptions {
28
- protected _emitter?: EventEmitter2;
28
+ protected _emitter?: IEventEmitter;
29
29
  protected _data: IOptions;
30
30
 
31
- constructor(emitter?: EventEmitter2) {
31
+ constructor(emitter?: IEventEmitter) {
32
32
  this._emitter = emitter;
33
33
  this._data = defaultOptions();
34
34
  this.loadFromStorage();
@@ -73,15 +73,23 @@ export class Options implements IOptions {
73
73
  * @param fields - Name of fields to be reset. Specify `undefined` to reset all.
74
74
  */
75
75
  resetToDefaults(fields?: string[]): void {
76
+ const defaults = Options.defaults();
76
77
  if (fields !== undefined) {
77
- const defaults = Options.defaults();
78
- const resetData = fields.reduce((acc, field) => {
79
- acc[field] = defaults[field];
80
- return acc;
81
- }, {});
82
- this.data = { ...this.data, ...resetData };
78
+ const resetData: Partial<IOptions> = {};
79
+ for (const field of fields) {
80
+ if (field in defaults) resetData[field] = defaults[field];
81
+ }
82
+ this.data = resetData;
83
83
  } else {
84
- this.data = { ...this.data, ...Options.defaults() };
84
+ this.data = defaults;
85
+ }
86
+ }
87
+
88
+ setProperty<K extends keyof IOptions>(key: K, value = Options.defaults()[key]): void {
89
+ // for object-valued fields any new literal counts as a change
90
+ if (this._data[key] !== value) {
91
+ this._data[key] = value;
92
+ this.change();
85
93
  }
86
94
  }
87
95
 
@@ -89,10 +97,26 @@ export class Options implements IOptions {
89
97
  return this._data;
90
98
  }
91
99
 
92
- set data(value: IOptions) {
93
- const enablePartialMode = value.enableStreamingMode ? value.enablePartialMode : false;
94
- const sceneGraph = enablePartialMode ? false : value.sceneGraph;
95
- this._data = { ...Options.defaults(), ...this._data, ...value, enablePartialMode, sceneGraph };
100
+ set data(value: Partial<IOptions>) {
101
+ const defaults = Options.defaults();
102
+ const merged: IOptions = { ...defaults, ...this._data, ...value };
103
+ // replace undefined to default value for known properties
104
+ for (const key of Object.keys(defaults)) {
105
+ if (merged[key] === undefined) merged[key] = defaults[key];
106
+ }
107
+ this._data = merged;
108
+ // partial mode first
109
+ if (this._data.enablePartialMode) {
110
+ this._data.enableStreamingMode = true;
111
+ this._data.sceneGraph = false;
112
+ }
113
+ // sectionFillColor since 27.5
114
+ if (!value.sectionFillColor && value.cuttingPlaneFillColor)
115
+ this._data.sectionFillColor = {
116
+ r: value.cuttingPlaneFillColor.red,
117
+ g: value.cuttingPlaneFillColor.green,
118
+ b: value.cuttingPlaneFillColor.blue,
119
+ };
96
120
  this.change();
97
121
  }
98
122
 
@@ -101,8 +125,7 @@ export class Options implements IOptions {
101
125
  }
102
126
 
103
127
  set showWCS(value: boolean) {
104
- this._data.showWCS = value;
105
- this.change();
128
+ this.setProperty("showWCS", value);
106
129
  }
107
130
 
108
131
  get cameraAnimation(): boolean {
@@ -110,8 +133,7 @@ export class Options implements IOptions {
110
133
  }
111
134
 
112
135
  set cameraAnimation(value: boolean) {
113
- this._data.cameraAnimation = value;
114
- this.change();
136
+ this.setProperty("cameraAnimation", value);
115
137
  }
116
138
 
117
139
  get antialiasing(): boolean | string {
@@ -119,8 +141,7 @@ export class Options implements IOptions {
119
141
  }
120
142
 
121
143
  set antialiasing(value: boolean | string) {
122
- this._data.antialiasing = value;
123
- this.change();
144
+ this.setProperty("antialiasing", value);
124
145
  }
125
146
 
126
147
  get groundShadow(): boolean {
@@ -128,8 +149,7 @@ export class Options implements IOptions {
128
149
  }
129
150
 
130
151
  set groundShadow(value: boolean) {
131
- this._data.groundShadow = value;
132
- this.change();
152
+ this.setProperty("groundShadow", value);
133
153
  }
134
154
 
135
155
  get shadows(): boolean {
@@ -137,8 +157,7 @@ export class Options implements IOptions {
137
157
  }
138
158
 
139
159
  set shadows(value: boolean) {
140
- this._data.shadows = value;
141
- this.change();
160
+ this.setProperty("shadows", value);
142
161
  }
143
162
 
144
163
  get cameraAxisXSpeed(): number {
@@ -146,8 +165,7 @@ export class Options implements IOptions {
146
165
  }
147
166
 
148
167
  set cameraAxisXSpeed(value: number) {
149
- this._data.cameraAxisXSpeed = value;
150
- this.change();
168
+ this.setProperty("cameraAxisXSpeed", value);
151
169
  }
152
170
 
153
171
  get cameraAxisYSpeed(): number {
@@ -155,8 +173,7 @@ export class Options implements IOptions {
155
173
  }
156
174
 
157
175
  set cameraAxisYSpeed(value: number) {
158
- this.cameraAxisYSpeed = value;
159
- this.change();
176
+ this.setProperty("cameraAxisYSpeed", value);
160
177
  }
161
178
 
162
179
  get ambientOcclusion(): boolean {
@@ -164,8 +181,7 @@ export class Options implements IOptions {
164
181
  }
165
182
 
166
183
  set ambientOcclusion(value: boolean) {
167
- this._data.ambientOcclusion = value;
168
- this.change();
184
+ this.setProperty("ambientOcclusion", value);
169
185
  }
170
186
 
171
187
  get enableStreamingMode(): boolean {
@@ -173,9 +189,10 @@ export class Options implements IOptions {
173
189
  }
174
190
 
175
191
  set enableStreamingMode(value: boolean) {
176
- this._data.enableStreamingMode = value;
177
- if (!value) this._data.enablePartialMode = false;
178
- this.change();
192
+ this.setProperty("enableStreamingMode", value);
193
+ if (!value) {
194
+ this.setProperty("enablePartialMode", false);
195
+ }
179
196
  }
180
197
 
181
198
  get enablePartialMode(): boolean {
@@ -183,12 +200,11 @@ export class Options implements IOptions {
183
200
  }
184
201
 
185
202
  set enablePartialMode(value: boolean) {
186
- this._data.enablePartialMode = value;
203
+ this.setProperty("enablePartialMode", value);
187
204
  if (value) {
188
- this._data.enableStreamingMode = true;
189
- this._data.sceneGraph = false;
205
+ this.setProperty("enableStreamingMode", true);
206
+ this.setProperty("sceneGraph", false);
190
207
  }
191
- this.change();
192
208
  }
193
209
 
194
210
  get memoryLimit(): number {
@@ -196,135 +212,208 @@ export class Options implements IOptions {
196
212
  }
197
213
 
198
214
  set memoryLimit(value: number) {
199
- this._data.memoryLimit = value;
200
- this.change();
215
+ this.setProperty("memoryLimit", value);
201
216
  }
202
217
 
203
218
  get cuttingPlaneFillColor(): RGB {
204
- return this._data.cuttingPlaneFillColor;
219
+ console.warn(
220
+ "Options.cuttingPlaneFillColor has been deprecated since 27.5 and will be removed in a future release, use sectionFillColor instead"
221
+ );
222
+ return {
223
+ red: this._data.sectionFillColor.r,
224
+ green: this._data.sectionFillColor.g,
225
+ blue: this._data.sectionFillColor.b,
226
+ };
205
227
  }
206
228
 
207
229
  set cuttingPlaneFillColor(value: RGB) {
208
- this._data.cuttingPlaneFillColor = value;
209
- this.change();
230
+ console.warn(
231
+ "Options.cuttingPlaneFillColor has been deprecated since 27.5 and will be removed in a future release, use sectionFillColor instead"
232
+ );
233
+ this.setProperty("sectionFillColor", {
234
+ r: value.red,
235
+ g: value.green,
236
+ b: value.blue,
237
+ });
238
+ }
239
+
240
+ get enableSectionFill(): boolean {
241
+ return this._data.enableSectionFill;
242
+ }
243
+
244
+ set enableSectionFill(value: boolean) {
245
+ this.setProperty("enableSectionFill", value);
246
+ }
247
+
248
+ get sectionFillColor(): { r: number; g: number; b: number } {
249
+ return this._data.sectionFillColor;
250
+ }
251
+
252
+ set sectionFillColor(value: { r: number; g: number; b: number }) {
253
+ this.setProperty("sectionFillColor", value);
254
+ }
255
+
256
+ get sectionUseObjectColor(): boolean {
257
+ return this._data.sectionUseObjectColor;
258
+ }
259
+
260
+ set sectionUseObjectColor(value: boolean) {
261
+ this.setProperty("sectionUseObjectColor", value);
262
+ }
263
+
264
+ get enableSectionHatch(): boolean {
265
+ return this._data.enableSectionHatch;
266
+ }
267
+
268
+ set enableSectionHatch(value: boolean) {
269
+ this.setProperty("enableSectionHatch", value);
270
+ }
271
+
272
+ get sectionHatchColor(): { r: number; g: number; b: number } {
273
+ return this._data.sectionHatchColor;
274
+ }
275
+
276
+ set sectionHatchColor(value: { r: number; g: number; b: number }) {
277
+ this.setProperty("sectionHatchColor", value);
210
278
  }
211
279
 
212
- get edgesColor() {
280
+ get sectionHatchScale(): number {
281
+ return this._data.sectionHatchScale;
282
+ }
283
+
284
+ set sectionHatchScale(value: number) {
285
+ this.setProperty("sectionHatchScale", value);
286
+ }
287
+
288
+ get enableSectionOutline(): boolean {
289
+ return this._data.enableSectionOutline;
290
+ }
291
+
292
+ set enableSectionOutline(value: boolean) {
293
+ this.setProperty("enableSectionOutline", value);
294
+ }
295
+
296
+ get sectionOutlineColor(): { r: number; g: number; b: number } {
297
+ return this._data.sectionOutlineColor;
298
+ }
299
+
300
+ set sectionOutlineColor(value: { r: number; g: number; b: number }) {
301
+ this.setProperty("sectionOutlineColor", value);
302
+ }
303
+
304
+ get sectionOutlineWidth(): number {
305
+ return this._data.sectionOutlineWidth;
306
+ }
307
+
308
+ set sectionOutlineWidth(value: number) {
309
+ this.setProperty("sectionOutlineWidth", value);
310
+ }
311
+
312
+ get edgesColor(): { r: number; g: number; b: number } {
213
313
  return this._data.edgesColor;
214
314
  }
215
315
 
216
- set edgesColor(value) {
217
- this._data.edgesColor = value;
218
- this.change();
316
+ set edgesColor(value: { r: number; g: number; b: number }) {
317
+ this.setProperty("edgesColor", value);
219
318
  }
220
319
 
221
- get facesColor() {
320
+ get facesColor(): { r: number; g: number; b: number } {
222
321
  return this._data.facesColor;
223
322
  }
224
323
 
225
- set facesColor(value) {
226
- this._data.facesColor = value;
227
- this.change();
324
+ set facesColor(value: { r: number; g: number; b: number }) {
325
+ this.setProperty("facesColor", value);
228
326
  }
229
327
 
230
- get edgesVisibility() {
328
+ get edgesVisibility(): boolean {
231
329
  return this._data.edgesVisibility;
232
330
  }
233
331
 
234
- set edgesVisibility(value) {
235
- this._data.edgesVisibility = value;
236
- this.change();
332
+ set edgesVisibility(value: boolean) {
333
+ this.setProperty("edgesVisibility", value);
237
334
  }
238
335
 
239
- get edgesOverlap() {
336
+ get edgesOverlap(): boolean {
240
337
  return this._data.edgesOverlap;
241
338
  }
242
339
 
243
- set edgesOverlap(value) {
244
- this._data.edgesOverlap = value;
245
- this.change();
340
+ set edgesOverlap(value: boolean) {
341
+ this.setProperty("edgesOverlap", value);
246
342
  }
247
343
 
248
- get facesOverlap() {
344
+ get facesOverlap(): boolean {
249
345
  return this._data.facesOverlap;
250
346
  }
251
347
 
252
- set facesOverlap(value) {
253
- this._data.facesOverlap = value;
254
- this.change();
348
+ set facesOverlap(value: boolean) {
349
+ this.setProperty("facesOverlap", value);
255
350
  }
256
351
 
257
- get facesTransparancy() {
352
+ get facesTransparancy(): number {
258
353
  return this._data.facesTransparancy;
259
354
  }
260
355
 
261
- set facesTransparancy(value) {
262
- this._data.facesTransparancy = value;
263
- this.change();
356
+ set facesTransparancy(value: number) {
357
+ this.setProperty("facesTransparancy", value);
264
358
  }
265
359
 
266
- get enableCustomHighlight() {
360
+ get enableCustomHighlight(): boolean {
267
361
  return this._data.enableCustomHighlight;
268
362
  }
269
363
 
270
- set enableCustomHighlight(value) {
271
- this._data.enableCustomHighlight = value;
272
- this.change();
364
+ set enableCustomHighlight(value: boolean) {
365
+ this.setProperty("enableCustomHighlight", value);
273
366
  }
274
367
 
275
- get sceneGraph() {
368
+ get sceneGraph(): boolean {
276
369
  return this._data.sceneGraph;
277
370
  }
278
371
 
279
- set sceneGraph(value) {
280
- this._data.sceneGraph = value;
281
- if (value) this._data.enablePartialMode = false;
282
- this.change();
372
+ set sceneGraph(value: boolean) {
373
+ this.setProperty("sceneGraph", value);
374
+ if (value) {
375
+ this.setProperty("enablePartialMode", false);
376
+ }
283
377
  }
284
378
 
285
- get edgeModel() {
379
+ get edgeModel(): boolean {
286
380
  return Boolean(this._data.edgeModel);
287
381
  }
288
382
 
289
- set edgeModel(value) {
290
- this._data.edgeModel = Boolean(value);
291
- this.change();
383
+ set edgeModel(value: boolean) {
384
+ this.setProperty("edgeModel", value);
292
385
  }
293
386
 
294
- get reverseZoomWheel() {
387
+ get reverseZoomWheel(): boolean {
295
388
  return this._data.reverseZoomWheel;
296
389
  }
297
390
 
298
391
  set reverseZoomWheel(value: boolean) {
299
- this._data.reverseZoomWheel = !!value;
300
- this.change();
392
+ this.setProperty("reverseZoomWheel", value);
301
393
  }
302
394
 
303
- get enableZoomWheel() {
395
+ get enableZoomWheel(): boolean {
304
396
  return this._data.enableZoomWheel;
305
397
  }
306
398
 
307
399
  set enableZoomWheel(value: boolean) {
308
- this._data.enableZoomWheel = !!value;
309
- this.change();
400
+ this.setProperty("enableZoomWheel", value);
310
401
  }
311
402
 
312
- get enableGestures() {
403
+ get enableGestures(): boolean {
313
404
  return this._data.enableGestures;
314
405
  }
315
406
 
316
407
  set enableGestures(value: boolean) {
317
- this._data.enableGestures = !!value;
318
- this.change();
408
+ this.setProperty("enableGestures", value);
319
409
  }
320
410
 
321
- get geometryType() {
411
+ get geometryType(): string {
322
412
  return this._data.geometryType;
323
413
  }
324
414
 
325
415
  set geometryType(value: string) {
326
- this._data.geometryType = value;
327
- this.change();
416
+ this.setProperty("geometryType", value);
328
417
  }
329
418
 
330
419
  get rulerUnit(): string {
@@ -332,17 +421,15 @@ export class Options implements IOptions {
332
421
  }
333
422
 
334
423
  set rulerUnit(value: string) {
335
- this._data.rulerUnit = value;
336
- this.change();
424
+ this.setProperty("rulerUnit", value);
337
425
  }
338
426
 
339
- get rulerPrecision(): any {
427
+ get rulerPrecision(): "Default" | "Auto" | number {
340
428
  return this._data.rulerPrecision;
341
429
  }
342
430
 
343
- set rulerPrecision(value: any) {
344
- this._data.rulerPrecision = value;
345
- this.change();
431
+ set rulerPrecision(value: "Default" | "Auto" | number) {
432
+ this.setProperty("rulerPrecision", value);
346
433
  }
347
434
 
348
435
  get cameraMode(): CameraMode {
@@ -350,7 +437,22 @@ export class Options implements IOptions {
350
437
  }
351
438
 
352
439
  set cameraMode(value: CameraMode) {
353
- this._data.cameraMode = value;
354
- this.change();
440
+ this.setProperty("cameraMode", value);
441
+ }
442
+
443
+ get snapshotMimeType(): string {
444
+ return this._data.snapshotMimeType;
445
+ }
446
+
447
+ set snapshotMimeType(value: string) {
448
+ this.setProperty("snapshotMimeType", value);
449
+ }
450
+
451
+ get snapshotQuality(): number {
452
+ return this._data.snapshotQuality;
453
+ }
454
+
455
+ set snapshotQuality(value: number) {
456
+ this.setProperty("snapshotQuality", value);
355
457
  }
356
458
  }
@@ -167,10 +167,12 @@ export interface IViewer extends IEventEmitter, ICommandService {
167
167
  * - {@link UpdateEvent | update}
168
168
  * - {@link RenderEvent | render}
169
169
  *
170
- * @param force - If `true` updates the viewer immidietly. Otherwise the update will be scheduled for
171
- * the next animation frame. Default is `false`.
170
+ * @param force - If `true` updates the viewer immidietly. If a `number` is specified and more than the
171
+ * given amount of milliseconds has elapsed since the last rendering, the update is performed
172
+ * immediately as well. Otherwise the update will be scheduled for the next animation frame. Default
173
+ * is `false`.
172
174
  */
173
- update(force?: boolean): void;
175
+ update(force?: boolean | number): void;
174
176
 
175
177
  /**
176
178
  * Loads a file into the viewer.
@@ -226,9 +226,10 @@ export interface IText {
226
226
  font_size?: number;
227
227
 
228
228
  /**
229
- * Deprecated. Use {@link font_size} instead.
229
+ * Deprecated since `25.3`. Use {@link font_size} instead.
230
+ *
231
+ * @deprecated
230
232
  */
231
-
232
233
  text_size?: number;
233
234
 
234
235
  /**
@@ -373,12 +374,16 @@ export interface IImage {
373
374
  src: string;
374
375
 
375
376
  /**
376
- * Deprecated. Use {@link position2} instead. Width of the image.
377
+ * Deprecated since `26.5`. Use {@link position2} instead. Width of the image.
378
+ *
379
+ * @deprecated
377
380
  */
378
381
  width?: number;
379
382
 
380
383
  /**
381
- * Deprecated. Use {@link position2} instead. Height of the image.
384
+ * Deprecated since `26.5`. Use {@link position2} instead. Height of the image.
385
+ *
386
+ * @deprecated
382
387
  */
383
388
  height?: number;
384
389
 
@@ -403,12 +408,16 @@ export interface IRectangle {
403
408
  position2: IPoint;
404
409
 
405
410
  /**
406
- * Deprecated. Use {@link position2} instead. Width of the rectangle.
411
+ * Deprecated since `26.5`. Use {@link position2} instead. Width of the rectangle.
412
+ *
413
+ * @deprecated
407
414
  */
408
415
  width?: number;
409
416
 
410
417
  /**
411
- * Deprecated. Use {@link position2} instead. Height of the rectangle.
418
+ * Deprecated since `26.5`. Use {@link position2} instead. Height of the rectangle.
419
+ *
420
+ * @deprecated
412
421
  */
413
422
  height?: number;
414
423
 
@@ -100,6 +100,20 @@ export interface ChangeCameraModeEvent {
100
100
  mode: string;
101
101
  }
102
102
 
103
+ /**
104
+ * Event that fires when cutting planes (slices) have been changed.
105
+ *
106
+ * Fires when cutting planes are added, deleted, or transformed (moved/rotated).
107
+ *
108
+ * @event
109
+ */
110
+ export interface ChangeCuttingPlanesEvent {
111
+ /**
112
+ * Event type.
113
+ */
114
+ type: "changecuttingplanes";
115
+ }
116
+
103
117
  /**
104
118
  * Event that fires when the default color of new markup objects has been changed.
105
119
  *
@@ -807,6 +821,11 @@ export interface ViewerEventMap {
807
821
  */
808
822
  changecameramode: ChangeCameraModeEvent;
809
823
 
824
+ /**
825
+ * Event that fires when cutting planes (slices) have been changed.
826
+ */
827
+ changecuttingplanes: ChangeCuttingPlanesEvent;
828
+
810
829
  /**
811
830
  * Event that fires when the markup color has been changed.
812
831
  */