[139] Fenster- und Türliste (SVG/PDF): lange Zellen umbrechen statt zu überlappen, Spaltenbreiten angepasst

This commit is contained in:
Claude committed 2026-11-05 13:01:42 +00:00
1 parent 7e968b6b1a
commit 26bbd9adb6
4 files changed
+128 -7

No files matched your search

+2
View File
@@ -2604,6 +2604,8 @@ Modelle · [44] Aus Datei einfügen · [45] Favoriten · [68] Gelände mit Baugr
(◐, DXF-Parser, IFC-Import) · [52] Icons (◐, `CommandIcon.tsx`) · [56] Startparameter · [89] Git-freundliches
Format · [90] Versionsvergleich · [91] Assistent · [92] Speckle.
- ✅ **[139] Kleine Fehler aus der Doku.** (5.11.) Beim Schreiben der Doku gefunden: (1) Befehl `wand` startete den Zauberstab statt der Wand; der Zauberstab heisst jetzt `zauberstab` (Kürzel `zs`), `wand` = Wand, Kern-Befehl `wand` unverändert. (2) Cmd/Strg+S war doppelt belegt: jetzt Speichern (bekannter Pfad ohne Dialog, sonst Dialog), Cmd/Strg+Shift+S = Speichern unter, Teilen auf Cmd/Strg+Shift+J. (3) `schedule --openings --format svg`: Zellen werden in der Blattaufteilung (`area_report.rs`, gilt auch für PDF) auf Spaltenbreite umbrochen statt zu überlappen, Spaltenbreiten der Liste angepasst. Offen: Speichern/Speichern unter nur per vitest geprüft, nicht in der Tauri-App.
- ◐ **[68] Baugrube / Geländebearbeitung.** (30.10.) Kontext-Objekt `excavation` (Rust-Modell, `ContextObject`):
Sohle (`outline`, `bottom` m ±0.00), Böschung `slope` (Standard 45°, je Kante `edgeSlopes`), Schüttung `fillSlope`
(33.7°), Bermen `bermWidth`/`bermHeight`. Neues Gelände = clamp(t, b − d·tan β, b + H(d)) mit d = Abstand zum
+97 -4
View File
@@ -239,6 +239,59 @@ fn wrap(text: &str, max_mm: f64, size_pt: f64) -> Vec<String> {
lines
}
/// Geschätzte Textbreite in mm (Helvetica: Ziffern 0.556 em, Fett etwas breiter; bewusst grosszügig).
fn char_w_mm(size_pt: f64, bold: bool) -> f64 {
size_pt * 0.3528 * if bold { 0.58 } else { 0.52 }
}
/// Bricht eine Zelle in Zeilen, die in `avail_mm` passen: an Leerzeichen, überlange Wörter hart.
fn fit_cell(text: &str, avail_mm: f64, size_pt: f64, bold: bool) -> Vec<String> {
let max = (avail_mm / char_w_mm(size_pt, bold)).floor().max(1.0) as usize;
let mut lines: Vec<String> = Vec::new();
let mut cur = String::new();
let push_word = |cur: &mut String, lines: &mut Vec<String>, w: &str| {
let mut w: Vec<char> = w.chars().collect();
while utf16_len(&w.iter().collect::<String>()) > max {
let mut n = 0;
let mut take = 0;
for (i, c) in w.iter().enumerate() {
n += c.len_utf16();
if n > max {
break;
}
take = i + 1;
}
let take = take.max(1);
if !cur.is_empty() {
lines.push(std::mem::take(cur));
}
lines.push(w.drain(..take).collect());
}
let ws: String = w.iter().collect();
if ws.is_empty() {
return;
}
if cur.is_empty() {
*cur = ws;
} else if utf16_len(cur) + 1 + utf16_len(&ws) <= max {
cur.push(' ');
cur.push_str(&ws);
} else {
lines.push(std::mem::replace(cur, ws));
}
};
for w in text.split_whitespace() {
push_word(&mut cur, &mut lines, w);
}
if !cur.is_empty() {
lines.push(cur);
}
if lines.is_empty() {
lines.push(String::new());
}
lines
}
fn text(x: f64, y: f64, s: &str, size: f64, bold: bool, right: bool) -> Prim {
Prim::Text { x, y, s: s.to_string(), size, bold, right }
}
@@ -288,7 +341,18 @@ pub fn layout(report: &Report, o: &LayoutOptions) -> Layout {
let numeric: Vec<bool> = (0..s.columns.len()).map(|i| s.rows.iter().any(|r| matches!(r.cells.get(i), Some(Cell::Num { .. })))).collect();
// 0 = keine Linie, 1 = oben
let draw_row = |pages: &mut Vec<Vec<Prim>>, y: &mut f64, cells: &[String], bold: bool, top: bool| {
if *y + row_h > height - m {
// Zellen auf Spaltenbreite umbrechen; die Zeile wächst mit der höchsten Zelle.
let wrapped: Vec<Vec<String>> = cells
.iter()
.enumerate()
.map(|(i, c)| {
let w = xs.get(i + 1).copied().unwrap_or(f64::NAN) - xs.get(i).copied().unwrap_or(f64::NAN);
if w.is_finite() { fit_cell(c, (w - 3.0).max(2.0), 8.5, bold) } else { vec![c.clone()] }
})
.collect();
let n = wrapped.iter().map(|l| l.len()).max().unwrap_or(1).max(1);
let h = if n == 1 { row_h } else { n as f64 * 3.6 + 2.4 };
if *y + h > height - m {
pages.push(Vec::new());
*y = m;
}
@@ -296,13 +360,15 @@ pub fn layout(report: &Report, o: &LayoutOptions) -> Layout {
if top {
pg.push(Prim::Line { x1: m, y1: *y, x2: m + inner, y2: *y, w: 0.35 });
}
for (i, c) in cells.iter().enumerate() {
for (i, lines) in wrapped.iter().enumerate() {
let right = numeric.get(i).copied().unwrap_or(false);
let xi = xs.get(i).copied().unwrap_or(f64::NAN);
let xn = xs.get(i + 1).copied().unwrap_or(f64::NAN);
pg.push(text(if right { xn - 1.5 } else { xi + 1.5 }, *y + 4.2, c, 8.5, bold, right));
for (k, l) in lines.iter().enumerate() {
pg.push(text(if right { xn - 1.5 } else { xi + 1.5 }, *y + 4.2 + k as f64 * 3.6, l, 8.5, bold, right));
}
}
*y += row_h;
*y += h;
};
draw_row(&mut pages, &mut y, &s.columns, true, false);
page!().push(Prim::Line { x1: m, y1: y, x2: m + inner, y2: y, w: 0.35 });
@@ -420,6 +486,33 @@ mod tests {
assert_eq!(p["notes"][0], "Eine Fussnote");
}
#[test]
fn lange_zellen_ueberlappen_nicht() {
let r: Report = serde_json::from_value(json!({
"title": "T", "projectName": "",
"sections": [{ "heading": "H", "columns": ["Nr", "Bezeichnung sehr lang", "Mass"], "widths": [1, 1, 1],
"rows": [{ "cells": ["EG.01", "Hebeschiebetür Aluminium dreifach verglast mit Oberlicht", { "n": 1234567.891, "d": 2 }] }] }],
"notes": []
}))
.unwrap();
let l = layout(&r, &LayoutOptions::default());
// Text-Kästen je Grundlinie sammeln: (links, rechts) nach Ausrichtung; keine zwei überlappen.
let mut rows: std::collections::BTreeMap<i64, Vec<(f64, f64)>> = Default::default();
for p in &l.pages[0] {
if let Prim::Text { x, y, s, size, bold, right } = p {
let w = utf16_len(s) as f64 * char_w_mm(*size, *bold) * 0.9;
let (a, b) = if *right { (x - w, *x) } else { (*x, x + w) };
rows.entry((y * 100.0).round() as i64).or_default().push((a, b));
}
}
for (_, mut v) in rows {
v.sort_by(|a, b| a.0.partial_cmp(&b.0).unwrap());
for w in v.windows(2) {
assert!(w[0].1 <= w[1].0, "Überlappung {:?}", w);
}
}
}
#[test]
fn seiten_und_svg() {
let l = layout(&sample(), &LayoutOptions::default());
+26
View File
@@ -302,3 +302,29 @@ describe("scheduleRows — Dächer und Stützen (bisher fehlten sie in Liste/Ele
expect(scheduleRows(proj).some((r) => r.id === "RM1")).toBe(false);
});
});
describe("Fenster- und Türliste als Blatt ([139])", () => {
it("keine zwei Texte derselben Zeile überlappen (Musterhaus komplex)", async () => {
const { buildComplexSampleProject } = await import("../model/sampleProjectComplex");
const { buildOpeningReport } = await import("./openingSchedule");
const { layoutAreaReport } = await import("./areaReport");
const lay = layoutAreaReport(buildOpeningReport(buildComplexSampleProject()));
let texts = 0;
for (const page of lay.pages) {
const rows = new Map<number, [number, number][]>();
for (const p of page) {
if (p.k !== "text") continue;
texts++;
const w = p.s.length * p.size * 0.3528 * 0.45; // untere Schätzung der Breite
const box: [number, number] = p.align === "right" ? [p.x - w, p.x] : [p.x, p.x + w];
const key = Math.round(p.y * 100);
rows.set(key, [...(rows.get(key) ?? []), box]);
}
for (const boxes of rows.values()) {
boxes.sort((a, b) => a[0] - b[0]);
for (let i = 1; i < boxes.length; i++) expect(boxes[i - 1]![1]).toBeLessThanOrEqual(boxes[i]![0] + 1e-6);
}
}
expect(texts).toBeGreaterThan(50);
});
});
+3 -3
View File
@@ -102,7 +102,7 @@ function withReveals(sec: ReportSection, rows: OpeningScheduleRow[]): ReportSect
return {
...sec,
columns: [...sec.columns, ...keys.map((name) => t("openings.col.reveal", { name }))],
widths: [...sec.widths, ...keys.map(() => 1.4)],
widths: [...sec.widths, ...keys.map(() => 1.9)],
rows: sec.rows.map((row, i) => ({ ...row, cells: [...row.cells, ...keys.map((k) => num(revealArea(rows[i]!, k), 2))] })),
};
}
@@ -119,7 +119,7 @@ function windowBase(rows: OpeningScheduleRow[]): ReportSection {
return {
heading: t("openings.windows"),
columns: [t("openings.col.mark"), t("openings.col.type"), t("openings.col.floor"), t("openings.col.rooms"), t("openings.col.width"), t("openings.col.height"), t("openings.col.sill"), t("openings.col.sound"), t("openings.col.u"), t("openings.col.rc"), t("openings.col.ext"), t("openings.col.notes")],
widths: [1.4, 2.4, 1.4, 3.2, 1.2, 1.2, 1.2, 1.6, 1.1, 1.1, 1.4, 3],
widths: [1.3, 3.4, 1.9, 3, 1.4, 1.4, 1.4, 1.5, 1.3, 1.3, 1.6, 2.6],
rows: rows.map((r): ReportRow => ({ cells: [r.mark, r.typeName, r.floor, roomsText(r), num(r.width, 2), num(r.height, 2), num(r.sill, 2), r.soundClass, num(r.uValue, 2), r.burglaryClass, externalText(r.external), r.notes] })),
};
}
@@ -128,7 +128,7 @@ function doorBase(rows: OpeningScheduleRow[]): ReportSection {
return {
heading: t("openings.doors"),
columns: [t("openings.col.mark"), t("openings.col.type"), t("openings.col.floor"), t("openings.col.rooms"), t("openings.col.width"), t("openings.col.height"), t("openings.col.clearWidth"), t("openings.col.clearHeight"), t("openings.col.swing"), t("openings.col.fire"), t("openings.col.sound"), t("openings.col.u"), t("openings.col.rc"), t("openings.col.ext"), t("openings.col.notes")],
widths: [1.4, 2.2, 1.3, 3, 1.1, 1.1, 1.2, 1.2, 2.6, 1.1, 1.5, 1, 1, 1.3, 2.6],
widths: [1.3, 3, 1.9, 3, 1.3, 1.3, 1.4, 1.4, 2.6, 1.1, 1.5, 1.1, 1.3, 1.6, 2.4],
rows: rows.map((r): ReportRow => ({ cells: [r.mark, r.typeName, r.floor, roomsText(r), num(r.width, 2), num(r.height, 2), num(r.clearWidth, 2), num(r.clearHeight, 2), swingText(r), r.fireRating, r.soundClass, num(r.uValue, 2), r.burglaryClass, externalText(r.external), r.notes] })),
};
}