Merge branch 'worktree-agent-a916c018860e27cb8' into claude/practical-noether-1hb2s1
This commit is contained in:
17 files changed
+934
-116
No files matched your search
@@ -49,10 +49,13 @@ describe("IFC-Export: Zonen und Geschoss-Kennwerte (SIA 416)", () => {
|
||||
expect(lines(ifc, "IFCCLASSIFICATION")).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("ohne Räume keine Zonen und keine Geschoss-Mengen", () => {
|
||||
it("ohne Räume keine Zonen; Geschoss-Mengen nur aus der Konstruktionsfläche der Wände ([259])", () => {
|
||||
const ifc = exportIfcSpf({ ...sampleProject, rooms: [] });
|
||||
expect(lines(ifc, "IFCZONE")).toHaveLength(0);
|
||||
expect(ifc).not.toContain("Qto_BuildingStoreyBaseQuantities");
|
||||
expect(ifc).toContain("Qto_BuildingStoreyBaseQuantities");
|
||||
expect(ifc).toMatch(/IFCQUANTITYAREA\('NetFloorArea',\$,\$,0\.0,\$\)/);
|
||||
// Ohne Wände und Räume: gar keine Geschoss-Mengen.
|
||||
expect(exportIfcSpf({ ...sampleProject, rooms: [], walls: [], openings: [] })).not.toContain("Qto_BuildingStoreyBaseQuantities");
|
||||
});
|
||||
|
||||
it("GUIDs der Zonen und der übrigen Bauteile bleiben stabil (zweimal exportiert gleich)", () => {
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
// [259] IFC-Export für Fachplaner (Vorprojekt): alle drei Beispielprojekte gegen ifcopenshell — Schema/Express-Regeln/
|
||||
// Geometrie (`scripts/validate-ifc.py`) und die inhaltliche Prüfung `scripts/check-ifc-fachplaner.py` (räumliche
|
||||
// Struktur, jedes Bauteil genau einmal eingeordnet, Georeferenz lokal + IfcMapConversion EPSG:2056, Öffnungen gefüllt
|
||||
// und im Geschoss des Wirts, Räume mit Mengen/SIA-416-Kategorie, Wandschichten, Mengen ±1 % gegen die Geometrie,
|
||||
// Geschoss-GF mit Konstruktionsfläche, Kontext nur mit Option, keine 2D-Objektbibliothek als 3D-Körper).
|
||||
// Ohne Python/ifcopenshell übersprungen (CI installiert es).
|
||||
|
||||
import { describe, expect, it, vi } 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, ifcGuid, type IfcExportOptions } from "./exportIfc";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import { buildComplexSampleProject } from "../model/sampleProjectComplex";
|
||||
import { buildWettbewerbSampleProject } from "../model/sampleProjectWettbewerb";
|
||||
import type { Drawing2D, Project } from "../model/types";
|
||||
|
||||
const hasIfcOpenShell = spawnSync("python3", ["-c", "import ifcopenshell, ifcopenshell.validate, ifcopenshell.util.shape, _pytest"]).status === 0;
|
||||
|
||||
function writeIfc(name: string, ifc: string): string {
|
||||
const file = join(mkdtempSync(join(tmpdir(), "dossier-ifc-fp-")), `${name}.ifc`);
|
||||
writeFileSync(file, ifc);
|
||||
return file;
|
||||
}
|
||||
|
||||
interface Check {
|
||||
problems: string[];
|
||||
stats: Record<string, unknown> & { counts: Record<string, number>; context: number; far: number; known: string[]; map?: number[]; storeyQto?: Record<string, Record<string, number>> };
|
||||
}
|
||||
|
||||
/** Beide Prüfskripte; liefert die Kennwerte der inhaltlichen Prüfung. */
|
||||
function check(name: string, ifc: string, flags: string[]): Check {
|
||||
const file = writeIfc(name, ifc);
|
||||
const v = spawnSync("python3", ["scripts/validate-ifc.py", file], { encoding: "utf8", timeout: 400_000 });
|
||||
expect(`${v.stdout}\n${v.stderr}`).toContain(" 0 Befunde");
|
||||
const r = spawnSync("python3", ["scripts/check-ifc-fachplaner.py", file, "--json", ...flags], { encoding: "utf8", timeout: 400_000 });
|
||||
expect(r.stdout, r.stderr).not.toBe("");
|
||||
const out = JSON.parse(r.stdout) as Check;
|
||||
expect(out.problems).toEqual([]);
|
||||
expect(r.status).toBe(0);
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Export mit festem Zeitstempel (Vergleich zweier Dateien). */
|
||||
function exportAt(p: Project, options: IfcExportOptions = {}): string {
|
||||
vi.useFakeTimers();
|
||||
vi.setSystemTime(new Date("2026-11-14T10:00:00Z"));
|
||||
try {
|
||||
return exportIfcSpf(p, options);
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
}
|
||||
|
||||
describe.skipIf(!hasIfcOpenShell)("[259] IFC für Fachplaner (ifcopenshell)", { timeout: 900_000 }, () => {
|
||||
it("Musterhaus: Struktur, Mengen, Öffnungen", () => {
|
||||
const c = check("musterhaus", exportIfcSpf(sampleProject), []);
|
||||
expect(c.stats.counts.IfcWall).toBe(sampleProject.walls.length);
|
||||
expect(c.stats.context).toBe(0);
|
||||
});
|
||||
|
||||
it("Wettbewerb: georeferenziert (lokal + IfcMapConversion, ±0.00 = 441.30), Geschoss-GF mit Konstruktionsfläche", () => {
|
||||
const p = buildWettbewerbSampleProject();
|
||||
const c = check("wettbewerb", exportIfcSpf(p), ["--geo"]);
|
||||
expect(c.stats.far).toBeLessThan(1000);
|
||||
expect(c.stats.map).toEqual([p.geoAnchor!.lv95.e - p.geoAnchor!.model.x, p.geoAnchor!.lv95.n - p.geoAnchor!.model.y, 441.3]);
|
||||
const eg = c.stats.storeyQto!.Erdgeschoss;
|
||||
expect(eg.GrossFloorArea).toBeGreaterThan(eg.NetFloorArea);
|
||||
expect(c.stats.spaces).toBe(p.rooms!.length);
|
||||
});
|
||||
|
||||
it("Wettbewerb mit Kontext: Nachbargebäude am IfcSite, sonst nichts geändert", () => {
|
||||
const p = buildWettbewerbSampleProject();
|
||||
const c = check("wettbewerb-kontext", exportIfcSpf(p, { context: true }), ["--geo", "--context"]);
|
||||
expect(c.stats.context).toBe(p.context!.filter((o) => o.type === "importedMesh").length);
|
||||
});
|
||||
|
||||
it("komplex: Bogenkanten (Erker) mit Fläche/Volumen = Mengen, Kontext (Gelände + Nachbar) mit Option", () => {
|
||||
const p = buildComplexSampleProject();
|
||||
// Offen ([259]): Anbauwand OG Ost unter dem Pultdach (Netz mit Dach-Oberkante + Fenster) — ifcopenshell scheitert am
|
||||
// Abzug der Öffnung (30.4 statt 7.5 m³); Netz und Mengen stimmen mit dem 3D überein.
|
||||
const known = `--known=${ifcGuid(`${p.id}/wall/og-anbau-o`)}`;
|
||||
const k = check("komplex", exportIfcSpf(p), ["--geo", known]);
|
||||
expect(k.stats.known.length).toBeLessThanOrEqual(1);
|
||||
const c = check("komplex-kontext", exportIfcSpf(p, { context: true }), ["--geo", "--context", known]);
|
||||
expect(c.stats.counts.IfcGeographicElement).toBeGreaterThanOrEqual(1); // Gelände (TERRAIN)
|
||||
expect(c.stats.context).toBe(2); // Gelände + Nachbargebäude; Höhenlinien und Baugrube nicht
|
||||
});
|
||||
});
|
||||
|
||||
describe("[259] 2D-Objektbibliothek im IFC", () => {
|
||||
it("bleibt draussen: die Datei ist mit und ohne Objekte zeichengleich", () => {
|
||||
const objs: Drawing2D[] = [
|
||||
{ id: "wc", type: "drawing2d", levelId: "eg", categoryCode: "23", geom: { shape: "libobj", libId: "lib:wc-wand", at: { x: 1, y: 1 }, rotation: 0 } },
|
||||
{ id: "ti", type: "drawing2d", levelId: "eg", categoryCode: "22", geom: { shape: "libobj", libId: "lib:tisch-80x140", at: { x: 3, y: 2 }, rotation: 0.5, seed: 3 } },
|
||||
];
|
||||
const without = exportAt(sampleProject);
|
||||
const withObjs = exportAt({ ...sampleProject, drawings2d: [...sampleProject.drawings2d, ...objs] });
|
||||
expect(withObjs).toBe(without);
|
||||
expect(withObjs).not.toMatch(/IFCFURNITURE|IFCSANITARYTERMINAL|IFCFURNISHINGELEMENT/);
|
||||
});
|
||||
});
|
||||
@@ -307,10 +307,14 @@ describe("exportIfcSpf — IFC4-Export", () => {
|
||||
// Das Loch-Face-Set hat 48 CoordIndex-Tripel.
|
||||
const triCounts = faceSets.map((l) => (l.match(/\(\d+,\d+,\d+\)/g) ?? []).length);
|
||||
expect(triCounts).toContain(48);
|
||||
// Zugehörige Punktliste hat 144 Punkte (3er-Koordinaten-Tupel).
|
||||
const pointLists = lines.filter((l) => l.includes("=IFCCARTESIANPOINTLIST3D("));
|
||||
const ptCounts = pointLists.map((l) => (l.match(/\([^()]*,[^()]*,[^()]*\)/g) ?? []).length);
|
||||
expect(ptCounts).toContain(144);
|
||||
// [259] Zugehörige Punktliste verschweisst: jede Ecke einmal (vorher 144 = 3 je Dreieck).
|
||||
const hole = faceSets[triCounts.indexOf(48)];
|
||||
const listId = /IFCTRIANGULATEDFACESET\(#(\d+)/.exec(hole)![1];
|
||||
const list = lines.find((l) => l.startsWith(`#${listId}=`))!;
|
||||
const pts = list.match(/\([^()]*,[^()]*,[^()]*\)/g) ?? [];
|
||||
expect(new Set(pts).size).toBe(pts.length);
|
||||
expect(pts.length).toBeLessThan(144);
|
||||
expect(pts.length).toBeGreaterThanOrEqual(16); // Quader-Ecken + Loch-Ecken vorne/hinten
|
||||
// Keine dangling refs (der Kern-Invarianten-Check gilt auch mit Face-Sets).
|
||||
const { defined, referenced } = collectIds(spf);
|
||||
expect([...referenced].filter((id) => !defined.has(id))).toEqual([]);
|
||||
@@ -433,28 +437,26 @@ describe("exportIfcSpf — IFC4-Export", () => {
|
||||
expect(b.filter((g) => a.has(g))).toEqual([]);
|
||||
});
|
||||
|
||||
it("georeferenziert: mit geoAnchor werden die ECHTEN LV95-Koordinaten geschrieben (lokal bearbeitet, weltweit lagerichtig)", () => {
|
||||
// Modell lokal nahe (0,0), aber geoAnchor sagt: Modell (0,0) = LV95
|
||||
// (2600000,1200000). Der Export muss die Profil-/Punkt-Koordinaten auf die
|
||||
// echten Landeskoordinaten (Millionenbereich) verschoben schreiben.
|
||||
it("[259] georeferenziert: Geometrie bleibt lokal, IfcMapConversion trägt den LV95-Versatz und die Höhe von ±0.00", () => {
|
||||
// Modell lokal nahe (0,0), geoAnchor: Modell (2,1) = LV95 (2600002,1200001) ⇒ Ursprung = (2600000,1200000).
|
||||
// Vorher lag die ganze Geometrie in LV95-Millionen (Revit/Archicad warnen, Genauigkeit leidet).
|
||||
const local = fixtureProject();
|
||||
const withoutAnchor = exportIfcSpf(local);
|
||||
// Ohne Bezug: lokale Koordinaten, KEINE Millionenwerte im Text.
|
||||
expect(withoutAnchor).not.toMatch(/26000\d\d\./);
|
||||
expect(withoutAnchor).not.toContain("IFCMAPCONVERSION");
|
||||
|
||||
const geo: Project = {
|
||||
...local,
|
||||
geoAnchor: { lv95: { e: 2600000, n: 1200000 }, model: { x: 0, y: 0 } },
|
||||
geoAnchor: { lv95: { e: 2600002, n: 1200001 }, model: { x: 2, y: 1 } },
|
||||
referenceElevationMasl: 441.3,
|
||||
};
|
||||
const spf = exportIfcSpf(geo);
|
||||
// W1.start (0,0) -> LV95 (2600000,1200000); W2.end (5,4) -> (2600005,1200004).
|
||||
expect(spf).toContain("2600000.");
|
||||
expect(spf).toContain("1200000.");
|
||||
expect(spf).toContain("2600005.");
|
||||
// Koordinatensystem deklariert (IFC4): EPSG:2056 + Identitäts-Abbildung.
|
||||
// Nur der Versatz in Millionen, keine Koordinate.
|
||||
expect(spf.match(/\b2600000\.0\b/g)).toHaveLength(1);
|
||||
expect(spf).not.toMatch(/2600005\./);
|
||||
expect(spf).toContain("IFCPROJECTEDCRS('EPSG:2056'");
|
||||
expect(spf).toContain("IFCMAPCONVERSION(");
|
||||
expect(withoutAnchor).not.toContain("IFCMAPCONVERSION");
|
||||
expect(spf).toMatch(/IFCMAPCONVERSION\(#\d+,#\d+,2600000\.0,1200000\.0,441\.3,1\.0,0\.0,1\.0\);/);
|
||||
expect(spf).toMatch(/IFCSITE\(.*,441\.3,\$,\$\);/);
|
||||
// Struktur bleibt valide (keine dangling refs / Duplikate).
|
||||
const { defined, referenced, duplicates } = collectIds(spf);
|
||||
expect(duplicates).toEqual([]);
|
||||
|
||||
@@ -29,6 +29,11 @@ export interface IfcExportOptions {
|
||||
ebkph?: boolean;
|
||||
/** `categoryCode` (Ebene) des Modells als System „Dossier-Ebenen". */
|
||||
layerCodes?: boolean;
|
||||
/**
|
||||
* [259] Kontext mitgeben: Gelände (IfcGeographicElement TERRAIN) und Netze auf Umgebungsklassen wie Nachbargebäude
|
||||
* (IfcBuildingElementProxy „Kontext"), am IfcSite. Ohne Angabe nicht: Fachplaner wollen meist nur das Gebäude.
|
||||
*/
|
||||
context?: boolean;
|
||||
}
|
||||
|
||||
/** Deterministische 22-stellige IFC-GUID aus einem Namen (Rust, `ifc_export::ifc_guid`). */
|
||||
@@ -67,13 +72,13 @@ export function decodeExportFlat(bytes: Uint8Array): [Float64Array, string] {
|
||||
|
||||
/**
|
||||
* Baut aus einem Projekt einen vollständigen IFC-SPF-String (IFC4, oder IFC2x3 mit `options.schema`). Kein
|
||||
* Datei-IO. Leeres Projekt ⇒ valider Minimal-IFC (Project/Site/Building). Georeferenziert (`geoAnchor`):
|
||||
* Geometrie in LV95. Verlangt das geladene Format-Modul (`await loadFileio()`).
|
||||
* Datei-IO. Leeres Projekt ⇒ valider Minimal-IFC (Project/Site/Building). Georeferenziert (`geoAnchor`): Geometrie
|
||||
* lokal, IfcMapConversion mit dem LV95-Versatz und der Höhe von ±0.00 ([259]). Verlangt das geladene Format-Modul (`await loadFileio()`).
|
||||
*/
|
||||
export function exportIfcSpf(project: Project, options: IfcExportOptions = {}): string {
|
||||
const now = Date.now();
|
||||
const iso = new Date(now).toISOString().replace(/\.\d+Z$/, "");
|
||||
const args = [Math.floor(now / 1000), options.schema === "IFC2X3" ? 1 : 0, options.ebkph ? 1 : 0, options.layerCodes ? 1 : 0];
|
||||
const args = [Math.floor(now / 1000), options.schema === "IFC2X3" ? 1 : 0, options.ebkph ? 1 : 0, options.layerCodes ? 1 : 0, options.context ? 1 : 0];
|
||||
const [buf, strings] = decodeExportFlat(documentFor(project).queryBin("ifcExportData", args, iso));
|
||||
const m = fileio();
|
||||
const text = m.export_ifc_flat(buf, strings);
|
||||
|
||||
Reference in new issue
Block a user