[271] Umbau in Schnitt, Ansicht, 2D und Möbeln: Abbruch-Stück und Ausfachung auch im Schnitt und in der Ansicht (Bogenwände eingeschlossen), Projektionslinien und Ansichts-Öffnungen in Umbau-Farbe, 2D-Elemente/Möbel/Bäume mit Status
Schnitt und Ansicht rechnen die Ersatzstücke der Öffnungen aus dem Projekt mit allem (die zugemauerte Öffnung fehlt im gefilterten Projekt); Grundriss auch für Bogenwände. Projektionslinien des Schnitts über Output::edge_ids, Öffnungslinien der Ansicht über restyle_with. Drawing2D.renovation (Möbel/Symbole immer, übrige 2D-Elemente nur mit ausdrücklichem Status), Strichfarbe in drawings::emit; Bäume: Tree.status IST der Umbau-Status (tree_renovation), kein zweites Feld. Schnitt entfernt jetzt auch ausgeblendete Bäume/Körper (without_hidden). Beispiel :umbau mit Möbeln, Bäumen und Ansicht West; Bilder doc/review-271/06-09.
This commit is contained in:
26 files changed
+822
-50
No files matched your search
@@ -67,11 +67,26 @@ pub fn stamp_renovation(mut ops: Vec<Op>, ren: Option<&Value>) -> Vec<Op> {
|
||||
};
|
||||
for op in ops.iter_mut() {
|
||||
if let Op::Add { collection, items, .. } = op {
|
||||
if !RENOVATION_COLLECTIONS.contains(&collection.as_str()) {
|
||||
let coll = collection.as_str();
|
||||
// [271] Bäume: ihr Bestand ([149], `status`) ist der Umbau-Status (Neu = neu, Abbruch = zu fällen).
|
||||
if coll == "trees" {
|
||||
let tree_status = if r.get("status").and_then(Value::as_str) == Some("demolish") { "remove" } else { "new" };
|
||||
for it in items.iter_mut().filter_map(Value::as_object_mut) {
|
||||
if it.get("status").and_then(Value::as_str).is_none_or(|s| s == "existing") {
|
||||
it.insert("status".into(), Value::String(tree_status.into()));
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if !RENOVATION_COLLECTIONS.contains(&coll) && coll != "drawings2d" {
|
||||
continue;
|
||||
}
|
||||
for it in items.iter_mut() {
|
||||
if let Some(o) = it.as_object_mut() {
|
||||
// [271] 2D-Elemente: Möbel/Symbole und Linienwerk; Masse, Texte, Koten, Raster u. ä. sind keine Bauteile.
|
||||
if coll == "drawings2d" && !o.get("geom").and_then(|g| g.get("shape")).and_then(Value::as_str).is_some_and(|s| STAMPED_SHAPES.contains(&s)) {
|
||||
continue;
|
||||
}
|
||||
o.entry("renovation").or_insert_with(|| r.clone());
|
||||
}
|
||||
}
|
||||
@@ -80,6 +95,9 @@ pub fn stamp_renovation(mut ops: Vec<Op>, ren: Option<&Value>) -> Vec<Op> {
|
||||
ops
|
||||
}
|
||||
|
||||
/// [271] 2D-Formen, die den Zeichen-Status tragen (Linienwerk, Möbel und Symbole).
|
||||
const STAMPED_SHAPES: [&str; 9] = ["line", "polyline", "rect", "circle", "arc", "ellipse", "libobj", "block", "bezier"];
|
||||
|
||||
/// Wie [`ops`], mit Hinweis-Schlüssel (i18n) für die Hülle; bisher nur Verschieben ([144]: Öffnung an
|
||||
/// der Nachbaröffnung angehalten).
|
||||
pub fn result(root: &Map<String, Value>, p: &Project, text: &str) -> Result<GripResult, String> {
|
||||
|
||||
@@ -4981,6 +4981,10 @@ pub struct Drawing2D {
|
||||
#[serde(rename = "hatchSource", default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub hatch_source: Option<AttributeSource>,
|
||||
/// [271] Umbau: Status (Bestand, Abbruch, Neu) und Etappe — auch für Objekte der Bibliothek (Möbel). Fehlt ⇒ Bestand.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub renovation: Option<Renovation>,
|
||||
/// [272] Variante, zu der das Element gehört (`Project.designOptionSets`). Fehlt ⇒ Hauptmodell (immer sichtbar).
|
||||
#[serde(rename = "designOption", default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
|
||||
@@ -2361,7 +2361,8 @@ fn assemble_cached(c: &Ctx, revs: &crate::document::Revs, cc: &mut super::cache:
|
||||
h = (h ^ b as u64).wrapping_mul(0x0000_0100_0000_01b3);
|
||||
}
|
||||
// [199] Die Zahlen der Aussenbemassung weichen Schnittmarken aus: der Stand der Schnitte gehört dazu.
|
||||
(h ^ revs.field("drawingLevels").rotate_left(7)) ^ cc.drawings.sig.wrapping_mul(0xff51_afd7_ed55_8ccd)
|
||||
// [271] Möbel und Zeichnungen folgen dem Umbaufilter (Ebene) und den Umbau-Farben/Etappen des Projekts.
|
||||
(h ^ revs.field("drawingLevels").rotate_left(7) ^ revs.field("renovation").rotate_left(13)) ^ cc.drawings.sig.wrapping_mul(0xff51_afd7_ed55_8ccd)
|
||||
};
|
||||
// [140] Achsraster enden an der Gebäudegrundfläche: ihr Stand folgt auch Wänden, Körpern und Dächern.
|
||||
let stamps = revs.item_stamps("drawings2d").unwrap_or(&[]);
|
||||
|
||||
@@ -236,6 +236,8 @@ pub fn shape_name(g: &Drawing2DGeom) -> &'static str {
|
||||
/// Element-Attribute nach den Override-Regeln (Farbe, Strichstärke, Linienstil) und die Ebene.
|
||||
#[derive(Clone, Copy, Default)]
|
||||
pub struct Attrs<'a> {
|
||||
/// [271] Strichmuster „Abbruch“ ([`crate::renovation::DEMOLISH_DASH`]) statt des Linienstils.
|
||||
pub demolish_dash: bool,
|
||||
pub color: Option<&'a str>,
|
||||
pub weight: Option<f64>,
|
||||
pub line_style_id: Option<&'a str>,
|
||||
@@ -245,12 +247,13 @@ pub struct Attrs<'a> {
|
||||
impl<'a> Attrs<'a> {
|
||||
/// Ohne Overrides: die Felder des Elements.
|
||||
pub fn of(c: &Ctx<'a>, d: &'a Drawing2D) -> Self {
|
||||
Attrs { color: d.color.as_deref(), weight: d.weight_mm, line_style_id: d.line_style_id.as_deref(), category: c.cat(&d.category_code) }
|
||||
Attrs { demolish_dash: false, color: d.color.as_deref(), weight: d.weight_mm, line_style_id: d.line_style_id.as_deref(), category: c.cat(&d.category_code) }
|
||||
}
|
||||
|
||||
/// Mit Override-Aktionen (`ov.x ?? d.x`).
|
||||
pub fn with(d: &'a Drawing2D, ov: &'a Actions, category: Option<&'a LayerCategory>) -> Self {
|
||||
Attrs {
|
||||
demolish_dash: false,
|
||||
color: ov.color.as_deref().or(d.color.as_deref()),
|
||||
weight: ov.lineweight.or(d.weight_mm),
|
||||
line_style_id: ov.linetype_id.as_deref().or(d.line_style_id.as_deref()),
|
||||
@@ -375,6 +378,13 @@ fn street_name_on_axis(c: &Ctx, d: &Drawing2D, text: &str, height: f64, at: Vec2
|
||||
/// trifft sie auch die rekursiv erzeugte Block-Geometrie (dort mehrfach, wie in TS).
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn emit(c: &Ctx, d: &Drawing2D, attrs: Attrs, geom: &Drawing2DGeom, greyed: bool, scale: f64, sink: &mut Sink, depth: u32) -> Result<(), String> {
|
||||
// [271] Umbaufilter: Möbel und Elemente mit Umbau-Status zeichnen in der Farbe ihres Status (Linienfarbe, sonst die
|
||||
// Füllfarbe) und bei Abbruch gestrichelt; sie gehen den Regeln vor wie bei Wänden.
|
||||
let mut attrs = attrs;
|
||||
if let Some(st) = c.renovation().and_then(|r| r.styled.get(&d.id)) {
|
||||
attrs.color = Some(st.line.as_deref().unwrap_or(&st.fill));
|
||||
attrs.demolish_dash = st.dashed;
|
||||
}
|
||||
let clamp = |v: Option<f64>| v.filter(|x| *x < 1.0).map(|x| jsnum::max(0.0, x));
|
||||
sink.frames.push((clamp(d.opacity), clamp(d.fill_opacity)));
|
||||
let r = emit_inner(c, d, attrs, geom, greyed, scale, sink, depth);
|
||||
@@ -662,6 +672,7 @@ fn emit_inner(c: &Ctx, d: &Drawing2D, attrs: Attrs, geom: &Drawing2DGeom, greyed
|
||||
};
|
||||
let raw = ls.and_then(|l| l.dash.as_ref());
|
||||
let (dash, dash_ref) = match raw {
|
||||
_ if attrs.demolish_dash => (Some(Cow::Borrowed(&crate::renovation::DEMOLISH_DASH[..])), sink.fresh_ref()),
|
||||
None => (None, 0),
|
||||
Some(r) if dash_scale != 1.0 => (Some(Cow::Owned(r.iter().map(|x| x * dash_scale).collect::<Vec<f64>>())), sink.fresh_ref()),
|
||||
Some(r) => (Some(Cow::Borrowed(r.as_slice())), DASH_REF_STYLE + ls_idx.unwrap_or(0) as u32),
|
||||
|
||||
@@ -71,6 +71,8 @@ const IMPORTED_RGB: [f64; 3] = [159.0 / 255.0, 166.0 / 255.0, 174.0 / 255.0];
|
||||
/// [115] Freie Körper: Farbe wie im 3D (`EXTRUSION_RGB` in `toWalls3d/extrusions.ts`).
|
||||
const BODY_RGB: [f64; 3] = [0.85, 0.55, 0.25];
|
||||
const EPS: f64 = 1e-6;
|
||||
/// [271] Tiefe (m) vor der Öffnungsmitte, in der ein Ersatzstück auf Verdeckung geprüft wird (die Fassade davor zählt nicht).
|
||||
const PATCH_DEPTH_SLACK: f64 = 0.5;
|
||||
const HIDDEN_INK: &str = "#8a929c";
|
||||
const HIDDEN_MM: f64 = 0.13;
|
||||
const HIDDEN_DASH: [f64; 2] = super::line_pattern::HIDDEN;
|
||||
@@ -205,12 +207,13 @@ pub fn elevation_primitives(p: &Project, level: &LevelSpec, shadows: bool, mono:
|
||||
/// `None` = Schalter im Projekt). [33] Regeln wirken auf Flächen (Füllung, Schraffur, ausblenden), Kanten
|
||||
/// (Farbe, Stärke, Umriss aus) und Öffnungen (Linien, Glasfüllung).
|
||||
pub fn elevation_primitives_with(p: &Project, level: &LevelSpec, shadows: bool, mono: bool, vis: &Visibility, scale: f64, rules: Option<&HashSet<String>>) -> Result<Option<(Vec<Primitive>, [f64; 4])>, String> {
|
||||
elevation_primitives_ren(p, level, shadows, mono, vis, scale, rules, None)
|
||||
elevation_primitives_ren(p, level, shadows, mono, vis, scale, rules, None, p)
|
||||
}
|
||||
|
||||
/// [271] Wie [`elevation_primitives_with`] mit den Umbau-Farben `ren` (das Ausgeblendete fehlt schon in `p`).
|
||||
/// [271] Wie [`elevation_primitives_with`] mit den Umbau-Farben `ren` (das Ausgeblendete fehlt schon in `p`; `orig` ist das
|
||||
/// Projekt mit allem, Quelle der Ersatzstücke zugemauerter Öffnungen).
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn elevation_primitives_ren(p: &Project, level: &LevelSpec, shadows: bool, mono: bool, vis: &Visibility, scale: f64, rules: Option<&HashSet<String>>, ren: Option<&crate::renovation::Resolved>) -> Result<Option<(Vec<Primitive>, [f64; 4])>, String> {
|
||||
pub fn elevation_primitives_ren(p: &Project, level: &LevelSpec, shadows: bool, mono: bool, vis: &Visibility, scale: f64, rules: Option<&HashSet<String>>, ren: Option<&crate::renovation::Resolved>, orig: &Project) -> Result<Option<(Vec<Primitive>, [f64; 4])>, String> {
|
||||
let Some(plane) = level.plane() else { return Ok(None) };
|
||||
let frame = frame_of(&plane);
|
||||
let mut walls = model3d::emit_walls_with(p, false, false)?;
|
||||
@@ -416,6 +419,22 @@ pub fn elevation_primitives_ren(p: &Project, level: &LevelSpec, shadows: bool, m
|
||||
_ => op.depth <= d + 1e-6,
|
||||
});
|
||||
}
|
||||
// [271] Umbau: Ersatzstücke der Öffnungen in Bestandswänden (Abbruch-Stück bzw. Ausfachung) auf der Fassade. Sie stehen im
|
||||
// Projekt MIT den Öffnungen (`orig`: die zugemauerte fehlt in `p`), gelten für sichtbare Klassen und Wände.
|
||||
let patch_ops: Vec<(ProjOpening, &crate::renovation::Patch)> = match ren.filter(|r| !r.patches.is_empty()) {
|
||||
Some(r) => {
|
||||
let shown = |c: &str| vis.visible(c) && vis.render(c);
|
||||
collect_openings(orig, &frame, win)
|
||||
.into_iter()
|
||||
.filter_map(|op| r.patches.iter().find(|pa| pa.opening_id == op.id).map(|pa| (op, pa)))
|
||||
.filter(|(op, pa)| {
|
||||
let cat_ok = orig.openings.iter().flatten().find(|o| o.id == op.id).is_none_or(|o| shown(&o.category_code)) && wall_cat.get(pa.wall_id.as_str()).is_none_or(|c| shown(c));
|
||||
cat_ok && !hidden_walls.contains(&pa.wall_id) && !far.as_ref().is_some_and(|(_, dropped)| dropped.contains(&(Role::Wall, pa.wall_id.clone())))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
None => Vec::new(),
|
||||
};
|
||||
let mut occ = vec![(faces.len() + openings.len()) as f64];
|
||||
for f in &faces {
|
||||
occ.extend([f.depth_max, f.pts.len() as f64]);
|
||||
@@ -495,7 +514,7 @@ pub fn elevation_primitives_ren(p: &Project, level: &LevelSpec, shadows: bool, m
|
||||
}
|
||||
}
|
||||
// [149] Bäume: Silhouette (Krone gefüllt, Stamm) in der Maler-Reihenfolge; Bauteile davor verdecken sie.
|
||||
for (depth, tree) in super::trees::view_trees(p, level, vis, Some(super::trees::view_crown_fill(mono)), None) {
|
||||
for (depth, tree) in super::trees::view_trees(p, level, vis, Some(super::trees::view_crown_fill(mono)), None, ren) {
|
||||
for prim in tree {
|
||||
if let Primitive::Polygon { pts, .. } = &prim {
|
||||
for q in pts {
|
||||
@@ -690,9 +709,18 @@ pub fn elevation_primitives_ren(p: &Project, level: &LevelSpec, shadows: bool, m
|
||||
seq += 1;
|
||||
}
|
||||
}
|
||||
let mut push = |prim: Primitive| {
|
||||
items.push(Item { depth: d, seq, rank: None, prim });
|
||||
seq += 1;
|
||||
// [271] Umbaufilter: Linien der Öffnung in der Linienfarbe des Status (neu rot), bei Abbruch gestrichelt; Flächen
|
||||
// (Rahmen, Glas, Blatt) behalten ihre Füllung.
|
||||
let ostyle = ren.and_then(|r| r.styled.get(&op.id));
|
||||
let mut push = |mut prim: Primitive| {
|
||||
let mut extra = Vec::new();
|
||||
if let Some(st) = ostyle {
|
||||
crate::renovation::restyle_with(&mut prim, st, &mut extra, false);
|
||||
}
|
||||
for q in std::iter::once(prim).chain(extra) {
|
||||
items.push(Item { depth: d, seq, rank: None, prim: q });
|
||||
seq += 1;
|
||||
}
|
||||
};
|
||||
// [33] Regeln der Öffnung: Linienfarbe/-stärke, Füllung für Glas und Türblatt.
|
||||
let ov = if op_rules { opening_override(p, rv, &op.id) } else { None };
|
||||
@@ -754,6 +782,35 @@ pub fn elevation_primitives_ren(p: &Project, level: &LevelSpec, shadows: bool, m
|
||||
}
|
||||
}
|
||||
|
||||
// [271] Ersatzstücke: nicht verdeckte (Mitte sichtbar), auf der Wand — mit offener Öffnung unter deren Rahmen, bei
|
||||
// geschlossener Wand (Öffnung im Filter ausgeblendet) knapp vor der Fassade.
|
||||
if !patch_ops.is_empty() {
|
||||
let mut b = vec![patch_ops.len() as f64];
|
||||
for (op, _) in &patch_ops {
|
||||
let q = &op.pts;
|
||||
b.extend([(q[0][0] + q[1][0] + q[2][0] + q[3][0]) / 4.0, (q[0][1] + q[1][1] + q[2][1] + q[3][1]) / 4.0, op.depth - PATCH_DEPTH_SLACK]);
|
||||
}
|
||||
let hidden_pt = crate::plan::elevation_geom::occluded_points(&occ, &b);
|
||||
for (k, (op, pa)) in patch_ops.iter().enumerate() {
|
||||
if hidden_pt.get(1 + k) == Some(&1.0) || op.pts.iter().any(|q| !q[0].is_finite() || !q[1].is_finite()) {
|
||||
continue;
|
||||
}
|
||||
let ring: Vec<Vec2> = op.pts.iter().map(|q| v2(q[0], q[1])).collect();
|
||||
for q in &ring {
|
||||
acc.add(q.x, q.y);
|
||||
}
|
||||
// Fläche unter dem Fenster (offene Öffnung) bzw. vor der Fassade (geschlossene Wand); der gestrichelte Umriss
|
||||
// des Abbruch-Stücks liegt über dem Fenster, sonst verdeckte dessen Rahmen die Aussage.
|
||||
let depth = if pa.closed { op.depth - PATCH_DEPTH_SLACK * 0.6 } else { op.depth - EPS * 50.0 };
|
||||
let outline_depth = if pa.closed { depth } else { op.depth - EPS * 200.0 };
|
||||
for prim in crate::renovation::patch_prims(ring, &pa.style, EDGE_MM, &op.id) {
|
||||
let depth = if matches!(prim, Primitive::Polygon { .. }) { depth } else { outline_depth };
|
||||
items.push(Item { depth, seq, rank: None, prim });
|
||||
seq += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Painter: fern zuerst; Gleichstand nach Rang (Decke < Wand < Dach < Rest), dann Reihenfolge.
|
||||
let nz = |d: f64| if d.is_nan() { 0.0 } else { d };
|
||||
items.sort_by(|a, b| {
|
||||
@@ -970,8 +1027,9 @@ pub fn elevation_plan_buf(p: &Project, args: &[f64], text: &str) -> Result<Vec<u
|
||||
// [271] Umbaufilter (angefragt, sonst der der Ebene): Ausgeblendetes fehlt (verdeckt nichts), Farben auf die Flächen.
|
||||
let ren = super::section::query::renovation_view(p, &v, &level).map(|r| r.resolve(p)).filter(|r| !r.is_empty());
|
||||
let filtered = ren.as_ref().filter(|r| !r.hidden.is_empty()).map(|r| crate::renovation::without_hidden(p, &r.hidden));
|
||||
let orig = p;
|
||||
let p = filtered.as_ref().unwrap_or(p);
|
||||
if let Some((mut prims, bounds)) = elevation_primitives_ren(p, &level, shadows, mono, &vis, scale, on.as_ref(), ren.as_ref())? {
|
||||
if let Some((mut prims, bounds)) = elevation_primitives_ren(p, &level, shadows, mono, &vis, scale, on.as_ref(), ren.as_ref(), orig)? {
|
||||
super::extras::scale_line_weights(p, scale, &mut prims);
|
||||
w.group(&prims);
|
||||
// Achsraster ([112]): Achsen quer zur Blickebene.
|
||||
|
||||
@@ -306,6 +306,8 @@ pub struct CutRules {
|
||||
/// [256] Vorgabe-Stil der Klasse je importiertem Netz (`Output::meshes`-Index): Füllung, Umrissfarbe, -stärke
|
||||
/// (`style::class_cut_style`, z. B. Nachbargebäude hellgrau statt schwarz).
|
||||
pub class: HashMap<usize, (String, String, f64)>,
|
||||
/// [271] Umbau-Farbe der Projektionslinien je Besitzer (`Output::edge_ids`): Linienfarbe bzw. Strichmuster des Status.
|
||||
pub edge: HashMap<(Kind, usize), crate::renovation::Style>,
|
||||
}
|
||||
|
||||
impl CutRules {
|
||||
@@ -313,6 +315,14 @@ impl CutRules {
|
||||
/// Abbruch. Geht den Regeln vor (der Umbaufilter ist die Aussage des Plans).
|
||||
pub fn with_renovation(mut self, out: &Output, r: Option<&crate::renovation::Resolved>) -> CutRules {
|
||||
let Some(r) = r.filter(|r| !r.styled.is_empty()) else { return self };
|
||||
// Projektionslinien: Besitzer mit Umbau-Farbe (nur Linienfarbe und Strichmuster, die Fläche gibt es nicht).
|
||||
for (k, id) in &out.edge_ids {
|
||||
if let Some(st) = r.styled.get(id) {
|
||||
if st.line.is_some() || st.dashed {
|
||||
self.edge.insert(*k, st.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
if out.cuts.iter().all(|c| c.source_id.as_ref().is_none_or(|s| !r.styled.contains_key(s))) {
|
||||
return self;
|
||||
}
|
||||
@@ -351,7 +361,7 @@ impl CutRules {
|
||||
mesh = rules.into_iter().enumerate().filter_map(|(i, r)| r.filter(|r| r.0.any()).map(|r| (i, MeshLineStyle { color: r.0.color.clone(), weight: r.0.lineweight.filter(|w| w.is_finite() && *w >= 0.0), dash: super::overrides::linetype_dash(p, r.0.linetype_id.as_deref()) }))).collect();
|
||||
}
|
||||
let class = out.meshes.iter().enumerate().filter_map(|(i, m)| m.category.as_deref().and_then(|k| super::style::class_cut_style(p, k)).map(|s| (i, s))).collect();
|
||||
CutRules { loose: loose_fill_components(p), ov, terrain, terrain_dash, terrain_hatch, mesh, class }
|
||||
CutRules { loose: loose_fill_components(p), ov, terrain, terrain_dash, terrain_hatch, mesh, class, edge: HashMap::new() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -551,6 +561,8 @@ pub struct Output {
|
||||
pub mesh_lines: Vec<(usize, Vec<[f64; 2]>)>,
|
||||
/// [180] Klasse der Bauteile hinter den Projektionskanten (`Edge::kind`, `Edge::index`; Netze über `meshes`).
|
||||
pub edge_cats: HashMap<(Kind, usize), String>,
|
||||
/// [271] Element-Id der Bauteile hinter den Projektionskanten (wie `edge_cats`): Umbau-Farbe der Projektionslinien.
|
||||
pub edge_ids: HashMap<(Kind, usize), String>,
|
||||
/// [208] ±0.00 und „Gelände"-Klasse ausgeblendet? (Bodenlinie ohne Geländenetz, `elevation::ground_ref`); Standard: 0 / nein.
|
||||
pub ground: (f64, bool),
|
||||
}
|
||||
@@ -582,6 +594,32 @@ pub(crate) fn edge_categories(p: &Project, walls: &[Option<&Wall>], slabs: &[ban
|
||||
m
|
||||
}
|
||||
|
||||
/// [271] Element-Ids der Projektions-Besitzer (Schlüssel wie [`edge_categories`]): Wände, Decken, Treppen, Stützen, Dächer, Körper.
|
||||
pub(crate) fn edge_ids(p: &Project, walls: &[Option<&Wall>], slabs: &[bands::SlabOwner]) -> HashMap<(Kind, usize), String> {
|
||||
let mut m = HashMap::new();
|
||||
for (i, w) in walls.iter().enumerate() {
|
||||
if let Some(w) = w {
|
||||
m.insert((Kind::Wall, i), w.id.clone());
|
||||
}
|
||||
}
|
||||
for (i, s) in slabs.iter().enumerate() {
|
||||
let id = match s {
|
||||
bands::SlabOwner::Ceiling(c, _) => &c.id,
|
||||
bands::SlabOwner::Stair(st) => &st.id,
|
||||
bands::SlabOwner::Column(c) => &c.id,
|
||||
bands::SlabOwner::None => continue,
|
||||
};
|
||||
m.insert((Kind::Slab, i), id.clone());
|
||||
}
|
||||
for (i, r) in p.roofs.as_deref().unwrap_or(&[]).iter().enumerate() {
|
||||
m.insert((Kind::Roof, i), r.id.clone());
|
||||
}
|
||||
for (i, b) in p.extruded_solids.as_deref().unwrap_or(&[]).iter().enumerate() {
|
||||
m.insert((Kind::Body, i), b.id.clone());
|
||||
}
|
||||
m
|
||||
}
|
||||
|
||||
/// [152] Ein importiertes Netz im Schnitt.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct MeshMeta {
|
||||
@@ -654,6 +692,7 @@ pub(super) fn compute_plane(p: &Project, level: &LevelSpec, bodies: &[BodyMesh],
|
||||
let walls: Vec<Option<&Wall>> = owners.iter().zip(&virt).map(|(o, v)| v.as_ref().or(*o)).collect();
|
||||
let slabs = slab_owners(p, &slabs_r);
|
||||
let edge_cats = edge_categories(p, &walls, &slabs);
|
||||
let edge_ids = edge_ids(p, &walls, &slabs);
|
||||
// [180] Ausgeblendete Klassen vor der Dominanz und der Verdeckung entfernen (nicht erst beim Zeichnen).
|
||||
let shown = |c: &str| vis.visible(c) && vis.render(c);
|
||||
let skip = |k: Kind, i: usize| edge_cats.get(&(k, i)).is_some_and(|c| !shown(c));
|
||||
@@ -687,7 +726,7 @@ pub(super) fn compute_plane(p: &Project, level: &LevelSpec, bodies: &[BodyMesh],
|
||||
let (mut visible, hidden) = projection_edges(p, &plane, &walls_r, &wi, &slabs_r, &bodies, &meshes, &cuts, level.hidden_lines, level.depth, strip.map_or(&[][..], |s| &s.half[..]), &skip);
|
||||
shaped_projection(&mut visible, p, &walls_r, &plane);
|
||||
let meshes = meshes.iter().map(|m| MeshMeta { id: m.mesh.id.clone(), name: m.mesh.name.clone(), category: Some(m.mesh.category_code.clone()) }).collect();
|
||||
let mut out = Output { cuts, visible, hidden, profiles: Vec::new(), earth: Vec::new(), shoring: Vec::new(), terrain_id: None, meshes, mesh_lines, edge_cats, ground: super::elevation::ground_ref(p, &|c| vis.visible(c) && vis.render(c)) };
|
||||
let mut out = Output { cuts, visible, hidden, profiles: Vec::new(), earth: Vec::new(), shoring: Vec::new(), terrain_id: None, meshes, mesh_lines, edge_cats, edge_ids, ground: super::elevation::ground_ref(p, &|c| vis.visible(c) && vis.render(c)) };
|
||||
append_terrain_profiles(&mut out, p, base, u);
|
||||
clip_context_meshes_to_terrain(&mut out);
|
||||
if let Some(s) = strip {
|
||||
|
||||
@@ -458,3 +458,43 @@ pub fn section_opening_primitives_mv(p: &Project, level: &LevelSpec, vis: &Visib
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// [271] Umbau im Schnitt: Ersatzstücke von Öffnungen in Bestandswänden (`renovation::Patch`) als Fläche in der Öffnung
|
||||
/// (Abbruch-Stück gelb gestrichelt, Ausfachung rot), dort, wo die Schnittebene die Öffnung trifft — wie die geschnittene
|
||||
/// Öffnung selbst ([`cross_section`], Bogenwände über die Sehne). `p` ist das Projekt MIT den im Filter ausgeblendeten
|
||||
/// Elementen (die geschlossene Öffnung steht sonst nicht darin); Wände in `skip` (Regel „Ausblenden“) und ausgeblendete
|
||||
/// Klassen entfallen. Ohne gültige Lage nichts (NaN, fehlende Wand/Öffnung).
|
||||
pub fn section_patch_primitives(p: &Project, level: &LevelSpec, vis: &Visibility, patches: &[crate::renovation::Patch], skip: &HashSet<String>) -> Vec<Primitive> {
|
||||
let Some(plane) = level.plane() else { return Vec::new() };
|
||||
if level.kind != "section" || patches.is_empty() {
|
||||
return Vec::new();
|
||||
}
|
||||
let u_raw = plane.u_model();
|
||||
let l = hypot2(u_raw.0, u_raw.1);
|
||||
let l = if l == 0.0 || l.is_nan() { 1.0 } else { l };
|
||||
let u = (u_raw.0 / l, u_raw.1 / l);
|
||||
let p0 = plane.base();
|
||||
let mut out = Vec::new();
|
||||
for pa in patches {
|
||||
let (Some(o), Some(wall)) = (p.openings.iter().flatten().find(|o| o.id == pa.opening_id), p.walls.iter().find(|w| w.id == pa.wall_id)) else { continue };
|
||||
if skip.contains(&wall.id) || !vis.visible(&wall.category_code) || !vis.render(&wall.category_code) || !vis.visible(&o.category_code) || !vis.render(&o.category_code) {
|
||||
continue;
|
||||
}
|
||||
let chord = arc_section_opening(p, wall, o, Some((p0, u)));
|
||||
let (wall, o) = match &chord {
|
||||
Some((vw, vo)) => (vw, vo),
|
||||
None => (wall, o),
|
||||
};
|
||||
let Ok(Some(c)) = cross_section(p, wall, o, p0, u) else { continue };
|
||||
let ring = rect(c.u_at(c.face_min), c.u_at(c.face_max), c.z_bottom, c.z_top);
|
||||
if ring.iter().any(|q| !q.x.is_finite() || !q.y.is_finite()) {
|
||||
continue;
|
||||
}
|
||||
let mut q = crate::renovation::patch_prims(ring, &pa.style, SECTION_VISIBLE_MM, &pa.opening_id);
|
||||
if vis.greyed(&wall.category_code) {
|
||||
q = q.into_iter().map(|x| x.with_greyed(true)).collect();
|
||||
}
|
||||
out.extend(q);
|
||||
}
|
||||
out
|
||||
}
|
||||
@@ -656,6 +656,15 @@ pub fn section_primitives_mv(out: &Output, mono: bool, hidden_lines: bool, vis:
|
||||
acc.add(e.b[0], e.b[1]);
|
||||
let mut l = line(v2(e.a[0], e.a[1]), v2(e.b[0], e.b[1]), "section-visible", SECTION_VISIBLE_MM, SECTION_VISIBLE_INK);
|
||||
mesh_style(e, &mut l);
|
||||
// [271] Umbau: Projektionslinie in der Linienfarbe des Status, bei Abbruch gestrichelt.
|
||||
if let (Some(st), Primitive::Line { color, dash, .. }) = (rules.edge.get(&(e.kind, e.index)), &mut l) {
|
||||
if let Some(c) = &st.line {
|
||||
*color = Some(c.clone().into());
|
||||
}
|
||||
if st.dashed {
|
||||
*dash = Some(Some(crate::renovation::DEMOLISH_DASH.to_vec()));
|
||||
}
|
||||
}
|
||||
prims.push(l);
|
||||
}
|
||||
// [152] Offene Schnittlinien importierter Netze (Flächen ohne Dicke, nicht-mannigfaltige Netze): schwer
|
||||
|
||||
@@ -76,7 +76,9 @@ pub fn section_plan_buf(p: &Project, args: &[f64], text: &str) -> Result<Vec<u8>
|
||||
if let Some(r) = &ren {
|
||||
hidden_ids.extend(r.hidden.iter().cloned());
|
||||
}
|
||||
let filtered = (!hidden_ids.is_empty()).then(|| without_elements(p, &hidden_ids));
|
||||
let filtered = (!hidden_ids.is_empty()).then(|| crate::renovation::without_hidden(p, &hidden_ids));
|
||||
// [271] Das Projekt mit allem (die zugemauerte Öffnung fehlt in `p` unten): Quelle der Ersatzstücke der Öffnungen.
|
||||
let orig = p;
|
||||
let p = filtered.as_ref().unwrap_or(p);
|
||||
// [184] Öffnungen mit Detailgrad grob (Strich im Schnitt): Wandschnitt an Sturz/Brüstung flach. Das ändert die
|
||||
// Schnittflächen, gehört also in den Schlüssel (unten) und in die Sichtbarkeit.
|
||||
@@ -138,12 +140,18 @@ pub fn section_plan_buf(p: &Project, args: &[f64], text: &str) -> Result<Vec<u8>
|
||||
let detail = mvo.as_ref().map_or(detail, |o| o.detail);
|
||||
let (mut prims, bounds) = section_primitives_mv(&out, mono, hidden, &vis, scale, detail, level.cut_hatch, &CutRules::of(p, &out, rv).with_renovation(&out, ren.as_ref()), smv.as_ref());
|
||||
w.post = crate::plan::extras::sketch_post(Some(level.sketch), scale);
|
||||
// [271] Umbau: Abbruch-Stück (neue Öffnung in Bestandswand) und Ausfachung (zugemauerte Öffnung) in der Schnittfläche.
|
||||
let parts = unfold::parts(&level);
|
||||
if let Some(r) = ren.as_ref().filter(|r| !r.patches.is_empty()) {
|
||||
for (l, s) in &parts {
|
||||
prims.extend(unfold::clip_prims(section_patch_primitives(orig, l, &vis, &r.patches, &hidden_ids), s.as_ref()));
|
||||
}
|
||||
}
|
||||
// Strichstärken nach Massstab ([32]) wie im Grundriss.
|
||||
crate::plan::extras::scale_line_weights(p, scale, &mut prims);
|
||||
// [149] Bäume hinter der Schnittebene: transparente Silhouette unter dem Schnitt (Bauteile verdecken sie).
|
||||
// [176] Geknickter Schnitt: Bäume, Öffnungen und Achsen je Segment, auf den Streifen geschnitten und abgewickelt.
|
||||
let parts = unfold::parts(&level);
|
||||
let mut trees: Vec<Primitive> = parts.iter().flat_map(|(l, s)| crate::plan::trees::view_trees(p, l, &vis, None, Some(mono)).into_iter().flat_map(move |(_, t)| unfold::keep_group(t, s.as_ref()))).collect();
|
||||
let mut trees: Vec<Primitive> = parts.iter().flat_map(|(l, s)| crate::plan::trees::view_trees(p, l, &vis, None, Some(mono), ren.as_ref()).into_iter().flat_map(move |(_, t)| unfold::keep_group(t, s.as_ref()))).collect();
|
||||
let bounds = crate::plan::trees::union_bounds(bounds, &trees);
|
||||
crate::plan::extras::scale_line_weights(p, scale, &mut trees);
|
||||
trees.extend(prims);
|
||||
|
||||
@@ -235,6 +235,7 @@ pub(super) fn merge_output(acc: &mut Option<Output>, o: Output) {
|
||||
a.shoring.extend(o.shoring);
|
||||
a.mesh_lines.extend(o.mesh_lines);
|
||||
a.edge_cats.extend(o.edge_cats);
|
||||
a.edge_ids.extend(o.edge_ids);
|
||||
if a.terrain_id.is_none() {
|
||||
a.terrain_id = o.terrain_id;
|
||||
}
|
||||
|
||||
@@ -130,7 +130,12 @@ pub(super) fn plan_trees(c: &Ctx, out: &mut Vec<Primitive>) {
|
||||
continue;
|
||||
}
|
||||
let greyed = Some(c.greyed(&t.category_code));
|
||||
let from = out.len();
|
||||
out.extend(tree_symbol(t, &g, c.cat(&t.category_code), greyed));
|
||||
// [271] Umbaufilter: der Baum in der Farbe seines Status (Bestand grau, Fällen gelb gestrichelt, Neu rot).
|
||||
if let Some(st) = c.renovation().and_then(|r| r.styled.get(&t.id)) {
|
||||
crate::renovation::restyle_linework(out, from, st, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,7 +279,7 @@ pub fn tree_symbol(t: &Tree, g: &TreeGeom, cat: Option<&LayerCategory>, greyed:
|
||||
/// Ebene trifft, erscheinen geschnitten: Kronen- und Stammquerschnitt mit Schnittstärke, davor liegende Teile
|
||||
/// entfallen (Mitte vor der Ebene: nur der Querschnitt als Umriss des Teils dahinter), Teile dahinter bleiben als
|
||||
/// Silhouette.
|
||||
pub fn view_trees(p: &Project, level: &LevelSpec, vis: &Visibility, fill: Option<&str>, cut: Option<bool>) -> Vec<(f64, Vec<Primitive>)> {
|
||||
pub fn view_trees(p: &Project, level: &LevelSpec, vis: &Visibility, fill: Option<&str>, cut: Option<bool>, ren: Option<&crate::renovation::Resolved>) -> Vec<(f64, Vec<Primitive>)> {
|
||||
let Some(trees) = p.trees.as_deref().filter(|t| !t.is_empty()) else { return vec![] };
|
||||
let Some(plane) = level.plane() else { return vec![] };
|
||||
let [nx, _, nz] = plane.normal;
|
||||
@@ -322,6 +327,10 @@ pub fn view_trees(p: &Project, level: &LevelSpec, vis: &Visibility, fill: Option
|
||||
prims.push(poly(to(&c), if mono { "none" } else { VIEW_CROWN_CUT_FILL }, stroke, VIEW_CUT_MM, pick, greyed));
|
||||
}
|
||||
}
|
||||
// [271] Umbaufilter: Silhouette in der Linienfarbe des Status (Bestand grau, Fällen gelb gestrichelt, Neu rot).
|
||||
if let Some(st) = ren.and_then(|r| r.styled.get(&t.id)) {
|
||||
crate::renovation::restyle_linework(&mut prims, 0, st, false);
|
||||
}
|
||||
out.push((depth, prims));
|
||||
}
|
||||
out
|
||||
@@ -471,7 +480,7 @@ mod tests {
|
||||
fn section_polys(p: &Project, id: &str) -> Vec<(f64, Vec<Vec2>)> {
|
||||
let l = p.drawing_levels.iter().find(|l| l.id == "sc").unwrap();
|
||||
let level = LevelSpec::from_json(&serde_json::to_value(l).unwrap());
|
||||
view_trees(p, &level, &Visibility::default(), None, Some(false))
|
||||
view_trees(p, &level, &Visibility::default(), None, Some(false), None)
|
||||
.into_iter()
|
||||
.flat_map(|(_, ps)| ps)
|
||||
.filter_map(|q| match q {
|
||||
@@ -509,7 +518,7 @@ mod tests {
|
||||
// Ansicht unverändert: ganze Silhouette, keine Schnittstärke.
|
||||
let l = p.drawing_levels.iter().find(|l| l.id == "an").unwrap();
|
||||
let level = LevelSpec::from_json(&serde_json::to_value(l).unwrap());
|
||||
let ps = view_trees(&p, &level, &Visibility::default(), None, None);
|
||||
let ps = view_trees(&p, &level, &Visibility::default(), None, None, None);
|
||||
assert!(ps.iter().flat_map(|(_, ps)| ps).all(|q| !matches!(q, Primitive::Polygon { stroke_width_mm, .. } if *stroke_width_mm == VIEW_CUT_MM)));
|
||||
}
|
||||
|
||||
|
||||
@@ -97,6 +97,25 @@ pub fn opening_renovation<'a>(p: &'a Project, o: &'a Opening) -> Option<&'a Reno
|
||||
o.renovation.as_ref().or_else(|| p.walls.iter().find(|w| w.id == o.host_wall_id).and_then(|w| w.renovation.as_ref()))
|
||||
}
|
||||
|
||||
/// Umbau-Angaben eines Baums: sein Bestand ([149], `Tree.status`) IST der Umbau-Status — bestehend = Bestand, neu = Neu,
|
||||
/// zu fällen = Abbruch. Ein Feld, keine zweite Wahrheit (der Baum trägt kein eigenes `renovation`); Etappen kennt er nicht
|
||||
/// (gilt als Etappe 1).
|
||||
pub fn tree_renovation(t: &Tree) -> Renovation {
|
||||
let status = match t.status {
|
||||
TreeStatus::New => RenovationStatus::New,
|
||||
TreeStatus::Remove => RenovationStatus::Demolish,
|
||||
_ => RenovationStatus::Existing,
|
||||
};
|
||||
Renovation { status, ..Default::default() }
|
||||
}
|
||||
|
||||
/// Nimmt eine 2D-Zeichnung am Umbaufilter teil? Möbel und Symbole (Objekte der Bibliothek, Blöcke) immer (ohne Angabe =
|
||||
/// Bestand); alle übrigen 2D-Elemente (Linien, Masse, Texte, Koten, Raster …) nur mit ausdrücklichem Umbau-Status — sonst
|
||||
/// blieben im Umbauplan alle Masse und Beschriftungen grau.
|
||||
pub fn drawing_takes_part(d: &Drawing2D) -> bool {
|
||||
d.renovation.is_some() || matches!(d.geom, Drawing2DGeom::Libobj { .. } | Drawing2DGeom::Block { .. })
|
||||
}
|
||||
|
||||
/// Umbau-Farbe eines Status, aufgelöst (Projekt-Vorgabe über der SIA-Vorgabe).
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Style {
|
||||
@@ -299,6 +318,13 @@ impl View {
|
||||
for x in p.extruded_solids.iter().flatten() {
|
||||
put(&x.id, self.treat(x.renovation.as_ref()), &mut out);
|
||||
}
|
||||
// [271] 2D-Zeichnungen (Möbel, Symbole und Elemente mit ausdrücklichem Status) und Bäume ([149]: Status = Umbau-Status).
|
||||
for x in p.drawings2d.iter().filter(|d| drawing_takes_part(d)) {
|
||||
put(&x.id, self.treat(x.renovation.as_ref()), &mut out);
|
||||
}
|
||||
for t in p.trees.iter().flatten() {
|
||||
put(&t.id, self.treat(Some(&tree_renovation(t))), &mut out);
|
||||
}
|
||||
// Räume: nur sichtbar oder nicht (ein Raum ist kein Bauteil, er bekommt keine Umbau-Farbe).
|
||||
for x in p.rooms.iter().flatten() {
|
||||
if !self.visible(x.renovation.as_ref()) {
|
||||
@@ -366,8 +392,12 @@ pub fn without_hidden(p: &Project, hidden: &HashSet<String>) -> Project {
|
||||
if let Some(v) = &mut q.extruded_solids {
|
||||
v.retain(|x| !hidden.contains(&x.id));
|
||||
}
|
||||
// [272] 2D-Zeichnungen anderer Varianten.
|
||||
// [272] 2D-Zeichnungen anderer Varianten, [271] Möbel und Symbole im Umbaufilter.
|
||||
q.drawings2d.retain(|x| !hidden.contains(&x.id));
|
||||
// [271] Bäume (Schnitt, Ansicht, 3D).
|
||||
if let Some(v) = &mut q.trees {
|
||||
v.retain(|x| !hidden.contains(&x.id));
|
||||
}
|
||||
q
|
||||
}
|
||||
|
||||
@@ -491,6 +521,21 @@ pub fn prim_element(q: &Primitive) -> Option<&str> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Strichzeichnung eines Objekts ohne Schnittfläche (Baum, Möbel): `prims[from..]` in der Linienfarbe des Status (sonst
|
||||
/// seiner Füllfarbe: Bestand grau, Abbruch gelb gestrichelt, Neu rot); gefüllte Flächen (Stamm) in der Füllfarbe,
|
||||
/// ausser mit `fill = false` (Silhouetten in Schnitt und Ansicht).
|
||||
pub fn restyle_linework(prims: &mut Vec<Primitive>, from: usize, st: &Style, fill: bool) {
|
||||
if from >= prims.len() {
|
||||
return;
|
||||
}
|
||||
let st = Style { fill: st.fill.clone(), line: Some(st.line.clone().unwrap_or_else(|| st.fill.clone())), dashed: st.dashed };
|
||||
let mut extra = Vec::new();
|
||||
for q in prims[from..].iter_mut() {
|
||||
restyle_with(q, &st, &mut extra, fill);
|
||||
}
|
||||
prims.extend(extra);
|
||||
}
|
||||
|
||||
/// Umbau-Farben auf `prims[from..]`: jedes Primitiv nach seinem Element ([`prim_element`]), sonst nach `owner`
|
||||
/// (z. B. die Wand, deren Umrisslinien keine Id tragen). Umrisslinien gestrichelter Flächen kommen dahinter.
|
||||
pub fn restyle_range(r: &Resolved, prims: &mut Vec<Primitive>, from: usize, owner: Option<&str>) {
|
||||
@@ -515,14 +560,28 @@ fn cut_fill(q: &Primitive) -> bool {
|
||||
matches!(q, Primitive::Polygon { opening_id: None, wall_id: Some(_), .. } | Primitive::Polygon { opening_id: None, column_id: Some(_), .. })
|
||||
}
|
||||
|
||||
/// Grundriss: Fläche eines Ersatzstücks (Wandband zwischen den Leibungen der Öffnung), `None` bei Bogenwänden
|
||||
/// oder ohne gültige Lage.
|
||||
/// Grundriss: Fläche eines Ersatzstücks (Wandband zwischen den Leibungen der Öffnung; bei Bogenwänden das Ringstück
|
||||
/// zwischen den Versatzbögen), `None` ohne gültige Lage.
|
||||
pub fn patch_ring(p: &Project, w: &Wall, o: &Opening) -> Option<Vec<Vec2>> {
|
||||
if crate::wall_arc::WallArc::of_wall(w).is_some() {
|
||||
return None;
|
||||
}
|
||||
let total = p.wall_thickness(w, 0.2);
|
||||
let ref_off = crate::joins::reference_offset(crate::model3d::wall_reference(w), total);
|
||||
if let Some(arc) = crate::wall_arc::WallArc::of_wall(w) {
|
||||
// Öffnungsmass in Bogenlänge der Achse (wie im Schnitt und in der Ansicht), Querversatz links der Laufrichtung.
|
||||
let axis = arc.length();
|
||||
let from = o.position.max(0.0).min(axis);
|
||||
let to = (o.position + o.width).min(axis).max(from);
|
||||
let (n0, n1) = (ref_off - total / 2.0, ref_off + total / 2.0);
|
||||
if !(to - from >= 1e-4) || ![from, to, n0, n1].iter().all(|x| x.is_finite()) {
|
||||
return None;
|
||||
}
|
||||
let st = arc.stations(from, to, arc.r_max(n0, n1));
|
||||
let at = |s: f64, n: f64| {
|
||||
let q = arc.point(s, n);
|
||||
Vec2 { x: q.x, y: q.y }
|
||||
};
|
||||
let ring: Vec<Vec2> = st.iter().map(|&s| at(s, n0)).chain(st.iter().rev().map(|&s| at(s, n1))).collect();
|
||||
return ring.iter().all(|v| v.x.is_finite() && v.y.is_finite()).then_some(ring);
|
||||
}
|
||||
let wr = crate::opening_geom::WallRef { start: crate::opening_geom::v(w.start.x, w.start.y), end: crate::opening_geom::v(w.end.x, w.end.y), total, ref_off };
|
||||
let (from, to) = crate::opening_geom::opening_interval(&wr, o.position, o.width)?;
|
||||
let fp = crate::plan::wall_poche::wall_footprint([w.start.x, w.start.y], [w.end.x, w.end.y], total, ref_off);
|
||||
@@ -653,9 +712,13 @@ pub fn renovation_of<'a>(p: &'a Project, id: &str) -> Option<&'a Renovation> {
|
||||
)*};
|
||||
}
|
||||
look!(ceilings, roofs, stairs, columns, extruded_solids, rooms);
|
||||
None
|
||||
p.drawings2d.iter().find(|d| d.id == id).and_then(|d| d.renovation.as_ref())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "renovation_tests.rs"]
|
||||
pub(crate) mod tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "renovation_tests2.rs"]
|
||||
mod tests2;
|
||||
@@ -304,7 +304,7 @@ fn grundriss_filter_der_ebene_und_etappe() {
|
||||
assert!(has_wall(&q, "W9"));
|
||||
}
|
||||
|
||||
fn section_prims(p: &Project, extra: Value) -> Vec<Primitive> {
|
||||
pub(crate) fn section_prims(p: &Project, extra: Value) -> Vec<Primitive> {
|
||||
let level = p.drawing_levels.iter().find(|l| l.id == "schnitt-a").unwrap();
|
||||
let mut v = json!({"level": level, "scale": 50, "detail": "mittel"});
|
||||
for (k, x) in extra.as_object().unwrap() {
|
||||
@@ -454,7 +454,7 @@ fn neue_bauteile_tragen_den_zeichen_status() {
|
||||
}
|
||||
_ => panic!(),
|
||||
}
|
||||
// 2D-Zeichnungen bekommen keinen Status.
|
||||
// 2D-Zeichnungen ohne Form (kein Möbel, kein Linienwerk) bekommen keinen Status (Rest: `renovation_tests2.rs`).
|
||||
assert!(matches!(&out[1], Op::Add { items, .. } if items[0].get("renovation").is_none()));
|
||||
// Bestand ohne Etappe = ohne Feld; Unsinn wird ignoriert.
|
||||
for r in [json!({"status": "existing"}), json!({"status": "kaputt"}), json!(42), json!(null)] {
|
||||
|
||||
@@ -0,0 +1,415 @@
|
||||
//! [271] Rest des Umbaufilters: Ersatzstücke in Schnitt und Ansicht, Projektionslinien, Möbel/2D-Elemente und Bäume.
|
||||
|
||||
use super::tests::{project, section_prims, umbau_fixture};
|
||||
use super::*;
|
||||
use crate::plan::domains::{plan_domains, PlanArgs};
|
||||
use serde_json::{json, Value};
|
||||
|
||||
/// Umbau-Fixture mit Schnitt Q (Nord–Süd bei x = 3.5: trifft O1 in W1 und O2 in W3), Ansicht Nord, Möbeln (Sofa neu, Tisch
|
||||
/// Abbruch, Sofa ohne Angabe), Linien (eine ohne Angabe, eine „neu“) und drei Bäumen (bestehend, zu fällen, neu).
|
||||
fn fixture() -> Value {
|
||||
let mut v = umbau_fixture();
|
||||
v["drawingLevels"].as_array_mut().unwrap().extend([
|
||||
json!({"id": "schnitt-q", "name": "Schnitt Q", "kind": "section", "visible": true, "locked": false, "linePoints": [{"x": 3.5, "y": -1}, {"x": 3.5, "y": 5}], "directionSign": -1}),
|
||||
json!({"id": "ansicht-nord", "name": "Ansicht Nord", "kind": "elevation", "visible": true, "locked": false, "linePoints": [{"x": 6, "y": 6}, {"x": -1, "y": 6}], "directionSign": 1}),
|
||||
]);
|
||||
let lib = |id: &str, lib: &str, x: f64, y: f64, r: Option<Value>| {
|
||||
let mut d = json!({"id": id, "type": "drawing2d", "levelId": "eg", "categoryCode": "22", "geom": {"shape": "libobj", "libId": lib, "at": {"x": x, "y": y}, "rotation": 0}});
|
||||
if let Some(r) = r {
|
||||
d["renovation"] = r;
|
||||
}
|
||||
d
|
||||
};
|
||||
let line = |id: &str, y: f64, r: Option<Value>| {
|
||||
let mut d = json!({"id": id, "type": "drawing2d", "levelId": "eg", "categoryCode": "22", "geom": {"shape": "line", "a": {"x": 0.5, "y": y}, "b": {"x": 1.5, "y": y}}});
|
||||
if let Some(r) = r {
|
||||
d["renovation"] = r;
|
||||
}
|
||||
d
|
||||
};
|
||||
let tree = |id: &str, x: f64, st: &str| {
|
||||
json!({"id": id, "type": "tree", "floorId": "eg", "categoryCode": "13", "position": {"x": x, "y": 2}, "trunkDiameter": 0.3, "crownDiameter": 3, "crownBase": 2, "height": 8, "shape": "round", "status": st, "foliage": "deciduous"})
|
||||
};
|
||||
v["drawings2d"].as_array_mut().unwrap().extend([
|
||||
lib("M1", "lib:sofa-2", 1.0, 1.0, Some(json!({"status": "new"}))),
|
||||
lib("M2", "lib:tisch-80x140", 3.0, 1.0, Some(json!({"status": "demolish"}))),
|
||||
lib("M3", "lib:sofa-2", 1.0, 3.0, None),
|
||||
line("L0", 3.6, None),
|
||||
line("L1", 3.8, Some(json!({"status": "new"}))),
|
||||
]);
|
||||
v["trees"] = json!([tree("T1", 8.0, "existing"), tree("T2", 12.0, "remove"), tree("T3", 16.0, "new")]);
|
||||
let layers = v["layers"].as_array_mut().unwrap();
|
||||
if !layers.iter().any(|l| l["code"] == "22") {
|
||||
layers.push(json!({"code": "22", "name": "Möbel", "color": "#4a4a4a", "lw": 0.13, "visible": true, "locked": false}));
|
||||
}
|
||||
v
|
||||
}
|
||||
|
||||
fn plan_args(extra: &Value) -> String {
|
||||
let codes: Vec<String> = (0..100).map(|k| format!("{k:02}")).collect();
|
||||
let mut t = json!({"floor": "eg", "show": codes, "scale": 100});
|
||||
for (k, x) in extra.as_object().unwrap() {
|
||||
t[k] = x.clone();
|
||||
}
|
||||
t.to_string()
|
||||
}
|
||||
|
||||
fn drawings_with(p: &Project, extra: Value) -> Vec<Primitive> {
|
||||
plan_domains(p, &PlanArgs::parse_in(p, 1.0, &plan_args(&extra)).unwrap()).unwrap().drawings.prims
|
||||
}
|
||||
|
||||
fn trees_with(p: &Project, extra: Value) -> Vec<Primitive> {
|
||||
plan_domains(p, &PlanArgs::parse_in(p, 1.0, &plan_args(&extra)).unwrap()).unwrap().columns
|
||||
}
|
||||
|
||||
/// Linien einer Zeichnung: (Farbe, gestrichelt).
|
||||
fn drawing_lines(prims: &[Primitive], id: &str) -> Vec<(String, bool)> {
|
||||
prims
|
||||
.iter()
|
||||
.filter_map(|q| match q {
|
||||
Primitive::Line { drawing_id: Some(d), color, dash, .. } if d == id => Some((color.as_ref().map(|c| c.to_string()).unwrap_or_default(), matches!(dash, Some(Some(_))))),
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn moebel_und_linienwerk_je_filter() {
|
||||
let p = project(&fixture());
|
||||
let new_c = default_style(RenovationStatus::New).line.unwrap();
|
||||
let dem_c = default_style(RenovationStatus::Demolish).fill;
|
||||
let ex_c = default_style(RenovationStatus::Existing).fill;
|
||||
// Ohne Filter: alles da, keine Umbau-Farbe.
|
||||
let all = drawings_with(&p, json!({}));
|
||||
for id in ["M1", "M2", "M3", "L0", "L1"] {
|
||||
let l = drawing_lines(&all, id);
|
||||
assert!(!l.is_empty(), "{id}");
|
||||
assert!(l.iter().all(|(c, d)| *c != new_c && *c != dem_c && *c != ex_c && !d), "{id}: {l:?}");
|
||||
}
|
||||
// Bestand: Neues fehlt (Sofa M1, Linie L1), der Abbruch-Tisch steht noch.
|
||||
let b = drawings_with(&p, json!({"renovation": "bestand"}));
|
||||
assert!(drawing_lines(&b, "M1").is_empty() && drawing_lines(&b, "L1").is_empty());
|
||||
assert!(!drawing_lines(&b, "M2").is_empty() && !drawing_lines(&b, "M3").is_empty() && !drawing_lines(&b, "L0").is_empty());
|
||||
// Endzustand: ohne Abbruch-Möbel, Neues da, ohne Farbe.
|
||||
let e = drawings_with(&p, json!({"renovation": "endzustand"}));
|
||||
assert!(drawing_lines(&e, "M2").is_empty(), "Abbruch-Tisch fehlt im Endzustand");
|
||||
assert!(!drawing_lines(&e, "M1").is_empty() && !drawing_lines(&e, "M3").is_empty() && !drawing_lines(&e, "L1").is_empty());
|
||||
assert!(drawing_lines(&e, "M1").iter().all(|(c, _)| *c != new_c));
|
||||
// Umbauplan: Bestand grau, Abbruch gelb gestrichelt, Neu rot; eine Linie ohne Angabe bleibt unverändert.
|
||||
let u = drawings_with(&p, json!({"renovation": "umbauplan"}));
|
||||
assert!(drawing_lines(&u, "M3").iter().all(|(c, d)| *c == ex_c && !d), "{:?}", drawing_lines(&u, "M3"));
|
||||
assert!(drawing_lines(&u, "M2").iter().all(|(c, d)| *c == dem_c && *d), "{:?}", drawing_lines(&u, "M2"));
|
||||
assert!(drawing_lines(&u, "M1").iter().all(|(c, d)| *c == new_c && !d), "{:?}", drawing_lines(&u, "M1"));
|
||||
assert!(drawing_lines(&u, "L1").iter().all(|(c, _)| *c == new_c));
|
||||
assert!(drawing_lines(&u, "L0").iter().all(|(c, d)| *c != ex_c && !d), "ohne Angabe nicht grau: {:?}", drawing_lines(&u, "L0"));
|
||||
// Neubau: Abbruch weg, Neu rot, Bestand ohne Farbe.
|
||||
let n = drawings_with(&p, json!({"renovation": "neubau"}));
|
||||
assert!(drawing_lines(&n, "M2").is_empty() && drawing_lines(&n, "M1").iter().all(|(c, _)| *c == new_c));
|
||||
assert!(drawing_lines(&n, "M3").iter().all(|(c, _)| *c != ex_c));
|
||||
// Der Filter der Ebene wirkt ebenso (ohne Argument).
|
||||
let mut v = fixture();
|
||||
for l in v["drawingLevels"].as_array_mut().unwrap() {
|
||||
if l["id"] == "eg" {
|
||||
l["renovationFilter"] = json!("endzustand");
|
||||
}
|
||||
}
|
||||
assert!(drawing_lines(&drawings_with(&project(&v), json!({})), "M2").is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn moebel_filter_unsinn_bleibt_ruhig() {
|
||||
// Unbekannter Status und Etappe, unbekanntes Objekt, absurde Lage: kein Panic, alles endlich.
|
||||
let mut v = fixture();
|
||||
for d in v["drawings2d"].as_array_mut().unwrap() {
|
||||
if d["id"] == "M1" {
|
||||
d["renovation"] = json!({"status": "kaputt", "phase": "gibts-nicht"});
|
||||
}
|
||||
if d["id"] == "M3" {
|
||||
d["geom"]["libId"] = json!("lib:zukunft");
|
||||
d["geom"]["at"] = json!({"x": 1e300, "y": -1e300});
|
||||
}
|
||||
}
|
||||
let p = project(&v);
|
||||
for f in ["bestand", "abbruch", "neubau", "umbauplan", "endzustand", "", "gibts-nicht"] {
|
||||
let prims = drawings_with(&p, json!({"renovation": f, "renovationPhase": "etappe-x"}));
|
||||
assert!(prims.iter().all(|q| !matches!(q, Primitive::Line { a, .. } if a.x.is_nan() || a.y.is_nan())), "{f}");
|
||||
}
|
||||
// Ein unbekannter Status gilt als Bestand: im Bestandsplan steht M1.
|
||||
assert!(!drawing_lines(&drawings_with(&p, json!({"renovation": "bestand"})), "M1").is_empty());
|
||||
}
|
||||
|
||||
fn tree_lines_at(prims: &[Primitive], x: f64) -> Vec<(String, bool)> {
|
||||
prims
|
||||
.iter()
|
||||
.filter_map(|q| match q {
|
||||
Primitive::Line { a, cls, color, dash, .. } if &**cls == "tree-crown" && (a.x - x).abs() < 1.6 && (a.y - 2.0).abs() < 1.6 => {
|
||||
Some((color.as_ref().map(|c| c.to_string()).unwrap_or_default(), matches!(dash, Some(Some(_)))))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn baeume_folgen_dem_umbau_status() {
|
||||
let p = project(&fixture());
|
||||
// Der Bestand des Baums ([149]) IST der Umbau-Status: bestehend = Bestand, zu fällen = Abbruch, neu = Neu.
|
||||
let t = |s: &str| tree_renovation(&Tree { status: serde_json::from_value(json!(s)).unwrap(), ..Default::default() }).status;
|
||||
assert_eq!((t("existing"), t("remove"), t("new"), t("unbekannt")), (RenovationStatus::Existing, RenovationStatus::Demolish, RenovationStatus::New, RenovationStatus::Existing));
|
||||
let trees = |extra: Value| {
|
||||
let d = trees_with(&p, extra);
|
||||
[8.0, 12.0, 16.0].map(|x| tree_lines_at(&d, x))
|
||||
};
|
||||
// Ohne Filter: alle drei.
|
||||
assert!(trees(json!({})).iter().all(|l| !l.is_empty()));
|
||||
// Bestand: der neue Baum fehlt, der zu fällende steht noch. Endzustand: der zu fällende fehlt.
|
||||
let b = trees(json!({"renovation": "bestand"}));
|
||||
assert!(!b[0].is_empty() && !b[1].is_empty() && b[2].is_empty(), "{:?}", b.iter().map(|l| l.len()).collect::<Vec<_>>());
|
||||
let e = trees(json!({"renovation": "endzustand"}));
|
||||
assert!(!e[0].is_empty() && e[1].is_empty() && !e[2].is_empty());
|
||||
// Umbauplan: grau / gelb gestrichelt / rot.
|
||||
let u = trees(json!({"renovation": "umbauplan"}));
|
||||
assert!(u[0].iter().all(|(c, d)| *c == default_style(RenovationStatus::Existing).fill && !d), "{:?}", u[0]);
|
||||
assert!(u[1].iter().any(|(_, d)| *d) && u[1].iter().any(|(c, _)| *c == default_style(RenovationStatus::Demolish).fill), "{:?}", u[1]);
|
||||
assert!(u[2].iter().all(|(c, _)| *c == default_style(RenovationStatus::New).line.unwrap()), "{:?}", u[2]);
|
||||
// Projekt im Zustand: der zu fällende Baum fehlt im Endzustand (Schnitt, Ansicht, 3D), der neue im Bestand.
|
||||
let ids = |q: &Project| q.trees.iter().flatten().map(|t| t.id.clone()).collect::<Vec<_>>();
|
||||
assert_eq!(ids(&project_in_state(&p, Some("endzustand"), None)), vec!["T1", "T3"]);
|
||||
assert_eq!(ids(&project_in_state(&p, Some("bestand"), None)), vec!["T1", "T2"]);
|
||||
}
|
||||
|
||||
fn section_q(p: &Project, extra: Value) -> Vec<Primitive> {
|
||||
let level = p.drawing_levels.iter().find(|l| l.id == "schnitt-q").unwrap();
|
||||
let mut v = json!({"level": level, "scale": 50, "detail": "mittel"});
|
||||
for (k, x) in extra.as_object().unwrap() {
|
||||
v[k] = x.clone();
|
||||
}
|
||||
let buf = crate::queries::run_bin(p, "sectionPlan", &[0.0, 1.0, 0.0], &v.to_string()).unwrap();
|
||||
crate::plan::buf::View::parse(&buf).and_then(|v| v.prims()).unwrap_or_default()
|
||||
}
|
||||
|
||||
fn elevation_of(p: &Project, level: &str, extra: Value) -> Vec<Primitive> {
|
||||
let level = p.drawing_levels.iter().find(|l| l.id == level).unwrap();
|
||||
let mut v = json!({"level": level});
|
||||
for (k, x) in extra.as_object().unwrap() {
|
||||
v[k] = x.clone();
|
||||
}
|
||||
let buf = crate::queries::run_bin(p, "elevationPlan", &[0.0, 0.0, 100.0], &v.to_string()).unwrap();
|
||||
crate::plan::buf::View::parse(&buf).and_then(|v| v.prims()).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Flächen eines Ersatzstücks: Polygone der Öffnung `id` mit dieser Füllung.
|
||||
fn patch_polys<'a>(prims: &'a [Primitive], id: &str, fill: &str) -> Vec<&'a Vec<Vec2>> {
|
||||
prims
|
||||
.iter()
|
||||
.filter_map(|q| match q {
|
||||
Primitive::Polygon { pts, fill: f, opening_id: Some(o), .. } if o == id && f == fill => Some(pts),
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn bbox(pts: &[Vec2]) -> [f64; 4] {
|
||||
pts.iter().fold([f64::INFINITY, f64::INFINITY, f64::NEG_INFINITY, f64::NEG_INFINITY], |b, q| [b[0].min(q.x), b[1].min(q.y), b[2].max(q.x), b[3].max(q.y)])
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn schnitt_zeigt_abbruch_stueck_und_ausfachung() {
|
||||
let p = project(&fixture());
|
||||
let (yellow, red) = (default_style(RenovationStatus::Demolish).fill, default_style(RenovationStatus::New).fill);
|
||||
// Umbauplan: neue Öffnung O1 in Bestandswand W1 = gelbes Abbruch-Stück, zugemauerte O2 in W3 = rote Ausfachung.
|
||||
let u = section_q(&p, json!({"renovation": "umbauplan"}));
|
||||
let o1 = patch_polys(&u, "O1", &yellow);
|
||||
let o2 = patch_polys(&u, "O2", &red);
|
||||
assert_eq!((o1.len(), o2.len()), (1, 1));
|
||||
// Lage: Brüstung 0.9 bis Sturz 2.1 (O1) bzw. 2.2 (O2), Breite = Wanddicke 0.345.
|
||||
let b1 = bbox(o1[0]);
|
||||
assert!((b1[1] - 0.9).abs() < 1e-6 && (b1[3] - 2.1).abs() < 1e-6, "{b1:?}");
|
||||
assert!((b1[2] - b1[0] - 0.345).abs() < 1e-3, "{b1:?}");
|
||||
let b2 = bbox(o2[0]);
|
||||
assert!((b2[1] - 0.9).abs() < 1e-6 && (b2[3] - 2.2).abs() < 1e-6, "{b2:?}");
|
||||
// Abbruch gestrichelt umrandet, Ausfachung nicht.
|
||||
assert!(u.iter().any(|q| matches!(q, Primitive::Line { dash: Some(Some(_)), opening_id: Some(o), .. } if o == "O1")));
|
||||
assert!(!u.iter().any(|q| matches!(q, Primitive::Line { dash: Some(Some(_)), opening_id: Some(o), .. } if o == "O2")));
|
||||
// Abbruchplan: O1 fehlt (Wand zu), das gelbe Stück liegt über der Wand; O2 steht.
|
||||
let a = section_q(&p, json!({"renovation": "abbruch"}));
|
||||
assert_eq!(patch_polys(&a, "O1", &yellow).len(), 1);
|
||||
assert!(patch_polys(&a, "O2", &red).is_empty());
|
||||
// Neubauplan: O2 zugemauert, rote Ausfachung über der geschlossenen Wand; kein Abbruch-Stück.
|
||||
let n = section_q(&p, json!({"renovation": "neubau"}));
|
||||
assert_eq!(patch_polys(&n, "O2", &red).len(), 1);
|
||||
assert!(patch_polys(&n, "O1", &yellow).is_empty());
|
||||
// Bestand, Endzustand und ohne Filter: keine Ersatzstücke.
|
||||
for f in [json!({"renovation": "bestand"}), json!({"renovation": "endzustand"}), json!({})] {
|
||||
let q = section_q(&p, f.clone());
|
||||
assert!(patch_polys(&q, "O1", &yellow).is_empty() && patch_polys(&q, "O2", &red).is_empty(), "{f}");
|
||||
}
|
||||
// Der Filter der Ebene wirkt ohne Argument.
|
||||
let mut v = fixture();
|
||||
for l in v["drawingLevels"].as_array_mut().unwrap() {
|
||||
if l["id"] == "schnitt-q" {
|
||||
l["renovationFilter"] = json!("umbauplan");
|
||||
}
|
||||
}
|
||||
assert_eq!(patch_polys(§ion_q(&project(&v), json!({})), "O1", &yellow).len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn schnitt_ersatzstueck_ohne_treffer_und_unsinn() {
|
||||
let yellow = default_style(RenovationStatus::Demolish).fill;
|
||||
// Schnitt A (y = 2) trifft O1/O2 nicht: kein Stück, kein Fehler.
|
||||
let p = project(&fixture());
|
||||
assert!(patch_polys(§ion_prims(&p, json!({"renovation": "umbauplan"})), "O1", &yellow).is_empty());
|
||||
// Schnittlinie entartet (beide Punkte gleich) bzw. parallel zur Wand: nichts, kein Panic.
|
||||
for pts in [json!([{"x": 3.5, "y": 1}, {"x": 3.5, "y": 1}]), json!([{"x": 0, "y": 0.001}, {"x": 5, "y": 0.001}])] {
|
||||
let mut v = fixture();
|
||||
for l in v["drawingLevels"].as_array_mut().unwrap() {
|
||||
if l["id"] == "schnitt-q" {
|
||||
l["linePoints"] = pts.clone();
|
||||
}
|
||||
}
|
||||
let q = section_q(&project(&v), json!({"renovation": "umbauplan"}));
|
||||
assert!(patch_polys(&q, "O1", &yellow).is_empty());
|
||||
}
|
||||
// Öffnung ohne Breite: kein Stück.
|
||||
let mut v = fixture();
|
||||
for o in v["openings"].as_array_mut().unwrap() {
|
||||
if o["id"] == "O1" {
|
||||
o["width"] = json!(0);
|
||||
}
|
||||
}
|
||||
assert!(patch_polys(§ion_q(&project(&v), json!({"renovation": "umbauplan"})), "O1", &yellow).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn schnitt_projektionslinien_in_umbau_farbe() {
|
||||
let p = project(&fixture());
|
||||
let red = default_style(RenovationStatus::New).line.unwrap();
|
||||
// Linien hinter der Schnittebene: W9 (neu, x = 2.4) bzw. W2 (Abbruch, x = 5), je nach Blickrichtung.
|
||||
let count = |v: &[Primitive]| {
|
||||
let vis = |q: &&Primitive| matches!(q, Primitive::Line { cls, .. } if &**cls == "section-visible");
|
||||
let red_n = v.iter().filter(vis).filter(|q| matches!(q, Primitive::Line { color: Some(c), .. } if **c == *red)).count();
|
||||
let dash_n = v.iter().filter(vis).filter(|q| matches!(q, Primitive::Line { dash: Some(Some(_)), .. })).count();
|
||||
(red_n, dash_n)
|
||||
};
|
||||
assert_eq!(count(§ion_q(&p, json!({}))), (0, 0), "ohne Filter keine Umbau-Linien");
|
||||
let u = count(§ion_q(&p, json!({"renovation": "umbauplan"})));
|
||||
assert!(u.0 + u.1 > 0, "Projektion in Umbau-Farbe: {u:?}");
|
||||
// Im Endzustand ohne Farbe.
|
||||
assert_eq!(count(§ion_q(&p, json!({"renovation": "endzustand"}))), (0, 0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ansicht_ersatzstuecke_und_oeffnungen_in_umbau_farbe() {
|
||||
let p = project(&fixture());
|
||||
let (yellow, red) = (default_style(RenovationStatus::Demolish).fill, default_style(RenovationStatus::New).fill);
|
||||
let red_line = default_style(RenovationStatus::New).line.unwrap();
|
||||
// Ansicht Süd, Umbauplan: O1 (neu) als rotes Fenster, darunter das gelbe Abbruch-Stück (gestrichelt umrandet).
|
||||
let u = elevation_of(&p, "ansicht-sued", json!({"renovation": "umbauplan"}));
|
||||
assert_eq!(patch_polys(&u, "O1", &yellow).len(), 1);
|
||||
assert!(u.iter().any(|q| matches!(q, Primitive::Line { dash: Some(Some(_)), opening_id: Some(o), .. } if o == "O1")));
|
||||
assert!(u.iter().any(|q| matches!(q, Primitive::Polygon { stroke, opening_id: Some(o), .. } if o == "O1" && *stroke == red_line)), "Fensterlinien rot");
|
||||
// Das Stück liegt auf der Öffnung: Breite 1.0, Höhe 1.2.
|
||||
let b = bbox(patch_polys(&u, "O1", &yellow)[0]);
|
||||
assert!((b[2] - b[0] - 1.0).abs() < 1e-3 && (b[3] - b[1] - 1.2).abs() < 1e-3, "{b:?}");
|
||||
// Abbruchplan: die Öffnung fehlt (Wand zu), das gelbe Stück liegt auf der Fassade.
|
||||
let a = elevation_of(&p, "ansicht-sued", json!({"renovation": "abbruch"}));
|
||||
assert_eq!(patch_polys(&a, "O1", &yellow).len(), 1);
|
||||
// Bestand, Endzustand, ohne Filter: kein Ersatzstück.
|
||||
for f in [json!({"renovation": "bestand"}), json!({"renovation": "endzustand"}), json!({})] {
|
||||
assert!(patch_polys(&elevation_of(&p, "ansicht-sued", f.clone()), "O1", &yellow).is_empty(), "{f}");
|
||||
}
|
||||
// Ansicht Nord: die zugemauerte O2 in W3 trägt im Neubauplan die rote Ausfachung.
|
||||
let n = elevation_of(&p, "ansicht-nord", json!({"renovation": "neubau"}));
|
||||
assert_eq!(patch_polys(&n, "O2", &red).len(), 1, "Ausfachung O2");
|
||||
// Von Süden liegt W3 hinter W1: kein Stück (verdeckt).
|
||||
assert!(patch_polys(&elevation_of(&p, "ansicht-sued", json!({"renovation": "neubau"})), "O2", &red).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zeichen_status_fuer_baeume_und_zeichnungen() {
|
||||
use crate::ops::Op;
|
||||
let line = json!({"id": "l", "geom": {"shape": "line"}});
|
||||
let dim = json!({"id": "d", "geom": {"shape": "dimension"}});
|
||||
let lib = json!({"id": "m", "geom": {"shape": "libobj"}});
|
||||
let tree = json!({"id": "t", "status": "existing"});
|
||||
let tree_own = json!({"id": "t2", "status": "remove"});
|
||||
let add = |c: &str, items: Vec<Value>| Op::Add { collection: c.into(), items, at: None };
|
||||
let out = crate::commands::stamp_renovation(vec![add("drawings2d", vec![line, dim, lib]), add("trees", vec![tree.clone(), tree_own])], Some(&json!({"status": "new"})));
|
||||
match &out[0] {
|
||||
Op::Add { items, .. } => {
|
||||
assert_eq!(items[0]["renovation"], json!({"status": "new"}));
|
||||
assert!(items[1].get("renovation").is_none(), "Masse sind keine Bauteile");
|
||||
assert_eq!(items[2]["renovation"], json!({"status": "new"}));
|
||||
}
|
||||
_ => panic!(),
|
||||
}
|
||||
// Bäume: der Status des Baums ist der Umbau-Status; eine eigene Angabe bleibt.
|
||||
match &out[1] {
|
||||
Op::Add { items, .. } => assert_eq!((items[0]["status"].as_str(), items[1]["status"].as_str()), (Some("new"), Some("remove"))),
|
||||
_ => panic!(),
|
||||
}
|
||||
let out = crate::commands::stamp_renovation(vec![add("trees", vec![tree])], Some(&json!({"status": "demolish"})));
|
||||
assert!(matches!(&out[0], Op::Add { items, .. } if items[0]["status"] == "remove"));
|
||||
}
|
||||
|
||||
/// Bäume (Pick-Id `tree:<id>`) in einer Schnitt-/Ansichts-Ausgabe.
|
||||
fn trees_in(prims: &[Primitive]) -> std::collections::BTreeSet<String> {
|
||||
prims
|
||||
.iter()
|
||||
.filter_map(|q| match q {
|
||||
Primitive::Polygon { context_object_id: Some(c), .. } => c.strip_prefix(crate::tree::TREE_PICK_PREFIX).map(String::from),
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn baeume_in_schnitt_und_ansicht_folgen_dem_filter() {
|
||||
let p = project(&fixture());
|
||||
let set = |v: &[&str]| v.iter().map(|s| s.to_string()).collect::<std::collections::BTreeSet<_>>();
|
||||
// Schnitt Q blickt nach Osten (x = 3.5, Richtung −1): alle drei Bäume stehen dahinter; Ansicht Süd blickt nach Norden.
|
||||
let all = trees_in(§ion_q(&p, json!({})));
|
||||
assert_eq!(all, set(&["T1", "T2", "T3"]), "ohne Filter alle");
|
||||
assert_eq!(trees_in(§ion_q(&p, json!({"renovation": "bestand"}))), set(&["T1", "T2"]));
|
||||
assert_eq!(trees_in(§ion_q(&p, json!({"renovation": "abbruch"}))), set(&["T1", "T2"]));
|
||||
assert_eq!(trees_in(§ion_q(&p, json!({"renovation": "endzustand"}))), set(&["T1", "T3"]));
|
||||
assert_eq!(trees_in(§ion_q(&p, json!({"renovation": "neubau"}))), set(&["T1", "T3"]));
|
||||
let south = |f: Value| trees_in(&elevation_of(&p, "ansicht-sued", f));
|
||||
assert_eq!(south(json!({"renovation": "bestand"})), set(&["T1", "T2"]));
|
||||
assert_eq!(south(json!({"renovation": "endzustand"})), set(&["T1", "T3"]));
|
||||
// Umbauplan: der zu fällende Baum gelb gestrichelt, der neue rot (Linienfarbe), der bestehende grau.
|
||||
let u = section_q(&p, json!({"renovation": "umbauplan"}));
|
||||
let stroke_of = |id: &str| -> Vec<String> {
|
||||
u.iter()
|
||||
.filter_map(|q| match q {
|
||||
Primitive::Polygon { stroke, context_object_id: Some(c), .. } if c.strip_prefix(crate::tree::TREE_PICK_PREFIX) == Some(id) && stroke != "none" => Some(stroke.clone()),
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
};
|
||||
assert!(!stroke_of("T3").is_empty() && stroke_of("T3").iter().all(|c| *c == default_style(RenovationStatus::New).line.unwrap()), "{:?}", stroke_of("T3"));
|
||||
assert!(stroke_of("T1").iter().all(|c| *c == default_style(RenovationStatus::Existing).fill), "{:?}", stroke_of("T1"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bogenwand_traegt_ersatzstueck_in_allen_drei_zeichnungen() {
|
||||
// W1 als flacher Bogen (Bulge): O1 (neu) bleibt eine Öffnung in einer Bestandswand.
|
||||
let mut v = fixture();
|
||||
for w in v["walls"].as_array_mut().unwrap() {
|
||||
if w["id"] == "W1" {
|
||||
w["bulge"] = json!(0.15);
|
||||
}
|
||||
}
|
||||
let p = project(&v);
|
||||
let yellow = default_style(RenovationStatus::Demolish).fill;
|
||||
// Grundriss (Abbruchplan: die Öffnung fehlt, das Stück liegt über der Wand): ein endliches Ringstück mit Fläche.
|
||||
let walls = plan_domains(&p, &PlanArgs::parse_in(&p, 1.0, &plan_args(&json!({"renovation": "abbruch"}))).unwrap()).unwrap().walls;
|
||||
let rings = patch_polys(&walls, "O1", &yellow);
|
||||
assert_eq!(rings.len(), 1, "Grundriss");
|
||||
let b = bbox(rings[0]);
|
||||
assert!(b.iter().all(|x| x.is_finite()) && b[2] - b[0] > 0.5 && b[3] - b[1] > 0.3, "{b:?}");
|
||||
// Schnitt und Ansicht: die Sehne der Öffnung wie beim Einbauteil selbst.
|
||||
assert_eq!(patch_polys(§ion_q(&p, json!({"renovation": "umbauplan"})), "O1", &yellow).len(), 1);
|
||||
assert_eq!(patch_polys(&elevation_of(&p, "ansicht-sued", json!({"renovation": "umbauplan"})), "O1", &yellow).len(), 1);
|
||||
}
|
||||
Reference in new issue
Block a user