@buerli.io/headless 0.5.0-beta.1 → 0.5.0-beta.3

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,1726 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
26
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
27
+ var m = o[Symbol.asyncIterator], i;
28
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
29
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
30
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
31
+ };
32
+ Object.defineProperty(exports, "__esModule", { value: true });
33
+ /* eslint-disable max-lines */
34
+ const classcad_1 = require("@buerli.io/classcad");
35
+ const core_1 = require("@buerli.io/core");
36
+ const three_1 = require("three");
37
+ const BufferGeometryUtils_ = __importStar(require("three/examples/jsm/utils/BufferGeometryUtils"));
38
+ const selection_1 = require("./utils/selection");
39
+ const featureAPI = classcad_1.ccAPI.feature;
40
+ const sketcherAPI = classcad_1.ccAPI.sketcher;
41
+ const baseModelerAPI = classcad_1.ccAPI.baseModeler;
42
+ const assemblyBuilderAPI = classcad_1.ccAPI.assemblyBuilder;
43
+ const baseUtils = classcad_1.ccUtils.base;
44
+ const asmUtils = classcad_1.ccUtils.assembly;
45
+ let BufferGeometryUtils = BufferGeometryUtils_;
46
+ if (BufferGeometryUtils.BufferGeometryUtils) {
47
+ BufferGeometryUtils = BufferGeometryUtils.BufferGeometryUtils;
48
+ }
49
+ /**
50
+ * Returns the cclass of the given dimension type
51
+ * @param type type of the dimension as string
52
+ * @returns cclass type of given type
53
+ */
54
+ const getDimensionType = (type) => {
55
+ let cclass = classcad_1.CCClasses.CCLinearDimension;
56
+ switch (type) {
57
+ case 'LinearDimension':
58
+ cclass = classcad_1.CCClasses.CCLinearDimension;
59
+ break;
60
+ }
61
+ return cclass;
62
+ };
63
+ /**
64
+ * Transforms the transformation which is local to the ownerId into global
65
+ * transformation and returns it.
66
+ * @param ownerId node to get the global transformation from
67
+ * @param localTransformation transformation local to the owner, will be calculated into global transformation
68
+ * @returns the global transformation from local transformation to owner
69
+ */
70
+ const getGlobalTransformation = (drawingId, ownerId, localTransformation) => {
71
+ const lT = localTransformation;
72
+ const coordSysOwner = asmUtils.getCoordSysFromNode(drawingId, ownerId);
73
+ if (coordSysOwner) {
74
+ const origin = [lT[0].x, lT[0].y, lT[0].z];
75
+ const xAxis = [lT[1].x, lT[1].y, lT[1].z];
76
+ const yAxis = [lT[2].x, lT[2].y, lT[2].z];
77
+ const zAxis = new three_1.Vector3().crossVectors(new three_1.Vector3(lT[1].x, lT[1].y, lT[1].z), new three_1.Vector3(lT[2].x, lT[2].y, lT[2].z));
78
+ const matrix = core_1.MathUtils.convertToMatrix4([origin, xAxis, yAxis, [zAxis.x, zAxis.y, zAxis.z]]);
79
+ const transformation = core_1.MathUtils.convertToMatrix4(coordSysOwner).clone().multiply(matrix);
80
+ const transformationCoords = core_1.MathUtils.convertToCoordinateSystem(transformation);
81
+ const tC = transformationCoords;
82
+ return [
83
+ { x: tC[0][0], y: tC[0][1], z: tC[0][2] },
84
+ { x: tC[1][0], y: tC[1][1], z: tC[1][2] },
85
+ { x: tC[2][0], y: tC[2][1], z: tC[2][2] },
86
+ ];
87
+ }
88
+ return undefined;
89
+ };
90
+ /**
91
+ * Helps to create the buffer geometry of the given object recursively.
92
+ * @param object object to create the buffergeometry from
93
+ * @param bufferGeomArray array to fill up with buffert geometries
94
+ */
95
+ const createRecursiveBufferGeometry = async (object, drawingId, bufferGeomArray) => {
96
+ let cDrawing = (0, core_1.getDrawing)(drawingId);
97
+ const tree = cDrawing.structure.tree;
98
+ if (object.link || object.solids) {
99
+ // Part
100
+ const solids = object.link ? tree[object.link].solids : object.solids;
101
+ if (solids != undefined) {
102
+ let geometries = [];
103
+ for (const solid of solids) {
104
+ let cachedSolid = cDrawing.geometry.cache[solid];
105
+ if (cachedSolid) {
106
+ // if solid already cached, take it from cache
107
+ geometries = [...geometries, ...cachedSolid.meshes.map(m => m.geometry)];
108
+ }
109
+ else {
110
+ // else get visualisation from classcad
111
+ await classcad_1.ccAPI.baseModeler.requestVisualisationOfEntities(drawingId, [solid]);
112
+ cDrawing = (0, core_1.getDrawing)(drawingId); // get current drawing state after request
113
+ cachedSolid = cDrawing.geometry.cache[solid];
114
+ if (cachedSolid) {
115
+ geometries = [...geometries, ...cachedSolid.meshes.map(m => m.geometry)];
116
+ }
117
+ else {
118
+ console.warn(`There is no cached entry for ${solid}!`, cDrawing.geometry.cache);
119
+ }
120
+ }
121
+ }
122
+ if (geometries.length > 0) {
123
+ const transformation = cDrawing.api.structure.calculateGlobalTransformation(object.id);
124
+ const bufferGeom = BufferGeometryUtils.mergeBufferGeometries(geometries);
125
+ bufferGeom.applyMatrix4(transformation);
126
+ bufferGeomArray.push(bufferGeom);
127
+ }
128
+ }
129
+ }
130
+ else if (object.children) {
131
+ // Assembly
132
+ for (const child of object.children) {
133
+ if (tree[child].class === classcad_1.CCClasses.CCProductReference || tree[child].class === classcad_1.CCClasses.CCProductReferenceET) {
134
+ await createRecursiveBufferGeometry(tree[child], drawingId, bufferGeomArray);
135
+ }
136
+ }
137
+ }
138
+ };
139
+ /**
140
+ * We traverse recursively over structure tree, starting with object and create THREE objects
141
+ * for the scene. Each part or assembly will be turned into groups and subgroups. Solids which are children of the
142
+ * parts will be turned into groups as well. Children of solids will be merged to meshes. Faces of a solid with different color
143
+ * or transparency will get its own mesh.
144
+ * @param object root object where we start building the three scene
145
+ * @param drawingId id of the drawing
146
+ * @param root the root of the scene
147
+ * @param result object containing all the current collected nodes, solids, meshes
148
+ * @param options e.g. meshPerGeometry controls if each geometry element gets a own mesh or if they will be combined/merged
149
+ */
150
+ const createRecursiveScene = async (object, drawingId, root, result, options) => {
151
+ let cDrawing = (0, core_1.getDrawing)(drawingId);
152
+ const tree = cDrawing.structure.tree;
153
+ if (object.link || object.solids) {
154
+ // Part
155
+ const entities = object.link ? tree[object.link].solids : object.solids;
156
+ if (entities != undefined) {
157
+ const part = new three_1.Group();
158
+ part.matrix = core_1.MathUtils.convertToMatrix4(object.coordinateSystem);
159
+ part.matrixAutoUpdate = false;
160
+ part.userData = { id: object.id }; // product reference id
161
+ part.name = object.name; // product reference name
162
+ for (const entity of entities) {
163
+ let cachedEntity = cDrawing.geometry.cache[entity];
164
+ if (!cachedEntity) {
165
+ // else get visualisation from classcad
166
+ await classcad_1.ccAPI.baseModeler.requestVisualisationOfEntities(drawingId, [entity]);
167
+ cDrawing = (0, core_1.getDrawing)(drawingId); // get current drawing state after request
168
+ cachedEntity = cDrawing.geometry.cache[entity];
169
+ }
170
+ if (cachedEntity && cachedEntity.meshes.length > 0) {
171
+ const solidObject = cDrawing.structure.tree[cachedEntity.container.ownerId];
172
+ if (solidObject) {
173
+ const _solid = new three_1.Group();
174
+ _solid.name = solidObject.name;
175
+ _solid.userData = { id: solidObject.id }; // add solid id to the userData
176
+ if (options === null || options === void 0 ? void 0 : options.meshPerGeometry) {
177
+ // Create a mesh for each geometry element
178
+ cachedEntity.meshes.forEach(m => {
179
+ const mesh = new three_1.Mesh();
180
+ mesh.userData = { id: m.graphicId }; // add graphic id to the userData
181
+ mesh.geometry = m.geometry;
182
+ mesh.material = new three_1.MeshStandardMaterial({
183
+ color: m.color,
184
+ transparent: m.opacity < 1,
185
+ opacity: m.opacity,
186
+ });
187
+ _solid.add(mesh);
188
+ result.meshes.push(mesh);
189
+ });
190
+ }
191
+ else {
192
+ // Merge all geometries into one mesh, sort them by color
193
+ const colorMeshesMap = getDifferentColoredMeshesFromEntity(cachedEntity);
194
+ Object.keys(colorMeshesMap).forEach(key => {
195
+ const coloredMeshes = colorMeshesMap[key];
196
+ const mesh = new three_1.Mesh();
197
+ mesh.geometry = BufferGeometryUtils.mergeBufferGeometries(coloredMeshes.map(m => m.geometry));
198
+ mesh.material = new three_1.MeshStandardMaterial({
199
+ color: coloredMeshes[0].color,
200
+ transparent: coloredMeshes[0].opacity < 1,
201
+ opacity: coloredMeshes[0].opacity,
202
+ });
203
+ _solid.add(mesh); // Add mesh to solid of the scene
204
+ result.meshes.push(mesh); // Collect mesh to return result later
205
+ });
206
+ }
207
+ part.add(_solid);
208
+ result.solids.push(_solid);
209
+ }
210
+ }
211
+ }
212
+ root.add(part);
213
+ result.nodes.push(part);
214
+ }
215
+ }
216
+ else if (object.children) {
217
+ // Assembly
218
+ const assembly = new three_1.Group();
219
+ assembly.matrix = core_1.MathUtils.convertToMatrix4(object.coordinateSystem);
220
+ assembly.matrixAutoUpdate = false;
221
+ assembly.userData = { id: object.id }; // assembly root or product reference id
222
+ assembly.name = object.name; // assembly root or product reference name
223
+ result.nodes.push(assembly);
224
+ root.add(assembly);
225
+ for (const child of object.children) {
226
+ if (tree[child].class === classcad_1.CCClasses.CCProductReference || tree[child].class === classcad_1.CCClasses.CCProductReferenceET) {
227
+ await createRecursiveScene(tree[child], drawingId, assembly, result, options);
228
+ }
229
+ }
230
+ }
231
+ };
232
+ /**
233
+ * Get all meshes in a map, sorted by their color / transparency
234
+ * @param entity entity to look for the meshes
235
+ * @returns map (key = color/transparency as string, value = meshes array)
236
+ */
237
+ const getDifferentColoredMeshesFromEntity = (entity) => {
238
+ const colorMeshesMap = {};
239
+ entity.meshes.forEach(mesh => {
240
+ const key = mesh.color.getHexString() + mesh.opacity.toString();
241
+ if (colorMeshesMap[key]) {
242
+ colorMeshesMap[key].push(mesh);
243
+ }
244
+ else {
245
+ colorMeshesMap[key] = [mesh];
246
+ }
247
+ });
248
+ return colorMeshesMap;
249
+ };
250
+ /**
251
+ * Helper function to log relevant points to find geometry to the console.
252
+ * This helps the user to copy the points directly from console to parameter of
253
+ * findOrSelect() method.
254
+ * @param points Array of points array to log to the console
255
+ */
256
+ const logPoints = (points) => {
257
+ let log = 'Relevant points of selected gometry = [[';
258
+ if (points && points.length > 0) {
259
+ for (let i = 0; i < points.length; i++) {
260
+ for (let j = 0; j < points[i].length; j++) {
261
+ const x = Math.round(points[i][j].x * 1000) / 1000;
262
+ const y = Math.round(points[i][j].y * 1000) / 1000;
263
+ const z = Math.round(points[i][j].z * 1000) / 1000;
264
+ log += '{ x: ' + x + ', y: ' + y + ', z: ' + z + '}';
265
+ log += points[i].length - 1 === j ? '' : ',';
266
+ }
267
+ log += points.length - 1 === i ? ']]' : '],[';
268
+ }
269
+ console.info(log);
270
+ }
271
+ };
272
+ class CAD {
273
+ constructor() {
274
+ this.drawingId = null;
275
+ this.queue = Promise.resolve(0);
276
+ this.queue = Promise.resolve(0);
277
+ }
278
+ resolve(callback, ...args) {
279
+ return (this.queue = this.queue
280
+ .then(() => Promise.all(args).then(callback))
281
+ .catch(e => {
282
+ // catch is necessary to avoid error promises in the queue
283
+ }));
284
+ }
285
+ init(callback) {
286
+ const promise = new Promise(async (resolve, reject) => {
287
+ const drawingId = await classcad_1.ccAPI.base.createCCDrawing();
288
+ if (!drawingId)
289
+ throw new Error('Drawing could not be created');
290
+ this.drawingId = drawingId;
291
+ const publicApi = {
292
+ addNodes: async (...nodes) => {
293
+ var e_1, _a;
294
+ const nodesToAdd = [];
295
+ try {
296
+ for (var nodes_1 = __asyncValues(nodes), nodes_1_1; nodes_1_1 = await nodes_1.next(), !nodes_1_1.done;) {
297
+ const node = nodes_1_1.value;
298
+ const [rProductId, rOwnerId] = await new Promise(res => this.resolve(id => res(id), node.productId, node.ownerId));
299
+ const nodeParam = {
300
+ referenceId: rProductId,
301
+ ownerId: rOwnerId,
302
+ transformation: getGlobalTransformation(drawingId, rOwnerId, node.transformation) || node.transformation,
303
+ name: node.name,
304
+ };
305
+ nodesToAdd.push(nodeParam);
306
+ }
307
+ }
308
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
309
+ finally {
310
+ try {
311
+ if (nodes_1_1 && !nodes_1_1.done && (_a = nodes_1.return)) await _a.call(nodes_1);
312
+ }
313
+ finally { if (e_1) throw e_1.error; }
314
+ }
315
+ return classcad_1.ccAPI.assemblyBuilder.addNodes(drawingId, nodesToAdd);
316
+ },
317
+ addDimensions: async (...dimensions) => {
318
+ var e_2, _a;
319
+ const dimParamsToAdd = [];
320
+ try {
321
+ for (var dimensions_1 = __asyncValues(dimensions), dimensions_1_1; dimensions_1_1 = await dimensions_1.next(), !dimensions_1_1.done;) {
322
+ const dim = dimensions_1_1.value;
323
+ const [rProductId] = await new Promise(res => this.resolve(id => res(id), dim.productId));
324
+ const dimensionType = getDimensionType(dim.dimParam.dimType);
325
+ const dimParam = {
326
+ productId: rProductId,
327
+ param: {
328
+ type: dimensionType,
329
+ name: dim.dimParam.dimName,
330
+ label: dim.dimParam.dimLabel,
331
+ value: dim.dimParam.dimValue,
332
+ startPos: dim.dimParam.dimStartPos,
333
+ endPos: dim.dimParam.dimEndPos,
334
+ textPos: dim.dimParam.dimTextPos,
335
+ textAngle: dim.dimParam.dimTextAngle,
336
+ orientation: dim.dimParam.dimOrientation,
337
+ color: dim.dimParam.dimColor,
338
+ layer: dim.dimParam.dimLayer,
339
+ },
340
+ dxfView: dim.dxfView,
341
+ };
342
+ dimParamsToAdd.push(dimParam);
343
+ }
344
+ }
345
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
346
+ finally {
347
+ try {
348
+ if (dimensions_1_1 && !dimensions_1_1.done && (_a = dimensions_1.return)) await _a.call(dimensions_1);
349
+ }
350
+ finally { if (e_2) throw e_2.error; }
351
+ }
352
+ return classcad_1.ccAPI.drawing2D.addDimensions(drawingId, dimParamsToAdd);
353
+ },
354
+ create2DViews: (productId, viewTypes, viewOptions) => {
355
+ return this.resolve(async ([rProductId]) => {
356
+ const viewIds = await classcad_1.ccAPI.drawing2D.create2DViews(drawingId, rProductId, viewTypes, viewOptions);
357
+ if (viewIds !== null) {
358
+ await classcad_1.ccAPI.drawing2D.centerAllViews(drawingId, rProductId, viewTypes);
359
+ return viewIds;
360
+ }
361
+ return null;
362
+ }, productId);
363
+ },
364
+ getBoundaryBoxFromViews: (productId, viewTypes) => {
365
+ return this.resolve(async ([rProductId]) => {
366
+ const bbs = await classcad_1.ccAPI.drawing2D.getBoundaryBoxFromViews(drawingId, rProductId, viewTypes);
367
+ return bbs;
368
+ }, productId);
369
+ },
370
+ place2DViews: (productId, viewPositions) => {
371
+ return this.resolve(async ([rProductId]) => {
372
+ return classcad_1.ccAPI.drawing2D.place2DViews(drawingId, rProductId, viewPositions);
373
+ }, productId);
374
+ },
375
+ exportDXF: (productId, dxfTemplateFilename) => {
376
+ return this.resolve(async ([rProductId]) => {
377
+ return classcad_1.ccAPI.drawing2D.exportDXF(drawingId, rProductId, dxfTemplateFilename);
378
+ }, productId);
379
+ },
380
+ exportSVG: (productId, modus, renderSize, dxfTemplateFilename) => {
381
+ return this.resolve(async ([rProductId]) => {
382
+ modus = modus ? modus : classcad_1.SVGModusType.FIT_WHOLE_DRAWING;
383
+ const renderSizeParam = (renderSize === null || renderSize === void 0 ? void 0 : renderSize.x) && (renderSize === null || renderSize === void 0 ? void 0 : renderSize.y) ? [renderSize.x, renderSize.y] : undefined;
384
+ return classcad_1.ccAPI.drawing2D.exportSVG(drawingId, rProductId, modus, renderSizeParam, dxfTemplateFilename);
385
+ }, productId);
386
+ },
387
+ removeDimensions: (dimensionIds) => {
388
+ return this.resolve(async ([...rDimensionIds]) => {
389
+ return classcad_1.ccAPI.drawing2D.removeDimensions(drawingId, rDimensionIds);
390
+ }, ...dimensionIds);
391
+ },
392
+ linearPattern: (partId, entities, references1, params1, references2, params2) => {
393
+ return this.resolve(async ([rPartId, rEntities, rReferences1, rReferences2]) => {
394
+ const patternId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCLinearPattern, 'LinearPattern');
395
+ if (patternId != null) {
396
+ // entities
397
+ const cDrawing = await (0, core_1.getDrawing)(drawingId);
398
+ const entArray = [];
399
+ for (const rEntity of rEntities) {
400
+ const entity = cDrawing.structure.tree[(await rEntity)].children;
401
+ if (entity != undefined) {
402
+ entArray.push(entity[0]);
403
+ }
404
+ }
405
+ const distance1Param = {
406
+ value: params1.distance,
407
+ isExpr: typeof params1.distance === 'string',
408
+ };
409
+ const count1Param = {
410
+ value: params1.count,
411
+ isExpr: typeof params1.count === 'string',
412
+ };
413
+ const params1Param = [
414
+ params1.inverted,
415
+ distance1Param,
416
+ count1Param,
417
+ params1.merged,
418
+ ];
419
+ let params2Param = null;
420
+ if (params2) {
421
+ const distance2Param = {
422
+ value: params2.distance,
423
+ isExpr: typeof params2.distance === 'string',
424
+ };
425
+ const count2Param = {
426
+ value: params2.count,
427
+ isExpr: typeof params2.count === 'string',
428
+ };
429
+ params2Param = [params2.inverted, distance2Param, count2Param];
430
+ }
431
+ // resolve references1
432
+ const refs1 = [];
433
+ let refs2 = [];
434
+ for (const rRef1 of rReferences1) {
435
+ refs1.push(await rRef1);
436
+ }
437
+ // resolve references2 if present
438
+ if (rReferences2) {
439
+ for (const rRef2 of rReferences2) {
440
+ refs2.push(await rRef2);
441
+ }
442
+ }
443
+ else {
444
+ refs2 = null;
445
+ }
446
+ await featureAPI.updatePattern(drawingId, patternId, entArray, refs1, params1Param, refs2, params2Param);
447
+ return patternId;
448
+ }
449
+ return null;
450
+ }, partId, entities, references1, references2);
451
+ },
452
+ circularPattern: (partId, entities, references, params) => {
453
+ return this.resolve(async ([rPartId, rEntities, ...rReferences]) => {
454
+ const patternId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCCircularPattern, 'CircularPattern');
455
+ if (patternId != null) {
456
+ // entities
457
+ const cDrawing = await (0, core_1.getDrawing)(drawingId);
458
+ const entArray = [];
459
+ for (const rEntity of rEntities) {
460
+ const entity = cDrawing.structure.tree[(await rEntity)].children;
461
+ if (entity != undefined) {
462
+ entArray.push(entity[0]);
463
+ }
464
+ }
465
+ const angleParam = { value: params.angle, isExpr: typeof params.angle === 'string' };
466
+ const countParam = { value: params.count, isExpr: typeof params.count === 'string' };
467
+ const paramsParam = [
468
+ params.inverted,
469
+ angleParam,
470
+ countParam,
471
+ params.merged,
472
+ ];
473
+ rReferences = Array.isArray(rReferences) ? rReferences : [rReferences];
474
+ await featureAPI.updatePattern(drawingId, patternId, entArray, rReferences, paramsParam, null, null);
475
+ return patternId;
476
+ }
477
+ return null;
478
+ }, partId, entities, ...references);
479
+ },
480
+ extrusion: (partId, sketchId, type, limit1, limit2, taperAngle, direction, capEnds) => {
481
+ return this.resolve(async ([rPartId, rSketchId]) => {
482
+ const extrusion = await featureAPI.createExtrusion(drawingId, rPartId);
483
+ if (extrusion) {
484
+ const cDrawing = await (0, core_1.getDrawing)(drawingId);
485
+ const sketchLines = [];
486
+ // TODO: Which sketch lines need to be included, is CCClasses.CCCurve and its derivation enough?
487
+ sketchLines.push(...baseUtils.getChildren(rSketchId, classcad_1.CCClasses.CCCurve, cDrawing.structure.tree));
488
+ if (sketchLines) {
489
+ const limit1Param = { value: limit1, isExpr: typeof limit1 === 'string' };
490
+ const limit2Param = { value: limit2, isExpr: typeof limit2 === 'string' };
491
+ const taperAngleParam = {
492
+ value: taperAngle,
493
+ isExpr: typeof taperAngle === 'string',
494
+ };
495
+ const directionParam = {
496
+ value: direction,
497
+ isExpr: typeof direction === 'string',
498
+ };
499
+ await featureAPI.updateExtrusion(drawingId, extrusion, sketchLines, type, limit1Param, limit2Param, taperAngleParam, directionParam, capEnds);
500
+ return extrusion;
501
+ }
502
+ }
503
+ }, partId, sketchId);
504
+ },
505
+ revolve: (partId, sketchId, axisIds, angle1, angle2, inverted) => {
506
+ return this.resolve(async ([rPartId, rSketchId, ...rAxisIds]) => {
507
+ const revolve = await featureAPI.createRevolve(drawingId, rPartId);
508
+ if (revolve) {
509
+ const cDrawing = await (0, core_1.getDrawing)(drawingId);
510
+ const sketchLines = [];
511
+ sketchLines.push(...baseUtils.getChildren(rSketchId, classcad_1.CCClasses.CCCircle, cDrawing.structure.tree));
512
+ sketchLines.push(...baseUtils.getChildren(rSketchId, classcad_1.CCClasses.CCLine, cDrawing.structure.tree));
513
+ if (sketchLines) {
514
+ const angle1Param = { value: angle1, isExpr: typeof angle1 === 'string' };
515
+ const angle2Param = { value: angle2, isExpr: typeof angle2 === 'string' };
516
+ await featureAPI.updateRevolve(drawingId, revolve, sketchLines, rAxisIds, angle1Param, angle2Param, inverted);
517
+ return revolve;
518
+ }
519
+ }
520
+ }, partId, sketchId, ...axisIds);
521
+ },
522
+ boolean: (partId, type, entities) => {
523
+ return this.resolve(async ([rPartId, rEntities]) => {
524
+ const cDrawing = await (0, core_1.getDrawing)(drawingId);
525
+ const entArray = [];
526
+ for (const rEntity of rEntities) {
527
+ const entity = cDrawing.structure.tree[(await rEntity)].children;
528
+ if (entity != undefined) {
529
+ entArray.push(entity[0]);
530
+ }
531
+ }
532
+ const boolId = await featureAPI.createBooleanOperation(drawingId, rPartId, {
533
+ type,
534
+ entities: entArray,
535
+ });
536
+ if (boolId != null) {
537
+ await featureAPI.updateBooleanOperation(drawingId, boolId, type, entArray);
538
+ return boolId;
539
+ }
540
+ return null;
541
+ }, partId, entities);
542
+ },
543
+ box: (partId, references, width, length, height) => {
544
+ return this.resolve(async ([rPartId, ...rReferences]) => {
545
+ const boxId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCBox, 'Box');
546
+ if (boxId != null) {
547
+ const widthParam = { value: width, isExpr: typeof width === 'string' };
548
+ const lengthParam = { value: length, isExpr: typeof length === 'string' };
549
+ const heightParam = { value: height, isExpr: typeof height === 'string' };
550
+ await featureAPI.updateBox(drawingId, boxId, rReferences, widthParam, lengthParam, heightParam);
551
+ return boxId;
552
+ }
553
+ return null;
554
+ }, partId, ...references);
555
+ },
556
+ cylinder: (partId, references, diameter, height) => {
557
+ return this.resolve(async ([rPartId, ...rReferences]) => {
558
+ const cylId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCCylinder, 'Cylinder');
559
+ if (cylId != null) {
560
+ const diameterParam = { value: diameter, isExpr: typeof diameter === 'string' };
561
+ const heightParam = { value: height, isExpr: typeof height === 'string' };
562
+ await featureAPI.updateCylinder(drawingId, cylId, rReferences, diameterParam, heightParam);
563
+ return cylId;
564
+ }
565
+ return null;
566
+ }, partId, ...references);
567
+ },
568
+ chamfer: (partId, type, references, dist1, dist2, angle) => {
569
+ return this.resolve(async ([rPartId, rReferences]) => {
570
+ const dist1Param = { value: dist1, isExpr: typeof dist1 === 'string' };
571
+ const dist2Param = { value: dist2, isExpr: typeof dist2 === 'string' };
572
+ const angleParam = { value: angle, isExpr: typeof angle === 'string' };
573
+ const chamferId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCChamfer, 'Chamfer');
574
+ if (chamferId != null) {
575
+ await featureAPI.updateChamfer(drawingId, chamferId, type, rReferences, dist1Param, dist2Param, angleParam);
576
+ return chamferId;
577
+ }
578
+ return null;
579
+ }, partId, references);
580
+ },
581
+ cone: (partId, references, bDiameter, tDiameter, height) => {
582
+ return this.resolve(async ([rPartId, ...rReferences]) => {
583
+ const coneId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCCone, 'Cone');
584
+ if (coneId != null) {
585
+ const bDiamParam = { value: bDiameter, isExpr: typeof bDiameter === 'string' };
586
+ const tDiamParam = { value: tDiameter, isExpr: typeof tDiameter === 'string' };
587
+ const heightParam = { value: height, isExpr: typeof height === 'string' };
588
+ await featureAPI.updateCone(drawingId, coneId, rReferences, bDiamParam, tDiamParam, heightParam);
589
+ return coneId;
590
+ }
591
+ return null;
592
+ }, partId, ...references);
593
+ },
594
+ createFastenedConstraint: async (asmId, mate1, mate2, xOffset, yOffset, zOffset, name) => {
595
+ const [rAsmId, rWcs1, rWcs2] = await new Promise(res => this.resolve(ids => res(ids), asmId, mate1.wcsId, mate2.wcsId));
596
+ const rMatePath1 = await new Promise(res => this.resolve(paths => res(paths), ...mate1.matePath));
597
+ const rMatePath2 = await new Promise(res => this.resolve(paths => res(paths), ...mate2.matePath));
598
+ const constraintId = await assemblyBuilderAPI.create3DConstraint(drawingId, rAsmId, classcad_1.CCClasses.CCFastenedConstraint, name);
599
+ if (constraintId != null) {
600
+ const xOffsetParam = { value: xOffset, isExpr: typeof xOffset === 'string' };
601
+ const yOffsetParam = { value: yOffset, isExpr: typeof yOffset === 'string' };
602
+ const zOffsetParam = { value: zOffset, isExpr: typeof zOffset === 'string' };
603
+ await assemblyBuilderAPI.updateFastenedConstraints(drawingId, [
604
+ {
605
+ constrId: constraintId,
606
+ mate1: { matePath: rMatePath1, wcsId: rWcs1, flip: mate1.flip, reoriented: mate1.reoriented },
607
+ mate2: { matePath: rMatePath2, wcsId: rWcs2, flip: mate2.flip, reoriented: mate2.reoriented },
608
+ xOffset: xOffsetParam,
609
+ yOffset: yOffsetParam,
610
+ zOffset: zOffsetParam,
611
+ },
612
+ ]);
613
+ return constraintId;
614
+ }
615
+ return null;
616
+ },
617
+ updateFastenedConstraints: async (...constraints) => {
618
+ var e_3, _a;
619
+ const constrToAdd = [];
620
+ try {
621
+ for (var constraints_1 = __asyncValues(constraints), constraints_1_1; constraints_1_1 = await constraints_1.next(), !constraints_1_1.done;) {
622
+ const constr = constraints_1_1.value;
623
+ const [rConstrId, rWcs1, rWcs2] = await new Promise(res => this.resolve(ids => res(ids), constr.constrId, constr.mate1.wcsId, constr.mate2.wcsId));
624
+ const rMatePath1 = await new Promise(res => this.resolve(paths => res(paths), ...constr.mate1.matePath));
625
+ const rMatePath2 = await new Promise(res => this.resolve(paths => res(paths), ...constr.mate2.matePath));
626
+ const xOffsetParam = { value: constr.xOffset, isExpr: typeof constr.xOffset === 'string' };
627
+ const yOffsetParam = { value: constr.yOffset, isExpr: typeof constr.yOffset === 'string' };
628
+ const zOffsetParam = { value: constr.zOffset, isExpr: typeof constr.zOffset === 'string' };
629
+ constrToAdd.push({
630
+ constrId: rConstrId,
631
+ mate1: {
632
+ matePath: rMatePath1,
633
+ wcsId: rWcs1,
634
+ flip: constr.mate1.flip,
635
+ reoriented: constr.mate1.reoriented,
636
+ },
637
+ mate2: {
638
+ matePath: rMatePath2,
639
+ wcsId: rWcs2,
640
+ flip: constr.mate2.flip,
641
+ reoriented: constr.mate2.reoriented,
642
+ },
643
+ xOffset: xOffsetParam,
644
+ yOffset: yOffsetParam,
645
+ zOffset: zOffsetParam,
646
+ });
647
+ }
648
+ }
649
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
650
+ finally {
651
+ try {
652
+ if (constraints_1_1 && !constraints_1_1.done && (_a = constraints_1.return)) await _a.call(constraints_1);
653
+ }
654
+ finally { if (e_3) throw e_3.error; }
655
+ }
656
+ await assemblyBuilderAPI.updateFastenedConstraints(drawingId, constrToAdd);
657
+ },
658
+ createFastenedOriginConstraint: async (asmId, mate1, xOffset, yOffset, zOffset, name) => {
659
+ const [rAsmId, rWcs1] = await new Promise(res => this.resolve(ids => res(ids), asmId, mate1.wcsId));
660
+ const rMatePath = await new Promise(res => this.resolve(paths => res(paths), ...mate1.matePath));
661
+ const constraintId = await assemblyBuilderAPI.create3DConstraint(drawingId, rAsmId, classcad_1.CCClasses.CCFastenedOriginConstraint, name);
662
+ if (constraintId != null) {
663
+ const xOffsetParam = { value: xOffset, isExpr: typeof xOffset === 'string' };
664
+ const yOffsetParam = { value: yOffset, isExpr: typeof yOffset === 'string' };
665
+ const zOffsetParam = { value: zOffset, isExpr: typeof zOffset === 'string' };
666
+ await assemblyBuilderAPI.updateFastenedOriginConstraints(drawingId, [
667
+ {
668
+ constrId: constraintId,
669
+ mate1: { matePath: rMatePath, wcsId: rWcs1, flip: mate1.flip, reoriented: mate1.reoriented },
670
+ xOffset: xOffsetParam,
671
+ yOffset: yOffsetParam,
672
+ zOffset: zOffsetParam,
673
+ },
674
+ ]);
675
+ return constraintId;
676
+ }
677
+ return null;
678
+ },
679
+ updateFastenedOriginConstraints: async (...constraints) => {
680
+ var e_4, _a;
681
+ const constraintsToAdd = [];
682
+ try {
683
+ for (var constraints_2 = __asyncValues(constraints), constraints_2_1; constraints_2_1 = await constraints_2.next(), !constraints_2_1.done;) {
684
+ const constr = constraints_2_1.value;
685
+ const [rConstrId, rWcs1] = await new Promise(res => this.resolve(ids => res(ids), constr.constrId, constr.mate1.wcsId));
686
+ const rMatePath = await new Promise(res => this.resolve(paths => res(paths), ...constr.mate1.matePath));
687
+ const xOffsetParam = { value: constr.xOffset, isExpr: typeof constr.xOffset === 'string' };
688
+ const yOffsetParam = { value: constr.yOffset, isExpr: typeof constr.yOffset === 'string' };
689
+ const zOffsetParam = { value: constr.zOffset, isExpr: typeof constr.zOffset === 'string' };
690
+ constraintsToAdd.push({
691
+ constrId: rConstrId,
692
+ mate1: {
693
+ matePath: rMatePath,
694
+ wcsId: rWcs1,
695
+ flip: constr.mate1.flip,
696
+ reoriented: constr.mate1.reoriented,
697
+ },
698
+ xOffset: xOffsetParam,
699
+ yOffset: yOffsetParam,
700
+ zOffset: zOffsetParam,
701
+ });
702
+ }
703
+ }
704
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
705
+ finally {
706
+ try {
707
+ if (constraints_2_1 && !constraints_2_1.done && (_a = constraints_2.return)) await _a.call(constraints_2);
708
+ }
709
+ finally { if (e_4) throw e_4.error; }
710
+ }
711
+ await assemblyBuilderAPI.updateFastenedOriginConstraints(drawingId, constraintsToAdd);
712
+ },
713
+ createCylindricalConstraint: async (asmId, mate1, mate2, zOffsetLimits, zRotationLimits, name) => {
714
+ const [rAsmId, rWcs1, rWcs2] = await new Promise(res => this.resolve(ids => res(ids), asmId, mate1.wcsId, mate2.wcsId));
715
+ const rMatePath1 = await new Promise(res => this.resolve(paths => res(paths), ...mate1.matePath));
716
+ const rMatePath2 = await new Promise(res => this.resolve(paths => res(paths), ...mate2.matePath));
717
+ const constraintId = await assemblyBuilderAPI.create3DConstraint(drawingId, rAsmId, classcad_1.CCClasses.CCCylindricalConstraint, name);
718
+ if (constraintId != null) {
719
+ await assemblyBuilderAPI.updateCylindricalConstraints(drawingId, [
720
+ {
721
+ constrId: constraintId,
722
+ mate1: {
723
+ matePath: rMatePath1,
724
+ wcsId: rWcs1,
725
+ flip: mate1.flip,
726
+ reoriented: mate1.reoriented,
727
+ },
728
+ mate2: {
729
+ matePath: rMatePath2,
730
+ wcsId: rWcs2,
731
+ flip: mate2.flip,
732
+ reoriented: mate2.reoriented,
733
+ },
734
+ zOffsetLimits,
735
+ zRotationLimits,
736
+ },
737
+ ]);
738
+ return constraintId;
739
+ }
740
+ return null;
741
+ },
742
+ updateCylindricalConstraints: async (...constraints) => {
743
+ var e_5, _a;
744
+ const constrToAdd = [];
745
+ try {
746
+ for (var constraints_3 = __asyncValues(constraints), constraints_3_1; constraints_3_1 = await constraints_3.next(), !constraints_3_1.done;) {
747
+ const constr = constraints_3_1.value;
748
+ const [rConstrId, rWcs1, rWcs2] = await new Promise(res => this.resolve(ids => res(ids), constr.constrId, constr.mate1.wcsId, constr.mate2.wcsId));
749
+ const rMatePath1 = await new Promise(res => this.resolve(paths => res(paths), ...constr.mate1.matePath));
750
+ const rMatePath2 = await new Promise(res => this.resolve(paths => res(paths), ...constr.mate2.matePath));
751
+ constrToAdd.push({
752
+ constrId: rConstrId,
753
+ mate1: {
754
+ matePath: rMatePath1,
755
+ wcsId: rWcs1,
756
+ flip: constr.mate1.flip,
757
+ reoriented: constr.mate1.reoriented,
758
+ },
759
+ mate2: {
760
+ matePath: rMatePath2,
761
+ wcsId: rWcs2,
762
+ flip: constr.mate2.flip,
763
+ reoriented: constr.mate2.reoriented,
764
+ },
765
+ zOffsetLimits: constr.zOffsetLimits,
766
+ zRotationLimits: constr.zRotationLimits,
767
+ });
768
+ }
769
+ }
770
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
771
+ finally {
772
+ try {
773
+ if (constraints_3_1 && !constraints_3_1.done && (_a = constraints_3.return)) await _a.call(constraints_3);
774
+ }
775
+ finally { if (e_5) throw e_5.error; }
776
+ }
777
+ await assemblyBuilderAPI.updateCylindricalConstraints(drawingId, constrToAdd);
778
+ },
779
+ createRevoluteConstraint: async (asmId, mate1, mate2, zOffset, zRotationLimits, name) => {
780
+ const [rAsmId, rWcs1, rWcs2] = await new Promise(res => this.resolve(ids => res(ids), asmId, mate1.wcsId, mate2.wcsId));
781
+ const rMatePath1 = await new Promise(res => this.resolve(paths => res(paths), ...mate1.matePath));
782
+ const rMatePath2 = await new Promise(res => this.resolve(paths => res(paths), ...mate2.matePath));
783
+ const constraintId = await assemblyBuilderAPI.create3DConstraint(drawingId, rAsmId, classcad_1.CCClasses.CCRevoluteConstraint, name);
784
+ if (constraintId != null) {
785
+ const zOffsetParam = { value: zOffset, isExpr: typeof zOffset === 'string' };
786
+ await assemblyBuilderAPI.updateRevoluteConstraints(drawingId, [
787
+ {
788
+ constrId: constraintId,
789
+ mate1: {
790
+ matePath: rMatePath1,
791
+ wcsId: rWcs1,
792
+ flip: mate1.flip,
793
+ reoriented: mate1.reoriented,
794
+ },
795
+ mate2: {
796
+ matePath: rMatePath2,
797
+ wcsId: rWcs2,
798
+ flip: mate2.flip,
799
+ reoriented: mate2.reoriented,
800
+ },
801
+ zOffset: zOffsetParam,
802
+ zRotationLimits,
803
+ },
804
+ ]);
805
+ return constraintId;
806
+ }
807
+ return null;
808
+ },
809
+ updateRevoluteConstraints: async (...constraints) => {
810
+ var e_6, _a;
811
+ const constrToAdd = [];
812
+ try {
813
+ for (var constraints_4 = __asyncValues(constraints), constraints_4_1; constraints_4_1 = await constraints_4.next(), !constraints_4_1.done;) {
814
+ const constr = constraints_4_1.value;
815
+ const [rConstrId, rWcs1, rWcs2] = await new Promise(res => this.resolve(ids => res(ids), constr.constrId, constr.mate1.wcsId, constr.mate2.wcsId));
816
+ const rMatePath1 = await new Promise(res => this.resolve(paths => res(paths), ...constr.mate1.matePath));
817
+ const rMatePath2 = await new Promise(res => this.resolve(paths => res(paths), ...constr.mate2.matePath));
818
+ const zOffsetParam = { value: constr.zOffset, isExpr: typeof constr.zOffset === 'string' };
819
+ constrToAdd.push({
820
+ constrId: rConstrId,
821
+ mate1: {
822
+ matePath: rMatePath1,
823
+ wcsId: rWcs1,
824
+ flip: constr.mate1.flip,
825
+ reoriented: constr.mate1.reoriented,
826
+ },
827
+ mate2: {
828
+ matePath: rMatePath2,
829
+ wcsId: rWcs2,
830
+ flip: constr.mate2.flip,
831
+ reoriented: constr.mate2.reoriented,
832
+ },
833
+ zOffset: zOffsetParam,
834
+ zRotationLimits: constr.zRotationLimits,
835
+ });
836
+ }
837
+ }
838
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
839
+ finally {
840
+ try {
841
+ if (constraints_4_1 && !constraints_4_1.done && (_a = constraints_4.return)) await _a.call(constraints_4);
842
+ }
843
+ finally { if (e_6) throw e_6.error; }
844
+ }
845
+ await assemblyBuilderAPI.updateRevoluteConstraints(drawingId, constrToAdd);
846
+ },
847
+ createSliderConstraint: async (asmId, mate1, mate2, xOffset, yOffset, zOffsetLimits, name) => {
848
+ const [rAsmId, rWcs1, rWcs2] = await new Promise(res => this.resolve(ids => res(ids), asmId, mate1.wcsId, mate2.wcsId));
849
+ const rMatePath1 = await new Promise(res => this.resolve(paths => res(paths), ...mate1.matePath));
850
+ const rMatePath2 = await new Promise(res => this.resolve(paths => res(paths), ...mate2.matePath));
851
+ const constraintId = await assemblyBuilderAPI.create3DConstraint(drawingId, rAsmId, classcad_1.CCClasses.CCSliderConstraint, name);
852
+ if (constraintId != null) {
853
+ const xOffsetParam = { value: xOffset, isExpr: typeof xOffset === 'string' };
854
+ const yOffsetParam = { value: yOffset, isExpr: typeof yOffset === 'string' };
855
+ await assemblyBuilderAPI.updateSliderConstraints(drawingId, [
856
+ {
857
+ constrId: constraintId,
858
+ mate1: {
859
+ matePath: rMatePath1,
860
+ wcsId: rWcs1,
861
+ flip: mate1.flip,
862
+ reoriented: mate1.reoriented,
863
+ },
864
+ mate2: {
865
+ matePath: rMatePath2,
866
+ wcsId: rWcs2,
867
+ flip: mate2.flip,
868
+ reoriented: mate2.reoriented,
869
+ },
870
+ xOffset: xOffsetParam,
871
+ yOffset: yOffsetParam,
872
+ zOffsetLimits,
873
+ },
874
+ ]);
875
+ return constraintId;
876
+ }
877
+ return null;
878
+ },
879
+ updateSliderConstraints: async (...constraints) => {
880
+ var e_7, _a;
881
+ const constrToAdd = [];
882
+ try {
883
+ for (var constraints_5 = __asyncValues(constraints), constraints_5_1; constraints_5_1 = await constraints_5.next(), !constraints_5_1.done;) {
884
+ const constr = constraints_5_1.value;
885
+ const [rConstrId, rWcs1, rWcs2] = await new Promise(res => this.resolve(ids => res(ids), constr.constrId, constr.mate1.wcsId, constr.mate2.wcsId));
886
+ const rMatePath1 = await new Promise(res => this.resolve(paths => res(paths), ...constr.mate1.matePath));
887
+ const rMatePath2 = await new Promise(res => this.resolve(paths => res(paths), ...constr.mate2.matePath));
888
+ const xOffsetParam = { value: constr.xOffset, isExpr: typeof constr.xOffset === 'string' };
889
+ const yOffsetParam = { value: constr.yOffset, isExpr: typeof constr.yOffset === 'string' };
890
+ constrToAdd.push({
891
+ constrId: rConstrId,
892
+ mate1: {
893
+ matePath: rMatePath1,
894
+ wcsId: rWcs1,
895
+ flip: constr.mate1.flip,
896
+ reoriented: constr.mate1.reoriented,
897
+ },
898
+ mate2: {
899
+ matePath: rMatePath2,
900
+ wcsId: rWcs2,
901
+ flip: constr.mate2.flip,
902
+ reoriented: constr.mate2.reoriented,
903
+ },
904
+ xOffset: xOffsetParam,
905
+ yOffset: yOffsetParam,
906
+ zOffsetLimits: constr.zOffsetLimits,
907
+ });
908
+ }
909
+ }
910
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
911
+ finally {
912
+ try {
913
+ if (constraints_5_1 && !constraints_5_1.done && (_a = constraints_5.return)) await _a.call(constraints_5);
914
+ }
915
+ finally { if (e_7) throw e_7.error; }
916
+ }
917
+ await assemblyBuilderAPI.updateSliderConstraints(drawingId, constrToAdd);
918
+ },
919
+ createPlanarConstraint: async (asmId, mate1, mate2, zOffset, xOffsetLimits, yOffsetLimits, zRotationLimits, name) => {
920
+ const [rAsmId, rWcs1, rWcs2] = await new Promise(res => this.resolve(ids => res(ids), asmId, mate1.wcsId, mate2.wcsId));
921
+ const rMatePath1 = await new Promise(res => this.resolve(paths => res(paths), ...mate1.matePath));
922
+ const rMatePath2 = await new Promise(res => this.resolve(paths => res(paths), ...mate2.matePath));
923
+ const constraintId = await assemblyBuilderAPI.create3DConstraint(drawingId, rAsmId, classcad_1.CCClasses.CCPlanarConstraint, name);
924
+ if (constraintId != null) {
925
+ const zOffsetParam = { value: zOffset, isExpr: typeof zOffset === 'string' };
926
+ await assemblyBuilderAPI.updatePlanarConstraints(drawingId, [
927
+ {
928
+ constrId: constraintId,
929
+ mate1: {
930
+ matePath: rMatePath1,
931
+ wcsId: rWcs1,
932
+ flip: mate1.flip,
933
+ reoriented: mate1.reoriented,
934
+ },
935
+ mate2: {
936
+ matePath: rMatePath2,
937
+ wcsId: rWcs2,
938
+ flip: mate2.flip,
939
+ reoriented: mate2.reoriented,
940
+ },
941
+ zOffset: zOffsetParam,
942
+ xOffsetLimits,
943
+ yOffsetLimits,
944
+ zRotationLimits,
945
+ },
946
+ ]);
947
+ return constraintId;
948
+ }
949
+ return null;
950
+ },
951
+ updatePlanarConstraints: async (...constraints) => {
952
+ var e_8, _a;
953
+ const constrToAdd = [];
954
+ try {
955
+ for (var constraints_6 = __asyncValues(constraints), constraints_6_1; constraints_6_1 = await constraints_6.next(), !constraints_6_1.done;) {
956
+ const constr = constraints_6_1.value;
957
+ const [rConstrId, rWcs1, rWcs2] = await new Promise(res => this.resolve(ids => res(ids), constr.constrId, constr.mate1.wcsId, constr.mate2.wcsId));
958
+ const rMatePath1 = await new Promise(res => this.resolve(paths => res(paths), ...constr.mate1.matePath));
959
+ const rMatePath2 = await new Promise(res => this.resolve(paths => res(paths), ...constr.mate2.matePath));
960
+ const zOffsetParam = { value: constr.zOffset, isExpr: typeof constr.zOffset === 'string' };
961
+ constrToAdd.push({
962
+ constrId: rConstrId,
963
+ mate1: {
964
+ matePath: rMatePath1,
965
+ wcsId: rWcs1,
966
+ flip: constr.mate1.flip,
967
+ reoriented: constr.mate1.reoriented,
968
+ },
969
+ mate2: {
970
+ matePath: rMatePath2,
971
+ wcsId: rWcs2,
972
+ flip: constr.mate2.flip,
973
+ reoriented: constr.mate2.reoriented,
974
+ },
975
+ zOffset: zOffsetParam,
976
+ xOffsetLimits: constr.xOffsetLimits,
977
+ yOffsetLimits: constr.yOffsetLimits,
978
+ zRotationLimits: constr.zRotationLimits,
979
+ });
980
+ }
981
+ }
982
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
983
+ finally {
984
+ try {
985
+ if (constraints_6_1 && !constraints_6_1.done && (_a = constraints_6.return)) await _a.call(constraints_6);
986
+ }
987
+ finally { if (e_8) throw e_8.error; }
988
+ }
989
+ await assemblyBuilderAPI.updatePlanarConstraints(drawingId, constrToAdd);
990
+ },
991
+ createParallelConstraint: async (asmId, mate1, mate2, xOffsetLimits, yOffsetLimits, zOffsetLimits, zRotationLimits, name) => {
992
+ const [rAsmId, rWcs1, rWcs2] = await new Promise(res => this.resolve(ids => res(ids), asmId, mate1.wcsId, mate2.wcsId));
993
+ const rMatePath1 = await new Promise(res => this.resolve(paths => res(paths), ...mate1.matePath));
994
+ const rMatePath2 = await new Promise(res => this.resolve(paths => res(paths), ...mate2.matePath));
995
+ const constraintId = await assemblyBuilderAPI.create3DConstraint(drawingId, rAsmId, classcad_1.CCClasses.CCParallelConstraint, name);
996
+ if (constraintId != null) {
997
+ await assemblyBuilderAPI.updateParallelConstraints(drawingId, [
998
+ {
999
+ constrId: constraintId,
1000
+ mate1: {
1001
+ matePath: rMatePath1,
1002
+ wcsId: rWcs1,
1003
+ flip: mate1.flip,
1004
+ reoriented: mate1.reoriented,
1005
+ },
1006
+ mate2: {
1007
+ matePath: rMatePath2,
1008
+ wcsId: rWcs2,
1009
+ flip: mate2.flip,
1010
+ reoriented: mate2.reoriented,
1011
+ },
1012
+ xOffsetLimits,
1013
+ yOffsetLimits,
1014
+ zOffsetLimits,
1015
+ zRotationLimits,
1016
+ },
1017
+ ]);
1018
+ return constraintId;
1019
+ }
1020
+ return null;
1021
+ },
1022
+ updateParallelConstraints: async (...constraints) => {
1023
+ var e_9, _a;
1024
+ const constrToAdd = [];
1025
+ try {
1026
+ for (var constraints_7 = __asyncValues(constraints), constraints_7_1; constraints_7_1 = await constraints_7.next(), !constraints_7_1.done;) {
1027
+ const constr = constraints_7_1.value;
1028
+ const [rConstrId, rWcs1, rWcs2] = await new Promise(res => this.resolve(ids => res(ids), constr.constrId, constr.mate1.wcsId, constr.mate2.wcsId));
1029
+ const rMatePath1 = await new Promise(res => this.resolve(paths => res(paths), ...constr.mate1.matePath));
1030
+ const rMatePath2 = await new Promise(res => this.resolve(paths => res(paths), ...constr.mate2.matePath));
1031
+ constrToAdd.push({
1032
+ constrId: rConstrId,
1033
+ mate1: {
1034
+ matePath: rMatePath1,
1035
+ wcsId: rWcs1,
1036
+ flip: constr.mate1.flip,
1037
+ reoriented: constr.mate1.reoriented,
1038
+ },
1039
+ mate2: {
1040
+ matePath: rMatePath2,
1041
+ wcsId: rWcs2,
1042
+ flip: constr.mate2.flip,
1043
+ reoriented: constr.mate2.reoriented,
1044
+ },
1045
+ xOffsetLimits: constr.xOffsetLimits,
1046
+ yOffsetLimits: constr.yOffsetLimits,
1047
+ zOffsetLimits: constr.zOffsetLimits,
1048
+ zRotationLimits: constr.zRotationLimits,
1049
+ });
1050
+ }
1051
+ }
1052
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
1053
+ finally {
1054
+ try {
1055
+ if (constraints_7_1 && !constraints_7_1.done && (_a = constraints_7.return)) await _a.call(constraints_7);
1056
+ }
1057
+ finally { if (e_9) throw e_9.error; }
1058
+ }
1059
+ await assemblyBuilderAPI.updateParallelConstraints(drawingId, constrToAdd);
1060
+ },
1061
+ update3dConstraintValues: async (...constrValues) => {
1062
+ var e_10, _a;
1063
+ const constrValueParams = [];
1064
+ try {
1065
+ for (var constrValues_1 = __asyncValues(constrValues), constrValues_1_1; constrValues_1_1 = await constrValues_1.next(), !constrValues_1_1.done;) {
1066
+ const constrVal = constrValues_1_1.value;
1067
+ const [rConstrId] = await new Promise(res => this.resolve(ids => res(ids), constrVal.constrId));
1068
+ constrValueParams.push({
1069
+ constrId: rConstrId,
1070
+ paramName: constrVal.paramName,
1071
+ value: constrVal.value,
1072
+ });
1073
+ }
1074
+ }
1075
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
1076
+ finally {
1077
+ try {
1078
+ if (constrValues_1_1 && !constrValues_1_1.done && (_a = constrValues_1.return)) await _a.call(constrValues_1);
1079
+ }
1080
+ finally { if (e_10) throw e_10.error; }
1081
+ }
1082
+ await assemblyBuilderAPI.update3DConstraintValues(drawingId, constrValueParams);
1083
+ },
1084
+ createBufferGeometry: async (objectId) => {
1085
+ await this.queue;
1086
+ this.queue = Promise.resolve(0);
1087
+ const rObjectId = await objectId;
1088
+ const cDrawing = (0, core_1.getDrawing)(drawingId);
1089
+ const structureTree = cDrawing.structure.tree;
1090
+ const bufferGeomArray = [];
1091
+ if (rObjectId != null) {
1092
+ const rootObj = structureTree[rObjectId];
1093
+ await createRecursiveBufferGeometry(rootObj, drawingId, bufferGeomArray);
1094
+ if (bufferGeomArray.length > 0) {
1095
+ return bufferGeomArray;
1096
+ }
1097
+ }
1098
+ return undefined;
1099
+ },
1100
+ createScene: async (objectId, options) => {
1101
+ await this.queue;
1102
+ this.queue = Promise.resolve(0);
1103
+ const rObjectId = await objectId;
1104
+ const cDrawing = (0, core_1.getDrawing)(drawingId);
1105
+ const structureTree = cDrawing.structure.tree;
1106
+ const scene = new three_1.Scene();
1107
+ const result = {
1108
+ nodes: [],
1109
+ solids: [],
1110
+ meshes: [],
1111
+ };
1112
+ if (rObjectId != null) {
1113
+ const rootObj = structureTree[rObjectId];
1114
+ if (rootObj) {
1115
+ await createRecursiveScene(rootObj, drawingId, scene, result, options);
1116
+ }
1117
+ else {
1118
+ throw new Error('Root object does not exist!');
1119
+ }
1120
+ }
1121
+ return Object.assign({ scene }, result);
1122
+ },
1123
+ createExpressions: (partId, ...members) => {
1124
+ return this.resolve(async ([rPartId]) => {
1125
+ const membersToAdd = [];
1126
+ members.forEach(mem => {
1127
+ const isExpr = typeof mem.value === 'string'; // TODO Expression unterscheiden von normalen STrings
1128
+ const dataType = classcad_1.DataType.REAL; // TODO: Aktuell nur Real Werte als Expression
1129
+ const featureAPIParam = {
1130
+ value: mem.value,
1131
+ isExpr: isExpr,
1132
+ };
1133
+ membersToAdd.push({ name: mem.name, value: featureAPIParam, dataType });
1134
+ });
1135
+ const success = featureAPI.updateExpressionSets(drawingId, [
1136
+ { productId: rPartId, toAddMembers: membersToAdd, toModifyMembers: [], toDeleteList: [] },
1137
+ ]);
1138
+ return success;
1139
+ }, partId);
1140
+ },
1141
+ createAssemblyAsTemplate: (name) => {
1142
+ return this.resolve(async ([]) => {
1143
+ return await assemblyBuilderAPI.createAssemblyAsTemplate(drawingId, name);
1144
+ });
1145
+ },
1146
+ createRootAssembly: (name) => {
1147
+ return this.resolve(async ([]) => {
1148
+ return await assemblyBuilderAPI.createRootAssembly(drawingId, name);
1149
+ });
1150
+ },
1151
+ createPart: (name) => {
1152
+ return this.resolve(async ([]) => {
1153
+ const partName = name ? name : 'Part';
1154
+ return await featureAPI.newPart(drawingId, partName);
1155
+ });
1156
+ },
1157
+ createPartAsTemplate: (name) => {
1158
+ return this.resolve(async ([]) => {
1159
+ const partName = name ? name : 'Part';
1160
+ return await assemblyBuilderAPI.createPartAsTemplate(drawingId, partName);
1161
+ });
1162
+ },
1163
+ createWorkAxis: (partId, type, references, position, direction, local, name) => {
1164
+ return this.resolve(async ([rPartId, ...rReferences]) => {
1165
+ const wAName = name ? name : 'WorkAxis';
1166
+ const wAId = await featureAPI.createWorkGeometry(drawingId, rPartId, classcad_1.CCClasses.CCWorkAxis, wAName);
1167
+ if (wAId != null) {
1168
+ const positionParam = {
1169
+ value: position,
1170
+ isExpr: typeof position === 'string',
1171
+ };
1172
+ const directionParam = {
1173
+ value: direction,
1174
+ isExpr: typeof direction === 'string',
1175
+ };
1176
+ await featureAPI.updateWorkAxis(drawingId, wAId, type, rReferences, positionParam, directionParam, local);
1177
+ return wAId;
1178
+ }
1179
+ return null;
1180
+ }, partId, ...references);
1181
+ },
1182
+ createWorkCoordSystem: (partId, type, references, coordinateSystem, offset, rotation, inverted, local, name) => {
1183
+ return this.resolve(async ([rPartId, ...rReferences]) => {
1184
+ const wCSName = name ? name : 'WorkCoordSystem';
1185
+ const wCSId = await featureAPI.createWorkGeometry(drawingId, rPartId, classcad_1.CCClasses.CCWorkCoordSystem, wCSName);
1186
+ if (wCSId != null) {
1187
+ const offsetParam = { value: offset, isExpr: typeof offset === 'string' };
1188
+ const rotationParam = {
1189
+ value: rotation,
1190
+ isExpr: typeof rotation === 'string',
1191
+ };
1192
+ await featureAPI.updateWorkCoordSystem(drawingId, wCSId, type, rReferences, coordinateSystem, offsetParam, rotationParam, inverted, local);
1193
+ return wCSId;
1194
+ }
1195
+ return null;
1196
+ }, partId, ...references);
1197
+ },
1198
+ createWorkPlane: (partId, type, references, offset, angle, position, normal, local, name) => {
1199
+ return this.resolve(async ([rPartId, ...rReferences]) => {
1200
+ const wPName = name ? name : 'WorkPlane';
1201
+ const wPId = await featureAPI.createWorkGeometry(drawingId, rPartId, classcad_1.CCClasses.CCWorkPlane, wPName);
1202
+ if (wPId != undefined) {
1203
+ const offsetParam = { value: offset, isExpr: typeof offset === 'string' };
1204
+ const angleParam = { value: angle, isExpr: typeof angle === 'string' };
1205
+ const positionParam = {
1206
+ value: position,
1207
+ isExpr: typeof position === 'string',
1208
+ };
1209
+ const normalParam = { value: normal, isExpr: typeof normal === 'string' };
1210
+ await featureAPI.updateWorkPlane(drawingId, wPId, type, rReferences, offsetParam, angleParam, positionParam, normalParam, local);
1211
+ return wPId;
1212
+ }
1213
+ return null;
1214
+ }, partId, ...references);
1215
+ },
1216
+ createWorkPoint: (partId, type, references, position, local, name) => {
1217
+ return this.resolve(async ([rPartId, ...rReferences]) => {
1218
+ const wPTName = name ? name : 'WorkPoint';
1219
+ const wPTId = await featureAPI.createWorkGeometry(drawingId, rPartId, classcad_1.CCClasses.CCWorkPoint, wPTName);
1220
+ if (wPTId != undefined) {
1221
+ const positionParam = {
1222
+ value: position,
1223
+ isExpr: typeof position === 'string',
1224
+ };
1225
+ await featureAPI.updateWorkPoint(drawingId, wPTId, type, rReferences, positionParam, local);
1226
+ return wPTId;
1227
+ }
1228
+ return null;
1229
+ }, partId, ...references);
1230
+ },
1231
+ fillet: (partId, references, radius) => {
1232
+ return this.resolve(async ([rPartId, rReferences]) => {
1233
+ const radiusParam = { value: radius, isExpr: typeof radius === 'string' };
1234
+ const filletId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCConstantRadiusFillet, 'Fillet');
1235
+ if (filletId != null) {
1236
+ await featureAPI.updateFillet(drawingId, filletId, rReferences, radiusParam);
1237
+ return filletId;
1238
+ }
1239
+ return null;
1240
+ }, partId, references);
1241
+ },
1242
+ findOrSelect: (partId, type, length, positions) => {
1243
+ return this.resolve(async ([rPartId]) => {
1244
+ let filter = core_1.lineSegmentsFilter;
1245
+ switch (type) {
1246
+ case 0: // Vertex
1247
+ filter = core_1.pointFilter;
1248
+ break;
1249
+ case 1: // Edge
1250
+ filter = core_1.lineSegmentsFilter;
1251
+ break;
1252
+ case 2: // Loop
1253
+ filter = core_1.loopFilter;
1254
+ break;
1255
+ case 3: // Face
1256
+ filter = core_1.planeFilter;
1257
+ break;
1258
+ }
1259
+ const geometries = positions
1260
+ ? await classcad_1.ccAPI.geometry.findGeometriesByPoints(drawingId, rPartId, type, positions)
1261
+ : await (0, selection_1.waitForSelect)(length, filter, (resolveSelection, items, diff) => {
1262
+ if (items.length > length - 1) {
1263
+ resolveSelection(items.map(i => i.data.graphicId));
1264
+ classcad_1.ccAPI.geometry
1265
+ .getPointsByGeometries(drawingId, items.map(i => i.data.graphicId))
1266
+ .then(points => {
1267
+ logPoints(points);
1268
+ });
1269
+ }
1270
+ });
1271
+ return geometries;
1272
+ }, partId);
1273
+ },
1274
+ getAssemblyFromContainer: (asmName) => {
1275
+ return this.resolve(async ([]) => {
1276
+ const asmIds = asmUtils.getAssemblyFromContainer(drawingId, asmName);
1277
+ if (asmIds != undefined) {
1278
+ return Array.isArray(asmIds) ? asmIds : [asmIds];
1279
+ }
1280
+ return null;
1281
+ });
1282
+ },
1283
+ getAssemblyNode: (refId, nodeName) => {
1284
+ return this.resolve(async ([rRefId]) => {
1285
+ const nodeIds = asmUtils.getAssemblyNode(drawingId, rRefId, nodeName);
1286
+ if (nodeIds != undefined) {
1287
+ return Array.isArray(nodeIds) ? nodeIds : [nodeIds];
1288
+ }
1289
+ return null;
1290
+ }, refId);
1291
+ },
1292
+ setCurrentNode: (refId) => {
1293
+ return this.resolve(async ([rRefId]) => {
1294
+ await assemblyBuilderAPI.setCurrentNode(drawingId, rRefId);
1295
+ }, refId);
1296
+ },
1297
+ getCurrentNode: () => {
1298
+ return this.resolve(async () => {
1299
+ const drw = (0, core_1.getDrawing)(drawingId);
1300
+ return drw.structure.currentNode;
1301
+ });
1302
+ },
1303
+ getCoordSysFromNode: (refId) => {
1304
+ return this.resolve(async ([rRefId]) => {
1305
+ const coordSys = asmUtils.getCoordSysFromNode(drawingId, rRefId);
1306
+ if (coordSys != undefined) {
1307
+ return coordSys;
1308
+ }
1309
+ return null;
1310
+ }, refId);
1311
+ },
1312
+ setCurrentProduct: (productId) => {
1313
+ return this.resolve(async ([rProductId]) => {
1314
+ await classcad_1.ccAPI.baseModeler.setCurrentProduct(drawingId, rProductId);
1315
+ }, productId);
1316
+ },
1317
+ getCurrentProduct: () => {
1318
+ return this.resolve(async () => {
1319
+ const drw = (0, core_1.getDrawing)(drawingId);
1320
+ return drw.structure.currentProduct;
1321
+ });
1322
+ },
1323
+ getPartFromContainer: (partName) => {
1324
+ return this.resolve(async ([]) => {
1325
+ const partIds = asmUtils.getPartFromContainer(drawingId, partName);
1326
+ if (partIds != undefined) {
1327
+ return Array.isArray(partIds) ? partIds : [partIds];
1328
+ }
1329
+ return null;
1330
+ });
1331
+ },
1332
+ getWorkCoordSystem: (refId, wcsName) => {
1333
+ return this.resolve(async ([rRefId]) => {
1334
+ console.warn('Warning: getWorkCoordSystem() is deprecated, use getWorkGeometry() instead, getWorkCoordSystem() will be removed in a future release.');
1335
+ const wcsIds = asmUtils.getWorkCoordSystem(drawingId, rRefId, wcsName);
1336
+ if (wcsIds != undefined) {
1337
+ return Array.isArray(wcsIds) ? wcsIds : [wcsIds];
1338
+ }
1339
+ return null;
1340
+ }, refId);
1341
+ },
1342
+ getWorkGeometry: (refId, type, wgName) => {
1343
+ return this.resolve(async ([rRefId]) => {
1344
+ const wgIds = asmUtils.getWorkGeometry(drawingId, rRefId, type, wgName);
1345
+ if (wgIds != undefined) {
1346
+ return Array.isArray(wgIds) ? wgIds : [wgIds];
1347
+ }
1348
+ return null;
1349
+ }, refId);
1350
+ },
1351
+ getConstraint: (refId, constrName) => {
1352
+ return this.resolve(async ([rRefId]) => {
1353
+ console.warn('Warning: getConstraint() is deprecated, use specific methods e.g. getFastenedConstraint() instead, getConstraint() will be removed in a future release.');
1354
+ const constrIds = asmUtils.getConstraint(drawingId, rRefId, constrName);
1355
+ if (constrIds != undefined) {
1356
+ return Array.isArray(constrIds) ? constrIds : [constrIds];
1357
+ }
1358
+ return null;
1359
+ }, refId);
1360
+ },
1361
+ getFastenedConstraint: (refId, constrName) => {
1362
+ return this.resolve(async ([rRefId]) => {
1363
+ const constraint = asmUtils.getFastenedConstraint(drawingId, rRefId, constrName);
1364
+ if (constraint != undefined) {
1365
+ return {
1366
+ constrId: constraint.constrId,
1367
+ mate1: constraint.mate1,
1368
+ mate2: constraint.mate2,
1369
+ xOffset: constraint.xOffset.value,
1370
+ yOffset: constraint.yOffset.value,
1371
+ zOffset: constraint.zOffset.value,
1372
+ };
1373
+ }
1374
+ return null;
1375
+ }, refId);
1376
+ },
1377
+ getFastenedOriginConstraint: (refId, constrName) => {
1378
+ return this.resolve(async ([rRefId]) => {
1379
+ const constraint = asmUtils.getFastenedOriginConstraint(drawingId, rRefId, constrName);
1380
+ if (constraint != undefined) {
1381
+ return {
1382
+ constrId: constraint.constrId,
1383
+ mate1: constraint.mate1,
1384
+ xOffset: constraint.xOffset.value,
1385
+ yOffset: constraint.yOffset.value,
1386
+ zOffset: constraint.zOffset.value,
1387
+ };
1388
+ }
1389
+ return null;
1390
+ }, refId);
1391
+ },
1392
+ getRevoluteConstraint: (refId, constrName) => {
1393
+ return this.resolve(async ([rRefId]) => {
1394
+ const constraint = asmUtils.getRevoluteConstraint(drawingId, rRefId, constrName);
1395
+ if (constraint != undefined) {
1396
+ return {
1397
+ constrId: constraint.constrId,
1398
+ mate1: constraint.mate1,
1399
+ mate2: constraint.mate2,
1400
+ zOffset: constraint.zOffset.value,
1401
+ zRotationLimits: constraint.zRotationLimits,
1402
+ };
1403
+ }
1404
+ return null;
1405
+ }, refId);
1406
+ },
1407
+ getSliderConstraint: (refId, constrName) => {
1408
+ return this.resolve(async ([rRefId]) => {
1409
+ const constraint = asmUtils.getSliderConstraint(drawingId, rRefId, constrName);
1410
+ if (constraint != undefined) {
1411
+ return {
1412
+ constrId: constraint.constrId,
1413
+ mate1: constraint.mate1,
1414
+ mate2: constraint.mate2,
1415
+ xOffset: constraint.xOffset.value,
1416
+ yOffset: constraint.yOffset.value,
1417
+ zOffsetLimits: constraint.zOffsetLimits,
1418
+ };
1419
+ }
1420
+ return null;
1421
+ }, refId);
1422
+ },
1423
+ getPlanarConstraint: (refId, constrName) => {
1424
+ return this.resolve(async ([rRefId]) => {
1425
+ const constraint = asmUtils.getPlanarConstraint(drawingId, rRefId, constrName);
1426
+ if (constraint != undefined) {
1427
+ return {
1428
+ constrId: constraint.constrId,
1429
+ mate1: constraint.mate1,
1430
+ mate2: constraint.mate2,
1431
+ zOffset: constraint.zOffset.value,
1432
+ xOffsetLimits: constraint.xOffsetLimits,
1433
+ yOffsetLimits: constraint.yOffsetLimits,
1434
+ zRotationLimits: constraint.zRotationLimits,
1435
+ };
1436
+ }
1437
+ return null;
1438
+ }, refId);
1439
+ },
1440
+ getParallelConstraint: (refId, constrName) => {
1441
+ return this.resolve(async ([rRefId]) => {
1442
+ const constraint = asmUtils.getParallelConstraint(drawingId, rRefId, constrName);
1443
+ if (constraint != undefined) {
1444
+ return {
1445
+ constrId: constraint.constrId,
1446
+ mate1: constraint.mate1,
1447
+ mate2: constraint.mate2,
1448
+ xOffsetLimits: constraint.xOffsetLimits,
1449
+ yOffsetLimits: constraint.yOffsetLimits,
1450
+ zOffsetLimits: constraint.zOffsetLimits,
1451
+ zRotationLimits: constraint.zRotationLimits,
1452
+ };
1453
+ }
1454
+ return null;
1455
+ }, refId);
1456
+ },
1457
+ getCylindricalConstraint: (refId, constrName) => {
1458
+ return this.resolve(async ([rRefId]) => {
1459
+ const constraint = asmUtils.getCylindricalConstraint(drawingId, rRefId, constrName);
1460
+ if (constraint != undefined) {
1461
+ return {
1462
+ constrId: constraint.constrId,
1463
+ mate1: constraint.mate1,
1464
+ mate2: constraint.mate2,
1465
+ zOffsetLimits: constraint.zOffsetLimits,
1466
+ zRotationLimits: constraint.zRotationLimits,
1467
+ };
1468
+ }
1469
+ return null;
1470
+ }, refId);
1471
+ },
1472
+ getFeatureByName: (partId, featureName) => {
1473
+ return this.resolve(async ([rProductId]) => {
1474
+ const feature = await featureAPI.getFeatureByName(drawingId, rProductId, featureName);
1475
+ if (feature !== null) {
1476
+ return feature;
1477
+ }
1478
+ return null;
1479
+ }, partId);
1480
+ },
1481
+ removeNodes: (...nodes) => {
1482
+ return this.resolve(async ([...rNodes]) => {
1483
+ return assemblyBuilderAPI.removeNodes(drawingId, rNodes);
1484
+ }, ...nodes);
1485
+ },
1486
+ importFeature: (partId, content, format, name) => {
1487
+ return this.resolve(async ([rPartId]) => {
1488
+ const featureName = name ? name : 'Import';
1489
+ const importFeatureId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCImport, featureName);
1490
+ if (importFeatureId !== null) {
1491
+ const solids = await featureAPI.updateImport(drawingId, importFeatureId, content, format, featureName);
1492
+ if (solids !== null) {
1493
+ return importFeatureId;
1494
+ }
1495
+ }
1496
+ return null;
1497
+ }, partId);
1498
+ },
1499
+ loadSketch: (partId, stream, planeId, name) => {
1500
+ return this.resolve(async ([rPartId, rPlaneId]) => {
1501
+ const sketch = await sketcherAPI.createSketch(drawingId, rPartId);
1502
+ if (sketch) {
1503
+ await featureAPI.closeFeature(drawingId, sketch);
1504
+ const tree = (0, core_1.getDrawing)(drawingId).structure.tree;
1505
+ const plane = tree[rPlaneId];
1506
+ if (plane && baseUtils.isA(plane.class, classcad_1.CCClasses.CCWorkPlane)) {
1507
+ await sketcherAPI.setWorkPlane(drawingId, sketch, rPlaneId);
1508
+ }
1509
+ else {
1510
+ await sketcherAPI.createAndSetWorkPlane(drawingId, sketch, rPlaneId);
1511
+ }
1512
+ await sketcherAPI.loadSketch(drawingId, rPartId, sketch, stream, name);
1513
+ return sketch;
1514
+ }
1515
+ }, partId, planeId);
1516
+ },
1517
+ copySketch: (partId, sketchId, planeId) => {
1518
+ return this.resolve(async ([rPartId, rPlaneId, rSketchId]) => {
1519
+ const sketch = await sketcherAPI.createSketch(drawingId, rPartId);
1520
+ if (sketch) {
1521
+ await featureAPI.closeFeature(drawingId, sketch);
1522
+ const tree = (0, core_1.getDrawing)(drawingId).structure.tree;
1523
+ const plane = tree[rPlaneId];
1524
+ if (plane && baseUtils.isA(plane.class, classcad_1.CCClasses.CCWorkPlane)) {
1525
+ await sketcherAPI.setWorkPlane(drawingId, sketch, rPlaneId);
1526
+ }
1527
+ else {
1528
+ await sketcherAPI.createAndSetWorkPlane(drawingId, sketch, rPlaneId);
1529
+ }
1530
+ await sketcherAPI.copySketch(drawingId, sketch, rSketchId);
1531
+ return sketch;
1532
+ }
1533
+ }, partId, planeId, sketchId);
1534
+ },
1535
+ placeSketch: (sketchId, planeId, invertPlane, axisId, isXAxis, invertAxis, originId) => {
1536
+ return this.resolve(async ([rSketchId, rPlaneId, rAxisId, rOriginId]) => {
1537
+ await sketcherAPI.setSketchRefs(drawingId, rSketchId, rPlaneId, invertPlane, rAxisId, isXAxis, invertAxis, rOriginId);
1538
+ }, sketchId, planeId, axisId, originId);
1539
+ },
1540
+ transformNode: (referenceId, ownerId, transformation) => {
1541
+ return this.resolve(async ([rRefId, rOwnerId]) => {
1542
+ await assemblyBuilderAPI.setNodeTransformation(drawingId, rRefId, rOwnerId, transformation);
1543
+ }, referenceId, ownerId);
1544
+ },
1545
+ translate: (partId, featureIds, references, inverted, distance) => {
1546
+ return this.resolve(async ([rPartId, rFeatureIds, ...rReferences]) => {
1547
+ const translationId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCTranslation, 'Translate');
1548
+ if (translationId !== null) {
1549
+ const cDrawing = await (0, core_1.getDrawing)(drawingId);
1550
+ const entArray = [];
1551
+ for (const rFeatureId of rFeatureIds) {
1552
+ const entity = cDrawing.structure.tree[(await rFeatureId)].children;
1553
+ if (entity != undefined) {
1554
+ entArray.push(entity[0]);
1555
+ }
1556
+ }
1557
+ const dist = { value: distance, isExpr: typeof distance === 'string' };
1558
+ await featureAPI.updateTransformation(drawingId, translationId, entArray, rReferences, inverted, dist);
1559
+ return translationId;
1560
+ }
1561
+ return null;
1562
+ }, partId, featureIds, ...references);
1563
+ },
1564
+ // TODO: Remove this method. Is it necessary?
1565
+ updateTranslate: (translationId, distance) => {
1566
+ return this.resolve(async ([rTranslationId]) => {
1567
+ const cDrawing = await (0, core_1.getDrawing)(drawingId);
1568
+ const members = cDrawing.structure.tree[rTranslationId].members;
1569
+ if (members !== null && members !== undefined) {
1570
+ const entArray = members['bodiesToTransform'].members.map(m => m.value);
1571
+ const references = members['references'].members.map(m => m.value);
1572
+ const inverted = members['inverted'].value;
1573
+ const dist = distance !== null ? distance : members['translationDistance'].value;
1574
+ const distParam = { value: dist, isExpr: typeof distance === 'string' };
1575
+ await featureAPI.openFeature(drawingId, rTranslationId);
1576
+ await featureAPI.updateTransformation(drawingId, rTranslationId, entArray, references, inverted, distParam);
1577
+ await featureAPI.closeFeature(drawingId, rTranslationId);
1578
+ }
1579
+ }, translationId);
1580
+ },
1581
+ save: (type) => {
1582
+ return classcad_1.ccAPI.baseModeler.save(drawingId, type);
1583
+ },
1584
+ saveToUrl: (url, filetype) => {
1585
+ return classcad_1.ccAPI.baseModeler.saveToUrl(drawingId, url, filetype);
1586
+ },
1587
+ load: (content, type) => {
1588
+ return classcad_1.ccAPI.baseModeler.load(drawingId, content, type);
1589
+ },
1590
+ loadFromUrl: (url, filetype) => {
1591
+ return classcad_1.ccAPI.baseModeler.loadFromUrl(drawingId, url, filetype, true);
1592
+ },
1593
+ loadProduct: (content, type) => {
1594
+ return classcad_1.ccAPI.assemblyBuilder.loadProduct(drawingId, content, type);
1595
+ },
1596
+ loadProductFromUrl: (url, filetype) => {
1597
+ return classcad_1.ccAPI.assemblyBuilder.loadProductFromUrl(drawingId, url, filetype);
1598
+ },
1599
+ pick: (partId, type, points) => {
1600
+ return this.resolve(async ([rPartId]) => {
1601
+ const refs = await featureAPI.pick(drawingId, rPartId, type, points);
1602
+ if (refs != undefined) {
1603
+ return Array.isArray(refs) ? refs : [refs];
1604
+ }
1605
+ return null;
1606
+ }, partId);
1607
+ },
1608
+ setExpressions: (partId, ...members) => {
1609
+ return this.resolve(async ([rPartId]) => {
1610
+ const membersToModify = [];
1611
+ members.forEach(mem => {
1612
+ const isExpr = typeof mem.value === 'string'; // TODO Expression unterscheiden von normalen Strings
1613
+ const featureAPIParam = {
1614
+ value: mem.value,
1615
+ isExpr,
1616
+ };
1617
+ membersToModify.push({ name: mem.name, value: featureAPIParam });
1618
+ });
1619
+ const success = featureAPI.updateExpressionSets(drawingId, [
1620
+ { productId: rPartId, toAddMembers: [], toModifyMembers: membersToModify, toDeleteList: [] },
1621
+ ]);
1622
+ return success;
1623
+ }, partId);
1624
+ },
1625
+ setExpressionSets: (...exprSets) => {
1626
+ return this.resolve(async ([...rExprSets]) => {
1627
+ const exprSetsToSet = [];
1628
+ rExprSets.forEach(exprSet => {
1629
+ const membersToModify = [];
1630
+ exprSet.members.forEach((mem) => {
1631
+ const isExpr = typeof mem.value === 'string'; // TODO Expression unterscheiden von normalen Strings
1632
+ const featureAPIParam = {
1633
+ value: mem.value,
1634
+ isExpr,
1635
+ };
1636
+ membersToModify.push({ name: mem.name, value: featureAPIParam });
1637
+ });
1638
+ exprSetsToSet.push({
1639
+ productId: exprSet.partId,
1640
+ toAddMembers: [],
1641
+ toModifyMembers: membersToModify,
1642
+ toDeleteList: [],
1643
+ });
1644
+ });
1645
+ const success = await featureAPI.updateExpressionSets(drawingId, exprSetsToSet);
1646
+ return success;
1647
+ }, ...exprSets);
1648
+ },
1649
+ deleteExpressions: (partId, members) => {
1650
+ return this.resolve(async ([rPartId]) => {
1651
+ const success = featureAPI.updateExpressionSets(drawingId, [
1652
+ { productId: rPartId, toAddMembers: [], toModifyMembers: [], toDeleteList: members },
1653
+ ]);
1654
+ return success;
1655
+ }, partId);
1656
+ },
1657
+ sphere: (partId, references, radius) => {
1658
+ return this.resolve(async ([rPartId, ...rReferences]) => {
1659
+ const sphereId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCSphere, 'Sphere');
1660
+ if (sphereId != null) {
1661
+ const radiusParam = { value: radius, isExpr: typeof radius === 'string' };
1662
+ await featureAPI.updateSphere(drawingId, sphereId, rReferences, radiusParam);
1663
+ return sphereId;
1664
+ }
1665
+ return null;
1666
+ }, partId, ...references);
1667
+ },
1668
+ mirror: async (partId, entities, references) => {
1669
+ const [rPartId] = await new Promise(res => this.resolve(ids => res(ids), partId));
1670
+ const rEntities = await new Promise(res => this.resolve(ids => res(ids), ...entities));
1671
+ const rReferences = await new Promise(res => this.resolve(paths => res(paths), ...references));
1672
+ const cDrawing = (0, core_1.getDrawing)(drawingId);
1673
+ const entArray = [];
1674
+ for (const rEntity of rEntities) {
1675
+ const entity = cDrawing.structure.tree[rEntity].children;
1676
+ if (entity != undefined) {
1677
+ entArray.push(entity[0]);
1678
+ }
1679
+ }
1680
+ const mirrorId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCMirror, 'Mirror');
1681
+ if (mirrorId != null) {
1682
+ await featureAPI.updateMirror(drawingId, mirrorId, entArray, rReferences);
1683
+ return mirrorId;
1684
+ }
1685
+ return null;
1686
+ },
1687
+ removeOperations: async (operations, toOperation) => {
1688
+ const rOperations = await new Promise(res => this.resolve(ids => res(ids), ...operations));
1689
+ const [rToOperation] = await new Promise(res => this.resolve(paths => res(paths), toOperation));
1690
+ if (operations && operations.length > 0) {
1691
+ await baseModelerAPI.deleteObjects(drawingId, rOperations);
1692
+ }
1693
+ else if (rToOperation) {
1694
+ const toRemoveOps = [];
1695
+ const cDrawing = (0, core_1.getDrawing)(drawingId);
1696
+ const tree = cDrawing.structure.tree;
1697
+ const opSeq = cDrawing.api.structure.filterTree(tree, obj => obj.name === 'OperationSequence').pop();
1698
+ const opRefs = opSeq && baseUtils.getChildren(opSeq.id, classcad_1.CCClasses.CCObjectReference, tree);
1699
+ const filteredOps = opRefs === null || opRefs === void 0 ? void 0 : opRefs.map(opRef => { var _a, _b; return (_b = (_a = tree[opRef].members) === null || _a === void 0 ? void 0 : _a.refObj) === null || _b === void 0 ? void 0 : _b.value; });
1700
+ if (filteredOps) {
1701
+ let opNotFound = true;
1702
+ let index = filteredOps.length - 2; // -2 => Avoid RollBackBar
1703
+ while (opNotFound) {
1704
+ if (filteredOps[index] !== rToOperation) {
1705
+ toRemoveOps.push(filteredOps[index]);
1706
+ }
1707
+ else {
1708
+ opNotFound = false;
1709
+ }
1710
+ index--;
1711
+ }
1712
+ }
1713
+ await baseModelerAPI.deleteObjects(drawingId, toRemoveOps);
1714
+ }
1715
+ },
1716
+ };
1717
+ callback(publicApi);
1718
+ resolve(drawingId);
1719
+ });
1720
+ return () => promise.then(drawingId => core_1.api.getState().api.removeDrawing(drawingId));
1721
+ }
1722
+ destroy() {
1723
+ this.drawingId && core_1.api.getState().api.removeDrawing(this.drawingId);
1724
+ }
1725
+ }
1726
+ exports.default = CAD;