[144] Merge: Türen/Fenster verschieben (Befehl, Objekt-Info, Griff mit Länge)
This commit is contained in:
22 files changed
+451
-12
No files matched your search
@@ -95,7 +95,7 @@ export const scaleCommand: Command = {
|
||||
onInput: (state, input, ctx): [CommandState, CommandResult] => {
|
||||
const s = state as ScState;
|
||||
if (s.phase === "done") return idle();
|
||||
if (!hasTransformSelection(ctx.selection)) {
|
||||
if (!hasTransformSelection(ctx.selection, "scale")) {
|
||||
return [{ phase: "done", lastPoint: null } as ScDone, { draft: null, done: true }];
|
||||
}
|
||||
|
||||
|
||||
@@ -143,4 +143,28 @@ describe("Transformations-Befehle", () => {
|
||||
expect(engine.isActive()).toBe(false);
|
||||
expect(lines(log.project)[0].b).toEqual({ x: 2, y: 0 });
|
||||
});
|
||||
|
||||
// [144] Tür allein gewählt: Bewegen startet, getippte Distanz schiebt sie entlang der Wand (W1: x 0…5).
|
||||
it("Öffnung: Bewegen mit getippter Distanz gleitet entlang der Wand; Drehen/Spiegeln lehnen ab", () => {
|
||||
const sel: CommandSelection = { wallIds: [], drawingId: null, openingIds: ["D1"] };
|
||||
const { engine, log } = setup(sel);
|
||||
const door = () => log.project.openings!.find((o) => o.id === "D1")!;
|
||||
expect(door().position).toBe(0.8);
|
||||
expect(engine.start("move")).toBe(true);
|
||||
engine.pick({ x: 1.25, y: 0 });
|
||||
engine.move({ x: 3, y: 0 });
|
||||
engine.submitText("0.5");
|
||||
expect(engine.isActive()).toBe(false);
|
||||
expect(door().position).toBeCloseTo(1.3, 9);
|
||||
expect(door().hostWallId).toBe("W1");
|
||||
// Relative Koordinate quer zur Wand: nur der Anteil längs zählt; am Wandende geklemmt.
|
||||
engine.start("move");
|
||||
engine.pick({ x: 0, y: 0 });
|
||||
engine.submitText("@9,0.05");
|
||||
expect(door().position).toBeCloseTo(5 - 0.9, 9);
|
||||
for (const op of ["rotate", "mirror"]) {
|
||||
expect(engine.start(op)).toBe(false);
|
||||
}
|
||||
expect(log.notes).toEqual(["transform.needSelection", "transform.needSelection"]);
|
||||
});
|
||||
});
|
||||
@@ -93,7 +93,7 @@ export function makeTransformCommand(op: TransformCmdOp, labelKey: TranslationKe
|
||||
|
||||
const input = (state: CommandState, inp: CmdInput, ctx: CommandContext): [CommandState, CommandResult] => {
|
||||
const s = state as TrState;
|
||||
if (s.phase === "done" || !hasTransformSelection(ctx.selection)) return done();
|
||||
if (s.phase === "done" || !hasTransformSelection(ctx.selection, op)) return done();
|
||||
if (inp.kind === "option") {
|
||||
const mode = MODES.find((m) => m.id === inp.id);
|
||||
if (!mode) return [s, { draft: s.cursor ? preview(s, s.cursor, ctx).draft : null }];
|
||||
|
||||
@@ -333,7 +333,7 @@ export class CommandEngine {
|
||||
this.host.notify?.(blocked, undefined, "warning");
|
||||
return false;
|
||||
}
|
||||
if (cmd.needsSelection && !hasTransformSelection(this.host.context(null).selection)) {
|
||||
if (cmd.needsSelection && !hasTransformSelection(this.host.context(null).selection, cmd.name)) {
|
||||
this.host.notify?.(cmd.needsSelection);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -84,6 +84,8 @@ export interface CommandSelection {
|
||||
stairIds?: string[];
|
||||
/** Gewählte Räume (Mehrfachauswahl). */
|
||||
roomIds?: string[];
|
||||
/** Gewählte Öffnungen ([144]): Wandöffnungen gleiten beim Verschieben entlang ihrer Wand. */
|
||||
openingIds?: string[];
|
||||
}
|
||||
|
||||
/** Live-Kontext, den ein Befehl bei jedem Schritt erhält (analog ToolContext). */
|
||||
|
||||
@@ -800,6 +800,7 @@ export const de = {
|
||||
"objinfo.opening.hostAngle": "Drehung (waagrechte Fläche)",
|
||||
"objinfo.opening.slope": "Neigung der Fläche",
|
||||
"objinfo.opening.position": "Position (ab Wandanfang)",
|
||||
"objinfo.opening.positionEnd": "Abstand ab Wandende",
|
||||
"objinfo.opening.width": "Breite",
|
||||
"objinfo.opening.height": "Höhe",
|
||||
"objinfo.opening.sill": "Brüstung",
|
||||
|
||||
@@ -799,6 +799,7 @@ export const en: Record<TranslationKey, string> = {
|
||||
"objinfo.opening.hostAngle": "Rotation (level surface)",
|
||||
"objinfo.opening.slope": "Surface slope",
|
||||
"objinfo.opening.position": "Position (from wall start)",
|
||||
"objinfo.opening.positionEnd": "Distance from wall end",
|
||||
"objinfo.opening.width": "Width",
|
||||
"objinfo.opening.height": "Height",
|
||||
"objinfo.opening.sill": "Sill height",
|
||||
|
||||
@@ -1650,6 +1650,14 @@ export function OpeningSection({
|
||||
value={opening.position}
|
||||
onCommit={(v) => host.onSetOpeningPosition(v)}
|
||||
/>
|
||||
{/* [144] Gegenstück: Abstand des zweiten Pfostens vom Wandende (nur gerade Wand). */}
|
||||
{opening.wallLength != null && (
|
||||
<DimensionField
|
||||
label={t("objinfo.opening.positionEnd")}
|
||||
value={opening.wallLength - opening.position - opening.width}
|
||||
onCommit={(v) => host.onSetOpeningPosition(opening.wallLength! - v - opening.width)}
|
||||
/>
|
||||
)}
|
||||
<DimensionField
|
||||
label={t("objinfo.opening.width")}
|
||||
value={opening.width}
|
||||
|
||||
@@ -84,6 +84,7 @@ describe("Selection", () => {
|
||||
roofIds: ["r"],
|
||||
stairIds: [],
|
||||
roomIds: [],
|
||||
openingIds: [],
|
||||
});
|
||||
expect(toTransformSelection(s)).toEqual(c);
|
||||
});
|
||||
|
||||
@@ -137,6 +137,7 @@ export function toCommandSelection(sel: Selection): CommandSelection {
|
||||
roofIds: sel.roofs,
|
||||
stairIds: sel.stairs,
|
||||
roomIds: sel.rooms,
|
||||
openingIds: sel.openings,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -155,7 +156,8 @@ export function hasTransformable(sel: Selection): boolean {
|
||||
sel.ceilings.length > 0 ||
|
||||
sel.roofs.length > 0 ||
|
||||
sel.stairs.length > 0 ||
|
||||
sel.rooms.length > 0
|
||||
sel.rooms.length > 0 ||
|
||||
sel.openings.length > 0
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -211,6 +211,8 @@ export interface OpeningInfo {
|
||||
hostWallName: string;
|
||||
/** Abstand vom Wand-Startpunkt (Meter). */
|
||||
position: number;
|
||||
/** Achslänge der geraden Wirtswand (fehlt bei Bogenwand) — „Abstand ab Wandende“ ([144]). */
|
||||
wallLength?: number;
|
||||
width: number;
|
||||
height: number;
|
||||
/** Brüstungshöhe (Meter); 0 bei Türen. */
|
||||
|
||||
@@ -22,6 +22,10 @@ declare global {
|
||||
polylines: (prefix: string) => { id: string; pts: { x: number; y: number }[] }[];
|
||||
/** [137] Gewählte 2D-Elemente und Gruppen. */
|
||||
selected: () => { drawings: string[]; groups: string[]; all: string };
|
||||
/** [144] Öffnungen (id, Wirtswand, Lage ab Wandanfang). */
|
||||
openings: () => { id: string; hostWallId: string; position: number }[];
|
||||
/** [144] Auswahl setzen (wie ein Klick), z. B. `{ openings: ["D1"] }`. */
|
||||
select: (patch: Record<string, string[]>) => void;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -46,6 +50,8 @@ export function installTestHooks(): void {
|
||||
getState().project.drawings2d.flatMap((d) => (d.geom.shape === "line" ? [{ a: d.geom.a, b: d.geom.b }] : [])),
|
||||
polylines: (prefix) =>
|
||||
getState().project.drawings2d.flatMap((d) => (d.id.startsWith(prefix) && d.geom.shape === "polyline" ? [{ id: d.id, pts: d.geom.pts }] : [])),
|
||||
openings: () => (getState().project.openings ?? []).map((o) => ({ id: o.id, hostWallId: o.hostWallId, position: o.position })),
|
||||
select: (patch) => getState().setSelection(patch),
|
||||
selected: () => ({ drawings: [...getState().selection.drawings], groups: [...getState().selection.groups], all: JSON.stringify(getState().selection) }),
|
||||
};
|
||||
}
|
||||
@@ -44,6 +44,7 @@ function sheetOnlySelection(level: DrawingLevel, sel: TransformSelection): Trans
|
||||
roofIds: [],
|
||||
stairIds: [],
|
||||
roomIds: [],
|
||||
openingIds: [],
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -380,6 +380,18 @@ export function useGripEditing(opts: {
|
||||
return out;
|
||||
})();
|
||||
|
||||
// Einheitsrichtung der Wirtswand, wenn eine Wandöffnung gewählt ist (sonst null).
|
||||
const openingWallDir = (): Vec2 | null => {
|
||||
if (!selectedOpeningId) return null;
|
||||
const op = (project.openings ?? []).find((o) => o.id === selectedOpeningId);
|
||||
const w = op && !op.hostRoofId && !op.hostCeilingId ? project.walls.find((x) => x.id === op.hostWallId) : undefined;
|
||||
if (!w) return null;
|
||||
const dx = w.end.x - w.start.x;
|
||||
const dy = w.end.y - w.start.y;
|
||||
const len = Math.hypot(dx, dy);
|
||||
return len > 1e-9 ? { x: dx / len, y: dy / len } : null;
|
||||
};
|
||||
|
||||
// Nachbar-Griff-Index INNERHALB desselben Elements (für Anker-Auflösung).
|
||||
// null = kein Nachbar möglich (Einzelgriff-Element wie Kreis/Öffnung/Treppe).
|
||||
const neighborGripIndex = (index: number): number | null => {
|
||||
@@ -564,6 +576,10 @@ export function useGripEditing(opts: {
|
||||
// Gemeinsam genutzt vom Tab-Feld-Controller UND dem Shift-Ortho-Bezug UND
|
||||
// dem Cursor-HUD (Länge/Winkel-Anzeige neben der Maus).
|
||||
const resolveGripAnchor = (index: number): Vec2 | null => {
|
||||
// Wandöffnung ([144]): einziger Griff (Mitte) — Bezug ist seine Lage beim Greifen, die getippte
|
||||
// Länge ist also die Verschiebung entlang der Wand.
|
||||
const wallOpening = openingWallDir();
|
||||
if (wallOpening) return gripOriginRef.current ?? grips[index] ?? null;
|
||||
// Bei Mehrfachauswahl gehört der gezogene Griff evtl. NICHT dem einzeln
|
||||
// selektierten `selectedDrawing`, sondern einem anderen Element der
|
||||
// Auswahl — das eigentliche Element über `gripOwners` auflösen.
|
||||
@@ -626,7 +642,16 @@ export function useGripEditing(opts: {
|
||||
if (!info) return;
|
||||
const anchor = resolveGripAnchor(info.index);
|
||||
if (!anchor) return; // ohne Anker keine polare Eingabe möglich
|
||||
const wallDir = openingWallDir();
|
||||
setGripEdit((prev) => {
|
||||
if (!prev && wallDir) {
|
||||
// Öffnung ([144]): Richtung = Wandrichtung (bzw. Gegenrichtung, je nach bisherigem Zug), damit
|
||||
// die getippte Länge genau die Strecke entlang der Wand ist.
|
||||
const g = grips[info.index];
|
||||
const along = (g.x - anchor.x) * wallDir.x + (g.y - anchor.y) * wallDir.y;
|
||||
const deg = (Math.atan2(wallDir.y, wallDir.x) * 180) / Math.PI + (along < 0 ? 180 : 0);
|
||||
return { anchor, active: "length", locks: { length: Math.abs(along), angle: ((deg % 360) + 360) % 360 } };
|
||||
}
|
||||
if (!prev) {
|
||||
const { length, angleDeg: angle } = gripPolar(anchor, grips[info.index]);
|
||||
return { anchor, active: "length", locks: { length, angle } };
|
||||
|
||||
@@ -582,8 +582,8 @@ export function useTransformShortcuts(
|
||||
return;
|
||||
}
|
||||
// Transformierbar sind Wände, 2D-Zeichnungen, extrudierte Körper, Stützen,
|
||||
// Decken/Dächer/Treppen/Räume. Öffnungen laufen bewusst NICHT hierüber, sondern über ihre
|
||||
// eigenen Bewegpunkte (Grips) — sie sind wandgebunden. Ohne Auswahl: still.
|
||||
// Decken/Dächer/Treppen/Räume und ([144]) Öffnungen — die gleiten beim Verschieben entlang ihrer
|
||||
// Wand; Drehen/Spiegeln lehnt die Engine für sie allein mit Hinweis ab. Ohne Auswahl: still.
|
||||
if (!hasTransformSelection) return;
|
||||
const op = matchesShortcut(e, "transformMove", overrides)
|
||||
? "move"
|
||||
|
||||
@@ -101,6 +101,8 @@ function singleTransformSel(kind: string, id: string): TransformSelection | null
|
||||
if (kind === "roof") return { wallIds: [], drawingId: null, roofIds: [id] };
|
||||
if (kind === "stair") return { wallIds: [], drawingId: null, stairIds: [id] };
|
||||
if (kind === "room") return { wallIds: [], drawingId: null, roomIds: [id] };
|
||||
// [144] Öffnung: X/Y im Objekt-Info verschiebt sie entlang (bzw. in eine andere) Wand.
|
||||
if (kind === "opening") return { wallIds: [], drawingId: null, openingIds: [id] };
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -949,8 +951,11 @@ export function usePanelHostBase(opts: {
|
||||
updateOpening(selection.id, { sillHeight });
|
||||
},
|
||||
onSetOpeningPosition: (position) => {
|
||||
if (selection?.kind === "opening" && position >= 0)
|
||||
updateOpening(selection.id, { position });
|
||||
if (selection?.kind !== "opening" || !Number.isFinite(position)) return;
|
||||
// [144] In der Wand halten: auf [0, Wandlänge − Breite] klemmen (Bogenwand: nur ≥ 0).
|
||||
const o = selection.opening;
|
||||
const max = o?.wallLength != null ? Math.max(0, o.wallLength - o.width) : Infinity;
|
||||
updateOpening(selection.id, { position: Math.min(max, Math.max(0, position)) });
|
||||
},
|
||||
onSetOpeningSwingAngle: (swingAngle) => {
|
||||
if (selection?.kind === "opening" && swingAngle > 0)
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
// [144] Öffnungen allein verschieben, am komplexen Musterhaus: jede Tür/jedes Fenster in einer geraden
|
||||
// Wand gleitet um die Projektion des Verschiebevektors auf die Wandachse (geklemmt), Wirt bleibt.
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildComplexSampleProject } from "../model/sampleProjectComplex";
|
||||
import { transformMutation } from "./transform";
|
||||
|
||||
describe("Öffnungen verschieben (Musterhaus komplex)", () => {
|
||||
it("jede Wandöffnung gleitet entlang ihrer Wand", () => {
|
||||
const p = buildComplexSampleProject();
|
||||
const walls = new Map(p.walls.map((w) => [w.id, w]));
|
||||
const ops = (p.openings ?? []).filter((o) => {
|
||||
const w = walls.get(o.hostWallId);
|
||||
return w && !w.bulge && !o.locked && !o.hostRoofId && !o.hostCeilingId;
|
||||
});
|
||||
expect(ops.length).toBeGreaterThan(5);
|
||||
for (const o of ops) {
|
||||
const w = walls.get(o.hostWallId)!;
|
||||
const len = Math.hypot(w.end.x - w.start.x, w.end.y - w.start.y);
|
||||
const u = { x: (w.end.x - w.start.x) / len, y: (w.end.y - w.start.y) / len };
|
||||
// 0.3 m längs + 0.02 m quer (bleibt in der Wand).
|
||||
const d = { x: u.x * 0.3 - u.y * 0.02, y: u.y * 0.3 + u.x * 0.02 };
|
||||
const next = transformMutation({ wallIds: [], drawingId: null, openingIds: [o.id] }, "move", [{ x: 0, y: 0 }, d], "move", 1)(p);
|
||||
const m = next.openings!.find((x) => x.id === o.id)!;
|
||||
expect(m.hostWallId, o.id).toBe(o.hostWallId);
|
||||
expect(m.position, o.id).toBeCloseTo(Math.min(len - o.width, o.position + 0.3), 9);
|
||||
}
|
||||
});
|
||||
});
|
||||
+10
-2
@@ -51,6 +51,8 @@ export interface TransformSelection {
|
||||
stairIds?: string[];
|
||||
/** Gewählte Räume (Mehrfachauswahl). */
|
||||
roomIds?: string[];
|
||||
/** Gewählte Öffnungen ([144]): nur Verschieben, entlang der Wirtswand (Kern `slide_opening`). */
|
||||
openingIds?: string[];
|
||||
}
|
||||
|
||||
/** Auswahl (Befehlskontext) → TransformSelection (gleiche Form, alle Elementarten). */
|
||||
@@ -65,12 +67,18 @@ export function toTransformSel(sel: CommandSelection): TransformSelection {
|
||||
roofIds: sel.roofIds,
|
||||
stairIds: sel.stairIds,
|
||||
roomIds: sel.roomIds,
|
||||
openingIds: sel.openingIds,
|
||||
};
|
||||
}
|
||||
|
||||
/** Hat die Auswahl überhaupt etwas Transformierbares? */
|
||||
export function hasTransformSelection(sel: CommandSelection): boolean {
|
||||
/**
|
||||
* Hat die Auswahl überhaupt etwas Transformierbares? Öffnungen zählen nur beim Verschieben/Kopieren
|
||||
* ([144]); für Drehen/Spiegeln/Skalieren (`op`) nicht — eine Öffnung allein gleitet nur in der Wand.
|
||||
*/
|
||||
export function hasTransformSelection(sel: CommandSelection, op?: string): boolean {
|
||||
const openings = op !== "rotate" && op !== "mirror" && op !== "scale" && (sel.openingIds?.length ?? 0) > 0;
|
||||
return (
|
||||
openings ||
|
||||
sel.wallIds.length > 0 ||
|
||||
sel.drawingId !== null ||
|
||||
(sel.drawingIds?.length ?? 0) > 0 ||
|
||||
|
||||
Reference in new issue
Block a user