Merge [B5] IFC-Export: Schema-Option IFC2x3 (Coordination View 2.0) neben IFC4
Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
11 files changed
+933
-78
No files matched your search
@@ -542,6 +542,29 @@ Ganzes nicht WASM-tauglich (rayon, tempfile, SystemTime) — nur einzelne Module
|
||||
ist eine Näherung (Weg zwischen den Tritt-Schwerpunkten + Auftritt, mit Steigung), Wendeltreppe ein Lauf inkl.
|
||||
Mitte, Geländer von L-/Wendeltreppen fehlt wie im 3D, Geländer-Länge = Lauflänge × Seiten; Pfosten nicht
|
||||
als IfcMember; nicht in Revit/ArchiCAD geöffnet.
|
||||
- ✅ Schema-Option IFC4 (Standard) | IFC2x3 (Coordination View 2.0). (28.10.) Viele Fachplaner-Programme (ältere
|
||||
Revit/ArchiCAD, Statik, Energie, Kalkulation) verlangen noch 2x3. Export-Dialog: Auswahl „IFC-Schema“ (nur bei
|
||||
IFC), CLI `ifc --schema 4|2x3` (auch bei `convert`), `IfcExportOptions.schema`. Rust `ifc_export.rs`
|
||||
(`Schema`, META mit Schema + WGS84-Breite/Länge, `FLAT_VERSION` 4): `FILE_SCHEMA(('IFC2X3'))`,
|
||||
`FILE_DESCRIPTION('ViewDefinition [CoordinationView_V2.0]')`; Netze als IfcFacetedBrep (dichtes, aussen
|
||||
orientiertes Netz; IfcClosedShell) bzw. IfcShellBasedSurfaceModel (IfcOpenShell) aus IfcFace/IfcPolyLoop statt
|
||||
IfcTriangulatedFaceSet; IfcWallStandardCase nur für Extrusions-Wände mit IfcMaterialLayerSetUsage (2x3 WR1), sonst
|
||||
IfcWall; IfcDoorStyle/IfcWindowStyle (Ausführung als Attribut, ein Style je Ausführung, Zuordnung über
|
||||
IfcRelDefinesByType) statt OperationType/PartitioningType am Bauteil; kein IfcRoofType in 2x3 → Dachschichten
|
||||
(IfcMaterialLayerSet) direkt am Dach; IfcStyledItem über IfcPresentationStyleAssignment; Georeferenz über
|
||||
IfcSite.RefLatitude/RefLongitude/RefElevation (WGS84 aus dem LV95-Bezug, swisstopo-Näherung) und
|
||||
ePSet_ProjectedCRS/ePSet_MapConversion am IfcProject (statt IfcProjectedCRS/IfcMapConversion). Attributlisten nach
|
||||
IFC2X3_TC1: ohne PredefinedType bei Wand/Stütze/Öffnung, ShapeType bei Dach/Treppe, NumberOfRiser ohne
|
||||
PredefinedType am Lauf, IfcZone ohne LongName (Langname als Beschreibung), IfcMaterial/-Layer/-LayerSet/-Usage,
|
||||
IfcQuantity* ohne Formula, IfcClassification/-Reference ohne Description/Location/Tokens (Source/Edition Pflicht),
|
||||
IfcPerson mit FamilyName. Quantities, Psets, Zonen, Klassifikation und alle GlobalIds wie IFC4. Geprüft: Rust-Tests
|
||||
(`ifc_export.rs`, auch kaputte Puffer), `exportIfc.ifc2x3.test.ts`: ifcopenshell validiert gegen IFC2X3 (0 Befunde,
|
||||
Demo-Haus mit/ohne Klassifikation und Georeferenz, Dach mit Typ, Stützen, Wand mit/ohne Mesh, Umlaute), Volumen
|
||||
und Welt-Bounding-Box je Bauteil gleich der IFC4-Ausgabe (≤ 1e-6), eigener Import liest die 2x3-Datei als Meshes
|
||||
und als Bauteile mit gleichem Ergebnis wie IFC4. Offen: nicht in Revit/ArchiCAD/Solibri geöffnet (die
|
||||
buildingSMART-Konvention für ePSet_* am IfcProject nach bestem Wissen, ohne Gegenprüfung in einer Anwendung); Türen/
|
||||
Fenster ohne IfcDoorLiningProperties/-PanelProperties; kein IfcFaceBasedSurfaceModel-Pfad für CV-2.0-Zertifizierung;
|
||||
Netz-Wände/Dächer als Brep sind grösser als IfcTriangulatedFaceSet (ein Punkt je Ecke, drei Entitäten je Dreieck). · M
|
||||
- Geprüft nur im Linux-Container (vitest + ifcopenshell 0.9: 0 Befunde, Volumen), nicht in
|
||||
Solibri/BIMcollab und nicht in der Tauri-App.
|
||||
- ◐ **[BCF] BCF 2.1/3.0 (BIM Collaboration Format).** (28.10.) Koordinations-Themen mit Solibri, BIMcollab,
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
|
||||
Aufruf: python3 scripts/validate-ifc.py datei.ifc [weitere.ifc …]
|
||||
Exit 0 = alles gültig; sonst werden die Befunde ausgegeben und Exit 1.
|
||||
Braucht `pip install ifcopenshell` (getestet mit 0.8/0.9).
|
||||
Braucht `pip install ifcopenshell` (getestet mit 0.8/0.9). Das Schema (IFC4, IFC2X3 …) liest ifcopenshell aus
|
||||
`FILE_SCHEMA` der Datei; IFC2x3-Exporte werden also gegen IFC2X3_TC1 geprüft.
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// IFC4-Schreiber ([B5], Port von `src/export/exportIfc.ts`): erzeugt aus einer flachen Bauteilliste die
|
||||
// IFC4-/IFC2x3-Schreiber ([B5], Port von `src/export/exportIfc.ts`): erzeugt aus einer flachen Bauteilliste die
|
||||
// STEP-Datei (ISO 10303-21). TS sammelt aus Projekt und Plan (Wand-Bänder, Öffnungen, Dach-Meshes,
|
||||
// Raumflächen, Georeferenz — alles Geometrie, die im TS-Modell lebt) und gibt sie fertig gerechnet
|
||||
// weiter; Rust vergibt die Entitätsnummern und baut die Entitäten, GUIDs, Typen mit Materialschichten,
|
||||
@@ -10,7 +10,8 @@
|
||||
//
|
||||
// [FLAT_VERSION, META, Datensatz, Datensatz, …]
|
||||
// META = project_id, project_name, now (Sekunden, ganzzahlig), iso (Zeitstempel, Text), has_geo (0/1),
|
||||
// ref_elevation (NaN = keine), n_storeys, (id, name, base) × n_storeys
|
||||
// ref_elevation (NaN = keine), ref_lat, ref_lon (WGS84-Grad, NaN = keine; nur IFC2x3),
|
||||
// schema (0 = IFC4, 1 = IFC2x3), n_storeys, (id, name, base) × n_storeys
|
||||
// PTS = n, x0, y0, …, x(n−1), y(n−1) (Profil, offen; Rust schliesst es)
|
||||
// MESH = n_verts, x, y, z, …, n_tris, i0, i1, i2, …, closed (0/1) (Indizes 0-basiert)
|
||||
// TYPEREF = has (0/1); wenn 1: kind (0 Wand, 1 Decke, 2 Dach), type_id, type_name, predefined (Text),
|
||||
@@ -73,6 +74,13 @@
|
||||
// übersprungen, ohne Raum keine Zone). GlobalId aus `zone/<key>`; Psets/Mengen wie bei Bauteilen.
|
||||
// ATTACH = 14, key, PSETS (Psets/Mengen an ein schon geschriebenes Bauteil/Geschoss, Schlüssel wie oben)
|
||||
//
|
||||
// Schema IFC2x3 (Coordination View 2.0, TC1; [B5] 28.10.): gleiche Datensätze, GUIDs, Psets und Mengen, aber
|
||||
// die Entitäten des Schemas — Netze als IfcFacetedBrep (dicht) bzw. IfcShellBasedSurfaceModel (offen) statt
|
||||
// IfcTriangulatedFaceSet, IfcWallStandardCase für Wände mit IfcMaterialLayerSetUsage, IfcDoorStyle/
|
||||
// IfcWindowStyle statt OperationType am Bauteil, Dachschichten direkt am Dach (es gibt keinen IfcRoofType),
|
||||
// Georeferenz als IfcSite.RefLatitude/RefLongitude plus ePSet_ProjectedCRS/ePSet_MapConversion am IfcProject,
|
||||
// IfcPresentationStyleAssignment um die Oberflächenstile, Attributlisten nach IFC2X3_TC1.
|
||||
//
|
||||
// Danach folgen (am Pufferende) Typ-Zuordnungen, Eigenschaftssätze, räumliche Eingliederung und Fuss.
|
||||
//
|
||||
// Fehlerverhalten: ein kaputter Puffer (falsche Version, unbekannter Datensatz, abgeschnitten, Index
|
||||
@@ -87,7 +95,15 @@ use std::collections::HashMap;
|
||||
use crate::ifc_openings::{fill_geometry, DoorKind, FillParams, FillPart, Sash, MAX_SASHES};
|
||||
|
||||
/// Version der flachen Kodierung (erstes Element des Puffers). 3 seit 28.10.: Basismengen (Pset-Arten 3–5), Deckenaussparungen, Treppen mit Läufen.
|
||||
pub const FLAT_VERSION: f64 = 3.0;
|
||||
/// 4 seit 28.10.: Schema-Wahl und Breite/Länge im META.
|
||||
pub const FLAT_VERSION: f64 = 4.0;
|
||||
|
||||
/// IFC-Schema der Ausgabe.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
pub enum Schema {
|
||||
Ifc4,
|
||||
Ifc2x3,
|
||||
}
|
||||
|
||||
pub const REC_WALL_SOLIDS: f64 = 1.0;
|
||||
pub const REC_WALL_MESH: f64 = 2.0;
|
||||
@@ -774,6 +790,7 @@ struct TypeAcc {
|
||||
/// Entitäten-Schreiber mit allem Zustand, den die TS-Fassung in Closures hielt.
|
||||
struct Builder {
|
||||
lines: Vec<String>,
|
||||
schema: Schema,
|
||||
project_id: String,
|
||||
owner_history: usize,
|
||||
context: usize,
|
||||
@@ -801,9 +818,16 @@ struct Builder {
|
||||
column_materials: Vec<(String, String, Vec<usize>)>,
|
||||
/// Bauteil-Schlüssel (wie für die GlobalId, z. B. `wall/<id>`) → Entität; Ziel von Klassifikation/Zone/Attach.
|
||||
elements: HashMap<String, usize>,
|
||||
/// IFC2x3: Türen/Fenster je (Tür?, Ausführung) → Bauteile; am Ende je ein IfcDoorStyle/IfcWindowStyle.
|
||||
fill_styles: Vec<(bool, String, Vec<usize>)>,
|
||||
}
|
||||
|
||||
impl Builder {
|
||||
/// Ausgabe im Schema IFC2x3?
|
||||
fn v2(&self) -> bool {
|
||||
self.schema == Schema::Ifc2x3
|
||||
}
|
||||
|
||||
/// Schreibt eine neue Entity-Zeile und liefert ihre Nummer.
|
||||
fn add(&mut self, ty: &str, params: String) -> usize {
|
||||
let id = self.lines.len() + 1;
|
||||
@@ -942,10 +966,12 @@ impl Builder {
|
||||
"IFCSURFACESTYLERENDERING",
|
||||
format!("#{colour},{},$,$,$,$,$,$,{}", fmt_real(transparency), enum_("NOTDEFINED")),
|
||||
);
|
||||
self.styles[role] = self.add(
|
||||
let style = self.add(
|
||||
"IFCSURFACESTYLE",
|
||||
format!("{},{},{}", ifc_string(name), enum_("BOTH"), refs(&[rendering])),
|
||||
);
|
||||
// IFC2x3: IfcStyledItem.Styles verlangt IfcPresentationStyleAssignment (in IFC4 direkt der Stil).
|
||||
self.styles[role] = if self.v2() { self.add("IFCPRESENTATIONSTYLEASSIGNMENT", refs(&[style])) } else { style };
|
||||
}
|
||||
self.styles[role]
|
||||
}
|
||||
@@ -1013,9 +1039,20 @@ impl Builder {
|
||||
(placement, shape)
|
||||
}
|
||||
|
||||
/// Dreiecks-Mesh als IfcTriangulatedFaceSet + Shape + Placement (Punkte tragen die Geometrie absolut
|
||||
/// im Rahmen der Trägerstruktur).
|
||||
/// Dreiecks-Mesh als IfcTriangulatedFaceSet (IFC2x3: IfcFacetedBrep bzw. IfcShellBasedSurfaceModel) +
|
||||
/// Shape + Placement (Punkte tragen die Geometrie absolut im Rahmen der Trägerstruktur).
|
||||
fn emit_triangulated_product(&mut self, mesh: &Mesh, relative_to: usize) -> (usize, usize) {
|
||||
let (item, rep_type) = if self.v2() { self.emit_face_brep(mesh) } else { (self.emit_face_set(mesh), "Tessellation") };
|
||||
let rep = self.add(
|
||||
"IFCSHAPEREPRESENTATION",
|
||||
format!("#{},{},{},{}", self.context, ifc_string("Body"), ifc_string(rep_type), refs(&[item])),
|
||||
);
|
||||
let shape = self.add("IFCPRODUCTDEFINITIONSHAPE", format!("$,$,{}", refs(&[rep])));
|
||||
let placement = self.emit_placement(0.0, relative_to);
|
||||
(placement, shape)
|
||||
}
|
||||
|
||||
fn emit_face_set(&mut self, mesh: &Mesh) -> usize {
|
||||
let coords: Vec<String> = mesh
|
||||
.positions
|
||||
.chunks_exact(3)
|
||||
@@ -1029,26 +1066,54 @@ impl Builder {
|
||||
.collect();
|
||||
// Closed=.T. nur, wenn TS das Mesh als dichtes, aussen orientiertes Volumen geprüft hat.
|
||||
let closed = if mesh.closed { ".T." } else { "$" };
|
||||
let face_set = self.add("IFCTRIANGULATEDFACESET", format!("#{point_list},$,{closed},({}),$", tris.join(",")));
|
||||
let rep = self.add(
|
||||
"IFCSHAPEREPRESENTATION",
|
||||
format!("#{},{},{},{}", self.context, ifc_string("Body"), ifc_string("Tessellation"), refs(&[face_set])),
|
||||
);
|
||||
let shape = self.add("IFCPRODUCTDEFINITIONSHAPE", format!("$,$,{}", refs(&[rep])));
|
||||
let placement = self.emit_placement(0.0, relative_to);
|
||||
(placement, shape)
|
||||
self.add("IFCTRIANGULATEDFACESET", format!("#{point_list},$,{closed},({}),$", tris.join(",")))
|
||||
}
|
||||
|
||||
/// IfcBuildingElement-Subtyp mit dem üblichen 9-Attribut-Flatten.
|
||||
/// IFC2x3: ein IfcCartesianPoint je Ecke, je Dreieck IfcPolyLoop → IfcFaceOuterBound → IfcFace. Dichtes,
|
||||
/// aussen orientiertes Netz = IfcFacetedBrep über IfcClosedShell, sonst IfcShellBasedSurfaceModel über
|
||||
/// IfcOpenShell. Dreiecke mit doppelter Ecke (ohne Fläche) entfallen. Liefert (Körper, Darstellungsart).
|
||||
fn emit_face_brep(&mut self, mesh: &Mesh) -> (usize, &'static str) {
|
||||
let points: Vec<usize> = mesh
|
||||
.positions
|
||||
.chunks_exact(3)
|
||||
.map(|c| self.add("IFCCARTESIANPOINT", list(&[fmt_real(c[0]), fmt_real(c[1]), fmt_real(c[2])])))
|
||||
.collect();
|
||||
let mut faces = Vec::with_capacity(mesh.indices.len() / 3);
|
||||
for c in mesh.indices.chunks_exact(3) {
|
||||
if c[0] == c[1] || c[1] == c[2] || c[0] == c[2] {
|
||||
continue;
|
||||
}
|
||||
let poly_loop = self.add("IFCPOLYLOOP", refs(&[points[c[0]], points[c[1]], points[c[2]]]));
|
||||
let bound = self.add("IFCFACEOUTERBOUND", format!("#{poly_loop},.T."));
|
||||
faces.push(self.add("IFCFACE", refs(&[bound])));
|
||||
}
|
||||
if mesh.closed {
|
||||
let shell = self.add("IFCCLOSEDSHELL", refs(&faces));
|
||||
(self.add("IFCFACETEDBREP", format!("#{shell}")), "Brep")
|
||||
} else {
|
||||
let shell = self.add("IFCOPENSHELL", refs(&faces));
|
||||
(self.add("IFCSHELLBASEDSURFACEMODEL", refs(&[shell])), "SurfaceModel")
|
||||
}
|
||||
}
|
||||
|
||||
/// Menge (IfcQuantityLength/Area/Volume): IFC4 hat zusätzlich `Formula`.
|
||||
fn emit_quantity(&mut self, ty: &str, name: &str, value: f64) -> usize {
|
||||
let formula = if self.v2() { "" } else { ",$" };
|
||||
self.add(ty, format!("{},$,$,{}{formula}", ifc_string(name), fmt_real(value)))
|
||||
}
|
||||
|
||||
/// IfcBuildingElement-Subtyp mit dem üblichen 9-Attribut-Flatten. Das letzte Attribut ist in IFC4 die
|
||||
/// PredefinedType, in IFC2x3 je Klasse ShapeType/PredefinedType/CompositionType; IfcWall und IfcColumn
|
||||
/// haben es dort nicht.
|
||||
fn emit_building_element(&mut self, ty: &str, guid: String, name: &str, placement: usize, shape: usize, predefined: Option<String>) -> usize {
|
||||
let last = if self.v2() && matches!(ty, "IFCWALL" | "IFCWALLSTANDARDCASE" | "IFCCOLUMN") {
|
||||
String::new()
|
||||
} else {
|
||||
format!(",{}", predefined.as_deref().unwrap_or("$"))
|
||||
};
|
||||
self.add(
|
||||
ty,
|
||||
format!(
|
||||
"{guid},#{},{},$,$,#{placement},#{shape},$,{}",
|
||||
self.owner_history,
|
||||
ifc_string(name),
|
||||
predefined.as_deref().unwrap_or("$")
|
||||
),
|
||||
format!("{guid},#{},{},$,$,#{placement},#{shape},${last}", self.owner_history, ifc_string(name)),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1057,7 +1122,7 @@ impl Builder {
|
||||
if let Some(&id) = self.materials.get(component_id) {
|
||||
return id;
|
||||
}
|
||||
let id = self.add("IFCMATERIAL", format!("{},$,$", ifc_string(component_name)));
|
||||
let id = self.add("IFCMATERIAL", if self.v2() { ifc_string(component_name) } else { format!("{},$,$", ifc_string(component_name)) });
|
||||
self.materials.insert(component_id.to_string(), id);
|
||||
id
|
||||
}
|
||||
@@ -1072,21 +1137,34 @@ impl Builder {
|
||||
for l in &t.layers {
|
||||
let m = self.material_of(&l.component_id, &l.component_name);
|
||||
let thickness = if l.thickness.is_finite() { l.thickness.max(0.0) } else { 0.0 };
|
||||
layer_ids.push(self.add("IFCMATERIALLAYER", format!("#{m},{},$,$,$,$,$", fmt_real(thickness))));
|
||||
let layer = if self.v2() { format!("#{m},{},$", fmt_real(thickness)) } else { format!("#{m},{},$,$,$,$,$", fmt_real(thickness)) };
|
||||
layer_ids.push(self.add("IFCMATERIALLAYER", layer));
|
||||
}
|
||||
// IFC2x3 kennt keinen IfcRoofType: das Dach bekommt nur die Schichten (direkt am Bauteil, s. `build_ifc`).
|
||||
let no_type = self.v2() && t.kind == TypeKind::Roof;
|
||||
let guid = self.gid(&key);
|
||||
let type_id = self.add(
|
||||
t.kind.ifc(),
|
||||
format!("{guid},#{},{},$,$,$,$,$,$,{}", self.owner_history, ifc_string(&t.name), enum_(&t.predefined)),
|
||||
);
|
||||
let type_id = if no_type {
|
||||
0
|
||||
} else {
|
||||
self.add(
|
||||
t.kind.ifc(),
|
||||
format!("{guid},#{},{},$,$,$,$,$,$,{}", self.owner_history, ifc_string(&t.name), enum_(&t.predefined)),
|
||||
)
|
||||
};
|
||||
let mut layer_set = 0;
|
||||
if !layer_ids.is_empty() {
|
||||
let set = self.add("IFCMATERIALLAYERSET", format!("{},{},$", refs(&layer_ids), ifc_string(&t.name)));
|
||||
let rel_guid = self.gid(&format!("{key}/material"));
|
||||
self.add(
|
||||
"IFCRELASSOCIATESMATERIAL",
|
||||
format!("{rel_guid},#{},$,$,{},#{set}", self.owner_history, refs(&[type_id])),
|
||||
);
|
||||
let set = if self.v2() {
|
||||
self.add("IFCMATERIALLAYERSET", format!("{},{}", refs(&layer_ids), ifc_string(&t.name)))
|
||||
} else {
|
||||
self.add("IFCMATERIALLAYERSET", format!("{},{},$", refs(&layer_ids), ifc_string(&t.name)))
|
||||
};
|
||||
if !no_type {
|
||||
let rel_guid = self.gid(&format!("{key}/material"));
|
||||
self.add(
|
||||
"IFCRELASSOCIATESMATERIAL",
|
||||
format!("{rel_guid},#{},$,$,{},#{set}", self.owner_history, refs(&[type_id])),
|
||||
);
|
||||
}
|
||||
layer_set = set;
|
||||
}
|
||||
self.type_index.insert(key.clone(), self.types.len());
|
||||
@@ -1150,7 +1228,20 @@ fn rec_name(code: f64) -> &'static str {
|
||||
}
|
||||
}
|
||||
|
||||
/// Baut aus dem flachen Puffer die STEP-Datei (IFC4). Fehler als Text.
|
||||
/// Winkel in Grad als IfcCompoundPlaneAngleMeasure `(Grad,Minuten,Sekunden,Millionstel)`; alle Glieder tragen das
|
||||
/// Vorzeichen des Winkels. `limit` = Betragsgrenze (90 Breite, 180 Länge), darüber wird geklemmt.
|
||||
fn compound_angle(deg: f64, limit: f64) -> String {
|
||||
let neg = deg < 0.0;
|
||||
// In Millionstel Bogensekunden runden (ganzzahlig), dann zerlegen — so gibt es keine Überträge von 60.
|
||||
let total = (deg.abs().min(limit) * 3600.0 * 1_000_000.0).round() as i64;
|
||||
let micro = total % 1_000_000;
|
||||
let secs = total / 1_000_000;
|
||||
let (d, m, s) = (secs / 3600, (secs / 60) % 60, secs % 60);
|
||||
let sg = if neg { -1 } else { 1 };
|
||||
format!("({},{},{},{})", sg * d, sg * m, sg * s, sg * micro)
|
||||
}
|
||||
|
||||
/// 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() };
|
||||
let version = r.raw()?;
|
||||
@@ -1168,6 +1259,12 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
|
||||
let iso = r.string()?;
|
||||
let has_geo = r.flag()?;
|
||||
let ref_elevation = r.raw()?;
|
||||
let (ref_lat, ref_lon) = (r.raw()?, r.raw()?);
|
||||
let schema = match r.idx()? {
|
||||
0 => Schema::Ifc4,
|
||||
1 => Schema::Ifc2x3,
|
||||
k => return Err(format!("unbekanntes Schema {k} bei {}", r.pos - 1)),
|
||||
};
|
||||
let n_storeys = r.idx()?;
|
||||
let mut storey_defs = Vec::new();
|
||||
for _ in 0..n_storeys {
|
||||
@@ -1179,6 +1276,7 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
|
||||
|
||||
let mut w = Builder {
|
||||
lines: Vec::new(),
|
||||
schema,
|
||||
project_id,
|
||||
owner_history: 0,
|
||||
context: 0,
|
||||
@@ -1200,7 +1298,9 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
|
||||
spaces: Vec::new(),
|
||||
column_materials: Vec::new(),
|
||||
elements: HashMap::new(),
|
||||
fill_styles: Vec::new(),
|
||||
};
|
||||
let v2 = schema == Schema::Ifc2x3;
|
||||
let pname = |dflt: &str| if project_name.is_empty() { dflt.to_string() } else { project_name.clone() };
|
||||
|
||||
// Geteilte Grundgeometrie: Ursprung, Z-Extrusionsrichtung, Identitäts-Placement.
|
||||
@@ -1210,7 +1310,11 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
|
||||
|
||||
// Owner-History (minimal, aber vorhanden — manche Importer verlangen sie).
|
||||
let org = w.add("IFCORGANIZATION", format!("$,{},$,$,$", ifc_string("dossier")));
|
||||
let person = w.add("IFCPERSON", format!("{},$,$,$,$,$,$,$", ifc_string("dossier")));
|
||||
// IFC2x3 verlangt FamilyName oder GivenName (WR1), IFC4 genügt die Kennung.
|
||||
let person = w.add(
|
||||
"IFCPERSON",
|
||||
if v2 { format!("{0},{0},$,$,$,$,$,$", ifc_string("dossier")) } else { format!("{},$,$,$,$,$,$,$", ifc_string("dossier")) },
|
||||
);
|
||||
let person_org = w.add("IFCPERSONANDORGANIZATION", format!("#{person},#{org},$"));
|
||||
let app = w.add(
|
||||
"IFCAPPLICATION",
|
||||
@@ -1239,8 +1343,9 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
|
||||
);
|
||||
|
||||
// Georeferenz: Geometrie liegt schon in LV95-Weltkoordinaten (TS), die Abbildung ist die Identität;
|
||||
// das Koordinatensystem wird trotzdem deklariert (IFC4 IfcProjectedCRS + IfcMapConversion).
|
||||
if has_geo {
|
||||
// das Koordinatensystem wird trotzdem deklariert (IFC4 IfcProjectedCRS + IfcMapConversion; IFC2x3 kennt
|
||||
// beide nicht und bekommt ePSet_ProjectedCRS/ePSet_MapConversion am IfcProject, s. unten).
|
||||
if has_geo && !v2 {
|
||||
let crs = w.add(
|
||||
"IFCPROJECTEDCRS",
|
||||
format!(
|
||||
@@ -1284,11 +1389,17 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
|
||||
);
|
||||
// RefElevation (m ü. M.): rein informativ, die Geometrie wird nicht verschoben.
|
||||
let site_ref_elev = if ref_elevation.is_finite() { fmt_real(ref_elevation) } else { "$".to_string() };
|
||||
// IFC2x3: Breite/Länge des Bezugspunkts (WGS84) als IfcCompoundPlaneAngleMeasure; IFC4 trägt sie im CRS.
|
||||
let (site_lat, site_lon) = if v2 && has_geo && ref_lat.is_finite() && ref_lon.is_finite() {
|
||||
(compound_angle(ref_lat, 90.0), compound_angle(ref_lon, 180.0))
|
||||
} else {
|
||||
("$".to_string(), "$".to_string())
|
||||
};
|
||||
let g = w.gid("site");
|
||||
let site_entity = w.add(
|
||||
"IFCSITE",
|
||||
format!(
|
||||
"{g},#{},{},$,$,#{site_placement},$,$,{},$,$,{site_ref_elev},$,$",
|
||||
"{g},#{},{},$,$,#{site_placement},$,$,{},{site_lat},{site_lon},{site_ref_elev},$,$",
|
||||
w.owner_history,
|
||||
ifc_string("Standort"),
|
||||
enum_("ELEMENT")
|
||||
@@ -1316,6 +1427,38 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
|
||||
format!("{g},#{},$,$,#{site_entity},{}", w.owner_history, refs(&[w.building_entity])),
|
||||
);
|
||||
|
||||
// IFC2x3-Georeferenz (Konvention buildingSMART): Koordinatensystem und Abbildung als Eigenschaftssätze am
|
||||
// IfcProject. Die Geometrie liegt schon in LV95, die Abbildung ist die Identität.
|
||||
if v2 && has_geo {
|
||||
let txt = |name: &str, ty: &str, v: &str| (name.to_string(), format!("{ty}({})", ifc_string(v)));
|
||||
let num = |name: &str, ty: &str, v: f64| (name.to_string(), format!("{ty}({})", fmt_real(v)));
|
||||
let crs = [
|
||||
txt("Name", "IFCLABEL", "EPSG:2056"),
|
||||
txt("Description", "IFCTEXT", "CH1903+ / LV95"),
|
||||
txt("GeodeticDatum", "IFCIDENTIFIER", "CH1903+"),
|
||||
txt("MapProjection", "IFCIDENTIFIER", "Swiss Oblique Mercator"),
|
||||
txt("MapUnit", "IFCLABEL", "METRE"),
|
||||
];
|
||||
let conversion = [
|
||||
num("Eastings", "IFCLENGTHMEASURE", 0.0),
|
||||
num("Northings", "IFCLENGTHMEASURE", 0.0),
|
||||
num("OrthogonalHeight", "IFCLENGTHMEASURE", 0.0),
|
||||
num("XAxisAbscissa", "IFCREAL", 1.0),
|
||||
num("XAxisOrdinate", "IFCREAL", 0.0),
|
||||
num("Scale", "IFCREAL", 1.0),
|
||||
];
|
||||
for (set, props) in [("ePSet_ProjectedCRS", &crs[..]), ("ePSet_MapConversion", &conversion[..])] {
|
||||
let ids: Vec<usize> = props
|
||||
.iter()
|
||||
.map(|(n, v)| w.add("IFCPROPERTYSINGLEVALUE", format!("{},$,{v},$", ifc_string(n))))
|
||||
.collect();
|
||||
let g = w.gid(&format!("project/{set}"));
|
||||
let pset = w.add("IFCPROPERTYSET", format!("{g},#{},{},$,{}", w.owner_history, ifc_string(set), refs(&ids)));
|
||||
let g = w.gid(&format!("project/{set}/rel"));
|
||||
w.add("IFCRELDEFINESBYPROPERTIES", format!("{g},#{},$,$,{},#{pset}", w.owner_history, refs(&[project_entity])));
|
||||
}
|
||||
}
|
||||
|
||||
// Je Geschoss ein IfcBuildingStorey (Elevation = base).
|
||||
let mut storey_entities = Vec::new();
|
||||
for (id, name, base) in storey_defs {
|
||||
@@ -1380,7 +1523,10 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
|
||||
} else {
|
||||
(w.emit_placement(0.0, parent), w.emit_swept_shape(&solids))
|
||||
};
|
||||
let entity = w.finish_typed("IFCWALL", format!("wall/{id}"), &name, &ty, &psets, structure, placement, shape, None, true);
|
||||
// IFC2x3: IfcWallStandardCase verlangt genau eine IfcMaterialLayerSetUsage (WR1) — nur dann.
|
||||
let standard = v2 && has_frame && usage && ty.as_ref().is_some_and(|t| !t.layers.is_empty());
|
||||
let class = if standard { "IFCWALLSTANDARDCASE" } else { "IFCWALL" };
|
||||
let entity = w.finish_typed(class, format!("wall/{id}"), &name, &ty, &psets, structure, placement, shape, None, true);
|
||||
if has_frame && usage {
|
||||
// Schichten des Typs der Wandachse zuordnen: erste Schicht (aussen) liegt bei `offset`
|
||||
// von der Achse, die übrigen folgen in +Y (linke Normale).
|
||||
@@ -1388,7 +1534,7 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
|
||||
if let Some(set) = set {
|
||||
let u = w.add(
|
||||
"IFCMATERIALLAYERSETUSAGE",
|
||||
format!("#{set},{},{},{},$", enum_("AXIS2"), enum_("POSITIVE"), fmt_real(offset)),
|
||||
format!("#{set},{},{},{}{}", enum_("AXIS2"), enum_("POSITIVE"), fmt_real(offset), if v2 { "" } else { ",$" }),
|
||||
);
|
||||
let g = w.gid(&format!("wall/{id}/material"));
|
||||
w.add(
|
||||
@@ -1458,10 +1604,10 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
|
||||
let opening_entity = w.add(
|
||||
"IFCOPENINGELEMENT",
|
||||
format!(
|
||||
"{g},#{},{},$,$,#{opening_placement},#{opening_shape},$,{}",
|
||||
"{g},#{},{},$,$,#{opening_placement},#{opening_shape},${}",
|
||||
w.owner_history,
|
||||
ifc_string(if is_door { "Türöffnung" } else { "Fensteröffnung" }),
|
||||
enum_("OPENING")
|
||||
if v2 { String::new() } else { format!(",{}", enum_("OPENING")) }
|
||||
),
|
||||
);
|
||||
let g = w.gid(&format!("voids/{opening_id}"));
|
||||
@@ -1475,17 +1621,27 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
|
||||
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.map(enum_).unwrap_or_else(|| "$".to_string());
|
||||
// IFC4: PredefinedType, OperationType/PartitioningType, UserDefined… am Bauteil; IFC2x3 hat nur
|
||||
// Höhe und Breite — die Ausführung steht im IfcDoorStyle/IfcWindowStyle (`fill_styles`).
|
||||
let tail = if v2 { String::new() } else { format!(",{},{operation},$", enum_(if is_door { "DOOR" } else { "WINDOW" })) };
|
||||
let fill_entity = w.add(
|
||||
if is_door { "IFCDOOR" } else { "IFCWINDOW" },
|
||||
format!(
|
||||
"{g},#{},{},$,$,#{fill_placement},{fill_shape},$,{},{},{},{operation},$",
|
||||
"{g},#{},{},$,$,#{fill_placement},{fill_shape},$,{},{}{tail}",
|
||||
w.owner_history,
|
||||
ifc_string(&fill_name),
|
||||
fmt_real(depth),
|
||||
fmt_real(width),
|
||||
enum_(if is_door { "DOOR" } else { "WINDOW" })
|
||||
fmt_real(width)
|
||||
),
|
||||
);
|
||||
if v2 {
|
||||
let op = kind.unwrap_or("NOTDEFINED").to_string();
|
||||
if let Some((_, _, v)) = w.fill_styles.iter_mut().find(|(d, o, _)| *d == is_door && *o == op) {
|
||||
v.push(fill_entity);
|
||||
} else {
|
||||
w.fill_styles.push((is_door, op, vec![fill_entity]));
|
||||
}
|
||||
}
|
||||
let g = w.gid(&format!("fills/{opening_id}"));
|
||||
w.add(
|
||||
"IFCRELFILLSELEMENT",
|
||||
@@ -1537,17 +1693,18 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
|
||||
};
|
||||
let fkey = format!("{key}/flight/{k}");
|
||||
let guid = w.gid(&fkey);
|
||||
// IFC2x3: NumberOfRiser, keine PredefinedType.
|
||||
let flight_type = if v2 { String::new() } else { format!(",{}", enum_(&f.predefined)) };
|
||||
let flight = w.add(
|
||||
"IFCSTAIRFLIGHT",
|
||||
format!(
|
||||
"{guid},#{},{},$,$,#{placement},#{shape},$,{},{},{},{},{}",
|
||||
"{guid},#{},{},$,$,#{placement},#{shape},$,{},{},{},{}{flight_type}",
|
||||
w.owner_history,
|
||||
ifc_string(&f.name),
|
||||
f.risers,
|
||||
f.treads,
|
||||
fmt_real(f.riser_height),
|
||||
fmt_real(f.tread_length),
|
||||
enum_(&f.predefined)
|
||||
fmt_real(f.tread_length)
|
||||
),
|
||||
);
|
||||
for p in &f.psets {
|
||||
@@ -1628,9 +1785,9 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
|
||||
} else {
|
||||
w.spaces.push((structure, vec![space]));
|
||||
}
|
||||
let q_net = w.add("IFCQUANTITYAREA", format!("{},$,$,{},$", ifc_string("NetFloorArea"), fmt_real(net)));
|
||||
let q_gross = w.add("IFCQUANTITYAREA", format!("{},$,$,{},$", ifc_string("GrossFloorArea"), fmt_real(gross)));
|
||||
let q_height = w.add("IFCQUANTITYLENGTH", format!("{},$,$,{},$", ifc_string("Height"), fmt_real(height)));
|
||||
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 g = w.gid(&format!("space/{id}/qto"));
|
||||
let qto = w.add(
|
||||
"IFCELEMENTQUANTITY",
|
||||
@@ -1748,11 +1905,20 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
|
||||
}
|
||||
if !by_code.is_empty() {
|
||||
let opt = |s: &str| if s.is_empty() { "$".to_string() } else { ifc_string(s) };
|
||||
let system = w.add("IFCCLASSIFICATION", format!("{},{},$,{},$,$,$", opt(&source), opt(&edition), ifc_string(&name)));
|
||||
// IFC2x3: Source und Edition sind Pflicht (leer = ''), keine Description/Location/Tokens.
|
||||
let system = if v2 {
|
||||
w.add("IFCCLASSIFICATION", format!("{},{},$,{}", ifc_string(&source), ifc_string(&edition), ifc_string(&name)))
|
||||
} else {
|
||||
w.add("IFCCLASSIFICATION", format!("{},{},$,{},$,$,$", opt(&source), opt(&edition), ifc_string(&name)))
|
||||
};
|
||||
for (code, ref_name, ids) in by_code {
|
||||
let reference = w.add(
|
||||
"IFCCLASSIFICATIONREFERENCE",
|
||||
format!("$,{},{},#{system},$,$", ifc_string(&code), opt(&ref_name)),
|
||||
if v2 {
|
||||
format!("$,{},{},#{system}", ifc_string(&code), opt(&ref_name))
|
||||
} else {
|
||||
format!("$,{},{},#{system},$,$", ifc_string(&code), opt(&ref_name))
|
||||
},
|
||||
);
|
||||
let g = w.gid(&format!("classification/{name}/{code}"));
|
||||
w.add(
|
||||
@@ -1782,9 +1948,14 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
|
||||
}
|
||||
let zone_key = format!("zone/{key}");
|
||||
let g = w.gid(&zone_key);
|
||||
// IFC2x3: IfcZone hat kein LongName — der lange Name steht dort als Beschreibung.
|
||||
let zone = w.add(
|
||||
"IFCZONE",
|
||||
format!("{g},#{},{},$,$,{}", w.owner_history, ifc_string(&name), ifc_string(&long_name)),
|
||||
if v2 {
|
||||
format!("{g},#{},{},{},$", w.owner_history, ifc_string(&name), ifc_string(&long_name))
|
||||
} else {
|
||||
format!("{g},#{},{},$,$,{}", w.owner_history, ifc_string(&name), ifc_string(&long_name))
|
||||
},
|
||||
);
|
||||
let g = w.gid(&format!("{zone_key}/spaces"));
|
||||
w.add(
|
||||
@@ -1815,6 +1986,17 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
|
||||
if t.occurrences.is_empty() {
|
||||
continue;
|
||||
}
|
||||
if t.type_id == 0 {
|
||||
// IFC2x3 ohne Typ (Dach): Schichten direkt am Bauteil.
|
||||
if t.layer_set != 0 {
|
||||
let g = w.gid(&format!("{}/occurrences/material", t.key));
|
||||
w.add(
|
||||
"IFCRELASSOCIATESMATERIAL",
|
||||
format!("{g},#{},$,$,{},#{}", w.owner_history, refs(&t.occurrences), t.layer_set),
|
||||
);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
let g = w.gid(&format!("{}/occurrences", t.key));
|
||||
w.add(
|
||||
"IFCRELDEFINESBYTYPE",
|
||||
@@ -1822,6 +2004,26 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
|
||||
);
|
||||
}
|
||||
|
||||
// ── IFC2x3: Türen/Fenster mit IfcDoorStyle/IfcWindowStyle (Ausführung als Attribut des Styles) ──
|
||||
let fill_styles = std::mem::take(&mut w.fill_styles);
|
||||
for (is_door, op, occurrences) in &fill_styles {
|
||||
let (class, label) = if *is_door { ("IFCDOORSTYLE", "Tür") } else { ("IFCWINDOWSTYLE", "Fenster") };
|
||||
let key = format!("style/{}/{op}", if *is_door { "door" } else { "window" });
|
||||
let g = w.gid(&key);
|
||||
let name = if op == "NOTDEFINED" { label.to_string() } else { format!("{label} {op}") };
|
||||
// Tür: OperationType, ConstructionType; Fenster: ConstructionType, OperationType (Reihenfolge je Schema).
|
||||
let (first, second) = if *is_door { (enum_(op), enum_("NOTDEFINED")) } else { (enum_("NOTDEFINED"), enum_(op)) };
|
||||
let style = w.add(
|
||||
class,
|
||||
format!("{g},#{},{},$,$,$,$,$,{first},{second},.F.,.F.", w.owner_history, ifc_string(&name)),
|
||||
);
|
||||
let g = w.gid(&format!("{key}/occurrences"));
|
||||
w.add(
|
||||
"IFCRELDEFINESBYTYPE",
|
||||
format!("{g},#{},$,$,{},#{style}", w.owner_history, refs(occurrences)),
|
||||
);
|
||||
}
|
||||
|
||||
// ── Eigenschaftssätze ──
|
||||
let psets = std::mem::take(&mut w.psets);
|
||||
for ps in &psets {
|
||||
@@ -1847,7 +2049,7 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
|
||||
let mut ids = Vec::with_capacity(q.quantities.len());
|
||||
for (ty, name, value) in &q.quantities {
|
||||
// IFC verlangt Mengen ≥ 0.
|
||||
ids.push(w.add(ty, format!("{},$,$,{},$", ifc_string(name), fmt_real(value.max(0.0)))));
|
||||
ids.push(w.emit_quantity(ty, name, value.max(0.0)));
|
||||
}
|
||||
let g = w.gid(&format!("{}/{}", q.owner_key, q.name));
|
||||
let set = w.add("IFCELEMENTQUANTITY", format!("{g},#{},{},$,$,{}", w.owner_history, ifc_string(&q.name), refs(&ids)));
|
||||
@@ -1869,7 +2071,8 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
|
||||
let file_name = format!("{}.ifc", pname("modell"));
|
||||
let mut out = String::with_capacity(w.lines.iter().map(|l| l.len() + 1).sum::<usize>() + 512);
|
||||
out.push_str("ISO-10303-21;\nHEADER;\n");
|
||||
out.push_str(&format!("FILE_DESCRIPTION({},{});\n", list(&[ifc_string("")]), ifc_string("2;1")));
|
||||
let description = if v2 { "ViewDefinition [CoordinationView_V2.0]" } else { "" };
|
||||
out.push_str(&format!("FILE_DESCRIPTION({},{});\n", list(&[ifc_string(description)]), ifc_string("2;1")));
|
||||
out.push_str(&format!(
|
||||
"FILE_NAME({},{},{},{},{},{},{});\n",
|
||||
ifc_string(&file_name),
|
||||
@@ -1880,7 +2083,7 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result<String, String> {
|
||||
ifc_string("dossier"),
|
||||
ifc_string("")
|
||||
));
|
||||
out.push_str("FILE_SCHEMA(('IFC4'));\nENDSEC;\n\nDATA;\n");
|
||||
out.push_str(&format!("FILE_SCHEMA(('{}'));\nENDSEC;\n\nDATA;\n", if v2 { "IFC2X3" } else { "IFC4" }));
|
||||
for l in &w.lines {
|
||||
out.push_str(l);
|
||||
out.push('\n');
|
||||
@@ -1979,10 +2182,20 @@ mod tests {
|
||||
struct B {
|
||||
f: Vec<f64>,
|
||||
s: Vec<String>,
|
||||
/// 0 = IFC4, 1 = IFC2x3 (im META).
|
||||
schema: f64,
|
||||
}
|
||||
impl B {
|
||||
fn new() -> Self {
|
||||
B { f: vec![FLAT_VERSION], s: Vec::new() }
|
||||
B { f: vec![FLAT_VERSION], s: Vec::new(), schema: 0.0 }
|
||||
}
|
||||
fn v2() -> Self {
|
||||
B { schema: 1.0, ..B::new() }
|
||||
}
|
||||
/// META ab `has_geo`: Geo-Flag, Höhe, Breite/Länge (nur mit Geo), Schema, Anzahl Geschosse.
|
||||
fn meta_tail(&mut self, geo: bool, elevation: f64, storeys: f64) {
|
||||
let (lat, lon) = if geo { (47.376_9, 8.541_7) } else { (f64::NAN, f64::NAN) };
|
||||
self.f.extend([if geo { 1.0 } else { 0.0 }, elevation, lat, lon, self.schema, storeys]);
|
||||
}
|
||||
fn s(&mut self, x: &str) -> f64 {
|
||||
self.s.push(x.to_string());
|
||||
@@ -2113,12 +2326,15 @@ mod tests {
|
||||
}
|
||||
|
||||
fn full_house(with_geo: bool) -> B {
|
||||
let mut b = B::new();
|
||||
full_house_in(B::new(), with_geo)
|
||||
}
|
||||
|
||||
fn full_house_in(mut b: B, with_geo: bool) -> B {
|
||||
b.str("t");
|
||||
b.str("Haus Ä");
|
||||
b.n(&[1_700_000_000.0]);
|
||||
b.str("2026-10-28T12:00:00");
|
||||
b.n(&[if with_geo { 1.0 } else { 0.0 }, if with_geo { 421.5 } else { f64::NAN }, 1.0]);
|
||||
b.meta_tail(with_geo, if with_geo { 421.5 } else { f64::NAN }, 1.0);
|
||||
b.str("eg");
|
||||
b.str("Erdgeschoss");
|
||||
b.n(&[0.0]);
|
||||
@@ -2412,12 +2628,15 @@ mod tests {
|
||||
|
||||
/// Kopf (META) eines Mini-Projekts ohne Geschoss.
|
||||
fn mini() -> B {
|
||||
let mut b = B::new();
|
||||
mini_in(B::new())
|
||||
}
|
||||
|
||||
fn mini_in(mut b: B) -> B {
|
||||
b.str("t");
|
||||
b.str("H");
|
||||
b.n(&[1_700_000_000.0]);
|
||||
b.str("2026-10-28T12:00:00");
|
||||
b.n(&[0.0, f64::NAN, 0.0]);
|
||||
b.meta_tail(false, f64::NAN, 0.0);
|
||||
b
|
||||
}
|
||||
|
||||
@@ -2720,6 +2939,178 @@ mod tests {
|
||||
assert!(build(&bad).is_err());
|
||||
}
|
||||
|
||||
fn full_house_2x3(with_geo: bool) -> String {
|
||||
build(&full_house_in(B::v2(), with_geo)).unwrap()
|
||||
}
|
||||
|
||||
/// GlobalId (erster Parameter) der ersten Entität eines Typs.
|
||||
fn guid_of(ifc: &str, ty: &str) -> String {
|
||||
let l = first_line(ifc, ty);
|
||||
l[l.find('(').unwrap() + 2..][..22].to_string()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ifc2x3_kopf_und_entitaeten() {
|
||||
let ifc = full_house_2x3(true);
|
||||
assert!(ifc.contains("FILE_DESCRIPTION(('ViewDefinition [CoordinationView_V2.0]'),'2;1');"));
|
||||
assert!(ifc.contains("FILE_SCHEMA(('IFC2X3'));"));
|
||||
assert!(ifc.is_ascii());
|
||||
check_structure(&ifc);
|
||||
// Nur Entitäten, die es in IFC2x3 gibt.
|
||||
for gone in ["IFCTRIANGULATEDFACESET", "IFCCARTESIANPOINTLIST3D", "IFCROOFTYPE", "IFCMAPCONVERSION", "IFCPROJECTEDCRS"] {
|
||||
assert_eq!(count(&ifc, gone), 0, "{gone}");
|
||||
}
|
||||
// W1 hat Achse + Usage (StandardCase), W2 nicht (IfcWall).
|
||||
assert_eq!(count(&ifc, "IFCWALLSTANDARDCASE"), 1);
|
||||
assert_eq!(count(&ifc, "IFCWALL"), 1);
|
||||
assert_eq!(count(&ifc, "IFCMATERIALLAYERSETUSAGE"), 1);
|
||||
assert!(first_line(&ifc, "IFCMATERIALLAYERSETUSAGE").ends_with(".AXIS2.,.POSITIVE.,-0.2);"));
|
||||
// Wand ohne PredefinedType (8 Attribute), Stütze ebenso.
|
||||
assert!(first_line(&ifc, "IFCWALL").ends_with(",$);") && first_line(&ifc, "IFCWALL").matches(',').count() == 7, "{}", first_line(&ifc, "IFCWALL"));
|
||||
assert!(first_line(&ifc, "IFCCOLUMN").ends_with(",$);"), "{}", first_line(&ifc, "IFCCOLUMN"));
|
||||
// Material-Schicht und -Satz in der kurzen 2x3-Form.
|
||||
assert!(first_line(&ifc, "IFCMATERIAL").ends_with("');") && !first_line(&ifc, "IFCMATERIAL").contains(",$,$"));
|
||||
assert!(first_line(&ifc, "IFCMATERIALLAYER").ends_with(",$);") && first_line(&ifc, "IFCMATERIALLAYER").matches(',').count() == 2);
|
||||
// Tür: nur Höhe und Breite; Ausführung im IfcDoorStyle, verbunden über IfcRelDefinesByType.
|
||||
let door = first_line(&ifc, "IFCDOOR");
|
||||
assert!(door.ends_with(",$,2.1,0.9);"), "{door}");
|
||||
let style = first_line(&ifc, "IFCDOORSTYLE");
|
||||
assert!(style.contains(",$,$,$,$,$,.SINGLE_SWING_LEFT.,.NOTDEFINED.,.F.,.F.);"), "{style}");
|
||||
assert_eq!(count(&ifc, "IFCWINDOWSTYLE"), 0);
|
||||
assert_eq!(count(&ifc, "IFCRELDEFINESBYTYPE"), 2); // Wandtyp + Türstil
|
||||
// Öffnung ohne PredefinedType; Raum, Treppe, Dach in der 2x3-Form.
|
||||
assert!(first_line(&ifc, "IFCOPENINGELEMENT").ends_with(",$);") && !first_line(&ifc, "IFCOPENINGELEMENT").contains(".OPENING."));
|
||||
assert!(first_line(&ifc, "IFCROOF").ends_with(".GABLE_ROOF.);"));
|
||||
assert!(first_line(&ifc, "IFCSTAIR").ends_with(".STRAIGHT_RUN_STAIR.);"));
|
||||
// Dach: Netz als Brep (dicht), Schichten direkt am Dach (kein Typ).
|
||||
assert_eq!(count(&ifc, "IFCFACETEDBREP"), 1);
|
||||
assert_eq!(count(&ifc, "IFCCLOSEDSHELL"), 1);
|
||||
assert_eq!(count(&ifc, "IFCFACE"), 4);
|
||||
assert_eq!(count(&ifc, "IFCPOLYLOOP"), 4);
|
||||
assert!(ifc.contains("'Body','Brep'"));
|
||||
assert_eq!(count(&ifc, "IFCRELASSOCIATESMATERIAL"), 4); // Wandtyp, Usage, Dachschichten, Stütze
|
||||
// Stile der Teilrollen über IfcPresentationStyleAssignment.
|
||||
assert_eq!(count(&ifc, "IFCPRESENTATIONSTYLEASSIGNMENT"), 3);
|
||||
// Mengen ohne Formula.
|
||||
assert!(first_line(&ifc, "IFCQUANTITYAREA").ends_with(",$,$,1.9);"), "{}", first_line(&ifc, "IFCQUANTITYAREA"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ifc2x3_georeferenz_ueber_site_und_epset() {
|
||||
let ifc = full_house_2x3(true);
|
||||
let site = first_line(&ifc, "IFCSITE");
|
||||
assert!(site.contains(".ELEMENT.,(47,22,36,840000),(8,32,30,120000),421.5,$,$);"), "{site}");
|
||||
assert!(ifc.contains("'ePSet_ProjectedCRS'") && ifc.contains("'ePSet_MapConversion'"));
|
||||
assert!(ifc.contains("IFCPROPERTYSINGLEVALUE('Name',$,IFCLABEL('EPSG:2056'),$)"));
|
||||
assert!(ifc.contains("IFCPROPERTYSINGLEVALUE('Scale',$,IFCREAL(1.0),$)"));
|
||||
// Ohne Georeferenz keine Winkel und keine Sätze.
|
||||
let plain = full_house_2x3(false);
|
||||
assert!(first_line(&plain, "IFCSITE").contains(".ELEMENT.,$,$,$,$,$);"));
|
||||
assert!(!plain.contains("ePSet_"));
|
||||
// IFC4 behält CRS + Abbildung und schreibt keine Winkel.
|
||||
let v4 = build(&full_house(true)).unwrap();
|
||||
assert!(first_line(&v4, "IFCSITE").contains(".ELEMENT.,$,$,421.5,$,$);"));
|
||||
assert!(!v4.contains("ePSet_"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn winkel_in_grad_minuten_sekunden() {
|
||||
assert_eq!(compound_angle(47.376_9, 90.0), "(47,22,36,840000)");
|
||||
assert_eq!(compound_angle(-0.5, 90.0), "(0,-30,0,0)");
|
||||
assert_eq!(compound_angle(-47.5, 90.0), "(-47,-30,0,0)");
|
||||
assert_eq!(compound_angle(0.0, 90.0), "(0,0,0,0)");
|
||||
// Kein Überlauf auf 60 Sekunden: 59.9999999° rundet sauber hoch.
|
||||
assert_eq!(compound_angle(10.999_999_999_9, 90.0), "(11,0,0,0)");
|
||||
assert_eq!(compound_angle(1000.0, 90.0), "(90,0,0,0)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ifc2x3_gleiche_guids_wie_ifc4() {
|
||||
let (a, b) = (build(&full_house(true)).unwrap(), full_house_2x3(true));
|
||||
for ty in ["IFCPROJECT", "IFCSITE", "IFCBUILDING", "IFCBUILDINGSTOREY", "IFCSLAB", "IFCSPACE", "IFCROOF", "IFCCOLUMN", "IFCSTAIR", "IFCDOOR", "IFCOPENINGELEMENT", "IFCWALLTYPE", "IFCELEMENTQUANTITY"] {
|
||||
assert_eq!(guid_of(&a, ty), guid_of(&b, ty), "{ty}");
|
||||
}
|
||||
// Wand W1: StandardCase trägt die GlobalId des IfcWall.
|
||||
assert_eq!(guid_of(&b, "IFCWALLSTANDARDCASE"), ifc_guid("t/wall/W1"));
|
||||
assert_eq!(b, full_house_2x3(true));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ifc2x3_offenes_netz_ist_shell_based_surface_model() {
|
||||
let mut b = mini_in(B::v2());
|
||||
b.n(&[REC_ROOF, -1.0]);
|
||||
b.str("R");
|
||||
b.str("Dach");
|
||||
b.str("FLAT_ROOF");
|
||||
b.no_type();
|
||||
b.no_psets();
|
||||
// Zwei Dreiecke (offen) plus ein entartetes (doppelte Ecke).
|
||||
b.n(&[4.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0]);
|
||||
b.n(&[3.0, 0.0, 1.0, 2.0, 0.0, 2.0, 3.0, 0.0, 0.0, 1.0]);
|
||||
b.f.push(0.0);
|
||||
let ifc = build(&b).unwrap();
|
||||
check_structure(&ifc);
|
||||
assert_eq!(count(&ifc, "IFCSHELLBASEDSURFACEMODEL"), 1);
|
||||
assert_eq!(count(&ifc, "IFCOPENSHELL"), 1);
|
||||
assert_eq!(count(&ifc, "IFCFACE"), 2);
|
||||
assert_eq!(count(&ifc, "IFCCARTESIANPOINT"), 6); // Ursprung, 4 Ecken (je einmal), Placement
|
||||
assert!(ifc.contains("'Body','SurfaceModel'"));
|
||||
assert_eq!(count(&ifc, "IFCFACETEDBREP"), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ifc2x3_fenster_stil_klassifikation_zone_treppe() {
|
||||
let mut b = full_house_in(B::v2(), false);
|
||||
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) });
|
||||
b.n(&[REC_ZONE]);
|
||||
b.str("sia416/HNF");
|
||||
b.str("HNF");
|
||||
b.str("Hauptnutzfläche");
|
||||
b.n(&[1.0]);
|
||||
b.str("R1");
|
||||
b.f.push(0.0);
|
||||
b.n(&[REC_CLASSIFICATION]);
|
||||
b.str("eBKP-H");
|
||||
b.str("");
|
||||
b.str("");
|
||||
b.n(&[1.0]);
|
||||
b.str("wall/W1");
|
||||
b.str("C");
|
||||
b.str("Konstruktion");
|
||||
stair_with_parts(&mut b);
|
||||
let ifc = build(&b).unwrap();
|
||||
check_structure(&ifc);
|
||||
let win = first_line(&ifc, "IFCWINDOWSTYLE");
|
||||
assert!(win.contains(",$,$,$,$,$,.NOTDEFINED.,.DOUBLE_PANEL_VERTICAL.,.F.,.F.);"), "{win}");
|
||||
// Wandöffnung: Tür ohne Ausführung → Stil NOTDEFINED; Tür 1 hat eigenen Stil.
|
||||
assert_eq!(count(&ifc, "IFCDOORSTYLE"), 2);
|
||||
assert!(ifc.contains(",.NOTDEFINED.,.NOTDEFINED.,.F.,.F.);"));
|
||||
let hole = ifc.lines().find(|l| l.contains("IFCDOOR(") && l.contains(",$,$,2.1,1.0);"));
|
||||
assert!(hole.is_some());
|
||||
// Klassifikation: Pflichtfelder als '', keine IFC4-Zusatzfelder.
|
||||
assert!(first_line(&ifc, "IFCCLASSIFICATION").ends_with("('','',$,'eBKP-H');") || first_line(&ifc, "IFCCLASSIFICATION").contains("'','',$,'eBKP-H');"), "{}", first_line(&ifc, "IFCCLASSIFICATION"));
|
||||
assert!(first_line(&ifc, "IFCCLASSIFICATIONREFERENCE").contains("$,'C','Konstruktion',#"), "{}", first_line(&ifc, "IFCCLASSIFICATIONREFERENCE"));
|
||||
assert!(!first_line(&ifc, "IFCCLASSIFICATIONREFERENCE").ends_with(",$,$);"));
|
||||
// Zone: Langname als Beschreibung.
|
||||
assert!(first_line(&ifc, "IFCZONE").contains(",'HNF','Hauptnutzfl\\X2\\00E4\\X0\\che',$);"), "{}", first_line(&ifc, "IFCZONE"));
|
||||
// Treppenlauf: NumberOfRiser… ohne PredefinedType.
|
||||
assert!(first_line(&ifc, "IFCSTAIRFLIGHT").ends_with(",7,7,0.1857,0.28);"), "{}", first_line(&ifc, "IFCSTAIRFLIGHT"));
|
||||
assert_eq!(count(&ifc, "IFCTRIANGULATEDFACESET"), 0);
|
||||
assert_eq!(count(&ifc, "IFCFACETEDBREP"), 2); // Dach + Geländer (Mesh dicht? s. mesh_tetra: closed = 1)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unbekanntes_schema_ist_fehler() {
|
||||
let mut b = mini();
|
||||
let n = b.f.len();
|
||||
b.f[n - 2] = 2.0;
|
||||
assert!(build(&b).is_err());
|
||||
b.f[n - 2] = 0.5;
|
||||
assert!(build(&b).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leeres_projekt_ist_gueltig() {
|
||||
let mut b = B::new();
|
||||
@@ -2727,7 +3118,7 @@ mod tests {
|
||||
b.str("");
|
||||
b.n(&[1.0]);
|
||||
b.str("iso");
|
||||
b.n(&[0.0, f64::NAN, 0.0]);
|
||||
b.meta_tail(false, f64::NAN, 0.0);
|
||||
let ifc = build(&b).unwrap();
|
||||
check_structure(&ifc);
|
||||
assert!(ifc.contains("IFCPROJECT('"));
|
||||
@@ -2744,7 +3135,7 @@ mod tests {
|
||||
b.str("x");
|
||||
b.n(&[1.0]);
|
||||
b.str("iso");
|
||||
b.n(&[0.0, f64::NAN, 0.0]);
|
||||
b.meta_tail(false, f64::NAN, 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);
|
||||
@@ -2772,10 +3163,23 @@ mod tests {
|
||||
let _ = build_ifc(&g, &s);
|
||||
}
|
||||
}
|
||||
// Dasselbe im Schema IFC2x3 (eigene Zweige für Netze, Stile, Zonen, Klassifikation).
|
||||
let b = full_house_in(B::v2(), true);
|
||||
let (f, s) = b.data();
|
||||
for n in 0..f.len() {
|
||||
let _ = build_ifc(&f[..n], &s);
|
||||
}
|
||||
for i in 0..f.len() {
|
||||
for bad in [f64::NAN, f64::INFINITY, -1.0, 1e30, 0.5] {
|
||||
let mut g = f.to_vec();
|
||||
g[i] = bad;
|
||||
let _ = build_ifc(&g, &s);
|
||||
}
|
||||
}
|
||||
// Unbekannter Datensatz, Geschoss-Index ausserhalb, Dreiecks-Index ausserhalb.
|
||||
let mut g = vec![FLAT_VERSION, 0.0, 0.0, 1.0, 0.0, 0.0, f64::NAN, 0.0, 99.0];
|
||||
let mut g = vec![FLAT_VERSION, 0.0, 0.0, 1.0, 0.0, 0.0, f64::NAN, f64::NAN, f64::NAN, 0.0, 0.0, 99.0];
|
||||
assert!(build_ifc(&g, "a").is_err());
|
||||
g[8] = REC_STAIR;
|
||||
g[11] = REC_STAIR;
|
||||
g.extend([3.0]);
|
||||
assert!(build_ifc(&g, "a").is_err());
|
||||
let mut m = B::new();
|
||||
@@ -2783,7 +3187,7 @@ mod tests {
|
||||
m.str("x");
|
||||
m.n(&[1.0]);
|
||||
m.str("i");
|
||||
m.n(&[0.0, f64::NAN, 0.0]);
|
||||
m.meta_tail(false, f64::NAN, 0.0);
|
||||
m.n(&[REC_ROOF, -1.0]);
|
||||
m.str("R");
|
||||
m.str("R");
|
||||
|
||||
+33
-2
@@ -1,7 +1,7 @@
|
||||
// dossier-cli (Phase C): importiert nur src/core, und die Befehle laufen headless gegen das
|
||||
// Beispielprojekt (inkl. der echten WASM-Pakete aus src/engine/pkg*).
|
||||
import { describe, expect, it, beforeAll } from "vitest";
|
||||
import { mkdtempSync, readFileSync, writeFileSync, readdirSync, statSync } from "node:fs";
|
||||
import { describe, expect, it, beforeAll, vi } from "vitest";
|
||||
import { existsSync, mkdtempSync, readFileSync, writeFileSync, readdirSync, statSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { run } from "./main";
|
||||
@@ -71,6 +71,37 @@ describe("dossier-cli", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("IFC mit --schema: 4 (Standard) und 2x3 (Coordination View 2.0), anderes ist ein Fehler", async () => {
|
||||
const out = join(dir, "schema.ifc");
|
||||
expect(await call("ifc", "--out", out)).toBe(0);
|
||||
expect(readFileSync(out, "utf8")).toContain("FILE_SCHEMA(('IFC4'));");
|
||||
expect(await call("ifc", "--schema", "4", "--out", out)).toBe(0);
|
||||
expect(readFileSync(out, "utf8")).toContain("FILE_SCHEMA(('IFC4'));");
|
||||
for (const v of ["2x3", "IFC2X3", "ifc2x3"]) {
|
||||
expect(await call("ifc", "--schema", v, "--out", out)).toBe(0);
|
||||
const text = readFileSync(out, "utf8");
|
||||
expect(text).toContain("FILE_SCHEMA(('IFC2X3'));");
|
||||
expect(text).toContain("ViewDefinition [CoordinationView_V2.0]");
|
||||
expect(text).not.toContain("IFCTRIANGULATEDFACESET");
|
||||
}
|
||||
// convert reicht die Option durch.
|
||||
const conv = join(dir, "convert.ifc");
|
||||
expect(await run(["convert", file, conv, "--schema", "2x3"])).toBe(0);
|
||||
expect(readFileSync(conv, "utf8")).toContain("FILE_SCHEMA(('IFC2X3'));");
|
||||
// Unbekanntes Schema: `fail` beendet den Prozess (hier abgefangen) und schreibt keine Datei.
|
||||
const exit = vi.spyOn(process, "exit").mockImplementation((code) => {
|
||||
throw new Error(`exit ${code}`);
|
||||
});
|
||||
const err = vi.spyOn(process.stderr, "write").mockImplementation(() => true);
|
||||
try {
|
||||
await expect(call("ifc", "--schema", "2x4", "--out", join(dir, "nope.ifc"))).rejects.toThrow("exit 1");
|
||||
} finally {
|
||||
exit.mockRestore();
|
||||
err.mockRestore();
|
||||
}
|
||||
expect(existsSync(join(dir, "nope.ifc"))).toBe(false);
|
||||
});
|
||||
|
||||
it("DWG über das Format-WASM (acadrust, R2018)", async () => {
|
||||
const out = join(dir, "eg.dwg");
|
||||
expect(await call("dwg", "--level", "eg", "--out", out)).toBe(0);
|
||||
|
||||
+12
-1
@@ -10,6 +10,7 @@
|
||||
// dossier-cli <projekt.obp> section <Name> [--out schnitt.svg] (braucht render3d-WASM)
|
||||
// dossier-cli <projekt.obp> elevation <Name> [--out ansicht.svg]
|
||||
// dossier-cli <projekt.obp> ifc [--ebkph] [--ebenen] (IFC mit eBKP-H-Hauptgruppen bzw. Modell-Ebenen als Klassifikation)
|
||||
// --schema 4|2x3: IFC4 (Standard) oder IFC2x3 (Coordination View 2.0)
|
||||
// dossier-cli <projekt.obp> dxf [--binary] [--scale 100] [--dim-unit cm] [--layout]|dwg|ifc|step|obj|stl|glb|gltf|schedule|kennzahlen|sun [--level EG] [--out datei]
|
||||
// glb/gltf = glTF 2.0 (Y-up, Meter, Geschoss als Eltern; --flat ohne Geschoss-Knoten)
|
||||
// dossier-cli convert <eingabe> <ausgabe> [--cmd "befehl"]… Format nach Endung: dxf/dwg/ifc/obp → obp-Import,
|
||||
@@ -98,6 +99,16 @@ import { serveStdio } from "./mcp";
|
||||
|
||||
type Args = { positional: string[]; flags: Map<string, string>; cmds: string[] };
|
||||
|
||||
/** `--schema 4|ifc4|2x3|ifc2x3` → IFC-Schema des Exports (ohne Angabe IFC4). */
|
||||
function ifcSchemaFlag(args: Args): "IFC4" | "IFC2X3" {
|
||||
const v = args.flags.get("schema");
|
||||
if (v === undefined) return "IFC4";
|
||||
const k = v.toLowerCase().replace(/^ifc/, "");
|
||||
if (k === "4") return "IFC4";
|
||||
if (k === "2x3") return "IFC2X3";
|
||||
return fail(`--schema: "${v}" unbekannt (4 oder 2x3)`);
|
||||
}
|
||||
|
||||
function parseArgs(argv: string[]): Args {
|
||||
const positional: string[] = [];
|
||||
const flags = new Map<string, string>();
|
||||
@@ -590,7 +601,7 @@ async function execute(project: Project, file: string, command: string, rest: st
|
||||
case "ifc":
|
||||
await loadFileio();
|
||||
// --ebkph: eBKP-H-Hauptgruppen je Bauteilart; --ebenen: Ebene (categoryCode) des Modells als Klassifikation.
|
||||
out(args, exportIfcSpf(project, { ebkph: args.flags.has("ebkph"), layerCodes: args.flags.has("ebenen") }), `${project.name || "projekt"}.ifc`);
|
||||
out(args, exportIfcSpf(project, { ebkph: args.flags.has("ebkph"), layerCodes: args.flags.has("ebenen"), schema: ifcSchemaFlag(args) }), `${project.name || "projekt"}.ifc`);
|
||||
return 0;
|
||||
case "obj":
|
||||
await loadFileio();
|
||||
|
||||
@@ -0,0 +1,338 @@
|
||||
// IFC2x3-Export (Coordination View 2.0, [B5] 28.10.): Schema-Option des IFC-Exports.
|
||||
//
|
||||
// - Text: Kopf, Entitäten des Schemas (keine IFC4-Entitäten), gleiche GlobalIds wie IFC4.
|
||||
// - Eigener Import (`src/io/ifcImport.ts`, `ifcElements.ts`): liest die 2x3-Datei als Meshes und als
|
||||
// Bauteile mit demselben Ergebnis wie die IFC4-Datei.
|
||||
// - ifcopenshell (nur mit Python/ifcopenshell): Schema-Prüfung der 2x3-Datei ohne Befunde, Volumen und
|
||||
// Lage je Bauteil gleich der IFC4-Ausgabe.
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { mkdtempSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import "../engine/fileioWasm.setup";
|
||||
import { exportIfcSpf } from "./exportIfc";
|
||||
import { ifcElementsToProject, readIfcElements } from "../io/ifcElements";
|
||||
import { readIfc } from "../io/ifcImport";
|
||||
import { emptyProject, sampleProject } from "../model/sampleProject";
|
||||
import type { Project } from "../model/types";
|
||||
|
||||
const hasIfcOpenShell = spawnSync("python3", ["-c", "import ifcopenshell, ifcopenshell.validate, _pytest"]).status === 0;
|
||||
const bytesOf = (s: string) => new TextEncoder().encode(s);
|
||||
|
||||
const geoProject: Project = { ...sampleProject, geoAnchor: { lv95: { e: 2683000, n: 1248000 }, height: 410, model: { x: 0, y: 0 } } };
|
||||
/** Laufende Import-Ids (`ifc-wall-<Zeit>-<Zähler>`) in Reihenfolge des Auftretens nummerieren. */
|
||||
function normIds(x: unknown): unknown {
|
||||
const seen = new Map<string, string>();
|
||||
return JSON.parse(
|
||||
JSON.stringify(x).replace(/ifc-[a-z]+-[0-9a-z]+-\d+/g, (m) => {
|
||||
if (!seen.has(m)) seen.set(m, `id${seen.size}`);
|
||||
return seen.get(m)!;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
/** Demo-Haus mit mehrschichtigem Dachtyp am Dach (in IFC2x3 ohne IfcRoofType). */
|
||||
const roofTyped: Project = { ...sampleProject, roofs: (sampleProject.roofs ?? []).map((r) => ({ ...r, roofTypeId: "roof-warm" })) };
|
||||
const v4 = (p: Project, o = {}) => exportIfcSpf(p, o);
|
||||
const v3 = (p: Project, o = {}) => exportIfcSpf(p, { ...o, schema: "IFC2X3" });
|
||||
|
||||
/** Entitätsnamen (`#n=IFCWALL(`) der Datei. */
|
||||
function entityNames(ifc: string): Set<string> {
|
||||
return new Set([...ifc.matchAll(/^#\d+=(IFC[A-Z0-9]+)\(/gm)].map((m) => m[1]));
|
||||
}
|
||||
/** GlobalIds aller Zeilen, die mit `'<22 Zeichen>'` beginnen. */
|
||||
function guids(ifc: string): Set<string> {
|
||||
return new Set([...ifc.matchAll(/^#\d+=IFC[A-Z0-9]+\('([0-9A-Za-z_$]{22})'/gm)].map((m) => m[1]));
|
||||
}
|
||||
|
||||
describe("IFC2x3-Export: Text", () => {
|
||||
const ifc = v3(sampleProject);
|
||||
it("Kopf: Schema IFC2X3 und Coordination View 2.0; IFC4 bleibt Standard", () => {
|
||||
expect(ifc).toContain("FILE_SCHEMA(('IFC2X3'));");
|
||||
expect(ifc).toContain("FILE_DESCRIPTION(('ViewDefinition [CoordinationView_V2.0]'),'2;1');");
|
||||
expect(v4(sampleProject)).toContain("FILE_SCHEMA(('IFC4'));");
|
||||
expect(exportIfcSpf(sampleProject, { schema: "IFC4" }).split("\n").slice(-20)).toEqual(v4(sampleProject).split("\n").slice(-20));
|
||||
// eslint-disable-next-line no-control-regex
|
||||
expect(/^[\x00-\x7f]*$/.test(ifc)).toBe(true);
|
||||
});
|
||||
|
||||
it("keine IFC4-Entitäten, Ersatz aus IFC2x3", () => {
|
||||
const names = entityNames(ifc);
|
||||
for (const gone of [
|
||||
"IFCTRIANGULATEDFACESET",
|
||||
"IFCCARTESIANPOINTLIST3D",
|
||||
"IFCROOFTYPE",
|
||||
"IFCPROJECTEDCRS",
|
||||
"IFCMAPCONVERSION",
|
||||
]) {
|
||||
expect(names.has(gone), gone).toBe(false);
|
||||
}
|
||||
// Dach als Netz → IfcFacetedBrep (dicht) bzw. IfcShellBasedSurfaceModel; Türen mit IfcDoorStyle.
|
||||
expect(names.has("IFCFACETEDBREP") || names.has("IFCSHELLBASEDSURFACEMODEL")).toBe(true);
|
||||
expect(names.has("IFCDOORSTYLE")).toBe(true);
|
||||
expect(names.has("IFCWALLSTANDARDCASE")).toBe(true);
|
||||
expect(names.has("IFCPRESENTATIONSTYLEASSIGNMENT")).toBe(true);
|
||||
// Türen/Fenster ohne PredefinedType/OperationType: nur Höhe und Breite am Ende.
|
||||
for (const line of ifc.split("\n").filter((l) => /^#\d+=IFC(DOOR|WINDOW)\(/.test(l))) {
|
||||
expect(line, line).toMatch(/,\$,[\d.]+,[\d.]+\);$/);
|
||||
}
|
||||
});
|
||||
|
||||
it("gleiche GlobalIds wie IFC4 (ausser den Entitäten, die es nur in einem Schema gibt)", () => {
|
||||
const a = guids(v4(sampleProject));
|
||||
const b = guids(ifc);
|
||||
const onlyIn3 = [...b].filter((g) => !a.has(g));
|
||||
const onlyIn4 = [...a].filter((g) => !b.has(g));
|
||||
// IFC2x3: Türstil + Beziehung (je Ausführung); IFC4: Dachtyp samt Zuordnung, Material am Typ.
|
||||
expect(onlyIn3.length).toBeLessThanOrEqual(8);
|
||||
expect(onlyIn4.length).toBeLessThanOrEqual(6);
|
||||
// Alle Bauteile (IfcProduct) tragen in beiden Schemata dieselbe GlobalId.
|
||||
const productGuids = (t: string) =>
|
||||
new Set(
|
||||
[...t.matchAll(/^#\d+=(IFCWALL|IFCWALLSTANDARDCASE|IFCSLAB|IFCROOF|IFCDOOR|IFCWINDOW|IFCSTAIR|IFCSTAIRFLIGHT|IFCRAILING|IFCCOLUMN|IFCSPACE|IFCOPENINGELEMENT|IFCBUILDINGSTOREY|IFCBUILDING|IFCSITE|IFCPROJECT)\('([^']{22})'/gm)].map((m) => m[2]),
|
||||
);
|
||||
expect(productGuids(ifc)).toEqual(productGuids(v4(sampleProject)));
|
||||
});
|
||||
|
||||
it("Georeferenz: IfcSite RefLatitude/RefLongitude/RefElevation und ePSet_*, kein IfcMapConversion", () => {
|
||||
const g = v3(geoProject);
|
||||
const site = g.split("\n").find((l) => /^#\d+=IFCSITE\(/.test(l))!;
|
||||
// LV95 2683000/1248000 ≈ Zürich-Nord: 47° 25′ N, 8° 33′ E (swisstopo-Näherung).
|
||||
const m = site.match(/\.ELEMENT\.,\((\d+),(\d+),(\d+),(\d+)\),\((\d+),(\d+),(\d+),(\d+)\),410\.0,\$,\$\);$/);
|
||||
expect(m, site).not.toBeNull();
|
||||
const [lat, lon] = [m!.slice(1, 5).map(Number), m!.slice(5, 9).map(Number)];
|
||||
expect(lat[0] + lat[1] / 60 + lat[2] / 3600 + lat[3] / 3.6e9).toBeCloseTo(47.4, 0);
|
||||
expect(lon[0] + lon[1] / 60 + lon[2] / 3600 + lon[3] / 3.6e9).toBeCloseTo(8.5, 0);
|
||||
expect(g).toContain("'ePSet_ProjectedCRS'");
|
||||
expect(g).toContain("'ePSet_MapConversion'");
|
||||
expect(g).toContain("IFCLABEL('EPSG:2056')");
|
||||
expect(g).not.toContain("IFCMAPCONVERSION");
|
||||
// Ohne Bezug weder Winkel noch Sätze.
|
||||
expect(ifc).not.toContain("ePSet_");
|
||||
expect(ifc.split("\n").find((l) => /^#\d+=IFCSITE\(/.test(l))).toContain(".ELEMENT.,$,$,$,$,$);");
|
||||
// IFC4 trägt die Georeferenz weiter über IfcMapConversion.
|
||||
expect(v4(geoProject)).toContain("IFCMAPCONVERSION(");
|
||||
});
|
||||
|
||||
it("Klassifikation, Zonen, Psets und Mengen wie in IFC4", () => {
|
||||
const a = v4(sampleProject, { ebkph: true });
|
||||
const b = v3(sampleProject, { ebkph: true });
|
||||
for (const name of ["IFCCLASSIFICATION", "IFCCLASSIFICATIONREFERENCE", "IFCRELASSOCIATESCLASSIFICATION", "IFCPROPERTYSET", "IFCELEMENTQUANTITY", "IFCQUANTITYAREA", "IFCQUANTITYLENGTH", "IFCQUANTITYVOLUME", "IFCZONE"]) {
|
||||
const n = (t: string) => (t.match(new RegExp(`^#\\d+=${name}\\(`, "gm")) ?? []).length;
|
||||
expect(n(b), name).toBe(n(a));
|
||||
}
|
||||
expect(b).toContain("'Qto_WallBaseQuantities'");
|
||||
expect(b).toContain("'Pset_WallCommon'");
|
||||
expect(b).toContain("'eBKP-H'");
|
||||
});
|
||||
|
||||
it("deterministisch", () => {
|
||||
// Zeitstempel (`now`, `iso`) ändern sich je Sekunde: nur die Datensätze vergleichen.
|
||||
const strip = (t: string) => t.replace(/FILE_NAME\([^;]*;/, "").replace(/IFCOWNERHISTORY\([^;]*;/, "");
|
||||
expect(strip(v3(sampleProject))).toBe(strip(v3(sampleProject)));
|
||||
});
|
||||
});
|
||||
|
||||
describe("IFC2x3-Export: eigener Import liest dasselbe wie bei IFC4", () => {
|
||||
const a = v4(sampleProject);
|
||||
const b = v3(sampleProject);
|
||||
|
||||
it("Meshes: gleiche Körper (GlobalId, Volumen), Schema IFC2X3 erkannt", async () => {
|
||||
const r4 = await readIfc(bytesOf(a));
|
||||
const r3 = await readIfc(bytesOf(b));
|
||||
expect(r4.report.schema).toBe("IFC4");
|
||||
expect(r3.report.schema).toBe("IFC2X3");
|
||||
expect(r3.report.parseErrors).toBe(0);
|
||||
expect(r3.report.skippedItems).toEqual({});
|
||||
expect(r3.report.productsWithoutGeometry).toBe(0);
|
||||
expect(r3.products.length).toBe(r4.products.length);
|
||||
const vol = (p: { positions: ArrayLike<number>; indices: ArrayLike<number> }) => {
|
||||
let v = 0;
|
||||
for (let i = 0; i + 2 < p.indices.length; i += 3) {
|
||||
const [x, y, z] = [p.indices[i] * 3, p.indices[i + 1] * 3, p.indices[i + 2] * 3];
|
||||
const q = p.positions;
|
||||
v += (q[x] * (q[y + 1] * q[z + 2] - q[y + 2] * q[z + 1]) + q[x + 1] * (q[y + 2] * q[z] - q[y] * q[z + 2]) + q[x + 2] * (q[y] * q[z + 1] - q[y + 1] * q[z])) / 6;
|
||||
}
|
||||
return v;
|
||||
};
|
||||
const byId4 = new Map(r4.products.map((p) => [p.globalId, p]));
|
||||
for (const p of r3.products) {
|
||||
const q = byId4.get(p.globalId);
|
||||
expect(q, `${p.ifcClass} ${p.name}`).toBeDefined();
|
||||
expect(p.name).toBe(q!.name);
|
||||
expect(p.storey).toBe(q!.storey);
|
||||
expect(vol(p), `${p.ifcClass} ${p.name}`).toBeCloseTo(vol(q!), 6);
|
||||
expect(vol(p)).toBeGreaterThan(0);
|
||||
}
|
||||
});
|
||||
|
||||
it("Bauteile: gleiche Wände, Öffnungen, Decken, Räume", async () => {
|
||||
const e4 = await readIfcElements(bytesOf(a));
|
||||
const e3 = await readIfcElements(bytesOf(b));
|
||||
expect(e3.report.parseErrors).toBe(0);
|
||||
const p4 = ifcElementsToProject(emptyProject, e4.products, e4.elements, { fileName: "haus.ifc" });
|
||||
const p3 = ifcElementsToProject(emptyProject, e3.products, e3.elements, { fileName: "haus.ifc" });
|
||||
expect(p3.summary).toEqual(p4.summary);
|
||||
for (const key of ["walls", "openings", "ceilings", "rooms", "wallTypes"] as const) {
|
||||
expect(normIds(p3.project[key]), key).toEqual(normIds(p4.project[key]));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// ── ifcopenshell ────────────────────────────────────────────────────────────
|
||||
|
||||
function writeIfc(name: string, ifc: string): string {
|
||||
const dir = mkdtempSync(join(tmpdir(), "dossier-ifc2x3-"));
|
||||
const file = join(dir, `${name}.ifc`);
|
||||
writeFileSync(file, ifc);
|
||||
return file;
|
||||
}
|
||||
|
||||
function validate(name: string, ifc: string): { status: number | null; out: string } {
|
||||
const r = spawnSync("python3", ["scripts/validate-ifc.py", writeIfc(name, ifc)], { encoding: "utf8", timeout: 120_000 });
|
||||
return { status: r.status, out: `${r.stdout}\n${r.stderr}` };
|
||||
}
|
||||
|
||||
// Je Produkt (GlobalId): Klasse, Volumen und Welt-Bounding-Box der Geometrie sowie Schema der Datei.
|
||||
const PRODUCTS = `
|
||||
import json, sys
|
||||
import ifcopenshell, ifcopenshell.geom, ifcopenshell.util.shape as us
|
||||
m = ifcopenshell.open(sys.argv[1])
|
||||
s = ifcopenshell.geom.settings()
|
||||
s.set("use-world-coords", True)
|
||||
out = {"schema": m.schema, "products": {}}
|
||||
for p in m.by_type("IfcProduct"):
|
||||
if p.Representation is None:
|
||||
continue
|
||||
sh = ifcopenshell.geom.create_shape(s, p)
|
||||
v = sh.geometry.verts
|
||||
xs, ys, zs = v[0::3], v[1::3], v[2::3]
|
||||
out["products"][p.GlobalId] = {"cls": p.is_a(), "name": p.Name, "volume": us.get_volume(sh.geometry),
|
||||
"bbox": [min(xs), max(xs), min(ys), max(ys), min(zs), max(zs)]}
|
||||
print(json.dumps(out))
|
||||
`;
|
||||
|
||||
interface ProductInfo {
|
||||
cls: string;
|
||||
name: string | null;
|
||||
volume: number;
|
||||
bbox: number[];
|
||||
}
|
||||
|
||||
function products(name: string, ifc: string): { schema: string; products: Record<string, ProductInfo> } {
|
||||
const r = spawnSync("python3", ["-c", PRODUCTS, writeIfc(name, ifc)], { encoding: "utf8", timeout: 120_000 });
|
||||
expect(r.status, r.stderr).toBe(0);
|
||||
return JSON.parse(r.stdout);
|
||||
}
|
||||
|
||||
// Schema je Bauteil (nach ifcopenshell gelesen): Typ-Zuordnung, Türausführung, Material am Dach.
|
||||
const DETAILS = `
|
||||
import json, sys
|
||||
import ifcopenshell
|
||||
m = ifcopenshell.open(sys.argv[1])
|
||||
out = {"standardCase": len(m.by_type("IfcWallStandardCase", include_subtypes=False)),
|
||||
"doorOps": sorted({(d.is_a(), getattr(d, "OperationType", None)) for d in m.by_type("IfcDoorStyle")} | {(d.is_a(), getattr(d, "OperationType", None)) for d in m.by_type("IfcWindowStyle")}),
|
||||
"doorsWithStyle": sum(1 for d in m.by_type("IfcDoor") if any(r.is_a("IfcRelDefinesByType") for r in d.IsDefinedBy)),
|
||||
"doors": len(m.by_type("IfcDoor")),
|
||||
"wallUsage": sum(1 for w in m.by_type("IfcWallStandardCase") for r in w.HasAssociations if r.is_a("IfcRelAssociatesMaterial") and r.RelatingMaterial.is_a("IfcMaterialLayerSetUsage")),
|
||||
"roofLayers": [[l.LayerThickness for l in r.RelatingMaterial.MaterialLayers] for roof in m.by_type("IfcRoof") for r in roof.HasAssociations if r.is_a("IfcRelAssociatesMaterial") and r.RelatingMaterial.is_a("IfcMaterialLayerSet")],
|
||||
"site": [m.by_type("IfcSite")[0].RefLatitude, m.by_type("IfcSite")[0].RefLongitude, m.by_type("IfcSite")[0].RefElevation]}
|
||||
print(json.dumps(out))
|
||||
`;
|
||||
|
||||
function details(name: string, ifc: string): Record<string, unknown> {
|
||||
const r = spawnSync("python3", ["-c", DETAILS, writeIfc(name, ifc)], { encoding: "utf8", timeout: 120_000 });
|
||||
expect(r.status, r.stderr).toBe(0);
|
||||
return JSON.parse(r.stdout);
|
||||
}
|
||||
|
||||
/** Eine freistehende Wand 5 × 0.4 × 2.6 m mit einem Fenster (wie `exportIfc.validate.test.ts`). */
|
||||
function singleWall(recess: boolean): Project {
|
||||
return {
|
||||
...sampleProject,
|
||||
walls: [{ id: "W1", type: "wall", floorId: "eg", categoryCode: "20", start: { x: 0, y: 0 }, end: { x: 5, y: 0 }, wallTypeId: "solo", height: 2.6 }],
|
||||
wallTypes: [...sampleProject.wallTypes, { id: "solo", name: "Beton 40", layers: [{ componentId: sampleProject.components[0].id, thickness: 0.4 }] }],
|
||||
windowTypes: [{ id: "wt", name: "Fenster", kind: "drehkipp", wingCount: 1, glazing: "dreifach", frameThickness: 0.08, defaultSillHeight: 0.9, defaultWidth: 1.2, defaultHeight: 1.2, innerLayerRecess: recess }],
|
||||
openings: [{ id: "F1", type: "opening", hostWallId: "W1", categoryCode: "21", kind: "window", position: 1, width: 1.2, height: 1.2, sillHeight: 0.9, typeId: "wt" }],
|
||||
ceilings: [],
|
||||
roofs: [],
|
||||
rooms: [],
|
||||
stairs: [],
|
||||
columns: [],
|
||||
} as Project;
|
||||
}
|
||||
|
||||
/** Wie `singleWall`, dazu Stützen (Rechteck/rund), damit auch IfcColumn geprüft wird. */
|
||||
function withColumns(): Project {
|
||||
const col = (id: string, profile: { kind: "rect"; width: number; depth: number } | { kind: "round"; radius: number }) => ({
|
||||
id, type: "column" as const, floorId: "eg", categoryCode: "50", position: { x: 1, y: 1 }, profile, rotation: 0.3, height: 2.5,
|
||||
});
|
||||
return { ...sampleProject, columns: [col("S1", { kind: "rect", width: 0.3, depth: 0.2 }), col("S2", { kind: "round", radius: 0.15 })] };
|
||||
}
|
||||
|
||||
// Je Fall ein Python-Prozess (~3 s, unter Last mehr): eigenes Zeitlimit.
|
||||
describe.skipIf(!hasIfcOpenShell)("IFC2x3-Export gegen ifcopenshell", { timeout: 90_000 }, () => {
|
||||
const cases: [string, Project, object][] = [
|
||||
["demo-haus", sampleProject, {}],
|
||||
["demo-haus-klassifiziert", sampleProject, { ebkph: true, layerCodes: true }],
|
||||
["demo-haus-geo", geoProject, {}],
|
||||
["dach-mit-typ", roofTyped, {}],
|
||||
["stuetzen", withColumns(), {}],
|
||||
["wand-oeffnung", singleWall(false), {}],
|
||||
["wand-mesh", singleWall(true), {}],
|
||||
["umlaute", { ...sampleProject, name: "Wohnüberbauung «Süd»", rooms: (sampleProject.rooms ?? []).map((r) => ({ ...r, name: "Küche/Essen" })) }, {}],
|
||||
];
|
||||
|
||||
it.each(cases)("%s: Schema IFC2X3 ohne Befunde, Körper erzeugbar", (name, project, opts) => {
|
||||
const r = validate(name, v3(project, opts));
|
||||
expect(r.out).toContain("0 Befunde");
|
||||
expect(r.status).toBe(0);
|
||||
expect(products(name, v3(project, opts)).schema).toBe("IFC2X3");
|
||||
});
|
||||
|
||||
it.each(cases)("%s: Volumen und Lage je Bauteil gleich IFC4", (name, project, opts) => {
|
||||
const four = products(name + "-4", v4(project, opts));
|
||||
const three = products(name + "-3", v3(project, opts));
|
||||
expect(four.schema).toBe("IFC4");
|
||||
expect(Object.keys(three.products).sort()).toEqual(Object.keys(four.products).sort());
|
||||
expect(Object.keys(three.products).length).toBeGreaterThan(0);
|
||||
for (const [id, p3] of Object.entries(three.products)) {
|
||||
const p4 = four.products[id];
|
||||
const what = `${p3.cls} ${p3.name}`;
|
||||
expect(Math.abs(p3.volume - p4.volume), `${what}: ${p3.volume} vs ${p4.volume}`).toBeLessThanOrEqual(1e-6);
|
||||
p3.bbox.forEach((x, i) => expect(Math.abs(x - p4.bbox[i]), `${what} bbox ${i}`).toBeLessThanOrEqual(1e-6));
|
||||
// Klasse: IfcWallStandardCase ist ein IfcWall; sonst gleich.
|
||||
expect(p3.cls === p4.cls || (p4.cls === "IfcWall" && p3.cls === "IfcWallStandardCase"), `${p4.cls} → ${p3.cls}`).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("Demo-Haus: StandardCase mit Usage, Türen mit Style, Dachschichten am Dach", () => {
|
||||
const d = details("demo-haus", v3(roofTyped)) as {
|
||||
standardCase: number;
|
||||
doorsWithStyle: number;
|
||||
doors: number;
|
||||
wallUsage: number;
|
||||
roofLayers: number[][];
|
||||
doorOps: [string, string][];
|
||||
};
|
||||
// Jede StandardCase-Wand hat genau eine LayerSetUsage (IFC2x3 WR1).
|
||||
expect(d.standardCase).toBeGreaterThan(0);
|
||||
expect(d.wallUsage).toBe(d.standardCase);
|
||||
expect(d.doors).toBeGreaterThan(0);
|
||||
expect(d.doorsWithStyle).toBe(d.doors);
|
||||
expect(d.doorOps.length).toBeGreaterThan(0);
|
||||
// Dachtyp gibt es in IFC2x3 nicht: Schichten direkt am Dach.
|
||||
expect(d.roofLayers.length).toBeGreaterThan(0);
|
||||
for (const layers of d.roofLayers) expect(layers.reduce((s, x) => s + x, 0)).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("Georeferenz: IfcSite-Winkel gelesen, Höhe 410", () => {
|
||||
const d = details("geo", v3(geoProject)) as { site: [number[], number[], number] };
|
||||
const deg = (a: number[]) => a[0] + a[1] / 60 + a[2] / 3600 + (a[3] ?? 0) / 3.6e9;
|
||||
expect(deg(d.site[0])).toBeCloseTo(47.4, 0);
|
||||
expect(deg(d.site[1])).toBeCloseTo(8.5, 0);
|
||||
expect(d.site[2]).toBeCloseTo(410, 9);
|
||||
});
|
||||
});
|
||||
+25
-4
@@ -1,4 +1,8 @@
|
||||
// IFC4-Export (STEP Physical File / ISO-10303-21) des semantischen Modells.
|
||||
// IFC-Export (IFC4 oder IFC2x3, STEP Physical File / ISO-10303-21) des semantischen Modells.
|
||||
//
|
||||
// Schema ([B5], 28.10.): `options.schema` = "IFC4" (Standard) oder "IFC2X3" (Coordination View 2.0).
|
||||
// TS sammelt in beiden Fällen dasselbe; nur das META trägt die Wahl (und die WGS84-Breite/Länge des
|
||||
// Bezugspunkts für `IfcSite.RefLatitude/RefLongitude`), die Entitäten des Schemas schreibt Rust.
|
||||
//
|
||||
// Seit [B5] (28.10.) schreibt Rust die Datei (`src-tauri/fileio/src/ifc_export.rs`, Format-Modul
|
||||
// pkgFileIo): TS sammelt hier aus Projekt und Plan die Bauteile samt fertig gerechneter Geometrie
|
||||
@@ -107,6 +111,7 @@ import { columnFootprint } from "../geometry/column";
|
||||
import { openingInterval, openingVerticalExtent } from "../geometry/opening";
|
||||
import { emitRoofs } from "../plan/toWalls3d/roofs";
|
||||
import { fileio } from "../engine/fileioWasm";
|
||||
import { lv95ToWgs84 } from "../io/lv95";
|
||||
import { fillParams, type FillParams } from "./ifcOpenings";
|
||||
import { stairParts } from "./ifcStairs";
|
||||
import {
|
||||
@@ -129,9 +134,17 @@ import {
|
||||
type ClassificationSystem,
|
||||
type ClassifiedKind,
|
||||
type IfcExportOptions,
|
||||
type IfcSchema,
|
||||
} from "./ifcClassification";
|
||||
|
||||
export type { IfcExportOptions } from "./ifcClassification";
|
||||
export type { IfcExportOptions, IfcSchema } from "./ifcClassification";
|
||||
|
||||
/** WGS84 des LV95-Bezugspunkts (swisstopo-Näherung); `null` ohne Bezug oder bei unbrauchbaren Zahlen. */
|
||||
function refLatLon(lv95: { e: number; n: number } | undefined): { lat: number; lon: number } | null {
|
||||
if (!lv95 || !Number.isFinite(lv95.e) || !Number.isFinite(lv95.n)) return null;
|
||||
const { lat, lon } = lv95ToWgs84(lv95.e, lv95.n);
|
||||
return Number.isFinite(lat) && Number.isFinite(lon) ? { lat, lon } : null;
|
||||
}
|
||||
|
||||
/** Deterministische 22-stellige IFC-GUID aus einem Namen (Rust, `ifc_export.rs::ifc_guid`). */
|
||||
export function ifcGuid(name: string): string {
|
||||
@@ -145,7 +158,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 = 3;
|
||||
const FLAT_VERSION = 4;
|
||||
const REC_WALL_SOLIDS = 1;
|
||||
const REC_WALL_MESH = 2;
|
||||
const REC_CEILING = 3;
|
||||
@@ -241,6 +254,9 @@ class FlatIfc {
|
||||
iso: string;
|
||||
hasGeo: boolean;
|
||||
refElevation: number | null;
|
||||
/** WGS84-Grad des Bezugspunkts (nur IFC2x3-Site); `null` = keine. */
|
||||
refLatLon: { lat: number; lon: number } | null;
|
||||
schema: IfcSchema;
|
||||
storeys: { id: string; name: string; base: number }[];
|
||||
}): void {
|
||||
this.nums.push(
|
||||
@@ -250,6 +266,9 @@ class FlatIfc {
|
||||
this.str(m.iso),
|
||||
m.hasGeo ? 1 : 0,
|
||||
m.refElevation ?? Number.NaN,
|
||||
m.refLatLon?.lat ?? Number.NaN,
|
||||
m.refLatLon?.lon ?? Number.NaN,
|
||||
m.schema === "IFC2X3" ? 1 : 0,
|
||||
m.storeys.length,
|
||||
);
|
||||
for (const s of m.storeys) this.nums.push(this.str(s.id), this.str(s.name), s.base);
|
||||
@@ -612,7 +631,7 @@ function qto(name: string, quantities: readonly Qty[]): PsetIn[] {
|
||||
}
|
||||
|
||||
/**
|
||||
* Baut aus einem Projekt einen vollständigen IFC4-SPF-String (STEP Physical
|
||||
* Baut aus einem Projekt einen vollständigen IFC-SPF-String (IFC4, oder IFC2x3 mit `options.schema`; STEP Physical
|
||||
* File). Kein Datei-IO. Leeres Projekt ⇒ valider Minimal-IFC (Project/Site/Building, kein Crash).
|
||||
* Verlangt das geladene Format-Modul (`await loadFileio()`).
|
||||
*/
|
||||
@@ -647,6 +666,8 @@ export function exportIfcSpf(projectIn: Project, options: IfcExportOptions = {})
|
||||
iso: new Date().toISOString().replace(/\.\d+Z$/, ""),
|
||||
hasGeo: !!project.geoAnchor,
|
||||
refElevation: typeof refElevation === "number" ? refElevation : null,
|
||||
refLatLon: refLatLon(project.geoAnchor?.lv95),
|
||||
schema: options.schema === "IFC2X3" ? "IFC2X3" : "IFC4",
|
||||
storeys: floors.map((f, i) => ({ id: f.id, name: f.name, base: storeyBase[i] })),
|
||||
});
|
||||
|
||||
|
||||
@@ -29,8 +29,13 @@
|
||||
|
||||
import type { LayerCategory, Project } from "../model/types";
|
||||
|
||||
/** Optionen der Klassifikation im IFC-Export. */
|
||||
/** IFC-Schema der Ausgabe: IFC4 (Standard) oder IFC2x3 (Coordination View 2.0, TC1). */
|
||||
export type IfcSchema = "IFC4" | "IFC2X3";
|
||||
|
||||
/** Optionen des IFC-Exports: Schema und Klassifikation. */
|
||||
export interface IfcExportOptions {
|
||||
/** Schema der Datei; ohne Angabe IFC4. */
|
||||
schema?: IfcSchema;
|
||||
/** eBKP-H-Hauptgruppen je Bauteilart (Standardzuordnung, s. Dateikopf). */
|
||||
ebkph?: boolean;
|
||||
/** `categoryCode` (Ebene) des Modells als System „Dossier-Ebenen". */
|
||||
|
||||
@@ -1788,6 +1788,10 @@ export const de = {
|
||||
"exportSave.ifc.layers": "Ebene (Kategorie-Code) des Modells als Klassifikation",
|
||||
"exportSave.ifc.layersHint": "System «Dossier-Ebenen»: Code und Name der Grafik-Ebene jedes Bauteils (kein Baukostenplan).",
|
||||
"exportSave.ifc.zonesNote": "SIA-416-Zonen (HNF, NNF …) und Geschossflächen sind immer enthalten, sobald Räume vorhanden sind.",
|
||||
"exportSave.ifc.schema": "IFC-Schema",
|
||||
"exportSave.ifc.schema4": "IFC4 (Standard)",
|
||||
"exportSave.ifc.schema2x3": "IFC2x3 (Coordination View 2.0)",
|
||||
"exportSave.ifc.schemaHint": "IFC2x3 für ältere Programme (Revit/ArchiCAD-Versionen, Statik, Energie, Kalkulation): Netze als Brep, Türen/Fenster mit Style, Georeferenz über IfcSite und ePSet_MapConversion. Inhalt und GUIDs wie bei IFC4.",
|
||||
"exportSave.fmt.csv": "Bauteilliste (CSV)",
|
||||
"exportSave.fmt.ifc": "IFC (BIM)",
|
||||
"exportSave.fmt.obj": "OBJ (3D-Mesh)",
|
||||
|
||||
@@ -1950,6 +1950,10 @@ export const en: Record<TranslationKey, string> = {
|
||||
"exportSave.ifc.layers": "Model layer (category code) as classification",
|
||||
"exportSave.ifc.layersHint": "System “Dossier-Ebenen”: code and name of each element's graphic layer (not a cost plan).",
|
||||
"exportSave.ifc.zonesNote": "SIA 416 zones (HNF, NNF …) and storey areas are always included when rooms exist.",
|
||||
"exportSave.ifc.schema": "IFC schema",
|
||||
"exportSave.ifc.schema4": "IFC4 (default)",
|
||||
"exportSave.ifc.schema2x3": "IFC2x3 (Coordination View 2.0)",
|
||||
"exportSave.ifc.schemaHint": "IFC2x3 for older programs (Revit/ArchiCAD versions, structural, energy, cost estimation): meshes as Brep, doors/windows with styles, georeferencing via IfcSite and ePSet_MapConversion. Same content and GUIDs as IFC4.",
|
||||
"exportSave.fmt.csv": "Component schedule (CSV)",
|
||||
"exportSave.fmt.ifc": "IFC (BIM)",
|
||||
"exportSave.fmt.obj": "OBJ (3D mesh)",
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { t } from "../i18n";
|
||||
import { Dropdown } from "./Dropdown";
|
||||
import type { IfcExportOptions } from "../export/ifcClassification";
|
||||
import type { IfcExportOptions, IfcSchema } from "../export/ifcClassification";
|
||||
|
||||
/** Direkt-herunterladbare Exportformate (mit Datei-Endung). */
|
||||
export type ExportSaveFormat = "csv" | "ifc" | "obj" | "stl" | "glb" | "step";
|
||||
@@ -64,7 +64,9 @@ export function ExportSaveDialog({
|
||||
// IFC-Klassifikation (Schweizer Praxis): beides aus, bis die Nutzerin es wählt.
|
||||
const [ebkph, setEbkph] = useState(false);
|
||||
const [layerCodes, setLayerCodes] = useState(false);
|
||||
const onConfirm = () => onSave(format, filename, format === "ifc" ? { ebkph, layerCodes } : undefined);
|
||||
// IFC-Schema: IFC4 (Standard) oder IFC2x3 für ältere Fachplaner-Programme.
|
||||
const [schema, setSchema] = useState<IfcSchema>("IFC4");
|
||||
const onConfirm = () => onSave(format, filename, format === "ifc" ? { schema, ebkph, layerCodes } : undefined);
|
||||
|
||||
return (
|
||||
<div className="imp-overlay" onClick={onClose}>
|
||||
@@ -102,6 +104,17 @@ export function ExportSaveDialog({
|
||||
|
||||
{format === "ifc" && (
|
||||
<section className="imp-section">
|
||||
<div className="imp-section-title">{t("exportSave.ifc.schema")}</div>
|
||||
<Dropdown
|
||||
value={schema}
|
||||
onChange={(v) => setSchema(v as IfcSchema)}
|
||||
title={t("exportSave.ifc.schema")}
|
||||
options={[
|
||||
{ value: "IFC4", label: t("exportSave.ifc.schema4") },
|
||||
{ value: "IFC2X3", label: t("exportSave.ifc.schema2x3") },
|
||||
]}
|
||||
/>
|
||||
<div className="imp-note">{t("exportSave.ifc.schemaHint")}</div>
|
||||
<label className="imp-check">
|
||||
<input type="checkbox" checked={ebkph} onChange={(e) => setEbkph(e.target.checked)} />
|
||||
<span>{t("exportSave.ifc.ebkph")}</span>
|
||||
|
||||
Reference in new issue
Block a user