@shapediver/viewer.features.drawing-tools 3.3.4 → 3.3.6
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.
- package/package.json +12 -13
- package/src/api/implementation/DrawingToolsApi.ts +0 -130
- package/src/api/implementation/restrictions/AbstractRestrictionApi.ts +0 -34
- package/src/api/implementation/restrictions/AbstractSnapRestrictionApi.ts +0 -36
- package/src/api/implementation/restrictions/geometry/GeometryRestrictionApi.ts +0 -56
- package/src/api/implementation/restrictions/plane/PlaneRestrictionApi.ts +0 -70
- package/src/api/implementation/restrictions/plane/snap/AngularRestrictionApi.ts +0 -35
- package/src/api/implementation/restrictions/plane/snap/AxisRestrictionApi.ts +0 -19
- package/src/api/implementation/restrictions/plane/snap/GridRestrictionApi.ts +0 -35
- package/src/api/interfaces/IDrawingToolsApi.ts +0 -98
- package/src/api/interfaces/IRestrictionApi.ts +0 -15
- package/src/api/interfaces/ISnapRestrictionApi.ts +0 -18
- package/src/business/implementation/DrawingToolsManager.ts +0 -618
- package/src/business/implementation/managers/HistoryManager.ts +0 -101
- package/src/business/implementation/managers/TextVisualizationManager.ts +0 -269
- package/src/business/implementation/managers/geometry/GeometryManager.ts +0 -95
- package/src/business/implementation/managers/geometry/GeometryMathManager.ts +0 -289
- package/src/business/implementation/managers/geometry/GeometryState.ts +0 -436
- package/src/business/implementation/managers/geometry/helpers/GeometryManagerHelper.ts +0 -170
- package/src/business/implementation/managers/interaction/EventManager.ts +0 -80
- package/src/business/implementation/managers/interaction/InteractionManager.ts +0 -268
- package/src/business/implementation/managers/interaction/RestrictionManager.ts +0 -132
- package/src/business/implementation/managers/interaction/handlers/DeletionInteractionHandler.ts +0 -48
- package/src/business/implementation/managers/interaction/handlers/InsertionInteractionHandler.ts +0 -149
- package/src/business/implementation/managers/interaction/handlers/MidPointInteractionHandler.ts +0 -127
- package/src/business/implementation/managers/interaction/helpers/InteractionManagerHelper.ts +0 -411
- package/src/business/implementation/managers/interaction/restrictions/AbstractRestriction.ts +0 -99
- package/src/business/implementation/managers/interaction/restrictions/geometry/GeometryRestriction.ts +0 -237
- package/src/business/implementation/managers/interaction/restrictions/plane/PlaneRestriction.ts +0 -337
- package/src/business/implementation/managers/interaction/restrictions/plane/snap/AngularRestriction.ts +0 -394
- package/src/business/implementation/managers/interaction/restrictions/plane/snap/AxisRestriction.ts +0 -116
- package/src/business/implementation/managers/interaction/restrictions/plane/snap/GridRestriction.ts +0 -246
- package/src/business/implementation/utils/numberCleaner.ts +0 -5
- package/src/business/interfaces/IDrawingToolsManager.ts +0 -312
- package/src/business/interfaces/IManager.ts +0 -7
- package/src/business/interfaces/IRestriction.ts +0 -63
- package/src/business/interfaces/IRestrictionBase.ts +0 -33
- package/src/business/interfaces/ISnapRestriction.ts +0 -70
- package/src/business/interfaces/events/EventResponseMapping.ts +0 -19
- package/src/business/interfaces/events/IDrawingToolsEvent.ts +0 -16
- package/src/index.ts +0 -72
- package/src/three/CSS2DRenderer.ts +0 -212
- package/tsconfig.json +0 -17
|
@@ -1,618 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Callbacks,
|
|
3
|
-
DefaultTextures,
|
|
4
|
-
IDrawingToolsManager,
|
|
5
|
-
MATERIAL_INDEX,
|
|
6
|
-
PointsData,
|
|
7
|
-
Settings,
|
|
8
|
-
SettingsOptional
|
|
9
|
-
} from '../interfaces/IDrawingToolsManager';
|
|
10
|
-
import { DrawingToolsEventResponseMapping } from '../interfaces/events/EventResponseMapping';
|
|
11
|
-
import {
|
|
12
|
-
EventEngine,
|
|
13
|
-
EVENTTYPE_DRAWING_TOOLS,
|
|
14
|
-
IEvent,
|
|
15
|
-
ShapeDiverViewerDrawingToolsError,
|
|
16
|
-
UuidGenerator
|
|
17
|
-
} from '@shapediver/viewer.shared.services';
|
|
18
|
-
import { EventManager } from './managers/interaction/EventManager';
|
|
19
|
-
import {
|
|
20
|
-
FLAG_TYPE,
|
|
21
|
-
ITreeNode,
|
|
22
|
-
IViewportApi,
|
|
23
|
-
sceneTree,
|
|
24
|
-
TreeNode
|
|
25
|
-
} from '@shapediver/viewer';
|
|
26
|
-
import { GeometryManager } from './managers/geometry/GeometryManager';
|
|
27
|
-
import { GeometryMathManager } from './managers/geometry/GeometryMathManager';
|
|
28
|
-
import { GeometryState } from './managers/geometry/GeometryState';
|
|
29
|
-
import { HistoryManager } from './managers/HistoryManager';
|
|
30
|
-
import { InteractionManager } from './managers/interaction/InteractionManager';
|
|
31
|
-
import { IRay } from '@shapediver/viewer.features.interaction';
|
|
32
|
-
import { IRestriction, RESTRICTION_TYPE, RestrictionProperties } from '../interfaces/IRestriction';
|
|
33
|
-
import { RestrictionManager } from './managers/interaction/RestrictionManager';
|
|
34
|
-
import { TextVisualizationManager } from './managers/TextVisualizationManager';
|
|
35
|
-
import { vec3 } from 'gl-matrix';
|
|
36
|
-
|
|
37
|
-
export class DrawingToolsManager implements IDrawingToolsManager {
|
|
38
|
-
// #region Properties (17)
|
|
39
|
-
|
|
40
|
-
readonly #callbacks: Callbacks;
|
|
41
|
-
readonly #defaultTextures: DefaultTextures;
|
|
42
|
-
readonly #eventEngine = EventEngine.instance;
|
|
43
|
-
readonly #eventManager: EventManager;
|
|
44
|
-
readonly #geometryManager: GeometryManager;
|
|
45
|
-
readonly #geometryMathManager: GeometryMathManager;
|
|
46
|
-
readonly #historyManager: HistoryManager;
|
|
47
|
-
readonly #interactionManager: InteractionManager;
|
|
48
|
-
readonly #keysPressed: { [key: string]: boolean } = {};
|
|
49
|
-
readonly #parentNode: ITreeNode;
|
|
50
|
-
readonly #settings: Settings;
|
|
51
|
-
readonly #textVisualizationManager: TextVisualizationManager;
|
|
52
|
-
readonly #uuidGenerator: UuidGenerator = UuidGenerator.instance;
|
|
53
|
-
readonly #viewport: IViewportApi;
|
|
54
|
-
|
|
55
|
-
#closed: boolean = false;
|
|
56
|
-
#continuousRenderingFlag?: string;
|
|
57
|
-
#uuid = this.#uuidGenerator.create();
|
|
58
|
-
|
|
59
|
-
// #endregion Properties (17)
|
|
60
|
-
|
|
61
|
-
// #region Constructors (1)
|
|
62
|
-
|
|
63
|
-
constructor(viewport: IViewportApi, callbacks: Callbacks, settings: SettingsOptional, defaultTextures?: DefaultTextures) {
|
|
64
|
-
this.#viewport = viewport;
|
|
65
|
-
this.#callbacks = callbacks;
|
|
66
|
-
this.#settings = this.cleanSettings(settings);
|
|
67
|
-
this.#defaultTextures = defaultTextures!;
|
|
68
|
-
|
|
69
|
-
this.#parentNode = new TreeNode(`DrawingToolsManager_${this.#uuid}`);
|
|
70
|
-
sceneTree.root.addChild(this.#parentNode);
|
|
71
|
-
sceneTree.root.updateVersion(false, false);
|
|
72
|
-
|
|
73
|
-
this.#geometryMathManager = new GeometryMathManager(this);
|
|
74
|
-
this.#geometryManager = new GeometryManager(this);
|
|
75
|
-
this.#interactionManager = new InteractionManager(this);
|
|
76
|
-
this.#textVisualizationManager = new TextVisualizationManager(this);
|
|
77
|
-
this.#historyManager = new HistoryManager(this);
|
|
78
|
-
|
|
79
|
-
this.#eventManager = new EventManager(this.#viewport, {
|
|
80
|
-
onDown: this.onDown.bind(this),
|
|
81
|
-
onUp: this.onUp.bind(this),
|
|
82
|
-
onOut: this.onOut.bind(this),
|
|
83
|
-
onMove: this.onMove.bind(this),
|
|
84
|
-
onKeyDown: this.onKeyDown.bind(this),
|
|
85
|
-
onKeyUp: this.onKeyUp.bind(this)
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
this.#continuousRenderingFlag = this.#viewport.addFlag(FLAG_TYPE.CONTINUOUS_RENDERING);
|
|
89
|
-
|
|
90
|
-
// special case, the scene is still empty, so we create a grid by default and show the scene
|
|
91
|
-
if (sceneTree.root.boundingBox.isEmpty())
|
|
92
|
-
this.#viewport.show = true;
|
|
93
|
-
|
|
94
|
-
// add listener for geometry changes, if autoUpdate is enabled the drawing tool will update automatically
|
|
95
|
-
this.#eventEngine.addListener(EVENTTYPE_DRAWING_TOOLS.GEOMETRY_CHANGED, (e: IEvent) => {
|
|
96
|
-
const event = e as DrawingToolsEventResponseMapping[EVENTTYPE_DRAWING_TOOLS.GEOMETRY_CHANGED];
|
|
97
|
-
if (event.temporary === false && event.points !== undefined && event.recordHistory !== false) {
|
|
98
|
-
if (this.#settings.general.autoUpdate && this.#interactionManager.insertionInteractionHandler.insertionActive === false && (this.#settings.geometry.autoClose || this.#settings.geometry.close === this.#geometryManager.geometryState.closeLoop)) {
|
|
99
|
-
this.update();
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// #endregion Constructors (1)
|
|
106
|
-
|
|
107
|
-
// #region Public Getters And Setters (22)
|
|
108
|
-
|
|
109
|
-
public get callbacks(): Callbacks {
|
|
110
|
-
return this.#callbacks;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
public get closed(): boolean {
|
|
114
|
-
return this.#closed;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
public get defaultTextures(): DefaultTextures {
|
|
118
|
-
return this.#defaultTextures;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
public get geometryManager(): GeometryManager {
|
|
122
|
-
return this.#geometryManager;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
public get geometryMathManager(): GeometryMathManager {
|
|
126
|
-
return this.#geometryMathManager;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
public get geometryState(): GeometryState {
|
|
130
|
-
return this.#geometryManager.geometryState;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
public get historyManager(): HistoryManager {
|
|
134
|
-
return this.#historyManager;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
public get indicesArrayLines(): Uint8Array | null | undefined {
|
|
138
|
-
return this.#geometryManager.geometryState.indicesArrayLines;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
public get insertionActive(): boolean {
|
|
142
|
-
return this.#interactionManager.insertionInteractionHandler.insertionActive;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
public get interactionManager(): InteractionManager {
|
|
146
|
-
return this.#interactionManager;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
public get parentNode(): ITreeNode {
|
|
150
|
-
return this.#parentNode;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
public get positionArray(): Float32Array {
|
|
154
|
-
return this.#geometryManager.geometryState.positionArray;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
public get restrictionManager(): RestrictionManager {
|
|
158
|
-
return this.#interactionManager.restrictionManager;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
public get restrictions(): { [key: string]: IRestriction } {
|
|
162
|
-
return this.restrictionManager.restrictions;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
public get settings(): Settings {
|
|
166
|
-
return this.#settings;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
public get showDistanceLabels(): boolean {
|
|
170
|
-
return this.#textVisualizationManager.showDistanceLabels;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
public set showDistanceLabels(value: boolean) {
|
|
174
|
-
this.#textVisualizationManager.showDistanceLabels = value;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
public get showPointLabels(): boolean {
|
|
178
|
-
return this.#textVisualizationManager.showPointLabels;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
public set showPointLabels(value: boolean) {
|
|
182
|
-
this.#textVisualizationManager.showPointLabels = value;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
public get textVisualizationManager(): TextVisualizationManager {
|
|
186
|
-
return this.#textVisualizationManager;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
public get uuid(): string {
|
|
190
|
-
return this.#uuid;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
public get viewport(): IViewportApi {
|
|
194
|
-
return this.#viewport;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// #endregion Public Getters And Setters (22)
|
|
198
|
-
|
|
199
|
-
// #region Public Methods (28)
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Add a point to the drawing tool.
|
|
203
|
-
*
|
|
204
|
-
* @param index
|
|
205
|
-
* @param position
|
|
206
|
-
* @returns
|
|
207
|
-
*/
|
|
208
|
-
public addPoint(index: number, position?: vec3 | undefined, temporary = false): void {
|
|
209
|
-
if (this.#closed) return;
|
|
210
|
-
if (!this.#geometryManager.canAddPoint()) {
|
|
211
|
-
this.#eventEngine.emitEvent(EVENTTYPE_DRAWING_TOOLS.MAXIMUM_POINTS, {
|
|
212
|
-
viewportId: this.viewport.id,
|
|
213
|
-
drawingToolsId: this.#uuid,
|
|
214
|
-
message: `The maximum amount of points (${this.#settings.geometry.maxPoints}) has been exceeded.`
|
|
215
|
-
});
|
|
216
|
-
throw new ShapeDiverViewerDrawingToolsError(`The maximum amount of points (${this.#settings.geometry.maxPoints}) has been exceeded.`);
|
|
217
|
-
}
|
|
218
|
-
this.#geometryManager.addPoint(index, position, temporary);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
public addPointTemporary(index: number, position?: vec3 | undefined): void {
|
|
222
|
-
this.addPoint(index, position, true);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Add a ray tracing intersection restriction to the drawing tool.
|
|
227
|
-
*
|
|
228
|
-
* @param planeProperties
|
|
229
|
-
* @returns
|
|
230
|
-
*/
|
|
231
|
-
public addRestriction(properties: RestrictionProperties, token?: string): string | undefined {
|
|
232
|
-
return this.#interactionManager.restrictionManager.addRestriction(properties, token);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
public canRedo(): boolean {
|
|
236
|
-
return this.#historyManager.canRedo();
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
public canUndo(): boolean {
|
|
240
|
-
return this.#historyManager.canUndo();
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
public cancel(): void {
|
|
244
|
-
if (this.#closed) return;
|
|
245
|
-
try {
|
|
246
|
-
this.#callbacks.onCancel();
|
|
247
|
-
} catch (e) {
|
|
248
|
-
throw new ShapeDiverViewerDrawingToolsError('An error occurred while cancelling the drawing tool.');
|
|
249
|
-
}
|
|
250
|
-
this.#eventEngine.emitEvent(EVENTTYPE_DRAWING_TOOLS.CANCEL, { viewportId: this.viewport.id, drawingToolsId: this.#uuid });
|
|
251
|
-
this.close();
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
public close(): void {
|
|
255
|
-
if (this.#closed) return;
|
|
256
|
-
if (this.#continuousRenderingFlag)
|
|
257
|
-
this.#viewport.removeFlag(this.#continuousRenderingFlag);
|
|
258
|
-
this.#eventManager.close();
|
|
259
|
-
this.#geometryMathManager.close();
|
|
260
|
-
this.#geometryManager.close();
|
|
261
|
-
this.#interactionManager.close();
|
|
262
|
-
this.#textVisualizationManager.close();
|
|
263
|
-
|
|
264
|
-
sceneTree.root.removeChild(this.#parentNode);
|
|
265
|
-
sceneTree.root.updateVersion(false, false);
|
|
266
|
-
this.#closed = true;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
public getPointsData(): PointsData {
|
|
270
|
-
return this.geometryState.getPointsData();
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
public keyPressed(key: string | string[]): boolean {
|
|
274
|
-
if (Array.isArray(key)) {
|
|
275
|
-
// check if one of the keys is pressed
|
|
276
|
-
let result = false;
|
|
277
|
-
for (let i = 0; i < key.length; i++) {
|
|
278
|
-
result = result || this.keyPressCheck(key[i]);
|
|
279
|
-
}
|
|
280
|
-
return result;
|
|
281
|
-
} else {
|
|
282
|
-
return this.keyPressCheck(key);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
public movePoint(index: number, position: vec3, temporary = false): void {
|
|
287
|
-
this.#geometryManager.movePoint(index, position, temporary);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
public movePointTemporary(index: number, position: vec3): void {
|
|
291
|
-
this.movePoint(index, position, true);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
public onDown(event: PointerEvent, ray: IRay): void {
|
|
295
|
-
if (this.closed) return;
|
|
296
|
-
this.#interactionManager.onDown(event, ray);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
public onKeyDown(event: KeyboardEvent): void {
|
|
300
|
-
if (this.closed) return;
|
|
301
|
-
|
|
302
|
-
this.#keysPressed[event.key] = true;
|
|
303
|
-
|
|
304
|
-
const insertKeyPressed = this.keyPressed(this.#settings.controls.insert);
|
|
305
|
-
const cancelKeyPressed = this.keyPressed(this.#settings.controls.cancel);
|
|
306
|
-
const confirmKeyPressed = this.keyPressed(this.#settings.controls.confirm);
|
|
307
|
-
const deleteKeyPressed = this.keyPressed(this.#settings.controls.delete);
|
|
308
|
-
const undoKeyPressed = this.keyPressed(this.#settings.controls.undo);
|
|
309
|
-
const redoKeyPressed = this.keyPressed(this.#settings.controls.redo);
|
|
310
|
-
|
|
311
|
-
/**
|
|
312
|
-
* IF CONFIRM KEY IS PRESSED
|
|
313
|
-
* - IF INSERTION IS ACTIVE, STOP INSERTION
|
|
314
|
-
* - IF INSERTION IS NOT ACTIVE, UPDATE DRAWING TOOL
|
|
315
|
-
*/
|
|
316
|
-
if (confirmKeyPressed) {
|
|
317
|
-
if (this.insertionActive) {
|
|
318
|
-
this.#interactionManager.stopInsertion();
|
|
319
|
-
this.update();
|
|
320
|
-
} else {
|
|
321
|
-
this.update();
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* IF CANCEL KEY IS PRESSED
|
|
327
|
-
* - IF INSERTION IS ACTIVE, STOP INSERTION
|
|
328
|
-
* - IF INSERTION IS NOT ACTIVE, CANCEL DRAWING TOOL
|
|
329
|
-
*/
|
|
330
|
-
if (cancelKeyPressed) {
|
|
331
|
-
if (this.insertionActive) {
|
|
332
|
-
this.#interactionManager.stopInsertion();
|
|
333
|
-
} else {
|
|
334
|
-
this.cancel();
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
/**
|
|
339
|
-
* IF INSERT KEY IS PRESSED
|
|
340
|
-
* - START INSERTION
|
|
341
|
-
*/
|
|
342
|
-
if (insertKeyPressed) {
|
|
343
|
-
this.startInsertion();
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* IF DELETE KEY IS PRESSED
|
|
348
|
-
* - DELETE SELECTION
|
|
349
|
-
*/
|
|
350
|
-
if (deleteKeyPressed) {
|
|
351
|
-
this.#interactionManager.deleteSelection();
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* IF UNDO KEY IS PRESSED
|
|
356
|
-
* - UNDO
|
|
357
|
-
*/
|
|
358
|
-
if (undoKeyPressed) {
|
|
359
|
-
this.#historyManager.undo();
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
/**
|
|
363
|
-
* IF REDO KEY IS PRESSED
|
|
364
|
-
* - REDO
|
|
365
|
-
*/
|
|
366
|
-
if (redoKeyPressed) {
|
|
367
|
-
this.#historyManager.redo();
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
public onKeyUp(event: KeyboardEvent): void {
|
|
372
|
-
if (this.closed) return;
|
|
373
|
-
this.#keysPressed[event.key] = false;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
public onMove(event: PointerEvent, ray: IRay): void {
|
|
377
|
-
if (this.closed) return;
|
|
378
|
-
if (!this.#continuousRenderingFlag)
|
|
379
|
-
this.#continuousRenderingFlag = this.#viewport.addFlag(FLAG_TYPE.CONTINUOUS_RENDERING);
|
|
380
|
-
this.#interactionManager.onMove(event, ray);
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
public onOut(): void {
|
|
384
|
-
if (this.closed) return;
|
|
385
|
-
this.#interactionManager.onOut();
|
|
386
|
-
if (this.#continuousRenderingFlag) {
|
|
387
|
-
this.#viewport.removeFlag(this.#continuousRenderingFlag);
|
|
388
|
-
this.#continuousRenderingFlag = undefined;
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
public onUp(): void {
|
|
393
|
-
if (this.closed) return;
|
|
394
|
-
this.#interactionManager.onUp();
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
public redo(): void {
|
|
398
|
-
this.#historyManager.redo();
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
/**
|
|
402
|
-
* Remove a point from the drawing tool.
|
|
403
|
-
*
|
|
404
|
-
* @param index
|
|
405
|
-
* @returns
|
|
406
|
-
*/
|
|
407
|
-
public removePoint(index: number, temporary = false): void {
|
|
408
|
-
if (this.#closed) return;
|
|
409
|
-
if (!this.geometryState.canRemovePoint()) {
|
|
410
|
-
this.#eventEngine.emitEvent(EVENTTYPE_DRAWING_TOOLS.MINIMUM_POINTS, {
|
|
411
|
-
viewportId: this.viewport.id,
|
|
412
|
-
drawingToolsId: this.#uuid,
|
|
413
|
-
message: `The minimum amount of points (${this.#settings.geometry.minPoints}) has not been met.`
|
|
414
|
-
});
|
|
415
|
-
throw new ShapeDiverViewerDrawingToolsError(`The minimum amount of points (${this.#settings.geometry.minPoints}) has not been met.`);
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
this.#geometryManager.removePoint(index, temporary);
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
public removePointTemporary(index: number): void {
|
|
422
|
-
this.removePoint(index, true);
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
public removePoints(indices: number[]): void {
|
|
426
|
-
if (this.#closed) return;
|
|
427
|
-
|
|
428
|
-
if (!this.geometryState.canRemovePoint(indices.length)) {
|
|
429
|
-
this.#eventEngine.emitEvent(EVENTTYPE_DRAWING_TOOLS.MINIMUM_POINTS, {
|
|
430
|
-
viewportId: this.viewport.id,
|
|
431
|
-
drawingToolsId: this.#uuid,
|
|
432
|
-
message: `The minimum amount of points (${this.#settings.geometry.minPoints}) has not been met.`
|
|
433
|
-
});
|
|
434
|
-
throw new ShapeDiverViewerDrawingToolsError(`The minimum amount of points (${this.#settings.geometry.minPoints}) has not been met.`);
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
this.#geometryManager.removePoints(indices);
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* Remove a restriction from the drawing tool.
|
|
442
|
-
*
|
|
443
|
-
* @param token
|
|
444
|
-
*/
|
|
445
|
-
public removeRestriction(token: string): void {
|
|
446
|
-
this.#interactionManager.restrictionManager.removeRestriction(token);
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
public resetMaterialIndices(): void {
|
|
450
|
-
this.#geometryManager.resetMaterialIndices();
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
public startInsertion() {
|
|
454
|
-
if (this.geometryState.canAddPoint()) {
|
|
455
|
-
this.#interactionManager.startInsertion();
|
|
456
|
-
} else {
|
|
457
|
-
this.#eventEngine.emitEvent(EVENTTYPE_DRAWING_TOOLS.MAXIMUM_POINTS, {
|
|
458
|
-
viewportId: this.viewport.id,
|
|
459
|
-
drawingToolsId: this.#uuid,
|
|
460
|
-
message: `The maximum amount of points (${this.#settings.geometry.maxPoints}) has been exceeded.`
|
|
461
|
-
});
|
|
462
|
-
throw new ShapeDiverViewerDrawingToolsError(`The maximum amount of points (${this.#settings.geometry.maxPoints}) has been exceeded.`);
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
public undo(): void {
|
|
467
|
-
this.#historyManager.undo();
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
public update(): PointsData | undefined {
|
|
471
|
-
if (this.#closed) return;
|
|
472
|
-
|
|
473
|
-
const pointsCount = this.geometryState.getPointCount();
|
|
474
|
-
if (this.#settings.geometry.minPoints !== undefined && pointsCount < this.#settings.geometry.minPoints) {
|
|
475
|
-
this.#eventEngine.emitEvent(EVENTTYPE_DRAWING_TOOLS.MINIMUM_POINTS, {
|
|
476
|
-
viewportId: this.viewport.id,
|
|
477
|
-
drawingToolsId: this.#uuid,
|
|
478
|
-
message: `The minimum amount of points (${this.#settings.geometry.minPoints}) has not been met. Current number of points: ${pointsCount}.`
|
|
479
|
-
});
|
|
480
|
-
throw new ShapeDiverViewerDrawingToolsError(`The minimum amount of points (${this.#settings.geometry.minPoints}) has not been met. Current number of points: ${pointsCount}.`);
|
|
481
|
-
} else if (this.#settings.geometry.maxPoints !== undefined && pointsCount > this.#settings.geometry.maxPoints) {
|
|
482
|
-
this.#eventEngine.emitEvent(EVENTTYPE_DRAWING_TOOLS.MAXIMUM_POINTS, {
|
|
483
|
-
viewportId: this.viewport.id,
|
|
484
|
-
drawingToolsId: this.#uuid,
|
|
485
|
-
message: `The maximum amount of points (${this.#settings.geometry.maxPoints}) has been exceeded. Current number of points: ${pointsCount}.`
|
|
486
|
-
});
|
|
487
|
-
throw new ShapeDiverViewerDrawingToolsError(`The maximum amount of points (${this.#settings.geometry.maxPoints}) has been exceeded. Current number of points: ${pointsCount}.`);
|
|
488
|
-
} else if(!(this.#settings.geometry.autoClose || this.#settings.geometry.close === this.#geometryManager.geometryState.closeLoop)) {
|
|
489
|
-
this.#eventEngine.emitEvent(EVENTTYPE_DRAWING_TOOLS.UNCLOSED_LOOP, {
|
|
490
|
-
viewportId: this.viewport.id,
|
|
491
|
-
drawingToolsId: this.#uuid,
|
|
492
|
-
message: 'The geometry is not closed, but is required to be closed.'
|
|
493
|
-
});
|
|
494
|
-
throw new ShapeDiverViewerDrawingToolsError('The geometry is not closed, but is required to be closed.');
|
|
495
|
-
} else{
|
|
496
|
-
const pointsData = this.geometryState.getPointsData();
|
|
497
|
-
try {
|
|
498
|
-
this.#callbacks.onUpdate(pointsData);
|
|
499
|
-
this.#eventEngine.emitEvent(EVENTTYPE_DRAWING_TOOLS.UPDATE, { viewportId: this.viewport.id, drawingToolsId: this.#uuid });
|
|
500
|
-
} catch (e) {
|
|
501
|
-
throw new ShapeDiverViewerDrawingToolsError('An error occurred while updating the drawing tool.');
|
|
502
|
-
}
|
|
503
|
-
if (this.#settings.general.closeOnUpdate) this.close();
|
|
504
|
-
return pointsData;
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
public updateMaterialIndex(index: number, materialIndex: MATERIAL_INDEX): void {
|
|
509
|
-
this.#geometryManager.updateMaterialIndex(index, materialIndex);
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
public updateTextVisualization(): void {
|
|
513
|
-
this.#textVisualizationManager.createPointLabels();
|
|
514
|
-
this.#textVisualizationManager.createDistanceLabels();
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
// #endregion Public Methods (28)
|
|
518
|
-
|
|
519
|
-
// #region Private Methods (2)
|
|
520
|
-
|
|
521
|
-
private cleanSettings(settingsOptional: SettingsOptional): Settings {
|
|
522
|
-
if (typeof settingsOptional === 'string') settingsOptional = JSON.parse(settingsOptional);
|
|
523
|
-
|
|
524
|
-
const settings: Settings = {
|
|
525
|
-
geometry: {
|
|
526
|
-
points: [],
|
|
527
|
-
mode: 'lines',
|
|
528
|
-
close: true,
|
|
529
|
-
autoClose: false
|
|
530
|
-
},
|
|
531
|
-
restrictions: {},
|
|
532
|
-
visualization: {
|
|
533
|
-
distanceMultiplicationFactor: settingsOptional.visualization?.distanceMultiplicationFactor === undefined ? 2 : settingsOptional.visualization.distanceMultiplicationFactor,
|
|
534
|
-
pointLabels: settingsOptional.visualization?.pointLabels === undefined ? false : settingsOptional.visualization.pointLabels,
|
|
535
|
-
distanceLabels: settingsOptional.visualization?.distanceLabels === undefined ? true : settingsOptional.visualization.distanceLabels,
|
|
536
|
-
points: settingsOptional.visualization?.points === undefined ? {
|
|
537
|
-
size_0: 15, size_1: 20, size_2: 15, size_3: 20, size_4: 15, size_5: 20,
|
|
538
|
-
color_0: '#0d44f0', color_1: '#197aeb', color_2: '#9e27d8', color_3: '#bc47fd', color_4: '#00ff78', color_5: '#00ff78'
|
|
539
|
-
} : settingsOptional.visualization.points,
|
|
540
|
-
lines: settingsOptional.visualization?.lines === undefined ? {
|
|
541
|
-
color: '#0d44f0'
|
|
542
|
-
} : settingsOptional.visualization.lines
|
|
543
|
-
},
|
|
544
|
-
controls: {
|
|
545
|
-
insert: settingsOptional.controls?.insert === undefined ? ['Insert', '+'] : settingsOptional.controls.insert,
|
|
546
|
-
delete: settingsOptional.controls?.delete === undefined ? ['Delete', '-'] : settingsOptional.controls.delete,
|
|
547
|
-
confirm: settingsOptional.controls?.confirm === undefined ? 'Enter' : settingsOptional.controls.confirm,
|
|
548
|
-
cancel: settingsOptional.controls?.cancel === undefined ? 'Escape' : settingsOptional.controls.cancel,
|
|
549
|
-
undo: settingsOptional.controls?.undo === undefined ? 'Control+z' : settingsOptional.controls.undo,
|
|
550
|
-
redo: settingsOptional.controls?.redo === undefined ? 'Control+y' : settingsOptional.controls.redo
|
|
551
|
-
},
|
|
552
|
-
general: {
|
|
553
|
-
autoStart: settingsOptional.general?.autoStart === undefined ? true : settingsOptional.general.autoStart,
|
|
554
|
-
autoUpdate: settingsOptional.general?.autoUpdate === undefined ? false : settingsOptional.general.autoUpdate,
|
|
555
|
-
closeOnUpdate: settingsOptional.general?.closeOnUpdate === undefined ? false : settingsOptional.general.closeOnUpdate,
|
|
556
|
-
displayUnit: settingsOptional.general?.displayUnit === undefined ? '' : settingsOptional.general.displayUnit
|
|
557
|
-
}
|
|
558
|
-
};
|
|
559
|
-
|
|
560
|
-
if (settingsOptional.geometry !== undefined) {
|
|
561
|
-
settings.geometry = {
|
|
562
|
-
points: settingsOptional.geometry.points === undefined ? [] : settingsOptional.geometry.points,
|
|
563
|
-
mode: settingsOptional.geometry.mode === 'points' ? 'points' : 'lines',
|
|
564
|
-
minPoints: settingsOptional.geometry.minPoints,
|
|
565
|
-
maxPoints: settingsOptional.geometry.maxPoints,
|
|
566
|
-
strictMinMaxPoints: settingsOptional.geometry.strictMinMaxPoints === undefined ? true : settingsOptional.geometry.strictMinMaxPoints,
|
|
567
|
-
close: settingsOptional.geometry.close === undefined ? true : settingsOptional.geometry.close,
|
|
568
|
-
autoClose: settingsOptional.geometry.autoClose === undefined ? true : settingsOptional.geometry.autoClose
|
|
569
|
-
};
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
const min = vec3.fromValues(Infinity, Infinity, Infinity);
|
|
573
|
-
const max = vec3.fromValues(-Infinity, -Infinity, -Infinity);
|
|
574
|
-
for (let i = 0; i < settings.geometry.points.length; i++) {
|
|
575
|
-
const point = settings.geometry.points[i];
|
|
576
|
-
|
|
577
|
-
min[0] = Math.min(min[0], point[0]);
|
|
578
|
-
min[1] = Math.min(min[1], point[1]);
|
|
579
|
-
min[2] = Math.min(min[2], point[2]);
|
|
580
|
-
|
|
581
|
-
max[0] = Math.max(max[0], point[0]);
|
|
582
|
-
max[1] = Math.max(max[1], point[1]);
|
|
583
|
-
max[2] = Math.max(max[2], point[2]);
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
if (settingsOptional.restrictions === undefined || Object.keys(settingsOptional.restrictions).length === 0) {
|
|
587
|
-
settings.restrictions['plane'] = { type: RESTRICTION_TYPE.PLANE };
|
|
588
|
-
} else {
|
|
589
|
-
settings.restrictions = settingsOptional.restrictions as { [key: string]: RestrictionProperties };
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
return settings;
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
private keyPressCheck(key: string): boolean {
|
|
596
|
-
const pressedKeys = Object.keys(this.#keysPressed).filter(key => this.#keysPressed[key] === true);
|
|
597
|
-
|
|
598
|
-
// check if it the only key that is pressed
|
|
599
|
-
if (key.includes('+') && key.length > 1) {
|
|
600
|
-
const keys = key.split('+');
|
|
601
|
-
|
|
602
|
-
// there are more keys pressed than the keys in the combination
|
|
603
|
-
if (keys.length !== pressedKeys.length) return false;
|
|
604
|
-
let result = true;
|
|
605
|
-
for (let i = 0; i < keys.length; i++)
|
|
606
|
-
result = result && (this.#keysPressed[keys[i]] || false);
|
|
607
|
-
|
|
608
|
-
return result;
|
|
609
|
-
} else {
|
|
610
|
-
// there are also other keys pressed
|
|
611
|
-
if (pressedKeys.length > 1) return false;
|
|
612
|
-
|
|
613
|
-
return this.#keysPressed[key] || false;
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
// #endregion Private Methods (2)
|
|
618
|
-
}
|