Merge [282] PDF-Ebenen in Plan-Reihenfolge, Präsentationsplan schlägt passenden Massstab vor
This commit is contained in:
12 files changed
+157
-15
No files matched your search
+1
-1
@@ -100,7 +100,7 @@ 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_SCALES, POSTER_EXTRAS_DEFAULT, POSTER_SITUATION_SCALE, PRESENTATION_DEFAULT_SCALE, levelHasContent, PRESENTATION_TEMPLATE_ID, presentationDefaults, presentationSheetOps, planPresentationSheet } from "../plan/presentationSheet";
|
||||
export { PRESENTATION_SCALES, POSTER_EXTRAS_DEFAULT, POSTER_SITUATION_SCALE, PRESENTATION_DEFAULT_SCALE, levelHasContent, PRESENTATION_TEMPLATE_ID, presentationDefaults, presentationSheetOps, planPresentationSheet, fittingPresentationScale } from "../plan/presentationSheet";
|
||||
export type { PresentationOptions, PosterExtras, PosterTableKind, PresentationPlan, PresentationLabels } from "../plan/presentationSheet";
|
||||
export { lineEndsOf, lineEndsCode, lineEndsFromCode, lineEndsSvgAttrs, planLineEndsProps, MITER_LIMIT as LINE_MITER_LIMIT } from "../model/lineEnds";
|
||||
export type { LineEnds } from "../model/lineEnds";
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
// [282] PDF-Ebenen: die Stapelung (Zeichenreihenfolge) des ganzen Plans bleibt erhalten. Befund: Decken-Füllung
|
||||
// (Kategorie 30, im Plan UNTER den Wänden) lag als Ebene nach „Wände" (20) und deckte sie im Erdgeschoss weiss zu.
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildWettbewerbSampleProject } from "../model/sampleProjectWettbewerb";
|
||||
import { visibleCodesFromSnapshot } from "../model/layoutModel";
|
||||
import { getState } from "../state/appStore";
|
||||
import { presentationDefaults, presentationSheetOps } from "../plan/presentationSheet";
|
||||
import { viewportSnapshotPlan } from "../plan/viewportPlan";
|
||||
import type { Plan } from "../plan/generatePlan";
|
||||
import { categoryLayerGroups, layerRunsInPlanOrder } from "./pdfLayers";
|
||||
|
||||
const LABELS = { sheetName: "P", masterName: "M", north: "N", northGroup: "N", scaleBarGroup: "S", situation: "S", tableAreas: "A", tableSiteProof: "B", imagePlaceholder: "I", imageHint: "H" };
|
||||
|
||||
const poly = (x: number): Plan["primitives"][number] =>
|
||||
({ kind: "polygon", pts: [{ x, y: 0 }, { x: x + 1, y: 0 }, { x: x + 1, y: 1 }], fill: "#fff", stroke: "#000", strokeWidthMm: 0.1, hatch: {} }) as never;
|
||||
|
||||
describe("layerRunsInPlanOrder", () => {
|
||||
it("bildet Läufe in der Reihenfolge des ganzen Plans (Decke zuerst, dann Wand, dann Raum)", () => {
|
||||
const [d, w, r] = [poly(1), poly(2), poly(3)];
|
||||
const b = { minX: 0, minY: 0, maxX: 5, maxY: 5 };
|
||||
const full: Plan = { primitives: [d, w, r], bounds: b };
|
||||
const groups: { name: string; plan: Plan }[] = [
|
||||
{ name: "Wände", plan: { primitives: [w], bounds: b } },
|
||||
{ name: "Decken", plan: { primitives: [d], bounds: b } },
|
||||
{ name: "Räume", plan: { primitives: [r], bounds: b } },
|
||||
];
|
||||
expect(layerRunsInPlanOrder(full, groups).map((x) => x.name)).toEqual(["Decken", "Wände", "Räume"]);
|
||||
});
|
||||
|
||||
it("verschränkte Gruppen ergeben mehrere Läufe, nichts geht verloren oder doppelt", () => {
|
||||
const p = [poly(1), poly(2), poly(3), poly(4)];
|
||||
const b = { minX: 0, minY: 0, maxX: 5, maxY: 5 };
|
||||
const groups: { name: string; plan: Plan }[] = [
|
||||
{ name: "A", plan: { primitives: [p[0], p[2]], bounds: b } },
|
||||
{ name: "B", plan: { primitives: [p[1], p[3]], bounds: b } },
|
||||
];
|
||||
const full: Plan = { primitives: p, bounds: b };
|
||||
const runs = layerRunsInPlanOrder(full, groups);
|
||||
expect(runs.map((x) => x.name)).toEqual(["A", "B", "A", "B"]);
|
||||
expect(runs.flatMap((x) => x.primitives)).toEqual(p);
|
||||
});
|
||||
});
|
||||
|
||||
describe("[282] Wettbewerb Präsentationsplan", () => {
|
||||
it("Erdgeschoss: Läufe enthalten alle Primitive des ganzen Plans, Wände nach den Decken", async () => {
|
||||
getState().loadProject(buildWettbewerbSampleProject());
|
||||
const p0 = getState().project;
|
||||
const res = presentationSheetOps(p0, { ...presentationDefaults(p0), scale: 200 }, LABELS as never, "t282")!;
|
||||
getState().applyChange(res.ops);
|
||||
const p = getState().project;
|
||||
const lay = p.layouts!.find((l) => l.id === res.layoutId)!;
|
||||
const vp = lay.viewports.find((v) => p.viewSnapshots!.find((s) => s.id === v.snapshotId)!.activeLevelId === "eg")!;
|
||||
const snap = p.viewSnapshots!.find((s) => s.id === vp.snapshotId)!;
|
||||
const codes = visibleCodesFromSnapshot(snap);
|
||||
const full = await viewportSnapshotPlan(p, snap, codes, 200, true, vp);
|
||||
const groups: { name: string; plan: Plan }[] = [];
|
||||
for (const g of categoryLayerGroups(p.layers, codes, "x")) groups.push({ name: g.name, plan: await viewportSnapshotPlan(p, snap, g.codes, 200, true, vp) });
|
||||
const runs = layerRunsInPlanOrder(full, groups);
|
||||
expect(runs.flatMap((r) => r.primitives).length).toBe(full.primitives.length);
|
||||
const idx = (n: string) => runs.findIndex((r) => r.name === n && r.primitives.some((q) => "wallId" in q && q.wallId));
|
||||
const ceil = runs.findIndex((r) => r.primitives.some((q) => "ceilingId" in q && q.ceilingId));
|
||||
expect(idx("Wände")).toBeGreaterThanOrEqual(0);
|
||||
expect(ceil).toBeGreaterThanOrEqual(0);
|
||||
expect(ceil).toBeLessThan(idx("Wände"));
|
||||
}, 120_000);
|
||||
});
|
||||
@@ -15,7 +15,7 @@ import "svg2pdf.js";
|
||||
import type { Layout, LayoutPaperFormat, MasterLayout, Project } from "../model/types";
|
||||
import { t } from "../i18n/translate";
|
||||
import { legendPlan, legendPrintSvg } from "./legendSvg";
|
||||
import { categoryLayerGroups, enablePdfLayers, type PdfLayers } from "./pdfLayers";
|
||||
import { categoryLayerGroups, enablePdfLayers, layerRunsInPlanOrder, type PdfLayers } from "./pdfLayers";
|
||||
import { generatePlan, type Plan } from "../plan/generatePlan";
|
||||
import { snapshotMono, snapshotOverrideRuleIds, snapshotTemplate, viewportDesignOptions, viewportLevelPlan, viewportSnapshotPlan } from "../plan/viewportPlan";
|
||||
import { isDoc3dSnapshot } from "../plan/toAxo";
|
||||
@@ -260,10 +260,13 @@ async function renderPage(
|
||||
// Alle Ebenen mit den Grenzen des GANZEN Plans, sonst läge jede anders zentriert.
|
||||
doc.setFillColor(255, 255, 255);
|
||||
doc.rect(vp.xMm, vp.yMm, vp.widthMm, vp.heightMm, "F");
|
||||
for (const g of categoryLayerGroups(project.layers, codes, t("pdfLayers.other"))) {
|
||||
const plan = await planOf(g.codes);
|
||||
if (plan.primitives.length === 0) continue; // leere Ebenen nicht anlegen
|
||||
await ctx.layers.run(g.name, () => draw(plan, true, full.bounds));
|
||||
// [282] Stapelung des ganzen Plans erhalten: Läufe in Plan-Reihenfolge statt Ebene für Ebene nach
|
||||
// Kategorie-Baum (sonst deckt die Decken-Füllung die Wände zu).
|
||||
const groups: { name: string; plan: Plan }[] = [];
|
||||
for (const g of categoryLayerGroups(project.layers, codes, t("pdfLayers.other"))) groups.push({ name: g.name, plan: await planOf(g.codes) });
|
||||
for (const run of layerRunsInPlanOrder(full, groups)) {
|
||||
if (run.primitives.length === 0) continue;
|
||||
await ctx.layers.run(run.name, () => draw({ ...full, primitives: run.primitives }, true, full.bounds));
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
|
||||
@@ -101,3 +101,37 @@ export function categoryLayerGroups(
|
||||
if (rest.size > 0) out.push({ name: otherName, codes: rest });
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* [282] Teilpläne je Ebene in der Stapelung des GANZEN Plans: die Primitive des Gesamtplans werden den Gruppen
|
||||
* zugeordnet (Gleichheit des Primitivs, bei Mehrfachtreffern der Reihe nach) und in Läufen gleicher Gruppe
|
||||
* ausgegeben. Eine Ebene je Gruppe nacheinander zu zeichnen verfälscht die Stapelung, wo Kategorien im Plan
|
||||
* gegenüber dem Kategorie-Baum vertauscht liegen (Decken-Füllung liegt unter den Wänden). Gleichnamige Läufe
|
||||
* gehören im PDF zur selben Ebene. Nicht zuordenbare Primitive bleiben beim vorigen Lauf.
|
||||
*/
|
||||
export function layerRunsInPlanOrder<P>(
|
||||
full: { primitives: P[] },
|
||||
groups: { name: string; plan: { primitives: P[] } }[],
|
||||
): { name: string; primitives: P[] }[] {
|
||||
const owners = new Map<string, number[]>();
|
||||
groups.forEach((g, gi) => {
|
||||
for (const q of g.plan.primitives) {
|
||||
const k = JSON.stringify(q);
|
||||
const list = owners.get(k);
|
||||
if (list) list.push(gi);
|
||||
else owners.set(k, [gi]);
|
||||
}
|
||||
});
|
||||
const runs: { name: string; primitives: P[] }[] = [];
|
||||
let cur = -1;
|
||||
for (const q of full.primitives) {
|
||||
const list = owners.get(JSON.stringify(q));
|
||||
const gi = list && list.length > 0 ? (list.length > 1 ? list.shift()! : list[0]) : cur >= 0 ? cur : 0;
|
||||
if (gi !== cur || runs.length === 0) {
|
||||
runs.push({ name: groups[gi]?.name ?? "", primitives: [] });
|
||||
cur = gi;
|
||||
}
|
||||
runs[runs.length - 1].primitives.push(q);
|
||||
}
|
||||
return runs;
|
||||
}
|
||||
+2
-1
@@ -4180,7 +4180,8 @@ export const de = {
|
||||
"presentation.northGroup": "Nordpfeil",
|
||||
"presentation.scaleBarGroup": "Massstabsbalken",
|
||||
"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.tooBig": "Präsentationsplan nicht angelegt: passt auch 1:{scale} nicht aufs Blatt – grösseres Format wählen",
|
||||
"presentation.tooBigSuggest": "Präsentationsplan nicht angelegt: passt in 1:{scale} nicht aufs Blatt – grösster passender Massstab: 1:{fit}",
|
||||
"presentation.empty": "Präsentationsplan: keine Ansicht mit Inhalt gewählt",
|
||||
"presentation.extras": "Plakat-Inhalt",
|
||||
"presentation.extras.situation": "Situation 1:500",
|
||||
|
||||
+2
-1
@@ -4166,7 +4166,8 @@ export const en: Record<TranslationKey, string> = {
|
||||
"presentation.northGroup": "North arrow",
|
||||
"presentation.scaleBarGroup": "Scale bar",
|
||||
"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.tooBig": "Presentation sheet not created: does not fit even at 1:{scale} – choose a larger format",
|
||||
"presentation.tooBigSuggest": "Presentation sheet not created: does not fit at 1:{scale} – largest scale that fits: 1:{fit}",
|
||||
"presentation.empty": "Presentation sheet: no view with content chosen",
|
||||
"presentation.extras": "Poster content",
|
||||
"presentation.extras.situation": "Site plan 1:500",
|
||||
|
||||
@@ -5,7 +5,7 @@ import { generatePlan } from "./generatePlan";
|
||||
import { getState } from "../state/appStore";
|
||||
import { sheetSizeMm } from "../model/layoutModel";
|
||||
import { posterMetrics } from "../model/posterTemplates";
|
||||
import { POSTER_EXTRAS_DEFAULT, PRESENTATION_TEMPLATE_ID, levelHasContent, planPresentationSheet, presentationDefaults, presentationSheetOps } from "./presentationSheet";
|
||||
import { fittingPresentationScale, POSTER_EXTRAS_DEFAULT, PRESENTATION_TEMPLATE_ID, levelHasContent, planPresentationSheet, presentationDefaults, presentationSheetOps } from "./presentationSheet";
|
||||
import type { Project } from "../model/types";
|
||||
|
||||
const LABELS = {
|
||||
@@ -434,4 +434,21 @@ describe("[66] Präsentationsplan", () => {
|
||||
const bottoms = [...res.plan.items, ...(res.plan.tables ?? []), ...(res.plan.image ? [res.plan.image] : [])].filter((i) => (i.page ?? 0) === 0).map((i) => i.yMm + i.heightMm);
|
||||
expect(Math.max(...bottoms)).toBeGreaterThan(841 * 0.6);
|
||||
}, 90_000);
|
||||
|
||||
// [282] Passt der Plan im gewählten Massstab nicht: kein überlaufendes Blatt, sondern der grösste passende Massstab als Vorschlag.
|
||||
it("[282] Massstab-Vorschlag: 1:50 auf A4 passt nicht, vorgeschlagener Massstab passt", () => {
|
||||
st().loadProject(buildWettbewerbSampleProject());
|
||||
const p = st().project;
|
||||
const o = { ...presentationDefaults(p), paper: "a4" as const, orientation: "portrait" as const, scale: 50 };
|
||||
expect(planPresentationSheet(p, o).fits).toBe(false);
|
||||
const s = fittingPresentationScale(p, o);
|
||||
expect(s).not.toBeNull();
|
||||
expect(s!).toBeGreaterThan(50);
|
||||
expect(planPresentationSheet(p, { ...o, scale: s }).fits).toBe(true);
|
||||
// Der Vorschlag ist der grösste: der nächstgrössere Massstab passt nicht.
|
||||
const bigger = [50, 100, 200, 500, 1000].filter((x) => x > 50 && x < s!);
|
||||
for (const b of bigger) expect(planPresentationSheet(p, { ...o, scale: b }).fits).toBe(false);
|
||||
// Was schon passt, braucht keinen Vorschlag auf Kosten des Massstabs: A1 1:200.
|
||||
expect(planPresentationSheet(p, { ...presentationDefaults(p), scale: 200 }).fits).toBe(true);
|
||||
}, 60_000);
|
||||
});
|
||||
@@ -334,6 +334,19 @@ function posterTextMetrics(size: { w: number; h: number }): { sizeMm: number; dy
|
||||
*/
|
||||
const showsMarks = (o: PresentationOptions) => !!o.poster && (o.elevationIds.length > 0 || (o.sectionIds ?? []).length > 0);
|
||||
|
||||
/**
|
||||
* [282] Passt der Präsentationsplan im gewählten Massstab nicht aufs Blatt: der grösste gemeinsame Massstab (kleinster
|
||||
* Nenner aus {@link PRESENTATION_SCALES}, nur kleiner als der gewählte), bei dem er passt; sonst `null`. Je-Ebene-Massstäbe
|
||||
* (`scales`) bleiben, wie gewählt.
|
||||
*/
|
||||
export function fittingPresentationScale(project: Project, o: PresentationOptions): number | null {
|
||||
for (const s of PRESENTATION_SCALES) {
|
||||
if (o.scale && s <= o.scale) continue;
|
||||
if (planPresentationSheet(project, { ...o, scale: s }).fits) return s;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Massstab und Rahmen aus dem Kern (ohne das Projekt zu ändern). */
|
||||
export function planPresentationSheet(project: Project, o: PresentationOptions): PresentationPlan {
|
||||
const { template } = presentationTemplate(project);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// [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 { fittingPresentationScale, presentationSheetOps, type PresentationOptions } from "../core";
|
||||
import { t } from "../i18n";
|
||||
import { getState } from "./appStore";
|
||||
|
||||
@@ -19,11 +19,16 @@ export function createPresentationSheet(o: PresentationOptions): string | null {
|
||||
st.notify(t("presentation.empty"), "warning");
|
||||
return null;
|
||||
}
|
||||
// [282] Passt nichts aufs Blatt: kein überlaufendes Blatt anlegen, sondern den grössten passenden Massstab vorschlagen.
|
||||
if (!res.plan.fits) {
|
||||
const fit = fittingPresentationScale(st.project, o);
|
||||
st.notify(fit ? t("presentation.tooBigSuggest", { scale: res.plan.scale, fit }) : t("presentation.tooBig", { scale: res.plan.scale }), "warning");
|
||||
return null;
|
||||
}
|
||||
st.applyChange(res.ops);
|
||||
const pages = res.plan.pages ?? 1;
|
||||
if (res.plan.fits && pages > 1) st.notify(t("presentation.donePages", { scale: res.plan.scale, pages }), "info");
|
||||
else 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");
|
||||
if (pages > 1) st.notify(t("presentation.donePages", { scale: res.plan.scale, pages }), "info");
|
||||
else st.notify(t("presentation.done", { scale: res.plan.scale, n: res.plan.items.length }), "info");
|
||||
return res.layoutId;
|
||||
} catch (e) {
|
||||
st.notify(`${t("presentation.failed")}: ${e instanceof Error ? e.message : String(e)}`, "error");
|
||||
|
||||
@@ -33,8 +33,10 @@ export const PresentationDialogHost = memo(function PresentationDialogHost({
|
||||
const confirm = useCallback(() => {
|
||||
if (!opts) return;
|
||||
const id = createPresentationSheet(opts);
|
||||
// [282] Nicht angelegt (z. B. passt nicht aufs Blatt): Dialog bleibt offen, Massstab/Format anpassbar.
|
||||
if (!id) return;
|
||||
setOpts(null);
|
||||
if (id) onCreated(id);
|
||||
onCreated(id);
|
||||
}, [opts, onCreated]);
|
||||
|
||||
const dialogRef = useModalFocus({});
|
||||
|
||||
Reference in new issue
Block a user