@buerli.io/core 1.0.0 → 1.0.1-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.
Files changed (74) hide show
  1. package/README.md +19 -19
  2. package/build/cjs/geometry/ThreeGeometryCreator.js +320 -320
  3. package/build/cjs/geometry/index.js +17 -17
  4. package/build/cjs/graphic/filters.js +25 -25
  5. package/build/cjs/index.js +26 -26
  6. package/build/cjs/re-export.js +29 -29
  7. package/build/cjs/store/index.js +37 -37
  8. package/build/cjs/store/states/buerli.js +98 -98
  9. package/build/cjs/store/states/cad.js +47 -47
  10. package/build/cjs/store/states/drawing.js +49 -49
  11. package/build/cjs/store/states/geometry.js +157 -157
  12. package/build/cjs/store/states/graphic.js +115 -115
  13. package/build/cjs/store/states/interaction.js +55 -55
  14. package/build/cjs/store/states/message.js +25 -25
  15. package/build/cjs/store/states/plugin.js +115 -115
  16. package/build/cjs/store/states/selection.js +267 -267
  17. package/build/cjs/store/states/structure.js +250 -250
  18. package/build/cjs/store/store.js +9 -9
  19. package/build/cjs/store/subscribtion/selection.js +49 -49
  20. package/build/cjs/store/subscribtion/subscribeToDrawing.js +13 -13
  21. package/build/cjs/types/InteractionInfo.js +11 -11
  22. package/build/cjs/types/index.js +34 -34
  23. package/build/cjs/utils/Math.js +91 -91
  24. package/build/cjs/utils/Measure.js +576 -576
  25. package/build/cjs/utils/Timing.js +34 -34
  26. package/build/esm/geometry/ThreeGeometryCreator.js +291 -291
  27. package/build/esm/geometry/index.js +1 -1
  28. package/build/esm/graphic/filters.js +12 -12
  29. package/build/esm/index.js +10 -10
  30. package/build/esm/re-export.js +23 -23
  31. package/build/esm/store/index.js +26 -26
  32. package/build/esm/store/states/buerli.js +92 -92
  33. package/build/esm/store/states/cad.js +42 -42
  34. package/build/esm/store/states/drawing.js +45 -45
  35. package/build/esm/store/states/geometry.js +129 -129
  36. package/build/esm/store/states/graphic.js +110 -110
  37. package/build/esm/store/states/interaction.js +50 -50
  38. package/build/esm/store/states/message.js +21 -21
  39. package/build/esm/store/states/plugin.js +109 -109
  40. package/build/esm/store/states/selection.js +261 -261
  41. package/build/esm/store/states/structure.js +219 -219
  42. package/build/esm/store/store.js +3 -3
  43. package/build/esm/store/subscribtion/selection.js +44 -44
  44. package/build/esm/store/subscribtion/subscribeToDrawing.js +9 -9
  45. package/build/esm/types/InteractionInfo.js +6 -6
  46. package/build/esm/types/index.js +16 -16
  47. package/build/esm/utils/Math.js +65 -65
  48. package/build/esm/utils/Measure.js +550 -550
  49. package/build/esm/utils/Timing.js +31 -31
  50. package/build/types/geometry/ThreeGeometryCreator.d.ts +256 -256
  51. package/build/types/geometry/index.d.ts +1 -1
  52. package/build/types/graphic/filters.d.ts +11 -11
  53. package/build/types/index.d.ts +38 -38
  54. package/build/types/re-export.d.ts +70 -70
  55. package/build/types/store/index.d.ts +16 -16
  56. package/build/types/store/states/buerli.d.ts +41 -41
  57. package/build/types/store/states/cad.d.ts +56 -56
  58. package/build/types/store/states/drawing.d.ts +45 -45
  59. package/build/types/store/states/geometry.d.ts +64 -64
  60. package/build/types/store/states/graphic.d.ts +21 -21
  61. package/build/types/store/states/interaction.d.ts +34 -34
  62. package/build/types/store/states/message.d.ts +30 -30
  63. package/build/types/store/states/plugin.d.ts +53 -53
  64. package/build/types/store/states/selection.d.ts +69 -69
  65. package/build/types/store/states/structure.d.ts +47 -47
  66. package/build/types/store/store.d.ts +2 -2
  67. package/build/types/store/subscribtion/selection.d.ts +7 -7
  68. package/build/types/store/subscribtion/subscribeToDrawing.d.ts +4 -4
  69. package/build/types/types/InteractionInfo.d.ts +42 -42
  70. package/build/types/types/index.d.ts +7 -7
  71. package/build/types/utils/Math.d.ts +21 -21
  72. package/build/types/utils/Measure.d.ts +64 -64
  73. package/build/types/utils/Timing.d.ts +8 -8
  74. package/package.json +45 -45
@@ -1,250 +1,250 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.structureApi = exports.structureData = void 0;
30
- const fast_json_patch_1 = __importDefault(require("fast-json-patch"));
31
- const jsonpatch_1 = __importDefault(require("jsonpatch"));
32
- const THREE = __importStar(require("three"));
33
- const types_1 = require("../../types");
34
- const Math_1 = require("../../utils/Math");
35
- ////////////////////////////////////////////////////
36
- // DATA
37
- ////////////////////////////////////////////////////
38
- const structureData = () => {
39
- return Object.assign(Object.assign({}, (0, types_1.DEFAULT_STRUCTURE_TREE)()), { visibleContainers: [], products: [] });
40
- };
41
- exports.structureData = structureData;
42
- ////////////////////////////////////////////////////
43
- // API
44
- ////////////////////////////////////////////////////
45
- const structureApi = (set, get, buerliApi) => ({
46
- get: () => {
47
- return get().structure;
48
- },
49
- set: (structure) => {
50
- const { api } = get();
51
- // TODO: clear object selection if needed
52
- // 1. set the state
53
- set({
54
- structure: Object.assign(Object.assign({}, get().structure), structure),
55
- });
56
- // 2. collect and cleanup data
57
- api.graphic.cleanupGraphicRecords();
58
- // console.log('cleanup')
59
- api.structure.postProcessStructureUpdate();
60
- },
61
- applyPatches: (patches) => {
62
- const before = get().structure.products.concat(get().structure.visibleContainers);
63
- const applyBlock = (block) => {
64
- if (block.length === 0)
65
- return;
66
- set(state => {
67
- let structure = state.structure;
68
- try {
69
- // TODO: keep an eye on the patch behaviour in general.
70
- // For large changes 'fast-json-patch' is much more performant than 'jsonpatch'.
71
- // However, for smaller changes 'jsonpatch' is more performant than 'fast-json-patch'.
72
- if (block.length > 100) {
73
- structure = fast_json_patch_1.default.applyPatch(state.structure, block, false, false).newDocument;
74
- }
75
- else {
76
- structure = jsonpatch_1.default.apply_patch(state.structure, block);
77
- }
78
- }
79
- catch (e) {
80
- console.error(e);
81
- }
82
- // console.info('currentProduct in new patched structure: ', structure.currentProduct)
83
- return { structure: Object.assign(Object.assign({}, state.structure), structure) };
84
- });
85
- };
86
- const treePatches = [];
87
- const otherPatches = [];
88
- for (const patch of patches) {
89
- if (patch.path.startsWith('/tree/')) {
90
- treePatches.push(patch);
91
- }
92
- else {
93
- otherPatches.push(patch);
94
- }
95
- }
96
- // console.info(JSON.stringify(otherPatches))
97
- //////////////////////////////////////////////////////////////////////////////
98
- // The following split of the state update helps very much in some cases to
99
- // prevent not existing object access in many React hooks.
100
- // 1. Perform meta information update as the first step (root, currentProduct, ...)
101
- applyBlock(otherPatches);
102
- // 2. Perform tree update as a second, separate step
103
- applyBlock(treePatches);
104
- // TODO: The update behaviour for structure updates in buerli/zustand/react-hooks
105
- // has to be analyzed in more detail based on a very simple example.
106
- //////////////////////////////////////////////////////////////////////////////
107
- const { api } = get();
108
- api.structure.postProcessStructureUpdate();
109
- // Update the bounds, but only if products or visible containers changed.
110
- const after = get().structure.products.concat(get().structure.visibleContainers);
111
- if (before.sort().join() !== after.sort().join()) {
112
- api.geometry.updateBounds();
113
- }
114
- },
115
- filterTree: (tree, filter) => {
116
- const objs = [];
117
- const keys = Object.getOwnPropertyNames(tree);
118
- for (const key of keys) {
119
- const obj = tree[key];
120
- if (filter(obj)) {
121
- objs.push(obj);
122
- }
123
- }
124
- return objs;
125
- },
126
- findTree: (tree, filter) => {
127
- const keys = Object.getOwnPropertyNames(tree);
128
- for (const key of keys) {
129
- const obj = tree[key];
130
- if (filter(obj)) {
131
- return obj;
132
- }
133
- }
134
- return undefined;
135
- },
136
- collectUsedSolidIds: () => {
137
- const { api, structure } = get();
138
- const solidObjs = api.structure.filterTree(structure.tree, obj => typeof obj.geometryIdList !== 'undefined');
139
- const solidIds = [];
140
- solidObjs.forEach(solidObj => solidIds.push(...(solidObj.geometryIdList || [])));
141
- return solidIds;
142
- },
143
- collectProducts: (root) => {
144
- const { structure } = get();
145
- const products = [];
146
- const recursive = (id) => {
147
- const obj = structure.tree[id];
148
- if (obj) {
149
- if ((obj.solids && obj.solids.length > 0) || obj.link) {
150
- products.push(obj);
151
- }
152
- if (obj.children) {
153
- for (const child of obj.children) {
154
- recursive(child);
155
- }
156
- }
157
- }
158
- };
159
- recursive(root);
160
- return products;
161
- },
162
- getProductSolidIds: (productId) => {
163
- const { structure } = get();
164
- let solids;
165
- const product = structure.tree[productId];
166
- if (product.link !== undefined) {
167
- solids = structure.tree[product.link].solids || [];
168
- }
169
- else {
170
- solids = product.solids || [];
171
- }
172
- return [...solids];
173
- },
174
- postProcessStructureUpdate: () => {
175
- const { api, structure } = get();
176
- //////////
177
- // 1. Collect the products
178
- //////////
179
- const searchRoot = structure.root; // || structure.currentInstance || structure.currentProduct
180
- const productIds = api.structure.collectProducts(searchRoot).map(p => p.id);
181
- //////////
182
- // 2. Collect the solid ids
183
- //////////
184
- let solidIds = [];
185
- productIds.forEach(prodId => solidIds.push(...(api.structure.getProductSolidIds(prodId) || [])));
186
- // remove duplicates
187
- solidIds = solidIds.filter((item, index) => solidIds.indexOf(item) === index);
188
- //////////
189
- // 3. Add the result to the state
190
- //////////
191
- set(state => ({
192
- structure: Object.assign(Object.assign({}, state.structure), { visibleContainers: solidIds, products: productIds }),
193
- }));
194
- },
195
- /**
196
- * Calculates the global transformation matrix for the given _objectId_.
197
- *
198
- * @param objectId The object to calculate the global transformation for.
199
- * @param matrix The initial matrix (mainly used for recursion). It is an out parameter and in the end, it will contain the same matrix as the return value of this function.
200
- * @returns The global transformation matrix for the given _objectId_.
201
- */
202
- calculateGlobalTransformation: (objectId, matrix = new THREE.Matrix4().identity()) => {
203
- const { structure, api } = get();
204
- const { tree, root } = structure;
205
- const obj = tree[objectId];
206
- if (obj && obj.coordinateSystem) {
207
- const objMatrix = Math_1.MathUtils.convertToMatrix4(obj.coordinateSystem);
208
- matrix = matrix.clone().premultiply(objMatrix);
209
- }
210
- if (objectId !== root && obj.parent) {
211
- matrix = api.structure.calculateGlobalTransformation(obj.parent, matrix);
212
- }
213
- return matrix;
214
- },
215
- calculateProductBounds: (productId, base) => {
216
- const { graphic, api } = get();
217
- const posInf = Number.POSITIVE_INFINITY;
218
- const negInf = Number.NEGATIVE_INFINITY;
219
- const baseMin = base ? base.min.clone() : new THREE.Vector3(posInf, posInf, posInf);
220
- const baseMax = base ? base.max.clone() : new THREE.Vector3(negInf, negInf, negInf);
221
- let box = new THREE.Box3(baseMin, baseMax);
222
- const productIds = api.structure.collectProducts(productId).map(p => p.id);
223
- for (const pId of productIds) {
224
- const matrix = api.structure.calculateGlobalTransformation(pId);
225
- const contIds = api.structure.getProductSolidIds(pId);
226
- for (const contId of contIds) {
227
- const cont = graphic.containers[contId];
228
- if (cont) {
229
- const min = new THREE.Vector3().fromArray(cont.properties.min);
230
- const max = new THREE.Vector3().fromArray(cont.properties.max);
231
- const b = new THREE.Box3(min.clone(), max.clone());
232
- b.applyMatrix4(matrix);
233
- box = box.union(b);
234
- }
235
- }
236
- }
237
- const sphere = new THREE.Sphere();
238
- box.getBoundingSphere(sphere);
239
- return { center: sphere.center, radius: sphere.radius, max: box.max, min: box.min };
240
- },
241
- /**
242
- * This is a workaround to get the corresponding drawing id via API.
243
- *
244
- * > !!! Should not be used in user code !!!
245
- *
246
- * @returns The drawing id.
247
- */
248
- getDrawingId: () => get().id,
249
- });
250
- exports.structureApi = structureApi;
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 __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.structureApi = exports.structureData = void 0;
30
+ const fast_json_patch_1 = __importDefault(require("fast-json-patch"));
31
+ const jsonpatch_1 = __importDefault(require("jsonpatch"));
32
+ const THREE = __importStar(require("three"));
33
+ const types_1 = require("../../types");
34
+ const Math_1 = require("../../utils/Math");
35
+ ////////////////////////////////////////////////////
36
+ // DATA
37
+ ////////////////////////////////////////////////////
38
+ const structureData = () => {
39
+ return Object.assign(Object.assign({}, (0, types_1.DEFAULT_STRUCTURE_TREE)()), { visibleContainers: [], products: [] });
40
+ };
41
+ exports.structureData = structureData;
42
+ ////////////////////////////////////////////////////
43
+ // API
44
+ ////////////////////////////////////////////////////
45
+ const structureApi = (set, get, buerliApi) => ({
46
+ get: () => {
47
+ return get().structure;
48
+ },
49
+ set: (structure) => {
50
+ const { api } = get();
51
+ // TODO: clear object selection if needed
52
+ // 1. set the state
53
+ set({
54
+ structure: Object.assign(Object.assign({}, get().structure), structure),
55
+ });
56
+ // 2. collect and cleanup data
57
+ api.graphic.cleanupGraphicRecords();
58
+ // console.log('cleanup')
59
+ api.structure.postProcessStructureUpdate();
60
+ },
61
+ applyPatches: (patches) => {
62
+ const before = get().structure.products.concat(get().structure.visibleContainers);
63
+ const applyBlock = (block) => {
64
+ if (block.length === 0)
65
+ return;
66
+ set(state => {
67
+ let structure = state.structure;
68
+ try {
69
+ // TODO: keep an eye on the patch behaviour in general.
70
+ // For large changes 'fast-json-patch' is much more performant than 'jsonpatch'.
71
+ // However, for smaller changes 'jsonpatch' is more performant than 'fast-json-patch'.
72
+ if (block.length > 100) {
73
+ structure = fast_json_patch_1.default.applyPatch(state.structure, block, false, false).newDocument;
74
+ }
75
+ else {
76
+ structure = jsonpatch_1.default.apply_patch(state.structure, block);
77
+ }
78
+ }
79
+ catch (e) {
80
+ console.error(e);
81
+ }
82
+ // console.info('currentProduct in new patched structure: ', structure.currentProduct)
83
+ return { structure: Object.assign(Object.assign({}, state.structure), structure) };
84
+ });
85
+ };
86
+ const treePatches = [];
87
+ const otherPatches = [];
88
+ for (const patch of patches) {
89
+ if (patch.path.startsWith('/tree/')) {
90
+ treePatches.push(patch);
91
+ }
92
+ else {
93
+ otherPatches.push(patch);
94
+ }
95
+ }
96
+ // console.info(JSON.stringify(otherPatches))
97
+ //////////////////////////////////////////////////////////////////////////////
98
+ // The following split of the state update helps very much in some cases to
99
+ // prevent not existing object access in many React hooks.
100
+ // 1. Perform meta information update as the first step (root, currentProduct, ...)
101
+ applyBlock(otherPatches);
102
+ // 2. Perform tree update as a second, separate step
103
+ applyBlock(treePatches);
104
+ // TODO: The update behaviour for structure updates in buerli/zustand/react-hooks
105
+ // has to be analyzed in more detail based on a very simple example.
106
+ //////////////////////////////////////////////////////////////////////////////
107
+ const { api } = get();
108
+ api.structure.postProcessStructureUpdate();
109
+ // Update the bounds, but only if products or visible containers changed.
110
+ const after = get().structure.products.concat(get().structure.visibleContainers);
111
+ if (before.sort().join() !== after.sort().join()) {
112
+ api.geometry.updateBounds();
113
+ }
114
+ },
115
+ filterTree: (tree, filter) => {
116
+ const objs = [];
117
+ const keys = Object.getOwnPropertyNames(tree);
118
+ for (const key of keys) {
119
+ const obj = tree[key];
120
+ if (filter(obj)) {
121
+ objs.push(obj);
122
+ }
123
+ }
124
+ return objs;
125
+ },
126
+ findTree: (tree, filter) => {
127
+ const keys = Object.getOwnPropertyNames(tree);
128
+ for (const key of keys) {
129
+ const obj = tree[key];
130
+ if (filter(obj)) {
131
+ return obj;
132
+ }
133
+ }
134
+ return undefined;
135
+ },
136
+ collectUsedSolidIds: () => {
137
+ const { api, structure } = get();
138
+ const solidObjs = api.structure.filterTree(structure.tree, obj => typeof obj.geometryIdList !== 'undefined');
139
+ const solidIds = [];
140
+ solidObjs.forEach(solidObj => solidIds.push(...(solidObj.geometryIdList || [])));
141
+ return solidIds;
142
+ },
143
+ collectProducts: (root) => {
144
+ const { structure } = get();
145
+ const products = [];
146
+ const recursive = (id) => {
147
+ const obj = structure.tree[id];
148
+ if (obj) {
149
+ if ((obj.solids && obj.solids.length > 0) || obj.link) {
150
+ products.push(obj);
151
+ }
152
+ if (obj.children) {
153
+ for (const child of obj.children) {
154
+ recursive(child);
155
+ }
156
+ }
157
+ }
158
+ };
159
+ recursive(root);
160
+ return products;
161
+ },
162
+ getProductSolidIds: (productId) => {
163
+ const { structure } = get();
164
+ let solids;
165
+ const product = structure.tree[productId];
166
+ if (product.link !== undefined) {
167
+ solids = structure.tree[product.link].solids || [];
168
+ }
169
+ else {
170
+ solids = product.solids || [];
171
+ }
172
+ return [...solids];
173
+ },
174
+ postProcessStructureUpdate: () => {
175
+ const { api, structure } = get();
176
+ //////////
177
+ // 1. Collect the products
178
+ //////////
179
+ const searchRoot = structure.root; // || structure.currentInstance || structure.currentProduct
180
+ const productIds = api.structure.collectProducts(searchRoot).map(p => p.id);
181
+ //////////
182
+ // 2. Collect the solid ids
183
+ //////////
184
+ let solidIds = [];
185
+ productIds.forEach(prodId => solidIds.push(...(api.structure.getProductSolidIds(prodId) || [])));
186
+ // remove duplicates
187
+ solidIds = solidIds.filter((item, index) => solidIds.indexOf(item) === index);
188
+ //////////
189
+ // 3. Add the result to the state
190
+ //////////
191
+ set(state => ({
192
+ structure: Object.assign(Object.assign({}, state.structure), { visibleContainers: solidIds, products: productIds }),
193
+ }));
194
+ },
195
+ /**
196
+ * Calculates the global transformation matrix for the given _objectId_.
197
+ *
198
+ * @param objectId The object to calculate the global transformation for.
199
+ * @param matrix The initial matrix (mainly used for recursion). It is an out parameter and in the end, it will contain the same matrix as the return value of this function.
200
+ * @returns The global transformation matrix for the given _objectId_.
201
+ */
202
+ calculateGlobalTransformation: (objectId, matrix = new THREE.Matrix4().identity()) => {
203
+ const { structure, api } = get();
204
+ const { tree, root } = structure;
205
+ const obj = tree[objectId];
206
+ if (obj && obj.coordinateSystem) {
207
+ const objMatrix = Math_1.MathUtils.convertToMatrix4(obj.coordinateSystem);
208
+ matrix = matrix.clone().premultiply(objMatrix);
209
+ }
210
+ if (objectId !== root && obj.parent) {
211
+ matrix = api.structure.calculateGlobalTransformation(obj.parent, matrix);
212
+ }
213
+ return matrix;
214
+ },
215
+ calculateProductBounds: (productId, base) => {
216
+ const { graphic, api } = get();
217
+ const posInf = Number.POSITIVE_INFINITY;
218
+ const negInf = Number.NEGATIVE_INFINITY;
219
+ const baseMin = base ? base.min.clone() : new THREE.Vector3(posInf, posInf, posInf);
220
+ const baseMax = base ? base.max.clone() : new THREE.Vector3(negInf, negInf, negInf);
221
+ let box = new THREE.Box3(baseMin, baseMax);
222
+ const productIds = api.structure.collectProducts(productId).map(p => p.id);
223
+ for (const pId of productIds) {
224
+ const matrix = api.structure.calculateGlobalTransformation(pId);
225
+ const contIds = api.structure.getProductSolidIds(pId);
226
+ for (const contId of contIds) {
227
+ const cont = graphic.containers[contId];
228
+ if (cont) {
229
+ const min = new THREE.Vector3().fromArray(cont.properties.min);
230
+ const max = new THREE.Vector3().fromArray(cont.properties.max);
231
+ const b = new THREE.Box3(min.clone(), max.clone());
232
+ b.applyMatrix4(matrix);
233
+ box = box.union(b);
234
+ }
235
+ }
236
+ }
237
+ const sphere = new THREE.Sphere();
238
+ box.getBoundingSphere(sphere);
239
+ return { center: sphere.center, radius: sphere.radius, max: box.max, min: box.min };
240
+ },
241
+ /**
242
+ * This is a workaround to get the corresponding drawing id via API.
243
+ *
244
+ * > !!! Should not be used in user code !!!
245
+ *
246
+ * @returns The drawing id.
247
+ */
248
+ getDrawingId: () => get().id,
249
+ });
250
+ exports.structureApi = structureApi;
@@ -1,9 +1,9 @@
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.api = void 0;
7
- const vanilla_1 = __importDefault(require("zustand/vanilla"));
8
- const buerli_1 = require("./states/buerli");
9
- exports.api = (0, vanilla_1.default)()(buerli_1.createState);
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.api = void 0;
7
+ const vanilla_1 = __importDefault(require("zustand/vanilla"));
8
+ const buerli_1 = require("./states/buerli");
9
+ exports.api = (0, vanilla_1.default)()(buerli_1.createState);
@@ -1,49 +1,49 @@
1
- "use strict";
2
- // This is the solution for cases when object was deleted from tree and we need to remove corresponding selectedItem.
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.unsubscribeItems = exports.subscribeItems = exports.unsubs = void 0;
5
- const subscribeToDrawing_1 = require("./subscribeToDrawing");
6
- // This object contains unsubscibe function for all existing selections in all drawings
7
- exports.unsubs = {};
8
- function getId(selectorId, itemId) {
9
- return `${selectorId}_${itemId}`;
10
- }
11
- function subscribeItems(buerliApi, drawingId, selectorId, items) {
12
- const items_ = items || buerliApi.getState().drawing.refs[drawingId].selection.refs[selectorId].items;
13
- items_.forEach(item => {
14
- subscribeItem(buerliApi, drawingId, selectorId, item);
15
- });
16
- }
17
- exports.subscribeItems = subscribeItems;
18
- function subscribeItem(buerliApi, drawingId, selectorId, item) {
19
- if (item.removeCondition && !exports.unsubs[getId(selectorId, item.id)]) {
20
- const selApi = buerliApi.getState().drawing.refs[drawingId].api.selection;
21
- exports.unsubs[getId(selectorId, item.id)] = (0, subscribeToDrawing_1.subscribeToDrawing)(buerliApi, drawingId, (d) => item.removeCondition && item.removeCondition(d), (removeCond) => {
22
- var _a;
23
- // Unselect item whose removeCondition got true
24
- if (removeCond) {
25
- const newItems = ((_a = buerliApi.getState().drawing.refs[drawingId].selection.refs[selectorId]) === null || _a === void 0 ? void 0 : _a.items) || [];
26
- selApi.setItems(selectorId, newItems.filter(item_ => item_.id !== item.id));
27
- }
28
- });
29
- }
30
- }
31
- function unsubscribeItems(buerliApi, drawingId, selectorId, items) {
32
- var _a, _b, _c, _d;
33
- // The following line leeds to exceptions if for example the corresponding drawing is going to be reset.
34
- // To prevent those exceptions, check all properties for existance.
35
- const items_ = items || ((_d = (_c = (_b = (_a = buerliApi.getState().drawing.refs[drawingId]) === null || _a === void 0 ? void 0 : _a.selection) === null || _b === void 0 ? void 0 : _b.refs) === null || _c === void 0 ? void 0 : _c[selectorId]) === null || _d === void 0 ? void 0 : _d.items) || [];
36
- items_.forEach(item => {
37
- unsubscribeItem(selectorId, item);
38
- });
39
- }
40
- exports.unsubscribeItems = unsubscribeItems;
41
- function unsubscribeItem(selectorId, item) {
42
- if (item.removeCondition) {
43
- const id = getId(selectorId, item.id);
44
- if (exports.unsubs[id]) {
45
- exports.unsubs[id]();
46
- delete exports.unsubs[id];
47
- }
48
- }
49
- }
1
+ "use strict";
2
+ // This is the solution for cases when object was deleted from tree and we need to remove corresponding selectedItem.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.unsubscribeItems = exports.subscribeItems = exports.unsubs = void 0;
5
+ const subscribeToDrawing_1 = require("./subscribeToDrawing");
6
+ // This object contains unsubscibe function for all existing selections in all drawings
7
+ exports.unsubs = {};
8
+ function getId(selectorId, itemId) {
9
+ return `${selectorId}_${itemId}`;
10
+ }
11
+ function subscribeItems(buerliApi, drawingId, selectorId, items) {
12
+ const items_ = items || buerliApi.getState().drawing.refs[drawingId].selection.refs[selectorId].items;
13
+ items_.forEach(item => {
14
+ subscribeItem(buerliApi, drawingId, selectorId, item);
15
+ });
16
+ }
17
+ exports.subscribeItems = subscribeItems;
18
+ function subscribeItem(buerliApi, drawingId, selectorId, item) {
19
+ if (item.removeCondition && !exports.unsubs[getId(selectorId, item.id)]) {
20
+ const selApi = buerliApi.getState().drawing.refs[drawingId].api.selection;
21
+ exports.unsubs[getId(selectorId, item.id)] = (0, subscribeToDrawing_1.subscribeToDrawing)(buerliApi, drawingId, (d) => item.removeCondition && item.removeCondition(d), (removeCond) => {
22
+ var _a;
23
+ // Unselect item whose removeCondition got true
24
+ if (removeCond) {
25
+ const newItems = ((_a = buerliApi.getState().drawing.refs[drawingId].selection.refs[selectorId]) === null || _a === void 0 ? void 0 : _a.items) || [];
26
+ selApi.setItems(selectorId, newItems.filter(item_ => item_.id !== item.id));
27
+ }
28
+ });
29
+ }
30
+ }
31
+ function unsubscribeItems(buerliApi, drawingId, selectorId, items) {
32
+ var _a, _b, _c, _d;
33
+ // The following line leeds to exceptions if for example the corresponding drawing is going to be reset.
34
+ // To prevent those exceptions, check all properties for existance.
35
+ const items_ = items || ((_d = (_c = (_b = (_a = buerliApi.getState().drawing.refs[drawingId]) === null || _a === void 0 ? void 0 : _a.selection) === null || _b === void 0 ? void 0 : _b.refs) === null || _c === void 0 ? void 0 : _c[selectorId]) === null || _d === void 0 ? void 0 : _d.items) || [];
36
+ items_.forEach(item => {
37
+ unsubscribeItem(selectorId, item);
38
+ });
39
+ }
40
+ exports.unsubscribeItems = unsubscribeItems;
41
+ function unsubscribeItem(selectorId, item) {
42
+ if (item.removeCondition) {
43
+ const id = getId(selectorId, item.id);
44
+ if (exports.unsubs[id]) {
45
+ exports.unsubs[id]();
46
+ delete exports.unsubs[id];
47
+ }
48
+ }
49
+ }