Merge [K4][6][8] Restliche Aktionen erzeugen Ops direkt (Editier-Befehle, Einfuegen/Gruppen, Panels, Ressourcen, 3D-Griffe); Patch auf gleichen Wert erzeugt keinen Undo-Schritt
Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
59 files changed
+1311
-960
No files matched your search
@@ -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"];
|
||||
}
|
||||
>,
|
||||
),
|
||||
|
||||
@@ -56,24 +56,24 @@ function project(groups: Group[]): Project {
|
||||
describe("groupSelection", () => {
|
||||
it("erzeugt eine Gruppe aus ≥2 gewählten Elementen", () => {
|
||||
const p = project([]);
|
||||
const res = groupSelection(p, { ...EMPTY_MEM, wallIds: ["w1", "w2"] }, []);
|
||||
const res = groupSelection({ ...EMPTY_MEM, wallIds: ["w1", "w2"] }, []);
|
||||
expect(res).not.toBeNull();
|
||||
expect(res!.project.groups).toHaveLength(1);
|
||||
expect(res!.project.groups![0]).toMatchObject({ wallIds: ["w1", "w2"], groupIds: [] });
|
||||
const out = applyOps(p, res!.ops);
|
||||
expect(out.groups).toHaveLength(1);
|
||||
expect(out.groups![0]).toMatchObject({ wallIds: ["w1", "w2"], groupIds: [] });
|
||||
});
|
||||
|
||||
it("weniger als 2 Elemente gruppiert nicht (Vectorworks-Konvention)", () => {
|
||||
const p = project([]);
|
||||
expect(groupSelection(p, { ...EMPTY_MEM, wallIds: ["w1"] }, [])).toBeNull();
|
||||
expect(groupSelection(p, EMPTY_MEM, [])).toBeNull();
|
||||
expect(groupSelection({ ...EMPTY_MEM, wallIds: ["w1"] }, [])).toBeNull();
|
||||
expect(groupSelection(EMPTY_MEM, [])).toBeNull();
|
||||
});
|
||||
|
||||
it("bereits gewählte Gruppen werden als Untergruppen verschachtelt, nicht vermischt", () => {
|
||||
const inner: Group = { id: "g1", wallIds: ["w1"], drawingIds: [], ceilingIds: [], roomIds: [], stairIds: [], columnIds: [], roofIds: [], openingIds: [], groupIds: [] };
|
||||
const p = project([inner]);
|
||||
const res = groupSelection(p, { ...EMPTY_MEM, wallIds: ["w2"] }, ["g1"]);
|
||||
const res = groupSelection({ ...EMPTY_MEM, wallIds: ["w2"] }, ["g1"]);
|
||||
expect(res).not.toBeNull();
|
||||
const outer = res!.project.groups!.find((g) => g.id === res!.groupId)!;
|
||||
const outer = applyOps(p, res!.ops).groups!.find((g) => g.id === res!.groupId)!;
|
||||
expect(outer.wallIds).toEqual(["w2"]);
|
||||
expect(outer.groupIds).toEqual(["g1"]);
|
||||
});
|
||||
@@ -297,7 +297,7 @@ describe("ungroup", () => {
|
||||
const p = project([inner, outer]);
|
||||
const res = ungroup(p, "g2");
|
||||
expect(res).not.toBeNull();
|
||||
expect(res!.project.groups!.map((g) => g.id)).toEqual(["g1"]); // g2 weg, g1 bleibt
|
||||
expect(applyOps(p, res!.ops).groups!.map((g) => g.id)).toEqual(["g1"]); // g2 weg, g1 bleibt
|
||||
expect(res!.members.wallIds).toEqual(["w2"]);
|
||||
expect(res!.subGroupIds).toEqual(["g1"]);
|
||||
});
|
||||
|
||||
@@ -11,7 +11,7 @@ import { uniqueId } from "../tools/types";
|
||||
import type { Primitive } from "../core";
|
||||
import { applyOps } from "../core";
|
||||
import type { CoreOp } from "../core";
|
||||
import { itemsOf, patchItem } from "../core";
|
||||
import { addItems, itemsOf, patchItem, removeItems } from "../core";
|
||||
import type { EntityCollection } from "../core";
|
||||
|
||||
/** Mitglieds-IDs je Elementart — dieselbe Form wie `Group`, ohne `id`/`name`/`groupIds`. */
|
||||
@@ -353,10 +353,9 @@ export function activeGroupOps(before: Project, ops: readonly CoreOp[], groupPat
|
||||
* ihre Mitglieder platt zu vermischen). Leere Auswahl → `null` (nichts zu tun).
|
||||
*/
|
||||
export function groupSelection(
|
||||
project: Project,
|
||||
sel: GroupMembership,
|
||||
selectedGroupIds: string[],
|
||||
): { project: Project; groupId: string } | null {
|
||||
): { ops: CoreOp[]; groupId: string } | null {
|
||||
const totalCount =
|
||||
KEYS.reduce((n, k) => n + sel[k].length, 0) + selectedGroupIds.length;
|
||||
if (totalCount < 2) return null; // Gruppieren braucht ≥ 2 Elemente (Vectorworks-Konvention)
|
||||
@@ -373,7 +372,7 @@ export function groupSelection(
|
||||
openingIds: sel.openingIds,
|
||||
groupIds: [...selectedGroupIds],
|
||||
};
|
||||
return { project: { ...project, groups: [...(project.groups ?? []), g] }, groupId: id };
|
||||
return { ops: addItems("groups", [g]), groupId: id };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -386,11 +385,11 @@ export function groupSelection(
|
||||
export function ungroup(
|
||||
project: Project,
|
||||
groupId: string,
|
||||
): { project: Project; members: GroupMembership; subGroupIds: string[] } | null {
|
||||
): { ops: CoreOp[]; members: GroupMembership; subGroupIds: string[] } | null {
|
||||
const g = (project.groups ?? []).find((x) => x.id === groupId);
|
||||
if (!g) return null;
|
||||
return {
|
||||
project: { ...project, groups: (project.groups ?? []).filter((x) => x.id !== groupId) },
|
||||
ops: removeItems(project, "groups", [groupId]),
|
||||
members: {
|
||||
wallIds: g.wallIds,
|
||||
drawingIds: g.drawingIds,
|
||||
|
||||
@@ -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"]);
|
||||
});
|
||||
});
|
||||
+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", [])),
|
||||
};
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import type { CopyMode, TransformOp } from "../tools/transform";
|
||||
import type { CommandEngine } from "../commands/engine";
|
||||
import type { CommandLineHandle } from "../ui/CommandLine";
|
||||
import type { Drawing2D, Project, Vec2 } from "../model/types";
|
||||
import type { CoreOp } from "../core";
|
||||
import { differenceDrawings, intersectionDrawings, unionDrawings } from "../editors/booleanOps";
|
||||
import type { BooleanResult } from "../editors/booleanOps";
|
||||
import { groupSelection, mergeMembership, ungroup, EMPTY_MEMBERSHIP } from "./groupActions";
|
||||
@@ -548,7 +549,7 @@ export function useElementClipboardShortcut(
|
||||
setElementClipboard: (c: ElementClipboard | null) => void,
|
||||
activeLevelId: string,
|
||||
project: Project,
|
||||
setProject: (next: Project | ((p: Project) => Project)) => void,
|
||||
applyChange: (ops: readonly CoreOp[]) => void,
|
||||
setSelected: {
|
||||
wallIds: (ids: string[]) => void;
|
||||
drawingIds: (ids: string[]) => void;
|
||||
@@ -587,8 +588,8 @@ export function useElementClipboardShortcut(
|
||||
e.preventDefault();
|
||||
const paste = (clip: ElementClipboard | null) => {
|
||||
if (!clip || isClipboardEmpty(clip)) return;
|
||||
const { project: next, pastedIds } = pasteElementClipboard(project, clip, activeLevelId);
|
||||
setProject(next);
|
||||
const { ops, pastedIds } = pasteElementClipboard(clip, activeLevelId);
|
||||
applyChange(ops);
|
||||
setSelected.wallIds(pastedIds.wallIds);
|
||||
setSelected.drawingIds(pastedIds.drawingIds);
|
||||
setSelected.ceilingIds(pastedIds.ceilingIds);
|
||||
@@ -764,7 +765,7 @@ export function useTransformShortcuts(
|
||||
*/
|
||||
export function useGroupShortcut(
|
||||
project: Project,
|
||||
setProject: (updater: (p: Project) => Project) => void,
|
||||
applyChange: (ops: readonly CoreOp[]) => void,
|
||||
currentSelection: GroupMembership,
|
||||
selectedGroupIds: string[],
|
||||
applySelection: (mem: GroupMembership, groupIds: string[]) => void,
|
||||
@@ -781,24 +782,24 @@ export function useGroupShortcut(
|
||||
// Ungruppieren: für jede gewählte Gruppe eine Hülle auflösen; ihre
|
||||
// direkten Mitglieder (+ Untergruppen) werden die neue Auswahl.
|
||||
if (selectedGroupIds.length === 0) return;
|
||||
let p = project;
|
||||
const ops: CoreOp[] = [];
|
||||
let members: GroupMembership = { ...EMPTY_MEMBERSHIP };
|
||||
const newGroupIds: string[] = [];
|
||||
for (const gid of selectedGroupIds) {
|
||||
const res = ungroup(p, gid);
|
||||
const res = ungroup(project, gid);
|
||||
if (!res) continue;
|
||||
p = res.project;
|
||||
ops.push(...res.ops);
|
||||
members = mergeMembership(members, res.members);
|
||||
newGroupIds.push(...res.subGroupIds);
|
||||
}
|
||||
setProject(() => p);
|
||||
applyChange(ops);
|
||||
applySelection(members, newGroupIds);
|
||||
return;
|
||||
}
|
||||
// Gruppieren: aktuelle Auswahl (+ bereits gewählte Gruppen als Untergruppen).
|
||||
const res = groupSelection(project, currentSelection, selectedGroupIds);
|
||||
const res = groupSelection(currentSelection, selectedGroupIds);
|
||||
if (!res) return;
|
||||
setProject(() => res.project);
|
||||
applyChange(res.ops);
|
||||
applySelection(currentSelection, [res.groupId]);
|
||||
};
|
||||
window.addEventListener("keydown", onKey);
|
||||
|
||||
+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