[93] Merge: Zeichnen auf dem Layout-Blatt = Zeichnen im Grundriss (Blatt-Ebene mit normalen 2D-Zeichnungen, Format 3 migriert Anmerkungen)
Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
43 files changed
+1245
-2756
No files matched your search
+82
-136
@@ -27,6 +27,7 @@ import type {
|
||||
Drawing2D,
|
||||
DrawingLevel,
|
||||
Layout,
|
||||
LayoutViewport,
|
||||
Project,
|
||||
Roof,
|
||||
Vec2,
|
||||
@@ -78,16 +79,18 @@ import {
|
||||
} from "./viewport/grip3dHud";
|
||||
import { ResourceManager } from "./ui/ResourceManager";
|
||||
import type { ResourceManagerHandlers, TabId as ResourceTabId } from "./ui/ResourceManager";
|
||||
import { LayoutSheetView } from "./ui/LayoutSheet";
|
||||
import {
|
||||
createViewport,
|
||||
createAnnotation,
|
||||
createSheetLevel,
|
||||
effectiveSheetSizeMm,
|
||||
findMaster,
|
||||
isSheetLevel,
|
||||
sheetMmToModel,
|
||||
sheetLevelOf,
|
||||
SHEET_SCALE_DENOMINATOR,
|
||||
addViewport as addViewportToLayout,
|
||||
removeViewport as removeViewportFromLayout,
|
||||
patchViewport as patchViewportInLayout,
|
||||
addAnnotation as addAnnotationToLayout,
|
||||
removeAnnotation as removeAnnotationFromLayout,
|
||||
patchAnnotation as patchAnnotationInLayout,
|
||||
} from "./model/layoutModel";
|
||||
import { HatchSwatch } from "./ui/hatchPreview";
|
||||
import { TopBar, ViewRibbonTab } from "./ui/TopBar";
|
||||
@@ -511,13 +514,6 @@ export default function App() {
|
||||
setEditTextMinHeightM,
|
||||
} = useContextMenuState();
|
||||
|
||||
// Gewählte Annotation auf einem offenen Layout-Blatt (Linie/Rechteck/Text/
|
||||
// Bild) — gehoben aus LayoutSheetView, damit die Attribute-Palette (rechtes
|
||||
// Panel) dieselbe Auswahl sieht wie ein Drawing2D im Grundriss.
|
||||
const [selectedLayoutAnnotationId, setSelectedLayoutAnnotationId] = useState<string | null>(
|
||||
null,
|
||||
);
|
||||
|
||||
// Beim Geschosswechsel die Wand-Auswahl + offene Overlays zurücksetzen (die
|
||||
// Wände eines anderen Geschosses sind eine andere Menge). Der Ansichtswechsel
|
||||
// (Grundriss ↔ 3D) lässt die Auswahl bestehen — dieselbe wallId gilt in
|
||||
@@ -602,6 +598,8 @@ export default function App() {
|
||||
const activeLevel =
|
||||
project.drawingLevels.find((z) => z.id === activeLevelId) ??
|
||||
project.drawingLevels[0];
|
||||
// Massstab der Arbeitsebene: auf einem Blatt Papier 1:1, sonst der gewählte Plan-Massstab.
|
||||
const planScale = isSheetLevel(activeLevel) ? SHEET_SCALE_DENOMINATOR : scaleDenominator;
|
||||
|
||||
// Sichtbare Kategorie-Codes — Basisfilter für Grundriss & 3D.
|
||||
const visibleCodes = useMemo(
|
||||
@@ -1041,24 +1039,10 @@ export default function App() {
|
||||
// Ein Klick auf ein gekoppeltes Zeichen-Werkzeug (Wand/Linie/Rechteck/Polylinie)
|
||||
// STARTET den passenden Befehl in der Engine und fokussiert das Befehlsfeld
|
||||
// („Dialog drin"). „Auswahl" beendet einen laufenden Befehl (Auswahl-Modus).
|
||||
// Zeichenwerkzeuge, die auf einem offenen Layout-Blatt sinnvoll sind (Markups
|
||||
// in Papier-mm, s. LayoutSheet.tsx `annotToolFromGlobal`) — dieselben Tool-IDs
|
||||
// wie im Grundriss, KEIN eigenes Werkzeug nur fürs Layout (Nutzer-Feedback).
|
||||
const LAYOUT_ANNOT_TOOLS: ToolId[] = ["line", "rect", "text", "textbox", "image"];
|
||||
|
||||
const onSelectTool = (id: ToolId) => {
|
||||
// Erneuter Klick auf das bereits AKTIVE Werkzeug schaltet zurück auf
|
||||
// „Auswahl" (Nutzer-Wunsch) — statt das Werkzeug einfach neu zu starten.
|
||||
if (id !== "select" && id === activeTool) id = "select";
|
||||
if (activeLayout) {
|
||||
// Ein Layout-Blatt ist offen: PlanView/die Befehls-Engine haben keinen
|
||||
// sichtbaren Canvas (LayoutSheetView ersetzt die Mitte) — Zeichenwerkzeuge
|
||||
// wertet dort `activeTool` direkt aus (Klick + ggf. Datei-Dialog fürs
|
||||
// Bild), alles andere (Wand/Raum/… — auf dem Blatt ohne Bedeutung) fällt
|
||||
// auf „Auswahl" zurück statt eine Befehls-Engine ohne Canvas zu starten.
|
||||
setActiveTool(LAYOUT_ANNOT_TOOLS.includes(id) ? id : "select");
|
||||
return;
|
||||
}
|
||||
if (id === "image") {
|
||||
// Datei-Auswahl ist async (Dateidialog) — kein Klick-Platzieren wie bei
|
||||
// den übrigen Zeichen-Werkzeugen, daher hier abgefangen statt über die
|
||||
@@ -1753,7 +1737,7 @@ export default function App() {
|
||||
modelEditable: activeLevel.kind !== "section" && activeLevel.kind !== "elevation",
|
||||
sheet: sectionSheet,
|
||||
visibleCodes,
|
||||
scaleDenominator,
|
||||
scaleDenominator: planScale,
|
||||
snap,
|
||||
setDraft,
|
||||
snapFor,
|
||||
@@ -1864,16 +1848,6 @@ export default function App() {
|
||||
planViewRef,
|
||||
);
|
||||
|
||||
// Gewählte Layout-Annotation als echtes Objekt (statt nur ihrer Id) — liegt
|
||||
// in `Layout.annotations` (Papier-mm), NICHT im Modell, daher separat von
|
||||
// `deriveSelection` (die nur Projekt-Bauteile kennt) aufgelöst. Muss VOR
|
||||
// `textTarget`/`selection` stehen (beide lesen sie synchron im selben Render).
|
||||
const selectedLayoutAnnotation = useMemo(() => {
|
||||
if (activeLayoutId === null || !selectedLayoutAnnotationId) return null;
|
||||
const layout = (project.layouts ?? []).find((l) => l.id === activeLayoutId);
|
||||
return layout?.annotations?.find((a) => a.id === selectedLayoutAnnotationId) ?? null;
|
||||
}, [project.layouts, activeLayoutId, selectedLayoutAnnotationId]);
|
||||
|
||||
// Text-Ziel der Oberleisten-Text-Gruppe: der Stempel-Text des (einzeln)
|
||||
// gewählten Raums. Ohne aktive Editor-Auswahl wirkt Formatierung auf das ganze
|
||||
// Doc (range: null). Ist kein Raum gewählt → null (Controls setzen nur
|
||||
@@ -1914,21 +1888,6 @@ export default function App() {
|
||||
};
|
||||
}
|
||||
}
|
||||
// Ausgewähltes Text-Markup auf einem offenen Layout-Blatt: wie Raum-Stempel
|
||||
// OHNE Grössen-Kopplung ans Modell (Papier-mm-Kontext, `heightMm` ist bereits
|
||||
// der Basiswert für Runs ohne eigene `sizePt`) — die Oberleisten-Grösse
|
||||
// wirkt hier also normal, anders als bei freiem Grundriss-Text oben.
|
||||
if (selectedLayoutAnnotation && selectedLayoutAnnotation.kind === "text" && activeLayoutId !== null) {
|
||||
const ann = selectedLayoutAnnotation;
|
||||
return {
|
||||
doc: ann.doc ?? docFromText(ann.text),
|
||||
range: null,
|
||||
apply: (newDoc: RichTextDoc) =>
|
||||
patchOpenLayout(activeLayoutId, (l) =>
|
||||
patchAnnotationInLayout(l, ann.id, { doc: newDoc, text: plainText(newDoc) }),
|
||||
),
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}, [
|
||||
selectedRoom,
|
||||
@@ -1936,8 +1895,6 @@ export default function App() {
|
||||
selectedDrawingId,
|
||||
project.drawings2d,
|
||||
updateDrawing2D,
|
||||
selectedLayoutAnnotation,
|
||||
activeLayoutId,
|
||||
]);
|
||||
|
||||
// ── 3D-Editier-Griffe (direkt im Viewport3D) ──────────────────────────────
|
||||
@@ -2287,26 +2244,7 @@ export default function App() {
|
||||
|
||||
// ── Selektions-Attribut-Kontrakt (Attributes-/Object-Info-Paletten) ───────
|
||||
// Normalisierte, effektiv aufgelöste Sicht auf das erste selektierte Element.
|
||||
// Eine gewählte Layout-Annotation hat Vorrang (eigener, minimaler Zweig —
|
||||
// sie ist kein Projekt-Bauteil, `deriveSelection` kennt sie nicht): Farbe
|
||||
// (Linie/Rechteck/Text) + Strichstärke (nur Linie/Rechteck, s. `annotKind`-
|
||||
// Prüfung in AttributesPanel) landen so in DERSELBEN Palette wie ein
|
||||
// Drawing2D im Grundriss (Nutzer-Feedback).
|
||||
const selection = useMemo((): Selection | null => {
|
||||
if (selectedLayoutAnnotation) {
|
||||
const a = selectedLayoutAnnotation;
|
||||
return {
|
||||
kind: "layoutAnnotation",
|
||||
annotKind: a.kind,
|
||||
id: a.id,
|
||||
categoryCode: "",
|
||||
color: ("color" in a ? a.color : undefined) ?? "#111111",
|
||||
weightMm: ("weightMm" in a ? a.weightMm : undefined) ?? 0.25,
|
||||
isImage: a.kind === "image",
|
||||
opacity: a.kind === "image" ? a.opacity ?? 1 : undefined,
|
||||
bbox: { minX: 0, minY: 0, maxX: 0, maxY: 0 },
|
||||
};
|
||||
}
|
||||
return deriveSelection(
|
||||
project,
|
||||
selectedWallIds,
|
||||
@@ -2321,7 +2259,6 @@ export default function App() {
|
||||
selectedContextObjectIds.length === 1 ? selectedContextObjectIds[0] : null,
|
||||
);
|
||||
}, [
|
||||
selectedLayoutAnnotation,
|
||||
project,
|
||||
selectedWallIds,
|
||||
selectedDrawingId,
|
||||
@@ -2643,6 +2580,60 @@ export default function App() {
|
||||
const patchOpenLayout = (id: string, fn: (l: Layout) => Layout, coalesceKey?: string) =>
|
||||
applyChange((p) => patchItem(p, "layouts", id, fn), coalesceKey);
|
||||
|
||||
// Ein offenes Blatt IST eine Zeichnungsebene: seine Blatt-Ebene (`layoutId`) wird die aktive Ebene,
|
||||
// damit Werkzeuge, Befehle, Fang, Griffe, Auswahl und Undo genau wie im Grundriss wirken. Beim
|
||||
// Schliessen kehrt die vorige Ebene zurück; wählt man im Navigator eine andere Ebene, schliesst
|
||||
// das Blatt.
|
||||
const sheetLevel = activeLayout ? sheetLevelOf(project, activeLayout.id) : undefined;
|
||||
const levelBeforeSheetRef = useRef<string | null>(null);
|
||||
const enteredSheetRef = useRef<string | null>(null);
|
||||
useEffect(() => {
|
||||
const current = project.drawingLevels.find((l) => l.id === activeLevelId);
|
||||
if (activeLayout) {
|
||||
if (!sheetLevel) {
|
||||
// Layout ohne Blatt-Ebene (z. B. per CLI angelegt): einmal nachtragen.
|
||||
applyChange(addItems("drawingLevels", [createSheetLevel(`sheet-${activeLayout.id}`, activeLayout)]));
|
||||
return;
|
||||
}
|
||||
if (activeLevelId === sheetLevel.id) {
|
||||
enteredSheetRef.current = activeLayout.id;
|
||||
return;
|
||||
}
|
||||
if (enteredSheetRef.current === activeLayout.id) {
|
||||
enteredSheetRef.current = null;
|
||||
setActiveLayoutId(null);
|
||||
return;
|
||||
}
|
||||
if (current && !isSheetLevel(current)) levelBeforeSheetRef.current = current.id;
|
||||
setActiveLevelId(sheetLevel.id);
|
||||
return;
|
||||
}
|
||||
enteredSheetRef.current = null;
|
||||
if (current && !isSheetLevel(current)) return;
|
||||
const back =
|
||||
project.drawingLevels.find((l) => l.id === levelBeforeSheetRef.current && !isSheetLevel(l)) ??
|
||||
project.drawingLevels.find((l) => !isSheetLevel(l));
|
||||
if (back && back.id !== activeLevelId) setActiveLevelId(back.id);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [activeLayout?.id, sheetLevel?.id, activeLevelId]);
|
||||
const sheetPane =
|
||||
activeLayout && sheetLevel && activeLevelId === sheetLevel.id
|
||||
? {
|
||||
layout: activeLayout,
|
||||
handlers: {
|
||||
onBack: () => setActiveLayoutId(null),
|
||||
onPatchViewport: (viewportId: string, patch: Partial<Omit<LayoutViewport, "id" | "snapshotId">>) =>
|
||||
patchOpenLayout(activeLayout.id, (l) => patchViewportInLayout(l, viewportId, patch)),
|
||||
onRemoveViewport: (viewportId: string) =>
|
||||
patchOpenLayout(activeLayout.id, (l) => removeViewportFromLayout(l, viewportId)),
|
||||
onAddViewport: (snapshotId: string, init: Partial<Omit<LayoutViewport, "id" | "snapshotId">>) =>
|
||||
patchOpenLayout(activeLayout.id, (l) =>
|
||||
addViewportToLayout(l, createViewport(`vp-${Date.now()}`, snapshotId, init)),
|
||||
),
|
||||
},
|
||||
}
|
||||
: null;
|
||||
|
||||
// ── Effektive Darstellung für die Hauptansicht ────────────────────────────
|
||||
// 3D: Geschosse nach dem Modus des Zeichnungsebenen-Panels, Kategorien nach
|
||||
// dem Modus des Ebenen-Panels. Grundriss: Kategorien nach dem Ebenen-Panel.
|
||||
@@ -2665,8 +2656,13 @@ export default function App() {
|
||||
const visible = new Map(
|
||||
project.drawingLevels.map((z) => [z.id, z.visible]),
|
||||
);
|
||||
// Blatt-Ebenen stehen für sich: nur sichtbar, wenn ihr Blatt offen ist, und dann allein.
|
||||
const sheets = new Set(project.drawingLevels.filter(isSheetLevel).map((z) => z.id));
|
||||
const onSheet = sheets.has(activeLevelId);
|
||||
return (id) =>
|
||||
itemDisplay(drawingLevelsMode, id === activeLevelId, visible.get(id) ?? false);
|
||||
onSheet || sheets.has(id)
|
||||
? { render: id === activeLevelId, greyed: false, locked: false }
|
||||
: itemDisplay(drawingLevelsMode, id === activeLevelId, visible.get(id) ?? false);
|
||||
}, [project.drawingLevels, drawingLevelsMode, activeLevelId]);
|
||||
|
||||
// Resolver: je Kategorie-Code die Render-Entscheidung. „Aktiv" = die per
|
||||
@@ -2767,7 +2763,7 @@ export default function App() {
|
||||
// bewusst nicht mitgenommen).
|
||||
useDrawingLevelsWindowHost(
|
||||
{
|
||||
drawingLevels: project.drawingLevels,
|
||||
drawingLevels: project.drawingLevels.filter((z) => !z.layoutId),
|
||||
activeLevelId,
|
||||
displayMode: drawingLevelsMode,
|
||||
},
|
||||
@@ -3066,6 +3062,14 @@ export default function App() {
|
||||
const { onImageOrPdfFileChosen } = useImageImportHandling({
|
||||
activeLevelId: activeLevel.id,
|
||||
activeCategoryCode,
|
||||
// Auf einem Blatt: 60 mm breit, mitten aufs Papier.
|
||||
imagePlacement: sheetPane
|
||||
? (() => {
|
||||
const m = findMaster(project, sheetPane.layout);
|
||||
const size = effectiveSheetSizeMm(m ?? sheetPane.layout);
|
||||
return { widthM: 0.06, center: sheetMmToModel(size.w / 2, size.h / 2) };
|
||||
})()
|
||||
: undefined,
|
||||
applyChange,
|
||||
notify,
|
||||
setSelectedDrawingId,
|
||||
@@ -3113,8 +3117,6 @@ export default function App() {
|
||||
openSettings,
|
||||
onOpenStampEditor,
|
||||
openResources,
|
||||
activeLayout,
|
||||
patchOpenLayout,
|
||||
dxfInputRef,
|
||||
planViewRef,
|
||||
selection,
|
||||
@@ -3503,69 +3505,13 @@ export default function App() {
|
||||
Befehlszeile nur so breit wie der Viewport (nicht die ganze App),
|
||||
und die Docks nehmen die volle Body-Höhe ein (inkl. der Zeile). */}
|
||||
<div className="center-col">
|
||||
{activeLayout ? (
|
||||
/* Layout-Modus (Phase 2b): das Blatt füllt den Haupt-Viewport (statt
|
||||
Grundriss/3D) und ist direkt mit der Maus editierbar — platzieren/
|
||||
verschieben/skalieren/löschen der Viewports, Pan/Zoom, mm↔Bildschirm.
|
||||
Die Befehlszeile entfällt (kein Zeichnen auf dem Blatt). */
|
||||
<LayoutSheetView
|
||||
project={project}
|
||||
layout={activeLayout}
|
||||
activeTool={activeTool}
|
||||
onToolChange={onSelectTool}
|
||||
selectedAnnotId={selectedLayoutAnnotationId}
|
||||
onSelectAnnot={setSelectedLayoutAnnotationId}
|
||||
handlers={{
|
||||
onBack: () => {
|
||||
setActiveLayoutId(null);
|
||||
setSelectedLayoutAnnotationId(null);
|
||||
// Ein auf dem Blatt armiertes Zeichenwerkzeug (line/rect/text/
|
||||
// image) hat im Grundriss KEINEN laufenden Befehl in der Engine
|
||||
// (der wird für ein offenes Layout bewusst nicht gestartet, s.
|
||||
// `onSelectTool`) — zurück auf „Auswahl", sonst zeigt das
|
||||
// Werkzeugpanel ein „aktives" Werkzeug ohne echten Befehl dahinter.
|
||||
setActiveTool("select");
|
||||
},
|
||||
onPatchViewport: (viewportId, patch) =>
|
||||
patchOpenLayout(activeLayout.id, (l) =>
|
||||
patchViewportInLayout(l, viewportId, patch),
|
||||
),
|
||||
onRemoveViewport: (viewportId) =>
|
||||
patchOpenLayout(activeLayout.id, (l) =>
|
||||
removeViewportFromLayout(l, viewportId),
|
||||
),
|
||||
onAddViewport: (snapshotId, init) =>
|
||||
patchOpenLayout(activeLayout.id, (l) =>
|
||||
addViewportToLayout(
|
||||
l,
|
||||
createViewport(`vp-${Date.now()}`, snapshotId, init),
|
||||
),
|
||||
),
|
||||
onAddAnnotation: (kind, init) => {
|
||||
const id = `ann-${Date.now()}`;
|
||||
patchOpenLayout(activeLayout.id, (l) =>
|
||||
addAnnotationToLayout(l, createAnnotation(id, kind, init)),
|
||||
);
|
||||
return id;
|
||||
},
|
||||
onPatchAnnotation: (annotationId, patch, coalesceKey) =>
|
||||
patchOpenLayout(
|
||||
activeLayout.id,
|
||||
(l) => patchAnnotationInLayout(l, annotationId, patch),
|
||||
coalesceKey,
|
||||
),
|
||||
onRemoveAnnotation: (annotationId) =>
|
||||
patchOpenLayout(activeLayout.id, (l) =>
|
||||
removeAnnotationFromLayout(l, annotationId),
|
||||
),
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
{(
|
||||
<>
|
||||
{/* Hauptansicht (Mitte) — füllt den verbleibenden Platz. Die Plan-
|
||||
Ansicht meldet Cursor + Zoom an die Status-/Oberleiste und nimmt
|
||||
das Zoom-Handle entgegen. */}
|
||||
<Content
|
||||
sheet={sheetPane}
|
||||
project={project}
|
||||
level={activeLevel}
|
||||
viewType={viewType}
|
||||
|
||||
+1
-1
@@ -170,7 +170,7 @@ function loadProject(path: string): Project {
|
||||
}
|
||||
|
||||
function findLevel(project: Project, kinds: string[], name: string | undefined) {
|
||||
const levels = project.drawingLevels.filter((l) => kinds.includes(l.kind));
|
||||
const levels = project.drawingLevels.filter((l) => kinds.includes(l.kind) && !l.layoutId);
|
||||
if (!name) return levels[0];
|
||||
const n = name.toLowerCase();
|
||||
return levels.find((l) => l.id.toLowerCase() === n || l.name.toLowerCase() === n);
|
||||
|
||||
@@ -18,13 +18,17 @@ export interface CreatePreview {
|
||||
info: number[];
|
||||
}
|
||||
|
||||
/** Kontext der Anfrage: aktive Ebene/Geschoss, Kategorie, Wandtyp. */
|
||||
/** Schrifthöhe neuer Texte auf einem Layout-Blatt (Papier 1:1): 3.5 mm. */
|
||||
export const SHEET_TEXT_HEIGHT_M = 0.0035;
|
||||
|
||||
/** Kontext der Anfrage: aktive Ebene/Geschoss, Kategorie, Wandtyp (auf einem Blatt: Papier-Schrifthöhe). */
|
||||
function ctxReq(ctx: CommandContext): object {
|
||||
return {
|
||||
level: ctx.level.id,
|
||||
floorHeight: ctx.level.floorHeight ?? null,
|
||||
cat: ctx.defaultCategoryCode,
|
||||
wallType: ctx.activeWallTypeId,
|
||||
...(ctx.level.layoutId ? { textHeight: SHEET_TEXT_HEIGHT_M } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+37
-114
@@ -12,17 +12,19 @@
|
||||
|
||||
import { jsPDF } from "jspdf";
|
||||
import "svg2pdf.js";
|
||||
import type { Layout, LayoutAnnotation, MasterLayout, Project } from "../model/types";
|
||||
import type { Layout, MasterLayout, Project } from "../model/types";
|
||||
import { generatePlan } from "../plan/generatePlan";
|
||||
import { planToPrintSvg } from "./planToPrintSvg";
|
||||
import { annotationTextLines } from "../text/renderHtml";
|
||||
import { docFromText } from "../text/richText";
|
||||
import { collectVisibleCodes } from "../model/types";
|
||||
import {
|
||||
findMaster,
|
||||
findSnapshot,
|
||||
folderPdfPages,
|
||||
resolveTitleBlock,
|
||||
resolveViewportScale,
|
||||
SHEET_SCALE_DENOMINATOR,
|
||||
sheetLevelOf,
|
||||
sheetMmToModel,
|
||||
visibleCodesFromSnapshot,
|
||||
type FolderPdfPage,
|
||||
type ResolvedTitleBlock,
|
||||
@@ -79,110 +81,36 @@ function clip(s: string, max: number): string {
|
||||
return s.length > max ? s.slice(0, max - 1) + "…" : s;
|
||||
}
|
||||
|
||||
/** "#rrggbb"/"#rgb" → [r,g,b] (0..255); ungültige Eingabe fällt auf Tinte zurück. */
|
||||
function hexToRgb(hex: string): [number, number, number] {
|
||||
const h = hex.replace("#", "").trim();
|
||||
const full = h.length === 3 ? h.split("").map((c) => c + c).join("") : h;
|
||||
const n = parseInt(full, 16);
|
||||
if (full.length !== 6 || !Number.isFinite(n)) return [17, 17, 17];
|
||||
return [(n >> 16) & 255, (n >> 8) & 255, n & 255];
|
||||
}
|
||||
|
||||
/** Bildformat aus dem MIME-Teil der Data-URL ableiten (jsPDF `addImage` braucht es explizit). */
|
||||
function imageFormatFromDataUrl(src: string): string {
|
||||
const ext = (/^data:image\/(\w+)/i.exec(src)?.[1] ?? "png").toLowerCase();
|
||||
if (ext === "jpg" || ext === "jpeg") return "JPEG";
|
||||
if (ext === "webp") return "WEBP";
|
||||
return "PNG";
|
||||
}
|
||||
|
||||
const SVG_NS = "http://www.w3.org/2000/svg";
|
||||
|
||||
/**
|
||||
* Baut EIN Mini-SVG (Blattgrösse) mit allen Text-Markups einer Seite — reiche
|
||||
* Docs (mehrere Absätze/gemischte Formatierung) + Wortumbruch bei gesetzter
|
||||
* Rahmenbreite, exakt wie `LayoutSheet.tsx`s `AnnotationSvg`. Ein gemeinsamer
|
||||
* `doc.svg()`-Aufruf statt einem je Annotation (einfacher, ein Layout-Pass).
|
||||
* `null`, wenn die Seite keine Text-Markups trägt.
|
||||
* Die 2D-Zeichnung des Blatts (Blatt-Ebene, `DrawingLevel.layoutId`) über Viewports und Master:
|
||||
* derselbe Plan wie am Bildschirm (`generatePlan`, Massstab 1:1, Export-Modus), über
|
||||
* `planToPrintSvg` fest aufs Papier gelegt (Ursprung oben links), ohne eigenes weisses Blatt.
|
||||
*/
|
||||
function buildAnnotationTextsSvg(
|
||||
annotations: LayoutAnnotation[],
|
||||
sheetW: number,
|
||||
sheetH: number,
|
||||
): SVGSVGElement | null {
|
||||
const texts = annotations.filter(
|
||||
(a): a is Extract<LayoutAnnotation, { kind: "text" }> => a.kind === "text",
|
||||
async function renderSheetDrawing(doc: jsPDF, project: Project, layout: Layout, widthMm: number, heightMm: number): Promise<void> {
|
||||
const level = sheetLevelOf(project, layout.id);
|
||||
if (!level || !project.drawings2d.some((d) => d.levelId === level.id)) return;
|
||||
const a = sheetMmToModel(0, heightMm);
|
||||
const b = sheetMmToModel(widthMm, 0);
|
||||
const plan = generatePlan(
|
||||
project,
|
||||
level.id,
|
||||
collectVisibleCodes(project.layers),
|
||||
undefined,
|
||||
"fein",
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
SHEET_SCALE_DENOMINATOR,
|
||||
true,
|
||||
);
|
||||
if (texts.length === 0) return null;
|
||||
|
||||
const svg = document.createElementNS(SVG_NS, "svg") as SVGSVGElement;
|
||||
svg.setAttribute("xmlns", SVG_NS);
|
||||
svg.setAttribute("width", String(sheetW));
|
||||
svg.setAttribute("height", String(sheetH));
|
||||
svg.setAttribute("viewBox", `0 0 ${sheetW} ${sheetH}`);
|
||||
|
||||
for (const ann of texts) {
|
||||
const el = document.createElementNS(SVG_NS, "text");
|
||||
for (const line of annotationTextLines(ann, ann.doc ?? docFromText(ann.text))) {
|
||||
const lineTspan = document.createElementNS(SVG_NS, "tspan");
|
||||
lineTspan.setAttribute("x", String(line.x));
|
||||
lineTspan.setAttribute("y", String(line.y));
|
||||
lineTspan.setAttribute("text-anchor", line.anchor);
|
||||
if (line.tspans.length === 0) {
|
||||
lineTspan.textContent = "";
|
||||
} else {
|
||||
for (const ts of line.tspans) {
|
||||
const run = document.createElementNS(SVG_NS, "tspan");
|
||||
run.setAttribute("font-size", String(ts.fontSize));
|
||||
run.setAttribute("fill", ts.fill);
|
||||
if (ts.fontWeight) run.setAttribute("font-weight", ts.fontWeight);
|
||||
if (ts.fontStyle) run.setAttribute("font-style", ts.fontStyle);
|
||||
run.setAttribute("font-family", ts.fontFamily ?? "Helvetica, Arial, sans-serif");
|
||||
if (ts.textDecoration) run.setAttribute("text-decoration", ts.textDecoration);
|
||||
run.textContent = ts.text;
|
||||
lineTspan.appendChild(run);
|
||||
}
|
||||
}
|
||||
el.appendChild(lineTspan);
|
||||
}
|
||||
svg.appendChild(el);
|
||||
}
|
||||
return svg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zeichnet die 2D-Markups (Linie/Rechteck/Bild) EINER Seite direkt via jsPDF-
|
||||
* Vektorprimitive — dieselbe Schicht wie `LayoutSheet.tsx`s Annotations-SVG,
|
||||
* hier aber ÜBER Viewports UND Master gezeichnet (Aufrufreihenfolge in
|
||||
* `renderPage`), analog zur Zeichenreihenfolge im In-Viewport-Editor.
|
||||
*/
|
||||
function drawAnnotationShapes(doc: jsPDF, layout: Layout): void {
|
||||
for (const ann of layout.annotations ?? []) {
|
||||
if (ann.kind === "line") {
|
||||
const [r, g, b] = hexToRgb(ann.color ?? "#111111");
|
||||
doc.setDrawColor(r, g, b);
|
||||
doc.setLineWidth(ann.weightMm ?? 0.25);
|
||||
doc.line(ann.x1Mm, ann.y1Mm, ann.x2Mm, ann.y2Mm);
|
||||
} else if (ann.kind === "rect") {
|
||||
const [r, g, b] = hexToRgb(ann.color ?? "#111111");
|
||||
doc.setDrawColor(r, g, b);
|
||||
doc.setLineWidth(ann.weightMm ?? 0.25);
|
||||
doc.rect(ann.xMm, ann.yMm, ann.widthMm, ann.heightMm);
|
||||
} else if (ann.kind === "image" && ann.widthMm > 0 && ann.heightMm > 0 && ann.src) {
|
||||
try {
|
||||
doc.addImage(
|
||||
ann.src,
|
||||
imageFormatFromDataUrl(ann.src),
|
||||
ann.xMm,
|
||||
ann.yMm,
|
||||
ann.widthMm,
|
||||
ann.heightMm,
|
||||
);
|
||||
} catch {
|
||||
// Defekte/leere Data-URL überspringt nur dieses Bild, nicht die Seite.
|
||||
}
|
||||
}
|
||||
}
|
||||
const print = planToPrintSvg(plan, {
|
||||
scaleDenominator: SHEET_SCALE_DENOMINATOR,
|
||||
pageWidthMm: widthMm,
|
||||
pageHeightMm: heightMm,
|
||||
bounds: { minX: a.x, minY: a.y, maxX: b.x, maxY: b.y },
|
||||
transparent: true,
|
||||
});
|
||||
await doc.svg(print.svg, { x: 0, y: 0, width: widthMm, height: heightMm });
|
||||
}
|
||||
|
||||
/** Zeichnet die Viewports + Master-Elemente EINER Seite in das jsPDF-Dokument. */
|
||||
@@ -242,16 +170,11 @@ async function renderPage(
|
||||
drawTitleBlock(doc, widthMm, heightMm, tb, layout.paper, layout.orientation);
|
||||
}
|
||||
|
||||
// 2D-Markups (Linie/Rechteck/Bild/Text) — ÜBER Viewports + Master, wie im
|
||||
// In-Viewport-Editor (LayoutSheet.tsx). Fehlte bisher komplett im Export.
|
||||
drawAnnotationShapes(doc, layout);
|
||||
const textsSvg = buildAnnotationTextsSvg(layout.annotations ?? [], widthMm, heightMm);
|
||||
if (textsSvg) {
|
||||
try {
|
||||
await doc.svg(textsSvg, { x: 0, y: 0, width: widthMm, height: heightMm });
|
||||
} catch {
|
||||
// Rich-Text-Rendering eines Markups darf die Seite nicht killen.
|
||||
}
|
||||
// 2D-Zeichnung des Blatts — ÜBER Viewports + Master, wie am Bildschirm.
|
||||
try {
|
||||
await renderSheetDrawing(doc, project, layout, widthMm, heightMm);
|
||||
} catch {
|
||||
// Eine Blatt-Zeichnung, die nicht rendert, darf die Seite nicht killen.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
// Blatt-Zeichnung im Layout-PDF: die Blatt-Ebene eines Layouts (`DrawingLevel.layoutId`, Papier 1:1 in
|
||||
// Metern) liegt über `planToPrintSvg` mit festem Bereich genau auf dem Papier — Ursprung oben links,
|
||||
// Strichstärken unverändert (auch mit `scaleLineWeights`), ohne weisses Blatt dahinter.
|
||||
|
||||
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
||||
import { generatePlan } from "../plan/generatePlan";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import { collectVisibleCodes, type Project } from "../model/types";
|
||||
import { createSheetLevel, sheetMmToModel, SHEET_SCALE_DENOMINATOR } from "../model/layoutModel";
|
||||
import { planToPrintSvg } from "./planToPrintSvg";
|
||||
|
||||
interface El {
|
||||
tag: string;
|
||||
attrs: Map<string, string>;
|
||||
kids: El[];
|
||||
textContent: string;
|
||||
setAttribute(k: string, v: unknown): void;
|
||||
getAttribute(k: string): string | null;
|
||||
appendChild(c: El): El;
|
||||
insertBefore(n: El, r: El | null): El;
|
||||
readonly firstChild: El | null;
|
||||
}
|
||||
|
||||
function el(tag: string): El {
|
||||
return {
|
||||
tag,
|
||||
attrs: new Map(),
|
||||
kids: [],
|
||||
textContent: "",
|
||||
setAttribute(k, v) {
|
||||
this.attrs.set(k, String(v));
|
||||
},
|
||||
getAttribute(k) {
|
||||
return this.attrs.get(k) ?? null;
|
||||
},
|
||||
appendChild(c) {
|
||||
this.kids.push(c);
|
||||
return c;
|
||||
},
|
||||
insertBefore(n) {
|
||||
this.kids.unshift(n);
|
||||
return n;
|
||||
},
|
||||
get firstChild() {
|
||||
return this.kids[0] ?? null;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const all = (e: El): El[] => [e, ...e.kids.flatMap(all)];
|
||||
|
||||
const sheet = createSheetLevel("blatt", { id: "L1", name: "Blatt 1" });
|
||||
const a = sheetMmToModel(10, 20);
|
||||
const b = sheetMmToModel(110, 20);
|
||||
const project: Project = {
|
||||
...sampleProject,
|
||||
scaleLineWeights: true,
|
||||
drawingLevels: [...sampleProject.drawingLevels, sheet],
|
||||
drawings2d: [
|
||||
...sampleProject.drawings2d,
|
||||
{ id: "s1", type: "drawing2d", levelId: "blatt", categoryCode: "20", geom: { shape: "line", a, b }, weightMm: 0.5, color: "#ff0000" },
|
||||
] as Project["drawings2d"],
|
||||
};
|
||||
|
||||
describe("Druck-SVG der Blatt-Ebene", () => {
|
||||
let prev: unknown;
|
||||
beforeAll(() => {
|
||||
const g = globalThis as { document?: unknown };
|
||||
prev = g.document;
|
||||
g.document = { createElementNS: (_: string, tag: string) => el(tag) };
|
||||
});
|
||||
afterAll(() => {
|
||||
(globalThis as { document?: unknown }).document = prev;
|
||||
});
|
||||
|
||||
it("liegt mm-genau auf dem Papier, Stärke 1:1, ohne weisses Blatt", () => {
|
||||
const plan = generatePlan(project, "blatt", collectVisibleCodes(project.layers), undefined, "fein", false, false, false, SHEET_SCALE_DENOMINATOR, true);
|
||||
// Nur die Blatt-Zeichnung: keine Wände des Geschosses, keine projektglobalen Zutaten.
|
||||
expect(plan.primitives.every((p) => !("wallId" in p && p.wallId))).toBe(true);
|
||||
const lo = sheetMmToModel(0, 297);
|
||||
const hi = sheetMmToModel(210, 0);
|
||||
const print = planToPrintSvg(plan, {
|
||||
scaleDenominator: SHEET_SCALE_DENOMINATOR,
|
||||
pageWidthMm: 210,
|
||||
pageHeightMm: 297,
|
||||
bounds: { minX: lo.x, minY: lo.y, maxX: hi.x, maxY: hi.y },
|
||||
transparent: true,
|
||||
});
|
||||
const svg = print.svg as unknown as El;
|
||||
expect(svg.kids.some((k) => k.tag === "rect" && k.getAttribute("fill") === "#ffffff")).toBe(false);
|
||||
const red = all(svg).filter((e) => e.getAttribute("stroke") === "#ff0000");
|
||||
expect(red.length).toBeGreaterThan(0);
|
||||
const geo = red.map((e) => e.getAttribute("points") ?? `${e.getAttribute("x1")},${e.getAttribute("y1")} ${e.getAttribute("x2")},${e.getAttribute("y2")}`).join(" ");
|
||||
const nums = geo.split(/[\s,]+/).map(Number);
|
||||
expect(nums).toHaveLength(4);
|
||||
[10, 20, 110, 20].forEach((v, i) => expect(nums[i]).toBeCloseTo(v, 6));
|
||||
expect(Number(red[0].getAttribute("stroke-width"))).toBeCloseTo(0.5, 9);
|
||||
});
|
||||
});
|
||||
@@ -100,6 +100,13 @@ export interface PrintSvgOptions {
|
||||
pageHeightMm: number;
|
||||
/** Rand um den Plan-Inhalt in mm (weisser Blattrand). */
|
||||
marginMm?: number;
|
||||
/**
|
||||
* Fester Modell-Bereich, der das Blatt füllt (statt den Inhalt zu zentrieren) — die Blatt-Ebene
|
||||
* eines Layouts liegt so genau auf dem Papier (Ursprung oben links, s. `DrawingLevel.layoutId`).
|
||||
*/
|
||||
bounds?: { minX: number; minY: number; maxX: number; maxY: number };
|
||||
/** Ohne weisses Blatt dahinter (als Schicht über anderem Inhalt). */
|
||||
transparent?: boolean;
|
||||
}
|
||||
|
||||
/** Modell-Meter → Papier-Millimeter im Massstab 1:N. */
|
||||
@@ -120,7 +127,7 @@ export function planToPrintSvg(plan: Plan, opts: PrintSvgOptions): PrintSvg {
|
||||
// bewusst, ohne ihn aktuell für einen Versatz zu nutzen (zentrierte Lage).
|
||||
void (opts.marginMm ?? 10);
|
||||
|
||||
const b = plan.bounds;
|
||||
const b = opts.bounds ?? plan.bounds;
|
||||
// Inhalts-Maße in mm (massstäblich), unverschoben.
|
||||
const contentWmm = (b.maxX - b.minX) * k;
|
||||
const contentHmm = (b.maxY - b.minY) * k;
|
||||
@@ -151,7 +158,7 @@ export function planToPrintSvg(plan: Plan, opts: PrintSvgOptions): PrintSvg {
|
||||
bg.setAttribute("width", String(opts.pageWidthMm));
|
||||
bg.setAttribute("height", String(opts.pageHeightMm));
|
||||
bg.setAttribute("fill", "#ffffff");
|
||||
svg.appendChild(bg);
|
||||
if (!opts.transparent) svg.appendChild(bg);
|
||||
|
||||
// Jedes Primitiv in mm-Knoten übersetzen (Kern, Anweisungsliste s. `plan_print_svg.rs`).
|
||||
const o = Float64Array.of(n, opts.pageWidthMm, opts.pageHeightMm, b.minX, b.minY, b.maxX, b.maxY);
|
||||
|
||||
@@ -435,8 +435,6 @@ export const de = {
|
||||
"objinfo.kind.column": "Stütze",
|
||||
"objinfo.kind.roof": "Dach",
|
||||
"objinfo.kind.contextObject": "Kontext-Objekt",
|
||||
"objinfo.kind.layoutAnnotation": "Blatt-Markup",
|
||||
"objinfo.layoutAnnotationHint": "Position/Grösse in mm direkt am Rahmen auf dem Blatt bearbeiten (Greifpunkte oder die Felder dort).",
|
||||
// ── Kontext-Objekt-Attribute (Object-Info-Panel) ────────────────────────
|
||||
"objinfo.contextObject.section": "Georeferenzierung",
|
||||
"objinfo.contextObject.type": "Art",
|
||||
@@ -2427,7 +2425,6 @@ export const de = {
|
||||
// Editor
|
||||
"layouts.editorTitle": "Layout-Editor",
|
||||
"layouts.fit": "Einpassen",
|
||||
"layouts.zoom100": "Echte Grösse (100 %, 1:1 auf dem Bildschirm)",
|
||||
"layouts.addViewport": "Viewport hinzufügen",
|
||||
"layouts.pickSnapshot": "Ausschnitt wählen …",
|
||||
"layouts.noSnapshots": "Keine Ausschnitte vorhanden. Zuerst einen Ausschnitt speichern.",
|
||||
@@ -2446,23 +2443,9 @@ export const de = {
|
||||
"layouts.placeViewport": "Viewport aufziehen",
|
||||
"layouts.placeHint": "Rechteck auf dem Blatt aufziehen, dann Ausschnitt binden.",
|
||||
"layouts.bindSnapshot": "Ausschnitt binden",
|
||||
"layouts.emptyViewports":
|
||||
"Noch keine Viewports. „Viewport aufziehen\" wählen und ein Rechteck auf dem Blatt ziehen.",
|
||||
// Annotationen (Linie/Rechteck/Text/Bild) direkt auf dem Blatt — gezeichnet
|
||||
// mit denselben Werkzeugen wie im Grundriss (linkes Werkzeugpanel), kein
|
||||
// eigenes Werkzeug nur fürs Layout.
|
||||
"layouts.annotTextTitle": "Text",
|
||||
"layouts.annotTextLabel": "Textinhalt:",
|
||||
"layouts.annotEditText": "Text ändern",
|
||||
"layouts.annotRemove": "Annotation entfernen",
|
||||
"layouts.annotX": "X (mm)",
|
||||
"layouts.annotY": "Y (mm)",
|
||||
"layouts.annotWidth": "Breite (mm)",
|
||||
"layouts.annotHeight": "Höhe (mm)",
|
||||
"layouts.annot.line": "Linie",
|
||||
"layouts.annot.rect": "Rechteck",
|
||||
"layouts.annot.text": "Text",
|
||||
"layouts.annot.image": "Bild",
|
||||
// Baum / „+"-Menü / Ordner
|
||||
"layouts.add": "Neu …",
|
||||
"layouts.addFolder": "Ordner erstellen",
|
||||
|
||||
@@ -433,8 +433,6 @@ export const en: Record<TranslationKey, string> = {
|
||||
"objinfo.kind.column": "Column",
|
||||
"objinfo.kind.roof": "Roof",
|
||||
"objinfo.kind.contextObject": "Context object",
|
||||
"objinfo.kind.layoutAnnotation": "Sheet markup",
|
||||
"objinfo.layoutAnnotationHint": "Edit position/size in mm directly on the frame on the sheet (grips or the fields there).",
|
||||
// ── Context object attributes (object info panel) ───────────────────────
|
||||
"objinfo.contextObject.section": "Georeferencing",
|
||||
"objinfo.contextObject.type": "Type",
|
||||
@@ -2414,7 +2412,6 @@ export const en: Record<TranslationKey, string> = {
|
||||
// Editor
|
||||
"layouts.editorTitle": "Layout editor",
|
||||
"layouts.fit": "Fit",
|
||||
"layouts.zoom100": "True size (100%, 1:1 on screen)",
|
||||
"layouts.addViewport": "Add viewport",
|
||||
"layouts.pickSnapshot": "Pick a view …",
|
||||
"layouts.noSnapshots": "No views available. Save a view first.",
|
||||
@@ -2433,22 +2430,8 @@ export const en: Record<TranslationKey, string> = {
|
||||
"layouts.placeViewport": "Draw viewport",
|
||||
"layouts.placeHint": "Drag a rectangle on the sheet, then bind a snapshot.",
|
||||
"layouts.bindSnapshot": "Bind snapshot",
|
||||
"layouts.emptyViewports":
|
||||
"No viewports yet. Choose “Draw viewport” and drag a rectangle on the sheet.",
|
||||
// Annotations (line/rect/text/image) drawn directly on the sheet — with the
|
||||
// same tools as the plan (left tools panel), no layout-only tool.
|
||||
"layouts.annotTextTitle": "Text",
|
||||
"layouts.annotTextLabel": "Text content:",
|
||||
"layouts.annotEditText": "Edit text",
|
||||
"layouts.annotRemove": "Remove annotation",
|
||||
"layouts.annotX": "X (mm)",
|
||||
"layouts.annotY": "Y (mm)",
|
||||
"layouts.annotWidth": "Width (mm)",
|
||||
"layouts.annotHeight": "Height (mm)",
|
||||
"layouts.annot.line": "Line",
|
||||
"layouts.annot.rect": "Rectangle",
|
||||
"layouts.annot.text": "Text",
|
||||
"layouts.annot.image": "Image",
|
||||
// Tree / “+” menu / folders
|
||||
"layouts.add": "New …",
|
||||
"layouts.addFolder": "Create folder",
|
||||
|
||||
+2
-12
@@ -1,6 +1,6 @@
|
||||
// Bild-Datei → eingebettete Data-URL + natürliche Pixelgrösse — gemeinsame
|
||||
// Grundlage für „Bild einfügen" im Plan (Drawing2D `{shape:"image"}`) UND im
|
||||
// Layout (LayoutAnnotation `kind:"image"`). Reine Browser-API (FileReader +
|
||||
// Grundlage für „Bild einfügen" (Drawing2D `{shape:"image"}`, auch auf einem
|
||||
// Layout-Blatt). Reine Browser-API (FileReader +
|
||||
// Image), kein Tauri-fs nötig — funktioniert identisch im Web-Preview.
|
||||
|
||||
export interface LoadedImageAsset {
|
||||
@@ -36,13 +36,3 @@ export function defaultImageSizeM(
|
||||
const ratio = naturalHeight / Math.max(1, naturalWidth);
|
||||
return { widthM, heightM: Math.max(0.05, widthM * ratio) };
|
||||
}
|
||||
|
||||
/** Default-Grösse (mm) fürs Layout-Blatt, analog mit anderer Default-Breite. */
|
||||
export function defaultImageSizeMm(
|
||||
naturalWidth: number,
|
||||
naturalHeight: number,
|
||||
widthMm = 60,
|
||||
): { widthMm: number; heightMm: number } {
|
||||
const ratio = naturalHeight / Math.max(1, naturalWidth);
|
||||
return { widthMm, heightMm: Math.max(2, widthMm * ratio) };
|
||||
}
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
// (pdfjs-dist, reine Browser-/Webview-API — kein Tauri-fs nötig) und als
|
||||
// Data-URL zurückgegeben. Kein eigener PDF-Rendering-Pfad im Plan/Layout —
|
||||
// eine importierte PDF-Seite ist danach ein ganz normales Bild-Element
|
||||
// (Drawing2D `{shape:"image"}` bzw. LayoutAnnotation `kind:"image"`).
|
||||
// (Drawing2D `{shape:"image"}`, auch auf einem Layout-Blatt).
|
||||
|
||||
import * as pdfjsLib from "pdfjs-dist";
|
||||
import type { LoadedImageAsset } from "./imageAsset";
|
||||
|
||||
@@ -21,7 +21,7 @@ import { documentFor, sharedDocument } from "../core/document";
|
||||
import type { LoadFileResult } from "../core/document";
|
||||
|
||||
/** Aktuelle Version des Dateiformats (muss `PROJECT_FORMAT_VERSION` im Kern entsprechen — Test). */
|
||||
export const PROJECT_FORMAT_VERSION = 2;
|
||||
export const PROJECT_FORMAT_VERSION = 3;
|
||||
|
||||
export type ParseProjectResult = LoadFileResult;
|
||||
|
||||
|
||||
@@ -11,15 +11,14 @@ import type {
|
||||
ViewSnapshot,
|
||||
} from "./types";
|
||||
import {
|
||||
addAnnotation,
|
||||
addViewport,
|
||||
buildLayoutTree,
|
||||
buildMasterTree,
|
||||
collectFolderLayouts,
|
||||
createAnnotation,
|
||||
createLayout,
|
||||
createLayoutFolder,
|
||||
createMasterLayout,
|
||||
createSheetLevel,
|
||||
createViewport,
|
||||
deleteFolder,
|
||||
deleteMasterFolder,
|
||||
@@ -28,15 +27,18 @@ import {
|
||||
findSnapshot,
|
||||
folderPdfPages,
|
||||
isDescendant,
|
||||
isSheetLevel,
|
||||
moveFolderToFolder,
|
||||
moveLayoutToFolder,
|
||||
PAPER_FORMATS,
|
||||
patchAnnotation,
|
||||
patchViewport,
|
||||
removeAnnotation,
|
||||
removeViewport,
|
||||
resolveTitleBlock,
|
||||
resolveViewportScale,
|
||||
SHEET_SCALE_DENOMINATOR,
|
||||
sheetLevelOf,
|
||||
sheetMmToModel,
|
||||
sheetModelToMm,
|
||||
sheetSizeMm,
|
||||
visibleCodesFromSnapshot,
|
||||
} from "./layoutModel";
|
||||
@@ -139,91 +141,29 @@ describe("Viewport-CRUD (immutabel)", () => {
|
||||
});
|
||||
});
|
||||
|
||||
// ── Annotationen (Linie/Rechteck/Text) ───────────────────────────────────────
|
||||
// ── Blatt-Ebene (2D-Zeichnung auf dem Blatt) ────────────────────────────────
|
||||
|
||||
describe("createAnnotation — Defaults je Art", () => {
|
||||
it("line: Default-Geometrie ohne Farbe/Strichstärke", () => {
|
||||
const a = createAnnotation("a1", "line");
|
||||
expect(a).toEqual({ id: "a1", kind: "line", x1Mm: 20, y1Mm: 20, x2Mm: 80, y2Mm: 20 });
|
||||
});
|
||||
it("line: init überschreibt einzelne Felder + optionale Farbe/Strichstärke", () => {
|
||||
const a = createAnnotation("a1", "line", { x1Mm: 5, color: "#f00", weightMm: 0.5 });
|
||||
expect(a).toMatchObject({ x1Mm: 5, y1Mm: 20, color: "#f00", weightMm: 0.5 });
|
||||
});
|
||||
it("rect: Default-Grösse", () => {
|
||||
const a = createAnnotation("a2", "rect");
|
||||
expect(a).toEqual({ id: "a2", kind: "rect", xMm: 20, yMm: 20, widthMm: 40, heightMm: 30 });
|
||||
});
|
||||
it("text: Default-Zeilenhöhe 3.5mm, leerer Text", () => {
|
||||
const a = createAnnotation("a3", "text");
|
||||
expect(a).toEqual({ id: "a3", kind: "text", xMm: 20, yMm: 20, text: "", heightMm: 3.5 });
|
||||
});
|
||||
it("text: init setzt Inhalt + Höhe", () => {
|
||||
const a = createAnnotation("a3", "text", { text: "EG", heightMm: 5 });
|
||||
expect(a).toMatchObject({ text: "EG", heightMm: 5 });
|
||||
});
|
||||
it("text: init mit doc/widthMm (Rich-Text-Frame) wird übernommen", () => {
|
||||
const doc = { version: 1 as const, paragraphs: [{ runs: [{ text: "Hi", marks: {} }] }] };
|
||||
const a = createAnnotation("a3", "text", { doc, widthMm: 50 });
|
||||
expect(a).toMatchObject({ doc, widthMm: 50 });
|
||||
});
|
||||
it("image: Default-Grösse, leere Quelle", () => {
|
||||
const a = createAnnotation("a4", "image");
|
||||
expect(a).toEqual({ id: "a4", kind: "image", xMm: 20, yMm: 20, widthMm: 60, heightMm: 40, src: "" });
|
||||
});
|
||||
it("image: init setzt Quelle + Grösse + Deckkraft", () => {
|
||||
const a = createAnnotation("a4", "image", { src: "data:image/png;base64,x", widthMm: 30, heightMm: 20, opacity: 0.5 });
|
||||
expect(a).toMatchObject({ src: "data:image/png;base64,x", widthMm: 30, heightMm: 20, opacity: 0.5 });
|
||||
});
|
||||
});
|
||||
describe("Blatt-Ebene", () => {
|
||||
const lay = createLayout("l1", "Blatt 1", "a3", "landscape");
|
||||
const sheet = createSheetLevel("sheet-l1", lay);
|
||||
|
||||
describe("Annotations-CRUD (immutabel)", () => {
|
||||
const base = createLayout("l1", "L", "a4", "portrait");
|
||||
|
||||
it("addAnnotation verändert das Original nicht", () => {
|
||||
const after = addAnnotation(base, createAnnotation("a1", "line"));
|
||||
expect(base.annotations).toBeUndefined();
|
||||
expect(after.annotations).toHaveLength(1);
|
||||
expect(after).not.toBe(base);
|
||||
it("ist eine Zeichnungsebene mit Layout-Bezug", () => {
|
||||
expect(sheet).toEqual({ id: "sheet-l1", name: "Blatt 1", kind: "drawing", visible: true, locked: false, layoutId: "l1" });
|
||||
expect(isSheetLevel(sheet)).toBe(true);
|
||||
expect(isSheetLevel({ layoutId: undefined })).toBe(false);
|
||||
expect(isSheetLevel(undefined)).toBe(false);
|
||||
});
|
||||
|
||||
it("addAnnotation baut auf einer fehlenden `annotations`-Liste auf (Alt-Layout)", () => {
|
||||
const legacy: Layout = { id: "old", name: "Alt", paper: "a4", orientation: "portrait", viewports: [] };
|
||||
const after = addAnnotation(legacy, createAnnotation("a1", "rect"));
|
||||
expect(after.annotations).toHaveLength(1);
|
||||
expect(legacy.annotations).toBeUndefined();
|
||||
it("wird über das Layout gefunden", () => {
|
||||
const p = { drawingLevels: [{ id: "eg", name: "EG", kind: "floor", visible: true, locked: false }, sheet] } as unknown as Project;
|
||||
expect(sheetLevelOf(p, "l1")).toBe(sheet);
|
||||
expect(sheetLevelOf(p, "nope")).toBeUndefined();
|
||||
});
|
||||
|
||||
it("removeAnnotation entfernt per Id", () => {
|
||||
let l = addAnnotation(base, createAnnotation("a1", "line"));
|
||||
l = addAnnotation(l, createAnnotation("a2", "rect"));
|
||||
const removed = removeAnnotation(l, "a1");
|
||||
expect(removed.annotations!.map((a) => a.id)).toEqual(["a2"]);
|
||||
});
|
||||
|
||||
it("removeAnnotation auf Alt-Layout ohne `annotations` bleibt heil (No-op)", () => {
|
||||
const legacy: Layout = { id: "old", name: "Alt", paper: "a4", orientation: "portrait", viewports: [] };
|
||||
const r = removeAnnotation(legacy, "nope");
|
||||
expect(r.annotations).toEqual([]);
|
||||
});
|
||||
|
||||
it("patchAnnotation ändert nur das Ziel, immutabel", () => {
|
||||
const l = addAnnotation(base, createAnnotation("a1", "line", { color: "#111" }));
|
||||
const patched = patchAnnotation(l, "a1", { x1Mm: 42, color: "#0f0" });
|
||||
expect(patched.annotations![0]).toMatchObject({ x1Mm: 42, color: "#0f0" });
|
||||
expect((l.annotations![0] as { color?: string }).color).toBe("#111");
|
||||
});
|
||||
|
||||
it("patchAnnotation: unbekannte Id → No-op (gleiche Werte, neue Liste)", () => {
|
||||
const l = addAnnotation(base, createAnnotation("a1", "line"));
|
||||
const noop = patchAnnotation(l, "nope", { x1Mm: 1 });
|
||||
expect((noop.annotations![0] as { x1Mm: number }).x1Mm).toBe(20);
|
||||
});
|
||||
|
||||
it("patchAnnotation auf einer Text-Annotation ändert den Inhalt", () => {
|
||||
const l = addAnnotation(base, createAnnotation("t1", "text", { text: "EG" }));
|
||||
const patched = patchAnnotation(l, "t1", { text: "1. OG" });
|
||||
expect(patched.annotations![0]).toMatchObject({ text: "1. OG" });
|
||||
it("Papier-mm ↔ Meter (1:1, y nach unten = −y), hin und zurück", () => {
|
||||
expect(sheetMmToModel(420, 297)).toEqual({ x: 0.42, y: -0.297 });
|
||||
expect(sheetModelToMm({ x: 0.42, y: -0.297 })).toEqual({ xMm: 420, yMm: 297 });
|
||||
expect(SHEET_SCALE_DENOMINATOR).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
+28
-91
@@ -7,22 +7,22 @@
|
||||
//
|
||||
// Rechnung im Rust-Kern ([K4] S3, `src-tauri/core/src/layout_model.rs`, `folder_tree.rs`): Blattgrössen,
|
||||
// Ordner-Bäume (Aufbau, Blätter eines Ordners, Löschen, Nachfahren-Test), Seitenplanung des Ordner-PDF und
|
||||
// Titelblock. Hier bleiben Fabriken, einfache Listen-Änderungen (Viewports, Annotationen, Blatt verschieben)
|
||||
// Titelblock. Hier bleiben Fabriken, einfache Listen-Änderungen (Viewports, Blatt verschieben), die Blatt-Ebene
|
||||
// und Nachschlagen; die Baum-Fassaden setzen die Knoten aus den Indizes des Kerns mit den Original-Objekten
|
||||
// zusammen (Objekt-Identität bleibt).
|
||||
//
|
||||
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import type {
|
||||
DrawingLevel,
|
||||
Layout,
|
||||
LayoutAnnotation,
|
||||
LayoutAnnotationPatch,
|
||||
LayoutFolder,
|
||||
LayoutOrientation,
|
||||
LayoutPaperFormat,
|
||||
LayoutViewport,
|
||||
MasterLayout,
|
||||
Project,
|
||||
Vec2,
|
||||
ViewSnapshot,
|
||||
} from "./types";
|
||||
import { core } from "../engine/coreWasm";
|
||||
@@ -413,103 +413,40 @@ export function patchViewport(
|
||||
};
|
||||
}
|
||||
|
||||
// ── Fabrik + immutable CRUD (Annotationen auf einem Layout) ─────────────────
|
||||
// Analog zu Viewports: Linie/Rechteck/Text als vom Viewport-Baum unabhängige
|
||||
// Markup-Schicht in Papier-mm. `annotations ?? []` ist überall die Basis, damit
|
||||
// Alt-Layouts (ohne das Feld) unverändert bleiben (additiv).
|
||||
// ── Blatt-Ebene (2D-Zeichnung auf dem Blatt) ─────────────────────────────────
|
||||
// Was auf einem Blatt gezeichnet wird, sind gewöhnliche `drawings2d` auf der Blatt-Ebene des Layouts
|
||||
// (`DrawingLevel.layoutId`, Art "drawing"): dieselben Werkzeuge, Fang, Griffe, Auswahl und dasselbe
|
||||
// Rendering wie im Grundriss. Koordinaten = Papier 1:1 in Metern, Ursprung oben links, Papier-y nach
|
||||
// unten = −y (s. {@link sheetMmToModel}).
|
||||
|
||||
/**
|
||||
* Neue Annotation mit Default-Geometrie je Art (Linie/Rechteck: sichtbare
|
||||
* Mindestgrösse; Text: 3.5 mm Zeilenhöhe, wie im Attribute-Editor üblich).
|
||||
* `init` überschreibt einzelne Felder — der Aufrufer (Editor) übergibt i. d. R.
|
||||
* die vollständige, aus dem Zeichnen gewonnene Geometrie.
|
||||
*/
|
||||
export function createAnnotation(
|
||||
id: string,
|
||||
kind: LayoutAnnotation["kind"],
|
||||
init: LayoutAnnotationPatch = {},
|
||||
): LayoutAnnotation {
|
||||
const colorPatch = init.color !== undefined ? { color: init.color } : {};
|
||||
if (kind === "line") {
|
||||
return {
|
||||
id,
|
||||
kind: "line",
|
||||
x1Mm: init.x1Mm ?? 20,
|
||||
y1Mm: init.y1Mm ?? 20,
|
||||
x2Mm: init.x2Mm ?? 80,
|
||||
y2Mm: init.y2Mm ?? 20,
|
||||
...colorPatch,
|
||||
...(init.weightMm !== undefined ? { weightMm: init.weightMm } : {}),
|
||||
};
|
||||
}
|
||||
if (kind === "rect") {
|
||||
return {
|
||||
id,
|
||||
kind: "rect",
|
||||
xMm: init.xMm ?? 20,
|
||||
yMm: init.yMm ?? 20,
|
||||
widthMm: init.widthMm ?? 40,
|
||||
heightMm: init.heightMm ?? 30,
|
||||
...colorPatch,
|
||||
...(init.weightMm !== undefined ? { weightMm: init.weightMm } : {}),
|
||||
};
|
||||
}
|
||||
if (kind === "image") {
|
||||
return {
|
||||
id,
|
||||
kind: "image",
|
||||
xMm: init.xMm ?? 20,
|
||||
yMm: init.yMm ?? 20,
|
||||
widthMm: init.widthMm ?? 60,
|
||||
heightMm: init.heightMm ?? 40,
|
||||
src: init.src ?? "",
|
||||
...(init.opacity !== undefined ? { opacity: init.opacity } : {}),
|
||||
};
|
||||
}
|
||||
return {
|
||||
id,
|
||||
kind: "text",
|
||||
xMm: init.xMm ?? 20,
|
||||
yMm: init.yMm ?? 20,
|
||||
text: init.text ?? "",
|
||||
heightMm: init.heightMm ?? 3.5,
|
||||
...colorPatch,
|
||||
...(init.doc !== undefined ? { doc: init.doc } : {}),
|
||||
...(init.widthMm !== undefined ? { widthMm: init.widthMm } : {}),
|
||||
};
|
||||
/** Ist die Ebene die Blatt-Ebene eines Layouts (nicht im Navigator, nur bei offenem Blatt sichtbar)? */
|
||||
export function isSheetLevel(level: Pick<DrawingLevel, "layoutId"> | undefined | null): boolean {
|
||||
return !!level?.layoutId;
|
||||
}
|
||||
|
||||
/** Fügt eine Annotation an (immutabel). */
|
||||
export function addAnnotation(layout: Layout, annotation: LayoutAnnotation): Layout {
|
||||
return { ...layout, annotations: [...(layout.annotations ?? []), annotation] };
|
||||
/** Die Blatt-Ebene des Layouts `layoutId`, falls vorhanden. */
|
||||
export function sheetLevelOf(project: Project, layoutId: string): DrawingLevel | undefined {
|
||||
return project.drawingLevels.find((l) => l.layoutId === layoutId);
|
||||
}
|
||||
|
||||
/** Entfernt eine Annotation per Id (immutabel). */
|
||||
export function removeAnnotation(layout: Layout, annotationId: string): Layout {
|
||||
return {
|
||||
...layout,
|
||||
annotations: (layout.annotations ?? []).filter((a) => a.id !== annotationId),
|
||||
};
|
||||
/** Neue (leere) Blatt-Ebene für `layout`. */
|
||||
export function createSheetLevel(id: string, layout: Pick<Layout, "id" | "name">): DrawingLevel {
|
||||
return { id, name: layout.name, kind: "drawing", visible: true, locked: false, layoutId: layout.id };
|
||||
}
|
||||
|
||||
/**
|
||||
* Ändert Felder einer Annotation (immutabel). No-op, wenn die Id fehlt. Der
|
||||
* Patch ist bewusst art-unabhängig ({@link LayoutAnnotationPatch}) — es werden
|
||||
* nur die tatsächlich übergebenen Felder gemergt.
|
||||
*/
|
||||
export function patchAnnotation(
|
||||
layout: Layout,
|
||||
annotationId: string,
|
||||
patch: LayoutAnnotationPatch,
|
||||
): Layout {
|
||||
return {
|
||||
...layout,
|
||||
annotations: (layout.annotations ?? []).map((a) =>
|
||||
a.id === annotationId ? ({ ...a, ...patch } as LayoutAnnotation) : a,
|
||||
),
|
||||
};
|
||||
/** Papier-mm (x nach rechts, y nach unten) → Blatt-Ebene (Meter, y nach oben). */
|
||||
export function sheetMmToModel(xMm: number, yMm: number): Vec2 {
|
||||
return { x: xMm / 1000, y: -yMm / 1000 };
|
||||
}
|
||||
|
||||
/** Blatt-Ebene (Meter) → Papier-mm. */
|
||||
export function sheetModelToMm(p: Vec2): { xMm: number; yMm: number } {
|
||||
return { xMm: p.x * 1000, yMm: -p.y * 1000 };
|
||||
}
|
||||
|
||||
/** Massstab der Blatt-Ebene: Papier 1:1. */
|
||||
export const SHEET_SCALE_DENOMINATOR = 1;
|
||||
|
||||
// ── Auflösungen ──────────────────────────────────────────────────────────────
|
||||
|
||||
/** Findet einen Ausschnitt (View-Snapshot) im Projekt. */
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// Genutzt von der Modell-Rundreise und dem Robustheitstest des Kerns.
|
||||
|
||||
import { sampleProject } from "./sampleProject";
|
||||
import type { Drawing2DGeom, LayoutAnnotation, ParametricRule, Project, RichTextDoc } from "./types";
|
||||
import type { Drawing2DGeom, ParametricRule, Project, RichTextDoc } from "./types";
|
||||
|
||||
export const plain = (p: unknown): unknown => JSON.parse(JSON.stringify(p));
|
||||
|
||||
@@ -47,19 +47,14 @@ const rules: ParametricRule[] = [
|
||||
{ type: "sequence", rules: [{ type: "reference-line", referenceLine: "right", target: "exterior" }], stopOnMatch: true },
|
||||
];
|
||||
|
||||
const annotations: LayoutAnnotation[] = [
|
||||
{ kind: "line", id: "a1", x1Mm: 0, y1Mm: 0, x2Mm: 10, y2Mm: 10, color: "#000000", weightMm: 0.25 },
|
||||
{ kind: "rect", id: "a2", xMm: 1, yMm: 2, widthMm: 30, heightMm: 20 },
|
||||
{ kind: "text", id: "a3", xMm: 1, yMm: 2, text: "Titel", heightMm: 5, doc, widthMm: 40 },
|
||||
{ kind: "image", id: "a4", xMm: 1, yMm: 2, widthMm: 30, heightMm: 20, src: "data:image/png;base64,AAAA", opacity: 1 },
|
||||
];
|
||||
|
||||
/** Beispielprojekt, ergänzt um alle Element-Arten, die es selbst nicht enthält. */
|
||||
export function richProject(): Project {
|
||||
const lvl = sampleProject.drawingLevels[0].id;
|
||||
return {
|
||||
...sampleProject,
|
||||
formatVersion: 2,
|
||||
formatVersion: 3,
|
||||
// Blatt-Ebene des Layouts „lay1" (2D-Zeichnung auf dem Blatt).
|
||||
drawingLevels: [...sampleProject.drawingLevels, { id: "sheet-lay1", name: "Blatt 1", kind: "drawing", visible: true, locked: false, layoutId: "lay1" }],
|
||||
textStyles: [{ id: "ts1", label: "Titel", marks: { bold: true, font: "Helvetica", sizePt: 14 } }],
|
||||
blockDefs: [{ id: "blk1", name: "Nordpfeil", geom2d: geoms.slice(0, 4) }],
|
||||
pens: [{ id: "pen1", name: "Kontur" }],
|
||||
@@ -111,7 +106,7 @@ export function richProject(): Project {
|
||||
layerVisibility: { "10": true, "20": false }, drawingVisibility: { [lvl]: true }, enabledOverrideRuleIds: ["or1"], cameraCenter: { x: 1, y: 2 }, cameraPxPerMeter: 40,
|
||||
}],
|
||||
viewSnapshotFolders: [{ id: "vf1", name: "Pläne" }, { id: "vf2", name: "Unter", parentId: "vf1" }],
|
||||
layouts: [{ id: "lay1", name: "Blatt 1", paper: "a3", orientation: "landscape", planNumber: "A-12", masterId: "m1", folderId: "lf1", viewports: [{ id: "vp1", snapshotId: "vs1", xMm: 10, yMm: 10, widthMm: 200, heightMm: 150, scaleDenominator: 50 }], annotations }],
|
||||
layouts: [{ id: "lay1", name: "Blatt 1", paper: "a3", orientation: "landscape", planNumber: "A-12", masterId: "m1", folderId: "lf1", viewports: [{ id: "vp1", snapshotId: "vs1", xMm: 10, yMm: 10, widthMm: 200, heightMm: 150, scaleDenominator: 50 }] }],
|
||||
masterLayouts: [{ id: "m1", name: "Master", paper: "a3", orientation: "landscape", titleBlock: { projectName: "P", sheetName: "S", scale: "1:100", date: "28.10.", author: "K" }, border: true }],
|
||||
layoutFolders: [{ id: "lf1", name: "Pläne", kind: "layout" }],
|
||||
referenceElevationMasl: 432.1,
|
||||
|
||||
@@ -927,6 +927,14 @@ export type DrawingLevel = {
|
||||
* Fehlt ⇒ an; `false` ⇒ aus.
|
||||
*/
|
||||
levelMarks?: boolean;
|
||||
/**
|
||||
* Blatt-Ebene (nur kind "drawing"): gehört zum Layout mit dieser ID und trägt dessen
|
||||
* 2D-Zeichnung (Linien, Texte, Bilder …) als gewöhnliche `drawings2d`. Koordinaten = Papier
|
||||
* im Massstab 1:1 in Metern, Ursprung oben links am Blatt, Papier-y nach unten = −y
|
||||
* (Papier-mm (x, y) ↔ Modell (x/1000, −y/1000)). Nicht im Navigator; nur sichtbar, wenn das
|
||||
* Blatt offen ist. Fehlt ⇒ gewöhnliche Ebene.
|
||||
*/
|
||||
layoutId?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -1275,65 +1283,13 @@ export type Layout = {
|
||||
customWidthMm?: number;
|
||||
/** Freie Blatthöhe in mm (siehe {@link Layout.customWidthMm}). */
|
||||
customHeightMm?: number;
|
||||
viewports: Array<LayoutViewport>;
|
||||
/**
|
||||
* 2D-Markups direkt auf dem Blatt (Linie/Rechteck/Text), siehe
|
||||
* {@link LayoutAnnotation}. Additiv — Alt-Layouts ohne dieses Feld laden
|
||||
* unverändert (Editor/CRUD behandeln ein fehlendes Array wie ein leeres).
|
||||
* Die 2D-Zeichnung auf dem Blatt liegt auf der Blatt-Ebene ({@link DrawingLevel.layoutId}),
|
||||
* nicht im Layout (bis Format 2: `annotations`, s. `project_format::migrate_layout_annotations`).
|
||||
*/
|
||||
annotations?: Array<LayoutAnnotation>;
|
||||
viewports: Array<LayoutViewport>;
|
||||
};
|
||||
|
||||
/** Layout-Beschriftung (Tag `kind`). */
|
||||
export type LayoutAnnotation =
|
||||
| {
|
||||
kind: "line";
|
||||
id: string;
|
||||
x1Mm: number;
|
||||
y1Mm: number;
|
||||
x2Mm: number;
|
||||
y2Mm: number;
|
||||
color?: string;
|
||||
weightMm?: number;
|
||||
}
|
||||
| {
|
||||
kind: "rect";
|
||||
id: string;
|
||||
xMm: number;
|
||||
yMm: number;
|
||||
widthMm: number;
|
||||
heightMm: number;
|
||||
color?: string;
|
||||
weightMm?: number;
|
||||
}
|
||||
| {
|
||||
kind: "text";
|
||||
id: string;
|
||||
xMm: number;
|
||||
yMm: number;
|
||||
text: string;
|
||||
heightMm: number;
|
||||
color?: string;
|
||||
/**
|
||||
* Reiches Textfeld (mehrere Absätze, gemischte Formatierung) — Vorrang vor
|
||||
* `text`, s. gleichnamiges Feld bei `Drawing2DGeom["text"]`.
|
||||
*/
|
||||
doc?: RichTextDoc;
|
||||
/** Optionale Rahmenbreite (mm) — bricht `doc` wortweise um; fehlt sie: einzeilig. */
|
||||
widthMm?: number;
|
||||
}
|
||||
| {
|
||||
kind: "image";
|
||||
id: string;
|
||||
xMm: number;
|
||||
yMm: number;
|
||||
widthMm: number;
|
||||
heightMm: number;
|
||||
/** Bildquelle als Data-URL (PNG/JPEG) — eingebettet, keine externe Datei. */
|
||||
src: string;
|
||||
opacity?: number;
|
||||
};
|
||||
|
||||
/**
|
||||
* Ein Ordner im Layouts-Baum (DOSSIER A3). Layouts verweisen per `folderId` auf
|
||||
* ihren Ordner; `parentId` erlaubt Verschachtelung (Ordner in Ordner). Fehlt
|
||||
|
||||
@@ -26,7 +26,6 @@ import type {
|
||||
LineStyle,
|
||||
Opening,
|
||||
Project,
|
||||
RichTextDoc,
|
||||
Roof,
|
||||
SashDef,
|
||||
Vec2,
|
||||
@@ -84,29 +83,6 @@ export interface ImportedText {
|
||||
layer?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flaches Patch-Objekt für {@link LayoutAnnotation} — alle Felder ALLER Arten
|
||||
* optional (statt eines pro Art unterscheidenden Unions), damit CRUD/Handler
|
||||
* unabhängig von der konkreten `kind` bleiben (der Aufrufer setzt ohnehin nur
|
||||
* die zur gewählten Annotation passenden Felder).
|
||||
*/
|
||||
export type LayoutAnnotationPatch = Partial<{
|
||||
x1Mm: number;
|
||||
y1Mm: number;
|
||||
x2Mm: number;
|
||||
y2Mm: number;
|
||||
xMm: number;
|
||||
yMm: number;
|
||||
widthMm: number;
|
||||
heightMm: number;
|
||||
text: string;
|
||||
color: string;
|
||||
weightMm: number;
|
||||
doc: RichTextDoc;
|
||||
src: string;
|
||||
opacity: number;
|
||||
}>;
|
||||
|
||||
// ── Helfer ───────────────────────────────────────────────────────────────
|
||||
|
||||
export const getWallType = (project: Project, wall: Wall): WallType => {
|
||||
|
||||
@@ -124,21 +124,14 @@ export function AttributesPanel() {
|
||||
}
|
||||
|
||||
const isDrawing = sel.kind === "drawing2d";
|
||||
// Layout-Annotation (Linie/Rechteck/Text/Bild auf einem Blatt) — kein
|
||||
// Projekt-Bauteil, daher ohne Ebene/Bauteil-Vererbung: Farbe/Strichstärke
|
||||
// sind IMMER ein eigener Wert (kein 3-Quellen-Dropdown, keine Füllung/
|
||||
// Schraffur/Masse — s. Ausblendungen weiter unten).
|
||||
const isAnnotation = sel.kind === "layoutAnnotation";
|
||||
// Strichstärke: Wand/Decke/Stütze/Drawing2D tragen einen eigenen Override
|
||||
// (`strokeWeight`/`weightMm`) + Quellen-Dropdown; andere Elementarten erben
|
||||
// stets aus der Kategorie (kein Setter im Kontrakt → nicht editierbar). Bei
|
||||
// Annotationen nur Linie/Rechteck (Text/Bild kennen keine Strichstärke).
|
||||
// stets aus der Kategorie (kein Setter im Kontrakt → nicht editierbar).
|
||||
const weightEditable =
|
||||
sel.kind === "wall" ||
|
||||
sel.kind === "ceiling" ||
|
||||
sel.kind === "column" ||
|
||||
isDrawing ||
|
||||
(isAnnotation && (sel.annotKind === "line" || sel.annotKind === "rect"));
|
||||
isDrawing;
|
||||
// Schraffur: Wand/Decke/Stütze (Schnitt-/Ansichts-Schraffur) oder
|
||||
// geschlossene 2D-Form.
|
||||
const fillEditable =
|
||||
@@ -312,29 +305,7 @@ export function AttributesPanel() {
|
||||
GESPERRT und zeigt die Strichstärke DES STIFTS (ein Stift trägt
|
||||
beides zusammen, s. model/penSets.ts) statt des sonst aufgelösten
|
||||
`weightMm`. */}
|
||||
{isAnnotation ? (
|
||||
weightEditable && (
|
||||
<>
|
||||
<span className="attr-key">{t("attr.weight")}</span>
|
||||
<span className="attr-val">
|
||||
<input
|
||||
className="attr-num"
|
||||
style={{ width: 72 }}
|
||||
type="number"
|
||||
step={0.01}
|
||||
min={0}
|
||||
list="attr-pen-weights"
|
||||
value={sel.weightMm}
|
||||
onChange={(e) => {
|
||||
const v = Number(e.target.value);
|
||||
if (Number.isFinite(v)) host.onSetSelectionWeight(v);
|
||||
}}
|
||||
/>
|
||||
</span>
|
||||
</>
|
||||
)
|
||||
) : (
|
||||
sourceRow(
|
||||
{sourceRow(
|
||||
"attr.weight",
|
||||
weightEditable && !sel.colorPenId,
|
||||
weightUi,
|
||||
@@ -360,8 +331,7 @@ export function AttributesPanel() {
|
||||
))}
|
||||
</datalist>
|
||||
</>,
|
||||
)
|
||||
)}
|
||||
)}
|
||||
|
||||
{/* Deckkraft (0..1) — bei BILDERN deren eigene Bild-Deckkraft, bei
|
||||
allen übrigen 2D-Formen die Objekt-Transparenz (wirkt auf Strich
|
||||
@@ -429,7 +399,7 @@ export function AttributesPanel() {
|
||||
|
||||
{/* Linienstil — nur Drawing2D trägt ihn (Wand/Decke/Annotation etc.
|
||||
read-only), Rest wie gehabt. */}
|
||||
{!isAnnotation && (
|
||||
{(
|
||||
<>
|
||||
<span className="attr-key">{t("attr.lineStyle")}</span>
|
||||
<span className="attr-val">
|
||||
@@ -608,7 +578,7 @@ export function AttributesPanel() {
|
||||
Nach Bauteil (erbt vom Component-Manager, Default) / eigener Wert.
|
||||
Eine Layout-Annotation kennt keine Füllung (nur Umriss) — Sektion
|
||||
entfällt komplett statt drei bedeutungslose Dropdowns zu zeigen. */}
|
||||
{!isAnnotation && (
|
||||
{(
|
||||
<>
|
||||
<div className="attr-section-label">{t("attr.fill")}</div>
|
||||
|
||||
@@ -797,7 +767,7 @@ export function AttributesPanel() {
|
||||
„Ausdehnung X/Y" beschriften (Nutzer-Report: Fenster zeigte „Höhe
|
||||
0.34 m" = Wanddicke). Öffnungen tragen Breite/Höhe im eigenen
|
||||
Abschnitt, dort entfällt die bbox ganz. */}
|
||||
{!isAnnotation && !sel.opening && (
|
||||
{!sel.opening && (
|
||||
<>
|
||||
<div className="attr-section-label">{t("attr.size")}</div>
|
||||
<span className="attr-key">{t(isModelElement ? "attr.extentX" : "attr.width")}</span>
|
||||
|
||||
@@ -77,7 +77,8 @@ export function DrawingLevelsPanel() {
|
||||
};
|
||||
|
||||
// Oberstes Geschoss zuoberst (wie DOSSIER): Anzeige umkehren.
|
||||
const levelsTopDown = [...project.drawingLevels].reverse();
|
||||
// Blatt-Ebenen (Layout-Zeichnung) gehören zum Blatt, nicht in den Navigator.
|
||||
const levelsTopDown = project.drawingLevels.filter((z) => !z.layoutId).reverse();
|
||||
|
||||
// Klick aufs Auge in „Alle anzeigen"/„Nur aktive" schaltet automatisch auf
|
||||
// „Ausgewählte" (DOSSIER-Regel), damit das Sichtbarkeits-Flag sofort greift.
|
||||
|
||||
@@ -168,16 +168,7 @@ export function ObjectInfoPanel() {
|
||||
|
||||
<div className="objinfo-sep" />
|
||||
|
||||
{/* Bezugspunkt/X-Y/Maße sind MODELL-Meter (Grundriss) — für eine Layout-
|
||||
Annotation (Papier-Millimeter, eigenes Koordinatensystem) gibt es
|
||||
keinen sinnvollen Bezugspunkt hier; Position/Grösse editiert man
|
||||
direkt am Rahmen auf dem Blatt (Greifpunkte + das dortige HUD in
|
||||
mm — `layout-sheet-hud` in LayoutSheet.tsx). Sonst zeigte dieses
|
||||
Panel für sie fest 0/0 (Selection.bbox ist für sie ein Platzhalter,
|
||||
s. App.tsx) — verwirrend statt nur „nicht anwendbar". */}
|
||||
{sel.kind === "layoutAnnotation" ? (
|
||||
<div className="objinfo-empty">{t("objinfo.layoutAnnotationHint")}</div>
|
||||
) : (
|
||||
{(
|
||||
<>
|
||||
{/* Bezugspunkt-Würfel (3×3, immer quadratisch) links, X/Y/Z als Spalte
|
||||
rechts daneben (Nutzer-Wunsch). */}
|
||||
|
||||
@@ -241,6 +241,9 @@ export function generatePlan(
|
||||
compactUnderlay = false,
|
||||
): Plan {
|
||||
const compact = compactUnderlay && !mono && !forPrint;
|
||||
// Blatt-Ebene eines Layouts (Papier 1:1): ohne projektglobale Zutaten (Kontext, Luftbilder,
|
||||
// Schnittlinien, Schatten, Baurecht) — die gehören zum Modell, nicht aufs Papier.
|
||||
if (project.drawingLevels.some((l) => l.id === floorId && l.layoutId)) includeGlobal = false;
|
||||
// Den ganzen Grundriss rechnet der Kern auf dem Dokument ([K3d]/[K4], `plan/{domains,walls,stairs,
|
||||
// drawings,extras}.rs`): Schattenstudie und Baurecht zuunterst, Decken, Dächer, Räume, Wände mit
|
||||
// Öffnungen, Treppen, Stützen, 2D-Zeichnungen, Extrusions-Umrisse, Kontext und Schnittführung,
|
||||
|
||||
@@ -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;
|
||||
/**
|
||||
|
||||
@@ -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));
|
||||
});
|
||||
});
|
||||
@@ -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));
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
+2
-127
@@ -7417,134 +7417,9 @@ body {
|
||||
background: var(--sheet);
|
||||
touch-action: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.layout-sheet-paper {
|
||||
position: absolute;
|
||||
background: #ffffff;
|
||||
border: 1px solid rgba(26, 26, 24, 0.18);
|
||||
box-shadow: 0 4px 22px rgba(26, 26, 24, 0.22);
|
||||
}
|
||||
|
||||
.layout-sheet-vp {
|
||||
position: absolute;
|
||||
overflow: hidden;
|
||||
background: #ffffff;
|
||||
outline: 1px solid rgba(0, 0, 0, 0.35);
|
||||
}
|
||||
.layout-sheet-vp.selected {
|
||||
outline: 1.5px solid #3b82f6;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.layout-sheet-vp-missing {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
/* Darin die Plan-Ansicht der Blatt-Ebene (füllt die Fläche). */
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 10px;
|
||||
color: #b00;
|
||||
text-align: center;
|
||||
padding: 4px;
|
||||
}
|
||||
|
||||
/* Resize-Griffe (8 Stück) — kleine blaue Quadrate am Rand des gewählten VP. */
|
||||
.layout-sheet-grip {
|
||||
position: absolute;
|
||||
width: 9px;
|
||||
height: 9px;
|
||||
margin: -5px 0 0 -5px; /* auf den Ankerpunkt zentrieren */
|
||||
background: #ffffff;
|
||||
border: 1.5px solid #3b82f6;
|
||||
border-radius: 2px;
|
||||
z-index: 4;
|
||||
}
|
||||
|
||||
/* Ghost-Rechteck beim Aufziehen einer neuen Platzierung. */
|
||||
.layout-sheet-ghost {
|
||||
position: absolute;
|
||||
border: 1.5px dashed #3b82f6;
|
||||
background: rgba(59, 130, 246, 0.12);
|
||||
z-index: 4;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* Transparenter Vollflächen-Fänger hinter dem Inline-Text-Editor — ein Klick
|
||||
daneben schliesst ihn (jede Änderung ist bereits live gespeichert). */
|
||||
.layout-sheet-inline-backdrop {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
z-index: 6;
|
||||
}
|
||||
|
||||
/* Inline-Text-Editor DIREKT auf dem Blatt (kein schwebendes Fenster) — weisser
|
||||
Rahmen wie Papier, blauer Rand während der Bearbeitung. WYSIWYG: Schrift-
|
||||
grösse UND Feldhöhe der Textfläche folgen dem echten Blatt-Zoom über
|
||||
`--rt-font-size`/`--rt-min-height` (inline von LayoutSheet.tsx gesetzt) —
|
||||
NUR die Textfläche, NICHT die Toolbar (dasselbe Muster wie
|
||||
.planview-inline-text, s. dort; ersetzt das vorige `transform:scale()` auf
|
||||
die GANZE Box, das die Toolbar beim Reinzoomen mit aufblies). */
|
||||
.layout-sheet-inline-text {
|
||||
position: absolute;
|
||||
z-index: 7;
|
||||
background: #ffffff;
|
||||
outline: 1.5px solid #3b82f6;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
|
||||
}
|
||||
.layout-sheet-inline-text .rt-editor {
|
||||
min-height: inherit;
|
||||
/* Toolbar verlässt den Fluss (s. .rt-toolbar unten) — nur noch die
|
||||
Textfläche bleibt im normalen Fluss, damit ihre Oberkante GENAU an der
|
||||
positionierten Box-Oberkante liegt (= Zeilenanfang der Annotation).
|
||||
`overflow:visible` (Basisregel setzt `hidden`), sonst würde die frei
|
||||
schwebende Toolbar oben abgeschnitten. `border:none` (Basisregel: 1px) —
|
||||
jeder Rahmen/jedes Padding auf `.rt-editor`/`.rt-surface` verschiebt den
|
||||
sichtbaren Text nach rechts/unten relativ zur positionierten Ecke (Bug-
|
||||
Meldung "Sprung nach rechts oben"); die blaue `outline` auf
|
||||
`.layout-sheet-inline-text` selbst übernimmt weiterhin die visuelle
|
||||
Rahmen-Anzeige (outline verschiebt den Inhalt NICHT, da ausserhalb der
|
||||
Box gezeichnet). */
|
||||
display: block;
|
||||
overflow: visible;
|
||||
border: none;
|
||||
/* s. .planview-inline-text .rt-editor — explizite Breite gegen "Wort läuft
|
||||
aus der Fläche raus statt umzubrechen" (die Aussen-Box hat eine feste
|
||||
`width` per Inline-Style, aber ohne diese Zeile war das für lange,
|
||||
leerzeichenlose Wörter nicht garantiert). */
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
/* REGRESSION-Fix "Editor ist tiefer als der Text": vorher stand die Toolbar
|
||||
IM normalen Fluss ÜBER der Textfläche (column-flex in .rt-editor) — ihre
|
||||
feste, zoomunabhängige Höhe (~38px: Padding+Button+Rahmen) schob die
|
||||
Fläche um diesen Betrag nach unten, während die Positionierung (JS) nur
|
||||
mit EINER Zeilenhöhe Abstand zur Baseline rechnete. Bei üblichem Zoom ist
|
||||
eine Zeilenhöhe kleiner als die Toolbar-Höhe → die Fläche landete UNTER
|
||||
dem eigentlichen Text. Jetzt schwebt die Toolbar frei OBERHALB der Box,
|
||||
ausserhalb ihres Flusses — sie verschiebt die Textfläche nicht mehr. */
|
||||
.layout-sheet-inline-text .rt-toolbar {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 100%;
|
||||
margin-bottom: 4px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
box-shadow: var(--shadow-1);
|
||||
}
|
||||
.layout-sheet-inline-text .rt-surface {
|
||||
font-size: var(--rt-font-size, 16px);
|
||||
line-height: 1.25; /* deckt sich mit primitives.tsx "drawingText" (fontSize*1.25) */
|
||||
min-height: var(--rt-min-height, 1.4em);
|
||||
padding: 0; /* kein Padding — verschiebt sonst den Text relativ zur Anker-Ecke */
|
||||
/* s. .planview-inline-text .rt-surface — harter Umbruch auch mitten im
|
||||
Wort statt Überlauf, plus Sicherheitsnetz gegen intrinsische
|
||||
Mindestbreite. */
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
overflow-wrap: anywhere;
|
||||
min-width: 0;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
/* Inline-Text-Editor auf der 2D-Zeichenfläche (PlanView) — dasselbe Prinzip
|
||||
|
||||
@@ -18,10 +18,9 @@ export interface FontMetricRatios {
|
||||
}
|
||||
|
||||
/** Zeilenabstand-Vielfaches für gezeichneten Text, EINE Quelle für alle
|
||||
* Verbraucher (primitives.tsx "drawingText" fontSize*1.25, PlanView.tsx/
|
||||
* LayoutSheet.tsx Inline-Editor-Anker UND deren CSS `line-height` in
|
||||
* styles.css `.planview-inline-text .rt-surface`/`.layout-sheet-inline-text
|
||||
* .rt-surface` — alle MÜSSEN denselben Wert verwenden, sonst driften
|
||||
* Verbraucher (primitives.tsx "drawingText" fontSize*1.25, PlanView.tsx
|
||||
* Inline-Editor-Anker UND dessen CSS `line-height` in styles.css
|
||||
* `.planview-inline-text .rt-surface` — alle MÜSSEN denselben Wert verwenden, sonst driften
|
||||
* Editor-Position und späteres Rendering wieder auseinander). */
|
||||
export const TEXT_LINE_HEIGHT_MULT = 1.25;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { docFromText, makeRun, type RichTextDoc } from "./richText";
|
||||
import { annotationTextLines, docToHtml, layoutText, runCssProps } from "./renderHtml";
|
||||
import { docToHtml, layoutText, runCssProps } from "./renderHtml";
|
||||
|
||||
const OPTS = { x: 0, y: 0, lineHeight: 10, unitPerPt: 1, basePt: 10, color: "#000000" };
|
||||
|
||||
@@ -29,16 +29,6 @@ describe("layoutText", () => {
|
||||
expect(at({ columnWidth: NaN })).toEqual(at({}));
|
||||
});
|
||||
|
||||
it("Layout-Markup: Basis = Höhe in mm, Vorschub 1.25 × Höhe, Rahmen nur bei Breite > 0 umbrochen", () => {
|
||||
const doc = docFromText("eins zwei drei");
|
||||
const l = annotationTextLines({ xMm: 10, yMm: 20, heightMm: 4, widthMm: 15 }, doc);
|
||||
expect(l.map((x) => x.y)).toEqual([20, 25, 30]);
|
||||
expect(l[0].tspans[0]).toMatchObject({ fontSize: 4, fill: "#111111" });
|
||||
// Negative Breite: kein Umbruch, aber (wie früher) Spalte für die Lage.
|
||||
const r = annotationTextLines({ xMm: 10, yMm: 20, heightMm: 4, widthMm: -6 }, { version: 1, paragraphs: [{ runs: [makeRun("x")], align: "right" }] });
|
||||
expect([r.length, r[0].x]).toEqual([1, 4]);
|
||||
});
|
||||
|
||||
it("bricht lange Absätze wortweise auf mehrere Zeilen um", () => {
|
||||
const doc = docFromText("eins zwei drei vier fünf");
|
||||
const lines = layoutText(doc, { ...OPTS, wrapWidthUnits: 30 });
|
||||
|
||||
@@ -264,27 +264,6 @@ export function layoutText(doc: RichTextDoc, opts: SvgTextOptions): SvgLine[] {
|
||||
return lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zeilen eines Text-Markups auf dem Layout-Blatt (Papier-mm; Layout-Blatt und Layout-PDF): Höhe
|
||||
* `heightMm` als Basisgrösse, Vorschub 1.25 × Höhe, erste Grundlinie bei `yMm`; mit Rahmenbreite
|
||||
* (`widthMm` > 0) wortweise umbrochen, Mitte/rechts im Rahmen (jede Breite ≠ 0 zählt dafür, wie früher).
|
||||
*/
|
||||
export function annotationTextLines(
|
||||
ann: { xMm: number; yMm: number; heightMm: number; widthMm?: number; color?: string },
|
||||
doc: RichTextDoc,
|
||||
): SvgLine[] {
|
||||
return layoutText(doc, {
|
||||
x: ann.xMm,
|
||||
y: ann.yMm,
|
||||
lineHeight: ann.heightMm * 1.25,
|
||||
unitPerPt: 25.4 / 72,
|
||||
basePt: (ann.heightMm / 25.4) * 72,
|
||||
color: ann.color ?? "#111111",
|
||||
wrapWidthUnits: ann.widthMm && ann.widthMm > 0 ? ann.widthMm : undefined,
|
||||
columnWidth: ann.widthMm,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Raumstempel-Block (Kern `stamp_block`): Rich-Text-Zeilen (Vorschub 1.3 × Basisgrösse bzw. die
|
||||
* Absatz-Zeilenhöhe) und darunter die Live-Zeilen (0.8 × Basisgrösse), vertikal um `y0` zentriert,
|
||||
|
||||
@@ -432,7 +432,7 @@ export function ImportDialog({
|
||||
value={existingLevelId}
|
||||
onChange={(v) => setExistingLevelId(v)}
|
||||
title={t("import.target.existing")}
|
||||
options={project.drawingLevels.map((z) => ({
|
||||
options={project.drawingLevels.filter((z) => !z.layoutId).map((z) => ({
|
||||
value: z.id,
|
||||
label: `${z.name} · ${t(kindBadgeKey(z.kind))}`,
|
||||
}))}
|
||||
|
||||
+326
-1260
File diff suppressed because it is too large.
Load diff
@@ -1,27 +1,13 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { LayoutAnnotation, LayoutViewport } from "../model/types";
|
||||
import type { LayoutViewport } from "../model/types";
|
||||
import {
|
||||
annotationBoundsMm,
|
||||
annotationHandleAt,
|
||||
applyHandleDrag,
|
||||
applyLineHandleDrag,
|
||||
clampRectToSheet,
|
||||
distanceToSegment,
|
||||
fitTransform,
|
||||
handleAt,
|
||||
lineHandleAt,
|
||||
mmToScreen,
|
||||
normalizeRect,
|
||||
panBy,
|
||||
pickAnnotation,
|
||||
pickAnnotationHandle,
|
||||
pickViewport,
|
||||
screenToMm,
|
||||
translateAnnotation,
|
||||
vpRect,
|
||||
zoomAtCursor,
|
||||
type RectMm,
|
||||
type SheetTransform,
|
||||
} from "./layoutSheetMath";
|
||||
|
||||
const vp = (
|
||||
@@ -32,64 +18,6 @@ const vp = (
|
||||
heightMm: number,
|
||||
): LayoutViewport => ({ id, snapshotId: "s", xMm, yMm, widthMm, heightMm });
|
||||
|
||||
describe("mm ↔ screen", () => {
|
||||
const t: SheetTransform = { scale: 2, tx: 100, ty: 50 };
|
||||
it("mmToScreen applies scale + translate", () => {
|
||||
expect(mmToScreen(t, { xMm: 10, yMm: 20 })).toEqual({ x: 120, y: 90 });
|
||||
});
|
||||
it("screenToMm is the inverse", () => {
|
||||
const p = screenToMm(t, 120, 90);
|
||||
expect(p.xMm).toBeCloseTo(10);
|
||||
expect(p.yMm).toBeCloseTo(20);
|
||||
});
|
||||
it("roundtrips arbitrary points", () => {
|
||||
const s = mmToScreen(t, { xMm: 37.5, yMm: -12.25 });
|
||||
const m = screenToMm(t, s.x, s.y);
|
||||
expect(m.xMm).toBeCloseTo(37.5);
|
||||
expect(m.yMm).toBeCloseTo(-12.25);
|
||||
});
|
||||
});
|
||||
|
||||
describe("fitTransform", () => {
|
||||
it("centres an A4 portrait sheet in a wide canvas", () => {
|
||||
const t = fitTransform(210, 297, 1000, 600, 0.92);
|
||||
// Höhe ist der Engpass: scale = 600*0.92/297.
|
||||
expect(t.scale).toBeCloseTo((600 * 0.92) / 297);
|
||||
// Zentriert: linker Rand = (1000 - 210*scale)/2.
|
||||
expect(t.tx).toBeCloseTo((1000 - 210 * t.scale) / 2);
|
||||
expect(t.ty).toBeCloseTo((600 - 297 * t.scale) / 2);
|
||||
});
|
||||
it("falls back to scale 1 on degenerate canvas", () => {
|
||||
const t = fitTransform(210, 297, 0, 0);
|
||||
expect(t.scale).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("zoomAtCursor", () => {
|
||||
it("keeps the mm point under the cursor fixed", () => {
|
||||
const t: SheetTransform = { scale: 2, tx: 100, ty: 50 };
|
||||
const cursor = { x: 300, y: 220 };
|
||||
const before = screenToMm(t, cursor.x, cursor.y);
|
||||
const zt = zoomAtCursor(t, 1.25, cursor.x, cursor.y);
|
||||
expect(zt.scale).toBeCloseTo(2.5);
|
||||
const after = screenToMm(zt, cursor.x, cursor.y);
|
||||
expect(after.xMm).toBeCloseTo(before.xMm);
|
||||
expect(after.yMm).toBeCloseTo(before.yMm);
|
||||
});
|
||||
it("clamps scale to bounds", () => {
|
||||
const t: SheetTransform = { scale: 30, tx: 0, ty: 0 };
|
||||
const zt = zoomAtCursor(t, 4, 0, 0);
|
||||
expect(zt.scale).toBeLessThanOrEqual(40);
|
||||
});
|
||||
});
|
||||
|
||||
describe("panBy", () => {
|
||||
it("shifts translation, keeps scale", () => {
|
||||
const t = panBy({ scale: 3, tx: 10, ty: 20 }, 5, -7);
|
||||
expect(t).toEqual({ scale: 3, tx: 15, ty: 13 });
|
||||
});
|
||||
});
|
||||
|
||||
describe("handleAt", () => {
|
||||
const r: RectMm = { xMm: 20, yMm: 20, widthMm: 100, heightMm: 60 };
|
||||
it("detects corners with priority over edges", () => {
|
||||
@@ -203,189 +131,3 @@ describe("vpRect", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// ── Annotationen (Linie/Rechteck/Text) ──────────────────────────────────────
|
||||
|
||||
const line = (id: string, x1: number, y1: number, x2: number, y2: number): LayoutAnnotation => ({
|
||||
id,
|
||||
kind: "line",
|
||||
x1Mm: x1,
|
||||
y1Mm: y1,
|
||||
x2Mm: x2,
|
||||
y2Mm: y2,
|
||||
});
|
||||
const rect = (id: string, x: number, y: number, w: number, h: number): LayoutAnnotation => ({
|
||||
id,
|
||||
kind: "rect",
|
||||
xMm: x,
|
||||
yMm: y,
|
||||
widthMm: w,
|
||||
heightMm: h,
|
||||
});
|
||||
const text = (id: string, x: number, y: number, t: string, h = 3.5): LayoutAnnotation => ({
|
||||
id,
|
||||
kind: "text",
|
||||
xMm: x,
|
||||
yMm: y,
|
||||
text: t,
|
||||
heightMm: h,
|
||||
});
|
||||
const image = (id: string, x: number, y: number, w: number, h: number): LayoutAnnotation => ({
|
||||
id,
|
||||
kind: "image",
|
||||
xMm: x,
|
||||
yMm: y,
|
||||
widthMm: w,
|
||||
heightMm: h,
|
||||
src: "data:image/png;base64,",
|
||||
});
|
||||
|
||||
describe("distanceToSegment", () => {
|
||||
it("returns perpendicular distance for a point beside the segment", () => {
|
||||
expect(distanceToSegment(5, 3, 0, 0, 10, 0)).toBeCloseTo(3);
|
||||
});
|
||||
it("clamps to the nearest endpoint beyond the segment", () => {
|
||||
expect(distanceToSegment(-4, 0, 0, 0, 10, 0)).toBeCloseTo(4);
|
||||
expect(distanceToSegment(14, 0, 0, 0, 10, 0)).toBeCloseTo(4);
|
||||
});
|
||||
it("degenerates to point distance for a zero-length segment", () => {
|
||||
expect(distanceToSegment(3, 4, 0, 0, 0, 0)).toBeCloseTo(5);
|
||||
});
|
||||
});
|
||||
|
||||
describe("annotationBoundsMm", () => {
|
||||
it("rect: its own rectangle", () => {
|
||||
expect(annotationBoundsMm(rect("r", 10, 20, 30, 40))).toEqual({
|
||||
xMm: 10,
|
||||
yMm: 20,
|
||||
widthMm: 30,
|
||||
heightMm: 40,
|
||||
});
|
||||
});
|
||||
it("line: normalized bounding rect of both endpoints", () => {
|
||||
expect(annotationBoundsMm(line("l", 30, 30, 10, 10))).toEqual({
|
||||
xMm: 10,
|
||||
yMm: 10,
|
||||
widthMm: 20,
|
||||
heightMm: 20,
|
||||
});
|
||||
});
|
||||
it("text: box sits above the baseline, width grows with character count", () => {
|
||||
const b = annotationBoundsMm(text("t", 10, 20, "AB", 4));
|
||||
expect(b.xMm).toBe(10);
|
||||
expect(b.yMm).toBe(16); // 20 - heightMm
|
||||
expect(b.heightMm).toBeCloseTo(5); // heightMm * 1.25
|
||||
expect(b.widthMm).toBeGreaterThan(0);
|
||||
});
|
||||
it("image: its own rectangle, like rect", () => {
|
||||
expect(annotationBoundsMm(image("i", 5, 5, 40, 30))).toEqual({
|
||||
xMm: 5,
|
||||
yMm: 5,
|
||||
widthMm: 40,
|
||||
heightMm: 30,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("pickAnnotation", () => {
|
||||
it("hits a line within tolerance of the segment", () => {
|
||||
expect(pickAnnotation([line("l", 0, 0, 10, 0)], 5, 1, 2)).toBe("l");
|
||||
expect(pickAnnotation([line("l", 0, 0, 10, 0)], 5, 5, 2)).toBe(null);
|
||||
});
|
||||
it("hits a rect on its border and its interior", () => {
|
||||
const r = rect("r", 20, 20, 10, 10);
|
||||
expect(pickAnnotation([r], 20, 20, 1)).toBe("r"); // corner
|
||||
expect(pickAnnotation([r], 25, 25, 1)).toBe("r"); // interior
|
||||
expect(pickAnnotation([r], 100, 100, 1)).toBe(null);
|
||||
});
|
||||
it("hits a text annotation near its baseline box", () => {
|
||||
const tx = text("t", 10, 20, "Hallo", 4);
|
||||
expect(pickAnnotation([tx], 12, 18, 1)).toBe("t");
|
||||
expect(pickAnnotation([tx], 200, 200, 1)).toBe(null);
|
||||
});
|
||||
it("returns the topmost (last) annotation in overlap, like pickViewport", () => {
|
||||
const overlapping = [rect("a", 0, 0, 50, 50), rect("b", 10, 10, 50, 50)];
|
||||
expect(pickAnnotation(overlapping, 30, 30, 1)).toBe("b");
|
||||
});
|
||||
it("hits an image on its border and its interior, like rect", () => {
|
||||
const img = image("i", 20, 20, 10, 10);
|
||||
expect(pickAnnotation([img], 20, 20, 1)).toBe("i"); // corner
|
||||
expect(pickAnnotation([img], 25, 25, 1)).toBe("i"); // interior
|
||||
expect(pickAnnotation([img], 100, 100, 1)).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe("lineHandleAt", () => {
|
||||
it("hits the first endpoint within tolerance", () => {
|
||||
expect(lineHandleAt(0, 0, 10, 0, 0.5, 0.5, 2)).toBe("p1");
|
||||
});
|
||||
it("hits the second endpoint within tolerance", () => {
|
||||
expect(lineHandleAt(0, 0, 10, 0, 9.5, 0.5, 2)).toBe("p2");
|
||||
});
|
||||
it("hits the body between the endpoints", () => {
|
||||
expect(lineHandleAt(0, 0, 10, 0, 5, 1, 2)).toBe("body");
|
||||
});
|
||||
it("misses far away", () => {
|
||||
expect(lineHandleAt(0, 0, 10, 0, 5, 20, 2)).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe("annotationHandleAt / pickAnnotationHandle", () => {
|
||||
it("line: endpoint takes priority over body", () => {
|
||||
const l = line("l", 0, 0, 10, 0);
|
||||
expect(annotationHandleAt(l, 0, 0.5, 2)).toEqual({ kind: "line", handle: "p1" });
|
||||
expect(annotationHandleAt(l, 5, 0.5, 2)).toEqual({ kind: "line", handle: "body" });
|
||||
});
|
||||
it("rect: corner/edge/body like a viewport", () => {
|
||||
const r = rect("r", 20, 20, 10, 10);
|
||||
expect(annotationHandleAt(r, 20, 20, 1)).toEqual({ kind: "rect", handle: "nw" });
|
||||
expect(annotationHandleAt(r, 25, 25, 1)).toEqual({ kind: "rect", handle: "body" });
|
||||
});
|
||||
it("image: same handle set as rect", () => {
|
||||
const img = image("i", 20, 20, 10, 10);
|
||||
expect(annotationHandleAt(img, 30, 30, 1)).toEqual({ kind: "image", handle: "se" });
|
||||
});
|
||||
it("text: no handle system, plain bbox hit still reported as pickAnnotationHandle body", () => {
|
||||
const tx = text("t", 10, 20, "Hallo", 4);
|
||||
expect(annotationHandleAt(tx, 12, 18, 1)).toBe(null);
|
||||
expect(pickAnnotationHandle([tx], 12, 18, 1)).toEqual({
|
||||
id: "t",
|
||||
hit: { kind: "line", handle: "body" },
|
||||
});
|
||||
});
|
||||
it("pickAnnotationHandle returns null outside every annotation", () => {
|
||||
expect(pickAnnotationHandle([line("l", 0, 0, 10, 0)], 500, 500, 1)).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe("applyLineHandleDrag", () => {
|
||||
const l = line("l", 0, 0, 10, 0) as Extract<LayoutAnnotation, { kind: "line" }>;
|
||||
it("p1 moves only the first endpoint", () => {
|
||||
expect(applyLineHandleDrag(l, "p1", 2, 3)).toEqual({ x1Mm: 2, y1Mm: 3, x2Mm: 10, y2Mm: 0 });
|
||||
});
|
||||
it("p2 moves only the second endpoint", () => {
|
||||
expect(applyLineHandleDrag(l, "p2", 2, 3)).toEqual({ x1Mm: 0, y1Mm: 0, x2Mm: 12, y2Mm: 3 });
|
||||
});
|
||||
it("body moves both endpoints", () => {
|
||||
expect(applyLineHandleDrag(l, "body", 2, 3)).toEqual({ x1Mm: 2, y1Mm: 3, x2Mm: 12, y2Mm: 3 });
|
||||
});
|
||||
});
|
||||
|
||||
describe("translateAnnotation", () => {
|
||||
it("moves both endpoints of a line", () => {
|
||||
const moved = translateAnnotation(line("l", 0, 0, 10, 10), 5, -5);
|
||||
expect(moved).toMatchObject({ x1Mm: 5, y1Mm: -5, x2Mm: 15, y2Mm: 5 });
|
||||
});
|
||||
it("moves the origin of a rect", () => {
|
||||
const moved = translateAnnotation(rect("r", 10, 10, 20, 20), 3, 4);
|
||||
expect(moved).toMatchObject({ xMm: 13, yMm: 14, widthMm: 20, heightMm: 20 });
|
||||
});
|
||||
it("moves the anchor point of a text annotation", () => {
|
||||
const moved = translateAnnotation(text("t", 10, 10, "Hi"), 1, 2);
|
||||
expect(moved).toMatchObject({ xMm: 11, yMm: 12, text: "Hi" });
|
||||
});
|
||||
it("moves the origin of an image, like rect", () => {
|
||||
const moved = translateAnnotation(image("i", 10, 10, 20, 20), 3, 4);
|
||||
expect(moved).toMatchObject({ xMm: 13, yMm: 14, widthMm: 20, heightMm: 20 });
|
||||
});
|
||||
});
|
||||
+4
-295
@@ -1,25 +1,14 @@
|
||||
// Reine, testbare Geometrie für die In-Viewport-Layout-Ansicht (Phase 2b):
|
||||
// Bildschirm↔Blatt-mm-Transform (Pan/Zoom-to-Cursor/Einpassen), Viewport-
|
||||
// Reine, testbare Geometrie für die Viewports auf dem Layout-Blatt: Viewport-
|
||||
// Trefferlogik (Body + 8 Resize-Griffe), Resize-Mathe mit Mindestgrösse,
|
||||
// Rechteck-Normalisierung (Aufziehen) und Clamp an die Blattkanten.
|
||||
//
|
||||
// KEINE React-/DOM-Abhängigkeit — nur Zahlen. Das UI (LayoutSheet.tsx) baut
|
||||
// darauf auf. Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import type { LayoutAnnotation, LayoutViewport } from "../model/types";
|
||||
import type { LayoutViewport } from "../model/types";
|
||||
|
||||
/**
|
||||
* Affine Blatt-Transform: Bildschirm-Pixel = mm · scale + translate.
|
||||
* `scale` ist px pro mm (immer > 0), `tx/ty` die Blatt-Ursprungslage (mm 0,0)
|
||||
* in Canvas-Pixeln.
|
||||
*/
|
||||
export interface SheetTransform {
|
||||
/** Pixel pro Millimeter (> 0). */
|
||||
scale: number;
|
||||
/** Bildschirm-X des Blatt-Ursprungs (mm x=0) in Canvas-Pixeln. */
|
||||
tx: number;
|
||||
/** Bildschirm-Y des Blatt-Ursprungs (mm y=0) in Canvas-Pixeln. */
|
||||
ty: number;
|
||||
function clamp(v: number, lo: number, hi: number): number {
|
||||
return v < lo ? lo : v > hi ? hi : v;
|
||||
}
|
||||
|
||||
/** Ein Punkt in Blatt-Millimetern. */
|
||||
@@ -48,68 +37,6 @@ export type Handle =
|
||||
| "w"
|
||||
| "body";
|
||||
|
||||
export const MIN_SCALE = 0.05;
|
||||
export const MAX_SCALE = 40;
|
||||
|
||||
function clamp(v: number, lo: number, hi: number): number {
|
||||
return v < lo ? lo : v > hi ? hi : v;
|
||||
}
|
||||
|
||||
// ── Transform ────────────────────────────────────────────────────────────────
|
||||
|
||||
/** Blatt-mm → Canvas-Pixel. */
|
||||
export function mmToScreen(t: SheetTransform, p: Mm): { x: number; y: number } {
|
||||
return { x: p.xMm * t.scale + t.tx, y: p.yMm * t.scale + t.ty };
|
||||
}
|
||||
|
||||
/** Canvas-Pixel → Blatt-mm. */
|
||||
export function screenToMm(t: SheetTransform, sx: number, sy: number): Mm {
|
||||
return { xMm: (sx - t.tx) / t.scale, yMm: (sy - t.ty) / t.scale };
|
||||
}
|
||||
|
||||
/**
|
||||
* Einpass-Transform: Blatt (mm) zentriert in die Canvas-Fläche (px), mit
|
||||
* `margin` (Anteil, z. B. 0.92 = 8 % Rand). Degenerierte Eingaben → scale=1.
|
||||
*/
|
||||
export function fitTransform(
|
||||
sheetWMm: number,
|
||||
sheetHMm: number,
|
||||
canvasWPx: number,
|
||||
canvasHPx: number,
|
||||
margin = 0.92,
|
||||
): SheetTransform {
|
||||
const sx = (canvasWPx * margin) / sheetWMm;
|
||||
const sy = (canvasHPx * margin) / sheetHMm;
|
||||
let scale = Math.min(sx, sy);
|
||||
if (!Number.isFinite(scale) || scale <= 0) scale = 1;
|
||||
scale = clamp(scale, MIN_SCALE, MAX_SCALE);
|
||||
const tx = (canvasWPx - sheetWMm * scale) / 2;
|
||||
const ty = (canvasHPx - sheetHMm * scale) / 2;
|
||||
return { scale, tx, ty };
|
||||
}
|
||||
|
||||
/**
|
||||
* Zoom um den Cursor: der mm-Punkt unter (sx,sy) bleibt fix. `factor` > 1 zoomt
|
||||
* rein, < 1 raus; der Massstab wird auf [MIN_SCALE, MAX_SCALE] geklemmt.
|
||||
*/
|
||||
export function zoomAtCursor(
|
||||
t: SheetTransform,
|
||||
factor: number,
|
||||
sx: number,
|
||||
sy: number,
|
||||
): SheetTransform {
|
||||
const newScale = clamp(t.scale * factor, MIN_SCALE, MAX_SCALE);
|
||||
// mm-Punkt unter dem Cursor VOR dem Zoom.
|
||||
const m = screenToMm(t, sx, sy);
|
||||
// Neue Translation, damit derselbe mm-Punkt wieder unter (sx,sy) liegt.
|
||||
return { scale: newScale, tx: sx - m.xMm * newScale, ty: sy - m.yMm * newScale };
|
||||
}
|
||||
|
||||
/** Verschiebt die Transform um (dxPx,dyPx) Canvas-Pixel (Pan). */
|
||||
export function panBy(t: SheetTransform, dxPx: number, dyPx: number): SheetTransform {
|
||||
return { scale: t.scale, tx: t.tx + dxPx, ty: t.ty + dyPx };
|
||||
}
|
||||
|
||||
// ── Viewport-Rechtecke / Treffer ─────────────────────────────────────────────
|
||||
|
||||
/** Rechteck-Sicht eines Viewports (nur die Blattgeometrie). */
|
||||
@@ -320,221 +247,3 @@ export function handleAnchors(r: RectMm): { handle: Handle; xMm: number; yMm: nu
|
||||
{ handle: "w", xMm: x, yMm: cy },
|
||||
];
|
||||
}
|
||||
|
||||
// ── Annotationen (Linie/Rechteck/Text/Bild) ─────────────────────────────────
|
||||
// Rechteck/Bild teilen sich die Viewport-Griff-Mathe (dieselbe RectMm-Form,
|
||||
// 8 Ecken/Kanten-Griffe). Linie bekommt zwei Endpunkt-Griffe (wie eine Linie
|
||||
// im Grundriss). Text bleibt vorerst griff-los (Rahmen kommt beim Aufziehen).
|
||||
|
||||
/** Kürzester Abstand (mm) eines Punkts zu einem Liniensegment. */
|
||||
export function distanceToSegment(
|
||||
px: number,
|
||||
py: number,
|
||||
x1: number,
|
||||
y1: number,
|
||||
x2: number,
|
||||
y2: number,
|
||||
): number {
|
||||
const dx = x2 - x1;
|
||||
const dy = y2 - y1;
|
||||
const lenSq = dx * dx + dy * dy;
|
||||
if (lenSq === 0) return Math.hypot(px - x1, py - y1);
|
||||
const t = clamp(((px - x1) * dx + (py - y1) * dy) / lenSq, 0, 1);
|
||||
const cx = x1 + t * dx;
|
||||
const cy = y1 + t * dy;
|
||||
return Math.hypot(px - cx, py - cy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Umhüllendes Rechteck (mm) einer Annotation — für Text nur eine GROBE Box
|
||||
* (kein echtes Font-Measuring im SVG; Breite aus Zeichenzahl geschätzt), reicht
|
||||
* aber für Trefferlogik + Auswahl-Rahmen. `yMm` einer Text-Annotation ist die
|
||||
* Baseline, die Box liegt daher oberhalb davon.
|
||||
*/
|
||||
export function annotationBoundsMm(ann: LayoutAnnotation): RectMm {
|
||||
if (ann.kind === "rect" || ann.kind === "image") {
|
||||
return { xMm: ann.xMm, yMm: ann.yMm, widthMm: ann.widthMm, heightMm: ann.heightMm };
|
||||
}
|
||||
if (ann.kind === "line") {
|
||||
return normalizeRect(ann.x1Mm, ann.y1Mm, ann.x2Mm, ann.y2Mm);
|
||||
}
|
||||
// Text: grobe Box aus Zeichenzahl geschätzt (kein echtes Font-Measuring im
|
||||
// SVG) — bei gesetzter Rahmenbreite (`widthMm`, Rich-Text-Frame) gilt diese
|
||||
// statt der Schätzung; die Höhe bleibt eine grobe Zeilenschätzung.
|
||||
const estWidthMm = Math.max(ann.heightMm, ann.text.length * ann.heightMm * 0.6);
|
||||
const lines = ann.doc ? Math.max(1, ann.doc.paragraphs.length) : 1;
|
||||
return {
|
||||
xMm: ann.xMm,
|
||||
yMm: ann.yMm - ann.heightMm,
|
||||
widthMm: ann.widthMm ?? estWidthMm,
|
||||
heightMm: ann.heightMm * 1.25 * lines,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Trefferlogik (mm) für EINE Annotation: Linie → Abstand zum Segment ≤ tolMm;
|
||||
* Rechteck → Rahmen ODER Innenfläche (wiederverwendet {@link handleAt}, jeder
|
||||
* Nicht-null-Rückgabewert zählt als Treffer); Text → Bounding-Box + Toleranz.
|
||||
*/
|
||||
export function annotationHit(
|
||||
ann: LayoutAnnotation,
|
||||
xMm: number,
|
||||
yMm: number,
|
||||
tolMm: number,
|
||||
): boolean {
|
||||
if (ann.kind === "line") {
|
||||
return distanceToSegment(xMm, yMm, ann.x1Mm, ann.y1Mm, ann.x2Mm, ann.y2Mm) <= tolMm;
|
||||
}
|
||||
if (ann.kind === "rect" || ann.kind === "image") {
|
||||
const r: RectMm = { xMm: ann.xMm, yMm: ann.yMm, widthMm: ann.widthMm, heightMm: ann.heightMm };
|
||||
return handleAt(r, xMm, yMm, tolMm) !== null;
|
||||
}
|
||||
const b = annotationBoundsMm(ann);
|
||||
return (
|
||||
xMm >= b.xMm - tolMm &&
|
||||
xMm <= b.xMm + b.widthMm + tolMm &&
|
||||
yMm >= b.yMm - tolMm &&
|
||||
yMm <= b.yMm + b.heightMm + tolMm
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Topmost-Treffer über eine Annotations-Liste (letzte = oberste, wie
|
||||
* {@link pickViewport}). Liefert die Id des ERSTEN Treffers von oben, sonst null.
|
||||
*/
|
||||
export function pickAnnotation(
|
||||
annotations: LayoutAnnotation[],
|
||||
xMm: number,
|
||||
yMm: number,
|
||||
tolMm: number,
|
||||
): string | null {
|
||||
for (let i = annotations.length - 1; i >= 0; i--) {
|
||||
const a = annotations[i];
|
||||
if (annotationHit(a, xMm, yMm, tolMm)) return a.id;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// ── Resize-Griffe für Annotationen (wie im Grundriss: Endpunkte/Ecken) ──────
|
||||
|
||||
/** Griff einer Linien-Annotation: die beiden Endpunkte oder der Körper. */
|
||||
export type LineHandle = "p1" | "p2" | "body";
|
||||
|
||||
/** Griff-Ergebnis für EINE Annotation — je Art ein anderer Griff-Typ. */
|
||||
export type AnnotHandleHit =
|
||||
| { kind: "rect" | "image"; handle: Handle }
|
||||
| { kind: "line"; handle: LineHandle };
|
||||
|
||||
/**
|
||||
* Griff (oder Körper) einer Linien-Annotation an einem mm-Punkt: die
|
||||
* Endpunkte haben Vorrang vor dem Segment (wie ein Linien-Griff im Grundriss).
|
||||
*/
|
||||
export function lineHandleAt(
|
||||
x1: number,
|
||||
y1: number,
|
||||
x2: number,
|
||||
y2: number,
|
||||
xMm: number,
|
||||
yMm: number,
|
||||
tolMm: number,
|
||||
): LineHandle | null {
|
||||
if (Math.hypot(xMm - x1, yMm - y1) <= tolMm) return "p1";
|
||||
if (Math.hypot(xMm - x2, yMm - y2) <= tolMm) return "p2";
|
||||
if (distanceToSegment(xMm, yMm, x1, y1, x2, y2) <= tolMm) return "body";
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Griff (oder Körper) EINER Annotation an einem mm-Punkt — Linie liefert einen
|
||||
* Endpunkt-Griff, Rechteck/Bild die 8 Viewport-artigen Ecken-/Kanten-Griffe
|
||||
* (wiederverwendet {@link handleAt}). Text hat (noch) keine Griffe → `null`.
|
||||
*/
|
||||
export function annotationHandleAt(
|
||||
ann: LayoutAnnotation,
|
||||
xMm: number,
|
||||
yMm: number,
|
||||
tolMm: number,
|
||||
): AnnotHandleHit | null {
|
||||
if (ann.kind === "line") {
|
||||
const h = lineHandleAt(ann.x1Mm, ann.y1Mm, ann.x2Mm, ann.y2Mm, xMm, yMm, tolMm);
|
||||
return h ? { kind: "line", handle: h } : null;
|
||||
}
|
||||
if (ann.kind === "rect" || ann.kind === "image") {
|
||||
const r: RectMm = { xMm: ann.xMm, yMm: ann.yMm, widthMm: ann.widthMm, heightMm: ann.heightMm };
|
||||
const h = handleAt(r, xMm, yMm, tolMm);
|
||||
return h ? { kind: ann.kind, handle: h } : null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Topmost Griff-Treffer über eine Annotations-Liste (wie {@link pickAnnotation},
|
||||
* aber liefert zusätzlich den konkreten Griff für Resize statt nur Verschieben).
|
||||
*/
|
||||
export function pickAnnotationHandle(
|
||||
annotations: LayoutAnnotation[],
|
||||
xMm: number,
|
||||
yMm: number,
|
||||
tolMm: number,
|
||||
): { id: string; hit: AnnotHandleHit } | null {
|
||||
for (let i = annotations.length - 1; i >= 0; i--) {
|
||||
const a = annotations[i];
|
||||
const hit = annotationHandleAt(a, xMm, yMm, tolMm);
|
||||
if (hit) return { id: a.id, hit };
|
||||
if (annotationHit(a, xMm, yMm, tolMm)) {
|
||||
// Text (kein Griff-System) oder ein Nicht-Griff-Treffer im Inneren.
|
||||
return { id: a.id, hit: { kind: "line", handle: "body" } };
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Endpunkte einer Linien-Annotation als mm-Punkte (für die Griff-Darstellung). */
|
||||
export function lineHandleAnchors(ann: Extract<LayoutAnnotation, { kind: "line" }>): Mm[] {
|
||||
return [
|
||||
{ xMm: ann.x1Mm, yMm: ann.y1Mm },
|
||||
{ xMm: ann.x2Mm, yMm: ann.y2Mm },
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Wendet einen Linien-Griff-Drag an: `p1`/`p2` verschiebt genau diesen
|
||||
* Endpunkt, `body` das ganze Segment (Delta).
|
||||
*/
|
||||
export function applyLineHandleDrag(
|
||||
start: Extract<LayoutAnnotation, { kind: "line" }>,
|
||||
handle: LineHandle,
|
||||
dxMm: number,
|
||||
dyMm: number,
|
||||
): { x1Mm: number; y1Mm: number; x2Mm: number; y2Mm: number } {
|
||||
if (handle === "p1") {
|
||||
return { x1Mm: start.x1Mm + dxMm, y1Mm: start.y1Mm + dyMm, x2Mm: start.x2Mm, y2Mm: start.y2Mm };
|
||||
}
|
||||
if (handle === "p2") {
|
||||
return { x1Mm: start.x1Mm, y1Mm: start.y1Mm, x2Mm: start.x2Mm + dxMm, y2Mm: start.y2Mm + dyMm };
|
||||
}
|
||||
return {
|
||||
x1Mm: start.x1Mm + dxMm,
|
||||
y1Mm: start.y1Mm + dyMm,
|
||||
x2Mm: start.x2Mm + dxMm,
|
||||
y2Mm: start.y2Mm + dyMm,
|
||||
};
|
||||
}
|
||||
|
||||
/** Verschiebt eine Annotation um ein mm-Delta — alle ihre Punkte wandern mit. */
|
||||
export function translateAnnotation(
|
||||
ann: LayoutAnnotation,
|
||||
dxMm: number,
|
||||
dyMm: number,
|
||||
): LayoutAnnotation {
|
||||
if (ann.kind === "line") {
|
||||
return {
|
||||
...ann,
|
||||
x1Mm: ann.x1Mm + dxMm,
|
||||
y1Mm: ann.y1Mm + dyMm,
|
||||
x2Mm: ann.x2Mm + dxMm,
|
||||
y2Mm: ann.y2Mm + dyMm,
|
||||
};
|
||||
}
|
||||
return { ...ann, xMm: ann.xMm + dxMm, yMm: ann.yMm + dyMm };
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
import type { ComponentProps, CSSProperties } from "react";
|
||||
import type { ComponentProps, CSSProperties, ReactNode } from "react";
|
||||
import type { HatchRender, Plan, PlanImage, Primitive } from "../../core";
|
||||
import { materializeGreyed, materializeUnderlay, type UnderlayGroup } from "../../core";
|
||||
import type { Drawing2D, EdgeGrip, Vec2 } from "../../model/types";
|
||||
@@ -580,6 +580,15 @@ export interface PlanViewProps {
|
||||
* (`SnapSettings.hoverDivideCount`); Default 2.
|
||||
*/
|
||||
hoverDivideCount?: number;
|
||||
/**
|
||||
* Hintergrund unter der Zeichnung (z. B. das Layout-Blatt: Papier, Master, Viewports), gezeichnet
|
||||
* im SVG zwischen Raster und Geometrie. `origin` = Ursprung des Overlays (viewBox-Einheiten, s.
|
||||
* planView/overlayOrigin.ts), `pxPerMeter` = aktueller Zoom. Mit Hintergrund zeichnet der SVG-Pfad
|
||||
* (wie bei Luftbildern), damit er sichtbar bleibt.
|
||||
*/
|
||||
backdrop?: (origin: Vec2, pxPerMeter: number) => ReactNode;
|
||||
/** Einpass-Bereich (Modell-Meter) statt der Plan-Grenzen — z. B. das Blatt. */
|
||||
fitBounds?: { minX: number; minY: number; maxX: number; maxY: number };
|
||||
}
|
||||
|
||||
/** Treiber für das Ziehen von Editier-Griffen (von App bereitgestellt). */
|
||||
@@ -705,6 +714,8 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
|
||||
snapColor = DEFAULT_SNAP_COLOR,
|
||||
hoverDivideDelayMs = 300,
|
||||
hoverDivideCount = 2,
|
||||
backdrop,
|
||||
fitBounds,
|
||||
},
|
||||
ref,
|
||||
) {
|
||||
@@ -720,14 +731,16 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
|
||||
// toScreen-Abbildung. Reset-/Einpassen-Ziel + Bezug für die Zoom-Grenzen; wird
|
||||
// NICHT automatisch angewandt (nur bei resetKey-Wechsel und „Einpassen").
|
||||
const defaultView = useMemo<ViewBox>(() => {
|
||||
const { minX, minY, maxX, maxY } = planRaw.bounds;
|
||||
const { minX, minY, maxX, maxY } = fitBounds ?? planRaw.bounds;
|
||||
// Fester Einpass-Bereich (Blatt): Rand relativ zu seiner Grösse statt der festen Modell-Marge.
|
||||
const pad = fitBounds ? Math.max(maxX - minX, maxY - minY) * PX_PER_M * 0.04 : PAD;
|
||||
return {
|
||||
x: minX * PX_PER_M - PAD,
|
||||
y: -maxY * PX_PER_M - PAD,
|
||||
w: (maxX - minX) * PX_PER_M + PAD * 2,
|
||||
h: (maxY - minY) * PX_PER_M + PAD * 2,
|
||||
x: minX * PX_PER_M - pad,
|
||||
y: -maxY * PX_PER_M - pad,
|
||||
w: (maxX - minX) * PX_PER_M + pad * 2,
|
||||
h: (maxY - minY) * PX_PER_M + pad * 2,
|
||||
};
|
||||
}, [planRaw]);
|
||||
}, [planRaw, fitBounds]);
|
||||
|
||||
// Aktueller Ausschnitt; treibt die viewBox des SVG. Initial = eingepasst.
|
||||
const [view, setView] = useState<ViewBox>(defaultView);
|
||||
@@ -823,7 +836,7 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
|
||||
);
|
||||
// Engine WIRKLICH aktiv? Steuert das Umschalten SVG↔GPU: bei false rendert der
|
||||
// volle SVG-Pfad (Fallback), bei true übernimmt die GPU-Ebene + Text-Overlay.
|
||||
const useGpuRenderer = wantGpu && glReady && !hasBgImages && !hasDrawingImages;
|
||||
const useGpuRenderer = wantGpu && glReady && !hasBgImages && !hasDrawingImages && !backdrop;
|
||||
|
||||
// `planRaw.greyedRanges` (andere Ebenen als gedimmte Referenz) ohne Klonen der
|
||||
// Primitive: der WebGL-Pfad dimmt selbst beim Zeichnen (nur planRaw), alle
|
||||
@@ -3035,7 +3048,7 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
|
||||
glReady bleibt false → Deadlock). Bei WebGL-Fehler bleibt es leer hinten
|
||||
und der volle SVG-Pfad übernimmt sichtbar. NICHT montiert, wenn ein
|
||||
Luftbild aktiv ist — dann rendert der SVG-Pfad alles inkl. Bild-Ebene. */}
|
||||
{wantGpu && !hasBgImages && (
|
||||
{wantGpu && !hasBgImages && !backdrop && (
|
||||
<canvas
|
||||
ref={canvasRef}
|
||||
style={{
|
||||
@@ -3117,6 +3130,7 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
|
||||
pxPerMeter={currentPxPerMeter()}
|
||||
/>
|
||||
)}
|
||||
{backdrop?.(overlayOrigin, currentPxPerMeter())}
|
||||
{/* Georeferenzierte Luftbilder ZWISCHEN Blatt-Hintergrund und Geometrie:
|
||||
Modell-Meter × PX_PER_M mit negierter y-Achse (s. toScreen) → Bild-Norden
|
||||
(max.y) oben bei y=−max.y·PX; das Bild zeichnet natürlich von oben (kein
|
||||
|
||||
@@ -9,11 +9,14 @@
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
|
||||
import { t } from "../i18n";
|
||||
import { LayoutSheetPane, type LayoutSheetHandlers, type SheetPlanProps } from "../ui/LayoutSheet";
|
||||
import { SHEET_SCALE_DENOMINATOR } from "../model/layoutModel";
|
||||
import type {
|
||||
Ceiling,
|
||||
Drawing2D,
|
||||
DrawingLevel,
|
||||
EdgeGrip,
|
||||
Layout,
|
||||
Project,
|
||||
Roof,
|
||||
Vec2,
|
||||
@@ -141,7 +144,14 @@ export function Content({
|
||||
onEdit3dGroup,
|
||||
onGrip3dEditTab,
|
||||
onGrip3dEditCancel,
|
||||
sheet,
|
||||
}: {
|
||||
/**
|
||||
* Offenes Layout-Blatt: `level` ist dann dessen Blatt-Ebene (`layoutId`). Gezeichnet wird in
|
||||
* derselben Plan-Ansicht wie auf jeder Zeichnungsebene; das Blatt liefert nur den Hintergrund
|
||||
* (Papier, Master, Viewports) und das Platzieren der Viewports (ui/LayoutSheet.tsx).
|
||||
*/
|
||||
sheet?: { layout: Layout; handlers: LayoutSheetHandlers } | null;
|
||||
project: Project;
|
||||
level: DrawingLevel;
|
||||
viewType: ViewType;
|
||||
@@ -372,10 +382,11 @@ export function Content({
|
||||
// 3D-Umschaltung — eine Zeichnung hat keine Höhe/3D. So sind importierte
|
||||
// DXF-Polylinien hier sofort sichtbar und mit den 2D-Werkzeugen bearbeitbar.
|
||||
if (level.kind === "drawing") {
|
||||
return (
|
||||
<main className="content">
|
||||
<DrawingTabs project={project} handlers={viewSnapshotTabs} />
|
||||
// Blatt-Ebene eines offenen Layouts: Papier 1:1 (Massstab 1), Hintergrund + Viewports vom Blatt.
|
||||
const plan = (sheetPlan?: SheetPlanProps) => (
|
||||
<LevelPlanView
|
||||
backdrop={sheetPlan?.backdrop}
|
||||
fitBounds={sheetPlan?.fitBounds}
|
||||
project={project}
|
||||
level={level}
|
||||
visibleCodes={visibleCodes}
|
||||
@@ -383,7 +394,7 @@ export function Content({
|
||||
floorDisplay={floorDisplay}
|
||||
detail={detail}
|
||||
referenceLines={referenceLines}
|
||||
scaleDenominator={scaleDenominator}
|
||||
scaleDenominator={sheetPlan ? SHEET_SCALE_DENOMINATOR : scaleDenominator}
|
||||
hairline={hairline}
|
||||
showGrid={showGrid}
|
||||
marqueeColor={marqueeColor}
|
||||
@@ -417,7 +428,7 @@ export function Content({
|
||||
onCommitTextEdit={onCommitTextEdit}
|
||||
onCloseTextEdit={onCloseTextEdit}
|
||||
onOpenSectionLevel={onSelectLevel}
|
||||
onPlanSelect={onPlanSelect}
|
||||
onPlanSelect={sheetPlan?.onPlanSelect ?? onPlanSelect}
|
||||
onPlanMarquee={onPlanMarquee}
|
||||
onSegmentCut={onSegmentCut}
|
||||
onPlanContextMenu={onPlanContextMenu}
|
||||
@@ -432,6 +443,27 @@ export function Content({
|
||||
selectedDrawingIds={selectedDrawingIds}
|
||||
gripHandlers={gripHandlers}
|
||||
/>
|
||||
);
|
||||
if (level.layoutId && sheet && sheet.layout.id === level.layoutId) {
|
||||
return (
|
||||
<main className="content">
|
||||
<LayoutSheetPane
|
||||
project={project}
|
||||
layout={sheet.layout}
|
||||
handlers={sheet.handlers}
|
||||
toolInputActive={toolInputActive}
|
||||
onPlanSelect={onPlanSelect}
|
||||
planViewRef={planViewRef}
|
||||
>
|
||||
{plan}
|
||||
</LayoutSheetPane>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<main className="content">
|
||||
<DrawingTabs project={project} handlers={viewSnapshotTabs} />
|
||||
{plan()}
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -663,6 +695,8 @@ function useCrossKindOverlay(
|
||||
|
||||
/** Abgeleiteter Grundriss eines Geschosses. */
|
||||
function LevelPlanView({
|
||||
backdrop,
|
||||
fitBounds,
|
||||
project,
|
||||
level,
|
||||
visibleCodes,
|
||||
@@ -719,6 +753,10 @@ function LevelPlanView({
|
||||
selectedDrawingIds,
|
||||
gripHandlers,
|
||||
}: {
|
||||
/** Hintergrund unter der Zeichnung (Layout-Blatt), s. `PlanView.backdrop`. */
|
||||
backdrop?: SheetPlanProps["backdrop"];
|
||||
/** Einpass-Bereich statt der Plan-Grenzen (Layout-Blatt). */
|
||||
fitBounds?: SheetPlanProps["fitBounds"];
|
||||
project: Project;
|
||||
level: DrawingLevel;
|
||||
visibleCodes: Set<string>;
|
||||
@@ -913,6 +951,8 @@ function LevelPlanView({
|
||||
selectedDrawingId={selectedDrawingId}
|
||||
selectedDrawingIds={selectedDrawingIds}
|
||||
gripHandlers={gripHandlers}
|
||||
backdrop={backdrop}
|
||||
fitBounds={fitBounds}
|
||||
/>
|
||||
{/* NACH PlanView gerendert (nicht als box-shadow auf .pane), damit der
|
||||
Isolations-Rahmen über der PlanView-SVG sichtbar bleibt. */}
|
||||
|
||||
Reference in new issue
Block a user