[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:
21 files changed
+220
-20
No files matched your search
@@ -933,6 +933,16 @@ pub fn import_ops(root: &Map<String, Value>, d: &DrawingImport, dec: &Decision,
|
||||
o.insert("name".into(), n.into());
|
||||
}
|
||||
}
|
||||
// [285] Landeskoordinaten = Kataster/Vermessung: die neuen Klassen zeigt der Arbeitsgrundriss als Unterlage
|
||||
// (`LayerCategory.underlay`), damit Wände darüber lesbar bleiben; Druck/Export bleiben deckend.
|
||||
let cadastral = dec.view_center.is_none() && bbox(d).is_some_and(|b| lv95_origin(root, [(b[0] + b[2]) / 2.0, (b[1] + b[3]) / 2.0], &dec.geo_label).is_some());
|
||||
if cadastral {
|
||||
for ch in plan.children.iter_mut() {
|
||||
if let Some(o) = ch.as_object_mut() {
|
||||
o.insert("underlay".into(), true.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
if !plan.children.is_empty() {
|
||||
let parent = json!({"code": plan.parent_code, "name": dec.parent_name, "color": "#707078", "lw": 0.18, "visible": true, "locked": false, "children": plan.children});
|
||||
ensure_layers_with_parent(&mut layers, Some(parent));
|
||||
|
||||
@@ -3012,6 +3012,11 @@ pub struct LayerCategory {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub fill: Option<String>,
|
||||
/// [285] Im Arbeitsgrundriss (Bildschirm, nie Druck/Export) halbtransparent als Unterlage zeigen, damit Wände darüber
|
||||
/// lesbar bleiben. Fehlt: an für Umgebungsklassen („05 Kontext" und Kinder: Kataster, Strassen, Gelände …), sonst aus.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub underlay: Option<bool>,
|
||||
/// Unterkategorien (Baum).
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
|
||||
@@ -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>()
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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() };
|
||||
|
||||
@@ -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)?;
|
||||
|
||||
@@ -420,12 +420,13 @@ pub fn run_bin(p: &Project, name: &str, args: &[f64], text: &str) -> Result<Vec<
|
||||
Ok(drawings::underlay_groups(&domains::Ctx::new(p, &a)).iter().flat_map(|v| v.to_le_bytes()).collect())
|
||||
}
|
||||
// Linien der Zeichnungen `[Massstab, Schalter, Index…]` (Index in `drawings2d`), mit Override-Regeln;
|
||||
// Schalter: Bit 1 = gedimmt, Bit 2 = Schwarz-Weiss ([140]).
|
||||
// Schalter: Bit 1 = gedimmt, Bit 2 = Schwarz-Weiss ([140]), Bit 3 = Klasse als Unterlage ([285]).
|
||||
("drawingLines", n) if n >= 2 => {
|
||||
let mut a = domains::PlanArgs::parse(1.0, "{}")?;
|
||||
a.scale = args[0];
|
||||
let c = domains::Ctx::new(p, &a);
|
||||
let flags = if args[1].is_finite() && args[1] >= 0.0 { args[1] as u32 } else { 0 };
|
||||
a.context_underlay = flags & 4 != 0;
|
||||
let c = domains::Ctx::new(p, &a);
|
||||
// Strichstärken nach Massstab wie im übrigen Plan.
|
||||
let post = Some(crate::plan::extras::Post { mono: flags & 2 != 0, lw: crate::plan::extras::line_weight_factor(p, args[0]), sketch: 0.0, keep: Default::default() }).filter(crate::plan::extras::Post::active);
|
||||
buf_with(post, |sink| drawings::underlay_lines(&c, &args[2..], flags & 1 != 0, sink))
|
||||
|
||||
@@ -185,6 +185,7 @@ pub fn viewport_args(p: &Project, snap: &ViewSnapshot, scale: f64, mono: bool) -
|
||||
// [272] Variantenkombination des Ausschnitts (über der der Ebene).
|
||||
design_options: crate::design_options::stored_choice(p, snap.design_option_combination.as_deref(), snap.design_options.as_ref()).into_iter().flatten().collect(),
|
||||
design_option_edit: None,
|
||||
context_underlay: false,
|
||||
};
|
||||
a.apply_model_view(p);
|
||||
a
|
||||
|
||||
Reference in new issue
Block a user