diff --git a/src/geometry/drawingIndex.ts b/src/geometry/drawingIndex.ts index fd3ecbb7..dc571202 100644 --- a/src/geometry/drawingIndex.ts +++ b/src/geometry/drawingIndex.ts @@ -153,3 +153,18 @@ export function nearestInDrawings(index: DrawingIndex, m: Vec2, maxDist: number) } return best; } + +/** ALLE Zeichnungen mit einem Segment näher als `maxDist` an `m`, nächste zuerst (je Zeichnung ihr nächstes Segment). */ +export function drawingsWithinDistance(index: DrawingIndex, m: Vec2, maxDist: number): NearestHit[] { + const out: NearestHit[] = []; + for (const i of drawingsNear(index, m, maxDist)) { + const d = index.drawings[i]; + let best: NearestHit | null = null; + forEachSegment(d, (a, b) => { + const dist = pointSegDist(m, a, b); + if (dist < maxDist && (!best || dist < best.dist)) best = { drawing: d, a, b, dist }; + }); + if (best) out.push(best); + } + return out.sort((x, y) => x.dist - y.dist); +} diff --git a/src/i18n/de.ts b/src/i18n/de.ts index 625da7fc..e2a1b197 100644 --- a/src/i18n/de.ts +++ b/src/i18n/de.ts @@ -1590,6 +1590,27 @@ export const de = { "import.applying.heading": "Importiere ins Projekt", "import.applying.hint": "Geometrie wird ins Projekt eingehängt und Grundriss/3D neu aufgebaut … Bei sehr vielen Elementen kann das einen Moment dauern.", + "pick.list.title": "Objekte an dieser Stelle ({n})", + "pick.list.hint.mac": "⌘-Klick: nächstes Objekt", + "pick.list.hint.other": "Strg-Klick: nächstes Objekt", + "pick.kind.section": "Schnittlinie", + "pick.kind.opening": "Öffnung", + "pick.kind.wall": "Wand", + "pick.kind.column": "Stütze", + "pick.kind.drawing": "2D-Element", + "pick.kind.solid": "Körper", + "pick.kind.ceiling": "Decke", + "pick.kind.stair": "Treppe", + "pick.kind.room": "Raum", + "pick.kind.roof": "Dach", + "pick.kind.context": "Kontext-Objekt", + "pick.shape.line": "Linie", + "pick.shape.polyline": "Polylinie", + "pick.shape.area": "Fläche", + "pick.shape.text": "Text", + "pick.shape.circle": "Kreis", + "pick.shape.arc": "Bogen", + "pick.shape.image": "Bild", "import.confirm": "Importieren", "import.cancel": "Abbrechen", "import.badge.floor": "Geschoss", diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 26ef8b36..e2e16415 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -1578,6 +1578,27 @@ export const en: Record = { "import.applying.heading": "Importing into project", "import.applying.hint": "Attaching geometry to the project and rebuilding plan/3D … this can take a moment for very many elements.", + "pick.list.title": "Objects at this spot ({n})", + "pick.list.hint.mac": "⌘-click: next object", + "pick.list.hint.other": "Ctrl-click: next object", + "pick.kind.section": "Section line", + "pick.kind.opening": "Opening", + "pick.kind.wall": "Wall", + "pick.kind.column": "Column", + "pick.kind.drawing": "2D element", + "pick.kind.solid": "Solid", + "pick.kind.ceiling": "Ceiling", + "pick.kind.stair": "Stair", + "pick.kind.room": "Room", + "pick.kind.roof": "Roof", + "pick.kind.context": "Context object", + "pick.shape.line": "Line", + "pick.shape.polyline": "Polyline", + "pick.shape.area": "Area", + "pick.shape.text": "Text", + "pick.shape.circle": "Circle", + "pick.shape.arc": "Arc", + "pick.shape.image": "Image", "import.confirm": "Import", "import.cancel": "Cancel", "import.badge.floor": "Floor", diff --git a/src/plan/PlanView.tsx b/src/plan/PlanView.tsx index 77e111b0..f22f1083 100644 --- a/src/plan/PlanView.tsx +++ b/src/plan/PlanView.tsx @@ -17,6 +17,7 @@ import type { ComponentProps, CSSProperties } from "react"; import type { HatchRender, Plan, PlanImage, Primitive } from "./generatePlan"; import { materializeGreyed, materializeUnderlay, type UnderlayGroup } from "./generatePlan"; import type { Drawing2D, EdgeGrip, Vec2 } from "../model/types"; +import { t } from "../i18n"; import type { ToolHandlers, ToolId, ToolMods } from "../tools/types"; import type { HudFieldsState } from "../tools/hudFormat"; import type { RichTextDoc } from "../text/richText"; @@ -59,10 +60,11 @@ import { DraftOverlay } from "./planView/overlays"; import { PlanRulers } from "./planView/PlanRulers"; import { PlanGrid } from "./planView/PlanGrid"; import { expandRegion, indexedInRegion, regionContains, type Bounds } from "./planView/cullPrimitives"; -import { buildSegmentIndex, nearestSegment, pointSegDist } from "./planView/segmentIndex"; +import { buildSegmentIndex, nearestSegment, pointSegDist, segmentsNear } from "./planView/segmentIndex"; import { buildOwnerIndex, ownedBy, type OwnerField, type OwnerIndex } from "./planView/ownerIndex"; import { buildDrawingIndex, + drawingsWithinDistance, marqueeHitUnderlay, nearestInDrawings, type DrawingIndex, @@ -198,6 +200,48 @@ export interface PlanViewHandle { confirmEdgeEdit: () => void; } +/** Art eines auswählbaren Objekts an einer Klickstelle (Reihenfolge = Standard-Priorität). */ +export type PickKind = + | "section" | "opening" | "wall" | "column" | "drawing" | "solid" + | "ceiling" | "stair" | "room" | "roof" | "context"; + +const PICK_ORDER: readonly PickKind[] = [ + "section", "opening", "wall", "column", "drawing", "solid", + "ceiling", "stair", "room", "roof", "context", +]; + +/** Ein Objekt unter dem Cursor — für das Durchschalten übereinanderliegender Objekte. */ +export interface PickCandidate { + kind: PickKind; + id: string; + /** Polygon-Index (für die lokale Hervorhebung), falls aus einem Polygon. */ + hitIndex: number | null; + /** Kurzbezeichnung für die Liste (z. B. "Wand", "Linie"). */ + label: string; +} + +/** Ids einer Auswahl OHNE Klickposition/Shift — Ergebnis von `defaultPick`. */ +type PickIds = Omit; + +const EMPTY_PICK: PickIds = { + hitIndex: null, + wallId: null, + drawingId: null, + ceilingId: null, + openingId: null, + stairId: null, + roomId: null, + extrudedSolidId: null, + columnId: null, + roofId: null, + sectionLineId: null, + contextObjectId: null, +}; + +/** Mac: Cmd+Klick; sonst Strg+Klick (Alt+Klick ist die Schere, Ctrl+Klick unter macOS das Kontextmenü). */ +const IS_MAC = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform); +const cycleModifier = (e: { metaKey: boolean; ctrlKey: boolean }): boolean => (IS_MAC ? e.metaKey : e.ctrlKey); + /** Ergebnis eines Links-Klicks (Auswahl) an einer Modellposition. */ export interface PlanSelection { /** Klickposition in Modell-Metern. */ @@ -1813,7 +1857,8 @@ export const PlanView = forwardRef( } } // Sonst: auf dem Körper eines gewählten Elements? → Parallel-Verschieben. - const body = grabbedBody(e.clientX, e.clientY); + // Cmd/Strg+Klick = nächstes Objekt wählen, NICHT den gewählten Körper greifen. + const body = cycleModifier(e) ? null : grabbedBody(e.clientX, e.clientY); if (body) { e.preventDefault(); e.currentTarget.setPointerCapture(e.pointerId); @@ -1825,7 +1870,8 @@ export const PlanView = forwardRef( // Griffe inaktiv): Links-Drag auf einem gewählten Körper verschiebt es; die // koinzidenten Enden der übrigen gewählten Elemente wandern mit (App). if (e.button === 0 && !toolActive && !!gripHandlers && !gripsActive) { - const body = grabbedBody(e.clientX, e.clientY); + // Cmd/Strg+Klick = nächstes Objekt wählen, NICHT den gewählten Körper greifen. + const body = cycleModifier(e) ? null : grabbedBody(e.clientX, e.clientY); if (body) { e.preventDefault(); e.currentTarget.setPointerCapture(e.pointerId); @@ -2051,6 +2097,312 @@ export const PlanView = forwardRef( else setView(next); }; + // Standard-Auswahl an einer Stelle (genau die BISHERIGE Prioritätskette: Schnitt- + // linie > Öffnung > Wand > Stütze > 2D > Körper > Decke > Treppe > Raum > Dach > + // Kontext). Liefert nur die Ids + Polygon-Index; `model`/`shift` ergänzt der Aufrufer. + const defaultPick = (clientX: number, clientY: number): PickIds => { + const hitIndex = hitTest(clientX, clientY); + const hit = hitIndex !== null ? plan.primitives[hitIndex] : undefined; + // Öffnung (Fenster/Tür) zuerst: ihr Symbol sitzt in der ausgesparten Lücke + // bzw. schlägt über die Wand — ein Klick nahe am Symbol wählt die Öffnung. + // Schnitt-/Ansichtslinie zuerst: ihr schmales Band liegt über allem, ein + // Klick genau darauf meint die Linie (nicht die darunterliegende Wand) — + // dann sofort melden (kein anderes Element konkurriert). + const sectionLineId = pickSectionLine(clientX, clientY); + if (sectionLineId) { + return { ...EMPTY_PICK, hitIndex, sectionLineId }; + } + const openingId = pickOpening(clientX, clientY); + const wallId = + openingId ? null : hit && hit.kind === "polygon" ? hit.wallId ?? null : null; + // Stütze (Tragwerk): ihre Querschnitt-Poché liegt ÜBER der Wand-Poché — + // ein direkter Klick auf sie trifft zuerst die Stütze (hit.columnId), sonst + // die Fläche per Punkt-in-Polygon. Priorität direkt nach Öffnung/Wand. + const polyColumnId = + hit && hit.kind === "polygon" ? hit.columnId ?? null : null; + const columnId = + openingId || wallId + ? null + : polyColumnId ?? pickColumn(clientX, clientY); + // Traf der Klick KEINE Wand/Öffnung/Stütze: zuerst eine getroffene gefüllte + // 2D-Fläche (Polygon mit drawingId), sonst die 2D-Linien (Drawing2D) per Nähe. + const polyDrawingId = + hit && hit.kind === "polygon" ? hit.drawingId ?? null : null; + const drawingId = + openingId || wallId || columnId + ? null + : polyDrawingId ?? pickDrawing(clientX, clientY); + // Extrudierter Körper (truck-Integration): sein Footprint-Umriss ersetzt + // die frühere Drawing2D-Fläche, also gleiche Priorität wie drawingId. + const polyExtrudedSolidId = + hit && hit.kind === "polygon" ? hit.extrudedSolidId ?? null : null; + const extrudedSolidId = + openingId || wallId || columnId || drawingId + ? null + : polyExtrudedSolidId ?? pickExtrudedSolid(clientX, clientY); + // Decke nur, wenn weder Öffnung/Wand noch 2D-Element getroffen wurde. Da die + // Decken-Polygone UNTER der Wand-Poché liegen, trifft ein direkter Klick + // auf die Wand zuerst die Wand; freie Deckenfläche trifft die Decke. + const hitCeilingId = + hit && hit.kind === "polygon" ? hit.ceilingId ?? null : null; + const ceilingId = + openingId || wallId || columnId || drawingId || extrudedSolidId ? null : hitCeilingId; + // Treppe nur, wenn nichts anderes getroffen wurde (Tritte liegen frei). + const stairId = + openingId || wallId || columnId || drawingId || extrudedSolidId || ceilingId + ? null + : pickStair(clientX, clientY); + // Raum als vorletzte Priorität: die Raum-Fläche liegt UNTER allem anderen. + const roomId = + openingId || wallId || columnId || drawingId || extrudedSolidId || ceilingId || stairId + ? null + : pickRoom(clientX, clientY); + // Dach als LETZTE Priorität: die Traufe-Fläche deckt den ganzen Grundriss + // ab, daher erst wählen, wenn wirklich nichts anderes getroffen wurde. + const roofId = + openingId || wallId || columnId || drawingId || extrudedSolidId || ceilingId || stairId || roomId + ? null + : pickRoof(clientX, clientY); + // Kontext-Objekt (Gebäude/Terrain) als ALLERLETZTE Priorität — seine + // Bbox-Pick-Fläche kann grosszügig überlappen, daher erst wenn wirklich + // nichts anderes getroffen wurde. + const contextObjectId = + openingId || wallId || columnId || drawingId || extrudedSolidId || ceilingId || stairId || roomId || roofId + ? null + : pickContextObject(clientX, clientY); + return { + hitIndex, + wallId, + drawingId, + ceilingId, + openingId, + stairId, + roomId, + extrudedSolidId, + columnId, + roofId, + sectionLineId: null, + contextObjectId, + }; + }; + + // ── Übereinanderliegende Objekte durchschalten ──────────────────────────── + // Cmd+Klick (Mac) / Strg+Klick wählt das nächste Objekt UNTER dem Cursor; + // wiederholtes Klicken an derselben Stelle läuft zyklisch durch alle. Eine + // kleine Liste zeigt alle Objekte an der Stelle (direkt anklickbar). Der + // normale Klick bleibt die bisherige Prioritätskette (`defaultPick`). + const [pickList, setPickList] = useState<{ x: number; y: number; items: PickCandidate[]; idx: number } | null>(null); + const cycleRef = useRef<{ + x: number; + y: number; + prims: readonly Primitive[]; + items: PickCandidate[]; + idx: number; + model: Vec2; + } | null>(null); + // Liste/Zyklus verwerfen, sobald sich Ausschnitt oder Plan ändern. + useEffect(() => { + setPickList(null); + cycleRef.current = null; + }, [view, planRaw]); + useEffect(() => { + if (!pickList) return; + const onKey = (ev: KeyboardEvent) => { + if (ev.key === "Escape") setPickList(null); + }; + window.addEventListener("keydown", onKey); + return () => window.removeEventListener("keydown", onKey); + }, [pickList]); + + /** Alle Polygone unter dem Cursor, oberstes zuerst. */ + const hitTestAll = (clientX: number, clientY: number): number[] => { + const m = rawModelAt(clientX, clientY); + const prims = plan.primitives; + const out: number[] = []; + for (let i = prims.length - 1; i >= 0; i--) { + const p = prims[i]; + if (p.kind === "polygon" && pointInPolygon(m, p.pts)) out.push(i); + } + return out; + }; + + /** Bezeichnung eines 2D-Elements nach Form (Linie/Fläche/Text/Kreis/…). */ + const drawingLabel = (id: string): string => { + const g = getUnderlayIds()?.get(id); + const ud = g?.drawings.find((x) => x.id === id); + if (ud) { + return ud.geom.shape === "line" + ? t("pick.shape.line") + : ud.geom.shape === "polyline" && ud.geom.closed + ? t("pick.shape.area") + : t("pick.shape.polyline"); + } + for (const p of plan.primitives) { + if (!("drawingId" in p) || p.drawingId !== id) continue; + switch (p.kind) { + case "line": return t("pick.shape.line"); + case "polygon": return t("pick.shape.area"); + case "drawingText": + case "drawingTextPath": return t("pick.shape.text"); + case "drawingCircle": return t("pick.shape.circle"); + case "drawingArc": return t("pick.shape.arc"); + case "drawingImage": return t("pick.shape.image"); + default: break; + } + } + return t("pick.kind.drawing"); + }; + + /** IDs ALLER 2D-Elemente nahe am Cursor (nächste zuerst). */ + const nearDrawingIds = (clientX: number, clientY: number): string[] => { + const pxPerM = currentPxPerMeter(); + const m = rawModelAt(clientX, clientY); + const tol = LINE_PICK_PX / pxPerM; + const found: Array<{ id: string; d: number }> = []; + const segIdx = getSegmentIndex(); + if (segIdx) { + for (const { i, dist } of segmentsNear(segIdx, plan.primitives, m, tol)) { + const id = (plan.primitives[i] as Extract).drawingId; + if (id) found.push({ id, d: dist }); + } + } + const uIdx = getUnderlayIndex(); + if (uIdx) for (const h of drawingsWithinDistance(uIdx, m, tol)) found.push({ id: h.drawing.id, d: h.dist }); + for (const p of plan.primitives) { + if ((p.kind === "drawingCircle" || p.kind === "drawingArc") && p.drawingId) { + const dpx = distToDrawingRing(clientX, clientY, p); + if (dpx < LINE_PICK_PX) found.push({ id: p.drawingId, d: dpx / pxPerM }); + } + } + const textId = pickDrawingText(clientX, clientY); + if (textId) found.push({ id: textId, d: tol * 2 }); + const imgId = pickDrawingImage(clientX, clientY); + if (imgId) found.push({ id: imgId, d: tol * 3 }); + found.sort((a, b) => a.d - b.d); + return found.map((f) => f.id); + }; + + /** Alle Objekte unter dem Cursor; Eintrag 0 ist IMMER die bisherige Standardauswahl. */ + const collectCandidates = (clientX: number, clientY: number, dp: PickIds): PickCandidate[] => { + const out: PickCandidate[] = []; + const seen = new Set(); + const add = (kind: PickKind, id: string | null | undefined, hitIndex: number | null) => { + if (!id) return; + const key = `${kind}:${id}`; + if (seen.has(key)) return; + seen.add(key); + out.push({ kind, id, hitIndex, label: kind === "drawing" ? drawingLabel(id) : t(`pick.kind.${kind}`) }); + }; + // 1) Standard-Treffer zuerst. + add("section", dp.sectionLineId, dp.hitIndex); + add("opening", dp.openingId, dp.hitIndex); + add("wall", dp.wallId, dp.hitIndex); + add("column", dp.columnId, dp.hitIndex); + add("drawing", dp.drawingId, dp.hitIndex); + add("solid", dp.extrudedSolidId, dp.hitIndex); + add("ceiling", dp.ceilingId, dp.hitIndex); + add("stair", dp.stairId, dp.hitIndex); + add("room", dp.roomId, dp.hitIndex); + add("roof", dp.roofId, dp.hitIndex); + add("context", dp.contextObjectId, dp.hitIndex); + const first = out.slice(); + // 2) Alles Übrige an dieser Stelle, nach Standard-Priorität sortiert. + const rest: PickCandidate[] = []; + const addRest = (kind: PickKind, id: string | null | undefined, hitIndex: number | null) => { + const before = out.length; + add(kind, id, hitIndex); + if (out.length > before) rest.push(out.pop()!); + }; + for (const idx of hitTestAll(clientX, clientY)) { + const p = plan.primitives[idx]; + if (p.kind !== "polygon") continue; + addRest("opening", p.openingId, idx); + addRest("wall", p.wallId, idx); + addRest("column", p.columnId, idx); + addRest("drawing", p.drawingId, idx); + addRest("solid", p.extrudedSolidId, idx); + addRest("ceiling", p.ceilingId, idx); + addRest("stair", p.stairId, idx); + addRest("room", p.roomId, idx); + addRest("roof", p.roofId, idx); + addRest("context", p.contextObjectId, idx); + addRest("section", p.sectionLineId, idx); + } + for (const id of nearDrawingIds(clientX, clientY)) addRest("drawing", id, null); + addRest("opening", pickOpening(clientX, clientY), null); + addRest("column", pickColumn(clientX, clientY), null); + addRest("solid", pickExtrudedSolid(clientX, clientY), null); + addRest("stair", pickStair(clientX, clientY), null); + addRest("room", pickRoom(clientX, clientY), null); + addRest("roof", pickRoof(clientX, clientY), null); + addRest("context", pickContextObject(clientX, clientY), null); + addRest("section", pickSectionLine(clientX, clientY), null); + // Stabil nach Standard-Priorität ordnen (innerhalb einer Art bleibt die Fundreihenfolge). + const ordered = rest + .map((c, i) => ({ c, i })) + .sort((a, b) => PICK_ORDER.indexOf(a.c.kind) - PICK_ORDER.indexOf(b.c.kind) || a.i - b.i) + .map((e) => e.c); + return [...first, ...ordered]; + }; + + const applyCandidate = (c: PickCandidate, model: Vec2, shift: boolean) => { + if (!onSelect) return; + setSelected(c.hitIndex); + onSelect({ + ...EMPTY_PICK, + model, + hitIndex: c.hitIndex, + shift, + wallId: c.kind === "wall" ? c.id : null, + drawingId: c.kind === "drawing" ? c.id : null, + ceilingId: c.kind === "ceiling" ? c.id : null, + openingId: c.kind === "opening" ? c.id : null, + stairId: c.kind === "stair" ? c.id : null, + roomId: c.kind === "room" ? c.id : null, + extrudedSolidId: c.kind === "solid" ? c.id : null, + columnId: c.kind === "column" ? c.id : null, + roofId: c.kind === "roof" ? c.id : null, + sectionLineId: c.kind === "section" ? c.id : null, + contextObjectId: c.kind === "context" ? c.id : null, + }); + }; + + /** + * Cmd/Strg+Klick: nächstes Objekt unter dem Cursor wählen. Liefert true, wenn + * behandelt (sonst läuft der normale Klick weiter, z. B. bei leerer Stelle). + */ + const cycleSelect = (e: React.PointerEvent): boolean => { + const prev = cycleRef.current; + const same = + prev && + prev.prims === plan.primitives && + Math.hypot(e.clientX - prev.x, e.clientY - prev.y) <= 5; + let items: PickCandidate[]; + let idx: number; + let model: Vec2; + if (same) { + items = prev!.items; + idx = (prev!.idx + 1) % items.length; + model = prev!.model; + } else { + items = collectCandidates(e.clientX, e.clientY, defaultPick(e.clientX, e.clientY)); + if (items.length === 0) return false; + idx = items.length > 1 ? 1 : 0; // erster Cmd-Klick: das Objekt UNTER dem Standard-Treffer + const v = clientToView(e.clientX, e.clientY, view); + model = viewToModel(v.x, v.y); + } + cycleRef.current = { x: e.clientX, y: e.clientY, prims: plan.primitives, items, idx, model }; + applyCandidate(items[idx], model, e.shiftKey); + const rect = svgRef.current?.getBoundingClientRect(); + setPickList({ + x: e.clientX - (rect?.left ?? 0) + 14, + y: e.clientY - (rect?.top ?? 0) + 14, + items, + idx, + }); + return true; + }; + const endDrag = (e: React.PointerEvent) => { // Perf: einen anhängigen (rAF-gedrosselten) Drag mit der FINALEN Position // sofort anwenden, damit das Objekt exakt an der Loslass-Stelle landet, bevor @@ -2161,112 +2513,16 @@ export const PlanView = forwardRef( setMarqueeRect(null); return; } - // Kein Drag → Klick: Wand unter dem Cursor wählen bzw. Auswahl löschen. + // Kein Drag → Klick: Objekt unter dem Cursor wählen bzw. Auswahl löschen. setMarqueeRect(null); - const hitIndex = hitTest(e.clientX, e.clientY); - setSelected(hitIndex); + if (onSelect && cycleModifier(e) && cycleSelect(e)) return; + setPickList(null); + cycleRef.current = null; + const dp = defaultPick(e.clientX, e.clientY); + setSelected(dp.hitIndex); if (onSelect) { const v = clientToView(e.clientX, e.clientY, view); - const hit = hitIndex !== null ? plan.primitives[hitIndex] : undefined; - // Öffnung (Fenster/Tür) zuerst: ihr Symbol sitzt in der ausgesparten Lücke - // bzw. schlägt über die Wand — ein Klick nahe am Symbol wählt die Öffnung. - // Schnitt-/Ansichtslinie zuerst: ihr schmales Band liegt über allem, ein - // Klick genau darauf meint die Linie (nicht die darunterliegende Wand) — - // dann sofort melden (kein anderes Element konkurriert). - const sectionLineId = pickSectionLine(e.clientX, e.clientY); - if (sectionLineId) { - onSelect({ - model: viewToModel(v.x, v.y), - hitIndex, - wallId: null, - drawingId: null, - ceilingId: null, - openingId: null, - stairId: null, - roomId: null, - extrudedSolidId: null, - columnId: null, - roofId: null, - sectionLineId, - contextObjectId: null, - shift: e.shiftKey, - }); - return; - } - const openingId = pickOpening(e.clientX, e.clientY); - const wallId = - openingId ? null : hit && hit.kind === "polygon" ? hit.wallId ?? null : null; - // Stütze (Tragwerk): ihre Querschnitt-Poché liegt ÜBER der Wand-Poché — - // ein direkter Klick auf sie trifft zuerst die Stütze (hit.columnId), sonst - // die Fläche per Punkt-in-Polygon. Priorität direkt nach Öffnung/Wand. - const polyColumnId = - hit && hit.kind === "polygon" ? hit.columnId ?? null : null; - const columnId = - openingId || wallId - ? null - : polyColumnId ?? pickColumn(e.clientX, e.clientY); - // Traf der Klick KEINE Wand/Öffnung/Stütze: zuerst eine getroffene gefüllte - // 2D-Fläche (Polygon mit drawingId), sonst die 2D-Linien (Drawing2D) per Nähe. - const polyDrawingId = - hit && hit.kind === "polygon" ? hit.drawingId ?? null : null; - const drawingId = - openingId || wallId || columnId - ? null - : polyDrawingId ?? pickDrawing(e.clientX, e.clientY); - // Extrudierter Körper (truck-Integration): sein Footprint-Umriss ersetzt - // die frühere Drawing2D-Fläche, also gleiche Priorität wie drawingId. - const polyExtrudedSolidId = - hit && hit.kind === "polygon" ? hit.extrudedSolidId ?? null : null; - const extrudedSolidId = - openingId || wallId || columnId || drawingId - ? null - : polyExtrudedSolidId ?? pickExtrudedSolid(e.clientX, e.clientY); - // Decke nur, wenn weder Öffnung/Wand noch 2D-Element getroffen wurde. Da die - // Decken-Polygone UNTER der Wand-Poché liegen, trifft ein direkter Klick - // auf die Wand zuerst die Wand; freie Deckenfläche trifft die Decke. - const hitCeilingId = - hit && hit.kind === "polygon" ? hit.ceilingId ?? null : null; - const ceilingId = - openingId || wallId || columnId || drawingId || extrudedSolidId ? null : hitCeilingId; - // Treppe nur, wenn nichts anderes getroffen wurde (Tritte liegen frei). - const stairId = - openingId || wallId || columnId || drawingId || extrudedSolidId || ceilingId - ? null - : pickStair(e.clientX, e.clientY); - // Raum als vorletzte Priorität: die Raum-Fläche liegt UNTER allem anderen. - const roomId = - openingId || wallId || columnId || drawingId || extrudedSolidId || ceilingId || stairId - ? null - : pickRoom(e.clientX, e.clientY); - // Dach als LETZTE Priorität: die Traufe-Fläche deckt den ganzen Grundriss - // ab, daher erst wählen, wenn wirklich nichts anderes getroffen wurde. - const roofId = - openingId || wallId || columnId || drawingId || extrudedSolidId || ceilingId || stairId || roomId - ? null - : pickRoof(e.clientX, e.clientY); - // Kontext-Objekt (Gebäude/Terrain) als ALLERLETZTE Priorität — seine - // Bbox-Pick-Fläche kann grosszügig überlappen, daher erst wenn wirklich - // nichts anderes getroffen wurde. - const contextObjectId = - openingId || wallId || columnId || drawingId || extrudedSolidId || ceilingId || stairId || roomId || roofId - ? null - : pickContextObject(e.clientX, e.clientY); - onSelect({ - model: viewToModel(v.x, v.y), - hitIndex, - wallId, - drawingId, - ceilingId, - openingId, - stairId, - roomId, - extrudedSolidId, - columnId, - roofId, - sectionLineId: null, - contextObjectId, - shift: e.shiftKey, - }); + onSelect({ model: viewToModel(v.x, v.y), ...dp, shift: e.shiftKey }); } return; } @@ -3317,6 +3573,38 @@ export const PlanView = forwardRef( ); })()} + {pickList && ( +
ev.stopPropagation()} + onClick={(ev) => ev.stopPropagation()} + > +
+ {t("pick.list.title", { n: pickList.items.length })} +
+ {pickList.items.map((c, i) => ( + + ))} +
{t(IS_MAC ? "pick.list.hint.mac" : "pick.list.hint.other")}
+
+ )} ); }); diff --git a/src/plan/planView/segmentIndex.test.ts b/src/plan/planView/segmentIndex.test.ts index 54e433dc..e925c6de 100644 --- a/src/plan/planView/segmentIndex.test.ts +++ b/src/plan/planView/segmentIndex.test.ts @@ -60,3 +60,16 @@ describe("segmentIndex", () => { expect(nearestSegment(idx, prims, { x: 500, y: 500 }, 1)).toBeNull(); }); }); + +describe("segmentsNear (alle Treffer, nächster zuerst)", () => { + it("liefert alle Segmente in Reichweite, sortiert, und entspricht der linearen Suche", async () => { + const { segmentsNear } = await import("./segmentIndex"); + const prims: Primitive[] = [line(0, 0, 10, 0, "a"), line(0, 0.5, 10, 0.5, "b"), line(0, 5, 10, 5, "c"), line(-2000, -2000, 2000, 2000, "long")]; + for (let i = 0; i < 300; i++) prims.push(line(50 + i, 50, 51 + i, 51, `f${i}`)); + const idx = buildSegmentIndex(prims)!; + const hits = segmentsNear(idx, prims, { x: 5, y: 0.2 }, 1); + expect(hits.map((h) => (prims[h.i] as any).drawingId)).toEqual(["a", "b"].concat(hits.length > 2 ? ["long"] : []).slice(0, hits.length)); + expect(hits[0].dist).toBeLessThanOrEqual(hits[1].dist); + expect(hits.every((h) => h.dist < 1)).toBe(true); + }); +}); diff --git a/src/plan/planView/segmentIndex.ts b/src/plan/planView/segmentIndex.ts index 4422b6ba..b4ce8031 100644 --- a/src/plan/planView/segmentIndex.ts +++ b/src/plan/planView/segmentIndex.ts @@ -131,3 +131,33 @@ export function nearestSegment( } return best; } + +/** ALLE indizierten Segmente mit Abstand < `maxDist` (Modell-Einheiten), nächste zuerst. */ +export function segmentsNear( + index: SegmentIndex, + prims: readonly Primitive[], + m: Vec2, + maxDist: number, +): Array<{ i: number; dist: number }> { + const { minX, minY, cell, cols, rows, cellStart, items, long } = index; + const found = new Map(); + const consider = (i: number) => { + const p = prims[i] as Extract; + const d = pointSegDist(m, p.a, p.b); + if (d < maxDist) found.set(i, d); + }; + for (const i of long) consider(i); + const x0 = Math.floor((m.x - maxDist - minX) / cell); + const x1 = Math.floor((m.x + maxDist - minX) / cell); + const y0 = Math.floor((m.y - maxDist - minY) / cell); + const y1 = Math.floor((m.y + maxDist - minY) / cell); + if (!(x1 < 0 || y1 < 0 || x0 >= cols || y0 >= rows)) { + for (let y = Math.max(0, y0); y <= Math.min(rows - 1, y1); y++) { + for (let x = Math.max(0, x0); x <= Math.min(cols - 1, x1); x++) { + const c = y * cols + x; + for (let k = cellStart[c]; k < cellStart[c + 1]; k++) consider(items[k]); + } + } + } + return [...found].map(([i, dist]) => ({ i, dist })).sort((a, b) => a.dist - b.dist); +} diff --git a/src/plan/planView/underlayAccess.test.ts b/src/plan/planView/underlayAccess.test.ts index 9b232282..f8484f6d 100644 --- a/src/plan/planView/underlayAccess.test.ts +++ b/src/plan/planView/underlayAccess.test.ts @@ -75,3 +75,14 @@ describe("underlayAccess == Primitiv-Varianten", () => { } }); }); + +describe("drawingsWithinDistance", () => { + it("liefert alle Zeichnungen in Reichweite, nächste zuerst", async () => { + const { drawingsWithinDistance, buildDrawingIndex: build } = await import("../../geometry/drawingIndex"); + const mk = (id: string, y: number) => + ({ id, type: "drawing2d", levelId: "L", categoryCode: "60", geom: { shape: "line", a: { x: 0, y }, b: { x: 10, y } } }) as Drawing2D; + const ds = [mk("near", 0.3), mk("nearer", 0.1), mk("far", 9)]; + const hits = drawingsWithinDistance(build(ds)!, { x: 5, y: 0 }, 1); + expect(hits.map((h) => h.drawing.id)).toEqual(["nearer", "near"]); + }); +}); diff --git a/src/plan/planView/underlayAccess.ts b/src/plan/planView/underlayAccess.ts index 843d6913..034904e2 100644 --- a/src/plan/planView/underlayAccess.ts +++ b/src/plan/planView/underlayAccess.ts @@ -9,7 +9,7 @@ import type { ModelRect } from "./geometry"; import { polyEnclosedByRect, polyTouchesRect } from "./geometry"; import { drawingBox } from "../../geometry/drawingBounds"; import { forEachSegment } from "../../geometry/drawingIndex"; -export { buildDrawingIndex, nearestInDrawings, type DrawingIndex } from "../../geometry/drawingIndex"; +export { buildDrawingIndex, drawingsWithinDistance, nearestInDrawings, type DrawingIndex } from "../../geometry/drawingIndex"; // ── Marquee ───────────────────────────────────────────────────────────────── diff --git a/src/styles.css b/src/styles.css index c555c6bf..fa15b997 100644 --- a/src/styles.css +++ b/src/styles.css @@ -7977,3 +7977,42 @@ body { @keyframes busy-spin { to { transform: rotate(360deg); } } + +/* Liste der Objekte an der Klickstelle (Cmd/Strg+Klick = nächstes Objekt). */ +.pick-list { + position: absolute; + z-index: 5; + min-width: 190px; + max-height: 60%; + overflow: auto; + padding: 4px; + background: var(--panel); + border: 1px solid var(--border); + border-radius: 8px; + box-shadow: var(--shadow-3); + font-size: 12px; + color: var(--text); +} +.pick-list-head { + padding: 4px 8px 6px; + font-weight: 600; + color: var(--text-dim, var(--text)); +} +.pick-list-item { + display: block; + width: 100%; + padding: 5px 8px; + text-align: left; + background: transparent; + border: 0; + border-radius: 5px; + color: inherit; + cursor: pointer; +} +.pick-list-item:hover { background: var(--hover, rgba(128, 128, 128, 0.15)); } +.pick-list-item.is-current { background: var(--accent-soft, rgba(255, 140, 0, 0.22)); font-weight: 600; } +.pick-list-hint { + padding: 6px 8px 2px; + opacity: 0.65; + font-size: 11px; +}