[154] DXF/DWG-Export georeferenziert: Baugrube, Baurecht und Bäume wandern mit (alle Entitäten in LV95)
Die Projekt-Verschiebung (translatePatch/translateOps, auch Neuer Bezugspunkt) liess Baugrube (excavation, Ebene CONTEXT) und Parzelle/Baulinien (siteRules, Ebene SYMBOLS) lokal; geo_rebase (IFC) vergass Baurecht und Bäume. Test: Musterhaus komplex je Geschoss, DXF alle Punkt-Codes und DWG (libredwg) im LV95-Rahmen, Rundreise Export -> Import in einem Rahmen.
This commit is contained in:
5 files changed
+213
-5
No files matched your search
@@ -4018,6 +4018,15 @@ Code-Übernahme Lizenz der Abhängigkeiten prüfen, Pflicht [51].
|
||||
Reihenfolge, Ebenen, Strichstärken, True-Color, Koordinaten ≤ 5e-7 m (Rundung des alten Writers auf 6 Stellen;
|
||||
neu volle f64). Neu: 2D-Texte als TEXT (fehlten bisher), CLI exportiert georeferenziert wie die App.
|
||||
Gegencheck ezdxf (`scripts/validate-dxf.py`, Test übersprungen ohne `pip install ezdxf`): 0 Auditor-Fehler.
|
||||
- ✅ **Georeferenzierter Export: alle Entitäten in LV95** (7.11., Befund aus [154]): Baugrube (Kontext `excavation`,
|
||||
Ebene CONTEXT) und Parzelle/Baulinien (`siteRules`, Ebene SYMBOLS) blieben beim Export mit `geoAnchor` (App, CLI `dxf`/`dwg`)
|
||||
lokal und lagen nach dem Import 2.7 Mio. m neben dem Gebäude. Ursache: die Projekt-Verschiebung (`geo_translate.rs`,
|
||||
`translatePatch`/`translateOps`; auch „Neuer Bezugspunkt“) nahm Baugrube und Baurecht nicht mit (Baugrube bekam sogar ein
|
||||
leeres `positions`); `geo_rebase.rs` (IFC) vergass Baurecht und Bäume. Jetzt Baugrube (Umriss), Baurecht (Parzelle,
|
||||
Baulinien, Feld-Op `siteRules`) und Bäume überall. Test `export/exportDxf.georef.test.ts`: Musterhaus komplex je Geschoss
|
||||
bei 1:50, DXF alle Punkt-Codes (10/11/13/14: Linien, Polylinien, Bögen, Texte, INSERT + ATTRIB, Bemassung, HATCH, Kontext)
|
||||
und DWG (libredwg) im LV95-Rahmen ± 200 m, Rundreise Export → Import gemeinsam in einem Rahmen; Rust je 1 Test.
|
||||
Linksbündige TEXT tragen im DWG den Ausrichtungspunkt (0, 0) wie AutoCAD (`(11 0 0 0)`, ohne Wirkung). Nur Linux-Container.
|
||||
- ✅ **Binär-DXF-Export** (28.10.): `export_dxf_binary` (acadrust `DxfWriter::new_binary`, R2018 UTF-8),
|
||||
Dialog-Format „DXF binär“, CLI `dxf --binary`. Rundreise acadrust + ezdxf (gleiche Entitäten/Ebenen wie
|
||||
ASCII, 0 Auditor-Fehler, kleiner als der Text). Offen: in AutoCAD/BricsCAD selbst nicht geöffnet.
|
||||
|
||||
@@ -81,7 +81,8 @@ fn shift_positions(pos: &mut [f64], dx: f64, dy: f64) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Verschiebt sämtliche Modell-Koordinaten (`translateProject`), auch die Innenhöfe der Dächer.
|
||||
/// Verschiebt sämtliche Modell-Koordinaten (`translateProject`), auch die Innenhöfe der Dächer, Bäume und
|
||||
/// das Baurecht (Parzelle, Baulinien).
|
||||
pub fn translate_project(p: &Project, dx: f64, dy: f64) -> Project {
|
||||
if dx == 0.0 && dy == 0.0 {
|
||||
return p.clone();
|
||||
@@ -114,6 +115,16 @@ pub fn translate_project(p: &Project, dx: f64, dy: f64) -> Project {
|
||||
for c in out.columns.iter_mut().flatten() {
|
||||
c.position = shift(c.position, dx, dy);
|
||||
}
|
||||
for t in out.trees.iter_mut().flatten() {
|
||||
t.position = shift(t.position, dx, dy);
|
||||
}
|
||||
if let Some(r) = &mut out.site_rules {
|
||||
shift_all(&mut r.parcel, dx, dy);
|
||||
for l in r.building_lines.iter_mut().flatten() {
|
||||
l.a = shift(l.a, dx, dy);
|
||||
l.b = shift(l.b, dx, dy);
|
||||
}
|
||||
}
|
||||
for s in out.extruded_solids.iter_mut().flatten() {
|
||||
shift_all(&mut s.points, dx, dy);
|
||||
if let Some(c) = &mut s.circle {
|
||||
@@ -191,6 +202,23 @@ mod tests {
|
||||
assert_eq!(r.holes.as_ref().unwrap()[0][2], Vec2 { x: 12.0, y: -3.0 });
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn baurecht_baeume_und_baugrube_wandern_mit() {
|
||||
// Befund [154]: Parzelle/Baulinien blieben in Welt-Exporten lokal.
|
||||
let mut p: Project = serde_json::from_str(include_str!("../tests/fixtures/sample_project.json")).unwrap();
|
||||
p.site_rules = Some(SiteRules {
|
||||
parcel: vec![Vec2 { x: -1.0, y: -1.0 }, Vec2 { x: 5.0, y: -1.0 }, Vec2 { x: 5.0, y: 4.0 }],
|
||||
building_lines: Some(vec![SiteRulesBuildingLines { a: Vec2 { x: 0.0, y: 3.0 }, b: Vec2 { x: 4.0, y: 3.0 }, ..Default::default() }]),
|
||||
..Default::default()
|
||||
});
|
||||
p.trees = Some(vec![Tree { id: "t".into(), position: Vec2 { x: 1.0, y: 1.0 }, ..Default::default() }]);
|
||||
let t = translate_project(&p, 10.0, -5.0);
|
||||
let s = t.site_rules.as_ref().unwrap();
|
||||
assert_eq!(s.parcel[2], Vec2 { x: 15.0, y: -1.0 });
|
||||
assert_eq!(s.building_lines.as_ref().unwrap()[0].a, Vec2 { x: 10.0, y: -2.0 });
|
||||
assert_eq!(t.trees.as_ref().unwrap()[0].position, Vec2 { x: 11.0, y: -4.0 });
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lv95_bern() {
|
||||
// Bezugspunkt Bern (alte Sternwarte): 46°57'08.66" N, 7°26'22.50" E.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Verschiebung des ganzen Projekts um einen festen Vektor ([K4] S3, vorher `translateProject` in
|
||||
//! `src/model/geoRebase.ts`; Befehl „Neuer Bezugspunkt", Welt-Koordinaten für DXF/IFC-Export): reine
|
||||
//! Translation aller Modell-Koordinaten (Wände, Decken, Dächer, Treppen, Räume, Stützen, Extrusionen,
|
||||
//! 2D-Zeichnungen, Kontext-Schicht, Schnitt-/Ansichtslinien, Geo-Anker). Richtungsvektoren und Winkel
|
||||
//! 2D-Zeichnungen, Kontext-Schicht inkl. Baugrube, Bäume, Schnitt-/Ansichtslinien, Baurecht, Geo-Anker). Richtungsvektoren und Winkel
|
||||
//! bleiben, Höhen (z) auch. Rechnung auf der rohen Projekt-Wurzel (`serde_json`).
|
||||
//!
|
||||
//! Wie in TS bestehen verschobene Punkte nur aus `x`/`y` (weitere Felder eines Punkts entfallen).
|
||||
@@ -104,7 +104,7 @@ fn shift_contour(c: &Value, dx: f64, dy: f64) -> Value {
|
||||
Value::Object(m)
|
||||
}
|
||||
|
||||
/// Kontext-Objekt: Konturen-Satz, Bild (min/max) oder Mesh (`positions` = flache `[x, y, z]`-Tripel, nur x/y).
|
||||
/// Kontext-Objekt: Konturen-Satz, Bild (min/max), Baugrube (Umriss) oder Mesh (`positions` = flache `[x, y, z]`-Tripel, nur x/y).
|
||||
fn shift_context(o: &Value, dx: f64, dy: f64) -> Value {
|
||||
let mut m = obj(o);
|
||||
match o.get("type").and_then(Value::as_str) {
|
||||
@@ -113,6 +113,8 @@ fn shift_context(o: &Value, dx: f64, dy: f64) -> Value {
|
||||
set(&mut m, "contours", Some(Value::Array(cs)));
|
||||
}
|
||||
Some("image") => shift_pts_fields(&mut m, &["min", "max"], dx, dy, &[]),
|
||||
// Baugrube ([68]): Sohle-Umriss (Böschungen/Bermen sind Abstände, keine Lage).
|
||||
Some("excavation") => shift_pts_fields(&mut m, &[], dx, dy, &["outline"]),
|
||||
_ => {
|
||||
let mut pos: Vec<Value> = o.get("positions").and_then(Value::as_array).cloned().unwrap_or_default();
|
||||
let mut i = 0;
|
||||
@@ -228,6 +230,27 @@ pub fn translate_anchor(root: &Map<String, Value>, dx: f64, dy: f64) -> Option<V
|
||||
Some(Value::Object(m))
|
||||
}
|
||||
|
||||
/// Baurecht verschoben (`siteRules.parcel`, `buildingLines[].a/b`; Grenzabstände/Höhen bleiben), `None` ohne.
|
||||
pub fn translate_site_rules(root: &Map<String, Value>, dx: f64, dy: f64) -> Option<Value> {
|
||||
let r = root.get("siteRules").filter(|v| truthy(Some(v)))?;
|
||||
let mut m = obj(r);
|
||||
if m.contains_key("parcel") {
|
||||
shift_pts_fields(&mut m, &[], dx, dy, &["parcel"]);
|
||||
}
|
||||
if let Some(Value::Array(ls)) = r.get("buildingLines") {
|
||||
let n: Vec<Value> = ls
|
||||
.iter()
|
||||
.map(|l| {
|
||||
let mut lm = obj(l);
|
||||
shift_pts_fields(&mut lm, &["a", "b"], dx, dy, &[]);
|
||||
Value::Object(lm)
|
||||
})
|
||||
.collect();
|
||||
m.insert("buildingLines".into(), Value::Array(n));
|
||||
}
|
||||
Some(Value::Object(m))
|
||||
}
|
||||
|
||||
/// Patch für `{...project, ...patch}`: verschobene Listen und Geo-Anker (`translateProject`). Leer bei `dx = dy = 0`.
|
||||
pub fn project_patch(root: &Map<String, Value>, dx: f64, dy: f64) -> Map<String, Value> {
|
||||
let mut out = Map::new();
|
||||
@@ -238,6 +261,9 @@ pub fn project_patch(root: &Map<String, Value>, dx: f64, dy: f64) -> Map<String,
|
||||
if let Some(a) = translate_anchor(root, dx, dy) {
|
||||
out.insert("geoAnchor".into(), a);
|
||||
}
|
||||
if let Some(r) = translate_site_rules(root, dx, dy) {
|
||||
out.insert("siteRules".into(), r);
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
@@ -255,6 +281,9 @@ pub fn translate_ops(root: &Map<String, Value>, dx: f64, dy: f64) -> Vec<Value>
|
||||
if let Some(a) = translate_anchor(root, dx, dy) {
|
||||
ops.push(json!({"kind": "setField", "key": "geoAnchor", "value": a}));
|
||||
}
|
||||
if let Some(r) = translate_site_rules(root, dx, dy) {
|
||||
ops.push(json!({"kind": "setField", "key": "siteRules", "value": r}));
|
||||
}
|
||||
ops
|
||||
}
|
||||
|
||||
@@ -304,6 +333,25 @@ mod tests {
|
||||
assert!(project_patch(&p, 0.0, 0.0).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn baugrube_und_baurecht_wandern_mit() {
|
||||
// Befund [154]: Baugrube (Kontext `excavation`) und Parzelle/Baulinien (`siteRules`) blieben beim
|
||||
// georeferenzierten DXF-Export lokal und lagen nach dem Import neben dem Gebäude.
|
||||
let p = root(json!({
|
||||
"context": [{"id": "b", "type": "excavation", "outline": [{"x": 0, "y": 0}, {"x": 2, "y": 0}, {"x": 2, "y": 1}], "bottom": -3}],
|
||||
"siteRules": {"parcel": [{"x": -1, "y": -1}, {"x": 5, "y": -1}, {"x": 5, "y": 4}], "defaultSetback": 5, "buildingLines": [{"a": {"x": 0, "y": 3}, "b": {"x": 4, "y": 3}}]},
|
||||
}));
|
||||
let patch = project_patch(&p, 100.0, 200.0);
|
||||
assert_eq!(patch["context"][0]["outline"][1], json!({"x": 102.0, "y": 200.0}));
|
||||
assert!(patch["context"][0].get("positions").is_none());
|
||||
assert_eq!(patch["context"][0]["bottom"], -3);
|
||||
assert_eq!(patch["siteRules"]["parcel"][0], json!({"x": 99.0, "y": 199.0}));
|
||||
assert_eq!(patch["siteRules"]["buildingLines"][0]["b"], json!({"x": 104.0, "y": 203.0}));
|
||||
assert_eq!(patch["siteRules"]["defaultSetback"], 5);
|
||||
let ops = translate_ops(&p, 1.0, 1.0);
|
||||
assert!(ops.iter().any(|o| o["kind"] == "setField" && o["key"] == "siteRules" && o["value"]["parcel"][0] == json!({"x": 0.0, "y": 0.0})));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ops_ohne_unveraenderte_ebenen() {
|
||||
let p = root(json!({
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
// Georeferenzierter DXF-/DWG-Export ([154]-Befund, 7.11.): ALLE Entitäten liegen im selben Rahmen (LV95).
|
||||
// Vorher blieben die Baugrube (Kontext `excavation`, Ebene CONTEXT) und Parzelle/Baulinien (`siteRules`,
|
||||
// Ebene SYMBOLS) in lokalen Koordinaten, weil die Projekt-Verschiebung sie nicht mitnahm — nach dem Import
|
||||
// lagen sie Hunderte Kilometer neben dem Gebäude. Geprüft am Musterhaus komplex (Kataster, Raster, Bemassung,
|
||||
// Blöcke/INSERT mit ATTRIB, Texte, Schraffur bei 1:50, Kontext), je Geschoss: DXF (Gruppen-Codes), DWG
|
||||
// (libredwg) und die Rundreise durch den eigenen Import.
|
||||
|
||||
import "../engine/fileioWasm.setup";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildPlanDwg, buildPlanDxf } from "./exportDxf";
|
||||
import { libreDwgReader, nums, readDxf } from "./cadReadBack.testutil";
|
||||
import { buildComplexSampleProject } from "../model/sampleProjectComplex";
|
||||
import { generatePlan } from "../plan/generatePlan";
|
||||
import { flattenCategories } from "../model/types";
|
||||
import type { Project } from "../model/types";
|
||||
import { projectGeoOrigin, projectToWorldCoords } from "../model/geoRebase";
|
||||
import { parseDxf } from "../io/dxfParser";
|
||||
import { ProjectDocument } from "../core/document";
|
||||
|
||||
const allCodes = (p: Project) => new Set(flattenCategories(p.layers).map((l) => l.code));
|
||||
|
||||
const project = buildComplexSampleProject();
|
||||
const origin = projectGeoOrigin(project)!;
|
||||
const world = projectToWorldCoords(project);
|
||||
const floors = project.drawingLevels.filter((l) => l.kind === "floor");
|
||||
/** Rahmen um das Grundstück (Kataster der Nachbarn reicht ≈ 55 m weit). */
|
||||
const R = 200;
|
||||
const inFrame = (x: number, y: number) => Math.abs(x - origin.e) < R && Math.abs(y - origin.n) < R;
|
||||
|
||||
describe("Georeferenzierter Export: alle Entitäten im LV95-Rahmen", () => {
|
||||
it("Baugrube und Baurecht wandern mit dem Projekt", () => {
|
||||
const ex = world.context?.find((c) => c.type === "excavation");
|
||||
expect(ex && "outline" in ex && ex.outline.every((p) => inFrame(p.x, p.y))).toBe(true);
|
||||
expect(ex && "positions" in ex).toBe(false);
|
||||
expect(world.siteRules!.parcel.every((p) => inFrame(p.x, p.y))).toBe(true);
|
||||
expect(world.siteRules!.buildingLines!.every((l) => inFrame(l.a.x, l.a.y) && inFrame(l.b.x, l.b.y))).toBe(true);
|
||||
});
|
||||
|
||||
for (const lvl of floors) {
|
||||
it(`${lvl.name}: DXF (alle Punkt-Codes) und DWG (libredwg)`, async () => {
|
||||
// 1:50: Wände mit Schraffur (HATCH) statt schwarzer Füllung.
|
||||
const plan = generatePlan(world, lvl.id, allCodes(world), undefined, "mittel", false, false, true, 50);
|
||||
const dxf = readDxf(buildPlanDxf(plan, world, { scaleDenominator: 50, levelId: lvl.id }));
|
||||
const bad: string[] = [];
|
||||
// Punkt-Codes der Modellbereichs-Entitäten (10/11/13/14 x, 20/21/23/24 y): Endpunkte, Ecken, Einfügepunkte,
|
||||
// Textlagen, Bemassungs-Definitionspunkte, Schraffur-Ränder.
|
||||
for (const e of dxf.entities) {
|
||||
for (const [cx, cy] of [[10, 20], [11, 21], [13, 23], [14, 24]]) {
|
||||
const xs = nums(e, cx);
|
||||
const ys = nums(e, cy);
|
||||
for (let i = 0; i < Math.min(xs.length, ys.length); i++) {
|
||||
// HATCH: Seed-/Musterbasispunkt (0, 0) ist kein Lagepunkt.
|
||||
if (e.type === "HATCH" && xs[i] === 0 && ys[i] === 0) continue;
|
||||
if (!inFrame(xs[i], ys[i])) bad.push(`${e.layer}/${e.type} ${cx}: ${xs[i]}, ${ys[i]}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
expect(bad.slice(0, 5)).toEqual([]);
|
||||
expect(dxf.entities.some((e) => e.type === "INSERT")).toBe(true);
|
||||
|
||||
const db = (await libreDwgReader())(buildPlanDwg(plan, world, { scaleDenominator: 50, levelId: lvl.id }));
|
||||
// TEXT links/Grundlinie: der Ausrichtungspunkt ist nicht gespeichert und lautet (0, 0) wie bei AutoCAD
|
||||
// (`(11 0 0 0)`); er gilt nur bei Mitte/rechts — dort steht er im Rahmen (endPoint geprüft).
|
||||
const unset = (e: { type: string }, p?: { x: number; y: number }) => e.type === "TEXT" && p?.x === 0 && p?.y === 0;
|
||||
const dwgBad = db.entities.flatMap((e) =>
|
||||
[e.startPoint, unset(e, e.endPoint) ? undefined : e.endPoint, e.center, ...(e.vertices ?? [])]
|
||||
.filter((p) => p && !inFrame(p.x, p.y))
|
||||
.map((p) => `${e.layer}/${e.type}: ${p!.x}, ${p!.y}`),
|
||||
);
|
||||
expect(dwgBad.slice(0, 5)).toEqual([]);
|
||||
});
|
||||
}
|
||||
|
||||
it("Rundreise Export → Import: alle importierten Zeichnungen im selben Rahmen", () => {
|
||||
const plan = generatePlan(world, "eg", allCodes(world));
|
||||
const parsed = parseDxf(buildPlanDxf(plan, world, { levelId: "eg" }));
|
||||
const base: Project = {
|
||||
...project,
|
||||
geoAnchor: undefined,
|
||||
siteRules: undefined,
|
||||
walls: [],
|
||||
openings: [],
|
||||
rooms: [],
|
||||
drawings2d: [],
|
||||
stairs: [],
|
||||
ceilings: [],
|
||||
roofs: [],
|
||||
columns: [],
|
||||
context: [],
|
||||
};
|
||||
const doc = new ProjectDocument(base);
|
||||
const r = doc.importDrawing(
|
||||
base,
|
||||
parsed.src,
|
||||
{
|
||||
target: { kind: "new", name: "Import" },
|
||||
categoryMode: "byLayer",
|
||||
activeCategoryCode: "20",
|
||||
importMeshes: false,
|
||||
levelNameTemplate: "Import {n}",
|
||||
parentName: "Import",
|
||||
dashStyleTemplate: "{pattern}",
|
||||
},
|
||||
0,
|
||||
);
|
||||
doc.close();
|
||||
if ("problems" in r) throw new Error(r.problems.join("; "));
|
||||
// Alle Punkte der importierten Zeichnungen (wie immer der Import sie verschiebt: gemeinsam).
|
||||
const xs: number[] = [];
|
||||
const ys: number[] = [];
|
||||
for (const d of r.project.drawings2d) {
|
||||
for (const m of JSON.stringify(d.geom).matchAll(/\{"x":(-?[\d.e+-]+),"y":(-?[\d.e+-]+)\}/g)) {
|
||||
xs.push(Number(m[1]));
|
||||
ys.push(Number(m[2]));
|
||||
}
|
||||
}
|
||||
expect(xs.length).toBeGreaterThan(1000);
|
||||
const span = (v: number[]) => v.reduce((a, b) => Math.max(a, b), -Infinity) - v.reduce((a, b) => Math.min(a, b), Infinity);
|
||||
expect(span(xs)).toBeLessThan(2 * R);
|
||||
expect(span(ys)).toBeLessThan(2 * R);
|
||||
});
|
||||
});
|
||||
@@ -24,8 +24,9 @@ import type { Project } from "./types";
|
||||
/**
|
||||
* Verschiebt SÄMTLICHE Modell-Koordinaten eines Projekts um den festen Vektor
|
||||
* (dx,dy) — Wände, Decken, Dächer, Öffnungen-Host (folgt automatisch der Wand),
|
||||
* Treppen, Räume, Stützen, Extrusionen, freie 2D-Geometrie, Kontext-Schicht
|
||||
* (Import/Terrain/Konturen), Schnitt-/Ansichtslinien sowie den Geo-Anker
|
||||
* Treppen, Räume, Stützen, Bäume, Extrusionen, freie 2D-Geometrie, Kontext-Schicht
|
||||
* (Import/Terrain/Konturen/Baugrube), Schnitt-/Ansichtslinien, Baurecht (Parzelle,
|
||||
* Baulinien; bis 7.11. vergessen, [154]) sowie den Geo-Anker
|
||||
* (`geoAnchor.model`, damit der LV95-Bezug exakt erhalten bleibt). Richtungs-
|
||||
* Vektoren (z. B. `Stair.dir`) und Winkel-Felder bleiben unangetastet — eine
|
||||
* reine Translation ändert keine Orientierung. Unveränderte Teile behalten ihre Identität;
|
||||
|
||||
Reference in new issue
Block a user