[158] Raumbuch: Nutzung und Oberflächen je Raum (Boden/Wand/Decke, Aufbau), Raum-Belag im Grundriss statt Deckenbelag, Nassraum aus Nutzung, Belagszeile im Stempel, Objekt-Info, Liste/Blatt-Tabelle/CSV, Mengen, IFC-Psets mit Rundreise
This commit is contained in:
27 files changed
+1406
-26
No files matched your search
@@ -1184,7 +1184,31 @@ pub fn ifc_export_data(src: &Project, opt: &IfcOptions) -> Result<Flat, String>
|
||||
w_pts(&mut f, &room.boundary);
|
||||
let cat = f.str(&sia_key(room.sia_category));
|
||||
f.nums(&[area.net, area.gross, cat]);
|
||||
w_psets(&mut f, &[Pset { name: "Pset_SpaceCommon", props: common }]);
|
||||
// [158] Raumbuch: Oberflächen als Pset_SpaceCoveringRequirements (IFC2x3: in Pset_SpaceCommon),
|
||||
// Nutzung und Bodenaufbau im eigenen Pset; nur mit Angaben im Modell.
|
||||
let label = |v: Option<&str>| crate::room_book::finish_label(&p, v);
|
||||
let coverings: Vec<Prop> = [("FloorCovering", label(room.floor_finish.as_deref())), ("WallCovering", label(room.wall_finish.as_deref())), ("CeilingCovering", label(room.ceiling_finish.as_deref()))]
|
||||
.into_iter()
|
||||
.filter(|(_, v)| !v.is_empty())
|
||||
.map(|(k, v)| Prop::Label(k, v))
|
||||
.collect();
|
||||
let mut psets = Vec::new();
|
||||
if opt.ifc2x3 {
|
||||
common.extend(coverings);
|
||||
psets.push(Pset { name: "Pset_SpaceCommon", props: common });
|
||||
} else {
|
||||
psets.push(Pset { name: "Pset_SpaceCommon", props: common });
|
||||
if !coverings.is_empty() {
|
||||
psets.push(Pset { name: "Pset_SpaceCoveringRequirements", props: coverings });
|
||||
}
|
||||
}
|
||||
let mut book: Vec<Prop> = Vec::new();
|
||||
book.extend(room.usage.map(|u| u.key()).filter(|k| !k.is_empty()).map(|k| Prop::Label("Usage", k.to_string())));
|
||||
book.extend(room.floor_build_up.as_deref().map(str::trim).filter(|s| !s.is_empty()).map(|s| Prop::Label("FloorBuildUp", s.to_string())));
|
||||
if !book.is_empty() {
|
||||
psets.push(Pset { name: "Dossier_RoomBook", props: book });
|
||||
}
|
||||
w_psets(&mut f, &psets);
|
||||
}
|
||||
f.num(REC_END_SPACES);
|
||||
|
||||
|
||||
@@ -862,10 +862,25 @@ fn elements_ops(root: &Map<String, Value>, meta: &Value, products: &[IfcProduct]
|
||||
let n = boundary.len() as f64;
|
||||
let (sx, sy) = boundary.iter().fold((0.0, 0.0), |(a, b), p| (a + p["x"].as_f64().unwrap_or(f64::NAN), b + p["y"].as_f64().unwrap_or(f64::NAN)));
|
||||
let name = [s.long_name.as_deref(), s.name.as_deref()].into_iter().flatten().find(|x| !x.is_empty()).map(str::to_string).unwrap_or_else(|| format!("Raum {}", rooms_before + rooms.len() + 1));
|
||||
rooms.push(json!({
|
||||
let mut room = json!({
|
||||
"id": ctx.new_id("room"), "type": "room", "floorId": fid, "categoryCode": ROOM_CATEGORY, "siaCategory": sia,
|
||||
"name": name, "boundary": boundary, "color": room_color, "stampAnchor": {"x": js_num(sx / n), "y": js_num(sy / n)},
|
||||
}));
|
||||
});
|
||||
// [158] Raumbuch aus den Psets: Nutzung (bekannte Kennung), Oberflächen (Material gleichen Namens →
|
||||
// seine Kennung, sonst Freitext), Bodenaufbau.
|
||||
if let Some(u) = s.info.text("Usage").and_then(|u| crate::model::RoomUsage::from_key(&u)) {
|
||||
room["usage"] = u.key().into();
|
||||
}
|
||||
for (prop, field) in [("FloorCovering", "floorFinish"), ("WallCovering", "wallFinish"), ("CeilingCovering", "ceilingFinish")] {
|
||||
if let Some(t) = s.info.text(prop) {
|
||||
let comp = root.get("components").and_then(Value::as_array).and_then(|cs| cs.iter().find(|c| c.get("name").and_then(Value::as_str).map(str::trim) == Some(t.as_str()))).and_then(|c| c.get("id")).and_then(Value::as_str);
|
||||
room[field] = comp.map_or_else(|| t.clone(), str::to_string).into();
|
||||
}
|
||||
}
|
||||
if let Some(t) = s.info.text("FloorBuildUp") {
|
||||
room["floorBuildUp"] = t.into();
|
||||
}
|
||||
rooms.push(room);
|
||||
}
|
||||
|
||||
let mut roof_types = list_of(root, "roofTypes");
|
||||
@@ -1175,6 +1190,33 @@ mod tests {
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
/// [158] Raumbuch-Eigenschaften eines IfcSpace: Nutzung, Oberflächen (Material gleichen Namens → Kennung,
|
||||
/// sonst Freitext), Bodenaufbau; unbekannte Nutzung fällt weg.
|
||||
#[test]
|
||||
fn space_room_book_props() {
|
||||
let data = vec![0.0, 2.6, 4.0, 0.0, 0.0, 3.0, 0.0, 3.0, 2.0, 0.0, 2.0];
|
||||
let mut sp = json!({"kind": "space", "at": 0, "n": 11, "storey": 0, "layers": [], "classifications": [], "longName": "Bad",
|
||||
"common": {"Usage": "bath", "FloorCovering": "Feinsteinzeug", "WallCovering": "Abrieb 1 mm", "FloorBuildUp": "UB 80"}});
|
||||
let meta = |sp: &Value| json!({
|
||||
"schema": "IFC4", "lengthScale": 1, "products": [], "skippedItems": {}, "skippedProducts": {},
|
||||
"productsWithoutGeometry": 0, "simplifiedBooleans": 0, "voidsApplied": 0, "voidsIgnored": 0, "parseErrors": 0, "truncated": false,
|
||||
"elements": {"storeys": [{"globalId": "s", "name": "EG", "elevation": 0.0}], "elements": [sp], "kept": {}, "keptReasons": {}},
|
||||
});
|
||||
let mut base = root();
|
||||
base.remove("geoAnchor");
|
||||
base.insert("components".into(), json!([{"id": "fl", "name": "Feinsteinzeug", "color": "#ccc"}]));
|
||||
let opts = IfcOptions { file_name: "a.ifc".into(), group: None, elements: true };
|
||||
let r = ifc_import(&base, &meta(&sp).to_string(), &[], &[], &data, &opts, 0.0).unwrap();
|
||||
let rooms = added(&r.ops, "rooms");
|
||||
assert_eq!(rooms.len(), 1);
|
||||
let room = &rooms[0];
|
||||
assert_eq!((room["usage"].as_str(), room["floorFinish"].as_str(), room["wallFinish"].as_str(), room["floorBuildUp"].as_str()), (Some("bath"), Some("fl"), Some("Abrieb 1 mm"), Some("UB 80")));
|
||||
assert!(room.get("ceilingFinish").is_none());
|
||||
sp["common"] = json!({"Usage": "sauna"});
|
||||
let r = ifc_import(&base, &meta(&sp).to_string(), &[], &[], &data, &opts, 0.0).unwrap();
|
||||
assert!(added(&r.ops, "rooms")[0].get("usage").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn roof_stair_arc_wall_round_opening_type_by_name_and_map_shift() {
|
||||
let (m, data) = meta("Haustür Eiche");
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
pub mod export_schedule;
|
||||
pub mod opening_schedule;
|
||||
pub mod room_book;
|
||||
pub mod u_value;
|
||||
pub mod sheet_table;
|
||||
pub mod terrain;
|
||||
|
||||
@@ -3468,6 +3468,10 @@ pub struct RoomStamp {
|
||||
#[serde(rename = "roundingStep", default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub rounding_step: Option<f64>,
|
||||
/// [158] Bodenbelag des Raums als Zeile anzeigen (Live-Zeile). Fehlt/false: keine Belagszeile.
|
||||
#[serde(rename = "showFinish", default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub show_finish: Option<bool>,
|
||||
#[serde(flatten)]
|
||||
#[ts(skip)]
|
||||
pub extra: Extra,
|
||||
@@ -3531,11 +3535,67 @@ pub struct Room {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub stamp: Option<RoomStamp>,
|
||||
/// [158] Raumbuch: Nutzung (Wohnen, Bad, Verkehr …); Nassraum wird daraus abgeleitet.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub usage: Option<RoomUsage>,
|
||||
/// [158] Bodenbelag: Kennung eines Bauteil-Materials (`components`) oder Freitext. Ein Material mit
|
||||
/// Oberflächenmuster gilt im Grundriss im Raum statt des Belags der Decke.
|
||||
#[serde(rename = "floorFinish", default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub floor_finish: Option<String>,
|
||||
/// [158] Wandoberfläche (Material-Kennung oder Freitext).
|
||||
#[serde(rename = "wallFinish", default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub wall_finish: Option<String>,
|
||||
/// [158] Deckenoberfläche (Material-Kennung oder Freitext).
|
||||
#[serde(rename = "ceilingFinish", default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub ceiling_finish: Option<String>,
|
||||
/// [158] Bodenaufbau als Freitext (z. B. „Parkett 15, UB 80, TSD 20").
|
||||
#[serde(rename = "floorBuildUp", default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub floor_build_up: Option<String>,
|
||||
#[serde(flatten)]
|
||||
#[ts(skip)]
|
||||
pub extra: Extra,
|
||||
}
|
||||
|
||||
/// [158] Nutzung eines Raums (Raumbuch). Nassräume: Bad, WC, Dusche, Waschküche.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize, TS)]
|
||||
pub enum RoomUsage {
|
||||
#[default]
|
||||
#[serde(rename = "living")]
|
||||
Living,
|
||||
#[serde(rename = "sleeping")]
|
||||
Sleeping,
|
||||
#[serde(rename = "kitchen")]
|
||||
Kitchen,
|
||||
#[serde(rename = "dining")]
|
||||
Dining,
|
||||
#[serde(rename = "bath")]
|
||||
Bath,
|
||||
#[serde(rename = "wc")]
|
||||
Wc,
|
||||
#[serde(rename = "shower")]
|
||||
Shower,
|
||||
#[serde(rename = "laundry")]
|
||||
Laundry,
|
||||
#[serde(rename = "circulation")]
|
||||
Circulation,
|
||||
#[serde(rename = "technical")]
|
||||
Technical,
|
||||
#[serde(rename = "storage")]
|
||||
Storage,
|
||||
#[serde(rename = "office")]
|
||||
Office,
|
||||
#[serde(rename = "other")]
|
||||
Other,
|
||||
#[serde(other)]
|
||||
#[ts(skip)]
|
||||
Unknown,
|
||||
}
|
||||
|
||||
// ── Freie 2D-Zeichengeometrie (Drawing2D) ──────────────────────────────────
|
||||
// Ein semantisches 2D-Element (wie Wall/Door), das beim Rendern abgeleitet wird
|
||||
// (keine vorab erzeugten Plan-Primitive). Siehe docs/design/drawing-tools.md §7.
|
||||
@@ -4534,6 +4594,9 @@ pub enum LayoutTableSource {
|
||||
/// [68] Erdarbeiten: Baugruben mit Abtrag/Auftrag/Hinterfüllung.
|
||||
#[serde(rename = "earthworks")]
|
||||
Earthworks,
|
||||
/// [158] Raumbuch: Oberflächen je Raum.
|
||||
#[serde(rename = "roomBook")]
|
||||
RoomBook,
|
||||
#[serde(other)]
|
||||
#[ts(skip)]
|
||||
Unknown,
|
||||
|
||||
@@ -115,7 +115,7 @@ pub fn reveal_areas(p: &Project, w: &Wall, o: &Opening) -> Vec<RevealArea> {
|
||||
acc
|
||||
}
|
||||
|
||||
fn in_ring(x: f64, y: f64, ring: &[Vec2]) -> bool {
|
||||
pub(crate) fn in_ring(x: f64, y: f64, ring: &[Vec2]) -> bool {
|
||||
let mut inside = false;
|
||||
let mut j = ring.len().wrapping_sub(1);
|
||||
for i in 0..ring.len() {
|
||||
@@ -139,18 +139,27 @@ fn room_at(p: &Project, floor_id: &str, x: f64, y: f64) -> Option<String> {
|
||||
p.rooms.as_deref().unwrap_or(&[]).iter().find(|r| r.floor_id == floor_id && in_ring(x, y, &r.boundary)).map(room_label)
|
||||
}
|
||||
|
||||
/// Räume links/rechts der Wand an der Achsposition `at` (Meter ab Wandanfang).
|
||||
fn rooms_beside(p: &Project, w: &Wall, at: f64) -> (Option<String>, Option<String>) {
|
||||
/// Prüfpunkte links/rechts der Wand an der Achsposition `at` (Meter ab Wandanfang), je eine halbe
|
||||
/// Wanddicke plus 10 cm neben der Achse; `None` bei entarteter Wand.
|
||||
pub(crate) fn side_points(p: &Project, w: &Wall, at: f64) -> Option<([f64; 2], [f64; 2])> {
|
||||
let (dx, dy) = (w.end.x - w.start.x, w.end.y - w.start.y);
|
||||
let len = hypot2(dx, dy);
|
||||
if !(len > 1e-9) {
|
||||
return (None, None);
|
||||
return None;
|
||||
}
|
||||
let (ux, uy) = (dx / len, dy / len);
|
||||
let (px, py) = (w.start.x + ux * at, w.start.y + uy * at);
|
||||
let (nx, ny) = (-uy, ux);
|
||||
let d = Project::type_thickness(&p.wall_type_or_fallback(w).layers) + 0.1;
|
||||
(room_at(p, &w.floor_id, px + nx * d, py + ny * d), room_at(p, &w.floor_id, px - nx * d, py - ny * d))
|
||||
Some(([px + nx * d, py + ny * d], [px - nx * d, py - ny * d]))
|
||||
}
|
||||
|
||||
/// Räume links/rechts der Wand an der Achsposition `at` (Meter ab Wandanfang).
|
||||
fn rooms_beside(p: &Project, w: &Wall, at: f64) -> (Option<String>, Option<String>) {
|
||||
match side_points(p, w, at) {
|
||||
Some((l, r)) => (room_at(p, &w.floor_id, l[0], l[1]), room_at(p, &w.floor_id, r[0], r[1])),
|
||||
None => (None, None),
|
||||
}
|
||||
}
|
||||
|
||||
fn has_rooms(p: &Project, floor_id: &str) -> bool {
|
||||
|
||||
@@ -365,11 +365,14 @@ fn floor_finishes(c: &Ctx, rooms: &[Primitive], out: &mut Vec<Primitive>) {
|
||||
})
|
||||
.collect()
|
||||
};
|
||||
if ceilings.is_empty() {
|
||||
// [158] Räume mit eigenem Bodenbelag (Bauteil-Material): dort gilt ihr Belag statt dem der Decke.
|
||||
let own = ff::own_finish_rooms(c);
|
||||
if ceilings.is_empty() && own.is_empty() {
|
||||
return;
|
||||
}
|
||||
// Aussparungen und Nassräume erst rechnen, wenn ein Belag gezeichnet wird.
|
||||
let mut excl: Option<Vec<Vec<[f64; 2]>>> = None;
|
||||
let own_rings: Vec<Vec<[f64; 2]>> = own.iter().map(|(_, _, ring)| ring.clone()).collect();
|
||||
// Belag je Quelle nach Darstellung und Regeln: (Stücke, Stärke, Farbe, Ebene).
|
||||
let mut jobs: Vec<(Vec<([f64; 2], [f64; 2])>, f64, String, &str, Option<String>)> = Vec::new();
|
||||
let mut wet: Option<Vec<Vec<[f64; 2]>>> = None;
|
||||
for ce in ceilings {
|
||||
// [33] Schicht-Override mit eigener Schraffur bzw. ohne Muster: kein Belagsmuster.
|
||||
@@ -394,6 +397,31 @@ fn floor_finishes(c: &Ctx, rooms: &[Primitive], out: &mut Vec<Primitive>) {
|
||||
ff::clip_inside_any(&segs, wet.get_or_insert_with(|| ff::wet_rooms(c)))
|
||||
}
|
||||
};
|
||||
let segs = if own_rings.is_empty() { segs } else { ff::clip_outside_all(segs, &own_rings) };
|
||||
let w = ov.lineweight.map_or(w, |x| ff::weight(Some(x)));
|
||||
jobs.push((segs, w, ov.color.unwrap_or(ink), &ce.category_code, ov.linetype_id));
|
||||
}
|
||||
for (room, comp, ring) in &own {
|
||||
let ov = c.overrides(Some("floor_finish"), &room.category_code, Some(&comp.name));
|
||||
let show = match ov.hide {
|
||||
Some(true) => false,
|
||||
Some(false) => true,
|
||||
None => match mode {
|
||||
ff::Show::Off => false,
|
||||
ff::Show::All => true,
|
||||
ff::Show::Wet => ff::is_tile(comp) && ff::is_wet_room(room),
|
||||
},
|
||||
};
|
||||
if !show {
|
||||
continue;
|
||||
}
|
||||
let Some((segs, w)) = ff::room_segments(comp, ring, c.a.scale) else { continue };
|
||||
let w = ov.lineweight.map_or(w, |x| ff::weight(Some(x)));
|
||||
jobs.push((segs, w, ov.color.unwrap_or_else(|| ff::INK.to_string()), &room.category_code, ov.linetype_id));
|
||||
}
|
||||
// Aussparungen erst rechnen, wenn ein Belag gezeichnet wird.
|
||||
let mut excl: Option<Vec<Vec<[f64; 2]>>> = None;
|
||||
for (segs, w, ink, cat, linetype) in jobs {
|
||||
if segs.is_empty() {
|
||||
continue;
|
||||
}
|
||||
@@ -412,10 +440,8 @@ fn floor_finishes(c: &Ctx, rooms: &[Primitive], out: &mut Vec<Primitive>) {
|
||||
v
|
||||
});
|
||||
let segs = ff::clip_outside_all(segs, excl);
|
||||
let w = ov.lineweight.map_or(w, |x| ff::weight(Some(x)));
|
||||
let ink = ov.color.unwrap_or(ink);
|
||||
let dash = overrides::linetype_dash(p, ov.linetype_id.as_deref());
|
||||
let greyed = Some(c.greyed(&ce.category_code));
|
||||
let dash = overrides::linetype_dash(p, linetype.as_deref());
|
||||
let greyed = Some(c.greyed(cat));
|
||||
for (a, b) in segs {
|
||||
out.push(line(pv(a), pv(b), "floor-finish-pattern", w, dash.clone(), &ink, greyed));
|
||||
}
|
||||
@@ -968,6 +994,14 @@ fn rooms(c: &Ctx, out: &mut Vec<Primitive>, bounds: &mut Bounds, obstacles: &sup
|
||||
(room.stamp_doc.clone().unwrap_or_else(|| doc_from_text(&room.name)), lines)
|
||||
}
|
||||
};
|
||||
// [158] Belagszeile (Einstellung am Stempel, Vorgabe aus): Bodenbelag des Raums.
|
||||
let mut extra_lines = extra_lines;
|
||||
if !overview && room.stamp.as_ref().and_then(|s| s.show_finish) == Some(true) {
|
||||
let label = crate::room_book::finish_label(c.p, room.floor_finish.as_deref());
|
||||
if !label.is_empty() {
|
||||
extra_lines.push(StampLine { text: label, align: Align::Center });
|
||||
}
|
||||
}
|
||||
let candidates = if room.stamp_anchor.is_some() { vec![at] } else { stamp_candidates(&pts, pole) };
|
||||
// [140] Teil 6: ohne eigenen Anker weicht der Stempel anderem Planinhalt im Raum aus (`place_stamp`).
|
||||
let obst = if room.stamp_anchor.is_some() { Default::default() } else { obstacles.within(ring_bounds(&pts)) };
|
||||
@@ -2204,6 +2238,91 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// [158] Raum mit eigenem Bodenbelag (Material mit Muster): im Raum gilt sein Muster, auf den Raum
|
||||
/// beschnitten, statt des Deckenbelags; ausserhalb bleibt der Deckenbelag.
|
||||
#[test]
|
||||
fn belag_aus_raum_statt_decke() {
|
||||
let mut p = belag_projekt(SurfacePatternKind::Grid, 0.3, 0.3);
|
||||
p.components.push(Component { id: "fliese".into(), name: "Feinsteinzeug".into(), surface_pattern: Some(SurfacePattern { kind: SurfacePatternKind::Grid, spacing: 0.6, height: Some(0.6), ..Default::default() }), ..Default::default() });
|
||||
let mut bad = p.rooms.as_ref().unwrap()[0].clone();
|
||||
bad.id = "R-bad".into();
|
||||
bad.floor_id = "og".into();
|
||||
bad.name = "Raum 7".into();
|
||||
bad.stamp_anchor = Some(Vec2 { x: 4.5, y: 3.6 });
|
||||
bad.boundary = vec![Vec2 { x: 3.0, y: 2.0 }, Vec2 { x: 4.8, y: 2.0 }, Vec2 { x: 4.8, y: 3.8 }, Vec2 { x: 3.0, y: 3.8 }];
|
||||
p.rooms.as_mut().unwrap().push(bad.clone());
|
||||
let before = belag(&p, "og", 1.0, 50.0, serde_json::json!({}));
|
||||
let ring: Vec<[f64; 2]> = bad.boundary.iter().map(|v| [v.x, v.y]).collect();
|
||||
let inside = |l: &[(Vec2, Vec2, f64, String)]| l.iter().filter(|(a, b, ..)| crate::surface_pattern::point_in([(a.x + b.x) / 2.0, (a.y + b.y) / 2.0], &ring)).count();
|
||||
let n_before = inside(&before);
|
||||
p.rooms.as_mut().unwrap().last_mut().unwrap().floor_finish = Some("fliese".into());
|
||||
let after = belag(&p, "og", 1.0, 50.0, serde_json::json!({}));
|
||||
let n_after = inside(&after);
|
||||
assert!(n_after > 0 && n_before > 0, "{n_after} / {n_before}");
|
||||
// Im Raum nur noch Linien des 0.6-Rasters (x bzw. y auf 3.0 + k·0.6).
|
||||
for (a, b, ..) in after.iter().filter(|(a, b, ..)| crate::surface_pattern::point_in([(a.x + b.x) / 2.0, (a.y + b.y) / 2.0], &ring)) {
|
||||
let on = |v: f64| ((v - 3.0) / 0.6 - ((v - 3.0) / 0.6).round()).abs() < 1e-6 || ((v - 2.0) / 0.6 - ((v - 2.0) / 0.6).round()).abs() < 1e-6;
|
||||
assert!((a.x - b.x).abs() < 1e-9 && on(a.x) || (a.y - b.y).abs() < 1e-9 && on(a.y), "{a:?}–{b:?}");
|
||||
}
|
||||
// Ausserhalb unverändert der Deckenbelag (gleiche Linienlänge ausserhalb des Raums).
|
||||
let outside_len = |l: &[(Vec2, Vec2, f64, String)]| {
|
||||
let mut rest = Vec::new();
|
||||
for (a, b, ..) in l {
|
||||
crate::surface_pattern::clip_outside_poly([a.x, a.y], [b.x, b.y], &ring, &mut rest);
|
||||
}
|
||||
rest.iter().map(|(a, b)| ((b[0] - a[0]).powi(2) + (b[1] - a[1]).powi(2)).sqrt()).sum::<f64>()
|
||||
};
|
||||
assert!((outside_len(&before) - outside_len(&after)).abs() < 1e-6, "{} {}", outside_len(&before), outside_len(&after));
|
||||
// Freitext-Belag: kein Muster bekannt, der Deckenbelag bleibt.
|
||||
p.rooms.as_mut().unwrap().last_mut().unwrap().floor_finish = Some("Linoleum".into());
|
||||
assert_eq!(belag(&p, "og", 1.0, 50.0, serde_json::json!({})).len(), before.len());
|
||||
}
|
||||
|
||||
/// [158] Nassraum aus der Nutzung: im Modus „Nassräume" (1:100) zeigt der Raum mit Nutzung „Dusche"
|
||||
/// und Plattenbelag sein Muster, auch ohne Deckenbelag und ohne passenden Namen.
|
||||
#[test]
|
||||
fn belag_nassraum_aus_nutzung() {
|
||||
let mut p = belag_projekt(SurfacePatternKind::RunningBond, 0.6, 0.1);
|
||||
p.components.push(Component { id: "fliese".into(), name: "Feinsteinzeug".into(), surface_pattern: Some(SurfacePattern { kind: SurfacePatternKind::Grid, spacing: 0.3, height: Some(0.3), ..Default::default() }), ..Default::default() });
|
||||
let mut r = p.rooms.as_ref().unwrap()[0].clone();
|
||||
r.id = "R-d".into();
|
||||
r.floor_id = "og".into();
|
||||
r.name = "Raum 7".into();
|
||||
r.stamp_anchor = Some(Vec2 { x: 4.5, y: 3.6 });
|
||||
r.boundary = vec![Vec2 { x: 3.0, y: 2.0 }, Vec2 { x: 4.8, y: 2.0 }, Vec2 { x: 4.8, y: 3.8 }, Vec2 { x: 3.0, y: 3.8 }];
|
||||
r.floor_finish = Some("fliese".into());
|
||||
p.rooms.as_mut().unwrap().push(r);
|
||||
set_finish(&mut p, "og", Some(FloorFinishDisplay::Wet));
|
||||
assert!(belag(&p, "og", 1.0, 100.0, serde_json::json!({})).is_empty(), "ohne Nutzung, Name kein Nassraum");
|
||||
p.rooms.as_mut().unwrap().last_mut().unwrap().usage = Some(RoomUsage::Shower);
|
||||
let l = belag(&p, "og", 1.0, 100.0, serde_json::json!({}));
|
||||
assert!(l.len() >= 4, "{}", l.len());
|
||||
// Nutzung „Lager" schlägt den Namen „Bad".
|
||||
let last = p.rooms.as_mut().unwrap().last_mut().unwrap();
|
||||
last.usage = Some(RoomUsage::Storage);
|
||||
last.name = "Bad".into();
|
||||
assert!(belag(&p, "og", 1.0, 100.0, serde_json::json!({})).is_empty());
|
||||
}
|
||||
|
||||
/// [158] Belagszeile im Raumstempel nur mit Einstellung (Vorgabe aus).
|
||||
#[test]
|
||||
fn stempel_belagszeile() {
|
||||
let mut p = sample();
|
||||
p.components.push(Component { id: "par".into(), name: "Parkett Eiche".into(), ..Default::default() });
|
||||
let r = &mut p.rooms.as_mut().unwrap()[0];
|
||||
r.floor_finish = Some("par".into());
|
||||
r.stamp = Some(RoomStamp { name: "Wohnen".into(), show_floor_area: true, ..Default::default() });
|
||||
let (floor, cat) = (r.floor_id.clone(), r.category_code.clone());
|
||||
let lines = |p: &Project| {
|
||||
let t = serde_json::json!({ "floor": floor, "show": [cat], "grey": [], "scale": 50 }).to_string();
|
||||
let d = plan_domains(p, &PlanArgs::parse(1.0, &t).unwrap()).unwrap();
|
||||
d.rooms.iter().find_map(|q| match q { Primitive::Text { extra_lines, room_id: Some(_), .. } => Some(extra_lines.iter().map(|l| l.text.clone()).collect::<Vec<_>>()), _ => None }).unwrap()
|
||||
};
|
||||
assert!(!lines(&p).iter().any(|l| l == "Parkett Eiche"));
|
||||
p.rooms.as_mut().unwrap()[0].stamp.as_mut().unwrap().show_finish = Some(true);
|
||||
assert!(lines(&p).iter().any(|l| l == "Parkett Eiche"), "{:?}", lines(&p));
|
||||
}
|
||||
|
||||
/// [156] Override-Regeln der Bauteilart „floor_finish": ausblenden, erzwingen, färben.
|
||||
#[test]
|
||||
fn belag_regeln() {
|
||||
|
||||
@@ -58,8 +58,13 @@ fn has_any(text: &str, words: &[&str]) -> bool {
|
||||
words.iter().any(|w| t.contains(w))
|
||||
}
|
||||
|
||||
/// Nassraum nach Name (auch Stempel-Name): Bad, WC, Dusche, Nasszelle, Toilette, Sanitär …
|
||||
/// Nassraum: [158] aus der Nutzung (`Room.usage`), ohne Nutzung nach dem Namen ([`is_wet_name`]).
|
||||
pub fn is_wet_room(r: &Room) -> bool {
|
||||
crate::room_book::is_wet(r)
|
||||
}
|
||||
|
||||
/// Nassraum nach Name (auch Stempel-Name): Bad, WC, Dusche, Nasszelle, Toilette, Sanitär …
|
||||
pub fn is_wet_name(r: &Room) -> bool {
|
||||
const WET: [&str; 12] = ["bad", "wc", "dusche", "nasszelle", "toilette", "sanitär", "sanitaer", "waschraum", "bath", "shower", "toilet", "lavabo"];
|
||||
let names = [Some(r.name.as_str()), r.stamp.as_ref().map(|s| s.name.as_str()), r.stamp.as_ref().and_then(|s| s.name_line2.as_deref())];
|
||||
names.into_iter().flatten().any(|n| has_any(n, &WET))
|
||||
@@ -83,6 +88,31 @@ pub fn thinning_scale(scale: f64) -> f64 {
|
||||
s * MIN_PAPER_MM / crate::surface_pattern::MIN_PAPER_MM
|
||||
}
|
||||
|
||||
/// [158] Räume des Geschosses mit eigenem Bodenbelag aus den Bauteil-Materialien (sichtbar, gültiger
|
||||
/// Umriss): Raum, Material, Umriss. Freitext-Beläge gelten nicht (kein Muster bekannt).
|
||||
pub fn own_finish_rooms<'a>(c: &Ctx<'a>) -> Vec<(&'a Room, &'a Component, Vec<P>)> {
|
||||
c.p.rooms
|
||||
.as_deref()
|
||||
.unwrap_or(&[])
|
||||
.iter()
|
||||
.filter(|r| r.floor_id == c.a.floor && r.boundary.len() >= 3 && c.vis(&r.category_code, &r.id))
|
||||
.filter_map(|r| {
|
||||
let comp = crate::room_book::finish_component(c.p, r.floor_finish.as_deref())?;
|
||||
let ring: Vec<P> = r.boundary.iter().map(|v| [v.x, v.y]).collect();
|
||||
ring.iter().all(|q| q[0].is_finite() && q[1].is_finite()).then_some((r, comp, ring))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// [158] Belagsmuster eines Raums: Muster des Materials auf dem Raumumriss (Ursprung erster Punkt,
|
||||
/// Ausrichtung am Plan), ausgedünnt wie der Deckenbelag; dazu die Strichstärke.
|
||||
pub fn room_segments(comp: &Component, ring: &[P], scale: f64) -> Option<(Vec<(P, P)>, f64)> {
|
||||
let pat = comp.surface_pattern.as_ref()?;
|
||||
let spec = crate::surface_pattern::spec_of(pat, 0.0)?;
|
||||
let segs = crate::surface_pattern::segments(ring, &spec, *ring.first()?, thinning_scale(scale));
|
||||
Some((segs, weight(pat.weight_mm)))
|
||||
}
|
||||
|
||||
/// Umrisse der Nassräume des Geschosses.
|
||||
pub fn wet_rooms(c: &Ctx) -> Vec<Vec<P>> {
|
||||
c.p.rooms.as_deref().unwrap_or(&[]).iter().filter(|r| r.floor_id == c.a.floor && r.boundary.len() >= 3 && is_wet_room(r)).map(|r| r.boundary.iter().map(|v| [v.x, v.y]).collect()).collect()
|
||||
|
||||
@@ -74,6 +74,7 @@ pub fn run(p: &Project, name: &str, args: &[f64], text: &str) -> Result<String,
|
||||
("scheduleRows", _) => json(&export_schedule::schedule_rows(p)),
|
||||
("openingSchedule", _) => json(&crate::opening_schedule::opening_schedule(p)),
|
||||
("elementSchedule", _) => json(&crate::u_value::element_schedule(p)),
|
||||
("roomBook", _) => json(&crate::room_book::room_book(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()),
|
||||
|
||||
@@ -0,0 +1,406 @@
|
||||
//! [158] Raumbuch: Oberflächen je Raum (Boden, Wand, Decke), Nutzung und die Mengen daraus.
|
||||
//!
|
||||
//! Je Raum eine Zeile mit Geschoss, Nummer, Name, Fläche, Nutzung (Nassraum abgeleitet), Bodenbelag,
|
||||
//! Wand- und Deckenoberfläche (Bauteil-Material über seine Kennung oder Freitext) und Bodenaufbau.
|
||||
//! Mengen: Bodenfläche = Deckenfläche = Raumfläche (netto); Wandfläche netto = Umfang × lichte Höhe −
|
||||
//! Öffnungen in den Wänden am Raum. Lichte Höhe aus den Decken über/unter dem Raum (Oberkante der Decke
|
||||
//! am Boden bis Unterkante der Decke darüber), sonst Geschosshöhe.
|
||||
//! Die Tabelle wird im Kern gerechnet; CSV/PDF und Blatt-Tabelle formatieren dieselben Zeilen.
|
||||
|
||||
use crate::model::*;
|
||||
use serde::Serialize;
|
||||
|
||||
impl RoomUsage {
|
||||
/// Kennung wie im JSON (`living`, `bath` …); leer für unbekannte Werte.
|
||||
pub fn key(self) -> &'static str {
|
||||
match self {
|
||||
RoomUsage::Living => "living",
|
||||
RoomUsage::Sleeping => "sleeping",
|
||||
RoomUsage::Kitchen => "kitchen",
|
||||
RoomUsage::Dining => "dining",
|
||||
RoomUsage::Bath => "bath",
|
||||
RoomUsage::Wc => "wc",
|
||||
RoomUsage::Shower => "shower",
|
||||
RoomUsage::Laundry => "laundry",
|
||||
RoomUsage::Circulation => "circulation",
|
||||
RoomUsage::Technical => "technical",
|
||||
RoomUsage::Storage => "storage",
|
||||
RoomUsage::Office => "office",
|
||||
RoomUsage::Other => "other",
|
||||
RoomUsage::Unknown => "",
|
||||
}
|
||||
}
|
||||
|
||||
/// Alle wählbaren Nutzungen (Reihenfolge der Auswahl).
|
||||
pub const ALL: [RoomUsage; 13] = [
|
||||
RoomUsage::Living,
|
||||
RoomUsage::Sleeping,
|
||||
RoomUsage::Kitchen,
|
||||
RoomUsage::Dining,
|
||||
RoomUsage::Bath,
|
||||
RoomUsage::Wc,
|
||||
RoomUsage::Shower,
|
||||
RoomUsage::Laundry,
|
||||
RoomUsage::Circulation,
|
||||
RoomUsage::Technical,
|
||||
RoomUsage::Storage,
|
||||
RoomUsage::Office,
|
||||
RoomUsage::Other,
|
||||
];
|
||||
|
||||
pub fn from_key(k: &str) -> Option<RoomUsage> {
|
||||
let k = k.trim().to_lowercase();
|
||||
Self::ALL.into_iter().find(|u| u.key() == k)
|
||||
}
|
||||
|
||||
/// Nassraum: Bad, WC, Dusche, Waschküche.
|
||||
pub fn is_wet(self) -> bool {
|
||||
matches!(self, RoomUsage::Bath | RoomUsage::Wc | RoomUsage::Shower | RoomUsage::Laundry)
|
||||
}
|
||||
}
|
||||
|
||||
/// Bauteil-Material, auf das eine Oberflächen-Angabe verweist (Kennung, sonst gleicher Name).
|
||||
pub fn finish_component<'a>(p: &'a Project, v: Option<&str>) -> Option<&'a Component> {
|
||||
let v = v.map(str::trim).filter(|s| !s.is_empty())?;
|
||||
p.component(v).or_else(|| p.components.iter().find(|c| c.name.trim() == v))
|
||||
}
|
||||
|
||||
/// Anzeigetext einer Oberflächen-Angabe: Name des Materials, sonst der Freitext.
|
||||
pub fn finish_label(p: &Project, v: Option<&str>) -> String {
|
||||
let t = v.map(str::trim).unwrap_or("");
|
||||
match p.component(t) {
|
||||
Some(c) if !t.is_empty() => c.name.clone(),
|
||||
_ => t.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
fn level_of<'a>(p: &'a Project, id: &str) -> Option<&'a DrawingLevel> {
|
||||
p.drawing_levels.iter().find(|l| l.id == id)
|
||||
}
|
||||
|
||||
fn in_ceiling(ce: &Ceiling, x: f64, y: f64) -> bool {
|
||||
use crate::opening_schedule::in_ring;
|
||||
ce.outline.len() >= 3 && in_ring(x, y, &ce.outline) && !ce.openings.as_deref().unwrap_or(&[]).iter().any(|h| h.len() >= 3 && in_ring(x, y, h))
|
||||
}
|
||||
|
||||
/// Lichte Höhe eines Raums (m): von der Oberkante der Decke unter dem Raum (bis 0.3 m unter bzw. 0.5 m
|
||||
/// über dem Geschossboden, sonst der Geschossboden) bis zur Unterkante der nächsten Decke darüber
|
||||
/// (sonst Geschossoberkante). Ohne Geschosshöhe 2.5 m.
|
||||
pub fn clear_height(p: &Project, r: &Room) -> f64 {
|
||||
let lvl = level_of(p, &r.floor_id);
|
||||
let base = lvl.and_then(|l| l.base_elevation).filter(|v| v.is_finite()).unwrap_or(0.0);
|
||||
let fh = lvl.and_then(|l| l.floor_height).filter(|h| h.is_finite() && *h > 0.0).unwrap_or(2.5);
|
||||
let ring: Vec<[f64; 2]> = r.boundary.iter().map(|v| [v.x, v.y]).collect();
|
||||
if ring.len() < 3 {
|
||||
return fh;
|
||||
}
|
||||
let [x, y] = crate::room_area::label_point(&ring);
|
||||
let over: Vec<(f64, f64)> = p.ceilings.as_deref().unwrap_or(&[]).iter().filter(|ce| in_ceiling(ce, x, y)).map(|ce| p.ceiling_vertical_extent(ce)).filter(|(a, b)| a.is_finite() && b.is_finite()).collect();
|
||||
let floor_z = over.iter().map(|e| e.1).filter(|t| *t >= base - 0.3 && *t <= base + 0.5).fold(f64::NAN, f64::max);
|
||||
let floor_z = if floor_z.is_finite() { floor_z } else { base };
|
||||
let ceil_z = over.iter().map(|e| e.0).filter(|b| *b > floor_z + 1.0).fold(f64::NAN, f64::min);
|
||||
let ceil_z = if ceil_z.is_finite() { ceil_z } else { base + fh };
|
||||
let h = ceil_z - floor_z;
|
||||
if h.is_finite() && h > 0.5 {
|
||||
h
|
||||
} else {
|
||||
fh
|
||||
}
|
||||
}
|
||||
|
||||
/// Fläche der Wand-Öffnungen (Tür, Fenster) am Raum: Öffnungen in Wänden des Geschosses, deren Prüfpunkt
|
||||
/// neben der Wand (eine Seite) im Raum liegt.
|
||||
pub fn opening_area(p: &Project, r: &Room) -> f64 {
|
||||
use crate::opening_schedule::{in_ring, side_points};
|
||||
let mut sum = 0.0;
|
||||
for o in p.openings.as_deref().unwrap_or(&[]) {
|
||||
if crate::opening_shape::is_surface_hosted(o) {
|
||||
continue;
|
||||
}
|
||||
let Some(w) = p.walls.iter().find(|w| w.id == o.host_wall_id && w.floor_id == r.floor_id) else { continue };
|
||||
let Some((a, b)) = side_points(p, w, o.position + o.width / 2.0) else { continue };
|
||||
if in_ring(a[0], a[1], &r.boundary) || in_ring(b[0], b[1], &r.boundary) {
|
||||
let area = o.width * o.height;
|
||||
if area.is_finite() && area > 0.0 {
|
||||
sum += area;
|
||||
}
|
||||
}
|
||||
}
|
||||
sum
|
||||
}
|
||||
|
||||
/// Nassraum: aus der Nutzung, ohne Nutzung nach dem Namen (`plan::floor_finish::is_wet_name`).
|
||||
pub fn is_wet(r: &Room) -> bool {
|
||||
match r.usage {
|
||||
Some(u) if u != RoomUsage::Unknown => u.is_wet(),
|
||||
_ => crate::plan::floor_finish::is_wet_name(r),
|
||||
}
|
||||
}
|
||||
|
||||
/// Eine Zeile des Raumbuchs (JSON-Form: `RoomBookRow` in TS).
|
||||
#[derive(Debug, Clone, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RoomBookRow {
|
||||
pub id: String,
|
||||
pub floor: String,
|
||||
pub floor_id: String,
|
||||
pub number: String,
|
||||
pub name: String,
|
||||
/// Nettofläche (m²) = Boden- und Deckenfläche.
|
||||
pub area: f64,
|
||||
pub perimeter: f64,
|
||||
pub clear_height: f64,
|
||||
/// Nutzungs-Kennung (`living` …), leer ohne Angabe.
|
||||
pub usage: String,
|
||||
pub wet: bool,
|
||||
/// Anzeigetexte (Material-Name oder Freitext), leer ohne Angabe.
|
||||
pub floor_finish: String,
|
||||
pub wall_finish: String,
|
||||
pub ceiling_finish: String,
|
||||
pub floor_build_up: String,
|
||||
/// Wandfläche netto: Umfang × lichte Höhe − Öffnungen (m²).
|
||||
pub wall_area: f64,
|
||||
pub opening_area: f64,
|
||||
}
|
||||
|
||||
/// Menge einer Oberfläche: Fläche je Material/Freitext und Lage.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct FinishQty {
|
||||
/// "floor", "wall" oder "ceiling".
|
||||
pub surface: &'static str,
|
||||
pub finish: String,
|
||||
pub area: f64,
|
||||
pub rooms: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RoomBook {
|
||||
pub rows: Vec<RoomBookRow>,
|
||||
pub quantities: Vec<FinishQty>,
|
||||
}
|
||||
|
||||
/// Raumnummern natürlich vergleichen („1.2" vor „1.10").
|
||||
fn natural_cmp(a: &str, b: &str) -> std::cmp::Ordering {
|
||||
let split = |s: &str| -> Vec<(bool, String)> {
|
||||
let mut out: Vec<(bool, String)> = Vec::new();
|
||||
for ch in s.chars() {
|
||||
let d = ch.is_ascii_digit();
|
||||
match out.last_mut() {
|
||||
Some((k, t)) if *k == d => t.push(ch),
|
||||
_ => out.push((d, ch.to_string())),
|
||||
}
|
||||
}
|
||||
out
|
||||
};
|
||||
let (x, y) = (split(a), split(b));
|
||||
for (p, q) in x.iter().zip(y.iter()) {
|
||||
let o = match (p.0, q.0) {
|
||||
(true, true) => p.1.trim_start_matches('0').len().cmp(&q.1.trim_start_matches('0').len()).then_with(|| p.1.trim_start_matches('0').cmp(q.1.trim_start_matches('0'))),
|
||||
_ => p.1.cmp(&q.1),
|
||||
};
|
||||
if o != std::cmp::Ordering::Equal {
|
||||
return o;
|
||||
}
|
||||
}
|
||||
x.len().cmp(&y.len())
|
||||
}
|
||||
|
||||
/// Raumbuch des Projekts: Zeilen je Geschoss (Ebenen-Reihenfolge), dann nach Raumnummer (natürlich,
|
||||
/// Räume ohne Nummer in Dokumentreihenfolge danach); dazu die Mengen je Oberfläche und Material.
|
||||
pub fn room_book(p: &Project) -> RoomBook {
|
||||
let mut rows = Vec::new();
|
||||
for r in p.rooms.as_deref().unwrap_or(&[]) {
|
||||
if r.boundary.len() < 3 {
|
||||
continue;
|
||||
}
|
||||
let ring: Vec<[f64; 2]> = r.boundary.iter().map(|v| [v.x, v.y]).collect();
|
||||
let ev = crate::room_area::evaluate(&ring, 0.0);
|
||||
let area = if ev.net.is_finite() { ev.net } else { 0.0 };
|
||||
let perimeter = if ev.perimeter.is_finite() { ev.perimeter } else { 0.0 };
|
||||
let h = clear_height(p, r);
|
||||
let open = opening_area(p, r);
|
||||
let number = r.stamp.as_ref().and_then(|s| s.number.as_deref()).map(str::trim).unwrap_or("").to_string();
|
||||
rows.push(RoomBookRow {
|
||||
id: r.id.clone(),
|
||||
floor: level_of(p, &r.floor_id).map_or(r.floor_id.clone(), |l| l.name.clone()),
|
||||
floor_id: r.floor_id.clone(),
|
||||
number,
|
||||
name: r.name.clone(),
|
||||
area,
|
||||
perimeter,
|
||||
clear_height: h,
|
||||
usage: r.usage.map(|u| u.key().to_string()).unwrap_or_default(),
|
||||
wet: is_wet(r),
|
||||
floor_finish: finish_label(p, r.floor_finish.as_deref()),
|
||||
wall_finish: finish_label(p, r.wall_finish.as_deref()),
|
||||
ceiling_finish: finish_label(p, r.ceiling_finish.as_deref()),
|
||||
floor_build_up: r.floor_build_up.as_deref().map(str::trim).unwrap_or("").to_string(),
|
||||
wall_area: (perimeter * h - open).max(0.0),
|
||||
opening_area: open,
|
||||
});
|
||||
}
|
||||
let level_index = |id: &str| p.drawing_levels.iter().position(|l| l.id == id).unwrap_or(usize::MAX);
|
||||
rows.sort_by(|a, b| {
|
||||
level_index(&a.floor_id).cmp(&level_index(&b.floor_id)).then_with(|| match (a.number.is_empty(), b.number.is_empty()) {
|
||||
(false, false) => natural_cmp(&a.number, &b.number),
|
||||
(true, false) => std::cmp::Ordering::Greater,
|
||||
(false, true) => std::cmp::Ordering::Less,
|
||||
(true, true) => std::cmp::Ordering::Equal,
|
||||
})
|
||||
});
|
||||
let mut quantities: Vec<FinishQty> = Vec::new();
|
||||
for surface in ["floor", "wall", "ceiling"] {
|
||||
for r in &rows {
|
||||
let (finish, area) = match surface {
|
||||
"floor" => (&r.floor_finish, r.area),
|
||||
"wall" => (&r.wall_finish, r.wall_area),
|
||||
_ => (&r.ceiling_finish, r.area),
|
||||
};
|
||||
if finish.is_empty() {
|
||||
continue;
|
||||
}
|
||||
match quantities.iter_mut().find(|q| q.surface == surface && &q.finish == finish) {
|
||||
Some(q) => {
|
||||
q.area += area;
|
||||
q.rooms += 1;
|
||||
}
|
||||
None => quantities.push(FinishQty { surface, finish: finish.clone(), area, rooms: 1 }),
|
||||
}
|
||||
}
|
||||
}
|
||||
RoomBook { rows, quantities }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn v(x: f64, y: f64) -> Vec2 {
|
||||
Vec2 { x, y }
|
||||
}
|
||||
|
||||
/// Wohnen 0.15..2.85 × 0.15..3.85 (2.7 × 3.7), Bad 3.15..5.85 × 0.15..2.15 (2.7 × 2.0), Innenwand x = 3
|
||||
/// mit Tür 0.9 × 2.1 zwischen beiden; Südwand mit Fenster 1.2 × 1.4 am Wohnen. Geschoss 2.8 m.
|
||||
fn sample() -> Project {
|
||||
let wall = |id: &str, a: Vec2, b: Vec2| Wall { id: id.into(), floor_id: "eg".into(), start: a, end: b, wall_type_id: "wt".into(), height: 2.8, ..Default::default() };
|
||||
let room = |id: &str, name: &str, pts: Vec<Vec2>| Room { id: id.into(), floor_id: "eg".into(), name: name.into(), boundary: pts, ..Default::default() };
|
||||
Project {
|
||||
drawing_levels: vec![DrawingLevel { id: "eg".into(), name: "EG".into(), floor_height: Some(2.8), ..Default::default() }],
|
||||
wall_types: vec![WallType { id: "wt".into(), name: "W".into(), layers: vec![Layer { thickness: 0.3, ..Default::default() }], ..Default::default() }],
|
||||
components: vec![Component { id: "parkett".into(), name: "Parkett Eiche".into(), ..Default::default() }, Component { id: "fliese".into(), name: "Feinsteinzeug".into(), ..Default::default() }],
|
||||
walls: vec![wall("s", v(0.0, 0.0), v(6.0, 0.0)), wall("m", v(3.0, 0.0), v(3.0, 4.0))],
|
||||
rooms: Some(vec![
|
||||
Room { floor_finish: Some("parkett".into()), wall_finish: Some("Abrieb 1 mm, weiss".into()), ceiling_finish: Some("Weissputz".into()), usage: Some(RoomUsage::Living), stamp: Some(RoomStamp { number: Some("1.10".into()), name: "Wohnen".into(), ..Default::default() }), ..room("r1", "Wohnen", vec![v(0.15, 0.15), v(2.85, 0.15), v(2.85, 3.85), v(0.15, 3.85)]) },
|
||||
Room { floor_finish: Some("fliese".into()), wall_finish: Some("fliese".into()), ceiling_finish: Some("Weissputz".into()), usage: Some(RoomUsage::Bath), stamp: Some(RoomStamp { number: Some("1.2".into()), name: "Nasszelle".into(), ..Default::default() }), ..room("r2", "Nasszelle", vec![v(3.15, 0.15), v(5.85, 0.15), v(5.85, 2.15), v(3.15, 2.15)]) },
|
||||
]),
|
||||
openings: Some(vec![
|
||||
Opening { id: "t1".into(), host_wall_id: "m".into(), kind: ElementKind::Door, position: 1.0, width: 0.9, height: 2.1, ..Default::default() },
|
||||
Opening { id: "f1".into(), host_wall_id: "s".into(), kind: ElementKind::Window, position: 1.0, width: 1.2, height: 1.4, sill_height: 0.9, ..Default::default() },
|
||||
]),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn modell_rundreise_und_alte_daten() {
|
||||
let p = sample();
|
||||
let j = serde_json::to_value(&p.rooms.as_ref().unwrap()[1]).unwrap();
|
||||
assert_eq!(j["usage"], "bath");
|
||||
assert_eq!(j["floorFinish"], "fliese");
|
||||
let back: Room = serde_json::from_value(j).unwrap();
|
||||
assert_eq!(back, p.rooms.as_ref().unwrap()[1]);
|
||||
// Ohne Felder: nichts geschrieben (Alt-Daten unverändert).
|
||||
let plain = serde_json::to_value(Room { id: "x".into(), ..Default::default() }).unwrap();
|
||||
for k in ["usage", "floorFinish", "wallFinish", "ceilingFinish", "floorBuildUp"] {
|
||||
assert!(plain.get(k).is_none(), "{k}");
|
||||
}
|
||||
// Unbekannte Nutzung bricht das Laden nicht.
|
||||
let r: Room = serde_json::from_value(serde_json::json!({"id": "y", "usage": "sauna"})).unwrap();
|
||||
assert_eq!(r.usage, Some(RoomUsage::Unknown));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nassraum_aus_nutzung_sonst_name() {
|
||||
let mut r = Room { name: "Nasszelle".into(), usage: Some(RoomUsage::Storage), ..Default::default() };
|
||||
assert!(!is_wet(&r), "Nutzung geht vor dem Namen");
|
||||
r.usage = Some(RoomUsage::Shower);
|
||||
r.name = "Raum 3".into();
|
||||
assert!(is_wet(&r));
|
||||
r.usage = None;
|
||||
assert!(!is_wet(&r));
|
||||
r.name = "Bad/WC".into();
|
||||
assert!(is_wet(&r), "Rückfall Name");
|
||||
for u in RoomUsage::ALL {
|
||||
assert_eq!(RoomUsage::from_key(u.key()), Some(u));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zeilen_und_reihenfolge() {
|
||||
let b = room_book(&sample());
|
||||
let ids: Vec<&str> = b.rows.iter().map(|r| r.id.as_str()).collect();
|
||||
assert_eq!(ids, vec!["r2", "r1"], "1.2 vor 1.10");
|
||||
let w = b.rows.iter().find(|r| r.id == "r1").unwrap();
|
||||
assert_eq!((w.floor.as_str(), w.number.as_str(), w.usage.as_str(), w.wet), ("EG", "1.10", "living", false));
|
||||
assert_eq!((w.floor_finish.as_str(), w.wall_finish.as_str(), w.ceiling_finish.as_str()), ("Parkett Eiche", "Abrieb 1 mm, weiss", "Weissputz"));
|
||||
let bad = b.rows.iter().find(|r| r.id == "r2").unwrap();
|
||||
assert!(bad.wet);
|
||||
assert_eq!(bad.floor_finish, "Feinsteinzeug");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mengen_boden_wand_decke() {
|
||||
let b = room_book(&sample());
|
||||
let w = b.rows.iter().find(|r| r.id == "r1").unwrap();
|
||||
assert!((w.area - 2.7 * 3.7).abs() < 1e-9);
|
||||
assert!((w.clear_height - 2.8).abs() < 1e-9);
|
||||
// Wohnen: Tür 0.9 × 2.1 und Fenster 1.2 × 1.4.
|
||||
assert!((w.opening_area - (0.9 * 2.1 + 1.2 * 1.4)).abs() < 1e-9, "{}", w.opening_area);
|
||||
assert!((w.wall_area - (2.0 * (2.7 + 3.7) * 2.8 - 0.9 * 2.1 - 1.2 * 1.4)).abs() < 1e-9);
|
||||
let bad = b.rows.iter().find(|r| r.id == "r2").unwrap();
|
||||
assert!((bad.wall_area - (2.0 * (2.7 + 2.0) * 2.8 - 0.9 * 2.1)).abs() < 1e-9, "{}", bad.wall_area);
|
||||
let q = |s: &str, f: &str| b.quantities.iter().find(|q| q.surface == s && q.finish == f).map(|q| (q.area, q.rooms));
|
||||
let (a, n) = q("floor", "Parkett Eiche").unwrap();
|
||||
assert!((a - 2.7 * 3.7).abs() < 1e-9 && n == 1);
|
||||
let (a, n) = q("ceiling", "Weissputz").unwrap();
|
||||
assert!((a - (2.7 * 3.7 + 2.7 * 2.0)).abs() < 1e-9 && n == 2);
|
||||
let (a, _) = q("wall", "Feinsteinzeug").unwrap();
|
||||
assert!((a - bad.wall_area).abs() < 1e-9);
|
||||
assert!(q("floor", "").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lichte_hoehe_aus_decken() {
|
||||
let mut p = sample();
|
||||
// Decke unter dem Raum (OK 0.0 + Belag 0.1 über Boden) und darüber (UK 2.6).
|
||||
let ce = |id: &str, bottom: f64, top: f64| -> Ceiling {
|
||||
serde_json::from_value(serde_json::json!({ "id": id, "type": "ceiling", "floorId": "eg", "categoryCode": "50",
|
||||
"outline": [{"x": 0, "y": 0}, {"x": 6, "y": 0}, {"x": 6, "y": 4}, {"x": 0, "y": 4}],
|
||||
"bottom": {"mode": "custom", "z": bottom}, "top": {"mode": "custom", "z": top} })).unwrap()
|
||||
};
|
||||
p.ceilings = Some(vec![ce("unten", -0.25, 0.1), ce("oben", 2.6, 2.8)]);
|
||||
let r = &p.rooms.as_ref().unwrap()[0];
|
||||
assert_eq!(p.ceiling_vertical_extent(&p.ceilings.as_ref().unwrap()[0]), (-0.25, 0.1));
|
||||
assert!((clear_height(&p, r) - 2.5).abs() < 1e-9, "{}", clear_height(&p, r));
|
||||
assert!(clear_height(&Project::default(), &Room::default()) > 0.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leeres_projekt_und_unsinn() {
|
||||
assert!(room_book(&Project::default()).rows.is_empty());
|
||||
let mut p = sample();
|
||||
p.rooms.as_mut().unwrap()[0].boundary = vec![v(f64::NAN, 0.0), v(1.0, f64::INFINITY), v(0.0, 1.0)];
|
||||
let b = room_book(&p);
|
||||
assert!(b.rows.iter().all(|r| r.area.is_finite() && r.wall_area.is_finite()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn natuerliche_nummern() {
|
||||
use std::cmp::Ordering::*;
|
||||
assert_eq!(natural_cmp("1.2", "1.10"), Less);
|
||||
assert_eq!(natural_cmp("E01", "E1"), Equal);
|
||||
assert_eq!(natural_cmp("2.01", "10.01"), Less);
|
||||
}
|
||||
}
|
||||
@@ -95,6 +95,23 @@ const EARTHWORKS: &[Col] = &[
|
||||
c("backfill", "sheetTable.col.backfill", 1.6, true, true),
|
||||
];
|
||||
|
||||
/// [158] Raumbuch: Oberflächen je Raum.
|
||||
const ROOM_BOOK: &[Col] = &[
|
||||
c("floor", "openings.col.floor", 1.2, false, true),
|
||||
c("number", "roomBook.col.number", 1.0, false, true),
|
||||
c("name", "sheetTable.col.room", 2.4, false, true),
|
||||
c("area", "sheetTable.col.area", 1.2, true, true),
|
||||
c("usage", "roomBook.col.usage", 1.6, false, true),
|
||||
c("floorFinish", "roomBook.col.floorFinish", 2.4, false, true),
|
||||
c("wallFinish", "roomBook.col.wallFinish", 2.4, false, true),
|
||||
c("ceilingFinish", "roomBook.col.ceilingFinish", 2.4, false, true),
|
||||
c("buildUp", "roomBook.col.buildUp", 3.0, false, false),
|
||||
c("clearHeight", "roomBook.col.clearHeight", 1.2, true, false),
|
||||
c("wallArea", "roomBook.col.wallArea", 1.3, true, false),
|
||||
c("perimeter", "roomBook.col.perimeter", 1.2, true, false),
|
||||
c("wet", "roomBook.col.wet", 1.0, false, false),
|
||||
];
|
||||
|
||||
/// Schlüssel der Werttexte (Art, aussen/innen, Aufschlag …).
|
||||
pub const VALUE_KEYS: &[&str] = &[
|
||||
"sheetTable.v.window",
|
||||
@@ -112,6 +129,20 @@ pub const VALUE_KEYS: &[&str] = &[
|
||||
"openings.swing.right",
|
||||
"openings.dir.in",
|
||||
"openings.dir.out",
|
||||
"roomBook.usage.living",
|
||||
"roomBook.usage.sleeping",
|
||||
"roomBook.usage.kitchen",
|
||||
"roomBook.usage.dining",
|
||||
"roomBook.usage.bath",
|
||||
"roomBook.usage.wc",
|
||||
"roomBook.usage.shower",
|
||||
"roomBook.usage.laundry",
|
||||
"roomBook.usage.circulation",
|
||||
"roomBook.usage.technical",
|
||||
"roomBook.usage.storage",
|
||||
"roomBook.usage.office",
|
||||
"roomBook.usage.other",
|
||||
"roomBook.wet",
|
||||
];
|
||||
|
||||
pub fn catalog(source: LayoutTableSource) -> &'static [Col] {
|
||||
@@ -121,6 +152,7 @@ pub fn catalog(source: LayoutTableSource) -> &'static [Col] {
|
||||
LayoutTableSource::Rooms => ROOMS,
|
||||
LayoutTableSource::Elements => ELEMENTS,
|
||||
LayoutTableSource::Earthworks => EARTHWORKS,
|
||||
LayoutTableSource::RoomBook => ROOM_BOOK,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +160,7 @@ pub fn catalog(source: LayoutTableSource) -> &'static [Col] {
|
||||
pub fn catalog_json() -> Value {
|
||||
let one = |s: &[Col]| s.iter().map(|k| json!({"id": k.id, "key": k.key, "numeric": k.numeric, "default": k.default})).collect::<Vec<_>>();
|
||||
json!({
|
||||
"sources": {"openings": one(OPENINGS), "areas": one(AREAS), "rooms": one(ROOMS), "elements": one(ELEMENTS), "earthworks": one(EARTHWORKS)},
|
||||
"sources": {"openings": one(OPENINGS), "areas": one(AREAS), "rooms": one(ROOMS), "elements": one(ELEMENTS), "earthworks": one(EARTHWORKS), "roomBook": one(ROOM_BOOK)},
|
||||
"valueKeys": VALUE_KEYS,
|
||||
})
|
||||
}
|
||||
@@ -261,9 +293,36 @@ fn data_of(p: &Project, t: &LayoutTable, lb: &Labels) -> Data {
|
||||
LayoutTableSource::Rooms => rooms_data(p),
|
||||
LayoutTableSource::Elements => elements_data(p, lb),
|
||||
LayoutTableSource::Earthworks => earthworks_data(p, lb),
|
||||
LayoutTableSource::RoomBook => room_book_data(p, lb),
|
||||
}
|
||||
}
|
||||
|
||||
/// [158] Raumbuch: eine Zeile je Raum (Reihenfolge wie `room_book`).
|
||||
fn room_book_data(p: &Project, lb: &Labels) -> Data {
|
||||
let rows = crate::room_book::room_book(p)
|
||||
.rows
|
||||
.into_iter()
|
||||
.map(|r| {
|
||||
vec![
|
||||
txt(r.floor),
|
||||
txt(r.number),
|
||||
txt(r.name),
|
||||
num(r.area, 2),
|
||||
txt(if r.usage.is_empty() { String::new() } else { lb.get(&format!("roomBook.usage.{}", r.usage)) }),
|
||||
txt(r.floor_finish),
|
||||
txt(r.wall_finish),
|
||||
txt(r.ceiling_finish),
|
||||
txt(r.floor_build_up),
|
||||
num(r.clear_height, 2),
|
||||
num(r.wall_area, 2),
|
||||
num(r.perimeter, 2),
|
||||
txt(if r.wet { lb.get("roomBook.wet") } else { String::new() }),
|
||||
]
|
||||
})
|
||||
.collect();
|
||||
Data { rows, total_last: false }
|
||||
}
|
||||
|
||||
/// [68] Erdarbeiten je Baugrube (m³ gegen das gewachsene Terrain) mit Summenzeile.
|
||||
fn earthworks_data(p: &Project, lb: &Labels) -> Data {
|
||||
let q = crate::excavation::quantities(p);
|
||||
@@ -612,6 +671,35 @@ mod tests {
|
||||
assert!(r[0].total >= 1, "Summenzeile");
|
||||
}
|
||||
|
||||
/// [158] Raumbuch als Blatt-Tabelle: Standard-Spalten, Nutzung beschriftet, Material-Name.
|
||||
#[test]
|
||||
fn raumbuch_tabelle() {
|
||||
let mut t = table("rb", None);
|
||||
t.source = LayoutTableSource::RoomBook;
|
||||
let mut p = project(0, vec![t]);
|
||||
p.components = vec![Component { id: "par".into(), name: "Parkett".into(), ..Default::default() }];
|
||||
p.rooms = Some(vec![Room {
|
||||
id: "r".into(),
|
||||
floor_id: "eg".into(),
|
||||
name: "Wohnen".into(),
|
||||
usage: Some(RoomUsage::Living),
|
||||
floor_finish: Some("par".into()),
|
||||
wall_finish: Some("Abrieb".into()),
|
||||
boundary: vec![Vec2 { x: 0.0, y: 0.0 }, Vec2 { x: 4.0, y: 0.0 }, Vec2 { x: 4.0, y: 5.0 }, Vec2 { x: 0.0, y: 5.0 }],
|
||||
stamp: Some(RoomStamp { number: Some("0.01".into()), name: "Wohnen".into(), ..Default::default() }),
|
||||
..Default::default()
|
||||
}]);
|
||||
let lb = Labels::parse(&json!({"roomBook.usage.living": "WOHN", "roomBook.col.floorFinish": "Boden"}));
|
||||
let r = render(&p, &p.layouts.as_ref().unwrap()[0], &lb);
|
||||
assert_eq!(r[0].total, 1);
|
||||
let tx = texts(&r[0]);
|
||||
for s in ["Boden", "EG", "0.01", "Wohnen", "20.00", "WOHN", "Parkett", "Abrieb"] {
|
||||
assert!(tx.contains(&s.to_string()), "{s}: {tx:?}");
|
||||
}
|
||||
assert_eq!(catalog_json()["sources"]["roomBook"].as_array().unwrap().iter().filter(|c| c["default"] == true).count(), 8);
|
||||
assert_eq!(serde_json::to_value(LayoutTableSource::RoomBook).unwrap(), "roomBook");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ohne_tabellen_und_abfrage() {
|
||||
let p = project(1, vec![]);
|
||||
|
||||
Reference in new issue
Block a user