[K4][6][8] Ressourcen, Stifte/Paletten, Text-Stile, Raumprogramm, Baurecht, Sonne, Kontext-Schicht und 3D-Griffe mit mitgefuehrten Ecken erzeugen Ops direkt; TODO: Rest-Liste von setProject/diffToOps
Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
18 files changed
+419
-300
No files matched your search
@@ -246,16 +246,30 @@ truck (`trucksolid`) bleibt eigenes WASM-Modul (Panic-Isolation), wird vom Kern
|
||||
**Messung** (vitest/WASM, Linux-Container unter Last, 3000 Wände, `applyChange.perf.test.ts`): Griff ziehen 3,3 → 0,2–0,3 ms
|
||||
je Mausschritt, Auswahl (300 Wände) verschieben 30 → 5,5–7,5 ms, Eigenschaft tippen 2,3–3,8 → 0,03 ms; Undo/Redo 0,45 → 0,07 ms.
|
||||
Kern nativ: 300 `replace` auf 5000 Wände 11,2 → 1,5 ms. Rest beim Verschieben: JSON der 300 Wände (TS→Kern) und Kopien im Kern.
|
||||
**Noch über `setProject(fn)` + `diffToOps`** (Kosten nur proportional zu den geänderten Listen; keine Mausschritt-Pfade mehr):
|
||||
Ressourcen/Stifte/Paletten/Text-Stile in `projectSlice.ts` (kleine Listen; `setActivePenSet`/`patchPenSet*` mit
|
||||
`rebakePenColors` fassen ganze Listen an), `usePanelHostBase.ts` (Stützen, Extrusionen, Layouts/Masterlayouts, Ausschnitte,
|
||||
Kontext-Objekte), `useProjectActions.ts` (Wand-/Decken-/Dachtypen, Override-Regeln …), `App.tsx` (Stil übertragen, Sperren,
|
||||
Kategorien ein/aus/isolieren, IFC-/Datei-Import, Kollisions-Marken, Layout-Handler, Georeferenz), Einfügen/Gruppieren/
|
||||
Ungruppieren (`useKeyboardShortcuts.ts`), Raumprogramm/Baurecht/Sonnenstand-Panels, `siteSlice.ts`, Ressourcen-Fenster,
|
||||
Werkzeug-Commits (`tools/`), Editier-Befehle trim/extend/fillet/chamfer/break/join/explode/align/autodim/defblock/georef/
|
||||
sectionline/solid/solidbool/voidbox/terrain/ceilingOpening, Befehls-Commits innerhalb einer Gruppe ohne `opsMutation`.
|
||||
Offen: diese Liste abbauen, danach `diffToOps` nur noch für Laden/Fremdstände; Ebenen-/Gruppen-Logik (`groupActions.ts`) nach
|
||||
Rust; 3D-Griffe mit mitgeführten Ecken (`onEdit3dVertex`) ebenfalls als Gruppe; Undo-Verlauf als Liste in der UI [84].
|
||||
**Dritte Etappe (28.10.): Rest der Aktionen auf Ops.** Umgestellt: Editier-Befehle trim/extend/fillet/chamfer/break/join/explode/
|
||||
align/autodim/defblock/georef/sectionline/solid/solidbool/voidbox/terrain/ceilingOpening und die Werkzeug-Commits in `tools/tools.ts`
|
||||
(alle `CommandResult.commit`/`ToolResult.commit` sind jetzt `opsMutation`); Einfügen (`pasteElementClipboard`), Gruppieren/
|
||||
Ungruppieren (`groupSelection`/`ungroup` liefern Ops); `usePanelHostBase.ts` (Stützen, Extrusionen, Kontext-Bild, Ausschnitte +
|
||||
Ordner, Layouts/Masterlayouts/Ordner), `useProjectActions.ts` (Wand-/Decken-/Dach-/Tür-/Fenster-/Treppentypen, Override-Regeln,
|
||||
Stil speichern), `App.tsx` (Split, 2D-Boolean, Segment schneiden, Stil übertragen, Sperren, Kategorien aus/isolieren,
|
||||
Nicht-drucken, Kollisions-Marken, Layout-Blatt, Einstellungen/Georeferenz, Schatten), `projectSlice.ts` (Bauteile, Schraffuren,
|
||||
Linien-/Text-Stile, Stifte/Stiftsätze mit `rebakePenOps`, Paletten), `siteSlice.ts`, Raumprogramm/Baurecht/Sonne-Panels
|
||||
(`roomProgramOps`, `addProgramSheetOps`, `setField`); 3D-Griffe mit mitgeführten Ecken: `Wasm3DViewport` fasst Element und
|
||||
mitgeführte Ecken je Maus-Schritt zur Gruppe mit Schlüssel (`onEditGroup` = `groupChanges`), ein Zug = ein Undo-Schritt.
|
||||
Neuer Helfer `replaceWithMany` (Elemente durch mehrere an derselben Stelle ersetzen: explode, Split). Die Projekt → Projekt-Fassungen
|
||||
der Befehle/Editoren sind gelöscht (`explodeDrawings`, `alignDrawings`, `applyDrawingStyle`, `setLocked*`, `rebakePenColors`,
|
||||
`applyClashMarkers` …); wo CLI/Tests sie brauchen, sind es dünne Hüllen um die Ops (`applyRoomProgram`, `addProgramSheet`).
|
||||
Gleichheit: beim Umbau je Befehl 300 Zufallsprojekte (trim … ceilingOpening, 8 Ausrichtungen), dazu Typ-CRUD, 46 Panel-Schritte und
|
||||
37 Ressourcen-/Stiftsatz-Schritte (inkl. Undo-Tiefe und Meldungen) gegen die alte setProject-Fassung (Stand vor dem Umbau): gleiches
|
||||
Projekt bis auf erzeugte ids. Bleibende Tests: `commands/cmds/editOps.test.ts`, `state/panelOps.test.ts`, `state/resourceOps.test.ts`,
|
||||
`replaceWithMany` in `core/opsBuild.test.ts` und die umgestellten Bestandstests (align, explode, matchProps, objectLock, penSets, clash,
|
||||
groupActions, elementClipboard). Nicht in der Tauri-App getestet (nur vitest/Linux + e2e im Browser).
|
||||
**`setProject(fn)` + `diffToOps` bleibt nur noch für:** Datei-Öffnen/Neu/Vorlage/Wiederherstellen (`useProjectFileActions`),
|
||||
Import (DXF-Layer/Linienstile in `runImport`, Bilder einfügen in `useImportHandling`, IFC-Bauteile in `App.tsx` `runIfcImport`),
|
||||
das Ressourcen-Fenster (Fremd-Synchronisation) und das CLI (`cli/main.ts`: ganze Dateien, Projekt → Projekt-Hilfen); dazu der
|
||||
Rückfall für Befehle ohne mitgeführte Ops in `App.tsx` (gibt es keine mehr; der Typ `commit: (p) => Project` erlaubt es noch).
|
||||
Offen: Ebenen-/Gruppen-Logik (`groupActions.ts`) nach Rust; Undo-Verlauf als Liste in der UI [84]; `diffToOps` entfällt erst, wenn auch
|
||||
Laden/Import/CLI Ops liefern.
|
||||
- ○ **S4 Typen aus Rust**: `types.ts` wird aus den Rust-Strukturen erzeugt (ts-rs); Datei-I/O (`projectFormat`, Migration, IFC/DXF/
|
||||
STEP-Ex- und -Import) im Kern.
|
||||
Offene Entscheide/Risiken: Kosten der JSON-Übergabe bei grossen Projekten (Teil-Updates statt Neuaufbau), Struktur-Sharing im
|
||||
@@ -347,7 +361,7 @@ Entscheid CLA vs. Verzicht auf Dual Licensing.
|
||||
- ◐ **[6] Jede Aktion ist ein Befehl mit JSON-Parametern.** Registratur vorhanden, aber interaktiv;
|
||||
Panels/Griffe ändern das Projekt direkt. 28.10.: die häufigsten Aktionen (Griffe, Objekt-Info, Auswahl-Transformationen,
|
||||
Löschen, Zeichenbefehle) liefern ihre Änderung als JSON-Ops (`core/opsBuild.ts`, Store `applyChange`) — Grundlage für
|
||||
Makros/MCP; Rest-Liste unter [K4] S3. · L
|
||||
Makros/MCP; Rest (nur Laden/Import/CLI) unter [K4] S3. · L
|
||||
- ◐ **[7] Zentrale Validierung nach jedem Befehl.** 28.10.: jede Projektänderung wird im Kern geprüft (`ops.rs`, NaN/neue doppelte
|
||||
ids → Rücknahme mit Meldung); weitere Regeln (Bezüge, Geometrie) offen. · M
|
||||
- ◐ **[8] Undo über Befehle.** 28.10.: Verlauf im Rust-Kern als inverse Ops (coalesceKey, Gruppen, Speichergrenze), keine
|
||||
@@ -357,7 +371,7 @@ Entscheid CLA vs. Verzicht auf Dual Licensing.
|
||||
ArrayBuffer. Tests: `history.roundtrip.test.ts`, e2e „Mehrmals ganz zurück und wieder vor“.
|
||||
Snapshots mehr ([K4] S3). 28.10.: Griffe, Objekt-Info, Auswahl-Transformationen, Löschen und Zeichenbefehle erzeugen Ops
|
||||
direkt (`applyChange`/`opsMutation`); Gruppen mit Schlüssel: ein Griff-Zug mit mitgeführten Ecken = ein Schritt. Offen:
|
||||
Rest-Liste unter [K4] S3. · M
|
||||
Rest (nur Laden/Import/CLI) unter [K4] S3. · M
|
||||
- ◐ **[9] MCP-Brücke.** Headless `dossier-cli … mcp`; Brücke zum offenen Fenster fehlt. · M
|
||||
|
||||
### Daten
|
||||
|
||||
@@ -3711,6 +3711,7 @@ export default function App() {
|
||||
onEdit3dRoofPitch={onEdit3dRoofPitch}
|
||||
onEdit3dWallTop={onEdit3dWallTop}
|
||||
onEdit3dEnd={onEdit3dEnd}
|
||||
onEdit3dGroup={groupChanges}
|
||||
onGrip3dEditTab={cycleGrip3dEditField}
|
||||
onGrip3dEditCancel={cancelGrip3dEdit}
|
||||
/>
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
|
||||
import type { Drawing2D, DrawingLevel, Project } from "../model/types";
|
||||
import { t } from "../i18n";
|
||||
import { applyOps } from "../core/ops";
|
||||
import type { CoreOp } from "../core/ops";
|
||||
import { addItems } from "../core/opsBuild";
|
||||
import { layoutRoomProgram } from "./roomProgram";
|
||||
import type { LayoutGroup, LayoutItem, RoomProgramLayout } from "./roomProgram";
|
||||
|
||||
@@ -123,8 +126,13 @@ export function buildProgramSheet(project: Project, labels: SheetLabels, stamp:
|
||||
return { level, drawings, layout };
|
||||
}
|
||||
|
||||
/** Fügt das Blatt dem Projekt hinzu (für `setProject`); ohne Räume unverändert. */
|
||||
export function addProgramSheet(project: Project, sheet: ProgramSheet): Project {
|
||||
if (sheet.drawings.length === 0) return project;
|
||||
return { ...project, drawingLevels: [...project.drawingLevels, sheet.level], drawings2d: [...project.drawings2d, ...sheet.drawings] };
|
||||
/** Ops: fügt das Blatt (Ebene + Zeichnungen) hinzu; ohne Räume keine Ops. */
|
||||
export function addProgramSheetOps(sheet: ProgramSheet): CoreOp[] {
|
||||
if (sheet.drawings.length === 0) return [];
|
||||
return [...addItems("drawingLevels", [sheet.level]), ...addItems("drawings2d", sheet.drawings)];
|
||||
}
|
||||
|
||||
/** Wie {@link addProgramSheetOps}, als Projekt → Projekt (CLI, Tests); ohne Räume unverändert. */
|
||||
export function addProgramSheet(project: Project, sheet: ProgramSheet): Project {
|
||||
return applyOps(project, addProgramSheetOps(sheet));
|
||||
}
|
||||
+2
-2
@@ -25,10 +25,10 @@ export type { Project, DrawingLevel } from "../model/types";
|
||||
export { computeKennzahlen, checkRoomProgram, solidVolume } from "../analysis/kennzahlen";
|
||||
export type { Kennzahlen, ProgramCheck } from "../analysis/kennzahlen";
|
||||
export { compareRoomProgram, layoutRoomProgram, DEFAULT_PROGRAM_TOLERANCE } from "../analysis/roomProgram";
|
||||
export { buildProgramSheet, addProgramSheet, groupColor, defaultSheetLabels } from "../analysis/roomProgramSheet";
|
||||
export { buildProgramSheet, addProgramSheet, addProgramSheetOps, groupColor, defaultSheetLabels } from "../analysis/roomProgramSheet";
|
||||
export type { ProgramSheet, SheetLabels } from "../analysis/roomProgramSheet";
|
||||
export type { RoomProgramCompare, RoomProgramLayout, CompareRow, CompareSum, Light, LayoutItem, LayoutGroup } from "../analysis/roomProgram";
|
||||
export { readSheetFile, suggestMapping, mapRows, importedRows, applyRoomProgram, cellNumber, cellText, detectHeaderRow, parseKind, PROGRAM_FIELDS } from "../io/roomProgramImport";
|
||||
export { readSheetFile, suggestMapping, mapRows, importedRows, applyRoomProgram, roomProgramOps, cellNumber, cellText, detectHeaderRow, parseKind, PROGRAM_FIELDS } from "../io/roomProgramImport";
|
||||
export type { SheetData, SheetCell, Mapping, ColumnMap, ProgramField, ImportLine, ImportMode, SkipReason } from "../io/roomProgramImport";
|
||||
export { buildProgramReport } from "../export/programReport";
|
||||
export { computeAreaTable, computeIvhb } from "../analysis/areaTable";
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
|
||||
import type { Project, RoomProgramRow, SiaCategory } from "../model/types";
|
||||
import { fileio, loadFileio } from "../engine/fileioWasm";
|
||||
import { applyOps } from "../core/ops";
|
||||
import type { CoreOp } from "../core/ops";
|
||||
import { setField } from "../core/opsBuild";
|
||||
|
||||
export type SheetCell = string | number | null;
|
||||
|
||||
@@ -284,8 +287,13 @@ export function importedRows(lines: ImportLine[]): RoomProgramRow[] {
|
||||
|
||||
export type ImportMode = "replace" | "append";
|
||||
|
||||
/** Fügt Programmzeilen in das Projekt ein (für `setProject`): ersetzen oder anhängen. Keine Zeilen → unverändert. */
|
||||
export function applyRoomProgram(project: Project, rows: RoomProgramRow[], mode: ImportMode): Project {
|
||||
if (rows.length === 0) return project;
|
||||
return { ...project, roomProgram: mode === "append" ? [...(project.roomProgram ?? []), ...rows] : rows };
|
||||
/** Ops: Programmzeilen ins Projekt einfügen — ersetzen oder anhängen. Keine Zeilen → keine Ops. */
|
||||
export function roomProgramOps(project: Project, rows: RoomProgramRow[], mode: ImportMode): CoreOp[] {
|
||||
if (rows.length === 0) return [];
|
||||
return [setField("roomProgram", mode === "append" ? [...(project.roomProgram ?? []), ...rows] : rows)];
|
||||
}
|
||||
|
||||
/** Wie {@link roomProgramOps}, als Projekt → Projekt (CLI, Tests). Keine Zeilen → unverändert. */
|
||||
export function applyRoomProgram(project: Project, rows: RoomProgramRow[], mode: ImportMode): Project {
|
||||
return applyOps(project, roomProgramOps(project, rows, mode));
|
||||
}
|
||||
@@ -3,13 +3,17 @@ import {
|
||||
activePenSet,
|
||||
resolvePenColor,
|
||||
resolvePenWeight,
|
||||
rebakePenColors,
|
||||
rebakePenOps,
|
||||
generateStandardPenPalette,
|
||||
seedStandardPenSet,
|
||||
seedStandardPenSetOps,
|
||||
PEN_FALLBACK_COLOR,
|
||||
PEN_FALLBACK_WEIGHT,
|
||||
} from "./penSets";
|
||||
import type { Ceiling, Component, Drawing2D, LayerCategory, PenStyle, Project, Room, Wall } from "./types";
|
||||
import { applyOps } from "../core/ops";
|
||||
|
||||
const rebakePenColors = (p: Project): Project => applyOps(p, rebakePenOps(p));
|
||||
const seedStandardPenSet = (p: Project): Project => applyOps(p, seedStandardPenSetOps(p));
|
||||
|
||||
function baseProject(overrides: Partial<Project> = {}): Project {
|
||||
return {
|
||||
|
||||
+25
-21
@@ -15,6 +15,9 @@
|
||||
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import type { ColorPen, Component, LayerCategory, PenSet, PenStyle, Project } from "./types";
|
||||
import { applyOps } from "../core/ops";
|
||||
import type { CoreOp } from "../core/ops";
|
||||
import { addItems, fieldOps, patchItems, setFieldIfChanged } from "../core/opsBuild";
|
||||
|
||||
/** Farbe eines Stifts, der im aktiven Stiftsatz (noch) keinen Eintrag hat. */
|
||||
export const PEN_FALLBACK_COLOR = "#9aa0a6";
|
||||
@@ -122,15 +125,15 @@ export function generateStandardPenPalette(): { pens: ColorPen[]; styles: Record
|
||||
* eigene Stifte/Sätze existieren. Der neue Satz wird aktiv, wenn noch KEIN
|
||||
* Stiftsatz aktiv war (dieselbe Konvention wie `addPenSet`).
|
||||
*/
|
||||
export function seedStandardPenSet(project: Project): Project {
|
||||
export function seedStandardPenSetOps(project: Project): CoreOp[] {
|
||||
const { pens, styles } = generateStandardPenPalette();
|
||||
const penSet: PenSet = { id: `penset-${Date.now()}`, name: "Standard (CAD-Palette)", pens: styles };
|
||||
return rebakePenColors({
|
||||
...project,
|
||||
pens,
|
||||
penSets: [...(project.penSets ?? []), penSet],
|
||||
activePenSetId: project.activePenSetId ?? penSet.id,
|
||||
});
|
||||
const stateOps = [
|
||||
...fieldOps(project, "pens", pens),
|
||||
...addItems("penSets", [penSet]),
|
||||
...setFieldIfChanged(project, "activePenSetId", project.activePenSetId ?? penSet.id),
|
||||
];
|
||||
return [...stateOps, ...rebakePenOps(applyOps(project, stateOps))];
|
||||
}
|
||||
|
||||
/** Der aktuell aktive Stiftsatz, oder `undefined` (kein Stiftsatz angelegt/aktiviert). */
|
||||
@@ -236,18 +239,19 @@ function bakeElementColorAndWeight<
|
||||
* verschachtelt in `Project.layouts`) und `Tür`/`ExtrudedSolid`/Kontext-
|
||||
* Objekte — kein `colorPenId`-Feld dort (Scope-Entscheid, s. PENDENZEN.md).
|
||||
*/
|
||||
export function rebakePenColors(project: Project): Project {
|
||||
return {
|
||||
...project,
|
||||
components: project.components.map((c) => bakeComponent(project, c)),
|
||||
layers: project.layers.map((cat) => bakeCategory(project, cat)),
|
||||
walls: project.walls.map((w) => bakeElementColorAndWeight(project, w, "strokeWeight")),
|
||||
drawings2d: project.drawings2d.map((d) => bakeElementColorAndWeight(project, d, "weightMm")),
|
||||
ceilings: project.ceilings?.map((c) => bakeElementColorAndWeight(project, c, "strokeWeight")),
|
||||
columns: project.columns?.map((c) => bakeElementColorAndWeight(project, c, "strokeWeight")),
|
||||
roofs: project.roofs?.map((r) => bakeElementColor(project, r)),
|
||||
openings: project.openings?.map((o) => bakeElementColor(project, o)),
|
||||
stairs: project.stairs?.map((s) => bakeElementColor(project, s)),
|
||||
rooms: project.rooms?.map((r) => bakeElementColor(project, r)),
|
||||
};
|
||||
export function rebakePenOps(project: Project): CoreOp[] {
|
||||
const all = () => true;
|
||||
const layers = project.layers.map((cat) => bakeCategory(project, cat));
|
||||
return [
|
||||
...patchItems(project, "components", all, (c) => bakeComponent(project, c)),
|
||||
...(layers.every((c, i) => c === project.layers[i]) ? [] : fieldOps(project, "layers", layers)),
|
||||
...patchItems(project, "walls", all, (w) => bakeElementColorAndWeight(project, w, "strokeWeight")),
|
||||
...patchItems(project, "drawings2d", all, (d) => bakeElementColorAndWeight(project, d, "weightMm")),
|
||||
...patchItems(project, "ceilings", all, (c) => bakeElementColorAndWeight(project, c, "strokeWeight")),
|
||||
...patchItems(project, "columns", all, (c) => bakeElementColorAndWeight(project, c, "strokeWeight")),
|
||||
...patchItems(project, "roofs", all, (r) => bakeElementColor(project, r)),
|
||||
...patchItems(project, "openings", all, (o) => bakeElementColor(project, o)),
|
||||
...patchItems(project, "stairs", all, (s) => bakeElementColor(project, s)),
|
||||
...patchItems(project, "rooms", all, (r) => bakeElementColor(project, r)),
|
||||
];
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
// • Parzellenfläche: Eingabefeld → `Project.parcelArea` (leer/0 = aus der Parzellengrenze, sonst nicht gesetzt).
|
||||
// • Raumprogramm: Soll-Zeilen (Name, Fläche je Raum, Anzahl) bearbeiten; der Status je Zeile
|
||||
// kommt aus `checkRoomProgram`.
|
||||
// Änderungen laufen über `setProject` mit coalesceKey, damit Tippen einen Undo-Schritt ergibt.
|
||||
// Änderungen laufen über `applyChange` (Ops) mit coalesceKey, damit Tippen einen Undo-Schritt ergibt.
|
||||
|
||||
import { t } from "../i18n";
|
||||
import type { TranslationKey } from "../i18n";
|
||||
@@ -12,6 +12,7 @@ import { usePanelHost } from "./host";
|
||||
import { useStore } from "../state/appStore";
|
||||
import { checkRoomProgram, computeKennzahlen, polygonArea } from "../core";
|
||||
import type { Project, RoomProgramRow } from "../model/types";
|
||||
import { setField, setFieldIfChanged } from "../core";
|
||||
import { RoomProgramImportButton } from "../ui/RoomProgramImportDialog";
|
||||
import { ProgramCompareSection } from "./ProgramCompareSection";
|
||||
|
||||
@@ -41,7 +42,7 @@ const fmt = (n: number, d = 1) => n.toLocaleString("de-CH", { minimumFractionDig
|
||||
|
||||
export function KennzahlenSection() {
|
||||
const host = usePanelHost();
|
||||
const setProject = useStore((s) => s.setProject);
|
||||
const applyChange = useStore((s) => s.applyChange);
|
||||
const notify = useStore((s) => s.notify);
|
||||
const project = host.project;
|
||||
const k = computeKennzahlen(project);
|
||||
@@ -50,22 +51,18 @@ export function KennzahlenSection() {
|
||||
|
||||
const setParcel = (text: string) => {
|
||||
const v = parseNum(text);
|
||||
setProject((p: Project) => {
|
||||
const { parcelArea: _old, ...rest } = p;
|
||||
return v !== null && v > 0 ? { ...rest, parcelArea: v } : rest;
|
||||
}, "parcelArea");
|
||||
applyChange((p: Project) => setFieldIfChanged(p, "parcelArea", v !== null && v > 0 ? v : undefined), "parcelArea");
|
||||
};
|
||||
const patchRow = (i: number, patch: Partial<RoomProgramRow>, field: string) =>
|
||||
setProject(
|
||||
(p: Project) => ({ ...p, roomProgram: (p.roomProgram ?? []).map((r, j) => (j === i ? { ...r, ...patch } : r)) }),
|
||||
applyChange(
|
||||
(p: Project) => [setField("roomProgram", (p.roomProgram ?? []).map((r, j) => (j === i ? { ...r, ...patch } : r)))],
|
||||
`roomProgram:${i}:${field}`,
|
||||
);
|
||||
const addRow = () => setProject((p: Project) => ({ ...p, roomProgram: [...(p.roomProgram ?? []), { name: "", area: 20, count: 1 }] }));
|
||||
const addRow = () => applyChange((p: Project) => [setField("roomProgram", [...(p.roomProgram ?? []), { name: "", area: 20, count: 1 }])]);
|
||||
const removeRow = (i: number) =>
|
||||
setProject((p: Project) => {
|
||||
applyChange((p: Project) => {
|
||||
const next = (p.roomProgram ?? []).filter((_, j) => j !== i);
|
||||
const { roomProgram: _old, ...rest } = p;
|
||||
return next.length > 0 ? { ...rest, roomProgram: next } : rest;
|
||||
return setFieldIfChanged(p, "roomProgram", next.length > 0 ? next : undefined);
|
||||
});
|
||||
|
||||
const tiles: { label: string; value: string; title: TranslationKey }[] = [
|
||||
@@ -182,7 +179,7 @@ export function KennzahlenSection() {
|
||||
<button type="button" className="kz-add" onClick={addRow}>
|
||||
{t("program.add")}
|
||||
</button>
|
||||
<RoomProgramImportButton project={project} onApply={(fn) => setProject(fn)} notify={notify} />
|
||||
<RoomProgramImportButton project={project} onApply={(build) => applyChange(build)} notify={notify} />
|
||||
</div>
|
||||
{rows.length > 0 && <ProgramCompareSection statusLabel={programStatusLabel} />}
|
||||
</div>
|
||||
|
||||
@@ -11,7 +11,7 @@ import { t } from "../i18n";
|
||||
import type { TranslationKey } from "../i18n";
|
||||
import { usePanelHost } from "./host";
|
||||
import { useStore } from "../state/appStore";
|
||||
import { addProgramSheet, areaReportToCsv, buildAreaReportPdf, buildProgramReport, buildProgramSheet, compareRoomProgram, defaultSheetLabels, DEFAULT_PROGRAM_TOLERANCE } from "../core";
|
||||
import { addProgramSheetOps, areaReportToCsv, buildAreaReportPdf, buildProgramReport, buildProgramSheet, compareRoomProgram, defaultSheetLabels, DEFAULT_PROGRAM_TOLERANCE, setFieldIfChanged } from "../core";
|
||||
import type { CompareRow, CompareSum, Light } from "../core";
|
||||
import type { Project } from "../model/types";
|
||||
import { downloadCsv } from "./downloadFile";
|
||||
@@ -41,7 +41,7 @@ function SumRow({ s, label, total }: { s: CompareSum; label: string; total?: boo
|
||||
export function ProgramCompareSection({ statusLabel }: { statusLabel: (status: CompareRow["status"]) => string }) {
|
||||
const host = usePanelHost();
|
||||
const project = host.project;
|
||||
const setProject = useStore((s) => s.setProject);
|
||||
const applyChange = useStore((s) => s.applyChange);
|
||||
const notify = useStore((s) => s.notify);
|
||||
const c = compareRoomProgram(project);
|
||||
if (c.rows.length === 0) return null;
|
||||
@@ -51,10 +51,11 @@ export function ProgramCompareSection({ statusLabel }: { statusLabel: (status: C
|
||||
|
||||
const setTolerance = (text: string) => {
|
||||
const v = Number(text.trim().replace(",", "."));
|
||||
setProject((p: Project) => {
|
||||
const { roomProgramTolerance: _old, ...rest } = p;
|
||||
return text.trim() !== "" && Number.isFinite(v) && v >= 0 && v <= 100 ? { ...rest, roomProgramTolerance: v / 100 } : rest;
|
||||
}, "roomProgramTolerance");
|
||||
applyChange(
|
||||
(p: Project) =>
|
||||
setFieldIfChanged(p, "roomProgramTolerance", text.trim() !== "" && Number.isFinite(v) && v >= 0 && v <= 100 ? v / 100 : undefined),
|
||||
"roomProgramTolerance",
|
||||
);
|
||||
};
|
||||
|
||||
const exportPdf = () => {
|
||||
@@ -71,8 +72,8 @@ export function ProgramCompareSection({ statusLabel }: { statusLabel: (status: C
|
||||
notify(t("program.generate.none"), "warning");
|
||||
return;
|
||||
}
|
||||
// Ein setProject = ein Undo-Schritt: Ebene und alle Zeichnungen zusammen.
|
||||
setProject((p: Project) => addProgramSheet(p, sheet));
|
||||
// Ein applyChange = ein Undo-Schritt: Ebene und alle Zeichnungen zusammen.
|
||||
applyChange(addProgramSheetOps(sheet));
|
||||
host.onSelectLevel(sheet.level.id);
|
||||
notify(t("program.generate.done", { n: sheet.layout.items.length, name: sheet.level.name }));
|
||||
};
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import { t } from "../i18n";
|
||||
import { usePanelHost } from "./host";
|
||||
import { useStore } from "../state/appStore";
|
||||
import { checkSiteRules } from "../core";
|
||||
import { checkSiteRules, setField } from "../core";
|
||||
import type { Project, SiteRules } from "../model/types";
|
||||
import { lineFromDrawing, parcelFromDrawing } from "./siteRulesInput";
|
||||
|
||||
@@ -20,7 +20,7 @@ function parseLen(text: string): number | undefined | null {
|
||||
|
||||
export function SiteRulesSection() {
|
||||
const host = usePanelHost();
|
||||
const setProject = useStore((s) => s.setProject);
|
||||
const applyChange = useStore((s) => s.applyChange);
|
||||
const rules = host.project.siteRules;
|
||||
const sel = host.selection;
|
||||
const selDrawing = sel?.kind === "drawing2d" ? host.project.drawings2d.find((d) => d.id === sel.id) : undefined;
|
||||
@@ -28,19 +28,18 @@ export function SiteRulesSection() {
|
||||
const selLine = lineFromDrawing(selDrawing);
|
||||
|
||||
const write = (fn: (r: SiteRules) => SiteRules | undefined, key?: string) =>
|
||||
setProject((p: Project) => {
|
||||
const { siteRules: old, ...rest } = p;
|
||||
if (!old) return p;
|
||||
const next = fn(old);
|
||||
return next ? { ...rest, siteRules: next } : rest;
|
||||
applyChange((p: Project) => {
|
||||
const old = p.siteRules;
|
||||
if (!old) return [];
|
||||
return [setField("siteRules", fn(old))];
|
||||
}, key);
|
||||
|
||||
const takeParcel = () => {
|
||||
if (!selParcel) return;
|
||||
setProject((p: Project) => {
|
||||
applyChange((p: Project) => {
|
||||
// Neue Grenze: Grenzabstände je Kante passen nicht mehr → zurücksetzen.
|
||||
const { setbacks: _old, ...prev } = p.siteRules ?? { parcel: [], defaultSetback: 4 };
|
||||
return { ...p, siteRules: { ...prev, parcel: selParcel } };
|
||||
return [setField("siteRules", { ...prev, parcel: selParcel })];
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
import { t } from "../i18n";
|
||||
import { usePanelHost } from "./host";
|
||||
import { useStore } from "../state/appStore";
|
||||
import { projectLatLon, sunPosition } from "../core";
|
||||
import type { Project, SunStudy } from "../model/types";
|
||||
import { projectLatLon, setField, sunPosition } from "../core";
|
||||
import type { SunStudy } from "../model/types";
|
||||
import { defaultStudyIso, formatMinutes, isoToLocal, localToIso } from "./sunStudyTime";
|
||||
|
||||
/** Merkdaten: Tagundnachtgleiche, Sommer- und Wintersonnenwende (Tag/Monat). */
|
||||
@@ -18,11 +18,11 @@ const PRESETS: { key: "sun.equinox" | "sun.summer" | "sun.winter"; md: string }[
|
||||
|
||||
export function SunStudySection() {
|
||||
const host = usePanelHost();
|
||||
const setProject = useStore((s) => s.setProject);
|
||||
const applyChange = useStore((s) => s.applyChange);
|
||||
const study: SunStudy = host.project.sunStudy ?? { when: defaultStudyIso(), show: false };
|
||||
const local = isoToLocal(study.when) ?? isoToLocal(defaultStudyIso())!;
|
||||
|
||||
const write = (next: SunStudy, key?: string) => setProject((p: Project) => ({ ...p, sunStudy: next }), key);
|
||||
const write = (next: SunStudy, key?: string) => applyChange([setField("sunStudy", next)], key);
|
||||
const setLocal = (date: string, minutes: number, key?: string) => {
|
||||
const iso = localToIso({ date, minutes });
|
||||
if (iso) write({ ...study, when: iso }, key);
|
||||
|
||||
@@ -48,13 +48,13 @@ const store = createStore<RootState>((api) => ({
|
||||
...createSelectionSlice(api as unknown as StoreApi<SelectionSlice>),
|
||||
...createViewSlice(api as unknown as StoreApi<ViewSlice>),
|
||||
...createLayoutSlice(api as unknown as StoreApi<LayoutSlice>),
|
||||
// Site-/Kontext-Slice liest `project` und schreibt über `setProject`
|
||||
// Site-/Kontext-Slice liest `project` und schreibt über `applyChange`
|
||||
// (beide aus der Projekt-Slice) — daher die kombinierte Sicht im Cast.
|
||||
...createSiteSlice(
|
||||
api as unknown as StoreApi<
|
||||
SiteSlice & {
|
||||
project: ProjectSlice["project"];
|
||||
setProject: ProjectSlice["setProject"];
|
||||
applyChange: ProjectSlice["applyChange"];
|
||||
}
|
||||
>,
|
||||
),
|
||||
|
||||
+101
-171
@@ -8,7 +8,7 @@
|
||||
// laufen. Die Slice tippt daher nur ihre eigenen Felder; `get()` liefert
|
||||
// RootState (siehe appStore.ts), wir greifen punktuell auf View-Felder zu.
|
||||
|
||||
import { diffToOps } from "../core/ops";
|
||||
import { applyOps, diffToOps } from "../core/ops";
|
||||
import type { CoreOp } from "../core/ops";
|
||||
import {
|
||||
addItems,
|
||||
@@ -17,7 +17,9 @@ import {
|
||||
patchItem,
|
||||
patchItems,
|
||||
removeItems,
|
||||
replaceItem,
|
||||
setField,
|
||||
setFieldIfChanged,
|
||||
} from "../core";
|
||||
import { withVertexType, type PolylineVertexType } from "../core";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
@@ -40,8 +42,8 @@ import type {
|
||||
} from "../model/types";
|
||||
import {
|
||||
activePenSet,
|
||||
rebakePenColors,
|
||||
seedStandardPenSet as buildStandardPenSet,
|
||||
rebakePenOps,
|
||||
seedStandardPenSetOps,
|
||||
PEN_FALLBACK_COLOR,
|
||||
PEN_FALLBACK_WEIGHT,
|
||||
} from "../model/penSets";
|
||||
@@ -764,18 +766,12 @@ export function createProjectSlice(
|
||||
),
|
||||
|
||||
// ── Ressourcen ─────────────────────────────────────────────────────────
|
||||
patchComponent: (id, patch) =>
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
components: p.components.map((c) =>
|
||||
c.id === id ? { ...c, ...patch } : c,
|
||||
),
|
||||
})),
|
||||
patchComponent: (id, patch) => applyChange((p) => patchItem(p, "components", id, patch)),
|
||||
|
||||
addComponent: () =>
|
||||
setProject((p) => {
|
||||
let hatches = p.hatches;
|
||||
let hatchId = hatches[0]?.id;
|
||||
applyChange((p) => {
|
||||
const ops: CoreOp[] = [];
|
||||
let hatchId = p.hatches[0]?.id;
|
||||
if (!hatchId) {
|
||||
const fallback: HatchStyle = {
|
||||
id: `hatch-${Date.now()}`,
|
||||
@@ -785,7 +781,7 @@ export function createProjectSlice(
|
||||
angle: 0,
|
||||
color: "#2b3039",
|
||||
};
|
||||
hatches = [fallback];
|
||||
ops.push(...fieldOps(p, "hatches", [fallback]));
|
||||
hatchId = fallback.id;
|
||||
}
|
||||
const component: Component = {
|
||||
@@ -795,30 +791,26 @@ export function createProjectSlice(
|
||||
hatchId,
|
||||
joinPriority: 50,
|
||||
};
|
||||
return { ...p, hatches, components: [...p.components, component] };
|
||||
return [...ops, ...addItems("components", [component])];
|
||||
}),
|
||||
|
||||
deleteComponent: (id) =>
|
||||
setProject((p) => {
|
||||
applyChange((p) => {
|
||||
const used = p.wallTypes.some((wt) =>
|
||||
wt.layers.some((l) => l.componentId === id),
|
||||
);
|
||||
if (used) {
|
||||
const name = p.components.find((c) => c.id === id)?.name ?? id;
|
||||
get().notify(t("alert.componentInUse", { name }), "warning");
|
||||
return p;
|
||||
return [];
|
||||
}
|
||||
return { ...p, components: p.components.filter((c) => c.id !== id) };
|
||||
return removeItems(p, "components", [id]);
|
||||
}),
|
||||
|
||||
patchHatch: (id, patch) =>
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
hatches: p.hatches.map((h) => (h.id === id ? { ...h, ...patch } : h)),
|
||||
})),
|
||||
patchHatch: (id, patch) => applyChange((p) => patchItem(p, "hatches", id, patch)),
|
||||
|
||||
addHatch: () =>
|
||||
setProject((p) => {
|
||||
applyChange((p) => {
|
||||
const hatch: HatchStyle = {
|
||||
id: `hatch-${Date.now()}`,
|
||||
name: t("default.hatchName"),
|
||||
@@ -828,30 +820,24 @@ export function createProjectSlice(
|
||||
color: "#2b3039",
|
||||
lineStyleId: p.lineStyles[0]?.id,
|
||||
};
|
||||
return { ...p, hatches: [...p.hatches, hatch] };
|
||||
return addItems("hatches", [hatch]);
|
||||
}),
|
||||
|
||||
deleteHatch: (id) =>
|
||||
setProject((p) => {
|
||||
applyChange((p) => {
|
||||
const used = p.components.some((c) => c.hatchId === id);
|
||||
if (used) {
|
||||
const name = p.hatches.find((h) => h.id === id)?.name ?? id;
|
||||
get().notify(t("alert.hatchInUse", { name }), "warning");
|
||||
return p;
|
||||
return [];
|
||||
}
|
||||
return { ...p, hatches: p.hatches.filter((h) => h.id !== id) };
|
||||
return removeItems(p, "hatches", [id]);
|
||||
}),
|
||||
|
||||
patchLineStyle: (id, patch) =>
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
lineStyles: p.lineStyles.map((l) =>
|
||||
l.id === id ? { ...l, ...patch } : l,
|
||||
),
|
||||
})),
|
||||
patchLineStyle: (id, patch) => applyChange((p) => patchItem(p, "lineStyles", id, patch)),
|
||||
|
||||
addLineStyle: () =>
|
||||
setProject((p) => {
|
||||
applyChange(() => {
|
||||
const lineStyle: LineStyle = {
|
||||
id: `line-${Date.now()}`,
|
||||
name: t("default.lineStyleName"),
|
||||
@@ -859,87 +845,70 @@ export function createProjectSlice(
|
||||
color: "#2b3039",
|
||||
dash: null,
|
||||
};
|
||||
return { ...p, lineStyles: [...p.lineStyles, lineStyle] };
|
||||
return addItems("lineStyles", [lineStyle]);
|
||||
}),
|
||||
|
||||
deleteLineStyle: (id) =>
|
||||
setProject((p) => {
|
||||
applyChange((p) => {
|
||||
const used = p.hatches.some((h) => h.lineStyleId === id);
|
||||
if (used) {
|
||||
const name = p.lineStyles.find((l) => l.id === id)?.name ?? id;
|
||||
get().notify(t("alert.lineStyleInUse", { name }), "warning");
|
||||
return p;
|
||||
return [];
|
||||
}
|
||||
return { ...p, lineStyles: p.lineStyles.filter((l) => l.id !== id) };
|
||||
return removeItems(p, "lineStyles", [id]);
|
||||
}),
|
||||
|
||||
importLineStyles: (styles) =>
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
lineStyles: [
|
||||
...p.lineStyles,
|
||||
...styles.map((s, i) => ({ ...s, id: `ls-${Date.now()}-${i}` })),
|
||||
],
|
||||
})),
|
||||
applyChange(addItems("lineStyles", styles.map((s, i) => ({ ...s, id: `ls-${Date.now()}-${i}` })))),
|
||||
|
||||
patchTextStyle: (id, patch) =>
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
textStyles: (p.textStyles ?? DEFAULT_PRESETS).map((s) =>
|
||||
s.id === id ? { ...s, ...patch, marks: { ...s.marks, ...patch.marks } } : s,
|
||||
applyChange((p) =>
|
||||
fieldOps(
|
||||
p,
|
||||
"textStyles",
|
||||
(p.textStyles ?? DEFAULT_PRESETS).map((s) =>
|
||||
s.id === id ? { ...s, ...patch, marks: { ...s.marks, ...patch.marks } } : s,
|
||||
),
|
||||
),
|
||||
})),
|
||||
),
|
||||
|
||||
addTextStyle: () =>
|
||||
setProject((p) => {
|
||||
applyChange((p) => {
|
||||
const style: TextStylePreset = {
|
||||
id: `ts-${Date.now()}`,
|
||||
label: t("default.textStyleName"),
|
||||
marks: { sizePt: 10 },
|
||||
};
|
||||
return { ...p, textStyles: [...(p.textStyles ?? DEFAULT_PRESETS), style] };
|
||||
return fieldOps(p, "textStyles", [...(p.textStyles ?? DEFAULT_PRESETS), style]);
|
||||
}),
|
||||
|
||||
deleteTextStyle: (id) =>
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
textStyles: (p.textStyles ?? DEFAULT_PRESETS).filter((s) => s.id !== id),
|
||||
})),
|
||||
applyChange((p) => fieldOps(p, "textStyles", (p.textStyles ?? DEFAULT_PRESETS).filter((s) => s.id !== id))),
|
||||
|
||||
importHatches: (hatches) =>
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
hatches: [
|
||||
...p.hatches,
|
||||
...hatches.map((h, i) => ({ ...h, id: `ht-${Date.now()}-${i}` })),
|
||||
],
|
||||
})),
|
||||
applyChange(addItems("hatches", hatches.map((h, i) => ({ ...h, id: `ht-${Date.now()}-${i}` })))),
|
||||
|
||||
// ── Stiftsätze ─────────────────────────────────────────────────────────
|
||||
addPen: () =>
|
||||
setProject((p) => {
|
||||
applyChange((p) => {
|
||||
const pen: ColorPen = { id: `pen-${Date.now()}`, name: t("default.penName") };
|
||||
return {
|
||||
...p,
|
||||
pens: [...(p.pens ?? []), pen],
|
||||
return [
|
||||
...addItems("pens", [pen]),
|
||||
// Neuer Stift bekommt in JEDEM bestehenden Stiftsatz sofort einen
|
||||
// Eintrag (Fallback-Grauton+Stärke) — Stiftsätze bleiben dadurch
|
||||
// immer deckungsgleich zur `pens`-Liste, keine "fehlt in Satz X"-Lücken.
|
||||
penSets: p.penSets?.map((s) => ({
|
||||
...patchItems(p, "penSets", () => true, (s) => ({
|
||||
...s,
|
||||
pens: { ...s.pens, [pen.id]: { color: PEN_FALLBACK_COLOR, weight: PEN_FALLBACK_WEIGHT } },
|
||||
})),
|
||||
};
|
||||
];
|
||||
}),
|
||||
|
||||
renamePen: (id, name) =>
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
pens: p.pens?.map((pen) => (pen.id === id ? { ...pen, name } : pen)),
|
||||
})),
|
||||
renamePen: (id, name) => applyChange((p) => patchItem(p, "pens", id, { name })),
|
||||
|
||||
deletePen: (id) =>
|
||||
setProject((p) => {
|
||||
applyChange((p) => {
|
||||
const clearPenRefs = <T extends { colorPenId?: string; foregroundPenId?: string; backgroundPenId?: string }>(x: T): T =>
|
||||
x.colorPenId === id || x.foregroundPenId === id || x.backgroundPenId === id
|
||||
? {
|
||||
@@ -953,20 +922,19 @@ export function createProjectSlice(
|
||||
...(cat.colorPenId === id ? { ...cat, colorPenId: undefined } : cat),
|
||||
...(cat.children ? { children: cat.children.map(clearCategoryPenRefs) } : {}),
|
||||
});
|
||||
return {
|
||||
...p,
|
||||
pens: p.pens?.filter((pen) => pen.id !== id),
|
||||
penSets: p.penSets?.map((s) => {
|
||||
return [
|
||||
...removeItems(p, "pens", [id]),
|
||||
...patchItems(p, "penSets", () => true, (s) => {
|
||||
const { [id]: _removed, ...rest } = s.pens;
|
||||
return { ...s, pens: rest };
|
||||
}),
|
||||
components: p.components.map(clearPenRefs),
|
||||
layers: p.layers.map(clearCategoryPenRefs),
|
||||
};
|
||||
...patchItems(p, "components", () => true, clearPenRefs),
|
||||
...fieldOps(p, "layers", p.layers.map(clearCategoryPenRefs)),
|
||||
];
|
||||
}),
|
||||
|
||||
addPenSet: () =>
|
||||
setProject((p) => {
|
||||
applyChange((p) => {
|
||||
const current = activePenSet(p);
|
||||
const penSet: PenSet = {
|
||||
id: `penset-${Date.now()}`,
|
||||
@@ -977,128 +945,90 @@ export function createProjectSlice(
|
||||
(p.pens ?? []).map((pen) => [pen.id, { color: PEN_FALLBACK_COLOR, weight: PEN_FALLBACK_WEIGHT }]),
|
||||
),
|
||||
};
|
||||
const penSets = [...(p.penSets ?? []), penSet];
|
||||
// Erster Stiftsatz überhaupt: automatisch aktivieren (sonst löst jeder
|
||||
// Stift-Verweis bis zur ersten manuellen Aktivierung auf den Fallback auf).
|
||||
return {
|
||||
...p,
|
||||
penSets,
|
||||
activePenSetId: p.activePenSetId ?? penSet.id,
|
||||
};
|
||||
return [
|
||||
...addItems("penSets", [penSet]),
|
||||
...setFieldIfChanged(p, "activePenSetId", p.activePenSetId ?? penSet.id),
|
||||
];
|
||||
}),
|
||||
|
||||
renamePenSet: (id, name) =>
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
penSets: p.penSets?.map((s) => (s.id === id ? { ...s, name } : s)),
|
||||
})),
|
||||
renamePenSet: (id, name) => applyChange((p) => patchItem(p, "penSets", id, { name })),
|
||||
|
||||
deletePenSet: (id) =>
|
||||
setProject((p) => {
|
||||
applyChange((p) => {
|
||||
if (p.activePenSetId === id) {
|
||||
const name = p.penSets?.find((s) => s.id === id)?.name ?? id;
|
||||
get().notify(t("alert.penSetIsActive", { name }), "warning");
|
||||
return p;
|
||||
return [];
|
||||
}
|
||||
return { ...p, penSets: p.penSets?.filter((s) => s.id !== id) };
|
||||
return removeItems(p, "penSets", [id]);
|
||||
}),
|
||||
|
||||
setActivePenSet: (id) =>
|
||||
setProject((p) => rebakePenColors({ ...p, activePenSetId: id })),
|
||||
applyChange((p) => {
|
||||
const stateOps = [setField("activePenSetId", id)];
|
||||
return [...stateOps, ...rebakePenOps(applyOps(p, stateOps))];
|
||||
}),
|
||||
|
||||
patchPenSetColor: (setId, penId, color) =>
|
||||
setProject((p) => {
|
||||
const next = {
|
||||
...p,
|
||||
penSets: p.penSets?.map((s) =>
|
||||
s.id === setId
|
||||
? {
|
||||
...s,
|
||||
pens: {
|
||||
...s.pens,
|
||||
[penId]: { ...(s.pens[penId] ?? { color: PEN_FALLBACK_COLOR, weight: PEN_FALLBACK_WEIGHT }), color },
|
||||
},
|
||||
}
|
||||
: s,
|
||||
),
|
||||
};
|
||||
return setId === p.activePenSetId ? rebakePenColors(next) : next;
|
||||
applyChange((p) => {
|
||||
const stateOps = patchItem(p, "penSets", setId, (s) => ({
|
||||
...s,
|
||||
pens: {
|
||||
...s.pens,
|
||||
[penId]: { ...(s.pens[penId] ?? { color: PEN_FALLBACK_COLOR, weight: PEN_FALLBACK_WEIGHT }), color },
|
||||
},
|
||||
}));
|
||||
return setId === p.activePenSetId ? [...stateOps, ...rebakePenOps(applyOps(p, stateOps))] : stateOps;
|
||||
}),
|
||||
|
||||
patchPenSetWeight: (setId, penId, weight) =>
|
||||
setProject((p) => {
|
||||
const next = {
|
||||
...p,
|
||||
penSets: p.penSets?.map((s) =>
|
||||
s.id === setId
|
||||
? {
|
||||
...s,
|
||||
pens: {
|
||||
...s.pens,
|
||||
[penId]: { ...(s.pens[penId] ?? { color: PEN_FALLBACK_COLOR, weight: PEN_FALLBACK_WEIGHT }), weight },
|
||||
},
|
||||
}
|
||||
: s,
|
||||
),
|
||||
};
|
||||
return setId === p.activePenSetId ? rebakePenColors(next) : next;
|
||||
applyChange((p) => {
|
||||
const stateOps = patchItem(p, "penSets", setId, (s) => ({
|
||||
...s,
|
||||
pens: {
|
||||
...s.pens,
|
||||
[penId]: { ...(s.pens[penId] ?? { color: PEN_FALLBACK_COLOR, weight: PEN_FALLBACK_WEIGHT }), weight },
|
||||
},
|
||||
}));
|
||||
return setId === p.activePenSetId ? [...stateOps, ...rebakePenOps(applyOps(p, stateOps))] : stateOps;
|
||||
}),
|
||||
|
||||
seedStandardPenSet: () => setProject((p) => buildStandardPenSet(p)),
|
||||
seedStandardPenSet: () => applyChange((p) => seedStandardPenSetOps(p)),
|
||||
|
||||
addCustomPalette: () =>
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
customPalettes: [
|
||||
...(p.customPalettes ?? []),
|
||||
{ id: `palette-${Date.now()}`, name: t("default.customPaletteName"), colors: [] },
|
||||
],
|
||||
})),
|
||||
applyChange(
|
||||
addItems("customPalettes", [{ id: `palette-${Date.now()}`, name: t("default.customPaletteName"), colors: [] }]),
|
||||
),
|
||||
|
||||
renameCustomPalette: (id, name) =>
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
customPalettes: p.customPalettes?.map((c) => (c.id === id ? { ...c, name } : c)),
|
||||
})),
|
||||
renameCustomPalette: (id, name) => applyChange((p) => patchItem(p, "customPalettes", id, { name })),
|
||||
|
||||
deleteCustomPalette: (id) =>
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
customPalettes: p.customPalettes?.filter((c) => c.id !== id),
|
||||
})),
|
||||
deleteCustomPalette: (id) => applyChange((p) => removeItems(p, "customPalettes", [id])),
|
||||
|
||||
addColorToCustomPalette: (paletteId, hex) =>
|
||||
setProject((p) => {
|
||||
const palettes = p.customPalettes ?? [];
|
||||
const target = palettes.find((c) => c.id === paletteId);
|
||||
applyChange((p) => {
|
||||
const target = (p.customPalettes ?? []).find((c) => c.id === paletteId);
|
||||
if (!target) {
|
||||
const created = { id: `palette-${Date.now()}`, name: t("default.customPaletteName"), colors: [hex] };
|
||||
return { ...p, customPalettes: [...palettes, created] };
|
||||
return addItems("customPalettes", [created]);
|
||||
}
|
||||
const withoutDupe = target.colors.filter((c) => c.toLowerCase() !== hex.toLowerCase());
|
||||
const updated = { ...target, colors: [hex, ...withoutDupe] };
|
||||
return { ...p, customPalettes: palettes.map((c) => (c.id === target.id ? updated : c)) };
|
||||
return [replaceItem("customPalettes", { ...target, colors: [hex, ...withoutDupe] })];
|
||||
}),
|
||||
|
||||
removeColorFromCustomPalette: (paletteId, hex) =>
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
customPalettes: p.customPalettes?.map((c) =>
|
||||
c.id === paletteId ? { ...c, colors: c.colors.filter((h) => h.toLowerCase() !== hex.toLowerCase()) } : c,
|
||||
),
|
||||
})),
|
||||
applyChange((p) =>
|
||||
patchItem(p, "customPalettes", paletteId, (c) => ({
|
||||
...c,
|
||||
colors: c.colors.filter((h) => h.toLowerCase() !== hex.toLowerCase()),
|
||||
})),
|
||||
),
|
||||
|
||||
setCustomPaletteVisible: (id, visible) =>
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
customPalettes: p.customPalettes?.map((c) => (c.id === id ? { ...c, visible } : c)),
|
||||
})),
|
||||
setCustomPaletteVisible: (id, visible) => applyChange((p) => patchItem(p, "customPalettes", id, { visible })),
|
||||
|
||||
setBuiltinPaletteVisible: (bank, visible) =>
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
builtinPaletteBanks: { ...p.builtinPaletteBanks, [bank]: visible },
|
||||
})),
|
||||
applyChange((p) => [setField("builtinPaletteBanks", { ...p.builtinPaletteBanks, [bank]: visible })]),
|
||||
|
||||
insertDrawingPoint: (drawingId, segIndex, pt) =>
|
||||
applyChange((p) =>
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
// Ressourcen, Stifte/Paletten, Text-Stile, Kontext-Schicht und 3D-Griffe laufen über Ops ([K4] S3):
|
||||
// jede Aktion = genau ein Undo-Schritt, Ergebnis wie erwartet. Beim Umbau wurden 37 Schritte dieser Aktionen
|
||||
// gegen die alte setProject-Fassung (git HEAD) verglichen: Projekt, Undo-Tiefe und Meldungen gleich.
|
||||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
import { getState } from "./appStore";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import type { ContextObject, Project } from "../model/types";
|
||||
|
||||
const st = () => getState();
|
||||
|
||||
beforeEach(() => {
|
||||
const p: Project = {
|
||||
...structuredClone(sampleProject),
|
||||
components: sampleProject.components.map((c, i) => (i === 0 ? { ...c, colorPenId: "p1" } : c)),
|
||||
walls: sampleProject.walls.map((w, i) => (i === 0 ? { ...w, colorPenId: "p1" } : w)),
|
||||
};
|
||||
st().setProject(p);
|
||||
st().clearHistory();
|
||||
});
|
||||
|
||||
/** Eine Aktion → ein Undo-Schritt; Undo stellt das Projekt exakt wieder her. */
|
||||
function oneStep(label: string, act: () => void): void {
|
||||
const before = st().project;
|
||||
const depth = st().undoDepth;
|
||||
act();
|
||||
expect(st().undoDepth, label).toBe(depth + 1);
|
||||
st().undo();
|
||||
expect(JSON.parse(JSON.stringify(st().project)), label).toEqual(JSON.parse(JSON.stringify(before)));
|
||||
st().redo();
|
||||
}
|
||||
|
||||
describe("Ressourcen und Stiftsätze über Ops", () => {
|
||||
it("Bauteile, Schraffuren, Linienstile: anlegen, ändern, geschütztes Löschen", () => {
|
||||
const c0 = st().project.components[0].id;
|
||||
const h0 = st().project.hatches[0].id;
|
||||
oneStep("patchComponent", () => st().patchComponent(c0, { name: "X" }));
|
||||
expect(st().project.components[0].name).toBe("X");
|
||||
oneStep("addComponent", () => st().addComponent());
|
||||
expect(st().project.components).toHaveLength(sampleProject.components.length + 1);
|
||||
// Von einer Wandart verwendetes Bauteil: Meldung, keine Änderung, kein Undo-Schritt.
|
||||
const depth = st().undoDepth;
|
||||
st().deleteComponent(c0);
|
||||
expect(st().undoDepth).toBe(depth);
|
||||
oneStep("addHatch", () => st().addHatch());
|
||||
oneStep("patchHatch", () => st().patchHatch(h0, { scale: 3 }));
|
||||
oneStep("addLineStyle", () => st().addLineStyle());
|
||||
oneStep("importHatches", () => st().importHatches([{ name: "H", pattern: "diagonal", scale: 1, angle: 0, color: "#000" }]));
|
||||
});
|
||||
|
||||
it("Text-Stile: die Vorgaben werden beim ersten Ändern ins Projekt übernommen", () => {
|
||||
expect(st().project.textStyles).toBeUndefined();
|
||||
oneStep("addTextStyle", () => st().addTextStyle());
|
||||
expect(st().project.textStyles!.length).toBeGreaterThan(1);
|
||||
const id = st().project.textStyles![0].id;
|
||||
oneStep("patchTextStyle", () => st().patchTextStyle(id, { label: "Neu" }));
|
||||
expect(st().project.textStyles![0].label).toBe("Neu");
|
||||
});
|
||||
|
||||
it("Stifte: Stift anlegen, Stiftsatz aktivieren und Farbe ändern bäckt die Farben ein", () => {
|
||||
oneStep("addPen", () => st().addPen());
|
||||
oneStep("addPenSet", () => st().addPenSet());
|
||||
const setId = st().project.penSets![0].id;
|
||||
expect(st().project.activePenSetId).toBe(setId); // erster Satz wird aktiv
|
||||
oneStep("patchPenSetColor", () => st().patchPenSetColor(setId, "p1", "#123456"));
|
||||
// Bauteil und Wand mit `colorPenId: "p1"` tragen jetzt die gebackene Farbe — in einem Schritt.
|
||||
expect(st().project.components[0].color).toBe("#123456");
|
||||
expect(st().project.walls[0].color).toBe("#123456");
|
||||
oneStep("patchPenSetWeight", () => st().patchPenSetWeight(setId, "p1", 0.7));
|
||||
expect(st().project.walls[0].strokeWeight).toBe(0.7);
|
||||
oneStep("addPenSet 2", () => st().addPenSet());
|
||||
const set2 = st().project.penSets![1].id;
|
||||
oneStep("patchPenSetColor inaktiv", () => st().patchPenSetColor(set2, "p1", "#abcdef"));
|
||||
expect(st().project.walls[0].color).toBe("#123456"); // aktiver Satz unverändert
|
||||
oneStep("setActivePenSet", () => st().setActivePenSet(set2));
|
||||
expect(st().project.walls[0].color).toBe("#abcdef");
|
||||
// Aktiver Satz ist geschützt.
|
||||
const depth = st().undoDepth;
|
||||
st().deletePenSet(set2);
|
||||
expect(st().undoDepth).toBe(depth);
|
||||
oneStep("deletePen", () => st().deletePen("p1"));
|
||||
expect(st().project.components[0].colorPenId).toBeUndefined(); // Verweis gelöst, Farbe bleibt
|
||||
oneStep("seedStandardPenSet", () => st().seedStandardPenSet());
|
||||
expect(st().project.pens).toHaveLength(255);
|
||||
});
|
||||
|
||||
it("Farbpaletten", () => {
|
||||
oneStep("addCustomPalette", () => st().addCustomPalette());
|
||||
const id = st().project.customPalettes![0].id;
|
||||
oneStep("addColor", () => st().addColorToCustomPalette(id, "#ff0000"));
|
||||
oneStep("addColor 2", () => st().addColorToCustomPalette(id, "#00ff00"));
|
||||
oneStep("addColor Duplikat", () => st().addColorToCustomPalette(id, "#FF0000"));
|
||||
expect(st().project.customPalettes![0].colors).toEqual(["#FF0000", "#00ff00"]);
|
||||
oneStep("addColor neue Palette", () => st().addColorToCustomPalette(undefined, "#0000ff"));
|
||||
expect(st().project.customPalettes).toHaveLength(2);
|
||||
oneStep("removeColor", () => st().removeColorFromCustomPalette(id, "#00ff00"));
|
||||
oneStep("builtin", () => st().setBuiltinPaletteVisible("ral", false));
|
||||
expect(st().project.builtinPaletteBanks).toMatchObject({ ral: false });
|
||||
});
|
||||
});
|
||||
|
||||
describe("Kontext-Schicht über Ops", () => {
|
||||
const mesh = (id: string, categoryCode: string): ContextObject =>
|
||||
({ id, type: "importedMesh", name: id, positions: [0, 0, 0, 1, 0, 0, 0, 1, 0], indices: [0, 1, 2], categoryCode }) as unknown as ContextObject;
|
||||
|
||||
it("Hinzufügen ergänzt fehlende Kategorien, Entfernen und Leeren je ein Schritt", () => {
|
||||
const codes = (p: Project) => JSON.stringify(p.layers);
|
||||
const before = codes(st().project);
|
||||
oneStep("addContextObjects", () => st().addContextObjects([mesh("m1", "15"), mesh("m2", "15")]));
|
||||
expect(st().project.context!.map((o) => o.id)).toEqual(["m1", "m2"]);
|
||||
expect(codes(st().project)).not.toBe(before);
|
||||
oneStep("removeContextObject", () => st().removeContextObject("m1"));
|
||||
expect(st().project.context!.map((o) => o.id)).toEqual(["m2"]);
|
||||
oneStep("removeContextObjects", () => st().removeContextObjects(["m2"]));
|
||||
expect(st().project.context).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("3D-Griffe: Element und mitgeführte Ecken", () => {
|
||||
it("ein Zug mit mehreren Maus-Schritten = ein Undo-Schritt (Gruppe mit Schlüssel)", () => {
|
||||
const [a, b] = st().project.walls;
|
||||
const depth = st().undoDepth;
|
||||
for (let k = 1; k <= 6; k++) {
|
||||
st().groupChanges(() => {
|
||||
st().moveGripOf(null, a.id, 1, { x: a.end.x + k * 0.1, y: a.end.y });
|
||||
st().moveGripOf(null, b.id, 0, { x: a.end.x + k * 0.1, y: a.end.y });
|
||||
}, `grip3d:${a.id}:1`);
|
||||
}
|
||||
expect(st().undoDepth).toBe(depth + 1);
|
||||
expect(st().project.walls[0].end.x).toBeCloseTo(a.end.x + 0.6, 12);
|
||||
expect(st().project.walls[1].start.x).toBeCloseTo(a.end.x + 0.6, 12);
|
||||
st().undo();
|
||||
expect(st().project.walls[0].end).toEqual(a.end);
|
||||
expect(st().project.walls[1].start).toEqual(b.start);
|
||||
});
|
||||
});
|
||||
+13
-22
@@ -4,14 +4,15 @@
|
||||
//
|
||||
// Entwurfsentscheidung: `context` ist Teil von `project` (ein einziger
|
||||
// Wahrheits-Baum, konsistent mit projectSlice). Diese Slice MUTIERT daher
|
||||
// `project.context` IMMUTABEL über die vorhandene `setProject`-Aktion
|
||||
// (Cross-Slice), genau wie projectSlice ein neues Project-Objekt liefert. So
|
||||
// bleiben Persistenz/Undo später einheitlich am Project hängen.
|
||||
// `project.context` über die vorhandene `applyChange`-Aktion (Ops, Cross-Slice),
|
||||
// genau wie projectSlice. So bleiben Persistenz/Undo einheitlich am Project hängen.
|
||||
//
|
||||
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import { generateTerrainFromContours } from "../model/terrain";
|
||||
import type { ContextObject, Project } from "../model/types";
|
||||
import { addItems, fieldOps, removeItems } from "../core/opsBuild";
|
||||
import type { CoreOp } from "../core/ops";
|
||||
import { ensureContextCategories } from "../model/contextCategories";
|
||||
import type { StoreApi } from "./store";
|
||||
|
||||
@@ -38,12 +39,12 @@ export interface SiteSlice {
|
||||
|
||||
/**
|
||||
* Cross-Slice-Abhängigkeit: diese Slice liest `project` und schreibt es über
|
||||
* `setProject` (beide aus projectSlice). Der Store komponiert SiteSlice mit
|
||||
* `applyChange` (beide aus projectSlice). Der Store komponiert SiteSlice mit
|
||||
* dieser Sicht, sodass `get()`/Actions typsicher auf das Projekt zugreifen.
|
||||
*/
|
||||
type SiteSliceDeps = {
|
||||
project: Project;
|
||||
setProject: (next: Project | ((p: Project) => Project)) => void;
|
||||
applyChange: (ops: readonly CoreOp[] | ((p: Project) => readonly CoreOp[])) => void;
|
||||
};
|
||||
|
||||
export function createSiteSlice(
|
||||
@@ -51,13 +52,6 @@ export function createSiteSlice(
|
||||
): SiteSlice {
|
||||
const { get } = api;
|
||||
|
||||
// Immutabler Kontext-Updater: ersetzt `project.context` über die vorhandene
|
||||
// setProject-Aktion (konsistent mit projectSlice-Stil).
|
||||
const setContext = (
|
||||
update: (ctx: ContextObject[]) => ContextObject[],
|
||||
): void => {
|
||||
get().setProject((p) => ({ ...p, context: update(p.context ?? []) }));
|
||||
};
|
||||
|
||||
// Wie `setContext`, aber fürs HINZUFÜGEN: ergänzt zusätzlich jede fehlende
|
||||
// Grafik-Kategorie der neu ankommenden Objekte in `project.layers` (s.
|
||||
@@ -69,11 +63,10 @@ export function createSiteSlice(
|
||||
const codes = added
|
||||
.map((o) => o.categoryCode)
|
||||
.filter((c): c is string => !!c);
|
||||
get().setProject((p) => ({
|
||||
...p,
|
||||
context: [...(p.context ?? []), ...added],
|
||||
layers: ensureContextCategories(p.layers, codes),
|
||||
}));
|
||||
get().applyChange((p) => [
|
||||
...addItems("context", added),
|
||||
...fieldOps(p, "layers", ensureContextCategories(p.layers, codes)),
|
||||
]);
|
||||
};
|
||||
|
||||
return {
|
||||
@@ -81,13 +74,11 @@ export function createSiteSlice(
|
||||
|
||||
addContextObjects: (objs) => addToContext(objs),
|
||||
|
||||
removeContextObject: (id) =>
|
||||
setContext((ctx) => ctx.filter((o) => o.id !== id)),
|
||||
removeContextObject: (id) => get().applyChange((p) => removeItems(p, "context", [id])),
|
||||
|
||||
removeContextObjects: (ids) => {
|
||||
if (ids.length === 0) return;
|
||||
const drop = new Set(ids);
|
||||
setContext((ctx) => ctx.filter((o) => !drop.has(o.id)));
|
||||
get().applyChange((p) => removeItems(p, "context", ids));
|
||||
},
|
||||
|
||||
generateTerrain: (contourSetId) => {
|
||||
@@ -102,6 +93,6 @@ export function createSiteSlice(
|
||||
return terrain.id;
|
||||
},
|
||||
|
||||
clearContext: () => setContext(() => []),
|
||||
clearContext: () => get().applyChange((p) => fieldOps(p, "context", [])),
|
||||
};
|
||||
}
|
||||
@@ -9,8 +9,8 @@ import { useEffect, useMemo, useRef, useState } from "react";
|
||||
import { createPortal } from "react-dom";
|
||||
import { t } from "../i18n";
|
||||
import type { TranslationKey } from "../i18n";
|
||||
import { applyRoomProgram, cellText, importedRows, mapRows, PROGRAM_FIELDS, readSheetFile, suggestMapping } from "../core";
|
||||
import type { ImportMode, Mapping, ProgramField, SheetData, SkipReason } from "../core";
|
||||
import { roomProgramOps, cellText, importedRows, mapRows, PROGRAM_FIELDS, readSheetFile, suggestMapping } from "../core";
|
||||
import type { CoreOp, ImportMode, Mapping, ProgramField, SheetData, SkipReason } from "../core";
|
||||
import type { Project, RoomProgramRow } from "../model/types";
|
||||
|
||||
const FIELD_KEY: Record<ProgramField, TranslationKey> = {
|
||||
@@ -235,7 +235,7 @@ export function RoomProgramImportDialog({ fileName, sheets, existing, onImport,
|
||||
export interface RoomProgramImportButtonProps {
|
||||
project: Project;
|
||||
/** Übernimmt die Zeilen ins Projekt (ein Undo-Schritt). */
|
||||
onApply: (project: (p: Project) => Project) => void;
|
||||
onApply: (build: (p: Project) => readonly CoreOp[]) => void;
|
||||
notify: (message: string, kind?: "info" | "warning" | "error") => void;
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ export function RoomProgramImportButton({ project, onApply, notify }: RoomProgra
|
||||
existing={project.roomProgram?.length ?? 0}
|
||||
onClose={() => setData(null)}
|
||||
onImport={(rows, mode) => {
|
||||
onApply((p) => applyRoomProgram(p, rows, mode));
|
||||
onApply((p) => roomProgramOps(p, rows, mode));
|
||||
notify(t("program.import.done", { n: rows.length }));
|
||||
setData(null);
|
||||
}}
|
||||
|
||||
@@ -327,6 +327,7 @@ export function Wasm3DViewport({
|
||||
onEditRoofPitch,
|
||||
onEditWallTop,
|
||||
onEditEnd,
|
||||
onEditGroup,
|
||||
section3d = null,
|
||||
onClearSection3d,
|
||||
commandActive = false,
|
||||
@@ -406,6 +407,12 @@ export function Wasm3DViewport({
|
||||
onEditWallTop?: (wallId: string, topZ: number) => void;
|
||||
/** Ende eines Griff-Drags. */
|
||||
onEditEnd?: () => void;
|
||||
/**
|
||||
* Fasst die Änderungen EINES Maus-Schritts (Element + mitgeführte Ecken anderer Elemente) zu einem
|
||||
* Undo-Schritt zusammen; gleicher `key` über die Schritte eines Zugs = ein Schritt für den ganzen
|
||||
* Zug ([K4] S3, Store `groupChanges`). Fehlt es, läuft `fn` direkt.
|
||||
*/
|
||||
onEditGroup?: (fn: () => void, key: string) => void;
|
||||
/** Aktive 3D-Schnittebene (world point+normal) aus der gebundenen Schnittlinie
|
||||
* (App-State, `sectionPlaneFromLevel`), oder `null` = kein Live-Schnitt.
|
||||
* Ersetzt den früheren lokalen Hardcode-Toggle. */
|
||||
@@ -469,6 +476,14 @@ export function Wasm3DViewport({
|
||||
onEditWallTopRef.current = onEditWallTop;
|
||||
const onEditEndRef = useRef(onEditEnd);
|
||||
onEditEndRef.current = onEditEnd;
|
||||
const onEditGroupRef = useRef(onEditGroup);
|
||||
onEditGroupRef.current = onEditGroup;
|
||||
/** Ein Maus-Schritt als Gruppe (ein Undo-Schritt je Zug), s. `onEditGroup`. */
|
||||
const editGroup = (key: string, fn: () => void) => {
|
||||
const g = onEditGroupRef.current;
|
||||
if (g) g(fn, key);
|
||||
else fn();
|
||||
};
|
||||
const onGrip3dEditTabRef = useRef(onGrip3dEditTab);
|
||||
onGrip3dEditTabRef.current = onGrip3dEditTab;
|
||||
const onGrip3dEditCancelRef = useRef(onGrip3dEditCancel);
|
||||
@@ -1075,20 +1090,25 @@ export function Wasm3DViewport({
|
||||
: axisLock === "y"
|
||||
? { x: anchor.x, y: model.y }
|
||||
: applyAngleConstraint(anchor, model, 45);
|
||||
const applied = constrained
|
||||
? (onEditVertexRef.current?.(drag.target, drag.index, constrained) ?? constrained)
|
||||
: (onEditVertexRef.current?.(
|
||||
drag.target,
|
||||
drag.index,
|
||||
model,
|
||||
drag.excludeWallIds,
|
||||
drag.excludeDrawingIds,
|
||||
) ?? model);
|
||||
// Koinzidente Endpunkte ANDERER gewählter Elemente mitführen — exakt
|
||||
// auf denselben (ggf. gesnappten) Punkt, ohne erneut zu snappen.
|
||||
for (const c of drag.coincident) {
|
||||
onEditVertexRef.current?.(c.target, c.index, applied);
|
||||
}
|
||||
// Element und mitgeführte Ecken = EIN Undo-Schritt für den ganzen Zug (Gruppe mit Schlüssel).
|
||||
let applied: Vec2 = model;
|
||||
const t0 = drag.target;
|
||||
editGroup(`grip3d:${t0.wallId ?? t0.drawingId ?? t0.ceilingId ?? t0.roofId ?? ""}:${drag.index}`, () => {
|
||||
applied = constrained
|
||||
? (onEditVertexRef.current?.(drag.target, drag.index, constrained) ?? constrained)
|
||||
: (onEditVertexRef.current?.(
|
||||
drag.target,
|
||||
drag.index,
|
||||
model,
|
||||
drag.excludeWallIds,
|
||||
drag.excludeDrawingIds,
|
||||
) ?? model);
|
||||
// Koinzidente Endpunkte ANDERER gewählter Elemente mitführen — exakt
|
||||
// auf denselben (ggf. gesnappten) Punkt, ohne erneut zu snappen.
|
||||
for (const c of drag.coincident) {
|
||||
onEditVertexRef.current?.(c.target, c.index, applied);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (drag.kind === "edge") {
|
||||
@@ -1124,14 +1144,17 @@ export function Wasm3DViewport({
|
||||
y: constrainedModel.y - drag.lastModel.y,
|
||||
};
|
||||
if (delta.x !== 0 || delta.y !== 0) {
|
||||
onEditBodyRef.current?.(drag.target, delta, !!moveAxisLock || shiftKey);
|
||||
// Koinzidente Sibling-Ecken (ANDERER gewählter Elemente) um dasselbe
|
||||
// Delta mitführen — ihre LIVE-Position wird inkrementell
|
||||
// fortgeschrieben und absolut neu gesetzt (kein Snap).
|
||||
for (const c of drag.moveCoincident) {
|
||||
c.pos = { x: c.pos.x + delta.x, y: c.pos.y + delta.y };
|
||||
onEditVertexRef.current?.(c.target, c.index, c.pos);
|
||||
}
|
||||
const t1 = drag.target;
|
||||
editGroup(`grip3dMove:${t1.wallId ?? t1.drawingId ?? t1.ceilingId ?? t1.roofId ?? ""}`, () => {
|
||||
onEditBodyRef.current?.(drag.target, delta, !!moveAxisLock || shiftKey);
|
||||
// Koinzidente Sibling-Ecken (ANDERER gewählter Elemente) um dasselbe
|
||||
// Delta mitführen — ihre LIVE-Position wird inkrementell
|
||||
// fortgeschrieben und absolut neu gesetzt (kein Snap).
|
||||
for (const c of drag.moveCoincident) {
|
||||
c.pos = { x: c.pos.x + delta.x, y: c.pos.y + delta.y };
|
||||
onEditVertexRef.current?.(c.target, c.index, c.pos);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
drag.lastModel = constrainedModel;
|
||||
|
||||
@@ -138,6 +138,7 @@ export function Content({
|
||||
onEdit3dRoofPitch,
|
||||
onEdit3dWallTop,
|
||||
onEdit3dEnd,
|
||||
onEdit3dGroup,
|
||||
onGrip3dEditTab,
|
||||
onGrip3dEditCancel,
|
||||
}: {
|
||||
@@ -258,6 +259,8 @@ export function Content({
|
||||
onEdit3dRoofPitch: (roofId: string, apexHeight: number) => void;
|
||||
onEdit3dWallTop: (wallId: string, topZ: number) => void;
|
||||
onEdit3dEnd: () => void;
|
||||
/** Maus-Schritt eines 3D-Griff-Zugs als Gruppe mit Schlüssel (ein Undo-Schritt je Zug). */
|
||||
onEdit3dGroup?: (fn: () => void, key: string) => void;
|
||||
/** Tab während eines laufenden 3D-Griff-Drags (Endpunkt/Verschieben): Feld-
|
||||
* Controller fürs Cursor-HUD öffnen/zykeln, s. App.tsx `cycleGrip3dEditField`. */
|
||||
onGrip3dEditTab?: () => void;
|
||||
@@ -471,6 +474,7 @@ export function Content({
|
||||
onEditRoofPitch={onEdit3dRoofPitch}
|
||||
onEditWallTop={onEdit3dWallTop}
|
||||
onEditEnd={onEdit3dEnd}
|
||||
onEditGroup={onEdit3dGroup}
|
||||
onGrip3dEditTab={onGrip3dEditTab}
|
||||
onGrip3dEditCancel={onGrip3dEditCancel}
|
||||
/>
|
||||
|
||||
Reference in new issue
Block a user