@buerli.io/headless 0.9.0 → 0.9.1-beta.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.
@@ -249,9 +249,48 @@ class CAD {
249
249
  for (var instances_1 = __asyncValues(instances), instances_1_1; instances_1_1 = await instances_1.next(), !instances_1_1.done;) {
250
250
  const instance = instances_1_1.value;
251
251
  const [rProductId, rOwnerId] = await new Promise(res => this.resolve(id => res(id), instance.productId, instance.ownerId));
252
+ // Looking for the productId given by an identifier or name
253
+ // Priorities:
254
+ // 1. Look for the identifier then for the name in the part templates
255
+ // 2. Look for the identifier then for the name in the assembly templates
256
+ let product = rProductId;
257
+ if (typeof rProductId === 'string') {
258
+ let products = asmUtils.getPartTemplate(drawingId, rProductId);
259
+ if (products.length > 1) {
260
+ throw 'More than one product has been found for given name or ident: ' + rProductId;
261
+ }
262
+ else if (products.length < 1) {
263
+ products = asmUtils.getAssemblyTemplate(drawingId, rProductId);
264
+ if (products.length < 1) {
265
+ throw 'No product found for given name or ident: ' + rProductId;
266
+ }
267
+ else if (products.length > 1) {
268
+ throw 'More than one product has been found for given name or ident: ' + rProductId;
269
+ }
270
+ }
271
+ product = products[0];
272
+ }
273
+ let owner = rOwnerId;
274
+ if (typeof rOwnerId === 'string') {
275
+ owner = baseUtils.findObject(drawingId, {
276
+ ident: rOwnerId,
277
+ name: rOwnerId,
278
+ });
279
+ if (!owner) {
280
+ throw 'The owner to add instances on given by name or ident "' + rOwnerId + '" does not exist.';
281
+ }
282
+ const clazz = (0, core_1.getDrawing)(drawingId).structure.tree[owner].class;
283
+ if (!baseUtils.isA(clazz, classcad_1.CCClasses.IProductReference) && !baseUtils.isA(clazz, classcad_1.CCClasses.CCAssembly)) {
284
+ throw ('The owner to add instances on given by name or ident "' +
285
+ rOwnerId +
286
+ '" is of the wrong type: "' +
287
+ clazz +
288
+ '". Make sure the owner is an instance, a root assembly or an assembly template.');
289
+ }
290
+ }
252
291
  const instanceParam = {
253
- productId: rProductId,
254
- ownerId: rOwnerId,
292
+ productId: product,
293
+ ownerId: owner,
255
294
  transformation: instance.transformation,
256
295
  name: instance.name,
257
296
  options: Object.assign(Object.assign({}, instance.options), { isLocal: true }), // in non-interactive mode, the transformation is local to the owner
@@ -1248,6 +1287,24 @@ class CAD {
1248
1287
  return null;
1249
1288
  }, id);
1250
1289
  },
1290
+ findInstance: (options) => {
1291
+ return this.resolve(async () => {
1292
+ const instance = baseUtils.findObject(drawingId, {
1293
+ ident: options.instanceIdent,
1294
+ name: options.instanceName,
1295
+ });
1296
+ if (!instance) {
1297
+ return null;
1298
+ }
1299
+ const clazz = (0, core_1.getDrawing)(drawingId).structure.tree[instance].class;
1300
+ if (!baseUtils.isA(clazz, classcad_1.CCClasses.IProductReference)) {
1301
+ return null;
1302
+ }
1303
+ else {
1304
+ return instance;
1305
+ }
1306
+ });
1307
+ },
1251
1308
  getProductsOfInstances: (instanceIds) => {
1252
1309
  return this.resolve(async ([rInstanceIds]) => {
1253
1310
  const drawing = (0, core_1.getDrawing)(drawingId);
@@ -1467,10 +1524,43 @@ class CAD {
1467
1524
  return null;
1468
1525
  }, id);
1469
1526
  },
1470
- removeInstances: (...instances) => {
1471
- return this.resolve(async ([...rInstances]) => {
1472
- return assemblyBuilderAPI.removeInstances(drawingId, rInstances);
1473
- }, ...instances);
1527
+ removeInstances: async (...instances) => {
1528
+ var e_11, _a;
1529
+ const instancesToRemove = [];
1530
+ try {
1531
+ for (var instances_2 = __asyncValues(instances), instances_2_1; instances_2_1 = await instances_2.next(), !instances_2_1.done;) {
1532
+ const instance = instances_2_1.value;
1533
+ const [rInstanceId] = await new Promise(res => this.resolve(id => res(id), instance.id));
1534
+ let instanceId = rInstanceId;
1535
+ if (typeof rInstanceId === 'string') {
1536
+ instanceId = baseUtils.findObject(drawingId, {
1537
+ ident: rInstanceId,
1538
+ name: rInstanceId,
1539
+ });
1540
+ if (!instanceId) {
1541
+ throw 'The instance to remove given by name or ident "' + rInstanceId + '" does not exist.';
1542
+ }
1543
+ const clazz = (0, core_1.getDrawing)(drawingId).structure.tree[instanceId].class;
1544
+ if (!baseUtils.isA(clazz, classcad_1.CCClasses.IProductReference)) {
1545
+ throw ('The instance to remove given by name or ident "' +
1546
+ rInstanceId +
1547
+ '" is of the wrong type "' +
1548
+ clazz +
1549
+ '". Make sure the object is an instance.');
1550
+ }
1551
+ }
1552
+ const instanceParam = { id: instanceId };
1553
+ instancesToRemove.push(instanceParam);
1554
+ }
1555
+ }
1556
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
1557
+ finally {
1558
+ try {
1559
+ if (instances_2_1 && !instances_2_1.done && (_a = instances_2.return)) await _a.call(instances_2);
1560
+ }
1561
+ finally { if (e_11) throw e_11.error; }
1562
+ }
1563
+ return assemblyBuilderAPI.removeInstances(drawingId, instancesToRemove);
1474
1564
  },
1475
1565
  importFeature: (partId, content, format, name) => {
1476
1566
  return this.resolve(async ([rPartId]) => {
@@ -1527,26 +1617,44 @@ class CAD {
1527
1617
  }, sketchId, planeId, axisId, originId);
1528
1618
  },
1529
1619
  transformInstances: async (...instances) => {
1530
- var e_11, _a;
1620
+ var e_12, _a;
1531
1621
  const instancesToTransform = [];
1532
1622
  try {
1533
- for (var instances_2 = __asyncValues(instances), instances_2_1; instances_2_1 = await instances_2.next(), !instances_2_1.done;) {
1534
- const instance = instances_2_1.value;
1623
+ for (var instances_3 = __asyncValues(instances), instances_3_1; instances_3_1 = await instances_3.next(), !instances_3_1.done;) {
1624
+ const instance = instances_3_1.value;
1535
1625
  const [rInstanceId] = await new Promise(res => this.resolve(id => res(id), instance.id));
1626
+ let instanceId = rInstanceId;
1627
+ if (typeof rInstanceId === 'string') {
1628
+ instanceId = baseUtils.findObject(drawingId, {
1629
+ ident: rInstanceId,
1630
+ name: rInstanceId,
1631
+ });
1632
+ if (!instanceId) {
1633
+ throw 'The instance to transform given by name or ident "' + rInstanceId + '" does not exist.';
1634
+ }
1635
+ const clazz = (0, core_1.getDrawing)(drawingId).structure.tree[instanceId].class;
1636
+ if (!baseUtils.isA(clazz, classcad_1.CCClasses.IProductReference)) {
1637
+ throw ('The instance to transform given by name or ident "' +
1638
+ rInstanceId +
1639
+ '" is of the wrong type "' +
1640
+ clazz +
1641
+ '". Make sure the object is an instance.');
1642
+ }
1643
+ }
1536
1644
  const instanceParam = {
1537
- id: rInstanceId,
1645
+ id: instanceId,
1538
1646
  transformation: instance.transformation,
1539
1647
  options: { isLocal: true }, // in non-interactive mode, the transformation is local to the owner
1540
1648
  };
1541
1649
  instancesToTransform.push(instanceParam);
1542
1650
  }
1543
1651
  }
1544
- catch (e_11_1) { e_11 = { error: e_11_1 }; }
1652
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
1545
1653
  finally {
1546
1654
  try {
1547
- if (instances_2_1 && !instances_2_1.done && (_a = instances_2.return)) await _a.call(instances_2);
1655
+ if (instances_3_1 && !instances_3_1.done && (_a = instances_3.return)) await _a.call(instances_3);
1548
1656
  }
1549
- finally { if (e_11) throw e_11.error; }
1657
+ finally { if (e_12) throw e_12.error; }
1550
1658
  }
1551
1659
  return assemblyBuilderAPI.transformInstances(drawingId, instancesToTransform);
1552
1660
  },
@@ -1627,8 +1735,22 @@ class CAD {
1627
1735
  };
1628
1736
  membersToModify.push({ name: mem.name, value: featureAPIParam });
1629
1737
  });
1738
+ // Looking for the partId given by an identifier or name
1739
+ let part = expr.partId;
1740
+ if (typeof part === 'string') {
1741
+ const products = asmUtils.getPartTemplate(drawingId, part);
1742
+ if (products.length > 1) {
1743
+ throw 'More than one product has been found for given name or ident: ' + part;
1744
+ }
1745
+ else if (products.length < 1) {
1746
+ throw 'No product found for given name or ident: ' + part;
1747
+ }
1748
+ else {
1749
+ part = products[0];
1750
+ }
1751
+ }
1630
1752
  expressionsToSet.push({
1631
- productId: expr.partId,
1753
+ productId: part,
1632
1754
  toAddMembers: [],
1633
1755
  toModifyMembers: membersToModify,
1634
1756
  toDeleteList: [],
@@ -247,9 +247,48 @@ export default class CAD {
247
247
  for (var instances_1 = __asyncValues(instances), instances_1_1; instances_1_1 = await instances_1.next(), !instances_1_1.done;) {
248
248
  const instance = instances_1_1.value;
249
249
  const [rProductId, rOwnerId] = await new Promise(res => this.resolve(id => res(id), instance.productId, instance.ownerId));
250
+ // Looking for the productId given by an identifier or name
251
+ // Priorities:
252
+ // 1. Look for the identifier then for the name in the part templates
253
+ // 2. Look for the identifier then for the name in the assembly templates
254
+ let product = rProductId;
255
+ if (typeof rProductId === 'string') {
256
+ let products = asmUtils.getPartTemplate(drawingId, rProductId);
257
+ if (products.length > 1) {
258
+ throw 'More than one product has been found for given name or ident: ' + rProductId;
259
+ }
260
+ else if (products.length < 1) {
261
+ products = asmUtils.getAssemblyTemplate(drawingId, rProductId);
262
+ if (products.length < 1) {
263
+ throw 'No product found for given name or ident: ' + rProductId;
264
+ }
265
+ else if (products.length > 1) {
266
+ throw 'More than one product has been found for given name or ident: ' + rProductId;
267
+ }
268
+ }
269
+ product = products[0];
270
+ }
271
+ let owner = rOwnerId;
272
+ if (typeof rOwnerId === 'string') {
273
+ owner = baseUtils.findObject(drawingId, {
274
+ ident: rOwnerId,
275
+ name: rOwnerId,
276
+ });
277
+ if (!owner) {
278
+ throw 'The owner to add instances on given by name or ident "' + rOwnerId + '" does not exist.';
279
+ }
280
+ const clazz = getDrawing(drawingId).structure.tree[owner].class;
281
+ if (!baseUtils.isA(clazz, CCClasses.IProductReference) && !baseUtils.isA(clazz, CCClasses.CCAssembly)) {
282
+ throw ('The owner to add instances on given by name or ident "' +
283
+ rOwnerId +
284
+ '" is of the wrong type: "' +
285
+ clazz +
286
+ '". Make sure the owner is an instance, a root assembly or an assembly template.');
287
+ }
288
+ }
250
289
  const instanceParam = {
251
- productId: rProductId,
252
- ownerId: rOwnerId,
290
+ productId: product,
291
+ ownerId: owner,
253
292
  transformation: instance.transformation,
254
293
  name: instance.name,
255
294
  options: Object.assign(Object.assign({}, instance.options), { isLocal: true }), // in non-interactive mode, the transformation is local to the owner
@@ -1246,6 +1285,24 @@ export default class CAD {
1246
1285
  return null;
1247
1286
  }, id);
1248
1287
  },
1288
+ findInstance: (options) => {
1289
+ return this.resolve(async () => {
1290
+ const instance = baseUtils.findObject(drawingId, {
1291
+ ident: options.instanceIdent,
1292
+ name: options.instanceName,
1293
+ });
1294
+ if (!instance) {
1295
+ return null;
1296
+ }
1297
+ const clazz = getDrawing(drawingId).structure.tree[instance].class;
1298
+ if (!baseUtils.isA(clazz, CCClasses.IProductReference)) {
1299
+ return null;
1300
+ }
1301
+ else {
1302
+ return instance;
1303
+ }
1304
+ });
1305
+ },
1249
1306
  getProductsOfInstances: (instanceIds) => {
1250
1307
  return this.resolve(async ([rInstanceIds]) => {
1251
1308
  const drawing = getDrawing(drawingId);
@@ -1465,10 +1522,43 @@ export default class CAD {
1465
1522
  return null;
1466
1523
  }, id);
1467
1524
  },
1468
- removeInstances: (...instances) => {
1469
- return this.resolve(async ([...rInstances]) => {
1470
- return assemblyBuilderAPI.removeInstances(drawingId, rInstances);
1471
- }, ...instances);
1525
+ removeInstances: async (...instances) => {
1526
+ var e_11, _a;
1527
+ const instancesToRemove = [];
1528
+ try {
1529
+ for (var instances_2 = __asyncValues(instances), instances_2_1; instances_2_1 = await instances_2.next(), !instances_2_1.done;) {
1530
+ const instance = instances_2_1.value;
1531
+ const [rInstanceId] = await new Promise(res => this.resolve(id => res(id), instance.id));
1532
+ let instanceId = rInstanceId;
1533
+ if (typeof rInstanceId === 'string') {
1534
+ instanceId = baseUtils.findObject(drawingId, {
1535
+ ident: rInstanceId,
1536
+ name: rInstanceId,
1537
+ });
1538
+ if (!instanceId) {
1539
+ throw 'The instance to remove given by name or ident "' + rInstanceId + '" does not exist.';
1540
+ }
1541
+ const clazz = getDrawing(drawingId).structure.tree[instanceId].class;
1542
+ if (!baseUtils.isA(clazz, CCClasses.IProductReference)) {
1543
+ throw ('The instance to remove given by name or ident "' +
1544
+ rInstanceId +
1545
+ '" is of the wrong type "' +
1546
+ clazz +
1547
+ '". Make sure the object is an instance.');
1548
+ }
1549
+ }
1550
+ const instanceParam = { id: instanceId };
1551
+ instancesToRemove.push(instanceParam);
1552
+ }
1553
+ }
1554
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
1555
+ finally {
1556
+ try {
1557
+ if (instances_2_1 && !instances_2_1.done && (_a = instances_2.return)) await _a.call(instances_2);
1558
+ }
1559
+ finally { if (e_11) throw e_11.error; }
1560
+ }
1561
+ return assemblyBuilderAPI.removeInstances(drawingId, instancesToRemove);
1472
1562
  },
1473
1563
  importFeature: (partId, content, format, name) => {
1474
1564
  return this.resolve(async ([rPartId]) => {
@@ -1525,26 +1615,44 @@ export default class CAD {
1525
1615
  }, sketchId, planeId, axisId, originId);
1526
1616
  },
1527
1617
  transformInstances: async (...instances) => {
1528
- var e_11, _a;
1618
+ var e_12, _a;
1529
1619
  const instancesToTransform = [];
1530
1620
  try {
1531
- for (var instances_2 = __asyncValues(instances), instances_2_1; instances_2_1 = await instances_2.next(), !instances_2_1.done;) {
1532
- const instance = instances_2_1.value;
1621
+ for (var instances_3 = __asyncValues(instances), instances_3_1; instances_3_1 = await instances_3.next(), !instances_3_1.done;) {
1622
+ const instance = instances_3_1.value;
1533
1623
  const [rInstanceId] = await new Promise(res => this.resolve(id => res(id), instance.id));
1624
+ let instanceId = rInstanceId;
1625
+ if (typeof rInstanceId === 'string') {
1626
+ instanceId = baseUtils.findObject(drawingId, {
1627
+ ident: rInstanceId,
1628
+ name: rInstanceId,
1629
+ });
1630
+ if (!instanceId) {
1631
+ throw 'The instance to transform given by name or ident "' + rInstanceId + '" does not exist.';
1632
+ }
1633
+ const clazz = getDrawing(drawingId).structure.tree[instanceId].class;
1634
+ if (!baseUtils.isA(clazz, CCClasses.IProductReference)) {
1635
+ throw ('The instance to transform given by name or ident "' +
1636
+ rInstanceId +
1637
+ '" is of the wrong type "' +
1638
+ clazz +
1639
+ '". Make sure the object is an instance.');
1640
+ }
1641
+ }
1534
1642
  const instanceParam = {
1535
- id: rInstanceId,
1643
+ id: instanceId,
1536
1644
  transformation: instance.transformation,
1537
1645
  options: { isLocal: true }, // in non-interactive mode, the transformation is local to the owner
1538
1646
  };
1539
1647
  instancesToTransform.push(instanceParam);
1540
1648
  }
1541
1649
  }
1542
- catch (e_11_1) { e_11 = { error: e_11_1 }; }
1650
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
1543
1651
  finally {
1544
1652
  try {
1545
- if (instances_2_1 && !instances_2_1.done && (_a = instances_2.return)) await _a.call(instances_2);
1653
+ if (instances_3_1 && !instances_3_1.done && (_a = instances_3.return)) await _a.call(instances_3);
1546
1654
  }
1547
- finally { if (e_11) throw e_11.error; }
1655
+ finally { if (e_12) throw e_12.error; }
1548
1656
  }
1549
1657
  return assemblyBuilderAPI.transformInstances(drawingId, instancesToTransform);
1550
1658
  },
@@ -1625,8 +1733,22 @@ export default class CAD {
1625
1733
  };
1626
1734
  membersToModify.push({ name: mem.name, value: featureAPIParam });
1627
1735
  });
1736
+ // Looking for the partId given by an identifier or name
1737
+ let part = expr.partId;
1738
+ if (typeof part === 'string') {
1739
+ const products = asmUtils.getPartTemplate(drawingId, part);
1740
+ if (products.length > 1) {
1741
+ throw 'More than one product has been found for given name or ident: ' + part;
1742
+ }
1743
+ else if (products.length < 1) {
1744
+ throw 'No product found for given name or ident: ' + part;
1745
+ }
1746
+ else {
1747
+ part = products[0];
1748
+ }
1749
+ }
1628
1750
  expressionsToSet.push({
1629
- productId: expr.partId,
1751
+ productId: part,
1630
1752
  toAddMembers: [],
1631
1753
  toModifyMembers: membersToModify,
1632
1754
  toDeleteList: [],
@@ -29,8 +29,8 @@ export declare type ApiHistory = {
29
29
  * - If the owner is an instance in the expanded tree, its template in the assembly container will also be updated.
30
30
  * - If the onwer is an assembly template, all instances of the template will also be updated
31
31
  * @param instances array of objects containing the information of "to add" instances. See following parameter descriptions.
32
- * @param productId id or identifier of the product to instantiate
33
- * @param ownerId id or identifier of the owner of to adding instance, owner can be root assembly, assembly instance or assembly template.
32
+ * @param productId id, identifier or name of the product to instantiate
33
+ * @param ownerId id, identifier or name of the owner of to adding instance, owner can be root assembly, assembly instance or assembly template.
34
34
  * @param transformation transformation (origin, x-Dir, y-Dir) of the instance
35
35
  * @param name optional name for the instance
36
36
  * @param options optional object containing ident property, to define a identifier for the adding instance
@@ -991,6 +991,21 @@ export declare type ApiHistory = {
991
991
  * @return array containing the ids of the found instances
992
992
  */
993
993
  getInstance: (id: VID, instanceName?: string) => IDs;
994
+ /**
995
+ * Find first instance which can be identified by given identifier or name.
996
+ * If both optional parameters has been set, the identifier is treated with priority.
997
+ * If no instance with given identifier will be found, the name is used to find an instance.
998
+ *
999
+ * @param drawingId The drawing id.
1000
+ * @param options Optional parameters to identify to find instance.
1001
+ * @param options.instanceIdent Identifier to find the instance by an identifier
1002
+ * @param options.instanceName Name to find the instance by its name
1003
+ * @returns first found instance which meets the searching conditions or null if nothing could be found
1004
+ */
1005
+ findInstance: (options: {
1006
+ instanceIdent?: ObjectIdent;
1007
+ instanceName?: string;
1008
+ }) => ID;
994
1009
  /**
995
1010
  * Returns the product ids of the given instance ids.
996
1011
  * @param instanceIds ids of the instances to get the product ids from
@@ -1261,7 +1276,7 @@ export declare type ApiHistory = {
1261
1276
  /**
1262
1277
  * Removes instances from root assembly, other instances or assembly templates.
1263
1278
  * @param instances array of instance objects. See following parameter descriptions.
1264
- * @param id id or identifier of the instance to remove
1279
+ * @param id id, identifier or name of the instance to remove
1265
1280
  * @example // tbd
1266
1281
  */
1267
1282
  removeInstances: (...instances: {
@@ -1271,7 +1286,7 @@ export declare type ApiHistory = {
1271
1286
  * Transforms instances by the given transformation.
1272
1287
  * The transformations are local to the instances parent, which is an assembly.
1273
1288
  * @param instances array of instance objects. See following descriptions.
1274
- * @param id id or identifier of the instance to transform
1289
+ * @param id id, identifier or name of the instance to transform
1275
1290
  * @param transformation transformation (origin, xDir, yDir) of the instance local to the owner.
1276
1291
  * @example // tbd
1277
1292
  */
@@ -1320,7 +1335,7 @@ export declare type ApiHistory = {
1320
1335
  /**
1321
1336
  * Updates multiple expressions in different parts at once
1322
1337
  * @param expressions array of expression objects containing the part id and the expression to set
1323
- * @param partId id or identifier of part to update expression
1338
+ * @param partId id, identifier or name of part to update expression
1324
1339
  * @param members array of members to update which contain a name and a value. Value can be an expression, e.g. '2 * laenge'
1325
1340
  * @example // tbd
1326
1341
  * @returns true, if updating expressions in all parts was successfull
@@ -1356,7 +1371,7 @@ export declare type ApiHistory = {
1356
1371
  * @param instanceId id of the instance to get the mate path from
1357
1372
  * @return array containing the ids as a path from given instance to current instance
1358
1373
  */
1359
- getMatePath: (instanceId: VID) => Promise<ObjectID[]>;
1374
+ getMatePath: (instanceId: VID | ObjectIdent) => Promise<ObjectID[]>;
1360
1375
  /**
1361
1376
  * Creates a slice operation.
1362
1377
  * Slices the entities of the given operations by the given reference.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buerli.io/headless",
3
- "version": "0.9.0",
3
+ "version": "0.9.1-beta.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",
@@ -32,7 +32,7 @@
32
32
  "three-stdlib": ">=2.11.0"
33
33
  },
34
34
  "dependencies": {
35
- "@buerli.io/classcad": "0.9.0",
35
+ "@buerli.io/classcad": "0.9.1-beta.0",
36
36
  "flat-promise": "^1.0.3"
37
37
  }
38
38
  }