[181] Standort-Import: Linien als einzelne 2D-Polylinien auf der Klasse statt je Klasse ein contourSet; Tag-Namen importedMesh/terrainMesh bewusst belassen (begründet in TODO.md)
This commit is contained in:
15 files changed
+129
-88
No files matched your search
@@ -54,6 +54,7 @@ const store = createStore<RootState>((api) => ({
|
||||
api as unknown as StoreApi<
|
||||
SiteSlice & {
|
||||
project: ProjectSlice["project"];
|
||||
activeLevelId: string;
|
||||
applyChange: ProjectSlice["applyChange"];
|
||||
}
|
||||
>,
|
||||
|
||||
@@ -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;
|
||||
|
||||
+15
-6
@@ -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])),
|
||||
|
||||
|
||||
@@ -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)),
|
||||
});
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user