From 7f638d206b89d64f23d06385b52bc6309f732473 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 6 Nov 2026 10:06:48 +0000 Subject: [PATCH] =?UTF-8?q?[140]=20Plandarstellung=20Teil=204:=20Blatt-Vie?= =?UTF-8?q?wports=20in=20Tusche=20(Farbe=20=C3=BCber=20Vorlage),=20Anzeige?= =?UTF-8?q?=20=E2=80=9ETusche",=20d=C3=BCnne=20D=C3=A4mmung=20ohne=20Muste?= =?UTF-8?q?r=20ab=201:75,=20Stift-St=C3=A4rken=20nach=20Rangfolge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/core/src/pens.rs | 48 +++++++++++++++++---------- src-tauri/core/src/plan/section.rs | 43 +++++++++++++++++++++++- src-tauri/core/src/sheet_viewports.rs | 39 ++++++++++++++++++---- src-tauri/core/src/standards.rs | 5 +-- src/core/index.ts | 1 + src/export/layoutPdf.ts | 4 +-- src/i18n/de.ts | 4 +-- src/i18n/en.ts | 4 +-- src/plan/presentationSheet.ts | 2 +- src/plan/viewportPlan.test.ts | 27 +++++++++++++-- src/plan/viewportPlan.ts | 20 ++++++++--- src/ui/LayoutSheet.tsx | 4 +-- 12 files changed, 158 insertions(+), 43 deletions(-) diff --git a/src-tauri/core/src/pens.rs b/src-tauri/core/src/pens.rs index 91106410..9d741d67 100644 --- a/src-tauri/core/src/pens.rs +++ b/src-tauri/core/src/pens.rs @@ -73,26 +73,32 @@ pub fn free_color_palette() -> Vec { out } -/// 255 Stifte + Stile der Standardpalette (`generateStandardPenPalette`): `(pens, styles)`. +/// [140] Strichstärken-Rangfolge der Plandarstellung bei 1:100 (mm): Schnittkante Wände 0.25, Decken/Öffnungen +/// 0.18, Symbole/Ansicht 0.13, Schraffur/Bemassung 0.1, Haarlinie 0.02. +pub const PEN_WEIGHT_STEPS: [f64; 5] = [0.25, 0.18, 0.13, 0.1, 0.02]; + +/// 255 Stifte + Stile der Standardpalette (`generateStandardPenPalette`): `(pens, styles)`. Strichstärken nach +/// [`PEN_WEIGHT_STEPS`]: je Farbton die dunkelste Stufe am stärksten (wie die Plan-Rangfolge), Schwarz 0.25. pub fn standard_pen_palette() -> (Vec, Map) { let mut pens = Vec::with_capacity(255); let mut styles = Map::new(); - let mut add = |id: u32, name: String, color: String| { + let mut add = |id: u32, name: String, color: String, weight: f64| { pens.push(json!({"id": id.to_string(), "name": name})); - styles.insert(id.to_string(), json!({"color": color, "weight": PEN_FALLBACK_WEIGHT})); + styles.insert(id.to_string(), json!({"color": color, "weight": weight})); }; - for (id, name, color) in [ - (1, "Rot", "#ff0000"), - (2, "Gelb", "#ffff00"), - (3, "Grün", "#00ff00"), - (4, "Cyan", "#00ffff"), - (5, "Blau", "#0000ff"), - (6, "Magenta", "#ff00ff"), - (7, "Schwarz", "#000000"), - (8, "Dunkelgrau", "#414141"), - (9, "Grau", "#808080"), + let [w25, w18, w13, w10, w02] = PEN_WEIGHT_STEPS; + for (id, name, color, w) in [ + (1, "Rot", "#ff0000", w18), + (2, "Gelb", "#ffff00", w18), + (3, "Grün", "#00ff00", w18), + (4, "Cyan", "#00ffff", w18), + (5, "Blau", "#0000ff", w18), + (6, "Magenta", "#ff00ff", w18), + (7, "Schwarz", "#000000", w25), + (8, "Dunkelgrau", "#414141", w13), + (9, "Grau", "#808080", w10), ] { - add(id, name.to_string(), color.to_string()); + add(id, name.to_string(), color.to_string(), w); } let mut id = 10; for hue in 0..24 { @@ -102,12 +108,13 @@ pub fn standard_pen_palette() -> (Vec, Map) { let level = (step % 5) as f64; let l = 0.75 - level * 0.14; let s = if saturated { 0.85 } else { 0.4 }; - add(id, format!("Stift {id}"), hsl_to_hex(h, s, l)); + // Stufe 0 (hell) … 4 (dunkel): dunkler = stärker. + add(id, format!("Stift {id}"), hsl_to_hex(h, s, l), PEN_WEIGHT_STEPS[4 - (step % 5)]); id += 1; } } - for (gid, color) in [(250, "#333333"), (251, "#5b5b5b"), (252, "#848484"), (253, "#adadad"), (254, "#d6d6d6"), (255, "#ffffff")] { - add(gid, format!("Grau {gid}"), color.to_string()); + for (gid, color, w) in [(250, "#333333", w25), (251, "#5b5b5b", w18), (252, "#848484", w13), (253, "#adadad", w10), (254, "#d6d6d6", w02), (255, "#ffffff", w18)] { + add(gid, format!("Grau {gid}"), color.to_string(), w); } (pens, styles) } @@ -342,6 +349,13 @@ mod tests { assert_eq!(styles.len(), 255); assert_eq!(styles["7"]["color"], "#000000"); assert_eq!(pens[9]["name"], "Stift 10"); + // [140] Stärken nach der Plan-Rangfolge, alle fünf Stufen vertreten. + assert_eq!(styles["7"]["weight"], 0.25); + assert_eq!((styles["10"]["weight"].as_f64(), styles["14"]["weight"].as_f64()), (Some(0.02), Some(0.25))); + for w in PEN_WEIGHT_STEPS { + assert!(styles.values().filter(|s| s["weight"].as_f64() == Some(w)).count() >= 10, "{w}"); + } + assert!(styles.values().all(|s| PEN_WEIGHT_STEPS.contains(&s["weight"].as_f64().unwrap()))); } #[test] diff --git a/src-tauri/core/src/plan/section.rs b/src-tauri/core/src/plan/section.rs index 29f90513..f455daa3 100644 --- a/src-tauri/core/src/plan/section.rs +++ b/src-tauri/core/src/plan/section.rs @@ -2286,6 +2286,30 @@ fn ring_bbox(r: &[[f64; 2]]) -> [f64; 4] { r.iter().fold([f64::INFINITY, f64::INFINITY, f64::NEG_INFINITY, f64::NEG_INFINITY], |b, q| [b[0].min(q[0]), b[1].min(q[1]), b[2].max(q[0]), b[3].max(q[1])]) } +/// [140] Dämmschichten (Dämmschlange, Zickzack, Welle) unter [`THIN_INSULATION_PAPER_MM`] Papierdicke ab 1:75 +/// ohne Muster (nur Füllung und feine Fuge): die Schlange einer 3–4 cm Trittschalldämmung wäre in 1:100 ein +/// dichter Zickzack-Balken. 1:50 (und `scale` 0) zeichnet sie immer. +pub fn plain_thin_insulation(mut cuts: Vec, scale: f64) -> Vec { + if !(scale >= THIN_MERGE_FROM) || !scale.is_finite() { + return cuts; + } + for c in &mut cuts { + let Some(h) = c.hatch.as_mut() else { continue }; + if !matches!(h.pattern, HatchPattern::Insulation | HatchPattern::InsulationHard | HatchPattern::InsulationWave) || h.kind.is_some() { + continue; + } + let half = ring_len(&c.pts) / 2.0; + let thick = if half > 0.0 { ring_area(&c.pts) / half } else { 0.0 }; + if thick * 1000.0 / scale < THIN_INSULATION_PAPER_MM { + h.pattern = HatchPattern::None; + } + } + cuts +} + +/// [140] Papierdicke (mm), unter der Dämmschichten ab 1:75 ohne Muster gezeichnet werden. +pub const THIN_INSULATION_PAPER_MM: f64 = 0.5; + /// [140] Dünne Schnitt-Schichten (Putz, Parkett, Trittschall, Folien) bei 1:`scale` zusammenfassen: eine Schicht /// unter [`walls::THIN_LAYER_PAPER_MM`] Papierdicke (Dicke ≈ Fläche / halber Umfang) übernimmt Füllung und /// Schraffur der dickeren Nachbarschicht desselben Bauteils, mit der sie die längste Kante teilt, und wird mit @@ -2377,7 +2401,7 @@ pub fn section_primitives(out: &Output, mono: bool, hidden_lines: bool, vis: &Vi /// [`section_primitives`] beim Massstab 1:`scale` (dünne Schichten zusammengefasst, [`merge_thin_cuts`]). pub fn section_primitives_at(out: &Output, mono: bool, hidden_lines: bool, vis: &Visibility, scale: f64) -> (Vec, [f64; 4]) { - let merged = merge_thin_cuts(&out.cuts, scale); + let merged = plain_thin_insulation(merge_thin_cuts(&out.cuts, scale), scale); let mut prims = Vec::new(); let mut acc = Acc::new(); let shown = |code: &str| vis.visible(code) && vis.render(code); @@ -3137,6 +3161,23 @@ mod tests { assert!(merge_thin_cuts(&other, 100.0).iter().any(|c| c.fill.as_deref() == Some("#a"))); } + /// [140] Trittschall 4 cm: 1:100 (0.4 mm Papier) ohne Zickzack, 1:50 mit; dicke Dämmung bleibt. + #[test] + fn duenne_daemmung_ohne_muster_ab_1_100() { + let rect = |v0: f64, v1: f64| vec![[0.0, v1], [5.0, v1], [5.0, v0], [0.0, v0]]; + let mk = |v0: f64, v1: f64, pattern: HatchPattern| { + let mut c = Cut::new(Kind::Slab, 0, rect(v0, v1)); + c.hatch = Some(HatchRender { pattern, ..section_hatch() }); + c + }; + let cuts = vec![mk(0.0, 0.04, HatchPattern::Insulation), mk(0.1, 0.26, HatchPattern::Insulation), mk(0.3, 0.33, HatchPattern::InsulationHard), mk(0.4, 0.43, HatchPattern::Diagonal)]; + let pat = |cs: &[Cut]| cs.iter().map(|c| c.hatch.as_ref().unwrap().pattern).collect::>(); + use HatchPattern as P; + assert_eq!(pat(&plain_thin_insulation(cuts.clone(), 50.0)), [P::Insulation, P::Insulation, P::InsulationHard, P::Diagonal], "1:50 alle Muster"); + assert_eq!(pat(&plain_thin_insulation(cuts.clone(), 100.0)), [P::None, P::Insulation, P::None, P::Diagonal], "1:100"); + assert_eq!(pat(&plain_thin_insulation(cuts, 0.0)), [P::Insulation, P::Insulation, P::InsulationHard, P::Diagonal]); + } + #[test] fn beispiel_schnitt_mit_pick_ids() { let p = sample(); diff --git a/src-tauri/core/src/sheet_viewports.rs b/src-tauri/core/src/sheet_viewports.rs index 494fcd26..8d060d24 100644 --- a/src-tauri/core/src/sheet_viewports.rs +++ b/src-tauri/core/src/sheet_viewports.rs @@ -62,8 +62,16 @@ fn detail_of(d: DetailLevel) -> Detail { } } +/// [140] Tusche (Schwarz-Weiss) im Viewport: Standard wie in der App; Farbe nur, wenn die Ansichtsvorlage +/// des Ausschnitts ausdrücklich `mono: false` setzt (z. B. „Präsentation" farbig gewählt). +pub fn snapshot_mono(p: &Project, snap: &ViewSnapshot) -> bool { + let Some(id) = snap.template_id.as_deref() else { return true }; + let t = p.view_templates.iter().flatten().find(|t| t.id == id); + t.and_then(|t| t.mono) != Some(false) +} + /// Plan-Argumente eines Viewports (wie `ViewportPlanSvg`: projektglobal, nicht für den Druck). -pub fn viewport_args(snap: &ViewSnapshot, scale: f64) -> PlanArgs { +pub fn viewport_args(snap: &ViewSnapshot, scale: f64, mono: bool) -> PlanArgs { let (detail, auto_coarse) = crate::plan::domains::effective_detail(detail_of(snap.detail), scale); PlanArgs { floor: snap.active_level_id.clone(), @@ -75,7 +83,7 @@ pub fn viewport_args(snap: &ViewSnapshot, scale: f64) -> PlanArgs { scale, for_print: false, compact: false, - mono: false, + mono, sun_when: None, auto_coarse, } @@ -126,7 +134,7 @@ pub fn snapshot_buf(p: &Project, snap: &ViewSnapshot, scale: f64, shadows: Optio 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(), + _ => plan_domains_buf(p, &viewport_args(snap, scale, snapshot_mono(p, snap))).ok(), } } @@ -159,7 +167,8 @@ fn candidate_codes(p: &Project) -> HashSet { /// TS) fehlen im Schnitt — der Kern hat sie hier nicht. fn section_view_buf(p: &Project, level: &DrawingLevel, snap: &ViewSnapshot, scale: f64) -> Option> { use crate::plan::prim::Primitive; - let args = viewport_args(snap, scale); + let mono = snapshot_mono(p, snap); + let args = viewport_args(snap, scale, mono); let invisible: Vec = candidate_codes(p).into_iter().filter(|c| !args.show.contains(c)).collect(); let text = serde_json::json!({ "level": serde_json::to_value(level).ok()?, @@ -170,9 +179,9 @@ fn section_view_buf(p: &Project, level: &DrawingLevel, snap: &ViewSnapshot, scal }) .to_string(); let raw = if level.kind == DrawingLevelKind::Section { - crate::plan::section::section_plan_buf(p, &[0.0, 1.0, 0.0], &text) + crate::plan::section::section_plan_buf(p, &[f64::from(u8::from(mono)), 1.0, 0.0], &text) } else { - crate::plan::elevation::elevation_plan_buf(p, &[0.0, if level.shadows.unwrap_or(false) { 1.0 } else { 0.0 }, scale], &text) + crate::plan::elevation::elevation_plan_buf(p, &[f64::from(u8::from(mono)), if level.shadows.unwrap_or(false) { 1.0 } else { 0.0 }, scale], &text) } .ok()?; let rv = crate::plan::buf::View::parse(&raw)?; @@ -385,6 +394,22 @@ pub(crate) mod tests { assert!((x - 95.0).abs() < 1e-9 && (y - 70.0).abs() < 1e-9); } + /// [140] Viewports zeichnen in Tusche wie die App; Farbe nur über die Vorlage (`mono: false`). + #[test] + fn viewport_tusche_ausser_vorlage_farbig() { + let mut v = json(); + v["viewTemplates"] = serde_json::json!([{"id": "farbig", "name": "F", "mono": false}, {"id": "tusche", "name": "T", "mono": true}, {"id": "offen", "name": "O"}]); + let mut p: Project = serde_json::from_value(v).unwrap(); + let mut snap = p.view_snapshots.as_ref().unwrap()[0].clone(); + assert!(snapshot_mono(&p, &snap), "ohne Vorlage: Tusche"); + for (id, mono) in [("farbig", false), ("tusche", true), ("offen", true), ("fehlt", true)] { + snap.template_id = Some(id.into()); + assert_eq!(snapshot_mono(&p, &snap), mono, "{id}"); + } + p.view_templates = None; + assert!(snapshot_mono(&p, &snap)); + } + /// [100] Deckenspiegel-Viewport: derselbe Inhalt wie die Deckenspiegel-Ebene (Wände, Untersicht). #[test] fn deckenspiegel_viewport() { @@ -400,7 +425,7 @@ pub(crate) mod tests { assert_eq!(maps.len(), 1); assert_eq!(maps[0].scale, 50.0); let snap = &p.view_snapshots.as_ref().unwrap()[1]; - let direct = crate::plan::domains::plan_domains(&p, &viewport_args(snap, 50.0)).unwrap(); + let direct = crate::plan::domains::plan_domains(&p, &viewport_args(snap, 50.0, snapshot_mono(&p, snap))).unwrap(); assert!(!direct.walls.is_empty() && !direct.ceilings.is_empty(), "Wände und Untersicht im Viewport"); let b = crate::plan::buf::View::parse(&maps[0].buf).unwrap().bounds().unwrap(); assert!(b[2] - b[0] > 9.9 && b[3] - b[1] > 5.9, "Ausmass der Decke: {b:?}"); diff --git a/src-tauri/core/src/standards.rs b/src-tauri/core/src/standards.rs index 428ec0c2..2bd2754f 100644 --- a/src-tauri/core/src/standards.rs +++ b/src-tauri/core/src/standards.rs @@ -268,11 +268,12 @@ pub fn roof_types() -> Vec { /// Alle Standard-Ressourcen je Projekt-Liste, in Abhängigkeitsreihenfolge. /// [66] Ansichtsvorlagen für Pläne „mit einem Klick" (an Geschoss/Schnitt/Ansicht binden oder anwenden): -/// Präsentation (farbig, Schatten, ohne Referenz- und Konstruktionslinien), Eingabe 1:100 und Ausführung 1:50 +/// Präsentation (Tusche wie alle Pläne [140], Farbe über `mono: false` wählbar; Schatten, ohne Referenz- und +/// Konstruktionslinien), Eingabe 1:100 und Ausführung 1:50 /// (schwarz-weiss nach SIA 400). pub fn view_templates() -> Vec { vec![ - json!({"id": "std-vt-praesentation", "name": "Präsentation", "detail": "mittel", "mono": false, "shadows": true, "hiddenLines": false, + json!({"id": "std-vt-praesentation", "name": "Präsentation", "detail": "mittel", "mono": true, "shadows": true, "hiddenLines": false, "layerVisibility": {"90": false, "99": false}}), json!({"id": "std-vt-eingabe-100", "name": "Eingabeplan 1:100", "detail": "mittel", "scaleDenominator": 100, "mono": true, "shadows": false, "layerVisibility": {"99": false}}), diff --git a/src/core/index.ts b/src/core/index.ts index c13c27da..259c92c6 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -244,6 +244,7 @@ export { sectionUAxisModel, } from "../plan/toSection"; export { viewportLevelPlan } from "../plan/viewportPlan"; +export { snapshotMono } from "../plan/viewportPlan"; export { TRUCK_MESH_READY_EVENT, diff --git a/src/export/layoutPdf.ts b/src/export/layoutPdf.ts index be2a7312..9fae6c7c 100644 --- a/src/export/layoutPdf.ts +++ b/src/export/layoutPdf.ts @@ -17,7 +17,7 @@ import { t } from "../i18n/translate"; import { legendPlan, legendPrintSvg } from "./legendSvg"; import { categoryLayerGroups, enablePdfLayers, type PdfLayers } from "./pdfLayers"; import { generatePlan, type Plan } from "../plan/generatePlan"; -import { viewportLevelPlan } from "../plan/viewportPlan"; +import { snapshotMono, viewportLevelPlan } from "../plan/viewportPlan"; import { planToPrintSvg } from "./planToPrintSvg"; import { drawTablesPdf, sheetTables } from "./sheetTable"; import { collectVisibleCodes } from "../model/types"; @@ -169,7 +169,7 @@ async function renderPage( // nach Massstab) — wie ViewportPlan in LayoutSheet.tsx, sonst wiche das PDF von der Vorschau ab. const scaleN = ctx.scaleOverride ?? resolveViewportScale(vp, snap); // Geschoss/Zeichnung, Schnitt oder Ansicht ([115]) — wie ViewportPlanSvg, im Druck-Modus. - const planOf = (visible: Set) => viewportLevelPlan(project, snap.activeLevelId, visible, snap.detail, scaleN, true); + const planOf = (visible: Set) => viewportLevelPlan(project, snap.activeLevelId, visible, snap.detail, scaleN, true, snapshotMono(project, snap)); const draw = async (plan: Plan, transparent: boolean, bounds?: Plan["bounds"]) => { const print = planToPrintSvg(plan, { scaleDenominator: scaleN, pageWidthMm: vp.widthMm, pageHeightMm: vp.heightMm, transparent, bounds }); await doc.svg(print.svg, { x: vp.xMm, y: vp.yMm, width: vp.widthMm, height: vp.heightMm }); diff --git a/src/i18n/de.ts b/src/i18n/de.ts index 16e2b4c4..aa112cb5 100644 --- a/src/i18n/de.ts +++ b/src/i18n/de.ts @@ -91,7 +91,7 @@ export const de = { "display.style.group": "Darstellungsart", "display.style.hint": "Darstellungsart der aktiven Ansicht", "display.style.color": "Farbig", - "display.style.mono": "Schwarz-Weiss", + "display.style.mono": "Tusche", "display.style.shaded": "Schattiert", "display.style.shadedEdges": "Schattiert mit Kanten", "display.style.white": "Weiss", @@ -1145,7 +1145,7 @@ export const de = { "resources.viewTemplates.detail": "Detailgrad", "resources.viewTemplates.scale": "Massstab 1:", "resources.viewTemplates.displayMode": "Darstellungsmodus", - "resources.viewTemplates.mono": "Schwarz-Weiss", + "resources.viewTemplates.mono": "Tusche", "resources.viewTemplates.shadows": "Schatten", "resources.viewTemplates.hiddenLines": "Verdeckte Kanten", "resources.viewTemplates.sketch": "Skizzenstil", diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 7398bb95..4bcf1b22 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -90,7 +90,7 @@ export const en: Record = { "display.style.group": "Display style", "display.style.hint": "Display style of the active view", "display.style.color": "Color", - "display.style.mono": "Black & white", + "display.style.mono": "Ink", "display.style.shaded": "Shaded", "display.style.shadedEdges": "Shaded with edges", "display.style.white": "White", @@ -1139,7 +1139,7 @@ export const en: Record = { "resources.viewTemplates.detail": "Detail level", "resources.viewTemplates.scale": "Scale 1:", "resources.viewTemplates.displayMode": "Display mode", - "resources.viewTemplates.mono": "Black and white", + "resources.viewTemplates.mono": "Ink", "resources.viewTemplates.shadows": "Shadows", "resources.viewTemplates.hiddenLines": "Hidden lines", "resources.viewTemplates.sketch": "Sketch style", diff --git a/src/plan/presentationSheet.ts b/src/plan/presentationSheet.ts index 0b030b44..012e59ac 100644 --- a/src/plan/presentationSheet.ts +++ b/src/plan/presentationSheet.ts @@ -97,7 +97,7 @@ export function presentationTemplate(project: Project): { template: ViewTemplate if (own) return { template: own, isNew: false }; const std = (addedItems(standardsMergeOps(project), "viewTemplates") as ViewTemplate[]).find((t) => t.id === PRESENTATION_TEMPLATE_ID); return { - template: std ?? { id: PRESENTATION_TEMPLATE_ID, name: "Präsentation", detail: "mittel", mono: false, shadows: true, hiddenLines: false }, + template: std ?? { id: PRESENTATION_TEMPLATE_ID, name: "Präsentation", detail: "mittel", mono: true, shadows: true, hiddenLines: false }, isNew: true, }; } diff --git a/src/plan/viewportPlan.test.ts b/src/plan/viewportPlan.test.ts index 930d4520..be9f694b 100644 --- a/src/plan/viewportPlan.test.ts +++ b/src/plan/viewportPlan.test.ts @@ -3,7 +3,7 @@ import { describe, expect, it } from "vitest"; import { buildComplexSampleProject } from "../model/sampleProjectComplex"; import { collectVisibleCodes } from "../model/types"; import { generatePlan } from "./generatePlan"; -import { viewportLevelPlan } from "./viewportPlan"; +import { snapshotMono, viewportLevelPlan } from "./viewportPlan"; const p = buildComplexSampleProject(); const codes = collectVisibleCodes(p.layers); @@ -23,7 +23,30 @@ describe("viewportLevelPlan", () => { it("Geschoss: wie bisher generatePlan", async () => { const plan = await viewportLevelPlan(p, "eg", codes, "mittel", 100); - expect(plan.primitives.length).toBe(generatePlan(p, "eg", codes, undefined, "mittel", false, false, true, 100).primitives.length); + expect(plan.primitives.length).toBe(generatePlan(p, "eg", codes, undefined, "mittel", false, true, true, 100).primitives.length); + }); + + // [140] Blatt und PDF folgen dem Tusche-Standard der App: keine bunten Farben (Ziegelrot …), ausser + // die Vorlage des Ausschnitts wählt Farbe (`mono: false`). + it("Tusche als Standard, Farbe nur auf Wunsch", async () => { + const bunt = (plan: { primitives: unknown[] }) => { + const hex = JSON.stringify(plan.primitives).match(/#[0-9a-fA-F]{6}\b/g) ?? []; + return hex.filter((h) => { + const [r, g, b] = [1, 3, 5].map((i) => parseInt(h.slice(i, i + 2), 16)); + return Math.max(r, g, b) - Math.min(r, g, b) > 24; + }); + }; + expect(bunt(await viewportLevelPlan(p, "ansicht-sued", codes, "mittel", 100))).toEqual([]); + expect(bunt(await viewportLevelPlan(p, "ansicht-sued", codes, "mittel", 100, false, false)).length).toBeGreaterThan(0); + }); + + it("snapshotMono: Vorlage mit mono: false = farbig, sonst Tusche", () => { + const q = { ...p, viewTemplates: [{ id: "f", name: "F", mono: false }, { id: "t", name: "T", mono: true }] }; + const snap = { templateId: undefined as string | undefined }; + expect(snapshotMono(q, snap)).toBe(true); + expect(snapshotMono(q, { templateId: "f" })).toBe(false); + expect(snapshotMono(q, { templateId: "t" })).toBe(true); + expect(snapshotMono(q, { templateId: "weg" })).toBe(true); }); it("unbekannte Ebene: leer, kein Fehler", async () => { diff --git a/src/plan/viewportPlan.ts b/src/plan/viewportPlan.ts index e7946469..a334567e 100644 --- a/src/plan/viewportPlan.ts +++ b/src/plan/viewportPlan.ts @@ -11,11 +11,20 @@ import { computeSection, generateSectionPlan } from "./toSection"; import { generateElevationPlan } from "./toElevation"; import { levelMarkerPrimitives, levelMarksEnabled } from "./levelMarkers"; +/** + * [140] Tusche (Schwarz-Weiss) für einen Viewport: Standard wie in der App; Farbe nur, wenn die + * Ansichtsvorlage des Ausschnitts ausdrücklich `mono: false` setzt (Kern: `sheet_viewports::snapshot_mono`). + */ +export function snapshotMono(project: Pick, snap: { templateId?: string | null }): boolean { + if (!snap.templateId) return true; + return project.viewTemplates?.find((t) => t.id === snap.templateId)?.mono !== false; +} + const EMPTY: Plan = { primitives: [], bounds: { minX: 0, minY: 0, maxX: 1, maxY: 1 } }; /** * Plan der Ebene `levelId` für einen Layout-Viewport bzw. dessen PDF (`forPrint`: `noPrint`-Elemente - * entfallen). Schnitte brauchen die truck-Körper und sind darum asynchron. + * entfallen; `mono`: Tusche, s. {@link snapshotMono}). Schnitte brauchen die truck-Körper und sind darum asynchron. */ export async function viewportLevelPlan( project: Project, @@ -24,23 +33,24 @@ export async function viewportLevelPlan( detail: DetailLevel | undefined, scaleDenominator: number, forPrint = false, + mono = true, ): Promise { const level = project.drawingLevels.find((l) => l.id === levelId); if (!level) return EMPTY; if (level.kind !== "section" && level.kind !== "elevation") { - return generatePlan(project, levelId, visibleCodes, undefined, detail, false, false, true, scaleDenominator, forPrint); + return generatePlan(project, levelId, visibleCodes, undefined, detail, false, mono, true, scaleDenominator, forPrint); } let raw: Plan | null; if (level.kind === "section") { const out = await computeSection(project, level); raw = out - ? generateSectionPlan(out, false, { hiddenLines: level.hiddenLines, visibleCodes, openings: true, scaleDenominator }) + ? generateSectionPlan(out, mono, { hiddenLines: level.hiddenLines, visibleCodes, openings: true, scaleDenominator }) : null; } else { - raw = generateElevationPlan(project, level, { visibleCodes, scaleDenominator }); + raw = generateElevationPlan(project, level, { visibleCodes, scaleDenominator, mono }); } if (!raw || raw.primitives.length === 0) return EMPTY; - const own = generatePlan(project, level.id, visibleCodes, undefined, detail, false, false, false, scaleDenominator, forPrint); + const own = generatePlan(project, level.id, visibleCodes, undefined, detail, false, mono, false, scaleDenominator, forPrint); const marks = levelMarksEnabled(level) ? levelMarkerPrimitives(project, raw.bounds) : []; const b = { ...raw.bounds }; const grow = (x: number, y: number) => { diff --git a/src/ui/LayoutSheet.tsx b/src/ui/LayoutSheet.tsx index 020047e9..d8af11e2 100644 --- a/src/ui/LayoutSheet.tsx +++ b/src/ui/LayoutSheet.tsx @@ -25,7 +25,7 @@ import type { Project, Vec2, } from "../model/types"; -import { createTable, PX_PER_M, sheetTables, TABLE_SOURCES, tableSourceLabel, viewportLevelPlan } from "../core"; +import { createTable, PX_PER_M, sheetTables, TABLE_SOURCES, snapshotMono, tableSourceLabel, viewportLevelPlan } from "../core"; import type { TableOut } from "../core"; import { SheetTableHud } from "./SheetTableHud"; import { planToPrintSvg } from "../export/planToPrintSvg"; @@ -89,7 +89,7 @@ export function ViewportPlanSvg({ // Massstab ZUERST: er geht in die Plan-Erzeugung ein (Bemassung in Papier-mm, s. model/dimension.ts). const scaleN = resolveViewportScale(viewport, snap); // Geschoss/Zeichnung wie bisher; Schnitt/Ansicht über die abgeleitete Projektion ([115], Schnitt asynchron). - void viewportLevelPlan(project, snap.activeLevelId, codes, snap.detail, scaleN) + void viewportLevelPlan(project, snap.activeLevelId, codes, snap.detail, scaleN, false, snapshotMono(project, snap)) .then((plan) => { if (disposed) return; const print = planToPrintSvg(plan, {