[26][B2] Dach: Innenhöfe (Roof.holes) und Neigung je Kante (Roof.edgePitchDeg), Objekt-Info, Befehl Dachhof
Modell (Rust, ts-rs): Roof.holes (Ringe) und Roof.edgePitchDeg (je Umrisskante, dann Hofkanten; null = Giebel, negativ = Standard, Feld fehlt = wie bisher). roof.rs: custom_roof rechnet über weighted_roof (alle Ringe, Überstand je Kante, Hofringe schrumpfen); ungültige Höfe und Pult fallen auf das bisherige Dach zurück. Dächer ohne die Felder bleiben bitgleich (CLI-SVG/IFC). Plan: Hof als Loch der Dachfläche, Hofkanten als Traufe. 3D: Gehrung an Graten zwischen verschieden geneigten Flächen (Dachschichten bleiben geschlossen). UI: Kantenliste mit Neigung/Giebel im Objekt-Info, Hofliste mit Entfernen, Befehl "Dachhof". Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
24 files changed
+1341
-41
No files matched your search
@@ -0,0 +1,118 @@
|
||||
// Dach: Kantenneigung und Innenhöfe ([26]) über Store/Ops — ein Undo-Schritt je Aktion — und die
|
||||
// Rundreise durch das Projektformat (Rust-Modell ↔ TS: `holes`, `edgePitchDeg` mit `null` = Giebel).
|
||||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
import { getState, setState } from "./appStore";
|
||||
import type { Project, Roof } from "../model/types";
|
||||
import { addRoofHole, removeRoofHole, roofGeometry, setRoofEdge } from "../core";
|
||||
import { parseProjectFile, serializeProject } from "../io/projectFormat";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
|
||||
const roof: Roof = {
|
||||
id: "RF1",
|
||||
type: "roof",
|
||||
floorId: "eg",
|
||||
categoryCode: "31",
|
||||
outline: [
|
||||
{ x: 0, y: 0 },
|
||||
{ x: 12, y: 0 },
|
||||
{ x: 12, y: 8 },
|
||||
{ x: 0, y: 8 },
|
||||
],
|
||||
shape: "walm",
|
||||
pitchDeg: 35,
|
||||
overhang: 0,
|
||||
ridgeAxis: "x",
|
||||
thickness: 0.2,
|
||||
};
|
||||
const court = [
|
||||
{ x: 4, y: 2 },
|
||||
{ x: 4, y: 6 },
|
||||
{ x: 8, y: 6 },
|
||||
{ x: 8, y: 2 },
|
||||
];
|
||||
|
||||
const baseProject = {
|
||||
id: "p",
|
||||
name: "T",
|
||||
layers: [],
|
||||
drawingLevels: [{ id: "eg", name: "EG", kind: "floor", visible: true, locked: false, floorHeight: 2.6, baseElevation: 0 }],
|
||||
walls: [],
|
||||
drawings2d: [],
|
||||
roofs: [roof],
|
||||
} as unknown as Project;
|
||||
|
||||
const current = (): Roof => getState().project.roofs![0];
|
||||
|
||||
beforeEach(() => {
|
||||
setState({ project: JSON.parse(JSON.stringify(baseProject)), undoDepth: 0, redoDepth: 0, canUndo: false, canRedo: false });
|
||||
getState().clearHistory();
|
||||
});
|
||||
|
||||
describe("Kantenneigung über Ops", () => {
|
||||
it("Kante ändern ist ein Undo-Schritt; Zurück stellt das Feld wieder her", () => {
|
||||
getState().updateRoof("RF1", setRoofEdge(current(), 0, { kind: "pitch", deg: 20 }));
|
||||
expect(current().edgePitchDeg).toEqual([20]);
|
||||
expect(getState().undoDepth).toBe(1);
|
||||
getState().undo();
|
||||
expect(current().edgePitchDeg).toBeUndefined();
|
||||
});
|
||||
|
||||
it("Tippen einer Zahl (gleicher Schlüssel) koalesziert zu einem Schritt", () => {
|
||||
const key = "roof-edge-RF1-1";
|
||||
getState().updateRoof("RF1", { overhang: 0.1 }); // Koaleszenz-Grenze
|
||||
getState().clearHistory();
|
||||
getState().updateRoof("RF1", setRoofEdge(current(), 1, { kind: "pitch", deg: 3 }), key);
|
||||
getState().updateRoof("RF1", setRoofEdge(current(), 1, { kind: "pitch", deg: 30 }), key);
|
||||
expect(current().edgePitchDeg).toEqual([-1, 30]);
|
||||
expect(getState().undoDepth).toBe(1);
|
||||
getState().undo();
|
||||
expect(current().edgePitchDeg).toBeUndefined();
|
||||
});
|
||||
|
||||
it("Giebel (null) bleibt im Projekt und ändert die Geometrie", () => {
|
||||
const before = roofGeometry(current(), 0);
|
||||
getState().updateRoof("RF1", { edgePitchDeg: [-1, null, -1, null] });
|
||||
expect(current().edgePitchDeg).toEqual([-1, null, -1, null]);
|
||||
const after = roofGeometry(current(), 0);
|
||||
expect(after.gables.length).toBe(2);
|
||||
expect(before.gables.length).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Innenhöfe über Ops", () => {
|
||||
it("Hof hinzufügen und entfernen: je ein Undo-Schritt, Dach spart den Hof aus", () => {
|
||||
getState().updateRoof("RF1", addRoofHole(current(), court));
|
||||
expect(current().holes).toEqual([court]);
|
||||
expect(roofGeometry(current(), 0).eavesHoles).toHaveLength(1);
|
||||
expect(getState().undoDepth).toBe(1);
|
||||
getState().updateRoof("RF1", removeRoofHole(current(), 0));
|
||||
expect(current().holes).toBeUndefined();
|
||||
expect(getState().undoDepth).toBe(2);
|
||||
getState().undo();
|
||||
expect(current().holes).toEqual([court]);
|
||||
getState().undo();
|
||||
expect(current().holes).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Projektdatei: Rundreise", () => {
|
||||
it("holes und edgePitchDeg (mit null) überstehen Schreiben und Lesen", () => {
|
||||
const withFields: Roof = { ...roof, holes: [court], edgePitchDeg: [20, null, -1, 45, 10, -1, -1, null] };
|
||||
const p = { ...sampleProject, roofs: [withFields] } as Project;
|
||||
const r = parseProjectFile(serializeProject(p));
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
expect(r.project.roofs![0].holes).toEqual([court]);
|
||||
expect(r.project.roofs![0].edgePitchDeg).toEqual([20, null, -1, 45, 10, -1, -1, null]);
|
||||
});
|
||||
|
||||
it("ohne die Felder bleiben sie auch nach der Rundreise weg", () => {
|
||||
const p = { ...sampleProject, roofs: [roof] } as Project;
|
||||
const text = serializeProject(p);
|
||||
expect(text).not.toContain("edgePitchDeg");
|
||||
expect(text).not.toContain("holes");
|
||||
const r = parseProjectFile(text);
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
expect("holes" in r.project.roofs![0]).toBe(false);
|
||||
expect("edgePitchDeg" in r.project.roofs![0]).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -58,7 +58,8 @@ import {
|
||||
wallVerticalExtent,
|
||||
} from "../model/wall";
|
||||
import { ceilingArea, outlineBBox } from "../core";
|
||||
import { roofBBox, roofBaseElevation, roofGeometry } from "../core";
|
||||
import { roofBBox, roofBaseElevation, roofEdgeList, roofGeometry } from "../core";
|
||||
import type { RoofEdge } from "../core";
|
||||
import { openingGapQuad, openingVerticalExtent } from "../core";
|
||||
import { stairGeometry, stairBBox } from "../core";
|
||||
|
||||
@@ -115,6 +116,12 @@ export interface RoofInfo {
|
||||
/** Untere/linke Ecke der Bounding-Box (fix beim Breite/Tiefe-Resize). */
|
||||
minX: number;
|
||||
minY: number;
|
||||
/** Kanten (Umriss, dann Höfe) mit Neigungsvorgabe ([26], `roofEdgeList`). */
|
||||
edges: RoofEdge[];
|
||||
/** Innenhöfe: Fläche (m²) und Punktzahl je Hof, in der Reihenfolge von `Roof.holes`. */
|
||||
holes: { area: number; points: number }[];
|
||||
/** Ob `edgePitchDeg` gesetzt ist. */
|
||||
hasEdgePitch: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -867,6 +874,9 @@ function roofSelection(project: Project, roof: Roof): Selection {
|
||||
depth: Math.abs(bb.y1 - bb.y0),
|
||||
minX: bb.x0,
|
||||
minY: bb.y0,
|
||||
edges: roofEdgeList(roof),
|
||||
holes: (roof.holes ?? []).map((h) => ({ area: Math.abs(polygonArea(h)), points: h.length })),
|
||||
hasEdgePitch: roof.edgePitchDeg !== undefined,
|
||||
};
|
||||
return {
|
||||
kind: "roof",
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
// Extrahiert aus App.tsx. Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import { applyFillMode } from "./fillMode";
|
||||
import { addItems, fieldOps, opsMutation, patchItem, patchItems, removeItems, setFieldIfChanged } from "../core";
|
||||
import { addItems, fieldOps, opsMutation, patchItem, patchItems, removeItems, removeRoofHole, setFieldIfChanged, setRoofEdge } from "../core";
|
||||
import type { CoreOp } from "../core";
|
||||
import { useMemo, type RefObject } from "react";
|
||||
import type { DrawingLevel, Layout, Project } from "../model/types";
|
||||
@@ -929,8 +929,20 @@ export function usePanelHostBase(opts: {
|
||||
},
|
||||
onOpenOpeningEditor: (id) => setOpeningEditorId(id),
|
||||
// ── Dach-Attribute (nur bei selektiertem Dach) ─────────────────────────
|
||||
onSetRoofPatch: (patch) => {
|
||||
if (selection?.kind === "roof") updateRoof(selection.id, patch);
|
||||
onSetRoofPatch: (patch, coalesceKey) => {
|
||||
if (selection?.kind === "roof") updateRoof(selection.id, patch, coalesceKey);
|
||||
},
|
||||
onSetRoofEdge: (index, spec) => {
|
||||
if (selection?.kind !== "roof") return;
|
||||
const r = (project.roofs ?? []).find((x) => x.id === selection.id);
|
||||
if (!r) return;
|
||||
// Zahl tippen: gleicher Schlüssel je Kante ⇒ ein Undo-Schritt; Giebel-Schalter einzeln.
|
||||
updateRoof(selection.id, setRoofEdge(r, index, spec), spec.kind === "pitch" ? `roof-edge-${selection.id}-${index}` : undefined);
|
||||
},
|
||||
onRemoveRoofHole: (k) => {
|
||||
if (selection?.kind !== "roof") return;
|
||||
const r = (project.roofs ?? []).find((x) => x.id === selection.id);
|
||||
if (r) updateRoof(selection.id, removeRoofHole(r, k));
|
||||
},
|
||||
// ── Schnitt-/Ansichtslinie (nur bei selektierter Linie) ────────────────
|
||||
sectionLine,
|
||||
|
||||
Reference in new issue
Block a user