From 6bcaa02a696802ac8211ec7833c4256c84cea913 Mon Sep 17 00:00:00 2001 From: karim Date: Fri, 23 Oct 2026 01:04:12 +0200 Subject: [PATCH] =?UTF-8?q?Schnitt/Ansicht:=20Hoehen-Griffe=20(Wand-Oberka?= =?UTF-8?q?nte,=20Fenster=20Ober-/Unterkante)=20=E2=80=94=20Hoehe/Bruestun?= =?UTF-8?q?g=20direkt=20im=20Blatt=20anpassen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 1 + src/state/useGripEditing.ts | 107 +++++++++++++++++++++++++++++++++++- 2 files changed, 106 insertions(+), 2 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index a153005d..9a58c0e8 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1742,6 +1742,7 @@ export default function App() { engineRef, commandLineRef, updateOpening, + updateWall, moveStairBy, moveRoomGrip, moveCeilingGrip, diff --git a/src/state/useGripEditing.ts b/src/state/useGripEditing.ts index 4242722f..f9d4a6f4 100644 --- a/src/state/useGripEditing.ts +++ b/src/state/useGripEditing.ts @@ -67,6 +67,8 @@ export function useGripEditing(opts: { engineRef: RefObject; commandLineRef: RefObject; updateOpening: (id: string, patch: Record) => void; + /** Wand ändern (Höhen-Griff im Schnitt); `coalesceKey` fasst einen Zug zu EINEM Undo-Schritt. */ + updateWall: (id: string, patch: Partial, coalesceKey?: string) => void; moveStairBy: (id: string, delta: Vec2) => void; moveRoomGrip: (id: string, index: number, pt: Vec2) => void; moveCeilingGrip: (id: string, index: number, pt: Vec2) => void; @@ -114,6 +116,7 @@ export function useGripEditing(opts: { engineRef, commandLineRef, updateOpening, + updateWall, moveStairBy, moveRoomGrip, moveCeilingGrip, @@ -181,11 +184,67 @@ export function useGripEditing(opts: { return effectiveDrawingIds; })(); + // ── Höhen-Griffe im Schnitt/in der Ansicht ─────────────────────────────── + // Gewählte Wand: Griff an der Oberkante (ändert `height`). Gewähltes Fenster: Griffe + // an Ober- und Unterkante (Höhe bzw. Brüstung, Oberkante bleibt stehen); Tür nur oben. + // Alles in Blatt-Koordinaten (u, Höhe über ±0.00). Projekt erst beim Loslassen. + type SheetHeightGrip = { + kind: "wallTop" | "openingTop" | "openingBottom"; + id: string; + pt: Vec2; + u0: number; + u1: number; + base: number; + top: number; + bottom: number; + }; + const sheetHeightGrips: SheetHeightGrip[] = (() => { + if (modelEditable || !sheet) return []; + const bbox = (kind: "wall" | "opening", id: string) => { + const polys = sheetOwnerOutlines(sheet.levelId, kind, id); + if (polys.length === 0) return null; + let u0 = Infinity, u1 = -Infinity, v0 = Infinity, v1 = -Infinity; + for (const poly of polys) for (const q of poly) { + u0 = Math.min(u0, q.x); u1 = Math.max(u1, q.x); + v0 = Math.min(v0, q.y); v1 = Math.max(v1, q.y); + } + return { u0, u1, v0, v1 }; + }; + const floorBase = (floorId: string) => project.drawingLevels.find((l) => l.id === floorId)?.baseElevation ?? 0; + if (selectedOpeningId) { + const op = (project.openings ?? []).find((o) => o.id === selectedOpeningId); + const w = op && project.walls.find((x) => x.id === op.hostWallId); + const bb = op && bbox("opening", op.id); + if (!op || !w || !bb || op.locked) return []; + const base = floorBase(w.floorId); + const mid = (bb.u0 + bb.u1) / 2; + const out: SheetHeightGrip[] = [ + { kind: "openingTop", id: op.id, pt: { x: mid, y: bb.v1 }, u0: bb.u0, u1: bb.u1, base, top: bb.v1, bottom: bb.v0 }, + ]; + if (op.kind === "window") { + out.push({ kind: "openingBottom", id: op.id, pt: { x: mid, y: bb.v0 }, u0: bb.u0, u1: bb.u1, base, top: bb.v1, bottom: bb.v0 }); + } + return out; + } + if (selectedWallId && selectedWallIds.length <= 1) { + const w = project.walls.find((x) => x.id === selectedWallId); + const bb = w && bbox("wall", w.id); + if (!w || !bb || w.locked) return []; + return [ + { kind: "wallTop", id: w.id, pt: { x: (bb.u0 + bb.u1) / 2, y: bb.v1 }, u0: bb.u0, u1: bb.u1, base: floorBase(w.floorId), top: bb.v1, bottom: bb.v0 }, + ]; + } + return []; + })(); + const grips: Vec2[] = (() => { // Öffnung (Fenster/Tür): EIN Mittelpunkt-Griff auf der Wandachse. Ziehen // verschiebt die Öffnung entlang der Wirts-Wand (siehe applyGrip → // `position`). Nur bei genau einer selektierten Öffnung (Auswahl exklusiv). - if (!modelEditable && effectiveDrawingIds.length === 0) return []; + if (!modelEditable && effectiveDrawingIds.length === 0) { + sheetHeightGrips.forEach((_, i) => { gripOwners.push({ localIndex: i }); gripOwnerRange.push([0, sheetHeightGrips.length - 1]); }); + return sheetHeightGrips.map((g) => g.pt); + } if (selectedOpeningId && modelEditable) { const op = (project.openings ?? []).find((o) => o.id === selectedOpeningId); const w = op && project.walls.find((x) => x.id === op.hostWallId); @@ -500,6 +559,8 @@ export function useGripEditing(opts: { const pendingWallMoveRef = useRef<{ wallId: string; total: Vec2 } | null>(null); /** Aufgeschobene Öffnungs-Verschiebung im Schnitt/in der Ansicht (neue `position`). */ const pendingOpeningMoveRef = useRef<{ id: string; position: number } | null>(null); + /** Aufgeschobene Höhen-Änderung im Schnitt (Wand `height` bzw. Öffnung `height`/`sillHeight`). */ + const pendingSheetHeightRef = useRef<{ kind: "wall" | "opening"; id: string; patch: Record } | null>(null); /** Laufendes Blatt-Delta (u, Meter) eines Zugs im Schnitt (s. moveInSheet). */ const sheetDuRef = useRef<{ id: string; du: number } | null>(null); const pendingBodyRef = useRef<{ drawingId: string; total: Vec2 } | null>(null); @@ -939,6 +1000,12 @@ export function useGripEditing(opts: { /** Ausstehenden Zug jetzt in das Projekt schreiben (EINE Mutation). */ const commitPendingGrip = () => { + const ph = pendingSheetHeightRef.current; + pendingSheetHeightRef.current = null; + if (ph) { + if (ph.kind === "wall") updateWall(ph.id, ph.patch as Partial); + else updateOpening(ph.id, ph.patch); + } const pa = pendingAreaGripRef.current; pendingAreaGripRef.current = null; if (pa) { @@ -1176,6 +1243,40 @@ export function useGripEditing(opts: { const gripHandlers = { onGripMove: (index: number, raw: Vec2, pxPerMeter: number, mods: ToolMods) => { + // Schnitt/Ansicht: Höhen-Griff (Wand-Oberkante, Fenster Ober-/Unterkante). + if (!modelEditable && sheet) { + const g = sheetHeightGrips[index]; + if (!g) return; + const v = mods.ctrl ? raw.y : Math.round(raw.y * 100) / 100; // 1-cm-Raster, Strg = frei + let newTop = g.top; + let newBottom = g.bottom; + if (g.kind === "wallTop") { + newTop = Math.max(g.base + 0.3, v); + pendingSheetHeightRef.current = { kind: "wall", id: g.id, patch: { height: Math.round((newTop - g.base) * 1000) / 1000 } }; + } else if (g.kind === "openingTop") { + newTop = Math.max(g.bottom + 0.2, v); + pendingSheetHeightRef.current = { kind: "opening", id: g.id, patch: { height: Math.round((newTop - g.bottom) * 1000) / 1000 } }; + } else { + newBottom = Math.min(g.top - 0.2, Math.max(g.base, v)); + pendingSheetHeightRef.current = { + kind: "opening", + id: g.id, + patch: { sillHeight: Math.round((newBottom - g.base) * 1000) / 1000, height: Math.round((g.top - newBottom) * 1000) / 1000 }, + }; + } + const bottom = g.kind === "wallTop" ? g.bottom : newBottom; + setDraft({ + preview: [{ + kind: "poly", + pts: [{ x: g.u0, y: bottom }, { x: g.u1, y: bottom }, { x: g.u1, y: newTop }, { x: g.u0, y: newTop }], + closed: true, + }], + vertices: [], + snap: null, + hud: { at: { x: (g.u0 + g.u1) / 2, y: g.kind === "openingBottom" ? newBottom : newTop }, text: `${(newTop - bottom).toFixed(2)} m` }, + }); + return; + } // Erster Move-Event nach dem Grab (gripDragInfoRef noch leer): die // AKTUELLE — hier noch unveränderte — Position als Flucht-Bezugspunkt // verankern (s. Kommentar an gripOriginRef). @@ -1423,7 +1524,9 @@ export function useGripEditing(opts: { // danach wie onGripEnd aufräumen. onGripCancel: (index: number, origin: Vec2) => { // Ausstehender Zug: einfach verwerfen (das Projekt wurde nie verändert). - if (pendingGripRef.current || pendingWallGripRef.current || pendingAreaGripRef.current) { + if (pendingSheetHeightRef.current) { + pendingSheetHeightRef.current = null; + } else if (pendingGripRef.current || pendingWallGripRef.current || pendingAreaGripRef.current) { pendingGripRef.current = null; pendingWallGripRef.current = null; pendingAreaGripRef.current = null;