[K4][6][8] Panel-Aktionen, Typ-CRUD und App-Handler erzeugen Ops direkt (usePanelHostBase, useProjectActions, Split/Boolean/Sperren/Kategorien/Kollisionsmarken/Layout/Einstellungen); neuer Helfer replaceWithMany
Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
14 files changed
+477
-455
No files matched your search
@@ -3,9 +3,15 @@
|
||||
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import { isLocked, setLocked, setLockedForMembers } from "./objectLock";
|
||||
import { isLocked, lockMembersOps, lockOps } from "./objectLock";
|
||||
import type { MemberKind } from "./groupActions";
|
||||
import { applyOps } from "../core/ops";
|
||||
import type { Project, Wall, Drawing2D } from "../model/types";
|
||||
|
||||
const setLocked = (p: Project, kind: MemberKind, id: string, locked: boolean) => applyOps(p, lockOps(p, kind, id, locked));
|
||||
const setLockedForMembers = (p: Project, m: Partial<Record<MemberKind, string[]>>, locked: boolean) =>
|
||||
applyOps(p, lockMembersOps(p, m, locked));
|
||||
|
||||
const wall: Wall = {
|
||||
id: "w1",
|
||||
type: "wall",
|
||||
|
||||
+17
-32
@@ -11,6 +11,8 @@
|
||||
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import type { Project } from "../model/types";
|
||||
import { patchItem } from "../core";
|
||||
import type { CoreOp } from "../core";
|
||||
import type { MemberKind } from "./groupActions";
|
||||
|
||||
/** Ist das Element (Art + ID) gesperrt? `false` für unbekannte/fehlende IDs. */
|
||||
@@ -35,40 +37,25 @@ export function isLocked(project: Project, kind: MemberKind, id: string): boolea
|
||||
}
|
||||
}
|
||||
|
||||
/** Setzt die Sperre eines Elements (immutabel); unbekannte IDs sind ein No-Op. */
|
||||
export function setLocked(project: Project, kind: MemberKind, id: string, locked: boolean): Project {
|
||||
/** Ops: setzt die Sperre eines Elements; unbekannte IDs sind ein No-Op (keine Ops). */
|
||||
export function lockOps(project: Project, kind: MemberKind, id: string, locked: boolean): CoreOp[] {
|
||||
switch (kind) {
|
||||
case "wallIds":
|
||||
return { ...project, walls: project.walls.map((w) => (w.id === id ? { ...w, locked } : w)) };
|
||||
return patchItem(project, "walls", id, { locked });
|
||||
case "drawingIds":
|
||||
return {
|
||||
...project,
|
||||
drawings2d: project.drawings2d.map((d) => (d.id === id ? { ...d, locked } : d)),
|
||||
};
|
||||
return patchItem(project, "drawings2d", id, { locked });
|
||||
case "ceilingIds":
|
||||
return {
|
||||
...project,
|
||||
ceilings: (project.ceilings ?? []).map((c) => (c.id === id ? { ...c, locked } : c)),
|
||||
};
|
||||
return patchItem(project, "ceilings", id, { locked });
|
||||
case "roomIds":
|
||||
return { ...project, rooms: (project.rooms ?? []).map((r) => (r.id === id ? { ...r, locked } : r)) };
|
||||
return patchItem(project, "rooms", id, { locked });
|
||||
case "stairIds":
|
||||
return {
|
||||
...project,
|
||||
stairs: (project.stairs ?? []).map((s) => (s.id === id ? { ...s, locked } : s)),
|
||||
};
|
||||
return patchItem(project, "stairs", id, { locked });
|
||||
case "columnIds":
|
||||
return {
|
||||
...project,
|
||||
columns: (project.columns ?? []).map((c) => (c.id === id ? { ...c, locked } : c)),
|
||||
};
|
||||
return patchItem(project, "columns", id, { locked });
|
||||
case "roofIds":
|
||||
return { ...project, roofs: (project.roofs ?? []).map((r) => (r.id === id ? { ...r, locked } : r)) };
|
||||
return patchItem(project, "roofs", id, { locked });
|
||||
case "openingIds":
|
||||
return {
|
||||
...project,
|
||||
openings: (project.openings ?? []).map((o) => (o.id === id ? { ...o, locked } : o)),
|
||||
};
|
||||
return patchItem(project, "openings", id, { locked });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,16 +64,14 @@ export function setLocked(project: Project, kind: MemberKind, id: string, locked
|
||||
* Zug (ein Undo-Schritt für "Auswahl sperren/entsperren", nicht einer je
|
||||
* Element). Reihenfolge/Struktur wie `MemberKind` — jedes Feld optional.
|
||||
*/
|
||||
export function setLockedForMembers(
|
||||
export function lockMembersOps(
|
||||
project: Project,
|
||||
members: Partial<Record<MemberKind, string[]>>,
|
||||
locked: boolean,
|
||||
): Project {
|
||||
let next = project;
|
||||
): CoreOp[] {
|
||||
const ops: CoreOp[] = [];
|
||||
for (const kind of Object.keys(members) as MemberKind[]) {
|
||||
for (const id of members[kind] ?? []) {
|
||||
next = setLocked(next, kind, id, locked);
|
||||
}
|
||||
for (const id of members[kind] ?? []) ops.push(...lockOps(project, kind, id, locked));
|
||||
}
|
||||
return next;
|
||||
return ops;
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
// Typ-CRUD (`useProjectActions`) und Panel-Aktionen (`usePanelHostBase`) liefern ihre Änderung als Ops
|
||||
// ([K4] S3): „applyOps(vorher, Ops) == erwartetes Ergebnis". Beim Umbau wurden dieselben Schritte
|
||||
// gegen die alte setProject-Fassung (git HEAD) verglichen: Typ-CRUD und 46 Panel-Aktionen, gleich.
|
||||
// Die Hooks laufen hier über `renderToString` (kein DOM nötig) und geben ihre Closures heraus.
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createElement } from "react";
|
||||
import { renderToString } from "react-dom/server";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import type { Project } from "../model/types";
|
||||
import { applyOps } from "../core/ops";
|
||||
import type { CoreOp } from "../core/ops";
|
||||
import { useProjectActions } from "./useProjectActions";
|
||||
import { usePanelHostBase } from "./usePanelHostBase";
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
function capture<T>(f: () => T): T {
|
||||
let out: T | undefined;
|
||||
renderToString(
|
||||
createElement(() => {
|
||||
out = f();
|
||||
return null;
|
||||
}),
|
||||
);
|
||||
return out as T;
|
||||
}
|
||||
|
||||
/** Platzhalter für die vielen Zustandsfelder, die die getesteten Aktionen nicht anfassen. */
|
||||
function deepStub(): any {
|
||||
const fn = function () {
|
||||
return undefined;
|
||||
};
|
||||
return new Proxy(fn, {
|
||||
get: (_t, k) => (k === Symbol.toPrimitive ? () => "" : k === "then" ? undefined : deepStub()),
|
||||
apply: () => undefined,
|
||||
});
|
||||
}
|
||||
function stubObj(over: Record<string, unknown>): any {
|
||||
return new Proxy(over, {
|
||||
get: (t, k) => (k in t ? (t as any)[k] : typeof k === "symbol" ? undefined : deepStub()),
|
||||
});
|
||||
}
|
||||
|
||||
/** Zustandshalter: Ops anwenden wie der Store. */
|
||||
function holder(start: Project) {
|
||||
const h = {
|
||||
p: start,
|
||||
notes: [] as string[],
|
||||
applyChange: (c: readonly CoreOp[] | ((p: Project) => readonly CoreOp[])) => {
|
||||
h.p = applyOps(h.p, typeof c === "function" ? c(h.p) : c);
|
||||
},
|
||||
};
|
||||
return h;
|
||||
}
|
||||
|
||||
describe("useProjectActions: Typ-CRUD über Ops", () => {
|
||||
it("Anlegen, Ändern, geschütztes Löschen, Stil speichern", () => {
|
||||
const h = holder({ ...sampleProject, doorTypes: [], windowTypes: [], stairTypes: [], roofTypes: [] });
|
||||
const a = capture(() => useProjectActions(h.applyChange, (m) => h.notes.push(m), { current: null }));
|
||||
const wt = h.p.wallTypes[0].id;
|
||||
const nWall = h.p.wallTypes.length;
|
||||
|
||||
a.addWallType();
|
||||
expect(h.p.wallTypes).toHaveLength(nWall + 1);
|
||||
expect(h.p.wallTypes[nWall].layers).toHaveLength(1);
|
||||
a.patchWallType(wt, { name: "Neu" });
|
||||
expect(h.p.wallTypes[0].name).toBe("Neu");
|
||||
a.deleteWallType(wt); // wird von Wänden verwendet
|
||||
expect(h.p.wallTypes).toHaveLength(nWall + 1);
|
||||
expect(h.notes).toHaveLength(1);
|
||||
a.deleteWallType(h.p.wallTypes[nWall].id);
|
||||
expect(h.p.wallTypes).toHaveLength(nWall);
|
||||
|
||||
a.addDoorType();
|
||||
a.addWindowType();
|
||||
a.addStairType();
|
||||
a.addRoofType();
|
||||
a.addCeilingType();
|
||||
expect([h.p.doorTypes!.length, h.p.windowTypes!.length, h.p.stairTypes!.length, h.p.roofTypes!.length]).toEqual([1, 1, 1, 1]);
|
||||
a.patchDoorType(h.p.doorTypes![0].id, { name: "T" });
|
||||
expect(h.p.doorTypes![0].name).toBe("T");
|
||||
|
||||
const opening = (h.p.openings ?? [])[0];
|
||||
if (opening) {
|
||||
a.saveOpeningStyle(opening.id, "Mein Stil");
|
||||
const after = h.p.openings!.find((o) => o.id === opening.id)!;
|
||||
const list = opening.kind === "door" ? h.p.doorTypes! : h.p.windowTypes!;
|
||||
expect(list.some((t) => t.id === after.typeId && t.name === "Mein Stil")).toBe(true);
|
||||
}
|
||||
|
||||
a.setOverrideRules([]);
|
||||
expect(h.p.overrideRules).toEqual([]);
|
||||
a.deleteDoorType(h.p.doorTypes![0].id);
|
||||
expect(h.p.doorTypes!.some((d) => d.name === "T")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
const L0 = sampleProject.drawingLevels[0].id;
|
||||
const base: Project = {
|
||||
...sampleProject,
|
||||
columns: [
|
||||
{ id: "col1", type: "column", floorId: L0, categoryCode: "20", position: { x: 1, y: 1 }, height: 3, rotation: 0, profile: { kind: "rect", width: 0.3, depth: 0.3 } },
|
||||
{ id: "col2", type: "column", floorId: L0, categoryCode: "20", position: { x: 3, y: 1 }, height: 3, rotation: 0, profile: { kind: "round", radius: 0.2 } },
|
||||
] as any,
|
||||
extrudedSolids: [{ id: "ex1", type: "extrudedSolid", levelId: L0, points: [{ x: 0, y: 0 }, { x: 1, y: 0 }, { x: 1, y: 1 }], height: 1 }] as any,
|
||||
context: [{ id: "img1", type: "image", min: { x: 0, y: 0 }, max: { x: 1, y: 1 }, opacity: 1 }] as any,
|
||||
viewSnapshots: [{ id: "vs-1", name: "A", state: {} }, { id: "vs-2", name: "B", state: {} }] as any,
|
||||
viewSnapshotFolders: [{ id: "vsf-1", name: "F" }] as any,
|
||||
layouts: [{ id: "lay-1", name: "L1", masterId: "mas-1" }, { id: "lay-2", name: "L2" }] as any,
|
||||
masterLayouts: [{ id: "mas-1", name: "M1" }] as any,
|
||||
layoutFolders: [{ id: "folder-1", name: "LF" }, { id: "mfolder-1", name: "MF", kind: "master" }] as any,
|
||||
};
|
||||
|
||||
function host(h: ReturnType<typeof holder>, selection: any) {
|
||||
(globalThis as any).requestAnimationFrame = () => 0;
|
||||
return capture(() =>
|
||||
usePanelHostBase({
|
||||
project: h.p,
|
||||
setProject: (n: any) => {
|
||||
h.p = typeof n === "function" ? n(h.p) : n;
|
||||
},
|
||||
applyChange: h.applyChange,
|
||||
activeLevelId: L0,
|
||||
setActiveLevelId: () => {},
|
||||
setViewType: () => {},
|
||||
activeLevel: sampleProject.drawingLevels[0],
|
||||
viewType: "grundriss",
|
||||
selection,
|
||||
projectActions: stubObj({ snapshotLayerVisibility: () => ({}), snapshotDrawingVisibility: () => ({}), applyLayerVisibility: () => {}, applyDrawingVisibility: () => {} }),
|
||||
selectionState: stubObj({ selectedContextObjectIds: [] }),
|
||||
toolState: stubObj({}),
|
||||
topBarState: stubObj({}),
|
||||
dialogState: stubObj({ setActiveLayoutId: () => {} }),
|
||||
contextMenuState: stubObj({}),
|
||||
engineView: { commandName: null },
|
||||
planViewRef: { current: null },
|
||||
dxfInputRef: { current: null },
|
||||
activeLayout: undefined,
|
||||
patchOpenLayout: () => {},
|
||||
} as any),
|
||||
) as any;
|
||||
}
|
||||
|
||||
describe("usePanelHostBase: Panel-Aktionen über Ops", () => {
|
||||
it("Stützen, Extrusionen, Kontext-Bild", () => {
|
||||
const h = holder(base);
|
||||
host(h, { kind: "column", id: "col1" }).onSetColumnWidth(0.5);
|
||||
expect((h.p.columns![0].profile as any).width).toBe(0.5);
|
||||
host(h, { kind: "column", id: "col2" }).onSetColumnWidth(0.5); // runde Stütze: keine Breite
|
||||
expect(h.p.columns![1].profile).toEqual({ kind: "round", radius: 0.2 });
|
||||
host(h, { kind: "column", id: "col1" }).onSetColumnProfileKind("round");
|
||||
expect(h.p.columns![0].profile).toEqual({ kind: "round", radius: 0.25 });
|
||||
host(h, { kind: "column", id: "col1" }).onSetColumnRotation(90);
|
||||
expect(h.p.columns![0].rotation).toBeCloseTo(Math.PI / 2, 12);
|
||||
host(h, { kind: "column", id: "col1" }).onSetSelectionLevel("og");
|
||||
expect(h.p.columns![0].floorId).toBe("og");
|
||||
expect(h.p.columns![1]).toBe(base.columns![1]); // unberührt: gleiche Referenz
|
||||
host(h, { kind: "extrudedSolid", id: "ex1" }).onSetExtrudedSolidHeight(2.5);
|
||||
host(h, { kind: "extrudedSolid", id: "ex1" }).onSetExtrudedSolidSubtract(true);
|
||||
expect(h.p.extrudedSolids![0]).toMatchObject({ height: 2.5, operation: "subtract" });
|
||||
host(h, { kind: "contextObject", id: "img1" }).onSetSelectionOpacity(0.4);
|
||||
expect((h.p.context![0] as any).opacity).toBe(0.4);
|
||||
host(h, null).onSetGeoAnchor({ lv95: { e: 1, n: 2 }, model: { x: 0, y: 0 } });
|
||||
expect(h.p.geoAnchor).toEqual({ lv95: { e: 1, n: 2 }, model: { x: 0, y: 0 } });
|
||||
});
|
||||
|
||||
it("Ausschnitte und Ordner", () => {
|
||||
const h = holder(base);
|
||||
const a = host(h, null);
|
||||
a.onRenameViewSnapshot("vs-1", " Neu A ");
|
||||
expect(h.p.viewSnapshots![0].name).toBe("Neu A");
|
||||
a.onMoveViewSnapshotToFolder("vs-2", "vsf-1");
|
||||
expect((h.p.viewSnapshots![1] as any).folderId).toBe("vsf-1");
|
||||
const id = a.onCaptureViewSnapshot("Neu", "vsf-1");
|
||||
expect(h.p.viewSnapshots!.at(-1)!.id).toBe(id);
|
||||
a.onDeleteViewSnapshot("vs-2");
|
||||
expect(h.p.viewSnapshots!.map((s) => s.id)).toEqual(["vs-1", id]);
|
||||
a.onDeleteViewSnapshotFolder("vsf-1");
|
||||
expect(h.p.viewSnapshotFolders).toEqual([]);
|
||||
});
|
||||
|
||||
it("Layouts, Masterlayouts, Layout-Ordner", () => {
|
||||
const h = holder(base);
|
||||
const a = host(h, null);
|
||||
a.onRenameLayout("lay-2", "Z");
|
||||
expect(h.p.layouts![1].name).toBe("Z");
|
||||
a.onDeleteMasterLayout("mas-1"); // löst die Bindung der Layouts
|
||||
expect(h.p.masterLayouts).toEqual([]);
|
||||
expect(h.p.layouts![0].masterId).toBeUndefined();
|
||||
a.onDeleteLayout("lay-1");
|
||||
expect(h.p.layouts!.map((l) => l.id)).toEqual(["lay-2"]);
|
||||
const id = a.onCreateLayout({ paper: "a4", orientation: "portrait", folderId: "folder-1" });
|
||||
expect(h.p.layouts!.at(-1)).toMatchObject({ id, folderId: "folder-1" });
|
||||
a.onMoveLayoutToFolder("lay-2", "folder-1");
|
||||
expect((h.p.layouts![0] as any).folderId).toBe("folder-1");
|
||||
a.onDeleteLayoutFolder("folder-1");
|
||||
expect(h.p.layoutFolders!.map((f) => f.id)).toEqual(["mfolder-1"]);
|
||||
});
|
||||
});
|
||||
+79
-227
@@ -8,7 +8,8 @@
|
||||
// Extrahiert aus App.tsx. Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import { applyFillMode } from "./fillMode";
|
||||
import { opsMutation, patchItem } from "../core";
|
||||
import { addItems, fieldOps, opsMutation, patchItem, patchItems, removeItems, setFieldIfChanged } from "../core";
|
||||
import type { CoreOp } from "../core";
|
||||
import { useMemo, type RefObject } from "react";
|
||||
import type { DrawingLevel, Layout, Project } from "../model/types";
|
||||
import { resolvePenColor } from "../model/penSets";
|
||||
@@ -107,6 +108,8 @@ function captureCameraState(
|
||||
export function usePanelHostBase(opts: {
|
||||
project: Project;
|
||||
setProject: (updater: (p: Project) => Project) => void;
|
||||
/** Änderung direkt als Ops ([K4] S3), s. `ProjectSlice.applyChange`. */
|
||||
applyChange: (ops: readonly CoreOp[] | ((p: Project) => readonly CoreOp[]), coalesceKey?: string) => void;
|
||||
activeLevelId: string;
|
||||
setActiveLevelId: (id: string) => void;
|
||||
activeLevel: DrawingLevel;
|
||||
@@ -226,6 +229,7 @@ export function usePanelHostBase(opts: {
|
||||
const {
|
||||
project,
|
||||
setProject,
|
||||
applyChange,
|
||||
activeLevelId,
|
||||
setActiveLevelId,
|
||||
activeLevel,
|
||||
@@ -508,26 +512,20 @@ export function usePanelHostBase(opts: {
|
||||
patchAnnotationInLayout(l, selection.id, { opacity }),
|
||||
);
|
||||
else if (selection?.kind === "contextObject")
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
context: (p.context ?? []).map((o) =>
|
||||
o.id === selection.id && o.type === "image" ? { ...o, opacity } : o,
|
||||
),
|
||||
}));
|
||||
applyChange((p) =>
|
||||
patchItem(p, "context", selection.id, (o) => (o.type === "image" ? { ...o, opacity } : o)),
|
||||
);
|
||||
},
|
||||
onSetSelectionImageFilters: (filters) => {
|
||||
// Nur Kontext-Objekt-Bilder tragen `filters` (s. `ContextImage`) —
|
||||
// gemergt mit den bestehenden Werten (Teil-Update, ein Slider ändert
|
||||
// nur SEINEN eigenen Wert).
|
||||
if (selection?.kind !== "contextObject") return;
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
context: (p.context ?? []).map((o) =>
|
||||
o.id === selection.id && o.type === "image"
|
||||
? { ...o, filters: { ...o.filters, ...filters } }
|
||||
: o,
|
||||
applyChange((p) =>
|
||||
patchItem(p, "context", selection.id, (o) =>
|
||||
o.type === "image" ? { ...o, filters: { ...o.filters, ...filters } } : o,
|
||||
),
|
||||
}));
|
||||
);
|
||||
},
|
||||
onSetSelectionForeground: (color) => {
|
||||
// Vordergrund-Override: Wand, Decke oder Drawing2D.
|
||||
@@ -708,12 +706,7 @@ export function usePanelHostBase(opts: {
|
||||
case "room": updateRoom(id, { categoryCode: code }); break;
|
||||
case "drawing2d": updateDrawing2D(id, { categoryCode: code }); break;
|
||||
case "column":
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
columns: (p.columns ?? []).map((c) =>
|
||||
c.id === id ? { ...c, categoryCode: code } : c,
|
||||
),
|
||||
}));
|
||||
applyChange((p) => patchItem(p, "columns", id, { categoryCode: code }));
|
||||
break;
|
||||
default: break; // extrudedSolid/door: keine Kategorie am Element
|
||||
}
|
||||
@@ -729,20 +722,10 @@ export function usePanelHostBase(opts: {
|
||||
case "room": updateRoom(id, { floorId: levelId }); break;
|
||||
case "drawing2d": updateDrawing2D(id, { levelId }); break;
|
||||
case "extrudedSolid":
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
extrudedSolids: (p.extrudedSolids ?? []).map((s) =>
|
||||
s.id === id ? { ...s, levelId } : s,
|
||||
),
|
||||
}));
|
||||
applyChange((p) => patchItem(p, "extrudedSolids", id, { levelId }));
|
||||
break;
|
||||
case "column":
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
columns: (p.columns ?? []).map((c) =>
|
||||
c.id === id ? { ...c, floorId: levelId } : c,
|
||||
),
|
||||
}));
|
||||
applyChange((p) => patchItem(p, "columns", id, { floorId: levelId }));
|
||||
break;
|
||||
default: break; // opening: Ebene kommt aus der Wirts-Wand
|
||||
}
|
||||
@@ -1003,74 +986,42 @@ export function usePanelHostBase(opts: {
|
||||
onSetExtrudedSolidHeight: (height) => {
|
||||
if (selection?.kind !== "extrudedSolid" || !(height > 0)) return;
|
||||
const id = selection.id;
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
extrudedSolids: (p.extrudedSolids ?? []).map((s) =>
|
||||
s.id === id ? { ...s, height } : s,
|
||||
),
|
||||
}));
|
||||
applyChange((p) => patchItem(p, "extrudedSolids", id, { height }));
|
||||
},
|
||||
onSetExtrudedSolidTaper: (taper) => {
|
||||
if (selection?.kind !== "extrudedSolid") return;
|
||||
const clamped = Math.min(1, Math.max(0, taper));
|
||||
const id = selection.id;
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
extrudedSolids: (p.extrudedSolids ?? []).map((s) =>
|
||||
s.id === id ? { ...s, taper: clamped } : s,
|
||||
),
|
||||
}));
|
||||
applyChange((p) => patchItem(p, "extrudedSolids", id, { taper: clamped }));
|
||||
},
|
||||
onSetExtrudedSolidCornerRadius: (radius) => {
|
||||
if (selection?.kind !== "extrudedSolid") return;
|
||||
const r = Math.max(0, radius);
|
||||
const id = selection.id;
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
extrudedSolids: (p.extrudedSolids ?? []).map((s) =>
|
||||
s.id === id ? { ...s, cornerRadius: r > 0 ? r : undefined } : s,
|
||||
),
|
||||
}));
|
||||
applyChange((p) => patchItem(p, "extrudedSolids", id, { cornerRadius: r > 0 ? r : undefined }));
|
||||
},
|
||||
onSetExtrudedSolidChamfer: (chamfer) => {
|
||||
if (selection?.kind !== "extrudedSolid") return;
|
||||
const c = Math.max(0, chamfer);
|
||||
const id = selection.id;
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
extrudedSolids: (p.extrudedSolids ?? []).map((s) =>
|
||||
s.id === id ? { ...s, chamfer: c > 0 ? c : undefined } : s,
|
||||
),
|
||||
}));
|
||||
applyChange((p) => patchItem(p, "extrudedSolids", id, { chamfer: c > 0 ? c : undefined }));
|
||||
},
|
||||
onSetExtrudedSolidSubtract: (subtract) => {
|
||||
if (selection?.kind !== "extrudedSolid") return;
|
||||
const id = selection.id;
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
extrudedSolids: (p.extrudedSolids ?? []).map((s) =>
|
||||
s.id === id ? { ...s, operation: subtract ? ("subtract" as const) : undefined } : s,
|
||||
),
|
||||
}));
|
||||
applyChange((p) => patchItem(p, "extrudedSolids", id, { operation: subtract ? ("subtract" as const) : undefined }));
|
||||
},
|
||||
onSetExtrudedSolidBaseOffset: (offset) => {
|
||||
if (selection?.kind !== "extrudedSolid" || !Number.isFinite(offset)) return;
|
||||
const id = selection.id;
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
extrudedSolids: (p.extrudedSolids ?? []).map((s) =>
|
||||
s.id === id ? { ...s, baseOffset: Math.abs(offset) > 1e-9 ? offset : undefined } : s,
|
||||
),
|
||||
}));
|
||||
applyChange((p) => patchItem(p, "extrudedSolids", id, { baseOffset: Math.abs(offset) > 1e-9 ? offset : undefined }));
|
||||
},
|
||||
// ── Stützen-Attribute (Tragwerk; nur bei selektierter Stütze) ──────────
|
||||
onSetColumnProfileKind: (kind) => {
|
||||
if (selection?.kind !== "column") return;
|
||||
const id = selection.id;
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
columns: (p.columns ?? []).map((c) => {
|
||||
if (c.id !== id) return c;
|
||||
applyChange((p) =>
|
||||
patchItem(p, "columns", id, (c) => {
|
||||
if (kind === c.profile.kind) return c;
|
||||
// Profil-Typ wechseln: sinnvolles Mass aus dem bisherigen ableiten.
|
||||
if (kind === "round") {
|
||||
@@ -1078,65 +1029,50 @@ export function usePanelHostBase(opts: {
|
||||
c.profile.kind === "rect"
|
||||
? Math.max(c.profile.width, c.profile.depth) / 2
|
||||
: c.profile.radius;
|
||||
return { ...c, profile: { kind: "round", radius: r } };
|
||||
return { ...c, profile: { kind: "round" as const, radius: r } };
|
||||
}
|
||||
const side = c.profile.kind === "round" ? c.profile.radius * 2 : 0.3;
|
||||
return { ...c, profile: { kind: "rect", width: side, depth: side } };
|
||||
return { ...c, profile: { kind: "rect" as const, width: side, depth: side } };
|
||||
}),
|
||||
}));
|
||||
);
|
||||
},
|
||||
onSetColumnWidth: (width) => {
|
||||
if (selection?.kind !== "column" || !(width > 0)) return;
|
||||
const id = selection.id;
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
columns: (p.columns ?? []).map((c) =>
|
||||
c.id === id && c.profile.kind === "rect"
|
||||
? { ...c, profile: { ...c.profile, width } }
|
||||
: c,
|
||||
applyChange((p) =>
|
||||
patchItem(p, "columns", id, (c) =>
|
||||
c.profile.kind === "rect" ? { ...c, profile: { ...c.profile, width } } : c,
|
||||
),
|
||||
}));
|
||||
);
|
||||
},
|
||||
onSetColumnDepth: (depth) => {
|
||||
if (selection?.kind !== "column" || !(depth > 0)) return;
|
||||
const id = selection.id;
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
columns: (p.columns ?? []).map((c) =>
|
||||
c.id === id && c.profile.kind === "rect"
|
||||
? { ...c, profile: { ...c.profile, depth } }
|
||||
: c,
|
||||
applyChange((p) =>
|
||||
patchItem(p, "columns", id, (c) =>
|
||||
c.profile.kind === "rect" ? { ...c, profile: { ...c.profile, depth } } : c,
|
||||
),
|
||||
}));
|
||||
);
|
||||
},
|
||||
onSetColumnRadius: (radius) => {
|
||||
if (selection?.kind !== "column" || !(radius > 0)) return;
|
||||
const id = selection.id;
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
columns: (p.columns ?? []).map((c) =>
|
||||
c.id === id && c.profile.kind === "round"
|
||||
? { ...c, profile: { ...c.profile, radius } }
|
||||
: c,
|
||||
applyChange((p) =>
|
||||
patchItem(p, "columns", id, (c) =>
|
||||
c.profile.kind === "round" ? { ...c, profile: { ...c.profile, radius } } : c,
|
||||
),
|
||||
}));
|
||||
);
|
||||
},
|
||||
onSetColumnHeight: (height) => {
|
||||
if (selection?.kind !== "column" || !(height > 0)) return;
|
||||
const id = selection.id;
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
columns: (p.columns ?? []).map((c) => (c.id === id ? { ...c, height } : c)),
|
||||
}));
|
||||
applyChange((p) => patchItem(p, "columns", id, { height }));
|
||||
},
|
||||
onSetColumnRotation: (deg) => {
|
||||
if (selection?.kind !== "column" || !Number.isFinite(deg)) return;
|
||||
const id = selection.id;
|
||||
const rotation = (deg * Math.PI) / 180;
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
columns: (p.columns ?? []).map((c) => (c.id === id ? { ...c, rotation } : c)),
|
||||
}));
|
||||
applyChange((p) => patchItem(p, "columns", id, { rotation }));
|
||||
},
|
||||
// ── Site-/Kontext-Schicht ──────────────────────────────────────────────
|
||||
contextObjects: project.context ?? [],
|
||||
@@ -1146,7 +1082,7 @@ export function usePanelHostBase(opts: {
|
||||
onRemoveContextObjects: removeContextObjects,
|
||||
onGenerateTerrain: generateTerrain,
|
||||
onSetGeoAnchor: (anchor) => {
|
||||
setProject((p) => ({ ...p, geoAnchor: anchor }));
|
||||
applyChange((p) => setFieldIfChanged(p, "geoAnchor", anchor));
|
||||
},
|
||||
onImportDxf: () => dxfInputRef.current?.click(),
|
||||
onStartGeoref: () => onRunCommand("georef"),
|
||||
@@ -1234,10 +1170,7 @@ export function usePanelHostBase(opts: {
|
||||
// Neuer Ausschnitt landet im aktiven Ordner (falls das Panel einen
|
||||
// mitgibt), sonst auf der Wurzelebene — additiv (folderId optional).
|
||||
const full = folderId ? { ...snap, folderId } : snap;
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
viewSnapshots: [...(p.viewSnapshots ?? []), full],
|
||||
}));
|
||||
applyChange(addItems("viewSnapshots", [full]));
|
||||
return full.id;
|
||||
},
|
||||
|
||||
@@ -1272,10 +1205,7 @@ export function usePanelHostBase(opts: {
|
||||
...captureCameraState(planViewRef, viewType),
|
||||
};
|
||||
const snap = captureViewSnapshot(`vs-${Date.now()}`, name, st);
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
viewSnapshots: [...(p.viewSnapshots ?? []), snap],
|
||||
}));
|
||||
applyChange(addItems("viewSnapshots", [snap]));
|
||||
setSelectedViewSnapshotId(snap.id);
|
||||
return snap.id;
|
||||
},
|
||||
@@ -1298,13 +1228,9 @@ export function usePanelHostBase(opts: {
|
||||
setScaleDenominator(st.scaleDenominator);
|
||||
applyLayerVisibility(st.layerVisibility);
|
||||
applyDrawingVisibility(st.drawingVisibility);
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
overrideRules: applyOverrideRuleEnabled(
|
||||
p.overrideRules ?? [],
|
||||
st.enabledOverrideRuleIds,
|
||||
),
|
||||
}));
|
||||
applyChange((p) =>
|
||||
fieldOps(p, "overrideRules", applyOverrideRuleEnabled(p.overrideRules ?? [], st.enabledOverrideRuleIds)),
|
||||
);
|
||||
requestAnimationFrame(() => {
|
||||
planViewRef.current?.applyScale(st.scaleDenominator);
|
||||
// Kamera NACH `applyScale` restaurieren (nicht statt): `applyScale`
|
||||
@@ -1326,19 +1252,11 @@ export function usePanelHostBase(opts: {
|
||||
onRenameViewSnapshot: (id: string, name: string) => {
|
||||
const trimmed = name.trim();
|
||||
if (!trimmed) return;
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
viewSnapshots: (p.viewSnapshots ?? []).map((s) =>
|
||||
s.id === id ? { ...s, name: trimmed } : s,
|
||||
),
|
||||
}));
|
||||
applyChange((p) => patchItem(p, "viewSnapshots", id, { name: trimmed }));
|
||||
},
|
||||
|
||||
onDeleteViewSnapshot: (id: string) => {
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
viewSnapshots: (p.viewSnapshots ?? []).filter((s) => s.id !== id),
|
||||
}));
|
||||
applyChange((p) => removeItems(p, "viewSnapshots", [id]));
|
||||
if (selectedViewSnapshotId === id) setSelectedViewSnapshotId(null);
|
||||
},
|
||||
|
||||
@@ -1352,51 +1270,31 @@ export function usePanelHostBase(opts: {
|
||||
t("viewsnap.folder.defaultName"),
|
||||
parentId,
|
||||
);
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
viewSnapshotFolders: [...(p.viewSnapshotFolders ?? []), folder],
|
||||
}));
|
||||
applyChange(addItems("viewSnapshotFolders", [folder]));
|
||||
return id;
|
||||
},
|
||||
onRenameViewSnapshotFolder: (id, name) => {
|
||||
const trimmed = name.trim();
|
||||
if (!trimmed) return;
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
viewSnapshotFolders: (p.viewSnapshotFolders ?? []).map((f) =>
|
||||
f.id === id ? { ...f, name: trimmed } : f,
|
||||
),
|
||||
}));
|
||||
applyChange((p) => patchItem(p, "viewSnapshotFolders", id, { name: trimmed }));
|
||||
},
|
||||
onDeleteViewSnapshotFolder: (id) => {
|
||||
setProject((p) => {
|
||||
applyChange((p) => {
|
||||
const { folders, snapshots } = deleteViewSnapshotFolder(
|
||||
id,
|
||||
p.viewSnapshotFolders ?? [],
|
||||
p.viewSnapshots ?? [],
|
||||
);
|
||||
return { ...p, viewSnapshotFolders: folders, viewSnapshots: snapshots };
|
||||
return [...fieldOps(p, "viewSnapshotFolders", folders), ...fieldOps(p, "viewSnapshots", snapshots)];
|
||||
});
|
||||
},
|
||||
onMoveViewSnapshotToFolder: (snapshotId, folderId) => {
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
viewSnapshots: moveSnapshotToFolder(
|
||||
p.viewSnapshots ?? [],
|
||||
snapshotId,
|
||||
folderId,
|
||||
),
|
||||
}));
|
||||
applyChange((p) => fieldOps(p, "viewSnapshots", moveSnapshotToFolder(p.viewSnapshots ?? [], snapshotId, folderId)));
|
||||
},
|
||||
onMoveViewSnapshotFolder: (folderId, parentId) => {
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
viewSnapshotFolders: moveViewSnapshotFolder(
|
||||
p.viewSnapshotFolders ?? [],
|
||||
folderId,
|
||||
parentId,
|
||||
),
|
||||
}));
|
||||
applyChange((p) =>
|
||||
fieldOps(p, "viewSnapshotFolders", moveViewSnapshotFolder(p.viewSnapshotFolders ?? [], folderId, parentId)),
|
||||
);
|
||||
},
|
||||
|
||||
// Footer-Bar des Ausschnitte-Panels: die aktuell „angewählte" Id plus
|
||||
@@ -1414,67 +1312,40 @@ export function usePanelHostBase(opts: {
|
||||
// Anlegen öffnet es direkt; Löschen schliesst es, falls es das offene trifft.
|
||||
onAddLayout: (name, paper, orientation) => {
|
||||
const lay = createLayout(`lay-${Date.now()}`, name, paper, orientation);
|
||||
setProject((p) => ({ ...p, layouts: [...(p.layouts ?? []), lay] }));
|
||||
applyChange(addItems("layouts", [lay]));
|
||||
setActiveLayoutId(lay.id);
|
||||
},
|
||||
onRenameLayout: (id, name) => {
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
layouts: (p.layouts ?? []).map((l) =>
|
||||
l.id === id ? { ...l, name } : l,
|
||||
),
|
||||
}));
|
||||
applyChange((p) => patchItem(p, "layouts", id, { name }));
|
||||
},
|
||||
onDeleteLayout: (id) => {
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
layouts: (p.layouts ?? []).filter((l) => l.id !== id),
|
||||
}));
|
||||
applyChange((p) => removeItems(p, "layouts", [id]));
|
||||
setActiveLayoutId((cur) => (cur === id ? null : cur));
|
||||
},
|
||||
onOpenLayout: (id) => setActiveLayoutId(id),
|
||||
onAddMasterLayout: (name) => {
|
||||
const m = createMasterLayout(`mas-${Date.now()}`, name, "a4", "portrait");
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
masterLayouts: [...(p.masterLayouts ?? []), m],
|
||||
}));
|
||||
applyChange(addItems("masterLayouts", [m]));
|
||||
},
|
||||
onRenameMasterLayout: (id, name) => {
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
masterLayouts: (p.masterLayouts ?? []).map((m) =>
|
||||
m.id === id ? { ...m, name } : m,
|
||||
),
|
||||
}));
|
||||
applyChange((p) => patchItem(p, "masterLayouts", id, { name }));
|
||||
},
|
||||
onDeleteMasterLayout: (id) => {
|
||||
// Master löschen UND Bindungen der Layouts lösen (masterId → undefined).
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
masterLayouts: (p.masterLayouts ?? []).filter((m) => m.id !== id),
|
||||
layouts: (p.layouts ?? []).map((l) =>
|
||||
l.masterId === id ? { ...l, masterId: undefined } : l,
|
||||
),
|
||||
}));
|
||||
applyChange((p) => [
|
||||
...removeItems(p, "masterLayouts", [id]),
|
||||
...patchItems(p, "layouts", (l) => l.masterId === id, (l) => ({ ...l, masterId: undefined })),
|
||||
]);
|
||||
},
|
||||
onPatchMasterLayout: (id, patch) => {
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
masterLayouts: (p.masterLayouts ?? []).map((m) =>
|
||||
m.id === id ? { ...m, ...patch } : m,
|
||||
),
|
||||
}));
|
||||
applyChange((p) => patchItem(p, "masterLayouts", id, patch));
|
||||
},
|
||||
|
||||
// ── Layouts-Baum (Ordner) + Erstell-Dialoge (DOSSIER A3) ────────────
|
||||
onAddLayoutFolder: (parentId) => {
|
||||
const id = `folder-${Date.now()}`;
|
||||
const folder = createLayoutFolder(id, t("layouts.folder.defaultName"), parentId);
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
layoutFolders: [...(p.layoutFolders ?? []), folder],
|
||||
}));
|
||||
applyChange(addItems("layoutFolders", [folder]));
|
||||
return id;
|
||||
},
|
||||
onAddMasterFolder: (parentId) => {
|
||||
@@ -1485,38 +1356,30 @@ export function usePanelHostBase(opts: {
|
||||
parentId,
|
||||
"master",
|
||||
);
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
layoutFolders: [...(p.layoutFolders ?? []), folder],
|
||||
}));
|
||||
applyChange(addItems("layoutFolders", [folder]));
|
||||
return id;
|
||||
},
|
||||
onDeleteMasterFolder: (id) => {
|
||||
setProject((p) => {
|
||||
applyChange((p) => {
|
||||
const { folders, masters } = deleteMasterFolder(
|
||||
id,
|
||||
p.layoutFolders ?? [],
|
||||
p.masterLayouts ?? [],
|
||||
);
|
||||
return { ...p, layoutFolders: folders, masterLayouts: masters };
|
||||
return [...fieldOps(p, "layoutFolders", folders), ...fieldOps(p, "masterLayouts", masters)];
|
||||
});
|
||||
},
|
||||
onRenameLayoutFolder: (id, name) => {
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
layoutFolders: (p.layoutFolders ?? []).map((f) =>
|
||||
f.id === id ? { ...f, name } : f,
|
||||
),
|
||||
}));
|
||||
applyChange((p) => patchItem(p, "layoutFolders", id, { name }));
|
||||
},
|
||||
onDeleteLayoutFolder: (id) => {
|
||||
setProject((p) => {
|
||||
applyChange((p) => {
|
||||
const { folders, layouts } = deleteLayoutFolder(
|
||||
id,
|
||||
p.layoutFolders ?? [],
|
||||
p.layouts ?? [],
|
||||
);
|
||||
return { ...p, layoutFolders: folders, layouts };
|
||||
return [...fieldOps(p, "layoutFolders", folders), ...fieldOps(p, "layouts", layouts)];
|
||||
});
|
||||
},
|
||||
onCreateLayout: (opts) => {
|
||||
@@ -1538,7 +1401,7 @@ export function usePanelHostBase(opts: {
|
||||
? { customWidthMm, customHeightMm }
|
||||
: {}),
|
||||
};
|
||||
setProject((p) => ({ ...p, layouts: [...(p.layouts ?? []), full] }));
|
||||
applyChange(addItems("layouts", [full]));
|
||||
return id;
|
||||
},
|
||||
onCreateMasterLayout: (opts) => {
|
||||
@@ -1555,10 +1418,7 @@ export function usePanelHostBase(opts: {
|
||||
custom,
|
||||
);
|
||||
const full = opts.folderId ? { ...m, folderId: opts.folderId } : m;
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
masterLayouts: [...(p.masterLayouts ?? []), full],
|
||||
}));
|
||||
applyChange(addItems("masterLayouts", [full]));
|
||||
return id;
|
||||
},
|
||||
onExportFolderPdf: (folderId) => {
|
||||
@@ -1569,20 +1429,12 @@ export function usePanelHostBase(opts: {
|
||||
});
|
||||
},
|
||||
onMoveLayoutToFolder: (layoutId, folderId) => {
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
layouts: moveLayoutToFolder(p.layouts ?? [], layoutId, folderId),
|
||||
}));
|
||||
applyChange((p) => fieldOps(p, "layouts", moveLayoutToFolder(p.layouts ?? [], layoutId, folderId)));
|
||||
},
|
||||
onMoveFolderToFolder: (folderId, parentId) => {
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
layoutFolders: moveFolderToFolder(
|
||||
p.layoutFolders ?? [],
|
||||
folderId,
|
||||
parentId,
|
||||
),
|
||||
}));
|
||||
applyChange((p) =>
|
||||
fieldOps(p, "layoutFolders", moveFolderToFolder(p.layoutFolders ?? [], folderId, parentId)),
|
||||
);
|
||||
},
|
||||
};
|
||||
return value;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Bündelt Projekt-Mutationen als (referenzstabile) Store-Actions plus die
|
||||
// Ressourcen-Typ-CRUD (Wand-/Decken-/Dach-/Tür-/Fenster-/Treppentyp), die
|
||||
// direkt über `setProject` laufen (kein eigener Slice). Löschen ist je Typ
|
||||
// direkt über `applyChange` (Ops) laufen (kein eigener Slice). Löschen ist je Typ
|
||||
// geschützt, solange ein Element ihn per `typeId`/`wallTypeId`/… referenziert.
|
||||
// Nur aus App() herausgezogen, um die Funktion zu entlasten — reine
|
||||
// Zustands-/Aktions-Bündelung, keine Verhaltensänderung.
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
import type { RefObject } from "react";
|
||||
import { useStore } from "./appStore";
|
||||
import { addItems, fieldOps, patchItem, removeItems } from "../core";
|
||||
import type { CoreOp } from "../core";
|
||||
import { t } from "../i18n";
|
||||
import type {
|
||||
CeilingType,
|
||||
@@ -56,11 +58,11 @@ function contextObjectsBounds(objs: ContextObject[]): Vec2[] | null {
|
||||
}
|
||||
|
||||
export function useProjectActions(
|
||||
// `setProject`/`notify` kommen als Parameter herein statt erneut via
|
||||
// `applyChange`/`notify` kommen als Parameter herein statt erneut via
|
||||
// useStore geholt zu werden: beide werden schon früher in App() gebraucht
|
||||
// (Command-Engine/Grips, vor dieser Sektion) und bleiben dort deklariert —
|
||||
// sonst gäbe es die Store-Action zweimal (Duplikat-Deklaration in App()).
|
||||
setProject: (next: Project | ((p: Project) => Project)) => void,
|
||||
applyChange: (ops: readonly CoreOp[] | ((p: Project) => readonly CoreOp[])) => void,
|
||||
notify: (message: string, kind?: NotifyKind) => void,
|
||||
planViewRef: RefObject<PlanViewHandle | null>,
|
||||
) {
|
||||
@@ -122,99 +124,85 @@ export function useProjectActions(
|
||||
const deleteDrawingPoint = useStore((s) => s.deleteDrawingPoint);
|
||||
const setPolylineVertexType = useStore((s) => s.setPolylineVertexType);
|
||||
// Wandstile: immutable Patch eines Wandtyps (z. B. Schichtfugen-Stile). Kein
|
||||
// eigener Store-Slice nötig — läuft direkt über setProject wie die übrigen
|
||||
// eigener Store-Slice nötig — läuft direkt über applyChange wie die übrigen
|
||||
// Ressourcen-Mutationen.
|
||||
const patchWallType = (id: string, patch: Partial<WallType>) =>
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
wallTypes: p.wallTypes.map((wt) => (wt.id === id ? { ...wt, ...patch } : wt)),
|
||||
}));
|
||||
applyChange((p) => patchItem(p, "wallTypes", id, patch));
|
||||
// Grafische Override-Regeln: ersetzt die ganze Regelliste (Reihenfolge =
|
||||
// Priorität, oben gewinnt). Läuft wie die übrigen Ressourcen-Mutationen
|
||||
// direkt über setProject — persistiert damit automatisch im Projekt-JSON.
|
||||
// direkt über applyChange — persistiert damit automatisch im Projekt-JSON.
|
||||
const setOverrideRules = (rules: OverrideRule[]) =>
|
||||
setProject((p) => ({ ...p, overrideRules: rules }));
|
||||
applyChange((p) => fieldOps(p, "overrideRules", rules));
|
||||
// Deckenstile: immutable Patch eines Deckentyps — analog `patchWallType`.
|
||||
const patchCeilingType = (id: string, patch: Partial<CeilingType>) =>
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
ceilingTypes: (p.ceilingTypes ?? []).map((ct) =>
|
||||
ct.id === id ? { ...ct, ...patch } : ct,
|
||||
),
|
||||
}));
|
||||
applyChange((p) => patchItem(p, "ceilingTypes", id, patch));
|
||||
// Neuen Wandtyp anlegen: eine Default-Schicht (erstes Bauteil, 200 mm).
|
||||
const addWallType = () =>
|
||||
setProject((p) => {
|
||||
applyChange((p) => {
|
||||
const componentId = p.components[0]?.id ?? "";
|
||||
const wallType: WallType = {
|
||||
id: `wt-${Date.now()}`,
|
||||
name: t("default.wallTypeName"),
|
||||
layers: [{ componentId, thickness: 0.2 }],
|
||||
};
|
||||
return { ...p, wallTypes: [...p.wallTypes, wallType] };
|
||||
return addItems("wallTypes", [wallType]);
|
||||
});
|
||||
// Wandtyp löschen — geschützt, solange ihn eine Wand verwendet.
|
||||
const deleteWallType = (id: string) =>
|
||||
setProject((p) => {
|
||||
applyChange((p) => {
|
||||
const used = p.walls.some((w) => w.wallTypeId === id);
|
||||
if (used) {
|
||||
const name = p.wallTypes.find((wt) => wt.id === id)?.name ?? id;
|
||||
notify(t("alert.wallTypeInUse", { name }), "warning");
|
||||
return p;
|
||||
return [];
|
||||
}
|
||||
return { ...p, wallTypes: p.wallTypes.filter((wt) => wt.id !== id) };
|
||||
return removeItems(p, "wallTypes", [id]);
|
||||
});
|
||||
// Neuen Deckentyp anlegen — analog `addWallType` (150 mm Default).
|
||||
const addCeilingType = () =>
|
||||
setProject((p) => {
|
||||
applyChange((p) => {
|
||||
const componentId = p.components[0]?.id ?? "";
|
||||
const ceilingType: CeilingType = {
|
||||
id: `ct-${Date.now()}`,
|
||||
name: t("default.ceilingTypeName"),
|
||||
layers: [{ componentId, thickness: 0.15 }],
|
||||
};
|
||||
return { ...p, ceilingTypes: [...(p.ceilingTypes ?? []), ceilingType] };
|
||||
return addItems("ceilingTypes", [ceilingType]);
|
||||
});
|
||||
// Deckentyp löschen — geschützt, solange ihn eine Decke verwendet.
|
||||
const deleteCeilingType = (id: string) =>
|
||||
setProject((p) => {
|
||||
applyChange((p) => {
|
||||
const used = (p.ceilings ?? []).some((c) => c.ceilingTypeId === id);
|
||||
if (used) {
|
||||
const name = (p.ceilingTypes ?? []).find((ct) => ct.id === id)?.name ?? id;
|
||||
notify(t("alert.ceilingTypeInUse", { name }), "warning");
|
||||
return p;
|
||||
return [];
|
||||
}
|
||||
return {
|
||||
...p,
|
||||
ceilingTypes: (p.ceilingTypes ?? []).filter((ct) => ct.id !== id),
|
||||
};
|
||||
return removeItems(p, "ceilingTypes", [id]);
|
||||
});
|
||||
// ── Dachtypen (Dachaufbauten) — analog Deckentyp ──────────────────────────
|
||||
const patchRoofType = (id: string, patch: Partial<RoofType>) =>
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
roofTypes: (p.roofTypes ?? []).map((rt) => (rt.id === id ? { ...rt, ...patch } : rt)),
|
||||
}));
|
||||
applyChange((p) => patchItem(p, "roofTypes", id, patch));
|
||||
const addRoofType = () =>
|
||||
setProject((p) => {
|
||||
applyChange((p) => {
|
||||
const componentId = p.components[0]?.id ?? "";
|
||||
const roofType: RoofType = {
|
||||
id: `rt-${Date.now()}`,
|
||||
name: t("default.roofTypeName"),
|
||||
layers: [{ componentId, thickness: 0.2 }],
|
||||
};
|
||||
return { ...p, roofTypes: [...(p.roofTypes ?? []), roofType] };
|
||||
return addItems("roofTypes", [roofType]);
|
||||
});
|
||||
// Dachtyp löschen — geschützt, solange ihn ein Dach verwendet.
|
||||
const deleteRoofType = (id: string) =>
|
||||
setProject((p) => {
|
||||
applyChange((p) => {
|
||||
const used = (p.roofs ?? []).some((r) => r.roofTypeId === id);
|
||||
if (used) {
|
||||
const name = (p.roofTypes ?? []).find((rt) => rt.id === id)?.name ?? id;
|
||||
notify(t("alert.roofTypeInUse", { name }), "warning");
|
||||
return p;
|
||||
return [];
|
||||
}
|
||||
return { ...p, roofTypes: (p.roofTypes ?? []).filter((rt) => rt.id !== id) };
|
||||
return removeItems(p, "roofTypes", [id]);
|
||||
});
|
||||
// ── Bauteil-Typen: Tür / Fenster / Treppe (Bibliothek) ────────────────────
|
||||
// Anlegen/Patchen/Löschen analog Wand-/Deckentyp — direkt über setProject
|
||||
@@ -222,7 +210,7 @@ export function useProjectActions(
|
||||
// per `typeId` referenziert. Defaults orientieren sich an den Element-Inline-
|
||||
// Werten (Tür 0.9×2.0, Fenster 1.2×1.4 Brüstung 0.9).
|
||||
const addDoorType = () =>
|
||||
setProject((p) => {
|
||||
applyChange(() => {
|
||||
const dt: DoorType = {
|
||||
id: `dt-${Date.now()}`,
|
||||
name: t("default.doorTypeName"),
|
||||
@@ -233,27 +221,22 @@ export function useProjectActions(
|
||||
defaultWidth: 0.9,
|
||||
defaultHeight: 2.0,
|
||||
};
|
||||
return { ...p, doorTypes: [...(p.doorTypes ?? []), dt] };
|
||||
return addItems("doorTypes", [dt]);
|
||||
});
|
||||
const patchDoorType = (id: string, patch: Partial<DoorType>) =>
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
doorTypes: (p.doorTypes ?? []).map((dt) =>
|
||||
dt.id === id ? { ...dt, ...patch } : dt,
|
||||
),
|
||||
}));
|
||||
applyChange((p) => patchItem(p, "doorTypes", id, patch));
|
||||
const deleteDoorType = (id: string) =>
|
||||
setProject((p) => {
|
||||
applyChange((p) => {
|
||||
const used = (p.openings ?? []).some((o) => o.typeId === id);
|
||||
if (used) {
|
||||
const name = (p.doorTypes ?? []).find((dt) => dt.id === id)?.name ?? id;
|
||||
notify(t("alert.doorTypeInUse", { name }), "warning");
|
||||
return p;
|
||||
return [];
|
||||
}
|
||||
return { ...p, doorTypes: (p.doorTypes ?? []).filter((dt) => dt.id !== id) };
|
||||
return removeItems(p, "doorTypes", [id]);
|
||||
});
|
||||
const addWindowType = () =>
|
||||
setProject((p) => {
|
||||
applyChange(() => {
|
||||
const wt: WindowType = {
|
||||
id: `ft-${Date.now()}`,
|
||||
name: t("default.windowTypeName"),
|
||||
@@ -265,35 +248,27 @@ export function useProjectActions(
|
||||
defaultWidth: 1.2,
|
||||
defaultHeight: 1.4,
|
||||
};
|
||||
return { ...p, windowTypes: [...(p.windowTypes ?? []), wt] };
|
||||
return addItems("windowTypes", [wt]);
|
||||
});
|
||||
const patchWindowType = (id: string, patch: Partial<WindowType>) =>
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
windowTypes: (p.windowTypes ?? []).map((wt) =>
|
||||
wt.id === id ? { ...wt, ...patch } : wt,
|
||||
),
|
||||
}));
|
||||
applyChange((p) => patchItem(p, "windowTypes", id, patch));
|
||||
const deleteWindowType = (id: string) =>
|
||||
setProject((p) => {
|
||||
applyChange((p) => {
|
||||
const used = (p.openings ?? []).some((o) => o.typeId === id);
|
||||
if (used) {
|
||||
const name = (p.windowTypes ?? []).find((wt) => wt.id === id)?.name ?? id;
|
||||
notify(t("alert.windowTypeInUse", { name }), "warning");
|
||||
return p;
|
||||
return [];
|
||||
}
|
||||
return {
|
||||
...p,
|
||||
windowTypes: (p.windowTypes ?? []).filter((wt) => wt.id !== id),
|
||||
};
|
||||
return removeItems(p, "windowTypes", [id]);
|
||||
});
|
||||
// „Als Stil speichern": aktuellen Fenster-/Tür-Typ der Öffnung als NEUEN
|
||||
// benannten Stil ablegen und der Öffnung zuweisen (VW „Fenster speichern…").
|
||||
// Ohne Bezugstyp wird aus den Default-Feldern ein frischer Stil erzeugt.
|
||||
const saveOpeningStyle = (openingId: string, name: string) =>
|
||||
setProject((p) => {
|
||||
applyChange((p) => {
|
||||
const o = (p.openings ?? []).find((x) => x.id === openingId);
|
||||
if (!o) return p;
|
||||
if (!o) return [];
|
||||
if (o.kind === "door") {
|
||||
const base = (p.doorTypes ?? []).find((d) => d.id === o.typeId);
|
||||
const nt: DoorType = base
|
||||
@@ -308,13 +283,7 @@ export function useProjectActions(
|
||||
defaultWidth: 0.9,
|
||||
defaultHeight: 2.0,
|
||||
};
|
||||
return {
|
||||
...p,
|
||||
doorTypes: [...(p.doorTypes ?? []), nt],
|
||||
openings: (p.openings ?? []).map((x) =>
|
||||
x.id === openingId ? { ...x, typeId: nt.id } : x,
|
||||
),
|
||||
};
|
||||
return [...addItems("doorTypes", [nt]), ...patchItem(p, "openings", openingId, { typeId: nt.id })];
|
||||
}
|
||||
const base = (p.windowTypes ?? []).find((w) => w.id === o.typeId);
|
||||
const nt: WindowType = base
|
||||
@@ -330,16 +299,10 @@ export function useProjectActions(
|
||||
defaultWidth: 1.2,
|
||||
defaultHeight: 1.4,
|
||||
};
|
||||
return {
|
||||
...p,
|
||||
windowTypes: [...(p.windowTypes ?? []), nt],
|
||||
openings: (p.openings ?? []).map((x) =>
|
||||
x.id === openingId ? { ...x, typeId: nt.id } : x,
|
||||
),
|
||||
};
|
||||
return [...addItems("windowTypes", [nt]), ...patchItem(p, "openings", openingId, { typeId: nt.id })];
|
||||
});
|
||||
const addStairType = () =>
|
||||
setProject((p) => {
|
||||
applyChange(() => {
|
||||
const st: StairType = {
|
||||
id: `st-${Date.now()}`,
|
||||
name: t("default.stairTypeName"),
|
||||
@@ -350,24 +313,19 @@ export function useProjectActions(
|
||||
railing: "keine",
|
||||
defaultWidth: 1.0,
|
||||
};
|
||||
return { ...p, stairTypes: [...(p.stairTypes ?? []), st] };
|
||||
return addItems("stairTypes", [st]);
|
||||
});
|
||||
const patchStairType = (id: string, patch: Partial<StairType>) =>
|
||||
setProject((p) => ({
|
||||
...p,
|
||||
stairTypes: (p.stairTypes ?? []).map((st) =>
|
||||
st.id === id ? { ...st, ...patch } : st,
|
||||
),
|
||||
}));
|
||||
applyChange((p) => patchItem(p, "stairTypes", id, patch));
|
||||
const deleteStairType = (id: string) =>
|
||||
setProject((p) => {
|
||||
applyChange((p) => {
|
||||
const used = (p.stairs ?? []).some((s) => s.typeId === id);
|
||||
if (used) {
|
||||
const name = (p.stairTypes ?? []).find((st) => st.id === id)?.name ?? id;
|
||||
notify(t("alert.stairTypeInUse", { name }), "warning");
|
||||
return p;
|
||||
return [];
|
||||
}
|
||||
return { ...p, stairTypes: (p.stairTypes ?? []).filter((st) => st.id !== id) };
|
||||
return removeItems(p, "stairTypes", [id]);
|
||||
});
|
||||
const importLineStyles = useStore((s) => s.importLineStyles);
|
||||
const importHatches = useStore((s) => s.importHatches);
|
||||
|
||||
Reference in new issue
Block a user