From 5d216b67647747fb319ded58bbafa48541d9e74e Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 29 Oct 2026 10:09:25 +0000 Subject: [PATCH] =?UTF-8?q?[K3c][K3d]=20Grundriss-Unterlage=20unter=20Schn?= =?UTF-8?q?itt/Ansicht=20im=20Kern=20(planUnderlay.ts=20gel=C3=B6scht)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Abfrage planUnderlay liest den Grundriss aus den Plan-Caches, bildet ihn ab, dimmt, entfernt Auswahl-Ids und hängt die Schnittlinie an. Gleichheit gegen TS: 456 Fälle, 142 405 Primitive. --- TODO.md | 7 + src-tauri/core/src/model/generated.rs | 2 +- src-tauri/core/src/plan/mod.rs | 1 + src-tauri/core/src/plan/underlay.rs | 314 +++++++++++++++++++++++++ src-tauri/core/src/queries.rs | 17 ++ src/core/document.ts | 1 + src/core/index.ts | 2 +- src/model/types.generated.ts | 2 +- src/plan/generatePlan.ts | 82 ++++++- src/plan/generatePlan.underlay.test.ts | 38 +++ src/plan/planUnderlay.test.ts | 96 -------- src/plan/planUnderlay.ts | 184 --------------- src/views/viewportContent.tsx | 9 +- 13 files changed, 457 insertions(+), 298 deletions(-) create mode 100644 src-tauri/core/src/plan/underlay.rs delete mode 100644 src/plan/planUnderlay.test.ts delete mode 100644 src/plan/planUnderlay.ts diff --git a/TODO.md b/TODO.md index f88541c5..e0ba37d8 100644 --- a/TODO.md +++ b/TODO.md @@ -162,6 +162,13 @@ truck (`trucksolid`) bleibt eigenes WASM-Modul (Panic-Isolation), wird vom Kern render3d-Verdeckung) nicht neu gebaut. Bleibt in TS: `planUnderlay.ts` (legt den TS-Grundriss unter Schnitt/Ansicht; zieht mit `generatePlan`/`drawing2d.ts` um), das Bauen der truck-Körper (asynchron, eigenes WASM). + ✅ (29.10.) Grundriss-Unterlage im Kern: `plan/underlay.rs`, Abfrage `planUnderlay` (Argumente wie `planDomains` + Ebene + + `minY`) liest den Grundriss aus den Plan-Caches (Haupt-Puffer + Zeichnungs-Stücke), bildet ab (Drehung/Verschiebung, + Schraffurwinkel, Bilder nur ohne Drehung), dimmt, entfernt die Auswahl-Ids und hängt die Schnittlinie an; TS-Fassade + `planUnderlayPrimitives(project, level, floorId, minY, …)` in `generatePlan.ts` (dort auch `crossKindOverlayAllowed`). + `planUnderlay.ts` gelöscht, seine Tests als Rust-Tests. Gleichheit gegen die TS-Fassung (Object.is, inkl. Strip der Ids): + 456 Fälle / 142 405 Primitive (9 Projekte inkl. 2D-Zeichnungen, Schnitt-/Ansichtslinien + schräg/senkrecht/beide + Blickrichtungen, Mono/Detail/Massstab). Nicht in der App angesehen (e2e grün). (Die automatischen Höhenkoten `levelMarkers.ts` rechnet seit 29.10. der Kern, Abfrage `levelMarkers`.) - ◐ **[K3d] Aufräumen:** TS-Primitive-Erzeugung löschen, SVG/PDF/DXF-Export lesen den Puffer. Hängt an [K4]: Rust braucht das typisierte Modell (Bauteil-Typen, Schraffuren, Linienstile, Kategorien) und einen Plan-Puffer v2 mit Pick-IDs + vollem `Primitive`-Umfang diff --git a/src-tauri/core/src/model/generated.rs b/src-tauri/core/src/model/generated.rs index 84dbf2cb..78056656 100644 --- a/src-tauri/core/src/model/generated.rs +++ b/src-tauri/core/src/model/generated.rs @@ -1298,7 +1298,7 @@ pub struct DrawingLevel { pub hidden_lines: Option, /// Grundriss-Unterlage (nur Schnitt/Ansicht): ID eines Geschosses, dessen /// Grundriss AUSGERICHTET unter dem Schnitt/der Ansicht gezeigt wird (Schnitt- - /// linie waagrecht, Blickrichtung nach oben, s. `plan/planUnderlay.ts`). + /// linie waagrecht, Blickrichtung nach oben, s. Kern `plan/underlay.rs`). /// Fehlt ⇒ keine Unterlage. #[serde(rename = "planUnderlayId", default, skip_serializing_if = "Option::is_none")] #[ts(optional)] diff --git a/src-tauri/core/src/plan/mod.rs b/src-tauri/core/src/plan/mod.rs index d338a96a..b374a275 100644 --- a/src-tauri/core/src/plan/mod.rs +++ b/src-tauri/core/src/plan/mod.rs @@ -13,3 +13,4 @@ pub mod section; pub mod elevation; pub mod cache; pub mod extras; +pub mod underlay; diff --git a/src-tauri/core/src/plan/underlay.rs b/src-tauri/core/src/plan/underlay.rs new file mode 100644 index 00000000..98f49ce0 --- /dev/null +++ b/src-tauri/core/src/plan/underlay.rs @@ -0,0 +1,314 @@ +//! Grundriss-Unterlage in Schnitt/Ansicht (früher `src/plan/planUnderlay.ts`): ein Geschoss- +//! Grundriss wird AUSGERICHTET unter die Schnitt-/Ansichtsfläche gelegt — die klassische +//! Konstruktion „Ansicht über dem Grundriss“. Die Schnittlinie wird waagrecht gedreht, die +//! Blickrichtung zeigt im Blatt nach OBEN, und die u-Achse stimmt mit der des Schnitts überein +//! (`Plane::u_model`): ein Punkt im Grundriss liegt senkrecht unter seiner Projektion im Schnitt. +//! +//! Reine Starrkörper-Abbildung (Drehung + Verschiebung, keine Spiegelung) — Kreise bleiben Kreise, +//! Bögen behalten ihren Drehsinn. Die Unterlage ist gedimmt, ohne Auswahl-Ids (fremde Projektion: +//! ein Klick darf nie das echte Bauteil wählen) und trägt die Schnittlinie selbst (strichpunktiert). +//! Rechenreihenfolge wie in der TS-Fassung (bitgleich). + +use super::prim::Primitive; +use crate::jsmath::hypot2; +use crate::jsnum::{atan2, max, min}; +use crate::model::Vec2; + +/// Abstand (Meter) zwischen tiefster Schnitt-/Ansichtskante und Grundriss-Oberkante. +pub const GAP_M: f64 = 1.5; + +/// Abbildung Grundriss (Modell x/y) → Schnitt-Blatt (u, Höhe) (`PlanToSectionMap`). +#[derive(Clone, Copy, Debug)] +pub struct SectionMap { + /// Ursprung = Startpunkt der Schnittlinie. + pub p0: Vec2, + /// Horizontale Schnitt-u-Achse im Grundriss (Blickrichtungs-RECHTS). + pub u: Vec2, + /// Blickrichtung im Grundriss (Einheit). + pub n: Vec2, + /// Drehwinkel (Radiant, CCW). + pub theta: f64, + /// Vertikaler Versatz im Blatt. + pub dy: f64, +} + +/// Abbildung aus der Schnitt-/Ansichtslinie (`planToSectionMap`); `None` ohne (gültige) Linie. +pub fn section_map(line: [Vec2; 2], direction_sign: Option) -> Option { + let [p0, p1] = line; + let len = hypot2(p1.x - p0.x, p1.y - p0.y); + if len < 1e-9 { + return None; + } + let dx = (p1.x - p0.x) / len; + let dy = (p1.y - p0.y) / len; + let sign = direction_sign.unwrap_or(1.0); + // Wie `sectionPlaneFromLevel`: Links-Normale der Linie, per directionSign gedreht. + let n = Vec2 { x: -dy * sign, y: dx * sign }; + // Wie `sectionUAxisModel`: u = (n.y, −n.x). + let u = Vec2 { x: n.y, y: -n.x }; + Some(SectionMap { p0, u, n, theta: atan2(n.x, u.x), dy: 0.0 }) +} + +/// Bildet einen Grundriss-Punkt ins Schnitt-Blatt ab (`mapPlanPoint`). +pub fn map_point(m: &SectionMap, p: Vec2) -> Vec2 { + let rx = p.x - m.p0.x; + let ry = p.y - m.p0.y; + Vec2 { x: rx * m.u.x + ry * m.u.y, y: rx * m.n.x + ry * m.n.y + m.dy } +} + +/// Bildet ein Plan-Primitiv ab (`mapPlanPrimitive`). Achsparallele Rasterbilder lassen sich nicht +/// drehen und entfallen — ausser die Abbildung ist eine reine Verschiebung. +pub fn map_primitive(m: &SectionMap, pr: Primitive) -> Option { + let p = |q: Vec2| map_point(m, q); + Some(match pr { + Primitive::Polygon { pts, mut hatch, fill, stroke, stroke_width_mm, greyed, opacity, no_stroke_edges, wall_id, drawing_id, ceiling_id, opening_id, stair_id, room_id, extruded_solid_id, context_object_id, column_id, roof_id, section_line_id } => { + if hatch.origin.is_some() || m.theta != 0.0 { + // SVG-Musterwinkel dreht im Uhrzeigersinn (Bildschirm) = −Winkel im Modell. + hatch.angle -= (m.theta * 180.0) / std::f64::consts::PI; + hatch.origin = hatch.origin.map(p); + } + Primitive::Polygon { pts: pts.into_iter().map(p).collect(), hatch, fill, stroke, stroke_width_mm, greyed, opacity, no_stroke_edges, wall_id, drawing_id, ceiling_id, opening_id, stair_id, room_id, extruded_solid_id, context_object_id, column_id, roof_id, section_line_id } + } + // `motif` ist im Strich-lokalen Raum definiert — dreht mit der Linie mit. + Primitive::Line { a, b, cls, weight_mm, dash, zigzag, motif, color, drawing_id, opening_id, stair_id, greyed, opacity } => Primitive::Line { a: p(a), b: p(b), cls, weight_mm, dash, zigzag, motif, color, drawing_id, opening_id, stair_id, greyed, opacity }, + Primitive::Arc { center, from, to, r, cls, weight_mm, dash, opening_id, stair_id, greyed, opacity } => Primitive::Arc { center: p(center), from: p(from), to: p(to), r, cls, weight_mm, dash, opening_id, stair_id, greyed, opacity }, + Primitive::Text { at, doc, extra_lines, base_pt, color, room_id, greyed, opacity } => Primitive::Text { at: p(at), doc, extra_lines, base_pt, color, room_id, greyed, opacity }, + Primitive::DrawingText { at, text, height_m, angle, color, marks, wrap_width, doc, drawing_id, greyed, opacity } => Primitive::DrawingText { at: p(at), text, height_m, angle: angle + m.theta, color, marks, wrap_width, doc, drawing_id, greyed, opacity }, + Primitive::DrawingTextPath { path_pts, text, height_m, color, drawing_id, greyed, opacity } => Primitive::DrawingTextPath { path_pts: path_pts.into_iter().map(p).collect(), text, height_m, color, drawing_id, greyed, opacity }, + Primitive::DrawingCircle { center, r, fill, stroke, weight_mm, dash, drawing_id, greyed, opacity } => Primitive::DrawingCircle { center: p(center), r, fill, stroke, weight_mm, dash, drawing_id, greyed, opacity }, + Primitive::DrawingArc { center, r, a0, a1, stroke, weight_mm, dash, drawing_id, greyed, opacity } => Primitive::DrawingArc { center: p(center), r, a0: a0 + m.theta, a1: a1 + m.theta, stroke, weight_mm, dash, drawing_id, greyed, opacity }, + Primitive::DrawingImage { min: lo, max: hi, src, opacity, drawing_id, greyed } => { + if m.theta.abs() > 1e-9 { + return None; + } + let (a, b) = (p(lo), p(hi)); + Primitive::DrawingImage { min: Vec2 { x: min(a.x, b.x), y: min(a.y, b.y) }, max: Vec2 { x: max(a.x, b.x), y: max(a.y, b.y) }, src, opacity, drawing_id, greyed } + } + }) +} + +/// Höchster Stützpunkt eines Primitivs (`primitivePoints`, nur y), für die Höhenlage der Unterlage. +fn max_y(pr: &Primitive, acc: &mut f64) { + let mut see = |y: f64| { + if y > *acc { + *acc = y; + } + }; + match pr { + Primitive::Polygon { pts, .. } => pts.iter().for_each(|q| see(q.y)), + Primitive::Line { a, b, .. } => { + see(a.y); + see(b.y); + } + Primitive::Arc { from, to, center, .. } => { + see(from.y); + see(to.y); + see(center.y); + } + Primitive::Text { at, .. } | Primitive::DrawingText { at, .. } => see(at.y), + Primitive::DrawingTextPath { path_pts, .. } => path_pts.iter().for_each(|q| see(q.y)), + Primitive::DrawingCircle { center, r, .. } | Primitive::DrawingArc { center, r, .. } => see(center.y + r), + Primitive::DrawingImage { min, max, .. } => { + see(min.y); + see(max.y); + } + } +} + +/// Auswahl-Ids entfernen (die Geometrie stammt aus einer fremden Projektion) und dimmen. +fn as_reference(pr: Primitive) -> Primitive { + let mut pr = pr.with_greyed(true); + match &mut pr { + Primitive::Polygon { wall_id, drawing_id, ceiling_id, opening_id, stair_id, room_id, extruded_solid_id, context_object_id, column_id, roof_id, section_line_id, .. } => { + for id in [wall_id, drawing_id, ceiling_id, opening_id, stair_id, room_id, extruded_solid_id, context_object_id, column_id, roof_id, section_line_id] { + *id = None; + } + } + Primitive::Line { drawing_id, opening_id, stair_id, .. } => { + *drawing_id = None; + *opening_id = None; + *stair_id = None; + } + Primitive::Arc { opening_id, stair_id, .. } => { + *opening_id = None; + *stair_id = None; + } + Primitive::Text { room_id, .. } => *room_id = None, + Primitive::DrawingText { drawing_id, .. } + | Primitive::DrawingTextPath { drawing_id, .. } + | Primitive::DrawingImage { drawing_id, .. } + | Primitive::DrawingCircle { drawing_id, .. } + | Primitive::DrawingArc { drawing_id, .. } => *drawing_id = None, + } + pr +} + +/// Legt die Grundriss-Primitive ausgerichtet unter einen Schnitt / eine Ansicht, deren tiefste Kante +/// bei `section_min_y` liegt (`planUnderlayPrimitives`): gedimmt, ohne Auswahl-Ids, dazu die +/// Schnittlinie. Ohne gültige Linie leer. +pub fn underlay_primitives(line: Option<[Vec2; 2]>, direction_sign: Option, plan: impl IntoIterator, section_min_y: f64) -> Vec { + let Some(line) = line else { return vec![] }; + let Some(base) = section_map(line, direction_sign) else { return vec![] }; + let mut mapped = Vec::new(); + let mut top = f64::NEG_INFINITY; + for pr in plan { + let Some(q) = map_primitive(&base, pr) else { continue }; + max_y(&q, &mut top); + mapped.push(q); + } + // Die Schnittlinie (w = 0) liegt immer mit in der Unterlage. + if 0.0 > top { + top = 0.0; + } + let shift = section_min_y - GAP_M - top; + let o = Vec2 { x: 0.0, y: 0.0 }; + let shift_map = SectionMap { p0: o, u: Vec2 { x: 1.0, y: 0.0 }, n: Vec2 { x: 0.0, y: 1.0 }, theta: 0.0, dy: shift }; + let mut out: Vec = mapped.into_iter().filter_map(|q| map_primitive(&shift_map, q)).map(as_reference).collect(); + let [l0, l1] = line; + let len = hypot2(l1.x - l0.x, l1.y - l0.y); + out.push(Primitive::Line { + a: Vec2 { x: 0.0, y: shift }, + b: Vec2 { x: len, y: shift }, + cls: "section-underlay-line".into(), + weight_mm: 0.25, + dash: Some(Some(vec![3.0, 0.8, 0.4, 0.8])), + zigzag: None, + motif: None, + color: Some("#8a3b2c".into()), + drawing_id: None, + opening_id: None, + stair_id: None, + greyed: None, + opacity: None, + }); + out +} + +/// Primitive eines `planDomains`-Ergebnisses in Plan-Reihenfolge: Haupt-Puffer mit den Zeichnungs- +/// Stücken an Stelle ihrer (leeren) Gruppe 7. +pub fn plan_out_primitives(out: &super::domains::PlanOut) -> Result, String> { + use crate::plan_buf::View; + let bad = || "planUnderlay: Plan-Puffer unlesbar".to_string(); + let v = View::parse(&out.main).ok_or_else(bad)?; + let main = v.prims().ok_or_else(bad)?; + let groups = v.groups().ok_or_else(bad)?; + let at = groups.get(7).map_or(main.len(), |g| g.0); + let mut prims = Vec::with_capacity(main.len()); + let mut it = main.into_iter(); + prims.extend(it.by_ref().take(at)); + for (_, bytes) in &out.chunks { + let bytes = bytes.as_ref().ok_or_else(|| "planUnderlay: Zeichnungs-Stück fehlt".to_string())?; + prims.extend(View::parse(bytes).and_then(|c| c.prims()).ok_or_else(bad)?); + } + prims.extend(it); + Ok(prims) +} + +/// Argumente aus dem Abfrage-Text: die `planDomains`-Argumente des Geschosses plus `level` (Schnitt/ +/// Ansicht) und `minY` (tiefste Kante des Schnitts). +pub fn parse_args(text: &str) -> Result<(Option<[Vec2; 2]>, Option, f64), String> { + let v: serde_json::Value = serde_json::from_str(text).map_err(|e| format!("planUnderlay: {e}"))?; + let level = super::section::LevelSpec::from_json(v.get("level").unwrap_or(&serde_json::Value::Null)); + let min_y = v.get("minY").and_then(|x| x.as_f64()).ok_or("planUnderlay: minY fehlt")?; + Ok((level.line, level.direction_sign, min_y)) +} + +/// Plan-Puffer (eine Gruppe) der Unterlage. +pub fn underlay_buf(prims: &[Primitive]) -> Vec { + let mut w = crate::plan_buf::Writer::new(false); + w.group(prims); + w.finish() +} + +#[cfg(test)] +mod tests { + use super::*; + + fn v(x: f64, y: f64) -> Vec2 { + Vec2 { x, y } + } + + fn line(a: Vec2, b: Vec2) -> Primitive { + Primitive::Line { a, b, cls: "t".into(), weight_mm: 0.25, dash: None, zigzag: None, motif: None, color: None, drawing_id: Some("d".into()), opening_id: None, stair_id: None, greyed: None, opacity: None } + } + + /// Abfrage auf dem Dokument (Plan-Caches, Zeichnungs-Stücke) == ohne Cache. + #[test] + fn abfrage_mit_und_ohne_cache_gleich() { + let text = include_str!("../../tests/fixtures/sample_project.json"); + let p: crate::model::Project = serde_json::from_str(text).unwrap(); + let mut d = crate::document::Document::from_json(text).unwrap(); + let sec = p.drawing_levels.iter().find(|l| l.line_points.is_some()).unwrap(); + for floor in p.drawing_levels.iter().filter(|l| l.kind == crate::model::DrawingLevelKind::Floor) { + let show: Vec<&str> = p.layers.iter().map(|l| l.code.as_str()).collect(); + let args = serde_json::json!({ "floor": floor.id, "show": show, "scale": 100, "level": serde_json::to_value(sec).unwrap(), "minY": -0.25 }).to_string(); + let plain = crate::queries::run_bin(&p, "planUnderlay", &[1.0], &args).unwrap(); + for _ in 0..2 { + assert_eq!(crate::queries::run_bin_doc(&mut d, "planUnderlay", &[1.0], &args).unwrap(), plain); + } + let n = crate::plan_buf::View::parse(&plain).unwrap().len(); + assert!(n > 5, "{n}"); + } + } + + #[test] + fn blickrichtung_nach_oben_keine_spiegelung() { + // Linie entlang +x, Blick nach +y: reine Verschiebung. + let m = section_map([v(-1.0, 2.0), v(12.0, 2.0)], Some(1.0)).unwrap(); + assert!(m.theta.abs() < 1e-12); + let q = map_point(&m, v(0.0, 5.0)); + assert!((q.x - 1.0).abs() < 1e-12 && (q.y - 3.0).abs() < 1e-12); + // Umgekehrte Blickrichtung: 180°-Drehung. + let r = section_map([v(-1.0, 2.0), v(12.0, 2.0)], Some(-1.0)).unwrap(); + assert!((r.theta.abs() - std::f64::consts::PI).abs() < 1e-12); + assert!((map_point(&r, v(0.0, 0.0)).y - 2.0).abs() < 1e-12); + assert!(section_map([v(1.0, 1.0), v(1.0, 1.0)], None).is_none()); + } + + #[test] + fn u_wie_schnittebene() { + // Ein Punkt liegt senkrecht unter seiner Projektion im Schnitt (u wie `Plane::u_model`). + for (l, p, sign) in [([v(-1.0, 2.0), v(12.0, 2.0)], v(4.0, 7.0), 1.0), ([v(3.0, 0.0), v(3.0, 9.0)], v(6.0, 2.0), -1.0), ([v(0.0, 0.0), v(5.0, 5.0)], v(1.0, 3.0), 1.0)] { + let m = section_map(l, Some(sign)).unwrap(); + let plane = super::super::section::LevelSpec { line: Some(l), direction_sign: Some(sign), ..Default::default() }.plane().unwrap(); + let (ux, uy) = plane.u_model(); + let (bx, by) = plane.base(); + let len = hypot2(ux, uy); + let expected = ((p.x - bx) * ux + (p.y - by) * uy) / len; + assert!((map_point(&m, p).x - expected).abs() < 1e-9); + } + } + + #[test] + fn unterlage_mit_abstand_gedimmt_ohne_ids_plus_schnittlinie() { + let out = underlay_primitives(Some([v(-1.0, 2.0), v(12.0, 2.0)]), Some(1.0), vec![line(v(0.0, 0.0), v(11.0, 6.0))], -0.3); + let Primitive::Line { a, b, greyed, drawing_id, .. } = &out[0] else { panic!() }; + assert_eq!((*greyed, drawing_id.as_deref()), (Some(true), None)); + // Oberste Grundriss-Kante (y = 6 → w = 4) liegt GAP unter der Schnitt-Unterkante. + let top = a.y.max(b.y); + assert!((top - (-0.3 - GAP_M)).abs() < 1e-9); + assert!((a.x.min(b.x) - 1.0).abs() < 1e-9); + let Primitive::Line { a, b, cls, greyed, dash, .. } = out.last().unwrap() else { panic!() }; + assert_eq!(cls, "section-underlay-line"); + assert_eq!(*greyed, None); + assert_eq!(dash, &Some(Some(vec![3.0, 0.8, 0.4, 0.8]))); + assert!((b.x - a.x - 13.0).abs() < 1e-9 && (a.y - (top - 4.0)).abs() < 1e-9); + assert!(underlay_primitives(None, None, vec![line(v(0.0, 0.0), v(1.0, 1.0))], 0.0).is_empty()); + } + + #[test] + fn gedrehte_linie_dreht_schraffur_und_texte_bilder_entfallen() { + use super::super::prim::HatchRender; + let mut hatch: HatchRender = super::super::style::no_hatch(); + hatch.angle = 10.0; + let poly = Primitive::Polygon { pts: vec![v(0.0, 0.0), v(1.0, 0.0), v(1.0, 1.0)], fill: "#fff".into(), stroke: "#000".into(), stroke_width_mm: 0.2, hatch, greyed: None, opacity: None, no_stroke_edges: None, wall_id: Some("W".into()), drawing_id: None, ceiling_id: None, opening_id: None, stair_id: None, room_id: None, extruded_solid_id: None, context_object_id: None, column_id: None, roof_id: None, section_line_id: None }; + let img = Primitive::DrawingImage { min: v(0.0, 0.0), max: v(1.0, 1.0), src: "x".into(), opacity: 1.0, drawing_id: None, greyed: None }; + // Linie entlang +y → Drehung um 90°. + let out = underlay_primitives(Some([v(0.0, 0.0), v(0.0, 5.0)]), None, vec![poly, img], 0.0); + assert_eq!(out.len(), 2, "Bild entfällt bei Drehung"); + let Primitive::Polygon { hatch, wall_id, greyed, .. } = &out[0] else { panic!() }; + assert_eq!((wall_id, *greyed), (&None, Some(true))); + // Blick nach −x: θ = −90°, das Muster dreht um +90°. + assert!((hatch.angle - 100.0).abs() < 1e-9, "{}", hatch.angle); + } +} diff --git a/src-tauri/core/src/queries.rs b/src-tauri/core/src/queries.rs index 468671cb..3bdff3c4 100644 --- a/src-tauri/core/src/queries.rs +++ b/src-tauri/core/src/queries.rs @@ -153,6 +153,14 @@ pub fn run_bin(p: &Project, name: &str, args: &[f64], text: &str) -> Result { + let a = domains::PlanArgs::parse(args[0], text)?; + let (line, sign, min_y) = crate::plan::underlay::parse_args(text)?; + let bytes = domains::plan_domains_buf(p, &a)?; + let prims = crate::plan_buf::View::parse(&bytes).and_then(|v| v.prims()).ok_or("planUnderlay: Plan-Puffer unlesbar")?; + Ok(crate::plan::underlay::underlay_buf(&crate::plan::underlay::underlay_primitives(line, sign, prims, min_y))) + } ("sectionPlan", _) => crate::plan::section::section_plan_buf(p, args, text), ("elevationPlan", _) => crate::plan::elevation::elevation_plan_buf(p, args, text), _ => Err(format!("Unbekannte Abfrage: {name}")), @@ -172,6 +180,15 @@ pub fn run_bin_doc(d: &mut crate::document::Document, name: &str, args: &[f64], let (p, revs, cache) = d.project_cached().map_err(model_err)?; return crate::plan::domains::plan_domains_cached(p, revs, cache, &a, &have).map(|o| o.encode()); } + if name == "planUnderlay" && args.len() == 1 { + // Der Grundriss kommt aus den Plan-Caches (wie `generatePlan` desselben Geschosses). + let a = crate::plan::domains::PlanArgs::parse(args[0], text)?; + let (line, sign, min_y) = crate::plan::underlay::parse_args(text)?; + let (p, revs, cache) = d.project_cached().map_err(model_err)?; + let out = crate::plan::domains::plan_domains_cached(p, revs, cache, &a, &Default::default())?; + let prims = crate::plan::underlay::plan_out_primitives(&out)?; + return Ok(crate::plan::underlay::underlay_buf(&crate::plan::underlay::underlay_primitives(line, sign, prims, min_y))); + } run_bin(d.project().map_err(model_err)?, name, args, text) } diff --git a/src/core/document.ts b/src/core/document.ts index 166f9b76..9aa2ffb1 100644 --- a/src/core/document.ts +++ b/src/core/document.ts @@ -54,6 +54,7 @@ export type QueryName = | "drawingLines" | "drawingPrims" | "levelMarkers" + | "planUnderlay" | "sectionPlan" | "elevationPlan" | "modelJson"; diff --git a/src/core/index.ts b/src/core/index.ts index 35be770d..747db81e 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -241,7 +241,7 @@ export { export { crossKindOverlayAllowed, planUnderlayPrimitives, -} from "../plan/planUnderlay"; +} from "../plan/generatePlan"; export { type Bounds, diff --git a/src/model/types.generated.ts b/src/model/types.generated.ts index c700bcab..fc493bac 100644 --- a/src/model/types.generated.ts +++ b/src/model/types.generated.ts @@ -917,7 +917,7 @@ export type DrawingLevel = { /** * Grundriss-Unterlage (nur Schnitt/Ansicht): ID eines Geschosses, dessen * Grundriss AUSGERICHTET unter dem Schnitt/der Ansicht gezeigt wird (Schnitt- - * linie waagrecht, Blickrichtung nach oben, s. `plan/planUnderlay.ts`). + * linie waagrecht, Blickrichtung nach oben, s. Kern `plan/underlay.rs`). * Fehlt ⇒ keine Unterlage. */ planUnderlayId?: string; diff --git a/src/plan/generatePlan.ts b/src/plan/generatePlan.ts index dddbeb17..6a433a8f 100644 --- a/src/plan/generatePlan.ts +++ b/src/plan/generatePlan.ts @@ -20,6 +20,8 @@ import type { ContextImage, ContextObject, Drawing2D, + DrawingLevel, + DrawingLevelKind, Project, Vec2, } from "../model/types"; @@ -446,6 +448,74 @@ const MAX_CHUNK_STORES = 16; const DETAIL_CODE: Record = { grob: 0, mittel: 1, fein: 2 }; +/** Argumente der Kern-Abfrage `planDomains` (auch `planUnderlay`). */ +function planDomainsArgs( + floorId: string, + visibleCodes: Set, + categoryDisplay: CategoryDisplayResolver, + referenceLines: boolean, + global: boolean, + scale: number, + forPrint: boolean, + compact: boolean, + mono: boolean, + sunWhen: number, +): Record { + // Sichtbar und gezeichnet bzw. gedimmt: über die sichtbaren Codes (wenige), nicht über alle + // Elemente — der Kern zeichnet ein Element genau dann, wenn sein Code in `show` steht. + const show: string[] = []; + const grey: string[] = []; + for (const c of visibleCodes) { + const d = categoryDisplay(c); + if (!d.render) continue; + show.push(c); + if (d.greyed) grey.push(c); + } + return { floor: floorId, show, grey, referenceLines, global, scale, forPrint, compact, mono, sunWhen: Number.isNaN(sunWhen) ? null : sunWhen }; +} + +/** + * Grundriss-Unterlage in Schnitt/Ansicht aus dem Kern (`plan/underlay.rs`, früher `planUnderlay.ts`): + * der Grundriss des Geschosses `floorId` (wie `generatePlan` ohne projektglobale Zutaten, aus den + * Plan-Caches) AUSGERICHTET unter die Schnitt-/Ansichtsfläche gelegt, deren tiefste Kante bei + * `sectionMinY` liegt — Schnittlinie waagrecht, Blickrichtung im Blatt nach oben, u-Achse wie im + * Schnitt. Gedimmt, ohne Auswahl-Ids (fremde Projektion), plus die Schnittlinie (strichpunktiert). + */ +export function planUnderlayPrimitives( + project: Project, + level: DrawingLevel, + floorId: string, + sectionMinY: number, + visibleCodes: Set, + categoryDisplay: CategoryDisplayResolver = SHOW_ALL, + detail: DetailLevel = "mittel", + showReferenceLines = false, + mono = false, + scaleDenominator: number = DEFAULT_SCALE_DENOMINATOR, +): Primitive[] { + const args = planDomainsArgs(floorId, visibleCodes, categoryDisplay, showReferenceLines, false, scaleDenominator, false, false, mono, NaN); + const text = JSON.stringify({ ...args, level: { kind: level.kind, linePoints: level.linePoints, directionSign: level.directionSign }, minY: sectionMinY }); + return decodePlanBuf(documentFor(project).queryBin("planUnderlay", [DETAIL_CODE[detail] ?? 1], text)).prims; +} + +/** + * Welche Fremd-Art-Ebene darf als Unterlage in welcher aktiven Ebene erscheinen? + * Massgebend ist der Koordinatenraum: Geschoss und freie Zeichnung teilen X/Y, + * Schnitte/Ansichten messen dagegen Länge×Höhe entlang IHRER Linie. Ein Schnitt + * im Grundriss (oder ein Grundriss/eine andere Ansicht im Schnitt) lag darum + * nur zufällig irgendwo und überdeckte den eigentlichen Plan (Nutzer-Report + * 2026-10-20: Fenster der Ansicht im EG-Grundriss, Raumstempel im Schnitt). + * • freie Zeichnung: alles (Kalkierpapier zum Abzeichnen, Nutzer-Wunsch). + * • Geschoss: nur freie Zeichnungen (gleicher X/Y-Raum). + * • Schnitt/Ansicht: nichts — ein Grundriss kommt dort ausgerichtet über + * `DrawingLevel.planUnderlayId` dazu (s. {@link planUnderlayPrimitives}). + */ +export function crossKindOverlayAllowed(active: DrawingLevelKind, other: DrawingLevelKind): boolean { + if (active === "drawing") return true; + if (active === "floor") return other === "drawing"; + return false; +} + /** * Der Grundriss eines Geschosses aus dem Kern: Decken, Dächer, Räume, Wände mit Öffnungen, Treppen, * Stützen, 2D-Zeichnungen, Extrusions-Umrisse und (mit `global`) Schatten, Baurecht, Kontext-Konturen @@ -468,17 +538,7 @@ function planDomains( /** Zeitpunkt der Schattenstudie (Unix-ms, NaN = keiner). */ sunWhen: number, ): DomainPrims { - // Sichtbar und gezeichnet bzw. gedimmt: über die sichtbaren Codes (wenige), nicht über alle - // Elemente — der Kern zeichnet ein Element genau dann, wenn sein Code in `show` steht. - const show: string[] = []; - const grey: string[] = []; - for (const c of visibleCodes) { - const d = categoryDisplay(c); - if (!d.render) continue; - show.push(c); - if (d.greyed) grey.push(c); - } - const args = JSON.stringify({ floor: floorId, show, grey, referenceLines, global, scale, forPrint, compact, mono, sunWhen: Number.isNaN(sunWhen) ? null : sunWhen }); + const args = JSON.stringify(planDomainsArgs(floorId, visibleCodes, categoryDisplay, referenceLines, global, scale, forPrint, compact, mono, sunWhen)); const held = chunkStores.get(args); const query = held && held.size ? `${args.slice(0, -1)},"have":[${[...held.keys()].join(",")}]}` : args; const res = readPlanMulti(documentFor(project).queryBin("planDomains", [DETAIL_CODE[detail] ?? 1], query), held); diff --git a/src/plan/generatePlan.underlay.test.ts b/src/plan/generatePlan.underlay.test.ts index 7a422abd..4e1f4e6d 100644 --- a/src/plan/generatePlan.underlay.test.ts +++ b/src/plan/generatePlan.underlay.test.ts @@ -165,3 +165,41 @@ describe("Ebenen ein-/ausblenden (Kataster-Performance)", () => { expect(lineHash(generatePlan(recolored, "L1", vis(["60"])))).not.toBe(first); }); }); + +// Grundriss-Unterlage unter Schnitt/Ansicht (Kern `plan/underlay.rs`; Rechnung dort getestet). +import { crossKindOverlayAllowed, planUnderlayPrimitives } from "./generatePlan"; +import { sampleProject } from "../model/sampleProject"; + +describe("planUnderlayPrimitives (Kern)", () => { + it("Grundriss gedimmt, ohne Auswahl-Ids, unter dem Schnitt, plus Schnittlinie", () => { + const sec = sampleProject.drawingLevels.find((l) => l.kind === "section")!; + const eg = sampleProject.drawingLevels.find((l) => l.kind === "floor")!; + const codes = new Set(sampleProject.layers.map((l) => l.code)); + const out = planUnderlayPrimitives(sampleProject, sec, eg.id, -0.3, codes); + expect(out.length).toBeGreaterThan(10); + const last = out[out.length - 1]; + expect(last.kind === "line" && last.cls).toBe("section-underlay-line"); + const body = out.slice(0, -1); + expect(body.every((p) => (p as { greyed?: boolean }).greyed === true)).toBe(true); + expect(body.some((p) => "wallId" in p || "roomId" in p || "drawingId" in p)).toBe(false); + let top = -Infinity; + for (const p of body) if (p.kind === "polygon") for (const q of p.pts) top = Math.max(top, q.y); + expect(top).toBeLessThanOrEqual(-0.3 - 1.5 + 1e-9); + // ohne Schnittlinie: nichts + expect(planUnderlayPrimitives(sampleProject, { ...sec, linePoints: undefined }, eg.id, 0, codes)).toEqual([]); + }); +}); + +describe("crossKindOverlayAllowed", () => { + it("nur Ebenen im selben Koordinatenraum überlagern sich", () => { + expect(crossKindOverlayAllowed("floor", "drawing")).toBe(true); + expect(crossKindOverlayAllowed("floor", "section")).toBe(false); + expect(crossKindOverlayAllowed("floor", "elevation")).toBe(false); + expect(crossKindOverlayAllowed("section", "floor")).toBe(false); + expect(crossKindOverlayAllowed("elevation", "section")).toBe(false); + expect(crossKindOverlayAllowed("section", "drawing")).toBe(false); + // Freie Zeichnung bleibt Kalkierpapier für alles. + expect(crossKindOverlayAllowed("drawing", "section")).toBe(true); + expect(crossKindOverlayAllowed("drawing", "floor")).toBe(true); + }); +}); diff --git a/src/plan/planUnderlay.test.ts b/src/plan/planUnderlay.test.ts deleted file mode 100644 index a7720515..00000000 --- a/src/plan/planUnderlay.test.ts +++ /dev/null @@ -1,96 +0,0 @@ -import { describe, expect, it } from "vitest"; -import type { DrawingLevel } from "../model/types"; -import type { Primitive } from "./generatePlan"; -import { - PLAN_UNDERLAY_GAP_M, - crossKindOverlayAllowed, - mapPlanPoint, - planToSectionMap, - planUnderlayPrimitives, -} from "./planUnderlay"; -import { sectionPlaneFromLevel, sectionUAxisModel } from "./toSection"; - -const level = (p0: { x: number; y: number }, p1: { x: number; y: number }, sign: 1 | -1 = 1): DrawingLevel => ({ - id: "s", - name: "S", - kind: "section", - visible: true, - locked: false, - linePoints: [p0, p1], - directionSign: sign, -}); - -const line = (a: { x: number; y: number }, b: { x: number; y: number }): Primitive => ({ - kind: "line", - a, - b, - cls: "t", - weightMm: 0.25, -}); - -describe("planToSectionMap", () => { - it("u stimmt mit der Schnitt-u-Achse überein (Punkt liegt senkrecht unter seiner Projektion)", () => { - for (const [lv, p] of [ - [level({ x: -1, y: 2 }, { x: 12, y: 2 }), { x: 4, y: 7 }], - [level({ x: 3, y: 0 }, { x: 3, y: 9 }, -1), { x: 6, y: 2 }], - [level({ x: 0, y: 0 }, { x: 5, y: 5 }), { x: 1, y: 3 }], - ] as const) { - const m = planToSectionMap(lv)!; - const plane = sectionPlaneFromLevel(lv)!; - const uAx = sectionUAxisModel(plane); - const len = Math.hypot(uAx.x, uAx.y); - const uExpected = ((p.x - plane.point[0]) * uAx.x + (p.y - plane.point[2]) * uAx.y) / len; - expect(mapPlanPoint(m, p).x).toBeCloseTo(uExpected, 9); - } - }); - - it("Blickrichtung zeigt im Blatt nach oben, keine Spiegelung", () => { - // Linie entlang +x, Blick nach +y (Norden): reine Verschiebung. - const m = planToSectionMap(level({ x: -1, y: 2 }, { x: 12, y: 2 }))!; - expect(m.theta).toBeCloseTo(0, 12); - const q = mapPlanPoint(m, { x: 0, y: 5 }); - expect(q.x).toBeCloseTo(1, 12); - expect(q.y).toBeCloseTo(3, 12); // 3 m hinter der Linie → 3 m nach oben - // Umgekehrte Blickrichtung: 180°-Drehung (Determinante +1). - const r = planToSectionMap(level({ x: -1, y: 2 }, { x: 12, y: 2 }, -1))!; - expect(Math.abs(r.theta)).toBeCloseTo(Math.PI, 12); - expect(mapPlanPoint(r, { x: 0, y: 0 }).y).toBeCloseTo(2, 12); - }); - - it("ohne Linie keine Abbildung", () => { - expect(planToSectionMap({ ...level({ x: 0, y: 0 }, { x: 1, y: 0 }), linePoints: undefined })).toBeNull(); - }); -}); - -describe("planUnderlayPrimitives", () => { - it("legt den Grundriss mit Abstand unter den Schnitt, gedimmt, plus Schnittlinie", () => { - const lv = level({ x: -1, y: 2 }, { x: 12, y: 2 }); - const out = planUnderlayPrimitives(lv, [line({ x: 0, y: 0 }, { x: 11, y: 6 })], -0.3); - const mapped = out[0] as Extract; - expect(mapped.greyed).toBe(true); - // Oberste Grundriss-Kante (y = 6 → w = 4) liegt GAP unter der Schnitt-Unterkante. - const top = Math.max(mapped.a.y, mapped.b.y); - expect(top).toBeCloseTo(-0.3 - PLAN_UNDERLAY_GAP_M, 9); - // u bleibt erhalten (x − (−1)). - expect(Math.min(mapped.a.x, mapped.b.x)).toBeCloseTo(1, 9); - const cut = out[out.length - 1] as Extract; - expect(cut.cls).toBe("section-underlay-line"); - expect(cut.b.x - cut.a.x).toBeCloseTo(13, 9); - // Schnittlinie liegt 4 m unter der obersten Grundriss-Kante (w = 0). - expect(cut.a.y).toBeCloseTo(top - 4, 9); - }); -}); - -describe("crossKindOverlayAllowed", () => { - it("nur Ebenen im selben Koordinatenraum überlagern sich", () => { - expect(crossKindOverlayAllowed("floor", "drawing")).toBe(true); - expect(crossKindOverlayAllowed("floor", "section")).toBe(false); - expect(crossKindOverlayAllowed("floor", "elevation")).toBe(false); - expect(crossKindOverlayAllowed("section", "floor")).toBe(false); - expect(crossKindOverlayAllowed("elevation", "section")).toBe(false); - expect(crossKindOverlayAllowed("section", "drawing")).toBe(false); - // Freie Zeichnung bleibt Kalkierpapier für alles. - expect(crossKindOverlayAllowed("drawing", "section")).toBe(true); - expect(crossKindOverlayAllowed("drawing", "floor")).toBe(true); - }); -}); diff --git a/src/plan/planUnderlay.ts b/src/plan/planUnderlay.ts deleted file mode 100644 index 8f40bc2d..00000000 --- a/src/plan/planUnderlay.ts +++ /dev/null @@ -1,184 +0,0 @@ -// Grundriss-Unterlage in Schnitt/Ansicht: ein Geschoss-Grundriss wird -// AUSGERICHTET unter die Schnitt-/Ansichtsfläche gelegt — wie die klassische -// Konstruktion "Ansicht über dem Grundriss". Die Schnittlinie wird dazu -// waagrecht gedreht, die Blickrichtung zeigt im Blatt nach OBEN (Betrachter -// steht unten, die gesehene Fassade liegt an der Unterkante des Grundrisses), -// und die u-Achse stimmt exakt mit der des Schnitts/der Ansicht überein -// (`sectionUAxisModel`, im Kern `Plane::u_model` bzw. der Ansichts-Rahmen): ein Punkt im Grundriss liegt also -// senkrecht unter seiner Projektion im Schnitt. -// -// Reine Starrkörper-Abbildung (Drehung + Verschiebung, keine Spiegelung) — -// Kreise bleiben Kreise, Bögen behalten ihren Drehsinn. - -import type { DrawingLevel, DrawingLevelKind, Vec2 } from "../model/types"; -import type { Primitive } from "./generatePlan"; - -/** Abstand (Meter) zwischen tiefster Schnitt-/Ansichtskante und Grundriss-Oberkante. */ -export const PLAN_UNDERLAY_GAP_M = 1.5; - -/** Abbildung Grundriss (Modell x/y) → Schnitt-Blatt (u, Höhe). */ -export interface PlanToSectionMap { - /** Ursprung = Startpunkt der Schnittlinie. */ - p0: Vec2; - /** Horizontale Schnitt-u-Achse im Grundriss (Blickrichtungs-RECHTS). */ - u: Vec2; - /** Blickrichtung im Grundriss (Einheit). */ - n: Vec2; - /** Drehwinkel (Radiant, CCW) der Abbildung. */ - theta: number; - /** Vertikaler Versatz im Blatt. */ - dy: number; -} - -/** - * Baut die Abbildung aus der Schnitt-/Ansichtslinie einer Ebene (`null` ohne - * Linie). `dy` bleibt 0 — der Aufrufer schiebt den Grundriss danach unter den - * Schnitt (s. {@link planUnderlayPrimitives}). - */ -export function planToSectionMap(level: DrawingLevel): PlanToSectionMap | null { - const line = level.linePoints; - if (!line) return null; - const [p0, p1] = line; - const len = Math.hypot(p1.x - p0.x, p1.y - p0.y); - if (len < 1e-9) return null; - const dx = (p1.x - p0.x) / len; - const dy = (p1.y - p0.y) / len; - const sign = level.directionSign ?? 1; - // Wie `sectionPlaneFromLevel`: Links-Normale der Linie, per directionSign gedreht. - const n: Vec2 = { x: -dy * sign, y: dx * sign }; - // Wie `sectionUAxisModel`: u = (n.y, −n.x) — Blickrichtungs-RECHTS. - const u: Vec2 = { x: n.y, y: -n.x }; - // Bild der x-Achse (1,0) ist (u.x, n.x) → cosθ = u.x, sinθ = n.x. - return { p0, u, n, theta: Math.atan2(n.x, u.x), dy: 0 }; -} - -/** Bildet einen Grundriss-Punkt ins Schnitt-Blatt ab. */ -export function mapPlanPoint(m: PlanToSectionMap, p: Vec2): Vec2 { - const rx = p.x - m.p0.x; - const ry = p.y - m.p0.y; - return { x: rx * m.u.x + ry * m.u.y, y: rx * m.n.x + ry * m.n.y + m.dy }; -} - -/** - * Bildet ein Plan-Primitiv ab. Achsparallele Rasterbilder lassen sich nicht - * drehen und entfallen (`null`) — ausser die Abbildung ist eine reine - * Verschiebung. - */ -export function mapPlanPrimitive(m: PlanToSectionMap, pr: Primitive): Primitive | null { - const P = (p: Vec2) => mapPlanPoint(m, p); - switch (pr.kind) { - case "polygon": { - const hatch = pr.hatch.origin || m.theta !== 0 - ? { - ...pr.hatch, - // SVG-Musterwinkel dreht im Uhrzeigersinn (Bildschirm) = −Winkel im Modell. - angle: pr.hatch.angle - (m.theta * 180) / Math.PI, - origin: pr.hatch.origin ? P(pr.hatch.origin) : undefined, - } - : pr.hatch; - return { ...pr, pts: pr.pts.map(P), hatch }; - } - case "line": - // `motif` ist im Strich-lokalen Raum definiert — dreht mit der Linie mit. - return { ...pr, a: P(pr.a), b: P(pr.b) }; - case "arc": - return { ...pr, center: P(pr.center), from: P(pr.from), to: P(pr.to) }; - case "text": - return { ...pr, at: P(pr.at) }; - case "drawingText": - return { ...pr, at: P(pr.at), angle: pr.angle + m.theta }; - case "drawingTextPath": - return { ...pr, pathPts: pr.pathPts.map(P) }; - case "drawingCircle": - return { ...pr, center: P(pr.center) }; - case "drawingArc": - return { ...pr, center: P(pr.center), a0: pr.a0 + m.theta, a1: pr.a1 + m.theta }; - case "drawingImage": { - if (Math.abs(m.theta) > 1e-9) return null; - const a = P(pr.min); - const b = P(pr.max); - return { - ...pr, - min: { x: Math.min(a.x, b.x), y: Math.min(a.y, b.y) }, - max: { x: Math.max(a.x, b.x), y: Math.max(a.y, b.y) }, - }; - } - } -} - -/** Alle Stützpunkte eines Primitivs (für die Höhenlage der Unterlage). */ -function primitivePoints(pr: Primitive): Vec2[] { - switch (pr.kind) { - case "polygon": return pr.pts; - case "line": return [pr.a, pr.b]; - case "arc": return [pr.from, pr.to, pr.center]; - case "text": - case "drawingText": return [pr.at]; - case "drawingTextPath": return pr.pathPts; - case "drawingCircle": - case "drawingArc": - return [{ x: pr.center.x, y: pr.center.y + pr.r }]; - case "drawingImage": return [pr.min, pr.max]; - } -} - -/** - * Legt die Grundriss-Primitive `planPrims` ausgerichtet unter einen Schnitt/ - * eine Ansicht, deren tiefste Kante bei `sectionMinY` liegt. Die Unterlage ist - * gedimmt (Referenz) und trägt zusätzlich die Schnittlinie selbst (strichpunk- - * tiert), damit sichtbar ist, wo geschnitten bzw. von wo geblickt wird. - */ -export function planUnderlayPrimitives( - level: DrawingLevel, - planPrims: Primitive[], - sectionMinY: number, -): Primitive[] { - const base = planToSectionMap(level); - if (!base) return []; - const mapped: Primitive[] = []; - let maxY = -Infinity; - for (const pr of planPrims) { - const q = mapPlanPrimitive(base, pr); - if (!q) continue; - for (const p of primitivePoints(q)) if (p.y > maxY) maxY = p.y; - mapped.push(q); - } - // Schnittlinie (w = 0) liegt immer mit in der Unterlage. - if (0 > maxY) maxY = 0; - const shift = sectionMinY - PLAN_UNDERLAY_GAP_M - maxY; - const out: Primitive[] = []; - for (const q of mapped) { - const moved = mapPlanPrimitive({ p0: { x: 0, y: 0 }, u: { x: 1, y: 0 }, n: { x: 0, y: 1 }, theta: 0, dy: shift }, q); - if (moved) out.push({ ...moved, greyed: true } as Primitive); - } - const [l0, l1] = level.linePoints!; - const len = Math.hypot(l1.x - l0.x, l1.y - l0.y); - out.push({ - kind: "line", - a: { x: 0, y: shift }, - b: { x: len, y: shift }, - cls: "section-underlay-line", - weightMm: 0.25, - dash: [3, 0.8, 0.4, 0.8], - color: "#8a3b2c", - }); - return out; -} - -/** - * Welche Fremd-Art-Ebene darf als Unterlage in welcher aktiven Ebene erscheinen? - * Massgebend ist der Koordinatenraum: Geschoss und freie Zeichnung teilen X/Y, - * Schnitte/Ansichten messen dagegen Länge×Höhe entlang IHRER Linie. Ein Schnitt - * im Grundriss (oder ein Grundriss/eine andere Ansicht im Schnitt) lag darum - * nur zufällig irgendwo und überdeckte den eigentlichen Plan (Nutzer-Report - * 2026-10-20: Fenster der Ansicht im EG-Grundriss, Raumstempel im Schnitt). - * • freie Zeichnung: alles (Kalkierpapier zum Abzeichnen, Nutzer-Wunsch). - * • Geschoss: nur freie Zeichnungen (gleicher X/Y-Raum). - * • Schnitt/Ansicht: nichts — ein Grundriss kommt dort ausgerichtet über - * `DrawingLevel.planUnderlayId` dazu (s. plan/planUnderlay.ts). - */ -export function crossKindOverlayAllowed(active: DrawingLevelKind, other: DrawingLevelKind): boolean { - if (active === "drawing") return true; - if (active === "floor") return other === "drawing"; - return false; -} diff --git a/src/views/viewportContent.tsx b/src/views/viewportContent.tsx index 5da1acbb..6cdf68a4 100644 --- a/src/views/viewportContent.tsx +++ b/src/views/viewportContent.tsx @@ -1120,7 +1120,7 @@ function SectionPlanView({ const rawPlan = isElevation ? elevationPlan : sectionPlan; // Grundriss-Unterlage (Nutzer-Wunsch: "in der Ansicht auch mal einen // Grundriss zeigen können"): das in `level.planUnderlayId` gewählte Geschoss - // AUSGERICHTET unter dem Schnitt/der Ansicht (s. plan/planUnderlay.ts) — + // AUSGERICHTET unter dem Schnitt/der Ansicht (Kern `plan/underlay.rs`) — // nicht mehr jede sichtbare Ebene lose übereinander (die lag in einem // fremden Koordinatenraum und verdeckte den Schnitt). const underlayFloor = project.drawingLevels.find( @@ -1129,18 +1129,19 @@ function SectionPlanView({ const sectionMinY = rawPlan?.bounds.minY; const overlayPrimitives = useMemo(() => { if (!underlayFloor || sectionMinY === undefined) return []; - const floorPlan = generatePlan( + // Der Kern legt den Grundriss (aus seinen Plan-Caches) gedimmt und ohne Auswahl-Ids darunter. + return planUnderlayPrimitives( project, + level, underlayFloor.id, + sectionMinY, visibleCodes, categoryDisplay, detail, referenceLines, mono, - false, scaleDenominator, ); - return planUnderlayPrimitives(level, floorPlan.primitives, sectionMinY).map(stripSelectableIds); }, [underlayFloor, sectionMinY, project, level, visibleCodes, categoryDisplay, detail, referenceLines, mono, scaleDenominator]); // Eigene 2D-Elemente des Schnitts/der Ansicht (Bemassung, Höhenkoten, // Beschriftung, Ergänzungslinien …): liegen in `drawings2d` mit