diff --git a/TODO.md b/TODO.md index 392a5931..64b596b5 100644 --- a/TODO.md +++ b/TODO.md @@ -369,6 +369,15 @@ Ganzes nicht WASM-tauglich (rayon, tempfile, SystemTime) — nur einzelne Module Profiländerung, Decken aus Dreiecksnetzen mit T-Stössen (zwei Teilflächen → Mesh), Tür-Anschlag/ Öffnungsrichtung, Tür-/Fenstertyp aus IfcDoorType/IfcWindowType, Farbe der Bauteile; nur Linux- Container/vitest, nicht in der Tauri-App geprüft (Dialog nur per tsc). + (28.10., Tür-Ausführung) Tür: OperationType (IfcDoor, sonst IfcDoorType/IfcDoorStyle) → Scharnierseite + (LEFT = Scharnier auf +X der Tür-Platzierung, von der Aufschlagseite +Y gesehen, wie unser Export) und + Aufschlagseite (+Y gegen die Wandachse), Türtyp nach Dreh/Schiebe und Blattzahl; Fenster: + PartitioningType (IfcWindow, sonst IfcWindowType/IfcWindowStyle) → Fenstertyp mit gleicher Flügelzahl, + sonst `wingCount` an der Öffnung. Erkennung in Rust (`ifc_semantic.rs::operation`), TS ordnet zu. + Rundreise: alle 8 Kombinationen Scharnier/Aufschlag/Richtung landen räumlich gleich (Scharnierpunkt, + Aufschlagrichtung; `openingDir` kommt als „in“ mit gespiegeltem `swing` zurück), 2-flügliges Fenster → + Typ „Fenster 2-flügl.“. Offen: LEFT/RIGHT nur gegen den eigenen Export geprüft (nicht Revit/ArchiCAD); + Türen ohne Ausführung bleiben beim Standard (kein Raten aus der Platzierung). - ◐ **[B5] IFC-Export nachziehen** (`exportIfc.ts`). Stand 28.10.: - ✅ Nicht-ASCII nach ISO 10303-21 (`\X2\`/`\X4\`). - ✅ Materialschichten: Wand-/Decken-/Dachtypen als IfcWallType/IfcSlabType/IfcRoofType mit diff --git a/src-tauri/fileio/src/ifc_semantic.rs b/src-tauri/fileio/src/ifc_semantic.rs index b4f56d2e..d302d0c7 100644 --- a/src-tauri/fileio/src/ifc_semantic.rs +++ b/src-tauri/fileio/src/ifc_semantic.rs @@ -107,6 +107,15 @@ pub struct Opening { /// Brüstung über Wand-Unterkante. pub sill: f64, pub height: f64, + /// Ausführung: IfcDoorTypeOperationEnum (Tür) bzw. IfcWindowTypePartitioningEnum (Fenster) vom + /// Bauteil, sonst vom Typ (IfcDoorType/IfcWindowType, IFC2x3 IfcDoorStyle/IfcWindowStyle); + /// NOTDEFINED/USERDEFINED → `None`. + pub operation: Option, + /// Tür: Aufschlag (+Y der Tür-Platzierung, IFC) links (+1) bzw. rechts (−1) der Wandachse; 0 = unbekannt. + pub swing: i8, + /// Tür: Scharnier am Wandanfang (+1) bzw. -ende (−1) nach LEFT/RIGHT der Ausführung (IFC: von der + /// Aufschlagseite gesehen; LEFT = Scharnier auf +X der Tür-Platzierung); 0 = unbekannt. + pub hinge: i8, } #[derive(Clone, Debug, Default)] @@ -488,6 +497,44 @@ struct Ctx<'r, 'a> { } impl Ctx<'_, '_> { + /// Ausführung, Aufschlagseite und Scharnier einer Tür/eines Fensters (s. [`Opening`]); `d` = + /// Richtung der (endgültigen) Wandachse. + fn operation(&mut self, id: u64, d: V2) -> (Option, i8, i8) { + let f = self.r.f; + let Some(e) = f.get(id) else { return (None, 0, 0) }; + let pick = |v: Option<&Value>| v.and_then(|v| v.as_enum()).filter(|x| *x != "NOTDEFINED" && *x != "USERDEFINED").map(str::to_string); + // IFC4: IfcDoor.OperationType / IfcWindow.PartitioningType (12. Attribut). + let own = if e.ty.starts_with("IFCDOOR") || e.ty.starts_with("IFCWINDOW") { pick(e.arg(11)) } else { None }; + let op = own.or_else(|| { + let t = f.get(*self.type_of.get(&id)?)?; + match t.ty.as_str() { + "IFCDOORTYPE" | "IFCWINDOWTYPE" => pick(t.arg(10)), + "IFCDOORSTYLE" => pick(t.arg(8)), + "IFCWINDOWSTYLE" => pick(t.arg(9)), + _ => None, + } + }); + // Seite nur mit bekannter Ausführung (ohne sie ist die Platzierung oft einfach die der Wand). + if !e.ty.starts_with("IFCDOOR") || op.is_none() { + return (op, 0, 0); + } + let Some(place) = e.arg(5).and_then(|v| v.as_ref_id()) else { return (op, 0, 0) }; + let xf = self.r.object_placement(place, 0); + let x = xf.apply_dir([1.0, 0.0, 0.0]); + let y = xf.apply_dir([0.0, 1.0, 0.0]); + let (Some(x), Some(y)) = (unit2([x[0], x[1]]), unit2([y[0], y[1]])) else { return (op, 0, 0) }; + let side = |v: f64| if v > 0.5 { 1 } else if v < -0.5 { -1 } else { 0 }; + let swing = side(dot2(y, left(d))); + let hinge = match op.as_deref() { + Some(o) if !o.starts_with("DOUBLE_DOOR") && (o.ends_with("LEFT") || o.ends_with("RIGHT")) => { + let h = if o.ends_with("LEFT") { x } else { [-x[0], -x[1]] }; + -side(dot2(h, d)) + } + _ => 0, + }; + (op, swing, hinge) + } + fn info(&self, id: u64, color: Option<[f64; 4]>) -> Info { let f = self.r.f; let Some(e) = f.get(id) else { return Info::default() }; @@ -954,10 +1001,25 @@ pub(crate) fn analyze(r: &mut Reader, rels: &Rels, ids: &[u64]) -> Semantic { let z0 = b[4].max(w.z0); let z1 = b[5].min(w.z1); let info = cx.info(filling.unwrap_or(*o), None); + let (operation, swing, hinge) = match filling { + Some(x) => cx.operation(*x, d), + None => (None, 0, 0), + }; if let Some(x) = filling { out.converted.insert(*x); } - out.openings.push(Opening { info, host, kind: *kind, position: u0, width: u1 - u0, sill: z0 - w.z0, height: z1 - z0 }); + out.openings.push(Opening { + info, + host, + kind: *kind, + position: u0, + width: u1 - u0, + sill: z0 - w.z0, + height: z1 - z0, + operation, + swing, + hinge, + }); } out.walls.push(Wall { info: w.info, start, end, z0: w.z0, z1: w.z1, thickness: w.thickness }); } @@ -967,7 +1029,7 @@ pub(crate) fn analyze(r: &mut Reader, rels: &Rels, ids: &[u64]) -> Semantic { // --------------------------------------------------------------------------- // Flache Kodierung für JS: Texte/Verweise als JSON, Zahlen in einem Float64Array. // wall: sx, sy, ex, ey, z0, z1, thickness -// opening: position, width, sill, height +// opening: position, width, sill, height, swing (±1/0), hinge (±1/0) // slab: z0, z1, nRings, (nPts, x, y, …)* (erster Ring = Umriss) // column: cx, cy, rotation, z0, z1, a, b (rect: Breite, Tiefe; round: Radius, 0) // space: z0, z1, nPts, x, y, … @@ -1018,7 +1080,13 @@ pub(crate) fn encode(s: &Semantic) -> (serde_json::Value, Vec) { OpeningKind::Window => "window", OpeningKind::Hole => "hole", }; - push("opening", &o.info, json!({ "host": o.host, "openingKind": kind }), vec![o.position, o.width, o.sill, o.height], &mut data); + push( + "opening", + &o.info, + json!({ "host": o.host, "openingKind": kind, "operation": o.operation }), + vec![o.position, o.width, o.sill, o.height, o.swing as f64, o.hinge as f64], + &mut data, + ); } for sl in &s.slabs { let mut nums = vec![sl.z0, sl.z1, (1 + sl.holes.len()) as f64]; @@ -1221,6 +1289,33 @@ ENDSEC;\nEND-ISO-10303-21;\n" let w = &s.walls[0]; assert!(close2(w.start, [6.0, 0.0]) && close2(w.end, [0.0, 0.0]), "{w:?}"); assert!(close(s.openings[0].position, 6.0 - 1.9)); + // Ohne Ausführung und Platzierung: nichts abgeleitet. + assert_eq!((s.openings[0].operation.as_deref(), s.openings[0].swing, s.openings[0].hinge), (None, 0, 0)); + + // Tür-Ausführung ([B4]): OperationType am Bauteil, eigene Platzierung in der Öffnungsmitte mit + // X = −x (Y = Z × X = −y = Aufschlag nach rechts der Wandachse +x). LEFT = Scharnier auf +X der + // Tür = −x-Seite = Wandanfang. Fenster: PartitioningType am Typ (IfcRelDefinesByType). + let door = "#800=IFCDOOR('f800',$,'F800',$,$,#820,$,$,2100.,900.,.DOOR.,.SINGLE_SWING_LEFT.,$);\ +#821=IFCCARTESIANPOINT((1450.,0.,0.));#822=IFCDIRECTION((-1.,0.,0.));#823=IFCAXIS2PLACEMENT3D(#821,#11,#822);#820=IFCLOCALPLACEMENT(#1004,#823);"; + let window = "#830=IFCWINDOWTYPE('wt',$,'Fenster 2',$,$,$,$,$,$,.WINDOW.,.DOUBLE_PANEL_VERTICAL.,$,$);\ +#831=IFCRELDEFINESBYTYPE('dt',$,$,$,(#810),#830);"; + let src2 = src.replace("#800=IFCDOOR('f800',$,'F800',$,$,#1004,$,$,$,$,$,$,$);", door) + ""; + let src2 = src2.replace("#906=IFCRELASSOCIATESMATERIAL", &format!("{window}#906=IFCRELASSOCIATESMATERIAL")); + let (_, s) = sem(&src2); + let d = &s.openings[0]; + assert_eq!((d.operation.as_deref(), d.swing, d.hinge), (Some("SINGLE_SWING_LEFT"), -1, 1), "{d:?}"); + assert_eq!(s.openings[1].operation.as_deref(), Some("DOUBLE_PANEL_VERTICAL")); + // Umgekehrte Wand: Scharnier am Ende, Aufschlag links der neuen Richtung. + let (_, s) = sem(&src2.replace(".POSITIVE.", ".NEGATIVE.")); + assert_eq!((s.openings[0].swing, s.openings[0].hinge), (1, -1)); + // RIGHT: Scharnier auf −X der Tür = +x-Seite = Wandende. + let (_, s) = sem(&src2.replace(".SINGLE_SWING_LEFT.", ".SINGLE_SWING_RIGHT.")); + assert_eq!((s.openings[0].swing, s.openings[0].hinge), (-1, -1)); + // Zweiflüglig: Seite ohne Scharnier-Angabe; NOTDEFINED zählt nicht. + let (_, s) = sem(&src2.replace(".SINGLE_SWING_LEFT.", ".DOUBLE_DOOR_SINGLE_SWING.")); + assert_eq!((s.openings[0].operation.as_deref(), s.openings[0].swing, s.openings[0].hinge), (Some("DOUBLE_DOOR_SINGLE_SWING"), -1, 0)); + let (_, s) = sem(&src2.replace(".SINGLE_SWING_LEFT.", ".NOTDEFINED.")); + assert_eq!(s.openings[0].operation, None); } #[test] diff --git a/src/io/ifcElements.test.ts b/src/io/ifcElements.test.ts index 04eeec5c..6397c483 100644 --- a/src/io/ifcElements.test.ts +++ b/src/io/ifcElements.test.ts @@ -79,6 +79,42 @@ describe("IFC-Import als Bauteile: Rundreise Demo-Haus", () => { expect(text).toContain('"walls":9'); }); + it("Tür-Anschlag/Aufschlag und Fensterteilung aus OperationType/PartitioningType (Rundreise)", async () => { + // Lage im Raum vergleichen (die Wand kann umgekehrt ankommen): Scharnierpunkt und Aufschlagrichtung. + const physical = (o: Opening, w: Wall) => { + const l = Math.hypot(w.end.x - w.start.x, w.end.y - w.start.y); + const u = { x: (w.end.x - w.start.x) / l, y: (w.end.y - w.start.y) / l }; + const along = (o.hinge ?? "start") === "start" ? o.position : o.position + o.width; + const s = ((o.swing ?? "left") === "left" ? 1 : -1) * ((o.openingDir ?? "in") === "in" ? 1 : -1); + return { hinge: { x: w.start.x + u.x * along, y: w.start.y + u.y * along }, swing: { x: -u.y * s, y: u.x * s } }; + }; + for (const hinge of ["start", "end"] as const) + for (const swing of ["left", "right"] as const) + for (const openingDir of ["in", "out"] as const) { + const src: Project = { + ...sampleProject, + openings: (sampleProject.openings ?? []).map((o) => + o.id === "D1" ? { ...o, hinge, swing, openingDir } : o.id === "O2" ? { ...o, wingCount: 2 } : o, + ), + }; + const { project: p } = await importInto(emptyProject, src); + const d1 = src.openings!.find((o) => o.id === "D1")!; + const w1 = src.walls.find((w) => w.id === d1.hostWallId)!; + const got = (p.openings ?? []).find((o) => o.kind === "door")!; + const gw = p.walls.find((w) => w.id === got.hostWallId)!; + const want = physical(d1, w1); + const have = physical(got, gw); + const tag = `${hinge}/${swing}/${openingDir}`; + expect(near(have.hinge, want.hinge), tag).toBe(true); + expect(near(have.swing, want.swing), tag).toBe(true); + expect(got.typeId, tag).toBe("door-standard"); + // Fenster O2 mit zwei Flügeln: Typ mit zwei Flügeln (oder eigene Flügelzahl). + const o2 = (p.openings ?? []).find((o) => o.kind === "window" && Math.abs(o.width - 1.4) < 1e-6)!; + const wt = (p.windowTypes ?? []).find((t) => t.id === o2.typeId); + expect(o2.wingCount ?? wt?.wingCount, tag).toBe(2); + } + }); + it("in ein Projekt ohne Geschosse/Typen: legt Geschosse, Wand-/Deckentypen und Materialien an", async () => { const bare: Project = { ...emptyProject, diff --git a/src/io/ifcElements.ts b/src/io/ifcElements.ts index 35a1cd2a..c09999a9 100644 --- a/src/io/ifcElements.ts +++ b/src/io/ifcElements.ts @@ -77,6 +77,12 @@ export interface IfcOpeningData extends IfcInfo { width: number; sill: number; height: number; + /** Ausführung: IfcDoorTypeOperationEnum bzw. IfcWindowTypePartitioningEnum (Bauteil, sonst Typ). */ + operation: string | null; + /** Tür: Aufschlag links (+1) / rechts (−1) der Wandachse, 0 = unbekannt (Rust `ifc_semantic`). */ + swing: number; + /** Tür: Scharnier am Wandanfang (+1) / -ende (−1), 0 = unbekannt. */ + hinge: number; } export interface IfcSlabData extends IfcInfo { outline: Vec2[]; @@ -117,6 +123,7 @@ interface RawElement extends IfcInfo { n: number; host?: number; openingKind?: "door" | "window" | "hole"; + operation?: string | null; profile?: "rect" | "round"; longName?: string | null; sia?: string | null; @@ -170,8 +177,19 @@ export function decodeIfcElements(flat: IfcFlat): IfcElementsData | null { break; case "opening": { const host = wallIndex.get(e.host ?? -1); - if (host !== undefined && v.length === 4) { - out.openings.push({ ...info, host, kind: e.openingKind ?? "hole", position: v[0], width: v[1], sill: v[2], height: v[3] }); + if (host !== undefined && v.length === 6) { + out.openings.push({ + ...info, + host, + kind: e.openingKind ?? "hole", + position: v[0], + width: v[1], + sill: v[2], + height: v[3], + operation: e.operation ?? null, + swing: Math.sign(v[4]), + hinge: Math.sign(v[5]), + }); } break; } @@ -422,7 +440,26 @@ export function ifcElementsToProject( const host = walls[o.host]; if (!host) continue; const kind = o.kind === "window" ? "window" : "door"; - const typeId = o.kind === "door" ? project.doorTypes?.[0]?.id : o.kind === "window" ? project.windowTypes?.[0]?.id : undefined; + const op = o.operation ?? ""; + // Tür: Typ nach Art (Dreh/Schiebe) und Blattzahl aus der Ausführung, sonst der erste Typ. + const sliding = op.includes("SLIDING"); + const leaves = op.startsWith("DOUBLE_DOOR") ? 2 : 1; + const doorType = + (op ? project.doorTypes?.find((t) => t.kind === (sliding ? "schiebe" : "dreh") && t.leafCount === leaves) : undefined) ?? + project.doorTypes?.[0]; + // Fenster: Flügelzahl aus der Teilung (nur senkrechte Standardfälle); Typ mit dieser Flügelzahl, sonst + // der erste Typ mit eigener Flügelzahl an der Öffnung. + const wings = ({ SINGLE_PANEL: 1, DOUBLE_PANEL_VERTICAL: 2, TRIPLE_PANEL_VERTICAL: 3 } as Record)[op]; + const windowType = (wings ? project.windowTypes?.find((t) => t.wingCount === wings) : undefined) ?? project.windowTypes?.[0]; + const typeId = o.kind === "door" ? doorType?.id : o.kind === "window" ? windowType?.id : undefined; + const doorExtra = + o.kind === "door" + ? { + ...(o.hinge !== 0 ? { hinge: o.hinge > 0 ? ("start" as const) : ("end" as const) } : {}), + ...(o.swing !== 0 ? { swing: o.swing > 0 ? ("left" as const) : ("right" as const) } : {}), + } + : {}; + const windowExtra = o.kind === "window" && wings && (windowType?.wingCount ?? 1) !== wings ? { wingCount: wings } : {}; openings.push({ id: newId("opening"), type: "opening", @@ -435,6 +472,8 @@ export function ifcElementsToProject( sillHeight: round(o.sill, 1e-6), ...(o.kind === "hole" ? { doorType: "wandoeffnung" as const } : {}), ...(typeId ? { typeId } : {}), + ...doorExtra, + ...windowExtra, }); }