@buerli.io/headless 0.3.0-beta.1 → 0.4.0-beta.2

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.
@@ -412,7 +412,7 @@ export declare type ApiHistory = {
412
412
  wcsId: VID;
413
413
  flip: FlipType;
414
414
  reoriented: ReorientedType;
415
- }, xOffset: number | string, yOffset: number | string, zOffset: number | string, name: string) => ID;
415
+ }, xOffset: number | string, yOffset: number | string, zOffset: number | string, name: string) => Promise<ObjectID | null>;
416
416
  /**
417
417
  * Updates a fastened constraint.
418
418
  * @param constrId id of the constraint to update
@@ -444,13 +444,13 @@ export declare type ApiHistory = {
444
444
  updateFastenedConstraints: (...constraints: {
445
445
  constrId: VID;
446
446
  mate1: {
447
- matePath: number[];
447
+ matePath: VID[];
448
448
  wcsId: VID;
449
449
  flip: number;
450
450
  reoriented: number;
451
451
  };
452
452
  mate2: {
453
- matePath: number[];
453
+ matePath: VID[];
454
454
  wcsId: VID;
455
455
  flip: number;
456
456
  reoriented: number;
@@ -500,7 +500,7 @@ export declare type ApiHistory = {
500
500
  wcsId: VID;
501
501
  flip: FlipType;
502
502
  reoriented: ReorientedType;
503
- }, xOffset: number | string, yOffset: number | string, zOffset: number | string, name: string) => ID;
503
+ }, xOffset: number | string, yOffset: number | string, zOffset: number | string, name: string) => Promise<ObjectID | null>;
504
504
  /**
505
505
  * Updates a fastened origin constraint.
506
506
  * @param constrId id of the constraint to update
@@ -524,10 +524,10 @@ export declare type ApiHistory = {
524
524
  * @image // tbd
525
525
  */
526
526
  updateFastenedOriginConstraints: (...constraints: {
527
- constrId: number;
527
+ constrId: VID;
528
528
  mate1: {
529
- matePath: number[];
530
- wcsId: number;
529
+ matePath: VID[];
530
+ wcsId: VID;
531
531
  flip: number;
532
532
  reoriented: number;
533
533
  };
@@ -1137,9 +1137,9 @@ export default class CAD {
1137
1137
  init(callback: (api: ApiHistory) => void): () => Promise<void>;
1138
1138
  destroy(): void;
1139
1139
  }
1140
- declare type VID = ObjectID | Promise<ObjectID> | null | Promise<number | null>;
1140
+ declare type VID = ObjectID | null | Promise<ObjectID | null>;
1141
1141
  declare type VIDs = ObjectID[] | Promise<ObjectID[]>;
1142
- declare type ID = Promise<ObjectID> | Promise<number | null>;
1142
+ declare type ID = Promise<ObjectID | null>;
1143
1143
  declare type IDs = Promise<ObjectID[]>;
1144
1144
  declare type Point = {
1145
1145
  x: number;
package/build/history.js CHANGED
@@ -1,3 +1,10 @@
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
+ };
1
8
  /* eslint-disable max-lines */
2
9
  import { ccAPI, CCClasses, ccUtils, DataType, } from '@buerli.io/classcad';
3
10
  import { api, getDrawing, lineSegmentsFilter, loopFilter, MathUtils, planeFilter, pointFilter, } from '@buerli.io/core';
@@ -303,7 +310,7 @@ export default class CAD {
303
310
  dim.dimParam.dimTextAngle,
304
311
  dim.dimParam.dimOrientation,
305
312
  dim.dimParam.dimColor || 256,
306
- dim.dimParam.dimLayer || '2', // which layer makes sense as default?
313
+ dim.dimParam.dimLayer || '2',
307
314
  ],
308
315
  dim.dxfView,
309
316
  ];
@@ -330,7 +337,7 @@ export default class CAD {
330
337
  dim.dimParam.dimTextAngle,
331
338
  dim.dimParam.dimOrientation,
332
339
  dim.dimParam.dimColor || 256,
333
- dim.dimParam.dimLayer || '2', // which layer makes sense as default?
340
+ dim.dimParam.dimLayer || '2',
334
341
  ],
335
342
  dim.dxfView,
336
343
  ]);
@@ -583,90 +590,109 @@ export default class CAD {
583
590
  return null;
584
591
  }, partId, ...references);
585
592
  },
586
- createFastenedConstraint: (asmId, mate1, mate2, xOffset, yOffset, zOffset, name) => {
587
- return this.resolve(async ([rAsmId, rMate1, rMate2, rMatePath1, rMatePath2]) => {
588
- const constraintId = await ccAPI.assemblyBuilder.create3DConstraint(drawingId, rAsmId, CCClasses.CCFastenedConstraint, name);
589
- if (constraintId != null) {
590
- const xOffsetParam = { value: xOffset, isExpr: typeof xOffset === 'string' };
591
- const yOffsetParam = { value: yOffset, isExpr: typeof yOffset === 'string' };
592
- const zOffsetParam = { value: zOffset, isExpr: typeof zOffset === 'string' };
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);
596
- return constraintId;
597
- }
598
- return null;
599
- }, asmId, mate1, mate2, ...mate1.matePath, ...mate2.matePath);
600
- },
601
- updateFastenedConstraint: (constrId, mate1, mate2, xOffset, yOffset, zOffset) => {
602
- return this.resolve(async ([rConstrId, rMate1, rMate2, rMatePath1, rMatePath2]) => {
593
+ createFastenedConstraint: async (asmId, mate1, mate2, xOffset, yOffset, zOffset, name) => {
594
+ const [rAsmId, rWcs1, rWcs2] = await new Promise(res => this.resolve(ids => res(ids), asmId, mate1.wcsId, mate2.wcsId));
595
+ const rMatePath1 = await new Promise(res => this.resolve(paths => res(paths), ...mate1.matePath));
596
+ const rMatePath2 = await new Promise(res => this.resolve(paths => res(paths), ...mate2.matePath));
597
+ const constraintId = await ccAPI.assemblyBuilder.create3DConstraint(drawingId, rAsmId, CCClasses.CCFastenedConstraint, name);
598
+ if (constraintId != null) {
603
599
  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);
610
- },
611
- updateFastenedConstraints: (...constraints) => {
612
- return this.resolve(async ([...rConstraints]) => {
613
- const constrToAdd = [];
614
- rConstraints.forEach(constr => {
600
+ const yOffsetParam = { value: yOffset, isExpr: typeof yOffset === 'string' };
601
+ const zOffsetParam = { value: zOffset, isExpr: typeof zOffset === 'string' };
602
+ await ccAPI.assemblyBuilder.updateFastenedConstraint(drawingId, constraintId, [rMatePath1, rWcs1, mate1.flip, mate1.reoriented], [rMatePath2, rWcs2, mate2.flip, mate2.reoriented], xOffsetParam, yOffsetParam, zOffsetParam);
603
+ return constraintId;
604
+ }
605
+ return null;
606
+ },
607
+ updateFastenedConstraint: async (constrId, mate1, mate2, xOffset, yOffset, zOffset) => {
608
+ const [rConstrId, rWcs1, rWcs2] = await new Promise(res => this.resolve(ids => res(ids), constrId, mate1.wcsId, mate2.wcsId));
609
+ const rMatePath1 = await new Promise(res => this.resolve(paths => res(paths), ...mate1.matePath));
610
+ const rMatePath2 = await new Promise(res => this.resolve(paths => res(paths), ...mate2.matePath));
611
+ const xOffsetParam = { value: xOffset, isExpr: typeof xOffset === 'string' };
612
+ const yOffsetParam = { value: yOffset, isExpr: typeof xOffset === 'string' };
613
+ const zOffsetParam = { value: zOffset, isExpr: typeof xOffset === 'string' };
614
+ await ccAPI.assemblyBuilder.updateFastenedConstraint(drawingId, rConstrId, [rMatePath1, rWcs1, mate1.flip, mate1.reoriented], [rMatePath2, rWcs2, mate2.flip, mate2.reoriented], xOffsetParam, yOffsetParam, zOffsetParam);
615
+ },
616
+ updateFastenedConstraints: async (...constraints) => {
617
+ var e_1, _a;
618
+ const constrToAdd = [];
619
+ try {
620
+ for (var constraints_1 = __asyncValues(constraints), constraints_1_1; constraints_1_1 = await constraints_1.next(), !constraints_1_1.done;) {
621
+ const constr = constraints_1_1.value;
622
+ const [rConstrId, rWcs1, rWcs2] = await new Promise(res => this.resolve(ids => res(ids), constr.constrId, constr.mate1.wcsId, constr.mate2.wcsId));
623
+ const rMatePath1 = await new Promise(res => this.resolve(paths => res(paths), ...constr.mate1.matePath));
624
+ const rMatePath2 = await new Promise(res => this.resolve(paths => res(paths), ...constr.mate2.matePath));
615
625
  const xOffsetParam = [constr.xOffset, typeof constr.xOffset === 'string'];
616
626
  const yOffsetParam = [constr.yOffset, typeof constr.yOffset === 'string'];
617
627
  const zOffsetParam = [constr.zOffset, typeof constr.zOffset === 'string'];
618
628
  constrToAdd.push([
619
- constr.constrId,
620
- [constr.mate1.matePath, constr.mate1.wcsId, constr.mate1.flip, constr.mate1.reoriented],
621
- [constr.mate2.matePath, constr.mate2.wcsId, constr.mate2.flip, constr.mate2.reoriented],
629
+ rConstrId,
630
+ [rMatePath1, rWcs1, constr.mate1.flip, constr.mate1.reoriented],
631
+ [rMatePath2, rWcs2, constr.mate2.flip, constr.mate2.reoriented],
622
632
  xOffsetParam,
623
633
  yOffsetParam,
624
634
  zOffsetParam,
625
635
  ]);
626
- });
627
- await ccAPI.assemblyBuilder.updateFastenedConstraints(drawingId, constrToAdd);
628
- }, ...constraints);
629
- },
630
- createFastenedOriginConstraint: (asmId, mate1, xOffset, yOffset, zOffset, name) => {
631
- return this.resolve(async ([rAsmId, rMatePath, rMateWcsId]) => {
632
- const constraintId = await ccAPI.assemblyBuilder.create3DConstraint(drawingId, rAsmId, CCClasses.CCFastenedOriginConstraint, name);
633
- if (constraintId != null) {
634
- const xOffsetParam = { value: xOffset, isExpr: typeof xOffset === 'string' };
635
- const yOffsetParam = { value: yOffset, isExpr: typeof yOffset === 'string' };
636
- const zOffsetParam = { value: zOffset, isExpr: typeof zOffset === 'string' };
637
- rMatePath = Array.isArray(rMatePath) ? rMatePath : [rMatePath];
638
- await ccAPI.assemblyBuilder.updateFastenedOriginConstraint(drawingId, constraintId, [rMatePath, rMateWcsId, mate1.flip, mate1.reoriented], xOffsetParam, yOffsetParam, zOffsetParam);
639
- return constraintId;
640
636
  }
641
- return null;
642
- }, asmId, ...mate1.matePath, mate1.wcsId);
637
+ }
638
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
639
+ finally {
640
+ try {
641
+ if (constraints_1_1 && !constraints_1_1.done && (_a = constraints_1.return)) await _a.call(constraints_1);
642
+ }
643
+ finally { if (e_1) throw e_1.error; }
644
+ }
645
+ await ccAPI.assemblyBuilder.updateFastenedConstraints(drawingId, constrToAdd);
643
646
  },
644
- updateFastenedOriginConstraint: (constrId, mate1, xOffset, yOffset, zOffset) => {
645
- return this.resolve(async ([rConstrId, rMatePath, rMateWcsId]) => {
647
+ createFastenedOriginConstraint: async (asmId, mate1, xOffset, yOffset, zOffset, name) => {
648
+ const [rAsmId, rWcs1] = await new Promise(res => this.resolve(ids => res(ids), asmId, mate1.wcsId));
649
+ const rMatePath = await new Promise(res => this.resolve(paths => res(paths), ...mate1.matePath));
650
+ const constraintId = await ccAPI.assemblyBuilder.create3DConstraint(drawingId, rAsmId, CCClasses.CCFastenedOriginConstraint, name);
651
+ if (constraintId != null) {
646
652
  const xOffsetParam = { value: xOffset, isExpr: typeof xOffset === 'string' };
647
653
  const yOffsetParam = { value: yOffset, isExpr: typeof yOffset === 'string' };
648
654
  const zOffsetParam = { value: zOffset, isExpr: typeof zOffset === 'string' };
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);
652
- },
653
- updateFastenedOriginConstraints: (...constraints) => {
654
- return this.resolve(async ([...rConstraints]) => {
655
- const constrToAdd = [];
656
- rConstraints.forEach(constr => {
655
+ await ccAPI.assemblyBuilder.updateFastenedOriginConstraint(drawingId, constraintId, [rMatePath, rWcs1, mate1.flip, mate1.reoriented], xOffsetParam, yOffsetParam, zOffsetParam);
656
+ return constraintId;
657
+ }
658
+ return null;
659
+ },
660
+ updateFastenedOriginConstraint: async (constrId, mate1, xOffset, yOffset, zOffset) => {
661
+ const [rConstrId, rWcs1] = await new Promise(res => this.resolve(ids => res(ids), constrId, mate1.wcsId));
662
+ const rMatePath = await new Promise(res => this.resolve(paths => res(paths), ...mate1.matePath));
663
+ const xOffsetParam = { value: xOffset, isExpr: typeof xOffset === 'string' };
664
+ const yOffsetParam = { value: yOffset, isExpr: typeof yOffset === 'string' };
665
+ const zOffsetParam = { value: zOffset, isExpr: typeof zOffset === 'string' };
666
+ await ccAPI.assemblyBuilder.updateFastenedOriginConstraint(drawingId, rConstrId, [rMatePath, rWcs1, mate1.flip, mate1.reoriented], xOffsetParam, yOffsetParam, zOffsetParam);
667
+ },
668
+ updateFastenedOriginConstraints: async (...constraints) => {
669
+ var e_2, _a;
670
+ const constrToAdd = [];
671
+ try {
672
+ for (var constraints_2 = __asyncValues(constraints), constraints_2_1; constraints_2_1 = await constraints_2.next(), !constraints_2_1.done;) {
673
+ const constr = constraints_2_1.value;
674
+ const [rConstrId, rWcs1] = await new Promise(res => this.resolve(ids => res(ids), constr.constrId, constr.mate1.wcsId));
675
+ const rMatePath = await new Promise(res => this.resolve(paths => res(paths), ...constr.mate1.matePath));
657
676
  const xOffsetParam = [constr.xOffset, typeof constr.xOffset === 'string'];
658
677
  const yOffsetParam = [constr.yOffset, typeof constr.yOffset === 'string'];
659
678
  const zOffsetParam = [constr.zOffset, typeof constr.zOffset === 'string'];
660
679
  constrToAdd.push([
661
- constr.constrId,
662
- [constr.mate1.matePath, constr.mate1.wcsId, constr.mate1.flip, constr.mate1.reoriented],
680
+ rConstrId,
681
+ [rMatePath, rWcs1, constr.mate1.flip, constr.mate1.reoriented],
663
682
  xOffsetParam,
664
683
  yOffsetParam,
665
684
  zOffsetParam,
666
685
  ]);
667
- });
668
- await ccAPI.assemblyBuilder.updateFastenedOriginConstraints(drawingId, constrToAdd);
669
- }, ...constraints);
686
+ }
687
+ }
688
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
689
+ finally {
690
+ try {
691
+ if (constraints_2_1 && !constraints_2_1.done && (_a = constraints_2.return)) await _a.call(constraints_2);
692
+ }
693
+ finally { if (e_2) throw e_2.error; }
694
+ }
695
+ await ccAPI.assemblyBuilder.updateFastenedOriginConstraints(drawingId, constrToAdd);
670
696
  },
671
697
  createBufferGeometry: async (objectId) => {
672
698
  await this.queue;
@@ -693,7 +719,12 @@ export default class CAD {
693
719
  const scene = new Scene();
694
720
  if (rObjectId != null) {
695
721
  const rootObj = structureTree[rObjectId];
696
- await createRecursiveScene(rootObj, drawingId, scene, options);
722
+ if (rootObj) {
723
+ await createRecursiveScene(rootObj, drawingId, scene, options);
724
+ }
725
+ else {
726
+ throw new Error('Root object does not exist!');
727
+ }
697
728
  }
698
729
  return scene;
699
730
  },
@@ -984,7 +1015,7 @@ export default class CAD {
984
1015
  const featureName = name ? name : 'Import';
985
1016
  const importFeatureId = await featureAPI.createFeature(drawingId, rPartId, CCClasses.CCImport, featureName);
986
1017
  if (importFeatureId !== null) {
987
- const solids = await featureAPI.loadGeometryStreamToImportFeature(drawingId, importFeatureId, content, format);
1018
+ const solids = await featureAPI.updateImport(drawingId, importFeatureId, content, format, featureName);
988
1019
  if (solids !== null) {
989
1020
  return importFeatureId;
990
1021
  }
@@ -996,6 +1027,7 @@ export default class CAD {
996
1027
  return this.resolve(async ([rPartId, rPlaneId]) => {
997
1028
  const sketch = await sketcherAPI.createSketch(drawingId, rPartId);
998
1029
  if (sketch) {
1030
+ await featureAPI.closeFeature(drawingId, sketch);
999
1031
  const tree = getDrawing(drawingId).structure.tree;
1000
1032
  const plane = tree[rPlaneId];
1001
1033
  if (plane && base.isA(plane.class, CCClasses.CCWorkPlane)) {
@@ -1013,6 +1045,7 @@ export default class CAD {
1013
1045
  return this.resolve(async ([rPartId, rPlaneId, rSketchId]) => {
1014
1046
  const sketch = await sketcherAPI.createSketch(drawingId, rPartId);
1015
1047
  if (sketch) {
1048
+ await featureAPI.closeFeature(drawingId, sketch);
1016
1049
  const tree = getDrawing(drawingId).structure.tree;
1017
1050
  const plane = tree[rPlaneId];
1018
1051
  if (plane && base.isA(plane.class, CCClasses.CCWorkPlane)) {
package/build/solid.js CHANGED
@@ -182,7 +182,9 @@ export default class CAD {
182
182
  this.queue = Promise.resolve(0);
183
183
  }
184
184
  resolve(callback, ...args) {
185
- return (this.queue = this.queue.then(() => Promise.all(args).then(callback)).catch(e => {
185
+ return (this.queue = this.queue
186
+ .then(() => Promise.all(args).then(callback))
187
+ .catch(e => {
186
188
  // catch is necessary to avoid error promises in the queue
187
189
  }));
188
190
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buerli.io/headless",
3
- "version": "0.3.0-beta.1",
3
+ "version": "0.4.0-beta.2",
4
4
  "description": "A non-manifold CAD workflow for the web",
5
5
  "author": "AWV Informatik AG <info@awv-informatik.ch>",
6
6
  "license": "ISC",
@@ -12,8 +12,8 @@
12
12
  "scripts": {
13
13
  "ver": "npm version",
14
14
  "prepack": "npm run clean && npm run build",
15
- "clean": "rimraf ./build",
16
- "build": "tsc",
15
+ "clean": "rimraf ./build && rimraf ./tsconfig.tsbuildinfo",
16
+ "build": "tsc -v && tsc",
17
17
  "build:dev": "tsc --sourceMap true --declarationMap true",
18
18
  "test": "echo no tests yet",
19
19
  "lint": "eslint \"./src/**/*.ts?(x)\"",
@@ -23,13 +23,14 @@
23
23
  "@types/three": "^0.137",
24
24
  "copyfiles": "^2.1.1",
25
25
  "rimraf": "^2.6.3",
26
- "three": "^0.138"
26
+ "three": "^0.138",
27
+ "typescript": "4.1.2"
27
28
  },
28
29
  "peerDependencies": {
29
30
  "three": ">=0.138"
30
31
  },
31
32
  "dependencies": {
32
- "@buerli.io/classcad": "0.3.0-beta.1",
33
+ "@buerli.io/classcad": "0.4.0-beta.2",
33
34
  "flat-promise": "^1.0.3"
34
35
  }
35
36
  }