Files
DOSSIER/src-tauri/core/src/plan/section/openings.rs
T
Claude 6fef64aec9 [271] Umbau in Schnitt, Ansicht, 2D und Möbeln: Abbruch-Stück und Ausfachung auch im Schnitt und in der Ansicht (Bogenwände eingeschlossen), Projektionslinien und Ansichts-Öffnungen in Umbau-Farbe, 2D-Elemente/Möbel/Bäume mit Status
Schnitt und Ansicht rechnen die Ersatzstücke der Öffnungen aus dem Projekt mit allem (die zugemauerte Öffnung fehlt im gefilterten Projekt); Grundriss auch für Bogenwände. Projektionslinien des Schnitts über Output::edge_ids, Öffnungslinien der Ansicht über restyle_with. Drawing2D.renovation (Möbel/Symbole immer, übrige 2D-Elemente nur mit ausdrücklichem Status), Strichfarbe in drawings::emit; Bäume: Tree.status IST der Umbau-Status (tree_renovation), kein zweites Feld. Schnitt entfernt jetzt auch ausgeblendete Bäume/Körper (without_hidden). Beispiel :umbau mit Möbeln, Bäumen und Ansicht West; Bilder doc/review-271/06-09.
2026-11-17 16:57:21 +00:00

501 lines
25 KiB
Rust

//! Geschnittene Fenster und Türen (früher `sectionOpenings.ts`): Rahmen, Flügel, Glas, Sturz und
//! Storenkasten im Querschnitt der Wand (`section_opening_primitives()`). Aufgerufen von der Abfrage
//! `section_plan_buf()` (`query.rs`).
use super::*;
use crate::plan::model_view::{Options, SectionLook};
const OPENING_INK: &str = "#1f242c";
const FRAME_MM: f64 = 0.25;
const GLASS_MM: f64 = crate::plan::style::GLASS_LINE_MM;
const DEFAULT_FRAME_DEPTH: f64 = 0.07;
const DEFAULT_FRAME_WIDTH: f64 = 0.06;
const DOOR_LEAF_THICKNESS: f64 = 0.04;
pub(super) const MIN_CROSS: f64 = 0.15;
pub(super) const LINTEL_FILL: &str = "#d4d7db";
pub(super) const SHADING_PACK_FILL: &str = "#e6e8eb";
fn rect(u0: f64, u1: f64, v0: f64, v1: f64) -> Vec<Vec2> {
vec![v2(min(u0, u1), v0), v2(max(u0, u1), v0), v2(max(u0, u1), v1), v2(min(u0, u1), v1)]
}
fn opening_poly(pts: Vec<Vec2>, profile: bool, id: &str) -> Primitive {
let mut pr = if profile { polygon(pts, "#ffffff", OPENING_INK, FRAME_MM, no_hatch_base()) } else { polygon(pts, "none", "none", 0.0, no_hatch_base()) };
if let Primitive::Polygon { opening_id, .. } = &mut pr {
*opening_id = Some(id.into());
}
pr
}
pub(super) struct CrossSection {
n0: f64,
un: f64,
pub(super) z_bottom: f64,
pub(super) z_top: f64,
pub(super) face_min: f64,
pub(super) face_max: f64,
/// Formöffnung ([G3]): Umriss (Öffnungskoordinaten), Lage der Schnittstelle darin und Brüstungshöhe.
pub(super) shape: Option<(Vec<crate::opening_shape::P>, f64, f64)>,
}
impl CrossSection {
fn u_at(&self, s: f64) -> f64 {
(s - self.n0) / self.un
}
}
pub(super) fn axis_frame(w: &Wall) -> ((f64, f64), (f64, f64)) {
let (dx, dy) = (w.end.x - w.start.x, w.end.y - w.start.y);
let l = hypot2(dx, dy);
let l = if l == 0.0 || l.is_nan() { 1.0 } else { l };
let u = (dx / l, dy / l);
(u, (-u.1, u.0))
}
pub(super) fn cross_section(p: &Project, wall: &Wall, o: &Opening, p0: (f64, f64), u: (f64, f64)) -> Result<Option<CrossSection>, String> {
let Some((from, to)) = opening_interval(wall, o) else { return Ok(None) };
let (a, n) = axis_frame(wall);
let un = u.0 * n.0 + u.1 * n.1;
if un.abs() < MIN_CROSS {
return Ok(None);
}
let rel = (p0.0 - wall.start.x, p0.1 - wall.start.y);
let n0 = rel.0 * n.0 + rel.1 * n.1;
let a0 = rel.0 * a.0 + rel.1 * a.1;
let ua = u.0 * a.0 + u.1 * a.1;
let total = sum_thickness(&p.wall_type_or_fallback(wall).layers);
let ref_off = crate::joins::reference_offset(model3d::wall_reference(wall), total);
let along = a0 + ((ref_off - n0) / un) * ua;
if along < from + 1e-4 || along > to - 1e-4 {
return Ok(None);
}
let (mut z_bottom, mut z_top) = opening_extent(p, wall, o);
// Formöffnung ([G3]): lichte Höhe an der Schnittstelle aus dem Umriss.
let mut shape = None;
if let Some(poly) = crate::opening_shape::opening_outline(o, to - from, z_top - z_bottom) {
let Some((lo, hi)) = crate::opening_shape::v_range(&poly, along - from) else { return Ok(None) };
shape = Some((poly, along - from, z_bottom));
(z_bottom, z_top) = (z_bottom + lo, z_bottom + hi);
}
if z_top - z_bottom < 1e-3 {
return Ok(None);
}
Ok(Some(CrossSection { n0, un, z_bottom, z_top, face_min: ref_off - total / 2.0, face_max: ref_off + total / 2.0, shape }))
}
/// Sash-Liste eines Fenstertyps (`sashesOfWindowType`) für das Fenster-Symbol.
pub(crate) fn sashes_of_window_type(wt: &WindowType) -> Vec<crate::opening_geom::Sash> {
if let Some(s) = wt.sashes.as_deref().filter(|s| !s.is_empty()) {
return s
.iter()
.map(|s| crate::opening_geom::Sash {
post: s.kind == SashDefKind::Pfosten,
auto_width: s.auto_width != Some(false),
width: s.width.unwrap_or(f64::NAN),
post_width: s.post_width.unwrap_or(f64::NAN),
operable: s.opening.is_some_and(|o| o != OpeningKind::Fest),
})
.collect();
}
let wc = if wt.wing_count == 0.0 || wt.wing_count.is_nan() { 1.0 } else { wt.wing_count };
let n = max(1.0, round(wc).min(crate::opening_geom::MAX_WINGS)) as usize;
let operable = wt.kind != OpeningKind::Fest;
(0..n).map(|_| crate::opening_geom::Sash { post: false, auto_width: true, width: f64::NAN, post_width: f64::NAN, operable }).collect()
}
fn window_cut(p: &Project, wall: &Wall, o: &Opening, c: &CrossSection, look: SectionLook, shading_box: bool) -> Result<Vec<Primitive>, String> {
let full = look == SectionLook::Full;
let wt = p.window_type(o);
let fw = max(0.02, wt.and_then(|t| t.frame_width).unwrap_or(DEFAULT_FRAME_WIDTH));
let (_, n) = axis_frame(wall);
let off_of = |q: crate::opening_geom::V| (q.x - wall.start.x) * n.0 + (q.y - wall.start.y) * n.1;
let mut f_min = (c.face_min + c.face_max) / 2.0 - DEFAULT_FRAME_DEPTH / 2.0;
let mut f_max = f_min + DEFAULT_FRAME_DEPTH;
let mut glass: Vec<f64> = vec![(f_min + f_max) / 2.0];
// `windowSymbol(project, wall, o, 1, spec, "mittel")`.
let total = sum_thickness(&p.wall_type_or_fallback(wall).layers);
let ref_off = crate::joins::reference_offset(model3d::wall_reference(wall), total);
let spec = wt.map(|t| crate::opening_geom::WindowSpec {
sashes: sashes_of_window_type(t),
frame_width: t.frame_width.unwrap_or(DEFAULT_FRAME_WIDTH),
frame_depth: t.frame_depth.unwrap_or(f64::NAN),
inset_from_face: t.inset_from_face.or_else(|| crate::opening_detail::default_frame_inset(p, o)).unwrap_or(f64::NAN),
inset_inner: t.inset_face == Some(WindowTypeInsetFace::Innen),
inset_mid: t.inset_face == Some(WindowTypeInsetFace::Mitte),
frame_width_end: f64::NAN,
swing: Vec::new(),
});
// [105] Rahmen-Detail: Lage/Tiefe übersteuert, Breite oben/unten, Anschlussprofile.
let det = crate::opening_detail::frame_of(p, o).filter(|f| f.detailed);
let spec = spec.map(|s| match &det {
Some(f) => crate::opening_geom::WindowSpec {
frame_depth: f.depth,
inset_from_face: f.inset,
inset_inner: f.face == crate::opening_detail::Face::Innen,
inset_mid: f.face == crate::opening_detail::Face::Mitte,
..s
},
None => s,
});
let finite = [wall.start.x, wall.start.y, wall.end.x, wall.end.y, total, ref_off, o.position, o.width].iter().all(|x| x.is_finite());
let sym = if finite {
let wr = crate::opening_geom::WallRef { start: crate::opening_geom::v(wall.start.x, wall.start.y), end: crate::opening_geom::v(wall.end.x, wall.end.y), total, ref_off };
crate::opening_geom::window_symbol(&wr, o.position, o.width, 1.0, spec.as_ref(), o.wing_count.unwrap_or(f64::NAN), crate::opening_geom::Detail::Mittel)
} else {
None
};
if let (Some(sym), true) = (sym, spec.is_some()) {
let mut lo = f64::INFINITY;
let mut hi = f64::NEG_INFINITY;
for q in &sym.frame {
let s = off_of(*q);
lo = min(lo, s);
hi = max(hi, s);
}
f_min = lo;
f_max = hi;
if !sym.glass_lines.is_empty() {
let mut seen: Vec<f64> = Vec::new();
for (q, _) in &sym.glass_lines {
let x = round(off_of(*q) * 1e6) / 1e6;
// `new Set` (SameValueZero: 0 = -0, NaN = NaN).
if !seen.iter().any(|&s| s == x || (s.is_nan() && x.is_nan())) {
seen.push(x);
}
}
glass = seen;
}
}
let u0 = c.u_at(f_min);
let u1 = c.u_at(f_max);
let h = c.z_top - c.z_bottom;
let fwv = min(fw, h / 3.0);
let (sp, sh) = det.as_ref().map_or((0.0, 0.0), |f| (min(f.sill_profile, h / 4.0), min(f.shading_profile, h / 4.0)));
let (fwb, fwt) = det.as_ref().map_or((fwv, fwv), |f| (min(max(0.02, f.sides.bottom), h / 3.0), min(max(0.02, f.sides.top), h / 3.0)));
let mut out = vec![opening_poly(rect(c.u_at(c.face_min), c.u_at(c.face_max), c.z_bottom, c.z_top), false, &o.id)];
// [184] Grob: Leibungen offen (Wandschnitt) und ein Strich in der Rahmenmitte, kein Profil, kein Sturz,
// keine Fensterbank, keine Storen: nur der Strich.
if look == SectionLook::Line {
let u = (u0 + u1) / 2.0;
let mut l = line(v2(u, c.z_bottom), v2(u, c.z_top), "section-window-glass", GLASS_MM, OPENING_INK);
if let Primitive::Line { opening_id, .. } = &mut l {
*opening_id = Some(o.id.clone());
}
out.push(l);
return Ok(out);
}
// [184] Mittel: einfacher Rahmen (Rechteck oben/unten) und eine Glaslinie; Fensterbank als einfache Fläche,
// kein Sturz, kein Kämpfer.
if !full {
out.push(opening_poly(rect(u0, u1, c.z_bottom, c.z_bottom + fwv), true, &o.id));
out.push(opening_poly(rect(u0, u1, c.z_top - fwv, c.z_top), true, &o.id));
let u = (u0 + u1) / 2.0;
let mut l = line(v2(u, c.z_bottom + fwv), v2(u, c.z_top - fwv), "section-window-glass", GLASS_MM, OPENING_INK);
if let Primitive::Line { opening_id, .. } = &mut l {
*opening_id = Some(o.id.clone());
}
out.push(l);
sill_and_shading(&mut out, p, o, c, (f_min, f_max), look, shading_box);
return Ok(out);
}
let (zb0, zt0) = (c.z_bottom + sp, c.z_top - sh);
out.push(opening_poly(rect(u0, u1, zb0, zb0 + fwb), true, &o.id));
out.push(opening_poly(rect(u0, u1, zt0 - fwt, zt0), true, &o.id));
// Fensterbank- und Storen-Anschlussprofil.
if sp > 1e-4 {
out.push(opening_poly(rect(u0, u1, c.z_bottom, zb0), true, &o.id));
}
if sh > 1e-4 {
out.push(opening_poly(rect(u0, u1, zt0, c.z_top), true, &o.id));
}
for s in glass {
let u = c.u_at(s);
let mut l = line(v2(u, zb0 + fwb), v2(u, zt0 - fwt), "section-window-glass", GLASS_MM, OPENING_INK);
if let Primitive::Line { opening_id, .. } = &mut l {
*opening_id = Some(o.id.clone());
}
out.push(l);
}
// [105] Kämpfer (Oberlicht) und waagrechte Sprossen-Riegel geschnitten, in ihrer Breite.
if let Some(t) = wt.filter(|_| !crate::opening_shape::is_shaped(o)) {
let (lo, hi) = (zb0 + fwb, zt0 - fwt);
let tw = det.as_ref().map(|f| f.transom_width).filter(|v| v.is_finite()).unwrap_or(fw);
let mw = det.as_ref().map(|f| f.mullion_width).filter(|v| v.is_finite()).unwrap_or(fw);
let mut bars: Vec<(f64, f64)> = Vec::new();
let mut top = hi;
let tr = t.transom_height.unwrap_or(0.0);
if tr > 1e-4 && c.z_top - tr > lo + tw && c.z_top - tr < hi - tw / 2.0 {
let z = c.z_top - tr;
bars.push((z - tw / 2.0, z + tw / 2.0));
top = z - tw / 2.0;
}
let rows = t.mullion_rows.unwrap_or(1.0).round().clamp(1.0, 20.0) as usize;
for r in 1..rows {
let z = lo + (top - lo) * r as f64 / rows as f64;
bars.push((z - mw / 2.0, z + mw / 2.0));
}
for (z0, z1) in bars {
out.push(opening_poly(rect(u0, u1, z0, z1), true, &o.id));
}
}
if let Some(t) = wt {
// Formöffnung ([G3]): kein Sturz-Querschnitt (Bogen/Schräge statt Sturz).
if !crate::opening_shape::is_shaped(o) {
lintel_cut(&mut out, o, c, t.lintel_height, sturz_box_depth(t, o, shading_box));
}
}
sill_and_shading(&mut out, p, o, c, (f_min, f_max), look, shading_box);
Ok(out)
}
/// Tiefe des Storenkastens im Sturz (ab der Aussenfläche in die Wand), 0 = keiner (Option "Storenkasten" aus,
/// Formöffnung oder Kasten vorgesetzt).
fn sturz_box_depth(t: &WindowType, o: &Opening, shading_box: bool) -> f64 {
let shading = t.shading.as_ref().filter(|s| s.create && shading_box && !crate::opening_shape::is_shaped(o));
shading.filter(|s| s.mount == Some(WindowShadingMount::Sturz)).map_or(0.0, |s| max(0.0, s.r#box.depth))
}
/// Fensterbaenke und Storenkasten im Schnitt. Fensterbaenke nur bei ausdruecklicher Wahl am Typ: fein mit Gefaelle,
/// sonst als einfache Flaeche. Der Storenkasten nur mit der Option "Storenkasten" der Modelldarstellung (Basis aus,
/// wie im Grundriss, [184]).
fn sill_and_shading(out: &mut Vec<Primitive>, p: &Project, o: &Opening, c: &CrossSection, frame: (f64, f64), look: SectionLook, shading_box: bool) {
let (f_min, f_max) = frame;
let Some(t) = p.window_type(o) else { return };
let zb = c.z_bottom;
// Grob: keine Fensterbank (Wandschnitt genuegt).
if look != SectionLook::Line {
if matches!(t.sill_board, Some(WindowTypeSillBoard::Aussen | WindowTypeSillBoard::Beide)) {
// Aussen: bis 4 cm vor die Aussenfläche, fein mit Gefälle.
let out_s = min(f_min, c.face_min) - 0.04;
let pts = if look == SectionLook::Full {
vec![v2(c.u_at(f_min), zb), v2(c.u_at(out_s), zb - 0.015), v2(c.u_at(out_s), zb - 0.045), v2(c.u_at(f_min), zb - 0.03)]
} else {
rect(c.u_at(f_min), c.u_at(out_s), zb - 0.03, zb)
};
out.push(opening_poly(pts, true, &o.id));
}
if matches!(t.sill_board, Some(WindowTypeSillBoard::Innen | WindowTypeSillBoard::Beide)) {
let in_s = max(f_max, c.face_max) + 0.02;
out.push(opening_poly(rect(c.u_at(f_max), c.u_at(in_s), zb - 0.025, zb), true, &o.id));
}
}
let Some(sh) = t.shading.as_ref().filter(|s| s.create && shading_box && !crate::opening_shape::is_shaped(o)) else { return };
let sturz = sh.mount == Some(WindowShadingMount::Sturz);
let h = max(0.0, sh.r#box.height);
let d = max(0.0, sh.r#box.depth);
if h > 1e-4 && d > 1e-4 {
// Im Sturz: ab der Aussenfläche in die Wand; vorgesetzt: vor der Rahmen-Vorderkante.
let (s0, s1) = if sturz { (c.face_min, c.face_min + d) } else { (f_min - d, f_min) };
out.push(opening_poly(rect(c.u_at(s0), c.u_at(s1), c.z_top, c.z_top + h), true, &o.id));
// Lamellen-/Rollpaket im Kasten.
let m = min(0.02, d / 4.0);
let mut pack = polygon(rect(c.u_at(s0 + m), c.u_at(s1 - m), c.z_top + m, c.z_top + h * 0.6), SHADING_PACK_FILL, OPENING_INK, crate::plan::style::SYMBOL_LINE_MM, no_hatch_base());
if let Primitive::Polygon { opening_id, .. } = &mut pack {
*opening_id = Some(o.id.clone());
}
out.push(pack);
}
}
/// Sturz im Schnitt ([94]): eigener Querschnitt über der Öffnung (Beton grau), neben einem
/// Storenkasten im Sturz (`box_depth` ab der Aussenfläche) nur über den Rest der Wanddicke.
fn lintel_cut(out: &mut Vec<Primitive>, o: &Opening, c: &CrossSection, height: Option<f64>, box_depth: f64) {
let h = height.unwrap_or(0.0);
if !(h > 1e-4) {
return;
}
let s0 = min(c.face_max, c.face_min + box_depth);
if c.face_max - s0 <= 1e-4 {
return;
}
let mut pr = polygon(rect(c.u_at(s0), c.u_at(c.face_max), c.z_top, c.z_top + h), LINTEL_FILL, OPENING_INK, FRAME_MM, no_hatch_base());
if let Primitive::Polygon { opening_id, .. } = &mut pr {
*opening_id = Some(o.id.clone());
}
out.push(pr);
}
fn door_cut(p: &Project, o: &Opening, c: &CrossSection, look: SectionLook) -> Vec<Primitive> {
let mut out = vec![opening_poly(rect(c.u_at(c.face_min), c.u_at(c.face_max), c.z_bottom, c.z_top), false, &o.id)];
// [184] Ohne Detail (Modelldarstellung): grob das Blatt als Linie, mittel als Fläche, beide in der Wandmitte
// (Wandöffnung: nur die Lücke).
if look != SectionLook::Full {
let kind = p.door_type(o).map(|t| t.kind);
if o.door_type != Some(OpeningDoorType::Wandoeffnung) && kind != Some(DoorTypeKind::Wandoeffnung) {
let mid = (c.face_min + c.face_max) / 2.0;
if look == SectionLook::Line {
let mut l = line(v2(c.u_at(mid), c.z_bottom), v2(c.u_at(mid), c.z_top), "section-window-glass", GLASS_MM, OPENING_INK);
if let Primitive::Line { opening_id, .. } = &mut l {
*opening_id = Some(o.id.clone());
}
out.push(l);
} else {
out.push(opening_poly(rect(c.u_at(mid - DOOR_LEAF_THICKNESS / 2.0), c.u_at(mid + DOOR_LEAF_THICKNESS / 2.0), c.z_bottom + 0.01, c.z_top), true, &o.id));
}
}
return out;
}
if !crate::opening_shape::is_shaped(o) {
lintel_cut(&mut out, o, c, p.door_type(o).and_then(|t| t.lintel_height), 0.0);
}
let kind = p.door_type(o).map(|t| t.kind);
// [105] Zargen-Arten: Sturz-Profil der Zarge und Blatt im Falz.
if let Some(df) = crate::opening_detail::door_frame_of(p, o).filter(|_| matches!(kind, Some(DoorTypeKind::Dreh | DoorTypeKind::Pendel | DoorTypeKind::Unknown))) {
door_frame_cut(&mut out, o, c, &df);
return out;
}
if o.door_type == Some(OpeningDoorType::Wandoeffnung) || kind == Some(DoorTypeKind::Wandoeffnung) {
return out;
}
let mid = (c.face_min + c.face_max) / 2.0;
let fw = min(DEFAULT_FRAME_WIDTH, (c.z_top - c.z_bottom) / 4.0);
if kind == Some(DoorTypeKind::Schiebe) {
// Schiebetür vor der Wand ([95]): Blatt vor der Fläche auf der Aufschlagseite (linke Normale wie im Grundriss).
let swing = if matches!(o.swing, None | Some(SwingSide::Left)) { 1.0 } else { -1.0 };
let dir = if matches!(o.opening_dir, None | Some(OpeningOpeningDir::In)) { 1.0 } else { -1.0 };
let face = if swing * dir > 0.0 { c.face_max } else { c.face_min };
let s = swing * dir;
out.push(opening_poly(rect(c.u_at(face + s * 0.01), c.u_at(face + s * (0.01 + DOOR_LEAF_THICKNESS)), c.z_bottom + 0.01, c.z_top + 0.03), true, &o.id));
return out;
}
out.push(opening_poly(rect(c.u_at(mid - DEFAULT_FRAME_DEPTH / 2.0), c.u_at(mid + DEFAULT_FRAME_DEPTH / 2.0), c.z_top - fw, c.z_top), true, &o.id));
if kind == Some(DoorTypeKind::Hebeschiebe) {
// Zwei Flügel auf versetzten Gleisen, je mit Glaslinie.
for off in [-0.035, 0.035] {
let (a, b) = (mid + off - 0.02, mid + off + 0.02);
out.push(opening_poly(rect(c.u_at(a), c.u_at(b), c.z_bottom + 0.03, c.z_top - fw), true, &o.id));
let mut l = line(v2(c.u_at(mid + off), c.z_bottom + 0.03 + fw), v2(c.u_at(mid + off), c.z_top - 2.0 * fw), "section-window-glass", GLASS_MM, OPENING_INK);
if let Primitive::Line { opening_id, .. } = &mut l {
*opening_id = Some(o.id.clone());
}
out.push(l);
}
return out;
}
out.push(opening_poly(rect(c.u_at(mid - DOOR_LEAF_THICKNESS / 2.0), c.u_at(mid + DOOR_LEAF_THICKNESS / 2.0), c.z_bottom + 0.01, c.z_top - fw), true, &o.id));
out
}
/// Türzarge im Schnitt ([105]): Profil am Sturz (gleiches Profil wie im Grundriss, `x` nach unten)
/// und Türblatt im Falz der Aufschlagseite.
fn door_frame_cut(out: &mut Vec<Primitive>, o: &Opening, c: &CrossSection, df: &crate::opening_detail::DoorFrame) {
use crate::opening_detail as od;
let total = c.face_max - c.face_min;
let innen = od::aufschlag_innen(o);
let s_of = |d: f64| c.face_min + if innen { total - d } else { d };
let profile = od::door_frame_profile(df, total, innen);
let clear = od::profile_clear_x(&profile);
for (_, poly) in &profile {
let pts: Vec<Vec2> = poly.iter().map(|q| v2(c.u_at(s_of(q[1])), c.z_top - q[0])).collect();
let mut pr = if df.steel { polygon(pts, OPENING_INK, OPENING_INK, FRAME_MM, no_hatch_base()) } else { polygon(pts, "#ffffff", OPENING_INK, FRAME_MM, no_hatch_base()) };
if let Primitive::Polygon { opening_id, .. } = &mut pr {
*opening_id = Some(o.id.clone());
}
out.push(pr);
}
let (d0, d1) = od::leaf_band(df, total, innen);
let top = c.z_top - max(clear - df.falz_width, 0.0);
out.push(opening_poly(rect(c.u_at(s_of(d0)), c.u_at(s_of(d1)), c.z_bottom + 0.01, top), true, &o.id));
}
/// `sectionOpeningPrimitives`.
#[cfg(test)]
pub fn section_opening_primitives(p: &Project, level: &LevelSpec, vis: &Visibility) -> Result<Vec<Primitive>, String> {
let mut o = crate::plan::model_view::resolve(None, crate::plan::style::Detail::Fein, 50.0);
o.window.shading_box = true;
section_opening_primitives_mv(p, level, vis, &o)
}
/// [173]/[184] Geschnittene Öffnungen nach der Modelldarstellung `mv` (Detailgrad wie im Grundriss, Rangfolge Element >
/// Stufe > Basis, EINE Auflösung `Options::section_look`): grob Linie, mittel einfacher Rahmen, fein volles Profil;
/// Storenkasten nach `windows.shadingBox`.
pub fn section_opening_primitives_mv(p: &Project, level: &LevelSpec, vis: &Visibility, mv: &Options) -> Result<Vec<Primitive>, String> {
let Some(plane) = level.plane() else { return Ok(Vec::new()) };
if level.kind != "section" {
return Ok(Vec::new());
}
let u_raw = plane.u_model();
let l = hypot2(u_raw.0, u_raw.1);
let l = if l == 0.0 || l.is_nan() { 1.0 } else { l };
let u = (u_raw.0 / l, u_raw.1 / l);
let p0 = plane.base();
let mut walls_by_id: HashMap<&str, &Wall> = HashMap::new();
for w in &p.walls {
walls_by_id.insert(w.id.as_str(), w);
}
let mut out = Vec::new();
for o in p.openings.as_deref().unwrap_or(&[]) {
if !vis.visible(&o.category_code) || !vis.render(&o.category_code) {
continue;
}
// Dach-/Deckenfenster ([103]): Schnitt durch Rahmen, Glas und Eindeckrahmen.
if let Some(f) = crate::opening_shape::host_frame(p, o) {
let greyed = vis.greyed(&o.category_code);
for (part, corners) in crate::opening_shape::surface_window_boxes(p, o, &f) {
let Some(pts) = crate::opening_shape::box_section(&corners, p0, u) else { continue };
let pr = opening_poly(pts.iter().map(|q| v2(q[0], q[1])).collect(), part != 0, &o.id);
out.push(if greyed { pr.with_greyed(true) } else { pr });
}
continue;
}
let Some(wall) = walls_by_id.get(o.host_wall_id.as_str()).copied() else { continue };
if !vis.visible(&wall.category_code) {
continue;
}
// Bogenwand ([T2], [216]): gerades Einbauteil dort, wo das 3D es hat (Sehne der Einzug-Zone, tangential am Bogen
// an der Schnittstelle oder Sehne zwischen den Laibungen).
let chord = arc_section_opening(p, wall, o, Some((p0, u)));
let (wall, o) = match &chord {
Some((vw, vo)) => (vw, vo),
None => (wall, o),
};
let Some(c) = cross_section(p, wall, o, p0, u)? else { continue };
let prims = if o.kind == ElementKind::Window { window_cut(p, wall, o, &c, mv.section_look(false, o.detail_level), mv.window.shading_box)? } else { door_cut(p, o, &c, mv.section_look(true, o.detail_level)) };
let greyed = vis.greyed(&o.category_code);
for pr in prims {
out.push(if greyed { pr.with_greyed(true) } else { pr });
}
}
Ok(out)
}
/// [271] Umbau im Schnitt: Ersatzstücke von Öffnungen in Bestandswänden (`renovation::Patch`) als Fläche in der Öffnung
/// (Abbruch-Stück gelb gestrichelt, Ausfachung rot), dort, wo die Schnittebene die Öffnung trifft — wie die geschnittene
/// Öffnung selbst ([`cross_section`], Bogenwände über die Sehne). `p` ist das Projekt MIT den im Filter ausgeblendeten
/// Elementen (die geschlossene Öffnung steht sonst nicht darin); Wände in `skip` (Regel „Ausblenden“) und ausgeblendete
/// Klassen entfallen. Ohne gültige Lage nichts (NaN, fehlende Wand/Öffnung).
pub fn section_patch_primitives(p: &Project, level: &LevelSpec, vis: &Visibility, patches: &[crate::renovation::Patch], skip: &HashSet<String>) -> Vec<Primitive> {
let Some(plane) = level.plane() else { return Vec::new() };
if level.kind != "section" || patches.is_empty() {
return Vec::new();
}
let u_raw = plane.u_model();
let l = hypot2(u_raw.0, u_raw.1);
let l = if l == 0.0 || l.is_nan() { 1.0 } else { l };
let u = (u_raw.0 / l, u_raw.1 / l);
let p0 = plane.base();
let mut out = Vec::new();
for pa in patches {
let (Some(o), Some(wall)) = (p.openings.iter().flatten().find(|o| o.id == pa.opening_id), p.walls.iter().find(|w| w.id == pa.wall_id)) else { continue };
if skip.contains(&wall.id) || !vis.visible(&wall.category_code) || !vis.render(&wall.category_code) || !vis.visible(&o.category_code) || !vis.render(&o.category_code) {
continue;
}
let chord = arc_section_opening(p, wall, o, Some((p0, u)));
let (wall, o) = match &chord {
Some((vw, vo)) => (vw, vo),
None => (wall, o),
};
let Ok(Some(c)) = cross_section(p, wall, o, p0, u) else { continue };
let ring = rect(c.u_at(c.face_min), c.u_at(c.face_max), c.z_bottom, c.z_top);
if ring.iter().any(|q| !q.x.is_finite() || !q.y.is_finite()) {
continue;
}
let mut q = crate::renovation::patch_prims(ring, &pa.style, SECTION_VISIBLE_MM, &pa.opening_id);
if vis.greyed(&wall.category_code) {
q = q.into_iter().map(|x| x.with_greyed(true)).collect();
}
out.extend(q);
}
out
}