diff --git a/src-tauri/core/src/plan/drawings.rs b/src-tauri/core/src/plan/drawings.rs index c3d4dc87..193c747a 100644 --- a/src-tauri/core/src/plan/drawings.rs +++ b/src-tauri/core/src/plan/drawings.rs @@ -1930,8 +1930,13 @@ pub fn plan_drawings(c: &Ctx, sink: &mut Sink, bounds: &mut Bounds) -> Result<() /// auf Klassen, die `pred` (Klassen-Code) wählt und die der Plan zeigt; je Klasse in Projekt-Reihenfolge. Quelle der /// gefüllten Kataster-Gebäude und -Gewässer im Situationsplan (`situation.rs`). pub fn closed_rings_by_class(c: &Ctx, pred: impl Fn(&str) -> bool) -> Vec<(String, Vec>)> { + closed_rings_by_class_ids(c, pred).into_iter().map(|(k, v)| (k, v.into_iter().map(|(_, r)| r).collect())).collect() +} + +/// Wie [`closed_rings_by_class`], aber jeder Ring trägt die Id seiner Zeichnung (Anwahl der gefüllten Flächen). +pub fn closed_rings_by_class_ids(c: &Ctx, pred: impl Fn(&str) -> bool) -> Vec<(String, Vec<(String, Vec<[f64; 2]>)>)> { let mut memo = Memo::default(); - let mut out: Vec<(String, Vec>)> = Vec::new(); + let mut out: Vec<(String, Vec<(String, Vec<[f64; 2]>)>)> = Vec::new(); for d in &c.p.drawings2d { if !matches!(d.geom, Drawing2DGeom::Polyline { closed: true, .. } | Drawing2DGeom::Rect { .. }) || !pred(&d.category_code) || !on_floor(c, d) { continue; @@ -1952,9 +1957,10 @@ pub fn closed_rings_by_class(c: &Ctx, pred: impl Fn(&str) -> bool) -> Vec<(Strin if rings.is_empty() { continue; } + let rings = rings.into_iter().map(|r| (d.id.clone(), r)); match out.iter_mut().find(|(k, _)| *k == d.category_code) { Some((_, v)) => v.extend(rings), - None => out.push((d.category_code.clone(), rings)), + None => out.push((d.category_code.clone(), rings.collect())), } } out diff --git a/src-tauri/core/src/plan/situation.rs b/src-tauri/core/src/plan/situation.rs index d49ecffa..c60c37aa 100644 --- a/src-tauri/core/src/plan/situation.rs +++ b/src-tauri/core/src/plan/situation.rs @@ -193,12 +193,31 @@ pub fn mesh_polygons(positions: &[f64], indices: &[f64]) -> Vec { /// Gefüllte Flächen: ein Polygon je Fläche; Löcher sind über Brücken eingebunden (Brückenkanten ohne Strich). fn fill_polygons(polys: &[Polygon], f: (&str, &str), context_id: Option<&str>, greyed: bool, out: &mut Vec) { + fill_polygons_of(polys, f, context_id, greyed, out, |_| None) +} + +/// Wie [`fill_polygons`]; `drawing_of` nennt je Polygon die Zeichnung, der es gehört (Anwahl im Plan). +fn fill_polygons_of(polys: &[Polygon], f: (&str, &str), context_id: Option<&str>, greyed: bool, out: &mut Vec, drawing_of: impl Fn(&Polygon) -> Option) { for poly in polys { - let Some(outer) = poly.first().filter(|r| r.len() >= 3) else { continue }; + let from = out.len(); + fill_polygon(poly, f, context_id, greyed, out); + if let Some(id) = drawing_of(poly) { + for q in &mut out[from..] { + if let Primitive::Polygon { drawing_id, .. } = q { + *drawing_id = Some(id.clone()); + } + } + } + } +} + +fn fill_polygon(poly: &Polygon, f: (&str, &str), context_id: Option<&str>, greyed: bool, out: &mut Vec) { + { + let Some(outer) = poly.first().filter(|r| r.len() >= 3) else { return }; let holes: Vec = poly.iter().skip(1).filter(|r| r.len() >= 3).cloned().collect(); if holes.is_empty() { out.push(polygon(outer.iter().map(|q| v2(*q)).collect(), f.0, f.1, OUTLINE_MM, context_id, greyed)); - continue; + return; } let merged = crate::polygon_holes::merge_holes(outer, &holes, 1e-4); let mut prim = polygon(merged.ring.iter().map(|q| v2(*q)).collect(), f.0, f.1, OUTLINE_MM, context_id, greyed); @@ -231,15 +250,17 @@ fn name_has(c: &Ctx, code: &str, words: &[&str]) -> bool { /// der Klasse der Zeichnung (die Klasse bestimmt über [`super::drawings::closed_rings_by_class`], ob sie erscheinen). /// Innenhöfe sind Löcher. Unterhalb der Zeichnungen; deren Linien bleiben darüber. pub fn cadastre_prims(c: &Ctx, s: &Opts, out: &mut Vec) { - let fills = |kind: fn(&Ctx, &str) -> bool| super::drawings::closed_rings_by_class(c, |code| kind(c, code)); + let fills = |kind: fn(&Ctx, &str) -> bool| super::drawings::closed_rings_by_class_ids(c, |code| kind(c, code)); if let Some(f) = colors(s.context) { for (code, rings) in fills(is_building_class) { - fill_polygons(&crate::polygon_bool::nest_even_odd(&rings), f, None, c.greyed(&code), out); + let (polys, owner) = nest_with_owner(&rings); + fill_polygons_of(&polys, f, None, c.greyed(&code), out, owner); } } for (code, rings) in fills(is_water_class) { let from = out.len(); - fill_polygons(&crate::polygon_bool::nest_even_odd(&rings), WATER, None, c.greyed(&code), out); + let (polys, owner) = nest_with_owner(&rings); + fill_polygons_of(&polys, WATER, None, c.greyed(&code), out, owner); for q in &mut out[from..] { if let Primitive::Polygon { hatch, .. } = q { *hatch = Box::new(water_hatch(c.a.scale)); @@ -248,6 +269,24 @@ pub fn cadastre_prims(c: &Ctx, s: &Opts, out: &mut Vec) { } } +/// Verschachtelt die Ringe (gerade/ungerade) und liefert dazu die Zuordnung Polygon → Zeichnung: Der Aussenring eines +/// Polygons gehört der Zeichnung, deren Ring denselben Eckpunkt hat (kleinster Flächenunterschied bei mehreren). +fn nest_with_owner(rings: &[(String, Ring)]) -> (Vec, impl Fn(&Polygon) -> Option + '_) { + let plain: Vec = rings.iter().map(|(_, r)| r.clone()).collect(); + let area = |r: &Ring| (0..r.len()).map(|i| r[i][0] * r[(i + 1) % r.len()][1] - r[(i + 1) % r.len()][0] * r[i][1]).sum::().abs() / 2.0; + let owner = move |poly: &Polygon| -> Option { + let outer = poly.first()?; + let a = area(outer); + let p0 = *outer.first()?; + rings + .iter() + .filter(|(_, r)| r.contains(&p0)) + .min_by(|x, y| (area(&x.1) - a).abs().total_cmp(&(area(&y.1) - a).abs())) + .map(|(id, _)| id.clone()) + }; + (crate::polygon_bool::nest_even_odd(&plain), owner) +} + /// Wasser als feine waagrechte Parallelschraffur (Plangrafik-Brauch für Gewässer): bleibt in Tusche erhalten, wo die /// hellblaue Fläche weiss wird (`extras::Post`: bunte Fläche → Papier, bunte Schraffur → Tinte). Abstand auf dem /// Papier fest ([`WATER_HATCH_MM`]), unabhängig vom Massstab; Musterabstand = 8 · scale / 90 m. diff --git a/src/panels/ObjectInfoPanel.tsx b/src/panels/ObjectInfoPanel.tsx index 171edce2..71f3e32d 100644 --- a/src/panels/ObjectInfoPanel.tsx +++ b/src/panels/ObjectInfoPanel.tsx @@ -36,7 +36,7 @@ import { ViewShadowsInfo, MeasurementSection } from "./objectInfo/InfoBlocks"; import { DimensionField, RotateField } from "./objectInfo/fields"; import { elementDimensions } from "./objectInfo/elementDims"; import { InfoGroups, hasInfoGroups } from "./objectInfo/InfoGroups"; -import { InfoGroup } from "./objectInfo/InfoGroup"; +import { infoGroupFrame, useInfoGroupState } from "./objectInfo/InfoGroup"; // ── Bezugspunkt-Raster ─────────────────────────────────────────────────────── // Neun Anker als 3×3-Raster. Zeile 0 = oben (fy=0), Spalte 0 = links (fx=0). @@ -63,6 +63,8 @@ function toDeg360(rad: number): number { export function ObjectInfoPanel({ showPlacement = true }: { showPlacement?: boolean } = {}) { const host = usePanelHost(); const storeProject = useStore((st) => st.project); + // [121] Abschnitts-Rahmen ohne eigene Komponente (kein Render je Abschnitt bei Inhaltsänderung). + const gst = useInfoGroupState(); const sel = useSelectionInfo(); // Gewählter Bezugspunkt — Default Mitte (Vectorworks-Standardanker beim @@ -194,7 +196,7 @@ export function ObjectInfoPanel({ showPlacement = true }: { showPlacement?: bool {showPlacement && ( <> - + {infoGroupFrame(gst, "refpoint", <> {/* Bezugspunkt-Würfel (3×3, immer quadratisch) links, X/Y/Z als Spalte rechts daneben (Nutzer-Wunsch). */}
@@ -248,9 +250,9 @@ export function ObjectInfoPanel({ showPlacement = true }: { showPlacement?: bool host.onRotateSelectionAround(px, py, deg)} />
-
+ )} - + {infoGroupFrame(gst, "dimensions", <> {/* Maße (editierbar) — Commit auf blur/Enter skaliert um den Anker. */} {elementDims ? ( // [204a] Wand: Länge/Dicke/Höhe, Öffnung: Breite/Höhe/Brüstung (nur Anzeige). @@ -351,7 +353,7 @@ export function ObjectInfoPanel({ showPlacement = true }: { showPlacement?: bool /> )} - + )} )} {/* Gelände-/Umgebungs-Element (Netzkörper, Gelände, Höhenlinien …): Art, Herkunft (nur Auskunft, [181]), @@ -359,7 +361,7 @@ export function ObjectInfoPanel({ showPlacement = true }: { showPlacement?: bool georeferenziert importiert wurde (Nutzer-Wunsch zum Prüfen). */} {sel.contextObject && ( <> - + {infoGroupFrame(gst, "contextProps", <>
{t("objinfo.contextObject.type")} {t(`objinfo.contextObject.type.${sel.contextObject.objType}`)} @@ -369,9 +371,9 @@ export function ObjectInfoPanel({ showPlacement = true }: { showPlacement?: bool
)} -
+ )} {/* [239] Herkunft und LV95 stehen in eigener Gruppe (Standard zugeklappt: nur Auskunft). */} - + {infoGroupFrame(gst, "georef", <> {sel.contextObject.source && (
{t("objinfo.contextObject.source")} @@ -394,7 +396,7 @@ export function ObjectInfoPanel({ showPlacement = true }: { showPlacement?: bool {t("objinfo.contextObject.noAnchor")}
)} -
+ )} )} {/* [189] Bauteil-/BIM-Abschnitte (Wand, Decke, Öffnung, Treppe, Raum …) als einklappbare Gruppen. */} diff --git a/src/panels/objectInfo/InfoGroup.tsx b/src/panels/objectInfo/InfoGroup.tsx index 0f925145..b7a09073 100644 --- a/src/panels/objectInfo/InfoGroup.tsx +++ b/src/panels/objectInfo/InfoGroup.tsx @@ -1,25 +1,34 @@ // [189] Einklappbarer Abschnitt der Objekt-Info: Kopfzeile (Knopf mit Pfeil) und Inhalt. Die Abschnitts- // Komponenten (`WallSection` …) bringen ihre eigene Kopf-Trennlinie mit; die erste blendet das CSS im Rumpf aus. -import { useEffect, useRef, useSyncExternalStore, type ReactNode } from "react"; +import { useSyncExternalStore, type ReactNode } from "react"; import { t } from "../../i18n"; import { INFO_GROUP_TITLE, type InfoGroupId } from "./groups"; import { clearInfoGroupFocus, getInfoGroupState, isInfoGroupOpen, subscribeInfoGroups, toggleInfoGroup } from "./infoGroupState"; -export function InfoGroup({ id, children }: { id: InfoGroupId; children: ReactNode }) { - const st = useSyncExternalStore(subscribeInfoGroups, getInfoGroupState, getInfoGroupState); +type GroupState = ReturnType; + +/** Zustand der Abschnitte (offen/zu, Fokus-Anfrage) für [`infoGroupFrame`]. */ +export function useInfoGroupState(): GroupState { + return useSyncExternalStore(subscribeInfoGroups, getInfoGroupState, getInfoGroupState); +} + +/** + * Abschnitt als blosses Markup, ohne eigene Komponente: Das Panel liest den Zustand einmal ([`useInfoGroupState`]) + * und rahmt damit mehrere Abschnitte, ohne dass je Abschnitt ein Komponenten-Render bei jeder Änderung des Inhalts + * anfällt ([121], Render-Zählung). Die Fokus-Anfrage löst der Ref des Kopfknopfs ein. + */ +export function infoGroupFrame(st: GroupState, id: InfoGroupId, children: ReactNode): ReactNode { const open = isInfoGroupOpen(st, id); - const head = useRef(null); - useEffect(() => { - if (st.focus?.id !== id) return; - head.current?.scrollIntoView?.({ block: "nearest" }); - head.current?.focus(); - clearInfoGroupFocus(); - }, [st.focus, id]); return ( -
+
); } + +export function InfoGroup({ id, children }: { id: InfoGroupId; children: ReactNode }) { + const st = useInfoGroupState(); + return infoGroupFrame(st, id, children); +}