[143] DXF/DWG-Import: Höhenlinien als Gelände-Höhenlinien (contourSet) statt 2D-Zeichnung
Erkennung per Layer-Name, Erhebung/konstantem Z (3D-Polylinien) und Höhentexten (Kern import_terrain.rs); Option im Import-Dialog, Zähler in Dialog und Meldung.
This commit is contained in:
17 files changed
+555
-16
No files matched your search
@@ -486,6 +486,8 @@ async function importAny(path: string, args: Args): Promise<Project> {
|
||||
categoryMode: "byLayer",
|
||||
activeCategoryCode: base.layers[0].code,
|
||||
importMeshes: true,
|
||||
terrainContours: (parsed.summary.terrainContours ?? 0) > 0,
|
||||
terrainName: "Höhenlinien",
|
||||
parentName: `Import ${fileName}`,
|
||||
dashStyleTemplate: "PDF-Strich {pattern} mm",
|
||||
},
|
||||
|
||||
@@ -41,6 +41,10 @@ export interface DrawingImportDecision {
|
||||
parentName?: string;
|
||||
/** Name neuer Linienstile aus PDF-Strichmustern, `{pattern}` = Muster. */
|
||||
dashStyleTemplate?: string;
|
||||
/** [143] Erkannte Höhenlinien als Gelände-Höhenlinien (`contourSet`) statt als 2D-Zeichnung übernehmen. */
|
||||
terrainContours?: boolean;
|
||||
/** [143] Name des Höhenlinien-Satzes (übersetzt). */
|
||||
terrainName?: string;
|
||||
}
|
||||
|
||||
/** Rohergebnis des IFC-Lesers (`fileio`): Bericht (JSON), Positionen, Indizes, Zahlen der Bauteil-Erkennung. */
|
||||
@@ -504,7 +508,7 @@ export class ProjectDocument {
|
||||
* Linienstile, 2D-Zeichnungen, Kontext-Meshes) und wendet sie als EINEN Undo-Schritt an.
|
||||
*/
|
||||
importDrawing(base: Project, src: ImportSource, decision: DrawingImportDecision, now: number) {
|
||||
return this.commitCore<{ levelId: string; drawings: number; meshes: number }>(base, (h) =>
|
||||
return this.commitCore<{ levelId: string; drawings: number; meshes: number; terrainContours: number }>(base, (h) =>
|
||||
core().doc_import_drawing(h, src.geom, JSON.stringify(src.strings), JSON.stringify(src.source), JSON.stringify(decision), "", now),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2338,6 +2338,12 @@ export const de = {
|
||||
"import.placement.origin": "An DXF-Koordinaten (relativ zum Nullpunkt)",
|
||||
"import.placement.viewCenter": "In die Mitte der aktuellen Ansicht",
|
||||
"import.mesh.heading": "Meshes",
|
||||
"import.terrain.heading": "Höhenlinien",
|
||||
"import.terrain.asTerrain": "Höhenlinien als Gelände übernehmen ({n} erkannt)",
|
||||
"import.terrain.note": "Erkannt am Layer-Namen, an der Erhebung oder an Höhentexten. Sie landen als Gelände-Höhenlinien in der Kontext-Schicht (Befehl „Gelände erzeugen“, „Baugrube erstellen“), nicht als 2D-Zeichnung.",
|
||||
"import.terrain.fromTexts": "{n} Höhen stammen aus Höhentexten.",
|
||||
"import.terrain.setName": "Höhenlinien (Import)",
|
||||
"import.terrain.done": "{n} Höhenlinien als Gelände übernommen — „Gelände erzeugen“ bildet daraus das Geländemodell.",
|
||||
"import.mesh.asContext": "Meshes als Kontext-Geometrie (3D) importieren",
|
||||
"import.mesh.note": "Meshes sind keine 2D-Zeichnung — sie landen in der Kontext-Schicht.",
|
||||
"import.dwg.heading": "DWG-Datei",
|
||||
|
||||
@@ -2326,6 +2326,12 @@ export const en: Record<TranslationKey, string> = {
|
||||
"import.placement.origin": "At DXF coordinates (relative to origin)",
|
||||
"import.placement.viewCenter": "Centered in the current view",
|
||||
"import.mesh.heading": "Meshes",
|
||||
"import.terrain.heading": "Contour lines",
|
||||
"import.terrain.asTerrain": "Import contour lines as terrain ({n} found)",
|
||||
"import.terrain.note": "Detected by layer name, elevation or height labels. They become terrain contour lines in the context layer (\"Create terrain\", \"Create excavation\") instead of a 2D drawing.",
|
||||
"import.terrain.fromTexts": "{n} heights come from height labels.",
|
||||
"import.terrain.setName": "Contour lines (import)",
|
||||
"import.terrain.done": "{n} contour lines imported as terrain — \"Create terrain\" builds the terrain model from them.",
|
||||
"import.mesh.asContext": "Import meshes as context geometry (3D)",
|
||||
"import.mesh.note": "Meshes are not 2D drawings — they go into the context layer.",
|
||||
"import.dwg.heading": "DWG file",
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
// [143] DXF-Höhenlinien (Layer-Name, Erhebung, 3D-Polylinie, Höhentexte) werden beim Import zu Gelände-Höhenlinien
|
||||
// (`contourSet`) statt zu 2D-Zeichnungen; im leeren Projekt entsteht daraus mit „Gelände erzeugen" das Geländemodell.
|
||||
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import { parseDxf } from "./dxfParser";
|
||||
import { loadFileioForTests } from "../engine/fileioWasm.testing";
|
||||
import { importInto } from "./importView.testutil";
|
||||
import { emptyProject } from "../model/sampleProject";
|
||||
import { terrainCommand } from "../commands/cmds/terrain";
|
||||
import type { CommandContext } from "../commands/types";
|
||||
import type { Project } from "../model/types";
|
||||
|
||||
beforeAll(loadFileioForTests);
|
||||
|
||||
function dxf(...entities: string[][]): string {
|
||||
const lines = ["0", "SECTION", "2", "ENTITIES"];
|
||||
for (const pairs of entities) lines.push(...pairs);
|
||||
lines.push("0", "ENDSEC", "0", "EOF");
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
/** Rechteck-Ring (Kantenlänge 2·r) als LWPOLYLINE mit Erhebung (Gruppe 38). */
|
||||
const ring = (layer: string, r: number, z: number | null): string[] => [
|
||||
"0", "LWPOLYLINE", "8", layer, "90", "4", "70", "1", ...(z === null ? [] : ["38", String(z)]),
|
||||
"10", String(-r), "20", String(-r), "10", String(r), "20", String(-r), "10", String(r), "20", String(r), "10", String(-r), "20", String(r),
|
||||
];
|
||||
|
||||
/** 3D-Polylinie (POLYLINE-Flag 8) mit konstantem Z als offener Zug. */
|
||||
const poly3d = (layer: string, y: number, z: number): string[] => [
|
||||
"0", "POLYLINE", "8", layer, "70", "8",
|
||||
...[0, 5, 10].flatMap((x) => ["0", "VERTEX", "8", layer, "70", "32", "10", String(x), "20", String(y), "30", String(z)]),
|
||||
"0", "SEQEND",
|
||||
];
|
||||
|
||||
const text = (layer: string, s: string, x: number, y: number): string[] => ["0", "TEXT", "8", layer, "10", String(x), "20", String(y), "40", "0.5", "1", s];
|
||||
|
||||
const ctxOf = (p: Project): CommandContext => ({
|
||||
project: p,
|
||||
level: p.drawingLevels.find((l) => l.kind === "floor")!,
|
||||
defaultCategoryCode: p.layers[0].code,
|
||||
activeLineStyleId: "solid",
|
||||
activeWallTypeId: p.wallTypes[0]?.id ?? "",
|
||||
lastPoint: null,
|
||||
selection: { wallIds: [], drawingId: null, drawingIds: [] } as unknown as CommandContext["selection"],
|
||||
});
|
||||
|
||||
const sets = (p: Project) => (p.context ?? []).filter((o) => o.type === "contourSet");
|
||||
|
||||
describe("[143] DXF-Höhenlinien als Gelände", () => {
|
||||
it("erkennt Polylinien mit Erhebung auf einem Höhenlinien-Layer und zählt sie in der Zusammenfassung", () => {
|
||||
const parsed = parseDxf(dxf(ring("Hoehenlinien", 5, 430), ring("Hoehenlinien", 10, 431), ring("Hoehenlinien", 15, 432), ring("Wände", 3, null)));
|
||||
expect(parsed.summary.terrainContours).toBe(3);
|
||||
const r = importInto(emptyProject, parsed, { terrainContours: true, terrainName: "HL" });
|
||||
expect(r.terrainContours).toBe(3);
|
||||
expect(r.drawings).toHaveLength(1); // nur die Wand-Linie bleibt Zeichnung
|
||||
const [set] = sets(r.project);
|
||||
expect(set).toMatchObject({ type: "contourSet", name: "HL", categoryCode: "02" });
|
||||
if (set.type !== "contourSet") return;
|
||||
expect(set.contours.map((c) => c.z)).toEqual([430, 431, 432]);
|
||||
expect(set.contours.every((c) => c.closed && c.pts.length === 4)).toBe(true);
|
||||
});
|
||||
|
||||
it("ohne die Option bleibt alles 2D-Zeichnung", () => {
|
||||
const parsed = parseDxf(dxf(ring("Hoehenlinien", 5, 430), ring("Hoehenlinien", 10, 431)));
|
||||
const r = importInto(emptyProject, parsed, { terrainContours: false });
|
||||
expect(r.terrainContours).toBe(0);
|
||||
expect(r.drawings).toHaveLength(2);
|
||||
expect(sets(r.project)).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("3D-Polylinien mit konstantem Z auf beliebigem Layer (drei Höhen), Gefälle-Linien nicht", () => {
|
||||
const parsed = parseDxf(dxf(poly3d("L1", 0, 100), poly3d("L1", 10, 101), poly3d("L1", 20, 102)));
|
||||
expect(parsed.summary.terrainContours).toBe(3);
|
||||
const sloped = [
|
||||
"0", "POLYLINE", "8", "L1", "70", "8",
|
||||
...[100, 101, 102].flatMap((z, i) => ["0", "VERTEX", "8", "L1", "70", "32", "10", String(i), "20", "30", "30", String(z)]),
|
||||
"0", "SEQEND",
|
||||
];
|
||||
expect(parseDxf(dxf(poly3d("L1", 0, 100), poly3d("L1", 10, 101), sloped)).summary.terrainContours).toBeUndefined();
|
||||
});
|
||||
|
||||
it("Höhentexte ersetzen fehlendes Z; die Texte werden nicht noch einmal Zeichnung", () => {
|
||||
const parsed = parseDxf(
|
||||
dxf(ring("HL", 5, null), ring("HL", 10, null), text("Kote", "432.50", 0, 5.1), text("Kote", "433,0", 0, 10.1), text("Kote", "Hang", 0, 5)),
|
||||
);
|
||||
expect(parsed.summary.terrainContours).toBe(2);
|
||||
expect(parsed.summary.terrainFromTexts).toBe(2);
|
||||
const r = importInto(emptyProject, parsed, { terrainContours: true });
|
||||
const [set] = sets(r.project);
|
||||
if (set?.type !== "contourSet") throw new Error("contourSet erwartet");
|
||||
expect(set.contours.map((c) => c.z).sort()).toEqual([432.5, 433]);
|
||||
expect(r.drawings).toHaveLength(1); // Text „Hang"
|
||||
});
|
||||
|
||||
it("im leeren Projekt entsteht mit „Gelände erzeugen“ das Geländemodell aus den importierten Linien", () => {
|
||||
const parsed = parseDxf(dxf(ring("Hoehenlinien", 5, 430), ring("Hoehenlinien", 10, 431), ring("Hoehenlinien", 15, 432), ring("Hoehenlinien", 20, 433)));
|
||||
const r = importInto(emptyProject, parsed, { terrainContours: true });
|
||||
const res = terrainCommand.autoRun!(ctxOf(r.project));
|
||||
expect(res.notice).toBeUndefined();
|
||||
const out = res.commit!(r.project);
|
||||
expect((out.context ?? []).filter((o) => o.type === "terrainMesh")).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
@@ -33,6 +33,10 @@ export interface ImportSummary {
|
||||
layout?: string;
|
||||
/** Die Datei war beschädigt/abgeschnitten und wurde nur teilweise gelesen. */
|
||||
recovered: boolean;
|
||||
/** [143] Erkannte Gelände-Höhenlinien (Layer-Name, Erhebung, Höhentexte); fehlt, wenn keine gefunden wurden. */
|
||||
terrainContours?: number;
|
||||
/** [143] Davon Linien, deren Höhe aus einem Höhentext stammt. */
|
||||
terrainFromTexts?: number;
|
||||
}
|
||||
|
||||
/** Gelesene Datei + Zusammenfassung (Zustand des Import-Dialogs). */
|
||||
|
||||
@@ -632,7 +632,7 @@ export function useProjectFileActions(
|
||||
// der Aufbau nach dem Einhängen blockiert noch einmal mehrere Sekunden.
|
||||
beginBusy(t("busy.import"));
|
||||
const center = decision.placement === "viewCenter" ? planViewRef.current?.viewCenterModel() : undefined;
|
||||
let r: { levelId: string } | null = null;
|
||||
let r: { levelId: string; terrainContours?: number } | null = null;
|
||||
try {
|
||||
r = getState().commitImport((doc, base, now) =>
|
||||
doc.importDrawing(
|
||||
@@ -643,6 +643,8 @@ export function useProjectFileActions(
|
||||
categoryMode: decision.categoryMode,
|
||||
activeCategoryCode,
|
||||
importMeshes: decision.importMeshes,
|
||||
terrainContours: decision.terrainContours,
|
||||
terrainName: t("import.terrain.setName"),
|
||||
...(center ? { viewCenter: [center.x, center.y] as [number, number] } : {}),
|
||||
levelNameTemplate: t("default.drawingName", { n: "{n}" }),
|
||||
parentName: t("import.layers.parentName", { name: importParentName(decision) }),
|
||||
@@ -658,7 +660,11 @@ export function useProjectFileActions(
|
||||
}
|
||||
setImportState(null);
|
||||
// Auf die Ziel-Ebene wechseln, damit die importierte Geometrie sichtbar ist (zurückgewiesen: Hinweis weg).
|
||||
if (r) setActiveLevelId(r.levelId);
|
||||
if (r) {
|
||||
setActiveLevelId(r.levelId);
|
||||
// [143] Bericht: wie viele Linien als Gelände-Höhenlinien übernommen wurden.
|
||||
if (r.terrainContours) notify(t("import.terrain.done", { n: r.terrainContours }), "info");
|
||||
}
|
||||
else endBusy();
|
||||
};
|
||||
|
||||
|
||||
+26
-1
@@ -51,6 +51,8 @@ export interface ImportDecision {
|
||||
categoryMode: CategoryMode;
|
||||
/** Ob die Meshes als Kontext-Geometrie übernommen werden. */
|
||||
importMeshes: boolean;
|
||||
/** [143] Ob erkannte Höhenlinien als Gelände (Kontext) statt als 2D-Zeichnung übernommen werden. */
|
||||
terrainContours: boolean;
|
||||
/**
|
||||
* Platzierung der importierten Geometrie: `origin` = 1:1 an den DXF-Koordinaten
|
||||
* (relativ zum Nullpunkt); `viewCenter` = der Gesamt-Umriss wird in die Mitte
|
||||
@@ -185,6 +187,10 @@ export function ImportDialog({
|
||||
const [categoryModeChoice, setCategoryMode] = useState<CategoryMode | null>(null);
|
||||
const categoryMode: CategoryMode = categoryModeChoice ?? (layers.length > 0 ? "byLayer" : "active");
|
||||
const [importMeshes, setImportMeshes] = useState<boolean>(true);
|
||||
// [143] Vorgabe an, sobald Höhenlinien erkannt sind; erst eine Wahl des Nutzers überschreibt sie.
|
||||
const terrainFound = summary?.terrainContours ?? 0;
|
||||
const [terrainChoice, setTerrainChoice] = useState<boolean | null>(null);
|
||||
const terrainContours = terrainFound > 0 && (terrainChoice ?? true);
|
||||
const [placement, setPlacement] = useState<"origin" | "viewCenter">("origin");
|
||||
// Zwischen Klick auf „Importieren" und dem (synchronen, u. U. mehrere
|
||||
// Sekunden dauernden — Drawings ins Projekt einhängen + Plan/3D neu bauen)
|
||||
@@ -218,7 +224,7 @@ export function ImportDialog({
|
||||
// GEMALT. Ein setTimeout(0) feuert oft vor dem Paint — der Dialog sah dann
|
||||
// bis zum Ende des (blockierenden) Imports unverändert eingefroren aus.
|
||||
requestAnimationFrame(() =>
|
||||
requestAnimationFrame(() => onImport({ target, categoryMode, importMeshes, placement, parsed })),
|
||||
requestAnimationFrame(() => onImport({ target, categoryMode, importMeshes, terrainContours, placement, parsed })),
|
||||
);
|
||||
};
|
||||
|
||||
@@ -520,6 +526,25 @@ export function ImportDialog({
|
||||
</section>
|
||||
)}
|
||||
|
||||
{/* [143] Höhenlinien als Gelände. */}
|
||||
{terrainFound > 0 && (
|
||||
<section className="imp-section">
|
||||
<div className="imp-section-title">{t("import.terrain.heading")}</div>
|
||||
<label className="imp-check">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={terrainContours}
|
||||
onChange={(e) => setTerrainChoice(e.target.checked)}
|
||||
/>
|
||||
<span>{t("import.terrain.asTerrain", { n: terrainFound })}</span>
|
||||
</label>
|
||||
<div className="imp-note">
|
||||
{t("import.terrain.note")}
|
||||
{(summary?.terrainFromTexts ?? 0) > 0 && ` ${t("import.terrain.fromTexts", { n: summary?.terrainFromTexts ?? 0 })}`}
|
||||
</div>
|
||||
</section>
|
||||
)}
|
||||
|
||||
{/* Mesh-Behandlung. */}
|
||||
{hasMeshes && (
|
||||
<section className="imp-section">
|
||||
|
||||
Reference in new issue
Block a user