[66] Präsentationsplan: Dialog, Knopf im Layouts-Panel, Massstabsbalken, Fassade, Tests
This commit is contained in:
7 files changed
+279
-4
No files matched your search
@@ -33,6 +33,7 @@ import { programStatusLabel } from "./panels/KennzahlenSection";
|
||||
import { sectionPlaneFromLevel, sectionUAxisModel } from "./core";
|
||||
import { setDxfImportTrigger } from "./io/dxfImportHook";
|
||||
import { ImportDialog } from "./ui/ImportDialog";
|
||||
import { PresentationDialogHost } from "./ui/PresentationDialog";
|
||||
import { BusyOverlay } from "./ui/BusyOverlay";
|
||||
import { ExportPdfDialog } from "./ui/ExportPdfDialog";
|
||||
import { ExportDxfDialog } from "./ui/ExportDxfDialog";
|
||||
@@ -2666,6 +2667,8 @@ export default function App() {
|
||||
{/* Modaler Import-Dialog (DXF/DWG) — offen, sobald eine Datei gewählt/
|
||||
fallengelassen wurde. Liefert eine strukturierte Entscheidung an
|
||||
runImport (Ebene anlegen / Drawings anhängen / Meshes als Kontext). */}
|
||||
{/* [66] Präsentationsplan: Dialog (Befehl `praesentation`, Knopf im Layouts-Panel) */}
|
||||
<PresentationDialogHost onCreated={setActiveLayoutId} />
|
||||
{importState && (
|
||||
<ImportDialog
|
||||
fileName={importState.fileName}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
import { COMMANDS, ALIASES } from "../registry";
|
||||
import { setPresentationDialogOpener } from "../../state/presentationSheetHook";
|
||||
import { createPresentationSheet } from "../../state/presentationSheet";
|
||||
import { getState } from "../../state/appStore";
|
||||
import { buildComplexSampleProject } from "../../model/sampleProjectComplex";
|
||||
import { presentationDefaults } from "../../core";
|
||||
|
||||
describe("[66] Befehl praesentation", () => {
|
||||
beforeEach(() => {
|
||||
getState().loadProject(buildComplexSampleProject());
|
||||
getState().clearHistory();
|
||||
});
|
||||
|
||||
it("Aliase führen auf den Befehl, der den Dialog öffnet", () => {
|
||||
expect(ALIASES.praesentationsplan).toBe("praesentation");
|
||||
expect(ALIASES.presentation).toBe("praesentation");
|
||||
let opened = 0;
|
||||
setPresentationDialogOpener(() => opened++);
|
||||
const res = COMMANDS.praesentation.autoRun!({} as never);
|
||||
expect(res.done).toBe(true);
|
||||
expect(opened).toBe(1);
|
||||
setPresentationDialogOpener(null);
|
||||
});
|
||||
|
||||
it("Bestätigen legt das Blatt in EINEM Undo-Schritt an", () => {
|
||||
const before = getState().project;
|
||||
const o = presentationDefaults(before);
|
||||
const id = createPresentationSheet({ ...o, sketch: true });
|
||||
expect(id).toBeTruthy();
|
||||
const p = getState().project;
|
||||
const lay = p.layouts!.find((l) => l.id === id)!;
|
||||
expect(lay.viewports.length).toBeGreaterThanOrEqual(o.floors.length);
|
||||
expect(p.drawingLevels.some((l) => l.sketch)).toBe(true);
|
||||
expect(getState().undoDepth).toBe(1);
|
||||
getState().undo();
|
||||
const q = getState().project;
|
||||
expect(q.layouts?.some((l) => l.id === id)).toBe(false);
|
||||
expect(q.drawingLevels.some((l) => l.sketch)).toBe(false);
|
||||
expect(q.drawingLevels.length).toBe(before.drawingLevels.length);
|
||||
});
|
||||
});
|
||||
@@ -82,3 +82,5 @@ export { AI_TOOLS, AI_BRIDGE_DEFAULT_PORT, aiText, aiToolDef, hmacHex, randomHex
|
||||
export type { AiToolDef, AiToolResult, AiBridgeMsg } from "./aiToolDefs";
|
||||
export { callAiTool } from "./aiTools";
|
||||
export type { AiHost } from "./aiTools";
|
||||
export { PRESENTATION_TEMPLATE_ID, presentationDefaults, presentationSheetOps, planPresentationSheet } from "../plan/presentationSheet";
|
||||
export type { PresentationOptions, PresentationPlan, PresentationLabels } from "../plan/presentationSheet";
|
||||
@@ -34,6 +34,7 @@ import {
|
||||
type LayoutSizeStart,
|
||||
type NewLayoutStart,
|
||||
} from "../ui/LayoutCreateDialogs";
|
||||
import { openPresentationDialog } from "../state/presentationSheetHook";
|
||||
import { PublishSection } from "./PublishSection";
|
||||
import { t } from "../i18n";
|
||||
|
||||
@@ -809,6 +810,15 @@ export function LayoutsPanel() {
|
||||
>
|
||||
<PlusIcon />
|
||||
</button>
|
||||
<button
|
||||
className="nav-add"
|
||||
data-testid="presentation-open"
|
||||
style={{ display: "inline-flex", padding: "1px 5px" }}
|
||||
title={t("presentation.button")}
|
||||
onClick={openPresentationDialog}
|
||||
>
|
||||
<PresentationIcon />
|
||||
</button>
|
||||
</span>
|
||||
</header>
|
||||
|
||||
@@ -913,3 +923,15 @@ export function LayoutsTabIcon() {
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
/** [66] Symbol „Präsentationsplan" — Blatt mit vier Ausschnitten. */
|
||||
function PresentationIcon() {
|
||||
return (
|
||||
<svg width={13} height={13} viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth={1.3} aria-hidden="true">
|
||||
<rect x={1.5} y={2.5} width={13} height={11} rx={1} />
|
||||
<rect x={3.5} y={4.5} width={4} height={3} />
|
||||
<rect x={8.5} y={4.5} width={4} height={3} />
|
||||
<rect x={3.5} y={9} width={9} height={2.5} />
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
@@ -56,10 +56,18 @@ describe("[66] Präsentationsplan", () => {
|
||||
expect(snap.templateId).toBe(PRESENTATION_TEMPLATE_ID);
|
||||
expect(snap.templateLinked).toBe(true);
|
||||
}
|
||||
// Titel je Viewport + Nordpfeil auf der Blatt-Ebene.
|
||||
// Titel je Viewport + Nordpfeil + Massstabsbalken (2 Beschriftungen) 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);
|
||||
const onSheet = p.drawings2d.filter((d) => d.levelId === sheet.id);
|
||||
const texts = onSheet.filter((d) => d.geom.shape === "text");
|
||||
expect(texts.length).toBe(lay.viewports.length + 1 + 2);
|
||||
expect(onSheet.filter((d) => /-s\d$/.test(d.id) && d.geom.shape === "polyline").length).toBe(5);
|
||||
// Titel und Balken liegen auf dem Blatt.
|
||||
for (const d of onSheet) if (d.geom.shape === "text") {
|
||||
expect(d.geom.at.x * 1000).toBeGreaterThan(0);
|
||||
expect(d.geom.at.x * 1000).toBeLessThan(size.w);
|
||||
expect(-d.geom.at.y * 1000).toBeLessThan(size.h);
|
||||
}
|
||||
// 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);
|
||||
|
||||
@@ -175,6 +175,33 @@ function northArrow(stamp: string, levelId: string, cat: string, cx: number, cy:
|
||||
];
|
||||
}
|
||||
|
||||
/** Massstabsbalken-Längen (Modell-Meter), kleinste zuerst. */
|
||||
const SCALEBAR_TOTALS = [1, 2, 5, 10, 20, 50, 100, 200];
|
||||
|
||||
/**
|
||||
* Massstabsbalken auf der Blatt-Ebene (Papier-mm): fünf abwechselnd gefüllte Felder, rechtes Ende bei `rightMm`,
|
||||
* Mitte bei `cyMm`; Gesamtlänge die grösste runde Länge bis 50 mm auf dem Papier. Ein Massstabsbalken-Element
|
||||
* (`shape: "scalebar"`) passt nicht, weil die Blatt-Ebene 1:1 in Papier-mm rechnet.
|
||||
*/
|
||||
export function scaleBar(stamp: string, levelId: string, cat: string, rightMm: number, cyMm: number, scale: number): Drawing2D[] {
|
||||
const total = [...SCALEBAR_TOTALS].reverse().find((m) => (m * 1000) / scale <= 50) ?? SCALEBAR_TOTALS[0];
|
||||
const len = (total * 1000) / scale;
|
||||
const n = 5;
|
||||
const h = 1.6;
|
||||
const x0 = rightMm - len;
|
||||
const out: Drawing2D[] = [];
|
||||
for (let i = 0; i < n; i++) {
|
||||
const a = x0 + (len * i) / n;
|
||||
const b = x0 + (len * (i + 1)) / n;
|
||||
const pts = [sheetMmToModel(a, cyMm - h / 2), sheetMmToModel(b, cyMm - h / 2), sheetMmToModel(b, cyMm + h / 2), sheetMmToModel(a, cyMm + h / 2)];
|
||||
out.push(sheetShape(`d-pres-${stamp}-s${i}`, levelId, cat, { shape: "polyline", closed: true, pts }, { weightMm: 0.18, ...(i % 2 === 0 ? { fillColor: "#111111" } : {}) }));
|
||||
}
|
||||
out.push(sheetText(`d-pres-${stamp}-s${n}`, levelId, cat, x0 - 0.6, cyMm + h / 2 + 2.6, "0", 2));
|
||||
const label = `${total} m`;
|
||||
out.push(sheetText(`d-pres-${stamp}-s${n + 1}`, levelId, cat, rightMm - label.length * 1.2, cyMm + h / 2 + 2.6, label, 2));
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Kategorie für Titel und Nordpfeil: „Text"/„Beschriftung", sonst die erste. */
|
||||
function annotationCategory(project: Project): string {
|
||||
const all: LayerCategory[] = [];
|
||||
@@ -240,7 +267,15 @@ export function presentationSheetOps(
|
||||
// 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));
|
||||
const cx = firstFloor.xMm + firstFloor.widthMm - 8;
|
||||
const cy = firstFloor.yMm + firstFloor.heightMm + 4.8;
|
||||
drawings.push(...northArrow(stamp, sheetLevel.id, cat, cx, cy, 3.6, labels.north));
|
||||
// Massstabsbalken links vom Nordpfeil, sofern er den Titel nicht berührt (Breite grob 0.65 × Schrifthöhe je Zeichen).
|
||||
const bar = scaleBar(stamp, sheetLevel.id, cat, cx - 3.6 - 10, cy - 1, plan.scale);
|
||||
const title = byId.get(firstFloor.levelId)!.name;
|
||||
const titleEnd = firstFloor.xMm + FRAME_PAD_MM + (title.length + 8) * 4 * 0.65;
|
||||
const barLeft = Math.min(...bar.flatMap((d) => (d.geom.shape === "polyline" ? d.geom.pts.map((p) => p.x * 1000) : [])));
|
||||
if (barLeft - 6 > titleEnd) drawings.push(...bar);
|
||||
}
|
||||
ops.push(...addItems("layouts", [{ ...layout, viewports: vps }]), ...addItems("drawingLevels", [sheetLevel]));
|
||||
ops.push(...addItems("viewSnapshots", snaps), ...addItems("drawings2d", drawings));
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
// [66] Dialog „Präsentationsplan": Geschosse, Ansichten/Schnitt, Blattformat, Skizzenstil. Registriert sich
|
||||
// selbst als Öffner (`state/presentationSheetHook`), damit Befehl `praesentation` und der Knopf im
|
||||
// Layouts-Panel ihn öffnen. Beim Bestätigen entsteht das Blatt in EINEM Undo-Schritt
|
||||
// (`state/presentationSheet.ts`); `onCreated` öffnet es. Overlay wie `LayoutCreateDialogs` (kein window.prompt).
|
||||
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { t } from "../i18n";
|
||||
import { presentationDefaults, type PresentationOptions } from "../core";
|
||||
import type { LayoutOrientation, LayoutPaperFormat } from "../model/types";
|
||||
import { PAPER_FORMAT_GROUPS } from "../model/layoutModel";
|
||||
import { getState, useStore } from "../state/appStore";
|
||||
import { setPresentationDialogOpener } from "../state/presentationSheetHook";
|
||||
import { createPresentationSheet } from "../state/presentationSheet";
|
||||
|
||||
export function PresentationDialogHost({ onCreated }: { onCreated: (layoutId: string) => void }) {
|
||||
const [opts, setOpts] = useState<PresentationOptions | null>(null);
|
||||
const project = useStore((s) => s.project);
|
||||
|
||||
useEffect(() => {
|
||||
setPresentationDialogOpener(() => setOpts(presentationDefaults(getState().project)));
|
||||
return () => setPresentationDialogOpener(null);
|
||||
}, []);
|
||||
|
||||
const close = useCallback(() => setOpts(null), []);
|
||||
const confirm = useCallback(() => {
|
||||
if (!opts) return;
|
||||
const id = createPresentationSheet(opts);
|
||||
setOpts(null);
|
||||
if (id) onCreated(id);
|
||||
}, [opts, onCreated]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!opts) return;
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.key === "Escape") close();
|
||||
else if (e.key === "Enter") confirm();
|
||||
};
|
||||
window.addEventListener("keydown", onKey);
|
||||
return () => window.removeEventListener("keydown", onKey);
|
||||
}, [opts, close, confirm]);
|
||||
|
||||
if (!opts) return null;
|
||||
const floors = project.drawingLevels.filter((l) => l.kind === "floor" && !l.layoutId);
|
||||
const sections = project.drawingLevels.filter((l) => l.kind === "section");
|
||||
const hasElevations = project.drawingLevels.some((l) => l.kind === "elevation");
|
||||
const set = (patch: Partial<PresentationOptions>) => setOpts({ ...opts, ...patch });
|
||||
const toggleFloor = (id: string, on: boolean) =>
|
||||
// Blattreihenfolge = Reihenfolge der Geschosse im Projekt.
|
||||
set({ floors: floors.map((f) => f.id).filter((f) => (f === id ? on : opts.floors.includes(f))) });
|
||||
const empty = opts.floors.length === 0 && !(opts.elevations && hasElevations) && !opts.sectionId;
|
||||
|
||||
return (
|
||||
<div className="imp-overlay" onClick={close}>
|
||||
<div
|
||||
className="imp-dialog presentation-dialog"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-label={t("presentation.title")}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<header className="imp-head">
|
||||
<span className="imp-head-title">{t("presentation.title")}</span>
|
||||
<button className="imp-close" onClick={close} aria-label={t("export.close")}>
|
||||
×
|
||||
</button>
|
||||
</header>
|
||||
<div className="imp-body">
|
||||
<section className="imp-section">
|
||||
<div className="imp-section-title">{t("presentation.floors")}</div>
|
||||
{floors.map((f) => (
|
||||
<label key={f.id} className="imp-check" style={{ display: "flex", gap: 6, alignItems: "center" }}>
|
||||
<input
|
||||
type="checkbox"
|
||||
data-floor={f.id}
|
||||
checked={opts.floors.includes(f.id)}
|
||||
onChange={(e) => toggleFloor(f.id, e.target.checked)}
|
||||
/>
|
||||
{f.name}
|
||||
</label>
|
||||
))}
|
||||
</section>
|
||||
<section className="imp-section">
|
||||
<label className="imp-check" style={{ display: "flex", gap: 6, alignItems: "center" }}>
|
||||
<input
|
||||
type="checkbox"
|
||||
data-testid="presentation-elevations"
|
||||
disabled={!hasElevations}
|
||||
checked={opts.elevations && hasElevations}
|
||||
onChange={(e) => set({ elevations: e.target.checked })}
|
||||
/>
|
||||
{t("presentation.elevations")}
|
||||
</label>
|
||||
</section>
|
||||
<section className="imp-section">
|
||||
<div className="imp-section-title">{t("presentation.section")}</div>
|
||||
<select
|
||||
className="imp-select"
|
||||
data-testid="presentation-section"
|
||||
value={opts.sectionId ?? ""}
|
||||
onChange={(e) => set({ sectionId: e.target.value || null })}
|
||||
>
|
||||
<option value="">{t("presentation.noSection")}</option>
|
||||
{sections.map((s) => (
|
||||
<option key={s.id} value={s.id}>
|
||||
{s.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</section>
|
||||
<section className="imp-section">
|
||||
<div className="imp-section-title">{t("presentation.sheet")}</div>
|
||||
<div style={{ display: "flex", gap: 8, alignItems: "center" }}>
|
||||
<select
|
||||
className="imp-select"
|
||||
data-testid="presentation-paper"
|
||||
value={opts.paper}
|
||||
onChange={(e) => set({ paper: e.target.value as LayoutPaperFormat })}
|
||||
>
|
||||
{PAPER_FORMAT_GROUPS.flatMap((g) => g.formats).map((f) => (
|
||||
<option key={f} value={f}>
|
||||
{f.toUpperCase()}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<div className="imp-seg">
|
||||
{(["portrait", "landscape"] as LayoutOrientation[]).map((o) => (
|
||||
<button
|
||||
key={o}
|
||||
type="button"
|
||||
className={`imp-seg-btn${opts.orientation === o ? " active" : ""}`}
|
||||
onClick={() => set({ orientation: o })}
|
||||
>
|
||||
{o === "portrait" ? t("layouts.portrait") : t("layouts.landscape")}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section className="imp-section">
|
||||
<label className="imp-check" style={{ display: "flex", gap: 6, alignItems: "center" }}>
|
||||
<input
|
||||
type="checkbox"
|
||||
data-testid="presentation-sketch"
|
||||
checked={opts.sketch}
|
||||
onChange={(e) => set({ sketch: e.target.checked })}
|
||||
/>
|
||||
{t("presentation.sketch")}
|
||||
</label>
|
||||
</section>
|
||||
<p style={{ fontSize: 11, color: "var(--muted)", margin: "4px 0 0" }}>{t("presentation.hint")}</p>
|
||||
</div>
|
||||
<footer className="imp-foot">
|
||||
<button className="imp-btn" onClick={close}>
|
||||
{t("export.cancel")}
|
||||
</button>
|
||||
<button className="imp-btn primary" data-testid="presentation-create" disabled={empty} onClick={confirm}>
|
||||
{t("presentation.create")}
|
||||
</button>
|
||||
</footer>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user