[K3d] DXF-/DWG-Sammler im Kern: plan_dxf.rs liest Plan-Puffer und Projekt-Dokument

Ebenen, Linientypen, Textstile, Bemassungen (DIMSTYLE/DIMENSION), Türen/Fenster und Blockinstanzen
(BLOCK/INSERT/ATTRIB), Schraffuren (HATCH, Verlauf, Zufallsstriche), Papierbereich: die flache
Zeichnung entsteht im Kern und geht über TS an fileio (Schreibung unverändert dort). TS behält das
Text-Layout (Zeilen der Raumstempel, Absätze/Wörter der Einzeltexte, Schriftfamilie) und schickt es
flach mit; der Spaltenumbruch läuft im Kern (blocklokale Grösse). FlatDrawing-Klasse, Sammler und
dxfCadParts (ausser fontNameOf) in TS gelöscht, Tests nach Rust.

Gleichheit (temporärer Test gegen die alte TS-Fassung): flache Zeichnung Zahl für Zahl und
Zeichenketten gleich über 451 Fälle (Beispiel + Fachplaner-Projekt, 3 Geschosse × 3 Detailgrade ×
mono × 3 Optionssätze, 300 Zufallspläne mit allen Primitiv-/Schraffur-Arten, Zusatz-Primitive,
bigSample(8)); DXF/Binär byte-gleich; CLI dxf/dwg (--binary, --scale, --dim-unit cm, --layout)
36 Dateien byte-gleich zur CLI des Hauptstands.

Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
Claude committed 2026-10-29 01:49:28 +00:00
1 parent 70bb23f2bc
commit 9a3d07158b
9 files changed
+1609 -1072

No files matched your search

+1
View File
@@ -63,6 +63,7 @@ pub mod plan_scene;
pub mod plan_pick;
pub mod snap;
pub mod plan_svg;
pub mod plan_dxf;
#[cfg(feature = "web")]
mod web;
File diff suppressed because it is too large. Load diff
+1 -1
View File
@@ -11,7 +11,7 @@ thread_local! {
static DOCS: RefCell<Vec<Option<Document>>> = const { RefCell::new(Vec::new()) };
}
fn with_doc<R>(h: u32, f: impl FnOnce(&mut Document) -> R) -> Option<R> {
pub(crate) fn with_doc<R>(h: u32, f: impl FnOnce(&mut Document) -> R) -> Option<R> {
DOCS.with(|d| d.borrow_mut().get_mut((h as usize).checked_sub(1)?)?.as_mut().map(f))
}
+1
View File
@@ -36,6 +36,7 @@ mod plan_scene;
mod plan_pick;
mod snap;
mod plan_svg;
mod plan_dxf;
use wasm_bindgen::prelude::wasm_bindgen;
+36
View File
@@ -0,0 +1,36 @@
//! Bindung des DXF-Sammlers (`crate::plan_dxf`) auf gehaltenen Plan-Puffern (Abschnitte wie
//! `plan_parts`) und dem Projekt-Dokument. Leeres Ergebnis = Puffer fehlt (TS legt neu ab und
//! fragt nochmals), Dokument nicht offen/unpassend oder kaputte Eingabe — nie Panic.
use crate::plan_dxf::{collect, encode, texts_from, DxfOptions};
use crate::plan_parts::parts_from;
use wasm_bindgen::prelude::wasm_bindgen;
/// Flache Zeichnung (Format `plan_dxf::encode`). `opts` = `[Massstab, Schraffuren 0/1, cm 0/1,
/// Papierbereich 0/1, minX, minY, maxX, maxY]`; `text_nums`/`text_strs` = Text-Eingabe
/// (`plan_dxf::texts_from`, Texte je mit `\0` davor); `default_font` = Standard-Schrift.
#[wasm_bindgen]
pub fn plan_dxf_flat(doc: u32, segs: &[f64], text_nums: &[f64], text_strs: &str, opts: &[f64], default_font: &str) -> Vec<u8> {
let Ok([scale, hatches, cm, layout, min_x, min_y, max_x, max_y]) = <[f64; 8]>::try_from(opts) else { return Vec::new() };
if !(scale.is_finite() && scale > 0.0) {
return Vec::new();
}
let strs: Vec<&str> = text_strs.split('\0').skip(1).collect();
let Some(texts) = texts_from(text_nums, &strs) else { return Vec::new() };
let Some(held) = super::plan_buf::held_for_segs(segs) else { return Vec::new() };
let Some(mut parts) = parts_from(segs, |nr| held.iter().find(|e| e.0 == nr).map(|e| &*e.1)) else { return Vec::new() };
let o = DxfOptions {
scale,
include_hatches: hatches != 0.0,
dim_cm: cm != 0.0,
paper_layout: layout != 0.0,
bounds: [min_x, min_y, max_x, max_y],
default_font: default_font.to_string(),
};
super::document::with_doc(doc, |d| {
let p = d.project().ok()?;
collect(&mut parts, &texts, p, &o).map(|f| encode(&f))
})
.flatten()
.unwrap_or_default()
}