2118 lines
86 KiB
Python
2118 lines
86 KiB
Python
#!/usr/bin/env python3
|
|
"""Regression test for the CAD extraction pipeline improvements.
|
|
|
|
Reproduces the failure modes found in the 主辅楼 run with synthetic DXF files:
|
|
- curtain-wall glazing locked inside INSERT blocks (incl. wrapper blocks and
|
|
blocks whose CJK names were mangled by DWG->DXF conversion)
|
|
- annotation layers (*-IDEN) matching broad category patterns like A-DOOR*
|
|
- floor-plan sheets exported as near-empty XREF shells
|
|
|
|
Run: python3 tests/test_extraction_pipeline.py
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import math
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
WORK = ROOT / "work" / "pipeline_test"
|
|
VENDOR = ROOT / "work" / "vendor"
|
|
|
|
sys.path.insert(0, str(VENDOR.resolve()))
|
|
import ezdxf # noqa: E402
|
|
|
|
FAILURES: list[str] = []
|
|
|
|
|
|
def check(name: str, condition: bool, detail: str = "") -> None:
|
|
status = "ok" if condition else "FAIL"
|
|
print(f"[{status}] {name}" + (f" — {detail}" if detail and not condition else ""))
|
|
if not condition:
|
|
FAILURES.append(name)
|
|
|
|
|
|
def make_plan_dxf(path: Path) -> None:
|
|
doc = ezdxf.new("R2010", setup=True)
|
|
for layer in (
|
|
"I-WALL",
|
|
"A-GLAZ-CURT",
|
|
"S-GRID-IDEN",
|
|
"A-ANNO-DIMS",
|
|
"A-DOOR-IDEN",
|
|
"A-DOOR",
|
|
"A-DETL",
|
|
):
|
|
doc.layers.add(layer)
|
|
msp = doc.modelspace()
|
|
|
|
# Walls: building outline 40m x 20m (mm units).
|
|
for start, end in [
|
|
((0, 0), (40000, 0)),
|
|
((40000, 0), (40000, 20000)),
|
|
((40000, 20000), (0, 20000)),
|
|
((0, 20000), (0, 0)),
|
|
]:
|
|
msp.add_line(start, end, dxfattribs={"layer": "I-WALL"})
|
|
|
|
# Filler detail lines so the sheet is not "near empty" (>60 entities).
|
|
for i in range(70):
|
|
msp.add_line((1000 + i * 100, 5000), (1000 + i * 100, 5500), dxfattribs={"layer": "A-DETL"})
|
|
|
|
# Case 1: glazing block whose CJK name was mangled in conversion
|
|
# ("系统嵌板" -> "系统嵌"); matched by the widened GLAZING_BLOCK_PATTERNS.
|
|
mangled = doc.blocks.new(name="系统嵌 - SZ_ _偏100_-407498-平图")
|
|
mangled.add_line((0, 0), (3000, 0), dxfattribs={"layer": "A-GLAZ-CURT"})
|
|
for i in range(4):
|
|
msp.add_blockref("系统嵌 - SZ_ _偏100_-407498-平图", (i * 4000, 0))
|
|
|
|
# Case 2: glazing nested inside a wrapper block whose name matches nothing.
|
|
panel = doc.blocks.new(name="PNL-407498")
|
|
panel.add_line((0, 0), (0, 3000), dxfattribs={"layer": "A-GLAZ-CURT"})
|
|
wrapper = doc.blocks.new(name="SHEET-WRAP")
|
|
for i in range(3):
|
|
wrapper.add_blockref("PNL-407498", (40000, i * 5000))
|
|
msp.add_blockref("SHEET-WRAP", (0, 0))
|
|
|
|
# Annotation block content that must stay out of the spec.
|
|
axis = doc.blocks.new(name="轴号-01")
|
|
axis.add_circle((0, 0), 400, dxfattribs={"layer": "S-GRID-IDEN"})
|
|
axis.add_line((0, 0), (0, 2000), dxfattribs={"layer": "A-ANNO-DIMS"})
|
|
for i in range(5):
|
|
msp.add_blockref("轴号-01", (i * 8000, 22000))
|
|
|
|
# Door tag lines (annotation) vs a real door swing arc.
|
|
msp.add_line((5000, 0), (5800, 0), dxfattribs={"layer": "A-DOOR-IDEN"})
|
|
msp.add_arc((10000, 0), 900, 0, 90, dxfattribs={"layer": "A-DOOR"})
|
|
|
|
doc.saveas(path)
|
|
|
|
|
|
def make_xref_shell_dxf(path: Path) -> None:
|
|
doc = ezdxf.new("R2010")
|
|
doc.layers.add("A-ANNO-SYMB")
|
|
doc.add_xref_def(filename="../XREF/roof_geometry.dwg", name="XREF-ROOF")
|
|
msp = doc.modelspace()
|
|
msp.add_text("屋顶平面图", dxfattribs={"layer": "A-ANNO-SYMB"})
|
|
for i in range(4):
|
|
msp.add_line((i * 1000, 0), (i * 1000, 500), dxfattribs={"layer": "A-ANNO-SYMB"})
|
|
doc.saveas(path)
|
|
|
|
|
|
def to_mif(text: str) -> str:
|
|
"""Encode CJK chars as AutoCAD MIF escapes (\\M+5XXXX, codepage 936)."""
|
|
out = []
|
|
for ch in text:
|
|
if ord(ch) > 127:
|
|
out.append("\\M+5%04X" % int.from_bytes(ch.encode("gbk"), "big"))
|
|
else:
|
|
out.append(ch)
|
|
return "".join(out)
|
|
|
|
|
|
def make_multiframe_dxf(path: Path, mif_titles: bool = False) -> None:
|
|
"""Chinese sheet-wall pattern: two floor-plan frames stacked 98100 apart.
|
|
|
|
Reproduces the 贝昂 failure mode: one DWG holds every floor; frames keep
|
|
their sheet positions, so extraction without per-frame offsets scatters
|
|
floors diagonally. mif_titles=True writes the plan titles as MIF escapes
|
|
(\\M+5....), the 黄桥文体中心 pattern that plain text matching misses.
|
|
"""
|
|
doc = ezdxf.new("R2010", setup=True)
|
|
for layer in ("WALL", "DOTE", "PUB_TEXT"):
|
|
doc.layers.add(layer)
|
|
msp = doc.modelspace()
|
|
pitch = 98100.0
|
|
|
|
def draw_frame(oy: float, title: str) -> None:
|
|
# walls: 40m x 20m outline + interior partitions (>=10 lines for clip refine)
|
|
outline = [
|
|
((0, 0), (40000, 0)),
|
|
((40000, 0), (40000, 20000)),
|
|
((40000, 20000), (0, 20000)),
|
|
((0, 20000), (0, 0)),
|
|
]
|
|
interior = [((8000 * i, 0), (8000 * i, 20000)) for i in range(1, 5)]
|
|
interior += [
|
|
((0, 10000), (40000, 10000)),
|
|
((12000, 5000), (28000, 5000)),
|
|
((20000, 0), (20000, 10000)),
|
|
((30000, 10000), (30000, 20000)),
|
|
]
|
|
for (sx, sy), (ex, ey) in outline + interior:
|
|
msp.add_line((sx, sy + oy), (ex, ey + oy), dxfattribs={"layer": "WALL"})
|
|
for i in range(6): # vertical grid lines on DOTE (TArch convention)
|
|
x = i * 8000
|
|
msp.add_line((x, -3000 + oy), (x, 26000 + oy), dxfattribs={"layer": "DOTE"})
|
|
for j in range(3): # horizontal grid lines
|
|
y = j * 10000
|
|
msp.add_line((-3000, y + oy), (46000, y + oy), dxfattribs={"layer": "DOTE"})
|
|
if mif_titles:
|
|
title = to_mif(title)
|
|
msp.add_text(title, height=800, dxfattribs={"layer": "PUB_TEXT"}).set_placement((18000, oy - 6000))
|
|
|
|
draw_frame(0.0, "一层平面图")
|
|
draw_frame(-pitch, "二层平面图")
|
|
# a SHORT MTEXT reaches the title-height probe (long ones are skipped
|
|
# first); MTEXT has char_height, not height — 27号 1#A crashed here
|
|
msp.add_mtext("备注说明", dxfattribs={"layer": "PUB_TEXT", "char_height": 500}).set_location((5000, 5000))
|
|
doc.saveas(path)
|
|
|
|
|
|
def make_blockgrid_dxf(path: Path) -> None:
|
|
"""黄桥 pattern: plan grids live inside anonymous wrapper blocks (A$C...),
|
|
NOT in modelspace, and floor wall bboxes differ (F2 covers half the
|
|
building). Clip-corner fallback then mis-aligns by 20 m in x; only
|
|
grid-line correlation via INSERT expansion recovers the true offset."""
|
|
doc = ezdxf.new("R2010", setup=True)
|
|
for layer in ("WALL", "DOTE", "PUB_TEXT"):
|
|
doc.layers.add(layer)
|
|
msp = doc.modelspace()
|
|
pitch = 98100.0
|
|
|
|
def draw_frame(index: int, oy: float, title: str, full_walls: bool) -> None:
|
|
wall_x0 = 0 if full_walls else 20000
|
|
outline = [
|
|
((wall_x0, 0), (40000, 0)),
|
|
((40000, 0), (40000, 20000)),
|
|
((40000, 20000), (wall_x0, 20000)),
|
|
((wall_x0, 20000), (wall_x0, 0)),
|
|
]
|
|
interior = [((8000 * i, 0), (8000 * i, 20000)) for i in range(3 if full_walls else 4, 5)]
|
|
interior += [
|
|
((wall_x0, 10000), (40000, 10000)),
|
|
((30000, 10000), (30000, 20000)),
|
|
((wall_x0 + 2000, 5000), (wall_x0 + 8000, 5000)),
|
|
((wall_x0 + 5000, 0), (wall_x0 + 5000, 10000)),
|
|
((34000, 0), (34000, 20000)),
|
|
((wall_x0 + 1000, 15000), (38000, 15000)),
|
|
]
|
|
for (sx, sy), (ex, ey) in outline + interior:
|
|
msp.add_line((sx, sy + oy), (ex, ey + oy), dxfattribs={"layer": "WALL"})
|
|
block = doc.blocks.new(name=f"A$CGRID{index}")
|
|
# real structural grids have varied bays; a perfectly uniform grid makes
|
|
# subset correlation ambiguous (any multiple of the pitch ties)
|
|
for x in (0, 8000, 19000, 26000, 37000, 40000):
|
|
block.add_line((x, -3000), (x, 26000), dxfattribs={"layer": "DOTE"})
|
|
for y in (0, 6000, 10000, 20000):
|
|
block.add_line((-3000, y), (46000, y), dxfattribs={"layer": "DOTE"})
|
|
msp.add_blockref(f"A$CGRID{index}", (0, oy))
|
|
msp.add_text(title, height=800, dxfattribs={"layer": "PUB_TEXT"}).set_placement((18000, oy - 6000))
|
|
|
|
draw_frame(1, 0.0, "一层平面图", True)
|
|
draw_frame(2, -pitch, "二层平面图", False)
|
|
doc.saveas(path)
|
|
|
|
|
|
def make_rowframe_dxf(path: Path, layer_prefix: str = "", grid_style: str = "lines") -> None:
|
|
"""Row layout (3#辅房 pattern): frames side by side, pitch on X, titles same row.
|
|
|
|
layer_prefix simulates design institutes that prefix every layer
|
|
(13号地块: A_WALL/A_DOTE) — exact-token axis patterns then miss the grid.
|
|
grid_style="ticks" draws 0.8 m axis-number stubs just OUTSIDE the wall
|
|
bbox instead of full-span grid lines (13号: no through grids at all) —
|
|
tick positions still fingerprint the grid for correlation.
|
|
"""
|
|
doc = ezdxf.new("R2010", setup=True)
|
|
wall_layer = f"{layer_prefix}WALL"
|
|
grid_layer = f"{layer_prefix}DOTE"
|
|
for layer in (wall_layer, grid_layer, "PUB_TEXT"):
|
|
doc.layers.add(layer)
|
|
msp = doc.modelspace()
|
|
pitch = 21000.0
|
|
|
|
def draw_frame(ox: float, title: str) -> None:
|
|
outline = [((0, 0), (8000, 0)), ((8000, 0), (8000, 16000)), ((8000, 16000), (0, 16000)), ((0, 16000), (0, 0))]
|
|
interior = [((0, 2000 * i), (8000, 2000 * i)) for i in range(1, 8)]
|
|
interior += [((4000, 0), (4000, 16000)), ((2000, 4000), (6000, 4000)), ((2000, 12000), (6000, 12000))]
|
|
for (sx, sy), (ex, ey) in outline + interior:
|
|
msp.add_line((sx + ox, sy), (ex + ox, ey), dxfattribs={"layer": wall_layer})
|
|
if grid_style == "ticks":
|
|
for x in (0, 2600, 4000, 8000): # varied bays; stubs beyond the wall bbox
|
|
msp.add_line((x + ox, -3200), (x + ox, -2400), dxfattribs={"layer": grid_layer})
|
|
msp.add_line((x + ox, 16400), (x + ox, 17200), dxfattribs={"layer": grid_layer})
|
|
for y in (0, 3400, 5000, 11000):
|
|
msp.add_line((-3200 + ox, y), (-2400 + ox, y), dxfattribs={"layer": grid_layer})
|
|
msp.add_line((8400 + ox, y), (9200 + ox, y), dxfattribs={"layer": grid_layer})
|
|
else:
|
|
for i in range(3):
|
|
x = i * 4000
|
|
msp.add_line((x + ox, -2500), (x + ox, 18500), dxfattribs={"layer": grid_layer})
|
|
for j in range(4):
|
|
y = j * 5000
|
|
msp.add_line((-2500 + ox, y), (10500 + ox, y), dxfattribs={"layer": grid_layer})
|
|
msp.add_text(title, height=700, dxfattribs={"layer": "PUB_TEXT"}).set_placement((2500 + ox, -5200))
|
|
|
|
draw_frame(0.0, "一层平面图")
|
|
draw_frame(pitch, "二层平面图")
|
|
doc.saveas(path)
|
|
|
|
|
|
def make_auxref_dxf(path: Path) -> None:
|
|
"""27号 2# pattern: an auxiliary structure ("非机动坡道一层平面图") sits ABOVE
|
|
the main plans, grabs the F1 key, and must NOT become the alignment
|
|
reference — its grid is unrelated to the tower's."""
|
|
doc = ezdxf.new("R2010", setup=True)
|
|
for layer in ("WALL", "DOTE", "PUB_TEXT"):
|
|
doc.layers.add(layer)
|
|
msp = doc.modelspace()
|
|
pitch = 98100.0
|
|
|
|
def draw_main(oy: float, title: str) -> None:
|
|
outline = [
|
|
((0, 0), (40000, 0)),
|
|
((40000, 0), (40000, 20000)),
|
|
((40000, 20000), (0, 20000)),
|
|
((0, 20000), (0, 0)),
|
|
]
|
|
interior = [((8000 * i, 0), (8000 * i, 20000)) for i in range(1, 5)]
|
|
interior += [((0, 10000), (40000, 10000)), ((12000, 5000), (28000, 5000))]
|
|
for (sx, sy), (ex, ey) in outline + interior:
|
|
msp.add_line((sx, sy + oy), (ex, ey + oy), dxfattribs={"layer": "WALL"})
|
|
for x in (0, 8000, 19000, 26000, 37000, 40000): # varied bays
|
|
msp.add_line((x, -3000 + oy), (x, 26000 + oy), dxfattribs={"layer": "DOTE"})
|
|
for y in (0, 6000, 10000, 20000):
|
|
msp.add_line((-3000, y + oy), (46000, y + oy), dxfattribs={"layer": "DOTE"})
|
|
msp.add_text(title, height=800, dxfattribs={"layer": "PUB_TEXT"}).set_placement((18000, oy - 6000))
|
|
|
|
# ramp frame on top: tiny 6x10 structure with its own (unrelated) grid
|
|
ry = pitch
|
|
for start, end in [
|
|
((0, 0), (6000, 0)),
|
|
((6000, 0), (6000, 10000)),
|
|
((6000, 10000), (0, 10000)),
|
|
((0, 10000), (0, 0)),
|
|
((0, 3300), (6000, 3300)),
|
|
((0, 7100), (6000, 7100)),
|
|
((2500, 0), (2500, 10000)),
|
|
]:
|
|
msp.add_line((start[0], start[1] + ry), (end[0], end[1] + ry), dxfattribs={"layer": "WALL"})
|
|
for x in (0, 2500, 6000):
|
|
msp.add_line((x, ry - 2600), (x, ry + 12600), dxfattribs={"layer": "DOTE"})
|
|
for y in (0, 3300, 10000):
|
|
msp.add_line((-2600, y + ry), (8600, y + ry), dxfattribs={"layer": "DOTE"})
|
|
msp.add_text("非机动坡道一层平面图", height=800, dxfattribs={"layer": "PUB_TEXT"}).set_placement((2000, ry - 6000))
|
|
|
|
draw_main(0.0, "一层平面图")
|
|
draw_main(-pitch, "二层平面图")
|
|
doc.saveas(path)
|
|
|
|
|
|
def make_nogrid_dxf(path: Path) -> None:
|
|
"""27号 2#/13号 pattern: frames carry NO axis geometry at all, and floor wall
|
|
bboxes differ (F2 covers half the building) — clip-corner fallback is
|
|
off by 20 m in x; only wall-profile correlation recovers the offset."""
|
|
doc = ezdxf.new("R2010", setup=True)
|
|
for layer in ("WALL", "PUB_TEXT"):
|
|
doc.layers.add(layer)
|
|
msp = doc.modelspace()
|
|
pitch = 98100.0
|
|
|
|
def draw_frame(oy: float, title: str, full_walls: bool) -> None:
|
|
wall_x0 = 0 if full_walls else 20000
|
|
outline = [
|
|
((wall_x0, 0), (40000, 0)),
|
|
((40000, 0), (40000, 20000)),
|
|
((40000, 20000), (wall_x0, 20000)),
|
|
((wall_x0, 20000), (wall_x0, 0)),
|
|
]
|
|
# varied interior bays shared by both floors (the correlation fingerprint)
|
|
interior = [
|
|
((26000, 0), (26000, 20000)),
|
|
((31000, 0), (31000, 20000)),
|
|
((37000, 0), (37000, 20000)),
|
|
((20000, 0), (20000, 20000)),
|
|
((23000, 0), (23000, 20000)),
|
|
((20000, 6000), (40000, 6000)),
|
|
((20000, 9400), (40000, 9400)),
|
|
((20000, 15000), (40000, 15000)),
|
|
]
|
|
if full_walls:
|
|
interior += [
|
|
((6000, 0), (6000, 20000)),
|
|
((11000, 0), (11000, 20000)),
|
|
((0, 6000), (20000, 6000)),
|
|
((0, 15000), (20000, 15000)),
|
|
]
|
|
for (sx, sy), (ex, ey) in outline + interior:
|
|
msp.add_line((sx, sy + oy), (ex, ey + oy), dxfattribs={"layer": "WALL"})
|
|
msp.add_text(title, height=800, dxfattribs={"layer": "PUB_TEXT"}).set_placement((18000, oy - 6000))
|
|
|
|
draw_frame(0.0, "一层平面图", True)
|
|
draw_frame(-pitch, "二层平面图", False)
|
|
doc.saveas(path)
|
|
|
|
|
|
def make_blocktitle_dxf(path: Path) -> None:
|
|
"""13号 cached-XREF pattern: each sheet lives in ONE block (msp = INSERT
|
|
stubs), so plan TITLES are inside blocks too — title scan must expand."""
|
|
doc = ezdxf.new("R2010", setup=True)
|
|
for layer in ("WALL", "DOTE", "PUB_TEXT"):
|
|
doc.layers.add(layer)
|
|
msp = doc.modelspace()
|
|
pitch = 98100.0
|
|
|
|
def make_sheet(idx: int, title: str) -> str:
|
|
blk = doc.blocks.new(name=f"X-00-00{idx}")
|
|
outline = [
|
|
((0, 0), (40000, 0)),
|
|
((40000, 0), (40000, 20000)),
|
|
((40000, 20000), (0, 20000)),
|
|
((0, 20000), (0, 0)),
|
|
]
|
|
interior = [((8000 * i, 0), (8000 * i, 20000)) for i in range(1, 5)]
|
|
interior += [((0, 10000), (40000, 10000)), ((12000, 5000), (28000, 5000))]
|
|
for (sx, sy), (ex, ey) in outline + interior:
|
|
blk.add_line((sx, sy), (ex, ey), dxfattribs={"layer": "WALL"})
|
|
for x in (0, 8000, 19000, 26000, 37000, 40000):
|
|
blk.add_line((x, -3000), (x, 26000), dxfattribs={"layer": "DOTE"})
|
|
for y in (0, 6000, 10000, 20000):
|
|
blk.add_line((-3000, y), (46000, y), dxfattribs={"layer": "DOTE"})
|
|
blk.add_text(title, height=800, dxfattribs={"layer": "PUB_TEXT"}).set_placement((18000, -6000))
|
|
return blk.name
|
|
|
|
msp.add_blockref(make_sheet(1, "一层平面图"), (0, 0))
|
|
msp.add_blockref(make_sheet(2, "二层平面图"), (0, -pitch))
|
|
doc.saveas(path)
|
|
|
|
|
|
def make_titleblock_dxf(path: Path) -> None:
|
|
"""13号 加长A0 pattern: one ELONGATED sheet holds two towers far apart; the
|
|
pitch-sized rough window sees only the tower above the title and the clip
|
|
truncates the sheet. Title-block INSERTs (A0+0.5_V1 …) carry the true
|
|
frame rect and must define the clip."""
|
|
doc = ezdxf.new("R2010", setup=True)
|
|
for layer in ("WALL", "DOTE", "PUB_TEXT", "TK"):
|
|
doc.layers.add(layer)
|
|
msp = doc.modelspace()
|
|
pitch = 98100.0
|
|
|
|
def tower(ox: float, oy: float, bays: tuple) -> None:
|
|
outline = [
|
|
((ox, oy), (ox + 40000, oy)),
|
|
((ox + 40000, oy), (ox + 40000, oy + 20000)),
|
|
((ox + 40000, oy + 20000), (ox, oy + 20000)),
|
|
((ox, oy + 20000), (ox, oy)),
|
|
]
|
|
for (sx, sy), (ex, ey) in outline:
|
|
msp.add_line((sx, sy), (ex, ey), dxfattribs={"layer": "WALL"})
|
|
for b in bays:
|
|
msp.add_line((ox + b, oy), (ox + b, oy + 20000), dxfattribs={"layer": "WALL"})
|
|
for x in (0, 8000, 19000, 26000, 37000, 40000):
|
|
msp.add_line((ox + x, oy - 3000), (ox + x, oy + 26000), dxfattribs={"layer": "DOTE"})
|
|
for y in (0, 6000, 10000, 20000):
|
|
msp.add_line((ox - 3000, oy + y), (ox + 43000, oy + y), dxfattribs={"layer": "DOTE"})
|
|
|
|
def frame_block(name: str, w: float, h: float) -> str:
|
|
if name not in doc.blocks:
|
|
blk = doc.blocks.new(name=name)
|
|
blk.add_lwpolyline([(0, 0), (w, 0), (w, h), (0, h)], close=True, dxfattribs={"layer": "TK"})
|
|
return name
|
|
|
|
# F1: elongated sheet, twin towers 110 m apart inside ONE frame
|
|
tower(0.0, 0.0, (8000, 19000, 26000))
|
|
tower(110000.0, 0.0, (5000, 14000, 33000))
|
|
msp.add_blockref(frame_block("A0+0.5_V1", 179000, 85100), (-12000, -22000))
|
|
msp.add_text("一层平面图", height=800, dxfattribs={"layer": "PUB_TEXT"}).set_placement((18000, -9000))
|
|
# F2: normal sheet below, single tower
|
|
tower(0.0, -pitch, (8000, 19000, 26000))
|
|
msp.add_blockref(frame_block("A1_V1", 85100, 60400), (-12000, -pitch - 22000))
|
|
msp.add_text("二层平面图", height=800, dxfattribs={"layer": "PUB_TEXT"}).set_placement((18000, -pitch - 9000))
|
|
doc.saveas(path)
|
|
|
|
|
|
def make_ladder_dxf(path: Path) -> None:
|
|
"""Storey-table automation: a multi-floor title (三、五层平面图) must expand
|
|
into per-floor config entries, and the 剖面图 frame's DIM_ELEV ladder must
|
|
yield per-frame ladders + a uniform-step storey suggestion."""
|
|
doc = ezdxf.new("R2010", setup=True)
|
|
for layer in ("WALL", "DOTE", "PUB_TEXT", "DIM_ELEV"):
|
|
doc.layers.add(layer)
|
|
msp = doc.modelspace()
|
|
pitch = 98100.0
|
|
|
|
def draw_frame(oy: float, title: str) -> None:
|
|
outline = [
|
|
((0, 0), (40000, 0)),
|
|
((40000, 0), (40000, 20000)),
|
|
((40000, 20000), (0, 20000)),
|
|
((0, 20000), (0, 0)),
|
|
]
|
|
interior = [((8000 * i, 0), (8000 * i, 20000)) for i in range(1, 5)]
|
|
interior += [((0, 10000), (40000, 10000))]
|
|
for (sx, sy), (ex, ey) in outline + interior:
|
|
msp.add_line((sx, sy + oy), (ex, ey + oy), dxfattribs={"layer": "WALL"})
|
|
for x in (0, 8000, 19000, 26000, 37000, 40000):
|
|
msp.add_line((x, -3000 + oy), (x, 26000 + oy), dxfattribs={"layer": "DOTE"})
|
|
for y in (0, 6000, 10000, 20000):
|
|
msp.add_line((-3000, y + oy), (46000, y + oy), dxfattribs={"layer": "DOTE"})
|
|
msp.add_text(title, height=800, dxfattribs={"layer": "PUB_TEXT"}).set_placement((18000, oy - 6000))
|
|
|
|
draw_frame(0.0, "一层平面图")
|
|
draw_frame(-pitch, "三、五层平面图")
|
|
draw_frame(-2 * pitch, "十一至十四层平面图")
|
|
# section frame with an elevation ladder: 0..21 step 3.0 + noise values
|
|
sx0 = 120000.0
|
|
msp.add_text("1-1剖面图", height=800, dxfattribs={"layer": "PUB_TEXT"}).set_placement((sx0 + 8000, -6000))
|
|
for k in range(8):
|
|
v = 3.0 * k
|
|
msp.add_text(f"{v:.3f}", height=350, dxfattribs={"layer": "DIM_ELEV"}).set_placement(
|
|
(sx0 + 2000, 1000 + k * 3000)
|
|
)
|
|
for noise in ("0.150", "22.500"):
|
|
msp.add_text(noise, height=350, dxfattribs={"layer": "DIM_ELEV"}).set_placement((sx0 + 6000, 2000))
|
|
doc.saveas(path)
|
|
|
|
|
|
def make_mixedrow_dxf(path: Path) -> None:
|
|
"""27号 1#B pattern: main plans stack in a COLUMN, but a couple of stray
|
|
same-row detail titles fabricate a bogus (much smaller) x-pitch. clip_w
|
|
then shrinks to that x-pitch and the refine window drops the building's
|
|
second wing (unit-block plans: one wing's midpoint falls outside)."""
|
|
doc = ezdxf.new("R2010", setup=True)
|
|
for layer in ("WALL", "DOTE", "PUB_TEXT"):
|
|
doc.layers.add(layer)
|
|
msp = doc.modelspace()
|
|
pitch = 98100.0
|
|
|
|
def draw_frame(oy: float, title: str) -> None:
|
|
# two wings: x 0..30000 and 50000..80000 (gap between); title under the LEFT wing
|
|
for x0 in (0.0, 50000.0):
|
|
outline = [
|
|
((x0, 0), (x0 + 30000, 0)),
|
|
((x0 + 30000, 0), (x0 + 30000, 14000)),
|
|
((x0 + 30000, 14000), (x0, 14000)),
|
|
((x0, 14000), (x0, 0)),
|
|
]
|
|
interior = [((x0 + d, 0), (x0 + d, 14000)) for d in (6000, 13000, 21000)]
|
|
for (sx, sy), (ex, ey) in outline + interior:
|
|
msp.add_line((sx, sy + oy), (ex, ey + oy), dxfattribs={"layer": "WALL"})
|
|
for x in (0, 8000, 19000, 30000, 50000, 61000, 72000, 80000):
|
|
msp.add_line((x, -3000 + oy), (x, 17000 + oy), dxfattribs={"layer": "DOTE"})
|
|
for y in (0, 5200, 9000, 14000):
|
|
msp.add_line((-3000, y + oy), (83000, y + oy), dxfattribs={"layer": "DOTE"})
|
|
msp.add_text(title, height=800, dxfattribs={"layer": "PUB_TEXT"}).set_placement((12000, oy - 6000))
|
|
|
|
draw_frame(0.0, "一层平面图")
|
|
draw_frame(-pitch, "二层平面图")
|
|
# stray detail frames titled 平面图 in ONE row of their own, 15 m apart:
|
|
# their x-gap is the only same-row gap and must NOT define the clip width
|
|
# for the main column (real 1#B: 非机动坡道 frames row made pitch_x≈15.8k)
|
|
sy = -250000.0
|
|
for i, title in enumerate(("电梯机房平面图", "水箱间平面图")):
|
|
ox = 300000.0 + i * 15000.0
|
|
for start, end in [
|
|
((ox, sy), (ox + 8000, sy)),
|
|
((ox + 8000, sy), (ox + 8000, sy + 6000)),
|
|
((ox + 8000, sy + 6000), (ox, sy + 6000)),
|
|
((ox, sy + 6000), (ox, sy)),
|
|
((ox + 4000, sy), (ox + 4000, sy + 6000)),
|
|
((ox, sy + 3000), (ox + 8000, sy + 3000)),
|
|
((ox + 2000, sy), (ox + 2000, sy + 6000)),
|
|
((ox + 6000, sy + 3000), (ox + 6000, sy + 6000)),
|
|
((ox + 1000, sy + 1500), (ox + 7000, sy + 1500)),
|
|
((ox + 1000, sy + 4500), (ox + 7000, sy + 4500)),
|
|
]:
|
|
msp.add_line(start, end, dxfattribs={"layer": "WALL"})
|
|
msp.add_text(title, height=800, dxfattribs={"layer": "PUB_TEXT"}).set_placement((ox + 1000, sy - 6000))
|
|
doc.saveas(path)
|
|
|
|
|
|
def run(cmd: list[str]) -> subprocess.CompletedProcess:
|
|
return subprocess.run(cmd, cwd=ROOT, text=True, capture_output=True)
|
|
|
|
|
|
def main() -> int:
|
|
if WORK.exists():
|
|
shutil.rmtree(WORK)
|
|
dxf_dir = WORK / "dxf"
|
|
dxf_dir.mkdir(parents=True)
|
|
make_plan_dxf(dxf_dir / "plan.dxf")
|
|
make_xref_shell_dxf(dxf_dir / "roof.dxf")
|
|
|
|
# cached-xref sheet (13号 pattern): msp holds only INSERT stubs, the real
|
|
# content is CACHED as a block definition inside the same file
|
|
cx_doc = ezdxf.new("R2010")
|
|
cx_doc.layers.add("WALL")
|
|
cx_blk = cx_doc.blocks.new(name="X-00-0011")
|
|
for i in range(300):
|
|
cx_blk.add_line((i * 100, 0), (i * 100, 5000), dxfattribs={"layer": "WALL"})
|
|
cx_msp = cx_doc.modelspace()
|
|
cx_msp.add_text("总平面图", dxfattribs={"layer": "PUB_TEXT"})
|
|
for i in range(3):
|
|
cx_msp.add_blockref("X-00-0011", (i * 50000, 0))
|
|
cx_doc.saveas(dxf_dir / "cachedxref.dxf")
|
|
|
|
# --- cad_dxf_report: XREF shell must be flagged, plan must not ---
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/cad_dxf_report.py",
|
|
"--input",
|
|
str(dxf_dir),
|
|
"--work",
|
|
str(WORK / "report_work"),
|
|
"--output",
|
|
str(WORK / "read_report"),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
check("cad_dxf_report runs", proc.returncode == 0, proc.stderr[-800:])
|
|
report = json.loads((WORK / "read_report" / "cad_read_report.json").read_text(encoding="utf-8"))
|
|
by_file = {item["file"]: item for item in report["files"]}
|
|
roof_warnings = " ".join(by_file.get("roof.dxf", {}).get("warnings", []))
|
|
check("roof.dxf flagged as XREF shell", "likely_xref_shell" in roof_warnings, roof_warnings)
|
|
check(
|
|
"plan.dxf has no warnings",
|
|
not by_file.get("plan.dxf", {}).get("warnings"),
|
|
str(by_file.get("plan.dxf", {}).get("warnings")),
|
|
)
|
|
cx_warnings = " ".join(by_file.get("cachedxref.dxf", {}).get("warnings", []))
|
|
check(
|
|
"cached-xref stub sheet points at expand_blocks",
|
|
"cached_xref_content" in cx_warnings and "expand_blocks" in cx_warnings,
|
|
cx_warnings,
|
|
)
|
|
check(
|
|
"cached-xref not misreported as re-export ask",
|
|
"likely_xref_shell" not in cx_warnings and "near_empty" not in cx_warnings,
|
|
cx_warnings,
|
|
)
|
|
md = (WORK / "read_report" / "cad_read_report.md").read_text(encoding="utf-8")
|
|
check("markdown has warnings section", "Warnings (resolve before modeling)" in md)
|
|
|
|
# --- derive with default config: glazing captured from blocks ---
|
|
config = {
|
|
"scale": 0.001,
|
|
"drawings": [{"file": "plan.dxf", "floors": [{"key": "1F", "name": "首层", "z": 0.0, "height": 4.2}]}],
|
|
}
|
|
config_path = WORK / "config.json"
|
|
config_path.write_text(json.dumps(config, ensure_ascii=False), encoding="utf-8")
|
|
spec_path = WORK / "building_spec.json"
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/derive_showcase_spec.py",
|
|
"--dxf-dir",
|
|
str(dxf_dir),
|
|
"--config",
|
|
str(config_path),
|
|
"--out",
|
|
str(spec_path),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
check("derive runs", proc.returncode == 0, proc.stderr[-800:])
|
|
spec = json.loads(spec_path.read_text(encoding="utf-8"))
|
|
segments = spec["floors"]["1F"]["segments"]
|
|
glazing_layers = {seg.get("layer") for seg in segments.get("glazing", [])}
|
|
check("glazing captured from blocks", len(segments.get("glazing", [])) >= 2, str(segments.get("glazing")))
|
|
check("glazing came from A-GLAZ-CURT", glazing_layers <= {"A-GLAZ-CURT"}, str(glazing_layers))
|
|
# Both capture paths must contribute: 4 mangled-name inserts are horizontal
|
|
# (y const), 3 probe-only nested panels are vertical (x const at 40m).
|
|
has_vertical = any(abs(seg["start"][0] - seg["end"][0]) < 1e-6 for seg in segments.get("glazing", []))
|
|
check("probe path captured nested wrapper glazing", has_vertical)
|
|
check("walls captured", len(segments.get("walls", [])) >= 4)
|
|
check("door swing arc classified as doors", len(segments.get("doors", [])) > 0)
|
|
door_layers = {seg.get("layer") for seg in segments.get("doors", [])}
|
|
check("A-DOOR-IDEN excluded from doors", "A-DOOR-IDEN" not in door_layers, str(door_layers))
|
|
all_layers = {seg.get("layer") for segs in segments.values() for seg in segs}
|
|
check("S-GRID-IDEN/A-ANNO-DIMS not extracted", not ({"S-GRID-IDEN", "A-ANNO-DIMS"} & all_layers), str(all_layers))
|
|
|
|
# --- audit with default config: gates pass, exit 0 ---
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/audit_showcase_extraction.py",
|
|
"--dxf-dir",
|
|
str(dxf_dir),
|
|
"--config",
|
|
str(config_path),
|
|
"--spec",
|
|
str(spec_path),
|
|
"--out",
|
|
str(WORK / "audit_ok"),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
check("audit (glazing captured) exits 0", proc.returncode == 0, proc.stderr[-800:])
|
|
audit = json.loads((WORK / "audit_ok" / "extraction_audit.json").read_text(encoding="utf-8"))
|
|
gates = {gate["name"]: gate["status"] for gate in audit["gates"]}
|
|
check("glazing gate PASS", gates.get("glazing_captured") == "PASS", str(gates))
|
|
check("annotation gate PASS", gates.get("no_annotation_layers_classified") == "PASS", str(gates))
|
|
locked = audit["coverage"]["block_locked_length_meters"]
|
|
check("block-locked length reported", locked > 0, str(audit["coverage"]))
|
|
|
|
# --- derive+audit with expansion disabled: glazing gate must FAIL (exit 3) ---
|
|
config_off = dict(config)
|
|
config_off.update({"classify_block_contents": False, "expand_glazing_blocks": False})
|
|
config_off_path = WORK / "config_off.json"
|
|
config_off_path.write_text(json.dumps(config_off, ensure_ascii=False), encoding="utf-8")
|
|
spec_off_path = WORK / "building_spec_off.json"
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/derive_showcase_spec.py",
|
|
"--dxf-dir",
|
|
str(dxf_dir),
|
|
"--config",
|
|
str(config_off_path),
|
|
"--out",
|
|
str(spec_off_path),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
check("derive (expansion off) runs", proc.returncode == 0, proc.stderr[-800:])
|
|
spec_off = json.loads(spec_off_path.read_text(encoding="utf-8"))
|
|
check(
|
|
"expansion off reproduces glazing=0",
|
|
len(spec_off["floors"]["1F"]["segments"].get("glazing", [])) == 0,
|
|
)
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/audit_showcase_extraction.py",
|
|
"--dxf-dir",
|
|
str(dxf_dir),
|
|
"--config",
|
|
str(config_off_path),
|
|
"--spec",
|
|
str(spec_off_path),
|
|
"--out",
|
|
str(WORK / "audit_fail"),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
check("audit gate failure exits 3", proc.returncode == 3, f"rc={proc.returncode} {proc.stderr[-400:]}")
|
|
audit_fail = json.loads((WORK / "audit_fail" / "extraction_audit.json").read_text(encoding="utf-8"))
|
|
gates_fail = {gate["name"]: gate["status"] for gate in audit_fail["gates"]}
|
|
check("glazing gate FAIL when blocks unexpanded", gates_fail.get("glazing_captured") == "FAIL", str(gates_fail))
|
|
|
|
# --- multi-frame sheet: detect frames, grid-align, alignment gate ---
|
|
mf_path = dxf_dir / "multiframe.dxf"
|
|
make_multiframe_dxf(mf_path)
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/cad_dxf_report.py",
|
|
"--input",
|
|
str(dxf_dir),
|
|
"--work",
|
|
str(WORK / "report_work2"),
|
|
"--output",
|
|
str(WORK / "read_report2"),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
report2 = json.loads((WORK / "read_report2" / "cad_read_report.json").read_text(encoding="utf-8"))
|
|
mf_item = {item["file"]: item for item in report2["files"]}.get("multiframe.dxf", {})
|
|
check(
|
|
"multi_frame_sheet warning raised",
|
|
any("multi_frame_sheet" in w for w in mf_item.get("warnings", [])),
|
|
str(mf_item.get("warnings")),
|
|
)
|
|
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/detect_sheet_frames.py",
|
|
"--dxf",
|
|
str(mf_path),
|
|
"--out-config",
|
|
str(WORK / "frames.json"),
|
|
"--out-report",
|
|
str(WORK / "frames.md"),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
check("detect_sheet_frames runs", proc.returncode == 0, proc.stderr[-800:])
|
|
frames = json.loads((WORK / "frames.json").read_text(encoding="utf-8"))
|
|
floors = frames["drawings"][0]["floors"]
|
|
keys = [floor["key"] for floor in floors]
|
|
check("two plan frames found", sorted(keys) == ["F1", "F2"], str(keys))
|
|
off = {floor["key"]: floor["offset"] for floor in floors}
|
|
ok_offset = abs(off["F2"][0] - 0.0) <= 120 and abs(off["F2"][1] - 98100.0) <= 120
|
|
check("grid alignment recovers frame offset", ok_offset, str(off))
|
|
|
|
frames.update({"scale": 0.001, "layers": {"walls": ["WALL"], "grid": ["DOTE"]}})
|
|
aligned_cfg = WORK / "config_frames.json"
|
|
aligned_cfg.write_text(json.dumps(frames, ensure_ascii=False), encoding="utf-8")
|
|
aligned_spec = WORK / "spec_frames.json"
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/derive_showcase_spec.py",
|
|
"--dxf-dir",
|
|
str(dxf_dir),
|
|
"--config",
|
|
str(aligned_cfg),
|
|
"--out",
|
|
str(aligned_spec),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
check("derive multi-frame runs", proc.returncode == 0, proc.stderr[-800:])
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/audit_showcase_extraction.py",
|
|
"--dxf-dir",
|
|
str(dxf_dir),
|
|
"--config",
|
|
str(aligned_cfg),
|
|
"--spec",
|
|
str(aligned_spec),
|
|
"--out",
|
|
str(WORK / "audit_frames"),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
audit_frames = json.loads((WORK / "audit_frames" / "extraction_audit.json").read_text(encoding="utf-8"))
|
|
gates_frames = {gate["name"]: gate["status"] for gate in audit_frames["gates"]}
|
|
check("floors_aligned gate PASS with offsets", gates_frames.get("floors_aligned") == "PASS", str(gates_frames))
|
|
|
|
# Same clips but WITHOUT offsets -> the diagonal-staircase bug -> gate FAIL.
|
|
bad = json.loads(aligned_cfg.read_text(encoding="utf-8"))
|
|
for floor in bad["drawings"][0]["floors"]:
|
|
floor["offset"] = [0.0, 0.0]
|
|
bad_cfg = WORK / "config_frames_bad.json"
|
|
bad_cfg.write_text(json.dumps(bad, ensure_ascii=False), encoding="utf-8")
|
|
bad_spec = WORK / "spec_frames_bad.json"
|
|
run(
|
|
[
|
|
sys.executable,
|
|
"scripts/derive_showcase_spec.py",
|
|
"--dxf-dir",
|
|
str(dxf_dir),
|
|
"--config",
|
|
str(bad_cfg),
|
|
"--out",
|
|
str(bad_spec),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/audit_showcase_extraction.py",
|
|
"--dxf-dir",
|
|
str(dxf_dir),
|
|
"--config",
|
|
str(bad_cfg),
|
|
"--spec",
|
|
str(bad_spec),
|
|
"--out",
|
|
str(WORK / "audit_frames_bad"),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
check("misaligned floors exit 3", proc.returncode == 3, f"rc={proc.returncode}")
|
|
audit_bad = json.loads((WORK / "audit_frames_bad" / "extraction_audit.json").read_text(encoding="utf-8"))
|
|
gates_bad = {gate["name"]: gate["status"] for gate in audit_bad["gates"]}
|
|
check("floors_aligned gate FAIL without offsets", gates_bad.get("floors_aligned") == "FAIL", str(gates_bad))
|
|
cov = audit_frames["coverage"]
|
|
check("clip-scoped coverage reported", cov.get("clipped_supported_length_coverage") is not None, str(cov))
|
|
|
|
# --- horizontal-row frames (3#辅房 pattern) ---
|
|
row_dir = WORK / "dxf_row"
|
|
row_dir.mkdir(parents=True, exist_ok=True)
|
|
make_rowframe_dxf(row_dir / "rowframes.dxf")
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/detect_sheet_frames.py",
|
|
"--dxf",
|
|
str(row_dir / "rowframes.dxf"),
|
|
"--out-config",
|
|
str(WORK / "frames_row.json"),
|
|
"--out-report",
|
|
str(WORK / "frames_row.md"),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
check("detect handles row layout", proc.returncode == 0, proc.stderr[-600:])
|
|
frames_row = json.loads((WORK / "frames_row.json").read_text(encoding="utf-8"))
|
|
row_floors = frames_row["drawings"][0]["floors"]
|
|
row_off = {f["key"]: f["offset"] for f in row_floors}
|
|
check("row layout: two floors", sorted(row_off) == ["F1", "F2"], str(row_off))
|
|
ok_row = "F2" in row_off and abs(row_off["F2"][0] + 21000.0) <= 120 and abs(row_off["F2"][1]) <= 120
|
|
check("row layout: x-pitch offset recovered", ok_row, str(row_off))
|
|
|
|
# prefixed layers (13号地块: A_WALL/A_DOTE) must still grid-align
|
|
make_rowframe_dxf(row_dir / "rowframes_prefixed.dxf", layer_prefix="A_")
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/detect_sheet_frames.py",
|
|
"--dxf",
|
|
str(row_dir / "rowframes_prefixed.dxf"),
|
|
"--out-config",
|
|
str(WORK / "frames_pref.json"),
|
|
"--out-report",
|
|
str(WORK / "frames_pref.md"),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
check("detect handles prefixed layers", proc.returncode == 0, proc.stderr[-400:])
|
|
if proc.returncode == 0:
|
|
frames_pref = json.loads((WORK / "frames_pref.json").read_text(encoding="utf-8"))
|
|
pref_off = {f["key"]: f["offset"] for f in frames_pref["drawings"][0]["floors"]}
|
|
pref_md = (WORK / "frames_pref.md").read_text(encoding="utf-8")
|
|
ok_pref = "F2" in pref_off and abs(pref_off["F2"][0] + 21000.0) <= 120 and "WEAK" not in pref_md
|
|
check("prefixed A_DOTE grid still votes", ok_pref, f"{pref_off} weak={'WEAK' in pref_md}")
|
|
|
|
# tick-style grids (13号: 0.8m axis stubs outside the wall bbox, no through lines)
|
|
make_rowframe_dxf(row_dir / "rowframes_ticks.dxf", grid_style="ticks")
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/detect_sheet_frames.py",
|
|
"--dxf",
|
|
str(row_dir / "rowframes_ticks.dxf"),
|
|
"--out-config",
|
|
str(WORK / "frames_ticks.json"),
|
|
"--out-report",
|
|
str(WORK / "frames_ticks.md"),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
check("detect handles tick grids", proc.returncode == 0, proc.stderr[-400:])
|
|
if proc.returncode == 0:
|
|
frames_ticks = json.loads((WORK / "frames_ticks.json").read_text(encoding="utf-8"))
|
|
tick_off = {f["key"]: f["offset"] for f in frames_ticks["drawings"][0]["floors"]}
|
|
tick_md = (WORK / "frames_ticks.md").read_text(encoding="utf-8")
|
|
ok_ticks = "F2" in tick_off and abs(tick_off["F2"][0] + 21000.0) <= 120 and "WEAK" not in tick_md
|
|
check("axis ticks vote like grid lines", ok_ticks, f"{tick_off} weak={'WEAK' in tick_md}")
|
|
|
|
# --- merge_wall_solids: shapely union of wall segments (spec_to_glb) ---
|
|
sys.path.insert(0, str(ROOT / "scripts"))
|
|
import spec_to_glb # noqa: E402
|
|
|
|
l_walls = [
|
|
{"start": [0, 0], "end": [10, 0], "width": 0.24, "layer": "WALL"},
|
|
{"start": [10, 0], "end": [10, 8], "width": 0.24, "layer": "WALL"},
|
|
]
|
|
check("spec_to_glb exposes merged_wall_polygons", hasattr(spec_to_glb, "merged_wall_polygons"))
|
|
if hasattr(spec_to_glb, "merged_wall_polygons"):
|
|
polys = spec_to_glb.merged_wall_polygons(l_walls)
|
|
check("L walls union to a single polygon", len(polys) == 1, f"{len(polys)} polygons")
|
|
if len(polys) == 1:
|
|
corner_count = len(list(polys[0].exterior.coords)) - 1
|
|
# A seamless right-angle corner is exactly 6 corners; 8 means the
|
|
# w/2 x w/2 notch at the shared endpoint was left open.
|
|
check("L union corner is seamless (6 corners)", corner_count == 6, f"{corner_count} corners")
|
|
minx, miny, maxx, maxy = polys[0].bounds
|
|
check(
|
|
"free wall ends are not extended",
|
|
abs(minx - 0.0) < 1e-6 and abs(maxy - 8.0) < 1e-6,
|
|
f"bounds={polys[0].bounds}",
|
|
)
|
|
|
|
wall_spec = {
|
|
"project": {"name": "wall-merge-test"},
|
|
"units": "meters",
|
|
"categories": {"walls": {"label": "墙体", "color": "#d4cbb8"}},
|
|
"source": {"config": {}},
|
|
"floors": {
|
|
"F1": {
|
|
"name": "首层",
|
|
"z": 0.0,
|
|
"height": 4.0,
|
|
"bounds": [0, 0, 12, 10],
|
|
"segments": {"walls": list(l_walls)},
|
|
}
|
|
},
|
|
}
|
|
|
|
def build_glb(tag: str, config: dict) -> tuple[bytes, dict]:
|
|
spec = json.loads(json.dumps(wall_spec))
|
|
spec["source"]["config"] = config
|
|
spec_file = WORK / f"wall_spec_{tag}.json"
|
|
spec_file.write_text(json.dumps(spec, ensure_ascii=False), encoding="utf-8")
|
|
out_file = WORK / f"wall_{tag}.glb"
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/spec_to_glb.py",
|
|
"--spec",
|
|
str(spec_file),
|
|
"--out",
|
|
str(out_file),
|
|
"--name",
|
|
tag,
|
|
]
|
|
)
|
|
check(f"spec_to_glb ({tag}) runs", proc.returncode == 0, proc.stderr[-400:])
|
|
info = json.loads(proc.stdout.strip().splitlines()[-1]) if proc.returncode == 0 else {}
|
|
return (out_file.read_bytes() if out_file.exists() else b""), info
|
|
|
|
default_bytes, default_info = build_glb("default", {})
|
|
off_bytes, _ = build_glb("off", {"merge_wall_solids": False})
|
|
on_bytes, on_info = build_glb("on", {"merge_wall_solids": True})
|
|
check(
|
|
"merge_wall_solids default matches explicit off byte-for-byte",
|
|
default_bytes == off_bytes and len(default_bytes) > 0,
|
|
)
|
|
check("merge_wall_solids on changes the output", on_bytes not in (b"", default_bytes))
|
|
check(
|
|
"merged walls keep one node with valid triangles",
|
|
on_info.get("nodes") == default_info.get("nodes") and on_info.get("triangles", 0) > 0,
|
|
f"default={default_info} on={on_info}",
|
|
)
|
|
|
|
# --- glazing_mullions: panel grid over merged glazing bands ---
|
|
check("spec_to_glb exposes glazing_mullion_segments", hasattr(spec_to_glb, "glazing_mullion_segments"))
|
|
if hasattr(spec_to_glb, "glazing_mullion_segments"):
|
|
band = [{"start": [0, 0], "end": [6, 0], "width": 0.06, "layer": "CURTWALL"}]
|
|
msegs = spec_to_glb.glazing_mullion_segments(band, 0.0, 4.0, panel_w=1.5)
|
|
verticals = [s for s in msegs if "_z0" not in s]
|
|
transoms = [s for s in msegs if "_z0" in s]
|
|
check("6m band at 1.5m pitch gives 5 vertical mullions", len(verticals) == 5, f"{len(verticals)} verticals")
|
|
check("band gets top+bottom transoms", len(transoms) == 2, f"{len(transoms)} transoms")
|
|
if transoms:
|
|
zs = sorted(float(s["_z0"]) for s in transoms)
|
|
check("transoms sit at the floor lines", abs(zs[0] - 0.0) < 0.15 and abs(zs[-1] - 4.0) < 0.15, str(zs))
|
|
|
|
glaze_spec = {
|
|
"project": {"name": "mullion-test"},
|
|
"units": "meters",
|
|
"categories": {
|
|
"walls": {"label": "墙体", "color": "#d4cbb8"},
|
|
"glazing": {"label": "玻璃", "color": "#79b8c9"},
|
|
},
|
|
"source": {"config": {}},
|
|
"floors": {
|
|
"F1": {
|
|
"name": "首层",
|
|
"z": 0.0,
|
|
"height": 4.0,
|
|
"bounds": [0, 0, 8, 4],
|
|
"segments": {
|
|
"glazing": [
|
|
{"start": [0, 0], "end": [6, 0], "width": 0.06, "layer": "CURTWALL"},
|
|
]
|
|
},
|
|
}
|
|
},
|
|
}
|
|
|
|
def build_glaze_glb(tag: str, config: dict) -> tuple[bytes, dict]:
|
|
spec = json.loads(json.dumps(glaze_spec))
|
|
spec["source"]["config"] = config
|
|
spec_file = WORK / f"glaze_spec_{tag}.json"
|
|
spec_file.write_text(json.dumps(spec, ensure_ascii=False), encoding="utf-8")
|
|
out_file = WORK / f"glaze_{tag}.glb"
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/spec_to_glb.py",
|
|
"--spec",
|
|
str(spec_file),
|
|
"--out",
|
|
str(out_file),
|
|
"--name",
|
|
tag,
|
|
]
|
|
)
|
|
check(f"spec_to_glb ({tag}) runs", proc.returncode == 0, proc.stderr[-400:])
|
|
info = json.loads(proc.stdout.strip().splitlines()[-1]) if proc.returncode == 0 else {}
|
|
return (out_file.read_bytes() if out_file.exists() else b""), info
|
|
|
|
gdefault_bytes, gdefault_info = build_glaze_glb("default", {})
|
|
goff_bytes, _ = build_glaze_glb("off", {"glazing_mullions": False})
|
|
gon_bytes, gon_info = build_glaze_glb("on", {"glazing_mullions": True})
|
|
check(
|
|
"glazing_mullions default matches explicit off byte-for-byte",
|
|
gdefault_bytes == goff_bytes and len(gdefault_bytes) > 0,
|
|
)
|
|
check("glazing_mullions on changes the output", gon_bytes not in (b"", gdefault_bytes))
|
|
check(
|
|
"mullions add a walls node and keep the glass pane",
|
|
gon_info.get("nodes", 0) == gdefault_info.get("nodes", 0) + 1
|
|
and gon_info.get("triangles", 0) > gdefault_info.get("triangles", 0),
|
|
f"default={gdefault_info} on={gon_info}",
|
|
)
|
|
|
|
# --- GBK/ANSI_936 DXF survives sanitize + report (libredwg dwg2dxf output) ---
|
|
gbk_dir = WORK / "dxf_gbk"
|
|
gbk_dir.mkdir(parents=True, exist_ok=True)
|
|
gbk_lines = [
|
|
"999",
|
|
"天正注释行 should be stripped",
|
|
"0",
|
|
"SECTION",
|
|
"2",
|
|
"HEADER",
|
|
"9",
|
|
"$ACADVER",
|
|
"1",
|
|
"AC1009",
|
|
"9",
|
|
"$DWGCODEPAGE",
|
|
"3",
|
|
"ANSI_936",
|
|
"0",
|
|
"ENDSEC",
|
|
"0",
|
|
"SECTION",
|
|
"2",
|
|
"ENTITIES",
|
|
"0",
|
|
"TEXT",
|
|
"8",
|
|
"PUB_TEXT",
|
|
"10",
|
|
"0.0",
|
|
"20",
|
|
"0.0",
|
|
"40",
|
|
"500.0",
|
|
"1",
|
|
"一层平面图",
|
|
"0",
|
|
"ENDSEC",
|
|
"0",
|
|
"EOF",
|
|
"",
|
|
]
|
|
(gbk_dir / "gbk_plan.dxf").write_bytes("\r\n".join(gbk_lines).encode("gbk"))
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/cad_dxf_report.py",
|
|
"--input",
|
|
str(gbk_dir),
|
|
"--work",
|
|
str(WORK / "gbk_work"),
|
|
"--output",
|
|
str(WORK / "gbk_report"),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
check("report survives GBK/ANSI_936 DXF", proc.returncode == 0, proc.stderr[-600:])
|
|
gbk_report = WORK / "gbk_report" / "cad_read_report.json"
|
|
check("GBK report json parses", gbk_report.exists() and bool(json.loads(gbk_report.read_text(encoding="utf-8"))))
|
|
sanitized_gbk = WORK / "gbk_work" / "dxf_sanitized" / "gbk_plan.dxf"
|
|
if sanitized_gbk.exists():
|
|
doc = ezdxf.readfile(sanitized_gbk)
|
|
texts = [e.dxf.text for e in doc.modelspace() if e.dxftype() == "TEXT"]
|
|
check("sanitize preserves GBK CJK text", texts == ["一层平面图"], str(texts))
|
|
raw_bytes = sanitized_gbk.read_bytes()
|
|
check(
|
|
"sanitize still strips 999 comments",
|
|
b"999" not in raw_bytes.split(b"ENTITIES")[0] or b"should be stripped" not in raw_bytes,
|
|
)
|
|
else:
|
|
check("sanitized GBK dxf exists", False, str(sanitized_gbk))
|
|
|
|
# --- MIF-escaped plan titles (\M+5....): 黄桥文体中心 pattern ---
|
|
mif_dir = WORK / "dxf_mif"
|
|
mif_dir.mkdir(parents=True, exist_ok=True)
|
|
make_multiframe_dxf(mif_dir / "mifframes.dxf", mif_titles=True)
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/detect_sheet_frames.py",
|
|
"--dxf",
|
|
str(mif_dir / "mifframes.dxf"),
|
|
"--out-config",
|
|
str(WORK / "frames_mif.json"),
|
|
"--out-report",
|
|
str(WORK / "frames_mif.md"),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
check("detect handles MIF titles", proc.returncode == 0, proc.stderr[-600:])
|
|
if proc.returncode == 0:
|
|
frames_mif = json.loads((WORK / "frames_mif.json").read_text(encoding="utf-8"))
|
|
mif_keys = sorted(f["key"] for f in frames_mif["drawings"][0]["floors"])
|
|
check("MIF titles decoded to two plan frames", mif_keys == ["F1", "F2"], str(mif_keys))
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/cad_dxf_report.py",
|
|
"--input",
|
|
str(mif_dir),
|
|
"--work",
|
|
str(WORK / "mif_work"),
|
|
"--output",
|
|
str(WORK / "mif_report"),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
mif_report = json.loads((WORK / "mif_report" / "cad_read_report.json").read_text(encoding="utf-8"))
|
|
mif_item = {i["file"]: i for i in mif_report["files"]}.get("mifframes.dxf", {})
|
|
check(
|
|
"multi_frame_sheet warning fires on MIF titles",
|
|
any("multi_frame_sheet" in w for w in mif_item.get("warnings", [])),
|
|
str(mif_item.get("warnings")),
|
|
)
|
|
|
|
# --- block-wrapped plan grids (黄桥 A$C... wrapper blocks) ---
|
|
bg_dir = WORK / "dxf_blockgrid"
|
|
bg_dir.mkdir(parents=True, exist_ok=True)
|
|
make_blockgrid_dxf(bg_dir / "blockgrid.dxf")
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/detect_sheet_frames.py",
|
|
"--dxf",
|
|
str(bg_dir / "blockgrid.dxf"),
|
|
"--out-config",
|
|
str(WORK / "frames_bg.json"),
|
|
"--out-report",
|
|
str(WORK / "frames_bg.md"),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
check("detect handles block-wrapped grids", proc.returncode == 0, proc.stderr[-600:])
|
|
if proc.returncode == 0:
|
|
frames_bg = json.loads((WORK / "frames_bg.json").read_text(encoding="utf-8"))
|
|
bg_off = {f["key"]: f["offset"] for f in frames_bg["drawings"][0]["floors"]}
|
|
ok_bg = "F2" in bg_off and abs(bg_off["F2"][0]) <= 120 and abs(bg_off["F2"][1] - 98100.0) <= 120
|
|
check("block-grid correlation beats clip-corner fallback", ok_bg, str(bg_off))
|
|
|
|
# --- auxiliary-titled frame must not become the reference (27号 2#) ---
|
|
aux_dir = WORK / "dxf_auxref"
|
|
aux_dir.mkdir(parents=True, exist_ok=True)
|
|
make_auxref_dxf(aux_dir / "auxref.dxf")
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/detect_sheet_frames.py",
|
|
"--dxf",
|
|
str(aux_dir / "auxref.dxf"),
|
|
"--out-config",
|
|
str(WORK / "frames_aux.json"),
|
|
"--out-report",
|
|
str(WORK / "frames_aux.md"),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
check("detect handles aux-titled frames", proc.returncode == 0, proc.stderr[-600:])
|
|
if proc.returncode == 0:
|
|
aux_md = (WORK / "frames_aux.md").read_text(encoding="utf-8")
|
|
ref_line = next((line for line in aux_md.splitlines() if line.startswith("- reference frame:")), "")
|
|
check("aux title is not the reference", "非机动坡道" not in ref_line, ref_line)
|
|
check("plain 一层平面图 is the reference", "(一层平面图)" in ref_line, ref_line)
|
|
frames_aux = json.loads((WORK / "frames_aux.json").read_text(encoding="utf-8"))
|
|
aux_off = {f["name"]: f["offset"] for f in frames_aux["drawings"][0]["floors"]}
|
|
f2 = aux_off.get("二层平面图")
|
|
ok_aux = f2 is not None and abs(f2[0]) <= 120 and abs(f2[1] - 98100.0) <= 120
|
|
check("main F2 aligns to main F1 (not ramp)", ok_aux, str(aux_off))
|
|
check("aux frame flagged in report", "auxiliary" in aux_md, aux_md[-400:])
|
|
|
|
# --- gridless frames: wall-profile correlation beats clip-corner (27号 2#/13号) ---
|
|
ng_dir = WORK / "dxf_nogrid"
|
|
ng_dir.mkdir(parents=True, exist_ok=True)
|
|
make_nogrid_dxf(ng_dir / "nogrid.dxf")
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/detect_sheet_frames.py",
|
|
"--dxf",
|
|
str(ng_dir / "nogrid.dxf"),
|
|
"--out-config",
|
|
str(WORK / "frames_ng.json"),
|
|
"--out-report",
|
|
str(WORK / "frames_ng.md"),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
check("detect handles gridless frames", proc.returncode == 0, proc.stderr[-600:])
|
|
if proc.returncode == 0:
|
|
frames_ng = json.loads((WORK / "frames_ng.json").read_text(encoding="utf-8"))
|
|
ng_off = {f["name"]: f["offset"] for f in frames_ng["drawings"][0]["floors"]}
|
|
ng_md = (WORK / "frames_ng.md").read_text(encoding="utf-8")
|
|
f2 = ng_off.get("二层平面图")
|
|
ok_ng = f2 is not None and abs(f2[0]) <= 120 and abs(f2[1] - 98100.0) <= 120
|
|
check("wall-profile correlation recovers offset", ok_ng, str(ng_off))
|
|
check("wall correlation reported (not silent WEAK)", "wall-correlated" in ng_md, ng_md[-500:])
|
|
|
|
# --- plan titles inside cached-xref blocks (13号: msp = INSERT stubs only) ---
|
|
bt_dir = WORK / "dxf_blocktitle"
|
|
bt_dir.mkdir(parents=True, exist_ok=True)
|
|
make_blocktitle_dxf(bt_dir / "blocktitle.dxf")
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/detect_sheet_frames.py",
|
|
"--dxf",
|
|
str(bt_dir / "blocktitle.dxf"),
|
|
"--out-config",
|
|
str(WORK / "frames_bt.json"),
|
|
"--out-report",
|
|
str(WORK / "frames_bt.md"),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
bt_ok = proc.returncode == 0
|
|
check("detect finds titles inside blocks", bt_ok, (proc.stdout + proc.stderr)[-400:])
|
|
if bt_ok:
|
|
frames_bt = json.loads((WORK / "frames_bt.json").read_text(encoding="utf-8"))
|
|
bt = {f["name"]: f for f in frames_bt["drawings"][0]["floors"]}
|
|
check("both block-wrapped frames detected", set(bt) == {"一层平面图", "二层平面图"}, str(set(bt)))
|
|
f2 = bt.get("二层平面图")
|
|
ok_bt = f2 is not None and abs(f2["offset"][0]) <= 120 and abs(f2["offset"][1] - 98100.0) <= 120
|
|
check("block-wrapped frames aligned", ok_bt, str(f2 and f2["offset"]))
|
|
|
|
# --- title-block INSERTs define clips; elongated sheets must not be halved (13号 加长A0) ---
|
|
tb_dir = WORK / "dxf_titleblock"
|
|
tb_dir.mkdir(parents=True, exist_ok=True)
|
|
make_titleblock_dxf(tb_dir / "titleblock.dxf")
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/detect_sheet_frames.py",
|
|
"--dxf",
|
|
str(tb_dir / "titleblock.dxf"),
|
|
"--out-config",
|
|
str(WORK / "frames_tb.json"),
|
|
"--out-report",
|
|
str(WORK / "frames_tb.md"),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
check("detect handles title-block frames", proc.returncode == 0, proc.stderr[-500:])
|
|
if proc.returncode == 0:
|
|
frames_tb = json.loads((WORK / "frames_tb.json").read_text(encoding="utf-8"))
|
|
tb = {f["name"]: f for f in frames_tb["drawings"][0]["floors"]}
|
|
f1 = tb.get("一层平面图")
|
|
ok_tb = f1 is not None and f1["clip"][0] <= 0 and f1["clip"][2] >= 149000
|
|
check("elongated-A0 clip spans both towers", ok_tb, str(f1 and f1["clip"]))
|
|
tb_md = (WORK / "frames_tb.md").read_text(encoding="utf-8")
|
|
check("frame-block clips reported", "frame-block" in tb_md, tb_md[-300:])
|
|
|
|
# --- cross-floor datum: self-consistent but misplaced floor must FAIL audit (13号 F3 错槽) ---
|
|
cd_dir = WORK / "dxf_crossdatum"
|
|
cd_dir.mkdir(parents=True, exist_ok=True)
|
|
cd_doc = ezdxf.new("R2010", setup=True)
|
|
cd_doc.layers.add("WALL")
|
|
cd_msp = cd_doc.modelspace()
|
|
|
|
def cd_tower(ox: float, bays: tuple) -> None:
|
|
for start, end in [
|
|
((ox, 0), (ox + 20000, 0)),
|
|
((ox + 20000, 0), (ox + 20000, 10000)),
|
|
((ox + 20000, 10000), (ox, 10000)),
|
|
((ox, 10000), (ox, 0)),
|
|
]:
|
|
cd_msp.add_line(start, end, dxfattribs={"layer": "WALL"})
|
|
for b in bays:
|
|
cd_msp.add_line((ox + b, 0), (ox + b, 10000), dxfattribs={"layer": "WALL"})
|
|
cd_msp.add_line((ox + 2000, 5200), (ox + 18000, 5200), dxfattribs={"layer": "WALL"})
|
|
cd_msp.add_line((ox + 1000, 2600), (ox + 19000, 2600), dxfattribs={"layer": "WALL"})
|
|
cd_msp.add_line((ox + bays[0] + 800, 0), (ox + bays[0] + 800, 10000), dxfattribs={"layer": "WALL"})
|
|
|
|
# F1 sheet: towers A (distinct bays) + B, 36 m apart. F2 sheet at x=100000:
|
|
# tower-A pattern that belongs in the A slot.
|
|
cd_tower(0.0, (3200, 7500, 16100))
|
|
cd_tower(36000.0, (4900, 12300, 17700))
|
|
cd_tower(100000.0, (3200, 7500, 16100))
|
|
cd_doc.saveas(cd_dir / "crossdatum.dxf")
|
|
|
|
def cd_audit(tag: str, offset_x: float) -> tuple[int, str]:
|
|
cfg = {
|
|
"scale": 0.001,
|
|
"generate_footprints": True,
|
|
"drawings": [
|
|
{
|
|
"file": "crossdatum.dxf",
|
|
"floors": [
|
|
{
|
|
"key": "F1",
|
|
"name": "一层",
|
|
"z": 0.0,
|
|
"height": 3.0,
|
|
"clip": [-2000.0, -2000.0, 58000.0, 12000.0],
|
|
"offset": [0.0, 0.0],
|
|
},
|
|
{
|
|
"key": "F2",
|
|
"name": "二层",
|
|
"z": 3.0,
|
|
"height": 3.0,
|
|
"clip": [98000.0, -2000.0, 122000.0, 12000.0],
|
|
"offset": [offset_x, 0.0],
|
|
},
|
|
],
|
|
}
|
|
],
|
|
}
|
|
cfg_path = WORK / f"cd_config_{tag}.json"
|
|
cfg_path.write_text(json.dumps(cfg, ensure_ascii=False), encoding="utf-8")
|
|
spec_path = WORK / f"cd_spec_{tag}.json"
|
|
run(
|
|
[
|
|
sys.executable,
|
|
"scripts/derive_showcase_spec.py",
|
|
"--dxf-dir",
|
|
str(cd_dir),
|
|
"--config",
|
|
str(cfg_path),
|
|
"--out",
|
|
str(spec_path),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/audit_showcase_extraction.py",
|
|
"--dxf-dir",
|
|
str(cd_dir),
|
|
"--config",
|
|
str(cfg_path),
|
|
"--spec",
|
|
str(spec_path),
|
|
"--out",
|
|
str(WORK / f"cd_audit_{tag}"),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
md = (WORK / f"cd_audit_{tag}" / "extraction_audit.json").read_text(encoding="utf-8")
|
|
return proc.returncode, md
|
|
|
|
rc_bad, md_bad = cd_audit("bad", -64000.0) # A-pattern lands in the B slot (36 m off)
|
|
check(
|
|
"misplaced floor FAILs cross-floor datum",
|
|
rc_bad != 0 and "cross_floor" in md_bad,
|
|
md_bad[-400:] if rc_bad == 0 else "",
|
|
)
|
|
rc_good, md_good = cd_audit("good", -100000.0) # correct slot
|
|
check("correct slot PASSes cross-floor datum", rc_good == 0, md_good[-400:] if rc_good != 0 else "")
|
|
|
|
# --- multi-floor titles expand; per-frame ladders + storey suggestion (27号/13号 config 手写之痛) ---
|
|
ld_dir = WORK / "dxf_ladder"
|
|
ld_dir.mkdir(parents=True, exist_ok=True)
|
|
make_ladder_dxf(ld_dir / "ladder.dxf")
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/detect_sheet_frames.py",
|
|
"--dxf",
|
|
str(ld_dir / "ladder.dxf"),
|
|
"--out-config",
|
|
str(WORK / "frames_ld.json"),
|
|
"--out-report",
|
|
str(WORK / "frames_ld.md"),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
check("detect handles ladder/multi-floor sheet", proc.returncode == 0, proc.stderr[-500:])
|
|
if proc.returncode == 0:
|
|
frames_ld = json.loads((WORK / "frames_ld.json").read_text(encoding="utf-8"))
|
|
ld = {f["key"]: f for f in frames_ld["drawings"][0]["floors"]}
|
|
check(
|
|
"enumerated title expands (三、五层)",
|
|
"F3" in ld and "F5" in ld and ld["F3"]["clip"] == ld["F5"]["clip"],
|
|
str(sorted(ld)),
|
|
)
|
|
check("range title expands (十一至十四层)", all(f"F{n}" in ld for n in (11, 12, 13, 14)), str(sorted(ld)))
|
|
check("compound CN numerals parsed (no F0 keys)", not any(k.startswith("F0") for k in ld), str(sorted(ld)))
|
|
ld_md = (WORK / "frames_ld.md").read_text(encoding="utf-8")
|
|
check("per-frame elevation ladder reported", "1-1剖面图" in ld_md and "ladder:" in ld_md, ld_md[-500:])
|
|
check("uniform storey step suggested", "suggested storey table: uniform step 3.0" in ld_md, ld_md[-600:])
|
|
|
|
# --- register_site_outlines.py: ICP registration recovers rotation+translation ---
|
|
reg_dir = WORK / "register"
|
|
reg_dir.mkdir(parents=True, exist_ok=True)
|
|
# model footprint: 30x12 rect with an asymmetric notch (pins the 180° flip)
|
|
model_poly = [[0, 0], [30, 0], [30, 12], [8, 12], [8, 9], [0, 9]]
|
|
reg_spec = {
|
|
"project": "reg",
|
|
"units": {"scale": 0.001},
|
|
"categories": {},
|
|
"source": {"config": {}},
|
|
"floors": {
|
|
"F1": {
|
|
"name": "F1",
|
|
"z": 0.0,
|
|
"height": 3.0,
|
|
"bounds": [0, 0, 30, 12],
|
|
"segments": {"walls": []},
|
|
"footprint": {"polygons": [model_poly]},
|
|
"caps": [],
|
|
}
|
|
},
|
|
}
|
|
(reg_dir / "spec.json").write_text(json.dumps(reg_spec), encoding="utf-8")
|
|
th = math.radians(30.0)
|
|
site_pts = [
|
|
[round(x * math.cos(th) - y * math.sin(th) + 500.0, 3), round(x * math.sin(th) + y * math.cos(th) + 200.0, 3)]
|
|
for x, y in model_poly
|
|
]
|
|
(reg_dir / "pts.json").write_text(json.dumps(site_pts), encoding="utf-8")
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/register_site_outlines.py",
|
|
"--spec",
|
|
str(reg_dir / "spec.json"),
|
|
"--floors",
|
|
"F1",
|
|
"--site-points",
|
|
str(reg_dir / "pts.json"),
|
|
"--out",
|
|
str(reg_dir / "reg.json"),
|
|
]
|
|
)
|
|
check("register_site_outlines runs", proc.returncode == 0, proc.stderr[-500:])
|
|
if proc.returncode == 0:
|
|
reg = json.loads((reg_dir / "reg.json").read_text(encoding="utf-8"))
|
|
d_rot = abs((reg["rotation_deg"] - 30.0 + 180) % 360 - 180)
|
|
check("registration recovers rotation", d_rot <= 0.5, str(reg))
|
|
check("registration residual small", reg["residual_m"] <= 0.15, str(reg))
|
|
check("manifest fragment emitted", "model_anchor_m" in reg.get("manifest_entry", {}), str(reg.keys()))
|
|
|
|
# --- massing_from_outline.py: honest massing spec from site outline ---
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/massing_from_outline.py",
|
|
"--outline",
|
|
str(reg_dir / "pts.json"),
|
|
"--storeys",
|
|
"5",
|
|
"--height",
|
|
"3.0",
|
|
"--name",
|
|
"test_massing",
|
|
"--out",
|
|
str(reg_dir / "massing.json"),
|
|
]
|
|
)
|
|
check("massing_from_outline runs", proc.returncode == 0, proc.stderr[-500:])
|
|
if proc.returncode == 0:
|
|
ms = json.loads((reg_dir / "massing.json").read_text(encoding="utf-8"))
|
|
fl = ms["floors"]
|
|
top = fl[max(fl, key=lambda k: fl[k]["z"])]
|
|
check(
|
|
"massing has N floors with walls+footprint",
|
|
len(fl) == 5 and all(f["segments"]["walls"] and f["footprint"]["polygons"] for f in fl.values()),
|
|
str({k: len(v["segments"]["walls"]) for k, v in fl.items()}),
|
|
)
|
|
check("massing top floor capped", bool(top["caps"]), str(top.get("caps")))
|
|
description = ms.get("project", {}).get("description", "")
|
|
check("massing marked as outline volume", "体量" in description, description)
|
|
|
|
# --- bogus x-pitch from stray same-row titles must not shrink clips (27号 1#B) ---
|
|
mx_dir = WORK / "dxf_mixedrow"
|
|
mx_dir.mkdir(parents=True, exist_ok=True)
|
|
make_mixedrow_dxf(mx_dir / "mixedrow.dxf")
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/detect_sheet_frames.py",
|
|
"--dxf",
|
|
str(mx_dir / "mixedrow.dxf"),
|
|
"--out-config",
|
|
str(WORK / "frames_mx.json"),
|
|
"--out-report",
|
|
str(WORK / "frames_mx.md"),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
check("detect handles mixed row/column titles", proc.returncode == 0, proc.stderr[-600:])
|
|
if proc.returncode == 0:
|
|
frames_mx = json.loads((WORK / "frames_mx.json").read_text(encoding="utf-8"))
|
|
mx = {f["name"]: f for f in frames_mx["drawings"][0]["floors"]}
|
|
f1 = mx.get("一层平面图")
|
|
ok_span = f1 is not None and f1["clip"][0] <= 0 and f1["clip"][2] >= 80000
|
|
check("clip spans both wings despite stray x-pitch", ok_span, str(f1 and f1["clip"]))
|
|
f2 = mx.get("二层平面图")
|
|
ok_mx = f2 is not None and abs(f2["offset"][0]) <= 120 and abs(f2["offset"][1] - 98100.0) <= 120
|
|
check("mixed layout offset recovered", ok_mx, str(f2 and f2["offset"]))
|
|
|
|
# --- twin-tower floors must get SEPARATE footprint hulls (13号 一号楼: 凹包桥接
|
|
# 两塔, use_footprint_slabs 在 36m 空隙上生成横跨飘板) ---
|
|
tt_dir = WORK / "dxf_twintower"
|
|
tt_dir.mkdir(parents=True, exist_ok=True)
|
|
tt_doc = ezdxf.new("R2010", setup=True)
|
|
tt_doc.layers.add("I-WALL")
|
|
tt_msp = tt_doc.modelspace()
|
|
for ox in (0.0, 60000.0): # two 20m x 10m towers, 40 m of void between
|
|
for start, end in [
|
|
((ox, 0), (ox + 20000, 0)),
|
|
((ox + 20000, 0), (ox + 20000, 10000)),
|
|
((ox + 20000, 10000), (ox, 10000)),
|
|
((ox, 10000), (ox, 0)),
|
|
((ox + 7000, 0), (ox + 7000, 10000)),
|
|
((ox + 13000, 0), (ox + 13000, 10000)),
|
|
((ox, 5000), (ox + 20000, 5000)),
|
|
]:
|
|
tt_msp.add_line(start, end, dxfattribs={"layer": "I-WALL"})
|
|
tt_doc.saveas(tt_dir / "twin.dxf")
|
|
tt_config = {
|
|
"scale": 0.001,
|
|
"generate_footprints": True,
|
|
"use_footprint_slabs": True,
|
|
"drawings": [{"file": "twin.dxf", "floors": [{"key": "F4", "name": "标准层", "z": 12.0, "height": 4.2}]}],
|
|
}
|
|
tt_cfg = WORK / "tt_config.json"
|
|
tt_cfg.write_text(json.dumps(tt_config, ensure_ascii=False), encoding="utf-8")
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/derive_showcase_spec.py",
|
|
"--dxf-dir",
|
|
str(tt_dir),
|
|
"--config",
|
|
str(tt_cfg),
|
|
"--out",
|
|
str(WORK / "tt_spec.json"),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
check("derive twin-tower floor runs", proc.returncode == 0, proc.stderr[-400:])
|
|
if proc.returncode == 0:
|
|
tt_spec = json.loads((WORK / "tt_spec.json").read_text(encoding="utf-8"))
|
|
polys = tt_spec["floors"]["F4"]["footprint"]["polygons"]
|
|
spans = [max(p[0] for p in poly) - min(p[0] for p in poly) for poly in polys]
|
|
check("two separate footprint hulls", len(polys) == 2, f"n={len(polys)} spans={spans}")
|
|
check("no hull bridges the void", all(s < 25.0 for s in spans), f"spans={spans}")
|
|
|
|
# --- leak gates: frame ledger — every detected frame in config OR explicitly discarded ---
|
|
fl_frames = WORK / "frames_ledger_probe.json"
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/detect_sheet_frames.py",
|
|
"--dxf",
|
|
str(mf_path),
|
|
"--out-config",
|
|
str(fl_frames),
|
|
"--out-report",
|
|
str(WORK / "frames_ledger_probe.md"),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
check("ledger probe detect runs", proc.returncode == 0, proc.stderr[-300:])
|
|
fl_detected = json.loads(fl_frames.read_text(encoding="utf-8"))["drawings"][0]["floors"]
|
|
fl_f1 = next(f for f in fl_detected if f["name"] == "一层平面图")
|
|
|
|
def ledger_audit(tag: str, extra: dict) -> tuple[int, str]:
|
|
cfg = {
|
|
"scale": 0.001,
|
|
"drawings": [
|
|
{
|
|
"file": "multiframe.dxf",
|
|
"floors": [
|
|
{
|
|
"key": "F1",
|
|
"name": "一层平面图",
|
|
"z": 0.0,
|
|
"height": 4.2,
|
|
"clip": fl_f1["clip"],
|
|
"offset": fl_f1["offset"],
|
|
},
|
|
],
|
|
}
|
|
],
|
|
**extra,
|
|
}
|
|
cfg_path = WORK / f"ledger_cfg_{tag}.json"
|
|
cfg_path.write_text(json.dumps(cfg, ensure_ascii=False), encoding="utf-8")
|
|
spec_path = WORK / f"ledger_spec_{tag}.json"
|
|
run(
|
|
[
|
|
sys.executable,
|
|
"scripts/derive_showcase_spec.py",
|
|
"--dxf-dir",
|
|
str(dxf_dir),
|
|
"--config",
|
|
str(cfg_path),
|
|
"--out",
|
|
str(spec_path),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/audit_showcase_extraction.py",
|
|
"--dxf-dir",
|
|
str(dxf_dir),
|
|
"--config",
|
|
str(cfg_path),
|
|
"--spec",
|
|
str(spec_path),
|
|
"--out",
|
|
str(WORK / f"ledger_audit_{tag}"),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
"--frames",
|
|
str(fl_frames),
|
|
]
|
|
)
|
|
body = (WORK / f"ledger_audit_{tag}" / "extraction_audit.json").read_text(encoding="utf-8")
|
|
return proc.returncode, body
|
|
|
|
rc_miss, md_miss = ledger_audit("miss", {})
|
|
check(
|
|
"unaccounted frame FAILs ledger",
|
|
rc_miss != 0 and "frame_ledger" in md_miss and "二层平面图" in md_miss,
|
|
md_miss[-400:] if rc_miss == 0 else "",
|
|
)
|
|
rc_ok, md_ok = ledger_audit("ok", {"discarded_frames": [{"name": "二层平面图", "reason": "测试弃用"}]})
|
|
check("explicit discard PASSes ledger", rc_ok == 0, md_ok[-400:] if rc_ok != 0 else "")
|
|
|
|
# --- leak gates: declared areas + storey count cross-checks (twin-tower scenario) ---
|
|
tt_spec_data = json.loads((WORK / "tt_spec.json").read_text(encoding="utf-8"))
|
|
tt_area = sum(float(f["footprint"].get("area", 0.0)) for f in tt_spec_data["floors"].values())
|
|
|
|
def tt_audit(tag: str, extra: dict) -> tuple[int, str]:
|
|
cfg = dict(tt_config, **extra)
|
|
cfg_path = WORK / f"tt_cfg_{tag}.json"
|
|
cfg_path.write_text(json.dumps(cfg, ensure_ascii=False), encoding="utf-8")
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/audit_showcase_extraction.py",
|
|
"--dxf-dir",
|
|
str(tt_dir),
|
|
"--config",
|
|
str(cfg_path),
|
|
"--spec",
|
|
str(WORK / "tt_spec.json"),
|
|
"--out",
|
|
str(WORK / f"tt_audit_{tag}"),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
body = (WORK / f"tt_audit_{tag}" / "extraction_audit.json").read_text(encoding="utf-8")
|
|
return proc.returncode, body
|
|
|
|
rc, body = tt_audit("good", {"declared_areas_m2": {"F4": round(tt_area)}, "expected_storeys_above_ground": 1})
|
|
check("area+storey cross-checks PASS on truth", rc == 0, body[-400:] if rc != 0 else "")
|
|
rc, body = tt_audit("badarea", {"declared_areas_m2": {"F4": round(tt_area * 2)}})
|
|
check("declared-area mismatch FAILs", rc != 0 and "area_declared" in body, body[-400:] if rc == 0 else "")
|
|
rc, body = tt_audit("badcount", {"expected_storeys_above_ground": 5})
|
|
check("storey-count mismatch FAILs", rc != 0 and "storey_count" in body, body[-400:] if rc == 0 else "")
|
|
|
|
# --- leak warning: unfamiliar layer dialect must be called out ---
|
|
dial_dir = WORK / "dxf_dialect"
|
|
dial_dir.mkdir(parents=True, exist_ok=True)
|
|
dial_doc = ezdxf.new("R2010")
|
|
for layer in ("XQTB-QT", "PUB_TEXT"):
|
|
dial_doc.layers.add(layer)
|
|
dial_msp = dial_doc.modelspace()
|
|
for i in range(500):
|
|
dial_msp.add_line((i * 100, 0), (i * 100, 4000), dxfattribs={"layer": "XQTB-QT"})
|
|
dial_msp.add_text("一层平面图", dxfattribs={"layer": "PUB_TEXT", "height": 800}).set_placement((20000, -5000))
|
|
dial_doc.saveas(dial_dir / "dialect.dxf")
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/cad_dxf_report.py",
|
|
"--input",
|
|
str(dial_dir),
|
|
"--work",
|
|
str(WORK / "dialect_work"),
|
|
"--output",
|
|
str(WORK / "dialect_report"),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
check("dialect report runs", proc.returncode == 0, proc.stderr[-400:])
|
|
if proc.returncode == 0:
|
|
drep = json.loads((WORK / "dialect_report" / "cad_read_report.json").read_text(encoding="utf-8"))
|
|
dw = " ".join({i["file"]: i for i in drep["files"]}.get("dialect.dxf", {}).get("warnings", []))
|
|
check("unknown layer dialect warned", "unknown_layer_dialect" in dw, dw)
|
|
|
|
# --- floor_order gaps must warn loudly, not silently drop floors (13号 b2: F11-F16 消失) ---
|
|
fo_config = {
|
|
"scale": 0.001,
|
|
"floor_order": ["1F", "GHOST"],
|
|
"drawings": [
|
|
{
|
|
"file": "plan.dxf",
|
|
"floors": [
|
|
{"key": "1F", "name": "首层", "z": 0.0, "height": 4.2},
|
|
{"key": "2F", "name": "二层", "z": 4.2, "height": 4.2},
|
|
],
|
|
}
|
|
],
|
|
}
|
|
fo_path = WORK / "fo_config.json"
|
|
fo_path.write_text(json.dumps(fo_config, ensure_ascii=False), encoding="utf-8")
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/derive_showcase_spec.py",
|
|
"--dxf-dir",
|
|
str(dxf_dir),
|
|
"--config",
|
|
str(fo_path),
|
|
"--out",
|
|
str(WORK / "fo_spec.json"),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
check("derive with floor_order gaps fails hard", proc.returncode == 3, proc.stderr[-400:])
|
|
check("missing-from-order floor fails", "floor_order" in proc.stderr and "2F" in proc.stderr, proc.stderr[-300:])
|
|
check("ghost order key fails", "GHOST" in proc.stderr, proc.stderr[-300:])
|
|
|
|
# --- assemble_campus: per-building rotation_deg (27号: 4#楼独自斜置) ---
|
|
asm_dir = WORK / "assemble"
|
|
asm_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
def mini_spec(tag: str) -> str:
|
|
walls = []
|
|
for (sx, sy), (ex, ey) in [((0, 0), (10, 0)), ((10, 0), (10, 20)), ((10, 20), (0, 20)), ((0, 20), (0, 0))]:
|
|
walls.append({"start": [sx, sy], "end": [ex, ey], "width": 0.2, "layer": "WALL"})
|
|
spec = {
|
|
"project": tag,
|
|
"units": {"scale": 0.001},
|
|
"categories": {"walls": {"label": "墙", "color": "#ccc"}},
|
|
"source": {"config": {"use_footprint_slabs": True, "roof_specs": []}},
|
|
"floors": {
|
|
"F1": {
|
|
"name": "F1",
|
|
"z": 0.0,
|
|
"height": 3.0,
|
|
"bounds": [0, 0, 10, 20],
|
|
"segments": {"walls": walls},
|
|
"footprint": {"polygons": [[[0, 0], [10, 0], [10, 20], [0, 20]]]},
|
|
"caps": [],
|
|
}
|
|
},
|
|
}
|
|
p = asm_dir / f"spec_{tag}.json"
|
|
p.write_text(json.dumps(spec), encoding="utf-8")
|
|
return str(p)
|
|
|
|
manifest = {
|
|
"campus_origin_surveying_m": [0.0, 0.0],
|
|
"rotation_deg": 0.0,
|
|
"buildings": {
|
|
"A": {"spec": mini_spec("a"), "prefix": "A", "model_anchor_m": [0.0, 0.0], "survey_anchor_m": [0.0, 0.0]},
|
|
"B": {
|
|
"spec": mini_spec("b"),
|
|
"prefix": "B",
|
|
"model_anchor_m": [0.0, 0.0],
|
|
"survey_anchor_m": [50.0, 0.0],
|
|
"rotation_deg": 90.0,
|
|
},
|
|
},
|
|
}
|
|
mpath = asm_dir / "manifest.json"
|
|
mpath.write_text(json.dumps(manifest), encoding="utf-8")
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/assemble_campus.py",
|
|
"--manifest",
|
|
str(mpath),
|
|
"--out",
|
|
str(asm_dir / "campus.json"),
|
|
"--project-name",
|
|
"rot-test",
|
|
"--allow-overlap",
|
|
]
|
|
)
|
|
check("assemble_campus per-building rotation runs", proc.returncode == 0, proc.stderr[-500:])
|
|
if proc.returncode == 0:
|
|
campus = json.loads((asm_dir / "campus.json").read_text(encoding="utf-8"))
|
|
bb = campus["floors"]["BF1"]["bounds"]
|
|
ok_rot = (
|
|
abs(bb[0] - 30.0) < 0.01
|
|
and abs(bb[1] - 0.0) < 0.01
|
|
and abs(bb[2] - 50.0) < 0.01
|
|
and abs(bb[3] - 10.0) < 0.01
|
|
)
|
|
check("per-building rotation applied (90deg)", ok_rot, str(bb))
|
|
ab = campus["floors"]["AF1"]["bounds"]
|
|
ok_a = abs(ab[0]) < 0.01 and abs(ab[2] - 10.0) < 0.01 and abs(ab[3] - 20.0) < 0.01
|
|
check("unrotated sibling unaffected", ok_a, str(ab))
|
|
|
|
# --- isolated legend clusters (黄桥图签窗图例 -> footprint 细三角飘板) ---
|
|
iso_dir = WORK / "dxf_isolated"
|
|
iso_dir.mkdir(parents=True, exist_ok=True)
|
|
iso_doc = ezdxf.new("R2010", setup=True)
|
|
for layer in ("I-WALL", "A-GLAZ-CURT"):
|
|
iso_doc.layers.add(layer)
|
|
iso_msp = iso_doc.modelspace()
|
|
for start, end in [
|
|
((0, 0), (40000, 0)),
|
|
((40000, 0), (40000, 20000)),
|
|
((40000, 20000), (0, 20000)),
|
|
((0, 20000), (0, 0)),
|
|
]:
|
|
iso_msp.add_line(start, end, dxfattribs={"layer": "I-WALL"})
|
|
iso_msp.add_line((0, 0), (20000, 0), dxfattribs={"layer": "A-GLAZ-CURT"}) # real facade band
|
|
for i in range(3): # window legend in the title block, 60 m east of the building
|
|
iso_msp.add_line((100000, 30000 + i * 400), (101000, 30000 + i * 400), dxfattribs={"layer": "A-GLAZ-CURT"})
|
|
iso_doc.saveas(iso_dir / "plan.dxf")
|
|
iso_config = {
|
|
"scale": 0.001,
|
|
"drawings": [{"file": "plan.dxf", "floors": [{"key": "1F", "name": "首层", "z": 0.0, "height": 4.2}]}],
|
|
}
|
|
|
|
def derive_iso(tag: str, extra: dict) -> tuple[dict, str]:
|
|
cfg = dict(iso_config, **extra)
|
|
cfg_path = WORK / f"iso_config_{tag}.json"
|
|
cfg_path.write_text(json.dumps(cfg, ensure_ascii=False), encoding="utf-8")
|
|
out_path = WORK / f"iso_spec_{tag}.json"
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/derive_showcase_spec.py",
|
|
"--dxf-dir",
|
|
str(iso_dir),
|
|
"--config",
|
|
str(cfg_path),
|
|
"--out",
|
|
str(out_path),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
check(f"derive isolated ({tag}) runs", proc.returncode == 0, proc.stderr[-400:])
|
|
return json.loads(out_path.read_text(encoding="utf-8")), proc.stderr
|
|
|
|
iso_spec, iso_err = derive_iso("default", {})
|
|
glz = iso_spec["floors"]["1F"]["segments"].get("glazing", [])
|
|
far = [s for s in glz if max(s["start"][0], s["end"][0]) > 60]
|
|
check("isolated legend cluster dropped by default", len(glz) > 0 and not far, f"glazing={len(glz)} far={len(far)}")
|
|
check("isolated-cluster drop warns loudly", "isolated" in iso_err.lower(), iso_err[-200:])
|
|
check(
|
|
"bounds shrink to the real building",
|
|
iso_spec["floors"]["1F"]["bounds"][2] <= 45.0,
|
|
str(iso_spec["floors"]["1F"]["bounds"]),
|
|
)
|
|
iso_spec_off, _ = derive_iso("off", {"drop_isolated_clusters": False})
|
|
glz_off = iso_spec_off["floors"]["1F"]["segments"].get("glazing", [])
|
|
check(
|
|
"legend kept when drop_isolated_clusters=false",
|
|
any(max(s["start"][0], s["end"][0]) > 60 for s in glz_off),
|
|
f"glazing={len(glz_off)}",
|
|
)
|
|
|
|
# --- segments must be TRIMMED to the frame clip, not kept whole ---
|
|
# (13号: a 56m-wide frame emitted 143m of geometry because long table/
|
|
# border lines with an inside midpoint carried the full sheet width)
|
|
trim_dir = WORK / "dxf_trim"
|
|
trim_dir.mkdir(parents=True, exist_ok=True)
|
|
trim_doc = ezdxf.new("R2010", setup=True)
|
|
trim_doc.layers.add("I-WALL")
|
|
trim_msp = trim_doc.modelspace()
|
|
for start, end in [
|
|
((0, 0), (40000, 0)),
|
|
((40000, 0), (40000, 20000)),
|
|
((40000, 20000), (0, 20000)),
|
|
((0, 20000), (0, 0)),
|
|
]:
|
|
trim_msp.add_line(start, end, dxfattribs={"layer": "I-WALL"})
|
|
trim_msp.add_line((-50000, 10000), (90000, 10000), dxfattribs={"layer": "I-WALL"})
|
|
trim_doc.saveas(trim_dir / "plan.dxf")
|
|
trim_cfg = WORK / "trim_config.json"
|
|
trim_cfg.write_text(
|
|
json.dumps(
|
|
{
|
|
"scale": 0.001,
|
|
"drop_isolated_clusters": False,
|
|
"drawings": [
|
|
{
|
|
"file": "plan.dxf",
|
|
"floors": [
|
|
{
|
|
"key": "1F",
|
|
"name": "首层",
|
|
"z": 0.0,
|
|
"height": 4.2,
|
|
"clip": [-1000, -1000, 41000, 21000],
|
|
},
|
|
],
|
|
}
|
|
],
|
|
},
|
|
ensure_ascii=False,
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
trim_spec_path = WORK / "trim_spec.json"
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/derive_showcase_spec.py",
|
|
"--dxf-dir",
|
|
str(trim_dir),
|
|
"--config",
|
|
str(trim_cfg),
|
|
"--out",
|
|
str(trim_spec_path),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
check("derive clip-trim runs", proc.returncode == 0, proc.stderr[-400:])
|
|
trim_spec = json.loads(trim_spec_path.read_text(encoding="utf-8"))
|
|
trim_walls = trim_spec["floors"]["1F"]["segments"]["walls"]
|
|
trim_max_x = max(max(s["start"][0], s["end"][0]) for s in trim_walls)
|
|
trim_min_x = min(min(s["start"][0], s["end"][0]) for s in trim_walls)
|
|
check(
|
|
"crossing line trimmed to the clip window",
|
|
len(trim_walls) == 5 and -1.5 <= trim_min_x and trim_max_x <= 42.5,
|
|
f"n={len(trim_walls)} x=[{trim_min_x:.1f},{trim_max_x:.1f}]",
|
|
)
|
|
|
|
# --- unsupported roof outlines (黄桥坡屋面: canopy with hatch-only posts) ---
|
|
uns_dir = WORK / "dxf_unsupported"
|
|
uns_dir.mkdir(parents=True, exist_ok=True)
|
|
uns_doc = ezdxf.new("R2010", setup=True)
|
|
for layer in ("I-WALL", "A-ROOF"):
|
|
uns_doc.layers.add(layer)
|
|
uns_msp = uns_doc.modelspace()
|
|
for start, end in [
|
|
((0, 0), (40000, 0)),
|
|
((40000, 0), (40000, 20000)),
|
|
((40000, 20000), (0, 20000)),
|
|
((0, 20000), (0, 0)),
|
|
]:
|
|
uns_msp.add_line(start, end, dxfattribs={"layer": "I-WALL"})
|
|
uns_msp.add_line((5000, 10000), (35000, 10000), dxfattribs={"layer": "A-ROOF"}) # over the building
|
|
uns_msp.add_line((80000, 50000), (95000, 50000), dxfattribs={"layer": "A-ROOF"}) # over nothing
|
|
uns_doc.saveas(uns_dir / "plan.dxf")
|
|
uns_config = {
|
|
"scale": 0.001,
|
|
"generate_footprints": True,
|
|
"drop_isolated_clusters": False, # keep the far roof line so THIS rule is what's tested
|
|
"drawings": [{"file": "plan.dxf", "floors": [{"key": "1F", "name": "首层", "z": 0.0, "height": 4.2}]}],
|
|
}
|
|
|
|
def derive_uns(tag: str, extra: dict) -> tuple[dict, str]:
|
|
cfg = dict(uns_config, **extra)
|
|
cfg_path = WORK / f"uns_config_{tag}.json"
|
|
cfg_path.write_text(json.dumps(cfg, ensure_ascii=False), encoding="utf-8")
|
|
out_path = WORK / f"uns_spec_{tag}.json"
|
|
proc = run(
|
|
[
|
|
sys.executable,
|
|
"scripts/derive_showcase_spec.py",
|
|
"--dxf-dir",
|
|
str(uns_dir),
|
|
"--config",
|
|
str(cfg_path),
|
|
"--out",
|
|
str(out_path),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
]
|
|
)
|
|
check(f"derive unsupported-roof ({tag}) runs", proc.returncode == 0, proc.stderr[-400:])
|
|
return json.loads(out_path.read_text(encoding="utf-8")), proc.stderr
|
|
|
|
uns_spec, uns_err = derive_uns("default", {})
|
|
roof_segs = uns_spec["floors"]["1F"]["segments"].get("roof", [])
|
|
check(
|
|
"unsupported roof line dropped, supported kept",
|
|
len(roof_segs) == 1 and max(roof_segs[0]["start"][0], roof_segs[0]["end"][0]) <= 45,
|
|
f"roof={[(s['start'], s['end']) for s in roof_segs]}",
|
|
)
|
|
check("unsupported-roof drop warns loudly", "unsupported_roof" in uns_err, uns_err[-200:])
|
|
uns_spec_off, _ = derive_uns("off", {"drop_unsupported_roof_lines": False})
|
|
check(
|
|
"roof lines kept when drop_unsupported_roof_lines=false",
|
|
len(uns_spec_off["floors"]["1F"]["segments"].get("roof", [])) == 2,
|
|
)
|
|
|
|
# --- ODA auto-fallback: broken libredwg conversion reconverts via ODA ---
|
|
# A garbage .dwg makes dwg2dxf fail (or be absent); with ODA_CONVERTER
|
|
# pointing at a fake directory-converter the report must recover the file
|
|
# instead of shipping a failed/empty record (黄桥: libredwg emits broken
|
|
# DXF for large TArch files while ODA reads back 21k entities).
|
|
oda_dir = WORK / "dxf_oda"
|
|
oda_dir.mkdir(parents=True, exist_ok=True)
|
|
(oda_dir / "broken.dwg").write_bytes(b"NOT-A-REAL-DWG" * 64)
|
|
good_template = WORK / "oda_template.dxf"
|
|
shutil.copy2(dxf_dir / "plan.dxf", good_template)
|
|
fake_conv = WORK / "fake_oda.sh"
|
|
fake_conv.write_text(
|
|
"#!/bin/sh\n"
|
|
'for f in "$1"/*.dwg; do\n'
|
|
' name=$(basename "$f" .dwg)\n'
|
|
f' cp "{good_template}" "$2/$name.dxf"\n'
|
|
"done\n",
|
|
encoding="utf-8",
|
|
)
|
|
fake_conv.chmod(0o755)
|
|
import os as _os
|
|
|
|
env = dict(_os.environ, ODA_CONVERTER=str(fake_conv))
|
|
proc = subprocess.run(
|
|
[
|
|
sys.executable,
|
|
"scripts/cad_dxf_report.py",
|
|
"--input",
|
|
str(oda_dir),
|
|
"--work",
|
|
str(WORK / "oda_work"),
|
|
"--output",
|
|
str(WORK / "oda_report"),
|
|
"--vendor-dir",
|
|
str(VENDOR),
|
|
],
|
|
cwd=ROOT,
|
|
text=True,
|
|
capture_output=True,
|
|
env=env,
|
|
)
|
|
check("report with ODA fallback runs", proc.returncode == 0, proc.stderr[-600:])
|
|
oda_json = json.loads((WORK / "oda_report" / "cad_read_report.json").read_text(encoding="utf-8"))
|
|
oda_convs = [c for c in oda_json["conversions"] if str(c.get("status", "")).startswith("oda_fallback")]
|
|
check("oda_fallback conversion recorded", any(c["status"] == "oda_fallback_ok" for c in oda_convs), str(oda_convs))
|
|
broken_item = {i["file"]: i for i in oda_json["files"]}.get("broken.dxf", {})
|
|
check(
|
|
"broken DWG recovered via ODA fallback",
|
|
broken_item.get("status") != "failed" and broken_item.get("modelspace_entities", 0) > 0,
|
|
str({k: broken_item.get(k) for k in ("status", "modelspace_entities")}),
|
|
)
|
|
|
|
print()
|
|
if FAILURES:
|
|
print(f"{len(FAILURES)} check(s) failed: {FAILURES}")
|
|
return 1
|
|
print("All checks passed.")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|