Merge branch 'worktree-agent-a8a5cc245da2f38b2' into claude/practical-noether-1hb2s1
# Conflicts: # src/panels/ObjectInfoPanel.tsx
This commit is contained in:
39 files changed
+9917
-8624
No files matched your search
@@ -43,19 +43,15 @@ const END_MARK_OPTIONS: EndMark[] = ["none", "arrow", "arrowOpen", "dot", "tick"
|
||||
// Element-spezifische Attribut-Abschnitte (Wand/Decke/Öffnung/Treppe/Raum) —
|
||||
// aus ObjectInfoPanel hierher verschoben (Ribbon Phase 3: ObjectInfo trägt nur
|
||||
// noch Bezugspunkt + Masse).
|
||||
import {
|
||||
WallSection,
|
||||
CeilingSection,
|
||||
RoofSection,
|
||||
OpeningSection,
|
||||
StairSection,
|
||||
RoomSection,
|
||||
ExtrudedSolidSection,
|
||||
ColumnSection,
|
||||
SectionLineSection,
|
||||
DetailRefSection,
|
||||
DimRefsSection,
|
||||
} from "./ObjectInfoPanel";
|
||||
import { WallSection } from "./objectInfo/WallSection";
|
||||
import { CeilingSection } from "./objectInfo/CeilingSection";
|
||||
import { RoofSection } from "./objectInfo/RoofSections";
|
||||
import { OpeningSection } from "./objectInfo/OpeningSections";
|
||||
import { StairSection } from "./objectInfo/StairSection";
|
||||
import { RoomSection } from "./objectInfo/RoomSection";
|
||||
import { ExtrudedSolidSection, ColumnSection } from "./objectInfo/SolidSections";
|
||||
import { SectionLineSection } from "./objectInfo/SectionLineSection";
|
||||
import { DetailRefSection, DimRefsSection } from "./objectInfo/RefSections";
|
||||
import { SurfacePatternPlacement } from "./SurfacePatternPlacement";
|
||||
|
||||
/** UI-Zustand des 3-Optionen-Quellen-Dropdowns (nicht 1:1 das Modell-Feld:
|
||||
|
||||
+21
-2506
File diff suppressed because it is too large.
Load diff
@@ -20,6 +20,7 @@ Kern; hier stehen Eingabe und Darstellung. Zustand über den Store (`src/state`)
|
||||
| Datei | Inhalt |
|
||||
|---|---|
|
||||
| `ToolsPanel.tsx`, `AttributesPanel.tsx`, `ObjectInfoPanel.tsx` | Werkzeug-Palette, Attribute, Objekt-Info der Auswahl (`ContextObjectProps.tsx`, `UValueRow.tsx`, `SurfacePatternPlacement.tsx` sind Teile davon) |
|
||||
| `objectInfo/*.tsx` | Abschnitte je Element-Art (`WallSection`, `CeilingSection`, `RoofSections`, `OpeningSections`, `StairSection`, `RoomSection`, `SolidSections`, `SectionLineSection`, `RefSections`, `TreeSection`), gemeinsame Felder (`fields.tsx`) und Info-Blöcke (`InfoBlocks.tsx`); `AttributesPanel` und `ObjectInfoPanel` rufen sie (`[165]`) |
|
||||
| `DrawingLevelsPanel.tsx`, `LayersPanel.tsx`, `ElementTreePanel.tsx` | Zeichnungsebenen, Ebenen, Baum Geschoss → Bauteilklasse → Element |
|
||||
| `LayoutsPanel.tsx`, `PublishSection.tsx`, `ViewSnapshotsPanel.tsx` | Layouts als Baum, Publikationssätze (`[79]`), gespeicherte Ansichten |
|
||||
| `RoomBalancePanel.tsx` | Flächenbilanz mit den Abschnitten `AreaTableSection.tsx`, `KennzahlenSection.tsx`, `ProgramCompareSection.tsx`, `ElementScheduleSection.tsx`, `OpeningScheduleSection.tsx`, `RoomBookSection.tsx`; Stempel-Editor `RoomStampEditor.tsx` |
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
// Abschnitt „Decke" der Attribute ([165] aus `ObjectInfoPanel.tsx`): Aufbau, Höhenlage, Öffnungen.
|
||||
// Gerufen von `AttributesPanel`.
|
||||
|
||||
import { useStore } from "../../state/appStore";
|
||||
import type { CeilingInfo } from "../../state/selectionInfo";
|
||||
import { usePanelHost } from "../host";
|
||||
import { t } from "../../i18n";
|
||||
import { Dropdown } from "../../ui/Dropdown";
|
||||
import { UValueRow } from "../UValueRow";
|
||||
import { formatM } from "../../model/types";
|
||||
import { BuildingFlags, DimensionField, VerticalAnchorRow } from "./fields";
|
||||
|
||||
export function CeilingSection({
|
||||
ceiling,
|
||||
host,
|
||||
}: {
|
||||
ceiling: CeilingInfo;
|
||||
host: ReturnType<typeof usePanelHost>;
|
||||
}) {
|
||||
const storeProject = useStore((st) => st.project);
|
||||
const isSingle = ceiling.singleLayer;
|
||||
const multiPresets = ceiling.ceilingTypes.filter((ct) => ct.layerCount > 1);
|
||||
|
||||
function chooseSingle() {
|
||||
if (isSingle) return;
|
||||
host.onSetCeilingThickness(ceiling.thickness);
|
||||
}
|
||||
function chooseMulti() {
|
||||
if (!isSingle) return;
|
||||
const first = multiPresets[0];
|
||||
if (first) host.onSetCeilingType(first.id);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="objinfo-sep" />
|
||||
<div className="objinfo-section-label">{t("objinfo.ceiling.section")}</div>
|
||||
<BuildingFlags isExternal={ceiling.isExternal} loadBearing={ceiling.loadBearing} host={host} />
|
||||
|
||||
{/* Aufbau-Typ-Segment. */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.ceiling.buildup")}</span>
|
||||
<div className="objinfo-segment">
|
||||
<button
|
||||
type="button"
|
||||
className={"objinfo-seg-btn" + (isSingle ? " active" : "")}
|
||||
onClick={chooseSingle}
|
||||
>
|
||||
{t("objinfo.wall.single")}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={"objinfo-seg-btn" + (!isSingle ? " active" : "")}
|
||||
onClick={chooseMulti}
|
||||
disabled={isSingle && multiPresets.length === 0}
|
||||
>
|
||||
{t("objinfo.wall.multi")}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Einschichtig → Dicke-Zahlfeld. Mehrschichtig → Preset-Dropdown. */}
|
||||
{isSingle ? (
|
||||
<DimensionField
|
||||
label={t("objinfo.ceiling.thickness")}
|
||||
value={ceiling.thickness}
|
||||
onCommit={(v) => host.onSetCeilingThickness(v)}
|
||||
/>
|
||||
) : (
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.ceiling.preset")}</span>
|
||||
<Dropdown
|
||||
value={ceiling.typeId}
|
||||
onChange={(id) => host.onSetCeilingType(id)}
|
||||
options={ceiling.ceilingTypes.map((ct) => ({
|
||||
value: ct.id,
|
||||
label: ct.label,
|
||||
title: ct.name,
|
||||
}))}
|
||||
title={t("objinfo.ceiling.preset")}
|
||||
width={150}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Referenzgeschoss (read-only Anzeige). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.ceiling.refFloor")}</span>
|
||||
<span className="objinfo-fval">{ceiling.floorName}</span>
|
||||
</div>
|
||||
<UValueRow project={storeProject} kind="ceiling" typeId={ceiling.typeId} />
|
||||
|
||||
{/* Fläche + Volumen (read-only). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.ceiling.area")}</span>
|
||||
<span className="objinfo-fval">{ceiling.area.toFixed(2)} m²</span>
|
||||
</div>
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.volume")}</span>
|
||||
<span className="objinfo-fval">{ceiling.volume.toFixed(2)} m³</span>
|
||||
</div>
|
||||
|
||||
{/* Aussparungen (Treppenauge/Schacht) — Liste mit Entfernen je Loch.
|
||||
Anlegen über den Befehl „Deckenloch" (BIM-Ribbon). */}
|
||||
{ceiling.openings.length > 0 && (
|
||||
<>
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.ceiling.openings")}</span>
|
||||
<span className="objinfo-fval">{ceiling.openings.length}</span>
|
||||
</div>
|
||||
{ceiling.openings.map((o, i) => (
|
||||
<div className="objinfo-field" key={i}>
|
||||
<span className="objinfo-flabel objinfo-muted">
|
||||
{`${i + 1}: ${o.width.toFixed(2)} × ${o.depth.toFixed(2)} m`}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
className="objinfo-typebtn"
|
||||
title={t("objinfo.ceiling.removeOpening")}
|
||||
aria-label={t("objinfo.ceiling.removeOpening")}
|
||||
onClick={() => host.onRemoveCeilingOpening(i)}
|
||||
>
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
|
||||
<div className="objinfo-sep" />
|
||||
|
||||
{/* OK der Decke: an Geschoss gebunden ODER eigene Höhe. */}
|
||||
<VerticalAnchorRow
|
||||
label={t("objinfo.ceiling.top")}
|
||||
anchor={ceiling.top}
|
||||
defaultZ={ceiling.zTop}
|
||||
floors={ceiling.floors}
|
||||
defaultFloorId={ceiling.floorId}
|
||||
onChange={(a) => host.onSetCeilingTop(a)}
|
||||
/>
|
||||
|
||||
{/* UK der Decke: an Geschoss gebunden ODER eigene Höhe; ohne Override
|
||||
bleibt es beim heutigen Verhalten UK = OK − Dicke. */}
|
||||
<VerticalAnchorRow
|
||||
label={t("objinfo.ceiling.bottom")}
|
||||
anchor={ceiling.bottom}
|
||||
defaultZ={ceiling.zBottom}
|
||||
floors={ceiling.floors}
|
||||
defaultFloorId={ceiling.floorId}
|
||||
onChange={(a) => host.onSetCeilingBottom?.(a)}
|
||||
/>
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.ceiling.height")}</span>
|
||||
<span className="objinfo-fval">{formatM(ceiling.zTop - ceiling.zBottom)}</span>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
// Kleine Info-Blöcke der Objekt-Info ([165] aus `ObjectInfoPanel.tsx`): Messwert-Anzeige und Hinweis zu den
|
||||
// Schlagschatten der Ansicht. Gerufen von `ObjectInfoPanel`.
|
||||
|
||||
import type { MeasurementReadout } from "../../tools/types";
|
||||
import { t } from "../../i18n";
|
||||
import { useStore } from "../../state/appStore";
|
||||
import { patchItem } from "../../core";
|
||||
|
||||
// ── Mess-Werkzeug-Abschnitt ───────────────────────────────────────────────────
|
||||
// Zeigt die Live-Messwerte (letztes Segment, aufsummierte Länge, umschlossene
|
||||
// Fläche, Richtung). Fläche nur, sobald der Zug ≥ 3 Ecken hat.
|
||||
export function MeasurementSection({ m }: { m: MeasurementReadout }) {
|
||||
return (
|
||||
<div className="objinfo-measure">
|
||||
<div className="objinfo-section-label">{t("objinfo.measure.title")}</div>
|
||||
<div className="objinfo-measure-grid">
|
||||
<span className="objinfo-measure-key">{t("objinfo.measure.segment")}</span>
|
||||
<span className="objinfo-measure-val">{m.segment.toFixed(3)} m</span>
|
||||
<span className="objinfo-measure-key">{t("objinfo.measure.total")}</span>
|
||||
<span className="objinfo-measure-val">{m.total.toFixed(3)} m</span>
|
||||
<span className="objinfo-measure-key">{t("objinfo.measure.angle")}</span>
|
||||
<span className="objinfo-measure-val">{m.angle.toFixed(1)}°</span>
|
||||
{m.area != null && (
|
||||
<>
|
||||
<span className="objinfo-measure-key">{t("objinfo.measure.area")}</span>
|
||||
<span className="objinfo-measure-val">{m.area.toFixed(2)} m²</span>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<div className="objinfo-measure-hint">{t("objinfo.measure.hint")}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/** [137] Schlagschatten der Ansicht angeklickt: Schalter der aktiven Ansicht (DrawingLevel.shadows, Undo). */
|
||||
export function ViewShadowsInfo() {
|
||||
const level = useStore((s) => s.project.drawingLevels.find((l) => l.id === s.activeLevelId));
|
||||
const applyChange = useStore((s) => s.applyChange);
|
||||
return (
|
||||
<div className="objinfo-panel">
|
||||
<div className="objinfo-head">
|
||||
<span className="objinfo-kind">{t("objinfo.kind.viewShadows")}</span>
|
||||
</div>
|
||||
<div className="objinfo-muted objinfo-site-hint">{t("elevation.shadows.hint")}</div>
|
||||
{level && (
|
||||
<label className="objinfo-row" style={{ display: "flex", gap: 6, alignItems: "center" }}>
|
||||
<input
|
||||
type="checkbox"
|
||||
data-testid="view-shadows"
|
||||
checked={!!level.shadows}
|
||||
onChange={(e) => applyChange((p) => patchItem(p, "drawingLevels", level.id, { shadows: e.target.checked }))}
|
||||
/>
|
||||
{t("elevation.shadows")}
|
||||
</label>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,397 @@
|
||||
// Abschnitte „Öffnung" und „Flächenöffnung" der Attribute ([165] aus `ObjectInfoPanel.tsx`) samt der
|
||||
// Linien-Übersteuerung der Öffnung. Gerufen von `AttributesPanel`.
|
||||
|
||||
import { useStore } from "../../state/appStore";
|
||||
import type { OpeningInfo } from "../../state/selectionInfo";
|
||||
import { usePanelHost } from "../host";
|
||||
import { t } from "../../i18n";
|
||||
import { Dropdown } from "../../ui/Dropdown";
|
||||
import type { DetailLevel } from "../../model/viewTypes";
|
||||
import { formatM } from "../../model/types";
|
||||
import { surfaceOpeningInfo } from "../../core";
|
||||
import { ColorHexField } from "../../ui/ColorHexField";
|
||||
import { DimensionField } from "./fields";
|
||||
|
||||
// Anzeige-Fallbacks für die Öffnungs-Linien-Übersteuerung (LineStyleRow) —
|
||||
// dieselben Werte wie POCHE_STROKE/SYMBOL_HAIRLINE_MM im Grundriss (Kern: plan/style.rs)
|
||||
// (reine UI-Default-Anzeige, kein Re-Export nötig).
|
||||
const OPENING_LINE_DEFAULT_COLOR = "#1a1a1a";
|
||||
|
||||
const OPENING_LINE_DEFAULT_WEIGHT = 0.02;
|
||||
|
||||
|
||||
// ── Öffnungs-Attribut-Abschnitt ──────────────────────────────────────────────
|
||||
// Art (Fenster/Tür), Wirts-Wand, Position/Breite/Höhe/Brüstung, bei Türen
|
||||
// zusätzlich Anschlag/Aufschlag/Richtung/Winkel; UK/OK read-only.
|
||||
export function OpeningSection({
|
||||
opening,
|
||||
host,
|
||||
}: {
|
||||
opening: OpeningInfo;
|
||||
host: ReturnType<typeof usePanelHost>;
|
||||
}) {
|
||||
const storeProject = useStore((st) => st.project);
|
||||
const isDoor = opening.kind === "door";
|
||||
if (opening.hostRoofId || opening.hostCeilingId) {
|
||||
return <SurfaceOpeningSection opening={opening} host={host} />;
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<div className="objinfo-sep" />
|
||||
<div className="objinfo-section-label">{t("objinfo.opening.section")}</div>
|
||||
|
||||
{/* Tür-/Fenstertyp (Bibliothek) — je nach Art aus doorTypes bzw. windowTypes.
|
||||
Der ⚙-Knopf öffnet den reichen Fenster-/Tür-Einstellungsdialog. */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.opening.type")}</span>
|
||||
<Dropdown
|
||||
value={opening.typeId ?? ""}
|
||||
onChange={(v) => host.onSetOpeningType(v)}
|
||||
options={[
|
||||
{ value: "", label: t("objinfo.type.none") },
|
||||
...(isDoor
|
||||
? storeProject.doorTypes ?? []
|
||||
: storeProject.windowTypes ?? []
|
||||
).map((ty) => ({ value: ty.id, label: ty.name })),
|
||||
]}
|
||||
title={t("objinfo.opening.type")}
|
||||
width={106}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
className="objinfo-typebtn"
|
||||
title={t("objinfo.opening.editType")}
|
||||
aria-label={t("objinfo.opening.editType")}
|
||||
onClick={() => host.onOpenOpeningEditor(opening.id)}
|
||||
>
|
||||
⚙
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Art (Fenster/Tür) — read-only: die Gattung wird beim Platzieren mit dem
|
||||
jeweiligen Werkzeug festgelegt und NICHT nachträglich umgeschaltet
|
||||
(ein Fenster in eine Tür zu verwandeln ergibt keinen sinnvollen Bauteil). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.opening.kind")}</span>
|
||||
<span className="objinfo-fval">
|
||||
{t(isDoor ? "objinfo.opening.kind.door" : "objinfo.opening.kind.window")}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Wirts-Wand (read-only Anzeige des Geschosses/Wand-Bezugs). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.opening.hostWall")}</span>
|
||||
<span className="objinfo-fval">{opening.hostWallName}</span>
|
||||
</div>
|
||||
|
||||
{/* Editierbare Maße. */}
|
||||
<DimensionField
|
||||
label={t("objinfo.opening.position")}
|
||||
value={opening.position}
|
||||
onCommit={(v) => host.onSetOpeningPosition(v)}
|
||||
/>
|
||||
{/* [144] Gegenstück: Abstand des zweiten Pfostens vom Wandende (nur gerade Wand). */}
|
||||
{opening.wallLength != null && (
|
||||
<DimensionField
|
||||
label={t("objinfo.opening.positionEnd")}
|
||||
value={opening.wallLength - opening.position - opening.width}
|
||||
onCommit={(v) => host.onSetOpeningPosition(opening.wallLength! - v - opening.width)}
|
||||
/>
|
||||
)}
|
||||
<DimensionField
|
||||
label={t("objinfo.opening.width")}
|
||||
value={opening.width}
|
||||
onCommit={(v) => host.onSetOpeningWidth(v)}
|
||||
/>
|
||||
<DimensionField
|
||||
label={t("objinfo.opening.height")}
|
||||
value={opening.height}
|
||||
onCommit={(v) => host.onSetOpeningHeight(v)}
|
||||
/>
|
||||
{!isDoor && (
|
||||
<>
|
||||
<DimensionField
|
||||
label={t("objinfo.opening.sill")}
|
||||
value={opening.sillHeight}
|
||||
onCommit={(v) => host.onSetOpeningSill(v)}
|
||||
/>
|
||||
{/* Fenster-spezifisch: Flügelanzahl (1–4). */}
|
||||
<DimensionField
|
||||
label={t("objinfo.opening.wingCount")}
|
||||
value={opening.wingCount ?? 1}
|
||||
min={1}
|
||||
onCommit={(v) => host.onSetOpeningWingCount(Math.max(1, Math.min(4, Math.round(v))))}
|
||||
/>
|
||||
{/* Grundriss-Linien je Kategorie: Rahmen (Blendrahmen+Stulp), Fenster
|
||||
(Flügelrahmen/Sprossen), Sims (Auf-/Untersicht, nur wenn der
|
||||
Fenstertyp sie aktiviert hat — s. WindowType.sillLine). */}
|
||||
<LineStyleRow
|
||||
label={t("objinfo.opening.frameLine")}
|
||||
value={opening.frameLine}
|
||||
fallbackColor={OPENING_LINE_DEFAULT_COLOR}
|
||||
fallbackWeight={OPENING_LINE_DEFAULT_WEIGHT}
|
||||
onChange={host.onSetOpeningFrameLine}
|
||||
/>
|
||||
<LineStyleRow
|
||||
label={t("objinfo.opening.frameViewLine")}
|
||||
value={opening.frameViewLine}
|
||||
fallbackColor={opening.frameLine?.color ?? OPENING_LINE_DEFAULT_COLOR}
|
||||
fallbackWeight={opening.frameLine?.weight ?? OPENING_LINE_DEFAULT_WEIGHT}
|
||||
onChange={host.onSetOpeningFrameViewLine}
|
||||
/>
|
||||
<LineStyleRow
|
||||
label={t("objinfo.opening.sashLine")}
|
||||
value={opening.sashLine}
|
||||
fallbackColor={OPENING_LINE_DEFAULT_COLOR}
|
||||
fallbackWeight={OPENING_LINE_DEFAULT_WEIGHT}
|
||||
onChange={host.onSetOpeningSashLine}
|
||||
/>
|
||||
<LineStyleRow
|
||||
label={t("objinfo.opening.sillLine")}
|
||||
value={opening.sillLineStyle}
|
||||
fallbackColor={OPENING_LINE_DEFAULT_COLOR}
|
||||
fallbackWeight={OPENING_LINE_DEFAULT_WEIGHT}
|
||||
onChange={host.onSetOpeningSillLineStyle}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Tür-spezifisch: Typ / Sturzlinien / Anschlag / Aufschlagseite / Richtung / Winkel. */}
|
||||
{isDoor && (
|
||||
<>
|
||||
{/* Tür-Typ (normal / Wandöffnung). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.opening.doorType")}</span>
|
||||
<Dropdown
|
||||
value={opening.doorType ?? "normal"}
|
||||
onChange={(v) => host.onSetOpeningDoorType(v as "normal" | "wandoeffnung")}
|
||||
options={[
|
||||
{ value: "normal", label: t("objinfo.opening.doorType.normal") },
|
||||
{ value: "wandoeffnung", label: t("objinfo.opening.doorType.wandoeffnung") },
|
||||
]}
|
||||
title={t("objinfo.opening.doorType")}
|
||||
width={130}
|
||||
/>
|
||||
</div>
|
||||
{/* Sturzlinien-Darstellung (keine/innen/aussen/beide). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.opening.lintelLines")}</span>
|
||||
<Dropdown
|
||||
value={opening.lintelLines ?? "beide"}
|
||||
onChange={(v) => host.onSetOpeningLintelLines(v as "keine" | "innen" | "aussen" | "beide")}
|
||||
options={[
|
||||
{ value: "keine", label: t("objinfo.opening.lintelLines.keine") },
|
||||
{ value: "innen", label: t("objinfo.opening.lintelLines.innen") },
|
||||
{ value: "aussen", label: t("objinfo.opening.lintelLines.aussen") },
|
||||
{ value: "beide", label: t("objinfo.opening.lintelLines.beide") },
|
||||
]}
|
||||
title={t("objinfo.opening.lintelLines")}
|
||||
width={130}
|
||||
/>
|
||||
</div>
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.opening.hinge")}</span>
|
||||
<Dropdown
|
||||
value={opening.hinge ?? "start"}
|
||||
onChange={(v) => host.onSetOpeningHinge(v as "start" | "end")}
|
||||
options={[
|
||||
{ value: "start", label: t("objinfo.opening.hinge.start") },
|
||||
{ value: "end", label: t("objinfo.opening.hinge.end") },
|
||||
]}
|
||||
title={t("objinfo.opening.hinge")}
|
||||
width={130}
|
||||
/>
|
||||
</div>
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.opening.swing")}</span>
|
||||
<Dropdown
|
||||
value={opening.swing ?? "left"}
|
||||
onChange={(v) => host.onSetOpeningSwing(v as "left" | "right")}
|
||||
options={[
|
||||
{ value: "left", label: t("objinfo.opening.swing.left") },
|
||||
{ value: "right", label: t("objinfo.opening.swing.right") },
|
||||
]}
|
||||
title={t("objinfo.opening.swing")}
|
||||
width={130}
|
||||
/>
|
||||
</div>
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.opening.dir")}</span>
|
||||
<Dropdown
|
||||
value={opening.openingDir ?? "in"}
|
||||
onChange={(v) => host.onSetOpeningDir(v as "in" | "out")}
|
||||
options={[
|
||||
{ value: "in", label: t("objinfo.opening.dir.in") },
|
||||
{ value: "out", label: t("objinfo.opening.dir.out") },
|
||||
]}
|
||||
title={t("objinfo.opening.dir")}
|
||||
width={130}
|
||||
/>
|
||||
</div>
|
||||
<DimensionField
|
||||
label={t("objinfo.opening.swingAngle")}
|
||||
value={opening.swingAngle ?? 90}
|
||||
min={1}
|
||||
onCommit={(v) => host.onSetOpeningSwingAngle(v)}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Detailstufe-Übersteuerung — fehlt sie ("" = Ansicht), gilt die
|
||||
ansichtsweite Detailstufe (Grundriss-Kopfzeile). Wirkt auf dasselbe
|
||||
grob/mittel/fein-Symbol wie die Ansichts-Detailstufe (Türblatt-Bogen,
|
||||
Rahmen/Glaslinien), nur PRO ELEMENT statt für den ganzen Plan. */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.opening.detailLevel")}</span>
|
||||
<Dropdown
|
||||
value={opening.detailLevel ?? ""}
|
||||
onChange={(v) =>
|
||||
host.onSetOpeningDetailLevel(v === "" ? undefined : (v as DetailLevel))
|
||||
}
|
||||
options={[
|
||||
{ value: "", label: t("objinfo.detailLevel.view") },
|
||||
{ value: "grob", label: t("topbar.detail.grob") },
|
||||
{ value: "mittel", label: t("topbar.detail.mittel") },
|
||||
{ value: "fein", label: t("topbar.detail.fein") },
|
||||
]}
|
||||
title={t("objinfo.opening.detailLevel")}
|
||||
width={130}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="objinfo-sep" />
|
||||
|
||||
{/* UK/OK (read-only, aus der Wand-UK + Brüstung/Höhe abgeleitet). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.opening.bottom")}</span>
|
||||
<span className="objinfo-fval">{formatM(opening.zBottom)}</span>
|
||||
</div>
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.opening.top")}</span>
|
||||
<span className="objinfo-fval">{formatM(opening.zTop)}</span>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// ── Dach-/Deckenfenster ([103]) ─────────────────────────────────────────────
|
||||
// Wirt (Dach/Decke + Geschoss), Breite quer und Höhe im Gefälle (in der Fläche gemessen), Lage des
|
||||
// Mittelpunkts im Grundriss, Drehung nur auf waagrechten Flächen; UK/OK und Neigung aus dem Kern.
|
||||
function SurfaceOpeningSection({
|
||||
opening,
|
||||
host,
|
||||
}: {
|
||||
opening: OpeningInfo;
|
||||
host: ReturnType<typeof usePanelHost>;
|
||||
}) {
|
||||
const storeProject = useStore((st) => st.project);
|
||||
const info = surfaceOpeningInfo(storeProject, opening.id);
|
||||
const roof = !!opening.hostRoofId;
|
||||
const hp = opening.hostPoint ?? { x: 0, y: 0 };
|
||||
return (
|
||||
<>
|
||||
<div className="objinfo-sep" />
|
||||
<div className="objinfo-section-label">{t("objinfo.opening.section")}</div>
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.opening.type")}</span>
|
||||
<Dropdown
|
||||
value={opening.typeId ?? ""}
|
||||
onChange={(v) => host.onSetOpeningType(v)}
|
||||
options={[
|
||||
{ value: "", label: t("objinfo.type.none") },
|
||||
...(storeProject.windowTypes ?? []).map((ty) => ({ value: ty.id, label: ty.name })),
|
||||
]}
|
||||
title={t("objinfo.opening.type")}
|
||||
width={106}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
className="objinfo-typebtn"
|
||||
title={t("objinfo.opening.editType")}
|
||||
aria-label={t("objinfo.opening.editType")}
|
||||
onClick={() => host.onOpenOpeningEditor(opening.id)}
|
||||
>
|
||||
⚙
|
||||
</button>
|
||||
</div>
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t(roof ? "objinfo.opening.hostRoof" : "objinfo.opening.hostCeiling")}</span>
|
||||
<span className="objinfo-fval">{info?.hostName ?? "–"}</span>
|
||||
</div>
|
||||
<DimensionField label={t("objinfo.opening.surfaceWidth")} value={opening.width} onCommit={(v) => host.onSetOpeningWidth(v)} />
|
||||
<DimensionField label={t("objinfo.opening.surfaceHeight")} value={opening.height} onCommit={(v) => host.onSetOpeningHeight(v)} />
|
||||
<DimensionField label={t("objinfo.opening.hostX")} value={hp.x} min={-1e9} onCommit={(x) => host.onSetOpeningHost?.({ hostPoint: { x, y: hp.y } })} />
|
||||
<DimensionField label={t("objinfo.opening.hostY")} value={hp.y} min={-1e9} onCommit={(y) => host.onSetOpeningHost?.({ hostPoint: { x: hp.x, y } })} />
|
||||
{!roof && (
|
||||
<DimensionField
|
||||
label={t("objinfo.opening.hostAngle")}
|
||||
value={opening.hostAngle ?? 0}
|
||||
min={-360}
|
||||
unit="°"
|
||||
step={1}
|
||||
digits={1}
|
||||
onCommit={(a) => host.onSetOpeningHost?.({ hostAngle: a })}
|
||||
/>
|
||||
)}
|
||||
{info && (
|
||||
<>
|
||||
<div className="objinfo-sep" />
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.opening.slope")}</span>
|
||||
<span className="objinfo-fval">{info.slopeDeg.toFixed(1)}°</span>
|
||||
</div>
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.opening.bottom")}</span>
|
||||
<span className="objinfo-fval">{formatM(info.zBottom)}</span>
|
||||
</div>
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.opening.top")}</span>
|
||||
<span className="objinfo-fval">{formatM(info.zTop)}</span>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/** Farbe + Strichstärke (mm) einer Linien-Kategorie, mit "System"-Fallback-
|
||||
* Anzeige (Override `undefined` ⇒ zeigt `fallbackColor`/`fallbackWeight`,
|
||||
* Ändern setzt sofort einen expliziten Override). */
|
||||
function LineStyleRow({
|
||||
label,
|
||||
value,
|
||||
fallbackColor,
|
||||
fallbackWeight,
|
||||
onChange,
|
||||
}: {
|
||||
label: string;
|
||||
value: { color?: string; weight?: number } | undefined;
|
||||
fallbackColor: string;
|
||||
fallbackWeight: number;
|
||||
onChange: (v: { color?: string; weight?: number } | undefined) => void;
|
||||
}) {
|
||||
return (
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{label}</span>
|
||||
<ColorHexField
|
||||
value={value?.color ?? fallbackColor}
|
||||
onChange={(color) => onChange({ ...value, color })}
|
||||
/>
|
||||
<input
|
||||
className="objinfo-input objinfo-input-narrow"
|
||||
type="number"
|
||||
step={0.01}
|
||||
min={0}
|
||||
value={(value?.weight ?? fallbackWeight).toFixed(2)}
|
||||
onChange={(e) => {
|
||||
const w = Number(e.target.value);
|
||||
if (isFinite(w) && w >= 0) onChange({ ...value, weight: w });
|
||||
}}
|
||||
title={t("objinfo.lineWeight")}
|
||||
/>
|
||||
<span className="objinfo-unit">mm</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
// Abschnitte für Bemassungs-Bezüge und Detail-Verweise der Attribute ([165] aus `ObjectInfoPanel.tsx`).
|
||||
// Gerufen von `AttributesPanel`.
|
||||
|
||||
import type { DimRef } from "../../model/types";
|
||||
import { usePanelHost } from "../host";
|
||||
import { t } from "../../i18n";
|
||||
import type { TranslationKey } from "../../i18n";
|
||||
import type { DetailRefInfo } from "../../state/selectionInfo";
|
||||
import { Dropdown } from "../../ui/Dropdown";
|
||||
|
||||
// ── Assoziative Bemassung ([38]) ────────────────────────────────────────────
|
||||
// Je Punkt: frei, angehängt (Merkmal + Element) oder Bezug verloren; „Bemassung lösen" entfernt alle.
|
||||
export function DimRefsSection({
|
||||
refs,
|
||||
drawingId,
|
||||
host,
|
||||
}: {
|
||||
refs: (DimRef | null)[];
|
||||
drawingId: string;
|
||||
host: ReturnType<typeof usePanelHost>;
|
||||
}) {
|
||||
const lost = refs.some((r) => r?.lost);
|
||||
return (
|
||||
<>
|
||||
<div className="objinfo-sep" />
|
||||
<div className="objinfo-section-label">{t("objinfo.dimRefs.section")}</div>
|
||||
{refs.map((r, i) => (
|
||||
<div className="objinfo-field" key={i} data-testid="dim-ref">
|
||||
<span className="objinfo-flabel">{t("objinfo.dimRefs.point", { n: i + 1 })}</span>
|
||||
<span className="objinfo-fval">
|
||||
{!r
|
||||
? t("objinfo.dimRefs.free")
|
||||
: r.lost
|
||||
? t("objinfo.dimRefs.lost", { id: r.id })
|
||||
: `${t(`objinfo.dimRefs.feature.${r.feature}` as TranslationKey)} · ${r.id}${r.id2 ? ` / ${r.id2}` : ""}`}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
{lost && <div className="objinfo-measure-hint">{t("objinfo.dimRefs.lostHint")}</div>}
|
||||
<div className="objinfo-field">
|
||||
<button type="button" className="objinfo-btn" onClick={() => host.onDetachDimension(drawingId)}>
|
||||
{t("cmd.dimdetach.label")}
|
||||
</button>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// ── Detail-/Schnitt-Verweis-Attribut-Abschnitt ──────────────────────────────
|
||||
// Bezeichner (obere Zeile) + Blattverknüpfung (Dropdown der Project.layouts,
|
||||
// „kein Verweis" löst sie); ohne Verknüpfung zusätzlich ein manueller
|
||||
// Blattname-Platzhalter (untere Zeile, s. `DetailRefInfo`-Kommentar).
|
||||
export function DetailRefSection({
|
||||
detailRef,
|
||||
drawingId,
|
||||
host,
|
||||
}: {
|
||||
detailRef: DetailRefInfo;
|
||||
drawingId: string;
|
||||
host: ReturnType<typeof usePanelHost>;
|
||||
}) {
|
||||
return (
|
||||
<>
|
||||
<div className="objinfo-sep" />
|
||||
<div className="objinfo-section-label">{t("objinfo.detailRef.section")}</div>
|
||||
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.detailRef.label")}</span>
|
||||
<input
|
||||
type="text"
|
||||
className="objinfo-text"
|
||||
value={detailRef.label}
|
||||
onChange={(e) => host.onSetDetailRefLabel(drawingId, e.target.value)}
|
||||
title={t("objinfo.detailRef.label")}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.detailRef.sheet")}</span>
|
||||
<Dropdown
|
||||
value={detailRef.sheetLayoutId ?? ""}
|
||||
onChange={(v) => host.onSetDetailRefSheetLayout(drawingId, v === "" ? undefined : v)}
|
||||
options={[
|
||||
{ value: "", label: t("objinfo.detailRef.sheet.none") },
|
||||
...detailRef.availableLayouts.map((l) => ({ value: l.id, label: l.name })),
|
||||
]}
|
||||
title={t("objinfo.detailRef.sheet")}
|
||||
width={130}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{!detailRef.sheetLayoutId && (
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.detailRef.sheetLabel")}</span>
|
||||
<input
|
||||
type="text"
|
||||
className="objinfo-text"
|
||||
value={detailRef.sheetLabel ?? ""}
|
||||
placeholder={t("objinfo.detailRef.sheetLabel.hint")}
|
||||
onChange={(e) => host.onSetDetailRefSheetLabel(drawingId, e.target.value)}
|
||||
title={t("objinfo.detailRef.sheetLabel")}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,430 @@
|
||||
// Abschnitte „Dach" der Attribute ([165] aus `ObjectInfoPanel.tsx`): Dachform, Gauben und Dachränder.
|
||||
// Gerufen von `AttributesPanel`.
|
||||
|
||||
import { useStore } from "../../state/appStore";
|
||||
import type { RoofInfo } from "../../state/selectionInfo";
|
||||
import { usePanelHost } from "../host";
|
||||
import { useMemo } from "react";
|
||||
import { dormerStatus } from "../../analysis/dormerStatus";
|
||||
import type { Dormer, DormerKind, RoofShape } from "../../model/types";
|
||||
import type { TranslationKey } from "../../i18n";
|
||||
import { t } from "../../i18n";
|
||||
import { Dropdown } from "../../ui/Dropdown";
|
||||
import { UValueRow } from "../UValueRow";
|
||||
import { formatM } from "../../model/types";
|
||||
import type { RoofEdge, EdgeSpec } from "../../core";
|
||||
|
||||
// ── Treppen-Attribut-Abschnitt ───────────────────────────────────────────────
|
||||
// Grundform (gerade/L/Wendel), Laufbreite, Stufenanzahl, Steighöhe (+ abgeleitete
|
||||
// Steigungshöhe/Auftrittstiefe), Laufrichtung; Referenzgeschoss + UK/OK read-only.
|
||||
/** Rechteck-Umriss (CCW) aus unterer/linker Ecke + Breite/Tiefe (für Dach-Resize). */
|
||||
function rectOutline(x0: number, y0: number, w: number, d: number) {
|
||||
return [
|
||||
{ x: x0, y: y0 },
|
||||
{ x: x0 + w, y: y0 },
|
||||
{ x: x0 + w, y: y0 + d },
|
||||
{ x: x0, y: y0 + d },
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/** Gauben ([G5]) des Dachs: Art, Masse, Neigung, Aufbau je Gaube; Hinzufügen über den Befehl „Gaube". */
|
||||
function DormersSection({ roof, host }: { roof: RoofInfo; host: ReturnType<typeof usePanelHost> }) {
|
||||
const storeProject = useStore((st) => st.project);
|
||||
const dormers = roof.dormers ?? [];
|
||||
const status = useMemo(() => dormerStatus(storeProject), [storeProject]);
|
||||
const patch = (i: number, p: Partial<Dormer>) =>
|
||||
host.onSetRoofPatch({ dormers: dormers.map((d, k) => (k === i ? { ...d, ...p } : d)) }, `dormer-${i}`);
|
||||
const num = (labelKey: TranslationKey, value: number, step: number, apply: (v: number) => void) => (
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t(labelKey)}</span>
|
||||
<input
|
||||
type="number"
|
||||
className="objinfo-text"
|
||||
step={step}
|
||||
value={Number(value.toFixed(2))}
|
||||
onChange={(e) => {
|
||||
const v = Number(e.target.value);
|
||||
if (Number.isFinite(v)) apply(v);
|
||||
}}
|
||||
title={t(labelKey)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
return (
|
||||
<>
|
||||
<div className="objinfo-sep" />
|
||||
<div className="objinfo-section-label">{t("objinfo.dormer.section")}</div>
|
||||
{dormers.map((d, i) => (
|
||||
<div key={d.id} data-testid="objinfo-dormer">
|
||||
{(() => {
|
||||
const st = status.find((s) => s.dormerId === d.id);
|
||||
if (!st || !(st.clamped || st.invalid)) return null;
|
||||
return (
|
||||
<div className="objinfo-warn" role="alert" data-testid="objinfo-dormer-warning">
|
||||
{st.invalid ? t("objinfo.dormer.invalid") : t("objinfo.dormer.clamped", { height: st.effectiveHeight.toFixed(2) })}
|
||||
</div>
|
||||
);
|
||||
})()}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.dormer.kind")}</span>
|
||||
<Dropdown
|
||||
value={d.kind}
|
||||
onChange={(v) => patch(i, { kind: v as DormerKind })}
|
||||
options={[
|
||||
{ value: "schlepp", label: t("objinfo.dormer.kind.schlepp") },
|
||||
{ value: "sattel", label: t("objinfo.dormer.kind.sattel") },
|
||||
{ value: "flach", label: t("objinfo.dormer.kind.flach") },
|
||||
{ value: "walm", label: t("objinfo.dormer.kind.walm") },
|
||||
]}
|
||||
title={t("objinfo.dormer.kind")}
|
||||
width={130}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
className="objinfo-typebtn"
|
||||
title={t("objinfo.dormer.remove")}
|
||||
aria-label={t("objinfo.dormer.remove")}
|
||||
onClick={() => host.onSetRoofPatch({ dormers: dormers.filter((_, k) => k !== i) })}
|
||||
>
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
{num("objinfo.dormer.width", d.width, 0.1, (v) => patch(i, { width: Math.max(0.8, v) }))}
|
||||
{num("objinfo.dormer.frontHeight", d.frontHeight, 0.05, (v) => patch(i, { frontHeight: Math.max(0.5, v) }))}
|
||||
{d.kind !== "flach" &&
|
||||
num("objinfo.dormer.pitch", d.pitchDeg ?? (d.kind === "schlepp" ? 15 : 40), 1, (v) =>
|
||||
patch(i, { pitchDeg: Math.max(0, Math.min(75, v)), depth: undefined }),
|
||||
)}
|
||||
{d.kind === "schlepp" &&
|
||||
num("objinfo.dormer.depth", d.depth ?? 0, 0.1, (v) => patch(i, { depth: v > 0.1 ? v : undefined }))}
|
||||
{num("objinfo.dormer.overhang", d.overhang ?? 0.15, 0.05, (v) => patch(i, { overhang: Math.max(0, v) }))}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.dormer.wallType")}</span>
|
||||
<Dropdown
|
||||
value={d.wallTypeId ?? ""}
|
||||
onChange={(v) => patch(i, { wallTypeId: v || undefined })}
|
||||
options={[
|
||||
{ value: "", label: t("objinfo.dormer.wallType.default") },
|
||||
...storeProject.wallTypes.map((wt) => ({ value: wt.id, label: wt.name })),
|
||||
]}
|
||||
title={t("objinfo.dormer.wallType")}
|
||||
width={130}
|
||||
/>
|
||||
</div>
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.dormer.roofType")}</span>
|
||||
<Dropdown
|
||||
value={d.roofTypeId ?? ""}
|
||||
onChange={(v) => patch(i, { roofTypeId: v || undefined })}
|
||||
options={[
|
||||
{ value: "", label: t("objinfo.dormer.roofType.host") },
|
||||
...(storeProject.roofTypes ?? []).map((rt) => ({ value: rt.id, label: rt.name })),
|
||||
]}
|
||||
title={t("objinfo.dormer.roofType")}
|
||||
width={130}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
<div className="objinfo-field">
|
||||
<button type="button" className="objinfo-typebtn" title={t("objinfo.dormer.add")} onClick={() => host.onRunCommand("dormer")}>
|
||||
{t("objinfo.dormer.addBtn")}
|
||||
</button>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/** Dach-Abschnitt: Form, Neigung(en), Überstand, Firstrichtung, Dicke. */
|
||||
export function RoofSection({
|
||||
roof,
|
||||
host,
|
||||
}: {
|
||||
roof: RoofInfo;
|
||||
host: ReturnType<typeof usePanelHost>;
|
||||
}) {
|
||||
const storeProject = useStore((st) => st.project);
|
||||
const numField = (
|
||||
labelKey: TranslationKey,
|
||||
value: number,
|
||||
step: number,
|
||||
apply: (v: number) => void,
|
||||
) => (
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t(labelKey)}</span>
|
||||
<input
|
||||
type="number"
|
||||
className="objinfo-text"
|
||||
step={step}
|
||||
value={Number(value.toFixed(2))}
|
||||
onChange={(e) => {
|
||||
const v = Number(e.target.value);
|
||||
if (Number.isFinite(v)) apply(v);
|
||||
}}
|
||||
title={t(labelKey)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
return (
|
||||
<>
|
||||
<div className="objinfo-sep" />
|
||||
<div className="objinfo-section-label">{t("objinfo.roof.section")}</div>
|
||||
|
||||
{/* Dachform. */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.roof.shape")}</span>
|
||||
<Dropdown
|
||||
value={roof.shape}
|
||||
onChange={(v) => host.onSetRoofPatch({ shape: v as RoofShape })}
|
||||
options={[
|
||||
{ value: "flach", label: t("objinfo.roof.shape.flach") },
|
||||
{ value: "pult", label: t("objinfo.roof.shape.pult") },
|
||||
{ value: "sattel", label: t("objinfo.roof.shape.sattel") },
|
||||
{ value: "walm", label: t("objinfo.roof.shape.walm") },
|
||||
{ value: "mansarde", label: t("objinfo.roof.shape.mansarde") },
|
||||
{ value: "zelt", label: t("objinfo.roof.shape.zelt") },
|
||||
]}
|
||||
title={t("objinfo.roof.shape")}
|
||||
width={130}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Dachtyp (mehrschichtiger Aufbau) — leer = einschichtig (Dicke unten). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.roof.type")}</span>
|
||||
<Dropdown
|
||||
value={roof.roofTypeId ?? ""}
|
||||
onChange={(v) => host.onSetRoofPatch({ roofTypeId: v || undefined })}
|
||||
options={[
|
||||
{ value: "", label: t("objinfo.roof.type.single") },
|
||||
...(storeProject.roofTypes ?? []).map((rt) => ({ value: rt.id, label: rt.name })),
|
||||
]}
|
||||
title={t("objinfo.roof.type")}
|
||||
width={130}
|
||||
/>
|
||||
</div>
|
||||
<UValueRow project={storeProject} kind="roof" typeId={roof.roofTypeId} />
|
||||
|
||||
{/* Firstrichtung (X/Y) — nur bei Formen mit First relevant. */}
|
||||
{roof.shape !== "flach" && roof.shape !== "zelt" && (
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.roof.ridgeAxis")}</span>
|
||||
<Dropdown
|
||||
value={roof.ridgeAxis}
|
||||
onChange={(v) => host.onSetRoofPatch({ ridgeAxis: v as "x" | "y" })}
|
||||
options={[
|
||||
{ value: "x", label: t("objinfo.roof.ridgeAxis.x") },
|
||||
{ value: "y", label: t("objinfo.roof.ridgeAxis.y") },
|
||||
]}
|
||||
title={t("objinfo.roof.ridgeAxis")}
|
||||
width={130}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Neigung(en) — Flachdach hat keine. */}
|
||||
{roof.shape !== "flach" &&
|
||||
numField("objinfo.roof.pitch", roof.pitchDeg, 1, (v) =>
|
||||
host.onSetRoofPatch({ pitchDeg: Math.max(0, Math.min(85, v)) }),
|
||||
)}
|
||||
{roof.shape === "mansarde" &&
|
||||
numField("objinfo.roof.pitchUpper", roof.pitchUpperDeg ?? roof.pitchDeg / 2, 1, (v) =>
|
||||
host.onSetRoofPatch({ pitchUpperDeg: Math.max(0, Math.min(85, v)) }),
|
||||
)}
|
||||
{/* Mansarde-Untertyp (Giebel/Walm/Zelt) + Knicklage. */}
|
||||
{roof.shape === "mansarde" && (
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.roof.mansardType")}</span>
|
||||
<Dropdown
|
||||
value={roof.mansardType ?? "giebel"}
|
||||
onChange={(v) =>
|
||||
host.onSetRoofPatch({ mansardType: v as "giebel" | "walm" | "zelt" })
|
||||
}
|
||||
options={[
|
||||
{ value: "giebel", label: t("objinfo.roof.mansard.giebel") },
|
||||
{ value: "walm", label: t("objinfo.roof.mansard.walm") },
|
||||
{ value: "zelt", label: t("objinfo.roof.mansard.zelt") },
|
||||
]}
|
||||
title={t("objinfo.roof.mansardType")}
|
||||
width={130}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{roof.shape === "mansarde" &&
|
||||
numField("objinfo.roof.mansardKnee", (roof.mansardKneeRatio ?? 0.4) * 100, 1, (v) =>
|
||||
host.onSetRoofPatch({ mansardKneeRatio: Math.max(5, Math.min(49, v)) / 100 }),
|
||||
)}
|
||||
|
||||
{roof.shape === "sattel" &&
|
||||
numField("objinfo.roof.halfHip", (roof.halfHipRatio ?? 0) * 100, 5, (v) =>
|
||||
host.onSetRoofPatch({ halfHipRatio: Math.max(0, Math.min(90, v)) / 100 }),
|
||||
)}
|
||||
|
||||
{/* Grundriss-Masse (Breite/Tiefe): das Umriss-Rechteck neu bilden, die
|
||||
untere/linke Ecke (minX/minY) bleibt fix. */}
|
||||
{/* Mit Innenhöfen oder Kanten ausserhalb eines Vierecks würde das Rechteck die Höfe/Kantenneigungen
|
||||
zerstören — dort entfallen Breite/Tiefe. */}
|
||||
{roof.holes.length === 0 &&
|
||||
roof.edges.length === 4 &&
|
||||
numField("objinfo.roof.width", roof.width, 0.1, (v) => {
|
||||
const w = Math.max(0.2, v);
|
||||
host.onSetRoofPatch({
|
||||
outline: rectOutline(roof.minX, roof.minY, w, roof.depth),
|
||||
});
|
||||
})}
|
||||
{roof.holes.length === 0 &&
|
||||
roof.edges.length === 4 &&
|
||||
numField("objinfo.roof.depth", roof.depth, 0.1, (v) => {
|
||||
const d = Math.max(0.2, v);
|
||||
host.onSetRoofPatch({
|
||||
outline: rectOutline(roof.minX, roof.minY, roof.width, d),
|
||||
});
|
||||
})}
|
||||
|
||||
{/* Überstand: Traufe (senkrecht zum First) + Ortgang (Giebelseite). */}
|
||||
{numField("objinfo.roof.overhang", roof.overhang, 0.05, (v) =>
|
||||
host.onSetRoofPatch({ overhang: Math.max(0, v) }),
|
||||
)}
|
||||
{roof.shape !== "flach" &&
|
||||
roof.shape !== "zelt" &&
|
||||
numField(
|
||||
"objinfo.roof.overhangGable",
|
||||
roof.overhangGable ?? roof.overhang,
|
||||
0.05,
|
||||
(v) => host.onSetRoofPatch({ overhangGable: Math.max(0, v) }),
|
||||
)}
|
||||
{numField("objinfo.roof.thickness", roof.thickness, 0.02, (v) =>
|
||||
host.onSetRoofPatch({ thickness: Math.max(0.01, v) }),
|
||||
)}
|
||||
{/* Traufhöhe (absolutes Z) — z. B. für einen Kniestock übers Geschoss anheben. */}
|
||||
{numField("objinfo.roof.baseElevation", roof.baseElevation, 0.1, (v) =>
|
||||
host.onSetRoofPatch({ baseElevation: v }),
|
||||
)}
|
||||
|
||||
{/* Kanten: Neigung je Kante (leer = Standard) und Giebel ([26]). Wirkt bei Sattel/Walm/
|
||||
Mansarde/Zelt; Flach und Pult ignorieren sie. */}
|
||||
{roof.shape !== "flach" && roof.shape !== "pult" && (
|
||||
<RoofEdgesSection roof={roof} host={host} />
|
||||
)}
|
||||
{/* Innenhöfe: Liste mit Entfernen, Hinzufügen über den Befehl „Dachhof“. */}
|
||||
<DormersSection roof={roof} host={host} />
|
||||
{roof.shape !== "pult" && (
|
||||
<>
|
||||
<div className="objinfo-sep" />
|
||||
<div className="objinfo-section-label">{t("objinfo.roof.courts")}</div>
|
||||
{roof.holes.map((h, i) => (
|
||||
<div className="objinfo-field" key={i}>
|
||||
<span className="objinfo-flabel objinfo-muted">
|
||||
{t("objinfo.roof.courtRow", { n: i + 1, area: h.area.toFixed(2) })}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
className="objinfo-typebtn"
|
||||
title={t("objinfo.roof.courtRemove")}
|
||||
aria-label={t("objinfo.roof.courtRemove")}
|
||||
onClick={() => host.onRemoveRoofHole(i)}
|
||||
>
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
<div className="objinfo-field">
|
||||
<button
|
||||
type="button"
|
||||
className="objinfo-typebtn"
|
||||
title={t("objinfo.roof.courtAdd")}
|
||||
onClick={() => host.onRunCommand("roofhole")}
|
||||
>
|
||||
{t("objinfo.roof.courtAddBtn")}
|
||||
</button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
<div className="objinfo-sep" />
|
||||
|
||||
{/* Abgeleitete Werte (read-only). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.roof.ridgeHeight")}</span>
|
||||
<span className="objinfo-fval">{formatM(roof.ridgeHeight)}</span>
|
||||
</div>
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.roof.area")}</span>
|
||||
<span className="objinfo-fval">{roof.footprintArea.toFixed(2)} m²</span>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/** Kantenliste eines Dachs: Neigung je Kante (leer = Standard) + Giebel-Schalter. */
|
||||
function RoofEdgesSection({
|
||||
roof,
|
||||
host,
|
||||
}: {
|
||||
roof: RoofInfo;
|
||||
host: ReturnType<typeof usePanelHost>;
|
||||
}) {
|
||||
// Tippen einer Zahl = ein Undo-Schritt je Kante (gleicher coalesceKey, s. Host).
|
||||
const setEdge = (e: RoofEdge, spec: EdgeSpec) => host.onSetRoofEdge(e.index, spec);
|
||||
return (
|
||||
<>
|
||||
<div className="objinfo-sep" />
|
||||
<div className="objinfo-section-label">{t("objinfo.roof.edges")}</div>
|
||||
{roof.edges.map((e) => {
|
||||
const label =
|
||||
e.ring === 0
|
||||
? t("objinfo.roof.edge", { n: e.edge + 1 })
|
||||
: t("objinfo.roof.edgeCourt", { c: e.ring, n: e.edge + 1 });
|
||||
const gable = e.spec.kind === "gable";
|
||||
const placeholder = e.defaultGable ? t("objinfo.roof.edgeGable") : String(roof.pitchDeg);
|
||||
return (
|
||||
<div className="objinfo-field objinfo-roof-edge" key={e.index} data-edge={e.index}>
|
||||
<span className="objinfo-flabel" title={`${e.length.toFixed(2)} m`}>
|
||||
{label}
|
||||
</span>
|
||||
<input
|
||||
type="number"
|
||||
className="objinfo-text"
|
||||
min={0}
|
||||
max={89}
|
||||
step={1}
|
||||
disabled={gable}
|
||||
placeholder={placeholder}
|
||||
value={e.spec.kind === "pitch" ? Number(e.spec.deg.toFixed(2)) : ""}
|
||||
aria-label={`${label}: ${t("objinfo.roof.edgePitch")}`}
|
||||
title={t("objinfo.roof.edgePitch")}
|
||||
onChange={(ev) => {
|
||||
const raw = ev.target.value;
|
||||
if (raw === "") return setEdge(e, { kind: "default" });
|
||||
const v = Number(raw);
|
||||
if (Number.isFinite(v)) setEdge(e, { kind: "pitch", deg: v });
|
||||
}}
|
||||
/>
|
||||
<label className="objinfo-muted" title={t("objinfo.roof.edgeGableHint")}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={gable}
|
||||
aria-label={`${label}: ${t("objinfo.roof.edgeGable")}`}
|
||||
onChange={(ev) => setEdge(e, ev.target.checked ? { kind: "gable" } : { kind: "default" })}
|
||||
/>
|
||||
{t("objinfo.roof.edgeGable")}
|
||||
</label>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
{roof.hasEdgePitch && (
|
||||
<div className="objinfo-field">
|
||||
<button
|
||||
type="button"
|
||||
className="objinfo-typebtn"
|
||||
onClick={() => host.onSetRoofPatch({ edgePitchDeg: undefined })}
|
||||
>
|
||||
{t("objinfo.roof.edgesReset")}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
// Abschnitt „Raum" der Attribute ([165] aus `ObjectInfoPanel.tsx`): Name, Nutzung, SIA-Kategorie, Fläche,
|
||||
// Stempel und die Oberflächen-Felder. Gerufen von `AttributesPanel`.
|
||||
|
||||
import type { RoomInfo } from "../../state/selectionInfo";
|
||||
import { usePanelHost } from "../host";
|
||||
import { t } from "../../i18n";
|
||||
import { Dropdown } from "../../ui/Dropdown";
|
||||
import type { SiaCategory, Project, Room } from "../../model/types";
|
||||
import { SIA_CATEGORIES, siaLabelFull, patchItem, roomBook, ROOM_USAGES, usageLabel } from "../../core";
|
||||
import { formatM } from "../../model/types";
|
||||
import { useStore } from "../../state/appStore";
|
||||
import type { TranslationKey } from "../../i18n";
|
||||
|
||||
// ── Raum-Attribut-Abschnitt ──────────────────────────────────────────────────
|
||||
// Editierbarer Name, SIA-416-Kategorie (5 Blatt-Kategorien), abgeleitete Fläche
|
||||
// + Umfang (read-only), Referenzgeschoss, sowie ein Button, der den Rich-Text-
|
||||
// Stempel-Editor öffnet. Alle Werte/Setter über den Host.
|
||||
export function RoomSection({
|
||||
room,
|
||||
roomId,
|
||||
host,
|
||||
}: {
|
||||
room: RoomInfo;
|
||||
roomId: string;
|
||||
host: ReturnType<typeof usePanelHost>;
|
||||
}) {
|
||||
return (
|
||||
<>
|
||||
<div className="objinfo-sep" />
|
||||
<div className="objinfo-section-label">{t("objinfo.room.section")}</div>
|
||||
|
||||
{/* Name (editierbar). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.room.name")}</span>
|
||||
<input
|
||||
type="text"
|
||||
className="objinfo-text"
|
||||
value={room.name}
|
||||
onChange={(e) => host.onSetRoomName(e.target.value)}
|
||||
title={t("objinfo.room.name")}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* SIA-416-Kategorie (5 Blatt-Kategorien). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.room.sia")}</span>
|
||||
<Dropdown
|
||||
value={room.siaCategory}
|
||||
onChange={(v) => host.onSetRoomSia(v as SiaCategory)}
|
||||
options={SIA_CATEGORIES.map((c) => ({
|
||||
value: c,
|
||||
label: siaLabelFull(c),
|
||||
}))}
|
||||
title={t("objinfo.room.sia")}
|
||||
width={170}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Fläche + Umfang (read-only, abgeleitet). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.room.area")}</span>
|
||||
<span className="objinfo-fval">{room.area.toFixed(2)} m²</span>
|
||||
</div>
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.room.perimeter")}</span>
|
||||
<span className="objinfo-fval">{formatM(room.perimeter)}</span>
|
||||
</div>
|
||||
|
||||
{/* Referenzgeschoss (read-only). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.room.refFloor")}</span>
|
||||
<span className="objinfo-fval">{room.floorName}</span>
|
||||
</div>
|
||||
|
||||
{/* [158] Raumbuch: Nutzung und Oberflächen. */}
|
||||
<RoomFinishFields roomId={roomId} />
|
||||
|
||||
{/* Stempel bearbeiten (öffnet den Rich-Text-Editor). */}
|
||||
<button
|
||||
type="button"
|
||||
className="objinfo-btn"
|
||||
onClick={() => host.onEditRoomStamp(roomId)}
|
||||
>
|
||||
{t("objinfo.room.editStamp")}
|
||||
</button>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
type RoomFinishField = "floorFinish" | "wallFinish" | "ceilingFinish" | "floorBuildUp";
|
||||
|
||||
|
||||
/** [158] Nutzung (Nassraum abgeleitet) und Oberflächen Boden/Wand/Decke (Material aus dem Projekt oder
|
||||
* Freitext; ein eingegebener Material-Name wird als Verweis gespeichert) und Bodenaufbau. */
|
||||
function RoomFinishFields({ roomId }: { roomId: string }) {
|
||||
const storeProject = useStore((st) => st.project);
|
||||
const applyChange = useStore((s) => s.applyChange);
|
||||
const project = storeProject;
|
||||
const room = (project.rooms ?? []).find((r) => r.id === roomId);
|
||||
if (!room) return null;
|
||||
const comps = project.components;
|
||||
const listId = `room-finish-materials-${roomId}`;
|
||||
const shown = (v: string | undefined) => comps.find((c) => c.id === v)?.name ?? v ?? "";
|
||||
const set = (field: RoomFinishField | "usage", value: string | undefined) =>
|
||||
applyChange((p: Project) => patchItem(p, "rooms", roomId, { [field]: value } as Partial<Room>), `room:${roomId}:${field}`);
|
||||
const setFinish = (field: RoomFinishField, text: string) => {
|
||||
const v = text.trim();
|
||||
if (!v) return set(field, undefined);
|
||||
const comp = field === "floorBuildUp" ? undefined : comps.find((c) => c.name.trim() === v);
|
||||
set(field, comp ? comp.id : text);
|
||||
};
|
||||
// Nassraum wie im Kern (Nutzung, sonst Name), für [156] „Nassräume" im Grundriss.
|
||||
const wet = roomBook(project).rows.find((r) => r.id === roomId)?.wet ?? false;
|
||||
const finishInput = (field: RoomFinishField, label: TranslationKey) => (
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t(label)}</span>
|
||||
<input
|
||||
type="text"
|
||||
className="objinfo-text"
|
||||
list={field === "floorBuildUp" ? undefined : listId}
|
||||
value={shown(room[field])}
|
||||
placeholder={field === "floorBuildUp" ? undefined : t("objinfo.room.finishHint")}
|
||||
onChange={(e) => setFinish(field, e.target.value)}
|
||||
title={t(label)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
return (
|
||||
<>
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.room.usage")}</span>
|
||||
<Dropdown
|
||||
value={room.usage ?? ""}
|
||||
onChange={(v) => set("usage", v || undefined)}
|
||||
options={[{ value: "", label: t("objinfo.room.usageNone") }, ...ROOM_USAGES.map((u) => ({ value: u, label: usageLabel(u) }))]}
|
||||
title={t("objinfo.room.usage")}
|
||||
width={170}
|
||||
/>
|
||||
</div>
|
||||
{wet && (
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.room.wet")}</span>
|
||||
<span className="objinfo-fval">✓</span>
|
||||
</div>
|
||||
)}
|
||||
<div className="objinfo-section-label">{t("objinfo.room.finishes")}</div>
|
||||
<datalist id={listId}>
|
||||
{comps.map((c) => (
|
||||
<option key={c.id} value={c.name} />
|
||||
))}
|
||||
</datalist>
|
||||
{finishInput("floorFinish", "objinfo.room.floorFinish")}
|
||||
{finishInput("wallFinish", "objinfo.room.wallFinish")}
|
||||
{finishInput("ceilingFinish", "objinfo.room.ceilingFinish")}
|
||||
{finishInput("floorBuildUp", "objinfo.room.buildUp")}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
// Abschnitt „Schnitt-/Ansichtslinie" der Attribute ([165] aus `ObjectInfoPanel.tsx`): Name, Art, Tiefe,
|
||||
// Umkehren, Höhenmarken, Plan-Unterlage. Gerufen von `AttributesPanel`.
|
||||
|
||||
import { useStore } from "../../state/appStore";
|
||||
import type { DrawingLevel, Vec2 } from "../../model/types";
|
||||
import { usePanelHost } from "../host";
|
||||
import { t } from "../../i18n";
|
||||
import type { TranslationKey } from "../../i18n";
|
||||
import { Dropdown } from "../../ui/Dropdown";
|
||||
|
||||
// ── Schnitt-/Ansichtslinien-Abschnitt (Object-Info; nur die gewählte Linie) ──
|
||||
// Name (editierbar), Blickrichtung umkehren (directionSign-Flip), Endpunkt-
|
||||
// Koordinaten (editierbar) + Schnitt-Tiefe; Löschen setzt linePoints zurück
|
||||
// (die Ebene bleibt bestehen). Eine Schnittlinie ist KEIN Projekt-Bauteil,
|
||||
// darum kommt sie über `host.sectionLine` (nicht über `selection`).
|
||||
export function SectionLineSection({
|
||||
level,
|
||||
host,
|
||||
}: {
|
||||
level: DrawingLevel;
|
||||
host: ReturnType<typeof usePanelHost>;
|
||||
}) {
|
||||
const storeProject = useStore((st) => st.project);
|
||||
const line = level.linePoints;
|
||||
const kindLabel =
|
||||
level.kind === "elevation"
|
||||
? t("objinfo.sectionLine.kind.elevation")
|
||||
: t("objinfo.sectionLine.kind.section");
|
||||
const patchPoint = (which: 0 | 1, axis: "x" | "y", value: number) => {
|
||||
if (!line) return;
|
||||
const next: [Vec2, Vec2] = [{ ...line[0] }, { ...line[1] }];
|
||||
next[which] = { ...next[which], [axis]: value };
|
||||
host.onSetSectionLinePatch({ linePoints: next });
|
||||
};
|
||||
const coordField = (labelKey: TranslationKey, value: number, on: (v: number) => void) => (
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t(labelKey)}</span>
|
||||
<input
|
||||
type="number"
|
||||
className="objinfo-text"
|
||||
step={0.1}
|
||||
value={value}
|
||||
onChange={(e) => {
|
||||
const v = Number(e.target.value);
|
||||
if (Number.isFinite(v)) on(v);
|
||||
}}
|
||||
title={t(labelKey)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
return (
|
||||
<>
|
||||
<div className="objinfo-sep" />
|
||||
<div className="objinfo-section-label">
|
||||
{t("objinfo.sectionLine.section")} · {kindLabel}
|
||||
</div>
|
||||
|
||||
{/* Name (editierbar). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.sectionLine.name")}</span>
|
||||
<input
|
||||
type="text"
|
||||
className="objinfo-text"
|
||||
value={level.name}
|
||||
onChange={(e) => host.onSetSectionLinePatch({ name: e.target.value })}
|
||||
title={t("objinfo.sectionLine.name")}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Blickrichtung umkehren (directionSign-Flip). */}
|
||||
<button
|
||||
type="button"
|
||||
className="objinfo-btn"
|
||||
onClick={() =>
|
||||
host.onSetSectionLinePatch({
|
||||
directionSign: (level.directionSign ?? 1) === 1 ? -1 : 1,
|
||||
})
|
||||
}
|
||||
>
|
||||
{t("objinfo.sectionLine.flip")}
|
||||
</button>
|
||||
|
||||
{/* 3D-Live-Schnitt an diese Linie binden (nur mit gesetzter Linie sinnvoll):
|
||||
der Viewport clippt dann vertikal entlang dieser Ebene. */}
|
||||
{line && (
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.sectionLine.cut3d")}</span>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={host.section3dCutActive}
|
||||
onChange={() => host.onToggleSection3dCut(level.id)}
|
||||
title={t("objinfo.sectionLine.cut3d")}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Endpunkt-Koordinaten (nur wenn eine Linie gesetzt ist). */}
|
||||
{line && (
|
||||
<>
|
||||
{coordField("objinfo.sectionLine.startX", line[0].x, (v) => patchPoint(0, "x", v))}
|
||||
{coordField("objinfo.sectionLine.startY", line[0].y, (v) => patchPoint(0, "y", v))}
|
||||
{coordField("objinfo.sectionLine.endX", line[1].x, (v) => patchPoint(1, "x", v))}
|
||||
{coordField("objinfo.sectionLine.endY", line[1].y, (v) => patchPoint(1, "y", v))}
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Schnitt-Tiefe (leer = unbegrenzt). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.sectionLine.depth")}</span>
|
||||
<input
|
||||
type="number"
|
||||
className="objinfo-text"
|
||||
step={0.5}
|
||||
min={0}
|
||||
value={level.depth ?? ""}
|
||||
placeholder={t("objinfo.sectionLine.depthHint")}
|
||||
onChange={(e) => {
|
||||
const raw = e.target.value.trim();
|
||||
if (raw === "") {
|
||||
host.onSetSectionLinePatch({ depth: undefined });
|
||||
return;
|
||||
}
|
||||
const v = Number(raw);
|
||||
if (Number.isFinite(v) && v > 0) host.onSetSectionLinePatch({ depth: v });
|
||||
}}
|
||||
title={t("objinfo.sectionLine.depth")}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Verdeckte Kanten (gestrichelt) — Default aus (blasses Liniengewirr). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.sectionLine.hiddenLines")}</span>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={level.hiddenLines ?? false}
|
||||
onChange={(e) => host.onSetSectionLinePatch({ hiddenLines: e.target.checked })}
|
||||
title={t("objinfo.sectionLine.hiddenLines")}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Automatische Höhenkoten (Geschosse + oberste Kante). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.sectionLine.levelMarks")}</span>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={level.levelMarks !== false}
|
||||
onChange={(e) => host.onSetSectionLinePatch({ levelMarks: e.target.checked ? undefined : false })}
|
||||
title={t("objinfo.sectionLine.levelMarks")}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Grundriss-Unterlage: ein Geschoss ausgerichtet unter dem Schnitt/der Ansicht. */}
|
||||
{line && (
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.sectionLine.planUnderlay")}</span>
|
||||
<Dropdown
|
||||
value={level.planUnderlayId ?? ""}
|
||||
onChange={(v) => host.onSetSectionLinePatch({ planUnderlayId: v || undefined })}
|
||||
options={[
|
||||
{ value: "", label: t("objinfo.sectionLine.planUnderlay.none") },
|
||||
...storeProject.drawingLevels
|
||||
.filter((l) => l.kind === "floor")
|
||||
.map((l) => ({ value: l.id, label: l.name })),
|
||||
]}
|
||||
title={t("objinfo.sectionLine.planUnderlay")}
|
||||
width={150}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Löschen: linePoints zurücksetzen (die Ebene bleibt bestehen). */}
|
||||
<button type="button" className="objinfo-btn" onClick={() => host.onDeleteSectionLine()}>
|
||||
{t("objinfo.sectionLine.delete")}
|
||||
</button>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,278 @@
|
||||
// Abschnitte „Extrudierter Körper" und „Stütze" der Attribute ([165] aus `ObjectInfoPanel.tsx`), dazu die
|
||||
// Kennwert-Zeilen des Körpers (truck). Gerufen von `AttributesPanel`.
|
||||
|
||||
import type { SolidSpec, SolidProps } from "../../engine/truckSolid";
|
||||
import { useState, useEffect } from "react";
|
||||
import { solidProps } from "../../engine/truckSolid";
|
||||
import { t } from "../../i18n";
|
||||
import type { ExtrudedSolidInfo, ColumnInfo } from "../../state/selectionInfo";
|
||||
import { usePanelHost } from "../host";
|
||||
import { Dropdown } from "../../ui/Dropdown";
|
||||
import { DimensionField } from "./fields";
|
||||
|
||||
/** Volumen/Oberfläche/Schwerpunkt aus truck (asynchron, aus dem tessellierten B-Rep). */
|
||||
function SolidPropsRows({ spec }: { spec: SolidSpec | null }) {
|
||||
const [props, setProps] = useState<SolidProps | null>(null);
|
||||
const key = JSON.stringify(spec);
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
setProps(null);
|
||||
if (!spec) return;
|
||||
solidProps(spec).then(
|
||||
(p) => alive && setProps(p),
|
||||
() => alive && setProps(null),
|
||||
);
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [key]);
|
||||
if (!props) return null;
|
||||
const f = (v: number, d = 2) => v.toLocaleString(undefined, { minimumFractionDigits: d, maximumFractionDigits: d });
|
||||
return (
|
||||
<>
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.extrudedSolid.volume")}</span>
|
||||
<span className="objinfo-fval">{f(props.volume)} m³</span>
|
||||
</div>
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.extrudedSolid.surface")}</span>
|
||||
<span className="objinfo-fval">{f(props.area)} m²</span>
|
||||
</div>
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.extrudedSolid.centroid")}</span>
|
||||
<span className="objinfo-fval">
|
||||
{f(props.centroid[0])} / {f(props.centroid[1])} / {f(props.centroid[2])}
|
||||
</span>
|
||||
</div>
|
||||
{!props.closed && <div className="objinfo-field objinfo-warn">{t("objinfo.extrudedSolid.notClosed")}</div>}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// ── Extrusions-Attribut-Abschnitt (truck-Integration) ───────────────────────
|
||||
// Höhe editierbar (löst Re-Extrusion aus); Grundfläche + Geschoss read-only.
|
||||
export function ExtrudedSolidSection({
|
||||
solid,
|
||||
host,
|
||||
}: {
|
||||
solid: ExtrudedSolidInfo;
|
||||
host: ReturnType<typeof usePanelHost>;
|
||||
}) {
|
||||
return (
|
||||
<>
|
||||
<div className="objinfo-sep" />
|
||||
<div className="objinfo-section-label">{t("objinfo.extrudedSolid.section")}</div>
|
||||
|
||||
{/* Höhe (editierbar, > 0) — löst eine Re-Extrusion (truck-WASM) aus. */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.extrudedSolid.height")}</span>
|
||||
<input
|
||||
type="number"
|
||||
className="objinfo-text"
|
||||
step={0.01}
|
||||
min={0.01}
|
||||
value={solid.height}
|
||||
onChange={(e) => {
|
||||
const v = Number(e.target.value);
|
||||
if (Number.isFinite(v) && v > 0) host.onSetExtrudedSolidHeight(v);
|
||||
}}
|
||||
title={t("objinfo.extrudedSolid.height")}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<SolidPropsRows spec={solid.spec} />
|
||||
|
||||
{/* Abstand über Geschoss-UK (Brüstungs-/Durchbruchshöhe). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.extrudedSolid.baseOffset")}</span>
|
||||
<input
|
||||
type="number"
|
||||
className="objinfo-text"
|
||||
step={0.05}
|
||||
value={solid.baseOffset}
|
||||
onChange={(e) => {
|
||||
const v = Number(e.target.value);
|
||||
if (Number.isFinite(v)) host.onSetExtrudedSolidBaseOffset(v);
|
||||
}}
|
||||
title={t("objinfo.extrudedSolid.baseOffset")}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Abzugskörper: zieht sich von Wänden/Decken/Stützen ab (Grundriss, Schnitt, 3D, STEP). */}
|
||||
{solid.canSubtract && (
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.extrudedSolid.subtract")}</span>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={solid.subtract}
|
||||
onChange={(e) => host.onSetExtrudedSolidSubtract(e.target.checked)}
|
||||
title={t("objinfo.extrudedSolid.subtractHint")}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{solid.brepLabel && (
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.extrudedSolid.brep")}</span>
|
||||
<span className="objinfo-fval">{solid.brepLabel}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Eckenradius (editierbar, ≥ 0): echte Kreisbögen an den Ecken der Aussenkontur. */}
|
||||
{!solid.brepLabel && (
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.extrudedSolid.cornerRadius")}</span>
|
||||
<input
|
||||
type="number"
|
||||
className="objinfo-text"
|
||||
step={0.05}
|
||||
min={0}
|
||||
value={solid.cornerRadius}
|
||||
onChange={(e) => {
|
||||
const v = Number(e.target.value);
|
||||
if (Number.isFinite(v) && v >= 0) host.onSetExtrudedSolidCornerRadius(v);
|
||||
}}
|
||||
title={t("objinfo.extrudedSolid.cornerRadius")}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Fase (editierbar, ≥ 0): gerade Abschrägung der Ecken der Aussenkontur. */}
|
||||
{!solid.brepLabel && (
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.extrudedSolid.chamfer")}</span>
|
||||
<input
|
||||
type="number"
|
||||
className="objinfo-text"
|
||||
step={0.05}
|
||||
min={0}
|
||||
value={solid.chamfer}
|
||||
onChange={(e) => {
|
||||
const v = Number(e.target.value);
|
||||
if (Number.isFinite(v) && v >= 0) host.onSetExtrudedSolidChamfer(v);
|
||||
}}
|
||||
title={t("objinfo.extrudedSolid.chamfer")}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Verjüngung (editierbar, 0..1) — löst eine Re-Extrusion (truck-WASM) aus. */}
|
||||
{!solid.brepLabel && (
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.extrudedSolid.taper")}</span>
|
||||
<input
|
||||
type="number"
|
||||
className="objinfo-text"
|
||||
step={0.05}
|
||||
min={0}
|
||||
max={1}
|
||||
value={solid.taper}
|
||||
onChange={(e) => {
|
||||
const v = Number(e.target.value);
|
||||
if (Number.isFinite(v)) host.onSetExtrudedSolidTaper(v);
|
||||
}}
|
||||
title={t("objinfo.extrudedSolid.taper")}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Grundfläche (read-only, abgeleitet). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.extrudedSolid.area")}</span>
|
||||
<span className="objinfo-fval">{solid.area.toFixed(2)} m²</span>
|
||||
</div>
|
||||
|
||||
{/* Geschoss (read-only). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.extrudedSolid.floor")}</span>
|
||||
<span className="objinfo-fval">{solid.floorName}</span>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// ── Stützen-Attribut-Abschnitt (Tragwerk) ───────────────────────────────────
|
||||
// Profil (Rechteck/Kreis) + Masse, Höhe, Drehung editierbar; Geschoss + UK/OK
|
||||
// read-only.
|
||||
export function ColumnSection({
|
||||
column,
|
||||
host,
|
||||
}: {
|
||||
column: ColumnInfo;
|
||||
host: ReturnType<typeof usePanelHost>;
|
||||
}) {
|
||||
return (
|
||||
<>
|
||||
<div className="objinfo-sep" />
|
||||
<div className="objinfo-section-label">{t("objinfo.column.section")}</div>
|
||||
|
||||
{/* Profil-Dropdown (Rechteck/Kreis). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.column.profile")}</span>
|
||||
<Dropdown
|
||||
value={column.profile.kind}
|
||||
onChange={(v) => host.onSetColumnProfileKind(v as "rect" | "round")}
|
||||
options={[
|
||||
{ value: "rect", label: t("objinfo.column.profile.rect") },
|
||||
{ value: "round", label: t("objinfo.column.profile.round") },
|
||||
]}
|
||||
title={t("objinfo.column.profile")}
|
||||
width={130}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Editierbare Masse je Profil. */}
|
||||
{column.profile.kind === "round" ? (
|
||||
<DimensionField
|
||||
label={t("objinfo.column.radius")}
|
||||
value={column.profile.radius}
|
||||
onCommit={(v) => host.onSetColumnRadius(v)}
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
<DimensionField
|
||||
label={t("objinfo.column.width")}
|
||||
value={column.profile.kind === "rect" ? column.profile.width : 0}
|
||||
onCommit={(v) => host.onSetColumnWidth(v)}
|
||||
/>
|
||||
<DimensionField
|
||||
label={t("objinfo.column.depth")}
|
||||
value={column.profile.kind === "rect" ? column.profile.depth : 0}
|
||||
onCommit={(v) => host.onSetColumnDepth(v)}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
||||
<DimensionField
|
||||
label={t("objinfo.column.height")}
|
||||
value={column.height}
|
||||
onCommit={(v) => host.onSetColumnHeight(v)}
|
||||
/>
|
||||
|
||||
{/* Drehung (Grad). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.column.rotation")}</span>
|
||||
<input
|
||||
type="number"
|
||||
className="objinfo-text"
|
||||
step={1}
|
||||
value={Number(column.rotationDeg.toFixed(1))}
|
||||
onChange={(e) => {
|
||||
const v = Number(e.target.value);
|
||||
if (Number.isFinite(v)) host.onSetColumnRotation(v);
|
||||
}}
|
||||
title={t("objinfo.column.rotation")}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Geschoss (read-only). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.column.floor")}</span>
|
||||
<span className="objinfo-fval">{column.floorName}</span>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,269 @@
|
||||
// Abschnitt „Treppe" der Attribute ([165] aus `ObjectInfoPanel.tsx`): Treppenform und Läufe.
|
||||
// Gerufen von `AttributesPanel`.
|
||||
|
||||
import { useStore } from "../../state/appStore";
|
||||
import type { StairInfo } from "../../state/selectionInfo";
|
||||
import { usePanelHost } from "../host";
|
||||
import { t } from "../../i18n";
|
||||
import { Dropdown } from "../../ui/Dropdown";
|
||||
import type { StairShape } from "../../model/types";
|
||||
import { formatM } from "../../model/types";
|
||||
import { DimensionField } from "./fields";
|
||||
|
||||
/**
|
||||
* [151] Läufe und Podest einer Podesttreppe (L, U, gerade mit Podest): Lauflängen, Steigungen im ersten
|
||||
* Lauf, Drehsinn (L/U), Treppenauge, Mittellauf und Versatz (U), Podesttiefe (U, gerade mit Podest).
|
||||
*/
|
||||
function StairFlightFields({ stair, host }: { stair: StairInfo; host: ReturnType<typeof usePanelHost> }) {
|
||||
const isU = stair.shape === "U";
|
||||
const turn = stair.turn ?? 1;
|
||||
return (
|
||||
<>
|
||||
<DimensionField
|
||||
label={t("objinfo.stair.run1")}
|
||||
value={stair.runLength ?? 0}
|
||||
onCommit={(v) => v > 0.1 && host.onSetStairPatch({ runLength: v })}
|
||||
/>
|
||||
<DimensionField
|
||||
label={t("objinfo.stair.run2")}
|
||||
value={stair.run2Length ?? stair.runLength ?? 0}
|
||||
onCommit={(v) => v > 0.1 && host.onSetStairPatch({ run2Length: v })}
|
||||
/>
|
||||
<DimensionField
|
||||
label={t("objinfo.stair.run1Steps")}
|
||||
unit="" step={1} digits={0} value={stair.run1Steps ?? 0}
|
||||
onCommit={(v) => host.onSetStairPatch({ run1Steps: v >= 1 ? Math.round(v) : undefined })}
|
||||
/>
|
||||
{stair.shape !== "straightLanding" && (
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.stair.turn")}</span>
|
||||
<div className="objinfo-segment">
|
||||
<button
|
||||
type="button"
|
||||
className={"objinfo-seg-btn" + (turn > 0 ? " active" : "")}
|
||||
onClick={() => host.onSetStairPatch({ turn: 1 })}
|
||||
>
|
||||
{t("objinfo.stair.turn.left")}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={"objinfo-seg-btn" + (turn < 0 ? " active" : "")}
|
||||
onClick={() => host.onSetStairPatch({ turn: -1 })}
|
||||
>
|
||||
{t("objinfo.stair.turn.right")}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{stair.shape !== "L" && (
|
||||
<DimensionField
|
||||
label={t("objinfo.stair.landing")}
|
||||
value={stair.landingLength ?? stair.width}
|
||||
onCommit={(v) => v > 0.1 && host.onSetStairPatch({ landingLength: v })}
|
||||
/>
|
||||
)}
|
||||
{isU && (
|
||||
<>
|
||||
<DimensionField
|
||||
label={t("objinfo.stair.gap")}
|
||||
value={stair.gap ?? 0.1}
|
||||
onCommit={(v) => v >= 0 && host.onSetStairPatch({ gap: v })}
|
||||
/>
|
||||
<DimensionField
|
||||
label={t("objinfo.stair.midSteps")}
|
||||
unit="" step={1} digits={0} value={stair.midSteps ?? 0}
|
||||
onCommit={(v) => host.onSetStairPatch({ midSteps: v >= 1 ? Math.round(v) : undefined })}
|
||||
/>
|
||||
{(stair.midSteps ?? 0) >= 1 && (
|
||||
<DimensionField
|
||||
label={t("objinfo.stair.midOffset")}
|
||||
min={-10} value={stair.midOffset ?? 0}
|
||||
onCommit={(v) => host.onSetStairPatch({ midOffset: v !== 0 ? v : undefined })}
|
||||
/>
|
||||
)}
|
||||
<DimensionField
|
||||
label={t("objinfo.stair.run2Offset")}
|
||||
min={-10} value={stair.run2Offset ?? 0}
|
||||
onCommit={(v) => host.onSetStairPatch({ run2Offset: v !== 0 ? v : undefined })}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
export function StairSection({
|
||||
stair,
|
||||
host,
|
||||
}: {
|
||||
stair: StairInfo;
|
||||
host: ReturnType<typeof usePanelHost>;
|
||||
}) {
|
||||
const storeProject = useStore((st) => st.project);
|
||||
return (
|
||||
<>
|
||||
<div className="objinfo-sep" />
|
||||
<div className="objinfo-section-label">{t("objinfo.stair.section")}</div>
|
||||
|
||||
{/* Treppentyp (Bibliothek) — treibt u. a. die 3D-Tragart (massiv/offen). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.stair.type")}</span>
|
||||
<Dropdown
|
||||
value={stair.typeId ?? ""}
|
||||
onChange={(v) => host.onSetStairType(v)}
|
||||
options={[
|
||||
{ value: "", label: t("objinfo.type.none") },
|
||||
...(storeProject.stairTypes ?? []).map((st) => ({
|
||||
value: st.id,
|
||||
label: st.name,
|
||||
})),
|
||||
]}
|
||||
title={t("objinfo.stair.type")}
|
||||
width={130}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Grundform-Dropdown. */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.stair.shape")}</span>
|
||||
<Dropdown
|
||||
value={stair.shape}
|
||||
onChange={(v) => host.onSetStairShape(v as StairShape)}
|
||||
options={[
|
||||
{ value: "straight", label: t("objinfo.stair.shape.straight") },
|
||||
{ value: "L", label: t("objinfo.stair.shape.L") },
|
||||
{ value: "U", label: t("objinfo.stair.shape.U") },
|
||||
{ value: "straightLanding", label: t("objinfo.stair.shape.straightLanding") },
|
||||
{ value: "spiral", label: t("objinfo.stair.shape.spiral") },
|
||||
]}
|
||||
title={t("objinfo.stair.shape")}
|
||||
width={130}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Referenzpunkt der Laufbreite (links/mitte/rechts). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.stair.referenz")}</span>
|
||||
<Dropdown
|
||||
value={stair.referenz ?? "mitte"}
|
||||
onChange={(v) => host.onSetStairReferenz(v as "links" | "mitte" | "rechts")}
|
||||
options={[
|
||||
{ value: "links", label: t("objinfo.stair.referenz.links") },
|
||||
{ value: "mitte", label: t("objinfo.stair.referenz.mitte") },
|
||||
{ value: "rechts", label: t("objinfo.stair.referenz.rechts") },
|
||||
]}
|
||||
title={t("objinfo.stair.referenz")}
|
||||
width={130}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Laufrichtung (aufwärts/abwärts). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.stair.direction")}</span>
|
||||
<div className="objinfo-segment">
|
||||
<button
|
||||
type="button"
|
||||
className={"objinfo-seg-btn" + (stair.up ? " active" : "")}
|
||||
onClick={() => host.onSetStairUp(true)}
|
||||
>
|
||||
{t("objinfo.stair.direction.up")}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={"objinfo-seg-btn" + (!stair.up ? " active" : "")}
|
||||
onClick={() => host.onSetStairUp(false)}
|
||||
>
|
||||
{t("objinfo.stair.direction.down")}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Pfeil-Darstellung (offener Winkel- oder gefüllter SIA-Vollpfeil). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.stair.arrow")}</span>
|
||||
<div className="objinfo-segment">
|
||||
<button
|
||||
type="button"
|
||||
className={"objinfo-seg-btn" + ((stair.arrowStyle ?? "line") === "line" ? " active" : "")}
|
||||
onClick={() => host.onSetStairArrowStyle("line")}
|
||||
>
|
||||
{t("objinfo.stair.arrow.line")}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={"objinfo-seg-btn" + (stair.arrowStyle === "filled" ? " active" : "")}
|
||||
onClick={() => host.onSetStairArrowStyle("filled")}
|
||||
>
|
||||
{t("objinfo.stair.arrow.filled")}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Editierbare Maße. */}
|
||||
<DimensionField
|
||||
label={t("objinfo.stair.width")}
|
||||
value={stair.width}
|
||||
onCommit={(v) => host.onSetStairWidth(v)}
|
||||
/>
|
||||
{stair.shape === "spiral" && (
|
||||
<DimensionField
|
||||
label={t("objinfo.stair.column")}
|
||||
value={stair.centerColumn ?? 0}
|
||||
onCommit={(v) => host.onSetStairColumn(v)}
|
||||
/>
|
||||
)}
|
||||
{stair.shape !== "spiral" && stair.shape !== "straight" && <StairFlightFields stair={stair} host={host} />}
|
||||
<DimensionField
|
||||
label={t("objinfo.stair.steps")}
|
||||
value={stair.stepCount}
|
||||
onCommit={(v) => host.onSetStairSteps(v)}
|
||||
/>
|
||||
<DimensionField
|
||||
label={t("objinfo.stair.rise")}
|
||||
value={stair.totalRise}
|
||||
onCommit={(v) => host.onSetStairRise(v)}
|
||||
/>
|
||||
|
||||
{/* Abgeleitete Werte (read-only). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.stair.riser")}</span>
|
||||
<span className="objinfo-fval">{formatM(stair.riserHeight)}</span>
|
||||
</div>
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.stair.tread")}</span>
|
||||
<span className="objinfo-fval">{formatM(stair.treadDepth)}</span>
|
||||
</div>
|
||||
{stair.concreteVolume !== undefined && (
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.stair.concreteVolume")}</span>
|
||||
<span className="objinfo-fval">{stair.concreteVolume.toFixed(2)} m³</span>
|
||||
</div>
|
||||
)}
|
||||
{stair.soffitArea !== undefined && (
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.stair.soffitArea")}</span>
|
||||
<span className="objinfo-fval">{stair.soffitArea.toFixed(2)} m²</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Referenzgeschoss (read-only). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.stair.refFloor")}</span>
|
||||
<span className="objinfo-fval">{stair.floorName}</span>
|
||||
</div>
|
||||
|
||||
<div className="objinfo-sep" />
|
||||
|
||||
{/* UK/OK (read-only). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.stair.bottom")}</span>
|
||||
<span className="objinfo-fval">{formatM(stair.zBottom)}</span>
|
||||
</div>
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.stair.top")}</span>
|
||||
<span className="objinfo-fval">{formatM(stair.zTop)}</span>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
// Abschnitt „Baum" der Objekt-Info ([165] aus `ObjectInfoPanel.tsx`) samt den Auswahllisten für Form, Status
|
||||
// und Laub. Gerufen von `ObjectInfoPanel`.
|
||||
|
||||
import type { TreeShape, TreeStatus, TreeFoliage, Tree } from "../../model/types";
|
||||
import { useStore } from "../../state/appStore";
|
||||
import { t } from "../../i18n";
|
||||
import { patchItem } from "../../core";
|
||||
import { Dropdown } from "../../ui/Dropdown";
|
||||
import type { TranslationKey } from "../../i18n";
|
||||
import { DimensionField } from "./fields";
|
||||
|
||||
// ── Editierbares Maßfeld ─────────────────────────────────────────────────────
|
||||
// Kontrolliert über den vom Host gelieferten Wert, hält aber während des
|
||||
// Tippens einen lokalen Entwurf. Commit auf blur/Enter; Escape verwirft.
|
||||
// Nach erfolgreichem Resize liefert der Host eine neue bbox → neuer `value` →
|
||||
// das Feld zeigt automatisch die aktualisierte Größe. `min` erlaubt negative
|
||||
// Werte (z. B. absolute Z-Höhen unter 0).
|
||||
// ── Baum ([149]) ─────────────────────────────────────────────────────────────
|
||||
// Lage (Stammmitte), Masse, Form, Bestand, Laub/Nadel und Art des ersten gewählten Baums; jede Änderung
|
||||
// ein Undo-Schritt (Kern prüft die Op). Bei mehreren gewählten Bäumen wirken Form/Bestand/Laub auf alle.
|
||||
const TREE_SHAPES: TreeShape[] = ["round", "oval", "columnar", "conical"];
|
||||
|
||||
const TREE_STATUS: TreeStatus[] = ["existing", "new", "remove"];
|
||||
|
||||
const TREE_FOLIAGE: TreeFoliage[] = ["deciduous", "conifer"];
|
||||
|
||||
|
||||
export function TreeSection({ ids }: { ids: readonly string[] }) {
|
||||
const storeProject = useStore((st) => st.project);
|
||||
const applyChange = useStore((s) => s.applyChange);
|
||||
const trees = (storeProject.trees ?? []).filter((x) => ids.includes(x.id));
|
||||
const tree = trees[0];
|
||||
if (!tree) return <div className="objinfo-panel"><div className="objinfo-empty">{t("objinfo.empty")}</div></div>;
|
||||
const locked = !!tree.locked;
|
||||
const set = (patch: Partial<Tree>, all = false) =>
|
||||
applyChange((p) => (all ? trees : [tree]).filter((x) => !x.locked).flatMap((x) => patchItem(p, "trees", x.id, patch)));
|
||||
const level = storeProject.drawingLevels.find((l) => l.id === tree.floorId);
|
||||
return (
|
||||
<div className="objinfo-panel objinfo-tree">
|
||||
<div className="objinfo-head">
|
||||
<span className="objinfo-kind">{trees.length > 1 ? t("objinfo.tree.many", { n: trees.length }) : t("objinfo.kind.tree")}</span>
|
||||
</div>
|
||||
<div className="objinfo-section-label">{t("objinfo.tree.section")}</div>
|
||||
<label className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.tree.species")}</span>
|
||||
<input
|
||||
className="objinfo-text"
|
||||
type="text"
|
||||
defaultValue={tree.species ?? ""}
|
||||
key={`sp-${tree.id}-${tree.species ?? ""}`}
|
||||
disabled={locked}
|
||||
placeholder={t("objinfo.tree.speciesHint")}
|
||||
onBlur={(e) => {
|
||||
const v = e.target.value.trim();
|
||||
if (v !== (tree.species ?? "")) set({ species: v || undefined });
|
||||
}}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter") (e.target as HTMLInputElement).blur();
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.tree.showLabel")}</span>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={tree.showLabel === true}
|
||||
disabled={locked}
|
||||
onChange={(e) => set({ showLabel: e.target.checked }, true)}
|
||||
title={t("objinfo.tree.showLabelHint")}
|
||||
data-testid="tree-show-label"
|
||||
/>
|
||||
</div>
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.tree.status")}</span>
|
||||
<Dropdown
|
||||
value={tree.status}
|
||||
onChange={(v) => set({ status: v as TreeStatus }, true)}
|
||||
options={TREE_STATUS.map((v) => ({ value: v, label: t(`objinfo.tree.status.${v}` as TranslationKey) }))}
|
||||
title={t("objinfo.tree.status")}
|
||||
width={130}
|
||||
/>
|
||||
</div>
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.tree.shape")}</span>
|
||||
<Dropdown
|
||||
value={tree.shape}
|
||||
onChange={(v) => set({ shape: v as TreeShape }, true)}
|
||||
options={TREE_SHAPES.map((v) => ({ value: v, label: t(`objinfo.tree.shape.${v}` as TranslationKey) }))}
|
||||
title={t("objinfo.tree.shape")}
|
||||
width={130}
|
||||
/>
|
||||
</div>
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.tree.foliage")}</span>
|
||||
<Dropdown
|
||||
value={tree.foliage}
|
||||
onChange={(v) => set({ foliage: v as TreeFoliage }, true)}
|
||||
options={TREE_FOLIAGE.map((v) => ({ value: v, label: t(`objinfo.tree.foliage.${v}` as TranslationKey) }))}
|
||||
title={t("objinfo.tree.foliage")}
|
||||
width={130}
|
||||
/>
|
||||
</div>
|
||||
<DimensionField label={t("objinfo.tree.height")} value={tree.height} min={0.5} onCommit={(v) => set({ height: v, crownBase: Math.min(tree.crownBase, 0.9 * v) })} />
|
||||
<DimensionField label={t("objinfo.tree.crownDiameter")} value={tree.crownDiameter} min={0.2} onCommit={(v) => set({ crownDiameter: v })} />
|
||||
<DimensionField label={t("objinfo.tree.crownBase")} value={tree.crownBase} onCommit={(v) => set({ crownBase: Math.min(v, 0.9 * tree.height) })} />
|
||||
<DimensionField label={t("objinfo.tree.trunkDiameter")} value={tree.trunkDiameter} min={0.02} onCommit={(v) => set({ trunkDiameter: v })} />
|
||||
<DimensionField label="X" value={tree.position.x} min={-Infinity} onCommit={(v) => set({ position: { x: v, y: tree.position.y } })} />
|
||||
<DimensionField label="Y" value={tree.position.y} min={-Infinity} onCommit={(v) => set({ position: { x: tree.position.x, y: v } })} />
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.column.floor")}</span>
|
||||
<span className="objinfo-fval">{level?.name ?? tree.floorId}</span>
|
||||
</div>
|
||||
{locked && <div className="objinfo-muted">{t("objinfo.tree.locked")}</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
// Abschnitt „Wand" der Attribute ([165] aus `ObjectInfoPanel.tsx`): Referenzlinie, Aufbau, Geschoss, Unter-
|
||||
// und Oberkante. Gerufen von `AttributesPanel`.
|
||||
|
||||
import { useStore } from "../../state/appStore";
|
||||
import type { WallInfo } from "../../state/selectionInfo";
|
||||
import { usePanelHost } from "../host";
|
||||
import { t } from "../../i18n";
|
||||
import { Dropdown } from "../../ui/Dropdown";
|
||||
import type { WallReferenceLine, SliceTermination } from "../../model/types";
|
||||
import { UValueRow } from "../UValueRow";
|
||||
import { formatM } from "../../model/types";
|
||||
import { BuildingFlags, DimensionField, VerticalAnchorRow } from "./fields";
|
||||
|
||||
// ── Wand-Attribut-Abschnitt ──────────────────────────────────────────────────
|
||||
// Aufbau-Typ (einschichtig/mehrschichtig), Dicke/Preset, Referenzgeschoss +
|
||||
// Oberverknüpfung, UK/OK je Modus-Umschalter. Alle Werte/Setter über den Host.
|
||||
export function WallSection({
|
||||
wall,
|
||||
host,
|
||||
}: {
|
||||
wall: WallInfo;
|
||||
host: ReturnType<typeof usePanelHost>;
|
||||
}) {
|
||||
const storeProject = useStore((st) => st.project);
|
||||
// Aufbau-Typ-Segment: einschichtig vs. mehrschichtig. Aus dem Modell
|
||||
// abgeleitet (singleLayer); der Umschalter auf „mehrschichtig" wählt einen
|
||||
// mehrschichtigen Wandtyp-Preset (erster mit >1 Schicht), auf „einschichtig"
|
||||
// setzt er die Dicke des aktuellen Aufbaus als einschichtige Wand.
|
||||
const isSingle = wall.singleLayer;
|
||||
|
||||
const multiPresets = wall.wallTypes.filter((wt) => wt.layerCount > 1);
|
||||
|
||||
function chooseSingle() {
|
||||
if (isSingle) return;
|
||||
// Auf einschichtig wechseln: aktuelle Gesamtdicke als Einzelschicht setzen.
|
||||
host.onSetWallThickness(wall.thickness);
|
||||
}
|
||||
function chooseMulti() {
|
||||
if (!isSingle) return;
|
||||
const first = multiPresets[0];
|
||||
if (first) host.onSetWallType(first.id);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="objinfo-sep" />
|
||||
<div className="objinfo-section-label">{t("objinfo.wall.section")}</div>
|
||||
|
||||
{/* Referenzlinie (wo die Achse über die Dicke liegt) — außen/mitte/innen ODER
|
||||
bei mehrschichtigen Wänden eine SCHICHTTRENNLINIE (Fuge). Ein Fugenwert
|
||||
wird als "off:<offset>" kodiert und übersteuert die benannte Linie. */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.wall.refLine")}</span>
|
||||
<Dropdown
|
||||
value={
|
||||
wall.referenceOffset != null
|
||||
? `off:${wall.referenceOffset.toFixed(4)}`
|
||||
: wall.referenceLine
|
||||
}
|
||||
onChange={(v) => {
|
||||
if (v.startsWith("off:")) host.onSetWallReferenceOffset(Number(v.slice(4)));
|
||||
else host.onSetWallReferenceLine(v as WallReferenceLine);
|
||||
}}
|
||||
options={[
|
||||
{ value: "left", label: t("objinfo.wall.refLine.left") },
|
||||
{ value: "center", label: t("objinfo.wall.refLine.center") },
|
||||
{ value: "right", label: t("objinfo.wall.refLine.right") },
|
||||
...wall.layerBoundaries.map((b) => ({
|
||||
value: `off:${b.offset.toFixed(4)}`,
|
||||
label: `${t("objinfo.wall.refLine.joint")} ${b.label}`,
|
||||
})),
|
||||
]}
|
||||
title={t("objinfo.wall.refLine")}
|
||||
width={120}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Terminierung am Deckenanschluss (Zuschnitt, NICHT Priorität): ob die Wand
|
||||
an der Decke endet oder oberhalb wieder auftaucht. Default "both". */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.wall.sliceTermination")}</span>
|
||||
<Dropdown
|
||||
value={wall.sliceTermination}
|
||||
onChange={(v) => host.onSetWallSliceTermination(v as SliceTermination)}
|
||||
options={[
|
||||
{ value: "both", label: t("objinfo.wall.sliceTermination.both") },
|
||||
{ value: "below", label: t("objinfo.wall.sliceTermination.below") },
|
||||
{ value: "above", label: t("objinfo.wall.sliceTermination.above") },
|
||||
]}
|
||||
title={t("objinfo.wall.sliceTermination")}
|
||||
width={120}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* An Dach anschliessen ([G2]): automatisch endet die Wand an der Dach-Unterkante, "Ja"
|
||||
verlängert sie bis unter das Dach, "Nein" lässt die Dächer die Wand nicht schneiden. */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.wall.roofAttach")}</span>
|
||||
<Dropdown
|
||||
value={wall.roofAttach}
|
||||
onChange={(v) => host.onSetWallRoofAttach(v as "auto" | "on" | "off")}
|
||||
options={[
|
||||
{ value: "auto", label: t("objinfo.wall.roofAttach.auto") },
|
||||
{ value: "on", label: t("objinfo.wall.roofAttach.on") },
|
||||
{ value: "off", label: t("objinfo.wall.roofAttach.off") },
|
||||
]}
|
||||
title={t("objinfo.wall.roofAttach.tip")}
|
||||
width={120}
|
||||
/>
|
||||
</div>
|
||||
<BuildingFlags isExternal={wall.isExternal} loadBearing={wall.loadBearing} host={host} />
|
||||
|
||||
{/* Aufbau-Typ-Segment. */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.wall.buildup")}</span>
|
||||
<div className="objinfo-segment">
|
||||
<button
|
||||
type="button"
|
||||
className={"objinfo-seg-btn" + (isSingle ? " active" : "")}
|
||||
onClick={chooseSingle}
|
||||
>
|
||||
{t("objinfo.wall.single")}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={"objinfo-seg-btn" + (!isSingle ? " active" : "")}
|
||||
onClick={chooseMulti}
|
||||
disabled={isSingle && multiPresets.length === 0}
|
||||
>
|
||||
{t("objinfo.wall.multi")}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Einschichtig → Dicke-Zahlfeld. Mehrschichtig → Preset-Dropdown. */}
|
||||
{isSingle ? (
|
||||
<DimensionField
|
||||
label={t("objinfo.wall.thickness")}
|
||||
value={wall.thickness}
|
||||
onCommit={(v) => host.onSetWallThickness(v)}
|
||||
/>
|
||||
) : (
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.wall.preset")}</span>
|
||||
<Dropdown
|
||||
value={wall.wallTypeId}
|
||||
onChange={(id) => host.onSetWallType(id)}
|
||||
options={wall.wallTypes.map((wt) => ({
|
||||
value: wt.id,
|
||||
label: wt.label,
|
||||
title: wt.name,
|
||||
}))}
|
||||
title={t("objinfo.wall.preset")}
|
||||
width={150}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Referenzgeschoss (read-only Anzeige). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.wall.refFloor")}</span>
|
||||
<span className="objinfo-fval">{wall.floorName}</span>
|
||||
</div>
|
||||
<UValueRow project={storeProject} kind="wall" typeId={wall.wallTypeId} />
|
||||
|
||||
{/* Länge + Volumen (read-only). Volumen ist NETTO — Fenster/Türen
|
||||
abgezogen; der Titel zeigt zusätzlich das Bruttovolumen. */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.wall.length")}</span>
|
||||
<span className="objinfo-fval">{formatM(wall.length)}</span>
|
||||
</div>
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.volume")}</span>
|
||||
<span
|
||||
className="objinfo-fval"
|
||||
title={
|
||||
wall.openingVolume > 0
|
||||
? `${t("objinfo.wall.volumeGross")}: ${wall.grossVolume.toFixed(2)} m³ − ${wall.openingVolume.toFixed(2)} m³`
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
{wall.netVolume.toFixed(2)} m³
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Verknüpfung zum oberen Geschoss: OK an nächstes Geschoss binden. */}
|
||||
<label className="objinfo-field objinfo-check-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.wall.linkAbove")}</span>
|
||||
<input
|
||||
type="checkbox"
|
||||
className="objinfo-check"
|
||||
checked={wall.top?.mode === "floor"}
|
||||
disabled={!wall.floorAbove}
|
||||
title={
|
||||
wall.floorAbove
|
||||
? wall.floorAbove.name
|
||||
: t("objinfo.wall.floorAboveNone")
|
||||
}
|
||||
onChange={(e) => {
|
||||
if (e.target.checked && wall.floorAbove) {
|
||||
host.onSetWallTop({ mode: "floor", floorId: wall.floorAbove.id });
|
||||
} else {
|
||||
host.onSetWallTop(null);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
|
||||
<div className="objinfo-sep" />
|
||||
|
||||
{/* OK & UK getrennt: je „an Geschoss gebunden" ODER „eigene Höhe". OK
|
||||
(oben) steht oben, UK (unten) darunter — räumlich passend (Nutzer). */}
|
||||
<VerticalAnchorRow
|
||||
label={t("objinfo.wall.top")}
|
||||
anchor={wall.top}
|
||||
defaultZ={wall.zTop}
|
||||
floors={wall.floors}
|
||||
defaultFloorId={wall.floorAbove?.id ?? wall.floorId}
|
||||
onChange={(a) => host.onSetWallTop(a)}
|
||||
/>
|
||||
<VerticalAnchorRow
|
||||
label={t("objinfo.wall.bottom")}
|
||||
anchor={wall.bottom}
|
||||
defaultZ={wall.zBottom}
|
||||
floors={wall.floors}
|
||||
defaultFloorId={wall.floorId}
|
||||
onChange={(a) => host.onSetWallBottom(a)}
|
||||
/>
|
||||
|
||||
{/* Höhe = OK − UK (abgeleitet, read-only). */}
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.wall.height")}</span>
|
||||
<span className="objinfo-fval">{formatM(wall.zTop - wall.zBottom)}</span>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
// Gemeinsame Eingabefelder der Objekt-Info ([165] aus `ObjectInfoPanel.tsx`): Mass-Feld mit Anzeige-Einheit,
|
||||
// Drehfeld, Zeile für den vertikalen Anker und die Bauteil-Schalter (aussen, tragend). Gerufen von den
|
||||
// Abschnitten in diesem Ordner und von `ObjectInfoPanel.tsx`.
|
||||
|
||||
import { usePanelHost } from "../host";
|
||||
import { t } from "../../i18n";
|
||||
import type { VerticalAnchor } from "../../model/types";
|
||||
import { Dropdown } from "../../ui/Dropdown";
|
||||
import { useState, useRef } from "react";
|
||||
|
||||
// ── Decken-Attribut-Abschnitt ────────────────────────────────────────────────
|
||||
// Aufbau-Typ (einschichtig/mehrschichtig), Dicke/Preset, Referenzgeschoss +
|
||||
// OK-Bindung, Fläche. Alle Werte/Setter über den Host.
|
||||
/** Aussenbauteil / tragend ([97]/[98]): wirken auf Bauteil-/Öffnungslisten und das IFC-Pset. */
|
||||
export function BuildingFlags({ isExternal, loadBearing, host }: { isExternal: boolean; loadBearing: boolean; host: ReturnType<typeof usePanelHost> }) {
|
||||
return (
|
||||
<>
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.isExternal")}</span>
|
||||
<input type="checkbox" data-testid="objinfo-isExternal" checked={isExternal} onChange={(e) => host.onSetBuildingFlags({ isExternal: e.target.checked })} />
|
||||
</div>
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.loadBearing")}</span>
|
||||
<input type="checkbox" data-testid="objinfo-loadBearing" checked={loadBearing} onChange={(e) => host.onSetBuildingFlags({ loadBearing: e.target.checked })} />
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// ── UK/OK-Zeile: Modus-Umschalter (Geschoss/eigene Höhe) + Feld ──────────────
|
||||
// „Geschoss gebunden" → Geschoss-Dropdown; „eigene Höhe" → absolutes Z-Feld.
|
||||
// `null`-Anchor (undefined im Modell) = Geschoss-Default; zeigt „eigene Höhe"
|
||||
// mit dem aufgelösten Default-Z als Ausgangswert NICHT — Default ist
|
||||
// „an Geschoss gebunden" (Geschoss-Default-Verhalten).
|
||||
export function VerticalAnchorRow({
|
||||
label,
|
||||
anchor,
|
||||
defaultZ,
|
||||
floors,
|
||||
defaultFloorId,
|
||||
onChange,
|
||||
}: {
|
||||
label: string;
|
||||
anchor?: VerticalAnchor;
|
||||
defaultZ: number;
|
||||
floors: { id: string; name: string }[];
|
||||
defaultFloorId: string;
|
||||
onChange: (a: VerticalAnchor | null) => void;
|
||||
}) {
|
||||
const mode: "floor" | "custom" = anchor?.mode === "custom" ? "custom" : "floor";
|
||||
|
||||
function setMode(next: "floor" | "custom") {
|
||||
if (next === mode) return;
|
||||
if (next === "custom") {
|
||||
onChange({ mode: "custom", z: defaultZ });
|
||||
} else {
|
||||
// Zurück auf Geschoss-Bindung: bei vorhandenem expliziten Geschoss dieses,
|
||||
// sonst Default-Geschoss → entspricht dem Geschoss-Default-Verhalten.
|
||||
onChange({ mode: "floor", floorId: defaultFloorId });
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="objinfo-wall-anchor">
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{label}</span>
|
||||
<div className="objinfo-segment">
|
||||
<button
|
||||
type="button"
|
||||
className={"objinfo-seg-btn" + (mode === "floor" ? " active" : "")}
|
||||
onClick={() => setMode("floor")}
|
||||
>
|
||||
{t("objinfo.wall.anchorFloor")}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={"objinfo-seg-btn" + (mode === "custom" ? " active" : "")}
|
||||
onClick={() => setMode("custom")}
|
||||
>
|
||||
{t("objinfo.wall.anchorCustom")}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{/* Unterzeile in normaler Label-/Wert-Struktur: Label links, Control in
|
||||
der Wert-Spalte (Nutzer-Wunsch — vorher hing das Control ohne Label
|
||||
im Einzug der linken Spalte). */}
|
||||
{mode === "floor" ? (
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.anchor.refFloor")}</span>
|
||||
<Dropdown
|
||||
value={anchor?.mode === "floor" ? anchor.floorId : defaultFloorId}
|
||||
onChange={(id) => onChange({ mode: "floor", floorId: id })}
|
||||
options={floors.map((f) => ({ value: f.id, label: f.name }))}
|
||||
title={t("objinfo.anchor.refFloor")}
|
||||
width={150}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<DimensionField
|
||||
label={t("objinfo.anchor.customHeight")}
|
||||
value={anchor?.mode === "custom" ? anchor.z : defaultZ}
|
||||
min={-Infinity}
|
||||
onCommit={(z) => onChange({ mode: "custom", z })}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
export function DimensionField({
|
||||
label,
|
||||
value,
|
||||
onCommit,
|
||||
min = 0,
|
||||
unit = "m",
|
||||
step = 0.01,
|
||||
digits = 3,
|
||||
}: {
|
||||
label: string;
|
||||
value: number;
|
||||
onCommit: (v: number) => void;
|
||||
min?: number;
|
||||
unit?: string;
|
||||
step?: number;
|
||||
/** Nachkommastellen der Anzeige (Papier-mm: 1). */
|
||||
digits?: number;
|
||||
}) {
|
||||
// Entwurf als String, damit Zwischenzustände (leer, „1.") tippbar sind.
|
||||
// `null` = kein aktiver Entwurf → zeige den Host-Wert.
|
||||
const [draft, setDraft] = useState<string | null>(null);
|
||||
// Enter committet und nimmt danach den Fokus — das `blur` im selben Handler sieht noch den alten
|
||||
// Entwurf (State noch nicht neu gerendert) und committete ein zweites Mal (X/Y: doppelte Verschiebung).
|
||||
const pending = useRef<string | null>(null);
|
||||
pending.current = draft;
|
||||
|
||||
const shown = draft ?? (Object.is(Number(value.toFixed(digits)), -0) ? 0 : value).toFixed(digits);
|
||||
|
||||
function commit() {
|
||||
const d = pending.current;
|
||||
if (d === null) return;
|
||||
pending.current = null;
|
||||
const v = Number(d);
|
||||
setDraft(null);
|
||||
if (isFinite(v) && v >= min) onCommit(v);
|
||||
}
|
||||
|
||||
return (
|
||||
<label className="objinfo-field">
|
||||
<span className="objinfo-flabel">{label}</span>
|
||||
<input
|
||||
className="objinfo-input"
|
||||
type="number"
|
||||
step={step}
|
||||
min={isFinite(min) ? min : undefined}
|
||||
value={shown}
|
||||
onChange={(e) => setDraft(e.target.value)}
|
||||
onBlur={commit}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter") {
|
||||
commit();
|
||||
(e.target as HTMLInputElement).blur();
|
||||
} else if (e.key === "Escape") {
|
||||
setDraft(null);
|
||||
(e.target as HTMLInputElement).blur();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<span className="objinfo-unit">{unit}</span>
|
||||
</label>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// ── Dreh-Feld (Delta-Winkel in Grad) ─────────────────────────────────────────
|
||||
// Anders als DimensionField zeigt dieses Feld KEINEN persistenten Host-Wert —
|
||||
// eine „aktuelle Rotation" gibt es für die Selektion generell nicht (Wand ist
|
||||
// nur eine Achse, Drawing2D/Extrusion tragen keinen Rotationswinkel). Das Feld
|
||||
// ist daher ein Delta: Eingabe = Drehung ab jetzt, danach zeigt es wieder „0".
|
||||
export function RotateField({ onCommit }: { onCommit: (deg: number) => void }) {
|
||||
const [draft, setDraft] = useState<string | null>(null);
|
||||
const shown = draft ?? "0";
|
||||
|
||||
function commit() {
|
||||
if (draft === null) return;
|
||||
const v = Number(draft);
|
||||
setDraft(null);
|
||||
if (isFinite(v) && v !== 0) onCommit(v);
|
||||
}
|
||||
|
||||
return (
|
||||
<label className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.rotate")}</span>
|
||||
<input
|
||||
className="objinfo-input"
|
||||
type="number"
|
||||
step={1}
|
||||
value={shown}
|
||||
onChange={(e) => setDraft(e.target.value)}
|
||||
onBlur={commit}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter") {
|
||||
commit();
|
||||
(e.target as HTMLInputElement).blur();
|
||||
} else if (e.key === "Escape") {
|
||||
setDraft(null);
|
||||
(e.target as HTMLInputElement).blur();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<span className="objinfo-unit">°</span>
|
||||
</label>
|
||||
);
|
||||
}
|
||||
+12
-1
@@ -15,7 +15,7 @@ Grundriss auf den Bildschirm kommt: `doc/ARCHITEKTUR.md`, Abschnitt 3.4.
|
||||
|
||||
| Datei | Inhalt |
|
||||
|---|---|
|
||||
| `plan/PlanView.tsx` | die Plan-Ansicht: Kamera, Picken, Marquee, Werkzeug-Eingaben. Legt über die GPU-Fläche eine SVG-Ebene für Auswahl, Griffe, Fang und Text; ohne GPU-Weg zeichnet diese Ebene den ganzen Plan (`?gl=0`) |
|
||||
| `plan/PlanView.tsx` | die Plan-Ansicht: Props, Zustand, Aufruf der Hooks aus `planView/` in fester Reihenfolge und die SVG-Ebene. Legt über die GPU-Fläche eine SVG-Ebene für Auswahl, Griffe, Fang und Text; ohne GPU-Weg zeichnet diese Ebene den ganzen Plan (`?gl=0`) |
|
||||
| `plan/useWasmPlanRenderer.ts` | Hook für render2d als WASM/WebGPU (Browser, Electron): verbindet Canvas, Plan und Ausschnitt mit der Renderer-Sitzung |
|
||||
| `plan/wasmRendererSession.ts` | Besitzer des WASM-Renderers eines Canvas: der eine Ort, der render2d aufruft (Bild, Grösse, Verlust des GPU-Geräts) |
|
||||
| `plan/useNativePlanRenderer.ts` | Hook für den nativen Metal-Weg auf macOS (Tauri); dieselbe Schnittstelle, die Pixel entstehen in einer Fläche unter der Webansicht |
|
||||
@@ -38,5 +38,16 @@ Massstab als Props bekommt.
|
||||
| `planView/liveMeet.tsx` | bildschirmkonstanter Massstab für Überlagerungen während einer Pan-/Zoom-Geste |
|
||||
| `planView/gripCull.ts` | welche Griffe bei sehr vielen Stützpunkten gezeichnet werden (nur im Ausschnitt) |
|
||||
| `planView/PlanGrid.tsx`, `planView/PlanRulers.tsx` | sichtbares Raster und Lineale am Rand |
|
||||
| `planView/types.ts`, `planView/constants.ts` | öffentliche Typen (`PlanSelection`, `PlanViewProps`, `GripHandlers` …) und Konstanten (Zoom-Grenzen, Treffer-Toleranzen, Culling) |
|
||||
| `planView/usePlanEngine.ts` | Renderer-Anbindung: Pick-Index, Engine-Wahl (nativ, WASM, SVG), aufbereiteter Plan, Culling, Papier-Massstab, GL-Effekte |
|
||||
| `planView/usePlanCoords.ts` | Steuerhandle (`useImperativeHandle`), Zieh-Zustände, Umrechnung Bildschirm ↔ Ansicht ↔ Modell, Griff-Treffer |
|
||||
| `planView/usePlanPicking.ts` | Treffer-Abfragen (Bauteile, 2D-Elemente, Lage, Bäume), Hover-Teilpunkte, gegriffener Körper |
|
||||
| `planView/usePlanPointer.ts` | `onPointerDown`/`onPointerMove`, imperativer Pan, Drosselung der Drags, Standard-Auswahl |
|
||||
| `planView/usePlanPickCycle.ts` | Durchschalten übereinanderliegender Objekte (Liste, Zyklus) und `endDrag` (Pointer-Up) |
|
||||
| `planView/usePlanZoomInput.ts` | Rad-Zoom, Doppelklick, Kontextmenü |
|
||||
| `planView/usePlanHighlights.ts` | Hervorhebung der Auswahl und des Hover-Treffers |
|
||||
|
||||
Die Hooks sind aus dem Körper von `PlanView` herausgelöst (`[165]`): jeder bekommt die Werte, die er liest, als ein
|
||||
Objekt und gibt zurück, was `PlanView` danach braucht; die Reihenfolge der Aufrufe ist die der Effekte.
|
||||
|
||||
Picken, Culling, Marquee und Massstab-Helfer ohne React liegen in `src/plan/planView/`.
|
||||
+372
-2869
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,100 @@
|
||||
// Konstanten und kleine Hilfen der Plan-Ansicht (`PlanView.tsx`): Culling-Schwellen, Zoom-Grenzen,
|
||||
// Treffer-Toleranzen, Pick-Reihenfolge. [165] aus `PlanView.tsx` herausgelöst; gerufen von
|
||||
// `PlanView.tsx` und den Hooks in `planView/`.
|
||||
|
||||
import type { PickKind } from "../../../core";
|
||||
import { expandRegion, regionContains, type Bounds } from "../../../core";
|
||||
import type { ViewBox__plan_planView_geometry as ViewBox } from "../../../core";
|
||||
import type { PickIds } from "./types";
|
||||
|
||||
// Viewport-Culling (s. `cullPrimitives.ts`): erst ab dieser Primitiv-Anzahl
|
||||
// aktiv — normale Projekte liegen weit darunter und bleiben unverändert.
|
||||
export const CULL_THRESHOLD = 5000;
|
||||
// Puffer um `view` als Vielfaches der View-Grösse je Seite (50 % → ein
|
||||
// Schwenk muss schon über die halbe Bildschirmbreite hinausgehen, bevor neu
|
||||
// gerechnet wird).
|
||||
export const CULL_MARGIN_FACTOR = 0.5;
|
||||
export const cullMargin = (vb: ViewBox) => Math.max(vb.w, vb.h) * CULL_MARGIN_FACTOR;
|
||||
// Text-Primitive unter dieser Höhe (als Anteil der aktuellen View-Höhe)
|
||||
// gelten als unleserlich und werden gar nicht erst gerendert (s.
|
||||
// `isTooSmallToRead` in cullPrimitives.ts) — unabhängig von der Position.
|
||||
// 0.5 % einer typischen Bildschirmhöhe (~800 px) sind ~4 px, die Schwelle,
|
||||
// ab der Text praktisch ohnehin nicht mehr lesbar ist.
|
||||
export const MIN_RELATIVE_TEXT_HEIGHT = 0.002;
|
||||
// Reingezoomt seit der letzten Neuberechnung (View < 75 % der Grösse, für die
|
||||
// die Lesbarkeits-Schwelle berechnet wurde) → neu rechnen, auch wenn `view`
|
||||
// noch in der gepufferten Region liegt — sonst bliebe die Schwelle (an der
|
||||
// ALTEN, grösseren View-Höhe bemessen) zu streng und Text, der beim aktuellen
|
||||
// Zoom längst lesbar wäre, bliebe unsichtbar. Früher 30 %: da lief das Culling
|
||||
// noch über ALLE Primitive (Mio. bei Kataster-Importen) und durfte selten
|
||||
// laufen; seit `svgCandidates` filtert es nur noch die SVG-Elemente (Texte,
|
||||
// ~10^4–10^5) und ist billig — bei 30 % blieben Beschriftungen beim Reinzoomen
|
||||
// bis zu 3,3× zu lange ausgeblendet.
|
||||
export const CULL_RESCALE_FACTOR = 0.75;
|
||||
|
||||
export interface CullState {
|
||||
region: Bounds;
|
||||
minTextHeightVb: number;
|
||||
forViewW: number;
|
||||
forViewH: number;
|
||||
}
|
||||
export function computeCullState(view: ViewBox): CullState {
|
||||
return {
|
||||
region: expandRegion(view, cullMargin(view)),
|
||||
minTextHeightVb: view.h * MIN_RELATIVE_TEXT_HEIGHT,
|
||||
forViewW: view.w,
|
||||
forViewH: view.h,
|
||||
};
|
||||
}
|
||||
export function cullStateStale(s: CullState, view: ViewBox): boolean {
|
||||
if (!regionContains(s.region, view)) return true;
|
||||
return view.w < s.forViewW * CULL_RESCALE_FACTOR || view.h < s.forViewH * CULL_RESCALE_FACTOR;
|
||||
}
|
||||
|
||||
// Zoom-Grenzen relativ zur eingepassten Default-Ansicht. Kleinere viewBox-
|
||||
// Breite = stärkerer Zoom. ZOOM_MAX → max. Hineinzoomen, ZOOM_MIN → Herauszoomen.
|
||||
// Grosszügig bemessen (CAD-Anspruch: vom Milimeter-Detail bis zum Siedlungs-
|
||||
// Kontext) statt der früheren 250×-Spanne (50/0.2), die für Detailarbeit an
|
||||
// einem Gebäude deutlich zu eng war.
|
||||
export const ZOOM_MAX = 20000; // bis 20 000× hinein (Sub-Millimeter-Details)
|
||||
export const ZOOM_MIN = 0.005; // bis 200× heraus (Siedlungs-/Site-Kontext)
|
||||
export const WHEEL_STEP = 0.001; // Empfindlichkeit des Mausrads
|
||||
export const WHEEL_MAX_DELTA = 100; // grosse Rad-/Trackpad-Ausschläge pro Ereignis begrenzen
|
||||
|
||||
// Schwelle (Bildschirm-Pixel), ab der ein Links-Ziehen als Marquee gilt; darunter
|
||||
// bleibt es ein Klick (Einzelwahl). Verhindert versehentliche Mini-Rechtecke.
|
||||
export const MARQUEE_THRESHOLD_PX = 4;
|
||||
|
||||
// Trefferradius (Bildschirm-Pixel) für das Greifen eines Editier-Griffs.
|
||||
export const GRIP_HIT_PX = 9;
|
||||
// Toleranz (Bildschirm-Pixel) für die Linien-Auswahl von 2D-Zeichenelementen.
|
||||
export const LINE_PICK_PX = 6;
|
||||
|
||||
export const PICK_ORDER: readonly PickKind[] = [
|
||||
"section", "opening", "wall", "column", "drawing", "solid", "tree",
|
||||
"ceiling", "stair", "room", "roof", "site", "context",
|
||||
];
|
||||
|
||||
export 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,
|
||||
siteId: null,
|
||||
treeId: null,
|
||||
};
|
||||
|
||||
/** Mac: Cmd+Klick; sonst Strg+Klick (Alt+Klick ist die Schere, Ctrl+Klick unter macOS das Kontextmenü). */
|
||||
/** [149] Präfix der Baum-Pick-Id im Feld `contextObjectId` (Kern `tree::TREE_PICK_PREFIX`). */
|
||||
export const TREE_PICK = "@tree:";
|
||||
|
||||
export const IS_MAC = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform);
|
||||
export const cycleModifier = (e: { metaKey: boolean; ctrlKey: boolean }): boolean => (IS_MAC ? e.metaKey : e.ctrlKey);
|
||||
@@ -0,0 +1,465 @@
|
||||
// Typen der Plan-Ansicht (`PlanView.tsx`): Auswahl-Ergebnisse, Eigenschaften, Steuerhandle und
|
||||
// Griff-Treiber. [165] aus `PlanView.tsx` herausgelöst; `PlanView.tsx` führt die öffentlichen Typen
|
||||
// unverändert wieder aus, die übrigen Dateien in `planView/` importieren sie von hier.
|
||||
|
||||
import type { ReactNode } from "react";
|
||||
import type { HatchRender, Plan, PickKind } from "../../../core";
|
||||
import type { EdgeGrip, Vec2 } from "../../../model/types";
|
||||
import type { ToolHandlers, ToolId, ToolMods } from "../../../tools/types";
|
||||
import type { HudFieldsState } from "../../../tools/hudFormat";
|
||||
import type { RichTextDoc } from "../../../text/richText";
|
||||
import type { DisplayUnits } from "../../../tools/displayUnits";
|
||||
import type { Selection } from "../../../state/selection";
|
||||
|
||||
/** Ein Polygon mit Schraffur + die ihm zugewiesene <pattern>-ID. */
|
||||
export interface HatchedPoly {
|
||||
patternId: string;
|
||||
hatch: HatchRender;
|
||||
}
|
||||
|
||||
/**
|
||||
* Imperatives Steuerhandle der Plan-Ansicht für die Oberleiste (Zoom-Buttons).
|
||||
* Die Ansicht behält Pan/Zoom intern; das Handle löst nur die fest definierten
|
||||
* Sprünge aus, ohne den sonstigen Zustand zu berühren.
|
||||
*/
|
||||
export interface PlanViewHandle {
|
||||
/** Auf die eingepasste Standard-Ansicht zurücksetzen (Einpassen). */
|
||||
fit: () => void;
|
||||
/**
|
||||
* Auf die aktuelle Auswahl einpassen (lokal hervorgehobenes Polygon); gibt es
|
||||
* keine Auswahl, verhält es sich wie „Einpassen".
|
||||
*/
|
||||
fitSelection: () => void;
|
||||
/**
|
||||
* Den Zoom so setzen, dass das Modell im PAPIER-Massstab 1:N abgebildet wird
|
||||
* (siehe docs/design/plans-output.md §3). Hält die aktuelle Bildmitte. Wird
|
||||
* von der Oberleiste benutzt (Massstab-Preset wählen, „100 %").
|
||||
*/
|
||||
applyScale: (n: number) => void;
|
||||
/** Aktuelle Pixel/Meter-Skala (für Snap-Toleranz der Command-Engine). */
|
||||
pxPerMeter: () => number;
|
||||
/** Mitte des aktuellen Ausschnitts in Modell-Metern (z. B. für Import-Platzierung). */
|
||||
viewCenterModel: () => Vec2;
|
||||
/**
|
||||
* Setzt die Bildmitte + den Zoom (Bildschirm-px je Meter) direkt — Gegenstück
|
||||
* zu `viewCenterModel`/`pxPerMeter` (Auslesen). Für „gespeicherter Ausschnitt
|
||||
* wiederherstellen": stellt WOHIN man schaut wieder her, nicht nur WAS
|
||||
* sichtbar ist. No-op ohne Messung (SVG noch nicht gemountet).
|
||||
*/
|
||||
setCamera: (center: Vec2, pxPerMeter: number) => void;
|
||||
/**
|
||||
* Auf eine beliebige Punktmenge (Modell-Meter) einpassen, z. B. die Bounding-
|
||||
* Box neu importierter Kontext-Objekte (Auto-Zoom nach Geo-/DXF-Import).
|
||||
* Leere Punktmenge → No-op (kein Fit, kein Crash).
|
||||
*/
|
||||
fitBounds: (pts: Vec2[]) => void;
|
||||
/**
|
||||
* Einen bewaffneten Punkt-Griff (s. gripDrag) an seiner AKTUELLEN Position
|
||||
* abschließen — dieselbe Aktion wie ein bestätigender Klick/Enter auf der
|
||||
* Zeichenfläche, aber von der Befehlszeile aus angestoßen (Enter dort MIT
|
||||
* leerem Eingabetext: kein neuer Wert zu locken, nur „fertig, so lassen").
|
||||
* No-op ohne bewaffneten Griff.
|
||||
*/
|
||||
confirmGripEdit: () => void;
|
||||
/** Dasselbe für einen bewaffneten Kanten-Griff (s. edgeDrag). */
|
||||
confirmEdgeEdit: () => void;
|
||||
}
|
||||
|
||||
/** 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`. */
|
||||
export type PickIds = Omit<PlanSelection, "model" | "shift" | "replaces">;
|
||||
|
||||
/** Ergebnis eines Links-Klicks (Auswahl) an einer Modellposition. */
|
||||
export interface PlanSelection {
|
||||
/** Klickposition in Modell-Metern. */
|
||||
model: Vec2;
|
||||
/** Index des getroffenen Polygon-Primitivs, oder `null` (Leerraum). */
|
||||
hitIndex: number | null;
|
||||
/**
|
||||
* ID der getroffenen Wand (aus dem Polygon-Primitiv), oder `null`, wenn der
|
||||
* Klick keine Wand traf (Leerraum bzw. ein Polygon ohne Wandbezug). Damit
|
||||
* setzt der Aufrufer (App) die Auswahl auf genau diese Wand (bzw. leert sie).
|
||||
*/
|
||||
wallId: string | null;
|
||||
/**
|
||||
* ID des getroffenen 2D-Zeichenelements (Drawing2D), wenn der Klick nahe an
|
||||
* dessen Linien lag und KEINE Wand getroffen wurde; sonst `null`.
|
||||
*/
|
||||
drawingId: string | null;
|
||||
/**
|
||||
* ID der getroffenen Decke (aus dem Polygon-Primitiv), wenn der Klick eine
|
||||
* Decken-Fläche traf und KEINE Wand/kein 2D-Element; sonst `null`.
|
||||
*/
|
||||
ceilingId: string | null;
|
||||
/**
|
||||
* ID der getroffenen Öffnung (Fenster/Tür), wenn der Klick nahe an ihrem Symbol
|
||||
* (Türblatt/Schwenkbogen/Fenster-Glaslinie/-Rahmen) lag und KEINE Wand/kein
|
||||
* 2D-Element/keine Decke getroffen wurde; sonst `null`.
|
||||
*/
|
||||
openingId: string | null;
|
||||
/**
|
||||
* ID der getroffenen Treppe (aus einem Tritt-/Podest-Polygon), wenn der Klick
|
||||
* eine Treppe traf und KEINE Wand/kein 2D-Element/keine Decke/keine Öffnung;
|
||||
* sonst `null`.
|
||||
*/
|
||||
stairId: string | null;
|
||||
/**
|
||||
* ID des getroffenen Raums (aus einer Raum-Fläche), wenn der Klick einen Raum
|
||||
* traf und KEIN Element höherer Priorität (Wand/2D/Decke/Öffnung/Treppe);
|
||||
* sonst `null`.
|
||||
*/
|
||||
roomId: string | null;
|
||||
/**
|
||||
* ID des getroffenen extrudierten Körpers (truck-Integration, Footprint-
|
||||
* Umriss), wenn der Klick ihn traf und KEIN Element höherer Priorität
|
||||
* (Wand/2D/Decke/Öffnung/Treppe); sonst `null`.
|
||||
*/
|
||||
extrudedSolidId: string | null;
|
||||
/**
|
||||
* ID der getroffenen Stütze (Column, Grundriss-Querschnitt), wenn der Klick sie
|
||||
* traf und KEIN Element höherer Priorität (Öffnung/Wand); sonst `null`.
|
||||
*/
|
||||
columnId: string | null;
|
||||
/**
|
||||
* ID des getroffenen Dachs (Traufe-Fläche), wenn der Klick es traf und KEIN
|
||||
* Element höherer Priorität (alle anderen gehen vor); sonst `null`.
|
||||
*/
|
||||
roofId: string | null;
|
||||
/**
|
||||
* ID der getroffenen Schnitt-/Ansichtslinie (DrawingLevel), wenn der Klick ihr
|
||||
* dünnes Pick-Band traf; sonst `null`. Höchste Priorität (das schmale Band liegt
|
||||
* über allem — ein Klick genau darauf meint die Linie).
|
||||
*/
|
||||
sectionLineId: string | null;
|
||||
/**
|
||||
* ID des getroffenen Kontext-Objekts (importiertes Gebäude/Terrain), wenn der
|
||||
* Klick sein Grundriss-Pick-Band traf und KEIN Element höherer Priorität
|
||||
* (alle anderen gehen vor, analog `roofId`); sonst `null`.
|
||||
*/
|
||||
contextObjectId: string | null;
|
||||
/**
|
||||
* [137] Getroffene Lage-Darstellung (Schattenfläche → `"sunStudy"`, Baurechtslinie → `"siteRules"`),
|
||||
* wenn kein Element höherer Priorität getroffen wurde; Vorrang vor Kontext-Objekten (sie liegt darüber).
|
||||
*/
|
||||
siteId?: string | null;
|
||||
/**
|
||||
* [149] Getroffener Baum (Kronenfläche, Pick-Id `@tree:<id>` im Feld `contextObjectId`), wenn keine
|
||||
* Öffnung/Wand/Stütze/2D-Element/Körper getroffen wurde; Vorrang vor Decke, Raum, Dach und Gelände.
|
||||
*/
|
||||
treeId?: string | null;
|
||||
/**
|
||||
* War beim Klick Shift gedrückt? Dann ERWEITERT der Aufrufer (App) die
|
||||
* Auswahl um das getroffene Element (bzw. schaltet es ab/zu), statt sie zu
|
||||
* ersetzen. Bei Leerraum-Klick mit Shift bleibt die Auswahl erhalten.
|
||||
*/
|
||||
shift: boolean;
|
||||
/**
|
||||
* Nur bei Shift + Durchschalten (Cmd/Strg+Shift-Klick wiederholt an derselben
|
||||
* Stelle): das im vorigen Schritt dazugewählte Objekt wird zuerst wieder
|
||||
* entfernt, damit nicht jede Zwischenstation in der Auswahl landet.
|
||||
*/
|
||||
replaces?: { kind: PickKind; id: string };
|
||||
}
|
||||
|
||||
/**
|
||||
* Ergebnis eines Auswahl-Rechtecks (Marquee). `wallIds` ist die nach der
|
||||
* CAD-Konvention bestimmte Menge getroffener Wände (siehe `crossing`). Der
|
||||
* Aufrufer (App) ersetzt die aktuelle Auswahl durch diese Menge.
|
||||
*/
|
||||
export interface MarqueeSelection {
|
||||
wallIds: string[];
|
||||
/** Getroffene 2D-Zeichenelemente (gleiche window/crossing-Konvention). */
|
||||
drawingIds: string[];
|
||||
/** Getroffene Decken/Räume/Treppen (gleiche window/crossing-Konvention). */
|
||||
ceilingIds: string[];
|
||||
roomIds: string[];
|
||||
stairIds: string[];
|
||||
/** [149] Getroffene Bäume (Kronenfläche, gleiche Konvention). */
|
||||
treeIds?: string[];
|
||||
/**
|
||||
* Zieh-Richtung: `false` = links→rechts (positiv Δx) → nur VOLLSTÄNDIG
|
||||
* eingeschlossene Wände; `true` = rechts→links (negativ Δx) → auch berührte/
|
||||
* kreuzende Wände (CAD-Konvention: „crossing window").
|
||||
*/
|
||||
crossing: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ein per Doppelklick getroffenes, potenziell gruppiertes Element — genau
|
||||
* EIN Feld gesetzt (analog `PlanSelection`, aber ohne die Klick-spezifischen
|
||||
* Felder). Für Gruppen-Eintritt (`onEnterGroup`); Formen ohne eigenes
|
||||
* Polygon-Primitiv (z. B. reine Linien-2D-Elemente) werden hier nicht
|
||||
* erkannt (kleine, bewusste Vereinfachung — s. `anyGroupableHit`).
|
||||
*/
|
||||
export interface GroupableHit {
|
||||
wallId?: string;
|
||||
drawingId?: string;
|
||||
ceilingId?: string;
|
||||
roomId?: string;
|
||||
stairId?: string;
|
||||
columnId?: string;
|
||||
roofId?: string;
|
||||
}
|
||||
|
||||
export interface PlanViewProps {
|
||||
plan: Plan;
|
||||
/**
|
||||
* Stabiler Schlüssel des Plan-Kontexts (z. B. Geschoss-/Ebenen-ID). Der
|
||||
* sichtbare Ausschnitt wird NUR auf „eingepasst" zurückgesetzt, wenn sich
|
||||
* dieser Schlüssel ändert (Plan-/Geschoss-Wechsel) — NICHT bei jeder Modell-/
|
||||
* Bounds-Änderung durch Editieren. So „wandert" die Ansicht beim Verschieben/
|
||||
* Löschen nicht mehr mit; sie ändert sich nur durch manuelles Pan/Zoom/
|
||||
* Einpassen. Fehlt der Schlüssel, bleibt der Ausschnitt nach dem ersten
|
||||
* Einpassen stehen (kein Auto-Reset).
|
||||
*/
|
||||
resetKey?: string;
|
||||
/**
|
||||
* Meldet die Cursor-Position in Modell-Koordinaten (Meter) nach oben, bzw.
|
||||
* `null`, wenn der Zeiger die Fläche verlässt. Optional — ohne Callback
|
||||
* verhält sich die Ansicht wie zuvor.
|
||||
*/
|
||||
onCursor?: (model: Vec2 | null) => void;
|
||||
/**
|
||||
* Meldet den LIVE Papier-Massstab als Nenner N (1:N), berechnet aus dem
|
||||
* aktuellen Ausschnitt + Canvas-Größe + dpi (docs/design/plans-output.md §3).
|
||||
* Aktualisiert sich beim Wheel-Zoom/Pan/Resize. Optional.
|
||||
*/
|
||||
onScale?: (n: number) => void;
|
||||
/**
|
||||
* Links-Klick (Auswahl): meldet die getroffene Wand (bzw. `hitIndex: null`
|
||||
* bei Klick in den Leerraum → Auswahl löschen). Optional. Die Ansicht
|
||||
* markiert das getroffene Polygon zusätzlich selbst (lokale Hervorhebung).
|
||||
*/
|
||||
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-
|
||||
* gelegene Kante und entfernt sie. Optional. Nur ausgelöst, wenn ein 2D-Element
|
||||
* unter dem Cursor liegt (sonst no-op).
|
||||
*/
|
||||
onSegmentCut?: (drawingId: string, model: Vec2) => void;
|
||||
/**
|
||||
* Die Auswahl (kontrolliert von App, [130]). Die Ansicht markiert ALLE Primitive
|
||||
* JEDES gewählten Elements mit einer Akzentkontur (Wände: alle Bänder; Dach: die
|
||||
* Traufe; Kontext-Objekte/Schnittlinien: das Pick-Band). Gewählte GRUPPEN zeigen
|
||||
* statt der Mitglieds-Umrisse nur eine Bounding-Box (s. `groupBBox`); die übrigen
|
||||
* Arten tragen weiterhin die volle Mitgliedschaft. Fehlt = nichts gewählt.
|
||||
*/
|
||||
selection?: Selection;
|
||||
/**
|
||||
* Der Stempel-Griff des (einzeln) gewählten Raums: sein Anker (Meter) + ID.
|
||||
* PlanView zeichnet einen ziehbaren Griff und meldet Bewegung/Doppelklick.
|
||||
* `null` = kein einzelner Raum gewählt.
|
||||
*/
|
||||
roomStamp?: { roomId: string; anchor: Vec2 } | null;
|
||||
/** Der Stempel-Griff wurde verschoben (inkrementelles Modell-Delta). */
|
||||
/** `from`: gezeichnete Lage des Stempels (der Kern verschiebt ab ihr, solange der Raum keinen eigenen Anker hat). */
|
||||
onStampMove?: (roomId: string, delta: Vec2, from?: Vec2) => void;
|
||||
/** Doppelklick auf einen Raum-Stempel: Editor öffnen. */
|
||||
onStampEdit?: (roomId: string) => void;
|
||||
/** Doppelklick auf ein Text-2D-Element: Inhalt bearbeiten (Editor öffnen). */
|
||||
onEditDrawingText?: (drawingId: string) => void;
|
||||
/**
|
||||
* Doppelklick auf IRGENDEIN Element (Wand/2D/Decke/Raum/Treppe/Stütze/
|
||||
* Dach): meldet, welches Element getroffen wurde (genau EIN Feld gesetzt).
|
||||
* Der Aufrufer prüft, ob es zu einer Gruppe gehört (Vectorworks „Gruppe
|
||||
* betreten") und liefert `true`, wenn er die Gruppe betreten hat — dann
|
||||
* bricht `onDoubleClick` sofort ab, VOR allen anderen Doppelklick-Aktionen
|
||||
* (Gruppen-Eintritt hat Vorrang, wie in Vectorworks). `false`/kein Handler
|
||||
* → die übrigen Doppelklick-Prüfungen (Text/Raum-Stempel/Schnittlinie) laufen
|
||||
* normal weiter.
|
||||
*/
|
||||
onEnterGroup?: (hit: GroupableHit) => boolean;
|
||||
/**
|
||||
* Drawing2D-ID, deren Inhalt gerade inline auf der Zeichenfläche editiert
|
||||
* wird (frisch über `text`/`textbox` erzeugt ODER per Doppelklick auf ein
|
||||
* bestehendes Element geöffnet) — `null`/undefined = kein Inline-Editor
|
||||
* offen. PlanView rendert dafür einen `RichTextEditor`-Overlay direkt über
|
||||
* dem Element (kein Dialog), positioniert/skaliert über den aktuellen
|
||||
* Ausschnitt.
|
||||
*/
|
||||
editTextId?: string | null;
|
||||
/**
|
||||
* Mindesthöhe (Meter) des Inline-Editors, wenn `editTextId` aus einem
|
||||
* frisch aufgezogenen Textspalten-RAHMEN kommt (s. textbox.ts). `null`/
|
||||
* undefined = keine Mindesthöhe, der Inhalt bestimmt die Höhe allein.
|
||||
*/
|
||||
editTextMinHeightM?: number | null;
|
||||
/** Jede Änderung im Inline-Text-Editor (live, pro Tastendruck). */
|
||||
onCommitTextEdit?: (doc: RichTextDoc) => void;
|
||||
/** Inline-Text-Editor schliessen (Backdrop-Klick/Escape). */
|
||||
onCloseTextEdit?: () => void;
|
||||
/** Doppelklick auf eine Schnittlinie: in deren 2D-Schnittansicht springen
|
||||
* (Zeichnungsebene aktivieren). */
|
||||
onOpenSectionLevel?: (levelId: string) => void;
|
||||
/**
|
||||
* Links-Drag (Marquee): meldet die im Auswahl-Rechteck getroffenen Wände nach
|
||||
* der CAD-Konvention (siehe {@link MarqueeSelection}). Optional.
|
||||
*/
|
||||
onMarquee?: (selection: MarqueeSelection) => void;
|
||||
/**
|
||||
* Rechts-Klick: öffnet ein Kontextmenü an der Cursorposition. Erhält die
|
||||
* Viewport-Pixel (clientX/Y) plus den Modellpunkt. Optional. Das Standard-
|
||||
* Browser-Kontextmenü wird immer unterdrückt.
|
||||
*/
|
||||
onContextMenu?: (info: { clientX: number; clientY: number; model: Vec2 }) => void;
|
||||
/**
|
||||
* Aktives Zeichenwerkzeug. `"select"`/undefined = bisheriges Verhalten
|
||||
* (Auswahl/Marquee). Bei einem aktiven Zeichenwerkzeug übernimmt das Werkzeug
|
||||
* die linke Maustaste (Punkte setzen) statt der Auswahl; Pan/Zoom bleiben.
|
||||
*/
|
||||
activeTool?: ToolId;
|
||||
/**
|
||||
* Übernimmt ein Zeichenwerkzeug ODER eine Transformation die linke Maustaste?
|
||||
* Wird von App berechnet (Zeichenwerkzeug aktiv ODER laufende Transformation).
|
||||
* Fehlt der Wert, wird aus `activeTool` abgeleitet (Rückwärtskompatibilität).
|
||||
*/
|
||||
toolInputActive?: boolean;
|
||||
/**
|
||||
* Werkzeug-Treiber: PlanView meldet rohe Modellpunkte + Pixel/Meter hierher
|
||||
* und zeichnet den zurückgegebenen `draft` als Overlay (Vorschau + Snap-Marker).
|
||||
*/
|
||||
toolHandlers?: ToolHandlers;
|
||||
/** Lineale (oben + links, VW-Stil) einblenden. Default an. */
|
||||
showRulers?: boolean;
|
||||
/** Sichtbares Hintergrund-Raster (rein visuell, unabhängig vom Fang-Raster). Default aus. */
|
||||
showGrid?: boolean;
|
||||
/**
|
||||
* Feld-Status der Befehlszeile fürs Cursor-HUD (Tab-Feld-Zyklus §2.7):
|
||||
* gelockte/live Werte je Feld, aktives Tab-Ziel und der gerade getippte
|
||||
* Text. Das HUD spiegelt damit die Eingabe LIVE am Cursor (VW-Verhalten:
|
||||
* tippen → Wert erscheint oben im Kästchen UND unten im Befehl); ohne
|
||||
* Felder fällt es auf die draft.hud-Livewerte zurück.
|
||||
*/
|
||||
hudFields?: HudFieldsState | null;
|
||||
/**
|
||||
* Editier-Griffe (Grips) des aktuell EINZELN selektierten Elements, in Modell-
|
||||
* Metern (Wand-Enden, 2D-Vertices/Ecken). Werden als ziehbare Quadrate
|
||||
* gezeichnet; das Ziehen meldet sich über {@link gripHandlers}. Nur im
|
||||
* Auswahl-Werkzeug sichtbar/aktiv.
|
||||
*/
|
||||
grips?: Vec2[];
|
||||
/**
|
||||
* Bezier-Hilfslinien (Anker → Kontrollpunkt-Griff) des selektierten
|
||||
* Elements — gestrichelt gerendert, damit sichtbar bleibt, welcher Griff
|
||||
* welchen Kurvenabschnitt steuert (s. `useGripEditing.ts`).
|
||||
*/
|
||||
gripHandleLines?: { a: Vec2; b: Vec2 }[];
|
||||
/**
|
||||
* Kanten-/Seiten-Griffe (Edge Grips) des selektierten Elements: je Seite ein
|
||||
* dreieckiger Anfasser am Kanten-Mittelpunkt, dessen Spitze nach AUSSEN zeigt.
|
||||
* Ziehen meldet sich über {@link GripHandlers.onEdgeMove}. Nur sichtbar/aktiv,
|
||||
* wenn auch die Eckpunkt-Griffe aktiv sind.
|
||||
*/
|
||||
edgeGrips?: EdgeGrip[];
|
||||
/**
|
||||
* „Display"-Modus: alle Plan-Linien als konstante Haarlinie (1 px) zeichnen,
|
||||
* statt der echten mm-Strichstärken (Print). Reine Darstellung.
|
||||
*/
|
||||
hairline?: boolean;
|
||||
/** Griff-Zieh-Treiber: Live-Bewegung (gesnappt) + Abschluss. */
|
||||
gripHandlers?: GripHandlers;
|
||||
/**
|
||||
* Schnitt-/Ansichts-Blatt: zusätzlich gewählte Öffnungen und Decken per
|
||||
* Körper-Zug greifbar (die App überträgt das Blatt-Delta entlang der
|
||||
* Schnittlinie, s. useGripEditing `sheet`). Im Grundriss aus.
|
||||
*/
|
||||
sheetBodies?: boolean;
|
||||
/**
|
||||
* Farbe des Auswahlrahmens (Marquee-Ziehauswahl). Einstellbar im
|
||||
* Einstellungs-Fenster (State in ViewSlice); Default = Akzent „Yuyake".
|
||||
*/
|
||||
marqueeColor?: string;
|
||||
/**
|
||||
* Farbe der Snap-/Endpunkt-Hervorhebung (Werkzeug-Overlay). Einstellbar im
|
||||
* Einstellungs-Fenster (State in ViewSlice); Default = Akzent „Sora".
|
||||
*/
|
||||
snapColor?: string;
|
||||
/**
|
||||
* Ruht der Cursor (kein Werkzeug/Drag aktiv) länger als diese Zeit (ms) auf
|
||||
* einer 2D-Linie, erscheinen ihre Teilpunkte (s. `hoverDivideCount`) kurz
|
||||
* mit Akzentfarbe — reine Sichtbarkeits-Hilfe, kein Snap-Ziel. Einstellbar
|
||||
* im Footer (`SnapSettings.hoverDivideDelayMs`); Default 300 ms.
|
||||
*/
|
||||
hoverDivideDelayMs?: number;
|
||||
/**
|
||||
* In wie viele gleiche Teile die gehoverte Linie dabei angezeigt wird
|
||||
* (2 = nur der Mittelpunkt). Einstellbar im Footer
|
||||
* (`SnapSettings.hoverDivideCount`); Default 2.
|
||||
*/
|
||||
hoverDivideCount?: number;
|
||||
/**
|
||||
* Hintergrund unter der Zeichnung (z. B. das Layout-Blatt: Papier, Master, Viewports), gezeichnet
|
||||
* im SVG zwischen Raster und Geometrie. `origin` = Ursprung des Overlays (viewBox-Einheiten, s.
|
||||
* planView/overlayOrigin.ts), `pxPerMeter` = aktueller Zoom. Mit Hintergrund zeichnet der SVG-Pfad
|
||||
* (wie bei Luftbildern), damit er sichtbar bleibt.
|
||||
*/
|
||||
backdrop?: (origin: Vec2, pxPerMeter: number) => ReactNode;
|
||||
/** Anzeige-Einheiten von Linealen und HUD (Layout-Blatt: Papier-mm, y nach unten, [93]). */
|
||||
units?: DisplayUnits;
|
||||
/** Einpass-Bereich (Modell-Meter) statt der Plan-Grenzen — z. B. das Blatt. */
|
||||
fitBounds?: { minX: number; minY: number; maxX: number; maxY: number };
|
||||
}
|
||||
|
||||
/** Treiber für das Ziehen von Editier-Griffen (von App bereitgestellt). */
|
||||
/** Gegriffener Körper beim Parallel-Verschieben. */
|
||||
export interface BodyTarget {
|
||||
wallId?: string;
|
||||
drawingId?: string;
|
||||
/** Nur im Schnitt/in der Ansicht (`sheetBodies`). */
|
||||
openingId?: string;
|
||||
/** Nur im Schnitt/in der Ansicht (`sheetBodies`). */
|
||||
ceilingId?: string;
|
||||
/** Nur im Schnitt/in der Ansicht (`sheetBodies`). */
|
||||
stairId?: string;
|
||||
}
|
||||
|
||||
export interface GripHandlers {
|
||||
onGripMove(index: number, raw: Vec2, pxPerMeter: number, mods: ToolMods): void;
|
||||
/**
|
||||
* Ganzes Element parallel verschieben (inkrementelles Delta in Metern).
|
||||
* `target` benennt das gegriffene Element (Wand-ID ODER Drawing-ID) — wichtig
|
||||
* bei MEHRFACHAUSWAHL, wo das unter dem Cursor gegriffene Element verschoben
|
||||
* wird und koinzidente Enden der übrigen gewählten Elemente mitwandern. Fehlt
|
||||
* `target`, gilt das einzeln selektierte Element (Rückwärtskompatibilität).
|
||||
*/
|
||||
onMoveBody(
|
||||
delta: Vec2,
|
||||
target?: BodyTarget,
|
||||
mods?: ToolMods,
|
||||
): void;
|
||||
/**
|
||||
* Eine SEITE (Kante) ziehen: verschiebt beide Vertices der Kante senkrecht
|
||||
* (nur die Normal-Komponente von `raw` wirkt; siehe App). `raw` ist der rohe
|
||||
* Modellpunkt unter dem Cursor.
|
||||
*/
|
||||
onEdgeMove(edge: EdgeGrip, raw: Vec2, pxPerMeter: number, mods: ToolMods): void;
|
||||
onGripEnd(): void;
|
||||
/**
|
||||
* Bewaffneten Punkt-Griff verwerfen (Escape): setzt den Punkt exakt auf
|
||||
* `origin` zurück (ohne Snap/Ortho-Neuauswertung) und räumt danach wie
|
||||
* {@link onGripEnd} auf.
|
||||
*/
|
||||
onGripCancel(index: number, origin: Vec2): void;
|
||||
/** Bewaffneten Kanten-Griff an seiner aktuellen Position abschließen. */
|
||||
onEdgeEnd(): void;
|
||||
/**
|
||||
* Bewaffneten Kanten-Griff verwerfen (Escape): setzt ihn exakt auf `anchor`
|
||||
* (den originalen Kanten-Mittelpunkt) zurück und räumt danach wie
|
||||
* {@link onEdgeEnd} auf.
|
||||
*/
|
||||
onEdgeCancel(edge: EdgeGrip, anchor: Vec2): void;
|
||||
}
|
||||
@@ -0,0 +1,388 @@
|
||||
// Steuerhandle (`useImperativeHandle`), Zieh-Zustände (Pan, Marquee, Griffe, Körper, Stempel), Tastatur-
|
||||
// Abschluss bewaffneter Griffe, Umrechnung Bildschirm ↔ Ansicht ↔ Modell und Griff-Treffer der Plan-Ansicht
|
||||
// ([165] aus `PlanView.tsx`). Aufgerufen einmal von `PlanView`.
|
||||
|
||||
import { useRef, useImperativeHandle, useState, useEffect, useMemo } from "react";
|
||||
import { planPrimAt, fitBoxFor, viewForScale, PX_PER_M, viewForCamera, toScreen, meetScale } from "../../../core";
|
||||
import type { ViewBox__plan_planView_geometry as ViewBox, ClientMap } from "../../../core";
|
||||
import type { Vec2, EdgeGrip } from "../../../model/types";
|
||||
import type { BodyTarget } from "./types";
|
||||
import { GRIP_HIT_PX } from "./constants";
|
||||
import { createCursorStore } from "../../../state/cursorStore";
|
||||
import type { GripHandlers } from "./types";
|
||||
import type { PlanViewHandle } from "./types";
|
||||
import type { Plan } from "../../../core";
|
||||
|
||||
/** Werte aus `PlanView`, die dieser Hook liest (unverändert, ohne Kopie). */
|
||||
export interface UsePlanCoordsArgs {
|
||||
gripHandlers: GripHandlers | undefined;
|
||||
ref: React.ForwardedRef<PlanViewHandle>;
|
||||
setView: React.Dispatch<React.SetStateAction<ViewBox>>;
|
||||
defaultViewRef: React.MutableRefObject<ViewBox>;
|
||||
planRef: React.MutableRefObject<Plan>;
|
||||
toScreenRef: React.MutableRefObject<(p: Vec2) => Vec2>;
|
||||
viewRef: React.MutableRefObject<ViewBox>;
|
||||
svgRef: React.MutableRefObject<SVGSVGElement | null>;
|
||||
setPaperScale: React.Dispatch<React.SetStateAction<number | null>>;
|
||||
roomStamp: { roomId: string; anchor: Vec2; } | null | undefined;
|
||||
stampAt: Vec2 | null;
|
||||
plan: Plan;
|
||||
canvasRef: React.MutableRefObject<HTMLCanvasElement | null>;
|
||||
view: ViewBox;
|
||||
grips: Vec2[] | undefined;
|
||||
edgeGrips: EdgeGrip[] | undefined;
|
||||
onCursor: ((model: Vec2 | null) => void) | undefined;
|
||||
}
|
||||
|
||||
export function usePlanCoords(inp: UsePlanCoordsArgs) {
|
||||
const {
|
||||
gripHandlers,
|
||||
ref,
|
||||
setView,
|
||||
defaultViewRef,
|
||||
planRef,
|
||||
toScreenRef,
|
||||
viewRef,
|
||||
svgRef,
|
||||
setPaperScale,
|
||||
roomStamp,
|
||||
stampAt,
|
||||
plan,
|
||||
canvasRef,
|
||||
view,
|
||||
grips,
|
||||
edgeGrips,
|
||||
onCursor,
|
||||
} = inp;
|
||||
|
||||
// Frischer Spiegel der gripHandlers-Prop für das (unten stabil mit leeren
|
||||
// Deps memoisierte) Imperativ-Handle — direkt referenzieren würde die Prop
|
||||
// vom ERSTEN Render einfrieren (stale closure, s. Kommentar dort).
|
||||
const gripHandlersRef = useRef(gripHandlers);
|
||||
gripHandlersRef.current = gripHandlers;
|
||||
|
||||
// Imperatives Steuerhandle für die Oberleiste (Einpassen / Auswahl / Massstab).
|
||||
// Stabil (leere Deps); liest den frischen Ausschnitt + die Auswahl aus Refs.
|
||||
useImperativeHandle(
|
||||
ref,
|
||||
() => ({
|
||||
fit: () => setView(defaultViewRef.current),
|
||||
confirmGripEdit: () => {
|
||||
// Von der Befehlszeile aus angestoßen (Enter mit leerem Eingabetext,
|
||||
// s. App.tsx) — dieselbe Aktion wie ein bestätigender Klick auf der
|
||||
// Zeichenfläche (siehe onPointerDown-Kopf unten), nur eben nicht über
|
||||
// ein Pointer-Event.
|
||||
if (gripDrag.current) {
|
||||
gripDrag.current = null;
|
||||
gripHandlersRef.current?.onGripEnd();
|
||||
}
|
||||
},
|
||||
confirmEdgeEdit: () => {
|
||||
if (edgeDrag.current) {
|
||||
edgeDrag.current = null;
|
||||
gripHandlersRef.current?.onEdgeEnd();
|
||||
}
|
||||
},
|
||||
fitSelection: () => {
|
||||
const sel = selectedRef.current;
|
||||
const prim = sel !== null ? planPrimAt(planRef.current, sel) : undefined;
|
||||
if (prim && prim.kind === "polygon") {
|
||||
setView(fitBoxFor(prim.pts, toScreenRef.current));
|
||||
} else {
|
||||
setView(defaultViewRef.current);
|
||||
}
|
||||
},
|
||||
applyScale: (n: number) => {
|
||||
const target = viewForScale(n, viewRef.current, svgRef.current);
|
||||
if (target) setView(target);
|
||||
// Diesen Massstab als stabile Referenz für die Print-Strichbreiten merken:
|
||||
// ab jetzt skalieren die Papier-mm-Linien um genau dieses N (bis der
|
||||
// nächste Massstab gewählt wird); Rad-Zoom lässt ihn unberührt.
|
||||
if (n > 0) setPaperScale(n);
|
||||
},
|
||||
pxPerMeter: () => currentPxPerMeter(),
|
||||
viewCenterModel: () => {
|
||||
// Mitte der frischen viewBox (aus Ref) → Modell (inverse toScreen).
|
||||
const v = viewRef.current;
|
||||
return { x: (v.x + v.w / 2) / PX_PER_M, y: -(v.y + v.h / 2) / PX_PER_M };
|
||||
},
|
||||
setCamera: (center, pxPerMeter) => {
|
||||
const target = viewForCamera(center, pxPerMeter, svgRef.current);
|
||||
if (target) setView(target);
|
||||
},
|
||||
fitBounds: (pts) => {
|
||||
if (pts.length === 0) return; // leerer Import → kein Fit, kein Crash
|
||||
setView(fitBoxFor(pts, toScreenRef.current));
|
||||
},
|
||||
}),
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[],
|
||||
);
|
||||
// Transiente Pan-Zieh-Daten (Mitteltaste; kein State → kein Re-Render je
|
||||
// Bewegung).
|
||||
const drag = useRef<{
|
||||
pointerId: number;
|
||||
startClientX: number;
|
||||
startClientY: number;
|
||||
startView: ViewBox;
|
||||
} | null>(null);
|
||||
const [dragging, setDragging] = useState(false);
|
||||
|
||||
// Transiente Marquee-Zieh-Daten (linke Taste). Startpunkt in viewBox-Einheiten
|
||||
// + die Bildschirm-Pixel (für die Klick-vs-Drag-Schwelle).
|
||||
const marquee = useRef<{
|
||||
pointerId: number;
|
||||
startClientX: number;
|
||||
startClientY: number;
|
||||
startView: Vec2; // Startpunkt in viewBox-Einheiten
|
||||
moved: boolean; // Schwelle überschritten → echtes Rechteck (kein Klick)
|
||||
} | null>(null);
|
||||
// Aktuelles Auswahl-Rechteck in viewBox-Einheiten (für die sichtbare Kontur);
|
||||
// null = kein Marquee aktiv.
|
||||
const [marqueeRect, setMarqueeRect] = useState<{
|
||||
x: number;
|
||||
y: number;
|
||||
w: number;
|
||||
h: number;
|
||||
crossing: boolean;
|
||||
} | null>(null);
|
||||
|
||||
|
||||
// Transiente Griff-Zieh-Daten (linke Taste auf einem Grip). Kein State je
|
||||
// Bewegung; die Modell-Mutation läuft live über gripHandlers.onGripMove.
|
||||
// Anders als bei Kante/Körper braucht das Loslassen der Maus die Bearbeitung
|
||||
// NICHT mehr zu beenden: der Griff bleibt „bewaffnet" (kein Pointer-Capture),
|
||||
// folgt dem Cursor beim Schweben weiter — wie beim Zeichnen (Klick → Punkt
|
||||
// setzen, Maus bewegt sich frei, Wert tippbar, nächster Klick/Enter bestätigt,
|
||||
// Escape verwirft zur ursprünglichen Position `origin` zurück).
|
||||
const gripDrag = useRef<{ pointerId: number; index: number; origin: Vec2; startX?: number; startY?: number } | null>(
|
||||
null,
|
||||
);
|
||||
// Transiente Kanten-Griff-Zieh-Daten (linke Taste auf einem Dreieck-Anfasser).
|
||||
// Hält den gegriffenen EdgeGrip (Momentaufnahme vom Grab — sein `.mid` ist der
|
||||
// Anker für Feld-Eingabe/Escape-Revert); die Mutation läuft live über
|
||||
// onEdgeMove. Dasselbe „bewaffnet"-Verhalten wie gripDrag oben: Loslassen
|
||||
// beendet die Bearbeitung NICHT, erst ein weiterer Klick/Enter (bestätigt)
|
||||
// oder Escape (verwirft zurück auf `edge.mid`).
|
||||
const edgeDrag = useRef<{ pointerId: number; edge: EdgeGrip; startX?: number; startY?: number } | null>(null);
|
||||
// Transiente „Körper verschieben"-Daten: letzter Modellpunkt, gegen den das
|
||||
// inkrementelle Delta gebildet wird (parallel-Verschiebung des Elements).
|
||||
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
|
||||
// inkrementelle Delta gebildet wird (verschiebt NUR den Raum-Stempel-Anker).
|
||||
// `offset` ([140]): Abstand der gezeichneten Lage vom Anker (Pol), einmal mit dem ersten Delta
|
||||
// übergeben — der Kern setzt den Anker auf Pol + Delta, der Stempel springt so nicht zum Pol.
|
||||
const stampDrag = useRef<{ pointerId: number; roomId: string; last: Vec2; from: Vec2 | null } | null>(
|
||||
null,
|
||||
);
|
||||
// Letzter Links-Klick (Zeit + Bildschirmposition) für die manuelle Doppelklick-
|
||||
// Erkennung auf Raum-Stempel (Pointer-Capture unterdrückt natives dblclick).
|
||||
const lastClickRef = useRef<{ t: number; x: number; y: number } | null>(null);
|
||||
|
||||
// Tastatur-Abschluss eines bewaffneten Punkt- ODER Kanten-Griffs (s. gripDrag/
|
||||
// edgeDrag oben): Escape verwirft (zurück auf die Ursprungsposition), Enter
|
||||
// bestätigt die aktuelle Position — beide NUR wenn kein Eingabefeld
|
||||
// fokussiert ist (die Befehlszeile behandelt ihr eigenes Enter für getippte
|
||||
// Werte selbst, s. App.tsx).
|
||||
useEffect(() => {
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
// Aktuelle Handler über die Ref lesen: `gripHandlers` ist bei jedem Render ein
|
||||
// neues Objekt — mit [gripHandlers] als Abhängigkeit wurde der Listener ständig
|
||||
// ab- und neu angehängt und verpasste Tasten in diesem Fenster (Esc wurde dann
|
||||
// von der Auswahl-Aufhebung statt vom Griff-Abbruch verbraucht).
|
||||
const gripHandlers = gripHandlersRef.current;
|
||||
const gd = gripDrag.current;
|
||||
const ed = edgeDrag.current;
|
||||
if ((!gd && !ed) || !gripHandlers) return;
|
||||
if (e.key !== "Escape" && e.key !== "Enter") return;
|
||||
const el = e.target as HTMLElement | null;
|
||||
if (el && (el.tagName === "INPUT" || el.tagName === "TEXTAREA" || el.isContentEditable)) {
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
if (gd) {
|
||||
gripDrag.current = null;
|
||||
if (e.key === "Escape") gripHandlers.onGripCancel(gd.index, gd.origin);
|
||||
else gripHandlers.onGripEnd();
|
||||
} else if (ed) {
|
||||
edgeDrag.current = null;
|
||||
if (e.key === "Escape") gripHandlers.onEdgeCancel(ed.edge, ed.edge.mid);
|
||||
else gripHandlers.onEdgeEnd();
|
||||
}
|
||||
};
|
||||
window.addEventListener("keydown", onKey);
|
||||
return () => window.removeEventListener("keydown", onKey);
|
||||
}, []);
|
||||
|
||||
/** Bildschirm-px-Distanz Cursor → Stempel-Griff; null = kein einzelner Raum. */
|
||||
const stampHandleAt = (clientX: number, clientY: number): string | null => {
|
||||
if (!roomStamp || !stampAt) return null;
|
||||
const s = vbToClient(toScreen(stampAt).x, toScreen(stampAt).y);
|
||||
const d = Math.hypot(clientX - s.x, clientY - s.y);
|
||||
return d <= GRIP_HIT_PX ? roomStamp.roomId : null;
|
||||
};
|
||||
|
||||
// Lokale Auswahl: Index des hervorgehobenen Polygon-Primitivs (oder null).
|
||||
// Reine Darstellung; die eigentliche Wand-Auswahl meldet onSelect nach oben.
|
||||
// Beim Plan-Wechsel zurücksetzen (Indizes sind nicht mehr gültig).
|
||||
const [selected, setSelected] = useState<number | null>(null);
|
||||
const selectedRef = useRef(selected);
|
||||
selectedRef.current = selected;
|
||||
useEffect(() => {
|
||||
setSelected(null);
|
||||
}, [plan]);
|
||||
|
||||
// Verhältnis viewBox-Einheiten ↔ Bildschirm-Pixel. preserveAspectRatio
|
||||
// "xMidYMid meet" passt die viewBox einheitlich (kleinerer Faktor) ein und
|
||||
// zentriert sie; daraus ergibt sich die effektive Skala + der Versatz.
|
||||
const measure = (vb: ViewBox) => {
|
||||
// Untransformierte Box (GPU-Fläche) bevorzugen: das SVG trägt während einer
|
||||
// imperativen Zoom-Geste einen CSS-Transform.
|
||||
const el = canvasRef.current ?? svgRef.current;
|
||||
const rect = el?.getBoundingClientRect();
|
||||
const pxW = rect?.width ?? vb.w;
|
||||
const pxH = rect?.height ?? vb.h;
|
||||
// Bildschirm-Pixel je viewBox-Einheit (meet = min beider Achsen).
|
||||
const scale = Math.min(pxW / vb.w, pxH / vb.h);
|
||||
const drawnW = vb.w * scale;
|
||||
const drawnH = vb.h * scale;
|
||||
// Letterbox-Versatz durch die Zentrierung.
|
||||
const offX = (pxW - drawnW) / 2;
|
||||
const offY = (pxH - drawnH) / 2;
|
||||
return { rect, scale, offX, offY };
|
||||
};
|
||||
|
||||
// Cursor-Position (clientX/Y) → viewBox-Koordinaten des aktuellen Ausschnitts.
|
||||
const clientToView = (clientX: number, clientY: number, vb: ViewBox): Vec2 => {
|
||||
const { rect, scale, offX, offY } = measure(vb);
|
||||
const left = rect?.left ?? 0;
|
||||
const top = rect?.top ?? 0;
|
||||
return {
|
||||
x: vb.x + (clientX - left - offX) / scale,
|
||||
y: vb.y + (clientY - top - offY) / scale,
|
||||
};
|
||||
};
|
||||
|
||||
// viewBox-Einheiten → Modell-Koordinaten in Metern (Inverse des fixen
|
||||
// toScreen): x/PX_PER_M, Plan-Y zeigt nach oben → −y/PX_PER_M.
|
||||
const viewToModel = (vbX: number, vbY: number): Vec2 => ({
|
||||
x: vbX / PX_PER_M,
|
||||
y: -vbY / PX_PER_M,
|
||||
});
|
||||
|
||||
// Roher Modellpunkt (Meter) unter dem Cursor — für die Zeichenwerkzeuge.
|
||||
const rawModelAt = (clientX: number, clientY: number): Vec2 => {
|
||||
const v = clientToView(clientX, clientY, view);
|
||||
return viewToModel(v.x, v.y);
|
||||
};
|
||||
// viewBox-Koordinaten → Client-Pixel (Inverse von clientToView), für die
|
||||
// Griff-Trefferprüfung in Bildschirm-Pixeln.
|
||||
const vbToClient = (vbX: number, vbY: number): { x: number; y: number } => {
|
||||
const { rect, scale, offX, offY } = measure(view);
|
||||
const left = rect?.left ?? 0;
|
||||
const top = rect?.top ?? 0;
|
||||
return { x: left + offX + (vbX - view.x) * scale, y: top + offY + (vbY - view.y) * scale };
|
||||
};
|
||||
// Abbildung Modell → Client-Pixel (toScreen + vbToClient) für Pixel-Abfragen im Kern.
|
||||
const clientMap = (): ClientMap => {
|
||||
const { rect, scale, offX, offY } = measure(view);
|
||||
return { left: (rect?.left ?? 0) + offX, top: (rect?.top ?? 0) + offY, viewX: view.x, viewY: view.y, scale };
|
||||
};
|
||||
// Index des Griffs unter dem Cursor (Bildschirm-Pixel) oder null.
|
||||
const gripAt = (clientX: number, clientY: number): number | null => {
|
||||
if (!grips) return null;
|
||||
for (let i = 0; i < grips.length; i++) {
|
||||
const vb = toScreen(grips[i]);
|
||||
const c = vbToClient(vb.x, vb.y);
|
||||
if (Math.hypot(c.x - clientX, c.y - clientY) <= GRIP_HIT_PX) return i;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
// Bildschirm-Versatz (viewBox-Einheiten) eines Kanten-Anfassers entlang seiner
|
||||
// Normale: das Dreieck sitzt etwas AUSSERHALB der Kante. Y wird gespiegelt
|
||||
// (toScreen spiegelt Y), damit „außen" am Bildschirm auch wirklich außen ist.
|
||||
// Dreieck-Höhe (nach außen) + halbe Basisbreite in Bildschirm-Pixeln. Die Basis
|
||||
// sitzt AUF der Linie (am Kanten-Mittelpunkt), die Spitze zeigt nach außen.
|
||||
// Flacher, breiter Pfeil (Apex ~124°, also flacher als 120°) statt spitzem
|
||||
// Dreieck: breitere Basis, geringere Höhe.
|
||||
const EDGE_GRIP_H_PX = 7;
|
||||
const EDGE_GRIP_HALF_PX = 9;
|
||||
const screenNormal = (n: Vec2): Vec2 => ({ x: n.x, y: -n.y });
|
||||
// Index des Kanten-Griffs unter dem Cursor (Bildschirm-Pixel) oder null. Die
|
||||
// Trefferfläche liegt um die Dreiecks-Mitte (etwas außerhalb der Linie).
|
||||
const edgeGripAt = (clientX: number, clientY: number): EdgeGrip | null => {
|
||||
if (!edgeGrips) return null;
|
||||
const s = meetScale(view, canvasRef.current ?? svgRef.current) ?? 1;
|
||||
const midOutVb = (EDGE_GRIP_H_PX * 0.45) / s; // Mitte des Dreiecks
|
||||
for (const e of edgeGrips) {
|
||||
const m = toScreen(e.mid);
|
||||
const sn = screenNormal(e.normal);
|
||||
const cVb = { x: m.x + sn.x * midOutVb, y: m.y + sn.y * midOutVb };
|
||||
const c = vbToClient(cVb.x, cVb.y);
|
||||
if (Math.hypot(c.x - clientX, c.y - clientY) <= GRIP_HIT_PX) return e;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
// Aktuelle Bildschirm-Pixel pro Meter (für die zoom-unabhängige Snap-Toleranz).
|
||||
const currentPxPerMeter = (): number =>
|
||||
(meetScale(view, canvasRef.current ?? svgRef.current) ?? 1) * PX_PER_M;
|
||||
// Modifikatoren eines Pointer-Events (Shift=Ortho, Ctrl/Cmd=Snap aus).
|
||||
const toolMods = (e: React.PointerEvent | React.MouseEvent) => ({
|
||||
shift: e.shiftKey,
|
||||
ctrl: e.ctrlKey || e.metaKey,
|
||||
alt: e.altKey,
|
||||
});
|
||||
|
||||
// Cursor in Modell-Metern nach oben melden (Statusleiste) und für die
|
||||
// Lineal-Marker halten — beides KEIN React-State dieser Komponente (s.
|
||||
// cursorStore.ts): sonst renderte jede Mausbewegung den ganzen Plan neu.
|
||||
const rulerCursor = useMemo(() => createCursorStore(), []);
|
||||
const setRulerCursor = rulerCursor.set;
|
||||
const reportCursor = (clientX: number, clientY: number) => {
|
||||
const v = clientToView(clientX, clientY, view);
|
||||
const m = viewToModel(v.x, v.y);
|
||||
setRulerCursor(m);
|
||||
if (!onCursor) return;
|
||||
onCursor(m);
|
||||
};
|
||||
|
||||
return {
|
||||
drag,
|
||||
dragging,
|
||||
setDragging,
|
||||
marquee,
|
||||
marqueeRect,
|
||||
setMarqueeRect,
|
||||
gripDrag,
|
||||
edgeDrag,
|
||||
moveDrag,
|
||||
stampDrag,
|
||||
lastClickRef,
|
||||
stampHandleAt,
|
||||
selected,
|
||||
setSelected,
|
||||
measure,
|
||||
clientToView,
|
||||
viewToModel,
|
||||
rawModelAt,
|
||||
vbToClient,
|
||||
clientMap,
|
||||
gripAt,
|
||||
EDGE_GRIP_H_PX,
|
||||
EDGE_GRIP_HALF_PX,
|
||||
screenNormal,
|
||||
edgeGripAt,
|
||||
currentPxPerMeter,
|
||||
toolMods,
|
||||
rulerCursor,
|
||||
setRulerCursor,
|
||||
reportCursor,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,436 @@
|
||||
// Renderer-Anbindung der Plan-Ansicht ([165] aus `PlanView.tsx`): Pick-Index im Kern, Wahl der Engine
|
||||
// (native Metal-Fläche, render2d als WASM/WebGPU oder SVG-Rückfall), aufbereiteter Plan, Unterlage,
|
||||
// SVG-Kandidaten samt Culling, Papier-Massstab, Overlay-Ursprung und die GL-Effekte. Aufgerufen einmal von
|
||||
// `PlanView`; die Reihenfolge der Hooks und Effekte ist wie vor der Aufteilung.
|
||||
|
||||
import { useRef, useEffect, useMemo, useState, useLayoutEffect } from "react";
|
||||
import { PlanPickIndex, planTextEntries, materializeGreyed, materializeUnderlay, roomStampAt, buildDrawingIndex, isGpuText, meetScale, PLAN_DASH_VAR, toScreen, scaleFromView, PX_PER_M } from "../../../core";
|
||||
import { useNativeAvailable, useNativePlanRenderer } from "../useNativePlanRenderer";
|
||||
import { useWasmPlanRenderer } from "../useWasmPlanRenderer";
|
||||
import type { UnderlayGroup, DrawingIndex, Primitive, ViewBox__plan_planView_geometry as ViewBox } from "../../../core";
|
||||
import type { Drawing2D, Vec2 } from "../../../model/types";
|
||||
import { CULL_THRESHOLD, computeCullState, cullStateStale } from "./constants";
|
||||
import type { CullState } from "./constants";
|
||||
import { pickOverlayOrigin, makeToLocal } from "./overlayOrigin";
|
||||
import { createMeetStore, createValueStore } from "./liveMeet";
|
||||
import { endBusyAfterPaint } from "../../../state/busyStore";
|
||||
import type { Plan } from "../../../core";
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
/** Werte aus `PlanView`, die dieser Hook liest (unverändert, ohne Kopie). */
|
||||
export interface UsePlanEngineArgs {
|
||||
editTextId: string | null | undefined;
|
||||
planRaw: Plan;
|
||||
backdrop: ((origin: Vec2, pxPerMeter: number) => ReactNode) | undefined;
|
||||
roomStamp: { roomId: string; anchor: Vec2; } | null | undefined;
|
||||
defaultView: ViewBox;
|
||||
view: ViewBox;
|
||||
hairline: boolean | undefined;
|
||||
onScale: ((n: number) => void) | undefined;
|
||||
resetKey: string | undefined;
|
||||
}
|
||||
|
||||
export function usePlanEngine(inp: UsePlanEngineArgs) {
|
||||
const {
|
||||
editTextId,
|
||||
planRaw,
|
||||
backdrop,
|
||||
roomStamp,
|
||||
defaultView,
|
||||
view,
|
||||
hairline,
|
||||
onScale,
|
||||
resetKey,
|
||||
} = inp;
|
||||
|
||||
// Viewport-/LOD-Culling für `primitiveEls` (s. cullPrimitives.ts) — NUR
|
||||
// aktiv bei sehr vielen Primitiven (Kataster-DXF-Import, Nutzer-Report
|
||||
// 2026-10-09: 59'391 Einzel-Textbeschriftungen liessen die App nach dem
|
||||
// Import hängen, weil React/SVG ALLE auf einmal als DOM-Knoten erzeugte,
|
||||
// egal ob sichtbar oder lesbar) — bei normalen Projekten bleibt das
|
||||
// Verhalten exakt wie zuvor (kein Overhead, `cullState` bleibt `null`).
|
||||
//
|
||||
// ZWEI Kriterien, nicht nur Position: direkt nach einem Import zeigt die
|
||||
// "eingepasste" Übersicht den GESAMTEN Umriss (bei Luzern: 2158×2583 m) —
|
||||
// technisch liegen dann ALLE 59'391 Labels "im Bild", wären aber jedes nur
|
||||
// ein paar Pixel gross und unleserlich. `minTextHeightVb` filtert zusätzlich
|
||||
// nach Lesbarkeit bei der aktuellen Zoomstufe (unabhängig von der Position) —
|
||||
// erst damit bleibt auch der ALLERERSTE Blick nach dem Import schnell.
|
||||
//
|
||||
// Puffer+Hysterese (CULL_MARGIN_FACTOR, `cullStateStale`), damit kleine
|
||||
// Schwenks/Zoom-Schritte KEINE Neuberechnung auslösen — dieselbe Überlegung
|
||||
// wie beim bestehenden `primitiveEls`-Memo weiter unten, das bewusst NICHT
|
||||
// an `view` hängt (sonst Ruckler auf WebKitGTK bei jedem Pan/Zoom, s.
|
||||
// Kommentar dort): nur bei einem GRÖSSEREN Schwenk ODER spürbarem Hinein-
|
||||
// zoomen (view schrumpft stark — reines "liegt noch drin" reicht hier
|
||||
// NICHT, ein View, der nur kleiner wird, bleibt sonst fälschlich innerhalb
|
||||
// der alten, zu grosszügigen Region) wird neu gerechnet.
|
||||
// Auswahl-Index im Kern (s. planView/planPick.ts): 2D-Zeichenlinien, Polygone, Symbol-Linien,
|
||||
// Kreise/Bögen und Besitzer über `plan.primitives` (dieselben Indizes). LAZY: der Kern baut ihn
|
||||
// erst bei der ersten Abfrage je Plan; der vorige wird dann freigegeben.
|
||||
const pickIndexRef = useRef<PlanPickIndex | null>(null);
|
||||
const getPick = (): PlanPickIndex => {
|
||||
const cached = pickIndexRef.current;
|
||||
if (cached && cached.plan === plan) return cached;
|
||||
cached?.release();
|
||||
const ix = new PlanPickIndex(plan);
|
||||
pickIndexRef.current = ix;
|
||||
return ix;
|
||||
};
|
||||
useEffect(() => () => pickIndexRef.current?.release(), []);
|
||||
|
||||
const svgRef = useRef<SVGSVGElement | null>(null);
|
||||
const canvasRef = useRef<HTMLCanvasElement | null>(null);
|
||||
|
||||
// Engine-Auswahl. Zwei GPU-Pfade, kein WebGL2 mehr:
|
||||
// • NATIVE Metal-Fläche hinter der Webview (macOS-Tauri mit Feature native2d, s.
|
||||
// useNativePlanRenderer.ts): STANDARD, wo verfügbar; `?native=0` schaltet sie ab.
|
||||
// • render2d als WASM/WebGPU (useWasmPlanRenderer): überall sonst (Linux/Electron).
|
||||
// Der SVG-Renderer bleibt die Interaktions-Ebene (Text/Griffe/Auswahl) und der Rückfall,
|
||||
// wenn kein GPU-Pfad läuft (`?gl=0` erzwingt ihn). Solange die Verfügbarkeit des nativen
|
||||
// Pfads noch erfragt wird (null), startet KEINE Engine.
|
||||
const hasWebGpu = typeof navigator !== "undefined" && "gpu" in navigator;
|
||||
const nativeAvail = useNativeAvailable();
|
||||
const glParam = typeof window === "undefined" ? null : new URLSearchParams(window.location.search).get("gl");
|
||||
const nativeOptOut = typeof window !== "undefined" && new URLSearchParams(window.location.search).get("native") === "0";
|
||||
const wantNative = nativeAvail === true && !nativeOptOut && glParam !== "0";
|
||||
const wantWasm = !wantNative && nativeAvail !== null && hasWebGpu && glParam !== "0";
|
||||
// Alle Hooks unbedingt aufrufen (Hook-Regeln); je nach Flag ist genau einer aktiv.
|
||||
const wasmHook = useWasmPlanRenderer(canvasRef, wantWasm);
|
||||
const nativeHook = useNativePlanRenderer(canvasRef, wantNative);
|
||||
const activeEngine = wantWasm ? wasmHook : nativeHook;
|
||||
// Text im Inline-Editor nicht zusätzlich nativ zeichnen.
|
||||
const setNativeExcludedText = nativeHook.setExcludedText;
|
||||
useEffect(() => {
|
||||
setNativeExcludedText(editTextId ?? null);
|
||||
}, [editTextId, setNativeExcludedText]);
|
||||
const { render: renderGl, updateGeometry, ready: glReady } = activeEngine;
|
||||
// „GPU-Canvas montieren?" — beide GPU-Pfade brauchen das Canvas (an der ABSICHT
|
||||
// montiert, nicht am ready, sonst könnte die Engine mangels Canvas nie starten).
|
||||
const wantGpu = wantWasm || wantNative;
|
||||
// Georeferenzierte Hintergrund-Rasterbilder (Luftbild) vorhanden? Der GPU-
|
||||
// Canvas löscht das Blatt UNDURCHSICHTIG (clearColor …,1) und würde ein
|
||||
// dahinterliegendes Bild verdecken. Daher bei aktivem Luftbild bewusst den
|
||||
// vollen SVG-Pfad nutzen — dort liegt das Bild als eigene Ebene ZWISCHEN
|
||||
// Blatt-Hintergrund und Geometrie (sichtbar, ohne den GL-Renderer zu ändern).
|
||||
const hasBgImages = (planRaw.backgroundImages?.length ?? 0) > 0;
|
||||
// Eingebettete Bild-Zeichenelemente (Drawing2D `{shape:"image"}`, Foto/Logo/
|
||||
// PDF-Seite) kann das GPU-Backend ebenfalls nicht texturieren (kein Bild-
|
||||
// Primitiv in render2d, s. toRenderScene.ts `RImage`-Kommentar) — dieselbe
|
||||
// SVG-Fallback-Regel wie bei georeferenzierten Luftbildern.
|
||||
// useMemo: lief sonst bei JEDEM Render über alle Primitive (3,7 Mio. bei Kataster).
|
||||
// Texte/Bilder aus den Typ-Kennungen des Plan-Puffers (`planTextEntries`), ohne alle Primitive zu lesen.
|
||||
const hasDrawingImages = useMemo(
|
||||
() => planTextEntries(planRaw).some((e) => e.p.kind === "drawingImage"),
|
||||
[planRaw],
|
||||
);
|
||||
// Engine WIRKLICH aktiv? Steuert das Umschalten SVG↔GPU: bei false rendert der
|
||||
// volle SVG-Pfad (Fallback), bei true übernimmt die GPU-Ebene + Text-Overlay.
|
||||
const useGpuRenderer = wantGpu && glReady && !hasBgImages && !hasDrawingImages && !backdrop;
|
||||
|
||||
// `planRaw.greyedRanges` (andere Ebenen als gedimmte Referenz) ohne Klonen der
|
||||
// Primitive: der WebGL-Pfad dimmt selbst beim Zeichnen (nur planRaw), alle
|
||||
// übrigen Verbraucher (SVG-Overlay, Schraffur-Muster, WASM) lesen `greyed`
|
||||
// direkt am Primitiv und bekommen deshalb diese materialisierte Variante.
|
||||
// Linien werden nur geklont, wenn sie NICHT der WebGL-Pfad zeichnet.
|
||||
const plan = useMemo(() => {
|
||||
// Die kompakte Linien-Unterlage (planRaw.underlay) zeichnet nur der WebGL-Pfad
|
||||
// selbst; alle anderen Wege brauchen echte 'line'-Primitive.
|
||||
const lines = !useGpuRenderer || wantWasm;
|
||||
return materializeGreyed(lines ? materializeUnderlay(planRaw) : planRaw, lines);
|
||||
}, [planRaw, useGpuRenderer, wantWasm]);
|
||||
// [140] Stempel-Griff an der tatsächlichen Lage des Stempels im Plan (ohne eigenen Anker rückt der Kern
|
||||
// ihn vom Pol weg: L-Raum, Hindernisse); sonst am Anker.
|
||||
const stampAt = useMemo(
|
||||
() => (roomStamp ? (roomStampAt(planRaw, roomStamp.roomId) ?? roomStamp.anchor) : null),
|
||||
[planRaw, roomStamp],
|
||||
);
|
||||
// Kompakte Linien-Unterlage (nur im reinen WebGL-Modus noch als `plan.underlay`
|
||||
// vorhanden): Hover/Pick/Marquee/Hervorhebung greifen direkt auf die Zeichnungen
|
||||
// zu, Strukturen entstehen LAZY je Plan (s. planView/underlayAccess.ts).
|
||||
const underlayRef = useRef<{
|
||||
key: UnderlayGroup[];
|
||||
drawings: Drawing2D[];
|
||||
index?: DrawingIndex | null;
|
||||
ids?: Map<string, UnderlayGroup>;
|
||||
} | null>(null);
|
||||
const getUnderlay = () => {
|
||||
const groups = plan.underlay;
|
||||
if (!groups || groups.length === 0) return null;
|
||||
let c = underlayRef.current;
|
||||
if (!c || c.key !== groups) {
|
||||
c = { key: groups, drawings: groups.flatMap((g) => g.drawings) };
|
||||
underlayRef.current = c;
|
||||
}
|
||||
return c;
|
||||
};
|
||||
const getUnderlayIndex = (): DrawingIndex | null => {
|
||||
const c = getUnderlay();
|
||||
if (!c) return null;
|
||||
if (c.index === undefined) c.index = buildDrawingIndex(c.drawings);
|
||||
return c.index;
|
||||
};
|
||||
const getUnderlayIds = (): Map<string, UnderlayGroup> | null => {
|
||||
const c = getUnderlay();
|
||||
if (!c) return null;
|
||||
if (!c.ids) {
|
||||
c.ids = new Map();
|
||||
for (const g of c.key) for (const d of g.drawings) c.ids.set(d.id, g);
|
||||
}
|
||||
return c.ids;
|
||||
};
|
||||
|
||||
// Nur die Primitive, die das SVG überhaupt selbst zeichnet (der Rest kommt aus
|
||||
// WebGL/WASM bzw. — ohne GPU — aus `drawingRuns`), einmal je Plan/Modus
|
||||
// vorgefiltert. Sonst liefen Culling UND der React-Abgleich der Kinderliste
|
||||
// bei jedem Render über ALLE Primitive — bei einem Kataster-Import 3,7 Mio.
|
||||
// GL-Linien, von denen das SVG keine einzige zeichnet (gemessen: 120–170 ms
|
||||
// je Zoom-Schritt allein fürs Culling, für am Ende ~500 sichtbare Texte).
|
||||
// Mit GPU zeichnet das SVG nur Texte: dann kommen die Kandidaten aus den Text-Einträgen des
|
||||
// Plan-Puffers (`planTextEntries`, [K3d]) — die übrigen Primitive werden nicht gelesen.
|
||||
const svgCandidates = useMemo(() => {
|
||||
const out: Array<{ p: Primitive; i: number }> = [];
|
||||
const items: ReadonlyArray<{ p: Primitive; i: number }> = useGpuRenderer ? planTextEntries(plan) : plan.primitives.map((p, i) => ({ p, i }));
|
||||
for (const { p, i } of items) {
|
||||
const drawnElsewhere = useGpuRenderer
|
||||
? wantWasm
|
||||
? p.kind !== "drawingText"
|
||||
: p.kind !== "text" && p.kind !== "drawingText"
|
||||
: p.kind === "line" && !!p.drawingId;
|
||||
// Einfache Texte zeichnet die native Fläche selbst (Vektor-Glyphen, auch gedreht).
|
||||
if (useGpuRenderer && wantNative && nativeHook.gpuTexts && isGpuText(p)) continue;
|
||||
if (!drawnElsewhere) out.push({ p, i });
|
||||
}
|
||||
return out;
|
||||
}, [plan, useGpuRenderer, wantWasm, wantNative, nativeHook.gpuTexts]);
|
||||
const needsCull = svgCandidates.length > CULL_THRESHOLD;
|
||||
const [cullState, setCullState] = useState<CullState | null>(() => {
|
||||
if (!needsCull) return null;
|
||||
return computeCullState(defaultView);
|
||||
});
|
||||
useEffect(() => {
|
||||
if (!needsCull) {
|
||||
if (cullState !== null) setCullState(null);
|
||||
return;
|
||||
}
|
||||
if (!cullState || cullStateStale(cullState, view)) {
|
||||
setCullState(computeCullState(view));
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [view, needsCull, plan]);
|
||||
|
||||
// Stabiler Papier-Massstab-Nenner N (1:N) als REFERENZ für die Print-Strich-
|
||||
// breiten. BEWUSST NICHT der live aus dem Zoom abgeleitete N (der sich beim
|
||||
// Rad-Zoom ändert): Print-Strichbreiten sind echte Papier-mm, die beim Zoomen
|
||||
// MIT der Geometrie skalieren (reinzoomen = dicker). Damit das funktioniert,
|
||||
// muss die mm→Welt-Umrechnung an einem beim Rad-Zoom KONSTANTEN N hängen; er
|
||||
// ändert sich nur, wenn die Oberleiste explizit einen Massstab setzt
|
||||
// (applyScale) bzw. beim ersten Messen/Einpassen. So gilt: 1:10→1:100 = ×10
|
||||
// dicker (halber Sprung des Nenners → 10× mehr Welt-Meter je Papier-mm).
|
||||
const [paperScale, setPaperScale] = useState<number | null>(null);
|
||||
const paperScaleRef = useRef(paperScale);
|
||||
paperScaleRef.current = paperScale;
|
||||
// Strichmuster (Linientypen) im PLOT-Massstab: fest im Modell-Raum, auch im Anzeigemodus, wo der
|
||||
// Strich-Massstab dem Zoom folgt — so gleicht der Rhythmus bei jedem Zoom der Druckansicht.
|
||||
activeEngine.setDashScale(paperScale ?? 0);
|
||||
// SVG-Pfad: Strichmuster unter non-scaling-stroke über die meet-Variable im Modell-Raum halten
|
||||
// (`dashArrayCss`); bei jedem festgeschriebenen Ausschnitt nachgeführt, ohne React-Neuaufbau.
|
||||
const syncDashVar = (v: ViewBox) => {
|
||||
const el = svgRef.current;
|
||||
const m = meetScale(v, canvasRef.current ?? el);
|
||||
if (el && m != null && m > 0) el.style.setProperty(PLAN_DASH_VAR, String(m));
|
||||
};
|
||||
useLayoutEffect(() => syncDashVar(view));
|
||||
// Frische Werte in Refs spiegeln, damit das (stabile) imperative Handle und
|
||||
// der Resize-Beobachter stets den aktuellen Stand lesen (Handle hat leere Deps).
|
||||
const viewRef = useRef(view);
|
||||
viewRef.current = view;
|
||||
// Lokaler Ursprung des SVG-Overlays (viewBox-Einheiten, s. planView/overlayOrigin.ts): alles, was
|
||||
// ins DOM geht, ist relativ dazu (f32-sicher auch bei LV95); `view`, Treffer und Fang bleiben
|
||||
// absolut. Bleibt dasselbe Objekt, solange der Ausschnitt in der Nähe bleibt (Memos unten).
|
||||
const overlayOriginRef = useRef<Vec2 | null>(null);
|
||||
const overlayOrigin = pickOverlayOrigin(view, overlayOriginRef.current);
|
||||
overlayOriginRef.current = overlayOrigin;
|
||||
const toLocal = useMemo(() => makeToLocal(overlayOrigin), [overlayOrigin]);
|
||||
// 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);
|
||||
toScreenRef.current = toScreen;
|
||||
const planRef = useRef(plan);
|
||||
planRef.current = plan;
|
||||
// Zuletzt tessellierter LOD-Bucket (quantisierter Zoom). Nur bei Bucket-Wechsel
|
||||
// wird die Bogen-Geometrie neu aufgebaut — sonst bliebe Pan/Zoom reines
|
||||
// Matrix-Update. −Infinity = „noch nie tesselliert".
|
||||
const lodBucketRef = useRef<number>(-Infinity);
|
||||
|
||||
// Papier-Massstab-Nenner (1:N) für die GL-Strichbreiten — ECHTE mm im Massstab
|
||||
// (0.35 mm bei 1:100). Bevorzugt der stabile `paperScale` (wie beim SVG-Print);
|
||||
// solange der noch nicht gemessen ist, der live aus dem Ausschnitt abgeleitete N.
|
||||
// Im Haarlinien-Modus (Display, wie `textScaleForGl` daneben) NICHT den
|
||||
// stabilen `paperScale`: der bliebe beim Rad-Zoom konstant, während die GPU-
|
||||
// Strichbreite (`mm_to_device_px` = N/1000·PX_PER_M·meet) über `meet` trotzdem
|
||||
// mit dem Zoom wächst — genau der Haarlinien-Bug (Finding 1). Der LIVE aus dem
|
||||
// Ausschnitt abgeleitete `scaleFromView` ist hingegen exakt der reziproke Wert
|
||||
// von `meet` (siehe dessen Formel), sodass N·meet — und damit die GL-Strich-
|
||||
// breite in Geräte-px — unabhängig vom Zoom konstant bleibt: dieselbe Wirkung
|
||||
// wie `non-scaling-stroke` im SVG-Pfad, nur über den Massstab-Nenner erzielt.
|
||||
// Display-Modus (Haarlinien): Die Strichbreite bleibt NICHT konstant in Pixeln,
|
||||
// sondern wächst mit dem Zoom — sanft (Exponent 0.4) relativ zur Ansicht 1:100:
|
||||
// weit weg bleiben die Striche fein (mind. 1 px im Shader), nah dran werden sie
|
||||
// sichtbar kräftiger statt auf Haarlinien-Breite zu kleben. Bewusst nur MILD (Exponent 0.4, höchstens ×3): bei 0.8/×12 wirkten alle Elemente beim Hineinzoomen klobig dick.
|
||||
const paperScaleForGl = (v: ViewBox): number => {
|
||||
// Elementbox der GPU-Fläche (NIE transformiert): das SVG trägt während einer
|
||||
// imperativen Zoom-Geste einen CSS-Transform, seine Box wäre verzerrt (Striche
|
||||
// wurden dadurch beim Herauszoomen kurz riesig).
|
||||
const box = canvasRef.current ?? svgRef.current;
|
||||
if (!hairline) return paperScaleRef.current ?? scaleFromView(v, box) ?? 100;
|
||||
const live = scaleFromView(v, box) ?? 100;
|
||||
// Hineinzoomen (live < 100) mild wachsen, Herauszoomen (live > 100) deutlich dünner.
|
||||
const grow = Math.min(3, Math.max(0.1, Math.pow(100 / live, live < 100 ? 0.4 : 0.75)));
|
||||
return live * grow;
|
||||
};
|
||||
|
||||
// Referenz-Nenner (1:N) NUR für die Text-Schriftgröße der Engine — spiegelt
|
||||
// EXAKT die SVG-Formel (case "text" unten, gleiche `print`-Bedingung): im
|
||||
// normalen Anzeigemodus fest auf die Referenzskala 1:100 (Raumstempel bleibt
|
||||
// lesbar, unabhängig vom zufälligen Einpass-Massstab der Ansicht), erst im
|
||||
// Druck-Modus der echte gemessene `paperScale`. BEWUSST NICHT `paperScaleForGl`
|
||||
// (das dort verwendete live abgeleitete N wäre für Text willkürlich/unlesbar
|
||||
// und würde vom SVG-Referenzpfad abweichen — siehe Doku in `gpu::Renderer`).
|
||||
const textScaleForGl = (): number => {
|
||||
const print = !hairline && paperScale != null && paperScale > 0;
|
||||
return print ? paperScale! : 100;
|
||||
};
|
||||
|
||||
// Bildschirm-Massstab (Geräte-px je Modell-Meter) beim aktuellen Ausschnitt:
|
||||
// meet-Skala (CSS-px je viewBox-Einheit) · PX_PER_M (viewBox-Einheiten je Meter)
|
||||
// · dpr (Geräte-px je CSS-px). Steuert die adaptive Bogen-Tessellierung.
|
||||
const pxPerMeterForView = (v: ViewBox): number => {
|
||||
const meet = meetScale(v, canvasRef.current ?? svgRef.current);
|
||||
if (!meet || meet <= 0) return 0;
|
||||
return meet * PX_PER_M * (window.devicePixelRatio || 1);
|
||||
};
|
||||
// LOD-Bucket = quantisierter Zoom (log2 des Bildschirm-Massstabs, auf Ganzzahl
|
||||
// gerundet → Schritte von ×2). Nur ein Bucket-Wechsel löst eine Neu-Tessellierung
|
||||
// aus; innerhalb eines Buckets bleibt Pan/Zoom reines Matrix-Uniform-Update.
|
||||
const lodBucketForView = (v: ViewBox): number => {
|
||||
const s = pxPerMeterForView(v);
|
||||
return s > 0 ? Math.round(Math.log2(s)) : -Infinity;
|
||||
};
|
||||
|
||||
// GL-Geometrie beim Plan-Wechsel neu tessellieren + sofort neu zeichnen. Der
|
||||
// aktuelle LOD-Bucket wird mitgeschrieben, damit der Pan/Zoom-Effekt weiss, ab
|
||||
// wann sich der Zoom weit genug bewegt hat, um Bögen neu aufzulösen.
|
||||
useEffect(() => {
|
||||
if (!useGpuRenderer) return;
|
||||
const v = viewRef.current;
|
||||
updateGeometry(wantWasm ? plan : planRaw, pxPerMeterForView(v));
|
||||
lodBucketRef.current = lodBucketForView(v);
|
||||
renderGl(v, paperScaleForGl(v), textScaleForGl());
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [useGpuRenderer, planRaw, wantWasm ? plan : null, updateGeometry, renderGl]);
|
||||
|
||||
// Import-Hinweis (busyStore) beenden, sobald der neue Plan aufgebaut UND
|
||||
// gezeichnet ist — deklariert NACH dem Geometrie-Effekt oben, läuft also
|
||||
// danach; das Beenden wartet zusätzlich auf den nächsten gemalten Frame.
|
||||
useEffect(() => {
|
||||
endBusyAfterPaint();
|
||||
}, [planRaw]);
|
||||
|
||||
// GL bei jeder Ausschnittsänderung (Pan/Zoom) neu zeichnen. Normalfall: NUR
|
||||
// Matrix-Uniform (keine Re-Tessellierung → flüssig). Ausnahme: hat der Zoom
|
||||
// einen neuen LOD-Bucket erreicht, werden die Bögen einmalig mit dem neuen
|
||||
// Bildschirm-Massstab neu tesselliert (rund beim Hineinzoomen, billig weit weg).
|
||||
// Kostennotiz: `updateGeometry` baut die GESAMTE Linien-/Füll-Geometrie neu auf,
|
||||
// nicht nur die Bögen — Bucket-Wechsel sind aber selten (Zoom-Faktor ×2).
|
||||
useEffect(() => {
|
||||
if (!useGpuRenderer) return;
|
||||
const bucket = lodBucketForView(view);
|
||||
if (bucket !== lodBucketRef.current) {
|
||||
lodBucketRef.current = bucket;
|
||||
updateGeometry(wantWasm ? plan : planRaw, pxPerMeterForView(view));
|
||||
}
|
||||
renderGl(view, paperScaleForGl(view), textScaleForGl());
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [useGpuRenderer, renderGl, view, paperScale]);
|
||||
|
||||
|
||||
// LIVE Papier-Massstab (1:N) nach oben melden. Berechnung aus der effektiven
|
||||
// meet-Skala (Bildschirm-px je viewBox-Einheit) → px je Meter → mm je Meter,
|
||||
// verglichen mit der Papier-Abbildung. Aktualisiert bei Ausschnitts-/Größen-
|
||||
// änderung; ein ResizeObserver fängt reine Größenänderungen ab.
|
||||
const reportScale = () => {
|
||||
if (!onScale) return;
|
||||
const n = scaleFromView(viewRef.current, svgRef.current);
|
||||
if (n != null && isFinite(n)) onScale(n);
|
||||
};
|
||||
useEffect(() => {
|
||||
reportScale();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [onScale, view, plan]);
|
||||
useEffect(() => {
|
||||
const el = svgRef.current;
|
||||
if (!el) return;
|
||||
const ro = new ResizeObserver(() => reportScale());
|
||||
ro.observe(el);
|
||||
return () => ro.disconnect();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [onScale]);
|
||||
|
||||
// Referenz-Papier-Massstab initialisieren, sobald das SVG messbar ist (bzw. der
|
||||
// Plan/das Geschoss wechselt): aus dem AKTUELLEN Ausschnitt (der beim Wechsel
|
||||
// eingepasst wird). Danach bleibt er beim Rad-Zoom stehen; applyScale setzt ihn
|
||||
// explizit neu. Ohne Messung (SSR/erste Runde) bleibt er null → Fallback im
|
||||
// Renderer auf live-N, damit Print nie „unsichtbar" wird.
|
||||
useEffect(() => {
|
||||
if (paperScaleRef.current != null) return;
|
||||
const n = scaleFromView(viewRef.current, svgRef.current);
|
||||
if (n != null && isFinite(n) && n > 0) setPaperScale(n);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [view]);
|
||||
// Beim Plan-/Geschoss-Wechsel den Referenz-Massstab an den (frisch eingepassten)
|
||||
// Ausschnitt angleichen.
|
||||
useEffect(() => {
|
||||
const n = scaleFromView(defaultViewRef.current, svgRef.current);
|
||||
if (n != null && isFinite(n) && n > 0) setPaperScale(n);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [resetKey]);
|
||||
|
||||
return {
|
||||
getPick,
|
||||
svgRef,
|
||||
canvasRef,
|
||||
wantNative,
|
||||
wantWasm,
|
||||
nativeHook,
|
||||
renderGl,
|
||||
wantGpu,
|
||||
hasBgImages,
|
||||
useGpuRenderer,
|
||||
plan,
|
||||
stampAt,
|
||||
getUnderlay,
|
||||
getUnderlayIndex,
|
||||
getUnderlayIds,
|
||||
svgCandidates,
|
||||
cullState,
|
||||
paperScale,
|
||||
setPaperScale,
|
||||
syncDashVar,
|
||||
viewRef,
|
||||
overlayOriginRef,
|
||||
overlayOrigin,
|
||||
toLocal,
|
||||
meetStore,
|
||||
viewStore,
|
||||
defaultViewRef,
|
||||
toScreenRef,
|
||||
planRef,
|
||||
paperScaleForGl,
|
||||
textScaleForGl,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,315 @@
|
||||
// Hervorhebungen der Plan-Ansicht ([165] aus `PlanView.tsx`): Konturen der gewählten Bauteile und 2D-Elemente,
|
||||
// Textrahmen, Pfade für die native Fläche und die Vorschau des überfahrenen Listeneintrags. Aufgerufen
|
||||
// einmal von `PlanView`.
|
||||
|
||||
import type { Primitive, OwnerField, PickKind } from "../../../core";
|
||||
import { useMemo, useEffect } from "react";
|
||||
import { planPrimAt } from "../../../core";
|
||||
import { textFrameCorners } from "../../../text/textFrame";
|
||||
import { TREE_PICK } from "./constants";
|
||||
import { PlanPickIndex } from "../../../core";
|
||||
import type { Plan } from "../../../core";
|
||||
import type { UnderlayGroup } from "../../../core";
|
||||
import type { ViewBox__plan_planView_geometry as ViewBox } from "../../../core";
|
||||
import type { Vec2 } from "../../../model/types";
|
||||
import type { PickCandidate } from "./types";
|
||||
|
||||
/** Werte aus `PlanView`, die dieser Hook liest (unverändert, ohne Kopie). */
|
||||
export interface UsePlanHighlightsArgs {
|
||||
getPick: () => PlanPickIndex;
|
||||
selectedWallIds: string[];
|
||||
selected: number | null;
|
||||
plan: Plan;
|
||||
selectedDrawingIds: string[];
|
||||
getUnderlayIds: () => Map<string, UnderlayGroup> | null;
|
||||
editTextId: string | null | undefined;
|
||||
useGpuRenderer: boolean;
|
||||
wantNative: boolean;
|
||||
nativeHook: { render: (viewBox: ViewBox, paperScaleN?: number, _textScale?: number, onSent?: () => void) => void; updateGeometry: (plan: Plan, pxPerMeter?: number) => void; ready: boolean; gpuTexts: boolean; setExcludedText: (id: string | null) => void; setHighlight: (prims: readonly Primitive[], color: string) => void; setDashScale: (n: number) => void; };
|
||||
toLocal: (p: Vec2) => Vec2;
|
||||
overlayHeavyRef: React.MutableRefObject<boolean>;
|
||||
selectedCeilingIds: string[];
|
||||
selectedOpeningIds: string[];
|
||||
selectedStairIds: string[];
|
||||
selectedRoomIds: string[];
|
||||
selectedRoofIds: string[];
|
||||
selectedContextObjectIds: string[];
|
||||
selectedSite: string[];
|
||||
selectedTreeIds: string[];
|
||||
selectedSectionLineIds: string[];
|
||||
selectedExtrudedSolidIds: string[];
|
||||
selectedColumnIds: string[];
|
||||
hoverPick: PickCandidate | null;
|
||||
}
|
||||
|
||||
export function usePlanHighlights(inp: UsePlanHighlightsArgs) {
|
||||
const {
|
||||
getPick,
|
||||
selectedWallIds,
|
||||
selected,
|
||||
plan,
|
||||
selectedDrawingIds,
|
||||
getUnderlayIds,
|
||||
editTextId,
|
||||
useGpuRenderer,
|
||||
wantNative,
|
||||
nativeHook,
|
||||
toLocal,
|
||||
overlayHeavyRef,
|
||||
selectedCeilingIds,
|
||||
selectedOpeningIds,
|
||||
selectedStairIds,
|
||||
selectedRoomIds,
|
||||
selectedRoofIds,
|
||||
selectedContextObjectIds,
|
||||
selectedSite,
|
||||
selectedTreeIds,
|
||||
selectedSectionLineIds,
|
||||
selectedExtrudedSolidIds,
|
||||
selectedColumnIds,
|
||||
hoverPick,
|
||||
} = inp;
|
||||
|
||||
// Hervorhebungs-Konturen der Auswahl. Vorrang hat die wand-bezogene Auswahl
|
||||
// (selectedWallIds, von App kontrolliert): dann werden ALLE Bänder JEDER
|
||||
// gewählten Wand umrandet. Ohne Wand-Auswahl greift die lokale Klick-
|
||||
// Hervorhebung (ein einzelnes Polygon per hitIndex), z. B. für Polygone ohne
|
||||
// Wandbezug.
|
||||
// Besitzer über den Auswahl-Index im Kern (s. planView/planPick.ts) — statt je Elementart ein
|
||||
// `plan.primitives.filter`.
|
||||
const primsOwnedBy = <K extends Primitive>(
|
||||
field: OwnerField,
|
||||
ids: ReadonlyArray<string> | undefined,
|
||||
keep: (p: Primitive) => p is K,
|
||||
): K[] => {
|
||||
if (!ids || ids.length === 0) return [];
|
||||
return getPick().ownedBy(field, ids).filter(keep);
|
||||
};
|
||||
|
||||
const highlightPolys = useMemo(() => {
|
||||
if (selectedWallIds && selectedWallIds.length) {
|
||||
return primsOwnedBy("wallId", selectedWallIds, (p): p is Extract<Primitive, { kind: "polygon" }> => p.kind === "polygon");
|
||||
}
|
||||
if (selected !== null) {
|
||||
const p = planPrimAt(plan, selected);
|
||||
if (p && p.kind === "polygon") return [p];
|
||||
}
|
||||
return [];
|
||||
}, [plan, selectedWallIds, selected]);
|
||||
|
||||
// Hervorhebung der selektierten 2D-Zeichenelemente (Mehrfach/Marquee): alle
|
||||
// Linien-/Polygon-Primitive, deren drawingId in der Auswahl liegt, werden mit
|
||||
// Akzentkontur überzeichnet (sichtbares Feedback auch ohne Griffe).
|
||||
const highlightDrawPrims = useMemo(() => {
|
||||
const ids =
|
||||
selectedDrawingIds && selectedDrawingIds.length
|
||||
? new Set(selectedDrawingIds)
|
||||
: null;
|
||||
if (!ids) return [];
|
||||
const fromPrims = primsOwnedBy("drawingId", selectedDrawingIds, (p): p is Extract<Primitive, { kind: "line" | "polygon" }> => p.kind === "line" || p.kind === "polygon");
|
||||
// Linien kompakt gehaltener Zeichnungen entstehen nur für die gewählten (wenige).
|
||||
const underIds = getUnderlayIds();
|
||||
if (!underIds || !selectedDrawingIds) return fromPrims;
|
||||
// Pro Gruppe EIN Durchlauf über deren Zeichnungen (statt `find` je gewählter ID:
|
||||
// bei tausenden gewählten Katasterobjekten sonst quadratisch).
|
||||
const extra: Array<Extract<Primitive, { kind: "line" | "polygon" }>> = [];
|
||||
const groups = new Set<NonNullable<ReturnType<typeof underIds.get>>>();
|
||||
for (const id of selectedDrawingIds) {
|
||||
const g = underIds.get(id);
|
||||
if (g) groups.add(g);
|
||||
}
|
||||
for (const g of groups) {
|
||||
const chosen = g.drawings.filter((d) => ids.has(d.id));
|
||||
if (chosen.length) for (const pr of g.build(chosen)) if (pr.kind === "line") extra.push(pr);
|
||||
}
|
||||
return extra.length ? [...fromPrims, ...extra] : fromPrims;
|
||||
}, [plan, selectedDrawingIds]);
|
||||
|
||||
// Hervorhebung ausgewählter TEXT-Objekte (Auswahl-Rahmen, Nutzer-Wunsch):
|
||||
// `drawingText` hat keine `pts`/`a`/`b` wie Linie/Polygon, daher eigener
|
||||
// Zweig statt `highlightDrawPrims` — der Rahmen wird geschätzt, s.
|
||||
// `text/textFrame.ts` `textFrameCorners`. Während des Inline-Editors (`editTextId`) NICHT
|
||||
// zusätzlich zeichnen — der Editor-Rahmen selbst übernimmt dort die Anzeige.
|
||||
const highlightTextFrames = useMemo(() => {
|
||||
const ids =
|
||||
selectedDrawingIds && selectedDrawingIds.length ? new Set(selectedDrawingIds) : null;
|
||||
if (!ids) return [];
|
||||
return primsOwnedBy("drawingId", selectedDrawingIds, (p): p is Extract<Primitive, { kind: "drawingText" }> => p.kind === "drawingText" && p.drawingId !== editTextId);
|
||||
}, [plan, selectedDrawingIds, editTextId]);
|
||||
|
||||
// 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") {
|
||||
const a = toLocal(p.a), b = toLocal(p.b);
|
||||
parts.push(`M${a.x} ${a.y}L${b.x} ${b.y}`);
|
||||
} else if (p.pts.length > 1) {
|
||||
const q = p.pts.map(toLocal);
|
||||
parts.push(`M${q.map((s) => `${s.x} ${s.y}`).join("L")}Z`);
|
||||
}
|
||||
}
|
||||
return parts.join("");
|
||||
}, [highlightDrawPrims, nativeHighlight, toLocal]);
|
||||
overlayHeavyRef.current = highlightDrawPath.length > 300_000;
|
||||
const highlightTextPath = useMemo(() => {
|
||||
const parts: string[] = [];
|
||||
for (const p of highlightTextFrames) {
|
||||
const q = textFrameCorners(p).map(toLocal);
|
||||
parts.push(`M${q.map((s) => `${s.x} ${s.y}`).join("L")}Z`);
|
||||
}
|
||||
return parts.join("");
|
||||
}, [highlightTextFrames, toLocal]);
|
||||
|
||||
// Hervorhebung der selektierten Decken: alle Polygone JEDER gewählten Decke
|
||||
// (Fläche + Umriss) mit Akzentkontur überzeichnen — analog zur Wand-Auswahl.
|
||||
const highlightCeilingPolys = useMemo(() => {
|
||||
const ids =
|
||||
selectedCeilingIds && selectedCeilingIds.length
|
||||
? new Set(selectedCeilingIds)
|
||||
: null;
|
||||
if (!ids) return [];
|
||||
return primsOwnedBy("ceilingId", selectedCeilingIds, (p): p is Extract<Primitive, { kind: "polygon" }> => p.kind === "polygon");
|
||||
}, [plan, selectedCeilingIds]);
|
||||
|
||||
// Hervorhebung der selektierten Öffnungen: alle Symbol-Primitive (Linien/Bögen/
|
||||
// Rahmen) mit der gewählten openingId mit Akzentkontur überzeichnen.
|
||||
const highlightOpeningPrims = useMemo(() => {
|
||||
const ids =
|
||||
selectedOpeningIds && selectedOpeningIds.length
|
||||
? new Set(selectedOpeningIds)
|
||||
: null;
|
||||
if (!ids) return [];
|
||||
return primsOwnedBy("openingId", selectedOpeningIds, (p): p is Extract<Primitive, { kind: "line" | "arc" | "polygon" }> => p.kind === "line" || p.kind === "arc" || p.kind === "polygon");
|
||||
}, [plan, selectedOpeningIds]);
|
||||
|
||||
// Hervorhebung der selektierten Treppen: alle Tritt-/Symbol-Primitive (Polygone
|
||||
// + Linien) mit der gewählten stairId mit Akzentkontur überzeichnen.
|
||||
const highlightStairPrims = useMemo(() => {
|
||||
const ids =
|
||||
selectedStairIds && selectedStairIds.length ? new Set(selectedStairIds) : null;
|
||||
if (!ids) return [];
|
||||
return primsOwnedBy("stairId", selectedStairIds, (p): p is Extract<Primitive, { kind: "line" | "polygon" }> => p.kind === "line" || p.kind === "polygon");
|
||||
}, [plan, selectedStairIds]);
|
||||
|
||||
// Hervorhebung der selektierten Räume: die Fläche JEDES gewählten Raums (Polygon
|
||||
// mit roomId) mit Akzentkontur überzeichnen — analog zur Decken-Auswahl.
|
||||
const highlightRoomPolys = useMemo(() => {
|
||||
const ids =
|
||||
selectedRoomIds && selectedRoomIds.length ? new Set(selectedRoomIds) : null;
|
||||
if (!ids) return [];
|
||||
return primsOwnedBy("roomId", selectedRoomIds, (p): p is Extract<Primitive, { kind: "polygon" }> => p.kind === "polygon");
|
||||
}, [plan, selectedRoomIds]);
|
||||
|
||||
// Hervorhebung der selektierten Dächer: das (unsichtbare) Traufe-Pick-Polygon
|
||||
// mit roofId als Akzentkontur überzeichnen — analog zur Raum-/Decken-Auswahl.
|
||||
const highlightRoofPolys = useMemo(() => {
|
||||
const ids =
|
||||
selectedRoofIds && selectedRoofIds.length ? new Set(selectedRoofIds) : null;
|
||||
if (!ids) return [];
|
||||
return primsOwnedBy("roofId", selectedRoofIds, (p): p is Extract<Primitive, { kind: "polygon" }> => p.kind === "polygon");
|
||||
}, [plan, selectedRoofIds]);
|
||||
|
||||
// Hervorhebung der selektierten Kontext-Objekte (Gebäude/Terrain): das
|
||||
// (unsichtbare) Bbox-Pick-Band mit contextObjectId als Akzentkontur
|
||||
// überzeichnen — analog zur Dach-/Raum-Auswahl.
|
||||
// [137] Gewählte Lage-Darstellung (Schatten/Baurecht): ihre Flächen bzw. Bänder (`@…`-Ids) ebenso.
|
||||
const highlightContextObjectPolys = useMemo(() => {
|
||||
const ids = [
|
||||
...(selectedContextObjectIds ?? []),
|
||||
...(selectedSite ?? []).map((s) => "@" + s),
|
||||
...(selectedTreeIds ?? []).map((s) => TREE_PICK + s),
|
||||
];
|
||||
if (!ids.length) return [];
|
||||
return primsOwnedBy("contextObjectId", ids, (p): p is Extract<Primitive, { kind: "polygon" }> => p.kind === "polygon");
|
||||
}, [plan, selectedContextObjectIds, selectedSite, selectedTreeIds]);
|
||||
|
||||
// Hervorhebung der selektierten Schnitt-/Ansichtslinie: das (unsichtbare)
|
||||
// Pick-Band (Polygon mit sectionLineId) mit Akzentkontur überzeichnen.
|
||||
const highlightSectionLinePolys = useMemo(() => {
|
||||
const ids =
|
||||
selectedSectionLineIds && selectedSectionLineIds.length
|
||||
? new Set(selectedSectionLineIds)
|
||||
: null;
|
||||
if (!ids) return [];
|
||||
return primsOwnedBy("sectionLineId", selectedSectionLineIds, (p): p is Extract<Primitive, { kind: "polygon" }> => p.kind === "polygon");
|
||||
}, [plan, selectedSectionLineIds]);
|
||||
|
||||
// Hervorhebung der selektierten extrudierten Körper (truck-Integration): der
|
||||
// Footprint-Umriss (Polygon mit extrudedSolidId) mit Akzentkontur überzeichnen
|
||||
// — analog zur Raum-Auswahl.
|
||||
const highlightExtrudedSolidPolys = useMemo(() => {
|
||||
const ids =
|
||||
selectedExtrudedSolidIds && selectedExtrudedSolidIds.length
|
||||
? new Set(selectedExtrudedSolidIds)
|
||||
: null;
|
||||
if (!ids) return [];
|
||||
return primsOwnedBy("extrudedSolidId", selectedExtrudedSolidIds, (p): p is Extract<Primitive, { kind: "polygon" }> => p.kind === "polygon");
|
||||
}, [plan, selectedExtrudedSolidIds]);
|
||||
|
||||
// Hervorhebung der selektierten Stützen (Tragwerk): der Querschnitt-Umriss
|
||||
// (Polygon mit columnId) mit Akzentkontur überzeichnen — analog Extrusion/Raum.
|
||||
const highlightColumnPolys = useMemo(() => {
|
||||
const ids =
|
||||
selectedColumnIds && selectedColumnIds.length ? new Set(selectedColumnIds) : null;
|
||||
if (!ids) return [];
|
||||
return primsOwnedBy("columnId", selectedColumnIds, (p): p is Extract<Primitive, { kind: "polygon" }> => p.kind === "polygon");
|
||||
}, [plan, selectedColumnIds]);
|
||||
|
||||
// Primitive des per Listen-Hover vorgemerkten Objekts (Vorschau-Hervorhebung).
|
||||
const hoverPrims = useMemo((): Primitive[] => {
|
||||
if (!hoverPick) return [];
|
||||
if (hoverPick.kind === "site") return primsOwnedBy("contextObjectId", ["@" + hoverPick.id], (_p): _p is Primitive => true);
|
||||
if (hoverPick.kind === "tree") return primsOwnedBy("contextObjectId", [TREE_PICK + hoverPick.id], (_p): _p is Primitive => true);
|
||||
const field: Record<Exclude<PickKind, "site" | "tree">, OwnerField> = {
|
||||
wall: "wallId", drawing: "drawingId", ceiling: "ceilingId", opening: "openingId",
|
||||
stair: "stairId", room: "roomId", roof: "roofId", context: "contextObjectId",
|
||||
section: "sectionLineId", solid: "extrudedSolidId", column: "columnId",
|
||||
};
|
||||
const out: Primitive[] = primsOwnedBy(field[hoverPick.kind], [hoverPick.id], (_p): _p is Primitive => true);
|
||||
if (hoverPick.kind === "drawing") {
|
||||
// Linien kompakt gehaltener Zeichnungen entstehen nur für dieses eine Objekt.
|
||||
const g = getUnderlayIds()?.get(hoverPick.id);
|
||||
const d = g?.drawings.find((x) => x.id === hoverPick.id);
|
||||
if (g && d) for (const pr of g.build([d])) out.push(pr);
|
||||
}
|
||||
return out;
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [hoverPick, plan]);
|
||||
|
||||
return {
|
||||
highlightPolys,
|
||||
highlightDrawPrims,
|
||||
highlightDrawPath,
|
||||
highlightTextPath,
|
||||
highlightCeilingPolys,
|
||||
highlightOpeningPrims,
|
||||
highlightStairPrims,
|
||||
highlightRoomPolys,
|
||||
highlightRoofPolys,
|
||||
highlightContextObjectPolys,
|
||||
highlightSectionLinePolys,
|
||||
highlightExtrudedSolidPolys,
|
||||
highlightColumnPolys,
|
||||
hoverPrims,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,587 @@
|
||||
// Durchschalten übereinanderliegender Objekte in der Plan-Ansicht ([165] aus `PlanView.tsx`): Auswahlliste,
|
||||
// Klick-Zyklen (Cmd/Strg+Klick, einfacher Klick) und `endDrag` (Pointer-Up: Auswahl, Marquee, Drag-Ende).
|
||||
// Aufgerufen einmal von `PlanView`.
|
||||
|
||||
import type { Selection } from "../../../state/selection";
|
||||
import { useState, useEffect, useRef } from "react";
|
||||
import type { PickCandidate, PickIds } from "./types";
|
||||
import type { Plan, Primitive, PickKind } from "../../../core";
|
||||
import type { Vec2 } from "../../../model/types";
|
||||
import type { PlainCycle } from "../pickCycle";
|
||||
import { selectionHas, plainCycleNext, cycleHint } from "../pickCycle";
|
||||
import { t } from "../../../i18n";
|
||||
import { LINE_PICK_PX, TREE_PICK, PICK_ORDER, EMPTY_PICK, MARQUEE_THRESHOLD_PX, cycleModifier } from "./constants";
|
||||
import { planPrimAt, drawingsWithinDistance } from "../../../core";
|
||||
import type { ViewBox__plan_planView_geometry as ViewBox } from "../../../core";
|
||||
import { PlanPickIndex } from "../../../core";
|
||||
import type { UnderlayGroup } from "../../../core";
|
||||
import type { DrawingIndex } from "../../../core";
|
||||
import type { PlanSelection } from "./types";
|
||||
import type { EdgeGrip } from "../../../model/types";
|
||||
import type { GripHandlers } from "./types";
|
||||
import type { BodyTarget } from "./types";
|
||||
import type { ToolHandlers } from "../../../tools/types";
|
||||
import type { MarqueeSelection } from "./types";
|
||||
import type { ModelRect } from "../../../core";
|
||||
|
||||
/** Werte aus `PlanView`, die dieser Hook liest (unverändert, ohne Kopie). */
|
||||
export interface UsePlanPickCycleArgs {
|
||||
selection: Selection;
|
||||
onPickHint: ((hint: string | null) => void) | undefined;
|
||||
view: ViewBox;
|
||||
planRaw: Plan;
|
||||
resetKey: string | undefined;
|
||||
getPick: () => PlanPickIndex;
|
||||
rawModelAt: (clientX: number, clientY: number) => Vec2;
|
||||
getUnderlayIds: () => Map<string, UnderlayGroup> | null;
|
||||
currentPxPerMeter: () => number;
|
||||
plan: Plan;
|
||||
getUnderlayIndex: () => DrawingIndex | null;
|
||||
pickDrawingText: (clientX: number, clientY: number) => string | null;
|
||||
pickDrawingImage: (clientX: number, clientY: number) => string | null;
|
||||
describePick: ((kind: PickKind, id: string) => string | undefined) | undefined;
|
||||
pickOpening: (clientX: number, clientY: number) => string | null;
|
||||
pickColumn: (clientX: number, clientY: number) => string | null;
|
||||
pickExtrudedSolid: (clientX: number, clientY: number) => string | null;
|
||||
pickStair: (clientX: number, clientY: number) => string | null;
|
||||
pickRoom: (clientX: number, clientY: number) => string | null;
|
||||
pickRoof: (clientX: number, clientY: number) => string | null;
|
||||
pickTree: (clientX: number, clientY: number) => string | null;
|
||||
pickSiteAt: (clientX: number, clientY: number) => string | null;
|
||||
pickContextObject: (clientX: number, clientY: number) => string | null;
|
||||
pickSectionLine: (clientX: number, clientY: number) => string | null;
|
||||
onSelect: ((selection: PlanSelection) => void) | undefined;
|
||||
setSelected: React.Dispatch<React.SetStateAction<number | null>>;
|
||||
defaultPick: (clientX: number, clientY: number) => PickIds;
|
||||
clientToView: (clientX: number, clientY: number, vb: ViewBox) => Vec2;
|
||||
viewToModel: (vbX: number, vbY: number) => Vec2;
|
||||
svgRef: React.MutableRefObject<SVGSVGElement | null>;
|
||||
dragMoveRaf: React.MutableRefObject<number | null>;
|
||||
gripDrag: React.MutableRefObject<{ pointerId: number; index: number; origin: Vec2; startX?: number; startY?: number; } | null>;
|
||||
edgeDrag: React.MutableRefObject<{ pointerId: number; edge: EdgeGrip; startX?: number; startY?: number; } | null>;
|
||||
dragMovePending: React.MutableRefObject<{ cx: number; cy: number; shift: boolean; ctrl: boolean; alt: boolean; pointerId: number; } | null>;
|
||||
gripHandlers: GripHandlers | undefined;
|
||||
stampDrag: React.MutableRefObject<{ pointerId: number; roomId: string; last: Vec2; from: Vec2 | null; } | null>;
|
||||
moveDrag: React.MutableRefObject<{ pointerId: number; last: Vec2; startX?: number; startY?: number; target: BodyTarget; } | null>;
|
||||
flushDragMove: () => void;
|
||||
toolActive: boolean;
|
||||
toolHandlers: ToolHandlers | undefined;
|
||||
toolMods: (e: React.PointerEvent | React.MouseEvent) => { shift: boolean; ctrl: boolean; alt: boolean; };
|
||||
marquee: React.MutableRefObject<{ pointerId: number; startClientX: number; startClientY: number; startView: Vec2; moved: boolean; } | null>;
|
||||
onMarquee: ((selection: MarqueeSelection) => void) | undefined;
|
||||
marqueeHitAll: (rect: ModelRect, crossing: boolean) => string[];
|
||||
setMarqueeRect: React.Dispatch<React.SetStateAction<{ x: number; y: number; w: number; h: number; crossing: boolean; } | null>>;
|
||||
drag: React.MutableRefObject<{ pointerId: number; startClientX: number; startClientY: number; startView: ViewBox; } | null>;
|
||||
commitPan: () => void;
|
||||
setDragging: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
}
|
||||
|
||||
export function usePlanPickCycle(inp: UsePlanPickCycleArgs) {
|
||||
const {
|
||||
selection,
|
||||
onPickHint,
|
||||
view,
|
||||
planRaw,
|
||||
resetKey,
|
||||
getPick,
|
||||
rawModelAt,
|
||||
getUnderlayIds,
|
||||
currentPxPerMeter,
|
||||
plan,
|
||||
getUnderlayIndex,
|
||||
pickDrawingText,
|
||||
pickDrawingImage,
|
||||
describePick,
|
||||
pickOpening,
|
||||
pickColumn,
|
||||
pickExtrudedSolid,
|
||||
pickStair,
|
||||
pickRoom,
|
||||
pickRoof,
|
||||
pickTree,
|
||||
pickSiteAt,
|
||||
pickContextObject,
|
||||
pickSectionLine,
|
||||
onSelect,
|
||||
setSelected,
|
||||
defaultPick,
|
||||
clientToView,
|
||||
viewToModel,
|
||||
svgRef,
|
||||
dragMoveRaf,
|
||||
gripDrag,
|
||||
edgeDrag,
|
||||
dragMovePending,
|
||||
gripHandlers,
|
||||
stampDrag,
|
||||
moveDrag,
|
||||
flushDragMove,
|
||||
toolActive,
|
||||
toolHandlers,
|
||||
toolMods,
|
||||
marquee,
|
||||
onMarquee,
|
||||
marqueeHitAll,
|
||||
setMarqueeRect,
|
||||
drag,
|
||||
commitPan,
|
||||
setDragging,
|
||||
} = inp;
|
||||
|
||||
// ── Ü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);
|
||||
// Beim Überfahren eines Listeneintrags wird dieses Objekt im Plan hervorgehoben
|
||||
// (Vorschau, ohne zu wählen) — so erkennt man, welcher Eintrag welches Objekt ist.
|
||||
const [hoverPick, setHoverPick] = useState<PickCandidate | null>(null);
|
||||
useEffect(() => {
|
||||
if (!pickList) setHoverPick(null);
|
||||
}, [pickList]);
|
||||
const cycleRef = useRef<{
|
||||
x: number;
|
||||
y: number;
|
||||
plan: Plan;
|
||||
items: PickCandidate[];
|
||||
idx: number;
|
||||
model: Vec2;
|
||||
/** Zuletzt per Shift dazugewähltes Objekt (für Shift-Durchschalten). */
|
||||
applied?: PickCandidate;
|
||||
/** Liste per Cmd+Shift geöffnet → Klick auf einen Eintrag ERWEITERT die Auswahl. */
|
||||
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);
|
||||
const plainCyclePlan = useRef<Plan | 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;
|
||||
}, [view, planRaw]);
|
||||
// Der Klick-Zyklus überlebt neu erzeugte Pläne (Greifen des Gewählten baut den Plan neu auf): Kandidaten
|
||||
// sind Ids; nur Ausschnitt oder Ebene verwerfen ihn.
|
||||
useEffect(() => {
|
||||
plainCycleRef.current = null;
|
||||
onPickHint?.(null);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [view, resetKey]);
|
||||
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[] => getPick().polygonsAt(rawModelAt(clientX, clientY));
|
||||
|
||||
/** 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");
|
||||
}
|
||||
switch (getPick().drawingKind(id)) {
|
||||
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: 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 pick = getPick();
|
||||
for (const { i, dist } of pick.segmentsNear(m, tol)) {
|
||||
const id = (planPrimAt(plan, i) as Extract<Primitive, { kind: "line" }>).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 { i, dpx } of pick.ringsNear(m, pxPerM, LINE_PICK_PX)) {
|
||||
found.push({ id: (planPrimAt(plan, i) as Extract<Primitive, { kind: "drawingCircle" | "drawingArc" }>).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<string>();
|
||||
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);
|
||||
const base = kind === "drawing" ? drawingLabel(id) : kind === "site" ? t(id === "siteRules" ? "pick.site.siteRules" : id === "viewShadows" ? "pick.site.viewShadows" : "pick.site.sunStudy") : t(`pick.kind.${kind}`);
|
||||
const cat = describePick?.(kind, id);
|
||||
out.push({ kind, id, hitIndex, label: cat ? `${base} · ${cat}` : base });
|
||||
};
|
||||
// 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("tree", dp.treeId, 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("site", dp.siteId, 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 = planPrimAt(plan, 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);
|
||||
if (p.contextObjectId?.startsWith(TREE_PICK)) addRest("tree", p.contextObjectId.slice(TREE_PICK.length), idx);
|
||||
else if (p.contextObjectId?.startsWith("@")) addRest("site", p.contextObjectId.slice(1), idx);
|
||||
else 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("tree", pickTree(clientX, clientY), null);
|
||||
addRest("site", pickSiteAt(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,
|
||||
replaces?: { kind: PickKind; id: string },
|
||||
) => {
|
||||
if (!onSelect) return;
|
||||
setSelected(c.hitIndex);
|
||||
onSelect({
|
||||
...EMPTY_PICK,
|
||||
model,
|
||||
replaces,
|
||||
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,
|
||||
siteId: c.kind === "site" ? c.id : null,
|
||||
treeId: c.kind === "tree" ? 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<SVGSVGElement>): boolean => {
|
||||
const prev = cycleRef.current;
|
||||
const same =
|
||||
prev &&
|
||||
prev.plan === plan &&
|
||||
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);
|
||||
}
|
||||
const replaces =
|
||||
e.shiftKey && same && prev?.applied && prev.applied.id !== items[idx].id
|
||||
? { kind: prev.applied.kind, id: prev.applied.id }
|
||||
: undefined;
|
||||
cycleRef.current = {
|
||||
x: e.clientX,
|
||||
y: e.clientY,
|
||||
plan,
|
||||
items,
|
||||
idx,
|
||||
model,
|
||||
applied: e.shiftKey ? items[idx] : undefined,
|
||||
additive: e.shiftKey,
|
||||
};
|
||||
applyCandidate(items[idx], model, e.shiftKey, replaces);
|
||||
const rect = svgRef.current?.getBoundingClientRect();
|
||||
setPickList({
|
||||
x: e.clientX - (rect?.left ?? 0) + 14,
|
||||
y: e.clientY - (rect?.top ?? 0) + 14,
|
||||
items,
|
||||
idx,
|
||||
});
|
||||
return true;
|
||||
};
|
||||
|
||||
/** [137] Loslassen ohne Bewegung (ohne Shift), und der Klick setzt den Klick-Zyklus fort? */
|
||||
const clickCycles = (e: React.PointerEvent, startX: number | undefined, startY: number | undefined): boolean =>
|
||||
startX !== undefined &&
|
||||
startY !== undefined &&
|
||||
!e.shiftKey &&
|
||||
Math.hypot(e.clientX - startX, e.clientY - startY) < MARQUEE_THRESHOLD_PX &&
|
||||
plainCycleNext(plainCycleRef.current, { x: e.clientX, y: e.clientY, t: Date.now(), planKey: resetKey ?? null }, selection) !== null;
|
||||
|
||||
/** [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: resetKey ?? null }, selection) : null;
|
||||
if (next === null || !pc) return false;
|
||||
pc.idx = next;
|
||||
pc.t = now;
|
||||
const v = clientToView(clientX, clientY, view);
|
||||
// Polygon-Index nur aus demselben Plan (sonst zeigt die lokale Hervorhebung auf ein fremdes Primitiv).
|
||||
const c = pc.items[next];
|
||||
applyCandidate(plainCyclePlan.current === plan ? c : { ...c, hitIndex: null }, 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
|
||||
// committet wird.
|
||||
if (dragMoveRaf.current !== null) {
|
||||
cancelAnimationFrame(dragMoveRaf.current);
|
||||
dragMoveRaf.current = null;
|
||||
}
|
||||
// [137] Klick ohne Bewegung auf einen Griff an der Stelle des letzten Klicks: nächstes Objekt statt Griff
|
||||
// bewaffnen (bei kleinem Massstab liegen die Griffe dicht, z. B. Bemassungsketten 1:500). Nichts wurde
|
||||
// gezogen — Griff ohne Änderung abschliessen.
|
||||
const gd0 = gripDrag.current?.pointerId === e.pointerId ? gripDrag.current : null;
|
||||
const ed0 = edgeDrag.current?.pointerId === e.pointerId ? edgeDrag.current : null;
|
||||
if ((gd0 || ed0) && clickCycles(e, (gd0 ?? ed0)!.startX, (gd0 ?? ed0)!.startY)) {
|
||||
gripDrag.current = null;
|
||||
edgeDrag.current = null;
|
||||
dragMovePending.current = null;
|
||||
if (gd0) gripHandlers?.onGripEnd();
|
||||
else gripHandlers?.onEdgeEnd();
|
||||
plainCycleStep(e.clientX, e.clientY);
|
||||
return;
|
||||
}
|
||||
if (
|
||||
(edgeDrag.current && edgeDrag.current.pointerId === e.pointerId) ||
|
||||
(gripDrag.current && gripDrag.current.pointerId === e.pointerId) ||
|
||||
(stampDrag.current && stampDrag.current.pointerId === e.pointerId) ||
|
||||
(moveDrag.current && moveDrag.current.pointerId === e.pointerId)
|
||||
) {
|
||||
dragMovePending.current = {
|
||||
cx: e.clientX,
|
||||
cy: e.clientY,
|
||||
shift: e.shiftKey,
|
||||
ctrl: e.ctrlKey || e.metaKey,
|
||||
alt: e.altKey,
|
||||
pointerId: e.pointerId,
|
||||
};
|
||||
flushDragMove();
|
||||
}
|
||||
|
||||
// Stempel-Griff loslassen: Ziehen abschließen.
|
||||
const sd = stampDrag.current;
|
||||
if (sd && sd.pointerId === e.pointerId) {
|
||||
if (e.currentTarget.hasPointerCapture(e.pointerId)) {
|
||||
e.currentTarget.releasePointerCapture(e.pointerId);
|
||||
}
|
||||
stampDrag.current = null;
|
||||
return;
|
||||
}
|
||||
// Kanten-Griff: Maus loslassen beendet die Bearbeitung NICHT mehr — kein
|
||||
// Pointer-Capture gehalten, der Griff bleibt bewaffnet und folgt weiter dem
|
||||
// Cursor. Abschluss erst per erneutem Klick (oben in onPointerDown) oder
|
||||
// Enter, Verwerfen per Escape (beides im Tastatur-Effekt unten).
|
||||
if (edgeDrag.current && edgeDrag.current.pointerId === e.pointerId) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Editier-Griff: Maus loslassen beendet die Bearbeitung NICHT mehr — kein
|
||||
// Pointer-Capture gehalten, der Griff bleibt bewaffnet und folgt weiter dem
|
||||
// Cursor. Abschluss erst per erneutem Klick (oben in onPointerDown) oder
|
||||
// Enter, Verwerfen per Escape (beides im Tastatur-Effekt unten).
|
||||
if (gripDrag.current && gripDrag.current.pointerId === e.pointerId) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Körper-Verschieben loslassen.
|
||||
const md = moveDrag.current;
|
||||
if (md && md.pointerId === e.pointerId) {
|
||||
if (e.currentTarget.hasPointerCapture(e.pointerId)) {
|
||||
e.currentTarget.releasePointerCapture(e.pointerId);
|
||||
}
|
||||
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 (clickCycles(e, md.startX, md.startY)) plainCycleStep(e.clientX, e.clientY);
|
||||
return;
|
||||
}
|
||||
|
||||
// Aktives Zeichenwerkzeug: linke Taste loslassen = Punkt setzen (Klick).
|
||||
if (toolActive && e.button === 0) {
|
||||
if (e.currentTarget.hasPointerCapture(e.pointerId)) {
|
||||
e.currentTarget.releasePointerCapture(e.pointerId);
|
||||
}
|
||||
toolHandlers!.onToolClick(
|
||||
rawModelAt(e.clientX, e.clientY),
|
||||
currentPxPerMeter(),
|
||||
toolMods(e),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Marquee/Klick (linke Taste) abschließen.
|
||||
const mq = marquee.current;
|
||||
if (mq && mq.pointerId === e.pointerId) {
|
||||
if (e.currentTarget.hasPointerCapture(e.pointerId)) {
|
||||
e.currentTarget.releasePointerCapture(e.pointerId);
|
||||
}
|
||||
marquee.current = null;
|
||||
if (mq.moved) {
|
||||
// Echtes Auswahl-Rechteck: Wände nach CAD-Konvention bestimmen und nach
|
||||
// oben melden. Das Rechteck stand zuletzt in marqueeRect (viewBox-Raum)
|
||||
// → in Modell-Raum umrechnen und gegen die Wand-Polygone testen.
|
||||
const cur = clientToView(e.clientX, e.clientY, view);
|
||||
const crossing = e.clientX - mq.startClientX < 0;
|
||||
const a = viewToModel(mq.startView.x, mq.startView.y);
|
||||
const b = viewToModel(cur.x, cur.y);
|
||||
const rect = {
|
||||
minX: Math.min(a.x, b.x),
|
||||
minY: Math.min(a.y, b.y),
|
||||
maxX: Math.max(a.x, b.x),
|
||||
maxY: Math.max(a.y, b.y),
|
||||
};
|
||||
if (onMarquee) {
|
||||
onMarquee({
|
||||
wallIds: getPick().marquee("wallId", rect, crossing),
|
||||
drawingIds: marqueeHitAll(rect, crossing),
|
||||
ceilingIds: getPick().marquee("ceilingId", rect, crossing),
|
||||
roomIds: getPick().marquee("roomId", rect, crossing),
|
||||
stairIds: getPick().marquee("stairId", rect, crossing),
|
||||
// [149] Bäume: Kronen-Pickfläche (`contextObjectId = "@tree:<id>"`).
|
||||
treeIds: getPick()
|
||||
.marquee("contextObjectId", rect, crossing)
|
||||
.filter((id) => id.startsWith(TREE_PICK))
|
||||
.map((id) => id.slice(TREE_PICK.length)),
|
||||
crossing,
|
||||
});
|
||||
}
|
||||
// Die lokale Einzel-Hervorhebung räumen (jetzt gilt die Mengenauswahl).
|
||||
setSelected(null);
|
||||
setMarqueeRect(null);
|
||||
return;
|
||||
}
|
||||
// Kein Drag → Klick: Objekt unter dem Cursor wählen bzw. Auswahl löschen.
|
||||
setMarqueeRect(null);
|
||||
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: resetKey ?? null, items, idx: 0 } : null;
|
||||
plainCyclePlan.current = plan;
|
||||
onPickHint?.(cycleHint(items.length, 0));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const d = drag.current;
|
||||
if (!d || d.pointerId !== e.pointerId) return;
|
||||
if (e.currentTarget.hasPointerCapture(e.pointerId)) {
|
||||
e.currentTarget.releasePointerCapture(e.pointerId);
|
||||
}
|
||||
// Imperativen GL-Pan in React-State übernehmen (Ausschnitt final festschreiben).
|
||||
commitPan();
|
||||
drag.current = null;
|
||||
setDragging(false);
|
||||
};
|
||||
|
||||
return {
|
||||
pickList,
|
||||
setPickList,
|
||||
hoverPick,
|
||||
setHoverPick,
|
||||
cycleRef,
|
||||
applyCandidate,
|
||||
endDrag,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,409 @@
|
||||
// Treffer-Abfragen der Plan-Ansicht ([165] aus `PlanView.tsx`): welches Bauteil, 2D-Element, Lage-Objekt
|
||||
// oder welcher Baum liegt unter dem Cursor (über den Pick-Index im Kern), dazu die Hover-Teilpunkte,
|
||||
// der gegriffene Körper und die Marquee-Treffer. Aufgerufen einmal von `PlanView`.
|
||||
|
||||
import type { GroupableHit, BodyTarget } from "./types";
|
||||
import { planPrimAt, nearestInDrawings, marqueeHitUnderlay } from "../../../core";
|
||||
import { LINE_PICK_PX, TREE_PICK } from "./constants";
|
||||
import type { Primitive, ModelRect } from "../../../core";
|
||||
import type { Vec2 } from "../../../model/types";
|
||||
import { useState, useRef, useEffect } from "react";
|
||||
import type { ViewBox__plan_planView_geometry as ViewBox } from "../../../core";
|
||||
import { PlanPickIndex } from "../../../core";
|
||||
import type { Plan } from "../../../core";
|
||||
import type { DrawingIndex } from "../../../core";
|
||||
import type { ClientMap } from "../../../core";
|
||||
import type { UnderlayGroup } from "../../../core";
|
||||
import type { Drawing2D } from "../../../model/types";
|
||||
|
||||
/** Werte aus `PlanView`, die dieser Hook liest (unverändert, ohne Kopie). */
|
||||
export interface UsePlanPickingArgs {
|
||||
clientToView: (clientX: number, clientY: number, vb: ViewBox) => Vec2;
|
||||
view: ViewBox;
|
||||
getPick: () => PlanPickIndex;
|
||||
viewToModel: (vbX: number, vbY: number) => Vec2;
|
||||
plan: Plan;
|
||||
currentPxPerMeter: () => number;
|
||||
rawModelAt: (clientX: number, clientY: number) => Vec2;
|
||||
getUnderlayIndex: () => DrawingIndex | null;
|
||||
clientMap: () => ClientMap;
|
||||
hoverDivideDelayMs: number;
|
||||
toolActive: boolean;
|
||||
sheetBodies: boolean;
|
||||
selectedOpeningIds: string[];
|
||||
selectedCeilingIds: string[];
|
||||
selectedStairIds: string[];
|
||||
selectedWallIds: string[];
|
||||
selectedDrawingIds: string[];
|
||||
selectedDrawingId: string | null;
|
||||
getUnderlayIds: () => Map<string, UnderlayGroup> | null;
|
||||
getUnderlay: () => { key: UnderlayGroup[]; drawings: Drawing2D[]; index?: DrawingIndex | null; ids?: Map<string, UnderlayGroup>; } | null;
|
||||
}
|
||||
|
||||
export function usePlanPicking(inp: UsePlanPickingArgs) {
|
||||
const {
|
||||
clientToView,
|
||||
view,
|
||||
getPick,
|
||||
viewToModel,
|
||||
plan,
|
||||
currentPxPerMeter,
|
||||
rawModelAt,
|
||||
getUnderlayIndex,
|
||||
clientMap,
|
||||
hoverDivideDelayMs,
|
||||
toolActive,
|
||||
sheetBodies,
|
||||
selectedOpeningIds,
|
||||
selectedCeilingIds,
|
||||
selectedStairIds,
|
||||
selectedWallIds,
|
||||
selectedDrawingIds,
|
||||
selectedDrawingId,
|
||||
getUnderlayIds,
|
||||
getUnderlay,
|
||||
} = inp;
|
||||
|
||||
// Trefferprüfung: liefert den Index des obersten Polygon-Primitivs unter dem
|
||||
// Cursor (Modellpunkt in einem Schicht-Polygon) oder null. In umgekehrter
|
||||
// Reihenfolge testen, damit das zuletzt gezeichnete (oberste) zuerst trifft.
|
||||
// [137] Übersprungen werden Flächen ohne Bauteil: Darstellung ohne Id (Schlagschatten der Ansicht,
|
||||
// Baurechts-Verstösse, Muster) und unsichtbare Pick-Bänder (Gelände-Rahmen, Baugrube, Schatten, Schnittlinie)
|
||||
// — sie lagen sonst über Wänden und Decken und machten diese unwählbar. Eine sichtbare Kontext-Fläche
|
||||
// (Gelände in der Ansicht) verdeckt dagegen wie bisher.
|
||||
const hitTest = (clientX: number, clientY: number): number | null => {
|
||||
const v = clientToView(clientX, clientY, view);
|
||||
// Unter einem Gelände-/Baugruben-Band zählt die leere Innenfläche einer 2D-Kontur (z. B. Parzelle) nicht:
|
||||
// dort meint der Klick das Gelände (die Kontur bleibt über ihre Linie wählbar) — wie vor [137].
|
||||
const pick = getPick();
|
||||
let underBand = false;
|
||||
for (const i of pick.polygonsAt(viewToModel(v.x, v.y))) {
|
||||
const p = pick.prim(i);
|
||||
if (p?.kind !== "polygon") continue;
|
||||
if (p.wallId || p.drawingId || p.ceilingId || p.openingId || p.stairId || p.roomId || p.extrudedSolidId || p.columnId || p.roofId) {
|
||||
const emptyArea = p.drawingId && p.fill === "none" && (!p.hatch || p.hatch.pattern === "none");
|
||||
return underBand && emptyArea ? null : i;
|
||||
}
|
||||
// Lage-Darstellung (`@…`: Schlagschatten der Ansicht, Schatten, Baurecht) verdeckt nie — sie liegt auf den
|
||||
// Bauteilen und wird erst nach ihnen gewählt (bzw. per erneutem Klick, [137] Klick-Zyklus).
|
||||
if (((p.contextObjectId && !p.contextObjectId.startsWith("@")) || p.sectionLineId) && p.fill !== "none") return i;
|
||||
if (p.contextObjectId && !p.contextObjectId.startsWith("@")) underBand = true;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
// Irgendein Element (Wand/Decke/Raum/Treppe/Stütze/Dach/2D) unter dem
|
||||
// Cursor — für Gruppen-Eintritt per Doppelklick (`onEnterGroup`). Nutzt
|
||||
// `hitTest` (Polygon-Primitive, deckt alle flächigen Bauteile ab) und
|
||||
// fällt für linienbasierte 2D-Elemente auf `pickDrawing` zurück (das
|
||||
// selbst erst nach dessen Definition unten verfügbar ist, daher als
|
||||
// separate Closure statt inline hier).
|
||||
const anyGroupableHit = (clientX: number, clientY: number): GroupableHit | null => {
|
||||
const idx = hitTest(clientX, clientY);
|
||||
if (idx !== null) {
|
||||
const p = planPrimAt(plan, idx);
|
||||
if (p?.kind === "polygon") {
|
||||
if (p.wallId) return { wallId: p.wallId };
|
||||
if (p.ceilingId) return { ceilingId: p.ceilingId };
|
||||
if (p.roomId) return { roomId: p.roomId };
|
||||
if (p.stairId) return { stairId: p.stairId };
|
||||
if (p.columnId) return { columnId: p.columnId };
|
||||
if (p.roofId) return { roofId: p.roofId };
|
||||
if (p.drawingId) return { drawingId: p.drawingId };
|
||||
}
|
||||
}
|
||||
const did = pickDrawing(clientX, clientY);
|
||||
return did ? { drawingId: did } : null;
|
||||
};
|
||||
|
||||
// Nächstgelegenes 2D-Zeichenelement (Drawing2D) zum Cursor per Linien-Nähe in
|
||||
// Bildschirm-Pixeln (zoom-unabhängige Toleranz). Liefert die drawingId oder null.
|
||||
const pickDrawing = (clientX: number, clientY: number): string | null => {
|
||||
let bestId: string | null = null;
|
||||
let bestDist = LINE_PICK_PX;
|
||||
const pick = getPick();
|
||||
const pxPerM = currentPxPerMeter();
|
||||
const m = rawModelAt(clientX, clientY);
|
||||
const seg = pick.nearestSegment(m, LINE_PICK_PX / pxPerM);
|
||||
if (seg) {
|
||||
bestId = (planPrimAt(plan, seg.i) as Extract<Primitive, { kind: "line" }>).drawingId!;
|
||||
bestDist = seg.dist * pxPerM;
|
||||
}
|
||||
const uIndex = getUnderlayIndex();
|
||||
if (uIndex) {
|
||||
const hit = nearestInDrawings(uIndex, m, bestDist / pxPerM);
|
||||
if (hit) {
|
||||
bestId = hit.drawing.id;
|
||||
bestDist = hit.dist * pxPerM;
|
||||
}
|
||||
}
|
||||
// Kreise/Bögen (Ring-Abstand wie früher `distToDrawingRing`), in Plan-Reihenfolge.
|
||||
for (const { i, dpx } of pick.ringsNear(m, pxPerM, LINE_PICK_PX)) {
|
||||
if (dpx < bestDist) {
|
||||
bestDist = dpx;
|
||||
bestId = (planPrimAt(plan, i) as Extract<Primitive, { kind: "drawingCircle" | "drawingArc" }>).drawingId!;
|
||||
}
|
||||
}
|
||||
if (bestId) return bestId;
|
||||
// Kein Linien-/Kreis-/Bogen-Treffer: Text- dann Bild-Elemente prüfen (eigene Bbox-Logik).
|
||||
return pickDrawingText(clientX, clientY) ?? pickDrawingImage(clientX, clientY);
|
||||
};
|
||||
|
||||
// Nächstgelegenes EINZELNES Geraden-Segment (nicht das ganze Element) für
|
||||
// die Hover-Teilpunkte-Anzeige (s. hoverDivideSeg unten) — dieselbe Nähe-
|
||||
// Logik wie pickDrawing, liefert aber die zwei Endpunkte des getroffenen
|
||||
// Segments selbst: eine Polylinie besteht aus mehreren "line"-Primitiven
|
||||
// (eins je Segment, gleiche drawingId), unterteilt werden soll nur das
|
||||
// konkret gehoverte Segment, nicht das ganze Element.
|
||||
const nearestLineSegment = (clientX: number, clientY: number): { a: Vec2; b: Vec2 } | null => {
|
||||
const m = rawModelAt(clientX, clientY);
|
||||
const maxDist = LINE_PICK_PX / currentPxPerMeter();
|
||||
let best: { a: Vec2; b: Vec2 } | null = null;
|
||||
let bestDist = maxDist;
|
||||
const seg = getPick().nearestSegment(m, maxDist);
|
||||
if (seg) {
|
||||
const p = planPrimAt(plan, seg.i) as Extract<Primitive, { kind: "line" }>;
|
||||
best = { a: p.a, b: p.b };
|
||||
bestDist = seg.dist;
|
||||
}
|
||||
const uIndex = getUnderlayIndex();
|
||||
if (uIndex) {
|
||||
const hit = nearestInDrawings(uIndex, m, bestDist);
|
||||
if (hit) best = { a: hit.a, b: hit.b };
|
||||
}
|
||||
return best;
|
||||
};
|
||||
|
||||
// Trifft der Klick ein Text-2D-Element (kind "drawingText")? Grosszügige Modell-
|
||||
// Bounding-Box um den Ankerpunkt (Text hat keine Linien-Geometrie zum Anfassen; Winkel
|
||||
// vernachlässigt) — im Kern (`plan_pick.rs`). Liefert die drawingId oder null.
|
||||
const pickDrawingText = (clientX: number, clientY: number): string | null => {
|
||||
const pick = getPick();
|
||||
const i = pick.drawingTextAt(rawModelAt(clientX, clientY));
|
||||
return i === null ? null : ((pick.prim(i) as { drawingId?: string }).drawingId ?? null);
|
||||
};
|
||||
|
||||
// Trifft der Klick ein Bild-2D-Element (kind "drawingImage")? Reine Bounding-Box-Prüfung
|
||||
// (achsparallel, oberstes zuerst). Liefert die drawingId oder null.
|
||||
const pickDrawingImage = (clientX: number, clientY: number): string | null => {
|
||||
const pick = getPick();
|
||||
const i = pick.drawingImageAt(rawModelAt(clientX, clientY));
|
||||
return i === null ? null : ((pick.prim(i) as { drawingId?: string }).drawingId ?? null);
|
||||
};
|
||||
|
||||
// Nächstgelegene Öffnung (Fenster/Tür) zum Cursor: Linien-/Bogen-Primitive mit
|
||||
// `openingId` per Bildschirm-Nähe, plus getroffene Fenster-Rahmen (Polygon mit
|
||||
// openingId, per Punkt-in-Polygon). Liefert die openingId oder null.
|
||||
const pickOpening = (clientX: number, clientY: number): string | null => {
|
||||
const v = clientToView(clientX, clientY, view);
|
||||
const m = viewToModel(v.x, v.y);
|
||||
const pick = getPick();
|
||||
// Getroffener Rahmen (das zuerst gezeichnete Polygon) hat Vorrang vor Symbol-Linien.
|
||||
const hit = pick.bottomPolygon(m, "openingId");
|
||||
if (hit !== null) return (planPrimAt(plan, hit) as { openingId?: string }).openingId!;
|
||||
const i = pick.nearestSymbolPx(["openingId"], ["openingId"], clientMap(), { x: clientX, y: clientY }, LINE_PICK_PX);
|
||||
return i === null ? null : (planPrimAt(plan, i) as { openingId?: string }).openingId!;
|
||||
};
|
||||
|
||||
// Nächstgelegene Treppe zum Cursor: getroffenes Tritt-/Podest-Polygon (per
|
||||
// Punkt-in-Polygon), sonst eine nahe Symbollinie (Lauflinie/Pfeil) mit stairId.
|
||||
const pickStair = (clientX: number, clientY: number): string | null => {
|
||||
const v = clientToView(clientX, clientY, view);
|
||||
const m = viewToModel(v.x, v.y);
|
||||
const pick = getPick();
|
||||
const hit = pick.bottomPolygon(m, "stairId");
|
||||
if (hit !== null) return (planPrimAt(plan, hit) as { stairId?: string }).stairId!;
|
||||
const i = pick.nearestSymbolPx(["stairId"], [], clientMap(), { x: clientX, y: clientY }, LINE_PICK_PX);
|
||||
return i === null ? null : (planPrimAt(plan, i) as { stairId?: string }).stairId!;
|
||||
};
|
||||
|
||||
// Getroffener Raum: die Raum-Fläche (Polygon mit `roomId`) per Punkt-in-Polygon.
|
||||
// Bei überlappenden Räumen gewinnt der zuletzt gezeichnete (oberste).
|
||||
const pickRoom = (clientX: number, clientY: number): string | null => {
|
||||
const v = clientToView(clientX, clientY, view);
|
||||
const i = getPick().topPolygon(viewToModel(v.x, v.y), "roomId");
|
||||
return i === null ? null : (planPrimAt(plan, i) as { roomId?: string }).roomId!;
|
||||
};
|
||||
|
||||
// Getroffenes Dach: das unsichtbare Traufe-Pick-Polygon per Punkt-in-Polygon
|
||||
// (die sichtbaren Dachlinien allein wären schwer exakt zu treffen).
|
||||
const pickRoof = (clientX: number, clientY: number): string | null => {
|
||||
const v = clientToView(clientX, clientY, view);
|
||||
const i = getPick().topPolygon(viewToModel(v.x, v.y), "roofId");
|
||||
return i === null ? null : (planPrimAt(plan, i) as { roofId?: string }).roofId!;
|
||||
};
|
||||
|
||||
// Getroffene Schnitt-/Ansichtslinie: ihr schmales, unsichtbares Pick-Band
|
||||
// (Polygon mit sectionLineId) per Punkt-in-Polygon.
|
||||
const pickSectionLine = (clientX: number, clientY: number): string | null => {
|
||||
const v = clientToView(clientX, clientY, view);
|
||||
const i = getPick().topPolygon(viewToModel(v.x, v.y), "sectionLineId");
|
||||
return i === null ? null : (planPrimAt(plan, i) as { sectionLineId?: string }).sectionLineId!;
|
||||
};
|
||||
|
||||
// Getroffenes Kontext-Objekt (importiertes Gebäude/Terrain): sein unsichtbares
|
||||
// Grundriss-Pick-Band (Bounding-Box) per Punkt-in-Polygon — macht es wie eine
|
||||
// Wand irgendwo innerhalb seiner Fläche anklickbar, nicht nur exakt auf der
|
||||
// dünnen Umrisslinie.
|
||||
// Pick-Ids unter dem Cursor im Feld `contextObjectId`, oberste zuerst. Die abgeleitete Lage-Darstellung
|
||||
// ([137], Kern `plan/extras.rs`) trägt dort `@sunStudy`/`@siteRules` (Schattenflächen, Baurechts-Bänder).
|
||||
const contextIdsAt = (clientX: number, clientY: number): string[] => {
|
||||
const v = clientToView(clientX, clientY, view);
|
||||
const pick = getPick();
|
||||
return pick.polygonsAt(viewToModel(v.x, v.y), "contextObjectId").map((i) => (pick.prim(i) as { contextObjectId?: string }).contextObjectId!);
|
||||
};
|
||||
|
||||
// [137] Getroffene Lage-Darstellung: Quelle `"sunStudy"`/`"siteRules"` (Baurechtslinie vor Schatten) oder null.
|
||||
const pickSiteAt = (clientX: number, clientY: number): string | null => {
|
||||
const ids = contextIdsAt(clientX, clientY).filter((id) => id.startsWith("@") && !id.startsWith(TREE_PICK));
|
||||
const id = ids.find((x) => x === "@siteRules") ?? ids[0];
|
||||
return id ? id.slice(1) : null;
|
||||
};
|
||||
|
||||
// [149] Getroffener Baum (oberste Kronenfläche) oder null.
|
||||
const pickTree = (clientX: number, clientY: number): string | null => {
|
||||
const id = contextIdsAt(clientX, clientY).find((x) => x.startsWith(TREE_PICK));
|
||||
return id ? id.slice(TREE_PICK.length) : null;
|
||||
};
|
||||
|
||||
const pickContextObject = (clientX: number, clientY: number): string | null =>
|
||||
contextIdsAt(clientX, clientY).find((id) => !id.startsWith("@")) ?? null;
|
||||
|
||||
// Getroffener extrudierter Körper (truck-Integration): der Footprint-Umriss
|
||||
// ist ein reiner Haarlinien-Umriss (fill:"none"), aber per Punkt-in-Polygon
|
||||
// trotzdem als FLÄCHE anklickbar (analog Raum, nicht nur auf der Linie).
|
||||
const pickExtrudedSolid = (clientX: number, clientY: number): string | null => {
|
||||
const v = clientToView(clientX, clientY, view);
|
||||
const i = getPick().topPolygon(viewToModel(v.x, v.y), "extrudedSolidId");
|
||||
return i === null ? null : (planPrimAt(plan, i) as { extrudedSolidId?: string }).extrudedSolidId!;
|
||||
};
|
||||
|
||||
// Getroffene Stütze (Tragwerk): ihr Querschnitt ist eine gefüllte Poché
|
||||
// (Polygon mit columnId) — per Punkt-in-Polygon als FLÄCHE anklickbar.
|
||||
const pickColumn = (clientX: number, clientY: number): string | null => {
|
||||
const v = clientToView(clientX, clientY, view);
|
||||
const i = getPick().topPolygon(viewToModel(v.x, v.y), "columnId");
|
||||
return i === null ? null : (planPrimAt(plan, i) as { columnId?: string }).columnId!;
|
||||
};
|
||||
|
||||
// Hover-Teilpunkte (Nutzer-Wunsch): ruht der Cursor im Auswahl-Ruhezustand
|
||||
// (kein Werkzeug/Drag/Marquee — s. Aufruf in onPointerMove) länger als
|
||||
// `hoverDivideDelayMs` auf einem 2D-Linien-Segment, werden dessen gleiche
|
||||
// Teilpunkte (Anzahl `hoverDivideCount`, 2 = nur Mitte) kurz mit
|
||||
// Akzentfarbe eingeblendet. Reine Sichtbarkeits-Hilfe, kein Snap-Ziel.
|
||||
const [hoverDivideSeg, setHoverDivideSeg] = useState<{ a: Vec2; b: Vec2 } | null>(null);
|
||||
// Zuletzt erkanntes Segment (Serialisiert als Schlüssel) — erkennt einen
|
||||
// Wechsel, ohne bei jedem Move-Event neu zu timern.
|
||||
const hoverDivideKeyRef = useRef<string | null>(null);
|
||||
const hoverDivideTimerRef = useRef<number | null>(null);
|
||||
|
||||
// Nächstliegendes Linien-Segment unterm Cursor ermitteln und die
|
||||
// Hover-Teilpunkte-Anzeige entsprechend (neu) timern/verwerfen.
|
||||
const updateHoverDivide = (clientX: number, clientY: number) => {
|
||||
const seg = nearestLineSegment(clientX, clientY);
|
||||
const key = seg ? `${seg.a.x},${seg.a.y}|${seg.b.x},${seg.b.y}` : null;
|
||||
if (key === hoverDivideKeyRef.current) return; // dasselbe Segment (oder weiter keins)
|
||||
hoverDivideKeyRef.current = key;
|
||||
if (hoverDivideTimerRef.current !== null) {
|
||||
window.clearTimeout(hoverDivideTimerRef.current);
|
||||
hoverDivideTimerRef.current = null;
|
||||
}
|
||||
setHoverDivideSeg(null); // Segment gewechselt → alte Anzeige sofort weg
|
||||
if (!seg) return;
|
||||
hoverDivideTimerRef.current = window.setTimeout(() => {
|
||||
hoverDivideTimerRef.current = null;
|
||||
setHoverDivideSeg(seg);
|
||||
}, hoverDivideDelayMs);
|
||||
};
|
||||
const clearHoverDivide = () => {
|
||||
if (hoverDivideTimerRef.current !== null) {
|
||||
window.clearTimeout(hoverDivideTimerRef.current);
|
||||
hoverDivideTimerRef.current = null;
|
||||
}
|
||||
hoverDivideKeyRef.current = null;
|
||||
setHoverDivideSeg(null);
|
||||
};
|
||||
// Weg, sobald ein Werkzeug aktiv wird (sonst könnte eine veraltete Anzeige
|
||||
// ohne weiteres Move-Event über einem neuen Werkzeug-Entwurf stehen bleiben).
|
||||
useEffect(() => {
|
||||
if (toolActive) clearHoverDivide();
|
||||
}, [toolActive]);
|
||||
useEffect(() => () => clearHoverDivide(), []);
|
||||
|
||||
// Liegt der Cursor auf dem KÖRPER eines GEWÄHLTEN Elements (Wand-Poché bzw.
|
||||
// 2D-Linie)? Liefert das gegriffene Element (Wand-ID ODER Drawing-ID) für das
|
||||
// Parallel-Verschieben — oder null. Bei MEHRFACHAUSWAHL wird das Element UNTER
|
||||
// dem Cursor gegriffen; die übrigen gewählten Enden wandern (App) koinzident mit.
|
||||
const grabbedBody = (
|
||||
clientX: number,
|
||||
clientY: number,
|
||||
): BodyTarget | null => {
|
||||
// Schnitt/Ansicht: gewählte Öffnung bzw. Decke unter dem Cursor (Vorrang vor
|
||||
// der Wirtswand, die im Blatt dahinter liegt).
|
||||
if (sheetBodies) {
|
||||
const hi = hitTest(clientX, clientY);
|
||||
const p = hi !== null ? planPrimAt(plan, hi) ?? null : null;
|
||||
if (p && "openingId" in p && p.openingId && selectedOpeningIds?.includes(p.openingId)) {
|
||||
return { openingId: p.openingId };
|
||||
}
|
||||
if (p && p.kind === "polygon" && p.ceilingId && selectedCeilingIds?.includes(p.ceilingId)) {
|
||||
return { ceilingId: p.ceilingId };
|
||||
}
|
||||
if (p && p.kind === "polygon" && p.stairId && selectedStairIds?.includes(p.stairId)) {
|
||||
return { stairId: p.stairId };
|
||||
}
|
||||
}
|
||||
const selWalls = new Set(selectedWallIds ?? []);
|
||||
if (selWalls.size) {
|
||||
const hi = hitTest(clientX, clientY);
|
||||
if (hi !== null) {
|
||||
const p = planPrimAt(plan, hi);
|
||||
if (p?.kind === "polygon" && p.wallId && selWalls.has(p.wallId)) {
|
||||
return { wallId: p.wallId };
|
||||
}
|
||||
}
|
||||
}
|
||||
const selDraws = selectedDrawingIds && selectedDrawingIds.length
|
||||
? new Set(selectedDrawingIds)
|
||||
: selectedDrawingId
|
||||
? new Set([selectedDrawingId])
|
||||
: null;
|
||||
if (selDraws) {
|
||||
const id = pickDrawing(clientX, clientY);
|
||||
if (id && selDraws.has(id)) return { drawingId: id };
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
// Marquee über Zeichnungen: Primitive (ohne die der kompakten Unterlage, deren
|
||||
// Polygon-Punkte allein sonst ein anderes Ergebnis lieferten) + Unterlage.
|
||||
const marqueeHitAll = (rect: ModelRect, crossing: boolean): string[] => {
|
||||
const ids = getUnderlayIds();
|
||||
const fromPrims = getPick().marqueeDrawings(rect, crossing, ids?.keys());
|
||||
const u = getUnderlay();
|
||||
return u ? [...fromPrims, ...marqueeHitUnderlay(u.drawings, rect, crossing)] : fromPrims;
|
||||
};
|
||||
|
||||
return {
|
||||
hitTest,
|
||||
anyGroupableHit,
|
||||
pickDrawing,
|
||||
pickDrawingText,
|
||||
pickDrawingImage,
|
||||
pickOpening,
|
||||
pickStair,
|
||||
pickRoom,
|
||||
pickRoof,
|
||||
pickSectionLine,
|
||||
pickSiteAt,
|
||||
pickTree,
|
||||
pickContextObject,
|
||||
pickExtrudedSolid,
|
||||
pickColumn,
|
||||
hoverDivideSeg,
|
||||
updateHoverDivide,
|
||||
clearHoverDivide,
|
||||
grabbedBody,
|
||||
marqueeHitAll,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,680 @@
|
||||
// Zeiger-Eingabe der Plan-Ansicht ([165] aus `PlanView.tsx`): `onPointerDown`/`onPointerMove`, imperativer
|
||||
// Pan/Zoom im GPU-Pfad (SVG-Transform, Frame-Drosselung), Drosselung modell-ändernder Drags und die
|
||||
// Standard-Auswahl (`defaultPick`). Aufgerufen einmal von `PlanView`.
|
||||
|
||||
import type { MeetStore, ValueStore } from "./liveMeet";
|
||||
import { cycleModifier, MARQUEE_THRESHOLD_PX, EMPTY_PICK } from "./constants";
|
||||
import { useRef, useEffect } from "react";
|
||||
import type { ViewBox__plan_planView_geometry as ViewBox } from "../../../core";
|
||||
import { localViewBoxAttr } from "./overlayOrigin";
|
||||
import { meetScale, planPrimAt } from "../../../core";
|
||||
import type { PickIds } from "./types";
|
||||
import type { Vec2 } from "../../../model/types";
|
||||
import type { GripHandlers } from "./types";
|
||||
import type { EdgeGrip } from "../../../model/types";
|
||||
import type { ToolHandlers } from "../../../tools/types";
|
||||
import type { BodyTarget } from "./types";
|
||||
import type { Plan } from "../../../core";
|
||||
|
||||
/** Werte aus `PlanView`, die dieser Hook liest (unverändert, ohne Kopie). */
|
||||
export interface UsePlanPointerArgs {
|
||||
gripDrag: React.MutableRefObject<{ pointerId: number; index: number; origin: Vec2; startX?: number; startY?: number; } | null>;
|
||||
gripHandlers: GripHandlers | undefined;
|
||||
edgeDrag: React.MutableRefObject<{ pointerId: number; edge: EdgeGrip; startX?: number; startY?: number; } | null>;
|
||||
toolActive: boolean;
|
||||
onStampEdit: ((roomId: string) => void) | undefined;
|
||||
lastClickRef: React.MutableRefObject<{ t: number; x: number; y: number; } | null>;
|
||||
stampHandleAt: (clientX: number, clientY: number) => string | null;
|
||||
pickRoom: (clientX: number, clientY: number) => string | null;
|
||||
drag: React.MutableRefObject<{ pointerId: number; startClientX: number; startClientY: number; startView: ViewBox; } | null>;
|
||||
view: ViewBox;
|
||||
setDragging: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
onSegmentCut: ((drawingId: string, model: Vec2) => void) | undefined;
|
||||
pickDrawing: (clientX: number, clientY: number) => string | null;
|
||||
clientToView: (clientX: number, clientY: number, vb: ViewBox) => Vec2;
|
||||
viewToModel: (vbX: number, vbY: number) => Vec2;
|
||||
toolHandlers: ToolHandlers | undefined;
|
||||
rawModelAt: (clientX: number, clientY: number) => Vec2;
|
||||
currentPxPerMeter: () => number;
|
||||
toolMods: (e: React.PointerEvent | React.MouseEvent) => { shift: boolean; ctrl: boolean; alt: boolean; };
|
||||
roomStamp: { roomId: string; anchor: Vec2; } | null | undefined;
|
||||
onStampMove: ((roomId: string, delta: Vec2, from?: Vec2) => void) | undefined;
|
||||
stampDrag: React.MutableRefObject<{ pointerId: number; roomId: string; last: Vec2; from: Vec2 | null; } | null>;
|
||||
stampAt: Vec2 | null;
|
||||
gripsActive: boolean;
|
||||
gripAt: (clientX: number, clientY: number) => number | null;
|
||||
grips: Vec2[] | undefined;
|
||||
edgeGripsActive: boolean;
|
||||
edgeGripAt: (clientX: number, clientY: number) => EdgeGrip | null;
|
||||
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>;
|
||||
svgRef: React.MutableRefObject<SVGSVGElement | null>;
|
||||
canvasRef: React.MutableRefObject<HTMLCanvasElement | null>;
|
||||
overlayOriginRef: React.MutableRefObject<Vec2 | null>;
|
||||
viewRef: React.MutableRefObject<ViewBox>;
|
||||
meetStore: MeetStore;
|
||||
syncDashVar: (v: ViewBox) => void;
|
||||
viewStore: ValueStore<ViewBox>;
|
||||
wantNative: boolean;
|
||||
renderGl: ((viewBox: ViewBox, paperScaleN?: number, _textScale?: number, onSent?: () => void) => void) | ((viewBox: ViewBox, paperScaleN?: number, textScaleN?: number) => void);
|
||||
paperScaleForGl: (v: ViewBox) => number;
|
||||
textScaleForGl: () => number;
|
||||
defaultView: ViewBox;
|
||||
setView: React.Dispatch<React.SetStateAction<ViewBox>>;
|
||||
reportCursor: (clientX: number, clientY: number) => void;
|
||||
setMarqueeRect: React.Dispatch<React.SetStateAction<{ x: number; y: number; w: number; h: number; crossing: boolean; } | null>>;
|
||||
updateHoverDivide: (clientX: number, clientY: number) => void;
|
||||
measure: (vb: ViewBox) => { rect: DOMRect | undefined; scale: number; offX: number; offY: number; };
|
||||
useGpuRenderer: boolean;
|
||||
hitTest: (clientX: number, clientY: number) => number | null;
|
||||
plan: Plan;
|
||||
pickSectionLine: (clientX: number, clientY: number) => string | null;
|
||||
pickOpening: (clientX: number, clientY: number) => string | null;
|
||||
pickColumn: (clientX: number, clientY: number) => string | null;
|
||||
pickExtrudedSolid: (clientX: number, clientY: number) => string | null;
|
||||
pickTree: (clientX: number, clientY: number) => string | null;
|
||||
pickStair: (clientX: number, clientY: number) => string | null;
|
||||
pickRoof: (clientX: number, clientY: number) => string | null;
|
||||
pickSiteAt: (clientX: number, clientY: number) => string | null;
|
||||
pickContextObject: (clientX: number, clientY: number) => string | null;
|
||||
}
|
||||
|
||||
export function usePlanPointer(inp: UsePlanPointerArgs) {
|
||||
const {
|
||||
gripDrag,
|
||||
gripHandlers,
|
||||
edgeDrag,
|
||||
toolActive,
|
||||
onStampEdit,
|
||||
lastClickRef,
|
||||
stampHandleAt,
|
||||
pickRoom,
|
||||
drag,
|
||||
view,
|
||||
setDragging,
|
||||
onSegmentCut,
|
||||
pickDrawing,
|
||||
clientToView,
|
||||
viewToModel,
|
||||
toolHandlers,
|
||||
rawModelAt,
|
||||
currentPxPerMeter,
|
||||
toolMods,
|
||||
roomStamp,
|
||||
onStampMove,
|
||||
stampDrag,
|
||||
stampAt,
|
||||
gripsActive,
|
||||
gripAt,
|
||||
grips,
|
||||
edgeGripsActive,
|
||||
edgeGripAt,
|
||||
grabbedBody,
|
||||
moveDrag,
|
||||
marquee,
|
||||
svgRef,
|
||||
canvasRef,
|
||||
overlayOriginRef,
|
||||
viewRef,
|
||||
meetStore,
|
||||
syncDashVar,
|
||||
viewStore,
|
||||
wantNative,
|
||||
renderGl,
|
||||
paperScaleForGl,
|
||||
textScaleForGl,
|
||||
defaultView,
|
||||
setView,
|
||||
reportCursor,
|
||||
setMarqueeRect,
|
||||
updateHoverDivide,
|
||||
measure,
|
||||
useGpuRenderer,
|
||||
hitTest,
|
||||
plan,
|
||||
pickSectionLine,
|
||||
pickOpening,
|
||||
pickColumn,
|
||||
pickExtrudedSolid,
|
||||
pickTree,
|
||||
pickStair,
|
||||
pickRoof,
|
||||
pickSiteAt,
|
||||
pickContextObject,
|
||||
} = inp;
|
||||
|
||||
// Maus-Schema (docs/design/context-menu.md): MITTE = schwenken (Pan),
|
||||
// LINKS = Auswahl, RECHTS = Kontextmenü, RAD = Zoom.
|
||||
const onPointerDown = (e: React.PointerEvent<SVGSVGElement>) => {
|
||||
// Ein Punkt- ODER Kanten-Griff ist bereits „bewaffnet" (Maus wurde
|
||||
// losgelassen, der Griff folgt seither dem Cursor) — JEDER weitere
|
||||
// Linksklick bestätigt nur die aktuelle Position, statt irgendeine andere
|
||||
// Aktion (Doppelklick, Schere, neue Auswahl, …) an derselben Stelle
|
||||
// auszulösen.
|
||||
if (e.button === 0 && gripDrag.current && gripHandlers) {
|
||||
e.preventDefault();
|
||||
gripDrag.current = null;
|
||||
gripHandlers.onGripEnd();
|
||||
return;
|
||||
}
|
||||
if (e.button === 0 && edgeDrag.current && gripHandlers) {
|
||||
e.preventDefault();
|
||||
edgeDrag.current = null;
|
||||
gripHandlers.onEdgeEnd();
|
||||
return;
|
||||
}
|
||||
// Doppelklick (zweiter Klick der Sequenz) auf einen Raum-Stempel/-Fläche →
|
||||
// Stempel-Editor öffnen. Manuell über Zeit/Abstand erkannt, weil PlanView
|
||||
// Pointer-Capture nutzt und der Browser dann kein natives `dblclick`
|
||||
// synthetisiert (bzw. `detail` nicht zuverlässig füllt).
|
||||
if (e.button === 0 && !toolActive && onStampEdit) {
|
||||
const now = Date.now();
|
||||
const prev = lastClickRef.current;
|
||||
const isDbl =
|
||||
prev &&
|
||||
now - prev.t < 400 &&
|
||||
Math.hypot(e.clientX - prev.x, e.clientY - prev.y) < 6;
|
||||
lastClickRef.current = { t: now, x: e.clientX, y: e.clientY };
|
||||
if (isDbl) {
|
||||
const rid =
|
||||
stampHandleAt(e.clientX, e.clientY) ?? pickRoom(e.clientX, e.clientY);
|
||||
if (rid) {
|
||||
e.preventDefault();
|
||||
lastClickRef.current = null;
|
||||
onStampEdit(rid);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e.button === 1) {
|
||||
// Mittlere Taste: Ausschnitt zum Ziehen einfrieren (Pan).
|
||||
e.preventDefault(); // verhindert Auto-Scroll-Modus im Browser.
|
||||
e.currentTarget.setPointerCapture(e.pointerId);
|
||||
drag.current = {
|
||||
pointerId: e.pointerId,
|
||||
startClientX: e.clientX,
|
||||
startClientY: e.clientY,
|
||||
startView: view,
|
||||
};
|
||||
setDragging(true);
|
||||
return;
|
||||
}
|
||||
if (e.button === 0 && e.altKey && onSegmentCut) {
|
||||
// Alt+Klick = Schere: getroffenes 2D-Element bestimmen und Segment-Löschen
|
||||
// an App melden (App ermittelt die nächstgelegene Kante aus dem Modellpunkt).
|
||||
const id = pickDrawing(e.clientX, e.clientY);
|
||||
if (id) {
|
||||
e.preventDefault();
|
||||
const v = clientToView(e.clientX, e.clientY, view);
|
||||
onSegmentCut(id, viewToModel(v.x, v.y));
|
||||
return;
|
||||
}
|
||||
// Kein 2D-Element getroffen → wie ein normaler Klick weiterbehandeln.
|
||||
}
|
||||
if (e.button === 0 && toolActive) {
|
||||
// Aktives Zeichenwerkzeug: linke Taste setzt Punkte (kein Marquee). Capture,
|
||||
// damit move/up zuverlässig ankommen; sofort eine Vorschau anstoßen.
|
||||
e.preventDefault();
|
||||
e.currentTarget.setPointerCapture(e.pointerId);
|
||||
toolHandlers!.onToolMove(
|
||||
rawModelAt(e.clientX, e.clientY),
|
||||
currentPxPerMeter(),
|
||||
toolMods(e),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (e.button === 0 && !toolActive && roomStamp && onStampMove) {
|
||||
// Linke Taste auf dem Stempel-Griff: NUR den Stempel-Anker verschieben.
|
||||
const rid = stampHandleAt(e.clientX, e.clientY);
|
||||
if (rid) {
|
||||
e.preventDefault();
|
||||
e.currentTarget.setPointerCapture(e.pointerId);
|
||||
stampDrag.current = {
|
||||
pointerId: e.pointerId,
|
||||
roomId: rid,
|
||||
last: rawModelAt(e.clientX, e.clientY),
|
||||
// [140] Der Kern verschiebt ab der gezeichneten Lage (ohne eigenen Anker rückt der Plan den Stempel vom Pol weg).
|
||||
from: stampAt,
|
||||
};
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (e.button === 0 && gripsActive) {
|
||||
// Linke Taste auf einem Editier-Griff: Griff ziehen (Endpunkt verschieben).
|
||||
const gi = gripAt(e.clientX, e.clientY);
|
||||
if (gi !== null) {
|
||||
e.preventDefault();
|
||||
// KEIN Pointer-Capture: der Griff bleibt nach dem Loslassen bewaffnet
|
||||
// und folgt via normalem Hover-onPointerMove weiter dem Cursor (s.
|
||||
// Kommentar an der gripDrag-Deklaration).
|
||||
gripDrag.current = { pointerId: e.pointerId, index: gi, origin: grips![gi], startX: e.clientX, startY: e.clientY };
|
||||
return;
|
||||
}
|
||||
// Linke Taste auf einem Kanten-Anfasser (Dreieck): Seite ziehen. KEIN
|
||||
// Pointer-Capture — dasselbe „bewaffnet nach Loslassen"-Verhalten wie
|
||||
// beim Punkt-Griff (s. Kommentar an der edgeDrag-Deklaration).
|
||||
if (edgeGripsActive) {
|
||||
const eg = edgeGripAt(e.clientX, e.clientY);
|
||||
if (eg) {
|
||||
e.preventDefault();
|
||||
edgeDrag.current = { pointerId: e.pointerId, edge: eg, startX: e.clientX, startY: e.clientY };
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Sonst: auf dem Körper eines gewählten Elements? → Parallel-Verschieben.
|
||||
// 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);
|
||||
moveDrag.current = { pointerId: e.pointerId, last: rawModelAt(e.clientX, e.clientY), target: body, startX: e.clientX, startY: e.clientY };
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Körper-Verschieben auch bei MEHRFACHAUSWAHL (dann sind die einzel-Element-
|
||||
// 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) {
|
||||
// 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);
|
||||
moveDrag.current = { pointerId: e.pointerId, last: rawModelAt(e.clientX, e.clientY), target: body, startX: e.clientX, startY: e.clientY };
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (e.button === 0) {
|
||||
// Linke Taste: Auswahl-Geste beginnen. Ob daraus ein Klick (eine Wand
|
||||
// wählen) oder ein Marquee (Mengenauswahl) wird, entscheidet sich erst
|
||||
// beim Loslassen anhand der zurückgelegten Strecke (Schwelle in
|
||||
// onPointerMove). Startpunkt in viewBox-Einheiten festhalten.
|
||||
e.currentTarget.setPointerCapture(e.pointerId);
|
||||
const start = clientToView(e.clientX, e.clientY, view);
|
||||
marquee.current = {
|
||||
pointerId: e.pointerId,
|
||||
startClientX: e.clientX,
|
||||
startClientY: e.clientY,
|
||||
startView: start,
|
||||
moved: false,
|
||||
};
|
||||
return;
|
||||
}
|
||||
// Rechte Taste (button 2): Kontextmenü läuft über onContextMenu.
|
||||
};
|
||||
|
||||
// Perf: modell-mutierende Drags (Griff/Kante/Körper/Stempel) auf EIN Update je
|
||||
// Animationsframe drosseln. Schnelles Ziehen feuert pointermove schneller, als
|
||||
// der Plan neu gebaut/gezeichnet werden kann — ungebremst staut sich ein
|
||||
// Rückstand ("kommt nicht hinterher"). Wir merken nur die NEUESTE Position und
|
||||
// verarbeiten sie einmal pro Frame.
|
||||
const dragMovePending = useRef<{
|
||||
cx: number;
|
||||
cy: number;
|
||||
shift: boolean;
|
||||
ctrl: boolean;
|
||||
alt: boolean;
|
||||
pointerId: number;
|
||||
} | null>(null);
|
||||
const dragMoveRaf = useRef<number | null>(null);
|
||||
|
||||
// Imperativer GL-Pan/Zoom: während der Geste NICHT setView pro Frame (das würde
|
||||
// die ganze PlanView neu rendern). GL-Matrix wird pro Frame aktualisiert; das
|
||||
// SVG-Overlay bekommt statt eines viewBox-Neusatzes (→ Cairo-Re-Raster in
|
||||
// WebKitGTK, teuer!) einen GPU-komponierten CSS-`transform`. React-State (view)
|
||||
// + echtes viewBox werden erst beim Loslassen abgeglichen → in WebKit KEIN
|
||||
// SVG-Re-Raster je Frame mehr.
|
||||
const panPending = useRef<ViewBox | null>(null);
|
||||
// true, wenn das SVG-Overlay zu schwer fürs Neu-Rastern je Frame ist (s. applySvgTransform).
|
||||
const overlayHeavyRef = useRef(false);
|
||||
const panStartView = useRef<ViewBox | null>(null); // viewBox bei Gestenbeginn (V0)
|
||||
const panRaf = useRef<number | null>(null);
|
||||
|
||||
// Ausstehende imperative Pan-Aufräumung beim Unmount.
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (panRaf.current !== null) cancelAnimationFrame(panRaf.current);
|
||||
};
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* CSS-transform, der das SVG (fest gezeichnet mit viewBox V0) so verschiebt/
|
||||
* skaliert, dass es exakt den Ziel-Ausschnitt V zeigt — deckungsgleich mit der
|
||||
* GL-Ebene (beide nutzen xMidYMid meet in dieselbe Elementbox).
|
||||
*/
|
||||
const applySvgTransform = (v0: ViewBox, v: ViewBox) => {
|
||||
const svg = svgRef.current;
|
||||
if (!svg) return;
|
||||
// Box der (untransformierten) GPU-Fläche: das SVG trägt selbst schon den
|
||||
// Transform der laufenden Geste (Zoom skaliert seine gemessene Box).
|
||||
const rect = (canvasRef.current ?? svg).getBoundingClientRect();
|
||||
if (rect.width <= 0 || rect.height <= 0) return;
|
||||
const m = Math.min(rect.width / v0.w, rect.height / v0.h); // meet-Skala bei V0
|
||||
const A = v0.w / v.w; // Zoomfaktor (uniform)
|
||||
const lbX = (rect.width - v0.w * m) / 2; // Letterbox-Offset (0 bei passendem Aspekt)
|
||||
const lbY = (rect.height - v0.h * m) / 2;
|
||||
const cx = m * A * (v0.x - v.x) + (1 - A) * lbX;
|
||||
const cy = m * A * (v0.y - v.y) + (1 - A) * lbY;
|
||||
if (!overlayHeavyRef.current) {
|
||||
// Leichtes Overlay: den echten viewBox setzen — der Vektor wird in jedem
|
||||
// Frame SCHARF neu gerastert (ein CSS-Transform würde die Ebene als Bitmap
|
||||
// strecken → verpixelt). Bildschirmkonstante Griffe skalieren dabei mit.
|
||||
svg.style.transform = "";
|
||||
svg.setAttribute("viewBox", localViewBoxAttr(v, overlayOriginRef.current ?? { x: 0, y: 0 }));
|
||||
return;
|
||||
}
|
||||
// Schweres Overlay (z. B. riesiger Auswahlpfad): GPU-komponierter CSS-Transform.
|
||||
svg.style.transformOrigin = "0 0";
|
||||
svg.style.transform = `translate(${cx}px, ${cy}px) scale(${A})`;
|
||||
};
|
||||
|
||||
const flushPan = () => {
|
||||
panRaf.current = null;
|
||||
const v = panPending.current;
|
||||
const v0 = panStartView.current;
|
||||
if (!v || !v0) return;
|
||||
viewRef.current = v; // abgeleitete Reads (Snap-Toleranz etc.) frisch halten
|
||||
// Overlay (SVG-Ausschnitt mit Raumstempeln/Textfeldern, Griffe/Fangpunkt-Grösse,
|
||||
// Lineal) wird im SELBEN Takt wie die Geometrie angewendet ([145]): bei der
|
||||
// nativen Fläche in dem Moment, in dem ihr Frame abgeschickt wird (sie zeichnet
|
||||
// ihn sofort) — NICHT erst bei der Antwort, sonst malte die Webview das Overlay
|
||||
// einen Frame später und die Texte liefen beim Zoomen hinter den Linien her.
|
||||
// Wartet ein Frame (Fläche noch beschäftigt), folgt das Overlay erst mit dessen
|
||||
// Versand; verworfene Zwischen-Frames setzen es nie.
|
||||
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));
|
||||
syncDashVar(v);
|
||||
viewStore.set(v);
|
||||
};
|
||||
if (wantNative) {
|
||||
(renderGl as (vb: ViewBox, ps: number, ts: number, onSent: () => 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) => {
|
||||
if (!panStartView.current) panStartView.current = { ...viewRef.current };
|
||||
panPending.current = v;
|
||||
if (panRaf.current === null) panRaf.current = requestAnimationFrame(flushPan);
|
||||
};
|
||||
useEffect(() => {
|
||||
if (panPending.current === null) {
|
||||
meetStore.set(null);
|
||||
viewStore.set(null);
|
||||
}
|
||||
}, [view, meetStore, viewStore]);
|
||||
/**
|
||||
* Griff-Grösse in Bildschirm-px: bewusst nur SCHWACH zoomabhängig (Exponent 0.2,
|
||||
* begrenzt) — kein hartes Konstant-Bleiben, damit man an den Griffen noch merkt,
|
||||
* ob man nah oder weit weg ist, aber ohne dass sie beim Zoomen mitwachsen.
|
||||
*/
|
||||
const gripK = (meet: number): number => {
|
||||
const ref = meetScale(defaultView, canvasRef.current ?? svgRef.current) ?? meet;
|
||||
return Math.min(1.4, Math.max(0.7, Math.pow(meet / ref, 0.2)));
|
||||
};
|
||||
/** Anhängigen imperativen Pan in React-State übernehmen (+ Transform lösen). */
|
||||
const commitPan = () => {
|
||||
if (panRaf.current !== null) {
|
||||
cancelAnimationFrame(panRaf.current);
|
||||
panRaf.current = null;
|
||||
}
|
||||
if (panPending.current) {
|
||||
// SVG-Transform lösen; setView setzt das echte viewBox (ein einziger Re-Raster).
|
||||
if (svgRef.current) svgRef.current.style.transform = "";
|
||||
setView(panPending.current);
|
||||
// Live-Werte NICHT sofort löschen: bis der neue `view` gerendert ist, würden
|
||||
// Griffe/Lineal sonst kurz mit dem ALTEN Ausschnitt gezeichnet (Flackern);
|
||||
// der Effekt unten räumt sie nach dem Render ab.
|
||||
panPending.current = null;
|
||||
}
|
||||
panStartView.current = null;
|
||||
};
|
||||
|
||||
const flushDragMove = () => {
|
||||
dragMoveRaf.current = null;
|
||||
const p = dragMovePending.current;
|
||||
dragMovePending.current = null;
|
||||
if (!p) return;
|
||||
const mods = { shift: p.shift, ctrl: p.ctrl, alt: p.alt };
|
||||
const raw = rawModelAt(p.cx, p.cy);
|
||||
const ed = edgeDrag.current;
|
||||
if (ed && ed.pointerId === p.pointerId) {
|
||||
gripHandlers!.onEdgeMove(ed.edge, raw, currentPxPerMeter(), mods);
|
||||
return;
|
||||
}
|
||||
const gd = gripDrag.current;
|
||||
if (gd && gd.pointerId === p.pointerId) {
|
||||
gripHandlers!.onGripMove(gd.index, raw, currentPxPerMeter(), mods);
|
||||
return;
|
||||
}
|
||||
const sd = stampDrag.current;
|
||||
if (sd && sd.pointerId === p.pointerId) {
|
||||
const delta = { x: raw.x - sd.last.x, y: raw.y - sd.last.y };
|
||||
if ((delta.x !== 0 || delta.y !== 0) && onStampMove) {
|
||||
onStampMove(sd.roomId, delta, sd.from ?? undefined);
|
||||
sd.from = null;
|
||||
sd.last = raw;
|
||||
}
|
||||
return;
|
||||
}
|
||||
const md = moveDrag.current;
|
||||
if (md && md.pointerId === p.pointerId) {
|
||||
const delta = { x: raw.x - md.last.x, y: raw.y - md.last.y };
|
||||
if (delta.x !== 0 || delta.y !== 0) {
|
||||
gripHandlers!.onMoveBody(delta, md.target, mods);
|
||||
md.last = raw;
|
||||
}
|
||||
return;
|
||||
}
|
||||
};
|
||||
const enqueueDragMove = (e: React.PointerEvent<SVGSVGElement>) => {
|
||||
dragMovePending.current = {
|
||||
cx: e.clientX,
|
||||
cy: e.clientY,
|
||||
shift: e.shiftKey,
|
||||
ctrl: e.ctrlKey || e.metaKey,
|
||||
alt: e.altKey,
|
||||
pointerId: e.pointerId,
|
||||
};
|
||||
if (dragMoveRaf.current === null) {
|
||||
dragMoveRaf.current = requestAnimationFrame(flushDragMove);
|
||||
}
|
||||
};
|
||||
|
||||
const onPointerMove = (e: React.PointerEvent<SVGSVGElement>) => {
|
||||
// Immer die Cursor-Position melden (auch ohne Ziehen), für die Statusleiste.
|
||||
reportCursor(e.clientX, e.clientY);
|
||||
|
||||
// Modell-mutierende Drags (Kante/Griff/Stempel/Körper): auf rAF drosseln —
|
||||
// ein Update je Frame mit der jeweils neuesten Position (siehe flushDragMove).
|
||||
if (
|
||||
(edgeDrag.current && edgeDrag.current.pointerId === e.pointerId) ||
|
||||
(gripDrag.current && gripDrag.current.pointerId === e.pointerId) ||
|
||||
(stampDrag.current && stampDrag.current.pointerId === e.pointerId) ||
|
||||
(moveDrag.current && moveDrag.current.pointerId === e.pointerId)
|
||||
) {
|
||||
enqueueDragMove(e);
|
||||
return;
|
||||
}
|
||||
|
||||
// Aktives Zeichenwerkzeug: Hover/Drag liefert die Live-Vorschau + Snap-Marker.
|
||||
// Mittlere Taste (Pan) bleibt davon unberührt (eigener Zweig unten).
|
||||
if (toolActive && drag.current === null) {
|
||||
toolHandlers!.onToolMove(
|
||||
rawModelAt(e.clientX, e.clientY),
|
||||
currentPxPerMeter(),
|
||||
toolMods(e),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Marquee (linke Taste) aufziehen: Rechteck in viewBox-Einheiten vom
|
||||
// Startpunkt zum aktuellen Cursor. Erst ab einer kleinen Pixel-Schwelle gilt
|
||||
// es als Drag (sonst bleibt es ein Klick → Einzelwahl beim Loslassen).
|
||||
const mq = marquee.current;
|
||||
if (mq && mq.pointerId === e.pointerId) {
|
||||
const dxPx = e.clientX - mq.startClientX;
|
||||
const dyPx = e.clientY - mq.startClientY;
|
||||
if (!mq.moved && Math.hypot(dxPx, dyPx) < MARQUEE_THRESHOLD_PX) return;
|
||||
mq.moved = true;
|
||||
const cur = clientToView(e.clientX, e.clientY, view);
|
||||
// crossing-Richtung aus dem Vorzeichen von Δx am Bildschirm (rechts→links
|
||||
// = negativ = berührend). Bildschirm-x und viewBox-x sind gleichläufig.
|
||||
const crossing = dxPx < 0;
|
||||
setMarqueeRect({
|
||||
x: Math.min(mq.startView.x, cur.x),
|
||||
y: Math.min(mq.startView.y, cur.y),
|
||||
w: Math.abs(cur.x - mq.startView.x),
|
||||
h: Math.abs(cur.y - mq.startView.y),
|
||||
crossing,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const d = drag.current;
|
||||
if (!d || d.pointerId !== e.pointerId) {
|
||||
// Echter Ruhezustand (kein Drag/Werkzeug/Marquee/Pan) — Hover-
|
||||
// Teilpunkte-Erkennung.
|
||||
updateHoverDivide(e.clientX, e.clientY);
|
||||
return;
|
||||
}
|
||||
const { scale } = measure(d.startView);
|
||||
// Bildschirm-Delta → viewBox-Einheiten; Inhalt folgt dem Cursor, also
|
||||
// verschiebt sich der Ausschnitt entgegengesetzt.
|
||||
const dx = (e.clientX - d.startClientX) / scale;
|
||||
const dy = (e.clientY - d.startClientY) / scale;
|
||||
const next: ViewBox = {
|
||||
x: d.startView.x - dx,
|
||||
y: d.startView.y - dy,
|
||||
w: d.startView.w,
|
||||
h: d.startView.h,
|
||||
};
|
||||
// GL-Pfad: imperativ (rAF, kein React-Render pro Frame). SVG-Pfad: wie bisher
|
||||
// über setView (das SVG muss über React neu rendern).
|
||||
if (useGpuRenderer) enqueuePan(next);
|
||||
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 ? planPrimAt(plan, 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);
|
||||
// [149] Baum (Kronenfläche) vor Decke, Raum, Dach und Gelände.
|
||||
const treeId =
|
||||
openingId || wallId || columnId || drawingId || extrudedSolidId ? null : pickTree(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 || treeId ? null : hitCeilingId;
|
||||
// Treppe nur, wenn nichts anderes getroffen wurde (Tritte liegen frei).
|
||||
const stairId =
|
||||
openingId || wallId || columnId || drawingId || extrudedSolidId || treeId || 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 || treeId || 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 || treeId || 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.
|
||||
// [137] Schatten/Baurechtslinien (Lage-Darstellung) über dem Gelände, unter allen Bauteilen.
|
||||
const siteId =
|
||||
openingId || wallId || columnId || drawingId || extrudedSolidId || treeId || ceilingId || stairId || roomId || roofId
|
||||
? null
|
||||
: pickSiteAt(clientX, clientY);
|
||||
const contextObjectId =
|
||||
openingId || wallId || columnId || drawingId || extrudedSolidId || treeId || ceilingId || stairId || roomId || roofId || siteId
|
||||
? null
|
||||
: pickContextObject(clientX, clientY);
|
||||
return {
|
||||
hitIndex,
|
||||
wallId,
|
||||
drawingId,
|
||||
ceilingId,
|
||||
openingId,
|
||||
stairId,
|
||||
roomId,
|
||||
extrudedSolidId,
|
||||
columnId,
|
||||
roofId,
|
||||
sectionLineId: null,
|
||||
contextObjectId,
|
||||
siteId,
|
||||
treeId,
|
||||
};
|
||||
};
|
||||
|
||||
return {
|
||||
onPointerDown,
|
||||
dragMovePending,
|
||||
dragMoveRaf,
|
||||
panPending,
|
||||
overlayHeavyRef,
|
||||
enqueuePan,
|
||||
gripK,
|
||||
commitPan,
|
||||
flushDragMove,
|
||||
onPointerMove,
|
||||
defaultPick,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
// Rad-Zoom, Doppelklick und Kontextmenü der Plan-Ansicht ([165] aus `PlanView.tsx`). Im GPU-Pfad zoomt
|
||||
// das Rad imperativ und schreibt den Ausschnitt nach kurzer Ruhe fest. Aufgerufen einmal von `PlanView`.
|
||||
|
||||
import type { ViewBox__plan_planView_geometry as ViewBox } from "../../../core";
|
||||
import type { Vec2 } from "../../../model/types";
|
||||
import { clamp } from "../../../core";
|
||||
import { WHEEL_MAX_DELTA, WHEEL_STEP, ZOOM_MAX, ZOOM_MIN } from "./constants";
|
||||
import { useRef, useEffect } from "react";
|
||||
import type { ToolHandlers } from "../../../tools/types";
|
||||
import type { GroupableHit } from "./types";
|
||||
|
||||
/** Werte aus `PlanView`, die dieser Hook liest (unverändert, ohne Kopie). */
|
||||
export interface UsePlanZoomInputArgs {
|
||||
clientToView: (clientX: number, clientY: number, vb: ViewBox) => Vec2;
|
||||
defaultView: ViewBox;
|
||||
svgRef: React.MutableRefObject<SVGSVGElement | null>;
|
||||
useGpuRenderer: boolean;
|
||||
panPending: React.MutableRefObject<ViewBox | null>;
|
||||
viewRef: React.MutableRefObject<ViewBox>;
|
||||
canvasRef: React.MutableRefObject<HTMLCanvasElement | null>;
|
||||
enqueuePan: (v: ViewBox) => void;
|
||||
commitPan: () => void;
|
||||
setView: React.Dispatch<React.SetStateAction<ViewBox>>;
|
||||
toolActive: boolean;
|
||||
toolHandlers: ToolHandlers | undefined;
|
||||
onEnterGroup: ((hit: GroupableHit) => boolean) | undefined;
|
||||
anyGroupableHit: (clientX: number, clientY: number) => GroupableHit | null;
|
||||
onEditDrawingText: ((drawingId: string) => void) | undefined;
|
||||
pickDrawingText: (clientX: number, clientY: number) => string | null;
|
||||
onStampEdit: ((roomId: string) => void) | undefined;
|
||||
stampHandleAt: (clientX: number, clientY: number) => string | null;
|
||||
pickRoom: (clientX: number, clientY: number) => string | null;
|
||||
onOpenSectionLevel: ((levelId: string) => void) | undefined;
|
||||
pickSectionLine: (clientX: number, clientY: number) => string | null;
|
||||
onContextMenu: ((info: { clientX: number; clientY: number; model: Vec2; }) => void) | undefined;
|
||||
view: ViewBox;
|
||||
viewToModel: (vbX: number, vbY: number) => Vec2;
|
||||
}
|
||||
|
||||
export function usePlanZoomInput(inp: UsePlanZoomInputArgs) {
|
||||
const {
|
||||
clientToView,
|
||||
defaultView,
|
||||
svgRef,
|
||||
useGpuRenderer,
|
||||
panPending,
|
||||
viewRef,
|
||||
canvasRef,
|
||||
enqueuePan,
|
||||
commitPan,
|
||||
setView,
|
||||
toolActive,
|
||||
toolHandlers,
|
||||
onEnterGroup,
|
||||
anyGroupableHit,
|
||||
onEditDrawingText,
|
||||
pickDrawingText,
|
||||
onStampEdit,
|
||||
stampHandleAt,
|
||||
pickRoom,
|
||||
onOpenSectionLevel,
|
||||
pickSectionLine,
|
||||
onContextMenu,
|
||||
view,
|
||||
viewToModel,
|
||||
} = inp;
|
||||
|
||||
/**
|
||||
* Rechnet aus einem Ausschnitt + Rad-Delta den neuen (geklemmten) Ausschnitt.
|
||||
* `anchorOverride`: Ankerpunkt in viewBox-Koordinaten (sonst aus clientX/Y über
|
||||
* die gemessene SVG-Box — die während eines imperativen Zooms transformiert ist).
|
||||
*/
|
||||
const zoomedView = (prev: ViewBox, clientX: number, clientY: number, deltaY: number, anchorOverride?: Vec2): ViewBox => {
|
||||
// Punkt unter dem Cursor (bleibt nach dem Zoom ortsfest).
|
||||
const anchor = anchorOverride ?? clientToView(clientX, clientY, prev);
|
||||
// Hochrollen (deltaY < 0) → hinein → kleinere viewBox.
|
||||
let factor = Math.exp(clamp(deltaY, -WHEEL_MAX_DELTA, WHEEL_MAX_DELTA) * WHEEL_STEP);
|
||||
// Zoom relativ zur Default-Breite begrenzen.
|
||||
const minW = defaultView.w / ZOOM_MAX;
|
||||
const maxW = defaultView.w / ZOOM_MIN;
|
||||
const targetW = clamp(prev.w * factor, minW, maxW);
|
||||
// Tatsächlich angewandter Faktor nach Klemmung (hält Seitenverhältnis).
|
||||
factor = targetW / prev.w;
|
||||
return {
|
||||
x: anchor.x - (anchor.x - prev.x) * factor,
|
||||
y: anchor.y - (anchor.y - prev.y) * factor,
|
||||
w: prev.w * factor,
|
||||
h: prev.h * factor,
|
||||
};
|
||||
};
|
||||
|
||||
// Zoom-Geste im GPU-Pfad: wie der Pan imperativ (kein React-Render pro Rad-
|
||||
// Schritt). Der Ausschnitt wird erst nach einer kurzen Ruhepause festgeschrieben.
|
||||
const wheelCommitTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
const WHEEL_COMMIT_MS = 70;
|
||||
|
||||
// Seiten-Scroll/-Zoom des Browsers beim Rad über dem Plan unterdrücken: React hängt `onWheel`
|
||||
// passiv an (dort `preventDefault` wirkungslos, Chromium meldet einen Konsolenfehler) — daher
|
||||
// ein eigener, nicht-passiver Listener am SVG.
|
||||
useEffect(() => {
|
||||
const el = svgRef.current;
|
||||
if (!el) return;
|
||||
const stop = (e: WheelEvent) => e.preventDefault();
|
||||
el.addEventListener("wheel", stop, { passive: false });
|
||||
return () => el.removeEventListener("wheel", stop);
|
||||
}, []);
|
||||
const onWheel = (e: React.WheelEvent<SVGSVGElement>) => {
|
||||
if (useGpuRenderer) {
|
||||
// Aktueller (logischer) Ausschnitt: ein laufender imperativer Zoom/Pan gewinnt.
|
||||
const base = panPending.current ?? viewRef.current;
|
||||
// Während der Geste trägt das SVG einen CSS-Transform → seine Box ist
|
||||
// verzerrt; die (untransformierte) GPU-Fläche liefert die echte Elementbox.
|
||||
const rect = (canvasRef.current ?? svgRef.current)?.getBoundingClientRect();
|
||||
let anchor: Vec2 | undefined;
|
||||
if (rect && rect.width > 0 && rect.height > 0) {
|
||||
const scale = Math.min(rect.width / base.w, rect.height / base.h);
|
||||
const offX = (rect.width - base.w * scale) / 2;
|
||||
const offY = (rect.height - base.h * scale) / 2;
|
||||
anchor = {
|
||||
x: base.x + (e.clientX - rect.left - offX) / scale,
|
||||
y: base.y + (e.clientY - rect.top - offY) / scale,
|
||||
};
|
||||
}
|
||||
enqueuePan(zoomedView(base, e.clientX, e.clientY, e.deltaY, anchor));
|
||||
if (wheelCommitTimer.current !== null) clearTimeout(wheelCommitTimer.current);
|
||||
wheelCommitTimer.current = setTimeout(() => {
|
||||
wheelCommitTimer.current = null;
|
||||
commitPan();
|
||||
}, WHEEL_COMMIT_MS);
|
||||
return;
|
||||
}
|
||||
setView((prev) => zoomedView(prev, e.clientX, e.clientY, e.deltaY));
|
||||
};
|
||||
|
||||
// Doppelklick → bei aktivem Werkzeug den mehrteiligen Entwurf abschließen,
|
||||
// sonst wieder auf die eingepasste Standard-Ansicht.
|
||||
const onDoubleClick = (e: React.MouseEvent<SVGSVGElement>) => {
|
||||
if (toolActive) {
|
||||
toolHandlers!.onToolCommit();
|
||||
return;
|
||||
}
|
||||
// Gruppen betreten hat VORRANG vor allen anderen Doppelklick-Aktionen
|
||||
// (Vectorworks: ein gruppiertes Element öffnet zuerst die Gruppe — erst
|
||||
// ein weiterer Doppelklick INNERHALB träfe dann z. B. den Text-Editor).
|
||||
if (onEnterGroup) {
|
||||
const hit = anyGroupableHit(e.clientX, e.clientY);
|
||||
if (hit && onEnterGroup(hit)) return;
|
||||
}
|
||||
// Doppelklick auf ein Text-2D-Element → Inhalt bearbeiten (Vorrang vor Raum).
|
||||
if (onEditDrawingText) {
|
||||
const tid = pickDrawingText(e.clientX, e.clientY);
|
||||
if (tid) {
|
||||
onEditDrawingText(tid);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Doppelklick auf einen Raum (Stempel-Griff ODER Fläche) → Stempel-Editor.
|
||||
if (onStampEdit) {
|
||||
const rid =
|
||||
stampHandleAt(e.clientX, e.clientY) ?? pickRoom(e.clientX, e.clientY);
|
||||
if (rid) {
|
||||
onStampEdit(rid);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Doppelklick auf eine Schnittlinie → in deren 2D-Schnittansicht springen.
|
||||
if (onOpenSectionLevel) {
|
||||
const sid = pickSectionLine(e.clientX, e.clientY);
|
||||
if (sid) {
|
||||
onOpenSectionLevel(sid);
|
||||
return;
|
||||
}
|
||||
}
|
||||
setView(defaultView);
|
||||
};
|
||||
|
||||
// Rechtsklick: Browser-Menü unterdrücken. Bei aktivem Werkzeug mit laufendem
|
||||
// Entwurf = abschließen (CAD-üblich, KEIN Kontextmenü); sonst Kontextmenü.
|
||||
const onContextMenuHandler = (e: React.MouseEvent<SVGSVGElement>) => {
|
||||
e.preventDefault();
|
||||
// Bei aktivem Werkzeug/Befehl ist Rechtsklick = Enter (abschließen/wiederholen,
|
||||
// §2.3) — KEIN Kontextmenü, auch ohne laufenden Entwurf.
|
||||
if (toolActive) {
|
||||
toolHandlers!.onToolCommit();
|
||||
return;
|
||||
}
|
||||
if (!onContextMenu) return;
|
||||
const v = clientToView(e.clientX, e.clientY, view);
|
||||
onContextMenu({
|
||||
clientX: e.clientX,
|
||||
clientY: e.clientY,
|
||||
model: viewToModel(v.x, v.y),
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
onWheel,
|
||||
onDoubleClick,
|
||||
onContextMenuHandler,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user