[B5] IFC-Export: Schema-Option IFC4 | IFC2x3 (Coordination View 2.0)
Rust-Schreiber mit Schema im META (FLAT_VERSION 4): FILE_SCHEMA IFC2X3 und ViewDefinition, Netze als IfcFacetedBrep/IfcShellBasedSurfaceModel, IfcWallStandardCase mit LayerSetUsage, IfcDoorStyle/IfcWindowStyle, Dachschichten direkt am Dach, Georeferenz über IfcSite und ePSet_MapConversion/ePSet_ProjectedCRS, Attributlisten nach IFC2X3_TC1. Export-Dialog mit Schema-Wahl, CLI ifc --schema 2x3. Geprüft: ifcopenshell (IFC2X3, 0 Befunde, Volumen gleich IFC4), eigener Import liest beide gleich. Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
11 files changed
+933
-78
No files matched your search
+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