@itwin/editor-frontend 4.0.0-dev.8 → 4.0.0-dev.81

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 +44 -1
  2. package/lib/cjs/CreateElementTool.d.ts +100 -100
  3. package/lib/cjs/CreateElementTool.js +325 -327
  4. package/lib/cjs/CreateElementTool.js.map +1 -1
  5. package/lib/cjs/DeleteElementsTool.d.ts +13 -13
  6. package/lib/cjs/DeleteElementsTool.js +38 -38
  7. package/lib/cjs/DeleteElementsTool.js.map +1 -1
  8. package/lib/cjs/EditTool.d.ts +38 -38
  9. package/lib/cjs/EditTool.js +80 -81
  10. package/lib/cjs/EditTool.js.map +1 -1
  11. package/lib/cjs/EditToolIpc.d.ts +18 -18
  12. package/lib/cjs/EditToolIpc.js +28 -28
  13. package/lib/cjs/ElementGeometryTool.d.ts +147 -147
  14. package/lib/cjs/ElementGeometryTool.js +704 -709
  15. package/lib/cjs/ElementGeometryTool.js.map +1 -1
  16. package/lib/cjs/ModifyCurveTools.d.ts +139 -139
  17. package/lib/cjs/ModifyCurveTools.js +776 -784
  18. package/lib/cjs/ModifyCurveTools.js.map +1 -1
  19. package/lib/cjs/ModifyElementTool.d.ts +47 -47
  20. package/lib/cjs/ModifyElementTool.js +177 -177
  21. package/lib/cjs/ModifyElementTool.js.map +1 -1
  22. package/lib/cjs/ProjectLocation/ProjectExtentsDecoration.d.ts +135 -135
  23. package/lib/cjs/ProjectLocation/ProjectExtentsDecoration.js +822 -822
  24. package/lib/cjs/ProjectLocation/ProjectExtentsDecoration.js.map +1 -1
  25. package/lib/cjs/ProjectLocation/ProjectGeolocation.d.ts +135 -135
  26. package/lib/cjs/ProjectLocation/ProjectGeolocation.js +532 -532
  27. package/lib/cjs/ProjectLocation/ProjectGeolocation.js.map +1 -1
  28. package/lib/cjs/SketchTools.d.ts +304 -304
  29. package/lib/cjs/SketchTools.js +1704 -1705
  30. package/lib/cjs/SketchTools.js.map +1 -1
  31. package/lib/cjs/SolidModelingTools.d.ts +380 -380
  32. package/lib/cjs/SolidModelingTools.js +1452 -1462
  33. package/lib/cjs/SolidModelingTools.js.map +1 -1
  34. package/lib/cjs/SolidPrimitiveTools.d.ts +318 -318
  35. package/lib/cjs/SolidPrimitiveTools.js +1372 -1378
  36. package/lib/cjs/SolidPrimitiveTools.js.map +1 -1
  37. package/lib/cjs/TransformElementsTool.d.ts +164 -164
  38. package/lib/cjs/TransformElementsTool.js +652 -652
  39. package/lib/cjs/TransformElementsTool.js.map +1 -1
  40. package/lib/cjs/UndoRedoTool.d.ts +16 -16
  41. package/lib/cjs/UndoRedoTool.js +41 -42
  42. package/lib/cjs/UndoRedoTool.js.map +1 -1
  43. package/lib/cjs/editor-frontend.d.ts +17 -17
  44. package/lib/cjs/editor-frontend.js +37 -33
  45. package/lib/cjs/editor-frontend.js.map +1 -1
  46. package/lib/esm/CreateElementTool.d.ts +100 -100
  47. package/lib/esm/CreateElementTool.js +317 -319
  48. package/lib/esm/CreateElementTool.js.map +1 -1
  49. package/lib/esm/DeleteElementsTool.d.ts +13 -13
  50. package/lib/esm/DeleteElementsTool.js +35 -34
  51. package/lib/esm/DeleteElementsTool.js.map +1 -1
  52. package/lib/esm/EditTool.d.ts +38 -38
  53. package/lib/esm/EditTool.js +77 -77
  54. package/lib/esm/EditTool.js.map +1 -1
  55. package/lib/esm/EditToolIpc.d.ts +18 -18
  56. package/lib/esm/EditToolIpc.js +24 -24
  57. package/lib/esm/ElementGeometryTool.d.ts +147 -147
  58. package/lib/esm/ElementGeometryTool.js +696 -701
  59. package/lib/esm/ElementGeometryTool.js.map +1 -1
  60. package/lib/esm/ModifyCurveTools.d.ts +139 -139
  61. package/lib/esm/ModifyCurveTools.js +771 -775
  62. package/lib/esm/ModifyCurveTools.js.map +1 -1
  63. package/lib/esm/ModifyElementTool.d.ts +47 -47
  64. package/lib/esm/ModifyElementTool.js +172 -172
  65. package/lib/esm/ModifyElementTool.js.map +1 -1
  66. package/lib/esm/ProjectLocation/ProjectExtentsDecoration.d.ts +135 -135
  67. package/lib/esm/ProjectLocation/ProjectExtentsDecoration.js +818 -814
  68. package/lib/esm/ProjectLocation/ProjectExtentsDecoration.js.map +1 -1
  69. package/lib/esm/ProjectLocation/ProjectGeolocation.d.ts +135 -135
  70. package/lib/esm/ProjectLocation/ProjectGeolocation.js +529 -526
  71. package/lib/esm/ProjectLocation/ProjectGeolocation.js.map +1 -1
  72. package/lib/esm/SketchTools.d.ts +304 -304
  73. package/lib/esm/SketchTools.js +1700 -1695
  74. package/lib/esm/SketchTools.js.map +1 -1
  75. package/lib/esm/SolidModelingTools.d.ts +380 -380
  76. package/lib/esm/SolidModelingTools.js +1444 -1437
  77. package/lib/esm/SolidModelingTools.js.map +1 -1
  78. package/lib/esm/SolidPrimitiveTools.d.ts +318 -318
  79. package/lib/esm/SolidPrimitiveTools.js +1368 -1367
  80. package/lib/esm/SolidPrimitiveTools.js.map +1 -1
  81. package/lib/esm/TransformElementsTool.d.ts +164 -164
  82. package/lib/esm/TransformElementsTool.js +647 -644
  83. package/lib/esm/TransformElementsTool.js.map +1 -1
  84. package/lib/esm/UndoRedoTool.d.ts +16 -16
  85. package/lib/esm/UndoRedoTool.js +38 -36
  86. package/lib/esm/UndoRedoTool.js.map +1 -1
  87. package/lib/esm/editor-frontend.d.ts +17 -17
  88. package/lib/esm/editor-frontend.js +21 -21
  89. package/package.json +20 -20
@@ -1,320 +1,318 @@
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
+ const category = this.briefcase?.editorToolSettings.category;
140
+ if (undefined === category)
141
+ throw new IModelError(IModelStatus.InvalidCategory, "");
142
+ return category;
143
+ }
144
+ get targetModelId() {
145
+ const model = this.briefcase?.editorToolSettings.model;
146
+ if (undefined === model)
147
+ throw new IModelError(IModelStatus.BadModel, "");
148
+ return model;
149
+ }
150
+ isCompatibleViewport(vp, isSelectedViewChange) {
151
+ if (!vp?.iModel.isBriefcaseConnection())
152
+ return false;
153
+ return undefined !== vp.iModel.editorToolSettings.model && super.isCompatibleViewport(vp, isSelectedViewChange);
154
+ }
155
+ /** Whether [[setupAndPromptForNextAction]] should call [[AccuSnap.enableSnap]] for current tool phase.
156
+ * @return true to enable snapping to elements.
157
+ */
158
+ get wantAccuSnap() { return false; }
159
+ /** Whether to automatically start element dynamics on button event.
160
+ * @return true if tool will implement [[InteractiveTool.onDynamicFrame]] to show element dynamics.
161
+ */
162
+ get wantDynamics() { return false; }
163
+ /** Whether tool is ready to insert the new element.
164
+ * @return true to call [[createElement]].
165
+ */
166
+ isComplete(_ev) { return false; }
167
+ /** Orchestrates advancing the internal state of the tool on a data button event.
168
+ * - Gather input: Initiates element dynamics and accepts additional points as required.
169
+ * - Complete operation: Create new element, restart or exit tool.
170
+ * @returns EventHandled.Yes if onReinitialize was called to restart or exit tool.
171
+ */
172
+ async processDataButton(ev) {
173
+ if (this.isComplete(ev)) {
174
+ await this.createElement();
175
+ await this.onReinitialize();
176
+ return EventHandled.Yes;
177
+ }
178
+ this.setupAndPromptForNextAction();
179
+ if (!this.isDynamicsStarted && this.wantDynamics)
180
+ this.beginDynamics();
181
+ return EventHandled.No;
182
+ }
183
+ async onDataButtonDown(ev) {
184
+ return this.processDataButton(ev);
185
+ }
186
+ async onResetButtonUp(_ev) {
187
+ await this.onReinitialize();
188
+ return EventHandled.No;
189
+ }
190
+ /** Setup initial tool state, prompts, etc. */
191
+ async onPostInstall() {
192
+ await super.onPostInstall();
193
+ this.setupAndPromptForNextAction();
194
+ }
195
+ /** Restore tool assistance after no longer being suspended by either a [[ViewTool]] or [[InputCollector]]. */
196
+ async onUnsuspend() {
197
+ this.provideToolAssistance();
198
+ }
199
+ /** Setup auto-locate, AccuSnap, AccuDraw, and supply tool assistance. */
200
+ setupAndPromptForNextAction() {
201
+ IModelApp.accuSnap.enableSnap(this.wantAccuSnap);
202
+ this.provideToolAssistance();
203
+ }
204
+ /** Sub-classes should override to provide tool specific instructions. */
205
+ provideToolAssistance(mainInstrText, additionalInstr) {
206
+ const mainMsg = "ElementSet.Prompts.IdentifyPoint";
207
+ const leftMsg = "ElementSet.Inputs.AcceptPoint";
208
+ const rightMsg = "ElementSet.Inputs.Cancel";
209
+ const mouseInstructions = [];
210
+ const touchInstructions = [];
211
+ if (!ToolAssistance.createTouchCursorInstructions(touchInstructions))
212
+ touchInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.OneTouchTap, CoreTools.translate(leftMsg), false, ToolAssistanceInputMethod.Touch));
213
+ mouseInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.LeftClick, CoreTools.translate(leftMsg), false, ToolAssistanceInputMethod.Mouse));
214
+ touchInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.TwoTouchTap, CoreTools.translate(rightMsg), false, ToolAssistanceInputMethod.Touch));
215
+ mouseInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.RightClick, CoreTools.translate(rightMsg), false, ToolAssistanceInputMethod.Mouse));
216
+ if (undefined !== additionalInstr) {
217
+ for (const instr of additionalInstr) {
218
+ if (ToolAssistanceInputMethod.Touch === instr.inputMethod)
219
+ touchInstructions.push(instr);
220
+ else
221
+ mouseInstructions.push(instr);
222
+ }
223
+ }
224
+ const sections = [];
225
+ sections.push(ToolAssistance.createSection(mouseInstructions, ToolAssistance.inputsLabel));
226
+ sections.push(ToolAssistance.createSection(touchInstructions, ToolAssistance.inputsLabel));
227
+ const mainInstruction = ToolAssistance.createInstruction(this.iconSpec, undefined !== mainInstrText ? mainInstrText : CoreTools.translate(mainMsg));
228
+ const instructions = ToolAssistance.createInstructions(mainInstruction, sections);
229
+ IModelApp.notifications.setToolAssistance(instructions);
230
+ }
231
+ }
232
+ /** @alpha Placement tool base class for creating new elements that use dynamics to show intermediate results. */
233
+ export class CreateElementWithDynamicsTool extends CreateElementTool {
234
+ get wantAccuSnap() { return true; }
235
+ get wantDynamics() { return true; }
236
+ clearGraphics() {
237
+ if (undefined === this._graphicsProvider)
238
+ return;
239
+ this._graphicsProvider.cleanupGraphic();
240
+ this._graphicsProvider = undefined;
241
+ }
242
+ async createGraphics(ev) {
243
+ if (!await this.updateDynamicData(ev))
244
+ return;
245
+ const placement = this.getPlacementProps();
246
+ if (undefined === placement)
247
+ return;
248
+ const geometry = this.getGeometryProps(placement);
249
+ if (undefined === geometry)
250
+ return;
251
+ if (undefined === this._graphicsProvider)
252
+ this._graphicsProvider = new DynamicGraphicsProvider(this.iModel, this.toolId);
253
+ // Set chord tolerance for curved surfaces...
254
+ if (ev.viewport)
255
+ this._graphicsProvider.chordTolerance = computeChordToleranceFromPoint(ev.viewport, ev.point);
256
+ await this._graphicsProvider.createGraphic(this.targetCategory, placement, geometry);
257
+ }
258
+ onDynamicFrame(_ev, context) {
259
+ if (undefined !== this._graphicsProvider)
260
+ this._graphicsProvider.addGraphic(context);
261
+ }
262
+ async onMouseMotion(ev) {
263
+ return this.createGraphics(ev);
264
+ }
265
+ async doCreateElement(_props, _data) { }
266
+ async updateElementData(_ev, _isDynamics) { }
267
+ async updateDynamicData(ev) {
268
+ if (!IModelApp.viewManager.inDynamicsMode)
269
+ return false; // Don't need to create graphic if dynamics aren't yet active...
270
+ await this.updateElementData(ev, true);
271
+ return true;
272
+ }
273
+ async createElement() {
274
+ const placement = this.getPlacementProps();
275
+ if (undefined === placement)
276
+ return;
277
+ const geometry = this.getGeometryProps(placement);
278
+ if (undefined === geometry)
279
+ return;
280
+ const elemProps = this.getElementProps(placement);
281
+ if (undefined === elemProps)
282
+ return;
283
+ let data;
284
+ if ("flatbuffer" === geometry.format) {
285
+ data = { entryArray: geometry.data };
286
+ delete elemProps.geom; // Leave unchanged until replaced by flatbuffer geometry...
287
+ }
288
+ else {
289
+ elemProps.geom = geometry.data;
290
+ }
291
+ return this.doCreateElement(elemProps, data);
292
+ }
293
+ setupAccuDraw() { }
294
+ setupAndPromptForNextAction() {
295
+ this.setupAccuDraw();
296
+ super.setupAndPromptForNextAction();
297
+ }
298
+ async acceptPoint(ev) {
299
+ await this.updateElementData(ev, false);
300
+ return true;
301
+ }
302
+ async onDataButtonDown(ev) {
303
+ if (!await this.acceptPoint(ev))
304
+ return EventHandled.Yes;
305
+ return super.onDataButtonDown(ev);
306
+ }
307
+ async cancelPoint(_ev) { return true; }
308
+ async onResetButtonUp(ev) {
309
+ if (!await this.cancelPoint(ev))
310
+ return EventHandled.Yes;
311
+ return super.onResetButtonUp(ev);
312
+ }
313
+ async onCleanup() {
314
+ this.clearGraphics();
315
+ return super.onCleanup();
316
+ }
317
+ }
320
318
  //# sourceMappingURL=CreateElementTool.js.map