Merge [70] Flaechentabelle (Flaechenarten nach SIA 416) und IVHB-Kennziffern in Rust, Panel, CSV/SVG/PDF, CLI kennzahlen --sia416 --ivhb
Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
20 files changed
+1692
-25
No files matched your search
@@ -0,0 +1,123 @@
|
||||
// Flächentabelle (Flächenarten je Geschoss) und IVHB-Kennziffern im Flächenbilanz-Panel ([70]).
|
||||
//
|
||||
// • Die Tabellen stammen aus demselben Berichtsmodell wie CSV und PDF (`buildAreaReport`):
|
||||
// was hier steht, steht auch im Export.
|
||||
// • Eingaben, die das Modell nicht hergibt (anrechenbare Grundstücksfläche, Grünfläche, Basis der
|
||||
// aGF, Untergeschosse), liegen nur in der Ansicht (nicht im Projekt).
|
||||
// Herleitung der Zahlen: `src-tauri/core/src/flaechen.rs`.
|
||||
|
||||
import { useMemo, useState } from "react";
|
||||
import { t } from "../i18n";
|
||||
import { usePanelHost } from "./host";
|
||||
import { areaReportToCsv, buildAreaReport, buildAreaReportPdf } from "../core";
|
||||
import type { AgfBasis } from "../core";
|
||||
import { DEFAULT_AREA_INPUTS, ivhbOptionsOf, type AreaInputs } from "./areaInputs";
|
||||
import { downloadCsv } from "./downloadFile";
|
||||
import { useStore } from "../state/appStore";
|
||||
|
||||
const BASES: AgfBasis[] = ["ngf", "gf", "nf"];
|
||||
|
||||
export function AreaTableSection() {
|
||||
const host = usePanelHost();
|
||||
const project = host.project;
|
||||
const [inputs, setInputs] = useState<AreaInputs>(DEFAULT_AREA_INPUTS);
|
||||
const notify = useStore((s) => s.notify);
|
||||
const report = useMemo(
|
||||
() => buildAreaReport(project, { areas: true, ivhb: true, ivhbOptions: ivhbOptionsOf(inputs) }),
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[project, inputs],
|
||||
);
|
||||
const set = (patch: Partial<AreaInputs>) => setInputs((i) => ({ ...i, ...patch }));
|
||||
const stem = `${project.name || "projekt"}-flaechen`;
|
||||
|
||||
const exportPdf = () => {
|
||||
try {
|
||||
buildAreaReportPdf(report).save(`${stem}.pdf`);
|
||||
} catch {
|
||||
notify(t("areas.exportPdf.fail"));
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="area-section">
|
||||
<div className="balance-head">
|
||||
<span className="balance-section-label">{t("areas.title")}</span>
|
||||
<span className="area-actions">
|
||||
<button type="button" className="balance-export" onClick={() => downloadCsv(`${stem}.csv`, areaReportToCsv(report))}>
|
||||
{t("areas.exportCsv")}
|
||||
</button>
|
||||
<button type="button" className="balance-export" onClick={exportPdf}>
|
||||
{t("areas.exportPdf")}
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{report.sections.map((s, si) => (
|
||||
<div key={si} className="area-block">
|
||||
<div className="area-heading">{s.heading}</div>
|
||||
<div className="area-scroll">
|
||||
<table className="area-table">
|
||||
<thead>
|
||||
<tr>
|
||||
{s.columns.map((c, i) => (
|
||||
<th key={i} className={i === 0 ? "" : "num"}>
|
||||
{c}
|
||||
</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{s.rows.map((r, ri) => (
|
||||
<tr key={ri} className={r.total ? "total" : ""}>
|
||||
{r.cells.map((c, ci) =>
|
||||
typeof c === "string" ? (
|
||||
<td key={ci}>{c}</td>
|
||||
) : (
|
||||
<td key={ci} className="num">
|
||||
{c.n === null ? "–" : c.n.toFixed(c.d)}
|
||||
</td>
|
||||
),
|
||||
)}
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
|
||||
<div className="area-inputs">
|
||||
<label className="kz-parcel">
|
||||
<span>{t("areas.agsfInput")}</span>
|
||||
<input type="text" inputMode="decimal" className="kz-input kz-num" value={inputs.agsf} title={t("areas.agsfInput.hint")} onChange={(e) => set({ agsf: e.target.value })} />
|
||||
<span>m²</span>
|
||||
</label>
|
||||
<label className="kz-parcel">
|
||||
<span>{t("areas.greenInput")}</span>
|
||||
<input type="text" inputMode="decimal" className="kz-input kz-num" value={inputs.greenArea} title={t("areas.greenInput.hint")} onChange={(e) => set({ greenArea: e.target.value })} />
|
||||
<span>m²</span>
|
||||
</label>
|
||||
<label className="kz-parcel">
|
||||
<span>{t("areas.basisInput")}</span>
|
||||
<select className="kz-input" value={inputs.agfBasis} onChange={(e) => set({ agfBasis: e.target.value as AgfBasis })}>
|
||||
{BASES.map((b) => (
|
||||
<option key={b} value={b}>
|
||||
{t(`areas.basis.${b}`)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label className="kz-parcel">
|
||||
<span>{t("areas.includeUnderground")}</span>
|
||||
<input type="checkbox" checked={inputs.includeUnderground} onChange={(e) => set({ includeUnderground: e.target.checked })} />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<ul className="area-notes">
|
||||
{report.notes.map((n, i) => (
|
||||
<li key={i}>{n}</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
// Inhalts-Panel „Flächenbilanz" (SIA 416) — listet alle Räume gruppiert nach
|
||||
// ihrer SIA-416-Blatt-Kategorie mit Zwischen-/Gesamtsummen und bietet einen
|
||||
// Inhalts-Panel „Flächenbilanz" — listet alle Räume gruppiert nach
|
||||
// ihrer Flächenart (SIA 416) mit Zwischen-/Gesamtsummen und bietet einen
|
||||
// CSV-Export, darüber die Kennzahlenleiste mit Parzelle und Raumprogramm
|
||||
// (KennzahlenSection). Fläche/Bilanz werden LIVE aus den Raum-Umrissen abgeleitet
|
||||
// (geometry/roomArea: evaluateRoom/balance/roomsToCsv) — nie gespeichert.
|
||||
@@ -13,6 +13,8 @@ import { balance, evaluateRoom, roomsToCsv, siaLabelFull } from "../core";
|
||||
import type { Room } from "../model/types";
|
||||
import { roomDisplayName } from "../model/roomStamp";
|
||||
import { KennzahlenSection } from "./KennzahlenSection";
|
||||
import { AreaTableSection } from "./AreaTableSection";
|
||||
import { downloadCsv } from "./downloadFile";
|
||||
|
||||
/** Löst je Raum die anrechenbare (Netto-)Fläche + Kategorie auf. */
|
||||
function roomAreas(rooms: Room[]): { category: Room["siaCategory"]; area: number }[] {
|
||||
@@ -30,22 +32,6 @@ function floorNameOf(
|
||||
return levels.find((z) => z.id === floorId)?.name ?? floorId;
|
||||
}
|
||||
|
||||
/** Stösst den Download einer CSV-Datei an (reiner Client, Blob-URL). */
|
||||
function downloadCsv(fileName: string, content: string): void {
|
||||
// BOM voranstellen, damit Excel UTF-8 (Umlaute/„m²") korrekt liest.
|
||||
const blob = new Blob(["" + content], {
|
||||
type: "text/csv;charset=utf-8;",
|
||||
});
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = fileName;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
export function RoomBalancePanel() {
|
||||
const host = usePanelHost();
|
||||
const rooms = host.project.rooms ?? [];
|
||||
@@ -55,6 +41,7 @@ export function RoomBalancePanel() {
|
||||
return (
|
||||
<div className="balance-panel">
|
||||
<KennzahlenSection />
|
||||
<AreaTableSection />
|
||||
<div className="balance-empty">{t("balance.empty")}</div>
|
||||
</div>
|
||||
);
|
||||
@@ -87,6 +74,9 @@ export function RoomBalancePanel() {
|
||||
{/* Kennzahlenleiste, Parzelle und Raumprogramm. */}
|
||||
<KennzahlenSection />
|
||||
|
||||
{/* Flächentabelle und IVHB-Kennziffern. */}
|
||||
<AreaTableSection />
|
||||
|
||||
{/* Raumliste (je Raum: Name · Geschoss · SIA · Fläche). */}
|
||||
<div className="balance-section-label">{t("balance.rooms")}</div>
|
||||
<div className="balance-table">
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { DEFAULT_AREA_INPUTS, ivhbOptionsOf, parseAreaNumber } from "./areaInputs";
|
||||
|
||||
describe("Flächen-Eingaben", () => {
|
||||
it("Komma und Punkt, leer und Unsinn", () => {
|
||||
expect(parseAreaNumber("412,5")).toBe(412.5);
|
||||
expect(parseAreaNumber(" 300.25 ")).toBe(300.25);
|
||||
expect(parseAreaNumber("")).toBeUndefined();
|
||||
expect(parseAreaNumber("abc")).toBeUndefined();
|
||||
expect(parseAreaNumber("-3")).toBeUndefined();
|
||||
expect(parseAreaNumber("Infinity")).toBeUndefined();
|
||||
});
|
||||
it("Optionen für den Kern", () => {
|
||||
expect(ivhbOptionsOf(DEFAULT_AREA_INPUTS)).toEqual({ agsf: undefined, greenArea: undefined, agfBasis: "ngf", includeUnderground: false });
|
||||
expect(ivhbOptionsOf({ agsf: "500", greenArea: "120,5", agfBasis: "gf", includeUnderground: true })).toEqual({
|
||||
agsf: 500,
|
||||
greenArea: 120.5,
|
||||
agfBasis: "gf",
|
||||
includeUnderground: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,26 @@
|
||||
// Eingaben und Hilfen des Flächen-Nachweises im Flächenbilanz-Panel ([70]).
|
||||
|
||||
import type { AgfBasis, IvhbOptions } from "../core";
|
||||
|
||||
/** Eingaben, die das Modell nicht hergibt; als Text, damit halbfertiges Tippen erhalten bleibt. */
|
||||
export interface AreaInputs {
|
||||
agsf: string;
|
||||
greenArea: string;
|
||||
agfBasis: AgfBasis;
|
||||
includeUnderground: boolean;
|
||||
}
|
||||
|
||||
export const DEFAULT_AREA_INPUTS: AreaInputs = { agsf: "", greenArea: "", agfBasis: "ngf", includeUnderground: false };
|
||||
|
||||
/** Zahl aus einer Eingabe (Komma oder Punkt); leer/ungültig/negativ → undefined. */
|
||||
export function parseAreaNumber(text: string): number | undefined {
|
||||
const s = text.trim().replace(",", ".");
|
||||
if (s === "") return undefined;
|
||||
const v = Number(s);
|
||||
return Number.isFinite(v) && v >= 0 ? v : undefined;
|
||||
}
|
||||
|
||||
/** Eingaben → Optionen für den Kern. */
|
||||
export function ivhbOptionsOf(i: AreaInputs): IvhbOptions {
|
||||
return { agsf: parseAreaNumber(i.agsf), greenArea: parseAreaNumber(i.greenArea), agfBasis: i.agfBasis, includeUnderground: i.includeUnderground };
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// Stösst den Download einer Datei an (reiner Client, Blob-URL).
|
||||
|
||||
export function downloadFile(fileName: string, blob: Blob): void {
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = fileName;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
/** CSV mit BOM, damit Excel UTF-8 (Umlaute/„m²") korrekt liest. */
|
||||
export function downloadCsv(fileName: string, content: string): void {
|
||||
downloadFile(fileName, new Blob(["" + content], { type: "text/csv;charset=utf-8;" }));
|
||||
}
|
||||
Reference in new issue
Block a user