From 990d6166802c305dfb4d28931068e7743e11f2f4 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 4 Nov 2026 14:33:53 +0000 Subject: [PATCH] =?UTF-8?q?[77]=20Zauberstab:=20Option=20S=20w=C3=A4hlt=20?= =?UTF-8?q?die=20Schraffur=20(oder=20nur=20Umriss)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67 --- TODO.md | 2 +- src/commands/cmds/wand.test.ts | 12 +++++++++++ src/commands/cmds/wand.ts | 38 ++++++++++++++++++++++++++-------- src/i18n/de.ts | 1 + src/i18n/en.ts | 1 + 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/TODO.md b/TODO.md index 995f9414..a19404c8 100644 --- a/TODO.md +++ b/TODO.md @@ -1739,7 +1739,7 @@ Reihenfolge = Abhängigkeiten. Neue Geometrie entsteht in Rust ([K]). - ◐ **[77] Zauberstab.** · M — 4.11.: Befehl `wand` (Kürzel `zs`/`zauberstab`): Klick in eine von Linien umschlossene Fläche (2D-Zeichnungen + Modellkanten des Geschosses, Kreise/Bögen als Sehnenzüge, Kreuzungen werden geteilt) → geschlossene Polylinie mit der ersten Projekt-Schraffur; Vorschau beim Überfahren. Kern `magic_wand.rs` - (planarer Graph, kleinste Masche, `kernel2d::room_from_point_inside_faces`), Tests Rust + vitest. Offen: Wahl der + (planarer Graph, kleinste Masche, `kernel2d::room_from_point_inside_faces`), Tests Rust + vitest. Offen: Schraffur/Option „nur Umriss", Inseln (Löcher) in der Fläche; Knopf in der Werkzeugleiste (2D) seit 4.11.; nicht in der App geklickt. - ✅ **[78] Autotext im Plankopf.** Titelblock löst Projekt/Blatt/Massstab/Datum auf; Plannummer laufend oder `Layout.planNumber` (27.10.). diff --git a/src/commands/cmds/wand.test.ts b/src/commands/cmds/wand.test.ts index 8ccd6405..dd4a0350 100644 --- a/src/commands/cmds/wand.test.ts +++ b/src/commands/cmds/wand.test.ts @@ -34,6 +34,18 @@ describe("wandCommand", () => { if (d.geom.shape === "polyline") expect(d.geom.closed).toBe(true); }); + it("Option S: nächste Schraffur, dann „keine“ (nur Umriss)", () => { + const p = project(); + const ctx = ctxOf(p); + const [s1] = wandCommand.onInput(wandCommand.init(), { kind: "option", id: "hatch" }, ctx); + expect(wandCommand.options(s1)[0].value).toBe("—"); + const [, r] = wandCommand.onInput(s1, { kind: "point", point: { x: 1, y: 1 } }, ctx); + const next = r.commit!(p); + expect(next.drawings2d[next.drawings2d.length - 1].hatchId).toBeUndefined(); + const [s2] = wandCommand.onInput(s1, { kind: "option", id: "hatch" }, ctx); + expect(wandCommand.options(s2)[0].value).toBe("Beton"); + }); + 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)); diff --git a/src/commands/cmds/wand.ts b/src/commands/cmds/wand.ts index e2ed750f..3d704f7e 100644 --- a/src/commands/cmds/wand.ts +++ b/src/commands/cmds/wand.ts @@ -1,28 +1,48 @@ // 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). +// zeigt sie schon beim Überfahren. Option S schaltet durch die Schraffuren des Projekts und „keine" (nur Umriss); +// Vorgabe ist die erste Schraffur. Die Wahl bleibt über mehrere Klicks (`sticky`). -import type { Command, CommandContext, CommandResult, CommandState, Vec2 } from "../types"; +import type { CmdOption, Command, CommandContext, CommandResult, CommandState, Vec2 } from "../types"; import { createMutation, createPreview } from "../createCore"; +interface WandState extends CommandState { + /** `hatch`: Index in `project.hatches` (`NONE` = nur Umriss); `name`: Anzeige in der Befehlszeile. */ + sticky: { hatch: number; name?: string }; +} + +const NONE = -1; const idle = (): [CommandState, CommandResult] => [{ phase: "point", lastPoint: null }, { draft: null, done: true }]; -const hatchOf = (ctx: CommandContext): string | undefined => ctx.project.hatches[0]?.id; +/** Gewählte Schraffur: Index in `project.hatches`, `NONE` = nur Umriss; ausser Reichweite → erste. */ +const hatchOf = (s: WandState, ctx: CommandContext): string | undefined => + s.sticky.hatch === NONE ? undefined : (ctx.project.hatches[s.sticky.hatch] ?? 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 }), + accepts: () => ["point", "option"], + options: (state): CmdOption[] => { + const s = state as WandState; + const value = s.sticky?.hatch === NONE ? "—" : (s.sticky?.name ?? "1"); + return [{ id: "hatch", labelKey: "cmd.wand.hatch", key: "S", value }]; + }, + init: (): WandState => ({ phase: "point", lastPoint: null, sticky: { hatch: 0 } }), onInput: (state, input, ctx): [CommandState, CommandResult] => { - if (input.kind !== "point") return [state, { draft: null }]; + const s = state as WandState; + if (input.kind === "option" && input.id === "hatch") { + const n = ctx.project.hatches.length; + // Reihenfolge: 0, 1, …, n−1, keine, 0 … + const next = s.sticky.hatch === NONE ? 0 : s.sticky.hatch + 1 >= n ? NONE : s.sticky.hatch + 1; + return [{ ...s, sticky: { hatch: next, name: next === NONE ? undefined : ctx.project.hatches[next]?.name } } as WandState, { draft: null }]; + } + if (input.kind !== "point") return [s, { 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) }) }]; + if (!createPreview(ctx, { cmd: "wand" }, [at]).ok) return [s, { draft: null }]; + return [s, { draft: null, commit: createMutation(ctx, { cmd: "wand", at, hatchId: hatchOf(s, ctx) }) }]; }, onMove: (state, point, _snap, ctx): [CommandState, CommandResult] => { diff --git a/src/i18n/de.ts b/src/i18n/de.ts index 3cd6fe4c..b04ea0f3 100644 --- a/src/i18n/de.ts +++ b/src/i18n/de.ts @@ -1805,6 +1805,7 @@ export const de = { "cmd.pointmarker.point": "Punkt:", "cmd.wand.label": "Zauberstab", "cmd.wand.point": "In eine umschlossene Fläche klicken:", + "cmd.wand.hatch": "Schraffur", "cmd.grid.label": "Achsraster", "cmd.grid.origin": "Ursprung des Achsrasters ( Radial ):", "cmd.grid.radial": "Radial", diff --git a/src/i18n/en.ts b/src/i18n/en.ts index ec4dc5c8..c9cec84a 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -1794,6 +1794,7 @@ export const en: Record = { "cmd.pointmarker.point": "Point:", "cmd.wand.label": "Magic wand", "cmd.wand.point": "Click inside an enclosed area:", + "cmd.wand.hatch": "Hatch", "cmd.grid.label": "Structural grid", "cmd.grid.origin": "Grid origin ( Radial ):", "cmd.grid.radial": "Radial",