From cb79c137531eb86c8eafc02885e4cdb6f9e05076 Mon Sep 17 00:00:00 2001 From: karim Date: Tue, 27 Oct 2026 19:25:06 +0100 Subject: [PATCH] Kern/Huelle Phase A.1: Kern-Lecks behoben (View-/Detail-Typen nach model/viewTypes, Pick-Typen nach plan/pickTypes, geomTransform/curves/lineSegments/layoutModel in den Kern verschoben) --- src/App.tsx | 2 +- src/commands/cmds/bezier.ts | 2 +- src/commands/cmds/defblock.ts | 2 +- src/commands/cmds/ellipse.ts | 2 +- src/commands/cmds/spline.ts | 2 +- src/editors/align.ts | 2 +- src/export/layoutPdf.ts | 2 +- src/export/planToPrintSvg.ts | 2 +- src/{tools => geometry}/curves.test.ts | 0 src/{tools => geometry}/curves.ts | 0 src/geometry/geomTransform.ts | 166 ++++++++++++++++++++++ src/{ui => geometry}/lineSegments.test.ts | 0 src/{ui => geometry}/lineSegments.ts | 0 src/{panels => model}/layoutModel.test.ts | 2 +- src/{panels => model}/layoutModel.ts | 2 +- src/model/types.ts | 2 +- src/model/viewTypes.ts | 49 +++++++ src/native/appMenu.ts | 2 +- src/panels/LayoutsPanel.tsx | 2 +- src/panels/ObjectInfoPanel.tsx | 2 +- src/panels/host.ts | 2 +- src/plan/generatePlan/drawing2d.ts | 4 +- src/plan/pickTypes.ts | 98 +++++++++++++ src/plan/planView/primitives.tsx | 2 +- src/plan/toWalls3d.ts | 17 ++- src/plan/toWalls3d/drawing2d.ts | 2 +- src/plan/toWalls3d/openings.ts | 2 +- src/state/selectionInfo.ts | 2 +- src/state/useExportHandlers.ts | 2 +- src/state/useGripEditing.ts | 3 +- src/state/usePanelHostBase.ts | 4 +- src/state/viewSlice.ts | 2 +- src/state/viewSnapshots.ts | 2 +- src/tools/snapping.ts | 2 +- src/tools/transform.ts | 162 +-------------------- src/ui/AppMenuBar.tsx | 2 +- src/ui/LayoutCreateDialogs.tsx | 2 +- src/ui/LayoutSheet.tsx | 2 +- src/ui/TopBar.tsx | 48 +------ src/ui/hatchPreview.tsx | 2 +- src/ui/resourceManager/LinesTab.tsx | 2 +- src/viewport/Wasm3DViewport.tsx | 2 +- src/viewport/raycast3d.test.ts | 6 +- src/viewport/raycast3d.ts | 98 +------------ src/viewport/useWasm3dRenderer.ts | 2 +- src/views/viewportContent.tsx | 2 +- 46 files changed, 373 insertions(+), 344 deletions(-) rename src/{tools => geometry}/curves.test.ts (100%) rename src/{tools => geometry}/curves.ts (100%) create mode 100644 src/geometry/geomTransform.ts rename src/{ui => geometry}/lineSegments.test.ts (100%) rename src/{ui => geometry}/lineSegments.ts (100%) rename src/{panels => model}/layoutModel.test.ts (99%) rename src/{panels => model}/layoutModel.ts (99%) create mode 100644 src/model/viewTypes.ts create mode 100644 src/plan/pickTypes.ts diff --git a/src/App.tsx b/src/App.tsx index 0afe858f..7a49fdf5 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -81,7 +81,7 @@ import { addAnnotation as addAnnotationToLayout, removeAnnotation as removeAnnotationFromLayout, patchAnnotation as patchAnnotationInLayout, -} from "./panels/layoutModel"; +} from "./model/layoutModel"; import { HatchSwatch } from "./ui/hatchPreview"; import { TopBar, ViewRibbonTab } from "./ui/TopBar"; import { AppMenuBar } from "./ui/AppMenuBar"; diff --git a/src/commands/cmds/bezier.ts b/src/commands/cmds/bezier.ts index 41645c07..47ce8096 100644 --- a/src/commands/cmds/bezier.ts +++ b/src/commands/cmds/bezier.ts @@ -9,7 +9,7 @@ import type { Drawing2D } from "../../model/types"; import { uniqueId } from "../../tools/types"; -import { sampleBezierChain } from "../../tools/curves"; +import { sampleBezierChain } from "../../geometry/curves"; import type { Command, CommandContext, diff --git a/src/commands/cmds/defblock.ts b/src/commands/cmds/defblock.ts index 2c4bcaaf..63e9a4af 100644 --- a/src/commands/cmds/defblock.ts +++ b/src/commands/cmds/defblock.ts @@ -11,7 +11,7 @@ // Leere/rein-block-Auswahl → No-Op (kein Commit). import type { BlockDef, Drawing2D } from "../../model/types"; -import { mvGeom } from "../../tools/transform"; +import { mvGeom } from "../../geometry/geomTransform"; import { uniqueId } from "../../tools/types"; import type { Command, diff --git a/src/commands/cmds/ellipse.ts b/src/commands/cmds/ellipse.ts index b9a5431c..e41cd35c 100644 --- a/src/commands/cmds/ellipse.ts +++ b/src/commands/cmds/ellipse.ts @@ -21,7 +21,7 @@ import type { Drawing2D } from "../../model/types"; import { segmentHud, uniqueId } from "../../tools/types"; -import { ellipsePts } from "../../tools/curves"; +import { ellipsePts } from "../../geometry/curves"; import type { CmdOption, Command, diff --git a/src/commands/cmds/spline.ts b/src/commands/cmds/spline.ts index d002f0cc..80a04b90 100644 --- a/src/commands/cmds/spline.ts +++ b/src/commands/cmds/spline.ts @@ -17,7 +17,7 @@ import type { Drawing2D } from "../../model/types"; import { segmentHud, uniqueId } from "../../tools/types"; -import { sampleCatmullRom, sampleUniformBSpline } from "../../tools/curves"; +import { sampleCatmullRom, sampleUniformBSpline } from "../../geometry/curves"; import type { Command, CommandContext, diff --git a/src/editors/align.ts b/src/editors/align.ts index 20ba1bd7..84cd57d2 100644 --- a/src/editors/align.ts +++ b/src/editors/align.ts @@ -8,7 +8,7 @@ import type { Drawing2D, Project, Vec2 } from "../model/types"; import { geomBBox } from "../state/selectionInfo"; -import { mvGeom } from "../tools/transform"; +import { mvGeom } from "../geometry/geomTransform"; /** Ausrichtungskante bzw. -achse. */ export type AlignMode = "left" | "right" | "centerX" | "top" | "bottom" | "centerY"; diff --git a/src/export/layoutPdf.ts b/src/export/layoutPdf.ts index 9add6215..3704e653 100644 --- a/src/export/layoutPdf.ts +++ b/src/export/layoutPdf.ts @@ -27,7 +27,7 @@ import { visibleCodesFromSnapshot, type FolderPdfPage, type ResolvedTitleBlock, -} from "../panels/layoutModel"; +} from "../model/layoutModel"; export { folderPdfPages, type FolderPdfPage }; diff --git a/src/export/planToPrintSvg.ts b/src/export/planToPrintSvg.ts index 6a989d16..3e3793ff 100644 --- a/src/export/planToPrintSvg.ts +++ b/src/export/planToPrintSvg.ts @@ -24,7 +24,7 @@ import type { HatchRender, Plan, Primitive } from "../plan/generatePlan"; import type { Vec2 } from "../model/types"; import { buildRandomHatchRuns, zigzagPoints, motifPoints } from "../plan/glPlan/glPlanHatch"; -import { dashHasDot } from "../ui/lineSegments"; +import { dashHasDot } from "../geometry/lineSegments"; import { wrapDocToLines, type SvgLine } from "../text/renderHtml"; import { docFromText } from "../text/richText"; diff --git a/src/tools/curves.test.ts b/src/geometry/curves.test.ts similarity index 100% rename from src/tools/curves.test.ts rename to src/geometry/curves.test.ts diff --git a/src/tools/curves.ts b/src/geometry/curves.ts similarity index 100% rename from src/tools/curves.ts rename to src/geometry/curves.ts diff --git a/src/geometry/geomTransform.ts b/src/geometry/geomTransform.ts new file mode 100644 index 00000000..0becc538 --- /dev/null +++ b/src/geometry/geomTransform.ts @@ -0,0 +1,166 @@ +// Punkt-Abbildung von 2D-Zeichengeometrie (Verschieben/Spiegeln/Drehen/Skalieren). Reine +// Geometrie ohne UI — Quelle für Transformations-Befehle, Block-Rendering und den Plan-Generator. + +import type { Drawing2DGeom, Vec2 } from "../model/types"; + + +/** + * Erkennt, ob `fn` die Umlauf-Orientierung umkehrt (Spiegelung) — via + * Flächenvorzeichen eines Test-Dreiecks unter `fn` (negativ ⇒ Spiegelung). + * Funktioniert für JEDE Isometrie/Similarity (Move/Rotate/Scale erhalten die + * Orientierung, Mirror kehrt sie um), ohne dass eine Operation ihre Spiegel- + * Eigenschaft explizit markieren müsste. + */ +export function reversesOrientation(fn: (p: Vec2) => Vec2): boolean { + const p0 = fn({ x: 0, y: 0 }), p1 = fn({ x: 1, y: 0 }), p2 = fn({ x: 0, y: 1 }); + return (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y) < 0; +} + +/** Bildet jeden Punkt einer 2D-Zeichengeometrie unter `fn` ab (Move/Mirror/Rotate/Array + Block-Rendering). */ +/** + * Wie {@link mvGeom}, zusätzlich für eine SKALIERUNG: `mvGeom` bildet nur + * PUNKTE ab — Radien, Schrifthöhen und der Bemassungs-Abstand sind aber keine + * Punkte und blieben sonst unverändert stehen (ein Kreis behielte unter einer + * 2×-Skalierung seinen Radius). Diese Funktion zieht die betroffenen + * Grössenfelder um denselben Faktor nach. + * + * Bewusst NICHT angefasst: `bulge` (ein Formverhältnis, skaleninvariant) und + * die Papier-mm-Felder von Bemassung/Linienenden — die beziehen sich auf das + * Blatt, nicht aufs Modell, und dürfen beim Skalieren des Objekts gleich + * bleiben. + */ +/** Skalierungsfaktor eines `op:"scale"`-Punkte-Tripels bei Interpolation `t`. */ +export function scaleFactor(pts: Vec2[], t: number): number { + const c = pts[0]; + const ref = Math.hypot(pts[1].x - c.x, pts[1].y - c.y) || 1; + const tgt = Math.hypot(pts[2].x - c.x, pts[2].y - c.y); + return 1 + (tgt / ref - 1) * t; +} + +export const scaleGeom = (geom: Drawing2DGeom, fn: (p: Vec2) => Vec2, f: number): Drawing2DGeom => { + const g = mvGeom(geom, fn); + switch (g.shape) { + case "circle": + return { ...g, r: g.r * f }; + case "arc": + return { ...g, r: g.r * f }; + case "ellipse": + return { ...g, rx: g.rx * f, ry: g.ry * f }; + case "dimension": + // `offset` ist der Normalabstand der Masslinie in Modellmass. + return { ...g, offset: g.offset * f }; + case "text": + return { + ...g, + height: g.height * f, + ...(g.width !== undefined ? { width: g.width * f } : {}), + }; + case "scalebar": + // Segmentlänge ist eine ECHTE Modell-Distanz (kein Papier-mm-Feld wie + // bei Kote/Bemassung) — muss bei einer Modell-Skalierung mitwachsen, + // sonst zeigt der Balken nach dem Skalieren die FALSCHE Distanz an. + return { ...g, segmentLength: g.segmentLength * f }; + case "block": + // Blockinstanz-Skalierung (s. Typ-Kommentar in model/types.ts) — + // ohne diesen Fall wäre der `scale`-Befehl auf eine Blockinstanz ein + // kompletter No-Op (kein Feld zum Multiplizieren). + return { ...g, scale: (g.scale ?? 1) * f }; + default: + return g; + } +}; + +export const mvGeom = (geom: Drawing2DGeom, fn: (p: Vec2) => Vec2): Drawing2DGeom => { + switch (geom.shape) { + case "line": + case "xline": + case "ray": + return { ...geom, a: fn(geom.a), b: fn(geom.b) }; + case "polyline": { + const pts = geom.pts.map(fn); + if (!geom.bulge) return { ...geom, pts }; + // Bulge-Vorzeichen ist rein relativ zur Zeichenrichtung definiert (links + // von a→b) — eine Spiegelung kehrt die Umlauf-Orientierung um und muss + // daher auch jeden Bogen umkehren, sonst wandert er auf die falsche Seite. + const bulge = reversesOrientation(fn) ? geom.bulge.map((b) => -b) : geom.bulge; + return { ...geom, pts, bulge }; + } + case "rect": { + // Achsparallel nur bei reiner Verschiebung erhaltbar; sonst → Polylinie. + const c = [ + geom.min, + { x: geom.max.x, y: geom.min.y }, + geom.max, + { x: geom.min.x, y: geom.max.y }, + ].map(fn); + const axisAligned = + Math.abs(c[0].y - c[1].y) < 1e-6 && + Math.abs(c[1].x - c[2].x) < 1e-6 && + Math.abs(c[2].y - c[3].y) < 1e-6; + if (axisAligned) { + const xs = c.map((p) => p.x), ys = c.map((p) => p.y); + return { + shape: "rect", + min: { x: Math.min(...xs), y: Math.min(...ys) }, + max: { x: Math.max(...xs), y: Math.max(...ys) }, + }; + } + return { shape: "polyline", pts: c, closed: true }; + } + case "circle": + return { ...geom, center: fn(geom.center) }; + case "arc": + return { ...geom, center: fn(geom.center) }; + case "ellipse": + return { ...geom, center: fn(geom.center) }; + case "bezier": + return { ...geom, pts: geom.pts.map(fn) }; + case "spline": + return { ...geom, pts: geom.pts.map(fn) }; + case "dimension": + return { ...geom, pts: geom.pts.map(fn) }; + case "kote": + return { ...geom, at: fn(geom.at) }; + case "detailref": + return { ...geom, at: fn(geom.at) }; + case "scalebar": + return { ...geom, at: fn(geom.at) }; + case "pointmarker": + return { ...geom, at: fn(geom.at) }; + case "text": + // Leader-Ziel bzw. Pfadpunkte (Text-entlang-Pfad) müssen mitwandern, + // sonst zeigt der Pfeil/Pfad nach einem Move/Mirror/Rotate/Array auf die + // alte Position. + return { + ...geom, + at: fn(geom.at), + ...(geom.leaderTarget ? { leaderTarget: fn(geom.leaderTarget) } : {}), + ...(geom.leaderBendPoints ? { leaderBendPoints: geom.leaderBendPoints.map(fn) } : {}), + ...(geom.pathPts ? { pathPts: geom.pathPts.map(fn) } : {}), + }; + case "block": { + // Wie Column: Winkel aus einem transformierten Richtungspunkt zurück- + // rechnen, damit Rotate/Mirror auch die Instanz-Ausrichtung mitnehmen + // (nicht nur den Einfügepunkt) — reine Translation liesse die Symbole + // beim Drehen der Auswahl in der alten Orientierung stehen. + const tip = { x: geom.at.x + Math.cos(geom.rotation), y: geom.at.y + Math.sin(geom.rotation) }; + const nb = fn(geom.at); + const nt = fn(tip); + return { ...geom, at: nb, rotation: Math.atan2(nt.y - nb.y, nt.x - nb.x) }; + } + case "image": { + // Wie Text: nur die Position folgt der Transformation (Zentrum wandert + // dorthin, wo `fn` es abbildet); die Box bleibt achsparallel/unverzerrt — + // ein Bild kann nicht geschert/rotiert dargestellt werden (kein `angle`-Feld). + const oldCenter = { x: (geom.min.x + geom.max.x) / 2, y: (geom.min.y + geom.max.y) / 2 }; + const newCenter = fn(oldCenter); + const dx = newCenter.x - oldCenter.x; + const dy = newCenter.y - oldCenter.y; + return { + ...geom, + min: { x: geom.min.x + dx, y: geom.min.y + dy }, + max: { x: geom.max.x + dx, y: geom.max.y + dy }, + }; + } + } +}; diff --git a/src/ui/lineSegments.test.ts b/src/geometry/lineSegments.test.ts similarity index 100% rename from src/ui/lineSegments.test.ts rename to src/geometry/lineSegments.test.ts diff --git a/src/ui/lineSegments.ts b/src/geometry/lineSegments.ts similarity index 100% rename from src/ui/lineSegments.ts rename to src/geometry/lineSegments.ts diff --git a/src/panels/layoutModel.test.ts b/src/model/layoutModel.test.ts similarity index 99% rename from src/panels/layoutModel.test.ts rename to src/model/layoutModel.test.ts index 2660722a..8e41fd21 100644 --- a/src/panels/layoutModel.test.ts +++ b/src/model/layoutModel.test.ts @@ -9,7 +9,7 @@ import type { MasterLayout, Project, ViewSnapshot, -} from "../model/types"; +} from "./types"; import { addAnnotation, addViewport, diff --git a/src/panels/layoutModel.ts b/src/model/layoutModel.ts similarity index 99% rename from src/panels/layoutModel.ts rename to src/model/layoutModel.ts index 4081302c..e92709f9 100644 --- a/src/panels/layoutModel.ts +++ b/src/model/layoutModel.ts @@ -19,7 +19,7 @@ import type { MasterLayout, Project, ViewSnapshot, -} from "../model/types"; +} from "./types"; // ── Blatt-Geometrie ────────────────────────────────────────────────────────── diff --git a/src/model/types.ts b/src/model/types.ts index 982382dc..3b6c1038 100644 --- a/src/model/types.ts +++ b/src/model/types.ts @@ -21,7 +21,7 @@ export type { RichTextDoc } from "../text/richText"; // Ansichts-Enums für Ausschnitte/View-Snapshots (Ansichtstyp, Kamera-Preset, // Detailgrad). Rein type-only importiert — zur Laufzeit erased, kein Zyklus // (TopBar importiert seinerseits nur `Project` als Typ). Wie SiaCategory oben. -import type { DetailLevel, View3d, ViewType } from "../ui/TopBar"; +import type { DetailLevel, View3d, ViewType } from "./viewTypes"; // ── Ressourcen-Bibliotheken (Vectorworks-/DOSSIER-Stil) ──────────────────── // Verwaltete, per id verwiesene Stil-Ressourcen. Verweis-Kette: diff --git a/src/model/viewTypes.ts b/src/model/viewTypes.ts new file mode 100644 index 00000000..c68c90c8 --- /dev/null +++ b/src/model/viewTypes.ts @@ -0,0 +1,49 @@ +// Ansichts-Typen (Geschoss-Ansicht, Detailgrad, 3D-Render-Modus, 3D-Blickwinkel). Gehören zum +// Modell/Kern, nicht zur Top-Bar — Kern und Hülle importieren sie von hier. + +/** Ansichtstyp eines Geschosses (wie in App). */ +export type ViewType = "grundriss" | "perspektive"; + +/** + * Detailgrad der Darstellung (≙ DOSSIER Einfach/Standard/Detail). Wirkt im + * Grundriss auf Tür-/Fenstersymbole + Schraffuren/Linienfeinheit (siehe + * generatePlan.DetailLevel); in der Perspektive noch ohne Wirkung (deferred). + */ +export type DetailLevel = "grob" | "mittel" | "fein"; + +/** + * Render-/Anzeigemodus der 3D-Ansicht: schattiert, einheitlich weiss (Clay-Look), + * texturiert (echte PBR-Materialien je Bauteil), Drahtgitter, Verdeckte Kanten + * (Hidden-Line), Schattiert mit Kanten (typischer BIM-Look: Bauteilfarben + + * Modell-Kanten obenauf). Wirkt nur in der Perspektive. Der Slot „section" + * (Schnittschraffur, Welle B) ist bewusst freigelassen. + */ +export type RenderMode = + | "shaded" + | "white" + | "contour" + | "textured" + | "wireframe" + | "hidden" + | "shaded-edges"; + +/** + * Kanonischer Blickwinkel der 3D-Ansicht (Vectorworks/DOSSIER-Stil). „front"/ + * „back"/„side"/„left" springen auf die vier Kardinalrichtungen (Vorne/Hinten/ + * Rechts/Links — KEINE Himmelsrichtungs-Labels, da es noch keinen Nordwinkel + * gibt); „top" auf die Draufsicht. „iso"/„isoFrontLeft"/„isoBackRight"/ + * „isoBackLeft" sind die vier oberen Iso-Oktanten (untere vier bleiben im + * Hochbau ungenutzt) — „iso" (vorne-oben-rechts) ist der bestehende Default. + * „perspective" ist der freie 3/4-Blick. Wirkt nur in der Perspektive. + */ +export type View3d = + | "front" + | "back" + | "side" + | "left" + | "top" + | "iso" + | "isoFrontLeft" + | "isoBackRight" + | "isoBackLeft" + | "perspective"; diff --git a/src/native/appMenu.ts b/src/native/appMenu.ts index c2e9e5ac..4e2da665 100644 --- a/src/native/appMenu.ts +++ b/src/native/appMenu.ts @@ -16,7 +16,7 @@ import { useEffect, useRef } from "react"; import { isTauriRuntime } from "../io/projectFile"; import { t } from "../i18n"; import { APP_VERSION } from "../ui/TopBar"; -import type { View3d, ViewType } from "../ui/TopBar"; +import type { View3d, ViewType } from "../model/viewTypes"; /** Alle Aktionen, die die native Menüleiste auslösen kann. */ export interface NativeAppMenuHandlers { diff --git a/src/panels/LayoutsPanel.tsx b/src/panels/LayoutsPanel.tsx index 7aede6e6..e8d8222d 100644 --- a/src/panels/LayoutsPanel.tsx +++ b/src/panels/LayoutsPanel.tsx @@ -27,7 +27,7 @@ import { PAPER_FORMAT_GROUPS, type FolderNode, type MasterFolderNode, -} from "./layoutModel"; +} from "../model/layoutModel"; import { NewLayoutDialog, NewMasterLayoutDialog, diff --git a/src/panels/ObjectInfoPanel.tsx b/src/panels/ObjectInfoPanel.tsx index 08fe6d61..2a943a2a 100644 --- a/src/panels/ObjectInfoPanel.tsx +++ b/src/panels/ObjectInfoPanel.tsx @@ -37,7 +37,7 @@ import type { } from "../model/types"; import { SIA_CATEGORIES, siaLabelFull } from "../geometry/roomArea"; import { Dropdown } from "../ui/Dropdown"; -import type { DetailLevel } from "../ui/TopBar"; +import type { DetailLevel } from "../model/viewTypes"; import { ColorHexField } from "../ui/ColorHexField"; import { usePanelHost } from "./host"; import type { diff --git a/src/panels/host.ts b/src/panels/host.ts index d19ece2e..24859281 100644 --- a/src/panels/host.ts +++ b/src/panels/host.ts @@ -42,7 +42,7 @@ import type { MeasurementReadout, SnapSettings, ToolId } from "../tools/types"; import type { Selection } from "../state/selectionInfo"; import type { TextStylePreset } from "../text/richText"; import type { ScheduleKind } from "../export/exportSchedule"; -import type { DetailLevel } from "../ui/TopBar"; +import type { DetailLevel } from "../model/viewTypes"; // ── Darstellungsmodus-Steuerung je Dock-Inhalt ──────────────────────────── diff --git a/src/plan/generatePlan/drawing2d.ts b/src/plan/generatePlan/drawing2d.ts index 232a3e3d..01da6847 100644 --- a/src/plan/generatePlan/drawing2d.ts +++ b/src/plan/generatePlan/drawing2d.ts @@ -14,8 +14,8 @@ import { type Primitive, } from "./shared"; import { layersStyleSig } from "./layerSig"; -import { ellipsePts, sampleBezierChain, sampleCatmullRom, sampleUniformBSpline } from "../../tools/curves"; -import { scaleGeom } from "../../tools/transform"; +import { ellipsePts, sampleBezierChain, sampleCatmullRom, sampleUniformBSpline } from "../../geometry/curves"; +import { scaleGeom } from "../../geometry/geomTransform"; import { bulgeArc, bulgeArcPoints } from "../../geometry/bulge"; import { END_MARK_DEFAULT_SIZE_MM, addEndMark, pullBack } from "./endMarks"; import { diff --git a/src/plan/pickTypes.ts b/src/plan/pickTypes.ts new file mode 100644 index 00000000..ebdb3da5 --- /dev/null +++ b/src/plan/pickTypes.ts @@ -0,0 +1,98 @@ +// Minimal-Formen der Pick-Geometrie (Wand-/Öffnungs-/Dach-… Körper für den 3D-Raycast). Sie +// stehen im Kern (`pickGeometry` in toWalls3d erzeugt sie); der Raycast der Hülle +// (viewport/raycast3d.ts) konsumiert sie. + +export type Vec3 = [number, number, number]; + +/** Minimal-Form eines Wand-Quaders für den Raycast (RWall erfüllt sie strukturell). */ +export interface PickWall { + start: readonly [number, number]; + end: readonly [number, number]; + thickness: number; + height: number; + baseElevation: number; + wallId: string; +} + +/** + * Minimal-Form einer Öffnungs-Box (Fenster/Tür) für den Raycast — dieselbe + * orientierte-Quader-Form wie `PickWall` (Achse jambStart→jambEnd in der + * XZ-Ebene, Dicke = Wanddicke am Sitz der Öffnung), nur über ihre EIGENE + * vertikale Ausdehnung (Brüstung..Sturz) statt der vollen Wandhöhe. + */ +export interface PickOpening { + start: readonly [number, number]; + end: readonly [number, number]; + thickness: number; + height: number; + baseElevation: number; + openingId: string; +} + +/** + * Minimal-Form eines Segments einer freien 2D-Zeichnung (Linie/Polylinie/ + * Rechteck) für den Raycast — dieselbe orientierte-Quader-Form wie + * `PickOpening`, aber mit fester (grosszügiger) Klick-Toleranz statt echter + * Bauteildicke: die sichtbare Boden-Spur im 3D ist nur 0.008m breit (s. + * `toWalls3d/drawing2d.ts::DRAWING_LINE_HALF_WIDTH`) — zu schmal, um + * zuverlässig zu treffen. `baseElevation` ist bereits die UNTERE Kante der + * Pick-Box (Boden-Spur-Höhe minus halbe Toleranzhöhe), s. `pickDrawingSegs`. + */ +export interface PickDrawingSeg { + start: readonly [number, number]; + end: readonly [number, number]; + baseElevation: number; + drawingId: string; +} + +/** Klick-Toleranz für 2D-Zeichnungs-Boden-Spuren im 3D (Welt-Meter, s. + * {@link PickDrawingSeg}) — quer zur Linie UND vertikal, je zur Hälfte um die + * sichtbare Spur zentriert. Analog dem 2D-Plan-Pick-Radius + * (`PlanView.tsx::LINE_PICK_PX`), hier als fester Welt-Wert statt Pixel- + * Toleranz (im 3D gibt es keinen globalen Pixel/Meter-Faktor). */ +export const DRAWING_PICK_TOLERANCE = 0.12; + +/** Minimal-Form eines Decken-Prismas für den Raycast (RSlab erfüllt sie strukturell). */ +export interface PickSlab { + outline: ReadonlyArray; + zBottom: number; + zTop: number; + ceilingId: string; +} + +/** + * Minimal-Form eines Treppen-Bounding-Prismas für den Raycast: ein achsparalleles + * Rechteck über den Grundriss-Fußabdruck (alle Tritte + Podest), extrudiert über + * die vertikale Ausdehnung der Treppe. Pragmatische Näherung statt Tritt-für- + * Tritt-Boxen — reicht für zuverlässiges Anklicken im 3D-Viewport. + */ +export interface PickStair { + outline: ReadonlyArray; + zBottom: number; + zTop: number; + stairId: string; +} + +/** + * Minimal-Form eines Dachs für den Raycast: die Dachflächen + Giebel als + * WORLD-Dreiecke (fan-trianguliert, dieselbe Konvention wie `emitRoofs`: + * model (x,y,z=Höhe) → world (x, z, y)). Präzise geneigte Flächen statt eines + * grosszügigen Bounding-Prismas — sonst stähle das Dach Klicks auf die + * Fassade dahinter (pickNearest entscheidet über die Strahl-Distanz). + */ +export interface PickRoof { + tris: ReadonlyArray; + roofId: string; +} + +/** + * Minimal-Form eines Kontext-Meshes (importiertes Gebäude/Terrain, s. + * `ContextObject`) für den Raycast: rohe WORLD-Dreiecke (dieselbe Konvention + * wie {@link PickRoof} — model (x,y,z=Höhe) → world (x, z, y)), keine + * Vereinfachung auf ein Bounding-Prisma (Gebäude-Meshes sind zu unregelmässig + * dafür, ein grosszügiges Prisma stähle Klicks auf dahinterliegende Bauteile). + */ +export interface PickContextMesh { + tris: ReadonlyArray; + contextObjectId: string; +} diff --git a/src/plan/planView/primitives.tsx b/src/plan/planView/primitives.tsx index 0fc9eb30..7d9276c6 100644 --- a/src/plan/planView/primitives.tsx +++ b/src/plan/planView/primitives.tsx @@ -9,7 +9,7 @@ import { docToLines, wrapDocToLines, type SvgLine } from "../../text/renderHtml" import type { Vec2 } from "../../model/types"; import { quantizePen } from "../../export/sceneToPrintSvg"; import { buildRandomHatchRuns, zigzagPoints, motifPoints, DASH_MM_TO_M } from "../glPlan/glPlanHatch"; -import { dashHasDot } from "../../ui/lineSegments"; +import { dashHasDot } from "../../geometry/lineSegments"; import { HAIRLINE_PX, PX_PER_M, mmToPx, printStrokeVb, visibleEdgeRuns } from "./geometry"; /** Basis-Kachelmaß (viewBox-Einheiten) einer Bild-Schraffur bei scaleX/scaleY = 1. */ diff --git a/src/plan/toWalls3d.ts b/src/plan/toWalls3d.ts index b5519d01..95136655 100644 --- a/src/plan/toWalls3d.ts +++ b/src/plan/toWalls3d.ts @@ -42,16 +42,15 @@ import type { Project, Vec2, Wall } from "../model/types"; import { getWallType, wallTypeThickness } from "../model/types"; -import type { ToolDraft } from "../tools/types"; import { stairVerticalExtent } from "../model/wall"; import { openingJambs, openingVerticalExtent } from "../geometry/opening"; -import type { DetailLevel } from "../ui/TopBar"; +import type { DetailLevel } from "../model/viewTypes"; import { stairBBox, stairGeometry } from "../geometry/stair"; import { roofBaseElevation, roofGeometry } from "../geometry/roof"; import type { Vec3 as RoofVec3 } from "../geometry/roof"; import { computeJoins } from "../model/joins"; import type { WallCuts } from "../model/joins"; -import type { PickOpening, PickRoof, PickStair, PickContextMesh, PickDrawingSeg } from "../viewport/raycast3d"; +import type { PickOpening, PickRoof, PickStair, PickContextMesh, PickDrawingSeg } from "./pickTypes"; import { EPS, IMPORTED_RGB, @@ -538,6 +537,16 @@ const SNAP_MARKER_HALF = 0.06; * unendliche Linie liefe unkontrolliert durchs ganze Modell). */ const SNAP_ANGLE_GUIDE_EXTEND_M = 6; +/** + * Minimal-Form eines Werkzeug-Drafts (`ToolDraft` der Hülle erfüllt sie strukturell): nur das, + * was `draftWorldLines` liest. So hängt der Kern nicht an `tools/types`. + */ +export interface DraftLike { + preview: Array<{ kind: "line"; a: Vec2; b: Vec2 } | { kind: "poly"; pts: Vec2[]; closed?: boolean }>; + vertices: Vec2[]; + snap?: { point: Vec2; kind?: string; refA?: Vec2 } | null; +} + /** * Wandelt den aktiven Werkzeug-Draft (`ToolDraft.preview`, Modell-Meter, * Grundriss-Ebene) in dasselbe flache Weltraum-LineList-Format wie @@ -559,7 +568,7 @@ const SNAP_ANGLE_GUIDE_EXTEND_M = 6; * schon, wohin der erste Punkt fängt — deshalb NICHT mehr früh bei leerem * `preview` abgebrochen. */ -export function draftWorldLines(draft: ToolDraft | null, planeY: number): Float32Array { +export function draftWorldLines(draft: DraftLike | null, planeY: number): Float32Array { if (!draft) return new Float32Array(0); const out: number[] = []; const pushSeg = (a: Vec2, bPt: Vec2, rgb: RRgb = DRAFT_LINE_RGB) => { diff --git a/src/plan/toWalls3d/drawing2d.ts b/src/plan/toWalls3d/drawing2d.ts index 401a400c..de4fed84 100644 --- a/src/plan/toWalls3d/drawing2d.ts +++ b/src/plan/toWalls3d/drawing2d.ts @@ -12,7 +12,7 @@ import type { Drawing2D, Project, Vec2 } from "../../model/types"; import { flattenCategories, getFloor } from "../../model/types"; import { DRAWING_LINE_FALLBACK_RGB, hexToRgb, type RRgb } from "./shared"; -import { DRAWING_PICK_TOLERANCE, type PickDrawingSeg } from "../../viewport/raycast3d"; +import { DRAWING_PICK_TOLERANCE, type PickDrawingSeg } from "../pickTypes"; /** Höhen-Offset über der Geschossebene gegen Z-Fighting (wie addDrawing2DLines in Viewport3D.tsx). */ const DRAWING_LINE_ELEVATION_EPS = 0.01; diff --git a/src/plan/toWalls3d/openings.ts b/src/plan/toWalls3d/openings.ts index 4ce24ae2..8637bcf6 100644 --- a/src/plan/toWalls3d/openings.ts +++ b/src/plan/toWalls3d/openings.ts @@ -7,7 +7,7 @@ import type { FrameCornerJoin, Opening, Project, SashDef, Wall } from "../../mod import { getDoorType, getWindowType, glazingPanesOf, openingsOfWall } from "../../model/types"; import { openingInterval, openingVerticalExtent } from "../../geometry/opening"; import { wallVerticalExtent } from "../../model/wall"; -import type { DetailLevel } from "../../ui/TopBar"; +import type { DetailLevel } from "../../model/viewTypes"; import { EPS, type RMesh, type RRgb } from "./shared"; import { wallThicknessSafe } from "./bands"; diff --git a/src/state/selectionInfo.ts b/src/state/selectionInfo.ts index 0d428d37..bbecc11e 100644 --- a/src/state/selectionInfo.ts +++ b/src/state/selectionInfo.ts @@ -45,7 +45,7 @@ import type { Wall, WallReferenceLine, } from "../model/types"; -import type { DetailLevel } from "../ui/TopBar"; +import type { DetailLevel } from "../model/viewTypes"; import { localToLv95 } from "../io/lv95"; import { resolveForeground, diff --git a/src/state/useExportHandlers.ts b/src/state/useExportHandlers.ts index eea233dd..548b7a0f 100644 --- a/src/state/useExportHandlers.ts +++ b/src/state/useExportHandlers.ts @@ -7,7 +7,7 @@ import { generatePlan } from "../plan/generatePlan"; import type { CategoryDisplayResolver } from "../plan/generatePlan"; -import type { DetailLevel } from "../ui/TopBar"; +import type { DetailLevel } from "../model/viewTypes"; import type { DisplayResolver } from "../viewport/Viewport3D"; import { savePlanPdf } from "../export/exportPdf"; import { savePlanSvg } from "../export/exportSvg"; diff --git a/src/state/useGripEditing.ts b/src/state/useGripEditing.ts index f9d4a6f4..d4c96e54 100644 --- a/src/state/useGripEditing.ts +++ b/src/state/useGripEditing.ts @@ -10,7 +10,8 @@ import { add, dot, leftNormal, normalize, scale, sub, wallCorners } from "../mod import type { Ceiling, Drawing2D, EdgeGrip, Project, Room, Stair, Vec2 } from "../model/types"; import { wallTypeThickness } from "../model/types"; import { drawingVertices } from "./projectSlice"; -import { areaMovePreview, mvGeom } from "../tools/transform"; +import { areaMovePreview } from "../tools/transform"; +import { mvGeom } from "../geometry/geomTransform"; import { drawingPreviewShapes } from "../tools/drawingPreview"; import type { DraftShape, SnapResult, SnapSettings, ToolDraft, ToolMods } from "../tools/types"; import { applyAngleConstraint, computeSnap } from "../tools/snapping"; diff --git a/src/state/usePanelHostBase.ts b/src/state/usePanelHostBase.ts index a2daa86c..4c89eeb1 100644 --- a/src/state/usePanelHostBase.ts +++ b/src/state/usePanelHostBase.ts @@ -12,7 +12,7 @@ import { useMemo, type RefObject } from "react"; import type { DrawingLevel, Layout, Project } from "../model/types"; import { resolvePenColor } from "../model/penSets"; import type { ToolId } from "../tools/types"; -import type { ViewType } from "../ui/TopBar"; +import type { ViewType } from "../model/viewTypes"; import type { TransformSelection } from "../tools/transform"; import type { PlanViewHandle } from "../plan/PlanView"; import type { PanelHostValue } from "../panels/host"; @@ -51,7 +51,7 @@ import { moveLayoutToFolder, moveFolderToFolder, patchAnnotation as patchAnnotationInLayout, -} from "../panels/layoutModel"; +} from "../model/layoutModel"; import { saveFolderPdf } from "../export/layoutPdf"; import type { useProjectActions } from "./useProjectActions"; import type { useSelectionState } from "./useSelectionState"; diff --git a/src/state/viewSlice.ts b/src/state/viewSlice.ts index 353a4d9b..38a97e37 100644 --- a/src/state/viewSlice.ts +++ b/src/state/viewSlice.ts @@ -8,7 +8,7 @@ // neue Zeichnungen / Status-Leiste) — view-seitiger Zustand wie activeLevelId. import { sampleProject } from "../model/sampleProject"; -import type { DetailLevel, RenderMode, View3d, ViewType } from "../ui/TopBar"; +import type { DetailLevel, RenderMode, View3d, ViewType } from "../model/viewTypes"; import type { DisplayMode } from "../panels/types"; import { DEFAULT_MARQUEE_COLOR, DEFAULT_SNAP_COLOR } from "../theme/accents"; import type { StoreApi } from "./store"; diff --git a/src/state/viewSnapshots.ts b/src/state/viewSnapshots.ts index 98b4a331..fba122cf 100644 --- a/src/state/viewSnapshots.ts +++ b/src/state/viewSnapshots.ts @@ -14,7 +14,7 @@ // Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md). import type { OverrideRule, ViewSnapshot, Vec2 } from "../model/types"; -import type { DetailLevel, View3d, ViewType } from "../ui/TopBar"; +import type { DetailLevel, View3d, ViewType } from "../model/viewTypes"; /** * Der wiederherstellbare KERNZUSTAND eines Ausschnitts — alle Felder, die ein diff --git a/src/tools/snapping.ts b/src/tools/snapping.ts index 4620e4c6..3a27fa55 100644 --- a/src/tools/snapping.ts +++ b/src/tools/snapping.ts @@ -14,7 +14,7 @@ import { centroid as roomCentroid } from "../geometry/roomArea"; import { columnFootprint } from "../geometry/column"; import { stairOutline } from "../geometry/stair"; import type { SnapKind, SnapResult, SnapSettings } from "./types"; -import { sampleBezierChain, sampleCatmullRom, sampleUniformBSpline } from "./curves"; +import { sampleBezierChain, sampleCatmullRom, sampleUniformBSpline } from "../geometry/curves"; import { buildDrawingIndex, drawingsNear, isIndexable, pointSegDist, type DrawingIndex } from "../geometry/drawingIndex"; import { sheetSnapSegments } from "./sheetSnapGeometry"; diff --git a/src/tools/transform.ts b/src/tools/transform.ts index 6354ef03..2e955267 100644 --- a/src/tools/transform.ts +++ b/src/tools/transform.ts @@ -29,6 +29,7 @@ import { columnFootprint } from "../geometry/column"; import { stairOutline } from "../geometry/stair"; import type { DraftShape } from "./types"; import { drawingPreviewShapes } from "./drawingPreview"; +import { mvGeom, reversesOrientation, scaleFactor, scaleGeom } from "../geometry/geomTransform"; import { uniqueId } from "./types"; import type { CommandSelection } from "../commands/types"; @@ -262,18 +263,6 @@ function gatherItems(project: Project, sel: TransformSelection, op: TransformOp) * aktuellen Winkel) mit-transformiert und der neue Winkel daraus gemessen wird * — das ergibt für alle drei Operationen die korrekte neue Ausrichtung. */ -/** - * Erkennt, ob `fn` die Umlauf-Orientierung umkehrt (Spiegelung) — via - * Flächenvorzeichen eines Test-Dreiecks unter `fn` (negativ ⇒ Spiegelung). - * Funktioniert für JEDE Isometrie/Similarity (Move/Rotate/Scale erhalten die - * Orientierung, Mirror kehrt sie um), ohne dass eine Operation ihre Spiegel- - * Eigenschaft explizit markieren müsste. - */ -function reversesOrientation(fn: (p: Vec2) => Vec2): boolean { - const p0 = fn({ x: 0, y: 0 }), p1 = fn({ x: 1, y: 0 }), p2 = fn({ x: 0, y: 1 }); - return (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y) < 0; -} - function mvColumn(col: Column, fn: (p: Vec2) => Vec2): Column { const base = col.position; const rot = col.rotation ?? 0; @@ -283,155 +272,6 @@ function mvColumn(col: Column, fn: (p: Vec2) => Vec2): Column { return { ...col, position: nb, rotation: Math.atan2(nt.y - nb.y, nt.x - nb.x) }; } -/** Bildet jeden Punkt einer 2D-Zeichengeometrie unter `fn` ab (Move/Mirror/Rotate/Array + Block-Rendering). */ -/** - * Wie {@link mvGeom}, zusätzlich für eine SKALIERUNG: `mvGeom` bildet nur - * PUNKTE ab — Radien, Schrifthöhen und der Bemassungs-Abstand sind aber keine - * Punkte und blieben sonst unverändert stehen (ein Kreis behielte unter einer - * 2×-Skalierung seinen Radius). Diese Funktion zieht die betroffenen - * Grössenfelder um denselben Faktor nach. - * - * Bewusst NICHT angefasst: `bulge` (ein Formverhältnis, skaleninvariant) und - * die Papier-mm-Felder von Bemassung/Linienenden — die beziehen sich auf das - * Blatt, nicht aufs Modell, und dürfen beim Skalieren des Objekts gleich - * bleiben. - */ -/** Skalierungsfaktor eines `op:"scale"`-Punkte-Tripels bei Interpolation `t`. */ -export function scaleFactor(pts: Vec2[], t: number): number { - const c = pts[0]; - const ref = Math.hypot(pts[1].x - c.x, pts[1].y - c.y) || 1; - const tgt = Math.hypot(pts[2].x - c.x, pts[2].y - c.y); - return 1 + (tgt / ref - 1) * t; -} - -export const scaleGeom = (geom: Drawing2DGeom, fn: (p: Vec2) => Vec2, f: number): Drawing2DGeom => { - const g = mvGeom(geom, fn); - switch (g.shape) { - case "circle": - return { ...g, r: g.r * f }; - case "arc": - return { ...g, r: g.r * f }; - case "ellipse": - return { ...g, rx: g.rx * f, ry: g.ry * f }; - case "dimension": - // `offset` ist der Normalabstand der Masslinie in Modellmass. - return { ...g, offset: g.offset * f }; - case "text": - return { - ...g, - height: g.height * f, - ...(g.width !== undefined ? { width: g.width * f } : {}), - }; - case "scalebar": - // Segmentlänge ist eine ECHTE Modell-Distanz (kein Papier-mm-Feld wie - // bei Kote/Bemassung) — muss bei einer Modell-Skalierung mitwachsen, - // sonst zeigt der Balken nach dem Skalieren die FALSCHE Distanz an. - return { ...g, segmentLength: g.segmentLength * f }; - case "block": - // Blockinstanz-Skalierung (s. Typ-Kommentar in model/types.ts) — - // ohne diesen Fall wäre der `scale`-Befehl auf eine Blockinstanz ein - // kompletter No-Op (kein Feld zum Multiplizieren). - return { ...g, scale: (g.scale ?? 1) * f }; - default: - return g; - } -}; - -export const mvGeom = (geom: Drawing2DGeom, fn: (p: Vec2) => Vec2): Drawing2DGeom => { - switch (geom.shape) { - case "line": - case "xline": - case "ray": - return { ...geom, a: fn(geom.a), b: fn(geom.b) }; - case "polyline": { - const pts = geom.pts.map(fn); - if (!geom.bulge) return { ...geom, pts }; - // Bulge-Vorzeichen ist rein relativ zur Zeichenrichtung definiert (links - // von a→b) — eine Spiegelung kehrt die Umlauf-Orientierung um und muss - // daher auch jeden Bogen umkehren, sonst wandert er auf die falsche Seite. - const bulge = reversesOrientation(fn) ? geom.bulge.map((b) => -b) : geom.bulge; - return { ...geom, pts, bulge }; - } - case "rect": { - // Achsparallel nur bei reiner Verschiebung erhaltbar; sonst → Polylinie. - const c = [ - geom.min, - { x: geom.max.x, y: geom.min.y }, - geom.max, - { x: geom.min.x, y: geom.max.y }, - ].map(fn); - const axisAligned = - Math.abs(c[0].y - c[1].y) < 1e-6 && - Math.abs(c[1].x - c[2].x) < 1e-6 && - Math.abs(c[2].y - c[3].y) < 1e-6; - if (axisAligned) { - const xs = c.map((p) => p.x), ys = c.map((p) => p.y); - return { - shape: "rect", - min: { x: Math.min(...xs), y: Math.min(...ys) }, - max: { x: Math.max(...xs), y: Math.max(...ys) }, - }; - } - return { shape: "polyline", pts: c, closed: true }; - } - case "circle": - return { ...geom, center: fn(geom.center) }; - case "arc": - return { ...geom, center: fn(geom.center) }; - case "ellipse": - return { ...geom, center: fn(geom.center) }; - case "bezier": - return { ...geom, pts: geom.pts.map(fn) }; - case "spline": - return { ...geom, pts: geom.pts.map(fn) }; - case "dimension": - return { ...geom, pts: geom.pts.map(fn) }; - case "kote": - return { ...geom, at: fn(geom.at) }; - case "detailref": - return { ...geom, at: fn(geom.at) }; - case "scalebar": - return { ...geom, at: fn(geom.at) }; - case "pointmarker": - return { ...geom, at: fn(geom.at) }; - case "text": - // Leader-Ziel bzw. Pfadpunkte (Text-entlang-Pfad) müssen mitwandern, - // sonst zeigt der Pfeil/Pfad nach einem Move/Mirror/Rotate/Array auf die - // alte Position. - return { - ...geom, - at: fn(geom.at), - ...(geom.leaderTarget ? { leaderTarget: fn(geom.leaderTarget) } : {}), - ...(geom.leaderBendPoints ? { leaderBendPoints: geom.leaderBendPoints.map(fn) } : {}), - ...(geom.pathPts ? { pathPts: geom.pathPts.map(fn) } : {}), - }; - case "block": { - // Wie Column: Winkel aus einem transformierten Richtungspunkt zurück- - // rechnen, damit Rotate/Mirror auch die Instanz-Ausrichtung mitnehmen - // (nicht nur den Einfügepunkt) — reine Translation liesse die Symbole - // beim Drehen der Auswahl in der alten Orientierung stehen. - const tip = { x: geom.at.x + Math.cos(geom.rotation), y: geom.at.y + Math.sin(geom.rotation) }; - const nb = fn(geom.at); - const nt = fn(tip); - return { ...geom, at: nb, rotation: Math.atan2(nt.y - nb.y, nt.x - nb.x) }; - } - case "image": { - // Wie Text: nur die Position folgt der Transformation (Zentrum wandert - // dorthin, wo `fn` es abbildet); die Box bleibt achsparallel/unverzerrt — - // ein Bild kann nicht geschert/rotiert dargestellt werden (kein `angle`-Feld). - const oldCenter = { x: (geom.min.x + geom.max.x) / 2, y: (geom.min.y + geom.max.y) / 2 }; - const newCenter = fn(oldCenter); - const dx = newCenter.x - oldCenter.x; - const dy = newCenter.y - oldCenter.y; - return { - ...geom, - min: { x: geom.min.x + dx, y: geom.min.y + dy }, - max: { x: geom.max.x + dx, y: geom.max.y + dy }, - }; - } - } -}; - /** Bildet Umriss + Aussparungen einer Decke unter `fn` ab. */ function mvCeiling(c: Ceiling, fn: (p: Vec2) => Vec2): Ceiling { return { diff --git a/src/ui/AppMenuBar.tsx b/src/ui/AppMenuBar.tsx index ae98fa20..ad7b5b40 100644 --- a/src/ui/AppMenuBar.tsx +++ b/src/ui/AppMenuBar.tsx @@ -9,7 +9,7 @@ import { Dropdown } from "./Dropdown"; import type { DropdownItem } from "./Dropdown"; import { t } from "../i18n"; -import type { View3d, ViewType } from "./TopBar"; +import type { View3d, ViewType } from "../model/viewTypes"; export interface AppMenuBarProps { /** Datei: Neu/Neu aus Vorlage/Öffnen/Speichern/Importieren. */ diff --git a/src/ui/LayoutCreateDialogs.tsx b/src/ui/LayoutCreateDialogs.tsx index 4aefe27a..8f8188b2 100644 --- a/src/ui/LayoutCreateDialogs.tsx +++ b/src/ui/LayoutCreateDialogs.tsx @@ -14,7 +14,7 @@ import type { LayoutPaperFormat, MasterLayout, } from "../model/types"; -import { PAPER_FORMAT_GROUPS } from "../panels/layoutModel"; +import { PAPER_FORMAT_GROUPS } from "../model/layoutModel"; /** Startwerte eines neuen Blatts/Masters (Grösse). */ export interface LayoutSizeStart { diff --git a/src/ui/LayoutSheet.tsx b/src/ui/LayoutSheet.tsx index bff06464..195212bf 100644 --- a/src/ui/LayoutSheet.tsx +++ b/src/ui/LayoutSheet.tsx @@ -32,7 +32,7 @@ import { resolveTitleBlock, resolveViewportScale, visibleCodesFromSnapshot, -} from "../panels/layoutModel"; +} from "../model/layoutModel"; import { annotationBoundsMm, applyHandleDrag, diff --git a/src/ui/TopBar.tsx b/src/ui/TopBar.tsx index 1c95aca0..c108d405 100644 --- a/src/ui/TopBar.tsx +++ b/src/ui/TopBar.tsx @@ -27,6 +27,7 @@ import { isMarkActive, toggleMark, } from "../text/richText"; +import type { DetailLevel, RenderMode, View3d, ViewType } from "../model/viewTypes"; import type { Align, BoolMark, @@ -35,53 +36,6 @@ import type { TextStylePreset, } from "../text/richText"; -/** Ansichtstyp eines Geschosses (wie in App). */ -export type ViewType = "grundriss" | "perspektive"; - -/** - * Detailgrad der Darstellung (≙ DOSSIER Einfach/Standard/Detail). Wirkt im - * Grundriss auf Tür-/Fenstersymbole + Schraffuren/Linienfeinheit (siehe - * generatePlan.DetailLevel); in der Perspektive noch ohne Wirkung (deferred). - */ -export type DetailLevel = "grob" | "mittel" | "fein"; - -/** - * Render-/Anzeigemodus der 3D-Ansicht: schattiert, einheitlich weiss (Clay-Look), - * texturiert (echte PBR-Materialien je Bauteil), Drahtgitter, Verdeckte Kanten - * (Hidden-Line), Schattiert mit Kanten (typischer BIM-Look: Bauteilfarben + - * Modell-Kanten obenauf). Wirkt nur in der Perspektive. Der Slot „section" - * (Schnittschraffur, Welle B) ist bewusst freigelassen. - */ -export type RenderMode = - | "shaded" - | "white" - | "contour" - | "textured" - | "wireframe" - | "hidden" - | "shaded-edges"; - -/** - * Kanonischer Blickwinkel der 3D-Ansicht (Vectorworks/DOSSIER-Stil). „front"/ - * „back"/„side"/„left" springen auf die vier Kardinalrichtungen (Vorne/Hinten/ - * Rechts/Links — KEINE Himmelsrichtungs-Labels, da es noch keinen Nordwinkel - * gibt); „top" auf die Draufsicht. „iso"/„isoFrontLeft"/„isoBackRight"/ - * „isoBackLeft" sind die vier oberen Iso-Oktanten (untere vier bleiben im - * Hochbau ungenutzt) — „iso" (vorne-oben-rechts) ist der bestehende Default. - * „perspective" ist der freie 3/4-Blick. Wirkt nur in der Perspektive. - */ -export type View3d = - | "front" - | "back" - | "side" - | "left" - | "top" - | "iso" - | "isoFrontLeft" - | "isoBackRight" - | "isoBackLeft" - | "perspective"; - /** * Farb-Modus des Grundrisses: „color" zeigt Kategorie-/Element-Farben (heutiges * Verhalten), „mono" erzeugt einen reinen Schwarz-Weiss-Plan. Wirkt nur im diff --git a/src/ui/hatchPreview.tsx b/src/ui/hatchPreview.tsx index d0a5d8a3..fce27087 100644 --- a/src/ui/hatchPreview.tsx +++ b/src/ui/hatchPreview.tsx @@ -10,7 +10,7 @@ import { useId } from "react"; import type { HatchStyle, LineStyle } from "../model/types"; -import { dashHasDot } from "./lineSegments"; +import { dashHasDot } from "../geometry/lineSegments"; // ── Kleiner deterministischer PRNG (mulberry32) ──────────────────────────── // Für „random"-Striche: stabil pro Seed, damit die Vorschau bei gleichem diff --git a/src/ui/resourceManager/LinesTab.tsx b/src/ui/resourceManager/LinesTab.tsx index f3341543..3731760f 100644 --- a/src/ui/resourceManager/LinesTab.tsx +++ b/src/ui/resourceManager/LinesTab.tsx @@ -15,7 +15,7 @@ import { type LineSegment, type LineSegmentType, type LinePresetKey, -} from "../lineSegments"; +} from "../../geometry/lineSegments"; import { MotifEditor } from "../MotifEditor"; import { t } from "../../i18n"; import { diff --git a/src/viewport/Wasm3DViewport.tsx b/src/viewport/Wasm3DViewport.tsx index d648843f..2aeafc72 100644 --- a/src/viewport/Wasm3DViewport.tsx +++ b/src/viewport/Wasm3DViewport.tsx @@ -47,7 +47,7 @@ import type { Project, Wall, Drawing2D, Ceiling, Roof, Vec2 } from "../model/typ import { ceilingVerticalExtent, wallVerticalExtent } from "../model/wall"; import { roofBaseElevation, roofGeometry } from "../geometry/roof"; import { projectToModel3d, pickGeometry, draftWorldLines, TRUCK_MESH_READY_EVENT } from "../plan/toWalls3d"; -import type { DetailLevel, RenderMode, View3d } from "../ui/TopBar"; +import type { DetailLevel, RenderMode, View3d } from "../model/viewTypes"; import type { ToolDraft } from "../tools/types"; import { hudSegments, type HudFieldsState } from "../tools/hudFormat"; import type { EngineMods } from "../commands/engine"; diff --git a/src/viewport/raycast3d.test.ts b/src/viewport/raycast3d.test.ts index 9d6a6787..c467aa4d 100644 --- a/src/viewport/raycast3d.test.ts +++ b/src/viewport/raycast3d.test.ts @@ -5,15 +5,17 @@ import { raySlabPrism, rayDrawingSeg, pickNearest, - DRAWING_PICK_TOLERANCE, type RayCamera, +} from "./raycast3d"; +import { + DRAWING_PICK_TOLERANCE, type PickWall, type PickSlab, type PickOpening, type PickStair, type PickContextMesh, type PickDrawingSeg, -} from "./raycast3d"; +} from "../plan/pickTypes"; // Kamera bei (0,1,10), Blick entlang -Z auf (0,1,0). Zentraler Strahl (ndc 0,0) // zeigt in -Z. World-Konvention: Modell (x,y) → world (x, elevation, y). diff --git a/src/viewport/raycast3d.ts b/src/viewport/raycast3d.ts index 30307ccb..8828441b 100644 --- a/src/viewport/raycast3d.ts +++ b/src/viewport/raycast3d.ts @@ -16,7 +16,10 @@ // wandert lateral mit dem Pixel — exakte Umkehrung von `worldToScreen`s // Ortho-Zweig, keine perspektivische Näherung mehr. -export type Vec3 = [number, number, number]; + +import { DRAWING_PICK_TOLERANCE } from "../plan/pickTypes"; +import type { Vec3, PickWall, PickOpening, PickDrawingSeg, PickSlab, PickStair, PickRoof, PickContextMesh } from "../plan/pickTypes"; +export type { Vec3 } from "../plan/pickTypes"; /** Kamera-Parameter für den Pick-Strahl (Teilmenge von Camera3d). */ export interface RayCamera { @@ -38,99 +41,6 @@ export interface Ray { dir: Vec3; } -/** Minimal-Form eines Wand-Quaders für den Raycast (RWall erfüllt sie strukturell). */ -export interface PickWall { - start: readonly [number, number]; - end: readonly [number, number]; - thickness: number; - height: number; - baseElevation: number; - wallId: string; -} - -/** - * Minimal-Form einer Öffnungs-Box (Fenster/Tür) für den Raycast — dieselbe - * orientierte-Quader-Form wie `PickWall` (Achse jambStart→jambEnd in der - * XZ-Ebene, Dicke = Wanddicke am Sitz der Öffnung), nur über ihre EIGENE - * vertikale Ausdehnung (Brüstung..Sturz) statt der vollen Wandhöhe. - */ -export interface PickOpening { - start: readonly [number, number]; - end: readonly [number, number]; - thickness: number; - height: number; - baseElevation: number; - openingId: string; -} - -/** - * Minimal-Form eines Segments einer freien 2D-Zeichnung (Linie/Polylinie/ - * Rechteck) für den Raycast — dieselbe orientierte-Quader-Form wie - * `PickOpening`, aber mit fester (grosszügiger) Klick-Toleranz statt echter - * Bauteildicke: die sichtbare Boden-Spur im 3D ist nur 0.008m breit (s. - * `toWalls3d/drawing2d.ts::DRAWING_LINE_HALF_WIDTH`) — zu schmal, um - * zuverlässig zu treffen. `baseElevation` ist bereits die UNTERE Kante der - * Pick-Box (Boden-Spur-Höhe minus halbe Toleranzhöhe), s. `pickDrawingSegs`. - */ -export interface PickDrawingSeg { - start: readonly [number, number]; - end: readonly [number, number]; - baseElevation: number; - drawingId: string; -} - -/** Klick-Toleranz für 2D-Zeichnungs-Boden-Spuren im 3D (Welt-Meter, s. - * {@link PickDrawingSeg}) — quer zur Linie UND vertikal, je zur Hälfte um die - * sichtbare Spur zentriert. Analog dem 2D-Plan-Pick-Radius - * (`PlanView.tsx::LINE_PICK_PX`), hier als fester Welt-Wert statt Pixel- - * Toleranz (im 3D gibt es keinen globalen Pixel/Meter-Faktor). */ -export const DRAWING_PICK_TOLERANCE = 0.12; - -/** Minimal-Form eines Decken-Prismas für den Raycast (RSlab erfüllt sie strukturell). */ -export interface PickSlab { - outline: ReadonlyArray; - zBottom: number; - zTop: number; - ceilingId: string; -} - -/** - * Minimal-Form eines Treppen-Bounding-Prismas für den Raycast: ein achsparalleles - * Rechteck über den Grundriss-Fußabdruck (alle Tritte + Podest), extrudiert über - * die vertikale Ausdehnung der Treppe. Pragmatische Näherung statt Tritt-für- - * Tritt-Boxen — reicht für zuverlässiges Anklicken im 3D-Viewport. - */ -export interface PickStair { - outline: ReadonlyArray; - zBottom: number; - zTop: number; - stairId: string; -} - -/** - * Minimal-Form eines Dachs für den Raycast: die Dachflächen + Giebel als - * WORLD-Dreiecke (fan-trianguliert, dieselbe Konvention wie `emitRoofs`: - * model (x,y,z=Höhe) → world (x, z, y)). Präzise geneigte Flächen statt eines - * grosszügigen Bounding-Prismas — sonst stähle das Dach Klicks auf die - * Fassade dahinter (pickNearest entscheidet über die Strahl-Distanz). - */ -export interface PickRoof { - tris: ReadonlyArray; - roofId: string; -} - -/** - * Minimal-Form eines Kontext-Meshes (importiertes Gebäude/Terrain, s. - * `ContextObject`) für den Raycast: rohe WORLD-Dreiecke (dieselbe Konvention - * wie {@link PickRoof} — model (x,y,z=Höhe) → world (x, z, y)), keine - * Vereinfachung auf ein Bounding-Prisma (Gebäude-Meshes sind zu unregelmässig - * dafür, ein grosszügiges Prisma stähle Klicks auf dahinterliegende Bauteile). - */ -export interface PickContextMesh { - tris: ReadonlyArray; - contextObjectId: string; -} - /** Ergebnis eines Picks: getroffenes Bauteil + Distanz entlang des Strahls. */ export interface PickHit { kind: "wall" | "ceiling" | "opening" | "stair" | "roof" | "contextObject" | "drawing"; diff --git a/src/viewport/useWasm3dRenderer.ts b/src/viewport/useWasm3dRenderer.ts index fcbf4804..0c533fd2 100644 --- a/src/viewport/useWasm3dRenderer.ts +++ b/src/viewport/useWasm3dRenderer.ts @@ -19,7 +19,7 @@ import { useCallback, useEffect, useRef, useState } from "react"; import type { ContextImage, Project } from "../model/types"; import { emitDrawingLineVerts, projectToModel3d } from "../plan/toWalls3d"; -import type { DetailLevel } from "../ui/TopBar"; +import type { DetailLevel } from "../model/viewTypes"; import { loadEngine3d } from "../engine/engine3d"; import { decodeMaterialTextures } from "./materialTextures"; import { decodeImageToRgba } from "../io/swissImage"; diff --git a/src/views/viewportContent.tsx b/src/views/viewportContent.tsx index 9569aac4..ab9f697f 100644 --- a/src/views/viewportContent.tsx +++ b/src/views/viewportContent.tsx @@ -49,7 +49,7 @@ import type { Pick3dHit } from "../viewport/Wasm3DViewport"; import { DrawingTabs } from "../DrawingTabs"; import type { ViewSnapshotTabsHandlers } from "../DrawingTabs"; import type { ToolDraft, ToolHandlers, ToolId } from "../tools/types"; -import type { DetailLevel, RenderMode, View3d, ViewType } from "../ui/TopBar"; +import type { DetailLevel, RenderMode, View3d, ViewType } from "../model/viewTypes"; /** * Akzentfarbe der 3D-Auswahl-Hervorhebung (Umriss-Linien, WASM-Viewport, s.