Neu gezeichnete Elemente treten der aktiven Gruppe bei; Fix: m/s/d bei Mehrfachauswahl
Zeichnet man ein neues Element, während man eine Gruppe betreten hat (Isolation), wird es automatisch Mitglied dieser (innersten) Gruppe — man zeichnet ja sichtlich "in" ihr. Vergleicht vor/nach jedem Commit über alle Elementarten auf neu hinzugekommene IDs, additiv zur eigentlichen Mutation. Separater Fix: Bewegen/Kopieren/Spiegeln/Drehen/Feld (m/s/d-Kürzel und die gleichnamigen Befehle) funktionierten nicht, sobald mehr als ein 2D-Element gewählt war — TransformSelection kannte nur ein einzelnes `drawingId`, das bei Mehrfachauswahl `null` ist. Neues `drawingIds`-Feld (Union mit `drawingId`, dedupliziert) durchgereicht von allen Aufrufstellen (Move/ Copy/Mirror/Array-Befehle, Tastatur-Kürzel-Pfad).
This commit is contained in:
1 parent
3be728c80e
commit
91908b1456
10 files changed
+219
-9
No files matched your search
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* `commitTransform`/`transformPreview` mit MEHREREN gewählten 2D-Elementen
|
||||
* (`TransformSelection.drawingIds`) — Nutzer-Report: "wenn ich zwei Linien
|
||||
* anwähle, dass ich dann m usw nicht verwenden kann". Vorher trug
|
||||
* `TransformSelection` nur ein einzelnes `drawingId`, das bei einer
|
||||
* Mehrfachauswahl (2+ Elemente) `null` war → Bewegen/Kopieren/Spiegeln/
|
||||
* Drehen/Feld griffen gar nicht.
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { commitTransform } from "./transform";
|
||||
import type { TransformSelection } from "./transform";
|
||||
import type { Drawing2D, Project } from "../model/types";
|
||||
|
||||
function project(drawings: Drawing2D[]): Project {
|
||||
return {
|
||||
id: "t",
|
||||
name: "T",
|
||||
lineStyles: [],
|
||||
hatches: [],
|
||||
components: [],
|
||||
wallTypes: [],
|
||||
drawingLevels: [],
|
||||
layers: [],
|
||||
walls: [],
|
||||
doors: [],
|
||||
drawings2d: drawings,
|
||||
};
|
||||
}
|
||||
|
||||
function line(id: string, x: number): Drawing2D {
|
||||
return {
|
||||
id,
|
||||
type: "drawing2d",
|
||||
levelId: "eg",
|
||||
categoryCode: "20",
|
||||
geom: { shape: "line", a: { x, y: 0 }, b: { x: x + 1, y: 0 } },
|
||||
};
|
||||
}
|
||||
|
||||
describe("commitTransform — Mehrfachauswahl (drawingIds)", () => {
|
||||
it("move: verschiebt ALLE gewählten 2D-Elemente, nicht nur eines", () => {
|
||||
const p = project([line("d1", 0), line("d2", 5), line("d3", 10)]);
|
||||
const sel: TransformSelection = { wallIds: [], drawingId: null, drawingIds: ["d1", "d2"] };
|
||||
const next = commitTransform(p, sel, "move", [{ x: 0, y: 0 }, { x: 2, y: 3 }], "move", 1);
|
||||
const d1 = next.drawings2d.find((d) => d.id === "d1")!.geom;
|
||||
const d2 = next.drawings2d.find((d) => d.id === "d2")!.geom;
|
||||
const d3 = next.drawings2d.find((d) => d.id === "d3")!.geom;
|
||||
if (d1.shape === "line") expect(d1.a).toEqual({ x: 2, y: 3 });
|
||||
if (d2.shape === "line") expect(d2.a).toEqual({ x: 7, y: 3 }); // 5+2
|
||||
if (d3.shape === "line") expect(d3.a).toEqual({ x: 10, y: 0 }); // nicht gewählt, unverändert
|
||||
});
|
||||
|
||||
it("copy: dupliziert ALLE gewählten 2D-Elemente (Original bleibt)", () => {
|
||||
const p = project([line("d1", 0), line("d2", 5)]);
|
||||
const sel: TransformSelection = { wallIds: [], drawingId: null, drawingIds: ["d1", "d2"] };
|
||||
const next = commitTransform(p, sel, "move", [{ x: 0, y: 0 }, { x: 1, y: 0 }], "copy", 1);
|
||||
expect(next.drawings2d.length).toBe(4); // 2 Original + 2 Kopien
|
||||
});
|
||||
|
||||
it("array: dupliziert ALLE gewählten 2D-Elemente N-mal", () => {
|
||||
const p = project([line("d1", 0), line("d2", 5)]);
|
||||
const sel: TransformSelection = { wallIds: [], drawingId: null, drawingIds: ["d1", "d2"] };
|
||||
const next = commitTransform(p, sel, "move", [{ x: 0, y: 0 }, { x: 1, y: 0 }], "array", 3);
|
||||
expect(next.drawings2d.length).toBe(8); // 2 Original + 2×3 Kopien
|
||||
});
|
||||
|
||||
it("weiterhin abwärtskompatibel: einzelnes `drawingId` (ohne drawingIds) funktioniert unverändert", () => {
|
||||
const p = project([line("d1", 0)]);
|
||||
const sel: TransformSelection = { wallIds: [], drawingId: "d1" };
|
||||
const next = commitTransform(p, sel, "move", [{ x: 0, y: 0 }, { x: 3, y: 0 }], "move", 1);
|
||||
const d1 = next.drawings2d[0].geom;
|
||||
if (d1.shape === "line") expect(d1.a).toEqual({ x: 3, y: 0 });
|
||||
});
|
||||
|
||||
it("drawingId + drawingIds zusammen werden dedupliziert (kein Doppel-Verschieben)", () => {
|
||||
const p = project([line("d1", 0), line("d2", 5)]);
|
||||
const sel: TransformSelection = { wallIds: [], drawingId: "d1", drawingIds: ["d1", "d2"] };
|
||||
const next = commitTransform(p, sel, "move", [{ x: 0, y: 0 }, { x: 1, y: 0 }], "copy", 1);
|
||||
expect(next.drawings2d.length).toBe(4); // je EINE Kopie pro Element, nicht zwei für d1
|
||||
});
|
||||
});
|
||||
+19
-6
@@ -30,13 +30,27 @@ export type CopyMode = "move" | "copy" | "array" | "distribute"; // U / I / O /
|
||||
/** Welche Auswahl transformiert wird. */
|
||||
export interface TransformSelection {
|
||||
wallIds: string[];
|
||||
/**
|
||||
* Einzeln gewähltes 2D-Element (Legacy-Feld, s. `CommandSelection.drawingId`).
|
||||
* `drawingIds` (Mehrfachauswahl) wird bevorzugt ausgewertet; beide zusammen
|
||||
* ergeben die MENGE der zu transformierenden 2D-Elemente (Union, dedupliziert).
|
||||
*/
|
||||
drawingId: string | null;
|
||||
/** ALLE gewählten 2D-Elemente (Mehrfachauswahl) — s. `CommandSelection.drawingIds`. */
|
||||
drawingIds?: string[];
|
||||
/** Gewählter extrudierter Körper (truck-Integration); nur move.ts setzt ihn. */
|
||||
extrudedSolidId?: string | null;
|
||||
/** Gewählte Stütze (Tragwerk); von move/copy/mirror gesetzt. */
|
||||
columnId?: string | null;
|
||||
}
|
||||
|
||||
/** Vereinigt `drawingId`/`drawingIds` zu einer eindeutigen ID-Menge (dedupliziert). */
|
||||
function drawingIdSet(sel: TransformSelection): Set<string> {
|
||||
const ids = new Set(sel.drawingIds ?? []);
|
||||
if (sel.drawingId) ids.add(sel.drawingId);
|
||||
return ids;
|
||||
}
|
||||
|
||||
/** Wie viele Klickpunkte die Operation braucht (Drehen = 3, sonst 2). */
|
||||
export const requiredPoints = (op: TransformOp): number => (op === "rotate" ? 3 : 2);
|
||||
|
||||
@@ -116,10 +130,8 @@ function gatherItems(project: Project, sel: TransformSelection): AnyItem[] {
|
||||
const items: AnyItem[] = [];
|
||||
const ids = new Set(sel.wallIds);
|
||||
for (const w of project.walls) if (ids.has(w.id)) items.push({ kind: "wall", wall: w });
|
||||
if (sel.drawingId) {
|
||||
const d = project.drawings2d.find((x) => x.id === sel.drawingId);
|
||||
if (d) items.push({ kind: "drawing", drawing: d });
|
||||
}
|
||||
const drawIds = drawingIdSet(sel);
|
||||
for (const d of project.drawings2d) if (drawIds.has(d.id)) items.push({ kind: "drawing", drawing: d });
|
||||
if (sel.extrudedSolidId) {
|
||||
const s = (project.extrudedSolids ?? []).find((x) => x.id === sel.extrudedSolidId);
|
||||
if (s) items.push({ kind: "extrudedSolid", solid: s });
|
||||
@@ -292,9 +304,10 @@ export function commitTransform(
|
||||
if (movesOriginal(mode)) {
|
||||
const fn = transformFn(op, pts, 1);
|
||||
walls = walls.map((w) => (wallIds.has(w.id) ? { ...w, start: fn(w.start), end: fn(w.end) } : w));
|
||||
if (sel.drawingId) {
|
||||
const moveDrawIds = drawingIdSet(sel);
|
||||
if (moveDrawIds.size > 0) {
|
||||
drawings2d = drawings2d.map((d) =>
|
||||
d.id === sel.drawingId ? { ...d, geom: mvGeom(d.geom, fn) } : d,
|
||||
moveDrawIds.has(d.id) ? { ...d, geom: mvGeom(d.geom, fn) } : d,
|
||||
);
|
||||
}
|
||||
if (sel.extrudedSolidId) {
|
||||
|
||||
Reference in new issue
Block a user