@buerli.io/core 0.10.0 → 0.12.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.
Files changed (81) hide show
  1. package/CHANGELOG.md +5 -0
  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 -35
  10. package/build/cjs/store/states/drawing.js +49 -49
  11. package/build/cjs/store/states/geometry.js +137 -137
  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 -30
  36. package/build/esm/store/states/drawing.js +45 -45
  37. package/build/esm/store/states/geometry.js +109 -109
  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 -42
  62. package/build/types/store/states/drawing.d.ts +45 -45
  63. package/build/types/store/states/geometry.d.ts +63 -63
  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 +157 -155
  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,137 +1,137 @@
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
- setColor: (containerId, 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
- const cachedGeom = Object.assign(Object.assign({}, get().geometry.cache[containerId]), { color });
80
- set(state => ({
81
- geometry: Object.assign(Object.assign({}, state.geometry), { cache: Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, cachedGeom), { dirtyStamp: Date.now() }) }) }),
82
- }));
83
- },
84
- setOpacity: (containerId, opacity) => {
85
- const cachedGeom = Object.assign(Object.assign({}, get().geometry.cache[containerId]), { opacity });
86
- set(state => ({
87
- geometry: Object.assign(Object.assign({}, state.geometry), { cache: Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, cachedGeom), { dirtyStamp: Date.now() }) }) }),
88
- }));
89
- },
90
- setConfig: (objId, config) => {
91
- set(state => {
92
- const productConfigs = Object.assign({}, state.geometry.config.product);
93
- if (config) {
94
- const newConfig = Object.assign({}, state.geometry.config.product[objId]);
95
- if ('disabled' in config)
96
- newConfig.disabled = config.disabled;
97
- if ('edges' in config)
98
- newConfig.edges = Object.assign(Object.assign({}, newConfig.edges), config.edges);
99
- if ('meshes' in config)
100
- newConfig.meshes = Object.assign(Object.assign({}, newConfig.meshes), config.meshes);
101
- if ('points' in config)
102
- newConfig.points = Object.assign(Object.assign({}, newConfig.points), config.points);
103
- productConfigs[objId] = newConfig;
104
- }
105
- else {
106
- delete productConfigs[objId];
107
- }
108
- return { geometry: Object.assign(Object.assign({}, state.geometry), { config: Object.assign(Object.assign({}, state.geometry.config), { product: productConfigs }) }) };
109
- });
110
- },
111
- findDecorated: () => {
112
- const { geometry: api } = get().api;
113
- 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); });
114
- },
115
- filter: (cb, options) => {
116
- const result = [];
117
- const { cache } = get().geometry;
118
- const contIds = Object.getOwnPropertyNames(cache).map(n => Number(n));
119
- for (const contId of contIds) {
120
- if ((options === null || options === void 0 ? void 0 : options.containerId) && contId !== options.containerId) {
121
- continue;
122
- }
123
- const ids = Object.getOwnPropertyNames(cache[contId].map).map(id => Number(id));
124
- for (const id of ids) {
125
- const elem = cache[contId].map[id];
126
- if (cb(elem)) {
127
- result.push(elem);
128
- if (options === null || options === void 0 ? void 0 : options.onlyOne) {
129
- return result;
130
- }
131
- }
132
- }
133
- }
134
- return result;
135
- },
136
- });
137
- 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
+ setColor: (containerId, 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
+ const cachedGeom = Object.assign(Object.assign({}, get().geometry.cache[containerId]), { color });
80
+ set(state => ({
81
+ geometry: Object.assign(Object.assign({}, state.geometry), { cache: Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, cachedGeom), { dirtyStamp: Date.now() }) }) }),
82
+ }));
83
+ },
84
+ setOpacity: (containerId, opacity) => {
85
+ const cachedGeom = Object.assign(Object.assign({}, get().geometry.cache[containerId]), { opacity });
86
+ set(state => ({
87
+ geometry: Object.assign(Object.assign({}, state.geometry), { cache: Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, cachedGeom), { dirtyStamp: Date.now() }) }) }),
88
+ }));
89
+ },
90
+ setConfig: (objId, config) => {
91
+ set(state => {
92
+ const productConfigs = Object.assign({}, state.geometry.config.product);
93
+ if (config) {
94
+ const newConfig = Object.assign({}, state.geometry.config.product[objId]);
95
+ if ('disabled' in config)
96
+ newConfig.disabled = config.disabled;
97
+ if ('edges' in config)
98
+ newConfig.edges = Object.assign(Object.assign({}, newConfig.edges), config.edges);
99
+ if ('meshes' in config)
100
+ newConfig.meshes = Object.assign(Object.assign({}, newConfig.meshes), config.meshes);
101
+ if ('points' in config)
102
+ newConfig.points = Object.assign(Object.assign({}, newConfig.points), config.points);
103
+ productConfigs[objId] = newConfig;
104
+ }
105
+ else {
106
+ delete productConfigs[objId];
107
+ }
108
+ return { geometry: Object.assign(Object.assign({}, state.geometry), { config: Object.assign(Object.assign({}, state.geometry.config), { product: productConfigs }) }) };
109
+ });
110
+ },
111
+ findDecorated: () => {
112
+ const { geometry: api } = get().api;
113
+ 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); });
114
+ },
115
+ filter: (cb, options) => {
116
+ const result = [];
117
+ const { cache } = get().geometry;
118
+ const contIds = Object.getOwnPropertyNames(cache).map(n => Number(n));
119
+ for (const contId of contIds) {
120
+ if ((options === null || options === void 0 ? void 0 : options.containerId) && contId !== options.containerId) {
121
+ continue;
122
+ }
123
+ const ids = Object.getOwnPropertyNames(cache[contId].map).map(id => Number(id));
124
+ for (const id of ids) {
125
+ const elem = cache[contId].map[id];
126
+ if (cb(elem)) {
127
+ result.push(elem);
128
+ if (options === null || options === void 0 ? void 0 : options.onlyOne) {
129
+ return result;
130
+ }
131
+ }
132
+ }
133
+ }
134
+ return result;
135
+ },
136
+ });
137
+ 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;
@@ -1,55 +1,55 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.interactionApi = exports.interactionData = void 0;
4
- ////////////////////////////////////////////////////
5
- // DATA
6
- ////////////////////////////////////////////////////
7
- const interactionData = () => ({
8
- hovered: null,
9
- selected: [],
10
- });
11
- exports.interactionData = interactionData;
12
- ////////////////////////////////////////////////////
13
- // API
14
- ////////////////////////////////////////////////////
15
- const interactionApi = (set, get, buerliApi) => ({
16
- /**
17
- * Sets the hovered item in the store to the given item.
18
- *
19
- * @param item The item.
20
- */
21
- setHovered: (item) => {
22
- set(state => (Object.assign(Object.assign({}, state), { interaction: Object.assign(Object.assign({}, state.interaction), { hovered: item }) })));
23
- },
24
- /**
25
- * Reset the 'selected' array to the given items.
26
- *
27
- * @param items The items.
28
- */
29
- setSelected: (items) => {
30
- set(state => (Object.assign(Object.assign({}, state), { interaction: Object.assign(Object.assign({}, state.interaction), { selected: items }) })));
31
- },
32
- /**
33
- * Adds the given item to the 'selected' array if it is not yet selected.
34
- * If the item is already selected, it will be removed from the 'selected' array.
35
- *
36
- * With 'multi' enabled, the already selected items will remain selected.
37
- *
38
- * @param item The item to select.
39
- * @param multi Do multi select.
40
- */
41
- select: (item, multi) => {
42
- const setSelected = get().api.interaction.setSelected;
43
- const selected = get().interaction.selected || [];
44
- const newKey = item.uniqueIdent;
45
- let newSel = selected.length === 1 && selected[0].uniqueIdent === newKey ? [] : [item];
46
- if (multi) {
47
- newSel = selected.filter(s => s.uniqueIdent != newKey);
48
- if (newSel.length === selected.length) {
49
- newSel.push(item);
50
- }
51
- }
52
- setSelected(newSel);
53
- },
54
- });
55
- exports.interactionApi = interactionApi;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.interactionApi = exports.interactionData = void 0;
4
+ ////////////////////////////////////////////////////
5
+ // DATA
6
+ ////////////////////////////////////////////////////
7
+ const interactionData = () => ({
8
+ hovered: null,
9
+ selected: [],
10
+ });
11
+ exports.interactionData = interactionData;
12
+ ////////////////////////////////////////////////////
13
+ // API
14
+ ////////////////////////////////////////////////////
15
+ const interactionApi = (set, get, buerliApi) => ({
16
+ /**
17
+ * Sets the hovered item in the store to the given item.
18
+ *
19
+ * @param item The item.
20
+ */
21
+ setHovered: (item) => {
22
+ set(state => (Object.assign(Object.assign({}, state), { interaction: Object.assign(Object.assign({}, state.interaction), { hovered: item }) })));
23
+ },
24
+ /**
25
+ * Reset the 'selected' array to the given items.
26
+ *
27
+ * @param items The items.
28
+ */
29
+ setSelected: (items) => {
30
+ set(state => (Object.assign(Object.assign({}, state), { interaction: Object.assign(Object.assign({}, state.interaction), { selected: items }) })));
31
+ },
32
+ /**
33
+ * Adds the given item to the 'selected' array if it is not yet selected.
34
+ * If the item is already selected, it will be removed from the 'selected' array.
35
+ *
36
+ * With 'multi' enabled, the already selected items will remain selected.
37
+ *
38
+ * @param item The item to select.
39
+ * @param multi Do multi select.
40
+ */
41
+ select: (item, multi) => {
42
+ const setSelected = get().api.interaction.setSelected;
43
+ const selected = get().interaction.selected || [];
44
+ const newKey = item.uniqueIdent;
45
+ let newSel = selected.length === 1 && selected[0].uniqueIdent === newKey ? [] : [item];
46
+ if (multi) {
47
+ newSel = selected.filter(s => s.uniqueIdent != newKey);
48
+ if (newSel.length === selected.length) {
49
+ newSel.push(item);
50
+ }
51
+ }
52
+ setSelected(newSel);
53
+ },
54
+ });
55
+ exports.interactionApi = interactionApi;