diff --git a/TODO.md b/TODO.md index 0c61773a..a06a1580 100644 --- a/TODO.md +++ b/TODO.md @@ -226,7 +226,7 @@ Punktwolken/BCF-Ausbau, Windows-Paket, [C5]/[C7]/[15] Kern-Umbauten — ausser s ## Import und Export - ◐ **[211]** Rendering mit Blender/Cycles (12.11.; Export-Paket `model.glb` + `scene.json` + `textures/` `export/blenderRender.ts`, Skript `scripts/blender/render_dossier.py`, Dialog, CLI `render`; Mac-Gegenprobe 12.11. lief, Befunde in [227] behoben). Offen: nicht in der Tauri-App/auf dem Mac geprüft (Berechtigungen, Metal-GPU, Ereignisse), nicht mit installiertem Blender 3.6/4.x (Mix-Knoten per Platz, `light_settings.ao_factor` nur in 5.x geprüft); Dialog nicht im Browser geklickt; ambientCG-Web-Texturen lädt die CLI nicht; Dachtyp-Schichten ohne Bildkarte (z. B. Faserzement) nur nach Namen. · M -- ◐ **[B4]** (= [25], zweite Stufe) IFC-Import zu echten Bauteilen (`io/ifcImport*`, `fileio`). Offen: Dächer, Treppen mit 3+ Podesten, Träger, schräge/gekrümmte Wände, Wände mit Profiländerung, Decken aus Netzen mit T-Stössen, Tür-Anschlag, Typen aus IfcDoorType/IfcWindowType, Farbe der Bauteile; LEFT/RIGHT nur gegen den eigenen Export geprüft. · L +- ◐ **[B4]** (= [25], zweite Stufe) IFC-Import zu echten Bauteilen (`io/ifcImport*`, `fileio`). Stand 18.11.: Rundreise eigener Export → Import für Träger (rechteckig → `Project.beams`, Oberkante über `topOffset`), Geländer (Pset `Dossier_Railing` mit Achse/Höhe/Art, nur eigener Export und nur wenn der Körper passt; fremde Geländer bleiben Mesh), Rampen (`IfcRamp`/`IfcRampFlight` als ebene schräge Platte → Decke mit `slope.ramp`; mehrere Läufe/Stufen bleiben Mesh), Dachplatten nicht doppelt (Test `src/io/ifcImport.roundtrip.test.ts`, `:wettbewerb`, `:komplex`); nicht auf dem Mac geprüft, Träger-Bezug ignoriert Decken, die schon vor dem Import im Projekt lagen. Offen: Dächer (Rundreise `:komplex`: nur 1 von 4 Dächern als Dach), Treppen mit 3+ Podesten, Träger mit Profil I/U und schräge Träger, geneigte `IfcSlab` (ausser Rampen), schräge/gekrümmte Wände, Wände mit Profiländerung, Decken aus Netzen mit T-Stössen, Tür-Anschlag, Typen aus IfcDoorType/IfcWindowType, Farbe der Bauteile; LEFT/RIGHT nur gegen den eigenen Export geprüft. · L - ◐ **[B3]-Rest** IFC-Geometrie-Import. Offen: IfcAdvancedBrep (NURBS), IFC4.3-Ausrichtung, IfcGridPlacement, B-Spline-Kurven, Profil-Kantenradien; CSG bei > 200 000 Dreiecken übersprungen; Farbe von Kontext-Meshes im 3D (`plan/toWalls3d.ts::emitMeshes` setzt fest `IMPORTED_RGB`). · M - ◐ **[B5]** IFC-Export (Kern `ifc_data.rs`, `ifc_export/`). 18.11.: Dach als `IfcRoof`-Aggregat (PredefinedType nach Dachform, Typ/`Pset_RoofCommon`/`Qto_RoofBaseQuantities` am Dach) mit je Dachfläche einem `IfcSlab` ROOF (Netz, `Pset_SlabCommon` inkl. Status Umbau, `Qto_SlabBaseQuantities`, Schichten des Dachtyps als `IfcMaterialLayerSetUsage` AXIS3/NEGATIVE, Dachfenster-Öffnung in der Wirtsfläche, Klassifikation auch an den Flächen), IFC4 und IFC2x3 (ifcopenshell-Schema gültig; Datensatz 9 ROOF neu geordnet, keine neue Nummer). Verschnittene Dächer/Gauben ([G5]) und Attika gehen als EIN Teil bzw. eigenes Teil statt je Fläche; Dachfläche bleibt Netz (kein Profil-Sweep); `IfcRoofType` nur IFC4. Offen: Wand/Decke-Felder ohne UI; Reference-Rückimport fehlt; IFC2x3 nicht gesondert geprüft; nicht in Revit/ArchiCAD geöffnet. · M - ◐ **[BCF]** BCF (`fileio/src/bcf.rs`). Offen: Kamera im nativen Metal-Fenster; Schnittebene aus dem Live-Schnitt übernehmen; Kamera-Roll; schräge Schnittebenen nur angezeigt; `extensions.xml`, Farbgruppen/Linien, BimSnippet, Dokument-Referenzen und verwandte Themen gehen beim Speichern verloren. · M diff --git a/src-tauri/core/src/ifc_data.rs b/src-tauri/core/src/ifc_data.rs index 122eaba0..4c9f3b07 100644 --- a/src-tauri/core/src/ifc_data.rs +++ b/src-tauri/core/src/ifc_data.rs @@ -154,6 +154,11 @@ fn layer_renovation_props(p: &Project, psets: &mut Vec, id: &str) { } } +/// Koordinate auf 1e-6 m für Textwerte (Achse eines Geländers). +fn fmt_coord(v: f64) -> String { + format!("{v:.6}") +} + fn ident(name: &'static str, v: &str) -> Prop { Prop::Ident(name, v.to_string()) } @@ -2065,7 +2070,18 @@ pub fn ifc_export_data(src: &Project, opt: &IfcOptions) -> Result let label = crate::railing::label(r); let mut psets = vec![Pset { name: "Pset_RailingCommon", props: vec![ident("Reference", &label)] }]; renovation_props(&p, &mut psets, "Pset_RailingCommon", r.renovation.as_ref()); - psets.push(Pset { name: "Dossier_Railing", props: vec![ident("Kind", kind), ident("Handrail", if s.handrail { "yes" } else { "no" })] }); + // [B4] Achse (Meter, Modellkoordinaten), Höhe und Schluss: damit liest der Import das Geländer als Bauteil zurück. + let axis_text = r.points.iter().map(|q| format!("{},{}", fmt_coord(q.x), fmt_coord(q.y))).collect::>().join(";"); + psets.push(Pset { + name: "Dossier_Railing", + props: vec![ + ident("Kind", kind), + ident("Handrail", if s.handrail { "yes" } else { "no" }), + ident("Axis", &axis_text), + ident("Closed", if r.closed.unwrap_or(false) { "yes" } else { "no" }), + ident("Height", &fmt_coord(s.height)), + ], + }); let len = crate::railing::length(&ax); let q = vec![ Qty { name: "Length", kind: QtyKind::Length, value: len }, diff --git a/src-tauri/core/src/import_ifc.rs b/src-tauri/core/src/import_ifc.rs index 8dc0a83f..72d856a3 100644 --- a/src-tauri/core/src/import_ifc.rs +++ b/src-tauri/core/src/import_ifc.rs @@ -27,6 +27,7 @@ const ROOF_CATEGORY: &str = "35"; const STAIR_CATEGORY: &str = "40"; /// [180] Träger (Extrusionskörper) wie „35 Träger" der Musterprojekte. const BEAM_CATEGORY: &str = "35"; +const RAILING_CATEGORY: &str = "55"; const ROOM_COLOR: &str = "#6b7280"; const SIA: [&str; 6] = ["HNF", "NNF", "VF", "FF", "KGF", "AGF"]; const LEVEL_TOL: f64 = 0.005; @@ -101,6 +102,18 @@ struct SlabData { holes: Vec>, z0: f64, z1: f64, + /// [B4] Geneigte Decke/Rampe: (Bezugspunkt, zweiter Punkt, Höhenunterschied, Rampe). + slope: Option<([f64; 2], [f64; 2], f64, bool)>, +} + +struct RailingData { + info: Info, + points: Vec<[f64; 2]>, + closed: bool, + height: f64, + z0: f64, + kind: String, + handrail: Option, } struct ColumnData { @@ -187,6 +200,7 @@ struct Elements { roofs: Vec, stairs: Vec, beams: Vec, + railings: Vec, kept: Map, /// Je Klasse die Gründe, weshalb Kandidaten Mesh blieben (`{"IfcWall": {"slopedTop": 3}}`). kept_reasons: Map, @@ -306,7 +320,15 @@ fn decode_elements(meta: &Value, data: &[f64]) -> Elements { "slab" => { if let Some(r) = v.get(2).and_then(|&c| rings(v, 3, c)) { if let Some((outline, holes)) = r.split_first() { - out.slabs.push(SlabData { info, z0: v[0], z1: v[1], outline: outline.clone(), holes: holes.to_vec() }); + let slope = e.get("slope").and_then(|k| { + let p2 = |key: &str| { + let a = k.get(key)?.as_array()?; + Some([a.first()?.as_f64()?, a.get(1)?.as_f64()?]) + }; + let rise = k.get("rise")?.as_f64()?; + (rise.is_finite() && rise != 0.0).then_some((p2("from")?, p2("to")?, rise, k.get("ramp").and_then(Value::as_bool).unwrap_or(false))) + }); + out.slabs.push(SlabData { info, z0: v[0], z1: v[1], outline: outline.clone(), holes: holes.to_vec(), slope }); } } } @@ -373,6 +395,21 @@ fn decode_elements(meta: &Value, data: &[f64]) -> Elements { out.beams.push(BeamData { info, outline: r.remove(0), z0: v[0], z1: v[1] }); } } + "railing" => { + let n = v.get(2).copied().unwrap_or(-1.0); + if n >= 2.0 && n.fract() == 0.0 && v.len() == 3 + 2 * n as usize && v[1] > 0.0 { + let kind = s_of(e.get("railingKind")).unwrap_or_else(|| "bars".into()); + out.railings.push(RailingData { + info, + points: v[3..].chunks_exact(2).map(|c| [c[0], c[1]]).collect(), + closed: e.get("closed").and_then(Value::as_bool).unwrap_or(false), + height: v[1], + z0: v[0], + kind, + handrail: e.get("handrail").and_then(Value::as_bool), + }); + } + } "space" => { if let Some(mut r) = rings(v, 2, 1.0) { out.spaces.push(SpaceData { @@ -426,6 +463,43 @@ fn id_of(v: &Value) -> &str { } /// [201] GlobalId der Quelle ans neue Element (`ifcGlobalId`). +/// Rechteckiger Träger-Grundriss → (Anfang, Ende, Breite): Achse längs der langen Seite durch die Mitte der kurzen. +/// `None` bei Nicht-Rechtecken (Körper). +fn beam_axis(ring: &[[f64; 2]]) -> Option<([f64; 2], [f64; 2], f64)> { + let ring: Vec<[f64; 2]> = if ring.len() == 5 && ring[0] == ring[4] { ring[..4].to_vec() } else { ring.to_vec() }; + if ring.len() != 4 { + return None; + } + let e: Vec<[f64; 2]> = (0..4).map(|i| [ring[(i + 1) % 4][0] - ring[i][0], ring[(i + 1) % 4][1] - ring[i][1]]).collect(); + let l: Vec = e.iter().map(|d| d[0].hypot(d[1])).collect(); + if l.iter().any(|x| !(*x > 1e-3)) { + return None; + } + let rect = (0..4).all(|i| (e[i][0] * e[(i + 1) % 4][0] + e[i][1] * e[(i + 1) % 4][1]).abs() <= 1e-6 * l[i] * l[(i + 1) % 4]) && (l[0] - l[2]).abs() <= 1e-6 && (l[1] - l[3]).abs() <= 1e-6; + if !rect { + return None; + } + let mid = |a: [f64; 2], b: [f64; 2]| [(a[0] + b[0]) / 2.0, (a[1] + b[1]) / 2.0]; + // Lange Seite = Achsrichtung (bei Quadrat die erste Kante). + let i = if l[1] > l[0] + 1e-9 { 1 } else { 0 }; + let (a0, a1) = (ring[i], ring[(i + 1) % 4]); + let (b0, b1) = (ring[(i + 3) % 4], ring[(i + 2) % 4]); + Some((mid(a0, b0), mid(a1, b1), l[(i + 1) % 4])) +} + +/// Punkt im Polygon (gerade/ungerade Regel). +fn point_in_ring(p: [f64; 2], ring: &[[f64; 2]]) -> bool { + let mut inside = false; + let n = ring.len(); + for i in 0..n { + let (a, b) = (ring[i], ring[(i + 1) % n]); + if (a[1] > p[1]) != (b[1] > p[1]) && p[0] < (b[0] - a[0]) * (p[1] - a[1]) / (b[1] - a[1]) + a[0] { + inside = !inside; + } + } + inside +} + fn set_gid(v: &mut Value, info: &Info) { if let Some(g) = &info.global_id { v["ifcGlobalId"] = g.clone().into(); @@ -591,7 +665,7 @@ fn list_of(root: &Map, key: &str) -> Vec<(Value, bool)> { fn elements_ops(root: &Map, meta: &Value, products: &[IfcProduct], el: &Elements, opts: &IfcOptions, now: f64) -> (Vec, Value, usize) { let kept: f64 = el.kept.values().map(|v| v.as_f64().unwrap_or(f64::NAN)).sum(); let mut summary = Map::new(); - for k in ["walls", "openings", "ceilings", "columns", "rooms", "roofs", "stairs", "beams", "floors", "wallTypes", "ceilingTypes", "roofTypes", "doorTypes", "windowTypes", "components", "meshes", "classified"] { + for k in ["walls", "openings", "ceilings", "columns", "rooms", "roofs", "stairs", "beams", "railings", "floors", "wallTypes", "ceilingTypes", "roofTypes", "doorTypes", "windowTypes", "components", "meshes", "classified"] { summary.insert(k.into(), 0.into()); } summary.insert("kept".into(), js_num(kept)); @@ -623,6 +697,9 @@ fn elements_ops(root: &Map, meta: &Value, products: &[IfcProduct] for b in &el.beams { b.outline.iter().for_each(|p| extra.extend(p)); } + for r in &el.railings { + r.points.iter().for_each(|p| extra.extend(p)); + } let [dx, dy] = map_shift(meta, root).unwrap_or_else(|| geo_shift(products, project_geo_origin(root), &extra)); let mv = |p: [f64; 2]| pt([round(p[0] + dx, 1e-9), round(p[1] + dy, 1e-9)]); @@ -836,8 +913,23 @@ fn elements_ops(root: &Map, meta: &Value, products: &[IfcProduct] if (s.z1 - floor_top).abs() > LEVEL_TOL { v.insert("top".into(), json!({"mode": "floor", "floorId": fid, "offset": js_num(anchor_offset(s.z1, base))})); } + if let Some((from, to, rise, ramp)) = s.slope { + let mut k = json!({"from": mv(from), "to": mv(to), "rise": js_num(round(rise, 1e-6))}); + if ramp { + k["ramp"] = true.into(); + } + v.insert("slope".into(), k); + } ceilings.push(Value::Object(v)); } + // Decken (Mitte, tiefste Unterkante, Loch) für die Träger: Bezug der Trägeroberkante ([280]). + let ceiling_under: Vec<(String, Vec<[f64; 2]>, Vec>, f64)> = el + .slabs + .iter() + .zip(ceilings.iter()) + .filter(|(sl, _)| sl.slope.is_none()) + .map(|(sl, c)| (c["floorId"].as_str().unwrap_or("").to_string(), sl.outline.clone(), sl.holes.clone(), sl.z0)) + .collect(); let mut columns: Vec = Vec::new(); for c in &el.columns { let (fid, base, _) = floor_of(&mut ctx, c.info.storey, c.z0); @@ -982,10 +1074,33 @@ fn elements_ops(root: &Map, meta: &Value, products: &[IfcProduct] set_gid(&mut v, &s.info); stairs.push(v); } - // Träger als Extrusionskörper (Grundriss + Höhe über der Geschoss-UK). + // Träger ([280]): rechteckiger Grundriss → Dossier-Träger (Achse, Breite, Höhe, Oberkante über `topOffset`); sonst + // Extrusionskörper (Grundriss + Höhe über der Geschoss-UK). let mut solids: Vec = Vec::new(); + let mut beams: Vec = Vec::new(); for b in &el.beams { - let (fid, base, _) = floor_of(&mut ctx, b.info.storey, b.z0); + let (fid, base, fh) = floor_of(&mut ctx, b.info.storey, b.z0); + if let Some((start, end, width)) = beam_axis(&b.outline) { + // Bezug wie `Project::beam_vertical_extent`: tiefste Deckenunterkante über der Achsmitte, sonst Geschoss-OK. + let mid = [(start[0] + end[0]) / 2.0, (start[1] + end[1]) / 2.0]; + let floor_top = base + fh; + let reference = ceiling_under + .iter() + .filter(|(f, outline, holes, _)| *f == fid && point_in_ring(mid, outline) && !holes.iter().any(|h| point_in_ring(mid, h))) + .map(|c| c.3) + .fold(floor_top, f64::min); + let mut v = json!({ + "id": ctx.new_id("beam"), "type": "beam", "floorId": fid, "categoryCode": BEAM_CATEGORY, + "start": mv(start), "end": mv(end), "width": js_num(round(width, 1e-6)), "height": js_num(round(b.z1 - b.z0, 1e-6)), + }); + let off = b.z1 - reference; + if off.abs() > 1e-6 { + v["topOffset"] = js_num(round(off, 1e-6)); + } + set_gid(&mut v, &b.info); + beams.push(v); + continue; + } let mut v = json!({ "id": ctx.new_id("solid"), "type": "extrudedSolid", "levelId": fid, "categoryCode": BEAM_CATEGORY, "points": b.outline.iter().map(|&p| mv(p)).collect::>(), "height": js_num(round(b.z1 - b.z0, 1e-6)), @@ -997,6 +1112,27 @@ fn elements_ops(root: &Map, meta: &Value, products: &[IfcProduct] set_gid(&mut v, &b.info); solids.push(v); } + // Geländer ([B4]): Achse und Art aus dem eigenen Export, Fuss relativ zur Geschoss-UK. + let mut railings: Vec = Vec::new(); + for r in &el.railings { + let (fid, base, _) = floor_of(&mut ctx, r.info.storey, r.z0); + let mut v = json!({ + "id": ctx.new_id("railing"), "type": "railing", "floorId": fid, "categoryCode": RAILING_CATEGORY, + "points": r.points.iter().map(|&p| mv(p)).collect::>(), "height": js_num(round(r.height, 1e-6)), "kind": r.kind, + }); + if r.closed { + v["closed"] = true.into(); + } + let off = anchor_offset(r.z0, base); + if off.abs() > 1e-6 { + v["baseOffset"] = js_num(round(off, 1e-6)); + } + if let Some(h) = r.handrail { + v["handrail"] = h.into(); + } + set_gid(&mut v, &r.info); + 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); @@ -1009,7 +1145,7 @@ fn elements_ops(root: &Map, meta: &Value, products: &[IfcProduct] + el.roofs.iter().filter(|r| r.info.classified).count() + el.stairs.iter().filter(|s| s.info.classified).count() + products.iter().filter(|p| !p.classifications.is_empty()).count(); - for (k, n) in [("walls", walls.len()), ("openings", openings.len()), ("ceilings", ceilings.len()), ("columns", columns.len()), ("rooms", rooms.len()), ("roofs", roofs.len()), ("stairs", stairs.len()), ("beams", solids.len()), ("meshes", n_meshes), ("classified", classified)] { + for (k, n) in [("walls", walls.len()), ("openings", openings.len()), ("ceilings", ceilings.len()), ("columns", columns.len()), ("rooms", rooms.len()), ("roofs", roofs.len()), ("stairs", stairs.len()), ("beams", solids.len() + beams.len()), ("railings", railings.len()), ("meshes", n_meshes), ("classified", classified)] { ctx.summary.insert(k.into(), n.into()); } @@ -1028,12 +1164,12 @@ fn elements_ops(root: &Map, meta: &Value, products: &[IfcProduct] if !walls.is_empty() { ops.push(Op::Add { collection: "walls".into(), items: walls, at: None }); } - for (key, items) in [("openings", openings), ("ceilings", ceilings), ("columns", columns), ("rooms", rooms), ("roofs", roofs), ("stairs", stairs), ("extrudedSolids", solids)] { + for (key, items) in [("openings", openings), ("ceilings", ceilings), ("columns", columns), ("rooms", rooms), ("roofs", roofs), ("stairs", stairs), ("beams", beams), ("railings", railings), ("extrudedSolids", solids)] { if root.get(key).is_some_and(|v| crate::json_util::truthy(Some(v))) { if !items.is_empty() { ops.push(Op::Add { collection: key.into(), items, at: None }); } - } else if !(key == "extrudedSolids" && items.is_empty()) { + } else if !(matches!(key, "extrudedSolids" | "beams" | "railings") && items.is_empty()) { ops.push(Op::SetField { key: key.into(), value: Some(Value::Array(items)), at: None }); } } @@ -1108,6 +1244,15 @@ fn rotate_elements(el: &mut Elements, cs: [f64; 2]) { for b in &mut el.beams { ring(&mut b.outline); } + for r in &mut el.railings { + r.points.iter_mut().for_each(rot); + } + for sl in &mut el.slabs { + if let Some((a, b, _, _)) = &mut sl.slope { + rot(a); + rot(b); + } + } } /// IFC ins Projekt `root`: als Kontext-Meshes oder (mit `opts.elements`) als Bauteile. @@ -1383,11 +1528,15 @@ mod tests { assert!((u["midOffset"].as_f64().unwrap() - 0.09).abs() < 1e-9, "{u}"); let typed: crate::model::Stair = serde_json::from_value(u.clone()).unwrap(); assert_eq!(typed.shape, crate::model::StairShape::U); - let solids = added(&r.ops, "extrudedSolids"); - assert_eq!(solids.len(), 1); - assert_eq!(solids[0]["type"].as_str(), Some("extrudedSolid")); - assert!((solids[0]["height"].as_f64().unwrap() - 0.4).abs() < 1e-9 && (solids[0]["baseOffset"].as_f64().unwrap() - 2.6).abs() < 1e-9); - assert!(at(&solids[0]["points"][2], 104.0, 50.2)); + // [B4] Rechteckiger Träger → Dossier-Träger: Achse durch die Mitte der kurzen Seiten, Oberkante über `topOffset`. + assert!(added(&r.ops, "extrudedSolids").is_empty()); + let beams = added(&r.ops, "beams"); + assert_eq!(beams.len(), 1); + let bm = beams[0]; + assert_eq!(bm["type"].as_str(), Some("beam")); + assert!((bm["height"].as_f64().unwrap() - 0.4).abs() < 1e-9 && (bm["width"].as_f64().unwrap() - 0.2).abs() < 1e-9, "{bm}"); + let (s0, e0) = (&bm["start"], &bm["end"]); + assert!(at(s0, 100.0, 50.1) && at(e0, 104.0, 50.1) || at(e0, 100.0, 50.1) && at(s0, 104.0, 50.1), "{bm}"); assert_eq!(r.summary.unwrap()["beams"].as_f64(), Some(1.0)); // Lokal x zeigt nach Norden (90°): alles um 90° gedreht, dann verschoben. @@ -1401,7 +1550,8 @@ mod tests { let stairs = added(&r.ops, "stairs"); assert!(at(&stairs[0]["start"], 98.0, 51.0) && at(&stairs[0]["dir"], 0.0, 1.0), "{}", stairs[0]); assert!(at(&stairs[1]["center"], 97.0, 52.0) && at(&stairs[1]["start"], 97.0, 52.8), "{}", stairs[1]); - assert!(at(&added(&r.ops, "extrudedSolids")[0]["points"][2], 99.8, 54.0)); + let bm = added(&r.ops, "beams")[0]; + assert!(at(&bm["start"], 99.9, 50.0) && at(&bm["end"], 99.9, 54.0) || at(&bm["end"], 99.9, 50.0) && at(&bm["start"], 99.9, 54.0), "{bm}"); // Ohne Projekt-Bezug bleibt die Datei lokal und ungedreht. let mut bare = root(); bare.remove("geoAnchor"); diff --git a/src-tauri/fileio/src/ifc_semantic.rs b/src-tauri/fileio/src/ifc_semantic.rs index c94314eb..30d7688d 100644 --- a/src-tauri/fileio/src/ifc_semantic.rs +++ b/src-tauri/fileio/src/ifc_semantic.rs @@ -97,7 +97,7 @@ pub struct Info { /// Eigenschaften der gemeinsamen Psets, die ins Modell übernommen werden; [158] dazu die Raum-Oberflächen /// (`Pset_SpaceCoveringRequirements`, IFC2x3 `Pset_SpaceCommon`) und Nutzung/Bodenaufbau (`Dossier_RoomBook`). -const COMMON_PROPS: [&str; 12] = [ +const COMMON_PROPS: [&str; 17] = [ "IsExternal", "LoadBearing", "FireRating", @@ -110,11 +110,17 @@ const COMMON_PROPS: [&str; 12] = [ "CeilingCovering", "Usage", "FloorBuildUp", + // `Dossier_Railing` ([B4]): Achse als Text, Art, Handlauf, Höhe. + "Axis", + "Closed", + "Kind", + "Handrail", + "Height", ]; /// Psets, deren Eigenschaften aus [`COMMON_PROPS`] gelesen werden: `Pset_*Common` und die Raumbuch-Psets. fn reads_common(name: &str) -> bool { - (name.starts_with("Pset_") && name.ends_with("Common")) || name == "Pset_SpaceCoveringRequirements" || name == "Dossier_RoomBook" + (name.starts_with("Pset_") && name.ends_with("Common")) || name == "Pset_SpaceCoveringRequirements" || name == "Dossier_RoomBook" || name == "Dossier_Railing" } #[derive(Clone, Debug, Default)] @@ -170,8 +176,35 @@ pub struct Slab { pub info: Info, pub outline: Vec, pub holes: Vec>, + /// Waagrechte Platte: UK/OK; geneigt (`slope`): UK/OK am Bezugspunkt `slope.from`. pub z0: f64, pub z1: f64, + /// [B4] Geneigte Platte (Rampe): Gefällelinie und Höhenunterschied, sonst `None`. + pub slope: Option, +} + +/// Gefällelinie einer geneigten Platte (Dossier `CeilingSlope`). +#[derive(Clone, Copy, Debug, Default, PartialEq)] +pub struct SlabSlope { + pub from: V2, + pub to: V2, + pub rise: f64, + /// Aus `IfcRamp`/`IfcRampFlight` ⇒ als Rampe darstellen. + pub ramp: bool, +} + +/// [B4] Geländer (Dossier `Railing`) aus dem eigenen Export (Pset `Dossier_Railing` mit Achse), wenn der Körper dazu passt. +#[derive(Clone, Debug, Default)] +pub struct Railing { + pub info: Info, + pub points: Vec, + pub closed: bool, + pub height: f64, + /// Fusshöhe (absolut, Unterkante des Körpers). + pub z0: f64, + /// `bars`, `glass`, `solid`, `perforated`. + pub kind: String, + pub handrail: Option, } #[derive(Clone, Copy, Debug, PartialEq)] @@ -282,6 +315,8 @@ pub struct Semantic { pub stairs: Vec, /// Träger als senkrechte Prismen (Dossier-Extrusionskörper). pub beams: Vec, + /// Geländer mit Dossier-Achse (eigener Export). + pub railings: Vec, /// Kandidaten (Wand, Decke, Stütze, Raum, Dach, Treppe), die nicht sicher abbildbar waren, je Klasse. pub kept: BTreeMap, /// Dieselben je Klasse und Grund (Kennwort, s. [`Reason`]). @@ -319,6 +354,8 @@ const R_PROFILE: &str = "profile"; const R_HOLES: &str = "holes"; /// Teil eines anderen Bauteils (Vorhangfassade, Baugruppe …). const R_PART: &str = "part"; +/// Rampe, die keine ebene schräge Platte ist. +const R_RAMP_FORM: &str = "rampForm"; // --------------------------------------------------------------------------- // 2D-Hilfen @@ -625,6 +662,88 @@ fn prism(s: &Shape) -> Option<(Vec, Vec>)> { ((sum - a).abs() <= 0.01 * a).then_some((outer, holes)) } +/// [B4] Ebene, geneigte Platte (Rampe): Oberseite und Unterseite auf parallelen Ebenen `z = gx·x + gy·y + c` +/// (Unterseite um `t` tiefer, lotrecht gemessen), alle übrigen Flächen senkrecht, Volumen = Fläche × t. +/// Liefert Umriss, Löcher, Gefälle `[gx, gy]`, `c` der Oberseite und `t`; `None` sonst (nichts raten). +fn sloped_plate(m: &Mesh) -> Option<(Vec, Vec>, V2, f64, f64)> { + if m.indices.len() < 12 || m.positions.len() < 12 || m.positions.iter().any(|v| !v.is_finite()) { + return None; + } + let p = |i: u32| -> Option<[f64; 3]> { + let k = i as usize * 3; + m.positions.get(k..k + 3).map(|s| [s[0], s[1], s[2]]) + }; + let mut top: Vec<[[f64; 3]; 3]> = Vec::new(); + let mut bottom: Vec<[[f64; 3]; 3]> = Vec::new(); + for t in m.indices.chunks_exact(3) { + let (a, b, c) = (p(t[0])?, p(t[1])?, p(t[2])?); + let (u, v) = ([b[0] - a[0], b[1] - a[1], b[2] - a[2]], [c[0] - a[0], c[1] - a[1], c[2] - a[2]]); + let n = [u[1] * v[2] - u[2] * v[1], u[2] * v[0] - u[0] * v[2], u[0] * v[1] - u[1] * v[0]]; + let l = (n[0] * n[0] + n[1] * n[1] + n[2] * n[2]).sqrt(); + if l < 1e-12 { + continue; + } + let nz = n[2] / l; + if nz > 0.05 { + top.push([a, b, c]); + } else if nz < -0.05 { + bottom.push([a, b, c]); + } else if nz.abs() > 1e-3 { + return None; + } + } + if top.is_empty() || bottom.is_empty() { + return None; + } + // Ebene der Oberseite aus dem ersten Dreieck. + let plane = |t: &[[f64; 3]; 3]| -> Option<(f64, f64, f64)> { + let (a, b, c) = (t[0], t[1], t[2]); + let n = [(b[1] - a[1]) * (c[2] - a[2]) - (b[2] - a[2]) * (c[1] - a[1]), (b[2] - a[2]) * (c[0] - a[0]) - (b[0] - a[0]) * (c[2] - a[2]), (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0])]; + (n[2].abs() > 1e-12).then(|| { + let (gx, gy) = (-n[0] / n[2], -n[1] / n[2]); + (gx, gy, a[2] - gx * a[0] - gy * a[1]) + }) + }; + let (gx, gy, c_top) = plane(&top[0])?; + let g = gx.hypot(gy); + if !(0.002..=0.6).contains(&g) { + return None; + } + let c_bot = { + let a = bottom[0][0]; + a[2] - gx * a[0] - gy * a[1] + }; + let fits = |tris: &[[[f64; 3]; 3]], c: f64| tris.iter().flatten().all(|q| (q[2] - (gx * q[0] + gy * q[1] + c)).abs() <= 1e-3); + if !fits(&top, c_top) || !fits(&bottom, c_bot) { + return None; + } + let t = c_top - c_bot; + if !(0.01..=3.0).contains(&t) { + return None; + } + let xy_area = |tris: &[[[f64; 3]; 3]]| -> f64 { tris.iter().map(|q| ((q[1][0] - q[0][0]) * (q[2][1] - q[0][1]) - (q[1][1] - q[0][1]) * (q[2][0] - q[0][0])).abs() / 2.0).sum() }; + let a = xy_area(&top); + if !(a > 1e-4 && (xy_area(&bottom) - a).abs() <= 0.01 * a && (signed_volume(&m.positions, &m.indices) - a * t).abs() <= 0.01 * a * t) { + return None; + } + let tris: Vec<[V2; 3]> = top.iter().map(|q| [[q[0][0], q[0][1]], [q[1][0], q[1][1]], [q[2][0], q[2][1]]]).collect(); + let mut outer: Option> = None; + let mut holes = Vec::new(); + for l in boundary_loops(&tris) { + if area2(&l) > 0.0 { + if outer.is_some() { + return None; + } + outer = Some(l); + } else { + holes.push(l.iter().rev().copied().collect::>()); + } + } + let outer = outer?; + let sum = area2(&outer) - holes.iter().map(|h| area2(h)).sum::(); + ((sum - a).abs() <= 0.01 * a).then_some((outer, holes, [gx, gy], c_top, t)) +} + /// Ausdehnung eines Körpers im Rahmen (Ursprung `o`, Richtung `d`, Normale `left(d)`): /// [u0,u1,v0,v1,z0,z1] und Füllgrad (Volumen / Quader). /// [168] Mitte der Hüllbox eines Netzes. @@ -1123,7 +1242,7 @@ impl Ctx<'_, '_> { } holes.push(ring); } - Ok(Slab { info: self.info(id, color), outline, holes, z0: s.z0, z1: s.z1 }) + Ok(Slab { info: self.info(id, color), outline, holes, z0: s.z0, z1: s.z1, slope: None }) } fn column(&mut self, id: u64) -> Result { @@ -1575,6 +1694,95 @@ fn stairs(cx: &mut Ctx, out: &mut Semantic, ids: &[u64], children: &HashMap>) { + let f = cx.r.f; + let rels = cx.rels; + for &id in ids { + let Some(e) = f.get(id) else { continue }; + if !matches!(e.ty.as_str(), "IFCRAMP" | "IFCRAMPFLIGHT") || rels.parent.get(&id).is_some_and(|p| !is_spatial(f, *p)) { + continue; + } + let mut parts = vec![id]; + parts.extend(children.get(&id).map(Vec::as_slice).unwrap_or(&[]).iter().copied().filter(|c| f.get(*c).is_some_and(|e| e.ty == "IFCRAMPFLIGHT"))); + let mut b = bodies(cx, &parts); + if b.is_empty() { + continue; + } + let class = class_name(&e.ty); + // Mehrere Läufe/Körper: nicht sicher als eine Platte lesbar. + if b.len() != 1 { + out.keep(&class, R_RAMP_FORM); + continue; + } + let (body_id, mesh, color) = b.remove(0); + let Some((outline, holes, [gx, gy], c_top, t)) = sloped_plate(&mesh) else { + out.keep(&class, R_RAMP_FORM); + continue; + }; + // Gefällelinie durch den Schwerpunkt des Umrisses, von der tiefsten bis zur höchsten Stelle. + let g = gx.hypot(gy); + let d = [gx / g, gy / g]; + let n = outline.len() as f64; + let c = outline.iter().fold([0.0, 0.0], |a, p| [a[0] + p[0] / n, a[1] + p[1] / n]); + let proj = |p: V2| p[0] * d[0] + p[1] * d[1]; + let (lo, hi) = outline.iter().fold((f64::INFINITY, f64::NEG_INFINITY), |a, p| (a.0.min(proj(*p)), a.1.max(proj(*p)))); + let (from, to) = ([c[0] + d[0] * (lo - proj(c)), c[1] + d[1] * (lo - proj(c))], [c[0] + d[0] * (hi - proj(c)), c[1] + d[1] * (hi - proj(c))]); + let z1 = gx * from[0] + gy * from[1] + c_top; + let mut info = cx.info(id, color); + if info.common.is_empty() && body_id != id { + info.common = cx.info(body_id, None).common; + } + out.converted.insert(id); + out.converted.insert(body_id); + out.slabs.push(Slab { info, outline, holes, z0: z1 - t, z1, slope: Some(SlabSlope { from, to, rise: g * (hi - lo), ramp: true }) }); + } +} + +/// [B4] Geländer des eigenen Exports: `Dossier_Railing` trägt die Achse (`Axis` = "x,y;x,y;…", `Closed`), Art, Handlauf und Höhe. +/// Übernommen wird nur, wenn der Körper dazu passt (Hüllbox enthält die Achse, Höhe = Körperhöhe); sonst bleibt es Mesh. +/// Fremde Geländer (ohne diese Eigenschaften) bleiben Mesh: aus einem Netz lässt sich keine Achse sicher lesen. +fn railings(cx: &mut Ctx, out: &mut Semantic, ids: &[u64]) { + let f = cx.r.f; + for &id in ids { + let Some(e) = f.get(id) else { continue }; + if e.ty != "IFCRAILING" || cx.rels.parent.get(&id).is_some_and(|p| !is_spatial(f, *p)) { + continue; + } + let Some(common) = cx.common.get(&id).filter(|c| c.contains_key("Axis")) else { continue }; + let axis: Option> = common["Axis"] + .split(';') + .map(|p| { + let (x, y) = p.split_once(',')?; + let q = [x.trim().parse::().ok()?, y.trim().parse::().ok()?]; + (q[0].is_finite() && q[1].is_finite()).then_some(q) + }) + .collect(); + let height = common.get("Height").and_then(|h| h.parse::().ok()).filter(|h| h.is_finite() && *h > 0.0); + let (closed, kind, handrail) = (common.get("Closed").is_some_and(|c| c == "yes"), common.get("Kind").cloned().unwrap_or_default(), common.get("Handrail").map(|h| h == "yes")); + let (Some(points), Some(height)) = (axis.filter(|a| a.len() >= 2), height) else { continue }; + if !["bars", "glass", "solid", "perforated"].contains(&kind.as_str()) { + continue; + } + let Some((mesh, color)) = cx.body(id) else { continue }; + let (mut lo, mut hi) = ([f64::INFINITY; 3], [f64::NEG_INFINITY; 3]); + for c in mesh.positions.chunks_exact(3) { + for k in 0..3 { + lo[k] = lo[k].min(c[k]); + hi[k] = hi[k].max(c[k]); + } + } + // Achsenpunkte liegen in der Hüllbox (Rand: halbe Füllungsdicke, Pfosten), Höhe stimmt auf 1 cm. + let tol = 0.3; + if !(lo.iter().chain(hi.iter()).all(|v| v.is_finite()) && ((hi[2] - lo[2]) - height).abs() <= 0.01 && points.iter().all(|p| p[0] >= lo[0] - tol && p[0] <= hi[0] + tol && p[1] >= lo[1] - tol && p[1] <= hi[1] + tol)) { + continue; + } + out.converted.insert(id); + out.railings.push(Railing { info: cx.info(id, color), points, closed, height, z0: lo[2], kind, handrail }); + } +} + /// Erkennt alle sicher abbildbaren Bauteile. pub(crate) fn analyze(r: &mut Reader, rels: &Rels, ids: &[u64]) -> Semantic { let f = r.f; @@ -1673,6 +1881,8 @@ pub(crate) fn analyze(r: &mut Reader, rels: &Rels, ids: &[u64]) -> Semantic { // Dächer zuerst: schräge Wandkronen darunter werden zum Dachanschluss. let roof_fail = roofs(&mut cx, &mut out, ids, &children); stairs(&mut cx, &mut out, ids, &children); + ramps(&mut cx, &mut out, ids, &children); + railings(&mut cx, &mut out, ids); let spatial = |id: u64| f.get(id).is_some_and(|e| matches!(e.ty.as_str(), "IFCBUILDINGSTOREY" | "IFCBUILDING" | "IFCSITE" | "IFCSPACE")); let mut walls = Vec::new(); @@ -1941,7 +2151,11 @@ pub(crate) fn encode(s: &Semantic) -> (serde_json::Value, Vec) { for h in &sl.holes { ring(h, &mut nums); } - push("slab", &sl.info, json!({}), nums, &mut data); + let extra = match &sl.slope { + Some(k) => json!({ "slope": { "from": k.from, "to": k.to, "rise": k.rise, "ramp": k.ramp } }), + None => json!({}), + }; + push("slab", &sl.info, extra, nums, &mut data); } for c in &s.columns { let (kind, a, b) = match c.profile { @@ -1965,6 +2179,12 @@ pub(crate) fn encode(s: &Semantic) -> (serde_json::Value, Vec) { ring(&b.outline, &mut nums); push("beam", &b.info, json!({}), nums, &mut data); } + for r in &s.railings { + let pts: Vec = r.points.iter().flatten().copied().collect(); + let mut nums = vec![r.z0, r.height, r.points.len() as f64]; + nums.extend(pts); + push("railing", &r.info, json!({ "railingKind": r.kind, "closed": r.closed, "handrail": r.handrail }), nums, &mut data); + } for st in &s.stairs { let nums = vec![ st.start[0], st.start[1], st.dir[0], st.dir[1], st.run_length, st.width, st.step_count as f64, st.z0, st.total_rise, st.run2_length, st.turn, st.center[0], st.center[1], st.radius, st.sweep_deg, st.center_column, @@ -2621,6 +2841,28 @@ ENDSEC;\nEND-ISO-10303-21;\n" assert_eq!(sm.kept.get("IfcBeam"), Some(&1), "{:?}", sm.kept_reasons); } + #[test] + fn ramp_flight_becomes_sloped_slab_and_other_forms_stay_mesh() { + // Rampe 10 × 4, steigt in +y mit 10 % von z = 0.5, 0.2 dick (lotrecht) ⇒ UK bei y = 0: 0.3. + let plate = roof_plate(0.0, 10.0, 0.0, 4.0, 0.5, 0.1, 0.2 / (1.0 + 0.01f64).sqrt()); + let flight = brep_product(100, "IFCRAMPFLIGHT", &plate, ".STRAIGHT."); + let (r, sm) = sem(&file(METRE, &flight)); + assert_eq!(sm.slabs.len(), 1, "{:?}", sm.kept_reasons); + assert!(r.products.is_empty(), "als Bauteil erkannt, nicht als Mesh"); + let sl = &sm.slabs[0]; + let k = sl.slope.expect("Gefälle"); + assert!(k.ramp); + assert!(close(k.rise.abs(), 0.4) && close(k.from[0], 5.0) && close2(k.to, [5.0, 4.0]) && close(sl.z1 - sl.z0, 0.2), "{sl:?}"); + assert!(close(sl.z1, 0.5) && sl.outline.len() == 4); + // Zwei Läufe: nicht sicher eine Platte ⇒ Mesh. + let a = brep_product(200, "IFCRAMPFLIGHT", &plate, ".STRAIGHT."); + let b = brep_product(300, "IFCRAMPFLIGHT", &roof_plate(0.0, 10.0, 6.0, 10.0, 0.5, 0.1, 0.2), ".STRAIGHT."); + let ramp = "#900=IFCRAMP('rp',$,'R',$,$,#22,$,$,.STRAIGHT_RUN_RAMP.);#901=IFCRELAGGREGATES('ra',$,$,$,#900,(#200,#300));#902=IFCRELCONTAINEDINSPATIALSTRUCTURE('rr',$,$,$,(#900),#23);"; + let (_, sm) = sem(&file(METRE, &format!("{a}{b}{ramp}"))); + assert!(sm.slabs.is_empty()); + assert_eq!(sm.kept.get("IfcRamp"), Some(&1), "{:?}", sm.kept_reasons); + } + #[test] fn map_conversion_is_read() { let geo = "#700=IFCPROJECTEDCRS('EPSG:2056',$,$,$,$,$,#701);#701=IFCSIUNIT(*,.LENGTHUNIT.,$,.METRE.);\ diff --git a/src/i18n/de.ts b/src/i18n/de.ts index 81d18230..52a8d7fa 100644 --- a/src/i18n/de.ts +++ b/src/i18n/de.ts @@ -3099,7 +3099,8 @@ export const de = { "ifc.importReport.rooms": "Räume", "ifc.importReport.roofs": "Dächer", "ifc.importReport.stairs": "Treppen", - "ifc.importReport.beams": "Träger (als Extrusionskörper)", + "ifc.importReport.beams": "Träger (rechteckige als Träger, sonst Extrusionskörper)", + "ifc.importReport.railings": "Geländer", "ifc.importReport.floors": "Neue Geschosse", "ifc.importReport.types": "Neue Typen (Wand, Decke, Dach, Tür, Fenster)", "ifc.importReport.meshes": "Übrige Bauteile als Kontext-Mesh", @@ -3115,6 +3116,7 @@ export const de = { "ifc.reason.holes": "Raum mit Loch", "ifc.reason.part": "Teil eines anderen Bauteils", "ifc.reason.roofForm": "Dachform nicht abbildbar (kein Rechteck, ungleiche Neigung, Tonnendach …)", + "ifc.reason.rampForm": "Rampe ist keine ebene schräge Platte (mehrere Läufe, gekrümmt, Stufen)", "ifc.reason.stairForm": "keine gleichmässige gerade, L-, U-, Podest- oder Wendeltreppe", "ifc.reason.stairTurn": "Podesttreppe, die Dossier nicht abbildet (mehr als zwei Podeste, Podest nicht an der Ecke, ungleiche Läufe)", "menu.native.importMesh": "3D-Modell importieren …", diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 8a687785..9f37fd74 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -3047,7 +3047,8 @@ export const en: Record = { "ifc.importReport.rooms": "Rooms", "ifc.importReport.roofs": "Roofs", "ifc.importReport.stairs": "Stairs", - "ifc.importReport.beams": "Beams (as extruded solids)", + "ifc.importReport.beams": "Beams (rectangular ones as beams, others as extruded solids)", + "ifc.importReport.railings": "Railings", "ifc.importReport.floors": "New floors", "ifc.importReport.types": "New types (wall, slab, roof, door, window)", "ifc.importReport.meshes": "Other elements as context mesh", @@ -3063,6 +3064,7 @@ export const en: Record = { "ifc.reason.holes": "room with a hole", "ifc.reason.part": "part of another element", "ifc.reason.roofForm": "roof shape not mappable (not a rectangle, unequal pitch, barrel roof …)", + "ifc.reason.rampForm": "ramp is not a single planar sloped slab (several flights, curved, stepped)", "ifc.reason.stairForm": "not a regular straight, L, U, landing or spiral stair", "ifc.reason.stairTurn": "landing stair Dossier cannot represent (more than two landings, landing not at the corner, unequal flights)", "menu.native.importMesh": "Import 3D model …", diff --git a/src/io/ifcImport.roundtrip.test.ts b/src/io/ifcImport.roundtrip.test.ts new file mode 100644 index 00000000..bf226d0d --- /dev/null +++ b/src/io/ifcImport.roundtrip.test.ts @@ -0,0 +1,75 @@ +// [B4] Rundreise Export → Import für Träger, Geländer, Rampen und Dächer: Fachplaner-Austausch darf Bauteile nicht in Körper +// verwandeln. Anzahl je Bauteilart gleich; Träger (Achse, Breite, Höhe), Geländer (Achse, Höhe, Art) und Rampe (Gefälle, +// Umriss) stimmen; die Dachplatten kommen nicht zusätzlich zum Dach als Netz. + +import "../engine/fileioWasm.setup"; +import { describe, expect, it } from "vitest"; +import { exportIfcSpf } from "../export/exportIfc"; +import { emptyProject } from "../model/sampleProject"; +import { buildComplexSampleProject } from "../model/sampleProjectComplex"; +import { buildWettbewerbSampleProject } from "../model/sampleProjectWettbewerb"; +import type { Project } from "../model/types"; +import type { IfcElementsSummary } from "./ifcImport"; +import { importIfcInto } from "./importView.testutil"; + +const near = (a: number, b: number, tol = 1e-5) => Math.abs(a - b) <= tol; + +async function roundtrip(src: Project) { + const spf = exportIfcSpf(src); + const r = await importIfcInto({ ...emptyProject, drawingLevels: src.drawingLevels }, new TextEncoder().encode(spf), { elements: true }); + return { spf, p: r.project, summary: r.summary as IfcElementsSummary }; +} +const count = (spf: string, cls: string) => (spf.match(new RegExp(`=${cls}\\(`, "g")) ?? []).length; +const len = (a: { start: { x: number; y: number }; end: { x: number; y: number } }) => Math.hypot(a.end.x - a.start.x, a.end.y - a.start.y); +const mid = (a: { start: { x: number; y: number }; end: { x: number; y: number } }) => [(a.start.x + a.end.x) / 2, (a.start.y + a.end.y) / 2]; + +describe("[B4] IFC-Rundreise: Träger, Geländer, Rampen, Dächer", () => { + it(":komplex: Träger kommen als Träger zurück, Dächer nicht doppelt", async () => { + const src = buildComplexSampleProject(); + const { spf, p, summary } = await roundtrip(src); + expect(src.beams!.length).toBeGreaterThan(0); + expect(count(spf, "IFCBEAM")).toBe(src.beams!.length); + expect(p.beams?.length).toBe(src.beams!.length); + expect(p.extrudedSolids ?? []).toEqual([]); + expect(summary.beams).toBe(src.beams!.length); + for (const b of src.beams!) { + const got = p.beams!.find((g) => g.floorId === b.floorId && near(len(g), len(b)) && near(mid(g)[0], mid(b)[0]) && near(mid(g)[1], mid(b)[1]))!; + expect(got, b.id).toBeDefined(); + expect(near(got.width, b.width) && near(got.height, b.height), JSON.stringify(got)).toBe(true); + expect(near(got.topOffset ?? 0, b.topOffset ?? 0, 1e-4), JSON.stringify([got.topOffset, b.topOffset])).toBe(true); + } + // Dach: Dachplatten (IfcSlab ROOF) kommen nicht zusätzlich zum Dach als Kontext-Netz. + const roofSlabs = (spf.match(/=IFCSLAB\([^;]*\.ROOF\.\);/g) ?? []).length; + expect(roofSlabs).toBeGreaterThan(0); + const gids = (p.context ?? []).map((c) => (c as { ifcGlobalId?: string }).ifcGlobalId).filter(Boolean); + expect(new Set(gids).size, "kein Bauteil doppelt als Netz").toBe(gids.length); + }); + + it(":wettbewerb: Geländer und Rampe kommen als Bauteile zurück", async () => { + const src = buildWettbewerbSampleProject(); + const { spf, p, summary } = await roundtrip(src); + expect((spf.match(/IFCPROPERTYSET\([^;]*Dossier_Railing/g) ?? []).length).toBe(src.railings!.length); + expect(p.railings?.length).toBe(src.railings!.length); + expect(summary.railings).toBe(src.railings!.length); + for (const r of src.railings!) { + const got = p.railings!.find((g) => g.floorId === r.floorId && g.points.length === r.points.length && g.points.every((q, i) => near(q.x, r.points[i].x) && near(q.y, r.points[i].y)))!; + expect(got, r.id).toBeDefined(); + expect(near(got.height, r.height)).toBe(true); + expect(got.kind).toBe(r.kind); + expect(got.closed ?? false).toBe(r.closed ?? false); + expect(near(got.baseOffset ?? 0, r.baseOffset ?? 0, 1e-4)).toBe(true); + } + const ramps = (src.ceilings ?? []).filter((c) => c.slope?.ramp); + expect(ramps.length).toBeGreaterThan(0); + expect(count(spf, "IFCRAMP\\b")).toBe(ramps.length); + expect((p.ceilings ?? []).filter((c) => c.slope?.ramp).length).toBe(ramps.length); + expect((p.ceilings ?? []).length).toBe((src.ceilings ?? []).length); + for (const c of ramps) { + const grade = (s: NonNullable) => s.rise / Math.hypot(s.to.x - s.from.x, s.to.y - s.from.y); + const got = (p.ceilings ?? []).find((g) => g.slope?.ramp && near(Math.abs(g.slope.rise), Math.abs(c.slope!.rise), 1e-3))!; + expect(got, c.id).toBeDefined(); + expect(Math.abs(grade(got.slope!))).toBeCloseTo(Math.abs(grade(c.slope!)), 3); + expect(got.outline.length).toBe(c.outline.length); + } + }); +}); diff --git a/src/io/ifcImport.ts b/src/io/ifcImport.ts index d39a926f..6b581516 100644 --- a/src/io/ifcImport.ts +++ b/src/io/ifcImport.ts @@ -123,8 +123,10 @@ export interface IfcElementsSummary { /** Dächer (Flach/Pult/Sattel/Walm, auch mit Neigung je Kante) und Treppen (gerade, L, Wendel) ([B4]). */ roofs: number; stairs: number; - /** Träger (IfcBeam) als Extrusionskörper ([B4]). */ + /** Träger (IfcBeam): rechteckige als Träger, sonst Extrusionskörper ([B4]). */ beams?: number; + /** Geländer des eigenen Exports (Achse im Pset `Dossier_Railing`) ([B4]). */ + railings?: number; /** Neu angelegte Geschosse. */ floors: number; wallTypes: number; diff --git a/src/ui/IfcImportDialog.tsx b/src/ui/IfcImportDialog.tsx index 4d5463bf..25a70025 100644 --- a/src/ui/IfcImportDialog.tsx +++ b/src/ui/IfcImportDialog.tsx @@ -79,6 +79,7 @@ const RECOGNIZED: ReadonlyArray<[string, (s: IfcElementsSummary) => number]> = [ ["ifc.importReport.roofs", (s) => s.roofs ?? 0], ["ifc.importReport.stairs", (s) => s.stairs ?? 0], ["ifc.importReport.beams", (s) => s.beams ?? 0], + ["ifc.importReport.railings", (s) => s.railings ?? 0], ["ifc.importReport.columns", (s) => s.columns], ["ifc.importReport.rooms", (s) => s.rooms], ["ifc.importReport.floors", (s) => s.floors],