[B5] IFC-Export: Dach als IfcRoof-Aggregat mit IfcSlab ROOF je Dachfläche (Schichten als IfcMaterialLayerSetUsage, Pset_SlabCommon, Qto_SlabBaseQuantities; IFC4 und IFC2x3)

This commit is contained in:
Claude committed 2026-11-18 08:37:42 +00:00
1 parent f22cee4557
commit 5bd56a4fd6
11 files changed
+300 -50

No files matched your search

@@ -68,6 +68,8 @@ pub(super) struct Builder {
pub(super) column_materials: Vec<(String, String, Vec<usize>)>,
/// Bauteil-Schlüssel (wie für die GlobalId, z. B. `wall/<id>`) → Entität; Ziel von Klassifikation/Zone/Attach.
pub(super) elements: HashMap<String, usize>,
/// Wirt für IfcRelVoidsElement, wenn der Schlüssel ein Aggregat ist (Dach → erste Dachfläche).
pub(super) void_alias: HashMap<String, usize>,
/// [201] Übernommene GlobalIds (Schlüssel wie für `gid`), Vorrang vor der abgeleiteten.
pub(super) guid_override: HashMap<String, String>,
/// IFC2x3: Türen/Fenster je (Tür?, Ausführung) → Bauteile; am Ende je ein IfcDoorStyle/IfcWindowStyle.
@@ -590,6 +592,22 @@ impl Builder {
(set != 0).then_some(set)
}
/// Aggregat ohne eigene Darstellung (IfcRoof): Typ, Eingliederung und Psets wie `finish_typed`.
#[allow(clippy::too_many_arguments)]
pub(super) fn finish_aggregate(&mut self, ifc: &str, guid_key: String, name: &str, ty: &Option<TypeRef>, psets: &[Pset], structure: i64, placement: usize, predefined: String) -> usize {
let guid = self.gid(&guid_key);
let entity = self.add(ifc, format!("{guid},#{},{},$,$,#{placement},$,$,{predefined}", self.owner_history, ifc_string(name)));
if let Some(i) = ty.as_ref().map(|t| self.type_for(t)) {
self.types[i].occurrences.push(entity);
}
self.add_to_containment(structure, entity);
for p in psets {
self.add_pset(p, entity, &guid_key);
}
self.elements.insert(guid_key, entity);
entity
}
/// Gemeinsamer Abschluss der Bauteile mit Typ und Psets: Typ (falls vorhanden) anlegen, Entität
/// schreiben, Typ-Exemplar, Eingliederung und Psets vormerken.
#[allow(clippy::too_many_arguments)]
+68 -10
View File
@@ -85,7 +85,12 @@
// ceiling_height (FinishCeilingHeight, mittlere lichte Höhe), PTS, net_area, gross_area,
// sia_category, PSETS
// END_SPACES = 8 (bündelt die Räume je Geschoss zu IfcRelAggregates)
// ROOF = 9, structure, id, name, predefined (Text), TYPEREF, PSETS, MESH
// ROOF = 9 ([B5] Aggregat), structure, id, name, predefined (Text), TYPEREF, PSETS, n_parts,
// (name, plane (Index der Dachfläche, −1 = Sonderteil), PSETS, MESH) × n_parts
// IfcRoof (PredefinedType nach Dachform; Typ, Pset_RoofCommon, Qto_RoofBaseQuantities) ohne Darstellung, per
// IfcRelAggregates je Teil ein IfcSlab ROOF mit Netz, Pset_SlabCommon, Qto_SlabBaseQuantities und den Schichten
// des Dachtyps als IfcMaterialLayerSetUsage (AXIS3, NEGATIVE). Teile: `roof/<id>/p<plane>` bzw. `roof/<id>/part<k>`;
// OPENING_SOLID mit Wirt `roof/<id>` sitzt im ersten Teil, mit `roof/<id>/p<plane>` in dieser Fläche.
// COLUMN = 10, structure, id, label, PTS, z_rel, depth, component_id (−1 = keine), component_name, PSETS
// COLUMN_PIECES = 20, structure, id, label, n, (PTS, z_rel, depth) × n, component_id (−1 = keine),
// component_name, PSETS ([141] Stütze mit Höhenabschnitten, je Abschnitt ein eigenes beschnittenes
@@ -379,6 +384,7 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
spaces: Vec::new(),
column_materials: Vec::new(),
elements: HashMap::new(),
void_alias: HashMap::new(),
fill_styles: Vec::new(),
};
let v2 = schema == Schema::Ifc2x3;
@@ -848,7 +854,13 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
}
let host_entity = match host.strip_prefix("wall/") {
Some(id) => w.walls.get(id).map(|x| x.0),
None => w.elements.get(&host).copied(),
None => w
.elements
.get(&host)
.or_else(|| w.void_alias.get(&host))
// `roof/<id>/p<n>` ohne diese Fläche (verschnittenes Dach): erster Teil des Dachs.
.or_else(|| host.rsplit_once("/p").and_then(|(roof, n)| n.parse::<u32>().ok().and_then(|_| w.void_alias.get(roof))))
.copied(),
};
let Some(host_entity) = host_entity else { continue };
let parent = w.placement_of(structure);
@@ -1169,9 +1181,46 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
let predefined = r.string()?;
let ty = r.type_ref()?;
let psets = r.psets()?;
let mesh = r.mesh()?;
let (placement, shape) = w.emit_triangulated_product(&mesh, w.placement_of(structure));
w.finish_typed("IFCROOF", format!("roof/{id}"), &name, &ty, &psets, structure, placement, shape, Some(enum_(&predefined)), false);
let n_parts = r.idx()?;
// [B5] IfcRoof als Aggregat ohne eigene Darstellung; je Dachfläche (bzw. Sonderteil) ein IfcSlab ROOF mit
// Schichten (IfcMaterialLayerSetUsage), Pset_SlabCommon und Qto_SlabBaseQuantities.
let placement = w.emit_placement(0.0, w.placement_of(structure));
let roof_key = format!("roof/{id}");
let roof_guid = w.gid(&roof_key);
let roof_entity = w.finish_aggregate("IFCROOF", roof_key.clone(), &name, &ty, &psets, structure, placement, enum_(&predefined));
let set = ty.as_ref().and_then(|t| w.layer_set_of(t));
let mut slabs = Vec::new();
for _ in 0..n_parts {
let part_name = r.string()?;
let plane = r.raw()?;
let part_psets = r.psets()?;
let mesh = r.mesh()?;
let (part_placement, shape) = w.emit_triangulated_product(&mesh, placement);
let key = if plane >= 0.0 { format!("{roof_key}/p{}", plane as i64) } else { format!("{roof_key}/part{}", slabs.len()) };
// GlobalId aus der des Dachs (stabil auch nach Import → Export, wo die Dach-id eine andere ist).
let guid = ifc_string(&ifc_guid(&format!("{roof_guid}/{}", key.rsplit('/').next().unwrap_or(""))));
let slab = w.emit_building_element("IFCSLAB", guid, &part_name, part_placement, shape, Some(enum_("ROOF")));
for p in &part_psets {
w.add_pset(p, slab, &key);
}
w.elements.insert(key, slab);
slabs.push(slab);
}
if let Some(&first) = slabs.first() {
// Dachfenster ohne Flächenangabe (verschnittenes Dach) sitzen im ersten Teil.
w.void_alias.insert(roof_key.clone(), first);
let g = w.gid(&format!("aggregates/{roof_key}"));
w.add("IFCRELAGGREGATES", format!("{g},#{},$,$,#{roof_entity},{}", w.owner_history, refs(&slabs)));
if let Some(set) = set {
// Schichten von aussen (oben) nach innen: Dickenrichtung = lokale Z-Achse, abwärts.
let u = w.add(
"IFCMATERIALLAYERSETUSAGE",
format!("#{set},{},{},0.{}", enum_("AXIS3"), enum_("NEGATIVE"), if v2 { "" } else { ",$" }),
);
let g = w.gid(&format!("{roof_key}/material"));
w.add("IFCRELASSOCIATESMATERIAL", format!("{g},#{},$,$,{},#{u}", w.owner_history, refs(&slabs)));
}
}
}
c if c == REC_COLUMN || c == REC_COLUMN_PIECES || c == REC_BEAM => {
let structure = r.structure(n_storeys)?;
@@ -1244,12 +1293,21 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
continue; // ohne Code keine Referenz
}
let Some(&entity) = w.elements.get(&key) else { continue };
if let Some((_, _, v)) = by_code.iter_mut().find(|(c, _, _)| *c == code) {
if !v.contains(&entity) {
v.push(entity);
// [B5] Dach: auch die Dachflächen (Teile des IfcRoof) tragen die Klassifikation (Leser erben nicht).
let mut targets = vec![entity];
if key.starts_with("roof/") {
let mut parts: Vec<(&String, usize)> = w.elements.iter().filter(|(k, _)| k.strip_prefix(&format!("{key}/")).is_some_and(|t| t.starts_with('p'))).map(|(k, v)| (k, *v)).collect();
parts.sort();
targets.extend(parts.into_iter().map(|x| x.1));
}
for entity in targets {
if let Some((_, _, v)) = by_code.iter_mut().find(|(c, _, _)| *c == code) {
if !v.contains(&entity) {
v.push(entity);
}
} else {
by_code.push((code.clone(), ref_name.clone(), vec![entity]));
}
} else {
by_code.push((code, ref_name, vec![entity]));
}
}
if !by_code.is_empty() {
+28 -8
View File
@@ -284,6 +284,11 @@ fn full_house_in(mut b: B, with_geo: bool) -> B {
b.str("Beton");
b.n(&[0.3]);
b.ref_pset("Pset_RoofCommon", "Satteldach");
// [B5] Teile: eine Dachfläche (Index 0) mit Pset_SlabCommon.
b.n(&[1.0]);
b.str("Satteldach 1");
b.n(&[0.0]);
b.ref_pset("Pset_SlabCommon", "Satteldach");
b.mesh_tetra();
// Stütze mit Material.
b.n(&[REC_COLUMN, 0.0]);
@@ -354,7 +359,7 @@ fn volles_haus_ist_wohlgeformt() {
assert!(ifc.is_ascii(), "Datei muss reines ASCII sein");
check_structure(&ifc);
assert_eq!(count(&ifc, "IFCWALL"), 2);
assert_eq!(count(&ifc, "IFCSLAB"), 1);
assert_eq!(count(&ifc, "IFCSLAB"), 2); // Decke + Dachfläche des Dachs
assert_eq!(count(&ifc, "IFCROOF"), 1);
assert_eq!(count(&ifc, "IFCCOLUMN"), 1);
assert_eq!(count(&ifc, "IFCSTAIR"), 1);
@@ -376,11 +381,17 @@ fn volles_haus_ist_wohlgeformt() {
assert_eq!(count(&ifc, "IFCMATERIALLAYERSET"), 2); // Wandtyp + Dachtyp
assert_eq!(count(&ifc, "IFCMATERIAL"), 2); // Beton (geteilt mit Dachtyp und Stütze) + Dämmung
assert_eq!(count(&ifc, "IFCRELDEFINESBYTYPE"), 2);
assert_eq!(count(&ifc, "IFCPROPERTYSET"), 5); // Wall, Space, Roof, Column + CH_Raum (Tür ohne Pset)
assert_eq!(count(&ifc, "IFCPROPERTYSET"), 6); // Wall, Space, Roof, SlabCommon der Dachfläche, Column + CH_Raum (Tür ohne Pset)
// Eingliederung: Geschoss (Wände, Decke, Treppe, Tür, Dach, Stütze) und Gebäude (Extrusion).
assert_eq!(count(&ifc, "IFCRELCONTAINEDINSPATIALSTRUCTURE"), 2);
// Project→Site, Site→Building, Building→Storeys, Geschoss→Räume.
assert_eq!(count(&ifc, "IFCRELAGGREGATES"), 4);
// Project→Site, Site→Building, Building→Storeys, Geschoss→Räume, Dach→Dachfläche.
assert_eq!(count(&ifc, "IFCRELAGGREGATES"), 5);
// [B5] Dach als Aggregat: IfcRoof ohne Darstellung, darunter IfcSlab ROOF mit den Schichten des Dachtyps.
let roof = first_line(&ifc, "IFCROOF");
assert!(roof.ends_with(",$,$,.GABLE_ROOF.);"), "{roof}");
assert!(first_line(&ifc, "IFCRELAGGREGATES").len() > 0);
assert!(ifc.lines().any(|l| l.contains("=IFCSLAB(") && l.ends_with(".ROOF.);")), "IfcSlab ROOF");
assert!(ifc.lines().any(|l| l.contains("=IFCMATERIALLAYERSETUSAGE(") && l.ends_with(".AXIS3.,.NEGATIVE.,0.,$);")));
}
/// Zeile der ersten Entität eines Typs.
@@ -581,7 +592,7 @@ fn wand_mit_achse_und_layer_set_usage() {
let ifc = build(&full_house(false)).unwrap();
check_structure(&ifc);
// Nur W1 hat Wandsystem: eine Usage, eine Axis-Darstellung, ein Axis-Kontext.
assert_eq!(count(&ifc, "IFCMATERIALLAYERSETUSAGE"), 1);
assert_eq!(count(&ifc, "IFCMATERIALLAYERSETUSAGE"), 2); // Wand W1 + Dachflächen
assert_eq!(count(&ifc, "IFCGEOMETRICREPRESENTATIONSUBCONTEXT"), 1);
let usage = first_line(&ifc, "IFCMATERIALLAYERSETUSAGE");
assert!(usage.contains(".AXIS2.,.POSITIVE.,-0.2,$"), "{usage}");
@@ -954,8 +965,9 @@ fn ifc2x3_kopf_und_entitaeten() {
// W1 hat Achse + Usage (StandardCase), W2 nicht (IfcWall).
assert_eq!(count(&ifc, "IFCWALLSTANDARDCASE"), 1);
assert_eq!(count(&ifc, "IFCWALL"), 1);
assert_eq!(count(&ifc, "IFCMATERIALLAYERSETUSAGE"), 1);
assert_eq!(count(&ifc, "IFCMATERIALLAYERSETUSAGE"), 2); // Wand + Dachflächen (IFC2x3: keine ReferenceExtent)
assert!(first_line(&ifc, "IFCMATERIALLAYERSETUSAGE").ends_with(".AXIS2.,.POSITIVE.,-0.2);"));
assert!(ifc.lines().any(|l| l.contains("=IFCMATERIALLAYERSETUSAGE(") && l.ends_with(".AXIS3.,.NEGATIVE.,0.);")));
// Wand ohne PredefinedType (8 Attribute), Stütze ebenso.
assert!(first_line(&ifc, "IFCWALL").ends_with(",$);") && first_line(&ifc, "IFCWALL").matches(',').count() == 7, "{}", first_line(&ifc, "IFCWALL"));
assert!(first_line(&ifc, "IFCCOLUMN").ends_with(",$);"), "{}", first_line(&ifc, "IFCCOLUMN"));
@@ -979,7 +991,7 @@ fn ifc2x3_kopf_und_entitaeten() {
assert_eq!(count(&ifc, "IFCFACE"), 4);
assert_eq!(count(&ifc, "IFCPOLYLOOP"), 4);
assert!(ifc.contains("'Body','Brep'"));
assert_eq!(count(&ifc, "IFCRELASSOCIATESMATERIAL"), 4); // Wandtyp, Usage, Dachschichten, Stütze
assert_eq!(count(&ifc, "IFCRELASSOCIATESMATERIAL"), 5); // Wandtyp, Usage, Dachschichten (am Dach), Usage der Dachflächen, Stütze
// Stile der Teilrollen über IfcPresentationStyleAssignment.
assert_eq!(count(&ifc, "IFCPRESENTATIONSTYLEASSIGNMENT"), 3);
// Mengen ohne Formula.
@@ -1037,6 +1049,10 @@ fn dachfenster_oeffnungskoerper() {
b.str("GABLE_ROOF");
b.no_type();
b.no_psets();
b.n(&[1.0]);
b.str("Dachfläche 1");
b.n(&[0.0]);
b.no_psets();
b.n(&[4.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0]);
b.n(&[2.0, 0.0, 1.0, 2.0, 0.0, 2.0, 3.0]);
b.f.push(0.0);
@@ -1081,6 +1097,10 @@ fn ifc2x3_offenes_netz_ist_shell_based_surface_model() {
b.str("FLAT_ROOF");
b.no_type();
b.no_psets();
b.n(&[1.0]);
b.str("Dachfläche 1");
b.n(&[0.0]);
b.no_psets();
// Zwei Dreiecke (offen) plus ein entartetes (doppelte Ecke).
b.n(&[4.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0]);
b.n(&[3.0, 0.0, 1.0, 2.0, 0.0, 2.0, 3.0, 0.0, 0.0, 1.0]);
@@ -1090,7 +1110,7 @@ fn ifc2x3_offenes_netz_ist_shell_based_surface_model() {
assert_eq!(count(&ifc, "IFCSHELLBASEDSURFACEMODEL"), 1);
assert_eq!(count(&ifc, "IFCOPENSHELL"), 1);
assert_eq!(count(&ifc, "IFCFACE"), 2);
assert_eq!(count(&ifc, "IFCCARTESIANPOINT"), 6); // Ursprung, 4 Ecken (je einmal), Placement
assert_eq!(count(&ifc, "IFCCARTESIANPOINT"), 7); // Ursprung, 4 Ecken (je einmal), 2 Placements (Dach, Dachfläche)
assert!(ifc.contains("'Body','SurfaceModel'"));
assert_eq!(count(&ifc, "IFCFACETEDBREP"), 0);
}