[285] Kataster/Kontext im Arbeitsgrundriss als halbtransparente Unterlage

Klassen "Als Unterlage" (LayerCategory.underlay, Vorgabe: Kontext-Klassen und Klassen aus
Landeskoordinaten-Importen) zeigt der Arbeitsgrundriss mit Deckkraft 0.35, damit Wände darüber
lesbar bleiben; Druck, PDF, SVG und CLI unverändert, Gruppenreihenfolge und Goldens unverändert.
This commit is contained in:
Claude committed 2026-11-18 14:53:13 +00:00
1 parent 188e05d8fe
commit 539d4e12dc
21 files changed
+220 -20

No files matched your search

+1
View File
@@ -150,6 +150,7 @@ pub fn ctx_key(a: &PlanArgs) -> String {
v.join("\u{2}")
});
format!("{}\u{1}{:?}\u{1}{}\u{1}{}\u{1}{}\u{1}{}\u{1}{}\u{1}{}\u{1}{}\u{1}{}", a.floor, a.detail, a.reference_lines, a.global, a.scale.to_bits(), a.for_print, a.compact, a.mono, a.auto_coarse, rules) + &a.model_view.as_deref().map_or(String::new(), |m| format!("\u{1}mv:{m}"))
+ if a.context_underlay { "\u{1}ul" } else { "" }
+ &a.trace_of.as_deref().map_or(String::new(), |t| format!("\u{1}trace:{t}"))
+ &a.renovation.as_deref().map_or(String::new(), |t| format!("\u{1}ren:{t}:{}", a.renovation_phase.as_deref().unwrap_or("")))
+ &a.design_options.iter().map(|(k, v)| format!("\u{1}opt:{k}={v}")).collect::<String>()
+1
View File
@@ -59,6 +59,7 @@ fn floor_args(a: &PlanArgs, floor: &str) -> PlanArgs {
renovation_phase: a.renovation_phase.clone(),
design_options: a.design_options.clone(),
design_option_edit: a.design_option_edit.clone(),
context_underlay: a.context_underlay,
}
}
+4 -1
View File
@@ -74,6 +74,8 @@ pub struct PlanArgs {
/// [272] Bearbeitungsvariante der Bildschirm-Ansicht (`designOptionEdit`: `{set, option, grey}`, nur Bildschirm;
/// aufgelöst in [`Ctx::new`] über `design_options::parse_edit`).
pub design_option_edit: Option<serde_json::Value>,
/// [285] Arbeitsgrundriss (Bildschirm): Klassen „als Unterlage" (Kataster, Kontext) halbtransparent (`drawings::underlay_class`).
pub context_underlay: bool,
}
/// [140] Ab diesem Massstab (1:N) zeichnet der Detailgrad „mittel" wie „grob".
@@ -124,6 +126,7 @@ impl PlanArgs {
renovation_phase: v.get("renovationPhase").and_then(|m| m.as_str()).filter(|m| !m.is_empty()).map(String::from),
design_options: crate::design_options::parse_request(v.get("designOptions")),
design_option_edit: v.get("designOptionEdit").filter(|e| e.is_object()).cloned(),
context_underlay: v.get("contextUnderlay").and_then(|b| b.as_bool()).unwrap_or(false),
})
}
@@ -1784,7 +1787,7 @@ pub fn room_stamp_spots(p: &Project, floor: &str, show: &HashSet<String>, scale:
return out;
}
let (detail, auto_coarse) = effective_detail(Detail::Mittel, scale);
let a = PlanArgs { floor: floor.to_string(), detail, show: show.clone(), grey: HashSet::new(), reference_lines: false, global: true, scale, for_print: false, compact: false, mono: false, sun_when: None, auto_coarse, rules: None, model_view: None, trace_of: None, renovation: None, renovation_phase: None, design_options: Vec::new(), design_option_edit: None };
let a = PlanArgs { floor: floor.to_string(), detail, show: show.clone(), grey: HashSet::new(), reference_lines: false, global: true, scale, for_print: false, compact: false, mono: false, sun_when: None, auto_coarse, rules: None, model_view: None, trace_of: None, renovation: None, renovation_phase: None, design_options: Vec::new(), design_option_edit: None, context_underlay: false };
let Ok(d) = plan_domains(p, &a) else { return out };
for q in d.rooms.iter().chain(&d.sections) {
if let Primitive::Text { at, room_id: Some(id), .. } = q {
+63 -7
View File
@@ -386,12 +386,33 @@ pub fn emit(c: &Ctx, d: &Drawing2D, attrs: Attrs, geom: &Drawing2DGeom, greyed:
attrs.demolish_dash = st.dashed;
}
let clamp = |v: Option<f64>| v.filter(|x| *x < 1.0).map(|x| jsnum::max(0.0, x));
// [285] Kontext-Klassen (Kataster …) im Arbeitsgrundriss halbtransparent, damit Wände darüber lesbar bleiben.
let under = if depth == 0 { underlay_opacity(c, &d.category_code) } else { None };
if under.is_some() {
sink.frames.push((under, None));
}
sink.frames.push((clamp(d.opacity), clamp(d.fill_opacity)));
let r = emit_inner(c, d, attrs, geom, greyed, scale, sink, depth);
sink.frames.pop();
if under.is_some() {
sink.frames.pop();
}
r
}
/// [285] Deckkraft der Zeichnungen einer Klasse, die der Arbeitsgrundriss als Unterlage zeigt.
pub const UNDERLAY_OPACITY: f64 = 0.35;
/// [285] Zeigt der Plan die Klasse `code` als halbtransparente Unterlage? Nur im Arbeitsgrundriss (`contextUnderlay`,
/// nie Druck/Export): nach `LayerCategory.underlay`, ohne Angabe die Umgebungsklassen (Kataster, Strassen, Gelände …).
pub(super) fn underlay_class(c: &Ctx, code: &str) -> bool {
c.a.context_underlay && !c.a.for_print && c.cat(code).and_then(|k| k.underlay).unwrap_or_else(|| crate::import_context::is_context_class(code))
}
fn underlay_opacity(c: &Ctx, code: &str) -> Option<f64> {
underlay_class(c, code).then_some(UNDERLAY_OPACITY)
}
fn opacity_mut(p: &mut Primitive) -> Option<&mut Option<f64>> {
match p {
Primitive::Polygon { opacity, .. }
@@ -2428,7 +2449,7 @@ pub fn plan_drawings_chunked(c: &Ctx, stamps: &[u64], cache: &mut super::cache::
continue;
}
let keep = if c.a.compact && compact_eligible(d) { Keep::NoLines } else { Keep::All };
seq.push((i, stamp, m.greyed as u8 | ((keep as u8) << 1)));
seq.push((i, stamp, m.greyed as u8 | ((keep as u8) << 1) | ((underlay_class(c, &d.category_code) as u8) << 4)));
}
let mut old = std::mem::take(&mut cache.chunks);
let mut new: HashMap<u64, Chunk> = HashMap::new();
@@ -2560,10 +2581,10 @@ fn build_chunk<'a>(
/// Gruppen der kompakten Unterlage: je (gedimmt, Ebene) in Reihenfolge des ersten Auftretens die
/// Indizes (in `project.drawings2d`) der Zeichnungen, deren Linien bei Bedarf entstehen. Format:
/// `[nGruppen, (gedimmt 0/1, n, Index…)…]`.
/// `[nGruppen, (Schalter, n, Index…)…]`; Schalter: Bit 1 = gedimmt, Bit 2 = Klasse als Unterlage ([285]).
pub fn underlay_groups(c: &Ctx) -> Vec<f64> {
let mut keys: HashMap<(bool, &str), usize> = HashMap::new();
let mut groups: Vec<(bool, Vec<f64>)> = Vec::new();
let mut groups: Vec<(bool, &str, Vec<f64>)> = Vec::new();
if c.a.compact {
let mut memo = Memo::default();
for (i, d) in c.p.drawings2d.iter().enumerate() {
@@ -2576,15 +2597,15 @@ pub fn underlay_groups(c: &Ctx) -> Vec<f64> {
}
let g = m.greyed;
let k = *keys.entry((g, d.category_code.as_str())).or_insert_with(|| {
groups.push((g, Vec::new()));
groups.push((g, d.category_code.as_str(), Vec::new()));
groups.len() - 1
});
groups[k].1.push(i as f64);
groups[k].2.push(i as f64);
}
}
let mut out = vec![groups.len() as f64];
for (g, idx) in groups {
out.push(if g { 1.0 } else { 0.0 });
for (g, code, idx) in groups {
out.push(f64::from(g as u8 | ((underlay_class(c, code) as u8) << 1)));
out.push(idx.len() as f64);
out.extend(idx);
}
@@ -3609,6 +3630,41 @@ mod tests {
assert!(!compact_eligible(&serde_json::from_value(d).unwrap()));
}
/// [285] Kontext-Klassen (Kataster …) zeigt nur der Arbeitsgrundriss halbtransparent; Druck/Export und andere
/// Klassen bleiben deckend, `LayerCategory.underlay` schaltet je Klasse um.
#[test]
fn kontext_klasse_als_unterlage() {
let line = serde_json::json!({ "shape": "line", "a": {"x": 0, "y": 0}, "b": {"x": 4, "y": 0} });
let mk = |code: &str| {
let mut d = drawing(line.clone());
d["categoryCode"] = serde_json::json!(code);
d
};
let p = project(serde_json::json!({"layers": [
{"code": "05", "name": "Kontext", "color": "#888888", "lw": 0.25, "visible": true, "locked": false},
{"code": "20", "name": "Zeichnung", "color": "#0a0a0a", "lw": 0.5, "visible": true, "locked": false},
{"code": "21", "name": "Eigene", "color": "#0a0a0a", "lw": 0.5, "visible": true, "locked": false, "underlay": true}
]}));
let op = |code: &str, extra: &str| -> Option<f64> {
let t = format!(r#"{{"floor":"eg","show":["05","20","21"],"scale":100{extra}}}"#);
let a = PlanArgs::parse(1.0, &t).unwrap();
let c = Ctx::new(&p, &a);
let d: Drawing2D = serde_json::from_value(mk(code)).unwrap();
let mut out = Out::default();
emit(&c, &d, Attrs::of(&c, &d), &d.geom, false, 100.0, &mut Sink::new(Target::Vec(&mut out), Keep::All), 0).unwrap();
out.prims.iter().find_map(|q| match q {
Primitive::Line { opacity, .. } => Some(opacity.unwrap_or(1.0)),
_ => None,
})
};
let work = r#","contextUnderlay":true"#;
assert_eq!(op("05", work), Some(UNDERLAY_OPACITY));
assert_eq!(op("21", work), Some(UNDERLAY_OPACITY), "ausdrücklich als Unterlage");
assert_eq!(op("20", work), Some(1.0));
assert_eq!(op("05", ""), Some(1.0), "ohne Arbeitsgrundriss deckend");
assert_eq!(op("05", r#","contextUnderlay":true,"forPrint":true"#), Some(1.0), "Druck unverändert");
}
#[test]
fn kompakt_nur_ohne_enden_und_boegen() {
let mk = |g: serde_json::Value| -> Drawing2D { serde_json::from_value(drawing(g)).unwrap() };
+1
View File
@@ -1861,6 +1861,7 @@ fn sheets(cx: &mut Ctx, main: &mut Buf, layer_by_code: &HashMap<&str, String>) {
renovation_phase: None,
design_options: Vec::new(),
design_option_edit: None,
context_underlay: false,
};
if let Some(entries) = plan_domains_buf(p, &args).ok().and_then(|buf| {
let view = View::parse(&buf)?;