From 5d017677e430073196dd15b2fdb4c93266ad4fb3 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 12 Nov 2026 06:53:03 +0000 Subject: [PATCH] =?UTF-8?q?[181]=20Standort-Import:=20Linien=20als=20einze?= =?UTF-8?q?lne=202D-Polylinien=20auf=20der=20Klasse=20statt=20je=20Klasse?= =?UTF-8?q?=20ein=20contourSet;=20Tag-Namen=20importedMesh/terrainMesh=20b?= =?UTF-8?q?ewusst=20belassen=20(begr=C3=BCndet=20in=20TODO.md)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TODO.md | 11 +++- src/i18n/de.ts | 4 +- src/i18n/en.ts | 4 +- src/io/geoContext.test.ts | 37 +++++++++--- src/io/geoContext.ts | 82 +++++++++++---------------- src/native/ContextImportWindowApp.tsx | 2 +- src/native/contextImportWindow.ts | 2 +- src/panels/SitePanel.tsx | 2 +- src/panels/host.ts | 3 +- src/state/appStore.ts | 1 + src/state/resourceOps.test.ts | 17 ++++++ src/state/siteSlice.ts | 21 +++++-- src/state/useNativeWindowHosts.ts | 3 +- src/state/useProjectActions.ts | 16 ++++-- src/ui/ContextImportDialog.tsx | 12 ++-- 15 files changed, 129 insertions(+), 88 deletions(-) diff --git a/TODO.md b/TODO.md index 3e5313d3..ca5a9b39 100644 --- a/TODO.md +++ b/TODO.md @@ -58,8 +58,15 @@ Wer zu einer ID mehr wissen will (Entscheide, Tests, Bilder), sucht dort nach `* Gelände-Element (`import_context::ifc_meshes`), `mesh_view::is_terrain` entfällt. Panel „Gelände" ohne Import-Liste (nur Aktionen); Auswahl im Elemente-Panel (Knoten „Gelände & Umgebung"), Klasse im Kopf der Objekt-Info änderbar. Entwurf in `doc/ARCHITEKTUR.md` Abschnitt 8. Geprüft: Rust/vitest/e2e, Musterhaus komplex mit Nachbarnetzen Grundriss 1:200/Schnitt/ - Ansicht per CLI vor/nach byte-gleich. Offen: Linien des Standort-Imports (OSM/swisstopo-Umrisse) bleiben je Klasse ein - `contourSet` statt einzelner 2D-Zeichnungen; Tag-Namen `importedMesh`/`terrainMesh` historisch; Mac-Gegenprobe. · L + Ansicht per CLI vor/nach byte-gleich. Nachtrag (12.11.): Linien des Standort-Imports (OSM/swisstopo-Umrisse: + Strassen, Parzellen, Gewässer, Gebäudeumrisse …) sind jetzt einzelne `drawing2d`-Polylinien (offen/geschlossen) auf der + Klasse ihrer Kategorie, auf der aktiven Ebene, Stift aus der Klasse – einzeln wähl-, verschieb-, lösch-, editierbar + (`io/geoContext.ts::featuresToImport`, `siteSlice.addContextObjects(objs, lines)`, ein Undo-Schritt; Dialog und + Fenster-Brücke reichen `lines` durch). `contourSet` bleibt nur für echte Höhenlinien (mit z). Tag-Namen + `importedMesh`/`terrainMesh` bewusst belassen: die zwei Arten tragen verschiedene Felder (Gelände: Höhenfarben, + Intervall, Erdtiefe, Glättung, Quell-Id; Netz: Farbe, Glättungswinkel, IFC-GlobalId), ein gemeinsamer Typ `mesh` mit Rolle + wäre eine Union mit vielen Option-Feldern und würde ~360 Stellen in ~94 Dateien berühren, ohne Code zu sparen; der Name + ist nur ein Tag. Offen: Mac-Gegenprobe. · L - ◐ **[180]** Alles Sichtbare auf Ebene/Klasse (11.11., Vorgabe Maintainer). Umgesetzt (11.11.): Audit-Tabelle in `doc/ARCHITEKTUR.md` 3.6; Standard-Klassen der abgeleiteten Darstellung `08 Schatten` (Sonnenschatten Grundriss, Schlagschatten Ansicht), `81 Auto-Bemassung` (Befehl `autodim`, je Kette änderbar), `82 Höhenkoten` (automatische diff --git a/src/i18n/de.ts b/src/i18n/de.ts index 21b0ba7e..366f573c 100644 --- a/src/i18n/de.ts +++ b/src/i18n/de.ts @@ -3218,8 +3218,8 @@ export const de = { "ctxImport.working": "Lade Geodaten…", "ctxImport.empty": "Keine Geometrie im gewählten Bereich gefunden.", "ctxImport.importError": "Import fehlgeschlagen.", - "ctxImport.imported": "{count} Objekte in {sets} Sätzen importiert.", - "ctxImport.importedWithSkipped": "{count} Objekte in {sets} Sätzen importiert ({skipped} Gebäude-Kachel(n) übersprungen, zu gross).", + "ctxImport.imported": "{count} Objekte als einzelne Elemente importiert.", + "ctxImport.importedWithSkipped": "{count} Objekte als einzelne Elemente importiert ({skipped} Gebäude-Kachel(n) übersprungen, zu gross).", "ctxImport.buildingsSkipped": "Keine Gebäude geladen — {count} Kachel(n) waren zu gross (dicht bebautes Gebiet). Kleineren Radius versuchen oder Generation wechseln.", // ── Raum-Befehl ───────────────────────────────────────────────────────────── diff --git a/src/i18n/en.ts b/src/i18n/en.ts index b4743bcf..7cbbb191 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -3205,8 +3205,8 @@ export const en: Record = { "ctxImport.working": "Loading geodata…", "ctxImport.empty": "No geometry found in the selected area.", "ctxImport.importError": "Import failed.", - "ctxImport.imported": "Imported {count} objects in {sets} sets.", - "ctxImport.importedWithSkipped": "Imported {count} objects in {sets} sets ({skipped} building tile(s) skipped, too large).", + "ctxImport.imported": "Imported {count} objects as individual elements.", + "ctxImport.importedWithSkipped": "Imported {count} objects as individual elements ({skipped} building tile(s) skipped, too large).", "ctxImport.buildingsSkipped": "No buildings loaded — {count} tile(s) were too large (dense built-up area). Try a smaller radius or switch generation.", // Room command. diff --git a/src/io/geoContext.test.ts b/src/io/geoContext.test.ts index 9a0d361d..e0bd26c8 100644 --- a/src/io/geoContext.test.ts +++ b/src/io/geoContext.test.ts @@ -4,7 +4,7 @@ import { describe, it, expect } from "vitest"; import { buildingsToMesh, - featuresToContextObjects, + featuresToImport, DEFAULT_BUILDING_HEIGHT, } from "./geoContext"; import type { GeoFeature } from "./geoContext"; @@ -88,8 +88,8 @@ describe("buildingsToMesh", () => { }); }); -describe("featuresToContextObjects", () => { - it("liefert Footprint-contourSet UND extrudiertes Gebäude-Mesh", () => { +describe("featuresToImport", () => { + it("liefert je Linie eine eigene 2D-Polylinie auf der Klasse UND das extrudierte Gebäude-Netz", () => { const features: GeoFeature[] = [ { category: "building", pts: square(10), closed: true, height: 9 }, { @@ -100,12 +100,31 @@ describe("featuresToContextObjects", () => { ], closed: false, }, + { + category: "road", + pts: [ + { x: 0, y: 5 }, + { x: 20, y: 5 }, + ], + closed: false, + }, ]; - const objs = featuresToContextObjects(features, "Ort"); - const types = objs.map((o) => o.type).sort(); - // contourSet (Gebäude-Footprint) + contourSet (Strasse) + importedMesh. - expect(objs.some((o) => o.type === "importedMesh")).toBe(true); - expect(objs.filter((o) => o.type === "contourSet").length).toBe(2); - expect(types).toContain("importedMesh"); + const { objects, lines } = featuresToImport(features, "Ort"); + // Kein contourSet mehr: jede Linie ist ein eigenes Element mit eigener Id. + expect(objects.map((o) => o.type)).toEqual(["importedMesh"]); + expect(lines).toHaveLength(3); + expect(new Set(lines.map((l) => l.id)).size).toBe(3); + expect(lines.every((l) => l.type === "drawing2d" && l.geom.shape === "polyline")).toBe(true); + expect(lines.map((l) => l.categoryCode)).toEqual(["12", "11", "11"]); + const closed = lines.map((l) => (l.geom.shape === "polyline" ? l.geom.closed : null)); + expect(closed).toEqual([true, false, false]); + }); + + it("verwirft Linien mit weniger als zwei Punkten", () => { + const { lines } = featuresToImport( + [{ category: "road", pts: [{ x: 0, y: 0 }], closed: false }], + "Ort", + ); + expect(lines).toHaveLength(0); }); }); diff --git a/src/io/geoContext.ts b/src/io/geoContext.ts index 8172041d..12dd7896 100644 --- a/src/io/geoContext.ts +++ b/src/io/geoContext.ts @@ -3,14 +3,14 @@ // Beide Quellen liefern am Ende dasselbe: geschlossene/offene Polylinien in // LOKALEN Modell-Metern (bereits um die Origin verschoben, siehe lv95.ts), // kategorisiert nach Art (Gebäude/Strasse/Wasser/Grün/Parkplatz/Bahn/Wald). Die UI wandelt diese in -// Linien-Elemente (`contourSet`) je Klasse um und legt sie in `project.context` ([181]: normale Elemente mit -// Klasse; die Quelle steht nur als Auskunft in `source`). +// einzelne 2D-Polylinien (`drawing2d`) auf der Klasse ihrer Kategorie um ([181]: normale, unabhängige Elemente); +// Gebäude-Volumen kommen als Netz-Element in `project.context`. // // Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md). import { allowHost } from "../net/net"; import { core } from "../engine/coreWasm"; -import type { ContextObject, Contour, ImportedMesh } from "../model/types"; +import type { ContextObject, Drawing2D, ImportedMesh } from "../model/types"; import { GEO_CATEGORY_DEFS } from "../model/contextCategories"; /** Fachliche Kategorie einer importierten Kontext-Linie. */ @@ -41,17 +41,6 @@ export interface GeoFeature { /** Default-Gebäudehöhe (m), wenn keine Höhe aus der Quelle vorliegt. */ export const DEFAULT_BUILDING_HEIGHT = 9; -/** Menschlicher Objektname je Kategorie (deutsch). */ -const CATEGORY_LABEL: Record = { - building: "Gebäude", - road: "Strassen", - water: "Gewässer", - green: "Grünflächen", - parking: "Parkplätze", - railway: "Bahn", - forest: "Wald", -}; - /** Erzeugt eine (kollisionsarme) ID für ein neues Kontext-Objekt. */ function contextId(prefix: string): string { return `${prefix}-${Date.now().toString(36)}-${Math.random() @@ -59,52 +48,47 @@ function contextId(prefix: string): string { .slice(2, 8)}`; } +/** Importierte Linie als freies 2D-Element, noch ohne Zeichnungsebene (`levelId` setzt der Aufrufer). */ +export type ImportedLine = Omit; + +/** Ergebnis von {@link featuresToImport}: Kontext-Elemente (Volumen) und einzelne 2D-Linien. */ +export interface GeoImport { + objects: ContextObject[]; + lines: ImportedLine[]; +} + /** - * Wandelt importierte Features in `ContextObject`s (je Kategorie EIN - * ContourSet). Die Konturen liegen auf z=0 (Grundriss-Kontext); geschlossene - * Ringe (Gebäude/Wasser/Grün) werden als geschlossene Konturen markiert, - * Strassen als offene Linienzüge. Der Aufrufer legt das Ergebnis über - * `onAddContextObjects` in `project.context` ab. + * Wandelt importierte Features in normale, unabhängige Elemente ([181]): jede Linie/jeder Ring wird EINE + * 2D-Polylinie (`drawing2d`) auf der Klasse ihrer Kategorie (Stift aus der Klasse), einzeln wähl-, verschieb-, + * lösch- und editierbar; Gebäude zusätzlich als extrudiertes Volumen (`importedMesh`) für 3D. Geschlossene + * Ringe (Gebäude/Wasser/Grün) sind geschlossene Polylinien, Strassen offene. Der Aufrufer ergänzt die + * Zeichnungsebene und legt das Ergebnis über `onImport` ab. */ -export function featuresToContextObjects( - features: GeoFeature[], - sourceLabel: string, -): ContextObject[] { - const byCat = new Map(); +export function featuresToImport(features: GeoFeature[], sourceLabel: string): GeoImport { + const lines: ImportedLine[] = []; for (const f of features) { if (f.pts.length < 2) continue; - const list = byCat.get(f.category) ?? []; - list.push({ - z: 0, - pts: f.pts.map((p) => ({ x: p.x, y: p.y })), - closed: f.closed, - }); - byCat.set(f.category, list); - } - - const objs: ContextObject[] = []; - for (const [cat, contours] of byCat) { - if (contours.length === 0) continue; - objs.push({ - id: contextId(`geo-${cat}`), - type: "contourSet", - name: `${CATEGORY_LABEL[cat]} (${sourceLabel})`, - categoryCode: GEO_CATEGORY_DEFS[cat].code, - source: sourceLabel, - contours, + lines.push({ + id: contextId(`geo-${f.category}`), + type: "drawing2d", + categoryCode: GEO_CATEGORY_DEFS[f.category].code, + geom: { + shape: "polyline", + pts: f.pts.map((p) => ({ x: p.x, y: p.y })), + closed: f.closed, + }, }); } - // Gebäude zusätzlich als extrudierte Volumen (Footprint × Höhe) für die - // 3D-Ansicht. Der flache Footprint bleibt als contourSet erhalten (2D-Plan), - // das Volumen kommt als importedMesh dazu — beide teilen dieselbe Lage. + // Gebäude zusätzlich als extrudierte Volumen (Footprint × Höhe) für die 3D-Ansicht; die flachen + // Umrisse sind die Linien oben, das Volumen ein eigenes Netz-Element mit derselben Lage. + const objects: ContextObject[] = []; const buildingMesh = buildingsToMesh( features.filter((f) => f.category === "building"), sourceLabel, ); - if (buildingMesh) objs.push(buildingMesh); - - return objs; + if (buildingMesh) objects.push(buildingMesh); + return { objects, lines }; } /** diff --git a/src/native/ContextImportWindowApp.tsx b/src/native/ContextImportWindowApp.tsx index 51caffac..e8244e4d 100644 --- a/src/native/ContextImportWindowApp.tsx +++ b/src/native/ContextImportWindowApp.tsx @@ -66,7 +66,7 @@ export function ContextImportWindowApp() { return ( send("onImport", objs)} + onImport={(objs, lines) => send("onImport", objs, lines)} onClose={onClose} geoAnchor={state.geoAnchor} onSetGeoAnchor={(anchor: GeoAnchor | undefined) => send("onSetGeoAnchor", anchor)} diff --git a/src/native/contextImportWindow.ts b/src/native/contextImportWindow.ts index 3edeb5e4..0289a4d2 100644 --- a/src/native/contextImportWindow.ts +++ b/src/native/contextImportWindow.ts @@ -26,7 +26,7 @@ export interface ContextImportSyncState { } export interface ContextImportCommandHandlers { - onImport: (objs: unknown[]) => void; + onImport: (objs: unknown[], lines: unknown[]) => void; onSetGeoAnchor: (anchor: GeoAnchor | undefined) => void; } diff --git a/src/panels/SitePanel.tsx b/src/panels/SitePanel.tsx index b7e10b10..08d40cdd 100644 --- a/src/panels/SitePanel.tsx +++ b/src/panels/SitePanel.tsx @@ -86,7 +86,7 @@ export function SitePanel() { {ctxImportOpen && ( host.onAddContextObjects(objs)} + onImport={(objs, lines) => host.onAddContextObjects(objs, lines)} onClose={() => setCtxImportOpen(false)} geoAnchor={project.geoAnchor} onSetGeoAnchor={host.onSetGeoAnchor} diff --git a/src/panels/host.ts b/src/panels/host.ts index 2ebf8cf3..9290d345 100644 --- a/src/panels/host.ts +++ b/src/panels/host.ts @@ -40,6 +40,7 @@ import type { WallType, } from "../model/types"; import type { MeasurementReadout, SnapSettings, ToolId } from "../tools/types"; +import type { ImportedLine } from "../io/geoContext"; import type { TerrainOptions } from "../model/terrain"; import type { TextStylePreset } from "../text/richText"; import type { ScheduleKind } from "../export/exportSchedule"; @@ -608,7 +609,7 @@ export interface PanelHostValue { // ── Gelände und Umgebung (SitePanel, Elemente-Panel) ───────────────────── // Die Elemente selbst liest das Panel aus dem Store (`project.context`). /** Fügt mehrere Gelände-/Umgebungs-Elemente hinzu (z. B. aus einem Standort-Import). */ - onAddContextObjects: (objs: ContextObject[]) => void; + onAddContextObjects: (objs: ContextObject[], lines?: ImportedLine[]) => void; /** [181] Wählt ein Gelände-/Umgebungs-Element (Elemente-Panel); `zoom` passt die Ansicht ein. */ onSelectSiteElement: (id: string, opts?: { zoom?: boolean }) => void; /** diff --git a/src/state/appStore.ts b/src/state/appStore.ts index 1cddbf42..7fb1cb4c 100644 --- a/src/state/appStore.ts +++ b/src/state/appStore.ts @@ -54,6 +54,7 @@ const store = createStore((api) => ({ api as unknown as StoreApi< SiteSlice & { project: ProjectSlice["project"]; + activeLevelId: string; applyChange: ProjectSlice["applyChange"]; } >, diff --git a/src/state/resourceOps.test.ts b/src/state/resourceOps.test.ts index 1652621b..16decf61 100644 --- a/src/state/resourceOps.test.ts +++ b/src/state/resourceOps.test.ts @@ -115,6 +115,23 @@ describe("Kontext-Schicht über Ops", () => { }); }); +describe("Import-Linien als einzelne 2D-Elemente ([181])", () => { + it("Linien landen als eigene drawings2d auf der aktiven Ebene und Klasse, ein Undo-Schritt", () => { + const before = st().project.drawings2d.length; + const line = (id: string) => ({ + id, + type: "drawing2d" as const, + categoryCode: "11", + geom: { shape: "polyline" as const, pts: [{ x: 0, y: 0 }, { x: 5, y: 0 }], closed: false }, + }); + oneStep("addContextObjects+lines", () => st().addContextObjects([], [line("l1"), line("l2")])); + const added = st().project.drawings2d.slice(before); + expect(added.map((d) => d.id)).toEqual(["l1", "l2"]); + expect(added.every((d) => d.levelId === st().activeLevelId && d.categoryCode === "11")).toBe(true); + expect(st().project.context ?? []).toEqual([]); + }); +}); + describe("3D-Griffe: Element und mitgeführte Ecken", () => { it("ein Zug mit mehreren Maus-Schritten = ein Undo-Schritt (Gruppe mit Schlüssel)", () => { const [a, b] = st().project.walls; diff --git a/src/state/siteSlice.ts b/src/state/siteSlice.ts index 8a8bed0d..c33f8dca 100644 --- a/src/state/siteSlice.ts +++ b/src/state/siteSlice.ts @@ -9,7 +9,8 @@ // Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md). import { generateTerrainFromContours, resmoothGridTerrain, type TerrainOptions } from "../model/terrain"; -import type { ContextObject, Project, Vec2 } from "../model/types"; +import type { ContextObject, Drawing2D, Project, Vec2 } from "../model/types"; +import type { ImportedLine } from "../io/geoContext"; import { documentFor } from "../core/document"; import { transformOps } from "../tools/transform"; import { addItems, fieldOps, patchItem, removeItems } from "../core/opsBuild"; @@ -22,7 +23,11 @@ export interface SiteSlice { /** Fügt ein Kontext-Objekt (Mesh/Konturen/Gelände) hinzu (immutabel). */ addContextObject: (obj: ContextObject) => void; /** Fügt mehrere Kontext-Objekte in einem Schritt hinzu (z. B. DXF-Import). */ - addContextObjects: (objs: ContextObject[]) => void; + /** + * Übernimmt Importe als normale Elemente: Kontext-Objekte in `project.context`, Linien (`lines`, z. B. die + * Umrisse des Standort-Imports) als einzelne 2D-Zeichnungen auf der aktiven Ebene; ein Undo-Schritt. + */ + addContextObjects: (objs: ContextObject[], lines?: ImportedLine[]) => void; /** Entfernt ein Kontext-Objekt per ID (No-op bei unbekannter ID). */ removeContextObject: (id: string) => void; /** Entfernt mehrere Kontext-Objekte in EINEM Schritt (z. B. eine ganze @@ -76,6 +81,7 @@ export interface SiteSlice { */ type SiteSliceDeps = { project: Project; + activeLevelId: string; applyChange: (ops: readonly CoreOp[] | ((p: Project) => readonly CoreOp[]), coalesceKey?: string) => void; }; @@ -90,13 +96,16 @@ export function createSiteSlice( // `ensureContextCategories`), damit sie sofort im Ebenen-Panel erscheinen // und über dessen Sichtbarkeit/Grau/Sperren steuerbar sind — genau wie // Wand/Decke/Dach, statt wie bisher immer unconditional gezeichnet zu werden. - const addToContext = (added: ContextObject[]): void => { - if (added.length === 0) return; - const codes = added + const addToContext = (added: ContextObject[], lines: ImportedLine[] = []): void => { + if (added.length === 0 && lines.length === 0) return; + const levelId = get().activeLevelId; + const drawings: Drawing2D[] = lines.map((l) => ({ ...l, levelId })); + const codes = [...added, ...drawings] .map((o) => o.categoryCode) .filter((c): c is string => !!c); get().applyChange((p) => [ ...addItems("context", added), + ...addItems("drawings2d", drawings), ...fieldOps(p, "layers", ensureContextCategories(p.layers, codes)), ]); }; @@ -104,7 +113,7 @@ export function createSiteSlice( return { addContextObject: (obj) => addToContext([obj]), - addContextObjects: (objs) => addToContext(objs), + addContextObjects: (objs, lines) => addToContext(objs, lines), removeContextObject: (id) => get().applyChange((p) => removeItems(p, "context", [id])), diff --git a/src/state/useNativeWindowHosts.ts b/src/state/useNativeWindowHosts.ts index d04a3cc1..63375e1c 100644 --- a/src/state/useNativeWindowHosts.ts +++ b/src/state/useNativeWindowHosts.ts @@ -4,6 +4,7 @@ // dann den Inline-Editor. Aufgerufen von `App.tsx`. import type { ContextObject } from "../model/types"; +import type { ImportedLine } from "../io/geoContext"; import { setFieldIfChanged } from "../core"; import { isTauriRuntime } from "../native/projectFile"; import { useContextImportWindowHost } from "../native/contextImportWindow"; @@ -67,7 +68,7 @@ export function useNativeWindowHosts(opts: { // Standort-Import als eigenes natives Fenster — s. native/contextImportWindow.ts. useContextImportWindowHost(geoAnchor, { - onImport: (objs) => addContextObjectsAndFit(objs as ContextObject[]), + onImport: (objs, lines) => addContextObjectsAndFit(objs as ContextObject[], lines as ImportedLine[]), onSetGeoAnchor: (anchor) => applyChange((p) => setFieldIfChanged(p, "geoAnchor", anchor)), }); diff --git a/src/state/useProjectActions.ts b/src/state/useProjectActions.ts index 04b03813..64b1bdb8 100644 --- a/src/state/useProjectActions.ts +++ b/src/state/useProjectActions.ts @@ -13,6 +13,7 @@ import { addItems, fieldOps, patchItem, removeItems } from "../core"; import type { CoreOp } from "../core"; import { t } from "../i18n"; import { uniqueId } from "../tools/types"; +import type { ImportedLine } from "../io/geoContext"; import { instantiatePreset } from "../model/openingPresets"; import type { CeilingType, @@ -36,12 +37,15 @@ import type { NotifyKind } from "./notifySlice"; * Z-Achse (reine 2D-Projektion, wie die Plan-Darstellung der Kontext- * Konturen in generatePlan.ts). Leere/degenerierte Eingabe → null. */ -function contextObjectsBounds(objs: ContextObject[]): Vec2[] | null { +function contextObjectsBounds(objs: ContextObject[], lines: readonly ImportedLine[] = []): Vec2[] | null { let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity; const acc = (x: number, y: number) => { minX = Math.min(minX, x); minY = Math.min(minY, y); maxX = Math.max(maxX, x); maxY = Math.max(maxY, y); }; + for (const l of lines) { + if (l.geom.shape === "polyline") for (const p of l.geom.pts) acc(p.x, p.y); + } for (const obj of objs) { if (obj.type === "contourSet") { for (const c of obj.contours) for (const p of c.pts) acc(p.x, p.y); @@ -346,13 +350,13 @@ export function useProjectActions( // Wie addContextObjects, aber passt die Plan-Ansicht danach auf die Bounding- // Box der NEU importierten Objekte ein (Auto-Zoom auf Import, ROADMAP §11) — // sonst muss man nach Standort-/Geo-Import manuell zur Geometrie suchen. - const addContextObjectsAndFit = (objs: ContextObject[]) => { - addContextObjects(objs); - fitToContextObjects(objs); + const addContextObjectsAndFit = (objs: ContextObject[], lines: ImportedLine[] = []) => { + addContextObjects(objs, lines); + fitToContextObjects(objs, lines); }; /** Plan-Ansicht auf schon übernommene Kontext-Objekte einpassen (Importe im Kern, [K4] S4). */ - const fitToContextObjects = (objs: readonly ContextObject[]) => { - const pts = contextObjectsBounds(objs as ContextObject[]); + const fitToContextObjects = (objs: readonly ContextObject[], lines: readonly ImportedLine[] = []) => { + const pts = contextObjectsBounds(objs as ContextObject[], lines); if (pts) planViewRef.current?.fitBounds(pts); }; const generateTerrain = useStore((s) => s.generateTerrain); diff --git a/src/ui/ContextImportDialog.tsx b/src/ui/ContextImportDialog.tsx index d8d3756e..4fecf383 100644 --- a/src/ui/ContextImportDialog.tsx +++ b/src/ui/ContextImportDialog.tsx @@ -20,7 +20,7 @@ import type { TerrainResolution } from "../io/swissAlti3d"; import { fetchSwissImage } from "../io/swissImage"; import { fetchOsm } from "../io/osm"; import type { OsmSelection } from "../io/osm"; -import { featuresToContextObjects } from "../io/geoContext"; +import { featuresToImport, type ImportedLine } from "../io/geoContext"; import type { GeoFeature } from "../io/geoContext"; import { smoothTerrainGrid, terrainMeshFromGrid } from "../model/terrain"; import { makeOrigin } from "../io/lv95"; @@ -43,8 +43,8 @@ export interface GeoAnchor { } export interface ContextImportDialogProps { - /** Übernimmt die fertigen Kontext-Objekte (nach erfolgreichem Import). */ - onImport: (objs: ContextObject[]) => void; + /** Übernimmt die fertigen Elemente (nach erfolgreichem Import): Kontext-Objekte und einzelne 2D-Linien ohne Zeichnungsebene. */ + onImport: (objs: ContextObject[], lines: ImportedLine[]) => void; onClose: () => void; /** Aktueller Georeferenzierungs-Bezug des Projekts (falls schon gesetzt). */ geoAnchor?: GeoAnchor; @@ -330,21 +330,19 @@ export function ContextImportDialog({ }); } - const objs = featuresToContextObjects(all, selected.label); + const { objects: objs, lines } = featuresToImport(all, selected.label); for (const o of extraObjs) objs.push(o); if (terrain) objs.push(terrain); if (image) objs.push(image); - onImport(objs); + onImport(objs, lines); setStatus( buildingsSkipped > 0 ? t("ctxImport.importedWithSkipped", { count: all.length + extraObjs.length, - sets: objs.length, skipped: buildingsSkipped, }) : t("ctxImport.imported", { count: all.length + extraObjs.length, - sets: objs.length, }), ); onClose();