[66] Merge: Präsentationsplan mit einem Klick (site_and_shadow mit Massstab und Baurecht-Schalter)
This commit is contained in:
28 files changed
+1184
-39
No files matched your search
@@ -123,3 +123,4 @@ pub mod dim_assoc;
|
||||
|
||||
#[cfg(feature = "web")]
|
||||
mod web;
|
||||
pub mod presentation_sheet;
|
||||
@@ -790,7 +790,7 @@ pub fn plan_domains_buf(p: &Project, a: &PlanArgs) -> Result<Vec<u8>, String> {
|
||||
w.group(g);
|
||||
}
|
||||
w.group(&violations);
|
||||
w.bounds = Some(super::extras::plan_bounds(&bounds, &super::extras::extra_bounds(p, &under)));
|
||||
w.bounds = Some(super::extras::plan_bounds(&bounds, &super::extras::extra_bounds(p, &under, |k| c.shown(k))));
|
||||
Ok(w.finish())
|
||||
}
|
||||
|
||||
@@ -798,7 +798,9 @@ pub fn plan_domains_buf(p: &Project, a: &PlanArgs) -> Result<Vec<u8>, String> {
|
||||
/// beim projektglobalen Aufruf (`global`).
|
||||
fn extras_of(p: &Project, a: &PlanArgs) -> (Vec<(Primitive, u32)>, Vec<Primitive>) {
|
||||
if a.global {
|
||||
super::extras::site_and_shadow(p, &a.floor, a.sun_when, a.scale)
|
||||
// [66] Baurecht (Parzelle, Baubereich, Verstösse) gehört zur Vermessung: ausgeblendete Kategorie „01" ⇒ ohne.
|
||||
let site = !(p.flat_categories().iter().any(|c| c.code == super::extras::SITE_CATEGORY) && !a.show.contains(super::extras::SITE_CATEGORY));
|
||||
super::extras::site_and_shadow(p, &a.floor, a.sun_when, a.scale, site)
|
||||
} else {
|
||||
(Vec::new(), Vec::new())
|
||||
}
|
||||
@@ -908,7 +910,7 @@ fn assemble_cached(c: &Ctx, revs: &crate::document::Revs, cc: &mut super::cache:
|
||||
domains_before(c, &mut d, &mut b)?;
|
||||
domains_after(c, &mut d);
|
||||
let (under, violations) = extras_of(c.p, c.a);
|
||||
let extra = super::extras::extra_bounds(c.p, &under);
|
||||
let extra = super::extras::extra_bounds(c.p, &under, |k| c.shown(k));
|
||||
apply_voids(c.p, c.a, &mut d);
|
||||
let plain = |g: Vec<Primitive>| g.into_iter().map(|q| (q, 0)).collect::<Vec<_>>();
|
||||
let mut lists = vec![under];
|
||||
@@ -1247,7 +1249,7 @@ mod tests {
|
||||
// Ausmass: Domänen und Kontext.
|
||||
let mut db = Bounds::new();
|
||||
db.merge(d.bounds.unwrap());
|
||||
assert_eq!(bounds, Some(super::super::extras::plan_bounds(&db, &super::super::extras::extra_bounds(&p, &[]))));
|
||||
assert_eq!(bounds, Some(super::super::extras::plan_bounds(&db, &super::super::extras::extra_bounds(&p, &[], |_| true))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -158,11 +158,18 @@ fn seg_band(a: Vec2, b: Vec2, half: f64) -> Option<Primitive> {
|
||||
/// Unterste Gruppe: Schatten, dann Parzellengrenze (Strich-Punkt) und zulässige Fläche
|
||||
/// (gestrichelt); mit Strichmuster-Kennung je Primitiv. Dazu die Verstösse (Gebäude-Grundfläche
|
||||
/// ausserhalb der zulässigen Fläche) für die oberste Gruppe.
|
||||
pub fn site_and_shadow(p: &Project, floor: &str, when_ms: Option<f64>, scale: f64) -> (Vec<(Primitive, u32)>, Vec<Primitive>) {
|
||||
/// Kategorie der Vermessung; ist sie im Projekt und ausgeblendet, entfällt das Baurecht im Grundriss ([66]).
|
||||
pub const SITE_CATEGORY: &str = "01";
|
||||
|
||||
/// `site = false`: nur der Schatten, ohne Baurecht.
|
||||
pub fn site_and_shadow(p: &Project, floor: &str, when_ms: Option<f64>, scale: f64, site: bool) -> (Vec<(Primitive, u32)>, Vec<Primitive>) {
|
||||
let mut shadow = Vec::new();
|
||||
sun_shadow(p, floor, when_ms, &mut shadow);
|
||||
let mut under: Vec<(Primitive, u32)> = shadow.into_iter().map(|q| (q, 0)).collect();
|
||||
let mut violations = Vec::new();
|
||||
if !site {
|
||||
return (under, violations);
|
||||
}
|
||||
if let (Some(check), Some(rules)) = (site_check(p, floor), p.site_rules.as_ref()) {
|
||||
let mut r = 1;
|
||||
ring_lines(&mut under, &rules.parcel, SITE_PARCEL_CLS, PARCEL_COLOR, 0.35, &PARCEL_DASH, r);
|
||||
@@ -484,7 +491,9 @@ pub fn sketch_post(on: Option<bool>, scale: f64) -> Option<Post> {
|
||||
/// Ausmass der Zutaten, die „Einpassen" und Druck ganz zeigen sollen: Schatten und Baurechts-Linien
|
||||
/// (`extra`) und die ganze Kontext-Schicht (Konturen, Netze, Luftbilder) — Rohwerte für
|
||||
/// [`plan_bounds`].
|
||||
pub fn extra_bounds(p: &Project, extra: &[(Primitive, u32)]) -> Bounds {
|
||||
/// Kontext-Objekte zählen nur, wenn ihre Kategorie gezeigt wird (`shown`, wie `plan_context`; ohne Kategorie
|
||||
/// immer) — sonst bestimmt ein ausgeblendetes Gelände Zoom und Viewport-Grösse ([66]).
|
||||
pub fn extra_bounds(p: &Project, extra: &[(Primitive, u32)], shown: impl Fn(&str) -> bool) -> Bounds {
|
||||
let mut b = Bounds::new();
|
||||
for (e, _) in extra {
|
||||
match e {
|
||||
@@ -501,6 +510,16 @@ pub fn extra_bounds(p: &Project, extra: &[(Primitive, u32)]) -> Bounds {
|
||||
}
|
||||
}
|
||||
for obj in p.context.as_deref().unwrap_or(&[]) {
|
||||
let code = match obj {
|
||||
ContextObject::ImportedMesh(m) => m.category_code.as_deref(),
|
||||
ContextObject::ContourSet(s) => s.category_code.as_deref(),
|
||||
ContextObject::TerrainMesh(t) => t.category_code.as_deref(),
|
||||
ContextObject::Image(i) => i.category_code.as_deref(),
|
||||
ContextObject::Excavation(e) => e.category_code.as_deref(),
|
||||
};
|
||||
if code.is_some_and(|k| !shown(k)) {
|
||||
continue;
|
||||
}
|
||||
match obj {
|
||||
ContextObject::ContourSet(cs) => {
|
||||
for c in &cs.contours {
|
||||
@@ -553,6 +572,20 @@ mod tests {
|
||||
serde_json::from_str(include_str!("../../tests/fixtures/sample_project.json")).unwrap()
|
||||
}
|
||||
|
||||
/// [66] Ausgeblendete Kontext-Kategorien (Höhenlinien) bestimmen das Ausmass nicht mit.
|
||||
#[test]
|
||||
fn ausmass_ohne_ausgeblendeten_kontext() {
|
||||
let mut p = sample();
|
||||
p.context = Some(vec![serde_json::from_value(serde_json::json!({
|
||||
"type": "contourSet", "id": "hl", "name": "HL", "categoryCode": "14",
|
||||
"contours": [{"z": 0.0, "pts": [{"x": -100.0, "y": -100.0}, {"x": 100.0, "y": 100.0}]}]
|
||||
}))
|
||||
.unwrap()]);
|
||||
let on = extra_bounds(&p, &[], |_| true).get().unwrap();
|
||||
assert_eq!(on, [-100.0, -100.0, 100.0, 100.0]);
|
||||
assert!(extra_bounds(&p, &[], |k| k != "14").get().is_none());
|
||||
}
|
||||
|
||||
/// [63] Profilverstösse erscheinen im Grundriss (schwächeres Rot); ohne Profil nichts.
|
||||
#[test]
|
||||
fn profilverstoesse_im_grundriss() {
|
||||
@@ -564,12 +597,15 @@ mod tests {
|
||||
serde_json::from_value(v).unwrap()
|
||||
};
|
||||
p.site_rules = Some(rules(serde_json::json!({})));
|
||||
let n0 = site_and_shadow(&p, &floor, None, 100.0).1.len();
|
||||
let n0 = site_and_shadow(&p, &floor, None, 100.0, true).1.len();
|
||||
p.site_rules = Some(rules(serde_json::json!({"profileAngle": 10.0, "profileHeight": 0.01})));
|
||||
let c = crate::site_rules::check_project(&p).unwrap();
|
||||
assert!(c.profile_exceeded);
|
||||
let n1 = site_and_shadow(&p, &floor, None, 100.0).1.len();
|
||||
let n1 = site_and_shadow(&p, &floor, None, 100.0, true).1.len();
|
||||
assert!(n1 > n0, "{n0} {n1}");
|
||||
// [66] Ohne Vermessung (Kategorie aus) kein Baurecht.
|
||||
let (under, viol) = site_and_shadow(&p, &floor, None, 100.0, false);
|
||||
assert!(under.is_empty() && viol.is_empty());
|
||||
}
|
||||
|
||||
/// Oberste Fläche mit Pick-Id unter dem Punkt (wie `PickIndex::polygons_at`, Maske „Kontext").
|
||||
@@ -592,7 +628,7 @@ mod tests {
|
||||
let floor = ground_floor_id(&p).unwrap().to_string();
|
||||
p.sun_study = Some(SunStudy { when: "2026-12-21T09:00:00Z".into(), show: true, ..Default::default() });
|
||||
let when = Some(1_797_843_600_000.0); // 2026-12-21T09:00:00Z
|
||||
let (under, _) = site_and_shadow(&p, &floor, when, 100.0);
|
||||
let (under, _) = site_and_shadow(&p, &floor, when, 100.0, true);
|
||||
let shadows: Vec<&Primitive> = under.iter().map(|(q, _)| q).filter(|q| matches!(q, Primitive::Polygon { fill, .. } if fill == SUN_SHADOW_FILL)).collect();
|
||||
assert!(!shadows.is_empty());
|
||||
assert!(shadows.iter().all(|q| matches!(q, Primitive::Polygon { context_object_id: Some(id), .. } if id == SITE_PICK_SUN)));
|
||||
@@ -604,17 +640,17 @@ mod tests {
|
||||
let inside = (0..400).map(|k| (x0 + (x1 - x0) * ((k % 20) as f64 + 0.5) / 20.0, y0 + (y1 - y0) * ((k / 20) as f64 + 0.5) / 20.0)).find(|q| crate::plan::pick::point_in_polygon(q.0, q.1, &flat)).unwrap();
|
||||
assert_eq!(top_pick(&under, inside.0, inside.1).as_deref(), Some(SITE_PICK_SUN));
|
||||
assert_eq!(top_pick(&under, 1e4, 1e4), None);
|
||||
assert!(site_and_shadow(&p, "anderes-geschoss", when, 100.0).0.is_empty());
|
||||
assert!(site_and_shadow(&p, "anderes-geschoss", when, 100.0, true).0.is_empty());
|
||||
p.sun_study.as_mut().unwrap().show = false;
|
||||
assert_eq!(top_pick(&site_and_shadow(&p, &floor, when, 100.0).0, inside.0, inside.1), None);
|
||||
assert_eq!(top_pick(&site_and_shadow(&p, &floor, when, 100.0, true).0, inside.0, inside.1), None);
|
||||
// Baurecht: Parzellengrenze bei x = −30, Grenzabstand 3 m → zulässige Fläche ab x = −27; Band ±0.15 m bei 1:100.
|
||||
p.site_rules = Some(serde_json::from_value(serde_json::json!({"parcel": [{"x": -30, "y": -30}, {"x": 40, "y": -30}, {"x": 40, "y": 40}, {"x": -30, "y": 40}], "defaultSetback": 3.0})).unwrap());
|
||||
let (under, _) = site_and_shadow(&p, &floor, when, 100.0);
|
||||
let (under, _) = site_and_shadow(&p, &floor, when, 100.0, true);
|
||||
assert_eq!(top_pick(&under, -30.1, 5.0).as_deref(), Some(SITE_PICK_RULES));
|
||||
assert_eq!(top_pick(&under, -27.0, 5.0).as_deref(), Some(SITE_PICK_RULES), "zulässige Fläche");
|
||||
assert_eq!(top_pick(&under, -28.5, 5.0), None);
|
||||
// Massstab 1:500: Band ±0.75 m.
|
||||
assert_eq!(top_pick(&site_and_shadow(&p, &floor, when, 500.0).0, -29.4, 5.0).as_deref(), Some(SITE_PICK_RULES));
|
||||
assert_eq!(top_pick(&site_and_shadow(&p, &floor, when, 500.0, true).0, -29.4, 5.0).as_deref(), Some(SITE_PICK_RULES));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -0,0 +1,274 @@
|
||||
//! [66] Präsentationsplan mit einem Klick: gemeinsamen Massstab wählen und die Ansichten (Grundrisse,
|
||||
//! Ansichten, Schnitt) in einem ruhigen Raster auf dem Blatt anordnen.
|
||||
//!
|
||||
//! Jede Gruppe (Grundrisse, Ansichten, Schnitte) bekommt gleich grosse Rahmen (grösster Inhalt der Gruppe
|
||||
//! plus Rand) und füllt Zeilen von links nach rechts; jede Zeile ist waagrecht zentriert, der ganze Block
|
||||
//! senkrecht, soweit Platz ist. Das Schriftfeld des Masters (unten rechts, wie `TitleBlockSvg`) bleibt frei.
|
||||
//! Gewählt wird der grösste Massstab aus [`SCALES`], bei dem alles auf das Blatt passt.
|
||||
|
||||
use crate::model::{DetailLevel, Project, ViewSnapshot};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{json, Value};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
/// Massstäbe in Wahlreihenfolge (grösster zuerst).
|
||||
pub const SCALES: [f64; 5] = [50.0, 100.0, 200.0, 500.0, 1000.0];
|
||||
/// Rand zwischen Inhalt und Viewport-Rahmen (mm).
|
||||
pub const FRAME_PAD_MM: f64 = 4.0;
|
||||
/// Abstand zwischen Rahmen (mm).
|
||||
pub const GAP_MM: f64 = 12.0;
|
||||
/// Platz für den Titel unter jedem Rahmen (mm).
|
||||
pub const TITLE_MM: f64 = 9.0;
|
||||
/// Blattrand (mm, innerhalb des Master-Rahmens bei 5 mm).
|
||||
pub const MARGIN_MM: f64 = 15.0;
|
||||
/// Schriftfeld des Masters: Breite, Höhe, Abstand zum Blattrand (mm, wie `TitleBlockSvg`).
|
||||
pub const TITLE_BLOCK_MM: [f64; 3] = [70.0, 30.0, 6.0];
|
||||
|
||||
/// Rahmen eines Viewports auf dem Blatt (mm, Ursprung oben links).
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Rect {
|
||||
pub x_mm: f64,
|
||||
pub y_mm: f64,
|
||||
pub width_mm: f64,
|
||||
pub height_mm: f64,
|
||||
}
|
||||
|
||||
/// Blatt: Grösse (mm) und das freizuhaltende Schriftfeld `[x, y, w, h]`.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Sheet {
|
||||
pub w: f64,
|
||||
pub h: f64,
|
||||
pub title_block: Option<[f64; 4]>,
|
||||
}
|
||||
|
||||
impl Sheet {
|
||||
pub fn new(w: f64, h: f64, title_block: bool) -> Sheet {
|
||||
let [tw, th, pad] = TITLE_BLOCK_MM;
|
||||
Sheet { w, h, title_block: title_block.then(|| [w - tw - pad, h - th - pad, tw, th]) }
|
||||
}
|
||||
}
|
||||
|
||||
/// Zeilen ab `y0` füllen; `strict`: `None`, wenn eine Zeile oder der Block nicht aufs Blatt passt.
|
||||
fn pack_from(items: &[(u32, f64, f64)], sheet: &Sheet, y0: f64, strict: bool) -> Option<(Vec<Rect>, f64)> {
|
||||
let (l, r, b) = (MARGIN_MM, sheet.w - MARGIN_MM, sheet.h - MARGIN_MM);
|
||||
let mut out = vec![Rect::default(); items.len()];
|
||||
let mut y = y0;
|
||||
let mut i = 0;
|
||||
while i < items.len() {
|
||||
let g = items[i].0;
|
||||
let j = i + items[i..].iter().take_while(|it| it.0 == g).count();
|
||||
let cw = items[i..j].iter().fold(0.0_f64, |m, it| m.max(it.1)) + 2.0 * FRAME_PAD_MM;
|
||||
let ch = items[i..j].iter().fold(0.0_f64, |m, it| m.max(it.2)) + 2.0 * FRAME_PAD_MM;
|
||||
let mut k = i;
|
||||
while k < j {
|
||||
let row_bottom = y + ch + TITLE_MM;
|
||||
let right = match sheet.title_block {
|
||||
Some([tx, ty, _, th]) if row_bottom > ty - GAP_MM && y < ty + th => tx - GAP_MM,
|
||||
_ => r,
|
||||
};
|
||||
let fit = ((right - l + GAP_MM) / (cw + GAP_MM)).floor();
|
||||
let n = if fit.is_finite() && fit >= 1.0 { fit as usize } else if strict { return None } else { 1 };
|
||||
let cnt = n.min(j - k);
|
||||
let row_w = cnt as f64 * cw + (cnt as f64 - 1.0) * GAP_MM;
|
||||
let x0 = l + ((right - l - row_w) / 2.0).max(0.0);
|
||||
for c in 0..cnt {
|
||||
out[k + c] = Rect { x_mm: x0 + c as f64 * (cw + GAP_MM), y_mm: y, width_mm: cw, height_mm: ch };
|
||||
}
|
||||
k += cnt;
|
||||
y = row_bottom + GAP_MM;
|
||||
}
|
||||
i = j;
|
||||
}
|
||||
let bottom = y - GAP_MM;
|
||||
if strict && bottom > b + 1e-9 {
|
||||
return None;
|
||||
}
|
||||
Some((out, bottom))
|
||||
}
|
||||
|
||||
/// Rahmen für Inhalte `(Gruppe, Breite, Höhe)` (Papier-mm, Gruppen aufsteigend sortiert) in Eingabe-
|
||||
/// reihenfolge; `None`, wenn sie nicht aufs Blatt passen. Der Block wird senkrecht zentriert, wenn das
|
||||
/// die Zeilen nicht verändert.
|
||||
pub fn pack(items: &[(u32, f64, f64)], sheet: &Sheet) -> Option<Vec<Rect>> {
|
||||
let (top, b) = (MARGIN_MM, sheet.h - MARGIN_MM);
|
||||
let (first, bottom) = pack_from(items, sheet, top, true)?;
|
||||
let off = (b - bottom) / 2.0;
|
||||
if off > 0.0 {
|
||||
if let Some((centered, _)) = pack_from(items, sheet, top + off, true) {
|
||||
return Some(centered);
|
||||
}
|
||||
}
|
||||
Some(first)
|
||||
}
|
||||
|
||||
/// Ergebnis der Wahl: Massstab, ob alles passt, Rahmen je Inhalt.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Choice {
|
||||
pub scale: f64,
|
||||
pub fits: bool,
|
||||
pub rects: Vec<Rect>,
|
||||
}
|
||||
|
||||
/// Grösster Massstab aus [`SCALES`], bei dem alles passt (`sizes_at(scale)` = Inhalte beim Massstab);
|
||||
/// passt nichts, der kleinste Massstab mit überlaufenden Zeilen (`fits = false`).
|
||||
pub fn choose(mut sizes_at: impl FnMut(f64) -> Vec<(u32, f64, f64)>, sheet: &Sheet) -> Choice {
|
||||
for s in SCALES {
|
||||
if let Some(rects) = pack(&sizes_at(s), sheet) {
|
||||
return Choice { scale: s, fits: true, rects };
|
||||
}
|
||||
}
|
||||
let s = SCALES[SCALES.len() - 1];
|
||||
let rects = pack_from(&sizes_at(s), sheet, MARGIN_MM, false).map(|r| r.0).unwrap_or_default();
|
||||
Choice { scale: s, fits: false, rects }
|
||||
}
|
||||
|
||||
/// Anfrage der Abfrage `presentationSheet`.
|
||||
#[derive(Deserialize, Default)]
|
||||
#[serde(rename_all = "camelCase", default)]
|
||||
pub struct Request {
|
||||
/// Ebenen (Geschosse, Ansichten, Schnitte) in Blattreihenfolge.
|
||||
pub levels: Vec<String>,
|
||||
/// Gruppe je Ebene (0 Grundrisse, 1 Ansichten, 2 Schnitte), aufsteigend.
|
||||
pub groups: Vec<u32>,
|
||||
pub layer_visibility: BTreeMap<String, bool>,
|
||||
pub detail: DetailLevel,
|
||||
pub sheet_w: f64,
|
||||
pub sheet_h: f64,
|
||||
pub title_block: bool,
|
||||
/// Schatten der Ansichten (Vorlage „Präsentation").
|
||||
pub shadows: bool,
|
||||
}
|
||||
|
||||
/// Abfrage `presentationSheet`: Massstab und Rahmen für die Ebenen; Ebenen ohne Inhalt stehen unter
|
||||
/// `skipped`.
|
||||
pub fn query(p: &Project, text: &str) -> Result<Value, String> {
|
||||
let req: Request = serde_json::from_str(text).map_err(|e| format!("presentationSheet: {e}"))?;
|
||||
if !(req.sheet_w > 0.0 && req.sheet_h > 0.0 && req.sheet_w.is_finite() && req.sheet_h.is_finite()) {
|
||||
return Err("presentationSheet: Blattgrösse ungültig".into());
|
||||
}
|
||||
let snap = |level: &str| ViewSnapshot {
|
||||
active_level_id: level.to_string(),
|
||||
layer_visibility: req.layer_visibility.clone(),
|
||||
detail: req.detail,
|
||||
scale_denominator: 100.0,
|
||||
..Default::default()
|
||||
};
|
||||
let bounds_at = |level: &str, s: f64| crate::sheet_viewports::snapshot_bounds(p, &snap(level), s, Some(req.shadows));
|
||||
// Ebenen ohne Inhalt fallen weg (geprüft beim mittleren Massstab).
|
||||
let mut kept: Vec<(String, u32)> = Vec::new();
|
||||
let mut skipped: Vec<String> = Vec::new();
|
||||
for (i, id) in req.levels.iter().enumerate() {
|
||||
let ok = p.drawing_levels.iter().any(|l| &l.id == id) && bounds_at(id, 100.0).is_some_and(|b| b.iter().all(|v| v.is_finite()) && b[2] > b[0] && b[3] > b[1]);
|
||||
if ok {
|
||||
kept.push((id.clone(), req.groups.get(i).copied().unwrap_or(0)));
|
||||
} else {
|
||||
skipped.push(id.clone());
|
||||
}
|
||||
}
|
||||
kept.sort_by_key(|k| k.1);
|
||||
let sheet = Sheet::new(req.sheet_w, req.sheet_h, req.title_block);
|
||||
let choice = choose(
|
||||
|s| {
|
||||
kept.iter()
|
||||
.map(|(id, g)| {
|
||||
let b = bounds_at(id, s).unwrap_or([0.0, 0.0, 1.0, 1.0]);
|
||||
(*g, (b[2] - b[0]) * 1000.0 / s, (b[3] - b[1]) * 1000.0 / s)
|
||||
})
|
||||
.collect()
|
||||
},
|
||||
&sheet,
|
||||
);
|
||||
let items: Vec<Value> = kept
|
||||
.iter()
|
||||
.zip(&choice.rects)
|
||||
.map(|((id, g), r)| json!({"levelId": id, "group": g, "xMm": r.x_mm, "yMm": r.y_mm, "widthMm": r.width_mm, "heightMm": r.height_mm}))
|
||||
.collect();
|
||||
Ok(json!({"scale": choice.scale, "fits": choice.fits, "items": items, "skipped": skipped}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn inside(r: &Rect, s: &Sheet) -> bool {
|
||||
r.x_mm >= MARGIN_MM - 1e-9
|
||||
&& r.y_mm >= MARGIN_MM - 1e-9
|
||||
&& r.x_mm + r.width_mm <= s.w - MARGIN_MM + 1e-9
|
||||
&& r.y_mm + r.height_mm + TITLE_MM <= s.h - MARGIN_MM + 1e-9
|
||||
}
|
||||
fn overlap(a: &Rect, b: &Rect) -> bool {
|
||||
a.x_mm < b.x_mm + b.width_mm && b.x_mm < a.x_mm + a.width_mm && a.y_mm < b.y_mm + b.height_mm + TITLE_MM && b.y_mm < a.y_mm + a.height_mm + TITLE_MM
|
||||
}
|
||||
fn check(rects: &[Rect], s: &Sheet) {
|
||||
for (i, a) in rects.iter().enumerate() {
|
||||
assert!(inside(a, s), "{a:?} ausserhalb");
|
||||
if let Some([tx, ty, tw, th]) = s.title_block {
|
||||
let tb = Rect { x_mm: tx, y_mm: ty, width_mm: tw, height_mm: th - TITLE_MM };
|
||||
assert!(!overlap(a, &tb), "{a:?} über dem Schriftfeld");
|
||||
}
|
||||
for b in &rects[i + 1..] {
|
||||
assert!(!overlap(a, b), "{a:?} überlappt {b:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Haus 12 × 10 m (4 Geschosse), Ansichten 12 × 9 m: A1 quer (841 × 594): 1:50 passt nicht,
|
||||
/// 1:100 schon.
|
||||
#[test]
|
||||
fn a1_waehlt_1_100_und_alles_liegt_auf_dem_blatt() {
|
||||
let s = Sheet::new(841.0, 594.0, true);
|
||||
let sizes = |sc: f64| {
|
||||
let mut v: Vec<(u32, f64, f64)> = (0..4).map(|_| (0, 12000.0 / sc, 10000.0 / sc)).collect();
|
||||
v.extend((0..4).map(|_| (1, 12000.0 / sc, 9000.0 / sc)));
|
||||
v.push((2, 12000.0 / sc, 9000.0 / sc));
|
||||
v
|
||||
};
|
||||
let c = choose(sizes, &s);
|
||||
assert!(c.fits);
|
||||
assert_eq!(c.scale, 100.0);
|
||||
assert_eq!(c.rects.len(), 9);
|
||||
check(&c.rects, &s);
|
||||
// Gleiche Rahmen je Gruppe, Grundrisse oben.
|
||||
assert!(c.rects[..4].iter().all(|r| r.width_mm == c.rects[0].width_mm && r.height_mm == c.rects[0].height_mm));
|
||||
assert!(c.rects[4].y_mm > c.rects[0].y_mm);
|
||||
}
|
||||
|
||||
/// Grosser Bau auf A3: 1:100 passt nicht, 1:200 auch nicht, 1:500 schon.
|
||||
#[test]
|
||||
fn kleines_blatt_waehlt_kleineren_massstab() {
|
||||
let s = Sheet::new(420.0, 297.0, true);
|
||||
let c = choose(|sc| (0..3).map(|g| (g, 60000.0 / sc, 30000.0 / sc)).collect(), &s);
|
||||
assert!(c.fits);
|
||||
assert_eq!(c.scale, 500.0);
|
||||
check(&c.rects, &s);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn passt_nichts_dann_kleinster_massstab_ohne_passt() {
|
||||
let s = Sheet::new(210.0, 297.0, false);
|
||||
let c = choose(|sc| vec![(0, 900_000.0 / sc, 900_000.0 / sc)], &s);
|
||||
assert!(!c.fits);
|
||||
assert_eq!(c.scale, 1000.0);
|
||||
assert_eq!(c.rects.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn schriftfeld_bleibt_frei_und_leere_liste() {
|
||||
let s = Sheet::new(594.0, 420.0, true);
|
||||
let items: Vec<(u32, f64, f64)> = (0..12).map(|i| (i / 6, 70.0, 50.0)).collect();
|
||||
let r = pack(&items, &s).expect("passt");
|
||||
check(&r, &s);
|
||||
assert_eq!(pack(&[], &s), Some(vec![]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unsinn_wird_abgelehnt() {
|
||||
let p = Project::default();
|
||||
assert!(query(&p, "kein json").is_err());
|
||||
assert!(query(&p, r#"{"sheetW": -1, "sheetH": 5}"#).is_err());
|
||||
let v = query(&p, r#"{"levels": ["fehlt"], "groups": [0], "sheetW": 841, "sheetH": 594}"#).unwrap();
|
||||
assert_eq!(v["skipped"][0], "fehlt");
|
||||
assert_eq!(v["items"].as_array().map(|a| a.len()), Some(0));
|
||||
}
|
||||
}
|
||||
@@ -75,6 +75,7 @@ pub fn run(p: &Project, name: &str, args: &[f64], text: &str) -> Result<String,
|
||||
("elementSchedule", _) => json(&crate::u_value::element_schedule(p)),
|
||||
("sheetTables", _) => Ok(crate::sheet_table::query(p, text).to_string()),
|
||||
("sheetTableCatalog", _) => Ok(crate::sheet_table::catalog_json().to_string()),
|
||||
("presentationSheet", _) => Ok(crate::presentation_sheet::query(p, text)?.to_string()),
|
||||
("uValue", _) => json(&crate::u_value::query(p, text)),
|
||||
("surfaceOpening", _) => json(&crate::opening_shape::surface_opening_info(p, text)),
|
||||
("openingPreview", _) => json(&crate::opening_preview::opening_preview(p, text)),
|
||||
|
||||
@@ -99,12 +99,7 @@ pub fn viewport_maps(p: &Project, layout: &Layout) -> Vec<VpMap> {
|
||||
continue;
|
||||
}
|
||||
let scale = viewport_scale(vp, Some(snap));
|
||||
let level = p.drawing_levels.iter().find(|l| l.id == snap.active_level_id);
|
||||
let buf = match level {
|
||||
Some(l) if matches!(l.kind, DrawingLevelKind::Section | DrawingLevelKind::Elevation) => section_view_buf(p, l, snap, scale),
|
||||
_ => plan_domains_buf(p, &viewport_args(snap, scale)).ok(),
|
||||
};
|
||||
let Some(buf) = buf else { continue };
|
||||
let Some(buf) = snapshot_buf(p, snap, scale, None) else { continue };
|
||||
let Some(b) = crate::plan::buf::View::parse(&buf).and_then(|v| v.bounds()) else { continue };
|
||||
out.push(VpMap {
|
||||
x_mm: vp.x_mm,
|
||||
@@ -121,6 +116,25 @@ pub fn viewport_maps(p: &Project, layout: &Layout) -> Vec<VpMap> {
|
||||
out
|
||||
}
|
||||
|
||||
/// Plan-Puffer des Inhalts eines Ausschnitts beim Massstab 1:`scale` (Grundriss bzw. Schnitt/Ansicht wie
|
||||
/// im Viewport). `shadows` übersteuert den Schatten der Ansicht (Präsentationsplan [66]: Vorlage vor dem Anwenden).
|
||||
pub fn snapshot_buf(p: &Project, snap: &ViewSnapshot, scale: f64, shadows: Option<bool>) -> Option<Vec<u8>> {
|
||||
match p.drawing_levels.iter().find(|l| l.id == snap.active_level_id) {
|
||||
Some(l) if matches!(l.kind, DrawingLevelKind::Section | DrawingLevelKind::Elevation) => match shadows {
|
||||
Some(s) => section_view_buf(p, &DrawingLevel { shadows: Some(s), ..l.clone() }, snap, scale),
|
||||
None => section_view_buf(p, l, snap, scale),
|
||||
},
|
||||
_ => plan_domains_buf(p, &viewport_args(snap, scale)).ok(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Ausmass (Modell-Meter `[minX, minY, maxX, maxY]`) des Ausschnitt-Inhalts — das Rechteck, dessen Mitte
|
||||
/// der Viewport zentriert.
|
||||
pub fn snapshot_bounds(p: &Project, snap: &ViewSnapshot, scale: f64, shadows: Option<bool>) -> Option<[f64; 4]> {
|
||||
let buf = snapshot_buf(p, snap, scale, shadows)?;
|
||||
crate::plan::buf::View::parse(&buf).and_then(|v| v.bounds())
|
||||
}
|
||||
|
||||
/// Kategorie-Codes, die Schnitt/Ansicht prüfen (`candidateCodes` in `toSection.ts`).
|
||||
fn candidate_codes(p: &Project) -> HashSet<String> {
|
||||
let mut codes: HashSet<String> = p.flat_categories().iter().map(|c| c.code.clone()).collect();
|
||||
|
||||
Reference in new issue
Block a user