@itwin/core-markup 4.0.0-dev.8 → 4.0.0-dev.80

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 (49) hide show
  1. package/CHANGELOG.md +41 -1
  2. package/lib/cjs/Markup.d.ts +323 -310
  3. package/lib/cjs/Markup.d.ts.map +1 -1
  4. package/lib/cjs/Markup.js +451 -420
  5. package/lib/cjs/Markup.js.map +1 -1
  6. package/lib/cjs/MarkupTool.d.ts +38 -38
  7. package/lib/cjs/MarkupTool.js +88 -88
  8. package/lib/cjs/MarkupTool.js.map +1 -1
  9. package/lib/cjs/RedlineTool.d.ts +145 -145
  10. package/lib/cjs/RedlineTool.d.ts.map +1 -1
  11. package/lib/cjs/RedlineTool.js +498 -512
  12. package/lib/cjs/RedlineTool.js.map +1 -1
  13. package/lib/cjs/SelectTool.d.ts +126 -126
  14. package/lib/cjs/SelectTool.js +741 -741
  15. package/lib/cjs/SelectTool.js.map +1 -1
  16. package/lib/cjs/SvgJsExt.d.ts +85 -85
  17. package/lib/cjs/SvgJsExt.js +185 -185
  18. package/lib/cjs/TextEdit.d.ts +43 -43
  19. package/lib/cjs/TextEdit.js +196 -196
  20. package/lib/cjs/TextEdit.js.map +1 -1
  21. package/lib/cjs/Undo.d.ts +46 -46
  22. package/lib/cjs/Undo.js +168 -168
  23. package/lib/cjs/core-markup.d.ts +18 -18
  24. package/lib/cjs/core-markup.js +38 -34
  25. package/lib/cjs/core-markup.js.map +1 -1
  26. package/lib/esm/Markup.d.ts +323 -310
  27. package/lib/esm/Markup.d.ts.map +1 -1
  28. package/lib/esm/Markup.js +447 -415
  29. package/lib/esm/Markup.js.map +1 -1
  30. package/lib/esm/MarkupTool.d.ts +38 -38
  31. package/lib/esm/MarkupTool.js +85 -84
  32. package/lib/esm/MarkupTool.js.map +1 -1
  33. package/lib/esm/RedlineTool.d.ts +145 -145
  34. package/lib/esm/RedlineTool.d.ts.map +1 -1
  35. package/lib/esm/RedlineTool.js +494 -498
  36. package/lib/esm/RedlineTool.js.map +1 -1
  37. package/lib/esm/SelectTool.d.ts +126 -126
  38. package/lib/esm/SelectTool.js +735 -734
  39. package/lib/esm/SelectTool.js.map +1 -1
  40. package/lib/esm/SvgJsExt.d.ts +85 -85
  41. package/lib/esm/SvgJsExt.js +180 -180
  42. package/lib/esm/TextEdit.d.ts +43 -43
  43. package/lib/esm/TextEdit.js +193 -191
  44. package/lib/esm/TextEdit.js.map +1 -1
  45. package/lib/esm/Undo.d.ts +46 -46
  46. package/lib/esm/Undo.js +164 -164
  47. package/lib/esm/core-markup.d.ts +18 -18
  48. package/lib/esm/core-markup.js +22 -22
  49. package/package.json +19 -19
@@ -1,499 +1,495 @@
1
- /*---------------------------------------------------------------------------------------------
2
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
- * See LICENSE.md in the project root for license terms and full copyright notice.
4
- *--------------------------------------------------------------------------------------------*/
5
- /** @packageDocumentation
6
- * @module MarkupTools
7
- */
8
- // cspell:ignore rtmp stmp
9
- import { Point3d, Vector3d } from "@itwin/core-geometry";
10
- import { CoordinateLockOverrides, CoreTools, EventHandled, IModelApp, QuantityType, ToolAssistance, ToolAssistanceImage, ToolAssistanceInputMethod, } from "@itwin/core-frontend";
11
- import { SVG } from "@svgdotjs/svg.js";
12
- import { MarkupApp } from "./Markup";
13
- import { MarkupTool } from "./MarkupTool";
14
- /** Base class for tools that place new Markup elements
15
- * @public
16
- */
17
- export class RedlineTool extends MarkupTool {
18
- constructor() {
19
- super(...arguments);
20
- this._minPoints = 1;
21
- this._nRequiredPoints = 2;
22
- this._points = [];
23
- }
24
- onAdded(el) {
25
- const markup = this.markup;
26
- const undo = markup.undo;
27
- undo.performOperation(this.keyin, () => undo.onAdded(el));
28
- markup.selected.restart(el);
29
- }
30
- isComplete(_ev) { return this._points.length >= this._nRequiredPoints; }
31
- setupAndPromptForNextAction() {
32
- super.setupAndPromptForNextAction();
33
- this.markup.disablePick();
34
- IModelApp.toolAdmin.setCursor(0 === this._points.length ? IModelApp.viewManager.crossHairCursor : IModelApp.viewManager.dynamicsCursor);
35
- }
36
- createMarkup(_svgMarkup, _ev, _isDynamics) { }
37
- clearDynamicsMarkup(_isDynamics) { this.markup.svgDynamics.clear(); }
38
- async onRestartTool() { return this.exitTool(); } // Default to single shot and return control to select tool...
39
- async onCleanup() { this.clearDynamicsMarkup(false); }
40
- async onReinitialize() {
41
- this.clearDynamicsMarkup(false);
42
- return super.onReinitialize();
43
- }
44
- async onUndoPreviousStep() {
45
- return (0 === this._points.length) ? false : (this.onReinitialize(), true);
46
- }
47
- async onMouseMotion(ev) {
48
- if (undefined === ev.viewport || this._points.length < this._minPoints)
49
- return;
50
- this.clearDynamicsMarkup(true);
51
- this.createMarkup(this.markup.svgDynamics, ev, true);
52
- }
53
- async onDataButtonDown(ev) {
54
- if (undefined === ev.viewport)
55
- return EventHandled.No;
56
- this._points.push(MarkupApp.convertVpToVb(ev.viewPoint));
57
- if (!this.isComplete(ev)) {
58
- this.setupAndPromptForNextAction();
59
- return EventHandled.No;
60
- }
61
- this.createMarkup(this.markup.svgMarkup, ev, false);
62
- await this.onReinitialize();
63
- return EventHandled.No;
64
- }
65
- async onResetButtonUp(_ev) {
66
- await this.onReinitialize();
67
- return EventHandled.No;
68
- }
69
- provideToolAssistance(mainInstrKey, singlePoint = false) {
70
- const mainInstruction = ToolAssistance.createInstruction(this.iconSpec, IModelApp.localization.getLocalizedString(mainInstrKey));
71
- const mouseInstructions = [];
72
- const touchInstructions = [];
73
- const acceptMsg = CoreTools.translate("ElementSet.Inputs.AcceptPoint");
74
- const rejectMsg = CoreTools.translate("ElementSet.Inputs.Exit");
75
- if (!ToolAssistance.createTouchCursorInstructions(touchInstructions))
76
- touchInstructions.push(ToolAssistance.createInstruction(singlePoint ? ToolAssistanceImage.OneTouchTap : ToolAssistanceImage.OneTouchDrag, acceptMsg, false, ToolAssistanceInputMethod.Touch));
77
- mouseInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.LeftClick, acceptMsg, false, ToolAssistanceInputMethod.Mouse));
78
- touchInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.TwoTouchTap, rejectMsg, false, ToolAssistanceInputMethod.Touch));
79
- mouseInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.RightClick, rejectMsg, false, ToolAssistanceInputMethod.Mouse));
80
- const sections = [];
81
- sections.push(ToolAssistance.createSection(mouseInstructions, ToolAssistance.inputsLabel));
82
- sections.push(ToolAssistance.createSection(touchInstructions, ToolAssistance.inputsLabel));
83
- const instructions = ToolAssistance.createInstructions(mainInstruction, sections);
84
- IModelApp.notifications.setToolAssistance(instructions);
85
- }
86
- }
87
- /** Tool for placing Markup Lines
88
- * @public
89
- */
90
- export class LineTool extends RedlineTool {
91
- showPrompt() { this.provideToolAssistance(CoreTools.tools + (0 === this._points.length ? "ElementSet.Prompts.StartPoint" : "ElementSet.Prompts.EndPoint")); }
92
- createMarkup(svgMarkup, ev, isDynamics) {
93
- if (this._points.length < (isDynamics ? this._nRequiredPoints - 1 : this._nRequiredPoints))
94
- return;
95
- const start = this._points[0];
96
- const end = isDynamics ? MarkupApp.convertVpToVb(ev.viewPoint) : this._points[1];
97
- const element = svgMarkup.line(start.x, start.y, end.x, end.y);
98
- this.setCurrentStyle(element, false);
99
- if (!isDynamics)
100
- this.onAdded(element);
101
- }
102
- }
103
- LineTool.toolId = "Markup.Line";
104
- LineTool.iconSpec = "icon-line";
105
- /** Tool for placing Markup Rectangles
106
- * @public
107
- */
108
- export class RectangleTool extends RedlineTool {
109
- constructor(_cornerRadius) {
110
- super();
111
- this._cornerRadius = _cornerRadius;
112
- } // Specify radius to create a rectangle with rounded corners.
113
- showPrompt() { this.provideToolAssistance(CoreTools.tools + (0 === this._points.length ? "ElementSet.Prompts.StartCorner" : "ElementSet.Prompts.OppositeCorner")); }
114
- createMarkup(svgMarkup, ev, isDynamics) {
115
- if (this._points.length < (isDynamics ? this._nRequiredPoints - 1 : this._nRequiredPoints))
116
- return;
117
- const start = this._points[0];
118
- const end = isDynamics ? MarkupApp.convertVpToVb(ev.viewPoint) : this._points[1];
119
- const vec = start.vectorTo(end);
120
- const width = Math.abs(vec.x);
121
- const height = Math.abs(vec.y);
122
- if (width < 1 || height < 1)
123
- return;
124
- const offset = Point3d.create(vec.x < 0 ? end.x : start.x, vec.y < 0 ? end.y : start.y); // define location by corner points...
125
- const element = svgMarkup.rect(width, height).move(offset.x, offset.y);
126
- this.setCurrentStyle(element, true);
127
- if (undefined !== this._cornerRadius)
128
- element.radius(this._cornerRadius);
129
- if (!isDynamics)
130
- this.onAdded(element);
131
- }
132
- }
133
- RectangleTool.toolId = "Markup.Rectangle";
134
- RectangleTool.iconSpec = "icon-rectangle";
135
- /** Tool for placing Markup Polygons
136
- * @public
137
- */
138
- export class PolygonTool extends RedlineTool {
139
- constructor(_numSides) {
140
- super();
141
- this._numSides = _numSides;
142
- } // Specify number of polygon sides. Default if undefined is 5.
143
- showPrompt() { this.provideToolAssistance(MarkupTool.toolKey + (0 === this._points.length ? "Polygon.Prompts.FirstPoint" : "Polygon.Prompts.NextPoint")); }
144
- getPoints(points, center, edge, numSides, inscribe) {
145
- if (numSides < 3 || numSides > 100)
146
- return false;
147
- let radius = center.distanceXY(edge);
148
- if (radius < 1)
149
- return false;
150
- const delta = (Math.PI * 2.0) / numSides;
151
- const vec = center.vectorTo(edge);
152
- let angle = Vector3d.unitX().planarRadiansTo(vec, Vector3d.unitZ());
153
- if (!inscribe) {
154
- const theta = delta * 0.5;
155
- angle -= theta;
156
- radius /= Math.cos(theta);
157
- }
158
- const rtmp = Point3d.create();
159
- const stmp = Point3d.create();
160
- for (let i = 0; i < numSides; i++, angle += delta) {
161
- rtmp.x = radius * Math.cos(angle);
162
- rtmp.y = radius * Math.sin(angle);
163
- rtmp.z = 0.0;
164
- center.plus(rtmp, stmp);
165
- points.push(stmp.x);
166
- points.push(stmp.y);
167
- }
168
- return true;
169
- }
170
- createMarkup(svgMarkup, ev, isDynamics) {
171
- if (this._points.length < (isDynamics ? this._nRequiredPoints - 1 : this._nRequiredPoints))
172
- return;
173
- const center = this._points[0];
174
- const edge = isDynamics ? MarkupApp.convertVpToVb(ev.viewPoint) : this._points[1];
175
- const pts = [];
176
- if (!this.getPoints(pts, center, edge, undefined !== this._numSides ? this._numSides : 5, true))
177
- return;
178
- const element = svgMarkup.polygon(pts);
179
- this.setCurrentStyle(element, true);
180
- if (!isDynamics)
181
- this.onAdded(element);
182
- }
183
- }
184
- PolygonTool.toolId = "Markup.Polygon";
185
- PolygonTool.iconSpec = "icon-polygon";
186
- /** Tool for placing Markup Clouds
187
- * @public
188
- */
189
- export class CloudTool extends RedlineTool {
190
- showPrompt() { this.provideToolAssistance(CoreTools.tools + (0 === this._points.length ? "ElementSet.Prompts.StartCorner" : "ElementSet.Prompts.OppositeCorner")); }
191
- createMarkup(svgMarkup, ev, isDynamics) {
192
- if (this._points.length < (isDynamics ? this._nRequiredPoints - 1 : this._nRequiredPoints))
193
- return;
194
- const start = this._points[0];
195
- const end = isDynamics ? MarkupApp.convertVpToVb(ev.viewPoint) : this._points[1];
196
- const vec = start.vectorTo(end);
197
- const width = Math.abs(vec.x);
198
- const height = Math.abs(vec.y);
199
- if (width < 10 || height < 10)
200
- return;
201
- if (undefined === this._cloud) {
202
- this._cloud = svgMarkup.path(MarkupApp.props.active.cloud.path);
203
- }
204
- else if (!isDynamics) {
205
- svgMarkup.add(this._cloud);
206
- }
207
- const offset = Point3d.create(vec.x < 0 ? end.x : start.x, vec.y < 0 ? end.y : start.y); // define location by corner points...
208
- this._cloud.move(offset.x, offset.y);
209
- this._cloud.width(width);
210
- this._cloud.height(height);
211
- this.setCurrentStyle(this._cloud, true);
212
- if (!isDynamics)
213
- this.onAdded(this._cloud);
214
- }
215
- clearDynamicsMarkup(isDynamics) {
216
- if (!isDynamics)
217
- super.clearDynamicsMarkup(isDynamics); // For dynamics we don't create a new cloud each frame, we just set the width/height...
218
- }
219
- }
220
- CloudTool.toolId = "Markup.Cloud";
221
- CloudTool.iconSpec = "icon-cloud";
222
- /** Tool for placing Markup Circles
223
- * @public
224
- */
225
- export class CircleTool extends RedlineTool {
226
- showPrompt() { this.provideToolAssistance(MarkupTool.toolKey + (0 === this._points.length ? "Circle.Prompts.FirstPoint" : "Circle.Prompts.NextPoint")); }
227
- createMarkup(svgMarkup, ev, isDynamics) {
228
- if (this._points.length < (isDynamics ? this._nRequiredPoints - 1 : this._nRequiredPoints))
229
- return;
230
- const start = this._points[0];
231
- const end = isDynamics ? MarkupApp.convertVpToVb(ev.viewPoint) : this._points[1];
232
- const radius = start.distanceXY(end);
233
- if (radius < 1)
234
- return;
235
- const element = svgMarkup.circle(radius * 2.0).center(start.x, start.y);
236
- this.setCurrentStyle(element, true);
237
- if (!isDynamics)
238
- this.onAdded(element);
239
- }
240
- }
241
- CircleTool.toolId = "Markup.Circle";
242
- CircleTool.iconSpec = "icon-circle";
243
- /** Tool for placing Markup Ellipses
244
- * @public
245
- */
246
- export class EllipseTool extends RedlineTool {
247
- showPrompt() { this.provideToolAssistance(CoreTools.tools + (0 === this._points.length ? "ElementSet.Prompts.StartCorner" : "ElementSet.Prompts.OppositeCorner")); }
248
- createMarkup(svgMarkup, ev, isDynamics) {
249
- if (this._points.length < (isDynamics ? this._nRequiredPoints - 1 : this._nRequiredPoints))
250
- return;
251
- const start = this._points[0];
252
- const end = isDynamics ? MarkupApp.convertVpToVb(ev.viewPoint) : this._points[1];
253
- const vec = start.vectorTo(end);
254
- const width = Math.abs(vec.x);
255
- const height = Math.abs(vec.y);
256
- if (width < 1 || height < 1)
257
- return;
258
- const offset = Point3d.create(vec.x < 0 ? end.x : start.x, vec.y < 0 ? end.y : start.y); // define location by corner points...
259
- const element = svgMarkup.ellipse(width, height).move(offset.x, offset.y);
260
- this.setCurrentStyle(element, true);
261
- if (!isDynamics)
262
- this.onAdded(element);
263
- }
264
- }
265
- EllipseTool.toolId = "Markup.Ellipse";
266
- EllipseTool.iconSpec = "icon-ellipse";
267
- /** Tool for placing Markup Arrows
268
- * @public
269
- */
270
- export class ArrowTool extends RedlineTool {
271
- /** ctor for ArrowTool
272
- * @param _arrowPos "start", "end", or "both". If undefined = "end".
273
- */
274
- constructor(_arrowPos) {
275
- super();
276
- this._arrowPos = _arrowPos;
277
- }
278
- showPrompt() { this.provideToolAssistance(CoreTools.tools + (0 === this._points.length ? "ElementSet.Prompts.StartPoint" : "ElementSet.Prompts.EndPoint")); }
279
- getOrCreateArrowMarker(color) {
280
- // NOTE: Flashing doesn't currently affect markers, need support for "context-stroke" and "context-fill". For now encode color in name...
281
- const arrowProps = MarkupApp.props.active.arrow;
282
- const arrowLength = arrowProps.length;
283
- const arrowWidth = arrowProps.width;
284
- const arrowMarkerId = `ArrowMarker${arrowLength}x${arrowWidth}-${color}`;
285
- let marker = SVG(`#${arrowMarkerId}`);
286
- if (null === marker) {
287
- marker = this.markup.svgMarkup.marker(arrowLength, arrowWidth).id(arrowMarkerId);
288
- marker.polygon([0, 0, arrowLength, arrowWidth * 0.5, 0, arrowWidth]);
289
- marker.attr("orient", "auto-start-reverse");
290
- marker.attr("overflow", "visible"); // Don't clip the stroke that is being applied to allow the specified start/end to be used directly while hiding the arrow tail fully under the arrow head...
291
- marker.attr("refX", arrowLength);
292
- marker.css({ stroke: color, fill: color });
293
- }
294
- return marker;
295
- }
296
- createMarkup(svgMarkup, ev, isDynamics) {
297
- if (this._points.length < (isDynamics ? this._nRequiredPoints - 1 : this._nRequiredPoints))
298
- return;
299
- const start = this._points[0];
300
- const end = isDynamics ? MarkupApp.convertVpToVb(ev.viewPoint) : this._points[1];
301
- const vec = start.vectorTo(end);
302
- if (!vec.normalizeInPlace())
303
- return;
304
- const element = svgMarkup.line(start.x, start.y, end.x, end.y);
305
- this.setCurrentStyle(element, false);
306
- const marker = this.getOrCreateArrowMarker(element.css("stroke"));
307
- const addToStart = ("start" === this._arrowPos || "both" === this._arrowPos);
308
- const addToEnd = ("end" === this._arrowPos || "both" === this._arrowPos);
309
- if (addToStart)
310
- element.marker("start", marker);
311
- if (addToEnd || !addToStart)
312
- element.marker("end", marker);
313
- if (!isDynamics)
314
- this.onAdded(element);
315
- }
316
- }
317
- ArrowTool.toolId = "Markup.Arrow";
318
- ArrowTool.iconSpec = "icon-callout";
319
- /** Tool for measuring distances and placing Markups of them
320
- * @public
321
- */
322
- export class DistanceTool extends ArrowTool {
323
- constructor() {
324
- super(...arguments);
325
- this._startPointWorld = new Point3d();
326
- }
327
- showPrompt() { this.provideToolAssistance(CoreTools.tools + (0 === this._points.length ? "ElementSet.Prompts.StartPoint" : "ElementSet.Prompts.EndPoint")); }
328
- setupAndPromptForNextAction() {
329
- IModelApp.accuSnap.enableSnap(true);
330
- IModelApp.toolAdmin.toolState.coordLockOvr = CoordinateLockOverrides.None;
331
- super.setupAndPromptForNextAction();
332
- }
333
- getFormattedDistance(distance) {
334
- const formatterSpec = IModelApp.quantityFormatter.findFormatterSpecByQuantityType(QuantityType.Length);
335
- if (undefined === formatterSpec)
336
- return undefined;
337
- return IModelApp.quantityFormatter.formatQuantity(distance, formatterSpec);
338
- }
339
- createMarkup(svgMarkup, ev, isDynamics) {
340
- if (this._points.length < (isDynamics ? this._nRequiredPoints - 1 : this._nRequiredPoints))
341
- return;
342
- const start = this._points[0];
343
- const end = isDynamics ? MarkupApp.convertVpToVb(ev.viewPoint) : this._points[1];
344
- const vec = start.vectorTo(end);
345
- if (!vec.normalizeInPlace())
346
- return;
347
- const formatterSpec = IModelApp.quantityFormatter.findFormatterSpecByQuantityType(QuantityType.Length);
348
- if (undefined === formatterSpec)
349
- return;
350
- const distanceLine = svgMarkup.line(start.x, start.y, end.x, end.y);
351
- this.setCurrentStyle(distanceLine, false);
352
- const marker = this.getOrCreateArrowMarker(distanceLine.css("stroke"));
353
- distanceLine.marker("start", marker);
354
- distanceLine.marker("end", marker);
355
- const loc = start.interpolate(0.5, end);
356
- const distance = IModelApp.quantityFormatter.formatQuantity(this._startPointWorld.distance(ev.point), formatterSpec);
357
- const text = svgMarkup.plain(distance).addClass(MarkupApp.textClass).attr("text-anchor", "middle").translate(loc.x, loc.y);
358
- this.setCurrentTextStyle(text);
359
- const textWithBg = this.createBoxedText(svgMarkup, text);
360
- if (!isDynamics) {
361
- const markup = this.markup;
362
- const undo = markup.undo;
363
- undo.performOperation(this.keyin, () => {
364
- undo.onAdded(distanceLine);
365
- undo.onAdded(textWithBg);
366
- });
367
- markup.selected.restart(textWithBg); // Select text+box so that user can freely position relative to distance line...
368
- }
369
- }
370
- async onDataButtonDown(ev) {
371
- if (undefined === await IModelApp.quantityFormatter.getFormatterSpecByQuantityType(QuantityType.Length)) {
372
- await this.onReinitialize();
373
- return EventHandled.No;
374
- }
375
- if (0 === this._points.length)
376
- this._startPointWorld.setFrom(ev.point);
377
- return super.onDataButtonDown(ev);
378
- }
379
- }
380
- DistanceTool.toolId = "Markup.Distance";
381
- DistanceTool.iconSpec = "icon-distance";
382
- /** Tool for placing Markup freehand sketches
383
- * @public
384
- */
385
- export class SketchTool extends RedlineTool {
386
- constructor() {
387
- super(...arguments);
388
- this._minDistSquared = 100;
389
- }
390
- showPrompt() { this.provideToolAssistance(CoreTools.tools + (0 === this._points.length ? "ElementSet.Prompts.StartPoint" : "ElementSet.Prompts.EndPoint")); }
391
- createMarkup(svgMarkup, ev, isDynamics) {
392
- if (this._points.length < (isDynamics ? this._nRequiredPoints - 1 : this._nRequiredPoints))
393
- return;
394
- const pts = [];
395
- const evPt = MarkupApp.convertVpToVb(ev.viewPoint);
396
- this._points.forEach((pt) => {
397
- pts.push(pt.x);
398
- pts.push(pt.y);
399
- });
400
- if (isDynamics && !evPt.isAlmostEqualXY(this._points[this._points.length - 1])) {
401
- pts.push(evPt.x);
402
- pts.push(evPt.y);
403
- }
404
- const isClosed = (this._points.length > 2 && (this._points[0].distanceSquaredXY(isDynamics ? evPt : this._points[this._points.length - 1]) < this._minDistSquared * 2));
405
- const element = isClosed ? svgMarkup.polygon(pts) : svgMarkup.polyline(pts);
406
- this.setCurrentStyle(element, isClosed);
407
- if (!isDynamics)
408
- this.onAdded(element);
409
- }
410
- async onMouseMotion(ev) {
411
- const evPt = MarkupApp.convertVpToVb(ev.viewPoint);
412
- if (undefined !== ev.viewport && this._points.length > 0 && evPt.distanceSquaredXY(this._points[this._points.length - 1]) > this._minDistSquared)
413
- this._points.push(evPt);
414
- return super.onMouseMotion(ev);
415
- }
416
- }
417
- SketchTool.toolId = "Markup.Sketch";
418
- SketchTool.iconSpec = "icon-draw";
419
- /** Tool for placing SVG symbols on a Markup
420
- * @public
421
- */
422
- export class SymbolTool extends RedlineTool {
423
- constructor(_symbolData, _applyCurrentStyle) {
424
- super();
425
- this._symbolData = _symbolData;
426
- this._applyCurrentStyle = _applyCurrentStyle;
427
- }
428
- async onInstall() {
429
- if (undefined === this._symbolData)
430
- return false;
431
- return super.onInstall();
432
- }
433
- showPrompt() {
434
- this.provideToolAssistance(0 === this._points.length ? (`${MarkupTool.toolKey}Symbol.Prompts.FirstPoint`) : `${CoreTools.tools}ElementSet.Prompts.OppositeCorner`, true);
435
- }
436
- createMarkup(svgMarkup, ev, isDynamics) {
437
- if (undefined === this._symbolData)
438
- return;
439
- if (this._points.length < this._minPoints)
440
- return;
441
- const start = this._points[0];
442
- const end = isDynamics ? MarkupApp.convertVpToVb(ev.viewPoint) : this._points[this._points.length - 1];
443
- const vec = start.vectorTo(end);
444
- const width = Math.abs(vec.x);
445
- const height = Math.abs(vec.y);
446
- if ((width < 10 || height < 10) && (isDynamics || this._points.length !== this._minPoints))
447
- return;
448
- if (undefined === this._symbol) {
449
- const symbol = svgMarkup.group().svg(this._symbolData); // creating group instead of using symbol because of inability to flash/hilite multi-color symbol instance...
450
- if (0 === symbol.children().length) {
451
- symbol.remove();
452
- this._symbolData = undefined;
453
- }
454
- try {
455
- symbol.flatten(symbol);
456
- }
457
- catch { }
458
- this._symbol = symbol;
459
- }
460
- else if (!isDynamics) {
461
- svgMarkup.add(this._symbol);
462
- }
463
- const offset = Point3d.create(vec.x < 0 ? end.x : start.x, vec.y < 0 ? end.y : start.y); // define location by corner points...
464
- if (!isDynamics && this._points.length === this._minPoints)
465
- this._symbol.size(ev.viewport.viewRect.width * 0.1).center(offset.x, offset.y);
466
- else if (!ev.isShiftKey)
467
- this._symbol.size(width).move(offset.x, offset.y);
468
- else
469
- this._symbol.size(width, height).move(offset.x, offset.y);
470
- if (this._applyCurrentStyle) {
471
- const active = MarkupApp.props.active; // Apply color and transparency only; using active stroke-width, etc. for pre-defined symbols is likely undesirable...
472
- this._symbol.forElementsOfGroup((child) => {
473
- const css = window.getComputedStyle(child.node);
474
- const toValue = (val, newVal) => (!val || val === "none") ? "none" : newVal;
475
- child.css({ "fill": toValue(css.fill, active.element.fill), "stroke": toValue(css.stroke, active.element.stroke), "fill-opacity": active.element["fill-opacity"], "stroke-opacity": active.element["stroke-opacity"] });
476
- });
477
- }
478
- if (!isDynamics)
479
- this.onAdded(this._symbol);
480
- }
481
- async onDataButtonUp(ev) {
482
- if (undefined === ev.viewport || this._points.length !== this._minPoints)
483
- return EventHandled.No;
484
- this.createMarkup(this.markup.svgMarkup, ev, false);
485
- await this.onReinitialize();
486
- return EventHandled.No;
487
- }
488
- async onResetButtonUp(_ev) {
489
- await this.onReinitialize();
490
- return EventHandled.No;
491
- }
492
- clearDynamicsMarkup(isDynamics) {
493
- if (!isDynamics)
494
- super.clearDynamicsMarkup(isDynamics); // For dynamics we don't create a new symbol each frame, we just set the width/height...
495
- }
496
- }
497
- SymbolTool.toolId = "Markup.Symbol";
498
- SymbolTool.iconSpec = "icon-symbol";
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ /** @packageDocumentation
6
+ * @module MarkupTools
7
+ */
8
+ // cspell:ignore rtmp stmp
9
+ import { Point3d, Vector3d } from "@itwin/core-geometry";
10
+ import { CoordinateLockOverrides, CoreTools, EventHandled, IModelApp, QuantityType, ToolAssistance, ToolAssistanceImage, ToolAssistanceInputMethod, } from "@itwin/core-frontend";
11
+ import { MarkupApp } from "./Markup";
12
+ import { MarkupTool } from "./MarkupTool";
13
+ /** Base class for tools that place new Markup elements
14
+ * @public
15
+ */
16
+ export class RedlineTool extends MarkupTool {
17
+ constructor() {
18
+ super(...arguments);
19
+ this._minPoints = 1;
20
+ this._nRequiredPoints = 2;
21
+ this._points = [];
22
+ }
23
+ onAdded(el) {
24
+ const markup = this.markup;
25
+ const undo = markup.undo;
26
+ undo.performOperation(this.keyin, () => undo.onAdded(el));
27
+ markup.selected.restart(el);
28
+ }
29
+ isComplete(_ev) { return this._points.length >= this._nRequiredPoints; }
30
+ setupAndPromptForNextAction() {
31
+ super.setupAndPromptForNextAction();
32
+ this.markup.disablePick();
33
+ IModelApp.toolAdmin.setCursor(0 === this._points.length ? IModelApp.viewManager.crossHairCursor : IModelApp.viewManager.dynamicsCursor);
34
+ }
35
+ createMarkup(_svgMarkup, _ev, _isDynamics) { }
36
+ clearDynamicsMarkup(_isDynamics) { this.markup.svgDynamics.clear(); }
37
+ async onRestartTool() { return this.exitTool(); } // Default to single shot and return control to select tool...
38
+ async onCleanup() { this.clearDynamicsMarkup(false); }
39
+ async onReinitialize() {
40
+ this.clearDynamicsMarkup(false);
41
+ return super.onReinitialize();
42
+ }
43
+ async onUndoPreviousStep() {
44
+ return (0 === this._points.length) ? false : (this.onReinitialize(), true);
45
+ }
46
+ async onMouseMotion(ev) {
47
+ if (undefined === ev.viewport || this._points.length < this._minPoints)
48
+ return;
49
+ this.clearDynamicsMarkup(true);
50
+ this.createMarkup(this.markup.svgDynamics, ev, true);
51
+ }
52
+ async onDataButtonDown(ev) {
53
+ if (undefined === ev.viewport)
54
+ return EventHandled.No;
55
+ this._points.push(MarkupApp.convertVpToVb(ev.viewPoint));
56
+ if (!this.isComplete(ev)) {
57
+ this.setupAndPromptForNextAction();
58
+ return EventHandled.No;
59
+ }
60
+ this.createMarkup(this.markup.svgMarkup, ev, false);
61
+ await this.onReinitialize();
62
+ return EventHandled.No;
63
+ }
64
+ async onResetButtonUp(_ev) {
65
+ await this.onReinitialize();
66
+ return EventHandled.No;
67
+ }
68
+ provideToolAssistance(mainInstrKey, singlePoint = false) {
69
+ const mainInstruction = ToolAssistance.createInstruction(this.iconSpec, IModelApp.localization.getLocalizedString(mainInstrKey));
70
+ const mouseInstructions = [];
71
+ const touchInstructions = [];
72
+ const acceptMsg = CoreTools.translate("ElementSet.Inputs.AcceptPoint");
73
+ const rejectMsg = CoreTools.translate("ElementSet.Inputs.Exit");
74
+ if (!ToolAssistance.createTouchCursorInstructions(touchInstructions))
75
+ touchInstructions.push(ToolAssistance.createInstruction(singlePoint ? ToolAssistanceImage.OneTouchTap : ToolAssistanceImage.OneTouchDrag, acceptMsg, false, ToolAssistanceInputMethod.Touch));
76
+ mouseInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.LeftClick, acceptMsg, false, ToolAssistanceInputMethod.Mouse));
77
+ touchInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.TwoTouchTap, rejectMsg, false, ToolAssistanceInputMethod.Touch));
78
+ mouseInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.RightClick, rejectMsg, false, ToolAssistanceInputMethod.Mouse));
79
+ const sections = [];
80
+ sections.push(ToolAssistance.createSection(mouseInstructions, ToolAssistance.inputsLabel));
81
+ sections.push(ToolAssistance.createSection(touchInstructions, ToolAssistance.inputsLabel));
82
+ const instructions = ToolAssistance.createInstructions(mainInstruction, sections);
83
+ IModelApp.notifications.setToolAssistance(instructions);
84
+ }
85
+ }
86
+ /** Tool for placing Markup Lines
87
+ * @public
88
+ */
89
+ class LineTool extends RedlineTool {
90
+ showPrompt() { this.provideToolAssistance(CoreTools.tools + (0 === this._points.length ? "ElementSet.Prompts.StartPoint" : "ElementSet.Prompts.EndPoint")); }
91
+ createMarkup(svgMarkup, ev, isDynamics) {
92
+ if (this._points.length < (isDynamics ? this._nRequiredPoints - 1 : this._nRequiredPoints))
93
+ return;
94
+ const start = this._points[0];
95
+ const end = isDynamics ? MarkupApp.convertVpToVb(ev.viewPoint) : this._points[1];
96
+ const element = svgMarkup.line(start.x, start.y, end.x, end.y);
97
+ this.setCurrentStyle(element, false);
98
+ if (!isDynamics)
99
+ this.onAdded(element);
100
+ }
101
+ }
102
+ LineTool.toolId = "Markup.Line";
103
+ LineTool.iconSpec = "icon-line";
104
+ export { LineTool };
105
+ /** Tool for placing Markup Rectangles
106
+ * @public
107
+ */
108
+ class RectangleTool extends RedlineTool {
109
+ constructor(_cornerRadius) {
110
+ super();
111
+ this._cornerRadius = _cornerRadius;
112
+ } // Specify radius to create a rectangle with rounded corners.
113
+ showPrompt() { this.provideToolAssistance(CoreTools.tools + (0 === this._points.length ? "ElementSet.Prompts.StartCorner" : "ElementSet.Prompts.OppositeCorner")); }
114
+ createMarkup(svgMarkup, ev, isDynamics) {
115
+ if (this._points.length < (isDynamics ? this._nRequiredPoints - 1 : this._nRequiredPoints))
116
+ return;
117
+ const start = this._points[0];
118
+ const end = isDynamics ? MarkupApp.convertVpToVb(ev.viewPoint) : this._points[1];
119
+ const vec = start.vectorTo(end);
120
+ const width = Math.abs(vec.x);
121
+ const height = Math.abs(vec.y);
122
+ if (width < 1 || height < 1)
123
+ return;
124
+ const offset = Point3d.create(vec.x < 0 ? end.x : start.x, vec.y < 0 ? end.y : start.y); // define location by corner points...
125
+ const element = svgMarkup.rect(width, height).move(offset.x, offset.y);
126
+ this.setCurrentStyle(element, true);
127
+ if (undefined !== this._cornerRadius)
128
+ element.radius(this._cornerRadius);
129
+ if (!isDynamics)
130
+ this.onAdded(element);
131
+ }
132
+ }
133
+ RectangleTool.toolId = "Markup.Rectangle";
134
+ RectangleTool.iconSpec = "icon-rectangle";
135
+ export { RectangleTool };
136
+ /** Tool for placing Markup Polygons
137
+ * @public
138
+ */
139
+ class PolygonTool extends RedlineTool {
140
+ constructor(_numSides) {
141
+ super();
142
+ this._numSides = _numSides;
143
+ } // Specify number of polygon sides. Default if undefined is 5.
144
+ showPrompt() { this.provideToolAssistance(MarkupTool.toolKey + (0 === this._points.length ? "Polygon.Prompts.FirstPoint" : "Polygon.Prompts.NextPoint")); }
145
+ getPoints(points, center, edge, numSides, inscribe) {
146
+ if (numSides < 3 || numSides > 100)
147
+ return false;
148
+ let radius = center.distanceXY(edge);
149
+ if (radius < 1)
150
+ return false;
151
+ const delta = (Math.PI * 2.0) / numSides;
152
+ const vec = center.vectorTo(edge);
153
+ let angle = Vector3d.unitX().planarRadiansTo(vec, Vector3d.unitZ());
154
+ if (!inscribe) {
155
+ const theta = delta * 0.5;
156
+ angle -= theta;
157
+ radius /= Math.cos(theta);
158
+ }
159
+ const rtmp = Point3d.create();
160
+ const stmp = Point3d.create();
161
+ for (let i = 0; i < numSides; i++, angle += delta) {
162
+ rtmp.x = radius * Math.cos(angle);
163
+ rtmp.y = radius * Math.sin(angle);
164
+ rtmp.z = 0.0;
165
+ center.plus(rtmp, stmp);
166
+ points.push(stmp.x);
167
+ points.push(stmp.y);
168
+ }
169
+ return true;
170
+ }
171
+ createMarkup(svgMarkup, ev, isDynamics) {
172
+ if (this._points.length < (isDynamics ? this._nRequiredPoints - 1 : this._nRequiredPoints))
173
+ return;
174
+ const center = this._points[0];
175
+ const edge = isDynamics ? MarkupApp.convertVpToVb(ev.viewPoint) : this._points[1];
176
+ const pts = [];
177
+ if (!this.getPoints(pts, center, edge, undefined !== this._numSides ? this._numSides : 5, true))
178
+ return;
179
+ const element = svgMarkup.polygon(pts);
180
+ this.setCurrentStyle(element, true);
181
+ if (!isDynamics)
182
+ this.onAdded(element);
183
+ }
184
+ }
185
+ PolygonTool.toolId = "Markup.Polygon";
186
+ PolygonTool.iconSpec = "icon-polygon";
187
+ export { PolygonTool };
188
+ /** Tool for placing Markup Clouds
189
+ * @public
190
+ */
191
+ class CloudTool extends RedlineTool {
192
+ showPrompt() { this.provideToolAssistance(CoreTools.tools + (0 === this._points.length ? "ElementSet.Prompts.StartCorner" : "ElementSet.Prompts.OppositeCorner")); }
193
+ createMarkup(svgMarkup, ev, isDynamics) {
194
+ if (this._points.length < (isDynamics ? this._nRequiredPoints - 1 : this._nRequiredPoints))
195
+ return;
196
+ const start = this._points[0];
197
+ const end = isDynamics ? MarkupApp.convertVpToVb(ev.viewPoint) : this._points[1];
198
+ const vec = start.vectorTo(end);
199
+ const width = Math.abs(vec.x);
200
+ const height = Math.abs(vec.y);
201
+ if (width < 10 || height < 10)
202
+ return;
203
+ if (undefined === this._cloud) {
204
+ this._cloud = svgMarkup.path(MarkupApp.props.active.cloud.path);
205
+ }
206
+ else if (!isDynamics) {
207
+ svgMarkup.add(this._cloud);
208
+ }
209
+ const offset = Point3d.create(vec.x < 0 ? end.x : start.x, vec.y < 0 ? end.y : start.y); // define location by corner points...
210
+ this._cloud.move(offset.x, offset.y);
211
+ this._cloud.width(width);
212
+ this._cloud.height(height);
213
+ this.setCurrentStyle(this._cloud, true);
214
+ if (!isDynamics)
215
+ this.onAdded(this._cloud);
216
+ }
217
+ clearDynamicsMarkup(isDynamics) {
218
+ if (!isDynamics)
219
+ super.clearDynamicsMarkup(isDynamics); // For dynamics we don't create a new cloud each frame, we just set the width/height...
220
+ }
221
+ }
222
+ CloudTool.toolId = "Markup.Cloud";
223
+ CloudTool.iconSpec = "icon-cloud";
224
+ export { CloudTool };
225
+ /** Tool for placing Markup Circles
226
+ * @public
227
+ */
228
+ class CircleTool extends RedlineTool {
229
+ showPrompt() { this.provideToolAssistance(MarkupTool.toolKey + (0 === this._points.length ? "Circle.Prompts.FirstPoint" : "Circle.Prompts.NextPoint")); }
230
+ createMarkup(svgMarkup, ev, isDynamics) {
231
+ if (this._points.length < (isDynamics ? this._nRequiredPoints - 1 : this._nRequiredPoints))
232
+ return;
233
+ const start = this._points[0];
234
+ const end = isDynamics ? MarkupApp.convertVpToVb(ev.viewPoint) : this._points[1];
235
+ const radius = start.distanceXY(end);
236
+ if (radius < 1)
237
+ return;
238
+ const element = svgMarkup.circle(radius * 2.0).center(start.x, start.y);
239
+ this.setCurrentStyle(element, true);
240
+ if (!isDynamics)
241
+ this.onAdded(element);
242
+ }
243
+ }
244
+ CircleTool.toolId = "Markup.Circle";
245
+ CircleTool.iconSpec = "icon-circle";
246
+ export { CircleTool };
247
+ /** Tool for placing Markup Ellipses
248
+ * @public
249
+ */
250
+ class EllipseTool extends RedlineTool {
251
+ showPrompt() { this.provideToolAssistance(CoreTools.tools + (0 === this._points.length ? "ElementSet.Prompts.StartCorner" : "ElementSet.Prompts.OppositeCorner")); }
252
+ createMarkup(svgMarkup, ev, isDynamics) {
253
+ if (this._points.length < (isDynamics ? this._nRequiredPoints - 1 : this._nRequiredPoints))
254
+ return;
255
+ const start = this._points[0];
256
+ const end = isDynamics ? MarkupApp.convertVpToVb(ev.viewPoint) : this._points[1];
257
+ const vec = start.vectorTo(end);
258
+ const width = Math.abs(vec.x);
259
+ const height = Math.abs(vec.y);
260
+ if (width < 1 || height < 1)
261
+ return;
262
+ const offset = Point3d.create(vec.x < 0 ? end.x : start.x, vec.y < 0 ? end.y : start.y); // define location by corner points...
263
+ const element = svgMarkup.ellipse(width, height).move(offset.x, offset.y);
264
+ this.setCurrentStyle(element, true);
265
+ if (!isDynamics)
266
+ this.onAdded(element);
267
+ }
268
+ }
269
+ EllipseTool.toolId = "Markup.Ellipse";
270
+ EllipseTool.iconSpec = "icon-ellipse";
271
+ export { EllipseTool };
272
+ /** Tool for placing Markup Arrows
273
+ * @public
274
+ */
275
+ class ArrowTool extends RedlineTool {
276
+ /** ctor for ArrowTool
277
+ * @param _arrowPos "start", "end", or "both". If undefined = "end".
278
+ */
279
+ constructor(_arrowPos) {
280
+ super();
281
+ this._arrowPos = _arrowPos;
282
+ }
283
+ showPrompt() { this.provideToolAssistance(CoreTools.tools + (0 === this._points.length ? "ElementSet.Prompts.StartPoint" : "ElementSet.Prompts.EndPoint")); }
284
+ getOrCreateArrowMarker(color) {
285
+ const arrowProps = MarkupApp.props.active.arrow;
286
+ return this.markup.createArrowMarker(color, arrowProps.length, arrowProps.width);
287
+ }
288
+ createMarkup(svgMarkup, ev, isDynamics) {
289
+ if (this._points.length < (isDynamics ? this._nRequiredPoints - 1 : this._nRequiredPoints))
290
+ return;
291
+ const start = this._points[0];
292
+ const end = isDynamics ? MarkupApp.convertVpToVb(ev.viewPoint) : this._points[1];
293
+ const vec = start.vectorTo(end);
294
+ if (!vec.normalizeInPlace())
295
+ return;
296
+ const element = svgMarkup.line(start.x, start.y, end.x, end.y);
297
+ this.setCurrentStyle(element, false);
298
+ const marker = this.getOrCreateArrowMarker(element.css("stroke"));
299
+ const addToStart = ("start" === this._arrowPos || "both" === this._arrowPos);
300
+ const addToEnd = ("end" === this._arrowPos || "both" === this._arrowPos);
301
+ if (addToStart)
302
+ element.marker("start", marker);
303
+ if (addToEnd || !addToStart)
304
+ element.marker("end", marker);
305
+ if (!isDynamics)
306
+ this.onAdded(element);
307
+ }
308
+ }
309
+ ArrowTool.toolId = "Markup.Arrow";
310
+ ArrowTool.iconSpec = "icon-callout";
311
+ export { ArrowTool };
312
+ /** Tool for measuring distances and placing Markups of them
313
+ * @public
314
+ */
315
+ class DistanceTool extends ArrowTool {
316
+ constructor() {
317
+ super(...arguments);
318
+ this._startPointWorld = new Point3d();
319
+ }
320
+ showPrompt() { this.provideToolAssistance(CoreTools.tools + (0 === this._points.length ? "ElementSet.Prompts.StartPoint" : "ElementSet.Prompts.EndPoint")); }
321
+ setupAndPromptForNextAction() {
322
+ IModelApp.accuSnap.enableSnap(true);
323
+ IModelApp.toolAdmin.toolState.coordLockOvr = CoordinateLockOverrides.None;
324
+ super.setupAndPromptForNextAction();
325
+ }
326
+ getFormattedDistance(distance) {
327
+ const formatterSpec = IModelApp.quantityFormatter.findFormatterSpecByQuantityType(QuantityType.Length);
328
+ if (undefined === formatterSpec)
329
+ return undefined;
330
+ return IModelApp.quantityFormatter.formatQuantity(distance, formatterSpec);
331
+ }
332
+ createMarkup(svgMarkup, ev, isDynamics) {
333
+ if (this._points.length < (isDynamics ? this._nRequiredPoints - 1 : this._nRequiredPoints))
334
+ return;
335
+ const start = this._points[0];
336
+ const end = isDynamics ? MarkupApp.convertVpToVb(ev.viewPoint) : this._points[1];
337
+ const vec = start.vectorTo(end);
338
+ if (!vec.normalizeInPlace())
339
+ return;
340
+ const formatterSpec = IModelApp.quantityFormatter.findFormatterSpecByQuantityType(QuantityType.Length);
341
+ if (undefined === formatterSpec)
342
+ return;
343
+ const distanceLine = svgMarkup.line(start.x, start.y, end.x, end.y);
344
+ this.setCurrentStyle(distanceLine, false);
345
+ const marker = this.getOrCreateArrowMarker(distanceLine.css("stroke"));
346
+ distanceLine.marker("start", marker);
347
+ distanceLine.marker("end", marker);
348
+ const loc = start.interpolate(0.5, end);
349
+ const distance = IModelApp.quantityFormatter.formatQuantity(this._startPointWorld.distance(ev.point), formatterSpec);
350
+ const text = svgMarkup.plain(distance).addClass(MarkupApp.textClass).attr("text-anchor", "middle").translate(loc.x, loc.y);
351
+ this.setCurrentTextStyle(text);
352
+ const textWithBg = this.createBoxedText(svgMarkup, text);
353
+ if (!isDynamics) {
354
+ const markup = this.markup;
355
+ const undo = markup.undo;
356
+ undo.performOperation(this.keyin, () => {
357
+ undo.onAdded(distanceLine);
358
+ undo.onAdded(textWithBg);
359
+ });
360
+ markup.selected.restart(textWithBg); // Select text+box so that user can freely position relative to distance line...
361
+ }
362
+ }
363
+ async onDataButtonDown(ev) {
364
+ if (undefined === await IModelApp.quantityFormatter.getFormatterSpecByQuantityType(QuantityType.Length)) {
365
+ await this.onReinitialize();
366
+ return EventHandled.No;
367
+ }
368
+ if (0 === this._points.length)
369
+ this._startPointWorld.setFrom(ev.point);
370
+ return super.onDataButtonDown(ev);
371
+ }
372
+ }
373
+ DistanceTool.toolId = "Markup.Distance";
374
+ DistanceTool.iconSpec = "icon-distance";
375
+ export { DistanceTool };
376
+ /** Tool for placing Markup freehand sketches
377
+ * @public
378
+ */
379
+ class SketchTool extends RedlineTool {
380
+ constructor() {
381
+ super(...arguments);
382
+ this._minDistSquared = 100;
383
+ }
384
+ showPrompt() { this.provideToolAssistance(CoreTools.tools + (0 === this._points.length ? "ElementSet.Prompts.StartPoint" : "ElementSet.Prompts.EndPoint")); }
385
+ createMarkup(svgMarkup, ev, isDynamics) {
386
+ if (this._points.length < (isDynamics ? this._nRequiredPoints - 1 : this._nRequiredPoints))
387
+ return;
388
+ const pts = [];
389
+ const evPt = MarkupApp.convertVpToVb(ev.viewPoint);
390
+ this._points.forEach((pt) => {
391
+ pts.push(pt.x);
392
+ pts.push(pt.y);
393
+ });
394
+ if (isDynamics && !evPt.isAlmostEqualXY(this._points[this._points.length - 1])) {
395
+ pts.push(evPt.x);
396
+ pts.push(evPt.y);
397
+ }
398
+ const isClosed = (this._points.length > 2 && (this._points[0].distanceSquaredXY(isDynamics ? evPt : this._points[this._points.length - 1]) < this._minDistSquared * 2));
399
+ const element = isClosed ? svgMarkup.polygon(pts) : svgMarkup.polyline(pts);
400
+ this.setCurrentStyle(element, isClosed);
401
+ if (!isDynamics)
402
+ this.onAdded(element);
403
+ }
404
+ async onMouseMotion(ev) {
405
+ const evPt = MarkupApp.convertVpToVb(ev.viewPoint);
406
+ if (undefined !== ev.viewport && this._points.length > 0 && evPt.distanceSquaredXY(this._points[this._points.length - 1]) > this._minDistSquared)
407
+ this._points.push(evPt);
408
+ return super.onMouseMotion(ev);
409
+ }
410
+ }
411
+ SketchTool.toolId = "Markup.Sketch";
412
+ SketchTool.iconSpec = "icon-draw";
413
+ export { SketchTool };
414
+ /** Tool for placing SVG symbols on a Markup
415
+ * @public
416
+ */
417
+ class SymbolTool extends RedlineTool {
418
+ constructor(_symbolData, _applyCurrentStyle) {
419
+ super();
420
+ this._symbolData = _symbolData;
421
+ this._applyCurrentStyle = _applyCurrentStyle;
422
+ }
423
+ async onInstall() {
424
+ if (undefined === this._symbolData)
425
+ return false;
426
+ return super.onInstall();
427
+ }
428
+ showPrompt() {
429
+ this.provideToolAssistance(0 === this._points.length ? (`${MarkupTool.toolKey}Symbol.Prompts.FirstPoint`) : `${CoreTools.tools}ElementSet.Prompts.OppositeCorner`, true);
430
+ }
431
+ createMarkup(svgMarkup, ev, isDynamics) {
432
+ if (undefined === this._symbolData)
433
+ return;
434
+ if (this._points.length < this._minPoints)
435
+ return;
436
+ const start = this._points[0];
437
+ const end = isDynamics ? MarkupApp.convertVpToVb(ev.viewPoint) : this._points[this._points.length - 1];
438
+ const vec = start.vectorTo(end);
439
+ const width = Math.abs(vec.x);
440
+ const height = Math.abs(vec.y);
441
+ if ((width < 10 || height < 10) && (isDynamics || this._points.length !== this._minPoints))
442
+ return;
443
+ if (undefined === this._symbol) {
444
+ const symbol = svgMarkup.group().svg(this._symbolData); // creating group instead of using symbol because of inability to flash/hilite multi-color symbol instance...
445
+ if (0 === symbol.children().length) {
446
+ symbol.remove();
447
+ this._symbolData = undefined;
448
+ }
449
+ try {
450
+ symbol.flatten(symbol);
451
+ }
452
+ catch { }
453
+ this._symbol = symbol;
454
+ }
455
+ else if (!isDynamics) {
456
+ svgMarkup.add(this._symbol);
457
+ }
458
+ const offset = Point3d.create(vec.x < 0 ? end.x : start.x, vec.y < 0 ? end.y : start.y); // define location by corner points...
459
+ if (!isDynamics && this._points.length === this._minPoints)
460
+ this._symbol.size(ev.viewport.viewRect.width * 0.1).center(offset.x, offset.y);
461
+ else if (!ev.isShiftKey)
462
+ this._symbol.size(width).move(offset.x, offset.y);
463
+ else
464
+ this._symbol.size(width, height).move(offset.x, offset.y);
465
+ if (this._applyCurrentStyle) {
466
+ const active = MarkupApp.props.active; // Apply color and transparency only; using active stroke-width, etc. for pre-defined symbols is likely undesirable...
467
+ this._symbol.forElementsOfGroup((child) => {
468
+ const css = window.getComputedStyle(child.node);
469
+ const toValue = (val, newVal) => (!val || val === "none") ? "none" : newVal;
470
+ child.css({ "fill": toValue(css.fill, active.element.fill), "stroke": toValue(css.stroke, active.element.stroke), "fill-opacity": active.element["fill-opacity"], "stroke-opacity": active.element["stroke-opacity"] });
471
+ });
472
+ }
473
+ if (!isDynamics)
474
+ this.onAdded(this._symbol);
475
+ }
476
+ async onDataButtonUp(ev) {
477
+ if (undefined === ev.viewport || this._points.length !== this._minPoints)
478
+ return EventHandled.No;
479
+ this.createMarkup(this.markup.svgMarkup, ev, false);
480
+ await this.onReinitialize();
481
+ return EventHandled.No;
482
+ }
483
+ async onResetButtonUp(_ev) {
484
+ await this.onReinitialize();
485
+ return EventHandled.No;
486
+ }
487
+ clearDynamicsMarkup(isDynamics) {
488
+ if (!isDynamics)
489
+ super.clearDynamicsMarkup(isDynamics); // For dynamics we don't create a new symbol each frame, we just set the width/height...
490
+ }
491
+ }
492
+ SymbolTool.toolId = "Markup.Symbol";
493
+ SymbolTool.iconSpec = "icon-symbol";
494
+ export { SymbolTool };
499
495
  //# sourceMappingURL=RedlineTool.js.map