[61][70] Raumprogramm: "Räume generieren" auf neuem Blatt (4:3), CLI, TODO
Knopf "Räume generieren" legt ein neues Blatt "Raumprogramm" (Zeichnungsebene der Art drawing) an: je Raum (Anzahl beachtet) ein Rechteck mit exakter Soll- Fläche im Seitenverhältnis 4:3, beschriftet mit Name und Fläche, je Gruppe/ Flächenart gruppiert mit Titel und Farbe, absteigend nach Fläche in Reihen gepackt (Packing in Rust, Abfrage programLayout, Gesamtbild nahe 4:3). Ebene und Zeichnungen entstehen in einem setProject, also ein Undo-Schritt. Entscheid: 2D-Zeichnungen statt Room-Objekte. Echte Räume gehören einem Geschoss und zählen in Flächenbilanz, Flächentabelle, Kennzahlen und IFC; die Soll-Rechtecke würden das Ist verfälschen und von checkRoomProgram als vorhanden zugeordnet. Als Zeichnung bleiben sie verschiebbar und als Vorlage nutzbar. CLI: raumprogramm [--import tabelle] [--generate] [--tolerance %] [--format json|csv|svg|pdf] [--save projekt.obp]; plan akzeptiert auch Zeichnungsebenen. Playwright-Test importiert, vergleicht, generiert und macht rückgängig. TODO.md [61]/[70] nachgeführt. Geprüft: npm run check, build:cli, npm run e2e (Browser-Build, Linux). Nicht in der Tauri-App getestet. Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
9 files changed
+356
-5
No files matched your search
@@ -0,0 +1,65 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import type { Project } from "../model/types";
|
||||
import { compareRoomProgram, layoutRoomProgram } from "./roomProgram";
|
||||
import { addProgramSheet, buildProgramSheet } from "./roomProgramSheet";
|
||||
import { computeAreaTable } from "./areaTable";
|
||||
import { computeKennzahlen } from "./kennzahlen";
|
||||
|
||||
const sq = (x: number, y: number, s: number) => [
|
||||
{ x, y }, { x: x + s, y }, { x: x + s, y: y + s }, { x, y: y + s },
|
||||
];
|
||||
const base = (sampleProject.rooms ?? [])[0]!;
|
||||
|
||||
const withProgram = (): Project => ({
|
||||
...sampleProject,
|
||||
rooms: [
|
||||
{ ...base, id: "r1", name: "Wohnen 1", boundary: sq(0, 0, 5) },
|
||||
{ ...base, id: "r2", name: "Bad", boundary: sq(10, 0, 2) },
|
||||
],
|
||||
roomProgram: [
|
||||
{ name: "Wohnen", area: 25, group: "Tag" },
|
||||
{ name: "Bad", area: 5, group: "Nacht" },
|
||||
{ name: "Zimmer", area: 12, count: 3, group: "Nacht" },
|
||||
],
|
||||
});
|
||||
|
||||
const labels = { levelName: "Raumprogramm", area: (a: number) => `${a.toFixed(1)} m²`, groupTitle: (n: string, a: number) => `${n} · ${a.toFixed(1)} m²` };
|
||||
|
||||
describe("Räume generieren", () => {
|
||||
it("neues Blatt, Rechtecke mit Soll-Fläche im Verhältnis 4:3, Ist unverändert", () => {
|
||||
const p = withProgram();
|
||||
const sheet = buildProgramSheet(p, labels, "t1");
|
||||
expect(sheet.level.kind).toBe("drawing");
|
||||
expect(sheet.level.name).toBe("Raumprogramm");
|
||||
const rects = sheet.drawings.filter((d) => d.geom.shape === "rect");
|
||||
expect(rects).toHaveLength(1 + 1 + 3);
|
||||
const areas = rects.map((d) => {
|
||||
const g = d.geom as { min: { x: number; y: number }; max: { x: number; y: number } };
|
||||
const w = g.max.x - g.min.x;
|
||||
const h = g.max.y - g.min.y;
|
||||
expect(w / h).toBeCloseTo(4 / 3, 9);
|
||||
return w * h;
|
||||
});
|
||||
expect(areas.sort((a, b) => a - b).map((a) => Math.round(a * 1e6) / 1e6)).toEqual([5, 12, 12, 12, 25]);
|
||||
// Gruppentitel
|
||||
expect(sheet.drawings.filter((d) => d.geom.shape === "text" && (d.geom as { text: string }).text.startsWith("Nacht"))).toHaveLength(1);
|
||||
|
||||
const q = addProgramSheet(p, sheet);
|
||||
expect(q.drawingLevels).toHaveLength(p.drawingLevels.length + 1);
|
||||
expect(q.rooms).toBe(p.rooms);
|
||||
expect(computeKennzahlen(q).gf).toBeCloseTo(computeKennzahlen(p).gf, 9);
|
||||
expect(computeAreaTable(q).total.ngf).toBeCloseTo(computeAreaTable(p).total.ngf, 9);
|
||||
expect(compareRoomProgram(q).total.ist).toBeCloseTo(compareRoomProgram(p).total.ist, 9);
|
||||
// zweites Mal: eindeutiger Name
|
||||
expect(buildProgramSheet(q, labels, "t2").level.name).toBe("Raumprogramm 2");
|
||||
expect(new Set(q.drawings2d.map((d) => d.id)).size).toBe(q.drawings2d.length);
|
||||
});
|
||||
it("leeres Programm → nichts", () => {
|
||||
const p: Project = { ...sampleProject, roomProgram: [] };
|
||||
const s = buildProgramSheet(p, labels, "x");
|
||||
expect(s.drawings).toHaveLength(0);
|
||||
expect(addProgramSheet(p, s)).toBe(p);
|
||||
expect(layoutRoomProgram(p).items).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,130 @@
|
||||
// „Räume generieren" ([61]): das Raumprogramm als neues Blatt (Zeichnungsebene „Raumprogramm").
|
||||
//
|
||||
// Entscheid Raum oder Zeichnung: Die Rechtecke sind freie 2D-Zeichnungen (Rechteck + Text) auf einer
|
||||
// eigenen Ebene der Art "drawing", KEINE `Room`s. Echte Räume gehören einem Geschoss (`floorId`), zählen
|
||||
// in Flächenbilanz, Flächentabelle, Kennzahlen und IFC — die Soll-Rechtecke würden das Ist verfälschen
|
||||
// (und `checkRoomProgram` würde sie dem Programm als „vorhanden" zuordnen). Als Zeichnung lassen sie sich
|
||||
// trotzdem verschieben, kopieren und als Vorlage über die eigenen Räume legen.
|
||||
//
|
||||
// Die Anordnung (Packing) rechnet der Kern (`room_program.rs`); hier entstehen nur die Modellobjekte.
|
||||
// Der Aufruf gehört in EIN `setProject` (ein Undo-Schritt).
|
||||
|
||||
import type { Drawing2D, DrawingLevel, Project } from "../model/types";
|
||||
import { t } from "../i18n";
|
||||
import { layoutRoomProgram } from "./roomProgram";
|
||||
import type { LayoutGroup, LayoutItem, RoomProgramLayout } from "./roomProgram";
|
||||
|
||||
/** Füllfarben der Gruppen (hell, Text darauf dunkel); weiter reihum. */
|
||||
const GROUP_COLORS = ["#dbe8f5", "#f7e3c8", "#dcefd6", "#f3d9e4", "#e6e0f3", "#f5f0c4", "#d2eeee", "#efdcd2"];
|
||||
|
||||
/** Farbe der Gruppe `index`. */
|
||||
export function groupColor(index: number): string {
|
||||
return GROUP_COLORS[((index % GROUP_COLORS.length) + GROUP_COLORS.length) % GROUP_COLORS.length]!;
|
||||
}
|
||||
|
||||
export interface SheetLabels {
|
||||
/** Name des neuen Blatts (Grundname; ist er vergeben, hängt eine Nummer an). */
|
||||
levelName: string;
|
||||
/** Beschriftung eines Raums unter dem Namen, z. B. „28.5 m²". */
|
||||
area: (area: number) => string;
|
||||
/** Titel einer Gruppe, z. B. „Wohnen · 120.0 m²". */
|
||||
groupTitle: (name: string, area: number) => string;
|
||||
}
|
||||
|
||||
const areaText = (a: number): string => a.toLocaleString("de-CH", { minimumFractionDigits: 1, maximumFractionDigits: 1 });
|
||||
|
||||
/** Beschriftungen in der Oberflächensprache. */
|
||||
export function defaultSheetLabels(): SheetLabels {
|
||||
return {
|
||||
levelName: t("program.generate.levelName"),
|
||||
area: (a) => `${areaText(a)} m²`,
|
||||
groupTitle: (name, a) => t("program.generate.groupTitle", { name, area: areaText(a) }),
|
||||
};
|
||||
}
|
||||
|
||||
export interface ProgramSheet {
|
||||
level: DrawingLevel;
|
||||
drawings: Drawing2D[];
|
||||
layout: RoomProgramLayout;
|
||||
}
|
||||
|
||||
const INK = "#222222";
|
||||
const OUTLINE = "#555555";
|
||||
const TEXT_CATEGORY = "50";
|
||||
const SHAPE_CATEGORY = "60";
|
||||
|
||||
function uniqueLevelName(project: Project, base: string): string {
|
||||
const names = new Set(project.drawingLevels.map((l) => l.name));
|
||||
if (!names.has(base)) return base;
|
||||
for (let n = 2; ; n++) if (!names.has(`${base} ${n}`)) return `${base} ${n}`;
|
||||
}
|
||||
|
||||
/** Höhe der Beschriftung (m) für ein Rechteck der Tiefe `d`. */
|
||||
function labelHeight(d: number): number {
|
||||
return Math.min(0.5, Math.max(0.22, d * 0.13));
|
||||
}
|
||||
|
||||
function roomDrawings(it: LayoutItem, color: string, level: string, id: string, labels: SheetLabels): Drawing2D[] {
|
||||
const h = labelHeight(it.d);
|
||||
const pad = Math.min(0.25, it.w * 0.05);
|
||||
const rect: Drawing2D = {
|
||||
id: `${id}-r`,
|
||||
type: "drawing2d",
|
||||
levelId: level,
|
||||
categoryCode: SHAPE_CATEGORY,
|
||||
geom: { shape: "rect", min: { x: it.x, y: it.y }, max: { x: it.x + it.w, y: it.y + it.d } },
|
||||
background: color,
|
||||
color: OUTLINE,
|
||||
};
|
||||
const name: Drawing2D = {
|
||||
id: `${id}-n`,
|
||||
type: "drawing2d",
|
||||
levelId: level,
|
||||
categoryCode: TEXT_CATEGORY,
|
||||
color: INK,
|
||||
geom: { shape: "text", at: { x: it.x + pad, y: it.y + it.d - pad - h }, text: it.name, height: h, angle: 0, width: Math.max(0.5, it.w - 2 * pad), marks: { bold: true, color: INK } },
|
||||
};
|
||||
const area: Drawing2D = {
|
||||
id: `${id}-a`,
|
||||
type: "drawing2d",
|
||||
levelId: level,
|
||||
categoryCode: TEXT_CATEGORY,
|
||||
color: INK,
|
||||
geom: { shape: "text", at: { x: it.x + pad, y: it.y + pad }, text: labels.area(it.area), height: h * 0.9, angle: 0, marks: { color: INK } },
|
||||
};
|
||||
return [rect, name, area];
|
||||
}
|
||||
|
||||
function titleDrawing(g: LayoutGroup, level: string, id: string, labels: SheetLabels): Drawing2D {
|
||||
return {
|
||||
id,
|
||||
type: "drawing2d",
|
||||
levelId: level,
|
||||
categoryCode: TEXT_CATEGORY,
|
||||
color: INK,
|
||||
geom: { shape: "text", at: { x: g.x, y: g.y + g.titleHeight * 0.25 }, text: labels.groupTitle(g.name, g.area), height: g.titleHeight * 0.4, angle: 0, marks: { bold: true, color: INK } },
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Ebene und Zeichnungen für das Raumprogramm des Projekts. Leer (`drawings.length === 0`), wenn das Programm
|
||||
* keine Zeile mit Namen und Fläche hat. `stamp` macht die Ids eindeutig.
|
||||
*/
|
||||
export function buildProgramSheet(project: Project, labels: SheetLabels, stamp: string = String(Date.now())): ProgramSheet {
|
||||
const layout = layoutRoomProgram(project, { gap: 1, titleHeight: 1.6 });
|
||||
const level: DrawingLevel = { id: `drawing-rp-${stamp}`, name: uniqueLevelName(project, labels.levelName), kind: "drawing", visible: true, locked: false };
|
||||
const drawings: Drawing2D[] = [];
|
||||
layout.groups.forEach((g) => {
|
||||
if (g.name) drawings.push(titleDrawing(g, level.id, `rp-${stamp}-g${g.index}`, labels));
|
||||
});
|
||||
layout.items.forEach((it, i) => {
|
||||
drawings.push(...roomDrawings(it, groupColor(it.groupIndex), level.id, `rp-${stamp}-${i}`, labels));
|
||||
});
|
||||
return { level, drawings, layout };
|
||||
}
|
||||
|
||||
/** Fügt das Blatt dem Projekt hinzu (für `setProject`); ohne Räume unverändert. */
|
||||
export function addProgramSheet(project: Project, sheet: ProgramSheet): Project {
|
||||
if (sheet.drawings.length === 0) return project;
|
||||
return { ...project, drawingLevels: [...project.drawingLevels, sheet.level], drawings2d: [...project.drawings2d, ...sheet.drawings] };
|
||||
}
|
||||
Reference in new issue
Block a user