[K4] Objekt-Info im Kern: deriveSelection rechnet selection_info.rs

Die Objekt-Info der Auswahl (effektive Attribute, bbox, Wand/Decke/Dach/Öffnung/Treppe/Raum/
Extrusion/Stütze/Kontext/Detailverweis) ist die Wurzel-Abfrage selectionInfo; state/selectionInfo.ts
hält Kontrakt und Fassade (B-Rep-Beschreibung der Extrusion aus TS). geomBBox ist gelöscht,
Ausrichten/Verteilen fragt drawingBBoxes. Schneller in Griffen und Objekt-Info: Felder kleiner
Objekte linear statt über den Map-Hash, Griff-Anfrage typisiert, Antworten direkt als Text,
js_fmt::to_fixed mit Schnellweg. Gleichheit über 174 360 Auswahlen und 24 000 Ausricht-Fälle
(einmaliger Test, gelöscht); TODO.md nachgeführt.

Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
Claude committed 2026-10-29 09:56:24 +00:00
1 parent bf743a3235
commit 365500516f
11 files changed
+1705 -958

No files matched your search

+63
View File
@@ -0,0 +1,63 @@
// Objekt-Info der Auswahl ([K4] S3: gerechnet im Kern, `selection_info.rs`) — Wand, Decke,
// Zeichnung, Extrusion (B-Rep-Beschreibung aus TS) und die Meldung bei unbekanntem Wandtyp.
import { describe, expect, it } from "vitest";
import { deriveSelection } from "./selectionInfo";
import { sampleProject } from "../model/sampleProject";
import type { Project } from "../model/types";
const base = (): Project => structuredClone(sampleProject);
describe("deriveSelection (Kern)", () => {
it("Wand: Typ-Liste, Geschosse, Länge, Volumen und UK/OK", () => {
const p = base();
const w = p.walls[0];
const sel = deriveSelection(p, [w.id], null)!;
expect(sel.kind).toBe("wall");
expect(sel.id).toBe(w.id);
expect(sel.wall!.wallTypes.length).toBe(p.wallTypes.length);
expect(sel.wall!.floors.every((f) => p.drawingLevels.some((z) => z.id === f.id && z.kind === "floor"))).toBe(true);
expect(sel.wall!.length).toBeCloseTo(Math.hypot(w.end.x - w.start.x, w.end.y - w.start.y), 12);
expect(sel.wall!.netVolume).toBeLessThanOrEqual(sel.wall!.grossVolume);
expect(sel.wall!.zTop).toBeGreaterThan(sel.wall!.zBottom);
expect(sel.bbox.minX).toBe(Math.min(w.start.x, w.end.x));
});
it("unbekannter Wandtyp bricht mit derselben Meldung ab wie bisher", () => {
const p = base();
p.walls[0] = { ...p.walls[0], wallTypeId: "fehlt" };
expect(() => deriveSelection(p, [p.walls[0].id], null)).toThrow("Unbekannter Wandtyp: fehlt");
});
it("Zeichnung: offene Linie ohne Füllung, Rechteck mit Ebenen-Vorgaben", () => {
const p = base();
const lvl = p.drawingLevels[0].id;
const code = p.layers[0].code;
p.drawings2d = [
{ id: "l", type: "drawing2d", levelId: lvl, categoryCode: code, geom: { shape: "line", a: { x: 0, y: 0 }, b: { x: 3, y: -2 } } },
{ id: "r", type: "drawing2d", levelId: lvl, categoryCode: code, hatchId: "h", geom: { shape: "rect", min: { x: 1, y: 1 }, max: { x: 2, y: 4 } } },
];
const l = deriveSelection(p, [], "l")!;
expect(l.closed).toBe(false);
expect(l.effectiveHatchId).toBeNull();
expect(l.bbox).toEqual({ minX: 0, minY: -2, maxX: 3, maxY: 0 });
const r = deriveSelection(p, [], "r")!;
expect(r.closed).toBe(true);
expect(r.fillHatchId).toBe("h");
expect(r.effectiveHatchId).toBe("h");
expect(deriveSelection(p, [], "nix")).toBeNull();
});
it("Extrusion: Fläche im Kern, B-Rep-Beschreibung (truck) aus TS", () => {
const p = base();
const lvl = p.drawingLevels[0].id;
p.extrudedSolids = [
{ id: "x", type: "extrudedSolid", levelId: lvl, points: [{ x: 0, y: 0 }, { x: 2, y: 0 }, { x: 2, y: 3 }], height: 2 },
];
const sel = deriveSelection(p, [], null, null, null, null, null, "x")!;
expect(sel.extrudedSolid!.area).toBeCloseTo(3, 12);
expect(sel.extrudedSolid!.spec).toMatchObject({ kind: "extrude", height: 2 });
expect(Object.keys(sel.extrudedSolid!)).toEqual([
"height", "taper", "cornerRadius", "chamfer", "area", "spec", "subtract", "canSubtract", "baseOffset", "floorId", "floorName",
]);
});
});
+53 -817
View File
@@ -8,59 +8,30 @@
// Übersteuerung am Element → LineStyle → Kategorie-Default. So zeigt die Palette
// den TATSÄCHLICH gezeichneten Wert, nicht nur das (oft leere) Override-Feld.
//
// [K4] S3: gerechnet wird im Rust-Kern (`src-tauri/core/src/selection_info.rs`, Wurzel-Abfrage
// `selectionInfo` auf dem Projekt-Dokument); hier stehen der Kontrakt (Typen) und die Fassade. Der
// B-Rep-Körper einer Extrusion (`spec`) kommt aus TS (`extrudedSolidSpec`, truck-Pipeline).
//
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
import { extrudedSolidSpec } from "../core";
import type { SolidSpec } from "../engine/truckSolid";
import {
ceilingThickness,
getCeilingType,
getComponent,
getWallType,
wallTypeLabel,
wallTypeThickness,
} from "../model/types";
import { documentFor } from "../core/document";
import type {
AttributeSource,
Ceiling,
Column,
ColumnProfile,
ContextImage,
ContextObject,
Drawing2D,
Drawing2DGeom,
ExtrudedSolid,
Opening,
Project,
Roof,
RoofShape,
Room,
SiaCategory,
SliceTermination,
Stair,
StairShape,
VerticalAnchor,
Wall,
WallReferenceLine,
} from "../model/types";
import { findCategory } from "../model/layers";
import type { DetailLevel } from "../model/viewTypes";
import { localToLv95 } from "../io/lv95";
import { resolveForeground, resolveBackground, resolveHatchId, resolveStrokeWeight } from "../core";
import { columnVerticalExtent } from "../model/wall";
import { columnFootprint } from "../core";
import { evaluateRoom, polygonArea } from "../core";
import {
ceilingVerticalExtent,
nextFloorAbove,
stairVerticalExtent,
wallVerticalExtent,
} from "../model/wall";
import { ceilingArea, outlineBBox } from "../core";
import { roofBBox, roofBaseElevation, roofEdgeList, roofGeometry } from "../core";
import type { RoofEdge } from "../core";
import { openingGapQuad, openingVerticalExtent } from "../core";
import { stairGeometry, stairBBox } from "../core";
/** Eintrag für die WallType-Auswahl (Preset-Dropdown) im Object-Info-Panel. */
export interface WallTypeChoice {
@@ -541,754 +512,16 @@ export interface ContextObjectInfo {
lv95Center?: { e: number; n: number };
}
const WALL_FALLBACK_MM = 0.18;
const DRAW_FALLBACK_COLOR = "#d0d0d0";
const WALL_FALLBACK_COLOR = "#2b3039";
/** Ob eine 2D-Form geschlossen ist (Füllung/Schraffur sinnvoll). */
function isClosedGeom(g: Drawing2DGeom): boolean {
return (
g.shape === "rect" ||
g.shape === "circle" ||
g.shape === "ellipse" ||
(g.shape === "polyline" && g.closed) ||
(g.shape === "spline" && g.closed)
);
}
/**
* Bounding-Box einer 2D-Form. Exportiert, weil auch die Editier-Werkzeuge sie
* brauchen (Ausrichten/Verteilen, `editors/align.ts`) — dieselbe Herleitung
* wie fürs Attribut-Panel, damit beide Seiten nie auseinanderlaufen.
*/
export function geomBBox(g: Drawing2DGeom): SelectionBBox {
let minX = Infinity,
minY = Infinity,
maxX = -Infinity,
maxY = -Infinity;
const acc = (x: number, y: number) => {
minX = Math.min(minX, x);
minY = Math.min(minY, y);
maxX = Math.max(maxX, x);
maxY = Math.max(maxY, y);
};
switch (g.shape) {
case "line":
case "xline":
case "ray":
acc(g.a.x, g.a.y);
acc(g.b.x, g.b.y);
break;
case "polyline":
for (const p of g.pts) acc(p.x, p.y);
break;
case "rect":
case "image":
acc(g.min.x, g.min.y);
acc(g.max.x, g.max.y);
break;
case "circle":
case "arc":
acc(g.center.x - g.r, g.center.y - g.r);
acc(g.center.x + g.r, g.center.y + g.r);
break;
case "ellipse": {
// Präzise Bounding-Box unter Berücksichtigung der Drehung (rotation=0
// beim heutigen Werkzeug, Feld existiert für spätere Quellen).
const c = Math.cos(g.rotation), s = Math.sin(g.rotation);
const hw = Math.hypot(g.rx * c, g.ry * s);
const hh = Math.hypot(g.rx * s, g.ry * c);
acc(g.center.x - hw, g.center.y - hh);
acc(g.center.x + hw, g.center.y + hh);
break;
}
case "bezier":
case "spline":
for (const p of g.pts) acc(p.x, p.y);
break;
case "dimension": {
for (const p of g.pts) acc(p.x, p.y);
if (g.pts.length >= 2) {
const a = g.pts[0], b = g.pts[g.pts.length - 1];
const dx = b.x - a.x, dy = b.y - a.y;
const len = Math.hypot(dx, dy) || 1;
const nx = (-dy / len) * g.offset, ny = (dx / len) * g.offset;
for (const p of g.pts) acc(p.x + nx, p.y + ny);
}
break;
}
case "kote":
case "text":
case "block":
case "detailref":
case "pointmarker":
acc(g.at.x, g.at.y);
break;
case "scalebar":
acc(g.at.x, g.at.y);
acc(g.at.x + g.segmentLength * g.segments, g.at.y);
break;
}
if (!isFinite(minX)) return { minX: 0, minY: 0, maxX: 0, maxY: 0 };
return { minX, minY, maxX, maxY };
}
/** Selektion für eine Wand ableiten (Farbe übersteuerbar, Strichstärke = Kategorie). */
function wallSelection(project: Project, wall: Wall): Selection {
const cat = findCategory(project.layers, wall.categoryCode);
const color = wall.color ?? cat?.color ?? WALL_FALLBACK_COLOR;
// Effektive Strichstärke: expliziter Override zuerst, sonst die Kategorie
// (die Quelle "layer"/"object" macht heute keinen Unterschied, da Component
// keine eigene Strichstärke trägt — siehe resolveStrokeWeight).
const weightMm = wall.strokeWeight ?? cat?.lw ?? WALL_FALLBACK_MM;
const minX = Math.min(wall.start.x, wall.end.x);
const minY = Math.min(wall.start.y, wall.end.y);
const maxX = Math.max(wall.start.x, wall.end.x);
const maxY = Math.max(wall.start.y, wall.end.y);
// Wand-Attribute auflösen (Referenzlinie, Aufbau, Referenzgeschoss, UK/OK).
const wt = getWallType(project, wall);
const thickness = wallTypeThickness(wt);
// Effektive Vordergrund-/Hintergrund-/Schraffur-Vorschau fürs Attribut-Panel
// (Nutzer-Wunsch: immer den TATSÄCHLICHEN Wert sehen, nicht nur ein leeres
// Override-Feld) — dieselbe Resolve-Kette wie beim Rendern (resolveForeground
// & Co.), als Bauteil-Repräsentant die ÄUSSERSTE Schicht (wie `abbrevOf`
// unten). Bei mehrschichtigem Aufbau nur eine Annäherung (jede Schicht kann
// im Schnitt ihre EIGENE Bauteilfarbe zeigen) — für die Panel-Vorschau
// ausreichend, der Override selbst wirkt ohnehin einheitlich auf alle Schichten.
const outerComponent = getComponent(project, wt.layers[0]?.componentId);
const effectiveForeground = outerComponent
? resolveForeground(outerComponent, wall.foreground, cat, wall.foregroundSource)
: wall.foreground;
const effectiveBackground = outerComponent
? resolveBackground(outerComponent, wall.background, cat, wall.backgroundSource)
: wall.background;
const effectiveHatchId = resolveHatchId(
wall.hatchId,
wall.hatchSource,
cat,
outerComponent?.hatchId,
);
const floor = project.drawingLevels.find((z) => z.id === wall.floorId);
const { zBottom, zTop } = wallVerticalExtent(project, wall);
const above = nextFloorAbove(project, wall);
// Volumen aus Achslänge × Gesamtdicke × Höhe, abzüglich der Öffnungen (jede
// Öffnung durchbricht die volle Wanddicke: Breite × Höhe × Dicke).
const length = Math.hypot(wall.end.x - wall.start.x, wall.end.y - wall.start.y);
const wallHeight = Math.max(0, zTop - zBottom);
const grossVolume = length * thickness * wallHeight;
const openingVolume = (project.openings ?? [])
.filter((o) => o.hostWallId === wall.id)
.reduce((sum, o) => sum + o.width * o.height * thickness, 0);
const netVolume = Math.max(0, grossVolume - openingVolume);
// Interne Schichttrennlinien als wählbare Referenz: von aussen (Schicht 0)
// nach innen aufsummiert; der Achsversatz +n = halbe Dicke − Fugenlage.
const half = thickness / 2;
const layerBoundaries: WallInfo["layerBoundaries"] = [];
let cum = 0;
const abbrevOf = (componentId: string): string => {
const c = getComponent(project, componentId);
return c ? c.abbrev ?? c.name : "?";
};
for (let i = 0; i < wt.layers.length - 1; i++) {
cum += wt.layers[i].thickness;
layerBoundaries.push({
offset: half - cum,
label: `${abbrevOf(wt.layers[i].componentId)}|${abbrevOf(wt.layers[i + 1].componentId)}`,
});
}
const wallInfo: WallInfo = {
referenceLine: wall.referenceLine ?? "center",
referenceOffset: wall.referenceOffset,
layerBoundaries,
sliceTermination: wall.sliceTermination ?? "both",
wallTypeId: wall.wallTypeId,
thickness,
singleLayer: wt.layers.length <= 1,
wallTypes: project.wallTypes.map((t) => ({
id: t.id,
name: t.name,
label: wallTypeLabel(t, project.components),
thickness: wallTypeThickness(t),
layerCount: t.layers.length,
})),
floorId: wall.floorId,
floorName: floor?.name ?? wall.floorId,
floors: project.drawingLevels
.filter((z) => z.kind === "floor")
.map((z) => ({ id: z.id, name: z.name })),
floorAbove: above,
bottom: wall.bottom,
top: wall.top,
zBottom,
zTop,
length,
grossVolume,
openingVolume,
netVolume,
};
// bbox aus der Wandachse (start/end); die Schichtdicke bleibt unberücksichtigt,
// damit die Box der Achs-Geometrie folgt (genügt für die Paletten).
return {
kind: "wall",
id: wall.id,
categoryCode: wall.categoryCode,
floorId: wall.floorId,
color,
colorPenId: wall.colorPenId,
weightMm,
fillHatchId: wall.hatchId,
fillColor: undefined,
foreground: wall.foreground,
foregroundPenId: wall.foregroundPenId,
background: wall.background,
backgroundPenId: wall.backgroundPenId,
foregroundSource: wall.foregroundSource,
backgroundSource: wall.backgroundSource,
effectiveForeground,
effectiveBackground,
effectiveHatchId,
strokeWeightOverride: wall.strokeWeight,
strokeWeightSource: wall.strokeWeightSource,
hatchSource: wall.hatchSource,
closed: undefined,
bbox: { minX, minY, maxX, maxY },
wall: wallInfo,
};
}
/** Selektion für eine Decke ableiten (Farbe übersteuerbar, Strichstärke = Kategorie). */
function ceilingSelection(project: Project, ceiling: Ceiling): Selection {
const cat = findCategory(project.layers, ceiling.categoryCode);
const color = ceiling.color ?? cat?.color ?? WALL_FALLBACK_COLOR;
const weightMm = ceiling.strokeWeight ?? cat?.lw ?? WALL_FALLBACK_MM;
const box = outlineBBox(ceiling.outline);
const wt = getCeilingType(project, ceiling);
const thickness = ceilingThickness(project, ceiling);
// Effektive Vordergrund-/Hintergrund-/Schraffur-Vorschau — s. Kommentar in
// wallSelection (dieselbe Kette, äusserste Schicht als Bauteil-Repräsentant).
const outerComponent = getComponent(project, wt.layers[0]?.componentId);
const effectiveForeground = outerComponent
? resolveForeground(outerComponent, ceiling.foreground, cat, ceiling.foregroundSource)
: ceiling.foreground;
const effectiveBackground = outerComponent
? resolveBackground(outerComponent, ceiling.background, cat, ceiling.backgroundSource)
: ceiling.background;
const effectiveHatchId = resolveHatchId(
ceiling.hatchId,
ceiling.hatchSource,
cat,
outerComponent?.hatchId,
);
const floor = project.drawingLevels.find((z) => z.id === ceiling.floorId);
const { zBottom, zTop } = ceilingVerticalExtent(project, ceiling);
const ceilingInfo: CeilingInfo = {
typeId: ceiling.ceilingTypeId ?? ceiling.wallTypeId,
thickness,
singleLayer: wt.layers.length <= 1,
area: ceilingArea(ceiling.outline),
volume: ceilingArea(ceiling.outline) * thickness,
ceilingTypes: (project.ceilingTypes ?? []).map((t) => ({
id: t.id,
name: t.name,
label: wallTypeLabel(t, project.components),
thickness: wallTypeThickness(t),
layerCount: t.layers.length,
})),
floorId: ceiling.floorId,
floorName: floor?.name ?? ceiling.floorId,
floors: project.drawingLevels
.filter((z) => z.kind === "floor")
.map((z) => ({ id: z.id, name: z.name })),
top: ceiling.top,
bottom: ceiling.bottom,
zBottom,
zTop,
// Aussparungen als anzeigefertige BBox-Masse (Breite × Tiefe je Loch).
openings: (ceiling.openings ?? []).map((hole) => {
const bb = outlineBBox(hole);
return { width: bb.maxX - bb.minX, depth: bb.maxY - bb.minY };
}),
};
return {
kind: "ceiling",
id: ceiling.id,
categoryCode: ceiling.categoryCode,
floorId: ceiling.floorId,
color,
colorPenId: ceiling.colorPenId,
weightMm,
fillHatchId: ceiling.hatchId,
fillColor: undefined,
foreground: ceiling.foreground,
foregroundPenId: ceiling.foregroundPenId,
background: ceiling.background,
backgroundPenId: ceiling.backgroundPenId,
foregroundSource: ceiling.foregroundSource,
backgroundSource: ceiling.backgroundSource,
effectiveForeground,
effectiveBackground,
effectiveHatchId,
strokeWeightOverride: ceiling.strokeWeight,
strokeWeightSource: ceiling.strokeWeightSource,
hatchSource: ceiling.hatchSource,
closed: true,
bbox: { minX: box.minX, minY: box.minY, maxX: box.maxX, maxY: box.maxY },
ceiling: ceilingInfo,
};
}
/** Selektion für ein Dach ableiten (Farbe übersteuerbar, Strichstärke = Kategorie). */
function roofSelection(project: Project, roof: Roof): Selection {
const cat = findCategory(project.layers, roof.categoryCode);
const color = roof.color ?? cat?.color ?? WALL_FALLBACK_COLOR;
const weightMm = cat?.lw ?? WALL_FALLBACK_MM;
const bb = roofBBox(roof.outline);
const eavesZ = roofBaseElevation(project, roof);
const g = roofGeometry(roof, eavesZ);
const footprintArea = Math.abs(bb.x1 - bb.x0) * Math.abs(bb.y1 - bb.y0);
const roofInfo: RoofInfo = {
shape: roof.shape,
pitchDeg: roof.pitchDeg,
pitchUpperDeg: roof.pitchUpperDeg,
roofTypeId: roof.roofTypeId,
mansardType: roof.mansardType,
mansardKneeRatio: roof.mansardKneeRatio,
halfHipRatio: roof.halfHipRatio,
overhang: roof.overhang,
overhangGable: roof.overhangGable,
ridgeAxis: roof.ridgeAxis,
thickness: roof.thickness,
baseElevation: eavesZ,
ridgeHeight: g.ridgeHeight,
footprintArea,
width: Math.abs(bb.x1 - bb.x0),
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",
id: roof.id,
categoryCode: roof.categoryCode,
floorId: roof.floorId,
color,
colorPenId: roof.colorPenId,
weightMm,
closed: true,
bbox: { minX: bb.x0, minY: bb.y0, maxX: bb.x1, maxY: bb.y1 },
roof: roofInfo,
};
}
/** Selektion für eine Öffnung ableiten (Farbe übersteuerbar, Strichstärke = Kategorie). */
function openingSelection(project: Project, o: Opening): Selection {
const cat = findCategory(project.layers, o.categoryCode);
const color = o.color ?? cat?.color ?? WALL_FALLBACK_COLOR;
const weightMm = cat?.lw ?? WALL_FALLBACK_MM;
const wall = project.walls.find((w) => w.id === o.hostWallId);
const floor = wall
? project.drawingLevels.find((z) => z.id === wall.floorId)
: undefined;
// Bounding-Box aus dem Lücken-Quad (volle Wanddicke); Fallback: leere Box.
const quad = wall ? openingGapQuad(project, wall, o) : null;
let minX = Infinity,
minY = Infinity,
maxX = -Infinity,
maxY = -Infinity;
for (const p of quad ?? []) {
minX = Math.min(minX, p.x);
minY = Math.min(minY, p.y);
maxX = Math.max(maxX, p.x);
maxY = Math.max(maxY, p.y);
}
if (!isFinite(minX)) {
minX = minY = maxX = maxY = 0;
}
const ext = wall
? openingVerticalExtent(project, wall, o)
: { zBottom: 0, zTop: o.height };
const openingInfo: OpeningInfo = {
id: o.id,
kind: o.kind,
hostWallId: o.hostWallId,
hostWallName: floor ? `${floor.name}` : o.hostWallId,
position: o.position,
width: o.width,
height: o.height,
sillHeight: o.sillHeight,
hinge: o.hinge,
swing: o.swing,
swingAngle: o.swingAngle,
openingDir: o.openingDir,
wingCount: o.wingCount,
doorType: o.doorType,
lintelLines: o.lintelLines,
typeId: o.typeId,
detailLevel: o.detailLevel,
zBottom: ext.zBottom,
zTop: ext.zTop,
frameLine: o.frameLine,
frameViewLine: o.frameViewLine,
sashLine: o.sashLine,
sillLineStyle: o.sillLineStyle,
};
return {
kind: "opening",
id: o.id,
categoryCode: o.categoryCode,
color,
colorPenId: o.colorPenId,
weightMm,
fillHatchId: undefined,
fillColor: undefined,
closed: undefined,
bbox: { minX, minY, maxX, maxY },
opening: openingInfo,
};
}
/** Selektion für eine Treppe ableiten (Farbe übersteuerbar, Strichstärke = Kategorie). */
function stairSelection(project: Project, s: Stair): Selection {
const cat = findCategory(project.layers, s.categoryCode);
const color = s.color ?? cat?.color ?? WALL_FALLBACK_COLOR;
const weightMm = cat?.lw ?? WALL_FALLBACK_MM;
const { zBottom, zTop } = stairVerticalExtent(project, s);
const totalRise = zTop - zBottom;
const geo = stairGeometry(s, totalRise);
const box = stairBBox(geo);
const floor = project.drawingLevels.find((z) => z.id === s.floorId);
const stairInfo: StairInfo = {
shape: s.shape,
width: s.width,
stepCount: s.stepCount,
totalRise,
riserHeight: geo.riserHeight,
treadDepth: geo.treadDepth,
up: s.up !== false,
arrowStyle: s.arrowStyle,
referenz: s.referenz,
typeId: s.typeId,
floorId: s.floorId,
floorName: floor?.name ?? s.floorId,
zBottom,
zTop,
};
return {
kind: "stair",
id: s.id,
categoryCode: s.categoryCode,
floorId: s.floorId,
color,
colorPenId: s.colorPenId,
weightMm,
fillHatchId: undefined,
fillColor: undefined,
closed: undefined,
bbox: { minX: box.minX, minY: box.minY, maxX: box.maxX, maxY: box.maxY },
stair: stairInfo,
};
}
/** Selektion für einen Raum ableiten (Fläche/Umfang aus dem Umriss abgeleitet). */
function roomSelection(project: Project, r: Room): Selection {
const cat = findCategory(project.layers, r.categoryCode);
const color = r.color ?? cat?.color ?? WALL_FALLBACK_COLOR;
const weightMm = cat?.lw ?? WALL_FALLBACK_MM;
const res = evaluateRoom(r.boundary, r.siaCategory);
const floor = project.drawingLevels.find((z) => z.id === r.floorId);
let minX = Infinity,
minY = Infinity,
maxX = -Infinity,
maxY = -Infinity;
for (const p of r.boundary) {
minX = Math.min(minX, p.x);
minY = Math.min(minY, p.y);
maxX = Math.max(maxX, p.x);
maxY = Math.max(maxY, p.y);
}
if (!isFinite(minX)) minX = minY = maxX = maxY = 0;
const roomInfo: RoomInfo = {
name: r.name,
siaCategory: r.siaCategory,
area: res.netArea,
perimeter: res.perimeter,
floorId: r.floorId,
floorName: floor?.name ?? r.floorId,
};
return {
kind: "room",
id: r.id,
categoryCode: r.categoryCode,
floorId: r.floorId,
color,
colorPenId: r.colorPenId,
weightMm,
fillHatchId: undefined,
fillColor: undefined,
closed: true,
bbox: { minX, minY, maxX, maxY },
room: roomInfo,
};
}
/** Auswahl-Farbe der Extrusions-Footprints (identisch zum Grundriss-Umriss/3D-Orange). */
const EXTRUSION_COLOR = "#d98c40";
/** Selektion für einen extrudierten Körper ableiten (truck-Integration). */
function extrudedSolidSelection(project: Project, s: ExtrudedSolid): Selection {
const floor = project.drawingLevels.find((z) => z.id === s.levelId);
let minX = Infinity,
minY = Infinity,
maxX = -Infinity,
maxY = -Infinity;
for (const p of s.points) {
minX = Math.min(minX, p.x);
minY = Math.min(minY, p.y);
maxX = Math.max(maxX, p.x);
maxY = Math.max(maxY, p.y);
}
if (!isFinite(minX)) minX = minY = maxX = maxY = 0;
const info: ExtrudedSolidInfo = {
height: s.height,
taper: s.taper ?? 0,
cornerRadius: s.cornerRadius ?? 0,
chamfer: s.chamfer ?? 0,
...(s.brep ? { brepLabel: s.brep.label ?? "B-Rep" } : {}),
area: polygonArea(s.points),
spec: s.operation === "subtract" ? null : extrudedSolidSpec(s, floor?.baseElevation ?? 0),
subtract: s.operation === "subtract",
canSubtract: !s.brep && (s.taper ?? 0) < 1e-6,
baseOffset: s.baseOffset ?? 0,
floorId: s.levelId,
floorName: floor?.name ?? s.levelId,
};
return {
kind: "extrudedSolid",
id: s.id,
categoryCode: "",
floorId: s.levelId,
color: EXTRUSION_COLOR,
weightMm: WALL_FALLBACK_MM,
fillHatchId: null,
fillColor: null,
closed: true,
bbox: { minX, minY, maxX, maxY },
extrudedSolid: info,
};
}
/** Umriss-/Auswahlfarbe der Stützen-Poché (neutrales Tragwerks-Grau). */
const COLUMN_COLOR = "#3a3f47";
/** Selektion für eine Stütze (Column) ableiten. */
function columnSelection(project: Project, col: Column): Selection {
const floor = project.drawingLevels.find((z) => z.id === col.floorId);
const category = findCategory(project.layers, col.categoryCode);
const pts = columnFootprint(col);
let minX = Infinity,
minY = Infinity,
maxX = -Infinity,
maxY = -Infinity;
for (const p of pts) {
minX = Math.min(minX, p.x);
minY = Math.min(minY, p.y);
maxX = Math.max(maxX, p.x);
maxY = Math.max(maxY, p.y);
}
if (!isFinite(minX)) minX = minY = maxX = maxY = 0;
const { zBottom, zTop } = columnVerticalExtent(project, col);
const info: ColumnInfo = {
profile: col.profile,
height: col.height,
rotationDeg: ((col.rotation ?? 0) * 180) / Math.PI,
floorId: col.floorId,
floorName: floor?.name ?? col.floorId,
zBottom,
zTop,
};
// Effektive Vordergrund-/Hintergrund-/Schraffur-/Strichstärke-Vorschau — s.
// Kommentar in wallSelection (dieselbe Kette, das zugewiesene Bauteil als
// Repräsentant statt der äussersten Schicht, da Column nur EIN componentId
// trägt statt eines geschichteten Aufbaus).
// `getComponent` wirft bei unbekannter ID (z. B. gelöschtes Bauteil) — die
// Panel-Vorschau soll dabei nicht abstürzen (analog dem try/catch in
// structures.ts addColumnPoche), einfach auf "kein Bauteil" zurückfallen.
const comp = col.componentId
? project.components.find((c) => c.id === col.componentId)
: undefined;
const effectiveForeground = comp
? resolveForeground(comp, col.foreground, category, col.foregroundSource)
: col.foreground;
const effectiveBackground = comp
? resolveBackground(comp, col.background, category, col.backgroundSource)
: col.background;
const effectiveHatchId = resolveHatchId(col.hatchId, col.hatchSource, category, comp?.hatchId);
const weightMm = resolveStrokeWeight(col.strokeWeight, col.strokeWeightSource, category, WALL_FALLBACK_MM);
return {
kind: "column",
id: col.id,
categoryCode: col.categoryCode,
floorId: col.floorId,
color: col.color ?? category?.color ?? COLUMN_COLOR,
colorPenId: col.colorPenId,
weightMm,
fillHatchId: col.hatchId,
foreground: col.foreground,
foregroundPenId: col.foregroundPenId,
background: col.background,
backgroundPenId: col.backgroundPenId,
foregroundSource: col.foregroundSource,
backgroundSource: col.backgroundSource,
effectiveForeground,
effectiveBackground,
effectiveHatchId,
strokeWeightOverride: col.strokeWeight,
strokeWeightSource: col.strokeWeightSource,
hatchSource: col.hatchSource,
bbox: { minX, minY, maxX, maxY },
column: info,
};
}
/**
* Selektion für ein Kontext-Objekt (importiertes Mesh/Terrain/Konturen-Satz)
* ableiten. Bbox aus den rohen x/y-Koordinaten (Meshes: flaches [x,y,z…]-
* Array, nur x/y je Vertex; Konturen: `pts` je Kontur) — die Höhe (z) bleibt
* unberücksichtigt (2D-Bbox wie bei allen anderen Elementarten). `lv95Center`
* nur, wenn `project.geoAnchor` gesetzt ist (sonst kein Rückrechnungs-Bezug).
*/
function contextObjectSelection(project: Project, obj: ContextObject): Selection {
let minX = Infinity,
minY = Infinity,
maxX = -Infinity,
maxY = -Infinity;
const consider = (x: number, y: number) => {
minX = Math.min(minX, x);
minY = Math.min(minY, y);
maxX = Math.max(maxX, x);
maxY = Math.max(maxY, y);
};
if (obj.type === "contourSet") {
for (const c of obj.contours) for (const p of c.pts) consider(p.x, p.y);
} else if (obj.type === "image") {
consider(obj.min.x, obj.min.y);
consider(obj.max.x, obj.max.y);
} else {
const pos = obj.positions;
for (let i = 0; i + 2 < pos.length; i += 3) consider(pos[i], pos[i + 1]);
}
if (!isFinite(minX)) minX = minY = maxX = maxY = 0;
const anchor = project.geoAnchor;
const lv95Center = anchor
? localToLv95(
(minX + maxX) / 2,
(minY + maxY) / 2,
{ e: anchor.lv95.e - anchor.model.x, n: anchor.lv95.n - anchor.model.y },
)
: undefined;
const isImage = obj.type === "image";
return {
kind: "contextObject",
id: obj.id,
categoryCode: "",
color: "#888888",
weightMm: WALL_FALLBACK_MM,
bbox: { minX, minY, maxX, maxY },
contextObject: { objType: obj.type, lv95Center },
// Deckkraft + Bildkorrektur nur bei Luftbildern (`ContextImage`) — steuert
// die (wiederverwendete) Deckkraft-Zeile + die neue Bildkorrektur-Sektion
// im Attribute-Panel, s. `AttributesPanel.tsx`.
isImage,
opacity: isImage ? ((obj as ContextImage).opacity ?? 1) : undefined,
imageFilters: isImage ? (obj as ContextImage).filters : undefined,
};
}
/** Selektion für ein 2D-Zeichenelement ableiten (gleiche Auflösung wie generatePlan). */
function drawingSelection(project: Project, d: Drawing2D): Selection {
const ls = d.lineStyleId
? project.lineStyles.find((l) => l.id === d.lineStyleId)
: undefined;
const cat = findCategory(project.layers, d.categoryCode);
const color = d.color ?? ls?.color ?? cat?.color ?? DRAW_FALLBACK_COLOR;
// Effektive Strichstärke, dieselbe Kette wie der Plan (`plan/drawings.rs`)
// (resolveStrokeWeight): Override zuerst, Source ≠ "object" (also "layer"
// ODER fehlend, s. AttributeSource-Default) erzwingt die Kategorie (umgeht
// das LineStyle-Gewicht), sonst die LineStyle-/Kategorie-Kette.
const weightMm =
d.weightMm ??
(d.strokeWeightSource !== "object" ? cat?.lw : undefined) ??
ls?.weight ??
cat?.lw ??
WALL_FALLBACK_MM;
const closed = isClosedGeom(d.geom);
// Effektive Vordergrund-/Hintergrund-/Schraffur-Vorschau — s. Kommentar in
// wallSelection. Ein Drawing2D hat KEIN eigenes Bauteil (daher auch keine
// „Nach Bauteil"-Option im Panel, s. AttributesPanel.tsx) — als Platzhalter
// ein leeres Bauteil, dessen foreground/background/hatchId immer fehlen,
// sodass die Kette bei einem (aus Alt-Daten) expliziten `source:"object"`
// korrekt auf „kein Wert" statt einer erfundenen Bauteilfarbe fällt. Anders
// als bei Wand/Decke (Default „Nach Bauteil") gilt bei Drawing2D „Nach
// Ebene" als Default — daher hier explizit `?? "layer"` VOR dem Resolver
// (der selbst weiterhin generisch „Nach Bauteil" als Default kennt).
const noComponent = { id: "", name: "", color, hatchId: "", joinPriority: 0 };
const effectiveForeground = closed
? resolveForeground(noComponent, d.foreground, cat, d.foregroundSource ?? "layer")
: undefined;
const effectiveBackground = closed
? resolveBackground(noComponent, d.background, cat, d.backgroundSource ?? "layer")
: undefined;
const effectiveHatchId = closed
? resolveHatchId(d.hatchId, d.hatchSource ?? "layer", cat, undefined)
: null;
return {
kind: "drawing2d",
id: d.id,
categoryCode: d.categoryCode,
floorId: d.levelId,
color,
colorPenId: d.colorPenId,
weightMm,
fillHatchId: closed ? d.hatchId ?? null : null,
fillColor: closed ? d.fillColor ?? null : null,
foreground: closed ? d.foreground : undefined,
foregroundPenId: closed ? d.foregroundPenId : undefined,
background: closed ? d.background : undefined,
backgroundPenId: closed ? d.backgroundPenId : undefined,
foregroundSource: closed ? d.foregroundSource : undefined,
backgroundSource: closed ? d.backgroundSource : undefined,
effectiveForeground,
effectiveBackground,
effectiveHatchId,
strokeWeightOverride: d.weightMm,
strokeWeightSource: d.strokeWeightSource,
hatchSource: closed ? d.hatchSource : undefined,
closed,
isImage: d.geom.shape === "image",
// Deckkraft: beim BILD die eigene Bild-Deckkraft, sonst die
// Objekt-Transparenz des Elements (`Drawing2D.opacity`).
opacity: d.geom.shape === "image" ? (d.geom.opacity ?? 1) : d.opacity,
bbox: geomBBox(d.geom),
detailRef:
d.geom.shape === "detailref"
? {
label: d.geom.label,
sheetLayoutId: d.geom.sheetLayoutId,
sheetLabel: d.geom.sheetLabel,
availableLayouts: (project.layouts ?? []).map((l) => ({ id: l.id, name: l.name })),
}
: undefined,
};
}
/** Meldungen, mit denen die Objekt-Info wie bisher abbricht (unbekannter Typ/Bauteil). */
const THROWN = /^Unbekannte[rs]? /;
/**
* Leitet den Selektions-Kontrakt für das ERSTE selektierte Element ab.
* Drawing-Auswahl und Wand-Auswahl schließen sich aus; bei Drawing-Auswahl
* hat diese Vorrang. Liefert `null`, wenn nichts (oder kein auffindbares
* Element) selektiert ist.
* Element) selektiert ist. Ein unbekannter Wand-/Deckentyp oder ein fehlendes
* Bauteil wirft wie bisher; ein Element, das das Kern-Modell nicht lesen kann,
* ergibt `null` (mit Warnung).
*/
export function deriveSelection(
project: Project,
@@ -1303,46 +536,49 @@ export function deriveSelection(
selectedRoofId: string | null = null,
selectedContextObjectId: string | null = null,
): Selection | null {
if (selectedContextObjectId) {
const o = (project.context ?? []).find((x) => x.id === selectedContextObjectId);
if (o) return contextObjectSelection(project, o);
const args = {
wallIds: selectedWallIds,
drawingId: selectedDrawingId,
ceilingId: selectedCeilingId,
openingId: selectedOpeningId,
stairId: selectedStairId,
roomId: selectedRoomId,
extrudedSolidId: selectedExtrudedSolidId,
columnId: selectedColumnId,
roofId: selectedRoofId,
contextObjectId: selectedContextObjectId,
// Lage in der Leseansicht (= Reihenfolge im Dokument): erspart dem Kern die lineare Suche.
at: {} as Record<string, number>,
};
const P = project as unknown as Record<string, { id: string }[] | undefined>;
const hint = (list: string, id: string | null | undefined) => {
if (!id) return;
const i = (P[list] ?? []).findIndex((x) => x.id === id);
if (i >= 0) args.at[list] = i;
};
hint("context", selectedContextObjectId);
hint("drawings2d", selectedDrawingId);
hint("extrudedSolids", selectedExtrudedSolidId);
hint("columns", selectedColumnId);
hint("openings", selectedOpeningId);
hint("walls", selectedWallIds[0]);
hint("ceilings", selectedCeilingId);
hint("roofs", selectedRoofId);
hint("stairs", selectedStairId);
hint("rooms", selectedRoomId);
let sel: Selection | null;
try {
sel = documentFor(project).queryRootMarked<Selection | null>("selectionInfo", JSON.stringify(args));
} catch (e) {
const msg = e instanceof Error ? e.message : String(e);
if (THROWN.test(msg)) throw new Error(msg);
console.warn("Objekt-Info:", msg);
return null;
}
if (selectedDrawingId) {
const d = project.drawings2d.find((x) => x.id === selectedDrawingId);
return d ? drawingSelection(project, d) : null;
if (sel?.extrudedSolid) {
const s = (project.extrudedSolids ?? []).find((x) => x.id === sel!.id);
const floor = s && project.drawingLevels.find((z) => z.id === s.levelId);
sel.extrudedSolid.spec = s && s.operation !== "subtract" ? extrudedSolidSpec(s, floor?.baseElevation ?? 0) : null;
}
if (selectedExtrudedSolidId) {
const s = (project.extrudedSolids ?? []).find((x) => x.id === selectedExtrudedSolidId);
return s ? extrudedSolidSelection(project, s) : null;
}
if (selectedColumnId) {
const c = (project.columns ?? []).find((x) => x.id === selectedColumnId);
return c ? columnSelection(project, c) : null;
}
if (selectedOpeningId) {
const o = (project.openings ?? []).find((x) => x.id === selectedOpeningId);
if (o) return openingSelection(project, o);
}
const wallId = selectedWallIds[0];
if (wallId) {
const w = project.walls.find((x) => x.id === wallId);
return w ? wallSelection(project, w) : null;
}
if (selectedCeilingId) {
const c = (project.ceilings ?? []).find((x) => x.id === selectedCeilingId);
return c ? ceilingSelection(project, c) : null;
}
if (selectedRoofId) {
const r = (project.roofs ?? []).find((x) => x.id === selectedRoofId);
return r ? roofSelection(project, r) : null;
}
if (selectedStairId) {
const s = (project.stairs ?? []).find((x) => x.id === selectedStairId);
return s ? stairSelection(project, s) : null;
}
if (selectedRoomId) {
const r = (project.rooms ?? []).find((x) => x.id === selectedRoomId);
return r ? roomSelection(project, r) : null;
}
return null;
return sel;
}