[137] Plan: erneuter Klick an derselben Stelle wählt das nächste Objekt darunter (Klick-Zyklus), Hinweis in der Statusleiste
This commit is contained in:
8 files changed
+186
-4
No files matched your search
@@ -2189,6 +2189,7 @@ export const de = {
|
||||
"pick.kind.site": "Lage",
|
||||
"pick.site.sunStudy": "Schatten (Sonnenstand)",
|
||||
"pick.site.siteRules": "Baurecht",
|
||||
"pick.cycle.hint": "{i}/{n} Treffer — erneut klicken zum Wechseln",
|
||||
"pick.shape.line": "Linie",
|
||||
"pick.shape.polyline": "Polylinie",
|
||||
"pick.shape.area": "Fläche",
|
||||
|
||||
@@ -2177,6 +2177,7 @@ export const en: Record<TranslationKey, string> = {
|
||||
"pick.kind.site": "Site",
|
||||
"pick.site.sunStudy": "Shadow (sun position)",
|
||||
"pick.site.siteRules": "Building regulations",
|
||||
"pick.cycle.hint": "{i}/{n} hits — click again to cycle",
|
||||
"pick.shape.line": "Line",
|
||||
"pick.shape.polyline": "Polyline",
|
||||
"pick.shape.area": "Area",
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// [137] Statusleisten-Hinweis zum Klick-Zyklus („2/3 Treffer — erneut klicken zum Wechseln"). Ausserhalb von
|
||||
// React-State, weil der Setzer (PlanView) und der Leser (StatusBar in App) in verschiedenen Teilbäumen sitzen.
|
||||
|
||||
import { useSyncExternalStore } from "react";
|
||||
|
||||
let current: string | null = null;
|
||||
const listeners = new Set<() => void>();
|
||||
|
||||
export function setPickHint(hint: string | null): void {
|
||||
if (hint === current) return;
|
||||
current = hint;
|
||||
for (const l of listeners) l();
|
||||
}
|
||||
|
||||
export function usePickHint(): string | null {
|
||||
return useSyncExternalStore(
|
||||
(l) => (listeners.add(l), () => listeners.delete(l)),
|
||||
() => current,
|
||||
);
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
// Rein gesteuert (controlled): alle Werte kommen aus App (Modell + View-State),
|
||||
// keine eigene Logik. Bezeichner englisch, UI-Text/Kommentare deutsch.
|
||||
|
||||
import { usePickHint } from "../state/pickHintStore";
|
||||
import { MODEL_UNITS, fmtDisplay, xToDisplay, yToDisplay, type DisplayUnits } from "../tools/displayUnits";
|
||||
import { useCursor } from "../state/cursorStore";
|
||||
import { useEffect, useRef, useState, memo } from "react";
|
||||
@@ -394,10 +395,12 @@ export const StatusBar = memo(function StatusBar({
|
||||
snap,
|
||||
onSnapChange,
|
||||
}: StatusBarProps) {
|
||||
// [137] Klick-Zyklus im Plan („2/3 Treffer — erneut klicken zum Wechseln") hat Vorrang vor dem Werkzeug-Hinweis.
|
||||
const pickHint = usePickHint();
|
||||
return (
|
||||
<footer className="statusbar">
|
||||
{/* Links: Werkzeug-Hinweis. */}
|
||||
<span className="sb-hint">{hint}</span>
|
||||
<span className="sb-hint" data-testid="status-hint">{pickHint ?? hint}</span>
|
||||
|
||||
{/* Rechts: abgeleiteter Wert-Cluster. Interaktive Kontrollen (Linien-
|
||||
Darstellung, Fang) zuerst, danach die reinen Anzeigewerte. */}
|
||||
|
||||
@@ -56,6 +56,7 @@ import { endBusyAfterPaint } from "../../state/busyStore";
|
||||
import { EMPTY_SELECTION, single } from "../../state/selection";
|
||||
import type { Selection } from "../../state/selection";
|
||||
import { createCursorStore, useCursorValue, type CursorStore } from "../../state/cursorStore";
|
||||
import { cycleHint, plainCycleNext, selectionHas, type PlainCycle } from "./pickCycle";
|
||||
|
||||
/**
|
||||
* Feld-Status der Befehlszeile fürs Cursor-HUD (Tab-Feld-Zyklus §2.7) — Typ
|
||||
@@ -382,6 +383,8 @@ export interface PlanViewProps {
|
||||
onSelect?: (selection: PlanSelection) => void;
|
||||
/** Kategorie-/Layer-Name eines Objekts für die Cmd/Strg+Klick-Liste ("Fläche · 01421"). */
|
||||
describePick?: (kind: PickKind, id: string) => string | undefined;
|
||||
/** [137] Statusleisten-Hinweis zum Klick-Zyklus („2/3 Treffer — erneut klicken …"), `null` = keiner. */
|
||||
onPickHint?: (hint: string | null) => void;
|
||||
/**
|
||||
* Alt+Klick (Schere/Segment löschen): meldet das nahe getroffene Drawing2D plus
|
||||
* den Modellpunkt des Klicks. Der Aufrufer (App) ermittelt daraus die nächst-
|
||||
@@ -632,6 +635,7 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
|
||||
onScale,
|
||||
onSelect,
|
||||
describePick,
|
||||
onPickHint,
|
||||
onMarquee,
|
||||
onSegmentCut,
|
||||
onContextMenu,
|
||||
@@ -1233,6 +1237,9 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
|
||||
const moveDrag = useRef<{
|
||||
pointerId: number;
|
||||
last: Vec2;
|
||||
/** Bildschirm-Start (ohne Bewegung = Klick, [137] Klick-Zyklus). */
|
||||
startX?: number;
|
||||
startY?: number;
|
||||
target: BodyTarget;
|
||||
} | null>(null);
|
||||
// Transiente Stempel-Griff-Zieh-Daten: letzter Modellpunkt, gegen den das
|
||||
@@ -1801,7 +1808,7 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
|
||||
if (body) {
|
||||
e.preventDefault();
|
||||
e.currentTarget.setPointerCapture(e.pointerId);
|
||||
moveDrag.current = { pointerId: e.pointerId, last: rawModelAt(e.clientX, e.clientY), target: body };
|
||||
moveDrag.current = { pointerId: e.pointerId, last: rawModelAt(e.clientX, e.clientY), target: body, startX: e.clientX, startY: e.clientY };
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1814,7 +1821,7 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
|
||||
if (body) {
|
||||
e.preventDefault();
|
||||
e.currentTarget.setPointerCapture(e.pointerId);
|
||||
moveDrag.current = { pointerId: e.pointerId, last: rawModelAt(e.clientX, e.clientY), target: body };
|
||||
moveDrag.current = { pointerId: e.pointerId, last: rawModelAt(e.clientX, e.clientY), target: body, startX: e.clientX, startY: e.clientY };
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -2207,9 +2214,23 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
|
||||
additive?: boolean;
|
||||
} | null>(null);
|
||||
// Liste/Zyklus verwerfen, sobald sich Ausschnitt oder Plan ändern.
|
||||
// [137] Einfacher Klick-Zyklus: Kandidaten des letzten einfachen Klicks (s. pickCycle.ts).
|
||||
const plainCycleRef = useRef<PlainCycle<PickCandidate> | null>(null);
|
||||
// Auswahl anderswo geändert (Escape, Panel): Zyklus und Hinweis verwerfen.
|
||||
useEffect(() => {
|
||||
const pc = plainCycleRef.current;
|
||||
if (pc && !selectionHas(selection, pc.items[pc.idx])) {
|
||||
plainCycleRef.current = null;
|
||||
onPickHint?.(null);
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [selection]);
|
||||
useEffect(() => {
|
||||
setPickList(null);
|
||||
cycleRef.current = null;
|
||||
plainCycleRef.current = null;
|
||||
onPickHint?.(null);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [view, planRaw]);
|
||||
useEffect(() => {
|
||||
if (!pickList) return;
|
||||
@@ -2416,6 +2437,20 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
|
||||
return true;
|
||||
};
|
||||
|
||||
/** [137] Einfacher Klick an der Stelle des letzten Klicks: nächsten Kandidaten wählen. true = behandelt. */
|
||||
const plainCycleStep = (clientX: number, clientY: number): boolean => {
|
||||
const pc = plainCycleRef.current;
|
||||
const now = Date.now();
|
||||
const next = onSelect ? plainCycleNext(pc, { x: clientX, y: clientY, t: now, planKey: plan }, selection) : null;
|
||||
if (next === null || !pc) return false;
|
||||
pc.idx = next;
|
||||
pc.t = now;
|
||||
const v = clientToView(clientX, clientY, view);
|
||||
applyCandidate(pc.items[next], viewToModel(v.x, v.y), false);
|
||||
onPickHint?.(cycleHint(pc.items.length, next));
|
||||
return true;
|
||||
};
|
||||
|
||||
const endDrag = (e: React.PointerEvent<SVGSVGElement>) => {
|
||||
// Perf: einen anhängigen (rAF-gedrosselten) Drag mit der FINALEN Position
|
||||
// sofort anwenden, damit das Objekt exakt an der Loslass-Stelle landet, bevor
|
||||
@@ -2474,6 +2509,10 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
|
||||
}
|
||||
moveDrag.current = null;
|
||||
gripHandlers!.onGripEnd();
|
||||
// [137] Ohne Bewegung war es ein Klick auf das Gewählte: an derselben Stelle zum nächsten Objekt wechseln.
|
||||
if (md.startX !== undefined && Math.hypot(e.clientX - md.startX, e.clientY - (md.startY ?? 0)) < MARQUEE_THRESHOLD_PX && !e.shiftKey) {
|
||||
plainCycleStep(e.clientX, e.clientY);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2528,14 +2567,23 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
|
||||
}
|
||||
// Kein Drag → Klick: Objekt unter dem Cursor wählen bzw. Auswahl löschen.
|
||||
setMarqueeRect(null);
|
||||
if (onSelect && cycleModifier(e) && cycleSelect(e)) return;
|
||||
if (onSelect && cycleModifier(e) && cycleSelect(e)) {
|
||||
plainCycleRef.current = null;
|
||||
onPickHint?.(null);
|
||||
return;
|
||||
}
|
||||
setPickList(null);
|
||||
cycleRef.current = null;
|
||||
if (!e.shiftKey && plainCycleStep(e.clientX, e.clientY)) return;
|
||||
const dp = defaultPick(e.clientX, e.clientY);
|
||||
setSelected(dp.hitIndex);
|
||||
if (onSelect) {
|
||||
const v = clientToView(e.clientX, e.clientY, view);
|
||||
onSelect({ model: viewToModel(v.x, v.y), ...dp, shift: e.shiftKey });
|
||||
// [137] Kandidaten an dieser Stelle merken: ein erneuter Klick hier wählt das nächste Objekt.
|
||||
const items = e.shiftKey ? [] : collectCandidates(e.clientX, e.clientY, dp);
|
||||
plainCycleRef.current = items.length > 1 ? { x: e.clientX, y: e.clientY, t: Date.now(), planKey: plan, items, idx: 0 } : null;
|
||||
onPickHint?.(cycleHint(items.length, 0));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
// [137] Wiederholter Klick an derselben Stelle schaltet durch die Objekte unter dem Cursor.
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { cycleHint, plainCycleNext, selectionHas, type PlainCycle } from "./pickCycle";
|
||||
import { EMPTY_SELECTION } from "../../state/selection";
|
||||
|
||||
const items = [
|
||||
{ kind: "drawing" as const, id: "dim" },
|
||||
{ kind: "site" as const, id: "sunStudy" },
|
||||
{ kind: "context" as const, id: "terrain" },
|
||||
];
|
||||
const prev: PlainCycle = { x: 100, y: 100, t: 1000, planKey: "P", items, idx: 0 };
|
||||
const sel = (o: Partial<typeof EMPTY_SELECTION>) => ({ ...EMPTY_SELECTION, ...o });
|
||||
|
||||
describe("[137] Klick-Zyklus", () => {
|
||||
it("zweiter Klick an derselben Stelle wählt das nächste Objekt, danach wieder das erste", () => {
|
||||
const s = sel({ drawings: ["dim"] });
|
||||
expect(plainCycleNext(prev, { x: 102, y: 99, t: 2000, planKey: "P" }, s)).toBe(1);
|
||||
expect(plainCycleNext({ ...prev, idx: 2 }, { x: 100, y: 100, t: 2000, planKey: "P" }, sel({ contextObjects: ["terrain"] }))).toBe(0);
|
||||
});
|
||||
|
||||
it("kein Zyklus: andere Stelle, Doppelklick, anderer Plan, Auswahl inzwischen geändert, nur ein Treffer", () => {
|
||||
const s = sel({ drawings: ["dim"] });
|
||||
expect(plainCycleNext(prev, { x: 120, y: 100, t: 2000, planKey: "P" }, s)).toBeNull();
|
||||
expect(plainCycleNext(prev, { x: 100, y: 100, t: 1200, planKey: "P" }, s)).toBeNull();
|
||||
expect(plainCycleNext(prev, { x: 100, y: 100, t: 2000, planKey: "Q" }, s)).toBeNull();
|
||||
expect(plainCycleNext(prev, { x: 100, y: 100, t: 2000, planKey: "P" }, EMPTY_SELECTION)).toBeNull();
|
||||
expect(plainCycleNext({ ...prev, items: items.slice(0, 1) }, { x: 100, y: 100, t: 2000, planKey: "P" }, s)).toBeNull();
|
||||
expect(plainCycleNext(null, { x: 100, y: 100, t: 2000, planKey: "P" }, s)).toBeNull();
|
||||
});
|
||||
|
||||
it("Auswahl-Abgleich je Art; Hinweis nur bei mehreren Treffern", () => {
|
||||
expect(selectionHas(sel({ site: ["sunStudy"] }), { kind: "site", id: "sunStudy" })).toBe(true);
|
||||
expect(selectionHas(sel({ sectionLines: ["s1"] }), { kind: "section", id: "s1" })).toBe(true);
|
||||
expect(selectionHas(sel({ walls: ["w"] }), { kind: "context", id: "w" })).toBe(false);
|
||||
expect(cycleHint(1, 0)).toBeNull();
|
||||
expect(cycleHint(3, 1)).toMatch(/2\/3/);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,69 @@
|
||||
// [137] Klick-Zyklus (übliches CAD-Verhalten): ein erneuter einfacher Klick an derselben Stelle wählt das nächste
|
||||
// Objekt unter dem Cursor — so erreicht man in dichten Plänen (Situation 1:500: Bemassung über Schatten und Gelände)
|
||||
// auch die unteren Objekte ohne Cmd/Strg+Klick-Liste. Doppelklick (< 400 ms) schaltet nicht; ebenso wenig, wenn die
|
||||
// Auswahl inzwischen anders ist (Escape, Panel), der Plan wechselte oder nur ein Objekt dort liegt.
|
||||
|
||||
import type { PickKind } from "../../core";
|
||||
import { t } from "../../i18n";
|
||||
import type { Selection, SelectionKind } from "../../state/selection";
|
||||
|
||||
/** Toleranz der „gleichen Stelle" (Bildschirm-px) und Doppelklick-Zeit (ms). */
|
||||
export const CYCLE_RADIUS_PX = 5;
|
||||
export const DOUBLE_CLICK_MS = 400;
|
||||
|
||||
export interface CycleItem {
|
||||
kind: PickKind;
|
||||
id: string;
|
||||
}
|
||||
|
||||
/** Zustand nach dem letzten einfachen Klick: Kandidaten an der Stelle und der angewandte Index. */
|
||||
export interface PlainCycle<T extends CycleItem = CycleItem> {
|
||||
x: number;
|
||||
y: number;
|
||||
t: number;
|
||||
/** Plan-Identität (anderer Plan = neue Liste). */
|
||||
planKey: unknown;
|
||||
items: T[];
|
||||
idx: number;
|
||||
}
|
||||
|
||||
const KIND_FIELD: Record<PickKind, SelectionKind> = {
|
||||
section: "sectionLines",
|
||||
opening: "openings",
|
||||
wall: "walls",
|
||||
column: "columns",
|
||||
drawing: "drawings",
|
||||
solid: "solids",
|
||||
ceiling: "ceilings",
|
||||
stair: "stairs",
|
||||
room: "rooms",
|
||||
roof: "roofs",
|
||||
site: "site",
|
||||
context: "contextObjects",
|
||||
};
|
||||
|
||||
/** Ist das Objekt (noch) gewählt? */
|
||||
export function selectionHas(sel: Selection | undefined, c: CycleItem): boolean {
|
||||
return !!sel && sel[KIND_FIELD[c.kind]].includes(c.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Index des nächsten Kandidaten, wenn dieser Klick den Zyklus fortsetzt — sonst `null` (normaler Klick mit
|
||||
* Standard-Priorität).
|
||||
*/
|
||||
export function plainCycleNext(
|
||||
prev: PlainCycle | null,
|
||||
click: { x: number; y: number; t: number; planKey: unknown },
|
||||
selection: Selection | undefined,
|
||||
): number | null {
|
||||
if (!prev || prev.items.length < 2 || prev.planKey !== click.planKey) return null;
|
||||
if (Math.hypot(click.x - prev.x, click.y - prev.y) > CYCLE_RADIUS_PX) return null;
|
||||
if (click.t - prev.t < DOUBLE_CLICK_MS) return null;
|
||||
if (!selectionHas(selection, prev.items[prev.idx])) return null;
|
||||
return (prev.idx + 1) % prev.items.length;
|
||||
}
|
||||
|
||||
/** Statusleisten-Hinweis „2/3 Treffer — erneut klicken zum Wechseln" (nur bei mehreren Objekten). */
|
||||
export function cycleHint(n: number, idx: number): string | null {
|
||||
return n > 1 ? t("pick.cycle.hint", { i: idx + 1, n }) : null;
|
||||
}
|
||||
@@ -57,6 +57,7 @@ import { DrawingTabs } from "../DrawingTabs";
|
||||
import type { ViewSnapshotTabsHandlers } from "../DrawingTabs";
|
||||
import type { ToolDraft, ToolHandlers, ToolId } from "../tools/types";
|
||||
import type { Selection } from "../state/selection";
|
||||
import { setPickHint } from "../state/pickHintStore";
|
||||
import type { DetailLevel, RenderMode, View3d, ViewType } from "../model/viewTypes";
|
||||
|
||||
/**
|
||||
@@ -857,6 +858,7 @@ function LevelPlanView({
|
||||
ref={planViewRef}
|
||||
plan={plan}
|
||||
describePick={describePick}
|
||||
onPickHint={setPickHint}
|
||||
resetKey={level.id}
|
||||
onCursor={onCursor}
|
||||
onScale={onScale}
|
||||
|
||||
Reference in new issue
Block a user