@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
@@ -0,0 +1,28 @@
1
+ import type { IfcModel } from "../../model/model-types";
2
+ import * as Inputs from "../inputs";
3
+ /**
4
+ * Elements of any kind whose body is given as data: exact boundary representations, such as an
5
+ * OpenCascade shape described with `occt.recipes.describe`, or triangle meshes.
6
+ * @beta
7
+ */
8
+ export declare class IFCElements {
9
+ private readonly recipes;
10
+ /**
11
+ * Adds an element of any class to a storey, its body written from a recipe: brep steps as
12
+ * advanced breps less their cavities, triangle steps as triangulated face sets.
13
+ *
14
+ * The body is scaled to the model's units; its roots may move and turn it, not scale or mirror
15
+ * it. Describe shapes with `ifcSurfaces` set.
16
+ * @param inputs - The model, the storey, the body, and the element's class, name, placement and material
17
+ * @returns A new model with the element
18
+ * @group create
19
+ * @shortname add element
20
+ * @drawable false
21
+ * @example
22
+ * ```typescript
23
+ * const body = await bitbybit.occt.recipes.describe({ shape: bracket, ifcSurfaces: true });
24
+ * model = await bitbybit.ifc.elements.add({ model, storey: "ground", body, type: "IfcFurniture", name: "Bracket", position: [2000, 1500, 0] });
25
+ * ```
26
+ */
27
+ add(inputs: Inputs.IFC.AddElementDto<IfcModel>): IfcModel;
28
+ }
@@ -0,0 +1,60 @@
1
+ import { Recipes, resolveDto } from "@bitbybit-dev/base";
2
+ import { millimetresPerUnit } from "../../build/project";
3
+ import { requirePoint, requireTurn } from "../../build/checks";
4
+ import { createBodiedElement } from "../../build/bodied-elements";
5
+ import { requireMaterial } from "../../build/materials";
6
+ import * as Inputs from "../inputs";
7
+ import { POINT3_SIZE } from "../../build/constants";
8
+ import { editModel, modelOf, resolveId } from "./service-support";
9
+ import { radiansOf } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/scalars";
10
+ /**
11
+ * Elements of any kind whose body is given as data: exact boundary representations, such as an
12
+ * OpenCascade shape described with `occt.recipes.describe`, or triangle meshes.
13
+ * @beta
14
+ */
15
+ export class IFCElements {
16
+ constructor() {
17
+ this.recipes = new Recipes();
18
+ }
19
+ /**
20
+ * Adds an element of any class to a storey, its body written from a recipe: brep steps as
21
+ * advanced breps less their cavities, triangle steps as triangulated face sets.
22
+ *
23
+ * The body is scaled to the model's units; its roots may move and turn it, not scale or mirror
24
+ * it. Describe shapes with `ifcSurfaces` set.
25
+ * @param inputs - The model, the storey, the body, and the element's class, name, placement and material
26
+ * @returns A new model with the element
27
+ * @group create
28
+ * @shortname add element
29
+ * @drawable false
30
+ * @example
31
+ * ```typescript
32
+ * const body = await bitbybit.occt.recipes.describe({ shape: bracket, ifcSurfaces: true });
33
+ * model = await bitbybit.ifc.elements.add({ model, storey: "ground", body, type: "IfcFurniture", name: "Bracket", position: [2000, 1500, 0] });
34
+ * ```
35
+ */
36
+ add(inputs) {
37
+ const resolved = resolveDto(Inputs.IFC.AddElementDto, inputs);
38
+ const model = modelOf(resolved.model);
39
+ const body = this.recipes.read({ recipe: resolved.body });
40
+ requirePoint(resolved.position, POINT3_SIZE, "position");
41
+ requireTurn(resolved.rotation, "rotation");
42
+ const storey = resolveId(model, resolved.storey, "IfcBuildingStorey", "storey");
43
+ const angle = radiansOf(resolved.rotation);
44
+ const [cos, sin] = [Math.cos(angle), Math.sin(angle)];
45
+ return editModel(model, (tx, writer) => {
46
+ createBodiedElement(tx, writer, {
47
+ storey,
48
+ id: resolved.id,
49
+ name: resolved.name,
50
+ type: resolved.type,
51
+ predefinedType: resolved.predefinedType,
52
+ objectType: resolved.objectType,
53
+ body,
54
+ scale: body.millimetresPerUnit / millimetresPerUnit(model),
55
+ frame: { origin: [...resolved.position], x: [cos, sin, 0], y: [-sin, cos, 0], z: [0, 0, 1] },
56
+ material: resolved.material === undefined ? undefined : requireMaterial(tx, resolved.material),
57
+ });
58
+ });
59
+ }
60
+ }
@@ -11,13 +11,13 @@ function described(memo, inputs) {
11
11
  if (elements !== undefined && !Array.isArray(elements)) {
12
12
  throw new TypeError("Expected the elements as a list of GlobalIds or ids");
13
13
  }
14
- const key = JSON.stringify([elements !== null && elements !== void 0 ? elements : null, inputs.groupByClass]);
14
+ const key = JSON.stringify([elements !== null && elements !== void 0 ? elements : null, inputs.groupByClass, inputs.propertySets]);
15
15
  const last = memo.get(model);
16
16
  if ((last === null || last === void 0 ? void 0 : last.key) === key) {
17
17
  return last.described;
18
18
  }
19
19
  const globalIds = (_a = inputs.elements) === null || _a === void 0 ? void 0 : _a.map((element) => selectedGlobalId(model, element));
20
- const result = modelRecipe(model, globalIds, millimetresPerUnit(model), lengthTolerance(model), inputs.groupByClass);
20
+ const result = modelRecipe(model, globalIds, millimetresPerUnit(model), lengthTolerance(model), inputs.groupByClass, inputs.propertySets);
21
21
  memo.set(model, { key, described: result });
22
22
  return result;
23
23
  }
@@ -82,6 +82,6 @@ export class IFCGeometry {
82
82
  * ```
83
83
  */
84
84
  unsupported(inputs) {
85
- return described(this.lastDescribed, Object.assign(Object.assign({}, inputs), { groupByClass: true })).problems;
85
+ return described(this.lastDescribed, Object.assign(Object.assign({}, inputs), { groupByClass: true, propertySets: false })).problems;
86
86
  }
87
87
  }
@@ -9,6 +9,7 @@ export * from "./windows";
9
9
  export * from "./slabs";
10
10
  export * from "./roofs";
11
11
  export * from "./site";
12
+ export * from "./elements";
12
13
  export * from "./columns";
13
14
  export * from "./beams";
14
15
  export * from "./members";
@@ -9,6 +9,7 @@ export * from "./windows";
9
9
  export * from "./slabs";
10
10
  export * from "./roofs";
11
11
  export * from "./site";
12
+ export * from "./elements";
12
13
  export * from "./columns";
13
14
  export * from "./beams";
14
15
  export * from "./members";
@@ -1,4 +1,4 @@
1
- import { requireFinite } from "../../build/checks";
1
+ import { requireTurn } from "../../build/checks";
2
2
  import { requireMaterial } from "../../build/materials";
3
3
  import * as Inputs from "../inputs";
4
4
  import { DEFAULT_MILLIMETRES } from "./defaults.constants";
@@ -25,5 +25,5 @@ export function memberMaterial(tx, name) {
25
25
  return name === undefined ? undefined : requireMaterial(tx, name);
26
26
  }
27
27
  export function finiteRotation(rotation) {
28
- requireFinite(rotation, "rotation in degrees");
28
+ requireTurn(rotation, "rotation");
29
29
  }
@@ -1,5 +1,5 @@
1
1
  import { resolveDto } from "@bitbybit-dev/base";
2
- import { WORLD_AXES, vectorToWorld } from "@bitbybit-dev/base/lib/api/services/helpers/frame-axes";
2
+ import { WORLD_AXES, vectorToWorld } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/frame-axes";
3
3
  import { textValue } from "../../step/values";
4
4
  import { createProject, DESIGN_TRANSFER_VIEW, millimetresPerUnit, projectOf, SCHEMA_FOR_NEW_MODELS } from "../../build/project";
5
5
  import { keyGlobalId } from "../../model/guid";
@@ -12,7 +12,7 @@ import { editModel, lengthTolerance, modelOf, oneOf, resolveId } from "./service
12
12
  import { PARALLEL_TOLERANCE, POINT3_SIZE } from "../../build/constants";
13
13
  import { moveElement } from "../../build/moving";
14
14
  import { removeObject } from "../../build/removal";
15
- import { requireFinite, requirePoint } from "../../build/checks";
15
+ import { requirePoint, requireTurn } from "../../build/checks";
16
16
  import { standingIn, storeyFrame, storeyOf, storeysOf } from "../../build/spatial";
17
17
  import { georeferenceOf } from "../../build/georeference";
18
18
  const LIBRARY = "@bitbybit-dev/ifc";
@@ -327,7 +327,7 @@ export class IFCModels {
327
327
  const resolved = resolveDto(Inputs.IFC.MoveElementDto, inputs);
328
328
  const model = modelOf(resolved.model);
329
329
  requirePoint(resolved.translation, POINT3_SIZE, "translation");
330
- requireFinite(resolved.rotation, "rotation in degrees");
330
+ requireTurn(resolved.rotation, "rotation");
331
331
  const element = resolveId(model, resolved.element, "IfcProduct", "element");
332
332
  const storey = storeyOf(model, element);
333
333
  const plan = storey === undefined ? WORLD_AXES : storeyFrame(model, storey);
@@ -1,6 +1,6 @@
1
1
  import { resolveDto } from "@bitbybit-dev/base";
2
- import { WORLD_AXES, pointToLocal, pointToWorld } from "@bitbybit-dev/base/lib/api/services/helpers/frame-axes";
3
- import { requireOutline } from "../../build/checks";
2
+ import { WORLD_AXES, pointToLocal, pointToWorld } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/frame-axes";
3
+ import { requireFinite, requireOutline } from "../../build/checks";
4
4
  import { createWallOpening, editWallOpening } from "../../build/openings";
5
5
  import { absoluteFrame, objectPlacementOf } from "../../build/placement";
6
6
  import { createSlabOpening } from "../../build/slab-openings";
@@ -35,16 +35,15 @@ export class IFCOpenings {
35
35
  const resolved = resolveDto(Inputs.IFC.AddOpeningDto, inputs);
36
36
  const model = modelOf(resolved.model);
37
37
  const wall = resolveId(model, resolved.wall, "IfcWall", "wall");
38
+ const offset = lengthIn(model, resolved.offset, DEFAULT_MILLIMETRES.openingOffset);
39
+ const width = lengthIn(model, resolved.width, DEFAULT_MILLIMETRES.openingWidth);
40
+ const height = lengthIn(model, resolved.height, DEFAULT_MILLIMETRES.openingHeight);
41
+ requireFinite(offset, "opening's offset");
42
+ requireFinite(resolved.sill, "opening's sill");
43
+ requireFinite(width, "opening's width");
44
+ requireFinite(height, "opening's height");
38
45
  return editModel(model, (tx, writer) => {
39
- createWallOpening(tx, writer, {
40
- wall,
41
- id: resolved.id,
42
- name: resolved.name,
43
- offset: lengthIn(model, resolved.offset, DEFAULT_MILLIMETRES.openingOffset),
44
- sill: resolved.sill,
45
- width: lengthIn(model, resolved.width, DEFAULT_MILLIMETRES.openingWidth),
46
- height: lengthIn(model, resolved.height, DEFAULT_MILLIMETRES.openingHeight),
47
- }, lengthTolerance(model));
46
+ createWallOpening(tx, writer, { wall, id: resolved.id, name: resolved.name, offset, sill: resolved.sill, width, height }, lengthTolerance(model));
48
47
  });
49
48
  }
50
49
  /**
@@ -65,6 +64,12 @@ export class IFCOpenings {
65
64
  const resolved = resolveDto(Inputs.IFC.EditOpeningDto, inputs);
66
65
  const model = modelOf(resolved.model);
67
66
  const element = resolveId(model, resolved.opening, "IfcElement", "opening");
67
+ const given = [[resolved.offset, "opening's offset"], [resolved.sill, "opening's sill"], [resolved.width, "opening's width"], [resolved.height, "opening's height"]];
68
+ given.forEach(([value, what]) => {
69
+ if (value !== undefined) {
70
+ requireFinite(value, what);
71
+ }
72
+ });
68
73
  return editModel(model, (tx, writer) => {
69
74
  editWallOpening(tx, writer, element, { offset: resolved.offset, sill: resolved.sill, width: resolved.width, height: resolved.height }, lengthTolerance(model));
70
75
  });
@@ -1,4 +1,4 @@
1
- import { resolveDto } from "@bitbybit-dev/base";
1
+ import { isRecord, resolveDto } from "@bitbybit-dev/base";
2
2
  import { addPropertySet, propertySetsOf, removePropertySet, removePropertyValues, setPropertyValues } from "../../build/properties";
3
3
  import * as Inputs from "../inputs";
4
4
  import { editModel, modelOf, resolveId } from "./service-support";
@@ -8,10 +8,11 @@ function propertySpecs(properties) {
8
8
  }
9
9
  return properties.map((property) => {
10
10
  const full = resolveDto(Inputs.IFC.PropertyDto, property);
11
- if (typeof full.value !== "string" && typeof full.value !== "boolean" && !(typeof full.value === "number" && Number.isFinite(full.value))) {
11
+ const value = isRecord(property) && property["value"] === "" ? "" : full.value;
12
+ if (typeof value !== "string" && typeof value !== "boolean" && !(typeof value === "number" && Number.isFinite(value))) {
12
13
  throw new TypeError(`The property '${full.name}' needs a text, a finite number, or true or false`);
13
14
  }
14
- return { name: full.name, value: full.value, type: full.type };
15
+ return { name: full.name, value, type: full.type };
15
16
  });
16
17
  }
17
18
  /**
@@ -30,6 +30,8 @@ export class IFCSite {
30
30
  requireOutline(resolved.outline, "outline");
31
31
  ((_a = resolved.holes) !== null && _a !== void 0 ? _a : []).forEach((hole, index) => requireOutline(hole, `hole ${index}`));
32
32
  requireFinite(resolved.elevation, "elevation");
33
+ const depth = lengthIn(model, resolved.depth, DEFAULT_MILLIMETRES.terrainDepth);
34
+ requireFinite(depth, "terrain's depth");
33
35
  return editModel(model, (tx, writer) => {
34
36
  var _a;
35
37
  createTerrain(tx, writer, {
@@ -37,7 +39,7 @@ export class IFCSite {
37
39
  name: resolved.name,
38
40
  outline: resolved.outline,
39
41
  holes: (_a = resolved.holes) !== null && _a !== void 0 ? _a : [],
40
- depth: lengthIn(model, resolved.depth, DEFAULT_MILLIMETRES.terrainDepth),
42
+ depth,
41
43
  elevation: resolved.elevation,
42
44
  material: resolved.material,
43
45
  }, lengthTolerance(model));
@@ -31,6 +31,7 @@ export class IFCSpaces {
31
31
  const storey = resolveId(model, resolved.storey, "IfcBuildingStorey", "storey");
32
32
  const predefinedType = oneOf(resolved.predefinedType, Inputs.IFC.spacePredefinedTypeEnum, "predefined type");
33
33
  const height = lengthIn(model, resolved.height, DEFAULT_MILLIMETRES.spaceHeight);
34
+ requireFinite(height, "space's height");
34
35
  return editModel(model, (tx, writer) => {
35
36
  createSpace(tx, writer, {
36
37
  storey,
@@ -78,7 +78,8 @@ export declare class IFCWalls {
78
78
  /**
79
79
  * Reads a wall's parameters back from the model: its axis, height, base, thickness, layers and
80
80
  * alignment, the walls it is joined to, its openings and its clippings. It reads walls other tools
81
- * wrote too, when they keep an axis and a layer set usage as IFC's standard walls do.
81
+ * wrote too, when they keep an axis and either a layer set usage or a body extruded from a strip
82
+ * along that axis, as Revit writes one.
82
83
  * @param inputs - The model and the wall
83
84
  * @returns The wall's parameters, in the plan of its storey
84
85
  * @group query
@@ -91,11 +92,12 @@ export declare class IFCWalls {
91
92
  */
92
93
  parameters(inputs: Inputs.IFC.WallDto<IfcModel>): Inputs.IFC.WallParametersDto;
93
94
  /**
94
- * Clips a wall with a plane, removing the part on the side the plane's normal points to, as a
95
- * wall is cut under a sloping roof.
95
+ * Clips a wall with a plane, removing the part on the side its normal points to, as under a
96
+ * sloping roof.
96
97
  *
97
- * The plane is given in the wall's storey, and a wall can be clipped by several planes. Clipping
98
- * keeps the wall's full height in its data, so joins stay right.
98
+ * The plane is given in the wall's storey, and a wall can be clipped by several. Clipping keeps
99
+ * the wall's full height in its data, so joins stay right. Bonsai keeps the clipping too, through
100
+ * the wall's `BBIM_Boolean` set.
99
101
  * @param inputs - The model, the wall, a point on the plane and its normal
100
102
  * @returns A new model with the wall clipped
101
103
  * @group edit
@@ -1,5 +1,5 @@
1
1
  import { resolveDto } from "@bitbybit-dev/base";
2
- import { WORLD_AXES, pointToWorld, vectorToWorld } from "@bitbybit-dev/base/lib/api/services/helpers/frame-axes";
2
+ import { WORLD_AXES, pointToWorld, vectorToWorld } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/frame-axes";
3
3
  import { requireFinite, requirePoint } from "../../build/checks";
4
4
  import { PARALLEL_TOLERANCE, POINT2_SIZE, POINT3_SIZE } from "../../build/constants";
5
5
  import { associateMaterial, layerSetFor, materialOf, requireLayerSet } from "../../build/materials";
@@ -60,6 +60,8 @@ export class IFCWalls {
60
60
  const predefinedType = oneOf(resolved.predefinedType, Inputs.IFC.wallPredefinedTypeEnum, "predefined type");
61
61
  const height = lengthIn(model, resolved.height, DEFAULT_MILLIMETRES.wallHeight);
62
62
  const thickness = lengthIn(model, resolved.thickness, DEFAULT_MILLIMETRES.wallThickness);
63
+ requireFinite(height, "wall's height");
64
+ requireFinite(resolved.baseOffset, "base offset");
63
65
  return editModel(model, (tx, writer) => {
64
66
  createWall(tx, writer, {
65
67
  storey,
@@ -148,6 +150,9 @@ export class IFCWalls {
148
150
  if (resolved.baseOffset !== undefined) {
149
151
  requireFinite(resolved.baseOffset, "base offset");
150
152
  }
153
+ if (resolved.height !== undefined) {
154
+ requireFinite(resolved.height, "wall's height");
155
+ }
151
156
  const alignment = resolved.alignment === undefined ? undefined : oneOf(resolved.alignment, Inputs.IFC.wallAlignmentEnum, "wall alignment");
152
157
  const tolerance = lengthTolerance(model);
153
158
  const storey = containerOf(model, wall);
@@ -162,7 +167,8 @@ export class IFCWalls {
162
167
  end: resolved.end === undefined ? undefined : inWorld(resolved.end),
163
168
  bottom: resolved.baseOffset === undefined ? undefined : pointToWorld(plan, [0, 0, resolved.baseOffset])[2],
164
169
  height: resolved.height,
165
- layerSet: resolved.layerSet !== undefined ? requireLayerSet(tx, resolved.layerSet) : resolved.thickness !== undefined ? layerSetFor(tx, writer, undefined, resolved.thickness, "Wall") : undefined,
170
+ layerSet: resolved.layerSet !== undefined ? requireLayerSet(tx, resolved.layerSet) : undefined,
171
+ thickness: resolved.thickness,
166
172
  alignment,
167
173
  }, tolerance, PARALLEL_TOLERANCE);
168
174
  });
@@ -170,7 +176,8 @@ export class IFCWalls {
170
176
  /**
171
177
  * Reads a wall's parameters back from the model: its axis, height, base, thickness, layers and
172
178
  * alignment, the walls it is joined to, its openings and its clippings. It reads walls other tools
173
- * wrote too, when they keep an axis and a layer set usage as IFC's standard walls do.
179
+ * wrote too, when they keep an axis and either a layer set usage or a body extruded from a strip
180
+ * along that axis, as Revit writes one.
174
181
  * @param inputs - The model and the wall
175
182
  * @returns The wall's parameters, in the plan of its storey
176
183
  * @group query
@@ -186,11 +193,12 @@ export class IFCWalls {
186
193
  return wallParametersOf(model, resolveId(model, inputs.wall, "IfcWall", "wall"), lengthTolerance(model));
187
194
  }
188
195
  /**
189
- * Clips a wall with a plane, removing the part on the side the plane's normal points to, as a
190
- * wall is cut under a sloping roof.
196
+ * Clips a wall with a plane, removing the part on the side its normal points to, as under a
197
+ * sloping roof.
191
198
  *
192
- * The plane is given in the wall's storey, and a wall can be clipped by several planes. Clipping
193
- * keeps the wall's full height in its data, so joins stay right.
199
+ * The plane is given in the wall's storey, and a wall can be clipped by several. Clipping keeps
200
+ * the wall's full height in its data, so joins stay right. Bonsai keeps the clipping too, through
201
+ * the wall's `BBIM_Boolean` set.
194
202
  * @param inputs - The model, the wall, a point on the plane and its normal
195
203
  * @returns A new model with the wall clipped
196
204
  * @group edit
@@ -1,4 +1,5 @@
1
1
  import { resolveDto } from "@bitbybit-dev/base";
2
+ import { requireFinite } from "../../build/checks";
2
3
  import { createFilling, createWindowType } from "../../build/fillings";
3
4
  import * as Inputs from "../inputs";
4
5
  import { DEFAULT_MILLIMETRES } from "./defaults.constants";
@@ -67,9 +68,11 @@ export class IFCWindows {
67
68
  const model = modelOf(resolved.model);
68
69
  const wall = resolveId(model, resolved.wall, "IfcWall", "wall");
69
70
  const type = resolveId(model, resolved.windowType, "IfcWindowType", "window type");
71
+ const offset = lengthIn(model, resolved.offset, DEFAULT_MILLIMETRES.openingOffset);
72
+ const sill = lengthIn(model, resolved.sill, DEFAULT_MILLIMETRES.windowSill);
73
+ requireFinite(offset, "window's offset");
74
+ requireFinite(sill, "window's sill");
70
75
  return editModel(model, (tx, writer) => {
71
- const offset = lengthIn(model, resolved.offset, DEFAULT_MILLIMETRES.openingOffset);
72
- const sill = lengthIn(model, resolved.sill, DEFAULT_MILLIMETRES.windowSill);
73
76
  createFilling(tx, writer, "IfcWindow", { wall, type, id: resolved.id, name: resolved.name, offset, sill }, lengthTolerance(model));
74
77
  });
75
78
  }
@@ -1,4 +1,4 @@
1
- import { WORLD_AXES } from "@bitbybit-dev/base/lib/api/services/helpers/frame-axes";
1
+ import { WORLD_AXES } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/frame-axes";
2
2
  import { enumValue, ref } from "../step/values";
3
3
  import { AGGREGATION, CONTAINMENT } from "./constants";
4
4
  import { objectPlacementOf } from "./placement";
@@ -0,0 +1,5 @@
1
+ import type { IfcTransaction } from "../model/transaction";
2
+ import type { ElementSpec } from "./build-types";
3
+ import type { EntityWriter } from "./entity-writer";
4
+ export declare function requireElementType(tx: IfcTransaction, type: string): string;
5
+ export declare function createBodiedElement(tx: IfcTransaction, writer: EntityWriter, spec: ElementSpec): number;
@@ -0,0 +1,35 @@
1
+ import { enumValue, ref } from "../step/values";
2
+ import { bodyContext } from "./contexts";
3
+ import { writeBodyItems } from "./exact-bodies";
4
+ import { associateMaterial } from "./materials";
5
+ import { objectPlacementOf } from "./placement";
6
+ import { containIn } from "./spatial";
7
+ const ELEMENT = "IfcElement";
8
+ const PREDEFINED_TYPE = "PredefinedType";
9
+ const USERDEFINED = "USERDEFINED";
10
+ const NOTDEFINED = "NOTDEFINED";
11
+ export function requireElementType(tx, type) {
12
+ const name = tx.schema.entityName(type);
13
+ if (name === undefined || !tx.schema.isSubtypeOf(name, ELEMENT) || tx.schema.entity(name).abstract) {
14
+ throw new Error(`'${type}' is not a kind of element the model's schema can hold; give one such as IfcBuildingElementProxy, IfcFurniture or IfcPipeFitting`);
15
+ }
16
+ return name;
17
+ }
18
+ export function createBodiedElement(tx, writer, spec) {
19
+ var _a;
20
+ const type = requireElementType(tx, spec.type);
21
+ const hasPredefinedType = tx.schema.entity(type).attributes.some((attribute) => attribute.name === PREDEFINED_TYPE);
22
+ if (!hasPredefinedType && spec.predefinedType !== undefined) {
23
+ throw new Error(`An ${type} has no predefined type to set`);
24
+ }
25
+ const { items, representationType } = writeBodyItems(writer, spec.body, spec.scale);
26
+ const placement = writer.localPlacement(objectPlacementOf(tx, spec.storey), spec.frame);
27
+ const body = writer.shapeRepresentation(bodyContext(tx, writer), "Body", representationType, items);
28
+ const attributes = Object.assign(Object.assign({ GlobalId: tx.globalId(spec.id), Name: spec.name, ObjectPlacement: ref(placement), Representation: ref(writer.productShape([body])) }, (spec.objectType === undefined ? {} : { ObjectType: spec.objectType })), (hasPredefinedType ? { PredefinedType: enumValue(spec.objectType === undefined ? (_a = spec.predefinedType) !== null && _a !== void 0 ? _a : NOTDEFINED : USERDEFINED) } : {}));
29
+ const element = writer.create(type, attributes);
30
+ containIn(tx, writer, spec.storey, element);
31
+ if (spec.material !== undefined) {
32
+ associateMaterial(tx, writer, [element], spec.material);
33
+ }
34
+ return element;
35
+ }
@@ -1,6 +1,6 @@
1
1
  import type { Base } from "@bitbybit-dev/base";
2
2
  import type { MeshArrays } from "@bitbybit-dev/base/lib/api/services/helpers/helper-types";
3
- import type { FrameAxes } from "@bitbybit-dev/base/lib/api/services/helpers/frame-axes";
3
+ import type { FrameAxes } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/frame-axes";
4
4
  import type * as Inputs from "../api/inputs";
5
5
  import type { IfcSchema } from "../schema/schema";
6
6
  import type { IfcEntity, IfcFileHeader, IfcValue } from "../step/step-types";
@@ -80,7 +80,7 @@ export interface WallGeometry {
80
80
  readonly height: number;
81
81
  readonly base: number;
82
82
  readonly body: number | undefined;
83
- readonly usage: number;
83
+ readonly usage: number | undefined;
84
84
  }
85
85
  export interface WallCuts {
86
86
  readonly start: Line2 | undefined;
@@ -103,11 +103,14 @@ export interface WallChange {
103
103
  readonly bottom: number | undefined;
104
104
  readonly height: number | undefined;
105
105
  readonly layerSet: number | undefined;
106
+ readonly thickness: number | undefined;
106
107
  readonly alignment: Inputs.IFC.wallAlignmentEnum | undefined;
107
108
  }
108
109
  export interface WallBody {
109
110
  readonly height: number;
110
111
  readonly base: number;
112
+ readonly low: number;
113
+ readonly high: number;
111
114
  readonly halfSpaces: readonly number[];
112
115
  }
113
116
  export interface OpeningChange {
@@ -343,3 +346,27 @@ export interface ContextKey {
343
346
  readonly identifier: string;
344
347
  readonly view: string;
345
348
  }
349
+ export interface BrepItems {
350
+ readonly items: number[];
351
+ readonly carved: boolean;
352
+ }
353
+ export interface BodyItems {
354
+ readonly items: readonly number[];
355
+ readonly representationType: string;
356
+ }
357
+ export interface PlacedSource {
358
+ readonly node: Base.RecipeNode;
359
+ readonly matrix: Base.TransformMatrix;
360
+ }
361
+ export interface ElementSpec {
362
+ readonly storey: number;
363
+ readonly id: string | undefined;
364
+ readonly name: string;
365
+ readonly type: string;
366
+ readonly predefinedType: string | undefined;
367
+ readonly objectType: string | undefined;
368
+ readonly body: Base.Recipe;
369
+ readonly scale: number;
370
+ readonly frame: Frame3;
371
+ readonly material: number | undefined;
372
+ }
@@ -3,4 +3,6 @@ export declare function requirePoint(point: unknown, size: number, what: string)
3
3
  export declare function requireOutline(points: unknown, what: string): void;
4
4
  export declare function requirePositive(value: number, what: string): void;
5
5
  export declare function requireFinite(value: number, what: string): void;
6
+ export declare function requireTurn(degrees: number, property: string): void;
7
+ export declare function requireWithinRecipes(length: number, what: string, property: string): void;
6
8
  export declare function requiredReference(reader: EntityReader, id: number, attribute: string): number;
@@ -1,3 +1,6 @@
1
+ import { InputError } from "@bitbybit-dev/base";
2
+ import { MAX_RECIPE_COORDINATE } from "@bitbybit-dev/base/lib/api/recipes/limits.constants";
3
+ import { radiansOf } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/scalars";
1
4
  import { isReference } from "../step/values";
2
5
  import { MIN_OUTLINE_POINTS, POINT2_SIZE } from "./constants";
3
6
  const COUNT_WORDS = ["no", "one", "two", "three"];
@@ -23,6 +26,17 @@ export function requireFinite(value, what) {
23
26
  throw new RangeError(`The ${what} must be a finite number, got ${value}`);
24
27
  }
25
28
  }
29
+ export function requireTurn(degrees, property) {
30
+ requireFinite(degrees, `${property} in degrees`);
31
+ if (!Number.isFinite(radiansOf(degrees))) {
32
+ throw new InputError(`The ${property} in degrees is too large to turn by, got ${degrees}: give the same turn within 360 degrees`, property);
33
+ }
34
+ }
35
+ export function requireWithinRecipes(length, what, property) {
36
+ if (length > MAX_RECIPE_COORDINATE) {
37
+ throw new InputError(`The ${what} must be at most ${MAX_RECIPE_COORDINATE}, the largest coordinate a geometry recipe holds, got ${length}`, property);
38
+ }
39
+ }
26
40
  export function requiredReference(reader, id, attribute) {
27
41
  const value = reader.attribute(id, attribute);
28
42
  if (!isReference(value)) {
@@ -0,0 +1,3 @@
1
+ import type { IfcTransaction } from "../model/transaction";
2
+ import type { EntityWriter } from "./entity-writer";
3
+ export declare function registerClippings(tx: IfcTransaction, writer: EntityWriter, product: number, before: number | undefined, after: number): void;
@@ -0,0 +1,39 @@
1
+ import { isReference } from "../step/values";
2
+ import { propertySetsOf, setPropertyValues } from "./properties";
3
+ import { firstItem } from "./representations";
4
+ const REGISTRY = "BBIM_Boolean";
5
+ const DATA = "Data";
6
+ const CLIPPING = "IfcBooleanClippingResult";
7
+ const BOOLEAN = "IfcBooleanResult";
8
+ const LISTED_ID = /\d+/g;
9
+ function clippingsOf(reader, body) {
10
+ const chain = [];
11
+ let current = body === undefined ? undefined : firstItem(reader, body);
12
+ while (current !== undefined && reader.typeOf(current) === CLIPPING) {
13
+ chain.unshift(current);
14
+ const first = reader.attribute(current, "FirstOperand");
15
+ current = isReference(first) ? first.ref : undefined;
16
+ }
17
+ return chain;
18
+ }
19
+ function listedIn(reader, product) {
20
+ var _a;
21
+ const data = (_a = propertySetsOf(reader, product).find((set) => set.name === REGISTRY)) === null || _a === void 0 ? void 0 : _a.properties[DATA];
22
+ return typeof data === "string" ? data : undefined;
23
+ }
24
+ export function registerClippings(tx, writer, product, before, after) {
25
+ var _a;
26
+ const listing = listedIn(tx, product);
27
+ const listed = ((_a = listing === null || listing === void 0 ? void 0 : listing.match(LISTED_ID)) !== null && _a !== void 0 ? _a : []).map(Number);
28
+ const old = clippingsOf(tx, before);
29
+ const isBoolean = (id) => {
30
+ const type = tx.typeOf(id);
31
+ return type !== undefined && tx.schema.isSubtypeOf(type, BOOLEAN);
32
+ };
33
+ const others = listed.filter((id) => !old.includes(id) && isBoolean(id));
34
+ const now = clippingsOf(tx, after).filter((_, index) => index >= old.length || listed.includes(old[index]));
35
+ const data = `[${[...others, ...now].join(", ")}]`;
36
+ if (data !== listing && (listing !== undefined || now.length)) {
37
+ setPropertyValues(tx, writer, product, REGISTRY, [{ name: DATA, value: data, type: "IfcLabel" }]);
38
+ }
39
+ }
@@ -5,7 +5,6 @@ export declare const LENGTH_PREFIXES: Readonly<Record<string, number>>;
5
5
  export declare const GEOMETRY_TOLERANCE_METRES = 0.000001;
6
6
  export declare const PARALLEL_TOLERANCE = 1e-9;
7
7
  export declare const OPENING_MARGIN_RATIO = 0.25;
8
- export declare const DEGREES_TO_RADIANS: number;
9
8
  export declare const VERTICAL_COSINE: number;
10
9
  export declare const POINT2_SIZE = 2;
11
10
  export declare const POINT3_SIZE = 3;
@@ -21,7 +21,6 @@ export const LENGTH_PREFIXES = {
21
21
  export const GEOMETRY_TOLERANCE_METRES = 1e-6;
22
22
  export const PARALLEL_TOLERANCE = 1e-9;
23
23
  export const OPENING_MARGIN_RATIO = 0.25;
24
- export const DEGREES_TO_RADIANS = Math.PI / 180;
25
24
  export const VERTICAL_COSINE = 1 - 1e-9;
26
25
  export const POINT2_SIZE = 2;
27
26
  export const POINT3_SIZE = 3;
@@ -1,6 +1,6 @@
1
- import { dot3, length3, scale3, subtract3 } from "@bitbybit-dev/base/lib/api/services/helpers/vectors";
1
+ import { axesAlong, squareFrame } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/frame-axes";
2
2
  import { enumValue, ref } from "../step/values";
3
- import { frameFrom, normalize3 } from "./math";
3
+ import { requiredFrame } from "./math";
4
4
  const AXIS_TOLERANCE = 1e-12;
5
5
  function isUnit(vector, axis) {
6
6
  return vector.every((value, index) => Math.abs(value - (index === axis ? 1 : 0)) <= AXIS_TOLERANCE);
@@ -90,8 +90,6 @@ export class EntityWriter {
90
90
  }
91
91
  }
92
92
  export function planeFrame(origin, normal, xHint) {
93
- const z = normalize3(normal);
94
- const projected = subtract3(xHint, scale3(z, dot3(xHint, z)));
95
- const fallback = Math.abs(z[0]) < Math.abs(z[1]) ? [1, 0, 0] : [0, 1, 0];
96
- return frameFrom(origin, z, length3(projected) > AXIS_TOLERANCE ? projected : fallback);
93
+ const frame = squareFrame(origin, normal, xHint);
94
+ return frame === "direction" ? axesAlong(origin, normal) : requiredFrame(frame);
97
95
  }
@@ -0,0 +1,4 @@
1
+ import type { Base } from "@bitbybit-dev/base";
2
+ import type { BodyItems } from "./build-types";
3
+ import type { EntityWriter } from "./entity-writer";
4
+ export declare function writeBodyItems(writer: EntityWriter, recipe: Base.Recipe, scale: number): BodyItems;