Schnittführungs-Symbol im Grundriss + Schnittlinien-Auswahl

generatePlan zeichnet fuer jede Schnitt-/Ansichtsebene mit linePoints das
klassische Symbol: Strichpunkt-Linie, Endmarken + Richtungspfeile (directionSign),
Kurz-Label an beiden Enden und ein unsichtbares Pick-Band (Polygon mit
sectionLineId). PlanView pickt die Linie (hoechste Prioritaet) und hebt die
Auswahl hervor. Neuer Selektionskanal selectedSectionLineId (Einzel-DrawingLevel-
Id) in selectionSlice; onPlanSelect + alle Reset-Stellen in App gepflegt.
Primitive.sectionLineId, PlanSelection.sectionLineId, Tests.
This commit is contained in:
2026-07-11 00:21:29 +02:00
parent 69b5cf5783
commit 033c876414
5 changed files with 364 additions and 1 deletions
+75
View File
@@ -197,6 +197,12 @@ export interface PlanSelection {
* Element höherer Priorität (alle anderen gehen vor); sonst `null`.
*/
roofId: string | null;
/**
* ID der getroffenen Schnitt-/Ansichtslinie (DrawingLevel), wenn der Klick ihr
* dünnes Pick-Band traf; sonst `null`. Höchste Priorität (das schmale Band liegt
* über allem — ein Klick genau darauf meint die Linie).
*/
sectionLineId: string | null;
/**
* War beim Klick Shift gedrückt? Dann ERWEITERT der Aufrufer (App) die
* Auswahl um das getroffene Element (bzw. schaltet es ab/zu), statt sie zu
@@ -287,6 +293,11 @@ export interface PlanViewProps {
selectedRoomIds?: string[];
/** Aktuell ausgewählte Dach-IDs (von App); die Ansicht markiert die Traufe. */
selectedRoofIds?: string[];
/**
* Aktuell ausgewählte Schnitt-/Ansichtslinien-IDs (DrawingLevel; von App). Die
* Ansicht markiert das Pick-Band JEDER dieser Linien mit einer Akzentkontur.
*/
selectedSectionLineIds?: string[];
/**
* Aktuell ausgewählte IDs extrudierter Körper (truck-Integration; kontrolliert
* von App). Die Ansicht markiert den Footprint-Umriss JEDES dieser Körper mit
@@ -416,6 +427,7 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
selectedStairIds,
selectedRoomIds,
selectedRoofIds,
selectedSectionLineIds,
selectedExtrudedSolidIds,
selectedColumnIds,
roomStamp,
@@ -1007,6 +1019,20 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
return null;
};
// Getroffene Schnitt-/Ansichtslinie: ihr schmales, unsichtbares Pick-Band
// (Polygon mit sectionLineId) per Punkt-in-Polygon.
const pickSectionLine = (clientX: number, clientY: number): string | null => {
const v = clientToView(clientX, clientY, view);
const m = viewToModel(v.x, v.y);
for (let i = plan.primitives.length - 1; i >= 0; i--) {
const p = plan.primitives[i];
if (p.kind === "polygon" && p.sectionLineId && pointInPolygon(m, p.pts)) {
return p.sectionLineId;
}
}
return null;
};
// Getroffener extrudierter Körper (truck-Integration): der Footprint-Umriss
// ist ein reiner Haarlinien-Umriss (fill:"none"), aber per Punkt-in-Polygon
// trotzdem als FLÄCHE anklickbar (analog Raum, nicht nur auf der Linie).
@@ -1518,6 +1544,28 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
const hit = hitIndex !== null ? plan.primitives[hitIndex] : undefined;
// Öffnung (Fenster/Tür) zuerst: ihr Symbol sitzt in der ausgesparten Lücke
// bzw. schlägt über die Wand — ein Klick nahe am Symbol wählt die Öffnung.
// Schnitt-/Ansichtslinie zuerst: ihr schmales Band liegt über allem, ein
// Klick genau darauf meint die Linie (nicht die darunterliegende Wand) —
// dann sofort melden (kein anderes Element konkurriert).
const sectionLineId = pickSectionLine(e.clientX, e.clientY);
if (sectionLineId) {
onSelect({
model: viewToModel(v.x, v.y),
hitIndex,
wallId: null,
drawingId: null,
ceilingId: null,
openingId: null,
stairId: null,
roomId: null,
extrudedSolidId: null,
columnId: null,
roofId: null,
sectionLineId,
shift: e.shiftKey,
});
return;
}
const openingId = pickOpening(e.clientX, e.clientY);
const wallId =
openingId ? null : hit && hit.kind === "polygon" ? hit.wallId ?? null : null;
@@ -1581,6 +1629,7 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
extrudedSolidId,
columnId,
roofId,
sectionLineId: null,
shift: e.shiftKey,
});
}
@@ -1780,6 +1829,20 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
);
}, [plan, selectedRoofIds]);
// Hervorhebung der selektierten Schnitt-/Ansichtslinie: das (unsichtbare)
// Pick-Band (Polygon mit sectionLineId) mit Akzentkontur überzeichnen.
const highlightSectionLinePolys = useMemo(() => {
const ids =
selectedSectionLineIds && selectedSectionLineIds.length
? new Set(selectedSectionLineIds)
: null;
if (!ids) return [];
return plan.primitives.filter(
(p): p is Extract<Primitive, { kind: "polygon" }> =>
p.kind === "polygon" && p.sectionLineId != null && ids.has(p.sectionLineId),
);
}, [plan, selectedSectionLineIds]);
// Hervorhebung der selektierten extrudierten Körper (truck-Integration): der
// Footprint-Umriss (Polygon mit extrudedSolidId) mit Akzentkontur überzeichnen
// — analog zur Raum-Auswahl.
@@ -2024,6 +2087,18 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
pointerEvents="none"
/>
))}
{/* Auswahl-Hervorhebung der gewählten Schnitt-/Ansichtslinie (Pick-Band). */}
{highlightSectionLinePolys.map((poly, i) => (
<polygon
key={`selsl-${i}`}
className="plan-selected"
points={poly.pts
.map(toScreen)
.map((s) => `${s.x},${s.y}`)
.join(" ")}
pointerEvents="none"
/>
))}
{/* Auswahl-Hervorhebung der gewählten extrudierten Körper (truck-Integration). */}
{highlightExtrudedSolidPolys.map((poly, i) => (
<polygon
+98
View File
@@ -0,0 +1,98 @@
/**
* Schnittführungs-Symbol im Grundriss (generatePlan → addSectionLines): jede
* Schnitt-/Ansichtsebene MIT `linePoints` erzeugt eine Strichpunkt-Linie
* (cls "section-line"), Endmarken + ein unsichtbares Pick-Band (Polygon mit
* `sectionLineId`). Ebenen OHNE Linie erzeugen nichts.
*/
import { describe, it, expect } from "vitest";
import { generatePlan } from "./generatePlan";
import type { DrawingLevel, Project } from "../model/types";
const visible = new Set(["20", "35"]);
function baseProject(levels: DrawingLevel[]): Project {
return {
id: "t",
name: "T",
lineStyles: [],
hatches: [],
components: [],
wallTypes: [],
drawingLevels: levels,
layers: [{ code: "20", name: "Wände", color: "#333", lw: 0.18, visible: true, locked: false }],
walls: [],
doors: [],
openings: [],
ceilings: [],
stairs: [],
rooms: [],
drawings2d: [],
context: [],
} as unknown as Project;
}
const floor: DrawingLevel = {
id: "eg",
name: "EG",
kind: "floor",
visible: true,
locked: false,
floorHeight: 2.6,
cutHeight: 1.0,
baseElevation: 0,
};
describe("generatePlan — Schnittführungs-Symbol", () => {
it("zeichnet Linie + Pick-Band für eine Schnittebene mit linePoints", () => {
const p = baseProject([
floor,
{
id: "s-a",
name: "Schnitt A",
kind: "section",
visible: true,
locked: false,
linePoints: [{ x: 0, y: 2 }, { x: 6, y: 2 }],
directionSign: 1,
},
]);
const prims = generatePlan(p, "eg", visible).primitives;
// Strichpunkt-Hauptlinie vorhanden.
const lines = prims.filter((pr) => pr.kind === "line" && pr.cls === "section-line");
expect(lines.length).toBeGreaterThan(0);
// Pick-Band trägt die Level-Id.
const band = prims.find((pr) => pr.kind === "polygon" && pr.sectionLineId === "s-a");
expect(band).toBeTruthy();
// Label-Text (Kurz-Tag „A") an den Enden.
const labels = prims.filter((pr) => pr.kind === "drawingText" && pr.text === "A");
expect(labels.length).toBe(2);
});
it("zeichnet NICHTS für eine Schnittebene ohne linePoints", () => {
const p = baseProject([
floor,
{ id: "s-b", name: "Schnitt B", kind: "section", visible: true, locked: false },
]);
const prims = generatePlan(p, "eg", visible).primitives;
expect(prims.some((pr) => pr.kind === "polygon" && pr.sectionLineId != null)).toBe(false);
expect(prims.some((pr) => pr.kind === "line" && pr.cls === "section-line")).toBe(false);
});
it("behandelt Ansichtsebenen (elevation) gleich", () => {
const p = baseProject([
floor,
{
id: "e-a",
name: "Ansicht Süd",
kind: "elevation",
visible: true,
locked: false,
linePoints: [{ x: 0, y: 0 }, { x: 4, y: 0 }],
directionSign: -1,
},
]);
const prims = generatePlan(p, "eg", visible).primitives;
expect(prims.some((pr) => pr.kind === "polygon" && pr.sectionLineId === "e-a")).toBe(true);
});
});
+143
View File
@@ -265,6 +265,12 @@ export type Primitive =
columnId?: string;
/** ID des Dachs (Roof), falls dieses (unsichtbare) Polygon der Traufe-Umriss ist (Auswahl). */
roofId?: string;
/**
* ID der Schnitt-/Ansichtslinie (DrawingLevel), falls dieses (unsichtbare)
* Pick-Band das Schnittführungs-Symbol umhüllt (für die Links-Klick-Auswahl
* der Schnittlinie im Grundriss).
*/
sectionLineId?: string;
}
| {
kind: "line";
@@ -892,6 +898,10 @@ export function generatePlan(
// die Reihenfolge unkritisch; wir hängen sie als Referenz an.
addContextContours(primitives, project);
// Schnittführungs-Symbole (klassische Schnittlinien) aller Schnitt-/Ansichts-
// ebenen mit gesetzter Linie — projektglobale Referenzgeometrie über dem Plan.
addSectionLines(primitives, project);
// Schwarz-Weiss (mono): nachträglich alle Farben auf reine Tinte zwingen.
// Element-/Kategorie-/Hatch-Farben werden ignoriert, Füllungen werden weiss,
// Musterlinien/Striche schwarz — so entsteht ein reiner S/W-Plan.
@@ -2641,6 +2651,139 @@ function addRoof(
}
}
// ── Schnittführungs-Symbol (klassische Schnittlinie im Grundriss) ───────────
/** Tinte der Schnittführungs-Linie/Marken (kräftiges Grau). */
const SECTION_LINE_INK = "#1f242c";
/** Haarlinie der Strichpunkt-Schnittlinie (mm Papier). */
const SECTION_LINE_MM = 0.18;
/** Kräftige Endmarken (Querstrich + Pfeil) (mm Papier). */
const SECTION_LINE_MARK_MM = 0.5;
/** Strichpunkt-Muster der Schnittlinie (lange Striche + Punkt, mm Papier). */
const SECTION_LINE_DASH: number[] = [6, 1.5, 0.4, 1.5];
/** Länge der Endmarken (Querstrich/Pfeil) in Modell-Metern. */
const SECTION_MARK_LEN = 0.6;
/** Halbe Breite des unsichtbaren Pick-Bands über der Linie (Modell-Meter). */
const SECTION_PICK_HALF = 0.3;
/** Schrifthöhe des Schnitt-Labels (Modell-Meter). */
const SECTION_LABEL_H = 0.5;
/**
* Kurz-Tag eines Schnitt-Labels: der letzte „Wort"-Teil des Ebenennamens (z. B.
* „Schnitt A" → „A"); enthält der Name kein Leerzeichen, der ganze Name. Klassisch
* wird der Schnitt an beiden Enden mit diesem Tag beschriftet (A–A).
*/
function sectionLabelTag(name: string): string {
const parts = name.trim().split(/\s+/);
return parts.length > 1 ? parts[parts.length - 1] : name.trim();
}
/**
* Zeichnet für jede Schnitt-/Ansichtsebene MIT gesetzter `linePoints` das
* klassische Schnittführungs-Symbol in den Grundriss: eine Strichpunkt-Haarlinie
* über die volle Länge, an beiden Enden einen kräftigen Querstrich + Richtungspfeil
* auf der Blickseite (`directionSign`) und das Schnitt-Label (Kurz-Tag) daneben.
* Zusätzlich ein unsichtbares Pick-Band (Polygon mit `sectionLineId`), damit die
* Linie im Grundriss anklickbar ist (analog dem Dach-Traufe-Pick-Polygon).
*/
function addSectionLines(out: Primitive[], project: Project): void {
for (const level of project.drawingLevels) {
if (level.kind !== "section" && level.kind !== "elevation") continue;
const line = level.linePoints;
if (!line) continue;
const [p0, p1] = line;
const axis = sub(p1, p0);
const len = Math.hypot(axis.x, axis.y);
if (len < 1e-6) continue;
const u = normalize(axis);
const n = leftNormal(u); // (-uy, ux)
const sign = level.directionSign ?? 1;
const bn = { x: n.x * sign, y: n.y * sign }; // Blicknormale
// Hauptlinie (Strichpunkt-Haarlinie).
out.push({
kind: "line",
a: p0,
b: p1,
cls: "section-line",
weightMm: SECTION_LINE_MM,
dash: SECTION_LINE_DASH,
color: SECTION_LINE_INK,
});
// Endmarken (Querstrich + Richtungspfeil + Label) an beiden Enden.
const half = SECTION_MARK_LEN / 2;
for (const end of [p0, p1]) {
// Querstrich senkrecht zur Linie, mittig am Endpunkt.
const t0 = { x: end.x - n.x * half, y: end.y - n.y * half };
const t1 = { x: end.x + n.x * half, y: end.y + n.y * half };
out.push({
kind: "line",
a: t0,
b: t1,
cls: "section-line",
weightMm: SECTION_LINE_MARK_MM,
color: SECTION_LINE_INK,
});
// Richtungspfeil: vom Querstrich-Ende auf der Blickseite entlang bn.
const base = { x: end.x + bn.x * half, y: end.y + bn.y * half };
const tip = { x: base.x + bn.x * SECTION_MARK_LEN, y: base.y + bn.y * SECTION_MARK_LEN };
const wingBack = {
x: tip.x - bn.x * SECTION_MARK_LEN * 0.4,
y: tip.y - bn.y * SECTION_MARK_LEN * 0.4,
};
const w = SECTION_MARK_LEN * 0.25;
out.push({ kind: "line", a: base, b: tip, cls: "section-line", weightMm: SECTION_LINE_MARK_MM, color: SECTION_LINE_INK });
out.push({
kind: "line",
a: tip,
b: { x: wingBack.x + u.x * w, y: wingBack.y + u.y * w },
cls: "section-line",
weightMm: SECTION_LINE_MARK_MM,
color: SECTION_LINE_INK,
});
out.push({
kind: "line",
a: tip,
b: { x: wingBack.x - u.x * w, y: wingBack.y - u.y * w },
cls: "section-line",
weightMm: SECTION_LINE_MARK_MM,
color: SECTION_LINE_INK,
});
// Label (Kurz-Tag) etwas hinter dem Pfeil, horizontal.
const labelAt = {
x: tip.x + bn.x * SECTION_MARK_LEN * 0.4 - SECTION_LABEL_H * 0.3,
y: tip.y + bn.y * SECTION_MARK_LEN * 0.4 + SECTION_LABEL_H * 0.5,
};
out.push({
kind: "drawingText",
at: labelAt,
text: sectionLabelTag(level.name),
heightM: SECTION_LABEL_H,
angle: 0,
color: SECTION_LINE_INK,
});
}
// Unsichtbares Pick-Band (Rechteck entlang der Linie) — klickbar per
// Punkt-in-Polygon in PlanView, trägt die DrawingLevel-Id.
const off = { x: n.x * SECTION_PICK_HALF, y: n.y * SECTION_PICK_HALF };
out.push({
kind: "polygon",
pts: [
{ x: p0.x + off.x, y: p0.y + off.y },
{ x: p1.x + off.x, y: p1.y + off.y },
{ x: p1.x - off.x, y: p1.y - off.y },
{ x: p0.x - off.x, y: p0.y - off.y },
],
fill: "none",
stroke: "none",
strokeWidthMm: 0,
hatch: NO_HATCH,
sectionLineId: level.id,
});
}
}
/**
* Deckkraft (0..255) der Raum-Füllung → 2-stelliges Hex-Suffix. Transluzente
* Farbfüllung entfällt — Plandarstellung schwarz/grau; Farbe bleibt späteren