[71][111] U-Werte aus dem Schichtaufbau (SIA 180) und lebendige Tabellen auf Layout-Blättern

[71] Kern u_value.rs: R = Rsi + Σ d/λ + Rse, hinterlüftete Schichten, Luftschicht, unvollständig ohne λ; Objekt-Info,
Ressourcen-Manager, Bauteilliste (CSV/PDF, CLI --elements), IFC ThermalTransmittance in Wand/Decke/Dach.
[111] Layout.tables: Fenster-/Türliste, Flächen SIA 416, Raumprogramm, Bauteile mit U-Wert als Tabelle auf dem Blatt
(Spaltenwahl, Schrift, Zeilenhöhe, Linien, Aufteilen auf mehrere Rahmen); Blattansicht, PDF (Vektortext), DXF.
This commit is contained in:
Claude committed 2026-10-30 06:09:50 +00:00
1 parent b2f66c777c
commit a3bc168f2d
31 files changed
+2274 -14

No files matched your search

+75
View File
@@ -0,0 +1,75 @@
// Bauteilliste und U-Werte ([71], SIA 180 / EN ISO 6946): je Wand, Decke und Dach Typ, Fläche und U-Wert aus
// dem Schichtaufbau (λ je Bauteil). Gerechnet wird im Kern (`src-tauri/core/src/u_value.rs`, Abfragen
// `elementSchedule` und `uValue`); hier nur Beschriftung mit `t()` und das Berichtsmodell für CSV/SVG/PDF
// (wie die Fenster-/Türliste, `openingSchedule.ts`).
import type { Layer, Project } from "../model/types";
import { t } from "../i18n";
import { documentFor } from "../core/document";
import type { AreaReport, Cell, ReportRow } from "./areaReport";
export type ElementKind = "wall" | "ceiling" | "roof";
/** Eine Zeile der Bauteilliste (Form wie `ElementRow` im Kern). */
export interface ElementScheduleRow {
kind: ElementKind;
id: string;
typeName: string;
floor: string;
floorId: string;
/** m². */
area: number;
/** Aufbaudicke in Metern. */
thickness: number;
/** `null` = unvollständig (Schicht ohne λ) oder kein Aufbau. */
u: number | null;
complete: boolean;
external: boolean | null;
}
/** Ergebnis der U-Wert-Rechnung (Form wie `UValue` im Kern). */
export interface UValueResult {
/** Gesamtwiderstand m²K/W (Teilsumme, wenn unvollständig). */
r: number;
u: number | null;
complete: boolean;
/** Schichten ohne λ. */
missing: number;
/** Hinterlüftete Schicht: Aussenseite zählt nicht. */
ventilated: boolean;
}
export function elementSchedule(project: Project): ElementScheduleRow[] {
return documentFor(project).query<ElementScheduleRow[]>("elementSchedule");
}
/** U-Wert eines Typs (`typeId`) oder eines Schichtaufbaus (`layers`, z. B. beim Bearbeiten). `null` = unbekannter Typ. */
export function uValueOf(project: Project, kind: ElementKind, source: { typeId: string } | { layers: readonly Layer[] }): UValueResult | null {
return documentFor(project).query<UValueResult | null>("uValue", [], JSON.stringify({ kind, ...source }));
}
/** „0.21" bzw. „–" (unvollständig). */
export function uValueText(u: UValueResult | null): string {
return u && u.u !== null ? u.u.toFixed(2) : "–";
}
const num = (n: number | null, d: number): Cell => ({ n: n !== null && Number.isFinite(n) ? n : null, d });
function externalText(e: boolean | null): string {
return e === null ? "" : e ? t("openings.external") : t("openings.internal");
}
/** Bericht „Bauteilliste": ein Abschnitt je Art (nur wenn vorhanden). */
export function buildElementReport(project: Project): AreaReport {
const rows = elementSchedule(project);
const sections = (["wall", "ceiling", "roof"] as const)
.map((kind) => ({ kind, list: rows.filter((r) => r.kind === kind) }))
.filter((g) => g.list.length > 0)
.map((g) => ({
heading: t(`elemSchedule.kind.${g.kind}`),
columns: [t("elemSchedule.col.type"), t("openings.col.floor"), t("elemSchedule.col.area"), t("elemSchedule.col.thickness"), t("openings.col.u"), t("openings.col.ext")],
widths: [4, 1.6, 1.4, 1.3, 1.3, 1.4],
rows: g.list.map((r): ReportRow => ({ cells: [r.typeName, r.floor, num(r.area, 2), num(r.thickness * 100, 1), r.u === null ? t("elemSchedule.incomplete") : num(r.u, 2), externalText(r.external)] })),
}));
return { title: t("elemSchedule.title"), projectName: project.name ?? "", sections, notes: [t("elemSchedule.foot")] };
}
+2 -1
View File
@@ -33,6 +33,7 @@ import { DEFAULT_SCALE_DENOMINATOR } from "../model/dimension";
import { fileio, loadFileio } from "../engine/fileioWasm";
import { core } from "../engine/coreWasm";
import { documentFor } from "../core/document";
import { tableLabels } from "./sheetTable";
import { planParts, withPlanParts } from "../plan/planParts";
export interface ExportDxfOptions {
@@ -138,7 +139,7 @@ export function collectPlanDrawing(
const o = Float64Array.of(scale, (opts.includeHatches ?? true) ? 1 : 0, opts.dimUnit === "cm" ? 1 : 0, opts.paperLayout ? 1 : 0, b.minX, b.minY, b.maxX, b.maxY);
const doc = documentFor(project).id;
// Eigener Puffer mit Schraffur-JSON (Verlauf-Schraffuren brauchen ihre Farben).
const bytes = withPlanParts(planParts(plan, true), (segs) => core().plan_dxf_flat(doc, segs, o, opts.levelId ?? ""));
const bytes = withPlanParts(planParts(plan, true), (segs) => core().plan_dxf_flat(doc, segs, o, opts.levelId ?? "", JSON.stringify(tableLabels(project))));
return decodeFlat(bytes);
}
+8
View File
@@ -15,6 +15,7 @@ import "svg2pdf.js";
import type { Layout, MasterLayout, Project } from "../model/types";
import { generatePlan } from "../plan/generatePlan";
import { planToPrintSvg } from "./planToPrintSvg";
import { drawTablesPdf, sheetTables } from "./sheetTable";
import { collectVisibleCodes } from "../model/types";
import {
findMaster,
@@ -170,6 +171,13 @@ async function renderPage(
drawTitleBlock(doc, widthMm, heightMm, tb, layout.paper, layout.orientation);
}
// Lebendige Tabellen ([111]): Vektortext + Linien wie in der Blattansicht.
try {
drawTablesPdf(doc, sheetTables(project, layout.id));
} catch {
// Eine Tabelle, die nicht rechnet, darf die Seite nicht killen.
}
// 2D-Zeichnung des Blatts — ÜBER Viewports + Master, wie am Bildschirm.
try {
await renderSheetDrawing(doc, project, layout, widthMm, heightMm);
+109
View File
@@ -0,0 +1,109 @@
import { describe, expect, it } from "vitest";
import { jsPDF } from "jspdf";
import { sampleProject } from "../model/sampleProject";
import type { Layout, LayoutTable, Opening, Project } from "../model/types";
import { drawTablesPdf, sheetTables, tableCatalog, tableLabels } from "./sheetTable";
import { buildElementReport, elementSchedule, uValueOf } from "./elementSchedule";
import { collectPlanDrawing } from "./exportDxf";
import { generatePlan } from "../plan/generatePlan";
const table = (over: Partial<LayoutTable> = {}): LayoutTable => ({ id: "tb", source: "openings", xMm: 10, yMm: 20, widthMm: 180, ...over });
function withTables(tables: LayoutTable[], p: Project = sampleProject): Project {
const layout: Layout = { id: "L1", name: "Blatt", paper: "a3", orientation: "landscape", viewports: [], tables };
return { ...p, layouts: [layout] };
}
/** Sichtbarer Text einer PDF-Seite (unkomprimierter Inhaltsstrom: `(text) Tj`). */
function pdfText(doc: jsPDF): string {
return doc.output();
}
describe("Tabellen auf dem Blatt ([111])", () => {
it("Fenster-/Türliste: eine Zeile je Öffnung, wächst mit dem Modell", () => {
const p = withTables([table()]);
const n = (p.openings ?? []).length;
const [a] = sheetTables(p, "L1");
expect(a.total).toBe(n);
expect(a.shown).toBe(n);
const texts = a.prims.filter((x) => x.k === "text").map((x) => (x as { s: string }).s);
expect(texts).toContain("F1.01");
// Ein weiteres Fenster im Modell: die Tabelle hat eine Zeile mehr und ist höher.
const first = (p.openings ?? []).find((o) => o.kind === "window")!;
const extra: Opening = { ...first, id: "neu-fenster", mark: "F-NEU" };
const p2: Project = { ...p, openings: [...(p.openings ?? []), extra] };
const [b] = sheetTables(p2, "L1");
expect(b.total).toBe(n + 1);
expect(b.heightMm).toBeGreaterThan(a.heightMm);
expect(b.prims.some((x) => x.k === "text" && x.s === "F-NEU")).toBe(true);
});
it("Spaltenwahl, Filter und Aufteilen auf zwei Rahmen", () => {
const p = withTables([
table({ id: "a", columns: ["mark", "type"], filter: "window", heightMm: 12 }),
table({ id: "b", continues: "a", xMm: 100, heightMm: 40 }),
]);
const [a, b] = sheetTables(p, "L1");
const windows = (p.openings ?? []).filter((o) => o.kind === "window").length;
expect(a.total).toBe(windows);
expect(a.shown).toBeLessThan(windows); // 12 mm = Kopf + 1 Zeile
expect(b.shown).toBeGreaterThan(0);
expect(a.shown + b.shown + b.hidden).toBe(windows);
// Die Fortsetzung erbt Quelle, Spalten und Filter.
expect(b.prims.filter((x) => x.k === "text" && x.s === tableLabels(p)["openings.col.mark"]).length).toBe(1);
});
it("alle vier Quellen liefern Primitive; Katalog nennt die Spalten", () => {
const cat = tableCatalog(sampleProject);
expect(Object.keys(cat.sources).sort()).toEqual(["areas", "elements", "openings", "rooms"]);
const p = withTables((["openings", "areas", "rooms", "elements"] as const).map((source) => table({ id: source, source })));
const out = sheetTables(p, "L1");
expect(out.map((o) => o.id)).toEqual(["openings", "areas", "rooms", "elements"]);
for (const o of out) expect(o.prims.some((x) => x.k === "text")).toBe(true);
});
it("PDF: Tabellentext als Vektor (Text im Inhaltsstrom)", () => {
const p = withTables([table({ columns: ["mark", "type", "width"] })]);
const doc = new jsPDF({ unit: "mm", format: [420, 297], orientation: "landscape", compress: false });
drawTablesPdf(doc, sheetTables(p, "L1"));
const pdf = pdfText(doc);
expect(pdf).toContain("(F1.01)");
expect(pdf).toContain(`(${tableLabels(p)["openings.col.mark"]})`);
});
it("DXF-Layout: Tabelle als Block mit Text", () => {
const p = withTables([table({ columns: ["mark", "type"] })]);
const plan = generatePlan(p, p.drawingLevels[0]!.id, new Set(), undefined, "fein", false, false, false, 100, true);
const texts = String(collectPlanDrawing(plan, p, { paperLayout: true, levelId: p.drawingLevels[0]!.id }).args()[1]).split("\0");
expect(texts).toContain("SHEETTAB_1");
expect(texts).toContain("F1.01");
expect(texts).toContain(tableLabels(p)["openings.col.mark"]);
});
});
describe("Bauteilliste und U-Wert ([71])", () => {
it("Beispielprojekt: Zeilen je Wand, U-Wert aus den Schichten", () => {
const rows = elementSchedule(sampleProject);
expect(rows.length).toBeGreaterThanOrEqual(sampleProject.walls.length);
for (const r of rows.filter((x) => x.complete)) expect(r.u!).toBeGreaterThan(0);
const rep = buildElementReport(sampleProject);
expect(rep.sections.length).toBeGreaterThan(0);
});
it("Aufbau ohne λ ist unvollständig, mit λ handgerechnet", () => {
const comps = [
{ ...sampleProject.components[0]!, id: "c-b", lambda: 2.3 },
{ ...sampleProject.components[0]!, id: "c-d", lambda: 0.035 },
{ ...sampleProject.components[0]!, id: "c-x", lambda: undefined },
];
const p: Project = { ...sampleProject, components: comps };
const layers = (ids: string[]) => ids.map((componentId, i) => ({ componentId, thickness: [0.16, 0.2, 0.1][i]! }));
const ok = uValueOf(p, "wall", { layers: layers(["c-d", "c-b"]) })!;
expect(ok.complete).toBe(true);
expect(ok.u!).toBeCloseTo(1 / (0.17 + 0.16 / 0.035 + 0.2 / 2.3), 6);
const bad = uValueOf(p, "wall", { layers: layers(["c-x", "c-b"]) })!;
expect(bad.complete).toBe(false);
expect(bad.u).toBeNull();
expect(bad.missing).toBe(1);
});
});
+100
View File
@@ -0,0 +1,100 @@
// Tabellen auf Layout-Blättern ([111]): lebendige Listen des Modells (Fenster/Türen, Flächen SIA 416,
// Raumprogramm, Bauteile mit U-Wert) als Primitive in Papier-mm. Gerechnet wird im Kern
// (`src-tauri/core/src/sheet_table.rs`, Abfrage `sheetTables`); hier nur die Beschriftung mit `t()`, die Kern-
// Fassade und das Zeichnen ins jsPDF (Vektortext) — dieselben Primitive wie Blattansicht und DXF.
import type { jsPDF } from "jspdf";
import type { Layout, LayoutTable, LayoutTableSource, Project } from "../model/types";
import { t } from "../i18n";
import { documentFor } from "../core/document";
export type { LayoutTable, LayoutTableSource };
export type TablePrim =
| { k: "text"; x: number; y: number; s: string; size: number; bold: boolean; italic: boolean; font: "sans" | "serif" | "mono"; align: "l" | "r" }
| { k: "line"; x1: number; y1: number; x2: number; y2: number; w: number };
export interface TableOut {
id: string;
prims: TablePrim[];
widthMm: number;
/** Tatsächlich gezeichnete Höhe. */
heightMm: number;
total: number;
shown: number;
/** Zeilen, die weder hier noch in einer Folgetabelle Platz finden. */
hidden: number;
}
export interface TableColumn {
id: string;
key: string;
numeric: boolean;
default: boolean;
}
interface Catalog {
sources: Record<LayoutTableSource, TableColumn[]>;
valueKeys: string[];
}
export const TABLE_SOURCES: readonly LayoutTableSource[] = ["openings", "areas", "rooms", "elements"];
export function tableSourceLabel(s: LayoutTableSource): string {
return t(`sheetTable.source.${s}`);
}
let catalogCache: Catalog | null = null;
/** Spalten je Quelle (Kern-Katalog; ändert sich nie zur Laufzeit). */
export function tableCatalog(project: Project): Catalog {
catalogCache ??= documentFor(project).query<Catalog>("sheetTableCatalog");
return catalogCache;
}
/** Beschriftungen in der aktuellen Sprache für alle Spalten und Werttexte. */
export function tableLabels(project: Project): Record<string, string> {
const cat = tableCatalog(project);
const labels: Record<string, string> = {};
for (const cols of Object.values(cat.sources)) for (const c of cols) labels[c.key] = t(c.key);
for (const k of cat.valueKeys) labels[k] = t(k);
return labels;
}
/** Alle Tabellen eines Blatts als Primitive (folgt dem Modell). */
export function sheetTables(project: Project, layoutId: string): TableOut[] {
if (!(project.layouts ?? []).some((l) => l.id === layoutId && (l.tables ?? []).length > 0)) return [];
return documentFor(project).query<TableOut[]>("sheetTables", [], JSON.stringify({ layoutId, labels: tableLabels(project) }));
}
/** Neue Tabelle mit sinnvollen Vorgaben (links, Breite nach Blatt, unter den vorhandenen). */
export function createTable(id: string, source: LayoutTableSource, sheetW: number, sheetH: number, existing: readonly LayoutTable[]): LayoutTable {
const width = Math.max(40, Math.min(sheetW - 20, 180));
const y = Math.min(10 + existing.length * 12, Math.max(10, sheetH - 40));
return { id, source, xMm: 10, yMm: y, widthMm: width };
}
const PDF_FONT = { sans: "helvetica", serif: "times", mono: "courier" } as const;
const PT_PER_MM = 72 / 25.4;
/** Zeichnet die Tabellen eines Blatts als Vektor (Text + Linien) auf die aktuelle jsPDF-Seite. */
export function drawTablesPdf(doc: jsPDF, tables: readonly TableOut[]): void {
doc.setTextColor(17, 17, 17);
doc.setDrawColor(17, 17, 17);
for (const tb of tables) {
for (const p of tb.prims) {
if (p.k === "line") {
doc.setLineWidth(p.w);
doc.line(p.x1, p.y1, p.x2, p.y2);
} else {
doc.setFont(PDF_FONT[p.font], p.bold && p.italic ? "bolditalic" : p.bold ? "bold" : p.italic ? "italic" : "normal");
doc.setFontSize(p.size * PT_PER_MM);
doc.text(p.s, p.x, p.y, { align: p.align === "r" ? "right" : "left" });
}
}
}
}
export function layoutTables(layout: Layout): LayoutTable[] {
return layout.tables ?? [];
}