Merge [B5][B4][70] IFC: eBKP-H-Hauptgruppen bzw. Modell-Ebenen als Klassifikation (Option), SIA-416-Zonen, Geschoss-GF/NGF; Import liest Klassifikation und Zonen

Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
Claude committed 2026-10-28 16:46:34 +00:00
commit a72ac89795
15 files changed
+945 -16

No files matched your search

+221 -1
View File
@@ -61,6 +61,17 @@
// ROOF = 9, structure, id, name, predefined (Text), TYPEREF, PSETS, MESH
// COLUMN = 10, structure, id, label, PTS, z_rel, depth, component_id (−1 = keine), component_name, PSETS
// END_COLUMNS = 11 (Materialzuordnung der Stützen)
// CLASSIFICATION = 12, name, source, edition (Text, leer = keine), n_refs, (key, code, ref_name) × n_refs
// ([B5], 28.10.) Ein Klassifikationssystem (IfcClassification) mit je Code einer
// IfcClassificationReference und EINER IfcRelAssociatesClassification für alle Bauteile mit
// diesem Code. `key` = Schlüssel des Bauteils wie für seine GlobalId (`wall/<id>`, `slab/<id>`,
// `roof/<id>`, `column/<id>`, `stair/<id>`, `fill/<Öffnungs-id>` (Tür/Fenster), `space/<id>`,
// `storey/<id>`); unbekannte Schlüssel werden übersprungen (kein Fehler). Gehört ans Ende
// (nach allen Bauteilen); ein System ohne auflösbares Bauteil entsteht nicht.
// ZONE = 13, key, name, long_name, n_spaces, (space_id) × n_spaces, PSETS
// IfcZone mit IfcRelAssignsToGroup der Räume (`space/<id>`-Entitäten; unbekannte ids werden
// übersprungen, ohne Raum keine Zone). GlobalId aus `zone/<key>`; Psets/Mengen wie bei Bauteilen.
// ATTACH = 14, key, PSETS (Psets/Mengen an ein schon geschriebenes Bauteil/Geschoss, Schlüssel wie oben)
//
// Danach folgen (am Pufferende) Typ-Zuordnungen, Eigenschaftssätze, räumliche Eingliederung und Fuss.
//
@@ -89,6 +100,9 @@ pub const REC_END_SPACES: f64 = 8.0;
pub const REC_ROOF: f64 = 9.0;
pub const REC_COLUMN: f64 = 10.0;
pub const REC_END_COLUMNS: f64 = 11.0;
pub const REC_CLASSIFICATION: f64 = 12.0;
pub const REC_ZONE: f64 = 13.0;
pub const REC_ATTACH: f64 = 14.0;
// ── IFC-GUID (Kompression nach IfcOpenShell `guid.compress`) ────────────────
@@ -785,6 +799,8 @@ struct Builder {
spaces: Vec<(i64, Vec<usize>)>,
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.
elements: HashMap<String, usize>,
}
impl Builder {
@@ -840,7 +856,7 @@ impl Builder {
if pset.props.is_empty() {
return; // IfcPropertySet verlangt mindestens eine Eigenschaft
}
if pset.name.starts_with("Qto_") {
if pset.name.starts_with("Qto_") || pset.name.starts_with("CH_Qto_") {
let quantities: Vec<(&'static str, String, f64)> = pset
.props
.iter()
@@ -1115,6 +1131,7 @@ impl Builder {
for p in psets {
self.add_pset(p, entity, &guid_key);
}
self.elements.insert(guid_key, entity);
entity
}
}
@@ -1126,6 +1143,9 @@ fn rec_name(code: f64) -> &'static str {
c if c == REC_WALL_MESH => "WALL_MESH",
c if c == REC_CEILING => "CEILING",
c if c == REC_OPENING => "OPENING",
c if c == REC_CLASSIFICATION => "CLASSIFICATION",
c if c == REC_ZONE => "ZONE",
c if c == REC_ATTACH => "ATTACH",
_ => "?",
}
}
@@ -1179,6 +1199,7 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
styles: [0; 3],
spaces: Vec::new(),
column_materials: Vec::new(),
elements: HashMap::new(),
};
let pname = |dflt: &str| if project_name.is_empty() { dflt.to_string() } else { project_name.clone() };
@@ -1312,6 +1333,7 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
fmt_real(base)
),
);
w.elements.insert(format!("storey/{id}"), entity);
w.storeys.push(Storey { id, entity, placement });
storey_entities.push(entity);
}
@@ -1470,6 +1492,7 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
format!("{g},#{},$,$,#{opening_entity},#{fill_entity}", w.owner_history),
);
w.add_to_containment(structure, fill_entity);
w.elements.insert(format!("fill/{opening_id}"), fill_entity);
for p in &psets {
w.add_pset(p, fill_entity, &format!("fill/{opening_id}"));
}
@@ -1557,6 +1580,7 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
stair
};
w.add_to_containment(structure, entity);
w.elements.insert(key.clone(), entity);
for p in &psets {
w.add_pset(p, entity, &key);
}
@@ -1571,6 +1595,7 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
let g = w.gid(&format!("extrusion/{id}"));
let entity = w.emit_building_element("IFCBUILDINGELEMENTPROXY", g, "Extrusion", placement, shape, None);
w.add_to_containment(structure, entity);
w.elements.insert(format!("extrusion/{id}"), entity);
}
c if c == REC_SPACE => {
let structure = r.structure(n_storeys)?;
@@ -1597,6 +1622,7 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
enum_(if external { "EXTERNAL" } else { "INTERNAL" })
),
);
w.elements.insert(format!("space/{id}"), space);
if let Some((_, v)) = w.spaces.iter_mut().find(|(s, _)| *s == structure) {
v.push(space);
} else {
@@ -1673,6 +1699,7 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
let g = w.gid(&format!("column/{id}"));
let entity = w.emit_building_element("IFCCOLUMN", g, &label, placement, shape, Some(enum_("COLUMN")));
w.add_to_containment(structure, entity);
w.elements.insert(format!("column/{id}"), entity);
for p in &psets {
w.add_pset(p, entity, &format!("column/{id}"));
}
@@ -1696,6 +1723,88 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
);
}
}
c if c == REC_CLASSIFICATION => {
let name = r.string()?;
let source = r.string()?;
let edition = r.string()?;
let n = r.idx()?;
// Je Code in Reihenfolge des ersten Auftretens: (Name der Referenz, Bauteile).
let mut by_code: Vec<(String, String, Vec<usize>)> = Vec::new();
for _ in 0..n {
let key = r.string()?;
let code = r.string()?;
let ref_name = r.string()?;
if code.is_empty() {
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);
}
} else {
by_code.push((code, ref_name, vec![entity]));
}
}
if !by_code.is_empty() {
let opt = |s: &str| if s.is_empty() { "$".to_string() } else { ifc_string(s) };
let system = w.add("IFCCLASSIFICATION", format!("{},{},$,{},$,$,$", opt(&source), opt(&edition), ifc_string(&name)));
for (code, ref_name, ids) in by_code {
let reference = w.add(
"IFCCLASSIFICATIONREFERENCE",
format!("$,{},{},#{system},$,$", ifc_string(&code), opt(&ref_name)),
);
let g = w.gid(&format!("classification/{name}/{code}"));
w.add(
"IFCRELASSOCIATESCLASSIFICATION",
format!("{g},#{},$,$,{},#{reference}", w.owner_history, refs(&ids)),
);
}
}
}
c if c == REC_ZONE => {
let key = r.string()?;
let name = r.string()?;
let long_name = r.string()?;
let n = r.idx()?;
let mut members = Vec::new();
for _ in 0..n {
let id = r.string()?;
if let Some(&e) = w.elements.get(&format!("space/{id}")) {
if !members.contains(&e) {
members.push(e);
}
}
}
let psets = r.psets()?;
if members.is_empty() {
continue;
}
let zone_key = format!("zone/{key}");
let g = w.gid(&zone_key);
let zone = w.add(
"IFCZONE",
format!("{g},#{},{},$,$,{}", w.owner_history, ifc_string(&name), ifc_string(&long_name)),
);
let g = w.gid(&format!("{zone_key}/spaces"));
w.add(
"IFCRELASSIGNSTOGROUP",
format!("{g},#{},$,$,{},$,#{zone}", w.owner_history, refs(&members)),
);
w.elements.insert(zone_key.clone(), zone);
for p in &psets {
w.add_pset(p, zone, &zone_key);
}
}
c if c == REC_ATTACH => {
let key = r.string()?;
let psets = r.psets()?;
if let Some(&entity) = w.elements.get(&key) {
for p in &psets {
w.add_pset(p, entity, &key);
}
}
}
other => return Err(format!("unbekannter Datensatz {other} ({}) bei {}", rec_name(other), r.pos - 1)),
}
}
@@ -2185,6 +2294,117 @@ mod tests {
}
/// Zeile der ersten Entität eines Typs.
/// Pset-Kodierung mit Einträgen `(Name, Art, Wert)`; Art 0 = IfcIdentifier (Wert = Text), 4 = Fläche.
fn put_pset(b: &mut B, name: &str, props: &[(&str, f64, Result<&str, f64>)]) {
b.f.push(1.0);
b.str(name);
b.f.push(props.len() as f64);
for (n, kind, v) in props {
b.str(n);
b.f.push(*kind);
match v {
Ok(text) => b.str(text),
Err(x) => b.f.push(*x),
}
}
}
/// Klassifikation (eBKP-H), Zone (SIA 416) und Geschoss-Mengen: Entitäten, Zuordnung, dauerhafte GUIDs.
#[test]
fn klassifikation_zone_und_geschossmengen() {
let mut b = full_house(false);
b.n(&[REC_ZONE]);
b.str("sia416/HNF");
b.str("HNF");
b.str("Hauptnutzfläche");
b.n(&[2.0]);
b.str("R1");
b.str("R9"); // unbekannt: übersprungen
put_pset(&mut b, "CH_Zone", &[("SIA416", 0.0, Ok("HNF"))]);
// Zweiter Satz im selben PSETS-Block geht nicht (Zahl steht vorn) — Mengen separat über ATTACH.
b.n(&[REC_ATTACH]);
b.str("zone/sia416/HNF");
put_pset(&mut b, "CH_Qto_SIA416", &[("NetFloorArea", 4.0, Err(1.9))]);
b.n(&[REC_ATTACH]);
b.str("storey/eg");
put_pset(&mut b, "Qto_BuildingStoreyBaseQuantities", &[("GrossFloorArea", 4.0, Err(2.4)), ("NetFloorArea", 4.0, Err(1.9))]);
// Zone ohne auflösbaren Raum: nichts schreiben.
b.n(&[REC_ZONE]);
b.str("sia416/FF");
b.str("FF");
b.str("Funktionsfläche");
b.n(&[1.0]);
b.str("R9");
b.f.push(0.0);
b.n(&[REC_CLASSIFICATION]);
b.str("eBKP-H");
b.str("CRB");
b.str("SN 506 511:2020");
b.n(&[6.0]);
for (k, code, name) in [
("wall/W1", "C", "Konstruktion Gebäude"),
("wall/W2", "C", "Konstruktion Gebäude"),
("fill/T1", "E", "Äussere Wandbekleidung Gebäude"),
("roof/Ro1", "F", "Bedachung Gebäude"),
("wall/Gibtsnicht", "C", "Konstruktion Gebäude"),
("space/R1", "", ""),
] {
b.str(k);
b.str(code);
b.str(name);
}
// System ohne auflösbares Bauteil: nicht schreiben.
b.n(&[REC_CLASSIFICATION]);
b.str("Leer");
b.str("");
b.str("");
b.n(&[1.0]);
b.str("wall/nope");
b.str("X");
b.str("X");
let ifc = build(&b).unwrap();
check_structure(&ifc);
assert_eq!(count(&ifc, "IFCCLASSIFICATION"), 1);
// Codes C, E, F; der Eintrag ohne Code und der unbekannte Schlüssel fallen weg.
assert_eq!(count(&ifc, "IFCCLASSIFICATIONREFERENCE"), 3);
assert_eq!(count(&ifc, "IFCRELASSOCIATESCLASSIFICATION"), 3);
let sys = first_line(&ifc, "IFCCLASSIFICATION");
assert!(sys.contains("'CRB','SN 506 511:2020',$,'eBKP-H',$,$,$"), "{sys}");
// Erste Beziehung (Code C): beide Wände.
let rel_c = first_line(&ifc, "IFCRELASSOCIATESCLASSIFICATION");
assert!(rel_c.contains(",(#") && rel_c.matches(",#").count() + rel_c.matches("(#").count() >= 3, "{rel_c}");
assert_eq!(count(&ifc, "IFCZONE"), 1);
assert_eq!(count(&ifc, "IFCRELASSIGNSTOGROUP"), 1);
let zone = first_line(&ifc, "IFCZONE");
assert!(zone.contains(",'HNF',$,$,'Hauptnutzfl\\X2\\00E4\\X0\\che'"), "{zone}");
assert!(ifc.contains("'Qto_BuildingStoreyBaseQuantities'"));
assert!(ifc.contains("'CH_Qto_SIA416'"));
assert!(ifc.contains("'CH_Zone'"));
// Dauerhaft: gleiche Eingabe, gleiche Datei.
assert_eq!(ifc, build(&b).unwrap());
}
#[test]
fn klassifikation_leere_codes_wohlgeformt_und_ohne_zone_nichts() {
// Ohne die neuen Datensätze ändert sich nichts: keine Klassifikation, keine Zone.
let ifc = build(&full_house(false)).unwrap();
assert_eq!(count(&ifc, "IFCCLASSIFICATION"), 0);
assert_eq!(count(&ifc, "IFCZONE"), 0);
// Abgeschnittene neue Datensätze: Fehler statt Panic.
for cut in 1..6 {
let mut b = full_house(false);
b.n(&[REC_CLASSIFICATION]);
b.str("a");
b.str("b");
b.str("c");
b.n(&[3.0]);
let n = b.f.len();
b.f.truncate(n - cut.min(3));
let (f, s) = b.data();
let _ = build_ifc(f, &s); // darf Err sein, nie panicken
}
}
fn first_line<'a>(ifc: &'a str, ty: &str) -> &'a str {
let head = format!("{ty}(");
ifc.lines().find(|l| l.split_once('=').is_some_and(|(_, b)| b.starts_with(&head))).unwrap_or_else(|| panic!("{ty} fehlt"))
+78
View File
@@ -457,6 +457,23 @@ pub(crate) fn arc_segments(span: f64, r: f64) -> usize {
// Ergebnis
// ---------------------------------------------------------------------------
/// Eine Klassifikations-Zuordnung (IfcRelAssociatesClassification -> IfcClassificationReference), z. B.
/// eBKP-H `C` "Konstruktion Gebäude".
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct Classification {
/// Name des Systems (IfcClassification.Name, sonst Source), z. B. `eBKP-H`.
pub system: String,
/// Code (IfcClassificationReference.Identification bzw. IFC2x3 ItemReference).
pub code: String,
pub name: Option<String>,
}
/// Klassifikationen als JSON für die JS-Seite (`system`, `code`, `name`).
#[cfg(feature = "web")]
pub(crate) fn classifications_json(list: &[Classification]) -> Vec<serde_json::Value> {
list.iter().map(|c| serde_json::json!({ "system": c.system, "code": c.code, "name": c.name })).collect()
}
/// Ein importiertes Bauteil.
#[derive(Clone, Debug, Default)]
pub struct IfcProductMesh {
@@ -467,6 +484,8 @@ pub struct IfcProductMesh {
pub storey: Option<String>,
/// RGBA 0..1.
pub color: Option<[f64; 4]>,
/// Klassifikationen des Bauteils (eBKP-H, BKP, Uniclass ...).
pub classifications: Vec<Classification>,
pub mesh: Mesh,
}
@@ -1670,6 +1689,10 @@ pub(crate) struct Rels {
pub material_color: HashMap<u64, [f64; 4]>,
/// Wirt → Öffnungen (IfcRelVoidsElement).
pub voids: HashMap<u64, Vec<u64>>,
/// Objekt (auch Typ) → Klassifikationsverweise (IfcRelAssociatesClassification).
pub classification_of: HashMap<u64, Vec<u64>>,
/// Objekt → Gruppen/Zonen (IfcRelAssignsToGroup).
pub groups_of: HashMap<u64, Vec<u64>>,
}
impl Rels {
@@ -1693,6 +1716,45 @@ impl Rels {
None
}
/// Klassifikationen eines Objekts (IfcClassificationReference mit Code; ein reines IfcClassification ohne
/// Code zählt nicht), mit dem System aus `ReferencedSource` (über verschachtelte Verweise nach oben).
pub(crate) fn classifications(&self, f: &StepFile, id: u64) -> Vec<Classification> {
let mut out: Vec<Classification> = Vec::new();
for &c in self.classification_of.get(&id).map(Vec::as_slice).unwrap_or(&[]) {
let Some(e) = f.get(c) else { continue };
if e.ty != "IFCCLASSIFICATIONREFERENCE" {
continue;
}
let code = e.arg(1).and_then(|v| v.as_str()).unwrap_or("").trim().to_string();
if code.is_empty() {
continue;
}
let name = e.arg(2).and_then(|v| v.as_str()).filter(|n| !n.is_empty()).map(str::to_string);
// System: ReferencedSource, ggf. über weitere Referenzen bis zur IfcClassification.
let mut system = String::new();
let mut cur = e.arg(3).and_then(|v| v.as_ref_id());
for _ in 0..8 {
let Some(se) = cur.and_then(|i| f.get(i)) else { break };
if se.ty == "IFCCLASSIFICATION" {
system = se
.arg(3)
.and_then(|v| v.as_str())
.filter(|n| !n.is_empty())
.or_else(|| se.arg(0).and_then(|v| v.as_str()))
.unwrap_or("")
.to_string();
break;
}
cur = se.arg(3).and_then(|v| v.as_ref_id());
}
let item = Classification { system, code, name };
if !out.contains(&item) {
out.push(item);
}
}
out
}
/// Geschoss (IfcBuildingStorey-id) eines Bauteils: Enthaltensein, sonst aufwärts über Aggregation.
pub(crate) fn storey_id(&self, f: &StepFile, mut id: u64) -> Option<u64> {
for _ in 0..32 {
@@ -1735,6 +1797,20 @@ impl Rels {
}
}
}
"IFCRELASSOCIATESCLASSIFICATION" => {
if let Some(c) = e.arg(5).and_then(|v| v.as_ref_id()) {
for o in refs(e.arg(4)) {
rels.classification_of.entry(o).or_default().push(c);
}
}
}
"IFCRELASSIGNSTOGROUP" => {
if let Some(g) = e.arg(6).and_then(|v| v.as_ref_id()) {
for o in refs(e.arg(4)) {
rels.groups_of.entry(o).or_default().push(g);
}
}
}
"IFCRELVOIDSELEMENT" => {
if let (Some(h), Some(o)) = (e.arg(4).and_then(|v| v.as_ref_id()), e.arg(5).and_then(|v| v.as_ref_id())) {
rels.voids.entry(h).or_default().push(o);
@@ -1877,6 +1953,7 @@ pub fn import_ifc_opts(bytes: &[u8], elements: bool) -> Result<IfcImport, String
name: e.arg(2).and_then(|v| v.as_str()).map(str::to_string),
storey: storey_of(id),
color,
classifications: rels.classifications(&f, id),
mesh,
});
}
@@ -2054,6 +2131,7 @@ mod web {
"name": p.name,
"storey": p.storey,
"color": p.color,
"classifications": super::classifications_json(&p.classifications),
"positionCount": p.mesh.positions.len(),
"indexCount": p.mesh.indices.len(),
})
+119 -2
View File
@@ -23,12 +23,15 @@
// - Raum (IfcSpace): Prisma mit einem Umriss ohne Löcher; Name (LongName), SIA-416-Kategorie aus
// der Eigenschaft `SIA416` (Dossier-Export) falls vorhanden.
// - Geschosse (IfcBuildingStorey): Name, Höhe (Platzierung, sonst Elevation).
// - Klassifikation (IfcRelAssociatesClassification → IfcClassificationReference, Bauteil oder Typ) an jedem
// erkannten Bauteil (`Info::classifications`); IfcZone (IfcRelAssignsToGroup) liefert dem Raum die
// SIA-416-Kategorie, wenn er keine eigene `SIA416`-Eigenschaft trägt.
//
// Unsinn ergibt „nicht erkannt" (bleibt Mesh), nie Panic.
use std::collections::{BTreeMap, HashMap, HashSet};
use crate::ifc_import::{class_name, signed_volume, Mesh, Reader, Rels, V2};
use crate::ifc_import::{class_name, signed_volume, Classification, Mesh, Reader, Rels, V2};
use crate::ifc_step::Value;
/// Höchstzahl Dreiecke je untersuchtem Körper.
@@ -72,6 +75,8 @@ pub struct Info {
/// Name des Typs (IfcWallType …) oder des Schichtaufbaus.
pub type_name: Option<String>,
pub layers: Vec<MatLayer>,
/// Klassifikationen (eBKP-H, BKP ...) des Bauteils, sonst seines Typs.
pub classifications: Vec<Classification>,
}
#[derive(Clone, Debug, Default)]
@@ -557,9 +562,39 @@ impl Ctx<'_, '_> {
color: color.or_else(|| mat.and_then(|m| self.rels.resolve_material_color(f, m))),
type_name,
layers,
classifications: {
let own = self.rels.classifications(f, id);
if own.is_empty() {
self.type_of.get(&id).map(|t| self.rels.classifications(f, *t)).unwrap_or_default()
} else {
own
}
},
}
}
/// SIA-416-Kategorie eines Raums aus seinen Zonen (IfcZone über IfcRelAssignsToGroup): Eigenschaft
/// `SIA416` der Zone (Dossier-Export), sonst der Zonenname, wenn er eine Kategorie ist.
fn zone_sia(&self, id: u64) -> Option<String> {
let f = self.r.f;
for g in self.rels.groups_of.get(&id).map(Vec::as_slice).unwrap_or(&[]) {
let Some(z) = f.get(*g) else { continue };
if z.ty != "IFCZONE" {
continue;
}
if let Some(v) = self.sia.get(g) {
return Some(v.clone());
}
let name = z.arg(2).and_then(|v| v.as_str()).unwrap_or("").trim().to_uppercase();
// SIA 416 schreibt KF; unser Modell heisst KGF.
let name = if name == "KF" { "KGF".to_string() } else { name };
if ["HNF", "NNF", "VF", "FF", "KGF", "AGF"].contains(&name.as_str()) {
return Some(name);
}
}
None
}
/// Material des Bauteils, sonst seines Typs.
fn material_id(&self, id: u64) -> Option<u64> {
self.rels.material_of.get(&id).or_else(|| self.type_of.get(&id).and_then(|t| self.rels.material_of.get(t))).copied()
@@ -774,7 +809,7 @@ impl Ctx<'_, '_> {
}
let f = self.r.f;
let long_name = f.get(id).and_then(|e| e.arg(7)).and_then(|v| v.as_str()).filter(|s| !s.is_empty()).map(str::to_string);
Some(Space { info: self.info(id, color), long_name, sia: self.sia.get(&id).cloned(), boundary, z0: s.z0, z1: s.z1 })
Some(Space { info: self.info(id, color), long_name, sia: self.sia.get(&id).cloned().or_else(|| self.zone_sia(id)), boundary, z0: s.z0, z1: s.z1 })
}
}
@@ -1049,6 +1084,7 @@ pub(crate) fn encode(s: &Semantic) -> (serde_json::Value, Vec<f64>) {
"color": i.color,
"typeName": i.type_name,
"layers": i.layers.iter().map(|l| json!({ "material": l.material, "thickness": l.thickness, "color": l.color })).collect::<Vec<_>>(),
"classifications": crate::ifc_import::classifications_json(&i.classifications),
})
};
let mut push = |kind: &str, i: &Info, extra: serde_json::Value, nums: Vec<f64>, data: &mut Vec<f64>| {
@@ -1397,6 +1433,87 @@ ENDSEC;\nEND-ISO-10303-21;\n"
assert!(r.skipped_products.is_empty(), "{:?}", r.skipped_products);
}
/// Raum (3 x 2, ohne eigene SIA-Eigenschaft) mit `extra` (Zone, Klassifikation ...) dahinter.
fn space_file(extra: &str) -> String {
let body = format!(
"#501=IFCCARTESIANPOINT((0.,0.));#502=IFCCARTESIANPOINT((3.,0.));#503=IFCCARTESIANPOINT((3.,2.));#504=IFCCARTESIANPOINT((0.,2.));\
#505=IFCPOLYLINE((#501,#502,#503,#504,#501));#506=IFCARBITRARYCLOSEDPROFILEDEF(.AREA.,$,#505);#507=IFCEXTRUDEDAREASOLID(#506,#13,#11,2.5);\
#508=IFCSHAPEREPRESENTATION($,'Body','SweptSolid',(#507));#509=IFCPRODUCTDEFINITIONSHAPE($,$,(#508));\
#500=IFCSPACE('sp',$,'1.01',$,$,#22,#509,'Bad',.ELEMENT.,.INTERNAL.,$);\
#520=IFCRELAGGREGATES('as',$,$,$,#23,(#500));\n{extra}"
);
file(METRE, &body)
}
#[test]
fn zone_name_and_zone_property_give_sia_category() {
// Zone heisst wie die Kategorie.
let (_, s) = sem(&space_file("#600=IFCZONE('z',$,'nnf',$,$,$);#601=IFCRELASSIGNSTOGROUP('ag',$,$,$,(#500),$,#600);"));
assert_eq!(s.spaces.len(), 1, "{:?}", s.kept);
assert_eq!(s.spaces[0].sia.as_deref(), Some("NNF"));
// SIA 416 schreibt KF, das Modell KGF.
let (_, s) = sem(&space_file("#600=IFCZONE('z',$,'KF',$,$,$);#601=IFCRELASSIGNSTOGROUP('ag',$,$,$,(#500),$,#600);"));
assert_eq!(s.spaces[0].sia.as_deref(), Some("KGF"));
// Eigenschaft der Zone (Dossier-Export) schlägt den Namen.
let zone = "#600=IFCZONE('z',$,'Zone 7',$,$,$);#601=IFCRELASSIGNSTOGROUP('ag',$,$,$,(#500),$,#600);\
#602=IFCPROPERTYSINGLEVALUE('SIA416',$,IFCLABEL('VF'),$);#603=IFCPROPERTYSET('zp',$,'CH_Zone',$,(#602));\
#604=IFCRELDEFINESBYPROPERTIES('zr',$,$,$,(#600),#603);";
let (_, s) = sem(&space_file(zone));
assert_eq!(s.spaces[0].sia.as_deref(), Some("VF"));
// Beliebiger Zonenname ohne Eigenschaft: keine Kategorie (kein Raten); eine IfcGroup zählt nicht.
let (_, s) = sem(&space_file("#600=IFCZONE('z',$,'Wohnung 3',$,$,$);#601=IFCRELASSIGNSTOGROUP('ag',$,$,$,(#500),$,#600);"));
assert_eq!(s.spaces[0].sia, None);
let (_, s) = sem(&space_file("#600=IFCGROUP('z',$,'HNF',$,$);#601=IFCRELASSIGNSTOGROUP('ag',$,$,$,(#500),$,#600);"));
assert_eq!(s.spaces[0].sia, None);
// Eigene Raum-Eigenschaft hat Vorrang vor der Zone.
let own = "#600=IFCZONE('z',$,'HNF',$,$,$);#601=IFCRELASSIGNSTOGROUP('ag',$,$,$,(#500),$,#600);\
#610=IFCPROPERTYSINGLEVALUE('SIA416',$,IFCLABEL('FF'),$);#611=IFCPROPERTYSET('rp',$,'CH_Raum',$,(#610));\
#612=IFCRELDEFINESBYPROPERTIES('rr',$,$,$,(#500),#611);";
let (_, s) = sem(&space_file(own));
assert_eq!(s.spaces[0].sia.as_deref(), Some("FF"));
}
#[test]
fn classification_references_of_element_type_and_mesh() {
// Stütze (Bauteil) mit eBKP-H, Raum mit Klassifikation über verschachtelte Referenz, BKP am Typ,
// dazu ein Dach (bleibt Mesh) mit Klassifikation.
let col = rect_product(40, "IFCCOLUMN", (1.0, 1.0, 0.0), (1.0, 0.0), (0.4, 0.4), 2.75, "");
let roof = rect_product(41, "IFCROOF", (1.0, 1.0, 3.0), (1.0, 0.0), (4.0, 3.0), 0.3, "");
let cls = "#700=IFCCLASSIFICATION('CRB','2020',$,'eBKP-H',$,$,$);\
#701=IFCCLASSIFICATIONREFERENCE($,'C','Konstruktion Geb\\X2\\00E4\\X0\\ude',#700,$,$);\
#702=IFCRELASSOCIATESCLASSIFICATION('c1',$,$,$,(#40),#701);\
#703=IFCCLASSIFICATIONREFERENCE($,'C02',$,#701,$,$);\
#704=IFCRELASSOCIATESCLASSIFICATION('c2',$,$,$,(#41),#703);\
#705=IFCCLASSIFICATIONREFERENCE($,' ',$,#700,$,$);\
#706=IFCRELASSOCIATESCLASSIFICATION('c3',$,$,$,(#40),#705);\
#707=IFCRELASSOCIATESCLASSIFICATION('c4',$,$,$,(#40),#700);";
let (r, s) = sem(&file(METRE, &format!("{col}{roof}{cls}")));
assert_eq!(s.columns.len(), 1, "{:?}", s.kept);
let c = &s.columns[0].info.classifications;
// Leerer Code und ein blosses IfcClassification (ohne Code) zählen nicht.
assert_eq!(c.len(), 1, "{c:?}");
assert_eq!((c[0].system.as_str(), c[0].code.as_str(), c[0].name.as_deref()), ("eBKP-H", "C", Some("Konstruktion Gebäude")));
// Roof bleibt Mesh, die Klassifikation kommt trotzdem mit (verschachtelte Referenz: System von oben).
let p = r.products.iter().find(|p| p.class == "IfcRoof").expect("Dach als Mesh");
assert_eq!(p.classifications.len(), 1);
assert_eq!((p.classifications[0].system.as_str(), p.classifications[0].code.as_str(), p.classifications[0].name.as_deref()), ("eBKP-H", "C02", None));
}
#[test]
fn classification_from_type_and_ifc2x3_layout() {
// Klassifikation am Typ (IfcRelDefinesByType) erbt das Bauteil; Wandtyp ohne Bauteil-Eigenes.
let col = rect_product(40, "IFCCOLUMN", (1.0, 1.0, 0.0), (1.0, 0.0), (0.4, 0.4), 2.75, "");
let cls = "#710=IFCCOLUMNTYPE('ct',$,'S30',$,$,$,$,$,$,.COLUMN.);\
#711=IFCRELDEFINESBYTYPE('dt',$,$,$,(#40),#710);\
#712=IFCCLASSIFICATION('CRB',$,$,'BKP',$,$,$);\
#713=IFCCLASSIFICATIONREFERENCE($,'214',$,#712,$,$);\
#714=IFCRELASSOCIATESCLASSIFICATION('c5',$,$,$,(#710),#713);";
let (_, s) = sem(&file(METRE, &format!("{col}{cls}")));
let c = &s.columns[0].info.classifications;
assert_eq!(c.len(), 1, "{c:?}");
assert_eq!((c[0].system.as_str(), c[0].code.as_str()), ("BKP", "214"));
}
impl Profile {
/// Auf 1e-9 gerundet (Vergleich in Tests).
fn round(self) -> Profile {