@classcad/client 0.0.0-stage → 3.0.0-beta.20261119090857

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.
Files changed (108) hide show
  1. package/README.md +20 -2
  2. package/bin/buerli-classcad.cjs +23 -0
  3. package/build/cjs/BuerliCadFacade.js +718 -0
  4. package/build/cjs/cclass/utils/assembly.js +687 -0
  5. package/build/cjs/cclass/utils/base.js +136 -0
  6. package/build/cjs/cclass/utils/index.js +99 -0
  7. package/build/cjs/cclass/utils/part.js +153 -0
  8. package/build/cjs/classcadEngine.js +33 -0
  9. package/build/cjs/createApi.js +71 -0
  10. package/build/cjs/createUnwrappedApi.js +43 -0
  11. package/build/cjs/facade.js +103 -0
  12. package/build/cjs/globals.js +157 -0
  13. package/build/cjs/index.js +102 -0
  14. package/build/cjs/io/AwvNodeClient.js +290 -0
  15. package/build/cjs/io/SocketIOClient.js +339 -0
  16. package/build/cjs/io/Transaction.js +134 -0
  17. package/build/cjs/io/WASMClient.js +433 -0
  18. package/build/cjs/io/WSClient.js +646 -0
  19. package/build/cjs/io/engineKey.js +202 -0
  20. package/build/cjs/re-export.js +35 -0
  21. package/build/cjs/session/host.js +479 -0
  22. package/build/cjs/session/identity.js +38 -0
  23. package/build/cjs/session/selection.js +283 -0
  24. package/build/cjs/session/share.js +229 -0
  25. package/build/cjs/session/types.js +23 -0
  26. package/build/cjs/test/SocketIOClient.spec.js +178 -0
  27. package/build/cjs/types/ComClient.js +10 -0
  28. package/build/cjs/utils/createRecursiveBufferGeometry.js +55 -0
  29. package/build/cjs/utils/createRecursiveScene.js +140 -0
  30. package/build/cjs/utils/getDifferentColoredMeshesFromEntity.js +24 -0
  31. package/build/cjs/utils/index.js +20 -0
  32. package/build/cjs/utils/polyline.js +65 -0
  33. package/build/cjs/utils/waitForSelect.js +29 -0
  34. package/build/esm/BuerliCadFacade.js +714 -0
  35. package/build/esm/cclass/utils/assembly.js +665 -0
  36. package/build/esm/cclass/utils/base.js +127 -0
  37. package/build/esm/cclass/utils/index.js +62 -0
  38. package/build/esm/cclass/utils/part.js +144 -0
  39. package/build/esm/classcadEngine.js +30 -0
  40. package/build/esm/createApi.js +66 -0
  41. package/build/esm/createUnwrappedApi.js +39 -0
  42. package/build/esm/facade.js +98 -0
  43. package/build/esm/globals.js +150 -0
  44. package/build/esm/index.js +80 -0
  45. package/build/esm/io/AwvNodeClient.js +286 -0
  46. package/build/esm/io/SocketIOClient.js +332 -0
  47. package/build/esm/io/Transaction.js +130 -0
  48. package/build/esm/io/WASMClient.js +429 -0
  49. package/build/esm/io/WSClient.js +642 -0
  50. package/build/esm/io/engineKey.js +196 -0
  51. package/build/esm/re-export.js +3 -0
  52. package/build/esm/session/host.js +474 -0
  53. package/build/esm/session/identity.js +34 -0
  54. package/build/esm/session/selection.js +277 -0
  55. package/build/esm/session/share.js +221 -0
  56. package/build/esm/session/types.js +20 -0
  57. package/build/esm/test/SocketIOClient.spec.js +178 -0
  58. package/build/esm/types/ComClient.js +7 -0
  59. package/build/esm/utils/createRecursiveBufferGeometry.js +51 -0
  60. package/build/esm/utils/createRecursiveScene.js +136 -0
  61. package/build/esm/utils/getDifferentColoredMeshesFromEntity.js +20 -0
  62. package/build/esm/utils/index.js +4 -0
  63. package/build/esm/utils/polyline.js +60 -0
  64. package/build/esm/utils/waitForSelect.js +23 -0
  65. package/build/types/BuerliCadFacade.d.ts +410 -0
  66. package/build/types/cclass/utils/assembly.d.ts +180 -0
  67. package/build/types/cclass/utils/base.d.ts +55 -0
  68. package/build/types/cclass/utils/index.d.ts +46 -0
  69. package/build/types/cclass/utils/part.d.ts +46 -0
  70. package/build/types/classcadEngine.d.ts +40 -0
  71. package/build/types/createApi.d.ts +65 -0
  72. package/build/types/createUnwrappedApi.d.ts +36 -0
  73. package/build/types/facade.d.ts +9 -0
  74. package/build/types/globals.d.ts +79 -0
  75. package/build/types/index.d.ts +82 -0
  76. package/build/types/io/AwvNodeClient.d.ts +182 -0
  77. package/build/types/io/SocketIOClient.d.ts +84 -0
  78. package/build/types/io/Transaction.d.ts +56 -0
  79. package/build/types/io/WASMClient.d.ts +239 -0
  80. package/build/types/io/WSClient.d.ts +242 -0
  81. package/build/types/io/engineKey.d.ts +137 -0
  82. package/build/types/re-export.d.ts +6 -0
  83. package/build/types/session/host.d.ts +108 -0
  84. package/build/types/session/identity.d.ts +46 -0
  85. package/build/types/session/selection.d.ts +164 -0
  86. package/build/types/session/share.d.ts +131 -0
  87. package/build/types/session/types.d.ts +113 -0
  88. package/build/types/test/SocketIOClient.spec.d.ts +0 -0
  89. package/build/types/types/ComClient.d.ts +307 -0
  90. package/build/types/utils/createRecursiveBufferGeometry.d.ts +8 -0
  91. package/build/types/utils/createRecursiveScene.d.ts +24 -0
  92. package/build/types/utils/getDifferentColoredMeshesFromEntity.d.ts +14 -0
  93. package/build/types/utils/index.d.ts +4 -0
  94. package/build/types/utils/polyline.d.ts +43 -0
  95. package/build/types/utils/waitForSelect.d.ts +4 -0
  96. package/doc/api/advanced/connection.md +488 -0
  97. package/doc/api/clients.md +2045 -0
  98. package/doc/api/engine-keys.md +230 -0
  99. package/doc/api/index.md +58 -0
  100. package/doc/api/modeling.md +682 -0
  101. package/doc/api/other.md +33 -0
  102. package/doc/api/session-sharing.md +706 -0
  103. package/package.json +59 -4
  104. package/test/classcadEngine.test.cjs +44 -0
  105. package/test/connect.test.cjs +81 -0
  106. package/test/engineKey.test.cjs +80 -0
  107. package/test/onClient.test.cjs +82 -0
  108. package/typedoc.json +8 -0
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findObject = exports.getDescendants = exports.getAncestors = exports.getAncestorIdByClass = exports.getChildren = exports.isA = void 0;
4
+ const sdkjs_1 = require("@classcad/sdkjs");
5
+ const re_export_1 = require("../../re-export");
6
+ /**
7
+ * Checks if the given class is equal to the provided type or derives from it.
8
+ *
9
+ * @param objClass The class to check.
10
+ * @param type The type to be checked for.
11
+ * @returns true if objClass is of type or derived from type, false else.
12
+ */
13
+ const isA = (objClass, type) => {
14
+ if (objClass && type) {
15
+ if (objClass === type) {
16
+ return true;
17
+ }
18
+ const clazz = re_export_1.classMap[objClass];
19
+ if (clazz && clazz.superClasses) {
20
+ return clazz.superClasses.includes(type);
21
+ }
22
+ }
23
+ return false;
24
+ };
25
+ exports.isA = isA;
26
+ /**
27
+ * Gets all children of the given object with the provided type.
28
+ *
29
+ * @param objId The id of the object to get children from.
30
+ * @param type The type of children to search for.
31
+ * @param tree The structure tree.
32
+ * @returns An array of object ids of the found children.
33
+ */
34
+ const getChildren = (objId, type, tree) => {
35
+ var _a, _b;
36
+ return ((_b = (_a = tree[objId]) === null || _a === void 0 ? void 0 : _a.children) === null || _b === void 0 ? void 0 : _b.filter(c => (0, exports.isA)(tree[c].class, type))) || [];
37
+ };
38
+ exports.getChildren = getChildren;
39
+ /**
40
+ * Searches for an object's ancestor of specified class.
41
+ * @param drawingId The drawing id.
42
+ * @param objectId The id of the object to search for its ancestor.
43
+ * @param parentClass The CCClass of the ancestor to search for.
44
+ * @returns first found object of specified class.
45
+ */
46
+ const getAncestorIdByClass = (drawingId, objectId, parentClass) => {
47
+ var _a;
48
+ const tree = (0, sdkjs_1.getDrawing)(drawingId).structure.tree;
49
+ let object = tree[((_a = tree[objectId]) === null || _a === void 0 ? void 0 : _a.parent) || -1];
50
+ while (object && object.class !== parentClass) {
51
+ object = tree[object.parent || -1];
52
+ }
53
+ return (object === null || object === void 0 ? void 0 : object.id) || null;
54
+ };
55
+ exports.getAncestorIdByClass = getAncestorIdByClass;
56
+ /**
57
+ * Gets all ancestors of the given object.
58
+ * @param drawingId The drawing id.
59
+ * @param objectId The id of the object to get ancestors from.
60
+ * @returns an array of object's ancestors.
61
+ */
62
+ const getAncestors = (drawingId, objectId) => {
63
+ var _a, _b;
64
+ const tree = (0, sdkjs_1.getDrawing)(drawingId).structure.tree;
65
+ let curId = (_a = tree[objectId]) === null || _a === void 0 ? void 0 : _a.parent;
66
+ const ancestors = [];
67
+ while (curId) {
68
+ ancestors.push(curId);
69
+ curId = (_b = tree[curId]) === null || _b === void 0 ? void 0 : _b.parent;
70
+ }
71
+ return ancestors;
72
+ };
73
+ exports.getAncestors = getAncestors;
74
+ /**
75
+ * Gets all descendants of the given object.
76
+ * @param drawingId The drawing id.
77
+ * @param objectId The id of the object to get descendants from.
78
+ * @returns an array of object's descendants.
79
+ */
80
+ const getDescendants = (drawingId, objectId) => {
81
+ const object = (0, sdkjs_1.getDrawing)(drawingId).structure.tree[objectId];
82
+ const descendants = [];
83
+ (object === null || object === void 0 ? void 0 : object.children) &&
84
+ object.children.forEach(child => {
85
+ descendants.push(child, ...(0, exports.getDescendants)(drawingId, child));
86
+ });
87
+ return descendants;
88
+ };
89
+ exports.getDescendants = getDescendants;
90
+ /**
91
+ * Find first object which can be identified by given identifier or name.
92
+ * If both optional parameters has been set, the identifier is treated with priority.
93
+ * If no object with given identifier will be found, the name is used to find an object, if available.
94
+ * @param drawingId The drawing id.
95
+ * @param options Optional parameters to identify to find object.
96
+ * @param options.ident Identifier to find the object by an identifier
97
+ * @param options.name Name to find the object by its name
98
+ * @returns first found object which meets the searching conditions
99
+ */
100
+ const findObject = (drawingId, options) => {
101
+ const drw = (0, sdkjs_1.getDrawing)(drawingId);
102
+ const tree = drw.structure.tree;
103
+ if (!options.ident && !options.name) {
104
+ throw 'Neither an identifier nor a name has been set to find object';
105
+ }
106
+ if (options.ident) {
107
+ const instance = findObjectByIdent(drawingId, options.ident);
108
+ if (instance) {
109
+ return instance;
110
+ }
111
+ }
112
+ if (options.name) {
113
+ const result = drw.api.structure.findTree(tree, obj => obj.name === options.name);
114
+ return result ? result.id : undefined;
115
+ }
116
+ };
117
+ exports.findObject = findObject;
118
+ /**
119
+ * Helperfunction to find any object by identifier which
120
+ * can eventually be found in the ident map
121
+ *
122
+ * @param drawingId The drawing id.
123
+ * @param objectIdent Identification of the object to find
124
+ * @returns Id of the found object or undefined
125
+ */
126
+ const findObjectByIdent = (drawingId, objectIdent) => {
127
+ var _a;
128
+ const structure = (0, sdkjs_1.getDrawing)(drawingId).structure;
129
+ const [identMapId] = (0, exports.getChildren)(structure.root, re_export_1.CCClasses.IdentToIdMap, structure.tree);
130
+ const identMap = identMapId && structure.tree[identMapId];
131
+ if (identMap) {
132
+ const map = (_a = identMap.members) === null || _a === void 0 ? void 0 : _a.map;
133
+ const keyValuePair = map.members.find(mem => mem.members[0].value === objectIdent);
134
+ return keyValuePair && keyValuePair.members[1].value;
135
+ }
136
+ };
@@ -0,0 +1,99 @@
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 () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.ccUtils = exports.getMessageTypeForErrors = void 0;
37
+ const assembly = __importStar(require("./assembly"));
38
+ const base = __importStar(require("./base"));
39
+ const part = __importStar(require("./part"));
40
+ /**
41
+ * The message type (`'info'`, `'warning'`, `'error'`) for errors in the form older engines report them.
42
+ *
43
+ * @internal
44
+ */
45
+ const getMessageTypeForErrors = (errors) => {
46
+ let maxErrorState = 0;
47
+ errors.map(e => {
48
+ maxErrorState = Math.max(maxErrorState, e.errorState);
49
+ });
50
+ switch (maxErrorState) {
51
+ case 0:
52
+ return 'info';
53
+ case 1:
54
+ return 'warning';
55
+ case 2:
56
+ return 'warning';
57
+ case 3:
58
+ return 'error';
59
+ default:
60
+ return 'info';
61
+ }
62
+ };
63
+ exports.getMessageTypeForErrors = getMessageTypeForErrors;
64
+ /**
65
+ * Helpers that look things up in a drawing's structure tree: classes, ancestors, work geometry, sketches, constraints.
66
+ *
67
+ * They read the tree in the buerli store; none of them calls the engine.
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * import { ccUtils, ScgClassType } from '@classcad/client'
72
+ *
73
+ * // The part a picked solid belongs to, and that part's sketches
74
+ * const partId = ccUtils.base.getAncestorIdByClass(facade.drawingId, solidId, ScgClassType.CCPart)
75
+ * if (partId !== null) {
76
+ * const sketches = ccUtils.part.getSketch(facade.drawingId, partId)
77
+ * const tree = await facade.tree()
78
+ * console.log(tree[partId].name, sketches.map(id => tree[id].name))
79
+ * }
80
+ * ```
81
+ * @advanced
82
+ * @category Modeling
83
+ */
84
+ exports.ccUtils = {
85
+ /**
86
+ * Class checks and tree walks: `isA` (a class or one derived from it), `getChildren`, `getAncestors`,
87
+ * `getAncestorIdByClass`, `getDescendants`, `findObject` (by identifier or name).
88
+ */
89
+ base,
90
+ /**
91
+ * Assemblies: `findProduct` (of an instance), `getInstance`, `getPartTemplate`, `getAssemblyTemplate`,
92
+ * `getTransformation`, `getMatePath`, `getWorkGeometry`, and the constraints (`getConstraint`,
93
+ * `getFastenedConstraint`, `getRevoluteConstraint`, …).
94
+ */
95
+ assembly,
96
+ /** Parts: `getWorkGeometry`, `getSketch`, `getSketchRegion`, `getSketchlines`. */
97
+ part,
98
+ };
99
+ exports.default = exports.ccUtils;
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculateRollbackMovement = exports.getSketchlines = exports.getSketch = exports.getSketchRegion = exports.getWorkGeometry = exports.getWorkCoordSystem = void 0;
4
+ const sdkjs_1 = require("@classcad/sdkjs");
5
+ const re_export_1 = require("../../re-export");
6
+ const assembly_1 = require("./assembly");
7
+ const base_1 = require("./base");
8
+ /**
9
+ * Helperfunction to get objects like work geometry or sketch regions from given product references
10
+ *
11
+ * @param drawingId The drawing id.
12
+ * @param refId Product reference to look for the object
13
+ * @param type Type of the object to look for
14
+ * @param objectName name of the object to look for (optional)
15
+ * @returns Array containing all the found objects. The array is empty if nothing was found
16
+ */
17
+ const getObjectsfromProdRef = (drawingId, refId, type, objectName) => {
18
+ const drw = (0, sdkjs_1.getDrawing)(drawingId);
19
+ const tree = drw.structure.tree;
20
+ const productId = (0, assembly_1.findProduct)(refId, tree) || sdkjs_1.NOID;
21
+ const product = tree[productId];
22
+ const result = [];
23
+ if (product) {
24
+ // This is an inner helper function to collect the objects of given type.
25
+ const collectObjIds = (setId, _type) => {
26
+ const allObjIds = (0, base_1.getChildren)(setId, _type, tree);
27
+ if (!objectName) {
28
+ return allObjIds;
29
+ }
30
+ else {
31
+ return allObjIds.filter(w => { var _a; return objectName === ((_a = tree[w]) === null || _a === void 0 ? void 0 : _a.name); });
32
+ }
33
+ };
34
+ if ((0, base_1.isA)(product.class, re_export_1.CCClasses.CCPart)) {
35
+ const geometrySetId = (0, base_1.getChildren)(productId, re_export_1.CCClasses.CCGeometrySet, tree).pop() || sdkjs_1.NOID;
36
+ result.push(...collectObjIds(geometrySetId, type));
37
+ const sketchSetId = (0, base_1.getChildren)(productId, re_export_1.CCClasses.CCSketchSet, tree).pop() || sdkjs_1.NOID;
38
+ result.push(...collectObjIds(sketchSetId, type));
39
+ }
40
+ else {
41
+ const allProdRefIds = (0, base_1.getChildren)(refId, re_export_1.CCClasses.CCProductReferenceET, tree);
42
+ for (const prodRefId of allProdRefIds) {
43
+ const prod = (0, assembly_1.findProduct)(prodRefId, tree);
44
+ if (prod) {
45
+ const geometrySetId = (0, base_1.getChildren)(productId, re_export_1.CCClasses.CCGeometrySet, tree).pop() || sdkjs_1.NOID;
46
+ result.push(...collectObjIds(geometrySetId, type));
47
+ const sketchSetId = (0, base_1.getChildren)(productId, re_export_1.CCClasses.CCSketchSet, tree).pop() || sdkjs_1.NOID;
48
+ result.push(...collectObjIds(sketchSetId, type));
49
+ }
50
+ }
51
+ }
52
+ }
53
+ return result;
54
+ };
55
+ /**
56
+ * @deprecated use getWorkGeometry() instead, getWorkCoordSystem() will be removed in a future release.
57
+ *
58
+ * Returns all workcoordsystems of given reference with specified name.
59
+ * If _wcsName_ is undefined, all workcoordsystems of given reference will be returned.
60
+ *
61
+ * @param drawingId The drawing id.
62
+ * @param refId The product reference to look for wcs.
63
+ * @param wcsName The name of wcs to look for.
64
+ * @returns An array of ids of all workcoordsystems found. The array is empty if nothing was found.
65
+ */
66
+ const getWorkCoordSystem = (drawingId, refId, wcsName) => {
67
+ console.warn('getWorkCoordSystem() is deprecated and will be removed in a future release. Use getWorkGeometry() instead.');
68
+ return getObjectsfromProdRef(drawingId, refId, re_export_1.CCClasses.CCWorkCSys, wcsName);
69
+ };
70
+ exports.getWorkCoordSystem = getWorkCoordSystem;
71
+ /**
72
+ * Returns all work geometry of given type and given reference with specified name.
73
+ * If wgName is undefined, all work geometry of given reference will be returned.
74
+ *
75
+ * @param drawingId The drawing id.
76
+ * @param refId The product reference to look for work geometry.
77
+ * @param type The type of work geometry to look for
78
+ * @param wgName The name of work geometry to look for.
79
+ * @returns An array of ids of all found work geometry. The array is empty if nothing was found.
80
+ */
81
+ const getWorkGeometry = (drawingId, refId, type, wgName) => {
82
+ return getObjectsfromProdRef(drawingId, refId, type, wgName);
83
+ };
84
+ exports.getWorkGeometry = getWorkGeometry;
85
+ /**
86
+ * Returns all sketch regions of given reference with specified name.
87
+ * If sketchRegionName is undefined, all sketch regions of given reference will be returned.
88
+ *
89
+ * @param drawingId The drawing id.
90
+ * @param refId The product reference to look for sketch region.
91
+ * @param sketchRegionName The name of sketch region to look for.
92
+ * @returns An array of ids of all found sketch regions. The array is empty if nothing was found.
93
+ */
94
+ const getSketchRegion = (drawingId, refId, sketchRegionName) => {
95
+ return getObjectsfromProdRef(drawingId, refId, re_export_1.CCClasses.CCSketchRegion, sketchRegionName);
96
+ };
97
+ exports.getSketchRegion = getSketchRegion;
98
+ const getSketch = (drawingId, refId, sketchName) => {
99
+ return getObjectsfromProdRef(drawingId, refId, re_export_1.CCClasses.CCSketch, sketchName);
100
+ };
101
+ exports.getSketch = getSketch;
102
+ /**
103
+ * Returns all sketch lines from a sketch or sketch regions
104
+ * @param sketchOrRegionIds id of the sketch or ids of the sketch regions
105
+ * @returns the sketchlines as array or undefined if empty
106
+ */
107
+ const getSketchlines = (drawingId, sketchOrRegionIds) => {
108
+ var _a;
109
+ const cDrawing = (0, sdkjs_1.getDrawing)(drawingId);
110
+ const tree = cDrawing.structure.tree;
111
+ const sketchLines = [];
112
+ // if its an array, all ids must be of type sketch region
113
+ if (Array.isArray(sketchOrRegionIds)) {
114
+ sketchOrRegionIds.forEach(sRId => {
115
+ var _a;
116
+ const sketchRegion = tree[sRId];
117
+ if (sketchRegion && (0, base_1.isA)(sketchRegion.class, re_export_1.CCClasses.CCSketchRegion)) {
118
+ sketchLines.push(...((_a = sketchRegion.members) === null || _a === void 0 ? void 0 : _a.curves).members.map(mem => mem.value));
119
+ }
120
+ else {
121
+ throw new Error('Not all ids in the given array are of type sketch region');
122
+ }
123
+ });
124
+ // if not, it can be both, sketch or sketch region
125
+ }
126
+ else {
127
+ const sketchOrRegion = tree[sketchOrRegionIds];
128
+ // TODO: Which sketch lines need to be included, is CCClasses.CCCurve and its derivation enough?
129
+ if (sketchOrRegion && (0, base_1.isA)(sketchOrRegion.class, re_export_1.CCClasses.CCSketch)) {
130
+ sketchLines.push(...(0, base_1.getChildren)(sketchOrRegionIds, re_export_1.CCClasses.CCCurve, tree));
131
+ }
132
+ else if (sketchOrRegion && (0, base_1.isA)(sketchOrRegion.class, re_export_1.CCClasses.CCSketchRegion)) {
133
+ sketchLines.push(...((_a = sketchOrRegion.members) === null || _a === void 0 ? void 0 : _a.curves).members.map(mem => mem.value));
134
+ }
135
+ else {
136
+ throw new Error('The id used to get sketchlines from is not of type sketch or sketch region.');
137
+ }
138
+ }
139
+ return sketchLines.length > 0 ? sketchLines : undefined;
140
+ };
141
+ exports.getSketchlines = getSketchlines;
142
+ const calculateRollbackMovement = (oldIndex, newIndex, featureIds, offset = 4) => {
143
+ const index = newIndex < offset ? offset : newIndex;
144
+ // If the rollback bar moves downwards, the index has to be incremented by 1.
145
+ const inc = newIndex > oldIndex ? 1 : 0;
146
+ if (index >= featureIds.length - 1) {
147
+ return { moveTo: 'end', featureId: -1, index };
148
+ }
149
+ else {
150
+ return { moveTo: 'before', featureId: featureIds[index + inc], index };
151
+ }
152
+ };
153
+ exports.calculateRollbackMovement = calculateRollbackMovement;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.classcadEngine = void 0;
4
+ const api_js_1 = require("@classcad/api-js");
5
+ const url = `https://awvstatic.com/classcad/download/${api_js_1.CLASSCAD_VERSION_QUALITY}/${api_js_1.CLASSCAD_VERSION}`;
6
+ /**
7
+ * The ClassCAD engine this package is built against: its version, its quality, and where its bundle is.
8
+ *
9
+ * `@classcad/api-js`, the ClassCAD API this package calls, is generated by the ClassCAD engine, and carries the
10
+ * version and the quality of the bundle it belongs to. That bundle is the engine this version of buerli is made
11
+ * for: {@link WASMClient} loads its WebAssembly from `wasmUrl`, and a host that runs the engine behind a server
12
+ * ({@link WSClient}, {@link SocketIOClient}) installs the same version, from `url`. A beta of buerli is built
13
+ * against an `alpha` build, a stable release against a `release`.
14
+ *
15
+ * `npx @classcad/client info` prints the same (`--json` for the object).
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { classcadEngine } from '@classcad/client'
20
+ *
21
+ * console.log(`Built against ClassCAD ${classcadEngine.version} (${classcadEngine.quality}): ${classcadEngine.url}`)
22
+ * ```
23
+ *
24
+ * @category Clients
25
+ */
26
+ exports.classcadEngine = Object.freeze({
27
+ version: api_js_1.CLASSCAD_VERSION,
28
+ quality: api_js_1.CLASSCAD_VERSION_QUALITY,
29
+ url,
30
+ metadataUrl: `${url}/metadata.json`,
31
+ wasmUrl: `${url}/wasm`,
32
+ apiUrl: `${url}/js/classcad-api-js-${api_js_1.CLASSCAD_VERSION}.tgz`,
33
+ });
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createApi = exports.getApiFacade = void 0;
4
+ const api_js_1 = require("@classcad/api-js");
5
+ const facade_1 = require("./facade");
6
+ const cache = {};
7
+ /**
8
+ * The low-level facade a drawing's API calls go through: one ClassCAD function, called by its name.
9
+ *
10
+ * `callSafeApiV(version, namespace, func, args, options)` runs `<version>.<namespace>.<func>` and resolves to the
11
+ * engine's reply, `{ result, messages, maxLevel }`; `callSafeApi` takes the namespace with its version
12
+ * (`'v1.part'`). `fetchTree` loads the structure tree anew, `callUnsafeApi` sends a command as it is. Replies are
13
+ * handled as in {@link createApi}. Use it for a function the typed API does not have, or one picked at runtime.
14
+ *
15
+ * @param drawingId - The drawing whose client the calls go to.
16
+ * @example
17
+ * ```ts
18
+ * import { getApiFacade } from '@classcad/client'
19
+ *
20
+ * // A call named at runtime, e.g. by a script or a tool an AI agent calls
21
+ * async function call(name: string, args: Record<string, unknown>) {
22
+ * const [namespace, func] = name.split('.') // 'part.box'
23
+ * const { result, messages } = await getApiFacade(drawingId).callSafeApiV('v1', namespace, func, args)
24
+ * return { result, messages }
25
+ * }
26
+ *
27
+ * const { result: part } = await call('part.create', { name: 'Part' })
28
+ * await call('part.box', { id: part, length: 50 })
29
+ * ```
30
+ * @advanced
31
+ * @category Modeling
32
+ */
33
+ const getApiFacade = (drawingId) => (0, facade_1.facade)(drawingId);
34
+ exports.getApiFacade = getApiFacade;
35
+ /**
36
+ * The ClassCAD API of a drawing; every call resolves to the engine's reply, `{ result, messages, maxLevel }`.
37
+ *
38
+ * `v1` holds the namespaces (`part`, `sketch`, `assembly`, `solid`, `curve`, `common`, `drawing2d`); they are also
39
+ * on the object itself, so `createApi(id).part` is `createApi(id).v1.part`. A call rejects when the reply carries an
40
+ * error, with that reply, and when the drawing has no client. Warnings and errors are logged and shown as messages
41
+ * of the drawing. `v0`, the old API, is deprecated. {@link createUnwrappedApi} gives the results without the reply
42
+ * around them.
43
+ *
44
+ * @param drawingId - A drawing that is connected, for example by {@link BuerliCadFacade.connect}.
45
+ * @param cached - `true` (default) returns the same object for the drawing on every call, `false` makes a new one.
46
+ * @example
47
+ * ```ts
48
+ * import { BuerliCadFacade, createApi, MessageLevel } from '@classcad/client'
49
+ *
50
+ * const drawingId = await BuerliCadFacade.utils.connect('Bracket')
51
+ * if (drawingId) {
52
+ * const api = createApi(drawingId)
53
+ * const part = (await api.v1.part.create({ name: 'Bracket' })).result!
54
+ * // The reply carries the engine's messages; a warning does not reject
55
+ * const { messages } = await api.v1.part.box({ id: part, length: 80, width: 40, height: 5 })
56
+ * const warnings = messages?.filter(m => m.level === MessageLevel.warning) ?? []
57
+ * if (warnings.length) console.warn(warnings.map(m => m.message))
58
+ * }
59
+ * ```
60
+ * @advanced
61
+ * @category Modeling
62
+ */
63
+ const createApi = (drawingId, cached = true) => {
64
+ const f = (0, exports.getApiFacade)(drawingId);
65
+ if (cached) {
66
+ cache[drawingId] = cache[drawingId] || Object.assign({ v0: (0, api_js_1.v0)(f), v1: (0, api_js_1.v1)(f) }, (0, api_js_1.v1)(f));
67
+ return cache[drawingId];
68
+ }
69
+ return Object.assign({ v0: (0, api_js_1.v0)(f), v1: (0, api_js_1.v1)(f) }, (0, api_js_1.v1)(f));
70
+ };
71
+ exports.createApi = createApi;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createUnwrappedApi = void 0;
4
+ const api_js_1 = require("@classcad/api-js");
5
+ const createApi_1 = require("./createApi");
6
+ const cache = {};
7
+ /**
8
+ * The ClassCAD API of a drawing, unwrapped: calls resolve to their result and reject on an engine error.
9
+ *
10
+ * The same namespaces as {@link createApi} (`v1.part`, `v1.sketch`, …, also on the object itself); this is what
11
+ * {@link BuerliCadFacade.api} is. A rejection carries the engine's reply (`{ result, messages, maxLevel }`).
12
+ * Warnings are logged and shown as messages of the drawing.
13
+ *
14
+ * @param drawingId - A drawing that is connected, for example by {@link BuerliCadFacade.connect}.
15
+ * @param cached - `true` (default) returns the same object for the drawing on every call, `false` makes a new one.
16
+ * @example
17
+ * ```ts
18
+ * import { BuerliCadFacade, createUnwrappedApi } from '@classcad/client'
19
+ *
20
+ * const drawingId = await BuerliCadFacade.utils.connect('Plate')
21
+ * if (drawingId) {
22
+ * const api = createUnwrappedApi(drawingId)
23
+ * try {
24
+ * const part = (await api.v1.part.create({ name: 'Plate' }))!
25
+ * await api.v1.part.box({ id: part, length: 200, width: 100, height: 8 })
26
+ * } catch (reply) {
27
+ * // The engine's reply, with the error in its messages
28
+ * console.error(reply)
29
+ * }
30
+ * }
31
+ * ```
32
+ * @advanced
33
+ * @category Modeling
34
+ */
35
+ const createUnwrappedApi = (drawingId, cached = true) => {
36
+ const f = (0, createApi_1.getApiFacade)(drawingId);
37
+ if (cached) {
38
+ cache[drawingId] = cache[drawingId] || Object.assign({ v0: (0, api_js_1.v0)(f), v1: (0, api_js_1.v1Unwrap)(f) }, (0, api_js_1.v1Unwrap)(f));
39
+ return cache[drawingId];
40
+ }
41
+ return Object.assign({ v0: (0, api_js_1.v0)(f), v1: (0, api_js_1.v1Unwrap)(f) }, (0, api_js_1.v1Unwrap)(f));
42
+ };
43
+ exports.createUnwrappedApi = createUnwrappedApi;
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.facade = exports.__callAPI = void 0;
4
+ const sdkjs_1 = require("@classcad/sdkjs");
5
+ const api_js_1 = require("@classcad/api-js");
6
+ const globals_1 = require("./globals");
7
+ const __callAPI = async (drawingId, task, options) => {
8
+ const comClient = globals_1.Globals.clientCache[drawingId];
9
+ if (!comClient) {
10
+ throw new Error('API call not possible, ClassCAD is not connected.');
11
+ }
12
+ const drawing = (0, sdkjs_1.getDrawing)(drawingId);
13
+ if (!drawing) {
14
+ throw new Error('API call not possible, buerli drawing does not exist.');
15
+ }
16
+ const usedSolidsBefore = drawing.api.structure.collectUsedSolidIds();
17
+ const streamMap = options === null || options === void 0 ? void 0 : options.streamMap;
18
+ options === null || options === void 0 ? true : delete options.streamMap;
19
+ const handleClassCadMessages = (fr) => {
20
+ var _a;
21
+ const errors = (_a = fr.messages) === null || _a === void 0 ? void 0 : _a.filter(m => m.level >= api_js_1.MessageLevel.warning);
22
+ if (errors && errors.length > 0) {
23
+ const toBuerliMessageType = (level) => {
24
+ switch (level) {
25
+ case api_js_1.MessageLevel.error:
26
+ case api_js_1.MessageLevel.fatal:
27
+ return 'error';
28
+ default:
29
+ return 'warning';
30
+ }
31
+ };
32
+ for (const e of errors) {
33
+ if (e.level === api_js_1.MessageLevel.warning) {
34
+ console.warn(`ClassCAD API Warning${e.api ? ` | ${e.api}` : ''} | ${e.message}`);
35
+ }
36
+ else {
37
+ console.error(`ClassCAD API Error${e.api ? ` | ${e.api}` : ''} | ${e.message}`);
38
+ }
39
+ const msg = { title: e.api, type: toBuerliMessageType(e.level), text: e.message, code: e.code, drawingId };
40
+ // It needs a timeout here to give the ui a bit of time to display each message
41
+ setTimeout(async () => (0, sdkjs_1.showMessage)(msg), 0); // TODO: there must be better ways than timeouts
42
+ }
43
+ }
44
+ };
45
+ try {
46
+ const fr = {};
47
+ const resp = await comClient.executeRequest(task, streamMap, options);
48
+ fr.result = resp.result;
49
+ fr.messages = resp.messages;
50
+ fr.maxLevel = resp.maxLevel;
51
+ if (resp.streamData) {
52
+ fr.streamData = resp.streamData;
53
+ }
54
+ handleClassCadMessages(fr);
55
+ return fr;
56
+ }
57
+ catch (err) {
58
+ const fr = err;
59
+ delete fr.streamData;
60
+ handleClassCadMessages(fr);
61
+ throw err;
62
+ }
63
+ finally {
64
+ const usedSolidsAfter = drawing.api.structure.collectUsedSolidIds();
65
+ // 2. cleanup data, only do this if the used solids did change
66
+ // TODO: Is there a better way to compare arrays?
67
+ if (usedSolidsBefore.sort().join() !== usedSolidsAfter.sort().join()) {
68
+ // TODO: When is the correct time to cleanup the graphic data
69
+ drawing.api.graphic.cleanupGraphicRecords();
70
+ }
71
+ // console.log('graphicContainers after command:', Object.getOwnPropertyNames(get().graphic.containers))
72
+ // console.log('geometryCache after command:', Object.getOwnPropertyNames(get().geometry.cache))
73
+ }
74
+ };
75
+ exports.__callAPI = __callAPI;
76
+ const facade = (drawingId) => {
77
+ return {
78
+ callSafeApi: async (namespace, func, args, options) => {
79
+ let id;
80
+ try {
81
+ const command = [{ [`${namespace}.${func}`]: args ? (Array.isArray(args) ? args : [args]) : [] }];
82
+ const promise = (0, exports.__callAPI)(drawingId, command, options);
83
+ id = (0, sdkjs_1.getDrawing)(drawingId).api.cad.addPending(`${namespace}.${func}`, { args, promise });
84
+ return (await promise); // TODO
85
+ }
86
+ finally {
87
+ id && (0, sdkjs_1.getDrawing)(drawingId).api.cad.removePending(id);
88
+ }
89
+ },
90
+ callSafeApiV: async (version, namespace, func, args, options) => {
91
+ const p = typeof args === 'undefined' || version === 'v0' ? args : [args]; // TODO: is this the correct place to do this?
92
+ return (0, exports.facade)(drawingId).callSafeApi(`${version}.${namespace}`, func, p, options);
93
+ },
94
+ callUnsafeApi: async (command) => {
95
+ return (0, exports.__callAPI)(drawingId, command);
96
+ },
97
+ fetchTree: async () => {
98
+ const comClient = globals_1.Globals.clientCache[drawingId];
99
+ await comClient.requestTree();
100
+ },
101
+ };
102
+ };
103
+ exports.facade = facade;