[288] Fangpunkte und Griffe wie Vectorworks: Fangsymbol je Art mit Kontrastrand und Hinweis-Schildchen, Auswahlgriffe als Quadrate, Kanten-Anfasser erst nach Kantenauswahl (zweiter Klick, Esc hebt auf)

This commit is contained in:
Claude committed 2026-11-18 21:49:20 +00:00
1 parent 4daef2990f
commit 140e30daae
22 files changed
+569 -213

No files matched your search

+8
View File
@@ -67,6 +67,14 @@ export const MARQUEE_THRESHOLD_PX = 4;
// Trefferradius (Bildschirm-Pixel) für das Greifen eines Editier-Griffs.
export const GRIP_HIT_PX = 9;
/**
* [288] Halbe Kantenlänge (Bildschirm-px) eines Auswahlgriffs (Vectorworks-Quadrat): fest, unabhängig vom Zoom.
* Einfüge-/Mittelgriffe kleiner, Hover grösser.
*/
export function gripSquareHalfPx(insert: boolean, hover: boolean): number {
const base = insert ? 3 : 4;
return hover ? base + 1.5 : base;
}
// Toleranz (Bildschirm-Pixel) für die Linien-Auswahl von 2D-Zeichenelementen.
export const LINE_PICK_PX = 6;
@@ -0,0 +1,46 @@
import { describe, expect, it } from "vitest";
import type { EdgeGrip } from "../../../model/types";
import { edgeHitAt, edgeKey, edgeSelStep, selectedEdgeOf } from "./edgeSelection";
// Quadrat 0..10 (Bildschirm = Modell × 10, damit Pixel-Toleranzen greifbar sind).
const sq = [
{ x: 0, y: 0 },
{ x: 10, y: 0 },
{ x: 10, y: 10 },
{ x: 0, y: 10 },
];
const edges: EdgeGrip[] = sq.map((a, i) => {
const b = sq[(i + 1) % 4];
return { mid: { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 }, normal: { x: 0, y: 0 }, aIndex: i, bIndex: (i + 1) % 4, a, b };
});
const toClient = (v: { x: number; y: number }) => ({ x: v.x * 10, y: v.y * 10 });
describe("[288] Kantenauswahl", () => {
it("Treffer auf der Kante innerhalb der Pixel-Toleranz, sonst keiner", () => {
expect(edgeHitAt(edges, toClient, { x: 30, y: 4 })?.aIndex).toBe(0);
expect(edgeHitAt(edges, toClient, { x: 104, y: 70 })?.aIndex).toBe(1);
expect(edgeHitAt(edges, toClient, { x: 50, y: 50 })).toBeNull();
expect(edgeHitAt(edges, toClient, { x: 30, y: 9 })).toBeNull();
});
it("Schlüssel unterscheidet Eigentümer bei gleichen Indizes", () => {
const a = { ...edges[0], owner: { wallId: "w1" } };
const b = { ...edges[0], owner: { drawingId: "d1" } };
expect(edgeKey(a)).not.toBe(edgeKey(b));
});
it("Zustand: zweiter Klick wählt, gleiche Kante läuft durch, daneben hebt auf, Esc hebt auf", () => {
let s = edgeSelStep(null, { kind: "click", hit: edges[1] });
expect(s).toEqual({ key: edgeKey(edges[1]), consumed: true });
expect(selectedEdgeOf(edges, s.key)).toBe(edges[1]);
s = edgeSelStep(s.key, { kind: "click", hit: edges[1] });
expect(s.consumed).toBe(false);
expect(s.key).toBe(edgeKey(edges[1]));
s = edgeSelStep(s.key, { kind: "click", hit: edges[2] });
expect(s).toEqual({ key: edgeKey(edges[2]), consumed: true });
expect(edgeSelStep(s.key, { kind: "escape" })).toEqual({ key: null, consumed: true });
expect(edgeSelStep(null, { kind: "escape" })).toEqual({ key: null, consumed: false });
expect(edgeSelStep(s.key, { kind: "click", hit: null })).toEqual({ key: null, consumed: false });
expect(edgeSelStep(s.key, { kind: "edges", edges: edges.slice(0, 2) }).key).toBeNull();
});
});
+84
View File
@@ -0,0 +1,84 @@
// [288] Kantenauswahl im Grundriss (Vectorworks-Arbeitsweise): der Anfasser zum Parallelverschieben erscheint nicht
// mehr an allen Kanten, sondern erst an EINER gewählten Kante. Ablauf: Element wählen → zweiter Klick auf eine seiner
// Kanten markiert sie (hervorgehoben + Anfasser) → Anfasser ziehen (Fang, getippter Abstand) → Esc hebt die
// Kantenauswahl auf. Reine Logik (Schlüssel, Treffer, Zustandsübergänge), die Ansicht hält nur den Schlüssel.
import type { EdgeGrip, Vec2 } from "../../../model/types";
/** Bildschirm-Toleranz (px) für den Klick auf eine Kante. */
export const EDGE_PICK_PX = 6;
/** Stabiler Schlüssel einer Kante: Eigentümer (Mehrfachauswahl) + Eckpunkt-Indizes. */
export function edgeKey(e: EdgeGrip): string {
return `${e.owner?.wallId ?? ""}|${e.owner?.drawingId ?? ""}|${e.aIndex}|${e.bIndex}`;
}
/** Abstand Punkt → Strecke (gleiche Einheit wie die Eingaben). */
function distToSeg(p: Vec2, a: Vec2, b: Vec2): number {
const dx = b.x - a.x;
const dy = b.y - a.y;
const l2 = dx * dx + dy * dy;
const t = l2 > 0 ? Math.max(0, Math.min(1, ((p.x - a.x) * dx + (p.y - a.y) * dy) / l2)) : 0;
return Math.hypot(p.x - (a.x + t * dx), p.y - (a.y + t * dy));
}
/**
* Kante unter dem Klick: nächste Kante, deren Strecke (am Bildschirm) höchstens `tolPx` vom Klick entfernt ist.
* `toClient` rechnet Modell-Meter in Client-Pixel. Kanten ohne Endpunkte werden übergangen.
*/
export function edgeHitAt(
edges: readonly EdgeGrip[] | undefined,
toClient: (v: Vec2) => Vec2,
click: Vec2,
tolPx: number = EDGE_PICK_PX,
): EdgeGrip | null {
if (!edges) return null;
let best: EdgeGrip | null = null;
let bestD = tolPx;
for (const e of edges) {
if (!e.a || !e.b) continue;
const d = distToSeg(click, toClient(e.a), toClient(e.b));
if (d <= bestD) {
bestD = d;
best = e;
}
}
return best;
}
/** Ergebnis eines Übergangs: neuer Schlüssel + ob das Ereignis verbraucht ist (kein Auswählen/Esc-Aufheben mehr). */
export interface EdgeSelStep {
key: string | null;
consumed: boolean;
}
/**
* Zustandsübergang der Kantenauswahl.
* - `click` mit Kante: neue Kante wählen (verbraucht den Klick); dieselbe Kante erneut: nicht verbraucht (der
* Klick läuft weiter, z. B. zum Durchschalten überlagerter Objekte), Kante bleibt.
* - `click` ohne Kante: Kantenauswahl aufheben, Klick nicht verbraucht (normales Wählen).
* - `escape`: hebt eine bestehende Kantenauswahl auf und verbraucht die Taste (die Elementauswahl bleibt).
* - `edges`: die aktuellen Kanten der Auswahl; fehlt die gewählte Kante darin, ist sie weg.
*/
export function edgeSelStep(
cur: string | null,
ev: { kind: "click"; hit: EdgeGrip | null } | { kind: "escape" } | { kind: "edges"; edges: readonly EdgeGrip[] | undefined },
): EdgeSelStep {
switch (ev.kind) {
case "click": {
if (!ev.hit) return { key: null, consumed: false };
const k = edgeKey(ev.hit);
return k === cur ? { key: cur, consumed: false } : { key: k, consumed: true };
}
case "escape":
return cur ? { key: null, consumed: true } : { key: null, consumed: false };
case "edges":
return { key: cur && ev.edges?.some((e) => edgeKey(e) === cur) ? cur : null, consumed: false };
}
}
/** Die gewählte Kante in den aktuellen Kanten-Griffen (oder null). */
export function selectedEdgeOf(edges: readonly EdgeGrip[] | undefined, key: string | null): EdgeGrip | null {
if (!key || !edges) return null;
return edges.find((e) => edgeKey(e) === key) ?? null;
}
+90 -110
View File
@@ -6,8 +6,7 @@ import type { Vec2 } from "../../../model/types";
import type { SnapResult, ToolDraft } from "../../../tools/types";
import { hudSegments, type HudFieldsState } from "../../../tools/hudFormat";
import { MODEL_UNITS, type DisplayUnits } from "../../../tools/displayUnits";
import { t } from "../../../i18n";
import type { TranslationKey } from "../../../i18n";
import { snapGlyph, snapTipText, type SnapGlyph } from "../../../tools/snapGlyph";
/**
* Zeichnet die Werkzeug-Vorschau: Vorschau-Formen (gestrichelte Akzentlinien /
@@ -36,7 +35,7 @@ export function DraftOverlay({
units?: DisplayUnits;
}) {
const vertSize = 4.5 * vbPerPx; // halbe Kantenlänge eines Stützpunkt-Quadrats (klein + einheitlich)
const markSize = 4.75 * vbPerPx; // halbe Kantenlänge des Snap-Markers (klein + fein)
const markSize = 6 * vbPerPx; // [288] halbe Grösse des Fangsymbols (gut sichtbar, mit Kontrastrand)
return (
<g className="tool-overlay" pointerEvents="none">
{/* Vorschau-Formen. */}
@@ -87,7 +86,7 @@ export function DraftOverlay({
)}
{/* Snap-Marker + optionale Ortho-Hilfslinie. */}
{draft.snap && (
<SnapMarker snap={draft.snap} toScreen={toScreen} size={markSize} color={snapColor} vbPerPx={vbPerPx} />
<SnapMarker snap={draft.snap} toScreen={toScreen} size={markSize} color={snapColor} vbPerPx={vbPerPx} units={units} />
)}
{/* Maß-/Winkel-HUD am Cursor (VW-Stil `L: … W: …`, oder einfacher Text). */}
{draft.hud && <DraftHud hud={draft.hud} toScreen={toScreen} vbPerPx={vbPerPx} hudFields={hudFields} units={units} />}
@@ -262,40 +261,86 @@ function AngleGuide({
);
}
/** Marker-Glyph je Snap-Art + (bei ortho) eine gestrichelte Hilfslinie. */
const SNAP_TIP_KINDS = new Set(["endpoint", "midpoint", "intersection", "center", "quadrant", "onEdge", "perpendicular", "tangent", "parallel", "extension", "divide"]);
/**
* [288] SVG-Pfad eines Fangsymbols um (x, y) mit halber Grösse r (viewBox-Einheiten). `filled`: Fläche in der
* Fangfarbe füllen (Raster-Punkt, Teilpunkt), sonst nur Kontur.
*/
function glyphPath(g: SnapGlyph, x: number, y: number, r: number): { d: string; filled: boolean } {
const p = (px: number, py: number) => `${px},${py}`;
switch (g) {
case "square":
return { d: `M${p(x - r, y - r)}H${x + r}V${y + r}H${x - r}Z`, filled: false };
case "triangle": {
const h = r * 1.15;
return { d: `M${p(x, y - h)}L${p(x + h, y + h * 0.75)}L${p(x - h, y + h * 0.75)}Z`, filled: false };
}
case "cross":
return { d: `M${p(x - r, y - r)}L${p(x + r, y + r)}M${p(x - r, y + r)}L${p(x + r, y - r)}`, filled: false };
case "perp":
// Rechter Winkel ⊾ mit kleinem Winkelquadrat.
return {
d: `M${p(x - r, y - r)}V${y + r}H${x + r}M${p(x - r, y + r * 0.1)}H${x - r * 0.1}V${y + r}`,
filled: false,
};
case "circle":
return { d: `M${p(x - r, y)}A${r},${r} 0 1 0 ${p(x + r, y)}A${r},${r} 0 1 0 ${p(x - r, y)}Z`, filled: false };
case "diamond":
case "diamondFill":
return { d: `M${p(x, y - r)}L${p(x + r, y)}L${p(x, y + r)}L${p(x - r, y)}Z`, filled: g === "diamondFill" };
case "tangent": {
const c = r * 0.7;
return {
d: `M${p(x - c, y)}A${c},${c} 0 1 0 ${p(x + c, y)}A${c},${c} 0 1 0 ${p(x - c, y)}ZM${p(x - r * 1.2, y - c)}H${x + r * 1.2}`,
filled: false,
};
}
case "parallel":
return { d: `M${p(x - r, y + r)}L${p(x - r * 0.2, y - r)}M${p(x + r * 0.2, y + r)}L${p(x + r, y - r)}`, filled: false };
case "plus":
return { d: `M${p(x - r, y)}H${x + r}M${p(x, y - r)}V${y + r}`, filled: false };
case "dot": {
const c = r * 0.45;
return { d: `M${p(x - c, y)}A${c},${c} 0 1 0 ${p(x + c, y)}A${c},${c} 0 1 0 ${p(x - c, y)}Z`, filled: true };
}
case "none":
return { d: "", filled: false };
}
}
/**
* Fangsymbol + Kurzhinweis (+ bei Ortho/Verlängerung eine gestrichelte Hilfslinie). [288] Je Fangart ein eigenes
* Symbol (`tools/snapGlyph.ts`), in der Fangfarbe über einem Kontrastrand (hell/dunkel je Thema), daneben ein
* Hinweis-Schildchen („Endpunkt", „Mitte" …, bei Hilfslinien mit Abstand/Richtung) — Vectorworks-Smart-Cursor als Leitbild.
*/
function SnapMarker({
snap,
toScreen,
size,
color,
vbPerPx,
units,
}: {
snap: SnapResult;
toScreen: (v: Vec2) => Vec2;
vbPerPx: number;
size: number;
/** Farbe des Snap-Glyphs (einstellbar, Default = Akzent „Sora"). */
/** Farbe des Snap-Glyphs (einstellbar). */
color: string;
units: DisplayUnits;
}) {
const s = toScreen(snap.point);
const r = size;
// Inline `style` überschreibt gezielt die CSS-Klassenfarbe (eine am Element
// selbst deklarierte Klassenregel gewinnt sonst gegen eine geerbte Farbe von
// einer umschließenden Gruppe — daher pro Glyph statt einmal an der Gruppe).
const glyphStyle = { stroke: color };
const helperStyle = { stroke: color };
const fillStyle = { stroke: color, fill: color };
// [287] Fangart als Kurztext am Marker (Archicad/VW-Art): sonst bleibt unklar, woran der Zeiger gerade hängt.
const tip = SNAP_TIP_KINDS.has(snap.kind) ? t(`snap.tip.${snap.kind}` as TranslationKey) : null;
const glyph = snapGlyph(snap.kind);
const { d, filled } = glyphPath(glyph, s.x, s.y, size);
const tip = snapTipText(snap, units);
const fontSize = 11 * vbPerPx;
const padX = 5 * vbPerPx;
const padY = 2.5 * vbPerPx;
const tipW = tip ? tip.length * fontSize * 0.6 + padX * 2 : 0;
const tipH = fontSize + padY * 2;
const tipX = s.x + size + 7 * vbPerPx;
const tipY = s.y - size - 7 * vbPerPx - tipH;
return (
<g className="snap-marker" data-snap-kind={snap.kind}>
{tip && (
<text className="snap-tip" x={s.x + 9 * vbPerPx} y={s.y - 7 * vbPerPx} fontSize={11 * vbPerPx} strokeWidth={3 * vbPerPx}>
{tip}
</text>
)}
<g className="snap-marker" data-snap-kind={snap.kind} data-snap-glyph={glyph}>
{(snap.kind === "ortho" || snap.kind === "extension") && snap.refA && (
<line
className="snap-helper-line"
@@ -303,102 +348,37 @@ function SnapMarker({
y1={toScreen(snap.refA).y}
x2={s.x}
y2={s.y}
style={helperStyle}
style={{ stroke: color }}
vectorEffect="non-scaling-stroke"
/>
)}
{snap.kind === "grid" && (
<circle
className="snap-glyph snap-fill"
cx={s.x}
cy={s.y}
r={r * 0.5}
style={fillStyle}
vectorEffect="non-scaling-stroke"
/>
)}
{snap.kind === "midpoint" && (
<line
className="snap-glyph"
x1={s.x - r}
y1={s.y}
x2={s.x + r}
y2={s.y}
style={glyphStyle}
vectorEffect="non-scaling-stroke"
/>
)}
{/* Teilpunkt (nur fangbar nach Verweilen, s. computeSnap-Dwell) — kleine
gefüllte Raute, bewusst anders als Mittelpunkt (Linie) und Raster
(Kreis), damit „warum snappt es hier" nachvollziehbar bleibt. */}
{snap.kind === "divide" && (
<polygon
className="snap-glyph snap-fill"
points={`${s.x},${s.y - r} ${s.x + r},${s.y} ${s.x},${s.y + r} ${s.x - r},${s.y}`}
style={fillStyle}
vectorEffect="non-scaling-stroke"
/>
)}
{snap.kind === "intersection" && (
{d && (
<>
<line className="snap-glyph" x1={s.x - r} y1={s.y - r} x2={s.x + r} y2={s.y + r} style={glyphStyle} vectorEffect="non-scaling-stroke" />
<line className="snap-glyph" x1={s.x - r} y1={s.y + r} x2={s.x + r} y2={s.y - r} style={glyphStyle} vectorEffect="non-scaling-stroke" />
</>
)}
{(snap.kind === "center" || snap.kind === "quadrant") && (
<circle className="snap-glyph" cx={s.x} cy={s.y} r={r} style={glyphStyle} vectorEffect="non-scaling-stroke" />
)}
{snap.kind === "onEdge" && (
<polygon
className="snap-glyph"
points={`${s.x},${s.y - r} ${s.x + r},${s.y} ${s.x},${s.y + r} ${s.x - r},${s.y}`}
style={glyphStyle}
vectorEffect="non-scaling-stroke"
/>
)}
{/* Senkrecht: ein rechter Winkel (⌐), wie das klassische CAD-Perpendicular-
Glyph — unterscheidet sich bewusst von „onEdge" (Raute), da die
Konstruktion vom letzten Punkt aus geschieht, nicht vom Cursor. */}
{snap.kind === "perpendicular" && (
<polyline
className="snap-glyph"
points={`${s.x - r},${s.y} ${s.x - r},${s.y + r} ${s.x},${s.y + r}`}
style={glyphStyle}
fill="none"
vectorEffect="non-scaling-stroke"
/>
)}
{/* Tangente: kleiner Kreis (wie „center") plus eine kurze Berührlinie. */}
{snap.kind === "tangent" && (
<>
<circle className="snap-glyph" cx={s.x} cy={s.y} r={r * 0.7} style={glyphStyle} vectorEffect="non-scaling-stroke" />
<line
className="snap-glyph"
x1={s.x - r}
y1={s.y + r}
x2={s.x + r}
y2={s.y - r}
style={glyphStyle}
<path className="snap-glyph-halo" d={d} vectorEffect="non-scaling-stroke" />
<path
className={"snap-glyph" + (filled ? " snap-fill" : "")}
d={d}
style={filled ? { stroke: color, fill: color } : { stroke: color }}
vectorEffect="non-scaling-stroke"
/>
</>
)}
{/* Parallel: zwei kurze parallele Striche (∥). */}
{snap.kind === "parallel" && (
<>
<line className="snap-glyph" x1={s.x - r} y1={s.y - r} x2={s.x - r * 0.3} y2={s.y + r} style={glyphStyle} vectorEffect="non-scaling-stroke" />
<line className="snap-glyph" x1={s.x + r * 0.3} y1={s.y - r} x2={s.x + r} y2={s.y + r} style={glyphStyle} vectorEffect="non-scaling-stroke" />
</>
)}
{(snap.kind === "endpoint" || snap.kind === "ortho" || snap.kind === "extension") && (
<circle
className="snap-glyph"
cx={s.x}
cy={s.y}
r={r}
style={glyphStyle}
vectorEffect="non-scaling-stroke"
/>
{tip && (
<g className="snap-tip-box">
<rect
className="snap-tip-bg"
x={tipX}
y={tipY}
width={tipW}
height={tipH}
rx={4 * vbPerPx}
style={{ stroke: color }}
vectorEffect="non-scaling-stroke"
/>
<text className="snap-tip" x={tipX + padX} y={tipY + tipH / 2} fontSize={fontSize} dominantBaseline="middle">
{tip}
</text>
</g>
)}
</g>
);
@@ -76,6 +76,8 @@ export interface UsePlanPickCycleArgs {
drag: React.MutableRefObject<{ pointerId: number; startClientX: number; startClientY: number; startView: ViewBox; } | null>;
commitPan: () => void;
setDragging: React.Dispatch<React.SetStateAction<boolean>>;
/** [288] Klick ohne Bewegung: Kante des Gewählten wählen. true = Klick verbraucht (kein Wählen/Durchschalten). */
onEdgeClick?: (clientX: number, clientY: number) => boolean;
}
export function usePlanPickCycle(inp: UsePlanPickCycleArgs) {
@@ -130,6 +132,7 @@ export function usePlanPickCycle(inp: UsePlanPickCycleArgs) {
drag,
commitPan,
setDragging,
onEdgeClick,
} = inp;
// ── Übereinanderliegende Objekte durchschalten ────────────────────────────
@@ -497,6 +500,9 @@ export function usePlanPickCycle(inp: UsePlanPickCycleArgs) {
}
moveDrag.current = null;
gripHandlers!.onGripEnd();
const still = md.startX !== undefined && md.startY !== undefined && Math.hypot(e.clientX - md.startX, e.clientY - md.startY) < MARQUEE_THRESHOLD_PX;
// [288] Klick ohne Bewegung auf eine Kante des Gewählten: Kante wählen (Anfasser zum Parallelverschieben).
if (still && !e.shiftKey && onEdgeClick?.(e.clientX, e.clientY)) return;
// [137] Ohne Bewegung war es ein Klick auf das Gewählte: an derselben Stelle zum nächsten Objekt wechseln.
if (clickCycles(e, md.startX, md.startY)) plainCycleStep(e.clientX, e.clientY);
return;
@@ -583,6 +589,8 @@ export function usePlanPickCycle(inp: UsePlanPickCycleArgs) {
}
setPickList(null);
cycleRef.current = null;
// [288] Klick auf eine Kante des Gewählten: Kante wählen statt neu zu wählen.
if (!e.shiftKey && onEdgeClick?.(e.clientX, e.clientY)) return;
if (!e.shiftKey && plainCycleStep(e.clientX, e.clientY)) return;
const dp = defaultPick(e.clientX, e.clientY);
setSelected(dp.hitIndex);
+4 -3
View File
@@ -47,7 +47,8 @@ export interface UsePlanPointerArgs {
edgeGripsActive: boolean;
edgeGripAt: (clientX: number, clientY: number) => EdgeGrip | null;
/** [26] Kante unter dem Cursor (Kanten-Anfasser) im Ruhezustand — die Plan-Ansicht hebt sie hervor. */
onHoverEdge?: (edge: EdgeGrip | null) => void;
/** [288] Griff unter dem Cursor (Hover-Zustand der Auswahlgriffe), null = keiner. */
onHoverGrip?: (index: number | null) => void;
grabbedBody: (clientX: number, clientY: number) => BodyTarget | null;
moveDrag: React.MutableRefObject<{ pointerId: number; last: Vec2; startX?: number; startY?: number; target: BodyTarget; } | null>;
marquee: React.MutableRefObject<{ pointerId: number; startClientX: number; startClientY: number; startView: Vec2; moved: boolean; } | null>;
@@ -114,7 +115,7 @@ export function usePlanPointer(inp: UsePlanPointerArgs) {
grips,
edgeGripsActive,
edgeGripAt,
onHoverEdge,
onHoverGrip,
grabbedBody,
moveDrag,
marquee,
@@ -554,7 +555,7 @@ export function usePlanPointer(inp: UsePlanPointerArgs) {
// Echter Ruhezustand (kein Drag/Werkzeug/Marquee/Pan) — Hover-
// Teilpunkte-Erkennung.
updateHoverDivide(e.clientX, e.clientY);
onHoverEdge?.(edgeGripsActive ? edgeGripAt(e.clientX, e.clientY) : null);
onHoverGrip?.(gripsActive ? gripAt(e.clientX, e.clientY) : null);
return;
}
const { scale } = measure(d.startView);