@bitbybit-dev/ifc 1.5.0 → 1.6.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 (96) hide show
  1. package/README.md +11 -5
  2. package/lib/api/dto-registry.js +3 -1
  3. package/lib/api/ifc-service.d.ts +10 -5
  4. package/lib/api/ifc-service.js +7 -5
  5. package/lib/api/inputs/ifc-inputs.d.ts +121 -5
  6. package/lib/api/inputs/ifc-inputs.js +162 -5
  7. package/lib/api/resolved-inputs/index.d.ts +6 -3
  8. package/lib/api/services/doors.js +4 -1
  9. package/lib/api/services/elements.d.ts +28 -0
  10. package/lib/api/services/elements.js +60 -0
  11. package/lib/api/services/geometry.js +3 -3
  12. package/lib/api/services/index.d.ts +1 -0
  13. package/lib/api/services/index.js +1 -0
  14. package/lib/api/services/member-support.js +2 -2
  15. package/lib/api/services/model.js +3 -3
  16. package/lib/api/services/openings.js +16 -11
  17. package/lib/api/services/properties.js +4 -3
  18. package/lib/api/services/site.js +3 -1
  19. package/lib/api/services/spaces.js +1 -0
  20. package/lib/api/services/walls.d.ts +7 -5
  21. package/lib/api/services/walls.js +15 -7
  22. package/lib/api/services/windows.js +5 -2
  23. package/lib/build/assemblies.js +1 -1
  24. package/lib/build/bodied-elements.d.ts +5 -0
  25. package/lib/build/bodied-elements.js +35 -0
  26. package/lib/build/build-types.d.ts +29 -2
  27. package/lib/build/checks.d.ts +2 -0
  28. package/lib/build/checks.js +14 -0
  29. package/lib/build/clipping-registry.d.ts +3 -0
  30. package/lib/build/clipping-registry.js +39 -0
  31. package/lib/build/constants.d.ts +0 -1
  32. package/lib/build/constants.js +0 -1
  33. package/lib/build/entity-writer.js +4 -6
  34. package/lib/build/exact-bodies.d.ts +4 -0
  35. package/lib/build/exact-bodies.js +273 -0
  36. package/lib/build/fillings.js +1 -1
  37. package/lib/build/math.d.ts +3 -2
  38. package/lib/build/math.js +24 -16
  39. package/lib/build/measure.js +11 -11
  40. package/lib/build/moving.js +12 -11
  41. package/lib/build/openings.js +1 -1
  42. package/lib/build/outlines.d.ts +2 -0
  43. package/lib/build/outlines.js +14 -2
  44. package/lib/build/placement.js +4 -3
  45. package/lib/build/project.js +1 -1
  46. package/lib/build/quantities.js +13 -11
  47. package/lib/build/roof-clipping.js +5 -5
  48. package/lib/build/roofs.js +17 -16
  49. package/lib/build/site.js +9 -13
  50. package/lib/build/slab-openings.js +4 -4
  51. package/lib/build/slabs-columns-beams.js +16 -19
  52. package/lib/build/solids.js +3 -2
  53. package/lib/build/spaces.js +8 -6
  54. package/lib/build/spatial.js +1 -1
  55. package/lib/build/wall-edits.js +21 -15
  56. package/lib/build/wall-geometry.d.ts +2 -1
  57. package/lib/build/wall-geometry.js +48 -18
  58. package/lib/build/wall-parameters.js +7 -3
  59. package/lib/build/walls.js +15 -8
  60. package/lib/geometry/advanced.js +12 -13
  61. package/lib/geometry/curves.d.ts +2 -1
  62. package/lib/geometry/curves.js +27 -10
  63. package/lib/geometry/edges.js +6 -9
  64. package/lib/geometry/elements.d.ts +1 -1
  65. package/lib/geometry/elements.js +22 -5
  66. package/lib/geometry/exact-brep.constants.d.ts +1 -0
  67. package/lib/geometry/exact-brep.constants.js +1 -0
  68. package/lib/geometry/exact-brep.d.ts +11 -0
  69. package/lib/geometry/exact-brep.js +371 -0
  70. package/lib/geometry/faceted.d.ts +1 -0
  71. package/lib/geometry/faceted.js +20 -8
  72. package/lib/geometry/geometry-types.d.ts +9 -1
  73. package/lib/geometry/items.d.ts +2 -0
  74. package/lib/geometry/items.js +34 -5
  75. package/lib/geometry/operators.js +1 -1
  76. package/lib/geometry/profiles.js +9 -5
  77. package/lib/geometry/surfaces.constants.d.ts +1 -0
  78. package/lib/geometry/surfaces.constants.js +1 -0
  79. package/lib/geometry/surfaces.d.ts +1 -1
  80. package/lib/geometry/surfaces.js +8 -6
  81. package/lib/geometry/swept-solids.constants.d.ts +1 -0
  82. package/lib/geometry/swept-solids.constants.js +1 -0
  83. package/lib/geometry/swept-solids.js +22 -12
  84. package/lib/model/io.js +1 -1
  85. package/lib/model/owner-history.d.ts +2 -0
  86. package/lib/model/owner-history.js +101 -0
  87. package/lib/model/snapshot.d.ts +1 -0
  88. package/lib/model/snapshot.js +4 -0
  89. package/lib/model/transaction.js +19 -10
  90. package/lib/model/upgrade-rows.d.ts +26 -0
  91. package/lib/model/upgrade-rows.js +240 -0
  92. package/lib/model/upgrade-types.d.ts +9 -0
  93. package/lib/model/upgrade-types.js +1 -0
  94. package/lib/model/upgrade.js +20 -7
  95. package/lib/schema/registry.js +1 -1
  96. package/package.json +2 -3
@@ -1,5 +1,7 @@
1
- import { signedVolumeOf } from "@bitbybit-dev/base/lib/api/services/helpers/mesh-measures";
2
- import { newellNormal, triangulateFace } from "@bitbybit-dev/base/lib/api/services/helpers/triangulation";
1
+ import { signedVolumeOf } from "@bitbybit-dev/base/lib/api/services/helpers/mesh/mesh-measures";
2
+ import { windingRepairs } from "@bitbybit-dev/base/lib/api/services/helpers/mesh/mesh-orientation";
3
+ import { newellNormal, triangulateFace } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/triangulation";
4
+ import { length3 } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/vectors";
3
5
  import { POINT3_SIZE } from "../build/constants";
4
6
  import { numbersOf } from "../build/placement";
5
7
  import { isList, isReference } from "../step/values";
@@ -141,7 +143,7 @@ export class MeshCollector {
141
143
  loops.push(vertices);
142
144
  }
143
145
  if (outer < 0) {
144
- const spans = loops.map((loop) => Math.hypot(...newellNormal(this.positions, loop)));
146
+ const spans = loops.map((loop) => length3(newellNormal(this.positions, loop)));
145
147
  outer = spans.indexOf(Math.max(...spans));
146
148
  }
147
149
  this.add(triangulateFace(this.positions, [(_b = loops[outer]) !== null && _b !== void 0 ? _b : [], ...loops.filter((_, at) => at !== outer)]));
@@ -202,13 +204,23 @@ export class MeshCollector {
202
204
  }
203
205
  }
204
206
  orient(first, sense) {
205
- if (sense === UNORIENTED || signedVolumeOf(this.positions, this.indices, first) * sense >= 0) {
207
+ if (sense === UNORIENTED) {
206
208
  return;
207
209
  }
208
- for (let at = first; at < this.indices.length; at += POINT3_SIZE) {
209
- const second = this.indices[at + 1];
210
- this.indices[at + 1] = this.indices[at + 2];
211
- this.indices[at + 2] = second;
210
+ windingRepairs(this.positions, this.indices, first).forEach((flip, triangle) => {
211
+ if (flip === 1) {
212
+ this.turnOver(first + triangle * POINT3_SIZE);
213
+ }
214
+ });
215
+ if (signedVolumeOf(this.positions, this.indices, first) * sense < 0) {
216
+ for (let at = first; at < this.indices.length; at += POINT3_SIZE) {
217
+ this.turnOver(at);
218
+ }
212
219
  }
213
220
  }
221
+ turnOver(at) {
222
+ const second = this.indices[at + 1];
223
+ this.indices[at + 1] = this.indices[at + 2];
224
+ this.indices[at + 2] = second;
225
+ }
214
226
  }
@@ -1,5 +1,5 @@
1
1
  import type { Base } from "@bitbybit-dev/base";
2
- import type { FrameAxes } from "@bitbybit-dev/base/lib/api/services/helpers/frame-axes";
2
+ import type { FrameAxes } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/frame-axes";
3
3
  import type * as Inputs from "../api/inputs";
4
4
  export type ProfileRegion = PolygonRegion | CircleRegion | CompositeRegion;
5
5
  export interface PolygonRegion {
@@ -38,6 +38,10 @@ export interface CurveTrim {
38
38
  readonly point: Base.Point3 | undefined;
39
39
  readonly parameter: number | undefined;
40
40
  }
41
+ export interface SweepBound {
42
+ readonly value: number;
43
+ readonly byLength: boolean;
44
+ }
41
45
  export interface ParametricSurface {
42
46
  readonly periods: readonly [number | undefined, number | undefined];
43
47
  point(u: number, v: number): Base.Point3;
@@ -101,3 +105,7 @@ export interface PartGroup {
101
105
  readonly rgba: readonly number[] | undefined;
102
106
  readonly entries: PartEntry[];
103
107
  }
108
+ export interface BrepEdgeEnds {
109
+ readonly start: Base.Point3;
110
+ readonly end: Base.Point3;
111
+ }
@@ -11,6 +11,7 @@ export declare class ItemConverter {
11
11
  private readonly representations;
12
12
  private readonly itemColours;
13
13
  private readonly solids;
14
+ private exact;
14
15
  constructor(model: ModelSnapshot, builder: RecipeBuilder, reach: number);
15
16
  representation(representation: number): number;
16
17
  parts(representation: number): readonly RecipePart[];
@@ -27,6 +28,7 @@ export declare class ItemConverter {
27
28
  private groupNode;
28
29
  private mapped;
29
30
  private mappedParts;
31
+ private advancedBreps;
30
32
  private meshNode;
31
33
  private meshOf;
32
34
  private facetedBrep;
@@ -1,6 +1,6 @@
1
- import { WORLD_AXES, axesToMatrix, vectorToLocal } from "@bitbybit-dev/base/lib/api/services/helpers/frame-axes";
2
- import { add3, length3, scale3 } from "@bitbybit-dev/base/lib/api/services/helpers/vectors";
3
- import { wound2 } from "@bitbybit-dev/base/lib/api/services/helpers/polygons";
1
+ import { WORLD_AXES, axesToMatrix, vectorToLocal } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/frame-axes";
2
+ import { add3, length3, scale3 } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/vectors";
3
+ import { wound2 } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/polygons";
4
4
  import { PARALLEL_TOLERANCE } from "../build/constants";
5
5
  import { axisPlacementFrame, directionOf } from "../build/placement";
6
6
  import { isEnumeration, isList, isReference } from "../step/values";
@@ -12,6 +12,7 @@ import { operatorMatrix } from "./operators";
12
12
  import { profileRegion } from "./profiles";
13
13
  import { regionSolid } from "./regions";
14
14
  import { SweptSolids } from "./swept-solids";
15
+ import { ExactBreps } from "./exact-brep";
15
16
  const IDENTITY = axesToMatrix(WORLD_AXES);
16
17
  const Z_AXIS = [0, 0, 1];
17
18
  const PLAIN_HALF_SPACES = new Set(["IfcHalfSpaceSolid", "IfcBoxedHalfSpace"]);
@@ -22,6 +23,7 @@ const MESH_ITEMS = new Set([
22
23
  "IfcTriangulatedFaceSet", "IfcPolygonalFaceSet", "IfcFacetedBrep", "IfcFacetedBrepWithVoids", "IfcAdvancedBrep", "IfcAdvancedBrepWithVoids", "IfcFaceBasedSurfaceModel", "IfcShellBasedSurfaceModel",
23
24
  ]);
24
25
  const BREPS_WITH_VOIDS = new Set(["IfcFacetedBrepWithVoids", "IfcAdvancedBrepWithVoids"]);
26
+ const ADVANCED_BREPS = new Set(["IfcAdvancedBrep", "IfcAdvancedBrepWithVoids"]);
25
27
  function isIdentity(matrix) {
26
28
  return matrix.every((value, index) => value === IDENTITY[index]);
27
29
  }
@@ -122,11 +124,12 @@ export class ItemConverter {
122
124
  case "IfcPolygonalFaceSet":
123
125
  case "IfcFacetedBrep":
124
126
  case "IfcFacetedBrepWithVoids":
125
- case "IfcAdvancedBrep":
126
- case "IfcAdvancedBrepWithVoids":
127
127
  case "IfcFaceBasedSurfaceModel":
128
128
  case "IfcShellBasedSurfaceModel":
129
129
  return this.meshNode(item, this.meshOf(item));
130
+ case "IfcAdvancedBrep":
131
+ case "IfcAdvancedBrepWithVoids":
132
+ return this.advancedBreps(item, [item]);
130
133
  default:
131
134
  throw new UnsupportedGeometryError(`An ${type} is not supported yet`);
132
135
  }
@@ -241,6 +244,9 @@ export class ItemConverter {
241
244
  groupNode(representation, entries) {
242
245
  const meshes = entries.flatMap((entry) => { var _a; return ("item" in entry && MESH_ITEMS.has((_a = this.model.typeOf(entry.item)) !== null && _a !== void 0 ? _a : "") ? [entry.item] : []); });
243
246
  if (entries.length > 1 && meshes.length === entries.length) {
247
+ if (meshes.every((item) => { var _a; return ADVANCED_BREPS.has((_a = this.model.typeOf(item)) !== null && _a !== void 0 ? _a : ""); })) {
248
+ return this.advancedBreps(representation, meshes);
249
+ }
244
250
  return this.meshNode(representation, concatenated(meshes.map((item) => this.meshOf(item))));
245
251
  }
246
252
  return this.joined(entries.map((entry) => ("item" in entry ? this.item(entry.item) : entry.node)));
@@ -268,6 +274,29 @@ export class ItemConverter {
268
274
  const matrix = operatorMatrix(this.model, target.ref);
269
275
  return isIdentity(matrix) ? shared : shared.map((part) => ({ rgba: part.rgba, node: this.builder.node({ op: "transform", of: part.node, matrix }) }));
270
276
  }
277
+ advancedBreps(owner, items) {
278
+ var _a;
279
+ let fallback;
280
+ let meshFailure;
281
+ try {
282
+ fallback = this.meshNode(owner, concatenated(items.map((item) => this.meshOf(item))));
283
+ }
284
+ catch (thrown) {
285
+ if (!(thrown instanceof UnsupportedGeometryError)) {
286
+ throw thrown;
287
+ }
288
+ meshFailure = thrown;
289
+ }
290
+ (_a = this.exact) !== null && _a !== void 0 ? _a : (this.exact = new ExactBreps(this.model, this.builder, this.curves));
291
+ const exact = this.exact.describe(items);
292
+ if (exact === undefined) {
293
+ if (fallback === undefined) {
294
+ throw meshFailure;
295
+ }
296
+ return fallback;
297
+ }
298
+ return this.builder.node(fallback === undefined ? exact : Object.assign(Object.assign({}, exact), { fallback }));
299
+ }
271
300
  meshNode(item, mesh) {
272
301
  if (!mesh.indices.length) {
273
302
  throw new UnsupportedGeometryError(`#${item} holds no faces with an area`);
@@ -1,4 +1,4 @@
1
- import { cross3, dot3, length3, scale3, subtract3 } from "@bitbybit-dev/base/lib/api/services/helpers/vectors";
1
+ import { cross3, dot3, length3, scale3, subtract3 } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/vectors";
2
2
  import { PARALLEL_TOLERANCE } from "../build/constants";
3
3
  import { directionOf, pointOf } from "../build/placement";
4
4
  import { isReference } from "../step/values";
@@ -1,4 +1,4 @@
1
- import { roundedCorners2, wound2 } from "@bitbybit-dev/base/lib/api/services/helpers/polygons";
1
+ import { roundedCorners2, wound2 } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/polygons";
2
2
  import { axisPlacementFrame } from "../build/placement";
3
3
  import { radiansPerUnit } from "../build/project";
4
4
  import { isList, isReference } from "../step/values";
@@ -6,6 +6,8 @@ import { arcSegments } from "./curves";
6
6
  import { UnsupportedGeometryError } from "./errors";
7
7
  import { placedOnPlan } from "../build/math";
8
8
  import { operatorMatrix } from "./operators";
9
+ import { dot2, length2 } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/vectors";
10
+ import { movedCoordinate } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/matrices";
9
11
  const FULL_TURN = 2 * Math.PI;
10
12
  const SIMILARITY_TOLERANCE = 1e-9;
11
13
  const MIRROR_ABOUT_Y = [-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
@@ -158,11 +160,13 @@ function ellipse(model, profile) {
158
160
  return Array.from({ length: segments }, (_, at) => corner(a * Math.cos((FULL_TURN * at) / segments), b * Math.sin((FULL_TURN * at) / segments)));
159
161
  }
160
162
  function onPlan(matrix, [x, y]) {
161
- return [matrix[0] * x + matrix[4] * y + matrix[12], matrix[1] * x + matrix[5] * y + matrix[13]];
163
+ return [movedCoordinate(matrix, x, y, 0, 0), movedCoordinate(matrix, x, y, 0, 1)];
162
164
  }
163
165
  function isSimilarity(matrix) {
164
- const scale = Math.hypot(matrix[0], matrix[1]);
165
- return Math.abs(Math.hypot(matrix[4], matrix[5]) - scale) <= SIMILARITY_TOLERANCE * scale && Math.abs(matrix[0] * matrix[4] + matrix[1] * matrix[5]) <= SIMILARITY_TOLERANCE * scale * scale;
166
+ const x = [matrix[0], matrix[1]];
167
+ const y = [matrix[4], matrix[5]];
168
+ const scale = length2(x);
169
+ return Math.abs(length2(y) - scale) <= SIMILARITY_TOLERANCE * scale && Math.abs(dot2(x, y)) <= SIMILARITY_TOLERANCE * scale * scale;
166
170
  }
167
171
  function circlePoints(center, radius) {
168
172
  const segments = arcSegments(FULL_TURN);
@@ -174,7 +178,7 @@ function transformedRegion(region, matrix) {
174
178
  return { kind: "composite", parts: region.parts.map((part) => transformedRegion(part, matrix)) };
175
179
  case "circle":
176
180
  if (isSimilarity(matrix)) {
177
- const scale = Math.hypot(matrix[0], matrix[1]);
181
+ const scale = length2([matrix[0], matrix[1]]);
178
182
  return { kind: "circle", center: onPlan(matrix, region.center), radius: region.radius * scale, innerRadius: region.innerRadius * scale };
179
183
  }
180
184
  return transformedRegion({ kind: "polygon", outer: circlePoints(region.center, region.radius), holes: region.innerRadius > 0 ? [circlePoints(region.center, region.innerRadius)] : [] }, matrix);
@@ -14,4 +14,5 @@ export declare const FIT_PROBES = 8;
14
14
  export declare const FIT_TOLERANCE = 0.000001;
15
15
  export declare const CUT_SAMPLES = 64;
16
16
  export declare const CUT_TURN: number;
17
+ export declare const CUT_SLACK = 1e-9;
17
18
  export declare const POLE_RATIO = 1e-9;
@@ -14,4 +14,5 @@ export const FIT_PROBES = 8;
14
14
  export const FIT_TOLERANCE = 1e-6;
15
15
  export const CUT_SAMPLES = 64;
16
16
  export const CUT_TURN = (2 * Math.PI) / 32;
17
+ export const CUT_SLACK = 1e-9;
17
18
  export const POLE_RATIO = 1e-9;
@@ -1,4 +1,4 @@
1
- import { type FrameAxes } from "@bitbybit-dev/base/lib/api/services/helpers/frame-axes";
1
+ import { type FrameAxes } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/frame-axes";
2
2
  import type { ModelSnapshot } from "../model/snapshot";
3
3
  import { CurveSampler } from "./curves";
4
4
  import type { ParametricSurface } from "./geometry-types";
@@ -1,6 +1,6 @@
1
- import { WORLD_AXES, pointToLocal, pointToWorld, vectorToWorld } from "@bitbybit-dev/base/lib/api/services/helpers/frame-axes";
2
- import { expandedKnots, knotDomain, nurbsSurfacePoint } from "@bitbybit-dev/base/lib/api/services/helpers/nurbs";
3
- import { add3, cross3, dot3, length3, scale3, subtract3 } from "@bitbybit-dev/base/lib/api/services/helpers/vectors";
1
+ import { WORLD_AXES, pointToLocal, pointToWorld, vectorToWorld } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/frame-axes";
2
+ import { expandedKnots, knotDomain, nurbsSurfacePoint } from "@bitbybit-dev/base/lib/api/services/helpers/curves/nurbs";
3
+ import { add3, cross3, distance3, dot3, length2, length3, scale3, subtract3 } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/vectors";
4
4
  import { axisPlacementFrame, directionOf, pointOf } from "../build/placement";
5
5
  import { isList, isReference } from "../step/values";
6
6
  import { CurveSampler } from "./curves";
@@ -87,7 +87,7 @@ function sphere(frame, radius) {
87
87
  point: (u, v) => pointToWorld(frame, [radius * Math.cos(v) * Math.cos(u), radius * Math.cos(v) * Math.sin(u), radius * Math.sin(v)]),
88
88
  parameters: (point) => {
89
89
  const [x, y, z] = pointToLocal(frame, point);
90
- const across = Math.hypot(x, y);
90
+ const across = length2([x, y]);
91
91
  return [across <= POLE_RATIO * radius ? Number.NaN : Math.atan2(y, x), Math.atan2(z, across)];
92
92
  },
93
93
  pole: (axis, side) => (axis === 1 ? (side * Math.PI) / 2 : undefined),
@@ -102,7 +102,7 @@ function torus(frame, major, minor) {
102
102
  },
103
103
  parameters: (point) => {
104
104
  const [x, y, z] = pointToLocal(frame, point);
105
- return [Math.atan2(y, x), Math.atan2(z, Math.hypot(x, y) - major)];
105
+ return [Math.atan2(y, x), Math.atan2(z, length2([x, y]) - major)];
106
106
  },
107
107
  pole: noPole,
108
108
  };
@@ -190,7 +190,9 @@ function splineSurface(model, surface, divided) {
190
190
  const clampV = (v) => into(v, v0, v1, closedV);
191
191
  const point = (u, v) => nurbsSurfacePoint([uDegree, vDegree], net, weights, [uKnots, vKnots], clampU(u), clampV(v));
192
192
  const corners = net.flat();
193
- const size = Math.hypot(...[0, 1, 2].map((axis) => Math.max(...corners.map((corner) => corner[axis])) - Math.min(...corners.map((corner) => corner[axis]))));
193
+ const lowest = (axis) => Math.min(...corners.map((corner) => corner[axis]));
194
+ const highest = (axis) => Math.max(...corners.map((corner) => corner[axis]));
195
+ const size = distance3([highest(0), highest(1), highest(2)], [lowest(0), lowest(1), lowest(2)]);
194
196
  const accepted = size * FIT_RATIO;
195
197
  const seed = (target) => {
196
198
  let best = [u0, v0];
@@ -2,6 +2,7 @@ import type { Base } from "@bitbybit-dev/base";
2
2
  export declare const FULL_TURN: number;
3
3
  export declare const TURN_SLACK = 1e-9;
4
4
  export declare const PARAMETER_RATIO = 0.000001;
5
+ export declare const LENGTH_MEASURE = "IFCLENGTHMEASURE";
5
6
  export declare const IDENTITY_MATRIX: Base.TransformMatrix;
6
7
  export declare const Y_TO_Z: Base.TransformMatrix;
7
8
  export declare const PYRAMID_TRIANGLES: readonly number[];
@@ -1,6 +1,7 @@
1
1
  export const FULL_TURN = 2 * Math.PI;
2
2
  export const TURN_SLACK = 1e-9;
3
3
  export const PARAMETER_RATIO = 1e-6;
4
+ export const LENGTH_MEASURE = "IFCLENGTHMEASURE";
4
5
  export const IDENTITY_MATRIX = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
5
6
  export const Y_TO_Z = [1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1];
6
7
  export const PYRAMID_TRIANGLES = [0, 2, 1, 0, 3, 2, 0, 1, 4, 1, 2, 4, 2, 3, 4, 3, 0, 4];
@@ -1,15 +1,15 @@
1
- import { axesToMatrix, vectorToWorld } from "@bitbybit-dev/base/lib/api/services/helpers/frame-axes";
2
- import { pathTangents, roundedPath3, sweepMatrices, transportedAxes } from "@bitbybit-dev/base/lib/api/services/helpers/paths";
3
- import { cross3, dot3, length3, scale3, subtract3 } from "@bitbybit-dev/base/lib/api/services/helpers/vectors";
1
+ import { axesToMatrix, vectorToWorld } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/frame-axes";
2
+ import { pathTangents, roundedPath3, sweepMatrices, transportedAxes } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/paths";
3
+ import { cross3, dot3, length3, scale2, scale3, subtract3 } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/vectors";
4
4
  import { PARALLEL_TOLERANCE } from "../build/constants";
5
5
  import { axisPlacementFrame, directionOf, pointOf } from "../build/placement";
6
6
  import { radiansPerUnit } from "../build/project";
7
- import { isReference } from "../step/values";
7
+ import { isReference, isTyped } from "../step/values";
8
8
  import { arcSegments } from "./curves";
9
9
  import { UnsupportedGeometryError } from "./errors";
10
10
  import { profileRegion } from "./profiles";
11
11
  import { profileNode, regionSolid } from "./regions";
12
- import { FULL_TURN, IDENTITY_MATRIX, PARAMETER_RATIO, PYRAMID_TRIANGLES, TURN_SLACK, Y_TO_Z } from "./swept-solids.constants";
12
+ import { FULL_TURN, IDENTITY_MATRIX, LENGTH_MEASURE, PARAMETER_RATIO, PYRAMID_TRIANGLES, TURN_SLACK, Y_TO_Z } from "./swept-solids.constants";
13
13
  const Z_AXIS = [0, 0, 1];
14
14
  const NO_AXIS = [0, 0, 0];
15
15
  function squared(vector, to) {
@@ -17,6 +17,12 @@ function squared(vector, to) {
17
17
  const length = length3(across);
18
18
  return length > PARALLEL_TOLERANCE ? scale3(across, 1 / length) : undefined;
19
19
  }
20
+ function boundOf(value) {
21
+ if (typeof value === "number") {
22
+ return { value, byLength: false };
23
+ }
24
+ return isTyped(value) && typeof value.value === "number" ? { value: value.value, byLength: value.type.toUpperCase() === LENGTH_MEASURE } : undefined;
25
+ }
20
26
  function moved(offset) {
21
27
  return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, offset[0], offset[1], offset[2], 1];
22
28
  }
@@ -45,7 +51,7 @@ export class SweptSolids {
45
51
  throw new UnsupportedGeometryError(`#${item} turns by an angle that is not above zero and at most a whole turn`);
46
52
  }
47
53
  const solid = regionSolid(this.builder, region, this.flat(item, (profile) => this.builder.node({
48
- op: "revolve", profile, origin: [origin[0], origin[1]], direction: [sign * direction[0], sign * direction[1]], angle,
54
+ op: "revolve", profile, origin: [origin[0], origin[1]], direction: scale2([direction[0], direction[1]], sign), angle,
49
55
  })));
50
56
  return this.placed(item, solid);
51
57
  }
@@ -190,6 +196,7 @@ export class SweptSolids {
190
196
  return isReference(directrix) ? this.curves.endTangents(directrix.ref) : [undefined, undefined];
191
197
  }
192
198
  sweptPath(item) {
199
+ var _a, _b, _c;
193
200
  const directrix = this.model.attribute(item, "Directrix");
194
201
  if (!isReference(directrix)) {
195
202
  throw new UnsupportedGeometryError(`#${item} has no directrix`);
@@ -198,14 +205,17 @@ export class SweptSolids {
198
205
  if (points.length < 2) {
199
206
  throw new UnsupportedGeometryError(`#${item} sweeps along a directrix of no length`);
200
207
  }
201
- const start = this.model.attribute(item, "StartParam");
202
- const end = this.model.attribute(item, "EndParam");
203
- if (start === null && end === null) {
208
+ const start = boundOf(this.model.attribute(item, "StartParam"));
209
+ const end = boundOf(this.model.attribute(item, "EndParam"));
210
+ if (start === undefined && end === undefined) {
204
211
  return points;
205
212
  }
206
- const span = this.curves.parameterSpan(directrix.ref);
207
- const from = typeof start === "number" ? start : 0;
208
- const to = typeof end === "number" ? end : span;
213
+ const byLength = (_a = start === null || start === void 0 ? void 0 : start.byLength) !== null && _a !== void 0 ? _a : end.byLength;
214
+ const span = start !== undefined && end !== undefined && start.byLength !== end.byLength
215
+ ? undefined
216
+ : byLength ? this.curves.lengthSpan(directrix.ref) : this.curves.parameterSpan(directrix.ref);
217
+ const from = (_b = start === null || start === void 0 ? void 0 : start.value) !== null && _b !== void 0 ? _b : 0;
218
+ const to = (_c = end === null || end === void 0 ? void 0 : end.value) !== null && _c !== void 0 ? _c : span;
209
219
  if (span !== undefined && to !== undefined && Math.abs(to - from - span) <= PARAMETER_RATIO * Math.max(1, span)) {
210
220
  return points;
211
221
  }
package/lib/model/io.js CHANGED
@@ -1,4 +1,4 @@
1
- import { isZip, zipEntries, zipEntryData } from "@bitbybit-dev/base/lib/api/services/helpers/zip";
1
+ import { isZip, zipEntries, zipEntryData } from "@bitbybit-dev/base/lib/api/services/helpers/files/zip";
2
2
  import { describeSupportedSchemas, readingSchemaFor, schemaNamed } from "../schema/registry";
3
3
  import { StepSyntaxError } from "../step/errors";
4
4
  import { encoderFor } from "../step/encoder";
@@ -0,0 +1,2 @@
1
+ import type { IfcTransaction } from "./transaction";
2
+ export declare function stampOwnerHistories(tx: IfcTransaction, created: readonly number[], changed: readonly number[]): void;
@@ -0,0 +1,101 @@
1
+ import { GlobalCDNProvider } from "@bitbybit-dev/base";
2
+ import { enumValue, isReference, ref } from "../step/values";
3
+ const OWNER_HISTORY = "IfcOwnerHistory";
4
+ const ROOT = "IfcRoot";
5
+ const PLACEMENT = "IfcObjectPlacement";
6
+ const APPLICATION = "IfcApplication";
7
+ const ORGANIZATION = "IfcOrganization";
8
+ const PERSON_AND_ORGANIZATION = "IfcPersonAndOrganization";
9
+ const IDENTIFIER = "@bitbybit-dev/ifc";
10
+ const DEVELOPER = "Bit By Bit Developers";
11
+ const VERSION_MARK = "/v";
12
+ const MILLISECONDS_PER_SECOND = 1000;
13
+ const UNSTAMPED = -1;
14
+ class Stamper {
15
+ constructor(tx, user) {
16
+ this.tx = tx;
17
+ this.user = user;
18
+ this.modified = new Map();
19
+ this.now = Math.floor(Date.now() / MILLISECONDS_PER_SECOND);
20
+ }
21
+ stampAdded(id) {
22
+ var _a;
23
+ if (!isReference(this.tx.attribute(id, "OwnerHistory"))) {
24
+ (_a = this.added) !== null && _a !== void 0 ? _a : (this.added = this.history({ OwningUser: ref(this.user), OwningApplication: ref(this.app()), CreationDate: this.now }, "ADDED"));
25
+ this.tx.update(id, { OwnerHistory: ref(this.added) });
26
+ }
27
+ }
28
+ stampModified(id) {
29
+ const before = this.tx.base.attribute(id, "OwnerHistory");
30
+ const now = this.tx.attribute(id, "OwnerHistory");
31
+ if (isReference(before) !== isReference(now) || (isReference(before) && isReference(now) && before.ref !== now.ref)) {
32
+ return;
33
+ }
34
+ const previous = isReference(before) ? before.ref : UNSTAMPED;
35
+ let history = this.modified.get(previous);
36
+ if (history === undefined) {
37
+ history = this.history(previous === UNSTAMPED
38
+ ? { OwningUser: ref(this.user), OwningApplication: ref(this.app()), CreationDate: this.now }
39
+ : {
40
+ OwningUser: this.tx.attribute(previous, "OwningUser"),
41
+ OwningApplication: this.tx.attribute(previous, "OwningApplication"),
42
+ State: this.tx.attribute(previous, "State"),
43
+ CreationDate: this.tx.attribute(previous, "CreationDate"),
44
+ }, "MODIFIED");
45
+ this.modified.set(previous, history);
46
+ }
47
+ this.tx.update(id, { OwnerHistory: ref(history) });
48
+ }
49
+ history(owner, action) {
50
+ return this.tx.create(OWNER_HISTORY, Object.assign(Object.assign({}, owner), { ChangeAction: enumValue(action), LastModifiedDate: this.now, LastModifyingUser: ref(this.user), LastModifyingApplication: ref(this.app()) }));
51
+ }
52
+ app() {
53
+ var _a;
54
+ if (this.application === undefined) {
55
+ const known = this.tx.byType(APPLICATION).find((application) => this.tx.valueOf(application, "ApplicationIdentifier") === IDENTIFIER);
56
+ this.application = (_a = known === null || known === void 0 ? void 0 : known.id) !== null && _a !== void 0 ? _a : this.tx.create(APPLICATION, {
57
+ ApplicationDeveloper: ref(this.tx.create(ORGANIZATION, { Name: DEVELOPER })),
58
+ Version: GlobalCDNProvider.BITBYBIT_CDN_URL.slice(GlobalCDNProvider.BITBYBIT_CDN_URL.lastIndexOf(VERSION_MARK) + VERSION_MARK.length),
59
+ ApplicationFullName: IDENTIFIER,
60
+ ApplicationIdentifier: IDENTIFIER,
61
+ });
62
+ }
63
+ return this.application;
64
+ }
65
+ }
66
+ function isA(tx, id, type) {
67
+ return tx.schema.isSubtypeOf(tx.entity(id).type, type);
68
+ }
69
+ function rootsChanged(tx, changed) {
70
+ const roots = new Set(changed.filter((id) => isA(tx, id, ROOT)));
71
+ const parts = changed.filter((id) => !roots.has(id));
72
+ const seen = new Set(changed);
73
+ for (let index = 0; index < parts.length; index++) {
74
+ const part = parts[index];
75
+ const placement = isA(tx, part, PLACEMENT);
76
+ for (const user of tx.referencesTo(part)) {
77
+ if (!seen.has(user) && !(placement && isA(tx, user, PLACEMENT))) {
78
+ seen.add(user);
79
+ if (isA(tx, user, ROOT)) {
80
+ roots.add(user);
81
+ }
82
+ else {
83
+ parts.push(user);
84
+ }
85
+ }
86
+ }
87
+ }
88
+ return [...roots].filter((id) => id < tx.base.nextId).sort((a, b) => a - b);
89
+ }
90
+ export function stampOwnerHistories(tx, created, changed) {
91
+ if (!tx.base.hasType(OWNER_HISTORY)) {
92
+ return;
93
+ }
94
+ const user = tx.byType(PERSON_AND_ORGANIZATION)[0];
95
+ if (user === undefined) {
96
+ return;
97
+ }
98
+ const stamper = new Stamper(tx, user.id);
99
+ created.filter((id) => isA(tx, id, ROOT)).forEach((id) => stamper.stampAdded(id));
100
+ rootsChanged(tx, changed).forEach((id) => stamper.stampModified(id));
101
+ }
@@ -27,6 +27,7 @@ export declare class ModelSnapshot extends EntityLookup implements IfcModel {
27
27
  typeOf(id: number): string | undefined;
28
28
  ids(): readonly number[];
29
29
  byType(type: string, includeSubtypes?: boolean): IfcEntity[];
30
+ hasType(type: string): boolean;
30
31
  globalIdOwners(globalId: string): number[];
31
32
  byGlobalId(globalId: string): number | undefined;
32
33
  referencesTo(id: number): readonly number[];
@@ -104,6 +104,10 @@ export class ModelSnapshot extends EntityLookup {
104
104
  }
105
105
  return ids.sort(ascending).map((id) => this.entity(id));
106
106
  }
107
+ hasType(type) {
108
+ const indexes = this.overlayIndexes();
109
+ return this.schema.subtypesOf(type).some((name) => { var _a, _b, _c, _d; return ((_b = (_a = indexes.idsOfType(name)) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : 0) > 0 || ((_d = (_c = this.source) === null || _c === void 0 ? void 0 : _c.idsOfType(name)) !== null && _d !== void 0 ? _d : NO_IDS).some((id) => !this.overlay.has(id)); });
110
+ }
107
111
  globalIdOwners(globalId) {
108
112
  var _a, _b, _c;
109
113
  const owners = [...((_a = this.overlayIndexes().ownersOfGlobalId(globalId)) !== null && _a !== void 0 ? _a : NO_IDS)];
@@ -4,11 +4,13 @@ import { DERIVED, isDerived, isList, isReference, referencesIn } from "../step/v
4
4
  import { PRUNABLE_TYPES } from "./constants";
5
5
  import { EntityLookup } from "./entity-lookup";
6
6
  import { automaticGlobalId, keyGlobalId, randomGlobalId, structureGlobalId } from "./guid";
7
+ import { stampOwnerHistories } from "./owner-history";
7
8
  import { checkReferences } from "./references";
8
9
  import { ModelSnapshot } from "./snapshot";
9
10
  const ascending = (a, b) => a - b;
10
11
  const STYLED_ITEM = "IfcStyledItem";
11
12
  const LAYER_ASSIGNMENT = "IfcPresentationLayerAssignment";
13
+ const SHAPE_ASPECT = "IfcShapeAspect";
12
14
  export class IfcTransaction extends EntityLookup {
13
15
  constructor(base, keySeed = base.keySeed) {
14
16
  super();
@@ -19,9 +21,7 @@ export class IfcTransaction extends EntityLookup {
19
21
  this.issued = 0;
20
22
  this.committed = false;
21
23
  if (!base.editable) {
22
- throw new Error(base.schemaName === base.schema.name
23
- ? `This ${base.schemaName} model can be shown and queried but not changed; changes are made to IFC4 models`
24
- : `This ${base.schemaName} file is read through the ${base.schema.name} schema, so it can be shown and queried but not changed`);
24
+ throw new Error(`This ${base.schemaName} file is read through the ${base.schema.name} schema, so it can be shown and queried but not changed`);
25
25
  }
26
26
  this.base = base;
27
27
  this.nextId = base.nextId;
@@ -130,8 +130,10 @@ export class IfcTransaction extends EntityLookup {
130
130
  }
131
131
  commit() {
132
132
  this.assertOpen();
133
- this.committed = true;
134
133
  this.pruneUnused();
134
+ const kept = [...this.changes.keys()].filter((id) => this.changes.get(id) !== null).sort(ascending);
135
+ stampOwnerHistories(this, kept.filter((id) => id >= this.base.nextId), kept.filter((id) => id < this.base.nextId));
136
+ this.committed = true;
135
137
  const overlay = this.base.overlay.withChanges([...this.changes].map(([id, entity]) => { var _a; return [id, entity === null && !((_a = this.base.source) === null || _a === void 0 ? void 0 : _a.has(id)) ? undefined : entity]; }));
136
138
  const next = new ModelSnapshot(Object.assign(Object.assign({}, this.base.parts), { overlay, nextId: this.nextId }));
137
139
  const inherited = this.base.releaseIndexes();
@@ -213,7 +215,7 @@ export class IfcTransaction extends EntityLookup {
213
215
  if (!users.every((user) => this.onlyPresents(user, id, removed))) {
214
216
  continue;
215
217
  }
216
- users.forEach((user) => this.letGo(user, id, removed));
218
+ users.forEach((user) => work.push(...this.letGo(user, id, removed)));
217
219
  removed.add(id);
218
220
  this.record(id, null);
219
221
  work.push(...entity.args.flatMap((arg) => referencesIn(arg)));
@@ -224,9 +226,10 @@ export class IfcTransaction extends EntityLookup {
224
226
  if (!entity) {
225
227
  return false;
226
228
  }
227
- if (this.schema.isSubtypeOf(entity.type, STYLED_ITEM)) {
228
- const item = this.attribute(user, "Item");
229
- return isReference(item) && item.ref === id && this.referencesTo(user).every((other) => removed.has(other));
229
+ const part = this.schema.isSubtypeOf(entity.type, STYLED_ITEM) ? "Item" : this.schema.isSubtypeOf(entity.type, SHAPE_ASPECT) ? "PartOfProductDefinitionShape" : undefined;
230
+ if (part !== undefined) {
231
+ const whole = this.attribute(user, part);
232
+ return isReference(whole) && whole.ref === id && this.referencesTo(user).every((other) => removed.has(other));
230
233
  }
231
234
  return this.schema.isSubtypeOf(entity.type, LAYER_ASSIGNMENT);
232
235
  }
@@ -235,7 +238,12 @@ export class IfcTransaction extends EntityLookup {
235
238
  if (this.schema.isSubtypeOf(entity.type, STYLED_ITEM)) {
236
239
  removed.add(user);
237
240
  this.record(user, null);
238
- return;
241
+ return [];
242
+ }
243
+ if (this.schema.isSubtypeOf(entity.type, SHAPE_ASPECT)) {
244
+ removed.add(user);
245
+ this.record(user, null);
246
+ return entity.args.flatMap((arg) => referencesIn(arg));
239
247
  }
240
248
  const position = this.schema.entity(entity.type).positions.get("AssignedItems");
241
249
  const assigned = entity.args[position];
@@ -243,8 +251,9 @@ export class IfcTransaction extends EntityLookup {
243
251
  if (!kept.length) {
244
252
  removed.add(user);
245
253
  this.record(user, null);
246
- return;
254
+ return [];
247
255
  }
248
256
  this.record(user, Object.assign(Object.assign({}, entity), { args: entity.args.map((arg, index) => (index === position ? kept : arg)) }));
257
+ return [];
249
258
  }
250
259
  }
@@ -0,0 +1,26 @@
1
+ import type { IfcAttributeInfo, IfcEntityInfo } from "../schema/schema-types";
2
+ import type { IfcEntity, IfcValue } from "../step/step-types";
3
+ import type { ModelSnapshot } from "./snapshot";
4
+ export declare class Ifc2x3Rows {
5
+ private readonly model;
6
+ readonly created: [number, IfcEntity][];
7
+ private nextId;
8
+ private issued;
9
+ constructor(model: ModelSnapshot);
10
+ get next(): number;
11
+ private get schema();
12
+ isDate(id: number): boolean;
13
+ restyled(entity: IfcEntity): IfcEntity;
14
+ surfaced(entity: IfcEntity): IfcEntity;
15
+ given(info: IfcEntityInfo, args: readonly IfcValue[]): readonly IfcValue[];
16
+ missing(info: IfcEntityInfo, entity: IfcEntity, attribute: IfcAttributeInfo): IfcValue | undefined;
17
+ converted(attribute: IfcAttributeInfo, entity: IfcEntity, value: IfcValue): IfcValue | undefined;
18
+ completed(info: IfcEntityInfo, entity: IfcEntity, args: IfcValue[]): IfcValue[];
19
+ private dated;
20
+ private enumerationTokens;
21
+ private flatNorth;
22
+ private enumerationFor;
23
+ private partsOf;
24
+ private offsetOf;
25
+ private globalId;
26
+ }