Merge [B5][B4][70] IFC: eBKP-H-Hauptgruppen bzw. Modell-Ebenen als Klassifikation (Option), SIA-416-Zonen, Geschoss-GF/NGF; Import liest Klassifikation und Zonen

Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
Claude committed 2026-10-28 16:46:34 +00:00
commit a72ac89795
15 files changed
+945 -16

No files matched your search

+200
View File
@@ -0,0 +1,200 @@
// IFC für die Schweizer Praxis ([B5], 28.10.): Klassifikation (eBKP-H-Hauptgruppen, Ebene des Modells),
// SIA-416-Zonen und Geschoss-Kennwerte; Rundreise Export → Import und Prüfung mit ifcopenshell.
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 { EBKPH_GROUPS, ebkphGroup, layerClassification } from "./ifcClassification";
import { readIfcElements } from "../io/ifcElements";
import { classificationSuffix, ifcToImportedMeshes, readIfc } from "../io/ifcImport";
import { sampleProject } from "../model/sampleProject";
import type { Project, Room } from "../model/types";
const hasIfcOpenShell = spawnSync("python3", ["-c", "import ifcopenshell, ifcopenshell.util.classification, ifcopenshell.validate, _pytest"]).status === 0;
const lines = (ifc: string, ty: string): string[] => ifc.split("\n").filter((l) => new RegExp(`^#\\d+=${ty}\\(`).test(l));
/** Demo-Haus mit Räumen in mehreren SIA-Kategorien (zwei im EG, einer im OG). */
function houseWithRooms(): Project {
const base = sampleProject.rooms![0];
const at = (id: string, floorId: string, siaCategory: Room["siaCategory"], dx: number): Room => ({
...base,
id,
floorId,
siaCategory,
name: id,
boundary: base.boundary.map((p) => ({ x: p.x + dx, y: p.y })),
});
return {
...sampleProject,
rooms: [base, at("R2", "eg", "HNF", 6), at("R3", "eg", "VF", 12), at("R4", "og", "NNF", 0)],
};
}
describe("eBKP-H-Standardzuordnung", () => {
it("nur gesicherte Hauptgruppen, Tür und Raum bleiben unklassifiziert", () => {
expect(Object.keys(EBKPH_GROUPS)).toEqual(["C", "E", "F"]);
expect(ebkphGroup("wall")).toEqual({ code: "C", name: "Konstruktion Gebäude" });
expect(ebkphGroup("slab")?.code).toBe("C");
expect(ebkphGroup("column")?.code).toBe("C");
expect(ebkphGroup("stair")?.code).toBe("C");
expect(ebkphGroup("roof")).toEqual({ code: "F", name: "Bedachung Gebäude" });
expect(ebkphGroup("window")).toEqual({ code: "E", name: "Äussere Wandbekleidung Gebäude" });
expect(ebkphGroup("door")).toBeNull();
expect(ebkphGroup("space")).toBeNull();
});
it("Ebene: Name aus dem Ebenenbaum, unbekannter Code bleibt Code, ohne Code nichts", () => {
expect(layerClassification(sampleProject, "20")?.code).toBe("20");
expect(layerClassification(sampleProject, "25")?.name).toBe("Stützen"); // Unterkategorie
expect(layerClassification(sampleProject, "777")).toEqual({ code: "777", name: "777" });
expect(layerClassification(sampleProject, undefined)).toBeNull();
expect(layerClassification(sampleProject, " ")).toBeNull();
});
});
describe("IFC-Export: Zonen und Geschoss-Kennwerte (SIA 416)", () => {
it("je Kategorie eine IfcZone mit ihren Räumen, Kategorie und Fläche als Eigenschaft", () => {
const ifc = exportIfcSpf(houseWithRooms());
// HNF (R1, R2), VF (R3), NNF (R4) → 3 Zonen; 4 Räume in 3 Zuordnungen.
const zones = lines(ifc, "IFCZONE");
expect(zones).toHaveLength(3);
expect(zones.map((l) => l.match(/,'(HNF|NNF|VF)',\$,\$,/)?.[1]).sort()).toEqual(["HNF", "NNF", "VF"]);
expect(lines(ifc, "IFCRELASSIGNSTOGROUP")).toHaveLength(3);
expect(ifc).toContain("'CH_Zone'");
expect(ifc).toContain("'CH_Qto_SIA416'");
// Ohne Option keine Klassifikation.
expect(lines(ifc, "IFCCLASSIFICATION")).toHaveLength(0);
});
it("ohne Räume keine Zonen und keine Geschoss-Mengen", () => {
const ifc = exportIfcSpf({ ...sampleProject, rooms: [] });
expect(lines(ifc, "IFCZONE")).toHaveLength(0);
expect(ifc).not.toContain("Qto_BuildingStoreyBaseQuantities");
});
it("GUIDs der Zonen und der übrigen Bauteile bleiben stabil (zweimal exportiert gleich)", () => {
const a = exportIfcSpf(houseWithRooms());
const b = exportIfcSpf(houseWithRooms());
const guids = (t: string) => [...t.matchAll(/=IFC[A-Z]+\('([0-9A-Za-z_$]{22})'/g)].map((m) => m[1]);
// Zeitstempel im Kopf/OwnerHistory ändern sich nicht innerhalb derselben Sekunde zuverlässig → nur GUIDs.
expect(guids(a)).toEqual(guids(b));
expect(new Set(guids(a)).size).toBe(guids(a).length);
});
});
describe("IFC-Export: Klassifikation", () => {
it("eBKP-H: ein System, je Hauptgruppe eine Referenz und eine Beziehung; Türen und Räume ohne", () => {
const ifc = exportIfcSpf(houseWithRooms(), { ebkph: true });
const sys = lines(ifc, "IFCCLASSIFICATION");
expect(sys).toHaveLength(1);
expect(sys[0]).toContain("'SN 506 511:2020'");
expect(sys[0]).toContain("'eBKP-H'");
const refs = lines(ifc, "IFCCLASSIFICATIONREFERENCE");
// C (Wand, Decke, Treppe), F (Dach), E (Fenster) — Stützen hat das Demo-Haus nicht.
expect(refs.map((l) => l.match(/^#\d+=IFCCLASSIFICATIONREFERENCE\(\$,'(\w)'/)![1]).sort()).toEqual(["C", "E", "F"]);
expect(lines(ifc, "IFCRELASSOCIATESCLASSIFICATION")).toHaveLength(3);
});
it("Ebene des Modells als eigenes System, beide Systeme zusammen möglich", () => {
const ifc = exportIfcSpf(houseWithRooms(), { layerCodes: true, ebkph: true });
expect(lines(ifc, "IFCCLASSIFICATION")).toHaveLength(2);
expect(ifc).toContain("'Dossier-Ebenen'");
const codes = lines(ifc, "IFCCLASSIFICATIONREFERENCE").map((l) => l.match(/^#\d+=IFCCLASSIFICATIONREFERENCE\(\$,'(\w+)'/)![1]);
// Wände 20, Decke 30, Dach 31, Treppe 40, Türen/Fenster 21, Räume 60 + eBKP-H C, E, F.
for (const c of ["20", "21", "30", "31", "40", "60", "C", "E", "F"]) expect(codes, c).toContain(c);
});
it("ohne Bauteile (leeres Projekt) kein leeres System", () => {
const ifc = exportIfcSpf({ ...sampleProject, walls: [], openings: [], ceilings: [], roofs: [], stairs: [], rooms: [], columns: [], extrudedSolids: [] }, { ebkph: true, layerCodes: true });
expect(lines(ifc, "IFCCLASSIFICATION")).toHaveLength(0);
});
});
describe("Rundreise Export → Import", () => {
it("Klassifikation kommt an Bauteilen und am Mesh-Rest wieder an", async () => {
const ifc = exportIfcSpf(houseWithRooms(), { ebkph: true, layerCodes: true });
const bytes = new TextEncoder().encode(ifc);
const { products, elements } = await readIfcElements(bytes);
const wall = elements.walls[0];
expect(wall.classifications?.map((c) => `${c.system}:${c.code}`).sort()).toEqual(["Dossier-Ebenen:20", "eBKP-H:C"]);
expect(wall.classifications?.find((c) => c.system === "eBKP-H")?.name).toBe("Konstruktion Gebäude");
const window = elements.openings.find((o) => o.kind === "window")!;
expect(window.classifications?.map((c) => `${c.system}:${c.code}`).sort()).toEqual(["Dossier-Ebenen:21", "eBKP-H:E"]);
const door = elements.openings.find((o) => o.kind === "door")!;
expect(door.classifications?.map((c) => c.system)).toEqual(["Dossier-Ebenen"]);
// Dach bleibt Mesh, trägt aber seine Klassifikation.
const roof = products.find((p) => p.ifcClass === "IfcRoof")!;
expect(roof.classifications?.map((c) => c.code).sort()).toEqual(["31", "F"]);
// Räume: Kategorie bleibt (auch über die Zone).
expect(elements.spaces.map((s) => s.sia).sort()).toEqual(["HNF", "HNF", "NNF", "VF"]);
});
it("Mesh-Import: Klassifikation im Namen des Kontext-Objekts", async () => {
const ifc = exportIfcSpf(sampleProject, { ebkph: true });
const { products } = await readIfc(new TextEncoder().encode(ifc));
expect(products.find((p) => p.ifcClass === "IfcRoof")?.classifications?.[0]).toMatchObject({ system: "eBKP-H", code: "F" });
const roof = ifcToImportedMeshes(products, "haus.ifc", { group: "product" }).find((m) => m.layer === "IfcRoof")!;
expect(roof.name).toMatch(/ \[eBKP-H F\]$/);
expect(classificationSuffix(undefined)).toBe("");
expect(classificationSuffix([{ system: "", code: "214", name: null }])).toBe(" [214]");
});
});
describe.skipIf(!hasIfcOpenShell)("ifcopenshell", () => {
const PY = `
import json, sys
import ifcopenshell, ifcopenshell.util.classification as uc, ifcopenshell.util.element as ue
m = ifcopenshell.open(sys.argv[1])
out = {"classes": {}, "zones": {}, "storeys": {}}
for e in m.by_type("IfcProduct"):
refs = uc.get_references(e)
if refs:
out["classes"].setdefault(e.is_a(), []).extend(sorted(f"{uc.get_classification(r).Name}:{r.Identification}" for r in refs))
for z in m.by_type("IfcZone"):
members = [a.is_a() for rel in z.IsGroupedBy for a in rel.RelatedObjects]
psets = ue.get_psets(z)
out["zones"][z.Name] = {"members": members, "sia": psets["CH_Zone"]["SIA416"], "area": psets["CH_Qto_SIA416"]["NetFloorArea"]}
for s in m.by_type("IfcBuildingStorey"):
out["storeys"][s.Name] = ue.get_psets(s, qtos_only=True)
print(json.dumps(out))
`;
const run = (name: string, ifc: string) => {
const dir = mkdtempSync(join(tmpdir(), "dossier-ifc-cls-"));
const file = join(dir, `${name}.ifc`);
writeFileSync(file, ifc);
const r = spawnSync("python3", ["-c", PY, file], { encoding: "utf8", timeout: 120_000 });
expect(r.status, r.stderr).toBe(0);
const v = spawnSync("python3", ["scripts/validate-ifc.py", file], { encoding: "utf8", timeout: 180_000 });
return { read: JSON.parse(r.stdout), valid: { status: v.status, out: `${v.stdout}${v.stderr}` } };
};
it("liest Klassifikation, Zonen und Geschoss-Mengen; 0 Befunde", () => {
const { read, valid } = run("klassifiziert", exportIfcSpf(houseWithRooms(), { ebkph: true, layerCodes: true }));
expect(valid.out).toMatch(/ 0 Befunde/);
expect(valid.status).toBe(0);
expect(read.classes.IfcWall).toContain("eBKP-H:C");
expect(read.classes.IfcWall).toContain("Dossier-Ebenen:20");
expect(read.classes.IfcRoof).toContain("eBKP-H:F");
expect(read.classes.IfcWindow).toContain("eBKP-H:E");
expect(read.classes.IfcDoor).not.toContain("eBKP-H:E");
expect(Object.keys(read.zones).sort()).toEqual(["HNF", "NNF", "VF"]);
expect(read.zones.HNF.members).toEqual(["IfcSpace", "IfcSpace"]);
expect(read.zones.HNF.sia).toBe("HNF");
// Zwei gleich grosse Räume: doppelte Nettofläche des Einzelraums.
expect(read.zones.HNF.area).toBeCloseTo(read.zones.VF.area * 2, 6);
const eg = read.storeys["Erdgeschoss"] ?? Object.values(read.storeys)[0];
expect(eg.Qto_BuildingStoreyBaseQuantities.GrossFloorArea).toBeGreaterThan(0);
expect(eg.CH_Qto_SIA416.GF).toBeCloseTo(eg.Qto_BuildingStoreyBaseQuantities.GrossFloorArea, 9);
}, 300_000);
it("Standardexport (ohne Option) mit Zonen: 0 Befunde", () => {
const { valid } = run("standard", exportIfcSpf(houseWithRooms()));
expect(valid.out).toMatch(/ 0 Befunde/);
expect(valid.status).toBe(0);
}, 300_000);
});
+119 -1
View File
@@ -66,6 +66,18 @@
// IsExternal beim Dach und bei SIA-416-AGF-Räumen, Glasanteil der Glastür). Kein U-Wert,
// keine Tragfunktion: dafür hat das Modell keine Felder.
//
// Schweizer Praxis ([B5], 28.10.):
// • Zonen: je vorkommender SIA-416-Kategorie (HNF, NNF, VF, FF, KGF, AGF) eine IfcZone mit
// IfcRelAssignsToGroup der IfcSpaces, Eigenschaft `CH_Zone.SIA416` und Summe der Nettoflächen
// (`CH_Qto_SIA416.NetFloorArea`). Immer dabei, sobald Räume da sind.
// • Geschoss-Kennwerte: je Geschoss mit Räumen `Qto_BuildingStoreyBaseQuantities` (GrossFloorArea = GF,
// NetFloorArea = NGF nach SIA 416) und `CH_Qto_SIA416` mit allen Blatt-/Summenflächen (HNF … GF).
// • Klassifikation (Option, `ifcClassification.ts`): eBKP-H-Hauptgruppen je Bauteilart und/oder die
// Ebene des Modells als System „Dossier-Ebenen" — IfcClassification + IfcClassificationReference +
// IfcRelAssociatesClassification.
// • Achsraster: nicht exportiert — das Modell führt keine Raster-Ressource (nur die Regel „grid" der
// parametrischen Wände mit festem Abstand).
//
// GUIDs ([B5]/[10]): deterministisch aus `<Projekt-id>/<Art>/<id>[/<Zusatz>]` über einen
// 128-Bit-Hash + Standard-IFC-GUID-Kompression (Zeichensatz 0-9,A-Z,a-z,_,$) — zweimal
// exportieren gibt dieselben GlobalIds, BIM-Koordination (Solibri, BIMcollab) erkennt die
@@ -108,6 +120,18 @@ import {
type Qty,
} from "./ifcQuantities";
import { roofBaseElevation, roofGeometry } from "../geometry/roof";
import { SIA_CATEGORIES, balance, siaLabel, type SiaCategory } from "../geometry/roomArea";
import {
EBKPH_SYSTEM,
LAYER_SYSTEM,
ebkphGroup,
layerClassification,
type ClassificationSystem,
type ClassifiedKind,
type IfcExportOptions,
} from "./ifcClassification";
export type { IfcExportOptions } from "./ifcClassification";
/** Deterministische 22-stellige IFC-GUID aus einem Namen (Rust, `ifc_export.rs::ifc_guid`). */
export function ifcGuid(name: string): string {
@@ -133,6 +157,9 @@ const REC_END_SPACES = 8;
const REC_ROOF = 9;
const REC_COLUMN = 10;
const REC_END_COLUMNS = 11;
const REC_CLASSIFICATION = 12;
const REC_ZONE = 13;
const REC_ATTACH = 14;
/** Typart in der flachen Kodierung (0 Wand, 1 Decke, 2 Dach). */
type TypeKind = 0 | 1 | 2;
@@ -402,6 +429,26 @@ class FlatIfc {
this.nums.push(REC_END_COLUMNS);
}
/** Zone (IfcZone) mit den Räumen `spaceIds`; `key` ergibt die dauerhafte GUID. */
zone(key: string, name: string, longName: string, spaceIds: readonly string[], psets: PsetIn[]): void {
this.nums.push(REC_ZONE, this.str(key), this.str(name), this.str(longName), spaceIds.length);
for (const id of spaceIds) this.nums.push(this.str(id));
this.psets(psets);
}
/** Psets/Mengen an ein geschriebenes Bauteil (Schlüssel wie für seine GUID, z. B. `storey/<id>`). */
attach(key: string, psets: PsetIn[]): void {
this.nums.push(REC_ATTACH, this.str(key));
this.psets(psets);
}
/** Ein Klassifikationssystem mit Zuordnungen (Bauteil-Schlüssel → Code, Name der Referenz). */
classification(system: ClassificationSystem, refs: readonly { key: string; code: string; name: string }[]): void {
if (refs.length === 0) return;
this.nums.push(REC_CLASSIFICATION, this.str(system.name), this.str(system.source), this.str(system.edition), refs.length);
for (const r of refs) this.nums.push(this.str(r.key), this.str(r.code), this.str(r.name));
}
/** Argumente für die Rust-Bindung: `[Zahlenpuffer, Zeichenketten durch \0 getrennt]`. */
args(): [Float64Array, string] {
return [new Float64Array(this.nums), this.strings.join("\0")];
@@ -569,7 +616,7 @@ function qto(name: string, quantities: readonly Qty[]): PsetIn[] {
* File). Kein Datei-IO. Leeres Projekt ⇒ valider Minimal-IFC (Project/Site/Building, kein Crash).
* Verlangt das geladene Format-Modul (`await loadFileio()`).
*/
export function exportIfcSpf(projectIn: Project): string {
export function exportIfcSpf(projectIn: Project, options: IfcExportOptions = {}): string {
// Georeferenziert exportieren: ist ein Standort-Bezug gesetzt (geoAnchor),
// wird die gesamte Geometrie auf die ECHTEN LV95-Weltkoordinaten verschoben,
// damit die IFC-Datei in anderer Software lagerichtig sitzt — auch wenn das
@@ -603,6 +650,13 @@ export function exportIfcSpf(projectIn: Project): string {
storeys: floors.map((f, i) => ({ id: f.id, name: f.name, base: storeyBase[i] })),
});
// Klassifikation: je Bauteil, das geschrieben wird, Schlüssel (wie für die GUID), Art und Ebene sammeln;
// Rust überspringt Schlüssel ohne geschriebenes Bauteil (degenerierte Wand, Öffnung ohne Körper …).
const classified: { key: string; kind: ClassifiedKind; categoryCode: string | undefined }[] = [];
const classify = (key: string, kind: ClassifiedKind, categoryCode: string | undefined): void => {
classified.push({ key, kind, categoryCode });
};
const componentName = (componentId: string): string =>
project.components.find((c) => c.id === componentId)?.name ?? componentId;
const typeRef = (
@@ -687,6 +741,7 @@ export function exportIfcSpf(projectIn: Project): string {
if (bands.length === 0) continue; // degenerierte Wand / keine Geometrie
const cutouts = cutoutsOf(wall);
cutoutsByWallId.set(wall.id, cutouts);
classify(`wall/${wall.id}`, "wall", wall.categoryCode);
if (!bandsMatchOpenings(wall, bands, cutouts)) {
meshWalls.push({ wall, bands: bandsByWallId.get(wall.id)! });
continue;
@@ -761,6 +816,7 @@ export function exportIfcSpf(projectIn: Project): string {
if (ceiling.outline.length < 3) continue;
const { zBottom, zTop } = ceilingVerticalExtent(project, ceiling);
const structure = structureOf(ceiling.floorId);
classify(`slab/${ceiling.id}`, "slab", ceiling.categoryCode);
let name: string = ceiling.id;
let ty: TypeRefIn | null = null;
const psets: PsetIn[] = [];
@@ -792,6 +848,7 @@ export function exportIfcSpf(projectIn: Project): string {
const depth = c.zTop - c.zBottom;
if (!(depth > 1e-6)) continue;
const isDoor = opening.kind === "door";
classify(`fill/${opening.id}`, isDoor ? "door" : "window", opening.categoryCode);
const props: PropIn[] = [];
let psetName: string;
if (isDoor) {
@@ -829,6 +886,7 @@ export function exportIfcSpf(projectIn: Project): string {
if (footprint.length < 3) continue;
const { zBottom, zTop } = stairVerticalExtent(project, stair);
const structure = structureOf(stair.floorId);
classify(`stair/${stair.id}`, "stair", stair.categoryCode);
const predefined = stair.shape === "straight" ? "STRAIGHT_RUN_STAIR" : stair.shape === "spiral" ? "SPIRAL_STAIR" : "QUARTER_TURN_STAIR";
flat.stair(structure, stair.id, predefined, footprint, zBottom - baseOf(structure), zTop - zBottom, stairParts(project, stair, baseOf(structure)));
}
@@ -848,6 +906,7 @@ export function exportIfcSpf(projectIn: Project): string {
// Geschoss AGGREGIERT (IfcRelAggregates), nicht enthalten. Dazu Basismengen
// (Qto_SpaceBaseQuantities), die SIA-416-Kategorie als Eigenschaft und Pset_SpaceCommon
// (AGF = Aussengeschossfläche ⇒ aussen, alles andere innen).
const roomAreas: { id: string; floorId: string; category: SiaCategory; area: number }[] = [];
for (const room of project.rooms ?? []) {
if (room.boundary.length < 3) continue;
const structure = structureOf(room.floorId);
@@ -855,6 +914,8 @@ export function exportIfcSpf(projectIn: Project): string {
const height = floor?.floorHeight && floor.floorHeight > 0 ? floor.floorHeight : 2.5;
const external = room.siaCategory === "AGF";
const area = evaluateRoom(room.boundary, room.siaCategory);
roomAreas.push({ id: room.id, floorId: room.floorId, category: room.siaCategory, area: area.netArea });
classify(`space/${room.id}`, "space", room.categoryCode);
const common: PropIn[] = [];
if (room.stamp?.number) common.push(identifier("Reference", room.stamp.number));
common.push({ name: "IsExternal", bool: external });
@@ -874,6 +935,41 @@ export function exportIfcSpf(projectIn: Project): string {
}
flat.endSpaces();
// SIA 416 ([70], [B5]): je vorkommender Kategorie eine IfcZone mit den Räumen. Kategorie als Eigenschaft
// (`CH_Zone.SIA416`, die der Import wieder liest), Summe der Nettoflächen als Menge.
for (const cat of SIA_CATEGORIES) {
const members = roomAreas.filter((r) => r.category === cat);
if (members.length === 0) continue;
const net = members.reduce((a, r) => a + r.area, 0);
flat.zone(
`sia416/${cat}`,
cat,
siaLabel(cat),
members.map((r) => r.id),
[
{ name: "CH_Zone", props: [identifier("SIA416", cat)] },
{ name: "CH_Qto_SIA416", props: [{ name: "NetFloorArea", area: Math.max(0, net) }] },
],
);
}
// Geschoss-Kennwerte: GF/NGF als Basismenge des IfcBuildingStorey, alle SIA-416-Flächen als CH_Qto_SIA416.
for (const floor of floors) {
const rooms = roomAreas.filter((r) => r.floorId === floor.id);
if (rooms.length === 0) continue;
const bal = balance(rooms.map((r) => ({ category: r.category, area: r.area })));
const keys = ["HNF", "NNF", "NF", "VF", "FF", "NGF", "KGF", "AGF", "GF"] as const;
flat.attach(`storey/${floor.id}`, [
{
name: "Qto_BuildingStoreyBaseQuantities",
props: [
{ name: "GrossFloorArea", area: Math.max(0, bal.byKey.GF) },
{ name: "NetFloorArea", area: Math.max(0, bal.byKey.NGF) },
],
},
{ name: "CH_Qto_SIA416", props: keys.map((k): PropIn => ({ name: k, area: Math.max(0, bal.byKey[k]) })) },
]);
}
// ── Dächer → IfcRoof ───────────────────────────────────────────────────
// Dieselben geschlossenen Schicht-Meshes wie das 3D (`emitRoofs`: Dachflächen je Schicht,
// an First/Grat gehrt), zu EINEM Face-Set je Dach vereint. Modell-Koordinaten sind bereits
@@ -881,6 +977,7 @@ export function exportIfcSpf(projectIn: Project): string {
// positiv ist — nur dann ist das Face-Set als geschlossen markiert.
for (const roof of project.roofs ?? []) {
const structure = structureOf(roof.floorId);
classify(`roof/${roof.id}`, "roof", roof.categoryCode);
const positions: number[] = [];
const indices: number[] = [];
for (const mesh of emitRoofs({ ...project, roofs: [roof] })) {
@@ -928,6 +1025,7 @@ export function exportIfcSpf(projectIn: Project): string {
const { zBottom, zTop } = columnVerticalExtent(project, col);
if (!(zTop > zBottom)) continue;
const structure = structureOf(col.floorId);
classify(`column/${col.id}`, "column", col.categoryCode);
const label = columnLabel(col);
flat.column({
structure,
@@ -942,6 +1040,26 @@ export function exportIfcSpf(projectIn: Project): string {
}
flat.endColumns();
// ── Klassifikation (Optionen), am Ende: alle Bauteile sind geschrieben ──────────────
if (options.ebkph) {
flat.classification(
EBKPH_SYSTEM,
classified.flatMap((c) => {
const g = ebkphGroup(c.kind);
return g ? [{ key: c.key, code: g.code, name: g.name }] : [];
}),
);
}
if (options.layerCodes) {
flat.classification(
LAYER_SYSTEM,
classified.flatMap((c) => {
const l = layerClassification(project, c.categoryCode);
return l ? [{ key: c.key, code: l.code, name: l.name }] : [];
}),
);
}
const m = fileio();
const [buf, strings] = flat.args();
const text = m.export_ifc_flat(buf, strings);
+99
View File
@@ -0,0 +1,99 @@
// Klassifikation im IFC-Export ([B5], 28.10.): welche Klassifikationssysteme das Modell hergibt und die
// Standard-Zuordnung nach eBKP-H. Reine Tabellen/Funktionen, kein IFC-Schreiben (das macht Rust über
// den Datensatz CLASSIFICATION, `ifc_export.rs`).
//
// Was das Modell führt: KEINEN eBKP-H-/BKP-Code. `categoryCode` an Bauteilen ist die Grafik-Ebene
// („20" Wände, „30" Decken …, `LayerCategory`), kein Kostenschlüssel. Daher zwei getrennte Wege:
// • `layerCodes` — die Ebene des Modells als eigenes System „Dossier-Ebenen" (Code = `categoryCode`,
// Name = Ebenenname). Stammt aus dem Modell, behauptet keinen Standard.
// • `ebkph` — Standardzuordnung je Bauteilart auf eBKP-H-HAUPTGRUPPEN (siehe `EBKPH_GROUPS`).
//
// Quelle eBKP-H: CRB, „eBKP-H Elementbasierter Baukostenplan Hochbau", SN 506 511 (Ausgabe 2020).
// Gesichert sind nur die Hauptgruppen-Buchstaben und ihre Namen (A Grundstück, B Vorbereitung,
// C Konstruktion Gebäude, D Technik Gebäude, E Äussere Wandbekleidung Gebäude, F Bedachung Gebäude,
// G Ausbau Gebäude, H Nutzungsspezifische Anlagen Gebäude, I Umgebung Gebäude, J Ausstattung,
// V Planungsleistungen, W Nebenkosten, Y Reserve, Z Mehrwertsteuer). Keine Untergruppen (C01 …):
// die hängen von Konstruktionsart und Lage ab, die das Modell nicht trägt.
//
// Die Zuordnung ist deshalb bewusst grob und ein VORSCHLAG für die Kostenplanung, kein Ersatz für
// die Einordnung durch die Kostenplanerin:
// Wand → C (Wandkonstruktion; Aussen-/Innenbekleidung E/G und nichttragende Innenwände
// unterscheidet das Modell nicht — dafür fehlt ein Feld am Wandtyp)
// Decke → C (Deckenkonstruktion; Bodenbeläge/Unterdecken wären G)
// Stütze → C
// Treppe → C (Treppenkonstruktion; Belag/Geländer wären G)
// Dach → F (Dachaufbau mit Eindeckung/Abdichtung; die reine Tragkonstruktion wäre C)
// Fenster → E (Fenster der Gebäudehülle)
// Tür → keine (Aussentür E, Innentür G — nicht unterscheidbar, daher nicht geraten)
// Raum → keine (Räume sind Flächen, kein Bauteil; sie haben die SIA-416-Zonen)
import type { LayerCategory, Project } from "../model/types";
/** Optionen der Klassifikation im IFC-Export. */
export interface IfcExportOptions {
/** eBKP-H-Hauptgruppen je Bauteilart (Standardzuordnung, s. Dateikopf). */
ebkph?: boolean;
/** `categoryCode` (Ebene) des Modells als System „Dossier-Ebenen". */
layerCodes?: boolean;
}
/** Bauteilarten, die klassifiziert werden können. */
export type ClassifiedKind = "wall" | "slab" | "roof" | "column" | "stair" | "window" | "door" | "space";
/** Ein Klassifikationssystem für IfcClassification. */
export interface ClassificationSystem {
name: string;
source: string;
/** Ausgabe; leer = keine Angabe. */
edition: string;
}
export const EBKPH_SYSTEM: ClassificationSystem = {
name: "eBKP-H",
source: "CRB Schweizerische Zentralstelle für Baurationalisierung",
edition: "SN 506 511:2020",
};
export const LAYER_SYSTEM: ClassificationSystem = {
name: "Dossier-Ebenen",
source: "Dossier",
edition: "",
};
/** Gesicherte eBKP-H-Hauptgruppen (nur die hier verwendeten). */
export const EBKPH_GROUPS = {
C: "Konstruktion Gebäude",
E: "Äussere Wandbekleidung Gebäude",
F: "Bedachung Gebäude",
} as const;
const EBKPH_BY_KIND: Partial<Record<ClassifiedKind, keyof typeof EBKPH_GROUPS>> = {
wall: "C",
slab: "C",
column: "C",
stair: "C",
roof: "F",
window: "E",
};
/** eBKP-H-Hauptgruppe zur Bauteilart, oder `null` (Tür, Raum: nicht eindeutig). */
export function ebkphGroup(kind: ClassifiedKind): { code: string; name: string } | null {
const code = EBKPH_BY_KIND[kind];
return code ? { code, name: EBKPH_GROUPS[code] } : null;
}
function findLayer(list: readonly LayerCategory[], code: string): LayerCategory | undefined {
for (const c of list) {
if (c.code === code) return c;
const sub = c.children ? findLayer(c.children, code) : undefined;
if (sub) return sub;
}
return undefined;
}
/** Ebene (Code + Name) eines Bauteils; ohne Code `null`, ohne bekannte Ebene der Code als Name. */
export function layerClassification(project: Project, categoryCode: string | undefined): { code: string; name: string } | null {
const code = categoryCode?.trim();
if (!code) return null;
return { code, name: findLayer(project.layers, code)?.name ?? code };
}