[89] Layout-Blatt: Zeichnen wie im Grundriss (Blatt-Ebene statt eigener Annotationen)

Jedes Layout hat eine Blatt-Ebene (DrawingLevel.layoutId, Papier 1:1 in Metern); ein offenes Blatt
macht sie zur aktiven Ebene in derselben PlanView: gleiche Befehle, Fang, Griffe, Vorschau/HUD,
Auswahl, Undo und dasselbe Rendering. Das Blatt liefert nur den Hintergrund (PlanView.backdrop) und
das Platzieren der Viewports. Format 3 migriert Layout.annotations zu drawings2d. Layout-PDF legt die
Blatt-Ebene über planToPrintSvg aufs Papier. Alter Annotations-Pfad gelöscht. e2e layoutSheet.spec.ts.
This commit is contained in:
Claude committed 2026-10-29 20:29:55 +00:00
1 parent c78021473b
commit 3ff123773a
43 files changed
+1245 -2756

No files matched your search

+1 -8
View File
@@ -352,15 +352,8 @@ export interface Selection {
| "extrudedSolid"
| "column"
| "roof"
| "contextObject"
| "layoutAnnotation";
| "contextObject";
id: string;
/**
* Konkrete Art der Layout-Annotation (nur `kind === "layoutAnnotation"`) —
* steuert z. B., ob die Strichstärke editierbar ist (Linie/Rechteck ja,
* Text/Bild nein).
*/
annotKind?: "line" | "rect" | "text" | "image";
/** Grafik-Kategorie (Ebene) des Elements. */
categoryCode: string;
/**
+3 -3
View File
@@ -52,7 +52,7 @@ describe("Projekt laden ([K4] S4)", () => {
st().undo();
expect(st().project).toBe(next);
// Kern-Dokument = Leseansicht (Speichern aus dem Kern).
expect(JSON.parse(serializeProject(st().project))).toEqual({ ...next, formatVersion: 2 });
expect(JSON.parse(serializeProject(st().project))).toEqual({ ...next, formatVersion: 3 });
});
it("openProjectFile: Kern liest, migriert und lädt direkt; Verlauf leer; kaputte Datei ändert nichts", () => {
@@ -70,7 +70,7 @@ describe("Projekt laden ([K4] S4)", () => {
expect(r.ok && r.migratedFrom).toBe(1);
expect(st().undoDepth).toBe(0);
expect(st().redoDepth).toBe(0);
expect(st().project.formatVersion).toBe(2);
expect(st().project.formatVersion).toBe(3);
expect(st().project.openings?.some((o) => o.id === "TX" && o.kind === "door")).toBe(true);
expect("doors" in st().project).toBe(false);
// Danach normal weiterarbeiten: ein Schritt, Undo zurück auf den geladenen Stand.
@@ -78,6 +78,6 @@ describe("Projekt laden ([K4] S4)", () => {
st().setProject(opsMutation((p) => patchItem(p, "walls", p.walls[0].id, { height: 7 })));
st().undo();
expect(st().project).toEqual(loaded);
expect(serializeProject(st().project)).toBe(JSON.stringify({ formatVersion: 2, ...loaded }, null, 2));
expect(serializeProject(st().project)).toBe(JSON.stringify({ formatVersion: 3, ...loaded }, null, 2));
});
});
+10 -3
View File
@@ -27,6 +27,11 @@ import type { Vec2 } from "../model/types";
export function useImageImportHandling(opts: {
activeLevelId: string;
activeCategoryCode: string;
/**
* Einfügen auf einem Layout-Blatt (Papier 1:1 in Metern): Bildbreite und Mitte des Bilds
* (sonst 2 m breit am Modell-Nullpunkt).
*/
imagePlacement?: { widthM: number; center: Vec2 };
/** Änderung als Ops (Store `applyChange`): alle Bilder eines Einfügens = ein Undo-Schritt. */
applyChange: (ops: readonly CoreOp[]) => void;
notify: (message: string, kind?: NotifyKind) => void;
@@ -48,6 +53,7 @@ export function useImageImportHandling(opts: {
const {
activeLevelId,
activeCategoryCode,
imagePlacement,
applyChange,
notify,
setSelectedDrawingId,
@@ -67,9 +73,10 @@ export function useImageImportHandling(opts: {
assets: { src: string; naturalWidth: number; naturalHeight: number }[],
) => {
const drawings = assets.map((a, i) => {
const { widthM, heightM } = defaultImageSizeM(a.naturalWidth, a.naturalHeight);
const cascade = i * 0.3;
const at: Vec2 = { x: -widthM / 2 + cascade, y: -heightM / 2 - cascade };
const { widthM, heightM } = defaultImageSizeM(a.naturalWidth, a.naturalHeight, imagePlacement?.widthM);
const cascade = i * 0.15 * widthM;
const c = imagePlacement?.center ?? { x: 0, y: 0 };
const at: Vec2 = { x: c.x - widthM / 2 + cascade, y: c.y - heightM / 2 - cascade };
return imageDrawing2d(activeLevelId, activeCategoryCode, a.src, at, widthM, heightM);
});
applyChange(addItems("drawings2d", drawings));
+17 -26
View File
@@ -11,7 +11,7 @@ import { applyFillMode } from "./fillMode";
import { addItems, fieldOps, opsMutation, patchItem, patchItems, removeItems, removeRoofHole, setFieldIfChanged, setRoofEdge } from "../core";
import type { CoreOp, ProjectMutation } from "../core";
import { useMemo, type RefObject } from "react";
import type { DrawingLevel, Layout, Project } from "../model/types";
import type { DrawingLevel, Project } from "../model/types";
import { resolvePenColor } from "../model/penSets";
import type { ToolId } from "../tools/types";
import type { ViewType } from "../model/viewTypes";
@@ -52,7 +52,7 @@ import {
deleteMasterFolder,
moveLayoutToFolder,
moveFolderToFolder,
patchAnnotation as patchAnnotationInLayout,
createSheetLevel,
} from "../model/layoutModel";
import { folderPdfBytes } from "../export/layoutPdf";
import { saveBinaryFile } from "../native/saveFile";
@@ -124,8 +124,6 @@ export function usePanelHostBase(opts: {
openSettings: () => void;
onOpenStampEditor: (roomId: string) => void;
openResources: (tab?: ResourceTabId) => void;
activeLayout: Layout | undefined;
patchOpenLayout: (id: string, fn: (l: Layout) => Layout) => void;
dxfInputRef: RefObject<HTMLInputElement | null>;
planViewRef: RefObject<PlanViewHandle | null>;
selection: Selection | null;
@@ -244,8 +242,6 @@ export function usePanelHostBase(opts: {
openSettings,
onOpenStampEditor,
openResources,
activeLayout,
patchOpenLayout,
dxfInputRef,
planViewRef,
selection,
@@ -422,15 +418,9 @@ export function usePanelHostBase(opts: {
updateStair(selection.id, { color });
else if (selection.kind === "room")
updateRoom(selection.id, { color });
else if (selection.kind === "layoutAnnotation" && activeLayout)
patchOpenLayout(activeLayout.id, (l) =>
patchAnnotationInLayout(l, selection.id, { color }),
);
},
// Stift-Kopplung der Farbe oben (s. `Selection.colorPenId`-Doku) —
// dieselben Selektionsarten wie `onSetSelectionColor`, MINUS Layout-
// Annotation (kein `colorPenId`-Feld dort, bewusster Scope-Schnitt s.
// PENDENZEN.md). `penId` gesetzt ⇒ Farbe sofort aus dem aktiven
// dieselben Selektionsarten wie `onSetSelectionColor`. `penId` gesetzt ⇒ Farbe sofort aus dem aktiven
// Stiftsatz backen; `undefined` ⇒ nur die Kopplung lösen, letzter
// gebackener Wert bleibt als freie Farbe stehen.
onSetSelectionColorPen: (penId) => {
@@ -445,15 +435,10 @@ export function usePanelHostBase(opts: {
else if (selection.kind === "room") updateRoom(selection.id, patch);
},
onSetSelectionWeight: (weightMm) => {
// Strichstärke-Override: Wand/Decke (`strokeWeight`) oder Drawing2D/
// Layout-Annotation (`weightMm`, Alt-Feldname bleibt).
// Strichstärke-Override: Wand/Decke (`strokeWeight`) oder Drawing2D (`weightMm`).
if (selection?.kind === "wall") updateWall(selection.id, { strokeWeight: weightMm });
else if (selection?.kind === "ceiling")
updateCeiling(selection.id, { strokeWeight: weightMm });
else if (selection?.kind === "layoutAnnotation" && activeLayout)
patchOpenLayout(activeLayout.id, (l) =>
patchAnnotationInLayout(l, selection.id, { weightMm }),
);
else if (selection?.kind === "drawing2d")
setElementWeight(selection.id, weightMm);
},
@@ -507,10 +492,6 @@ export function usePanelHostBase(opts: {
),
),
);
else if (selection?.kind === "layoutAnnotation" && activeLayout)
patchOpenLayout(activeLayout.id, (l) =>
patchAnnotationInLayout(l, selection.id, { opacity }),
);
else if (selection?.kind === "contextObject")
applyChange((p) =>
patchItem(p, "context", selection.id, (o) => (o.type === "image" ? { ...o, opacity } : o)),
@@ -1324,14 +1305,24 @@ 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);
applyChange(addItems("layouts", [lay]));
// Jedes Blatt trägt seine Blatt-Ebene (2D-Zeichnung auf dem Blatt, s. layoutModel).
applyChange([...addItems("layouts", [lay]), ...addItems("drawingLevels", [createSheetLevel(`sheet-${lay.id}`, lay)])]);
setActiveLayoutId(lay.id);
},
onRenameLayout: (id, name) => {
applyChange((p) => patchItem(p, "layouts", id, { name }));
},
onDeleteLayout: (id) => {
applyChange((p) => removeItems(p, "layouts", [id]));
// Mit dem Layout gehen seine Blatt-Ebene und deren Zeichnungen (ein Undo-Schritt).
applyChange((p) => {
const levels = p.drawingLevels.filter((l) => l.layoutId === id).map((l) => l.id);
const drawings = p.drawings2d.filter((d) => levels.includes(d.levelId)).map((d) => d.id);
return [
...removeItems(p, "drawings2d", drawings),
...removeItems(p, "drawingLevels", levels),
...removeItems(p, "layouts", [id]),
];
});
setActiveLayoutId((cur) => (cur === id ? null : cur));
},
onOpenLayout: (id) => setActiveLayoutId(id),
@@ -1413,7 +1404,7 @@ export function usePanelHostBase(opts: {
? { customWidthMm, customHeightMm }
: {}),
};
applyChange(addItems("layouts", [full]));
applyChange([...addItems("layouts", [full]), ...addItems("drawingLevels", [createSheetLevel(`sheet-${id}`, full)])]);
return id;
},
onCreateMasterLayout: (opts) => {