[77] Zauberstab: Klick in umschlossene Fläche → schraffierte Polylinie (Kern magic_wand.rs)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
Claude committed 2026-11-04 14:00:12 +00:00
1 parent 13f2262897
commit 369d8a81b3
10 files changed
+232 -2

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
/** `wandCommand` ([77]): Klick in ein Rechteck aus vier Linien → geschlossene Polylinie mit Schraffur; daneben nichts. */
import { describe, expect, it } from "vitest";
import { wandCommand } from "./wand";
import type { CommandContext, Project } from "../types";
import type { Drawing2D } from "../../model/types";
const line = (id: string, a: [number, number], b: [number, number]): Drawing2D =>
({ id, levelId: "eg", categoryCode: "20", geom: { shape: "line", a: { x: a[0], y: a[1] }, b: { x: b[0], y: b[1] } } }) as Drawing2D;
function project(): Project {
return {
id: "t", name: "T", lineStyles: [], components: [], wallTypes: [],
hatches: [{ id: "h1", name: "Beton", pattern: "diagonal", spacing: 0.1, angle: 45 } as unknown as Project["hatches"][number]],
drawingLevels: [{ id: "eg", name: "EG", kind: "floor", visible: true, locked: false, floorHeight: 2.6, cutHeight: 1.0, baseElevation: 0 }],
layers: [{ code: "20", name: "Zeichnung", color: "#0a0a0a", lw: 0.5, visible: true, locked: false }],
walls: [], openings: [], ceilings: [], stairs: [], rooms: [], context: [],
drawings2d: [line("a", [0, 0], [3, 0]), line("b", [3, 0], [3, 2]), line("c", [3, 2], [0, 2]), line("d", [0, 2], [0, 0])],
};
}
const ctxOf = (p: Project): CommandContext =>
({ project: p, level: p.drawingLevels[0], defaultCategoryCode: "20", activeLineStyleId: "solid", activeWallTypeId: "aw", lastPoint: null, selection: { wallIds: [], drawingId: null } }) as CommandContext;
describe("wandCommand", () => {
it("Klick in die Fläche: geschlossene Polylinie mit der ersten Schraffur", () => {
const p = project();
const ctx = ctxOf(p);
const [, r] = wandCommand.onInput(wandCommand.init(), { kind: "point", point: { x: 1, y: 1 } }, ctx);
expect(r.commit).toBeDefined();
const next = r.commit!(p);
const d = next.drawings2d[next.drawings2d.length - 1];
expect(d.geom.shape).toBe("polyline");
expect(d.hatchId).toBe("h1");
if (d.geom.shape === "polyline") expect(d.geom.closed).toBe(true);
});
it("Klick ausserhalb: kein Commit, Befehl bleibt aktiv", () => {
const p = project();
const [, r] = wandCommand.onInput(wandCommand.init(), { kind: "point", point: { x: 9, y: 9 } }, ctxOf(p));
expect(r.commit).toBeUndefined();
expect(r.done).toBeFalsy();
});
});
+34
View File
@@ -0,0 +1,34 @@
// Zauberstab ([77]): EIN Klick in eine von Linien umschlossene Fläche (2D-Zeichnungen und Modellkanten des
// Geschosses) → geschlossene Polylinie mit Schraffur. Die Masche sucht der Kern (`magic_wand.rs`); die Vorschau
// zeigt sie schon beim Überfahren. Schraffur: die erste Schraffur des Projekts (ohne Schraffuren nur der Umriss).
import type { Command, CommandContext, CommandResult, CommandState, Vec2 } from "../types";
import { createMutation, createPreview } from "../createCore";
const idle = (): [CommandState, CommandResult] => [{ phase: "point", lastPoint: null }, { draft: null, done: true }];
const hatchOf = (ctx: CommandContext): string | undefined => ctx.project.hatches[0]?.id;
export const wandCommand: Command = {
name: "wand",
labelKey: "cmd.wand.label",
prompt: () => "cmd.wand.point",
accepts: () => ["point"],
options: () => [],
init: () => ({ phase: "point", lastPoint: null }),
onInput: (state, input, ctx): [CommandState, CommandResult] => {
if (input.kind !== "point") return [state, { draft: null }];
const at: Vec2 = input.point;
// Kein Treffer: Befehl bleibt aktiv (nächster Klick), nichts wird angelegt.
if (!createPreview(ctx, { cmd: "wand" }, [at]).ok) return [state, { draft: null }];
return [state, { draft: null, commit: createMutation(ctx, { cmd: "wand", at, hatchId: hatchOf(ctx) }) }];
},
onMove: (state, point, _snap, ctx): [CommandState, CommandResult] => {
const pv = createPreview(ctx, { cmd: "wand" }, [point]);
return [state, { draft: { preview: pv.ok ? pv.shapes : [], vertices: [point] } }];
},
onConfirm: () => idle(),
onCancel: () => idle(),
};
+4
View File
@@ -35,6 +35,7 @@ import { detailrefCommand } from "./cmds/detailref";
import { scalebarCommand } from "./cmds/scalebar";
import { revcloudCommand } from "./cmds/revcloud";
import { pointmarkerCommand } from "./cmds/pointmarker";
import { wandCommand } from "./cmds/wand";
import { wipeoutCommand } from "./cmds/wipeout";
import { textCommand } from "./cmds/text";
import { leaderCommand } from "./cmds/leader";
@@ -106,6 +107,7 @@ export const COMMANDS: Record<string, Command> = {
scalebar: scalebarCommand,
revcloud: revcloudCommand,
pointmarker: pointmarkerCommand,
wand: wandCommand,
wipeout: wipeoutCommand,
text: textCommand,
leader: leaderCommand,
@@ -221,6 +223,8 @@ export const ALIASES: Record<string, string> = {
wolke: "revcloud",
revisionswolke: "revcloud",
pm: "pointmarker",
zs: "wand",
zauberstab: "wand",
punkt: "pointmarker",
knoten: "pointmarker",
wo: "wipeout",
+2
View File
@@ -1799,6 +1799,8 @@ export const de = {
"cmd.revcloud.arcSize": "Beulengrösse",
"cmd.pointmarker.label": "Punktmarker",
"cmd.pointmarker.point": "Punkt:",
"cmd.wand.label": "Zauberstab",
"cmd.wand.point": "In eine umschlossene Fläche klicken:",
"cmd.grid.label": "Achsraster",
"cmd.grid.origin": "Ursprung des Achsrasters ( Radial ):",
"cmd.grid.radial": "Radial",
+2
View File
@@ -1788,6 +1788,8 @@ export const en: Record<TranslationKey, string> = {
"cmd.revcloud.arcSize": "Arc size",
"cmd.pointmarker.label": "Point marker",
"cmd.pointmarker.point": "Point:",
"cmd.wand.label": "Magic wand",
"cmd.wand.point": "Click inside an enclosed area:",
"cmd.grid.label": "Structural grid",
"cmd.grid.origin": "Grid origin ( Radial ):",
"cmd.grid.radial": "Radial",