diff --git a/src-tauri/core/src/ifc_data.rs b/src-tauri/core/src/ifc_data.rs index f79532e8..aac22cf5 100644 --- a/src-tauri/core/src/ifc_data.rs +++ b/src-tauri/core/src/ifc_data.rs @@ -1389,7 +1389,11 @@ fn w_stair(f: &mut Flat, structure: f64, id: &str, predefined: &str, footprint: f.nums(&[n, fl.risers, fl.treads, fl.riser_height, fl.tread_length]); let p = f.str(fl.predefined); f.num(p); - w_psets(f, &qto("Qto_StairFlightBaseQuantities", fl.quantities.clone())); + let mut psets = qto("Qto_StairFlightBaseQuantities", fl.quantities.clone()); + if let Some(a) = fl.soffit_area { + psets.extend(qto("Dossier_StairFlightQuantities", vec![Qty { name: "SoffitArea", kind: QtyKind::Area, value: a }])); + } + w_psets(f, &psets); match &fl.body { FlightBody::Mesh(m) => { f.num(1.0); @@ -1427,6 +1431,18 @@ fn w_stair(f: &mut Flat, structure: f64, id: &str, predefined: &str, footprint: f.num(0.0); } } + match &parts.column { + Some(c) => { + let n = f.str("Spindel"); + f.nums(&[1.0, n]); + w_pts(f, &c.pts); + f.nums(&[c.z_rel, c.depth]); + w_psets(f, &qto("Qto_ColumnBaseQuantities", c.quantities.clone())); + } + None => { + f.num(0.0); + } + } } #[cfg(test)] diff --git a/src-tauri/core/src/ifc_stairs.rs b/src-tauri/core/src/ifc_stairs.rs index dd977855..1cf0b911 100644 --- a/src-tauri/core/src/ifc_stairs.rs +++ b/src-tauri/core/src/ifc_stairs.rs @@ -9,9 +9,12 @@ //! Zuordnung der Tritt-Prismen: bei "L" ist das Podest das Prisma mit dem Umriss des Podest-Polygons //! der Treppengeometrie; Tritte bis zur Podest-Oberkante gehören zum ersten, die darüber zum //! zweiten Lauf. Gerade und Wendeltreppen haben einen Lauf (die Wendel-Mitte bleibt Teil davon). +//! Die Mittelsäule (Spindel, `Stair.centerColumn`) einer Wendel ist kein Tritt: eigener Teil +//! (IfcColumn) mit Stützen-Basismengen. Ortbeton-Läufe (Netz) tragen zusätzlich die Untersicht +//! (Schalfläche, bei der Wendel die Wendelfläche) in `Dossier_StairFlightQuantities`. use crate::export_flat::{js_key, mesh_volume, orient_outward}; -use crate::ifc_quantities::{flight_quantities, railing_quantities, ring_area, slab_quantities, Qty}; +use crate::ifc_quantities::{column_quantities, flight_quantities, railing_quantities, ring_area, slab_quantities, Qty}; use crate::jsmath::hypot2; use crate::jsnum::round; use crate::model::*; @@ -48,6 +51,8 @@ pub struct StairFlightParts { /// IfcStairFlightTypeEnum. pub predefined: &'static str, pub quantities: Vec, + /// Untersicht (m²) eines Ortbeton-Laufs (Netz); `None` bei Tritt-Prismen. + pub soffit_area: Option, pub body: FlightBody, } @@ -70,6 +75,8 @@ pub struct StairParts { pub flights: Vec, pub landing: Option, pub rail: Option, + /// Mittelsäule (Spindel) einer Wendel: Prisma + Stützen-Basismengen. + pub column: Option, } const EPS: f64 = 1e-6; @@ -112,6 +119,53 @@ fn ifc_mesh(mut positions: Vec, indices: &[u32], base: f64) -> IfcMesh { IfcMesh { positions, indices } } +/// Untersicht eines geschlossenen, nach aussen orientierten Netzes: Summe der Dreiecke, deren +/// Normale nach unten zeigt (Schalfläche; bei der Wendel die Wendelfläche samt flachem Anlauf). +pub fn soffit_area(positions: &[f64], indices: &[u32]) -> f64 { + let p = |i: u32| { + let k = 3 * i as usize; + [positions[k], positions[k + 1], positions[k + 2]] + }; + let mut sum = 0.0; + for t in indices.chunks_exact(3) { + if t.iter().any(|&i| 3 * i as usize + 2 >= positions.len()) { + continue; + } + 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 len = crate::jsmath::hypot(&[n[0], n[1], n[2]]); + if len > 0.0 && n[2] < -1e-9 * len { + sum += len / 2.0; + } + } + sum +} + +/// Ortbeton-Lauf (Netz) einer Treppe: (Betonvolumen m³, Untersicht m²); `None` ohne Netz (keine +/// Beton-Gerade/-Wendel). `one` wie bei [`stair_parts`]. Ohne Mittelsäule. +pub fn concrete_flight_amounts(one: &Project) -> Option<(f64, f64)> { + let meshes = model3d::emit_stair_meshes(one); + if meshes.is_empty() { + return None; + } + let (positions, indices) = concat(&meshes); + let m = ifc_mesh(positions, &indices, 0.0); + Some((mesh_volume(&m.positions, &m.indices), soffit_area(&m.positions, &m.indices))) +} + +/// Lauflänge auf der Lauflinie: Wendel = Schraubenlinie im Laufradius, sonst Lauflänge; mit Steigung. +fn walk_length(stair: &Stair, rise: f64) -> f64 { + let run = if stair.shape == StairShape::Spiral { + let half_w = 0.05_f64.max(stair.width / 2.0); + let radius = (half_w + 0.1).max(stair.radius.unwrap_or(stair.width)); + stair.sweep.unwrap_or(270.0).to_radians().abs() * radius + } else { + stair.run_length + }; + hypot2(run, rise) +} + fn solid_of(s: &RSlab, base: f64) -> StairSolid { StairSolid { pts: s.outline.iter().map(|p| Vec2 { x: p[0], y: p[1] }).collect(), z_rel: s.z_bottom - base, depth: s.z_top - s.z_bottom } } @@ -125,7 +179,16 @@ pub fn stair_parts(one: &Project, stair: &Stair, base: f64) -> StairParts { let geo = crate::stair::decode_geometry(&crate::stair::geometry(&stair.encode(), rise)); let (riser_height, tread_depth, n_treads) = geo.as_ref().map_or((0.0, 0.0, 0), |g| (g.riser_height, g.tread_depth, g.treads.len())); let geo_landing = geo.as_ref().and_then(|g| g.landing.as_ref()); - let slabs = model3d::emit_stairs(one, false); + let mut slabs = model3d::emit_stairs(one, false); + // Mittelsäule: `slabs_of` hängt sie bei einer Wendel mit Säule als letzte Platte an. + let column = (stair.shape == StairShape::Spiral && stair.center.is_some() && stair.center_column.is_some_and(|r| r.is_finite() && r > 0.0)) + .then(|| slabs.pop()) + .flatten() + .map(|c| { + let s = solid_of(&c, base); + let quantities = column_quantities(&s.pts, s.depth); + Landing { pts: s.pts, z_rel: s.z_rel, depth: s.depth, quantities } + }); let meshes = model3d::emit_stair_meshes(one); let predefined = if stair.shape == StairShape::Spiral { "SPIRAL" } else { "STRAIGHT" }; @@ -190,7 +253,8 @@ pub fn stair_parts(one: &Project, stair: &Stair, base: f64) -> StairParts { riser_height, tread_length: tread_depth, predefined, - quantities: flight_quantities(hypot2(run, lift), volume), + quantities: flight_quantities(if stair.shape == StairShape::Spiral { walk_length(stair, rise) } else { hypot2(run, lift) }, volume), + soffit_area: None, body: FlightBody::Solids(solids), }); } @@ -199,6 +263,7 @@ pub fn stair_parts(one: &Project, stair: &Stair, base: f64) -> StairParts { let (positions, indices) = concat(&meshes); let mesh = ifc_mesh(positions, &indices, base); let volume = mesh_volume(&mesh.positions, &mesh.indices); + let soffit = soffit_area(&mesh.positions, &mesh.indices); flights.push(StairFlightParts { name: if flights.is_empty() { "Lauf".to_string() } else { format!("Lauf {}", flights.len() + 1) }, risers: n_treads as f64, @@ -206,7 +271,8 @@ pub fn stair_parts(one: &Project, stair: &Stair, base: f64) -> StairParts { riser_height, tread_length: tread_depth, predefined, - quantities: flight_quantities(hypot2(stair.run_length, rise), volume), + quantities: flight_quantities(walk_length(stair, rise), volume), + soffit_area: Some(soffit), body: FlightBody::Mesh(mesh), }); } @@ -221,9 +287,9 @@ pub fn stair_parts(one: &Project, stair: &Stair, base: f64) -> StairParts { let rail = (!rail_meshes.is_empty()).then(|| { let (positions, indices) = concat(&rail_meshes); let sides = if one.stair_type(stair).and_then(|t| t.railing) == Some(StairTypeRailing::Beide) { 2.0 } else { 1.0 }; - Rail { mesh: ifc_mesh(positions, &indices, base), quantities: railing_quantities(hypot2(stair.run_length, rise) * sides) } + Rail { mesh: ifc_mesh(positions, &indices, base), quantities: railing_quantities(walk_length(stair, rise) * sides) } }); - StairParts { flights, landing, rail } + StairParts { flights, landing, rail, column } } #[cfg(test)] @@ -295,5 +361,80 @@ mod tests { let rail = parts.rail.expect("Handlauf"); let len = rail.quantities[0].value; assert!((len - 2.0 * hypot2(3.0, 2.6)).abs() < 1e-9); + // Gerade Laufplatte: Untersicht = schräge Platte + flacher Anlauf ≈ Breite × Lauflänge (geneigt) + let soffit = parts.flights.iter().find_map(|f| f.soffit_area).unwrap(); + assert!(soffit > 3.0 && soffit < 1.0 * hypot2(3.0, 2.6) + 0.5, "Untersicht {soffit}"); + } + + fn wendel(type_id: &str, column: Option) -> Stair { + Stair { + id: "W".into(), + floor_id: "eg".into(), + shape: StairShape::Spiral, + start: Vec2 { x: 2.0, y: 0.0 }, + dir: Vec2 { x: 0.0, y: 1.0 }, + center: Some(Vec2 { x: 0.0, y: 0.0 }), + radius: Some(1.5), + sweep: Some(270.0), + width: 1.0, + total_rise: Some(2.8), + step_count: 14.0, + type_id: Some(type_id.into()), + center_column: column, + ..Default::default() + } + } + + fn beton() -> StairType { + StairType { id: "b".into(), structure: StairTypeStructure::Beton, railing: Some(StairTypeRailing::Rechts), default_width: 1.0, ..Default::default() } + } + + #[test] + fn beton_wendel_ein_lauf_als_netz_mit_wendelflaeche() { + let st = wendel("b", Some(0.12)); + let p = project_with(st.clone(), Some(beton())); + let parts = stair_parts(&p, &st, 0.0); + // genau ein Lauf (das Netz) — die Säule ist kein Lauf + assert_eq!(parts.flights.len(), 1, "{:?}", parts.flights.iter().map(|f| &f.name).collect::>()); + let f = &parts.flights[0]; + assert_eq!(f.predefined, "SPIRAL"); + let FlightBody::Mesh(m) = &f.body else { panic!("Wendel aus Ortbeton als Netz") }; + let v = mesh_volume(&m.positions, &m.indices); + let gv = f.quantities.iter().find(|q| q.name == "GrossVolume").unwrap().value; + assert!(v > 1.5 && (gv - v).abs() < 1e-9, "Volumen {v} / {gv}"); + assert_eq!(concrete_flight_amounts(&p).map(|a| a.0), Some(v)); + // Wendelfläche: Ringsektor 270° r 1…2 = 7.07 m² im Grundriss, geneigt etwas grösser + let soffit = f.soffit_area.unwrap(); + let plan = 0.75 * std::f64::consts::PI * (4.0 - 1.0); + assert!(soffit > plan && soffit < 1.3 * plan, "Untersicht {soffit} vs. {plan}"); + // Länge auf der Lauflinie (r 1.5, 270°) mit Steigung + let len = f.quantities.iter().find(|q| q.name == "Length").unwrap().value; + assert!((len - hypot2(1.5 * 1.5 * std::f64::consts::PI, 2.8)).abs() < 1e-9, "{len}"); + // Säule: eigener Teil mit Stützenmengen + let c = parts.column.expect("Spindel"); + assert!((c.depth - 2.8).abs() < 1e-9); + let cv = c.quantities.iter().find(|q| q.name == "NetVolume").unwrap().value; + assert!((cv - std::f64::consts::PI * 0.0144 * 2.8).abs() < 0.01, "{cv}"); + } + + #[test] + fn spindeltreppe_saeule_nicht_im_lauf() { + let ty = StairType { id: "sp".into(), structure: StairTypeStructure::Spindel, tread_thickness: 0.05, default_width: 1.0, ..Default::default() }; + let mit = wendel("sp", Some(0.1)); + let ohne = wendel("sp", None); + let a = stair_parts(&project_with(mit.clone(), Some(ty.clone())), &mit, 0.0); + let b = stair_parts(&project_with(ohne.clone(), Some(ty)), &ohne, 0.0); + let vol = |p: &StairParts| p.flights[0].quantities.iter().find(|q| q.name == "GrossVolume").unwrap().value; + assert!((vol(&a) - vol(&b)).abs() < 1e-9, "Säule nicht im Laufvolumen"); + assert!(a.column.is_some() && b.column.is_none()); + assert!(a.flights[0].soffit_area.is_none()); + } + + #[test] + fn untersicht_eines_wuerfels_ist_seine_bodenflaeche() { + let pos = [0., 0., 0., 1., 0., 0., 1., 1., 0., 0., 1., 0., 0., 0., 1., 1., 0., 1., 1., 1., 1., 0., 1., 1.]; + let idx = [0, 2, 1, 0, 3, 2, 4, 5, 6, 4, 6, 7, 0, 1, 5, 0, 5, 4, 1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 0, 4, 3, 4, 7]; + assert!((soffit_area(&pos, &idx) - 1.0).abs() < 1e-12); + assert_eq!(soffit_area(&pos, &[0, 1, 99]), 0.0); } } diff --git a/src-tauri/core/src/stairs3d.rs b/src-tauri/core/src/stairs3d.rs index f9484cd8..5bc9cd6c 100644 --- a/src-tauri/core/src/stairs3d.rs +++ b/src-tauri/core/src/stairs3d.rs @@ -587,7 +587,7 @@ fn tube_along(path: &[V3], radius: f64) -> Option<(Vec, Vec)> { let bi = cross(tangents[i], normal); for k in 0..TUBE_SEGMENTS { let a = std::f64::consts::TAU * k as f64 / TUBE_SEGMENTS as f64; - let (c, s) = (libm::cos(a) * radius, libm::sin(a) * radius); + let (c, s) = (crate::jsnum::cos(a) * radius, crate::jsnum::sin(a) * radius); for d in 0..3 { positions.push(path[i][d] + normal[d] * c + bi[d] * s); } diff --git a/src-tauri/fileio/src/ifc_export.rs b/src-tauri/fileio/src/ifc_export.rs index 862ecfcb..45a576f0 100644 --- a/src-tauri/fileio/src/ifc_export.rs +++ b/src-tauri/fileio/src/ifc_export.rs @@ -66,11 +66,13 @@ // IfcOpeningElement = Profil-Extrusion entlang z_dir (Position origin/x_dir/z_dir) im Geschoss- // Placement, IfcRelVoidsElement zum Wirt; IfcWindow/IfcDoor mit dem Netz, IfcRelFillsElement. // STAIR = 5, structure, id, predefined (Text), PTS, z_rel, depth (Ersatzkörper, nur ohne Läufe/Podest), -// PSETS, n_flights, FLIGHT × n_flights, has_landing, [LANDING], has_rail, [RAIL] +// PSETS, n_flights, FLIGHT × n_flights, has_landing, [LANDING], has_rail, [RAIL], +// has_column, [COLUMN] // FLIGHT = name, n_risers, n_treads, riser_height, tread_length, predefined (Text, IfcStairFlightTypeEnum), // PSETS, shape (0 = Extrusionen, 1 = Dreiecks-Mesh), 0: n, (PTS, z_rel, depth) × n | 1: MESH // LANDING = name, PTS, z_rel, depth, PSETS (IfcSlab, PredefinedType LANDING) // RAIL = name, predefined (Text, IfcRailingTypeEnum), PSETS, MESH +// COLUMN = name, PTS, z_rel, depth, PSETS (Mittelsäule/Spindel: IfcColumn, COLUMN) // Mit mindestens einem Lauf/Podest/Geländer ist die IfcStair selbst ohne Darstellung und fasst Läufe, // Podest und Geländer per IfcRelAggregates zusammen (nur die Treppe liegt im Geschoss). // EXTRUSION = 6, structure, id, PTS, z_rel, depth @@ -1901,10 +1903,11 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result { } let landing = if r.flag()? { Some(r.stair_landing()?) } else { None }; let rail = if r.flag()? { Some(r.stair_rail()?) } else { None }; + let column = if r.flag()? { Some(r.stair_landing()?) } else { None }; let key = format!("stair/{id}"); let parent = w.placement_of(structure); let g = w.gid(&key); - let entity = if flights.is_empty() && landing.is_none() && rail.is_none() { + let entity = if flights.is_empty() && landing.is_none() && rail.is_none() && column.is_none() { // Ohne Teile: ein Ersatzkörper (Fussabdruck) wie bisher. let (placement, shape) = w.emit_box_product(&pts, z_rel, depth, parent); w.emit_building_element("IFCSTAIR", g, "Treppe", placement, shape, Some(enum_(&predefined))) @@ -1966,6 +1969,16 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result { } parts.push(railing); } + if let Some(c) = &column { + let (placement, shape) = w.emit_box_product(&c.pts, c.z_rel, c.depth, stair_placement); + let ckey = format!("{key}/column"); + let guid = w.gid(&ckey); + let col = w.emit_building_element("IFCCOLUMN", guid, &c.name, placement, shape, Some(enum_("COLUMN"))); + for p in &c.psets { + w.add_pset(p, col, &ckey); + } + parts.push(col); + } let g = w.gid(&format!("aggregates/{key}")); w.add("IFCRELAGGREGATES", format!("{g},#{},$,$,#{stair},{}", w.owner_history, refs(&parts))); stair @@ -2633,7 +2646,7 @@ mod tests { b.pts(&SQUARE); b.n(&[0.0, 2.6]); b.no_psets(); - b.n(&[0.0, 0.0, 0.0]); + b.n(&[0.0, 0.0, 0.0, 0.0]); b.n(&[REC_EXTRUSION, -1.0]); b.str("X1"); b.pts(&SQUARE); @@ -3191,6 +3204,11 @@ mod tests { b.str("HANDRAIL"); b.no_psets(); b.mesh_tetra(); + b.n(&[1.0]); + b.str("Spindel"); + b.pts(&SQUARE); + b.n(&[0.0, 2.6]); + b.qto("Qto_ColumnBaseQuantities", &[("NetVolume", 5.0, 0.1)]); } #[test] @@ -3205,18 +3223,20 @@ mod tests { assert_eq!(count(&ifc, "IFCRAILING"), 1); assert_eq!(count(&ifc, "IFCSLAB"), 1); assert!(ifc.contains(".LANDING.);"), "Podest als IfcSlab(LANDING)"); + assert_eq!(count(&ifc, "IFCCOLUMN"), 1, "Spindel als IfcColumn"); + assert!(first_line(&ifc, "IFCCOLUMN").contains("'Spindel'")); let stair = first_line(&ifc, "IFCSTAIR"); assert!(stair.contains(",$,$,.QUARTER_TURN_STAIR.);") && !stair.contains("#,#"), "{stair}"); let flight = first_line(&ifc, "IFCSTAIRFLIGHT"); assert!(flight.contains(",7,7,0.1857,0.28,.STRAIGHT.);"), "{flight}"); - // Beide Läufe: Menge je Lauf; Treppe, Läufe, Podest, Geländer in EINER Aggregation, nur die Treppe im Geschoss/Gebäude. - assert_eq!(count(&ifc, "IFCELEMENTQUANTITY"), 2); - let agg = ifc.lines().find(|l| l.contains("IFCRELAGGREGATES(") && l.matches('#').count() == 7).expect("Aggregation der Treppe"); + // Beide Läufe + Spindel: Menge je Teil; Treppe, Läufe, Podest, Geländer, Spindel in EINER Aggregation, nur die Treppe im Geschoss/Gebäude. + assert_eq!(count(&ifc, "IFCELEMENTQUANTITY"), 3); + let agg = ifc.lines().find(|l| l.contains("IFCRELAGGREGATES(") && l.matches('#').count() == 8).expect("Aggregation der Treppe"); assert!(agg.contains(",#"), "{agg}"); let contained = first_line(&ifc, "IFCRELCONTAINEDINSPATIALSTRUCTURE"); assert_eq!(contained.matches('#').count(), 4, "nur die Treppe (Nummer, Owner, Treppe, Gebäude): {contained}"); // Läufe als Prismen, Geländer als Dreiecks-Netz. - assert_eq!(count(&ifc, "IFCEXTRUDEDAREASOLID"), 5); // 2 Läufe × 2 Prismen + Podest + assert_eq!(count(&ifc, "IFCEXTRUDEDAREASOLID"), 6); // 2 Läufe × 2 Prismen + Podest + Spindel assert_eq!(count(&ifc, "IFCTRIANGULATEDFACESET"), 1); // Ohne Teile: Ersatzkörper (Fussabdruck) wie vorher. let fallback = build(&b).unwrap(); @@ -3237,7 +3257,7 @@ mod tests { g.no_psets(); g.n(&[1.0]); g.mesh_tetra(); - g.n(&[0.0, 0.0]); + g.n(&[0.0, 0.0, 0.0]); let mesh = build(&g).unwrap(); check_structure(&mesh); assert_eq!(count(&mesh, "IFCSTAIRFLIGHT"), 1);