Merge [275] Umbau-Farben: Farbe oder Stift, gedämpfte Vorgabe, eigene Farben je Etappe
This commit is contained in:
40 files changed
+955
-143
No files matched your search
@@ -66,7 +66,7 @@ fn cycles_umbaufarben_nur_auf_wunsch() {
|
||||
mit_opts["renovationColors"] = json!(true);
|
||||
let mit = scene(&p, &mit_opts.to_string());
|
||||
let xml = mit["xml"].as_str().unwrap();
|
||||
assert!(xml.contains("Umbau-ffd800"), "Abbruch gelb");
|
||||
assert!(xml.contains(&format!("Umbau-{}", &crate::renovation::DEMOLISH_FILL[1..])), "Abbruch gelb");
|
||||
// Geometrie bleibt gleich.
|
||||
assert_eq!(ohne["triangles"], mit["triangles"]);
|
||||
// Ohne Filter keine Farben, auch mit dem Schalter.
|
||||
|
||||
@@ -3049,6 +3049,11 @@ pub enum LayerRenovation {
|
||||
pub struct RenovationPhase {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
/// [275] Eigene Umbau-Farben der Etappe (Neu/Abbruch dieser Etappe, z. B. Neubau Etappe 2 blau); fehlende Felder
|
||||
/// ⇒ die Farben des Projekts (`RenovationSettings.styles`), dann die SIA-Vorgabe.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub styles: Option<RenovationStyles>,
|
||||
#[serde(flatten)]
|
||||
#[ts(skip)]
|
||||
pub extra: Extra,
|
||||
@@ -3073,15 +3078,25 @@ pub enum RenovationShow {
|
||||
}
|
||||
|
||||
/// [271] Umbau-Farbe eines Status: Füllung der Schnittflächen, Linienfarbe, gestrichelt. Fehlende Felder ⇒ SIA-Vorgabe.
|
||||
/// [275] Statt einer freien Farbe ein Stift (`ColorPen.id`): seine Farbe aus dem aktiven Stiftsatz geht der freien
|
||||
/// Farbe vor (ein S/W-Plot-Stiftsatz färbt so auch die Umbau-Farben um; Stift ohne Eintrag ⇒ freie Farbe/Vorgabe).
|
||||
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize, TS)]
|
||||
#[serde(default)]
|
||||
pub struct RenovationStyle {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub fill: Option<String>,
|
||||
/// [275] Stift der Füllung.
|
||||
#[serde(rename = "fillPen", default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub fill_pen: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub line: Option<String>,
|
||||
/// [275] Stift der Linien.
|
||||
#[serde(rename = "linePen", default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub line_pen: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub dashed: Option<bool>,
|
||||
|
||||
@@ -137,6 +137,16 @@ pub fn dangling_refs(p: &Project) -> Vec<String> {
|
||||
for c in p.flat_categories() {
|
||||
check_pens(&mut out, &pens, "Kategorie", &c.code, [&c.color_pen_id, &none, &none]);
|
||||
}
|
||||
// [275] Stifte der Umbau-Farben (Projekt und Etappen).
|
||||
if let Some(r) = &p.renovation {
|
||||
let phases = r.phases.as_deref().unwrap_or(&[]);
|
||||
let sets = std::iter::once(("Projekt", p.id.as_str(), r.styles.as_ref())).chain(phases.iter().map(|x| ("Etappe", x.id.as_str(), x.styles.as_ref())));
|
||||
for (what, owner, st) in sets {
|
||||
for s in st.into_iter().flat_map(|s| [&s.existing, &s.demolish, &s.new]).flatten() {
|
||||
check_pens(&mut out, &pens, what, owner, [&s.fill_pen, &s.line_pen, &none]);
|
||||
}
|
||||
}
|
||||
}
|
||||
let pen_sets = ids(p.pen_sets.as_deref().unwrap_or(&[]), |s| s.id.as_str());
|
||||
miss(&mut out, "Projekt", &p.id, "Stiftsatz", p.active_pen_set_id.as_deref().unwrap_or(""), &pen_sets);
|
||||
for l in p.layouts.as_deref().unwrap_or(&[]) {
|
||||
|
||||
@@ -91,6 +91,8 @@ pub fn run(p: &Project, name: &str, args: &[f64], text: &str) -> Result<String,
|
||||
("areaTable", _) => json(&flaechen::area_table(&renovation_state(p, text))),
|
||||
// [271] Umbaufilter (eingebaute und eigene) für die Oberfläche.
|
||||
("renovationFilters", _) => json(&crate::renovation::filter_list(p)),
|
||||
// [275] Aufgelöste Umbau-Farben (Vorgabe, Projekt, Etappen) für Muster in der Oberfläche.
|
||||
("renovationStyles", _) => Ok(crate::renovation::styles_json(p).to_string()),
|
||||
// [274] Typ-Paar Bestand → Sanierungstyp (Editor, Vorschau) bzw. alle Paare mit Zählern (Umbau-Panel).
|
||||
("renovationPair", _) => json(&crate::renovation::build_up::pair_json(p, text)),
|
||||
("renovationPairs", _) => json(&crate::renovation::build_up::pairs_json(p)),
|
||||
|
||||
@@ -147,37 +147,105 @@ pub fn ghost_style() -> Style {
|
||||
Style { fill: "#e3e3e3".into(), line: Some("#a8a8a8".into()), dashed: false, ghost: true }
|
||||
}
|
||||
|
||||
/// SIA-400-Vorgabe: Bestand grau, Abbruch gelb und gestrichelt, Neu rot.
|
||||
/// [275] Vorgabe Bestand: mittleres Grau (SIA 400).
|
||||
pub const EXISTING_FILL: &str = "#a6a6a6";
|
||||
/// [275] Vorgabe Abbruch: ruhiges Ocker-Gelb statt Signalgelb (#ffd800, Wunsch Maintainer 17.11.: „weniger leuchtend“) —
|
||||
/// auf weissem Papier noch klar gelb, neben dem Grau des Bestands unterscheidbar, im dunklen Thema nicht grell.
|
||||
pub const DEMOLISH_FILL: &str = "#e8c35a";
|
||||
/// [275] Vorgabe Neu: gedämpftes Ziegelrot statt Signalrot (#e3001b), Linie eine Stufe dunkler.
|
||||
pub const NEW_FILL: &str = "#c8524a";
|
||||
pub const NEW_LINE: &str = "#9e3a33";
|
||||
|
||||
/// SIA-400-Vorgabe: Bestand grau, Abbruch gelb und gestrichelt, Neu rot ([275] gedämpfte Töne).
|
||||
pub fn default_style(s: RenovationStatus) -> Style {
|
||||
match s {
|
||||
RenovationStatus::Demolish => Style { fill: "#ffd800".into(), line: None, dashed: true, ghost: false },
|
||||
RenovationStatus::New => Style { fill: "#e3001b".into(), line: Some("#c00016".into()), dashed: false, ghost: false },
|
||||
_ => Style { fill: "#a6a6a6".into(), line: None, dashed: false, ghost: false },
|
||||
RenovationStatus::Demolish => Style { fill: DEMOLISH_FILL.into(), line: None, dashed: true, ghost: false },
|
||||
RenovationStatus::New => Style { fill: NEW_FILL.into(), line: Some(NEW_LINE.into()), dashed: false, ghost: false },
|
||||
_ => Style { fill: EXISTING_FILL.into(), line: None, dashed: false, ghost: false },
|
||||
}
|
||||
}
|
||||
|
||||
/// [275] Farbe eines Stifts (`ColorPen.id`) im aktiven Stiftsatz; `None` ohne aktiven Satz oder Eintrag (dann gilt die
|
||||
/// freie Farbe bzw. die Vorgabe — anders als bei Bauteilen kein Ersatz-Grau, damit ein Umbau-Plan nie grau wird).
|
||||
fn pen_color(p: &Project, pen: &str) -> Option<String> {
|
||||
let pen = pen.trim();
|
||||
if pen.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let active = p.active_pen_set_id.as_deref()?;
|
||||
let set = p.pen_sets.as_deref()?.iter().find(|s| s.id == active)?;
|
||||
let c = set.pens.get(pen)?.color.trim();
|
||||
(!c.is_empty()).then(|| c.to_string())
|
||||
}
|
||||
|
||||
fn pick(x: &RenovationStyles, s: RenovationStatus) -> Option<&RenovationStyle> {
|
||||
match s {
|
||||
RenovationStatus::Demolish => x.demolish.as_ref(),
|
||||
RenovationStatus::New => x.new.as_ref(),
|
||||
_ => x.existing.as_ref(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Eigene Angaben `o` über `st` legen: Stift vor freier Farbe, fehlende Felder lassen `st` stehen.
|
||||
fn apply_own(p: &Project, st: &mut Style, o: &RenovationStyle) {
|
||||
let free = |v: &Option<String>| v.as_deref().map(str::trim).filter(|f| !f.is_empty()).map(str::to_string);
|
||||
if let Some(f) = o.fill_pen.as_deref().and_then(|x| pen_color(p, x)).or_else(|| free(&o.fill)) {
|
||||
st.fill = f;
|
||||
}
|
||||
if let Some(l) = o.line_pen.as_deref().and_then(|x| pen_color(p, x)) {
|
||||
st.line = Some(l);
|
||||
} else if let Some(l) = o.line.as_deref().map(str::trim) {
|
||||
st.line = (!l.is_empty()).then(|| l.to_string());
|
||||
}
|
||||
if let Some(d) = o.dashed {
|
||||
st.dashed = d;
|
||||
}
|
||||
}
|
||||
|
||||
/// Umbau-Farbe eines Status im Projekt.
|
||||
pub fn style(p: &Project, s: RenovationStatus) -> Style {
|
||||
let mut st = default_style(s);
|
||||
let own = p.renovation.as_ref().and_then(|r| r.styles.as_ref()).and_then(|x| match s {
|
||||
RenovationStatus::Demolish => x.demolish.as_ref(),
|
||||
RenovationStatus::New => x.new.as_ref(),
|
||||
_ => x.existing.as_ref(),
|
||||
});
|
||||
if let Some(o) = own {
|
||||
if let Some(f) = o.fill.as_deref().map(str::trim).filter(|f| !f.is_empty()) {
|
||||
st.fill = f.to_string();
|
||||
}
|
||||
if let Some(l) = o.line.as_deref().map(str::trim) {
|
||||
st.line = (!l.is_empty()).then(|| l.to_string());
|
||||
}
|
||||
if let Some(d) = o.dashed {
|
||||
st.dashed = d;
|
||||
}
|
||||
if let Some(o) = p.renovation.as_ref().and_then(|r| r.styles.as_ref()).and_then(|x| pick(x, s)) {
|
||||
apply_own(p, &mut st, o);
|
||||
}
|
||||
st
|
||||
}
|
||||
|
||||
/// [275] Umbau-Farbe eines Status für Elemente der Etappe `ph`: deren eigene Angaben über der Projektfarbe;
|
||||
/// `None`, wenn die Etappe für diesen Status nichts Eigenes hat.
|
||||
pub fn phase_style(p: &Project, s: RenovationStatus, ph: &RenovationPhase) -> Option<Style> {
|
||||
let o = ph.styles.as_ref().and_then(|x| pick(x, s))?;
|
||||
let mut st = style(p, s);
|
||||
apply_own(p, &mut st, o);
|
||||
Some(st)
|
||||
}
|
||||
|
||||
const STATUSES: [RenovationStatus; 3] = [RenovationStatus::Existing, RenovationStatus::Demolish, RenovationStatus::New];
|
||||
|
||||
/// [275] Eigene Farben je Etappe (Index der Etappe → je Status), nur Etappen mit eigenen Angaben.
|
||||
fn phase_styles(p: &Project) -> HashMap<usize, [Option<Style>; 3]> {
|
||||
phases(p)
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(_, ph)| ph.styles.is_some())
|
||||
.map(|(i, ph)| (i, STATUSES.map(|s| phase_style(p, s, ph))))
|
||||
.filter(|(_, a)| a.iter().any(Option::is_some))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// [275] Aufgelöste Umbau-Farben für die Oberfläche (Abfrage `renovationStyles`): SIA-Vorgabe, Projekt und Etappen mit
|
||||
/// eigenen Angaben (Id → je Status), damit Muster im Panel/in der Legende genau die Farben des Plans zeigen.
|
||||
pub fn styles_json(p: &Project) -> serde_json::Value {
|
||||
use serde_json::{json, Map, Value};
|
||||
let one = |st: &Style| json!({"fill": st.fill, "line": st.line, "dashed": st.dashed});
|
||||
let set = |f: &dyn Fn(RenovationStatus) -> Style| json!({"existing": one(&f(STATUSES[0])), "demolish": one(&f(STATUSES[1])), "new": one(&f(STATUSES[2]))});
|
||||
let mut ph = Map::new();
|
||||
for x in phases(p).iter().filter(|x| x.styles.is_some()) {
|
||||
ph.insert(x.id.clone(), set(&|s| phase_style(p, s, x).unwrap_or_else(|| style(p, s))));
|
||||
}
|
||||
json!({"defaults": set(&default_style), "project": set(&|s| style(p, s)), "phases": Value::Object(ph)})
|
||||
}
|
||||
|
||||
/// Wie ein Element im Filter erscheint.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum Treat {
|
||||
@@ -199,6 +267,8 @@ pub struct View {
|
||||
pub edit: Option<crate::design_options::Edit>,
|
||||
phases: HashMap<String, usize>,
|
||||
styles: [Style; 3],
|
||||
/// [275] Eigene Farben je Etappe (Index → je Status).
|
||||
phase_styles: HashMap<usize, [Option<Style>; 3]>,
|
||||
}
|
||||
|
||||
impl View {
|
||||
@@ -226,7 +296,7 @@ impl View {
|
||||
let upto = if filter.is_some() { phase.filter(|s| !s.trim().is_empty()).and_then(|s| phase_index(p, s)) } else { None };
|
||||
let phases = phases(p).iter().enumerate().map(|(i, x)| (x.id.clone(), i)).collect();
|
||||
let styles = [style(p, RenovationStatus::Existing), style(p, RenovationStatus::Demolish), style(p, RenovationStatus::New)];
|
||||
Some(View { filter, options, upto, phases, styles, edit: None })
|
||||
Some(View { filter, options, upto, phases, styles, phase_styles: phase_styles(p), edit: None })
|
||||
}
|
||||
|
||||
/// [272] Mit Bearbeitungsvariante (Stift, nur Bildschirm-Anfragen `designOptionEdit`): die Variante ist sichtbar (geht
|
||||
@@ -236,7 +306,7 @@ impl View {
|
||||
let Some(e) = edit else { return v };
|
||||
let mut v = v.unwrap_or_else(|| {
|
||||
let styles = [style(p, RenovationStatus::Existing), style(p, RenovationStatus::Demolish), style(p, RenovationStatus::New)];
|
||||
View { filter: None, options: None, upto: None, phases: HashMap::new(), styles, edit: None }
|
||||
View { filter: None, options: None, upto: None, phases: HashMap::new(), styles, phase_styles: HashMap::new(), edit: None }
|
||||
});
|
||||
let c = v.options.get_or_insert_with(|| crate::design_options::Combination::primary(p));
|
||||
c.choice.insert(e.set.clone(), e.option.clone());
|
||||
@@ -268,8 +338,13 @@ impl View {
|
||||
}
|
||||
}
|
||||
|
||||
/// Darstellung eines Zustands im Filter.
|
||||
/// Darstellung eines Zustands im Filter (mit den Farben des Projekts).
|
||||
pub fn treat_state(&self, s: Option<RenovationStatus>) -> Treat {
|
||||
self.treat_in(s, None)
|
||||
}
|
||||
|
||||
/// Darstellung eines Zustands, mit den Farben der Etappe `phase` (Index), sofern sie eigene hat.
|
||||
fn treat_in(&self, s: Option<RenovationStatus>, phase: Option<usize>) -> Treat {
|
||||
let Some(s) = s else { return Treat::Hide };
|
||||
let Some(filter) = &self.filter else { return Treat::Show };
|
||||
let (show, k) = match s {
|
||||
@@ -279,14 +354,20 @@ impl View {
|
||||
};
|
||||
match show {
|
||||
RenovationShow::Hide => Treat::Hide,
|
||||
RenovationShow::Override => Treat::Style(self.styles[k].clone()),
|
||||
RenovationShow::Override => {
|
||||
let own = phase.and_then(|i| self.phase_styles.get(&i)).and_then(|a| a[k].as_ref());
|
||||
Treat::Style(own.unwrap_or(&self.styles[k]).clone())
|
||||
}
|
||||
_ => Treat::Show,
|
||||
}
|
||||
}
|
||||
|
||||
/// Darstellung eines Elements mit diesen Umbau-Angaben.
|
||||
/// Darstellung eines Elements mit diesen Umbau-Angaben. [275] Zeigt es noch seinen eigenen Status (nicht schon als
|
||||
/// Bestand einer späteren Etappe), gelten die eigenen Farben seiner Etappe.
|
||||
pub fn treat(&self, r: Option<&Renovation>) -> Treat {
|
||||
self.treat_state(self.state(r))
|
||||
let s = self.state(r);
|
||||
let own = if s == Some(status_of(r)) { r.and_then(|r| r.phase.as_deref()).and_then(|id| self.phases.get(id).copied()) } else { None };
|
||||
self.treat_in(s, own)
|
||||
}
|
||||
|
||||
/// Ist ein Element mit diesen Angaben im Filter sichtbar?
|
||||
@@ -353,7 +434,7 @@ impl View {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
put(&w.id, self.treat_state(s), out);
|
||||
put(&w.id, self.treat(w.renovation.as_ref()), out);
|
||||
}
|
||||
for o in p.openings.iter().flatten() {
|
||||
let host = wall_state.get(o.host_wall_id.as_str()).copied().flatten();
|
||||
@@ -361,8 +442,9 @@ impl View {
|
||||
out.hidden.insert(o.id.clone());
|
||||
continue;
|
||||
}
|
||||
let s = self.state(opening_renovation(p, o));
|
||||
put(&o.id, self.treat_state(s), out);
|
||||
let r = opening_renovation(p, o);
|
||||
let s = self.state(r);
|
||||
put(&o.id, self.treat(r), out);
|
||||
// Ersatzstück nur, wenn die Öffnung einen anderen Zustand hat als ihre (Bestands-)Wand.
|
||||
if o.renovation.is_none() || host != Some(RenovationStatus::Existing) {
|
||||
continue;
|
||||
@@ -372,7 +454,8 @@ impl View {
|
||||
Some(RenovationStatus::Demolish) => RenovationStatus::New,
|
||||
_ => continue,
|
||||
};
|
||||
if let Treat::Style(st) = self.treat_state(Some(virt)) {
|
||||
// [275] Das Stück gehört zur Etappe der Öffnung (deren eigene Farben).
|
||||
if let Treat::Style(st) = self.treat(Some(&Renovation { status: virt, phase: r.and_then(|r| r.phase.clone()), ..Default::default() })) {
|
||||
out.patches.push(Patch { opening_id: o.id.clone(), wall_id: o.host_wall_id.clone(), status: virt, style: st, closed: out.hidden.contains(&o.id) });
|
||||
}
|
||||
}
|
||||
@@ -410,10 +493,13 @@ impl View {
|
||||
pub fn colors(&self) -> Vec<String> {
|
||||
let mut out = Vec::new();
|
||||
let Some(f) = &self.filter else { return out };
|
||||
for (show, st) in [(f.existing, &self.styles[0]), (f.demolish, &self.styles[1]), (f.new, &self.styles[2])] {
|
||||
for (k, show) in [f.existing, f.demolish, f.new].into_iter().enumerate() {
|
||||
if show == RenovationShow::Override {
|
||||
out.push(st.fill.clone());
|
||||
out.extend(st.line.clone());
|
||||
// [275] Dazu die eigenen Farben der Etappen.
|
||||
for st in std::iter::once(&self.styles[k]).chain(self.phase_styles.values().filter_map(|a| a[k].as_ref())) {
|
||||
out.push(st.fill.clone());
|
||||
out.extend(st.line.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
out
|
||||
@@ -424,7 +510,11 @@ impl View {
|
||||
let opts = self.options.as_ref().map_or(String::new(), |c| c.key());
|
||||
let edit = self.edit.as_ref().map_or(String::new(), |e| format!("|edit:{}", e.key()));
|
||||
match &self.filter {
|
||||
Some(f) => format!("{}:{:?}{:?}{:?}:{:?}:{:?}|{opts}{edit}", f.id, f.existing, f.demolish, f.new, self.upto, self.styles),
|
||||
Some(f) => {
|
||||
let mut ph: Vec<_> = self.phase_styles.iter().collect();
|
||||
ph.sort_by_key(|(i, _)| **i);
|
||||
format!("{}:{:?}{:?}{:?}:{:?}:{:?}{ph:?}|{opts}{edit}", f.id, f.existing, f.demolish, f.new, self.upto, self.styles)
|
||||
}
|
||||
None => format!("-|{opts}{edit}"),
|
||||
}
|
||||
}
|
||||
@@ -1188,8 +1278,8 @@ pub mod build_up {
|
||||
let (old, new, side, m) = pair(p, w)?;
|
||||
let phase = w.renovation.as_ref().and_then(|r| r.phase.clone());
|
||||
let virt = |status| Renovation { status, phase: phase.clone(), ..Default::default() };
|
||||
let td = v.treat_state(v.state(Some(&virt(RenovationStatus::Demolish))));
|
||||
let tn = v.treat_state(v.state(Some(&virt(RenovationStatus::New))));
|
||||
let td = v.treat(Some(&virt(RenovationStatus::Demolish)));
|
||||
let tn = v.treat(Some(&virt(RenovationStatus::New)));
|
||||
let tk = v.treat(w.renovation.as_ref());
|
||||
let shown = match (td != Treat::Hide, tn != Treat::Hide) {
|
||||
(true, false) => Shown::Old,
|
||||
@@ -1412,3 +1502,7 @@ mod tests2;
|
||||
#[cfg(test)]
|
||||
#[path = "renovation_layers_tests.rs"]
|
||||
mod layers_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "renovation_style_tests.rs"]
|
||||
mod style_tests;
|
||||
@@ -0,0 +1,142 @@
|
||||
//! [275] Umbau-Farben: gedämpfte Vorgabe, Stift statt Farbe (aktiver Stiftsatz), eigene Farben je Etappe.
|
||||
|
||||
use super::tests::{fills_of, plan_with, project, umbau_fixture};
|
||||
use super::*;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
/// Fixture mit zwei Stiftsätzen (Farbe und S/W) und Stiften 7 (Füllung) und 8 (Linie).
|
||||
fn with_pens(mut v: Value, active: &str) -> Value {
|
||||
v["pens"] = json!([{"id": "7", "name": "Umbau Neu"}, {"id": "8", "name": "Umbau Linie"}]);
|
||||
v["penSets"] = json!([
|
||||
{"id": "farbe", "name": "Farbe", "pens": {"7": {"color": "#3366cc", "weight": 0.25}, "8": {"color": "#112244", "weight": 0.35}}},
|
||||
{"id": "sw", "name": "Plot S/W", "pens": {"7": {"color": "#bbbbbb", "weight": 0.25}, "8": {"color": "#000000", "weight": 0.35}}}
|
||||
]);
|
||||
v["activePenSetId"] = json!(active);
|
||||
v
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gedaempfte_vorgabe() {
|
||||
// Abbruch ruhiges Ocker, Neu gedämpftes Ziegelrot mit dunklerer Linie, Bestand unverändert grau.
|
||||
let d = default_style(RenovationStatus::Demolish);
|
||||
let n = default_style(RenovationStatus::New);
|
||||
assert_eq!((d.fill.as_str(), d.line.as_deref(), d.dashed), (DEMOLISH_FILL, None, true));
|
||||
assert_eq!((n.fill.as_str(), n.line.as_deref(), n.dashed), (NEW_FILL, Some(NEW_LINE), false));
|
||||
assert_eq!(default_style(RenovationStatus::Existing).fill, "#a6a6a6");
|
||||
// Nicht mehr die leuchtenden Werte.
|
||||
for c in [&d.fill, &n.fill, n.line.as_ref().unwrap()] {
|
||||
assert!(!["#ffd800", "#e3001b", "#c00016"].contains(&c.as_str()), "{c}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stift_statt_farbe_folgt_dem_aktiven_stiftsatz() {
|
||||
let mut v = with_pens(umbau_fixture(), "farbe");
|
||||
v["renovation"]["styles"] = json!({"new": {"fill": "#ff00ff", "fillPen": "7", "linePen": "8"}});
|
||||
let p = project(&v);
|
||||
let s = style(&p, RenovationStatus::New);
|
||||
// Stift geht der freien Farbe vor.
|
||||
assert_eq!((s.fill.as_str(), s.line.as_deref()), ("#3366cc", Some("#112244")));
|
||||
// Anderer Stiftsatz aktiv: die Umbau-Farbe wechselt mit.
|
||||
let p = project(&with_pens(v.clone(), "sw"));
|
||||
let s = style(&p, RenovationStatus::New);
|
||||
assert_eq!((s.fill.as_str(), s.line.as_deref()), ("#bbbbbb", Some("#000000")));
|
||||
// Im Plan: W9 (Neu) in der Stift-Farbe.
|
||||
let u = plan_with(&p, json!({"renovation": "umbauplan"}));
|
||||
assert!(fills_of(&u, "W9").iter().any(|f| f == "#bbbbbb"), "{:?}", fills_of(&u, "W9"));
|
||||
// Stift ohne Eintrag im aktiven Satz bzw. ohne aktiven Satz: freie Farbe, sonst Vorgabe.
|
||||
let mut w = v.clone();
|
||||
w["activePenSetId"] = json!("fehlt");
|
||||
let p = project(&w);
|
||||
assert_eq!(style(&p, RenovationStatus::New).fill, "#ff00ff");
|
||||
assert_eq!(style(&p, RenovationStatus::New).line.as_deref(), Some(NEW_LINE));
|
||||
w["renovation"]["styles"]["new"] = json!({"fillPen": "99"});
|
||||
w["activePenSetId"] = json!("farbe");
|
||||
assert_eq!(style(&project(&w), RenovationStatus::New).fill, NEW_FILL);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn eigene_farbe_je_etappe() {
|
||||
let mut v = umbau_fixture();
|
||||
// W9 ist Neu in Etappe 2; Etappe 2 bekommt Blau (nur Füllung), Etappe 1 nichts Eigenes.
|
||||
v["renovation"]["phases"][1]["styles"] = json!({"new": {"fill": "#2f6db5"}, "demolish": {"dashed": false}});
|
||||
// Eine zweite neue Wand ohne Etappe behält die Projektfarbe.
|
||||
for w in v["walls"].as_array_mut().unwrap() {
|
||||
if w["id"] == "W3" {
|
||||
w["renovation"] = json!({"status": "new"});
|
||||
}
|
||||
}
|
||||
let p = project(&v);
|
||||
let view = View::new(&p, Some("umbauplan"), None).unwrap();
|
||||
let r = view.resolve(&p);
|
||||
assert_eq!(r.styled["W9"].fill, "#2f6db5");
|
||||
// Fehlende Felder der Etappe: Linie aus dem Projekt bzw. der Vorgabe.
|
||||
assert_eq!(r.styled["W9"].line.as_deref(), Some(NEW_LINE));
|
||||
assert_eq!(r.styled["W3"].fill, NEW_FILL);
|
||||
// Abbruch ohne Etappe bleibt gestrichelt.
|
||||
assert!(r.styled["W2"].dashed);
|
||||
// Farben, die in Schwarz-Weiss erhalten bleiben, enthalten die der Etappe.
|
||||
assert!(view.colors().contains(&"#2f6db5".to_string()));
|
||||
// Cache-Schlüssel ändert sich mit der Etappen-Farbe.
|
||||
let mut v2 = v.clone();
|
||||
v2["renovation"]["phases"][1]["styles"]["new"]["fill"] = json!("#000080");
|
||||
assert_ne!(view.key(), View::new(&project(&v2), Some("umbauplan"), None).unwrap().key());
|
||||
// Im Grundriss.
|
||||
let u = plan_with(&p, json!({"renovation": "umbauplan"}));
|
||||
assert!(fills_of(&u, "W9").iter().any(|f| f == "#2f6db5"), "{:?}", fills_of(&u, "W9"));
|
||||
// Filter bis Etappe 2 zeigt W9 als Neu der Etappe (eigene Farbe); im Stand einer späteren Etappe ist es Bestand.
|
||||
let r = View::new(&p, Some("umbauplan"), Some("e2")).unwrap().resolve(&p);
|
||||
assert_eq!(r.styled["W9"].fill, "#2f6db5");
|
||||
let mut v3 = v.clone();
|
||||
v3["renovation"]["phases"].as_array_mut().unwrap().push(json!({"id": "e3", "name": "Etappe 3"}));
|
||||
let p3 = project(&v3);
|
||||
let r = View::new(&p3, Some("umbauplan"), Some("e3")).unwrap().resolve(&p3);
|
||||
assert_eq!(r.styled["W9"], style(&p3, RenovationStatus::Existing));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn etappe_mit_stift_und_ersatzstueck() {
|
||||
let mut v = with_pens(umbau_fixture(), "farbe");
|
||||
// O1 (neue Öffnung in Bestandswand W1) in Etappe 2: ihr Abbruch-Stück nimmt die Abbruch-Farbe der Etappe.
|
||||
for o in v["openings"].as_array_mut().unwrap() {
|
||||
if o["id"] == "O1" {
|
||||
o["renovation"] = json!({"status": "new", "phase": "e2"});
|
||||
}
|
||||
}
|
||||
v["renovation"]["phases"][1]["styles"] = json!({"demolish": {"fillPen": "7"}});
|
||||
let p = project(&v);
|
||||
let r = View::new(&p, Some("umbauplan"), None).unwrap().resolve(&p);
|
||||
let o1 = r.patches.iter().find(|x| x.opening_id == "O1").unwrap();
|
||||
assert_eq!(o1.style.fill, "#3366cc");
|
||||
// O2 (ohne Etappe) behält die Projekt-Vorgabe.
|
||||
let o2 = r.patches.iter().find(|x| x.opening_id == "O2").unwrap();
|
||||
assert_eq!(o2.style.fill, NEW_FILL);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unsinn_robust() {
|
||||
let mut v = umbau_fixture();
|
||||
v["renovation"]["styles"] = json!({"new": {"fill": " ", "fillPen": "", "linePen": " "}, "demolish": {"fillPen": null}});
|
||||
v["renovation"]["phases"][0]["styles"] = json!({"new": {"fillPen": "x", "fill": ""}});
|
||||
v["penSets"] = json!([{"id": "a", "name": "A", "pens": {"x": {"color": "", "weight": 0.1}}}]);
|
||||
v["activePenSetId"] = json!("a");
|
||||
let p = project(&v);
|
||||
assert_eq!(style(&p, RenovationStatus::New).fill, NEW_FILL);
|
||||
assert_eq!(style(&p, RenovationStatus::Demolish).fill, DEMOLISH_FILL);
|
||||
let view = View::new(&p, Some("umbauplan"), None).unwrap();
|
||||
let _ = view.resolve(&p);
|
||||
let _ = plan_with(&p, json!({"renovation": "umbauplan"}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn abfrage_renovation_styles() {
|
||||
let mut v = with_pens(umbau_fixture(), "farbe");
|
||||
v["renovation"]["phases"][1]["styles"] = json!({"new": {"fillPen": "7"}});
|
||||
let p = project(&v);
|
||||
let out: Value = serde_json::from_str(&crate::queries::run(&p, "renovationStyles", &[], "").unwrap()).unwrap();
|
||||
assert_eq!(out["defaults"]["demolish"]["fill"], DEMOLISH_FILL);
|
||||
assert_eq!(out["project"]["new"]["fill"], NEW_FILL);
|
||||
assert_eq!(out["project"]["demolish"]["dashed"], true);
|
||||
assert_eq!(out["phases"]["e2"]["new"]["fill"], "#3366cc");
|
||||
assert!(out["phases"].get("e1").is_none());
|
||||
}
|
||||
@@ -57,7 +57,7 @@ fn vorgaben_je_status() {
|
||||
assert_eq!(View::new(&p, Some("umbauplan"), None).unwrap().treat(None), ex(RenovationStatus::Existing));
|
||||
// SIA: Abbruch gelb gestrichelt, Neu rot.
|
||||
assert!(default_style(RenovationStatus::Demolish).dashed);
|
||||
assert!(default_style(RenovationStatus::New).fill.starts_with("#e3"));
|
||||
assert_eq!(default_style(RenovationStatus::New).fill, NEW_FILL);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -198,7 +198,7 @@ fn restyle_flaechen_und_linien() {
|
||||
assert_eq!(q.len(), 5);
|
||||
match &q[0] {
|
||||
Primitive::Polygon { fill, stroke, opening_id, .. } => {
|
||||
assert_eq!(fill, "#ffd800");
|
||||
assert_eq!(fill, DEMOLISH_FILL);
|
||||
assert_eq!(stroke, "none");
|
||||
assert_eq!(opening_id.as_deref(), Some("O1"));
|
||||
}
|
||||
@@ -219,7 +219,7 @@ fn restyle_flaechen_und_linien() {
|
||||
|
||||
use crate::plan::domains::{plan_domains, PlanArgs};
|
||||
|
||||
fn plan_with(p: &Project, extra: Value) -> Vec<Primitive> {
|
||||
pub(crate) fn plan_with(p: &Project, extra: Value) -> Vec<Primitive> {
|
||||
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() {
|
||||
@@ -240,7 +240,7 @@ fn has_opening(prims: &[Primitive], id: &str) -> bool {
|
||||
})
|
||||
}
|
||||
|
||||
fn fills_of(prims: &[Primitive], id: &str) -> Vec<String> {
|
||||
pub(crate) fn fills_of(prims: &[Primitive], id: &str) -> Vec<String> {
|
||||
prims
|
||||
.iter()
|
||||
.filter_map(|q| match q {
|
||||
|
||||
Reference in new issue
Block a user