From 2c43190ae0a4c7fcaa34e44e4842376f72fa73ee Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 27 Oct 2026 20:29:53 +0000 Subject: [PATCH] [B1][18] IFC-Export gegen ifcopenshell pruefen (Schema, Express-Regeln, Geometrie je Bauteil); Fund behoben: IfcOwnerHistory ADDED ohne LastModifiedDate - scripts/validate-ifc.py (eigenes Pruefskript), exportIfc.validate.test.ts ruft es auf, wenn ifcopenshell installiert ist (sonst uebersprungen); CI installiert ifcopenshell + pytest Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67 --- .github/workflows/check.yml | 2 ++ scripts/validate-ifc.py | 43 +++++++++++++++++++++++++++ src/export/exportIfc.ts | 5 +++- src/export/exportIfc.validate.test.ts | 35 ++++++++++++++++++++++ 4 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 scripts/validate-ifc.py create mode 100644 src/export/exportIfc.validate.test.ts diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 1e480170..0893ee5f 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -14,5 +14,7 @@ jobs: with: { targets: wasm32-unknown-unknown } - run: cargo install wasm-pack --locked - run: npm ci + # IFC-Prüfung in exportIfc.validate.test.ts ([B1]); ohne ifcopenshell würde sie übersprungen. + - run: pip install ifcopenshell pytest - run: npm run build:truck && npm run build:engine3d && npm run build:engine && npm run build:kernel2d && npm run build:dwgimport - run: npm run check diff --git a/scripts/validate-ifc.py b/scripts/validate-ifc.py new file mode 100644 index 00000000..6a0dbb1c --- /dev/null +++ b/scripts/validate-ifc.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 +"""IFC-Datei prüfen ([B1]/[18]): Schema + Express-Regeln (ifcopenshell.validate) und Geometrie je Bauteil. + +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). +""" + +import sys + +import ifcopenshell +import ifcopenshell.geom +import ifcopenshell.validate + + +def check(path: str) -> int: + logger = ifcopenshell.validate.json_logger() + model = ifcopenshell.open(path) + ifcopenshell.validate.validate(model, logger, express_rules=True) + problems = [f"{s.get('level', '?')}: {s.get('message', s)}" for s in logger.statements] + + settings = ifcopenshell.geom.settings() + shapes = 0 + for product in model.by_type("IfcProduct"): + if product.Representation is None: + continue + try: + ifcopenshell.geom.create_shape(settings, product) + shapes += 1 + except Exception as exc: # noqa: BLE001 — jeder Geometriefehler ist ein Befund + problems.append(f"Geometrie {product.is_a()} #{product.id()} {product.Name!r}: {exc}") + + print(f"{path}: {len(model.by_type('IfcProduct'))} Produkte, {shapes} Körper, {len(problems)} Befunde") + for p in problems[:200]: + print(" " + p) + return 1 if problems else 0 + + +if __name__ == "__main__": + if len(sys.argv) < 2: + print(__doc__) + sys.exit(2) + sys.exit(max(check(p) for p in sys.argv[1:])) diff --git a/src/export/exportIfc.ts b/src/export/exportIfc.ts index ac29d237..feadb72b 100644 --- a/src/export/exportIfc.ts +++ b/src/export/exportIfc.ts @@ -337,9 +337,12 @@ export function exportIfcSpf(projectIn: Project): string { "IFCAPPLICATION", `#${org},${S("1.0")},${S("dossier")},${S("dossier")}`, ); + // ChangeAction ADDED verlangt ein LastModifiedDate (IFC4-Regel IfcOwnerHistory.CorrectChangeAction): + // beim frischen Export ist es der Erstellungszeitpunkt. + const now = Math.floor(Date.now() / 1000); const ownerHistory = w.add( "IFCOWNERHISTORY", - `#${personOrg},#${app},$,${ENUM("ADDED")},$,$,$,${Math.floor(Date.now() / 1000)}`, + `#${personOrg},#${app},$,${ENUM("ADDED")},${now},$,$,${now}`, ); // Einheiten (Meter, Radiant, m², m³). diff --git a/src/export/exportIfc.validate.test.ts b/src/export/exportIfc.validate.test.ts new file mode 100644 index 00000000..dc54436b --- /dev/null +++ b/src/export/exportIfc.validate.test.ts @@ -0,0 +1,35 @@ +// IFC-Export gegen ifcopenshell prüfen ([B1]/[18]): Schema, Express-Regeln und Geometrie je Bauteil +// (`scripts/validate-ifc.py`). Ohne Python/ifcopenshell wird der Test übersprungen — in der CI ist +// es installiert (.github/workflows/check.yml). + +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 { exportIfcSpf } from "./exportIfc"; +import { sampleProject } from "../model/sampleProject"; + +const hasIfcOpenShell = spawnSync("python3", ["-c", "import ifcopenshell, ifcopenshell.validate, _pytest"]).status === 0; + +function validate(name: string, ifc: string): { status: number | null; out: string } { + const dir = mkdtempSync(join(tmpdir(), "dossier-ifc-")); + const file = join(dir, `${name}.ifc`); + writeFileSync(file, ifc); + const r = spawnSync("python3", ["scripts/validate-ifc.py", file], { encoding: "utf8", timeout: 120_000 }); + return { status: r.status, out: `${r.stdout}\n${r.stderr}` }; +} + +describe.skipIf(!hasIfcOpenShell)("IFC-Export gegen ifcopenshell", () => { + it("Demo-Haus: gültig, alle Körper erzeugbar", () => { + const r = validate("demo-haus", exportIfcSpf(sampleProject)); + expect(r.out).toContain("0 Befunde"); + expect(r.status).toBe(0); + }); + it("Umlaute in Namen", () => { + const p = { ...sampleProject, name: "Wohnüberbauung «Süd»", rooms: (sampleProject.rooms ?? []).map((r) => ({ ...r, name: "Küche/Essen" })) }; + const r = validate("umlaute", exportIfcSpf(p)); + expect(r.out).toContain("0 Befunde"); + expect(r.status).toBe(0); + }); +});