@buerli.io/headless 0.2.1 → 0.3.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.
package/build/history.js CHANGED
@@ -1,39 +1,21 @@
1
1
  /* eslint-disable max-lines */
2
- import { BooleanOperationType, ccAPI, CCClasses, ccUtils, ChamferType, DataType, WorkAxisType, WorkCoordSystemType, WorkPlaneType, WorkPointType, ViewType, OrientationType, } from '@buerli.io/classcad';
3
- import { api, getDrawing, MathUtils, } from '@buerli.io/core';
2
+ import { ccAPI, CCClasses, ccUtils, DataType, } from '@buerli.io/classcad';
3
+ import { api, getDrawing, lineSegmentsFilter, loopFilter, MathUtils, planeFilter, pointFilter, } from '@buerli.io/core';
4
4
  import { Group, Mesh, MeshStandardMaterial, Scene, Vector3 } from 'three';
5
5
  import * as BufferGeometryUtils_ from 'three/examples/jsm/utils/BufferGeometryUtils';
6
+ import { waitForSelect } from './utils/selection';
6
7
  const featureAPI = ccAPI.feature;
8
+ const sketcherAPI = ccAPI.sketcher;
9
+ const base = ccUtils.base;
7
10
  let BufferGeometryUtils = BufferGeometryUtils_;
8
11
  if (BufferGeometryUtils.BufferGeometryUtils) {
9
12
  BufferGeometryUtils = BufferGeometryUtils.BufferGeometryUtils;
10
13
  }
11
- // Qeued execute, returns the first result and expects it to be an ObjectID
12
- const exec = (instance, drawing, namespace, fn, stream, ...args) => {
13
- return (instance.queue = instance.queue.then(() => Promise.all(args).then(resolvedArgs => {
14
- return ccAPI.base.callSafeAPI(drawing, namespace, fn, resolvedArgs, stream).then(res => {
15
- return (res && res.results[0].result);
16
- });
17
- })));
18
- };
19
- const toCCVec = (args) => ({ x: args[0], y: args[1], z: args[2] });
20
- const toArray = (v) => (Array.isArray(v) ? v : v.toArray());
21
- const toEuler = (v) => toArray(v);
22
- const makeVec = (v) => toCCVec(toArray(v));
23
- const getBoxMember = (drawingId, featureId, member) => {
24
- const cDrawing = getDrawing(drawingId);
25
- const members = cDrawing.structure.tree[featureId].members;
26
- if (members) {
27
- switch (member) {
28
- case 'width':
29
- return members.width.value === undefined ? 10 : Number(members.width.value);
30
- case 'length':
31
- return members.length.value === undefined ? 10 : Number(members.length.value);
32
- case 'height':
33
- return members.height.value === undefined ? 10 : Number(members.height.value);
34
- }
35
- }
36
- };
14
+ /**
15
+ * Returns the data type of the given value
16
+ * @param value value to get the data type from
17
+ * @returns datatype of value
18
+ */
37
19
  const getDataType = (value) => {
38
20
  switch (typeof value) {
39
21
  case 'number':
@@ -44,136 +26,11 @@ const getDataType = (value) => {
44
26
  return DataType.STRING;
45
27
  }
46
28
  };
47
- const getBoolType = (type) => {
48
- switch (type) {
49
- case 'Union':
50
- return BooleanOperationType.UNION;
51
- case 'Subtraction':
52
- return BooleanOperationType.SUBTRACTION;
53
- case 'Intersection':
54
- return BooleanOperationType.INTERSECTION;
55
- case undefined:
56
- break;
57
- }
58
- };
59
- const getChamferType = (type) => {
60
- switch (type) {
61
- case 'Equal_Distance':
62
- return ChamferType.EQUAL_DISTANCE;
63
- case 'Two_Distances':
64
- return ChamferType.TWO_DISTANCES;
65
- case 'Distance_And_Angle':
66
- return ChamferType.DISTANCE_AND_ANGLE;
67
- case undefined:
68
- break;
69
- }
70
- };
71
- const getWCSType = (type) => {
72
- switch (type) {
73
- case 'XYAxisOrigin':
74
- return WorkCoordSystemType.WCS_XYAXISORIGIN;
75
- case 'Custom':
76
- return WorkCoordSystemType.WCS_CUSTOM;
77
- case undefined:
78
- break;
79
- }
80
- };
81
- const getWAType = (type) => {
82
- switch (type) {
83
- case 'Custom':
84
- return WorkAxisType.WA_USERDEFINED;
85
- case 'WorkPoints':
86
- return WorkAxisType.WA_WORKPOINTS;
87
- case 'PointAndDirection':
88
- return WorkAxisType.WA_POINTDIRECTION;
89
- case 'SketchLine':
90
- return WorkAxisType.WA_SKETCHLINE;
91
- case 'Curve':
92
- return WorkAxisType.WA_CURVE;
93
- case '2Points':
94
- return WorkAxisType.WA_2POINTS;
95
- case '2Planes':
96
- return WorkAxisType.WA_2PLANES;
97
- case undefined:
98
- break;
99
- }
100
- };
101
- const getWPType = (type) => {
102
- switch (type) {
103
- case 'Custom':
104
- return WorkPlaneType.WP_USERDEFINED;
105
- case 'Plane':
106
- return WorkPlaneType.WP_PLANE;
107
- case 'EdgeAndPoint':
108
- return WorkPlaneType.WP_EDGEPOINT;
109
- case '3Points':
110
- return WorkPlaneType.WP_3POINTS;
111
- case 'PointAndNormal':
112
- return WorkPlaneType.WP_POINTNORMAL;
113
- case 'PointAndFace':
114
- return WorkPlaneType.WP_POINTFACE;
115
- case 'LinePlaneAndAngle':
116
- return WorkPlaneType.WP_LINEPLANEANGLE;
117
- case undefined:
118
- break;
119
- }
120
- };
121
- const getWPTType = (type) => {
122
- switch (type) {
123
- case 'Custom':
124
- return WorkPointType.WPT_USERDEFINED;
125
- case 'Point':
126
- return WorkPointType.WPT_BREPVERTEX;
127
- case 'MidPointLine':
128
- return WorkPointType.WPT_EDGEMIDPOINT;
129
- case 'Center':
130
- return WorkPointType.WPT_CENTER;
131
- case 'BaryCenter':
132
- return WorkPointType.WPT_BARYCENTER;
133
- case 'Intersection':
134
- return WorkPointType.WPT_INTERSECTION;
135
- case 'InnerCircle':
136
- return WorkPointType.WPT_INNERCIRCLE;
137
- case 'MidPointOf2Points':
138
- return WorkPointType.WPT_2POINTS;
139
- case undefined:
140
- break;
141
- }
142
- };
143
- const getViewType = (type) => {
144
- switch (type) {
145
- case 'Top':
146
- return ViewType.TOP;
147
- case 'Front':
148
- return ViewType.FRONT;
149
- case 'Right':
150
- return ViewType.RIGHT;
151
- case 'Left':
152
- return ViewType.LEFT;
153
- case 'Bottom':
154
- return ViewType.BOTTOM;
155
- case 'Right_90°':
156
- return ViewType.RIGHT_90;
157
- case 'Left_90°':
158
- return ViewType.LEFT_90;
159
- case 'Back':
160
- return ViewType.BACK;
161
- case 'Iso':
162
- return ViewType.ISO;
163
- case undefined:
164
- break;
165
- }
166
- };
167
- const getOrientationType = (type) => {
168
- switch (type) {
169
- case 'Vertical':
170
- return OrientationType.VERTICAL;
171
- case 'Horizontal':
172
- return OrientationType.HORIZONTAL;
173
- case undefined:
174
- break;
175
- }
176
- };
29
+ /**
30
+ * Returns the cclass of the given dimension type
31
+ * @param type type of the dimension as string
32
+ * @returns cclass type of given type
33
+ */
177
34
  const getDimensionType = (type) => {
178
35
  switch (type) {
179
36
  case 'LinearDimension':
@@ -182,6 +39,13 @@ const getDimensionType = (type) => {
182
39
  break;
183
40
  }
184
41
  };
42
+ /**
43
+ * Transforms the transformation which is local to the ownerId into global
44
+ * transformation and returns it.
45
+ * @param ownerId node to get the global transformation from
46
+ * @param localTransformation transformation local to the owner, will be calculated into global transformation
47
+ * @returns the global transformation from local transformation to owner
48
+ */
185
49
  const getGlobalTransformation = (drawingId, ownerId, localTransformation) => {
186
50
  const lT = localTransformation;
187
51
  const coordSysOwner = ccUtils.assembly.getCoordSysFromNode(drawingId, ownerId);
@@ -202,6 +66,11 @@ const getGlobalTransformation = (drawingId, ownerId, localTransformation) => {
202
66
  }
203
67
  return undefined;
204
68
  };
69
+ /**
70
+ * Helps to create the buffer geometry of the given object recursively.
71
+ * @param object object to create the buffergeometry from
72
+ * @param bufferGeomArray array to fill up with buffert geometries
73
+ */
205
74
  const createRecursiveBufferGeometry = async (object, drawingId, bufferGeomArray) => {
206
75
  let cDrawing = getDrawing(drawingId);
207
76
  const tree = cDrawing.structure.tree;
@@ -359,6 +228,28 @@ const getDifferentColoredMeshesFromSolid = (solid) => {
359
228
  });
360
229
  return colorMeshesMap;
361
230
  };
231
+ /**
232
+ * Helper function to log relevant points to find geometry to the console.
233
+ * This helps the user to copy the points directly from console to parameter of
234
+ * findOrSelect() method.
235
+ * @param points Array of points array to log to the console
236
+ */
237
+ const logPoints = (points) => {
238
+ let log = 'Relevant points of selected gometry = [[';
239
+ if (points && points.length > 0) {
240
+ for (let i = 0; i < points.length; i++) {
241
+ for (let j = 0; j < points[i].length; j++) {
242
+ const x = Math.round(points[i][j].x * 1000) / 1000;
243
+ const y = Math.round(points[i][j].y * 1000) / 1000;
244
+ const z = Math.round(points[i][j].z * 1000) / 1000;
245
+ log += '{ x: ' + x + ', y: ' + y + ', z: ' + z + '}';
246
+ log += points[i].length - 1 === j ? '' : ',';
247
+ }
248
+ log += points.length - 1 === i ? ']]' : '],[';
249
+ }
250
+ console.info(log);
251
+ }
252
+ };
362
253
  export default class CAD {
363
254
  constructor() {
364
255
  this.drawingId = null;
@@ -366,7 +257,11 @@ export default class CAD {
366
257
  this.queue = Promise.resolve(0);
367
258
  }
368
259
  resolve(callback, ...args) {
369
- return (this.queue = this.queue.then(() => Promise.all(args).then(callback)));
260
+ return (this.queue = this.queue
261
+ .then(() => Promise.all(args).then(callback))
262
+ .catch(e => {
263
+ // catch is necessary to avoid error promises in the queue
264
+ }));
370
265
  }
371
266
  init(callback) {
372
267
  const promise = new Promise(async (resolve, reject) => {
@@ -382,21 +277,19 @@ export default class CAD {
382
277
  }, productId, ownerId);
383
278
  },
384
279
  addNodes: (...nodes) => {
385
- return this.resolve(async ([]) => {
280
+ return this.resolve(async ([...rNodes]) => {
386
281
  const nodesToAdd = [];
387
- nodes.forEach(node => {
282
+ rNodes.forEach(node => {
388
283
  const globalTransformation = getGlobalTransformation(drawingId, node.ownerId, node.transformation) || node.transformation;
389
284
  nodesToAdd.push([node.productId, node.ownerId, globalTransformation, node.name]);
390
285
  });
391
286
  return ccAPI.assemblyBuilder.addNodes(drawingId, nodesToAdd);
392
- });
287
+ }, ...nodes);
393
288
  },
394
289
  addDimension: (dim) => {
395
290
  return this.resolve(async ([rProductId]) => {
396
- const orientation = getOrientationType(dim.dimParam.dimOrientation);
397
- const view = getViewType(dim.dxfView);
398
291
  const dimensionType = getDimensionType(dim.dimParam.dimType);
399
- if (orientation !== undefined && view !== undefined) {
292
+ if (dim.dimParam.dimOrientation !== undefined && dim.dxfView !== undefined) {
400
293
  const dimParam = [
401
294
  rProductId,
402
295
  [
@@ -408,24 +301,22 @@ export default class CAD {
408
301
  dim.dimParam.dimEndPos,
409
302
  dim.dimParam.dimTextPos,
410
303
  dim.dimParam.dimTextAngle,
411
- orientation,
304
+ dim.dimParam.dimOrientation,
412
305
  dim.dimParam.dimColor || 256,
413
306
  dim.dimParam.dimLayer || '2', // which layer makes sense as default?
414
307
  ],
415
- view,
308
+ dim.dxfView,
416
309
  ];
417
310
  return ccAPI.drawing2D.addDimension(drawingId, dimParam);
418
311
  }
419
312
  }, dim.productId);
420
313
  },
421
314
  addDimensions: (...dimensions) => {
422
- return this.resolve(async ([]) => {
315
+ return this.resolve(async ([...rDimensions]) => {
423
316
  const dimsToAdd = [];
424
- dimensions.forEach(dim => {
425
- const orientation = getOrientationType(dim.dimParam.dimOrientation);
426
- const view = getViewType(dim.dxfView);
317
+ rDimensions.forEach(dim => {
427
318
  const dimensionType = getDimensionType(dim.dimParam.dimType);
428
- if (orientation !== undefined && view !== undefined) {
319
+ if (dim.dimParam.dimOrientation !== undefined && dim.dxfView !== undefined) {
429
320
  dimsToAdd.push([
430
321
  dim.productId,
431
322
  [
@@ -437,23 +328,22 @@ export default class CAD {
437
328
  dim.dimParam.dimEndPos,
438
329
  dim.dimParam.dimTextPos,
439
330
  dim.dimParam.dimTextAngle,
440
- orientation,
331
+ dim.dimParam.dimOrientation,
441
332
  dim.dimParam.dimColor || 256,
442
333
  dim.dimParam.dimLayer || '2', // which layer makes sense as default?
443
334
  ],
444
- view,
335
+ dim.dxfView,
445
336
  ]);
446
337
  }
447
338
  });
448
339
  return ccAPI.drawing2D.addDimensions(drawingId, dimsToAdd);
449
- });
340
+ }, ...dimensions);
450
341
  },
451
342
  create2DViews: (productId, viewTypes) => {
452
343
  return this.resolve(async ([rProductId]) => {
453
- const types = viewTypes.map(viewType => getViewType(viewType));
454
- const viewIds = await ccAPI.drawing2D.create2DViews(drawingId, rProductId, types);
344
+ const viewIds = await ccAPI.drawing2D.create2DViews(drawingId, rProductId, viewTypes);
455
345
  if (viewIds !== null) {
456
- await ccAPI.drawing2D.centerAllViews(drawingId, rProductId, types);
346
+ await ccAPI.drawing2D.centerAllViews(drawingId, rProductId, viewTypes);
457
347
  return viewIds;
458
348
  }
459
349
  return null;
@@ -461,8 +351,7 @@ export default class CAD {
461
351
  },
462
352
  getBoundaryBoxFromViews: (productId, viewTypes) => {
463
353
  return this.resolve(async ([rProductId]) => {
464
- const types = viewTypes === null || viewTypes === void 0 ? void 0 : viewTypes.map(viewType => getViewType(viewType));
465
- const bbs = await ccAPI.drawing2D.getBoundaryBoxFromViews(drawingId, rProductId, types);
354
+ const bbs = await ccAPI.drawing2D.getBoundaryBoxFromViews(drawingId, rProductId, viewTypes);
466
355
  return bbs;
467
356
  }, productId);
468
357
  },
@@ -470,9 +359,8 @@ export default class CAD {
470
359
  return this.resolve(async ([rProductId]) => {
471
360
  const viewPositionParams = [];
472
361
  viewPositions.forEach(viewPos => {
473
- const type = getViewType(viewPos.viewType);
474
- if (type !== undefined) {
475
- viewPositionParams.push([type, viewPos.vector]);
362
+ if (viewPos.viewType !== undefined) {
363
+ viewPositionParams.push([viewPos.viewType, viewPos.vector]);
476
364
  }
477
365
  });
478
366
  return ccAPI.drawing2D.place2DViews(drawingId, rProductId, viewPositionParams);
@@ -483,112 +371,247 @@ export default class CAD {
483
371
  return ccAPI.drawing2D.exportDXF(drawingId, rProductId);
484
372
  }, productId);
485
373
  },
374
+ exportSVG: (productId) => {
375
+ return this.resolve(async ([rProductId]) => {
376
+ return ccAPI.drawing2D.exportSVG(drawingId, rProductId);
377
+ }, productId);
378
+ },
486
379
  removeDimensions: (dimensionIds) => {
487
- return this.resolve(async () => {
488
- return ccAPI.drawing2D.removeDimensions(drawingId, dimensionIds);
489
- });
380
+ return this.resolve(async ([...rDimensionIds]) => {
381
+ return ccAPI.drawing2D.removeDimensions(drawingId, rDimensionIds);
382
+ }, ...dimensionIds);
383
+ },
384
+ linearPattern: (partId, entities, references1, params1, references2, params2) => {
385
+ return this.resolve(async ([rPartId, rEntities, rReferences1, rReferences2]) => {
386
+ const patternId = await featureAPI.createFeature(drawingId, rPartId, CCClasses.CCLinearPattern, 'LinearPattern');
387
+ if (patternId != null) {
388
+ // entities
389
+ const cDrawing = await getDrawing(drawingId);
390
+ const entArray = [];
391
+ for (const rEntity of rEntities) {
392
+ const entity = cDrawing.structure.tree[(await rEntity)].children;
393
+ if (entity != undefined) {
394
+ entArray.push(entity[0]);
395
+ }
396
+ }
397
+ const distance1Param = {
398
+ value: params1.distance,
399
+ isExpr: typeof params1.distance === 'string',
400
+ };
401
+ const count1Param = {
402
+ value: params1.count,
403
+ isExpr: typeof params1.count === 'string',
404
+ };
405
+ const params1Param = [
406
+ params1.inverted,
407
+ distance1Param,
408
+ count1Param,
409
+ params1.merged,
410
+ ];
411
+ let params2Param = null;
412
+ if (params2) {
413
+ const distance2Param = {
414
+ value: params2.distance,
415
+ isExpr: typeof params2.distance === 'string',
416
+ };
417
+ const count2Param = {
418
+ value: params2.count,
419
+ isExpr: typeof params2.count === 'string',
420
+ };
421
+ params2Param = [params2.inverted, distance2Param, count2Param];
422
+ }
423
+ // resolve references1
424
+ const refs1 = [];
425
+ let refs2 = [];
426
+ for (const rRef1 of rReferences1) {
427
+ refs1.push(await rRef1);
428
+ }
429
+ // resolve references2 if present
430
+ if (rReferences2) {
431
+ for (const rRef2 of rReferences2) {
432
+ refs2.push(await rRef2);
433
+ }
434
+ }
435
+ else {
436
+ refs2 = null;
437
+ }
438
+ await featureAPI.updatePattern(drawingId, patternId, entArray, refs1, params1Param, refs2, params2Param);
439
+ return patternId;
440
+ }
441
+ return null;
442
+ }, partId, entities, references1, references2);
443
+ },
444
+ circularPattern: (partId, entities, references, params) => {
445
+ return this.resolve(async ([rPartId, rEntities, ...rReferences]) => {
446
+ const patternId = await featureAPI.createFeature(drawingId, rPartId, CCClasses.CCCircularPattern, 'CircularPattern');
447
+ if (patternId != null) {
448
+ // entities
449
+ const cDrawing = await getDrawing(drawingId);
450
+ const entArray = [];
451
+ for (const rEntity of rEntities) {
452
+ const entity = cDrawing.structure.tree[(await rEntity)].children;
453
+ if (entity != undefined) {
454
+ entArray.push(entity[0]);
455
+ }
456
+ }
457
+ const angleParam = { value: params.angle, isExpr: typeof params.angle === 'string' };
458
+ const countParam = { value: params.count, isExpr: typeof params.count === 'string' };
459
+ const paramsParam = [
460
+ params.inverted,
461
+ angleParam,
462
+ countParam,
463
+ params.merged,
464
+ ];
465
+ rReferences = Array.isArray(rReferences) ? rReferences : [rReferences];
466
+ await featureAPI.updatePattern(drawingId, patternId, entArray, rReferences, paramsParam, null, null);
467
+ return patternId;
468
+ }
469
+ return null;
470
+ }, partId, entities, ...references);
471
+ },
472
+ extrusion: (partId, sketchId, type, limit1, limit2, taperAngle, direction, capEnds) => {
473
+ return this.resolve(async ([rPartId, rSketchId]) => {
474
+ const extrusion = await featureAPI.createExtrusion(drawingId, rPartId);
475
+ if (extrusion) {
476
+ const cDrawing = await getDrawing(drawingId);
477
+ const sketchLines = [];
478
+ // TODO: Which sketch lines need to be included, is CCClasses.CCCurve and its derivation enough?
479
+ sketchLines.push(...ccUtils.base.getChildren(rSketchId, CCClasses.CCCurve, cDrawing.structure.tree));
480
+ if (sketchLines) {
481
+ const limit1Param = { value: limit1, isExpr: typeof limit1 === 'string' };
482
+ const limit2Param = { value: limit2, isExpr: typeof limit2 === 'string' };
483
+ const taperAngleParam = {
484
+ value: taperAngle,
485
+ isExpr: typeof taperAngle === 'string',
486
+ };
487
+ const directionParam = {
488
+ value: direction,
489
+ isExpr: typeof direction === 'string',
490
+ };
491
+ await featureAPI.updateExtrusion(drawingId, extrusion, sketchLines, type, limit1Param, limit2Param, taperAngleParam, directionParam, capEnds);
492
+ return extrusion;
493
+ }
494
+ }
495
+ }, partId, sketchId);
496
+ },
497
+ revolve: (partId, sketchId, axisIds, angle1, angle2, inverted) => {
498
+ return this.resolve(async ([rPartId, rSketchId, ...rAxisIds]) => {
499
+ const revolve = await featureAPI.createRevolve(drawingId, rPartId);
500
+ if (revolve) {
501
+ const cDrawing = await getDrawing(drawingId);
502
+ const sketchLines = [];
503
+ sketchLines.push(...ccUtils.base.getChildren(rSketchId, CCClasses.CCCircle, cDrawing.structure.tree));
504
+ sketchLines.push(...ccUtils.base.getChildren(rSketchId, CCClasses.CCLine, cDrawing.structure.tree));
505
+ if (sketchLines) {
506
+ const angle1Param = { value: angle1, isExpr: typeof angle1 === 'string' };
507
+ const angle2Param = { value: angle2, isExpr: typeof angle2 === 'string' };
508
+ await featureAPI.updateRevolve(drawingId, revolve, sketchLines, rAxisIds, angle1Param, angle2Param, inverted);
509
+ return revolve;
510
+ }
511
+ }
512
+ }, partId, sketchId, ...axisIds);
490
513
  },
491
514
  boolean: (partId, type, entities) => {
492
- return this.resolve(async ([rPartId, ...rEntities]) => {
515
+ return this.resolve(async ([rPartId, rEntities]) => {
493
516
  const cDrawing = await getDrawing(drawingId);
494
517
  const entArray = [];
495
518
  for (const rEntity of rEntities) {
496
- const entity = cDrawing.structure.tree[rEntity].children;
519
+ const entity = cDrawing.structure.tree[(await rEntity)].children;
497
520
  if (entity != undefined) {
498
521
  entArray.push(entity[0]);
499
522
  }
500
523
  }
501
- const boolType = getBoolType(type);
502
- if (boolType != undefined) {
503
- const boolId = await featureAPI.createBooleanOperation(drawingId, rPartId, {
504
- type: boolType,
505
- entities: entArray,
506
- });
507
- if (boolId != null) {
508
- await featureAPI.updateBooleanOperation(drawingId, boolId, boolType, entArray);
509
- return boolId;
510
- }
524
+ const boolId = await featureAPI.createBooleanOperation(drawingId, rPartId, {
525
+ type,
526
+ entities: entArray,
527
+ });
528
+ if (boolId != null) {
529
+ await featureAPI.updateBooleanOperation(drawingId, boolId, type, entArray);
530
+ return boolId;
511
531
  }
512
- return null; // Todo: Exceptions?
513
- }, partId, ...entities);
532
+ return null;
533
+ }, partId, entities);
514
534
  },
515
535
  box: (partId, references, width, length, height) => {
516
- return this.resolve(async ([rPartId]) => {
536
+ return this.resolve(async ([rPartId, ...rReferences]) => {
517
537
  const boxId = await featureAPI.createFeature(drawingId, rPartId, CCClasses.CCBox, 'Box');
518
538
  if (boxId != null) {
519
539
  const widthParam = { value: width, isExpr: typeof width === 'string' };
520
540
  const lengthParam = { value: length, isExpr: typeof length === 'string' };
521
541
  const heightParam = { value: height, isExpr: typeof height === 'string' };
522
- await featureAPI.updateBox(drawingId, boxId, references, widthParam, lengthParam, heightParam);
542
+ await featureAPI.updateBox(drawingId, boxId, rReferences, widthParam, lengthParam, heightParam);
523
543
  return boxId;
524
544
  }
525
545
  return null;
526
- }, partId);
546
+ }, partId, ...references);
527
547
  },
528
548
  cylinder: (partId, references, diameter, height) => {
529
- return this.resolve(async ([rPartId]) => {
549
+ return this.resolve(async ([rPartId, ...rReferences]) => {
530
550
  const cylId = await featureAPI.createFeature(drawingId, rPartId, CCClasses.CCCylinder, 'Cylinder');
531
551
  if (cylId != null) {
532
- const diameterParam = { value: diameter, isExpr: typeof length === 'string' };
552
+ const diameterParam = { value: diameter, isExpr: typeof diameter === 'string' };
533
553
  const heightParam = { value: height, isExpr: typeof height === 'string' };
534
- await featureAPI.updateCylinder(drawingId, cylId, references, diameterParam, heightParam);
554
+ await featureAPI.updateCylinder(drawingId, cylId, rReferences, diameterParam, heightParam);
535
555
  return cylId;
536
556
  }
537
557
  return null;
538
- }, partId);
558
+ }, partId, ...references);
539
559
  },
540
560
  chamfer: (partId, type, references, dist1, dist2, angle) => {
541
- return this.resolve(async ([rPartId, ...rReferences]) => {
561
+ return this.resolve(async ([rPartId, rReferences]) => {
542
562
  const dist1Param = { value: dist1, isExpr: typeof dist1 === 'string' };
543
563
  const dist2Param = { value: dist2, isExpr: typeof dist2 === 'string' };
544
564
  const angleParam = { value: angle, isExpr: typeof angle === 'string' };
545
565
  const chamferId = await featureAPI.createFeature(drawingId, rPartId, CCClasses.CCChamfer, 'Chamfer');
546
- const chamferType = getChamferType(type);
547
- if (chamferType != undefined && chamferId != null) {
548
- await featureAPI.updateChamfer(drawingId, chamferId, chamferType, rReferences, dist1Param, dist2Param, angleParam);
566
+ if (chamferId != null) {
567
+ await featureAPI.updateChamfer(drawingId, chamferId, type, rReferences, dist1Param, dist2Param, angleParam);
549
568
  return chamferId;
550
569
  }
551
570
  return null;
552
- }, partId, ...references);
571
+ }, partId, references);
553
572
  },
554
573
  cone: (partId, references, bDiameter, tDiameter, height) => {
555
- return this.resolve(async ([rPartId]) => {
574
+ return this.resolve(async ([rPartId, ...rReferences]) => {
556
575
  const coneId = await featureAPI.createFeature(drawingId, rPartId, CCClasses.CCCone, 'Cone');
557
576
  if (coneId != null) {
558
577
  const bDiamParam = { value: bDiameter, isExpr: typeof bDiameter === 'string' };
559
578
  const tDiamParam = { value: tDiameter, isExpr: typeof tDiameter === 'string' };
560
579
  const heightParam = { value: height, isExpr: typeof height === 'string' };
561
- await featureAPI.updateCone(drawingId, coneId, references, bDiamParam, tDiamParam, heightParam);
580
+ await featureAPI.updateCone(drawingId, coneId, rReferences, bDiamParam, tDiamParam, heightParam);
562
581
  return coneId;
563
582
  }
564
583
  return null;
565
- }, partId);
584
+ }, partId, ...references);
566
585
  },
567
586
  createFastenedConstraint: (asmId, mate1, mate2, xOffset, yOffset, zOffset, name) => {
568
- return this.resolve(async ([rAsmId]) => {
587
+ return this.resolve(async ([rAsmId, rMate1, rMate2, rMatePath1, rMatePath2]) => {
569
588
  const constraintId = await ccAPI.assemblyBuilder.create3DConstraint(drawingId, rAsmId, CCClasses.CCFastenedConstraint, name);
570
589
  if (constraintId != null) {
571
590
  const xOffsetParam = { value: xOffset, isExpr: typeof xOffset === 'string' };
572
591
  const yOffsetParam = { value: yOffset, isExpr: typeof yOffset === 'string' };
573
592
  const zOffsetParam = { value: zOffset, isExpr: typeof zOffset === 'string' };
574
- await ccAPI.assemblyBuilder.updateFastenedConstraint(drawingId, constraintId, [mate1.matePath, mate1.wcsId, mate1.flip, mate1.reoriented], [mate2.matePath, mate2.wcsId, mate2.flip, mate2.reoriented], xOffsetParam, yOffsetParam, zOffsetParam);
593
+ rMatePath1 = Array.isArray(rMatePath1) ? rMatePath1 : [rMatePath1];
594
+ rMatePath2 = Array.isArray(rMatePath2) ? rMatePath2 : [rMatePath2];
595
+ await ccAPI.assemblyBuilder.updateFastenedConstraint(drawingId, constraintId, [rMatePath1, rMate1.wcsId, rMate1.flip, rMate1.reoriented], [rMatePath2, rMate2.wcsId, rMate2.flip, rMate2.reoriented], xOffsetParam, yOffsetParam, zOffsetParam);
575
596
  return constraintId;
576
597
  }
577
598
  return null;
578
- }, asmId);
599
+ }, asmId, mate1, mate2, ...mate1.matePath, ...mate2.matePath);
579
600
  },
580
601
  updateFastenedConstraint: (constrId, mate1, mate2, xOffset, yOffset, zOffset) => {
581
- return this.resolve(async ([rConstrId]) => {
582
- const xOffsetParam = { value: xOffset, isExpr: false };
583
- const yOffsetParam = { value: yOffset, isExpr: false };
584
- const zOffsetParam = { value: zOffset, isExpr: false };
585
- await ccAPI.assemblyBuilder.updateFastenedConstraint(drawingId, rConstrId, [mate1.matePath, mate1.wcsId, mate1.flip, mate1.reoriented], [mate2.matePath, mate2.wcsId, mate2.flip, mate2.reoriented], xOffsetParam, yOffsetParam, zOffsetParam);
586
- }, constrId);
602
+ return this.resolve(async ([rConstrId, rMate1, rMate2, rMatePath1, rMatePath2]) => {
603
+ const xOffsetParam = { value: xOffset, isExpr: typeof xOffset === 'string' };
604
+ const yOffsetParam = { value: yOffset, isExpr: typeof xOffset === 'string' };
605
+ const zOffsetParam = { value: zOffset, isExpr: typeof xOffset === 'string' };
606
+ rMatePath1 = Array.isArray(rMatePath1) ? rMatePath1 : [rMatePath1];
607
+ rMatePath2 = Array.isArray(rMatePath2) ? rMatePath2 : [rMatePath2];
608
+ await ccAPI.assemblyBuilder.updateFastenedConstraint(drawingId, rConstrId, [rMatePath1, rMate1.wcsId, rMate1.flip, rMate1.reoriented], [rMatePath2, rMate2.wcsId, rMate2.flip, rMate2.reoriented], xOffsetParam, yOffsetParam, zOffsetParam);
609
+ }, constrId, mate1, mate2, ...mate1.matePath, ...mate2.matePath);
587
610
  },
588
611
  updateFastenedConstraints: (...constraints) => {
589
- return this.resolve(async ([]) => {
612
+ return this.resolve(async ([...rConstraints]) => {
590
613
  const constrToAdd = [];
591
- constraints.forEach(constr => {
614
+ rConstraints.forEach(constr => {
592
615
  const xOffsetParam = [constr.xOffset, typeof constr.xOffset === 'string'];
593
616
  const yOffsetParam = [constr.yOffset, typeof constr.yOffset === 'string'];
594
617
  const zOffsetParam = [constr.zOffset, typeof constr.zOffset === 'string'];
@@ -602,33 +625,35 @@ export default class CAD {
602
625
  ]);
603
626
  });
604
627
  await ccAPI.assemblyBuilder.updateFastenedConstraints(drawingId, constrToAdd);
605
- });
628
+ }, ...constraints);
606
629
  },
607
630
  createFastenedOriginConstraint: (asmId, mate1, xOffset, yOffset, zOffset, name) => {
608
- return this.resolve(async ([rAsmId]) => {
631
+ return this.resolve(async ([rAsmId, rMatePath, rMateWcsId]) => {
609
632
  const constraintId = await ccAPI.assemblyBuilder.create3DConstraint(drawingId, rAsmId, CCClasses.CCFastenedOriginConstraint, name);
610
633
  if (constraintId != null) {
611
634
  const xOffsetParam = { value: xOffset, isExpr: typeof xOffset === 'string' };
612
635
  const yOffsetParam = { value: yOffset, isExpr: typeof yOffset === 'string' };
613
636
  const zOffsetParam = { value: zOffset, isExpr: typeof zOffset === 'string' };
614
- await ccAPI.assemblyBuilder.updateFastenedOriginConstraint(drawingId, constraintId, [mate1.matePath, mate1.wcsId, mate1.flip, mate1.reoriented], xOffsetParam, yOffsetParam, zOffsetParam);
637
+ rMatePath = Array.isArray(rMatePath) ? rMatePath : [rMatePath];
638
+ await ccAPI.assemblyBuilder.updateFastenedOriginConstraint(drawingId, constraintId, [rMatePath, rMateWcsId, mate1.flip, mate1.reoriented], xOffsetParam, yOffsetParam, zOffsetParam);
615
639
  return constraintId;
616
640
  }
617
641
  return null;
618
- }, asmId);
642
+ }, asmId, ...mate1.matePath, mate1.wcsId);
619
643
  },
620
644
  updateFastenedOriginConstraint: (constrId, mate1, xOffset, yOffset, zOffset) => {
621
- return this.resolve(async ([rConstrId]) => {
645
+ return this.resolve(async ([rConstrId, rMatePath, rMateWcsId]) => {
622
646
  const xOffsetParam = { value: xOffset, isExpr: typeof xOffset === 'string' };
623
647
  const yOffsetParam = { value: yOffset, isExpr: typeof yOffset === 'string' };
624
648
  const zOffsetParam = { value: zOffset, isExpr: typeof zOffset === 'string' };
625
- await ccAPI.assemblyBuilder.updateFastenedOriginConstraint(drawingId, rConstrId, [mate1.matePath, mate1.wcsId, mate1.flip, mate1.reoriented], xOffsetParam, yOffsetParam, zOffsetParam);
626
- }, constrId);
649
+ rMatePath = Array.isArray(rMatePath) ? rMatePath : [rMatePath];
650
+ await ccAPI.assemblyBuilder.updateFastenedOriginConstraint(drawingId, rConstrId, [rMatePath, rMateWcsId, mate1.flip, mate1.reoriented], xOffsetParam, yOffsetParam, zOffsetParam);
651
+ }, constrId, ...mate1.matePath, mate1.wcsId);
627
652
  },
628
653
  updateFastenedOriginConstraints: (...constraints) => {
629
- return this.resolve(async ([]) => {
654
+ return this.resolve(async ([...rConstraints]) => {
630
655
  const constrToAdd = [];
631
- constraints.forEach(constr => {
656
+ rConstraints.forEach(constr => {
632
657
  const xOffsetParam = [constr.xOffset, typeof constr.xOffset === 'string'];
633
658
  const yOffsetParam = [constr.yOffset, typeof constr.yOffset === 'string'];
634
659
  const zOffsetParam = [constr.zOffset, typeof constr.zOffset === 'string'];
@@ -641,7 +666,7 @@ export default class CAD {
641
666
  ]);
642
667
  });
643
668
  await ccAPI.assemblyBuilder.updateFastenedOriginConstraints(drawingId, constrToAdd);
644
- });
669
+ }, ...constraints);
645
670
  },
646
671
  createBufferGeometry: async (objectId) => {
647
672
  await this.queue;
@@ -673,18 +698,18 @@ export default class CAD {
673
698
  return scene;
674
699
  },
675
700
  createExpressions: (partId, ...members) => {
676
- return this.resolve(async (resolvedArgs) => {
701
+ return this.resolve(async ([rPartId]) => {
677
702
  const membersToAdd = [];
678
703
  members.forEach(mem => {
679
704
  const isExpr = typeof mem.value === 'string'; // TODO Expression unterscheiden von normalen STrings
680
- const dataType = getDataType(mem.value);
705
+ const dataType = isExpr ? DataType.REAL : getDataType(mem.value); // TODO: Aktuell nur Real Werte als Expression
681
706
  const featureAPIParam = {
682
707
  value: mem.value,
683
708
  isExpr: isExpr,
684
709
  };
685
710
  membersToAdd.push([mem.name, featureAPIParam, dataType]);
686
711
  });
687
- const success = featureAPI.updateExpressionSet(drawingId, resolvedArgs[0], membersToAdd, [], []);
712
+ const success = featureAPI.updateExpressionSet(drawingId, rPartId, membersToAdd, [], []);
688
713
  return success;
689
714
  }, partId);
690
715
  },
@@ -711,121 +736,109 @@ export default class CAD {
711
736
  });
712
737
  },
713
738
  createWorkAxis: (partId, type, references, position, direction, local, name) => {
714
- return this.resolve(async ([rPartId, rReferences]) => {
715
- const wAType = getWAType(type);
739
+ return this.resolve(async ([rPartId, ...rReferences]) => {
716
740
  const wAName = name ? name : 'WorkAxis';
717
741
  const wARefs = rReferences;
718
- if (wAType != undefined) {
719
- const wAId = await featureAPI.createWorkAxis(drawingId, rPartId, {
720
- axisType: wAType,
721
- references: wARefs,
722
- name: wAName,
723
- position: position,
724
- direction: direction,
725
- local: local,
726
- });
727
- if (wAId != null) {
728
- const positionParam = {
729
- value: position,
730
- isExpr: typeof position === 'string',
731
- };
732
- const directionParam = {
733
- value: direction,
734
- isExpr: typeof direction === 'string',
735
- };
736
- await featureAPI.updateWorkAxis(drawingId, wAId, wAType, wARefs, positionParam, directionParam, local);
737
- return wAId;
738
- }
742
+ const wAId = await featureAPI.createWorkAxis(drawingId, rPartId, {
743
+ axisType: type,
744
+ references: wARefs,
745
+ name: wAName,
746
+ position: position,
747
+ direction: direction,
748
+ local: local,
749
+ });
750
+ if (wAId != null) {
751
+ const positionParam = {
752
+ value: position,
753
+ isExpr: typeof position === 'string',
754
+ };
755
+ const directionParam = {
756
+ value: direction,
757
+ isExpr: typeof direction === 'string',
758
+ };
759
+ await featureAPI.updateWorkAxis(drawingId, wAId, type, wARefs, positionParam, directionParam, local);
760
+ return wAId;
739
761
  }
740
762
  return null;
741
- }, partId, references);
763
+ }, partId, ...references);
742
764
  },
743
765
  createWorkCoordSystem: (partId, type, references, coordinateSystem, offset, rotation, inverted, local, name) => {
744
- return this.resolve(async ([rPartId, rReferences]) => {
745
- const wCSType = getWCSType(type);
766
+ return this.resolve(async ([rPartId, ...rReferences]) => {
746
767
  const wCSName = name ? name : 'WorkCoordSystem';
747
768
  const wCSRefs = rReferences;
748
- if (wCSType != undefined) {
749
- const wCSId = await featureAPI.createWorkCoordSystem(drawingId, rPartId, {
750
- coordSystemType: wCSType,
751
- name: wCSName,
752
- references: wCSRefs,
753
- coordinateSystem,
754
- offset,
755
- rotation,
756
- inverted,
757
- local,
758
- });
759
- if (wCSId != null) {
760
- const offsetParam = { value: offset, isExpr: typeof offset === 'string' };
761
- const rotationParam = {
762
- value: rotation,
763
- isExpr: typeof rotation === 'string',
764
- };
765
- await featureAPI.updateWorkCoordSystem(drawingId, wCSId, wCSType, wCSRefs, coordinateSystem, offsetParam, rotationParam, inverted, local);
766
- return wCSId;
767
- }
769
+ const wCSId = await featureAPI.createWorkCoordSystem(drawingId, rPartId, {
770
+ coordSystemType: type,
771
+ name: wCSName,
772
+ references: wCSRefs,
773
+ coordinateSystem,
774
+ offset,
775
+ rotation,
776
+ inverted,
777
+ local,
778
+ });
779
+ if (wCSId != null) {
780
+ const offsetParam = { value: offset, isExpr: typeof offset === 'string' };
781
+ const rotationParam = {
782
+ value: rotation,
783
+ isExpr: typeof rotation === 'string',
784
+ };
785
+ await featureAPI.updateWorkCoordSystem(drawingId, wCSId, type, wCSRefs, coordinateSystem, offsetParam, rotationParam, inverted, local);
786
+ return wCSId;
768
787
  }
769
788
  return null;
770
- }, partId, references);
789
+ }, partId, ...references);
771
790
  },
772
791
  createWorkPlane: (partId, type, references, offset, angle, position, normal, local, name) => {
773
- return this.resolve(async ([rPartId, rReferences]) => {
774
- const wPType = getWPType(type);
792
+ return this.resolve(async ([rPartId, ...rReferences]) => {
775
793
  const wPName = name ? name : 'WorkPlane';
776
794
  const wPRefs = rReferences;
777
- if (wPType != undefined) {
778
- const wPId = await featureAPI.createWorkPlane(drawingId, rPartId, {
779
- planeType: wPType,
780
- references: wPRefs,
781
- offsetOrAngle: offset,
782
- name: wPName,
783
- position: position,
784
- normal: normal,
785
- local: local,
786
- });
787
- if (wPId != undefined) {
788
- const offsetParam = { value: offset, isExpr: typeof offset === 'string' };
789
- const angleParam = { value: angle, isExpr: typeof angle === 'string' };
790
- const positionParam = {
791
- value: position,
792
- isExpr: typeof position === 'string',
793
- };
794
- const normalParam = { value: normal, isExpr: typeof normal === 'string' };
795
- await featureAPI.updateWorkPlane(drawingId, wPId, wPType, wPRefs, offsetParam, angleParam, positionParam, normalParam, local);
796
- return wPId;
797
- }
795
+ const wPId = await featureAPI.createWorkPlane(drawingId, rPartId, {
796
+ planeType: type,
797
+ references: wPRefs,
798
+ offsetOrAngle: offset,
799
+ name: wPName,
800
+ position: position,
801
+ normal: normal,
802
+ local: local,
803
+ });
804
+ if (wPId != undefined) {
805
+ const offsetParam = { value: offset, isExpr: typeof offset === 'string' };
806
+ const angleParam = { value: angle, isExpr: typeof angle === 'string' };
807
+ const positionParam = {
808
+ value: position,
809
+ isExpr: typeof position === 'string',
810
+ };
811
+ const normalParam = { value: normal, isExpr: typeof normal === 'string' };
812
+ await featureAPI.updateWorkPlane(drawingId, wPId, type, wPRefs, offsetParam, angleParam, positionParam, normalParam, local);
813
+ return wPId;
798
814
  }
799
815
  return null;
800
- }, partId, references);
816
+ }, partId, ...references);
801
817
  },
802
818
  createWorkPoint: (partId, type, references, position, local, name) => {
803
- return this.resolve(async ([rPartId, rReferences]) => {
804
- const wPTType = getWPTType(type);
819
+ return this.resolve(async ([rPartId, ...rReferences]) => {
805
820
  const wPTName = name ? name : 'WorkPoint';
806
821
  const wPTRefs = rReferences;
807
- if (wPTType != undefined) {
808
- const wPTId = await featureAPI.createWorkPoint(drawingId, rPartId, {
809
- pointType: wPTType,
810
- references: wPTRefs,
811
- name: wPTName,
812
- position: position,
813
- local: local,
814
- });
815
- if (wPTId != undefined) {
816
- const positionParam = {
817
- value: position,
818
- isExpr: typeof position === 'string',
819
- };
820
- await featureAPI.updateWorkPoint(drawingId, wPTId, wPTType, wPTRefs, positionParam, local);
821
- return wPTId;
822
- }
822
+ const wPTId = await featureAPI.createWorkPoint(drawingId, rPartId, {
823
+ pointType: type,
824
+ references: wPTRefs,
825
+ name: wPTName,
826
+ position: position,
827
+ local: local,
828
+ });
829
+ if (wPTId != undefined) {
830
+ const positionParam = {
831
+ value: position,
832
+ isExpr: typeof position === 'string',
833
+ };
834
+ await featureAPI.updateWorkPoint(drawingId, wPTId, type, wPTRefs, positionParam, local);
835
+ return wPTId;
823
836
  }
824
837
  return null;
825
- }, partId, references);
838
+ }, partId, ...references);
826
839
  },
827
840
  fillet: (partId, references, radius) => {
828
- return this.resolve(async ([rPartId, ...rReferences]) => {
841
+ return this.resolve(async ([rPartId, rReferences]) => {
829
842
  const radiusParam = { value: radius, isExpr: typeof radius === 'string' };
830
843
  const filletId = await featureAPI.createFeature(drawingId, rPartId, CCClasses.CCConstantRadiusFillet, 'Fillet');
831
844
  if (filletId != null) {
@@ -833,7 +846,39 @@ export default class CAD {
833
846
  return filletId;
834
847
  }
835
848
  return null;
836
- }, partId, ...references);
849
+ }, partId, references);
850
+ },
851
+ findOrSelect: (partId, type, length, positions) => {
852
+ return this.resolve(async ([rPartId]) => {
853
+ let filter = lineSegmentsFilter;
854
+ switch (type) {
855
+ case 0: // Vertex
856
+ filter = pointFilter;
857
+ break;
858
+ case 1: // Edge
859
+ filter = lineSegmentsFilter;
860
+ break;
861
+ case 2: // Loop
862
+ filter = loopFilter;
863
+ break;
864
+ case 3: // Face
865
+ filter = planeFilter;
866
+ break;
867
+ }
868
+ const geometries = positions
869
+ ? await ccAPI.geometry.findGeometriesByPoints(drawingId, rPartId, type, positions)
870
+ : await waitForSelect(length, filter, (resolveSelection, items, diff) => {
871
+ if (items.length > length - 1) {
872
+ resolveSelection(items.map(i => i.data.graphicId));
873
+ ccAPI.geometry
874
+ .getPointsByGeometries(drawingId, items.map(i => i.data.graphicId))
875
+ .then(points => {
876
+ logPoints(points);
877
+ });
878
+ }
879
+ });
880
+ return geometries;
881
+ }, partId);
837
882
  },
838
883
  getAssemblyFromContainer: (asmName) => {
839
884
  return this.resolve(async ([]) => {
@@ -913,9 +958,9 @@ export default class CAD {
913
958
  },
914
959
  getFeatureByName: (partId, featureName) => {
915
960
  return this.resolve(async ([rProductId]) => {
916
- const solid = await featureAPI.getFeatureByName(drawingId, rProductId, featureName);
917
- if (solid !== null) {
918
- return solid;
961
+ const feature = await featureAPI.getFeatureByName(drawingId, rProductId, featureName);
962
+ if (feature !== null) {
963
+ return feature;
919
964
  }
920
965
  return null;
921
966
  }, partId);
@@ -926,13 +971,13 @@ export default class CAD {
926
971
  }, referenceId, ownerId);
927
972
  },
928
973
  removeNodes: (...nodes) => {
929
- return this.resolve(async ([]) => {
974
+ return this.resolve(async ([...rNodes]) => {
930
975
  const nodesToRemove = [];
931
- nodes.forEach(node => {
976
+ rNodes.forEach(node => {
932
977
  nodesToRemove.push([node.referenceId, node.ownerId]);
933
978
  });
934
979
  return ccAPI.assemblyBuilder.removeNodes(drawingId, nodesToRemove);
935
- });
980
+ }, ...nodes);
936
981
  },
937
982
  importFeature: (partId, content, format, name) => {
938
983
  return this.resolve(async ([rPartId]) => {
@@ -947,19 +992,58 @@ export default class CAD {
947
992
  return null;
948
993
  }, partId);
949
994
  },
995
+ loadSketch: (partId, stream, planeId, name) => {
996
+ return this.resolve(async ([rPartId, rPlaneId]) => {
997
+ const sketch = await sketcherAPI.createSketch(drawingId, rPartId);
998
+ if (sketch) {
999
+ const tree = getDrawing(drawingId).structure.tree;
1000
+ const plane = tree[rPlaneId];
1001
+ if (plane && base.isA(plane.class, CCClasses.CCWorkPlane)) {
1002
+ await sketcherAPI.setWorkPlane(drawingId, sketch, rPlaneId);
1003
+ }
1004
+ else {
1005
+ await sketcherAPI.createAndSetWorkPlane(drawingId, sketch, rPlaneId);
1006
+ }
1007
+ await sketcherAPI.loadSketch(drawingId, rPartId, sketch, stream, name);
1008
+ return sketch;
1009
+ }
1010
+ }, partId, planeId);
1011
+ },
1012
+ copySketch: (partId, sketchId, planeId) => {
1013
+ return this.resolve(async ([rPartId, rPlaneId, rSketchId]) => {
1014
+ const sketch = await sketcherAPI.createSketch(drawingId, rPartId);
1015
+ if (sketch) {
1016
+ const tree = getDrawing(drawingId).structure.tree;
1017
+ const plane = tree[rPlaneId];
1018
+ if (plane && base.isA(plane.class, CCClasses.CCWorkPlane)) {
1019
+ await sketcherAPI.setWorkPlane(drawingId, sketch, rPlaneId);
1020
+ }
1021
+ else {
1022
+ await sketcherAPI.createAndSetWorkPlane(drawingId, sketch, rPlaneId);
1023
+ }
1024
+ await sketcherAPI.copySketch(drawingId, sketch, rSketchId);
1025
+ return sketch;
1026
+ }
1027
+ }, partId, planeId, sketchId);
1028
+ },
1029
+ placeSketch: (sketchId, planeId, invertPlane, axisId, isXAxis, invertAxis, originId) => {
1030
+ return this.resolve(async ([rSketchId, rPlaneId, rAxisId, rOriginId]) => {
1031
+ await sketcherAPI.setSketchRefs(drawingId, rSketchId, rPlaneId, invertPlane, rAxisId, isXAxis, invertAxis, rOriginId);
1032
+ }, sketchId, planeId, axisId, originId);
1033
+ },
950
1034
  transformNode: (referenceId, ownerId, transformation) => {
951
1035
  return this.resolve(async ([rRefId, rOwnerId]) => {
952
1036
  await ccAPI.assemblyBuilder.setNodeTransformation(drawingId, rRefId, rOwnerId, transformation);
953
1037
  }, referenceId, ownerId);
954
1038
  },
955
1039
  translate: (partId, featureIds, references, inverted, distance) => {
956
- return this.resolve(async ([rPartId, rFeatureIds, rReferences]) => {
1040
+ return this.resolve(async ([rPartId, rFeatureIds, ...rReferences]) => {
957
1041
  const translationId = await featureAPI.createFeature(drawingId, rPartId, CCClasses.CCTranslation, 'Translate');
958
1042
  if (translationId !== null) {
959
1043
  const cDrawing = await getDrawing(drawingId);
960
1044
  const entArray = [];
961
1045
  for (const rFeatureId of rFeatureIds) {
962
- const entity = cDrawing.structure.tree[rFeatureId].children;
1046
+ const entity = cDrawing.structure.tree[(await rFeatureId)].children;
963
1047
  if (entity != undefined) {
964
1048
  entArray.push(entity[0]);
965
1049
  }
@@ -969,8 +1053,9 @@ export default class CAD {
969
1053
  return translationId;
970
1054
  }
971
1055
  return null;
972
- }, partId, featureIds, references);
1056
+ }, partId, featureIds, ...references);
973
1057
  },
1058
+ // TODO: Remove this method. Is it necessary?
974
1059
  updateTranslate: (translationId, distance) => {
975
1060
  return this.resolve(async ([rTranslationId]) => {
976
1061
  const cDrawing = await getDrawing(drawingId);
@@ -990,12 +1075,21 @@ export default class CAD {
990
1075
  save: (type) => {
991
1076
  return ccAPI.baseModeler.save(drawingId, type);
992
1077
  },
1078
+ saveToUrl: (url, filetype) => {
1079
+ return ccAPI.baseModeler.saveToUrl(drawingId, url, filetype);
1080
+ },
993
1081
  load: (content, type) => {
994
1082
  return ccAPI.baseModeler.load(drawingId, content, type);
995
1083
  },
1084
+ loadFromUrl: (url, filetype) => {
1085
+ return ccAPI.baseModeler.loadFromUrl(drawingId, url, filetype, true);
1086
+ },
996
1087
  loadProduct: (content, type) => {
997
1088
  return ccAPI.assemblyBuilder.loadProduct(drawingId, content, type);
998
1089
  },
1090
+ loadProductFromUrl: (url, filetype) => {
1091
+ return ccAPI.assemblyBuilder.loadProductFromUrl(drawingId, url, filetype);
1092
+ },
999
1093
  pick: (partId, type, points) => {
1000
1094
  return this.resolve(async ([rPartId]) => {
1001
1095
  const refs = await featureAPI.pick(drawingId, rPartId, type, points);
@@ -1006,7 +1100,7 @@ export default class CAD {
1006
1100
  }, partId);
1007
1101
  },
1008
1102
  setExpressions: (partId, ...members) => {
1009
- return this.resolve(async (resolvedArgs) => {
1103
+ return this.resolve(async ([rPartId]) => {
1010
1104
  const membersToModify = [];
1011
1105
  members.forEach(mem => {
1012
1106
  const isExpr = typeof mem.value === 'string'; // TODO Expression unterscheiden von normalen STrings
@@ -1016,16 +1110,16 @@ export default class CAD {
1016
1110
  };
1017
1111
  membersToModify.push([mem.name, featureAPIParam]);
1018
1112
  });
1019
- const success = featureAPI.updateExpressionSet(drawingId, resolvedArgs[0], [], membersToModify, []);
1113
+ const success = featureAPI.updateExpressionSet(drawingId, rPartId, [], membersToModify, []);
1020
1114
  return success;
1021
1115
  }, partId);
1022
1116
  },
1023
1117
  setExpressionSets: (...exprSets) => {
1024
- return this.resolve(async ([]) => {
1118
+ return this.resolve(async ([...rExprSets]) => {
1025
1119
  const exprSetsToSet = [];
1026
- exprSets.forEach(exprSet => {
1120
+ rExprSets.forEach(exprSet => {
1027
1121
  const membersToModify = [];
1028
- exprSet.members.forEach(mem => {
1122
+ exprSet.members.forEach((mem) => {
1029
1123
  const isExpr = typeof mem.value === 'string'; // TODO Expression unterscheiden von normalen STrings
1030
1124
  membersToModify.push([mem.name, [mem.value, isExpr]]);
1031
1125
  });
@@ -1033,24 +1127,24 @@ export default class CAD {
1033
1127
  });
1034
1128
  const success = await featureAPI.updateExpressionSets(drawingId, exprSetsToSet);
1035
1129
  return success;
1036
- });
1130
+ }, ...exprSets);
1037
1131
  },
1038
1132
  deleteExpressions: (partId, members) => {
1039
- return this.resolve(async (resolvedArgs) => {
1040
- const success = featureAPI.updateExpressionSet(drawingId, resolvedArgs[0], [], [], members);
1133
+ return this.resolve(async ([rPartId]) => {
1134
+ const success = featureAPI.updateExpressionSet(drawingId, rPartId, [], [], members);
1041
1135
  return success;
1042
1136
  }, partId);
1043
1137
  },
1044
1138
  sphere: (partId, references, radius) => {
1045
- return this.resolve(async ([rPartId]) => {
1139
+ return this.resolve(async ([rPartId, ...rReferences]) => {
1046
1140
  const sphereId = await featureAPI.createFeature(drawingId, rPartId, CCClasses.CCSphere, 'Sphere');
1047
1141
  if (sphereId != null) {
1048
1142
  const radiusParam = { value: radius, isExpr: typeof radius === 'string' };
1049
- await featureAPI.updateSphere(drawingId, sphereId, references, radiusParam);
1143
+ await featureAPI.updateSphere(drawingId, sphereId, rReferences, radiusParam);
1050
1144
  return sphereId;
1051
1145
  }
1052
1146
  return null;
1053
- }, partId);
1147
+ }, partId, ...references);
1054
1148
  },
1055
1149
  };
1056
1150
  callback(publicApi);