From d6a707475a2faefcef2a81286db8c7e32336cb1a Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 11 Nov 2026 05:26:50 +0000 Subject: [PATCH] =?UTF-8?q?[26]=20Dach:=20Eck-=20und=20Kanten-Griffe=20an?= =?UTF-8?q?=20Umriss=20und=20H=C3=B6fen=20im=20Grundriss,=20Kante=20beim?= =?UTF-8?q?=20Anfasser=20hervorgehoben?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TODO.md | 7 +- e2e/roofGrips.spec.ts | 53 +++++++++++++++ src-tauri/core/src/grips.rs | 82 +++++++++++++++++++++++ src/geometry/grips.ts | 3 + src/state/projectSlice.ts | 8 +++ src/state/roofPlanGrips.test.ts | 76 +++++++++++++++++++++ src/state/useGripEditing.ts | 60 +++++++++++++++-- src/state/useGripInputs.ts | 7 +- src/state/useProjectActions.ts | 4 ++ src/styles.css | 9 +++ src/views/ViewportCenter.tsx | 5 +- src/views/plan/PlanView.tsx | 16 ++++- src/views/plan/planView/usePlanPointer.ts | 4 ++ 13 files changed, 325 insertions(+), 9 deletions(-) create mode 100644 e2e/roofGrips.spec.ts create mode 100644 src/state/roofPlanGrips.test.ts diff --git a/TODO.md b/TODO.md index 72a0b1d0..fe66506c 100644 --- a/TODO.md +++ b/TODO.md @@ -220,8 +220,11 @@ Wer zu einer ID mehr wissen will (Entscheide, Tests, Bilder), sucht dort nach `* Musterhaus komplex: Erker). Offen: Gefälle der Dachhaut (nur Darstellung im Schnitt); Attika bei Pult, an Höfen und bei verschnittenen Dächern; Live-Schnitt im 3D (`roofCutLayers`) ohne Attika; Ansicht orientiert Aussenflächen am Dachschwerpunkt (konkave Umrisse), Attika in Dachfarbe statt Bauteilfarbe. · M -- ◐ **[26]** Dächer über beliebige Grundrisse (`core/src/roof*.rs`). Kante im Grundriss hervorheben und Kanten-/ - Hof-Griffe (PlanView); Mansarde mit Hof und verschieden geneigten Kanten (zweite Schicht nicht geschlossen); +- ◐ **[26]** Dächer über beliebige Grundrisse (`core/src/roof*.rs`). Grundriss-Griffe (11.11.): am einzeln gewählten Dach + Eck-Griffe und Kanten-Anfasser an Umriss UND Höfen (Kern-Ops `roofVertex`/`roofEdge`, flacher Index Umriss→Höfe, + Umriss bleibt frei, Vorschau + ein Undo-Schritt je Zug), Kante unter dem Anfasser wird hervorgehoben (`plan-edge-hover`, + auch bei Decke/Raum/Baugrube). Offen: Eck einfügen/löschen (Mittel-Raute) am Dach, Kanten-Neigung/Giebel per Kontextmenü am + Griff (heute im Objekt-Info), Hover-Hervorhebung in der App nicht angesehen; Mansarde mit Hof und verschieden geneigten Kanten (zweite Schicht nicht geschlossen); Schattenwurf nimmt die Hülle der Dachfläche. · M - ◐ **[137]** Alles Sichtbare anwählbar. (10.11. bewusst nicht anwählbar, mit Begründung: Punktwolken sind kein Modellelement (Sitzungszustand, Millionen Punkte) — Ausblenden/Entfernen im Lage-Panel („Punktwolken"); Baurechts-Hüllkörper diff --git a/e2e/roofGrips.spec.ts b/e2e/roofGrips.spec.ts new file mode 100644 index 00000000..7a7e63a3 --- /dev/null +++ b/e2e/roofGrips.spec.ts @@ -0,0 +1,53 @@ +// [26] Dach im Grundriss: Eckgriffe am gewählten Dach (Umriss, hier ein Rechteck), Eckgriff ziehen (der Umriss +// wird schief, kein Rechteck erzwungen), Rückgängig stellt ihn her. Bildschirm-Punkte wie in sectionBend.spec.ts. +import type { Page } from "@playwright/test"; +import { blurFocus, elementRows, expect, openSample, openTab, startNewProject, test } from "./app"; + +async function gripCentres(page: Page): Promise<{ x: number; y: number }[]> { + const c = await page.locator(".plan-grip").evaluateAll((els) => + els.map((e) => { + const r = e.getBoundingClientRect(); + return { x: Math.round(r.x + r.width / 2), y: Math.round(r.y + r.height / 2) }; + }), + ); + return c.sort((a, b) => a.x - b.x || a.y - b.y); +} + +/** Griff ziehen: ein Griff bleibt nach dem Loslassen „bewaffnet" und folgt dem Zeiger, bis ein Klick ihn setzt. */ +async function dragGrip(page: Page, from: { x: number; y: number }, to: { x: number; y: number }): Promise { + await page.mouse.move(from.x, from.y); + await page.mouse.down(); + await page.mouse.move(to.x, to.y, { steps: 6 }); + await page.mouse.up(); + await page.mouse.click(to.x, to.y); +} + +test("Dach: Eckgriff im Grundriss ziehen, Rückgängig ([26])", async ({ page }) => { + await startNewProject(page); + await openSample(page); + await openTab(page, "Elemente"); + await elementRows(page).filter({ hasText: "RF1" }).first().click(); + await expect(page.getByText("Dachform")).toBeVisible(); + + await expect.poll(() => page.locator(".plan-grip").count()).toBe(4); + // Kanten-Anfasser je Seite. + await expect(page.locator(".plan-edge-grip")).toHaveCount(4); + const before = await gripCentres(page); + + // Linkeste/oberste Ecke nach rechts-unten ziehen: Umriss wird schief, die übrigen Ecken bleiben. + const corner = before[0]; + const target = { x: corner.x + 60, y: corner.y + 30 }; + await dragGrip(page, corner, target); + await expect + .poll(async () => (await gripCentres(page)).some((g) => Math.abs(g.x - target.x) < 3 && Math.abs(g.y - target.y) < 3)) + .toBe(true); + const after = await gripCentres(page); + expect(after).toHaveLength(4); + const unchanged = before.filter((b) => after.some((a) => Math.abs(a.x - b.x) < 2 && Math.abs(a.y - b.y) < 2)); + expect(unchanged.length).toBe(3); + + // Ein Undo-Schritt stellt den Umriss her. + await blurFocus(page); + await page.keyboard.press("ControlOrMeta+z"); + await expect.poll(() => gripCentres(page)).toEqual(before); +}); diff --git a/src-tauri/core/src/grips.rs b/src-tauri/core/src/grips.rs index 38d26562..c2abe3ea 100644 --- a/src-tauri/core/src/grips.rs +++ b/src-tauri/core/src/grips.rs @@ -316,6 +316,29 @@ pub fn run(lk: &Lookup, req: &Request) -> Result { let (index, (x, y)) = (r.n("index"), r.p("pt")); patch("roofs", r.s("id"), &|e| roof_grip(e, index, x, y)).into() } + // [26] Dach über beliebigem Grundriss: Eckpunkt bzw. Kante des Umrisses oder eines Hofs. Flacher Index: + // erst die Ecken von `outline`, danach die der `holes` Ring für Ring (wie die Kanten-Nummerierung + // von `edgePitchDeg`); eine Kante liegt immer in EINEM Ring. + "roofVertex" => { + let (index, (x, y)) = (r.n("index"), r.p("pt")); + patch("roofs", r.s("id"), &|e| { + if !(x.is_finite() && y.is_finite()) { + return None; + } + roof_ring_edit(e, index, None, &|ring, i| Some(replace_at(ring, i as f64, &pt(x, y)))) + }) + .into() + } + "roofEdge" => { + let (a, b, (dx, dy)) = (r.n("a"), r.n("b"), r.p("delta")); + patch("roofs", r.s("id"), &|e| { + if !(dx.is_finite() && dy.is_finite()) { + return None; + } + roof_ring_edit(e, a, Some(b), &|ring, i| move_polygon_edge(ring, i as f64, b - (a - i as f64), dx, dy, true)) + }) + .into() + } "stairBy" => { let (dx, dy) = r.p("delta"); patch("stairs", r.s("id"), &|s| { @@ -1158,6 +1181,36 @@ mod dormer_grip_tests { } } +/// [26] Ring (Umriss oder Hof) des Dachs, in dem der flache Index `a` (und ggf. `b`) liegt, durch `f` ersetzen. +/// `f` bekommt den Ring und den Index von `a` darin. Gesperrt, Index ausserhalb, `b` in anderem Ring → None. +fn roof_ring_edit(r: &Value, a: f64, b: Option, f: &dyn Fn(&[Value], usize) -> Option) -> Option { + if truthy(field(r, "locked")) { + return None; + } + let outline = field(r, "outline")?.as_array()?; + let holes: Vec<&Vec> = arr(field(r, "holes")).iter().filter_map(|h| h.as_array()).collect(); + let mut off = 0usize; + for ring_no in 0..=holes.len() { + let ring: &[Value] = if ring_no == 0 { outline } else { holes[ring_no - 1] }; + let in_ring = |i: f64| index_in(i - off as f64, ring.len()); + if let Some(i) = in_ring(a) { + if let Some(b) = b { + in_ring(b)?; + } + let new = f(ring, i)?; + return Some(if ring_no == 0 { + with(r, "outline", new) + } else { + let mut hs: Vec = arr(field(r, "holes")).to_vec(); + hs[ring_no - 1] = new; + with(r, "holes", Value::Array(hs)) + }); + } + off += ring.len(); + } + None +} + /// Dach-Eckgriff: die gegenüberliegende Ecke bleibt fix, der Umriss bleibt ein achsparalleles Rechteck. fn roof_grip(r: &Value, index: f64, x: f64, y: f64) -> Option { if index >= DORMER_GRIP_BASE { @@ -1653,6 +1706,35 @@ mod tests { assert_eq!(e["outline"][2], json!({"x": 4, "y": 4})); } + /// [26] Dach: Ecken und Kanten von Umriss und Hof über den flachen Index; schiefer Umriss bleibt schief. + #[test] + fn dach_griffe_umriss_und_hof() { + let roof = json!({"id": "R", "type": "roof", "floorId": "F", "categoryCode": "35", "shape": "walm", + "outline": [{"x": 0, "y": 0}, {"x": 10, "y": 0}, {"x": 12, "y": 8}, {"x": 0, "y": 8}], + "holes": [[{"x": 3, "y": 2}, {"x": 5, "y": 2}, {"x": 5, "y": 4}, {"x": 3, "y": 4}]]}); + let r = root(json!({"roofs": [roof]})); + let ent = |v: Value| run(&Lookup::plain(&r), &rq(v)).unwrap().ops.first().map(|o| o.to_json()["entity"].clone()); + // Umriss-Ecke 2 ziehen: übrige Ecken (kein Rechteck erzwungen) und Höfe bleiben. + let e = ent(json!({"op": "roofVertex", "id": "R", "index": 2, "pt": [13, 9]})).unwrap(); + assert_eq!(e["outline"][2], json!({"x": 13, "y": 9})); + assert_eq!(e["outline"][1], json!({"x": 10, "y": 0})); + assert_eq!(e["holes"][0][0], json!({"x": 3, "y": 2})); + // Hof-Ecke: flacher Index 4 + 2 = Ecke 2 des Hofs. + let e = ent(json!({"op": "roofVertex", "id": "R", "index": 6, "pt": [6, 5]})).unwrap(); + assert_eq!(e["holes"][0][2], json!({"x": 6, "y": 5})); + assert_eq!(e["outline"].as_array().unwrap().len(), 4); + // Hof-Kante 4–5 (Hof-Ecken 0–1) um 1 nach oben. + let e = ent(json!({"op": "roofEdge", "id": "R", "a": 4, "b": 5, "delta": [0, 1]})).unwrap(); + assert_eq!((e["holes"][0][0]["y"].as_f64(), e["holes"][0][1]["y"].as_f64()), (Some(3.0), Some(3.0))); + // Umriss-Kante 3–0 (Schlusskante, Westwand) um 1 nach aussen. + let e = ent(json!({"op": "roofEdge", "id": "R", "a": 3, "b": 0, "delta": [-1, 0]})).unwrap(); + assert_eq!((e["outline"][3]["x"].as_f64(), e["outline"][0]["x"].as_f64()), (Some(-1.0), Some(-1.0))); + // Kante über zwei Ringe, Index ausserhalb, NaN: kein Op. + assert!(ent(json!({"op": "roofEdge", "id": "R", "a": 3, "b": 4, "delta": [0, 1]})).is_none()); + assert!(ent(json!({"op": "roofVertex", "id": "R", "index": 8, "pt": [0, 0]})).is_none()); + assert!(ent(json!({"op": "roofVertex", "id": "R", "index": -1, "pt": [0, 0]})).is_none()); + } + /// [176] Schnittlinie: Endpunkte und Knickpunkte als Griffe. #[test] fn schnittlinie_griffe() { diff --git a/src/geometry/grips.ts b/src/geometry/grips.ts index 6118607d..503f13ec 100644 --- a/src/geometry/grips.ts +++ b/src/geometry/grips.ts @@ -29,6 +29,9 @@ export type GripRequest = | { op: "roomStamp"; id: string; delta: P; pt?: P } | { op: "ceilingEdge" | "roomEdge"; id: string; a: number; b: number; delta: P } | { op: "excavationGrip"; id: string; index: number; pt: P } + // [26] Dach: Ecke bzw. Kante von Umriss/Hof, flacher Index (erst `outline`, dann `holes` Ring für Ring). + | { op: "roofVertex"; id: string; index: number; pt: P } + | { op: "roofEdge"; id: string; a: number; b: number; delta: P } // [176] Schnittlinie: 0 = Anfang, dann `bendPoints`, zuletzt das Ende. | { op: "sectionLineGrip"; id: string; index: number; pt: P } | { op: "sectionBendInsert"; id: string; seg: number; pt: P } diff --git a/src/state/projectSlice.ts b/src/state/projectSlice.ts index 61ea7a2f..b0f0160b 100644 --- a/src/state/projectSlice.ts +++ b/src/state/projectSlice.ts @@ -439,6 +439,10 @@ export interface ProjectSlice { moveRoofGrip: (roofId: string, index: number, pt: import("../model/types").Vec2) => void; /** Dach als Ganzes um `delta` verschieben (Verschiebe-Griff). */ moveRoofBy: (roofId: string, delta: import("../model/types").Vec2) => void; + /** [26] Dach-Ecke von Umriss bzw. Hof (flacher Index: `outline`, dann `holes`) auf `pt`; Umriss bleibt frei. */ + moveRoofVertex: (roofId: string, index: number, pt: import("../model/types").Vec2) => void; + /** [26] Dach-Kante von Umriss bzw. Hof (flache Eck-Indizes) um `delta` verschieben. */ + moveRoofEdge: (roofId: string, aIndex: number, bIndex: number, delta: import("../model/types").Vec2) => void; // ── Treppen-Editieren ────────────────────────────────────────────────────── /** Verschiebt eine Treppe (Antritt) um `delta`. */ @@ -1295,6 +1299,10 @@ export function createProjectSlice( // Dach als Ganzes verschieben (Verschiebe-Griff). moveRoofBy: (roofId, delta) => applyGrip({ op: "roofBy", id: roofId, delta: gripPt(delta) }, `moveRoofBy:${roofId}`), + moveRoofVertex: (roofId, index, pt) => + applyGrip({ op: "roofVertex", id: roofId, index, pt: gripPt(pt) }, `moveRoofVertex:${roofId}:${index}`), + moveRoofEdge: (roofId, aIndex, bIndex, delta) => + applyGrip({ op: "roofEdge", id: roofId, a: aIndex, b: bIndex, delta: gripPt(delta) }, `moveRoofEdge:${roofId}:${aIndex}:${bIndex}`), // ── Treppen-Editieren ────────────────────────────────────────────────── // (coalesceKey: siehe Kommentar bei moveGripOf.) diff --git a/src/state/roofPlanGrips.test.ts b/src/state/roofPlanGrips.test.ts new file mode 100644 index 00000000..348df6e2 --- /dev/null +++ b/src/state/roofPlanGrips.test.ts @@ -0,0 +1,76 @@ +// [26] Dach-Griffe im Grundriss: Ecke und Kante von Umriss bzw. Hof über die Store-Aktionen +// (flacher Index: erst `outline`, dann `holes`). Der Umriss bleibt frei (kein Rechteck), ein Zug = ein Undo-Schritt. +import { beforeEach, describe, expect, it } from "vitest"; +import { getState, setState } from "./appStore"; +import type { Project, Roof } from "../model/types"; + +const roof: Roof = { + id: "RF1", + type: "roof", + floorId: "eg", + categoryCode: "31", + outline: [ + { x: 0, y: 0 }, + { x: 10, y: 0 }, + { x: 12, y: 8 }, + { x: 0, y: 8 }, + ], + holes: [ + [ + { x: 3, y: 2 }, + { x: 5, y: 2 }, + { x: 5, y: 4 }, + { x: 3, y: 4 }, + ], + ], + shape: "walm", + pitchDeg: 35, + overhang: 0, + ridgeAxis: "x", + thickness: 0.2, +}; + +const baseProject = { + id: "p", + name: "T", + layers: [], + drawingLevels: [{ id: "eg", name: "EG", kind: "floor", visible: true, locked: false, floorHeight: 2.6, baseElevation: 0 }], + walls: [], + drawings2d: [], + roofs: [roof], +} as unknown as Project; + +const current = (): Roof => getState().project.roofs![0]; + +beforeEach(() => { + setState({ project: JSON.parse(JSON.stringify(baseProject)), undoDepth: 0, redoDepth: 0, canUndo: false, canRedo: false }); + getState().clearHistory(); +}); + +describe("Dach-Griffe im Grundriss", () => { + it("Umriss-Ecke ziehen: nur diese Ecke wandert, ein Undo-Schritt", () => { + getState().moveRoofVertex("RF1", 2, { x: 13, y: 9 }); + expect(current().outline[2]).toEqual({ x: 13, y: 9 }); + expect(current().outline[1]).toEqual({ x: 10, y: 0 }); + expect(current().holes).toEqual(roof.holes); + expect(getState().undoDepth).toBe(1); + getState().undo(); + expect(current().outline).toEqual(roof.outline); + }); + + it("Hof-Ecke und Hof-Kante über den flachen Index", () => { + getState().moveRoofVertex("RF1", 6, { x: 6, y: 5 }); + expect(current().holes![0][2]).toEqual({ x: 6, y: 5 }); + getState().moveRoofEdge("RF1", 4, 5, { x: 0, y: -1 }); + expect(current().holes![0][0].y).toBe(1); + expect(current().holes![0][1].y).toBe(1); + expect(current().outline).toEqual(roof.outline); + }); + + it("Kante über zwei Ringe oder ausserhalb: keine Änderung", () => { + getState().moveRoofEdge("RF1", 3, 4, { x: 0, y: 1 }); + getState().moveRoofVertex("RF1", 99, { x: 0, y: 0 }); + expect(current()).toEqual(roof); + expect(getState().undoDepth).toBe(0); + }); +}); diff --git a/src/state/useGripEditing.ts b/src/state/useGripEditing.ts index cdef7fe1..a457368e 100644 --- a/src/state/useGripEditing.ts +++ b/src/state/useGripEditing.ts @@ -8,7 +8,7 @@ import { useRef, useState, type RefObject } from "react"; import { useEventBundle, useSameData } from "./useEvent"; import { leftNormal, normalize, scale, sub, wallCorners } from "../model/geometry"; -import type { Ceiling, Drawing2D, EdgeGrip, Excavation, Project, Room, Vec2, Wall } from "../model/types"; +import type { Ceiling, Drawing2D, EdgeGrip, Excavation, Project, Roof, Room, Vec2, Wall } from "../model/types"; import { wallTypeThickness } from "../model/types"; import { bulgeArcPoints, drawingVertices, surfaceOpeningGripPatch, surfaceOpeningGrips, surfaceOpeningInfo, wallArcBand } from "../core"; import { gripDrawingIdsFor } from "./gripLimits"; @@ -71,6 +71,8 @@ export function useGripEditing(opts: { selectedCeiling: Ceiling | null; /** [68] Einzeln gewählte Baugrube (Umriss-Ecken, Kanten, Sohlenhöhe als Griffe). */ selectedExcavation?: Excavation | null; + /** [26] Einzeln gewähltes Dach: Ecken und Kanten von Umriss und Höfen als Griffe. */ + selectedRoof?: Roof | null; selectedRoom: Room | null; /** Die Auswahl ([130]); Einzel-Elemente daraus wie in `useSelectionState`. */ selection: Selection; @@ -111,6 +113,9 @@ export function useGripEditing(opts: { moveCeilingGrip: (id: string, index: number, pt: Vec2) => void; moveExcavationGrip: (id: string, index: number, pt: Vec2) => void; moveExcavationEdge: (id: string, aIndex: number, bIndex: number, delta: Vec2) => void; + /** [26] Dach: Ecke bzw. Kante von Umriss/Hof (flacher Index: erst `outline`, dann `holes` Ring für Ring). */ + moveRoofVertex?: (id: string, index: number, pt: Vec2) => void; + moveRoofEdge?: (id: string, aIndex: number, bIndex: number, delta: Vec2) => void; moveGripOf: ( drawingId: string | null, wallId: string | null, @@ -143,6 +148,7 @@ export function useGripEditing(opts: { selectedDrawing, selectedCeiling, selectedExcavation = null, + selectedRoof = null, selectedRoom, selection, levelId, @@ -228,6 +234,20 @@ export function useGripEditing(opts: { ? selectedDrawingIds : selectedDrawingIds.filter((id) => project.drawings2d.find((x) => x.id === id)?.levelId === levelId); + // [26] Dach-Griffe: nur bei einzeln gewähltem, nicht gesperrtem Dach und ohne andere Griff-Träger in der Auswahl. + const roofGripsOn = + modelEditable && !!selectedRoof && !selectedRoof.locked && !!opts.moveRoofVertex && !selectedCeiling && !selectedRoom && + !selectedExcavation && !selectedTree && !selectedSectionLine && effectiveDrawingIds.length === 0 && selectedWallIds.length === 0; + /** Ringe des Dachs in der Reihenfolge des flachen Index (Umriss, dann Höfe) samt Start-Index. */ + const roofRings = (r: Roof): { pts: Vec2[]; off: number }[] => { + let off = 0; + return [r.outline, ...(r.holes ?? [])].map((pts) => { + const ring = { pts, off }; + off += pts.length; + return ring; + }); + }; + // Griff-Grenzen (s. gripLimits.ts): grosse Mehrfachauswahlen ohne Griffe, ein einzeln gewähltes // Element immer mit Griffen (Kataster-Parzellen mit tausenden Stützpunkten). // [137] Gewählte Gruppe: keine Mitglieds-Griffe (Vectorworks: erst die Gruppe betreten) — ein Ziehen am @@ -338,6 +358,14 @@ export function useGripEditing(opts: { pts.forEach((_, i) => { gripOwners.push({ localIndex: i }); gripOwnerRange.push(i < nCorner ? [0, nCorner - 1] : [nCorner, pts.length - 1]); }); return pts; } + // [26] Dach: Ecken von Umriss und Höfen (flacher Index, Besitzer-Bereich = der eigene Ring). + if (roofGripsOn && selectedRoof) { + const out: Vec2[] = []; + for (const { pts, off } of roofRings(selectedRoof)) { + pts.forEach((q, i) => { out.push(q); gripOwners.push({ localIndex: off + i }); gripOwnerRange.push([off, off + pts.length - 1]); }); + } + return out; + } // [68] Baugrube: Umriss-Ecken + Sohlen-Griff (Lage: Schwerpunkt, y um die Sohlenhöhe versetzt). if (modelEditable && selectedExcavation && !selectedCeiling && effectiveDrawingIds.length === 0 && selectedWallIds.length === 0) { const pts = excavationGripPoints(selectedExcavation); @@ -470,6 +498,12 @@ export function useGripEditing(opts: { // Verschieben EINER Kante einer komplexen Polylinie, §Task B). const edgeGrips: EdgeGrip[] = (() => { // ringEdges/openEdges/polylineEdgeGrips: Kern (`geometry/grips.ts`, `grips.rs`). + // [26] Dach: Kanten von Umriss und Höfen, Indizes im flachen Ecken-Index. + if (roofGripsOn && selectedRoof) { + return roofRings(selectedRoof).flatMap(({ pts, off }) => + ringEdges(pts, {}).map((e) => ({ ...e, aIndex: e.aIndex + off, bIndex: e.bIndex + off })), + ); + } if (modelEditable && selectedExcavation && !selectedCeiling && effectiveDrawingIds.length === 0 && selectedWallIds.length === 0) { return ringEdges(selectedExcavation.outline, {}); } @@ -592,7 +626,7 @@ export function useGripEditing(opts: { // Dasselbe für das Verschieben eines ganzen 2D-Elements (Gesamt-Delta) und für // Kanten-Griffe von Polylinien (Ziel-Delta): bis zum Loslassen nur Vorschau. const pendingWallGripRef = useRef<{ wallId: string; localIndex: number; flat: number; pt: Vec2; arcLength?: number } | null>(null); - const pendingAreaGripRef = useRef<{ kind: "room" | "ceiling" | "excavation"; id: string; index: number; flat: number; pt: Vec2 } | null>(null); + const pendingAreaGripRef = useRef<{ kind: "room" | "ceiling" | "excavation" | "roof"; id: string; index: number; flat: number; pt: Vec2 } | null>(null); const pendingAreaMoveRef = useRef<{ kind: "ceiling" | "room" | "stair"; id: string; total: Vec2 } | null>(null); const pendingWallMoveRef = useRef<{ wallId: string; total: Vec2 } | null>(null); /** Aufgeschobene Öffnungs-Verschiebung im Schnitt/in der Ansicht (neue `position`). */ @@ -682,6 +716,10 @@ export function useGripEditing(opts: { // Wand/Öffnung/Treppe haben keine Polygon-Nachbarn → null. const resolvePolygonRing = (index: number): { pts: Vec2[]; index: number; closed: boolean } | null => { const owner = gripOwners[index]; + if (roofGripsOn && selectedRoof && !owner?.drawingId && !owner?.wallId) { + const ring = roofRings(selectedRoof).find((rg) => index >= rg.off && index < rg.off + rg.pts.length); + return ring ? { pts: ring.pts, index: index - ring.off, closed: true } : null; + } if (!owner?.drawingId && !owner?.wallId) { // Raum/Decke (exklusiv) — kein Owner, `localIndex` fehlt dann auch, also // ist der flache `index` selbst der Ring-Index. @@ -957,6 +995,11 @@ export function useGripEditing(opts: { } return; } + // [26] Dach: Ecke von Umriss/Hof als Vorschau, ein Undo-Schritt beim Setzen. + if (roofGripsOn && selectedRoof) { + pendingAreaGripRef.current = { kind: "roof", id: selectedRoof.id, index, flat: index, pt }; + return; + } // [68] Baugrube: Sohlen-Griff sofort (Höhe), Ecken als Vorschau bis zum Setzen. if (selectedExcavation && !selectedCeilingId && !selectedRoomId) { if (index >= selectedExcavation.outline.length) moveExcavationGrip(selectedExcavation.id, index, pt); @@ -1002,6 +1045,13 @@ export function useGripEditing(opts: { /** Vorschau-Form des ausstehenden Eckpunkt-Zugs (leer, wenn keiner läuft). */ const gripPreviewShapes = (): DraftShape[] => { const pa = pendingAreaGripRef.current; + if (pa?.kind === "roof" && selectedRoof) { + return roofRings(selectedRoof).map(({ pts, off }) => ({ + kind: "poly" as const, + pts: pts.map((q, i) => (off + i === pa.index ? pa.pt : q)), + closed: true, + })); + } if (pa) { const ring = pa.kind === "room" @@ -1060,6 +1110,7 @@ export function useGripEditing(opts: { if (pa) { if (pa.kind === "room") moveRoomGrip(pa.id, pa.index, pa.pt); else if (pa.kind === "excavation") moveExcavationGrip(pa.id, pa.index, pa.pt); + else if (pa.kind === "roof") opts.moveRoofVertex?.(pa.id, pa.index, pa.pt); else moveCeilingGrip(pa.id, pa.index, pa.pt); } const pw = pendingWallGripRef.current; @@ -1139,7 +1190,8 @@ export function useGripEditing(opts: { applyEdge(pend.edge, pend.delta); }; const applyEdge = (edge: EdgeGrip, delta: Vec2) => { - if (selectedExcavation && !selectedRoomId && !selectedCeilingId) moveExcavationEdge(selectedExcavation.id, edge.aIndex, edge.bIndex, delta); + if (roofGripsOn && selectedRoof) opts.moveRoofEdge?.(selectedRoof.id, edge.aIndex, edge.bIndex, delta); + else if (selectedExcavation && !selectedRoomId && !selectedCeilingId) moveExcavationEdge(selectedExcavation.id, edge.aIndex, edge.bIndex, delta); else if (selectedRoomId) moveRoomEdge(selectedRoomId, edge.aIndex, edge.bIndex, delta); else if (selectedCeilingId) moveCeilingEdge(selectedCeilingId, edge.aIndex, edge.bIndex, delta); else moveEdgeOf(edge.owner?.drawingId ?? selectedDrawingId, edge.owner?.wallId ?? selectedWallId, edge.aIndex, edge.bIndex, delta); @@ -1346,7 +1398,7 @@ export function useGripEditing(opts: { // das singuläre selectedDrawingId/selectedWallId) — von den eigenen // Snap-Kandidaten ausschließen (sonst fängt der Punkt an sich selbst). const owner = gripOwners[index]; - const snapSkip = selectedRoomId || selectedCeilingId || owner?.drawingId || owner?.wallId; + const snapSkip = selectedRoomId || selectedCeilingId || (roofGripsOn ? selectedRoof?.id : null) || owner?.drawingId || owner?.wallId; const excludeIds = snapSkip ? [snapSkip] : []; // Bezugspunkt für Shift-Ortho: ein Nachbar-Griff DESSELBEN Elements // (festes Ende), relativ zu dem die Bewegung auf H/V eingerastet wird. diff --git a/src/state/useGripInputs.ts b/src/state/useGripInputs.ts index 3561332f..d2311da0 100644 --- a/src/state/useGripInputs.ts +++ b/src/state/useGripInputs.ts @@ -43,6 +43,11 @@ export function useGripInputs(opts: { const o = (project.context ?? []).find((c) => c.id === selection.contextObjects[0]); return o && o.type === "excavation" ? o : null; }, [project.context, selection.contextObjects]); + // [26] Genau ein gewähltes Dach (Ecken-/Kanten-Griffe von Umriss und Höfen). + const selectedRoof = useMemo(() => { + if (selection.roofs.length !== 1) return null; + return (project.roofs ?? []).find((r) => r.id === selection.roofs[0]) ?? null; + }, [project.roofs, selection.roofs]); const selectedRoom = useMemo( () => (project.rooms ?? []).find((r) => r.id === selectedRoomId) ?? null, [project.rooms, selectedRoomId], @@ -89,5 +94,5 @@ export function useGripInputs(opts: { }); }; - return { selectedDrawing, selectedCeiling, selectedExcavation, selectedRoom, roomStamp, sectionSheet, snapFor }; + return { selectedDrawing, selectedCeiling, selectedExcavation, selectedRoof, selectedRoom, roomStamp, sectionSheet, snapFor }; } diff --git a/src/state/useProjectActions.ts b/src/state/useProjectActions.ts index 11ea6490..a34c5abf 100644 --- a/src/state/useProjectActions.ts +++ b/src/state/useProjectActions.ts @@ -376,6 +376,8 @@ export function useProjectActions( const moveCeilingGrip = useStore((s) => s.moveCeilingGrip); const moveExcavationGrip = useStore((s) => s.moveExcavationGrip); const moveExcavationEdge = useStore((s) => s.moveExcavationEdge); + const moveRoofVertex = useStore((s) => s.moveRoofVertex); + const moveRoofEdge = useStore((s) => s.moveRoofEdge); const moveCeilingBy = useStore((s) => s.moveCeilingBy); const moveCeilingEdge = useStore((s) => s.moveCeilingEdge); const updateCeiling = useStore((s) => s.updateCeiling); @@ -496,6 +498,8 @@ export function useProjectActions( moveCeilingGrip, moveExcavationGrip, moveExcavationEdge, + moveRoofVertex, + moveRoofEdge, moveCeilingBy, moveCeilingEdge, updateCeiling, diff --git a/src/styles.css b/src/styles.css index 88a8cdb3..91fc0ff3 100644 --- a/src/styles.css +++ b/src/styles.css @@ -2342,6 +2342,15 @@ body { nach außen. Gleiche papierfarbene + Akzent-Ring-Sprache wie die Eckpunkt- Griffe, nur mit runden statt spitzen Ecken (stroke-linejoin überstimmt die globale Miter-Regel für Plan-Polygone via höherer Selektor-Spezifität). */ +/* [26] Kante unter dem Kanten-Anfasser hervorgehoben. */ +.plan-svg .plan-edge-hover { + stroke: var(--accent); + stroke-width: 3.5; + stroke-linecap: round; + opacity: 0.85; + vector-effect: non-scaling-stroke; +} + .plan-svg .plan-edge-grip { fill: var(--sheet); stroke: var(--accent); diff --git a/src/views/ViewportCenter.tsx b/src/views/ViewportCenter.tsx index 9db75a28..2baad3af 100644 --- a/src/views/ViewportCenter.tsx +++ b/src/views/ViewportCenter.tsx @@ -103,7 +103,7 @@ export function ViewportCenter(props: { const project = useStore((s) => s.project); // ── Einzeln gewählte Elemente, Blatt, Fang für die Griffe → state/useGripInputs.ts ── - const { selectedDrawing, selectedCeiling, selectedExcavation, selectedRoom, roomStamp, sectionSheet, snapFor } = useGripInputs({ + const { selectedDrawing, selectedCeiling, selectedExcavation, selectedRoof, selectedRoom, roomStamp, sectionSheet, snapFor } = useGripInputs({ project, activeLevel, selection, @@ -121,6 +121,7 @@ export function ViewportCenter(props: { selectedDrawing, selectedCeiling, selectedExcavation, + selectedRoof, selectedRoom, selection, levelId: activeLevel.id, @@ -142,6 +143,8 @@ export function ViewportCenter(props: { moveCeilingGrip: pa.moveCeilingGrip, moveExcavationGrip: pa.moveExcavationGrip, moveExcavationEdge: pa.moveExcavationEdge, + moveRoofVertex: pa.moveRoofVertex, + moveRoofEdge: pa.moveRoofEdge, moveGripOf: pa.moveGripOf, moveRoomEdge: pa.moveRoomEdge, moveCeilingEdge: pa.moveCeilingEdge, diff --git a/src/views/plan/PlanView.tsx b/src/views/plan/PlanView.tsx index 1f365b1e..891b361e 100644 --- a/src/views/plan/PlanView.tsx +++ b/src/views/plan/PlanView.tsx @@ -9,7 +9,7 @@ import { forwardRef, useEffect, useMemo, useState } from "react"; import type { ComponentProps, CSSProperties } from "react"; import type { PlanImage, Primitive } from "../../core"; import { planLineEndsProps } from "../../core"; -import type { Vec2 } from "../../model/types"; +import type { EdgeGrip, Vec2 } from "../../model/types"; import { t } from "../../i18n"; import { docFromText } from "../../text/richText"; import { contentFontBaselineFromTop, TEXT_LINE_HEIGHT_MULT } from "../../text/fontMetrics"; @@ -173,6 +173,9 @@ export const PlanView = forwardRef( // Aktueller Ausschnitt; treibt die viewBox des SVG. Initial = eingepasst. const [view, setView] = useState(defaultView); + // [26] Kante unter dem Cursor (Kanten-Anfasser); gezeichnet wird sie nur für Flächen-Elemente + // (Dach, Decke, Raum, Baugrube), deren Kanten-Indizes Griff-Indizes sind. + const [hoverEdge, setHoverEdge] = useState(null); // Ausschnitt NUR bei Plan-/Geschoss-Wechsel (resetKey) auf „eingepasst" // zurücksetzen — NICHT bei jeder Bounds-Änderung durch Editieren (sonst // „wandert" die Ansicht beim Verschieben/Löschen mit). `defaultView` ist beim @@ -362,6 +365,7 @@ export const PlanView = forwardRef( grips, edgeGripsActive, edgeGripAt, + onHoverEdge: (e) => setHoverEdge((h) => (h?.aIndex === e?.aIndex && h?.bIndex === e?.bIndex && h?.owner === e?.owner ? h : e)), grabbedBody, moveDrag, marquee, @@ -1150,6 +1154,16 @@ export const PlanView = forwardRef( AUSSEN entlang der (bildschirm-transformierten) Normale versetzt, mit der Spitze nach außen. Y wird gespiegelt (toScreen spiegelt Y), damit das Dreieck wirklich nach außen zeigt. Größe bildschirmkonstant. */} + {edgeGripsActive && hoverEdge && !hoverEdge.owner?.drawingId && !hoverEdge.owner?.wallId && grips?.[hoverEdge.aIndex] && grips[hoverEdge.bIndex] && ( + + )} {edgeGripsActive && ( {(s) => diff --git a/src/views/plan/planView/usePlanPointer.ts b/src/views/plan/planView/usePlanPointer.ts index 67bd04fb..73cafe03 100644 --- a/src/views/plan/planView/usePlanPointer.ts +++ b/src/views/plan/planView/usePlanPointer.ts @@ -46,6 +46,8 @@ export interface UsePlanPointerArgs { grips: Vec2[] | undefined; edgeGripsActive: boolean; edgeGripAt: (clientX: number, clientY: number) => EdgeGrip | null; + /** [26] Kante unter dem Cursor (Kanten-Anfasser) im Ruhezustand — die Plan-Ansicht hebt sie hervor. */ + onHoverEdge?: (edge: EdgeGrip | null) => void; grabbedBody: (clientX: number, clientY: number) => BodyTarget | null; moveDrag: React.MutableRefObject<{ pointerId: number; last: Vec2; startX?: number; startY?: number; target: BodyTarget; } | null>; marquee: React.MutableRefObject<{ pointerId: number; startClientX: number; startClientY: number; startView: Vec2; moved: boolean; } | null>; @@ -110,6 +112,7 @@ export function usePlanPointer(inp: UsePlanPointerArgs) { grips, edgeGripsActive, edgeGripAt, + onHoverEdge, grabbedBody, moveDrag, marquee, @@ -546,6 +549,7 @@ export function usePlanPointer(inp: UsePlanPointerArgs) { // Echter Ruhezustand (kein Drag/Werkzeug/Marquee/Pan) — Hover- // Teilpunkte-Erkennung. updateHoverDivide(e.clientX, e.clientY); + onHoverEdge?.(edgeGripsActive ? edgeGripAt(e.clientX, e.clientY) : null); return; } const { scale } = measure(d.startView);