@buerli.io/core 0.0.34 → 0.0.35-beta.0
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/geometry/ThreeGeometryCreator.js +284 -0
- package/build/cjs/geometry/index.js +13 -0
- package/build/cjs/index.js +20 -0
- package/build/cjs/store/index.js +46 -0
- package/build/{store → cjs/store}/states/buerli.js +9 -5
- package/build/{store → cjs/store}/states/canvas.js +7 -2
- package/build/cjs/store/states/drawing.js +44 -0
- package/build/{store → cjs/store}/states/geometry.js +29 -5
- package/build/{store → cjs/store}/states/graphic.js +7 -2
- package/build/cjs/store/states/message.js +25 -0
- package/build/{store → cjs/store}/states/plugin.js +12 -13
- package/build/{store → cjs/store}/states/selection.js +47 -18
- package/build/cjs/store/states/structure.js +203 -0
- package/build/cjs/store/store.js +14 -0
- package/build/cjs/store/subscribtion/selection.js +47 -0
- package/build/cjs/store/subscribtion/subscribeToDrawing.js +9 -0
- package/build/cjs/types/ErrorTypes.js +2 -0
- package/build/cjs/types/IGraphicPackage.js +24 -0
- package/build/cjs/types/IStructurePatch.js +2 -0
- package/build/cjs/types/IStructureTree.js +27 -0
- package/build/cjs/types/index.js +16 -0
- package/build/cjs/utils/Math.js +33 -0
- package/build/cjs/utils/Measure.js +576 -0
- package/build/cjs/utils/Timing.js +34 -0
- package/build/{geometry → esm/geometry}/ThreeGeometryCreator.js +47 -17
- package/build/{geometry → esm/geometry}/index.js +0 -0
- package/build/{index.js → esm/index.js} +1 -0
- package/build/{store → esm/store}/index.js +4 -1
- package/build/esm/store/states/buerli.js +116 -0
- package/build/esm/store/states/canvas.js +13 -0
- package/build/{store → esm/store}/states/drawing.js +0 -0
- package/build/esm/store/states/geometry.js +98 -0
- package/build/esm/store/states/graphic.js +82 -0
- package/build/{store → esm/store}/states/message.js +2 -2
- package/build/esm/store/states/plugin.js +152 -0
- package/build/esm/store/states/selection.js +269 -0
- package/build/{store → esm/store}/states/structure.js +10 -4
- package/build/{store → esm/store}/store.js +0 -0
- package/build/esm/store/subscribtion/selection.js +41 -0
- package/build/esm/store/subscribtion/subscribeToDrawing.js +5 -0
- package/build/{types → esm/types}/ErrorTypes.js +0 -0
- package/build/{types → esm/types}/IGraphicPackage.js +0 -0
- package/build/{types → esm/types}/IStructurePatch.js +0 -0
- package/build/{types → esm/types}/IStructureTree.js +0 -0
- package/build/{types → esm/types}/index.js +0 -0
- package/build/{utils → esm/utils}/Math.js +0 -0
- package/build/{utils → esm/utils}/Measure.js +1 -1
- package/build/{utils → esm/utils}/Timing.js +5 -1
- package/build/{geometry → types/geometry}/ThreeGeometryCreator.d.ts +0 -0
- package/build/{geometry → types/geometry}/index.d.ts +0 -0
- package/build/types/index.d.ts +36 -4
- package/build/{store → types/store}/index.d.ts +3 -0
- package/build/{store → types/store}/states/buerli.d.ts +0 -0
- package/build/{store → types/store}/states/canvas.d.ts +0 -0
- package/build/{store → types/store}/states/drawing.d.ts +0 -0
- package/build/{store → types/store}/states/geometry.d.ts +0 -0
- package/build/{store → types/store}/states/graphic.d.ts +0 -0
- package/build/{store → types/store}/states/message.d.ts +0 -0
- package/build/{store → types/store}/states/plugin.d.ts +1 -1
- package/build/{store → types/store}/states/selection.d.ts +1 -0
- package/build/{store → types/store}/states/structure.d.ts +0 -0
- package/build/{store → types/store}/store.d.ts +0 -0
- package/build/types/store/subscribtion/selection.d.ts +5 -0
- package/build/types/store/subscribtion/subscribeToDrawing.d.ts +2 -0
- package/build/types/{ErrorTypes.d.ts → types/ErrorTypes.d.ts} +0 -0
- package/build/types/{IGraphicPackage.d.ts → types/IGraphicPackage.d.ts} +0 -0
- package/build/types/{IStructurePatch.d.ts → types/IStructurePatch.d.ts} +0 -0
- package/build/types/{IStructureTree.d.ts → types/IStructureTree.d.ts} +0 -1
- package/build/types/types/index.d.ts +4 -0
- package/build/{utils → types/utils}/Math.d.ts +0 -0
- package/build/{utils → types/utils}/Measure.d.ts +0 -0
- package/build/{utils → types/utils}/Timing.d.ts +0 -0
- package/package.json +9 -6
- package/build/index.d.ts +0 -35
|
@@ -1,15 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createGraphicItem = exports.selectionApi = exports.selectionData = exports.BuerliScope = void 0;
|
|
4
|
+
const selection_1 = require("../subscribtion/selection");
|
|
1
5
|
////////////////////////////////////////////////////
|
|
2
6
|
// CONSTANTS
|
|
3
7
|
////////////////////////////////////////////////////
|
|
4
|
-
|
|
5
|
-
|
|
8
|
+
exports.BuerliScope = 'ClassCAD';
|
|
9
|
+
const selectionData = () => ({
|
|
6
10
|
refs: {},
|
|
7
11
|
active: null,
|
|
8
12
|
});
|
|
9
|
-
|
|
13
|
+
exports.selectionData = selectionData;
|
|
14
|
+
const selectionApi = (set, get) => ({
|
|
10
15
|
unselectAll() {
|
|
16
|
+
const drawingId = get().id;
|
|
11
17
|
const activeSelector = get().selection.active;
|
|
12
18
|
if (activeSelector) {
|
|
19
|
+
const unselItems = get().selection.refs[activeSelector].items;
|
|
20
|
+
selection_1.unsubscribeItems(drawingId, activeSelector, unselItems);
|
|
13
21
|
set(state => {
|
|
14
22
|
const selector = state.selection.refs[activeSelector];
|
|
15
23
|
return {
|
|
@@ -19,12 +27,13 @@ export const selectionApi = (set, get) => ({
|
|
|
19
27
|
}
|
|
20
28
|
},
|
|
21
29
|
unselect(...unselItems) {
|
|
22
|
-
const { selection } = get();
|
|
30
|
+
const { selection, id: drawingId } = get();
|
|
23
31
|
const activeSelectorId = selection.active;
|
|
24
32
|
if (activeSelectorId) {
|
|
25
33
|
// Remove unselItems from selector's items
|
|
26
34
|
const selector = selection.refs[activeSelectorId];
|
|
27
35
|
const newItems = selector.items.filter(item => unselItems.find(uItem => uItem.id === item.id) === undefined);
|
|
36
|
+
selection_1.unsubscribeItems(drawingId, activeSelectorId, unselItems);
|
|
28
37
|
if (selector.customUnSelect) {
|
|
29
38
|
// Find recently unselected items
|
|
30
39
|
const diff = selector.items.filter(item1 => {
|
|
@@ -43,7 +52,7 @@ export const selectionApi = (set, get) => ({
|
|
|
43
52
|
}
|
|
44
53
|
},
|
|
45
54
|
select(...newItems) {
|
|
46
|
-
const { selection, api } = get();
|
|
55
|
+
const { selection, api, id: drawingId } = get();
|
|
47
56
|
const activeSelectorId = selection.active;
|
|
48
57
|
const { isItemSelected } = api.selection;
|
|
49
58
|
if (activeSelectorId) {
|
|
@@ -53,20 +62,25 @@ export const selectionApi = (set, get) => ({
|
|
|
53
62
|
let filteredItems = newItems.filter((item1, idx) => newItems.findIndex(item2 => item2.id === item1.id) === idx);
|
|
54
63
|
// Remove already selected items and duplicates
|
|
55
64
|
filteredItems = filteredItems.filter(item => !isItemSelected(item, activeSelectorId));
|
|
65
|
+
let unsubItems = [];
|
|
56
66
|
let result = [...curItems, ...filteredItems];
|
|
57
67
|
if (selector.maxLen > 0) {
|
|
58
68
|
if (filteredItems.length === selector.maxLen) {
|
|
59
69
|
result = [...filteredItems];
|
|
70
|
+
unsubItems = [...curItems];
|
|
60
71
|
}
|
|
61
72
|
else if (filteredItems.length > selector.maxLen) {
|
|
62
73
|
const extraItems = filteredItems.length - selector.maxLen;
|
|
63
74
|
// If filteredItems has bigger length then selector.maxLen, remove last few items from filteredItems.
|
|
64
75
|
result = filteredItems.slice(0, -extraItems);
|
|
76
|
+
unsubItems = [...curItems];
|
|
65
77
|
}
|
|
66
78
|
else if (filteredItems.length + curItems.length >= selector.maxLen) {
|
|
67
79
|
const extraItems = filteredItems.length + curItems.length - selector.maxLen;
|
|
80
|
+
const allItems = [...curItems, ...filteredItems];
|
|
68
81
|
// If filteredItems.len + curItems.len > selector.maxLen, remove first few items from union of curItems and filteredItems.
|
|
69
|
-
result =
|
|
82
|
+
result = allItems.slice(extraItems);
|
|
83
|
+
unsubItems = allItems.slice(0, extraItems);
|
|
70
84
|
}
|
|
71
85
|
}
|
|
72
86
|
if (selector.customSelect !== undefined) {
|
|
@@ -77,6 +91,10 @@ export const selectionApi = (set, get) => ({
|
|
|
77
91
|
selector.customSelect(activeSelectorId, result, diff);
|
|
78
92
|
}
|
|
79
93
|
else {
|
|
94
|
+
// subscribe items which will be selected
|
|
95
|
+
selection_1.subscribeItems(drawingId, activeSelectorId, result);
|
|
96
|
+
// unsubscribe items which will be unselected
|
|
97
|
+
selection_1.unsubscribeItems(drawingId, activeSelectorId, unsubItems);
|
|
80
98
|
set(state => {
|
|
81
99
|
return {
|
|
82
100
|
selection: Object.assign(Object.assign({}, state.selection), { refs: Object.assign(Object.assign({}, state.selection.refs), { [activeSelectorId]: Object.assign(Object.assign({}, selector), { items: result }) }) }),
|
|
@@ -121,15 +139,19 @@ export const selectionApi = (set, get) => ({
|
|
|
121
139
|
customUnSelect,
|
|
122
140
|
} }) }),
|
|
123
141
|
}));
|
|
124
|
-
return () =>
|
|
125
|
-
get()
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
142
|
+
return () => {
|
|
143
|
+
if (get && get()) {
|
|
144
|
+
const drawingId = get().id;
|
|
145
|
+
selection_1.unsubscribeItems(drawingId, selectorId);
|
|
146
|
+
set(state => {
|
|
147
|
+
const refs = state.selection.refs;
|
|
148
|
+
delete refs[selectorId];
|
|
149
|
+
return {
|
|
150
|
+
selection: Object.assign(Object.assign({}, state.selection), { active: state.selection.active === selectorId ? null : state.selection.active, refs }),
|
|
151
|
+
};
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
};
|
|
133
155
|
},
|
|
134
156
|
areItemsSelected: (items, selectorId) => {
|
|
135
157
|
const { selection } = get();
|
|
@@ -155,6 +177,11 @@ export const selectionApi = (set, get) => ({
|
|
|
155
177
|
return Boolean(selector.items.find(i => areItemsEqual(i, item)));
|
|
156
178
|
},
|
|
157
179
|
setItems(id, items) {
|
|
180
|
+
var _a;
|
|
181
|
+
const { selection, id: drawingId } = get();
|
|
182
|
+
const curItems = ((_a = selection.refs[id]) === null || _a === void 0 ? void 0 : _a.items) || [];
|
|
183
|
+
selection_1.unsubscribeItems(drawingId, id, curItems);
|
|
184
|
+
selection_1.subscribeItems(drawingId, id, items);
|
|
158
185
|
set(state => {
|
|
159
186
|
const selector = state.selection.refs[id];
|
|
160
187
|
return {
|
|
@@ -173,25 +200,27 @@ export const selectionApi = (set, get) => ({
|
|
|
173
200
|
if (graphicId !== undefined) {
|
|
174
201
|
const geomElem = container.map[graphicId];
|
|
175
202
|
if (geomElem) {
|
|
176
|
-
return createGraphicItem(productId, geomElem);
|
|
203
|
+
return exports.createGraphicItem(productId, geomElem);
|
|
177
204
|
}
|
|
178
205
|
}
|
|
179
206
|
}
|
|
180
207
|
return null;
|
|
181
208
|
},
|
|
182
209
|
});
|
|
210
|
+
exports.selectionApi = selectionApi;
|
|
183
211
|
////////////////////////////////////////////////////
|
|
184
212
|
//#region GLOBAL FUNCTIONS
|
|
185
213
|
const areItemsEqual = (a, b) => a.id === b.id && a.scope === b.scope;
|
|
186
214
|
const createGraphicIdent = (productId, graphicId, type) => {
|
|
187
215
|
return {
|
|
188
216
|
id: `${productId}|${graphicId}|${type}`,
|
|
189
|
-
scope: BuerliScope,
|
|
217
|
+
scope: exports.BuerliScope,
|
|
190
218
|
label: (type[0] + type[1]).toUpperCase(),
|
|
191
219
|
};
|
|
192
220
|
};
|
|
193
|
-
|
|
221
|
+
const createGraphicItem = (productId, el) => {
|
|
194
222
|
return Object.assign(Object.assign({}, createGraphicIdent(productId, el.graphicId, el.type)), { data: Object.assign(Object.assign({}, el), { productId }) });
|
|
195
223
|
};
|
|
224
|
+
exports.createGraphicItem = createGraphicItem;
|
|
196
225
|
//#endregion GLOBAL FUNCTIONS
|
|
197
226
|
////////////////////////////////////////////////////
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.structureApi = exports.structureData = void 0;
|
|
26
|
+
const jsonpatch_1 = __importDefault(require("jsonpatch"));
|
|
27
|
+
const THREE = __importStar(require("three"));
|
|
28
|
+
const types_1 = require("../../types");
|
|
29
|
+
const Math_1 = require("../../utils/Math");
|
|
30
|
+
////////////////////////////////////////////////////
|
|
31
|
+
// DATA
|
|
32
|
+
////////////////////////////////////////////////////
|
|
33
|
+
const structureData = () => {
|
|
34
|
+
return Object.assign(Object.assign({}, types_1.DEFAULT_STRUCTURE_TREE()), { visibleContainers: [], products: [] });
|
|
35
|
+
};
|
|
36
|
+
exports.structureData = structureData;
|
|
37
|
+
////////////////////////////////////////////////////
|
|
38
|
+
// API
|
|
39
|
+
////////////////////////////////////////////////////
|
|
40
|
+
const structureApi = (set, get) => ({
|
|
41
|
+
get: () => {
|
|
42
|
+
return get().structure;
|
|
43
|
+
},
|
|
44
|
+
set: (structure) => {
|
|
45
|
+
const { api } = get();
|
|
46
|
+
// TODO: clear object selection if needed
|
|
47
|
+
// 1. set the state
|
|
48
|
+
set({
|
|
49
|
+
structure: Object.assign(Object.assign({}, get().structure), structure),
|
|
50
|
+
});
|
|
51
|
+
// 2. collect and cleanup data
|
|
52
|
+
api.graphic.cleanupGraphicRecords();
|
|
53
|
+
// console.log('cleanup')
|
|
54
|
+
api.structure.postProcessStructureUpdate();
|
|
55
|
+
},
|
|
56
|
+
applyPatches: (patches) => {
|
|
57
|
+
const before = get().structure.products.concat(get().structure.visibleContainers);
|
|
58
|
+
// Timing.dump('load', 'received tree patches')
|
|
59
|
+
set(state => {
|
|
60
|
+
let structure = state.structure;
|
|
61
|
+
try {
|
|
62
|
+
structure = jsonpatch_1.default.apply_patch(state.structure, patches);
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
console.error(e);
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
structure: Object.assign(Object.assign({}, get().structure), structure),
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
const { api } = get();
|
|
72
|
+
api.structure.postProcessStructureUpdate();
|
|
73
|
+
// Update the bounds, but only if products or visible containers changed.
|
|
74
|
+
const after = get().structure.products.concat(get().structure.visibleContainers);
|
|
75
|
+
if (before.sort().join() !== after.sort().join()) {
|
|
76
|
+
api.geometry.updateBounds();
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
filterTree: (tree, filter) => {
|
|
80
|
+
const objs = [];
|
|
81
|
+
Object.getOwnPropertyNames(tree).forEach(name => {
|
|
82
|
+
const obj = tree[name];
|
|
83
|
+
if (filter(obj)) {
|
|
84
|
+
objs.push(obj);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
return objs;
|
|
88
|
+
},
|
|
89
|
+
collectUsedSolidIds: () => {
|
|
90
|
+
const { api, structure } = get();
|
|
91
|
+
const solidObjs = api.structure.filterTree(structure.tree, obj => typeof obj.geometryIdList !== 'undefined');
|
|
92
|
+
const solidIds = [];
|
|
93
|
+
solidObjs.forEach(solidObj => solidIds.push(...(solidObj.geometryIdList || [])));
|
|
94
|
+
return solidIds;
|
|
95
|
+
},
|
|
96
|
+
collectProducts: (root) => {
|
|
97
|
+
const { structure } = get();
|
|
98
|
+
const products = [];
|
|
99
|
+
const recursive = (id) => {
|
|
100
|
+
const obj = structure.tree[id];
|
|
101
|
+
if (obj) {
|
|
102
|
+
if ((obj.solids && obj.solids.length > 0) || obj.link) {
|
|
103
|
+
products.push(obj);
|
|
104
|
+
}
|
|
105
|
+
if (obj.children) {
|
|
106
|
+
for (const child of obj.children) {
|
|
107
|
+
recursive(child);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
recursive(root);
|
|
113
|
+
return products;
|
|
114
|
+
},
|
|
115
|
+
getProductSolidIds: (productId) => {
|
|
116
|
+
const { structure } = get();
|
|
117
|
+
let solids;
|
|
118
|
+
const product = structure.tree[productId];
|
|
119
|
+
if (product.link !== undefined) {
|
|
120
|
+
solids = structure.tree[product.link].solids || [];
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
solids = product.solids || [];
|
|
124
|
+
}
|
|
125
|
+
return [...solids];
|
|
126
|
+
},
|
|
127
|
+
postProcessStructureUpdate: () => {
|
|
128
|
+
const { api, structure } = get();
|
|
129
|
+
//////////
|
|
130
|
+
// 1. Collect the products
|
|
131
|
+
//////////
|
|
132
|
+
const searchRoot = structure.root; // || structure.currentNode || structure.currentProduct
|
|
133
|
+
const productIds = api.structure.collectProducts(searchRoot).map(p => p.id);
|
|
134
|
+
//////////
|
|
135
|
+
// 2. Collect the solid ids
|
|
136
|
+
//////////
|
|
137
|
+
let solidIds = [];
|
|
138
|
+
productIds.forEach(prodId => solidIds.push(...(api.structure.getProductSolidIds(prodId) || [])));
|
|
139
|
+
// remove duplicates
|
|
140
|
+
solidIds = solidIds.filter((item, index) => solidIds.indexOf(item) === index);
|
|
141
|
+
//////////
|
|
142
|
+
// 3. Add the result to the state
|
|
143
|
+
//////////
|
|
144
|
+
set(state => ({
|
|
145
|
+
structure: Object.assign(Object.assign({}, state.structure), { visibleContainers: solidIds, products: productIds }),
|
|
146
|
+
}));
|
|
147
|
+
},
|
|
148
|
+
/**
|
|
149
|
+
* Calculates the global transformation matrix for the given _objectId_.
|
|
150
|
+
*
|
|
151
|
+
* @param objectId The object to calculate the global transformation for.
|
|
152
|
+
* @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.
|
|
153
|
+
* @returns The global transformation matrix for the given _objectId_.
|
|
154
|
+
*/
|
|
155
|
+
calculateGlobalTransformation: (objectId, matrix = new THREE.Matrix4().identity()) => {
|
|
156
|
+
const { structure, api } = get();
|
|
157
|
+
const { tree, root } = structure;
|
|
158
|
+
const obj = tree[objectId];
|
|
159
|
+
if (obj && obj.coordinateSystem) {
|
|
160
|
+
const objMatrix = Math_1.MathUtils.convertToMatrix4(obj.coordinateSystem);
|
|
161
|
+
matrix = matrix.clone().premultiply(objMatrix);
|
|
162
|
+
}
|
|
163
|
+
if (objectId !== root && obj.parent) {
|
|
164
|
+
matrix = api.structure.calculateGlobalTransformation(obj.parent, matrix);
|
|
165
|
+
}
|
|
166
|
+
return matrix;
|
|
167
|
+
},
|
|
168
|
+
calculateProductBounds: (productId, base) => {
|
|
169
|
+
const { graphic, api } = get();
|
|
170
|
+
const posInf = Number.POSITIVE_INFINITY;
|
|
171
|
+
const negInf = Number.NEGATIVE_INFINITY;
|
|
172
|
+
const baseMin = base ? base.min.clone() : new THREE.Vector3(posInf, posInf, posInf);
|
|
173
|
+
const baseMax = base ? base.max.clone() : new THREE.Vector3(negInf, negInf, negInf);
|
|
174
|
+
let box = new THREE.Box3(baseMin, baseMax);
|
|
175
|
+
const productIds = api.structure.collectProducts(productId).map(p => p.id);
|
|
176
|
+
for (const pId of productIds) {
|
|
177
|
+
const matrix = api.structure.calculateGlobalTransformation(pId);
|
|
178
|
+
const contIds = api.structure.getProductSolidIds(pId);
|
|
179
|
+
for (const contId of contIds) {
|
|
180
|
+
const cont = graphic.containers[contId];
|
|
181
|
+
if (cont) {
|
|
182
|
+
const min = new THREE.Vector3().fromArray(cont.properties.min);
|
|
183
|
+
const max = new THREE.Vector3().fromArray(cont.properties.max);
|
|
184
|
+
const b = new THREE.Box3(min.clone(), max.clone());
|
|
185
|
+
b.applyMatrix4(matrix);
|
|
186
|
+
box = box.union(b);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
const sphere = new THREE.Sphere();
|
|
191
|
+
box.getBoundingSphere(sphere);
|
|
192
|
+
return { center: sphere.center, radius: sphere.radius, max: box.max, min: box.min };
|
|
193
|
+
},
|
|
194
|
+
/**
|
|
195
|
+
* This is a workaround to get the corresponding drawing id via API.
|
|
196
|
+
*
|
|
197
|
+
* > !!! Should not be used in user code !!!
|
|
198
|
+
*
|
|
199
|
+
* @returns The drawing id.
|
|
200
|
+
*/
|
|
201
|
+
getDrawingId: () => get().id,
|
|
202
|
+
});
|
|
203
|
+
exports.structureApi = structureApi;
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
const store = (set, get, buerliApi) => buerli_1.createState(set, get, buerliApi);
|
|
10
|
+
const wnd = typeof window !== 'undefined' ? window : null;
|
|
11
|
+
const middleware = wnd ? wnd.BUERLI_MIDDLEWARE || (wnd.BUERLI_MIDDLEWARE = []) : [];
|
|
12
|
+
const buerliStore = middleware.reduceRight((acc, cur) => cur(acc), store);
|
|
13
|
+
const api = vanilla_1.default(buerliStore);
|
|
14
|
+
exports.api = api;
|
|
@@ -0,0 +1,47 @@
|
|
|
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 __1 = require("../..");
|
|
6
|
+
const subscribeToDrawing_1 = require("./subscribeToDrawing");
|
|
7
|
+
// This object contains unsubscibe function for all existing selections in all drawings
|
|
8
|
+
exports.unsubs = {};
|
|
9
|
+
function getId(selectorId, itemId) {
|
|
10
|
+
return `${selectorId}_${itemId}`;
|
|
11
|
+
}
|
|
12
|
+
function subscribeItems(drawingId, selectorId, items) {
|
|
13
|
+
const items_ = items || __1.getDrawing(drawingId).selection.refs[selectorId].items;
|
|
14
|
+
items_.forEach(item => {
|
|
15
|
+
subscribeItem(drawingId, selectorId, item);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
exports.subscribeItems = subscribeItems;
|
|
19
|
+
function subscribeItem(drawingId, selectorId, item) {
|
|
20
|
+
if (item.removeCondition && !exports.unsubs[getId(selectorId, item.id)]) {
|
|
21
|
+
const selApi = __1.getDrawing(drawingId).api.selection;
|
|
22
|
+
exports.unsubs[getId(selectorId, item.id)] = subscribeToDrawing_1.subscribeToDrawing(drawingId, (d) => item.removeCondition && item.removeCondition(d), (removeCond) => {
|
|
23
|
+
var _a;
|
|
24
|
+
// Unselect item whose removeCondition got true
|
|
25
|
+
if (removeCond) {
|
|
26
|
+
const newItems = ((_a = __1.getDrawing(drawingId).selection.refs[selectorId]) === null || _a === void 0 ? void 0 : _a.items) || [];
|
|
27
|
+
selApi.setItems(selectorId, newItems.filter(item_ => item_.id !== item.id));
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function unsubscribeItems(drawingId, selectorId, items) {
|
|
33
|
+
const items_ = items || __1.getDrawing(drawingId).selection.refs[selectorId].items;
|
|
34
|
+
items_.forEach(item => {
|
|
35
|
+
unsubscribeItem(selectorId, item);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
exports.unsubscribeItems = unsubscribeItems;
|
|
39
|
+
function unsubscribeItem(selectorId, item) {
|
|
40
|
+
if (item.removeCondition) {
|
|
41
|
+
const id = getId(selectorId, item.id);
|
|
42
|
+
if (exports.unsubs[id]) {
|
|
43
|
+
exports.unsubs[id]();
|
|
44
|
+
delete exports.unsubs[id];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.subscribeToDrawing = void 0;
|
|
4
|
+
const store_1 = require("../store");
|
|
5
|
+
function subscribeToDrawing(drawingId, sel, callback) {
|
|
6
|
+
const unsub = store_1.api.subscribe(callback, state => state.drawing.refs[drawingId] && sel(state.drawing.refs[drawingId]));
|
|
7
|
+
return unsub;
|
|
8
|
+
}
|
|
9
|
+
exports.subscribeToDrawing = subscribeToDrawing;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Primitives = exports.LineSegments = exports.Surfaces = exports.AllTypes = exports.GraphicType = void 0;
|
|
4
|
+
var GraphicType;
|
|
5
|
+
(function (GraphicType) {
|
|
6
|
+
GraphicType["POINT"] = "point";
|
|
7
|
+
GraphicType["LINE"] = "line";
|
|
8
|
+
GraphicType["EDGE"] = "edge";
|
|
9
|
+
GraphicType["ARC"] = "arc";
|
|
10
|
+
GraphicType["CIRCLE"] = "circle";
|
|
11
|
+
GraphicType["PLANE"] = "plane";
|
|
12
|
+
GraphicType["CYLINDER"] = "cylinder";
|
|
13
|
+
GraphicType["CONE"] = "cone";
|
|
14
|
+
GraphicType["SPHERE"] = "sphere";
|
|
15
|
+
GraphicType["NURBS"] = "nurbs";
|
|
16
|
+
GraphicType["NURBSSURFACE"] = "nurbsSurface";
|
|
17
|
+
GraphicType["LOOP"] = "loop";
|
|
18
|
+
GraphicType["SOLID"] = "solid";
|
|
19
|
+
})(GraphicType = exports.GraphicType || (exports.GraphicType = {}));
|
|
20
|
+
const G = GraphicType;
|
|
21
|
+
exports.AllTypes = Object.keys(G).map(key => G[key]);
|
|
22
|
+
exports.Surfaces = [G.PLANE, G.CYLINDER, G.CONE, G.SPHERE, G.NURBS, G.NURBSSURFACE];
|
|
23
|
+
exports.LineSegments = [G.LINE, G.EDGE, G.ARC, G.CIRCLE];
|
|
24
|
+
exports.Primitives = exports.Surfaces.concat(exports.LineSegments).concat([G.POINT]);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MemberType = exports.NOID = exports.DEFAULT_STRUCTURE_TREE = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Defines the default structure tree.
|
|
6
|
+
* Should be used to initialize a new structure tree.
|
|
7
|
+
*/
|
|
8
|
+
const DEFAULT_STRUCTURE_TREE = () => {
|
|
9
|
+
return {
|
|
10
|
+
tree: {},
|
|
11
|
+
root: exports.NOID,
|
|
12
|
+
currentProduct: exports.NOID,
|
|
13
|
+
currentNode: exports.NOID,
|
|
14
|
+
testRoot: exports.NOID,
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
exports.DEFAULT_STRUCTURE_TREE = DEFAULT_STRUCTURE_TREE;
|
|
18
|
+
/** Zero is no Id in classcad, and no object will exist in the CCDatabase for Id === 0! */
|
|
19
|
+
exports.NOID = 0;
|
|
20
|
+
var MemberType;
|
|
21
|
+
(function (MemberType) {
|
|
22
|
+
MemberType["ARRAY"] = "array";
|
|
23
|
+
MemberType["ID"] = "id";
|
|
24
|
+
MemberType["POINT"] = "point";
|
|
25
|
+
MemberType["REAL"] = "real";
|
|
26
|
+
MemberType["STRING"] = "string";
|
|
27
|
+
})(MemberType = exports.MemberType || (exports.MemberType = {}));
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./ErrorTypes"), exports);
|
|
14
|
+
__exportStar(require("./IGraphicPackage"), exports);
|
|
15
|
+
__exportStar(require("./IStructurePatch"), exports);
|
|
16
|
+
__exportStar(require("./IStructureTree"), exports);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.MathUtils = void 0;
|
|
23
|
+
const THREE = __importStar(require("three"));
|
|
24
|
+
exports.MathUtils = {
|
|
25
|
+
convertToMatrix4: function (coordinateSystem) {
|
|
26
|
+
const [orig, vx, vy, vz] = coordinateSystem.map(row => new THREE.Vector3().fromArray(row));
|
|
27
|
+
return new THREE.Matrix4().makeBasis(vx, vy, vz).setPosition(orig);
|
|
28
|
+
},
|
|
29
|
+
convertToMatrix3: function (coordinateSystem) {
|
|
30
|
+
const [, vx, vy, vz] = coordinateSystem;
|
|
31
|
+
return new THREE.Matrix3().fromArray([...vx, ...vy, ...vz]);
|
|
32
|
+
},
|
|
33
|
+
};
|