[B5] IFC-Export: Tür-/Fenster-Geometrie nach Rust (ifc_openings.rs), TS sammelt nur Parameter
- ifc_openings.rs: Rahmen/Zarge, Blatt, Glas, Füllungs-Placement, OperationType/PartitioningType (JS-Zahlsemantik für min/max/round/hypot, Rechenreihenfolge wie TS) - ifcOpenings.ts: fillParams statt fillGeometry; flache Kodierung FILL, FLAT_VERSION 2 - Golden-Vergleich: 419 verschiedene IFC-Ausgaben vorher/nachher zeichengleich (bis auf Zeitstempel) Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
7 files changed
+904
-544
No files matched your search
@@ -418,6 +418,12 @@ Ganzes nicht WASM-tauglich (rayon, tempfile, SystemTime) — nur einzelne Module
|
||||
in `ifcOpenings.test.ts`. Offen: LEFT/RIGHT der Tür nach IFC-Konvention (Blick von der Aufschlagseite)
|
||||
gelesen, nicht in Revit/ArchiCAD gegengeprüft; ohne Sprossen, Fensterbank, Rollladenkasten, Schwelle,
|
||||
Flügelrahmen.
|
||||
- ✅ Tür/Fenster-Geometrie nach Rust (Regel „Kern in Rust“, 28.10.): `fileio/src/ifc_openings.rs` rechnet
|
||||
Rahmen/Zarge, Blatt, Glas, Füllungs-Placement und OperationType/PartitioningType; `export/ifcOpenings.ts`
|
||||
sammelt nur die Parameter (Typ-/Öffnungswerte, fehlende als „keine“), flache Kodierung FILL (Version 2).
|
||||
TS-Rechnung gelöscht, ihre Fälle als Rust-Tests. Golden-Vergleich: 419 verschiedene IFC-Ausgaben (Tests in
|
||||
`export/*ifc*`, `io/ifcImport`, `io/ifcElements` und 780 Tür-/Fenster-Varianten: Glas-/Schiebe-/Wandöffnung,
|
||||
Oberlicht, Flügeltabellen, Einzug innen, Klemmungen) vorher/nachher zeichengleich bis auf Zeitstempel.
|
||||
- ○ Offen: Bogenwände als echte Kurve. · M
|
||||
- ✅ Eigener IFC-Import ([B3]) zieht Öffnungen ab (28.10.): Rundreise vergleicht alle Wände mit dem
|
||||
ausgeschnittenen Volumen (`ifcImport.test.ts`).
|
||||
|
||||
+177
-109
@@ -30,12 +30,18 @@
|
||||
// WALL_MESH = 2, structure, id, name, TYPEREF, PSETS, MESH
|
||||
// CEILING = 3, structure, id, name, TYPEREF, PSETS, PTS, z_rel, depth
|
||||
// OPENING = 4, wall_id, structure, opening_id, is_door (0/1), fill_name, PTS (Öffnungskörper), z_rel,
|
||||
// depth, width, kind_text (Text oder −1 = keine: Tür OperationType, Fenster PartitioningType,
|
||||
// IFC-Enum-Name), FILL_FRAME, n_parts, (role, PTS, z_rel, depth) × n_parts, PSETS
|
||||
// FILL_FRAME = ox, oy, ux, uy (Welt-XY): Placement der Füllung (X = u, Y = linke Normale von u). Die
|
||||
// Teile-PTS bleiben Welt-XY, z_rel zählt ab Öffnungs-Unterkante. n_parts = 0: kein Körper.
|
||||
// role: 0 Rahmen/Zarge, 1 Türblatt, 2 Glas. Alle Teile eines Bauteils sind getrennte Körper in EINER
|
||||
// Darstellung, je mit eigenem IfcStyledItem (Farbe/Transparenz je Rolle).
|
||||
// depth, width, FILL, PSETS
|
||||
// FILL (Parameter aus dem Modell; Körper, Placement und OperationType/PartitioningType rechnet
|
||||
// `ifc_openings.rs`, Version 2 seit 28.10.; OPT = has (0/1), value):
|
||||
// wall_sx, wall_sy, wall_ex, wall_ey, from, to, z_bottom, z_top, n_lo, n_hi,
|
||||
// frame_depth OPT, inset OPT, inset_outside (0/1), frame_width OPT,
|
||||
// wing_count, panes (1–3), n_sashes, (post, post_width OPT, fixed, width OPT) × n_sashes,
|
||||
// door_kind (0 Dreh, 1 Schiebe, 2 Wandöffnung), leaf_count, swing_sign (±1), dir_sign (±1),
|
||||
// hinge_at_start (0/1), transom_height, glazed (0/1), glazing_ratio OPT
|
||||
// Die Füllung bekommt ein eigenes Placement (Ursprung = Öffnungsmitte auf der Achse, X = u, Y = linke
|
||||
// Normale von u; Tür: Y = Aufschlagrichtung); ohne Teile (Wandöffnung) kein Körper. Alle Teile
|
||||
// (0 Rahmen/Zarge, 1 Türblatt, 2 Glas) sind getrennte Körper in EINER Darstellung, je mit eigenem
|
||||
// IfcStyledItem (Farbe/Transparenz je Rolle).
|
||||
// STAIR = 5, structure, id, predefined (Text), PTS, z_rel, depth
|
||||
// EXTRUSION = 6, structure, id, PTS, z_rel, depth
|
||||
// SPACE = 7, structure, id, name, long_name, external (0/1), height, PTS, net_area, gross_area,
|
||||
@@ -56,8 +62,10 @@
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::ifc_openings::{fill_geometry, DoorKind, FillParams, FillPart, Sash, MAX_SASHES};
|
||||
|
||||
/// Version der flachen Kodierung (erstes Element des Puffers).
|
||||
pub const FLAT_VERSION: f64 = 1.0;
|
||||
pub const FLAT_VERSION: f64 = 2.0;
|
||||
|
||||
pub const REC_WALL_SOLIDS: f64 = 1.0;
|
||||
pub const REC_WALL_MESH: f64 = 2.0;
|
||||
@@ -378,23 +386,78 @@ impl<'a> Reader<'a> {
|
||||
let s = self.take(n.checked_mul(2).ok_or("Überlauf")?)?;
|
||||
Ok(s.chunks_exact(2).map(|c| (c[0], c[1])).collect())
|
||||
}
|
||||
/// Teile einer Füllung: n, (Rolle 0 Rahmen / 1 Blatt / 2 Glas, PTS, z_rel, depth) × n.
|
||||
fn parts(&mut self) -> Result<Vec<Part>, String> {
|
||||
/// Optionaler Wert: has (0/1), value.
|
||||
fn opt_f(&mut self) -> Result<Option<f64>, String> {
|
||||
let has = self.flag()?;
|
||||
let v = self.f()?;
|
||||
Ok(has.then_some(v))
|
||||
}
|
||||
/// FILL-Parameter einer Tür/eines Fensters (s. Kopf; Geometrie in `ifc_openings.rs`).
|
||||
fn fill_params(&mut self, is_door: bool) -> Result<FillParams, String> {
|
||||
let (sx, sy, ex, ey) = (self.f()?, self.f()?, self.f()?, self.f()?);
|
||||
let (from, to, z_bottom, z_top) = (self.f()?, self.f()?, self.f()?, self.f()?);
|
||||
let (n_lo, n_hi) = (self.f()?, self.f()?);
|
||||
let (frame_depth, inset) = (self.opt_f()?, self.opt_f()?);
|
||||
let inset_outside = self.flag()?;
|
||||
let frame_width = self.opt_f()?;
|
||||
let wing_count = self.f()?;
|
||||
let panes = self.idx()?;
|
||||
if !(1..=3).contains(&panes) {
|
||||
return Err(format!("Scheibenzahl {panes} bei {}", self.pos - 1));
|
||||
}
|
||||
let n = self.idx()?;
|
||||
if n > MAX_PARTS {
|
||||
return Err(format!("zu viele Teile ({n}) bei {}", self.pos - 1));
|
||||
if n > MAX_SASHES {
|
||||
return Err(format!("zu viele Flügel ({n}) bei {}", self.pos - 1));
|
||||
}
|
||||
let mut out = Vec::with_capacity(n);
|
||||
let mut sashes = Vec::with_capacity(n);
|
||||
for _ in 0..n {
|
||||
let role = self.idx()?;
|
||||
if role > 2 {
|
||||
return Err(format!("unbekannte Teilrolle {role} bei {}", self.pos - 1));
|
||||
}
|
||||
let pts = self.pts()?;
|
||||
let (z_rel, depth) = (self.f()?, self.f()?);
|
||||
out.push(Part { role, pts, z_rel, depth });
|
||||
let post = self.flag()?;
|
||||
let post_width = self.opt_f()?;
|
||||
let fixed = self.flag()?;
|
||||
let width = self.opt_f()?;
|
||||
sashes.push(Sash { post, post_width, fixed, width });
|
||||
}
|
||||
Ok(out)
|
||||
let door_kind = match self.idx()? {
|
||||
0 => DoorKind::Swing,
|
||||
1 => DoorKind::Sliding,
|
||||
2 => DoorKind::WallOpening,
|
||||
k => return Err(format!("unbekannte Türart {k} bei {}", self.pos - 1)),
|
||||
};
|
||||
let leaf_count = self.f()?;
|
||||
let (swing_sign, dir_sign) = (self.f()?, self.f()?);
|
||||
if swing_sign.abs() != 1.0 || dir_sign.abs() != 1.0 {
|
||||
return Err(format!("Aufschlag nicht ±1 bei {}", self.pos - 1));
|
||||
}
|
||||
let hinge_at_start = self.flag()?;
|
||||
let transom_height = self.f()?;
|
||||
let glazed = self.flag()?;
|
||||
let glazing_ratio = self.opt_f()?;
|
||||
Ok(FillParams {
|
||||
wall_start: (sx, sy),
|
||||
wall_end: (ex, ey),
|
||||
from,
|
||||
to,
|
||||
z_bottom,
|
||||
z_top,
|
||||
n_lo,
|
||||
n_hi,
|
||||
is_door,
|
||||
frame_depth,
|
||||
inset,
|
||||
inset_outside,
|
||||
frame_width,
|
||||
wing_count,
|
||||
panes,
|
||||
sashes,
|
||||
door_kind,
|
||||
leaf_count,
|
||||
swing_sign,
|
||||
dir_sign,
|
||||
hinge_at_start,
|
||||
transom_height,
|
||||
glazed,
|
||||
glazing_ratio,
|
||||
})
|
||||
}
|
||||
fn mesh(&mut self) -> Result<Mesh, String> {
|
||||
let nv = self.idx()?;
|
||||
@@ -458,29 +521,8 @@ impl<'a> Reader<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Obergrenze der Körper je Tür/Fenster (Rahmenteile, Scheiben, Pfosten).
|
||||
const MAX_PARTS: usize = 256;
|
||||
|
||||
/// Ein Körper einer Tür/eines Fensters (Welt-XY-Profil, Unterkante ab Öffnungs-UK).
|
||||
struct Part {
|
||||
/// 0 Rahmen/Zarge, 1 Türblatt, 2 Glas.
|
||||
role: usize,
|
||||
pts: Vec<(f64, f64)>,
|
||||
z_rel: f64,
|
||||
depth: f64,
|
||||
}
|
||||
|
||||
/// IfcDoorTypeOperationEnum / IfcWindowTypePartitioningEnum (IFC4): nur gültige Namen kommen durch.
|
||||
const DOOR_OPERATIONS: &[&str] = &[
|
||||
"SINGLE_SWING_LEFT", "SINGLE_SWING_RIGHT", "DOUBLE_DOOR_SINGLE_SWING", "DOUBLE_DOOR_SINGLE_SWING_OPPOSITE_LEFT",
|
||||
"DOUBLE_DOOR_SINGLE_SWING_OPPOSITE_RIGHT", "DOUBLE_SWING_LEFT", "DOUBLE_SWING_RIGHT", "DOUBLE_DOOR_DOUBLE_SWING",
|
||||
"SWING_FIXED_LEFT", "SWING_FIXED_RIGHT", "SLIDING_TO_LEFT", "SLIDING_TO_RIGHT", "DOUBLE_DOOR_SLIDING",
|
||||
"FOLDING_TO_LEFT", "FOLDING_TO_RIGHT", "DOUBLE_DOOR_FOLDING", "REVOLVING", "ROLLINGUP", "NOTDEFINED",
|
||||
];
|
||||
const WINDOW_PARTITIONINGS: &[&str] = &[
|
||||
"SINGLE_PANEL", "DOUBLE_PANEL_VERTICAL", "DOUBLE_PANEL_HORIZONTAL", "TRIPLE_PANEL_VERTICAL", "TRIPLE_PANEL_BOTTOM",
|
||||
"TRIPLE_PANEL_TOP", "TRIPLE_PANEL_LEFT", "TRIPLE_PANEL_RIGHT", "TRIPLE_PANEL_HORIZONTAL", "NOTDEFINED",
|
||||
];
|
||||
/// Ein Körper einer Tür/eines Fensters (Welt-XY-Profil, Unterkante ab Öffnungs-UK; `ifc_openings.rs`).
|
||||
type Part = FillPart;
|
||||
|
||||
/// Farbe und Durchsichtigkeit je Teilrolle (wie `PART_RGB` im 3D: Rahmen hellgrau, Blatt warm, Glas bläulich).
|
||||
const PART_STYLES: [(&str, [f64; 3], f64); 3] = [
|
||||
@@ -1222,20 +1264,17 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
|
||||
let void_z = r.f()?;
|
||||
let depth = r.f()?;
|
||||
let width = r.f()?;
|
||||
let kind = r.opt_string()?;
|
||||
let (fox, foy, fux, fuy) = (r.f()?, r.f()?, r.f()?, r.f()?);
|
||||
if ((fux * fux + fuy * fuy) - 1.0).abs() > 1e-6 {
|
||||
let fill = fill_geometry(&r.fill_params(is_door)?);
|
||||
let (kind, parts) = (fill.kind, fill.parts);
|
||||
let ((fox, foy), (fux, fuy)) = (fill.origin, fill.u);
|
||||
if ((fux * fux + fuy * fuy) - 1.0).abs() > 1e-6 || !(fox.is_finite() && foy.is_finite()) {
|
||||
return Err(format!("Füllungsrichtung nicht normiert bei {}", r.pos - 1));
|
||||
}
|
||||
let fill_frame = Frame { ox: fox, oy: foy, ux: fux, uy: fuy };
|
||||
let parts = r.parts()?;
|
||||
let psets = r.psets()?;
|
||||
let allowed = if is_door { DOOR_OPERATIONS } else { WINDOW_PARTITIONINGS };
|
||||
if let Some(k) = &kind {
|
||||
if !allowed.contains(&k.as_str()) {
|
||||
return Err(format!("unbekannte Ausführung {k:?} bei {}", r.pos - 1));
|
||||
}
|
||||
if parts.iter().any(|p| !(p.z_rel.is_finite() && p.depth.is_finite() && p.pts.iter().all(|q| q.0.is_finite() && q.1.is_finite()))) {
|
||||
return Err(format!("Füllung mit NaN/∞ bei {}", r.pos - 1));
|
||||
}
|
||||
let fill_frame = Frame { ox: fox, oy: foy, ux: fux, uy: fuy };
|
||||
let psets = r.psets()?;
|
||||
let Some(&(host_entity, host_placement, host_frame)) = w.walls.get(&wall_id) else {
|
||||
continue; // Wirtswand nicht geschrieben (degeneriert)
|
||||
};
|
||||
@@ -1262,7 +1301,7 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
|
||||
let fill_placement = w.emit_placement_frame(&fill_frame.relative_to(&host_frame), opening_placement);
|
||||
let fill_shape = if parts.is_empty() { "$".to_string() } else { format!("#{}", w.emit_parts_shape(&parts, &fill_frame)) };
|
||||
let g = w.gid(&format!("fill/{opening_id}"));
|
||||
let operation = kind.as_deref().map(enum_).unwrap_or_else(|| "$".to_string());
|
||||
let operation = kind.map(enum_).unwrap_or_else(|| "$".to_string());
|
||||
let fill_entity = w.add(
|
||||
if is_door { "IFCDOOR" } else { "IFCWINDOW" },
|
||||
format!(
|
||||
@@ -1616,22 +1655,9 @@ mod tests {
|
||||
fn no_type(&mut self) {
|
||||
self.f.push(0.0);
|
||||
}
|
||||
/// OPENING-Datensatz im neuen Format (Gegenstück zu `FlatIfc.opening`).
|
||||
/// OPENING-Datensatz (Gegenstück zu `FlatIfc.opening`), Füllung als Parameter.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn opening(
|
||||
&mut self,
|
||||
wall: &str,
|
||||
id: &str,
|
||||
is_door: bool,
|
||||
name: &str,
|
||||
void_pts: &[(f64, f64)],
|
||||
void_z: f64,
|
||||
depth: f64,
|
||||
width: f64,
|
||||
kind: Option<&str>,
|
||||
frame: [f64; 4],
|
||||
parts: &[(f64, &[(f64, f64)], f64, f64)],
|
||||
) {
|
||||
fn opening(&mut self, wall: &str, id: &str, is_door: bool, name: &str, void_pts: &[(f64, f64)], void_z: f64, depth: f64, width: f64, fill: &FillParams) {
|
||||
self.n(&[REC_OPENING]);
|
||||
self.str(wall);
|
||||
self.n(&[-1.0]);
|
||||
@@ -1640,19 +1666,34 @@ mod tests {
|
||||
self.str(name);
|
||||
self.pts(void_pts);
|
||||
self.n(&[void_z, depth, width]);
|
||||
match kind {
|
||||
Some(k) => self.str(k),
|
||||
None => self.f.push(-1.0),
|
||||
}
|
||||
self.n(&frame);
|
||||
self.f.push(parts.len() as f64);
|
||||
for (role, pts, z, d) in parts {
|
||||
self.f.push(*role);
|
||||
self.pts(pts);
|
||||
self.n(&[*z, *d]);
|
||||
}
|
||||
self.fill(fill);
|
||||
self.no_psets();
|
||||
}
|
||||
fn opt(&mut self, v: Option<f64>) {
|
||||
self.n(&[if v.is_some() { 1.0 } else { 0.0 }, v.unwrap_or(0.0)]);
|
||||
}
|
||||
fn fill(&mut self, p: &FillParams) {
|
||||
self.n(&[p.wall_start.0, p.wall_start.1, p.wall_end.0, p.wall_end.1, p.from, p.to, p.z_bottom, p.z_top, p.n_lo, p.n_hi]);
|
||||
self.opt(p.frame_depth);
|
||||
self.opt(p.inset);
|
||||
self.n(&[if p.inset_outside { 1.0 } else { 0.0 }]);
|
||||
self.opt(p.frame_width);
|
||||
self.n(&[p.wing_count, p.panes as f64, p.sashes.len() as f64]);
|
||||
for s in &p.sashes {
|
||||
self.n(&[if s.post { 1.0 } else { 0.0 }]);
|
||||
self.opt(s.post_width);
|
||||
self.n(&[if s.fixed { 1.0 } else { 0.0 }]);
|
||||
self.opt(s.width);
|
||||
}
|
||||
let k = match p.door_kind {
|
||||
DoorKind::Swing => 0.0,
|
||||
DoorKind::Sliding => 1.0,
|
||||
DoorKind::WallOpening => 2.0,
|
||||
};
|
||||
self.n(&[k, p.leaf_count, p.swing_sign, p.dir_sign, if p.hinge_at_start { 1.0 } else { 0.0 }, p.transom_height]);
|
||||
self.n(&[if p.glazed { 1.0 } else { 0.0 }]);
|
||||
self.opt(p.glazing_ratio);
|
||||
}
|
||||
fn wall_type(&mut self) {
|
||||
self.n(&[1.0, 0.0]);
|
||||
self.str("T1");
|
||||
@@ -1689,6 +1730,29 @@ mod tests {
|
||||
const SQUARE: [(f64, f64); 4] = [(0.0, 0.0), (5.0, 0.0), (5.0, 0.4), (0.0, 0.4)];
|
||||
|
||||
/// Ein Projekt mit je einem Bauteil jeder Art; zwei Wände gleichen Typs (Pset/Typ müssen sich teilen).
|
||||
/// Füllungs-Parameter: Wand (sx, sy) → (ex, ey), Achs-Intervall, Höhen, Dicke ±0.2.
|
||||
fn fill(is_door: bool, wall: [f64; 4], from: f64, to: f64, z0: f64, z1: f64) -> FillParams {
|
||||
FillParams {
|
||||
wall_start: (wall[0], wall[1]),
|
||||
wall_end: (wall[2], wall[3]),
|
||||
from,
|
||||
to,
|
||||
z_bottom: z0,
|
||||
z_top: z1,
|
||||
n_lo: -0.2,
|
||||
n_hi: 0.2,
|
||||
is_door,
|
||||
inset_outside: true,
|
||||
wing_count: 1.0,
|
||||
panes: 2,
|
||||
leaf_count: 1.0,
|
||||
swing_sign: 1.0,
|
||||
dir_sign: 1.0,
|
||||
hinge_at_start: true,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn full_house(with_geo: bool) -> B {
|
||||
let mut b = B::new();
|
||||
b.str("t");
|
||||
@@ -1716,15 +1780,11 @@ mod tests {
|
||||
b.n(&[0.0, 2.6]);
|
||||
}
|
||||
// Öffnung in W1: Tür mit Zarge, Blatt und Glas.
|
||||
// Scharnier am Ende, Aufschlag nach +Y: LEFT; Oberlicht gibt Glas.
|
||||
b.opening(
|
||||
"W1", "T1", true, "Haustür",
|
||||
&[(1.0, -0.02), (1.9, -0.02), (1.9, 0.42), (1.0, 0.42)], 0.0, 2.1, 0.9,
|
||||
Some("SINGLE_SWING_LEFT"), [1.45, 0.0, 0.0, 1.0],
|
||||
&[
|
||||
(0.0, &[(1.0, 0.0), (1.06, 0.0), (1.06, 0.07), (1.0, 0.07)], 0.0, 2.1),
|
||||
(1.0, &[(1.06, 0.015), (1.84, 0.015), (1.84, 0.055), (1.06, 0.055)], 0.0, 2.04),
|
||||
(2.0, &[(1.2, 0.02), (1.6, 0.02), (1.6, 0.05), (1.2, 0.05)], 0.5, 1.0),
|
||||
],
|
||||
&FillParams { hinge_at_start: false, transom_height: 0.4, ..fill(true, [0.0, 0.0, 5.0, 0.0], 1.0, 1.9, 0.0, 2.1) },
|
||||
);
|
||||
// Decke, Treppe, Extrusion.
|
||||
b.n(&[REC_CEILING, 0.0]);
|
||||
@@ -1923,8 +1983,7 @@ mod tests {
|
||||
b.opening(
|
||||
"W", "O", false, "Fenster",
|
||||
&[(10.3, 21.0), (10.3, 22.0), (9.7, 22.0), (9.7, 21.0)], 0.9, 1.2, 1.0,
|
||||
Some("SINGLE_PANEL"), [10.0, 21.5, 0.0, 1.0],
|
||||
&[(0.0, &[(10.2, 21.0), (10.2, 22.0), (9.8, 22.0), (9.8, 21.0)], 0.0, 1.2)],
|
||||
&fill(false, [10.0, 20.0, 10.0, 25.0], 1.0, 2.0, 0.9, 2.1),
|
||||
);
|
||||
let ifc = build(&b).unwrap();
|
||||
check_structure(&ifc);
|
||||
@@ -1946,14 +2005,15 @@ mod tests {
|
||||
check_structure(&ifc);
|
||||
let door = first_line(&ifc, "IFCDOOR");
|
||||
assert!(door.contains(".DOOR.,.SINGLE_SWING_LEFT.,$);"), "{door}");
|
||||
// Drei Körper (Zarge, Blatt, Glas) in EINER Darstellung, je ein IfcStyledItem, drei Stile.
|
||||
assert_eq!(count(&ifc, "IFCSTYLEDITEM"), 3);
|
||||
// Sechs Körper (Zarge 3, Kämpfer, Oberlicht-Glas, Blatt) in EINER Darstellung, je ein
|
||||
// IfcStyledItem, drei Stile (Rahmen, Blatt, Glas).
|
||||
assert_eq!(count(&ifc, "IFCSTYLEDITEM"), 6);
|
||||
assert_eq!(count(&ifc, "IFCSURFACESTYLE"), 3);
|
||||
assert_eq!(count(&ifc, "IFCSURFACESTYLERENDERING"), 3);
|
||||
assert!(ifc.contains("IFCSURFACESTYLE('Glas',.BOTH.,"));
|
||||
assert!(ifc.contains("IFCSURFACESTYLERENDERING(#"));
|
||||
let shapes = ifc.lines().filter(|l| l.contains("IFCSHAPEREPRESENTATION") && l.contains("'SweptSolid'") && l.matches('#').count() == 5).count();
|
||||
assert!(shapes >= 1, "Darstellung mit 3 Körpern fehlt");
|
||||
let shapes = ifc.lines().filter(|l| l.contains("IFCSHAPEREPRESENTATION") && l.contains("'SweptSolid'") && l.matches('#').count() == 8).count();
|
||||
assert!(shapes >= 1, "Darstellung mit 6 Körpern fehlt");
|
||||
// Füllungs-Placement mit Richtung (0,1,0) relativ zur Öffnung; Ursprung lokal.
|
||||
assert!(ifc.contains("IFCCARTESIANPOINT((1.45,0.0,0.0))"));
|
||||
}
|
||||
@@ -1961,26 +2021,34 @@ mod tests {
|
||||
#[test]
|
||||
fn fenster_ohne_teile_hat_keine_darstellung_und_enum_ist_geprueft() {
|
||||
let mut b = full_house(false);
|
||||
b.opening("W1", "F1", false, "Fenster", &SQUARE, 0.9, 1.2, 1.2, Some("DOUBLE_PANEL_VERTICAL"), [2.0, 0.0, 1.0, 0.0], &[]);
|
||||
b.opening("W1", "T2", true, "Wandöffnung", &SQUARE, 0.0, 2.1, 1.0, None, [3.0, 0.0, 1.0, 0.0], &[]);
|
||||
let w1 = [0.0, 0.0, 5.0, 0.0];
|
||||
b.opening("W1", "F1", false, "Fenster", &SQUARE, 0.9, 1.2, 1.2, &FillParams { wing_count: 2.0, ..fill(false, w1, 2.0, 3.2, 0.9, 2.1) });
|
||||
b.opening("W1", "T2", true, "Wandöffnung", &SQUARE, 0.0, 2.1, 1.0, &FillParams { door_kind: DoorKind::WallOpening, ..fill(true, w1, 3.0, 4.0, 0.0, 2.1) });
|
||||
let ifc = build(&b).unwrap();
|
||||
check_structure(&ifc);
|
||||
let win = first_line(&ifc, "IFCWINDOW");
|
||||
assert!(win.contains(".WINDOW.,.DOUBLE_PANEL_VERTICAL.,$);"), "{win}");
|
||||
assert!(win.contains(",$,$,1.2,1.2,.WINDOW."), "ohne Teile keine Darstellung: {win}");
|
||||
// Ungültige Ausführung (Fenster-Wert an der Tür und umgekehrt) ist ein Fehler, nie Panic.
|
||||
let hole = ifc.lines().filter(|l| l.contains("IFCDOOR(")).find(|l| l.contains(",$,$,2.1,1.0,.DOOR.,$,$);"));
|
||||
assert!(hole.is_some(), "Wandöffnung ohne Darstellung und Ausführung");
|
||||
// Kaputte Parameter: Fehler, nie Panic.
|
||||
let bad_params = [
|
||||
FillParams { panes: 0, ..fill(false, w1, 1.0, 2.0, 0.9, 2.1) },
|
||||
FillParams { swing_sign: 0.0, ..fill(true, w1, 1.0, 2.0, 0.0, 2.1) },
|
||||
FillParams { wing_count: f64::NAN, ..fill(false, w1, 1.0, 2.0, 0.9, 2.1) },
|
||||
FillParams { sashes: vec![Sash::default(); MAX_SASHES + 1], ..fill(false, w1, 1.0, 2.0, 0.9, 2.1) },
|
||||
// Wand ohne Länge: keine Richtung.
|
||||
fill(false, [1.0, 1.0, 1.0, 1.0], 0.0, 1.0, 0.0, 1.0),
|
||||
];
|
||||
for p in bad_params {
|
||||
let mut bad = full_house(false);
|
||||
bad.opening("W1", "F9", false, "Fenster", &SQUARE, 0.9, 1.2, 1.2, &p);
|
||||
assert!(build(&bad).is_err(), "{p:?}");
|
||||
}
|
||||
// Unbekannte Türart.
|
||||
let mut bad = full_house(false);
|
||||
bad.opening("W1", "T3", true, "Tür", &SQUARE, 0.0, 2.1, 1.0, Some("SINGLE_PANEL"), [1.0, 0.0, 1.0, 0.0], &[]);
|
||||
assert!(build(&bad).is_err());
|
||||
let mut bad = full_house(false);
|
||||
bad.opening("W1", "F3", false, "Fenster", &SQUARE, 0.9, 1.2, 1.2, Some("SINGLE_SWING_LEFT"), [1.0, 0.0, 1.0, 0.0], &[]);
|
||||
assert!(build(&bad).is_err());
|
||||
// Unbekannte Teilrolle, schiefe Richtung: Fehler.
|
||||
let mut bad = full_house(false);
|
||||
bad.opening("W1", "F4", false, "Fenster", &SQUARE, 0.9, 1.2, 1.2, None, [1.0, 0.0, 1.0, 0.0], &[(3.0, &SQUARE, 0.0, 1.0)]);
|
||||
assert!(build(&bad).is_err());
|
||||
let mut bad = full_house(false);
|
||||
bad.opening("W1", "F5", false, "Fenster", &SQUARE, 0.9, 1.2, 1.2, None, [1.0, 0.0, 3.0, 0.0], &[]);
|
||||
bad.opening("W1", "T9", true, "Tür", &SQUARE, 0.0, 2.1, 1.0, &fill(true, w1, 1.0, 2.0, 0.0, 2.1));
|
||||
let at = bad.f.len() - 1 /* psets */ - 3 /* glazed, ratio-opt */ - 6;
|
||||
bad.f[at] = 7.0;
|
||||
assert!(build(&bad).is_err());
|
||||
}
|
||||
|
||||
@@ -2041,7 +2109,7 @@ mod tests {
|
||||
b.n(&[1.0]);
|
||||
b.str("iso");
|
||||
b.n(&[0.0, f64::NAN, 0.0]);
|
||||
b.opening("gibt-es-nicht", "O1", false, "Fenster", &SQUARE, 0.0, 1.0, 1.0, None, [0.0, 0.0, 1.0, 0.0], &[]);
|
||||
b.opening("gibt-es-nicht", "O1", false, "Fenster", &SQUARE, 0.0, 1.0, 1.0, &fill(false, [0.0, 0.0, 5.0, 0.0], 0.0, 1.0, 0.0, 1.0));
|
||||
let ifc = build(&b).unwrap();
|
||||
check_structure(&ifc);
|
||||
assert_eq!(count(&ifc, "IFCOPENINGELEMENT"), 0);
|
||||
|
||||
@@ -0,0 +1,572 @@
|
||||
// Geometrie der Türen und Fenster für den IFC-Export ([B5], Port von `src/export/ifcOpenings.ts`, 28.10.):
|
||||
// statt einer Box getrennte Körper im selben Bauteil — Rahmen/Zarge, Türblatt bzw. Glas — plus
|
||||
// OperationType (Tür) und PartitioningType (Fenster). Alles sind vertikale Extrusionen von Grundriss-
|
||||
// Rechtecken (wie die Wände), Profile in Welt-XY, Höhen ab Öffnungs-Unterkante; `ifc_export.rs` rechnet sie
|
||||
// ins Füllungssystem. TS sammelt nur die Parameter aus dem Modell (`FillParams`, Kodierung im Kopf von
|
||||
// `ifc_export.rs`).
|
||||
//
|
||||
// Masse kommen aus dem Modell, soweit es sie hergibt (Rahmenbreite/-tiefe, Schichteinzug, Flügelzahl und
|
||||
// -tabelle, Verglasung, Blattzahl, Glasanteil, Oberlicht). Fehlendes füllen dieselben Konstanten wie das 3D
|
||||
// (`src-tauri/core/src/openings3d.rs`), damit IFC und Ansicht dasselbe zeigen:
|
||||
// - Rahmenbreite 6 cm, Rahmentiefe 7 cm (reale Rahmen sind 70–90 mm tief, nicht so dick wie die Wand),
|
||||
// Türblatt 4 cm.
|
||||
// - Glaspaket: nur im IFC nötig, das 3D zeichnet Einzelscheiben. 1 Scheibe 6 mm, 2 Scheiben 24 mm
|
||||
// (4-16-4, übliches Isolierglas), 3 Scheiben 36 mm (4-12-4-12-4 ≈ 36 mm).
|
||||
// Nicht abgebildet (bewusst einfach): Sprossen, Fensterbank/Rollladenkasten, Schwelle, Flügelrahmen im
|
||||
// Blendrahmen, Kassettenfelder, Schiebe-Laufschiene — die Körper stehen im geschlossenen Zustand.
|
||||
//
|
||||
// Bitgleich zur TS-Fassung (Golden-Vergleich der IFC-Ausgabe): JS-Zahlsemantik für Math.min/max/round und
|
||||
// Math.hypot (Kopien aus `src-tauri/core/src/jsnum.rs`/`jsmath.rs`, fileio hängt nicht vom Kern ab),
|
||||
// Rechenreihenfolge wie in TS.
|
||||
|
||||
pub const DEFAULT_FRAME_WIDTH: f64 = 0.06;
|
||||
pub const DEFAULT_FRAME_DEPTH: f64 = 0.07;
|
||||
pub const DOOR_LEAF_THICK: f64 = 0.04;
|
||||
/// Glaspaket-Dicke je Scheibenzahl (1, 2, 3).
|
||||
pub const GLASS_PACKAGE_THICKNESS: [f64; 3] = [0.006, 0.024, 0.036];
|
||||
/// Glasanteil des Türblatts, wenn der Typ keinen angibt.
|
||||
const DEFAULT_GLAZING_RATIO: f64 = 0.5;
|
||||
/// Kleinste Teilabmessung, damit nie ein flaches Profil entsteht (Meter).
|
||||
const MIN_DIM: f64 = 0.005;
|
||||
/// Pfostenbreite einer Flügeltabelle ohne Angabe.
|
||||
const DEFAULT_POST_WIDTH: f64 = 0.06;
|
||||
/// Höchstzahl Flügel (Unsinn-Schutz; TS kennt 1–4).
|
||||
pub const MAX_SASHES: usize = 64;
|
||||
|
||||
/// `Math.min(a, b)` (NaN gewinnt; −0 < +0).
|
||||
fn js_min(a: f64, b: f64) -> f64 {
|
||||
if a.is_nan() || b.is_nan() {
|
||||
f64::NAN
|
||||
} else if a < b || (a == b && a.is_sign_negative()) {
|
||||
a
|
||||
} else {
|
||||
b
|
||||
}
|
||||
}
|
||||
/// `Math.max(a, b)` (NaN gewinnt; +0 > −0).
|
||||
fn js_max(a: f64, b: f64) -> f64 {
|
||||
if a.is_nan() || b.is_nan() {
|
||||
f64::NAN
|
||||
} else if a > b || (a == b && a.is_sign_positive()) {
|
||||
a
|
||||
} else {
|
||||
b
|
||||
}
|
||||
}
|
||||
/// `Math.round(x)`.
|
||||
fn js_round(x: f64) -> f64 {
|
||||
if !x.is_finite() || x == 0.0 {
|
||||
return x;
|
||||
}
|
||||
if x > 0.0 && x < 0.5 {
|
||||
return 0.0;
|
||||
}
|
||||
if x < 0.0 && x >= -0.5 {
|
||||
return -0.0;
|
||||
}
|
||||
let r = x.ceil();
|
||||
if r - 0.5 > x { r - 1.0 } else { r }
|
||||
}
|
||||
/// `Math.hypot(a, b)` wie V8.
|
||||
fn js_hypot2(a: f64, b: f64) -> f64 {
|
||||
let v = [a, b];
|
||||
let mut max = 0.0f64;
|
||||
let mut nan = false;
|
||||
for &x in &v {
|
||||
let a = x.abs();
|
||||
if a.is_infinite() {
|
||||
return f64::INFINITY;
|
||||
}
|
||||
if a.is_nan() {
|
||||
nan = true;
|
||||
} else if a > max {
|
||||
max = a;
|
||||
}
|
||||
}
|
||||
if nan {
|
||||
return f64::NAN;
|
||||
}
|
||||
if max == 0.0 {
|
||||
return 0.0;
|
||||
}
|
||||
let (mut sum, mut comp) = (0.0f64, 0.0f64);
|
||||
for &x in &v {
|
||||
let n = x.abs() / max;
|
||||
let summand = n * n - comp;
|
||||
let prelim = sum + summand;
|
||||
comp = (prelim - sum) - summand;
|
||||
sum = prelim;
|
||||
}
|
||||
sum.sqrt() * max
|
||||
}
|
||||
|
||||
type V2 = (f64, f64);
|
||||
|
||||
/// Ein Eintrag der Flügeltabelle (`SashDef`), wie im Modell.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
||||
pub struct Sash {
|
||||
/// `kind === "pfosten"`.
|
||||
pub post: bool,
|
||||
/// `postWidth` (None = nicht gesetzt).
|
||||
pub post_width: Option<f64>,
|
||||
/// `autoWidth === false`.
|
||||
pub fixed: bool,
|
||||
/// `width` (None = nicht gesetzt).
|
||||
pub width: Option<f64>,
|
||||
}
|
||||
|
||||
/// Art einer Tür (`DoorType.kind`, Inline `doorType: "wandoeffnung"`).
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub enum DoorKind {
|
||||
#[default]
|
||||
Swing,
|
||||
Sliding,
|
||||
WallOpening,
|
||||
}
|
||||
|
||||
/// Parameter einer Füllung aus dem Modell (TS `fillParams`); fehlende Typwerte als `None`.
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct FillParams {
|
||||
pub wall_start: V2,
|
||||
pub wall_end: V2,
|
||||
/// Achs-Intervall (Abstand ab `wall_start`) und absolute Höhen der Öffnung.
|
||||
pub from: f64,
|
||||
pub to: f64,
|
||||
pub z_bottom: f64,
|
||||
pub z_top: f64,
|
||||
/// Querausdehnung der Wand entlang der linken Normalen ab `wall_start` (`n_lo` = Aussenseite).
|
||||
pub n_lo: f64,
|
||||
pub n_hi: f64,
|
||||
pub is_door: bool,
|
||||
/// Typ: `frameDepth`, `insetFromFace`, `insetFace === "aussen"` (Standard), `frameWidth`.
|
||||
pub frame_depth: Option<f64>,
|
||||
pub inset: Option<f64>,
|
||||
pub inset_outside: bool,
|
||||
pub frame_width: Option<f64>,
|
||||
/// Fenster: Flügelzahl (`opening.wingCount ?? type.wingCount ?? 1`), Scheiben (1–3), Flügeltabelle.
|
||||
pub wing_count: f64,
|
||||
pub panes: usize,
|
||||
pub sashes: Vec<Sash>,
|
||||
/// Tür: Art, Blattzahl, Aufschlagseite (+1 links der Achse / −1), Richtung (+1 innen / −1 aussen),
|
||||
/// Scharnier am Anfang, Oberlichthöhe, Glasblatt, Glasanteil.
|
||||
pub door_kind: DoorKind,
|
||||
pub leaf_count: f64,
|
||||
pub swing_sign: f64,
|
||||
pub dir_sign: f64,
|
||||
pub hinge_at_start: bool,
|
||||
pub transom_height: f64,
|
||||
pub glazed: bool,
|
||||
pub glazing_ratio: Option<f64>,
|
||||
}
|
||||
|
||||
/// Rolle eines Körpers: 0 Rahmen/Zarge, 1 Türblatt, 2 Glas.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct FillPart {
|
||||
pub role: usize,
|
||||
/// Profil in Welt-XY (Rechteck, gegen den Uhrzeigersinn in Achs-/Normalenrichtung).
|
||||
pub pts: Vec<V2>,
|
||||
/// Unterkante ab Öffnungs-Unterkante (m).
|
||||
pub z_rel: f64,
|
||||
/// Höhe des Körpers (m).
|
||||
pub depth: f64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct FillGeometry {
|
||||
/// Ursprung des Füllungssystems (Welt-XY): Öffnungsmitte auf der Wandachse.
|
||||
pub origin: V2,
|
||||
/// X-Richtung des Füllungssystems (Einheitsvektor); Y = linke Normale davon.
|
||||
pub u: V2,
|
||||
/// IfcDoorTypeOperationEnum bzw. IfcWindowTypePartitioningEnum; None = Modell gibt nichts her.
|
||||
pub kind: Option<&'static str>,
|
||||
pub parts: Vec<FillPart>,
|
||||
}
|
||||
|
||||
/// Flügeleinteilung, auf die Achsbreite aufgelöst: (von, bis, Pfosten?) ab Laibungsanfang.
|
||||
struct SashSpan {
|
||||
from: f64,
|
||||
to: f64,
|
||||
post: bool,
|
||||
}
|
||||
|
||||
/// Löst Flügel und Pfosten zu Intervallen auf: Pfosten und Flügel mit fester Breite behalten sie, die
|
||||
/// übrigen teilen den Rest gleichmässig (gleiche Regel wie `sashSegments` im 2D). Ohne Tabelle:
|
||||
/// `wing_count` gleiche Flügel.
|
||||
fn sash_spans(sashes: &[Sash], wing_count: f64, total: f64) -> Vec<SashSpan> {
|
||||
let list: Vec<Sash> = if !sashes.is_empty() {
|
||||
sashes.to_vec()
|
||||
} else {
|
||||
// Array.from({ length: Math.max(1, Math.round(wingCount)) }) — NaN ergibt eine leere Liste.
|
||||
let n = js_max(1.0, js_round(wing_count));
|
||||
let n = if n.is_nan() { 0 } else { (n as usize).min(MAX_SASHES) };
|
||||
vec![Sash::default(); n]
|
||||
};
|
||||
let post_w = |s: &Sash| js_max(0.0, s.post_width.unwrap_or(DEFAULT_POST_WIDTH));
|
||||
let fixed_w = |s: &Sash| -> Option<f64> {
|
||||
if s.post {
|
||||
Some(post_w(s))
|
||||
} else if s.fixed {
|
||||
Some(js_max(0.0, s.width.unwrap_or(0.0)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
};
|
||||
let mut fixed = 0.0;
|
||||
let mut auto = 0usize;
|
||||
for s in &list {
|
||||
match fixed_w(s) {
|
||||
None => auto += 1,
|
||||
Some(w) => fixed += w,
|
||||
}
|
||||
}
|
||||
let auto_w = if auto > 0 { js_max(0.0, total - fixed) / auto as f64 } else { 0.0 };
|
||||
let mut out = Vec::with_capacity(list.len());
|
||||
let mut at = 0.0;
|
||||
for s in &list {
|
||||
let w = fixed_w(s).unwrap_or(auto_w);
|
||||
out.push(SashSpan { from: at, to: at + w, post: s.post });
|
||||
at += w;
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Körper und Ausführung der Füllung einer Öffnung (Gegenstück der früheren TS-Funktion `fillGeometry`).
|
||||
pub fn fill_geometry(p: &FillParams) -> FillGeometry {
|
||||
let (dx, dy) = (p.wall_end.0 - p.wall_start.0, p.wall_end.1 - p.wall_start.1);
|
||||
let len = js_hypot2(dx, dy);
|
||||
let len = if len == 0.0 || len.is_nan() { 1.0 } else { len };
|
||||
let u = (dx / len, dy / len);
|
||||
let n = (-u.1, u.0);
|
||||
let w = p.to - p.from;
|
||||
let h = p.z_top - p.z_bottom;
|
||||
let at = |a: f64, b: f64| -> V2 { (p.wall_start.0 + u.0 * a + n.0 * b, p.wall_start.1 + u.1 * a + n.1 * b) };
|
||||
let rect = |a0: f64, a1: f64, b0: f64, b1: f64| vec![at(a0, b0), at(a1, b0), at(a1, b1), at(a0, b1)];
|
||||
let center = p.from + w / 2.0;
|
||||
let origin = at(center, 0.0);
|
||||
let mut parts: Vec<FillPart> = Vec::new();
|
||||
let mut add = |role: usize, a0: f64, a1: f64, b0: f64, b1: f64, z0: f64, z1: f64| {
|
||||
if a1 - a0 < 1e-6 || b1 - b0 < 1e-6 || z1 - z0 < 1e-6 {
|
||||
return;
|
||||
}
|
||||
parts.push(FillPart { role, pts: rect(a0, a1, b0, b1), z_rel: z0, depth: z1 - z0 });
|
||||
};
|
||||
|
||||
// Querlage des Rahmens: Tiefe (Typ oder 7 cm), Schichteinzug von der gewählten Wandfläche, auf die
|
||||
// Wanddicke geklemmt — dieselbe Rechnung wie `windowSymbol` (2D) und `resolveFrameNormalRange` (3D).
|
||||
let total = p.n_hi - p.n_lo;
|
||||
let fd = match p.frame_depth {
|
||||
Some(d) if d > 1e-9 => d,
|
||||
_ => DEFAULT_FRAME_DEPTH,
|
||||
};
|
||||
let frame_depth = js_min(total, fd);
|
||||
let inset = js_max(0.0, p.inset.unwrap_or(0.0));
|
||||
let front = if p.inset_outside { p.n_lo + inset } else { p.n_hi - inset };
|
||||
let back = if p.inset_outside { front + frame_depth } else { front - frame_depth };
|
||||
let mut b0 = js_max(p.n_lo, js_min(p.n_hi, js_min(front, back)));
|
||||
let mut b1 = js_max(p.n_lo, js_min(p.n_hi, js_max(front, back)));
|
||||
if b1 - b0 < MIN_DIM {
|
||||
b0 = p.n_lo;
|
||||
b1 = p.n_hi;
|
||||
}
|
||||
let b_mid = (b0 + b1) / 2.0;
|
||||
|
||||
// Sichtbare Rahmenbreite: höchstens ein Viertel der kleineren Öffnungsabmessung, sonst bliebe nichts offen.
|
||||
let fw_t = match p.frame_width {
|
||||
Some(x) if x > 1e-9 => x,
|
||||
_ => DEFAULT_FRAME_WIDTH,
|
||||
};
|
||||
let fw = js_max(MIN_DIM, js_min(fw_t, js_min(w, h) / 4.0));
|
||||
let a_in0 = p.from + fw;
|
||||
let a_in1 = p.to - fw;
|
||||
|
||||
if !p.is_door {
|
||||
// ── Fenster: Blendrahmen (Pfosten links/rechts, Sturz, Sohlbank), Mittelpfosten, Glas je Flügel ──
|
||||
add(0, p.from, a_in0, b0, b1, 0.0, h);
|
||||
add(0, a_in1, p.to, b0, b1, 0.0, h);
|
||||
add(0, a_in0, a_in1, b0, b1, h - fw, h);
|
||||
add(0, a_in0, a_in1, b0, b1, 0.0, fw);
|
||||
let pane = GLASS_PACKAGE_THICKNESS[p.panes.clamp(1, 3) - 1];
|
||||
let gt = js_min(pane, b1 - b0);
|
||||
let g0 = b_mid - gt / 2.0;
|
||||
let g1 = b_mid + gt / 2.0;
|
||||
let spans = sash_spans(&p.sashes, p.wing_count, a_in1 - a_in0);
|
||||
let mut glass_count = 0;
|
||||
for (i, s) in spans.iter().enumerate() {
|
||||
let x0 = a_in0 + s.from;
|
||||
let x1 = a_in0 + s.to;
|
||||
if s.post {
|
||||
add(0, x0, x1, b0, b1, fw, h - fw);
|
||||
continue;
|
||||
}
|
||||
// Zwischen zwei Flügeln ohne Pfosten steht ein Mittelpfosten (Breite = Rahmenbreite) auf der Grenze.
|
||||
let gx0 = if i == 0 || spans[i - 1].post { x0 } else { x0 + fw / 2.0 };
|
||||
let gx1 = if i == spans.len() - 1 || spans[i + 1].post { x1 } else { x1 - fw / 2.0 };
|
||||
if spans.get(i + 1).is_some_and(|nx| !nx.post) {
|
||||
add(0, x1 - fw / 2.0, x1 + fw / 2.0, b0, b1, fw, h - fw);
|
||||
}
|
||||
add(2, gx0, gx1, g0, g1, fw, h - fw);
|
||||
glass_count += 1;
|
||||
}
|
||||
// Teilung nach IFC: nur die senkrechten Standardfälle sind benannt (sonst NOTDEFINED, das Modell
|
||||
// kennt Sprossen und Seitenverhältnisse, die IFC nicht als Enum führt).
|
||||
let kind = match glass_count {
|
||||
1 => "SINGLE_PANEL",
|
||||
2 => "DOUBLE_PANEL_VERTICAL",
|
||||
3 => "TRIPLE_PANEL_VERTICAL",
|
||||
_ => "NOTDEFINED",
|
||||
};
|
||||
return FillGeometry { origin, u, kind: Some(kind), parts };
|
||||
}
|
||||
|
||||
// ── Tür ──
|
||||
// Aufschlagrichtung wie `doorSymbol`: linke Achsnormale, Richtung „aussen“ spiegelt sie.
|
||||
let swing_dir = (n.0 * p.swing_sign * p.dir_sign, n.1 * p.swing_sign * p.dir_sign);
|
||||
// Füllungssystem der Tür: Y = Aufschlagrichtung (IFC: die Tür schlägt nach +Y auf), X = Y × Z.
|
||||
let door_u = (swing_dir.1, -swing_dir.0);
|
||||
if p.door_kind == DoorKind::WallOpening {
|
||||
return FillGeometry { origin, u: door_u, kind: None, parts: Vec::new() };
|
||||
}
|
||||
|
||||
// Zarge: Pfosten links/rechts über die ganze Höhe und Sturz (keine Schwelle).
|
||||
add(0, p.from, a_in0, b0, b1, 0.0, h);
|
||||
add(0, a_in1, p.to, b0, b1, 0.0, h);
|
||||
add(0, a_in0, a_in1, b0, b1, h - fw, h);
|
||||
|
||||
// Oberlicht: fester Glasstreifen über einem Kämpfer (Riegel in Rahmenbreite) innerhalb der Öffnungshöhe.
|
||||
let th = p.transom_height;
|
||||
let has_transom = th > MIN_DIM && th < h - fw - 0.5;
|
||||
let leaf_top = if has_transom { h - fw - th - fw } else { h - fw };
|
||||
if has_transom {
|
||||
add(0, a_in0, a_in1, b0, b1, leaf_top, leaf_top + fw);
|
||||
let gt = js_min(GLASS_PACKAGE_THICKNESS[1], b1 - b0);
|
||||
add(2, a_in0, a_in1, b_mid - gt / 2.0, b_mid + gt / 2.0, leaf_top + fw, h - fw);
|
||||
}
|
||||
|
||||
// Türblatt/-blätter im lichten Mass der Zarge, mittig in der Rahmentiefe.
|
||||
let lt = js_min(DOOR_LEAF_THICK, b1 - b0);
|
||||
let l0 = b_mid - lt / 2.0;
|
||||
let l1 = b_mid + lt / 2.0;
|
||||
let leaf_spans: Vec<(f64, f64)> = if p.leaf_count >= 2.0 {
|
||||
vec![(a_in0, (a_in0 + a_in1) / 2.0), ((a_in0 + a_in1) / 2.0, a_in1)]
|
||||
} else {
|
||||
vec![(a_in0, a_in1)]
|
||||
};
|
||||
let ratio = js_min(0.9, js_max(0.05, p.glazing_ratio.unwrap_or(DEFAULT_GLAZING_RATIO)));
|
||||
for (x0, x1) in leaf_spans {
|
||||
if !p.glazed {
|
||||
add(1, x0, x1, l0, l1, 0.0, leaf_top);
|
||||
continue;
|
||||
}
|
||||
// Glastür: Glasfläche = Glasanteil des Blatts (gleichmässig verkleinert um die Blattmitte), das Blatt
|
||||
// als umlaufender Rahmen darum; das Glas füllt die Blattdicke zu 60 % (4–24 mm, mittig).
|
||||
let s = ratio.sqrt();
|
||||
let cx = (x0 + x1) / 2.0;
|
||||
let cz = leaf_top / 2.0;
|
||||
let gw = (x1 - x0) * s;
|
||||
let gh = leaf_top * s;
|
||||
let (px0, px1, pz0, pz1) = (cx - gw / 2.0, cx + gw / 2.0, cz - gh / 2.0, cz + gh / 2.0);
|
||||
add(1, x0, x1, l0, l1, 0.0, pz0);
|
||||
add(1, x0, x1, l0, l1, pz1, leaf_top);
|
||||
add(1, x0, px0, l0, l1, pz0, pz1);
|
||||
add(1, px1, x1, l0, l1, pz0, pz1);
|
||||
let gt = js_min(GLASS_PACKAGE_THICKNESS[1], lt * 0.6);
|
||||
add(2, px0, px1, b_mid - gt / 2.0, b_mid + gt / 2.0, pz0, pz1);
|
||||
}
|
||||
|
||||
// OperationType: Blattzahl und Scharnierseite. IFC blickt von der Aufschlagseite (+Y des Füllungssystems)
|
||||
// auf die Tür; "links" = Scharnier auf der +X-Seite des Systems (X = Y × Z, von +Y aus gesehen links).
|
||||
let hinge_axis = if p.hinge_at_start { p.from } else { p.to };
|
||||
let ha = at(hinge_axis, 0.0);
|
||||
let hinge_local_x = (ha.0 - origin.0) * door_u.0 + (ha.1 - origin.1) * door_u.1;
|
||||
let left = hinge_local_x > 0.0;
|
||||
let op = if p.door_kind == DoorKind::Sliding {
|
||||
if p.leaf_count >= 2.0 {
|
||||
"DOUBLE_DOOR_SLIDING"
|
||||
} else if left {
|
||||
"SLIDING_TO_LEFT"
|
||||
} else {
|
||||
"SLIDING_TO_RIGHT"
|
||||
}
|
||||
} else if p.leaf_count >= 2.0 {
|
||||
"DOUBLE_DOOR_SINGLE_SWING"
|
||||
} else if left {
|
||||
"SINGLE_SWING_LEFT"
|
||||
} else {
|
||||
"SINGLE_SWING_RIGHT"
|
||||
};
|
||||
FillGeometry { origin, u: door_u, kind: Some(op), parts }
|
||||
}
|
||||
|
||||
// Tests: die früheren TS-Fälle (`ifcOpenings.test.ts`), Wand entlang +X von (0,0) nach (5,0), 0.4 dick.
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn base(is_door: bool, from: f64, width: f64, z0: f64, height: f64) -> FillParams {
|
||||
FillParams {
|
||||
wall_start: (0.0, 0.0),
|
||||
wall_end: (5.0, 0.0),
|
||||
from,
|
||||
to: from + width,
|
||||
z_bottom: z0,
|
||||
z_top: z0 + height,
|
||||
n_lo: -0.2,
|
||||
n_hi: 0.2,
|
||||
is_door,
|
||||
inset_outside: true,
|
||||
wing_count: 1.0,
|
||||
panes: 2,
|
||||
leaf_count: 1.0,
|
||||
swing_sign: 1.0,
|
||||
dir_sign: 1.0,
|
||||
hinge_at_start: true,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
fn win() -> FillParams {
|
||||
base(false, 1.0, 1.2, 0.9, 1.2)
|
||||
}
|
||||
fn door() -> FillParams {
|
||||
base(true, 1.0, 1.0, 0.0, 2.1)
|
||||
}
|
||||
struct B {
|
||||
x0: f64,
|
||||
x1: f64,
|
||||
y0: f64,
|
||||
y1: f64,
|
||||
}
|
||||
fn bbox(p: &[V2]) -> B {
|
||||
let f = |g: fn(&V2) -> f64, init: f64, m: fn(f64, f64) -> f64| p.iter().map(g).fold(init, m);
|
||||
B { x0: f(|q| q.0, f64::MAX, f64::min), x1: f(|q| q.0, f64::MIN, f64::max), y0: f(|q| q.1, f64::MAX, f64::min), y1: f(|q| q.1, f64::MIN, f64::max) }
|
||||
}
|
||||
fn volume(parts: &[&FillPart]) -> f64 {
|
||||
parts.iter().map(|p| {
|
||||
let b = bbox(&p.pts);
|
||||
(b.x1 - b.x0) * (b.y1 - b.y0) * p.depth
|
||||
}).sum()
|
||||
}
|
||||
fn role(g: &FillGeometry, r: usize) -> Vec<&FillPart> {
|
||||
g.parts.iter().filter(|p| p.role == r).collect()
|
||||
}
|
||||
fn close(a: f64, b: f64) -> bool {
|
||||
(a - b).abs() < 1e-9
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fenster_rahmen_glas_konstanten() {
|
||||
let g = fill_geometry(&win());
|
||||
let (frame, glass) = (role(&g, 0), role(&g, 2));
|
||||
assert_eq!((frame.len(), glass.len(), g.kind), (4, 1, Some("SINGLE_PANEL")));
|
||||
let fw = DEFAULT_FRAME_WIDTH;
|
||||
assert!(close(volume(&frame), (1.2 * 1.2 - (1.2 - 2.0 * fw) * (1.2 - 2.0 * fw)) * DEFAULT_FRAME_DEPTH));
|
||||
let gb = bbox(&glass[0].pts);
|
||||
assert!(close(gb.x1 - gb.x0, 1.2 - 2.0 * fw) && close(gb.y1 - gb.y0, 0.024));
|
||||
assert!(close((gb.y0 + gb.y1) / 2.0, -0.2 + DEFAULT_FRAME_DEPTH / 2.0));
|
||||
assert!(close(glass[0].z_rel, fw) && close(glass[0].depth, 1.2 - 2.0 * fw));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fenster_masse_aus_typ_einzug_innen() {
|
||||
let p = FillParams { frame_width: Some(0.09), frame_depth: Some(0.1), inset: Some(0.05), inset_outside: false, panes: 3, ..win() };
|
||||
let g = fill_geometry(&p);
|
||||
let frame = role(&g, 0);
|
||||
let b = bbox(&frame[0].pts);
|
||||
assert!(close(b.y0, 0.05) && close(b.y1, 0.15));
|
||||
let gl = bbox(&role(&g, 2)[0].pts);
|
||||
assert!(close(gl.y1 - gl.y0, 0.036) && close(gl.x1 - gl.x0, 1.2 - 0.18));
|
||||
// Rahmentiefe auf die Wanddicke geklemmt.
|
||||
let g = fill_geometry(&FillParams { frame_depth: Some(1.0), ..win() });
|
||||
let b = bbox(&g.parts[0].pts);
|
||||
assert!(close(b.y0, -0.2) && close(b.y1, 0.2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fenster_fluegel_und_tabelle() {
|
||||
for (wing, kind) in [(2.0, "DOUBLE_PANEL_VERTICAL"), (3.0, "TRIPLE_PANEL_VERTICAL"), (4.0, "NOTDEFINED")] {
|
||||
let g = fill_geometry(&FillParams { wing_count: wing, ..win() });
|
||||
assert_eq!(role(&g, 2).len(), wing as usize);
|
||||
assert_eq!(role(&g, 0).len(), 4 + wing as usize - 1);
|
||||
assert_eq!(g.kind, Some(kind));
|
||||
}
|
||||
let sashes = vec![
|
||||
Sash { fixed: true, width: Some(0.5), ..Default::default() },
|
||||
Sash { post: true, post_width: Some(0.1), ..Default::default() },
|
||||
Sash::default(),
|
||||
];
|
||||
let g = fill_geometry(&FillParams { sashes, ..win() });
|
||||
let glass: Vec<B> = role(&g, 2).iter().map(|p| bbox(&p.pts)).collect();
|
||||
assert_eq!(glass.len(), 2);
|
||||
assert!(close(glass[0].x1 - glass[0].x0, 0.5));
|
||||
let clear = 1.2 - 2.0 * 0.06;
|
||||
assert!(close(glass[1].x1 - glass[1].x0, clear - 0.6) && close(glass[1].x0, glass[0].x1 + 0.1));
|
||||
assert_eq!(g.kind, Some("DOUBLE_PANEL_VERTICAL"));
|
||||
// Alles innerhalb der Öffnung und der Wand.
|
||||
for p in &fill_geometry(&FillParams { wing_count: 2.0, ..win() }).parts {
|
||||
let b = bbox(&p.pts);
|
||||
assert!(b.x0 >= 1.0 - 1e-9 && b.x1 <= 2.2 + 1e-9 && b.y0 >= -0.2 - 1e-9 && b.y1 <= 0.2 + 1e-9);
|
||||
assert!(p.z_rel >= -1e-9 && p.z_rel + p.depth <= 1.2 + 1e-9);
|
||||
}
|
||||
// Unsinnige Flügelzahl: keine Scheibe, kein Panic.
|
||||
assert!(role(&fill_geometry(&FillParams { wing_count: f64::NAN, ..win() }), 2).is_empty());
|
||||
assert!(fill_geometry(&FillParams { wing_count: 1e300, ..win() }).parts.len() <= 4 + 2 * MAX_SASHES);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tuer_zarge_blatt_glas_oberlicht() {
|
||||
let g = fill_geometry(&door());
|
||||
assert_eq!(role(&g, 0).len(), 3);
|
||||
let leaf = role(&g, 1);
|
||||
assert_eq!(leaf.len(), 1);
|
||||
let lb = bbox(&leaf[0].pts);
|
||||
assert!(close(lb.y1 - lb.y0, DOOR_LEAF_THICK) && close(lb.x1 - lb.x0, 1.0 - 2.0 * DEFAULT_FRAME_WIDTH));
|
||||
assert!(leaf[0].z_rel == 0.0 && close(leaf[0].depth, 2.1 - DEFAULT_FRAME_WIDTH));
|
||||
assert!(role(&g, 2).is_empty());
|
||||
// Zweiflügelig.
|
||||
let g = fill_geometry(&FillParams { leaf_count: 2.0, ..door() });
|
||||
assert_eq!((role(&g, 1).len(), g.kind), (2, Some("DOUBLE_DOOR_SINGLE_SWING")));
|
||||
// Glastür.
|
||||
let g = fill_geometry(&FillParams { glazed: true, glazing_ratio: Some(0.36), ..door() });
|
||||
let glass = role(&g, 2);
|
||||
assert_eq!(glass.len(), 1);
|
||||
let gb = bbox(&glass[0].pts);
|
||||
let (lw, lh) = (1.0 - 2.0 * DEFAULT_FRAME_WIDTH, 2.1 - DEFAULT_FRAME_WIDTH);
|
||||
assert!(close((gb.x1 - gb.x0) * glass[0].depth / (lw * lh), 0.36));
|
||||
let leaf = role(&g, 1);
|
||||
assert_eq!(leaf.len(), 4);
|
||||
assert!(close(volume(&leaf), (lw * lh - (gb.x1 - gb.x0) * glass[0].depth) * DOOR_LEAF_THICK));
|
||||
// Oberlicht.
|
||||
let g = fill_geometry(&FillParams { transom_height: 0.4, ..door() });
|
||||
let glass = role(&g, 2);
|
||||
assert!(close(glass[0].depth, 0.4) && close(glass[0].z_rel + glass[0].depth, 2.1 - DEFAULT_FRAME_WIDTH));
|
||||
let leaf = role(&g, 1)[0];
|
||||
assert!(close(leaf.z_rel + leaf.depth, 2.1 - DEFAULT_FRAME_WIDTH - 0.4 - DEFAULT_FRAME_WIDTH));
|
||||
// Reine Wandöffnung.
|
||||
let g = fill_geometry(&FillParams { door_kind: DoorKind::WallOpening, ..door() });
|
||||
assert!(g.kind.is_none() && g.parts.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tuer_anschlag_und_system() {
|
||||
// Wand entlang +X, linke Normale +Y. Standard: Aufschlag nach +Y, Scharnier am Anfang (x klein):
|
||||
// von +Y nach −Y gesehen liegt x klein rechts → RIGHT.
|
||||
let kind = |p: FillParams| fill_geometry(&p).kind;
|
||||
assert_eq!(kind(door()), Some("SINGLE_SWING_RIGHT"));
|
||||
assert_eq!(kind(FillParams { hinge_at_start: false, ..door() }), Some("SINGLE_SWING_LEFT"));
|
||||
assert_eq!(kind(FillParams { dir_sign: -1.0, ..door() }), Some("SINGLE_SWING_LEFT"));
|
||||
assert_eq!(kind(FillParams { swing_sign: -1.0, ..door() }), Some("SINGLE_SWING_LEFT"));
|
||||
assert_eq!(kind(FillParams { door_kind: DoorKind::Sliding, ..door() }), Some("SLIDING_TO_RIGHT"));
|
||||
assert_eq!(kind(FillParams { door_kind: DoorKind::Sliding, leaf_count: 2.0, ..door() }), Some("DOUBLE_DOOR_SLIDING"));
|
||||
let g = fill_geometry(&door());
|
||||
assert_eq!(g.origin, (1.5, 0.0));
|
||||
assert!(close(g.u.0, 1.0) && close(g.u.1, 0.0));
|
||||
assert!(close(fill_geometry(&FillParams { dir_sign: -1.0, ..door() }).u.0, -1.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn js_zahlen() {
|
||||
assert_eq!(js_round(2.5), 3.0);
|
||||
assert_eq!(js_round(-2.5), -2.0);
|
||||
assert!(js_min(0.0, -0.0).is_sign_negative() && js_max(-0.0, 0.0).is_sign_positive());
|
||||
assert_eq!(js_hypot2(3.0, 4.0), 5.0);
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ pub mod ifc_step;
|
||||
pub mod ifc_import;
|
||||
pub mod ifc_semantic;
|
||||
pub mod ifc_export;
|
||||
pub mod ifc_openings;
|
||||
pub mod csg;
|
||||
mod ifc_sweep;
|
||||
mod ifc_nurbs;
|
||||
|
||||
+23
-12
@@ -32,7 +32,7 @@
|
||||
// • Decke → IfcSlab (outline-Polygon, PredefinedType FLOOR).
|
||||
// • Öffnung → IfcOpeningElement (Quader über die ganze Wanddicke, etwas vorstehend) in der
|
||||
// Wand (IfcRelVoidsElement), darin IfcDoor/IfcWindow (IfcRelFillsElement) aus getrennten Körpern
|
||||
// ([B5], 28.10., `ifcOpenings.ts`): Rahmen/Zarge + Türblatt bzw. Glas je Flügel, mit Farbe/
|
||||
// ([B5], 28.10., Parameter `ifcOpenings.ts`, Rechnung `ifc_openings.rs`): Rahmen/Zarge + Türblatt bzw. Glas je Flügel, mit Farbe/
|
||||
// Transparenz je Rolle; OperationType (Tür: Blattzahl, Scharnierseite, Schiebe) und
|
||||
// PartitioningType (Fenster: Flügelzahl). Masse aus dem Modell (Rahmenbreite/-tiefe, Einzug,
|
||||
// Verglasung, Glasanteil, Oberlicht), sonst die Konstanten des 3D. Ohne Sprossen, Fensterbank,
|
||||
@@ -87,7 +87,7 @@ import { columnFootprint } from "../geometry/column";
|
||||
import { openingInterval, openingVerticalExtent } from "../geometry/opening";
|
||||
import { emitRoofs } from "../plan/toWalls3d/roofs";
|
||||
import { fileio } from "../engine/fileioWasm";
|
||||
import { fillGeometry, type FillGeometry } from "./ifcOpenings";
|
||||
import { fillParams, type FillParams } from "./ifcOpenings";
|
||||
|
||||
/** Deterministische 22-stellige IFC-GUID aus einem Namen (Rust, `ifc_export.rs::ifc_guid`). */
|
||||
export function ifcGuid(name: string): string {
|
||||
@@ -101,7 +101,7 @@ export function ifcString(s: string): string {
|
||||
|
||||
// ── Flacher Puffer (Gegenstück zu src-tauri/fileio/src/ifc_export.rs, dort die Kodierung) ─────
|
||||
|
||||
const FLAT_VERSION = 1;
|
||||
const FLAT_VERSION = 2;
|
||||
const REC_WALL_SOLIDS = 1;
|
||||
const REC_WALL_MESH = 2;
|
||||
const REC_CEILING = 3;
|
||||
@@ -246,18 +246,29 @@ class FlatIfc {
|
||||
voidZRel: number;
|
||||
depth: number;
|
||||
width: number;
|
||||
fill: FillGeometry;
|
||||
fill: FillParams;
|
||||
psets: PsetIn[];
|
||||
}): void {
|
||||
this.nums.push(REC_OPENING, this.str(o.wallId), o.structure, this.str(o.openingId), o.isDoor ? 1 : 0, this.str(o.fillName));
|
||||
this.pts(o.voidRect);
|
||||
this.nums.push(o.voidZRel, o.depth, o.width, o.fill.kind === null ? -1 : this.str(o.fill.kind));
|
||||
this.nums.push(o.fill.origin.x, o.fill.origin.y, o.fill.u.x, o.fill.u.y, o.fill.parts.length);
|
||||
for (const p of o.fill.parts) {
|
||||
this.nums.push(p.role);
|
||||
this.pts(p.pts);
|
||||
this.nums.push(p.zRel, p.depth);
|
||||
this.nums.push(o.voidZRel, o.depth, o.width);
|
||||
// FILL (Kopf von `ifc_export.rs`): Parameter, die Rust zu Körpern und Ausführung rechnet.
|
||||
const f = o.fill;
|
||||
const opt = (v: number | null | undefined) => this.nums.push(v == null ? 0 : 1, v ?? 0);
|
||||
this.nums.push(f.wallStart.x, f.wallStart.y, f.wallEnd.x, f.wallEnd.y, f.from, f.to, f.zBottom, f.zTop, f.nLo, f.nHi);
|
||||
opt(f.frameDepth);
|
||||
opt(f.inset);
|
||||
this.nums.push(f.insetOutside ? 1 : 0);
|
||||
opt(f.frameWidth);
|
||||
this.nums.push(f.wingCount, f.panes, f.sashes.length);
|
||||
for (const s of f.sashes) {
|
||||
this.nums.push(s.post ? 1 : 0);
|
||||
opt(s.postWidth);
|
||||
this.nums.push(s.fixed ? 1 : 0);
|
||||
opt(s.width);
|
||||
}
|
||||
this.nums.push(f.doorKind, f.leafCount, f.swingSign, f.dirSign, f.hingeAtStart ? 1 : 0, f.transomHeight, f.glazed ? 1 : 0);
|
||||
opt(f.glazingRatio);
|
||||
this.psets(o.psets);
|
||||
}
|
||||
|
||||
@@ -680,7 +691,7 @@ export function exportIfcSpf(projectIn: Project): string {
|
||||
// Der Öffnungskörper ist ein Quader über das Achs-Intervall und die Höhe, wie sie das 3D
|
||||
// stanzt (`openingInterval`/`openingVerticalExtent`), quer über alle Bänder der Wand plus
|
||||
// OPENING_OVERSHOOT. Die Füllung (Tür/Fenster) hat ein eigenes Placement
|
||||
// (Öffnungsmitte, Achse bzw. Aufschlagrichtung) und liegt in der Rahmentiefe (`ifcOpenings.ts`).
|
||||
// (Öffnungsmitte, Achse bzw. Aufschlagrichtung) und liegt in der Rahmentiefe (`ifc_openings.rs`).
|
||||
for (const wall of project.walls ?? []) {
|
||||
const host = hostExtent.get(wall.id);
|
||||
if (!host) continue; // Wirtswand übersprungen (degeneriert)
|
||||
@@ -715,7 +726,7 @@ export function exportIfcSpf(projectIn: Project): string {
|
||||
voidZRel: c.zBottom - baseOf(structure),
|
||||
depth,
|
||||
width: c.to - c.from,
|
||||
fill: fillGeometry(project, wall, opening, c, host),
|
||||
fill: fillParams(project, wall, opening, c, host),
|
||||
psets: [{ name: psetName, props }],
|
||||
});
|
||||
}
|
||||
|
||||
+56
-185
@@ -1,204 +1,75 @@
|
||||
// Geometrie der Türen/Fenster im IFC-Export ([B5]): Rahmen, Blatt, Glas, Ausführung. Reine Rechnung,
|
||||
// kein WASM nötig.
|
||||
// Türen/Fenster im IFC-Export ([B5]): TS sammelt nur die Parameter aus Typ und Öffnung; die Geometrie
|
||||
// rechnet Rust (`src-tauri/fileio/src/ifc_openings.rs`, dort die Fälle Rahmen/Blatt/Glas/Ausführung).
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { fillGeometry, DEFAULT_FRAME_WIDTH, DEFAULT_FRAME_DEPTH, DOOR_LEAF_THICK } from "./ifcOpenings";
|
||||
import { fillParams } from "./ifcOpenings";
|
||||
import type { DoorType, Opening, Project, Wall, WindowType } from "../model/types";
|
||||
|
||||
const wall = { id: "W", start: { x: 0, y: 0 }, end: { x: 5, y: 0 } } as Wall;
|
||||
const host = { nLo: -0.2, nHi: 0.2 };
|
||||
|
||||
function proj(over: { doorTypes?: DoorType[]; windowTypes?: WindowType[] }): Project {
|
||||
return { doorTypes: over.doorTypes ?? [], windowTypes: over.windowTypes ?? [] } as unknown as Project;
|
||||
}
|
||||
function door(over: Partial<Opening> = {}): Opening {
|
||||
return { id: "D", type: "opening", hostWallId: "W", categoryCode: "21", kind: "door", position: 1, width: 1, height: 2.1, sillHeight: 0, ...over } as Opening;
|
||||
}
|
||||
function win(over: Partial<Opening> = {}): Opening {
|
||||
return { id: "F", type: "opening", hostWallId: "W", categoryCode: "21", kind: "window", position: 1, width: 1.2, height: 1.2, sillHeight: 0.9, ...over } as Opening;
|
||||
}
|
||||
const proj = (over: { doorTypes?: DoorType[]; windowTypes?: WindowType[] }) =>
|
||||
({ doorTypes: over.doorTypes ?? [], windowTypes: over.windowTypes ?? [] }) as unknown as Project;
|
||||
const door = (over: Partial<Opening> = {}) =>
|
||||
({ id: "D", type: "opening", hostWallId: "W", categoryCode: "21", kind: "door", position: 1, width: 1, height: 2.1, sillHeight: 0, ...over }) as Opening;
|
||||
const win = (over: Partial<Opening> = {}) =>
|
||||
({ id: "F", type: "opening", hostWallId: "W", categoryCode: "21", kind: "window", position: 1, width: 1.2, height: 1.2, sillHeight: 0.9, ...over }) as Opening;
|
||||
const cut = (o: Opening) => ({ from: o.position, to: o.position + o.width, zBottom: o.sillHeight, zTop: o.sillHeight + o.height });
|
||||
const wt = (over: Partial<WindowType> = {}): WindowType =>
|
||||
({ id: "wt", name: "Fenster", kind: "dreh", wingCount: 1, glazing: "zweifach", frameThickness: 0.08, defaultSillHeight: 0.9, defaultWidth: 1.2, defaultHeight: 1.2, ...over }) as WindowType;
|
||||
({ id: "wt", name: "Fenster", kind: "dreh", wingCount: 1, glazing: "dreifach", frameThickness: 0.08, defaultSillHeight: 0.9, defaultWidth: 1.2, defaultHeight: 1.2, ...over }) as WindowType;
|
||||
const dtp = (over: Partial<DoorType> = {}): DoorType =>
|
||||
({ id: "dt", name: "Tür", kind: "dreh", leafCount: 1, leafStyle: "glatt", frameThickness: 0.06, defaultWidth: 1, defaultHeight: 2.1, ...over }) as DoorType;
|
||||
|
||||
const bbox = (pts: { x: number; y: number }[]) => ({
|
||||
x0: Math.min(...pts.map((p) => p.x)),
|
||||
x1: Math.max(...pts.map((p) => p.x)),
|
||||
y0: Math.min(...pts.map((p) => p.y)),
|
||||
y1: Math.max(...pts.map((p) => p.y)),
|
||||
});
|
||||
const volume = (parts: { pts: { x: number; y: number }[]; depth: number }[]) =>
|
||||
parts.reduce((a, p) => {
|
||||
const b = bbox(p.pts);
|
||||
return a + (b.x1 - b.x0) * (b.y1 - b.y0) * p.depth;
|
||||
}, 0);
|
||||
|
||||
describe("fillGeometry — Fenster", () => {
|
||||
it("Blendrahmen aus 4 Teilen + eine Glasscheibe, Masse aus Konstanten, Glas = Paketdicke", () => {
|
||||
const o = win({ typeId: "wt" });
|
||||
const g = fillGeometry(proj({ windowTypes: [wt()] }), wall, o, cut(o), host);
|
||||
const frame = g.parts.filter((p) => p.role === 0);
|
||||
const glass = g.parts.filter((p) => p.role === 2);
|
||||
expect(frame.length).toBe(4);
|
||||
expect(glass.length).toBe(1);
|
||||
expect(g.kind).toBe("SINGLE_PANEL");
|
||||
// Rahmenvolumen = (W·H − lichtes Mass) · Tiefe
|
||||
const fw = DEFAULT_FRAME_WIDTH;
|
||||
expect(volume(frame)).toBeCloseTo((1.2 * 1.2 - (1.2 - 2 * fw) * (1.2 - 2 * fw)) * DEFAULT_FRAME_DEPTH, 9);
|
||||
// Glas füllt das lichte Mass, 24 mm (zweifach), mittig in der Rahmentiefe (aussen = nLo).
|
||||
const gb = bbox(glass[0].pts);
|
||||
expect(gb.x1 - gb.x0).toBeCloseTo(1.2 - 2 * fw, 9);
|
||||
expect(gb.y1 - gb.y0).toBeCloseTo(0.024, 9);
|
||||
expect((gb.y0 + gb.y1) / 2).toBeCloseTo(-0.2 + DEFAULT_FRAME_DEPTH / 2, 9);
|
||||
expect(glass[0].zRel).toBeCloseTo(fw, 9);
|
||||
expect(glass[0].depth).toBeCloseTo(1.2 - 2 * fw, 9);
|
||||
});
|
||||
it("Rahmenbreite/-tiefe/Einzug/Verglasung aus dem Typ; Einzug von innen", () => {
|
||||
const o = win({ typeId: "wt" });
|
||||
const t = wt({ frameWidth: 0.09, frameDepth: 0.1, insetFromFace: 0.05, insetFace: "innen", glazing: "dreifach" });
|
||||
const g = fillGeometry(proj({ windowTypes: [t] }), wall, o, cut(o), host);
|
||||
const frame = g.parts.filter((p) => p.role === 0);
|
||||
const b = bbox(frame[0].pts);
|
||||
// innen = nHi: Vorderkante 5 cm eingezogen → Rahmen von 0.05 bis 0.15 (Tiefe 10 cm nach aussen)
|
||||
expect(b.y0).toBeCloseTo(0.05, 9);
|
||||
expect(b.y1).toBeCloseTo(0.15, 9);
|
||||
expect(bbox(frame[2].pts).y1 - bbox(frame[2].pts).y0).toBeCloseTo(0.1, 9);
|
||||
const gl = bbox(g.parts.find((p) => p.role === 2)!.pts);
|
||||
expect(gl.y1 - gl.y0).toBeCloseTo(0.036, 9);
|
||||
expect(gl.x1 - gl.x0).toBeCloseTo(1.2 - 0.18, 9);
|
||||
});
|
||||
it("Rahmentiefe wird auf die Wanddicke geklemmt", () => {
|
||||
const o = win({ typeId: "wt" });
|
||||
const g = fillGeometry(proj({ windowTypes: [wt({ frameDepth: 1 })] }), wall, o, cut(o), host);
|
||||
const b = bbox(g.parts[0].pts);
|
||||
expect(b.y0).toBeCloseTo(-0.2, 9);
|
||||
expect(b.y1).toBeCloseTo(0.2, 9);
|
||||
});
|
||||
it("Flügelzahl → Mittelpfosten + eine Scheibe je Flügel, PartitioningType", () => {
|
||||
for (const [wing, kind] of [
|
||||
[2, "DOUBLE_PANEL_VERTICAL"],
|
||||
[3, "TRIPLE_PANEL_VERTICAL"],
|
||||
[4, "NOTDEFINED"],
|
||||
] as const) {
|
||||
const o = win({ typeId: "wt", wingCount: wing });
|
||||
const g = fillGeometry(proj({ windowTypes: [wt()] }), wall, o, cut(o), host);
|
||||
expect(g.parts.filter((p) => p.role === 2).length, `${wing}`).toBe(wing);
|
||||
expect(g.parts.filter((p) => p.role === 0).length, `${wing}`).toBe(4 + (wing - 1));
|
||||
expect(g.kind).toBe(kind);
|
||||
}
|
||||
});
|
||||
it("Flügeltabelle mit Pfosten und fester Breite: Gläser abgrenzend, keine Überlappung", () => {
|
||||
const o = win({ typeId: "wt" });
|
||||
describe("fillParams", () => {
|
||||
it("Fenster: Typwerte, Flügeltabelle, Flügelzahl der Öffnung vor dem Typ", () => {
|
||||
const t = wt({
|
||||
frameWidth: 0.09,
|
||||
frameDepth: 0.1,
|
||||
insetFromFace: 0.05,
|
||||
insetFace: "innen",
|
||||
wingCount: 3,
|
||||
sashes: [{ kind: "fluegel", autoWidth: false, width: 0.5 }, { kind: "pfosten", postWidth: 0.1 }, { kind: "fluegel" }],
|
||||
});
|
||||
const o = win({ typeId: "wt", wingCount: 2 });
|
||||
expect(fillParams(proj({ windowTypes: [t] }), wall, o, cut(o), host)).toMatchObject({
|
||||
from: 1,
|
||||
to: 2.2,
|
||||
zBottom: 0.9,
|
||||
zTop: 2.1,
|
||||
nLo: -0.2,
|
||||
nHi: 0.2,
|
||||
frameDepth: 0.1,
|
||||
frameWidth: 0.09,
|
||||
inset: 0.05,
|
||||
insetOutside: false,
|
||||
wingCount: 2,
|
||||
panes: 3,
|
||||
sashes: [
|
||||
{ kind: "fluegel", autoWidth: false, width: 0.5 },
|
||||
{ kind: "pfosten", postWidth: 0.1 },
|
||||
{ kind: "fluegel" },
|
||||
{ post: false, fixed: true, width: 0.5 },
|
||||
{ post: true, postWidth: 0.1, fixed: false },
|
||||
{ post: false, fixed: false },
|
||||
],
|
||||
});
|
||||
const g = fillGeometry(proj({ windowTypes: [t] }), wall, o, cut(o), host);
|
||||
const glass = g.parts.filter((p) => p.role === 2).map((p) => bbox(p.pts));
|
||||
expect(glass.length).toBe(2);
|
||||
expect(glass[0].x1 - glass[0].x0).toBeCloseTo(0.5, 9);
|
||||
const clear = 1.2 - 2 * 0.06;
|
||||
expect(glass[1].x1 - glass[1].x0).toBeCloseTo(clear - 0.6, 9);
|
||||
expect(glass[1].x0).toBeCloseTo(glass[0].x1 + 0.1, 9);
|
||||
expect(g.kind).toBe("DOUBLE_PANEL_VERTICAL");
|
||||
// Ohne Typ: nichts vom Typ, zwei Scheiben, eine Flügel.
|
||||
const p = fillParams(proj({}), wall, win(), cut(win()), host);
|
||||
expect(p).toMatchObject({ frameDepth: undefined, frameWidth: undefined, insetOutside: true, wingCount: 1, panes: 2, sashes: [] });
|
||||
});
|
||||
it("ohne Typ: Standardmasse, zweifach, Flügelzahl der Öffnung", () => {
|
||||
const o = win({ wingCount: 2 });
|
||||
const g = fillGeometry(proj({}), wall, o, cut(o), host);
|
||||
const glass = g.parts.filter((p) => p.role === 2);
|
||||
expect(glass.length).toBe(2);
|
||||
const b = bbox(glass[0].pts);
|
||||
expect(b.y1 - b.y0).toBeCloseTo(0.024, 9);
|
||||
});
|
||||
it("alle Teile liegen innerhalb der Öffnung und der Wand", () => {
|
||||
const o = win({ typeId: "wt", wingCount: 2 });
|
||||
const g = fillGeometry(proj({ windowTypes: [wt()] }), wall, o, cut(o), host);
|
||||
for (const p of g.parts) {
|
||||
const b = bbox(p.pts);
|
||||
expect(b.x0).toBeGreaterThanOrEqual(1 - 1e-9);
|
||||
expect(b.x1).toBeLessThanOrEqual(2.2 + 1e-9);
|
||||
expect(b.y0).toBeGreaterThanOrEqual(-0.2 - 1e-9);
|
||||
expect(b.y1).toBeLessThanOrEqual(0.2 + 1e-9);
|
||||
expect(p.zRel).toBeGreaterThanOrEqual(-1e-9);
|
||||
expect(p.zRel + p.depth).toBeLessThanOrEqual(1.2 + 1e-9);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("fillGeometry — Tür", () => {
|
||||
it("Zarge (3 Teile) + Blatt, Blatt 4 cm mittig, Höhe bis unter den Sturz", () => {
|
||||
const o = door({ typeId: "dt" });
|
||||
const g = fillGeometry(proj({ doorTypes: [dtp()] }), wall, o, cut(o), host);
|
||||
expect(g.parts.filter((p) => p.role === 0).length).toBe(3);
|
||||
const leaf = g.parts.filter((p) => p.role === 1);
|
||||
expect(leaf.length).toBe(1);
|
||||
const lb = bbox(leaf[0].pts);
|
||||
expect(lb.y1 - lb.y0).toBeCloseTo(DOOR_LEAF_THICK, 9);
|
||||
expect(lb.x1 - lb.x0).toBeCloseTo(1 - 2 * DEFAULT_FRAME_WIDTH, 9);
|
||||
expect(leaf[0].zRel).toBe(0);
|
||||
expect(leaf[0].depth).toBeCloseTo(2.1 - DEFAULT_FRAME_WIDTH, 9);
|
||||
expect(g.parts.some((p) => p.role === 2)).toBe(false);
|
||||
});
|
||||
it("zweiflügelig: zwei Blätter, DOUBLE_DOOR_SINGLE_SWING", () => {
|
||||
const o = door({ typeId: "dt" });
|
||||
const g = fillGeometry(proj({ doorTypes: [dtp({ leafCount: 2 })] }), wall, o, cut(o), host);
|
||||
expect(g.parts.filter((p) => p.role === 1).length).toBe(2);
|
||||
expect(g.kind).toBe("DOUBLE_DOOR_SINGLE_SWING");
|
||||
});
|
||||
it("Glastür: Glasfläche = glazingRatio des Blatts, Blatt als Rahmen darum, ohne Überlappung", () => {
|
||||
const o = door({ typeId: "dt" });
|
||||
const g = fillGeometry(proj({ doorTypes: [dtp({ leafStyle: "glas", glazingRatio: 0.36 })] }), wall, o, cut(o), host);
|
||||
const glass = g.parts.filter((p) => p.role === 2);
|
||||
expect(glass.length).toBe(1);
|
||||
const gb = bbox(glass[0].pts);
|
||||
const leafW = 1 - 2 * DEFAULT_FRAME_WIDTH;
|
||||
const leafH = 2.1 - DEFAULT_FRAME_WIDTH;
|
||||
expect(((gb.x1 - gb.x0) * glass[0].depth) / (leafW * leafH)).toBeCloseTo(0.36, 9);
|
||||
const leaf = g.parts.filter((p) => p.role === 1);
|
||||
expect(leaf.length).toBe(4);
|
||||
// Blatt ohne Glasfläche = volle Blattfläche − Glasfläche, über 4 cm
|
||||
expect(volume(leaf)).toBeCloseTo((leafW * leafH - (gb.x1 - gb.x0) * glass[0].depth) * DOOR_LEAF_THICK, 9);
|
||||
});
|
||||
it("Oberlicht: Riegel + Glasstreifen, Blatt entsprechend kürzer", () => {
|
||||
const o = door({ typeId: "dt" });
|
||||
const g = fillGeometry(proj({ doorTypes: [dtp({ transomHeight: 0.4 })] }), wall, o, cut(o), host);
|
||||
const glass = g.parts.filter((p) => p.role === 2);
|
||||
expect(glass.length).toBe(1);
|
||||
expect(glass[0].depth).toBeCloseTo(0.4, 9);
|
||||
expect(glass[0].zRel + glass[0].depth).toBeCloseTo(2.1 - DEFAULT_FRAME_WIDTH, 9);
|
||||
const leaf = g.parts.find((p) => p.role === 1)!;
|
||||
expect(leaf.zRel + leaf.depth).toBeCloseTo(2.1 - DEFAULT_FRAME_WIDTH - 0.4 - DEFAULT_FRAME_WIDTH, 9);
|
||||
});
|
||||
it("reine Wandöffnung (Typ oder Inline): kein Körper, keine Ausführung", () => {
|
||||
const o = door({ typeId: "dt" });
|
||||
expect(fillGeometry(proj({ doorTypes: [dtp({ kind: "wandoeffnung" })] }), wall, o, cut(o), host)).toMatchObject({ kind: null, parts: [] });
|
||||
const o2 = door({ doorType: "wandoeffnung" });
|
||||
expect(fillGeometry(proj({}), wall, o2, cut(o2), host)).toMatchObject({ kind: null, parts: [] });
|
||||
});
|
||||
it("Scharnierseite und Aufschlag → LEFT/RIGHT (von der Aufschlagseite gesehen), Schiebetür", () => {
|
||||
// Wand entlang +X, linke Normale +Y. Standard: Aufschlag nach +Y, Scharnier am Anfang (x klein):
|
||||
// von +Y nach −Y gesehen liegt x klein rechts → RIGHT.
|
||||
const kind = (o: Opening, t: DoorType = dtp()) => fillGeometry(proj({ doorTypes: [t] }), wall, o, cut(o), host).kind;
|
||||
expect(kind(door({ typeId: "dt" }))).toBe("SINGLE_SWING_RIGHT");
|
||||
expect(kind(door({ typeId: "dt", hinge: "end" }))).toBe("SINGLE_SWING_LEFT");
|
||||
// Aufschlag nach aussen (−Y): Blickrichtung dreht → Seiten tauschen.
|
||||
expect(kind(door({ typeId: "dt", openingDir: "out" }))).toBe("SINGLE_SWING_LEFT");
|
||||
expect(kind(door({ typeId: "dt", swing: "right" }))).toBe("SINGLE_SWING_LEFT");
|
||||
expect(kind(door({ typeId: "dt" }), dtp({ kind: "schiebe" }))).toBe("SLIDING_TO_RIGHT");
|
||||
expect(kind(door({ typeId: "dt" }), dtp({ kind: "schiebe", leafCount: 2 }))).toBe("DOUBLE_DOOR_SLIDING");
|
||||
});
|
||||
it("Füllungssystem: Y = Aufschlagrichtung, Ursprung = Öffnungsmitte auf der Achse", () => {
|
||||
const o = door({ typeId: "dt" });
|
||||
const g = fillGeometry(proj({ doorTypes: [dtp()] }), wall, o, cut(o), host);
|
||||
expect(g.origin).toEqual({ x: 1.5, y: 0 });
|
||||
expect(g.u.x).toBeCloseTo(1, 12); // Aufschlag +Y → X = (swing.y, −swing.x) = (1, 0)
|
||||
expect(g.u.y).toBeCloseTo(0, 12);
|
||||
const out = fillGeometry(proj({ doorTypes: [dtp()] }), wall, door({ typeId: "dt", openingDir: "out" }), cut(o), host);
|
||||
expect(out.u.x).toBeCloseTo(-1, 12);
|
||||
it("Tür: Art, Blätter, Aufschlag, Scharnier, Oberlicht, Glas", () => {
|
||||
const o = door({ typeId: "dt", hinge: "end", swing: "right", openingDir: "out" });
|
||||
const t = dtp({ kind: "schiebe", leafCount: 2, transomHeight: 0.4, leafStyle: "glas", glazingRatio: 0.36 });
|
||||
expect(fillParams(proj({ doorTypes: [t] }), wall, o, cut(o), host)).toMatchObject({
|
||||
doorKind: 1,
|
||||
leafCount: 2,
|
||||
swingSign: -1,
|
||||
dirSign: -1,
|
||||
hingeAtStart: false,
|
||||
transomHeight: 0.4,
|
||||
glazed: true,
|
||||
glazingRatio: 0.36,
|
||||
});
|
||||
const plain = fillParams(proj({}), wall, door(), cut(door()), host);
|
||||
expect(plain).toMatchObject({ doorKind: 0, leafCount: 1, swingSign: 1, dirSign: 1, hingeAtStart: true, transomHeight: 0, glazed: false });
|
||||
expect(fillParams(proj({}), wall, door({ doorType: "wandoeffnung" }), cut(door()), host).doorKind).toBe(2);
|
||||
expect(fillParams(proj({ doorTypes: [dtp({ kind: "wandoeffnung" })] }), wall, door({ typeId: "dt" }), cut(door()), host).doorKind).toBe(2);
|
||||
});
|
||||
});
|
||||
+69
-238
@@ -1,260 +1,91 @@
|
||||
// Geometrie der Türen und Fenster für den IFC-Export ([B5], 28.10.): statt einer Box getrennte Körper im
|
||||
// selben Bauteil — Rahmen/Zarge, Türblatt bzw. Glas — plus OperationType (Tür) und PartitioningType
|
||||
// (Fenster). Alles sind vertikale Extrusionen von Grundriss-Rechtecken (wie die Wände), Profile in
|
||||
// Welt-XY, Höhen ab Öffnungs-Unterkante; Rust (`ifc_export.rs`) rechnet sie ins Füllungssystem.
|
||||
//
|
||||
// Masse kommen aus dem Modell, soweit es sie hergibt (Rahmenbreite/-tiefe, Schichteinzug, Flügelzahl und
|
||||
// -tabelle, Verglasung, Blattzahl, Glasanteil, Oberlicht). Fehlendes füllen dieselben Konstanten wie das
|
||||
// 3D (`src-tauri/core/src/openings3d.rs`), damit IFC und Ansicht dasselbe zeigen:
|
||||
// - Rahmenbreite 6 cm (`DEFAULT_FRAME_WIDTH`), Rahmentiefe 7 cm (`DEFAULT_FRAME_DEPTH`: reale Rahmen
|
||||
// sind 70–90 mm tief, nicht so dick wie die Wand), Türblatt 4 cm (`DOOR_LEAF_THICK`).
|
||||
// - Glaspaket: nur im IFC nötig, das 3D zeichnet Einzelscheiben. 1 Scheibe 6 mm, 2 Scheiben 24 mm
|
||||
// (4-16-4, übliches Isolierglas), 3 Scheiben 36 mm (4-12-4-12-4 ≈ 36 mm).
|
||||
// Nicht abgebildet (bewusst einfach): Sprossen, Fensterbank/Rollladenkasten, Schwelle, Flügelrahmen im
|
||||
// Blendrahmen, Kassettenfelder, Schiebe-Laufschiene — die Körper stehen im geschlossenen Zustand.
|
||||
// Türen und Fenster im IFC-Export ([B5]): sammelt die Parameter einer Füllung aus dem Modell (Typ und
|
||||
// Öffnung) für den Rust-Schreiber. Körper (Rahmen/Zarge, Türblatt, Glas), Füllungs-Placement und
|
||||
// OperationType/PartitioningType rechnet `src-tauri/fileio/src/ifc_openings.rs` (Port der früheren
|
||||
// TS-Rechnung, 28.10.; Kodierung FILL im Kopf von `ifc_export.rs`). Fehlende Typwerte bleiben `undefined`,
|
||||
// die Standardmasse (Rahmen 6 × 7 cm, Blatt 4 cm, Glaspakete) kennt nur Rust.
|
||||
|
||||
import type { Opening, Project, SashDef, Vec2, Wall } from "../model/types";
|
||||
import type { Opening, Project, Vec2, Wall } from "../model/types";
|
||||
import { getDoorType, getWindowType, glazingPanesOf } from "../model/types";
|
||||
|
||||
/** Rolle eines Körpers: 0 Rahmen/Zarge, 1 Türblatt, 2 Glas (Kodierung `ifc_export.rs`). */
|
||||
export type FillRole = 0 | 1 | 2;
|
||||
|
||||
export interface FillPart {
|
||||
role: FillRole;
|
||||
/** Profil in Welt-XY (Rechteck, gegen den Uhrzeigersinn in Achs-/Normalenrichtung). */
|
||||
pts: Vec2[];
|
||||
/** Unterkante ab Öffnungs-Unterkante (m). */
|
||||
zRel: number;
|
||||
/** Höhe des Körpers (m). */
|
||||
depth: number;
|
||||
/** Ein Eintrag der Flügeltabelle, wie im Modell (`SashDef`). */
|
||||
export interface FillSash {
|
||||
post: boolean;
|
||||
postWidth?: number;
|
||||
fixed: boolean;
|
||||
width?: number;
|
||||
}
|
||||
|
||||
export interface FillGeometry {
|
||||
/** Ursprung des Füllungssystems (Welt-XY): Öffnungsmitte auf der Wandachse. */
|
||||
origin: Vec2;
|
||||
/** X-Richtung des Füllungssystems (Einheitsvektor); Y = linke Normale davon. */
|
||||
u: Vec2;
|
||||
/** IfcDoorTypeOperationEnum bzw. IfcWindowTypePartitioningEnum; null = Modell gibt nichts her. */
|
||||
kind: string | null;
|
||||
parts: FillPart[];
|
||||
}
|
||||
|
||||
export const DEFAULT_FRAME_WIDTH = 0.06;
|
||||
export const DEFAULT_FRAME_DEPTH = 0.07;
|
||||
export const DOOR_LEAF_THICK = 0.04;
|
||||
/** Glaspaket-Dicke je Scheibenzahl (1, 2, 3). */
|
||||
export const GLASS_PACKAGE_THICKNESS = [0.006, 0.024, 0.036] as const;
|
||||
/** Glasanteil des Türblatts, wenn der Typ keinen angibt (`glas` ohne `glazingRatio`). */
|
||||
const DEFAULT_GLAZING_RATIO = 0.5;
|
||||
/** Kleinste Teilabmessung, damit nie ein flaches Profil entsteht (Meter). */
|
||||
const MIN_DIM = 0.005;
|
||||
|
||||
const sub = (a: Vec2, b: Vec2): Vec2 => ({ x: a.x - b.x, y: a.y - b.y });
|
||||
const norm = (v: Vec2): Vec2 => {
|
||||
const len = Math.hypot(v.x, v.y) || 1;
|
||||
return { x: v.x / len, y: v.y / len };
|
||||
};
|
||||
const leftOf = (u: Vec2): Vec2 => ({ x: -u.y, y: u.x });
|
||||
const dotv = (a: Vec2, b: Vec2): number => a.x * b.x + a.y * b.y;
|
||||
|
||||
/** Flügeleinteilung eines Fensters, auf die Achsbreite aufgelöst: (von, bis, Pfosten?) ab Laibungsanfang. */
|
||||
interface SashSpan {
|
||||
/** Parameter einer Füllung (Reihenfolge der Kodierung: `FlatIfc.opening` in `exportIfc.ts`). */
|
||||
export interface FillParams {
|
||||
wallStart: Vec2;
|
||||
wallEnd: Vec2;
|
||||
/** Achs-Intervall (Abstand ab `wall.start`) und absolute Höhen der Öffnung. */
|
||||
from: number;
|
||||
to: number;
|
||||
post: boolean;
|
||||
zBottom: number;
|
||||
zTop: number;
|
||||
/** Querausdehnung der ganzen Wand entlang der linken Normalen ab `wall.start` (`nLo` = Aussenseite). */
|
||||
nLo: number;
|
||||
nHi: number;
|
||||
frameDepth?: number;
|
||||
inset?: number;
|
||||
insetOutside: boolean;
|
||||
frameWidth?: number;
|
||||
/** Fenster: Flügelzahl, Scheiben (1–3), Flügeltabelle. */
|
||||
wingCount: number;
|
||||
panes: number;
|
||||
sashes: FillSash[];
|
||||
/** Tür: 0 Dreh, 1 Schiebe, 2 reine Wandöffnung. */
|
||||
doorKind: 0 | 1 | 2;
|
||||
leafCount: number;
|
||||
/** +1 Aufschlag links der Achse, −1 rechts; Richtung +1 innen, −1 aussen. */
|
||||
swingSign: 1 | -1;
|
||||
dirSign: 1 | -1;
|
||||
hingeAtStart: boolean;
|
||||
transomHeight: number;
|
||||
glazed: boolean;
|
||||
glazingRatio?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Löst Flügel (`fluegel`) und Pfosten (`pfosten`) zu Intervallen auf: Pfosten und Flügel mit fester Breite
|
||||
* behalten sie, die übrigen teilen den Rest gleichmässig (gleiche Regel wie `sashSegments` im 2D). Ohne
|
||||
* Tabelle: `wingCount` gleiche Flügel.
|
||||
* Parameter der Füllung einer Öffnung. `c` = Achs-Intervall und absolute Höhen der Öffnung, `host` =
|
||||
* Querausdehnung der ganzen Wand (wie im 2D/3D).
|
||||
*/
|
||||
function sashSpans(sashes: readonly SashDef[] | undefined, wingCount: number, total: number): SashSpan[] {
|
||||
const list: readonly SashDef[] =
|
||||
sashes && sashes.length > 0
|
||||
? sashes
|
||||
: Array.from({ length: Math.max(1, Math.round(wingCount)) }, (): SashDef => ({ kind: "fluegel" }));
|
||||
const postW = (s: SashDef): number => Math.max(0, s.postWidth ?? 0.06);
|
||||
const fixedW = (s: SashDef): number | null => (s.kind === "pfosten" ? postW(s) : s.autoWidth === false ? Math.max(0, s.width ?? 0) : null);
|
||||
let fixed = 0;
|
||||
let auto = 0;
|
||||
for (const s of list) {
|
||||
const w = fixedW(s);
|
||||
if (w === null) auto++;
|
||||
else fixed += w;
|
||||
}
|
||||
const autoW = auto > 0 ? Math.max(0, total - fixed) / auto : 0;
|
||||
const out: SashSpan[] = [];
|
||||
let at = 0;
|
||||
for (const s of list) {
|
||||
const w = fixedW(s) ?? autoW;
|
||||
out.push({ from: at, to: at + w, post: s.kind === "pfosten" });
|
||||
at += w;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Körper und Ausführung der Füllung einer Öffnung.
|
||||
*
|
||||
* `c` = Achs-Intervall (`from`/`to`, Abstand ab `wall.start`) und absolute Höhen der Öffnung, `host` =
|
||||
* Querausdehnung der ganzen Wand (`nLo`/`nHi` entlang der linken Normalen ab `wall.start`; `nLo` ist die
|
||||
* Aussenseite, wie im 2D/3D).
|
||||
*/
|
||||
export function fillGeometry(
|
||||
export function fillParams(
|
||||
project: Project,
|
||||
wall: Wall,
|
||||
opening: Opening,
|
||||
c: { from: number; to: number; zBottom: number; zTop: number },
|
||||
host: { nLo: number; nHi: number },
|
||||
): FillGeometry {
|
||||
const u = norm(sub(wall.end, wall.start));
|
||||
const n = leftOf(u);
|
||||
): FillParams {
|
||||
const isDoor = opening.kind === "door";
|
||||
const W = c.to - c.from;
|
||||
const H = c.zTop - c.zBottom;
|
||||
const at = (a: number, b: number): Vec2 => ({
|
||||
x: wall.start.x + u.x * a + n.x * b,
|
||||
y: wall.start.y + u.y * a + n.y * b,
|
||||
});
|
||||
/** Rechteck [a0,a1] entlang der Achse × [b0,b1] quer dazu (Welt-XY). */
|
||||
const rect = (a0: number, a1: number, b0: number, b1: number): Vec2[] => [at(a0, b0), at(a1, b0), at(a1, b1), at(a0, b1)];
|
||||
const center = c.from + W / 2;
|
||||
const origin = at(center, 0);
|
||||
const parts: FillPart[] = [];
|
||||
const add = (role: FillRole, a0: number, a1: number, b0: number, b1: number, z0: number, z1: number): void => {
|
||||
if (a1 - a0 < 1e-6 || b1 - b0 < 1e-6 || z1 - z0 < 1e-6) return;
|
||||
parts.push({ role, pts: rect(a0, a1, b0, b1), zRel: z0, depth: z1 - z0 });
|
||||
};
|
||||
|
||||
const dt = isDoor ? getDoorType(project, opening) : undefined;
|
||||
const wt = isDoor ? undefined : getWindowType(project, opening);
|
||||
const t = dt ?? wt;
|
||||
|
||||
// Querlage des Rahmens: Tiefe (Typ oder 7 cm), Schichteinzug von der gewählten Wandfläche, auf die
|
||||
// Wanddicke geklemmt — dieselbe Rechnung wie `windowSymbol` (2D) und `resolveFrameNormalRange` (3D).
|
||||
const total = host.nHi - host.nLo;
|
||||
const frameDepth = Math.min(total, t?.frameDepth && t.frameDepth > 1e-9 ? t.frameDepth : DEFAULT_FRAME_DEPTH);
|
||||
const inset = Math.max(0, t?.insetFromFace ?? 0);
|
||||
const outside = (t?.insetFace ?? "aussen") === "aussen";
|
||||
const front = outside ? host.nLo + inset : host.nHi - inset;
|
||||
const back = outside ? front + frameDepth : front - frameDepth;
|
||||
let b0 = Math.max(host.nLo, Math.min(host.nHi, Math.min(front, back)));
|
||||
let b1 = Math.max(host.nLo, Math.min(host.nHi, Math.max(front, back)));
|
||||
if (b1 - b0 < MIN_DIM) {
|
||||
b0 = host.nLo;
|
||||
b1 = host.nHi;
|
||||
}
|
||||
const bMid = (b0 + b1) / 2;
|
||||
|
||||
// Sichtbare Rahmenbreite: höchstens ein Viertel der kleineren Öffnungsabmessung, sonst bliebe nichts offen.
|
||||
const fw = Math.max(MIN_DIM, Math.min(t?.frameWidth && t.frameWidth > 1e-9 ? t.frameWidth : DEFAULT_FRAME_WIDTH, Math.min(W, H) / 4));
|
||||
const aIn0 = c.from + fw;
|
||||
const aIn1 = c.to - fw;
|
||||
|
||||
if (!isDoor) {
|
||||
// ── Fenster: Blendrahmen (Pfosten links/rechts, Sturz, Sohlbank), Mittelpfosten, Glas je Flügel ──
|
||||
const wing = opening.wingCount ?? wt?.wingCount ?? 1;
|
||||
add(0, c.from, aIn0, b0, b1, 0, H);
|
||||
add(0, aIn1, c.to, b0, b1, 0, H);
|
||||
add(0, aIn0, aIn1, b0, b1, H - fw, H);
|
||||
add(0, aIn0, aIn1, b0, b1, 0, fw);
|
||||
const panes = wt ? glazingPanesOf(wt) : 2;
|
||||
const gt = Math.min(GLASS_PACKAGE_THICKNESS[panes - 1], b1 - b0);
|
||||
const g0 = bMid - gt / 2;
|
||||
const g1 = bMid + gt / 2;
|
||||
const spans = sashSpans(wt?.sashes, wing, aIn1 - aIn0);
|
||||
let glassCount = 0;
|
||||
spans.forEach((s, i) => {
|
||||
const x0 = aIn0 + s.from;
|
||||
const x1 = aIn0 + s.to;
|
||||
if (s.post) {
|
||||
add(0, x0, x1, b0, b1, fw, H - fw);
|
||||
return;
|
||||
}
|
||||
// Zwischen zwei Flügeln ohne Pfosten steht ein Mittelpfosten (Breite = Rahmenbreite) auf der Grenze.
|
||||
const prev = spans[i - 1];
|
||||
const next = spans[i + 1];
|
||||
const gx0 = i === 0 || prev.post ? x0 : x0 + fw / 2;
|
||||
const gx1 = i === spans.length - 1 || next.post ? x1 : x1 - fw / 2;
|
||||
if (next && !next.post) add(0, x1 - fw / 2, x1 + fw / 2, b0, b1, fw, H - fw);
|
||||
add(2, gx0, gx1, g0, g1, fw, H - fw);
|
||||
glassCount++;
|
||||
});
|
||||
// Teilung nach IFC: nur die senkrechten Standardfälle sind benannt (sonst NOTDEFINED, das Modell
|
||||
// kennt Sprossen und Seitenverhältnisse, die IFC nicht als Enum führt).
|
||||
const kind = glassCount === 1 ? "SINGLE_PANEL" : glassCount === 2 ? "DOUBLE_PANEL_VERTICAL" : glassCount === 3 ? "TRIPLE_PANEL_VERTICAL" : "NOTDEFINED";
|
||||
return { origin, u, kind, parts };
|
||||
}
|
||||
|
||||
// ── Tür ──
|
||||
const kind = dt?.kind ?? (opening.doorType === "wandoeffnung" ? "wandoeffnung" : "dreh");
|
||||
const leafCount = dt?.leafCount ?? 1;
|
||||
// Aufschlagrichtung wie `doorSymbol`: linke Achsnormale, `openingDir: "out"` spiegelt sie.
|
||||
const swingSign = (opening.swing ?? "left") === "left" ? 1 : -1;
|
||||
const dirSign = (opening.openingDir ?? "in") === "in" ? 1 : -1;
|
||||
const swingDir: Vec2 = { x: n.x * swingSign * dirSign, y: n.y * swingSign * dirSign };
|
||||
// Füllungssystem der Tür: Y = Aufschlagrichtung (IFC: die Tür schlägt nach +Y auf), X = Y × Z.
|
||||
const doorU: Vec2 = { x: swingDir.y, y: -swingDir.x };
|
||||
if (kind === "wandoeffnung") return { origin, u: doorU, kind: null, parts: [] };
|
||||
|
||||
// Zarge: Pfosten links/rechts über die ganze Höhe und Sturz (keine Schwelle).
|
||||
add(0, c.from, aIn0, b0, b1, 0, H);
|
||||
add(0, aIn1, c.to, b0, b1, 0, H);
|
||||
add(0, aIn0, aIn1, b0, b1, H - fw, H);
|
||||
|
||||
// Oberlicht: fester Glasstreifen über einem Kämpfer (Riegel in Rahmenbreite) innerhalb der Öffnungshöhe.
|
||||
const th = dt?.transomHeight ?? 0;
|
||||
const hasTransom = th > MIN_DIM && th < H - fw - 0.5;
|
||||
const leafTop = hasTransom ? H - fw - th - fw : H - fw;
|
||||
if (hasTransom) {
|
||||
add(0, aIn0, aIn1, b0, b1, leafTop, leafTop + fw);
|
||||
const gt = Math.min(GLASS_PACKAGE_THICKNESS[1], b1 - b0);
|
||||
add(2, aIn0, aIn1, bMid - gt / 2, bMid + gt / 2, leafTop + fw, H - fw);
|
||||
}
|
||||
|
||||
// Türblatt/-blätter im lichten Mass der Zarge, mittig in der Rahmentiefe.
|
||||
const lt = Math.min(DOOR_LEAF_THICK, b1 - b0);
|
||||
const l0 = bMid - lt / 2;
|
||||
const l1 = bMid + lt / 2;
|
||||
const leafSpans: [number, number][] =
|
||||
leafCount >= 2
|
||||
? [
|
||||
[aIn0, (aIn0 + aIn1) / 2],
|
||||
[(aIn0 + aIn1) / 2, aIn1],
|
||||
]
|
||||
: [[aIn0, aIn1]];
|
||||
const glazed = dt?.leafStyle === "glas";
|
||||
const ratio = Math.min(0.9, Math.max(0.05, dt?.glazingRatio ?? DEFAULT_GLAZING_RATIO));
|
||||
for (const [x0, x1] of leafSpans) {
|
||||
if (!glazed) {
|
||||
add(1, x0, x1, l0, l1, 0, leafTop);
|
||||
continue;
|
||||
}
|
||||
// Glastür: Glasfläche = `glazingRatio` des Blatts (gleichmässig verkleinert um die Blattmitte), das
|
||||
// Blatt als umlaufender Rahmen darum; das Glas füllt die Blattdicke zu 60 % (4–24 mm, mittig).
|
||||
const s = Math.sqrt(ratio);
|
||||
const cx = (x0 + x1) / 2;
|
||||
const cz = leafTop / 2;
|
||||
const gw = (x1 - x0) * s;
|
||||
const gh = leafTop * s;
|
||||
const [px0, px1, pz0, pz1] = [cx - gw / 2, cx + gw / 2, cz - gh / 2, cz + gh / 2];
|
||||
add(1, x0, x1, l0, l1, 0, pz0);
|
||||
add(1, x0, x1, l0, l1, pz1, leafTop);
|
||||
add(1, x0, px0, l0, l1, pz0, pz1);
|
||||
add(1, px1, x1, l0, l1, pz0, pz1);
|
||||
const gt = Math.min(GLASS_PACKAGE_THICKNESS[1], lt * 0.6);
|
||||
add(2, px0, px1, bMid - gt / 2, bMid + gt / 2, pz0, pz1);
|
||||
}
|
||||
|
||||
// OperationType: Blattzahl und Scharnierseite. IFC blickt von der Aufschlagseite (+Y des Füllungssystems)
|
||||
// auf die Tür; "links" = Scharnier auf der +X-Seite des Systems (X = Y × Z, von +Y aus gesehen links).
|
||||
const hingeAtStart = (opening.hinge ?? "start") === "start";
|
||||
const hingeAxis = hingeAtStart ? c.from : c.to;
|
||||
const hingeLocalX = dotv(sub(at(hingeAxis, 0), origin), doorU);
|
||||
const left = hingeLocalX > 0;
|
||||
let op: string;
|
||||
if (kind === "schiebe") op = leafCount >= 2 ? "DOUBLE_DOOR_SLIDING" : left ? "SLIDING_TO_LEFT" : "SLIDING_TO_RIGHT";
|
||||
else op = leafCount >= 2 ? "DOUBLE_DOOR_SINGLE_SWING" : left ? "SINGLE_SWING_LEFT" : "SINGLE_SWING_RIGHT";
|
||||
return { origin, u: doorU, kind: op, parts };
|
||||
return {
|
||||
wallStart: wall.start,
|
||||
wallEnd: wall.end,
|
||||
from: c.from,
|
||||
to: c.to,
|
||||
zBottom: c.zBottom,
|
||||
zTop: c.zTop,
|
||||
nLo: host.nLo,
|
||||
nHi: host.nHi,
|
||||
frameDepth: t?.frameDepth,
|
||||
inset: t?.insetFromFace,
|
||||
insetOutside: (t?.insetFace ?? "aussen") === "aussen",
|
||||
frameWidth: t?.frameWidth,
|
||||
wingCount: opening.wingCount ?? wt?.wingCount ?? 1,
|
||||
panes: wt ? glazingPanesOf(wt) : 2,
|
||||
sashes: (wt?.sashes ?? []).map((s) => ({ post: s.kind === "pfosten", postWidth: s.postWidth, fixed: s.autoWidth === false, width: s.width })),
|
||||
doorKind: kind === "schiebe" ? 1 : kind === "wandoeffnung" ? 2 : 0,
|
||||
leafCount: dt?.leafCount ?? 1,
|
||||
swingSign: (opening.swing ?? "left") === "left" ? 1 : -1,
|
||||
dirSign: (opening.openingDir ?? "in") === "in" ? 1 : -1,
|
||||
hingeAtStart: (opening.hinge ?? "start") === "start",
|
||||
transomHeight: dt?.transomHeight ?? 0,
|
||||
glazed: dt?.leafStyle === "glas",
|
||||
glazingRatio: dt?.glazingRatio,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user