@buerli.io/core 1.0.1 → 1.1.0-beta.8

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 +41 -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 +32 -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 +29 -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 +28 -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 +17 -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 +32 -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 +2 -2
@@ -1,129 +1,129 @@
1
- import * as THREE from 'three';
2
- import { ThreeGeometryCreator } from '../../geometry/ThreeGeometryCreator';
3
- ////////////////////////////////////////////////////
4
- // DATA
5
- ////////////////////////////////////////////////////
6
- export const geometryData = () => ({
7
- cache: {},
8
- stamp: -1,
9
- bounds: {
10
- center: new THREE.Vector3(0, 0, 0),
11
- radius: 200,
12
- min: new THREE.Vector3(-100, -100, -100),
13
- max: new THREE.Vector3(100, 100, 100),
14
- },
15
- config: { product: {} },
16
- });
17
- ////////////////////////////////////////////////////
18
- // API
19
- ////////////////////////////////////////////////////
20
- export const geometryApi = (set, get, buerliApi) => ({
21
- /**
22
- * Updates the @see geometry.bounds depending on all products of the model.
23
- * The update will only happen, if at least one solid of one product is available.
24
- */
25
- updateBounds: () => {
26
- const { api, structure } = get();
27
- if (structure.visibleContainers.length > 0) {
28
- const bb = api.structure.calculateProductBounds(structure.root);
29
- set(state => ({ geometry: Object.assign(Object.assign({}, state.geometry), { stamp: Date.now(), bounds: bb }) }));
30
- }
31
- },
32
- createGeometryIfNotCached: (containerId, color) => {
33
- const { graphic, geometry } = get();
34
- let geom = geometry.cache[containerId];
35
- if (!geom) {
36
- const container = graphic.containers[containerId];
37
- if (container) {
38
- geom = new ThreeGeometryCreator().createGeometry(container, color);
39
- set(state => {
40
- const geometryCache = Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, geom), { dirtyStamp: Date.now() }) });
41
- return {
42
- geometry: Object.assign(Object.assign({}, state.geometry), { cache: geometryCache, stamp: Date.now() }),
43
- };
44
- });
45
- }
46
- }
47
- return geom;
48
- },
49
- setGraphicColor: (containerId, graphicId, r, g, b) => {
50
- // Provide values as a CSS color string, which will be gamma corrected by three.js
51
- const color = new THREE.Color(`rgb(${Math.round(r * 255)}, ${Math.round(g * 255)}, ${Math.round(b * 255)})`);
52
- set(state => {
53
- // If container cache is empty return
54
- if (!state.geometry.cache[containerId])
55
- return state;
56
- // Shallow clone meshes
57
- const meshes = [...state.geometry.cache[containerId].meshes];
58
- // Find graphic Object
59
- const graphic = meshes.find(mesh => mesh.graphicId === graphicId);
60
- if (!graphic)
61
- return state;
62
- // Apply color
63
- meshes[meshes.indexOf(graphic)] = Object.assign(Object.assign({}, graphic), { color });
64
- return {
65
- 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() }) }) }),
66
- };
67
- });
68
- },
69
- setContainerColor: (containerId, r, g, b) => {
70
- // Provide values as a CSS color string, which will be gamma corrected by three.js
71
- const color = new THREE.Color(`rgb(${Math.round(r * 255)}, ${Math.round(g * 255)}, ${Math.round(b * 255)})`);
72
- const cachedGeom = Object.assign(Object.assign({}, get().geometry.cache[containerId]), { color });
73
- set(state => ({
74
- geometry: Object.assign(Object.assign({}, state.geometry), { cache: Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, cachedGeom), { dirtyStamp: Date.now() }) }) }),
75
- }));
76
- },
77
- setOpacity: (containerId, opacity) => {
78
- const cachedGeom = Object.assign(Object.assign({}, get().geometry.cache[containerId]), { opacity });
79
- set(state => ({
80
- geometry: Object.assign(Object.assign({}, state.geometry), { cache: Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, cachedGeom), { dirtyStamp: Date.now() }) }) }),
81
- }));
82
- },
83
- setConfig: (objId, config) => {
84
- set(state => {
85
- const productConfigs = Object.assign({}, state.geometry.config.product);
86
- if (config) {
87
- const newConfig = Object.assign({}, state.geometry.config.product[objId]);
88
- if ('disabled' in config)
89
- newConfig.disabled = config.disabled;
90
- if ('edges' in config)
91
- newConfig.edges = Object.assign(Object.assign({}, newConfig.edges), config.edges);
92
- if ('meshes' in config)
93
- newConfig.meshes = Object.assign(Object.assign({}, newConfig.meshes), config.meshes);
94
- if ('points' in config)
95
- newConfig.points = Object.assign(Object.assign({}, newConfig.points), config.points);
96
- productConfigs[objId] = newConfig;
97
- }
98
- else {
99
- delete productConfigs[objId];
100
- }
101
- return { geometry: Object.assign(Object.assign({}, state.geometry), { config: Object.assign(Object.assign({}, state.geometry.config), { product: productConfigs }) }) };
102
- });
103
- },
104
- findDecorated: () => {
105
- const { geometry: api } = get().api;
106
- 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); });
107
- },
108
- filter: (cb, options) => {
109
- const result = [];
110
- const { cache } = get().geometry;
111
- const contIds = Object.getOwnPropertyNames(cache).map(n => Number(n));
112
- for (const contId of contIds) {
113
- if ((options === null || options === void 0 ? void 0 : options.containerId) && contId !== options.containerId) {
114
- continue;
115
- }
116
- const ids = Object.getOwnPropertyNames(cache[contId].map).map(id => Number(id));
117
- for (const id of ids) {
118
- const elem = cache[contId].map[id];
119
- if (cb(elem)) {
120
- result.push(elem);
121
- if (options === null || options === void 0 ? void 0 : options.onlyOne) {
122
- return result;
123
- }
124
- }
125
- }
126
- }
127
- return result;
128
- },
129
- });
1
+ import * as THREE from 'three';
2
+ import { ThreeGeometryCreator } from '../../geometry/ThreeGeometryCreator';
3
+ ////////////////////////////////////////////////////
4
+ // DATA
5
+ ////////////////////////////////////////////////////
6
+ export const geometryData = () => ({
7
+ cache: {},
8
+ stamp: -1,
9
+ bounds: {
10
+ center: new THREE.Vector3(0, 0, 0),
11
+ radius: 200,
12
+ min: new THREE.Vector3(-100, -100, -100),
13
+ max: new THREE.Vector3(100, 100, 100),
14
+ },
15
+ config: { product: {} },
16
+ });
17
+ ////////////////////////////////////////////////////
18
+ // API
19
+ ////////////////////////////////////////////////////
20
+ export const geometryApi = (set, get, buerliApi) => ({
21
+ /**
22
+ * Updates the @see geometry.bounds depending on all products of the model.
23
+ * The update will only happen, if at least one solid of one product is available.
24
+ */
25
+ updateBounds: () => {
26
+ const { api, structure } = get();
27
+ if (structure.visibleContainers.length > 0) {
28
+ const bb = api.structure.calculateProductBounds(structure.root);
29
+ set(state => ({ geometry: Object.assign(Object.assign({}, state.geometry), { stamp: Date.now(), bounds: bb }) }));
30
+ }
31
+ },
32
+ createGeometryIfNotCached: (containerId, color) => {
33
+ const { graphic, geometry } = get();
34
+ let geom = geometry.cache[containerId];
35
+ if (!geom) {
36
+ const container = graphic.containers[containerId];
37
+ if (container) {
38
+ geom = new ThreeGeometryCreator().createGeometry(container, color);
39
+ set(state => {
40
+ const geometryCache = Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, geom), { dirtyStamp: Date.now() }) });
41
+ return {
42
+ geometry: Object.assign(Object.assign({}, state.geometry), { cache: geometryCache, stamp: Date.now() }),
43
+ };
44
+ });
45
+ }
46
+ }
47
+ return geom;
48
+ },
49
+ setGraphicColor: (containerId, graphicId, r, g, b) => {
50
+ // Provide values as a CSS color string, which will be gamma corrected by three.js
51
+ const color = new THREE.Color(`rgb(${Math.round(r * 255)}, ${Math.round(g * 255)}, ${Math.round(b * 255)})`);
52
+ set(state => {
53
+ // If container cache is empty return
54
+ if (!state.geometry.cache[containerId])
55
+ return state;
56
+ // Shallow clone meshes
57
+ const meshes = [...state.geometry.cache[containerId].meshes];
58
+ // Find graphic Object
59
+ const graphic = meshes.find(mesh => mesh.graphicId === graphicId);
60
+ if (!graphic)
61
+ return state;
62
+ // Apply color
63
+ meshes[meshes.indexOf(graphic)] = Object.assign(Object.assign({}, graphic), { color });
64
+ return {
65
+ 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() }) }) }),
66
+ };
67
+ });
68
+ },
69
+ setContainerColor: (containerId, r, g, b) => {
70
+ // Provide values as a CSS color string, which will be gamma corrected by three.js
71
+ const color = new THREE.Color(`rgb(${Math.round(r * 255)}, ${Math.round(g * 255)}, ${Math.round(b * 255)})`);
72
+ const cachedGeom = Object.assign(Object.assign({}, get().geometry.cache[containerId]), { color });
73
+ set(state => ({
74
+ geometry: Object.assign(Object.assign({}, state.geometry), { cache: Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, cachedGeom), { dirtyStamp: Date.now() }) }) }),
75
+ }));
76
+ },
77
+ setOpacity: (containerId, opacity) => {
78
+ const cachedGeom = Object.assign(Object.assign({}, get().geometry.cache[containerId]), { opacity });
79
+ set(state => ({
80
+ geometry: Object.assign(Object.assign({}, state.geometry), { cache: Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, cachedGeom), { dirtyStamp: Date.now() }) }) }),
81
+ }));
82
+ },
83
+ setConfig: (objId, config) => {
84
+ set(state => {
85
+ const productConfigs = Object.assign({}, state.geometry.config.product);
86
+ if (config) {
87
+ const newConfig = Object.assign({}, state.geometry.config.product[objId]);
88
+ if ('disabled' in config)
89
+ newConfig.disabled = config.disabled;
90
+ if ('edges' in config)
91
+ newConfig.edges = Object.assign(Object.assign({}, newConfig.edges), config.edges);
92
+ if ('meshes' in config)
93
+ newConfig.meshes = Object.assign(Object.assign({}, newConfig.meshes), config.meshes);
94
+ if ('points' in config)
95
+ newConfig.points = Object.assign(Object.assign({}, newConfig.points), config.points);
96
+ productConfigs[objId] = newConfig;
97
+ }
98
+ else {
99
+ delete productConfigs[objId];
100
+ }
101
+ return { geometry: Object.assign(Object.assign({}, state.geometry), { config: Object.assign(Object.assign({}, state.geometry.config), { product: productConfigs }) }) };
102
+ });
103
+ },
104
+ findDecorated: () => {
105
+ const { geometry: api } = get().api;
106
+ 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); });
107
+ },
108
+ filter: (cb, options) => {
109
+ const result = [];
110
+ const { cache } = get().geometry;
111
+ const contIds = Object.getOwnPropertyNames(cache).map(n => Number(n));
112
+ for (const contId of contIds) {
113
+ if ((options === null || options === void 0 ? void 0 : options.containerId) && contId !== options.containerId) {
114
+ continue;
115
+ }
116
+ const ids = Object.getOwnPropertyNames(cache[contId].map).map(id => Number(id));
117
+ for (const id of ids) {
118
+ const elem = cache[contId].map[id];
119
+ if (cb(elem)) {
120
+ result.push(elem);
121
+ if (options === null || options === void 0 ? void 0 : options.onlyOne) {
122
+ return result;
123
+ }
124
+ }
125
+ }
126
+ }
127
+ return result;
128
+ },
129
+ });
@@ -1,110 +1,110 @@
1
- ////////////////////////////////////////////////////
2
- // DATA
3
- ////////////////////////////////////////////////////
4
- export const graphicData = () => ({
5
- containers: {},
6
- });
7
- ////////////////////////////////////////////////////
8
- // API
9
- ////////////////////////////////////////////////////
10
- export const graphicApi = (set, get, buerliApi) => ({
11
- addPackages: (packages) => {
12
- // Timing.dump('load', `add graphic packages ${graphic.length} ${graphic[0].containers.length}`)
13
- if (!Array.isArray(packages)) {
14
- packages = [packages];
15
- }
16
- let cacheChanged = false;
17
- const newChache = Object.assign({}, get().geometry.cache);
18
- const addedContainers = {};
19
- packages.forEach(gr => {
20
- gr.containers.forEach(cont => {
21
- addedContainers[cont.id] = cont;
22
- // If the cached geometry for the added container already exist,
23
- // it has to be removed from the cache to ensure geometry updates.
24
- if (newChache[cont.id]) {
25
- delete newChache[cont.id];
26
- cacheChanged = true;
27
- }
28
- });
29
- });
30
- set(state => ({
31
- graphic: Object.assign(Object.assign({}, state.graphic), { containers: Object.assign(Object.assign({}, state.graphic.containers), addedContainers) }),
32
- geometry: cacheChanged ? Object.assign(Object.assign({}, state.geometry), { cache: newChache, stamp: Date.now() }) : state.geometry,
33
- }));
34
- const { graphic, api } = get();
35
- /**
36
- * Update the bounds with the newly added graphic.
37
- */
38
- api.geometry.updateBounds();
39
- /**
40
- * Create the geometry for the graphic packages.
41
- * Only the geometry which does not already exist will be created (@see createGeometryIfNotCached).
42
- */
43
- const containerIds = Object.getOwnPropertyNames(graphic.containers);
44
- for (const id of containerIds) {
45
- api.geometry.createGeometryIfNotCached(id);
46
- }
47
- // console.log('graphicContainers after add:', Object.getOwnPropertyNames(get().graphic.containers))
48
- },
49
- cleanupGraphicRecords: () => {
50
- const { graphic, geometry, api } = get();
51
- // collect the used solid ids from the structure tree
52
- const solidIds = api.structure.collectUsedSolidIds();
53
- // console.log('solidIds before cleanup:', solidIds)
54
- // cleanup the graphic containers in the state
55
- const usedContainers = {};
56
- const existingContainers = graphic.containers;
57
- const existingContainerIds = Object.getOwnPropertyNames(existingContainers);
58
- if (existingContainerIds.length > 0) {
59
- existingContainerIds.forEach(contIdStr => {
60
- const contId = Number(contIdStr);
61
- if (solidIds.indexOf(contId) >= 0) {
62
- usedContainers[contId] = existingContainers[contId];
63
- }
64
- });
65
- set({ graphic: Object.assign(Object.assign({}, graphic), { containers: usedContainers }) });
66
- // console.log('graphicContainers after cleanup:', Object.getOwnPropertyNames(get().graphic.ontainers))
67
- }
68
- // cleanup the cached geometry depending on the uses solids
69
- const usedGeometry = {};
70
- const existingGeometry = geometry.cache;
71
- const existingGeometryIds = Object.getOwnPropertyNames(existingGeometry);
72
- if (existingGeometryIds.length > 0) {
73
- existingGeometryIds.forEach(contIdStr => {
74
- const contId = Number(contIdStr);
75
- if (solidIds.indexOf(contId) >= 0) {
76
- usedGeometry[contId] = existingGeometry[contId];
77
- }
78
- });
79
- set({ geometry: Object.assign(Object.assign({}, geometry), { cache: usedGeometry, stamp: Date.now() }) });
80
- }
81
- },
82
- filter: (cb, options) => {
83
- const result = [];
84
- const { containers } = get().graphic;
85
- const contIds = Object.getOwnPropertyNames(containers).map(n => Number(n));
86
- for (const contId of contIds) {
87
- if ((options === null || options === void 0 ? void 0 : options.containerId) && contId !== options.containerId) {
88
- continue;
89
- }
90
- const cont = containers[contId];
91
- const items = [
92
- ...((cont === null || cont === void 0 ? void 0 : cont.arcs) || []),
93
- ...((cont === null || cont === void 0 ? void 0 : cont.cones) || []),
94
- ...((cont === null || cont === void 0 ? void 0 : cont.edges) || []),
95
- ...((cont === null || cont === void 0 ? void 0 : cont.lines) || []),
96
- ...((cont === null || cont === void 0 ? void 0 : cont.meshes) || []),
97
- ...((cont === null || cont === void 0 ? void 0 : cont.vertices) || []),
98
- ];
99
- for (const elem of items) {
100
- if (cb(elem)) {
101
- result.push({ elem, solidId: cont.owner, containerId: cont.id });
102
- if (options === null || options === void 0 ? void 0 : options.onlyOne) {
103
- return result;
104
- }
105
- }
106
- }
107
- }
108
- return result;
109
- },
110
- });
1
+ ////////////////////////////////////////////////////
2
+ // DATA
3
+ ////////////////////////////////////////////////////
4
+ export const graphicData = () => ({
5
+ containers: {},
6
+ });
7
+ ////////////////////////////////////////////////////
8
+ // API
9
+ ////////////////////////////////////////////////////
10
+ export const graphicApi = (set, get, buerliApi) => ({
11
+ addPackages: (packages) => {
12
+ // Timing.dump('load', `add graphic packages ${graphic.length} ${graphic[0].containers.length}`)
13
+ if (!Array.isArray(packages)) {
14
+ packages = [packages];
15
+ }
16
+ let cacheChanged = false;
17
+ const newChache = Object.assign({}, get().geometry.cache);
18
+ const addedContainers = {};
19
+ packages.forEach(gr => {
20
+ gr.containers.forEach(cont => {
21
+ addedContainers[cont.id] = cont;
22
+ // If the cached geometry for the added container already exist,
23
+ // it has to be removed from the cache to ensure geometry updates.
24
+ if (newChache[cont.id]) {
25
+ delete newChache[cont.id];
26
+ cacheChanged = true;
27
+ }
28
+ });
29
+ });
30
+ set(state => ({
31
+ graphic: Object.assign(Object.assign({}, state.graphic), { containers: Object.assign(Object.assign({}, state.graphic.containers), addedContainers) }),
32
+ geometry: cacheChanged ? Object.assign(Object.assign({}, state.geometry), { cache: newChache, stamp: Date.now() }) : state.geometry,
33
+ }));
34
+ const { graphic, api } = get();
35
+ /**
36
+ * Update the bounds with the newly added graphic.
37
+ */
38
+ api.geometry.updateBounds();
39
+ /**
40
+ * Create the geometry for the graphic packages.
41
+ * Only the geometry which does not already exist will be created (@see createGeometryIfNotCached).
42
+ */
43
+ const containerIds = Object.getOwnPropertyNames(graphic.containers);
44
+ for (const id of containerIds) {
45
+ api.geometry.createGeometryIfNotCached(id);
46
+ }
47
+ // console.log('graphicContainers after add:', Object.getOwnPropertyNames(get().graphic.containers))
48
+ },
49
+ cleanupGraphicRecords: () => {
50
+ const { graphic, geometry, api } = get();
51
+ // collect the used solid ids from the structure tree
52
+ const solidIds = api.structure.collectUsedSolidIds();
53
+ // console.log('solidIds before cleanup:', solidIds)
54
+ // cleanup the graphic containers in the state
55
+ const usedContainers = {};
56
+ const existingContainers = graphic.containers;
57
+ const existingContainerIds = Object.getOwnPropertyNames(existingContainers);
58
+ if (existingContainerIds.length > 0) {
59
+ existingContainerIds.forEach(contIdStr => {
60
+ const contId = Number(contIdStr);
61
+ if (solidIds.indexOf(contId) >= 0) {
62
+ usedContainers[contId] = existingContainers[contId];
63
+ }
64
+ });
65
+ set({ graphic: Object.assign(Object.assign({}, graphic), { containers: usedContainers }) });
66
+ // console.log('graphicContainers after cleanup:', Object.getOwnPropertyNames(get().graphic.ontainers))
67
+ }
68
+ // cleanup the cached geometry depending on the uses solids
69
+ const usedGeometry = {};
70
+ const existingGeometry = geometry.cache;
71
+ const existingGeometryIds = Object.getOwnPropertyNames(existingGeometry);
72
+ if (existingGeometryIds.length > 0) {
73
+ existingGeometryIds.forEach(contIdStr => {
74
+ const contId = Number(contIdStr);
75
+ if (solidIds.indexOf(contId) >= 0) {
76
+ usedGeometry[contId] = existingGeometry[contId];
77
+ }
78
+ });
79
+ set({ geometry: Object.assign(Object.assign({}, geometry), { cache: usedGeometry, stamp: Date.now() }) });
80
+ }
81
+ },
82
+ filter: (cb, options) => {
83
+ const result = [];
84
+ const { containers } = get().graphic;
85
+ const contIds = Object.getOwnPropertyNames(containers).map(n => Number(n));
86
+ for (const contId of contIds) {
87
+ if ((options === null || options === void 0 ? void 0 : options.containerId) && contId !== options.containerId) {
88
+ continue;
89
+ }
90
+ const cont = containers[contId];
91
+ const items = [
92
+ ...((cont === null || cont === void 0 ? void 0 : cont.arcs) || []),
93
+ ...((cont === null || cont === void 0 ? void 0 : cont.cones) || []),
94
+ ...((cont === null || cont === void 0 ? void 0 : cont.edges) || []),
95
+ ...((cont === null || cont === void 0 ? void 0 : cont.lines) || []),
96
+ ...((cont === null || cont === void 0 ? void 0 : cont.meshes) || []),
97
+ ...((cont === null || cont === void 0 ? void 0 : cont.vertices) || []),
98
+ ];
99
+ for (const elem of items) {
100
+ if (cb(elem)) {
101
+ result.push({ elem, solidId: cont.owner, containerId: cont.id });
102
+ if (options === null || options === void 0 ? void 0 : options.onlyOne) {
103
+ return result;
104
+ }
105
+ }
106
+ }
107
+ }
108
+ return result;
109
+ },
110
+ });
@@ -1,50 +1,50 @@
1
- ////////////////////////////////////////////////////
2
- // DATA
3
- ////////////////////////////////////////////////////
4
- export const interactionData = () => ({
5
- hovered: null,
6
- selected: [],
7
- });
8
- ////////////////////////////////////////////////////
9
- // API
10
- ////////////////////////////////////////////////////
11
- export const interactionApi = (set, get, buerliApi) => ({
12
- /**
13
- * Sets the hovered item in the store to the given item.
14
- *
15
- * @param item The item.
16
- */
17
- setHovered: (item) => {
18
- set(state => (Object.assign(Object.assign({}, state), { interaction: Object.assign(Object.assign({}, state.interaction), { hovered: item }) })));
19
- },
20
- /**
21
- * Reset the 'selected' array to the given items.
22
- *
23
- * @param items The items.
24
- */
25
- setSelected: (items) => {
26
- set(state => (Object.assign(Object.assign({}, state), { interaction: Object.assign(Object.assign({}, state.interaction), { selected: items }) })));
27
- },
28
- /**
29
- * Adds the given item to the 'selected' array if it is not yet selected.
30
- * If the item is already selected, it will be removed from the 'selected' array.
31
- *
32
- * With 'multi' enabled, the already selected items will remain selected.
33
- *
34
- * @param item The item to select.
35
- * @param multi Do multi select.
36
- */
37
- select: (item, multi) => {
38
- const setSelected = get().api.interaction.setSelected;
39
- const selected = get().interaction.selected || [];
40
- const newKey = item.uniqueIdent;
41
- let newSel = selected.length === 1 && selected[0].uniqueIdent === newKey ? [] : [item];
42
- if (multi) {
43
- newSel = selected.filter(s => s.uniqueIdent != newKey);
44
- if (newSel.length === selected.length) {
45
- newSel.push(item);
46
- }
47
- }
48
- setSelected(newSel);
49
- },
50
- });
1
+ ////////////////////////////////////////////////////
2
+ // DATA
3
+ ////////////////////////////////////////////////////
4
+ export const interactionData = () => ({
5
+ hovered: null,
6
+ selected: [],
7
+ });
8
+ ////////////////////////////////////////////////////
9
+ // API
10
+ ////////////////////////////////////////////////////
11
+ export const interactionApi = (set, get, buerliApi) => ({
12
+ /**
13
+ * Sets the hovered item in the store to the given item.
14
+ *
15
+ * @param item The item.
16
+ */
17
+ setHovered: (item) => {
18
+ set(state => (Object.assign(Object.assign({}, state), { interaction: Object.assign(Object.assign({}, state.interaction), { hovered: item }) })));
19
+ },
20
+ /**
21
+ * Reset the 'selected' array to the given items.
22
+ *
23
+ * @param items The items.
24
+ */
25
+ setSelected: (items) => {
26
+ set(state => (Object.assign(Object.assign({}, state), { interaction: Object.assign(Object.assign({}, state.interaction), { selected: items }) })));
27
+ },
28
+ /**
29
+ * Adds the given item to the 'selected' array if it is not yet selected.
30
+ * If the item is already selected, it will be removed from the 'selected' array.
31
+ *
32
+ * With 'multi' enabled, the already selected items will remain selected.
33
+ *
34
+ * @param item The item to select.
35
+ * @param multi Do multi select.
36
+ */
37
+ select: (item, multi) => {
38
+ const setSelected = get().api.interaction.setSelected;
39
+ const selected = get().interaction.selected || [];
40
+ const newKey = item.uniqueIdent;
41
+ let newSel = selected.length === 1 && selected[0].uniqueIdent === newKey ? [] : [item];
42
+ if (multi) {
43
+ newSel = selected.filter(s => s.uniqueIdent != newKey);
44
+ if (newSel.length === selected.length) {
45
+ newSel.push(item);
46
+ }
47
+ }
48
+ setSelected(newSel);
49
+ },
50
+ });
@@ -1,21 +1,28 @@
1
- import { v4 as uuidv4 } from 'uuid';
2
- export const BuerliMessageScope = 'BuerliMessageScope';
3
- export const getInitialMessageState = (set, get, api) => ({
4
- message: {
5
- data: null,
6
- timestamp: -1,
7
- api: messageApi(set, get, api),
8
- },
9
- });
10
- const messageApi = (set, get, api) => ({
11
- show(message) {
12
- const newId = uuidv4();
13
- const msg = get().message;
14
- set({ message: Object.assign(Object.assign({}, msg), { data: Object.assign({ id: newId }, message), timestamp: Date.now() }) });
15
- return newId;
16
- },
17
- update(id, message) {
18
- const msg = get().message;
19
- set({ message: Object.assign(Object.assign({}, msg), { data: Object.assign({ id }, message), timestamp: Date.now() }) });
20
- },
21
- });
1
+ import { v4 as uuidv4 } from 'uuid';
2
+ export const BuerliMessageScope = 'BuerliMessageScope';
3
+ export const getInitialMessageState = (set, get, api) => ({
4
+ message: {
5
+ data: null,
6
+ timestamp: -1,
7
+ api: messageApi(set, get, api),
8
+ },
9
+ });
10
+ const messageApi = (set, get, api) => ({
11
+ show(message) {
12
+ const newId = uuidv4();
13
+ const msg = get().message;
14
+ set({ message: Object.assign(Object.assign({}, msg), { data: Object.assign({ id: newId }, message), timestamp: Date.now() }) });
15
+ return newId;
16
+ },
17
+ update(id, message) {
18
+ const msg = get().message;
19
+ set({ message: Object.assign(Object.assign({}, msg), { data: Object.assign({ id }, message), timestamp: Date.now() }) });
20
+ },
21
+ close(id) {
22
+ var _a;
23
+ const msg = get().message;
24
+ if (((_a = msg.data) === null || _a === void 0 ? void 0 : _a.id) === id) {
25
+ set({ message: Object.assign(Object.assign({}, msg), { data: null, timestamp: Date.now() }) });
26
+ }
27
+ },
28
+ });