[64][59][62][61] Schattenstudie im Grundriss mit Zeitregler, Kennzahlenleiste mit Parzelle und Raumprogramm-Editor

- Project.sunStudy (Zeitpunkt UTC, Schalter): Boden-Schatten zuunterst im Geschoss naechst +-0.00
  (plan/generatePlan/sunShadow.ts), Hoefe als Loecher (shadowPolygons liefert Ringe, withoutHoles zerlegt)
- Lage-Panel: Schalter, Datum, Merkdaten 21.3./21.6./21.12., Zeitregler in Ortszeit, Sonnenstand
- Flaechenbilanz-Panel: Kennzahlenleiste GF/aGF/GV/AZ/UeZ, Parzellenflaeche, Raumprogramm bearbeiten mit Status
- checkRoomProgram: leerer Name trifft keine Raeume mehr; Status im Toast uebersetzt
- Doc-Kommentar von DrawingLevel wieder am richtigen Interface

Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
Claude committed 2026-10-27 19:54:17 +00:00
1 parent 9867baa090
commit 0c84c50669
19 files changed
+702 -18

No files matched your search

+2 -1
View File
@@ -35,6 +35,7 @@ import type {
import { activePenSet, resolvePenColor, resolvePenWeight } from "./model/penSets";
import { PenColorField } from "./ui/PenColorField";
import { generatePlan, computeKennzahlen, checkRoomProgram } from "./core";
import { programStatusLabel } from "./panels/KennzahlenSection";
import type { CategoryDisplayResolver } from "./core";
import { sectionPlaneFromLevel, sectionUAxisModel } from "./core";
import { roofBaseElevation, roofGeometry } from "./core";
@@ -2420,7 +2421,7 @@ export default function App() {
if (prog.rows.length > 0) {
const bad = prog.rows.filter((r) => r.status !== "ok");
lines.push(t("kennzahlen.program", { ok: prog.rows.length - bad.length, n: prog.rows.length }));
for (const r of bad.slice(0, 4)) lines.push(t("kennzahlen.programIssue", { name: r.name, status: r.status }));
for (const r of bad.slice(0, 4)) lines.push(t("kennzahlen.programIssue", { name: r.name, status: programStatusLabel(r.status) }));
}
notify(lines.join(" — "), "info");
},
+10
View File
@@ -72,3 +72,13 @@ describe("checkRoomProgram", () => {
expect(r.extra.map((e) => e.name)).toEqual(["Keller"]);
});
});
describe("checkRoomProgram mit unfertiger Zeile", () => {
it("leerer Name zieht keine Räume an sich", () => {
const n = (sampleProject.rooms ?? []).length;
const c = checkRoomProgram({ ...sampleProject, roomProgram: [{ name: " ", area: 10 }] });
expect(c.rows[0].status).toBe("fehlt");
expect(c.rows[0].count).toBe(0);
expect(c.extra.length).toBe(n);
});
});
+2 -1
View File
@@ -105,7 +105,8 @@ export function checkRoomProgram(project: Project): ProgramCheck {
const used = new Set<string>();
const rows: ProgramRowResult[] = (project.roomProgram ?? []).map((row) => {
const n = norm(row.name);
const hits = rooms.filter((r) => !used.has(r.id) && norm(r.name).startsWith(n) && (!row.siaCategory || r.cat === row.siaCategory));
// Leerer Name (Zeile im Editor noch unfertig) trifft nichts — „" wäre Präfix jedes Raums.
const hits = rooms.filter((r) => n !== "" && !used.has(r.id) && norm(r.name).startsWith(n) && (!row.siaCategory || r.cat === row.siaCategory));
hits.forEach((h) => used.add(h.id));
const targetCount = Math.max(1, row.count ?? 1);
const area = hits.reduce((s, h) => s + h.area, 0);
+31 -1
View File
@@ -1,5 +1,7 @@
import { describe, expect, it } from "vitest";
import { sunPosition, shadowOfPrism, shadowPolygons } from "./sun";
import { sunPosition, shadowOfPrism, shadowPolygons, withoutHoles } from "./sun";
import { polygonArea } from "../geometry/roomArea";
import type { Vec2 } from "../model/types";
import { sampleProject } from "../model/sampleProject";
describe("sunPosition", () => {
@@ -36,3 +38,31 @@ describe("Schatten", () => {
expect(shadowPolygons(sampleProject, { azimuth: 200, elevation: -3 })).toEqual([]);
});
});
describe("Schatten mit Hof", () => {
// Quadratischer Ring (aussen 20 m, Hof 10 m) als Polygon mit Loch.
const ring = (x0: number, y0: number, s: number): Vec2[] => [
{ x: x0, y: y0 }, { x: x0 + s, y: y0 }, { x: x0 + s, y: y0 + s }, { x: x0, y: y0 + s },
];
const courtyard = [ring(0, 0, 20), ring(5, 5, 10).reverse()];
it("lochfreie Teile haben dieselbe Fläche wie Aussenring minus Hof", () => {
const parts = withoutHoles(courtyard);
expect(parts.length).toBeGreaterThan(1);
const sum = parts.reduce((s, p) => s + Math.abs(polygonArea(p)), 0);
expect(sum).toBeCloseTo(400 - 100, 6);
// Kein Teil enthält den Hofmittelpunkt.
for (const p of parts) {
const xs = p.map((q) => q.x);
const ys = p.map((q) => q.y);
const inside = Math.min(...xs) < 10 && Math.max(...xs) > 10 && Math.min(...ys) < 10 && Math.max(...ys) > 10;
expect(inside && Math.abs(polygonArea(p)) > 150).toBe(false);
}
});
it("ohne Loch bleibt das Polygon unverändert", () => {
expect(withoutHoles([ring(0, 0, 3)])).toEqual([ring(0, 0, 3)]);
});
it("Projekt-Schatten: erster Ring je Polygon ist der Aussenring", () => {
const polys = shadowPolygons(sampleProject, { azimuth: 200, elevation: 30 });
for (const p of polys) expect(p[0].length).toBeGreaterThanOrEqual(3);
});
});
+41 -4
View File
@@ -89,8 +89,11 @@ export function shadowOfPrism(footprint: Vec2[], zBottom: number, zTop: number,
return hull(pts);
}
/** Vereinigter Schatten aller Wände, Körper und Dächer als Polygone (Aussenring + Löcher je Eintrag). */
export function shadowPolygons(project: Project, sun: SunPosition): Vec2[][] {
/** Ein Schatten-Polygon: `[0]` Aussenring, weitere Ringe sind Löcher (Höfe). Ringe offen (ohne Wiederholung des Startpunkts). */
export type ShadowPolygon = Vec2[][];
/** Vereinigter Schatten aller Wände, Körper und Dächer (leer bei Nacht). */
export function shadowPolygons(project: Project, sun: SunPosition): ShadowPolygon[] {
if (shadowShift(sun) === null) return [];
const parts: Vec2[][] = [];
for (const w of project.walls) {
@@ -138,8 +141,42 @@ export function shadowPolygons(project: Project, sun: SunPosition): Vec2[][] {
.map((p) => [[...p.map((q): Pair => [q.x, q.y]), [p[0].x, p[0].y] as Pair]]);
if (polys.length === 0) return [];
const union = polygonClipping.union(polys[0], ...polys.slice(1));
// Pro Teilpolygon nur der Aussenring (Löcher eines Schattens sind Hofflächen: bewusst mitgeben).
return union.map((poly) => poly.map((ring) => ring.slice(0, -1).map(([x, y]) => ({ x, y }))));
}
/**
* Zerlegt ein Polygon mit Löchern in lochfreie Teile gleicher Gesamtfläche (für Ausgaben, die
* nur einfache Polygone füllen, z. B. das Plan-Primitiv). Jedes Loch wird von einer senkrechten
* Schnittlinie durch seinen Mittelpunkt geteilt; in den Streifen dazwischen berührt jeder
* Lochrest den Streifenrand und ist damit kein Loch mehr.
*/
export function withoutHoles(poly: ShadowPolygon): Vec2[][] {
const outer = poly[0];
if (!outer || outer.length < 3) return [];
if (poly.length === 1) return [outer];
const toPc = (ring: Vec2[]): Pair[] => [...ring.map((q): Pair => [q.x, q.y]), [ring[0].x, ring[0].y]];
const pc: PcPolygon = poly.filter((r) => r.length >= 3).map(toPc);
let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity;
for (const p of outer) {
minX = Math.min(minX, p.x); maxX = Math.max(maxX, p.x);
minY = Math.min(minY, p.y); maxY = Math.max(maxY, p.y);
}
const cuts = poly
.slice(1)
.filter((r) => r.length >= 3)
.map((r) => {
const xs = r.map((p) => p.x);
return (Math.min(...xs) + Math.max(...xs)) / 2;
})
.sort((a, b) => a - b);
const xs = [minX - 1, ...cuts, maxX + 1];
const out: Vec2[][] = [];
for (const poly of union) for (const ring of poly) out.push(ring.slice(0, -1).map(([x, y]) => ({ x, y })));
for (let i = 0; i + 1 < xs.length; i++) {
if (xs[i + 1] - xs[i] < 1e-9) continue;
const slab: PcPolygon = [[[xs[i], minY - 1], [xs[i + 1], minY - 1], [xs[i + 1], maxY + 1], [xs[i], maxY + 1], [xs[i], minY - 1]]];
for (const piece of polygonClipping.intersection(pc, slab)) {
if (piece[0].length >= 4) out.push(piece[0].slice(0, -1).map(([x, y]) => ({ x, y })));
}
}
return out;
}
+31
View File
@@ -1772,6 +1772,37 @@ export const de = {
"kennzahlen.noParcel": "Parzellenfläche nicht gesetzt (keine AZ/ÜZ)",
"kennzahlen.program": "Raumprogramm: {ok} von {n} erfüllt",
"kennzahlen.programIssue": "{name}: {status}",
"kennzahlen.gf": "Geschossfläche (SIA 416) aus den Räumen",
"kennzahlen.agf": "Anrechenbare Geschossfläche ≈ NGF",
"kennzahlen.gv": "Gebäudevolumen aus den freien Körpern",
"kennzahlen.az": "Ausnützungsziffer aGF / Parzelle",
"kennzahlen.uez": "Überbauungsziffer bebaute Fläche / Parzelle",
"kennzahlen.parcelArea": "Parzellenfläche",
"program.title": "Raumprogramm",
"program.name": "Name",
"program.namePlaceholder": "Raumname",
"program.area": "m² je Raum",
"program.count": "Anz.",
"program.status": "Stand",
"program.actual": "Gezeichnet: {count} Räume, {area} m²",
"program.remove": "Zeile entfernen",
"program.add": "+ Programmzeile",
"program.extra": "{n} Räume ohne Programmzeile",
"program.status.ok": "erfüllt",
"program.status.tooSmall": "zu klein",
"program.status.tooLarge": "zu gross",
"program.status.missing": "fehlt",
"program.status.tooFew": "zu wenige",
"program.status.tooMany": "zu viele",
"sun.show": "Schatten im Grundriss zeigen",
"sun.time": "Uhrzeit",
"sun.equinox": "Tagundnachtgleiche",
"sun.summer": "Sommersonnenwende",
"sun.winter": "Wintersonnenwende",
"sun.position": "Sonne: Azimut {az}°, Höhe {el}°",
"sun.belowHorizon": "Sonne unter dem Horizont",
"sun.noAnchor": "Standort Zürich angenommen",
"sun.noAnchor.hint": "Ohne Georeferenz rechnet die Studie mit Zürich. Standort über «Standort importieren» oder «Neuer Bezugspunkt» festlegen.",
"clash.none": "Keine Kollisionen gefunden.",
"clash.found": "Kollisionen gefunden",
"clash.failed": "Kollisionsprüfung fehlgeschlagen",
+31
View File
@@ -1733,6 +1733,37 @@ export const en: Record<TranslationKey, string> = {
"kennzahlen.noParcel": "Site area not set (no FAR/coverage)",
"kennzahlen.program": "Room programme: {ok} of {n} met",
"kennzahlen.programIssue": "{name}: {status}",
"kennzahlen.gf": "Gross floor area (SIA 416) from rooms",
"kennzahlen.agf": "Chargeable floor area ≈ net floor area",
"kennzahlen.gv": "Building volume from the free solids",
"kennzahlen.az": "Floor area ratio (usable area / site)",
"kennzahlen.uez": "Site coverage (built area / site)",
"kennzahlen.parcelArea": "Site area",
"program.title": "Room programme",
"program.name": "Name",
"program.namePlaceholder": "Room name",
"program.area": "m² per room",
"program.count": "Qty",
"program.status": "Status",
"program.actual": "Drawn: {count} rooms, {area} m²",
"program.remove": "Remove row",
"program.add": "+ Programme row",
"program.extra": "{n} rooms without programme row",
"program.status.ok": "met",
"program.status.tooSmall": "too small",
"program.status.tooLarge": "too large",
"program.status.missing": "missing",
"program.status.tooFew": "too few",
"program.status.tooMany": "too many",
"sun.show": "Show shadows in plan",
"sun.time": "Time of day",
"sun.equinox": "Equinox",
"sun.summer": "Summer solstice",
"sun.winter": "Winter solstice",
"sun.position": "Sun: azimuth {az}°, altitude {el}°",
"sun.belowHorizon": "Sun below the horizon",
"sun.noAnchor": "Location assumed: Zurich",
"sun.noAnchor.hint": "Without georeference the study uses Zurich. Set the location via “Import location” or “New reference point”.",
"clash.none": "No clashes found.",
"clash.found": "Clashes found",
"clash.failed": "Clash detection failed",
+1 -1
View File
@@ -69,7 +69,7 @@ const KNOWN_KEYS = new Set<string>([
"walls", "ceilings", "roofs", "openings", "stairs", "rooms", "drawings2d", "context",
"extrudedSolids", "columns", "groups", "parametricWalls", "overrideRules", "viewSnapshots",
"viewSnapshotFolders", "layouts", "masterLayouts", "layoutFolders", "referenceElevationMasl",
"geoAnchor", "roomProgram", "parcelArea",
"geoAnchor", "roomProgram", "parcelArea", "sunStudy",
]);
export type ParseProjectResult =
+18 -9
View File
@@ -925,15 +925,6 @@ export interface SequenceRule {
*/
export type DrawingLevelKind = "floor" | "section" | "elevation" | "drawing";
/**
* Eine Zeichnungsebene (DrawingLevel) — eine oberste Schnittebene des
* Dokuments. Ein Geschoss trägt die Bauteile (über `floorId`); ein
* Schnitt/Ansicht ist eine abgeleitete Projektion (vorerst Platzhalter); eine
* reine Zeichnung ist eine freie 2D-Ebene ohne Geschossbezug.
*
* Geschoss nutzt floorHeight/cutHeight/baseElevation; Schnitt/Ansicht nutzen
* linePoints/directionSign; "drawing" nutzt keines dieser Felder.
*/
/** Eine Zeile des Raumprogramms (Soll): wird gegen die gezeichneten Räume geprüft (`analysis/kennzahlen.ts`). */
export interface RoomProgramRow {
/** Raumname wie im Modell (Vergleich ohne Gross-/Kleinschreibung, Präfix „Wohnen" trifft „Wohnen 2"). */
@@ -946,6 +937,22 @@ export interface RoomProgramRow {
count?: number;
}
/**
* Eine Zeichnungsebene (DrawingLevel) — eine oberste Schnittebene des
* Dokuments. Ein Geschoss trägt die Bauteile (über `floorId`); ein
* Schnitt/Ansicht ist eine abgeleitete Projektion (vorerst Platzhalter); eine
* reine Zeichnung ist eine freie 2D-Ebene ohne Geschossbezug.
*
* Geschoss nutzt floorHeight/cutHeight/baseElevation; Schnitt/Ansicht nutzen
* linePoints/directionSign; "drawing" nutzt keines dieser Felder.
*/
/** Schattenstudie (`analysis/sun.ts`): der Schatten liegt auf dem Geschoss nächst ±0.00. */
export interface SunStudy {
/** Zeitpunkt als ISO-8601-Text in UTC, z. B. "2026-12-21T11:00:00Z". */
when: string;
show: boolean;
}
export interface DrawingLevel {
id: string;
name: string;
@@ -2907,6 +2914,8 @@ export interface Project {
roomProgram?: RoomProgramRow[];
/** Parzellenfläche (m²) für Ausnützungs- und Überbauungsziffer. */
parcelArea?: number;
/** Schattenstudie: Zeitpunkt (ISO 8601, UTC) und ob der Boden-Schatten im Grundriss erscheint. */
sunStudy?: SunStudy;
/** Grafik-Kategorie-Baum (geschossübergreifend). */
layers: LayerCategory[];
walls: Wall[];
+180
View File
@@ -0,0 +1,180 @@
// Kennzahlenleiste [62] und Raumprogramm-Editor [61] im Flächenbilanz-Panel.
//
// • Leiste: GF, aGF, GV, AZ, ÜZ (live aus `computeKennzahlen`), darunter je Geschoss GF/aGF.
// • Parzellenfläche: Eingabefeld → `Project.parcelArea` (leer/0 = nicht gesetzt).
// • Raumprogramm: Soll-Zeilen (Name, Fläche je Raum, Anzahl) bearbeiten; der Status je Zeile
// kommt aus `checkRoomProgram`.
// Änderungen laufen über `setProject` mit coalesceKey, damit Tippen einen Undo-Schritt ergibt.
import { t } from "../i18n";
import type { TranslationKey } from "../i18n";
import { usePanelHost } from "./host";
import { useStore } from "../state/appStore";
import { checkRoomProgram, computeKennzahlen } from "../core";
import type { Project, RoomProgramRow } from "../model/types";
type ProgramStatus = ReturnType<typeof checkRoomProgram>["rows"][number]["status"];
const STATUS_KEY: Record<ProgramStatus, TranslationKey> = {
ok: "program.status.ok",
"zu klein": "program.status.tooSmall",
"zu gross": "program.status.tooLarge",
fehlt: "program.status.missing",
"zu wenige": "program.status.tooFew",
"zu viele": "program.status.tooMany",
};
/** Übersetzter Status einer Raumprogramm-Zeile (auch für den Menü-Toast). */
export function programStatusLabel(status: ProgramStatus): string {
return t(STATUS_KEY[status]);
}
/** Zahl aus einer Eingabe (Komma oder Punkt); leer/ungültig → null. */
function parseNum(text: string): number | null {
const v = Number(text.trim().replace(",", "."));
return text.trim() !== "" && Number.isFinite(v) ? v : null;
}
const fmt = (n: number, d = 1) => n.toLocaleString("de-CH", { minimumFractionDigits: d, maximumFractionDigits: d });
export function KennzahlenSection() {
const host = usePanelHost();
const setProject = useStore((s) => s.setProject);
const project = host.project;
const k = computeKennzahlen(project);
const prog = checkRoomProgram(project);
const rows = project.roomProgram ?? [];
const setParcel = (text: string) => {
const v = parseNum(text);
setProject((p: Project) => {
const { parcelArea: _old, ...rest } = p;
return v !== null && v > 0 ? { ...rest, parcelArea: v } : rest;
}, "parcelArea");
};
const patchRow = (i: number, patch: Partial<RoomProgramRow>, field: string) =>
setProject(
(p: Project) => ({ ...p, roomProgram: (p.roomProgram ?? []).map((r, j) => (j === i ? { ...r, ...patch } : r)) }),
`roomProgram:${i}:${field}`,
);
const addRow = () => setProject((p: Project) => ({ ...p, roomProgram: [...(p.roomProgram ?? []), { name: "", area: 20, count: 1 }] }));
const removeRow = (i: number) =>
setProject((p: Project) => {
const next = (p.roomProgram ?? []).filter((_, j) => j !== i);
const { roomProgram: _old, ...rest } = p;
return next.length > 0 ? { ...rest, roomProgram: next } : rest;
});
const tiles: { label: string; value: string; title: TranslationKey }[] = [
{ label: "GF", value: `${fmt(k.gf)} m²`, title: "kennzahlen.gf" },
{ label: "aGF", value: `${fmt(k.agf)} m²`, title: "kennzahlen.agf" },
{ label: "GV", value: `${fmt(k.gv, 0)} m³`, title: "kennzahlen.gv" },
{ label: "AZ", value: k.az === null ? "–" : fmt(k.az, 2), title: "kennzahlen.az" },
{ label: "ÜZ", value: k.uez === null ? "–" : fmt(k.uez, 2), title: "kennzahlen.uez" },
];
return (
<div className="kz-section">
<div className="kz-bar">
{tiles.map((tile) => (
<div key={tile.label} className="kz-tile" title={t(tile.title)}>
<span className="kz-tile-label">{tile.label}</span>
<span className="kz-tile-value">{tile.value}</span>
</div>
))}
</div>
<label className="kz-parcel">
<span>{t("kennzahlen.parcelArea")}</span>
<input
type="number"
min={0}
step={1}
className="kz-input kz-num"
value={project.parcelArea !== undefined ? String(project.parcelArea) : ""}
placeholder="–"
onChange={(e) => setParcel(e.target.value)}
/>
<span>m²</span>
</label>
{k.levels.length > 0 && (
<div className="balance-table">
{k.levels.map((l) => (
<div key={l.levelId} className="balance-row">
<span className="balance-name">{l.name}</span>
<span className="balance-count">aGF {fmt(l.agf)}</span>
<span className="balance-area">GF {fmt(l.gf)} m²</span>
</div>
))}
</div>
)}
<div className="balance-section-label">{t("program.title")}</div>
{rows.length > 0 && (
<div className="kz-program">
<div className="kz-program-row kz-program-head">
<span>{t("program.name")}</span>
<span>{t("program.area")}</span>
<span>{t("program.count")}</span>
<span>{t("program.status")}</span>
<span />
</div>
{rows.map((row, i) => {
const res = prog.rows[i];
return (
<div key={i} className="kz-program-row">
<input
type="text"
className="kz-input"
value={row.name}
placeholder={t("program.namePlaceholder")}
onChange={(e) => patchRow(i, { name: e.target.value }, "name")}
/>
<input
type="number"
className="kz-input kz-num"
min={0}
step={0.5}
value={row.area}
onChange={(e) => {
const v = parseNum(e.target.value);
if (v !== null && v >= 0) patchRow(i, { area: v }, "area");
}}
/>
<input
type="number"
className="kz-input kz-num"
min={1}
step={1}
value={row.count ?? 1}
onChange={(e) => {
const v = parseNum(e.target.value);
if (v !== null && v >= 1) patchRow(i, { count: Math.round(v) }, "count");
}}
/>
<span
className={"kz-status" + (res?.status === "ok" ? " ok" : " bad")}
title={res ? t("program.actual", { count: res.count, area: fmt(res.area) }) : undefined}
>
{res ? programStatusLabel(res.status) : ""}
</span>
<button type="button" className="site-remove" title={t("program.remove")} aria-label={t("program.remove")} onClick={() => removeRow(i)}>
×
</button>
</div>
);
})}
</div>
)}
<button type="button" className="kz-add" onClick={addRow}>
{t("program.add")}
</button>
{rows.length > 0 && prog.extra.length > 0 && (
<div className="kz-extra" title={prog.extra.map((r) => r.name).join(", ")}>
{t("program.extra", { n: prog.extra.length })}
</div>
)}
</div>
);
}
+7 -1
View File
@@ -1,6 +1,7 @@
// Inhalts-Panel „Flächenbilanz" (SIA 416) — listet alle Räume gruppiert nach
// ihrer SIA-416-Blatt-Kategorie mit Zwischen-/Gesamtsummen und bietet einen
// CSV-Export. Fläche/Bilanz werden LIVE aus den Raum-Umrissen abgeleitet
// 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.
//
// Daten kommen über usePanelHost (project.rooms). Bezeichner englisch, UI-Text
@@ -11,6 +12,7 @@ import { usePanelHost } from "./host";
import { balance, evaluateRoom, roomsToCsv, siaLabelFull } from "../core";
import type { Room } from "../model/types";
import { roomDisplayName } from "../model/roomStamp";
import { KennzahlenSection } from "./KennzahlenSection";
/** Löst je Raum die anrechenbare (Netto-)Fläche + Kategorie auf. */
function roomAreas(rooms: Room[]): { category: Room["siaCategory"]; area: number }[] {
@@ -52,6 +54,7 @@ export function RoomBalancePanel() {
if (rooms.length === 0) {
return (
<div className="balance-panel">
<KennzahlenSection />
<div className="balance-empty">{t("balance.empty")}</div>
</div>
);
@@ -81,6 +84,9 @@ export function RoomBalancePanel() {
</button>
</div>
{/* Kennzahlenleiste, Parzelle und Raumprogramm. */}
<KennzahlenSection />
{/* Raumliste (je Raum: Name · Geschoss · SIA · Fläche). */}
<div className="balance-section-label">{t("balance.rooms")}</div>
<div className="balance-table">
+4
View File
@@ -6,6 +6,7 @@
// • Aktions-Zeile: „DXF importieren" (öffnet den in App montierten Datei-
// Dialog) + „Gelände erzeugen" (aus dem gewählten Kontur-Satz).
// • Liste der Kontext-Objekte: Name + Typ-Badge + „Entfernen".
// • Schattenstudie (SunStudySection): Schalter, Datum, Zeitregler.
// • DWG-Hinweis am Fuß.
//
// Bezeichner englisch, UI-Text/Kommentare deutsch (CONVENTIONS.md). Alle sichtbaren
@@ -21,6 +22,7 @@ import { Dropdown } from "../ui/Dropdown";
import { useStore } from "../state/appStore";
import { isTauriRuntime } from "../native/projectFile";
import { openContextImportWindowNative } from "../native/contextImportWindow";
import { SunStudySection } from "./SunStudySection";
/** Typ-spezifisches Badge-Label (i18n-Key) je Kontext-Objekt-Art. */
function typeBadgeKey(obj: ContextObject): TranslationKey {
@@ -154,6 +156,8 @@ export function SitePanel() {
</div>
)}
<div className="site-sep" />
<SunStudySection />
<div className="site-sep" />
{/* Kontext-Objekte nach Ebene (`layer`) gruppiert: importierte Gebäude
+75
View File
@@ -0,0 +1,75 @@
// Schattenstudie im Lage-Panel ([64]/[59]): Schalter, Datum, Zeitregler (Ortszeit) und
// Sonnenstand. Der Schatten selbst entsteht im Grundriss (`plan/generatePlan/sunShadow.ts`)
// aus `Project.sunStudy`; der Regler schreibt mit coalesceKey (ein Undo-Schritt je Ziehen).
import { t } from "../i18n";
import { usePanelHost } from "./host";
import { useStore } from "../state/appStore";
import { projectLatLon, sunPosition } from "../core";
import type { Project, SunStudy } from "../model/types";
import { defaultStudyIso, formatMinutes, isoToLocal, localToIso } from "./sunStudyTime";
/** Merkdaten: Tagundnachtgleiche, Sommer- und Wintersonnenwende (Tag/Monat). */
const PRESETS: { key: "sun.equinox" | "sun.summer" | "sun.winter"; md: string }[] = [
{ key: "sun.equinox", md: "03-21" },
{ key: "sun.summer", md: "06-21" },
{ key: "sun.winter", md: "12-21" },
];
export function SunStudySection() {
const host = usePanelHost();
const setProject = useStore((s) => s.setProject);
const study: SunStudy = host.project.sunStudy ?? { when: defaultStudyIso(), show: false };
const local = isoToLocal(study.when) ?? isoToLocal(defaultStudyIso())!;
const write = (next: SunStudy, key?: string) => setProject((p: Project) => ({ ...p, sunStudy: next }), key);
const setLocal = (date: string, minutes: number, key?: string) => {
const iso = localToIso({ date, minutes });
if (iso) write({ ...study, when: iso }, key);
};
const { lat, lon } = projectLatLon(host.project);
const sun = sunPosition(lat, lon, new Date(study.when));
const year = local.date.slice(0, 4);
return (
<div className="sun-study">
<label className="sun-row">
<input type="checkbox" checked={study.show} onChange={(e) => write({ ...study, show: e.target.checked })} />
<span>{t("sun.show")}</span>
</label>
<div className="sun-row">
<input
type="date"
className="kz-input"
value={local.date}
onChange={(e) => setLocal(e.target.value, local.minutes, "sunStudy:date")}
/>
{PRESETS.map((p) => (
<button key={p.md} type="button" className="site-btn sun-preset" title={t(p.key)} onClick={() => setLocal(`${year}-${p.md}`, local.minutes)}>
{p.md.slice(3)}.{p.md.slice(0, 2)}.
</button>
))}
</div>
<div className="sun-row">
<input
type="range"
className="sun-slider"
min={0}
max={1435}
step={5}
value={local.minutes}
aria-label={t("sun.time")}
onChange={(e) => setLocal(local.date, Number(e.target.value), "sunStudy:time")}
/>
<span className="sun-time">{formatMinutes(local.minutes)}</span>
</div>
<div className="sun-readout">
{sun.elevation > 0
? t("sun.position", { az: sun.azimuth.toFixed(0), el: sun.elevation.toFixed(1) })
: t("sun.belowHorizon")}
{!host.project.geoAnchor && <span title={t("sun.noAnchor.hint")}> · {t("sun.noAnchor")}</span>}
</div>
</div>
);
}
+18
View File
@@ -0,0 +1,18 @@
import { describe, expect, it } from "vitest";
import { defaultStudyIso, formatMinutes, isoToLocal, localToIso } from "./sunStudyTime";
describe("Zeitregler der Schattenstudie", () => {
it("Ortszeit ↔ UTC hin und zurück", () => {
const iso = localToIso({ date: "2026-12-21", minutes: 11 * 60 + 15 })!;
expect(isoToLocal(iso)).toEqual({ date: "2026-12-21", minutes: 675 });
});
it("ungültige Eingaben → null, Minuten werden begrenzt", () => {
expect(localToIso({ date: "21.12.2026", minutes: 600 })).toBeNull();
expect(isoToLocal("kein Datum")).toBeNull();
expect(isoToLocal(localToIso({ date: "2026-06-21", minutes: 5000 })!)!.minutes).toBe(1439);
});
it("Anzeige und Vorgabe", () => {
expect(formatMinutes(605)).toBe("10:05");
expect(isoToLocal(defaultStudyIso(new Date(2027, 4, 2)))).toEqual({ date: "2027-03-21", minutes: 720 });
});
});
+38
View File
@@ -0,0 +1,38 @@
// Zeitumrechnung des Schattenstudien-Reglers: gespeichert wird UTC (ISO 8601), bedient wird in
// Ortszeit des Rechners (Datum + Minuten seit Mitternacht).
export interface LocalTime {
/** "YYYY-MM-DD" in Ortszeit. */
date: string;
/** Minuten seit Mitternacht in Ortszeit (0..1439). */
minutes: number;
}
const pad = (n: number) => String(n).padStart(2, "0");
export function isoToLocal(iso: string): LocalTime | null {
const d = new Date(iso);
if (Number.isNaN(d.getTime())) return null;
return {
date: `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`,
minutes: d.getHours() * 60 + d.getMinutes(),
};
}
export function localToIso(t: LocalTime): string | null {
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(t.date);
if (!m || !Number.isFinite(t.minutes)) return null;
const min = Math.min(1439, Math.max(0, Math.round(t.minutes)));
const d = new Date(Number(m[1]), Number(m[2]) - 1, Number(m[3]), Math.floor(min / 60), min % 60);
if (Number.isNaN(d.getTime())) return null;
return d.toISOString();
}
export function formatMinutes(minutes: number): string {
return `${pad(Math.floor(minutes / 60))}:${pad(minutes % 60)}`;
}
/** Vorgabe beim ersten Einschalten: Tagundnachtgleiche des laufenden Jahres, 12:00 Ortszeit. */
export function defaultStudyIso(now = new Date()): string {
return localToIso({ date: `${now.getFullYear()}-03-21`, minutes: 12 * 60 })!;
}
+35
View File
@@ -0,0 +1,35 @@
/**
* `generatePlan` — Schattenstudie (`Project.sunStudy`): Boden-Schatten als halbtransparente
* Flächen ZUUNTERST im Grundriss des Geschosses nächst ±0.00, sonst nirgends.
*/
import { describe, it, expect } from "vitest";
import { generatePlan } from "./generatePlan";
import { SUN_SHADOW_FILL } from "./generatePlan/sunShadow";
import { sampleProject } from "../model/sampleProject";
import { flattenCategories } from "../model/types";
import type { Project } from "../model/types";
const ALL = new Set(flattenCategories(sampleProject.layers).map((c) => c.code));
const withStudy = (when: string, show = true): Project => ({ ...sampleProject, sunStudy: { when, show } });
const shadows = (p: Project, floorId: string) =>
generatePlan(p, floorId, ALL).primitives.filter((q) => q.kind === "polygon" && q.fill === SUN_SHADOW_FILL);
describe("Schattenstudie im Grundriss", () => {
it("Wintermittag: Schatten im EG, zuunterst gezeichnet", () => {
const p = withStudy("2026-12-21T11:00:00Z");
expect(shadows(p, "eg").length).toBeGreaterThan(0);
const first = generatePlan(p, "eg", ALL).primitives[0];
expect(first.kind === "polygon" && first.fill === SUN_SHADOW_FILL).toBe(true);
});
it("nicht im OG, nicht ausgeschaltet, nicht nachts, nicht ohne Studie", () => {
expect(shadows(withStudy("2026-12-21T11:00:00Z"), "og")).toEqual([]);
expect(shadows(withStudy("2026-12-21T11:00:00Z", false), "eg")).toEqual([]);
expect(shadows(withStudy("2026-12-21T22:00:00Z"), "eg")).toEqual([]);
expect(shadows(sampleProject, "eg")).toEqual([]);
});
it("ungültiges Datum → kein Schatten, kein Absturz", () => {
expect(shadows(withStudy("kein Datum"), "eg")).toEqual([]);
});
});
+3
View File
@@ -72,6 +72,7 @@ import {
import { addCeilingPoche } from "./generatePlan/ceilings";
import { subtractVoidsInPlan } from "./voids";
import { addContextContours } from "./generatePlan/context";
import { addSunShadow } from "./generatePlan/sunShadow";
import { DEFAULT_SCALE_DENOMINATOR } from "../model/dimension";
import {
addDrawing2D,
@@ -349,6 +350,8 @@ export function generatePlan(
compactUnderlay = false,
): Plan {
const primitives: Primitive[] = [];
// Schattenstudie zuunterst (projektglobal, nur im Geschoss nächst ±0.00).
if (includeGlobal) addSunShadow(primitives, project, floorId);
// Aktives Geschoss (für die Grundriss-Schnitthöhe der Treppen).
const floor = project.drawingLevels.find((z) => z.id === floorId);
// Code → Kategorie-Strichstärke (mm), damit die Wand-Umrisslinie aus dem
+44
View File
@@ -0,0 +1,44 @@
// Schattenstudie im Grundriss ([64]/[59]): Boden-Schatten zum Zeitpunkt `Project.sunStudy.when`
// als halbtransparente Flächen ZUUNTERST, nur im Geschoss nächst ±0.00 (der Schatten liegt auf
// z = 0). Rechnung in `analysis/sun.ts`; Löcher (Höfe) werden für das Plan-Primitiv zerlegt.
import type { Project } from "../../model/types";
import { projectLatLon, shadowPolygons, sunPosition, withoutHoles } from "../../analysis/sun";
import { NO_HATCH, type Primitive } from "./shared";
/** Füllfarbe der Schattenflächen (Erkennungsmerkmal in Tests). */
export const SUN_SHADOW_FILL = "#3a4a66";
const SUN_SHADOW_OPACITY = 0.28;
/** Geschoss, auf dem der Boden-Schatten erscheint: Basishöhe am nächsten bei 0. */
export function groundFloorId(project: Project): string | null {
let best: { id: string; d: number } | null = null;
for (const l of project.drawingLevels) {
if (l.kind !== "floor") continue;
const d = Math.abs(l.baseElevation ?? 0);
if (!best || d < best.d) best = { id: l.id, d };
}
return best?.id ?? null;
}
/** Hängt die Schattenflächen an `out` an (nichts ohne aktive Studie, nachts oder auf anderen Geschossen). */
export function addSunShadow(out: Primitive[], project: Project, floorId: string): void {
const study = project.sunStudy;
if (!study?.show || groundFloorId(project) !== floorId) return;
const when = new Date(study.when);
if (Number.isNaN(when.getTime())) return;
const { lat, lon } = projectLatLon(project);
for (const poly of shadowPolygons(project, sunPosition(lat, lon, when))) {
for (const pts of withoutHoles(poly)) {
out.push({
kind: "polygon",
pts,
fill: SUN_SHADOW_FILL,
stroke: "none",
strokeWidthMm: 0,
hatch: NO_HATCH,
opacity: SUN_SHADOW_OPACITY,
});
}
}
}
+131
View File
@@ -8053,3 +8053,134 @@ body {
.imp-overlay.recover-overlay {
z-index: 2100;
}
/* Kennzahlenleiste, Parzelle und Raumprogramm (Flächenbilanz-Panel, KennzahlenSection). */
.kz-section {
display: flex;
flex-direction: column;
gap: 6px;
margin-bottom: 8px;
}
.kz-bar {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
gap: 4px;
}
.kz-tile {
display: flex;
flex-direction: column;
padding: 4px 6px;
border: 1px solid var(--line);
border-radius: 6px;
background: var(--panel-2);
}
.kz-tile-label {
font-size: 10px;
color: var(--ink-2);
}
.kz-tile-value {
font-variant-numeric: tabular-nums;
font-weight: 600;
white-space: nowrap;
}
.kz-parcel {
display: flex;
align-items: center;
gap: 6px;
}
.kz-parcel > span:first-child {
flex: 1 1 auto;
color: var(--ink-2);
}
.kz-input {
min-width: 0;
padding: 2px 4px;
border: 1px solid var(--line);
border-radius: 4px;
background: var(--panel);
color: var(--ink);
font-size: 12px;
}
.kz-num {
width: 64px;
text-align: right;
font-variant-numeric: tabular-nums;
}
.kz-program {
display: flex;
flex-direction: column;
gap: 2px;
}
.kz-program-row {
display: grid;
grid-template-columns: minmax(0, 1fr) 56px 40px 64px 18px;
gap: 4px;
align-items: center;
}
.kz-program-row .kz-num {
width: 100%;
}
.kz-program-head {
font-size: 10px;
color: var(--ink-2);
}
.kz-status {
font-size: 11px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.kz-status.ok {
color: var(--ok, #2f8f4e);
}
.kz-status.bad {
color: var(--danger, #c0392b);
}
.kz-add {
align-self: flex-start;
padding: 3px 8px;
border: 1px dashed var(--line);
border-radius: 4px;
background: transparent;
color: var(--ink-2);
font-size: 12px;
cursor: pointer;
}
.kz-add:hover {
color: var(--ink);
border-color: var(--accent-border);
}
.kz-extra {
font-size: 11px;
color: var(--ink-2);
}
/* Schattenstudie (Lage-Panel, SunStudySection). */
.sun-study {
display: flex;
flex-direction: column;
gap: 6px;
}
.sun-row {
display: flex;
align-items: center;
gap: 6px;
}
.site-panel .sun-preset {
flex: 0 0 auto;
padding: 3px 6px;
}
.sun-slider {
flex: 1 1 auto;
min-width: 0;
accent-color: var(--accent);
}
.sun-time {
font-variant-numeric: tabular-nums;
width: 3em;
text-align: right;
}
.sun-readout {
color: var(--ink-2);
font-size: 11px;
}