@buerli.io/core 0.5.0-beta.1 → 0.5.0-beta.2

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 (80) hide show
  1. package/build/cjs/geometry/ThreeGeometryCreator.js +321 -0
  2. package/build/cjs/geometry/index.js +17 -0
  3. package/build/cjs/graphic/filters.js +25 -0
  4. package/build/cjs/index.js +25 -0
  5. package/build/cjs/store/index.js +37 -0
  6. package/build/cjs/store/states/buerli.js +98 -0
  7. package/build/cjs/store/states/cad.js +35 -0
  8. package/build/cjs/store/states/drawing.js +47 -0
  9. package/build/cjs/store/states/geometry.js +139 -0
  10. package/build/cjs/store/states/graphic.js +115 -0
  11. package/build/cjs/store/states/interaction.js +55 -0
  12. package/build/cjs/store/states/message.js +25 -0
  13. package/build/cjs/store/states/plugin.js +115 -0
  14. package/build/cjs/store/states/selection.js +258 -0
  15. package/build/cjs/store/states/structure.js +239 -0
  16. package/build/cjs/store/store.js +9 -0
  17. package/build/cjs/store/subscribtion/selection.js +46 -0
  18. package/build/cjs/store/subscribtion/subscribeToDrawing.js +13 -0
  19. package/build/cjs/types/IGraphicPackage.js +49 -0
  20. package/build/cjs/types/IStructurePatch.js +2 -0
  21. package/build/cjs/types/IStructureTree.js +27 -0
  22. package/build/cjs/types/InteractionInfo.js +11 -0
  23. package/build/cjs/types/index.js +20 -0
  24. package/build/cjs/utils/Math.js +91 -0
  25. package/build/cjs/utils/Measure.js +560 -0
  26. package/build/cjs/utils/Timing.js +34 -0
  27. package/build/{geometry → esm/geometry}/ThreeGeometryCreator.js +0 -0
  28. package/build/{geometry → esm/geometry}/index.js +0 -0
  29. package/build/{graphic → esm/graphic}/filters.js +0 -0
  30. package/build/{index.js → esm/index.js} +0 -0
  31. package/build/{store → esm/store}/index.js +0 -0
  32. package/build/{store → esm/store}/states/buerli.js +0 -0
  33. package/build/{store → esm/store}/states/cad.js +0 -0
  34. package/build/{store → esm/store}/states/drawing.js +0 -0
  35. package/build/{store → esm/store}/states/geometry.js +0 -0
  36. package/build/{store → esm/store}/states/graphic.js +0 -0
  37. package/build/{store → esm/store}/states/interaction.js +0 -0
  38. package/build/{store → esm/store}/states/message.js +0 -0
  39. package/build/{store → esm/store}/states/plugin.js +0 -0
  40. package/build/{store → esm/store}/states/selection.js +0 -0
  41. package/build/{store → esm/store}/states/structure.js +0 -0
  42. package/build/{store → esm/store}/store.js +0 -0
  43. package/build/{store → esm/store}/subscribtion/selection.js +0 -0
  44. package/build/{store → esm/store}/subscribtion/subscribeToDrawing.js +0 -0
  45. package/build/{types → esm/types}/IGraphicPackage.js +0 -0
  46. package/build/{types → esm/types}/IStructurePatch.js +0 -0
  47. package/build/{types → esm/types}/IStructureTree.js +0 -0
  48. package/build/{types → esm/types}/InteractionInfo.js +0 -0
  49. package/build/{types → esm/types}/index.js +0 -0
  50. package/build/{utils → esm/utils}/Math.js +0 -0
  51. package/build/{utils → esm/utils}/Measure.js +0 -0
  52. package/build/{utils → esm/utils}/Timing.js +0 -0
  53. package/build/{geometry → types/geometry}/ThreeGeometryCreator.d.ts +0 -0
  54. package/build/{geometry → types/geometry}/index.d.ts +0 -0
  55. package/build/{graphic → types/graphic}/filters.d.ts +0 -0
  56. package/build/types/index.d.ts +37 -4
  57. package/build/{store → types/store}/index.d.ts +0 -0
  58. package/build/{store → types/store}/states/buerli.d.ts +0 -0
  59. package/build/{store → types/store}/states/cad.d.ts +0 -0
  60. package/build/{store → types/store}/states/drawing.d.ts +0 -0
  61. package/build/{store → types/store}/states/geometry.d.ts +0 -0
  62. package/build/{store → types/store}/states/graphic.d.ts +0 -0
  63. package/build/{store → types/store}/states/interaction.d.ts +0 -0
  64. package/build/{store → types/store}/states/message.d.ts +0 -0
  65. package/build/{store → types/store}/states/plugin.d.ts +0 -0
  66. package/build/{store → types/store}/states/selection.d.ts +0 -0
  67. package/build/{store → types/store}/states/structure.d.ts +0 -0
  68. package/build/{store → types/store}/store.d.ts +0 -0
  69. package/build/{store → types/store}/subscribtion/selection.d.ts +0 -0
  70. package/build/{store → types/store}/subscribtion/subscribeToDrawing.d.ts +0 -0
  71. package/build/types/{IGraphicPackage.d.ts → types/IGraphicPackage.d.ts} +0 -0
  72. package/build/types/{IStructurePatch.d.ts → types/IStructurePatch.d.ts} +0 -0
  73. package/build/types/{IStructureTree.d.ts → types/IStructureTree.d.ts} +0 -0
  74. package/build/types/{InteractionInfo.d.ts → types/InteractionInfo.d.ts} +0 -0
  75. package/build/types/types/index.d.ts +4 -0
  76. package/build/{utils → types/utils}/Math.d.ts +0 -0
  77. package/build/{utils → types/utils}/Measure.d.ts +0 -0
  78. package/build/{utils → types/utils}/Timing.d.ts +0 -0
  79. package/package.json +7 -7
  80. package/build/index.d.ts +0 -37
@@ -0,0 +1,321 @@
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.isEqualGeometry = exports.EMPTY_CONTAINER_GEOMETRY = exports.ThreeGeometryCreator = void 0;
27
+ const THREE = __importStar(require("three"));
28
+ const types_1 = require("./../types");
29
+ const convertType = (contType) => {
30
+ let type = types_1.GraphicType.NONE;
31
+ switch (contType) {
32
+ case types_1.ContainerType.BREP:
33
+ type = types_1.GraphicType.BREP;
34
+ break;
35
+ case types_1.ContainerType.CURVEARRAY:
36
+ type = types_1.GraphicType.CURVEARRAY;
37
+ break;
38
+ case types_1.ContainerType.POLYBREP:
39
+ type = types_1.GraphicType.POLYBREP;
40
+ break;
41
+ }
42
+ return type;
43
+ };
44
+ /**
45
+ * Creates THREE geometry based on the data within a @see IGraphicContainer.
46
+ */
47
+ class ThreeGeometryCreator {
48
+ constructor() {
49
+ this.coordHeightTolerance = 0.01;
50
+ }
51
+ getMetadata(geometry, container, color = [0, 0, 0], opacity = 0) {
52
+ var _a;
53
+ const contProps = container.properties; // container has always properties
54
+ const geomProps = geometry ? geometry.properties : {};
55
+ let col = container.properties.material.color || color;
56
+ let opa = container.properties.material.opacity || opacity;
57
+ if (geomProps && geomProps.material) {
58
+ col = geomProps.material.color || col;
59
+ opa = geomProps.material.opacity || opa;
60
+ }
61
+ const rgbColor = new THREE.Color(col[0] / 255, col[1] / 255, col[2] / 255);
62
+ const layer = geomProps && geomProps.layer ? geomProps.layer : contProps.layer;
63
+ return {
64
+ color: rgbColor,
65
+ opacity: opa,
66
+ layer,
67
+ container: { id: container.id, ownerId: container.owner, type: convertType(container.type) },
68
+ operationId: (_a = geometry === null || geometry === void 0 ? void 0 : geometry.properties) === null || _a === void 0 ? void 0 : _a.operationId,
69
+ rawGraphic: geometry,
70
+ };
71
+ }
72
+ createGeometry(container, color = [0, 0, 0]) {
73
+ const { id: graphicId, properties, type: contType } = container;
74
+ const type = convertType(contType);
75
+ const box = { min: new THREE.Vector3(...properties.min), max: new THREE.Vector3(...properties.max) };
76
+ const meshes = [];
77
+ const lines = [];
78
+ const edges = [];
79
+ const arcs = [];
80
+ const pointMap = {};
81
+ const map = {};
82
+ if (container.meshes) {
83
+ container.meshes.forEach(mesh => {
84
+ const elem = this.createSurface(mesh, container, color);
85
+ if (elem.isValid) {
86
+ meshes.push(elem);
87
+ map[mesh.id] = elem;
88
+ }
89
+ else {
90
+ // TODO: The server should not send invalid meshes.
91
+ console.warn(`Invalid mesh detected`);
92
+ }
93
+ });
94
+ }
95
+ if (container.lines) {
96
+ container.lines.forEach(line => {
97
+ const elem = this.createLine(line, container, pointMap, color);
98
+ lines.push(elem);
99
+ map[line.id] = elem;
100
+ });
101
+ }
102
+ if (container.edges) {
103
+ container.edges.forEach(edge => {
104
+ const elem = this.createEdge(edge, container, pointMap, color);
105
+ edges.push(elem);
106
+ map[edge.id] = elem;
107
+ });
108
+ }
109
+ if (container.arcs) {
110
+ container.arcs.forEach(arc => {
111
+ const elem = this.createArc(arc, container, pointMap, color);
112
+ arcs.push(elem);
113
+ map[arc.id] = elem;
114
+ });
115
+ }
116
+ const points = Object.values(pointMap);
117
+ return Object.assign({ graphicId,
118
+ type,
119
+ map,
120
+ meshes,
121
+ lines,
122
+ edges,
123
+ arcs,
124
+ points,
125
+ box }, this.getMetadata(null, container, color));
126
+ }
127
+ createSurface(mesh, container, color = [0, 0, 0]) {
128
+ let meshGeom = this.createMesh(mesh, container, color);
129
+ switch (meshGeom.type) {
130
+ case types_1.GraphicType.PLANE:
131
+ meshGeom = this.createPlane(mesh, meshGeom);
132
+ break;
133
+ case types_1.GraphicType.CYLINDER:
134
+ meshGeom = this.createCylinder(mesh, meshGeom);
135
+ break;
136
+ case types_1.GraphicType.CONE:
137
+ meshGeom = this.createCone(mesh, meshGeom);
138
+ break;
139
+ case types_1.GraphicType.SPHERE:
140
+ meshGeom = this.createSphere(mesh, meshGeom);
141
+ break;
142
+ }
143
+ return meshGeom;
144
+ }
145
+ createMesh(mesh, container, color = [0, 0, 0]) {
146
+ const graphicId = mesh.id;
147
+ const loops = mesh.loops;
148
+ const type = mesh.properties.surface.type;
149
+ const geometry = new THREE.BufferGeometry();
150
+ geometry.setIndex(mesh.indices);
151
+ geometry.setAttribute('position', new THREE.Float32BufferAttribute(mesh.vertices, 3));
152
+ mesh.normals && geometry.setAttribute('normal', new THREE.Float32BufferAttribute(mesh.normals, 3));
153
+ return Object.assign({
154
+ // TODO: The server should not send invalid meshes.
155
+ isValid: mesh.vertices && mesh.vertices.length > 0, geometry,
156
+ graphicId,
157
+ type,
158
+ loops }, this.getMetadata(mesh, container, color));
159
+ }
160
+ createPlane(mesh, meshGeom) {
161
+ const type = types_1.GraphicType.PLANE;
162
+ const { normal: n, pointOnPlane: p } = mesh.properties.surface;
163
+ const pointOnPlane = new THREE.Vector3(p[0], p[1], p[2]);
164
+ const normal = new THREE.Vector3(n[0], n[1], n[2]).normalize();
165
+ return Object.assign(Object.assign({}, meshGeom), { type, pointOnPlane, normal });
166
+ }
167
+ createCylinder(mesh, meshGeom) {
168
+ const type = types_1.GraphicType.CYLINDER;
169
+ const { origin: o, axis: a, height, radius } = mesh.properties.surface;
170
+ const origin = new THREE.Vector3(o[0], o[1], o[2]);
171
+ const axis = new THREE.Vector3(a[0], a[1], a[2]).normalize();
172
+ return Object.assign(Object.assign({}, meshGeom), { type, origin, axis, height, radius });
173
+ }
174
+ createCone(mesh, meshGeom) {
175
+ const type = types_1.GraphicType.CONE;
176
+ const { origin: o, axis: a, height, radiusBottom, radiusTop } = mesh.properties.surface;
177
+ const origin = new THREE.Vector3(o[0], o[1], o[2]);
178
+ const axis = new THREE.Vector3(a[0], a[1], a[2]).normalize();
179
+ return Object.assign(Object.assign({}, meshGeom), { type, origin, axis, height, radiusBottom, radiusTop });
180
+ }
181
+ createSphere(mesh, meshGeom) {
182
+ const type = types_1.GraphicType.SPHERE;
183
+ const { radius } = mesh.properties.surface;
184
+ return Object.assign(Object.assign({}, meshGeom), { type, radius });
185
+ }
186
+ createLine(line, container, points, color = [0, 0, 0]) {
187
+ const graphicId = line.id;
188
+ let type = types_1.GraphicType.LINE;
189
+ if (container.type === types_1.ContainerType.CURVEARRAY) {
190
+ type = types_1.GraphicType.CURVELINE;
191
+ }
192
+ const pts = line.points;
193
+ const [startId, endId] = line.pointIds;
194
+ const start = new THREE.Vector3(pts[0], pts[1], pts[2]);
195
+ const end = new THREE.Vector3(pts[3], pts[4], pts[5]);
196
+ this.insertPoint(container, `${startId}|point`, startId, start.clone(), line.id, 'start', points);
197
+ this.insertPoint(container, `${endId}|point`, endId, end.clone(), line.id, 'end', points);
198
+ const geometry = new THREE.BufferGeometry().setFromPoints([start.clone(), end.clone()]);
199
+ return Object.assign(Object.assign({ geometry,
200
+ graphicId, type: type }, this.getMetadata(line, container, color)), { start: start.clone(), end: end.clone() });
201
+ }
202
+ createEdge(edge, container, points, color = [0, 0, 0]) {
203
+ const threePts = [];
204
+ const graphicId = edge.id;
205
+ let type = types_1.GraphicType.EDGE;
206
+ if (container.type === types_1.ContainerType.CURVEARRAY) {
207
+ type = types_1.GraphicType.CURVESPLINE;
208
+ }
209
+ const pts = edge.points;
210
+ for (let i = 0, length = pts.length / 3; i < length; i++) {
211
+ threePts.push(new THREE.Vector3(pts[i * 3], pts[i * 3 + 1], pts[i * 3 + 2]));
212
+ // Each segment has to be defined with start and end to use it for BufferGeometry
213
+ if (i > 0) {
214
+ threePts.push(new THREE.Vector3(pts[i * 3], pts[i * 3 + 1], pts[i * 3 + 2]));
215
+ }
216
+ }
217
+ // Seems like the three BufferGeometryUtils expect an edge to have an even number of points.
218
+ // Just add the end point twice if this is not the case.
219
+ if (threePts.length % 2 !== 0) {
220
+ threePts.push(threePts[threePts.length - 1].clone());
221
+ }
222
+ const start = threePts[0].clone();
223
+ const end = threePts[threePts.length - 1].clone();
224
+ const startId = edge.pointIds[0];
225
+ const endId = edge.pointIds[edge.pointIds.length - 1];
226
+ this.insertPoint(container, `${startId}|point`, startId, start, edge.id, 'start', points);
227
+ this.insertPoint(container, `${endId}|point`, endId, end, edge.id, 'end', points);
228
+ const geometry = new THREE.BufferGeometry().setFromPoints(threePts);
229
+ return Object.assign(Object.assign({ geometry,
230
+ graphicId, type: type }, this.getMetadata(edge, container, color)), { start: start.clone(), end: end.clone() });
231
+ }
232
+ createArc(arc, container, points, color = [0, 0, 0]) {
233
+ const graphicId = arc.id;
234
+ let type = arc.isCircle ? types_1.GraphicType.CIRCLE : types_1.GraphicType.ARC;
235
+ if (container.type === types_1.ContainerType.CURVEARRAY) {
236
+ type = arc.isCircle ? types_1.GraphicType.CURVECIRCLE : types_1.GraphicType.CURVEARC;
237
+ }
238
+ // take half of coordHeightTolerance used for faces, as classcad does it in the tessellation process
239
+ const coordHeight = this.coordHeightTolerance / 2;
240
+ const radius = arc.radius;
241
+ const center = new THREE.Vector3(arc.center[0], arc.center[1], arc.center[2]);
242
+ const normal = new THREE.Vector3(arc.zAxis[0], arc.zAxis[1], arc.zAxis[2]).normalize();
243
+ const startVector = new THREE.Vector3(arc.xAxis[0], arc.xAxis[1], arc.xAxis[2]).normalize().multiplyScalar(radius);
244
+ const theta = arc.isCircle ? Math.PI * 2 : arc.angle;
245
+ // calculate angle for one segment to fulfill coordHeight tolerance
246
+ let alpha = 2 * Math.acos(1 - coordHeight / radius);
247
+ // calculate number of segments
248
+ let segments = Math.ceil(Math.abs(arc.angle) / alpha);
249
+ // choose at minimum three segments
250
+ segments = Math.max(3, segments);
251
+ // adjust angle to match with number of segments, still fulfilling coordHeigth tolerance
252
+ alpha = theta / segments;
253
+ const threePts = [];
254
+ const matrix = new THREE.Matrix4().makeRotationAxis(normal, alpha);
255
+ const startPoint = center.clone();
256
+ startPoint.add(startVector);
257
+ threePts.push(startPoint);
258
+ for (let i = 0; i < segments; i++) {
259
+ startVector.applyMatrix4(matrix);
260
+ const nextPoint = center.clone();
261
+ nextPoint.add(startVector);
262
+ threePts.push(nextPoint.clone());
263
+ // Each segment has to be defined with start and end to use it for BufferGeometry
264
+ threePts.push(nextPoint.clone());
265
+ }
266
+ // Seems like the three BufferGeometryUtils expect an edge to have an even number of points.
267
+ // Just add the end point twice if this is not the case.
268
+ if (threePts.length % 2 !== 0) {
269
+ threePts.push(threePts[threePts.length - 1].clone());
270
+ }
271
+ const [startId, endId] = arc.pointIds;
272
+ const start = threePts[0].clone();
273
+ const end = threePts[threePts.length - 1].clone();
274
+ this.insertPoint(container, `${startId}|point`, startId, start, arc.id, 'start', points);
275
+ this.insertPoint(container, `${endId}|point`, endId, end, arc.id, 'end', points);
276
+ const geometry = new THREE.BufferGeometry().setFromPoints(threePts);
277
+ return Object.assign(Object.assign({ geometry,
278
+ graphicId, type: type }, this.getMetadata(arc, container, color)), { normal: normal.clone(), center: center.clone(), radius: arc.radius, angle: arc.angle });
279
+ }
280
+ createPoint(container, key, graphicId, position, ownerId, type) {
281
+ return Object.assign(Object.assign({ key,
282
+ graphicId, type: (container.type === types_1.ContainerType.CURVEARRAY ? types_1.GraphicType.CURVEPOINT : types_1.GraphicType.POINT) }, this.getMetadata(null, container)), { position: position.clone(), geometry: position.clone(), owners: [{ ownerId, type }] });
283
+ }
284
+ insertPoint(container, key, graphicId, position, ownerId, type, points) {
285
+ const existingPoint = points[key];
286
+ if (existingPoint) {
287
+ const filteredOwners = existingPoint.owners.filter(gr => gr.ownerId === ownerId && gr.type === type);
288
+ if (filteredOwners.length <= 0) {
289
+ existingPoint.owners.push({ ownerId, type });
290
+ }
291
+ }
292
+ else {
293
+ points[key] = this.createPoint(container, key, graphicId, position, ownerId, type);
294
+ }
295
+ }
296
+ }
297
+ exports.ThreeGeometryCreator = ThreeGeometryCreator;
298
+ const EMPTY_CONTAINER_GEOMETRY = () => {
299
+ return {
300
+ graphicId: Number.NaN,
301
+ type: types_1.GraphicType.NONE,
302
+ map: {},
303
+ meshes: [],
304
+ lines: [],
305
+ edges: [],
306
+ arcs: [],
307
+ points: [],
308
+ box: { min: new THREE.Vector3(), max: new THREE.Vector3() },
309
+ container: { id: Number.NaN, ownerId: Number.NaN, type: types_1.GraphicType.NONE },
310
+ color: new THREE.Color(),
311
+ opacity: 1.0,
312
+ layer: null,
313
+ operationId: Number.NaN,
314
+ rawGraphic: null,
315
+ };
316
+ };
317
+ exports.EMPTY_CONTAINER_GEOMETRY = EMPTY_CONTAINER_GEOMETRY;
318
+ const isEqualGeometry = (a, b) => {
319
+ return a.graphicId === b.graphicId && a.type === b.type;
320
+ };
321
+ exports.isEqualGeometry = isEqualGeometry;
@@ -0,0 +1,17 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./ThreeGeometryCreator"), exports);
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.solidFilter = exports.loopFilter = exports.planeFilter = exports.meshFilter = exports.pointFilter = exports.arcCircleFilter = exports.circleFilter = exports.arcFilter = exports.lineSegmentsFilter = exports.lineFilter = void 0;
4
+ const IGraphicPackage_1 = require("../types/IGraphicPackage");
5
+ const selection_1 = require("../store/states/selection");
6
+ const lineFilter = (scope, data) => scope === selection_1.BuerliScope && (data === IGraphicPackage_1.GraphicType.LINE || data === IGraphicPackage_1.GraphicType.EDGE);
7
+ exports.lineFilter = lineFilter;
8
+ const lineSegmentsFilter = (scope, data) => scope === selection_1.BuerliScope && IGraphicPackage_1.LineSegments.includes(data);
9
+ exports.lineSegmentsFilter = lineSegmentsFilter;
10
+ const arcFilter = (scope, data) => scope === selection_1.BuerliScope && data === IGraphicPackage_1.GraphicType.ARC;
11
+ exports.arcFilter = arcFilter;
12
+ const circleFilter = (scope, data) => scope === selection_1.BuerliScope && data === IGraphicPackage_1.GraphicType.CIRCLE;
13
+ exports.circleFilter = circleFilter;
14
+ const arcCircleFilter = (scope, data) => scope === selection_1.BuerliScope && (data === IGraphicPackage_1.GraphicType.ARC || data === IGraphicPackage_1.GraphicType.CIRCLE);
15
+ exports.arcCircleFilter = arcCircleFilter;
16
+ const pointFilter = (scope, data) => scope === selection_1.BuerliScope && data === IGraphicPackage_1.GraphicType.POINT;
17
+ exports.pointFilter = pointFilter;
18
+ const meshFilter = (scope, data) => scope === selection_1.BuerliScope && IGraphicPackage_1.Surfaces.includes(data);
19
+ exports.meshFilter = meshFilter;
20
+ const planeFilter = (scope, data) => scope === selection_1.BuerliScope && data === IGraphicPackage_1.GraphicType.PLANE;
21
+ exports.planeFilter = planeFilter;
22
+ const loopFilter = (scope, data) => scope === selection_1.BuerliScope && data === IGraphicPackage_1.GraphicType.LOOP;
23
+ exports.loopFilter = loopFilter;
24
+ const solidFilter = (scope, data) => scope === selection_1.BuerliScope && data === IGraphicPackage_1.GraphicType.BREP;
25
+ exports.solidFilter = solidFilter;
@@ -0,0 +1,25 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./store"), exports);
18
+ __exportStar(require("./geometry"), exports);
19
+ __exportStar(require("./types"), exports);
20
+ __exportStar(require("./utils/Math"), exports);
21
+ __exportStar(require("./utils/Measure"), exports);
22
+ __exportStar(require("./utils/Timing"), exports);
23
+ __exportStar(require("./store/subscribtion/subscribeToDrawing"), exports);
24
+ __exportStar(require("./graphic/filters"), exports);
25
+ //#endregion Re-export type definitions
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateMessage = exports.showMessage = exports.init = exports.getPlugin = exports.getDrawing = exports.api = exports.createGraphicItem = exports.BuerliScope = exports.BuerliMessageScope = void 0;
4
+ const store_1 = require("./store");
5
+ function getDrawing(id) {
6
+ const { drawing } = store_1.api.getState();
7
+ return drawing.refs[id];
8
+ }
9
+ exports.getDrawing = getDrawing;
10
+ /**
11
+ * @returns PluginState or undefined if either drawing or plugin don't exist
12
+ */
13
+ function getPlugin(drawingId, pluginId) {
14
+ var _a;
15
+ const { drawing } = store_1.api.getState();
16
+ return (_a = drawing.refs[drawingId]) === null || _a === void 0 ? void 0 : _a.plugin.refs[pluginId];
17
+ }
18
+ exports.getPlugin = getPlugin;
19
+ function init(options) {
20
+ store_1.api.getState().api.init(options);
21
+ }
22
+ exports.init = init;
23
+ function showMessage(message) {
24
+ return store_1.api.getState().message.api.show(message);
25
+ }
26
+ exports.showMessage = showMessage;
27
+ function updateMessage(id, message) {
28
+ store_1.api.getState().message.api.update(id, message);
29
+ }
30
+ exports.updateMessage = updateMessage;
31
+ var message_1 = require("./states/message");
32
+ Object.defineProperty(exports, "BuerliMessageScope", { enumerable: true, get: function () { return message_1.BuerliMessageScope; } });
33
+ var selection_1 = require("./states/selection");
34
+ Object.defineProperty(exports, "BuerliScope", { enumerable: true, get: function () { return selection_1.BuerliScope; } });
35
+ Object.defineProperty(exports, "createGraphicItem", { enumerable: true, get: function () { return selection_1.createGraphicItem; } });
36
+ var store_2 = require("./store");
37
+ Object.defineProperty(exports, "api", { enumerable: true, get: function () { return store_2.api; } });
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.drawingManagementApi = exports.generalApi = exports.createState = void 0;
4
+ const drawing_1 = require("./drawing");
5
+ const message_1 = require("./message");
6
+ const initError = 'Please call the init action before you use the buerli store.';
7
+ const createState = (set, get, buerliApi) => (Object.assign({ initDone: false, options: {
8
+ elements: {},
9
+ plugins: {},
10
+ globalPlugins: [],
11
+ theme: {
12
+ primary: '#e36b7c',
13
+ secondary: '#fcc7cb',
14
+ dark: '#54545d',
15
+ highlightedGeom: '#e36b7c',
16
+ hoveredGeom: '#40a9ff',
17
+ },
18
+ config: {
19
+ geometry: {},
20
+ },
21
+ }, drawing: {
22
+ ids: [],
23
+ refs: {},
24
+ active: null,
25
+ }, api: Object.assign(Object.assign({}, (0, exports.generalApi)(set, get, buerliApi)), (0, exports.drawingManagementApi)(set, get, buerliApi)) }, (0, message_1.getInitialMessageState)(set, get, buerliApi)));
26
+ exports.createState = createState;
27
+ const generalApi = set => ({
28
+ // TODO: rename init to setOptions and remove initDone if everything is ok
29
+ /**
30
+ * This api method initializes state. Considering user can accidentally ommit some important like elements,
31
+ * there is a warning disaplying for these cases.
32
+ *
33
+ * @param options - options which will be set into state.options
34
+ */
35
+ init(options) {
36
+ set(state => ({ options: Object.assign(Object.assign({}, state.options), options), initDone: true }));
37
+ },
38
+ });
39
+ exports.generalApi = generalApi;
40
+ const drawingManagementApi = (set, get, buerliApi) => ({
41
+ async createDrawing(name) {
42
+ const { initDone, drawing } = get();
43
+ if (!initDone)
44
+ throw new Error(initError);
45
+ const drawingState = (0, drawing_1.createDrawingState)(sel => set(state => {
46
+ const newState = typeof sel === 'function' ? sel(state.drawing.refs[drawingState.id]) : sel;
47
+ return {
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) }) }),
49
+ };
50
+ }), () => get().drawing.refs[drawingState.id], buerliApi, drawing.ids.length, name);
51
+ set(state => ({
52
+ drawing: Object.assign(Object.assign({}, state.drawing), { refs: Object.assign(Object.assign({}, state.drawing.refs), { [drawingState.id]: drawingState }), ids: [...state.drawing.ids, drawingState.id], active: drawingState.id }),
53
+ }));
54
+ // Initialize global plugins
55
+ get().options.globalPlugins.forEach(def => get().drawing.refs[drawingState.id].api.plugin.createPlugin(def));
56
+ return drawingState;
57
+ },
58
+ removeDrawing(id) {
59
+ const { initDone } = get();
60
+ if (!initDone)
61
+ throw new Error(initError);
62
+ // Note:
63
+ // Since it can lead to unexpected behaviour because of updating everything at once
64
+ // split the state modification into two parts.
65
+ // 1. Reset active drawing
66
+ // 2. Remove drawing from state
67
+ // Give the listeners the possibility to handle the active drawing before it is removed.
68
+ // There was exactly such a situation in buerli-examples, where a cad instance of buerli-headless
69
+ // was destroyed (removes drawing as well) while a components is going to be unmounted, but an
70
+ // other component already binds to the active drawing before it is removed. Yes, it can be handled
71
+ // by the application but it makes sense to pay attention to this behaviour at this place already.
72
+ // 1.
73
+ // Calculate and set the active drawing before removing the drawing from the store.
74
+ set(state => {
75
+ const index = state.drawing.ids.indexOf(id);
76
+ // Pick close by drawing unless another drawing has been active all along
77
+ const active = index >= 0 && state.drawing.active === id
78
+ ? state.drawing.ids[index + 1] || state.drawing.ids[index - 1] || null
79
+ : state.drawing.active;
80
+ return { drawing: Object.assign(Object.assign({}, state.drawing), { active }) };
81
+ });
82
+ // 2.
83
+ // Remove drawing from store.
84
+ set(state => {
85
+ const refs = Object.assign({}, state.drawing.refs);
86
+ const ids = state.drawing.ids.filter(d => d !== id);
87
+ delete refs[id];
88
+ return { drawing: Object.assign(Object.assign({}, state.drawing), { refs, ids }) };
89
+ });
90
+ },
91
+ setActiveDrawing(id) {
92
+ const { initDone, drawing } = get();
93
+ if (!initDone)
94
+ throw new Error(initError);
95
+ set({ drawing: Object.assign(Object.assign({}, drawing), { active: id }) });
96
+ },
97
+ });
98
+ exports.drawingManagementApi = drawingManagementApi;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cadApi = exports.cadData = void 0;
4
+ const uuid_1 = require("uuid");
5
+ ////////////////////////////////////////////////////
6
+ // DATA
7
+ ////////////////////////////////////////////////////
8
+ const cadData = () => ({
9
+ connected: false,
10
+ states: { current: 0, stack: [], captionMap: {} },
11
+ pending: [],
12
+ });
13
+ exports.cadData = cadData;
14
+ ////////////////////////////////////////////////////
15
+ // API
16
+ ////////////////////////////////////////////////////
17
+ const cadApi = (set, get, buerliApi) => ({
18
+ setStates: (current, stack, captionMap) => set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { states: Object.assign(Object.assign({}, state.cad.states), { current, stack, captionMap }) }) })),
19
+ setCaptionMap: (captionMap) => set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { states: Object.assign(Object.assign({}, state.cad.states), { captionMap }) }) })),
20
+ addPending: (name, options) => {
21
+ const id = (0, uuid_1.v4)();
22
+ set(state => ({
23
+ cad: Object.assign(Object.assign({}, state.cad), { pending: [...state.cad.pending, Object.assign(Object.assign({}, options), { id, name, stamp: Date.now() })] }),
24
+ }));
25
+ return id;
26
+ },
27
+ removePending: (id) => {
28
+ const newPending = get().cad.pending.filter(p => p.id !== id);
29
+ set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { pending: newPending }) }));
30
+ },
31
+ setConnected: (connected) => {
32
+ return set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { connected }) }));
33
+ },
34
+ });
35
+ exports.cadApi = cadApi;
@@ -0,0 +1,47 @@
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 cad_1 = require("./cad");
15
+ const geometry_1 = require("./geometry");
16
+ const graphic_1 = require("./graphic");
17
+ const interaction_1 = require("./interaction");
18
+ const plugin_1 = require("./plugin");
19
+ const selection_1 = require("./selection");
20
+ const structure_1 = require("./structure");
21
+ ////////////////////////////////////////////////////
22
+ // DATA
23
+ ////////////////////////////////////////////////////
24
+ const createDrawingState = (set, get, buerliApi, drawingNumber, name) => {
25
+ const drawingId = (0, uuid_1.v4)();
26
+ return {
27
+ structure: (0, structure_1.structureData)(),
28
+ selection: (0, selection_1.selectionData)(),
29
+ interaction: (0, interaction_1.interactionData)(),
30
+ plugin: (0, plugin_1.pluginData)(),
31
+ geometry: (0, geometry_1.geometryData)(),
32
+ graphic: (0, graphic_1.graphicData)(),
33
+ cad: (0, cad_1.cadData)(),
34
+ api: {
35
+ structure: (0, structure_1.structureApi)(set, get, buerliApi),
36
+ selection: (0, selection_1.selectionApi)(set, get, buerliApi),
37
+ plugin: (0, plugin_1.pluginApi)(set, get, buerliApi),
38
+ geometry: (0, geometry_1.geometryApi)(set, get, buerliApi),
39
+ graphic: (0, graphic_1.graphicApi)(set, get, buerliApi),
40
+ cad: (0, cad_1.cadApi)(set, get, buerliApi),
41
+ interaction: (0, interaction_1.interactionApi)(set, get, buerliApi),
42
+ },
43
+ id: drawingId,
44
+ name: name || `Drawing #${drawingNumber}`,
45
+ };
46
+ };
47
+ exports.createDrawingState = createDrawingState;