Merge branch 'worktree-agent-a9e01561581fb6028' into claude/practical-noether-1hb2s1

# Conflicts:
#	TODO.md
This commit is contained in:
Claude committed 2026-11-14 02:20:49 +00:00
commit 1406a060e7
30 files changed
+2142 -17

No files matched your search

+1 -1
View File
@@ -30,7 +30,7 @@ Ribbon-Befehle sie erreichen: `src/state/useToolInput.ts`.
|---|---|
| Bauteile | `wall.ts`, `opening.ts`, `ceiling.ts`, `ceilingOpening.ts`, `roof.ts`, `roofHole.ts`, `roofWindow.ts`, `dormer.ts`, `stair.ts`, `column.ts`, `room.ts`, `grid.ts`, `tree.ts`, `terrain.ts`, `excavation.ts` |
| Körper | `solid.ts`, `solidbool.ts`, `solidToParts.ts` (Körper → Bauteile, [222]), `voidbox.ts`, `extrude.ts`, `revolve.ts`, `loft.ts` |
| 2D zeichnen | `line.ts`, `xline.ts`, `ray.ts`, `polyline.ts`, `polygon.ts`, `rect.ts`, `circle.ts`, `arc.ts`, `ellipse.ts`, `bezier.ts`, `spline.ts`, `multiline.ts`, `revcloud.ts`, `wipeout.ts`, `block.ts`, `defblock.ts` |
| 2D zeichnen | `line.ts`, `xline.ts`, `ray.ts`, `polyline.ts`, `polygon.ts`, `rect.ts`, `circle.ts`, `arc.ts`, `ellipse.ts`, `bezier.ts`, `spline.ts`, `multiline.ts`, `revcloud.ts`, `wipeout.ts`, `block.ts`, `defblock.ts`, `libobj.ts` (Objekt aus der Bibliothek setzen, [253]) |
| Beschriften | `text.ts`, `textbox.ts`, `textpath.ts`, `leader.ts`, `dimension.ts`, `dimround.ts`, `dimdetach.ts`, `autodim.ts`, `kote.ts`, `detailref.ts`, `pointmarker.ts`, `scalebar.ts`, `sectionline.ts` |
| Bearbeiten | `transform.ts` (Bewegen, Drehen, Spiegeln), `copy.ts`, `scale.ts`, `array.ts`, `align.ts`, `offset.ts`, `trim.ts`, `extend.ts`, `fillet.ts`, `chamfer.ts`, `cornerHit.ts`, `break.ts`, `split.ts`, `join.ts`, `explode.ts` |
| Sonstiges | `measure.ts`, `wand.ts` (Zauberstab), `recognize.ts` (Bauteile aus Zeichnung), `georef.ts`, `import.ts`, `presentation.ts` |
+152
View File
@@ -0,0 +1,152 @@
/**
* Objektbibliothek 2D ([253]): Katalog aus dem Kern, Platzieren (Befehl `libobj`: Klasse wird im selben Schritt
* angelegt, Drehen/Spiegeln), Plan-Ausgabe nach Detailgrad, unbekannte Objekt-Id, Möbel sparen den Belag aus.
*/
import { describe, it, expect, beforeEach } from "vitest";
import { libobjCommand, setActiveLibObject, resetLibObjectPlacement } from "./libobj";
import { libCatalog, libDefaultParams, libGeometry, libGroups, libObjectDef } from "../../model/furnitureLib";
import { drawingPrimitives } from "../../plan/generatePlan";
import type { CommandContext, Project } from "../types";
import type { Drawing2D } from "../../model/types";
function project(layers: Project["layers"] = []): Project {
return {
id: "t",
name: "T",
lineStyles: [],
hatches: [],
components: [],
wallTypes: [],
drawingLevels: [{ id: "eg", name: "EG", kind: "floor", visible: true, locked: false, floorHeight: 2.6, cutHeight: 1.0, baseElevation: 0 }],
layers,
walls: [],
openings: [],
ceilings: [],
stairs: [],
rooms: [],
drawings2d: [],
context: [],
};
}
function makeCtx(p: Project): CommandContext {
return {
project: p,
level: p.drawingLevels[0],
defaultCategoryCode: "20",
activeLineStyleId: "solid",
activeWallTypeId: "aw",
lastPoint: null,
selection: { wallIds: [], drawingId: null },
};
}
const LAYER_MOEBEL = { code: "22", name: "Möbel", color: "#4a4a4a", lw: 0.13, visible: true, locked: false };
function place(p: Project, libId: string, at = { x: 3, y: 4 }) {
setActiveLibObject(libId, libDefaultParams(libObjectDef(libId)!));
const [, r] = libobjCommand.onInput(libobjCommand.init(), { kind: "point", point: at }, makeCtx(p));
expect(r.commit).toBeDefined();
return r.commit!(p);
}
beforeEach(() => resetLibObjectPlacement());
describe("Katalog", () => {
it("enthält alle Gruppen und Objekte aus dem Kern", () => {
const c = libCatalog();
expect(c.objects.length).toBeGreaterThanOrEqual(48);
expect(libGroups()).toEqual(["sanitary", "kitchen", "tables", "seating", "sleeping", "cupboards", "outdoor"]);
for (const o of c.objects) expect(libGeometry(o.id, libDefaultParams(o), "mittel").length).toBeGreaterThan(0);
});
it("Parameter sind allgemein beschrieben (Art, Vorgabe, Grenzen)", () => {
const wc = libObjectDef("lib:wc-wand")!;
expect(wc.params.find((p) => p.key === "w")).toMatchObject({ kind: "length", default: 0.38 });
expect(libObjectDef("lib:tisch-80x140")!.seeded).toBe(true);
});
});
describe("Befehl libobj", () => {
it("setzt ein WC auf Sanitär und legt die Klasse im selben Schritt an", () => {
const p = project([LAYER_MOEBEL]);
const next = place(p, "lib:wc-wand");
expect(next.drawings2d).toHaveLength(1);
const d = next.drawings2d[0];
expect(d.categoryCode).toBe("23");
expect(next.layers.some((l) => l.code === "23" && l.name === "Sanitär")).toBe(true);
expect(d.geom.shape).toBe("libobj");
if (d.geom.shape === "libobj") {
expect(d.geom.libId).toBe("lib:wc-wand");
expect(d.geom.at).toEqual({ x: 3, y: 4 });
expect(d.geom.rotation).toBe(0);
}
});
it("Möbel landen auf „Möbel“; eine vorhandene Klasse wird nicht doppelt angelegt", () => {
const p = project([LAYER_MOEBEL]);
const next = place(p, "lib:bett-140");
expect(next.drawings2d[0].categoryCode).toBe("22");
expect(next.layers.filter((l) => l.code === "22")).toHaveLength(1);
});
it("Drehen (R) und Spiegeln (M) gelten für das nächste Objekt", () => {
const p = project([LAYER_MOEBEL]);
setActiveLibObject("lib:sofa-2", libDefaultParams(libObjectDef("lib:sofa-2")!));
let [s] = libobjCommand.onInput(libobjCommand.init(), { kind: "option", id: "rotate" }, makeCtx(p));
[s] = libobjCommand.onInput(s, { kind: "option", id: "mirror" }, makeCtx(p));
const [, r] = libobjCommand.onInput(s, { kind: "point", point: { x: 1, y: 1 } }, makeCtx(p));
const g = r.commit!(p).drawings2d[0].geom;
expect(g.shape).toBe("libobj");
if (g.shape === "libobj") {
expect(g.rotation).toBeCloseTo(Math.PI / 2, 9);
expect(g.params?.mirror).toBe(true);
}
});
it("Vorschau hängt am Cursor", () => {
setActiveLibObject("lib:stuhl", {});
const [, r] = libobjCommand.onMove!(libobjCommand.init(), { x: 2, y: 2 }, null, makeCtx(project()));
expect(r.draft?.preview.length).toBeGreaterThan(0);
});
});
function libDrawing(geom: Extract<Drawing2D["geom"], { shape: "libobj" }>): Drawing2D {
return { id: "o1", type: "drawing2d", levelId: "eg", categoryCode: "23", geom };
}
describe("Plan-Ausgabe", () => {
const proj = () => project([LAYER_MOEBEL, { code: "23", name: "Sanitär", color: "#4a4a4a", lw: 0.13, visible: true, locked: false }]);
it("ein gesetztes WC erscheint als Linien an der Lage, gedreht", () => {
const d = libDrawing({ shape: "libobj", libId: "lib:wc-wand", at: { x: 10, y: 10 }, rotation: 0 });
const lines = drawingPrimitives(proj(), d).filter((p) => p.kind === "line");
expect(lines.length).toBeGreaterThan(4);
const ys = lines.flatMap((l) => [l.a.y, l.b.y]);
// Wandseite bei y = 10, Bug 55 cm davor.
expect(Math.min(...ys)).toBeCloseTo(10, 6);
expect(Math.max(...ys)).toBeCloseTo(10.55, 2);
const xs = lines.flatMap((l) => [l.a.x, l.b.x]);
expect(Math.max(...xs) - Math.min(...xs)).toBeCloseTo(0.38, 2);
});
it("Detailgrad: mehr Linien bei höherem Grad — Parameter ändern das Mass", () => {
const d = libDrawing({ shape: "libobj", libId: "lib:lavabo", at: { x: 0, y: 0 }, rotation: 0, params: { w: 0.8 } });
const xs = drawingPrimitives(proj(), d).filter((p) => p.kind === "line").flatMap((l) => [l.a.x, l.b.x]);
expect(Math.max(...xs) - Math.min(...xs)).toBeCloseTo(0.8, 2);
});
it("unbekannte Objekt-Id zeichnet einen Platzhalter-Rahmen statt zu scheitern", () => {
const d = libDrawing({ shape: "libobj", libId: "lib:gibt-es-nicht", at: { x: 0, y: 0 }, rotation: 0 });
expect(drawingPrimitives(proj(), d).filter((p) => p.kind === "line").length).toBeGreaterThanOrEqual(3);
});
it("gleicher Seed = gleiche Stühle; Unordnung 0 = regelmässig", () => {
const mk = (mess: number, seed: number) =>
drawingPrimitives(proj(), libDrawing({ shape: "libobj", libId: "lib:tisch-80x140", at: { x: 0, y: 0 }, rotation: 0, params: { mess }, seed }));
expect(JSON.stringify(mk(1, 5))).toEqual(JSON.stringify(mk(1, 5)));
expect(JSON.stringify(mk(1, 5))).not.toEqual(JSON.stringify(mk(1, 6)));
expect(JSON.stringify(mk(0, 5))).toEqual(JSON.stringify(mk(0, 6)));
});
});
+98
View File
@@ -0,0 +1,98 @@
// Objekt der Bibliothek setzen ([253]) — platziert ein Objekt der Standard-Bibliothek (Palette „Objekte") als
// parametrische Instanz (`{shape:"libobj"}`: Katalog-Id + Parameter + Lage); der Kern erzeugt die Linien zur
// Plan-Zeit nach Detailgrad. Welches Objekt aktiv ist, setzt die Palette über `setActiveLibObject`.
// „Einfügepunkt:" → Punkt (Klick setzt ein). Optionen: Drehen (R, +90°), Spiegeln (M). Drehung und Spiegelung
// bleiben für die nächsten Objekte erhalten. Die Vorschau hängt am Cursor.
// Klasse (Möbel, Sanitär, Fahrzeuge & Freiflächen) bestimmt der Kern; fehlt sie im Projekt, legt der Befehl sie
// im selben Undo-Schritt an.
import { createMutation, xy } from "../createCore";
import { libGeometry, libGeometryToPolys, type LibParams } from "../../model/furnitureLib";
import type { CmdOption, Command, CommandResult, CommandState, Vec2 } from "../types";
interface ActiveLib {
libId: string;
params: LibParams;
}
let active: ActiveLib | null = null;
/** Drehung (Radiant) und Spiegelung der Objekte, die als Nächstes gesetzt werden. */
let rotation = 0;
let mirror = false;
/** Die Palette wählt das Objekt (und seine Parameter) für den Befehl `libobj`. */
export function setActiveLibObject(libId: string, params: LibParams = {}): void {
active = { libId, params: { ...params } };
}
export function activeLibObject(): ActiveLib | null {
return active;
}
/** Nur für Tests: Drehung/Spiegelung zurücksetzen. */
export function resetLibObjectPlacement(): void {
rotation = 0;
mirror = false;
}
interface LibState extends CommandState {
phase: "point";
}
const OPTIONS: CmdOption[] = [
{ id: "rotate", labelKey: "cmd.libobj.rotate", key: "R" },
{ id: "mirror", labelKey: "cmd.libobj.mirror", key: "M" },
];
function instanceParams(): LibParams {
const p: LibParams = { ...(active?.params ?? {}) };
if (mirror) p.mirror = true;
else delete p.mirror;
return p;
}
function previewAt(at: Vec2): CommandResult {
if (!active) return { draft: null };
const c = Math.cos(rotation);
const s = Math.sin(rotation);
const geoms = libGeometry(active.libId, instanceParams(), "mittel", 0);
const polys = libGeometryToPolys(geoms, (p) => ({ x: at.x + p.x * c - p.y * s, y: at.y + p.x * s + p.y * c }));
return {
draft: {
preview: polys.map((pl) => ({ kind: "poly" as const, pts: pl.pts, closed: pl.closed })),
vertices: [at],
},
};
}
const state0 = (): LibState => ({ phase: "point", lastPoint: null });
export const libobjCommand: Command = {
name: "libobj",
labelKey: "cmd.libobj.label",
prompt: () => "cmd.libobj.point",
accepts: () => ["point", "option"],
options: () => OPTIONS.map((o) => (o.id === "mirror" ? { ...o, value: mirror ? "ja" : "nein" } : { ...o, value: `${Math.round((rotation * 180) / Math.PI) % 360}°` })),
init: state0,
onInput: (state, input, ctx): [CommandState, CommandResult] => {
if (input.kind === "option") {
if (input.id === "rotate") rotation = (rotation + Math.PI / 2) % (2 * Math.PI);
else if (input.id === "mirror") mirror = !mirror;
return [state, { draft: null }];
}
if (input.kind !== "point" || !active) return [state, { draft: null }];
const commit = createMutation(ctx, {
cmd: "libobj",
lib: active.libId,
at: xy(input.point),
rotation,
params: instanceParams(),
});
return [state0(), { draft: null, done: true, commit }];
},
onMove: (state, point): [CommandState, CommandResult] => [state, previewAt(point)],
onConfirm: (): [CommandState, CommandResult] => [state0(), { draft: null, done: true }],
onCancel: (): [CommandState, CommandResult] => [state0(), { draft: null, done: true }],
};
+2
View File
@@ -75,6 +75,7 @@ import { sectionLineCommand, viewLineCommand } from "./cmds/sectionline";
import { georefCommand } from "./cmds/georef";
import { blockCommand } from "./cmds/block";
import { defblockCommand } from "./cmds/defblock";
import { libobjCommand } from "./cmds/libobj";
import { presentationCommand } from "./cmds/presentation";
import { traceMoveCommand, traceRotateCommand } from "./cmds/tracemove";
import { renderingCommand } from "./cmds/rendering";
@@ -164,6 +165,7 @@ export const COMMANDS: Record<string, Command> = {
georef: georefCommand,
block: blockCommand,
defblock: defblockCommand,
libobj: libobjCommand,
tracemove: traceMoveCommand,
tracerotate: traceRotateCommand,
};
+79
View File
@@ -4250,6 +4250,85 @@ export const de = {
"help.shortcuts.commandsHint": "In die Befehlszeile tippen, dann Enter. Ändern: Einstellungen → Tastenkürzel.",
"file.newFromWettbewerbSample": "Neu aus Vorlage: Wettbewerb",
"menu.native.newFromWettbewerbSample": "Wettbewerb",
"lib.o.wc-wand": "WC wandhängend",
"lib.o.wc-kasten": "WC mit Spülkasten",
"lib.o.lavabo": "Lavabo",
"lib.o.handwaschbecken": "Handwaschbecken",
"lib.o.doppellavabo": "Doppellavabo",
"lib.o.dusche-90": "Dusche 90×90",
"lib.o.dusche-80x120": "Dusche 80×120",
"lib.o.wanne-170": "Badewanne 170×75",
"lib.o.wanne-180": "Badewanne 180×80",
"lib.o.urinal": "Urinal",
"lib.o.waschmaschine": "Waschmaschine / Tumbler",
"lib.o.kueche-unterbau": "Unterbau 55",
"lib.o.kueche-spuele": "Spüle 55",
"lib.o.kueche-kochfeld": "Kochfeld 55",
"lib.o.kueche-geschirrspueler": "Geschirrspüler 55",
"lib.o.kueche-kuehlschrank": "Kühlschrank 55",
"lib.o.kueche-hochschrank": "Hochschrank 55",
"lib.o.kueche-zeile": "Küchenzeile (55er-Module)",
"lib.o.kueche-insel": "Küchen-Insel",
"lib.o.tisch-80x140": "Tisch 80×140 mit Stühlen",
"lib.o.tisch-80x140-leer": "Tisch 80×140",
"lib.o.tisch-90x180": "Tisch 90×180 mit Stühlen",
"lib.o.tisch-90x180-leer": "Tisch 90×180",
"lib.o.tisch-rund-100": "Tisch rund Ø 100 mit Stühlen",
"lib.o.tisch-rund-100-leer": "Tisch rund Ø 100",
"lib.o.tisch-rund-120": "Tisch rund Ø 120 mit Stühlen",
"lib.o.tisch-rund-120-leer": "Tisch rund Ø 120",
"lib.o.tisch-buero": "Bürotisch 80×160",
"lib.o.stuhl": "Stuhl",
"lib.o.sofa-2": "Sofa 2er",
"lib.o.sofa-3": "Sofa 3er",
"lib.o.sessel": "Sessel",
"lib.o.salontisch": "Salontisch",
"lib.o.bett-90": "Bett 90×200",
"lib.o.bett-140": "Bett 140×200",
"lib.o.bett-160": "Bett 160×200",
"lib.o.bett-180": "Bett 180×200",
"lib.o.kinderbett": "Kinderbett 70×140",
"lib.o.nachttisch": "Nachttisch",
"lib.o.schrank-50": "Einbauschrank 50",
"lib.o.schrank-60": "Einbauschrank 60",
"lib.o.schrank-100": "Einbauschrank 100",
"lib.o.garderobe": "Garderobe T 35",
"lib.o.regal": "Regal T 35",
"lib.o.auto": "Auto mit Parkfeld",
"lib.o.parkfeld": "Parkfeld 2.50×5.00",
"lib.o.velo": "Velo",
"lib.o.wendekreis": "Rollstuhl-Wendekreis Ø 150",
"lib.g.sanitary": "Sanitär",
"lib.g.kitchen": "Küche",
"lib.g.tables": "Tische",
"lib.g.seating": "Sitzen",
"lib.g.sleeping": "Schlafen",
"lib.g.cupboards": "Schränke",
"lib.g.outdoor": "Aussenraum",
"lib.p.w": "Breite",
"lib.p.d": "Tiefe",
"lib.p.n": "Anzahl",
"lib.p.mess": "Unordnung",
"lib.p.field": "Parkfeld",
"lib.p.mirror": "Spiegeln",
"lib.title": "Objekte",
"lib.hint": "Objekt wählen, dann im Plan den Einfügepunkt klicken (R = drehen, M = spiegeln).",
"lib.empty": "Keine Objekte verfügbar.",
"lib.params": "Vorgaben",
"lib.reroll": "Neu würfeln",
"lib.section": "Objekt aus Bibliothek",
"lib.unknown": "Unbekanntes Objekt",
"cmd.libobj.label": "Objekt setzen",
"cmd.libobj.point": "Einfügepunkt:",
"cmd.libobj.rotate": "Drehen",
"cmd.libobj.mirror": "Spiegeln",
"history.cmd.libobj": "Objekt setzen",
"history.libobj.param": "Objekt-Parameter ändern",
"history.libobj.reroll": "Stühle neu würfeln",
"nav.objects": "Objekte",
"lib.p.diameter": "Durchmesser",
"lib.p.n.kitchen": "Module (55 cm)",
"lib.p.n.tables": "Stühle",
} as const;
export type TranslationKey = keyof typeof de;
+79
View File
@@ -4236,4 +4236,83 @@ export const en: Record<TranslationKey, string> = {
"help.shortcuts.commandsHint": "Type into the command line, then press Enter. To change: Settings → Keyboard shortcuts.",
"file.newFromWettbewerbSample": "New From Template: Competition",
"menu.native.newFromWettbewerbSample": "Competition",
"lib.o.wc-wand": "Wall-hung toilet",
"lib.o.wc-kasten": "Toilet with cistern",
"lib.o.lavabo": "Washbasin",
"lib.o.handwaschbecken": "Hand basin",
"lib.o.doppellavabo": "Double washbasin",
"lib.o.dusche-90": "Shower 90×90",
"lib.o.dusche-80x120": "Shower 80×120",
"lib.o.wanne-170": "Bathtub 170×75",
"lib.o.wanne-180": "Bathtub 180×80",
"lib.o.urinal": "Urinal",
"lib.o.waschmaschine": "Washer / dryer",
"lib.o.kueche-unterbau": "Base unit 55",
"lib.o.kueche-spuele": "Sink unit 55",
"lib.o.kueche-kochfeld": "Hob 55",
"lib.o.kueche-geschirrspueler": "Dishwasher 55",
"lib.o.kueche-kuehlschrank": "Fridge 55",
"lib.o.kueche-hochschrank": "Tall unit 55",
"lib.o.kueche-zeile": "Kitchen run (55 cm modules)",
"lib.o.kueche-insel": "Kitchen island",
"lib.o.tisch-80x140": "Table 80×140 with chairs",
"lib.o.tisch-80x140-leer": "Table 80×140",
"lib.o.tisch-90x180": "Table 90×180 with chairs",
"lib.o.tisch-90x180-leer": "Table 90×180",
"lib.o.tisch-rund-100": "Round table Ø 100 with chairs",
"lib.o.tisch-rund-100-leer": "Round table Ø 100",
"lib.o.tisch-rund-120": "Round table Ø 120 with chairs",
"lib.o.tisch-rund-120-leer": "Round table Ø 120",
"lib.o.tisch-buero": "Office desk 80×160",
"lib.o.stuhl": "Chair",
"lib.o.sofa-2": "Sofa 2-seater",
"lib.o.sofa-3": "Sofa 3-seater",
"lib.o.sessel": "Armchair",
"lib.o.salontisch": "Coffee table",
"lib.o.bett-90": "Bed 90×200",
"lib.o.bett-140": "Bed 140×200",
"lib.o.bett-160": "Bed 160×200",
"lib.o.bett-180": "Bed 180×200",
"lib.o.kinderbett": "Child bed 70×140",
"lib.o.nachttisch": "Bedside table",
"lib.o.schrank-50": "Built-in cupboard 50",
"lib.o.schrank-60": "Built-in cupboard 60",
"lib.o.schrank-100": "Built-in cupboard 100",
"lib.o.garderobe": "Wardrobe D 35",
"lib.o.regal": "Shelf D 35",
"lib.o.auto": "Car with parking bay",
"lib.o.parkfeld": "Parking bay 2.50×5.00",
"lib.o.velo": "Bicycle",
"lib.o.wendekreis": "Wheelchair turning circle Ø 150",
"lib.g.sanitary": "Sanitary",
"lib.g.kitchen": "Kitchen",
"lib.g.tables": "Tables",
"lib.g.seating": "Seating",
"lib.g.sleeping": "Sleeping",
"lib.g.cupboards": "Cupboards",
"lib.g.outdoor": "Outdoor",
"lib.p.w": "Width",
"lib.p.d": "Depth",
"lib.p.n": "Count",
"lib.p.mess": "Disorder",
"lib.p.field": "Parking bay",
"lib.p.mirror": "Mirror",
"lib.title": "Objects",
"lib.hint": "Pick an object, then click the insertion point in the plan (R = rotate, M = mirror).",
"lib.empty": "No objects available.",
"lib.params": "Defaults",
"lib.reroll": "Re-roll",
"lib.section": "Library object",
"lib.unknown": "Unknown object",
"cmd.libobj.label": "Place object",
"cmd.libobj.point": "Insertion point:",
"cmd.libobj.rotate": "Rotate",
"cmd.libobj.mirror": "Mirror",
"history.cmd.libobj": "Place object",
"history.libobj.param": "Change object parameter",
"history.libobj.reroll": "Re-roll chairs",
"nav.objects": "Objects",
"lib.p.diameter": "Diameter",
"lib.p.n.kitchen": "Modules (55 cm)",
"lib.p.n.tables": "Chairs",
};
+145
View File
@@ -0,0 +1,145 @@
// Objektbibliothek 2D ([253]) — dünne Fassade über den Katalog des Rust-Kerns
// (`src-tauri/core/src/furniture_lib.rs`). Der Katalog beschreibt Objekte mit Gruppe, Klasse, Einfügepunkt und
// einer allgemeinen Parameterliste; die Linien erzeugt der Kern (zur Plan-Zeit nach Detailgrad, hier nur für
// die Vorschau der Palette und des Platzier-Werkzeugs).
import { core } from "../engine/coreWasm";
import type { Drawing2DGeom } from "./types";
export type LibParamKind = "length" | "count" | "flag" | "fraction" | "choice";
export interface LibParamDef {
key: string;
kind: LibParamKind;
default: number;
min: number;
max: number;
step: number;
}
export interface LibObjectDef {
id: string;
/** Gruppe (`lib.g.<group>`). */
group: string;
/** Klasse: Schlüssel, Code und Name der Grafik-Kategorie. */
category: string;
categoryCode: string;
categoryName: string;
/** Einfügepunkt: Wandseite Mitte oder Mittelpunkt. */
anchor: "wall" | "center";
/** Nutzt den Seed (Unordnung der Stühle). */
seeded: boolean;
params: LibParamDef[];
}
export interface LibCatalog {
objects: LibObjectDef[];
categories: { key: string; code: string; name: string; color: string; lw: number }[];
}
/** Parameter einer Instanz (Name → Zahl/Bool/Text), wie im Modell. */
export type LibParams = Record<string, number | boolean | string>;
export type LibDetail = "grob" | "mittel" | "fein";
let cache: LibCatalog | null = null;
/** Der Katalog (einmal aus dem Kern gelesen). */
export function libCatalog(): LibCatalog {
if (!cache) {
try {
const c = JSON.parse(core().furniture_lib_catalog_json()) as Partial<LibCatalog>;
cache = { objects: c.objects ?? [], categories: c.categories ?? [] };
} catch {
cache = { objects: [], categories: [] };
}
}
return cache;
}
export function libObjectDef(id: string): LibObjectDef | undefined {
return libCatalog().objects.find((o) => o.id === id);
}
/** Gruppen in Palettenreihenfolge. */
export function libGroups(): string[] {
const seen: string[] = [];
for (const o of libCatalog().objects) if (!seen.includes(o.group)) seen.push(o.group);
return seen;
}
/** Vorgabe-Parameter eines Objekts (alle Schlüssel mit Vorgabewert). */
export function libDefaultParams(def: LibObjectDef): LibParams {
const out: LibParams = {};
for (const p of def.params) out[p.key] = p.kind === "flag" ? p.default >= 0.5 : p.default;
return out;
}
/** Lokale Geometrie (Einfügepunkt = Ursprung, ohne Drehung) für Vorschau; der Kern erzeugt sie. */
export function libGeometry(libId: string, params: LibParams, detail: LibDetail, seed = 0): Drawing2DGeom[] {
try {
return JSON.parse(core().furniture_lib_geometry_json(libId, JSON.stringify(params), detail, seed >>> 0)) as Drawing2DGeom[];
} catch {
return [];
}
}
type P = { x: number; y: number };
/** Geometrie als Linienzüge (Vorschau): Kreise, Bögen und Ellipsen abgetastet; `tf` bildet jeden Punkt ab. */
export function libGeometryToPolys(geoms: Drawing2DGeom[], tf: (p: P) => P = (p) => p): { pts: P[]; closed: boolean }[] {
const out: { pts: P[]; closed: boolean }[] = [];
const arc = (c: P, rx: number, ry: number, a0: number, a1: number, closed: boolean) => {
const n = Math.max(8, Math.ceil((Math.abs(a1 - a0) / (2 * Math.PI)) * 32));
const pts: P[] = [];
for (let i = 0; i <= n; i++) {
const a = a0 + ((a1 - a0) * i) / n;
pts.push(tf({ x: c.x + rx * Math.cos(a), y: c.y + ry * Math.sin(a) }));
}
out.push({ pts: closed ? pts.slice(0, -1) : pts, closed });
};
for (const g of geoms) {
switch (g.shape) {
case "line":
out.push({ pts: [tf(g.a), tf(g.b)], closed: false });
break;
case "rect":
out.push({
pts: [g.min, { x: g.max.x, y: g.min.y }, g.max, { x: g.min.x, y: g.max.y }].map(tf),
closed: true,
});
break;
case "polyline":
out.push({ pts: g.pts.map(tf), closed: g.closed });
break;
case "circle":
arc(g.center, g.r, g.r, 0, 2 * Math.PI, true);
break;
case "ellipse":
arc(g.center, g.rx, g.ry, 0, 2 * Math.PI, true);
break;
case "arc":
arc(g.center, g.r, g.r, g.a0, g.a1 > g.a0 ? g.a1 : g.a1 + 2 * Math.PI, false);
break;
default:
break;
}
}
return out;
}
/** Grenzen der Linienzüge (für den Massstab der Vorschau). */
export function polysBounds(polys: { pts: P[] }[]): { minX: number; minY: number; maxX: number; maxY: number } | null {
let b: { minX: number; minY: number; maxX: number; maxY: number } | null = null;
for (const pl of polys)
for (const p of pl.pts) {
if (!b) b = { minX: p.x, minY: p.y, maxX: p.x, maxY: p.y };
else {
b.minX = Math.min(b.minX, p.x);
b.minY = Math.min(b.minY, p.y);
b.maxX = Math.max(b.maxX, p.x);
b.maxY = Math.max(b.maxY, p.y);
}
}
return b;
}
+12
View File
@@ -1193,6 +1193,18 @@ export type Drawing2DGeom =
*/
scale?: number;
}
| {
shape: "libobj";
libId: string;
at: Vec2;
rotation: number;
/**
* Parameter (Name → Zahl/Bool/Text), z. B. `w`, `d`, `n`, `mirror`, `mess`; fehlend = Vorgabe des Objekts.
*/
params?: Record<string, number | boolean | string>;
/** Seed für zufällige Anteile (Unordnung der Stühle): gleicher Seed = gleiche Geometrie. */
seed?: number;
}
| {
shape: "image";
/** Obere-linke Ecke der Bild-Box (Modell-Meter). */
+4
View File
@@ -34,6 +34,7 @@ import { TreeSection } from "./objectInfo/TreeSection";
import { CameraSection } from "./objectInfo/CameraSection";
import { ViewShadowsInfo, MeasurementSection } from "./objectInfo/InfoBlocks";
import { DimensionField, RotateField } from "./objectInfo/fields";
import { LibObjectSection } from "./objectInfo/LibObjectSection";
import { elementDimensions } from "./objectInfo/elementDims";
import { InfoGroups, hasInfoGroups } from "./objectInfo/InfoGroups";
import { infoGroupFrame, useInfoGroupState } from "./objectInfo/InfoGroup";
@@ -262,6 +263,9 @@ export function ObjectInfoPanel({ showPlacement = true }: { showPlacement?: bool
<span className="objinfo-fval">{len(d.value).toFixed(u.digits)} {u.suffix}</span>
</div>
))
) : rawDrawing?.geom.shape === "libobj" ? (
// [253] Bibliotheks-Objekt: Masse und Parameter generisch aus dem Katalog.
<LibObjectSection drawing={rawDrawing} geom={rawDrawing.geom} />
) : (
<>
<DimensionField
+111
View File
@@ -0,0 +1,111 @@
// Dock-Panel „Objekte" ([253]) — Palette der Standard-Objektbibliothek 2D: Gruppen (Sanitär, Küche, Tische, …)
// mit Vorschau-Symbol je Objekt. Klick wählt das Objekt und startet den Befehl `libobj` (Einfügepunkt klicken,
// R = drehen, M = spiegeln). Der Katalog kommt aus dem Rust-Kern; die Vorschau zeichnet der Kern (grob).
import { useMemo } from "react";
import { t } from "../i18n";
import type { TranslationKey } from "../i18n";
import { usePanelHostAction } from "./host";
import { setActiveLibObject } from "../commands/cmds/libobj";
import {
libCatalog,
libDefaultParams,
libGeometry,
libGeometryToPolys,
libGroups,
polysBounds,
type LibObjectDef,
} from "../model/furnitureLib";
const SIZE = 44;
/** Vorschau: Linien des Objekts (grob) als kleines SVG, Plan-y nach oben. */
function Preview({ def }: { def: LibObjectDef }) {
const polys = useMemo(
() => libGeometryToPolys(libGeometry(def.id, libDefaultParams(def), "grob", 1), (p) => ({ x: p.x, y: -p.y })),
[def],
);
const b = polysBounds(polys);
if (!b) return <svg width={SIZE} height={SIZE} aria-hidden="true" />;
const w = Math.max(b.maxX - b.minX, 1e-3);
const h = Math.max(b.maxY - b.minY, 1e-3);
const pad = 3;
const k = (SIZE - 2 * pad) / Math.max(w, h);
const tx = (x: number) => pad + (x - b.minX) * k + ((SIZE - 2 * pad) - w * k) / 2;
const ty = (y: number) => pad + (y - b.minY) * k + ((SIZE - 2 * pad) - h * k) / 2;
return (
<svg width={SIZE} height={SIZE} viewBox={`0 0 ${SIZE} ${SIZE}`} fill="none" stroke="currentColor" strokeWidth={1} strokeLinejoin="round" aria-hidden="true" focusable="false">
{polys.map((pl, i) => {
const d = pl.pts.map((p, j) => `${j ? "L" : "M"}${tx(p.x).toFixed(2)} ${ty(p.y).toFixed(2)}`).join(" ") + (pl.closed ? "Z" : "");
return <path key={i} d={d} />;
})}
</svg>
);
}
export function ObjectLibraryPanel() {
const onRunCommand = usePanelHostAction("onRunCommand");
const catalog = useMemo(() => libCatalog(), []);
const groups = useMemo(() => libGroups(), []);
const place = (def: LibObjectDef) => {
setActiveLibObject(def.id, libDefaultParams(def));
onRunCommand("libobj");
};
if (catalog.objects.length === 0) {
return <div style={{ padding: 10, fontSize: 12, color: "var(--muted)" }}>{t("lib.empty")}</div>;
}
return (
<div className="objlib-panel" style={{ overflowY: "auto", padding: "6px 8px" }}>
<div style={{ fontSize: 11, color: "var(--muted)", marginBottom: 6 }}>{t("lib.hint")}</div>
{groups.map((g) => (
<details key={g} open={g === groups[0]} style={{ marginBottom: 4 }}>
<summary style={{ cursor: "pointer", fontSize: 12, fontWeight: 600, padding: "3px 0" }}>{t(`lib.g.${g}` as TranslationKey)}</summary>
<div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fill, minmax(72px, 1fr))", gap: 4, padding: "4px 0" }}>
{catalog.objects
.filter((o) => o.group === g)
.map((o) => {
const name = t(`lib.o.${o.id.replace(/^lib:/, "")}` as TranslationKey);
return (
<button
key={o.id}
type="button"
title={name}
aria-label={name}
onClick={() => place(o)}
style={{
display: "flex",
flexDirection: "column",
alignItems: "center",
gap: 2,
padding: "4px 2px",
border: "1px solid var(--border)",
borderRadius: 4,
background: "var(--field-bg)",
color: "var(--ink)",
cursor: "pointer",
font: "inherit",
}}
>
<Preview def={o} />
<span style={{ fontSize: 10, lineHeight: 1.15, textAlign: "center", overflowWrap: "anywhere" }}>{name}</span>
</button>
);
})}
</div>
</details>
))}
</div>
);
}
/** Tab-Symbol: Stuhl in der Draufsicht. */
export function ObjectLibraryTabIcon() {
return (
<svg width={16} height={16} viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth={1.4} strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" focusable="false">
<rect x="3" y="3" width="10" height="10" rx="1" />
<path d="M3 6h10" />
</svg>
);
}
+1
View File
@@ -28,6 +28,7 @@ Kern; hier stehen Eingabe und Darstellung. Zustand über den Store (`src/state`)
| `SitePanel.tsx` | Aktionen zu Gelände und Lage (Import, Gelände erzeugen, Baugrube; keine Import-Liste, [181]), mit `SiteRulesSection.tsx` (Baurecht), `SunStudySection.tsx` (Schatten) und `PointCloudSection.tsx` |
| `BcfPanel.tsx`, `ClashPanel.tsx` | BCF-Themen und Kollisionsliste; Sitzungszustand in `bcfSession.ts` und `clashSession.ts` |
| `HistoryPanel.tsx` | Undo-Verlauf mit Sprung auf einen Schritt |
| `ObjectLibraryPanel.tsx` | Palette „Objekte" ([253]): Standard-Symbole 2D nach Gruppen, Klick startet den Befehl `libobj`; Parameter später in `objectInfo/LibObjectSection.tsx` |
## Reine Helfer
+11
View File
@@ -24,6 +24,7 @@ import { SitePanel } from "./SitePanel";
import { RoomBalancePanel } from "./RoomBalancePanel";
import { ElementTreePanel, ElementsTabIcon } from "./ElementTreePanel";
import { ViewSnapshotsPanel, ViewSnapshotsTabIcon } from "./ViewSnapshotsPanel";
import { ObjectLibraryPanel, ObjectLibraryTabIcon } from "./ObjectLibraryPanel";
import { LayoutsPanel, LayoutsTabIcon } from "./LayoutsPanel";
import { BcfPanel } from "./BcfPanel";
import { ClashPanel } from "./ClashPanel";
@@ -57,6 +58,7 @@ export const BUILTIN_PANEL_IDS = {
clash: "clash",
history: "history",
objectSettings: "object-settings",
objectLibrary: "object-library",
} as const;
// Werkzeug-Palette (Symbol + Name je Werkzeug, ArchiCAD/Vectorworks-Stil).
@@ -68,6 +70,15 @@ registerPanel({
render: () => <ToolsPanel />,
});
// Objekt-Bibliothek 2D ([253]): Palette der Standard-Symbole (Sanitär, Küche, Möbel …) zum Einsetzen.
registerPanel({
id: BUILTIN_PANEL_IDS.objectLibrary,
title: "nav.objects",
icon: <ObjectLibraryTabIcon />,
hasDisplayMode: false,
render: () => <ObjectLibraryPanel />,
});
// Attribute-Palette (Stift/Füllung/Strichstärke der Auswahl, Vectorworks-Stil).
registerPanel({
id: BUILTIN_PANEL_IDS.attributes,
+3 -2
View File
@@ -45,7 +45,8 @@ import type {
// Attribute darunter (Vectorworks-Bild aus v6, vor dem Ribbon-UI-Phase-3-Bump).
// v13 ([238]): rechts oben (Objekt-Info/Flächenbilanz) bekommt mehr Höhe: Gewichte 1,6 : 1 statt 1 : 1,5 (die
// Flächenbilanz mit Raumprogramm war nur ~300 px hoch). Die Höhe merkt sich der Gruppen-Splitter (`resizeGroups`).
export const LAYOUT_VERSION = 13;
// v14 ([253]): Objekt-Bibliothek ("object-library") als Tab neben den Werkzeugen links oben.
export const LAYOUT_VERSION = 14;
/** localStorage-Schlüssel des zuletzt benutzten Layouts. */
const CURRENT_KEY = "cad.layout";
@@ -73,7 +74,7 @@ const NAMED_PREFIX = "cad.layouts.";
// der Attribute-Palette darunter (Vectorworks-Bild). Das Ribbon-Band bleibt als
// Reiter erreichbar, ist aber nicht mehr der primäre Weg zu den Werkzeugen.
const DEFAULT_LEFT_GROUPS: DockGroup[] = [
{ tabs: ["tools"], activeTab: "tools", weight: 1 },
{ tabs: ["tools", "object-library"], activeTab: "tools", weight: 1 },
{ tabs: ["attributes"], activeTab: "attributes", weight: 1 },
];
const DEFAULT_RIGHT_GROUPS: DockGroup[] = [
@@ -0,0 +1,95 @@
// Objekt-Info eines Bibliotheks-Objekts ([253], `Drawing2DGeom.shape === "libobj"`): die Felder entstehen generisch
// aus der Parameterliste des Katalogs (Länge, Anzahl, Ja/Nein, Anteil) — kein Formular je Objekt, damit eigene
// Objekte [254] ohne Änderung hier dazukommen. Änderungen laufen als Ops über `updateDrawing2D` (ein Undo-Schritt je
// Eingabe). Unbekannte Objekt-Id: nur ein Hinweis (die Plandarstellung zeigt einen Platzhalter-Rahmen).
import { t } from "../../i18n";
import type { TranslationKey } from "../../i18n";
import { useStore } from "../../state/appStore";
import type { Drawing2D } from "../../model/types";
import { libDefaultParams, libObjectDef, type LibObjectDef, type LibParamDef, type LibParams } from "../../model/furnitureLib";
import { DimensionField } from "./fields";
type LibGeom = Extract<Drawing2D["geom"], { shape: "libobj" }>;
/** Beschriftung eines Parameters; je Gruppe/Form spezifischer (Stühle, Module, Durchmesser). */
function paramLabel(def: LibObjectDef, p: LibParamDef): TranslationKey {
if (p.key === "n" && def.group === "kitchen") return "lib.p.n.kitchen";
if (p.key === "n" && def.group === "tables") return "lib.p.n.tables";
if (p.key === "w" && !def.params.some((q) => q.key === "d")) return "lib.p.diameter";
return `lib.p.${p.key}` as TranslationKey;
}
export function LibObjectSection({ drawing, geom }: { drawing: Drawing2D; geom: LibGeom }) {
const update = useStore((s) => s.updateDrawing2D);
const def = libObjectDef(geom.libId);
if (!def) {
return (
<div className="objinfo-field">
<span className="objinfo-fval objinfo-muted">
{t("lib.unknown")}: {geom.libId}
</span>
</div>
);
}
const values: LibParams = { ...libDefaultParams(def), ...(geom.params ?? {}) };
const set = (key: string, v: number | boolean) => update(drawing.id, { geom: { ...geom, params: { ...(geom.params ?? {}), [key]: v } } });
const name = t(`lib.o.${def.id.replace(/^lib:/, "")}` as TranslationKey);
return (
<div data-testid="libobj-section">
<div className="objinfo-field">
<span className="objinfo-flabel">{t("lib.section")}</span>
<span className="objinfo-fval">{name}</span>
</div>
{def.params.map((p) => {
const label = t(paramLabel(def, p));
const v = values[p.key];
if (p.kind === "length") {
return <DimensionField key={p.key} label={label} value={Number(v)} min={p.min} step={p.step} digits={3} onCommit={(x) => set(p.key, Math.min(p.max, Math.max(p.min, x)))} />;
}
if (p.kind === "flag") {
return (
<label className="objinfo-field" key={p.key}>
<span className="objinfo-flabel">{label}</span>
<input type="checkbox" checked={v === true || Number(v) >= 0.5} onChange={(e) => set(p.key, e.target.checked)} />
</label>
);
}
if (p.kind === "fraction") {
return (
<label className="objinfo-field" key={p.key}>
<span className="objinfo-flabel">{label}</span>
<input type="range" min={p.min} max={p.max} step={p.step} value={Number(v)} onChange={(e) => set(p.key, Number(e.target.value))} />
<span className="objinfo-unit">{Math.round(Number(v) * 100)} %</span>
</label>
);
}
return (
<label className="objinfo-field" key={p.key}>
<span className="objinfo-flabel">{label}</span>
<input
className="objinfo-input"
type="number"
min={p.min}
max={p.max}
step={p.step}
value={Number(v)}
onChange={(e) => {
const x = Math.round(Number(e.target.value));
if (Number.isFinite(x)) set(p.key, Math.min(p.max, Math.max(p.min, x)));
}}
/>
</label>
);
})}
{def.seeded && (
<div className="objinfo-field">
<button type="button" className="objinfo-btn" onClick={() => update(drawing.id, { geom: { ...geom, seed: (Math.random() * 0xffffffff) >>> 0 } })}>
{t("lib.reroll")}
</button>
</div>
)}
</div>
);
}