@buerli.io/headless 0.0.36-beta.0 → 0.1.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.
@@ -65,6 +65,150 @@ export declare type ApiHistory = {
65
65
  transformation: Transform;
66
66
  name?: string;
67
67
  }[]) => IDs;
68
+ /**
69
+ * Adds a dimension to the product in the 3D view
70
+ * @param dimension dimension to be added to a product
71
+ * @example
72
+ * // Get the current product
73
+ * const productId = await api.getCurrentProduct()
74
+ *
75
+ * // Create a dimension
76
+ * const dimension: DimensionType = {
77
+ * productId: productId,
78
+ * dimParam: {
79
+ * dimType: 'LinearDimension',
80
+ * dimLabel: 'Breite = ',
81
+ * dimStartPos: { x: 0, y: 0, z: 0 },
82
+ * dimEndPos: { x: 100, y: 0, z: 0 },
83
+ * dimTextPos: { x: 50, y: -10, z: 0 },
84
+ * dimTextAngle: 0,
85
+ * dimOrientation: 'Horizontal',
86
+ * },
87
+ * dxfView: 'Top',
88
+ * }
89
+ *
90
+ * // Add the dimension
91
+ * const dimensionId = await api.addDimension(dimension)
92
+ * @image // tbd
93
+ * @return id of the added dimension
94
+ */
95
+ addDimension: (dimension: DimensionType) => ID;
96
+ /**
97
+ * Adds multiple dimensions to products in the 3D view
98
+ * @param dimensions dimensions to be added to products
99
+ * @example
100
+ * // Get the current product
101
+ * const productId = await api.getCurrentProduct()
102
+ *
103
+ * // Create dimensions
104
+ * const dimension1: DimensionType = {
105
+ * productId: productId,
106
+ * dimParam: {
107
+ * dimType: 'LinearDimension',
108
+ * dimLabel: 'Breite = ',
109
+ * dimStartPos: { x: 0, y: 0, z: 0 },
110
+ * dimEndPos: { x: 100, y: 0, z: 0 },
111
+ * dimTextPos: { x: 50, y: -10, z: 0 },
112
+ * dimTextAngle: 0,
113
+ * dimOrientation: 'Horizontal',
114
+ * },
115
+ * dxfView: 'Top',
116
+ * }
117
+ *
118
+ * const dimension2: DimensionType = {
119
+ * productId: productId,
120
+ * dimParam: {
121
+ * dimType: 'LinearDimension',
122
+ * dimLabel: 'Laenge = ',
123
+ * dimStartPos: { x: 0, y: 0, z: 0 },
124
+ * dimEndPos: { x: 0, y: 100, z: 0 },
125
+ * dimTextPos: { x: 10, y: 50, z: 0 },
126
+ * dimTextAngle: 0,
127
+ * dimOrientation: 'Horizontal',
128
+ * },
129
+ * dxfView: 'Top',
130
+ * }
131
+ *
132
+ * // Add the dimensions
133
+ * const dimensionIds = await api.addDimensions(dimension1, dimension2)
134
+ * @image // tbd
135
+ * @return array of ids of the added dimensions
136
+ */
137
+ addDimensions: (...dimensions: {
138
+ productId: number;
139
+ dimParam: {
140
+ dimType: DimTypes;
141
+ dimName?: string;
142
+ dimLabel: string;
143
+ dimValue?: number | null;
144
+ dimStartPos: PointMemValue;
145
+ dimEndPos: PointMemValue;
146
+ dimTextPos: PointMemValue;
147
+ dimTextAngle: number;
148
+ dimOrientation: OrientationTypes;
149
+ dimColor?: number;
150
+ dimLayer?: string;
151
+ };
152
+ dxfView: ViewTypes;
153
+ }[]) => IDs;
154
+ /**
155
+ * Creates different 2D views, depending on the given view types, in the given product.
156
+ * @param productId id of the product where the view will be created in
157
+ * @param viewTypes array of view types. E.g. 'Top', 'Front', 'Iso', ...
158
+ * @example
159
+ * // Optionally add dimensions to the product, see addDimension() or addDimensions()
160
+ * await api.addDimensions(...)
161
+ *
162
+ * // Create the wanted views
163
+ * await api.create2DViews(productId, ['Top', 'Right_90°', 'Iso'])
164
+ * @image // tbd
165
+ */
166
+ create2DViews: (productId: VID, viewTypes: ViewTypes[]) => IDs;
167
+ /**
168
+ * This method returns the boundary box of the given views.
169
+ * @param productId id of the product from where the boundary box will returned
170
+ * @param viewTypes array of view types. E.g. 'Top', 'Front', 'Iso', ...
171
+ * @example
172
+ * // After views have been created, see create2DViews(), you can get boundary boxes
173
+ * const bbs = await api.getBoundaryBoxFromViews(productId, ['Top', 'Right_90°', 'Iso'])
174
+ *
175
+ * // Returns for each view a min and max point
176
+ * console.info(bbs) // [[{x: -105, y: -89, z: 0}, {x: 105, y: 55, z: 0}], [...], [...]]
177
+ * @image // tbd
178
+ */
179
+ getBoundaryBoxFromViews: (productId: VID, viewTypes?: ViewTypes[]) => Promise<[PointMemValue, PointMemValue][]>;
180
+ /**
181
+ * @param productId id of the product where the views will be placed in
182
+ * @param viewPositions array of objects, containing the viewType and a vector which defines the moving vector of the given view
183
+ * @example
184
+ * // After the views have been created, see create2DViews(), you can place them relatively to origin {0,0,0}
185
+ * await api.place2DViews(productId, [
186
+ * { viewType: 'Iso', vector: { x: 500, y: 500, z: 0 } },
187
+ * { viewType: 'Right_90°', vector: { x: 500, y: 0, z: 0 } },
188
+ * ])
189
+ * @image // tbd
190
+ */
191
+ place2DViews: (productId: VID, viewPositions: {
192
+ viewType: ViewTypes;
193
+ vector: PointMemValue;
194
+ }[]) => Promise<void>;
195
+ /**
196
+ * @param productId id of the product where the views exist for export
197
+ * @example
198
+ * // After creating and placing the views, see place2DViews(), you can export them
199
+ * // You will get the dxf stream back
200
+ * await api.exportDXF(productId)
201
+ * @image // tbd
202
+ */
203
+ exportDXF: (productId: VID) => Promise<Uint8Array | null>;
204
+ /**
205
+ * @param dimensionsIds ids of the dimensions to be removed
206
+ * @example
207
+ * // You can remove existing dimensions
208
+ * await api.removeDimensions(dimensionIds)
209
+ * @image // tbd
210
+ */
211
+ removeDimensions: (dimensionIds: number[]) => Promise<void>;
68
212
  /**
69
213
  * Creates a boolean operation.
70
214
  * @param partId id of the part where the operation will be created on
@@ -603,6 +747,43 @@ export declare type ApiHistory = {
603
747
  * @image // tbd
604
748
  */
605
749
  getAssemblyNode: (refId: VID, nodeName?: string) => IDs;
750
+ /**
751
+ * Returns the id of the current product
752
+ * @example // tbd
753
+ * @image // tbd
754
+ */
755
+ getCurrentProduct: () => ID;
756
+ /**
757
+ * Sets the node with refId to the new current node
758
+ *
759
+ * @param refId Reference id of the node to set as the current
760
+ * @example // tbd
761
+ * @image // tbd
762
+ */
763
+ setCurrentNode: (refId: VID) => void;
764
+ /**
765
+ * Sets the product with productId to the new current product
766
+ *
767
+ * @param productId Id of the product to set as the current
768
+ * @example // tbd
769
+ * @image // tbd
770
+ */
771
+ setCurrentProduct: (productId: VID) => void;
772
+ /**
773
+ * Returns the id of the current node
774
+ * @example // tbd
775
+ * @image // tbd
776
+ */
777
+ getCurrentNode: () => ID;
778
+ /**
779
+ * Returns the coordinate system of the node with the
780
+ * given refId. Where the node is an instance in the expanded tree of any product template
781
+ *
782
+ * @param refId Reference id of the node to get the coordinate system from
783
+ * @example // tbd
784
+ * @image // tbd
785
+ */
786
+ getCoordSysFromNode: (refId: VID) => Promise<number[][]>;
606
787
  /**
607
788
  * Returns the part with given name from part container.
608
789
  * If partName is empty, all parts from part container will be returned.
@@ -719,6 +900,16 @@ export declare type ApiHistory = {
719
900
  referenceId: number;
720
901
  ownerId: number;
721
902
  }[]) => Promise<void>;
903
+ /**
904
+ * Transforms the node with referenceId with the given transformation
905
+ *
906
+ * @param referenceId id of the node to transform
907
+ * @param ownerId id of the owner (parent) of node we want to transform
908
+ * @param transformation array of three vectors [origin, xAxis, yAxis]
909
+ * @example // tbd
910
+ * @image // tbd
911
+ */
912
+ transformNode: (referenceId: VID, ownerId: VID, transformation: Transform) => Promise<void>;
722
913
  /**
723
914
  * Translates a feature along a given axis.
724
915
  * @param partId id ot the part where features will be translated
@@ -768,16 +959,32 @@ export declare type ApiHistory = {
768
959
  * const geoms = await api.createBufferGeometry(part)
769
960
  * return geoms.map(geom => new THREE.Mesh(geom, new THREE.MeshStandardMaterial()))
770
961
  * @image // tbd
962
+ * @returns true, if updating expressions was successfull
771
963
  */
772
964
  setExpressions: (partId: VID, ...members: {
773
965
  name: string;
774
966
  value: number | PointMemValue | string;
775
- }[]) => Promise<void>;
967
+ }[]) => Promise<boolean>;
968
+ /**
969
+ * Updates multiple expression sets in different parts at once
970
+ *
971
+ * @param exprSets array of expression objects containing the part id and the expression to set
972
+ * @example // tbd
973
+ * @image // tbd
974
+ * @returns true, if updating expressions in all expression sets was successfull
975
+ */
976
+ setExpressionSets: (...exprSets: {
977
+ partId: number;
978
+ members: {
979
+ name: string;
980
+ value: number | PointMemValue | string;
981
+ }[];
982
+ }[]) => Promise<boolean>;
776
983
  };
777
984
  export default class CAD {
778
985
  private drawingId;
779
986
  queue: Promise<number>;
780
- constructor(url: string);
987
+ constructor();
781
988
  resolve(callback: (...results: any) => Promise<any>, ...args: any[]): Promise<any>;
782
989
  init(callback: (api: ApiHistory) => void): () => Promise<void>;
783
990
  destroy(): void;
@@ -799,6 +1006,26 @@ declare type ChamferTypes = 'Equal_Distance' | 'Two_Distances' | 'Distance_And_A
799
1006
  declare type PickTypes = 'vertex' | 'edge' | 'face';
800
1007
  declare type DataTypes = 'of1' | 'stp' | 'step';
801
1008
  declare type SupportedImportFormats = 'STEP' | 'STP' | 'SAT' | 'IWB' | 'IWP' | 'IWC' | 'IGS' | 'STL' | 'DXF' | 'DWG';
1009
+ declare type DimTypes = 'LinearDimension';
1010
+ declare type ViewTypes = 'Top' | 'Front' | 'Right' | 'Left' | 'Bottom' | 'Right_90°' | 'Left_90°' | 'Back' | 'Iso';
1011
+ export declare type OrientationTypes = 'Horizontal' | 'Vertical';
1012
+ export declare type DimensionType = {
1013
+ productId: number;
1014
+ dimParam: {
1015
+ dimType: DimTypes;
1016
+ dimName?: string;
1017
+ dimLabel: string;
1018
+ dimValue?: number | null;
1019
+ dimStartPos: PointMemValue;
1020
+ dimEndPos: PointMemValue;
1021
+ dimTextPos: PointMemValue;
1022
+ dimTextAngle: number;
1023
+ dimOrientation: OrientationTypes;
1024
+ dimColor?: number;
1025
+ dimLayer?: string;
1026
+ };
1027
+ dxfView: ViewTypes;
1028
+ };
802
1029
  /**
803
1030
  * Information about constraint.
804
1031
  * [
package/build/history.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable max-lines */
2
- import { BooleanOperationType, ccAPI, CCClasses, ccUtils, ChamferType, DataType, WorkAxisType, WorkCoordSystemType, WorkPlaneType, WorkPointType } from '@buerli.io/classcad';
3
- import { api, getDrawing, init, MathUtils, } from '@buerli.io/core';
4
- import { Group, Mesh, MeshStandardMaterial, Scene } from 'three';
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';
4
+ import { Group, Mesh, MeshStandardMaterial, Scene, Vector3 } from 'three';
5
5
  import * as BufferGeometryUtils_ from 'three/examples/jsm/utils/BufferGeometryUtils';
6
6
  const featureAPI = ccAPI.feature;
7
7
  let BufferGeometryUtils = BufferGeometryUtils_;
@@ -140,6 +140,68 @@ const getWPTType = (type) => {
140
140
  break;
141
141
  }
142
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
+ };
177
+ const getDimensionType = (type) => {
178
+ switch (type) {
179
+ case 'LinearDimension':
180
+ return CCClasses.CCLinearDimension;
181
+ case undefined:
182
+ break;
183
+ }
184
+ };
185
+ const getGlobalTransformation = (drawingId, ownerId, localTransformation) => {
186
+ const lT = localTransformation;
187
+ const coordSysOwner = ccUtils.assembly.getCoordSysFromNode(drawingId, ownerId);
188
+ if (coordSysOwner) {
189
+ const origin = [lT[0].x, lT[0].y, lT[0].z];
190
+ const xAxis = [lT[1].x, lT[1].y, lT[1].z];
191
+ const yAxis = [lT[2].x, lT[2].y, lT[2].z];
192
+ const zAxis = new Vector3().crossVectors(new Vector3(lT[1].x, lT[1].y, lT[1].z), new Vector3(lT[2].x, lT[2].y, lT[2].z));
193
+ const matrix = MathUtils.convertToMatrix4([origin, xAxis, yAxis, [zAxis.x, zAxis.y, zAxis.z]]);
194
+ const transformation = MathUtils.convertToMatrix4(coordSysOwner).clone().multiply(matrix);
195
+ const transformationCoords = MathUtils.convertToCoordinateSystem(transformation);
196
+ const tC = transformationCoords;
197
+ return [
198
+ { x: tC[0][0], y: tC[0][1], z: tC[0][2] },
199
+ { x: tC[1][0], y: tC[1][1], z: tC[1][2] },
200
+ { x: tC[2][0], y: tC[2][1], z: tC[2][2] },
201
+ ];
202
+ }
203
+ return undefined;
204
+ };
143
205
  const createRecursiveBufferGeometry = async (object, drawingId, bufferGeomArray) => {
144
206
  let cDrawing = getDrawing(drawingId);
145
207
  const tree = cDrawing.structure.tree;
@@ -244,14 +306,12 @@ const createRecursiveScene = async (object, drawingId, root, options) => {
244
306
  }
245
307
  };
246
308
  export default class CAD {
247
- constructor(url) {
309
+ constructor() {
248
310
  this.drawingId = null;
249
311
  this.queue = Promise.resolve(0);
250
312
  this.queue = Promise.resolve(0);
251
- init({ url });
252
313
  }
253
314
  resolve(callback, ...args) {
254
- // eslint-disable-next-line promise/no-callback-in-promise
255
315
  return (this.queue = this.queue.then(() => Promise.all(args).then(callback)));
256
316
  }
257
317
  init(callback) {
@@ -263,18 +323,117 @@ export default class CAD {
263
323
  const publicApi = {
264
324
  addNode: (productId, ownerId, transformation, name) => {
265
325
  return this.resolve(async ([rProductId, rOwnerId]) => {
266
- return ccAPI.assemblyBuilder.addNode(drawingId, rProductId, rOwnerId, transformation, name);
326
+ const globalTransformation = getGlobalTransformation(drawingId, rOwnerId, transformation) || transformation;
327
+ return ccAPI.assemblyBuilder.addNode(drawingId, rProductId, rOwnerId, globalTransformation, name);
267
328
  }, productId, ownerId);
268
329
  },
269
330
  addNodes: (...nodes) => {
270
331
  return this.resolve(async ([]) => {
271
332
  const nodesToAdd = [];
272
333
  nodes.forEach(node => {
273
- nodesToAdd.push([node.productId, node.ownerId, node.transformation, node.name]);
334
+ const globalTransformation = getGlobalTransformation(drawingId, node.ownerId, node.transformation) || node.transformation;
335
+ nodesToAdd.push([node.productId, node.ownerId, globalTransformation, node.name]);
274
336
  });
275
337
  return ccAPI.assemblyBuilder.addNodes(drawingId, nodesToAdd);
276
338
  });
277
339
  },
340
+ addDimension: (dim) => {
341
+ return this.resolve(async ([rProductId]) => {
342
+ const orientation = getOrientationType(dim.dimParam.dimOrientation);
343
+ const view = getViewType(dim.dxfView);
344
+ const dimensionType = getDimensionType(dim.dimParam.dimType);
345
+ if (orientation !== undefined && view !== undefined) {
346
+ const dimParam = [
347
+ rProductId,
348
+ [
349
+ dimensionType || 'CC_LinearDimenion',
350
+ dim.dimParam.dimName || 'Dimension',
351
+ dim.dimParam.dimLabel,
352
+ dim.dimParam.dimValue || null,
353
+ dim.dimParam.dimStartPos,
354
+ dim.dimParam.dimEndPos,
355
+ dim.dimParam.dimTextPos,
356
+ dim.dimParam.dimTextAngle,
357
+ orientation,
358
+ dim.dimParam.dimColor || 256,
359
+ dim.dimParam.dimLayer || '2', // which layer makes sense as default?
360
+ ],
361
+ view,
362
+ ];
363
+ return ccAPI.drawing2D.addDimension(drawingId, dimParam);
364
+ }
365
+ }, dim.productId);
366
+ },
367
+ addDimensions: (...dimensions) => {
368
+ return this.resolve(async ([]) => {
369
+ const dimsToAdd = [];
370
+ dimensions.forEach(dim => {
371
+ const orientation = getOrientationType(dim.dimParam.dimOrientation);
372
+ const view = getViewType(dim.dxfView);
373
+ const dimensionType = getDimensionType(dim.dimParam.dimType);
374
+ if (orientation !== undefined && view !== undefined) {
375
+ dimsToAdd.push([
376
+ dim.productId,
377
+ [
378
+ dimensionType || 'CC_LinearDimenion',
379
+ dim.dimParam.dimName || 'Dimension',
380
+ dim.dimParam.dimLabel,
381
+ dim.dimParam.dimValue || null,
382
+ dim.dimParam.dimStartPos,
383
+ dim.dimParam.dimEndPos,
384
+ dim.dimParam.dimTextPos,
385
+ dim.dimParam.dimTextAngle,
386
+ orientation,
387
+ dim.dimParam.dimColor || 256,
388
+ dim.dimParam.dimLayer || '2', // which layer makes sense as default?
389
+ ],
390
+ view,
391
+ ]);
392
+ }
393
+ });
394
+ return ccAPI.drawing2D.addDimensions(drawingId, dimsToAdd);
395
+ });
396
+ },
397
+ create2DViews: (productId, viewTypes) => {
398
+ return this.resolve(async ([rProductId]) => {
399
+ const types = viewTypes.map(viewType => getViewType(viewType));
400
+ const viewIds = await ccAPI.drawing2D.create2DViews(drawingId, rProductId, types);
401
+ if (viewIds !== null) {
402
+ await ccAPI.drawing2D.centerAllViews(drawingId, rProductId, types);
403
+ return viewIds;
404
+ }
405
+ return null;
406
+ }, productId);
407
+ },
408
+ getBoundaryBoxFromViews: (productId, viewTypes) => {
409
+ return this.resolve(async ([rProductId]) => {
410
+ const types = viewTypes === null || viewTypes === void 0 ? void 0 : viewTypes.map(viewType => getViewType(viewType));
411
+ const bbs = await ccAPI.drawing2D.getBoundaryBoxFromViews(drawingId, rProductId, types);
412
+ return bbs;
413
+ }, productId);
414
+ },
415
+ place2DViews: (productId, viewPositions) => {
416
+ return this.resolve(async ([rProductId]) => {
417
+ const viewPositionParams = [];
418
+ viewPositions.forEach(viewPos => {
419
+ const type = getViewType(viewPos.viewType);
420
+ if (type !== undefined) {
421
+ viewPositionParams.push([type, viewPos.vector]);
422
+ }
423
+ });
424
+ return ccAPI.drawing2D.place2DViews(drawingId, rProductId, viewPositionParams);
425
+ }, productId);
426
+ },
427
+ exportDXF: (productId) => {
428
+ return this.resolve(async ([rProductId]) => {
429
+ return ccAPI.drawing2D.exportDXF(drawingId, rProductId);
430
+ }, productId);
431
+ },
432
+ removeDimensions: (dimensionIds) => {
433
+ return this.resolve(async () => {
434
+ return ccAPI.drawing2D.removeDimensions(drawingId, dimensionIds);
435
+ });
436
+ },
278
437
  boolean: (partId, type, entities) => {
279
438
  return this.resolve(async ([rPartId, ...rEntities]) => {
280
439
  const cDrawing = await getDrawing(drawingId);
@@ -379,10 +538,14 @@ export default class CAD {
379
538
  const xOffsetParam = [constr.xOffset, typeof constr.xOffset === 'string'];
380
539
  const yOffsetParam = [constr.yOffset, typeof constr.yOffset === 'string'];
381
540
  const zOffsetParam = [constr.zOffset, typeof constr.zOffset === 'string'];
382
- constrToAdd.push([constr.constrId,
541
+ constrToAdd.push([
542
+ constr.constrId,
383
543
  [constr.mate1.matePath, constr.mate1.wcsId, constr.mate1.flip, constr.mate1.reoriented],
384
544
  [constr.mate2.matePath, constr.mate2.wcsId, constr.mate2.flip, constr.mate2.reoriented],
385
- xOffsetParam, yOffsetParam, zOffsetParam]);
545
+ xOffsetParam,
546
+ yOffsetParam,
547
+ zOffsetParam,
548
+ ]);
386
549
  });
387
550
  await ccAPI.assemblyBuilder.updateFastenedConstraints(drawingId, constrToAdd);
388
551
  });
@@ -415,9 +578,13 @@ export default class CAD {
415
578
  const xOffsetParam = [constr.xOffset, typeof constr.xOffset === 'string'];
416
579
  const yOffsetParam = [constr.yOffset, typeof constr.yOffset === 'string'];
417
580
  const zOffsetParam = [constr.zOffset, typeof constr.zOffset === 'string'];
418
- constrToAdd.push([constr.constrId,
581
+ constrToAdd.push([
582
+ constr.constrId,
419
583
  [constr.mate1.matePath, constr.mate1.wcsId, constr.mate1.flip, constr.mate1.reoriented],
420
- xOffsetParam, yOffsetParam, zOffsetParam]);
584
+ xOffsetParam,
585
+ yOffsetParam,
586
+ zOffsetParam,
587
+ ]);
421
588
  });
422
589
  await ccAPI.assemblyBuilder.updateFastenedOriginConstraints(drawingId, constrToAdd);
423
590
  });
@@ -632,6 +799,37 @@ export default class CAD {
632
799
  return null;
633
800
  }, refId);
634
801
  },
802
+ setCurrentNode: (refId) => {
803
+ return this.resolve(async ([rRefId]) => {
804
+ await ccAPI.assemblyBuilder.setCurrentNode(drawingId, rRefId);
805
+ }, refId);
806
+ },
807
+ getCurrentNode: () => {
808
+ return this.resolve(async () => {
809
+ const drw = getDrawing(drawingId);
810
+ return drw.structure.currentNode;
811
+ });
812
+ },
813
+ getCoordSysFromNode: (refId) => {
814
+ return this.resolve(async ([rRefId]) => {
815
+ const coordSys = ccUtils.assembly.getCoordSysFromNode(drawingId, rRefId);
816
+ if (coordSys != undefined) {
817
+ return coordSys;
818
+ }
819
+ return null;
820
+ }, refId);
821
+ },
822
+ setCurrentProduct: (productId) => {
823
+ return this.resolve(async ([rProductId]) => {
824
+ await ccAPI.baseModeler.setCurrentProduct(drawingId, rProductId);
825
+ }, productId);
826
+ },
827
+ getCurrentProduct: () => {
828
+ return this.resolve(async () => {
829
+ const drw = getDrawing(drawingId);
830
+ return drw.structure.currentProduct;
831
+ });
832
+ },
635
833
  getPartFromContainer: (partName) => {
636
834
  return this.resolve(async ([]) => {
637
835
  const partIds = ccUtils.assembly.getPartFromContainer(drawingId, partName);
@@ -695,6 +893,11 @@ export default class CAD {
695
893
  return null;
696
894
  }, partId);
697
895
  },
896
+ transformNode: (referenceId, ownerId, transformation) => {
897
+ return this.resolve(async ([rRefId, rOwnerId]) => {
898
+ await ccAPI.assemblyBuilder.setNodeTransformation(drawingId, rRefId, rOwnerId, transformation);
899
+ }, referenceId, ownerId);
900
+ },
698
901
  translate: (partId, featureIds, references, inverted, distance) => {
699
902
  return this.resolve(async ([rPartId, rFeatureIds, rReferences]) => {
700
903
  const translationId = await featureAPI.createFeature(drawingId, rPartId, CCClasses.CCTranslation, 'Translate');
@@ -763,6 +966,21 @@ export default class CAD {
763
966
  return success;
764
967
  }, partId);
765
968
  },
969
+ setExpressionSets: (...exprSets) => {
970
+ return this.resolve(async ([]) => {
971
+ const exprSetsToSet = [];
972
+ exprSets.forEach(exprSet => {
973
+ const membersToModify = [];
974
+ exprSet.members.forEach(mem => {
975
+ const isExpr = typeof mem.value === 'string'; // TODO Expression unterscheiden von normalen STrings
976
+ membersToModify.push([mem.name, [mem.value, isExpr]]);
977
+ });
978
+ exprSetsToSet.push([exprSet.partId, [], membersToModify, []]);
979
+ });
980
+ const success = await featureAPI.updateExpressionSets(drawingId, exprSetsToSet);
981
+ return success;
982
+ });
983
+ },
766
984
  deleteExpressions: (partId, members) => {
767
985
  return this.resolve(async (resolvedArgs) => {
768
986
  const success = featureAPI.updateExpressionSet(drawingId, resolvedArgs[0], [], [], members);
package/build/index.d.ts CHANGED
@@ -7,10 +7,12 @@ export { solid, history, createPolyline };
7
7
  *
8
8
  * Please have a look at https://github.com/awv-informatik/buerli/pull/129 for more information.
9
9
  */
10
- import { ApiHistory as ApiHistory1, ConstraintType as ConstraintType1, Transform as Transform1 } from './history';
10
+ import { ApiHistory as ApiHistory1, ConstraintType as ConstraintType1, Transform as Transform1, DimensionType as DimensionType1, OrientationTypes as OrientationTypes1 } from './history';
11
11
  export declare type ApiHistory = ApiHistory1;
12
12
  export declare type ConstraintType = ConstraintType1;
13
13
  export declare type Transform = Transform1;
14
+ export declare type DimensionType = DimensionType1;
15
+ export declare type OrientationTypes = OrientationTypes1;
14
16
  import { ApiNoHistory as ApiNoHistory1, FilletPoint as FilletPoint1, Polyline as Polyline1 } from './solid';
15
17
  export declare type ApiNoHistory = ApiNoHistory1;
16
18
  export declare type Polyline = Polyline1;
package/build/solid.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { AwvNodeClient } from '@buerli.io/classcad';
2
1
  import { ObjectID } from '@buerli.io/core';
3
2
  import { BufferGeometry, Scene, Vector3 } from 'three';
4
3
  /**
@@ -434,9 +433,8 @@ export declare type ApiNoHistory = {
434
433
  export declare function createPolyline(fPts: FilletPoint[]): Polyline;
435
434
  export default class CAD {
436
435
  private drawingId;
437
- private target;
438
436
  queue: Promise<number>;
439
- constructor(target: string | AwvNodeClient);
437
+ constructor();
440
438
  init(callback: (api: ApiNoHistory) => void): () => Promise<void>;
441
439
  destroy(): void;
442
440
  }
package/build/solid.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable max-lines */
2
2
  import { ccAPI } from '@buerli.io/classcad';
3
- import { api, getDrawing, init } from '@buerli.io/core';
3
+ import { api, getDrawing } from '@buerli.io/core';
4
4
  import { Mesh, MeshStandardMaterial, Scene, Shape } from 'three';
5
5
  import * as BufferGeometryUtils_ from 'three/examples/jsm/utils/BufferGeometryUtils';
6
6
  let BufferGeometryUtils = BufferGeometryUtils_;
@@ -68,10 +68,7 @@ const getTouchPoints = (info, radius) => {
68
68
  for (let i = 0; i < 2; i++) {
69
69
  const startPos = info.lineStarts[i];
70
70
  const endPos = info.lineEnds[i];
71
- const dir = endPos
72
- .clone()
73
- .sub(startPos)
74
- .normalize();
71
+ const dir = endPos.clone().sub(startPos).normalize();
75
72
  const maxDist = endPos.distanceTo(controlPos);
76
73
  dirs.push(dir);
77
74
  maxDists.push(maxDist);
@@ -194,17 +191,14 @@ const makeCCData = (curves) => {
194
191
  });
195
192
  };
196
193
  export default class CAD {
197
- constructor(target) {
194
+ constructor() {
198
195
  this.drawingId = null;
199
196
  this.queue = Promise.resolve(0);
200
197
  this.queue = Promise.resolve(0);
201
- if (typeof target !== 'string')
202
- this.target = target;
203
- init({ url: typeof target === 'string' ? target : '' });
204
198
  }
205
199
  init(callback) {
206
200
  const promise = new Promise(async (resolve, reject) => {
207
- const drawingId = await ccAPI.base.createCCDrawing('solid', this.target);
201
+ const drawingId = await ccAPI.base.createCCDrawing('solid');
208
202
  if (!drawingId)
209
203
  throw new Error('Drawing could not be created');
210
204
  this.drawingId = drawingId;
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@buerli.io/headless",
3
- "version": "0.0.36-beta.0",
3
+ "version": "0.1.0",
4
4
  "description": "A non-manifold CAD workflow for the web",
5
5
  "author": "AWV Informatik AG <info@awv-informatik.ch>",
6
+ "license": "ISC",
6
7
  "repository": {},
7
8
  "main": "build/index.js",
8
9
  "module": "build/index.js",
@@ -10,47 +11,24 @@
10
11
  "sideEffects": false,
11
12
  "scripts": {
12
13
  "ver": "npm version",
13
- "prepack": "npm run build:dist",
14
+ "prepack": "npm run clean && npm run build",
14
15
  "clean": "rimraf ./build",
15
- "build": "echo Typescript: && tsc --version && tsc && npm run build:copy && echo DONE",
16
- "build:dist": "npm run clean && echo Typescript: && tsc --version && tsc --sourceMap false && npm run build:copy && echo DONE",
17
- "build:copy": "copyfiles -a -u 1 \"./src/**/*.png\" \"./build\"",
16
+ "build": "tsc",
17
+ "build:dev": "tsc --sourceMap true --declarationMap true",
18
18
  "test": "echo no tests yet",
19
19
  "lint": "eslint \"./src/**/*.ts?(x)\"",
20
- "prettier": "prettier --write \"./{src,tests}/**/*.{js,jsx,ts,tsx,json}\""
21
- },
22
- "husky": {
23
- "hooks": {
24
- "pre-commit": "lint-staged"
25
- }
26
- },
27
- "prettier": {
28
- "semi": false,
29
- "arrowParens": "avoid",
30
- "trailingComma": "all",
31
- "singleQuote": true,
32
- "jsxBracketSameLine": true,
33
- "tabWidth": 2,
34
- "printWidth": 120
20
+ "prettify": "prettier --write \"./{src,tests}/**/*.{js,jsx,ts,tsx,json}\""
35
21
  },
36
- "lint-staged": {
37
- "*.{js,jsx,ts,tsx,json,md}": [
38
- "prettier --write",
39
- "git add"
40
- ]
41
- },
42
- "license": "ISC",
43
22
  "devDependencies": {
44
- "@types/three": "^0.130.1",
23
+ "@types/three": "^0.137",
45
24
  "copyfiles": "^2.1.1",
46
25
  "rimraf": "^2.6.3",
47
- "three": "^0.131.3",
48
- "typescript": "4.1.2"
26
+ "three": "^0.138"
49
27
  },
50
28
  "peerDependencies": {
51
- "three": ">=0.128"
29
+ "three": ">=0.138"
52
30
  },
53
31
  "dependencies": {
54
- "@buerli.io/classcad": "0.0.36-beta.0"
32
+ "@buerli.io/classcad": "0.1.0"
55
33
  }
56
34
  }