feat: harden CAD showcase skill and delivery pipeline

This commit is contained in:
2026-07-10 09:21:13 +08:00
parent a6856f903d
commit 8b1b1d5e89
53 changed files with 5405 additions and 1327 deletions

View File

@@ -9,6 +9,8 @@ import math
import sys
from pathlib import Path
import showcase_schema
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description=__doc__)
@@ -118,7 +120,15 @@ def segment_length(segment: dict) -> float:
return math.hypot(ex - sx, ey - sy)
def add_cad_pset(ifcopenshell, model, element, floor_key: str, category: str, segment: dict | None = None, source_index: int | None = None):
def add_cad_pset(
ifcopenshell,
model,
element,
floor_key: str,
category: str,
segment: dict | None = None,
source_index: int | None = None,
):
pset = ifcopenshell.api.pset.add_pset(model, product=element, name="CAD2BIM_Source")
props = {
"FloorKey": floor_key,
@@ -172,7 +182,17 @@ def add_slab(np, ifcopenshell, model, body_context, storey, floor_key: str, floo
return slab
def add_segment_element(ifcopenshell, model, body_context, storey, floor_key: str, floor: dict, category: str, segment: dict, source_index: int):
def add_segment_element(
ifcopenshell,
model,
body_context,
storey,
floor_key: str,
floor: dict,
category: str,
segment: dict,
source_index: int,
):
length = segment_length(segment)
if length < 0.05:
return None
@@ -276,9 +296,7 @@ def validate_ifc(ifcopenshell, path: Path, validate_geometry: bool) -> dict:
try:
geom.create_shape(settings, element)
except Exception as exc:
geometry_failures.append(
{"ifc_type": ifc_type, "name": element.Name, "error": str(exc)}
)
geometry_failures.append({"ifc_type": ifc_type, "name": element.Name, "error": str(exc)})
return {
"ifc_path": str(path),
@@ -310,7 +328,15 @@ def make_notes(report: dict) -> str:
"## Entity Counts",
"",
]
for key in ("IfcBuildingStorey", "IfcSlab", "IfcWall", "IfcColumn", "IfcBeam", "IfcPropertySet", "IfcExtrudedAreaSolid"):
for key in (
"IfcBuildingStorey",
"IfcSlab",
"IfcWall",
"IfcColumn",
"IfcBeam",
"IfcPropertySet",
"IfcExtrudedAreaSolid",
):
lines.append(f"- `{key}`: {counts.get(key, 0)}")
lines.extend(["", "## Storey Containment", ""])
for storey in report["storeys"]:
@@ -337,7 +363,11 @@ def make_notes(report: dict) -> str:
def main() -> int:
args = parse_args()
np, ifcopenshell = import_deps(Path(args.vendor_dir))
spec = json.loads(Path(args.spec).read_text(encoding="utf-8"))
spec = showcase_schema.normalize_spec(json.loads(Path(args.spec).read_text(encoding="utf-8")))
try:
showcase_schema.validate_spec(spec)
except showcase_schema.ValidationFailure as exc:
raise SystemExit(str(exc)) from exc
model, body_context, building = make_model(np, ifcopenshell, spec, args.project_name)
created = {"IfcSlab": 0, "IfcWall": 0, "IfcColumn": 0, "IfcBeam": 0}
limits = {
@@ -384,7 +414,12 @@ def main() -> int:
out_notes.parent.mkdir(parents=True, exist_ok=True)
out_report.write_text(json.dumps(report, ensure_ascii=False, indent=2), encoding="utf-8")
out_notes.write_text(make_notes(report), encoding="utf-8")
print(json.dumps({"ifc": str(out_ifc), "report": str(out_report), "notes": str(out_notes), "created": created}, ensure_ascii=False))
print(
json.dumps(
{"ifc": str(out_ifc), "report": str(out_report), "notes": str(out_notes), "created": created},
ensure_ascii=False,
)
)
return 0