[14][12] Kaputte Projekte: keine Abfrage wirft mehr, validate warnt vor hängenden Verweisen
Kern fällt bei hängenden Wandtypen/Bauteilen/Schraffuren/Linienstilen/Deckentypen auf Vorgaben zurück (Plan, Schnitt, Ansicht, 3D, IFC, Mesh); typisierte Sicht tolerant (model/lenient.rs: nur der Wert, der nicht passt, fällt auf die Vorgabe); Mesh-Export verwirft gebrochene Indizes/NaN-Ecken; projectWarnings (project_refs.rs) für dossier-cli/MCP validate. Fuzz-Test src/core/robustness.test.ts.
This commit is contained in:
29 files changed
+1323
-271
No files matched your search
@@ -215,18 +215,15 @@ fn pv(p: [f64; 2]) -> Vec2 {
|
||||
Vec2 { x: p[0], y: p[1] }
|
||||
}
|
||||
|
||||
/// `getComponent` (wirft in TS).
|
||||
/// `getComponent`; hängender Verweis (Datei/Import) → neutrales Rückfall-Bauteil statt Abbruch.
|
||||
fn component<'a>(p: &'a Project, id: &str) -> Result<&'a Component, String> {
|
||||
p.component(id).ok_or_else(|| format!("Unbekanntes Bauteil-Material: {id}"))
|
||||
Ok(p.component_or_fallback(id))
|
||||
}
|
||||
|
||||
/// `resolveHatch` mit der Fehlermeldung von TS (`getHatch`/`getLineStyle` werfen).
|
||||
pub(super) fn resolve_hatch_or_err(p: &Project, hatch_id: &str, wall_angle_deg: Option<f64>, fg: Option<&str>) -> Result<HatchRender, String> {
|
||||
let h = p.hatch(hatch_id).ok_or_else(|| format!("Unbekannte Schraffur: {hatch_id}"))?;
|
||||
if let Some(ls) = h.line_style_id.as_deref().filter(|s| !s.is_empty()) {
|
||||
p.line_style(ls).ok_or_else(|| format!("Unbekannter Linienstil: {ls}"))?;
|
||||
}
|
||||
resolve_hatch(p, hatch_id, wall_angle_deg, fg, None).ok_or_else(|| format!("Unbekannte Schraffur: {hatch_id}"))
|
||||
/// `resolveHatch`; hängende Schraffur (Datei/Import) → ohne Muster statt Abbruch (ein hängender
|
||||
/// Linienstil der Schraffur fällt in `resolve_hatch` auf die Vorgabe-Strichstärke zurück).
|
||||
pub(super) fn resolve_hatch_or_none(p: &Project, hatch_id: &str, wall_angle_deg: Option<f64>, fg: Option<&str>) -> HatchRender {
|
||||
resolve_hatch(p, hatch_id, wall_angle_deg, fg, None).unwrap_or_else(no_hatch)
|
||||
}
|
||||
|
||||
/// Footprints der gezeichneten Wände dieses Geschosses (`buildWallFootprints`).
|
||||
@@ -251,7 +248,8 @@ fn ceiling_layers<'a>(p: &'a Project, c: &Ceiling) -> Result<&'a [Layer], String
|
||||
return Ok(&ct.layers);
|
||||
}
|
||||
}
|
||||
p.wall_types.iter().find(|t| t.id == c.wall_type_id).map(|t| t.layers.as_slice()).ok_or_else(|| format!("Unbekannter Deckentyp: {}", c.ceiling_type_id.as_deref().unwrap_or(&c.wall_type_id)))
|
||||
// Hängender Typ (Datei/Import): Rückfall-Schicht statt Abbruch.
|
||||
Ok(p.wall_types.iter().find(|t| t.id == c.wall_type_id).map_or(Project::fallback_layers(), |t| t.layers.as_slice()))
|
||||
}
|
||||
|
||||
/// Typname einer Decke für `object_name` (Maps in TS: letzter Eintrag je id gewinnt).
|
||||
@@ -290,7 +288,7 @@ fn ceilings(c: &Ctx, out: &mut Vec<Primitive>, bounds: &mut Bounds) -> Result<()
|
||||
let stroke = color.unwrap_or(POCHE_STROKE);
|
||||
let view_hatch_id = resolve_hatch_id(ce.hatch_id.as_deref(), ce.hatch_source, category, comp.and_then(|k| k.view_hatch_id.as_deref()));
|
||||
let hatch = match (c.a.detail != Detail::Grob, comp, view_hatch_id.filter(|s| !s.is_empty())) {
|
||||
(true, Some(k), Some(id)) => resolve_hatch_or_err(p, id, None, resolve_foreground(k, ce.foreground.as_deref(), category, ce.foreground_source))?,
|
||||
(true, Some(k), Some(id)) => resolve_hatch_or_none(p, id, None, resolve_foreground(k, ce.foreground.as_deref(), category, ce.foreground_source)),
|
||||
_ => no_hatch(),
|
||||
};
|
||||
let fill = match comp {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
//! Ein Block wird über `scale_geom` (Skalierung, Drehung, Verschiebung) rekursiv ausgegeben.
|
||||
//! Texte bleiben Daten (`drawingText`); das Text-Layout macht der Verbraucher.
|
||||
|
||||
use super::domains::{resolve_hatch_or_err, Bounds, Ctx};
|
||||
use super::domains::{Bounds, Ctx};
|
||||
use super::overrides::Actions;
|
||||
use super::prim::{HatchRender, Primitive};
|
||||
use super::style::*;
|
||||
@@ -585,10 +585,8 @@ fn emit_inner(c: &Ctx, d: &Drawing2D, attrs: Attrs, geom: &Drawing2DGeom, greyed
|
||||
// Gefüllte Fläche einer geschlossenen Form (Vollton-Füllung und/oder Schraffur), vor den Strichen.
|
||||
let fill_poly = |em: &mut Em, pts: Vec<Vec2>| -> Result<(), String> {
|
||||
let hatch = match hatch_id.filter(|s| !s.is_empty()) {
|
||||
Some(h) => {
|
||||
resolve_hatch_or_err(p, h, None, foreground)?;
|
||||
resolve_hatch(p, h, None, foreground, Some((d.hatch_angle_deg, d.hatch_scale, d.hatch_origin))).ok_or_else(|| format!("Unbekannte Schraffur: {h}"))?
|
||||
}
|
||||
// Hängende Schraffur (Datei/Import): Fläche ohne Muster statt Abbruch.
|
||||
Some(h) => resolve_hatch(p, h, None, foreground, Some((d.hatch_angle_deg, d.hatch_scale, d.hatch_origin))).unwrap_or_else(no_hatch),
|
||||
None => no_hatch(),
|
||||
};
|
||||
let pr = polygon(pts, fill_color, "none", 0.0, hatch, em.greyed, Some(em.id));
|
||||
|
||||
@@ -150,7 +150,8 @@ fn collect_roof_faces(p: &Project, frame: &[f64; 9]) -> Result<Vec<Face>, String
|
||||
let fill = match roof.color.as_deref().filter(|c| !c.is_empty()) {
|
||||
Some(c) => hex_to_rgb(c, ROOF_RGB_FALLBACK),
|
||||
None => match outer.filter(|l| !l.component_id.is_empty()) {
|
||||
Some(l) => hex_to_rgb(&p.component(&l.component_id).ok_or_else(|| format!("Unbekanntes Bauteil-Material: {}", l.component_id))?.color, ROOF_RGB_FALLBACK),
|
||||
// Hängendes Bauteil (Datei/Import): Dach-Vorgabefarbe.
|
||||
Some(l) => p.component(&l.component_id).map_or(ROOF_RGB_FALLBACK, |c| hex_to_rgb(&c.color, ROOF_RGB_FALLBACK)),
|
||||
None => ROOF_RGB_FALLBACK,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -496,10 +496,6 @@ fn rect_of_band(c: &Cut) -> Option<[f64; 4]> {
|
||||
(c.pts.len() >= 3).then(|| bbox(&c.pts))
|
||||
}
|
||||
|
||||
fn missing(what: &str, id: &str) -> String {
|
||||
format!("{what}: {id}")
|
||||
}
|
||||
|
||||
/// Bauteil-Stil einer Schicht (Füllung, Schraffur) mit dem Override des Elements (`split*Layers`).
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn layer_style(
|
||||
@@ -515,7 +511,8 @@ fn layer_style(
|
||||
angle: f64,
|
||||
) -> Result<(String, HatchRender), String> {
|
||||
let hid = resolve_hatch_id(hatch_id, hatch_source, category, Some(&comp.hatch_id)).unwrap_or(&comp.hatch_id);
|
||||
let hatch = resolve_hatch(p, hid, Some(angle), resolve_foreground(comp, fg, category, fg_source), None).ok_or_else(|| missing("Unbekannte Schraffur", hid))?;
|
||||
// Hängende Schraffur (Datei/Import): ohne Muster statt Abbruch.
|
||||
let hatch = resolve_hatch(p, hid, Some(angle), resolve_foreground(comp, fg, category, fg_source), None).unwrap_or_else(no_hatch);
|
||||
let bg = resolve_background(comp, bg, category, bg_source);
|
||||
let fill = bg.map(String::from).unwrap_or_else(|| poche_fill(hatch.pattern).to_string());
|
||||
Ok((fill, hatch))
|
||||
@@ -525,7 +522,7 @@ fn layer_style(
|
||||
/// Jede Schicht ist im Schnitt-Modell eine eigene Platte; ihr Band trägt so genau ihr Bauteil.
|
||||
fn style_slab_layer(cp: &mut Cut, p: &Project, layer: &Layer, owner: &Ceiling) -> Result<(), String> {
|
||||
let category = p.layer_category(&owner.category_code);
|
||||
let comp = p.component(&layer.component_id).ok_or_else(|| missing("Unbekanntes Bauteil-Material", &layer.component_id))?;
|
||||
let comp = p.component_or_fallback(&layer.component_id);
|
||||
let (fill, hatch) = layer_style(p, comp, owner.hatch_id.as_deref(), owner.hatch_source, owner.foreground.as_deref(), owner.foreground_source, owner.background.as_deref(), owner.background_source, category, SECTION_SLAB_AXIS_ANGLE_DEG)?;
|
||||
cp.fill = Some(fill);
|
||||
cp.hatch = Some(hatch);
|
||||
@@ -561,7 +558,7 @@ fn split_wall_layers(cp: &Cut, p: &Project, layers: &[Layer], owner: &Wall, u_wo
|
||||
let mut out = Vec::with_capacity(layers.len());
|
||||
let mut acc = 0.0;
|
||||
for layer in ordered {
|
||||
let comp = p.component(&layer.component_id).ok_or_else(|| missing("Unbekanntes Bauteil-Material", &layer.component_id))?;
|
||||
let comp = p.component_or_fallback(&layer.component_id);
|
||||
let (fill, hatch) = layer_style(p, comp, owner.hatch_id.as_deref(), owner.hatch_source, owner.foreground.as_deref(), owner.foreground_source, owner.background.as_deref(), owner.background_source, category, SECTION_WALL_AXIS_ANGLE_DEG)?;
|
||||
let u_left = u_min + acc * scale;
|
||||
acc += layer.thickness;
|
||||
@@ -599,7 +596,7 @@ fn attach_cut_styles(cuts: Vec<Cut>, p: &Project, plane: &Plane, walls: &[Option
|
||||
cp.source_id = owner.map(|o| o.id.clone());
|
||||
cp.category = owner.map(|o| o.category_code.clone());
|
||||
if let Some(o) = owner {
|
||||
let wt = p.wall_type(o).ok_or_else(|| missing("Unbekannter Wandtyp", &o.wall_type_id))?;
|
||||
let wt = p.wall_type_or_fallback(o);
|
||||
if wt.layers.len() > 1 {
|
||||
bands.extend(split_wall_layers(&cp, p, &wt.layers, o, u_world)?);
|
||||
continue;
|
||||
@@ -618,7 +615,7 @@ fn attach_cut_styles(cuts: Vec<Cut>, p: &Project, plane: &Plane, walls: &[Option
|
||||
SlabOwner::Ceiling(o, layer) => {
|
||||
cp.source_id = Some(o.id.clone());
|
||||
cp.category = Some(o.category_code.clone());
|
||||
let layers = ceiling_layers(p, o).ok_or_else(|| missing("Unbekannter Deckentyp", o.ceiling_type_id.as_deref().unwrap_or(&o.wall_type_id)))?;
|
||||
let layers = ceiling_layers(p, o).unwrap_or(Project::fallback_layers());
|
||||
if layers.len() > 1 {
|
||||
// Schicht-Platte: Stil genau dieser Schicht; ohne Schicht (Dicke 0) ohne Stil.
|
||||
if let Some(l) = layer.and_then(|i| layers.get(i)) {
|
||||
@@ -1371,8 +1368,7 @@ fn cross_section(p: &Project, wall: &Wall, o: &Opening, p0: (f64, f64), u: (f64,
|
||||
let n0 = rel.0 * n.0 + rel.1 * n.1;
|
||||
let a0 = rel.0 * a.0 + rel.1 * a.1;
|
||||
let ua = u.0 * a.0 + u.1 * a.1;
|
||||
let wt = p.wall_type(wall).ok_or_else(|| missing("Unbekannter Wandtyp", &wall.wall_type_id))?;
|
||||
let total = sum_thickness(&wt.layers);
|
||||
let total = sum_thickness(&p.wall_type_or_fallback(wall).layers);
|
||||
let ref_off = crate::joins::reference_offset(model3d::wall_reference(wall), total);
|
||||
let along = a0 + ((ref_off - n0) / un) * ua;
|
||||
if along < from + 1e-4 || along > to - 1e-4 {
|
||||
@@ -1414,7 +1410,7 @@ fn window_cut(p: &Project, wall: &Wall, o: &Opening, c: &CrossSection) -> Result
|
||||
let mut f_max = f_min + DEFAULT_FRAME_DEPTH;
|
||||
let mut glass: Vec<f64> = vec![(f_min + f_max) / 2.0];
|
||||
// `windowSymbol(project, wall, o, 1, spec, "mittel")`.
|
||||
let total = sum_thickness(&p.wall_type(wall).ok_or_else(|| missing("Unbekannter Wandtyp", &wall.wall_type_id))?.layers);
|
||||
let total = sum_thickness(&p.wall_type_or_fallback(wall).layers);
|
||||
let ref_off = crate::joins::reference_offset(model3d::wall_reference(wall), total);
|
||||
let spec = wt.map(|t| crate::opening_geom::WindowSpec {
|
||||
sashes: sashes_of_window_type(t),
|
||||
|
||||
@@ -84,13 +84,11 @@ pub fn poche_fill(p: HatchPattern) -> &'static str {
|
||||
}
|
||||
}
|
||||
|
||||
/// `resolveHatch`: `None`, wenn Schraffur oder ihr Linienstil fehlen (TS wirft dort — Aufrufer fängt).
|
||||
/// `resolveHatch`: `None`, wenn die Schraffur fehlt. Ein hängender Linienstil der Schraffur
|
||||
/// (Datei/Import) zählt wie keiner (Vorgabe-Strichstärke 0.13, durchgezogen).
|
||||
pub fn resolve_hatch(p: &Project, hatch_id: &str, wall_angle_deg: Option<f64>, foreground: Option<&str>, placement: Option<(Option<f64>, Option<f64>, Option<Vec2>)>) -> Option<HatchRender> {
|
||||
let h = p.hatch(hatch_id)?;
|
||||
let ls = match h.line_style_id.as_deref().filter(|s| !s.is_empty()) {
|
||||
Some(id) => Some(p.line_style(id)?),
|
||||
None => None,
|
||||
};
|
||||
let ls = h.line_style_id.as_deref().filter(|s| !s.is_empty()).and_then(|id| p.line_style(id));
|
||||
let (p_angle, p_scale, p_origin) = placement.unwrap_or((None, None, None));
|
||||
let base_angle = p_angle.unwrap_or(h.angle);
|
||||
let angle = match wall_angle_deg {
|
||||
|
||||
@@ -34,8 +34,9 @@ pub fn opening_label(o: &Opening) -> String {
|
||||
format!("{} {}×{}", if o.kind == ElementKind::Door { "Tür" } else { "Fenster" }, to_fixed(o.width * 100.0, 0), to_fixed(o.height * 100.0, 0))
|
||||
}
|
||||
|
||||
/// Wandtyp; hängender Verweis (Datei/Import) → Rückfall-Typ, nie ein Fehler.
|
||||
fn wall_type<'a>(p: &'a Project, w: &Wall) -> Result<&'a WallType, String> {
|
||||
p.wall_type(w).ok_or_else(|| format!("Unbekannter Wandtyp: {}", w.wall_type_id))
|
||||
Ok(p.wall_type_or_fallback(w))
|
||||
}
|
||||
|
||||
/// Verschneidung der gezeichneten Wände (`computeJoins` in TS, gleicher Puffer). Fehler wie die
|
||||
@@ -52,33 +53,18 @@ fn plan_joins(p: &Project, walls: &[EffWall]) -> Result<Vec<WallCuts>, String> {
|
||||
(None, Some(WallReferenceLine::Right)) => buf.extend([2.0, 0.0]),
|
||||
_ => buf.extend([0.0, 0.0]),
|
||||
}
|
||||
let Some(wt) = p.wall_type(w) else {
|
||||
buf.extend([0.0, 0.0]);
|
||||
continue;
|
||||
};
|
||||
// Hängende Wandtypen/Bauteile (Datei/Import) verschneiden mit den Rückfall-Werten.
|
||||
let wt = p.wall_type_or_fallback(w);
|
||||
buf.extend([1.0, wt.layers.len() as f64]);
|
||||
for l in &wt.layers {
|
||||
let comp = p.component(&l.component_id);
|
||||
let idx = match comp {
|
||||
Some(c) => {
|
||||
let n = comp_index.len();
|
||||
*comp_index.entry(c.id.as_str()).or_insert(n) as f64
|
||||
}
|
||||
None => -1.0,
|
||||
};
|
||||
buf.extend([l.thickness, idx, comp.map_or(f64::NAN, |c| c.join_priority)]);
|
||||
let comp = p.component_or_fallback(&l.component_id);
|
||||
let n = comp_index.len();
|
||||
let idx = *comp_index.entry(comp.id.as_str()).or_insert(n) as f64;
|
||||
buf.extend([l.thickness, idx, comp.join_priority]);
|
||||
}
|
||||
}
|
||||
let out = joins::compute_joins_flat(&buf);
|
||||
if out.first() == Some(&1.0) {
|
||||
let bad = out.get(1).and_then(|i| walls.get(*i as usize));
|
||||
if let Some(e) = bad {
|
||||
for l in &wall_type(p, e.w)?.layers {
|
||||
p.component(&l.component_id).ok_or_else(|| format!("Unbekanntes Bauteil-Material: {}", l.component_id))?;
|
||||
}
|
||||
}
|
||||
return Err("computeJoins: unbekannter Wandtyp oder Bauteil".into());
|
||||
}
|
||||
// Fehler der Verschneidung (mit den Rückfällen oben nicht mehr erwartet): Wände ohne Verschneidung.
|
||||
if out.first() != Some(&0.0) {
|
||||
return Ok(vec![WallCuts::default(); walls.len()]);
|
||||
}
|
||||
@@ -199,9 +185,9 @@ fn wall_poche(c: &Ctx, out: &mut Vec<Primitive>, e: &EffWall, gaps: &[(f64, f64)
|
||||
return Ok(s.clone());
|
||||
}
|
||||
let layer = wt.layers.get(li).ok_or("Schicht fehlt")?;
|
||||
let comp = p.component(&layer.component_id).ok_or_else(|| format!("Unbekanntes Bauteil-Material: {}", layer.component_id))?;
|
||||
let comp = p.component_or_fallback(&layer.component_id);
|
||||
let hid = resolve_hatch_id(w.hatch_id.as_deref(), w.hatch_source, category, Some(&comp.hatch_id)).unwrap_or(&comp.hatch_id);
|
||||
let hatch = super::domains::resolve_hatch_or_err(p, hid, Some(angle), resolve_foreground(comp, w.foreground.as_deref(), category, w.foreground_source))?;
|
||||
let hatch = super::domains::resolve_hatch_or_none(p, hid, Some(angle), resolve_foreground(comp, w.foreground.as_deref(), category, w.foreground_source));
|
||||
let bg = resolve_background(comp, w.background.as_deref(), category, w.background_source);
|
||||
let fill = bg.unwrap_or(if hatch.pattern == HatchPattern::Solid { HATCH_INK } else { HATCH_PAPER }).to_string();
|
||||
styles.insert(li, (hatch.clone(), fill.clone()));
|
||||
|
||||
Reference in new issue
Block a user