diff --git a/TODO.md b/TODO.md index 4cf79225..df5d5f2b 100644 --- a/TODO.md +++ b/TODO.md @@ -127,9 +127,14 @@ Wer zu einer ID mehr wissen will (Entscheide, Tests, Bilder), sucht dort nach `* - ◐ **[156]** Bodenbelag-Muster massstabsgerecht. Möbel nur als Blöcke/Körper (geschlossene 2D-Formen der Kategorie „Möbel“ sparen nicht aus); Deckenspiegel-Untersicht unverändert (alte Ausdünnung). Nassraum nach Name ist durch [158] ersetzt. · S -- ◐ **[158]** Raumbuch. Keine IfcCovering-Bauteile (nur Pset-Texte); Wandoberfläche nicht je Wandseite, keine Sockel-/ - Leibungsflächen; lichte Höhe ohne Dachschrägen; Belagsmuster am ersten Umrisspunkt ausgerichtet; Belag im 3D und - im Deckenspiegel nicht nach Raum. · M +- ◐ **[158]** Raumbuch. Stand 11.11.: lichte Höhe unter Dachschrägen (kleinste/mittlere Höhe, Fläche < 1.0 m / 1.0–1.5 m / + ≥ 1.5 m nach SIA 416, Raster über dem Raum mit den Dächern des eigenen Geschosses; `room_book::height_bands`); + Wandoberflächen je Wandseite (`wall_sides`, Raumseite der Wand abzüglich Öffnungen), Leibungsflächen und Sockellänge + (Umfang − Türbreiten) in Zeile und Panel/Bericht; Belagsmuster im Plan an der längsten Raumkante ausgerichtet + (`floor_finish::pattern_frame`; Räume haben keinen eigenen Bezugspunkt). Offen: keine IfcCovering-Bauteile (nur + Pset-Texte); Bogenwände liefern keine Wandseite (Kante läuft unter „ohne Wand“); Wandfläche unter Schrägen rechnet + weiter mit der vollen lichten Höhe; Blatt-Tabelle (`sheet_table.rs`) ohne die neuen Spalten; Belag im 3D und im + Deckenspiegel nicht nach Raum. · M - ◐ **[157]** Plan-Review Musterhaus komplex (Schweizer Praxis). Stand 10.11. (CLI-SVG `--hatch`, Chromium, nur Linux): behoben: Raumstempel verlieren beim Ausweichen keine Zeile mehr (erst frei, dann mit geringster Überdeckung, Zeilen entfallen nur noch, wenn das Rechteck im Raum nirgends passt; `fit_room_stamp`); Schnitt-/Ansichtsbeschriftung („B-B“) diff --git a/src-tauri/core/src/plan/floor_finish.rs b/src-tauri/core/src/plan/floor_finish.rs index 2e979ca1..c2abb058 100644 --- a/src-tauri/core/src/plan/floor_finish.rs +++ b/src-tauri/core/src/plan/floor_finish.rs @@ -104,16 +104,36 @@ pub fn own_finish_rooms<'a>(c: &Ctx<'a>) -> Vec<(&'a Room, &'a Component, Vec

.collect() } -/// [158] Belagsmuster eines Raums: Muster des Materials auf dem Raumumriss (Ursprung erster Punkt, -/// Ausrichtung am Plan), ausgedünnt wie der Deckenbelag; dazu die Strichstärke. +/// [158] Ausrichtung des Belagsmusters: an der längsten Raumkante. Ursprung = Anfang dieser Kante, +/// Drehung = Kantenrichtung auf ±45° gefaltet (achsparallele Räume behalten die Plan-Ausrichtung); +/// entartete Umrisse: erster Punkt, keine Drehung. Räume haben keinen eigenen Bezugspunkt +/// (`stampAnchor` ist nur die Lage des Stempels). +pub fn pattern_frame(ring: &[P]) -> (P, f64) { + let mut best: Option<(f64, P, f64)> = None; + for i in 0..ring.len() { + let (a, b) = (ring[i], ring[(i + 1) % ring.len()]); + let len = (b[0] - a[0]).hypot(b[1] - a[1]); + if len.is_finite() && len > 1e-9 && best.map_or(true, |(l, _, _)| len > l + 1e-9) { + let deg = (b[1] - a[1]).atan2(b[0] - a[0]).to_degrees(); + best = Some((len, a, deg - 90.0 * (deg / 90.0).round())); + } + } + match best { + Some((_, a, deg)) => (a, deg), + None => (ring.first().copied().unwrap_or([0.0, 0.0]), 0.0), + } +} + +/// [158] Belagsmuster eines Raums: Muster des Materials auf dem Raumumriss (nach der längsten +/// Raumkante ausgerichtet, [`pattern_frame`]), ausgedünnt wie der Deckenbelag; dazu die Strichstärke. pub fn room_segments(comp: &Component, ring: &[P], scale: f64) -> Option<(Vec<(P, P)>, f64)> { let pat = comp.surface_pattern.as_ref()?; - let spec = crate::surface_pattern::spec_of(pat, 0.0)?; - let segs = crate::surface_pattern::segments(ring, &spec, *ring.first()?, thinning_scale(scale)); + let (origin, deg) = pattern_frame(ring); + let spec = crate::surface_pattern::spec_of(pat, deg)?; + let segs = crate::surface_pattern::segments(ring, &spec, origin, thinning_scale(scale)); Some((segs, weight(pat.weight_mm))) } -/// Umrisse der Nassräume des Geschosses. pub fn wet_rooms(c: &Ctx) -> Vec> { c.p.rooms.as_deref().unwrap_or(&[]).iter().filter(|r| r.floor_id == c.a.floor && r.boundary.len() >= 3 && is_wet_room(r)).map(|r| r.boundary.iter().map(|v| [v.x, v.y]).collect()).collect() } @@ -207,6 +227,7 @@ pub fn clip_inside_any(segs: &[(P, P)], polys: &[Vec

]) -> Vec<(P, P)> { #[cfg(test)] mod tests { use super::*; + use crate::model::{SurfacePattern, SurfacePatternDirection, SurfacePatternKind}; #[test] fn darstellung_je_massstab_und_einstellung() { @@ -234,4 +255,29 @@ mod tests { let h = convex_hull(vec![[0.0, 0.0], [1.0, 0.0], [0.5, 0.2], [1.0, 1.0], [0.0, 1.0], [0.5, 0.5]]); assert_eq!(h.len(), 4); } + + #[test] + fn muster_an_laengster_raumkante() { + // Achsparalleler Raum: keine Drehung, Ursprung am Anfang der längsten Kante (zweite: 5 m). + let r = [[0.0, 0.0], [2.0, 0.0], [2.0, 5.0], [0.0, 5.0]]; + assert_eq!(pattern_frame(&r), ([2.0, 0.0], 0.0)); + // Um 30° gedrehter Raum 6 × 3: Drehung = 30°, Ursprung = Anfang der Längskante. + let (c, s) = (30f64.to_radians().cos(), 30f64.to_radians().sin()); + let rot = |x: f64, y: f64| [x * c - y * s + 1.0, x * s + y * c + 2.0]; + let ring = [rot(0.0, 0.0), rot(6.0, 0.0), rot(6.0, 3.0), rot(0.0, 3.0)]; + let (o, deg) = pattern_frame(&ring); + assert!((deg - 30.0).abs() < 1e-9 && o == ring[0], "{o:?} {deg}"); + // Längskante rückwärts (180°): auf achsparallel gefaltet. + assert_eq!(pattern_frame(&[[6.0, 0.0], [0.0, 0.0], [0.0, 3.0], [6.0, 3.0]]).1, 0.0); + assert_eq!(pattern_frame(&[]), ([0.0, 0.0], 0.0)); + // Dielen („horizontal") laufen in der gedrehten Stube parallel zur Längskante. + let comp = Component { surface_pattern: Some(SurfacePattern { kind: SurfacePatternKind::Lines, direction: Some(SurfacePatternDirection::Horizontal), spacing: 0.5, ..Default::default() }), ..Default::default() }; + let (segs, _) = room_segments(&comp, &ring, 50.0).unwrap(); + assert!(!segs.is_empty()); + for (a, b) in segs { + let (dx, dy) = (b[0] - a[0], b[1] - a[1]); + let cross = (dx * s - dy * c).abs() / dx.hypot(dy); + assert!(cross < 1e-6, "{cross}"); + } + } } diff --git a/src-tauri/core/src/room_book.rs b/src-tauri/core/src/room_book.rs index 90b333e2..d3586acd 100644 --- a/src-tauri/core/src/room_book.rs +++ b/src-tauri/core/src/room_book.rs @@ -83,16 +83,16 @@ fn in_ceiling(ce: &Ceiling, x: f64, y: f64) -> bool { ce.outline.len() >= 3 && in_ring(x, y, &ce.outline) && !ce.openings.as_deref().unwrap_or(&[]).iter().any(|h| h.len() >= 3 && in_ring(x, y, h)) } -/// Lichte Höhe eines Raums (m): von der Oberkante der Decke unter dem Raum (bis 0.3 m unter bzw. 0.5 m -/// über dem Geschossboden, sonst der Geschossboden) bis zur Unterkante der nächsten Decke darüber -/// (sonst Geschossoberkante). Ohne Geschosshöhe 2.5 m. -pub fn clear_height(p: &Project, r: &Room) -> f64 { +/// Höhenbereich des Raums (Z unten, Z oben): von der Oberkante der Decke unter dem Raum (bis 0.3 m unter +/// bzw. 0.5 m über dem Geschossboden, sonst der Geschossboden) bis zur Unterkante der nächsten Decke +/// darüber (sonst Geschossoberkante). Ohne Geschosshöhe 2.5 m; ohne brauchbare Spanne Geschosshöhe. +pub fn clear_range(p: &Project, r: &Room) -> (f64, f64) { let lvl = level_of(p, &r.floor_id); let base = lvl.and_then(|l| l.base_elevation).filter(|v| v.is_finite()).unwrap_or(0.0); let fh = lvl.and_then(|l| l.floor_height).filter(|h| h.is_finite() && *h > 0.0).unwrap_or(2.5); let ring: Vec<[f64; 2]> = r.boundary.iter().map(|v| [v.x, v.y]).collect(); if ring.len() < 3 { - return fh; + return (base, base + fh); } let [x, y] = crate::room_area::label_point(&ring); let over: Vec<(f64, f64)> = p.ceilings.as_deref().unwrap_or(&[]).iter().filter(|ce| in_ceiling(ce, x, y)).map(|ce| p.ceiling_vertical_extent(ce)).filter(|(a, b)| a.is_finite() && b.is_finite()).collect(); @@ -100,19 +100,117 @@ pub fn clear_height(p: &Project, r: &Room) -> f64 { let floor_z = if floor_z.is_finite() { floor_z } else { base }; let ceil_z = over.iter().map(|e| e.0).filter(|b| *b > floor_z + 1.0).fold(f64::NAN, f64::min); let ceil_z = if ceil_z.is_finite() { ceil_z } else { base + fh }; - let h = ceil_z - floor_z; - if h.is_finite() && h > 0.5 { - h + if ceil_z - floor_z > 0.5 { + (floor_z, ceil_z) } else { - fh + (base, base + fh) } } -/// Fläche der Wand-Öffnungen (Tür, Fenster) am Raum: Öffnungen in Wänden des Geschosses, deren Prüfpunkt -/// neben der Wand (eine Seite) im Raum liegt. -pub fn opening_area(p: &Project, r: &Room) -> f64 { +/// Lichte Höhe eines Raums (m), s. [`clear_range`]: das Mass an der höchsten Stelle (Dachschrägen +/// berücksichtigt [`height_bands`]). +pub fn clear_height(p: &Project, r: &Room) -> f64 { + let (a, b) = clear_range(p, r); + b - a +} + +/// Untergrenze der Höhenbereiche nach SIA 416 (m): unter 1.0 m Raumhöhe zählt die Fläche nicht zur NF, +/// 1.0–1.5 m nur eingeschränkt, ab 1.5 m voll. +pub const BAND_LOW: f64 = 1.0; +pub const BAND_MID: f64 = 1.5; + +/// Lichte Höhe unter Dachschrägen: kleinste und mittlere Höhe sowie die Fläche je Höhenbereich. +#[derive(Debug, Clone, Copy, PartialEq, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct HeightBands { + pub min: f64, + pub mean: f64, + /// Fläche mit lichter Höhe < 1.0 m (m²). + pub area_low: f64, + /// Fläche mit 1.0 m ≤ lichte Höhe < 1.5 m (m²). + pub area_mid: f64, + /// Fläche mit lichter Höhe ≥ 1.5 m (m²). + pub area_full: f64, +} + +/// Dachflächen (Grundriss-Polygone mit Z) und Schichtdicke je Dach des Geschosses; nur Dächer des +/// eigenen Geschosses wirken auf einen Raum (ein Dach darunter ist sein Boden, eines darüber hat Luft). +pub struct RoofPlanes { + floor_id: String, + roofs: Vec<(Vec>, f64)>, +} + +pub fn roof_planes(p: &Project, floor_id: &str) -> RoofPlanes { + let roofs = p + .roofs + .as_deref() + .unwrap_or(&[]) + .iter() + .filter(|r| r.floor_id == floor_id) + .map(|r| (crate::roof::roof_geometry(&r.params(), p.roof_base_elevation(r)).planes, Project::type_thickness(&p.roof_layers(r)))) + .collect(); + RoofPlanes { floor_id: floor_id.to_string(), roofs } +} + +/// Höhenbereiche eines Raums mit den Dachflächen seines Geschosses. Ohne Dach (oder wo keine Dachfläche +/// über dem Raum liegt) gilt die lichte Höhe; sonst zählt je Punkt die Dachunterkante über dem Boden +/// (höchstens die lichte Höhe). Die Flächen kommen aus einem Raster über dem Raum (höchstens ~40 000 +/// Stützstellen) und werden auf die Nettofläche skaliert. +pub fn height_bands(p: &Project, r: &Room, roofs: &RoofPlanes, net_area: f64) -> HeightBands { + use crate::opening_schedule::in_ring; + let (floor_z, ceil_z) = clear_range(p, r); + let top = ceil_z - floor_z; + let band = |h: f64, area: f64| -> (f64, f64, f64) { + if h < BAND_LOW { + (area, 0.0, 0.0) + } else if h < BAND_MID { + (0.0, area, 0.0) + } else { + (0.0, 0.0, area) + } + }; + let flat = |h: f64| { + let (a, b, c) = band(h, net_area); + HeightBands { min: h, mean: h, area_low: a, area_mid: b, area_full: c } + }; + if roofs.floor_id != r.floor_id || roofs.roofs.is_empty() || r.boundary.len() < 3 || r.boundary.iter().any(|v| !v.x.is_finite() || !v.y.is_finite()) { + return flat(top); + } + let (x0, y0, x1, y1) = r.boundary.iter().fold((f64::INFINITY, f64::INFINITY, f64::NEG_INFINITY, f64::NEG_INFINITY), |b, v| (b.0.min(v.x), b.1.min(v.y), b.2.max(v.x), b.3.max(v.y))); + let step = (((x1 - x0) * (y1 - y0)) / 40_000.0).sqrt().max(0.05); + let (nx, ny) = ((((x1 - x0) / step).ceil() as usize).max(1), (((y1 - y0) / step).ceil() as usize).max(1)); + let (mut n, mut sum, mut min) = (0usize, 0.0, f64::INFINITY); + let mut counts = [0usize; 3]; + for j in 0..ny { + for i in 0..nx { + let (x, y) = (x0 + (i as f64 + 0.5) * step, y0 + (j as f64 + 0.5) * step); + if !in_ring(x, y, &r.boundary) { + continue; + } + let mut h = top; + for (planes, thick) in &roofs.roofs { + if let Some(u) = crate::roof::roof_underside_at(planes, *thick, x, y) { + h = h.min((u - floor_z).max(0.0)); + } + } + n += 1; + sum += h; + min = min.min(h); + counts[if h < BAND_LOW { 0 } else if h < BAND_MID { 1 } else { 2 }] += 1; + } + } + if n == 0 { + return flat(top); + } + let k = net_area / n as f64; + HeightBands { min, mean: sum / n as f64, area_low: counts[0] as f64 * k, area_mid: counts[1] as f64 * k, area_full: counts[2] as f64 * k } +} + +/// Wand-Öffnungen (Tür, Fenster) am Raum mit ihrer Wand: Öffnungen in Wänden des Geschosses, deren +/// Prüfpunkt neben der Wand (eine Seite) im Raum liegt. +fn room_openings<'a>(p: &'a Project, r: &Room) -> Vec<(&'a Opening, &'a Wall)> { use crate::opening_schedule::{in_ring, side_points}; - let mut sum = 0.0; + let mut out = Vec::new(); for o in p.openings.as_deref().unwrap_or(&[]) { if crate::opening_shape::is_surface_hosted(o) { continue; @@ -122,11 +220,105 @@ pub fn opening_area(p: &Project, r: &Room) -> f64 { if in_ring(a[0], a[1], &r.boundary) || in_ring(b[0], b[1], &r.boundary) { let area = o.width * o.height; if area.is_finite() && area > 0.0 { - sum += area; + out.push((o, w)); } } } - sum + out +} + +/// Fläche der Wand-Öffnungen (Tür, Fenster) am Raum. +pub fn opening_area(p: &Project, r: &Room) -> f64 { + room_openings(p, r).iter().map(|(o, _)| o.width * o.height).sum() +} + +/// Wandseite am Raum: der Teil einer Wand, an dem der Raumumriss anliegt (Raumseite der Wand). +/// `wall_id` leer = Umrisskante ohne Wand (z. B. Bogenwand oder frei). +#[derive(Debug, Clone, PartialEq, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct WallSide { + pub wall_id: String, + /// Länge der anliegenden Wandseite (m). + pub length: f64, + /// Fläche brutto = Länge × lichte Höhe (m²). + pub gross: f64, + /// Öffnungen in diesem Abschnitt (m²). + pub openings: f64, + /// Fläche netto = brutto − Öffnungen (m²). + pub area: f64, + /// Leibungsflächen der Öffnungen: Laibungsumfang × Wanddicke (m²). + pub reveals: f64, +} + +/// Wandseiten eines Raums: je Wand die Länge der Umrisskanten, die auf ihrer Fläche liegen (Kante +/// parallel zur Wandachse, im Abstand Wanddicke/2 ± 8 cm), mit den Öffnungen des Abschnitts. +pub fn wall_sides(p: &Project, r: &Room, height: f64) -> Vec { + let b = &r.boundary; + let openings = room_openings(p, r); + let mut sides: Vec = Vec::new(); + let mut add = |wall_id: &str, length: f64, ops: &[&(&Opening, &Wall)], thick: f64| { + let open: f64 = ops.iter().map(|(o, _)| o.width * o.height).sum(); + let reveals: f64 = ops.iter().map(|(o, _)| (if o.kind == ElementKind::Door { 2.0 * o.height + o.width } else { 2.0 * (o.height + o.width) }) * thick).sum(); + match sides.iter_mut().find(|s| s.wall_id == wall_id) { + Some(s) => { + s.length += length; + s.openings += open; + s.reveals += reveals; + } + None => sides.push(WallSide { wall_id: wall_id.to_string(), length, gross: 0.0, openings: open, area: 0.0, reveals }), + } + }; + for i in 0..b.len() { + let (a, c) = (&b[i], &b[(i + 1) % b.len()]); + let (ex, ey) = (c.x - a.x, c.y - a.y); + let elen = ex.hypot(ey); + if !(elen > 1e-9) || !elen.is_finite() { + continue; + } + let mut covered: Vec<(f64, f64)> = Vec::new(); + for w in p.walls.iter().filter(|w| w.floor_id == r.floor_id && w.bulge.unwrap_or(0.0).abs() < 1e-9) { + let (wx, wy) = (w.end.x - w.start.x, w.end.y - w.start.y); + let wl = wx.hypot(wy); + if !(wl > 1e-9) { + continue; + } + let (ux, uy) = (wx / wl, wy / wl); + if (ux * ey - uy * ex).abs() / elen > 0.02 { + continue; + } + let thick = p.wall_thickness(w, 0.2); + // Abstand der Kantenmitte zur Achse. + let (mx, my) = ((a.x + c.x) / 2.0 - w.start.x, (a.y + c.y) / 2.0 - w.start.y); + if ((-uy * mx + ux * my).abs() - thick / 2.0).abs() > 0.08 { + continue; + } + // Überlappung der Kante mit der Wand (Achskoordinate ab Wandanfang). + let (s0, s1) = ((a.x - w.start.x) * ux + (a.y - w.start.y) * uy, (c.x - w.start.x) * ux + (c.y - w.start.y) * uy); + let (lo, hi) = (s0.min(s1).max(0.0), s0.max(s1).min(wl)); + if hi - lo < 1e-6 { + continue; + } + let ops: Vec<&(&Opening, &Wall)> = openings.iter().filter(|(o, ow)| ow.id == w.id && o.position + o.width / 2.0 >= lo && o.position + o.width / 2.0 <= hi).collect(); + add(&w.id, hi - lo, &ops, thick); + covered.push((lo, hi)); + } + // Rest der Kante ohne Wand (Überlappungen mehrerer Wände nicht doppelt zählen). + let cov: f64 = covered.iter().map(|(a, b)| b - a).sum::().min(elen); + if elen - cov > 1e-6 { + add("", elen - cov, &[], 0.0); + } + } + for s in &mut sides { + s.gross = s.length * height; + s.area = (s.gross - s.openings).max(0.0); + } + sides +} + +/// Sockellänge: Umfang minus Türbreiten am Raum. +pub fn skirting_length(p: &Project, r: &Room, perimeter: f64) -> f64 { + let doors: f64 = room_openings(p, r).iter().filter(|(o, _)| o.kind == ElementKind::Door).map(|(o, _)| o.width).sum(); + (perimeter - doors).max(0.0) } /// Nassraum: aus der Nutzung, ohne Nutzung nach dem Namen (`plan::floor_finish::is_wet_name`). @@ -149,7 +341,14 @@ pub struct RoomBookRow { /// Nettofläche (m²) = Boden- und Deckenfläche. pub area: f64, pub perimeter: f64, + /// Lichte Höhe an der höchsten Stelle (m). pub clear_height: f64, + /// Kleinste und mittlere lichte Höhe unter Dachschrägen (m), Flächen je SIA-416-Höhenbereich (m²). + pub height_min: f64, + pub height_mean: f64, + pub area_under_1: f64, + pub area_1_to_15: f64, + pub area_over_15: f64, /// Nutzungs-Kennung (`living` …), leer ohne Angabe. pub usage: String, pub wet: bool, @@ -161,6 +360,12 @@ pub struct RoomBookRow { /// Wandfläche netto: Umfang × lichte Höhe − Öffnungen (m²). pub wall_area: f64, pub opening_area: f64, + /// Wandoberflächen je Wandseite (Raumseite), Höhe = lichte Höhe. + pub wall_sides: Vec, + /// Leibungsflächen aller Öffnungen am Raum (m²). + pub reveal_area: f64, + /// Sockellänge: Umfang minus Türbreiten (m). + pub skirting: f64, } /// Menge einer Oberfläche: Fläche je Material/Freitext und Lage. @@ -211,6 +416,7 @@ fn natural_cmp(a: &str, b: &str) -> std::cmp::Ordering { /// Räume ohne Nummer in Dokumentreihenfolge danach); dazu die Mengen je Oberfläche und Material. pub fn room_book(p: &Project) -> RoomBook { let mut rows = Vec::new(); + let mut roofs: Vec = Vec::new(); for r in p.rooms.as_deref().unwrap_or(&[]) { if r.boundary.len() < 3 { continue; @@ -221,6 +427,11 @@ pub fn room_book(p: &Project) -> RoomBook { let perimeter = if ev.perimeter.is_finite() { ev.perimeter } else { 0.0 }; let h = clear_height(p, r); let open = opening_area(p, r); + if !roofs.iter().any(|x| x.floor_id == r.floor_id) { + roofs.push(roof_planes(p, &r.floor_id)); + } + let hb = height_bands(p, r, roofs.iter().find(|x| x.floor_id == r.floor_id).unwrap(), area); + let sides = wall_sides(p, r, h); let number = r.stamp.as_ref().and_then(|s| s.number.as_deref()).map(str::trim).unwrap_or("").to_string(); rows.push(RoomBookRow { id: r.id.clone(), @@ -231,6 +442,11 @@ pub fn room_book(p: &Project) -> RoomBook { area, perimeter, clear_height: h, + height_min: hb.min, + height_mean: hb.mean, + area_under_1: hb.area_low, + area_1_to_15: hb.area_mid, + area_over_15: hb.area_full, usage: r.usage.map(|u| u.key().to_string()).unwrap_or_default(), wet: is_wet(r), floor_finish: finish_label(p, r.floor_finish.as_deref()), @@ -239,6 +455,9 @@ pub fn room_book(p: &Project) -> RoomBook { floor_build_up: r.floor_build_up.as_deref().map(str::trim).unwrap_or("").to_string(), wall_area: (perimeter * h - open).max(0.0), opening_area: open, + reveal_area: sides.iter().map(|s| s.reveals).sum(), + skirting: skirting_length(p, r, perimeter), + wall_sides: sides, }); } let level_index = |id: &str| p.drawing_levels.iter().position(|l| l.id == id).unwrap_or(usize::MAX); @@ -387,6 +606,71 @@ mod tests { assert!(clear_height(&Project::default(), &Room::default()) > 0.0); } + fn roof_project(base: Option) -> Project { + let sq = vec![v(0.0, 0.0), v(4.0, 0.0), v(4.0, 4.0), v(0.0, 4.0)]; + let roof: Roof = serde_json::from_value(serde_json::json!({ "id": "d", "type": "roof", "floorId": "dg", "categoryCode": "50", + "outline": [{"x": 0, "y": 0}, {"x": 4, "y": 0}, {"x": 4, "y": 4}, {"x": 0, "y": 4}], + "shape": "sattel", "pitchDeg": 45.0, "thickness": 0.0, "baseElevation": base })).unwrap(); + Project { + drawing_levels: vec![DrawingLevel { id: "dg".into(), name: "DG".into(), floor_height: Some(3.0), ..Default::default() }], + roofs: Some(vec![roof]), + rooms: Some(vec![Room { id: "k".into(), floor_id: "dg".into(), name: "Studio".into(), boundary: sq, ..Default::default() }]), + ..Default::default() + } + } + + #[test] + fn hoehenbereiche_unter_dachschraege() { + // Traufe auf Bodenhöhe, 45°: Höhe = Abstand zur nächsten Traufe (0..2 m), First 2 m. + let b = room_book(&roof_project(Some(0.0))); + let r = &b.rows[0]; + assert!((r.area - 16.0).abs() < 1e-6); + assert!((r.clear_height - 3.0).abs() < 1e-9, "lichte Höhe bleibt das Geschossmass"); + assert!(r.height_min < 0.1, "{}", r.height_min); + assert!((r.height_mean - 1.0).abs() < 0.05, "{}", r.height_mean); + // < 1.0: je 1 m Streifen an den Traufen (8 m²), 1.0–1.5: 4 m², ≥ 1.5: 4 m². + assert!((r.area_under_1 - 8.0).abs() < 0.3, "{}", r.area_under_1); + assert!((r.area_1_to_15 - 4.0).abs() < 0.3, "{}", r.area_1_to_15); + assert!((r.area_over_15 - 4.0).abs() < 0.3, "{}", r.area_over_15); + assert!((r.area_under_1 + r.area_1_to_15 + r.area_over_15 - r.area).abs() < 1e-6); + } + + #[test] + fn ohne_dachschraege_gilt_die_lichte_hoehe() { + // Traufe auf Geschossoberkante (3.0 m): der Raum steht voll unter dem Dach. + let b = room_book(&roof_project(None)); + let r = &b.rows[0]; + assert!((r.height_min - 3.0).abs() < 0.05 && (r.height_mean - 3.0).abs() < 0.2, "{} {}", r.height_min, r.height_mean); + assert!(r.area_under_1 < 1e-9 && r.area_1_to_15 < 1e-9); + // Eben, ohne Dach: Höhe überall gleich. + let s = room_book(&sample()); + assert!((s.rows[0].height_min - 2.8).abs() < 1e-9 && (s.rows[0].area_over_15 - s.rows[0].area).abs() < 1e-9); + } + + #[test] + fn wandseiten_leibungen_sockel() { + let b = room_book(&sample()); + let w = b.rows.iter().find(|r| r.id == "r1").unwrap(); + let side = |id: &str| w.wall_sides.iter().find(|s| s.wall_id == id).unwrap(); + // Südwand: 2.7 m mit Fenster, Innenwand: 3.7 m mit Tür. + let s = side("s"); + assert!((s.length - 2.7).abs() < 1e-9 && (s.openings - 1.2 * 1.4).abs() < 1e-9); + assert!((s.area - (2.7 * 2.8 - 1.2 * 1.4)).abs() < 1e-9); + assert!((s.reveals - 2.0 * (1.2 + 1.4) * 0.3).abs() < 1e-9, "{}", s.reveals); + let m = side("m"); + assert!((m.length - 3.7).abs() < 1e-9 && (m.openings - 0.9 * 2.1).abs() < 1e-9); + assert!((m.reveals - (2.0 * 2.1 + 0.9) * 0.3).abs() < 1e-9, "{}", m.reveals); + // Kanten ohne Wand (West, Nord) in einem Eintrag; alle Längen zusammen = Umfang. + assert!((side("").length - (3.7 + 2.7)).abs() < 1e-9); + assert!((w.wall_sides.iter().map(|s| s.length).sum::() - w.perimeter).abs() < 1e-9); + assert!((w.wall_sides.iter().map(|s| s.area).sum::() - w.wall_area).abs() < 1e-9); + assert!((w.reveal_area - (s.reveals + m.reveals)).abs() < 1e-9); + // Sockel: Umfang − Türbreite (Fenster zählen nicht). + assert!((w.skirting - (2.0 * (2.7 + 3.7) - 0.9)).abs() < 1e-9); + let bad = b.rows.iter().find(|r| r.id == "r2").unwrap(); + assert!((bad.skirting - (2.0 * (2.7 + 2.0) - 0.9)).abs() < 1e-9); + } + #[test] fn leeres_projekt_und_unsinn() { assert!(room_book(&Project::default()).rows.is_empty()); diff --git a/src/core/extra.ts b/src/core/extra.ts index ba011cea..56c86cb2 100644 --- a/src/core/extra.ts +++ b/src/core/extra.ts @@ -37,8 +37,8 @@ export { revealColumns, revealArea } from "../export/openingSchedule"; export type { RevealArea } from "../export/openingSchedule"; export { elementSchedule, uValueOf, uValueText, buildElementReport } from "../export/elementSchedule"; export type { ElementScheduleRow, UValueResult, ElementKind } from "../export/elementSchedule"; -export { roomBook, buildRoomBookReport, usageLabel, ROOM_USAGES } from "../export/roomBook"; -export type { RoomBook, RoomBookRow, FinishQty } from "../export/roomBook"; +export { roomBook, buildRoomBookReport, usageLabel, hasSlope, ROOM_USAGES } from "../export/roomBook"; +export type { RoomBook, RoomBookRow, FinishQty, WallSide } from "../export/roomBook"; export { sheetTables, createTable, drawTablesPdf, tableCatalog, tableLabels, tableSourceLabel, TABLE_SOURCES } from "../export/sheetTable"; export type { TableOut, TablePrim, TableColumn } from "../export/sheetTable"; export { computeAreaTable, computeIvhb } from "../analysis/areaTable"; diff --git a/src/export/roomBook.test.ts b/src/export/roomBook.test.ts index fe2046c8..28af3125 100644 --- a/src/export/roomBook.test.ts +++ b/src/export/roomBook.test.ts @@ -3,7 +3,7 @@ import { describe, expect, it } from "vitest"; import { sampleProject } from "../model/sampleProject"; import type { Layout, Project, Room } from "../model/types"; import { areaReportToCsv, parseAreaReportCsv } from "./areaReport"; -import { buildRoomBookReport, roomBook, usageLabel } from "./roomBook"; +import { buildRoomBookReport, hasSlope, roomBook, usageLabel } from "./roomBook"; import { sheetTables, tableLabels } from "./sheetTable"; import { t } from "../i18n/translate"; @@ -47,6 +47,22 @@ describe("Raumbuch ([158])", () => { expect(ceil.area).toBeCloseTo(w.area + 4, 9); }); + it("Wandseiten, Leibungen, Sockel und Höhenbereiche ([158])", () => { + const w = roomBook(p).rows[0]!; + expect(w.skirting).toBeGreaterThan(0); + expect(w.skirting).toBeLessThanOrEqual(w.perimeter); + expect(w.wallSides.reduce((a, s) => a + s.length, 0)).toBeCloseTo(w.perimeter, 6); + expect(w.wallSides.reduce((a, s) => a + s.area, 0)).toBeCloseTo(w.wallArea, 6); + expect(w.revealArea).toBeGreaterThanOrEqual(0); + // Ohne Dach: überall die lichte Höhe, alles im obersten Höhenbereich. + expect(w.heightMin).toBeCloseTo(w.clearHeight, 9); + expect(hasSlope(w)).toBe(false); + expect(w.areaUnder1 + w.area1To15 + w.areaOver15).toBeCloseTo(w.area, 6); + const rep = buildRoomBookReport(p); + expect(rep.sections[0]!.columns).toContain(t("roomBook.col.skirting")); + expect(rep.sections[0]!.rows[0]!.cells.length).toBe(rep.sections[0]!.columns.length); + }); + it("Bericht: Raumbuch und Mengen, CSV-Rundreise", () => { const rep = buildRoomBookReport(p); expect(rep.sections.map((s) => s.heading)).toEqual([t("roomBook.title"), t("roomBook.quantities")]); diff --git a/src/export/roomBook.ts b/src/export/roomBook.ts index 5fd2d984..33c7d6fe 100644 --- a/src/export/roomBook.ts +++ b/src/export/roomBook.ts @@ -19,8 +19,15 @@ export interface RoomBookRow { /** Nettofläche (m²) = Boden- und Deckenfläche. */ area: number; perimeter: number; - /** Lichte Höhe (m) aus den Decken, sonst Geschosshöhe. */ + /** Lichte Höhe (m) an der höchsten Stelle: aus den Decken, sonst Geschosshöhe. */ clearHeight: number; + /** Kleinste und mittlere lichte Höhe unter Dachschrägen (m). */ + heightMin: number; + heightMean: number; + /** Fläche (m²) nach SIA-416-Höhenbereichen: < 1.0 m, 1.0–1.5 m, ≥ 1.5 m lichte Höhe. */ + areaUnder1: number; + area1To15: number; + areaOver15: number; /** Nutzungs-Kennung, leer ohne Angabe. */ usage: RoomUsage | ""; wet: boolean; @@ -32,8 +39,27 @@ export interface RoomBookRow { /** Wandfläche netto: Umfang × lichte Höhe − Öffnungen (m²). */ wallArea: number; openingArea: number; + /** Wandoberflächen je Wandseite (Raumseite der Wand), Höhe = lichte Höhe. */ + wallSides: WallSide[]; + /** Leibungsflächen aller Öffnungen am Raum (m²). */ + revealArea: number; + /** Sockellänge: Umfang minus Türbreiten (m). */ + skirting: number; } +/** Wandseite am Raum (`wallId` leer = Umrisskante ohne Wand). */ +export interface WallSide { + wallId: string; + length: number; + gross: number; + openings: number; + area: number; + reveals: number; +} + +/** Hat der Raum Flächen unter 1.5 m lichter Höhe (Dachschräge)? */ +export const hasSlope = (r: RoomBookRow): boolean => r.areaUnder1 + r.area1To15 > 1e-9; + /** Menge einer Oberfläche je Material/Freitext. */ export interface FinishQty { surface: "floor" | "wall" | "ceiling"; @@ -75,11 +101,17 @@ function roomSection(rows: RoomBookRow[]): ReportSection { t("roomBook.col.ceilingFinish"), t("roomBook.col.buildUp"), t("roomBook.col.clearHeight"), + t("roomBook.col.heightMin"), + t("roomBook.col.heightMean"), + t("roomBook.col.areaUnder1"), + t("roomBook.col.area1To15"), t("roomBook.col.wallArea"), + t("roomBook.col.reveals"), + t("roomBook.col.skirting"), ], - widths: [1.2, 1, 2.4, 1.2, 1.6, 2.4, 2.4, 2.4, 3, 1.2, 1.3], + widths: [1.2, 1, 2.4, 1.2, 1.6, 2.4, 2.4, 2.4, 3, 1.2, 1.2, 1.2, 1.2, 1.2, 1.3, 1.2, 1.2], rows: rows.map((r) => ({ - cells: [r.floor, r.number, r.name, num(r.area, 2), usageLabel(r.usage), r.floorFinish, r.wallFinish, r.ceilingFinish, r.floorBuildUp, num(r.clearHeight, 2), num(r.wallArea, 2)], + cells: [r.floor, r.number, r.name, num(r.area, 2), usageLabel(r.usage), r.floorFinish, r.wallFinish, r.ceilingFinish, r.floorBuildUp, num(r.clearHeight, 2), num(r.heightMin, 2), num(r.heightMean, 2), num(r.areaUnder1, 2), num(r.area1To15, 2), num(r.wallArea, 2), num(r.revealArea, 2), num(r.skirting, 2)], })), }; } diff --git a/src/i18n/de.ts b/src/i18n/de.ts index 96f87790..23123172 100644 --- a/src/i18n/de.ts +++ b/src/i18n/de.ts @@ -3297,7 +3297,7 @@ export const de = { "roomBook.title": "Raumbuch", "roomBook.empty": "Keine Räume.", "roomBook.quantities": "Mengen je Oberfläche", - "roomBook.foot": "Bodenfläche = Deckenfläche = Raumfläche (netto). Wandfläche = Umfang × lichte Höhe − Öffnungen; lichte Höhe aus den Decken über und unter dem Raum, sonst Geschosshöhe.", + "roomBook.foot": "Bodenfläche = Deckenfläche = Raumfläche (netto). Wandfläche = Umfang × lichte Höhe − Öffnungen; lichte Höhe aus den Decken über und unter dem Raum, sonst Geschosshöhe. Unter Dachschrägen gelten die Höhenbereiche nach SIA 416 (< 1.0 m, 1.0–1.5 m, ≥ 1.5 m); Wandseiten mit Öffnungen abgezogen, Leibung = Laibungsumfang × Wanddicke, Sockel = Umfang − Türbreiten.", "roomBook.exportCsv": "CSV", "roomBook.exportPdf": "PDF", "roomBook.exportPdf.fail": "PDF des Raumbuchs konnte nicht erstellt werden.", @@ -3309,6 +3309,12 @@ export const de = { "roomBook.col.buildUp": "Bodenaufbau", "roomBook.col.clearHeight": "Lichte Höhe [m]", "roomBook.col.wallArea": "Wandfläche [m²]", + "roomBook.col.heightMin": "Lichte Höhe min [m]", + "roomBook.col.heightMean": "Lichte Höhe Ø [m]", + "roomBook.col.areaUnder1": "Fläche < 1.0 m [m²]", + "roomBook.col.area1To15": "Fläche 1.0–1.5 m [m²]", + "roomBook.col.reveals": "Leibungen [m²]", + "roomBook.col.skirting": "Sockel [m]", "roomBook.col.perimeter": "Umfang [m]", "roomBook.col.wet": "Nassraum", "roomBook.col.surface": "Oberfläche", diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 9db6343b..66938164 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -3284,7 +3284,7 @@ export const en: Record = { "roomBook.title": "Room book", "roomBook.empty": "No rooms.", "roomBook.quantities": "Quantities per finish", - "roomBook.foot": "Floor area = ceiling area = room area (net). Wall area = perimeter × clear height − openings; clear height from the slabs above and below the room, otherwise storey height.", + "roomBook.foot": "Floor area = ceiling area = room area (net). Wall area = perimeter × clear height − openings; clear height from the slabs above and below the room, otherwise storey height. Under sloping roofs the SIA 416 height bands apply (< 1.0 m, 1.0–1.5 m, ≥ 1.5 m); wall sides net of openings, reveal = reveal perimeter × wall thickness, skirting = perimeter − door widths.", "roomBook.exportCsv": "CSV", "roomBook.exportPdf": "PDF", "roomBook.exportPdf.fail": "Could not create the room book PDF.", @@ -3296,6 +3296,12 @@ export const en: Record = { "roomBook.col.buildUp": "Floor build-up", "roomBook.col.clearHeight": "Clear height [m]", "roomBook.col.wallArea": "Wall area [m²]", + "roomBook.col.heightMin": "Clear height min [m]", + "roomBook.col.heightMean": "Clear height avg [m]", + "roomBook.col.areaUnder1": "Area < 1.0 m [m²]", + "roomBook.col.area1To15": "Area 1.0–1.5 m [m²]", + "roomBook.col.reveals": "Reveals [m²]", + "roomBook.col.skirting": "Skirting [m]", "roomBook.col.perimeter": "Perimeter [m]", "roomBook.col.wet": "Wet room", "roomBook.col.surface": "Surface", diff --git a/src/panels/RoomBookSection.tsx b/src/panels/RoomBookSection.tsx index 90d5c77c..b8981daa 100644 --- a/src/panels/RoomBookSection.tsx +++ b/src/panels/RoomBookSection.tsx @@ -5,7 +5,7 @@ import { useMemo } from "react"; import { t } from "../i18n"; -import { areaReportToCsv, buildAreaReportPdf, buildRoomBookReport, roomBook, usageLabel } from "../core"; +import { areaReportToCsv, buildAreaReportPdf, buildRoomBookReport, hasSlope, roomBook, usageLabel } from "../core"; import { downloadCsv } from "./downloadFile"; import { useStore } from "../state/appStore"; @@ -15,6 +15,7 @@ export function RoomBookSection() { const project = useStore((s) => s.project); const notify = useStore((s) => s.notify); const book = useMemo(() => roomBook(project), [project]); + const sloped = book.rows.some(hasSlope); const stem = `${project.name || "projekt"}-raumbuch`; const exportPdf = () => { @@ -56,7 +57,17 @@ export function RoomBookSection() { {t("roomBook.col.wallFinish")} {t("roomBook.col.ceilingFinish")} {t("roomBook.col.clearHeight")} + {sloped && ( + <> + {t("roomBook.col.heightMin")} + {t("roomBook.col.heightMean")} + {t("roomBook.col.areaUnder1")} + {t("roomBook.col.area1To15")} + + )} {t("roomBook.col.wallArea")} + {t("roomBook.col.reveals")} + {t("roomBook.col.skirting")} @@ -71,7 +82,17 @@ export function RoomBookSection() { {r.wallFinish} {r.ceilingFinish} {m2(r.clearHeight)} + {sloped && ( + <> + {m2(r.heightMin)} + {m2(r.heightMean)} + {m2(r.areaUnder1)} + {m2(r.area1To15)} + + )} {m2(r.wallArea)} + {m2(r.revealArea)} + {m2(r.skirting)} ))}