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

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 +60 -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,178 @@
1
+ "use strict";
2
+ // import {
3
+ // DEFAULT_STRUCTURE_TREE,
4
+ // DrawingAPI,
5
+ // IGraphicPackage,
6
+ // IStructureProtocol,
7
+ // IStructurePatch,
8
+ // } from '@classcad/sdkjs'
9
+ // import * as assert from 'assert'
10
+ // import { readFileSync } from 'fs'
11
+ // import { join, resolve } from 'path'
12
+ // import io from 'socket.io'
13
+ // import { SocketIOClient, SocketIOEvent } from './../SocketIOClient'
14
+ // const resDir = resolve(join(__dirname, '..', '..', 'res', 'test'))
15
+ // const readResFile = (file: string) => readFileSync(join(resDir, file), 'utf-8')
16
+ // class TestDrawing implements DrawingAPI {
17
+ // private _structureTree: IStructureProtocol = DEFAULT_STRUCTURE_TREE()
18
+ // private _graphicPackages: IGraphicPackage[] = []
19
+ // private _errors: ServerError[] = []
20
+ // public getStructure(): IStructureProtocol {
21
+ // return this._structureTree
22
+ // }
23
+ // public setStructure(tree: IStructureProtocol): void {
24
+ // this._structureTree = tree
25
+ // }
26
+ // public applyPatches(patches: IStructurePatch[]): void {
27
+ // //
28
+ // }
29
+ // public addPackages(graphic: IGraphicPackage[]): void {
30
+ // this._graphicPackages.push(...graphic)
31
+ // }
32
+ // public addError(error: ServerError): void {
33
+ // this._errors.push(error)
34
+ // }
35
+ // }
36
+ // describe('SocketIOClient', () => {
37
+ // let _client: SocketIOClient
38
+ // let _mockServer: io.Server
39
+ // before(() => {
40
+ // _client = new SocketIOClient()
41
+ // _mockServer = io().listen(62135)
42
+ // _mockServer.on('connection', (socket: io.Socket) => {
43
+ // socket.emit(SocketIOEvent.CONNECT)
44
+ // socket.on('disconnect', () => {
45
+ // console.info('user disconnected')
46
+ // })
47
+ // socket.on(SocketIOEvent.INIT, () => {
48
+ // socket.emit(SocketIOEvent.PERMISSION, { id: 1, version: '8.x.x' })
49
+ // })
50
+ // socket.on(SocketIOEvent.SEND, (transactionID, command, factory) => {
51
+ // socket.emit(SocketIOEvent.JSON, { from: 'BeginFrame', transactionID })
52
+ // switch (command.command) {
53
+ // case 'GetTree': {
54
+ // const result = JSON.parse(readResFile('getTreeResult.json'))
55
+ // socket.emit(SocketIOEvent.JSON, {
56
+ // command: 'Result',
57
+ // from: command.command,
58
+ // result,
59
+ // })
60
+ // break
61
+ // }
62
+ // default:
63
+ // break
64
+ // }
65
+ // socket.emit(SocketIOEvent.JSON, { from: 'EndFrame', transactionID })
66
+ // })
67
+ // })
68
+ // })
69
+ // after(() => {
70
+ // _mockServer.close()
71
+ // })
72
+ // afterEach(() => {
73
+ // _client.removeAllListeners()
74
+ // })
75
+ // it(`should connect/disconnect to/from the server`, function(this: any, done) {
76
+ // let alreadyDone = false
77
+ // const safeDone = (err?: any) => {
78
+ // !alreadyDone ? done(err) : null
79
+ // alreadyDone = true
80
+ // }
81
+ // _client.on('connected', (client, connected) => {
82
+ // try {
83
+ // assert.strictEqual(connected, true)
84
+ // assert.strictEqual(client['_id'], 1)
85
+ // assert.strictEqual(client['_version'], '8.x.x')
86
+ // } catch (error) {
87
+ // _client.disconnect().catch()
88
+ // safeDone(error)
89
+ // }
90
+ // console.info('connected')
91
+ // })
92
+ // _client
93
+ // .connect(getUrl())
94
+ // .then(client => {
95
+ // assert.strictEqual(client['_id'], 1)
96
+ // assert.strictEqual(client['_version'], '8.x.x')
97
+ // _client.disconnect().catch()
98
+ // })
99
+ // .then(() => {
100
+ // safeDone()
101
+ // })
102
+ // .catch(error => {
103
+ // _client.disconnect().catch()
104
+ // safeDone(error)
105
+ // })
106
+ // })
107
+ // it(`should fail to connect/disconnect to/from the server`, function(this: any, done) {
108
+ // this.skip()
109
+ // // done();
110
+ // })
111
+ // it(`should get the classcad tree by promise`, function(this: any, done) {
112
+ // const drawing = new TestDrawing()
113
+ // _client
114
+ // .connect(getUrl())
115
+ // .then(client => {
116
+ // return client.requestTree(drawing)
117
+ // })
118
+ // .then(response => {
119
+ // const tree = response.result[0] as IStructureProtocol
120
+ // assert.strictEqual(tree.root, 49)
121
+ // assert.strictEqual(tree.testRoot, 0)
122
+ // assert.strictEqual(Object.getOwnPropertyNames(tree).length, 53)
123
+ // // TODO: more tree testing
124
+ // done()
125
+ // _client.disconnect().catch()
126
+ // })
127
+ // .catch(error => {
128
+ // done(error)
129
+ // _client.disconnect().catch()
130
+ // })
131
+ // })
132
+ // it(`should get the classcad tree by observing`, function(this: any, done) {
133
+ // // /////////////
134
+ // // testing code
135
+ // // /////////////
136
+ // let alreadyDone = false
137
+ // const safeDone = (err?: any) => {
138
+ // !alreadyDone ? done(err) : null
139
+ // alreadyDone = true
140
+ // }
141
+ // const testTree = (tree: IStructureProtocol) => {
142
+ // try {
143
+ // assert.strictEqual(tree.root, 49)
144
+ // assert.strictEqual(tree.testRoot, 0)
145
+ // assert.strictEqual(Object.getOwnPropertyNames(tree).length, 53)
146
+ // // TODO: more tree testing
147
+ // } catch (error) {
148
+ // safeDone(error)
149
+ // }
150
+ // }
151
+ // // /////////////
152
+ // // execute the request
153
+ // // /////////////
154
+ // const drawing = new TestDrawing()
155
+ // _client
156
+ // .connect(getUrl())
157
+ // .then(client => {
158
+ // return client.requestTree(drawing, {
159
+ // onTreeChanged: (tree: IStructureProtocol) => {
160
+ // testTree(tree)
161
+ // testTree(drawing.getStructure())
162
+ // },
163
+ // })
164
+ // })
165
+ // .then(response => {
166
+ // testTree(drawing.getStructure())
167
+ // safeDone()
168
+ // _client.disconnect().catch()
169
+ // })
170
+ // .catch(error => {
171
+ // safeDone(error)
172
+ // _client.disconnect().catch()
173
+ // })
174
+ // })
175
+ // })
176
+ // function getUrl(): string {
177
+ // return 'http://localhost:62135'
178
+ // }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EMISSION_CONFIG_UNSUPPORTED = void 0;
4
+ /**
5
+ * `Error.name` of the rejection when the engine does not support GetEmissionConfig/SetEmissionConfig.
6
+ *
7
+ * @advanced
8
+ * @category Connection
9
+ */
10
+ exports.EMISSION_CONFIG_UNSUPPORTED = 'EmissionConfigUnsupported';
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createRecursiveBufferGeometry = void 0;
4
+ const sdkjs_1 = require("@classcad/sdkjs");
5
+ const three_stdlib_1 = require("three-stdlib");
6
+ const createApi_1 = require("../createApi");
7
+ /**
8
+ * Helps to create the buffer geometry of the given object recursively.
9
+ * @param object object to create the buffergeometry from
10
+ * @param bufferGeomArray array to fill up with buffert geometries
11
+ */
12
+ const createRecursiveBufferGeometry = async (object, drawingId, bufferGeomArray) => {
13
+ let cDrawing = (0, sdkjs_1.getDrawing)(drawingId);
14
+ const tree = cDrawing.structure.tree;
15
+ if (object.link || object.solids || object.geometryIdList) {
16
+ // Part or Solid
17
+ const baseModeler = (0, createApi_1.createApi)(drawingId).v0.baseModeler;
18
+ const solids = object.link ? tree[object.link].solids : object.solids ? object.solids : object.geometryIdList;
19
+ if (solids != undefined) {
20
+ let geometries = [];
21
+ for (const solid of solids) {
22
+ let cachedSolid = cDrawing.geometry.cache[solid];
23
+ if (cachedSolid) {
24
+ // if solid already cached, take it from cache
25
+ geometries = [...geometries, ...cachedSolid.meshes.map(m => m.geometry)];
26
+ }
27
+ else {
28
+ // else get visualisation from classcad
29
+ await baseModeler.requestVisualisationOfEntities([solid]);
30
+ cDrawing = (0, sdkjs_1.getDrawing)(drawingId); // get current drawing state after request
31
+ cachedSolid = cDrawing.geometry.cache[solid];
32
+ if (cachedSolid) {
33
+ geometries = [...geometries, ...cachedSolid.meshes.map(m => m.geometry)];
34
+ }
35
+ else {
36
+ console.warn(`There is no cached entry for ${solid}!`, cDrawing.geometry.cache);
37
+ }
38
+ }
39
+ }
40
+ if (geometries.length > 0) {
41
+ const transformation = cDrawing.api.structure.calculateGlobalTransformation(object.id);
42
+ const bufferGeom = (0, three_stdlib_1.mergeBufferGeometries)(geometries);
43
+ bufferGeom.applyMatrix4(transformation);
44
+ bufferGeomArray.push(bufferGeom);
45
+ }
46
+ }
47
+ }
48
+ else if (object.children) {
49
+ // Assembly or Entity
50
+ for (const child of object.children) {
51
+ await (0, exports.createRecursiveBufferGeometry)(tree[child], drawingId, bufferGeomArray);
52
+ }
53
+ }
54
+ };
55
+ exports.createRecursiveBufferGeometry = createRecursiveBufferGeometry;
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createRecursiveScene = void 0;
4
+ const sdkjs_1 = require("@classcad/sdkjs");
5
+ const three_1 = require("three");
6
+ const three_stdlib_1 = require("three-stdlib");
7
+ const createApi_1 = require("../createApi");
8
+ const getDifferentColoredMeshesFromEntity_1 = require("./getDifferentColoredMeshesFromEntity");
9
+ /**
10
+ * We traverse recursively over structure tree, starting with object and create THREE objects
11
+ * for the scene. Each part or assembly will be turned into groups and subgroups. Solids which are children of the
12
+ * parts will be turned into groups as well. Children of solids will be merged to meshes. Faces of a solid with different color
13
+ * or transparency will get its own mesh.
14
+ * @param object root object where we start building the three scene
15
+ * @param drawingId id of the drawing
16
+ * @param root the root of the scene
17
+ * @param result object containing all the current collected nodes, solids, meshes
18
+ * @param options e.g. meshPerGeometry controls if each geometry element gets a own mesh or if they will be combined/merged
19
+ */
20
+ const createRecursiveScene = async (object, drawingId, root, result, options) => {
21
+ let cDrawing = (0, sdkjs_1.getDrawing)(drawingId);
22
+ const tree = cDrawing.structure.tree;
23
+ if (object.link || object.solids || object.geometryIdList) {
24
+ // Part or Solid
25
+ const baseModeler = (0, createApi_1.createApi)(drawingId).v0.baseModeler;
26
+ const entities = object.link ? tree[object.link].solids : object.solids ? object.solids : object.geometryIdList;
27
+ if (entities != undefined) {
28
+ const part = new three_1.Group();
29
+ const matrix = object.coordinateSystem ? sdkjs_1.MathUtils.convertToMatrix4(object.coordinateSystem) : new three_1.Matrix4();
30
+ matrix.decompose(part.position, part.quaternion, part.scale);
31
+ part.updateMatrix();
32
+ part.userData = { id: object.id }; // instance id
33
+ part.name = object.name; // instance name
34
+ for (const entity of entities) {
35
+ let cachedEntity = cDrawing.geometry.cache[entity];
36
+ if (!cachedEntity) {
37
+ // else get visualisation from classcad
38
+ await baseModeler.requestVisualisationOfEntities([entity]);
39
+ cDrawing = (0, sdkjs_1.getDrawing)(drawingId); // get current drawing state after request
40
+ cachedEntity = cDrawing.geometry.cache[entity];
41
+ }
42
+ if (cachedEntity && cachedEntity.meshes.length > 0) {
43
+ const solidObject = cDrawing.structure.tree[cachedEntity.container.ownerId];
44
+ if (solidObject) {
45
+ const _solid = new three_1.Group();
46
+ _solid.name = solidObject.name + '_solid';
47
+ _solid.userData = { id: solidObject.id }; // add solid id to the userData
48
+ result.nodes[_solid.name] = _solid;
49
+ result.nodes[`${solidObject.id}`] = _solid;
50
+ if (options === null || options === void 0 ? void 0 : options.meshPerGeometry) {
51
+ // Create a mesh for each geometry element
52
+ cachedEntity.meshes.forEach((m, i) => {
53
+ const mesh = new three_1.Mesh();
54
+ mesh.name = solidObject.name + '_' + i;
55
+ mesh.userData = { id: m.graphicId }; // add graphic id to the userData
56
+ if (!(options === null || options === void 0 ? void 0 : options.structureOnly)) {
57
+ mesh.geometry = m.geometry;
58
+ mesh.material = new three_1.MeshStandardMaterial({
59
+ color: m.color ? m.color : cachedEntity.color,
60
+ transparent: m.color ? m.opacity < 1 : cachedEntity.opacity < 1,
61
+ opacity: m.color ? m.opacity : cachedEntity.opacity,
62
+ });
63
+ mesh.material.name = mesh.name + '_material';
64
+ result.materials[mesh.material.name] = mesh.material;
65
+ }
66
+ result.nodes[mesh.name] = mesh;
67
+ _solid.add(mesh);
68
+ });
69
+ part.add(_solid);
70
+ }
71
+ else {
72
+ // Merge all geometries into one mesh, sort them by color
73
+ const colorMeshesMap = (0, getDifferentColoredMeshesFromEntity_1.getDifferentColoredMeshesFromEntity)(cachedEntity);
74
+ const colorMeshes = Object.keys(colorMeshesMap);
75
+ if (colorMeshes.length > 1) {
76
+ // If the solid consists of multiple meshes we must keep the group
77
+ colorMeshes.forEach((key, i) => {
78
+ const mesh = new three_1.Mesh();
79
+ mesh.name = solidObject.name + '_' + i;
80
+ mesh.userData = { id: solidObject.id }; // add solid id to the userData
81
+ if (!(options === null || options === void 0 ? void 0 : options.structureOnly)) {
82
+ mesh.geometry = (0, three_stdlib_1.mergeBufferGeometries)(colorMeshesMap[key].meshes.map(m => m.geometry));
83
+ mesh.material = new three_1.MeshStandardMaterial({
84
+ color: colorMeshesMap[key].color,
85
+ transparent: colorMeshesMap[key].opacity < 1,
86
+ opacity: colorMeshesMap[key].opacity,
87
+ });
88
+ mesh.material.name = mesh.name + '_material';
89
+ result.materials[mesh.material.name] = mesh.material;
90
+ }
91
+ result.nodes[mesh.name] = mesh; // Collect mesh to return result later
92
+ _solid.add(mesh); // Add mesh to solid of the scene
93
+ });
94
+ part.add(_solid);
95
+ }
96
+ else {
97
+ // Otherwise we can use the mesh itself
98
+ const key = colorMeshes[0];
99
+ const mesh = new three_1.Mesh();
100
+ mesh.name = solidObject.name;
101
+ mesh.userData = { id: solidObject.id }; // add solid id to the userData
102
+ if (!(options === null || options === void 0 ? void 0 : options.structureOnly)) {
103
+ mesh.geometry = (0, three_stdlib_1.mergeBufferGeometries)(colorMeshesMap[key].meshes.map(m => m.geometry));
104
+ mesh.material = new three_1.MeshStandardMaterial({
105
+ color: colorMeshesMap[key].color,
106
+ transparent: colorMeshesMap[key].opacity < 1,
107
+ opacity: colorMeshesMap[key].opacity,
108
+ });
109
+ mesh.material.name = mesh.name + '_material';
110
+ result.materials[mesh.material.name] = mesh.material;
111
+ }
112
+ result.nodes[mesh.name] = mesh;
113
+ part.add(mesh);
114
+ }
115
+ }
116
+ }
117
+ }
118
+ }
119
+ root.add(part);
120
+ result.nodes[part.name] = part;
121
+ result.nodes[`${object.id}`] = part;
122
+ }
123
+ }
124
+ else if (object.children) {
125
+ // Assembly or Entity
126
+ const group = new three_1.Group();
127
+ const matrix = object.coordinateSystem ? sdkjs_1.MathUtils.convertToMatrix4(object.coordinateSystem) : new three_1.Matrix4();
128
+ matrix.decompose(group.position, group.quaternion, group.scale);
129
+ group.updateMatrix();
130
+ group.userData = { id: object.id }; // assembly root or instance id
131
+ group.name = object.name; // assembly root or instance name
132
+ result.nodes[group.name] = group;
133
+ result.nodes[`${object.id}`] = group;
134
+ root.add(group);
135
+ for (const child of object.children) {
136
+ await (0, exports.createRecursiveScene)(tree[child], drawingId, group, result, options);
137
+ }
138
+ }
139
+ };
140
+ exports.createRecursiveScene = createRecursiveScene;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDifferentColoredMeshesFromEntity = void 0;
4
+ /**
5
+ * Get all meshes in a map, sorted by their color / opacity
6
+ * @param entity entity to look for the meshes
7
+ * @returns map (key = color/opacity as string, value = object containing the meshes, color and opacity)
8
+ */
9
+ const getDifferentColoredMeshesFromEntity = (entity) => {
10
+ const colorMeshesMap = {};
11
+ entity.meshes.forEach(mesh => {
12
+ const color = mesh.color ? mesh.color : entity.color;
13
+ const opacity = mesh.opacity ? mesh.opacity : entity.opacity;
14
+ const key = (color === null || color === void 0 ? void 0 : color.getHexString()) + (opacity === null || opacity === void 0 ? void 0 : opacity.toString());
15
+ if (colorMeshesMap[key]) {
16
+ colorMeshesMap[key].meshes.push(mesh);
17
+ }
18
+ else {
19
+ colorMeshesMap[key] = { meshes: [mesh], color, opacity };
20
+ }
21
+ });
22
+ return colorMeshesMap;
23
+ };
24
+ exports.getDifferentColoredMeshesFromEntity = getDifferentColoredMeshesFromEntity;
@@ -0,0 +1,20 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./createRecursiveBufferGeometry"), exports);
18
+ __exportStar(require("./createRecursiveScene"), exports);
19
+ __exportStar(require("./polyline"), exports);
20
+ __exportStar(require("./waitForSelect"), exports);
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getIncludingBulgeAngle = exports.getTouchPoints = void 0;
4
+ /**
5
+ * Calculates the including angle between two lines. The angle is measured from first to second line counterclockwise. If angle exceeds 180°, measuring is clockwise but negative angle
6
+ * @param info Info contains information about lines
7
+ */
8
+ const getIncludingAngle = (info) => {
9
+ // First line (line to point)
10
+ const line1 = info.lineEnds[0]
11
+ .clone()
12
+ .sub(info.lineStarts[0])
13
+ .normalize();
14
+ // Second line (line from point)
15
+ const line2 = info.lineEnds[1]
16
+ .clone()
17
+ .sub(info.lineStarts[1])
18
+ .normalize();
19
+ // Angle, measured from first line to second line counterclockwise.
20
+ // If angle exceeds 180°, measuring is clockwise but negative angle
21
+ const angle = Math.atan2(line1.x * line2.y - line1.y * line2.x, line1.x * line2.x + line1.y * line2.y);
22
+ return angle;
23
+ };
24
+ /**
25
+ * Returns the adjacent points of the fillet arc. These are the points where fillet arc tangentially touches the lines.
26
+ * @param info contains all information for the fillet, like start- and endpoints of adjacent lines and control point
27
+ * @param radius radius of the fillet arc
28
+ */
29
+ const getTouchPoints = (info, radius) => {
30
+ const controlPos = info.control;
31
+ const linearTolerance = 1e-3;
32
+ const dirs = [];
33
+ const maxDists = [];
34
+ for (let i = 0; i < 2; i++) {
35
+ const startPos = info.lineStarts[i];
36
+ const endPos = info.lineEnds[i];
37
+ const dir = endPos.clone().sub(startPos).normalize();
38
+ const maxDist = endPos.distanceTo(controlPos);
39
+ dirs.push(dir);
40
+ maxDists.push(maxDist);
41
+ }
42
+ if (radius + linearTolerance >= Math.min(maxDists[0], maxDists[1])) {
43
+ return null; // too large fillet
44
+ }
45
+ // Calculate distance from controlpt to touchpoint
46
+ const scalar = Math.abs(radius / Math.tan(getIncludingAngle(info) / 2));
47
+ return dirs.map(dir => dir
48
+ .clone()
49
+ .multiplyScalar(scalar)
50
+ .add(controlPos));
51
+ };
52
+ exports.getTouchPoints = getTouchPoints;
53
+ /**
54
+ * Calculates and returns the including angle between the touchpoints of the fillet. Attention: It is the angle of touchpoints and center of fillet arc and not the one between touchpoints and control point.
55
+ * @param info
56
+ */
57
+ const getIncludingBulgeAngle = (info) => {
58
+ // angle of first line, control point and second line
59
+ const angle = getIncludingAngle(info);
60
+ // Opposite angle of the angle which was calculated from control point and its adjacent lines
61
+ const oppositeAngle = Math.PI - Math.abs(angle);
62
+ const sign = angle / Math.abs(angle);
63
+ return oppositeAngle * sign * -1; // -1 because of bulges definition
64
+ };
65
+ exports.getIncludingBulgeAngle = getIncludingBulgeAngle;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.waitForSelect = waitForSelect;
7
+ const sdkjs_1 = require("@classcad/sdkjs");
8
+ const uuid_1 = require("uuid");
9
+ // @ts-ignore
10
+ const flat_promise_1 = __importDefault(require("flat-promise"));
11
+ async function waitForSelect(drawingId, length, filter, onChange) {
12
+ const id = (0, uuid_1.v4)();
13
+ const selApi = drawingId && (0, sdkjs_1.getDrawing)(drawingId).api.selection;
14
+ // Set up selection API
15
+ const { promise, resolve } = (0, flat_promise_1.default)();
16
+ const change = (selId, items, diff) => {
17
+ selApi && selApi.setItems(selId, items);
18
+ if (onChange)
19
+ onChange(resolve, items, diff);
20
+ };
21
+ const unsub = selApi && selApi.createSelector(id, filter, false, [], length, change, change);
22
+ // Wait for user interaction
23
+ selApi && selApi.activateSelector(id);
24
+ const result = await promise;
25
+ // Unsubscribe from all selections
26
+ unsub && unsub();
27
+ selApi && selApi.activateSelector(null);
28
+ return result;
29
+ }