@buerli.io/headless 1.0.1-beta.2 → 1.0.1

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