@buerli.io/headless 0.9.1-beta.1 → 0.11.0

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