Merge branch 'worktree-agent-a82867dee8c275a40' into claude/practical-noether-1hb2s1
This commit is contained in:
7 files changed
+278
-14
No files matched your search
@@ -57,6 +57,7 @@ const REC_CEILING_ARC: f64 = 21.0;
|
||||
const REC_SPACE_ARC: f64 = 22.0;
|
||||
const REC_GUIDS: f64 = 23.0;
|
||||
const REC_CONTEXT: f64 = 24.0;
|
||||
const REC_LAYERS: f64 = 25.0;
|
||||
|
||||
/// Toleranz des Kerns (`wall_bands.rs::EPS`) für „Öffnung trifft Band".
|
||||
const BAND_EPS: f64 = 1e-4;
|
||||
@@ -1521,12 +1522,23 @@ pub fn ifc_export_data(src: &Project, opt: &IfcOptions) -> Result<Flat, String>
|
||||
|
||||
// ── Räume → IfcSpace (im Geschoss aggregiert), Basismengen, SIA-416-Kategorie ──
|
||||
let mut room_areas: Vec<(String, String, SiaCategory, f64)> = Vec::new();
|
||||
let mut roof_cache: Vec<(String, crate::room_book::RoofPlanes)> = Vec::new();
|
||||
for room in p.rooms.as_deref().unwrap_or(&[]) {
|
||||
if room.boundary.len() < 3 {
|
||||
continue;
|
||||
}
|
||||
let structure = structure_of(&room.floor_id);
|
||||
let height = floors.iter().find(|fl| fl.id == room.floor_id).and_then(|fl| fl.floor_height).filter(|h| *h != 0.0 && !h.is_nan() && *h > 0.0).unwrap_or(2.5);
|
||||
// [259] Lichte Höhe wie im Raumbuch ([158]): Oberkante Boden bis Unterkante Decke darüber (`clear_range`); das
|
||||
// Geschossmass bleibt am IfcBuildingStorey. Unter Dachschrägen: Höhe = höchste Stelle (Körper), FinishCeilingHeight
|
||||
// = mittlere lichte Höhe, kleinste und mittlere Höhe zusätzlich in `Dossier_RoomBook`.
|
||||
let (range_lo, range_hi) = crate::room_book::clear_range(&p, room);
|
||||
let height = range_hi - range_lo;
|
||||
let storey_base_z = floors.iter().find(|fl| fl.id == room.floor_id).and_then(|fl| fl.base_elevation).filter(|v| v.is_finite()).unwrap_or(0.0);
|
||||
let z_rel = range_lo - storey_base_z;
|
||||
if !roof_cache.iter().any(|x| x.0 == room.floor_id) {
|
||||
roof_cache.push((room.floor_id.clone(), crate::room_book::roof_planes(&p, &room.floor_id)));
|
||||
}
|
||||
let roofs = &roof_cache.iter().find(|x| x.0 == room.floor_id).unwrap().1;
|
||||
let external = room.sia_category == SiaCategory::AGF;
|
||||
let area = crate::ring_arc::evaluate(&room.boundary, room.boundary_bulge.as_deref(), 0.0);
|
||||
room_areas.push((room.id.clone(), room.floor_id.clone(), room.sia_category, area.net));
|
||||
@@ -1538,8 +1550,9 @@ pub fn ifc_export_data(src: &Project, opt: &IfcOptions) -> Result<Flat, String>
|
||||
}
|
||||
common.push(Prop::Bool("IsExternal", external));
|
||||
let (id, name, long) = (f.str(&room.id), f.str(number.unwrap_or(&room.id)), f.str(&room.name));
|
||||
let bands = crate::room_book::height_bands(&p, room, roofs, area.net);
|
||||
let arcs = crate::ring_arc::has_arcs(room.boundary_bulge.as_deref(), room.boundary.len());
|
||||
f.nums(&[if arcs { REC_SPACE_ARC } else { REC_SPACE }, structure, id, name, long, if external { 1.0 } else { 0.0 }, height]);
|
||||
f.nums(&[if arcs { REC_SPACE_ARC } else { REC_SPACE }, structure, id, name, long, if external { 1.0 } else { 0.0 }, height, z_rel, bands.mean]);
|
||||
if arcs {
|
||||
w_bpts(&mut f, &room.boundary, room.boundary_bulge.as_deref());
|
||||
} else {
|
||||
@@ -1571,6 +1584,11 @@ pub fn ifc_export_data(src: &Project, opt: &IfcOptions) -> Result<Flat, String>
|
||||
if !book.is_empty() {
|
||||
psets.push(Pset { name: "Dossier_RoomBook", props: book });
|
||||
}
|
||||
// [259] Lichte Höhe unter Dachschrägen: kleinste und mittlere Höhe (Raumbuch [158]) als eigene Menge.
|
||||
psets.push(Pset {
|
||||
name: "Dossier_Qto_RoomBook",
|
||||
props: vec![Prop::Qty("ClearHeightMin", QtyKind::Length, bands.min), Prop::Qty("ClearHeightMean", QtyKind::Length, bands.mean)],
|
||||
});
|
||||
w_psets(&mut f, &psets);
|
||||
}
|
||||
f.num(REC_END_SPACES);
|
||||
@@ -1875,6 +1893,25 @@ pub fn ifc_export_data(src: &Project, opt: &IfcOptions) -> Result<Flat, String>
|
||||
classified.iter().filter_map(|(key, _, code)| layer_classification(&p, code).map(|(c, n)| (key.clone(), c, n))).collect();
|
||||
w_classification(&mut f, ("Dossier-Ebenen", "Dossier", ""), &refs);
|
||||
}
|
||||
// [259] Ebenen als IfcPresentationLayerAssignment (immer; Name wie die DXF-Ebene `Code_Bezeichnung`).
|
||||
let layered: Vec<(&String, String)> = classified
|
||||
.iter()
|
||||
.filter_map(|(key, _, code)| {
|
||||
let code = js_trim(code);
|
||||
if code.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let name = p.layer_category(code).map_or_else(|| code.to_string(), |l| format!("{}_{}", l.code, l.name));
|
||||
Some((key, name))
|
||||
})
|
||||
.collect();
|
||||
if !layered.is_empty() {
|
||||
f.nums(&[REC_LAYERS, layered.len() as f64]);
|
||||
for (key, name) in &layered {
|
||||
let (a, b) = (f.str(key), f.str(name));
|
||||
f.nums(&[a, b]);
|
||||
}
|
||||
}
|
||||
Ok(f)
|
||||
}
|
||||
|
||||
@@ -2265,7 +2302,7 @@ mod tests {
|
||||
p = sample();
|
||||
p.walls[0].wall_type_id = "fehlt".into();
|
||||
let f = ifc_export_data(&p, &IfcOptions::default()).unwrap();
|
||||
assert_eq!(f.nums.last(), Some(&REC_END_COLUMNS));
|
||||
assert!(f.nums.contains(&REC_END_COLUMNS));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2354,6 +2391,25 @@ mod tests {
|
||||
assert_eq!(fill_params(&p, &opening(ElementKind::Door, Some("dt"))).frame_depth, Some(0.16));
|
||||
}
|
||||
|
||||
/// [259] Ebenen im IFC (Datensatz LAYERS, Name wie die DXF-Ebene) und lichte Raumhöhe (Datensatz SPACE).
|
||||
#[test]
|
||||
fn ebenen_datensatz_und_lichte_raumhoehe() {
|
||||
let p = sample();
|
||||
let f = ifc_export_data(&p, &IfcOptions::default()).unwrap();
|
||||
let at = f.nums.iter().rposition(|v| *v == REC_LAYERS).expect("LAYERS");
|
||||
assert!(f.nums[at + 1] > 0.0);
|
||||
let name = f.strings[f.nums[at + 3] as usize].as_str();
|
||||
assert!(name.contains('_') || name.chars().all(|c| c.is_ascii_digit()), "{name}");
|
||||
// SPACE: height, z_rel, mittlere Höhe hinter `external`.
|
||||
let room = &p.rooms.as_ref().unwrap()[0];
|
||||
let at = (0..f.nums.len() - 9)
|
||||
.find(|&i| (f.nums[i] == REC_SPACE || f.nums[i] == REC_SPACE_ARC) && f.strings.get(f.nums[i + 2] as usize) == Some(&room.id))
|
||||
.expect("SPACE");
|
||||
let (h, z, mean) = (f.nums[at + 6], f.nums[at + 7], f.nums[at + 8]);
|
||||
let (lo, hi) = crate::room_book::clear_range(&p, room);
|
||||
assert!((h - (hi - lo)).abs() < 1e-9 && mean > 0.0 && mean <= h + 1e-9, "{h} {z} {mean}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn klassifikation_ebkph_und_ebenen() {
|
||||
assert_eq!(ebkph_group(Kind::Wall), Some(("C", "Konstruktion Gebäude")));
|
||||
|
||||
@@ -81,7 +81,8 @@
|
||||
// Mit mindestens einem Lauf/Podest/Geländer ist die IfcStair selbst ohne Darstellung und fasst Läufe,
|
||||
// Podest und Geländer per IfcRelAggregates zusammen (nur die Treppe liegt im Geschoss).
|
||||
// EXTRUSION = 6, structure, id, PTS, z_rel, depth
|
||||
// SPACE = 7, structure, id, name, long_name, external (0/1), height, PTS, net_area, gross_area,
|
||||
// SPACE = 7, structure, id, name, long_name, external (0/1), height (lichte Höhe), z_rel (Oberkante Boden über Geschoss),
|
||||
// ceiling_height (FinishCeilingHeight, mittlere lichte Höhe), PTS, net_area, gross_area,
|
||||
// sia_category, PSETS
|
||||
// END_SPACES = 8 (bündelt die Räume je Geschoss zu IfcRelAggregates)
|
||||
// ROOF = 9, structure, id, name, predefined (Text), TYPEREF, PSETS, MESH
|
||||
@@ -91,6 +92,10 @@
|
||||
// Profil; EIN IfcColumn mit n Extrusionen in einer SweptSolid-Darstellung, Placement auf dem tiefsten
|
||||
// Abschnitt; Material und Materialzuordnung wie COLUMN; die Mengen stehen fertig in PSETS)
|
||||
// END_COLUMNS = 11 (Materialzuordnung der Stützen)
|
||||
// LAYERS = 25, n_refs, (key, layer_name) x n_refs ([259]) IfcPresentationLayerAssignment je Ebene (Name =
|
||||
// "Code_Bezeichnung" wie im DXF); alle Darstellungen des Bauteils `key` (wie bei CLASSIFICATION, samt
|
||||
// aggregierter Teile) liegen auf genau einer Ebene. (IFC4 erlaubt bei IfcPresentationLayerWithStyle nur
|
||||
// Geometrie-Items; Sichtbarkeit/Sperre der Klasse wird daher nicht geschrieben.)
|
||||
// CLASSIFICATION = 12, name, source, edition (Text, leer = keine), n_refs, (key, code, ref_name) × n_refs
|
||||
// ([B5], 28.10.) Ein Klassifikationssystem (IfcClassification) mit je Code einer
|
||||
// IfcClassificationReference und EINER IfcRelAssociatesClassification für alle Bauteile mit
|
||||
@@ -167,6 +172,7 @@ pub const REC_GRID: f64 = 18.0;
|
||||
pub const REC_GUIDS: f64 = 23.0;
|
||||
pub const REC_TREE: f64 = 19.0;
|
||||
pub const REC_CONTEXT: f64 = 24.0;
|
||||
pub const REC_LAYERS: f64 = 25.0;
|
||||
pub const REC_COLUMN_PIECES: f64 = 20.0;
|
||||
pub const REC_CEILING_ARC: f64 = 21.0;
|
||||
pub const REC_SPACE_ARC: f64 = 22.0;
|
||||
@@ -202,6 +208,7 @@ fn rec_name(code: f64) -> &'static str {
|
||||
c if c == REC_GUIDS => "GUIDS",
|
||||
c if c == REC_TREE => "TREE",
|
||||
c if c == REC_CONTEXT => "CONTEXT",
|
||||
c if c == REC_LAYERS => "LAYERS",
|
||||
c if c == REC_COLUMN_PIECES => "COLUMN_PIECES",
|
||||
_ => "?",
|
||||
}
|
||||
@@ -220,6 +227,80 @@ fn compound_angle(deg: f64, limit: f64) -> String {
|
||||
format!("({},{},{},{})", sg * d, sg * m, sg * s, sg * micro)
|
||||
}
|
||||
|
||||
/// Zerlegt die Parameter einer Entity-Zeile `#n=TYPE(a,b,...);` auf oberster Ebene (Klammern und Strings beachtet).
|
||||
fn split_args(line: &str) -> (String, Vec<String>) {
|
||||
let Some(open) = line.find('(') else { return (String::new(), vec![]) };
|
||||
let ty = line[line.find('=').map_or(0, |i| i + 1)..open].to_string();
|
||||
let body = line[open + 1..].trim_end_matches(';').trim_end_matches(')');
|
||||
let (mut out, mut cur, mut depth, mut quote) = (Vec::new(), String::new(), 0i32, false);
|
||||
for ch in body.chars() {
|
||||
match ch {
|
||||
'\'' => {
|
||||
quote = !quote;
|
||||
cur.push(ch);
|
||||
}
|
||||
'(' if !quote => {
|
||||
depth += 1;
|
||||
cur.push(ch);
|
||||
}
|
||||
')' if !quote => {
|
||||
depth -= 1;
|
||||
cur.push(ch);
|
||||
}
|
||||
',' if !quote && depth == 0 => out.push(std::mem::take(&mut cur)),
|
||||
_ => cur.push(ch),
|
||||
}
|
||||
}
|
||||
out.push(cur);
|
||||
(ty, out)
|
||||
}
|
||||
|
||||
fn ref_ids(arg: &str) -> Vec<usize> {
|
||||
arg.split('#').skip(1).filter_map(|t| t.split(|c: char| !c.is_ascii_digit()).next()?.parse().ok()).collect()
|
||||
}
|
||||
|
||||
/// IfcRelAggregates: Eltern-Entitaet -> Teile.
|
||||
fn aggregate_children(lines: &[String]) -> HashMap<usize, Vec<usize>> {
|
||||
let mut out: HashMap<usize, Vec<usize>> = HashMap::new();
|
||||
for l in lines.iter().filter(|l| l.contains("=IFCRELAGGREGATES(")) {
|
||||
let (_, a) = split_args(l);
|
||||
if let (Some(parent), Some(kids)) = (a.get(4).and_then(|x| ref_ids(x).first().copied()), a.get(5)) {
|
||||
out.entry(parent).or_default().extend(ref_ids(kids));
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Alle IfcShapeRepresentation eines Bauteils samt seiner aggregierten Teile (Treppenlaeufe ...).
|
||||
fn shape_reps_of(lines: &[String], agg: &HashMap<usize, Vec<usize>>, entity: usize) -> Vec<usize> {
|
||||
let mut out = Vec::new();
|
||||
let mut todo = vec![entity];
|
||||
let mut guard = 0;
|
||||
while let Some(e) = todo.pop() {
|
||||
guard += 1;
|
||||
if guard > 10_000 {
|
||||
break;
|
||||
}
|
||||
if let Some(l) = lines.get(e.wrapping_sub(1)) {
|
||||
let (_, a) = split_args(l);
|
||||
// Product: GlobalId, OwnerHistory, Name, Description, ObjectType, ObjectPlacement, Representation
|
||||
if let Some(def) = a.get(6).and_then(|x| ref_ids(x).first().copied()) {
|
||||
if let Some(dl) = lines.get(def.wrapping_sub(1)) {
|
||||
let (ty, da) = split_args(dl);
|
||||
if ty == "IFCPRODUCTDEFINITIONSHAPE" {
|
||||
out.extend(da.get(2).map(|x| ref_ids(x)).unwrap_or_default());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(kids) = agg.get(&e) {
|
||||
todo.extend(kids.iter().copied());
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
|
||||
/// Baut aus dem flachen Puffer die STEP-Datei (IFC4 oder IFC2x3, je nach META). Fehler als Text.
|
||||
pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
|
||||
let mut r = Reader { buf: flat, pos: 0, strings: strings.split('\0').collect() };
|
||||
@@ -892,16 +973,18 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
|
||||
let long_name = r.string()?;
|
||||
let external = r.flag()?;
|
||||
let height = r.f()?;
|
||||
let z_rel = r.f()?;
|
||||
let ceiling_height = r.f()?;
|
||||
let pts = if arcs { r.bpts()? } else { r.pts()?.into_iter().map(|p| (p.0, p.1, 0.0)).collect() };
|
||||
let net = r.f()?;
|
||||
let gross = r.f()?;
|
||||
let sia = r.string()?;
|
||||
let psets = r.psets()?;
|
||||
let (placement, shape) = if arcs {
|
||||
w.emit_box_product_voids_arcs(&pts, &[], 0.0, height, w.placement_of(structure))
|
||||
w.emit_box_product_voids_arcs(&pts, &[], z_rel, height, w.placement_of(structure))
|
||||
} else {
|
||||
let plain: Vec<(f64, f64)> = pts.iter().map(|p| (p.0, p.1)).collect();
|
||||
w.emit_box_product(&plain, 0.0, height, w.placement_of(structure))
|
||||
w.emit_box_product(&plain, z_rel, height, w.placement_of(structure))
|
||||
};
|
||||
let g = w.gid(&format!("space/{id}"));
|
||||
let space = w.add(
|
||||
@@ -924,6 +1007,7 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
|
||||
let q_net = w.emit_quantity("IFCQUANTITYAREA", "NetFloorArea", net);
|
||||
let q_gross = w.emit_quantity("IFCQUANTITYAREA", "GrossFloorArea", gross);
|
||||
let q_height = w.emit_quantity("IFCQUANTITYLENGTH", "Height", height);
|
||||
let q_ceiling = w.emit_quantity("IFCQUANTITYLENGTH", "FinishCeilingHeight", ceiling_height);
|
||||
let g = w.gid(&format!("space/{id}/qto"));
|
||||
let qto = w.add(
|
||||
"IFCELEMENTQUANTITY",
|
||||
@@ -931,7 +1015,7 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
|
||||
"{g},#{},{},$,$,{}",
|
||||
w.owner_history,
|
||||
ifc_string("Qto_SpaceBaseQuantities"),
|
||||
refs(&[q_net, q_gross, q_height])
|
||||
refs(&[q_net, q_gross, q_height, q_ceiling])
|
||||
),
|
||||
);
|
||||
let g = w.gid(&format!("space/{id}/qto-rel"));
|
||||
@@ -1123,6 +1207,31 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
|
||||
}
|
||||
}
|
||||
}
|
||||
c if c == REC_LAYERS => {
|
||||
let n = r.idx()?;
|
||||
// Je Ebene in Reihenfolge des ersten Auftretens: (Name, Flags, Darstellungen); jede Darstellung nur einmal.
|
||||
let mut by_layer: Vec<(String, Vec<usize>)> = Vec::new();
|
||||
let mut seen: std::collections::HashSet<usize> = std::collections::HashSet::new();
|
||||
let agg = aggregate_children(&w.lines);
|
||||
for _ in 0..n {
|
||||
let key = r.string()?;
|
||||
let name = r.string()?;
|
||||
let Some(&entity) = w.elements.get(&key) else { continue };
|
||||
let reps: Vec<usize> = shape_reps_of(&w.lines, &agg, entity).into_iter().filter(|x| seen.insert(*x)).collect();
|
||||
if reps.is_empty() {
|
||||
continue;
|
||||
}
|
||||
if let Some((_, v)) = by_layer.iter_mut().find(|(c, _)| *c == name) {
|
||||
v.extend(reps);
|
||||
} else {
|
||||
by_layer.push((name, reps));
|
||||
}
|
||||
}
|
||||
for (name, items) in by_layer {
|
||||
// IfcPresentationLayerAssignment: Name, Description, AssignedItems, Identifier
|
||||
w.add("IFCPRESENTATIONLAYERASSIGNMENT", format!("{},$,{},$", ifc_string(&name), refs(&items)));
|
||||
}
|
||||
}
|
||||
c if c == REC_ZONE => {
|
||||
let key = r.string()?;
|
||||
let name = r.string()?;
|
||||
|
||||
@@ -257,7 +257,7 @@ fn full_house_in(mut b: B, with_geo: bool) -> B {
|
||||
b.str("R1");
|
||||
b.str("101");
|
||||
b.str("Wohnen");
|
||||
b.n(&[0.0, 2.5]);
|
||||
b.n(&[0.0, 2.5, 0.0, 2.5]);
|
||||
b.pts(&SQUARE);
|
||||
b.n(&[1.9, 2.0]);
|
||||
b.str("HNF");
|
||||
@@ -1355,3 +1355,29 @@ fn netz_wird_verschweisst() {
|
||||
assert_eq!(m.indices, vec![0, 1, 2, 1, 3, 2]);
|
||||
assert!(m.closed);
|
||||
}
|
||||
|
||||
/// [259] Ebenen: Darstellungen eines Bauteils (hier Raum und Stütze) liegen auf genau einer IfcPresentationLayerAssignment.
|
||||
#[test]
|
||||
fn ebenen_als_presentation_layer() {
|
||||
let mut b = full_house(true);
|
||||
b.n(&[REC_LAYERS, 3.0]);
|
||||
for (key, name) in [("space/R1", "60_Räume"), ("column/C1", "50_Stützen"), ("space/unbekannt", "99_x")] {
|
||||
b.str(key);
|
||||
b.str(name);
|
||||
}
|
||||
let ifc = build(&b).unwrap();
|
||||
check_structure(&ifc);
|
||||
assert_eq!(count(&ifc, "IFCPRESENTATIONLAYERASSIGNMENT"), 2, "unbekannte Schlüssel erzeugen keine Ebene");
|
||||
let layer = ifc.lines().find(|l| l.contains("IFCPRESENTATIONLAYERASSIGNMENT(\x27") && l.contains("St\\X2\\00FC\\X0\\tzen")).expect("Stützen-Ebene");
|
||||
assert!(layer.ends_with(",$);"), "{layer}");
|
||||
let mut seen = std::collections::HashSet::new();
|
||||
for l in ifc.lines().filter(|l| l.contains("IFCPRESENTATIONLAYERASSIGNMENT")) {
|
||||
let items = &l[l.find(",$,(").unwrap() + 4..];
|
||||
for id in items[..items.find(')').unwrap()].split(',') {
|
||||
assert!(seen.insert(id.to_string()), "Darstellung {id} doppelt");
|
||||
let target = ifc.lines().find(|x| x.starts_with(&format!("{id}="))).unwrap();
|
||||
assert!(target.contains("IFCSHAPEREPRESENTATION"), "{target}");
|
||||
}
|
||||
}
|
||||
assert_eq!(seen.len(), 2);
|
||||
}
|
||||
Reference in new issue
Block a user