diff --git a/src/commands/cmds/presentation.ts b/src/commands/cmds/presentation.ts new file mode 100644 index 00000000..164533dc --- /dev/null +++ b/src/commands/cmds/presentation.ts @@ -0,0 +1,29 @@ +// [66] Präsentationsplan — öffnet den Dialog (in App montiert) und endet sofort; das Blatt entsteht beim +// Bestätigen in einem Undo-Schritt (`state/presentationSheet.ts`). Muster wie `import`. + +import { openPresentationDialog } from "../../state/presentationSheetHook"; +import type { Command, CommandResult, CommandState } from "../types"; + +const IDLE: CommandState = { phase: "idle", lastPoint: null }; + +function open(): [CommandState, CommandResult] { + openPresentationDialog(); + return [{ ...IDLE }, { draft: null, done: true }]; +} + +export const presentationCommand: Command = { + name: "praesentation", + labelKey: "cmd.praesentation.label", + prompt: () => "cmd.praesentation.prompt", + accepts: () => [], + options: () => [], + init: () => ({ ...IDLE }), + autoRun: (): CommandResult => { + openPresentationDialog(); + return { draft: null, done: true }; + }, + onInput: () => open(), + onMove: (state): [CommandState, CommandResult] => [state, { draft: null }], + onConfirm: () => open(), + onCancel: (): [CommandState, CommandResult] => [{ ...IDLE }, { draft: null, done: true }], +}; diff --git a/src/commands/registry.ts b/src/commands/registry.ts index f03d8c4f..226196d8 100644 --- a/src/commands/registry.ts +++ b/src/commands/registry.ts @@ -71,6 +71,7 @@ import { sectionLineCommand, viewLineCommand } from "./cmds/sectionline"; import { georefCommand } from "./cmds/georef"; import { blockCommand } from "./cmds/block"; import { defblockCommand } from "./cmds/defblock"; +import { presentationCommand } from "./cmds/presentation"; /** Alle bekannten Befehle, Schlüssel = Befehlsname (lowercase). */ export const COMMANDS: Record = { @@ -140,6 +141,7 @@ export const COMMANDS: Record = { chamfer: chamferCommand, multiline: multilineCommand, import: importCommand, + praesentation: presentationCommand, terrain: terrainCommand, excavation: excavationCommand, measure: measureCommand, @@ -184,6 +186,9 @@ export const ALIASES: Record = { dachfenster: "roofwindow", oberlicht: "roofwindow", gaube: "dormer", + praesentationsplan: "praesentation", + präsentation: "praesentation", + presentation: "praesentation", lukarne: "dormer", dachhof: "roofhole", lichthof: "roofhole", diff --git a/src/core/document.ts b/src/core/document.ts index 7db4007a..319f76d0 100644 --- a/src/core/document.ts +++ b/src/core/document.ts @@ -123,6 +123,7 @@ export type RootQueryName = "penRebakeOps" | "penDeleteOps" | "penSeedOps" | "st /** Abfragen des Kerns (`queries.rs`). */ export type QueryName = | "surfaceOpening" + | "presentationSheet" | "kennzahlen" | "areaTable" | "programCompare" diff --git a/src/i18n/de.ts b/src/i18n/de.ts index b8c3e583..c1ae44dd 100644 --- a/src/i18n/de.ts +++ b/src/i18n/de.ts @@ -3275,6 +3275,25 @@ export const de = { "publish.empty": "Der Satz enthält keine Blätter.", "publish.done": "Publiziert (Dateien)", "publish.failed": "Publikation fehlgeschlagen", + "cmd.praesentation.label": "Präsentationsplan", + "cmd.praesentation.prompt": "Präsentationsplan einrichten …", + "presentation.title": "Präsentationsplan", + "presentation.button": "Präsentationsplan erstellen", + "presentation.floors": "Geschosse", + "presentation.elevations": "Ansichten", + "presentation.section": "Schnitt", + "presentation.noSection": "Kein Schnitt", + "presentation.sheet": "Blatt", + "presentation.sketch": "Skizzenstil (gezeigte Ebenen)", + "presentation.hint": "Der gemeinsame Massstab wird so gewählt, dass alles aufs Blatt passt; die Ausschnitte folgen der Vorlage „Präsentation“.", + "presentation.create": "Erstellen", + "presentation.sheetName": "Präsentationsplan", + "presentation.masterName": "Planrahmen {format}", + "presentation.north": "N", + "presentation.done": "Präsentationsplan 1:{scale} mit {n} Ansichten erstellt", + "presentation.tooBig": "Präsentationsplan: passt auch 1:{scale} nicht ganz aufs Blatt – grösseres Format wählen", + "presentation.empty": "Präsentationsplan: keine Ansicht mit Inhalt gewählt", + "presentation.failed": "Präsentationsplan konnte nicht erstellt werden", } as const; export type TranslationKey = keyof typeof de; diff --git a/src/i18n/en.ts b/src/i18n/en.ts index bd939648..99cf54c6 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -3261,4 +3261,23 @@ export const en: Record = { "publish.empty": "The set contains no sheets.", "publish.done": "Published (files)", "publish.failed": "Publishing failed", + "cmd.praesentation.label": "Presentation sheet", + "cmd.praesentation.prompt": "Set up presentation sheet …", + "presentation.title": "Presentation sheet", + "presentation.button": "Create presentation sheet", + "presentation.floors": "Floors", + "presentation.elevations": "Elevations", + "presentation.section": "Section", + "presentation.noSection": "No section", + "presentation.sheet": "Sheet", + "presentation.sketch": "Sketch style (shown views)", + "presentation.hint": "A common scale is chosen so that everything fits on the sheet; the views follow the “Presentation” template.", + "presentation.create": "Create", + "presentation.sheetName": "Presentation sheet", + "presentation.masterName": "Sheet frame {format}", + "presentation.north": "N", + "presentation.done": "Presentation sheet 1:{scale} with {n} views created", + "presentation.tooBig": "Presentation sheet: does not fully fit even at 1:{scale} – choose a larger format", + "presentation.empty": "Presentation sheet: no view with content chosen", + "presentation.failed": "Could not create the presentation sheet", }; diff --git a/src/plan/dbg66.test.ts b/src/plan/dbg66.test.ts new file mode 100644 index 00000000..85953833 --- /dev/null +++ b/src/plan/dbg66.test.ts @@ -0,0 +1,21 @@ +import { it } from "vitest"; +import { buildComplexSampleProject } from "../model/sampleProjectComplex"; +import { getState } from "../state/appStore"; +import { documentFor } from "../core/document"; +it("dbg", () => { + getState().loadProject(buildComplexSampleProject()); + const p = getState().project; + const codes: string[] = []; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const walk = (cs: any[]) => cs.forEach((c) => (codes.push(c.code + ":" + c.name), c.children && walk(c.children))); + walk(p.layers); + console.log(codes.join(" | ")); + const run = (hide: string[], lv: string) => { + const vis: Record = {}; + for (const c of codes) vis[c.split(":")[0]] = !hide.includes(c.split(":")[0]); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const r: any = documentFor(p).query("presentationSheet", [], JSON.stringify({ levels: [lv], groups: [0], layerVisibility: vis, detail: "mittel", sheetW: 841, sheetH: 594, titleBlock: true, shadows: true })); + return `${r.scale}:${Math.round(r.items[0]?.widthMm)}x${Math.round(r.items[0]?.heightMm)}`; + }; + for (const c of [[], ...codes.map((c) => [c.split(":")[0]])]) console.log("hide", c.join(), run(c, "eg"), run(c, "ansicht-sued")); +}); diff --git a/src/plan/presentationSheet.test.ts b/src/plan/presentationSheet.test.ts new file mode 100644 index 00000000..c07c6ad6 --- /dev/null +++ b/src/plan/presentationSheet.test.ts @@ -0,0 +1,85 @@ +import { beforeEach, describe, expect, it } from "vitest"; +import { buildComplexSampleProject } from "../model/sampleProjectComplex"; +import { getState } from "../state/appStore"; +import { sheetSizeMm } from "../model/layoutModel"; +import { PRESENTATION_TEMPLATE_ID, presentationDefaults, presentationSheetOps } from "./presentationSheet"; +import type { Project } from "../model/types"; + +const LABELS = { sheetName: "Präsentationsplan", masterName: "Planrahmen", north: "N" }; +const st = () => getState(); + +function overlaps(a: { xMm: number; yMm: number; widthMm: number; heightMm: number }, b: typeof a): boolean { + return a.xMm < b.xMm + b.widthMm && b.xMm < a.xMm + a.widthMm && a.yMm < b.yMm + b.heightMm && b.yMm < a.yMm + a.heightMm; +} + +describe("[66] Präsentationsplan", () => { + let project: Project; + beforeEach(() => { + st().loadProject(buildComplexSampleProject()); + st().clearHistory(); + project = st().project; + }); + + it("Vorschlag: alle Geschosse, Ansichten, ein Schnitt, A1 quer (Master)", () => { + const d = presentationDefaults(project); + expect(d.floors.length).toBeGreaterThanOrEqual(4); + expect(d.elevations).toBe(true); + expect(d.sectionId).not.toBeNull(); + expect([d.paper, d.orientation]).toEqual(["a1", "landscape"]); + expect(d.sketch).toBe(false); + }); + + it("ein Undo-Schritt: Blatt mit je einem Viewport pro Ebene, alle auf dem Blatt, ohne Überlappung", () => { + const o = presentationDefaults(project); + const elevations = project.drawingLevels.filter((l) => l.kind === "elevation").length; + const layoutsBefore = (project.layouts ?? []).length; + const res = presentationSheetOps(project, o, LABELS, "t1"); + expect(res).not.toBeNull(); + const { ops, layoutId, plan } = res!; + expect([50, 100, 200]).toContain(plan.scale); + expect(plan.fits).toBe(true); + st().applyChange(ops); + expect(st().undoDepth).toBe(1); + const p = st().project; + const lay = p.layouts!.find((l) => l.id === layoutId)!; + expect(lay.viewports.length).toBe(o.floors.length + elevations + 1); + expect(lay.masterId).toBeTruthy(); + const size = sheetSizeMm(lay.paper, lay.orientation); + for (const [i, v] of lay.viewports.entries()) { + expect(v.xMm).toBeGreaterThanOrEqual(0); + expect(v.yMm).toBeGreaterThanOrEqual(0); + expect(v.xMm + v.widthMm).toBeLessThanOrEqual(size.w); + expect(v.yMm + v.heightMm).toBeLessThanOrEqual(size.h); + expect(v.scaleDenominator).toBe(plan.scale); + for (const w of lay.viewports.slice(i + 1)) expect(overlaps(v, w)).toBe(false); + const snap = p.viewSnapshots!.find((s) => s.id === v.snapshotId)!; + expect(snap.templateId).toBe(PRESENTATION_TEMPLATE_ID); + expect(snap.templateLinked).toBe(true); + } + // Titel je Viewport + Nordpfeil auf der Blatt-Ebene. + const sheet = p.drawingLevels.find((l) => l.layoutId === layoutId)!; + const texts = p.drawings2d.filter((d) => d.levelId === sheet.id && d.geom.shape === "text"); + expect(texts.length).toBe(lay.viewports.length + 1); + // Skizze aus: Ebenen unverändert; Ansichten mit Schatten (Vorlage). + expect(p.drawingLevels.some((l) => l.sketch)).toBe(false); + expect(p.drawingLevels.filter((l) => l.kind === "elevation").every((l) => l.shadows)).toBe(true); + st().undo(); + expect((st().project.layouts ?? []).length).toBe(layoutsBefore); + expect(st().project.viewSnapshots?.some((s) => s.id.startsWith("vs-pres-"))).toBe(false); + }); + + it("gewählte Geschosse, ohne Ansichten/Schnitt, Skizze an, A3: kleinerer Massstab", () => { + const floors = project.drawingLevels.filter((l) => l.kind === "floor" && !l.layoutId).slice(0, 2).map((l) => l.id); + const res = presentationSheetOps(project, { floors, elevations: false, sectionId: null, paper: "a3", orientation: "landscape", sketch: true }, LABELS, "t2")!; + expect(res.plan.items.map((i) => i.levelId)).toEqual(floors); + expect(res.plan.scale).toBeGreaterThanOrEqual(100); + st().applyChange(res.ops); + const p = st().project; + expect(p.layouts!.find((l) => l.id === res.layoutId)!.viewports.length).toBe(2); + expect(floors.every((id) => p.drawingLevels.find((l) => l.id === id)!.sketch)).toBe(true); + }); + + it("nichts gewählt ⇒ null, Projekt unverändert", () => { + expect(presentationSheetOps(project, { floors: [], elevations: false, sectionId: null, paper: "a1", orientation: "landscape", sketch: false }, LABELS, "t3")).toBeNull(); + }); +}); diff --git a/src/plan/presentationSheet.ts b/src/plan/presentationSheet.ts new file mode 100644 index 00000000..4cff40db --- /dev/null +++ b/src/plan/presentationSheet.ts @@ -0,0 +1,256 @@ +// [66] Präsentationsplan mit einem Klick: neues Blatt mit den Grundrissen (alle oder gewählte Geschosse), +// den Ansichten und optional einem Schnitt, in gemeinsamem Massstab im Raster angeordnet, mit Titeln, +// Nordpfeil und Schriftfeld (Master), Ausschnitte an die Standard-Vorlage „Präsentation" gebunden. +// Massstabswahl und Anordnung rechnet der Kern (`presentation_sheet.rs`, Abfrage `presentationSheet`); +// hier entstehen daraus die Ops (ein Undo-Schritt beim Aufrufer). + +import type { + DetailLevel, + Drawing2D, + Drawing2DGeom, + DrawingLevel, + LayerCategory, + Layout, + LayoutOrientation, + LayoutPaperFormat, + LayoutViewport, + MasterLayout, + Project, + ViewSnapshot, + ViewTemplate, +} from "../model/types"; +import type { CoreOp } from "../core/ops"; +import { documentFor } from "../core/document"; +import { addedItems, addItems, patchItem } from "../core/opsBuild"; +import { standardsMergeOps } from "../model/standards"; +import { createLayout, createMasterLayout, createSheetLevel, sheetMmToModel, sheetSizeMm } from "../model/layoutModel"; + +/** Id der Standard-Ansichtsvorlage „Präsentation" (`standards.rs`). */ +export const PRESENTATION_TEMPLATE_ID = "std-vt-praesentation"; +/** Rand zwischen Inhalt und Rahmen (mm, wie `FRAME_PAD_MM` im Kern). */ +const FRAME_PAD_MM = 4; + +export interface PresentationOptions { + /** Geschosse (Ebenen der Art `floor`) in Blattreihenfolge. */ + floors: string[]; + /** Alle Ansichten (Ebenen der Art `elevation`) aufnehmen. */ + elevations: boolean; + /** Ein Schnitt (Ebene der Art `section`) oder keiner. */ + sectionId: string | null; + paper: LayoutPaperFormat; + orientation: LayoutOrientation; + /** Skizzenstil ([67]) für die gezeigten Ebenen. */ + sketch: boolean; +} + +export interface PresentationItem { + levelId: string; + group: number; + xMm: number; + yMm: number; + widthMm: number; + heightMm: number; +} + +export interface PresentationPlan { + scale: number; + fits: boolean; + items: PresentationItem[]; + skipped: string[]; +} + +/** Beschriftungen (vom Aufrufer über `t()`). */ +export interface PresentationLabels { + sheetName: string; + /** Name eines neu angelegten Masters, z. B. „Planrahmen A1 quer". */ + masterName: string; + north: string; +} + +const isFloor = (l: DrawingLevel) => l.kind === "floor" && !l.layoutId; + +/** Vorschlag für den Dialog: alle Geschosse, Ansichten, erster Schnitt; Blatt des meistgenutzten Masters, sonst A1 quer. */ +export function presentationDefaults(project: Project): PresentationOptions { + const levels = project.drawingLevels; + const masters = project.masterLayouts ?? []; + const uses = new Map(); + for (const l of project.layouts ?? []) if (l.masterId) uses.set(l.masterId, (uses.get(l.masterId) ?? 0) + 1); + const master = [...masters].sort((a, b) => (uses.get(b.id) ?? 0) - (uses.get(a.id) ?? 0))[0]; + const usable = master && !master.customWidthMm; + return { + floors: levels.filter(isFloor).map((l) => l.id), + elevations: levels.some((l) => l.kind === "elevation"), + sectionId: levels.find((l) => l.kind === "section")?.id ?? null, + paper: usable ? master.paper : "a1", + orientation: usable ? master.orientation : "landscape", + sketch: false, + }; +} + +/** Die Vorlage „Präsentation" des Projekts bzw. aus den Standards (dann muss sie mit angelegt werden). */ +export function presentationTemplate(project: Project): { template: ViewTemplate; isNew: boolean } { + const own = (project.viewTemplates ?? []).find((t) => t.id === PRESENTATION_TEMPLATE_ID); + if (own) return { template: own, isNew: false }; + const std = (addedItems(standardsMergeOps(project), "viewTemplates") as ViewTemplate[]).find((t) => t.id === PRESENTATION_TEMPLATE_ID); + return { + template: std ?? { id: PRESENTATION_TEMPLATE_ID, name: "Präsentation", detail: "mittel", mono: false, shadows: true, hiddenLines: false }, + isNew: true, + }; +} + +function categoryCodes(cats: readonly LayerCategory[], out: string[] = []): string[] { + for (const c of cats) { + out.push(c.code); + if (c.children) categoryCodes(c.children, out); + } + return out; +} + +/** Sichtbarkeit nach Vorlage: alle Kategorien sichtbar, ausser die von der Vorlage ausgeblendeten. */ +function templateVisibility(project: Project, t: ViewTemplate): Record { + const vis: Record = {}; + for (const c of categoryCodes(project.layers)) vis[c] = true; + return { ...vis, ...(t.layerVisibility ?? {}) }; +} + +/** Die gewählten Ebenen in Blattreihenfolge mit Gruppe (0 Grundrisse, 1 Ansichten, 2 Schnitt). */ +function chosenLevels(project: Project, o: PresentationOptions): { id: string; group: number }[] { + const byId = new Map(project.drawingLevels.map((l) => [l.id, l])); + const out: { id: string; group: number }[] = []; + for (const id of o.floors) if (byId.get(id) && isFloor(byId.get(id)!)) out.push({ id, group: 0 }); + if (o.elevations) for (const l of project.drawingLevels) if (l.kind === "elevation") out.push({ id: l.id, group: 1 }); + if (o.sectionId && byId.get(o.sectionId)?.kind === "section") out.push({ id: o.sectionId, group: 2 }); + return out; +} + +/** Master des Blatts: einer mit gleichem Format und gleicher Ausrichtung, sonst ein neuer. */ +function masterFor(project: Project, o: PresentationOptions): MasterLayout | undefined { + return (project.masterLayouts ?? []).find( + (m) => m.paper === o.paper && m.orientation === o.orientation && m.customWidthMm === undefined, + ); +} + +/** Massstab und Rahmen aus dem Kern (ohne das Projekt zu ändern). */ +export function planPresentationSheet(project: Project, o: PresentationOptions): PresentationPlan { + const { template } = presentationTemplate(project); + const size = sheetSizeMm(o.paper, o.orientation); + const levels = chosenLevels(project, o); + const text = JSON.stringify({ + levels: levels.map((l) => l.id), + groups: levels.map((l) => l.group), + layerVisibility: templateVisibility(project, template), + detail: (template.detail ?? "mittel") satisfies DetailLevel, + sheetW: size.w, + sheetH: size.h, + titleBlock: true, + shadows: template.shadows ?? false, + }); + return documentFor(project).query("presentationSheet", [], text); +} + +/** Text auf der Blatt-Ebene (Papier-mm, Schrifthöhe mm). */ +function sheetText(id: string, levelId: string, cat: string, xMm: number, yMm: number, text: string, hMm: number, bold = false): Drawing2D { + return { + id, + type: "drawing2d", + levelId, + categoryCode: cat, + geom: { shape: "text", at: sheetMmToModel(xMm, yMm), text, height: hMm / 1000, angle: 0, ...(bold ? { marks: { bold: true } } : {}) }, + color: "#111111", + } as Drawing2D; +} + +function sheetShape(id: string, levelId: string, cat: string, geom: Drawing2DGeom, extra: Partial = {}): Drawing2D { + return { id, type: "drawing2d", levelId, categoryCode: cat, geom, color: "#111111", weightMm: 0.25, ...extra } as Drawing2D; +} + +/** Nordpfeil (Norden = +y im Modell, Grundrisse sind nicht gedreht): Kreis, halb gefüllte Spitze, „N". */ +function northArrow(stamp: string, levelId: string, cat: string, cx: number, cy: number, r: number, north: string): Drawing2D[] { + const P = (x: number, y: number) => sheetMmToModel(cx + x, cy + y); + return [ + sheetShape(`d-pres-${stamp}-n0`, levelId, cat, { shape: "circle", center: P(0, 0), r: r / 1000 }), + sheetShape(`d-pres-${stamp}-n1`, levelId, cat, { shape: "polyline", closed: true, pts: [P(0, -r), P(r * 0.45, r * 0.75), P(0, r * 0.35)] }, { fillColor: "#111111" }), + sheetShape(`d-pres-${stamp}-n2`, levelId, cat, { shape: "polyline", closed: true, pts: [P(0, -r), P(0, r * 0.35), P(-r * 0.45, r * 0.75)] }), + sheetText(`d-pres-${stamp}-n3`, levelId, cat, cx - r - 4, cy + 1.4, north, r * 0.8, true), + ]; +} + +/** Kategorie für Titel und Nordpfeil: „Text"/„Beschriftung", sonst die erste. */ +function annotationCategory(project: Project): string { + const all: LayerCategory[] = []; + const walk = (cs: readonly LayerCategory[]) => cs.forEach((c) => (all.push(c), c.children && walk(c.children))); + walk(project.layers); + return (all.find((c) => /beschrift|text|annot/i.test(c.name)) ?? all.find((c) => c.code === "80") ?? all[0])?.code ?? "0"; +} + +/** + * Ops für das Präsentationsblatt (ein Undo-Schritt, wenn sie zusammen angewendet werden): Layout mit + * Blatt-Ebene und Master (neu, falls keiner zum Format passt), je Ebene ein an „Präsentation" gebundener + * Ausschnitt und ein Viewport, Titel und Nordpfeil auf der Blatt-Ebene, Schatten/Skizze an den Ebenen. + * `stamp` macht die Ids eindeutig. Keine Ebene mit Inhalt ⇒ `null`. + */ +export function presentationSheetOps( + project: Project, + o: PresentationOptions, + labels: PresentationLabels, + stamp: string, +): { ops: CoreOp[]; layoutId: string; plan: PresentationPlan } | null { + const plan = planPresentationSheet(project, o); + if (plan.items.length === 0) return null; + const { template, isNew } = presentationTemplate(project); + const ops: CoreOp[] = []; + if (isNew) ops.push(...addItems("viewTemplates", [template])); + let master = masterFor(project, o); + if (!master) { + const first = (project.masterLayouts ?? [])[0]; + master = { ...createMasterLayout(`mas-pres-${stamp}`, labels.masterName, o.paper, o.orientation), titleBlock: { ...(first?.titleBlock ?? {}) } }; + ops.push(...addItems("masterLayouts", [master])); + } + const layoutId = `lay-pres-${stamp}`; + const layout: Layout = { ...createLayout(layoutId, labels.sheetName, o.paper, o.orientation), masterId: master.id }; + const sheetLevel = createSheetLevel(`sheet-${layoutId}`, layout); + const vis = templateVisibility(project, template); + const cat = annotationCategory(project); + const byId = new Map(project.drawingLevels.map((l) => [l.id, l])); + const snaps: ViewSnapshot[] = []; + const vps: LayoutViewport[] = []; + const drawings: Drawing2D[] = []; + plan.items.forEach((it, i) => { + const level = byId.get(it.levelId)!; + const snapId = `vs-pres-${stamp}-${i}`; + snaps.push({ + id: snapId, + name: `${level.name} · ${template.name}`, + viewType: "grundriss", + view3d: "top", + scaleDenominator: plan.scale, + detail: template.detail ?? "mittel", + activeLevelId: level.id, + layerVisibility: vis, + drawingVisibility: {}, + ...(template.enabledOverrideRuleIds ? { enabledOverrideRuleIds: [...template.enabledOverrideRuleIds] } : {}), + templateId: template.id, + templateLinked: true, + } as ViewSnapshot); + vps.push({ id: `vp-pres-${stamp}-${i}`, snapshotId: snapId, xMm: it.xMm, yMm: it.yMm, widthMm: it.widthMm, heightMm: it.heightMm, scaleDenominator: plan.scale }); + drawings.push( + sheetText(`d-pres-${stamp}-t${i}`, sheetLevel.id, cat, it.xMm + FRAME_PAD_MM, it.yMm + it.heightMm + 6, `${level.name} 1:${plan.scale}`, 4, true), + ); + }); + // Nordpfeil rechts neben dem Titel des ersten Grundrisses. + const firstFloor = plan.items.find((it) => it.group === 0); + if (firstFloor) { + drawings.push(...northArrow(stamp, sheetLevel.id, cat, firstFloor.xMm + firstFloor.widthMm - 8, firstFloor.yMm + firstFloor.heightMm + 4.8, 3.6, labels.north)); + } + ops.push(...addItems("layouts", [{ ...layout, viewports: vps }]), ...addItems("drawingLevels", [sheetLevel])); + ops.push(...addItems("viewSnapshots", snaps), ...addItems("drawings2d", drawings)); + // Schatten (Vorlage) für Ansichten/Schnitt, Skizze nach Wahl für alle gezeigten Ebenen. + for (const it of plan.items) { + const level = byId.get(it.levelId)!; + const patch: Partial = {}; + if (it.group > 0 && template.shadows !== undefined && level.shadows !== template.shadows) patch.shadows = template.shadows; + if (o.sketch && !level.sketch) patch.sketch = true; + if (Object.keys(patch).length > 0) ops.push(...patchItem(project, "drawingLevels", level.id, patch)); + } + return { ops, layoutId, plan }; +} diff --git a/src/state/presentationSheet.ts b/src/state/presentationSheet.ts new file mode 100644 index 00000000..a547c3e8 --- /dev/null +++ b/src/state/presentationSheet.ts @@ -0,0 +1,30 @@ +// [66] Präsentationsplan anlegen: Ops aus dem Kern-Fassadenteil (`plan/presentationSheet.ts`), angewendet +// als EIN Undo-Schritt, Meldung über `notify`. Liefert die Id des neuen Blatts (zum Öffnen) oder `null`. + +import { presentationSheetOps, type PresentationOptions } from "../core"; +import { t } from "../i18n"; +import { getState } from "./appStore"; + +export function createPresentationSheet(o: PresentationOptions): string | null { + const st = getState(); + try { + const format = `${o.paper.toUpperCase()} ${o.orientation === "landscape" ? t("layouts.landscape") : t("layouts.portrait")}`; + const res = presentationSheetOps( + st.project, + o, + { sheetName: t("presentation.sheetName"), masterName: t("presentation.masterName", { format }), north: t("presentation.north") }, + String(Date.now()), + ); + if (!res) { + st.notify(t("presentation.empty"), "warning"); + return null; + } + st.applyChange(res.ops); + if (res.plan.fits) st.notify(t("presentation.done", { scale: res.plan.scale, n: res.plan.items.length }), "info"); + else st.notify(t("presentation.tooBig", { scale: res.plan.scale }), "warning"); + return res.layoutId; + } catch (e) { + st.notify(`${t("presentation.failed")}: ${e instanceof Error ? e.message : String(e)}`, "error"); + return null; + } +} diff --git a/src/state/presentationSheetHook.ts b/src/state/presentationSheetHook.ts new file mode 100644 index 00000000..6e6ecb0a --- /dev/null +++ b/src/state/presentationSheetHook.ts @@ -0,0 +1,14 @@ +// [66] Modul-Hook: App registriert den Öffner des Präsentationsplan-Dialogs; Befehl `praesentation` und +// der Knopf im Layouts-Panel rufen ihn auf, ohne an React/App gekoppelt zu sein (Muster `io/dxfImportHook`). + +let opener: (() => void) | null = null; + +/** App registriert hier den Öffner (oder hebt ihn beim Unmount auf). */ +export function setPresentationDialogOpener(fn: (() => void) | null): void { + opener = fn; +} + +/** Öffnet den Dialog „Präsentationsplan", falls App ihn registriert hat. */ +export function openPresentationDialog(): void { + opener?.(); +}