[328] IFC-Morphs im Export: Netze auf Gebäudeklassen gehen immer mit (Klasse, Geschoss, GlobalId der Herkunft); Import setzt Gebäudeklasse nach IFC-Klasse
This commit is contained in:
7 files changed
+242
-8
No files matched your search
@@ -64,6 +64,8 @@ const REC_LAYERS: f64 = 25.0;
|
||||
const REC_RAILING: f64 = 26.0;
|
||||
/// [281] Geneigte Decke als Netz; Rampe ⇒ `IfcRamp` mit `IfcRampFlight`.
|
||||
const REC_CEILING_MESH: f64 = 27.0;
|
||||
/// [328] Importiertes Netz eines Gebäudeteils (Archicad-Morph …): Geschoss, id, Name, IFC-Klasse, Netz.
|
||||
const REC_PART: f64 = 30.0;
|
||||
|
||||
/// Toleranz des Kerns (`wall_bands.rs::EPS`) für „Öffnung trifft Band".
|
||||
const BAND_EPS: f64 = 1e-4;
|
||||
@@ -1075,6 +1077,25 @@ enum Kind {
|
||||
Context,
|
||||
}
|
||||
|
||||
/// [328] IFC-Klassen, die ein importiertes Gebäudeteil beim Export behält (sonst IfcBuildingElementProxy).
|
||||
pub const PART_CLASSES: [&str; 10] = ["IfcBuildingElementProxy", "IfcCovering", "IfcFurnishingElement", "IfcFurniture", "IfcSlab", "IfcWall", "IfcColumn", "IfcBeam", "IfcMember", "IfcPlate"];
|
||||
|
||||
/// [328] Geschoss (Index in `storey_base`) eines Netzes mit Unterkante `z0`: das höchste, dessen Höhe höchstens 1 cm über
|
||||
/// `z0` liegt; tiefer als alle → das unterste; ohne Geschosse −1 (Gebäude).
|
||||
fn part_storey(storey_base: &[f64], z0: f64) -> f64 {
|
||||
if storey_base.is_empty() {
|
||||
return -1.0;
|
||||
}
|
||||
let mut best: Option<usize> = None;
|
||||
for (i, b) in storey_base.iter().enumerate() {
|
||||
if *b <= z0 + 0.01 && best.is_none_or(|j| *b > storey_base[j]) {
|
||||
best = Some(i);
|
||||
}
|
||||
}
|
||||
let lowest = (0..storey_base.len()).min_by(|a, b| storey_base[*a].total_cmp(&storey_base[*b])).unwrap_or(0);
|
||||
best.unwrap_or(lowest) as f64
|
||||
}
|
||||
|
||||
/// eBKP-H-Hauptgruppe zur Bauteilart, oder `None` (Tür, Raum: nicht eindeutig).
|
||||
fn ebkph_group(k: Kind) -> Option<(&'static str, &'static str)> {
|
||||
match k {
|
||||
@@ -1179,6 +1200,11 @@ pub fn ifc_export_data(src: &Project, opt: &IfcOptions) -> Result<Flat, String>
|
||||
p.rooms.iter().flatten().for_each(|x| push(format!("space/{}", x.id), &x.ifc_global_id));
|
||||
p.extruded_solids.iter().flatten().for_each(|x| push(format!("extrusion/{}", x.id), &x.ifc_global_id));
|
||||
p.openings.iter().flatten().for_each(|x| push(format!("fill/{}", x.id), &x.ifc_global_id));
|
||||
for c in p.context.iter().flatten() {
|
||||
if let ContextObject::ImportedMesh(m) = c {
|
||||
push(format!("part/{}", m.id), &m.ifc_global_id);
|
||||
}
|
||||
}
|
||||
let mut seen = std::collections::HashSet::new();
|
||||
guids.retain(|(_, g)| seen.insert(g.clone()));
|
||||
if !guids.is_empty() {
|
||||
@@ -2164,6 +2190,41 @@ pub fn ifc_export_data(src: &Project, opt: &IfcOptions) -> Result<Flat, String>
|
||||
w_mesh(&mut f, &positions, &indices, false);
|
||||
}
|
||||
|
||||
// ── [328] Importierte Netze auf Gebäudeklassen (Archicad-Morphs, Möbel, Bekleidungen …, alles ausser den
|
||||
// Umgebungsklassen) gehören zum Gebäude: immer dabei, im Geschoss, dessen Höhe die Unterkante des Netzes trägt, mit der
|
||||
// IFC-Klasse der Herkunft (`source` „IFC IfcCovering“; sonst Proxy) und ihrer GlobalId. Vorher fehlten sie im Export ganz. ──
|
||||
for c in p.context.iter().flatten() {
|
||||
let ContextObject::ImportedMesh(m) = c else { continue };
|
||||
if crate::import_context::is_context_class(&m.category_code) {
|
||||
continue;
|
||||
}
|
||||
let n = m.positions.len() / 3;
|
||||
if n < 3 || m.indices.len() < 3 || m.positions.iter().any(|v| !v.is_finite()) {
|
||||
continue;
|
||||
}
|
||||
let tris: Vec<u32> = m
|
||||
.indices
|
||||
.chunks_exact(3)
|
||||
.filter(|t| t.iter().all(|i| i.is_finite() && *i >= 0.0 && (*i as usize) < n) && t[0] != t[1] && t[1] != t[2] && t[0] != t[2])
|
||||
.flat_map(|t| t.iter().map(|i| *i as u32).collect::<Vec<_>>())
|
||||
.collect();
|
||||
if tris.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let z0 = m.positions.iter().skip(2).step_by(3).fold(f64::INFINITY, |a, z| a.min(*z));
|
||||
let structure = part_storey(&storey_base, z0);
|
||||
let base = base_of(structure);
|
||||
let mut positions = m.positions[..n * 3].to_vec();
|
||||
for z in positions.iter_mut().skip(2).step_by(3) {
|
||||
*z -= base;
|
||||
}
|
||||
let class = m.source.as_deref().and_then(|s| s.strip_prefix("IFC ")).map(str::trim).filter(|c| PART_CLASSES.iter().any(|k| k.eq_ignore_ascii_case(c))).unwrap_or("IfcBuildingElementProxy");
|
||||
classified.push((format!("part/{}", m.id), Kind::Context, m.category_code.clone()));
|
||||
let (id, name, cls) = (f.str(&m.id), f.str(if m.name.is_empty() { &m.id } else { &m.name }), f.str(class));
|
||||
f.nums(&[REC_PART, structure, id, name, cls]);
|
||||
w_mesh(&mut f, &positions, &tris, false);
|
||||
}
|
||||
|
||||
// ── [259] Kontext (Option): Gelände und Nachbarn am IfcSite, Höhen absolut (Modell-z, ±0.00 = 0) ──
|
||||
if opt.context {
|
||||
for c in p.context.iter().flatten() {
|
||||
@@ -2328,8 +2389,9 @@ mod tests {
|
||||
text.split('\0').map(String::from).collect()
|
||||
}
|
||||
|
||||
/// [259] Kontext nur mit Option: Gelände (jede Klasse) und Netze auf Umgebungsklassen; ein Netz auf einer
|
||||
/// Bauteil-Klasse (z. B. importierte Möblierung) bleibt draussen, ebenso kaputte Dreiecke.
|
||||
/// [259] Kontext nur mit Option: Gelände (jede Klasse) und Netze auf Umgebungsklassen; kaputte Dreiecke fallen weg.
|
||||
/// [328] Ein Netz auf einer Bauteil-Klasse (z. B. importierte Möblierung, Archicad-Morph) ist kein Kontext, geht aber
|
||||
/// immer mit — als Gebäudeteil (`REC_PART`) im Geschoss, mit oder ohne Option.
|
||||
#[test]
|
||||
fn kontext_nur_mit_option() {
|
||||
let mut p = sample();
|
||||
@@ -2339,13 +2401,21 @@ mod tests {
|
||||
let count = |f: &Flat| f.nums.iter().filter(|v| **v == REC_CONTEXT).count();
|
||||
let off = ifc_export_data(&p, &IfcOptions::default()).unwrap();
|
||||
assert!(!strings(&off).iter().any(|s| s == "nb" || s == "gel"));
|
||||
// Datensatz: REC_PART, Geschoss, id, Name, Klasse (Zahl 30 kommt auch sonst vor: über die Zeichenketten suchen).
|
||||
let parts = |f: &Flat| {
|
||||
let s = strings(f);
|
||||
let at = |k: &str| s.iter().position(|x| x == k).map(|i| i as f64);
|
||||
let (Some(id), Some(name)) = (at("moebel"), at("Netz moebel")) else { return 0 };
|
||||
f.nums.windows(4).filter(|w| w[0] == REC_PART && w[2] == id && w[3] == name).count()
|
||||
};
|
||||
assert_eq!(parts(&off), 1, "Gebäudeteil auch ohne Option");
|
||||
let on = ifc_export_data(&p, &IfcOptions { context: true, ..Default::default() }).unwrap();
|
||||
let s = strings(&on);
|
||||
assert!(count(&on) >= 2);
|
||||
for want in ["nb", "Netz nb", "12 Gebäude", "gel", "Gelände"] {
|
||||
assert!(s.iter().any(|x| x == want), "fehlt: {want}");
|
||||
}
|
||||
assert!(!s.iter().any(|x| x == "moebel"), "Netz auf Bauteil-Klasse ist kein Kontext");
|
||||
assert_eq!(parts(&on), 1, "Netz auf Bauteil-Klasse ist kein Kontext, sondern Gebäudeteil");
|
||||
// Datei: Nachbar mit einem gültigen Dreieck (die beiden kaputten fallen weg), Gelände am Grundstück.
|
||||
let (nums, text) = from_bytes(&on.to_bytes()).unwrap();
|
||||
let ifc = fileio_like_check(&nums, &text);
|
||||
|
||||
@@ -1174,8 +1174,12 @@ fn elements_ops(root: &Map<String, Value>, meta: &Value, products: &[IfcProduct]
|
||||
railings.push(v);
|
||||
}
|
||||
|
||||
// ── Übrige Bauteile als Kontext-Mesh ──
|
||||
let meshes = ifc_meshes(products, &opts.file_name, opts.group.as_deref().unwrap_or("auto"), [dx, dy], now);
|
||||
// ── Übrige Bauteile als Netz ──
|
||||
let mut meshes = ifc_meshes(products, &opts.file_name, opts.group.as_deref().unwrap_or("auto"), [dx, dy], now);
|
||||
// [328] Netze aus einem Geschoss der Datei (Archicad-Morphs, Möbel, Bekleidungen …) sind Teile des Gebäudes, nicht Umgebung:
|
||||
// Klasse nach ihrer IFC-Klasse (sonst „29 Diverse Bauteile“) — so zählen sie im Plan zum Gebäude und gehen im IFC-Export
|
||||
// mit (Umgebungsklassen nur mit der Option „Kontext“).
|
||||
let need_misc = building_mesh_classes(root, products, &mut meshes);
|
||||
let n_meshes = meshes.len();
|
||||
let classified = el.walls.iter().filter(|w| w.info.classified).count()
|
||||
+ el.openings.iter().filter(|o| o.kind != "hole" && o.info.classified).count()
|
||||
@@ -1216,10 +1220,71 @@ fn elements_ops(root: &Map<String, Value>, meta: &Value, products: &[IfcProduct]
|
||||
if n_meshes > 0 {
|
||||
ops.extend(context_ops(root, meshes));
|
||||
}
|
||||
if need_misc {
|
||||
let misc = json!({"code": MISC_CATEGORY, "name": "Diverse Bauteile", "color": "#1a1a1a", "lw": 0.18, "visible": true, "locked": false});
|
||||
match ops.iter_mut().find_map(|o| match o {
|
||||
Op::SetField { key, value: Some(Value::Array(a)), .. } if key == "layers" => Some(a),
|
||||
_ => None,
|
||||
}) {
|
||||
Some(a) => a.push(misc),
|
||||
None => {
|
||||
let mut layers = root.get("layers").and_then(Value::as_array).cloned().unwrap_or_default();
|
||||
layers.push(misc);
|
||||
ops.push(Op::SetField { key: "layers".into(), value: Some(Value::Array(layers)), at: None });
|
||||
}
|
||||
}
|
||||
}
|
||||
let _ = ctx.root;
|
||||
(ops, Value::Object(ctx.summary), n_meshes)
|
||||
}
|
||||
|
||||
/// [328] Klasse für Gebäudeteile ohne passende Dossier-Klasse (Archicad-Morph als IfcBuildingElementProxy …).
|
||||
const MISC_CATEGORY: &str = "29";
|
||||
|
||||
/// [328] Dossier-Klasse eines als Netz gebliebenen Gebäudeteils nach seiner IFC-Klasse (wie die Vorlagen).
|
||||
fn building_code(ifc_class: &str) -> &'static str {
|
||||
match ifc_class.to_ascii_uppercase().as_str() {
|
||||
"IFCWALL" | "IFCWALLSTANDARDCASE" | "IFCCURTAINWALL" => WALL_CATEGORY,
|
||||
"IFCDOOR" | "IFCWINDOW" => OPENING_CATEGORY,
|
||||
"IFCFURNISHINGELEMENT" | "IFCFURNITURE" | "IFCSYSTEMFURNITUREELEMENT" => "22",
|
||||
"IFCCOLUMN" => COLUMN_CATEGORY,
|
||||
"IFCSLAB" | "IFCPLATE" => CEILING_CATEGORY,
|
||||
"IFCROOF" => ROOF_CATEGORY,
|
||||
"IFCBEAM" | "IFCMEMBER" => BEAM_CATEGORY,
|
||||
"IFCSTAIR" | "IFCSTAIRFLIGHT" | "IFCRAMP" | "IFCRAMPFLIGHT" => STAIR_CATEGORY,
|
||||
"IFCRAILING" => RAILING_CATEGORY,
|
||||
_ => MISC_CATEGORY,
|
||||
}
|
||||
}
|
||||
|
||||
/// [328] Netze (je Bauteil, mit GlobalId) von Bauteilen in einem Geschoss der Datei auf ihre Gebäudeklasse setzen
|
||||
/// ([`building_code`]; fehlt die Klasse im Projekt: [`MISC_CATEGORY`]). Gelände und Teile ohne Geschoss bleiben Umgebung.
|
||||
/// `true`, wenn [`MISC_CATEGORY`] gebraucht wird und im Projekt fehlt.
|
||||
fn building_mesh_classes(root: &Map<String, Value>, products: &[crate::import_context::IfcProduct], meshes: &mut [Value]) -> bool {
|
||||
let layers = root.get("layers").and_then(Value::as_array).cloned().unwrap_or_default();
|
||||
let existing: HashSet<String> = crate::layers::flatten(&layers).into_iter().filter_map(|c| c.get("code").and_then(Value::as_str).map(str::to_string)).collect();
|
||||
let storey_of: HashMap<&str, &crate::import_context::IfcProduct> = products.iter().filter(|p| !p.global_id.is_empty()).map(|p| (p.global_id.as_str(), p)).collect();
|
||||
let mut need_misc = false;
|
||||
for m in meshes.iter_mut() {
|
||||
if m.get("type").and_then(Value::as_str) != Some("importedMesh") {
|
||||
continue;
|
||||
}
|
||||
let Some(p) = m.get("ifcGlobalId").and_then(Value::as_str).and_then(|g| storey_of.get(g)) else { continue };
|
||||
if p.storey.as_deref().is_none_or(str::is_empty) {
|
||||
continue;
|
||||
}
|
||||
let mut code = building_code(&p.ifc_class);
|
||||
if !existing.contains(code) {
|
||||
code = MISC_CATEGORY;
|
||||
}
|
||||
need_misc |= code == MISC_CATEGORY && !existing.contains(MISC_CATEGORY);
|
||||
if let Some(o) = m.as_object_mut() {
|
||||
o.insert("categoryCode".into(), code.into());
|
||||
}
|
||||
}
|
||||
need_misc
|
||||
}
|
||||
|
||||
/// Rückschub über die Georeferenz der Datei (IfcMapConversion, [B4]): die Datei liegt lokal, die Karte
|
||||
/// = lokal + (Ost, Nord). Hat das Projekt einen LV95-Bezug, landet das Modell an seinem Kartenort
|
||||
/// relativ zum Projekt-Nullpunkt. Nur ungedreht und Massstab 1 und nur bei LV95 (EPSG:2056) oder ohne
|
||||
@@ -1336,6 +1401,33 @@ pub fn ifc_import(root: &Map<String, Value>, meta_json: &str, positions: &[f64],
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// [328] Netze aus einem Geschoss bekommen eine Gebäudeklasse nach ihrer IFC-Klasse; fehlt die Klasse im Projekt,
|
||||
/// „29 Diverse Bauteile“ (wird angelegt); Teile ohne Geschoss bleiben Umgebung.
|
||||
#[test]
|
||||
fn netze_aus_geschoss_auf_gebaeudeklasse() {
|
||||
let pos = [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0];
|
||||
let idx = [0.0, 1.0, 2.0];
|
||||
let prod = |gid: &str, class: &str, storey: Option<&str>| crate::import_context::IfcProduct {
|
||||
global_id: gid.into(),
|
||||
ifc_class: class.into(),
|
||||
name: Some(gid.into()),
|
||||
storey: storey.map(String::from),
|
||||
color: None,
|
||||
classifications: vec![],
|
||||
positions: &pos,
|
||||
indices: &idx,
|
||||
};
|
||||
let products = [prod("a", "IfcBuildingElementProxy", Some("EG")), prod("b", "IfcFurnishingElement", Some("EG")), prod("c", "IfcColumn", Some("EG")), prod("d", "IfcBuildingElementProxy", None)];
|
||||
let mut meshes = crate::import_context::ifc_meshes(&products, "m.ifc", "product", [0.0, 0.0], 0.0);
|
||||
let root: Map<String, Value> = serde_json::from_value(json!({"layers": [{"code": "22", "name": "Möbel"}, {"code": "10", "name": "Situation"}]})).unwrap();
|
||||
assert!(building_mesh_classes(&root, &products, &mut meshes), "29 fehlt im Projekt");
|
||||
let codes: Vec<&str> = meshes.iter().map(|m| m["categoryCode"].as_str().unwrap()).collect();
|
||||
// Proxy → 29, Möbel → 22, Stütze (25 fehlt) → 29, ohne Geschoss bleibt 10.
|
||||
assert_eq!(codes, ["29", "22", "29", "10"]);
|
||||
assert_eq!(building_code("IFCWALLSTANDARDCASE"), WALL_CATEGORY);
|
||||
assert_eq!(building_code("IfcRailing"), "41");
|
||||
}
|
||||
|
||||
fn added<'a>(ops: &'a [Op], key: &str) -> Vec<&'a Value> {
|
||||
let mut out = Vec::new();
|
||||
for op in ops {
|
||||
|
||||
Reference in new issue
Block a user