Files
DOSSIER/src/plan/openingPreview.ts
T
Claude 3433d49c24 [122] Kern: verstecktes zweites Dokument abgeschafft (Fang mit Ausschluss, withDocument für abgewandelte Projekte)
documentFor findet nur offene Dokumente (Store, CLI, withDocument); kein sync/Differenz-Abgleich mehr.
Fang beim Ziehen: excludeIds -> doc_snap_hold(..., skip). Export/Publikation/Legende/Vorschau/Standards/
Stifte/Schnitt auf älterem Stand: kurzlebiges Dokument. Fremdes Projekt neben dem Store wirft in Dev/Tests.
2026-11-03 19:36:01 +00:00

64 lines
2.9 KiB
TypeScript

// Live-Vorschau einer Öffnung für den Fenster-/Tür-Dialog ([105]/[106]): Der Kern baut ein kleines
// Projekt (Abfrage `openingPreview`, `src-tauri/core/src/opening_preview.rs`: Wirtswand mit nur dieser
// Öffnung, Schnitt quer durch die Mitte, Ansicht von aussen); Grundriss, Schnitt und Ansicht rechnen die
// gewöhnlichen Kern-Fassaden, als SVG-Text (`planToSvgString`).
import type { DetailLevel, Project } from "../model/types";
import { documentFor, withDocument } from "../core/document";
import { generatePlan } from "./generatePlan";
import { computeSection, generateSectionPlan } from "./toSection";
import { generateElevationPlan } from "./toElevation";
import { planToSvgString } from "../export/planToSvgString";
export interface OpeningPreviewSvgs {
plan: string;
section: string | null;
elevation: string | null;
}
/** Vorschau-Projekt (oder `null`, wenn Öffnung/Wand fehlen). */
export function openingPreviewProject(project: Project, openingId: string): Project | null {
return documentFor(project).query<Project | null>("openingPreview", [], openingId);
}
/** Grundriss (Detailgrad `detail`), Schnitt und Ansicht der Öffnung als SVG-Text, Massstab 1:`scale`. */
export async function openingPreviewSvgs(project: Project, openingId: string, detail: DetailLevel = "fein", scale = 20): Promise<OpeningPreviewSvgs | null> {
const mini = openingPreviewProject(project, openingId);
if (!mini) return null;
// Das Vorschau-Projekt ist ein eigenes Projekt: eigenes, kurzlebiges Dokument ([122]).
return withDocument(mini, () => previewSvgs(mini, detail, scale));
}
async function previewSvgs(mini: Project, detail: DetailLevel, scale: number): Promise<OpeningPreviewSvgs> {
const codes = new Set<string>(["", ...collectCodes(mini)]);
const opts = { scaleDenominator: scale, marginM: 0.15 };
const plan = planToSvgString(generatePlan(mini, "preview-floor", codes, undefined, detail, false, false, false, scale), opts);
const secLevel = mini.drawingLevels.find((l) => l.id === "preview-section");
const elevLevel = mini.drawingLevels.find((l) => l.id === "preview-elevation");
let section: string | null = null;
if (secLevel) {
const out = await computeSection(mini, secLevel);
if (out) section = planToSvgString(generateSectionPlan(out, false, { visibleCodes: codes, openings: true }), opts);
}
let elevation: string | null = null;
if (elevLevel) {
const p = generateElevationPlan(mini, elevLevel, { visibleCodes: codes });
if (p) elevation = planToSvgString(p, opts);
}
return { plan, section, elevation };
}
function collectCodes(p: Project): string[] {
const out: string[] = [];
for (const w of p.walls) out.push(w.categoryCode);
for (const o of p.openings ?? []) out.push(o.categoryCode);
const walk = (cats: Project["layers"]) => {
for (const c of cats) {
out.push(c.code);
walk((c as { children?: Project["layers"] }).children ?? []);
}
};
walk(p.layers);
return out;
}