Files
DOSSIER/scripts/ifc-import-compare.py
T
Claude b158b334a2 [B3] IFC-Import: Öffnungen abziehen, Boolesche Körper und Halbräume, Rotation/Sweeps, Laden im Worker
- csg.rs: BSP-CSG (Verfahren csg.js, MIT, in Rust neu geschrieben: iterativ, Budget, Ursprung
  verschoben); Vereinigung/Differenz/Schnitt, Unsinn → None statt Panic. NOTICE ergänzt.
- ifc_import.rs: IfcRelVoidsElement wird abgezogen (auch Öffnungen am Ganzen, z. B. IfcRoof →
  Platten); IfcBooleanResult/ClippingResult mit allen drei Operationen, Halbräume (HalfSpace,
  Boxed, PolygonalBounded auf IfcPlane) als Quader/Prisma um den Wirt; Kurven jetzt räumlich
  (3D-Bögen, Leitkurven); Ausrundungen bei RoundedRectangle/I/L/U/T; Bericht `voidsApplied`.
- ifc_sweep.rs: IfcRevolvedAreaSolid, IfcSweptDiskSolid(+Polygonal),
  IfcFixedReferenceSweptAreaSolid, IfcSurfaceCurveSweptAreaSolid auf Ebene (Gehrung an Knicken).
- ifcImport.ts/.worker.ts: Lesen im Web-Worker (Puffer übertragen), Rückfall im aufrufenden Thread.
- Tests: Rust je Fall mit Sollvolumen; Rundreise des [B5]-Exports jetzt mit ausgeschnittenem Volumen
  für alle Wände; synthetische Testdatei io/testdata/ifc-geometry-cases.ifc, Gegencheck mit
  ifcopenshell (Skript zieht Öffnungen jetzt ab, stdout-Meldungen umgelenkt); Worker mit Attrappe.

Geprüft: npm run check grün, build:cli, CLI import-ifc; gegen ifcopenshell alle 35
buildingSMART-Sample-Test-Files und 39/46 IFC4.3-sample-models (lokal, nicht eingecheckt).
Nicht geprüft: Tauri-App/Browser (Worker nur als Attrappe in vitest), macOS.

Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
2026-10-28 11:59:51 +00:00

67 lines
2.3 KiB
Python

#!/usr/bin/env python3
"""Gegencheck für den IFC-Import ([B3]): Dreiecke und Volumen je Bauteil aus ifcopenshell.geom.
Aufruf: python3 scripts/ifc-import-compare.py datei.ifc [--no-openings]
Ausgabe (stdout, JSON): {"<GlobalId>": {"class": "IfcWall", "triangles": 12, "volume": 1.5}, …}
Volumen in m³ (Weltkoordinaten, Einheiten der Datei umgerechnet). Ausgelassen wie im Import:
IfcOpeningElement, IfcSpace, IfcAnnotation, IfcGrid, IfcVirtualElement, IfcSpatialZone und Bauteile ohne Körper.
Braucht `pip install ifcopenshell` (getestet mit 0.8/0.9).
"""
import json
import os
import sys
import ifcopenshell
import ifcopenshell.geom
import ifcopenshell.util.shape
SKIP = {"IfcOpeningElement", "IfcOpeningStandardCase", "IfcSpace", "IfcAnnotation", "IfcGrid", "IfcVirtualElement", "IfcSpatialZone"}
def main(path: str) -> int:
# ifcopenshell schreibt bei manchen Dateien Meldungen auf stdout (C++): stdout während des Lesens
# auf stderr umlenken, damit nur das JSON auf stdout landet.
sys.stdout.flush()
real_stdout = os.dup(1)
os.dup2(2, 1)
try:
out = shapes(path)
finally:
sys.stdout.flush()
os.dup2(real_stdout, 1)
os.close(real_stdout)
json.dump(out, sys.stdout)
return 0
def shapes(path: str) -> dict:
model = ifcopenshell.open(path)
settings = ifcopenshell.geom.settings()
settings.set("use-world-coords", True)
# Öffnungen werden abgezogen (wie im Import); `--no-openings` schaltet das ab.
settings.set("disable-opening-subtractions", "--no-openings" in sys.argv)
out = {}
for product in model.by_type("IfcProduct"):
if product.is_a() in SKIP or product.Representation is None:
continue
try:
shape = ifcopenshell.geom.create_shape(settings, product)
except Exception: # noqa: BLE001 — ohne Körper: auslassen
continue
geom = shape.geometry
out[product.GlobalId] = {
"class": product.is_a(),
"triangles": len(geom.faces) // 3,
"volume": ifcopenshell.util.shape.get_volume(geom),
}
return out
if __name__ == "__main__":
files = [a for a in sys.argv[1:] if not a.startswith("--")]
if len(files) != 1:
print(__doc__)
sys.exit(2)
sys.exit(main(files[0]))