@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,687 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMatePath = exports.getTransformation = exports.getInstance = exports.getAssemblyTemplate = exports.getPartTemplate = exports.getWorkGeometry = exports.getWorkCoordSystem = exports.getCircularPatternConstraint = exports.getLinearPatternConstraint = exports.getGroupConstraint = exports.getCylindricalConstraint = exports.getParallelConstraint = exports.getPlanarConstraint = exports.getSliderConstraint = exports.getRevoluteConstraint = exports.getFastenedOriginConstraint = exports.getFastenedConstraint = exports.getConstraint = exports.findProduct = void 0;
4
+ const sdkjs_1 = require("@classcad/sdkjs");
5
+ const three_1 = require("three");
6
+ const re_export_1 = require("../../re-export");
7
+ const base_1 = require("./base");
8
+ const part_1 = require("./part");
9
+ /**
10
+ * Finds the product of given reference in the structure tree
11
+ *
12
+ * @param refOrRefEtId The reference id or referenceET id.
13
+ * @param tree The structure tree.
14
+ * @returns The resolved product for the provided reference _refOrRefEtId_. If no product was found, _undefined_ is returned.
15
+ */
16
+ const findProduct = (refOrRefEtId, tree) => {
17
+ var _a, _b, _c, _d;
18
+ const refObj = tree[refOrRefEtId];
19
+ const isProd = (0, base_1.isA)(refObj === null || refObj === void 0 ? void 0 : refObj.class, re_export_1.CCClasses.CCProduct);
20
+ let product = undefined;
21
+ if (isProd) {
22
+ product = refObj === null || refObj === void 0 ? void 0 : refObj.id;
23
+ }
24
+ else {
25
+ let refId = refObj === null || refObj === void 0 ? void 0 : refObj.id;
26
+ const isRefEt = (0, base_1.isA)(refObj === null || refObj === void 0 ? void 0 : refObj.class, re_export_1.CCClasses.CCProductReferenceET);
27
+ if (isRefEt) {
28
+ refId = ((_b = (_a = refObj === null || refObj === void 0 ? void 0 : refObj.members) === null || _a === void 0 ? void 0 : _a.productRef) === null || _b === void 0 ? void 0 : _b.value) || refId;
29
+ }
30
+ const obj = tree[refId];
31
+ product = (_d = (_c = obj === null || obj === void 0 ? void 0 : obj.members) === null || _c === void 0 ? void 0 : _c.productId) === null || _d === void 0 ? void 0 : _d.value;
32
+ }
33
+ return product;
34
+ };
35
+ exports.findProduct = findProduct;
36
+ /**
37
+ * @deprecated use specific methods e.g. getFastenedConstraint() instead, getConstraint() will be removed in a future release.
38
+ *
39
+ * Returns the fastened or fastened origin constraint of given reference with specified name.
40
+ *
41
+ * @param drawingId The drawing id.
42
+ * @param refId The product reference to look for constraint.
43
+ * @param constrName The name of constraint to look for.
44
+ * @returns The constraint information as array. The array is empty if no constraint was found.
45
+ */
46
+ const getConstraint = (drawingId, refId, constrName) => {
47
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
48
+ console.warn('getConstraint() is deprecated and will be removed in a future release. Use specific methods e.g. getFastenedConstraint() instead.');
49
+ if (!constrName) {
50
+ return [];
51
+ }
52
+ const drw = (0, sdkjs_1.getDrawing)(drawingId);
53
+ const tree = drw.structure.tree;
54
+ const productId = (0, exports.findProduct)(refId, tree) || sdkjs_1.NOID;
55
+ const product = tree[productId];
56
+ if (product) {
57
+ const constrSetId = (0, base_1.getChildren)(productId, re_export_1.CCClasses.CCConstraintSet, tree).pop();
58
+ if (!constrSetId)
59
+ return [];
60
+ const allConstrIds = (0, base_1.getChildren)(constrSetId, re_export_1.CCClasses.CCHLConstraint, tree);
61
+ const constrId = allConstrIds.filter(c => { var _a; return ((_a = tree[c]) === null || _a === void 0 ? void 0 : _a.name) === constrName; }).pop();
62
+ if (!constrId)
63
+ return [];
64
+ const constr = tree[constrId];
65
+ if (!constr)
66
+ return [];
67
+ const firstRefMate = (_a = constr === null || constr === void 0 ? void 0 : constr.members) === null || _a === void 0 ? void 0 : _a.firstRefMate;
68
+ const secondRefMate = (_b = constr === null || constr === void 0 ? void 0 : constr.members) === null || _b === void 0 ? void 0 : _b.secondRefMate;
69
+ const xOffset = (_c = constr === null || constr === void 0 ? void 0 : constr.members) === null || _c === void 0 ? void 0 : _c.xOffset;
70
+ const yOffset = (_d = constr === null || constr === void 0 ? void 0 : constr.members) === null || _d === void 0 ? void 0 : _d.yOffset;
71
+ const zOffset = (_e = constr === null || constr === void 0 ? void 0 : constr.members) === null || _e === void 0 ? void 0 : _e.zOffset;
72
+ const first = [
73
+ (_g = (_f = firstRefMate.members[0]) === null || _f === void 0 ? void 0 : _f.members) === null || _g === void 0 ? void 0 : _g.map(m => m.value),
74
+ (_h = firstRefMate.members[1]) === null || _h === void 0 ? void 0 : _h.value,
75
+ (_j = firstRefMate.members[2]) === null || _j === void 0 ? void 0 : _j.value,
76
+ (_k = firstRefMate.members[3]) === null || _k === void 0 ? void 0 : _k.value,
77
+ ];
78
+ let second = [];
79
+ if (!(0, base_1.isA)(constr.class, re_export_1.CCClasses.CCFastenedOriginConstraint)) {
80
+ second = [
81
+ (_m = (_l = secondRefMate.members[0]) === null || _l === void 0 ? void 0 : _l.members) === null || _m === void 0 ? void 0 : _m.map(m => m.value),
82
+ (_o = secondRefMate.members[1]) === null || _o === void 0 ? void 0 : _o.value,
83
+ (_p = secondRefMate.members[2]) === null || _p === void 0 ? void 0 : _p.value,
84
+ (_q = secondRefMate.members[3]) === null || _q === void 0 ? void 0 : _q.value,
85
+ ];
86
+ }
87
+ return [constr === null || constr === void 0 ? void 0 : constr.id, first, second, xOffset === null || xOffset === void 0 ? void 0 : xOffset.value, yOffset === null || yOffset === void 0 ? void 0 : yOffset.value, zOffset === null || zOffset === void 0 ? void 0 : zOffset.value];
88
+ }
89
+ return [];
90
+ };
91
+ exports.getConstraint = getConstraint;
92
+ /**
93
+ * Returns the fastened constraint of given reference with specified name.
94
+ *
95
+ * @param drawingId The drawing id.
96
+ * @param refId The product reference to look for constraint.
97
+ * @param constrName The name of constraint to look for.
98
+ * @returns The found fastened constraint as object or undefined if nothing has been found
99
+ */
100
+ const getFastenedConstraint = (drawingId, refId, constrName) => {
101
+ var _a, _b, _c, _d, _e, _f;
102
+ if (!constrName) {
103
+ return undefined;
104
+ }
105
+ const constr = getConstraintFromTree(drawingId, refId, constrName);
106
+ if (constr && (0, base_1.isA)(constr.class, re_export_1.CCClasses.CCFastenedConstraint)) {
107
+ const first = getRefMate(constr, 'first');
108
+ const second = getRefMate(constr, 'second');
109
+ const xOffset = (_a = constr === null || constr === void 0 ? void 0 : constr.members) === null || _a === void 0 ? void 0 : _a.xOffset;
110
+ const yOffset = (_b = constr === null || constr === void 0 ? void 0 : constr.members) === null || _b === void 0 ? void 0 : _b.yOffset;
111
+ const zOffset = (_c = constr === null || constr === void 0 ? void 0 : constr.members) === null || _c === void 0 ? void 0 : _c.zOffset;
112
+ const xRotation = (_d = constr === null || constr === void 0 ? void 0 : constr.members) === null || _d === void 0 ? void 0 : _d.xRotation;
113
+ const yRotation = (_e = constr === null || constr === void 0 ? void 0 : constr.members) === null || _e === void 0 ? void 0 : _e.yRotation;
114
+ const zRotation = (_f = constr === null || constr === void 0 ? void 0 : constr.members) === null || _f === void 0 ? void 0 : _f.zRotation;
115
+ return {
116
+ constrId: constr.id,
117
+ mate1: first,
118
+ mate2: second,
119
+ xOffset: { value: xOffset.value, isExpr: xOffset.expression !== '' },
120
+ yOffset: { value: yOffset.value, isExpr: yOffset.expression !== '' },
121
+ zOffset: { value: zOffset.value, isExpr: zOffset.expression !== '' },
122
+ xRotation: { value: xRotation.value, isExpr: xRotation.expression !== '' },
123
+ yRotation: { value: yRotation.value, isExpr: yRotation.expression !== '' },
124
+ zRotation: { value: zRotation.value, isExpr: zRotation.expression !== '' },
125
+ };
126
+ }
127
+ return undefined;
128
+ };
129
+ exports.getFastenedConstraint = getFastenedConstraint;
130
+ /**
131
+ * Returns the fastened origin constraint of given reference with specified name.
132
+ *
133
+ * @param drawingId The drawing id.
134
+ * @param refId The product reference to look for constraint.
135
+ * @param constrName The name of constraint to look for.
136
+ * @returns The found fastened origin constraint as object or undefined if nothing has been found
137
+ */
138
+ const getFastenedOriginConstraint = (drawingId, refId, constrName) => {
139
+ var _a, _b, _c, _d, _e, _f;
140
+ if (!constrName) {
141
+ return undefined;
142
+ }
143
+ const constr = getConstraintFromTree(drawingId, refId, constrName);
144
+ if (constr && (0, base_1.isA)(constr.class, re_export_1.CCClasses.CCFastenedOriginConstraint)) {
145
+ const first = getRefMate(constr, 'first');
146
+ const xOffset = (_a = constr === null || constr === void 0 ? void 0 : constr.members) === null || _a === void 0 ? void 0 : _a.xOffset;
147
+ const yOffset = (_b = constr === null || constr === void 0 ? void 0 : constr.members) === null || _b === void 0 ? void 0 : _b.yOffset;
148
+ const zOffset = (_c = constr === null || constr === void 0 ? void 0 : constr.members) === null || _c === void 0 ? void 0 : _c.zOffset;
149
+ const xRotation = (_d = constr === null || constr === void 0 ? void 0 : constr.members) === null || _d === void 0 ? void 0 : _d.xRotation;
150
+ const yRotation = (_e = constr === null || constr === void 0 ? void 0 : constr.members) === null || _e === void 0 ? void 0 : _e.yRotation;
151
+ const zRotation = (_f = constr === null || constr === void 0 ? void 0 : constr.members) === null || _f === void 0 ? void 0 : _f.zRotation;
152
+ return {
153
+ constrId: constr.id,
154
+ mate1: first,
155
+ xOffset: { value: xOffset.value, isExpr: xOffset.expression !== '' },
156
+ yOffset: { value: yOffset.value, isExpr: yOffset.expression !== '' },
157
+ zOffset: { value: zOffset.value, isExpr: zOffset.expression !== '' },
158
+ xRotation: { value: xRotation.value, isExpr: xRotation.expression !== '' },
159
+ yRotation: { value: yRotation.value, isExpr: yRotation.expression !== '' },
160
+ zRotation: { value: zRotation.value, isExpr: zRotation.expression !== '' },
161
+ };
162
+ }
163
+ return undefined;
164
+ };
165
+ exports.getFastenedOriginConstraint = getFastenedOriginConstraint;
166
+ /**
167
+ * Returns the revolute constraint of given reference with specified name.
168
+ *
169
+ * @param drawingId The drawing id.
170
+ * @param refId The product reference to look for constraint.
171
+ * @param constrName The name of constraint to look for.
172
+ * @returns The found revolute constraint as object or undefined if nothing has been found
173
+ */
174
+ const getRevoluteConstraint = (drawingId, refId, constrName) => {
175
+ var _a, _b;
176
+ if (!constrName) {
177
+ return undefined;
178
+ }
179
+ const constr = getConstraintFromTree(drawingId, refId, constrName);
180
+ if (constr && (0, base_1.isA)(constr.class, re_export_1.CCClasses.CCRevoluteConstraint)) {
181
+ const first = getRefMate(constr, 'first');
182
+ const second = getRefMate(constr, 'second');
183
+ const zOffset = (_a = constr === null || constr === void 0 ? void 0 : constr.members) === null || _a === void 0 ? void 0 : _a.zOffset;
184
+ const zRotationLimits = (_b = constr === null || constr === void 0 ? void 0 : constr.members) === null || _b === void 0 ? void 0 : _b.zRotationLimits;
185
+ const zRotationMin = zRotationLimits === null || zRotationLimits === void 0 ? void 0 : zRotationLimits.members[0];
186
+ const zRotationMax = zRotationLimits === null || zRotationLimits === void 0 ? void 0 : zRotationLimits.members[1];
187
+ return {
188
+ constrId: constr.id,
189
+ mate1: first,
190
+ mate2: second,
191
+ zOffset: { value: zOffset.value, isExpr: zOffset.expression !== '' },
192
+ zRotationLimits: {
193
+ min: { value: zRotationMin.value, isExpr: zRotationMin.expression !== '' },
194
+ max: { value: zRotationMax.value, isExpr: zRotationMax.expression !== '' },
195
+ },
196
+ };
197
+ }
198
+ return undefined;
199
+ };
200
+ exports.getRevoluteConstraint = getRevoluteConstraint;
201
+ /**
202
+ * Returns the slider constraint of given reference with specified name.
203
+ *
204
+ * @param drawingId The drawing id.
205
+ * @param refId The product reference to look for constraint.
206
+ * @param constrName The name of constraint to look for.
207
+ * @returns The found slider constraint as object or undefined if nothing has been found
208
+ */
209
+ const getSliderConstraint = (drawingId, refId, constrName) => {
210
+ var _a, _b, _c;
211
+ if (!constrName) {
212
+ return undefined;
213
+ }
214
+ const constr = getConstraintFromTree(drawingId, refId, constrName);
215
+ if (constr && (0, base_1.isA)(constr.class, re_export_1.CCClasses.CCSliderConstraint)) {
216
+ const first = getRefMate(constr, 'first');
217
+ const second = getRefMate(constr, 'second');
218
+ const xOffset = (_a = constr === null || constr === void 0 ? void 0 : constr.members) === null || _a === void 0 ? void 0 : _a.xOffset;
219
+ const yOffset = (_b = constr === null || constr === void 0 ? void 0 : constr.members) === null || _b === void 0 ? void 0 : _b.yOffset;
220
+ const zOffsetLimits = (_c = constr === null || constr === void 0 ? void 0 : constr.members) === null || _c === void 0 ? void 0 : _c.zOffsetLimits;
221
+ const zOffsetMin = zOffsetLimits === null || zOffsetLimits === void 0 ? void 0 : zOffsetLimits.members[0];
222
+ const zOffsetMax = zOffsetLimits === null || zOffsetLimits === void 0 ? void 0 : zOffsetLimits.members[1];
223
+ return {
224
+ constrId: constr.id,
225
+ mate1: first,
226
+ mate2: second,
227
+ xOffset: { value: xOffset.value, isExpr: xOffset.expression !== '' },
228
+ yOffset: { value: yOffset.value, isExpr: yOffset.expression !== '' },
229
+ zOffsetLimits: {
230
+ min: { value: zOffsetMin.value, isExpr: zOffsetMin.expression !== '' },
231
+ max: { value: zOffsetMax.value, isExpr: zOffsetMax.expression !== '' },
232
+ },
233
+ };
234
+ }
235
+ return undefined;
236
+ };
237
+ exports.getSliderConstraint = getSliderConstraint;
238
+ /**
239
+ * Returns the planar constraint of given reference with specified name.
240
+ *
241
+ * @param drawingId The drawing id.
242
+ * @param refId The product reference to look for constraint.
243
+ * @param constrName The name of constraint to look for.
244
+ * @returns The found planar constraint as object or undefined if nothing has been found
245
+ */
246
+ const getPlanarConstraint = (drawingId, refId, constrName) => {
247
+ var _a, _b, _c, _d;
248
+ if (!constrName) {
249
+ return undefined;
250
+ }
251
+ const constr = getConstraintFromTree(drawingId, refId, constrName);
252
+ if (constr && (0, base_1.isA)(constr.class, re_export_1.CCClasses.CCPlanarConstraint)) {
253
+ const first = getRefMate(constr, 'first');
254
+ const second = getRefMate(constr, 'second');
255
+ const zOffset = (_a = constr === null || constr === void 0 ? void 0 : constr.members) === null || _a === void 0 ? void 0 : _a.zOffset;
256
+ const xOffsetLimits = (_b = constr === null || constr === void 0 ? void 0 : constr.members) === null || _b === void 0 ? void 0 : _b.xOffsetLimits;
257
+ const xOffsetMin = xOffsetLimits === null || xOffsetLimits === void 0 ? void 0 : xOffsetLimits.members[0];
258
+ const xOffsetMax = xOffsetLimits === null || xOffsetLimits === void 0 ? void 0 : xOffsetLimits.members[1];
259
+ const yOffsetLimits = (_c = constr === null || constr === void 0 ? void 0 : constr.members) === null || _c === void 0 ? void 0 : _c.yOffsetLimits;
260
+ const yOffsetMin = yOffsetLimits === null || yOffsetLimits === void 0 ? void 0 : yOffsetLimits.members[0];
261
+ const yOffsetMax = yOffsetLimits === null || yOffsetLimits === void 0 ? void 0 : yOffsetLimits.members[1];
262
+ const zRotationLimits = (_d = constr === null || constr === void 0 ? void 0 : constr.members) === null || _d === void 0 ? void 0 : _d.zRotationLimits;
263
+ const zRotationMin = zRotationLimits === null || zRotationLimits === void 0 ? void 0 : zRotationLimits.members[0];
264
+ const zRotationMax = zRotationLimits === null || zRotationLimits === void 0 ? void 0 : zRotationLimits.members[1];
265
+ return {
266
+ constrId: constr.id,
267
+ mate1: first,
268
+ mate2: second,
269
+ zOffset: { value: zOffset.value, isExpr: zOffset.expression !== '' },
270
+ xOffsetLimits: {
271
+ min: { value: xOffsetMin.value, isExpr: xOffsetMin.expression !== '' },
272
+ max: { value: xOffsetMax.value, isExpr: xOffsetMax.expression !== '' },
273
+ },
274
+ yOffsetLimits: {
275
+ min: { value: yOffsetMin.value, isExpr: yOffsetMin.expression !== '' },
276
+ max: { value: yOffsetMax.value, isExpr: yOffsetMax.expression !== '' },
277
+ },
278
+ zRotationLimits: {
279
+ min: { value: zRotationMin.value, isExpr: zRotationMin.expression !== '' },
280
+ max: { value: zRotationMax.value, isExpr: zRotationMax.expression !== '' },
281
+ },
282
+ };
283
+ }
284
+ return undefined;
285
+ };
286
+ exports.getPlanarConstraint = getPlanarConstraint;
287
+ /**
288
+ * Returns the parallel constraint of given reference with specified name.
289
+ *
290
+ * @param drawingId The drawing id.
291
+ * @param refId The product reference to look for constraint.
292
+ * @param constrName The name of constraint to look for.
293
+ * @returns The found parallel constraint as object or undefined if nothing has been found
294
+ */
295
+ const getParallelConstraint = (drawingId, refId, constrName) => {
296
+ var _a, _b, _c, _d;
297
+ if (!constrName) {
298
+ return undefined;
299
+ }
300
+ const constr = getConstraintFromTree(drawingId, refId, constrName);
301
+ if (constr && (0, base_1.isA)(constr.class, re_export_1.CCClasses.CCParallelConstraint)) {
302
+ const first = getRefMate(constr, 'first');
303
+ const second = getRefMate(constr, 'second');
304
+ const xOffsetLimits = (_a = constr === null || constr === void 0 ? void 0 : constr.members) === null || _a === void 0 ? void 0 : _a.xOffsetLimits;
305
+ const xOffsetMin = xOffsetLimits === null || xOffsetLimits === void 0 ? void 0 : xOffsetLimits.members[0];
306
+ const xOffsetMax = xOffsetLimits === null || xOffsetLimits === void 0 ? void 0 : xOffsetLimits.members[1];
307
+ const yOffsetLimits = (_b = constr === null || constr === void 0 ? void 0 : constr.members) === null || _b === void 0 ? void 0 : _b.yOffsetLimits;
308
+ const yOffsetMin = yOffsetLimits === null || yOffsetLimits === void 0 ? void 0 : yOffsetLimits.members[0];
309
+ const yOffsetMax = yOffsetLimits === null || yOffsetLimits === void 0 ? void 0 : yOffsetLimits.members[1];
310
+ const zOffsetLimits = (_c = constr === null || constr === void 0 ? void 0 : constr.members) === null || _c === void 0 ? void 0 : _c.zOffsetLimits;
311
+ const zOffsetMin = zOffsetLimits === null || zOffsetLimits === void 0 ? void 0 : zOffsetLimits.members[0];
312
+ const zOffsetMax = zOffsetLimits === null || zOffsetLimits === void 0 ? void 0 : zOffsetLimits.members[1];
313
+ const zRotationLimits = (_d = constr === null || constr === void 0 ? void 0 : constr.members) === null || _d === void 0 ? void 0 : _d.zRotationLimits;
314
+ const zRotationMin = zRotationLimits === null || zRotationLimits === void 0 ? void 0 : zRotationLimits.members[0];
315
+ const zRotationMax = zRotationLimits === null || zRotationLimits === void 0 ? void 0 : zRotationLimits.members[1];
316
+ return {
317
+ constrId: constr.id,
318
+ mate1: first,
319
+ mate2: second,
320
+ xOffsetLimits: {
321
+ min: { value: xOffsetMin.value, isExpr: xOffsetMin.expression !== '' },
322
+ max: { value: xOffsetMax.value, isExpr: xOffsetMax.expression !== '' },
323
+ },
324
+ yOffsetLimits: {
325
+ min: { value: yOffsetMin.value, isExpr: yOffsetMin.expression !== '' },
326
+ max: { value: yOffsetMax.value, isExpr: yOffsetMax.expression !== '' },
327
+ },
328
+ zOffsetLimits: {
329
+ min: { value: zOffsetMin.value, isExpr: zOffsetMin.expression !== '' },
330
+ max: { value: zOffsetMax.value, isExpr: zOffsetMax.expression !== '' },
331
+ },
332
+ zRotationLimits: {
333
+ min: { value: zRotationMin.value, isExpr: zRotationMin.expression !== '' },
334
+ max: { value: zRotationMax.value, isExpr: zRotationMax.expression !== '' },
335
+ },
336
+ };
337
+ }
338
+ return undefined;
339
+ };
340
+ exports.getParallelConstraint = getParallelConstraint;
341
+ /**
342
+ * Returns the cylindrical constraint of given reference with specified name.
343
+ *
344
+ * @param drawingId The drawing id.
345
+ * @param refId The product reference to look for constraint.
346
+ * @param constrName The name of constraint to look for.
347
+ * @returns The found cylindrical constraint as object or undefined if nothing has been found
348
+ */
349
+ const getCylindricalConstraint = (drawingId, refId, constrName) => {
350
+ var _a, _b;
351
+ if (!constrName) {
352
+ return undefined;
353
+ }
354
+ const constr = getConstraintFromTree(drawingId, refId, constrName);
355
+ if (constr && (0, base_1.isA)(constr.class, re_export_1.CCClasses.CCCylindricalConstraint)) {
356
+ const first = getRefMate(constr, 'first');
357
+ const second = getRefMate(constr, 'second');
358
+ const zOffsetLimits = (_a = constr === null || constr === void 0 ? void 0 : constr.members) === null || _a === void 0 ? void 0 : _a.zOffsetLimits;
359
+ const zOffsetMin = zOffsetLimits === null || zOffsetLimits === void 0 ? void 0 : zOffsetLimits.members[0];
360
+ const zOffsetMax = zOffsetLimits === null || zOffsetLimits === void 0 ? void 0 : zOffsetLimits.members[1];
361
+ const zRotationLimits = (_b = constr === null || constr === void 0 ? void 0 : constr.members) === null || _b === void 0 ? void 0 : _b.zRotationLimits;
362
+ const zRotationMin = zRotationLimits === null || zRotationLimits === void 0 ? void 0 : zRotationLimits.members[0];
363
+ const zRotationMax = zRotationLimits === null || zRotationLimits === void 0 ? void 0 : zRotationLimits.members[1];
364
+ return {
365
+ constrId: constr.id,
366
+ mate1: first,
367
+ mate2: second,
368
+ zOffsetLimits: {
369
+ min: { value: zOffsetMin.value, isExpr: zOffsetMin.expression !== '' },
370
+ max: { value: zOffsetMax.value, isExpr: zOffsetMax.expression !== '' },
371
+ },
372
+ zRotationLimits: {
373
+ min: { value: zRotationMin.value, isExpr: zRotationMin.expression !== '' },
374
+ max: { value: zRotationMax.value, isExpr: zRotationMax.expression !== '' },
375
+ },
376
+ };
377
+ }
378
+ return undefined;
379
+ };
380
+ exports.getCylindricalConstraint = getCylindricalConstraint;
381
+ /**
382
+ * Returns the group constraint of given reference with specified name.
383
+ *
384
+ * @param drawingId The drawing id.
385
+ * @param refId The product reference to look for constraint.
386
+ * @param constrName The name of constraint to look for.
387
+ * @returns The found group constraint as object or undefined if nothing has been found
388
+ */
389
+ const getGroupConstraint = (drawingId, refId, constrName) => {
390
+ var _a;
391
+ if (!constrName) {
392
+ return undefined;
393
+ }
394
+ const constr = getConstraintFromTree(drawingId, refId, constrName);
395
+ if (constr && (0, base_1.isA)(constr.class, re_export_1.CCClasses.CCGroupConstraint)) {
396
+ const instanceIds = ((_a = constr === null || constr === void 0 ? void 0 : constr.members) === null || _a === void 0 ? void 0 : _a.instances).members.map(memb => memb.value);
397
+ return {
398
+ constrId: constr.id,
399
+ instanceIds,
400
+ };
401
+ }
402
+ return undefined;
403
+ };
404
+ exports.getGroupConstraint = getGroupConstraint;
405
+ /**
406
+ * Returns the linear pattern constraint of given reference with specified name.
407
+ *
408
+ * @param drawingId The drawing id.
409
+ * @param refId The product reference to look for constraint.
410
+ * @param constrName The name of constraint to look for.
411
+ * @returns The found linear pattern constraint as object or undefined if nothing has been found
412
+ */
413
+ const getLinearPatternConstraint = (drawingId, refId, constrName) => {
414
+ var _a, _b, _c, _d, _e, _f;
415
+ if (!constrName) {
416
+ return undefined;
417
+ }
418
+ const constr = getConstraintFromTree(drawingId, refId, constrName);
419
+ if (constr && (0, base_1.isA)(constr.class, re_export_1.CCClasses.CCLinearPatternConstraint)) {
420
+ const instanceId = (_b = ((_a = constr === null || constr === void 0 ? void 0 : constr.members) === null || _a === void 0 ? void 0 : _a.instances).members[0]) === null || _b === void 0 ? void 0 : _b.value;
421
+ const first = getRefMate(constr, 'first');
422
+ const firstDirInstanceCount = (_c = constr === null || constr === void 0 ? void 0 : constr.members) === null || _c === void 0 ? void 0 : _c.firstDirInstanceCount;
423
+ const firstDirDistance = (_d = constr === null || constr === void 0 ? void 0 : constr.members) === null || _d === void 0 ? void 0 : _d.firstDirDistance;
424
+ const second = getRefMate(constr, 'second');
425
+ const secondDirInstanceCount = (_e = constr === null || constr === void 0 ? void 0 : constr.members) === null || _e === void 0 ? void 0 : _e.secondDirInstanceCount;
426
+ const secondDirDistance = (_f = constr === null || constr === void 0 ? void 0 : constr.members) === null || _f === void 0 ? void 0 : _f.secondDirDistance;
427
+ return {
428
+ constrId: constr.id,
429
+ instanceId,
430
+ mate1: first,
431
+ firstDirInstanceCount: { value: firstDirInstanceCount.value, isExpr: firstDirInstanceCount.expression !== '' },
432
+ firstDirDistance: { value: firstDirDistance.value, isExpr: firstDirDistance.expression !== '' },
433
+ mate2: second.matePath && second.wcsId ? second : undefined,
434
+ secondDirInstanceCount: { value: secondDirInstanceCount.value, isExpr: secondDirInstanceCount.expression !== '' },
435
+ secondDirDistance: { value: secondDirDistance.value, isExpr: secondDirDistance.expression !== '' },
436
+ };
437
+ }
438
+ return undefined;
439
+ };
440
+ exports.getLinearPatternConstraint = getLinearPatternConstraint;
441
+ /**
442
+ * Returns the circular pattern constraint of given reference with specified name.
443
+ *
444
+ * @param drawingId The drawing id.
445
+ * @param refId The product reference to look for constraint.
446
+ * @param constrName The name of constraint to look for.
447
+ * @returns The found circular pattern constraint as object or undefined if nothing has been found
448
+ */
449
+ const getCircularPatternConstraint = (drawingId, refId, constrName) => {
450
+ var _a, _b, _c, _d, _e;
451
+ if (!constrName) {
452
+ return undefined;
453
+ }
454
+ const constr = getConstraintFromTree(drawingId, refId, constrName);
455
+ if (constr && (0, base_1.isA)(constr.class, re_export_1.CCClasses.CCCircularPatternConstraint)) {
456
+ const instanceId = (_b = ((_a = constr === null || constr === void 0 ? void 0 : constr.members) === null || _a === void 0 ? void 0 : _a.instances).members[0]) === null || _b === void 0 ? void 0 : _b.value;
457
+ const first = getRefMate(constr, 'first');
458
+ const instanceCount = (_c = constr === null || constr === void 0 ? void 0 : constr.members) === null || _c === void 0 ? void 0 : _c.instanceCount;
459
+ const angle = (_d = constr === null || constr === void 0 ? void 0 : constr.members) === null || _d === void 0 ? void 0 : _d.angle;
460
+ const offset = (_e = constr === null || constr === void 0 ? void 0 : constr.members) === null || _e === void 0 ? void 0 : _e.offset;
461
+ return {
462
+ constrId: constr.id,
463
+ instanceId,
464
+ mate1: first,
465
+ instanceCount: { value: instanceCount.value, isExpr: instanceCount.expression !== '' },
466
+ angle: { value: angle.value, isExpr: angle.expression !== '' },
467
+ offset: { value: offset.value, isExpr: offset.expression !== '' },
468
+ };
469
+ }
470
+ return undefined;
471
+ };
472
+ exports.getCircularPatternConstraint = getCircularPatternConstraint;
473
+ /**
474
+ * Helperfunction to get the constraint from product reference by its name.
475
+ *
476
+ * @param drawingId The drawing id
477
+ * @param refId Product reference to look for the constraint in
478
+ * @param constrName Name of the constraint to look for
479
+ * @returns Constraint data
480
+ */
481
+ const getConstraintFromTree = (drawingId, refId, constrName) => {
482
+ const drw = (0, sdkjs_1.getDrawing)(drawingId);
483
+ const tree = drw.structure.tree;
484
+ const productId = (0, exports.findProduct)(refId, tree) || sdkjs_1.NOID;
485
+ const product = tree[productId];
486
+ if (product) {
487
+ const constrSetId = (0, base_1.getChildren)(productId, re_export_1.CCClasses.CCConstraintSet, tree).pop();
488
+ if (!constrSetId)
489
+ return;
490
+ const allConstrIds = (0, base_1.getChildren)(constrSetId, re_export_1.CCClasses.CCHLConstraint, tree);
491
+ const constrId = allConstrIds.filter(c => { var _a; return ((_a = tree[c]) === null || _a === void 0 ? void 0 : _a.name) === constrName; }).pop();
492
+ if (!constrId)
493
+ return;
494
+ const constr = tree[constrId];
495
+ if (!constr)
496
+ return;
497
+ return constr;
498
+ }
499
+ return undefined;
500
+ };
501
+ /**
502
+ * Helperfunction to get the first or second ref mate from a constraint
503
+ *
504
+ * @param constr Constraint to get ref mate from
505
+ * @param ident Identification to get first or second ref mate from constraint
506
+ * @returns Array containing relevant data of ref mate
507
+ */
508
+ const getRefMate = (constr, ident) => {
509
+ var _a, _b, _c, _d, _e, _f, _g;
510
+ const refMate = ident === 'first' ? (_a = constr === null || constr === void 0 ? void 0 : constr.members) === null || _a === void 0 ? void 0 : _a.firstRefMate : (_b = constr === null || constr === void 0 ? void 0 : constr.members) === null || _b === void 0 ? void 0 : _b.secondRefMate;
511
+ return {
512
+ matePath: (_d = (_c = refMate.members[0]) === null || _c === void 0 ? void 0 : _c.members) === null || _d === void 0 ? void 0 : _d.map(m => m.value),
513
+ wcsId: (_e = refMate.members[1]) === null || _e === void 0 ? void 0 : _e.value,
514
+ flip: (_f = refMate.members[2]) === null || _f === void 0 ? void 0 : _f.value,
515
+ reoriented: (_g = refMate.members[3]) === null || _g === void 0 ? void 0 : _g.value,
516
+ };
517
+ };
518
+ /**
519
+ * @deprecated use getWorkGeometry() instead, getWorkCoordSystem() will be removed in a future release.
520
+ *
521
+ * Returns all workcoordsystems of given reference with specified name.
522
+ * If _wcsName_ is undefined, all workcoordsystems of given reference will be returned.
523
+ *
524
+ * @param drawingId The drawing id.
525
+ * @param refId The product reference to look for wcs.
526
+ * @param wcsName The name of wcs to look for.
527
+ * @returns An array of ids of all workcoordsystems found. The array is empty if nothing was found.
528
+ */
529
+ const getWorkCoordSystem = (drawingId, refId, wcsName) => {
530
+ console.warn('getWorkCoordSystem() is deprecated and will be removed in a future release. Use getWorkGeometry() instead.');
531
+ return (0, part_1.getWorkCoordSystem)(drawingId, refId, wcsName);
532
+ };
533
+ exports.getWorkCoordSystem = getWorkCoordSystem;
534
+ /**
535
+ * Returns all work geometry of given type and given reference with specified name.
536
+ * If wgName is undefined, all work geometry of given reference will be returned.
537
+ *
538
+ * @param drawingId The drawing id.
539
+ * @param refId The product reference to look for work geometry.
540
+ * @param type The type of work geometry to look for
541
+ * @param wgName The name of work geometry to look for.
542
+ * @returns An array of ids of all found work geometry. The array is empty if nothing was found.
543
+ */
544
+ const getWorkGeometry = (drawingId, refId, type, wgName) => {
545
+ return (0, part_1.getWorkGeometry)(drawingId, refId, type, wgName);
546
+ };
547
+ exports.getWorkGeometry = getWorkGeometry;
548
+ /**
549
+ * Returns the part template with given identifier or name from part container.
550
+ * If _partName_ is undefined, all parts from part container will be returned.
551
+ *
552
+ * @param drawingId The drawing id.
553
+ * @param partName The identifier or name of the part to look for.
554
+ * @returns An array of ids of all parts found. The array is empty if nothing was found.
555
+ */
556
+ const getPartTemplate = (drawingId, partName) => {
557
+ const drw = (0, sdkjs_1.getDrawing)(drawingId);
558
+ const tree = drw.structure.tree;
559
+ const container = drw.api.structure.filterTree(tree, obj => obj.name === 'PartContainer').pop();
560
+ let parts = [];
561
+ if (container) {
562
+ parts = (0, base_1.getChildren)(container.id, re_export_1.CCClasses.CCPart, tree);
563
+ if (partName) {
564
+ const part = (0, base_1.findObject)(drawingId, { ident: partName, name: partName });
565
+ if (part) {
566
+ return [part];
567
+ }
568
+ parts = parts.filter(p => tree[p].name === partName);
569
+ }
570
+ }
571
+ return parts;
572
+ };
573
+ exports.getPartTemplate = getPartTemplate;
574
+ /**
575
+ * Returns the assembly template with given identifier or name from assembly container.
576
+ * If _asmName_ is undefined, all assemblies from assembly container will be returned.
577
+ *
578
+ * @param drawingId The drawing id.
579
+ * @param asmName The identifier or name of the assembly to look for.
580
+ * @returns An array of ids of all assemblies found. The array is empty if nothing was found.
581
+ */
582
+ const getAssemblyTemplate = (drawingId, asmName) => {
583
+ const drw = (0, sdkjs_1.getDrawing)(drawingId);
584
+ const tree = drw.structure.tree;
585
+ const container = drw.api.structure.filterTree(tree, obj => obj.name === 'AssemblyContainer').pop();
586
+ let assemblies = [];
587
+ if (container) {
588
+ assemblies = (0, base_1.getChildren)(container.id, re_export_1.CCClasses.CCAssembly, tree);
589
+ if (asmName) {
590
+ const assembly = (0, base_1.findObject)(drawingId, { ident: asmName, name: asmName });
591
+ if (assembly) {
592
+ return [assembly];
593
+ }
594
+ }
595
+ }
596
+ return assemblies;
597
+ };
598
+ exports.getAssemblyTemplate = getAssemblyTemplate;
599
+ /**
600
+ * Returns an instance or all instances of a node, depending on whether a name is given or not.
601
+ * The node is the parent of the instance/instances we're looking for and can be a root assembly,
602
+ * another instance or an assembly template.
603
+ *
604
+ * @param drawingId The drawing id.
605
+ * @param id id of the node from which we are searching the children for instances that have the name we are looking for.
606
+ * @param instanceName name of the instance we are looking for
607
+ * @returns array containing the ids of the found instances
608
+ */
609
+ const getInstance = (drawingId, id, instanceName) => {
610
+ const drw = (0, sdkjs_1.getDrawing)(drawingId);
611
+ const tree = drw.structure.tree;
612
+ let instances = (0, base_1.getChildren)(id, re_export_1.CCClasses.IProductReference, tree);
613
+ if (instanceName) {
614
+ instances = instances.filter(c => tree[c].name === instanceName);
615
+ }
616
+ return instances;
617
+ };
618
+ exports.getInstance = getInstance;
619
+ /**
620
+ * Returns the coordinate system (global transformation) of the given instance id.
621
+ *
622
+ * @param drawingId The drawing id
623
+ * @param instanceId id of the instance to get the coordinate system (global transformation) from
624
+ * @returns The coordinate system as an two-dimensional array
625
+ */
626
+ const getTransformation = (drawingId, instanceId) => {
627
+ const drw = (0, sdkjs_1.getDrawing)(drawingId);
628
+ const tree = drw.structure.tree;
629
+ const rootId = drw.structure.root;
630
+ const rootAsm = tree[rootId];
631
+ if (rootAsm) {
632
+ const transfMatrixInstance = drw.api.structure.calculateGlobalTransformation(instanceId);
633
+ const rootMatrix = rootAsm.coordinateSystem
634
+ ? sdkjs_1.MathUtils.convertToMatrix4(rootAsm.coordinateSystem)
635
+ : new three_1.Matrix4();
636
+ const instanceCoordSysAsMatrix = rootMatrix.clone().multiply(transfMatrixInstance);
637
+ const instanceCoordSys = sdkjs_1.MathUtils.convertToCoordinateSystem(instanceCoordSysAsMatrix);
638
+ return instanceCoordSys;
639
+ }
640
+ return undefined;
641
+ };
642
+ exports.getTransformation = getTransformation;
643
+ /**
644
+ * Creates and returns the mate path as array from the given instance id up to the current instance.
645
+ * This helps to get the right path to set constraints between instances which are located in
646
+ * nested assemblies.
647
+ * @param drawingId The drawing id
648
+ * @param instanceId id of the instance to get the mate path from. Id can be a number or string.
649
+ * @returns The mate path as array from the given instance id up to the current instance
650
+ */
651
+ const getMatePath = (drawingId, instanceId) => {
652
+ var _a, _b, _c, _d;
653
+ const drawing = (0, sdkjs_1.getDrawing)(drawingId);
654
+ if (!drawing) {
655
+ return [];
656
+ }
657
+ const structure = drawing.structure;
658
+ const tree = structure.tree;
659
+ let foundInstanceId;
660
+ if (typeof instanceId === 'number') {
661
+ foundInstanceId = instanceId;
662
+ }
663
+ else if (typeof instanceId === 'string') {
664
+ foundInstanceId = (0, base_1.findObject)(drawingId, { ident: instanceId, name: instanceId });
665
+ }
666
+ else {
667
+ throw 'Invalid instanceId';
668
+ }
669
+ if (!foundInstanceId) {
670
+ return [];
671
+ }
672
+ let prRefETId = foundInstanceId;
673
+ const pathET = [];
674
+ while ((0, base_1.isA)((_a = tree[prRefETId]) === null || _a === void 0 ? void 0 : _a.class, re_export_1.CCClasses.IProductReference)) {
675
+ pathET.push(prRefETId);
676
+ prRefETId = ((_b = tree[prRefETId]) === null || _b === void 0 ? void 0 : _b.parent) || -1;
677
+ }
678
+ const path = pathET.map(id => { var _a, _b; return ((_b = (_a = tree[id].members) === null || _a === void 0 ? void 0 : _a.productRef) === null || _b === void 0 ? void 0 : _b.value) || id; });
679
+ const currentInstance = drawing.structure.currentInstance;
680
+ const currentProduct = currentInstance && (((_d = (_c = tree[currentInstance].members) === null || _c === void 0 ? void 0 : _c.productRef) === null || _d === void 0 ? void 0 : _d.value) || currentInstance);
681
+ const pathLength = currentProduct && path.indexOf(currentProduct);
682
+ if (pathLength !== undefined && pathLength !== -1) {
683
+ path.splice(pathLength);
684
+ }
685
+ return path;
686
+ };
687
+ exports.getMatePath = getMatePath;