@buerli.io/core 0.13.0 → 0.13.1-beta.1

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 (81) hide show
  1. package/CHANGELOG.md +7 -7
  2. package/README.md +12 -12
  3. package/build/cjs/geometry/ThreeGeometryCreator.js +320 -320
  4. package/build/cjs/geometry/index.js +17 -17
  5. package/build/cjs/graphic/filters.js +25 -25
  6. package/build/cjs/index.js +25 -25
  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 +112 -112
  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/IGraphicPackage.js +46 -46
  22. package/build/cjs/types/IStructurePatch.js +2 -2
  23. package/build/cjs/types/IStructureTree.js +28 -28
  24. package/build/cjs/types/InteractionInfo.js +11 -11
  25. package/build/cjs/types/index.js +20 -20
  26. package/build/cjs/utils/Math.js +91 -91
  27. package/build/cjs/utils/Measure.js +576 -576
  28. package/build/cjs/utils/Timing.js +34 -34
  29. package/build/esm/geometry/ThreeGeometryCreator.js +291 -291
  30. package/build/esm/geometry/index.js +1 -1
  31. package/build/esm/graphic/filters.js +12 -12
  32. package/build/esm/index.js +9 -9
  33. package/build/esm/store/index.js +26 -26
  34. package/build/esm/store/states/buerli.js +92 -92
  35. package/build/esm/store/states/cad.js +42 -42
  36. package/build/esm/store/states/drawing.js +45 -45
  37. package/build/esm/store/states/geometry.js +129 -129
  38. package/build/esm/store/states/graphic.js +107 -107
  39. package/build/esm/store/states/interaction.js +50 -50
  40. package/build/esm/store/states/message.js +21 -21
  41. package/build/esm/store/states/plugin.js +109 -109
  42. package/build/esm/store/states/selection.js +261 -261
  43. package/build/esm/store/states/structure.js +219 -219
  44. package/build/esm/store/store.js +3 -3
  45. package/build/esm/store/subscribtion/selection.js +44 -44
  46. package/build/esm/store/subscribtion/subscribeToDrawing.js +9 -9
  47. package/build/esm/types/IGraphicPackage.js +43 -43
  48. package/build/esm/types/IStructurePatch.js +1 -1
  49. package/build/esm/types/IStructureTree.js +24 -24
  50. package/build/esm/types/InteractionInfo.js +6 -6
  51. package/build/esm/types/index.js +4 -4
  52. package/build/esm/utils/Math.js +65 -65
  53. package/build/esm/utils/Measure.js +550 -550
  54. package/build/esm/utils/Timing.js +31 -31
  55. package/build/types/geometry/ThreeGeometryCreator.d.ts +256 -256
  56. package/build/types/geometry/index.d.ts +1 -1
  57. package/build/types/graphic/filters.d.ts +11 -11
  58. package/build/types/index.d.ts +37 -37
  59. package/build/types/store/index.d.ts +16 -16
  60. package/build/types/store/states/buerli.d.ts +41 -41
  61. package/build/types/store/states/cad.d.ts +53 -53
  62. package/build/types/store/states/drawing.d.ts +45 -45
  63. package/build/types/store/states/geometry.d.ts +65 -65
  64. package/build/types/store/states/graphic.d.ts +22 -22
  65. package/build/types/store/states/interaction.d.ts +34 -34
  66. package/build/types/store/states/message.d.ts +30 -30
  67. package/build/types/store/states/plugin.d.ts +53 -53
  68. package/build/types/store/states/selection.d.ts +62 -62
  69. package/build/types/store/states/structure.d.ts +47 -47
  70. package/build/types/store/store.d.ts +2 -2
  71. package/build/types/store/subscribtion/selection.d.ts +7 -7
  72. package/build/types/store/subscribtion/subscribeToDrawing.d.ts +4 -4
  73. package/build/types/types/IGraphicPackage.d.ts +160 -160
  74. package/build/types/types/IStructurePatch.d.ts +6 -6
  75. package/build/types/types/IStructureTree.d.ts +80 -80
  76. package/build/types/types/InteractionInfo.d.ts +43 -43
  77. package/build/types/types/index.d.ts +4 -4
  78. package/build/types/utils/Math.d.ts +21 -21
  79. package/build/types/utils/Measure.d.ts +64 -64
  80. package/build/types/utils/Timing.d.ts +8 -8
  81. package/package.json +44 -44
@@ -1,157 +1,157 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.geometryApi = exports.geometryData = void 0;
27
- const THREE = __importStar(require("three"));
28
- const ThreeGeometryCreator_1 = require("../../geometry/ThreeGeometryCreator");
29
- ////////////////////////////////////////////////////
30
- // DATA
31
- ////////////////////////////////////////////////////
32
- const geometryData = () => ({
33
- cache: {},
34
- stamp: -1,
35
- bounds: {
36
- center: new THREE.Vector3(0, 0, 0),
37
- radius: 200,
38
- min: new THREE.Vector3(-100, -100, -100),
39
- max: new THREE.Vector3(100, 100, 100),
40
- },
41
- config: { product: {} },
42
- });
43
- exports.geometryData = geometryData;
44
- ////////////////////////////////////////////////////
45
- // API
46
- ////////////////////////////////////////////////////
47
- const geometryApi = (set, get, buerliApi) => ({
48
- /**
49
- * Updates the @see geometry.bounds depending on all products of the model.
50
- * The update will only happen, if at least one solid of one product is available.
51
- */
52
- updateBounds: () => {
53
- const { api, structure } = get();
54
- if (structure.visibleContainers.length > 0) {
55
- const bb = api.structure.calculateProductBounds(structure.root);
56
- set(state => ({ geometry: Object.assign(Object.assign({}, state.geometry), { stamp: Date.now(), bounds: bb }) }));
57
- }
58
- },
59
- createGeometryIfNotCached: (containerId, color) => {
60
- const { graphic, geometry } = get();
61
- let geom = geometry.cache[containerId];
62
- if (!geom) {
63
- const container = graphic.containers[containerId];
64
- if (container) {
65
- geom = new ThreeGeometryCreator_1.ThreeGeometryCreator().createGeometry(container, color);
66
- set(state => {
67
- const geometryCache = Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, geom), { dirtyStamp: Date.now() }) });
68
- return {
69
- geometry: Object.assign(Object.assign({}, state.geometry), { cache: geometryCache, stamp: Date.now() }),
70
- };
71
- });
72
- }
73
- }
74
- return geom;
75
- },
76
- setGraphicColor: (containerId, graphicId, r, g, b) => {
77
- // Provide values as a CSS color string, which will be gamma corrected by three.js
78
- const color = new THREE.Color(`rgb(${Math.round(r * 255)}, ${Math.round(g * 255)}, ${Math.round(b * 255)})`);
79
- set(state => {
80
- // If container cache is empty return
81
- if (!state.geometry.cache[containerId])
82
- return state;
83
- // Shallow clone meshes
84
- const meshes = [...state.geometry.cache[containerId].meshes];
85
- // Find graphic Object
86
- const graphic = meshes.find(mesh => mesh.graphicId === graphicId);
87
- if (!graphic)
88
- return state;
89
- // Apply color
90
- meshes[meshes.indexOf(graphic)] = Object.assign(Object.assign({}, graphic), { color });
91
- return {
92
- geometry: Object.assign(Object.assign({}, state.geometry), { cache: Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, state.geometry.cache[containerId]), { meshes, dirtyStamp: Date.now() }) }) }),
93
- };
94
- });
95
- },
96
- setContainerColor: (containerId, r, g, b) => {
97
- // Provide values as a CSS color string, which will be gamma corrected by three.js
98
- const color = new THREE.Color(`rgb(${Math.round(r * 255)}, ${Math.round(g * 255)}, ${Math.round(b * 255)})`);
99
- const cachedGeom = Object.assign(Object.assign({}, get().geometry.cache[containerId]), { color });
100
- set(state => ({
101
- geometry: Object.assign(Object.assign({}, state.geometry), { cache: Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, cachedGeom), { dirtyStamp: Date.now() }) }) }),
102
- }));
103
- },
104
- setOpacity: (containerId, opacity) => {
105
- const cachedGeom = Object.assign(Object.assign({}, get().geometry.cache[containerId]), { opacity });
106
- set(state => ({
107
- geometry: Object.assign(Object.assign({}, state.geometry), { cache: Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, cachedGeom), { dirtyStamp: Date.now() }) }) }),
108
- }));
109
- },
110
- setConfig: (objId, config) => {
111
- set(state => {
112
- const productConfigs = Object.assign({}, state.geometry.config.product);
113
- if (config) {
114
- const newConfig = Object.assign({}, state.geometry.config.product[objId]);
115
- if ('disabled' in config)
116
- newConfig.disabled = config.disabled;
117
- if ('edges' in config)
118
- newConfig.edges = Object.assign(Object.assign({}, newConfig.edges), config.edges);
119
- if ('meshes' in config)
120
- newConfig.meshes = Object.assign(Object.assign({}, newConfig.meshes), config.meshes);
121
- if ('points' in config)
122
- newConfig.points = Object.assign(Object.assign({}, newConfig.points), config.points);
123
- productConfigs[objId] = newConfig;
124
- }
125
- else {
126
- delete productConfigs[objId];
127
- }
128
- return { geometry: Object.assign(Object.assign({}, state.geometry), { config: Object.assign(Object.assign({}, state.geometry.config), { product: productConfigs }) }) };
129
- });
130
- },
131
- findDecorated: () => {
132
- const { geometry: api } = get().api;
133
- return api.filter(elem => { var _a, _b, _c, _d, _e; return Boolean((_b = (_a = elem.rawGraphic) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.label) || Boolean((_e = (_d = (_c = elem.rawGraphic) === null || _c === void 0 ? void 0 : _c.properties) === null || _d === void 0 ? void 0 : _d.material) === null || _e === void 0 ? void 0 : _e.color); });
134
- },
135
- filter: (cb, options) => {
136
- const result = [];
137
- const { cache } = get().geometry;
138
- const contIds = Object.getOwnPropertyNames(cache).map(n => Number(n));
139
- for (const contId of contIds) {
140
- if ((options === null || options === void 0 ? void 0 : options.containerId) && contId !== options.containerId) {
141
- continue;
142
- }
143
- const ids = Object.getOwnPropertyNames(cache[contId].map).map(id => Number(id));
144
- for (const id of ids) {
145
- const elem = cache[contId].map[id];
146
- if (cb(elem)) {
147
- result.push(elem);
148
- if (options === null || options === void 0 ? void 0 : options.onlyOne) {
149
- return result;
150
- }
151
- }
152
- }
153
- }
154
- return result;
155
- },
156
- });
157
- exports.geometryApi = geometryApi;
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
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.geometryApi = exports.geometryData = void 0;
27
+ const THREE = __importStar(require("three"));
28
+ const ThreeGeometryCreator_1 = require("../../geometry/ThreeGeometryCreator");
29
+ ////////////////////////////////////////////////////
30
+ // DATA
31
+ ////////////////////////////////////////////////////
32
+ const geometryData = () => ({
33
+ cache: {},
34
+ stamp: -1,
35
+ bounds: {
36
+ center: new THREE.Vector3(0, 0, 0),
37
+ radius: 200,
38
+ min: new THREE.Vector3(-100, -100, -100),
39
+ max: new THREE.Vector3(100, 100, 100),
40
+ },
41
+ config: { product: {} },
42
+ });
43
+ exports.geometryData = geometryData;
44
+ ////////////////////////////////////////////////////
45
+ // API
46
+ ////////////////////////////////////////////////////
47
+ const geometryApi = (set, get, buerliApi) => ({
48
+ /**
49
+ * Updates the @see geometry.bounds depending on all products of the model.
50
+ * The update will only happen, if at least one solid of one product is available.
51
+ */
52
+ updateBounds: () => {
53
+ const { api, structure } = get();
54
+ if (structure.visibleContainers.length > 0) {
55
+ const bb = api.structure.calculateProductBounds(structure.root);
56
+ set(state => ({ geometry: Object.assign(Object.assign({}, state.geometry), { stamp: Date.now(), bounds: bb }) }));
57
+ }
58
+ },
59
+ createGeometryIfNotCached: (containerId, color) => {
60
+ const { graphic, geometry } = get();
61
+ let geom = geometry.cache[containerId];
62
+ if (!geom) {
63
+ const container = graphic.containers[containerId];
64
+ if (container) {
65
+ geom = new ThreeGeometryCreator_1.ThreeGeometryCreator().createGeometry(container, color);
66
+ set(state => {
67
+ const geometryCache = Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, geom), { dirtyStamp: Date.now() }) });
68
+ return {
69
+ geometry: Object.assign(Object.assign({}, state.geometry), { cache: geometryCache, stamp: Date.now() }),
70
+ };
71
+ });
72
+ }
73
+ }
74
+ return geom;
75
+ },
76
+ setGraphicColor: (containerId, graphicId, r, g, b) => {
77
+ // Provide values as a CSS color string, which will be gamma corrected by three.js
78
+ const color = new THREE.Color(`rgb(${Math.round(r * 255)}, ${Math.round(g * 255)}, ${Math.round(b * 255)})`);
79
+ set(state => {
80
+ // If container cache is empty return
81
+ if (!state.geometry.cache[containerId])
82
+ return state;
83
+ // Shallow clone meshes
84
+ const meshes = [...state.geometry.cache[containerId].meshes];
85
+ // Find graphic Object
86
+ const graphic = meshes.find(mesh => mesh.graphicId === graphicId);
87
+ if (!graphic)
88
+ return state;
89
+ // Apply color
90
+ meshes[meshes.indexOf(graphic)] = Object.assign(Object.assign({}, graphic), { color });
91
+ return {
92
+ geometry: Object.assign(Object.assign({}, state.geometry), { cache: Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, state.geometry.cache[containerId]), { meshes, dirtyStamp: Date.now() }) }) }),
93
+ };
94
+ });
95
+ },
96
+ setContainerColor: (containerId, r, g, b) => {
97
+ // Provide values as a CSS color string, which will be gamma corrected by three.js
98
+ const color = new THREE.Color(`rgb(${Math.round(r * 255)}, ${Math.round(g * 255)}, ${Math.round(b * 255)})`);
99
+ const cachedGeom = Object.assign(Object.assign({}, get().geometry.cache[containerId]), { color });
100
+ set(state => ({
101
+ geometry: Object.assign(Object.assign({}, state.geometry), { cache: Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, cachedGeom), { dirtyStamp: Date.now() }) }) }),
102
+ }));
103
+ },
104
+ setOpacity: (containerId, opacity) => {
105
+ const cachedGeom = Object.assign(Object.assign({}, get().geometry.cache[containerId]), { opacity });
106
+ set(state => ({
107
+ geometry: Object.assign(Object.assign({}, state.geometry), { cache: Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, cachedGeom), { dirtyStamp: Date.now() }) }) }),
108
+ }));
109
+ },
110
+ setConfig: (objId, config) => {
111
+ set(state => {
112
+ const productConfigs = Object.assign({}, state.geometry.config.product);
113
+ if (config) {
114
+ const newConfig = Object.assign({}, state.geometry.config.product[objId]);
115
+ if ('disabled' in config)
116
+ newConfig.disabled = config.disabled;
117
+ if ('edges' in config)
118
+ newConfig.edges = Object.assign(Object.assign({}, newConfig.edges), config.edges);
119
+ if ('meshes' in config)
120
+ newConfig.meshes = Object.assign(Object.assign({}, newConfig.meshes), config.meshes);
121
+ if ('points' in config)
122
+ newConfig.points = Object.assign(Object.assign({}, newConfig.points), config.points);
123
+ productConfigs[objId] = newConfig;
124
+ }
125
+ else {
126
+ delete productConfigs[objId];
127
+ }
128
+ return { geometry: Object.assign(Object.assign({}, state.geometry), { config: Object.assign(Object.assign({}, state.geometry.config), { product: productConfigs }) }) };
129
+ });
130
+ },
131
+ findDecorated: () => {
132
+ const { geometry: api } = get().api;
133
+ return api.filter(elem => { var _a, _b, _c, _d, _e; return Boolean((_b = (_a = elem.rawGraphic) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.label) || Boolean((_e = (_d = (_c = elem.rawGraphic) === null || _c === void 0 ? void 0 : _c.properties) === null || _d === void 0 ? void 0 : _d.material) === null || _e === void 0 ? void 0 : _e.color); });
134
+ },
135
+ filter: (cb, options) => {
136
+ const result = [];
137
+ const { cache } = get().geometry;
138
+ const contIds = Object.getOwnPropertyNames(cache).map(n => Number(n));
139
+ for (const contId of contIds) {
140
+ if ((options === null || options === void 0 ? void 0 : options.containerId) && contId !== options.containerId) {
141
+ continue;
142
+ }
143
+ const ids = Object.getOwnPropertyNames(cache[contId].map).map(id => Number(id));
144
+ for (const id of ids) {
145
+ const elem = cache[contId].map[id];
146
+ if (cb(elem)) {
147
+ result.push(elem);
148
+ if (options === null || options === void 0 ? void 0 : options.onlyOne) {
149
+ return result;
150
+ }
151
+ }
152
+ }
153
+ }
154
+ return result;
155
+ },
156
+ });
157
+ exports.geometryApi = geometryApi;
@@ -1,112 +1,112 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.graphicApi = exports.graphicData = void 0;
4
- ////////////////////////////////////////////////////
5
- // DATA
6
- ////////////////////////////////////////////////////
7
- const graphicData = () => ({
8
- containers: {},
9
- });
10
- exports.graphicData = graphicData;
11
- ////////////////////////////////////////////////////
12
- // API
13
- ////////////////////////////////////////////////////
14
- const graphicApi = (set, get, buerliApi) => ({
15
- addPackages: (packages) => {
16
- // Timing.dump('load', `add graphic packages ${graphic.length} ${graphic[0].containers.length}`)
17
- let cacheChanged = false;
18
- const newChache = Object.assign({}, get().geometry.cache);
19
- const addedContainers = {};
20
- packages.forEach(gr => {
21
- gr.containers.forEach(cont => {
22
- addedContainers[cont.id] = cont;
23
- // If the cached geometry for the added container already exist,
24
- // it has to be removed from the cache to ensure geometry updates.
25
- if (newChache[cont.id]) {
26
- delete newChache[cont.id];
27
- cacheChanged = true;
28
- }
29
- });
30
- });
31
- set(state => ({
32
- graphic: Object.assign(Object.assign({}, state.graphic), { containers: Object.assign(Object.assign({}, state.graphic.containers), addedContainers) }),
33
- geometry: cacheChanged ? Object.assign(Object.assign({}, state.geometry), { cache: newChache, stamp: Date.now() }) : state.geometry,
34
- }));
35
- const { graphic, api } = get();
36
- /**
37
- * Update the bounds with the newly added graphic.
38
- */
39
- api.geometry.updateBounds();
40
- /**
41
- * Create the geometry for the graphic packages.
42
- * Only the geometry which does not already exist will be created (@see createGeometryIfNotCached).
43
- */
44
- const containerIds = Object.getOwnPropertyNames(graphic.containers);
45
- for (const id of containerIds) {
46
- api.geometry.createGeometryIfNotCached(id);
47
- }
48
- // console.log('graphicContainers after add:', Object.getOwnPropertyNames(get().graphic.containers))
49
- },
50
- cleanupGraphicRecords: () => {
51
- const { graphic, geometry, api } = get();
52
- // collect the used solid ids from the structure tree
53
- const solidIds = api.structure.collectUsedSolidIds();
54
- // console.log('solidIds before cleanup:', solidIds)
55
- // cleanup the graphic containers in the state
56
- const usedContainers = {};
57
- const existingContainers = graphic.containers;
58
- const existingContainerIds = Object.getOwnPropertyNames(existingContainers);
59
- if (existingContainerIds.length > 0) {
60
- existingContainerIds.forEach(contIdStr => {
61
- const contId = Number(contIdStr);
62
- if (solidIds.indexOf(contId) >= 0) {
63
- usedContainers[contId] = existingContainers[contId];
64
- }
65
- });
66
- set({ graphic: Object.assign(Object.assign({}, graphic), { containers: usedContainers }) });
67
- // console.log('graphicContainers after cleanup:', Object.getOwnPropertyNames(get().graphic.ontainers))
68
- }
69
- // cleanup the cached geometry depending on the uses solids
70
- const usedGeometry = {};
71
- const existingGeometry = geometry.cache;
72
- const existingGeometryIds = Object.getOwnPropertyNames(existingGeometry);
73
- if (existingGeometryIds.length > 0) {
74
- existingGeometryIds.forEach(contIdStr => {
75
- const contId = Number(contIdStr);
76
- if (solidIds.indexOf(contId) >= 0) {
77
- usedGeometry[contId] = existingGeometry[contId];
78
- }
79
- });
80
- set({ geometry: Object.assign(Object.assign({}, geometry), { cache: usedGeometry, stamp: Date.now() }) });
81
- }
82
- },
83
- filter: (cb, options) => {
84
- const result = [];
85
- const { containers } = get().graphic;
86
- const contIds = Object.getOwnPropertyNames(containers).map(n => Number(n));
87
- for (const contId of contIds) {
88
- if ((options === null || options === void 0 ? void 0 : options.containerId) && contId !== options.containerId) {
89
- continue;
90
- }
91
- const cont = containers[contId];
92
- const items = [
93
- ...((cont === null || cont === void 0 ? void 0 : cont.arcs) || []),
94
- ...((cont === null || cont === void 0 ? void 0 : cont.cones) || []),
95
- ...((cont === null || cont === void 0 ? void 0 : cont.edges) || []),
96
- ...((cont === null || cont === void 0 ? void 0 : cont.lines) || []),
97
- ...((cont === null || cont === void 0 ? void 0 : cont.meshes) || []),
98
- ...((cont === null || cont === void 0 ? void 0 : cont.vertices) || []),
99
- ];
100
- for (const elem of items) {
101
- if (cb(elem)) {
102
- result.push({ elem, solidId: cont.owner, containerId: cont.id });
103
- if (options === null || options === void 0 ? void 0 : options.onlyOne) {
104
- return result;
105
- }
106
- }
107
- }
108
- }
109
- return result;
110
- },
111
- });
112
- exports.graphicApi = graphicApi;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.graphicApi = exports.graphicData = void 0;
4
+ ////////////////////////////////////////////////////
5
+ // DATA
6
+ ////////////////////////////////////////////////////
7
+ const graphicData = () => ({
8
+ containers: {},
9
+ });
10
+ exports.graphicData = graphicData;
11
+ ////////////////////////////////////////////////////
12
+ // API
13
+ ////////////////////////////////////////////////////
14
+ const graphicApi = (set, get, buerliApi) => ({
15
+ addPackages: (packages) => {
16
+ // Timing.dump('load', `add graphic packages ${graphic.length} ${graphic[0].containers.length}`)
17
+ let cacheChanged = false;
18
+ const newChache = Object.assign({}, get().geometry.cache);
19
+ const addedContainers = {};
20
+ packages.forEach(gr => {
21
+ gr.containers.forEach(cont => {
22
+ addedContainers[cont.id] = cont;
23
+ // If the cached geometry for the added container already exist,
24
+ // it has to be removed from the cache to ensure geometry updates.
25
+ if (newChache[cont.id]) {
26
+ delete newChache[cont.id];
27
+ cacheChanged = true;
28
+ }
29
+ });
30
+ });
31
+ set(state => ({
32
+ graphic: Object.assign(Object.assign({}, state.graphic), { containers: Object.assign(Object.assign({}, state.graphic.containers), addedContainers) }),
33
+ geometry: cacheChanged ? Object.assign(Object.assign({}, state.geometry), { cache: newChache, stamp: Date.now() }) : state.geometry,
34
+ }));
35
+ const { graphic, api } = get();
36
+ /**
37
+ * Update the bounds with the newly added graphic.
38
+ */
39
+ api.geometry.updateBounds();
40
+ /**
41
+ * Create the geometry for the graphic packages.
42
+ * Only the geometry which does not already exist will be created (@see createGeometryIfNotCached).
43
+ */
44
+ const containerIds = Object.getOwnPropertyNames(graphic.containers);
45
+ for (const id of containerIds) {
46
+ api.geometry.createGeometryIfNotCached(id);
47
+ }
48
+ // console.log('graphicContainers after add:', Object.getOwnPropertyNames(get().graphic.containers))
49
+ },
50
+ cleanupGraphicRecords: () => {
51
+ const { graphic, geometry, api } = get();
52
+ // collect the used solid ids from the structure tree
53
+ const solidIds = api.structure.collectUsedSolidIds();
54
+ // console.log('solidIds before cleanup:', solidIds)
55
+ // cleanup the graphic containers in the state
56
+ const usedContainers = {};
57
+ const existingContainers = graphic.containers;
58
+ const existingContainerIds = Object.getOwnPropertyNames(existingContainers);
59
+ if (existingContainerIds.length > 0) {
60
+ existingContainerIds.forEach(contIdStr => {
61
+ const contId = Number(contIdStr);
62
+ if (solidIds.indexOf(contId) >= 0) {
63
+ usedContainers[contId] = existingContainers[contId];
64
+ }
65
+ });
66
+ set({ graphic: Object.assign(Object.assign({}, graphic), { containers: usedContainers }) });
67
+ // console.log('graphicContainers after cleanup:', Object.getOwnPropertyNames(get().graphic.ontainers))
68
+ }
69
+ // cleanup the cached geometry depending on the uses solids
70
+ const usedGeometry = {};
71
+ const existingGeometry = geometry.cache;
72
+ const existingGeometryIds = Object.getOwnPropertyNames(existingGeometry);
73
+ if (existingGeometryIds.length > 0) {
74
+ existingGeometryIds.forEach(contIdStr => {
75
+ const contId = Number(contIdStr);
76
+ if (solidIds.indexOf(contId) >= 0) {
77
+ usedGeometry[contId] = existingGeometry[contId];
78
+ }
79
+ });
80
+ set({ geometry: Object.assign(Object.assign({}, geometry), { cache: usedGeometry, stamp: Date.now() }) });
81
+ }
82
+ },
83
+ filter: (cb, options) => {
84
+ const result = [];
85
+ const { containers } = get().graphic;
86
+ const contIds = Object.getOwnPropertyNames(containers).map(n => Number(n));
87
+ for (const contId of contIds) {
88
+ if ((options === null || options === void 0 ? void 0 : options.containerId) && contId !== options.containerId) {
89
+ continue;
90
+ }
91
+ const cont = containers[contId];
92
+ const items = [
93
+ ...((cont === null || cont === void 0 ? void 0 : cont.arcs) || []),
94
+ ...((cont === null || cont === void 0 ? void 0 : cont.cones) || []),
95
+ ...((cont === null || cont === void 0 ? void 0 : cont.edges) || []),
96
+ ...((cont === null || cont === void 0 ? void 0 : cont.lines) || []),
97
+ ...((cont === null || cont === void 0 ? void 0 : cont.meshes) || []),
98
+ ...((cont === null || cont === void 0 ? void 0 : cont.vertices) || []),
99
+ ];
100
+ for (const elem of items) {
101
+ if (cb(elem)) {
102
+ result.push({ elem, solidId: cont.owner, containerId: cont.id });
103
+ if (options === null || options === void 0 ? void 0 : options.onlyOne) {
104
+ return result;
105
+ }
106
+ }
107
+ }
108
+ }
109
+ return result;
110
+ },
111
+ });
112
+ exports.graphicApi = graphicApi;