From 738b446be7317c319dd61605b33afef9d834bf30 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 4 Nov 2026 17:47:41 +0000 Subject: [PATCH] [130] Auswahl: ein Selection-Wert im Store statt 12 Felder, alle Leser/Schreiber umgestellt --- TODO.md | 8 + scripts/probe-edit-input.mjs | 6 +- src/App.tsx | 420 ++++--------------- src/panels/BcfPanel.tsx | 28 +- src/panels/ClashPanel.tsx | 6 +- src/panels/SitePanel.tsx | 4 +- src/panels/host.ts | 8 +- src/state/aiAccess.test.ts | 4 +- src/state/aiAccess.ts | 51 +-- src/state/contextObjectSelection.test.ts | 12 +- src/state/objectInfo.perf.test.ts | 2 +- src/state/panelOps.test.ts | 3 +- src/state/roofSelection.test.ts | 4 +- src/state/selection.ts | 15 + src/state/selectionInfo.contextImage.test.ts | 6 +- src/state/selectionInfo.test.ts | 14 +- src/state/selectionInfo.ts | 61 ++- src/state/selectionSlice.ts | 107 +---- src/state/useCommandEngineHost.ts | 94 +---- src/state/useGrip3dEditing.ts | 12 +- src/state/useGripEditing.ts | 39 +- src/state/useImportHandling.ts | 38 +- src/state/useKeyboardShortcuts.ts | 125 ++---- src/state/useMouseSelectionHandlers.ts | 342 ++++----------- src/state/usePanelHostBase.ts | 86 +--- src/state/useSelectionState.ts | 108 +---- src/views/plan/PlanView.tsx | 96 ++--- src/views/viewportContent.tsx | 195 ++------- 28 files changed, 425 insertions(+), 1469 deletions(-) diff --git a/TODO.md b/TODO.md index e4bda771..778c29bc 100644 --- a/TODO.md +++ b/TODO.md @@ -1169,6 +1169,14 @@ Prüfung des ganzen Programms (Rust-Kern, TS-Hülle, Build/Sicherheit), nur Code 4.11.: generische Fenster-Brücke `native/windowBridge.ts` (`useWindowBridgeHost`) für Einstellungen, Geschosse, Ebenen-Einstellungen und Kontext-Import (−110 Zeilen); Ressourcen-Fenster bleibt eigen (Teil-Änderungen, [121]). Nicht in der Tauri-App geprüft. + 4.11.: Auswahl als ein Wert: `state/selection.ts` (`Selection` mit 12 Arten, `mergeSelection` hält Referenzen + stabil, `clearKinds`, `single`, `toCommandSelection`/`toTransformSelection`, `toMembership`, `toIdLists`/`fromIdLists`, + vitest). Store: `selection` + `setSelection(patch)` + `clearSelection` statt 12 Felder/12 Setter; App, Maus-/ + Tastatur-/Befehls-/Griff-/Import-Hooks, BCF, Kollision, KI-Zugang, PlanView/viewportContent (eine `selection`-Prop + statt 13) und `deriveSelection(project, selection)` umgestellt; Objekt-Info-Typ heisst jetzt `SelectionInfo`; + SitePanel liest `s.selection.contextObjects` schmal. Verhalten unverändert (auch Eigenheiten: Geschosswechsel lässt + Kontext-Objekte gewählt, Schnitt hebt Kontext-Objekte nicht hervor, 3D-Klick auf 2D-Element wählt auch mit Shift nur + es). Offen: PlanView/useGrip3dEditing nutzen intern noch lokale `selected…Ids`-Namen; nicht in Tauri geprüft. 3.11. Lizenzteil erledigt: NOTICE ergänzt (OFL-Schriften, wgpu, Tauri, React, pdf.js, jsPDF, lcms, truck …), `src-tauri/deny.toml` + CI-Job `licenses` (check.yml, `cargo deny check licenses` je Crate). diff --git a/scripts/probe-edit-input.mjs b/scripts/probe-edit-input.mjs index 8498b72a..bbab5925 100644 --- a/scripts/probe-edit-input.mjs +++ b/scripts/probe-edit-input.mjs @@ -59,7 +59,7 @@ const wallEnds = () => p.evaluate(() => { if (!proj) return null; return proj.walls.map((w) => ({ id: w.id, start: w.start, end: w.end })); }); -const selectedWalls = () => p.evaluate(() => window.__store?.getState?.().selectedWallIds ?? []); +const selectedWalls = () => p.evaluate(() => window.__store?.getState?.().selection?.walls ?? []); const box = await planBox(); const cx = box.x + box.w / 2, cy = box.y + box.h / 2; @@ -144,8 +144,8 @@ console.log("(b) common corner:", stillJoined, "| wall1", moved); await clickTool("Auswahl"); await wait(120); // Genau Wand 2 selektieren (Store direkt — robuster als ein Pixel-Klick auf die // verschobene Geometrie). Testet (c) isoliert: Grip-Drag + Tab + Wert. -await p.evaluate((id) => window.__store.getState().setSelectedWallIds([id]), w2id); -await p.evaluate(() => window.__store.getState().setSelectedDrawingIds([])); +await p.evaluate((id) => window.__store.getState().setSelection({ walls: [id] }), w2id); +await p.evaluate(() => window.__store.getState().setSelection({ drawings: [] })); await wait(200); let gBefore = await grips(); console.log("(c) grips:", gBefore.length, "selected:", await selectedWalls()); diff --git a/src/App.tsx b/src/App.tsx index f4d80c20..5fb87100 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -119,6 +119,7 @@ import { setCursor } from "./state/cursorStore"; import { setLiveScale } from "./state/liveScaleStore"; import { useDrawingToolState } from "./state/useDrawingToolState"; import { useSelectionState } from "./state/useSelectionState"; +import { clearKinds, fromIdLists, hasTransformable, isEmpty, toIdLists, toMembership } from "./state/selection"; import { useGripEditing } from "./state/useGripEditing"; import { usePanelHostBase } from "./state/usePanelHostBase"; import { useDockDragState } from "./state/useDockDragState"; @@ -167,7 +168,7 @@ import { FloatingPanel } from "./panels/FloatingPanel"; import { DragOverlay } from "./panels/panelDrag"; import { hostWithMode, PanelHostProvider } from "./panels/host"; import { deriveSelection } from "./state/selectionInfo"; -import type { Selection } from "./state/selectionInfo"; +import type { SelectionInfo } from "./state/selectionInfo"; import { centroid as roomCentroid } from "./core"; import { docFromText, plainText, DEFAULT_PRESETS } from "./text/richText"; import type { RichTextDoc } from "./text/richText"; @@ -344,50 +345,22 @@ export default function App() { commitCopyCount, } = useDrawingToolState(project.wallTypes[0].id, project.lineStyles[0].id); - // ── Auswahl (Store-Slice) ───────────────────────────────────────────────── + // ── Auswahl (Store-Slice, ein `Selection`-Wert, [130]) ────────────────────── const { - selectedWallIds, - setSelectedWallIds, - selectedDrawingIds, - setSelectedDrawingIds, + selection, + setSelection, selectedDrawingId, - setSelectedDrawingId, elementClipboard, setElementClipboard, selectedWallId, - selectedCeilingIds, - setSelectedCeilingIds, selectedCeilingId, - selectedRoofIds, - setSelectedRoofIds, - selectedRoofId, - selectedSectionLineIds, - setSelectedSectionLineIds, selectedSectionLineId, section3dCutId, setSection3dCutId, updateRoof, moveRoofGrip, moveRoofBy, - selectedOpeningIds, - setSelectedOpeningIds, - selectedOpeningId, - selectedStairIds, - setSelectedStairIds, - selectedStairId, - selectedRoomIds, - setSelectedRoomIds, selectedRoomId, - selectedExtrudedSolidIds, - setSelectedExtrudedSolidIds, - selectedExtrudedSolidId, - selectedColumnIds, - setSelectedColumnIds, - selectedColumnId, - selectedContextObjectIds, - setSelectedContextObjectIds, - selectedGroupIds, - setSelectedGroupIds, groupPath, setGroupPath, } = useSelectionState(); @@ -417,16 +390,8 @@ export default function App() { // (Grundriss ↔ 3D) lässt die Auswahl bestehen — dieselbe wallId gilt in // beiden Ansichten; nur die offenen Overlays werden geschlossen. useEffect(() => { - setSelectedWallIds([]); - setSelectedDrawingId(null); - setSelectedCeilingIds([]); - setSelectedOpeningIds([]); - setSelectedStairIds([]); - setSelectedRoomIds([]); - setSelectedExtrudedSolidIds([]); - setSelectedColumnIds([]); - setSelectedRoofIds([]); - setSelectedSectionLineIds([]); + // Kontext-Objekte (projektweit) und Gruppen bleiben gewählt. + setSelection((s) => ({ ...clearKinds(), contextObjects: s.contextObjects })); setMenu(null); setEditor(null); }, [activeLevelId]); @@ -566,29 +531,7 @@ export default function App() { }; // ── Command-Engine (Rhino-artiges Befehlssystem) → state/useCommandEngineHost.ts ── - const selectionState = { - selectedWallIds, - selectedDrawingId, - selectedDrawingIds, - selectedExtrudedSolidId, - selectedColumnId, - selectedCeilingIds, - selectedRoofIds, - selectedStairIds, - selectedRoomIds, - groupPath, - setSelectedWallIds, - setSelectedCeilingIds, - setSelectedOpeningIds, - setSelectedStairIds, - setSelectedRoomIds, - setSelectedExtrudedSolidIds, - setSelectedColumnIds, - setSelectedRoofIds, - setSelectedContextObjectIds, - setSelectedSectionLineIds, - setSelectedDrawingId, - }; + const selectionState = { selection, groupPath, setSelection }; const { engineRef, engine, @@ -700,10 +643,10 @@ export default function App() { ); // [68] Genau eine gewählte Baugrube (Griffe für Umriss und Sohle). const selectedExcavation = useMemo(() => { - if (selectedContextObjectIds.length !== 1) return null; - const o = (project.context ?? []).find((c) => c.id === selectedContextObjectIds[0]); + if (selection.contextObjects.length !== 1) return null; + const o = (project.context ?? []).find((c) => c.id === selection.contextObjects[0]); return o && o.type === "excavation" ? o : null; - }, [project.context, selectedContextObjectIds]); + }, [project.context, selection.contextObjects]); const selectedRoom = useMemo( () => (project.rooms ?? []).find((r) => r.id === selectedRoomId) ?? null, [project.rooms, selectedRoomId], @@ -724,45 +667,22 @@ export default function App() { // Ob irgendeine löschbare Auswahl ansteht — geteilt zwischen dem Entf- // Tastatur-Handler unten und dem Menüpunkt „Bearbeiten > Löschen" (AppMenuBar). - const hasSelectionToDelete = () => - !!( - selectedSectionLineIds.length || - selectedDrawingIds.length || - selectedWallIds.length || - selectedCeilingIds.length || - selectedOpeningIds.length || - selectedStairIds.length || - selectedRoomIds.length || - selectedExtrudedSolidIds.length || - selectedColumnIds.length || - selectedRoofIds.length || - selectedContextObjectIds.length - ); + const hasSelectionToDelete = () => !isEmpty(selection, { withGroups: false }); // Löscht die AKTUELLE Auswahl (alle Kanäle) — geteilte Logik zwischen dem // Entf-Tastatur-Handler und dem Menüpunkt „Bearbeiten > Löschen". const deleteSelection = () => { // Ein Undo-Schritt für alles (Schnittlinien + Elemente), [K4] S3. groupChanges(() => deleteSelectionChanges()); - setSelectedDrawingIds([]); - setSelectedWallIds([]); - setSelectedCeilingIds([]); - setSelectedOpeningIds([]); - setSelectedStairIds([]); - setSelectedRoomIds([]); - setSelectedExtrudedSolidIds([]); - setSelectedColumnIds([]); - setSelectedRoofIds([]); - setSelectedContextObjectIds([]); - setSelectedSectionLineIds([]); + setSelection(clearKinds()); }; const deleteSelectionChanges = () => { // Schnittlinie(n): Entf löscht NUR ihre Linie (linePoints), die Ebene // bleibt — ADDITIV zu den übrigen Kanälen unten (nicht mehr exklusiv: // seit Cmd/Ctrl+A Schnittlinien zusammen mit Wänden/etc. mitselektiert, // würde ein frühes `return` hier die übrigen Kanäle stumm überspringen). - if (selectedSectionLineIds.length) { - for (const id of selectedSectionLineIds) patchLevel(id, { linePoints: undefined }); + if (selection.sectionLines.length) { + for (const id of selection.sectionLines) patchLevel(id, { linePoints: undefined }); } // Objekt-Sperre: gesperrte Elemente aus der Löschung ausnehmen (s. // `moveGrip`/`moveElementBy` im Kern, `grips.rs`, für dieselbe Prüfung @@ -770,16 +690,16 @@ export default function App() { // (s. deren Typdefinitionen) — bleiben ungefiltert. const notLocked = (kind: MemberKind, ids: string[]) => ids.filter((id) => !isLocked(project, kind, id)); - const dids = new Set(notLocked("drawingIds", selectedDrawingIds)); - const wids = new Set(notLocked("wallIds", selectedWallIds)); - const cids = new Set(notLocked("ceilingIds", selectedCeilingIds)); - const oids = new Set(notLocked("openingIds", selectedOpeningIds)); - const stids = new Set(notLocked("stairIds", selectedStairIds)); - const rmids = new Set(notLocked("roomIds", selectedRoomIds)); - const exids = new Set(selectedExtrudedSolidIds); - const colids = new Set(notLocked("columnIds", selectedColumnIds)); - const rfids = new Set(notLocked("roofIds", selectedRoofIds)); - const ctxids = new Set(selectedContextObjectIds); + const dids = new Set(notLocked("drawingIds", selection.drawings)); + const wids = new Set(notLocked("wallIds", selection.walls)); + const cids = new Set(notLocked("ceilingIds", selection.ceilings)); + const oids = new Set(notLocked("openingIds", selection.openings)); + const stids = new Set(notLocked("stairIds", selection.stairs)); + const rmids = new Set(notLocked("roomIds", selection.rooms)); + const exids = new Set(selection.solids); + const colids = new Set(notLocked("columnIds", selection.columns)); + const rfids = new Set(notLocked("roofIds", selection.roofs)); + const ctxids = new Set(selection.contextObjects); setProject( opsMutation((p) => [ ...removeItems(p, "drawings2d", dids), @@ -805,28 +725,8 @@ export default function App() { project, activeLevelId: activeLevel.id, shortcutOverrides, - selectedDrawingIds, - selectedWallIds, - selectedCeilingIds, - selectedOpeningIds, - selectedStairIds, - selectedRoomIds, - selectedExtrudedSolidIds, - selectedColumnIds, - selectedRoofIds, - selectedContextObjectIds, - selectedSectionLineIds, - setSelectedWallIds, - setSelectedDrawingIds, - setSelectedCeilingIds, - setSelectedOpeningIds, - setSelectedStairIds, - setSelectedRoomIds, - setSelectedExtrudedSolidIds, - setSelectedColumnIds, - setSelectedRoofIds, - setSelectedContextObjectIds, - setSelectedSectionLineIds, + selection, + setSelection, hasSelectionToDelete, deleteSelection, }); @@ -842,20 +742,12 @@ export default function App() { newIds = r.selectIds; return r.ops; }); - setSelectedDrawingIds(newIds); - setSelectedWallIds([]); + setSelection({ drawings: newIds, walls: [] }); }; // Ctrl/Cmd+S = Split, Ctrl/Cmd+J = Join der selektierten Drawing2D-Elemente — // siehe state/useKeyboardShortcuts.ts. - useSplitJoinShortcut( - selectedDrawingIds, - engine, - runSplit, - setSelectedDrawingIds, - setSelectedWallIds, - shortcutOverrides, - ); + useSplitJoinShortcut(selection.drawings, engine, runSplit, setSelection, shortcutOverrides); // Ctrl/Cmd+Shift+U/D/I = Boolean Vereinigung/Subtraktion/Schnitt — siehe // state/useKeyboardShortcuts.ts. (Ctrl/Cmd+C/V-Kopieren/Einfügen folgt weiter @@ -863,13 +755,13 @@ export default function App() { // 2D-Boolean-Operation (Union / Subtract / Intersect) auf die gewählten // geschlossenen Drawing2D anwenden. Reihenfolge der Auswahl = Reihenfolge in - // `selectedDrawingIds` (für Differenz: erstes Element = Basis). Ersetzt die + // `selection.drawings` (für Differenz: erstes Element = Basis). Ersetzt die // beteiligten Quellen durch das Ergebnis und selektiert die neuen Elemente. // Braucht ≥2 geschlossene Flächen; sonst No-op. const applyBoolean = ( op: (srcs: Drawing2D[]) => BooleanResult, ) => { - const order = selectedDrawingIds; + const order = selection.drawings; if (order.length < 2) return; const byId = new Map(project.drawings2d.map((d) => [d.id, d])); // In Auswahl-Reihenfolge (Basis zuerst) auflösen. @@ -880,21 +772,20 @@ export default function App() { if (result.replacedIds.length === 0) return; // <2 geschlossene → No-op const replaced = new Set(result.replacedIds); applyChange((p) => [...removeItems(p, "drawings2d", replaced), ...addItems("drawings2d", result.created)]); - setSelectedDrawingIds(result.created.map((d) => d.id)); - setSelectedWallIds([]); + setSelection({ drawings: result.created.map((d) => d.id), walls: [] }); }; - useBooleanOpsShortcut(selectedDrawingIds, project.drawings2d, applyBoolean, shortcutOverrides); + useBooleanOpsShortcut(selection.drawings, project.drawings2d, applyBoolean, shortcutOverrides); // „Eigenschaften übertragen" (2D-Kontextmenü) — dasselbe Zwischenablage- // Muster wie beim Ebenen-Menü (`layerClipboard`), nur für den vollen // Aussehen-Stil eines 2D-Elements (s. `editors/matchProps.ts`). const copyDrawingStyle = () => { - const d = project.drawings2d.find((x) => x.id === selectedDrawingIds[0]); + const d = project.drawings2d.find((x) => x.id === selection.drawings[0]); if (d) setDrawingStyleClipboard(readDrawingStyle(d)); }; const pasteDrawingStyle = () => { - if (!drawingStyleClipboard || selectedDrawingIds.length === 0) return; - applyChange((p) => applyDrawingStyleOps(p, selectedDrawingIds, drawingStyleClipboard)); + if (!drawingStyleClipboard || selection.drawings.length === 0) return; + applyChange((p) => applyDrawingStyleOps(p, selection.drawings, drawingStyleClipboard)); }; // Objekt sperren/entsperren (Kontextmenü) — wirkt auf die GANZE aktuelle @@ -902,16 +793,8 @@ export default function App() { // Anders als der Ebenen-/Geschoss-Sperrmodus (`DisplayMode`, session-lokal) // ist `locked` hier ein persistiertes Feld am Element selbst, s. // `state/objectLock.ts`. - const selectionLockMembers: Partial> = { - wallIds: selectedWallIds, - drawingIds: selectedDrawingIds, - ceilingIds: selectedCeilingIds, - roomIds: selectedRoomIds, - stairIds: selectedStairIds, - columnIds: selectedColumnIds, - roofIds: selectedRoofIds, - openingIds: selectedOpeningIds, - }; + const groupMembers = useMemo(() => toMembership(selection), [selection]); + const selectionLockMembers: Partial> = groupMembers; const selectionLockIds = ( Object.entries(selectionLockMembers) as [MemberKind, string[]][] ).flatMap(([kind, ids]) => ids.map((id) => [kind, id] as const)); @@ -926,16 +809,7 @@ export default function App() { // Ebene(n) der Auswahl ausblenden / isolieren (Kontextmenü). Nur bei geöffnetem // Menü berechnet — bei Kataster-Importen (~10^5 Zeichnungen) nicht bei jedem Render. const selectionLayerCodes = menu - ? selectionCategoryCodes(project, { - wallIds: selectedWallIds, - drawingIds: selectedDrawingIds, - ceilingIds: selectedCeilingIds, - roomIds: selectedRoomIds, - stairIds: selectedStairIds, - columnIds: selectedColumnIds, - roofIds: selectedRoofIds, - openingIds: selectedOpeningIds, - }) + ? selectionCategoryCodes(project, groupMembers) : []; const hideSelectionLayers = () => { if (selectionLayerCodes.length === 0) return; @@ -950,18 +824,18 @@ export default function App() { // „Nicht drucken"/„Drucken" (Kontextmenü) — nur `Drawing2D` kennt // `noPrint` (Nutzer-Wunsch „Kein 'nicht druckend'-Flag im Modell"), daher - // simpler als die Sperre oben: direkt über `selectedDrawingIds`. + // simpler als die Sperre oben: direkt über `selection.drawings`. const selectionAllNoPrint = - selectedDrawingIds.length > 0 && - selectedDrawingIds.every((id) => project.drawings2d.find((d) => d.id === id)?.noPrint); + selection.drawings.length > 0 && + selection.drawings.every((id) => project.drawings2d.find((d) => d.id === id)?.noPrint); const toggleSelectionNoPrint = () => { - if (selectedDrawingIds.length === 0) return; + if (selection.drawings.length === 0) return; const next = !selectionAllNoPrint; - applyChange((p) => patchItems(p, "drawings2d", selectedDrawingIds, (d) => ({ ...d, noPrint: next }))); + applyChange((p) => patchItems(p, "drawings2d", selection.drawings, (d) => ({ ...d, noPrint: next }))); }; // „Bemassung lösen" ([38]): gewählte Bemassungen mit Bezügen auf Modell-Elemente. - const attachedDimensionIds = selectedDrawingIds.filter((id) => { + const attachedDimensionIds = selection.drawings.filter((id) => { const g = project.drawings2d.find((d) => d.id === id)?.geom; return g?.shape === "dimension" && !!g.refs?.some(Boolean); }); @@ -972,31 +846,13 @@ export default function App() { // Ctrl/Cmd+G / Ctrl/Cmd+Shift+G = Gruppieren/Auflösen (Vectorworks-artig, // s. state/groupActions.ts). `applyGroupSelection` setzt nach dem Gruppieren/ // Auflösen alle betroffenen Auswahl-Kanäle auf einen Schlag. - const applyGroupSelection = (mem: GroupMembership, groupIds: string[]) => { - setSelectedWallIds(mem.wallIds); - setSelectedDrawingIds(mem.drawingIds); - setSelectedCeilingIds(mem.ceilingIds); - setSelectedOpeningIds(mem.openingIds); - setSelectedStairIds(mem.stairIds); - setSelectedRoomIds(mem.roomIds); - setSelectedColumnIds(mem.columnIds); - setSelectedRoofIds(mem.roofIds); - setSelectedGroupIds(groupIds); - }; + const applyGroupSelection = (mem: GroupMembership, groupIds: string[]) => + setSelection({ ...fromIdLists(mem), groups: groupIds }); useGroupShortcut( project, applyChange, - { - wallIds: selectedWallIds, - drawingIds: selectedDrawingIds, - ceilingIds: selectedCeilingIds, - roomIds: selectedRoomIds, - stairIds: selectedStairIds, - columnIds: selectedColumnIds, - roofIds: selectedRoofIds, - openingIds: selectedOpeningIds, - }, - selectedGroupIds, + groupMembers, + selection.groups, applyGroupSelection, shortcutOverrides, ); @@ -1056,22 +912,14 @@ export default function App() { removed = r.removed; return r.ops; }); - if (removed) setSelectedDrawingIds([]); + if (removed) setSelection({ drawings: [] }); }; // Transformations-Shortcuts (m/s/d, U/I/O/P-Modusleiste, „q" Messen) — siehe // state/useKeyboardShortcuts.ts. useTransformShortcuts( activeTool, - selectedWallIds.length > 0 || - !!selectedDrawingId || - selectedDrawingIds.length > 0 || - !!selectedExtrudedSolidId || - !!selectedColumnId || - selectedCeilingIds.length > 0 || - selectedRoofIds.length > 0 || - selectedStairIds.length > 0 || - selectedRoomIds.length > 0, + hasTransformable(selection), engine, (id) => onCommandOption(id), onRunCommand, @@ -1273,14 +1121,7 @@ export default function App() { selectedCeiling, selectedExcavation, selectedRoom, - selectedOpeningId, - selectedStairId, - selectedRoomId, - selectedCeilingId, - selectedDrawingId, - selectedWallId, - selectedWallIds, - selectedDrawingIds, + selection, levelId: activeLevel.id, modelEditable: activeLevel.kind !== "section" && activeLevel.kind !== "elevation", sheet: sectionSheet, @@ -1321,36 +1162,17 @@ export default function App() { edgeDragInfoRef, ); + const clipboardIds = useMemo(() => toIdLists(selection), [selection]); // Ctrl/Cmd+C / Ctrl/Cmd+V = Bauteile kopieren/einfügen (alle 9 Auswahl-Kanäle, // nicht nur 2D-Zeichenelemente) — siehe state/useKeyboardShortcuts.ts. useElementClipboardShortcut( - { - wallIds: selectedWallIds, - drawingIds: selectedDrawingIds, - ceilingIds: selectedCeilingIds, - roofIds: selectedRoofIds, - openingIds: selectedOpeningIds, - stairIds: selectedStairIds, - roomIds: selectedRoomIds, - extrudedSolidIds: selectedExtrudedSolidIds, - columnIds: selectedColumnIds, - }, + clipboardIds, elementClipboard, setElementClipboard, activeLevelId, project, applyChange, - { - wallIds: setSelectedWallIds, - drawingIds: setSelectedDrawingIds, - ceilingIds: setSelectedCeilingIds, - roofIds: setSelectedRoofIds, - openingIds: setSelectedOpeningIds, - stairIds: setSelectedStairIds, - roomIds: setSelectedRoomIds, - extrudedSolidIds: setSelectedExtrudedSolidIds, - columnIds: setSelectedColumnIds, - }, + setSelection, shortcutOverrides, ); @@ -1470,10 +1292,7 @@ export default function App() { setDraft, undo, commandLineRef, - selectedWallIds, - selectedDrawingIds, - selectedCeilingIds, - selectedRoofIds, + selection, updateRoof, moveRoofGrip, moveRoofBy, @@ -1487,33 +1306,9 @@ export default function App() { // ── Selektions-Attribut-Kontrakt (Attributes-/Object-Info-Paletten) ─────── // Normalisierte, effektiv aufgelöste Sicht auf das erste selektierte Element. - const selection = useMemo((): Selection | null => { - return deriveSelection( - project, - selectedWallIds, - selectedDrawingId, - selectedCeilingId, - selectedOpeningId, - selectedStairId, - selectedRoomId, - selectedExtrudedSolidId, - selectedColumnId, - selectedRoofId, - selectedContextObjectIds.length === 1 ? selectedContextObjectIds[0] : null, - ); - }, [ - project, - selectedWallIds, - selectedDrawingId, - selectedCeilingId, - selectedOpeningId, - selectedStairId, - selectedRoomId, - selectedExtrudedSolidId, - selectedColumnId, - selectedRoofId, - selectedContextObjectIds, - ], + const selectionInfo = useMemo( + (): SelectionInfo | null => deriveSelection(project, selection), + [project, selection], ); // Gewählte Schnitt-/Ansichtslinie (DrawingLevel) — separat von `selection`, da @@ -1966,9 +1761,9 @@ export default function App() { // Tatsächlich (noch) existierende gewählte Wände — IDs, die es nicht mehr gibt // (z. B. nach Löschen/Geschosswechsel), fallen heraus. const selectedWalls = useMemo(() => { - const ids = new Set(selectedWallIds); + const ids = new Set(selection.walls); return project.walls.filter((w) => ids.has(w.id)); - }, [project.walls, selectedWallIds]); + }, [project.walls, selection.walls]); const selectionCount = selectedWalls.length; // Erste gewählte Wand (für Status-Leiste / Kontextmenü-Aktionen mit Einzelbezug). const selectedWall = selectedWalls[0] ?? null; @@ -2106,34 +1901,7 @@ export default function App() { visibleCodes, categoryDisplay, floorDisplay, - selectionState: { - selectedWallIds, - setSelectedWallIds, - selectedDrawingIds, - setSelectedDrawingIds, - setSelectedDrawingId, - selectedCeilingIds, - setSelectedCeilingIds, - selectedOpeningIds, - setSelectedOpeningIds, - selectedStairIds, - setSelectedStairIds, - selectedRoomIds, - setSelectedRoomIds, - selectedExtrudedSolidIds, - setSelectedExtrudedSolidIds, - selectedColumnIds, - setSelectedColumnIds, - selectedRoofIds, - setSelectedRoofIds, - selectedContextObjectIds, - setSelectedContextObjectIds, - selectedSectionLineIds, - setSelectedSectionLineIds, - selectedGroupIds, - setSelectedGroupIds, - groupPath, - }, + selectionState: { selection, setSelection, groupPath }, contextMenuState: { setMenu, setStampEditorRoomId, editTextId, setEditTextId, setEditTextMinHeightM }, }); @@ -2151,17 +1919,7 @@ export default function App() { : undefined, applyChange, notify, - setSelectedDrawingId, - setSelectedWallIds, - setSelectedCeilingIds, - setSelectedOpeningIds, - setSelectedStairIds, - setSelectedRoomIds, - setSelectedExtrudedSolidIds, - setSelectedColumnIds, - setSelectedRoofIds, - setSelectedContextObjectIds, - setSelectedSectionLineIds, + setSelection, }); // App-weites Drag & Drop einer DXF/DWG-Datei — siehe state/useImportHandling.ts. @@ -2198,7 +1956,7 @@ export default function App() { openResources, dxfInputRef, planViewRef, - selection, + selection: selectionInfo, projectActions: { toggleLevelVisible, toggleCategoryVisible, @@ -2258,23 +2016,7 @@ export default function App() { updateRoom, addColorToCustomPalette, }, - selectionState: { - updateRoof, - setSelectedWallIds, - setSelectedDrawingId, - selectedContextObjectIds, - setSelectedCeilingIds, - setSelectedOpeningIds, - setSelectedStairIds, - setSelectedRoomIds, - setSelectedExtrudedSolidIds, - setSelectedColumnIds, - setSelectedRoofIds, - setSelectedContextObjectIds, - selectedSectionLineId, - setSelectedSectionLineIds, - section3dCutId, - }, + selectionState: { updateRoof, setSelection, selectedSectionLineId, section3dCutId }, toolState: { activeTool, activeWallTypeId, @@ -2774,17 +2516,7 @@ export default function App() { planViewRef={planViewRef} onCursor={setCursor} onScale={setLiveScale} - selectedWallIds={selectedWallIds} - selectedCeilingIds={selectedCeilingIds} - selectedOpeningIds={selectedOpeningIds} - selectedStairIds={selectedStairIds} - selectedExtrudedSolidIds={selectedExtrudedSolidIds} - selectedColumnIds={selectedColumnIds} - selectedGroupIds={selectedGroupIds} - selectedRoomIds={selectedRoomIds} - selectedRoofIds={selectedRoofIds} - selectedContextObjectIds={selectedContextObjectIds} - selectedSectionLineIds={selectedSectionLineIds} + selection={selection} roomStamp={roomStamp} onStampMove={ev.moveRoomStamp} onStampEdit={ev.onOpenStampEditor} @@ -2813,8 +2545,6 @@ export default function App() { grips={grips} gripHandleLines={gripHandleLines} edgeGrips={edgeGrips} - selectedDrawingId={selectedDrawingId} - selectedDrawingIds={selectedDrawingIds} gripHandlers={gripHandlers} edit3dWalls={edit3dWalls} edit3dDrawings={edit3dDrawings} @@ -3163,18 +2893,18 @@ export default function App() { patchCategory, duplicateLevel, deleteLevel, - clearSelection: () => setSelectedWallIds([]), + clearSelection: () => setSelection({ walls: [] }), fit: () => planViewRef.current?.fit(), fitSelection: () => planViewRef.current?.fitSelection(), closedSelectionCount: countClosedAreas( project.drawings2d.filter((d) => - selectedDrawingIds.includes(d.id), + selection.drawings.includes(d.id), ), ), union: () => applyBoolean(unionDrawings), difference: () => applyBoolean(differenceDrawings), intersect: () => applyBoolean(intersectionDrawings), - drawingSelectionCount: selectedDrawingIds.length, + drawingSelectionCount: selection.drawings.length, hasDrawingStyleClipboard: drawingStyleClipboard !== null, copyDrawingStyle, pasteDrawingStyle, @@ -3188,15 +2918,15 @@ export default function App() { toggleSelectionNoPrint, attachedDimensionCount: attachedDimensionIds.length, detachDimensions, - bringToFront: () => reorderDrawings(selectedDrawingIds, "front"), - bringForward: () => reorderDrawings(selectedDrawingIds, "forward"), - sendBackward: () => reorderDrawings(selectedDrawingIds, "backward"), - sendToBack: () => reorderDrawings(selectedDrawingIds, "back"), + bringToFront: () => reorderDrawings(selection.drawings, "front"), + bringForward: () => reorderDrawings(selection.drawings, "forward"), + sendBackward: () => reorderDrawings(selection.drawings, "backward"), + sendToBack: () => reorderDrawings(selection.drawings, "back"), // Stützpunkt-Einträge nur bei GENAU EINER selektierten Polylinie // (mehrere gleichzeitig hätten keinen eindeutigen Klick-Bezug). selectedPolyline: (() => { - if (selectedDrawingIds.length !== 1) return null; - const d = project.drawings2d.find((x) => x.id === selectedDrawingIds[0]); + if (selection.drawings.length !== 1) return null; + const d = project.drawings2d.find((x) => x.id === selection.drawings[0]); return d && d.geom.shape === "polyline" ? { id: d.id, pts: d.geom.pts, closed: d.geom.closed, bulge: d.geom.bulge } : null; diff --git a/src/panels/BcfPanel.tsx b/src/panels/BcfPanel.tsx index 4e9b9f7e..50966c4d 100644 --- a/src/panels/BcfPanel.tsx +++ b/src/panels/BcfPanel.tsx @@ -16,6 +16,7 @@ import { useMemo, useRef } from "react"; import { t } from "../i18n"; import { usePanelHost } from "./host"; import { getState, useStore } from "../state/appStore"; +import { fromIdLists, toIdLists } from "../state/selection"; import { saveBinaryFile } from "../native/saveFile"; import { BCF_STATUSES, @@ -73,31 +74,14 @@ function uuid(): string { function applySelection(sel: BcfSelection): void { const s = getState(); s.clearSelection(); - s.setSelectedWallIds(sel.wallIds); - s.setSelectedCeilingIds(sel.ceilingIds); - s.setSelectedOpeningIds(sel.openingIds); - s.setSelectedStairIds(sel.stairIds); - s.setSelectedRoomIds(sel.roomIds); - s.setSelectedExtrudedSolidIds(sel.extrudedSolidIds); - s.setSelectedColumnIds(sel.columnIds); - s.setSelectedRoofIds(sel.roofIds); - s.setSelectedContextObjectIds(sel.contextObjectIds); + s.setSelection(fromIdLists(sel)); } function currentSelection(): BcfSelection { - const s = getState(); - return { - ...emptyBcfSelection(), - wallIds: s.selectedWallIds, - ceilingIds: s.selectedCeilingIds, - openingIds: s.selectedOpeningIds, - stairIds: s.selectedStairIds, - roomIds: s.selectedRoomIds, - extrudedSolidIds: s.selectedExtrudedSolidIds, - columnIds: s.selectedColumnIds, - roofIds: s.selectedRoofIds, - contextObjectIds: s.selectedContextObjectIds, - }; + const l = toIdLists(getState().selection); + const out = emptyBcfSelection(); + for (const k of Object.keys(out) as (keyof BcfSelection)[]) out[k] = l[k]; + return out; } const f1 = (n: number) => n.toLocaleString("de-CH", { maximumFractionDigits: 1 }); diff --git a/src/panels/ClashPanel.tsx b/src/panels/ClashPanel.tsx index 244684da..9d9542d6 100644 --- a/src/panels/ClashPanel.tsx +++ b/src/panels/ClashPanel.tsx @@ -4,6 +4,7 @@ import { t } from "../i18n"; import { getState } from "../state/appStore"; +import { fromIdLists } from "../state/selection"; import { clashSelection, type Clash } from "../analysis/clash"; import { focusCamera, viewportAvailable } from "../viewport/cameraBridge"; import { runClashAndStore, setClashSession, useClashSession } from "./clashSession"; @@ -13,10 +14,7 @@ export function focusClash(c: Clash, index: number): void { const s = getState(); const sel = clashSelection(c); s.clearSelection(); - s.setSelectedWallIds(sel.wallIds); - s.setSelectedCeilingIds(sel.ceilingIds); - s.setSelectedExtrudedSolidIds(sel.extrudedSolidIds); - s.setSelectedContextObjectIds(sel.contextObjectIds); + s.setSelection(fromIdLists(sel)); setClashSession({ selected: index }); const radius = Math.hypot(c.max[0] - c.min[0], c.max[1] - c.min[1], c.max[2] - c.min[2]) / 2; if (viewportAvailable()) focusCamera(c.center, radius); diff --git a/src/panels/SitePanel.tsx b/src/panels/SitePanel.tsx index b10c5595..da592218 100644 --- a/src/panels/SitePanel.tsx +++ b/src/panels/SitePanel.tsx @@ -120,6 +120,8 @@ function ExcavationQty({ q }: { q: { cut: number; fill: number; backfill: number export function SitePanel() { const host = usePanelHost(); + // Gewählte Kontext-Objekte schmal aus dem Store ([121], [130]). + const selectedContextObjectIds = useStore((s) => s.selection.contextObjects); const notify = useStore((s) => s.notify); const objects = host.contextObjects; const contourSets = objects.filter((o) => o.type === "contourSet"); @@ -258,7 +260,7 @@ export function SitePanel() { key={obj.id} className={ "site-row" + - (host.selectedContextObjectIds.includes(obj.id) ? " site-row-selected" : "") + (selectedContextObjectIds.includes(obj.id) ? " site-row-selected" : "") } > diff --git a/src/panels/host.ts b/src/panels/host.ts index 4673f98e..6978f3f1 100644 --- a/src/panels/host.ts +++ b/src/panels/host.ts @@ -41,7 +41,7 @@ import type { } from "../model/types"; import type { MeasurementReadout, SnapSettings, ToolId } from "../tools/types"; import type { TerrainOptions } from "../model/terrain"; -import type { Selection } from "../state/selectionInfo"; +import type { SelectionInfo } from "../state/selectionInfo"; import type { TextStylePreset } from "../text/richText"; import type { ScheduleKind } from "../export/exportSchedule"; import type { DetailLevel } from "../model/viewTypes"; @@ -176,7 +176,7 @@ export interface PanelHostValue { * (oder `null`). Die Paletten lesen daraus Farbe/Strichstärke/Füllung/bbox * und grauen nicht-anwendbare Felder per `selection.kind` aus. */ - selection: Selection | null; + selection: SelectionInfo | null; /** * Live-Messwerte des Mess-Werkzeugs (Länge/Fläche/Winkel), oder `null`, wenn * gerade nicht gemessen wird. Das Objekt-Info-Panel zeigt sie dauerhaft an, @@ -595,8 +595,6 @@ export interface PanelHostValue { // ── Site-/Kontext-Schicht (SitePanel) ─────────────────────────────────── /** Aktuelle Kontext-Objekte (Meshes/Konturen/Gelände) aus `project.context`. */ contextObjects: ContextObject[]; - /** Im 3D-Viewport angewählte Kontext-Objekte (Umriss-Hervorhebung), s. selectionSlice. */ - selectedContextObjectIds: string[]; /** Fügt mehrere Kontext-Objekte hinzu (z. B. aus einem DXF-Import). */ onAddContextObjects: (objs: ContextObject[]) => void; /** Entfernt ein Kontext-Objekt per ID. */ @@ -822,7 +820,7 @@ export interface CreateMasterLayoutOptions { // importieren Panels nur aus „./host" und bleiben auf einen Pfad fokussiert. export type { DrawingLevel, LayerCategory }; export type { SnapSettings, ToolId }; -export type { Selection } from "../state/selectionInfo"; +export type { SelectionInfo } from "../state/selectionInfo"; export type { ScheduleKind, ScheduleRow } from "../export/exportSchedule"; // ── Hook ─────────────────────────────────────────────────────────────────── diff --git a/src/state/aiAccess.test.ts b/src/state/aiAccess.test.ts index 6a26bfa2..166c93b6 100644 --- a/src/state/aiAccess.test.ts +++ b/src/state/aiAccess.test.ts @@ -59,8 +59,8 @@ describe("KI-Zugriff (App-Host)", () => { const wall = sampleProject.walls[0]; const room = sampleProject.rooms![0]; expect((await handleAiCall("select", { ids: [wall.id, room.id, "gibtsnicht"] })).isError).toBe(false); - expect(getState().selectedWallIds).toEqual([wall.id]); - expect(getState().selectedRoomIds).toEqual([room.id]); + expect(getState().selection.walls).toEqual([wall.id]); + expect(getState().selection.rooms).toEqual([room.id]); expect(JSON.parse(text(await handleAiCall("get_selection", {})))).toMatchObject({ walls: [wall.id], rooms: [room.id] }); let fitted: { x: number; y: number }[] = []; setAiView({ fitBounds: (pts) => (fitted = pts) }); diff --git a/src/state/aiAccess.ts b/src/state/aiAccess.ts index a82406f1..c5114ab1 100644 --- a/src/state/aiAccess.ts +++ b/src/state/aiAccess.ts @@ -11,6 +11,7 @@ import { connectAiBridge, type AiBridgeStatus } from "../net/aiBridge"; import { buildPlanPdf } from "../export/exportPdf"; import { saveBinaryFile, saveTextFile } from "../native/saveFile"; import { getState, setState } from "./appStore"; +import type { Selection, SelectionKind } from "./selection"; export interface AiLogEntry { at: number; @@ -103,32 +104,18 @@ export function setAiView(v: { fitBounds(pts: Vec2[]): void } | null): void { // ── Host über den Store ───────────────────────────────────────────────────────────────────── -type SelSetter = keyof Pick< - ReturnType, - | "setSelectedWallIds" - | "setSelectedDrawingIds" - | "setSelectedCeilingIds" - | "setSelectedOpeningIds" - | "setSelectedStairIds" - | "setSelectedRoomIds" - | "setSelectedExtrudedSolidIds" - | "setSelectedColumnIds" - | "setSelectedRoofIds" - | "setSelectedContextObjectIds" ->; - -/** Liste des Projekts → Auswahl-Kanal (Lesen, Setzen). */ -const CHANNELS: [keyof Project, string, SelSetter][] = [ - ["walls", "selectedWallIds", "setSelectedWallIds"], - ["drawings2d", "selectedDrawingIds", "setSelectedDrawingIds"], - ["ceilings", "selectedCeilingIds", "setSelectedCeilingIds"], - ["openings", "selectedOpeningIds", "setSelectedOpeningIds"], - ["stairs", "selectedStairIds", "setSelectedStairIds"], - ["rooms", "selectedRoomIds", "setSelectedRoomIds"], - ["extrudedSolids", "selectedExtrudedSolidIds", "setSelectedExtrudedSolidIds"], - ["columns", "selectedColumnIds", "setSelectedColumnIds"], - ["roofs", "selectedRoofIds", "setSelectedRoofIds"], - ["context", "selectedContextObjectIds", "setSelectedContextObjectIds"], +/** Liste des Projekts → Auswahl-Art. */ +const CHANNELS: [keyof Project, SelectionKind][] = [ + ["walls", "walls"], + ["drawings2d", "drawings"], + ["ceilings", "ceilings"], + ["openings", "openings"], + ["stairs", "stairs"], + ["rooms", "rooms"], + ["extrudedSolids", "solids"], + ["columns", "columns"], + ["roofs", "roofs"], + ["context", "contextObjects"], ]; type Ent = Record & { id?: string }; @@ -172,18 +159,20 @@ export const appHost: AiHost = { return getState().project === before ? "vom Kern abgelehnt" : null; }, selection: () => { - const s = getState() as unknown as Record; - return Object.fromEntries(CHANNELS.map(([k, sel]) => [k, s[sel] ?? []]).filter(([, ids]) => ids.length > 0)); + const sel = getState().selection; + return Object.fromEntries(CHANNELS.map(([k, kind]) => [k, sel[kind]]).filter(([, ids]) => ids.length > 0)); }, select: (ids: string[]) => { const s = getState(); const p = s.project; - s.clearSelection(); - for (const [k, , set] of CHANNELS) { + const patch: Partial = {}; + for (const [k, kind] of CHANNELS) { const have = new Set(listOf(p, k).map((e) => e.id)); const mine = ids.filter((id) => have.has(id)); - if (mine.length) s[set](mine); + if (mine.length) patch[kind] = mine; } + s.clearSelection(); + s.setSelection(patch); }, zoomTo: (ids: string[]) => { const p = getState().project; diff --git a/src/state/contextObjectSelection.test.ts b/src/state/contextObjectSelection.test.ts index 13aa3f50..d127737a 100644 --- a/src/state/contextObjectSelection.test.ts +++ b/src/state/contextObjectSelection.test.ts @@ -32,7 +32,7 @@ describe("deriveSelection — Kontext-Objekt", () => { }, ], } as unknown as Project; - const sel = deriveSelection(project, [], null, null, null, null, null, null, null, null, "CTX1"); + const sel = deriveSelection(project, { contextObjects: ["CTX1"] }); expect(sel?.kind).toBe("contextObject"); expect(sel?.id).toBe("CTX1"); expect(sel?.bbox).toEqual({ minX: 0, minY: 0, maxX: 10, maxY: 6 }); @@ -54,7 +54,7 @@ describe("deriveSelection — Kontext-Objekt", () => { }, ], } as unknown as Project; - const sel = deriveSelection(project, [], null, null, null, null, null, null, null, null, "CTX1"); + const sel = deriveSelection(project, { contextObjects: ["CTX1"] }); // Bbox-Mittelpunkt (50,25) -> LV95 = origin + Mittelpunkt (origin = lv95 - model = lv95, model (0,0)). expect(sel?.contextObject?.lv95Center).toEqual({ e: 2600050, n: 1200025 }); }); @@ -73,7 +73,7 @@ describe("deriveSelection — Kontext-Objekt", () => { }, ], } as unknown as Project; - const sel = deriveSelection(project, [], null, null, null, null, null, null, null, null, "CTX1"); + const sel = deriveSelection(project, { contextObjects: ["CTX1"] }); // Der Modellpunkt (500,300) IST der Anker -> muss exakt auf lv95 (2600000,1200000) zurückrechnen. expect(sel?.contextObject?.lv95Center).toEqual({ e: 2600000, n: 1200000 }); }); @@ -92,18 +92,18 @@ describe("deriveSelection — Kontext-Objekt", () => { }, ], } as unknown as Project; - const sel = deriveSelection(project, [], null, null, null, null, null, null, null, null, "CS1"); + const sel = deriveSelection(project, { contextObjects: ["CS1"] }); expect(sel?.contextObject?.objType).toBe("contourSet"); expect(sel?.bbox).toEqual({ minX: -5, minY: -3, maxX: 8, maxY: 2 }); }); it("unbekannte Id -> null", () => { const project = { ...baseProject, context: [] } as unknown as Project; - expect(deriveSelection(project, [], null, null, null, null, null, null, null, null, "does-not-exist")).toBeNull(); + expect(deriveSelection(project, { contextObjects: ["does-not-exist"] })).toBeNull(); }); it("keine Kontext-Auswahl (null) -> fällt durch zu anderen Kanälen (hier auch leer -> null)", () => { const project = { ...baseProject, context: [] } as unknown as Project; - expect(deriveSelection(project, [], null)).toBeNull(); + expect(deriveSelection(project, {})).toBeNull(); }); }); diff --git a/src/state/objectInfo.perf.test.ts b/src/state/objectInfo.perf.test.ts index 4e51e926..4c8e2150 100644 --- a/src/state/objectInfo.perf.test.ts +++ b/src/state/objectInfo.perf.test.ts @@ -53,7 +53,7 @@ function bench(n: number, fn: (i: number) => void, rounds = 3): number { } const sel = (p: Project, k: { wall?: string; drawing?: string; roof?: string }) => - deriveSelection(p, k.wall ? [k.wall] : [], k.drawing ?? null, null, null, null, null, null, null, k.roof ?? null); + deriveSelection(p, { walls: k.wall ? [k.wall] : [], drawings: k.drawing ? [k.drawing] : [], roofs: k.roof ? [k.roof] : [] }); describe("Messung Objekt-Info und Griffe, 3000 Wände + 20 000 Zeichnungen", () => { it("Objekt-Info, Griff-Schritte, Polylinien-Punkttyp", { timeout: 120000 }, () => { diff --git a/src/state/panelOps.test.ts b/src/state/panelOps.test.ts index 9b7edd19..d045757f 100644 --- a/src/state/panelOps.test.ts +++ b/src/state/panelOps.test.ts @@ -11,6 +11,7 @@ import { applyOps } from "../core/ops"; import type { CoreOp } from "../core/ops"; import { useProjectActions } from "./useProjectActions"; import { usePanelHostBase } from "./usePanelHostBase"; +import { EMPTY_SELECTION } from "./selection"; /* eslint-disable @typescript-eslint/no-explicit-any */ function capture(f: () => T): T { @@ -126,7 +127,7 @@ function host(h: ReturnType, selection: any) { viewType: "grundriss", selection, projectActions: stubObj({ snapshotLayerVisibility: () => ({}), snapshotDrawingVisibility: () => ({}), applyLayerVisibility: () => {}, applyDrawingVisibility: () => {} }), - selectionState: stubObj({ selectedContextObjectIds: [] }), + selectionState: stubObj({ selection: EMPTY_SELECTION }), toolState: stubObj({}), topBarState: stubObj({}), dialogState: stubObj({ setActiveLayoutId: () => {} }), diff --git a/src/state/roofSelection.test.ts b/src/state/roofSelection.test.ts index 5c522841..c6dde160 100644 --- a/src/state/roofSelection.test.ts +++ b/src/state/roofSelection.test.ts @@ -37,7 +37,7 @@ const project = { describe("deriveSelection — Dach", () => { it("liefert eine Roof-Selection mit Form + abgeleiteten Werten", () => { - const sel = deriveSelection(project, [], null, null, null, null, null, null, null, "RF1"); + const sel = deriveSelection(project, { roofs: ["RF1"] }); expect(sel?.kind).toBe("roof"); expect(sel?.roof?.shape).toBe("sattel"); expect(sel?.roof?.pitchDeg).toBe(45); @@ -49,6 +49,6 @@ describe("deriveSelection — Dach", () => { }); it("ohne Dach-Auswahl kein Roof (null bei leerer Auswahl)", () => { - expect(deriveSelection(project, [], null)).toBeNull(); + expect(deriveSelection(project, {})).toBeNull(); }); }); diff --git a/src/state/selection.ts b/src/state/selection.ts index 30e8b09e..f07352dd 100644 --- a/src/state/selection.ts +++ b/src/state/selection.ts @@ -12,6 +12,7 @@ import type { CommandSelection } from "../commands/types"; import type { TransformSelection } from "../tools/transform"; +import type { GroupMembership } from "../core"; /** Gewählte Elemente, je Art eine Menge (Reihenfolge = Wahl-Reihenfolge). */ export interface Selection { @@ -199,3 +200,17 @@ export function fromIdLists(lists: Partial): Partial { filters: { saturation: 0.5, brightness: 1.1, contrast: 1, grayscale: 0.2 }, }, ]); - const sel = deriveSelection(project, [], null, null, null, null, null, null, null, null, "IMG1"); + const sel = deriveSelection(project, { contextObjects: ["IMG1"] }); expect(sel?.kind).toBe("contextObject"); expect(sel?.isImage).toBe(true); expect(sel?.opacity).toBe(0.8); @@ -56,7 +56,7 @@ describe("deriveSelection — Kontext-Objekt-Luftbild (ContextImage)", () => { const project = projectWith([ { id: "IMG1", type: "image", name: "Luftbild", src: "x", min: { x: 0, y: 0 }, max: { x: 1, y: 1 } }, ]); - const sel = deriveSelection(project, [], null, null, null, null, null, null, null, null, "IMG1"); + const sel = deriveSelection(project, { contextObjects: ["IMG1"] }); expect(sel?.opacity).toBe(1); expect(sel?.imageFilters).toBeUndefined(); }); @@ -65,7 +65,7 @@ describe("deriveSelection — Kontext-Objekt-Luftbild (ContextImage)", () => { const project = projectWith([ { id: "M1", type: "importedMesh", name: "Haus", positions: [0, 0, 0, 1, 0, 0, 0, 1, 0], indices: [0, 1, 2] }, ]); - const sel = deriveSelection(project, [], null, null, null, null, null, null, null, null, "M1"); + const sel = deriveSelection(project, { contextObjects: ["M1"] }); expect(sel?.isImage).toBeFalsy(); expect(sel?.opacity).toBeUndefined(); expect(sel?.imageFilters).toBeUndefined(); diff --git a/src/state/selectionInfo.test.ts b/src/state/selectionInfo.test.ts index 12007952..ecb36878 100644 --- a/src/state/selectionInfo.test.ts +++ b/src/state/selectionInfo.test.ts @@ -11,7 +11,7 @@ describe("deriveSelection (Kern)", () => { it("Wand: Typ-Liste, Geschosse, Länge, Volumen und UK/OK", () => { const p = base(); const w = p.walls[0]; - const sel = deriveSelection(p, [w.id], null)!; + const sel = deriveSelection(p, { walls: [w.id] })!; expect(sel.kind).toBe("wall"); expect(sel.id).toBe(w.id); expect(sel.wall!.wallTypes.length).toBe(p.wallTypes.length); @@ -25,7 +25,7 @@ describe("deriveSelection (Kern)", () => { it("unbekannter Wandtyp bricht mit derselben Meldung ab wie bisher", () => { const p = base(); p.walls[0] = { ...p.walls[0], wallTypeId: "fehlt" }; - expect(() => deriveSelection(p, [p.walls[0].id], null)).toThrow("Unbekannter Wandtyp: fehlt"); + expect(() => deriveSelection(p, { walls: [p.walls[0].id] })).toThrow("Unbekannter Wandtyp: fehlt"); }); it("Zeichnung: offene Linie ohne Füllung, Rechteck mit Ebenen-Vorgaben", () => { @@ -36,15 +36,15 @@ describe("deriveSelection (Kern)", () => { { id: "l", type: "drawing2d", levelId: lvl, categoryCode: code, geom: { shape: "line", a: { x: 0, y: 0 }, b: { x: 3, y: -2 } } }, { id: "r", type: "drawing2d", levelId: lvl, categoryCode: code, hatchId: "h", geom: { shape: "rect", min: { x: 1, y: 1 }, max: { x: 2, y: 4 } } }, ]; - const l = deriveSelection(p, [], "l")!; + const l = deriveSelection(p, { drawings: ["l"] })!; expect(l.closed).toBe(false); expect(l.effectiveHatchId).toBeNull(); expect(l.bbox).toEqual({ minX: 0, minY: -2, maxX: 3, maxY: 0 }); - const r = deriveSelection(p, [], "r")!; + const r = deriveSelection(p, { drawings: ["r"] })!; expect(r.closed).toBe(true); expect(r.fillHatchId).toBe("h"); expect(r.effectiveHatchId).toBe("h"); - expect(deriveSelection(p, [], "nix")).toBeNull(); + expect(deriveSelection(p, { drawings: ["nix"] })).toBeNull(); }); it("Extrusion: Fläche im Kern, B-Rep-Beschreibung (truck) aus TS", () => { @@ -53,7 +53,7 @@ describe("deriveSelection (Kern)", () => { p.extrudedSolids = [ { id: "x", type: "extrudedSolid", levelId: lvl, points: [{ x: 0, y: 0 }, { x: 2, y: 0 }, { x: 2, y: 3 }], height: 2 }, ]; - const sel = deriveSelection(p, [], null, null, null, null, null, "x")!; + const sel = deriveSelection(p, { solids: ["x"] })!; expect(sel.extrudedSolid!.area).toBeCloseTo(3, 12); expect(sel.extrudedSolid!.spec).toMatchObject({ kind: "extrude", height: 2 }); expect(Object.keys(sel.extrudedSolid!)).toEqual([ @@ -72,7 +72,7 @@ describe("deriveSelection (Kern)", () => { }); const edges = (r: Roof) => { // Neues Projekt-Objekt je Fall: der Kern gleicht über Referenzen ab. - return deriveSelection({ ...p, roofs: [r] }, [], null, null, null, null, null, null, null, "R")!.roof!.edges; + return deriveSelection({ ...p, roofs: [r] }, { roofs: ["R"] })!.roof!.edges; }; const list = edges(roof({ holes: [rect(4, 2, 4, 4)] })); expect(list).toHaveLength(8); diff --git a/src/state/selectionInfo.ts b/src/state/selectionInfo.ts index 322f210a..f56126a3 100644 --- a/src/state/selectionInfo.ts +++ b/src/state/selectionInfo.ts @@ -17,6 +17,8 @@ import { extrudedSolidSpec } from "../core"; import type { SolidSpec } from "../engine/truckSolid"; import { documentFor } from "../core/document"; +import { EMPTY_SELECTION, mergeSelection, single } from "./selection"; +import type { Selection } from "./selection"; import type { AttributeSource, DimRef, @@ -358,7 +360,7 @@ export interface SelectionBBox { * EFFEKTIV aufgelöst (Override sonst Default), damit die Palette den real * gezeichneten Wert zeigt. `fillHatchId`/`closed` sind nur für Drawing2D sinnvoll. */ -export interface Selection { +export interface SelectionInfo { kind: | "wall" | "ceiling" @@ -411,7 +413,7 @@ export interface Selection { */ foreground?: string; /** - * Stift-Kopplung von `foreground`, analog {@link Selection.colorPenId} — + * Stift-Kopplung von `foreground`, analog {@link SelectionInfo.colorPenId} — * gesetzt bei Wand, Decke, Stütze und Drawing2D (dieselben `kind`s wie * `foreground` selbst). */ @@ -421,7 +423,7 @@ export interface Selection { * System". Nachfolger von `fillColor`; hat im Plan Vorrang. */ background?: string; - /** Stift-Kopplung von `background`, analog {@link Selection.foregroundPenId}. */ + /** Stift-Kopplung von `background`, analog {@link SelectionInfo.foregroundPenId}. */ backgroundPenId?: string; /** * Quelle des Vordergrunds, wenn `foreground` NICHT gesetzt ist ("layer" = @@ -429,7 +431,7 @@ export interface Selection { * Wand, Decke und geschlossener Drawing2D (wie `foreground`/`pocheEditable`). */ foregroundSource?: AttributeSource; - /** Quelle des Hintergrunds, analog zu {@link Selection.foregroundSource}. */ + /** Quelle des Hintergrunds, analog zu {@link SelectionInfo.foregroundSource}. */ backgroundSource?: AttributeSource; /** * RAW Strichstärke-Override (mm) DIESES Elements; `undefined` = kein Override @@ -449,9 +451,9 @@ export interface Selection { * `undefined` = kein Wert an keiner Stelle der Kette (echtes „Nach System"). */ effectiveForeground?: string; - /** Effektiv aufgelöster Hintergrund, analog zu {@link Selection.effectiveForeground}. */ + /** Effektiv aufgelöster Hintergrund, analog zu {@link SelectionInfo.effectiveForeground}. */ effectiveBackground?: string; - /** Effektiv aufgelöste Schraffur-ID, analog zu {@link Selection.effectiveForeground}. */ + /** Effektiv aufgelöste Schraffur-ID, analog zu {@link SelectionInfo.effectiveForeground}. */ effectiveHatchId?: string | null; /** Ob die Form geschlossen ist (rect/circle/closed polyline) — nur Drawing2D. */ closed?: boolean; @@ -539,45 +541,34 @@ const THROWN = /^Unbekannte[rs]? /; * Bauteil wirft wie bisher; ein Element, das das Kern-Modell nicht lesen kann, * ergibt `null` (mit Warnung). */ -export function deriveSelection( - project: Project, - selectedWallIds: string[], - selectedDrawingId: string | null, - selectedCeilingId: string | null = null, - selectedOpeningId: string | null = null, - selectedStairId: string | null = null, - selectedRoomId: string | null = null, - selectedExtrudedSolidId: string | null = null, - selectedColumnId: string | null = null, - selectedRoofId: string | null = null, - selectedContextObjectId: string | null = null, -): Selection | null { +export function deriveSelection(project: Project, selection: Partial): SelectionInfo | null { + const sel = mergeSelection(EMPTY_SELECTION, selection); const args = { - wallIds: selectedWallIds, - drawingId: selectedDrawingId, - ceilingId: selectedCeilingId, - openingId: selectedOpeningId, - stairId: selectedStairId, - roomId: selectedRoomId, - extrudedSolidId: selectedExtrudedSolidId, - columnId: selectedColumnId, - roofId: selectedRoofId, - contextObjectId: selectedContextObjectId, + wallIds: sel.walls, + drawingId: single(sel, "drawings"), + ceilingId: single(sel, "ceilings"), + openingId: single(sel, "openings"), + stairId: single(sel, "stairs"), + roomId: single(sel, "rooms"), + extrudedSolidId: single(sel, "solids"), + columnId: single(sel, "columns"), + roofId: single(sel, "roofs"), + contextObjectId: single(sel, "contextObjects"), }; // Das Element sucht der Kern über den Positions-Index des Dokuments (keine lineare Suche). - let sel: Selection | null; + let info: SelectionInfo | null; try { - sel = documentFor(project).queryRootMarked("selectionInfo", JSON.stringify(args)); + info = documentFor(project).queryRootMarked("selectionInfo", JSON.stringify(args)); } catch (e) { const msg = e instanceof Error ? e.message : String(e); if (THROWN.test(msg)) throw new Error(msg); console.warn("Objekt-Info:", msg); return null; } - if (sel?.extrudedSolid) { - const s = (project.extrudedSolids ?? []).find((x) => x.id === sel!.id); + if (info?.extrudedSolid) { + const s = (project.extrudedSolids ?? []).find((x) => x.id === info!.id); const floor = s && project.drawingLevels.find((z) => z.id === s.levelId); - sel.extrudedSolid.spec = s && s.operation !== "subtract" ? extrudedSolidSpec(s, floor?.baseElevation ?? 0) : null; + info.extrudedSolid.spec = s && s.operation !== "subtract" ? extrudedSolidSpec(s, floor?.baseElevation ?? 0) : null; } - return sel; + return info; } diff --git a/src/state/selectionSlice.ts b/src/state/selectionSlice.ts index 94d42dcc..4f81e2d6 100644 --- a/src/state/selectionSlice.ts +++ b/src/state/selectionSlice.ts @@ -1,60 +1,27 @@ -// Auswahl-Slice: gewählte Wände (Menge) und das gewählte 2D-Zeichenelement. -// Wand- und 2D-Auswahl schließen sich gegenseitig aus. Reiner Umzug aus -// App.tsx. Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md). +// Auswahl-Slice: die Auswahl als EIN Wert (`Selection`, je Art eine Menge, [130]) +// plus der Isolations-Pfad der Gruppen. Bezeichner englisch, Kommentare deutsch. import type { StoreApi } from "./store"; +import { EMPTY_SELECTION, mergeSelection } from "./selection"; +import type { Selection } from "./selection"; /** Felder, die diese Slice in den RootState beisteuert. */ export interface SelectionSlice { - // Gewählte Wände als MENGE von IDs (Marquee/Einzelauswahl). - selectedWallIds: string[]; - // Gewählte 2D-Zeichenelemente als MENGE (Marquee/Mehrfach/Einzel) — getrennt - // von der Wand-Auswahl. Einzel-Auswahl = Array der Länge 1. - selectedDrawingIds: string[]; - // Gewählte Decken als MENGE von IDs — getrennt von Wand-/2D-Auswahl. - selectedCeilingIds: string[]; - // Gewählte Öffnungen (Fenster/Türen) als MENGE von IDs — getrennt. - selectedOpeningIds: string[]; - // Gewählte Treppen als MENGE von IDs — getrennt von den übrigen Kanälen. - selectedStairIds: string[]; - // Gewählte Räume als MENGE von IDs — getrennt von den übrigen Kanälen. - selectedRoomIds: string[]; - // Gewählte extrudierte Körper (truck-Integration) als MENGE von IDs — getrennt. - selectedExtrudedSolidIds: string[]; - // Gewählte Stützen (Tragwerk) als MENGE von IDs — getrennt von den übrigen Kanälen. - selectedColumnIds: string[]; - // Gewählte Dächer als MENGE von IDs — getrennt von den übrigen Kanälen. - selectedRoofIds: string[]; - // Gewählte Kontext-Objekte (importierte Gebäude/Terrain) als MENGE von IDs. - selectedContextObjectIds: string[]; - // Gewählte Schnitt-/Ansichtslinien (DrawingLevel-Ids) als MENGE von IDs — - // getrennt von den übrigen Kanälen (Shift-Klick togglet, Cmd/Ctrl+A wählt alle). - selectedSectionLineIds: string[]; - // Gewählte Gruppen (Vectorworks-artig) als MENGE von IDs — rein informativ/ - // fürs UI (Bounding-Box, Doppelklick-Ziel); die eigentlichen Mitglieder - // stehen zusätzlich in den übrigen `selected…Ids`-Kanälen (Verschieben/ - // Löschen/etc. brauchen so keine Gruppen-Sonderbehandlung), s. `groupActions.ts`. - selectedGroupIds: string[]; + /** Gewählte Elemente je Art. Komponenten lesen schmal: `useStore(s => s.selection.walls)`. */ + selection: Selection; // Isolations-Pfad (Vectorworks „Gruppe betreten"): Stapel der Gruppen-IDs, // in die per Doppelklick navigiert wurde — leer = nicht isoliert (normal), // letztes Element = die AKTIVE (innerste) Gruppe. Alles ausserhalb ihrer // transitiven Mitgliedschaft wird gedimmt/gesperrt (s. `groupActions.ts`). groupPath: string[]; - setSelectedWallIds: (ids: string[]) => void; - setSelectedDrawingIds: (ids: string[]) => void; - setSelectedCeilingIds: (ids: string[]) => void; - setSelectedOpeningIds: (ids: string[]) => void; - setSelectedStairIds: (ids: string[]) => void; - setSelectedRoomIds: (ids: string[]) => void; - setSelectedExtrudedSolidIds: (ids: string[]) => void; - setSelectedColumnIds: (ids: string[]) => void; - setSelectedRoofIds: (ids: string[]) => void; - setSelectedContextObjectIds: (ids: string[]) => void; - setSelectedSectionLineIds: (ids: string[]) => void; - setSelectedGroupIds: (ids: string[]) => void; + /** + * Ändert die genannten Arten (übrige bleiben). Gleicher Inhalt behält die alte + * Referenz; ohne Änderung kein Benachrichtigen. + */ + setSelection: (patch: Partial | ((s: Selection) => Partial)) => void; setGroupPath: (path: string[]) => void; - /** Auswahl (Wände + Decken + Öffnungen + Treppen + Dächer + 2D-Elemente) leeren. */ + /** Auswahl aller Arten (auch Gruppen) leeren. */ clearSelection: () => void; } @@ -63,50 +30,16 @@ export function createSelectionSlice( ): SelectionSlice { const { set } = api; return { - selectedWallIds: [], - selectedDrawingIds: [], - selectedCeilingIds: [], - selectedOpeningIds: [], - selectedStairIds: [], - selectedRoomIds: [], - selectedExtrudedSolidIds: [], - selectedColumnIds: [], - selectedRoofIds: [], - selectedContextObjectIds: [], - selectedSectionLineIds: [], - selectedGroupIds: [], + selection: EMPTY_SELECTION, groupPath: [], - setSelectedWallIds: (ids) => set({ selectedWallIds: ids }), - setSelectedDrawingIds: (ids) => set({ selectedDrawingIds: ids }), - setSelectedCeilingIds: (ids) => set({ selectedCeilingIds: ids }), - setSelectedOpeningIds: (ids) => set({ selectedOpeningIds: ids }), - setSelectedStairIds: (ids) => set({ selectedStairIds: ids }), - setSelectedRoomIds: (ids) => set({ selectedRoomIds: ids }), - setSelectedExtrudedSolidIds: (ids) => set({ selectedExtrudedSolidIds: ids }), - setSelectedColumnIds: (ids) => set({ selectedColumnIds: ids }), - setSelectedRoofIds: (ids) => set({ selectedRoofIds: ids }), - setSelectedContextObjectIds: (ids) => set({ selectedContextObjectIds: ids }), - setSelectedSectionLineIds: (ids) => set({ selectedSectionLineIds: ids }), - setSelectedGroupIds: (ids) => set({ selectedGroupIds: ids }), + setSelection: (patch) => + set((s) => ({ selection: mergeSelection(s.selection, typeof patch === "function" ? patch(s.selection) : patch) })), setGroupPath: (path) => set({ groupPath: path }), + // groupPath (Isolation) bleibt bewusst erhalten — Leerraum-Klick INNERHALB + // einer betretenen Gruppe soll nur deren Auswahl leeren, nicht aus der + // Gruppe hinauswerfen (Vectorworks-Verhalten). Verlassen ist ein + // expliziter Schritt (Knopf/Escape, s. `useGroupHandlers.ts`). clearSelection: () => - set({ - selectedWallIds: [], - selectedDrawingIds: [], - selectedCeilingIds: [], - selectedOpeningIds: [], - selectedStairIds: [], - selectedRoomIds: [], - selectedExtrudedSolidIds: [], - selectedColumnIds: [], - selectedRoofIds: [], - selectedContextObjectIds: [], - selectedSectionLineIds: [], - selectedGroupIds: [], - // groupPath (Isolation) bleibt bewusst erhalten — Leerraum-Klick INNERHALB - // einer betretenen Gruppe soll nur deren Auswahl leeren, nicht aus der - // Gruppe hinauswerfen (Vectorworks-Verhalten). Verlassen ist ein - // expliziter Schritt (Knopf/Escape, s. `useGroupHandlers.ts`). - }), + set((s) => ({ selection: mergeSelection(s.selection, EMPTY_SELECTION) })), }; } diff --git a/src/state/useCommandEngineHost.ts b/src/state/useCommandEngineHost.ts index 8c37c5ce..2f967d7b 100644 --- a/src/state/useCommandEngineHost.ts +++ b/src/state/useCommandEngineHost.ts @@ -22,6 +22,7 @@ import { loadShortcutOverrides, saveShortcutOverrides, type ShortcutOverrides } import { useCommandKeys } from "./commandKeys"; import { t } from "../i18n"; import { getState } from "./appStore"; +import { clearKinds, toCommandSelection } from "./selection"; import type { useSelectionState } from "./useSelectionState"; import type { useContextMenuState } from "../menus/useContextMenuState"; @@ -57,30 +58,7 @@ export function useCommandEngineHost(opts: { activeWallTypeId: string; visibleCodes: Set; snap: SnapSettings; - sel: Pick< - Sel, - | "selectedWallIds" - | "selectedDrawingId" - | "selectedDrawingIds" - | "selectedExtrudedSolidId" - | "selectedColumnId" - | "selectedCeilingIds" - | "selectedRoofIds" - | "selectedStairIds" - | "selectedRoomIds" - | "groupPath" - | "setSelectedWallIds" - | "setSelectedCeilingIds" - | "setSelectedOpeningIds" - | "setSelectedStairIds" - | "setSelectedRoomIds" - | "setSelectedExtrudedSolidIds" - | "setSelectedColumnIds" - | "setSelectedRoofIds" - | "setSelectedContextObjectIds" - | "setSelectedSectionLineIds" - | "setSelectedDrawingId" - >; + sel: Pick; setProject: (m: ProjectMutation) => void; setDraft: (d: ToolDraft | null) => void; notify: (msg: string, kind: "info" | "warning" | "error") => void; @@ -103,29 +81,7 @@ export function useCommandEngineHost(opts: { setEditTextId, setEditTextMinHeightM, } = opts; - const { - selectedWallIds, - selectedDrawingId, - selectedDrawingIds, - selectedExtrudedSolidId, - selectedColumnId, - selectedCeilingIds, - selectedRoofIds, - selectedStairIds, - selectedRoomIds, - groupPath, - setSelectedWallIds, - setSelectedCeilingIds, - setSelectedOpeningIds, - setSelectedStairIds, - setSelectedRoomIds, - setSelectedExtrudedSolidIds, - setSelectedColumnIds, - setSelectedRoofIds, - setSelectedContextObjectIds, - setSelectedSectionLineIds, - setSelectedDrawingId, - } = opts.sel; + const { selection, groupPath, setSelection } = opts.sel; // ── Command-Engine (Rhino-artiges Befehlssystem) ────────────────────────── // Eine stabile Engine-Instanz; alle Live-Werte (Kontext/Snap/visibleCodes) // liest der Host über einen jeweils aktualisierten `latest`-Ref, damit die @@ -141,15 +97,7 @@ export function useCommandEngineHost(opts: { activeWallTypeId, visibleCodes, snap, - selectedWallIds, - selectedDrawingId, - selectedDrawingIds, - selectedExtrudedSolidId, - selectedColumnId, - selectedCeilingIds, - selectedRoofIds, - selectedStairIds, - selectedRoomIds, + selection, groupPath, setProject, setDraft, @@ -162,15 +110,7 @@ export function useCommandEngineHost(opts: { activeWallTypeId, visibleCodes, snap, - selectedWallIds, - selectedDrawingId, - selectedDrawingIds, - selectedExtrudedSolidId, - selectedColumnId, - selectedCeilingIds, - selectedRoofIds, - selectedStairIds, - selectedRoomIds, + selection, groupPath, setProject, setDraft, @@ -193,17 +133,7 @@ export function useCommandEngineHost(opts: { // Befehl). Move/Copy/Offset operieren darauf. // Im Schnitt/in der Ansicht nur die 2D-Elemente der Ebene: Bauteile // leben im Grundriss-Raum, ein Schnitt-Delta wäre dort falsch. - selection: sheetOnlySelection(c.activeLevel, { - wallIds: c.selectedWallIds, - drawingId: c.selectedDrawingId, - drawingIds: c.selectedDrawingIds, - extrudedSolidId: c.selectedExtrudedSolidId, - columnId: c.selectedColumnId, - ceilingIds: c.selectedCeilingIds, - roofIds: c.selectedRoofIds, - stairIds: c.selectedStairIds, - roomIds: c.selectedRoomIds, - }), + selection: sheetOnlySelection(c.activeLevel, toCommandSelection(c.selection)), }; }, snap: (raw, draftPoints, mods) => { @@ -248,17 +178,7 @@ export function useCommandEngineHost(opts: { // onEditDrawingText (useMouseSelectionHandlers.ts), damit kein anderes // Element gleichzeitig markiert bleibt. focusDrawing: (id, minHeightM) => { - setSelectedWallIds([]); - setSelectedCeilingIds([]); - setSelectedOpeningIds([]); - setSelectedStairIds([]); - setSelectedRoomIds([]); - setSelectedExtrudedSolidIds([]); - setSelectedColumnIds([]); - setSelectedRoofIds([]); - setSelectedContextObjectIds([]); - setSelectedSectionLineIds([]); - setSelectedDrawingId(id); + setSelection({ ...clearKinds(), drawings: [id] }); setEditTextMinHeightM(minHeightM ?? null); setEditTextId(id); }, diff --git a/src/state/useGrip3dEditing.ts b/src/state/useGrip3dEditing.ts index 0c098c7a..cde7202b 100644 --- a/src/state/useGrip3dEditing.ts +++ b/src/state/useGrip3dEditing.ts @@ -24,6 +24,7 @@ import { import type { CommandLineHandle } from "../ui/CommandLine"; import { useEvent } from "./useEvent"; import type { useSelectionState } from "./useSelectionState"; +import type { Selection } from "./selection"; import type { useProjectActions } from "./useProjectActions"; type Sel = ReturnType; @@ -37,10 +38,7 @@ export function useGrip3dEditing(opts: { setDraft: (d: ToolDraft | null) => void; undo: () => void; commandLineRef: RefObject; - selectedWallIds: string[]; - selectedDrawingIds: string[]; - selectedCeilingIds: string[]; - selectedRoofIds: string[]; + selection: Selection; updateRoof: Sel["updateRoof"]; moveRoofGrip: Sel["moveRoofGrip"]; moveRoofBy: Sel["moveRoofBy"]; @@ -59,10 +57,7 @@ export function useGrip3dEditing(opts: { setDraft, undo, commandLineRef, - selectedWallIds, - selectedDrawingIds, - selectedCeilingIds, - selectedRoofIds, + selection, updateRoof, moveRoofGrip, moveRoofBy, @@ -73,6 +68,7 @@ export function useGrip3dEditing(opts: { moveElementByOf, updateWall, } = opts; + const { walls: selectedWallIds, drawings: selectedDrawingIds, ceilings: selectedCeilingIds, roofs: selectedRoofIds } = selection; // ── 3D-Editier-Griffe (direkt im Viewport3D) ────────────────────────────── // Genau EINE gewählte Wand (kein 2D-Element) bzw. genau EIN 2D-Element liefert // die Quelle der 3D-Griffe. Dieselben Store-Actions wie bei den Plan-Griffen diff --git a/src/state/useGripEditing.ts b/src/state/useGripEditing.ts index c30d34b7..cdafbd3e 100644 --- a/src/state/useGripEditing.ts +++ b/src/state/useGripEditing.ts @@ -21,6 +21,8 @@ import { sheetOwnerOutlines } from "../tools/sheetSnapGeometry"; import type { BodyTarget } from "../views/plan/PlanView"; import type { CommandLineHandle } from "../ui/CommandLine"; import type { CommandEngine } from "../commands/engine"; +import { single } from "./selection"; +import type { Selection } from "./selection"; export interface GripEditFieldsState { id: string; @@ -51,14 +53,8 @@ export function useGripEditing(opts: { /** [68] Einzeln gewählte Baugrube (Umriss-Ecken, Kanten, Sohlenhöhe als Griffe). */ selectedExcavation?: Excavation | null; selectedRoom: Room | null; - selectedOpeningId: string | null; - selectedStairId: string | null; - selectedRoomId: string | null; - selectedCeilingId: string | null; - selectedDrawingId: string | null; - selectedWallId: string | null; - selectedWallIds: string[]; - selectedDrawingIds: string[]; + /** Die Auswahl ([130]); Einzel-Elemente daraus wie in `useSelectionState`. */ + selection: Selection; levelId: string; /** * Ob Modell-Bauteile (Wand/Decke/Raum/Öffnung/Treppe) Griffe bekommen und per @@ -123,14 +119,7 @@ export function useGripEditing(opts: { selectedCeiling, selectedExcavation = null, selectedRoom, - selectedOpeningId, - selectedStairId, - selectedRoomId, - selectedCeilingId, - selectedDrawingId, - selectedWallId, - selectedWallIds, - selectedDrawingIds, + selection, levelId, modelEditable = true, sheet = null, @@ -156,6 +145,13 @@ export function useGripEditing(opts: { moveCeilingBy, moveElementByOf, } = opts; + const selectedOpeningId = single(selection, "openings"); + const selectedStairId = single(selection, "stairs"); + const selectedRoomId = single(selection, "rooms"); + const selectedCeilingId = single(selection, "ceilings"); + const selectedDrawingId = single(selection, "drawings"); + const selectedWallId = selection.walls[0] ?? null; + const { walls: selectedWallIds, drawings: selectedDrawingIds } = selection; const groupChanges = opts.groupChanges ?? ((fn: () => void) => fn()); // Bewegpunkt (Move-Handle) einer Treppe: liegt auf der Treppe (Mitte des @@ -184,15 +180,8 @@ export function useGripEditing(opts: { // demselben Element kommen, nicht irgendeinem anderen der Mehrfachauswahl. const gripOwnerRange: [number, number][] = []; - // Bei Mehrfachauswahl fehlt `selectedDrawingIds` manchmal trotzdem (nur die - // Einzel-ID `selectedDrawingId` gesetzt, s. useSelectionState-Konvention) — - // derselbe Fallback wie an anderen Stellen im Projekt. - const effectiveDrawingIds = - selectedDrawingIds.length > 0 - ? selectedDrawingIds - : selectedDrawingId - ? [selectedDrawingId] - : []; + // Die Einzel-ID leitet sich aus der Menge ab ([130]) — die Menge genügt. + const effectiveDrawingIds = selectedDrawingIds; // Griff-Grenzen (s. gripLimits.ts): grosse Mehrfachauswahlen ohne Griffe, ein einzeln gewähltes // Element immer mit Griffen (Kataster-Parzellen mit tausenden Stützpunkten). diff --git a/src/state/useImportHandling.ts b/src/state/useImportHandling.ts index a755ba72..e54dbeef 100644 --- a/src/state/useImportHandling.ts +++ b/src/state/useImportHandling.ts @@ -17,6 +17,8 @@ import { defaultImageSizeM, readImageFile } from "../io/imageAsset"; import { rasterizePdfPages } from "../io/pdfImport"; import { t } from "../i18n"; import type { Vec2 } from "../model/types"; +import { clearKinds } from "./selection"; +import type { Selection } from "./selection"; /** * „Bild einfügen" (Werkzeug „image"): kein Klick-Platzieren (Datei-Auswahl ist @@ -35,17 +37,7 @@ export function useImageImportHandling(opts: { /** Änderung als Ops (Store `applyChange`): alle Bilder eines Einfügens = ein Undo-Schritt. */ applyChange: (ops: readonly CoreOp[]) => void; notify: (message: string, kind?: NotifyKind) => void; - setSelectedDrawingId: (id: string | null) => void; - setSelectedWallIds: (ids: string[]) => void; - setSelectedCeilingIds: (ids: string[]) => void; - setSelectedOpeningIds: (ids: string[]) => void; - setSelectedStairIds: (ids: string[]) => void; - setSelectedRoomIds: (ids: string[]) => void; - setSelectedExtrudedSolidIds: (ids: string[]) => void; - setSelectedColumnIds: (ids: string[]) => void; - setSelectedRoofIds: (ids: string[]) => void; - setSelectedContextObjectIds: (ids: string[]) => void; - setSelectedSectionLineIds: (ids: string[]) => void; + setSelection: (patch: Partial) => void; }): { insertImageDrawings: (assets: { src: string; naturalWidth: number; naturalHeight: number }[]) => void; onImageOrPdfFileChosen: (file: File) => void; @@ -56,17 +48,7 @@ export function useImageImportHandling(opts: { imagePlacement, applyChange, notify, - setSelectedDrawingId, - setSelectedWallIds, - setSelectedCeilingIds, - setSelectedOpeningIds, - setSelectedStairIds, - setSelectedRoomIds, - setSelectedExtrudedSolidIds, - setSelectedColumnIds, - setSelectedRoofIds, - setSelectedContextObjectIds, - setSelectedSectionLineIds, + setSelection, } = opts; const insertImageDrawings = ( @@ -82,17 +64,7 @@ export function useImageImportHandling(opts: { applyChange(addItems("drawings2d", drawings)); const lastId = drawings.length ? drawings[drawings.length - 1].id : null; if (lastId) { - setSelectedDrawingId(lastId); - setSelectedWallIds([]); - setSelectedCeilingIds([]); - setSelectedOpeningIds([]); - setSelectedStairIds([]); - setSelectedRoomIds([]); - setSelectedExtrudedSolidIds([]); - setSelectedColumnIds([]); - setSelectedRoofIds([]); - setSelectedContextObjectIds([]); - setSelectedSectionLineIds([]); + setSelection({ ...clearKinds(), drawings: [lastId] }); } }; diff --git a/src/state/useKeyboardShortcuts.ts b/src/state/useKeyboardShortcuts.ts index 9c7577cc..a9fdd572 100644 --- a/src/state/useKeyboardShortcuts.ts +++ b/src/state/useKeyboardShortcuts.ts @@ -21,6 +21,8 @@ import { differenceDrawings, intersectionDrawings, unionDrawings } from "../edit import type { BooleanResult } from "../editors/booleanOps"; import { groupSelection, mergeMembership, ungroup, EMPTY_MEMBERSHIP } from "./groupActions"; import type { GroupMembership } from "./groupActions"; +import { clearKinds, fromIdLists, isEmpty } from "./selection"; +import type { Selection } from "./selection"; import { collectElementClipboard, isClipboardEmpty, @@ -251,28 +253,8 @@ export function useSelectAllAndDeleteShortcut(opts: { project: Project; activeLevelId: string; shortcutOverrides: ShortcutOverrides; - selectedDrawingIds: string[]; - selectedWallIds: string[]; - selectedCeilingIds: string[]; - selectedOpeningIds: string[]; - selectedStairIds: string[]; - selectedRoomIds: string[]; - selectedExtrudedSolidIds: string[]; - selectedColumnIds: string[]; - selectedRoofIds: string[]; - selectedContextObjectIds: string[]; - selectedSectionLineIds: string[]; - setSelectedWallIds: (ids: string[]) => void; - setSelectedDrawingIds: (ids: string[]) => void; - setSelectedCeilingIds: (ids: string[]) => void; - setSelectedOpeningIds: (ids: string[]) => void; - setSelectedStairIds: (ids: string[]) => void; - setSelectedRoomIds: (ids: string[]) => void; - setSelectedExtrudedSolidIds: (ids: string[]) => void; - setSelectedColumnIds: (ids: string[]) => void; - setSelectedRoofIds: (ids: string[]) => void; - setSelectedContextObjectIds: (ids: string[]) => void; - setSelectedSectionLineIds: (ids: string[]) => void; + selection: Selection; + setSelection: (patch: Partial) => void; hasSelectionToDelete: () => boolean; deleteSelection: () => void; }): void { @@ -282,16 +264,7 @@ export function useSelectAllAndDeleteShortcut(opts: { project, activeLevelId, shortcutOverrides, - setSelectedWallIds, - setSelectedDrawingIds, - setSelectedCeilingIds, - setSelectedOpeningIds, - setSelectedStairIds, - setSelectedRoomIds, - setSelectedExtrudedSolidIds, - setSelectedColumnIds, - setSelectedRoofIds, - setSelectedSectionLineIds, + setSelection, hasSelectionToDelete, deleteSelection, } = opts; @@ -305,30 +278,8 @@ export function useSelectAllAndDeleteShortcut(opts: { if (e.key === "Escape" && !e.ctrlKey && !e.metaKey && !e.altKey) { queueMicrotask(() => { if (e.defaultPrevented) return; - const any = - opts.selectedDrawingIds.length > 0 || - opts.selectedWallIds.length > 0 || - opts.selectedCeilingIds.length > 0 || - opts.selectedOpeningIds.length > 0 || - opts.selectedStairIds.length > 0 || - opts.selectedRoomIds.length > 0 || - opts.selectedExtrudedSolidIds.length > 0 || - opts.selectedColumnIds.length > 0 || - opts.selectedRoofIds.length > 0 || - opts.selectedContextObjectIds.length > 0 || - opts.selectedSectionLineIds.length > 0; - if (!any) return; - setSelectedWallIds([]); - setSelectedDrawingIds([]); - setSelectedCeilingIds([]); - setSelectedOpeningIds([]); - setSelectedStairIds([]); - setSelectedRoomIds([]); - setSelectedExtrudedSolidIds([]); - setSelectedColumnIds([]); - setSelectedRoofIds([]); - opts.setSelectedContextObjectIds([]); - setSelectedSectionLineIds([]); + if (isEmpty(opts.selection, { withGroups: false })) return; + setSelection(clearKinds()); }); return; } @@ -391,16 +342,18 @@ export function useSelectAllAndDeleteShortcut(opts: { roofIds.length || sectionLineIds.length ) { - setSelectedWallIds(wallIds); - setSelectedDrawingIds(drawingIds); - setSelectedCeilingIds(ceilingIds); - setSelectedOpeningIds(openingIds); - setSelectedStairIds(stairIds); - setSelectedRoomIds(roomIds); - setSelectedExtrudedSolidIds(extrudedSolidIds); - setSelectedColumnIds(columnIds); - setSelectedRoofIds(roofIds); - setSelectedSectionLineIds(sectionLineIds); + setSelection({ + walls: wallIds, + drawings: drawingIds, + ceilings: ceilingIds, + openings: openingIds, + stairs: stairIds, + rooms: roomIds, + solids: extrudedSolidIds, + columns: columnIds, + roofs: roofIds, + sectionLines: sectionLineIds, + }); e.preventDefault(); } return; @@ -423,17 +376,7 @@ export function useSelectAllAndDeleteShortcut(opts: { opts.activeTool, opts.transformActive, opts.shortcutOverrides, - opts.selectedDrawingIds, - opts.selectedWallIds, - opts.selectedCeilingIds, - opts.selectedOpeningIds, - opts.selectedStairIds, - opts.selectedRoomIds, - opts.selectedExtrudedSolidIds, - opts.selectedColumnIds, - opts.selectedRoofIds, - opts.selectedContextObjectIds, - opts.selectedSectionLineIds, + opts.selection, opts.project.walls, opts.project.drawings2d, opts.project.ceilings, @@ -460,8 +403,7 @@ export function useSplitJoinShortcut( selectedDrawingIds: string[], engine: CommandEngine, runSplit: (ids: string[]) => void, - setSelectedDrawingIds: (ids: string[]) => void, - setSelectedWallIds: (ids: string[]) => void, + setSelection: (patch: Partial) => void, overrides: ShortcutOverrides, ): void { useEffect(() => { @@ -481,8 +423,7 @@ export function useSplitJoinShortcut( // Join: exakt derselbe Befehl wie „join" tippen (Sofort-Befehl, autoRun). // Nach dem Verbinden zeigt die alte Auswahl auf ersetzte IDs → aufräumen. engine.start("join"); - setSelectedDrawingIds([]); - setSelectedWallIds([]); + setSelection({ drawings: [], walls: [] }); }; window.addEventListener("keydown", onKey); return () => window.removeEventListener("keydown", onKey); @@ -519,17 +460,7 @@ export function useElementClipboardShortcut( activeLevelId: string, project: Project, applyChange: (ops: readonly CoreOp[] | ((p: Project) => readonly CoreOp[])) => void, - setSelected: { - wallIds: (ids: string[]) => void; - drawingIds: (ids: string[]) => void; - ceilingIds: (ids: string[]) => void; - roofIds: (ids: string[]) => void; - openingIds: (ids: string[]) => void; - stairIds: (ids: string[]) => void; - roomIds: (ids: string[]) => void; - extrudedSolidIds: (ids: string[]) => void; - columnIds: (ids: string[]) => void; - }, + setSelection: (patch: Partial) => void, overrides: ShortcutOverrides, ): void { useEffect(() => { @@ -566,15 +497,7 @@ export function useElementClipboardShortcut( }); const pastedIds = out.ids; if (!pastedIds) return; - setSelected.wallIds(pastedIds.wallIds); - setSelected.drawingIds(pastedIds.drawingIds); - setSelected.ceilingIds(pastedIds.ceilingIds); - setSelected.roofIds(pastedIds.roofIds); - setSelected.openingIds(pastedIds.openingIds); - setSelected.stairIds(pastedIds.stairIds); - setSelected.roomIds(pastedIds.roomIds); - setSelected.extrudedSolidIds(pastedIds.extrudedSolidIds); - setSelected.columnIds(pastedIds.columnIds); + setSelection(fromIdLists(pastedIds)); }; if (navigator.clipboard?.readText) { navigator.clipboard diff --git a/src/state/useMouseSelectionHandlers.ts b/src/state/useMouseSelectionHandlers.ts index 280fcacc..5c24dea6 100644 --- a/src/state/useMouseSelectionHandlers.ts +++ b/src/state/useMouseSelectionHandlers.ts @@ -15,6 +15,8 @@ import type { RichTextDoc } from "../text/richText"; import { plainText } from "../text/richText"; import { hitTestWall } from "../viewport/planHitTest"; import type { useSelectionState } from "./useSelectionState"; +import { ELEMENT_KINDS, clearKinds, fromIdLists } from "./selection"; +import type { Selection, SelectionKind } from "./selection"; import type { useContextMenuState } from "../menus/useContextMenuState"; import { EMPTY_MEMBERSHIP, @@ -50,68 +52,14 @@ export function useMouseSelectionHandlers(opts: { * nur für Geschoss/Zeichnung) — sperrt Elemente einer nicht-aktiven, * überlagerten Ebene analog zum Kategorie-Sperren unten. */ floorDisplay: CategoryDisplayResolver & DisplayResolver; - selectionState: Pick< - ReturnType, - | "selectedWallIds" - | "setSelectedWallIds" - | "selectedDrawingIds" - | "setSelectedDrawingIds" - | "setSelectedDrawingId" - | "selectedCeilingIds" - | "setSelectedCeilingIds" - | "selectedOpeningIds" - | "setSelectedOpeningIds" - | "selectedStairIds" - | "setSelectedStairIds" - | "selectedRoomIds" - | "setSelectedRoomIds" - | "selectedExtrudedSolidIds" - | "setSelectedExtrudedSolidIds" - | "selectedColumnIds" - | "setSelectedColumnIds" - | "selectedRoofIds" - | "setSelectedRoofIds" - | "selectedContextObjectIds" - | "setSelectedContextObjectIds" - | "selectedSectionLineIds" - | "setSelectedSectionLineIds" - | "selectedGroupIds" - | "setSelectedGroupIds" - | "groupPath" - >; + selectionState: Pick, "selection" | "setSelection" | "groupPath">; contextMenuState: Pick< ReturnType, "setMenu" | "setStampEditorRoomId" | "editTextId" | "setEditTextId" | "setEditTextMinHeightM" >; }) { const { project, setProject, activeLevelId, visibleCodes, categoryDisplay, floorDisplay, selectionState, contextMenuState } = opts; - const { - selectedWallIds, - setSelectedWallIds, - selectedDrawingIds, - setSelectedDrawingIds, - setSelectedDrawingId, - selectedCeilingIds, - setSelectedCeilingIds, - selectedOpeningIds, - setSelectedOpeningIds, - selectedStairIds, - setSelectedStairIds, - selectedRoomIds, - setSelectedRoomIds, - selectedExtrudedSolidIds, - setSelectedExtrudedSolidIds, - selectedColumnIds, - setSelectedColumnIds, - selectedRoofIds, - setSelectedRoofIds, - selectedContextObjectIds, - setSelectedContextObjectIds, - selectedSectionLineIds, - setSelectedSectionLineIds, - setSelectedGroupIds, - groupPath, - } = selectionState; + const { selection, setSelection, groupPath } = selectionState; const { setMenu, setStampEditorRoomId, editTextId, setEditTextId, setEditTextMinHeightM } = contextMenuState; // ── Maus-Schema: Auswahl + Kontextmenü aus Grundriss / 3D ───────────────── @@ -120,34 +68,14 @@ export function useMouseSelectionHandlers(opts: { // Doppelklick auf einen Raum-Stempel: den Raum wählen + den Stempel-Editor // öffnen (Rich-Text-Popup). const onOpenStampEditor = (roomId: string) => { - setSelectedRoomIds([roomId]); - setSelectedWallIds([]); - setSelectedDrawingId(null); - setSelectedCeilingIds([]); - setSelectedOpeningIds([]); - setSelectedStairIds([]); - setSelectedExtrudedSolidIds([]); - setSelectedColumnIds([]); - setSelectedRoofIds([]); - setSelectedContextObjectIds([]); - setSelectedSectionLineIds([]); + setSelection({ ...clearKinds(), rooms: [roomId] }); setStampEditorRoomId(roomId); }; // Doppelklick auf ein Text-2D-Element: selektieren + Inhalts-Editor öffnen. const onEditDrawingText = (drawingId: string) => { const d = project.drawings2d.find((x) => x.id === drawingId); if (!d || d.geom.shape !== "text") return; - setSelectedDrawingId(drawingId); - setSelectedWallIds([]); - setSelectedCeilingIds([]); - setSelectedOpeningIds([]); - setSelectedStairIds([]); - setSelectedRoomIds([]); - setSelectedExtrudedSolidIds([]); - setSelectedColumnIds([]); - setSelectedRoofIds([]); - setSelectedContextObjectIds([]); - setSelectedSectionLineIds([]); + setSelection({ ...clearKinds(), drawings: [drawingId] }); // Bestehendes Element per Doppelklick: keine Rahmen-Mindesthöhe (nur bei // frisch aufgezogener Textspalte relevant, s. textbox.ts focusMinHeightM) // — sonst könnte eine vorige Textspalten-Erstellung hier nachwirken. @@ -265,19 +193,20 @@ export function useMouseSelectionHandlers(opts: { if (sel.shift) { // Je Art: Auswahl-Liste + Setter. `replaces` (Shift-Durchschalten) entfernt // zuerst das vorige Zwischenergebnis, bevor das neue Objekt umgeschaltet wird. + // Shift-Art (PlanSelection) → Auswahl-Art. const channels = { - section: [selectedSectionLineIds, setSelectedSectionLineIds], - wall: [selectedWallIds, setSelectedWallIds], - drawing: [selectedDrawingIds, setSelectedDrawingIds], - ceiling: [selectedCeilingIds, setSelectedCeilingIds], - opening: [selectedOpeningIds, setSelectedOpeningIds], - stair: [selectedStairIds, setSelectedStairIds], - room: [selectedRoomIds, setSelectedRoomIds], - solid: [selectedExtrudedSolidIds, setSelectedExtrudedSolidIds], - column: [selectedColumnIds, setSelectedColumnIds], - roof: [selectedRoofIds, setSelectedRoofIds], - context: [selectedContextObjectIds, setSelectedContextObjectIds], - } as const; + section: "sectionLines", + wall: "walls", + drawing: "drawings", + ceiling: "ceilings", + opening: "openings", + stair: "stairs", + room: "rooms", + solid: "solids", + column: "columns", + roof: "roofs", + context: "contextObjects", + } as const satisfies Record; type Kind = keyof typeof channels; const target: { kind: Kind; id: string } | null = sel.sectionLineId ? { kind: "section", id: sel.sectionLineId } @@ -304,16 +233,16 @@ export function useMouseSelectionHandlers(opts: { : null; const rep = sel.replaces; const base = (kind: Kind): string[] => { - const list = channels[kind][0] as readonly string[]; + const list = selection[channels[kind]]; return rep && rep.kind === kind ? list.filter((x) => x !== rep.id) : [...list]; }; - if (rep && (!target || rep.kind !== target.kind)) channels[rep.kind][1](base(rep.kind)); + const patch: Partial = {}; + if (rep && (!target || rep.kind !== target.kind)) patch[channels[rep.kind]] = base(rep.kind); if (target) { const list = base(target.kind); - channels[target.kind][1]( - list.includes(target.id) ? list.filter((x) => x !== target.id) : [...list, target.id], - ); + patch[channels[target.kind]] = list.includes(target.id) ? list.filter((x) => x !== target.id) : [...list, target.id]; } + setSelection(patch); return; } // Gruppen-Erweiterung: gehört das getroffene Element zu einer (im @@ -328,76 +257,37 @@ export function useMouseSelectionHandlers(opts: { groupPath, ); if (groupIds.length > 0) { - setSelectedWallIds(expanded.wallIds); - setSelectedDrawingIds(expanded.drawingIds); - setSelectedCeilingIds(expanded.ceilingIds); - setSelectedOpeningIds(expanded.openingIds); - setSelectedStairIds(expanded.stairIds); - setSelectedRoomIds(expanded.roomIds); - setSelectedColumnIds(expanded.columnIds); - setSelectedRoofIds(expanded.roofIds); - setSelectedExtrudedSolidIds([]); - setSelectedContextObjectIds([]); - setSelectedSectionLineIds([]); - setSelectedGroupIds(groupIds); + setSelection({ ...clearKinds(), ...fromIdLists(expanded), groups: groupIds }); return; } } - setSelectedGroupIds([]); // Ohne Shift: ersetzen. Öffnung hat Vorrang (ihr Symbol liegt in der Lücke), - // dann Wand, dann 2D-Element, dann Decke; sonst leeren. Die Kanäle schließen - // sich gegenseitig aus. - // Alle Kanäle ausser dem gewählten leeren — als Helfer, damit jeder Zweig - // (inkl. des neuen Dach-Kanals) konsistent bleibt. - const clearOthers = (keep: string) => { - if (keep !== "wall") setSelectedWallIds([]); - if (keep !== "drawing") setSelectedDrawingId(null); - if (keep !== "ceiling") setSelectedCeilingIds([]); - if (keep !== "opening") setSelectedOpeningIds([]); - if (keep !== "stair") setSelectedStairIds([]); - if (keep !== "room") setSelectedRoomIds([]); - if (keep !== "extrudedSolid") setSelectedExtrudedSolidIds([]); - if (keep !== "column") setSelectedColumnIds([]); - if (keep !== "roof") setSelectedRoofIds([]); - if (keep !== "contextObject") setSelectedContextObjectIds([]); - if (keep !== "sectionLine") setSelectedSectionLineIds([]); - }; - if (sel.sectionLineId) { - setSelectedSectionLineIds([sel.sectionLineId]); - clearOthers("sectionLine"); - } else if (sel.openingId) { - setSelectedOpeningIds([sel.openingId]); - clearOthers("opening"); - } else if (sel.wallId) { - setSelectedWallIds([sel.wallId]); - clearOthers("wall"); - } else if (sel.columnId) { - setSelectedColumnIds([sel.columnId]); - clearOthers("column"); - } else if (sel.drawingId) { - setSelectedDrawingId(sel.drawingId); - clearOthers("drawing"); - } else if (sel.extrudedSolidId) { - setSelectedExtrudedSolidIds([sel.extrudedSolidId]); - clearOthers("extrudedSolid"); - } else if (sel.ceilingId) { - setSelectedCeilingIds([sel.ceilingId]); - clearOthers("ceiling"); - } else if (sel.stairId) { - setSelectedStairIds([sel.stairId]); - clearOthers("stair"); - } else if (sel.roomId) { - setSelectedRoomIds([sel.roomId]); - clearOthers("room"); - } else if (sel.roofId) { - setSelectedRoofIds([sel.roofId]); - clearOthers("roof"); - } else if (sel.contextObjectId) { - setSelectedContextObjectIds([sel.contextObjectId]); - clearOthers("contextObject"); - } else { - clearOthers(""); - } + // dann Wand, dann 2D-Element, dann Decke; sonst leeren. Die Arten schließen + // sich gegenseitig aus (alle anderen und die Gruppen werden geleert). + const one: [SelectionKind, string] | null = sel.sectionLineId + ? ["sectionLines", sel.sectionLineId] + : sel.openingId + ? ["openings", sel.openingId] + : sel.wallId + ? ["walls", sel.wallId] + : sel.columnId + ? ["columns", sel.columnId] + : sel.drawingId + ? ["drawings", sel.drawingId] + : sel.extrudedSolidId + ? ["solids", sel.extrudedSolidId] + : sel.ceilingId + ? ["ceilings", sel.ceilingId] + : sel.stairId + ? ["stairs", sel.stairId] + : sel.roomId + ? ["rooms", sel.roomId] + : sel.roofId + ? ["roofs", sel.roofId] + : sel.contextObjectId + ? ["contextObjects", sel.contextObjectId] + : null; + setSelection({ ...clearKinds(), groups: [], ...(one ? { [one[0]]: [one[1]] } : {}) }); }; // Links-Drag (Marquee) im Grundriss: die getroffene Wand-MENGE übernehmen // (nach CAD-Konvention von PlanView bestimmt). Ersetzt die bisherige Auswahl. @@ -433,22 +323,19 @@ export function useMouseSelectionHandlers(opts: { // Gruppen-Erweiterung: jedes getroffene Element, das zu einer sichtbaren // Gruppe gehört, zieht deren ganze (transitive) Mitgliedschaft nach. const { expanded, groupIds } = expandToGroups(project, filtered, groupPath); - setSelectedWallIds(expanded.wallIds); - setSelectedDrawingIds(expanded.drawingIds); - setSelectedCeilingIds(expanded.ceilingIds); - setSelectedStairIds(expanded.stairIds); - setSelectedRoomIds(expanded.roomIds); - setSelectedGroupIds(groupIds); // Öffnungen/Extrusionen/Stützen/Dächer/Kontext-Objekte sind (noch) nicht // Teil des Marquee (Nutzer-Report betraf nur Decken/Räume/Treppen; Stütze/ // Dach liessen sich mit derselben `marqueeHitByField`-Mechanik ergänzen, // falls gewünscht) → beim Aufziehen abwählen. - setSelectedOpeningIds([]); - setSelectedExtrudedSolidIds([]); - setSelectedColumnIds([]); - setSelectedRoofIds([]); - setSelectedContextObjectIds([]); - setSelectedSectionLineIds([]); + setSelection({ + ...clearKinds(), + walls: expanded.wallIds, + drawings: expanded.drawingIds, + ceilings: expanded.ceilingIds, + stairs: expanded.stairIds, + rooms: expanded.roomIds, + groups: groupIds, + }); }; // Rechts-Klick im Grundriss: Wand-Kontextmenü. Trifft der Klick eine Wand, die // NICHT bereits in der Auswahl ist, wird die Auswahl auf sie gesetzt (damit die @@ -460,7 +347,7 @@ export function useMouseSelectionHandlers(opts: { model: Vec2; }) => { const wallId = hitTestWall(project, activeLevelId, visibleCodes, info.model); - if (wallId && !selectedWallIds.includes(wallId)) setSelectedWallIds([wallId]); + if (wallId && !selection.walls.includes(wallId)) setSelection({ walls: [wallId] }); setMenu({ kind: "plan", x: info.clientX, y: info.clientY, wallId, model: info.model }); }; // Links-KLICK im Nordstern-3D-Viewport (WASM, TS-Raycast): getroffenes Bauteil @@ -471,114 +358,39 @@ export function useMouseSelectionHandlers(opts: { // Leertreffer (kein Bauteil) → alle Selektionen leeren. const onViewport3dPick = (hit: Pick3dHit, additive: boolean) => { if (!hit) { - setSelectedWallIds([]); - setSelectedCeilingIds([]); - setSelectedDrawingId(null); - setSelectedOpeningIds([]); - setSelectedStairIds([]); - setSelectedRoomIds([]); - setSelectedExtrudedSolidIds([]); - setSelectedColumnIds([]); - setSelectedRoofIds([]); - setSelectedContextObjectIds([]); - setSelectedSectionLineIds([]); + setSelection(clearKinds()); return; } + // Öffnung (Fenster/Tür), Treppe, Kontext-Objekt, 2D-Element und Dach ersetzen + // die Auswahl exklusiv; nur Wände und Decken unterstützen additive + // Mehrfachauswahl (wie bisher; ein 2D-Treffer wählt auch mit Shift nur sich). if (hit.kind === "contextObject") { - setSelectedContextObjectIds([hit.id]); - setSelectedWallIds([]); - setSelectedCeilingIds([]); - setSelectedDrawingId(null); - setSelectedOpeningIds([]); - setSelectedStairIds([]); - setSelectedRoomIds([]); - setSelectedExtrudedSolidIds([]); - setSelectedColumnIds([]); - setSelectedRoofIds([]); - setSelectedSectionLineIds([]); + setSelection({ ...clearKinds(), contextObjects: [hit.id] }); return; } - // Öffnung (Fenster/Tür) und Treppe sind jetzt auch im WASM-Viewport pickbar - // (raycast3d/pickGeometry). Jede Art ersetzt die Auswahl exklusiv; nur Wände - // unterstützen additive Mehrfachauswahl (wie bisher). if (hit.kind === "opening") { - setSelectedOpeningIds([hit.id]); - setSelectedWallIds([]); - setSelectedCeilingIds([]); - setSelectedDrawingId(null); - setSelectedStairIds([]); - setSelectedRoomIds([]); - setSelectedExtrudedSolidIds([]); - setSelectedColumnIds([]); - setSelectedRoofIds([]); - setSelectedContextObjectIds([]); - setSelectedSectionLineIds([]); + setSelection({ ...clearKinds(), openings: [hit.id] }); return; } if (hit.kind === "drawing") { - setSelectedDrawingIds( - additive ? Array.from(new Set([...selectedDrawingIds, hit.id])) : [hit.id], - ); - setSelectedDrawingId(hit.id); - setSelectedWallIds([]); - setSelectedCeilingIds([]); - setSelectedOpeningIds([]); - setSelectedStairIds([]); - setSelectedRoomIds([]); - setSelectedExtrudedSolidIds([]); - setSelectedColumnIds([]); - setSelectedRoofIds([]); - setSelectedContextObjectIds([]); - setSelectedSectionLineIds([]); + setSelection({ ...clearKinds(), drawings: [hit.id] }); return; } if (hit.kind === "stair") { - setSelectedStairIds([hit.id]); - setSelectedWallIds([]); - setSelectedCeilingIds([]); - setSelectedDrawingId(null); - setSelectedOpeningIds([]); - setSelectedRoomIds([]); - setSelectedExtrudedSolidIds([]); - setSelectedColumnIds([]); - setSelectedRoofIds([]); - setSelectedContextObjectIds([]); - setSelectedSectionLineIds([]); + setSelection({ ...clearKinds(), stairs: [hit.id] }); return; } if (hit.kind === "roof") { - setSelectedRoofIds([hit.id]); - setSelectedWallIds([]); - setSelectedCeilingIds([]); - setSelectedDrawingId(null); - setSelectedOpeningIds([]); - setSelectedStairIds([]); - setSelectedRoomIds([]); - setSelectedExtrudedSolidIds([]); - setSelectedColumnIds([]); - setSelectedContextObjectIds([]); + // Schnittlinien bleiben hier (wie bisher) gewählt. + setSelection({ ...clearKinds(...ELEMENT_KINDS.filter((k) => k !== "sectionLines")), roofs: [hit.id] }); return; } - if (hit.kind === "wall") { - setSelectedWallIds( - additive ? Array.from(new Set([...selectedWallIds, hit.id])) : [hit.id], - ); - setSelectedCeilingIds([]); - } else { - setSelectedCeilingIds( - additive ? Array.from(new Set([...selectedCeilingIds, hit.id])) : [hit.id], - ); - setSelectedWallIds([]); - } - setSelectedDrawingId(null); - setSelectedOpeningIds([]); - setSelectedStairIds([]); - setSelectedContextObjectIds([]); - setSelectedRoomIds([]); - setSelectedExtrudedSolidIds([]); - setSelectedColumnIds([]); - setSelectedRoofIds([]); - setSelectedSectionLineIds([]); + const add = (ids: string[]) => (additive ? Array.from(new Set([...ids, hit.id])) : [hit.id]); + setSelection( + hit.kind === "wall" + ? { ...clearKinds(), walls: add(selection.walls) } + : { ...clearKinds(), ceilings: add(selection.ceilings) }, + ); }; return { onOpenStampEditor, diff --git a/src/state/usePanelHostBase.ts b/src/state/usePanelHostBase.ts index ab103798..fabaee73 100644 --- a/src/state/usePanelHostBase.ts +++ b/src/state/usePanelHostBase.ts @@ -18,7 +18,9 @@ import type { ViewType } from "../model/viewTypes"; import type { TransformSelection } from "../tools/transform"; import type { PlanViewHandle } from "../views/plan/PlanView"; import type { PanelHostValue } from "../panels/host"; -import type { Selection } from "./selectionInfo"; +import type { SelectionInfo } from "./selectionInfo"; +import { clearKinds } from "./selection"; +import type { SelectionKind } from "./selection"; import type { EngineView } from "../commands/engine"; import type { ScheduleKind } from "../export/exportSchedule"; import type { TabId as ResourceTabId } from "../ui/ResourceManager"; @@ -127,7 +129,7 @@ export function usePanelHostBase(opts: { openResources: (tab?: ResourceTabId) => void; dxfInputRef: RefObject; planViewRef: RefObject; - selection: Selection | null; + selection: SelectionInfo | null; projectActions: Pick< ReturnType, | "toggleLevelVisible" @@ -191,19 +193,8 @@ export function usePanelHostBase(opts: { selectionState: Pick< ReturnType, | "updateRoof" - | "setSelectedWallIds" - | "setSelectedDrawingId" - | "selectedContextObjectIds" - | "setSelectedCeilingIds" - | "setSelectedOpeningIds" - | "setSelectedStairIds" - | "setSelectedRoomIds" - | "setSelectedExtrudedSolidIds" - | "setSelectedColumnIds" - | "setSelectedRoofIds" - | "setSelectedContextObjectIds" + | "setSelection" | "selectedSectionLineId" - | "setSelectedSectionLineIds" | "section3dCutId" >; toolState: Pick< @@ -315,19 +306,8 @@ export function usePanelHostBase(opts: { } = projectActions; const { updateRoof, - setSelectedWallIds, - setSelectedDrawingId, - selectedContextObjectIds, - setSelectedCeilingIds, - setSelectedOpeningIds, - setSelectedStairIds, - setSelectedRoomIds, - setSelectedExtrudedSolidIds, - setSelectedColumnIds, - setSelectedRoofIds, - setSelectedContextObjectIds, + setSelection, selectedSectionLineId, - setSelectedSectionLineIds, section3dCutId, } = selectionState; const { activeTool, activeWallTypeId, setActiveWallTypeId, activeCategoryCode, setActiveCategoryCode, snap, setSnap } = @@ -1114,7 +1094,6 @@ export function usePanelHostBase(opts: { }, // ── Site-/Kontext-Schicht ────────────────────────────────────────────── contextObjects: project.context ?? [], - selectedContextObjectIds, onAddContextObjects: addContextObjectsAndFit, onRemoveContextObject: removeContextObject, onRemoveContextObjects: removeContextObjects, @@ -1134,44 +1113,20 @@ export function usePanelHostBase(opts: { opts?: { zoom?: boolean }, ) => { const applySelection = () => { - setSelectedWallIds([]); - setSelectedDrawingId(null); - setSelectedCeilingIds([]); - setSelectedOpeningIds([]); - setSelectedStairIds([]); - setSelectedRoomIds([]); - setSelectedExtrudedSolidIds([]); - setSelectedColumnIds([]); - setSelectedRoofIds([]); - setSelectedContextObjectIds([]); - setSelectedSectionLineIds([]); - switch (kind) { - case "Wand": - setSelectedWallIds([id]); - break; - case "Decke": - setSelectedCeilingIds([id]); - break; - case "Fenster": - case "Öffnung": - setSelectedOpeningIds([id]); - break; - case "Treppe": - setSelectedStairIds([id]); - break; - case "Extrusion": - setSelectedExtrudedSolidIds([id]); - break; - case "Dach": - setSelectedRoofIds([id]); - break; - case "Stütze": - setSelectedColumnIds([id]); - break; - default: - // z. B. Legacy-„Tür"-Datensätze (project.doors) — kein Auswahl-Kanal. - return; - } + const kindOf: Partial> = { + Wand: "walls", + Decke: "ceilings", + Fenster: "openings", + Öffnung: "openings", + Treppe: "stairs", + Extrusion: "solids", + Dach: "roofs", + Stütze: "columns", + }; + const k = kindOf[kind]; + setSelection({ ...clearKinds(), ...(k ? { [k]: [id] } : {}) }); + // z. B. Legacy-„Tür"-Datensätze (project.doors) — kein Auswahl-Kanal. + if (!k) return; if (opts?.zoom) requestAnimationFrame(() => planViewRef.current?.fit()); }; if (floorId && floorId !== activeLevelId) { @@ -1532,7 +1487,6 @@ export function usePanelHostBase(opts: { section3dCutId, onToggleSection3dCut, selectedViewSnapshotId, - selectedContextObjectIds, ]); return baseHost; diff --git a/src/state/useSelectionState.ts b/src/state/useSelectionState.ts index bdf38f10..7f590cff 100644 --- a/src/state/useSelectionState.ts +++ b/src/state/useSelectionState.ts @@ -12,122 +12,48 @@ import { useState } from "react"; import { useStore } from "./appStore"; import type { ElementClipboard } from "../editors/elementClipboard"; +import { single } from "./selection"; export function useSelectionState() { - const selectedWallIds = useStore((s) => s.selectedWallIds); - const setSelectedWallIds = useStore((s) => s.setSelectedWallIds); - // 2D-Auswahl ist jetzt eine MENGE (Marquee/Mehrfach). Für die bestehende - // Einzel-Element-Maschinerie (Grips, Edit, Attribute, Object-Info) wird lokal - // der „eine" gewählte Zeichnungs-ID abgeleitet (nur bei genau einem Element); - // `setSelectedDrawingId` bleibt als bequeme Einzel-Setter-Hülle erhalten. - const selectedDrawingIds = useStore((s) => s.selectedDrawingIds); - const setSelectedDrawingIds = useStore((s) => s.setSelectedDrawingIds); - const selectedDrawingId = - selectedDrawingIds.length === 1 ? selectedDrawingIds[0] : null; - const setSelectedDrawingId = (id: string | null) => - setSelectedDrawingIds(id ? [id] : []); + // Die ganze Auswahl (je Art eine Menge, [130]); App liest sie vollständig, die + // Einzel-Element-Maschinerie (Grips, Edit, Attribute, Object-Info) bekommt je Art + // das „eine" gewählte Element (nur bei genau einem). + const selection = useStore((s) => s.selection); + const setSelection = useStore((s) => s.setSelection); + const clearSelection = useStore((s) => s.clearSelection); // Zwischenablage für ALLE Bauteil-Arten (Ctrl/Cmd+C/V) — Wand/Decke/Dach/ // Öffnung/Treppe/Raum/Extrusion/Stütze + 2D-Zeichenelemente, s. // `editors/elementClipboard.ts`. Kopiert die GEWÄHLTEN Elemente tief; // Einfügen legt Klone mit neuen IDs auf dem AKTIVEN Geschoss an — so lässt // sich z. B. importiertes Mobiliar über Geschosse hinweg wiederverwenden. const [elementClipboard, setElementClipboard] = useState(null); - // Bequemer Einzel-Selektor (erste gewählte Wand). - const selectedWallId = selectedWallIds[0] ?? null; - // Decken-Auswahl (MENGE); für die Einzel-Element-Maschinerie der „eine" - // gewählte (bei genau einem Element). - const selectedCeilingIds = useStore((s) => s.selectedCeilingIds); - const setSelectedCeilingIds = useStore((s) => s.setSelectedCeilingIds); - const selectedCeilingId = - selectedCeilingIds.length === 1 ? selectedCeilingIds[0] : null; - // Dach-Auswahl (MENGE); Einzel-Element bei genau einem gewählten Dach. - const selectedRoofIds = useStore((s) => s.selectedRoofIds); - const setSelectedRoofIds = useStore((s) => s.setSelectedRoofIds); - const selectedRoofId = selectedRoofIds.length === 1 ? selectedRoofIds[0] : null; - // Schnitt-/Ansichtslinien-Auswahl (MENGE); Einzel-Element bei genau einer - // gewählten Linie (Attribut-/Patch-Logik bleibt darauf zugeschnitten). - const selectedSectionLineIds = useStore((s) => s.selectedSectionLineIds); - const setSelectedSectionLineIds = useStore((s) => s.setSelectedSectionLineIds); - const selectedSectionLineId = - selectedSectionLineIds.length === 1 ? selectedSectionLineIds[0] : null; // Welche Schnittlinie treibt den 3D-Live-Schnitt (reiner Ansichts-Zustand, // unabhängig von der Auswahl — der Schnitt bleibt beim Klick woanders aktiv). const [section3dCutId, setSection3dCutId] = useState(null); const updateRoof = useStore((s) => s.updateRoof); const moveRoofGrip = useStore((s) => s.moveRoofGrip); const moveRoofBy = useStore((s) => s.moveRoofBy); - const selectedOpeningIds = useStore((s) => s.selectedOpeningIds); - const setSelectedOpeningIds = useStore((s) => s.setSelectedOpeningIds); - const selectedOpeningId = - selectedOpeningIds.length === 1 ? selectedOpeningIds[0] : null; - const selectedStairIds = useStore((s) => s.selectedStairIds); - const setSelectedStairIds = useStore((s) => s.setSelectedStairIds); - const selectedStairId = - selectedStairIds.length === 1 ? selectedStairIds[0] : null; - const selectedRoomIds = useStore((s) => s.selectedRoomIds); - const setSelectedRoomIds = useStore((s) => s.setSelectedRoomIds); - const selectedRoomId = - selectedRoomIds.length === 1 ? selectedRoomIds[0] : null; - const selectedExtrudedSolidIds = useStore((s) => s.selectedExtrudedSolidIds); - const setSelectedExtrudedSolidIds = useStore((s) => s.setSelectedExtrudedSolidIds); - const selectedExtrudedSolidId = - selectedExtrudedSolidIds.length === 1 ? selectedExtrudedSolidIds[0] : null; - const selectedColumnIds = useStore((s) => s.selectedColumnIds); - const setSelectedColumnIds = useStore((s) => s.setSelectedColumnIds); - const selectedColumnId = - selectedColumnIds.length === 1 ? selectedColumnIds[0] : null; - const selectedContextObjectIds = useStore((s) => s.selectedContextObjectIds); - const setSelectedContextObjectIds = useStore((s) => s.setSelectedContextObjectIds); - // Gruppen (Vectorworks-artig): gewählte Gruppen-IDs + Isolations-Pfad - // ("Gruppe betreten"), s. `groupActions.ts`. - const selectedGroupIds = useStore((s) => s.selectedGroupIds); - const setSelectedGroupIds = useStore((s) => s.setSelectedGroupIds); + // Gruppen (Vectorworks-artig): Isolations-Pfad ("Gruppe betreten"), s. `groupActions.ts`. const groupPath = useStore((s) => s.groupPath); const setGroupPath = useStore((s) => s.setGroupPath); return { - selectedWallIds, - setSelectedWallIds, - selectedDrawingIds, - setSelectedDrawingIds, - selectedDrawingId, - setSelectedDrawingId, + selection, + setSelection, + clearSelection, + // Bequemer Einzel-Selektor (erste gewählte Wand). + selectedWallId: selection.walls[0] ?? null, + selectedDrawingId: single(selection, "drawings"), + selectedCeilingId: single(selection, "ceilings"), + selectedSectionLineId: single(selection, "sectionLines"), + selectedRoomId: single(selection, "rooms"), elementClipboard, setElementClipboard, - selectedWallId, - selectedCeilingIds, - setSelectedCeilingIds, - selectedCeilingId, - selectedRoofIds, - setSelectedRoofIds, - selectedRoofId, - selectedSectionLineIds, - setSelectedSectionLineIds, - selectedSectionLineId, section3dCutId, setSection3dCutId, updateRoof, moveRoofGrip, moveRoofBy, - selectedOpeningIds, - setSelectedOpeningIds, - selectedOpeningId, - selectedStairIds, - setSelectedStairIds, - selectedStairId, - selectedRoomIds, - setSelectedRoomIds, - selectedRoomId, - selectedExtrudedSolidIds, - setSelectedExtrudedSolidIds, - selectedExtrudedSolidId, - selectedColumnIds, - setSelectedColumnIds, - selectedColumnId, - selectedContextObjectIds, - setSelectedContextObjectIds, - selectedGroupIds, - setSelectedGroupIds, groupPath, setGroupPath, }; diff --git a/src/views/plan/PlanView.tsx b/src/views/plan/PlanView.tsx index 38c7131e..a12b1b2e 100644 --- a/src/views/plan/PlanView.tsx +++ b/src/views/plan/PlanView.tsx @@ -53,6 +53,8 @@ import { PlanPickIndex, type ClientMap, type OwnerField } from "../../core"; import { planPrimAt, planTextEntries } from "../../core"; import { buildDrawingIndex, drawingsWithinDistance, marqueeHitUnderlay, nearestInDrawings, type DrawingIndex } from "../../core"; import { endBusyAfterPaint } from "../../state/busyStore"; +import { EMPTY_SELECTION, single } from "../../state/selection"; +import type { Selection } from "../../state/selection"; import { createCursorStore, useCursorValue, type CursorStore } from "../../state/cursorStore"; /** @@ -382,62 +384,13 @@ export interface PlanViewProps { */ onSegmentCut?: (drawingId: string, model: Vec2) => void; /** - * Aktuell ausgewählte Wand-IDs (kontrolliert von App). Die Ansicht markiert - * ALLE Polygone JEDER dieser Wände mit einer Akzentkontur — unabhängig davon, - * welches Band der Klick traf. Leeres Array/undefined = keine Wand-Auswahl. + * Die Auswahl (kontrolliert von App, [130]). Die Ansicht markiert ALLE Primitive + * JEDES gewählten Elements mit einer Akzentkontur (Wände: alle Bänder; Dach: die + * Traufe; Kontext-Objekte/Schnittlinien: das Pick-Band). Gewählte GRUPPEN zeigen + * statt der Mitglieds-Umrisse nur eine Bounding-Box (s. `groupBBox`); die übrigen + * Arten tragen weiterhin die volle Mitgliedschaft. Fehlt = nichts gewählt. */ - selectedWallIds?: string[]; - /** - * Aktuell ausgewählte Decken-IDs (kontrolliert von App). Die Ansicht markiert - * ALLE Polygone JEDER dieser Decken mit einer Akzentkontur. - */ - selectedCeilingIds?: string[]; - /** - * Aktuell ausgewählte Öffnungs-IDs (Fenster/Tür; kontrolliert von App). Die - * Ansicht markiert alle Symbol-Primitive JEDER dieser Öffnungen. - */ - selectedOpeningIds?: string[]; - /** - * Aktuell ausgewählte Treppen-IDs (kontrolliert von App). Die Ansicht markiert - * alle Tritt-/Symbol-Primitive JEDER dieser Treppen mit einer Akzentkontur. - */ - selectedStairIds?: string[]; - /** - * Aktuell ausgewählte Raum-IDs (kontrolliert von App). Die Ansicht markiert die - * Fläche JEDES dieser Räume mit einer Akzentkontur. - */ - selectedRoomIds?: string[]; - /** Aktuell ausgewählte Dach-IDs (von App); die Ansicht markiert die Traufe. */ - selectedRoofIds?: string[]; - /** - * Aktuell ausgewählte Kontext-Objekt-IDs (importiertes Gebäude/Terrain; von - * App). Die Ansicht markiert das Grundriss-Pick-Band JEDES dieser Objekte mit - * einer Akzentkontur. - */ - selectedContextObjectIds?: string[]; - /** - * Aktuell ausgewählte Schnitt-/Ansichtslinien-IDs (DrawingLevel; von App). Die - * Ansicht markiert das Pick-Band JEDER dieser Linien mit einer Akzentkontur. - */ - selectedSectionLineIds?: string[]; - /** - * Aktuell ausgewählte IDs extrudierter Körper (truck-Integration; kontrolliert - * von App). Die Ansicht markiert den Footprint-Umriss JEDES dieser Körper mit - * einer Akzentkontur. - */ - selectedExtrudedSolidIds?: string[]; - /** - * Aktuell ausgewählte Stützen-IDs (Tragwerk; kontrolliert von App). Die Ansicht - * markiert den Querschnitt-Umriss JEDER dieser Stützen mit einer Akzentkontur. - */ - selectedColumnIds?: string[]; - /** - * IDs der gewählten GRUPPEN (Vectorworks-artig). Nicht-leer → die Ansicht - * zeigt statt der einzelnen Mitglieds-Umrisse nur eine Bounding-Box mit vier - * Eckpunkten (s. `groupBBox`); die per-Kind-`selected…Ids`-Felder tragen - * weiterhin die volle Mitgliedschaft (für Verschieben/Griffe/Löschen). - */ - selectedGroupIds?: string[]; + selection?: Selection; /** * Der Stempel-Griff des (einzeln) gewählten Raums: sein Anker (Meter) + ID. * PlanView zeichnet einen ziehbaren Griff und meldet Bewegung/Doppelklick. @@ -548,10 +501,6 @@ export interface PlanViewProps { * statt der echten mm-Strichstärken (Print). Reine Darstellung. */ hairline?: boolean; - /** ID des selektierten 2D-Elements (für „Körper greifen → verschieben"). */ - selectedDrawingId?: string | null; - /** Alle selektierten 2D-Elemente (Mehrfach-/Marquee-Auswahl) — für Hervorhebung. */ - selectedDrawingIds?: string[]; /** Griff-Zieh-Treiber: Live-Bewegung (gesnappt) + Abschluss. */ gripHandlers?: GripHandlers; /** @@ -680,18 +629,8 @@ export const PlanView = forwardRef( onMarquee, onSegmentCut, onContextMenu, - selectedWallIds, - selectedCeilingIds, - selectedOpeningIds, + selection = EMPTY_SELECTION, sheetBodies = false, - selectedStairIds, - selectedRoomIds, - selectedRoofIds, - selectedContextObjectIds, - selectedSectionLineIds, - selectedExtrudedSolidIds, - selectedColumnIds, - selectedGroupIds, roomStamp, onStampMove, onStampEdit, @@ -712,8 +651,6 @@ export const PlanView = forwardRef( gripHandleLines, edgeGrips, hairline, - selectedDrawingId, - selectedDrawingIds, gripHandlers, marqueeColor = DEFAULT_MARQUEE_COLOR, snapColor = DEFAULT_SNAP_COLOR, @@ -725,6 +662,21 @@ export const PlanView = forwardRef( }, ref, ) { + const { + walls: selectedWallIds, + ceilings: selectedCeilingIds, + openings: selectedOpeningIds, + stairs: selectedStairIds, + rooms: selectedRoomIds, + roofs: selectedRoofIds, + contextObjects: selectedContextObjectIds, + sectionLines: selectedSectionLineIds, + solids: selectedExtrudedSolidIds, + columns: selectedColumnIds, + groups: selectedGroupIds, + drawings: selectedDrawingIds, + } = selection; + const selectedDrawingId = single(selection, "drawings"); // Linke Maustaste liegt beim Werkzeug/der Transformation, wenn App das meldet // (toolInputActive) bzw. — fallback — ein Zeichenwerkzeug aktiv ist. const inputActive = toolInputActive ?? (!!activeTool && activeTool !== "select"); diff --git a/src/views/viewportContent.tsx b/src/views/viewportContent.tsx index 24a9f0ad..d4fa43e9 100644 --- a/src/views/viewportContent.tsx +++ b/src/views/viewportContent.tsx @@ -56,6 +56,7 @@ import type { Pick3dHit } from "../viewport/Wasm3DViewport"; import { DrawingTabs } from "../DrawingTabs"; import type { ViewSnapshotTabsHandlers } from "../DrawingTabs"; import type { ToolDraft, ToolHandlers, ToolId } from "../tools/types"; +import type { Selection } from "../state/selection"; import type { DetailLevel, RenderMode, View3d, ViewType } from "../model/viewTypes"; /** @@ -99,17 +100,7 @@ export const Content = memo(function Content({ planViewRef, onCursor, onScale, - selectedWallIds, - selectedCeilingIds, - selectedOpeningIds, - selectedStairIds, - selectedExtrudedSolidIds, - selectedColumnIds, - selectedGroupIds, - selectedRoomIds, - selectedRoofIds, - selectedContextObjectIds, - selectedSectionLineIds, + selection, roomStamp, onStampMove, onStampEdit, @@ -137,8 +128,6 @@ export const Content = memo(function Content({ grips, gripHandleLines, edgeGrips, - selectedDrawingId, - selectedDrawingIds, gripHandlers, edit3dWalls, edit3dDrawings, @@ -206,17 +195,8 @@ export const Content = memo(function Content({ planViewRef: React.RefObject; onCursor: (model: Vec2 | null) => void; onScale: (n: number) => void; - selectedWallIds: string[]; - selectedCeilingIds: string[]; - selectedOpeningIds: string[]; - selectedStairIds: string[]; - selectedExtrudedSolidIds: string[]; - selectedColumnIds: string[]; - selectedGroupIds: string[]; - selectedRoomIds: string[]; - selectedRoofIds: string[]; - selectedContextObjectIds: string[]; - selectedSectionLineIds: string[]; + /** Die Auswahl ([130]). */ + selection: Selection; roomStamp: { roomId: string; anchor: Vec2 } | null; onStampMove: (roomId: string, delta: Vec2) => void; onStampEdit: (roomId: string) => void; @@ -253,8 +233,6 @@ export const Content = memo(function Content({ grips: Vec2[]; gripHandleLines: { a: Vec2; b: Vec2 }[]; edgeGrips: EdgeGrip[]; - selectedDrawingId: string | null; - selectedDrawingIds?: string[]; gripHandlers: GripHandlers; /** Alle gewählten Wände — Quelle der 3D-Editier-Griffe (Mehrfachauswahl ⇒ alle). */ edit3dWalls: Wall[]; @@ -296,36 +274,18 @@ export const Content = memo(function Content({ const clashes = useClashSession().clashes; // Explosionsaxonometrie ([65]): Hervorhebung folgt dem auseinandergezogenen 3D-Modell. const explode = useStore((s) => (s.explode3d ? s.explode3dGap : 0)); + const { walls, ceilings, openings, stairs, roofs, contextObjects } = selection; const selectionLines = useMemo( () => - selectedWallIds.length === 0 && - selectedCeilingIds.length === 0 && - selectedOpeningIds.length === 0 && - selectedStairIds.length === 0 && - selectedRoofIds.length === 0 && - selectedContextObjectIds.length === 0 + walls.length === 0 && + ceilings.length === 0 && + openings.length === 0 && + stairs.length === 0 && + roofs.length === 0 && + contextObjects.length === 0 ? null - : selectionHighlightLines( - project, - selectedWallIds, - selectedCeilingIds, - HIGHLIGHT_RGB, - selectedOpeningIds, - selectedStairIds, - selectedRoofIds, - selectedContextObjectIds, - explode, - ), - [ - project, - explode, - selectedWallIds, - selectedCeilingIds, - selectedOpeningIds, - selectedStairIds, - selectedRoofIds, - selectedContextObjectIds, - ], + : selectionHighlightLines(project, walls, ceilings, HIGHLIGHT_RGB, openings, stairs, roofs, contextObjects, explode), + [project, explode, walls, ceilings, openings, stairs, roofs, contextObjects], ); // Kollisionen der letzten Prüfung: rote Hüllquader zusätzlich zur Auswahl-Hervorhebung. const highlightLines = useMemo(() => { @@ -410,16 +370,7 @@ export const Content = memo(function Content({ planViewRef={planViewRef} onCursor={onCursor} onScale={onScale} - selectedWallIds={selectedWallIds} - selectedCeilingIds={selectedCeilingIds} - selectedOpeningIds={selectedOpeningIds} - selectedStairIds={selectedStairIds} - selectedExtrudedSolidIds={selectedExtrudedSolidIds} - selectedColumnIds={selectedColumnIds} - selectedGroupIds={selectedGroupIds} - selectedRoomIds={selectedRoomIds} - selectedRoofIds={selectedRoofIds} - selectedSectionLineIds={selectedSectionLineIds} + selection={selection} roomStamp={roomStamp} onStampMove={onStampMove} onStampEdit={onStampEdit} @@ -443,8 +394,6 @@ export const Content = memo(function Content({ grips={grips} gripHandleLines={gripHandleLines} edgeGrips={edgeGrips} - selectedDrawingId={selectedDrawingId} - selectedDrawingIds={selectedDrawingIds} gripHandlers={gripHandlers} /> @@ -479,17 +428,7 @@ export const Content = memo(function Content({ planViewRef={planViewRef} onCursor={onCursor} onScale={onScale} - selectedWallIds={selectedWallIds} - selectedCeilingIds={selectedCeilingIds} - selectedOpeningIds={selectedOpeningIds} - selectedStairIds={selectedStairIds} - selectedExtrudedSolidIds={selectedExtrudedSolidIds} - selectedColumnIds={selectedColumnIds} - selectedGroupIds={selectedGroupIds} - selectedRoomIds={selectedRoomIds} - selectedRoofIds={selectedRoofIds} - selectedContextObjectIds={selectedContextObjectIds} - selectedSectionLineIds={selectedSectionLineIds} + selection={selection} roomStamp={roomStamp} onStampMove={onStampMove} onStampEdit={onStampEdit} @@ -513,8 +452,6 @@ export const Content = memo(function Content({ grips={grips} gripHandleLines={gripHandleLines} edgeGrips={edgeGrips} - selectedDrawingId={selectedDrawingId} - selectedDrawingIds={selectedDrawingIds} gripHandlers={gripHandlers} /> ); @@ -570,17 +507,7 @@ export const Content = memo(function Content({ planViewRef={planViewRef} onCursor={onCursor} onScale={onScale} - selectedWallIds={selectedWallIds} - selectedCeilingIds={selectedCeilingIds} - selectedOpeningIds={selectedOpeningIds} - selectedStairIds={selectedStairIds} - selectedExtrudedSolidIds={selectedExtrudedSolidIds} - selectedColumnIds={selectedColumnIds} - selectedGroupIds={selectedGroupIds} - selectedRoomIds={selectedRoomIds} - selectedRoofIds={selectedRoofIds} - selectedContextObjectIds={selectedContextObjectIds} - selectedSectionLineIds={selectedSectionLineIds} + selection={selection} roomStamp={roomStamp} onStampMove={onStampMove} onStampEdit={onStampEdit} @@ -604,8 +531,6 @@ export const Content = memo(function Content({ grips={grips} gripHandleLines={gripHandleLines} edgeGrips={edgeGrips} - selectedDrawingId={selectedDrawingId} - selectedDrawingIds={selectedDrawingIds} gripHandlers={gripHandlers} /> )} @@ -754,17 +679,7 @@ function LevelPlanView({ planViewRef, onCursor, onScale, - selectedWallIds, - selectedCeilingIds, - selectedOpeningIds, - selectedStairIds, - selectedExtrudedSolidIds, - selectedColumnIds, - selectedGroupIds, - selectedRoomIds, - selectedRoofIds, - selectedContextObjectIds, - selectedSectionLineIds, + selection, roomStamp, onStampMove, onStampEdit, @@ -788,8 +703,6 @@ function LevelPlanView({ grips, gripHandleLines, edgeGrips, - selectedDrawingId, - selectedDrawingIds, gripHandlers, }: { /** Hintergrund unter der Zeichnung (Layout-Blatt), s. `PlanView.backdrop`. */ @@ -815,17 +728,8 @@ function LevelPlanView({ planViewRef: React.RefObject; onCursor: (model: Vec2 | null) => void; onScale: (n: number) => void; - selectedWallIds: string[]; - selectedCeilingIds: string[]; - selectedOpeningIds: string[]; - selectedStairIds: string[]; - selectedExtrudedSolidIds: string[]; - selectedColumnIds: string[]; - selectedGroupIds: string[]; - selectedRoomIds: string[]; - selectedRoofIds: string[]; - selectedContextObjectIds?: string[]; - selectedSectionLineIds: string[]; + /** Die Auswahl ([130]). */ + selection: Selection; roomStamp: { roomId: string; anchor: Vec2 } | null; onStampMove: (roomId: string, delta: Vec2) => void; onStampEdit: (roomId: string) => void; @@ -853,8 +757,6 @@ function LevelPlanView({ grips: Vec2[]; gripHandleLines: { a: Vec2; b: Vec2 }[]; edgeGrips: EdgeGrip[]; - selectedDrawingId: string | null; - selectedDrawingIds?: string[]; gripHandlers: GripHandlers; }) { // Fremd-Art-Referenz-Unterlage (Nutzer-Wunsch: "will mal etwas vom Schnitt @@ -949,17 +851,7 @@ function LevelPlanView({ resetKey={level.id} onCursor={onCursor} onScale={onScale} - selectedWallIds={selectedWallIds} - selectedCeilingIds={selectedCeilingIds} - selectedOpeningIds={selectedOpeningIds} - selectedStairIds={selectedStairIds} - selectedExtrudedSolidIds={selectedExtrudedSolidIds} - selectedColumnIds={selectedColumnIds} - selectedGroupIds={selectedGroupIds} - selectedRoomIds={selectedRoomIds} - selectedRoofIds={selectedRoofIds} - selectedContextObjectIds={selectedContextObjectIds} - selectedSectionLineIds={selectedSectionLineIds} + selection={selection} roomStamp={roomStamp} onStampMove={onStampMove} onStampEdit={onStampEdit} @@ -987,8 +879,6 @@ function LevelPlanView({ snapColor={snapColor} hoverDivideDelayMs={hoverDivideDelayMs} hoverDivideCount={hoverDivideCount} - selectedDrawingId={selectedDrawingId} - selectedDrawingIds={selectedDrawingIds} gripHandlers={gripHandlers} backdrop={backdrop} units={unitsForLevel(level)} @@ -1027,16 +917,7 @@ function SectionPlanView({ planViewRef, onCursor, onScale, - selectedWallIds, - selectedCeilingIds, - selectedOpeningIds, - selectedStairIds, - selectedExtrudedSolidIds, - selectedColumnIds, - selectedGroupIds, - selectedRoomIds, - selectedRoofIds, - selectedSectionLineIds, + selection, roomStamp, onStampMove, onStampEdit, @@ -1060,8 +941,6 @@ function SectionPlanView({ grips, gripHandleLines, edgeGrips, - selectedDrawingId, - selectedDrawingIds, gripHandlers, }: { project: Project; @@ -1082,16 +961,8 @@ function SectionPlanView({ planViewRef: React.RefObject; onCursor: (model: Vec2 | null) => void; onScale: (n: number) => void; - selectedWallIds: string[]; - selectedCeilingIds: string[]; - selectedOpeningIds: string[]; - selectedStairIds: string[]; - selectedExtrudedSolidIds: string[]; - selectedColumnIds: string[]; - selectedGroupIds: string[]; - selectedRoomIds: string[]; - selectedRoofIds: string[]; - selectedSectionLineIds: string[]; + /** Die Auswahl ([130]). */ + selection: Selection; roomStamp: { roomId: string; anchor: Vec2 } | null; onStampMove: (roomId: string, delta: Vec2) => void; onStampEdit: (roomId: string) => void; @@ -1115,10 +986,13 @@ function SectionPlanView({ grips: Vec2[]; gripHandleLines: { a: Vec2; b: Vec2 }[]; edgeGrips: EdgeGrip[]; - selectedDrawingId: string | null; - selectedDrawingIds?: string[]; gripHandlers: GripHandlers; }) { + // Kontext-Objekte hebt der Schnitt (wie bisher) nicht hervor. + const sectionSelection = useMemo( + () => (selection.contextObjects.length ? { ...selection, contextObjects: [] } : selection), + [selection], + ); // Die Ansicht (kind "elevation") ist synchron (Kern, Painter); nur der Schnitt wartet auf die // truck-Körper. const isElevation = level.kind === "elevation"; @@ -1338,16 +1212,7 @@ function SectionPlanView({ resetKey={level.id} onCursor={onCursor} onScale={onScale} - selectedWallIds={selectedWallIds} - selectedCeilingIds={selectedCeilingIds} - selectedOpeningIds={selectedOpeningIds} - selectedStairIds={selectedStairIds} - selectedExtrudedSolidIds={selectedExtrudedSolidIds} - selectedColumnIds={selectedColumnIds} - selectedGroupIds={selectedGroupIds} - selectedRoomIds={selectedRoomIds} - selectedRoofIds={selectedRoofIds} - selectedSectionLineIds={selectedSectionLineIds} + selection={sectionSelection} roomStamp={roomStamp} onStampMove={onStampMove} onStampEdit={onStampEdit} @@ -1375,8 +1240,6 @@ function SectionPlanView({ snapColor={snapColor} hoverDivideDelayMs={hoverDivideDelayMs} hoverDivideCount={hoverDivideCount} - selectedDrawingId={selectedDrawingId} - selectedDrawingIds={selectedDrawingIds} gripHandlers={gripHandlers} sheetBodies />