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