@buerli.io/headless 0.4.1 → 0.5.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/history.js +1226 -0
- package/build/cjs/index.js +35 -0
- package/build/cjs/solid.js +435 -0
- package/build/cjs/utils/selection.js +32 -0
- package/build/{history.js → esm/history.js} +155 -150
- package/build/{index.js → esm/index.js} +0 -0
- package/build/{solid.js → esm/solid.js} +2 -2
- package/build/{utils → esm/utils}/selection.js +0 -0
- package/build/{history.d.ts → types/history.d.ts} +50 -22
- package/build/{index.d.ts → types/index.d.ts} +0 -0
- package/build/{solid.d.ts → types/solid.d.ts} +5 -5
- package/build/{utils → types/utils}/selection.d.ts +0 -0
- package/package.json +11 -11
|
@@ -0,0 +1,1226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
26
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
27
|
+
var m = o[Symbol.asyncIterator], i;
|
|
28
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
29
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
30
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
31
|
+
};
|
|
32
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
|
+
/* eslint-disable max-lines */
|
|
34
|
+
const classcad_1 = require("@buerli.io/classcad");
|
|
35
|
+
const core_1 = require("@buerli.io/core");
|
|
36
|
+
const three_1 = require("three");
|
|
37
|
+
const BufferGeometryUtils_ = __importStar(require("three/examples/jsm/utils/BufferGeometryUtils"));
|
|
38
|
+
const selection_1 = require("./utils/selection");
|
|
39
|
+
const featureAPI = classcad_1.ccAPI.feature;
|
|
40
|
+
const sketcherAPI = classcad_1.ccAPI.sketcher;
|
|
41
|
+
const base = classcad_1.ccUtils.base;
|
|
42
|
+
let BufferGeometryUtils = BufferGeometryUtils_;
|
|
43
|
+
if (BufferGeometryUtils.BufferGeometryUtils) {
|
|
44
|
+
BufferGeometryUtils = BufferGeometryUtils.BufferGeometryUtils;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Returns the data type of the given value
|
|
48
|
+
* @param value value to get the data type from
|
|
49
|
+
* @returns datatype of value
|
|
50
|
+
*/
|
|
51
|
+
const getDataType = (value) => {
|
|
52
|
+
switch (typeof value) {
|
|
53
|
+
case 'number':
|
|
54
|
+
return classcad_1.DataType.REAL;
|
|
55
|
+
case 'object':
|
|
56
|
+
return classcad_1.DataType.POINT;
|
|
57
|
+
case 'string':
|
|
58
|
+
return classcad_1.DataType.STRING;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Returns the cclass of the given dimension type
|
|
63
|
+
* @param type type of the dimension as string
|
|
64
|
+
* @returns cclass type of given type
|
|
65
|
+
*/
|
|
66
|
+
const getDimensionType = (type) => {
|
|
67
|
+
let cclass = classcad_1.CCClasses.CCLinearDimension;
|
|
68
|
+
switch (type) {
|
|
69
|
+
case 'LinearDimension':
|
|
70
|
+
cclass = classcad_1.CCClasses.CCLinearDimension;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
return cclass;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Transforms the transformation which is local to the ownerId into global
|
|
77
|
+
* transformation and returns it.
|
|
78
|
+
* @param ownerId node to get the global transformation from
|
|
79
|
+
* @param localTransformation transformation local to the owner, will be calculated into global transformation
|
|
80
|
+
* @returns the global transformation from local transformation to owner
|
|
81
|
+
*/
|
|
82
|
+
const getGlobalTransformation = (drawingId, ownerId, localTransformation) => {
|
|
83
|
+
const lT = localTransformation;
|
|
84
|
+
const coordSysOwner = classcad_1.ccUtils.assembly.getCoordSysFromNode(drawingId, ownerId);
|
|
85
|
+
if (coordSysOwner) {
|
|
86
|
+
const origin = [lT[0].x, lT[0].y, lT[0].z];
|
|
87
|
+
const xAxis = [lT[1].x, lT[1].y, lT[1].z];
|
|
88
|
+
const yAxis = [lT[2].x, lT[2].y, lT[2].z];
|
|
89
|
+
const zAxis = new three_1.Vector3().crossVectors(new three_1.Vector3(lT[1].x, lT[1].y, lT[1].z), new three_1.Vector3(lT[2].x, lT[2].y, lT[2].z));
|
|
90
|
+
const matrix = core_1.MathUtils.convertToMatrix4([origin, xAxis, yAxis, [zAxis.x, zAxis.y, zAxis.z]]);
|
|
91
|
+
const transformation = core_1.MathUtils.convertToMatrix4(coordSysOwner).clone().multiply(matrix);
|
|
92
|
+
const transformationCoords = core_1.MathUtils.convertToCoordinateSystem(transformation);
|
|
93
|
+
const tC = transformationCoords;
|
|
94
|
+
return [
|
|
95
|
+
{ x: tC[0][0], y: tC[0][1], z: tC[0][2] },
|
|
96
|
+
{ x: tC[1][0], y: tC[1][1], z: tC[1][2] },
|
|
97
|
+
{ x: tC[2][0], y: tC[2][1], z: tC[2][2] },
|
|
98
|
+
];
|
|
99
|
+
}
|
|
100
|
+
return undefined;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Helps to create the buffer geometry of the given object recursively.
|
|
104
|
+
* @param object object to create the buffergeometry from
|
|
105
|
+
* @param bufferGeomArray array to fill up with buffert geometries
|
|
106
|
+
*/
|
|
107
|
+
const createRecursiveBufferGeometry = async (object, drawingId, bufferGeomArray) => {
|
|
108
|
+
let cDrawing = (0, core_1.getDrawing)(drawingId);
|
|
109
|
+
const tree = cDrawing.structure.tree;
|
|
110
|
+
if (object.link || object.solids) {
|
|
111
|
+
// Part
|
|
112
|
+
const solids = object.link ? tree[object.link].solids : object.solids;
|
|
113
|
+
if (solids != undefined) {
|
|
114
|
+
let geometries = [];
|
|
115
|
+
for (const solid of solids) {
|
|
116
|
+
let cachedSolid = cDrawing.geometry.cache[solid];
|
|
117
|
+
if (cachedSolid) {
|
|
118
|
+
// if solid already cached, take it from cache
|
|
119
|
+
geometries = [...geometries, ...cachedSolid.meshes.map(m => m.geometry)];
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
// else get visualisation from classcad
|
|
123
|
+
await classcad_1.ccAPI.baseModeler.requestVisualisationOfEntities(drawingId, [solid]);
|
|
124
|
+
cDrawing = (0, core_1.getDrawing)(drawingId); // get current drawing state after request
|
|
125
|
+
cachedSolid = cDrawing.geometry.cache[solid];
|
|
126
|
+
if (cachedSolid) {
|
|
127
|
+
geometries = [...geometries, ...cachedSolid.meshes.map(m => m.geometry)];
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
console.warn(`There is no cached entry for ${solid}!`, cDrawing.geometry.cache);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (geometries.length > 0) {
|
|
135
|
+
const transformation = cDrawing.api.structure.calculateGlobalTransformation(object.id);
|
|
136
|
+
const bufferGeom = BufferGeometryUtils.mergeBufferGeometries(geometries);
|
|
137
|
+
bufferGeom.applyMatrix4(transformation);
|
|
138
|
+
bufferGeomArray.push(bufferGeom);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
else if (object.children) {
|
|
143
|
+
// Assembly
|
|
144
|
+
for (const child of object.children) {
|
|
145
|
+
if (tree[child].class === classcad_1.CCClasses.CCProductReference || tree[child].class === classcad_1.CCClasses.CCProductReferenceET) {
|
|
146
|
+
await createRecursiveBufferGeometry(tree[child], drawingId, bufferGeomArray);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* We traverse recursively over structure tree, starting with object and create three objects and meshes
|
|
153
|
+
* for the scene. Each part or assembly will be turned into groups and subgroups. Solids from parts will be turned
|
|
154
|
+
* into merged meshes, which are children of the group. Faces of a solid with different color
|
|
155
|
+
* or transparency will get its own mesh.
|
|
156
|
+
* @param object root object where we start building the three scene
|
|
157
|
+
* @param drawingId id of the drawing
|
|
158
|
+
* @param root the root of the scene
|
|
159
|
+
* @param options e.g. meshPerFace controls if each face gets a own mesh or if they will be combined/merged
|
|
160
|
+
*/
|
|
161
|
+
const createRecursiveScene = async (object, drawingId, root, options) => {
|
|
162
|
+
let cDrawing = (0, core_1.getDrawing)(drawingId);
|
|
163
|
+
const tree = cDrawing.structure.tree;
|
|
164
|
+
if (object.link || object.solids) {
|
|
165
|
+
// Part
|
|
166
|
+
const solids = object.link ? tree[object.link].solids : object.solids;
|
|
167
|
+
if (solids != undefined) {
|
|
168
|
+
let meshes = [];
|
|
169
|
+
const cachedSolids = [];
|
|
170
|
+
for (const solid of solids) {
|
|
171
|
+
let cachedSolid = cDrawing.geometry.cache[solid];
|
|
172
|
+
if (!cachedSolid) {
|
|
173
|
+
// else get visualisation from classcad
|
|
174
|
+
await classcad_1.ccAPI.baseModeler.requestVisualisationOfEntities(drawingId, [solid]);
|
|
175
|
+
cDrawing = (0, core_1.getDrawing)(drawingId); // get current drawing state after request
|
|
176
|
+
cachedSolid = cDrawing.geometry.cache[solid];
|
|
177
|
+
}
|
|
178
|
+
if (cachedSolid) {
|
|
179
|
+
if (options === null || options === void 0 ? void 0 : options.meshPerFace) {
|
|
180
|
+
meshes = [...meshes, ...cachedSolid.meshes.map(m => m)];
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
cachedSolids.push(cachedSolid);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
// If meshPerFace = true, we create for each face a separat mesh
|
|
188
|
+
if (options === null || options === void 0 ? void 0 : options.meshPerFace) {
|
|
189
|
+
if (meshes.length > 0) {
|
|
190
|
+
const part = new three_1.Group();
|
|
191
|
+
part.matrix = core_1.MathUtils.convertToMatrix4(object.coordinateSystem);
|
|
192
|
+
part.matrixAutoUpdate = false;
|
|
193
|
+
part.userData = { id: object.id }; // product reference id
|
|
194
|
+
part.name = object.name; // product reference name
|
|
195
|
+
for (const mesh of meshes) {
|
|
196
|
+
part.add(new three_1.Mesh(mesh.geometry, new three_1.MeshStandardMaterial({ color: mesh.color, transparent: mesh.opacity < 1, opacity: mesh.opacity })));
|
|
197
|
+
}
|
|
198
|
+
root.add(part);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
if (cachedSolids.length > 0) {
|
|
203
|
+
const part = new three_1.Group();
|
|
204
|
+
part.matrix = core_1.MathUtils.convertToMatrix4(object.coordinateSystem);
|
|
205
|
+
part.matrixAutoUpdate = false;
|
|
206
|
+
part.userData = { id: object.id }; // product reference id
|
|
207
|
+
part.name = object.name; // product reference name
|
|
208
|
+
// A cached solid can have different colored faces, e.g. if a brep has been decorated.
|
|
209
|
+
// In that case, we group the meshes with the same color/tranparency
|
|
210
|
+
for (const cs of cachedSolids) {
|
|
211
|
+
const colorMeshesMap = getDifferentColoredMeshesFromSolid(cs);
|
|
212
|
+
Object.keys(colorMeshesMap).forEach(key => {
|
|
213
|
+
const coloredMeshes = colorMeshesMap[key];
|
|
214
|
+
const mesh = new three_1.Mesh();
|
|
215
|
+
mesh.userData = { id: cs.container.ownerId }; // solid id
|
|
216
|
+
mesh.name = tree[cs.container.ownerId].name; // solid name
|
|
217
|
+
mesh.geometry = BufferGeometryUtils.mergeBufferGeometries(coloredMeshes.map(m => m.geometry));
|
|
218
|
+
mesh.material = new three_1.MeshStandardMaterial({
|
|
219
|
+
color: coloredMeshes[0].color,
|
|
220
|
+
transparent: coloredMeshes[0].opacity < 1,
|
|
221
|
+
opacity: coloredMeshes[0].opacity,
|
|
222
|
+
});
|
|
223
|
+
part.add(mesh);
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
root.add(part);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
else if (object.children) {
|
|
232
|
+
// Assembly
|
|
233
|
+
const assembly = new three_1.Group();
|
|
234
|
+
assembly.matrix = core_1.MathUtils.convertToMatrix4(object.coordinateSystem);
|
|
235
|
+
assembly.matrixAutoUpdate = false;
|
|
236
|
+
assembly.userData = { id: object.id }; // assembly root or product reference id
|
|
237
|
+
assembly.name = object.name; // assembly root or product reference name
|
|
238
|
+
root.add(assembly);
|
|
239
|
+
for (const child of object.children) {
|
|
240
|
+
if (tree[child].class === classcad_1.CCClasses.CCProductReference || tree[child].class === classcad_1.CCClasses.CCProductReferenceET) {
|
|
241
|
+
await createRecursiveScene(tree[child], drawingId, assembly, options);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* Get all meshes in a map, sorted by their color / transparency
|
|
248
|
+
* @param solid solid to look for the meshes
|
|
249
|
+
* @returns map (key = color/transparency as string, value = meshes array)
|
|
250
|
+
*/
|
|
251
|
+
const getDifferentColoredMeshesFromSolid = (solid) => {
|
|
252
|
+
const colorMeshesMap = {};
|
|
253
|
+
solid.meshes.forEach(mesh => {
|
|
254
|
+
const key = mesh.color.getHexString() + mesh.opacity.toString();
|
|
255
|
+
if (colorMeshesMap[key]) {
|
|
256
|
+
colorMeshesMap[key].push(mesh);
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
colorMeshesMap[key] = [mesh];
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
return colorMeshesMap;
|
|
263
|
+
};
|
|
264
|
+
/**
|
|
265
|
+
* Helper function to log relevant points to find geometry to the console.
|
|
266
|
+
* This helps the user to copy the points directly from console to parameter of
|
|
267
|
+
* findOrSelect() method.
|
|
268
|
+
* @param points Array of points array to log to the console
|
|
269
|
+
*/
|
|
270
|
+
const logPoints = (points) => {
|
|
271
|
+
let log = 'Relevant points of selected gometry = [[';
|
|
272
|
+
if (points && points.length > 0) {
|
|
273
|
+
for (let i = 0; i < points.length; i++) {
|
|
274
|
+
for (let j = 0; j < points[i].length; j++) {
|
|
275
|
+
const x = Math.round(points[i][j].x * 1000) / 1000;
|
|
276
|
+
const y = Math.round(points[i][j].y * 1000) / 1000;
|
|
277
|
+
const z = Math.round(points[i][j].z * 1000) / 1000;
|
|
278
|
+
log += '{ x: ' + x + ', y: ' + y + ', z: ' + z + '}';
|
|
279
|
+
log += points[i].length - 1 === j ? '' : ',';
|
|
280
|
+
}
|
|
281
|
+
log += points.length - 1 === i ? ']]' : '],[';
|
|
282
|
+
}
|
|
283
|
+
console.info(log);
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
class CAD {
|
|
287
|
+
constructor() {
|
|
288
|
+
this.drawingId = null;
|
|
289
|
+
this.queue = Promise.resolve(0);
|
|
290
|
+
this.queue = Promise.resolve(0);
|
|
291
|
+
}
|
|
292
|
+
resolve(callback, ...args) {
|
|
293
|
+
return (this.queue = this.queue
|
|
294
|
+
.then(() => Promise.all(args).then(callback))
|
|
295
|
+
.catch(e => {
|
|
296
|
+
// catch is necessary to avoid error promises in the queue
|
|
297
|
+
}));
|
|
298
|
+
}
|
|
299
|
+
init(callback) {
|
|
300
|
+
const promise = new Promise(async (resolve, reject) => {
|
|
301
|
+
const drawingId = await classcad_1.ccAPI.base.createCCDrawing();
|
|
302
|
+
if (!drawingId)
|
|
303
|
+
throw new Error('Drawing could not be created');
|
|
304
|
+
this.drawingId = drawingId;
|
|
305
|
+
const publicApi = {
|
|
306
|
+
addNode: (productId, ownerId, transformation, name) => {
|
|
307
|
+
return this.resolve(async ([rProductId, rOwnerId]) => {
|
|
308
|
+
const globalTransformation = getGlobalTransformation(drawingId, rOwnerId, transformation) || transformation;
|
|
309
|
+
return classcad_1.ccAPI.assemblyBuilder.addNode(drawingId, rProductId, rOwnerId, globalTransformation, name);
|
|
310
|
+
}, productId, ownerId);
|
|
311
|
+
},
|
|
312
|
+
addNodes: async (...nodes) => {
|
|
313
|
+
var e_1, _a;
|
|
314
|
+
const nodesToAdd = [];
|
|
315
|
+
try {
|
|
316
|
+
for (var nodes_1 = __asyncValues(nodes), nodes_1_1; nodes_1_1 = await nodes_1.next(), !nodes_1_1.done;) {
|
|
317
|
+
const node = nodes_1_1.value;
|
|
318
|
+
const [rProductId, rOwnerId] = await new Promise(res => this.resolve(id => res(id), node.productId, node.ownerId));
|
|
319
|
+
const nodeParam = {
|
|
320
|
+
referenceId: rProductId,
|
|
321
|
+
ownerId: rOwnerId,
|
|
322
|
+
transformation: getGlobalTransformation(drawingId, rOwnerId, node.transformation) || node.transformation,
|
|
323
|
+
name: node.name,
|
|
324
|
+
};
|
|
325
|
+
nodesToAdd.push(nodeParam);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
329
|
+
finally {
|
|
330
|
+
try {
|
|
331
|
+
if (nodes_1_1 && !nodes_1_1.done && (_a = nodes_1.return)) await _a.call(nodes_1);
|
|
332
|
+
}
|
|
333
|
+
finally { if (e_1) throw e_1.error; }
|
|
334
|
+
}
|
|
335
|
+
return classcad_1.ccAPI.assemblyBuilder.addNodes(drawingId, nodesToAdd);
|
|
336
|
+
},
|
|
337
|
+
addDimension: (dim) => {
|
|
338
|
+
return this.resolve(async ([rProductId]) => {
|
|
339
|
+
const dimensionType = getDimensionType(dim.dimParam.dimType);
|
|
340
|
+
const dimParam = {
|
|
341
|
+
productId: rProductId,
|
|
342
|
+
param: {
|
|
343
|
+
type: dimensionType,
|
|
344
|
+
name: dim.dimParam.dimName,
|
|
345
|
+
label: dim.dimParam.dimLabel,
|
|
346
|
+
value: dim.dimParam.dimValue,
|
|
347
|
+
startPos: dim.dimParam.dimStartPos,
|
|
348
|
+
endPos: dim.dimParam.dimEndPos,
|
|
349
|
+
textPos: dim.dimParam.dimTextPos,
|
|
350
|
+
textAngle: dim.dimParam.dimTextAngle,
|
|
351
|
+
orientation: dim.dimParam.dimOrientation,
|
|
352
|
+
color: dim.dimParam.dimColor,
|
|
353
|
+
layer: dim.dimParam.dimLayer,
|
|
354
|
+
},
|
|
355
|
+
dxfView: dim.dxfView,
|
|
356
|
+
};
|
|
357
|
+
return classcad_1.ccAPI.drawing2D.addDimension(drawingId, dimParam);
|
|
358
|
+
}, dim.productId);
|
|
359
|
+
},
|
|
360
|
+
addDimensions: async (...dimensions) => {
|
|
361
|
+
var e_2, _a;
|
|
362
|
+
const dimParamsToAdd = [];
|
|
363
|
+
try {
|
|
364
|
+
for (var dimensions_1 = __asyncValues(dimensions), dimensions_1_1; dimensions_1_1 = await dimensions_1.next(), !dimensions_1_1.done;) {
|
|
365
|
+
const dim = dimensions_1_1.value;
|
|
366
|
+
const [rProductId] = await new Promise(res => this.resolve(id => res(id), dim.productId));
|
|
367
|
+
const dimensionType = getDimensionType(dim.dimParam.dimType);
|
|
368
|
+
const dimParam = {
|
|
369
|
+
productId: rProductId,
|
|
370
|
+
param: {
|
|
371
|
+
type: dimensionType,
|
|
372
|
+
name: dim.dimParam.dimName,
|
|
373
|
+
label: dim.dimParam.dimLabel,
|
|
374
|
+
value: dim.dimParam.dimValue,
|
|
375
|
+
startPos: dim.dimParam.dimStartPos,
|
|
376
|
+
endPos: dim.dimParam.dimEndPos,
|
|
377
|
+
textPos: dim.dimParam.dimTextPos,
|
|
378
|
+
textAngle: dim.dimParam.dimTextAngle,
|
|
379
|
+
orientation: dim.dimParam.dimOrientation,
|
|
380
|
+
color: dim.dimParam.dimColor,
|
|
381
|
+
layer: dim.dimParam.dimLayer,
|
|
382
|
+
},
|
|
383
|
+
dxfView: dim.dxfView,
|
|
384
|
+
};
|
|
385
|
+
dimParamsToAdd.push(dimParam);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
389
|
+
finally {
|
|
390
|
+
try {
|
|
391
|
+
if (dimensions_1_1 && !dimensions_1_1.done && (_a = dimensions_1.return)) await _a.call(dimensions_1);
|
|
392
|
+
}
|
|
393
|
+
finally { if (e_2) throw e_2.error; }
|
|
394
|
+
}
|
|
395
|
+
return classcad_1.ccAPI.drawing2D.addDimensions(drawingId, dimParamsToAdd);
|
|
396
|
+
},
|
|
397
|
+
create2DViews: (productId, viewTypes, viewOptions) => {
|
|
398
|
+
return this.resolve(async ([rProductId]) => {
|
|
399
|
+
const viewIds = await classcad_1.ccAPI.drawing2D.create2DViews(drawingId, rProductId, viewTypes, viewOptions);
|
|
400
|
+
if (viewIds !== null) {
|
|
401
|
+
await classcad_1.ccAPI.drawing2D.centerAllViews(drawingId, rProductId, viewTypes);
|
|
402
|
+
return viewIds;
|
|
403
|
+
}
|
|
404
|
+
return null;
|
|
405
|
+
}, productId);
|
|
406
|
+
},
|
|
407
|
+
getBoundaryBoxFromViews: (productId, viewTypes) => {
|
|
408
|
+
return this.resolve(async ([rProductId]) => {
|
|
409
|
+
const bbs = await classcad_1.ccAPI.drawing2D.getBoundaryBoxFromViews(drawingId, rProductId, viewTypes);
|
|
410
|
+
return bbs;
|
|
411
|
+
}, productId);
|
|
412
|
+
},
|
|
413
|
+
place2DViews: (productId, viewPositions) => {
|
|
414
|
+
return this.resolve(async ([rProductId]) => {
|
|
415
|
+
return classcad_1.ccAPI.drawing2D.place2DViews(drawingId, rProductId, viewPositions);
|
|
416
|
+
}, productId);
|
|
417
|
+
},
|
|
418
|
+
exportDXF: (productId, dxfTemplateFilename) => {
|
|
419
|
+
return this.resolve(async ([rProductId]) => {
|
|
420
|
+
return classcad_1.ccAPI.drawing2D.exportDXF(drawingId, rProductId, dxfTemplateFilename);
|
|
421
|
+
}, productId);
|
|
422
|
+
},
|
|
423
|
+
exportSVG: (productId, modus, renderSize, dxfTemplateFilename) => {
|
|
424
|
+
return this.resolve(async ([rProductId]) => {
|
|
425
|
+
modus = modus ? modus : classcad_1.SVGModusType.FIT_WHOLE_DRAWING;
|
|
426
|
+
const renderSizeParam = (renderSize === null || renderSize === void 0 ? void 0 : renderSize.x) && (renderSize === null || renderSize === void 0 ? void 0 : renderSize.y) ? [renderSize.x, renderSize.y] : undefined;
|
|
427
|
+
return classcad_1.ccAPI.drawing2D.exportSVG(drawingId, rProductId, modus, renderSizeParam, dxfTemplateFilename);
|
|
428
|
+
}, productId);
|
|
429
|
+
},
|
|
430
|
+
removeDimensions: (dimensionIds) => {
|
|
431
|
+
return this.resolve(async ([...rDimensionIds]) => {
|
|
432
|
+
return classcad_1.ccAPI.drawing2D.removeDimensions(drawingId, rDimensionIds);
|
|
433
|
+
}, ...dimensionIds);
|
|
434
|
+
},
|
|
435
|
+
linearPattern: (partId, entities, references1, params1, references2, params2) => {
|
|
436
|
+
return this.resolve(async ([rPartId, rEntities, rReferences1, rReferences2]) => {
|
|
437
|
+
const patternId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCLinearPattern, 'LinearPattern');
|
|
438
|
+
if (patternId != null) {
|
|
439
|
+
// entities
|
|
440
|
+
const cDrawing = await (0, core_1.getDrawing)(drawingId);
|
|
441
|
+
const entArray = [];
|
|
442
|
+
for (const rEntity of rEntities) {
|
|
443
|
+
const entity = cDrawing.structure.tree[(await rEntity)].children;
|
|
444
|
+
if (entity != undefined) {
|
|
445
|
+
entArray.push(entity[0]);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
const distance1Param = {
|
|
449
|
+
value: params1.distance,
|
|
450
|
+
isExpr: typeof params1.distance === 'string',
|
|
451
|
+
};
|
|
452
|
+
const count1Param = {
|
|
453
|
+
value: params1.count,
|
|
454
|
+
isExpr: typeof params1.count === 'string',
|
|
455
|
+
};
|
|
456
|
+
const params1Param = [
|
|
457
|
+
params1.inverted,
|
|
458
|
+
distance1Param,
|
|
459
|
+
count1Param,
|
|
460
|
+
params1.merged,
|
|
461
|
+
];
|
|
462
|
+
let params2Param = null;
|
|
463
|
+
if (params2) {
|
|
464
|
+
const distance2Param = {
|
|
465
|
+
value: params2.distance,
|
|
466
|
+
isExpr: typeof params2.distance === 'string',
|
|
467
|
+
};
|
|
468
|
+
const count2Param = {
|
|
469
|
+
value: params2.count,
|
|
470
|
+
isExpr: typeof params2.count === 'string',
|
|
471
|
+
};
|
|
472
|
+
params2Param = [params2.inverted, distance2Param, count2Param];
|
|
473
|
+
}
|
|
474
|
+
// resolve references1
|
|
475
|
+
const refs1 = [];
|
|
476
|
+
let refs2 = [];
|
|
477
|
+
for (const rRef1 of rReferences1) {
|
|
478
|
+
refs1.push(await rRef1);
|
|
479
|
+
}
|
|
480
|
+
// resolve references2 if present
|
|
481
|
+
if (rReferences2) {
|
|
482
|
+
for (const rRef2 of rReferences2) {
|
|
483
|
+
refs2.push(await rRef2);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
else {
|
|
487
|
+
refs2 = null;
|
|
488
|
+
}
|
|
489
|
+
await featureAPI.updatePattern(drawingId, patternId, entArray, refs1, params1Param, refs2, params2Param);
|
|
490
|
+
return patternId;
|
|
491
|
+
}
|
|
492
|
+
return null;
|
|
493
|
+
}, partId, entities, references1, references2);
|
|
494
|
+
},
|
|
495
|
+
circularPattern: (partId, entities, references, params) => {
|
|
496
|
+
return this.resolve(async ([rPartId, rEntities, ...rReferences]) => {
|
|
497
|
+
const patternId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCCircularPattern, 'CircularPattern');
|
|
498
|
+
if (patternId != null) {
|
|
499
|
+
// entities
|
|
500
|
+
const cDrawing = await (0, core_1.getDrawing)(drawingId);
|
|
501
|
+
const entArray = [];
|
|
502
|
+
for (const rEntity of rEntities) {
|
|
503
|
+
const entity = cDrawing.structure.tree[(await rEntity)].children;
|
|
504
|
+
if (entity != undefined) {
|
|
505
|
+
entArray.push(entity[0]);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
const angleParam = { value: params.angle, isExpr: typeof params.angle === 'string' };
|
|
509
|
+
const countParam = { value: params.count, isExpr: typeof params.count === 'string' };
|
|
510
|
+
const paramsParam = [
|
|
511
|
+
params.inverted,
|
|
512
|
+
angleParam,
|
|
513
|
+
countParam,
|
|
514
|
+
params.merged,
|
|
515
|
+
];
|
|
516
|
+
rReferences = Array.isArray(rReferences) ? rReferences : [rReferences];
|
|
517
|
+
await featureAPI.updatePattern(drawingId, patternId, entArray, rReferences, paramsParam, null, null);
|
|
518
|
+
return patternId;
|
|
519
|
+
}
|
|
520
|
+
return null;
|
|
521
|
+
}, partId, entities, ...references);
|
|
522
|
+
},
|
|
523
|
+
extrusion: (partId, sketchId, type, limit1, limit2, taperAngle, direction, capEnds) => {
|
|
524
|
+
return this.resolve(async ([rPartId, rSketchId]) => {
|
|
525
|
+
const extrusion = await featureAPI.createExtrusion(drawingId, rPartId);
|
|
526
|
+
if (extrusion) {
|
|
527
|
+
const cDrawing = await (0, core_1.getDrawing)(drawingId);
|
|
528
|
+
const sketchLines = [];
|
|
529
|
+
// TODO: Which sketch lines need to be included, is CCClasses.CCCurve and its derivation enough?
|
|
530
|
+
sketchLines.push(...classcad_1.ccUtils.base.getChildren(rSketchId, classcad_1.CCClasses.CCCurve, cDrawing.structure.tree));
|
|
531
|
+
if (sketchLines) {
|
|
532
|
+
const limit1Param = { value: limit1, isExpr: typeof limit1 === 'string' };
|
|
533
|
+
const limit2Param = { value: limit2, isExpr: typeof limit2 === 'string' };
|
|
534
|
+
const taperAngleParam = {
|
|
535
|
+
value: taperAngle,
|
|
536
|
+
isExpr: typeof taperAngle === 'string',
|
|
537
|
+
};
|
|
538
|
+
const directionParam = {
|
|
539
|
+
value: direction,
|
|
540
|
+
isExpr: typeof direction === 'string',
|
|
541
|
+
};
|
|
542
|
+
await featureAPI.updateExtrusion(drawingId, extrusion, sketchLines, type, limit1Param, limit2Param, taperAngleParam, directionParam, capEnds);
|
|
543
|
+
return extrusion;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
}, partId, sketchId);
|
|
547
|
+
},
|
|
548
|
+
revolve: (partId, sketchId, axisIds, angle1, angle2, inverted) => {
|
|
549
|
+
return this.resolve(async ([rPartId, rSketchId, ...rAxisIds]) => {
|
|
550
|
+
const revolve = await featureAPI.createRevolve(drawingId, rPartId);
|
|
551
|
+
if (revolve) {
|
|
552
|
+
const cDrawing = await (0, core_1.getDrawing)(drawingId);
|
|
553
|
+
const sketchLines = [];
|
|
554
|
+
sketchLines.push(...classcad_1.ccUtils.base.getChildren(rSketchId, classcad_1.CCClasses.CCCircle, cDrawing.structure.tree));
|
|
555
|
+
sketchLines.push(...classcad_1.ccUtils.base.getChildren(rSketchId, classcad_1.CCClasses.CCLine, cDrawing.structure.tree));
|
|
556
|
+
if (sketchLines) {
|
|
557
|
+
const angle1Param = { value: angle1, isExpr: typeof angle1 === 'string' };
|
|
558
|
+
const angle2Param = { value: angle2, isExpr: typeof angle2 === 'string' };
|
|
559
|
+
await featureAPI.updateRevolve(drawingId, revolve, sketchLines, rAxisIds, angle1Param, angle2Param, inverted);
|
|
560
|
+
return revolve;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
}, partId, sketchId, ...axisIds);
|
|
564
|
+
},
|
|
565
|
+
boolean: (partId, type, entities) => {
|
|
566
|
+
return this.resolve(async ([rPartId, rEntities]) => {
|
|
567
|
+
const cDrawing = await (0, core_1.getDrawing)(drawingId);
|
|
568
|
+
const entArray = [];
|
|
569
|
+
for (const rEntity of rEntities) {
|
|
570
|
+
const entity = cDrawing.structure.tree[(await rEntity)].children;
|
|
571
|
+
if (entity != undefined) {
|
|
572
|
+
entArray.push(entity[0]);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
const boolId = await featureAPI.createBooleanOperation(drawingId, rPartId, {
|
|
576
|
+
type,
|
|
577
|
+
entities: entArray,
|
|
578
|
+
});
|
|
579
|
+
if (boolId != null) {
|
|
580
|
+
await featureAPI.updateBooleanOperation(drawingId, boolId, type, entArray);
|
|
581
|
+
return boolId;
|
|
582
|
+
}
|
|
583
|
+
return null;
|
|
584
|
+
}, partId, entities);
|
|
585
|
+
},
|
|
586
|
+
box: (partId, references, width, length, height) => {
|
|
587
|
+
return this.resolve(async ([rPartId, ...rReferences]) => {
|
|
588
|
+
const boxId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCBox, 'Box');
|
|
589
|
+
if (boxId != null) {
|
|
590
|
+
const widthParam = { value: width, isExpr: typeof width === 'string' };
|
|
591
|
+
const lengthParam = { value: length, isExpr: typeof length === 'string' };
|
|
592
|
+
const heightParam = { value: height, isExpr: typeof height === 'string' };
|
|
593
|
+
await featureAPI.updateBox(drawingId, boxId, rReferences, widthParam, lengthParam, heightParam);
|
|
594
|
+
return boxId;
|
|
595
|
+
}
|
|
596
|
+
return null;
|
|
597
|
+
}, partId, ...references);
|
|
598
|
+
},
|
|
599
|
+
cylinder: (partId, references, diameter, height) => {
|
|
600
|
+
return this.resolve(async ([rPartId, ...rReferences]) => {
|
|
601
|
+
const cylId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCCylinder, 'Cylinder');
|
|
602
|
+
if (cylId != null) {
|
|
603
|
+
const diameterParam = { value: diameter, isExpr: typeof diameter === 'string' };
|
|
604
|
+
const heightParam = { value: height, isExpr: typeof height === 'string' };
|
|
605
|
+
await featureAPI.updateCylinder(drawingId, cylId, rReferences, diameterParam, heightParam);
|
|
606
|
+
return cylId;
|
|
607
|
+
}
|
|
608
|
+
return null;
|
|
609
|
+
}, partId, ...references);
|
|
610
|
+
},
|
|
611
|
+
chamfer: (partId, type, references, dist1, dist2, angle) => {
|
|
612
|
+
return this.resolve(async ([rPartId, rReferences]) => {
|
|
613
|
+
const dist1Param = { value: dist1, isExpr: typeof dist1 === 'string' };
|
|
614
|
+
const dist2Param = { value: dist2, isExpr: typeof dist2 === 'string' };
|
|
615
|
+
const angleParam = { value: angle, isExpr: typeof angle === 'string' };
|
|
616
|
+
const chamferId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCChamfer, 'Chamfer');
|
|
617
|
+
if (chamferId != null) {
|
|
618
|
+
await featureAPI.updateChamfer(drawingId, chamferId, type, rReferences, dist1Param, dist2Param, angleParam);
|
|
619
|
+
return chamferId;
|
|
620
|
+
}
|
|
621
|
+
return null;
|
|
622
|
+
}, partId, references);
|
|
623
|
+
},
|
|
624
|
+
cone: (partId, references, bDiameter, tDiameter, height) => {
|
|
625
|
+
return this.resolve(async ([rPartId, ...rReferences]) => {
|
|
626
|
+
const coneId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCCone, 'Cone');
|
|
627
|
+
if (coneId != null) {
|
|
628
|
+
const bDiamParam = { value: bDiameter, isExpr: typeof bDiameter === 'string' };
|
|
629
|
+
const tDiamParam = { value: tDiameter, isExpr: typeof tDiameter === 'string' };
|
|
630
|
+
const heightParam = { value: height, isExpr: typeof height === 'string' };
|
|
631
|
+
await featureAPI.updateCone(drawingId, coneId, rReferences, bDiamParam, tDiamParam, heightParam);
|
|
632
|
+
return coneId;
|
|
633
|
+
}
|
|
634
|
+
return null;
|
|
635
|
+
}, partId, ...references);
|
|
636
|
+
},
|
|
637
|
+
createFastenedConstraint: async (asmId, mate1, mate2, xOffset, yOffset, zOffset, name) => {
|
|
638
|
+
const [rAsmId, rWcs1, rWcs2] = await new Promise(res => this.resolve(ids => res(ids), asmId, mate1.wcsId, mate2.wcsId));
|
|
639
|
+
const rMatePath1 = await new Promise(res => this.resolve(paths => res(paths), ...mate1.matePath));
|
|
640
|
+
const rMatePath2 = await new Promise(res => this.resolve(paths => res(paths), ...mate2.matePath));
|
|
641
|
+
const constraintId = await classcad_1.ccAPI.assemblyBuilder.create3DConstraint(drawingId, rAsmId, classcad_1.CCClasses.CCFastenedConstraint, name);
|
|
642
|
+
if (constraintId != null) {
|
|
643
|
+
const xOffsetParam = { value: xOffset, isExpr: typeof xOffset === 'string' };
|
|
644
|
+
const yOffsetParam = { value: yOffset, isExpr: typeof yOffset === 'string' };
|
|
645
|
+
const zOffsetParam = { value: zOffset, isExpr: typeof zOffset === 'string' };
|
|
646
|
+
await classcad_1.ccAPI.assemblyBuilder.updateFastenedConstraint(drawingId, constraintId, { matePath: rMatePath1, wcsId: rWcs1, flip: mate1.flip, reoriented: mate1.reoriented }, { matePath: rMatePath2, wcsId: rWcs2, flip: mate2.flip, reoriented: mate2.reoriented }, xOffsetParam, yOffsetParam, zOffsetParam);
|
|
647
|
+
return constraintId;
|
|
648
|
+
}
|
|
649
|
+
return null;
|
|
650
|
+
},
|
|
651
|
+
updateFastenedConstraint: async (constrId, mate1, mate2, xOffset, yOffset, zOffset) => {
|
|
652
|
+
const [rConstrId, rWcs1, rWcs2] = await new Promise(res => this.resolve(ids => res(ids), constrId, mate1.wcsId, mate2.wcsId));
|
|
653
|
+
const rMatePath1 = await new Promise(res => this.resolve(paths => res(paths), ...mate1.matePath));
|
|
654
|
+
const rMatePath2 = await new Promise(res => this.resolve(paths => res(paths), ...mate2.matePath));
|
|
655
|
+
const xOffsetParam = { value: xOffset, isExpr: typeof xOffset === 'string' };
|
|
656
|
+
const yOffsetParam = { value: yOffset, isExpr: typeof xOffset === 'string' };
|
|
657
|
+
const zOffsetParam = { value: zOffset, isExpr: typeof xOffset === 'string' };
|
|
658
|
+
await classcad_1.ccAPI.assemblyBuilder.updateFastenedConstraint(drawingId, rConstrId, { matePath: rMatePath1, wcsId: rWcs1, flip: mate1.flip, reoriented: mate1.reoriented }, { matePath: rMatePath2, wcsId: rWcs2, flip: mate2.flip, reoriented: mate2.reoriented }, xOffsetParam, yOffsetParam, zOffsetParam);
|
|
659
|
+
},
|
|
660
|
+
updateFastenedConstraints: async (...constraints) => {
|
|
661
|
+
var e_3, _a;
|
|
662
|
+
const constrToAdd = [];
|
|
663
|
+
try {
|
|
664
|
+
for (var constraints_1 = __asyncValues(constraints), constraints_1_1; constraints_1_1 = await constraints_1.next(), !constraints_1_1.done;) {
|
|
665
|
+
const constr = constraints_1_1.value;
|
|
666
|
+
const [rConstrId, rWcs1, rWcs2] = await new Promise(res => this.resolve(ids => res(ids), constr.constrId, constr.mate1.wcsId, constr.mate2.wcsId));
|
|
667
|
+
const rMatePath1 = await new Promise(res => this.resolve(paths => res(paths), ...constr.mate1.matePath));
|
|
668
|
+
const rMatePath2 = await new Promise(res => this.resolve(paths => res(paths), ...constr.mate2.matePath));
|
|
669
|
+
const xOffsetParam = { value: constr.xOffset, isExpr: typeof constr.xOffset === 'string' };
|
|
670
|
+
const yOffsetParam = { value: constr.yOffset, isExpr: typeof constr.yOffset === 'string' };
|
|
671
|
+
const zOffsetParam = { value: constr.zOffset, isExpr: typeof constr.zOffset === 'string' };
|
|
672
|
+
constrToAdd.push({
|
|
673
|
+
constrId: rConstrId,
|
|
674
|
+
mate1: {
|
|
675
|
+
matePath: rMatePath1,
|
|
676
|
+
wcsId: rWcs1,
|
|
677
|
+
flip: constr.mate1.flip,
|
|
678
|
+
reoriented: constr.mate1.reoriented,
|
|
679
|
+
},
|
|
680
|
+
mate2: {
|
|
681
|
+
matePath: rMatePath2,
|
|
682
|
+
wcsId: rWcs2,
|
|
683
|
+
flip: constr.mate2.flip,
|
|
684
|
+
reoriented: constr.mate2.reoriented,
|
|
685
|
+
},
|
|
686
|
+
xOffset: xOffsetParam,
|
|
687
|
+
yOffset: yOffsetParam,
|
|
688
|
+
zOffset: zOffsetParam,
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
693
|
+
finally {
|
|
694
|
+
try {
|
|
695
|
+
if (constraints_1_1 && !constraints_1_1.done && (_a = constraints_1.return)) await _a.call(constraints_1);
|
|
696
|
+
}
|
|
697
|
+
finally { if (e_3) throw e_3.error; }
|
|
698
|
+
}
|
|
699
|
+
await classcad_1.ccAPI.assemblyBuilder.updateFastenedConstraints(drawingId, constrToAdd);
|
|
700
|
+
},
|
|
701
|
+
createFastenedOriginConstraint: async (asmId, mate1, xOffset, yOffset, zOffset, name) => {
|
|
702
|
+
const [rAsmId, rWcs1] = await new Promise(res => this.resolve(ids => res(ids), asmId, mate1.wcsId));
|
|
703
|
+
const rMatePath = await new Promise(res => this.resolve(paths => res(paths), ...mate1.matePath));
|
|
704
|
+
const constraintId = await classcad_1.ccAPI.assemblyBuilder.create3DConstraint(drawingId, rAsmId, classcad_1.CCClasses.CCFastenedOriginConstraint, name);
|
|
705
|
+
if (constraintId != null) {
|
|
706
|
+
const xOffsetParam = { value: xOffset, isExpr: typeof xOffset === 'string' };
|
|
707
|
+
const yOffsetParam = { value: yOffset, isExpr: typeof yOffset === 'string' };
|
|
708
|
+
const zOffsetParam = { value: zOffset, isExpr: typeof zOffset === 'string' };
|
|
709
|
+
await classcad_1.ccAPI.assemblyBuilder.updateFastenedOriginConstraint(drawingId, constraintId, { matePath: rMatePath, wcsId: rWcs1, flip: mate1.flip, reoriented: mate1.reoriented }, xOffsetParam, yOffsetParam, zOffsetParam);
|
|
710
|
+
return constraintId;
|
|
711
|
+
}
|
|
712
|
+
return null;
|
|
713
|
+
},
|
|
714
|
+
updateFastenedOriginConstraint: async (constrId, mate1, xOffset, yOffset, zOffset) => {
|
|
715
|
+
const [rConstrId, rWcs1] = await new Promise(res => this.resolve(ids => res(ids), constrId, mate1.wcsId));
|
|
716
|
+
const rMatePath = await new Promise(res => this.resolve(paths => res(paths), ...mate1.matePath));
|
|
717
|
+
const xOffsetParam = { value: xOffset, isExpr: typeof xOffset === 'string' };
|
|
718
|
+
const yOffsetParam = { value: yOffset, isExpr: typeof yOffset === 'string' };
|
|
719
|
+
const zOffsetParam = { value: zOffset, isExpr: typeof zOffset === 'string' };
|
|
720
|
+
await classcad_1.ccAPI.assemblyBuilder.updateFastenedOriginConstraint(drawingId, rConstrId, { matePath: rMatePath, wcsId: rWcs1, flip: mate1.flip, reoriented: mate1.reoriented }, xOffsetParam, yOffsetParam, zOffsetParam);
|
|
721
|
+
},
|
|
722
|
+
updateFastenedOriginConstraints: async (...constraints) => {
|
|
723
|
+
var e_4, _a;
|
|
724
|
+
const constraintsToAdd = [];
|
|
725
|
+
try {
|
|
726
|
+
for (var constraints_2 = __asyncValues(constraints), constraints_2_1; constraints_2_1 = await constraints_2.next(), !constraints_2_1.done;) {
|
|
727
|
+
const constr = constraints_2_1.value;
|
|
728
|
+
const [rConstrId, rWcs1] = await new Promise(res => this.resolve(ids => res(ids), constr.constrId, constr.mate1.wcsId));
|
|
729
|
+
const rMatePath = await new Promise(res => this.resolve(paths => res(paths), ...constr.mate1.matePath));
|
|
730
|
+
const xOffsetParam = { value: constr.xOffset, isExpr: typeof constr.xOffset === 'string' };
|
|
731
|
+
const yOffsetParam = { value: constr.yOffset, isExpr: typeof constr.yOffset === 'string' };
|
|
732
|
+
const zOffsetParam = { value: constr.zOffset, isExpr: typeof constr.zOffset === 'string' };
|
|
733
|
+
constraintsToAdd.push({
|
|
734
|
+
constrId: rConstrId,
|
|
735
|
+
mate1: {
|
|
736
|
+
matePath: rMatePath,
|
|
737
|
+
wcsId: rWcs1,
|
|
738
|
+
flip: constr.mate1.flip,
|
|
739
|
+
reoriented: constr.mate1.reoriented,
|
|
740
|
+
},
|
|
741
|
+
xOffset: xOffsetParam,
|
|
742
|
+
yOffset: yOffsetParam,
|
|
743
|
+
zOffset: zOffsetParam,
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
748
|
+
finally {
|
|
749
|
+
try {
|
|
750
|
+
if (constraints_2_1 && !constraints_2_1.done && (_a = constraints_2.return)) await _a.call(constraints_2);
|
|
751
|
+
}
|
|
752
|
+
finally { if (e_4) throw e_4.error; }
|
|
753
|
+
}
|
|
754
|
+
await classcad_1.ccAPI.assemblyBuilder.updateFastenedOriginConstraints(drawingId, constraintsToAdd);
|
|
755
|
+
},
|
|
756
|
+
createBufferGeometry: async (objectId) => {
|
|
757
|
+
await this.queue;
|
|
758
|
+
this.queue = Promise.resolve(0);
|
|
759
|
+
const rObjectId = await objectId;
|
|
760
|
+
const cDrawing = (0, core_1.getDrawing)(drawingId);
|
|
761
|
+
const structureTree = cDrawing.structure.tree;
|
|
762
|
+
const bufferGeomArray = [];
|
|
763
|
+
if (rObjectId != null) {
|
|
764
|
+
const rootObj = structureTree[rObjectId];
|
|
765
|
+
await createRecursiveBufferGeometry(rootObj, drawingId, bufferGeomArray);
|
|
766
|
+
if (bufferGeomArray.length > 0) {
|
|
767
|
+
return bufferGeomArray;
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
return undefined;
|
|
771
|
+
},
|
|
772
|
+
createScene: async (objectId, options) => {
|
|
773
|
+
await this.queue;
|
|
774
|
+
this.queue = Promise.resolve(0);
|
|
775
|
+
const rObjectId = await objectId;
|
|
776
|
+
const cDrawing = (0, core_1.getDrawing)(drawingId);
|
|
777
|
+
const structureTree = cDrawing.structure.tree;
|
|
778
|
+
const scene = new three_1.Scene();
|
|
779
|
+
if (rObjectId != null) {
|
|
780
|
+
const rootObj = structureTree[rObjectId];
|
|
781
|
+
if (rootObj) {
|
|
782
|
+
await createRecursiveScene(rootObj, drawingId, scene, options);
|
|
783
|
+
}
|
|
784
|
+
else {
|
|
785
|
+
throw new Error('Root object does not exist!');
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
return scene;
|
|
789
|
+
},
|
|
790
|
+
createExpressions: (partId, ...members) => {
|
|
791
|
+
return this.resolve(async ([rPartId]) => {
|
|
792
|
+
const membersToAdd = [];
|
|
793
|
+
members.forEach(mem => {
|
|
794
|
+
const isExpr = typeof mem.value === 'string'; // TODO Expression unterscheiden von normalen STrings
|
|
795
|
+
const dataType = classcad_1.DataType.REAL; // TODO: Aktuell nur Real Werte als Expression
|
|
796
|
+
const featureAPIParam = {
|
|
797
|
+
value: mem.value,
|
|
798
|
+
isExpr: isExpr,
|
|
799
|
+
};
|
|
800
|
+
membersToAdd.push({ name: mem.name, value: featureAPIParam, dataType });
|
|
801
|
+
});
|
|
802
|
+
const success = featureAPI.updateExpressionSet(drawingId, rPartId, membersToAdd, [], []);
|
|
803
|
+
return success;
|
|
804
|
+
}, partId);
|
|
805
|
+
},
|
|
806
|
+
createAssemblyAsTemplate: (name) => {
|
|
807
|
+
return this.resolve(async ([]) => {
|
|
808
|
+
return await classcad_1.ccAPI.assemblyBuilder.createAssemblyAsTemplate(drawingId, name);
|
|
809
|
+
});
|
|
810
|
+
},
|
|
811
|
+
createRootAssembly: (name) => {
|
|
812
|
+
return this.resolve(async ([]) => {
|
|
813
|
+
return await classcad_1.ccAPI.assemblyBuilder.createRootAssembly(drawingId, name);
|
|
814
|
+
});
|
|
815
|
+
},
|
|
816
|
+
createPart: (name) => {
|
|
817
|
+
return this.resolve(async ([]) => {
|
|
818
|
+
const partName = name ? name : 'Part';
|
|
819
|
+
return await featureAPI.newPart(drawingId, partName);
|
|
820
|
+
});
|
|
821
|
+
},
|
|
822
|
+
createPartAsTemplate: (name) => {
|
|
823
|
+
return this.resolve(async ([]) => {
|
|
824
|
+
const partName = name ? name : 'Part';
|
|
825
|
+
return await classcad_1.ccAPI.assemblyBuilder.createPartAsTemplate(drawingId, partName);
|
|
826
|
+
});
|
|
827
|
+
},
|
|
828
|
+
createWorkAxis: (partId, type, references, position, direction, local, name) => {
|
|
829
|
+
return this.resolve(async ([rPartId, ...rReferences]) => {
|
|
830
|
+
const wAName = name ? name : 'WorkAxis';
|
|
831
|
+
const wAId = await featureAPI.createWorkGeometry(drawingId, rPartId, classcad_1.CCClasses.CCWorkAxis, wAName);
|
|
832
|
+
if (wAId != null) {
|
|
833
|
+
const positionParam = {
|
|
834
|
+
value: position,
|
|
835
|
+
isExpr: typeof position === 'string',
|
|
836
|
+
};
|
|
837
|
+
const directionParam = {
|
|
838
|
+
value: direction,
|
|
839
|
+
isExpr: typeof direction === 'string',
|
|
840
|
+
};
|
|
841
|
+
await featureAPI.updateWorkAxis(drawingId, wAId, type, rReferences, positionParam, directionParam, local);
|
|
842
|
+
return wAId;
|
|
843
|
+
}
|
|
844
|
+
return null;
|
|
845
|
+
}, partId, ...references);
|
|
846
|
+
},
|
|
847
|
+
createWorkCoordSystem: (partId, type, references, coordinateSystem, offset, rotation, inverted, local, name) => {
|
|
848
|
+
return this.resolve(async ([rPartId, ...rReferences]) => {
|
|
849
|
+
const wCSName = name ? name : 'WorkCoordSystem';
|
|
850
|
+
const wCSId = await featureAPI.createWorkGeometry(drawingId, rPartId, classcad_1.CCClasses.CCWorkCoordSystem, wCSName);
|
|
851
|
+
if (wCSId != null) {
|
|
852
|
+
const offsetParam = { value: offset, isExpr: typeof offset === 'string' };
|
|
853
|
+
const rotationParam = {
|
|
854
|
+
value: rotation,
|
|
855
|
+
isExpr: typeof rotation === 'string',
|
|
856
|
+
};
|
|
857
|
+
await featureAPI.updateWorkCoordSystem(drawingId, wCSId, type, rReferences, coordinateSystem, offsetParam, rotationParam, inverted, local);
|
|
858
|
+
return wCSId;
|
|
859
|
+
}
|
|
860
|
+
return null;
|
|
861
|
+
}, partId, ...references);
|
|
862
|
+
},
|
|
863
|
+
createWorkPlane: (partId, type, references, offset, angle, position, normal, local, name) => {
|
|
864
|
+
return this.resolve(async ([rPartId, ...rReferences]) => {
|
|
865
|
+
const wPName = name ? name : 'WorkPlane';
|
|
866
|
+
const wPId = await featureAPI.createWorkGeometry(drawingId, rPartId, classcad_1.CCClasses.CCWorkPlane, wPName);
|
|
867
|
+
if (wPId != undefined) {
|
|
868
|
+
const offsetParam = { value: offset, isExpr: typeof offset === 'string' };
|
|
869
|
+
const angleParam = { value: angle, isExpr: typeof angle === 'string' };
|
|
870
|
+
const positionParam = {
|
|
871
|
+
value: position,
|
|
872
|
+
isExpr: typeof position === 'string',
|
|
873
|
+
};
|
|
874
|
+
const normalParam = { value: normal, isExpr: typeof normal === 'string' };
|
|
875
|
+
await featureAPI.updateWorkPlane(drawingId, wPId, type, rReferences, offsetParam, angleParam, positionParam, normalParam, local);
|
|
876
|
+
return wPId;
|
|
877
|
+
}
|
|
878
|
+
return null;
|
|
879
|
+
}, partId, ...references);
|
|
880
|
+
},
|
|
881
|
+
createWorkPoint: (partId, type, references, position, local, name) => {
|
|
882
|
+
return this.resolve(async ([rPartId, ...rReferences]) => {
|
|
883
|
+
const wPTName = name ? name : 'WorkPoint';
|
|
884
|
+
const wPTId = await featureAPI.createWorkGeometry(drawingId, rPartId, classcad_1.CCClasses.CCWorkPoint, wPTName);
|
|
885
|
+
if (wPTId != undefined) {
|
|
886
|
+
const positionParam = {
|
|
887
|
+
value: position,
|
|
888
|
+
isExpr: typeof position === 'string',
|
|
889
|
+
};
|
|
890
|
+
await featureAPI.updateWorkPoint(drawingId, wPTId, type, rReferences, positionParam, local);
|
|
891
|
+
return wPTId;
|
|
892
|
+
}
|
|
893
|
+
return null;
|
|
894
|
+
}, partId, ...references);
|
|
895
|
+
},
|
|
896
|
+
fillet: (partId, references, radius) => {
|
|
897
|
+
return this.resolve(async ([rPartId, rReferences]) => {
|
|
898
|
+
const radiusParam = { value: radius, isExpr: typeof radius === 'string' };
|
|
899
|
+
const filletId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCConstantRadiusFillet, 'Fillet');
|
|
900
|
+
if (filletId != null) {
|
|
901
|
+
await featureAPI.updateFillet(drawingId, filletId, rReferences, radiusParam);
|
|
902
|
+
return filletId;
|
|
903
|
+
}
|
|
904
|
+
return null;
|
|
905
|
+
}, partId, references);
|
|
906
|
+
},
|
|
907
|
+
findOrSelect: (partId, type, length, positions) => {
|
|
908
|
+
return this.resolve(async ([rPartId]) => {
|
|
909
|
+
let filter = core_1.lineSegmentsFilter;
|
|
910
|
+
switch (type) {
|
|
911
|
+
case 0: // Vertex
|
|
912
|
+
filter = core_1.pointFilter;
|
|
913
|
+
break;
|
|
914
|
+
case 1: // Edge
|
|
915
|
+
filter = core_1.lineSegmentsFilter;
|
|
916
|
+
break;
|
|
917
|
+
case 2: // Loop
|
|
918
|
+
filter = core_1.loopFilter;
|
|
919
|
+
break;
|
|
920
|
+
case 3: // Face
|
|
921
|
+
filter = core_1.planeFilter;
|
|
922
|
+
break;
|
|
923
|
+
}
|
|
924
|
+
const geometries = positions
|
|
925
|
+
? await classcad_1.ccAPI.geometry.findGeometriesByPoints(drawingId, rPartId, type, positions)
|
|
926
|
+
: await (0, selection_1.waitForSelect)(length, filter, (resolveSelection, items, diff) => {
|
|
927
|
+
if (items.length > length - 1) {
|
|
928
|
+
resolveSelection(items.map(i => i.data.graphicId));
|
|
929
|
+
classcad_1.ccAPI.geometry
|
|
930
|
+
.getPointsByGeometries(drawingId, items.map(i => i.data.graphicId))
|
|
931
|
+
.then(points => {
|
|
932
|
+
logPoints(points);
|
|
933
|
+
});
|
|
934
|
+
}
|
|
935
|
+
});
|
|
936
|
+
return geometries;
|
|
937
|
+
}, partId);
|
|
938
|
+
},
|
|
939
|
+
getAssemblyFromContainer: (asmName) => {
|
|
940
|
+
return this.resolve(async ([]) => {
|
|
941
|
+
const asmIds = classcad_1.ccUtils.assembly.getAssemblyFromContainer(drawingId, asmName);
|
|
942
|
+
if (asmIds != undefined) {
|
|
943
|
+
return Array.isArray(asmIds) ? asmIds : [asmIds];
|
|
944
|
+
}
|
|
945
|
+
return null;
|
|
946
|
+
});
|
|
947
|
+
},
|
|
948
|
+
getAssemblyNode: (refId, nodeName) => {
|
|
949
|
+
return this.resolve(async ([rRefId]) => {
|
|
950
|
+
const nodeIds = classcad_1.ccUtils.assembly.getAssemblyNode(drawingId, rRefId, nodeName);
|
|
951
|
+
if (nodeIds != undefined) {
|
|
952
|
+
return Array.isArray(nodeIds) ? nodeIds : [nodeIds];
|
|
953
|
+
}
|
|
954
|
+
return null;
|
|
955
|
+
}, refId);
|
|
956
|
+
},
|
|
957
|
+
setCurrentNode: (refId) => {
|
|
958
|
+
return this.resolve(async ([rRefId]) => {
|
|
959
|
+
await classcad_1.ccAPI.assemblyBuilder.setCurrentNode(drawingId, rRefId);
|
|
960
|
+
}, refId);
|
|
961
|
+
},
|
|
962
|
+
getCurrentNode: () => {
|
|
963
|
+
return this.resolve(async () => {
|
|
964
|
+
const drw = (0, core_1.getDrawing)(drawingId);
|
|
965
|
+
return drw.structure.currentNode;
|
|
966
|
+
});
|
|
967
|
+
},
|
|
968
|
+
getCoordSysFromNode: (refId) => {
|
|
969
|
+
return this.resolve(async ([rRefId]) => {
|
|
970
|
+
const coordSys = classcad_1.ccUtils.assembly.getCoordSysFromNode(drawingId, rRefId);
|
|
971
|
+
if (coordSys != undefined) {
|
|
972
|
+
return coordSys;
|
|
973
|
+
}
|
|
974
|
+
return null;
|
|
975
|
+
}, refId);
|
|
976
|
+
},
|
|
977
|
+
setCurrentProduct: (productId) => {
|
|
978
|
+
return this.resolve(async ([rProductId]) => {
|
|
979
|
+
await classcad_1.ccAPI.baseModeler.setCurrentProduct(drawingId, rProductId);
|
|
980
|
+
}, productId);
|
|
981
|
+
},
|
|
982
|
+
getCurrentProduct: () => {
|
|
983
|
+
return this.resolve(async () => {
|
|
984
|
+
const drw = (0, core_1.getDrawing)(drawingId);
|
|
985
|
+
return drw.structure.currentProduct;
|
|
986
|
+
});
|
|
987
|
+
},
|
|
988
|
+
getPartFromContainer: (partName) => {
|
|
989
|
+
return this.resolve(async ([]) => {
|
|
990
|
+
const partIds = classcad_1.ccUtils.assembly.getPartFromContainer(drawingId, partName);
|
|
991
|
+
if (partIds != undefined) {
|
|
992
|
+
return Array.isArray(partIds) ? partIds : [partIds];
|
|
993
|
+
}
|
|
994
|
+
return null;
|
|
995
|
+
});
|
|
996
|
+
},
|
|
997
|
+
getWorkCoordSystem: (refId, wcsName) => {
|
|
998
|
+
return this.resolve(async ([rRefId]) => {
|
|
999
|
+
const wcsIds = classcad_1.ccUtils.assembly.getWorkCoordSystem(drawingId, rRefId, wcsName);
|
|
1000
|
+
if (wcsIds != undefined) {
|
|
1001
|
+
return Array.isArray(wcsIds) ? wcsIds : [wcsIds];
|
|
1002
|
+
}
|
|
1003
|
+
return null;
|
|
1004
|
+
}, refId);
|
|
1005
|
+
},
|
|
1006
|
+
getConstraint: (refId, constrName) => {
|
|
1007
|
+
return this.resolve(async ([rRefId]) => {
|
|
1008
|
+
const constrIds = classcad_1.ccUtils.assembly.getConstraint(drawingId, rRefId, constrName);
|
|
1009
|
+
if (constrIds != undefined) {
|
|
1010
|
+
return Array.isArray(constrIds) ? constrIds : [constrIds];
|
|
1011
|
+
}
|
|
1012
|
+
return null;
|
|
1013
|
+
}, refId);
|
|
1014
|
+
},
|
|
1015
|
+
getFeatureByName: (partId, featureName) => {
|
|
1016
|
+
return this.resolve(async ([rProductId]) => {
|
|
1017
|
+
const feature = await featureAPI.getFeatureByName(drawingId, rProductId, featureName);
|
|
1018
|
+
if (feature !== null) {
|
|
1019
|
+
return feature;
|
|
1020
|
+
}
|
|
1021
|
+
return null;
|
|
1022
|
+
}, partId);
|
|
1023
|
+
},
|
|
1024
|
+
removeNode: (referenceId, ownerId) => {
|
|
1025
|
+
return this.resolve(async ([rReferenceId, rOwnerId]) => {
|
|
1026
|
+
await classcad_1.ccAPI.assemblyBuilder.removeNode(drawingId, rReferenceId, rOwnerId);
|
|
1027
|
+
}, referenceId, ownerId);
|
|
1028
|
+
},
|
|
1029
|
+
removeNodes: (...nodes) => {
|
|
1030
|
+
return this.resolve(async ([...rNodes]) => {
|
|
1031
|
+
const nodesToRemove = [];
|
|
1032
|
+
rNodes.forEach(node => {
|
|
1033
|
+
nodesToRemove.push([node.referenceId, node.ownerId]);
|
|
1034
|
+
});
|
|
1035
|
+
return classcad_1.ccAPI.assemblyBuilder.removeNodes(drawingId, nodesToRemove);
|
|
1036
|
+
}, ...nodes);
|
|
1037
|
+
},
|
|
1038
|
+
importFeature: (partId, content, format, name) => {
|
|
1039
|
+
return this.resolve(async ([rPartId]) => {
|
|
1040
|
+
const featureName = name ? name : 'Import';
|
|
1041
|
+
const importFeatureId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCImport, featureName);
|
|
1042
|
+
if (importFeatureId !== null) {
|
|
1043
|
+
const solids = await featureAPI.updateImport(drawingId, importFeatureId, content, format, featureName);
|
|
1044
|
+
if (solids !== null) {
|
|
1045
|
+
return importFeatureId;
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
return null;
|
|
1049
|
+
}, partId);
|
|
1050
|
+
},
|
|
1051
|
+
loadSketch: (partId, stream, planeId, name) => {
|
|
1052
|
+
return this.resolve(async ([rPartId, rPlaneId]) => {
|
|
1053
|
+
const sketch = await sketcherAPI.createSketch(drawingId, rPartId);
|
|
1054
|
+
if (sketch) {
|
|
1055
|
+
await featureAPI.closeFeature(drawingId, sketch);
|
|
1056
|
+
const tree = (0, core_1.getDrawing)(drawingId).structure.tree;
|
|
1057
|
+
const plane = tree[rPlaneId];
|
|
1058
|
+
if (plane && base.isA(plane.class, classcad_1.CCClasses.CCWorkPlane)) {
|
|
1059
|
+
await sketcherAPI.setWorkPlane(drawingId, sketch, rPlaneId);
|
|
1060
|
+
}
|
|
1061
|
+
else {
|
|
1062
|
+
await sketcherAPI.createAndSetWorkPlane(drawingId, sketch, rPlaneId);
|
|
1063
|
+
}
|
|
1064
|
+
await sketcherAPI.loadSketch(drawingId, rPartId, sketch, stream, name);
|
|
1065
|
+
return sketch;
|
|
1066
|
+
}
|
|
1067
|
+
}, partId, planeId);
|
|
1068
|
+
},
|
|
1069
|
+
copySketch: (partId, sketchId, planeId) => {
|
|
1070
|
+
return this.resolve(async ([rPartId, rPlaneId, rSketchId]) => {
|
|
1071
|
+
const sketch = await sketcherAPI.createSketch(drawingId, rPartId);
|
|
1072
|
+
if (sketch) {
|
|
1073
|
+
await featureAPI.closeFeature(drawingId, sketch);
|
|
1074
|
+
const tree = (0, core_1.getDrawing)(drawingId).structure.tree;
|
|
1075
|
+
const plane = tree[rPlaneId];
|
|
1076
|
+
if (plane && base.isA(plane.class, classcad_1.CCClasses.CCWorkPlane)) {
|
|
1077
|
+
await sketcherAPI.setWorkPlane(drawingId, sketch, rPlaneId);
|
|
1078
|
+
}
|
|
1079
|
+
else {
|
|
1080
|
+
await sketcherAPI.createAndSetWorkPlane(drawingId, sketch, rPlaneId);
|
|
1081
|
+
}
|
|
1082
|
+
await sketcherAPI.copySketch(drawingId, sketch, rSketchId);
|
|
1083
|
+
return sketch;
|
|
1084
|
+
}
|
|
1085
|
+
}, partId, planeId, sketchId);
|
|
1086
|
+
},
|
|
1087
|
+
placeSketch: (sketchId, planeId, invertPlane, axisId, isXAxis, invertAxis, originId) => {
|
|
1088
|
+
return this.resolve(async ([rSketchId, rPlaneId, rAxisId, rOriginId]) => {
|
|
1089
|
+
await sketcherAPI.setSketchRefs(drawingId, rSketchId, rPlaneId, invertPlane, rAxisId, isXAxis, invertAxis, rOriginId);
|
|
1090
|
+
}, sketchId, planeId, axisId, originId);
|
|
1091
|
+
},
|
|
1092
|
+
transformNode: (referenceId, ownerId, transformation) => {
|
|
1093
|
+
return this.resolve(async ([rRefId, rOwnerId]) => {
|
|
1094
|
+
await classcad_1.ccAPI.assemblyBuilder.setNodeTransformation(drawingId, rRefId, rOwnerId, transformation);
|
|
1095
|
+
}, referenceId, ownerId);
|
|
1096
|
+
},
|
|
1097
|
+
translate: (partId, featureIds, references, inverted, distance) => {
|
|
1098
|
+
return this.resolve(async ([rPartId, rFeatureIds, ...rReferences]) => {
|
|
1099
|
+
const translationId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCTranslation, 'Translate');
|
|
1100
|
+
if (translationId !== null) {
|
|
1101
|
+
const cDrawing = await (0, core_1.getDrawing)(drawingId);
|
|
1102
|
+
const entArray = [];
|
|
1103
|
+
for (const rFeatureId of rFeatureIds) {
|
|
1104
|
+
const entity = cDrawing.structure.tree[(await rFeatureId)].children;
|
|
1105
|
+
if (entity != undefined) {
|
|
1106
|
+
entArray.push(entity[0]);
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
const dist = { value: distance, isExpr: typeof distance === 'string' };
|
|
1110
|
+
await featureAPI.updateTransformation(drawingId, translationId, entArray, rReferences, inverted, dist);
|
|
1111
|
+
return translationId;
|
|
1112
|
+
}
|
|
1113
|
+
return null;
|
|
1114
|
+
}, partId, featureIds, ...references);
|
|
1115
|
+
},
|
|
1116
|
+
// TODO: Remove this method. Is it necessary?
|
|
1117
|
+
updateTranslate: (translationId, distance) => {
|
|
1118
|
+
return this.resolve(async ([rTranslationId]) => {
|
|
1119
|
+
const cDrawing = await (0, core_1.getDrawing)(drawingId);
|
|
1120
|
+
const members = cDrawing.structure.tree[rTranslationId].members;
|
|
1121
|
+
if (members !== null && members !== undefined) {
|
|
1122
|
+
const entArray = members['bodiesToTransform'].members.map(m => m.value);
|
|
1123
|
+
const references = members['references'].members.map(m => m.value);
|
|
1124
|
+
const inverted = members['inverted'].value;
|
|
1125
|
+
const dist = distance !== null ? distance : members['translationDistance'].value;
|
|
1126
|
+
const distParam = { value: dist, isExpr: typeof distance === 'string' };
|
|
1127
|
+
await featureAPI.openFeature(drawingId, rTranslationId);
|
|
1128
|
+
await featureAPI.updateTransformation(drawingId, rTranslationId, entArray, references, inverted, distParam);
|
|
1129
|
+
await featureAPI.closeFeature(drawingId, rTranslationId);
|
|
1130
|
+
}
|
|
1131
|
+
}, translationId);
|
|
1132
|
+
},
|
|
1133
|
+
save: (type) => {
|
|
1134
|
+
return classcad_1.ccAPI.baseModeler.save(drawingId, type);
|
|
1135
|
+
},
|
|
1136
|
+
saveToUrl: (url, filetype) => {
|
|
1137
|
+
return classcad_1.ccAPI.baseModeler.saveToUrl(drawingId, url, filetype);
|
|
1138
|
+
},
|
|
1139
|
+
load: (content, type) => {
|
|
1140
|
+
return classcad_1.ccAPI.baseModeler.load(drawingId, content, type);
|
|
1141
|
+
},
|
|
1142
|
+
loadFromUrl: (url, filetype) => {
|
|
1143
|
+
return classcad_1.ccAPI.baseModeler.loadFromUrl(drawingId, url, filetype, true);
|
|
1144
|
+
},
|
|
1145
|
+
loadProduct: (content, type) => {
|
|
1146
|
+
return classcad_1.ccAPI.assemblyBuilder.loadProduct(drawingId, content, type);
|
|
1147
|
+
},
|
|
1148
|
+
loadProductFromUrl: (url, filetype) => {
|
|
1149
|
+
return classcad_1.ccAPI.assemblyBuilder.loadProductFromUrl(drawingId, url, filetype);
|
|
1150
|
+
},
|
|
1151
|
+
pick: (partId, type, points) => {
|
|
1152
|
+
return this.resolve(async ([rPartId]) => {
|
|
1153
|
+
const refs = await featureAPI.pick(drawingId, rPartId, type, points);
|
|
1154
|
+
if (refs != undefined) {
|
|
1155
|
+
return Array.isArray(refs) ? refs : [refs];
|
|
1156
|
+
}
|
|
1157
|
+
return null;
|
|
1158
|
+
}, partId);
|
|
1159
|
+
},
|
|
1160
|
+
setExpressions: (partId, ...members) => {
|
|
1161
|
+
return this.resolve(async ([rPartId]) => {
|
|
1162
|
+
const membersToModify = [];
|
|
1163
|
+
members.forEach(mem => {
|
|
1164
|
+
const isExpr = typeof mem.value === 'string'; // TODO Expression unterscheiden von normalen Strings
|
|
1165
|
+
const featureAPIParam = {
|
|
1166
|
+
value: mem.value,
|
|
1167
|
+
isExpr,
|
|
1168
|
+
};
|
|
1169
|
+
membersToModify.push({ name: mem.name, value: featureAPIParam });
|
|
1170
|
+
});
|
|
1171
|
+
const success = featureAPI.updateExpressionSet(drawingId, rPartId, [], membersToModify, []);
|
|
1172
|
+
return success;
|
|
1173
|
+
}, partId);
|
|
1174
|
+
},
|
|
1175
|
+
setExpressionSets: (...exprSets) => {
|
|
1176
|
+
return this.resolve(async ([...rExprSets]) => {
|
|
1177
|
+
const exprSetsToSet = [];
|
|
1178
|
+
rExprSets.forEach(exprSet => {
|
|
1179
|
+
const membersToModify = [];
|
|
1180
|
+
exprSet.members.forEach((mem) => {
|
|
1181
|
+
const isExpr = typeof mem.value === 'string'; // TODO Expression unterscheiden von normalen Strings
|
|
1182
|
+
const featureAPIParam = {
|
|
1183
|
+
value: mem.value,
|
|
1184
|
+
isExpr,
|
|
1185
|
+
};
|
|
1186
|
+
membersToModify.push({ name: mem.name, value: featureAPIParam });
|
|
1187
|
+
});
|
|
1188
|
+
exprSetsToSet.push({
|
|
1189
|
+
productId: exprSet.partId,
|
|
1190
|
+
toAddMembers: [],
|
|
1191
|
+
toModifyMembers: membersToModify,
|
|
1192
|
+
toDeleteList: [],
|
|
1193
|
+
});
|
|
1194
|
+
});
|
|
1195
|
+
const success = await featureAPI.updateExpressionSets(drawingId, exprSetsToSet);
|
|
1196
|
+
return success;
|
|
1197
|
+
}, ...exprSets);
|
|
1198
|
+
},
|
|
1199
|
+
deleteExpressions: (partId, members) => {
|
|
1200
|
+
return this.resolve(async ([rPartId]) => {
|
|
1201
|
+
const success = featureAPI.updateExpressionSet(drawingId, rPartId, [], [], members);
|
|
1202
|
+
return success;
|
|
1203
|
+
}, partId);
|
|
1204
|
+
},
|
|
1205
|
+
sphere: (partId, references, radius) => {
|
|
1206
|
+
return this.resolve(async ([rPartId, ...rReferences]) => {
|
|
1207
|
+
const sphereId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCSphere, 'Sphere');
|
|
1208
|
+
if (sphereId != null) {
|
|
1209
|
+
const radiusParam = { value: radius, isExpr: typeof radius === 'string' };
|
|
1210
|
+
await featureAPI.updateSphere(drawingId, sphereId, rReferences, radiusParam);
|
|
1211
|
+
return sphereId;
|
|
1212
|
+
}
|
|
1213
|
+
return null;
|
|
1214
|
+
}, partId, ...references);
|
|
1215
|
+
},
|
|
1216
|
+
};
|
|
1217
|
+
callback(publicApi);
|
|
1218
|
+
resolve(drawingId);
|
|
1219
|
+
});
|
|
1220
|
+
return () => promise.then(drawingId => core_1.api.getState().api.removeDrawing(drawingId));
|
|
1221
|
+
}
|
|
1222
|
+
destroy() {
|
|
1223
|
+
this.drawingId && core_1.api.getState().api.removeDrawing(this.drawingId);
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
exports.default = CAD;
|