@buerli.io/core 0.0.34 → 0.0.35-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/build/cjs/geometry/ThreeGeometryCreator.js +284 -0
  2. package/build/cjs/geometry/index.js +13 -0
  3. package/build/cjs/index.js +20 -0
  4. package/build/cjs/store/index.js +46 -0
  5. package/build/{store → cjs/store}/states/buerli.js +9 -5
  6. package/build/{store → cjs/store}/states/canvas.js +7 -2
  7. package/build/cjs/store/states/drawing.js +44 -0
  8. package/build/{store → cjs/store}/states/geometry.js +29 -5
  9. package/build/{store → cjs/store}/states/graphic.js +7 -2
  10. package/build/cjs/store/states/message.js +25 -0
  11. package/build/{store → cjs/store}/states/plugin.js +12 -13
  12. package/build/{store → cjs/store}/states/selection.js +47 -18
  13. package/build/cjs/store/states/structure.js +203 -0
  14. package/build/cjs/store/store.js +14 -0
  15. package/build/cjs/store/subscribtion/selection.js +47 -0
  16. package/build/cjs/store/subscribtion/subscribeToDrawing.js +9 -0
  17. package/build/cjs/types/ErrorTypes.js +2 -0
  18. package/build/cjs/types/IGraphicPackage.js +24 -0
  19. package/build/cjs/types/IStructurePatch.js +2 -0
  20. package/build/cjs/types/IStructureTree.js +27 -0
  21. package/build/cjs/types/index.js +16 -0
  22. package/build/cjs/utils/Math.js +33 -0
  23. package/build/cjs/utils/Measure.js +576 -0
  24. package/build/cjs/utils/Timing.js +34 -0
  25. package/build/{geometry → esm/geometry}/ThreeGeometryCreator.js +47 -17
  26. package/build/{geometry → esm/geometry}/index.js +0 -0
  27. package/build/{index.js → esm/index.js} +1 -0
  28. package/build/{store → esm/store}/index.js +4 -1
  29. package/build/esm/store/states/buerli.js +116 -0
  30. package/build/esm/store/states/canvas.js +13 -0
  31. package/build/{store → esm/store}/states/drawing.js +0 -0
  32. package/build/esm/store/states/geometry.js +98 -0
  33. package/build/esm/store/states/graphic.js +82 -0
  34. package/build/{store → esm/store}/states/message.js +2 -2
  35. package/build/esm/store/states/plugin.js +152 -0
  36. package/build/esm/store/states/selection.js +269 -0
  37. package/build/{store → esm/store}/states/structure.js +10 -4
  38. package/build/{store → esm/store}/store.js +0 -0
  39. package/build/esm/store/subscribtion/selection.js +41 -0
  40. package/build/esm/store/subscribtion/subscribeToDrawing.js +5 -0
  41. package/build/{types → esm/types}/ErrorTypes.js +0 -0
  42. package/build/{types → esm/types}/IGraphicPackage.js +0 -0
  43. package/build/{types → esm/types}/IStructurePatch.js +0 -0
  44. package/build/{types → esm/types}/IStructureTree.js +0 -0
  45. package/build/{types → esm/types}/index.js +0 -0
  46. package/build/{utils → esm/utils}/Math.js +0 -0
  47. package/build/{utils → esm/utils}/Measure.js +1 -1
  48. package/build/{utils → esm/utils}/Timing.js +5 -1
  49. package/build/{geometry → types/geometry}/ThreeGeometryCreator.d.ts +0 -0
  50. package/build/{geometry → types/geometry}/index.d.ts +0 -0
  51. package/build/types/index.d.ts +36 -4
  52. package/build/{store → types/store}/index.d.ts +3 -0
  53. package/build/{store → types/store}/states/buerli.d.ts +0 -0
  54. package/build/{store → types/store}/states/canvas.d.ts +0 -0
  55. package/build/{store → types/store}/states/drawing.d.ts +0 -0
  56. package/build/{store → types/store}/states/geometry.d.ts +0 -0
  57. package/build/{store → types/store}/states/graphic.d.ts +0 -0
  58. package/build/{store → types/store}/states/message.d.ts +0 -0
  59. package/build/{store → types/store}/states/plugin.d.ts +1 -1
  60. package/build/{store → types/store}/states/selection.d.ts +1 -0
  61. package/build/{store → types/store}/states/structure.d.ts +0 -0
  62. package/build/{store → types/store}/store.d.ts +0 -0
  63. package/build/types/store/subscribtion/selection.d.ts +5 -0
  64. package/build/types/store/subscribtion/subscribeToDrawing.d.ts +2 -0
  65. package/build/types/{ErrorTypes.d.ts → types/ErrorTypes.d.ts} +0 -0
  66. package/build/types/{IGraphicPackage.d.ts → types/IGraphicPackage.d.ts} +0 -0
  67. package/build/types/{IStructurePatch.d.ts → types/IStructurePatch.d.ts} +0 -0
  68. package/build/types/{IStructureTree.d.ts → types/IStructureTree.d.ts} +0 -1
  69. package/build/types/types/index.d.ts +4 -0
  70. package/build/{utils → types/utils}/Math.d.ts +0 -0
  71. package/build/{utils → types/utils}/Measure.d.ts +0 -0
  72. package/build/{utils → types/utils}/Timing.d.ts +0 -0
  73. package/package.json +9 -6
  74. package/build/index.d.ts +0 -35
@@ -0,0 +1,284 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.isEqualGeometry = exports.EMPTY_CONTAINER_GEOMETRY = exports.ThreeGeometryCreator = void 0;
23
+ const THREE = __importStar(require("three"));
24
+ const types_1 = require("./../types");
25
+ /**
26
+ * Creates THREE geometry based on the data within a @see IGraphicContainer.
27
+ */
28
+ class ThreeGeometryCreator {
29
+ constructor() {
30
+ this.coordHeightTolerance = 0.01;
31
+ }
32
+ getMetadata(geometry, container, color = [0, 0, 0], opacity = 0) {
33
+ const contProps = container.properties; // container has always properties
34
+ const geomProps = geometry ? geometry.properties : {};
35
+ let col = container.properties.material.color || color;
36
+ let opa = container.properties.material.opacity || opacity;
37
+ if (geomProps && geomProps.material) {
38
+ col = geomProps.material.color || col;
39
+ opa = geomProps.material.opacity || opa;
40
+ }
41
+ const rgbColor = new THREE.Color(col[0] / 255, col[1] / 255, col[2] / 255);
42
+ const layer = geomProps && geomProps.layer ? geomProps.layer : contProps.layer;
43
+ return { color: rgbColor, opacity: opa, layer, container: { id: container.id, ownerId: container.owner } };
44
+ }
45
+ createGeometry(container, color = [0, 0, 0]) {
46
+ const graphicId = container.id;
47
+ const { properties } = container;
48
+ const box = { min: new THREE.Vector3(...properties.min), max: new THREE.Vector3(...properties.max) };
49
+ const meshes = [];
50
+ const lines = [];
51
+ const edges = [];
52
+ const arcs = [];
53
+ const pointMap = {};
54
+ const map = {};
55
+ if (container.meshes) {
56
+ container.meshes.forEach(mesh => {
57
+ const elem = this.createSurface(mesh, container, color);
58
+ if (elem.isValid) {
59
+ meshes.push(elem);
60
+ map[mesh.id] = elem;
61
+ }
62
+ else {
63
+ // TODO: The server should not send invalid meshes.
64
+ console.warn(`Invalid mesh detected`);
65
+ }
66
+ });
67
+ }
68
+ if (container.lines) {
69
+ container.lines.forEach(line => {
70
+ const elem = this.createLine(line, container, pointMap, color);
71
+ lines.push(elem);
72
+ map[line.id] = elem;
73
+ });
74
+ }
75
+ if (container.edges) {
76
+ container.edges.forEach(edge => {
77
+ const elem = this.createEdge(edge, container, pointMap, color);
78
+ edges.push(elem);
79
+ map[edge.id] = elem;
80
+ });
81
+ }
82
+ if (container.arcs) {
83
+ container.arcs.forEach(arc => {
84
+ const elem = this.createArc(arc, container, pointMap, color);
85
+ arcs.push(elem);
86
+ map[arc.id] = elem;
87
+ });
88
+ }
89
+ const points = Object.values(pointMap);
90
+ return Object.assign({ graphicId,
91
+ map,
92
+ meshes,
93
+ lines,
94
+ edges,
95
+ arcs,
96
+ points,
97
+ box }, this.getMetadata(null, container, color));
98
+ }
99
+ createSurface(mesh, container, color = [0, 0, 0]) {
100
+ let meshGeom = this.createMesh(mesh, container, color);
101
+ switch (meshGeom.type) {
102
+ case types_1.GraphicType.PLANE:
103
+ meshGeom = this.createPlane(mesh, meshGeom);
104
+ break;
105
+ case types_1.GraphicType.CYLINDER:
106
+ meshGeom = this.createCylinder(mesh, meshGeom);
107
+ break;
108
+ case types_1.GraphicType.CONE:
109
+ meshGeom = this.createCone(mesh, meshGeom);
110
+ break;
111
+ case types_1.GraphicType.SPHERE:
112
+ meshGeom = this.createSphere(mesh, meshGeom);
113
+ break;
114
+ }
115
+ return meshGeom;
116
+ }
117
+ createMesh(mesh, container, color = [0, 0, 0]) {
118
+ const graphicId = mesh.id;
119
+ const loops = mesh.loops;
120
+ const type = mesh.properties.surface.type;
121
+ const geometry = new THREE.BufferGeometry();
122
+ geometry.setIndex(mesh.indices);
123
+ geometry.setAttribute('position', new THREE.Float32BufferAttribute(mesh.vertices, 3));
124
+ mesh.normals && geometry.setAttribute('normal', new THREE.Float32BufferAttribute(mesh.normals, 3));
125
+ return Object.assign({
126
+ // TODO: The server should not send invalid meshes.
127
+ isValid: mesh.vertices && mesh.vertices.length > 0, geometry,
128
+ graphicId,
129
+ type,
130
+ loops }, this.getMetadata(mesh, container, color));
131
+ }
132
+ createPlane(mesh, meshGeom) {
133
+ const type = types_1.GraphicType.PLANE;
134
+ const { normal: n, pointOnPlane: p } = mesh.properties.surface;
135
+ const pointOnPlane = new THREE.Vector3(p[0], p[1], p[2]);
136
+ const normal = new THREE.Vector3(n[0], n[1], n[2]).normalize();
137
+ return Object.assign(Object.assign({}, meshGeom), { type, pointOnPlane, normal });
138
+ }
139
+ createCylinder(mesh, meshGeom) {
140
+ const type = types_1.GraphicType.CYLINDER;
141
+ const { origin: o, axis: a, height, radius } = mesh.properties.surface;
142
+ const origin = new THREE.Vector3(o[0], o[1], o[2]);
143
+ const axis = new THREE.Vector3(a[0], a[1], a[2]).normalize();
144
+ return Object.assign(Object.assign({}, meshGeom), { type, origin, axis, height, radius });
145
+ }
146
+ createCone(mesh, meshGeom) {
147
+ const type = types_1.GraphicType.CONE;
148
+ const { origin: o, axis: a, height, radiusBottom, radiusTop } = mesh.properties.surface;
149
+ const origin = new THREE.Vector3(o[0], o[1], o[2]);
150
+ const axis = new THREE.Vector3(a[0], a[1], a[2]).normalize();
151
+ return Object.assign(Object.assign({}, meshGeom), { type, origin, axis, height, radiusBottom, radiusTop });
152
+ }
153
+ createSphere(mesh, meshGeom) {
154
+ const type = types_1.GraphicType.SPHERE;
155
+ const { radius } = mesh.properties.surface;
156
+ return Object.assign(Object.assign({}, meshGeom), { type, radius });
157
+ }
158
+ createLine(line, container, points, color = [0, 0, 0]) {
159
+ const graphicId = line.id;
160
+ const type = types_1.GraphicType.LINE;
161
+ const pts = line.points;
162
+ const [startId, endId] = line.pointIds;
163
+ const start = new THREE.Vector3(pts[0], pts[1], pts[2]);
164
+ const end = new THREE.Vector3(pts[3], pts[4], pts[5]);
165
+ this.insertPoint(container, `${startId}|point`, startId, start.clone(), line.id, 'start', points);
166
+ this.insertPoint(container, `${endId}|point`, endId, end.clone(), line.id, 'end', points);
167
+ const geometry = new THREE.BufferGeometry().setFromPoints([start.clone(), end.clone()]);
168
+ return Object.assign(Object.assign({ geometry,
169
+ graphicId,
170
+ type }, this.getMetadata(line, container, color)), { start: start.clone(), end: end.clone() });
171
+ }
172
+ createEdge(edge, container, points, color = [0, 0, 0]) {
173
+ const threePts = [];
174
+ const graphicId = edge.id;
175
+ const type = types_1.GraphicType.EDGE;
176
+ const pts = edge.points;
177
+ for (let i = 0, length = pts.length / 3; i < length; i++) {
178
+ threePts.push(new THREE.Vector3(pts[i * 3], pts[i * 3 + 1], pts[i * 3 + 2]));
179
+ // Each segment has to be defined with start and end to use it for BufferGeometry
180
+ if (i > 0) {
181
+ threePts.push(new THREE.Vector3(pts[i * 3], pts[i * 3 + 1], pts[i * 3 + 2]));
182
+ }
183
+ }
184
+ // Seems like the three BufferGeometryUtils expect an edge to have an even number of points.
185
+ // Just add the end point twice if this is not the case.
186
+ if (threePts.length % 2 !== 0) {
187
+ threePts.push(threePts[threePts.length - 1].clone());
188
+ }
189
+ const start = threePts[0].clone();
190
+ const end = threePts[threePts.length - 1].clone();
191
+ const startId = edge.pointIds[0];
192
+ const endId = edge.pointIds[edge.pointIds.length - 1];
193
+ this.insertPoint(container, `${startId}|point`, startId, start, edge.id, 'start', points);
194
+ this.insertPoint(container, `${endId}|point`, endId, end, edge.id, 'end', points);
195
+ const geometry = new THREE.BufferGeometry().setFromPoints(threePts);
196
+ return Object.assign(Object.assign({ geometry,
197
+ graphicId,
198
+ type }, this.getMetadata(edge, container, color)), { start: start.clone(), end: end.clone() });
199
+ }
200
+ createArc(arc, container, points, color = [0, 0, 0]) {
201
+ const graphicId = arc.id;
202
+ const type = arc.isCircle ? types_1.GraphicType.CIRCLE : types_1.GraphicType.ARC;
203
+ // take half of coordHeightTolerance used for faces, as classcad does it in the tessellation process
204
+ const coordHeight = this.coordHeightTolerance / 2;
205
+ const radius = arc.radius;
206
+ const center = new THREE.Vector3(arc.center[0], arc.center[1], arc.center[2]);
207
+ const normal = new THREE.Vector3(arc.zAxis[0], arc.zAxis[1], arc.zAxis[2]).normalize();
208
+ const startVector = new THREE.Vector3(arc.xAxis[0], arc.xAxis[1], arc.xAxis[2]).normalize().multiplyScalar(radius);
209
+ const theta = arc.isCircle ? Math.PI * 2 : arc.angle;
210
+ // calculate angle for one segment to fulfill coordHeight tolerance
211
+ let alpha = 2 * Math.acos(1 - coordHeight / radius);
212
+ // calculate number of segments
213
+ let segments = Math.ceil(Math.abs(arc.angle) / alpha);
214
+ // choose at minimum three segments
215
+ segments = Math.max(3, segments);
216
+ // adjust angle to match with number of segments, still fulfilling coordHeigth tolerance
217
+ alpha = theta / segments;
218
+ const threePts = [];
219
+ const matrix = new THREE.Matrix4().makeRotationAxis(normal, alpha);
220
+ const startPoint = center.clone();
221
+ startPoint.add(startVector);
222
+ threePts.push(startPoint);
223
+ for (let i = 0; i < segments; i++) {
224
+ startVector.applyMatrix4(matrix);
225
+ const nextPoint = center.clone();
226
+ nextPoint.add(startVector);
227
+ threePts.push(nextPoint.clone());
228
+ // Each segment has to be defined with start and end to use it for BufferGeometry
229
+ threePts.push(nextPoint.clone());
230
+ }
231
+ // Seems like the three BufferGeometryUtils expect an edge to have an even number of points.
232
+ // Just add the end point twice if this is not the case.
233
+ if (threePts.length % 2 !== 0) {
234
+ threePts.push(threePts[threePts.length - 1].clone());
235
+ }
236
+ const [startId, endId] = arc.pointIds;
237
+ const start = threePts[0].clone();
238
+ const end = threePts[threePts.length - 1].clone();
239
+ this.insertPoint(container, `${startId}|point`, startId, start, arc.id, 'start', points);
240
+ this.insertPoint(container, `${endId}|point`, endId, end, arc.id, 'end', points);
241
+ const geometry = new THREE.BufferGeometry().setFromPoints(threePts);
242
+ return Object.assign(Object.assign({ geometry,
243
+ graphicId,
244
+ type }, this.getMetadata(arc, container, color)), { normal: normal.clone(), center: center.clone(), radius: arc.radius, angle: arc.angle });
245
+ }
246
+ createPoint(container, key, graphicId, position, ownerId, type) {
247
+ return Object.assign(Object.assign({ key,
248
+ graphicId, type: types_1.GraphicType.POINT }, this.getMetadata(null, container)), { position: position.clone(), geometry: position.clone(), owners: [{ ownerId, type }] });
249
+ }
250
+ insertPoint(container, key, graphicId, position, ownerId, type, points) {
251
+ const existingPoint = points[key];
252
+ if (existingPoint) {
253
+ const filteredOwners = existingPoint.owners.filter(gr => gr.ownerId === ownerId && gr.type === type);
254
+ if (filteredOwners.length <= 0) {
255
+ existingPoint.owners.push({ ownerId, type });
256
+ }
257
+ }
258
+ else {
259
+ points[key] = this.createPoint(container, key, graphicId, position, ownerId, type);
260
+ }
261
+ }
262
+ }
263
+ exports.ThreeGeometryCreator = ThreeGeometryCreator;
264
+ const EMPTY_CONTAINER_GEOMETRY = () => {
265
+ return {
266
+ graphicId: Number.NaN,
267
+ map: {},
268
+ meshes: [],
269
+ lines: [],
270
+ edges: [],
271
+ arcs: [],
272
+ points: [],
273
+ box: { min: new THREE.Vector3(), max: new THREE.Vector3() },
274
+ container: { id: NaN, ownerId: NaN },
275
+ color: new THREE.Color(),
276
+ opacity: 1.0,
277
+ layer: null,
278
+ };
279
+ };
280
+ exports.EMPTY_CONTAINER_GEOMETRY = EMPTY_CONTAINER_GEOMETRY;
281
+ const isEqualGeometry = (a, b) => {
282
+ return a.graphicId === b.graphicId && a.type === b.type;
283
+ };
284
+ exports.isEqualGeometry = isEqualGeometry;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./ThreeGeometryCreator"), exports);
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./store"), exports);
14
+ __exportStar(require("./geometry"), exports);
15
+ __exportStar(require("./types"), exports);
16
+ __exportStar(require("./utils/Math"), exports);
17
+ __exportStar(require("./utils/Measure"), exports);
18
+ __exportStar(require("./utils/Timing"), exports);
19
+ __exportStar(require("./store/subscribtion/subscribeToDrawing"), exports);
20
+ //#endregion Re-export type definitions
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.updateMessage = exports.showMessage = exports.init = exports.getPlugin = exports.getDrawing = exports.createGraphicItem = exports.BuerliScope = exports.BuerliMessageScope = void 0;
14
+ const store_1 = require("./store");
15
+ function getDrawing(id) {
16
+ const { drawing } = store_1.api.getState();
17
+ return drawing.refs[id];
18
+ }
19
+ exports.getDrawing = getDrawing;
20
+ /**
21
+ * @returns PluginState or undefined if either drawing or plugin don't exist
22
+ */
23
+ function getPlugin(drawingId, pluginId) {
24
+ var _a;
25
+ const { drawing } = store_1.api.getState();
26
+ return (_a = drawing.refs[drawingId]) === null || _a === void 0 ? void 0 : _a.plugin.refs[pluginId];
27
+ }
28
+ exports.getPlugin = getPlugin;
29
+ function init(sel) {
30
+ store_1.api.getState().api.init(typeof sel === 'function' ? sel(store_1.api.getState()) || {} : sel);
31
+ }
32
+ exports.init = init;
33
+ function showMessage(message) {
34
+ return store_1.api.getState().message.api.show(message);
35
+ }
36
+ exports.showMessage = showMessage;
37
+ function updateMessage(id, message) {
38
+ store_1.api.getState().message.api.update(id, message);
39
+ }
40
+ exports.updateMessage = updateMessage;
41
+ var message_1 = require("./states/message");
42
+ Object.defineProperty(exports, "BuerliMessageScope", { enumerable: true, get: function () { return message_1.BuerliMessageScope; } });
43
+ var selection_1 = require("./states/selection");
44
+ Object.defineProperty(exports, "BuerliScope", { enumerable: true, get: function () { return selection_1.BuerliScope; } });
45
+ Object.defineProperty(exports, "createGraphicItem", { enumerable: true, get: function () { return selection_1.createGraphicItem; } });
46
+ __exportStar(require("./store"), exports);
@@ -1,7 +1,10 @@
1
- import { createDrawingState } from './drawing';
2
- import { getInitialMessageState } from './message';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createState = void 0;
4
+ const drawing_1 = require("./drawing");
5
+ const message_1 = require("./message");
3
6
  const initError = 'Please call the init action before you use the buerli store.';
4
- export const createState = (set, get, api) => (Object.assign({ initDone: false, options: {
7
+ const createState = (set, get, api) => (Object.assign({ initDone: false, options: {
5
8
  url: '',
6
9
  elements: {},
7
10
  plugins: {},
@@ -20,7 +23,8 @@ export const createState = (set, get, api) => (Object.assign({ initDone: false,
20
23
  ids: [],
21
24
  refs: {},
22
25
  active: null,
23
- }, api: Object.assign(Object.assign({}, generalApi(set, get)), drawingManagementApi(set, get, api)) }, getInitialMessageState(set, get, api)));
26
+ }, api: Object.assign(Object.assign({}, generalApi(set, get)), drawingManagementApi(set, get, api)) }, message_1.getInitialMessageState(set, get, api)));
27
+ exports.createState = createState;
24
28
  const generalApi = (set, get) => ({
25
29
  // TODO: rename init to setOptions and remove initDone if everything is ok
26
30
  /**
@@ -38,7 +42,7 @@ const drawingManagementApi = (set, get, api) => ({
38
42
  const { initDone, drawing } = get();
39
43
  if (!initDone)
40
44
  throw new Error(initError);
41
- const drawingState = createDrawingState(sel => set(state => {
45
+ const drawingState = drawing_1.createDrawingState(sel => set(state => {
42
46
  const newState = typeof sel === 'function' ? sel(state.drawing.refs[drawingState.id]) : sel;
43
47
  return {
44
48
  drawing: Object.assign(Object.assign({}, state.drawing), { refs: Object.assign(Object.assign({}, state.drawing.refs), { [drawingState.id]: Object.assign(Object.assign({}, state.drawing.refs[drawingState.id]), newState) }) }),
@@ -1,13 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.canvasApi = exports.canvasData = void 0;
1
4
  ////////////////////////////////////////////////////
2
5
  // DATA
3
6
  ////////////////////////////////////////////////////
4
- export const canvasData = () => ({
7
+ const canvasData = () => ({
5
8
  controls: { isInteracting: false, enabled: true },
6
9
  });
10
+ exports.canvasData = canvasData;
7
11
  ////////////////////////////////////////////////////
8
12
  // API
9
13
  ////////////////////////////////////////////////////
10
- export const canvasApi = (set, get) => ({
14
+ const canvasApi = (set, get) => ({
11
15
  setInteraction: (isInteracting) => set(state => ({ canvas: Object.assign(Object.assign({}, state.canvas), { controls: Object.assign(Object.assign({}, state.canvas.controls), { isInteracting }) }) })),
12
16
  setControlsEnabled: (enabled) => set(state => ({ canvas: Object.assign(Object.assign({}, state.canvas), { controls: Object.assign(Object.assign({}, state.canvas.controls), { enabled }) }) })),
13
17
  });
18
+ exports.canvasApi = canvasApi;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ /**!
3
+ * The Drawing manages all necessary data that belong to a model.
4
+ *
5
+ * On the one hand these are the structure and graphic data by which the
6
+ * CAD model is defined, on the other hand it administers additional data
7
+ * for the support with the client-sided development.
8
+ *
9
+ * @image /doc/assets/core/drawing.png
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.createDrawingState = void 0;
13
+ const uuid_1 = require("uuid");
14
+ const canvas_1 = require("./canvas");
15
+ const geometry_1 = require("./geometry");
16
+ const graphic_1 = require("./graphic");
17
+ const plugin_1 = require("./plugin");
18
+ const selection_1 = require("./selection");
19
+ const structure_1 = require("./structure");
20
+ ////////////////////////////////////////////////////
21
+ // DATA
22
+ ////////////////////////////////////////////////////
23
+ const createDrawingState = (set, get, api, drawingNumber, name) => {
24
+ const drawingId = uuid_1.v4();
25
+ return {
26
+ structure: structure_1.structureData(),
27
+ selection: selection_1.selectionData(),
28
+ plugin: plugin_1.pluginData(),
29
+ geometry: geometry_1.geometryData(),
30
+ graphic: graphic_1.graphicData(),
31
+ canvas: canvas_1.canvasData(),
32
+ api: {
33
+ structure: structure_1.structureApi(set, get),
34
+ selection: selection_1.selectionApi(set, get),
35
+ plugin: plugin_1.pluginApi(set, get),
36
+ geometry: geometry_1.geometryApi(set, get),
37
+ graphic: graphic_1.graphicApi(set, get),
38
+ canvas: canvas_1.canvasApi(set, get),
39
+ },
40
+ id: drawingId,
41
+ name: name || `Drawing #${drawingNumber}`,
42
+ };
43
+ };
44
+ exports.createDrawingState = createDrawingState;
@@ -1,9 +1,31 @@
1
- import * as THREE from 'three';
2
- import { ThreeGeometryCreator } from '../../geometry/ThreeGeometryCreator';
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.geometryApi = exports.geometryData = void 0;
23
+ const THREE = __importStar(require("three"));
24
+ const ThreeGeometryCreator_1 = require("../../geometry/ThreeGeometryCreator");
3
25
  ////////////////////////////////////////////////////
4
26
  // DATA
5
27
  ////////////////////////////////////////////////////
6
- export const geometryData = () => ({
28
+ const geometryData = () => ({
7
29
  cache: {},
8
30
  stamp: -1,
9
31
  bounds: {
@@ -14,10 +36,11 @@ export const geometryData = () => ({
14
36
  },
15
37
  config: { product: {} },
16
38
  });
39
+ exports.geometryData = geometryData;
17
40
  ////////////////////////////////////////////////////
18
41
  // API
19
42
  ////////////////////////////////////////////////////
20
- export const geometryApi = (set, get) => ({
43
+ const geometryApi = (set, get) => ({
21
44
  /**
22
45
  * Updates the @see geometry.bounds depending on all products of the model.
23
46
  * The update will only happen, if at least one solid of one product is available.
@@ -35,7 +58,7 @@ export const geometryApi = (set, get) => ({
35
58
  if (!geom) {
36
59
  const container = graphic.containers[containerId];
37
60
  if (container) {
38
- geom = new ThreeGeometryCreator().createGeometry(container, color);
61
+ geom = new ThreeGeometryCreator_1.ThreeGeometryCreator().createGeometry(container, color);
39
62
  set(state => {
40
63
  const geometryCache = Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: geom });
41
64
  return {
@@ -84,3 +107,4 @@ export const geometryApi = (set, get) => ({
84
107
  });
85
108
  },
86
109
  });
110
+ exports.geometryApi = geometryApi;
@@ -1,13 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.graphicApi = exports.graphicData = void 0;
1
4
  ////////////////////////////////////////////////////
2
5
  // DATA
3
6
  ////////////////////////////////////////////////////
4
- export const graphicData = () => ({
7
+ const graphicData = () => ({
5
8
  containers: {},
6
9
  });
10
+ exports.graphicData = graphicData;
7
11
  ////////////////////////////////////////////////////
8
12
  // API
9
13
  ////////////////////////////////////////////////////
10
- export const graphicApi = (set, get) => ({
14
+ const graphicApi = (set, get) => ({
11
15
  addPackages: (packages) => {
12
16
  // Timing.dump('load', `add graphic packages ${graphic.length} ${graphic[0].containers.length}`)
13
17
  let cacheChanged = false;
@@ -80,3 +84,4 @@ export const graphicApi = (set, get) => ({
80
84
  }
81
85
  },
82
86
  });
87
+ exports.graphicApi = graphicApi;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getInitialMessageState = exports.BuerliMessageScope = void 0;
4
+ const uuid_1 = require("uuid");
5
+ exports.BuerliMessageScope = 'BuerliMessageScope';
6
+ const getInitialMessageState = (set, get, api) => ({
7
+ message: {
8
+ data: null,
9
+ timestamp: -1,
10
+ api: messageApi(set, get, api),
11
+ },
12
+ });
13
+ exports.getInitialMessageState = getInitialMessageState;
14
+ const messageApi = (set, get, api) => ({
15
+ show(message) {
16
+ const newId = uuid_1.v4();
17
+ const msg = get().message;
18
+ set({ message: Object.assign(Object.assign({}, msg), { data: Object.assign({ id: newId }, message), timestamp: Date.now() }) });
19
+ return newId;
20
+ },
21
+ update(id, message) {
22
+ const msg = get().message;
23
+ set({ message: Object.assign(Object.assign({}, msg), { data: Object.assign({ id }, message), timestamp: Date.now() }) });
24
+ },
25
+ });
@@ -1,5 +1,8 @@
1
- import { v4 as uuidv4 } from 'uuid';
2
- export const pluginData = () => ({
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isPromisePlugin = exports.pluginApi = exports.pluginData = void 0;
4
+ const uuid_1 = require("uuid");
5
+ const pluginData = () => ({
3
6
  feature: [],
4
7
  global: [],
5
8
  refs: {},
@@ -9,13 +12,10 @@ export const pluginData = () => ({
9
12
  },
10
13
  visible: [],
11
14
  });
12
- export const pluginApi = (set, get) => ({
15
+ exports.pluginData = pluginData;
16
+ const pluginApi = (set, get) => ({
13
17
  setActiveFeature: (id) => {
14
18
  set(state => {
15
- if (id !== null && state.plugin.feature.indexOf(id) === -1) {
16
- console.warn('Given pluginId does not exist.');
17
- return state;
18
- }
19
19
  let plugins = state.plugin.refs;
20
20
  const oldPlugin = state.plugin.active.feature !== null && state.plugin.refs[state.plugin.active.feature];
21
21
  if (oldPlugin && state.plugin.active.feature !== id && !oldPlugin.persistent && id !== null) {
@@ -31,10 +31,6 @@ export const pluginApi = (set, get) => ({
31
31
  },
32
32
  setVisiblePlugin: (id, visible) => {
33
33
  set(currentState => {
34
- if (currentState.plugin.global.indexOf(id) === -1 && currentState.plugin.feature.indexOf(id) === -1) {
35
- console.warn('Given plugin id does not exist.');
36
- return currentState;
37
- }
38
34
  const filtered = currentState.plugin.visible.filter(p => p !== id);
39
35
  if (visible)
40
36
  filtered.push(id);
@@ -57,8 +53,9 @@ export const pluginApi = (set, get) => ({
57
53
  };
58
54
  });
59
55
  },
56
+ // TODO remove defaultId and useEmbeddedPlugin ?
60
57
  createPlugin: (def, defaultId, drawingId, objectId) => {
61
- const id = defaultId !== void 0 ? defaultId : uuidv4();
58
+ const id = defaultId !== void 0 ? defaultId : uuid_1.v4();
62
59
  function init(definition) {
63
60
  const { description, Root = null, View = null } = definition;
64
61
  const initialState = description.initialState || {};
@@ -109,6 +106,8 @@ export const pluginApi = (set, get) => ({
109
106
  };
110
107
  },
111
108
  });
112
- export function isPromisePlugin(def) {
109
+ exports.pluginApi = pluginApi;
110
+ function isPromisePlugin(def) {
113
111
  return def.then !== undefined;
114
112
  }
113
+ exports.isPromisePlugin = isPromisePlugin;