[123] Transformation nur noch über die Befehls-Engine, alte Werkzeug-Registry gestrichen
Bewegen/Drehen/Spiegeln laufen als Engine-Befehle (commands/cmds/transform.ts) mit den Abläufen der früheren App-Maschine (activeTransform): U/I/O/P-Kopiermodus, Distanz-/Winkelfeld, Dreh-Darstellung, Enter = Punkt an der Maus, Esc/Esc-Esc nach [99]. Knopf, Menü, Tasten m/s/d und getippter Befehl starten denselben Befehl. tools/tools.ts ist nur noch die Werkzeug-Liste; commitTransform (nur von Tests genutzt) entfällt. Neuer e2e-Test transform.spec.ts.
This commit is contained in:
21 files changed
+690
-1896
No files matched your search
+54
-480
@@ -1,484 +1,58 @@
|
||||
// Werkzeug-Registry (docs/design/drawing-tools.md §3, §4, §10). Alle Zeichenwerkzeuge sind an
|
||||
// Befehle gekoppelt (TOOL_COMMAND in App.tsx); die Elemente baut der Kern ([K4] S3,
|
||||
// `src-tauri/core/src/cmd_create.rs`). Hier stehen nur noch Platzhalter (Label, Hinweis) und
|
||||
// das Auswahl-Werkzeug.
|
||||
// Werkzeug-Liste der Palette ([123]): nur noch Beschriftung, Hinweis, Geschoss-Bindung und der
|
||||
// gekoppelte Befehl. Alle Zeichenwerkzeuge SIND Engine-Befehle (Klick aufs Werkzeug startet den
|
||||
// Befehl, die Elemente baut der Kern, `cmd_create.rs`); „select" ist der Auswahl-Modus, „image"
|
||||
// öffnet den Datei-Dialog (`onSelectTool` in App.tsx). Die frühere Tool-Registry mit eigenen
|
||||
// Klick-/Vorschau-Handlern ist entfallen.
|
||||
|
||||
import type { Tool, ToolId } from "./types";
|
||||
import type { ToolId } from "./types";
|
||||
|
||||
// ── Select ──────────────────────────────────────────────────────────────────
|
||||
// Reines Platzhalter-Werkzeug: die Auswahl-/Marquee-Logik bleibt in PlanView;
|
||||
// der Controller ruft dieses Werkzeug für "select" gar nicht erst auf.
|
||||
const selectTool: Tool = {
|
||||
id: "select",
|
||||
labelKey: "tool.select",
|
||||
hintKey: () => "tool.select.hint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
// ── Wall / Ceiling ───────────────────────────────────────────────────────────
|
||||
// An die gekoppelten Befehle `wall`/`ceiling` (TOOL_COMMAND in App.tsx) gebunden: Klick und
|
||||
// getipptes „wall“ münden in denselben Befehl, die Elemente baut der Kern ([K4] S3,
|
||||
// `cmd_create.rs`). Diese Tool-Objekte sind reine Platzhalter (wie window/door).
|
||||
const wallTool: Tool = {
|
||||
id: "wall",
|
||||
labelKey: "tool.wall",
|
||||
floorOnly: true,
|
||||
hintKey: () => "tool.wall.firstPoint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
const ceilingTool: Tool = {
|
||||
id: "ceiling",
|
||||
labelKey: "tool.ceiling",
|
||||
floorOnly: true,
|
||||
hintKey: () => "tool.ceiling.firstPoint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
// ── Window / Door (Öffnungen) ─────────────────────────────────────────────────
|
||||
// Beide sind an den gekoppelten Befehl `fenster`/`tuer` (TOOL_COMMAND) gebunden:
|
||||
// der interaktive Ablauf (Host-Wand picken → Position → committen) läuft komplett
|
||||
// in der CommandEngine. Diese Tool-Objekte sind reine Platzhalter (wie `select`);
|
||||
// der Controller ruft sie nicht auf, sobald der gekoppelte Befehl läuft.
|
||||
const windowTool: Tool = {
|
||||
id: "window",
|
||||
labelKey: "tool.window",
|
||||
floorOnly: true,
|
||||
hintKey: () => "tool.window.hint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
const doorTool: Tool = {
|
||||
id: "door",
|
||||
labelKey: "tool.door",
|
||||
floorOnly: true,
|
||||
hintKey: () => "tool.door.hint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
// ── Stair (Treppe) ───────────────────────────────────────────────────────────
|
||||
// An den gekoppelten Befehl `stair` (TOOL_COMMAND) gebunden: der interaktive
|
||||
// Ablauf (Startpunkt → Laufrichtung/Ende → committen) läuft komplett in der
|
||||
// CommandEngine. Dieses Tool-Objekt ist ein reiner Platzhalter (wie window/door);
|
||||
// der Controller ruft es nicht auf, sobald der gekoppelte Befehl läuft.
|
||||
const stairTool: Tool = {
|
||||
id: "stair",
|
||||
labelKey: "tool.stair",
|
||||
floorOnly: true,
|
||||
hintKey: () => "tool.stair.hint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
// ── Room (Raum) ──────────────────────────────────────────────────────────────
|
||||
// An den gekoppelten Befehl `room` (TOOL_COMMAND) gebunden: der interaktive
|
||||
// Ablauf (Klick-innen zur Erkennung ODER manueller Umriss) läuft komplett in der
|
||||
// CommandEngine. Dieses Tool-Objekt ist ein reiner Platzhalter (wie stair/window);
|
||||
// der Controller ruft es nicht auf, sobald der gekoppelte Befehl läuft.
|
||||
const roomTool: Tool = {
|
||||
id: "room",
|
||||
labelKey: "tool.room",
|
||||
floorOnly: true,
|
||||
hintKey: () => "tool.room.hint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
// ── Line / Polyline / Rectangle ──────────────────────────────────────────────
|
||||
// Gekoppelt an die Befehle `line`/`polyline`/`rect` (TOOL_COMMAND); reine Platzhalter.
|
||||
const lineTool: Tool = {
|
||||
id: "line",
|
||||
labelKey: "tool.line",
|
||||
hintKey: () => "tool.line.firstPoint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
// Konstruktionslinie: Platzhalter-Werkzeug, gekoppelt an den `xline`-Befehl
|
||||
// (zwei Punkte legen die Richtung fest, Rendering/Snapping verlängern weit
|
||||
// darüber hinaus). Nicht floorOnly (freies 2D-Element).
|
||||
const xlineTool: Tool = {
|
||||
id: "xline",
|
||||
labelKey: "tool.xline",
|
||||
hintKey: () => "tool.xline.hint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
// Strahl: Platzhalter-Werkzeug, gekoppelt an den `ray`-Befehl (wie `xline`,
|
||||
// aber nur einseitig verlängert). Nicht floorOnly (freies 2D-Element).
|
||||
const rayTool: Tool = {
|
||||
id: "ray",
|
||||
labelKey: "tool.ray",
|
||||
hintKey: () => "tool.ray.hint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
const polylineTool: Tool = {
|
||||
id: "polyline",
|
||||
labelKey: "tool.polyline",
|
||||
hintKey: () => "tool.polyline.firstPoint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
const rectTool: Tool = {
|
||||
id: "rect",
|
||||
labelKey: "tool.rect",
|
||||
hintKey: () => "tool.rect.firstCorner",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
// Kreis: Platzhalter-Werkzeug (analog window/door), gekoppelt an den
|
||||
// `circle`-Befehl (TOOL_COMMAND in App.tsx). Der eigentliche Ablauf
|
||||
// (Mittelpunkt → Radius) läuft über die Command-Engine — EIN Pfad für
|
||||
// Toolbar-Klick und getipptes „circle". Nicht floorOnly (freie 2D-Zeichnung).
|
||||
const circleTool: Tool = {
|
||||
id: "circle",
|
||||
labelKey: "tool.circle",
|
||||
hintKey: () => "tool.circle.hint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
// Bogen: Platzhalter-Werkzeug, gekoppelt an den `arc`-Befehl (3 Klicks:
|
||||
// Mitte → Start/Radius → Ende). Wie Kreis nicht floorOnly.
|
||||
const arcTool: Tool = {
|
||||
id: "arc",
|
||||
labelKey: "tool.arc",
|
||||
hintKey: () => "tool.arc.hint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
// Ellipse: Platzhalter-Werkzeug, gekoppelt an den `ellipse`-Befehl (zwei
|
||||
// Bounding-Box-Ecken). Wie Kreis/Bogen nicht floorOnly.
|
||||
const ellipseTool: Tool = {
|
||||
id: "ellipse",
|
||||
labelKey: "tool.ellipse",
|
||||
hintKey: () => "tool.ellipse.hint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
// Regelmässiges Vieleck: Platzhalter-Werkzeug, gekoppelt an den `polygon`-
|
||||
// Befehl (Mittelpunkt → Radius, Ecken-Zahl per Inline-Option). Wie Kreis/
|
||||
// Bogen/Ellipse nicht floorOnly; committet als geschlossene Polylinie.
|
||||
const polygonTool: Tool = {
|
||||
id: "polygon",
|
||||
labelKey: "tool.polygon",
|
||||
hintKey: () => "tool.polygon.hint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
// Block einfügen: Platzhalter-Werkzeug, gekoppelt an den `block`-Befehl
|
||||
// (Einfügepunkt, aktive Definition per Inline-Option). Nicht floorOnly.
|
||||
const blockTool: Tool = {
|
||||
id: "block",
|
||||
labelKey: "tool.block",
|
||||
hintKey: () => "tool.block.hint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
// Spline: Platzhalter-Werkzeug, gekoppelt an den `spline`-Befehl (Wegpunkte,
|
||||
// wie Polylinie, aber geglättet). Nicht floorOnly.
|
||||
const splineTool: Tool = {
|
||||
id: "spline",
|
||||
labelKey: "tool.spline",
|
||||
hintKey: () => "tool.spline.hint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
// Bezier: Platzhalter-Werkzeug, gekoppelt an den `bezier`-Befehl (manuelle
|
||||
// Kontrollpunkt-Kette). Nicht floorOnly.
|
||||
const bezierTool: Tool = {
|
||||
id: "bezier",
|
||||
labelKey: "tool.bezier",
|
||||
hintKey: () => "tool.bezier.hint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
// Bemassung: Platzhalter-Werkzeug, gekoppelt an den `dimension`-Befehl (zwei
|
||||
// Punkte + Lage der Masslinie). Nicht floorOnly.
|
||||
const dimensionTool: Tool = {
|
||||
id: "dimension",
|
||||
labelKey: "tool.dimension",
|
||||
hintKey: () => "tool.dimension.hint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
// Höhenkote: Platzhalter-Werkzeug, gekoppelt an den `kote`-Befehl (Punkt →
|
||||
// getippter Höhenwert). Nicht floorOnly.
|
||||
const koteTool: Tool = {
|
||||
id: "kote",
|
||||
labelKey: "tool.kote",
|
||||
hintKey: () => "tool.kote.hint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
// Detail-/Schnitt-Verweis: Platzhalter-Werkzeug, gekoppelt an den
|
||||
// `detailref`-Befehl (ein Klick → Verweisblase, Label/Blattverknüpfung
|
||||
// danach im Attribute-Panel). Freies 2D-Element (nicht floorOnly).
|
||||
const detailrefTool: Tool = {
|
||||
id: "detailref",
|
||||
labelKey: "tool.detailref",
|
||||
hintKey: () => "tool.detailref.hint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
// Massstabsbalken: Platzhalter-Werkzeug, gekoppelt an den `scalebar`-Befehl
|
||||
// (ein Klick, Segmentlänge/-anzahl per Option). Freies 2D-Element.
|
||||
const scalebarTool: Tool = {
|
||||
id: "scalebar",
|
||||
labelKey: "tool.scalebar",
|
||||
hintKey: () => "tool.scalebar.hint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
// Revisionswolke: Platzhalter-Werkzeug, gekoppelt an den `revcloud`-Befehl
|
||||
// (Punktfolge → Beulen-Kontur). Freies 2D-Element (nicht floorOnly).
|
||||
const revcloudTool: Tool = {
|
||||
id: "revcloud",
|
||||
labelKey: "tool.revcloud",
|
||||
hintKey: () => "tool.revcloud.hint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
// Punkt-/Knotenmarker: Platzhalter-Werkzeug, gekoppelt an den
|
||||
// `pointmarker`-Befehl (ein Klick → Kreuz-in-Kreis-Symbol). Freies
|
||||
// 2D-Element (nicht floorOnly).
|
||||
const pointmarkerTool: Tool = {
|
||||
id: "pointmarker",
|
||||
labelKey: "tool.pointmarker",
|
||||
hintKey: () => "tool.pointmarker.hint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
// Achsraster ([112]): Platzhalter-Werkzeug, gekoppelt an den `grid`-Befehl (Ursprung + Feldweiten).
|
||||
const gridTool: Tool = {
|
||||
id: "grid",
|
||||
labelKey: "tool.grid",
|
||||
hintKey: () => "tool.grid.hint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
// Wipeout/Maskenregion: Platzhalter-Werkzeug, gekoppelt an den
|
||||
// `wipeout`-Befehl (Punktfolge, schliesst automatisch → weisse Maskenfläche).
|
||||
// Freies 2D-Element (nicht floorOnly).
|
||||
const wipeoutTool: Tool = {
|
||||
id: "wipeout",
|
||||
labelKey: "tool.wipeout",
|
||||
hintKey: () => "tool.wipeout.hint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
// Text: Platzhalter-Werkzeug, gekoppelt an den `text`-Befehl (Ankerpunkt →
|
||||
// getippte Zeile). Wie Kreis/Bogen nicht floorOnly (freies 2D-Element).
|
||||
const textTool: Tool = {
|
||||
id: "text",
|
||||
labelKey: "tool.text",
|
||||
hintKey: () => "tool.text.hint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
// Leader: Platzhalter-Werkzeug, gekoppelt an den `leader`-Befehl (Zielpunkt →
|
||||
// Textanker → getippte Zeile, wie Text). Freies 2D-Element (nicht floorOnly).
|
||||
const leaderTool: Tool = {
|
||||
id: "leader",
|
||||
labelKey: "tool.leader",
|
||||
hintKey: () => "tool.leader.hint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
// Text-entlang-Pfad: Platzhalter-Werkzeug, gekoppelt an den `textpath`-Befehl
|
||||
// (≥2 Pfadpunkte → getippte Zeile, wie Text). Freies 2D-Element.
|
||||
const textpathTool: Tool = {
|
||||
id: "textpath",
|
||||
labelKey: "tool.textpath",
|
||||
hintKey: () => "tool.textpath.hint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
// Textspalte: Platzhalter-Werkzeug, gekoppelt an den `textbox`-Befehl (Anker →
|
||||
// Spaltenbreite → getippte Zeile). Freies 2D-Element (nicht floorOnly).
|
||||
const textboxTool: Tool = {
|
||||
id: "textbox",
|
||||
labelKey: "tool.textbox",
|
||||
hintKey: () => "tool.textbox.hint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
// Bild einfügen: KEIN Klick-Platzieren wie die übrigen Zeichen-Werkzeuge —
|
||||
// die Datei-Auswahl ist async (Dateidialog), daher fängt `onSelectTool`
|
||||
// (App.tsx) die ID VOR der normalen Werkzeug-Aktivierung ab und öffnet direkt
|
||||
// den Datei-Dialog (s. dortigen Kommentar). Dieses Objekt existiert nur, damit
|
||||
// `TOOLS`/`ToolsPanel` eine vollständige Abbildung + Label/Hint haben.
|
||||
const imageTool: Tool = {
|
||||
id: "image",
|
||||
labelKey: "tool.image",
|
||||
hintKey: () => "tool.image.hint",
|
||||
init: () => ({ phase: "idle" }),
|
||||
onClick: (s) => [s, { draft: null }],
|
||||
onMove: (s) => [s, { draft: null }],
|
||||
onCommitGesture: (s) => [s, { draft: null, done: true }],
|
||||
onCancel: (s) => [s, { draft: null, done: true }],
|
||||
};
|
||||
|
||||
// ── Registry ─────────────────────────────────────────────────────────────────
|
||||
|
||||
const TOOLS: Record<ToolId, Tool> = {
|
||||
select: selectTool,
|
||||
wall: wallTool,
|
||||
ceiling: ceilingTool,
|
||||
window: windowTool,
|
||||
door: doorTool,
|
||||
stair: stairTool,
|
||||
room: roomTool,
|
||||
line: lineTool,
|
||||
xline: xlineTool,
|
||||
ray: rayTool,
|
||||
polyline: polylineTool,
|
||||
rect: rectTool,
|
||||
circle: circleTool,
|
||||
arc: arcTool,
|
||||
ellipse: ellipseTool,
|
||||
polygon: polygonTool,
|
||||
block: blockTool,
|
||||
spline: splineTool,
|
||||
bezier: bezierTool,
|
||||
dimension: dimensionTool,
|
||||
kote: koteTool,
|
||||
detailref: detailrefTool,
|
||||
scalebar: scalebarTool,
|
||||
revcloud: revcloudTool,
|
||||
pointmarker: pointmarkerTool,
|
||||
grid: gridTool,
|
||||
wipeout: wipeoutTool,
|
||||
text: textTool,
|
||||
leader: leaderTool,
|
||||
textpath: textpathTool,
|
||||
textbox: textboxTool,
|
||||
image: imageTool,
|
||||
};
|
||||
|
||||
/** Liefert das Werkzeug zur ID. */
|
||||
export function getTool(id: ToolId): Tool {
|
||||
return TOOLS[id];
|
||||
export interface ToolInfo {
|
||||
/** UI-Label-Key (i18n), z. B. „tool.wall". */
|
||||
labelKey: string;
|
||||
/** Hinweis-Key (Tooltip). */
|
||||
hintKey: string;
|
||||
/** Nur auf Geschossen aktiv? (Wand braucht ein Geschoss.) */
|
||||
floorOnly?: boolean;
|
||||
/** Gekoppelter Engine-Befehl; fehlt bei „select" und „image". */
|
||||
command?: string;
|
||||
}
|
||||
|
||||
const TOOLS: Record<ToolId, ToolInfo> = {
|
||||
select: { labelKey: "tool.select", hintKey: "tool.select.hint" },
|
||||
wall: { labelKey: "tool.wall", hintKey: "tool.wall.firstPoint", floorOnly: true, command: "wall" },
|
||||
ceiling: { labelKey: "tool.ceiling", hintKey: "tool.ceiling.firstPoint", floorOnly: true, command: "ceiling" },
|
||||
window: { labelKey: "tool.window", hintKey: "tool.window.hint", floorOnly: true, command: "fenster" },
|
||||
door: { labelKey: "tool.door", hintKey: "tool.door.hint", floorOnly: true, command: "tuer" },
|
||||
stair: { labelKey: "tool.stair", hintKey: "tool.stair.hint", floorOnly: true, command: "stair" },
|
||||
room: { labelKey: "tool.room", hintKey: "tool.room.hint", floorOnly: true, command: "room" },
|
||||
line: { labelKey: "tool.line", hintKey: "tool.line.firstPoint", command: "line" },
|
||||
xline: { labelKey: "tool.xline", hintKey: "tool.xline.hint", command: "xline" },
|
||||
ray: { labelKey: "tool.ray", hintKey: "tool.ray.hint", command: "ray" },
|
||||
polyline: { labelKey: "tool.polyline", hintKey: "tool.polyline.firstPoint", command: "polyline" },
|
||||
rect: { labelKey: "tool.rect", hintKey: "tool.rect.firstCorner", command: "rect" },
|
||||
circle: { labelKey: "tool.circle", hintKey: "tool.circle.hint", command: "circle" },
|
||||
arc: { labelKey: "tool.arc", hintKey: "tool.arc.hint", command: "arc" },
|
||||
ellipse: { labelKey: "tool.ellipse", hintKey: "tool.ellipse.hint", command: "ellipse" },
|
||||
polygon: { labelKey: "tool.polygon", hintKey: "tool.polygon.hint", command: "polygon" },
|
||||
block: { labelKey: "tool.block", hintKey: "tool.block.hint", command: "block" },
|
||||
spline: { labelKey: "tool.spline", hintKey: "tool.spline.hint", command: "spline" },
|
||||
bezier: { labelKey: "tool.bezier", hintKey: "tool.bezier.hint", command: "bezier" },
|
||||
dimension: { labelKey: "tool.dimension", hintKey: "tool.dimension.hint", command: "dimension" },
|
||||
kote: { labelKey: "tool.kote", hintKey: "tool.kote.hint", command: "kote" },
|
||||
detailref: { labelKey: "tool.detailref", hintKey: "tool.detailref.hint", command: "detailref" },
|
||||
scalebar: { labelKey: "tool.scalebar", hintKey: "tool.scalebar.hint", command: "scalebar" },
|
||||
revcloud: { labelKey: "tool.revcloud", hintKey: "tool.revcloud.hint", command: "revcloud" },
|
||||
pointmarker: { labelKey: "tool.pointmarker", hintKey: "tool.pointmarker.hint", command: "pointmarker" },
|
||||
grid: { labelKey: "tool.grid", hintKey: "tool.grid.hint", command: "grid" },
|
||||
wipeout: { labelKey: "tool.wipeout", hintKey: "tool.wipeout.hint", command: "wipeout" },
|
||||
text: { labelKey: "tool.text", hintKey: "tool.text.hint", command: "text" },
|
||||
leader: { labelKey: "tool.leader", hintKey: "tool.leader.hint", command: "leader" },
|
||||
textpath: { labelKey: "tool.textpath", hintKey: "tool.textpath.hint", command: "textpath" },
|
||||
textbox: { labelKey: "tool.textbox", hintKey: "tool.textbox.hint", command: "textbox" },
|
||||
image: { labelKey: "tool.image", hintKey: "tool.image.hint" },
|
||||
};
|
||||
|
||||
/** Beschreibung des Werkzeugs zur ID. */
|
||||
export function toolInfo(id: ToolId): ToolInfo {
|
||||
return TOOLS[id];
|
||||
}
|
||||
@@ -8,10 +8,16 @@
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { commitTransform, rotateGizmoShapes, transformPreview } from "./transform";
|
||||
import type { TransformSelection } from "./transform";
|
||||
import { rotateGizmoShapes, transformOps, transformPreview } from "./transform";
|
||||
import type { CopyMode, TransformOp, TransformSelection } from "./transform";
|
||||
import { applyOps } from "../core";
|
||||
import type { Ceiling, Drawing2D, ExtrudedSolid, Project, Roof, Room, Stair } from "../model/types";
|
||||
|
||||
/** Transformation über die Kern-Ops anwenden (wie der Befehl beim Commit). */
|
||||
function commitTransform(p: Project, sel: TransformSelection, op: TransformOp, pts: { x: number; y: number }[], mode: CopyMode, count: number): Project {
|
||||
return applyOps(p, transformOps(p, sel, op, pts, mode, count));
|
||||
}
|
||||
|
||||
function project(drawings: Drawing2D[]): Project {
|
||||
return {
|
||||
id: "t",
|
||||
|
||||
+1
-14
@@ -14,7 +14,6 @@ import type { DraftShape } from "./types";
|
||||
import { uniqueStamp } from "./types";
|
||||
import { decodeShapes, pair } from "./coreCmd";
|
||||
import type { CommandSelection } from "../commands/types";
|
||||
import { applyOps } from "../core";
|
||||
import type { CoreOp, ProjectMutation } from "../core";
|
||||
import { cmdMutation, documentFor } from "../core/document";
|
||||
import { DEFAULT_SCALE_DENOMINATOR } from "../model/dimension";
|
||||
@@ -220,20 +219,8 @@ export function transformOps(
|
||||
return documentFor(project).cmdOps(transformReq(sel, op, pts, mode, count));
|
||||
}
|
||||
|
||||
/** Wendet die Transformation immutabel auf das Projekt an (Original + Kopien), über {@link transformOps}. */
|
||||
export function commitTransform(
|
||||
project: Project,
|
||||
sel: TransformSelection,
|
||||
op: TransformOp,
|
||||
pts: Vec2[],
|
||||
mode: CopyMode,
|
||||
count: number,
|
||||
): Project {
|
||||
return applyOps(project, transformOps(project, sel, op, pts, mode, count));
|
||||
}
|
||||
|
||||
/**
|
||||
* Wie {@link commitTransform}, als Projekt → Projekt-Funktion mit mitgeführten Ops (`opsMutation`) —
|
||||
* Die Transformation ({@link transformOps}) als Projekt → Projekt-Funktion mit mitgeführten Ops (`opsMutation`) —
|
||||
* für `CommandResult.commit`: `setProject` übergibt die Ops ohne Projekt-Differenz an den Kern.
|
||||
*/
|
||||
export function transformMutation(
|
||||
|
||||
+6
-79
@@ -1,12 +1,8 @@
|
||||
// Tool-System für das aktive Zeichnen im Grundriss (docs/design/drawing-tools.md).
|
||||
//
|
||||
// Werkzeuge sind reine Funktionen über einen internen `ToolState`
|
||||
// (Discriminated Union je Werkzeug). Sie greifen NUR über `commit(project)`
|
||||
// immutabel auf das Modell zu und schreiben nie Plan-Primitive — die Ansicht
|
||||
// bleibt abgeleitet. Bezeichner englisch, UI-Text via t().
|
||||
// Gemeinsame Typen des Zeichnens im Grundriss: Werkzeug-IDs, Snap, Vorschau (Draft) und die
|
||||
// PlanView-Brücke. Das Zeichnen selbst läuft über die Befehls-Engine (`src/commands`, [123]).
|
||||
// Bezeichner englisch, UI-Text via t().
|
||||
|
||||
import type { DrawingLevel, Project, Vec2 } from "../model/types";
|
||||
import type { ProjectMutation } from "../core";
|
||||
import type { Vec2 } from "../model/types";
|
||||
|
||||
/** Werkzeug-Identität. */
|
||||
export type ToolId =
|
||||
@@ -192,35 +188,7 @@ export const DEFAULT_SNAP: SnapSettings = {
|
||||
hoverDivideCount: 2,
|
||||
};
|
||||
|
||||
// ── Werkzeug-Schnittstelle ──────────────────────────────────────────────────
|
||||
|
||||
/** Live-Kontext, den ein Werkzeug bei jedem Schritt erhält. */
|
||||
export interface ToolContext {
|
||||
project: Project;
|
||||
/** Aktives Geschoss/die aktive Zeichnungsebene (Ziel der neuen Elemente). */
|
||||
level: DrawingLevel;
|
||||
/** Default-Kategorie-Code für neue Elemente. */
|
||||
defaultCategoryCode: string;
|
||||
/** Aktiver Wandtyp für das Wand-Werkzeug. */
|
||||
activeWallTypeId: string;
|
||||
/** Aktiver Linienstil-Code für 2D-Primitive. */
|
||||
activeLineStyleId: string;
|
||||
}
|
||||
|
||||
/** Ein an einer Modellposition ausgelöstes Pointer-Ereignis (fertig gesnappt). */
|
||||
export interface ToolPointer {
|
||||
/** Roher Modellpunkt (vor Snapping), in Metern. */
|
||||
raw: Vec2;
|
||||
/** Gesnappter Punkt + Marker-Info; null = kein Snap. */
|
||||
snap: SnapResult | null;
|
||||
/** Effektiver Punkt = snap?.point ?? raw. */
|
||||
point: Vec2;
|
||||
shift: boolean;
|
||||
ctrl: boolean;
|
||||
alt: boolean;
|
||||
/** 0 = links, 2 = rechts. */
|
||||
button: number;
|
||||
}
|
||||
// ── Vorschau (Draft) ────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Leichte Vorschau-Form (Rubber-Band). Bewusst NICHT der volle `Primitive`-Typ
|
||||
@@ -272,50 +240,9 @@ export interface ToolDraft {
|
||||
measure?: MeasurementReadout;
|
||||
}
|
||||
|
||||
/** Was ein Werkzeug-Schritt nach außen meldet. */
|
||||
export interface ToolResult {
|
||||
/** Neuer Vorschau-Zustand; null = nichts zu zeigen. */
|
||||
draft: ToolDraft | null;
|
||||
/** Bei Abschluss: Änderung mit mitgeführten Ops (`opsMutation`), die App über setProject anwendet. */
|
||||
commit?: ProjectMutation;
|
||||
/** true → Werkzeug ist fertig und kehrt in seinen Ruhezustand zurück. */
|
||||
done?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interner Zustand eines Werkzeugs. Basis-Form; jedes Werkzeug verfeinert sie zu
|
||||
* einer eigenen Discriminated Union (z. B. WallState) und castet beim Eintritt.
|
||||
*/
|
||||
export interface ToolState {
|
||||
phase: string;
|
||||
}
|
||||
|
||||
/** Die Werkzeug-Schnittstelle (reine Funktionen über einen internen State). */
|
||||
export interface Tool {
|
||||
id: ToolId;
|
||||
/** UI-Label-Key (i18n), z. B. „tool.wall". */
|
||||
labelKey: string;
|
||||
/** Statuszeilen-Hinweis-Key je Phase. */
|
||||
hintKey: (state: ToolState) => string;
|
||||
/** Nur auf Geschossen aktiv? (Wand braucht ein Geschoss.) */
|
||||
floorOnly?: boolean;
|
||||
/** Initialer Ruhezustand. */
|
||||
init(): ToolState;
|
||||
/** Klick (Punkt setzen). */
|
||||
onClick(state: ToolState, p: ToolPointer, ctx: ToolContext): [ToolState, ToolResult];
|
||||
/** Bewegung (Hover/Drag): nur Vorschau, nie Commit. */
|
||||
onMove(state: ToolState, p: ToolPointer, ctx: ToolContext): [ToolState, ToolResult];
|
||||
/** Doppelklick/Enter/Rechtsklick: mehrteilige Werkzeuge abschließen. */
|
||||
onCommitGesture(state: ToolState, ctx: ToolContext): [ToolState, ToolResult];
|
||||
/** Esc: Entwurf verwerfen, im selben Werkzeug bleiben. */
|
||||
onCancel(state: ToolState): [ToolState, ToolResult];
|
||||
/** Backspace: letzten gesetzten Punkt zurücknehmen (optional). */
|
||||
onUndoPoint?(state: ToolState, ctx: ToolContext): [ToolState, ToolResult];
|
||||
}
|
||||
|
||||
// ── PlanView-Brücke ──────────────────────────────────────────────────────────
|
||||
// PlanView meldet rohe Modellpunkte + die aktuelle Pixel/Meter-Skala nach oben;
|
||||
// der ToolController (App) snappt, fährt das Werkzeug und hält den `draft`,
|
||||
// App reicht sie an die Befehls-Engine (Snap, Schritt) und hält den `draft`,
|
||||
// den PlanView als Overlay zeichnet. So bleibt die Snap-/Modell-Logik außerhalb
|
||||
// der reinen Darstellungs-/Eingabeschicht.
|
||||
|
||||
|
||||
Reference in new issue
Block a user