Files
DOSSIER/src/commands/cmds/explode.ts
T
Claude ffc1e3a074 [K4] S3: Transformation und 2D-Editier-Befehle im Kern (cmd_transform.rs, cmd_edit.rs)
Verschieben/Drehen/Spiegeln/Skalieren/Reihe (alle Elementarten, Vorschau je Mausschritt),
Ausrichten/Verteilen, Block definieren, Trim, Extend, Verrunden, Fasen, Bruch, Offset, Join,
Auflösen rechnen Treffer, Vorschau und Ops im Kern; TS behält die Zustandsautomaten.
cmdMutation + doc_cmd_commit: rechnen und anwenden in einem Kern-Aufruf. Gelöscht:
geometry/geomTransform.ts, tools/drawingPreview.ts, transformSolid, joinDrawings und die
nicht mehr benutzten Kernel-Fassaden samt Bindungen. Gleichheit über Zufallsprojekte
(temporäre Tests, gelöscht) s. TODO.md.
2026-10-29 12:56:27 +00:00

43 lines
1.8 KiB
TypeScript

// Explode — löst die gewählten 2D-Elemente in ihre Einzelteile auf (Block →
// Teilgeometrien, Polylinie → Segmente, Rechteck → vier Linien). Sofort-Befehl
// ohne Punkt-Eingabe (wie Join/Split): wirkt auf die bestehende Auswahl.
//
// Die eigentliche Zerlegung rechnet der Kern (`cmd_edit.rs`, Fassade `editors/explode.ts`) — dort auch, was
// bewusst NICHT zerlegt wird (Kreis/Ellipse/Spline/Text/…): diese Elemente
// bleiben unverändert stehen, statt zu verschwinden.
import { cmdMutation } from "../../core";
import { uniqueStamp } from "../../tools/types";
import type { Command, CommandContext, CommandResult, CommandSelection, CommandState } from "../types";
/** Gewählte 2D-Elemente (Mehrfachauswahl bevorzugt). */
function selectedDrawingIds(sel: CommandSelection): string[] {
if (sel.drawingIds && sel.drawingIds.length) return sel.drawingIds;
return sel.drawingId ? [sel.drawingId] : [];
}
const done = (): [CommandState, CommandResult] => [
{ phase: "idle", lastPoint: null },
{ draft: null, done: true },
];
export const explodeCommand: Command = {
name: "explode",
labelKey: "cmd.explode.label",
prompt: () => "cmd.explode.label",
accepts: () => [],
options: () => [],
init: (): CommandState => ({ phase: "idle", lastPoint: null }),
autoRun: (ctx: CommandContext): CommandResult => {
const ids = selectedDrawingIds(ctx.selection);
if (ids.length === 0) return { draft: null, done: true };
return { draft: null, done: true, commit: cmdMutation({ cmd: "explode", ids, stamp: uniqueStamp() }) };
},
onInput: (): [CommandState, CommandResult] => done(),
onMove: (state): [CommandState, CommandResult] => [state, { draft: null }],
onConfirm: (): [CommandState, CommandResult] => done(),
onCancel: (): [CommandState, CommandResult] => done(),
};