brepjs-bim 0.15.0 → 0.15.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.
@@ -7508,6 +7508,12 @@ var FILE_NAME_RE = /(FILE_NAME\('[^']*','[^']*',)(?:\$|\(\$\)),(?:\$|\(\$\)),('[
7508
7508
  function stepString(value) {
7509
7509
  return `'${value.replace(/'/g, "''")}'`;
7510
7510
  }
7511
+ var STRING_OR_BARE_REAL_RE = /'(?:[^']|'')*'|(?<![\d.])(-?\d+)E([+-]?\d+)/g;
7512
+ function normalizeStepReals(bytes) {
7513
+ const text = new TextDecoder().decode(bytes);
7514
+ const fixed = text.replace(STRING_OR_BARE_REAL_RE, (match, mantissa, exponent) => mantissa === void 0 || exponent === void 0 ? match : `${mantissa}.E${exponent}`);
7515
+ return fixed === text ? bytes : new TextEncoder().encode(fixed);
7516
+ }
7511
7517
  var IfcWriter = class IfcWriter {
7512
7518
  #api;
7513
7519
  #modelId;
@@ -7563,7 +7569,7 @@ var IfcWriter = class IfcWriter {
7563
7569
  if (this.#closed) return (0, brepjs.err)(ifcError("IFC_ALREADY_SAVED", "Model has already been saved and closed"));
7564
7570
  try {
7565
7571
  const bytes = this.#api.SaveModel(this.#modelId);
7566
- return (0, brepjs.ok)(this.#patchHeader(bytes));
7572
+ return (0, brepjs.ok)(normalizeStepReals(this.#patchHeader(bytes)));
7567
7573
  } catch (e) {
7568
7574
  return (0, brepjs.err)(ifcError("IFC_SAVE_FAILED", "Failed to serialize IFC model", e));
7569
7575
  } finally {
@@ -7610,10 +7616,11 @@ function writeOwnerHistory(w, meta) {
7610
7616
  const appId = writeApplication(w, meta);
7611
7617
  const addressRefs = writePersonAddresses(w, meta.author.email);
7612
7618
  const personId = w.nextId();
7619
+ const hasName = meta.author.familyName !== void 0 || meta.author.givenName !== void 0;
7613
7620
  w.writeLine({
7614
7621
  expressID: personId,
7615
7622
  type: web_ifc.IFCPERSON,
7616
- Identification: null,
7623
+ Identification: hasName ? null : w.mkType(web_ifc.IFCIDENTIFIER, "unknown"),
7617
7624
  FamilyName: optionalLabel(w, meta.author.familyName),
7618
7625
  GivenName: optionalLabel(w, meta.author.givenName),
7619
7626
  MiddleNames: null,
@@ -7639,7 +7646,7 @@ function writeOwnerHistory(w, meta) {
7639
7646
  State: null,
7640
7647
  ChangeAction: {
7641
7648
  type: 3,
7642
- value: "ADDED"
7649
+ value: "NOTDEFINED"
7643
7650
  },
7644
7651
  LastModifiedDate: null,
7645
7652
  LastModifyingUser: null,
@@ -8009,7 +8016,7 @@ function writeWallEntity(w, guid, name, ownerHistoryId, localPlacementId, produc
8009
8016
  });
8010
8017
  return id;
8011
8018
  }
8012
- function writeSlabEntity(w, guid, name, predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
8019
+ function writeSlabEntity(w, guid, name, _predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
8013
8020
  const id = w.nextId();
8014
8021
  w.writeLine({
8015
8022
  expressID: id,
@@ -8022,14 +8029,11 @@ function writeSlabEntity(w, guid, name, predefinedType, ownerHistoryId, localPla
8022
8029
  ObjectPlacement: w.ref(localPlacementId),
8023
8030
  Representation: w.ref(productDefinitionShapeId),
8024
8031
  Tag: null,
8025
- PredefinedType: {
8026
- type: 3,
8027
- value: predefinedType
8028
- }
8032
+ PredefinedType: null
8029
8033
  });
8030
8034
  return id;
8031
8035
  }
8032
- function writeBeamEntity(w, guid, name, predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
8036
+ function writeBeamEntity(w, guid, name, _predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
8033
8037
  const id = w.nextId();
8034
8038
  w.writeLine({
8035
8039
  expressID: id,
@@ -8042,14 +8046,11 @@ function writeBeamEntity(w, guid, name, predefinedType, ownerHistoryId, localPla
8042
8046
  ObjectPlacement: w.ref(localPlacementId),
8043
8047
  Representation: w.ref(productDefinitionShapeId),
8044
8048
  Tag: null,
8045
- PredefinedType: {
8046
- type: 3,
8047
- value: predefinedType
8048
- }
8049
+ PredefinedType: null
8049
8050
  });
8050
8051
  return id;
8051
8052
  }
8052
- function writeColumnEntity(w, guid, name, predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
8053
+ function writeColumnEntity(w, guid, name, _predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
8053
8054
  const id = w.nextId();
8054
8055
  w.writeLine({
8055
8056
  expressID: id,
@@ -8062,10 +8063,7 @@ function writeColumnEntity(w, guid, name, predefinedType, ownerHistoryId, localP
8062
8063
  ObjectPlacement: w.ref(localPlacementId),
8063
8064
  Representation: w.ref(productDefinitionShapeId),
8064
8065
  Tag: null,
8065
- PredefinedType: {
8066
- type: 3,
8067
- value: predefinedType
8068
- }
8066
+ PredefinedType: null
8069
8067
  });
8070
8068
  return id;
8071
8069
  }
@@ -8987,7 +8985,7 @@ function writeSpaceGeometry(w, spec, geomSubContextId, parentPlacementId) {
8987
8985
  productDefinitionShapeId
8988
8986
  };
8989
8987
  }
8990
- function writeSpaceEntity(w, guid, name, longName, predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
8988
+ function writeSpaceEntity(w, guid, name, longName, _predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
8991
8989
  const id = w.nextId();
8992
8990
  w.writeLine({
8993
8991
  expressID: id,
@@ -9004,10 +9002,7 @@ function writeSpaceEntity(w, guid, name, longName, predefinedType, ownerHistoryI
9004
9002
  type: 3,
9005
9003
  value: "ELEMENT"
9006
9004
  },
9007
- PredefinedType: {
9008
- type: 3,
9009
- value: predefinedType
9010
- },
9005
+ PredefinedType: null,
9011
9006
  ElevationWithFlooring: null
9012
9007
  });
9013
9008
  return id;
@@ -9040,7 +9035,7 @@ function writeRelSpaceBoundary(w, guid, ownerHistoryId, spaceExpressId, elementE
9040
9035
  * are the IfcLocalPlacement and IfcProductDefinitionShape express IDs produced by
9041
9036
  * the geometry layer; pass `null` for either when not available.
9042
9037
  */
9043
- function writeRoofEntity(w, guid, name, predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
9038
+ function writeRoofEntity(w, guid, name, _predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
9044
9039
  const id = w.nextId();
9045
9040
  w.writeLine({
9046
9041
  expressID: id,
@@ -9053,10 +9048,7 @@ function writeRoofEntity(w, guid, name, predefinedType, ownerHistoryId, localPla
9053
9048
  ObjectPlacement: localPlacementId === null ? null : w.ref(localPlacementId),
9054
9049
  Representation: productDefinitionShapeId === null ? null : w.ref(productDefinitionShapeId),
9055
9050
  Tag: null,
9056
- PredefinedType: {
9057
- type: 3,
9058
- value: predefinedType
9059
- }
9051
+ PredefinedType: null
9060
9052
  });
9061
9053
  return id;
9062
9054
  }
@@ -9072,7 +9064,7 @@ function writeRoofType(w, ownerHistoryId, typeGuid, relGuid, predefinedType, occ
9072
9064
  type: web_ifc.IFCROOFTYPE,
9073
9065
  GlobalId: w.mkType(web_ifc.IFCGLOBALLYUNIQUEID, typeGuid),
9074
9066
  OwnerHistory: w.ref(ownerHistoryId),
9075
- Name: null,
9067
+ Name: w.mkType(web_ifc.IFCLABEL, "Roof Type"),
9076
9068
  Description: null,
9077
9069
  ApplicableOccurrence: null,
9078
9070
  HasPropertySets: null,
@@ -9238,7 +9230,7 @@ function writeCurtainWall(w, spec, grid, stableKey, name, ownerHistoryId, geomSu
9238
9230
  PlacementRelTo: parentPlacementId !== null ? w.ref(parentPlacementId) : null,
9239
9231
  RelativePlacement: w.ref(placement3DId)
9240
9232
  });
9241
- const predefinedType = spec.predefinedType ?? "CURTAIN_WALL";
9233
+ const predefinedType = spec.predefinedType ?? "NOTDEFINED";
9242
9234
  const curtainWallId = w.nextId();
9243
9235
  w.writeLine({
9244
9236
  expressID: curtainWallId,
@@ -9401,7 +9393,7 @@ function finishRepresentation(w, extrusionId, geomSubContextId, localPlacementId
9401
9393
  productDefinitionShapeId
9402
9394
  };
9403
9395
  }
9404
- function writeFootingEntity(w, guid, name, predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
9396
+ function writeFootingEntity(w, guid, name, _predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
9405
9397
  const id = w.nextId();
9406
9398
  w.writeLine({
9407
9399
  expressID: id,
@@ -9414,14 +9406,11 @@ function writeFootingEntity(w, guid, name, predefinedType, ownerHistoryId, local
9414
9406
  ObjectPlacement: w.ref(localPlacementId),
9415
9407
  Representation: w.ref(productDefinitionShapeId),
9416
9408
  Tag: null,
9417
- PredefinedType: {
9418
- type: 3,
9419
- value: predefinedType
9420
- }
9409
+ PredefinedType: null
9421
9410
  });
9422
9411
  return id;
9423
9412
  }
9424
- function writePileEntity(w, guid, name, predefinedType, constructionType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
9413
+ function writePileEntity(w, guid, name, _predefinedType, constructionType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
9425
9414
  const id = w.nextId();
9426
9415
  w.writeLine({
9427
9416
  expressID: id,
@@ -9434,10 +9423,7 @@ function writePileEntity(w, guid, name, predefinedType, constructionType, ownerH
9434
9423
  ObjectPlacement: w.ref(localPlacementId),
9435
9424
  Representation: w.ref(productDefinitionShapeId),
9436
9425
  Tag: null,
9437
- PredefinedType: {
9438
- type: 3,
9439
- value: predefinedType
9440
- },
9426
+ PredefinedType: null,
9441
9427
  ConstructionType: constructionType !== null ? {
9442
9428
  type: 3,
9443
9429
  value: constructionType
@@ -9543,14 +9529,14 @@ function writeLocalPlacement(w, origin, axisZ, axisX, parentPlacementId) {
9543
9529
  });
9544
9530
  return localPlacementId;
9545
9531
  }
9546
- function writeAssemblyType(w, typeConstant, typeGuid, relGuid, predefinedType, ownerHistoryId, occurrenceExpressIds) {
9532
+ function writeAssemblyType(w, typeConstant, typeName, typeGuid, relGuid, predefinedType, ownerHistoryId, occurrenceExpressIds) {
9547
9533
  const typeId = w.nextId();
9548
9534
  w.writeLine({
9549
9535
  expressID: typeId,
9550
9536
  type: typeConstant,
9551
9537
  GlobalId: w.mkType(web_ifc.IFCGLOBALLYUNIQUEID, typeGuid),
9552
9538
  OwnerHistory: w.ref(ownerHistoryId),
9553
- Name: null,
9539
+ Name: w.mkType(web_ifc.IFCLABEL, typeName),
9554
9540
  Description: null,
9555
9541
  ApplicableOccurrence: null,
9556
9542
  HasPropertySets: null,
@@ -9590,14 +9576,11 @@ function writeStairFlightEntity(w, guid, name, flight, ownerHistoryId, localPlac
9590
9576
  NumberOfTreads: w.mkType(web_ifc.IFCINTEGER, flight.numberOfRisers - 1),
9591
9577
  RiserHeight: w.mkType(web_ifc.IFCPOSITIVELENGTHMEASURE, toIfcLengthM(flight.riserHeight)),
9592
9578
  TreadLength: w.mkType(web_ifc.IFCPOSITIVELENGTHMEASURE, toIfcLengthM(flight.treadLength)),
9593
- PredefinedType: {
9594
- type: 3,
9595
- value: "STRAIGHT"
9596
- }
9579
+ PredefinedType: null
9597
9580
  });
9598
9581
  return id;
9599
9582
  }
9600
- function writeStairEntity(w, guid, name, predefinedType, ownerHistoryId, localPlacementId) {
9583
+ function writeStairEntity(w, guid, name, _predefinedType, ownerHistoryId, localPlacementId) {
9601
9584
  const id = w.nextId();
9602
9585
  w.writeLine({
9603
9586
  expressID: id,
@@ -9610,14 +9593,11 @@ function writeStairEntity(w, guid, name, predefinedType, ownerHistoryId, localPl
9610
9593
  ObjectPlacement: w.ref(localPlacementId),
9611
9594
  Representation: null,
9612
9595
  Tag: null,
9613
- PredefinedType: {
9614
- type: 3,
9615
- value: predefinedType
9616
- }
9596
+ PredefinedType: null
9617
9597
  });
9618
9598
  return id;
9619
9599
  }
9620
- function writeRampFlightEntity(w, guid, name, predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
9600
+ function writeRampFlightEntity(w, guid, name, _predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
9621
9601
  const id = w.nextId();
9622
9602
  w.writeLine({
9623
9603
  expressID: id,
@@ -9630,14 +9610,11 @@ function writeRampFlightEntity(w, guid, name, predefinedType, ownerHistoryId, lo
9630
9610
  ObjectPlacement: w.ref(localPlacementId),
9631
9611
  Representation: w.ref(productDefinitionShapeId),
9632
9612
  Tag: null,
9633
- PredefinedType: {
9634
- type: 3,
9635
- value: predefinedType
9636
- }
9613
+ PredefinedType: null
9637
9614
  });
9638
9615
  return id;
9639
9616
  }
9640
- function writeRampEntity(w, guid, name, predefinedType, ownerHistoryId, localPlacementId) {
9617
+ function writeRampEntity(w, guid, name, _predefinedType, ownerHistoryId, localPlacementId) {
9641
9618
  const id = w.nextId();
9642
9619
  w.writeLine({
9643
9620
  expressID: id,
@@ -9650,10 +9627,7 @@ function writeRampEntity(w, guid, name, predefinedType, ownerHistoryId, localPla
9650
9627
  ObjectPlacement: w.ref(localPlacementId),
9651
9628
  Representation: null,
9652
9629
  Tag: null,
9653
- PredefinedType: {
9654
- type: 3,
9655
- value: predefinedType
9656
- }
9630
+ PredefinedType: null
9657
9631
  });
9658
9632
  return id;
9659
9633
  }
@@ -9712,8 +9686,8 @@ function writeStairAssembly(w, spec, stairKey, assemblyGuid, ownerHistoryId, geo
9712
9686
  _usingCtx$2.d();
9713
9687
  }
9714
9688
  writeRelAggregates(w, deriveIfcGuidSync(`rel:AGGREGATES:STAIR:${stairKey}`), ownerHistoryId, assemblyExpressId, flightExpressIds);
9715
- writeAssemblyType(w, web_ifc.IFCSTAIRTYPE, deriveIfcGuidSync(`type:STAIR:${stairKey}`), deriveIfcGuidSync(`rel-type:STAIR:${stairKey}`), predefinedType, ownerHistoryId, [assemblyExpressId]);
9716
- if (flightExpressIds.length > 0) writeAssemblyType(w, web_ifc.IFCSTAIRFLIGHTTYPE, deriveIfcGuidSync(`type:STAIR_FLIGHT:${stairKey}`), deriveIfcGuidSync(`rel-type:STAIR_FLIGHT:${stairKey}`), "STRAIGHT", ownerHistoryId, flightExpressIds);
9689
+ writeAssemblyType(w, web_ifc.IFCSTAIRTYPE, "Stair Type", deriveIfcGuidSync(`type:STAIR:${stairKey}`), deriveIfcGuidSync(`rel-type:STAIR:${stairKey}`), predefinedType, ownerHistoryId, [assemblyExpressId]);
9690
+ if (flightExpressIds.length > 0) writeAssemblyType(w, web_ifc.IFCSTAIRFLIGHTTYPE, "Stair Flight Type", deriveIfcGuidSync(`type:STAIR_FLIGHT:${stairKey}`), deriveIfcGuidSync(`rel-type:STAIR_FLIGHT:${stairKey}`), "STRAIGHT", ownerHistoryId, flightExpressIds);
9717
9691
  return {
9718
9692
  ok: true,
9719
9693
  value: {
@@ -9773,8 +9747,8 @@ function writeRampAssembly(w, spec, rampKey, assemblyGuid, ownerHistoryId, geomS
9773
9747
  _usingCtx3.d();
9774
9748
  }
9775
9749
  writeRelAggregates(w, deriveIfcGuidSync(`rel:AGGREGATES:RAMP:${rampKey}`), ownerHistoryId, assemblyExpressId, flightExpressIds);
9776
- writeAssemblyType(w, web_ifc.IFCRAMPTYPE, deriveIfcGuidSync(`type:RAMP:${rampKey}`), deriveIfcGuidSync(`rel-type:RAMP:${rampKey}`), predefinedType, ownerHistoryId, [assemblyExpressId]);
9777
- if (flightExpressIds.length > 0) writeAssemblyType(w, web_ifc.IFCRAMPFLIGHTTYPE, deriveIfcGuidSync(`type:RAMP_FLIGHT:${rampKey}`), deriveIfcGuidSync(`rel-type:RAMP_FLIGHT:${rampKey}`), "STRAIGHT", ownerHistoryId, flightExpressIds);
9750
+ writeAssemblyType(w, web_ifc.IFCRAMPTYPE, "Ramp Type", deriveIfcGuidSync(`type:RAMP:${rampKey}`), deriveIfcGuidSync(`rel-type:RAMP:${rampKey}`), predefinedType, ownerHistoryId, [assemblyExpressId]);
9751
+ if (flightExpressIds.length > 0) writeAssemblyType(w, web_ifc.IFCRAMPFLIGHTTYPE, "Ramp Flight Type", deriveIfcGuidSync(`type:RAMP_FLIGHT:${rampKey}`), deriveIfcGuidSync(`rel-type:RAMP_FLIGHT:${rampKey}`), "STRAIGHT", ownerHistoryId, flightExpressIds);
9778
9752
  return {
9779
9753
  ok: true,
9780
9754
  value: {
@@ -9884,7 +9858,7 @@ function writeRailingGeometry(w, spec, solid, geomSubContextId, parentPlacementI
9884
9858
  usedFallback: false
9885
9859
  };
9886
9860
  }
9887
- function writeRailingEntity(w, guid, name, predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
9861
+ function writeRailingEntity(w, guid, name, _predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
9888
9862
  const id = w.nextId();
9889
9863
  w.writeLine({
9890
9864
  expressID: id,
@@ -9897,10 +9871,7 @@ function writeRailingEntity(w, guid, name, predefinedType, ownerHistoryId, local
9897
9871
  ObjectPlacement: w.ref(localPlacementId),
9898
9872
  Representation: w.ref(productDefinitionShapeId),
9899
9873
  Tag: null,
9900
- PredefinedType: {
9901
- type: 3,
9902
- value: predefinedType
9903
- }
9874
+ PredefinedType: null
9904
9875
  });
9905
9876
  return id;
9906
9877
  }
@@ -9986,7 +9957,7 @@ function writeCoveringGeometry(w, spec, geomSubContextId, parentPlacementId) {
9986
9957
  bodyItemId: extrusionId
9987
9958
  };
9988
9959
  }
9989
- function writeCoveringEntity(w, guid, name, predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
9960
+ function writeCoveringEntity(w, guid, name, _predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
9990
9961
  const id = w.nextId();
9991
9962
  w.writeLine({
9992
9963
  expressID: id,
@@ -9999,10 +9970,7 @@ function writeCoveringEntity(w, guid, name, predefinedType, ownerHistoryId, loca
9999
9970
  ObjectPlacement: w.ref(localPlacementId),
10000
9971
  Representation: w.ref(productDefinitionShapeId),
10001
9972
  Tag: null,
10002
- PredefinedType: {
10003
- type: 3,
10004
- value: predefinedType
10005
- }
9973
+ PredefinedType: null
10006
9974
  });
10007
9975
  return id;
10008
9976
  }
@@ -10948,7 +10916,7 @@ function writeElementQuantity(w, ownerHistoryId, qtoName, quantityIds) {
10948
10916
  OwnerHistory: w.ref(ownerHistoryId),
10949
10917
  Name: w.mkType(web_ifc.IFCLABEL, qtoName),
10950
10918
  Description: null,
10951
- MethodOfMeasurement: null,
10919
+ MethodOfMeasurement: w.mkType(web_ifc.IFCLABEL, "BaseQuantities"),
10952
10920
  Quantities: quantityIds.map((id) => w.ref(id))
10953
10921
  });
10954
10922
  return qtoId;
@@ -11628,11 +11596,11 @@ var TYPE_CONSTANT = {
11628
11596
  IFCRAILINGTYPE: web_ifc.IFCRAILINGTYPE,
11629
11597
  IFCCOVERINGTYPE: web_ifc.IFCCOVERINGTYPE
11630
11598
  };
11631
- function commonTypeFields(w, guid, ownerHistoryId) {
11599
+ function commonTypeFields(w, guid, ownerHistoryId, name) {
11632
11600
  return {
11633
11601
  GlobalId: w.mkType(web_ifc.IFCGLOBALLYUNIQUEID, guid),
11634
11602
  OwnerHistory: w.ref(ownerHistoryId),
11635
- Name: null,
11603
+ Name: w.mkType(web_ifc.IFCLABEL, name),
11636
11604
  Description: null,
11637
11605
  ApplicableOccurrence: null,
11638
11606
  HasPropertySets: null,
@@ -11642,7 +11610,7 @@ function commonTypeFields(w, guid, ownerHistoryId) {
11642
11610
  }
11643
11611
  function writeTypeObject(w, typeName, guid, ownerHistoryId, predefinedType) {
11644
11612
  const id = w.nextId();
11645
- const base = commonTypeFields(w, guid, ownerHistoryId);
11613
+ const base = commonTypeFields(w, guid, ownerHistoryId, `${typeName.slice(3, -4).replace("CURTAINWALL", "CURTAIN WALL").toLowerCase().replace(/(^|\s)\S/g, (c) => c.toUpperCase())} Type`);
11646
11614
  if (typeName === "IFCDOORTYPE") {
11647
11615
  w.writeLine({
11648
11616
  expressID: id,
@@ -13977,10 +13945,11 @@ async function fromIfc(bytes, options = {}) {
13977
13945
  const scale = readLengthScale(reader);
13978
13946
  const spatialRoot = buildSpatialTree(reader, scale);
13979
13947
  const containment = buildElementContainmentMap(reader);
13948
+ const typeEnums = buildTypePredefinedMap(reader);
13980
13949
  const elements = [];
13981
13950
  const byExpressId = /* @__PURE__ */ new Map();
13982
13951
  for (const [type, category] of ELEMENT_TYPES) for (const expressId of reader.getLinesOfType(type)) {
13983
- const element = readElement(reader, expressId, category, scale, containment, options.skipGeometry ?? false, diagnostics);
13952
+ const element = readElement(reader, expressId, category, scale, containment, typeEnums, options.skipGeometry ?? false, diagnostics);
13984
13953
  if (element === null) continue;
13985
13954
  elements.push(element);
13986
13955
  byExpressId.set(element.expressId, element);
@@ -14007,7 +13976,7 @@ async function fromIfc(bytes, options = {}) {
14007
13976
  * element line itself is unreadable (an `error` diagnostic is recorded). Any
14008
13977
  * sub-read failure is isolated by its own reader and never aborts the element.
14009
13978
  */
14010
- function readElement(reader, expressId, category, scale, containment, skipGeometry, diagnostics) {
13979
+ function readElement(reader, expressId, category, scale, containment, typeEnums, skipGeometry, diagnostics) {
14011
13980
  try {
14012
13981
  const line = reader.getLine(expressId);
14013
13982
  if (line === null) {
@@ -14016,7 +13985,7 @@ function readElement(reader, expressId, category, scale, containment, skipGeomet
14016
13985
  }
14017
13986
  const guid = readGuid(line);
14018
13987
  const name = readName(reader, line);
14019
- const predefinedType = readPredefinedType(line);
13988
+ const predefinedType = readPredefinedType(line) ?? typeEnums.get(expressId);
14020
13989
  const voidedBy = readVoids(reader, expressId).map((v) => v.openingExpressId);
14021
13990
  const fills = findFills(reader, expressId);
14022
13991
  const geometry = skipGeometry ? {
@@ -14135,6 +14104,27 @@ function readName(reader, line) {
14135
14104
  const raw = line["Name"]?.value;
14136
14105
  return typeof raw === "string" ? reader.decodeText(raw) : "";
14137
14106
  }
14107
+ /** occurrence expressId -> the relating type object's PredefinedType literal. */
14108
+ function buildTypePredefinedMap(reader) {
14109
+ const map = /* @__PURE__ */ new Map();
14110
+ for (const relId of reader.getLinesOfType(web_ifc.IFCRELDEFINESBYTYPE)) {
14111
+ const rel = reader.getLine(relId);
14112
+ if (rel === null) continue;
14113
+ const typeId = refValue(rel["RelatingType"]);
14114
+ if (typeId === void 0) continue;
14115
+ const typeLine = reader.getLine(typeId);
14116
+ if (typeLine === null) continue;
14117
+ const pred = readPredefinedType(typeLine);
14118
+ if (pred === void 0) continue;
14119
+ const related = rel["RelatedObjects"];
14120
+ if (!Array.isArray(related)) continue;
14121
+ for (const ref of related) {
14122
+ const id = refValue(ref);
14123
+ if (id !== void 0) map.set(id, pred);
14124
+ }
14125
+ }
14126
+ return map;
14127
+ }
14138
14128
  function readPredefinedType(line) {
14139
14129
  const raw = line["PredefinedType"]?.value;
14140
14130
  return typeof raw === "string" ? raw : void 0;
@@ -14539,11 +14529,7 @@ var CurtainWallSpecSchema = object({
14539
14529
  axisX: unitVec$5,
14540
14530
  axisZ: unitVec$5,
14541
14531
  materialName: string().min(1),
14542
- predefinedType: _enum([
14543
- "CURTAIN_WALL",
14544
- "NOTDEFINED",
14545
- "USERDEFINED"
14546
- ]).optional(),
14532
+ predefinedType: _enum(["NOTDEFINED", "USERDEFINED"]).optional(),
14547
14533
  panelMaterialName: string().min(1).optional(),
14548
14534
  mullionMaterialName: string().min(1).optional(),
14549
14535
  isExternal: boolean().optional(),
@@ -16770,6 +16756,8 @@ function familiesToBim(root, options) {
16770
16756
  return buildingResult;
16771
16757
  }
16772
16758
  const buildingId = buildingResult.value;
16759
+ const project = model.getProject();
16760
+ if (project !== null) model.aggregate(project.localId, siteResult.value);
16773
16761
  model.aggregate(siteResult.value, buildingId);
16774
16762
  const idByKeyPath = /* @__PURE__ */ new Map();
16775
16763
  const walk = (el, storeyId) => {
@@ -7485,6 +7485,12 @@ var FILE_NAME_RE = /(FILE_NAME\('[^']*','[^']*',)(?:\$|\(\$\)),(?:\$|\(\$\)),('[
7485
7485
  function stepString(value) {
7486
7486
  return `'${value.replace(/'/g, "''")}'`;
7487
7487
  }
7488
+ var STRING_OR_BARE_REAL_RE = /'(?:[^']|'')*'|(?<![\d.])(-?\d+)E([+-]?\d+)/g;
7489
+ function normalizeStepReals(bytes) {
7490
+ const text = new TextDecoder().decode(bytes);
7491
+ const fixed = text.replace(STRING_OR_BARE_REAL_RE, (match, mantissa, exponent) => mantissa === void 0 || exponent === void 0 ? match : `${mantissa}.E${exponent}`);
7492
+ return fixed === text ? bytes : new TextEncoder().encode(fixed);
7493
+ }
7488
7494
  var IfcWriter = class IfcWriter {
7489
7495
  #api;
7490
7496
  #modelId;
@@ -7540,7 +7546,7 @@ var IfcWriter = class IfcWriter {
7540
7546
  if (this.#closed) return err(ifcError("IFC_ALREADY_SAVED", "Model has already been saved and closed"));
7541
7547
  try {
7542
7548
  const bytes = this.#api.SaveModel(this.#modelId);
7543
- return ok(this.#patchHeader(bytes));
7549
+ return ok(normalizeStepReals(this.#patchHeader(bytes)));
7544
7550
  } catch (e) {
7545
7551
  return err(ifcError("IFC_SAVE_FAILED", "Failed to serialize IFC model", e));
7546
7552
  } finally {
@@ -7587,10 +7593,11 @@ function writeOwnerHistory(w, meta) {
7587
7593
  const appId = writeApplication(w, meta);
7588
7594
  const addressRefs = writePersonAddresses(w, meta.author.email);
7589
7595
  const personId = w.nextId();
7596
+ const hasName = meta.author.familyName !== void 0 || meta.author.givenName !== void 0;
7590
7597
  w.writeLine({
7591
7598
  expressID: personId,
7592
7599
  type: WebIFC.IFCPERSON,
7593
- Identification: null,
7600
+ Identification: hasName ? null : w.mkType(WebIFC.IFCIDENTIFIER, "unknown"),
7594
7601
  FamilyName: optionalLabel(w, meta.author.familyName),
7595
7602
  GivenName: optionalLabel(w, meta.author.givenName),
7596
7603
  MiddleNames: null,
@@ -7616,7 +7623,7 @@ function writeOwnerHistory(w, meta) {
7616
7623
  State: null,
7617
7624
  ChangeAction: {
7618
7625
  type: 3,
7619
- value: "ADDED"
7626
+ value: "NOTDEFINED"
7620
7627
  },
7621
7628
  LastModifiedDate: null,
7622
7629
  LastModifyingUser: null,
@@ -7986,7 +7993,7 @@ function writeWallEntity(w, guid, name, ownerHistoryId, localPlacementId, produc
7986
7993
  });
7987
7994
  return id;
7988
7995
  }
7989
- function writeSlabEntity(w, guid, name, predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
7996
+ function writeSlabEntity(w, guid, name, _predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
7990
7997
  const id = w.nextId();
7991
7998
  w.writeLine({
7992
7999
  expressID: id,
@@ -7999,14 +8006,11 @@ function writeSlabEntity(w, guid, name, predefinedType, ownerHistoryId, localPla
7999
8006
  ObjectPlacement: w.ref(localPlacementId),
8000
8007
  Representation: w.ref(productDefinitionShapeId),
8001
8008
  Tag: null,
8002
- PredefinedType: {
8003
- type: 3,
8004
- value: predefinedType
8005
- }
8009
+ PredefinedType: null
8006
8010
  });
8007
8011
  return id;
8008
8012
  }
8009
- function writeBeamEntity(w, guid, name, predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
8013
+ function writeBeamEntity(w, guid, name, _predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
8010
8014
  const id = w.nextId();
8011
8015
  w.writeLine({
8012
8016
  expressID: id,
@@ -8019,14 +8023,11 @@ function writeBeamEntity(w, guid, name, predefinedType, ownerHistoryId, localPla
8019
8023
  ObjectPlacement: w.ref(localPlacementId),
8020
8024
  Representation: w.ref(productDefinitionShapeId),
8021
8025
  Tag: null,
8022
- PredefinedType: {
8023
- type: 3,
8024
- value: predefinedType
8025
- }
8026
+ PredefinedType: null
8026
8027
  });
8027
8028
  return id;
8028
8029
  }
8029
- function writeColumnEntity(w, guid, name, predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
8030
+ function writeColumnEntity(w, guid, name, _predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
8030
8031
  const id = w.nextId();
8031
8032
  w.writeLine({
8032
8033
  expressID: id,
@@ -8039,10 +8040,7 @@ function writeColumnEntity(w, guid, name, predefinedType, ownerHistoryId, localP
8039
8040
  ObjectPlacement: w.ref(localPlacementId),
8040
8041
  Representation: w.ref(productDefinitionShapeId),
8041
8042
  Tag: null,
8042
- PredefinedType: {
8043
- type: 3,
8044
- value: predefinedType
8045
- }
8043
+ PredefinedType: null
8046
8044
  });
8047
8045
  return id;
8048
8046
  }
@@ -8964,7 +8962,7 @@ function writeSpaceGeometry(w, spec, geomSubContextId, parentPlacementId) {
8964
8962
  productDefinitionShapeId
8965
8963
  };
8966
8964
  }
8967
- function writeSpaceEntity(w, guid, name, longName, predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
8965
+ function writeSpaceEntity(w, guid, name, longName, _predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
8968
8966
  const id = w.nextId();
8969
8967
  w.writeLine({
8970
8968
  expressID: id,
@@ -8981,10 +8979,7 @@ function writeSpaceEntity(w, guid, name, longName, predefinedType, ownerHistoryI
8981
8979
  type: 3,
8982
8980
  value: "ELEMENT"
8983
8981
  },
8984
- PredefinedType: {
8985
- type: 3,
8986
- value: predefinedType
8987
- },
8982
+ PredefinedType: null,
8988
8983
  ElevationWithFlooring: null
8989
8984
  });
8990
8985
  return id;
@@ -9017,7 +9012,7 @@ function writeRelSpaceBoundary(w, guid, ownerHistoryId, spaceExpressId, elementE
9017
9012
  * are the IfcLocalPlacement and IfcProductDefinitionShape express IDs produced by
9018
9013
  * the geometry layer; pass `null` for either when not available.
9019
9014
  */
9020
- function writeRoofEntity(w, guid, name, predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
9015
+ function writeRoofEntity(w, guid, name, _predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
9021
9016
  const id = w.nextId();
9022
9017
  w.writeLine({
9023
9018
  expressID: id,
@@ -9030,10 +9025,7 @@ function writeRoofEntity(w, guid, name, predefinedType, ownerHistoryId, localPla
9030
9025
  ObjectPlacement: localPlacementId === null ? null : w.ref(localPlacementId),
9031
9026
  Representation: productDefinitionShapeId === null ? null : w.ref(productDefinitionShapeId),
9032
9027
  Tag: null,
9033
- PredefinedType: {
9034
- type: 3,
9035
- value: predefinedType
9036
- }
9028
+ PredefinedType: null
9037
9029
  });
9038
9030
  return id;
9039
9031
  }
@@ -9049,7 +9041,7 @@ function writeRoofType(w, ownerHistoryId, typeGuid, relGuid, predefinedType, occ
9049
9041
  type: WebIFC.IFCROOFTYPE,
9050
9042
  GlobalId: w.mkType(WebIFC.IFCGLOBALLYUNIQUEID, typeGuid),
9051
9043
  OwnerHistory: w.ref(ownerHistoryId),
9052
- Name: null,
9044
+ Name: w.mkType(WebIFC.IFCLABEL, "Roof Type"),
9053
9045
  Description: null,
9054
9046
  ApplicableOccurrence: null,
9055
9047
  HasPropertySets: null,
@@ -9215,7 +9207,7 @@ function writeCurtainWall(w, spec, grid, stableKey, name, ownerHistoryId, geomSu
9215
9207
  PlacementRelTo: parentPlacementId !== null ? w.ref(parentPlacementId) : null,
9216
9208
  RelativePlacement: w.ref(placement3DId)
9217
9209
  });
9218
- const predefinedType = spec.predefinedType ?? "CURTAIN_WALL";
9210
+ const predefinedType = spec.predefinedType ?? "NOTDEFINED";
9219
9211
  const curtainWallId = w.nextId();
9220
9212
  w.writeLine({
9221
9213
  expressID: curtainWallId,
@@ -9378,7 +9370,7 @@ function finishRepresentation(w, extrusionId, geomSubContextId, localPlacementId
9378
9370
  productDefinitionShapeId
9379
9371
  };
9380
9372
  }
9381
- function writeFootingEntity(w, guid, name, predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
9373
+ function writeFootingEntity(w, guid, name, _predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
9382
9374
  const id = w.nextId();
9383
9375
  w.writeLine({
9384
9376
  expressID: id,
@@ -9391,14 +9383,11 @@ function writeFootingEntity(w, guid, name, predefinedType, ownerHistoryId, local
9391
9383
  ObjectPlacement: w.ref(localPlacementId),
9392
9384
  Representation: w.ref(productDefinitionShapeId),
9393
9385
  Tag: null,
9394
- PredefinedType: {
9395
- type: 3,
9396
- value: predefinedType
9397
- }
9386
+ PredefinedType: null
9398
9387
  });
9399
9388
  return id;
9400
9389
  }
9401
- function writePileEntity(w, guid, name, predefinedType, constructionType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
9390
+ function writePileEntity(w, guid, name, _predefinedType, constructionType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
9402
9391
  const id = w.nextId();
9403
9392
  w.writeLine({
9404
9393
  expressID: id,
@@ -9411,10 +9400,7 @@ function writePileEntity(w, guid, name, predefinedType, constructionType, ownerH
9411
9400
  ObjectPlacement: w.ref(localPlacementId),
9412
9401
  Representation: w.ref(productDefinitionShapeId),
9413
9402
  Tag: null,
9414
- PredefinedType: {
9415
- type: 3,
9416
- value: predefinedType
9417
- },
9403
+ PredefinedType: null,
9418
9404
  ConstructionType: constructionType !== null ? {
9419
9405
  type: 3,
9420
9406
  value: constructionType
@@ -9520,14 +9506,14 @@ function writeLocalPlacement(w, origin, axisZ, axisX, parentPlacementId) {
9520
9506
  });
9521
9507
  return localPlacementId;
9522
9508
  }
9523
- function writeAssemblyType(w, typeConstant, typeGuid, relGuid, predefinedType, ownerHistoryId, occurrenceExpressIds) {
9509
+ function writeAssemblyType(w, typeConstant, typeName, typeGuid, relGuid, predefinedType, ownerHistoryId, occurrenceExpressIds) {
9524
9510
  const typeId = w.nextId();
9525
9511
  w.writeLine({
9526
9512
  expressID: typeId,
9527
9513
  type: typeConstant,
9528
9514
  GlobalId: w.mkType(WebIFC.IFCGLOBALLYUNIQUEID, typeGuid),
9529
9515
  OwnerHistory: w.ref(ownerHistoryId),
9530
- Name: null,
9516
+ Name: w.mkType(WebIFC.IFCLABEL, typeName),
9531
9517
  Description: null,
9532
9518
  ApplicableOccurrence: null,
9533
9519
  HasPropertySets: null,
@@ -9567,14 +9553,11 @@ function writeStairFlightEntity(w, guid, name, flight, ownerHistoryId, localPlac
9567
9553
  NumberOfTreads: w.mkType(WebIFC.IFCINTEGER, flight.numberOfRisers - 1),
9568
9554
  RiserHeight: w.mkType(WebIFC.IFCPOSITIVELENGTHMEASURE, toIfcLengthM(flight.riserHeight)),
9569
9555
  TreadLength: w.mkType(WebIFC.IFCPOSITIVELENGTHMEASURE, toIfcLengthM(flight.treadLength)),
9570
- PredefinedType: {
9571
- type: 3,
9572
- value: "STRAIGHT"
9573
- }
9556
+ PredefinedType: null
9574
9557
  });
9575
9558
  return id;
9576
9559
  }
9577
- function writeStairEntity(w, guid, name, predefinedType, ownerHistoryId, localPlacementId) {
9560
+ function writeStairEntity(w, guid, name, _predefinedType, ownerHistoryId, localPlacementId) {
9578
9561
  const id = w.nextId();
9579
9562
  w.writeLine({
9580
9563
  expressID: id,
@@ -9587,14 +9570,11 @@ function writeStairEntity(w, guid, name, predefinedType, ownerHistoryId, localPl
9587
9570
  ObjectPlacement: w.ref(localPlacementId),
9588
9571
  Representation: null,
9589
9572
  Tag: null,
9590
- PredefinedType: {
9591
- type: 3,
9592
- value: predefinedType
9593
- }
9573
+ PredefinedType: null
9594
9574
  });
9595
9575
  return id;
9596
9576
  }
9597
- function writeRampFlightEntity(w, guid, name, predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
9577
+ function writeRampFlightEntity(w, guid, name, _predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
9598
9578
  const id = w.nextId();
9599
9579
  w.writeLine({
9600
9580
  expressID: id,
@@ -9607,14 +9587,11 @@ function writeRampFlightEntity(w, guid, name, predefinedType, ownerHistoryId, lo
9607
9587
  ObjectPlacement: w.ref(localPlacementId),
9608
9588
  Representation: w.ref(productDefinitionShapeId),
9609
9589
  Tag: null,
9610
- PredefinedType: {
9611
- type: 3,
9612
- value: predefinedType
9613
- }
9590
+ PredefinedType: null
9614
9591
  });
9615
9592
  return id;
9616
9593
  }
9617
- function writeRampEntity(w, guid, name, predefinedType, ownerHistoryId, localPlacementId) {
9594
+ function writeRampEntity(w, guid, name, _predefinedType, ownerHistoryId, localPlacementId) {
9618
9595
  const id = w.nextId();
9619
9596
  w.writeLine({
9620
9597
  expressID: id,
@@ -9627,10 +9604,7 @@ function writeRampEntity(w, guid, name, predefinedType, ownerHistoryId, localPla
9627
9604
  ObjectPlacement: w.ref(localPlacementId),
9628
9605
  Representation: null,
9629
9606
  Tag: null,
9630
- PredefinedType: {
9631
- type: 3,
9632
- value: predefinedType
9633
- }
9607
+ PredefinedType: null
9634
9608
  });
9635
9609
  return id;
9636
9610
  }
@@ -9689,8 +9663,8 @@ function writeStairAssembly(w, spec, stairKey, assemblyGuid, ownerHistoryId, geo
9689
9663
  _usingCtx$2.d();
9690
9664
  }
9691
9665
  writeRelAggregates(w, deriveIfcGuidSync(`rel:AGGREGATES:STAIR:${stairKey}`), ownerHistoryId, assemblyExpressId, flightExpressIds);
9692
- writeAssemblyType(w, WebIFC.IFCSTAIRTYPE, deriveIfcGuidSync(`type:STAIR:${stairKey}`), deriveIfcGuidSync(`rel-type:STAIR:${stairKey}`), predefinedType, ownerHistoryId, [assemblyExpressId]);
9693
- if (flightExpressIds.length > 0) writeAssemblyType(w, WebIFC.IFCSTAIRFLIGHTTYPE, deriveIfcGuidSync(`type:STAIR_FLIGHT:${stairKey}`), deriveIfcGuidSync(`rel-type:STAIR_FLIGHT:${stairKey}`), "STRAIGHT", ownerHistoryId, flightExpressIds);
9666
+ writeAssemblyType(w, WebIFC.IFCSTAIRTYPE, "Stair Type", deriveIfcGuidSync(`type:STAIR:${stairKey}`), deriveIfcGuidSync(`rel-type:STAIR:${stairKey}`), predefinedType, ownerHistoryId, [assemblyExpressId]);
9667
+ if (flightExpressIds.length > 0) writeAssemblyType(w, WebIFC.IFCSTAIRFLIGHTTYPE, "Stair Flight Type", deriveIfcGuidSync(`type:STAIR_FLIGHT:${stairKey}`), deriveIfcGuidSync(`rel-type:STAIR_FLIGHT:${stairKey}`), "STRAIGHT", ownerHistoryId, flightExpressIds);
9694
9668
  return {
9695
9669
  ok: true,
9696
9670
  value: {
@@ -9750,8 +9724,8 @@ function writeRampAssembly(w, spec, rampKey, assemblyGuid, ownerHistoryId, geomS
9750
9724
  _usingCtx3.d();
9751
9725
  }
9752
9726
  writeRelAggregates(w, deriveIfcGuidSync(`rel:AGGREGATES:RAMP:${rampKey}`), ownerHistoryId, assemblyExpressId, flightExpressIds);
9753
- writeAssemblyType(w, WebIFC.IFCRAMPTYPE, deriveIfcGuidSync(`type:RAMP:${rampKey}`), deriveIfcGuidSync(`rel-type:RAMP:${rampKey}`), predefinedType, ownerHistoryId, [assemblyExpressId]);
9754
- if (flightExpressIds.length > 0) writeAssemblyType(w, WebIFC.IFCRAMPFLIGHTTYPE, deriveIfcGuidSync(`type:RAMP_FLIGHT:${rampKey}`), deriveIfcGuidSync(`rel-type:RAMP_FLIGHT:${rampKey}`), "STRAIGHT", ownerHistoryId, flightExpressIds);
9727
+ writeAssemblyType(w, WebIFC.IFCRAMPTYPE, "Ramp Type", deriveIfcGuidSync(`type:RAMP:${rampKey}`), deriveIfcGuidSync(`rel-type:RAMP:${rampKey}`), predefinedType, ownerHistoryId, [assemblyExpressId]);
9728
+ if (flightExpressIds.length > 0) writeAssemblyType(w, WebIFC.IFCRAMPFLIGHTTYPE, "Ramp Flight Type", deriveIfcGuidSync(`type:RAMP_FLIGHT:${rampKey}`), deriveIfcGuidSync(`rel-type:RAMP_FLIGHT:${rampKey}`), "STRAIGHT", ownerHistoryId, flightExpressIds);
9755
9729
  return {
9756
9730
  ok: true,
9757
9731
  value: {
@@ -9861,7 +9835,7 @@ function writeRailingGeometry(w, spec, solid, geomSubContextId, parentPlacementI
9861
9835
  usedFallback: false
9862
9836
  };
9863
9837
  }
9864
- function writeRailingEntity(w, guid, name, predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
9838
+ function writeRailingEntity(w, guid, name, _predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
9865
9839
  const id = w.nextId();
9866
9840
  w.writeLine({
9867
9841
  expressID: id,
@@ -9874,10 +9848,7 @@ function writeRailingEntity(w, guid, name, predefinedType, ownerHistoryId, local
9874
9848
  ObjectPlacement: w.ref(localPlacementId),
9875
9849
  Representation: w.ref(productDefinitionShapeId),
9876
9850
  Tag: null,
9877
- PredefinedType: {
9878
- type: 3,
9879
- value: predefinedType
9880
- }
9851
+ PredefinedType: null
9881
9852
  });
9882
9853
  return id;
9883
9854
  }
@@ -9963,7 +9934,7 @@ function writeCoveringGeometry(w, spec, geomSubContextId, parentPlacementId) {
9963
9934
  bodyItemId: extrusionId
9964
9935
  };
9965
9936
  }
9966
- function writeCoveringEntity(w, guid, name, predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
9937
+ function writeCoveringEntity(w, guid, name, _predefinedType, ownerHistoryId, localPlacementId, productDefinitionShapeId) {
9967
9938
  const id = w.nextId();
9968
9939
  w.writeLine({
9969
9940
  expressID: id,
@@ -9976,10 +9947,7 @@ function writeCoveringEntity(w, guid, name, predefinedType, ownerHistoryId, loca
9976
9947
  ObjectPlacement: w.ref(localPlacementId),
9977
9948
  Representation: w.ref(productDefinitionShapeId),
9978
9949
  Tag: null,
9979
- PredefinedType: {
9980
- type: 3,
9981
- value: predefinedType
9982
- }
9950
+ PredefinedType: null
9983
9951
  });
9984
9952
  return id;
9985
9953
  }
@@ -10925,7 +10893,7 @@ function writeElementQuantity(w, ownerHistoryId, qtoName, quantityIds) {
10925
10893
  OwnerHistory: w.ref(ownerHistoryId),
10926
10894
  Name: w.mkType(WebIFC.IFCLABEL, qtoName),
10927
10895
  Description: null,
10928
- MethodOfMeasurement: null,
10896
+ MethodOfMeasurement: w.mkType(WebIFC.IFCLABEL, "BaseQuantities"),
10929
10897
  Quantities: quantityIds.map((id) => w.ref(id))
10930
10898
  });
10931
10899
  return qtoId;
@@ -11605,11 +11573,11 @@ var TYPE_CONSTANT = {
11605
11573
  IFCRAILINGTYPE: WebIFC.IFCRAILINGTYPE,
11606
11574
  IFCCOVERINGTYPE: WebIFC.IFCCOVERINGTYPE
11607
11575
  };
11608
- function commonTypeFields(w, guid, ownerHistoryId) {
11576
+ function commonTypeFields(w, guid, ownerHistoryId, name) {
11609
11577
  return {
11610
11578
  GlobalId: w.mkType(WebIFC.IFCGLOBALLYUNIQUEID, guid),
11611
11579
  OwnerHistory: w.ref(ownerHistoryId),
11612
- Name: null,
11580
+ Name: w.mkType(WebIFC.IFCLABEL, name),
11613
11581
  Description: null,
11614
11582
  ApplicableOccurrence: null,
11615
11583
  HasPropertySets: null,
@@ -11619,7 +11587,7 @@ function commonTypeFields(w, guid, ownerHistoryId) {
11619
11587
  }
11620
11588
  function writeTypeObject(w, typeName, guid, ownerHistoryId, predefinedType) {
11621
11589
  const id = w.nextId();
11622
- const base = commonTypeFields(w, guid, ownerHistoryId);
11590
+ const base = commonTypeFields(w, guid, ownerHistoryId, `${typeName.slice(3, -4).replace("CURTAINWALL", "CURTAIN WALL").toLowerCase().replace(/(^|\s)\S/g, (c) => c.toUpperCase())} Type`);
11623
11591
  if (typeName === "IFCDOORTYPE") {
11624
11592
  w.writeLine({
11625
11593
  expressID: id,
@@ -13954,10 +13922,11 @@ async function fromIfc(bytes, options = {}) {
13954
13922
  const scale = readLengthScale(reader);
13955
13923
  const spatialRoot = buildSpatialTree(reader, scale);
13956
13924
  const containment = buildElementContainmentMap(reader);
13925
+ const typeEnums = buildTypePredefinedMap(reader);
13957
13926
  const elements = [];
13958
13927
  const byExpressId = /* @__PURE__ */ new Map();
13959
13928
  for (const [type, category] of ELEMENT_TYPES) for (const expressId of reader.getLinesOfType(type)) {
13960
- const element = readElement(reader, expressId, category, scale, containment, options.skipGeometry ?? false, diagnostics);
13929
+ const element = readElement(reader, expressId, category, scale, containment, typeEnums, options.skipGeometry ?? false, diagnostics);
13961
13930
  if (element === null) continue;
13962
13931
  elements.push(element);
13963
13932
  byExpressId.set(element.expressId, element);
@@ -13984,7 +13953,7 @@ async function fromIfc(bytes, options = {}) {
13984
13953
  * element line itself is unreadable (an `error` diagnostic is recorded). Any
13985
13954
  * sub-read failure is isolated by its own reader and never aborts the element.
13986
13955
  */
13987
- function readElement(reader, expressId, category, scale, containment, skipGeometry, diagnostics) {
13956
+ function readElement(reader, expressId, category, scale, containment, typeEnums, skipGeometry, diagnostics) {
13988
13957
  try {
13989
13958
  const line = reader.getLine(expressId);
13990
13959
  if (line === null) {
@@ -13993,7 +13962,7 @@ function readElement(reader, expressId, category, scale, containment, skipGeomet
13993
13962
  }
13994
13963
  const guid = readGuid(line);
13995
13964
  const name = readName(reader, line);
13996
- const predefinedType = readPredefinedType(line);
13965
+ const predefinedType = readPredefinedType(line) ?? typeEnums.get(expressId);
13997
13966
  const voidedBy = readVoids(reader, expressId).map((v) => v.openingExpressId);
13998
13967
  const fills = findFills(reader, expressId);
13999
13968
  const geometry = skipGeometry ? {
@@ -14112,6 +14081,27 @@ function readName(reader, line) {
14112
14081
  const raw = line["Name"]?.value;
14113
14082
  return typeof raw === "string" ? reader.decodeText(raw) : "";
14114
14083
  }
14084
+ /** occurrence expressId -> the relating type object's PredefinedType literal. */
14085
+ function buildTypePredefinedMap(reader) {
14086
+ const map = /* @__PURE__ */ new Map();
14087
+ for (const relId of reader.getLinesOfType(WebIFC.IFCRELDEFINESBYTYPE)) {
14088
+ const rel = reader.getLine(relId);
14089
+ if (rel === null) continue;
14090
+ const typeId = refValue(rel["RelatingType"]);
14091
+ if (typeId === void 0) continue;
14092
+ const typeLine = reader.getLine(typeId);
14093
+ if (typeLine === null) continue;
14094
+ const pred = readPredefinedType(typeLine);
14095
+ if (pred === void 0) continue;
14096
+ const related = rel["RelatedObjects"];
14097
+ if (!Array.isArray(related)) continue;
14098
+ for (const ref of related) {
14099
+ const id = refValue(ref);
14100
+ if (id !== void 0) map.set(id, pred);
14101
+ }
14102
+ }
14103
+ return map;
14104
+ }
14115
14105
  function readPredefinedType(line) {
14116
14106
  const raw = line["PredefinedType"]?.value;
14117
14107
  return typeof raw === "string" ? raw : void 0;
@@ -14516,11 +14506,7 @@ var CurtainWallSpecSchema = object({
14516
14506
  axisX: unitVec$5,
14517
14507
  axisZ: unitVec$5,
14518
14508
  materialName: string().min(1),
14519
- predefinedType: _enum([
14520
- "CURTAIN_WALL",
14521
- "NOTDEFINED",
14522
- "USERDEFINED"
14523
- ]).optional(),
14509
+ predefinedType: _enum(["NOTDEFINED", "USERDEFINED"]).optional(),
14524
14510
  panelMaterialName: string().min(1).optional(),
14525
14511
  mullionMaterialName: string().min(1).optional(),
14526
14512
  isExternal: boolean().optional(),
@@ -16747,6 +16733,8 @@ function familiesToBim(root, options) {
16747
16733
  return buildingResult;
16748
16734
  }
16749
16735
  const buildingId = buildingResult.value;
16736
+ const project = model.getProject();
16737
+ if (project !== null) model.aggregate(project.localId, siteResult.value);
16750
16738
  model.aggregate(siteResult.value, buildingId);
16751
16739
  const idByKeyPath = /* @__PURE__ */ new Map();
16752
16740
  const walk = (el, storeyId) => {
@@ -8,5 +8,5 @@ export interface CoveringRepresentationIds {
8
8
  bodyItemId: number;
9
9
  }
10
10
  export declare function writeCoveringGeometry(w: IfcWriter, spec: CoveringSpec, geomSubContextId: number, parentPlacementId: number | null): CoveringRepresentationIds;
11
- export declare function writeCoveringEntity(w: IfcWriter, guid: IfcGuid, name: string, predefinedType: CoveringPredefinedType, ownerHistoryId: number, localPlacementId: number, productDefinitionShapeId: number): number;
11
+ export declare function writeCoveringEntity(w: IfcWriter, guid: IfcGuid, name: string, _predefinedType: CoveringPredefinedType, ownerHistoryId: number, localPlacementId: number, productDefinitionShapeId: number): number;
12
12
  export declare function writeRelCoversBldgElements(w: IfcWriter, guid: IfcGuid, ownerHistoryId: number, relatingBuildingElementId: number, relatedCoveringIds: readonly number[]): number;
@@ -14,8 +14,8 @@ export declare function writeStorey(w: IfcWriter, guid: IfcGuid, name: string, e
14
14
  placementId: number;
15
15
  };
16
16
  export declare function writeWallEntity(w: IfcWriter, guid: IfcGuid, name: string, ownerHistoryId: number, localPlacementId: number, productDefinitionShapeId: number): number;
17
- export declare function writeSlabEntity(w: IfcWriter, guid: IfcGuid, name: string, predefinedType: 'FLOOR' | 'ROOF' | 'LANDING' | 'BASESLAB', ownerHistoryId: number, localPlacementId: number, productDefinitionShapeId: number): number;
17
+ export declare function writeSlabEntity(w: IfcWriter, guid: IfcGuid, name: string, _predefinedType: 'FLOOR' | 'ROOF' | 'LANDING' | 'BASESLAB', ownerHistoryId: number, localPlacementId: number, productDefinitionShapeId: number): number;
18
18
  export type BeamPredefinedTypeIfc = 'BEAM' | 'JOIST' | 'LINTEL' | 'HOLLOWCORE' | 'PURLIN' | 'RAFTER' | 'SPANDREL' | 'T_BEAM' | 'NOTDEFINED';
19
- export declare function writeBeamEntity(w: IfcWriter, guid: IfcGuid, name: string, predefinedType: BeamPredefinedTypeIfc, ownerHistoryId: number, localPlacementId: number, productDefinitionShapeId: number): number;
19
+ export declare function writeBeamEntity(w: IfcWriter, guid: IfcGuid, name: string, _predefinedType: BeamPredefinedTypeIfc, ownerHistoryId: number, localPlacementId: number, productDefinitionShapeId: number): number;
20
20
  export type ColumnPredefinedTypeIfc = 'COLUMN' | 'PILASTER' | 'NOTDEFINED';
21
- export declare function writeColumnEntity(w: IfcWriter, guid: IfcGuid, name: string, predefinedType: ColumnPredefinedTypeIfc, ownerHistoryId: number, localPlacementId: number, productDefinitionShapeId: number): number;
21
+ export declare function writeColumnEntity(w: IfcWriter, guid: IfcGuid, name: string, _predefinedType: ColumnPredefinedTypeIfc, ownerHistoryId: number, localPlacementId: number, productDefinitionShapeId: number): number;
@@ -7,5 +7,5 @@ export interface FoundationRepresentationIds {
7
7
  }
8
8
  export declare function writeFootingGeometry(w: IfcWriter, spec: FootingSpec, geomSubContextId: number, parentPlacementId: number | null): FoundationRepresentationIds;
9
9
  export declare function writePileGeometry(w: IfcWriter, spec: PileSpec, geomSubContextId: number, parentPlacementId: number | null): FoundationRepresentationIds;
10
- export declare function writeFootingEntity(w: IfcWriter, guid: IfcGuid, name: string, predefinedType: FootingPredefinedType, ownerHistoryId: number, localPlacementId: number, productDefinitionShapeId: number): number;
11
- export declare function writePileEntity(w: IfcWriter, guid: IfcGuid, name: string, predefinedType: PilePredefinedType, constructionType: PileConstructionType | null, ownerHistoryId: number, localPlacementId: number, productDefinitionShapeId: number): number;
10
+ export declare function writeFootingEntity(w: IfcWriter, guid: IfcGuid, name: string, _predefinedType: FootingPredefinedType, ownerHistoryId: number, localPlacementId: number, productDefinitionShapeId: number): number;
11
+ export declare function writePileEntity(w: IfcWriter, guid: IfcGuid, name: string, _predefinedType: PilePredefinedType, constructionType: PileConstructionType | null, ownerHistoryId: number, localPlacementId: number, productDefinitionShapeId: number): number;
@@ -14,4 +14,4 @@ export interface RailingRepresentationIds {
14
14
  usedFallback: boolean;
15
15
  }
16
16
  export declare function writeRailingGeometry(w: IfcWriter, spec: RailingSpec, solid: ValidSolid, geomSubContextId: number, parentPlacementId: number | null): RailingRepresentationIds;
17
- export declare function writeRailingEntity(w: IfcWriter, guid: IfcGuid, name: string, predefinedType: RailingPredefinedType, ownerHistoryId: number, localPlacementId: number, productDefinitionShapeId: number): number;
17
+ export declare function writeRailingEntity(w: IfcWriter, guid: IfcGuid, name: string, _predefinedType: RailingPredefinedType, ownerHistoryId: number, localPlacementId: number, productDefinitionShapeId: number): number;
@@ -8,7 +8,7 @@ export type RoofTypeEnum = RoofPredefinedType;
8
8
  * are the IfcLocalPlacement and IfcProductDefinitionShape express IDs produced by
9
9
  * the geometry layer; pass `null` for either when not available.
10
10
  */
11
- export declare function writeRoofEntity(w: IfcWriter, guid: IfcGuid, name: string, predefinedType: RoofTypeEnum, ownerHistoryId: number, localPlacementId: number | null, productDefinitionShapeId: number | null): number;
11
+ export declare function writeRoofEntity(w: IfcWriter, guid: IfcGuid, name: string, _predefinedType: RoofTypeEnum, ownerHistoryId: number, localPlacementId: number | null, productDefinitionShapeId: number | null): number;
12
12
  export interface RoofTypeWriteResult {
13
13
  typeExpressId: number;
14
14
  relExpressId: number;
@@ -6,6 +6,6 @@ export interface SpaceRepresentationIds {
6
6
  productDefinitionShapeId: number;
7
7
  }
8
8
  export declare function writeSpaceGeometry(w: IfcWriter, spec: SpaceSpec, geomSubContextId: number, parentPlacementId: number | null): SpaceRepresentationIds;
9
- export declare function writeSpaceEntity(w: IfcWriter, guid: IfcGuid, name: string, longName: string | null, predefinedType: SpacePredefinedType, ownerHistoryId: number, localPlacementId: number, productDefinitionShapeId: number): number;
9
+ export declare function writeSpaceEntity(w: IfcWriter, guid: IfcGuid, name: string, longName: string | null, _predefinedType: SpacePredefinedType, ownerHistoryId: number, localPlacementId: number, productDefinitionShapeId: number): number;
10
10
  export type SpaceBoundaryConnectionType = 'PHYSICAL' | 'VIRTUAL' | 'NOTDEFINED';
11
11
  export declare function writeRelSpaceBoundary(w: IfcWriter, guid: IfcGuid, ownerHistoryId: number, spaceExpressId: number, elementExpressId: number, connectionType: SpaceBoundaryConnectionType): void;
package/dist/index.d.ts CHANGED
@@ -34,7 +34,7 @@ export { checkReferentialIntegrity } from './validation/referentialIntegrity.js'
34
34
  export { checkSchema } from './validation/schemaCheck.js';
35
35
  export { checkRoundTrip } from './validation/roundTrip.js';
36
36
  export { checkGeometryValidity } from './validation/geometryValidity.js';
37
- export { issue, emptyReport, hasErrors, countBySeverity, } from './validation/severity.js';
37
+ export { issue, emptyReport, hasErrors, countBySeverity } from './validation/severity.js';
38
38
  export { writeIfcType } from './ifc-writer/typeWriter.js';
39
39
  export { writeZoneEntity, writeSystemEntity, writeRelAssignsToGroup, } from './ifc-writer/groupWriter.js';
40
40
  export { IFC_SCHEMAS, DEFAULT_IFC_SCHEMA, fileSchemaString, isIfcSchema, schemaSupports, } from './ifc-writer/schemaVersion.js';
@@ -57,7 +57,7 @@ export type { RoofSpec, RoofPredefinedType } from './specs/roofSpec.js';
57
57
  export type { CurtainWallSpec, CurtainWallPredefinedType } from './specs/curtainWallSpec.js';
58
58
  export type { CurtainWallGrid, CurtainWallComponent } from './elementFns/curtainWallFns.js';
59
59
  export type { FootingSpec, PileSpec, FootingPredefinedType, PilePredefinedType, PileConstructionType, } from './specs/foundationSpec.js';
60
- export type { StairSpec, StairFlightSpec, StairPredefinedType, } from './specs/stairSpec.js';
60
+ export type { StairSpec, StairFlightSpec, StairPredefinedType } from './specs/stairSpec.js';
61
61
  export type { RampSpec, RampFlightSpec, RampPredefinedType, RampFlightPredefinedType, } from './specs/rampSpec.js';
62
62
  export type { RailingSpec, RailingPredefinedType } from './specs/railingSpec.js';
63
63
  export type { CoveringSpec, CoveringPredefinedType } from './specs/coveringSpec.js';
@@ -69,7 +69,7 @@ export type { PathConnectionTypeIfc } from './ifc-writer/connectivityWriter.js';
69
69
  export type { DoorSpec, WindowSpec, SlabOpeningInput } from './specs/openingSpec.js';
70
70
  export type { ProxySpec } from './specs/proxySpec.js';
71
71
  export type { ProjectSpec, SiteSpec, BuildingSpec, StoreySpec } from './specs/spatialSpec.js';
72
- export type { BimCategory, BimElement, AnyBimElement, OpeningSpec, WallOpeningSpec, SlabOpeningSpec } from './types/bimTypes.js';
72
+ export type { BimCategory, BimElement, AnyBimElement, OpeningSpec, WallOpeningSpec, SlabOpeningSpec, } from './types/bimTypes.js';
73
73
  export { isWallOpening, isSlabOpening } from './types/bimTypes.js';
74
74
  export type { BimRelationship, AssociatesMaterialRel, AssociatesClassificationRel, VoidsWallRel, VoidsSlabRel, FillsOpeningRel, SpaceBoundaryRel, NestsRel, ConnectsElementsRel, ConnectsPathElementsRel, CoversElementRel, AssignsToGroupRel, } from './types/relationships.js';
75
75
  export type { MaterialLayer } from './types/materialTypes.js';
@@ -1,7 +1,7 @@
1
1
  import { BimError } from '../errors/bimError.js';
2
2
  import { Result } from 'brepjs';
3
3
  import { ClassificationRef } from '../types/classificationTypes.js';
4
- export type CurtainWallPredefinedType = 'CURTAIN_WALL' | 'NOTDEFINED' | 'USERDEFINED';
4
+ export type CurtainWallPredefinedType = 'NOTDEFINED' | 'USERDEFINED';
5
5
  /**
6
6
  * A planar curtain wall, modelled as a rectangular grid of glazing panels
7
7
  * (IfcPlate) framed by mullions (IfcMember). The wall spans `width` (along the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brepjs-bim",
3
- "version": "0.15.0",
3
+ "version": "0.15.2",
4
4
  "description": "BIM layer for brepjs — IFC4-aligned parametric building elements",
5
5
  "keywords": [
6
6
  "bim",