Schnitt/Ansicht: keine losen Fremd-Ueberlagerungen, keine Griffe in Grundriss-Koordinaten, Fang an Schnittkanten, Ansichtskanten hinter Bauteilen vor der Ebene, geschnittene Fenster/Tueren

- Fremd-Art-Ueberlagerung nur noch im gleichen Koordinatenraum (Geschoss <-> freie Zeichnung); Grundriss optional ausgerichtet unter Schnitt/Ansicht (DrawingLevel.planUnderlayId)
- Im Schnitt/in der Ansicht nur Griffe/Transformationen fuer 2D-Elemente der Ebene (Bauteile leben im Grundriss-Raum)
- Fangkanten der abgeleiteten Geometrie fuer computeSnap (sheetSnapGeometry)
- Im Schnitt gezeichnete 2D-Elemente werden angezeigt
- Kein Flackern/Zoom-Verlust: altes Ergebnis bleibt bis zum neuen, reine 2D-Aenderungen rechnen nicht neu
- section.rs: Bauteile komplett vor der Schnittebene verdecken nichts mehr
- Geschnittene Fenster (Rahmenprofil + Glas) und Tueren (Zarge + Blatt), Bodenlinie, Schnitt-Einstellungen ohne Auswahl
This commit is contained in:
karim committed 2026-10-21 18:53:12 +02:00
1 parent 6fbc8d4ff8
commit f44ba9ed85
20 files changed
+1049 -57

No files matched your search

+48
View File
@@ -583,6 +583,9 @@ struct PrismBounds {
u_min: f32,
u_max: f32,
depth_min: f32,
/// Groesste Tiefe des Fussabdrucks. `<= EPS` heisst: das Bauteil liegt
/// komplett VOR der Ebene (hinter dem Betrachter) und verdeckt nichts.
depth_max: f32,
z0: f32,
z1: f32,
opening_voids: Vec<(f32, f32, f32, f32)>,
@@ -592,6 +595,7 @@ fn prism_bounds(plane: &SectionPlane, prism: &Prism) -> PrismBounds {
let mut u_min = f32::INFINITY;
let mut u_max = f32::NEG_INFINITY;
let mut depth_min = f32::INFINITY;
let mut depth_max = f32::NEG_INFINITY;
for &p in &prism.footprint {
let w = to_world(p, 0.0); // u/Tiefe sind hoehenunabhaengig (vertikale Ebene)
let u = plane.project(w)[0];
@@ -599,6 +603,7 @@ fn prism_bounds(plane: &SectionPlane, prism: &Prism) -> PrismBounds {
u_min = u_min.min(u);
u_max = u_max.max(u);
depth_min = depth_min.min(d);
depth_max = depth_max.max(d);
}
let mut opening_voids = Vec::new();
@@ -633,6 +638,7 @@ fn prism_bounds(plane: &SectionPlane, prism: &Prism) -> PrismBounds {
u_min,
u_max,
depth_min,
depth_max,
z0: prism.z0,
z1: prism.z1,
opening_voids,
@@ -805,6 +811,14 @@ fn blocked_intervals(
continue;
}
}
// Komplett VOR der Schnittebene (hinter dem Betrachter, weggeschnitten):
// verdeckt nichts. Vorher zaehlte z. B. die Fassade zwischen Betrachter
// und Schnittlinie als Verdecker und versteckte jede Ansichtskante
// dahinter (Rueckwand, Fenster, Innenwaende) — der Schnitt zeigte fast
// nur noch Poché.
if b.depth_max <= EPS {
continue;
}
let ru = height_in_range(u0, u1, b.u_min, b.u_max, HeightBias::Vertical);
let rv = height_in_range(v0, v1, b.z0, b.z1, bias);
let rd = linear_greater_than(d0, d1, b.depth_min + EPS);
@@ -1138,6 +1152,40 @@ mod tests {
assert!((uv[1] - 1.5).abs() < 1e-6, "v = world.y");
}
/// Regression (Nutzer-Report 2026-10-20, "im Schnitt fehlen die Ansichten"):
/// eine Wand komplett VOR der Ebene (zwischen Betrachter und Schnittlinie,
/// also weggeschnitten) darf die Rueckwand dahinter NICHT verdecken.
#[test]
fn wand_vor_der_ebene_verdeckt_nichts_dahinter() {
let mk = |start: [f32; 2], end: [f32; 2]| WallInput {
start,
end,
thickness: 0.2,
height: 2.5,
base_elevation: 0.0,
color: [0.8, 0.8, 0.8],
openings: vec![],
layers: None,
holes: vec![],
material_index: None,
hatch: None,
cut: None,
};
// Vorderwand bei y=0, Rueckwand bei y=6, Schnitt bei y=2 Blick nach +y.
let walls = vec![mk([0.0, 0.0], [8.0, 0.0]), mk([0.0, 6.0], [8.0, 6.0])];
let plane = SectionPlane::looking_plus_y(2.0);
let out = cut_section(&plane, &walls, &[], &[]);
assert!(out.cut_polygons.is_empty());
assert!(
out.visible_edges.iter().any(|e| e.component.index == 1),
"Rueckwand muss sichtbare Kanten haben"
);
assert!(
out.visible_edges.iter().all(|e| e.component.index != 0),
"Vorderwand liegt hinter dem Betrachter"
);
}
// --- Fall (a): Schnitt mittig durch einen Wandschenkel --------------------
#[test]
+38 -8
View File
@@ -25,6 +25,7 @@ import type {
Ceiling,
ContextObject,
Drawing2D,
DrawingLevel,
Layout,
Project,
Roof,
@@ -276,6 +277,27 @@ function coupledCommandFor(id: ToolId): string | null {
return TOOL_COMMAND[id] ?? null;
}
/**
* Auswahl für Transformationen/Befehle: im Schnitt/in der Ansicht nur die
* 2D-Elemente der Ebene. Bauteile (Wand/Decke/…) sind dort zwar anwählbar
* (Objekt-Info, Löschen), leben aber im Grundriss-Raum — ein im Schnitt-Blatt
* gemessenes Delta/Drehzentrum würde sie an eine falsche Stelle setzen.
*/
function sheetOnlySelection(level: DrawingLevel, sel: TransformSelection): TransformSelection {
if (level.kind !== "section" && level.kind !== "elevation") return sel;
return {
wallIds: [],
drawingId: sel.drawingId,
drawingIds: sel.drawingIds,
extrudedSolidId: null,
columnId: null,
ceilingIds: [],
roofIds: [],
stairIds: [],
roomIds: [],
};
}
export default function App() {
// Sprachwechsel abonnieren: re-rendert den gesamten Baum, wenn die Sprache
// umgeschaltet wird (alle Kinder lesen denselben modulweiten Zustand über t).
@@ -661,7 +683,7 @@ export default function App() {
// Zeichnungen, extrudierte Körper, Stützen, Decken/Dächer/Treppen/Räume) —
// sonst wirken die Kürzel m/s/d nur auf einen Teil dessen, was
// `commitTransform` tatsächlich bewegt.
const transformSel: TransformSelection = {
const transformSel: TransformSelection = sheetOnlySelection(activeLevel, {
wallIds: selectedWallIds,
drawingId: selectedDrawingId,
drawingIds: selectedDrawingIds,
@@ -671,7 +693,7 @@ export default function App() {
roofIds: selectedRoofIds,
stairIds: selectedStairIds,
roomIds: selectedRoomIds,
};
});
const snapForTransform = (raw: Vec2, pxPerMeter: number, mods: ToolMods, points: Vec2[]) =>
computeSnap({
raw,
@@ -855,7 +877,9 @@ export default function App() {
lastPoint,
// Vorab gesetzte Auswahl aus dem Store (Rhino: erst selektieren, dann
// Befehl). Move/Copy/Offset operieren darauf.
selection: {
// Im Schnitt/in der Ansicht nur die 2D-Elemente der Ebene: Bauteile
// leben im Grundriss-Raum, ein Schnitt-Delta wäre dort falsch.
selection: sheetOnlySelection(c.activeLevel, {
wallIds: c.selectedWallIds,
drawingId: c.selectedDrawingId,
drawingIds: c.selectedDrawingIds,
@@ -865,7 +889,7 @@ export default function App() {
roofIds: c.selectedRoofIds,
stairIds: c.selectedStairIds,
roomIds: c.selectedRoomIds,
},
}),
};
},
snap: (raw, draftPoints, mods) => {
@@ -1696,9 +1720,9 @@ export default function App() {
selectedWallIds,
selectedDrawingIds,
levelId: activeLevel.id,
modelEditable: activeLevel.kind !== "section" && activeLevel.kind !== "elevation",
visibleCodes,
scaleDenominator,
snap,
setDraft,
snapFor,
@@ -2253,16 +2277,22 @@ export default function App() {
// Gewählte Schnitt-/Ansichtslinie (DrawingLevel) — separat von `selection`, da
// eine Schnittlinie KEIN Projekt-Bauteil ist. Speist die Schnittlinien-Sektion
// des Object-Info-Panels.
// Ohne gewählte Linie, aber mit aktivem Schnitt/aktiver Ansicht: deren
// Einstellungen (Tiefe, verdeckte Kanten, Grundriss-Unterlage …) direkt im
// Leerzustand zeigen — man arbeitet ja gerade IN diesem Schnitt.
const sectionLineId =
selectedSectionLineId ??
(activeLevel.kind === "section" || activeLevel.kind === "elevation" ? activeLevel.id : null);
const sectionLine = useMemo(
() =>
selectedSectionLineId
sectionLineId
? project.drawingLevels.find(
(z) =>
z.id === selectedSectionLineId &&
z.id === sectionLineId &&
(z.kind === "section" || z.kind === "elevation"),
) ?? null
: null,
[project.drawingLevels, selectedSectionLineId],
[project.drawingLevels, sectionLineId],
);
// Abgeleitete 3D-Schnittebene der gebundenen Schnittlinie (world point+normal
+2
View File
@@ -694,6 +694,8 @@ export const de = {
"objinfo.sectionLine.endY": "Ende Y",
"objinfo.sectionLine.depth": "Schnitt-Tiefe (m)",
"objinfo.sectionLine.hiddenLines": "Verdeckte Kanten",
"objinfo.sectionLine.planUnderlay": "Grundriss darunter",
"objinfo.sectionLine.planUnderlay.none": "Keiner",
"objinfo.sectionLine.depthHint": "leer = unbegrenzt",
"objinfo.sectionLine.delete": "Schnittlinie löschen",
"objinfo.extrudedSolid.section": "Extrusion",
+2
View File
@@ -690,6 +690,8 @@ export const en: Record<TranslationKey, string> = {
"objinfo.sectionLine.endY": "End Y",
"objinfo.sectionLine.depth": "Section depth (m)",
"objinfo.sectionLine.hiddenLines": "Hidden lines",
"objinfo.sectionLine.planUnderlay": "Plan below",
"objinfo.sectionLine.planUnderlay.none": "None",
"objinfo.sectionLine.depthHint": "empty = unlimited",
"objinfo.sectionLine.delete": "Delete section line",
"objinfo.extrudedSolid.section": "Extrusion",
+7
View File
@@ -952,6 +952,13 @@ export interface DrawingLevel {
* legen sich sonst als blasses Liniengewirr über Poché und Ansichtskanten.
*/
hiddenLines?: boolean;
/**
* Grundriss-Unterlage (nur Schnitt/Ansicht): ID eines Geschosses, dessen
* Grundriss AUSGERICHTET unter dem Schnitt/der Ansicht gezeigt wird (Schnitt-
* linie waagrecht, Blickrichtung nach oben, s. `plan/planUnderlay.ts`).
* Fehlt ⇒ keine Unterlage.
*/
planUnderlayId?: string;
}
/**
+19
View File
@@ -539,6 +539,25 @@ export function SectionLineSection({
/>
</div>
{/* Grundriss-Unterlage: ein Geschoss ausgerichtet unter dem Schnitt/der Ansicht. */}
{line && (
<div className="objinfo-field">
<span className="objinfo-flabel">{t("objinfo.sectionLine.planUnderlay")}</span>
<Dropdown
value={level.planUnderlayId ?? ""}
onChange={(v) => host.onSetSectionLinePatch({ planUnderlayId: v || undefined })}
options={[
{ value: "", label: t("objinfo.sectionLine.planUnderlay.none") },
...host.project.drawingLevels
.filter((l) => l.kind === "floor")
.map((l) => ({ value: l.id, label: l.name })),
]}
title={t("objinfo.sectionLine.planUnderlay")}
width={150}
/>
</div>
)}
{/* Löschen: linePoints zurücksetzen (die Ebene bleibt bestehen). */}
<button type="button" className="objinfo-btn" onClick={() => host.onDeleteSectionLine()}>
{t("objinfo.sectionLine.delete")}
+15
View File
@@ -825,6 +825,8 @@ const SECTION_HIDDEN_INK = "#8a929c";
const SECTION_CUT_OUTLINE_MM = 0.35;
/** Strichstärke sichtbarer Ansichtskanten (mm Papier). */
const SECTION_VISIBLE_MM = 0.18;
/** Strichstärke der Bodenlinie unter dem Schnitt (mm Papier, wie in der Ansicht). */
const SECTION_GROUND_MM = 0.5;
/** Strichstärke verdeckter Ansichtskanten (mm Papier, dünner). */
const SECTION_HIDDEN_MM = 0.13;
/** Strichmuster verdeckter Kanten (mm Papier). */
@@ -957,6 +959,19 @@ export function generateSectionPlan(
});
}
// Bodenlinie wie in der Ansicht (toElevation.ts): kräftige Linie über die
// volle Breite an der untersten Kante — ohne sie "schwebte" der Schnitt.
if (isFinite(minX) && maxX > minX) {
primitives.push({
kind: "line",
a: { x: minX, y: minY },
b: { x: maxX, y: minY },
cls: "section-ground",
weightMm: SECTION_GROUND_MM,
color: SECTION_INK,
});
}
if (!isFinite(minX)) return { primitives, bounds: { minX: 0, minY: 0, maxX: 1, maxY: 1 } };
return { primitives, bounds: { minX, minY, maxX, maxY } };
}
+96
View File
@@ -0,0 +1,96 @@
import { describe, expect, it } from "vitest";
import type { DrawingLevel } from "../model/types";
import type { Primitive } from "./generatePlan";
import {
PLAN_UNDERLAY_GAP_M,
crossKindOverlayAllowed,
mapPlanPoint,
planToSectionMap,
planUnderlayPrimitives,
} from "./planUnderlay";
import { sectionPlaneFromLevel, sectionUAxisModel } from "./toSection";
const level = (p0: { x: number; y: number }, p1: { x: number; y: number }, sign: 1 | -1 = 1): DrawingLevel => ({
id: "s",
name: "S",
kind: "section",
visible: true,
locked: false,
linePoints: [p0, p1],
directionSign: sign,
});
const line = (a: { x: number; y: number }, b: { x: number; y: number }): Primitive => ({
kind: "line",
a,
b,
cls: "t",
weightMm: 0.25,
});
describe("planToSectionMap", () => {
it("u stimmt mit der Schnitt-u-Achse überein (Punkt liegt senkrecht unter seiner Projektion)", () => {
for (const [lv, p] of [
[level({ x: -1, y: 2 }, { x: 12, y: 2 }), { x: 4, y: 7 }],
[level({ x: 3, y: 0 }, { x: 3, y: 9 }, -1), { x: 6, y: 2 }],
[level({ x: 0, y: 0 }, { x: 5, y: 5 }), { x: 1, y: 3 }],
] as const) {
const m = planToSectionMap(lv)!;
const plane = sectionPlaneFromLevel(lv)!;
const uAx = sectionUAxisModel(plane);
const len = Math.hypot(uAx.x, uAx.y);
const uExpected = ((p.x - plane.point[0]) * uAx.x + (p.y - plane.point[2]) * uAx.y) / len;
expect(mapPlanPoint(m, p).x).toBeCloseTo(uExpected, 9);
}
});
it("Blickrichtung zeigt im Blatt nach oben, keine Spiegelung", () => {
// Linie entlang +x, Blick nach +y (Norden): reine Verschiebung.
const m = planToSectionMap(level({ x: -1, y: 2 }, { x: 12, y: 2 }))!;
expect(m.theta).toBeCloseTo(0, 12);
const q = mapPlanPoint(m, { x: 0, y: 5 });
expect(q.x).toBeCloseTo(1, 12);
expect(q.y).toBeCloseTo(3, 12); // 3 m hinter der Linie → 3 m nach oben
// Umgekehrte Blickrichtung: 180°-Drehung (Determinante +1).
const r = planToSectionMap(level({ x: -1, y: 2 }, { x: 12, y: 2 }, -1))!;
expect(Math.abs(r.theta)).toBeCloseTo(Math.PI, 12);
expect(mapPlanPoint(r, { x: 0, y: 0 }).y).toBeCloseTo(2, 12);
});
it("ohne Linie keine Abbildung", () => {
expect(planToSectionMap({ ...level({ x: 0, y: 0 }, { x: 1, y: 0 }), linePoints: undefined })).toBeNull();
});
});
describe("planUnderlayPrimitives", () => {
it("legt den Grundriss mit Abstand unter den Schnitt, gedimmt, plus Schnittlinie", () => {
const lv = level({ x: -1, y: 2 }, { x: 12, y: 2 });
const out = planUnderlayPrimitives(lv, [line({ x: 0, y: 0 }, { x: 11, y: 6 })], -0.3);
const mapped = out[0] as Extract<Primitive, { kind: "line" }>;
expect(mapped.greyed).toBe(true);
// Oberste Grundriss-Kante (y = 6 → w = 4) liegt GAP unter der Schnitt-Unterkante.
const top = Math.max(mapped.a.y, mapped.b.y);
expect(top).toBeCloseTo(-0.3 - PLAN_UNDERLAY_GAP_M, 9);
// u bleibt erhalten (x − (−1)).
expect(Math.min(mapped.a.x, mapped.b.x)).toBeCloseTo(1, 9);
const cut = out[out.length - 1] as Extract<Primitive, { kind: "line" }>;
expect(cut.cls).toBe("section-underlay-line");
expect(cut.b.x - cut.a.x).toBeCloseTo(13, 9);
// Schnittlinie liegt 4 m unter der obersten Grundriss-Kante (w = 0).
expect(cut.a.y).toBeCloseTo(top - 4, 9);
});
});
describe("crossKindOverlayAllowed", () => {
it("nur Ebenen im selben Koordinatenraum überlagern sich", () => {
expect(crossKindOverlayAllowed("floor", "drawing")).toBe(true);
expect(crossKindOverlayAllowed("floor", "section")).toBe(false);
expect(crossKindOverlayAllowed("floor", "elevation")).toBe(false);
expect(crossKindOverlayAllowed("section", "floor")).toBe(false);
expect(crossKindOverlayAllowed("elevation", "section")).toBe(false);
expect(crossKindOverlayAllowed("section", "drawing")).toBe(false);
// Freie Zeichnung bleibt Kalkierpapier für alles.
expect(crossKindOverlayAllowed("drawing", "section")).toBe(true);
expect(crossKindOverlayAllowed("drawing", "floor")).toBe(true);
});
});
+184
View File
@@ -0,0 +1,184 @@
// Grundriss-Unterlage in Schnitt/Ansicht: ein Geschoss-Grundriss wird
// AUSGERICHTET unter die Schnitt-/Ansichtsfläche gelegt — wie die klassische
// Konstruktion "Ansicht über dem Grundriss". Die Schnittlinie wird dazu
// waagrecht gedreht, die Blickrichtung zeigt im Blatt nach OBEN (Betrachter
// steht unten, die gesehene Fassade liegt an der Unterkante des Grundrisses),
// und die u-Achse stimmt exakt mit der des Schnitts/der Ansicht überein
// (`sectionUAxisModel` / `elevationFrame`): ein Punkt im Grundriss liegt also
// senkrecht unter seiner Projektion im Schnitt.
//
// Reine Starrkörper-Abbildung (Drehung + Verschiebung, keine Spiegelung) —
// Kreise bleiben Kreise, Bögen behalten ihren Drehsinn.
import type { DrawingLevel, DrawingLevelKind, Vec2 } from "../model/types";
import type { Primitive } from "./generatePlan";
/** Abstand (Meter) zwischen tiefster Schnitt-/Ansichtskante und Grundriss-Oberkante. */
export const PLAN_UNDERLAY_GAP_M = 1.5;
/** Abbildung Grundriss (Modell x/y) → Schnitt-Blatt (u, Höhe). */
export interface PlanToSectionMap {
/** Ursprung = Startpunkt der Schnittlinie. */
p0: Vec2;
/** Horizontale Schnitt-u-Achse im Grundriss (Blickrichtungs-RECHTS). */
u: Vec2;
/** Blickrichtung im Grundriss (Einheit). */
n: Vec2;
/** Drehwinkel (Radiant, CCW) der Abbildung. */
theta: number;
/** Vertikaler Versatz im Blatt. */
dy: number;
}
/**
* Baut die Abbildung aus der Schnitt-/Ansichtslinie einer Ebene (`null` ohne
* Linie). `dy` bleibt 0 — der Aufrufer schiebt den Grundriss danach unter den
* Schnitt (s. {@link planUnderlayPrimitives}).
*/
export function planToSectionMap(level: DrawingLevel): PlanToSectionMap | null {
const line = level.linePoints;
if (!line) return null;
const [p0, p1] = line;
const len = Math.hypot(p1.x - p0.x, p1.y - p0.y);
if (len < 1e-9) return null;
const dx = (p1.x - p0.x) / len;
const dy = (p1.y - p0.y) / len;
const sign = level.directionSign ?? 1;
// Wie `sectionPlaneFromLevel`: Links-Normale der Linie, per directionSign gedreht.
const n: Vec2 = { x: -dy * sign, y: dx * sign };
// Wie `sectionUAxisModel`: u = (n.y, −n.x) — Blickrichtungs-RECHTS.
const u: Vec2 = { x: n.y, y: -n.x };
// Bild der x-Achse (1,0) ist (u.x, n.x) → cosθ = u.x, sinθ = n.x.
return { p0, u, n, theta: Math.atan2(n.x, u.x), dy: 0 };
}
/** Bildet einen Grundriss-Punkt ins Schnitt-Blatt ab. */
export function mapPlanPoint(m: PlanToSectionMap, p: Vec2): Vec2 {
const rx = p.x - m.p0.x;
const ry = p.y - m.p0.y;
return { x: rx * m.u.x + ry * m.u.y, y: rx * m.n.x + ry * m.n.y + m.dy };
}
/**
* Bildet ein Plan-Primitiv ab. Achsparallele Rasterbilder lassen sich nicht
* drehen und entfallen (`null`) — ausser die Abbildung ist eine reine
* Verschiebung.
*/
export function mapPlanPrimitive(m: PlanToSectionMap, pr: Primitive): Primitive | null {
const P = (p: Vec2) => mapPlanPoint(m, p);
switch (pr.kind) {
case "polygon": {
const hatch = pr.hatch.origin || m.theta !== 0
? {
...pr.hatch,
// SVG-Musterwinkel dreht im Uhrzeigersinn (Bildschirm) = −Winkel im Modell.
angle: pr.hatch.angle - (m.theta * 180) / Math.PI,
origin: pr.hatch.origin ? P(pr.hatch.origin) : undefined,
}
: pr.hatch;
return { ...pr, pts: pr.pts.map(P), hatch };
}
case "line":
// `motif` ist im Strich-lokalen Raum definiert — dreht mit der Linie mit.
return { ...pr, a: P(pr.a), b: P(pr.b) };
case "arc":
return { ...pr, center: P(pr.center), from: P(pr.from), to: P(pr.to) };
case "text":
return { ...pr, at: P(pr.at) };
case "drawingText":
return { ...pr, at: P(pr.at), angle: pr.angle + m.theta };
case "drawingTextPath":
return { ...pr, pathPts: pr.pathPts.map(P) };
case "drawingCircle":
return { ...pr, center: P(pr.center) };
case "drawingArc":
return { ...pr, center: P(pr.center), a0: pr.a0 + m.theta, a1: pr.a1 + m.theta };
case "drawingImage": {
if (Math.abs(m.theta) > 1e-9) return null;
const a = P(pr.min);
const b = P(pr.max);
return {
...pr,
min: { x: Math.min(a.x, b.x), y: Math.min(a.y, b.y) },
max: { x: Math.max(a.x, b.x), y: Math.max(a.y, b.y) },
};
}
}
}
/** Alle Stützpunkte eines Primitivs (für die Höhenlage der Unterlage). */
function primitivePoints(pr: Primitive): Vec2[] {
switch (pr.kind) {
case "polygon": return pr.pts;
case "line": return [pr.a, pr.b];
case "arc": return [pr.from, pr.to, pr.center];
case "text":
case "drawingText": return [pr.at];
case "drawingTextPath": return pr.pathPts;
case "drawingCircle":
case "drawingArc":
return [{ x: pr.center.x, y: pr.center.y + pr.r }];
case "drawingImage": return [pr.min, pr.max];
}
}
/**
* Legt die Grundriss-Primitive `planPrims` ausgerichtet unter einen Schnitt/
* eine Ansicht, deren tiefste Kante bei `sectionMinY` liegt. Die Unterlage ist
* gedimmt (Referenz) und trägt zusätzlich die Schnittlinie selbst (strichpunk-
* tiert), damit sichtbar ist, wo geschnitten bzw. von wo geblickt wird.
*/
export function planUnderlayPrimitives(
level: DrawingLevel,
planPrims: Primitive[],
sectionMinY: number,
): Primitive[] {
const base = planToSectionMap(level);
if (!base) return [];
const mapped: Primitive[] = [];
let maxY = -Infinity;
for (const pr of planPrims) {
const q = mapPlanPrimitive(base, pr);
if (!q) continue;
for (const p of primitivePoints(q)) if (p.y > maxY) maxY = p.y;
mapped.push(q);
}
// Schnittlinie (w = 0) liegt immer mit in der Unterlage.
if (0 > maxY) maxY = 0;
const shift = sectionMinY - PLAN_UNDERLAY_GAP_M - maxY;
const out: Primitive[] = [];
for (const q of mapped) {
const moved = mapPlanPrimitive({ p0: { x: 0, y: 0 }, u: { x: 1, y: 0 }, n: { x: 0, y: 1 }, theta: 0, dy: shift }, q);
if (moved) out.push({ ...moved, greyed: true } as Primitive);
}
const [l0, l1] = level.linePoints!;
const len = Math.hypot(l1.x - l0.x, l1.y - l0.y);
out.push({
kind: "line",
a: { x: 0, y: shift },
b: { x: len, y: shift },
cls: "section-underlay-line",
weightMm: 0.25,
dash: [3, 0.8, 0.4, 0.8],
color: "#8a3b2c",
});
return out;
}
/**
* Welche Fremd-Art-Ebene darf als Unterlage in welcher aktiven Ebene erscheinen?
* Massgebend ist der Koordinatenraum: Geschoss und freie Zeichnung teilen X/Y,
* Schnitte/Ansichten messen dagegen Länge×Höhe entlang IHRER Linie. Ein Schnitt
* im Grundriss (oder ein Grundriss/eine andere Ansicht im Schnitt) lag darum
* nur zufällig irgendwo und überdeckte den eigentlichen Plan (Nutzer-Report
* 2026-10-20: Fenster der Ansicht im EG-Grundriss, Raumstempel im Schnitt).
* • freie Zeichnung: alles (Kalkierpapier zum Abzeichnen, Nutzer-Wunsch).
* • Geschoss: nur freie Zeichnungen (gleicher X/Y-Raum).
* • Schnitt/Ansicht: nichts — ein Grundriss kommt dort ausgerichtet über
* `DrawingLevel.planUnderlayId` dazu (s. plan/planUnderlay.ts).
*/
export function crossKindOverlayAllowed(active: DrawingLevelKind, other: DrawingLevelKind): boolean {
if (active === "drawing") return true;
if (active === "floor") return other === "drawing";
return false;
}
+38
View File
@@ -0,0 +1,38 @@
import { describe, expect, it } from "vitest";
import { sampleProject } from "../model/sampleProject";
import type { DrawingLevel } from "../model/types";
import type { Primitive } from "./generatePlan";
import { sectionOpeningPrimitives } from "./sectionOpenings";
const section = (x: number): DrawingLevel => ({
id: "sx",
name: "Sx",
kind: "section",
visible: true,
locked: false,
// Senkrecht durch W1 (y = 0) bei x, Blick nach Westen.
linePoints: [{ x, y: -1 }, { x, y: 5 }],
directionSign: 1,
});
describe("sectionOpeningPrimitives", () => {
it("geschnittenes Fenster: Rahmenprofile an Brüstung/Sturz + Glaslinie, wählbar", () => {
const prims = sectionOpeningPrimitives(sampleProject, section(3.5));
const own = prims.filter((p) => "openingId" in p && p.openingId === "O1");
expect(own.length).toBeGreaterThanOrEqual(4);
const glass = own.filter((p): p is Extract<Primitive, { kind: "line" }> => p.kind === "line");
expect(glass.length).toBeGreaterThan(0);
// Glas läuft zwischen Brüstung (0.9 m über Wand-UK) und Sturz (2.1 m) — mit Rahmen dazwischen.
const vs = glass.flatMap((g) => [g.a.y, g.b.y]);
expect(Math.min(...vs)).toBeGreaterThan(0.9);
expect(Math.max(...vs)).toBeLessThan(2.1 + 1e-9);
});
it("Schnitt neben dem Fenster: nichts", () => {
expect(sectionOpeningPrimitives(sampleProject, section(1.0)).some((p) => "openingId" in p && p.openingId === "O1")).toBe(false);
});
it("Ansichten bekommen keine Schnitt-Öffnungen", () => {
expect(sectionOpeningPrimitives(sampleProject, { ...section(3.5), kind: "elevation" })).toEqual([]);
});
});
+210
View File
@@ -0,0 +1,210 @@
// Geschnittene Fenster/Türen im Schnitt. Der Schnitt-Extraktor (section.rs)
// spart in einer geschnittenen Wand nur die Öffnung aus (Brüstung + Sturz als
// Poché, dazwischen nichts) — das Fenster selbst fehlte, die Öffnung wirkte wie
// ein Loch. Hier entsteht der vertikale Querschnitt des Öffnungselements:
// • Fenster: Blendrahmen-Profil unten (auf der Brüstung) und oben (am Sturz)
// über die Rahmentiefe + Glaslinie(n) dazwischen. Rahmentiefe/-lage und
// Glas-Lage stammen aus DEMSELBEN `windowSymbol` wie der Grundriss — die
// Lage in der Wand stimmt also mit dem Grundriss überein.
// • Tür: Zargen-Profil am Sturz + geschlossenes Türblatt.
// Alles in Schnitt-Koordinaten (u, Höhe), wie `SectionOutput`.
import type { DrawingLevel, Opening, Project, Vec2, Wall } from "../model/types";
import { getWallType, getWindowType, sashesOfWindowType, wallTypeThickness } from "../model/types";
import { dot, sub } from "../model/geometry";
import { wallReferenceOffset } from "../model/wall";
import { openingInterval, openingVerticalExtent, wallAxisFrame, windowSymbol } from "../geometry/opening";
import { NO_HATCH, SHOW_ALL, type CategoryDisplayResolver, type Primitive } from "./generatePlan/shared";
import { sectionPlaneFromLevel, sectionUAxisModel } from "./toSection";
const INK = "#1f242c";
/** Umriss geschnittener Rahmen-/Blattprofile (mm Papier). */
const FRAME_MM = 0.25;
/** Glaslinien (mm Papier). */
const GLASS_MM = 0.13;
/** Default-Rahmentiefe/-profilbreite (m), wie im Grundriss (`opening.ts`). */
const DEFAULT_FRAME_DEPTH = 0.07;
const DEFAULT_FRAME_WIDTH = 0.06;
/** Türblatt-Dicke (m). */
const DOOR_LEAF_THICKNESS = 0.04;
/** Unter diesem |cos| zwischen Wandnormale und Schnitt-u gilt die Wand als
* (fast) parallel zum Schnitt — dort gibt es keinen sinnvollen Querschnitt. */
const MIN_CROSS = 0.15;
const rect = (u0: number, u1: number, v0: number, v1: number): Vec2[] => [
{ x: Math.min(u0, u1), y: v0 },
{ x: Math.max(u0, u1), y: v0 },
{ x: Math.max(u0, u1), y: v1 },
{ x: Math.min(u0, u1), y: v1 },
];
/**
* Plan-Primitive (u, Höhe) aller Fenster/Türen, deren Wand die Schnittebene der
* Ebene `level` IM Bereich der Öffnung kreuzt. Jedes Primitiv trägt die
* `openingId` — ein Klick im Schnitt wählt die Öffnung.
*/
export function sectionOpeningPrimitives(
project: Project,
level: DrawingLevel,
visibleCodes?: Set<string>,
categoryDisplay: CategoryDisplayResolver = SHOW_ALL,
): Primitive[] {
const plane = sectionPlaneFromLevel(level);
if (!plane || level.kind !== "section") return [];
const uRaw = sectionUAxisModel(plane);
const uLen = Math.hypot(uRaw.x, uRaw.y) || 1;
const U: Vec2 = { x: uRaw.x / uLen, y: uRaw.y / uLen };
const P0: Vec2 = { x: plane.point[0], y: plane.point[2] };
const wallsById = new Map(project.walls.map((w) => [w.id, w]));
const out: Primitive[] = [];
for (const o of project.openings ?? []) {
if (visibleCodes && !visibleCodes.has(o.categoryCode)) continue;
const disp = categoryDisplay(o.categoryCode);
if (!disp.render) continue;
const wall = wallsById.get(o.hostWallId);
if (!wall) continue;
if (visibleCodes && !visibleCodes.has(wall.categoryCode)) continue;
const cut = crossSection(project, wall, o, P0, U);
if (!cut) continue;
const prims = o.kind === "window" ? windowCut(project, wall, o, cut) : doorCut(o, cut);
for (const p of prims) out.push(disp.greyed ? ({ ...p, greyed: true } as Primitive) : p);
}
return out;
}
/** Abbildung "Offset quer zur Wand (n)" → Schnitt-u, falls die Schnittebene die
* Wandachse innerhalb der Öffnung kreuzt. */
interface CrossSection {
/** u eines Punktes mit Wand-Offset `s` (entlang der linken Normalen). */
uAt: (s: number) => number;
zBottom: number;
zTop: number;
/** Wand-Offsets der Wandflächen (min/max). */
faceMin: number;
faceMax: number;
}
function crossSection(project: Project, wall: Wall, o: Opening, P0: Vec2, U: Vec2): CrossSection | null {
const iv = openingInterval(wall, o);
if (!iv) return null;
const { u: a, n } = wallAxisFrame(wall);
const un = dot(U, n);
if (Math.abs(un) < MIN_CROSS) return null;
const rel = sub(P0, wall.start);
const n0 = dot(rel, n);
const a0 = dot(rel, a);
const ua = dot(U, a);
// Schnittlinie p(t) = P0 + t·U; Offset quer zur Wand: n0 + t·un.
const tAt = (s: number) => (s - n0) / un;
// Lage entlang der Achse dort, wo die Schnittlinie die Wandmitte quert.
const total = wallTypeThickness(getWallType(project, wall));
const refOff = wallReferenceOffset(wall, total);
const along = a0 + tAt(refOff) * ua;
if (along < iv.from + 1e-4 || along > iv.to - 1e-4) return null;
const { zBottom, zTop } = openingVerticalExtent(project, wall, o);
if (zTop - zBottom < 1e-3) return null;
return {
uAt: (s) => tAt(s),
zBottom,
zTop,
faceMin: refOff - total / 2,
faceMax: refOff + total / 2,
};
}
const profile = (pts: Vec2[], openingId: string): Primitive => ({
kind: "polygon",
pts,
fill: "#ffffff",
stroke: INK,
strokeWidthMm: FRAME_MM,
hatch: NO_HATCH,
openingId,
});
const pick = (pts: Vec2[], openingId: string): Primitive => ({
kind: "polygon",
pts,
fill: "none",
stroke: "none",
strokeWidthMm: 0,
hatch: NO_HATCH,
openingId,
});
function windowCut(project: Project, wall: Wall, o: Opening, c: CrossSection): Primitive[] {
const wt = getWindowType(project, o);
const spec = wt
? {
sashes: sashesOfWindowType(wt),
frameWidth: wt.frameWidth ?? DEFAULT_FRAME_WIDTH,
frameDepth: wt.frameDepth,
insetFromFace: wt.insetFromFace,
insetFace: wt.insetFace,
}
: undefined;
const fw = Math.max(0.02, spec?.frameWidth ?? DEFAULT_FRAME_WIDTH);
const { n } = wallAxisFrame(wall);
const offOf = (p: Vec2) => dot(sub(p, wall.start), n);
// Rahmenband quer zur Wand aus dem Grundriss-Symbol (gleiche Lage wie dort).
let fMin = (c.faceMin + c.faceMax) / 2 - DEFAULT_FRAME_DEPTH / 2;
let fMax = fMin + DEFAULT_FRAME_DEPTH;
let glass: number[] = [(fMin + fMax) / 2];
const sym = windowSymbol(project, wall, o, 1, spec, "mittel");
if (sym && spec) {
const offs = sym.frame.map(offOf);
fMin = Math.min(...offs);
fMax = Math.max(...offs);
const g = sym.glassLines.map(([p]) => offOf(p));
if (g.length > 0) glass = [...new Set(g.map((x) => Math.round(x * 1e6) / 1e6))];
}
const u0 = c.uAt(fMin);
const u1 = c.uAt(fMax);
const h = c.zTop - c.zBottom;
const fwv = Math.min(fw, h / 3);
const out: Primitive[] = [pick(rect(c.uAt(c.faceMin), c.uAt(c.faceMax), c.zBottom, c.zTop), o.id)];
out.push(profile(rect(u0, u1, c.zBottom, c.zBottom + fwv), o.id));
out.push(profile(rect(u0, u1, c.zTop - fwv, c.zTop), o.id));
for (const s of glass) {
const u = c.uAt(s);
out.push({
kind: "line",
a: { x: u, y: c.zBottom + fwv },
b: { x: u, y: c.zTop - fwv },
cls: "section-window-glass",
weightMm: GLASS_MM,
color: INK,
openingId: o.id,
});
}
return out;
}
function doorCut(o: Opening, c: CrossSection): Primitive[] {
const out: Primitive[] = [pick(rect(c.uAt(c.faceMin), c.uAt(c.faceMax), c.zBottom, c.zTop), o.id)];
if (o.doorType === "wandoeffnung") return out;
const mid = (c.faceMin + c.faceMax) / 2;
const fw = Math.min(DEFAULT_FRAME_WIDTH, (c.zTop - c.zBottom) / 4);
// Zarge am Sturz über die Rahmentiefe.
out.push(
profile(
rect(c.uAt(mid - DEFAULT_FRAME_DEPTH / 2), c.uAt(mid + DEFAULT_FRAME_DEPTH / 2), c.zTop - fw, c.zTop),
o.id,
),
);
// Geschlossenes Türblatt (knapp über Boden bis unter die Zarge).
out.push(
profile(
rect(
c.uAt(mid - DOOR_LEAF_THICKNESS / 2),
c.uAt(mid + DOOR_LEAF_THICKNESS / 2),
c.zBottom + 0.01,
c.zTop - fw,
),
o.id,
),
);
return out;
}
+31
View File
@@ -0,0 +1,31 @@
import { describe, expect, it } from "vitest";
import type { DrawingLevel, Project } from "../model/types";
import { sameSectionInputs, sameSectionLine } from "./toSection";
const project = { walls: [], drawings2d: [], ceilings: [] } as unknown as Project;
describe("sameSectionInputs", () => {
it("2D-Zeichnungen (z. B. Linien im Schnitt) lösen keine Neuberechnung aus", () => {
expect(sameSectionInputs(project, { ...project, drawings2d: [] })).toBe(true);
});
it("Bauteil-Änderungen schon", () => {
expect(sameSectionInputs(project, { ...project, walls: [] })).toBe(false);
});
});
describe("sameSectionLine", () => {
const lv: DrawingLevel = {
id: "s",
name: "S",
kind: "section",
visible: true,
locked: false,
linePoints: [{ x: 0, y: 0 }, { x: 5, y: 0 }],
};
it("Name/Unterlage egal, Linie/Richtung/Tiefe nicht", () => {
expect(sameSectionLine(lv, { ...lv, name: "X", planUnderlayId: "eg", hiddenLines: true })).toBe(true);
expect(sameSectionLine(lv, { ...lv, linePoints: [{ x: 0, y: 0 }, { x: 5, y: 1 }] })).toBe(false);
expect(sameSectionLine(lv, { ...lv, directionSign: -1 })).toBe(false);
expect(sameSectionLine(lv, { ...lv, depth: 3 })).toBe(false);
});
});
+44
View File
@@ -1213,3 +1213,47 @@ export async function computeSection(
if (level.depth !== undefined) filterByDepth(output, project, plane, level.depth);
return output;
}
/**
* Projekt-Felder, die den abgeleiteten Schnitt/die Ansicht NICHT beeinflussen.
* Vor allem `drawings2d`: jede Linie, die man IM Schnitt zeichnet, landet dort —
* ohne diesen Ausschluss rechnete jede solche Änderung den ganzen Schnitt neu.
*/
const SECTION_IRRELEVANT_KEYS = new Set<string>(["drawings2d", "layouts", "viewSnapshots", "masterLayouts"]);
/**
* Ob zwei Projektstände denselben Schnitt/dieselbe Ansicht ergeben — Vergleich
* je Feld per Referenz (das Projekt wird immutabel aktualisiert, unveränderte
* Teile behalten ihre Identität), ohne {@link SECTION_IRRELEVANT_KEYS}. Bei
* Unsicherheit `false` (dann wird eben neu gerechnet).
*/
export function sameSectionInputs(a: Project, b: Project): boolean {
if (a === b) return true;
const ra = a as unknown as Record<string, unknown>;
const rb = b as unknown as Record<string, unknown>;
const keys = new Set([...Object.keys(ra), ...Object.keys(rb)]);
for (const k of keys) {
if (SECTION_IRRELEVANT_KEYS.has(k)) continue;
if (ra[k] !== rb[k]) return false;
}
return true;
}
/** Ob zwei Stände einer Schnitt-/Ansichtsebene dieselbe Projektion ergeben. */
export function sameSectionLine(a: DrawingLevel, b: DrawingLevel): boolean {
if (a === b) return true;
const la = a.linePoints;
const lb = b.linePoints;
const sameLine =
la === lb ||
(!!la && !!lb &&
la[0].x === lb[0].x && la[0].y === lb[0].y && la[1].x === lb[1].x && la[1].y === lb[1].y);
return (
sameLine &&
a.id === b.id &&
a.kind === b.kind &&
(a.directionSign ?? 1) === (b.directionSign ?? 1) &&
a.depth === b.depth &&
!!a.shadows === !!b.shadows
);
}
+22 -8
View File
@@ -40,6 +40,15 @@ export function useGripEditing(opts: {
selectedWallIds: string[];
selectedDrawingIds: string[];
levelId: string;
/**
* Ob Modell-Bauteile (Wand/Decke/Raum/Öffnung/Treppe) Griffe bekommen und per
* Körper-Zug verschoben werden dürfen. `false` im Schnitt/in der Ansicht: deren
* Blatt misst Länge×Höhe entlang der Schnittlinie, die Bauteile aber X/Y im
* Grundriss — Griffe lägen an völlig falschen Stellen und ein Zug würde das
* Schnitt-Delta als Grundriss-Verschiebung anwenden. 2D-Elemente der Ebene
* selbst bleiben voll editierbar (sie leben im Blatt-Raum).
*/
modelEditable?: boolean;
visibleCodes: Set<string>;
/** Papier-Massstab (1:N) — die Bemassungs-Griffe hängen daran (Papier-mm). */
scaleDenominator: number;
@@ -86,6 +95,7 @@ export function useGripEditing(opts: {
selectedWallIds,
selectedDrawingIds,
levelId,
modelEditable = true,
visibleCodes,
scaleDenominator,
snap,
@@ -165,7 +175,8 @@ export function useGripEditing(opts: {
// Öffnung (Fenster/Tür): EIN Mittelpunkt-Griff auf der Wandachse. Ziehen
// verschiebt die Öffnung entlang der Wirts-Wand (siehe applyGrip →
// `position`). Nur bei genau einer selektierten Öffnung (Auswahl exklusiv).
if (selectedOpeningId) {
if (!modelEditable && effectiveDrawingIds.length === 0) return [];
if (selectedOpeningId && modelEditable) {
const op = (project.openings ?? []).find((o) => o.id === selectedOpeningId);
const w = op && project.walls.find((x) => x.id === op.hostWallId);
if (op && w) {
@@ -179,7 +190,7 @@ export function useGripEditing(opts: {
}
// Treppe: EIN Bewegpunkt (siehe stairMoveHandle); Ziehen verschiebt die
// ganze Treppe (applyGrip → moveStairBy). Auswahl exklusiv.
if (selectedStairId) {
if (selectedStairId && modelEditable) {
const st = (project.stairs ?? []).find((s) => s.id === selectedStairId);
if (!st) return [];
gripOwners.push({ localIndex: 0 });
@@ -188,13 +199,14 @@ export function useGripEditing(opts: {
}
// Decke: die Umriss-Vertices als Griffe (nur bei genau einer gewählten Decke,
// solange kein 2D-Element/Wand mitgewählt ist — kein Multi-Select für Decken).
if (selectedCeiling && effectiveDrawingIds.length === 0 && selectedWallIds.length === 0) {
if (modelEditable && selectedCeiling && effectiveDrawingIds.length === 0 && selectedWallIds.length === 0) {
const pts = [...selectedCeiling.outline];
pts.forEach((_, i) => { gripOwners.push({ localIndex: i }); gripOwnerRange.push([0, pts.length - 1]); });
return pts;
}
// Raum: die Umriss-Vertices als Griffe (nur bei genau einem gewählten Raum).
if (
modelEditable &&
selectedRoom &&
effectiveDrawingIds.length === 0 &&
selectedWallIds.length === 0 &&
@@ -239,7 +251,7 @@ export function useGripEditing(opts: {
: undefined;
pushGroup(drawingVertices(d, scaleDenominator), { drawingId: id }, keep);
}
if (effectiveDrawingIds.length === 0) {
if (modelEditable && effectiveDrawingIds.length === 0) {
for (const id of selectedWallIds) {
const w = project.walls.find((x) => x.id === id);
if (w) pushGroup([w.start, w.end], { wallId: id });
@@ -334,11 +346,12 @@ export function useGripEditing(opts: {
return out;
};
// Decke: geschlossener Ring aus dem Umriss (Auswahl exklusiv, wie bei grips).
if (selectedCeiling && effectiveDrawingIds.length === 0 && selectedWallIds.length === 0) {
if (modelEditable && selectedCeiling && effectiveDrawingIds.length === 0 && selectedWallIds.length === 0) {
return ringEdges(selectedCeiling.outline, {});
}
// Raum: geschlossener Ring aus dem Umriss.
if (
modelEditable &&
selectedRoom &&
effectiveDrawingIds.length === 0 &&
selectedWallIds.length === 0 &&
@@ -360,7 +373,7 @@ export function useGripEditing(opts: {
else if (g.shape === "spline" && !g.closed) out.push(...openEdges(verts, owner));
else if (g.shape === "line") out.push(...openEdges(verts, owner));
}
if (effectiveDrawingIds.length === 0) {
if (modelEditable && effectiveDrawingIds.length === 0) {
for (const id of selectedWallIds) {
const w = project.walls.find((x) => x.id === id);
if (!w) continue;
@@ -1161,7 +1174,7 @@ export function useGripEditing(opts: {
}
// Decke: ganzen Umriss verschieben (kein Multi-Koinzidenz-Handling nötig).
// Decke/Treppe/Raum: nur Gesamt-Delta + Vorschau, Projekt erst beim Loslassen.
const areaTarget: { kind: "ceiling" | "room" | "stair"; id: string } | null = target
const areaTarget: { kind: "ceiling" | "room" | "stair"; id: string } | null = target || !modelEditable
? null
: selectedCeilingId
? { kind: "ceiling", id: selectedCeilingId }
@@ -1185,7 +1198,8 @@ export function useGripEditing(opts: {
// Gegriffenes Element: bei Mehrfachauswahl das unter dem Cursor (target),
// sonst das einzeln selektierte. Wand UND 2D schließen sich aus.
const moveDrawingId = target ? target.drawingId ?? null : selectedDrawingId;
const moveWallId = target ? target.wallId ?? null : selectedWallId;
const moveWallId = modelEditable ? (target ? target.wallId ?? null : selectedWallId) : null;
if (!moveDrawingId && !moveWallId) return;
// 2D-Element: nur Gesamt-Delta merken + Vorschau; Projekt erst beim Loslassen.
// Wand: Gesamt-Delta + Vorschau; beim Loslassen folgen verbundene Eckpunkte.
if (moveWallId && !moveDrawingId) {
+2 -2
View File
@@ -960,10 +960,10 @@ export function usePanelHostBase(opts: {
// ── Schnitt-/Ansichtslinie (nur bei selektierter Linie) ────────────────
sectionLine,
onSetSectionLinePatch: (patch) => {
if (selectedSectionLineId) patchLevel(selectedSectionLineId, patch);
if (sectionLine) patchLevel(sectionLine.id, patch);
},
onDeleteSectionLine: () => {
if (selectedSectionLineId) patchLevel(selectedSectionLineId, { linePoints: undefined });
if (sectionLine) patchLevel(sectionLine.id, { linePoints: undefined });
},
// 3D-Live-Schnitt an die gewählte Schnittlinie binden (Toggle im Objekt-Info).
section3dCutActive: section3dCutId != null && section3dCutId === sectionLine?.id,
+5
View File
@@ -1982,6 +1982,11 @@ body {
padding: 4px 9px;
border-radius: 999px;
}
/* Über einer PlanView mit Lineal: unter/neben die Lineal-Leisten rücken. */
.pane-title--ruled {
top: 30px;
left: 30px;
}
.placeholder {
flex: 1;
+76
View File
@@ -0,0 +1,76 @@
import { afterEach, describe, expect, it } from "vitest";
import type { Project } from "../model/types";
import type { Primitive } from "../plan/generatePlan";
import { computeSnap } from "./snapping";
import { setSheetSnapSegments, snapSegmentsFromPrimitives } from "./sheetSnapGeometry";
import { DEFAULT_SNAP } from "./types";
const HATCH = { pattern: "none", scale: 1, angle: 0, color: "#000", lineWeight: 0.1, dash: null } as const;
const rect = (x0: number, y0: number, x1: number, y1: number): Primitive => ({
kind: "polygon",
pts: [
{ x: x0, y: y0 },
{ x: x1, y: y0 },
{ x: x1, y: y1 },
{ x: x0, y: y1 },
],
fill: "#fff",
stroke: "#000",
strokeWidthMm: 0.35,
hatch: { ...HATCH },
});
const emptyProject = (): Project =>
({
id: "p",
name: "P",
lineStyles: [],
hatches: [],
components: [],
wallTypes: [],
drawingLevels: [{ id: "s", name: "S", kind: "section", visible: true, locked: false }],
layers: [],
walls: [],
drawings2d: [],
context: [],
}) as unknown as Project;
describe("snapSegmentsFromPrimitives", () => {
it("Polygon-Kanten + Linien, geteilte Fugen nur einmal", () => {
// Zwei Bänder teilen die Kante x = 1.
const segs = snapSegmentsFromPrimitives([rect(0, 0, 1, 2), rect(1, 0, 2, 2)]);
expect(segs.length).toBe(7);
});
});
describe("computeSnap — abgeleitete Blatt-Geometrie (Schnitt/Ansicht)", () => {
afterEach(() => setSheetSnapSegments("s", null));
const snapAt = (x: number, y: number, levelId = "s") =>
computeSnap({
raw: { x, y },
project: emptyProject(),
levelId,
visibleCodes: new Set(),
settings: { ...DEFAULT_SNAP, grid: false },
draftPoints: [],
lastPoint: null,
pxPerMeter: 100,
shift: false,
ctrl: false,
});
it("fängt an Ecken der Schnitt-Poché", () => {
setSheetSnapSegments("s", snapSegmentsFromPrimitives([rect(0, 0, 0.3, 2.6)]));
const r = snapAt(0.32, 2.58);
expect(r?.kind).toBe("endpoint");
expect(r?.point.x).toBeCloseTo(0.3, 9);
expect(r?.point.y).toBeCloseTo(2.6, 9);
});
it("gilt nur für die eigene Ebene", () => {
setSheetSnapSegments("s", snapSegmentsFromPrimitives([rect(0, 0, 0.3, 2.6)]));
expect(snapAt(0.32, 2.58, "andere")?.kind).not.toBe("endpoint");
});
});
+58
View File
@@ -0,0 +1,58 @@
// Fang-Geometrie abgeleiteter Blätter (Schnitt/Ansicht). Deren Linien entstehen
// erst in der Ansicht (Schnitt-Extraktor bzw. Ansichts-Generator) und stehen
// NICHT im Projekt — `computeSnap` kennt sonst nur Projekt-Elemente der Ebene
// (im Schnitt also nur die 2D-Zeichnungen), man konnte an keine Schnitt- oder
// Ansichtskante fangen. Die Ansicht legt ihre Strecken hier je Ebenen-ID ab,
// `computeSnap` liest sie für die aktive Ebene mit.
import type { Vec2 } from "../model/types";
import type { Primitive } from "../plan/generatePlan";
export type SnapSeg = [Vec2, Vec2];
const byLevel = new Map<string, SnapSeg[]>();
/** Strecken der Ebene `levelId` setzen (leeres Array/`null` = entfernen). */
export function setSheetSnapSegments(levelId: string, segs: SnapSeg[] | null): void {
if (!segs || segs.length === 0) byLevel.delete(levelId);
else byLevel.set(levelId, segs);
}
/** Strecken der Ebene `levelId` (leer, wenn keine abgeleitete Ansicht). */
export function sheetSnapSegments(levelId: string): readonly SnapSeg[] {
return byLevel.get(levelId) ?? [];
}
const KEY_EPS = 1e-6;
const keyOf = (a: Vec2, b: Vec2): string => {
const r = (v: number) => Math.round(v / KEY_EPS);
const ka = `${r(a.x)},${r(a.y)}`;
const kb = `${r(b.x)},${r(b.y)}`;
return ka < kb ? `${ka}|${kb}` : `${kb}|${ka}`;
};
/**
* Fangstrecken aus Plan-Primitiven: Polygon-Kanten + Linien (ohne
* Schraffur-Musterlinien, die gar nicht als Primitive existieren). Doppelte
* Kanten (benachbarte Schicht-Bänder teilen ihre Fugen) fallen weg.
*/
export function snapSegmentsFromPrimitives(prims: readonly Primitive[]): SnapSeg[] {
const out: SnapSeg[] = [];
const seen = new Set<string>();
const push = (a: Vec2, b: Vec2) => {
if (Math.abs(a.x - b.x) < KEY_EPS && Math.abs(a.y - b.y) < KEY_EPS) return;
const k = keyOf(a, b);
if (seen.has(k)) return;
seen.add(k);
out.push([a, b]);
};
for (const p of prims) {
if (p.kind === "polygon") {
const n = p.pts.length;
for (let i = 0; i < n; i++) push(p.pts[i], p.pts[(i + 1) % n]);
} else if (p.kind === "line") {
push(p.a, p.b);
}
}
return out;
}
+18
View File
@@ -16,6 +16,7 @@ import { stairOutline } from "../geometry/stair";
import type { SnapKind, SnapResult, SnapSettings } from "./types";
import { sampleBezierChain, sampleCatmullRom, sampleUniformBSpline } from "./curves";
import { buildDrawingIndex, drawingsNear, isIndexable, pointSegDist, type DrawingIndex } from "../geometry/drawingIndex";
import { sheetSnapSegments } from "./sheetSnapGeometry";
const dist = (a: Vec2, b: Vec2): number => Math.hypot(a.x - b.x, a.y - b.y);
const mid = (a: Vec2, b: Vec2): Vec2 => ({ x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 });
@@ -410,6 +411,23 @@ export function computeSnap(input: SnapInput): SnapResult | null {
segs = collectSegments(input);
intSegs = segs;
}
// Abgeleitete Blatt-Geometrie (Schnitt/Ansicht, s. sheetSnapGeometry.ts):
// nur die Strecken in Cursornähe — eine Ansicht hat schnell Tausende Kanten,
// der paarweise Schnittpunkt-Fang bliebe sonst nicht flüssig.
const sheet = sheetSnapSegments(input.levelId);
if (sheet.length > 0) {
const near = sheet
.map((seg) => ({ seg, d: pointSegDist(raw, seg[0], seg[1]) }))
.filter((e) => e.d <= intRadius)
.sort((x, y) => x.d - y.d)
.slice(0, 64)
.map((e) => e.seg);
if (near.length > 0) {
const shared = intSegs === segs;
segs = segs.concat(near);
intSegs = shared ? segs : intSegs.concat(near);
}
}
}
// Teilpunkt-Verweilerkennung: braucht dieselben Strecken wie oben. Ohne sie
+134 -39
View File
@@ -6,7 +6,7 @@
// Extrahiert aus App.tsx (top-level, alles über Props — keine App-Closure).
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
import { useCallback, useEffect, useMemo, useState } from "react";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { t } from "../i18n";
import type {
@@ -22,11 +22,14 @@ import type {
import { categoryNameForPick } from "../plan/pickLabels";
import type { PickKind } from "../plan/PlanView";
import { generatePlan, generateSectionPlan, generateVisibleLevelsPlan } from "../plan/generatePlan";
import type { CategoryDisplayResolver, Primitive } from "../plan/generatePlan";
import type { CategoryDisplayResolver, Plan, Primitive } from "../plan/generatePlan";
import type { RichTextDoc } from "../text/richText";
import { computeSection } from "../plan/toSection";
import { computeSection, sameSectionInputs, sameSectionLine } from "../plan/toSection";
import type { SectionOutput } from "../plan/toSection";
import { generateElevationPlan } from "../plan/toElevation";
import { crossKindOverlayAllowed, planUnderlayPrimitives } from "../plan/planUnderlay";
import { sectionOpeningPrimitives } from "../plan/sectionOpenings";
import { setSheetSnapSegments, snapSegmentsFromPrimitives } from "../tools/sheetSnapGeometry";
import { pushNativeScene, pushNativeWalls } from "../plan/nativeSync";
import { selectionHighlightLines } from "../plan/toWalls3d";
import { applyGroupDimmingToPlan } from "../state/groupActions";
@@ -318,7 +321,6 @@ export function Content({
level={level}
visibleCodes={visibleCodes}
categoryDisplay={categoryDisplay}
floorDisplay={floorDisplay}
detail={detail}
referenceLines={referenceLines}
scaleDenominator={scaleDenominator}
@@ -606,7 +608,10 @@ function useCrossKindOverlay(
const overlayLevels = useMemo(
() =>
project.drawingLevels.filter(
(l) => l.kind !== activeLevel.kind && floorDisplay(l.id).render,
(l) =>
l.kind !== activeLevel.kind &&
crossKindOverlayAllowed(activeLevel.kind, l.kind) &&
floorDisplay(l.id).render,
),
[project.drawingLevels, activeLevel.kind, floorDisplay],
);
@@ -935,6 +940,16 @@ function LevelPlanView({
);
}
/**
* Geschnittene Fenster/Türen in den Schnitt-Plan einsetzen: nach den Cut-
* Polygonen (liegen in deren Aussparung), vor den Ansichtskanten — die Reihen-
* folge spielt kaum eine Rolle, da sie sich nicht überdecken.
*/
function withSectionOpenings(plan: Plan, openings: Primitive[]): Plan {
if (openings.length === 0) return plan;
return { ...plan, primitives: [...plan.primitives, ...openings] };
}
/**
* Schnitt-/Ansichts-Ebene: der render3d-Schnitt-Extraktor (WASM, plan/toSection)
* durchschneidet das Modell entlang der Schnittlinie der Ebene und übersetzt das
@@ -950,7 +965,6 @@ function SectionPlanView({
level,
visibleCodes,
categoryDisplay,
floorDisplay,
detail,
referenceLines,
scaleDenominator,
@@ -1005,7 +1019,6 @@ function SectionPlanView({
level: DrawingLevel;
visibleCodes: Set<string>;
categoryDisplay: CategoryDisplayResolver;
floorDisplay: CategoryDisplayResolver;
detail: DetailLevel;
referenceLines: boolean;
/** Papier-Massstab (1:N) — nur für Bemassungs-Feinheiten in Papier-mm. */
@@ -1066,14 +1079,37 @@ function SectionPlanView({
"loading",
);
// Stabile Eingaben der Projektion: nur ein neues Objekt, wenn sich etwas
// Schnitt-Relevantes geändert hat (nicht bei jeder 2D-Linie im Schnitt, s.
// sameSectionInputs). Spart das Neurechnen UND verhindert, dass die Ansicht
// bei jeder Änderung kurz leer wird.
const inputsRef = useRef<{ project: Project; level: DrawingLevel } | null>(null);
const prevInputs = inputsRef.current;
const inputs =
prevInputs &&
sameSectionInputs(prevInputs.project, project) &&
sameSectionLine(prevInputs.level, level)
? prevInputs
: { project, level };
useEffect(() => {
inputsRef.current = inputs;
});
// Ebenenwechsel: alten Schnitt verwerfen (gehört zu einer anderen Linie).
useEffect(() => {
setOutput(null);
setStatus("loading");
}, [level.id]);
useEffect(() => {
if (isElevation) return; // Ansicht: kein WASM-Schnitt (synchroner Generator).
let disposed = false;
setStatus("loading");
setOutput(null);
// Bisheriges Ergebnis stehen lassen, bis das neue fertig ist — sonst
// flackert die Ansicht auf "wird berechnet …" und die PlanView (Zoom/
// Ausschnitt) wird bei jeder Änderung neu aufgebaut.
void (async () => {
try {
const out = await computeSection(project, level);
const out = await computeSection(inputs.project, inputs.level);
if (disposed) return;
if (!out) {
setStatus("empty");
@@ -1089,52 +1125,111 @@ function SectionPlanView({
return () => {
disposed = true;
};
}, [project, level, isElevation]);
}, [inputs, isElevation]);
// Ansichts-Plan: gefüllte Fassadenansicht inkl. optionalem Schatten
// (level.shadows). Liefert null, wenn die Ebene keine Ansichtslinie trägt.
const elevationPlan = useMemo(
() =>
isElevation
? generateElevationPlan(project, level, { mono, visibleCodes, categoryDisplay })
? generateElevationPlan(inputs.project, inputs.level, { mono, visibleCodes, categoryDisplay })
: null,
[isElevation, project, level, mono, visibleCodes, categoryDisplay],
[isElevation, inputs, mono, visibleCodes, categoryDisplay],
);
const sectionPlan = useMemo(
() =>
!isElevation && output
? generateSectionPlan(output, mono, {
hiddenLines: level.hiddenLines,
visibleCodes,
categoryDisplay,
})
? withSectionOpenings(
generateSectionPlan(output, mono, {
hiddenLines: level.hiddenLines,
visibleCodes,
categoryDisplay,
}),
sectionOpeningPrimitives(inputs.project, inputs.level, visibleCodes, categoryDisplay),
)
: null,
[isElevation, output, mono, level.hiddenLines, visibleCodes, categoryDisplay],
[isElevation, output, mono, level.hiddenLines, visibleCodes, categoryDisplay, inputs],
);
const rawPlan = isElevation ? elevationPlan : sectionPlan;
// Fremd-Art-Referenz-Unterlage (Nutzer-Wunsch: "in der Ansicht auch mal
// einen Grundriss zeigen können") — dieselbe Überlagerung wie im Grundriss/
// 2D-Arbeitsblatt, nur umgekehrt: hier ist Schnitt/Ansicht die aktive Ebene,
// andere Geschosse/Zeichnungen/Schnitte/Ansichten erscheinen als Unterlage.
const overlayPrimitives = useCrossKindOverlay(
project,
level,
floorDisplay,
visibleCodes,
categoryDisplay,
detail,
referenceLines,
mono,
scaleDenominator,
// Grundriss-Unterlage (Nutzer-Wunsch: "in der Ansicht auch mal einen
// Grundriss zeigen können"): das in `level.planUnderlayId` gewählte Geschoss
// AUSGERICHTET unter dem Schnitt/der Ansicht (s. plan/planUnderlay.ts) —
// nicht mehr jede sichtbare Ebene lose übereinander (die lag in einem
// fremden Koordinatenraum und verdeckte den Schnitt).
const underlayFloor = project.drawingLevels.find(
(l) => l.id === level.planUnderlayId && l.kind === "floor",
);
const withOverlay = useMemo(
const sectionMinY = rawPlan?.bounds.minY;
const overlayPrimitives = useMemo(() => {
if (!underlayFloor || sectionMinY === undefined) return [];
const floorPlan = generatePlan(
project,
underlayFloor.id,
visibleCodes,
categoryDisplay,
detail,
referenceLines,
mono,
false,
scaleDenominator,
);
return planUnderlayPrimitives(level, floorPlan.primitives, sectionMinY).map(stripSelectableIds);
}, [underlayFloor, sectionMinY, project, level, visibleCodes, categoryDisplay, detail, referenceLines, mono, scaleDenominator]);
// Eigene 2D-Elemente des Schnitts/der Ansicht (Bemassung, Höhenkoten,
// Beschriftung, Ergänzungslinien …): liegen in `drawings2d` mit
// `levelId === level.id` im Blatt-Raum (u, Höhe). Bisher zeichnete die Ansicht
// NUR die abgeleitete Projektion — was man im Schnitt zeichnete, wurde zwar
// gespeichert, blieb aber unsichtbar.
const sheetDrawings = useMemo(
() =>
rawPlan && overlayPrimitives.length > 0
? { ...rawPlan, primitives: [...rawPlan.primitives, ...overlayPrimitives] }
: rawPlan,
[rawPlan, overlayPrimitives],
generatePlan(
project,
level.id,
visibleCodes,
categoryDisplay,
detail,
referenceLines,
mono,
false,
scaleDenominator,
),
[project, level.id, visibleCodes, categoryDisplay, detail, referenceLines, mono, scaleDenominator],
);
const withOverlay = useMemo(() => {
if (!rawPlan) return rawPlan;
const extra = sheetDrawings.primitives;
if (overlayPrimitives.length === 0 && extra.length === 0) return rawPlan;
const b = { ...rawPlan.bounds };
const grow = (x: number, y: number) => {
if (x < b.minX) b.minX = x;
if (y < b.minY) b.minY = y;
if (x > b.maxX) b.maxX = x;
if (y > b.maxY) b.maxY = y;
};
for (const pr of overlayPrimitives) {
if (pr.kind === "polygon") for (const p of pr.pts) grow(p.x, p.y);
else if (pr.kind === "line") { grow(pr.a.x, pr.a.y); grow(pr.b.x, pr.b.y); }
}
if (extra.length > 0) {
const eb = sheetDrawings.bounds;
grow(eb.minX, eb.minY);
grow(eb.maxX, eb.maxY);
}
// Unterlage zuunterst, Blatt-Zeichnungen obenauf.
return { ...rawPlan, primitives: [...overlayPrimitives, ...rawPlan.primitives, ...extra], bounds: b };
}, [rawPlan, overlayPrimitives, sheetDrawings]);
// Fangkanten der abgeleiteten Geometrie (Schnitt-/Ansichtskanten + Unterlage)
// für `computeSnap` bereitstellen — die stehen nicht im Projekt. Die eigenen
// 2D-Elemente fängt computeSnap ohnehin über `drawings2d`.
useEffect(() => {
if (!rawPlan) return;
setSheetSnapSegments(
level.id,
snapSegmentsFromPrimitives([...overlayPrimitives, ...rawPlan.primitives]),
);
return () => setSheetSnapSegments(level.id, null);
}, [rawPlan, overlayPrimitives, level.id]);
// Gruppen-Isolation ("Gruppe betreten") gilt auch für Schnitt-/Ansichts-
// Pläne, s. state/groupActions.ts::applyGroupDimming.
const plan = useMemo(
@@ -1165,7 +1260,7 @@ function SectionPlanView({
return (
<section className="pane">
<div className="pane-title">
<div className="pane-title pane-title--ruled">
{t("content.sectionTitle", { name: level.name, kind: kindLabel })}
</div>
{groupPath.length > 0 && (