[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
@@ -158,8 +158,13 @@ Wer zu einer ID mehr wissen will (Entscheide, Tests, Bilder), sucht dort nach `*
|
||||
- ◐ **[68]** Baugrube/Geländebearbeitung (Kontext-Objekt `excavation`). Verbau als echte Wand im Schnitt mit Dicke/
|
||||
Schraffur; Überlappung der Sohlenfläche nur gerastert; Arbeitsraum an konkaven Ecken ohne Prüfung; IVHB-Terrain
|
||||
nach kantonalem Recht. · M
|
||||
- ◐ **[143]** Baugrube erstellen. DXF-Höhenlinien landen als 2D-Zeichnung statt als `contourSet` (im leeren Projekt
|
||||
kein Weg zu „Gelände erzeugen“ ausser Standort-Import); Option „Baugrube aus Gebäudegrundfläche“. · S
|
||||
- ◐ **[143]** Baugrube erstellen. (9.11.) DXF/DWG-Höhenlinien werden beim Import erkannt (Layer-Name Höhenlinie/HL/
|
||||
Contour/Kote …, Erhebung Gruppe 38, 3D-Polylinien mit konstantem Z, sonst Höhentexte nahe der Linie) und als
|
||||
`contourSet` „02 Gelände“ statt als 2D-Zeichnung übernommen: Kern `import_terrain.rs`, Option „Höhenlinien als Gelände
|
||||
übernehmen“ im Import-Dialog (Vorgabe an, wenn erkannt), Zähler in Dialog und Meldung; „Gelände erzeugen“ geht damit im
|
||||
leeren Projekt. Geprüft: Rust (fileio, Kern), vitest `src/io/dxfTerrainImport.test.ts`; nicht in der Tauri-App/im
|
||||
Dialog angesehen, DWG nur über denselben Pfad. Offen: Option „Baugrube aus Gebäudegrundfläche“; Höhenlinien aus
|
||||
Splines/Bögen und mit abweichender Texthöhe-Zuordnung (Text weiter als 2.5× Höhe von der Linie) werden nicht erkannt. · S
|
||||
- ◐ **[27]** Punktwolken Stufe 1 (render3d `points.rs`). Beim Neuladen sind die Wolken weg (Stufe 2: Modellfeld
|
||||
`Project.pointClouds` + Asset, Vorschlag unter [B9]/`src/state/pointCloudStore.ts`); Speicher doppelt; Grundriss/
|
||||
Schnitt (Punkte in Scheibe), Fang an Punkten, Clip-Box. · L
|
||||
|
||||
@@ -95,7 +95,7 @@ Neues Modul: `<modul>.rs` und `mod` in `lib.rs`, Bindungen in `web/<modul>.rs` u
|
||||
| Datei | Inhalt |
|
||||
|---|---|
|
||||
| `import_ifc.rs`, `import_context.rs` | IFC zu Bauteilen bzw. Kontext-Netzen (gelesen hat vorher `fileio`) |
|
||||
| `import_drawing.rs`, `geo_mesh.rs` | DXF/DWG-Zeichnungen ins Projekt; swissBUILDINGS3D-Netze |
|
||||
| `import_drawing.rs`, `import_terrain.rs`, `geo_mesh.rs` | DXF/DWG-Zeichnungen ins Projekt (`import_terrain`: Höhenlinien erkennen, [143]); swissBUILDINGS3D-Netze |
|
||||
| `ifc_data.rs`, `ifc_quantities.rs`, `ifc_stairs.rs` | IFC-Export-Sammler, Basismengen, Treppen |
|
||||
| `mesh_data.rs` | Sammler für OBJ, STL, glTF |
|
||||
| `export_schedule.rs`, `opening_schedule.rs` | Bauteilliste, Fenster- und Türliste |
|
||||
|
||||
@@ -24,6 +24,8 @@ use std::collections::{HashMap, HashSet};
|
||||
|
||||
/// Kategorie generischer Importe (`GENERIC_IMPORT_CATEGORY`, „10 Situation").
|
||||
pub const GENERIC_IMPORT_CODE: &str = "10";
|
||||
/// [143] Kategorie der importierten Gelände-Höhenlinien (02 Gelände).
|
||||
const TERRAIN_CATEGORY: &str = "02";
|
||||
/// Füllfarbe aus HATCH importierter Flächen (`DXF_HATCH_FILL`).
|
||||
const DXF_HATCH_FILL: &str = "#c8c8c8";
|
||||
/// Papier-Millimeter je PDF-Punkt.
|
||||
@@ -74,6 +76,8 @@ pub struct Contour {
|
||||
pub closed: bool,
|
||||
pub filled: bool,
|
||||
pub curve: Option<Curve>,
|
||||
/// [143] Höhe wechselt entlang der Linie (3D-Polylinie mit Gefälle): keine Höhenlinie.
|
||||
pub z_varies: bool,
|
||||
pub pts: Vec<[f64; 2]>,
|
||||
/// Polylinie mit Bögen: Stützpunkte + DXF-Bulge je Stützpunkt.
|
||||
pub bulge: Option<(Vec<[f64; 2]>, Vec<f64>)>,
|
||||
@@ -180,7 +184,7 @@ pub fn decode_drawing(geom: &[f64], strings: &[String], id_prefix: &str, now: f6
|
||||
let layer = r.str()?;
|
||||
let flags = jsnum::to_int32(r.num()?);
|
||||
let z = r.num()?;
|
||||
let mut c = Contour { layer, z, closed: flags & 1 != 0, filled: flags & 2 != 0, curve: None, pts: Vec::new(), bulge: None };
|
||||
let mut c = Contour { layer, z, closed: flags & 1 != 0, filled: flags & 2 != 0, curve: None, z_varies: flags & 16 != 0, pts: Vec::new(), bulge: None };
|
||||
if flags & 4 != 0 {
|
||||
let circle = r.num()? == 1.0;
|
||||
let v = r.take(5)?;
|
||||
@@ -391,7 +395,7 @@ pub fn pdf_to_import(page: &PdfPage, scale: f64, with_texts: bool) -> DrawingImp
|
||||
if !out.layer_line_weights.get(&layer).is_some_and(|v| !v.is_null()) {
|
||||
out.layer_line_weights.insert(layer.clone(), json!(0.05));
|
||||
}
|
||||
out.contours.push(Contour { layer, z: 0.0, closed: true, filled: true, curve: None, pts: to_m(&p.pts), bulge: None });
|
||||
out.contours.push(Contour { layer, z: 0.0, closed: true, filled: true, curve: None, z_varies: false, pts: to_m(&p.pts), bulge: None });
|
||||
n_fill += 1.0;
|
||||
}
|
||||
}
|
||||
@@ -403,7 +407,7 @@ pub fn pdf_to_import(page: &PdfPage, scale: f64, with_texts: bool) -> DrawingImp
|
||||
out.layer_dashes.push((layer.clone(), pdf_dash_mm(&p.dash)));
|
||||
}
|
||||
let curve = p.curve.as_ref().map(|c| Curve { circle: c.circle, cx: c.cx * k, cy: c.cy * k, r: c.r * k, a0: c.a0, a1: c.a1 });
|
||||
out.contours.push(Contour { layer, z: 0.0, closed: p.closed, filled: false, curve, pts: to_m(&p.pts), bulge: None });
|
||||
out.contours.push(Contour { layer, z: 0.0, closed: p.closed, filled: false, curve, z_varies: false, pts: to_m(&p.pts), bulge: None });
|
||||
n_stroke += 1.0;
|
||||
}
|
||||
}
|
||||
@@ -571,6 +575,14 @@ pub fn summary_json(d: &DrawingImport) -> Value {
|
||||
m.insert("layout".into(), l.clone().into());
|
||||
}
|
||||
m.insert("recovered".into(), d.recovered.into());
|
||||
// [143] Erkannte Gelände-Höhenlinien (Dialog: Option „Höhenlinien als Gelände übernehmen").
|
||||
let det = crate::import_terrain::detect(d);
|
||||
if !det.lines.is_empty() {
|
||||
m.insert("terrainContours".into(), det.lines.len().into());
|
||||
if det.from_texts > 0 {
|
||||
m.insert("terrainFromTexts".into(), det.from_texts.into());
|
||||
}
|
||||
}
|
||||
Value::Object(m)
|
||||
}
|
||||
|
||||
@@ -684,6 +696,13 @@ pub struct Decision {
|
||||
pub parent_name: String,
|
||||
#[serde(default)]
|
||||
pub dash_style_template: String,
|
||||
/// [143] Erkannte Höhenlinien (`import_terrain::detect`) als Gelände-Höhenlinien (`contourSet`) statt als
|
||||
/// 2D-Zeichnung übernehmen.
|
||||
#[serde(default)]
|
||||
pub terrain_contours: bool,
|
||||
/// [143] Name des Höhenlinien-Satzes (übersetzt von der Hülle); leer = „Höhenlinien".
|
||||
#[serde(default)]
|
||||
pub terrain_name: String,
|
||||
}
|
||||
|
||||
/// Ergebnis von [`import_ops`].
|
||||
@@ -693,6 +712,8 @@ pub struct ImportResult {
|
||||
pub level_id: String,
|
||||
pub drawings: usize,
|
||||
pub meshes: usize,
|
||||
/// [143] Höhenlinien, die als Gelände (`contourSet`) übernommen wurden.
|
||||
pub terrain_contours: usize,
|
||||
}
|
||||
|
||||
fn layer_list(root: &Map<String, Value>) -> Vec<Value> {
|
||||
@@ -885,8 +906,15 @@ pub fn import_ops(root: &Map<String, Value>, d: &DrawingImport, dec: &Decision,
|
||||
(Some(c), Some(b)) => (c[0] - (b[0] + b[2]) / 2.0, c[1] - (b[1] + b[3]) / 2.0),
|
||||
_ => (0.0, 0.0),
|
||||
};
|
||||
// [143] Höhenlinien nicht als Zeichnung, sondern als Gelände-Höhenlinien.
|
||||
let det = if dec.terrain_contours { crate::import_terrain::detect(d) } else { Default::default() };
|
||||
let terrain_idx: HashSet<usize> = det.lines.iter().map(|(i, _)| *i).collect();
|
||||
let terrain_text: HashSet<usize> = det.used_texts.iter().copied().collect();
|
||||
let mut drawings = Vec::with_capacity(d.contours.len() + d.texts.len());
|
||||
for c in &d.contours {
|
||||
for (ci, c) in d.contours.iter().enumerate() {
|
||||
if terrain_idx.contains(&ci) {
|
||||
continue;
|
||||
}
|
||||
let Some(geom) = contour_geom(c, dx, dy) else { continue };
|
||||
let is_polyline = geom.get("shape").and_then(Value::as_str) == Some("polyline");
|
||||
let mut o = Map::new();
|
||||
@@ -906,7 +934,10 @@ pub fn import_ops(root: &Map<String, Value>, d: &DrawingImport, dec: &Decision,
|
||||
}
|
||||
drawings.push(Value::Object(o));
|
||||
}
|
||||
for t in &d.texts {
|
||||
for (ti, t) in d.texts.iter().enumerate() {
|
||||
if terrain_text.contains(&ti) {
|
||||
continue;
|
||||
}
|
||||
drawings.push(json!({
|
||||
"id": format!("dxf2d-{stamp}-{}", next_seq()),
|
||||
"type": "drawing2d",
|
||||
@@ -919,6 +950,38 @@ pub fn import_ops(root: &Map<String, Value>, d: &DrawingImport, dec: &Decision,
|
||||
if !drawings.is_empty() {
|
||||
ops.push(Op::Add { collection: "drawings2d".into(), items: drawings, at: None });
|
||||
}
|
||||
if !det.lines.is_empty() {
|
||||
let contours: Vec<Value> = det
|
||||
.lines
|
||||
.iter()
|
||||
.map(|&(i, z)| {
|
||||
let c = &d.contours[i];
|
||||
let mut o = Map::new();
|
||||
o.insert("z".into(), js_num(z));
|
||||
o.insert("pts".into(), c.pts.iter().map(|&p| pt(p, dx, dy)).collect::<Vec<_>>().into());
|
||||
o.insert("closed".into(), c.closed.into());
|
||||
if c.layer != "0" && !c.layer.is_empty() {
|
||||
o.insert("layer".into(), c.layer.clone().into());
|
||||
}
|
||||
Value::Object(o)
|
||||
})
|
||||
.collect();
|
||||
let name = if dec.terrain_name.trim().is_empty() { "Höhenlinien" } else { dec.terrain_name.trim() };
|
||||
ops.push(Op::Add {
|
||||
collection: "context".into(),
|
||||
items: vec![json!({
|
||||
"id": format!("dxf-contours-{stamp}-{}", next_seq()),
|
||||
"type": "contourSet",
|
||||
"name": name,
|
||||
"categoryCode": TERRAIN_CATEGORY,
|
||||
"contours": contours,
|
||||
})],
|
||||
at: None,
|
||||
});
|
||||
if crate::import_context::ensure_context_categories(&mut layers, [TERRAIN_CATEGORY]) {
|
||||
layers_changed = true;
|
||||
}
|
||||
}
|
||||
let mut n_meshes = 0;
|
||||
if dec.import_meshes && !d.meshes.is_empty() {
|
||||
let meshes = mesh_values(d);
|
||||
@@ -931,7 +994,7 @@ pub fn import_ops(root: &Map<String, Value>, d: &DrawingImport, dec: &Decision,
|
||||
if layers_changed {
|
||||
ops.push(Op::SetField { key: "layers".into(), value: Some(Value::Array(layers)), at: None });
|
||||
}
|
||||
ImportResult { ops, level_id, drawings: n_drawings, meshes: n_meshes }
|
||||
ImportResult { ops, level_id, drawings: n_drawings, meshes: n_meshes, terrain_contours: det.lines.len() }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -259,3 +259,112 @@ fn zeitmessung_kataster() {
|
||||
doc.commit(r.ops, None, 0.0, false).unwrap();
|
||||
eprintln!("commit {:?}", t.elapsed());
|
||||
}
|
||||
|
||||
// ── [143] Höhenlinien als Gelände ────────────────────────────────────────────
|
||||
|
||||
fn line(layer: &str, z: f64, pts: &[[f64; 2]]) -> Contour {
|
||||
Contour { layer: layer.into(), z, closed: false, filled: false, curve: None, z_varies: false, pts: pts.to_vec(), bulge: None }
|
||||
}
|
||||
|
||||
fn text(layer: &str, s: &str, x: f64, y: f64) -> Text {
|
||||
Text { layer: layer.into(), text: s.into(), x, y, height: 0.5, angle: 0.0 }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hoehenlinien_layername_und_erhebung() {
|
||||
use crate::import_terrain::{detect, is_contour_layer_name};
|
||||
for n in ["Höhenlinien", "HL", "A-CONTOUR_5m", "Kote", "hoehenlinie_neu", "ISO-Linien"] {
|
||||
assert!(is_contour_layer_name(n), "{n}");
|
||||
}
|
||||
for n in ["Wände", "0", "Strassen", "Hilfslinien", "Text"] {
|
||||
assert!(!is_contour_layer_name(n), "{n}");
|
||||
}
|
||||
let d = DrawingImport {
|
||||
contours: vec![
|
||||
line("Höhenlinien", 432.0, &[[0.0, 0.0], [5.0, 1.0], [9.0, 0.0]]),
|
||||
line("Höhenlinien", 433.0, &[[0.0, 3.0], [9.0, 3.0]]),
|
||||
line("Wände", 0.0, &[[0.0, 0.0], [1.0, 0.0]]),
|
||||
],
|
||||
..Default::default()
|
||||
};
|
||||
let det = detect(&d);
|
||||
assert_eq!(det.lines, vec![(0, 432.0), (1, 433.0)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hoehenlinien_ohne_hinweis_nur_bei_eindeutigem_muster() {
|
||||
use crate::import_terrain::detect;
|
||||
let mk = |zs: &[f64]| DrawingImport {
|
||||
contours: zs.iter().enumerate().map(|(i, &z)| line("Linien", z, &[[0.0, i as f64], [4.0, i as f64]])).collect(),
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(detect(&mk(&[430.0, 431.0, 432.0])).lines.len(), 3);
|
||||
assert!(detect(&mk(&[430.0, 431.0])).lines.is_empty(), "zu wenige Linien");
|
||||
assert!(detect(&mk(&[3.0, 3.0, 3.0])).lines.is_empty(), "eine Höhe = Geschossdecke o. Ä.");
|
||||
assert!(detect(&mk(&[0.0, 0.0, 0.0])).lines.is_empty(), "ohne Höhe");
|
||||
// 3D-Polylinie mit Gefälle ist keine Höhenlinie.
|
||||
let mut d = mk(&[430.0, 431.0, 432.0, 433.0]);
|
||||
d.contours[1].z_varies = true;
|
||||
assert_eq!(detect(&d).lines.len(), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hoehenlinien_aus_hoehentexten() {
|
||||
use crate::import_terrain::{detect, parse_height};
|
||||
assert_eq!(parse_height("432.50"), Some(432.5));
|
||||
assert_eq!(parse_height(" +432,5 m "), Some(432.5));
|
||||
assert_eq!(parse_height("-1.2"), Some(-1.2));
|
||||
assert_eq!(parse_height("EG 432"), None);
|
||||
assert_eq!(parse_height(""), None);
|
||||
let d = DrawingImport {
|
||||
contours: vec![
|
||||
line("Höhenlinien", 0.0, &[[0.0, 0.0], [10.0, 0.0]]),
|
||||
line("Höhenlinien", 0.0, &[[0.0, 5.0], [10.0, 5.0]]),
|
||||
line("Höhenlinien", 0.0, &[[0.0, 50.0], [10.0, 50.0]]), // ohne Text
|
||||
],
|
||||
texts: vec![text("Beschriftung", "432.5", 5.0, 0.2), text("Beschriftung", "433,0", 5.0, 4.9), text("Beschriftung", "Haus", 5.0, 0.1), text("Beschriftung", "99", 80.0, 80.0)],
|
||||
..Default::default()
|
||||
};
|
||||
let det = detect(&d);
|
||||
assert_eq!(det.lines, vec![(0, 432.5), (1, 433.0)]);
|
||||
assert_eq!(det.used_texts, vec![0, 1]);
|
||||
assert_eq!(det.from_texts, 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn import_hoehenlinien_als_contour_set() {
|
||||
let d = DrawingImport {
|
||||
contours: vec![
|
||||
line("Höhenlinien", 432.0, &[[0.0, 0.0], [5.0, 1.0], [9.0, 0.0]]),
|
||||
line("Höhenlinien", 433.0, &[[0.0, 3.0], [9.0, 3.0]]),
|
||||
line("Wände", 0.0, &[[0.0, 0.0], [1.0, 0.0]]),
|
||||
],
|
||||
texts: vec![text("Wände", "Haus", 1.0, 1.0)],
|
||||
..Default::default()
|
||||
};
|
||||
let dec = |on: bool| decision(json!({"target": {"kind": "new", "name": "HL"}, "categoryMode": "active", "activeCategoryCode": "20", "terrainContours": on, "terrainName": "Höhenlinien (Import)"}));
|
||||
let r = import_ops(&project(), &d, &dec(true), 1000.0);
|
||||
assert_eq!(r.terrain_contours, 2);
|
||||
assert_eq!(r.drawings, 2, "Wand-Linie und Text bleiben Zeichnung");
|
||||
let set = r
|
||||
.ops
|
||||
.iter()
|
||||
.find_map(|o| match o {
|
||||
Op::Add { collection, items, .. } if collection == "context" => Some(items[0].clone()),
|
||||
_ => None,
|
||||
})
|
||||
.expect("contourSet");
|
||||
assert_eq!(set["type"], json!("contourSet"));
|
||||
assert_eq!(set["name"], json!("Höhenlinien (Import)"));
|
||||
assert_eq!(set["contours"].as_array().unwrap().len(), 2);
|
||||
assert_eq!(set["contours"][0]["z"], json!(432));
|
||||
assert_eq!(set["contours"][0]["layer"], json!("Höhenlinien"));
|
||||
assert_eq!(set["contours"][1]["pts"].as_array().unwrap().len(), 2);
|
||||
// Kategorie 02 Gelände wird angelegt.
|
||||
assert!(r.ops.iter().any(|o| matches!(o, Op::SetField { key, .. } if key == "layers")));
|
||||
// Ohne die Option bleibt alles Zeichnung.
|
||||
let r = import_ops(&project(), &d, &dec(false), 1000.0);
|
||||
assert_eq!((r.terrain_contours, r.drawings), (0, 4));
|
||||
assert!(!r.ops.iter().any(|o| matches!(o, Op::Add { collection, .. } if collection == "context")));
|
||||
assert_eq!(summary_json(&d)["terrainContours"], json!(2));
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
//! [143] Höhenlinien im DXF/DWG-Import erkennen: Aus den gelesenen Konturen werden Gelände-Höhenlinien
|
||||
//! (`contourSet` der Kontext-Schicht, Grundlage für „Gelände erzeugen" und „Baugrube erstellen") statt einer
|
||||
//! 2D-Zeichnung.
|
||||
//!
|
||||
//! Erkannt wird in drei Stufen (reine Funktionen auf [`DrawingImport`], keine Ops):
|
||||
//! 1. **Layer-Name** als Hinweis (`Höhenlinie`, `HL`, `Contour`, `Kote` …): Konturen mit Höhe ≠ 0 zählen dazu.
|
||||
//! 2. **Layer ohne Hinweis**, aber mit eindeutigem Muster: mindestens drei offene/geschlossene Linienzüge,
|
||||
//! alle mit konstanter Höhe ≠ 0 und mindestens zwei verschiedenen Höhen.
|
||||
//! 3. **Höhentexte** als Ersatz, wenn die Höhe fehlt (Hinweis-Layer, Höhe 0): eine Zahl als Text nahe der Linie
|
||||
//! („432.50", „432,5 m") gibt der Linie ihre Höhe; der Text wird dann nicht mehr als Zeichnung übernommen.
|
||||
//!
|
||||
//! Nie Höhenlinien sind Kreise/Bögen, Schraffuren und 3D-Polylinien mit wechselnder Höhe (`z_varies`).
|
||||
|
||||
use crate::import_drawing::{Contour, DrawingImport};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
/// Ergebnis der Erkennung: Index der Kontur in `DrawingImport::contours` und ihre Höhe, dazu die Texte,
|
||||
/// die als Höhe verbraucht wurden.
|
||||
#[derive(Debug, Default, Clone, PartialEq)]
|
||||
pub struct TerrainDetection {
|
||||
pub lines: Vec<(usize, f64)>,
|
||||
/// Indizes in `DrawingImport::texts`, die als Höhenangabe gedient haben.
|
||||
pub used_texts: Vec<usize>,
|
||||
/// Davon Linien, deren Höhe aus einem Text stammt.
|
||||
pub from_texts: usize,
|
||||
}
|
||||
|
||||
/// Höhenwerte ausserhalb dieser Spanne (m) sind keine Höhenangaben.
|
||||
const MIN_Z: f64 = -500.0;
|
||||
const MAX_Z: f64 = 9000.0;
|
||||
|
||||
/// Hinweis aus dem Layer-Namen: ganze Wörter (`HL`, `Kote`, `Iso`) oder Wortteile (`Höhenlinien_5m`, `Contours`).
|
||||
pub fn is_contour_layer_name(name: &str) -> bool {
|
||||
let low = name.to_lowercase().replace('ö', "oe").replace('ü', "ue").replace('ä', "ae").replace('ß', "ss");
|
||||
const PARTS: [&str; 9] = ["hoehenlinie", "hoehenkurve", "hoehenkote", "contour", "isohypse", "isolinie", "hoehenschicht", "niveaulinie", "elevation"];
|
||||
if PARTS.iter().any(|p| low.contains(p)) {
|
||||
return true;
|
||||
}
|
||||
const WORDS: [&str; 8] = ["hl", "kote", "koten", "iso", "kurve", "kurven", "gelaendelinie", "terrain"];
|
||||
low.split(|c: char| !c.is_alphanumeric()).any(|w| WORDS.contains(&w))
|
||||
}
|
||||
|
||||
fn is_candidate(c: &Contour) -> bool {
|
||||
c.curve.is_none() && !c.filled && !c.z_varies && c.pts.len() >= 2 && c.z.is_finite() && c.z > MIN_Z && c.z < MAX_Z
|
||||
}
|
||||
|
||||
/// Zahl in einem Text („432.50", „+432,5", „432.5 m", „432.5 m ü. M.") oder `None`.
|
||||
pub fn parse_height(text: &str) -> Option<f64> {
|
||||
let t = text.trim();
|
||||
let t = t.strip_suffix("m ü. M.").or_else(|| t.strip_suffix("m ü.M.")).or_else(|| t.strip_suffix("müM")).or_else(|| t.strip_suffix("m.ü.M.")).unwrap_or(t);
|
||||
let t = t.trim().strip_suffix('m').unwrap_or(t).trim();
|
||||
let t = t.strip_prefix('+').unwrap_or(t);
|
||||
if t.is_empty() || !t.chars().all(|c| c.is_ascii_digit() || matches!(c, '.' | ',' | '-')) || !t.chars().any(|c| c.is_ascii_digit()) {
|
||||
return None;
|
||||
}
|
||||
let v: f64 = t.replace(',', ".").parse().ok()?;
|
||||
(v.is_finite() && v > MIN_Z && v < MAX_Z).then_some(v)
|
||||
}
|
||||
|
||||
fn dist_point_seg(p: [f64; 2], a: [f64; 2], b: [f64; 2]) -> f64 {
|
||||
let (dx, dy) = (b[0] - a[0], b[1] - a[1]);
|
||||
let l2 = dx * dx + dy * dy;
|
||||
let t = if l2 > 0.0 { (((p[0] - a[0]) * dx + (p[1] - a[1]) * dy) / l2).clamp(0.0, 1.0) } else { 0.0 };
|
||||
(p[0] - (a[0] + t * dx)).hypot(p[1] - (a[1] + t * dy))
|
||||
}
|
||||
|
||||
fn dist_to_line(p: [f64; 2], c: &Contour) -> f64 {
|
||||
let mut best = f64::INFINITY;
|
||||
for w in c.pts.windows(2) {
|
||||
best = best.min(dist_point_seg(p, w[0], w[1]));
|
||||
}
|
||||
if c.closed && c.pts.len() > 2 {
|
||||
best = best.min(dist_point_seg(p, c.pts[c.pts.len() - 1], c.pts[0]));
|
||||
}
|
||||
best
|
||||
}
|
||||
|
||||
/// Erkennt die Höhenlinien des Imports (s. Moduldoku). Leer, wenn nichts Eindeutiges gefunden wird.
|
||||
pub fn detect(d: &DrawingImport) -> TerrainDetection {
|
||||
let mut out = TerrainDetection::default();
|
||||
// Kandidaten je Layer.
|
||||
let mut by_layer: HashMap<&str, Vec<usize>> = HashMap::new();
|
||||
for (i, c) in d.contours.iter().enumerate() {
|
||||
if is_candidate(c) {
|
||||
by_layer.entry(c.layer.as_str()).or_default().push(i);
|
||||
}
|
||||
}
|
||||
let mut direct: HashSet<usize> = HashSet::new();
|
||||
let mut need_text: Vec<usize> = Vec::new();
|
||||
for (layer, idx) in &by_layer {
|
||||
if is_contour_layer_name(layer) {
|
||||
for &i in idx {
|
||||
if d.contours[i].z != 0.0 {
|
||||
direct.insert(i);
|
||||
} else {
|
||||
need_text.push(i);
|
||||
}
|
||||
}
|
||||
} else if idx.len() >= 3 && idx.iter().all(|&i| d.contours[i].z != 0.0) {
|
||||
let mut zs: Vec<i64> = idx.iter().map(|&i| (d.contours[i].z * 100.0).round() as i64).collect();
|
||||
zs.sort_unstable();
|
||||
zs.dedup();
|
||||
if zs.len() >= 2 {
|
||||
direct.extend(idx.iter().copied());
|
||||
}
|
||||
}
|
||||
}
|
||||
// Stufe 3: Höhentexte für Linien ohne Höhe.
|
||||
let mut from_text: HashMap<usize, (f64, f64, usize)> = HashMap::new(); // Linie → (Abstand, Höhe, Text)
|
||||
if !need_text.is_empty() {
|
||||
for (ti, t) in d.texts.iter().enumerate() {
|
||||
let Some(z) = parse_height(&t.text) else { continue };
|
||||
if !(t.x.is_finite() && t.y.is_finite()) {
|
||||
continue;
|
||||
}
|
||||
let tol = (2.5 * t.height.max(0.0)).max(0.25);
|
||||
let mut best: Option<(usize, f64)> = None;
|
||||
for &ci in &need_text {
|
||||
let dist = dist_to_line([t.x, t.y], &d.contours[ci]);
|
||||
if dist <= tol && best.map_or(true, |(_, bd)| dist < bd) {
|
||||
best = Some((ci, dist));
|
||||
}
|
||||
}
|
||||
if let Some((ci, dist)) = best {
|
||||
let e = from_text.entry(ci).or_insert((f64::INFINITY, z, ti));
|
||||
if dist < e.0 {
|
||||
*e = (dist, z, ti);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut used: HashSet<usize> = HashSet::new();
|
||||
let mut lines: Vec<(usize, f64)> = direct.into_iter().map(|i| (i, d.contours[i].z)).collect();
|
||||
for (ci, (_, z, ti)) in &from_text {
|
||||
lines.push((*ci, *z));
|
||||
used.insert(*ti);
|
||||
}
|
||||
lines.sort_by_key(|(i, _)| *i);
|
||||
out.from_texts = from_text.len();
|
||||
out.lines = lines;
|
||||
let mut ut: Vec<usize> = used.into_iter().collect();
|
||||
ut.sort_unstable();
|
||||
out.used_texts = ut;
|
||||
out
|
||||
}
|
||||
@@ -111,6 +111,7 @@ pub mod cmd_draw;
|
||||
pub mod cmd_solid;
|
||||
pub mod polyline_vertex;
|
||||
pub mod import_drawing;
|
||||
pub mod import_terrain;
|
||||
pub mod import_context;
|
||||
pub mod import_ifc;
|
||||
pub mod cmd_paste;
|
||||
|
||||
@@ -76,7 +76,7 @@ pub fn import_drawing_meshes(geom: &[f64], strings_json: &str, source_json: &str
|
||||
}
|
||||
|
||||
/// Bestätigten Zeichnungs-Import (DXF/DWG/PDF) als EINEN Undo-Schritt ins Dokument `h` übernehmen.
|
||||
/// `decision_json` s. [`Decision`]. Antwort: `{"ops":[…],"levelId":"…","drawings":n,"meshes":n}`.
|
||||
/// `decision_json` s. [`Decision`]. Antwort: `{"ops":[…],"levelId":"…","drawings":n,"meshes":n,"terrainContours":n}`.
|
||||
#[wasm_bindgen]
|
||||
pub fn doc_import_drawing(h: u32, geom: &[f64], strings_json: &str, source_json: &str, decision_json: &str, key: &str, now_ms: f64) -> String {
|
||||
let now = now_of(now_ms);
|
||||
@@ -90,7 +90,7 @@ pub fn doc_import_drawing(h: u32, geom: &[f64], strings_json: &str, source_json:
|
||||
};
|
||||
with_doc(h, |doc| {
|
||||
let r = imp::import_ops(doc.root(), &d, &dec, now);
|
||||
let extra = [("levelId", Value::from(r.level_id)), ("drawings", r.drawings.into()), ("meshes", r.meshes.into())];
|
||||
let extra = [("levelId", Value::from(r.level_id)), ("drawings", r.drawings.into()), ("meshes", r.meshes.into()), ("terrainContours", r.terrain_contours.into())];
|
||||
commit(doc, r.ops, &extra, key, now)
|
||||
})
|
||||
.unwrap_or_else(|| err("Dokument nicht offen"))
|
||||
|
||||
@@ -80,6 +80,9 @@ pub struct Contour {
|
||||
pub closed: bool,
|
||||
pub filled: bool,
|
||||
pub curve: Option<Curve>,
|
||||
/// [143] Die Höhen der Stützpunkte sind nicht einheitlich (3D-Polylinie mit Gefälle): `z` ist dann nur der
|
||||
/// erste Wert und die Kontur keine Höhenlinie.
|
||||
pub z_varies: bool,
|
||||
/// Polylinie mit Bögen (LWPOLYLINE/POLYLINE, Schraffur-Rand aus einer Polylinie): die Stützpunkte
|
||||
/// `[x, y, bulge]` (abgebildet, in Metern), damit die 2D-Zeichnung echte Bogen-Segmente bekommt
|
||||
/// statt des fein zerlegten Linienzugs (`pts` bleibt tesselliert für Kontext und Fang). Nur wenn
|
||||
@@ -535,6 +538,15 @@ fn finite2(p: &Vector3) -> bool {
|
||||
p.x.is_finite() && p.y.is_finite()
|
||||
}
|
||||
|
||||
/// [143] Wechselt die Höhe der Stützpunkte (mehr als 1 mm)?
|
||||
fn z_varies(verts: &[(Vector3, f64)]) -> bool {
|
||||
let mut zs = verts.iter().filter(|(v, _)| finite2(v)).map(|(v, _)| fz(v.z));
|
||||
match zs.next() {
|
||||
Some(first) => zs.any(|z| (z - first).abs() > 1e-3),
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn fz(z: f64) -> f64 {
|
||||
if z.is_finite() {
|
||||
z
|
||||
@@ -589,10 +601,20 @@ impl<'a> Mapper<'a> {
|
||||
closed,
|
||||
filled: false,
|
||||
curve: None,
|
||||
z_varies: false,
|
||||
bulge_verts: None,
|
||||
});
|
||||
}
|
||||
|
||||
/// [143] Kennzeichnet die zuletzt angelegte Kontur als „Höhe wechselt".
|
||||
fn mark_z_varies(&mut self, varies: bool) {
|
||||
if varies {
|
||||
if let Some(c) = self.contours.last_mut() {
|
||||
c.z_varies = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Polylinie mit Bulges: tesselliert wie bisher, dazu (wenn sinnvoll) die Stützpunkte mit Bulge
|
||||
/// ([`Contour::bulge_verts`]).
|
||||
fn push_bulged(&mut self, layer: &str, z: f64, verts: &[(Vector3, f64)], closed: bool, xf: &Xf) {
|
||||
@@ -650,7 +672,9 @@ impl<'a> Mapper<'a> {
|
||||
p.vertices.iter().filter(|v| v.flags & 16 == 0).map(|v| (v.position, 0.0)).collect();
|
||||
let z = verts.iter().find(|(v, _)| finite2(v)).map(|(v, _)| fz(v.z)).unwrap_or(fz(p.elevation));
|
||||
let pts = bulge_points(&verts, false);
|
||||
let varies = z_varies(&verts);
|
||||
self.push_contour(layer, z, pts, p.flags.closed, xf);
|
||||
self.mark_z_varies(varies);
|
||||
}
|
||||
EntityType::Polyline(p) => {
|
||||
let verts: Vec<(Vector3, f64)> = p
|
||||
@@ -661,7 +685,9 @@ impl<'a> Mapper<'a> {
|
||||
.collect();
|
||||
let z = verts.iter().find(|(v, _)| finite2(v)).map(|(v, _)| fz(v.z)).unwrap_or(0.0);
|
||||
let pts = bulge_points(&verts, false);
|
||||
let varies = z_varies(&verts);
|
||||
self.push_contour(layer, z, pts, p.flags.is_closed(), xf);
|
||||
self.mark_z_varies(varies);
|
||||
}
|
||||
EntityType::Arc(a) => self.arc(a.center, a.radius, a.start_angle, a.end_angle, layer, xf),
|
||||
EntityType::Circle(c) => self.circle(c.center, c.radius, layer, xf),
|
||||
@@ -1916,7 +1942,8 @@ pub fn encode(data: &ImportData) -> (Vec<f64>, Vec<String>) {
|
||||
let flags = u8::from(c.closed)
|
||||
| (u8::from(c.filled) << 1)
|
||||
| (u8::from(c.curve.is_some()) << 2)
|
||||
| (u8::from(c.bulge_verts.is_some()) << 3);
|
||||
| (u8::from(c.bulge_verts.is_some()) << 3)
|
||||
| (u8::from(c.z_varies) << 4);
|
||||
g.push(f64::from(flags));
|
||||
g.push(c.z);
|
||||
if let Some(cv) = c.curve {
|
||||
|
||||
@@ -1021,3 +1021,36 @@ fn kodierung_bulge_stuetzpunkte() {
|
||||
assert_eq!(g[j], 4.0);
|
||||
assert_eq!(&g[j + 1..j + 4], &[2_600_000.0, 1_200_000.0, 0.12]);
|
||||
}
|
||||
|
||||
// ── [143] Höhenlinien: Erhebung und konstantes Z ─────────────────────────────
|
||||
|
||||
#[test]
|
||||
fn lwpolyline_erhebung_gruppe_38() {
|
||||
let d = import_bytes(&dxf(
|
||||
&[],
|
||||
&[&["0", "LWPOLYLINE", "8", "Hoehenlinie", "90", "3", "70", "0", "38", "432.5", "10", "0", "20", "0", "10", "5", "20", "1", "10", "9", "20", "0"]],
|
||||
))
|
||||
.unwrap();
|
||||
let c = only_contour(&d);
|
||||
assert_eq!(c.z, 432.5);
|
||||
assert!(!c.z_varies);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn polyline3d_konstantes_und_wechselndes_z() {
|
||||
fn pl<'a>(zs: [&'a str; 3]) -> Vec<&'a str> {
|
||||
let mut v = vec!["0", "POLYLINE", "8", "HL", "70", "8"];
|
||||
for (i, z) in zs.iter().enumerate() {
|
||||
let x = ["0", "5", "9"][i];
|
||||
v.extend(["0", "VERTEX", "8", "HL", "70", "32", "10", x, "20", "1", "30", z]);
|
||||
}
|
||||
v.extend(["0", "SEQEND"]);
|
||||
v
|
||||
}
|
||||
let d = import_bytes(&dxf(&[], &[&pl(["430", "430", "430"])])).unwrap();
|
||||
let c = only_contour(&d);
|
||||
assert_eq!(c.z, 430.0);
|
||||
assert!(!c.z_varies);
|
||||
let d = import_bytes(&dxf(&[], &[&pl(["430", "431", "432"])])).unwrap();
|
||||
assert!(only_contour(&d).z_varies);
|
||||
}
|
||||
@@ -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