[34] Ansichtsvorlagen gelten vollständig für Schnitte und Ansichten: Blatt-Viewports (verknüpfte Vorlage, Detailgrad im Schnitt-Puffer) und CLI (--template: Detail, Massstab, Farbe, Kategorien, Ebenen-Felder)
This commit is contained in:
13 files changed
+366
-46
No files matched your search
@@ -155,6 +155,55 @@ describe("dossier-cli", () => {
|
||||
expect(readFileSync(stp, "utf8").startsWith("ISO-10303-21;")).toBe(true);
|
||||
}, 60_000);
|
||||
|
||||
// [34] `--template` gilt für Grundriss, Schnitt und Ansicht vollständig: Ebenen-Felder, Detailgrad, Massstab,
|
||||
// Tusche/Farbe, ausgeblendete Kategorien; ohne Flag die an der Ebene verknüpfte Vorlage.
|
||||
it("[34] Ansichtsvorlage in plan, section und elevation", async () => {
|
||||
const section = sampleProject.drawingLevels.find((l) => l.kind === "section")!;
|
||||
const elevation = sampleProject.drawingLevels.find((l) => l.kind === "elevation")!;
|
||||
const tpls = [
|
||||
{ id: "t-verdeckt", name: "Verdeckt", hiddenLines: true, cutHatch: true },
|
||||
{ id: "t-skizze", name: "Skizze", sketch: true },
|
||||
{ id: "t-fein", name: "Fein 1:50", detail: "fein" as const, scaleDenominator: 50 },
|
||||
{ id: "t-farbe", name: "Farbig", mono: false },
|
||||
{ id: "t-ohne-wand", name: "Ohne Wände", layerVisibility: { "20": false } },
|
||||
];
|
||||
const tf = join(dir, "vorlagen.obp");
|
||||
writeFileSync(tf, serializeProject({ ...sampleProject, viewTemplates: tpls }));
|
||||
const svg = async (args: string[], name: string, proj = tf) => {
|
||||
const out = join(dir, `${name}.svg`);
|
||||
expect(await run([proj, ...args, "--out", out])).toBe(0);
|
||||
return readFileSync(out, "utf8");
|
||||
};
|
||||
const plain = { section: await svg(["section", section.name], "v-s"), elevation: await svg(["elevation", elevation.name], "v-a"), plan: await svg(["plan"], "v-p") };
|
||||
// Ebenen-Felder: im Schnitt (verdeckte Kanten, Schraffur) und in Schnitt und Ansicht (Skizzenstil).
|
||||
expect(await svg(["section", section.name, "--template", "Verdeckt"], "v-s1")).not.toBe(plain.section);
|
||||
expect(await svg(["section", section.name, "--template", "t-skizze"], "v-s2")).not.toBe(plain.section);
|
||||
expect(await svg(["elevation", elevation.name, "--template", "Skizze"], "v-a1")).not.toBe(plain.elevation);
|
||||
// Detailgrad und Massstab der Vorlage; ein ausdrückliches --scale geht vor.
|
||||
const fein = await svg(["section", section.name, "--template", "Fein 1:50"], "v-s3");
|
||||
expect(fein).not.toBe(plain.section);
|
||||
expect(await svg(["section", section.name, "--template", "Fein 1:50", "--scale", "100"], "v-s4")).not.toBe(fein);
|
||||
expect(await svg(["plan", "--template", "Fein 1:50"], "v-p1")).not.toBe(plain.plan);
|
||||
// Farbe statt Tusche; ausgeblendete Kategorie.
|
||||
const farbig = await svg(["elevation", elevation.name, "--template", "Farbig"], "v-a2");
|
||||
expect(farbig).not.toBe(plain.elevation);
|
||||
expect(farbig).toBe(await svg(["elevation", elevation.name, "--color"], "v-a3"));
|
||||
const ohne = await svg(["plan", "--template", "Ohne Wände"], "v-p2");
|
||||
expect(ohne).not.toBe(plain.plan);
|
||||
expect(ohne.length).toBeLessThan(plain.plan.length);
|
||||
// Ohne Flag: die an der Ebene verknüpfte Vorlage.
|
||||
const linked = join(dir, "vorlagen-verknuepft.obp");
|
||||
writeFileSync(
|
||||
linked,
|
||||
serializeProject({
|
||||
...sampleProject,
|
||||
viewTemplates: tpls,
|
||||
drawingLevels: sampleProject.drawingLevels.map((l) => (l.id === section.id ? { ...l, templateId: "t-fein", templateLinked: true } : l)),
|
||||
}),
|
||||
);
|
||||
expect(await svg(["section", section.name], "v-s5", linked)).toBe(fein);
|
||||
}, 120_000);
|
||||
|
||||
it("unbekannter Befehl und fehlende Datei geben Fehlercode", async () => {
|
||||
expect(await call("gibtsnicht")).toBe(2);
|
||||
expect(await run([])).toBe(2);
|
||||
|
||||
+48
-24
@@ -10,8 +10,10 @@
|
||||
// dossier-cli <projekt.obp> section <Name> [--sketch] [--hatch] [--color] [--out schnitt.svg] (--format json: render2d-Szene)
|
||||
// dossier-cli <projekt.obp> elevation <Name> [--sketch] [--hatch] [--color] [--out ansicht.svg] (--sketch: Skizzenstil [67])
|
||||
// --color: Darstellung „Farbig" statt Tusche (Standard, [140])
|
||||
// plan/section/elevation: --template <Vorlage> wendet eine Ansichtsvorlage an
|
||||
// (Override-Regeln, Schnittflächen schraffiert …), --rule <Regel> schaltet eine
|
||||
// plan/section/elevation: --template <Vorlage> wendet eine Ansichtsvorlage ganz an
|
||||
// (Ebenen-Felder wie verdeckte Kanten/Schnittflächen schraffiert/Schatten/Skizze,
|
||||
// Detailgrad, Massstab, Tusche/Farbe, ausgeblendete Kategorien, Override-Regeln;
|
||||
// --scale/--color gehen vor; ohne Flag gilt die an der Ebene verknüpfte Vorlage [34]), --rule <Regel> schaltet eine
|
||||
// Override-Regel ein (auch Standard-Baustein, z. B. --rule "Deckenaufbau weiss") [33];
|
||||
// das Massstab-Kriterium einer Regel (ab/bis 1:n) gilt nach --scale
|
||||
// dossier-cli <projekt.obp> ifc [--ebkph] [--ebenen] (IFC mit eBKP-H-Hauptgruppen bzw. Modell-Ebenen als Klassifikation)
|
||||
@@ -125,11 +127,14 @@ import {
|
||||
withDocument,
|
||||
AI_BRIDGE_DEFAULT_PORT,
|
||||
standardOverrideRules,
|
||||
linkedViewTemplate,
|
||||
projectWithTemplate,
|
||||
templateDisplay,
|
||||
recognizeMutation,
|
||||
recognizeReport,
|
||||
recognizeSourceLevels,
|
||||
} from "../core";
|
||||
import type { Project } from "../core";
|
||||
import type { Project, ViewTemplate } from "../core";
|
||||
import { serveStdio } from "./mcp";
|
||||
import { startBridge } from "./mcpBridge";
|
||||
|
||||
@@ -206,27 +211,44 @@ function findLevel(project: Project, kinds: string[], name: string | undefined)
|
||||
return levels.find((l) => l.id.toLowerCase() === n || l.name.toLowerCase() === n);
|
||||
}
|
||||
|
||||
/** Ansichts-Felder einer Vorlage, die am Geschoss/Schnitt/Ansicht stehen (wie `state/viewTemplates.ts`). */
|
||||
const TEMPLATE_LEVEL_KEYS = ["cutHeight", "viewTop", "viewBottom", "viewDepth", "shadows", "hiddenLines", "sketch", "cutHatch", "floorFinish", "showTerrain"] as const;
|
||||
|
||||
/**
|
||||
* [33]/[34] `--template <Name|id>`: Ansichtsvorlage auf die Ebene anwenden (Override-Regeln nach
|
||||
* `enabledOverrideRuleIds`, Ebenen-Felder wie „Schnittflächen schraffiert"); `--rule <Name|id>`: eine
|
||||
* Override-Regel einschalten — fehlt sie im Projekt, aus den Standard-Bausteinen (z. B. „Deckenaufbau weiss").
|
||||
* [33]/[34] Wirksame Ansichtsvorlage der Ebene: `--template <Name|id>`, sonst die an der Ebene verknüpfte
|
||||
* (`templateLinked`). Gilt vollständig für Grundriss, Schnitt und Ansicht: Ebenen-Felder (Schnitthöhe,
|
||||
* Ansichtsbereich, Schatten, verdeckte Kanten, Skizze, Schnittflächen schraffiert, Bodenbelag, Gelände),
|
||||
* Override-Regeln, Strichstärken nach Massstab, dazu Detailgrad, Massstab, Tusche/Farbe und ausgeblendete
|
||||
* Kategorien ({@link templateView}).
|
||||
*/
|
||||
function withTemplate(project: Project, levelId: string, args: Args): Project {
|
||||
let p = project;
|
||||
function templateFor(project: Project, levelId: string, args: Args): ViewTemplate | undefined {
|
||||
const tName = args.flags.get("template");
|
||||
if (tName) {
|
||||
const n = tName.toLowerCase();
|
||||
const tpl = (p.viewTemplates ?? []).find((x) => x.id.toLowerCase() === n || x.name.toLowerCase() === n);
|
||||
const tpl = (project.viewTemplates ?? []).find((x) => x.id.toLowerCase() === n || x.name.toLowerCase() === n);
|
||||
if (!tpl) fail(`Ansichtsvorlage nicht gefunden: ${tName}`);
|
||||
const ids = tpl.enabledOverrideRuleIds;
|
||||
if (ids) p = { ...p, overrideRules: (p.overrideRules ?? []).map((r) => ({ ...r, enabled: ids.includes(r.id) })) };
|
||||
const patch: Record<string, unknown> = {};
|
||||
for (const k of TEMPLATE_LEVEL_KEYS) if (tpl[k] !== undefined) patch[k] = tpl[k];
|
||||
p = { ...p, drawingLevels: p.drawingLevels.map((l) => (l.id === levelId ? { ...l, ...patch } : l)) };
|
||||
return tpl;
|
||||
}
|
||||
return linkedViewTemplate(project, project.drawingLevels.find((l) => l.id === levelId));
|
||||
}
|
||||
|
||||
/** Darstellung einer Ebene nach Vorlage und Aufruf: ausdrückliche Optionen (`--scale`, `--color`) gehen vor. */
|
||||
function templateView(project: Project, levelId: string, args: Args, allCodes: Set<string>) {
|
||||
const tpl = templateFor(project, levelId, args);
|
||||
const d = templateDisplay(tpl);
|
||||
const hidden = new Set(d.hiddenCodes);
|
||||
return {
|
||||
tpl,
|
||||
detail: d.detail,
|
||||
scale: args.flags.has("scale") ? Number(args.flags.get("scale")) : (d.scaleDenominator ?? 100),
|
||||
mono: args.flags.has("color") ? inkArg(args) : (d.mono ?? true),
|
||||
codes: hidden.size ? new Set([...allCodes].filter((c) => !hidden.has(c))) : allCodes,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* [33]/[34] Ansichtsvorlage `tpl` auf die Ebene anwenden; `--rule <Name|id>`: eine Override-Regel einschalten —
|
||||
* fehlt sie im Projekt, aus den Standard-Bausteinen (z. B. „Deckenaufbau weiss").
|
||||
*/
|
||||
function withTemplate(project: Project, levelId: string, tpl: ViewTemplate | undefined, args: Args): Project {
|
||||
let p = tpl ? projectWithTemplate(project, levelId, tpl, true) : project;
|
||||
const rName = args.flags.get("rule");
|
||||
if (rName) {
|
||||
const n = rName.toLowerCase();
|
||||
@@ -664,12 +686,13 @@ async function execute(project: Project, file: string, command: string, rest: st
|
||||
if (!own) planProject = { ...project, drawingLevels: [...project.drawingLevels, lvl] };
|
||||
}
|
||||
// Massstab geht in die Plan-Erzeugung ein (Bemassung in Papier-mm, Strichstärken nach Massstab).
|
||||
const plan = generatePlan(withSketch(withTemplate(planProject, lvl.id, args), lvl.id, args), lvl.id, allCodes, undefined, "mittel", false, inkArg(args), true, scale);
|
||||
const tv = templateView(planProject, lvl.id, args, allCodes);
|
||||
const plan = generatePlan(withSketch(withTemplate(planProject, lvl.id, tv.tpl, args), lvl.id, args), lvl.id, tv.codes, undefined, tv.detail ?? "mittel", false, tv.mono, true, tv.scale);
|
||||
if (args.flags.get("format") === "json") {
|
||||
out(args, JSON.stringify(planToRenderScene(plan, scale)), `${lvl.name}.scene.json`);
|
||||
out(args, JSON.stringify(planToRenderScene(plan, tv.scale)), `${lvl.name}.scene.json`);
|
||||
return 0;
|
||||
}
|
||||
out(args, planToSvgString(plan, { scaleDenominator: scale, hatch: args.flags.has("hatch") && args.flags.get("hatch") !== "false" }), `${lvl.name}.svg`);
|
||||
out(args, planToSvgString(plan, { scaleDenominator: tv.scale, hatch: args.flags.has("hatch") && args.flags.get("hatch") !== "false" }), `${lvl.name}.svg`);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
@@ -679,17 +702,18 @@ async function execute(project: Project, file: string, command: string, rest: st
|
||||
const kind = command === "section" ? "section" : "elevation";
|
||||
const found = findLevel(project, [kind], name);
|
||||
if (!found) fail(`${command} nicht gefunden: ${name ?? "(erste)"}`);
|
||||
const sp = withSketch(withTemplate(project, found.id, args), found.id, args);
|
||||
const tv = templateView(project, found.id, args, allCodes);
|
||||
const sp = withSketch(withTemplate(project, found.id, tv.tpl, args), found.id, args);
|
||||
const lvl = sp.drawingLevels.find((l) => l.id === found.id) ?? found;
|
||||
// [157] Wie die App (`viewportLevelPlan`): verdeckte Kanten nach der Ebene, geschnittene Fenster/Türen,
|
||||
// automatische Höhenkoten (`levelMarks`) und die eigenen 2D-Elemente der Schnitt-/Ansichtsebene.
|
||||
const plan = await viewportLevelPlan(sp, lvl.id, allCodes, undefined, scale, false, inkArg(args));
|
||||
const plan = await viewportLevelPlan(sp, lvl.id, tv.codes, tv.detail, tv.scale, false, tv.mono);
|
||||
if (plan.primitives.length === 0) fail(kind === "section" ? "keine gültige Schnittlinie" : "keine gültige Ansichtslinie");
|
||||
if (args.flags.get("format") === "json") {
|
||||
out(args, JSON.stringify(planToRenderScene(plan, scale)), `${lvl.name}.scene.json`);
|
||||
out(args, JSON.stringify(planToRenderScene(plan, tv.scale)), `${lvl.name}.scene.json`);
|
||||
return 0;
|
||||
}
|
||||
out(args, planToSvgString(plan, { scaleDenominator: scale, hatch: args.flags.has("hatch") && args.flags.get("hatch") !== "false" }), `${lvl.name}.svg`);
|
||||
out(args, planToSvgString(plan, { scaleDenominator: tv.scale, hatch: args.flags.has("hatch") && args.flags.get("hatch") !== "false" }), `${lvl.name}.svg`);
|
||||
return 0;
|
||||
}
|
||||
case "dxf":
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ export { initCore } from "../engine/coreWasm";
|
||||
export { applyOps, validateProject, validateOps } from "./ops";
|
||||
export { projectWarnings } from "./ops";
|
||||
export type { CoreOp } from "./ops";
|
||||
export type { Project, DrawingLevel } from "../model/types";
|
||||
export type { Project, DrawingLevel, ViewTemplate } from "../model/types";
|
||||
export { computeKennzahlen, checkRoomProgram, solidVolume } from "../analysis/kennzahlen";
|
||||
export type { Kennzahlen, ProgramCheck } from "../analysis/kennzahlen";
|
||||
export { compareRoomProgram, layoutRoomProgram, DEFAULT_PROGRAM_TOLERANCE } from "../analysis/roomProgram";
|
||||
|
||||
@@ -247,6 +247,8 @@ export {
|
||||
export { viewportLevelPlan } from "../plan/viewportPlan";
|
||||
export { snapshotMono } from "../plan/viewportPlan";
|
||||
export { snapshotOverrideRuleIds } from "../plan/viewportPlan";
|
||||
export { snapshotTemplate } from "../plan/viewportPlan";
|
||||
export { TEMPLATE_LEVEL_KEYS, linkedViewTemplate, projectWithTemplate, templateDisplay, templateLevelPatch } from "../plan/viewTemplate";
|
||||
|
||||
export {
|
||||
TRUCK_MESH_READY_EVENT,
|
||||
|
||||
@@ -17,7 +17,7 @@ import { t } from "../i18n/translate";
|
||||
import { legendPlan, legendPrintSvg } from "./legendSvg";
|
||||
import { categoryLayerGroups, enablePdfLayers, type PdfLayers } from "./pdfLayers";
|
||||
import { generatePlan, type Plan } from "../plan/generatePlan";
|
||||
import { snapshotMono, snapshotOverrideRuleIds, viewportLevelPlan } from "../plan/viewportPlan";
|
||||
import { snapshotMono, snapshotOverrideRuleIds, snapshotTemplate, viewportLevelPlan } from "../plan/viewportPlan";
|
||||
import { planToPrintSvg } from "./planToPrintSvg";
|
||||
import { drawTablesPdf, sheetTables } from "./sheetTable";
|
||||
import { collectVisibleCodes } from "../model/types";
|
||||
@@ -171,7 +171,8 @@ async function renderPage(
|
||||
// Geschoss/Zeichnung, Schnitt oder Ansicht ([115]) — wie ViewportPlanSvg, im Druck-Modus.
|
||||
// [33] Override-Regeln des Ausschnitts bzw. seiner verknüpften Ansichtsvorlage (wie am Bildschirm).
|
||||
const ruleIds = snapshotOverrideRuleIds(project, snap);
|
||||
const planOf = (visible: Set<string>) => viewportLevelPlan(project, snap.activeLevelId, visible, snap.detail, scaleN, true, snapshotMono(project, snap), ruleIds);
|
||||
const template = snapshotTemplate(project, snap);
|
||||
const planOf = (visible: Set<string>) => viewportLevelPlan(project, snap.activeLevelId, visible, snap.detail, scaleN, true, snapshotMono(project, snap), ruleIds, template);
|
||||
const draw = async (plan: Plan, transparent: boolean, bounds?: Plan["bounds"]) => {
|
||||
const print = planToPrintSvg(plan, { scaleDenominator: scaleN, pageWidthMm: vp.widthMm, pageHeightMm: vp.heightMm, transparent, bounds });
|
||||
await doc.svg(print.svg, { x: vp.xMm, y: vp.yMm, width: vp.widthMm, height: vp.heightMm });
|
||||
|
||||
+2
-1
@@ -13,7 +13,8 @@ Fassaden, die den Kern fragen, und die Leser der Plan-Puffer. Die Hülle importi
|
||||
| `generatePlan/layerSig.ts` | Signatur der stilrelevanten Ebenen-Eigenschaften (Cache-Schlüssel) |
|
||||
| `toSection.ts` | `computeSection()` (Körper-Netze über truck), `generateSectionPlan()` (Abfrage `sectionPlan`) |
|
||||
| `toElevation.ts` | `generateElevationPlan()` (Abfrage `elevationPlan`) |
|
||||
| `viewportPlan.ts` | Inhalt eines Layout-Viewports: Plan der Ebene, auf die sein Ausschnitt zeigt |
|
||||
| `viewportPlan.ts` | Inhalt eines Layout-Viewports: Plan der Ebene, auf die sein Ausschnitt zeigt (mit verknüpfter Ansichtsvorlage) |
|
||||
| `viewTemplate.ts` | [34] Ansichtsvorlage → Projekt/Anzeigewerte für Viewport und CLI (`projectWithTemplate`, `templateDisplay`) |
|
||||
| `levelMarkers.ts` | automatische Höhenkoten in Schnitt und Ansicht |
|
||||
| `presentationSheet.ts` | Präsentationsplan mit einem Klick (`[66]`) |
|
||||
| `openingPreview.ts` | Vorschau im Fenster-/Tür-Dialog |
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
// [34] Ansichtsvorlagen in der Plan-Erzeugung: wie eine Vorlage (`Project.viewTemplates`) auf Schnitt, Ansicht
|
||||
// und Grundriss wirkt, wenn sie nicht über den Anzeigezustand der aktiven Ansicht kommt — auf Blatt-Viewports
|
||||
// (verknüpfte Vorlage des Ausschnitts) und in der CLI (`--template`, verknüpfte Vorlage der Ebene).
|
||||
// Reine Logik; Kern-Gegenstück für die Blatt-Puffer: `sheet_viewports::snapshot_project`.
|
||||
|
||||
import type { DrawingLevel, Project, ViewTemplate } from "../model/types";
|
||||
import type { DetailLevel } from "../model/viewTypes";
|
||||
|
||||
/** Ebenen-Felder, die eine Vorlage setzt (fehlt das Vorlagen-Feld, bleibt die Ansicht unberührt). */
|
||||
export const TEMPLATE_LEVEL_KEYS = ["cutHeight", "viewTop", "viewBottom", "viewDepth", "shadows", "hiddenLines", "sketch", "cutHatch", "floorFinish", "showTerrain"] as const;
|
||||
|
||||
/** Teilobjekt für die Ebene aus den gesetzten Feldern der Vorlage. */
|
||||
export function templateLevelPatch(t: ViewTemplate): Partial<DrawingLevel> {
|
||||
const out: Record<string, unknown> = {};
|
||||
for (const k of TEMPLATE_LEVEL_KEYS) if (t[k] !== undefined) out[k] = t[k];
|
||||
return out as Partial<DrawingLevel>;
|
||||
}
|
||||
|
||||
/** Die verknüpfte Vorlage einer Ansicht/eines Ausschnitts (nur bei `templateLinked`). */
|
||||
export function linkedViewTemplate(
|
||||
project: Pick<Project, "viewTemplates">,
|
||||
target: { templateId?: string | null; templateLinked?: boolean | null } | undefined,
|
||||
): ViewTemplate | undefined {
|
||||
if (!target?.templateId || !target.templateLinked) return undefined;
|
||||
return project.viewTemplates?.find((t) => t.id === target.templateId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Das Projekt, wie die Vorlage es für die Ebene `levelId` sieht: Ebenen-Felder der Vorlage und ihre
|
||||
* Strichstärken-Skalierung. `rules`: auch die Override-Regeln der Vorlage einschalten (alle übrigen aus) —
|
||||
* für Wege, die die Regeln aus dem Projekt lesen (CLI); Viewports übergeben sie ausdrücklich.
|
||||
*/
|
||||
export function projectWithTemplate(project: Project, levelId: string, t: ViewTemplate, rules = false): Project {
|
||||
const patch = templateLevelPatch(t);
|
||||
let p: Project = { ...project, drawingLevels: project.drawingLevels.map((l) => (l.id === levelId ? { ...l, ...patch } : l)) };
|
||||
if (t.scaleLineWeights !== undefined) p = { ...p, scaleLineWeights: t.scaleLineWeights };
|
||||
const ids = t.enabledOverrideRuleIds;
|
||||
if (rules && ids) p = { ...p, overrideRules: (p.overrideRules ?? []).map((r) => ({ ...r, enabled: ids.includes(r.id) })) };
|
||||
return p;
|
||||
}
|
||||
|
||||
/** Anzeigewerte, die eine Vorlage zusätzlich zu den Ebenen-Feldern vorgibt (CLI, Blatt). */
|
||||
export interface TemplateDisplay {
|
||||
detail: DetailLevel | undefined;
|
||||
scaleDenominator: number | undefined;
|
||||
mono: boolean | undefined;
|
||||
/** Kategorie-Codes, die die Vorlage ausblendet. */
|
||||
hiddenCodes: string[];
|
||||
}
|
||||
|
||||
export function templateDisplay(t: ViewTemplate | undefined): TemplateDisplay {
|
||||
return {
|
||||
detail: t?.detail,
|
||||
scaleDenominator: t?.scaleDenominator,
|
||||
mono: t?.mono,
|
||||
hiddenCodes: Object.entries(t?.layerVisibility ?? {})
|
||||
.filter(([, v]) => v === false)
|
||||
.map(([code]) => code),
|
||||
};
|
||||
}
|
||||
@@ -3,7 +3,8 @@ import { describe, expect, it } from "vitest";
|
||||
import { buildComplexSampleProject } from "../model/sampleProjectComplex";
|
||||
import { collectVisibleCodes } from "../model/types";
|
||||
import { generatePlan } from "./generatePlan";
|
||||
import { snapshotMono, snapshotOverrideRuleIds, viewportLevelPlan } from "./viewportPlan";
|
||||
import type { DrawingLevel, ViewTemplate } from "../model/types";
|
||||
import { snapshotMono, snapshotOverrideRuleIds, snapshotTemplate, viewportLevelPlan } from "./viewportPlan";
|
||||
|
||||
const p = buildComplexSampleProject();
|
||||
const codes = collectVisibleCodes(p.layers);
|
||||
@@ -149,3 +150,43 @@ describe("viewportLevelPlan: Override-Regeln des Ausschnitts ([33])", () => {
|
||||
expect(snapshotOverrideRuleIds(r, { templateId: "leer", templateLinked: true, enabledOverrideRuleIds: [] })).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
// [34] Verknüpfte Ansichtsvorlage des Ausschnitts: ihre Felder gelten auf dem Blatt für Schnitt, Ansicht und
|
||||
// Grundriss, als stünden sie an der Ebene selbst (Kern-Gegenstück: `sheet_viewports`-Tests).
|
||||
describe("viewportLevelPlan: Ansichtsvorlage ([34])", () => {
|
||||
const json = async (q: typeof p, level: string, tpl?: ViewTemplate, scale = 100, detail: "grob" | "mittel" | "fein" = "mittel") => {
|
||||
const plan = await viewportLevelPlan(q, level, codes, detail, scale, false, true, undefined, tpl);
|
||||
return JSON.stringify(plan.primitives);
|
||||
};
|
||||
const withLevel = (level: string, patch: Partial<DrawingLevel>) => ({ ...p, drawingLevels: p.drawingLevels.map((l) => (l.id === level ? { ...l, ...patch } : l)) });
|
||||
const cases: [string, Partial<ViewTemplate>][] = [
|
||||
["schnitt-a", { hiddenLines: true }],
|
||||
["schnitt-a", { cutHatch: true }],
|
||||
["schnitt-a", { sketch: true }],
|
||||
["ansicht-sued", { sketch: true }],
|
||||
["ansicht-sued", { shadows: false }],
|
||||
["ansicht-sued", { hiddenLines: true }],
|
||||
["eg", { cutHeight: 0.4 }],
|
||||
];
|
||||
it.each(cases)("%s: Vorlage %j = Feld an der Ebene", async (level, fields) => {
|
||||
const tpl: ViewTemplate = { id: "vt", name: "V", ...fields };
|
||||
const plain = await json(p, level);
|
||||
const want = await json(withLevel(level, fields as Partial<DrawingLevel>), level);
|
||||
expect(want).not.toBe(plain);
|
||||
expect(await json({ ...p, viewTemplates: [tpl] }, level, tpl)).toBe(want);
|
||||
expect(snapshotTemplate({ viewTemplates: [tpl] }, { templateId: "vt", templateLinked: true })).toBe(tpl);
|
||||
expect(snapshotTemplate({ viewTemplates: [tpl] }, { templateId: "vt", templateLinked: false })).toBeUndefined();
|
||||
});
|
||||
|
||||
it("Detailgrad und Strichstärken nach Massstab der Vorlage gelten im Schnitt und in der Ansicht", async () => {
|
||||
const fein: ViewTemplate = { id: "vt", name: "V", detail: "fein" };
|
||||
expect(await json(p, "schnitt-a", fein, 50, "grob")).toBe(await json(p, "schnitt-a", undefined, 50, "fein"));
|
||||
// Das Beispielprojekt skaliert die Strichstärken; die Vorlage dieses Ausschnitts schaltet das ab.
|
||||
const fest: ViewTemplate = { id: "vt", name: "V", scaleLineWeights: false };
|
||||
for (const level of ["schnitt-a", "ansicht-sued"]) {
|
||||
const want = await json({ ...p, scaleLineWeights: false }, level, undefined, 200);
|
||||
expect(want).not.toBe(await json(p, level, undefined, 200));
|
||||
expect(await json(p, level, fest, 200)).toBe(want);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -5,7 +5,9 @@
|
||||
// Blatt zeigte bloss seine 2D-Elemente. Nur Zusammensetzen vorhandener Kern-Abfragen.
|
||||
|
||||
import type { DetailLevel } from "../model/viewTypes";
|
||||
import type { Project } from "../model/types";
|
||||
import type { Project, ViewTemplate } from "../model/types";
|
||||
import { withDocument } from "../core/document";
|
||||
import { linkedViewTemplate, projectWithTemplate } from "./viewTemplate";
|
||||
import { generatePlan, type Plan, type Primitive } from "./generatePlan";
|
||||
import { computeSection, generateSectionPlan } from "./toSection";
|
||||
import { generateElevationPlan } from "./toElevation";
|
||||
@@ -33,6 +35,14 @@ export function snapshotOverrideRuleIds(
|
||||
return tpl?.enabledOverrideRuleIds ?? snap.enabledOverrideRuleIds ?? undefined;
|
||||
}
|
||||
|
||||
/** [34] Verknüpfte Ansichtsvorlage eines Ausschnitts, für {@link viewportLevelPlan} (Kern: `sheet_viewports::snapshot_template`). */
|
||||
export function snapshotTemplate(
|
||||
project: Pick<Project, "viewTemplates">,
|
||||
snap: { templateId?: string | null; templateLinked?: boolean | null },
|
||||
): ViewTemplate | undefined {
|
||||
return linkedViewTemplate(project, snap);
|
||||
}
|
||||
|
||||
const EMPTY: Plan = { primitives: [], bounds: { minX: 0, minY: 0, maxX: 1, maxY: 1 } };
|
||||
|
||||
/**
|
||||
@@ -49,6 +59,24 @@ export async function viewportLevelPlan(
|
||||
mono = true,
|
||||
/** [33] Eingeschaltete Override-Regeln ({@link snapshotOverrideRuleIds}); fehlt = Schalter im Projekt. */
|
||||
overrideRuleIds?: readonly string[] | null,
|
||||
/** [34] Verknüpfte Ansichtsvorlage des Ausschnitts: ihre Ebenen-Felder (verdeckte Kanten, Schnittflächen
|
||||
* schraffiert, Schatten, Skizzenstil …) und Detailgrad gelten für diesen Viewport (Kern: `sheet_viewports::snapshot_project`). */
|
||||
template?: ViewTemplate | null,
|
||||
): Promise<Plan> {
|
||||
if (!template) return levelPlan(project, levelId, visibleCodes, detail, scaleDenominator, forPrint, mono, overrideRuleIds);
|
||||
const tp = projectWithTemplate(project, levelId, template);
|
||||
return withDocument(tp, () => levelPlan(tp, levelId, visibleCodes, template.detail ?? detail, scaleDenominator, forPrint, mono, overrideRuleIds));
|
||||
}
|
||||
|
||||
async function levelPlan(
|
||||
project: Project,
|
||||
levelId: string,
|
||||
visibleCodes: Set<string>,
|
||||
detail: DetailLevel | undefined,
|
||||
scaleDenominator: number,
|
||||
forPrint: boolean,
|
||||
mono: boolean,
|
||||
overrideRuleIds: readonly string[] | null | undefined,
|
||||
): Promise<Plan> {
|
||||
const level = project.drawingLevels.find((l) => l.id === levelId);
|
||||
if (!level) return EMPTY;
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// (`patchTemplateOps` schreibt sie in einem Schritt in alle verknüpften Ansichten/Ausschnitte).
|
||||
// Alles liefert Ops (`applyChange`); eine Änderung = ein Undo-Schritt.
|
||||
|
||||
import { addItems, fieldOps, findItem, itemsOf, patchItem, removeItems } from "../core";
|
||||
import { addItems, fieldOps, findItem, itemsOf, patchItem, removeItems, TEMPLATE_LEVEL_KEYS, templateLevelPatch } from "../core";
|
||||
import type { CoreOp } from "../core";
|
||||
import type { DrawingLevel, OverrideRule, Project, ViewSnapshot, ViewTemplate } from "../model/types";
|
||||
import type { DetailLevel } from "../model/viewTypes";
|
||||
@@ -28,15 +28,8 @@ export interface ViewTemplateUi {
|
||||
scaleLineWeights: boolean;
|
||||
}
|
||||
|
||||
/** Geschoss-Felder, die eine Vorlage setzt (fehlt das Vorlagen-Feld, bleibt die Ansicht unberührt). */
|
||||
const LEVEL_KEYS = ["cutHeight", "viewTop", "viewBottom", "viewDepth", "shadows", "hiddenLines", "sketch", "cutHatch", "floorFinish", "showTerrain"] as const;
|
||||
|
||||
/** Teilobjekt für das Geschoss aus den gesetzten Feldern der Vorlage. */
|
||||
export function levelPatch(t: ViewTemplate): Partial<DrawingLevel> {
|
||||
const out: Record<string, unknown> = {};
|
||||
for (const k of LEVEL_KEYS) if (t[k] !== undefined) out[k] = t[k];
|
||||
return out as Partial<DrawingLevel>;
|
||||
}
|
||||
/** Teilobjekt für das Geschoss aus den gesetzten Feldern der Vorlage (fehlt das Feld, bleibt die Ansicht unberührt). */
|
||||
export const levelPatch = templateLevelPatch;
|
||||
|
||||
/** Teilobjekt für einen Ausschnitt (Kategorien werden zusammengeführt, nicht ersetzt). */
|
||||
export function snapshotPatch(t: ViewTemplate, s: ViewSnapshot): Partial<ViewSnapshot> {
|
||||
@@ -61,7 +54,7 @@ export function captureTemplate(id: string, name: string, level: DrawingLevel |
|
||||
mono: ui.mono,
|
||||
scaleLineWeights: ui.scaleLineWeights,
|
||||
};
|
||||
if (level) for (const k of LEVEL_KEYS) if (level[k] !== undefined) (t as unknown as Record<string, unknown>)[k] = level[k];
|
||||
if (level) for (const k of TEMPLATE_LEVEL_KEYS) if (level[k] !== undefined) (t as unknown as Record<string, unknown>)[k] = level[k];
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import type {
|
||||
Project,
|
||||
Vec2,
|
||||
} from "../model/types";
|
||||
import { createTable, PX_PER_M, sheetTables, TABLE_SOURCES, snapshotMono, snapshotOverrideRuleIds, tableSourceLabel, viewportLevelPlan } from "../core";
|
||||
import { createTable, PX_PER_M, sheetTables, TABLE_SOURCES, snapshotMono, snapshotOverrideRuleIds, snapshotTemplate, tableSourceLabel, viewportLevelPlan } from "../core";
|
||||
import type { TableOut } from "../core";
|
||||
import { SheetTableHud } from "./SheetTableHud";
|
||||
import { planToPrintSvg } from "../export/planToPrintSvg";
|
||||
@@ -89,7 +89,7 @@ export function ViewportPlanSvg({
|
||||
// Massstab ZUERST: er geht in die Plan-Erzeugung ein (Bemassung in Papier-mm, s. model/dimension.ts).
|
||||
const scaleN = resolveViewportScale(viewport, snap);
|
||||
// Geschoss/Zeichnung wie bisher; Schnitt/Ansicht über die abgeleitete Projektion ([115], Schnitt asynchron).
|
||||
void viewportLevelPlan(project, snap.activeLevelId, codes, snap.detail, scaleN, false, snapshotMono(project, snap), snapshotOverrideRuleIds(project, snap))
|
||||
void viewportLevelPlan(project, snap.activeLevelId, codes, snap.detail, scaleN, false, snapshotMono(project, snap), snapshotOverrideRuleIds(project, snap), snapshotTemplate(project, snap))
|
||||
.then((plan) => {
|
||||
if (disposed) return;
|
||||
const print = planToPrintSvg(plan, {
|
||||
|
||||
Reference in new issue
Block a user