Esc hebt Auswahl auf; Auswahl-Hervorhebung nativ auf der GPU (schnelles An-/Abwaehlen); Lineal und Overlay im Takt der nativen Flaeche (fluessig, kein Versatz der Pfeile)
This commit is contained in:
1 parent
27fb681f7c
commit
e4c164cb29
6 files changed
+176
-21
No files matched your search
@@ -170,6 +170,9 @@ pub struct LineBatch {
|
||||
pub stroke_mm: f32,
|
||||
#[serde(default)]
|
||||
pub screen_px: bool,
|
||||
/// Breite ist bereits in GERAETE-px (zoom-unabhaengig, z. B. Auswahl-Hervorhebung).
|
||||
#[serde(default)]
|
||||
pub device_px: bool,
|
||||
}
|
||||
|
||||
/// Ein Chunk (== `GpuGeometry` der Webview): Puffer-IDs statt GL-Puffer.
|
||||
@@ -569,7 +572,7 @@ impl ChunkRenderer {
|
||||
color: c,
|
||||
viewport_px: vp,
|
||||
stroke_px: b.stroke_mm,
|
||||
stroke_scale: if b.screen_px { meet as f32 } else { mm_px as f32 },
|
||||
stroke_scale: if b.device_px { 1.0 } else if b.screen_px { meet as f32 } else { mm_px as f32 },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+46
-7
@@ -28,7 +28,7 @@ import { RichTextEditor } from "../text/RichTextEditor";
|
||||
import { useGlPlanRenderer } from "./useGlPlanRenderer";
|
||||
import { useNativeAvailable, useNativePlanRenderer } from "./useNativePlanRenderer";
|
||||
import { isGpuText } from "./nativeText";
|
||||
import { LiveMeet, createMeetStore } from "./planView/liveMeet";
|
||||
import { LiveMeet, LiveValue, createMeetStore, createValueStore } from "./planView/liveMeet";
|
||||
import { useWasmPlanRenderer } from "./useWasmPlanRenderer";
|
||||
import { DEFAULT_MARQUEE_COLOR, DEFAULT_SNAP_COLOR } from "../theme/accents";
|
||||
import {
|
||||
@@ -942,6 +942,8 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
|
||||
viewRef.current = view;
|
||||
// Live-Massstab für bildschirmkonstante Overlays während Pan/Zoom (s. liveMeet.tsx).
|
||||
const meetStore = useMemo(() => createMeetStore(), []);
|
||||
// Live-Ausschnitt (Lineal) während Pan/Zoom.
|
||||
const viewStore = useMemo(() => createValueStore<ViewBox>(), []);
|
||||
const defaultViewRef = useRef(defaultView);
|
||||
defaultViewRef.current = defaultView;
|
||||
const toScreenRef = useRef(toScreen);
|
||||
@@ -1995,9 +1997,27 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
|
||||
const v0 = panStartView.current;
|
||||
if (!v || !v0) return;
|
||||
viewRef.current = v; // abgeleitete Reads (Snap-Toleranz etc.) frisch halten
|
||||
meetStore.set(meetScale(v, canvasRef.current ?? svgRef.current)); // Griffe/Fangpunkt in Pixelgrösse halten
|
||||
applySvgTransform(v0, v); // SVG per GPU-Composit (kein Re-Raster)
|
||||
renderGl(v, paperScaleForGl(v), textScaleForGl()); // GL exakt auf V (Strich in echten Papier-mm)
|
||||
// Overlay (SVG-Ausschnitt, Griffe/Fangpunkt-Grösse, Lineal) wird im SELBEN
|
||||
// Takt wie die Geometrie angewendet: die native Fläche bestätigt ihren Frame
|
||||
// erst nach dem Schnittstellen-Aufruf — liefe das Overlay voraus, würden
|
||||
// Pfeile/Griffe sichtbar gegen die Linien wandern ("spinnen").
|
||||
const apply = () => {
|
||||
if (panPending.current !== v) return; // überholt oder bereits festgeschrieben
|
||||
applySvgTransform(v0, v); // SVG: echter viewBox (scharf) bzw. CSS-Transform
|
||||
meetStore.set(meetScale(v, canvasRef.current ?? svgRef.current));
|
||||
viewStore.set(v);
|
||||
};
|
||||
if (wantNative) {
|
||||
(renderGl as (vb: ViewBox, ps: number, ts: number, onApplied: () => void) => void)(
|
||||
v,
|
||||
paperScaleForGl(v),
|
||||
textScaleForGl(),
|
||||
apply,
|
||||
);
|
||||
} else {
|
||||
renderGl(v, paperScaleForGl(v), textScaleForGl()); // GL exakt auf V (Strich in echten Papier-mm)
|
||||
apply();
|
||||
}
|
||||
};
|
||||
/** Pan-/Zoom-Ziel imperativ anwenden (rAF-gedrosselt), ohne React-Render. */
|
||||
const enqueuePan = (v: ViewBox) => {
|
||||
@@ -2016,6 +2036,7 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
|
||||
if (svgRef.current) svgRef.current.style.transform = "";
|
||||
setView(panPending.current);
|
||||
meetStore.set(null);
|
||||
viewStore.set(null);
|
||||
panPending.current = null;
|
||||
}
|
||||
panStartView.current = null;
|
||||
@@ -2789,7 +2810,24 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
|
||||
// Auswahl-Hervorhebung als EIN <path> je Art statt eines DOM-Elements je Objekt:
|
||||
// bei tausenden gewählten Katasterobjekten war der DOM-Aufbau (nicht die Auswahl)
|
||||
// der Engpass. Aussehen identisch (beide Klassen: fill none, Kontur).
|
||||
// Native Fläche aktiv → sie zeichnet die Auswahl-Hervorhebung selbst (GPU).
|
||||
const nativeHighlight = useGpuRenderer && wantNative;
|
||||
const setNativeHighlight = nativeHook.setHighlight;
|
||||
useEffect(() => {
|
||||
if (!nativeHighlight) return;
|
||||
const accent =
|
||||
typeof document !== "undefined"
|
||||
? getComputedStyle(document.documentElement).getPropertyValue("--accent").trim() || "#2f6fed"
|
||||
: "#2f6fed";
|
||||
setNativeHighlight(highlightDrawPrims, accent);
|
||||
}, [nativeHighlight, highlightDrawPrims, setNativeHighlight]);
|
||||
useEffect(() => {
|
||||
// Beim Verlassen des nativen Modus die native Hervorhebung leeren.
|
||||
if (!nativeHighlight) return;
|
||||
return () => setNativeHighlight([], "#000");
|
||||
}, [nativeHighlight, setNativeHighlight]);
|
||||
const highlightDrawPath = useMemo(() => {
|
||||
if (nativeHighlight) return "";
|
||||
const parts: string[] = [];
|
||||
for (const p of highlightDrawPrims) {
|
||||
if (p.kind === "line") {
|
||||
@@ -2802,7 +2840,7 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
|
||||
}
|
||||
return parts.join("");
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [highlightDrawPrims]);
|
||||
}, [highlightDrawPrims, nativeHighlight]);
|
||||
overlayHeavyRef.current = highlightDrawPath.length > 300_000;
|
||||
const highlightTextPath = useMemo(() => {
|
||||
const parts: string[] = [];
|
||||
@@ -3705,7 +3743,8 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
|
||||
fixiert zu bleiben. Als eigenständiges Element bleibt es während der
|
||||
Geste stehen (aktualisiert erst beim Loslassen, wenn `view` neu
|
||||
gesetzt wird) — exakt das gewünschte „statische" Verhalten. */}
|
||||
{showRulers && (() => {
|
||||
{showRulers && (<LiveValue store={viewStore} base={view}>{(liveView) => {
|
||||
const view = liveView;
|
||||
const m = measure(view);
|
||||
if (!m.rect) return null;
|
||||
const scale = m.scale || 1;
|
||||
@@ -3737,7 +3776,7 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
})()}
|
||||
}}</LiveValue>)}
|
||||
{pickList && (
|
||||
<div
|
||||
className="pick-list"
|
||||
|
||||
@@ -23,7 +23,7 @@ export interface NativeChunkLayout {
|
||||
fill_batches: { start: number; count: number; color: number[] }[];
|
||||
line_vtx: number | null;
|
||||
line_idx: number | null;
|
||||
line_batches: { start: number; count: number; color: number[]; stroke_mm: number; screen_px: boolean }[];
|
||||
line_batches: { start: number; count: number; color: number[]; stroke_mm: number; screen_px: boolean; device_px?: boolean }[];
|
||||
origin: [number, number];
|
||||
greyed: boolean;
|
||||
}
|
||||
|
||||
@@ -11,14 +11,16 @@
|
||||
|
||||
import { useSyncExternalStore, type ReactNode } from "react";
|
||||
|
||||
export interface MeetStore {
|
||||
get(): number | null;
|
||||
set(v: number | null): void;
|
||||
export interface ValueStore<T> {
|
||||
get(): T | null;
|
||||
set(v: T | null): void;
|
||||
subscribe(l: () => void): () => void;
|
||||
}
|
||||
export type MeetStore = ValueStore<number>;
|
||||
|
||||
export function createMeetStore(): MeetStore {
|
||||
let value: number | null = null;
|
||||
/** Kleiner externer Wert-Speicher (für useSyncExternalStore). */
|
||||
export function createValueStore<T>(): ValueStore<T> {
|
||||
let value: T | null = null;
|
||||
const listeners = new Set<() => void>();
|
||||
return {
|
||||
get: () => value,
|
||||
@@ -35,7 +37,17 @@ export function createMeetStore(): MeetStore {
|
||||
}
|
||||
|
||||
/** Rendert `children(meet)` mit dem Live-Massstab (null → `base` aus dem React-State). */
|
||||
export function createMeetStore(): MeetStore {
|
||||
return createValueStore<number>();
|
||||
}
|
||||
|
||||
export function LiveMeet({ store, base, children }: { store: MeetStore; base: number; children: (meet: number) => ReactNode }) {
|
||||
const live = useSyncExternalStore(store.subscribe, store.get);
|
||||
return <>{children(live ?? base)}</>;
|
||||
}
|
||||
|
||||
/** Wie {@link LiveMeet}, für beliebige Live-Werte (z. B. den Ausschnitt fürs Lineal). */
|
||||
export function LiveValue<T>({ store, base, children }: { store: ValueStore<T>; base: T; children: (v: T) => ReactNode }) {
|
||||
const live = useSyncExternalStore(store.subscribe, store.get);
|
||||
return <>{children(live ?? base)}</>;
|
||||
}
|
||||
@@ -10,7 +10,8 @@
|
||||
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import type { Plan } from './generatePlan';
|
||||
import { GpuChunkCache, type ViewBox } from './glPlan';
|
||||
import { GpuChunkCache, compilePrimitivesToGpu, type GpuGeometry, type ViewBox } from './glPlan';
|
||||
import type { Primitive } from './generatePlan';
|
||||
import { NativeGl, type NativeInvoke } from './glPlan/nativeGl';
|
||||
import { readCssColor } from './useGlPlanRenderer';
|
||||
import { NativeTextSync } from './nativeText';
|
||||
@@ -78,6 +79,9 @@ export function useNativePlanRenderer(
|
||||
const textSync = useRef(new NativeTextSync());
|
||||
const textsDisabled = useRef(false);
|
||||
const lastPlan = useRef<Plan | null>(null);
|
||||
// Auswahl-Hervorhebung als eigene native Geometrie (zuoberst, konstante Pixelbreite).
|
||||
const highlightGeom = useRef<GpuGeometry | null>(null);
|
||||
const lastPxPerMeter = useRef(0);
|
||||
const excludedText = useRef<string | null>(null);
|
||||
|
||||
const pushTexts = useCallback((plan: Plan | null) => {
|
||||
@@ -188,6 +192,7 @@ export function useNativePlanRenderer(
|
||||
const { remove } = textSync.current.delta([]);
|
||||
if (remove.length) void invoke('native2d_texts', { upsert: [], remove }).catch(() => {});
|
||||
lastPlan.current = null;
|
||||
highlightGeom.current = null;
|
||||
setGpuTexts(false);
|
||||
const { delete: del } = glRef.current.takeLayout([]);
|
||||
void invoke('native2d_layout', { layout: [], delete: del }).catch(() => {});
|
||||
@@ -200,6 +205,55 @@ export function useNativePlanRenderer(
|
||||
};
|
||||
}, [enabled, canvasRef, syncRect]);
|
||||
|
||||
/** Layout = Plan-Chunks + (optional) Auswahl-Hervorhebung zuoberst. */
|
||||
const takeFullLayout = useCallback(() => {
|
||||
const gl = glRef.current!;
|
||||
const geoms = cacheRef.current?.geometries ?? [];
|
||||
const hl = highlightGeom.current;
|
||||
const res = gl.takeLayout(hl ? [...geoms, hl] : geoms);
|
||||
if (hl && res.layout.length) {
|
||||
const dpr = typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1;
|
||||
const last = res.layout[res.layout.length - 1];
|
||||
last.line_batches = last.line_batches.map((b) => ({ ...b, stroke_mm: 2.5 * dpr, device_px: true }));
|
||||
}
|
||||
return res;
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* Auswahl-Hervorhebung nativ zeichnen (statt eines riesigen SVG-Pfads, dessen
|
||||
* Rastern bei grossen Kataster-Auswahlen beim An-/Abwählen Hunderte ms kostete).
|
||||
*/
|
||||
const setHighlight = useCallback(
|
||||
(prims: readonly Primitive[], color: string) => {
|
||||
const gl = glRef.current;
|
||||
const invoke = invokeRef.current;
|
||||
if (!gl || !invoke) return;
|
||||
const old = highlightGeom.current;
|
||||
if (old) {
|
||||
gl.deleteBuffer(old.fill.positionBuffer);
|
||||
gl.deleteBuffer(old.fill.indexBuffer);
|
||||
gl.deleteBuffer(old.line.vertexBuffer);
|
||||
gl.deleteBuffer(old.line.indexBuffer);
|
||||
highlightGeom.current = null;
|
||||
}
|
||||
if (prims.length) {
|
||||
const lines: Primitive[] = [];
|
||||
const mk = (a: { x: number; y: number }, b: { x: number; y: number }, drawingId?: string) =>
|
||||
lines.push({ kind: 'line', a, b, cls: 'sel', weightMm: 0.3, color, drawingId } as Primitive);
|
||||
for (const p of prims) {
|
||||
if (p.kind === 'line') mk(p.a, p.b, p.drawingId);
|
||||
else if (p.kind === 'polygon' && p.pts.length > 1) {
|
||||
for (let i = 0; i < p.pts.length; i++) mk(p.pts[i], p.pts[(i + 1) % p.pts.length], p.drawingId);
|
||||
}
|
||||
}
|
||||
highlightGeom.current = compilePrimitivesToGpu(gl, lines, lastPxPerMeter.current);
|
||||
}
|
||||
const { layout, delete: del } = takeFullLayout();
|
||||
void invoke('native2d_layout', { layout, delete: del }).catch(() => {});
|
||||
},
|
||||
[takeFullLayout],
|
||||
);
|
||||
|
||||
const updateGeometry = useCallback((plan: Plan, pxPerMeter = 0) => {
|
||||
const cache = cacheRef.current;
|
||||
const gl = glRef.current;
|
||||
@@ -217,19 +271,23 @@ export function useNativePlanRenderer(
|
||||
console.warn('Tessellierung fehlgeschlagen:', e);
|
||||
cache.dispose();
|
||||
}
|
||||
const { layout, delete: del } = gl.takeLayout(cache.geometries);
|
||||
lastPxPerMeter.current = pxPerMeter;
|
||||
const { layout, delete: del } = takeFullLayout();
|
||||
lastPlan.current = plan;
|
||||
// Direkt (nicht über sendFrame): Reihenfolge nach den Puffer-Uploads ist wichtig.
|
||||
void invoke('native2d_layout', { layout, delete: del }).catch((e) =>
|
||||
console.debug('native2d_layout fehlgeschlagen', e),
|
||||
);
|
||||
pushTexts(plan);
|
||||
}, [pushTexts]);
|
||||
}, [pushTexts, takeFullLayout]);
|
||||
|
||||
const render = useCallback(
|
||||
(viewBox: ViewBox, paperScaleN = 100) => {
|
||||
(viewBox: ViewBox, paperScaleN = 100, _textScale?: number, onApplied?: () => void) => {
|
||||
const invoke = invokeRef.current;
|
||||
if (!invoke) return;
|
||||
if (!invoke) {
|
||||
onApplied?.();
|
||||
return;
|
||||
}
|
||||
syncRect();
|
||||
const sheet = readCssColor('--sheet');
|
||||
sendFrame(() =>
|
||||
@@ -237,11 +295,20 @@ export function useNativePlanRenderer(
|
||||
view: viewBox,
|
||||
paperScale: paperScaleN,
|
||||
clear: sheet ? [sheet[0], sheet[1], sheet[2]] : null,
|
||||
}),
|
||||
}).then(
|
||||
(r) => {
|
||||
onApplied?.();
|
||||
return r;
|
||||
},
|
||||
(e) => {
|
||||
onApplied?.();
|
||||
throw e;
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
[sendFrame, syncRect],
|
||||
);
|
||||
|
||||
return { render, updateGeometry, ready, gpuTexts, setExcludedText };
|
||||
return { render, updateGeometry, ready, gpuTexts, setExcludedText, setHighlight };
|
||||
}
|
||||
@@ -332,6 +332,39 @@ export function useSelectAllAndDeleteShortcut(opts: {
|
||||
if (activeTool !== "select") return;
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (isEditableTarget(e)) return;
|
||||
// Escape = Auswahl aufheben. Erst NACH den anderen Escape-Handlern prüfen
|
||||
// (bewaffneter Griff, Entwurf, Dialoge verbrauchen Esc per preventDefault) —
|
||||
// daher im Mikro-Task: nur wenn niemand sonst Esc beansprucht hat.
|
||||
if (e.key === "Escape" && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
||||
queueMicrotask(() => {
|
||||
if (e.defaultPrevented) return;
|
||||
const any =
|
||||
opts.selectedDrawingIds.length > 0 ||
|
||||
opts.selectedWallIds.length > 0 ||
|
||||
opts.selectedCeilingIds.length > 0 ||
|
||||
opts.selectedOpeningIds.length > 0 ||
|
||||
opts.selectedStairIds.length > 0 ||
|
||||
opts.selectedRoomIds.length > 0 ||
|
||||
opts.selectedExtrudedSolidIds.length > 0 ||
|
||||
opts.selectedColumnIds.length > 0 ||
|
||||
opts.selectedRoofIds.length > 0 ||
|
||||
opts.selectedContextObjectIds.length > 0 ||
|
||||
opts.selectedSectionLineIds.length > 0;
|
||||
if (!any) return;
|
||||
setSelectedWallIds([]);
|
||||
setSelectedDrawingIds([]);
|
||||
setSelectedCeilingIds([]);
|
||||
setSelectedOpeningIds([]);
|
||||
setSelectedStairIds([]);
|
||||
setSelectedRoomIds([]);
|
||||
setSelectedExtrudedSolidIds([]);
|
||||
setSelectedColumnIds([]);
|
||||
setSelectedRoofIds([]);
|
||||
opts.setSelectedContextObjectIds([]);
|
||||
setSelectedSectionLineIds([]);
|
||||
});
|
||||
return;
|
||||
}
|
||||
// Alles auswählen (alle Bauteilarten des aktiven Geschosses/der Ebene +
|
||||
// die Schnittlinien-Symbole, die auf JEDEM Grundriss erscheinen).
|
||||
if (matchesShortcut(e, "selectAll", shortcutOverrides)) {
|
||||
@@ -425,6 +458,7 @@ export function useSelectAllAndDeleteShortcut(opts: {
|
||||
opts.selectedCeilingIds,
|
||||
opts.selectedOpeningIds,
|
||||
opts.selectedStairIds,
|
||||
opts.selectedRoomIds,
|
||||
opts.selectedExtrudedSolidIds,
|
||||
opts.selectedColumnIds,
|
||||
opts.selectedRoofIds,
|
||||
|
||||
Reference in new issue
Block a user