Files
DOSSIER/src-tauri/core/src/plan/situation_tests.rs
T
Claude fb0c932b53 [271] Umbaufilter: Status Bestand/Abbruch/Neu mit Etappen, Filter wie Archicad in Grundriss, Schnitt, Ansicht, Axo, 3D, Kennzahlen, DXF und IFC
Modell (Rust, gen:types): `renovation: {status, phase?}` an Wand, Öffnung (ohne eigenen Status
folgt sie der Wand), Decke, Dach, Treppe, Stütze, Körper und Raum (Raum nur Sichtbarkeit und
Flächen, keine Farbe); `Project.renovation` (Etappen, Farben, eigene Filter, KNOWN_KEYS);
`renovationFilter`/`renovationPhase` an DrawingLevel, ViewTemplate und ViewSnapshot — der Filter
gehört zur Ebene wie die Modelldarstellung [173], damit je Reiter, Ausschnitt und Vorlage.

Kern `renovation.rs` als ein Ort für „sichtbar/wie gezeichnet im Filter“: Vorgaben Bestand,
Abbruch, Neubau, Umbauplan, Endzustand; SIA-400-Farben (Bestand grau, Abbruch gelb gestrichelt,
Neu rot), anpassbar; Etappe „bis n“; neue Öffnung in Bestandswand = Abbruch-Stück, zugemauerte
Öffnung = Ausfachung (die Wand schliesst, wo die Öffnung ausgeblendet ist, wie bei der Regel
„Ausblenden“). Angebunden: Grundriss (Ctx.hidden, Farben je Element-Bereich, nur Schnittflächen
gefüllt, Symbole in Linienfarbe), Schnitt (without_elements + CutRules::with_renovation), Ansicht,
Vektor-Axo, 3D (model3dParts mit Filter, 3D-Fenster nimmt den Filter der aktiven Ebene),
Kennzahlen/Flächen (Text = Zustand), DXF (Layer <Klasse>_Abbruch/_Neu), IFC (Status im
Pset_*Common, Etappe in Dossier_Umbau). Tusche behält die Umbau-Farben (extras::KeepColors).
Neue Bauteile der Zeichenbefehle tragen den Zeichen-Status (commands::stamp_renovation).

Bedienung: Objekt-Info/Objekteinstellungen „Umbau“ und „Etappe“ (Mehrfachauswahl, ein
Undo-Schritt), Statusleiste „Umbau: …“ mit Zeichen-Status und Umbaufilter der Ansicht (im
Überlauf „⋯“ mit der Pausfolie), Befehl `umbau` (B/A/N; getippte Options-Kürzel mit Enter),
Ressourcen-Tab „Umbau“ (Etappen, Farben), Flächenbilanz „Zustand“, Vorlage „Beispiel Umbau“
(CLI :umbau), CLI --renovation/--phase für plan, section, elevation, axo, model3d, kennzahlen.

Tests: Kern renovation_tests.rs (20: Vorgaben, Etappen, Öffnungen in Bestandswand, Grundriss,
Schnitt, Ansicht, Kennzahlen, DXF, IFC, 3D, Tusche, Zeichen-Status, Unsinn), Robustheit (Plan,
Schnitt, Ansicht, Kennzahlen, 3D mit Filter), vitest model/renovation.test.ts und
commands/cmds/renovation.test.ts, e2e renovation271.spec.ts (2× grün). Goldens unverändert.
Bilder doc/review-271 (CLI-SVG --hatch in Chromium, App). Nur im Linux-Container geprüft, nicht
in der Tauri-App/auf dem Mac (Prüfschritt RELEASE-1.0 13.37). Offen: TODO [271].
2026-11-17 11:44:28 +00:00

246 lines
14 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! [207] Situationsplan / Schwarzplan: eigenes Gebäude schwarz, Kontext grau (bzw. schwarz), Klassen, Planzeichen.
use super::*;
use crate::plan::domains::{plan_domains_buf, PlanArgs};
use crate::standards::{derived_categories, model_views, SITUATION_CATEGORY, SYMBOL_CATEGORY};
use serde_json::{json, Value};
/// Würfel 10 × 6 × 8 m an (x0, y0), Dreiecke wie beim Import (aussen, ohne Boden-Duplikate).
fn box_mesh(id: &str, category: &str, x0: f64, y0: f64) -> Value {
let (x1, y1) = (x0 + 10.0, y0 + 6.0);
let positions = [x0, y0, 0.0, x1, y0, 0.0, x1, y1, 0.0, x0, y1, 0.0, x0, y0, 8.0, x1, y0, 8.0, x1, y1, 8.0, x0, y1, 8.0];
let indices = [0, 2, 1, 0, 3, 2, 4, 5, 6, 4, 6, 7, 0, 1, 5, 0, 5, 4, 1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 0, 4, 3, 4, 7];
json!({"type": "importedMesh", "id": id, "name": id, "categoryCode": category, "positions": positions.to_vec(), "indices": indices.to_vec()})
}
fn project() -> Project {
let mut v: Value = serde_json::from_str(include_str!("../../tests/fixtures/sample_project.json")).unwrap();
v["layers"].as_array_mut().unwrap().extend(derived_categories());
v["layers"].as_array_mut().unwrap().push(json!({"code": "12", "name": "Gebäude", "color": "#888888", "lw": 0.18, "visible": true, "locked": false}));
// Untergeschoss mit einer Wand ausserhalb des Hauses: zählt nicht zum Gebäude über dem Terrain.
v["drawingLevels"].as_array_mut().unwrap().push(json!({"id": "ug", "name": "UG", "kind": "floor", "visible": true, "locked": false, "baseElevation": -2.7}));
v["walls"].as_array_mut().unwrap().push(json!({"id": "w-ug", "type": "wall", "floorId": "ug", "categoryCode": "20", "start": {"x": 20, "y": 0}, "end": {"x": 25, "y": 0}, "wallTypeId": "aw", "height": 2.6}));
v["modelViewOptions"] = Value::Array(model_views());
v["context"] = json!([box_mesh("nachbar-1", "12", 12.0, -1.0), box_mesh("nachbar-2", "12", -14.0, 5.0)]);
serde_json::from_value(v).unwrap()
}
fn codes(p: &Project) -> Vec<String> {
p.flat_categories().iter().map(|c| c.code.clone()).collect()
}
fn plan(p: &Project, show: &[String], model_view: &str) -> Vec<Primitive> {
let a = PlanArgs::parse(1.0, &json!({"floor": "eg", "show": show, "global": true, "scale": 500, "modelView": model_view}).to_string()).unwrap();
let buf = plan_domains_buf(p, &a).unwrap();
crate::plan::buf::View::parse(&buf).unwrap().prims().unwrap()
}
fn without(codes: &[String], code: &str) -> Vec<String> {
codes.iter().filter(|c| *c != code).cloned().collect()
}
fn fills<'a>(ps: &'a [Primitive], color: &str) -> Vec<&'a Primitive> {
ps.iter().filter(|q| matches!(q, Primitive::Polygon { fill, .. } if fill == color)).collect()
}
fn ring_area(pts: &[Vec2]) -> f64 {
(0..pts.len()).map(|i| (pts[i].x * pts[(i + 1) % pts.len()].y - pts[(i + 1) % pts.len()].x * pts[i].y) / 2.0).sum::<f64>().abs()
}
#[test]
fn eigenes_gebaeude_schwarz_ohne_bauteile() {
let p = project();
let ps = plan(&p, &codes(&p), "std-mv-situation-wbw");
// Keine Wand-Poché, keine Raumstempel, keine Schnittmarken.
assert!(!ps.iter().any(|q| matches!(q, Primitive::Polygon { wall_id: Some(_), .. })), "Wände entfallen");
assert!(!ps.iter().any(|q| matches!(q, Primitive::Text { room_id: Some(_), .. })), "Raumstempel entfallen");
let black: Vec<_> = fills(&ps, "#000000").into_iter().filter(|q| matches!(q, Primitive::Polygon { context_object_id: None, stroke_width_mm, .. } if *stroke_width_mm == 0.1)).collect();
assert_eq!(black.len(), 1, "ein schwarzer Umriss (UG-Wand zählt nicht)");
let Primitive::Polygon { pts, .. } = black[0] else { unreachable!() };
assert!(pts.iter().all(|q| q.x < 6.0), "nur das Haus über dem Terrain: {pts:?}");
let a = ring_area(pts);
assert!(a > 15.0 && a < 40.0, "Fläche des Hauses: {a}");
}
#[test]
fn kontext_grau_und_schwarzplan_schwarz() {
let p = project();
let wbw = plan(&p, &codes(&p), "std-mv-situation-wbw");
let grey: Vec<_> = wbw.iter().filter(|q| matches!(q, Primitive::Polygon { context_object_id: Some(_), fill, .. } if fill == "#b8b8b8")).collect();
assert_eq!(grey.len(), 2, "zwei Nachbarn grau");
let Primitive::Polygon { pts, context_object_id, .. } = grey[0] else { unreachable!() };
assert_eq!(context_object_id.as_deref(), Some("nachbar-1"));
assert!((ring_area(pts) - 60.0).abs() < 1e-6, "Grundfläche aus der Aufsicht: {}", ring_area(pts));
let sp = plan(&p, &codes(&p), "std-mv-schwarzplan");
let black_ctx = sp.iter().filter(|q| matches!(q, Primitive::Polygon { context_object_id: Some(_), fill, .. } if fill == "#000000")).count();
assert_eq!(black_ctx, 2, "Schwarzplan: Nachbarn schwarz");
}
#[test]
fn alles_auf_klassen() {
let p = project();
let all = codes(&p);
let own = |ps: &[Primitive]| ps.iter().filter(|q| matches!(q, Primitive::Polygon { context_object_id: None, fill, stroke_width_mm, .. } if fill == "#000000" && *stroke_width_mm == 0.1)).count();
let ctx = |ps: &[Primitive]| ps.iter().filter(|q| matches!(q, Primitive::Polygon { context_object_id: Some(_), .. })).count();
let north = |ps: &[Primitive]| ps.iter().any(|q| matches!(q, Primitive::DrawingText { text, .. } if text == "N"));
let base = plan(&p, &all, "std-mv-situation-wbw");
assert!(own(&base) == 1 && ctx(&base) == 2 && north(&base));
let no_own = plan(&p, &without(&all, SITUATION_CATEGORY), "std-mv-situation-wbw");
assert!(own(&no_own) == 0 && ctx(&no_own) == 2 && north(&no_own), "Klasse 83 schaltet das eigene Gebäude");
let no_ctx = plan(&p, &without(&all, "12"), "std-mv-situation-wbw");
assert!(own(&no_ctx) == 1 && ctx(&no_ctx) == 0, "Klasse der Netze schaltet den Kontext");
let no_sym = plan(&p, &without(&all, SYMBOL_CATEGORY), "std-mv-situation-wbw");
assert!(own(&no_sym) == 1 && !north(&no_sym), "Klasse 84 schaltet Nordpfeil und Massstabsbalken");
}
#[test]
fn gewoehnlicher_grundriss_bleibt() {
let p = project();
let ps = plan(&p, &codes(&p), "mittel");
assert!(ps.iter().any(|q| matches!(q, Primitive::Polygon { wall_id: Some(_), .. })));
assert!(fills(&ps, "#b8b8b8").is_empty());
assert!(!ps.iter().any(|q| matches!(q, Primitive::DrawingText { text, .. } if text == "N")));
}
#[test]
fn dachaufsicht_zaehlt_zum_gebaeude() {
let p = project();
let Some(r) = p.roofs.as_deref().and_then(|r| r.first()) else { panic!("Fixture hat ein Dach") };
let g = crate::roof::roof_geometry(&r.params(), p.roof_base_elevation(r));
let polys = own_polygons(&p);
let (min_x, max_x) = g.eaves.iter().fold((f64::INFINITY, f64::NEG_INFINITY), |a, q| (a.0.min(q[0]), a.1.max(q[0])));
let xs: Vec<f64> = polys.iter().flat_map(|q| q[0].iter().map(|r| r[0])).collect();
assert!(xs.iter().cloned().fold(f64::INFINITY, f64::min) <= min_x + 1e-6 && xs.iter().cloned().fold(f64::NEG_INFINITY, f64::max) >= max_x - 1e-6, "Umriss deckt die Traufe");
}
#[test]
fn netz_flaeche_ohne_senkrechte() {
// Nur senkrechte Dreiecke: keine Fläche in der Aufsicht.
let pos = [0.0, 0.0, 0.0, 5.0, 0.0, 0.0, 5.0, 0.0, 3.0];
assert!(mesh_polygons(&pos, &[0.0, 1.0, 2.0]).is_empty());
// Ungültige Indizes und NaN: ohne Panic leer.
assert!(mesh_polygons(&[0.0, 0.0, 0.0, f64::NAN, 0.0, 0.0, 1.0, 1.0, 0.0], &[0.0, 1.0, 2.0, 0.0, 9.0, 1.0]).is_empty());
}
#[test]
fn massstabsbalken_rund_und_im_papiermass() {
assert_eq!(scalebar_total(500.0), 20.0);
assert_eq!(scalebar_total(1000.0), 50.0);
assert_eq!(scalebar_total(200.0), 10.0);
let s = symbols(500.0, 40.0, -10.0);
// Vier Balkenfelder + zwei Spitzenhälften, alle unter der Lage (Papierabstand 12 mm = 6 m).
let polys: Vec<_> = s.iter().filter_map(|q| if let Primitive::Polygon { pts, .. } = q { Some(pts) } else { None }).collect();
assert_eq!(polys.len(), 6);
assert!(polys.iter().flat_map(|p| p.iter()).all(|q| q.y < -10.0), "unter der Oberkante der Lage");
}
#[test]
fn baurecht_nur_parzellengrenze() {
let mut p = project();
p.site_rules = Some(serde_json::from_value(json!({"parcel": [{"x": -8, "y": -8}, {"x": 16, "y": -8}, {"x": 16, "y": 12}, {"x": -8, "y": 12}], "setbacks": [3, 3, 3, 3], "defaultSetback": 3, "show": true})).unwrap());
let mut all = codes(&p);
all.push("01".into());
let ps = plan(&p, &all, "std-mv-situation-wbw");
let cls = |c: &str| ps.iter().filter(|q| matches!(q, Primitive::Line { cls, .. } if cls == c)).count();
assert!(cls("site-parcel") >= 4, "Parzellengrenze bleibt");
assert_eq!(cls("site-allowed"), 0, "kein Baubereich");
let normal = plan(&p, &all, "mittel");
assert!(normal.iter().filter(|q| matches!(q, Primitive::Line { cls, .. } if cls == "site-allowed")).count() > 0, "im gewöhnlichen Grundriss schon");
}
fn poly2d(id: &str, code: &str, pts: &[(f64, f64)]) -> Value {
json!({"id": id, "type": "drawing2d", "levelId": "eg", "categoryCode": code, "geom": {"shape": "polyline", "closed": true, "pts": pts.iter().map(|(x, y)| json!({"x": x, "y": y})).collect::<Vec<_>>()}})
}
fn rect_pts(x0: f64, y0: f64, x1: f64, y1: f64) -> [(f64, f64); 4] {
[(x0, y0), (x1, y0), (x1, y1), (x0, y1)]
}
/// Kataster: Haus mit Innenhof (zwei geschlossene Polylinien), Nachbarhaus, Gewässer auf Klasse „17".
fn cadastre_project() -> Project {
let p = project();
let mut v = serde_json::to_value(&p).unwrap();
v["context"] = json!([]);
v["layers"].as_array_mut().unwrap().push(json!({"code": "17", "name": "Gewässer", "color": "#909090", "lw": 0.13, "visible": true, "locked": false}));
let d = v["drawings2d"].as_array_mut().unwrap();
d.push(poly2d("k-haus", "12", &rect_pts(30.0, -20.0, 60.0, 0.0)));
d.push(poly2d("k-hof", "12", &rect_pts(40.0, -14.0, 50.0, -6.0)));
d.push(poly2d("k-nachbar", "12", &rect_pts(70.0, -20.0, 80.0, -10.0)));
d.push(poly2d("k-see", "17", &rect_pts(30.0, 10.0, 60.0, 30.0)));
serde_json::from_value(v).unwrap()
}
#[test]
fn kataster_gebaeude_gefuellt_hof_als_loch() {
let p = cadastre_project();
let ps = plan(&p, &codes(&p), "std-mv-situation-wbw");
let grey: Vec<&Primitive> = fills(&ps, "#b8b8b8").into_iter().filter(|q| matches!(q, Primitive::Polygon { context_object_id: None, .. })).collect();
assert_eq!(grey.len(), 2, "Haus mit Hof und Nachbar, je eine Fläche");
// Haus: 30 x 20 minus Hof 10 x 8 = 520 m2; der Hof ist ein Loch (Brückenring).
let areas: Vec<f64> = grey.iter().map(|q| if let Primitive::Polygon { pts, .. } = q { ring_area(pts) } else { 0.0 }).collect();
assert!(areas.iter().any(|a| (a - 520.0).abs() < 0.5), "Haus abzüglich Hof: {areas:?}");
assert!(areas.iter().any(|a| (a - 100.0).abs() < 1e-6), "Nachbarhaus: {areas:?}");
// Brückenkanten ohne Strich, kein weisser Hof darüber.
assert!(grey.iter().any(|q| matches!(q, Primitive::Polygon { no_stroke_edges: Some(e), .. } if !e.is_empty())), "Brücke zum Hof");
assert!(fills(&ps, "#ffffff").iter().all(|q| matches!(q, Primitive::Polygon { stroke_width_mm, .. } if *stroke_width_mm != 0.1)), "keine weisse Fläche über dem Hof");
// Gewässer hellblau.
let water = fills(&ps, "#cfe3f1");
assert_eq!(water.len(), 1);
let Primitive::Polygon { pts, .. } = water[0] else { unreachable!() };
assert!((ring_area(pts) - 600.0).abs() < 1e-6);
}
#[test]
fn kataster_schwarzplan_und_klassen() {
let p = cadastre_project();
let all = codes(&p);
let sp = plan(&p, &all, "std-mv-schwarzplan");
let black = sp.iter().filter(|q| matches!(q, Primitive::Polygon { context_object_id: None, fill, stroke_width_mm, .. } if fill == "#000000" && *stroke_width_mm == 0.1)).count();
assert_eq!(black, 3, "eigenes Gebäude + Haus + Nachbar schwarz");
let no12 = plan(&p, &without(&all, "12"), "std-mv-situation-wbw");
assert!(fills(&no12, "#b8b8b8").is_empty(), "Klasse Gebäude schaltet die Kataster-Flächen");
let no17 = plan(&p, &without(&all, "17"), "std-mv-situation-wbw");
assert!(fills(&no17, "#cfe3f1").is_empty(), "Klasse Gewässer schaltet das Gewässer");
let normal = plan(&p, &all, "mittel");
assert!(fills(&normal, "#b8b8b8").is_empty() && fills(&normal, "#cfe3f1").is_empty());
}
/// [207] Gewässer: hellblau mit feiner Parallelschraffur; in Tusche bleibt die Schraffur (Fläche weiss, Linien Tinte),
/// sonst wäre das Wasser auf dem Papier unsichtbar.
#[test]
fn kataster_gewaesser_mit_schraffur_auch_in_tusche() {
use crate::plan::extras::Post;
let p = cadastre_project();
let ps = plan(&p, &codes(&p), "std-mv-situation-wbw");
let water = fills(&ps, "#cfe3f1");
let Primitive::Polygon { hatch, .. } = water[0] else { unreachable!() };
assert_eq!(hatch.pattern, HatchPattern::Diagonal);
assert_eq!(hatch.angle, 90.0, "waagrechte Linien (Musterwinkel 0 = senkrecht)");
assert!(hatch.line_weight <= 0.1, "fein: {}", hatch.line_weight);
// Abstand 1.2 mm auf dem Papier bei 1:500: 8 · scale / 90 m = 0.6 m.
assert!((8.0 * hatch.scale / 90.0 - 0.6).abs() < 1e-9, "Abstand {}", 8.0 * hatch.scale / 90.0);
let mut q = water[0].clone();
Post { mono: true, lw: 1.0, sketch: 0.0, keep: Default::default() }.apply(&mut q);
let Primitive::Polygon { fill, hatch, .. } = &q else { unreachable!() };
assert_eq!(fill, "#ffffff");
assert_eq!(hatch.pattern, HatchPattern::Diagonal);
assert_eq!(hatch.color, crate::plan::style::MONO_INK, "Schraffur in Tusche");
// Gebäude behalten keine Schraffur.
assert!(fills(&ps, "#b8b8b8").iter().all(|q| matches!(q, Primitive::Polygon { hatch, .. } if hatch.pattern == HatchPattern::None)));
}
/// [207] Gefüllte Kataster-Flächen tragen ihren Umriss selbst (wie die Kontextnetze): die Zeichnungs-Linien der
/// Ringe liegen nicht noch einmal darüber. Im gewöhnlichen Grundriss bleiben sie.
#[test]
fn kataster_umrisse_nicht_doppelt() {
let p = cadastre_project();
let all = codes(&p);
let kat_lines = |ps: &[Primitive]| ps.iter().filter(|q| matches!(q, Primitive::Line { drawing_id: Some(id), .. } if id.starts_with("k-"))).count();
assert_eq!(kat_lines(&plan(&p, &all, "std-mv-situation-wbw")), 0);
assert_eq!(kat_lines(&plan(&p, &all, "std-mv-schwarzplan")), 0);
assert!(kat_lines(&plan(&p, &all, "mittel")) > 0, "gewöhnlicher Grundriss zeichnet sie");
// Schwarzplan: Umriss der gefüllten Gebäude schwarz wie die Füllung.
let sp = plan(&p, &all, "std-mv-schwarzplan");
assert!(sp.iter().filter(|q| matches!(q, Primitive::Polygon { fill, .. } if fill == "#000000")).all(|q| matches!(q, Primitive::Polygon { stroke, .. } if stroke == "#000000")));
}