@itwin/editor-frontend 3.4.0-dev.9 → 3.4.1

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 (89) hide show
  1. package/CHANGELOG.md +53 -1
  2. package/lib/cjs/CreateElementTool.d.ts +100 -100
  3. package/lib/cjs/CreateElementTool.js +327 -327
  4. package/lib/cjs/CreateElementTool.js.map +1 -1
  5. package/lib/cjs/DeleteElementsTool.d.ts +15 -15
  6. package/lib/cjs/DeleteElementsTool.js +40 -40
  7. package/lib/cjs/DeleteElementsTool.js.map +1 -1
  8. package/lib/cjs/EditTool.d.ts +37 -37
  9. package/lib/cjs/EditTool.js +135 -135
  10. package/lib/cjs/EditTool.js.map +1 -1
  11. package/lib/cjs/ElementGeometryTool.d.ts +148 -148
  12. package/lib/cjs/ElementGeometryTool.d.ts.map +1 -1
  13. package/lib/cjs/ElementGeometryTool.js +711 -708
  14. package/lib/cjs/ElementGeometryTool.js.map +1 -1
  15. package/lib/cjs/ModifyCurveTools.d.ts +118 -118
  16. package/lib/cjs/ModifyCurveTools.js +668 -668
  17. package/lib/cjs/ModifyCurveTools.js.map +1 -1
  18. package/lib/cjs/ProjectLocation/ProjectExtentsDecoration.d.ts +137 -137
  19. package/lib/cjs/ProjectLocation/ProjectExtentsDecoration.d.ts.map +1 -1
  20. package/lib/cjs/ProjectLocation/ProjectExtentsDecoration.js +824 -821
  21. package/lib/cjs/ProjectLocation/ProjectExtentsDecoration.js.map +1 -1
  22. package/lib/cjs/ProjectLocation/ProjectGeolocation.d.ts +135 -135
  23. package/lib/cjs/ProjectLocation/ProjectGeolocation.d.ts.map +1 -1
  24. package/lib/cjs/ProjectLocation/ProjectGeolocation.js +532 -507
  25. package/lib/cjs/ProjectLocation/ProjectGeolocation.js.map +1 -1
  26. package/lib/cjs/SketchTools.d.ts +306 -306
  27. package/lib/cjs/SketchTools.js +1707 -1707
  28. package/lib/cjs/SketchTools.js.map +1 -1
  29. package/lib/cjs/SolidModelingTools.d.ts +380 -380
  30. package/lib/cjs/SolidModelingTools.d.ts.map +1 -1
  31. package/lib/cjs/SolidModelingTools.js +1461 -1459
  32. package/lib/cjs/SolidModelingTools.js.map +1 -1
  33. package/lib/cjs/SolidPrimitiveTools.d.ts +254 -254
  34. package/lib/cjs/SolidPrimitiveTools.js +1095 -1095
  35. package/lib/cjs/SolidPrimitiveTools.js.map +1 -1
  36. package/lib/cjs/TransformElementsTool.d.ts +166 -166
  37. package/lib/cjs/TransformElementsTool.js +654 -654
  38. package/lib/cjs/TransformElementsTool.js.map +1 -1
  39. package/lib/cjs/UndoRedoTool.d.ts +16 -16
  40. package/lib/cjs/UndoRedoTool.js +42 -42
  41. package/lib/cjs/UndoRedoTool.js.map +1 -1
  42. package/lib/cjs/editor-frontend.d.ts +15 -15
  43. package/lib/cjs/editor-frontend.js +31 -31
  44. package/lib/cjs/editor-frontend.js.map +1 -1
  45. package/lib/esm/CreateElementTool.d.ts +100 -100
  46. package/lib/esm/CreateElementTool.js +319 -319
  47. package/lib/esm/CreateElementTool.js.map +1 -1
  48. package/lib/esm/DeleteElementsTool.d.ts +15 -15
  49. package/lib/esm/DeleteElementsTool.js +36 -36
  50. package/lib/esm/DeleteElementsTool.js.map +1 -1
  51. package/lib/esm/EditTool.d.ts +37 -37
  52. package/lib/esm/EditTool.js +131 -131
  53. package/lib/esm/EditTool.js.map +1 -1
  54. package/lib/esm/ElementGeometryTool.d.ts +148 -148
  55. package/lib/esm/ElementGeometryTool.d.ts.map +1 -1
  56. package/lib/esm/ElementGeometryTool.js +703 -700
  57. package/lib/esm/ElementGeometryTool.js.map +1 -1
  58. package/lib/esm/ModifyCurveTools.d.ts +118 -118
  59. package/lib/esm/ModifyCurveTools.js +660 -660
  60. package/lib/esm/ModifyCurveTools.js.map +1 -1
  61. package/lib/esm/ProjectLocation/ProjectExtentsDecoration.d.ts +137 -137
  62. package/lib/esm/ProjectLocation/ProjectExtentsDecoration.d.ts.map +1 -1
  63. package/lib/esm/ProjectLocation/ProjectExtentsDecoration.js +816 -813
  64. package/lib/esm/ProjectLocation/ProjectExtentsDecoration.js.map +1 -1
  65. package/lib/esm/ProjectLocation/ProjectGeolocation.d.ts +135 -135
  66. package/lib/esm/ProjectLocation/ProjectGeolocation.d.ts.map +1 -1
  67. package/lib/esm/ProjectLocation/ProjectGeolocation.js +526 -501
  68. package/lib/esm/ProjectLocation/ProjectGeolocation.js.map +1 -1
  69. package/lib/esm/SketchTools.d.ts +306 -306
  70. package/lib/esm/SketchTools.js +1697 -1697
  71. package/lib/esm/SketchTools.js.map +1 -1
  72. package/lib/esm/SolidModelingTools.d.ts +380 -380
  73. package/lib/esm/SolidModelingTools.d.ts.map +1 -1
  74. package/lib/esm/SolidModelingTools.js +1436 -1434
  75. package/lib/esm/SolidModelingTools.js.map +1 -1
  76. package/lib/esm/SolidPrimitiveTools.d.ts +254 -254
  77. package/lib/esm/SolidPrimitiveTools.js +1086 -1086
  78. package/lib/esm/SolidPrimitiveTools.js.map +1 -1
  79. package/lib/esm/TransformElementsTool.d.ts +166 -166
  80. package/lib/esm/TransformElementsTool.js +646 -646
  81. package/lib/esm/TransformElementsTool.js.map +1 -1
  82. package/lib/esm/UndoRedoTool.d.ts +16 -16
  83. package/lib/esm/UndoRedoTool.js +36 -36
  84. package/lib/esm/UndoRedoTool.js.map +1 -1
  85. package/lib/esm/editor-frontend.d.ts +15 -15
  86. package/lib/esm/editor-frontend.js +19 -19
  87. package/lib/esm/editor-frontend.js.map +1 -1
  88. package/lib/public/locales/en/Editor.json +448 -448
  89. package/package.json +15 -15
@@ -1,320 +1,320 @@
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
- import { Id64, IModelStatus } from "@itwin/core-bentley";
6
- import { Constant, Point3d, Vector3d } from "@itwin/core-geometry";
7
- import { IModelError, isPlacement3dProps } from "@itwin/core-common";
8
- import { CoordSystem, CoreTools, EventHandled, GraphicBranch, IModelApp, PrimitiveTool, readElementGraphics, ToolAssistance, ToolAssistanceImage, ToolAssistanceInputMethod } from "@itwin/core-frontend";
9
- function computeChordToleranceFromPointAndRadius(vp, center, radius) {
10
- if (vp.view.is3d() && vp.view.isCameraOn) {
11
- const nearFrontCenter = vp.getFrustum(CoordSystem.World).frontCenter;
12
- const toFront = Vector3d.createStartEnd(center, nearFrontCenter);
13
- const viewZ = vp.rotation.rowZ();
14
- // If the sphere overlaps the near front plane just use near front point. This also handles behind eye conditions.
15
- if (viewZ.dotProduct(toFront) < radius) {
16
- center = nearFrontCenter;
17
- }
18
- else {
19
- // Find point on sphere closest to eye.
20
- const toEye = center.unitVectorTo(vp.view.camera.eye);
21
- // Only if not already behind the eye.
22
- if (toEye) {
23
- toEye.scaleInPlace(radius);
24
- center.addInPlace(toEye);
25
- }
26
- }
27
- }
28
- const viewPt = vp.worldToViewMap.transform0.multiplyPoint3dQuietNormalize(center);
29
- const viewPt2 = new Point3d(viewPt.x + 1.0, viewPt.y, viewPt.z);
30
- const pixelSize = vp.worldToViewMap.transform1.multiplyPoint3dQuietNormalize(viewPt).distance(vp.worldToViewMap.transform1.multiplyPoint3dQuietNormalize(viewPt2));
31
- // Return size of a physical pixel in meters.
32
- return (0.0 !== pixelSize ? vp.target.adjustPixelSizeForLOD(pixelSize) : 0.001);
33
- }
34
- /** @alpha */
35
- export function computeChordToleranceFromPoint(vp, pt, radius) {
36
- return computeChordToleranceFromPointAndRadius(vp, pt, radius ? radius : Constant.oneCentimeter);
37
- }
38
- /** @alpha */
39
- export function computeChordToleranceFromRange(vp, range) {
40
- return computeChordToleranceFromPointAndRadius(vp, range.center, 0.5 * range.low.distance(range.high));
41
- }
42
- /** @alpha */
43
- export class DynamicGraphicsProvider {
44
- constructor(iModel, prefix) {
45
- /** Chord tolerance to use to stroke the element's geometry in meters */
46
- this.chordTolerance = 0.001;
47
- this.iModel = iModel;
48
- this.prefix = prefix;
49
- }
50
- getRequestId(id) { return `${this.prefix}-${id}`; }
51
- getToleranceLog10() { return Math.floor(Math.log10(this.chordTolerance)); }
52
- async createRequest(categoryId, placement, geometry) {
53
- let graphicData;
54
- let is3d;
55
- if (is3d = isPlacement3dProps(placement)) {
56
- const requestProps = {
57
- id: this.getRequestId(this.elementId ? this.elementId : Id64.invalid),
58
- elementId: this.elementId,
59
- modelId: this.modelId,
60
- toleranceLog10: this.getToleranceLog10(),
61
- type: "3d",
62
- placement,
63
- categoryId,
64
- geometry,
65
- };
66
- graphicData = await IModelApp.tileAdmin.requestElementGraphics(this.iModel, requestProps);
67
- is3d = true;
68
- }
69
- else {
70
- const requestProps = {
71
- id: this.getRequestId(this.elementId ? this.elementId : Id64.invalid),
72
- elementId: this.elementId,
73
- modelId: this.modelId,
74
- toleranceLog10: this.getToleranceLog10(),
75
- type: "2d",
76
- placement,
77
- categoryId,
78
- geometry,
79
- };
80
- graphicData = await IModelApp.tileAdmin.requestElementGraphics(this.iModel, requestProps);
81
- }
82
- if (undefined === graphicData)
83
- return;
84
- const graphic = await readElementGraphics(graphicData, this.iModel, this.modelId ? this.modelId : Id64.invalid, is3d, { noFlash: true, noHilite: true });
85
- if (undefined === graphic)
86
- return;
87
- return IModelApp.renderSystem.createGraphicOwner(graphic);
88
- }
89
- /** Call to request a RenderGraphic for the supplied geometry and placement.
90
- * @see [[cleanupGraphic]] Must be called when the tool exits.
91
- */
92
- async createGraphic(categoryId, placement, geometry) {
93
- try {
94
- const graphic = await this.createRequest(categoryId, placement, geometry);
95
- this.cleanupGraphic();
96
- return (undefined !== (this.graphic = graphic));
97
- }
98
- catch {
99
- return false;
100
- }
101
- }
102
- /** Call to request a RenderGraphic for the supplied geometry and trigger a dynamic update upon fulfillment.
103
- * @note May be useful to update a dynamic preview outside of normal button and motion events, ex. modifier key change.
104
- * @see [[cleanupGraphic]] Must be called when the tool exits.
105
- */
106
- createGraphicAndUpdateDynamics(ev, categoryId, placement, geometry) {
107
- const promise = this._graphicPromise = this.createGraphic(categoryId, placement, geometry);
108
- promise.then(() => {
109
- if (promise !== this._graphicPromise)
110
- return; // abandoned this request...
111
- IModelApp.toolAdmin.updateDynamics(ev);
112
- }).catch((_) => { });
113
- }
114
- /** Call to dispose of [[RenderGraphic]] held by [[RenderGraphicOwner]].
115
- * @note Must be called when the tool exits to avoid leaks of graphics memory or other webgl resources.
116
- */
117
- cleanupGraphic() {
118
- if (undefined === this.graphic)
119
- return;
120
- this.graphic.disposeGraphic();
121
- this.graphic = undefined;
122
- }
123
- addGraphic(context, transform) {
124
- if (undefined === this.graphic)
125
- return;
126
- if (undefined === transform) {
127
- context.addGraphic(this.graphic);
128
- return;
129
- }
130
- const branch = new GraphicBranch(false);
131
- branch.add(this.graphic);
132
- const branchGraphic = context.createBranch(branch, transform);
133
- context.addGraphic(branchGraphic);
134
- }
135
- }
136
- /** @alpha Placement tool base class for creating new elements. */
137
- export class CreateElementTool extends PrimitiveTool {
138
- get targetCategory() {
139
- var _a;
140
- const category = (_a = this.briefcase) === null || _a === void 0 ? void 0 : _a.editorToolSettings.category;
141
- if (undefined === category)
142
- throw new IModelError(IModelStatus.InvalidCategory, "");
143
- return category;
144
- }
145
- get targetModelId() {
146
- var _a;
147
- const model = (_a = this.briefcase) === null || _a === void 0 ? void 0 : _a.editorToolSettings.model;
148
- if (undefined === model)
149
- throw new IModelError(IModelStatus.BadModel, "");
150
- return model;
151
- }
152
- isCompatibleViewport(vp, isSelectedViewChange) {
153
- if (!(vp === null || vp === void 0 ? void 0 : vp.iModel.isBriefcaseConnection()))
154
- return false;
155
- return undefined !== vp.iModel.editorToolSettings.model && super.isCompatibleViewport(vp, isSelectedViewChange);
156
- }
157
- /** Whether [[setupAndPromptForNextAction]] should call [[AccuSnap.enableSnap]] for current tool phase.
158
- * @return true to enable snapping to elements.
159
- */
160
- get wantAccuSnap() { return false; }
161
- /** Whether to automatically start element dynamics on button event.
162
- * @return true if tool will implement [[InteractiveTool.onDynamicFrame]] to show element dynamics.
163
- */
164
- get wantDynamics() { return false; }
165
- /** Whether tool is ready to insert the new element.
166
- * @return true to call [[createElement]].
167
- */
168
- isComplete(_ev) { return false; }
169
- /** Orchestrates advancing the internal state of the tool on a data button event.
170
- * - Gather input: Initiates element dynamics and accepts additional points as required.
171
- * - Complete operation: Create new element, restart or exit tool.
172
- * @returns EventHandled.Yes if onReinitialize was called to restart or exit tool.
173
- */
174
- async processDataButton(ev) {
175
- if (this.isComplete(ev)) {
176
- await this.createElement();
177
- await this.onReinitialize();
178
- return EventHandled.Yes;
179
- }
180
- this.setupAndPromptForNextAction();
181
- if (!this.isDynamicsStarted && this.wantDynamics)
182
- this.beginDynamics();
183
- return EventHandled.No;
184
- }
185
- async onDataButtonDown(ev) {
186
- return this.processDataButton(ev);
187
- }
188
- async onResetButtonUp(_ev) {
189
- await this.onReinitialize();
190
- return EventHandled.No;
191
- }
192
- /** Setup initial tool state, prompts, etc. */
193
- async onPostInstall() {
194
- await super.onPostInstall();
195
- this.setupAndPromptForNextAction();
196
- }
197
- /** Restore tool assistance after no longer being suspended by either a [[ViewTool]] or [[InputCollector]]. */
198
- async onUnsuspend() {
199
- this.provideToolAssistance();
200
- }
201
- /** Setup auto-locate, AccuSnap, AccuDraw, and supply tool assistance. */
202
- setupAndPromptForNextAction() {
203
- IModelApp.accuSnap.enableSnap(this.wantAccuSnap);
204
- this.provideToolAssistance();
205
- }
206
- /** Sub-classes should override to provide tool specific instructions. */
207
- provideToolAssistance(mainInstrText, additionalInstr) {
208
- const mainMsg = "ElementSet.Prompts.IdentifyPoint";
209
- const leftMsg = "ElementSet.Inputs.AcceptPoint";
210
- const rightMsg = "ElementSet.Inputs.Cancel";
211
- const mouseInstructions = [];
212
- const touchInstructions = [];
213
- if (!ToolAssistance.createTouchCursorInstructions(touchInstructions))
214
- touchInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.OneTouchTap, CoreTools.translate(leftMsg), false, ToolAssistanceInputMethod.Touch));
215
- mouseInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.LeftClick, CoreTools.translate(leftMsg), false, ToolAssistanceInputMethod.Mouse));
216
- touchInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.TwoTouchTap, CoreTools.translate(rightMsg), false, ToolAssistanceInputMethod.Touch));
217
- mouseInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.RightClick, CoreTools.translate(rightMsg), false, ToolAssistanceInputMethod.Mouse));
218
- if (undefined !== additionalInstr) {
219
- for (const instr of additionalInstr) {
220
- if (ToolAssistanceInputMethod.Touch === instr.inputMethod)
221
- touchInstructions.push(instr);
222
- else
223
- mouseInstructions.push(instr);
224
- }
225
- }
226
- const sections = [];
227
- sections.push(ToolAssistance.createSection(mouseInstructions, ToolAssistance.inputsLabel));
228
- sections.push(ToolAssistance.createSection(touchInstructions, ToolAssistance.inputsLabel));
229
- const mainInstruction = ToolAssistance.createInstruction(this.iconSpec, undefined !== mainInstrText ? mainInstrText : CoreTools.translate(mainMsg));
230
- const instructions = ToolAssistance.createInstructions(mainInstruction, sections);
231
- IModelApp.notifications.setToolAssistance(instructions);
232
- }
233
- }
234
- /** @alpha Placement tool base class for creating new elements that use dynamics to show intermediate results. */
235
- export class CreateElementWithDynamicsTool extends CreateElementTool {
236
- get wantAccuSnap() { return true; }
237
- get wantDynamics() { return true; }
238
- clearGraphics() {
239
- if (undefined === this._graphicsProvider)
240
- return;
241
- this._graphicsProvider.cleanupGraphic();
242
- this._graphicsProvider = undefined;
243
- }
244
- async createGraphics(ev) {
245
- if (!await this.updateDynamicData(ev))
246
- return;
247
- const placement = this.getPlacementProps();
248
- if (undefined === placement)
249
- return;
250
- const geometry = this.getGeometryProps(placement);
251
- if (undefined === geometry)
252
- return;
253
- if (undefined === this._graphicsProvider)
254
- this._graphicsProvider = new DynamicGraphicsProvider(this.iModel, this.toolId);
255
- // Set chord tolerance for curved surfaces...
256
- if (ev.viewport)
257
- this._graphicsProvider.chordTolerance = computeChordToleranceFromPoint(ev.viewport, ev.point);
258
- await this._graphicsProvider.createGraphic(this.targetCategory, placement, geometry);
259
- }
260
- onDynamicFrame(_ev, context) {
261
- if (undefined !== this._graphicsProvider)
262
- this._graphicsProvider.addGraphic(context);
263
- }
264
- async onMouseMotion(ev) {
265
- return this.createGraphics(ev);
266
- }
267
- async doCreateElement(_props, _data) { }
268
- async updateElementData(_ev, _isDynamics) { }
269
- async updateDynamicData(ev) {
270
- if (!IModelApp.viewManager.inDynamicsMode)
271
- return false; // Don't need to create graphic if dynamics aren't yet active...
272
- await this.updateElementData(ev, true);
273
- return true;
274
- }
275
- async createElement() {
276
- const placement = this.getPlacementProps();
277
- if (undefined === placement)
278
- return;
279
- const geometry = this.getGeometryProps(placement);
280
- if (undefined === geometry)
281
- return;
282
- const elemProps = this.getElementProps(placement);
283
- if (undefined === elemProps)
284
- return;
285
- let data;
286
- if ("flatbuffer" === geometry.format) {
287
- data = { entryArray: geometry.data };
288
- delete elemProps.geom; // Leave unchanged until replaced by flatbuffer geometry...
289
- }
290
- else {
291
- elemProps.geom = geometry.data;
292
- }
293
- return this.doCreateElement(elemProps, data);
294
- }
295
- setupAccuDraw() { }
296
- setupAndPromptForNextAction() {
297
- this.setupAccuDraw();
298
- super.setupAndPromptForNextAction();
299
- }
300
- async acceptPoint(ev) {
301
- await this.updateElementData(ev, false);
302
- return true;
303
- }
304
- async onDataButtonDown(ev) {
305
- if (!await this.acceptPoint(ev))
306
- return EventHandled.Yes;
307
- return super.onDataButtonDown(ev);
308
- }
309
- async cancelPoint(_ev) { return true; }
310
- async onResetButtonUp(ev) {
311
- if (!await this.cancelPoint(ev))
312
- return EventHandled.Yes;
313
- return super.onResetButtonUp(ev);
314
- }
315
- async onCleanup() {
316
- this.clearGraphics();
317
- return super.onCleanup();
318
- }
319
- }
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
+ import { Id64, IModelStatus } from "@itwin/core-bentley";
6
+ import { Constant, Point3d, Vector3d } from "@itwin/core-geometry";
7
+ import { IModelError, isPlacement3dProps } from "@itwin/core-common";
8
+ import { CoordSystem, CoreTools, EventHandled, GraphicBranch, IModelApp, PrimitiveTool, readElementGraphics, ToolAssistance, ToolAssistanceImage, ToolAssistanceInputMethod } from "@itwin/core-frontend";
9
+ function computeChordToleranceFromPointAndRadius(vp, center, radius) {
10
+ if (vp.view.is3d() && vp.view.isCameraOn) {
11
+ const nearFrontCenter = vp.getFrustum(CoordSystem.World).frontCenter;
12
+ const toFront = Vector3d.createStartEnd(center, nearFrontCenter);
13
+ const viewZ = vp.rotation.rowZ();
14
+ // If the sphere overlaps the near front plane just use near front point. This also handles behind eye conditions.
15
+ if (viewZ.dotProduct(toFront) < radius) {
16
+ center = nearFrontCenter;
17
+ }
18
+ else {
19
+ // Find point on sphere closest to eye.
20
+ const toEye = center.unitVectorTo(vp.view.camera.eye);
21
+ // Only if not already behind the eye.
22
+ if (toEye) {
23
+ toEye.scaleInPlace(radius);
24
+ center.addInPlace(toEye);
25
+ }
26
+ }
27
+ }
28
+ const viewPt = vp.worldToViewMap.transform0.multiplyPoint3dQuietNormalize(center);
29
+ const viewPt2 = new Point3d(viewPt.x + 1.0, viewPt.y, viewPt.z);
30
+ const pixelSize = vp.worldToViewMap.transform1.multiplyPoint3dQuietNormalize(viewPt).distance(vp.worldToViewMap.transform1.multiplyPoint3dQuietNormalize(viewPt2));
31
+ // Return size of a physical pixel in meters.
32
+ return (0.0 !== pixelSize ? vp.target.adjustPixelSizeForLOD(pixelSize) : 0.001);
33
+ }
34
+ /** @alpha */
35
+ export function computeChordToleranceFromPoint(vp, pt, radius) {
36
+ return computeChordToleranceFromPointAndRadius(vp, pt, radius ? radius : Constant.oneCentimeter);
37
+ }
38
+ /** @alpha */
39
+ export function computeChordToleranceFromRange(vp, range) {
40
+ return computeChordToleranceFromPointAndRadius(vp, range.center, 0.5 * range.low.distance(range.high));
41
+ }
42
+ /** @alpha */
43
+ export class DynamicGraphicsProvider {
44
+ constructor(iModel, prefix) {
45
+ /** Chord tolerance to use to stroke the element's geometry in meters */
46
+ this.chordTolerance = 0.001;
47
+ this.iModel = iModel;
48
+ this.prefix = prefix;
49
+ }
50
+ getRequestId(id) { return `${this.prefix}-${id}`; }
51
+ getToleranceLog10() { return Math.floor(Math.log10(this.chordTolerance)); }
52
+ async createRequest(categoryId, placement, geometry) {
53
+ let graphicData;
54
+ let is3d;
55
+ if (is3d = isPlacement3dProps(placement)) {
56
+ const requestProps = {
57
+ id: this.getRequestId(this.elementId ? this.elementId : Id64.invalid),
58
+ elementId: this.elementId,
59
+ modelId: this.modelId,
60
+ toleranceLog10: this.getToleranceLog10(),
61
+ type: "3d",
62
+ placement,
63
+ categoryId,
64
+ geometry,
65
+ };
66
+ graphicData = await IModelApp.tileAdmin.requestElementGraphics(this.iModel, requestProps);
67
+ is3d = true;
68
+ }
69
+ else {
70
+ const requestProps = {
71
+ id: this.getRequestId(this.elementId ? this.elementId : Id64.invalid),
72
+ elementId: this.elementId,
73
+ modelId: this.modelId,
74
+ toleranceLog10: this.getToleranceLog10(),
75
+ type: "2d",
76
+ placement,
77
+ categoryId,
78
+ geometry,
79
+ };
80
+ graphicData = await IModelApp.tileAdmin.requestElementGraphics(this.iModel, requestProps);
81
+ }
82
+ if (undefined === graphicData)
83
+ return;
84
+ const graphic = await readElementGraphics(graphicData, this.iModel, this.modelId ? this.modelId : Id64.invalid, is3d, { noFlash: true, noHilite: true });
85
+ if (undefined === graphic)
86
+ return;
87
+ return IModelApp.renderSystem.createGraphicOwner(graphic);
88
+ }
89
+ /** Call to request a RenderGraphic for the supplied geometry and placement.
90
+ * @see [[cleanupGraphic]] Must be called when the tool exits.
91
+ */
92
+ async createGraphic(categoryId, placement, geometry) {
93
+ try {
94
+ const graphic = await this.createRequest(categoryId, placement, geometry);
95
+ this.cleanupGraphic();
96
+ return (undefined !== (this.graphic = graphic));
97
+ }
98
+ catch {
99
+ return false;
100
+ }
101
+ }
102
+ /** Call to request a RenderGraphic for the supplied geometry and trigger a dynamic update upon fulfillment.
103
+ * @note May be useful to update a dynamic preview outside of normal button and motion events, ex. modifier key change.
104
+ * @see [[cleanupGraphic]] Must be called when the tool exits.
105
+ */
106
+ createGraphicAndUpdateDynamics(ev, categoryId, placement, geometry) {
107
+ const promise = this._graphicPromise = this.createGraphic(categoryId, placement, geometry);
108
+ promise.then(() => {
109
+ if (promise !== this._graphicPromise)
110
+ return; // abandoned this request...
111
+ IModelApp.toolAdmin.updateDynamics(ev);
112
+ }).catch((_) => { });
113
+ }
114
+ /** Call to dispose of [[RenderGraphic]] held by [[RenderGraphicOwner]].
115
+ * @note Must be called when the tool exits to avoid leaks of graphics memory or other webgl resources.
116
+ */
117
+ cleanupGraphic() {
118
+ if (undefined === this.graphic)
119
+ return;
120
+ this.graphic.disposeGraphic();
121
+ this.graphic = undefined;
122
+ }
123
+ addGraphic(context, transform) {
124
+ if (undefined === this.graphic)
125
+ return;
126
+ if (undefined === transform) {
127
+ context.addGraphic(this.graphic);
128
+ return;
129
+ }
130
+ const branch = new GraphicBranch(false);
131
+ branch.add(this.graphic);
132
+ const branchGraphic = context.createBranch(branch, transform);
133
+ context.addGraphic(branchGraphic);
134
+ }
135
+ }
136
+ /** @alpha Placement tool base class for creating new elements. */
137
+ export class CreateElementTool extends PrimitiveTool {
138
+ get targetCategory() {
139
+ var _a;
140
+ const category = (_a = this.briefcase) === null || _a === void 0 ? void 0 : _a.editorToolSettings.category;
141
+ if (undefined === category)
142
+ throw new IModelError(IModelStatus.InvalidCategory, "");
143
+ return category;
144
+ }
145
+ get targetModelId() {
146
+ var _a;
147
+ const model = (_a = this.briefcase) === null || _a === void 0 ? void 0 : _a.editorToolSettings.model;
148
+ if (undefined === model)
149
+ throw new IModelError(IModelStatus.BadModel, "");
150
+ return model;
151
+ }
152
+ isCompatibleViewport(vp, isSelectedViewChange) {
153
+ if (!(vp === null || vp === void 0 ? void 0 : vp.iModel.isBriefcaseConnection()))
154
+ return false;
155
+ return undefined !== vp.iModel.editorToolSettings.model && super.isCompatibleViewport(vp, isSelectedViewChange);
156
+ }
157
+ /** Whether [[setupAndPromptForNextAction]] should call [[AccuSnap.enableSnap]] for current tool phase.
158
+ * @return true to enable snapping to elements.
159
+ */
160
+ get wantAccuSnap() { return false; }
161
+ /** Whether to automatically start element dynamics on button event.
162
+ * @return true if tool will implement [[InteractiveTool.onDynamicFrame]] to show element dynamics.
163
+ */
164
+ get wantDynamics() { return false; }
165
+ /** Whether tool is ready to insert the new element.
166
+ * @return true to call [[createElement]].
167
+ */
168
+ isComplete(_ev) { return false; }
169
+ /** Orchestrates advancing the internal state of the tool on a data button event.
170
+ * - Gather input: Initiates element dynamics and accepts additional points as required.
171
+ * - Complete operation: Create new element, restart or exit tool.
172
+ * @returns EventHandled.Yes if onReinitialize was called to restart or exit tool.
173
+ */
174
+ async processDataButton(ev) {
175
+ if (this.isComplete(ev)) {
176
+ await this.createElement();
177
+ await this.onReinitialize();
178
+ return EventHandled.Yes;
179
+ }
180
+ this.setupAndPromptForNextAction();
181
+ if (!this.isDynamicsStarted && this.wantDynamics)
182
+ this.beginDynamics();
183
+ return EventHandled.No;
184
+ }
185
+ async onDataButtonDown(ev) {
186
+ return this.processDataButton(ev);
187
+ }
188
+ async onResetButtonUp(_ev) {
189
+ await this.onReinitialize();
190
+ return EventHandled.No;
191
+ }
192
+ /** Setup initial tool state, prompts, etc. */
193
+ async onPostInstall() {
194
+ await super.onPostInstall();
195
+ this.setupAndPromptForNextAction();
196
+ }
197
+ /** Restore tool assistance after no longer being suspended by either a [[ViewTool]] or [[InputCollector]]. */
198
+ async onUnsuspend() {
199
+ this.provideToolAssistance();
200
+ }
201
+ /** Setup auto-locate, AccuSnap, AccuDraw, and supply tool assistance. */
202
+ setupAndPromptForNextAction() {
203
+ IModelApp.accuSnap.enableSnap(this.wantAccuSnap);
204
+ this.provideToolAssistance();
205
+ }
206
+ /** Sub-classes should override to provide tool specific instructions. */
207
+ provideToolAssistance(mainInstrText, additionalInstr) {
208
+ const mainMsg = "ElementSet.Prompts.IdentifyPoint";
209
+ const leftMsg = "ElementSet.Inputs.AcceptPoint";
210
+ const rightMsg = "ElementSet.Inputs.Cancel";
211
+ const mouseInstructions = [];
212
+ const touchInstructions = [];
213
+ if (!ToolAssistance.createTouchCursorInstructions(touchInstructions))
214
+ touchInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.OneTouchTap, CoreTools.translate(leftMsg), false, ToolAssistanceInputMethod.Touch));
215
+ mouseInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.LeftClick, CoreTools.translate(leftMsg), false, ToolAssistanceInputMethod.Mouse));
216
+ touchInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.TwoTouchTap, CoreTools.translate(rightMsg), false, ToolAssistanceInputMethod.Touch));
217
+ mouseInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.RightClick, CoreTools.translate(rightMsg), false, ToolAssistanceInputMethod.Mouse));
218
+ if (undefined !== additionalInstr) {
219
+ for (const instr of additionalInstr) {
220
+ if (ToolAssistanceInputMethod.Touch === instr.inputMethod)
221
+ touchInstructions.push(instr);
222
+ else
223
+ mouseInstructions.push(instr);
224
+ }
225
+ }
226
+ const sections = [];
227
+ sections.push(ToolAssistance.createSection(mouseInstructions, ToolAssistance.inputsLabel));
228
+ sections.push(ToolAssistance.createSection(touchInstructions, ToolAssistance.inputsLabel));
229
+ const mainInstruction = ToolAssistance.createInstruction(this.iconSpec, undefined !== mainInstrText ? mainInstrText : CoreTools.translate(mainMsg));
230
+ const instructions = ToolAssistance.createInstructions(mainInstruction, sections);
231
+ IModelApp.notifications.setToolAssistance(instructions);
232
+ }
233
+ }
234
+ /** @alpha Placement tool base class for creating new elements that use dynamics to show intermediate results. */
235
+ export class CreateElementWithDynamicsTool extends CreateElementTool {
236
+ get wantAccuSnap() { return true; }
237
+ get wantDynamics() { return true; }
238
+ clearGraphics() {
239
+ if (undefined === this._graphicsProvider)
240
+ return;
241
+ this._graphicsProvider.cleanupGraphic();
242
+ this._graphicsProvider = undefined;
243
+ }
244
+ async createGraphics(ev) {
245
+ if (!await this.updateDynamicData(ev))
246
+ return;
247
+ const placement = this.getPlacementProps();
248
+ if (undefined === placement)
249
+ return;
250
+ const geometry = this.getGeometryProps(placement);
251
+ if (undefined === geometry)
252
+ return;
253
+ if (undefined === this._graphicsProvider)
254
+ this._graphicsProvider = new DynamicGraphicsProvider(this.iModel, this.toolId);
255
+ // Set chord tolerance for curved surfaces...
256
+ if (ev.viewport)
257
+ this._graphicsProvider.chordTolerance = computeChordToleranceFromPoint(ev.viewport, ev.point);
258
+ await this._graphicsProvider.createGraphic(this.targetCategory, placement, geometry);
259
+ }
260
+ onDynamicFrame(_ev, context) {
261
+ if (undefined !== this._graphicsProvider)
262
+ this._graphicsProvider.addGraphic(context);
263
+ }
264
+ async onMouseMotion(ev) {
265
+ return this.createGraphics(ev);
266
+ }
267
+ async doCreateElement(_props, _data) { }
268
+ async updateElementData(_ev, _isDynamics) { }
269
+ async updateDynamicData(ev) {
270
+ if (!IModelApp.viewManager.inDynamicsMode)
271
+ return false; // Don't need to create graphic if dynamics aren't yet active...
272
+ await this.updateElementData(ev, true);
273
+ return true;
274
+ }
275
+ async createElement() {
276
+ const placement = this.getPlacementProps();
277
+ if (undefined === placement)
278
+ return;
279
+ const geometry = this.getGeometryProps(placement);
280
+ if (undefined === geometry)
281
+ return;
282
+ const elemProps = this.getElementProps(placement);
283
+ if (undefined === elemProps)
284
+ return;
285
+ let data;
286
+ if ("flatbuffer" === geometry.format) {
287
+ data = { entryArray: geometry.data };
288
+ delete elemProps.geom; // Leave unchanged until replaced by flatbuffer geometry...
289
+ }
290
+ else {
291
+ elemProps.geom = geometry.data;
292
+ }
293
+ return this.doCreateElement(elemProps, data);
294
+ }
295
+ setupAccuDraw() { }
296
+ setupAndPromptForNextAction() {
297
+ this.setupAccuDraw();
298
+ super.setupAndPromptForNextAction();
299
+ }
300
+ async acceptPoint(ev) {
301
+ await this.updateElementData(ev, false);
302
+ return true;
303
+ }
304
+ async onDataButtonDown(ev) {
305
+ if (!await this.acceptPoint(ev))
306
+ return EventHandled.Yes;
307
+ return super.onDataButtonDown(ev);
308
+ }
309
+ async cancelPoint(_ev) { return true; }
310
+ async onResetButtonUp(ev) {
311
+ if (!await this.cancelPoint(ev))
312
+ return EventHandled.Yes;
313
+ return super.onResetButtonUp(ev);
314
+ }
315
+ async onCleanup() {
316
+ this.clearGraphics();
317
+ return super.onCleanup();
318
+ }
319
+ }
320
320
  //# sourceMappingURL=CreateElementTool.js.map