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

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