Merge branch 'worktree-agent-acb89ec95d3f38809' into claude/practical-noether-1hb2s1
# Conflicts: # TODO.md
This commit is contained in:
14 files changed
+2880
-2
No files matched your search
+25
-1
@@ -26,6 +26,9 @@
|
||||
// Bauteile ([B4]); Bericht als JSON auf stdout
|
||||
// dossier-cli <projekt.obp> import-mesh <datei.obj|stl|gltf|glb|ply> [--out neu.obp] [--unit mm|cm|m|inch|foot] [--up z|y|auto]
|
||||
// [--placement center|original] 3D-Modell als Kontext-Meshes; Bericht als JSON
|
||||
// dossier-cli <projekt.obp> erkennen [--level EG] [--source ebene] [--out neu.obp]
|
||||
// [154] Bauteile aus 2D-Zeichnung erkennen (Wände, Öffnungen, Räume
|
||||
// ins Geschoss); Bericht als JSON. Z. B. convert plan.dxf p.obp --cmd "erkennen --out e.obp"
|
||||
// dossier-cli <projekt.obp> model3d [--explode 3] [--out modell.json] 3D-Modell fürs Headless-Rendern (render_png)
|
||||
// dossier-cli pointcloud-info <datei.las|laz|e57|ply|xyz|pts> [--voxel 0.05] [--max 2000000]
|
||||
// Punktwolke lesen ([B9]) und Bericht als JSON (ohne Projekt)
|
||||
@@ -119,6 +122,9 @@ import {
|
||||
withDocument,
|
||||
AI_BRIDGE_DEFAULT_PORT,
|
||||
standardOverrideRules,
|
||||
recognizeMutation,
|
||||
recognizeReport,
|
||||
recognizeSourceLevels,
|
||||
} from "../core";
|
||||
import type { Project } from "../core";
|
||||
import { serveStdio } from "./mcp";
|
||||
@@ -363,7 +369,7 @@ export async function run(argv: string[]): Promise<number> {
|
||||
if (file === "mcp" && args.flags.has("app")) return runAppBridge(args);
|
||||
if (!file || (!command && args.cmds.length === 0)) {
|
||||
process.stderr.write(
|
||||
"Aufruf: dossier-cli <projekt.obp> <info|validate|migrate|plan|section|elevation|dxf|dwg|ifc|import-ifc|import-mesh|step|obj|stl|glb|gltf|schedule|kennzahlen|raumprogramm|sun|model3d> [Optionen]\n" +
|
||||
"Aufruf: dossier-cli <projekt.obp> <info|validate|migrate|plan|section|elevation|dxf|dwg|ifc|import-ifc|import-mesh|erkennen|step|obj|stl|glb|gltf|schedule|kennzahlen|raumprogramm|sun|model3d> [Optionen]\n" +
|
||||
" dossier-cli convert <eingabe.dxf|dwg|ifc|pdf|obj|stl|gltf|glb|ply|obp> <ausgabe.obp|dxf|dwg|ifc|obj|stl|glb|gltf|step> [--cmd \"befehl …\"]…\n" +
|
||||
" dossier-cli <projekt.obp> --cmd \"befehl …\" [--cmd …] ({last} = zuletzt geschriebene Datei)\n" +
|
||||
" dossier-cli pointcloud-info <datei> [--voxel 0.05] [--max 2000000]\n" +
|
||||
@@ -872,6 +878,24 @@ async function execute(project: Project, file: string, command: string, rest: st
|
||||
if (target) out(args, serializeProject(r.next), target);
|
||||
return 0;
|
||||
}
|
||||
case "erkennen": {
|
||||
// [154] Quelle: --source (Ebene, id oder Name), sonst die Zeichnung des Geschosses, sonst die erste Ebene mit Zeichnung.
|
||||
const lvl = findLevel(project, ["floor"], args.flags.get("level"));
|
||||
if (!lvl) fail("Geschoss nicht gefunden");
|
||||
const sources = recognizeSourceLevels(project);
|
||||
const want = args.flags.get("source")?.toLowerCase();
|
||||
const src = want
|
||||
? project.drawingLevels.find((l) => l.id.toLowerCase() === want || l.name.toLowerCase() === want)?.id
|
||||
: sources.includes(lvl.id)
|
||||
? lvl.id
|
||||
: sources[0];
|
||||
if (!src) fail("erkennen: keine 2D-Zeichnung (--source)");
|
||||
const opts = { levelId: lvl.id, floorHeight: lvl.floorHeight, sourceLevelId: src, wallTypeId: project.wallTypes[0]?.id, typeName: "Wand {cm} cm (erkannt)" };
|
||||
process.stdout.write(JSON.stringify(recognizeReport(project, opts), null, 2) + "\n");
|
||||
const target = args.flags.get("out");
|
||||
if (target) out(args, serializeProject(recognizeMutation(opts)(project)), target);
|
||||
return 0;
|
||||
}
|
||||
case "import-mesh": {
|
||||
const src = rest[0];
|
||||
if (!src) fail("import-mesh: Modelldatei fehlt");
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
/** `recognizeCommand` ([154]): Vorschau + Zähler beim Start, Bericht (B), Quelle (E), Enter = ein Commit. */
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { recognizeCommand, reportText } from "./recognize";
|
||||
import { resolveCommand } from "../registry";
|
||||
import type { CommandContext, Project } from "../types";
|
||||
import type { Drawing2D } from "../../model/types";
|
||||
|
||||
const poly = (id: string, code: string, pts: [number, number][], level = "imp"): Drawing2D =>
|
||||
({ id, type: "drawing2d", levelId: level, categoryCode: code, geom: { shape: "polyline", closed: true, pts: pts.map(([x, y]) => ({ x, y })) } }) as Drawing2D;
|
||||
|
||||
/** Raum 5 × 4 (Achsen), Aussenwände 30 cm, Innenwand 15 cm, Tür mit Bogen, Raumtext — auf einer Zeichnungsebene. */
|
||||
function project(): Project {
|
||||
return {
|
||||
id: "t", name: "T", lineStyles: [], hatches: [],
|
||||
components: [{ id: "brick", name: "Mauerwerk", color: "#a0522d" }] as Project["components"],
|
||||
wallTypes: [{ id: "aw", name: "Aussenwand 30", layers: [{ componentId: "brick", thickness: 0.3 }] }],
|
||||
drawingLevels: [
|
||||
{ id: "eg", name: "EG", kind: "floor", visible: true, locked: false, floorHeight: 2.8, cutHeight: 1.0, baseElevation: 0 },
|
||||
{ id: "imp", name: "Import", kind: "drawing", visible: true, locked: false },
|
||||
],
|
||||
layers: [
|
||||
{ code: "20", name: "Wände", color: "#000000", lw: 0.5, visible: true, locked: false },
|
||||
{ code: "101", name: "A-WALL", color: "#000000", lw: 0.5, visible: true, locked: false },
|
||||
{ code: "102", name: "A-DOOR", color: "#000000", lw: 0.25, visible: true, locked: false },
|
||||
],
|
||||
walls: [], openings: [], ceilings: [], stairs: [], rooms: [], context: [],
|
||||
drawings2d: [
|
||||
poly("o", "101", [[-0.15, -0.15], [1, -0.15], [1, 0.15], [0.15, 0.15], [0.15, 3.85], [4.85, 3.85], [4.85, 0.15], [1.9, 0.15], [1.9, -0.15], [5.15, -0.15], [5.15, 4.15], [-0.15, 4.15]]),
|
||||
poly("i", "101", [[2.425, 0.15], [2.575, 0.15], [2.575, 3.85], [2.425, 3.85]]),
|
||||
{ id: "arc", type: "drawing2d", levelId: "imp", categoryCode: "102", geom: { shape: "arc", center: { x: 1, y: 0 }, r: 0.9, a0: 0, a1: Math.PI / 2 } } as Drawing2D,
|
||||
{ id: "t1", type: "drawing2d", levelId: "imp", categoryCode: "102", geom: { shape: "text", at: { x: 0.5, y: 2 }, text: "Wohnen", height: 0.35, angle: 0 } } as Drawing2D,
|
||||
],
|
||||
} as Project;
|
||||
}
|
||||
|
||||
const ctxOf = (p: Project, drawingIds: string[] = []): CommandContext =>
|
||||
({ project: p, level: p.drawingLevels[0], defaultCategoryCode: "20", activeLineStyleId: "solid", activeWallTypeId: "aw", lastPoint: null, selection: { wallIds: [], drawingId: null, drawingIds } }) as CommandContext;
|
||||
|
||||
describe("recognizeCommand", () => {
|
||||
it("Name und Kürzel", () => {
|
||||
expect(resolveCommand("erkennen")?.name).toBe("erkennen");
|
||||
expect(resolveCommand("bauteileerkennen")?.name).toBe("erkennen");
|
||||
});
|
||||
|
||||
it("Start: Vorschau und Zähler aus der Zeichnungsebene, Enter übernimmt als ein Commit", () => {
|
||||
const p = project();
|
||||
const ctx = ctxOf(p);
|
||||
const start = recognizeCommand.autoRun!(ctx);
|
||||
expect(start.done).toBeFalsy();
|
||||
expect(start.draft?.preview.length).toBeGreaterThan(5);
|
||||
expect(start.notice?.key).toBe("cmd.recognize.summary");
|
||||
expect(start.notice?.params).toMatchObject({ walls: 5, doors: 1, windows: 0, voids: 0, rooms: 2 });
|
||||
const [, mv] = recognizeCommand.onMove(recognizeCommand.init(), { x: 1, y: 1 }, null, ctx);
|
||||
expect(mv.draft?.hud?.text).toContain("5");
|
||||
const [, r] = recognizeCommand.onConfirm(recognizeCommand.init(), ctx);
|
||||
expect(r.done).toBe(true);
|
||||
const next = r.commit!(p);
|
||||
expect(next.walls.length).toBe(5);
|
||||
expect(next.walls.every((w) => w.floorId === "eg" && w.height === 2.8)).toBe(true);
|
||||
expect(next.walls.filter((w) => w.wallTypeId === "aw").length).toBe(4);
|
||||
expect(next.wallTypes.length).toBe(2);
|
||||
expect(next.openings?.length).toBe(1);
|
||||
expect(next.openings?.[0].kind).toBe("door");
|
||||
expect(next.rooms?.map((x) => x.name).filter((n) => n === "Wohnen" || /^Raum \d$/.test(n)).length).toBe(2);
|
||||
});
|
||||
|
||||
it("Auswahl: nur die gewählten Elemente", () => {
|
||||
const p = project();
|
||||
const r = recognizeCommand.autoRun!(ctxOf(p, ["i"]));
|
||||
expect(r.notice?.params).toMatchObject({ walls: 1, doors: 0, rooms: 0 });
|
||||
});
|
||||
|
||||
it("Bericht (B) und Quelle (E)", () => {
|
||||
const p = project();
|
||||
const ctx = ctxOf(p);
|
||||
const [, rep] = recognizeCommand.onInput(recognizeCommand.init(), { kind: "option", id: "report" }, ctx);
|
||||
expect(rep.notice?.key).toBe("cmd.recognize.reportNotice");
|
||||
expect(String(rep.notice?.params?.text)).toMatch(/30|15/);
|
||||
const [s1] = recognizeCommand.onInput(recognizeCommand.init(), { kind: "option", id: "source" }, ctx);
|
||||
expect(recognizeCommand.options(s1)[0].value).toBe("Import");
|
||||
});
|
||||
|
||||
it("Bericht-Text zählt unklare Stellen je Grund", () => {
|
||||
const txt = reportText({
|
||||
walls: 1, doors: 0, windows: 0, voids: 0, rooms: 0, arcWalls: 0, filledWalls: 0, unnamedRooms: 0, thicknesses: [0.3], layerFilter: true,
|
||||
unclear: [{ code: "doorArc", x: 0, y: 0 }, { code: "doorArc", x: 1, y: 0 }, { code: "gapWide", x: 0, y: 0 }],
|
||||
});
|
||||
expect(txt).toContain("2×");
|
||||
expect(txt).toContain("1×");
|
||||
});
|
||||
|
||||
it("ohne Zeichnung: Vorbedingung meldet, nichts erkannt → kein Commit", () => {
|
||||
const p = { ...project(), drawings2d: [] };
|
||||
expect(recognizeCommand.precondition!(ctxOf(p))).toBe("cmd.recognize.noDrawing");
|
||||
const p2 = { ...project(), drawings2d: project().drawings2d.slice(3) };
|
||||
const [, r] = recognizeCommand.onConfirm(recognizeCommand.init(), ctxOf(p2));
|
||||
expect(r.commit).toBeUndefined();
|
||||
expect(r.notice?.key).toBe("cmd.recognize.nothing");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,146 @@
|
||||
// [154] Bauteile aus Zeichnung erkennen: aus den 2D-Linien eines Grundrisses (DXF/DWG-Import aus ArchiCAD,
|
||||
// Vectorworks, AutoCAD) Wände, Öffnungen und Räume. Quelle: die gewählten 2D-Elemente, sonst die Zeichnung des
|
||||
// aktiven Geschosses, sonst die erste Ebene mit Zeichnung (Option E schaltet durch). Beim Start zeigt die Vorschau
|
||||
// alles Erkannte (Wandbänder, Türen/Fenster/Durchbrüche, Räume, unklare Stellen als Kreuz), die Meldung zählt;
|
||||
// B zeigt den Bericht (unklar, mit Grund). Enter übernimmt als EIN Undo-Schritt ins aktive Geschoss (Höhe =
|
||||
// Geschosshöhe). Die Erkennung rechnet der Kern (`drawing_recognize.rs`).
|
||||
|
||||
import type { CmdOption, Command, CommandContext, CommandResult, CommandState, ToolDraft, Vec2 } from "../types";
|
||||
import { createPreview } from "../createCore";
|
||||
import { t, type TranslationKey } from "../../i18n";
|
||||
import { recognizeMutation, recognizeReport, recognizeSourceLevels } from "../../core";
|
||||
import type { RecognizeOptions, RecognizeReport } from "../../core";
|
||||
|
||||
interface RecognizeState extends CommandState {
|
||||
/** Gewählte Quell-Ebene (Option E) und ihr Name für die Befehlszeile. */
|
||||
sticky: { src?: string; name?: string };
|
||||
}
|
||||
|
||||
const selectedIds = (ctx: CommandContext): string[] =>
|
||||
ctx.selection.drawingIds ?? (ctx.selection.drawingId ? [ctx.selection.drawingId] : []);
|
||||
|
||||
/** Quell-Ebene: gewählt, sonst das aktive Geschoss (hat es Zeichnung), sonst die erste Zeichnungsebene. */
|
||||
function sourceOf(s: RecognizeState, ctx: CommandContext): string {
|
||||
const list = recognizeSourceLevels(ctx.project);
|
||||
if (s.sticky?.src && list.includes(s.sticky.src)) return s.sticky.src;
|
||||
if (list.includes(ctx.level.id)) return ctx.level.id;
|
||||
const drawing = list.find((id) => ctx.project.drawingLevels.find((l) => l.id === id)?.kind === "drawing");
|
||||
return drawing ?? list[0] ?? ctx.level.id;
|
||||
}
|
||||
|
||||
function optionsOf(s: RecognizeState, ctx: CommandContext): RecognizeOptions {
|
||||
return {
|
||||
levelId: ctx.level.id,
|
||||
floorHeight: ctx.level.floorHeight,
|
||||
sourceLevelId: sourceOf(s, ctx),
|
||||
ids: selectedIds(ctx),
|
||||
categoryCode: ctx.defaultCategoryCode,
|
||||
wallTypeId: ctx.activeWallTypeId,
|
||||
typeName: t("cmd.recognize.typeName"),
|
||||
roomName: t("cmd.recognize.roomName"),
|
||||
};
|
||||
}
|
||||
|
||||
interface Evaluated {
|
||||
report: RecognizeReport;
|
||||
draft: ToolDraft;
|
||||
}
|
||||
|
||||
// Je Mausschritt dieselbe Erkennung: gemerkt je Projektstand und Anfrage.
|
||||
let cache: { project: unknown; key: string; value: Evaluated } | null = null;
|
||||
|
||||
function evaluate(s: RecognizeState, ctx: CommandContext): Evaluated {
|
||||
const o = optionsOf(s, ctx);
|
||||
const key = JSON.stringify(o);
|
||||
if (cache && cache.project === ctx.project && cache.key === key) return cache.value;
|
||||
const report = recognizeReport(ctx.project, o);
|
||||
const pv = createPreview(ctx, { cmd: "recognize", src: o.sourceLevelId, ids: o.ids, typeName: o.typeName, roomName: o.roomName }, []);
|
||||
const value = { report, draft: { preview: pv.shapes, vertices: [] } };
|
||||
cache = { project: ctx.project, key, value };
|
||||
return value;
|
||||
}
|
||||
|
||||
const countParams = (r: RecognizeReport) => ({
|
||||
walls: r.walls,
|
||||
doors: r.doors,
|
||||
windows: r.windows,
|
||||
voids: r.voids,
|
||||
rooms: r.rooms,
|
||||
unclear: r.unclear.length,
|
||||
});
|
||||
|
||||
/** Kurzzeile am Cursor. */
|
||||
const hudText = (r: RecognizeReport): string => t("cmd.recognize.hud", countParams(r));
|
||||
|
||||
/** Bericht: unklare Stellen je Grund gezählt. */
|
||||
export function reportText(r: RecognizeReport): string {
|
||||
const by = new Map<string, number>();
|
||||
for (const u of r.unclear) by.set(u.code, (by.get(u.code) ?? 0) + 1);
|
||||
const parts = [...by].map(([code, n]) => `${n}× ${t(`cmd.recognize.reason.${code}` as TranslationKey)}`);
|
||||
const thick = r.thicknesses.map((x) => `${Math.round(x * 1000) / 10}`).join(" / ");
|
||||
const head = t("cmd.recognize.reportHead", { thick: thick || "—", filled: r.filledWalls, arcs: r.arcWalls, unnamed: r.unnamedRooms });
|
||||
const filter = r.layerFilter ? ` ${t("cmd.recognize.layerFilter")}` : "";
|
||||
return parts.length ? `${head}${filter} ${t("cmd.recognize.unclearList", { list: parts.join("; ") })}` : `${head}${filter} ${t("cmd.recognize.noUnclear")}`;
|
||||
}
|
||||
|
||||
function show(s: RecognizeState, ctx: CommandContext): CommandResult {
|
||||
const { report, draft } = evaluate(s, ctx);
|
||||
if (report.walls === 0) return { draft: null, notice: { key: "cmd.recognize.nothing", kind: "warning" } };
|
||||
return { draft, notice: { key: "cmd.recognize.summary", params: countParams(report), kind: "info" } };
|
||||
}
|
||||
|
||||
const done = (): [CommandState, CommandResult] => [{ phase: "confirm", lastPoint: null }, { draft: null, done: true }];
|
||||
|
||||
export const recognizeCommand: Command = {
|
||||
name: "erkennen",
|
||||
labelKey: "cmd.recognize.label",
|
||||
floorOnly: true,
|
||||
prompt: () => "cmd.recognize.prompt",
|
||||
accepts: () => ["option"],
|
||||
options: (state): CmdOption[] => {
|
||||
const s = state as RecognizeState;
|
||||
return [
|
||||
{ id: "source", labelKey: "cmd.recognize.source", key: "E", value: s.sticky?.name ?? t("cmd.recognize.sourceAuto") },
|
||||
{ id: "report", labelKey: "cmd.recognize.report", key: "B" },
|
||||
];
|
||||
},
|
||||
precondition: (ctx) => (recognizeSourceLevels(ctx.project).length === 0 && selectedIds(ctx).length === 0 ? "cmd.recognize.noDrawing" : null),
|
||||
init: (): RecognizeState => ({ phase: "confirm", lastPoint: null, sticky: {} }),
|
||||
|
||||
autoRun: (ctx) => show({ phase: "confirm", lastPoint: null, sticky: {} }, ctx),
|
||||
|
||||
onInput: (state, input, ctx): [CommandState, CommandResult] => {
|
||||
const s = state as RecognizeState;
|
||||
if (input.kind === "option" && input.id === "source") {
|
||||
const list = recognizeSourceLevels(ctx.project);
|
||||
const cur = sourceOf(s, ctx);
|
||||
const next = list[(list.indexOf(cur) + 1) % Math.max(1, list.length)] ?? cur;
|
||||
const name = ctx.project.drawingLevels.find((l) => l.id === next)?.name;
|
||||
const ns: RecognizeState = { ...s, sticky: { src: next, name } };
|
||||
return [ns, show(ns, ctx)];
|
||||
}
|
||||
if (input.kind === "option" && input.id === "report") {
|
||||
const { report, draft } = evaluate(s, ctx);
|
||||
return [s, { draft, notice: { key: "cmd.recognize.reportNotice", params: { text: reportText(report) }, kind: "info" } }];
|
||||
}
|
||||
return [s, { draft: evaluate(s, ctx).draft }];
|
||||
},
|
||||
|
||||
onMove: (state, point: Vec2, _snap, ctx): [CommandState, CommandResult] => {
|
||||
const { report, draft } = evaluate(state as RecognizeState, ctx);
|
||||
return [state, { draft: { ...draft, hud: { at: point, text: hudText(report) } } }];
|
||||
},
|
||||
|
||||
onConfirm: (state, ctx): [CommandState, CommandResult] => {
|
||||
const s = state as RecognizeState;
|
||||
const { report } = evaluate(s, ctx);
|
||||
cache = null;
|
||||
if (report.walls === 0) return [s, { draft: null, done: true, notice: { key: "cmd.recognize.nothing", kind: "warning" } }];
|
||||
const commit = recognizeMutation(optionsOf(s, ctx));
|
||||
return [{ phase: "confirm", lastPoint: null }, { draft: null, done: true, commit, notice: { key: "cmd.recognize.done", params: countParams(report), kind: "info" } }];
|
||||
},
|
||||
onCancel: () => {
|
||||
cache = null;
|
||||
return done();
|
||||
},
|
||||
};
|
||||
@@ -37,6 +37,7 @@ import { scalebarCommand } from "./cmds/scalebar";
|
||||
import { revcloudCommand } from "./cmds/revcloud";
|
||||
import { pointmarkerCommand } from "./cmds/pointmarker";
|
||||
import { wandCommand } from "./cmds/wand";
|
||||
import { recognizeCommand } from "./cmds/recognize";
|
||||
import { wipeoutCommand } from "./cmds/wipeout";
|
||||
import { textCommand } from "./cmds/text";
|
||||
import { leaderCommand } from "./cmds/leader";
|
||||
@@ -112,6 +113,7 @@ export const COMMANDS: Record<string, Command> = {
|
||||
revcloud: revcloudCommand,
|
||||
pointmarker: pointmarkerCommand,
|
||||
zauberstab: wandCommand,
|
||||
erkennen: recognizeCommand,
|
||||
wipeout: wipeoutCommand,
|
||||
text: textCommand,
|
||||
leader: leaderCommand,
|
||||
@@ -234,6 +236,8 @@ export const ALIASES: Record<string, string> = {
|
||||
revisionswolke: "revcloud",
|
||||
pm: "pointmarker",
|
||||
zs: "zauberstab",
|
||||
bauteileerkennen: "erkennen",
|
||||
recognize: "erkennen",
|
||||
punkt: "pointmarker",
|
||||
knoten: "pointmarker",
|
||||
wo: "wipeout",
|
||||
|
||||
@@ -88,3 +88,5 @@ export { lineEndsOf, lineEndsCode, lineEndsFromCode, lineEndsSvgAttrs, planLineE
|
||||
export type { LineEnds } from "../model/lineEnds";
|
||||
export type { LineCap, LineJoin } from "../model/types";
|
||||
export { standardOverrideRules } from "../model/standards";
|
||||
export { recognizeMutation, recognizeReport, recognizeSourceLevels } from "../io/recognizeDrawing";
|
||||
export type { RecognizeOptions, RecognizeReport, RecognizeUnclear } from "../io/recognizeDrawing";
|
||||
@@ -1962,6 +1962,30 @@ export const de = {
|
||||
"cmd.wand.label": "Zauberstab",
|
||||
"cmd.wand.point": "In eine umschlossene Fläche klicken:",
|
||||
"cmd.wand.hatch": "Schraffur",
|
||||
"cmd.recognize.label": "Bauteile aus Zeichnung erkennen",
|
||||
"cmd.recognize.prompt": "Erkannte Bauteile übernehmen (Enter), Quelle wählen (E) oder Bericht (B):",
|
||||
"cmd.recognize.source": "Quelle",
|
||||
"cmd.recognize.sourceAuto": "automatisch",
|
||||
"cmd.recognize.report": "Bericht",
|
||||
"cmd.recognize.typeName": "Wand {cm} cm (erkannt)",
|
||||
"cmd.recognize.roomName": "Raum {n}",
|
||||
"cmd.recognize.hud": "{walls} Wände · {doors} Türen · {windows} Fenster · {voids} Durchbrüche · {rooms} Räume · {unclear} unklar",
|
||||
"cmd.recognize.summary": "Erkannt: {walls} Wände, {doors} Türen, {windows} Fenster, {voids} Durchbrüche, {rooms} Räume; unklar: {unclear}. Enter übernimmt, B zeigt den Bericht.",
|
||||
"cmd.recognize.done": "Übernommen: {walls} Wände, {doors} Türen, {windows} Fenster, {voids} Durchbrüche, {rooms} Räume (ein Rückgängig-Schritt).",
|
||||
"cmd.recognize.nothing": "Keine Wände erkannt (parallele Linien im Abstand 5–60 cm).",
|
||||
"cmd.recognize.noDrawing": "Keine 2D-Zeichnung vorhanden – zuerst einen Grundriss (DXF/DWG) importieren.",
|
||||
"cmd.recognize.reportNotice": "{text}",
|
||||
"cmd.recognize.reportHead": "Wanddicken (cm): {thick}; mit Füllung bestätigt: {filled}; Bogenwände: {arcs}; Räume ohne Namen: {unnamed}.",
|
||||
"cmd.recognize.layerFilter": "Nur Linien auf Wand-Layern verwendet.",
|
||||
"cmd.recognize.unclearList": "Unklar: {list}.",
|
||||
"cmd.recognize.noUnclear": "Nichts unklar.",
|
||||
"cmd.recognize.reason.areaMismatch": "Flächenangabe weicht > 5 % vom Raum ab",
|
||||
"cmd.recognize.reason.areaOutside": "Flächenangabe ausserhalb eines erkannten Raums",
|
||||
"cmd.recognize.reason.lineUnpaired": "Wandlinie ohne Gegenlinie",
|
||||
"cmd.recognize.reason.doorArc": "Türbogen ohne Wandlücke",
|
||||
"cmd.recognize.reason.doorHalf": "halber Türbogen ohne Gegenflügel (als einflüglig angelegt)",
|
||||
"cmd.recognize.reason.gapWide": "Lücke über 1.5 m ohne Tür/Fenster (nicht angelegt)",
|
||||
"cmd.recognize.reason.tooMany": "zu viele Linien (über 60 000) – Auswahl verkleinern",
|
||||
"cmd.grid.label": "Achsraster",
|
||||
"cmd.grid.origin": "Ursprung des Achsrasters ( Radial ):",
|
||||
"cmd.grid.radial": "Radial",
|
||||
|
||||
@@ -1951,6 +1951,30 @@ export const en: Record<TranslationKey, string> = {
|
||||
"cmd.wand.label": "Magic wand",
|
||||
"cmd.wand.point": "Click inside an enclosed area:",
|
||||
"cmd.wand.hatch": "Hatch",
|
||||
"cmd.recognize.label": "Recognize elements from drawing",
|
||||
"cmd.recognize.prompt": "Accept recognized elements (Enter), choose source (E) or report (B):",
|
||||
"cmd.recognize.source": "Source",
|
||||
"cmd.recognize.sourceAuto": "automatic",
|
||||
"cmd.recognize.report": "Report",
|
||||
"cmd.recognize.typeName": "Wall {cm} cm (recognized)",
|
||||
"cmd.recognize.roomName": "Room {n}",
|
||||
"cmd.recognize.hud": "{walls} walls · {doors} doors · {windows} windows · {voids} openings · {rooms} rooms · {unclear} unclear",
|
||||
"cmd.recognize.summary": "Recognized: {walls} walls, {doors} doors, {windows} windows, {voids} wall openings, {rooms} rooms; unclear: {unclear}. Enter accepts, B shows the report.",
|
||||
"cmd.recognize.done": "Added: {walls} walls, {doors} doors, {windows} windows, {voids} wall openings, {rooms} rooms (one undo step).",
|
||||
"cmd.recognize.nothing": "No walls recognized (parallel lines 5–60 cm apart).",
|
||||
"cmd.recognize.noDrawing": "No 2D drawing – import a floor plan (DXF/DWG) first.",
|
||||
"cmd.recognize.reportNotice": "{text}",
|
||||
"cmd.recognize.reportHead": "Wall thicknesses (cm): {thick}; confirmed by fill: {filled}; curved walls: {arcs}; rooms without name: {unnamed}.",
|
||||
"cmd.recognize.layerFilter": "Only lines on wall layers used.",
|
||||
"cmd.recognize.unclearList": "Unclear: {list}.",
|
||||
"cmd.recognize.noUnclear": "Nothing unclear.",
|
||||
"cmd.recognize.reason.areaMismatch": "area label differs from the room by > 5 %",
|
||||
"cmd.recognize.reason.areaOutside": "area label outside any recognized room",
|
||||
"cmd.recognize.reason.lineUnpaired": "wall line without a parallel partner",
|
||||
"cmd.recognize.reason.doorArc": "door swing without a wall gap",
|
||||
"cmd.recognize.reason.doorHalf": "half door swing without a second leaf (created as single leaf)",
|
||||
"cmd.recognize.reason.gapWide": "gap over 1.5 m without door/window (not created)",
|
||||
"cmd.recognize.reason.tooMany": "too many lines (over 60,000) – narrow the selection",
|
||||
"cmd.grid.label": "Structural grid",
|
||||
"cmd.grid.origin": "Grid origin ( Radial ):",
|
||||
"cmd.grid.radial": "Radial",
|
||||
|
||||
@@ -0,0 +1,194 @@
|
||||
// [154] Rundreise: eigener DXF-Export eines Geschosses → DXF-Import (Layer als Kategorien, neue Zeichnungsebene)
|
||||
// → „Bauteile aus Zeichnung erkennen“ → Wände/Öffnungen mit dem Original vergleichen (Quote auf der Konsole).
|
||||
// Wände: Achse (beide Richtungen, ±1 cm) und Dicke (±1 mm); Öffnungen: Art und Pfosten (±2 cm), Türen zusätzlich
|
||||
// Scharnierpunkt und Aufschlagseite. Mit `DOSSIER_RECOGNIZE_OUT=<ordner>` werden Import und Ergebnis als .obp
|
||||
// geschrieben (Bilder für den Bericht).
|
||||
|
||||
import { writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import { loadFileioForTests } from "../engine/fileioWasm.testing";
|
||||
import { parseDxf } from "./dxfParser";
|
||||
import { buildPlanDxf } from "../export/exportDxf";
|
||||
import { generatePlan } from "../plan/generatePlan";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import { buildComplexSampleProject } from "../model/sampleProjectComplex";
|
||||
import { flattenCategories } from "../model/types";
|
||||
import type { Opening, Project, Vec2, Wall } from "../model/types";
|
||||
import { ProjectDocument } from "../core/document";
|
||||
import { bulgeArc } from "../geometry/bulge";
|
||||
import { serializeProject } from "./projectFormat";
|
||||
import { recognizeMutation, recognizeReport, type RecognizeReport } from "./recognizeDrawing";
|
||||
|
||||
const OUT = process.env.DOSSIER_RECOGNIZE_OUT;
|
||||
|
||||
const allCodes = (p: Project) => new Set(flattenCategories(p.layers).map((l) => l.code));
|
||||
const thickness = (p: Project, w: Wall) => (p.wallTypes.find((t) => t.id === w.wallTypeId)?.layers ?? []).reduce((s, l) => s + l.thickness, 0);
|
||||
const dist = (a: Vec2, b: Vec2) => Math.hypot(a.x - b.x, a.y - b.y);
|
||||
|
||||
interface Jambs {
|
||||
kind: "door" | "window" | "void";
|
||||
a: Vec2;
|
||||
b: Vec2;
|
||||
/** Tür: Scharnierpunkt und Aufschlagseite (Einheitsvektor quer zur Wand). */
|
||||
hinge?: Vec2;
|
||||
side?: Vec2;
|
||||
}
|
||||
|
||||
function jambs(p: Project, o: Opening): Jambs | null {
|
||||
const w = p.walls.find((x) => x.id === o.hostWallId);
|
||||
if (!w) return null;
|
||||
const l = dist(w.start, w.end);
|
||||
const u = { x: (w.end.x - w.start.x) / l, y: (w.end.y - w.start.y) / l };
|
||||
// Bogenwand: Lage als Bogenlänge auf der Achse ab `start`.
|
||||
const arc = w.bulge ? bulgeArc(w.start, w.end, w.bulge) : null;
|
||||
const at = (s: number) =>
|
||||
arc
|
||||
? { x: arc.center.x + arc.r * Math.cos(arc.a0 + Math.sign(arc.sweep) * (s / arc.r)), y: arc.center.y + arc.r * Math.sin(arc.a0 + Math.sign(arc.sweep) * (s / arc.r)) }
|
||||
: { x: w.start.x + u.x * s, y: w.start.y + u.y * s };
|
||||
const voidish = o.kind === "door" && (o.doorType === "wandoeffnung" || p.doorTypes?.find((t) => t.id === o.typeId)?.kind === "wandoeffnung");
|
||||
const kind = voidish ? "void" : o.kind;
|
||||
const j: Jambs = { kind, a: at(o.position), b: at(o.position + o.width) };
|
||||
if (kind === "door") {
|
||||
j.hinge = at(o.position + (o.hinge === "end" ? o.width : 0));
|
||||
const k = (o.swing === "right" ? -1 : 1) * (o.openingDir === "out" ? -1 : 1);
|
||||
j.side = { x: -u.y * k, y: u.x * k };
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
interface Quote {
|
||||
walls: [number, number];
|
||||
/** Achsen-Abdeckung 0…1. */
|
||||
axis: number;
|
||||
openings: [number, number];
|
||||
doors: [number, number];
|
||||
report: RecognizeReport;
|
||||
imported: Project;
|
||||
result: Project;
|
||||
}
|
||||
|
||||
/** Geschoss `levelId` von `orig` exportieren, in ein leeres Projekt mit denselben Typen importieren, erkennen. */
|
||||
function roundtrip(orig: Project, levelId: string): Quote {
|
||||
const plan = generatePlan(orig, levelId, allCodes(orig));
|
||||
const dxf = buildPlanDxf(plan, orig, { scaleDenominator: 100, levelId });
|
||||
const parsed = parseDxf(dxf);
|
||||
const base: Project = { ...orig, walls: [], openings: [], rooms: [], drawings2d: [], stairs: [], ceilings: [], roofs: [], columns: [] };
|
||||
const doc = new ProjectDocument(base);
|
||||
const r = doc.importDrawing(
|
||||
base,
|
||||
parsed.src,
|
||||
{
|
||||
target: { kind: "new", name: "Import" },
|
||||
categoryMode: "byLayer",
|
||||
activeCategoryCode: "20",
|
||||
importMeshes: false,
|
||||
levelNameTemplate: "Import {n}",
|
||||
parentName: "Import",
|
||||
dashStyleTemplate: "{pattern}",
|
||||
},
|
||||
0,
|
||||
);
|
||||
if ("problems" in r) throw new Error(r.problems.join("; "));
|
||||
const imported = r.project;
|
||||
const level = imported.drawingLevels.find((l) => l.id === levelId)!;
|
||||
const opts = { levelId, floorHeight: level.floorHeight, sourceLevelId: r.levelId, wallTypeId: orig.wallTypes[0]?.id, typeName: "Wand {cm} cm (erkannt)" };
|
||||
const report = recognizeReport(imported, opts);
|
||||
const result = recognizeMutation(opts)(imported);
|
||||
doc.close();
|
||||
|
||||
const ow = orig.walls.filter((w) => w.floorId === levelId);
|
||||
const nw = result.walls.filter((w) => w.floorId === levelId);
|
||||
// Gleiche Wand: Dicke, Endpunkte (±1 cm), bei Bogenwänden derselbe Bogen (Bulge, umgekehrt mit Gegenzeichen).
|
||||
const sameWall = (w: Wall, n: Wall) => {
|
||||
if (Math.abs(thickness(orig, w) - thickness(result, n)) >= 1e-3) return false;
|
||||
const fwd = dist(w.start, n.start) < 0.01 && dist(w.end, n.end) < 0.01;
|
||||
const rev = dist(w.start, n.end) < 0.01 && dist(w.end, n.start) < 0.01;
|
||||
const [bw, bn] = [w.bulge ?? 0, n.bulge ?? 0];
|
||||
return (fwd && Math.abs(bw - bn) < 1e-3) || (rev && Math.abs(bw + bn) < 1e-3);
|
||||
};
|
||||
const wallOk = ow.filter((w) => nw.some((n) => sameWall(w, n))).length;
|
||||
// Achsen-Abdeckung (gerade Wände): Anteil der Achslänge, die eine erkannte Achse gleicher Dicke trägt
|
||||
// (zusammengelegte Wände über einen T-Stoss zählen hier voll).
|
||||
const onAxis = (p: Vec2, n: Wall) => {
|
||||
const l2 = (n.end.x - n.start.x) ** 2 + (n.end.y - n.start.y) ** 2;
|
||||
const s = Math.max(0, Math.min(1, ((p.x - n.start.x) * (n.end.x - n.start.x) + (p.y - n.start.y) * (n.end.y - n.start.y)) / l2));
|
||||
return dist(p, { x: n.start.x + s * (n.end.x - n.start.x), y: n.start.y + s * (n.end.y - n.start.y) }) < 0.01;
|
||||
};
|
||||
let [axisOk, axisAll] = [0, 0];
|
||||
for (const w of ow.filter((x) => !x.bulge)) {
|
||||
const l = dist(w.start, w.end);
|
||||
const k = Math.max(1, Math.round(l / 0.05));
|
||||
for (let i = 0; i < k; i++) {
|
||||
const s = (i + 0.5) / k;
|
||||
const p = { x: w.start.x + s * (w.end.x - w.start.x), y: w.start.y + s * (w.end.y - w.start.y) };
|
||||
axisAll += l / k;
|
||||
if (nw.some((n) => !n.bulge && Math.abs(thickness(orig, w) - thickness(result, n)) < 1e-3 && onAxis(p, n))) axisOk += l / k;
|
||||
}
|
||||
}
|
||||
const oo = (orig.openings ?? []).filter((o) => ow.some((w) => w.id === o.hostWallId)).map((o) => jambs(orig, o)).filter((j): j is Jambs => !!j);
|
||||
const no = (result.openings ?? []).map((o) => jambs(result, o)).filter((j): j is Jambs => !!j);
|
||||
const same = (x: Jambs, y: Jambs) =>
|
||||
x.kind === y.kind && ((dist(x.a, y.a) < 0.02 && dist(x.b, y.b) < 0.02) || (dist(x.a, y.b) < 0.02 && dist(x.b, y.a) < 0.02));
|
||||
const openOk = oo.filter((x) => no.some((y) => same(x, y))).length;
|
||||
const od = oo.filter((x) => x.kind === "door");
|
||||
const doorOk = od.filter((x) =>
|
||||
no.some((y) => same(x, y) && dist(x.hinge!, y.hinge!) < 0.02 && dist(x.side!, y.side!) < 1e-6),
|
||||
).length;
|
||||
return { walls: [wallOk, ow.length], axis: axisAll ? axisOk / axisAll : 1, openings: [openOk, oo.length], doors: [doorOk, od.length], report, imported, result };
|
||||
}
|
||||
|
||||
const pct = ([a, b]: [number, number]) => `${a}/${b} (${b ? Math.round((100 * a) / b) : 100} %)`;
|
||||
|
||||
function log(name: string, q: Quote) {
|
||||
console.log(
|
||||
`[154] ${name}: Wände ${pct(q.walls)} (Achsen ${Math.round(q.axis * 100)} %), Öffnungen ${pct(q.openings)}, Türen mit Anschlag/Aufschlag ${pct(q.doors)}; ` +
|
||||
`erkannt ${q.report.walls} Wände, ${q.report.doors} Türen, ${q.report.windows} Fenster, ${q.report.voids} Durchbrüche, ${q.report.rooms} Räume, unklar ${q.report.unclear.length} (${[...new Set(q.report.unclear.map((u) => u.code))].join(", ")})`,
|
||||
);
|
||||
if (OUT) {
|
||||
writeFileSync(join(OUT, `${name}-import.obp`), serializeProject(q.imported));
|
||||
writeFileSync(join(OUT, `${name}-erkannt.obp`), serializeProject(q.result));
|
||||
}
|
||||
}
|
||||
|
||||
describe("[154] Rundreise DXF-Export → Import → Bauteile erkennen", () => {
|
||||
beforeAll(loadFileioForTests);
|
||||
|
||||
it("Musterhaus EG: alle Wände und Öffnungen, Tür mit Anschlag und Aufschlag", () => {
|
||||
const q = roundtrip(sampleProject, "eg");
|
||||
log("musterhaus-eg", q);
|
||||
expect(q.walls).toEqual([5, 5]);
|
||||
expect(q.openings).toEqual([3, 3]);
|
||||
expect(q.doors).toEqual([1, 1]);
|
||||
// Wandtypen nach Dicke wiederverwendet, keine neuen.
|
||||
expect(q.result.wallTypes.length).toBe(sampleProject.wallTypes.length);
|
||||
expect(q.report.layerFilter).toBe(true);
|
||||
// Raum mit Name aus dem Raumstempel.
|
||||
expect(q.result.rooms?.some((r) => r.name === "Wohnen")).toBe(true);
|
||||
});
|
||||
|
||||
it("Musterhaus OG", () => {
|
||||
const q = roundtrip(sampleProject, "og");
|
||||
log("musterhaus-og", q);
|
||||
expect(q.walls[0]).toBe(q.walls[1]);
|
||||
expect(q.openings[0]).toBe(q.openings[1]);
|
||||
});
|
||||
|
||||
it("Musterhaus komplex: Quote je Geschoss", () => {
|
||||
const p = buildComplexSampleProject();
|
||||
const floors = p.drawingLevels.filter((l) => l.kind === "floor" && p.walls.some((w) => w.floorId === l.id));
|
||||
let [w, wn, o, on, ax] = [0, 0, 0, 0, 0];
|
||||
for (const l of floors) {
|
||||
const q = roundtrip(p, l.id);
|
||||
log(`komplex-${l.id}`, q);
|
||||
w += q.walls[0];
|
||||
ax += q.axis / floors.length;
|
||||
wn += q.walls[1];
|
||||
o += q.openings[0];
|
||||
on += q.openings[1];
|
||||
}
|
||||
console.log(`[154] Musterhaus komplex gesamt: Wände ${pct([w, wn])} (Achsen ${Math.round(ax * 100)} %), Öffnungen ${pct([o, on])}`);
|
||||
expect(wn).toBeGreaterThan(0);
|
||||
expect(w / wn).toBeGreaterThan(0.6);
|
||||
}, 120_000);
|
||||
});
|
||||
@@ -0,0 +1,82 @@
|
||||
// [154] Bauteile aus Zeichnung erkennen — dünne Fassade über den Kern (`src-tauri/core/src/drawing_recognize.rs`):
|
||||
// aus den 2D-Linien eines Grundrisses (DXF/DWG-Import) Wände, Öffnungen und Räume. Erkennung, Vorschau, Bericht
|
||||
// und Ops rechnet der Kern; hier nur die Anfrage (Quell-Ebene, Auswahl, Namensvorlagen, Ziel-Geschoss).
|
||||
|
||||
import type { Project } from "../model/types";
|
||||
import type { ProjectMutation } from "../core/opsBuild";
|
||||
import { cmdMutation, documentFor } from "../core/document";
|
||||
|
||||
/** Unklare Stelle: Grund (Schlüssel `cmd.recognize.reason.<code>`) und Lage. */
|
||||
export interface RecognizeUnclear {
|
||||
code: "areaMismatch" | "areaOutside" | "lineUnpaired" | "doorArc" | "doorHalf" | "gapWide" | "tooMany";
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
/** Bericht der Erkennung (Abfrage `recognize`). */
|
||||
export interface RecognizeReport {
|
||||
walls: number;
|
||||
doors: number;
|
||||
windows: number;
|
||||
voids: number;
|
||||
rooms: number;
|
||||
arcWalls: number;
|
||||
/** Wände mit Füllung/Schraffur zwischen den Linien. */
|
||||
filledWalls: number;
|
||||
unnamedRooms: number;
|
||||
/** Erkannte Wanddicken (m, auf mm gerundet). */
|
||||
thicknesses: number[];
|
||||
/** Nur Linien auf Wand-Layern verwendet („Wand“, „Mauer“, „A-WALL“ …). */
|
||||
layerFilter: boolean;
|
||||
unclear: RecognizeUnclear[];
|
||||
}
|
||||
|
||||
export interface RecognizeOptions {
|
||||
/** Ziel-Geschoss (Wände, Höhe). */
|
||||
levelId: string;
|
||||
/** Geschosshöhe (Wandhöhe); fehlt → Kern-Vorgabe 2.6 m. */
|
||||
floorHeight?: number;
|
||||
/** Ebene mit der Zeichnung; fehlt → `levelId`. Ohne Wirkung, wenn `ids` gesetzt ist. */
|
||||
sourceLevelId?: string;
|
||||
/** Nur diese 2D-Elemente (Auswahl). */
|
||||
ids?: readonly string[];
|
||||
/** Kategorie, falls „20/21/60“ fehlen. */
|
||||
categoryCode?: string;
|
||||
/** Aktiver Wandtyp (Baustoff neuer Wandtypen). */
|
||||
wallTypeId?: string;
|
||||
/** Namensvorlage neuer Wandtypen, `{cm}` = Dicke. */
|
||||
typeName?: string;
|
||||
/** Namensvorlage unbenannter Räume, `{n}` = laufende Nummer. */
|
||||
roomName?: string;
|
||||
}
|
||||
|
||||
let seq = 0;
|
||||
|
||||
function request(o: RecognizeOptions): Record<string, unknown> {
|
||||
return {
|
||||
cmd: "recognize",
|
||||
src: o.sourceLevelId ?? o.levelId,
|
||||
ids: o.ids && o.ids.length > 0 ? [...o.ids] : [],
|
||||
typeName: o.typeName ?? "",
|
||||
roomName: o.roomName ?? "",
|
||||
ctx: { level: o.levelId, floorHeight: o.floorHeight ?? null, cat: o.categoryCode ?? "20", wallType: o.wallTypeId ?? "" },
|
||||
};
|
||||
}
|
||||
|
||||
/** Bericht (Zähler, unklare Stellen) ohne Änderung am Projekt. */
|
||||
export function recognizeReport(project: Project, o: RecognizeOptions): RecognizeReport {
|
||||
const { cmd: _cmd, ctx: _ctx, ...rest } = request(o);
|
||||
return documentFor(project).createQuery<RecognizeReport>({ q: "recognize", level: o.levelId, ...rest });
|
||||
}
|
||||
|
||||
/** Änderung: neue Wandtypen, Wände, Öffnungen, Räume als EIN Undo-Schritt. */
|
||||
export function recognizeMutation(o: RecognizeOptions): ProjectMutation {
|
||||
seq += 1;
|
||||
return cmdMutation({ ...request(o), stamp: `${Date.now()}-r${seq}` });
|
||||
}
|
||||
|
||||
/** Ebenen mit 2D-Zeichnung (Geschosse und Zeichnungsebenen), in Projekt-Reihenfolge. */
|
||||
export function recognizeSourceLevels(project: Project): string[] {
|
||||
const used = new Set(project.drawings2d.map((d) => d.levelId));
|
||||
return project.drawingLevels.filter((l) => (l.kind === "floor" || l.kind === "drawing") && used.has(l.id)).map((l) => l.id);
|
||||
}
|
||||
Reference in new issue
Block a user