@itwin/editor-backend 3.0.0-dev.100

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.
@@ -0,0 +1,622 @@
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ /** @packageDocumentation
7
+ * @module Editing
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.SolidModelingCommand = exports.BasicManipulationCommand = void 0;
11
+ const core_bentley_1 = require("@itwin/core-bentley");
12
+ const core_geometry_1 = require("@itwin/core-geometry");
13
+ const core_common_1 = require("@itwin/core-common");
14
+ const editor_common_1 = require("@itwin/editor-common");
15
+ const EditCommand_1 = require("./EditCommand");
16
+ /** @alpha */
17
+ class BasicManipulationCommand extends EditCommand_1.EditCommand {
18
+ constructor(iModel, _str) {
19
+ super(iModel);
20
+ this._str = _str;
21
+ }
22
+ async deleteElements(ids) {
23
+ for (const id of core_bentley_1.CompressedId64Set.iterable(ids))
24
+ this.iModel.elements.deleteElement(id);
25
+ return core_bentley_1.IModelStatus.Success;
26
+ }
27
+ async transformPlacement(ids, transProps) {
28
+ const transform = core_geometry_1.Transform.fromJSON(transProps);
29
+ for (const id of core_bentley_1.CompressedId64Set.iterable(ids)) {
30
+ const element = this.iModel.elements.getElement(id);
31
+ if (!element.placement.isValid)
32
+ continue; // Ignore assembly parents w/o geometry, etc...
33
+ element.placement.multiplyTransform(transform);
34
+ this.iModel.elements.updateElement(element);
35
+ }
36
+ return core_bentley_1.IModelStatus.Success;
37
+ }
38
+ async rotatePlacement(ids, matrixProps, aboutCenter) {
39
+ const matrix = core_geometry_1.Matrix3d.fromJSON(matrixProps);
40
+ for (const id of core_bentley_1.CompressedId64Set.iterable(ids)) {
41
+ const element = this.iModel.elements.getElement(id);
42
+ if (!element.placement.isValid)
43
+ continue; // Ignore assembly parents w/o geometry, etc...
44
+ const fixedPoint = aboutCenter ? element.placement.calculateRange().center : core_geometry_1.Point3d.createFrom(element.placement.origin);
45
+ const transform = core_geometry_1.Transform.createFixedPointAndMatrix(fixedPoint, matrix);
46
+ element.placement.multiplyTransform(transform);
47
+ this.iModel.elements.updateElement(element);
48
+ }
49
+ return core_bentley_1.IModelStatus.Success;
50
+ }
51
+ async insertGeometricElement(props, data) {
52
+ const newElem = this.iModel.elements.createElement(props);
53
+ const newId = this.iModel.elements.insertElement(newElem);
54
+ if (undefined === data)
55
+ return newId;
56
+ const updateProps = {
57
+ elementId: newId,
58
+ entryArray: data.entryArray,
59
+ isWorld: data.isWorld,
60
+ viewIndependent: data.viewIndependent,
61
+ };
62
+ const status = this.iModel.elementGeometryUpdate(updateProps);
63
+ if (core_bentley_1.DbResult.BE_SQLITE_OK !== status) {
64
+ this.iModel.elements.deleteElement(newId); // clean up element...
65
+ throw new core_common_1.IModelError(status, "Error updating element geometry");
66
+ }
67
+ return newId;
68
+ }
69
+ async insertGeometryPart(props, data) {
70
+ if (undefined === props.geom && undefined !== data) {
71
+ const builder = new core_common_1.GeometryStreamBuilder();
72
+ builder.appendGeometry(core_geometry_1.PointString3d.create(core_geometry_1.Point3d.createZero()));
73
+ props.geom = builder.geometryStream; // can't insert a DgnGeometryPart without geometry...
74
+ }
75
+ const newElem = this.iModel.elements.createElement(props);
76
+ const newId = this.iModel.elements.insertElement(newElem);
77
+ if (undefined === data)
78
+ return newId;
79
+ const updateProps = {
80
+ elementId: newId,
81
+ entryArray: data.entryArray,
82
+ is2dPart: data.is2dPart,
83
+ };
84
+ const status = this.iModel.elementGeometryUpdate(updateProps);
85
+ if (core_bentley_1.DbResult.BE_SQLITE_OK !== status) {
86
+ this.iModel.elements.deleteElement(newId); // clean up element...
87
+ throw new core_common_1.IModelError(status, "Error updating part geometry");
88
+ }
89
+ return newId;
90
+ }
91
+ async updateGeometricElement(propsOrId, data) {
92
+ let props;
93
+ if (typeof propsOrId === "string") {
94
+ if (undefined === data)
95
+ throw new core_common_1.IModelError(core_bentley_1.DbResult.BE_SQLITE_ERROR, "Flatbuffer data required for update by id");
96
+ props = this.iModel.elements.getElement(propsOrId);
97
+ }
98
+ else {
99
+ props = propsOrId;
100
+ }
101
+ if (undefined === props.id)
102
+ throw new core_common_1.IModelError(core_bentley_1.DbResult.BE_SQLITE_ERROR, "Element id required for update");
103
+ this.iModel.elements.updateElement(props);
104
+ if (undefined === data)
105
+ return;
106
+ const updateProps = {
107
+ elementId: props.id,
108
+ entryArray: data.entryArray,
109
+ isWorld: data.isWorld,
110
+ viewIndependent: data.viewIndependent,
111
+ };
112
+ const status = this.iModel.elementGeometryUpdate(updateProps);
113
+ if (core_bentley_1.DbResult.BE_SQLITE_OK !== status) {
114
+ throw new core_common_1.IModelError(status, "Error updating element geometry");
115
+ }
116
+ }
117
+ async requestElementGeometry(elementId, filter) {
118
+ let accepted;
119
+ const onGeometry = (info) => {
120
+ accepted = info;
121
+ if (undefined !== filter) {
122
+ let numDisplayable = 0;
123
+ for (const entry of info.entryArray) {
124
+ if (!core_common_1.ElementGeometry.isDisplayableEntry(entry))
125
+ continue;
126
+ numDisplayable++;
127
+ if (filter.maxDisplayable && numDisplayable > filter.maxDisplayable) {
128
+ accepted = undefined;
129
+ break;
130
+ }
131
+ if (filter.reject && filter.reject.some((opcode) => entry.opcode === opcode)) {
132
+ accepted = undefined;
133
+ break;
134
+ }
135
+ if (filter.accept && !filter.accept.some((opcode) => entry.opcode === opcode)) {
136
+ accepted = undefined;
137
+ break;
138
+ }
139
+ if (undefined === filter.geometry)
140
+ continue;
141
+ let entityType;
142
+ if (filter.geometry.curves && !(filter.geometry.surfaces || filter.geometry.solids))
143
+ entityType = core_common_1.ElementGeometry.isCurve(entry) ? core_common_1.BRepEntity.Type.Wire : undefined; // skip surface/solid opcodes...
144
+ else
145
+ entityType = core_common_1.ElementGeometry.getBRepEntityType(entry);
146
+ switch (entityType) {
147
+ case core_common_1.BRepEntity.Type.Wire:
148
+ if (!filter.geometry.curves)
149
+ accepted = undefined;
150
+ break;
151
+ case core_common_1.BRepEntity.Type.Sheet:
152
+ if (!filter.geometry.surfaces)
153
+ accepted = undefined;
154
+ break;
155
+ case core_common_1.BRepEntity.Type.Solid:
156
+ if (!filter.geometry.solids)
157
+ accepted = undefined;
158
+ break;
159
+ default:
160
+ accepted = undefined;
161
+ break;
162
+ }
163
+ if (undefined === accepted)
164
+ break;
165
+ }
166
+ }
167
+ };
168
+ const requestProps = {
169
+ onGeometry,
170
+ elementId,
171
+ };
172
+ if (core_bentley_1.DbResult.BE_SQLITE_OK !== this.iModel.elementGeometryRequest(requestProps))
173
+ return undefined;
174
+ return accepted;
175
+ }
176
+ async updateProjectExtents(extents) {
177
+ const newExtents = new core_geometry_1.Range3d();
178
+ newExtents.setFromJSON(extents);
179
+ if (newExtents.isNull)
180
+ throw new core_common_1.IModelError(core_bentley_1.DbResult.BE_SQLITE_ERROR, "Invalid project extents");
181
+ this.iModel.updateProjectExtents(newExtents);
182
+ // Set source from calculated to user so connectors preserve the change.
183
+ const unitsProps = { name: "Units", namespace: "dgn_Db" };
184
+ const unitsStr = this.iModel.queryFilePropertyString(unitsProps);
185
+ if (undefined !== unitsStr) {
186
+ const unitsVal = JSON.parse(unitsStr);
187
+ const calculated = 1;
188
+ if (calculated !== unitsVal.extentsSource) {
189
+ unitsVal.extentsSource = calculated;
190
+ this.iModel.saveFileProperty(unitsProps, JSON.stringify(unitsVal));
191
+ }
192
+ }
193
+ }
194
+ async updateEcefLocation(ecefLocation) {
195
+ // Clear GCS that caller already determined was invalid...
196
+ this.iModel.deleteFileProperty({ name: "DgnGCS", namespace: "dgn_Db" });
197
+ const newEcefLocation = new core_common_1.EcefLocation(ecefLocation);
198
+ this.iModel.updateEcefLocation(newEcefLocation);
199
+ }
200
+ }
201
+ exports.BasicManipulationCommand = BasicManipulationCommand;
202
+ BasicManipulationCommand.commandId = editor_common_1.editorBuiltInCmdIds.cmdBasicManipulation;
203
+ var QuerySubEntity;
204
+ (function (QuerySubEntity) {
205
+ /** Return whether the supplied face has a planar surface */
206
+ QuerySubEntity[QuerySubEntity["PlanarFace"] = 0] = "PlanarFace";
207
+ /** Return whether the angle between the normals of the supplied edge's faces never exceeds the internal smooth angle tolerance along the length of the edge */
208
+ QuerySubEntity[QuerySubEntity["SmoothEdge"] = 1] = "SmoothEdge";
209
+ /** Return whether the supplied sub-entity is a laminar edge of a sheet body, i.e. boundary of a single face */
210
+ QuerySubEntity[QuerySubEntity["LaminarEdge"] = 2] = "LaminarEdge";
211
+ /** Return whether the supplied sub-entity is a linear edge */
212
+ QuerySubEntity[QuerySubEntity["LinearEdge"] = 3] = "LinearEdge";
213
+ /** Return whether the angle between the normals of the supplied vertices's edges never exceeds the internal smooth angle tolerance along the length of the edge */
214
+ QuerySubEntity[QuerySubEntity["SmoothVertex"] = 4] = "SmoothVertex";
215
+ })(QuerySubEntity || (QuerySubEntity = {}));
216
+ var QueryBody;
217
+ (function (QueryBody) {
218
+ /** Return whether the geometric primitive index is a disjoint body */
219
+ QueryBody[QueryBody["DisjointBody"] = 0] = "DisjointBody";
220
+ /** Return whether the geometric primitive index is a sheet body with a single planar face */
221
+ QueryBody[QueryBody["SingleFacePlanarSheet"] = 1] = "SingleFacePlanarSheet";
222
+ /** Return whether the geometric primitive index is a sheet or solid entity that has all planar faces */
223
+ QueryBody[QueryBody["OnlyPlanarFaces"] = 2] = "OnlyPlanarFaces";
224
+ /** Return whether the geometric primitive index is a body with any edge that is non-linear or any face that is non-planar */
225
+ QueryBody[QueryBody["CurvedFaceOrEdge"] = 3] = "CurvedFaceOrEdge";
226
+ })(QueryBody || (QueryBody = {}));
227
+ var OperationType;
228
+ (function (OperationType) {
229
+ OperationType[OperationType["GeometrySummary"] = 0] = "GeometrySummary";
230
+ OperationType[OperationType["SubEntityGeometry"] = 1] = "SubEntityGeometry";
231
+ OperationType[OperationType["SubEntityParameterRange"] = 2] = "SubEntityParameterRange";
232
+ OperationType[OperationType["SubEntityEvaluate"] = 3] = "SubEntityEvaluate";
233
+ OperationType[OperationType["SubEntityQuery"] = 4] = "SubEntityQuery";
234
+ OperationType[OperationType["BodyQuery"] = 5] = "BodyQuery";
235
+ OperationType[OperationType["BodySubEntities"] = 6] = "BodySubEntities";
236
+ OperationType[OperationType["ConnectedSubEntity"] = 7] = "ConnectedSubEntity";
237
+ OperationType[OperationType["LocateSubEntity"] = 8] = "LocateSubEntity";
238
+ OperationType[OperationType["LocateFace"] = 9] = "LocateFace";
239
+ OperationType[OperationType["ClosestSubEntity"] = 10] = "ClosestSubEntity";
240
+ OperationType[OperationType["ClosestFace"] = 11] = "ClosestFace";
241
+ OperationType[OperationType["ClosestPoint"] = 12] = "ClosestPoint";
242
+ OperationType[OperationType["PointInside"] = 13] = "PointInside";
243
+ OperationType[OperationType["BooleanOp"] = 14] = "BooleanOp";
244
+ OperationType[OperationType["SewSheets"] = 15] = "SewSheets";
245
+ OperationType[OperationType["ThickenSheets"] = 16] = "ThickenSheets";
246
+ OperationType[OperationType["OffsetFaces"] = 17] = "OffsetFaces";
247
+ OperationType[OperationType["OffsetEdges"] = 18] = "OffsetEdges";
248
+ OperationType[OperationType["HollowFaces"] = 19] = "HollowFaces";
249
+ OperationType[OperationType["SweepFaces"] = 20] = "SweepFaces";
250
+ OperationType[OperationType["SpinFaces"] = 21] = "SpinFaces";
251
+ OperationType[OperationType["DeleteSubEntity"] = 22] = "DeleteSubEntity";
252
+ OperationType[OperationType["TransformSubEntity"] = 23] = "TransformSubEntity";
253
+ OperationType[OperationType["Blend"] = 24] = "Blend";
254
+ OperationType[OperationType["Chamfer"] = 25] = "Chamfer";
255
+ OperationType[OperationType["Cut"] = 26] = "Cut";
256
+ OperationType[OperationType["Emboss"] = 27] = "Emboss";
257
+ OperationType[OperationType["Imprint"] = 28] = "Imprint";
258
+ OperationType[OperationType["SweepBody"] = 29] = "SweepBody";
259
+ OperationType[OperationType["SpinBody"] = 30] = "SpinBody";
260
+ OperationType[OperationType["SweepPath"] = 31] = "SweepPath";
261
+ OperationType[OperationType["Loft"] = 32] = "Loft";
262
+ })(OperationType || (OperationType = {}));
263
+ /** @alpha */
264
+ class SolidModelingCommand extends BasicManipulationCommand {
265
+ async updateElementGeometryCache(props) {
266
+ return this.iModel.nativeDb.updateElementGeometryCache(props);
267
+ }
268
+ async createElementGeometryCache(id, filter) {
269
+ var _a, _b, _c, _d, _e;
270
+ const result = await this.updateElementGeometryCache({ id });
271
+ if (core_bentley_1.BentleyStatus.SUCCESS !== result.status)
272
+ return false;
273
+ if (undefined === filter)
274
+ return true;
275
+ if (filter.minGeom && (undefined === result.numGeom || filter.minGeom > result.numGeom))
276
+ return false;
277
+ if (filter.maxGeom && (undefined === result.numGeom || filter.maxGeom < result.numGeom))
278
+ return false;
279
+ if (!filter.parts && ((_a = result.numPart) !== null && _a !== void 0 ? _a : 0 > 0))
280
+ return false;
281
+ if (!filter.curves && ((_b = result.numCurve) !== null && _b !== void 0 ? _b : 0 > 0))
282
+ return false;
283
+ if (!filter.surfaces && ((_c = result.numSurface) !== null && _c !== void 0 ? _c : 0 > 0))
284
+ return false;
285
+ if (!filter.solids && ((_d = result.numSolid) !== null && _d !== void 0 ? _d : 0 > 0))
286
+ return false;
287
+ if (!filter.other && ((_e = result.numOther) !== null && _e !== void 0 ? _e : 0 > 0))
288
+ return false;
289
+ return true;
290
+ }
291
+ async clearElementGeometryCache() {
292
+ await this.updateElementGeometryCache({});
293
+ }
294
+ async summarizeElementGeometryCache(id) {
295
+ let accepted;
296
+ const onResult = (info) => {
297
+ accepted = info;
298
+ };
299
+ const params = { onResult };
300
+ const props = { id, op: OperationType.GeometrySummary, params };
301
+ this.iModel.nativeDb.elementGeometryCacheOperation(props);
302
+ return accepted;
303
+ }
304
+ requestSubEntityGeometry(id, subEntity) {
305
+ let accepted;
306
+ const onResult = (info) => {
307
+ accepted = info;
308
+ };
309
+ const params = { subEntity, onResult };
310
+ const props = { id, op: OperationType.SubEntityGeometry, params };
311
+ this.iModel.nativeDb.elementGeometryCacheOperation(props);
312
+ return accepted;
313
+ }
314
+ async getSubEntityGeometry(id, subEntity, opts) {
315
+ const geometryProps = this.requestSubEntityGeometry(id, subEntity);
316
+ if (undefined === (geometryProps === null || geometryProps === void 0 ? void 0 : geometryProps.geometry) || undefined === (geometryProps === null || geometryProps === void 0 ? void 0 : geometryProps.category))
317
+ return undefined;
318
+ const resultProps = {};
319
+ if (opts.wantGeometry)
320
+ resultProps.geometry = geometryProps.geometry;
321
+ if (opts.wantRange)
322
+ resultProps.range = ((geometryProps === null || geometryProps === void 0 ? void 0 : geometryProps.range) ? core_common_1.ElementGeometry.toElementAlignedBox3d(geometryProps === null || geometryProps === void 0 ? void 0 : geometryProps.range) : undefined);
323
+ if (opts.wantAppearance) {
324
+ const appearance = { category: geometryProps.category };
325
+ appearance.subCategory = geometryProps.subCategory;
326
+ appearance.material = geometryProps.material;
327
+ appearance.color = geometryProps.color;
328
+ appearance.transparency = geometryProps.transparency;
329
+ appearance.weight = geometryProps.weight;
330
+ resultProps.appearance = appearance;
331
+ }
332
+ if (!opts.wantGraphic)
333
+ return resultProps;
334
+ const requestId = opts.requestId ? opts.requestId : `SubEntity:${id}-${subEntity.id}`;
335
+ const toleranceLog10 = (opts.chordTolerance ? Math.floor(Math.log10(opts.chordTolerance)) : -2);
336
+ const requestProps = {
337
+ id: requestId,
338
+ modelId: this.iModel.iModelId,
339
+ toleranceLog10,
340
+ type: "3d",
341
+ placement: { origin: core_geometry_1.Point3d.createZero(), angles: core_geometry_1.YawPitchRollAngles.createDegrees(0, 0, 0) },
342
+ categoryId: geometryProps.category,
343
+ geometry: { format: "flatbuffer", data: [geometryProps.geometry] },
344
+ };
345
+ resultProps.graphic = await this.iModel.generateElementGraphics(requestProps);
346
+ return resultProps;
347
+ }
348
+ async getSubEntityParameterRange(id, subEntity) {
349
+ let accepted;
350
+ const onResult = (info) => {
351
+ accepted = info;
352
+ };
353
+ const params = { subEntity, onResult };
354
+ const props = { id, op: OperationType.SubEntityParameterRange, params };
355
+ this.iModel.nativeDb.elementGeometryCacheOperation(props);
356
+ return accepted;
357
+ }
358
+ async evaluateSubEntity(id, subEntity, uParam, vParam) {
359
+ let accepted;
360
+ const onResult = (info) => {
361
+ accepted = info;
362
+ };
363
+ const params = { subEntity, uParam, vParam, onResult };
364
+ const props = { id, op: OperationType.SubEntityEvaluate, params };
365
+ this.iModel.nativeDb.elementGeometryCacheOperation(props);
366
+ return accepted;
367
+ }
368
+ async subEntityQuery(id, subEntity, query) {
369
+ let accepted = false;
370
+ const onResult = (info) => {
371
+ accepted = info;
372
+ };
373
+ const params = { subEntity, query, onResult };
374
+ const props = { id, op: OperationType.SubEntityQuery, params };
375
+ this.iModel.nativeDb.elementGeometryCacheOperation(props);
376
+ return accepted;
377
+ }
378
+ async isPlanarFace(id, subEntity) {
379
+ return this.subEntityQuery(id, subEntity, QuerySubEntity.PlanarFace);
380
+ }
381
+ async isSmoothEdge(id, subEntity) {
382
+ return this.subEntityQuery(id, subEntity, QuerySubEntity.SmoothEdge);
383
+ }
384
+ async isLaminarEdge(id, subEntity) {
385
+ return this.subEntityQuery(id, subEntity, QuerySubEntity.LaminarEdge);
386
+ }
387
+ async isLinearEdge(id, subEntity) {
388
+ return this.subEntityQuery(id, subEntity, QuerySubEntity.LinearEdge);
389
+ }
390
+ async isSmoothVertex(id, subEntity) {
391
+ return this.subEntityQuery(id, subEntity, QuerySubEntity.SmoothVertex);
392
+ }
393
+ async bodyQuery(id, index, query) {
394
+ let accepted = false;
395
+ const onResult = (info) => {
396
+ accepted = info;
397
+ };
398
+ const params = { index, query, onResult };
399
+ const props = { id, op: OperationType.BodyQuery, params };
400
+ this.iModel.nativeDb.elementGeometryCacheOperation(props);
401
+ return accepted;
402
+ }
403
+ async isDisjointBody(id, index) {
404
+ return this.bodyQuery(id, index, QueryBody.DisjointBody);
405
+ }
406
+ async isSingleFacePlanarSheet(id, index) {
407
+ return this.bodyQuery(id, index, QueryBody.SingleFacePlanarSheet);
408
+ }
409
+ async hasOnlyPlanarFaces(id, index) {
410
+ return this.bodyQuery(id, index, QueryBody.OnlyPlanarFaces);
411
+ }
412
+ async hasCurvedFaceOrEdge(id, index) {
413
+ return this.bodyQuery(id, index, QueryBody.CurvedFaceOrEdge);
414
+ }
415
+ async getBodySubEntities(id, type, firstOnly) {
416
+ let accepted;
417
+ const onResult = (info) => {
418
+ accepted = info;
419
+ };
420
+ const params = { type, firstOnly, onResult };
421
+ const props = { id, op: OperationType.BodySubEntities, params };
422
+ this.iModel.nativeDb.elementGeometryCacheOperation(props);
423
+ return accepted;
424
+ }
425
+ async getConnectedSubEntities(id, subEntity, type, options) {
426
+ let accepted;
427
+ const onResult = (info) => {
428
+ accepted = info;
429
+ };
430
+ const params = { subEntity, type, options, onResult };
431
+ const props = { id, op: OperationType.ConnectedSubEntity, params };
432
+ this.iModel.nativeDb.elementGeometryCacheOperation(props);
433
+ return accepted;
434
+ }
435
+ async locateSubEntities(id, point, direction, options) {
436
+ let accepted;
437
+ const onResult = (info) => {
438
+ accepted = info;
439
+ };
440
+ const params = { point, direction, options, onResult };
441
+ const props = { id, op: OperationType.LocateSubEntity, params };
442
+ this.iModel.nativeDb.elementGeometryCacheOperation(props);
443
+ return accepted;
444
+ }
445
+ async locateFace(id, subEntity, point, direction) {
446
+ let accepted;
447
+ const onResult = (info) => {
448
+ accepted = info;
449
+ };
450
+ const params = { subEntity, point, direction, onResult };
451
+ const props = { id, op: OperationType.LocateFace, params };
452
+ this.iModel.nativeDb.elementGeometryCacheOperation(props);
453
+ return accepted;
454
+ }
455
+ async getClosestSubEntity(id, point) {
456
+ let accepted;
457
+ const onResult = (info) => {
458
+ accepted = info;
459
+ };
460
+ const params = { point, onResult };
461
+ const props = { id, op: OperationType.ClosestSubEntity, params };
462
+ this.iModel.nativeDb.elementGeometryCacheOperation(props);
463
+ return accepted;
464
+ }
465
+ async getClosestFace(id, point, direction) {
466
+ let accepted;
467
+ const onResult = (info) => {
468
+ accepted = info;
469
+ };
470
+ const params = { point, direction, onResult };
471
+ const props = { id, op: OperationType.ClosestFace, params };
472
+ this.iModel.nativeDb.elementGeometryCacheOperation(props);
473
+ return accepted;
474
+ }
475
+ async getClosestPoint(id, subEntity, point) {
476
+ let accepted;
477
+ const onResult = (info) => {
478
+ accepted = info;
479
+ };
480
+ const params = { subEntity, point, onResult };
481
+ const props = { id, op: OperationType.ClosestPoint, params };
482
+ this.iModel.nativeDb.elementGeometryCacheOperation(props);
483
+ return accepted;
484
+ }
485
+ async isPointInside(id, point) {
486
+ let accepted;
487
+ const onResult = (info) => {
488
+ accepted = info;
489
+ };
490
+ const params = { point, onResult };
491
+ const props = { id, op: OperationType.PointInside, params };
492
+ this.iModel.nativeDb.elementGeometryCacheOperation(props);
493
+ return accepted;
494
+ }
495
+ async getElementGeometryResults(id, info, opts) {
496
+ if (0 === info.entryArray.length || undefined === info.categoryId || undefined === info.bbox)
497
+ return undefined;
498
+ const resultProps = {};
499
+ if (opts.wantGeometry)
500
+ resultProps.geometry = info;
501
+ if (opts.wantRange)
502
+ resultProps.range = core_common_1.ElementGeometry.toElementAlignedBox3d(info.bbox);
503
+ if (opts.wantAppearance)
504
+ resultProps.categoryId = info.categoryId;
505
+ if (!(opts.wantGraphic || opts.writeChanges))
506
+ return resultProps;
507
+ let placement;
508
+ const sourceToWorld = (undefined === (info === null || info === void 0 ? void 0 : info.sourceToWorld) ? undefined : core_common_1.ElementGeometry.toTransform(info.sourceToWorld));
509
+ if (undefined === sourceToWorld) {
510
+ placement = { origin: core_geometry_1.Point3d.createZero(), angles: core_geometry_1.YawPitchRollAngles.createDegrees(0, 0, 0) };
511
+ }
512
+ else {
513
+ const origin = sourceToWorld.getOrigin();
514
+ const angles = new core_geometry_1.YawPitchRollAngles();
515
+ core_geometry_1.YawPitchRollAngles.createFromMatrix3d(sourceToWorld.matrix, angles);
516
+ placement = { origin, angles };
517
+ }
518
+ if (opts.writeChanges) {
519
+ if (opts.insertProps) {
520
+ opts.insertProps.placement = placement; // entryArray is local to this placement...
521
+ delete opts.insertProps.geom; // Ignore geometry if present...
522
+ resultProps.elementId = await this.insertGeometricElement(opts.insertProps, { entryArray: info.entryArray });
523
+ }
524
+ else {
525
+ const updateProps = this.iModel.elements.getElementProps({ id });
526
+ updateProps.category = info.categoryId; // allow category change...
527
+ updateProps.placement = placement; // entryArray is local to this placement...
528
+ await this.updateGeometricElement(updateProps, { entryArray: info.entryArray });
529
+ resultProps.elementId = id;
530
+ }
531
+ }
532
+ if (!opts.wantGraphic)
533
+ return resultProps;
534
+ const requestId = opts.requestId ? opts.requestId : `EGCacheOp:${id}`;
535
+ const toleranceLog10 = (opts.chordTolerance ? Math.floor(Math.log10(opts.chordTolerance)) : -2);
536
+ const requestProps = {
537
+ id: requestId,
538
+ modelId: this.iModel.iModelId,
539
+ toleranceLog10,
540
+ type: "3d",
541
+ placement,
542
+ categoryId: info.categoryId,
543
+ geometry: { format: "flatbuffer", data: info.entryArray },
544
+ };
545
+ resultProps.graphic = await this.iModel.generateElementGraphics(requestProps);
546
+ return resultProps;
547
+ }
548
+ async doElementGeometryOperation(props, opts) {
549
+ let accepted;
550
+ const onGeometry = (info) => {
551
+ accepted = info;
552
+ };
553
+ props.onGeometry = onGeometry;
554
+ this.iModel.nativeDb.elementGeometryCacheOperation(props);
555
+ if (undefined === accepted)
556
+ return undefined;
557
+ return this.getElementGeometryResults(props.id, accepted, opts);
558
+ }
559
+ async booleanOperation(id, params, opts) {
560
+ const props = { id, op: OperationType.BooleanOp, params };
561
+ const resultProps = await this.doElementGeometryOperation(props, opts);
562
+ // target insert = keep tools, target update = delete tools...
563
+ if (undefined !== resultProps && opts.writeChanges && undefined === opts.insertProps) {
564
+ for (const toolId of params.tools)
565
+ this.iModel.elements.deleteElement(toolId);
566
+ }
567
+ return resultProps;
568
+ }
569
+ async sewSheets(id, params, opts) {
570
+ const props = { id, op: OperationType.SewSheets, params };
571
+ const resultProps = await this.doElementGeometryOperation(props, opts);
572
+ // target insert = keep tools, target update = delete tools...
573
+ if (undefined !== resultProps && opts.writeChanges && undefined === opts.insertProps) {
574
+ for (const toolId of params.tools)
575
+ this.iModel.elements.deleteElement(toolId);
576
+ }
577
+ return resultProps;
578
+ }
579
+ async thickenSheets(id, params, opts) {
580
+ const props = { id, op: OperationType.ThickenSheets, params };
581
+ return this.doElementGeometryOperation(props, opts);
582
+ }
583
+ async offsetFaces(id, params, opts) {
584
+ const props = { id, op: OperationType.OffsetFaces, params };
585
+ return this.doElementGeometryOperation(props, opts);
586
+ }
587
+ async offsetEdges(id, params, opts) {
588
+ const props = { id, op: OperationType.OffsetEdges, params };
589
+ return this.doElementGeometryOperation(props, opts);
590
+ }
591
+ async hollowFaces(id, params, opts) {
592
+ const props = { id, op: OperationType.HollowFaces, params };
593
+ return this.doElementGeometryOperation(props, opts);
594
+ }
595
+ async sweepFaces(id, params, opts) {
596
+ const props = { id, op: OperationType.SweepFaces, params };
597
+ return this.doElementGeometryOperation(props, opts);
598
+ }
599
+ async spinFaces(id, params, opts) {
600
+ const props = { id, op: OperationType.SpinFaces, params };
601
+ return this.doElementGeometryOperation(props, opts);
602
+ }
603
+ async deleteSubEntities(id, params, opts) {
604
+ const props = { id, op: OperationType.DeleteSubEntity, params };
605
+ return this.doElementGeometryOperation(props, opts);
606
+ }
607
+ async transformSubEntities(id, params, opts) {
608
+ const props = { id, op: OperationType.TransformSubEntity, params };
609
+ return this.doElementGeometryOperation(props, opts);
610
+ }
611
+ async blendEdges(id, params, opts) {
612
+ const props = { id, op: OperationType.Blend, params };
613
+ return this.doElementGeometryOperation(props, opts);
614
+ }
615
+ async chamferEdges(id, params, opts) {
616
+ const props = { id, op: OperationType.Chamfer, params };
617
+ return this.doElementGeometryOperation(props, opts);
618
+ }
619
+ }
620
+ exports.SolidModelingCommand = SolidModelingCommand;
621
+ SolidModelingCommand.commandId = editor_common_1.editorBuiltInCmdIds.cmdSolidModeling;
622
+ //# sourceMappingURL=EditBuiltInCommand.js.map