@buerli.io/headless 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __asyncValues = (this && this.__asyncValues) || function (o) {
26
3
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
27
4
  var m = o[Symbol.asyncIterator], i;
@@ -34,7 +11,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
34
11
  const classcad_1 = require("@buerli.io/classcad");
35
12
  const core_1 = require("@buerli.io/core");
36
13
  const three_1 = require("three");
37
- const BufferGeometryUtils_ = __importStar(require("three/examples/jsm/utils/BufferGeometryUtils"));
14
+ const three_stdlib_1 = require("three-stdlib");
38
15
  const selection_1 = require("./utils/selection");
39
16
  const meshes_1 = require("./utils/meshes");
40
17
  const featureAPI = classcad_1.ccAPI.feature;
@@ -46,10 +23,6 @@ const geometryAPI = classcad_1.ccAPI.geometry;
46
23
  const baseUtils = classcad_1.ccUtils.base;
47
24
  const asmUtils = classcad_1.ccUtils.assembly;
48
25
  const partUtils = classcad_1.ccUtils.part;
49
- let BufferGeometryUtils = BufferGeometryUtils_;
50
- if (BufferGeometryUtils.BufferGeometryUtils) {
51
- BufferGeometryUtils = BufferGeometryUtils.BufferGeometryUtils;
52
- }
53
26
  const resolveVec = (value) => {
54
27
  if (Array.isArray(value))
55
28
  return { x: value[0], y: value[1], z: value[2] };
@@ -104,7 +77,7 @@ const createRecursiveBufferGeometry = async (object, drawingId, bufferGeomArray)
104
77
  }
105
78
  if (geometries.length > 0) {
106
79
  const transformation = cDrawing.api.structure.calculateGlobalTransformation(object.id);
107
- const bufferGeom = BufferGeometryUtils.mergeBufferGeometries(geometries);
80
+ const bufferGeom = (0, three_stdlib_1.mergeBufferGeometries)(geometries);
108
81
  bufferGeom.applyMatrix4(transformation);
109
82
  bufferGeomArray.push(bufferGeom);
110
83
  }
@@ -190,7 +163,7 @@ const createRecursiveScene = async (object, drawingId, root, result, options) =>
190
163
  mesh.name = solidObject.name + '_' + i;
191
164
  mesh.userData = { id: solidObject.id }; // add solid id to the userData
192
165
  if (!(options === null || options === void 0 ? void 0 : options.structureOnly)) {
193
- mesh.geometry = (BufferGeometryUtils.mergeBufferGeometries || BufferGeometryUtils.mergeGeometries)(colorMeshesMap[key].meshes.map(m => m.geometry));
166
+ mesh.geometry = (0, three_stdlib_1.mergeBufferGeometries)(colorMeshesMap[key].meshes.map(m => m.geometry));
194
167
  mesh.material = new three_1.MeshStandardMaterial({
195
168
  color: colorMeshesMap[key].color,
196
169
  transparent: colorMeshesMap[key].opacity < 1,
@@ -212,7 +185,7 @@ const createRecursiveScene = async (object, drawingId, root, result, options) =>
212
185
  mesh.name = solidObject.name;
213
186
  mesh.userData = { id: solidObject.id }; // add solid id to the userData
214
187
  if (!(options === null || options === void 0 ? void 0 : options.structureOnly)) {
215
- mesh.geometry = (BufferGeometryUtils.mergeBufferGeometries || BufferGeometryUtils.mergeGeometries)(colorMeshesMap[key].meshes.map(m => m.geometry));
188
+ mesh.geometry = (0, three_stdlib_1.mergeBufferGeometries)(colorMeshesMap[key].meshes.map(m => m.geometry));
216
189
  mesh.material = new three_1.MeshStandardMaterial({
217
190
  color: colorMeshesMap[key].color,
218
191
  transparent: colorMeshesMap[key].opacity < 1,
@@ -249,29 +222,6 @@ const createRecursiveScene = async (object, drawingId, root, result, options) =>
249
222
  }
250
223
  }
251
224
  };
252
- /**
253
- * Helper function to log relevant points to find geometry to the console.
254
- * This helps the user to copy the points directly from console to parameter of
255
- * findOrSelect() method.
256
- * @param points Array of points array to log to the console
257
- */
258
- const logPoints = (points) => {
259
- let log = 'Relevant points of selected gometry = [[';
260
- if (points && points.length > 0) {
261
- for (let i = 0; i < points.length; i++) {
262
- for (let j = 0; j < points[i].length; j++) {
263
- const point = resolveVec(points[i][j]);
264
- const x = Math.round(point.x * 1000) / 1000;
265
- const y = Math.round(point.y * 1000) / 1000;
266
- const z = Math.round(point.z * 1000) / 1000;
267
- log += '{ x: ' + x + ', y: ' + y + ', z: ' + z + '}';
268
- log += points[i].length - 1 === j ? '' : ',';
269
- }
270
- log += points.length - 1 === i ? ']]' : '],[';
271
- }
272
- console.info(log);
273
- }
274
- };
275
225
  class CAD {
276
226
  constructor() {
277
227
  this.drawingId = null;
@@ -1179,10 +1129,10 @@ class CAD {
1179
1129
  return null;
1180
1130
  }, partId, ...references);
1181
1131
  },
1182
- createWorkCoordSystem: (partId, type, references, coordinateSystem, offset, rotation, inverted = false, local = false, name) => {
1132
+ createWorkCoordSystem: (partId, type, references, offset, rotation, inverted = false, name) => {
1183
1133
  return this.resolve(async ([rPartId, ...rReferences]) => {
1184
1134
  const wCSName = name ? name : 'WorkCoordSystem';
1185
- const wCSId = await featureAPI.createWorkGeometry(drawingId, rPartId, classcad_1.CCClasses.CCWorkCoordSystem, wCSName);
1135
+ const wCSId = await featureAPI.createWorkGeometry(drawingId, rPartId, classcad_1.CCClasses.CCWorkCSys, wCSName);
1186
1136
  if (wCSId != null) {
1187
1137
  const offsetParam = {
1188
1138
  value: resolveVec(offset),
@@ -1192,7 +1142,7 @@ class CAD {
1192
1142
  value: resolveVec(rotation),
1193
1143
  isExpr: typeof rotation === 'string',
1194
1144
  };
1195
- await featureAPI.updateWorkCoordSystem(drawingId, wCSId, type, rReferences, coordinateSystem.map(resolveVec), offsetParam, rotationParam, inverted ? 1 : 0, local);
1145
+ await featureAPI.updateWorkCSys(drawingId, wCSId, type, rReferences, offsetParam, rotationParam, inverted ? 1 : 0);
1196
1146
  return wCSId;
1197
1147
  }
1198
1148
  return null;
@@ -1245,36 +1195,37 @@ class CAD {
1245
1195
  return null;
1246
1196
  }, partId, references);
1247
1197
  },
1248
- findOrSelect: (partId, type, length, positions) => {
1249
- return this.resolve(async ([rPartId]) => {
1250
- let filter = core_1.lineSegmentsFilter;
1251
- switch (type) {
1252
- case 0: // Vertex
1253
- filter = core_1.pointFilter;
1254
- break;
1255
- case 1: // Edge
1256
- filter = core_1.lineSegmentsFilter;
1257
- break;
1258
- case 2: // Loop
1259
- filter = core_1.loopFilter;
1260
- break;
1261
- case 3: // Face
1262
- filter = core_1.planeFilter;
1263
- break;
1264
- }
1265
- const geometries = positions
1266
- ? await geometryAPI.findGeometriesByPoints(drawingId, rPartId, type, positions.map(p => p.map(resolveVec)))
1267
- : await (0, selection_1.waitForSelect)(length, filter, (resolveSelection, items, diff) => {
1268
- if (items.length > length - 1) {
1269
- resolveSelection(items.map(i => i.data.graphicId));
1270
- geometryAPI
1271
- .getPointsByGeometries(drawingId, items.map(i => i.data.graphicId))
1272
- .then(points => {
1273
- logPoints(points);
1274
- });
1275
- }
1198
+ selectGeometry: (types, count) => {
1199
+ return this.resolve(async ([]) => {
1200
+ const filter = (scope, data) => scope === core_1.BuerliScope && types.some(type => type === data);
1201
+ // Check count param. If not set use by default 1, else check if not < 1
1202
+ const lCount = count ? (count < 1 ? 1 : count) : 1;
1203
+ const selections = await (0, selection_1.waitForSelect)(lCount, filter, (resolveSelection, items, diff) => {
1204
+ if (items.length > lCount - 1) {
1205
+ resolveSelection(items);
1206
+ }
1207
+ });
1208
+ const interactionInfos = [];
1209
+ for (const selection of selections) {
1210
+ // Get matching points from selected geometry and add to userData. TODO: Only if in part mode useful?
1211
+ const points = await geometryAPI.getPointsByGeometries(drawingId, [selection.data.graphicId]);
1212
+ const interactionInfo = (0, core_1.createInfo)({
1213
+ objectId: selection.data.container.ownerId,
1214
+ prodRefId: selection.data.productId,
1215
+ containerId: selection.data.container.id,
1216
+ graphicId: selection.data.graphicId,
1217
+ // objectPath: ?, TODO: Add path to the root in expanded tree, as soon as available
1218
+ userData: Object.assign(Object.assign({}, selection.data), { matchingPoints: points }),
1276
1219
  });
1277
- return geometries;
1220
+ interactionInfos.push(interactionInfo);
1221
+ }
1222
+ return interactionInfos;
1223
+ });
1224
+ },
1225
+ findGeometry: (partId, type, positions) => {
1226
+ return this.resolve(async ([rPartId]) => {
1227
+ const geoms = await geometryAPI.findGeometriesByPoints(drawingId, rPartId, type, positions.map(p => p.map(resolveVec)));
1228
+ return geoms;
1278
1229
  }, partId);
1279
1230
  },
1280
1231
  getAssemblyFromContainer: (asmName) => {
@@ -1573,10 +1524,29 @@ class CAD {
1573
1524
  await sketcherAPI.setSketchRefs(drawingId, rSketchId, rPlaneId, invertPlane, rAxisId, isXAxis, invertAxis, rOriginId);
1574
1525
  }, sketchId, planeId, axisId, originId);
1575
1526
  },
1576
- transformNode: (referenceId, ownerId, transformation) => {
1577
- return this.resolve(async ([rRefId, rOwnerId]) => {
1578
- await assemblyBuilderAPI.setNodeTransformation(drawingId, rRefId, rOwnerId, transformation);
1579
- }, referenceId, ownerId);
1527
+ transformNodes: async (...nodes) => {
1528
+ var e_11, _a;
1529
+ const nodesToTransform = [];
1530
+ try {
1531
+ for (var nodes_2 = __asyncValues(nodes), nodes_2_1; nodes_2_1 = await nodes_2.next(), !nodes_2_1.done;) {
1532
+ const node = nodes_2_1.value;
1533
+ const [rReferenceId] = await new Promise(res => this.resolve(id => res(id), node.referenceId));
1534
+ const nodeParam = {
1535
+ referenceId: rReferenceId,
1536
+ transformation: node.transformation,
1537
+ options: { isLocal: true }, // in non-interactive mode, the transformation is local to the owner
1538
+ };
1539
+ nodesToTransform.push(nodeParam);
1540
+ }
1541
+ }
1542
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
1543
+ finally {
1544
+ try {
1545
+ if (nodes_2_1 && !nodes_2_1.done && (_a = nodes_2.return)) await _a.call(nodes_2);
1546
+ }
1547
+ finally { if (e_11) throw e_11.error; }
1548
+ }
1549
+ return assemblyBuilderAPI.transformNodes(drawingId, nodesToTransform);
1580
1550
  },
1581
1551
  translate: (partId, featureIds, references, inverted, distance) => {
1582
1552
  return this.resolve(async ([rPartId, rFeatureIds, ...rReferences]) => {
@@ -1634,6 +1604,7 @@ class CAD {
1634
1604
  },
1635
1605
  pick: (partId, type, points) => {
1636
1606
  return this.resolve(async ([rPartId]) => {
1607
+ console.warn('Warning: pick() is deprecated, use findGeometry() instead, pick() will be removed in a future release.');
1637
1608
  const refs = await featureAPI.pick(drawingId, rPartId, type, points.map(resolveVec));
1638
1609
  if (refs != undefined) {
1639
1610
  return Array.isArray(refs) ? refs : [refs];
@@ -1737,6 +1708,50 @@ class CAD {
1737
1708
  return asmUtils.getMatePath(drawingId, rRefId);
1738
1709
  }, refId);
1739
1710
  },
1711
+ slice: async (partId, operations, reference, sideFlag) => {
1712
+ const [rPartId] = await new Promise(res => this.resolve(ids => res(ids), partId));
1713
+ const rOperations = await new Promise(res => this.resolve(ids => res(ids), ...operations));
1714
+ const [rReference] = await new Promise(res => this.resolve(paths => res(paths), reference));
1715
+ const cDrawing = (0, core_1.getDrawing)(drawingId);
1716
+ const entArray = [];
1717
+ for (const rOperation of rOperations) {
1718
+ const entities = cDrawing.structure.tree[rOperation].children;
1719
+ if (entities != undefined && entities.length > 0) {
1720
+ entArray.push(entities[0]); // use first entity of operation
1721
+ }
1722
+ }
1723
+ const sliceId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCSlice, 'Slice');
1724
+ if (sliceId != null) {
1725
+ await featureAPI.openFeature(drawingId, sliceId);
1726
+ if (entArray.length > 0) {
1727
+ await featureAPI.updateSlice(drawingId, sliceId, entArray, rReference, sideFlag ? 1 : 0);
1728
+ await featureAPI.closeFeature(drawingId, sliceId);
1729
+ return sliceId;
1730
+ }
1731
+ await featureAPI.closeFeature(drawingId, sliceId);
1732
+ await baseModelerAPI.deleteObjects(drawingId, [sliceId]);
1733
+ }
1734
+ return null;
1735
+ },
1736
+ sliceBySheet: async (partId, operationToSlice, operationOfSheet, sideFlag) => {
1737
+ const [rPartId] = await new Promise(res => this.resolve(ids => res(ids), partId));
1738
+ const [rOperationToSlice] = await new Promise(res => this.resolve(ids => res(ids), operationToSlice));
1739
+ const [rOperationOfSheet] = await new Promise(res => this.resolve(ids => res(ids), operationOfSheet));
1740
+ const entityToSlice = (0, core_1.getDrawing)(drawingId).structure.tree[rOperationToSlice].children;
1741
+ const entityOfSheet = (0, core_1.getDrawing)(drawingId).structure.tree[rOperationOfSheet].children;
1742
+ const sliceBySheetId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCSliceBySheet, 'SliceBySheet');
1743
+ if (sliceBySheetId != null) {
1744
+ await featureAPI.openFeature(drawingId, sliceBySheetId);
1745
+ if (entityToSlice && entityToSlice.length > 0 && entityOfSheet && entityOfSheet.length > 0) {
1746
+ await featureAPI.updateSliceBySheet(drawingId, sliceBySheetId, entityToSlice[0], entityOfSheet[0], sideFlag ? 1 : 0);
1747
+ await featureAPI.closeFeature(drawingId, sliceBySheetId);
1748
+ return sliceBySheetId;
1749
+ }
1750
+ await featureAPI.closeFeature(drawingId, sliceBySheetId);
1751
+ await baseModelerAPI.deleteObjects(drawingId, [sliceBySheetId]);
1752
+ }
1753
+ return null;
1754
+ },
1740
1755
  };
1741
1756
  callback(publicApi);
1742
1757
  resolve(drawingId);
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __asyncValues = (this && this.__asyncValues) || function (o) {
26
3
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
27
4
  var m = o[Symbol.asyncIterator], i;
@@ -35,13 +12,9 @@ exports.createPolyline = void 0;
35
12
  const classcad_1 = require("@buerli.io/classcad");
36
13
  const core_1 = require("@buerli.io/core");
37
14
  const three_1 = require("three");
38
- const BufferGeometryUtils_ = __importStar(require("three/examples/jsm/utils/BufferGeometryUtils"));
15
+ const three_stdlib_1 = require("three-stdlib");
39
16
  const meshes_1 = require("./utils/meshes");
40
17
  const solidAPI = classcad_1.ccAPI.solid;
41
- let BufferGeometryUtils = BufferGeometryUtils_;
42
- if (BufferGeometryUtils.BufferGeometryUtils) {
43
- BufferGeometryUtils = BufferGeometryUtils.BufferGeometryUtils;
44
- }
45
18
  const toCCVec = (args) => ({ x: args[0], y: args[1], z: args[2] });
46
19
  const toCCNbrVec = (args) => ({ x: args[0], y: args[1], z: args[2] });
47
20
  const toArray = (v) => (Array.isArray(v) ? v : v.toArray());
@@ -263,7 +236,7 @@ class CAD {
263
236
  await classcad_1.ccAPI.baseModeler.requestVisualisationOfObject(drawingId, rSolid);
264
237
  const entity = await getEntity(drawingId, rSolid);
265
238
  if (entity != null) {
266
- return BufferGeometryUtils.mergeBufferGeometries(entity.meshes.map(m => m.geometry));
239
+ return (0, three_stdlib_1.mergeBufferGeometries)(entity.meshes.map(m => m.geometry));
267
240
  }
268
241
  },
269
242
  createScene: async (solids, options) => {
@@ -310,7 +283,7 @@ class CAD {
310
283
  const colorMeshesMap = (0, meshes_1.getDifferentColoredMeshesFromEntity)(entity);
311
284
  Object.keys(colorMeshesMap).forEach(key => {
312
285
  const mesh = new three_1.Mesh();
313
- mesh.geometry = BufferGeometryUtils.mergeBufferGeometries(colorMeshesMap[key].meshes.map(m => m.geometry));
286
+ mesh.geometry = (0, three_stdlib_1.mergeBufferGeometries)(colorMeshesMap[key].meshes.map(m => m.geometry));
314
287
  mesh.material = new three_1.MeshStandardMaterial({
315
288
  color: colorMeshesMap[key].color,
316
289
  transparent: colorMeshesMap[key].opacity < 1,
@@ -7,9 +7,9 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
7
7
  };
8
8
  /* eslint-disable max-lines */
9
9
  import { ccAPI, CCClasses, ccUtils, DataType, SVGModusType, } from '@buerli.io/classcad';
10
- import { api, getDrawing, lineSegmentsFilter, loopFilter, MathUtils, planeFilter, pointFilter, } from '@buerli.io/core';
10
+ import { api, getDrawing, MathUtils, BuerliScope, createInfo, } from '@buerli.io/core';
11
11
  import { Group, Matrix4, Mesh, MeshStandardMaterial, Scene } from 'three';
12
- import * as BufferGeometryUtils_ from 'three/examples/jsm/utils/BufferGeometryUtils';
12
+ import { mergeBufferGeometries } from 'three-stdlib';
13
13
  import { waitForSelect } from './utils/selection';
14
14
  import { getDifferentColoredMeshesFromEntity } from './utils/meshes';
15
15
  const featureAPI = ccAPI.feature;
@@ -21,10 +21,6 @@ const geometryAPI = ccAPI.geometry;
21
21
  const baseUtils = ccUtils.base;
22
22
  const asmUtils = ccUtils.assembly;
23
23
  const partUtils = ccUtils.part;
24
- let BufferGeometryUtils = BufferGeometryUtils_;
25
- if (BufferGeometryUtils.BufferGeometryUtils) {
26
- BufferGeometryUtils = BufferGeometryUtils.BufferGeometryUtils;
27
- }
28
24
  const resolveVec = (value) => {
29
25
  if (Array.isArray(value))
30
26
  return { x: value[0], y: value[1], z: value[2] };
@@ -79,7 +75,7 @@ const createRecursiveBufferGeometry = async (object, drawingId, bufferGeomArray)
79
75
  }
80
76
  if (geometries.length > 0) {
81
77
  const transformation = cDrawing.api.structure.calculateGlobalTransformation(object.id);
82
- const bufferGeom = BufferGeometryUtils.mergeBufferGeometries(geometries);
78
+ const bufferGeom = mergeBufferGeometries(geometries);
83
79
  bufferGeom.applyMatrix4(transformation);
84
80
  bufferGeomArray.push(bufferGeom);
85
81
  }
@@ -165,7 +161,7 @@ const createRecursiveScene = async (object, drawingId, root, result, options) =>
165
161
  mesh.name = solidObject.name + '_' + i;
166
162
  mesh.userData = { id: solidObject.id }; // add solid id to the userData
167
163
  if (!(options === null || options === void 0 ? void 0 : options.structureOnly)) {
168
- mesh.geometry = (BufferGeometryUtils.mergeBufferGeometries || BufferGeometryUtils.mergeGeometries)(colorMeshesMap[key].meshes.map(m => m.geometry));
164
+ mesh.geometry = mergeBufferGeometries(colorMeshesMap[key].meshes.map(m => m.geometry));
169
165
  mesh.material = new MeshStandardMaterial({
170
166
  color: colorMeshesMap[key].color,
171
167
  transparent: colorMeshesMap[key].opacity < 1,
@@ -187,7 +183,7 @@ const createRecursiveScene = async (object, drawingId, root, result, options) =>
187
183
  mesh.name = solidObject.name;
188
184
  mesh.userData = { id: solidObject.id }; // add solid id to the userData
189
185
  if (!(options === null || options === void 0 ? void 0 : options.structureOnly)) {
190
- mesh.geometry = (BufferGeometryUtils.mergeBufferGeometries || BufferGeometryUtils.mergeGeometries)(colorMeshesMap[key].meshes.map(m => m.geometry));
186
+ mesh.geometry = mergeBufferGeometries(colorMeshesMap[key].meshes.map(m => m.geometry));
191
187
  mesh.material = new MeshStandardMaterial({
192
188
  color: colorMeshesMap[key].color,
193
189
  transparent: colorMeshesMap[key].opacity < 1,
@@ -224,29 +220,6 @@ const createRecursiveScene = async (object, drawingId, root, result, options) =>
224
220
  }
225
221
  }
226
222
  };
227
- /**
228
- * Helper function to log relevant points to find geometry to the console.
229
- * This helps the user to copy the points directly from console to parameter of
230
- * findOrSelect() method.
231
- * @param points Array of points array to log to the console
232
- */
233
- const logPoints = (points) => {
234
- let log = 'Relevant points of selected gometry = [[';
235
- if (points && points.length > 0) {
236
- for (let i = 0; i < points.length; i++) {
237
- for (let j = 0; j < points[i].length; j++) {
238
- const point = resolveVec(points[i][j]);
239
- const x = Math.round(point.x * 1000) / 1000;
240
- const y = Math.round(point.y * 1000) / 1000;
241
- const z = Math.round(point.z * 1000) / 1000;
242
- log += '{ x: ' + x + ', y: ' + y + ', z: ' + z + '}';
243
- log += points[i].length - 1 === j ? '' : ',';
244
- }
245
- log += points.length - 1 === i ? ']]' : '],[';
246
- }
247
- console.info(log);
248
- }
249
- };
250
223
  export default class CAD {
251
224
  constructor() {
252
225
  this.drawingId = null;
@@ -1154,10 +1127,10 @@ export default class CAD {
1154
1127
  return null;
1155
1128
  }, partId, ...references);
1156
1129
  },
1157
- createWorkCoordSystem: (partId, type, references, coordinateSystem, offset, rotation, inverted = false, local = false, name) => {
1130
+ createWorkCoordSystem: (partId, type, references, offset, rotation, inverted = false, name) => {
1158
1131
  return this.resolve(async ([rPartId, ...rReferences]) => {
1159
1132
  const wCSName = name ? name : 'WorkCoordSystem';
1160
- const wCSId = await featureAPI.createWorkGeometry(drawingId, rPartId, CCClasses.CCWorkCoordSystem, wCSName);
1133
+ const wCSId = await featureAPI.createWorkGeometry(drawingId, rPartId, CCClasses.CCWorkCSys, wCSName);
1161
1134
  if (wCSId != null) {
1162
1135
  const offsetParam = {
1163
1136
  value: resolveVec(offset),
@@ -1167,7 +1140,7 @@ export default class CAD {
1167
1140
  value: resolveVec(rotation),
1168
1141
  isExpr: typeof rotation === 'string',
1169
1142
  };
1170
- await featureAPI.updateWorkCoordSystem(drawingId, wCSId, type, rReferences, coordinateSystem.map(resolveVec), offsetParam, rotationParam, inverted ? 1 : 0, local);
1143
+ await featureAPI.updateWorkCSys(drawingId, wCSId, type, rReferences, offsetParam, rotationParam, inverted ? 1 : 0);
1171
1144
  return wCSId;
1172
1145
  }
1173
1146
  return null;
@@ -1220,36 +1193,37 @@ export default class CAD {
1220
1193
  return null;
1221
1194
  }, partId, references);
1222
1195
  },
1223
- findOrSelect: (partId, type, length, positions) => {
1224
- return this.resolve(async ([rPartId]) => {
1225
- let filter = lineSegmentsFilter;
1226
- switch (type) {
1227
- case 0: // Vertex
1228
- filter = pointFilter;
1229
- break;
1230
- case 1: // Edge
1231
- filter = lineSegmentsFilter;
1232
- break;
1233
- case 2: // Loop
1234
- filter = loopFilter;
1235
- break;
1236
- case 3: // Face
1237
- filter = planeFilter;
1238
- break;
1239
- }
1240
- const geometries = positions
1241
- ? await geometryAPI.findGeometriesByPoints(drawingId, rPartId, type, positions.map(p => p.map(resolveVec)))
1242
- : await waitForSelect(length, filter, (resolveSelection, items, diff) => {
1243
- if (items.length > length - 1) {
1244
- resolveSelection(items.map(i => i.data.graphicId));
1245
- geometryAPI
1246
- .getPointsByGeometries(drawingId, items.map(i => i.data.graphicId))
1247
- .then(points => {
1248
- logPoints(points);
1249
- });
1250
- }
1196
+ selectGeometry: (types, count) => {
1197
+ return this.resolve(async ([]) => {
1198
+ const filter = (scope, data) => scope === BuerliScope && types.some(type => type === data);
1199
+ // Check count param. If not set use by default 1, else check if not < 1
1200
+ const lCount = count ? (count < 1 ? 1 : count) : 1;
1201
+ const selections = await waitForSelect(lCount, filter, (resolveSelection, items, diff) => {
1202
+ if (items.length > lCount - 1) {
1203
+ resolveSelection(items);
1204
+ }
1205
+ });
1206
+ const interactionInfos = [];
1207
+ for (const selection of selections) {
1208
+ // Get matching points from selected geometry and add to userData. TODO: Only if in part mode useful?
1209
+ const points = await geometryAPI.getPointsByGeometries(drawingId, [selection.data.graphicId]);
1210
+ const interactionInfo = createInfo({
1211
+ objectId: selection.data.container.ownerId,
1212
+ prodRefId: selection.data.productId,
1213
+ containerId: selection.data.container.id,
1214
+ graphicId: selection.data.graphicId,
1215
+ // objectPath: ?, TODO: Add path to the root in expanded tree, as soon as available
1216
+ userData: Object.assign(Object.assign({}, selection.data), { matchingPoints: points }),
1251
1217
  });
1252
- return geometries;
1218
+ interactionInfos.push(interactionInfo);
1219
+ }
1220
+ return interactionInfos;
1221
+ });
1222
+ },
1223
+ findGeometry: (partId, type, positions) => {
1224
+ return this.resolve(async ([rPartId]) => {
1225
+ const geoms = await geometryAPI.findGeometriesByPoints(drawingId, rPartId, type, positions.map(p => p.map(resolveVec)));
1226
+ return geoms;
1253
1227
  }, partId);
1254
1228
  },
1255
1229
  getAssemblyFromContainer: (asmName) => {
@@ -1548,10 +1522,29 @@ export default class CAD {
1548
1522
  await sketcherAPI.setSketchRefs(drawingId, rSketchId, rPlaneId, invertPlane, rAxisId, isXAxis, invertAxis, rOriginId);
1549
1523
  }, sketchId, planeId, axisId, originId);
1550
1524
  },
1551
- transformNode: (referenceId, ownerId, transformation) => {
1552
- return this.resolve(async ([rRefId, rOwnerId]) => {
1553
- await assemblyBuilderAPI.setNodeTransformation(drawingId, rRefId, rOwnerId, transformation);
1554
- }, referenceId, ownerId);
1525
+ transformNodes: async (...nodes) => {
1526
+ var e_11, _a;
1527
+ const nodesToTransform = [];
1528
+ try {
1529
+ for (var nodes_2 = __asyncValues(nodes), nodes_2_1; nodes_2_1 = await nodes_2.next(), !nodes_2_1.done;) {
1530
+ const node = nodes_2_1.value;
1531
+ const [rReferenceId] = await new Promise(res => this.resolve(id => res(id), node.referenceId));
1532
+ const nodeParam = {
1533
+ referenceId: rReferenceId,
1534
+ transformation: node.transformation,
1535
+ options: { isLocal: true }, // in non-interactive mode, the transformation is local to the owner
1536
+ };
1537
+ nodesToTransform.push(nodeParam);
1538
+ }
1539
+ }
1540
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
1541
+ finally {
1542
+ try {
1543
+ if (nodes_2_1 && !nodes_2_1.done && (_a = nodes_2.return)) await _a.call(nodes_2);
1544
+ }
1545
+ finally { if (e_11) throw e_11.error; }
1546
+ }
1547
+ return assemblyBuilderAPI.transformNodes(drawingId, nodesToTransform);
1555
1548
  },
1556
1549
  translate: (partId, featureIds, references, inverted, distance) => {
1557
1550
  return this.resolve(async ([rPartId, rFeatureIds, ...rReferences]) => {
@@ -1609,6 +1602,7 @@ export default class CAD {
1609
1602
  },
1610
1603
  pick: (partId, type, points) => {
1611
1604
  return this.resolve(async ([rPartId]) => {
1605
+ console.warn('Warning: pick() is deprecated, use findGeometry() instead, pick() will be removed in a future release.');
1612
1606
  const refs = await featureAPI.pick(drawingId, rPartId, type, points.map(resolveVec));
1613
1607
  if (refs != undefined) {
1614
1608
  return Array.isArray(refs) ? refs : [refs];
@@ -1712,6 +1706,50 @@ export default class CAD {
1712
1706
  return asmUtils.getMatePath(drawingId, rRefId);
1713
1707
  }, refId);
1714
1708
  },
1709
+ slice: async (partId, operations, reference, sideFlag) => {
1710
+ const [rPartId] = await new Promise(res => this.resolve(ids => res(ids), partId));
1711
+ const rOperations = await new Promise(res => this.resolve(ids => res(ids), ...operations));
1712
+ const [rReference] = await new Promise(res => this.resolve(paths => res(paths), reference));
1713
+ const cDrawing = getDrawing(drawingId);
1714
+ const entArray = [];
1715
+ for (const rOperation of rOperations) {
1716
+ const entities = cDrawing.structure.tree[rOperation].children;
1717
+ if (entities != undefined && entities.length > 0) {
1718
+ entArray.push(entities[0]); // use first entity of operation
1719
+ }
1720
+ }
1721
+ const sliceId = await featureAPI.createFeature(drawingId, rPartId, CCClasses.CCSlice, 'Slice');
1722
+ if (sliceId != null) {
1723
+ await featureAPI.openFeature(drawingId, sliceId);
1724
+ if (entArray.length > 0) {
1725
+ await featureAPI.updateSlice(drawingId, sliceId, entArray, rReference, sideFlag ? 1 : 0);
1726
+ await featureAPI.closeFeature(drawingId, sliceId);
1727
+ return sliceId;
1728
+ }
1729
+ await featureAPI.closeFeature(drawingId, sliceId);
1730
+ await baseModelerAPI.deleteObjects(drawingId, [sliceId]);
1731
+ }
1732
+ return null;
1733
+ },
1734
+ sliceBySheet: async (partId, operationToSlice, operationOfSheet, sideFlag) => {
1735
+ const [rPartId] = await new Promise(res => this.resolve(ids => res(ids), partId));
1736
+ const [rOperationToSlice] = await new Promise(res => this.resolve(ids => res(ids), operationToSlice));
1737
+ const [rOperationOfSheet] = await new Promise(res => this.resolve(ids => res(ids), operationOfSheet));
1738
+ const entityToSlice = getDrawing(drawingId).structure.tree[rOperationToSlice].children;
1739
+ const entityOfSheet = getDrawing(drawingId).structure.tree[rOperationOfSheet].children;
1740
+ const sliceBySheetId = await featureAPI.createFeature(drawingId, rPartId, CCClasses.CCSliceBySheet, 'SliceBySheet');
1741
+ if (sliceBySheetId != null) {
1742
+ await featureAPI.openFeature(drawingId, sliceBySheetId);
1743
+ if (entityToSlice && entityToSlice.length > 0 && entityOfSheet && entityOfSheet.length > 0) {
1744
+ await featureAPI.updateSliceBySheet(drawingId, sliceBySheetId, entityToSlice[0], entityOfSheet[0], sideFlag ? 1 : 0);
1745
+ await featureAPI.closeFeature(drawingId, sliceBySheetId);
1746
+ return sliceBySheetId;
1747
+ }
1748
+ await featureAPI.closeFeature(drawingId, sliceBySheetId);
1749
+ await baseModelerAPI.deleteObjects(drawingId, [sliceBySheetId]);
1750
+ }
1751
+ return null;
1752
+ },
1715
1753
  };
1716
1754
  callback(publicApi);
1717
1755
  resolve(drawingId);
@@ -9,13 +9,9 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
9
9
  import { ccAPI } from '@buerli.io/classcad';
10
10
  import { api, getDrawing } from '@buerli.io/core';
11
11
  import { Group, Mesh, MeshStandardMaterial, Scene, Shape } from 'three';
12
- import * as BufferGeometryUtils_ from 'three/examples/jsm/utils/BufferGeometryUtils';
12
+ import { mergeBufferGeometries } from 'three-stdlib';
13
13
  import { getDifferentColoredMeshesFromEntity } from './utils/meshes';
14
14
  const solidAPI = ccAPI.solid;
15
- let BufferGeometryUtils = BufferGeometryUtils_;
16
- if (BufferGeometryUtils.BufferGeometryUtils) {
17
- BufferGeometryUtils = BufferGeometryUtils.BufferGeometryUtils;
18
- }
19
15
  const toCCVec = (args) => ({ x: args[0], y: args[1], z: args[2] });
20
16
  const toCCNbrVec = (args) => ({ x: args[0], y: args[1], z: args[2] });
21
17
  const toArray = (v) => (Array.isArray(v) ? v : v.toArray());
@@ -236,7 +232,7 @@ export default class CAD {
236
232
  await ccAPI.baseModeler.requestVisualisationOfObject(drawingId, rSolid);
237
233
  const entity = await getEntity(drawingId, rSolid);
238
234
  if (entity != null) {
239
- return BufferGeometryUtils.mergeBufferGeometries(entity.meshes.map(m => m.geometry));
235
+ return mergeBufferGeometries(entity.meshes.map(m => m.geometry));
240
236
  }
241
237
  },
242
238
  createScene: async (solids, options) => {
@@ -283,7 +279,7 @@ export default class CAD {
283
279
  const colorMeshesMap = getDifferentColoredMeshesFromEntity(entity);
284
280
  Object.keys(colorMeshesMap).forEach(key => {
285
281
  const mesh = new Mesh();
286
- mesh.geometry = BufferGeometryUtils.mergeBufferGeometries(colorMeshesMap[key].meshes.map(m => m.geometry));
282
+ mesh.geometry = mergeBufferGeometries(colorMeshesMap[key].meshes.map(m => m.geometry));
287
283
  mesh.material = new MeshStandardMaterial({
288
284
  color: colorMeshesMap[key].color,
289
285
  transparent: colorMeshesMap[key].opacity < 1,
@@ -1,5 +1,5 @@
1
- import { BooleanOperationType, ChamferType, FlipType, ReorientedType, WorkAxisType, WorkCoordSystemType, WorkPlaneType, WorkPointType, ViewType, OrientationType, ExtrusionType, BrepElemType, WorkGeomType, SVGModusType, LimitsParam, LimitedValue } from '@buerli.io/classcad';
2
- import { ObjectIdent, ObjectID, PointMemValue } from '@buerli.io/core';
1
+ import { BooleanOperationType, ChamferType, FlipType, ReorientedType, WorkAxisType, WorkCoordSystemType, WorkPlaneType, WorkPointType, ViewType, OrientationType, ExtrusionType, WorkGeomType, SVGModusType, LimitsParam, LimitedValue } from '@buerli.io/classcad';
2
+ import { DrawingID, ObjectIdent, ObjectID, PointMemValue, GraphicType, InteractionInfo } from '@buerli.io/core';
3
3
  import { BufferGeometry, Material, Object3D, Scene } from 'three';
4
4
  export declare type Vec = number[] | PointMemValue | THREE.Vector3 | THREE.Euler;
5
5
  /**
@@ -338,13 +338,13 @@ export declare type ApiHistory = {
338
338
  *
339
339
  * // Creates a part template and adds geometry to it
340
340
  * const partTempl1 = await api.createPartAsTemplate('Part_Template1')
341
- * const wcs1 = await api.createWorkCoordSystem(partTempl1, 'Custom', [], offset1, rot, 0, false, 'wcs1')
342
- * const wcs3 = await api.createWorkCoordSystem(partTempl1, 'Custom', [], offset3, rot, 0, false, 'wcs3')
341
+ * const wcs1 = await api.createWorkCoordSystem(partTempl1, WorkCoordSystemType.WCS_Custom, [], offset1, rot, false, 'wcs1')
342
+ * const wcs3 = await api.createWorkCoordSystem(partTempl1, WorkCoordSystemType.WCS_Custom, [], offset3, rot, false, 'wcs3')
343
343
  * api.box(partTempl1, [wcs1], 30, 30, 30)
344
344
  *
345
345
  * // Creates another part template and adds geometry to it
346
346
  * const partTempl2 = await api.createPartAsTemplate('Part_Template2')
347
- * const wcs2 = await api.createWorkCoordSystem(partTempl2, 'Custom', [], offset2, rot, 0, false, 'wcs2')
347
+ * const wcs2 = await api.createWorkCoordSystem(partTempl2, WorkCoordSystemType.WCS_Custom, [], offset2, rot, false, 'wcs2')
348
348
  * api.cone(partTempl2, [wcs2], 30, 0.1, 30)
349
349
  *
350
350
  * // Adds the created part templates as nodes to the root assembly
@@ -397,8 +397,8 @@ export declare type ApiHistory = {
397
397
  *
398
398
  * // Creates a part template and adds geometry to it
399
399
  * const partTempl = await api.createPartAsTemplate('Part_Template')
400
- * const wcs1 = await api.createWorkCoordSystem(partTempl, 'Custom', [], offset1, rot, 0, false, 'wcs')
401
- * const wcs2 = await api.createWorkCoordSystem(partTempl, 'Custom', [], offset2, rot, 0, false, 'wcs')
400
+ * const wcs1 = await api.createWorkCoordSystem(partTempl, WorkCoordSystemType.WCS_Custom, [], offset1, rot, false, 'wcs')
401
+ * const wcs2 = await api.createWorkCoordSystem(partTempl, WorkCoordSystemType.WCS_Custom, [], offset2, rot, false, 'wcs')
402
402
  * api.box(partTempl, [wcs1], 30, 30, 30)
403
403
  *
404
404
  * // Adds the created part template as a node to the root assembly
@@ -659,12 +659,12 @@ export declare type ApiHistory = {
659
659
  *
660
660
  * // Creates a part template and adds geometry to it
661
661
  * const partTempl1 = await api.createPartAsTemplate('Part_Template1')
662
- * const wcs1 = await api.createWorkCoordSystem(partTempl1, 'Custom', [], offset1, rot, 0, false, 'wcs1')
662
+ * const wcs1 = await api.createWorkCoordSystem(partTempl1, WorkCoordSystemType.WCS_Custom, [], offset1, rot, false, 'wcs1')
663
663
  * api.box(partTempl1, [wcs1], 30, 30, 30)
664
664
  *
665
665
  * // Creates another part template and adds geometry to it
666
666
  * const partTempl2 = await api.createPartAsTemplate('Part_Template2')
667
- * const wcs2 = await api.createWorkCoordSystem(partTempl2, 'Custom', [], offset2, rot, 0, false, 'wcs2')
667
+ * const wcs2 = await api.createWorkCoordSystem(partTempl2, WorkCoordSystemType.WCS_Custom, [], offset2, rot, false, 'wcs2')
668
668
  * api.cone(partTempl2, [wcs2], 30, 0.1, 30)
669
669
  *
670
670
  * // Adds the created part templates as nodes to the assembly
@@ -695,7 +695,7 @@ export declare type ApiHistory = {
695
695
  *
696
696
  * // Creates a part template and adds geometry to it
697
697
  * const partTempl = await api.createPartAsTemplate('Part_Template')
698
- * const wcs = await api.createWorkCoordSystem(partTempl, 'Custom', [], offset, rot, 0, false, 'wcs')
698
+ * const wcs = await api.createWorkCoordSystem(partTempl, WorkCoordSystemType.WCS_Custom, [], offset, rot, false, 'wcs')
699
699
  * api.box(partTempl, [wcs], 30, 30, 10)
700
700
  *
701
701
  * // Adds the created part template as a node to the root assembly
@@ -733,7 +733,7 @@ export declare type ApiHistory = {
733
733
  *
734
734
  * // Creates a part template and adds geometry to it
735
735
  * const partTempl = await api.createPartAsTemplate('Part_Template')
736
- * const wcs = await api.createWorkCoordSystem(partTempl, 'Custom', [], offset, rot, 0, false, 'wcs')
736
+ * const wcs = await api.createWorkCoordSystem(partTempl, WorkCoordSystemType.WCS_Custom, [], offset, rot, false, 'wcs')
737
737
  * api.box(partTempl, [wcs], 30, 30, 10)
738
738
  *
739
739
  * // Adds the created part template as a node to the root assembly
@@ -762,7 +762,6 @@ export declare type ApiHistory = {
762
762
  * @param offset offset from work coordinate system in x-, y- and z-direction
763
763
  * @param rotation rotation around x-, y- and z-axis from work coordinate system
764
764
  * @param inverted inverts the constraint between mate1 and mate2
765
- * @param local if true, work coordinate system is set in local coordinates of part???
766
765
  * @param name name of the work coordinate system, if not set default name = 'WorkCoordSystem'
767
766
  * @example
768
767
  * // Defines some consts
@@ -779,13 +778,13 @@ export declare type ApiHistory = {
779
778
  *
780
779
  * // Creates a part template and adds geometry to it
781
780
  * const partTempl1 = await api.createPartAsTemplate('Part_Template1')
782
- * const wcs1 = await api.createWorkCoordSystem(partTempl1, WorkCoordSystemType.WCS_Custom, [], offset1, rot, 0, false, 'wcs1')
783
- * const wcs3 = await api.createWorkCoordSystem(partTempl1, WorkCoordSystemType.WCS_Custom, [], offset3, rot, 0, false, 'wcs3')
781
+ * const wcs1 = await api.createWorkCoordSystem(partTempl1, WorkCoordSystemType.WCS_Custom, [], offset1, rot, false, 'wcs1')
782
+ * const wcs3 = await api.createWorkCoordSystem(partTempl1, WorkCoordSystemType.WCS_Custom, [], offset3, rot, false, 'wcs3')
784
783
  * api.box(partTempl1, [wcs1], 30, 30, 30)
785
784
  *
786
785
  * // Creates another part template and adds geometry to it
787
786
  * const partTempl2 = await api.createPartAsTemplate('Part_Template2')
788
- * const wcs2 = await api.createWorkCoordSystem(partTempl2, WorkCoordSystemType.WCS_Custom, [], offset2, rot, 0, false, 'wcs2')
787
+ * const wcs2 = await api.createWorkCoordSystem(partTempl2, WorkCoordSystemType.WCS_Custom, [], offset2, rot, false, 'wcs2')
789
788
  * api.cone(partTempl2, [wcs2], 30, 0.1, 30)
790
789
  *
791
790
  * // Adds the created part templates as nodes to the root assembly
@@ -797,7 +796,7 @@ export declare type ApiHistory = {
797
796
  * const geoms = await api.createBufferGeometry(rootAsm)
798
797
  * return geoms.map(geom => new THREE.Mesh(geom, new THREE.MeshStandardMaterial()))
799
798
  */
800
- createWorkCoordSystem: (partId: VID, type: WorkCoordSystemType, references: VID[], coordinateSystem: Vec[], offset: Vec, rotation: Vec, inverted: boolean, local: boolean, name?: string) => ID;
799
+ createWorkCoordSystem: (partId: VID, type: WorkCoordSystemType, references: VID[], offset: Vec, rotation: Vec, inverted: boolean, name?: string) => ID;
801
800
  /**
802
801
  * Creates a new work plane for the given part
803
802
  * @param partId id of the part to add the new work plane to
@@ -899,15 +898,27 @@ export declare type ApiHistory = {
899
898
  */
900
899
  fillet: (partId: VID, references: VIDs, radius: number | string) => ID;
901
900
  /**
902
- * Find geometry (vertices, edges, faces, loops) by given positions or selection. If positions parameter is null,
903
- * user can select geometry in graphical interface. For all selected geometries this function logs its
904
- * relevant points into console, to find the geometry later by points
905
- * @param partId id of the part looking for geometry in or selecting them
906
- * @param type type of geometry to find or select
907
- * @param length number of selections to make before resolving the selection
908
- * @param positions array of point arrays where to look for geometry or null if the geometry wants to be selected
901
+ * Important note: To use this method, you need to add the BuerliGeometry component to your application.
902
+ * Otherwise the selection of geometry won't work.
903
+ * @see https://buerli.io/docs/training-for-programmers/More/graphics#3-using-the-buerligeometry-react-component
904
+ *
905
+ * Lets the user select geometry in graphical interface. As soon as the geometry of given type has been selected, the method
906
+ * will return necessary information about it.
907
+ * @see https://buerli.io/docs/training-for-programmers/history/HowTos/useSelectionInHeadless
908
+ * @param types array of types to filter user selection.
909
+ * @param count optional number of selections to make (count must be >= 1). Default = 1.
910
+ */
911
+ selectGeometry: (types: GrT[], count?: number) => Promise<InteractionInfo[]>;
912
+ /**
913
+ * Find geometries of given type on solids in the given part at the given global positions.
914
+ * @param partId Id of the part where geometries tried to be found.
915
+ * @param type Type of the geometry to look for
916
+ * @param positions Array of elements containing one or more positions to look for the geometry
917
+ * @example
918
+ * // Find planes at two different positions
919
+ * const planes = await api.findGeometry(productId, GraphicType.PLANE, [[{x: 50, y: 50, z: 100}], [{x: 100, y: 50, z: 50}]])
909
920
  */
910
- findOrSelect: (partId: VID, type: BrepElemType, length: number, positions: Vec[][] | null) => IDs;
921
+ findGeometry: (partId: VID, type: GrT, positions: Vec[][]) => IDs;
911
922
  /**
912
923
  * Returns the assembly with given name from assembly container.
913
924
  * If asmName is empty, all assemblies from assembly container will be returned.
@@ -1174,14 +1185,18 @@ export declare type ApiHistory = {
1174
1185
  referenceId: VID | ObjectIdent;
1175
1186
  }[]) => Promise<void>;
1176
1187
  /**
1177
- * Transforms the node with referenceId with the given transformation within an assembly
1188
+ * Transforms the nodes with referenceId with the given transformation within an assembly.
1189
+ * The transformations are local to the nodes parent (owner), which is an assembly.
1178
1190
  *
1179
- * @param referenceId id of the node to transform
1180
- * @param ownerId id of the owner (parent) of node we want to transform
1181
- * @param transformation array of three vectors [origin, xAxis, yAxis]
1191
+ * @param nodes array of node parameter objects. See following descriptions.
1192
+ * @param referenceId id or identifier of the node to transform
1193
+ * @param transformation transformation (origin, xDir, yDir) of the node (local to the owner).
1182
1194
  * @example // tbd
1183
1195
  */
1184
- transformNode: (referenceId: VID, ownerId: VID, transformation: Transform) => Promise<void>;
1196
+ transformNodes: (...nodes: {
1197
+ referenceId: VID | ObjectIdent;
1198
+ transformation: Transform;
1199
+ }[]) => Promise<void>;
1185
1200
  /**
1186
1201
  * Translates a feature along a given axis.
1187
1202
  * @param partId id ot the part where features will be translated
@@ -1202,6 +1217,8 @@ export declare type ApiHistory = {
1202
1217
  */
1203
1218
  updateTranslate: (translationId: VID, distance: number) => Promise<void>;
1204
1219
  /**
1220
+ * @deprecated use findGeometry() instead, pick() will be removed in a future release.
1221
+ *
1205
1222
  * Returns found vertices, edges or faces depending on
1206
1223
  * given type an points. Given points define where to look for elements.
1207
1224
  * @param partId id of the part to pick elements
@@ -1255,9 +1272,27 @@ export declare type ApiHistory = {
1255
1272
  * @param refId id of the node to set the constraint on
1256
1273
  */
1257
1274
  getMatePath: (refId: VID) => Promise<ObjectID[]>;
1275
+ /**
1276
+ * Slices the entities of the given operations by the given reference.
1277
+ * @param partId id of the part where the slice will be created
1278
+ * @param operations ids of the operations from which its entities will be sliced
1279
+ * @param reference id of the workplane reference to use for the slice
1280
+ * @param sideFlag flag to toggle which side of the sliced entities will be kept
1281
+ * @return id of the slice operation
1282
+ */
1283
+ slice: (partId: VID, operations: VID[], reference: VID, sideFlag: boolean) => ID;
1284
+ /**
1285
+ * Slices the entity of an operation with a sheet entity of another operation
1286
+ * @param partId id of the part where the slice will be created
1287
+ * @param operationToSlice id of the operation of which its entity will be sliced
1288
+ * @param operationOfSheet id of the operation of which its entity is a sheet and used to slice the entity of operationToSlice
1289
+ * @param sideFlag flag to toggle which side of the sliced entity will be kept
1290
+ * @return id of the slice by sheet operation
1291
+ */
1292
+ sliceBySheet: (partId: VID, operationToSlice: VID, operationOfSheet: VID, sideFlag: boolean) => ID;
1258
1293
  };
1259
1294
  export default class CAD {
1260
- private drawingId;
1295
+ drawingId: DrawingID | null;
1261
1296
  queue: Promise<number>;
1262
1297
  constructor();
1263
1298
  resolve(callback: (...results: any) => Promise<any>, ...args: any[]): Promise<any>;
@@ -1283,6 +1318,7 @@ declare type MateParam = {
1283
1318
  flip: FlipType;
1284
1319
  reoriented: ReorientedType;
1285
1320
  };
1321
+ declare type GrT = GraphicType.POINT | GraphicType.LINE | GraphicType.ARC | GraphicType.CIRCLE | GraphicType.PLANE | GraphicType.CYLINDER | GraphicType.CONE | GraphicType.SPHERE | GraphicType.NURBSCURVE | GraphicType.NURBSSURFACE;
1286
1322
  export declare type Transform = [Point, Point, Point];
1287
1323
  export declare type DimensionType = {
1288
1324
  productId: VID;
@@ -1,4 +1,4 @@
1
- import { ObjectID } from '@buerli.io/core';
1
+ import { DrawingID, ObjectID } from '@buerli.io/core';
2
2
  import { BufferGeometry, Scene, Vector3 } from 'three';
3
3
  /**
4
4
  * A simple and intuitive javascript based api that incorporates solid operations like
@@ -442,7 +442,7 @@ export declare type ApiNoHistory = {
442
442
  */
443
443
  export declare function createPolyline(fPts: FilletPoint[]): Polyline;
444
444
  export default class CAD {
445
- private drawingId;
445
+ drawingId: DrawingID | null;
446
446
  queue: Promise<number>;
447
447
  constructor();
448
448
  resolve(callback: (...results: any) => Promise<any>, ...args: any[]): Promise<any>;
@@ -1,4 +1,4 @@
1
1
  import { SelectedItem } from '@buerli.io/core';
2
2
  declare type CustomSelect<T> = (resolve: (result: T) => Promise<T>, newItems: SelectedItem[], diff: SelectedItem[]) => void;
3
- export declare function waitForSelect<T>(length: number, filter: any, onChange: CustomSelect<T>): Promise<number[]>;
3
+ export declare function waitForSelect<T>(length: number, filter: any, onChange: CustomSelect<T>): Promise<SelectedItem<any>[]>;
4
4
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buerli.io/headless",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
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",
@@ -20,17 +20,19 @@
20
20
  "prettify": "prettier --write \"./{src,tests}/**/*.{js,jsx,ts,tsx,json}\""
21
21
  },
22
22
  "devDependencies": {
23
- "@types/three": "^0.143",
23
+ "@types/three": "^0.152.1",
24
24
  "copyfiles": "^2.1.1",
25
25
  "rimraf": "^2.6.3",
26
- "three": "^0.143",
26
+ "three": "^0.153",
27
+ "three-stdlib": "2.23.5",
27
28
  "typescript": "4.8.4"
28
29
  },
29
30
  "peerDependencies": {
30
- "three": ">=0.138"
31
+ "three": ">=0.138",
32
+ "three-stdlib": ">=2.11.0"
31
33
  },
32
34
  "dependencies": {
33
- "@buerli.io/classcad": "0.7.1",
35
+ "@buerli.io/classcad": "0.8.0",
34
36
  "flat-promise": "^1.0.3"
35
37
  }
36
38
  }