[K4] S4 Import: Aufrufer auf den Kern umgestellt, TS-Umwandlung gelöscht

DXF/DWG/PDF (Import-Dialog, CLI), IFC (Meshes/Bauteile) und Meshes laufen über ProjectDocument.importDrawing/
importIfc/importMesh (Store commitImport, ein Undo-Schritt). Dialoge halten nur Puffer + Zusammenfassung
(io/importSource.ts). Gelöscht: dxfToDrawings, pdfLineStyles, ifcElements, decodeImport/decodeIfc/decodeMesh,
ifcToImportedMeshes, meshObjectsToImportedMeshes, pdfPageToImport, buildDrawings, planImportLayers, Store
addDrawingLevel/importDrawings, Paritätstests. ensureContextCategories als Fassade über den Kern; CLI-PDF bekommt
wie die App Linienstile für Strichmuster. Tests über importView.testutil (Leseansicht des Kerns).
This commit is contained in:
Claude committed 2026-10-29 14:52:21 +00:00
1 parent 65e7f3a2ea
commit a5c3ea55f2
52 files changed
+880 -3010

No files matched your search

+24 -3
View File
@@ -56,7 +56,8 @@ pub fn ensure_context_categories<'a>(layers: &mut Vec<Value>, codes: impl IntoIt
return false;
}
let nested: Vec<Value> = NESTED.iter().filter(|d| missing.contains(d.code)).map(category).collect();
if !nested.is_empty() {
let added_nested = !nested.is_empty();
if added_nested {
match layers.iter().position(|l| l.get("code").and_then(Value::as_str) == Some(CONTEXT_PARENT.code)) {
Some(i) => {
let mut l = layers[i].as_object().cloned().unwrap_or_default();
@@ -72,10 +73,11 @@ pub fn ensure_context_categories<'a>(layers: &mut Vec<Value>, codes: impl IntoIt
}
}
}
if missing.contains(IMPORTED_ROOF.code) {
let roof = missing.contains(IMPORTED_ROOF.code);
if roof {
layers.push(category(&IMPORTED_ROOF));
}
true
added_nested || roof
}
/// Ops: Kontext-Objekte anhängen (fehlt die Liste, wird sie gesetzt) und fehlende Kontext-Kategorien ergänzen.
@@ -407,6 +409,25 @@ pub fn decode_mesh(f: &[f64], strings: &[String]) -> Result<(Vec<MeshObject>, Va
Ok((objects, report))
}
/// Ausdehnung aller Objekte (Meter, Modell-Achsen; Anzeige im Dialog); `None` ohne Punkte.
pub fn mesh_extent(objects: &[MeshObject]) -> Option<[f64; 3]> {
let mut lo = [f64::INFINITY; 3];
let mut hi = [f64::NEG_INFINITY; 3];
for o in objects {
for p in o.positions.chunks_exact(3) {
for a in 0..3 {
if p[a] < lo[a] {
lo[a] = p[a];
}
if p[a] > hi[a] {
hi[a] = p[a];
}
}
}
}
lo[0].is_finite().then(|| [hi[0] - lo[0], hi[1] - lo[1], hi[2] - lo[2]])
}
/// Verschiebung (x, y, z) je nach Platzierung (`meshShift`): `"center"` = Grundriss-Mitte auf den
/// Nullpunkt, Unterkante auf 0; `"original"` = Datei-Koordinaten, Landeskoordinaten auf den Modell-Nullpunkt.
pub fn mesh_shift(objects: &[MeshObject], placement: &str, origin: Option<[f64; 2]>) -> [f64; 3] {
+63 -1
View File
@@ -1,5 +1,5 @@
use super::*;
use crate::import_context::{ensure_context_categories, mesh_objects_to_meshes, stamp36, MeshObject};
use crate::import_context::{classification_suffix, ensure_context_categories, ifc_meshes, mesh_objects_to_meshes, stamp36, IfcProduct, MeshObject};
/// DXF-Puffer (Version 3) wie `fileio/src/import.rs::encode`: Layer „A" (rot) und „B", eine Linie,
/// eine Polylinie mit Bogen, ein Kreis, eine Schraffur, ein Text, ein Mesh auf „0".
@@ -142,6 +142,62 @@ fn pdf_mit_strichmuster() {
assert_eq!(info["layers"], json!({"PDF 0.18 #ff0000 (Strich 1.05/0.7)": 1, "PDF Fläche #ffffff": 1}));
}
#[test]
fn strichmuster_zu_linienstilen() {
assert!(same_dash(&[1.05, 0.7], &[1.0, 0.7]));
assert!(!same_dash(&[3.0, 1.0], &[1.0, 3.0]));
assert!(!same_dash(&[1.0, 1.0], &[1.0, 1.0, 1.0, 1.0]));
let solid = json!({"id": "thin", "name": "Volllinie", "weight": 0.13, "color": "#111", "dash": null});
let dashed = json!({"id": "d", "name": "Strich", "weight": 0.02, "color": "#111", "dash": [1, 0.7]});
let dashes: Vec<(String, Vec<f64>)> =
vec![("a".into(), vec![1.05, 0.7]), ("b".into(), vec![2.8, 1.4]), ("c".into(), vec![2.8, 1.4]), ("d".into(), vec![0.05, 0.7, 2.8, 0.7])];
let (created, by_layer) = plan_dash_styles(&dashes, &[solid.clone(), dashed], "S {pattern}");
assert_eq!(by_layer["a"], "d");
assert_eq!(created.len(), 2);
assert_eq!(by_layer["b"], by_layer["c"]);
assert_eq!(created[0], json!({"id": "pdf-dash-2_8_1_4", "name": "S 2.8/1.4", "weight": 0.02, "color": "#1a1a1a", "dash": [2.8, 1.4]}));
assert_eq!(created[1]["dash"], json!([0.05, 0.7, 2.8, 0.7]));
// Gleiche id schon vergeben → Zähler.
let taken = json!({"id": "pdf-dash-2_8_1_4", "kind": "dot", "dash": [2.8, 1.4]});
let (created, _) = plan_dash_styles(&dashes[1..2], &[taken], "{pattern}");
assert_eq!(created[0]["id"], json!("pdf-dash-2_8_1_4-2"));
assert!(plan_dash_styles(&[], &[solid], "").0.is_empty());
}
#[test]
fn ifc_meshes_farbe_und_globalid() {
let pos = [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0];
let idx = [0.0, 2.0, 1.0, 0.0, 1.0, 3.0];
let product = |color: Option<Vec<f64>>, gid: &str| IfcProduct {
global_id: gid.into(),
ifc_class: "IfcWall".into(),
name: Some("Wand".into()),
storey: Some("EG".into()),
color,
classifications: vec![],
positions: &pos,
indices: &idx,
};
let m = ifc_meshes(&[product(Some(vec![1.0, 0.5, 0.0, 0.8]), "2O2Fr$t4X7Zf8NOew3FLOH")], "x.ifc", "product", [0.0, 0.0], 0.0);
assert_eq!(m[0]["color"], json!("#ff8000"));
assert_eq!(m[0]["ifcGlobalId"], json!("2O2Fr$t4X7Zf8NOew3FLOH"));
assert_eq!(m[0]["name"], json!("EG: Wand"));
assert_eq!(m[0]["layer"], json!("IfcWall"));
let n = ifc_meshes(&[product(None, "")], "x.ifc", "product", [0.0, 0.0], 0.0);
assert!(n[0].get("color").is_none() && n[0].get("ifcGlobalId").is_none());
// Zusammengelegt: gemeinsame Farbe nur, wenn alle gleich; Indizes versetzt.
let red = || Some(vec![1.0, 0.0, 0.0, 1.0]);
let g = ifc_meshes(&[product(red(), "a"), product(red(), "b")], "x.ifc", "class", [10.0, 0.0], 0.0);
assert_eq!(g[0]["color"], json!("#ff0000"));
assert_eq!(g[0]["name"], json!("x: EG IfcWall (2)"));
assert_eq!(g[0]["indices"].as_array().unwrap()[6], json!(4));
assert_eq!(g[0]["positions"][0], json!(10));
let h = ifc_meshes(&[product(red(), "a"), product(Some(vec![0.0, 0.0, 1.0, 1.0]), "b")], "x.ifc", "class", [0.0, 0.0], 0.0);
assert!(h[0].get("color").is_none());
assert_eq!(classification_suffix(&[]), "");
assert_eq!(classification_suffix(&[json!({"system": "", "code": "214", "name": null})]), " [214]");
}
#[test]
fn kontext_kategorien() {
let mut l = vec![json!({"code": "20"})];
@@ -167,6 +223,12 @@ fn meshes_mitte_und_gruppen() {
assert_eq!(m.len(), 1);
assert_eq!(m[0]["name"], json!("haus: g (2)"));
assert_eq!(m[0]["indices"], json!([0, 1, 0, 2, 3, 2]));
// Viele Objekte („auto"): je Gruppe + Farbe zusammengelegt.
let many: Vec<MeshObject> = (0..2100).map(|i| obj(if i % 2 == 1 { "A" } else { "B" }, 0.0)).collect();
let m = mesh_objects_to_meshes(&many, "x.obj", "original", None, "auto", 0.0);
assert_eq!(m.len(), 2);
assert_eq!(m[0]["indices"].as_array().unwrap().len(), 1050 * 3);
assert_eq!(m[0]["color"], json!("#ff8000"));
}
/// Zeitmessung (nativ, von Hand): `IMPORT_BENCH=<geom-Datei>` mit `<geom>.strings.json` daneben.
+6 -2
View File
@@ -155,11 +155,15 @@ fn strings_of(json: &str) -> Result<Vec<String>, String> {
serde_json::from_str(json).map_err(|e| format!("Import-Texte: {e}"))
}
/// Bericht eines gelesenen Mesh-Imports (Format, Achse, Einheit, Dreiecke, Hinweise) für den Dialog.
/// Bericht eines gelesenen Mesh-Imports (Format, Achse, Einheit, Dreiecke, Hinweise) und Ausdehnung
/// (`[dx, dy, dz]` in Metern, `null` ohne Punkte) für den Dialog: `{"report":{…},"extent":…}`.
#[wasm_bindgen]
pub fn mesh_import_report(flat: &[f64], strings_json: &str) -> String {
match strings_of(strings_json).and_then(|s| crate::import_context::decode_mesh(flat, &s)) {
Ok((_, report)) => report.to_string(),
Ok((objects, report)) => {
let extent = crate::import_context::mesh_extent(&objects).map_or(Value::Null, |e| json!(e));
json!({"report": report, "extent": extent}).to_string()
}
Err(e) => err(e),
}
}
-4
View File
@@ -51,10 +51,6 @@ pub fn layers_call(name: &str, layers_json: &str, arg_json: &str, now_ms: f64) -
"insertAfter" => Value::Array(layers::insert_after(&cats, text(&arg["code"]), &arg["clone"])),
"remove" => Value::Array(layers::remove(&cats, text(&arg))),
"nextFreeCode" => Value::String(layers::next_free_code(&cats, if now_ms.is_finite() { now_ms } else { 0.0 })),
"planImport" => {
let plan = layers::plan_import(&strings(&arg["names"]), &cats, &obj(&arg["colors"]), &obj(&arg["weights"]));
json!({"children": plan.children, "parentCode": plan.parent_code, "codeByLayer": plan.code_by_layer})
}
// Fehlende Kontext-Kategorien ergänzen (`ensureContextCategories`); `null` = nichts fehlt.
"ensureContext" => {
let mut cats = cats;