[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

+76 -56
View File
@@ -9,7 +9,7 @@ import { forwardRef, useEffect, useMemo, useRef, useState } from "react";
import type { ComponentProps, CSSProperties } from "react";
import type { PlanImage, Primitive } from "../../core";
import { planLineEndsProps } from "../../core";
import type { EdgeGrip, Vec2 } from "../../model/types";
import type { Vec2 } from "../../model/types";
import { t } from "../../i18n";
import { docFromText } from "../../text/richText";
import { contentFontBaselineFromTop, TEXT_LINE_HEIGHT_MULT } from "../../text/fontMetrics";
@@ -29,6 +29,7 @@ import {
} from "./planView/primitives";
import { DraftOverlay } from "./planView/overlays";
import { visibleGripIndices } from "./planView/gripCull";
import { edgeHitAt, edgeSelStep, selectedEdgeOf } from "./planView/edgeSelection";
import { localViewBoxAttr } from "./planView/overlayOrigin";
import { PlanRulers } from "./planView/PlanRulers";
import { PlanGrid } from "./planView/PlanGrid";
@@ -37,7 +38,7 @@ import { planTextEntries } from "../../core";
import { EMPTY_SELECTION, single } from "../../state/selection";
import { useCursorValue, type CursorStore } from "../../state/cursorStore";
import type { HatchedPoly, PlanViewHandle, PlanViewProps } from "./planView/types";
import { IS_MAC } from "./planView/constants";
import { IS_MAC, gripSquareHalfPx } from "./planView/constants";
import { usePlanEngine } from "./planView/usePlanEngine";
import { usePlanCoords } from "./planView/usePlanCoords";
import { usePlanPicking } from "./planView/usePlanPicking";
@@ -164,8 +165,31 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
const toolActive = inputActive && !!toolHandlers;
// Editier-Griffe sind nur im Auswahl-Werkzeug aktiv.
const gripsActive = !toolActive && !!grips && grips.length > 0 && !!gripHandlers;
// Kanten-Griffe nur aktiv, wenn auch die Eckpunkt-Griffe aktiv sind.
const edgeGripsActive = gripsActive && !!edgeGrips && edgeGrips.length > 0;
// [288] Kantenauswahl: der Anfasser zum Parallelverschieben erscheint nur an der per zweitem Klick gewählten Kante
// (Vectorworks-Arbeitsweise, s. planView/edgeSelection.ts). Kanten-Griffe nur, wenn auch die Eckpunkt-Griffe aktiv sind.
const [edgeSelKey, setEdgeSelKey] = useState<string | null>(null);
const edgeSelKeyRef = useRef(edgeSelKey);
edgeSelKeyRef.current = edgeSelKey;
const selectedEdge = gripsActive ? selectedEdgeOf(edgeGrips, edgeSelKey) : null;
const shownEdgeGrips = useMemo(() => (selectedEdge ? [selectedEdge] : []), [selectedEdge]);
const edgeGripsActive = !!selectedEdge;
// Andere Auswahl → Kantenauswahl weg (Ring-Kanten von Raum/Decke/Dach tragen keinen Eigentümer im Schlüssel).
const selectionSig = JSON.stringify(selection);
useEffect(() => setEdgeSelKey(null), [selectionSig]);
// Esc hebt zuerst nur die Kantenauswahl auf (preventDefault: die Elementauswahl bleibt, s. useKeyboardShortcuts).
useEffect(() => {
const onKey = (e: KeyboardEvent) => {
if (e.key !== "Escape" || e.defaultPrevented || e.ctrlKey || e.metaKey || e.altKey) return;
const el = e.target as HTMLElement | null;
if (el && (el.tagName === "INPUT" || el.tagName === "TEXTAREA" || el.isContentEditable)) return;
const step = edgeSelStep(edgeSelKeyRef.current, { kind: "escape" });
if (!step.consumed) return;
e.preventDefault();
setEdgeSelKey(step.key);
};
window.addEventListener("keydown", onKey);
return () => window.removeEventListener("keydown", onKey);
}, []);
// Eingepasste Standard-Ansicht aus den AKTUELLEN Bounds, über die fixe
// toScreen-Abbildung. Reset-/Einpassen-Ziel + Bezug für die Zoom-Grenzen; wird
// NICHT automatisch angewandt (nur bei resetKey-Wechsel und „Einpassen").
@@ -194,13 +218,11 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
const [view, setView] = useState<ViewBox>(startView);
// [193] Sichtbarer Ausschnitt (Modell-Meter) für die Netzpunkt-Griffe grosser Netze (verzögert gemeldet).
useEffect(() => publishPlanViewport(viewBoxToMeshRect(view, PX_PER_M)), [view]);
// [26] Kante unter dem Cursor (Kanten-Anfasser); gezeichnet wird sie nur für Flächen-Elemente
// (Dach, Decke, Raum, Baugrube), deren Kanten-Indizes Griff-Indizes sind.
const [hoverEdge, setHoverEdge] = useState<EdgeGrip | null>(null);
// [121] Aktuellen Wert spiegeln: bei jeder Zeigerbewegung nur setzen, wenn sich die Kante ändert (ein
// setState mit gleichem Wert kann je nach React-Interna die ganze Plan-Ansicht ein zweites Mal rendern).
const hoverEdgeRef = useRef(hoverEdge);
hoverEdgeRef.current = hoverEdge;
// [288] Griff unter dem Cursor (Hover-Zustand der Auswahlgriffe). [121] Nur bei Änderung setzen (ein setState mit
// gleichem Wert kann je nach React-Interna die ganze Plan-Ansicht ein zweites Mal rendern).
const [hoverGrip, setHoverGrip] = useState<number | null>(null);
const hoverGripRef = useRef(hoverGrip);
hoverGripRef.current = hoverGrip;
// Ausschnitt NUR bei Plan-/Geschoss-Wechsel (resetKey) auf „eingepasst"
// zurücksetzen — NICHT bei jeder Bounds-Änderung durch Editieren (sonst
// „wandert" die Ansicht beim Verschieben/Löschen mit). `defaultView` ist beim
@@ -304,7 +326,7 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
canvasRef,
view,
grips,
edgeGrips,
edgeGrips: shownEdgeGrips,
onCursor,
});
// [165] Treffer-Abfragen (Bauteile, 2D-Elemente, Lage, Bäume), Hover-Teilpunkte, gegriffener Körper, Marquee-Treffer.
@@ -396,11 +418,10 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
grips,
edgeGripsActive,
edgeGripAt,
onHoverEdge: (e) => {
const h = hoverEdgeRef.current;
if (h?.aIndex === e?.aIndex && h?.bIndex === e?.bIndex && h?.owner === e?.owner) return;
hoverEdgeRef.current = e;
setHoverEdge(e);
onHoverGrip: (i) => {
if (hoverGripRef.current === i) return;
hoverGripRef.current = i;
setHoverGrip(i);
},
grabbedBody,
moveDrag,
@@ -499,6 +520,17 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
drag,
commitPan,
setDragging,
onEdgeClick: (clientX, clientY) => {
const hit = gripsActive
? edgeHitAt(edgeGrips, (v) => { const q = toScreen(v); return vbToClient(q.x, q.y); }, { x: clientX, y: clientY })
: null;
const step = edgeSelStep(edgeSelKeyRef.current, { kind: "click", hit });
if (step.key !== edgeSelKeyRef.current) {
edgeSelKeyRef.current = step.key;
setEdgeSelKey(step.key);
}
return step.consumed;
},
});
// [165] Mausrad-Zoom, Doppelklick, Kontextmenü.
const {
@@ -1038,7 +1070,7 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
const c2 = toLocal({ x: groupBBox.maxX, y: groupBBox.minY });
const c3 = toLocal({ x: groupBBox.maxX, y: groupBBox.maxY });
const c4 = toLocal({ x: groupBBox.minX, y: groupBBox.maxY });
const size = (4 * gripK(meet)) / meet;
const half = gripSquareHalfPx(false, false) / meet;
const corners = [c1, c2, c3, c4];
return (
<>
@@ -1048,12 +1080,13 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
pointerEvents="none"
/>
{corners.map((s, i) => (
<circle
<rect
key={`gbb-${i}`}
className="plan-grip plan-group-bbox-corner"
cx={s.x}
cy={s.y}
r={size}
x={s.x - half}
y={s.y - half}
width={half * 2}
height={half * 2}
pointerEvents="none"
/>
))}
@@ -1136,36 +1169,26 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
pointerEvents="none"
/>
))}
{/* Editier-Griffe des selektierten Elements (Wand-Enden / 2D-Vertices):
ziehbare Kreise. Bildschirmkonstante Größe über die meet-Skala.
Radius bewusst kleiner als der Treffer-Radius (GRIP_HIT_PX) — die
Klickfläche bleibt grosszügig, nur die sichtbare Form schrumpft. */}
{/* [288] Auswahlgriffe wie in Vectorworks: kleine gefüllte Quadrate mit dünnem hellem Rand, einheitliche
Bildschirmgrösse (meet-Skala), Hover = grösser + hohl. Einfüge-Griffe (Mitte eines Schnitt-Segments) als
kleinere hohle Quadrate. Sichtbare Form bewusst kleiner als der Treffer-Radius (GRIP_HIT_PX). */}
{gripsActive && (
<LiveMeet store={meetStore} base={meetScale(view, canvasRef.current ?? svgRef.current) ?? 1}>
{(meet) =>
// Viele Griffe (Kataster): nur die sichtbaren zeichnen (gripCull.ts).
(visibleGripIndices(grips!, toScreen, view, meet) ?? grips!.map((_, i) => i)).map((i) => {
const s = toLocal(grips![i]);
const size = (4.5 * gripK(meet)) / meet;
// Einfüge-Griff (Mitte eines Schnitt-Segments): kleine Raute, eigene Optik gegenüber den Eck-Griffen.
if ((grips![i] as { insert?: boolean }).insert) {
const d = size * 0.9;
return (
<polygon
key={`grip-${i}`}
className="plan-grip plan-grip-insert"
points={`${s.x},${s.y - d} ${s.x + d},${s.y} ${s.x},${s.y + d} ${s.x - d},${s.y}`}
pointerEvents="none"
/>
);
}
const insert = !!(grips![i] as { insert?: boolean }).insert;
const hover = hoverGrip === i;
const half = gripSquareHalfPx(insert, hover) / meet;
return (
<circle
<rect
key={`grip-${i}`}
className="plan-grip"
cx={s.x}
cy={s.y}
r={size}
className={"plan-grip" + (insert ? " plan-grip-insert" : "") + (hover ? " plan-grip-hover" : "")}
x={s.x - half}
y={s.y - half}
width={half * 2}
height={half * 2}
pointerEvents="none"
/>
);
@@ -1195,25 +1218,22 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
);
}}</LiveMeet>
)}
{/* Kanten-/Seiten-Griffe: je Seite ein dreieckiger Anfasser, leicht nach
AUSSEN entlang der (bildschirm-transformierten) Normale versetzt, mit
der Spitze nach außen. Y wird gespiegelt (toScreen spiegelt Y), damit
das Dreieck wirklich nach außen zeigt. Größe bildschirmkonstant. */}
{edgeGripsActive && hoverEdge && !hoverEdge.owner?.drawingId && !hoverEdge.owner?.wallId && grips?.[hoverEdge.aIndex] && grips[hoverEdge.bIndex] && (
{/* [288] Gewählte Kante (zweiter Klick auf eine Kante des Gewählten): hervorgehoben, nur sie trägt den
dreieckigen Anfasser zum Parallelverschieben (Basis auf der Kante, Spitze nach aussen). */}
{selectedEdge?.a && selectedEdge.b && (
<line
className="plan-edge-hover"
x1={toLocal(grips[hoverEdge.aIndex]).x}
y1={toLocal(grips[hoverEdge.aIndex]).y}
x2={toLocal(grips[hoverEdge.bIndex]).x}
y2={toLocal(grips[hoverEdge.bIndex]).y}
className="plan-edge-selected"
x1={toLocal(selectedEdge.a).x}
y1={toLocal(selectedEdge.a).y}
x2={toLocal(selectedEdge.b).x}
y2={toLocal(selectedEdge.b).y}
pointerEvents="none"
/>
)}
{edgeGripsActive && (
<LiveMeet store={meetStore} base={meetScale(view, canvasRef.current ?? svgRef.current) ?? 1}>
{(s) =>
(visibleGripIndices(edgeGrips!.map((g) => g.mid), toScreen, view, s) ?? edgeGrips!.map((_, i) => i)).map((i) => {
const eg = edgeGrips![i];
shownEdgeGrips.map((eg, i) => {
const m = toLocal(eg.mid);
// Normale in den Bildschirmraum (Y spiegeln); auf Bildschirm-px-Größen.
const sn = screenNormal(eg.normal);
+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);