Productize site machinery + config automation (session-proven -> scripts/)

- register_site_outlines.py: point-to-edge ICP registration CLI (footprint
  union vs site outline / DIM_COOR corners), manifest-ready output, loud
  warning above 2 m residual
- massing_from_outline.py: honest massing spec CLI (outline x storeys x
  height, labeled 总图轮廓体量), manifest anchors on stdout
- detect_sheet_frames: multi-floor titles (四、六、八 / 十一至十四) expand to
  per-storey config entries sharing clip/offset — the 13号 b2 silent-floor-
  loss class is now prevented at the source; compound CN numerals parsed
  (十一/二十一 no longer collapse to F0 keys); per-frame DIM_ELEV ladders +
  uniform-step storey suggestion in the report (evidence, not auto-filled z)
- 27号 2# real data: 19-storey enumerated title auto-expands, step 3.0 x 11
  suggestion correct; regression suite +11 checks

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-03 08:28:05 +08:00
parent 9729857549
commit fc05464749
6 changed files with 536 additions and 15 deletions

View File

@@ -73,11 +73,51 @@ FLOOR_NAME_KEY = [
def _cn(token: str) -> int:
"""Chinese numeral (1-99, incl. compounds 十一/二十/二十一) or digits to int."""
if token.isdigit():
return int(token)
if not token:
return 0
if "十" in token:
tens, _, ones = token.partition("十")
t = CN_NUM.get(tens, 0) if tens else 1
o = CN_NUM.get(ones, 0) if ones else 0
if tens and t == 0:
return 0
return t * 10 + o
return CN_NUM.get(token, 0)
def covered_floor_numbers(name: str) -> list[int]:
"""Floors covered by a multi-floor plan title, else [].
四、六、八层平面图 -> [4,6,8]; 十一至十四层平面图 -> [11,12,13,14].
One frame standing for N storeys is the norm in Chinese sets — hand-copying
N config entries is exactly where floors got silently lost (13号 b2).
"""
if "地下" in name or "夹层" in name:
return []
m = re.search(r"(?P<seq>[一二三四五六七八九十\d]+(?:(?:[、,,]|[至~~\-—])[一二三四五六七八九十\d]+)+)层", name)
if not m:
return []
nums: list[int] = []
for part in re.split(r"[、,,]", m.group("seq")):
rng = re.split(r"[至~~\-—]", part)
if len(rng) == 2:
a, b = _cn(rng[0]), _cn(rng[1])
if not (0 < a < b <= 99 and b - a <= 40):
return []
nums.extend(range(a, b + 1))
elif len(rng) == 1:
v = _cn(rng[0])
if v <= 0:
return []
nums.append(v)
else:
return []
return nums if len(nums) > 1 else []
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--dxf", required=True)
@@ -569,6 +609,31 @@ def main() -> int:
for f in floors:
f.pop("_vx"), f.pop("_hy"), f.pop("_walls"), f.pop("_aux")
# Expand multi-floor titles (四、六、八层 / 十一至十四层) into one config
# entry per storey sharing the frame's clip/offset — hand-copying N entries
# is where floors silently vanished (13号 b2 F11-F16). z/height stay with
# the Agent: fill them from the storey-elevation evidence, do not guess.
config_floors: list[dict] = []
def _unique_key(key: str) -> str:
base, i = key, 2
while any(cf["key"] == key for cf in config_floors):
key = f"{base}_{i}"
i += 1
return key
for f in floors:
covers = covered_floor_numbers(f["name"])
if covers:
for n in covers:
config_floors.append({"key": _unique_key(f"F{n}"), "name": f"{n}层({f['name']})",
"clip": f["clip"], "offset": f["offset"]})
notes.append(f"{f['name']}: multi-floor title expanded to "
f"{', '.join('F' + str(n) for n in covers)} (same clip/offset; fill z/height per storey)")
else:
config_floors.append({"key": _unique_key(f["key"]), "name": f["name"],
"clip": f["clip"], "offset": f["offset"]})
config = {
"project_name": path.stem,
"scale": 0.001,
@@ -577,7 +642,7 @@ def main() -> int:
"origin_strategy": "min",
"drawings": [{
"file": path.name,
"floors": [{k: f[k] for k in ("key", "name", "clip", "offset")} for f in floors],
"floors": config_floors,
}],
}
out_config = Path(args.out_config)
@@ -597,19 +662,20 @@ def main() -> int:
report.extend(f"- note: {n}" for n in notes)
if others:
seen = set()
report.extend(["", "## Elevation/Section frames (for floor heights; not floors)", ""])
frames_e: list[dict] = []
for o in sorted(others, key=lambda o: -o.get("h", 0)):
key = o["name"]
if key in seen:
if o["name"] in seen:
continue
seen.add(key)
report.append(f"- {o['name']} @ ({round(o['x'])}, {round(o['y'])})")
# Storey-elevation suggestions: 标高 texts (e.g. 8.100) inside section/
# elevation frames, clustered. Feed floors[].z/height from these.
seen.add(o["name"])
frames_e.append(o)
# Storey-elevation evidence: 标高 texts (e.g. 8.100) inside section/
# elevation frames, collected PER FRAME (aggregated lists mix stair
# half-landings from 楼梯剖面 into the storey ladder — 27号 1#A lesson).
elev_re = re.compile(r"^-?\d{1,3}\.\d{3}$")
votes: Counter = Counter()
boxes = [(o["x"] - clip_w * 0.6, o["y"] - pitch * 0.06, o["x"] + clip_w * 0.6, o["y"] + clip_h)
for o in others]
ladders: dict[str, set] = {o["name"]: set() for o in frames_e}
boxes = [(o["name"], o["x"] - clip_w * 0.6, o["y"] - pitch * 0.06,
o["x"] + clip_w * 0.6, o["y"] + clip_h) for o in frames_e]
for entity in msp:
if entity.dxftype() != "TEXT":
continue
@@ -620,14 +686,53 @@ def main() -> int:
pos = entity.dxf.insert
except Exception:
continue
if any(b[0] <= pos.x <= b[2] and b[1] <= pos.y <= b[3] for b in boxes):
votes[round(float(content), 3)] += 1
for name, x1, y1, x2, y2 in boxes:
if x1 <= pos.x <= x2 and y1 <= pos.y <= y2:
v = round(float(content), 3)
ladders[name].add(v)
votes[v] += 1
report.extend(["", "## Elevation/Section frames (for floor heights; not floors)", ""])
for o in frames_e:
line = f"- {o['name']} @ ({round(o['x'])}, {round(o['y'])})"
vals = sorted(ladders.get(o["name"], ()))
if vals:
shown = ", ".join(f"{v:+.3f}" for v in vals[:40])
line += f" ladder: {shown}" + (" …" if len(vals) > 40 else "")
report.append(line)
levels = sorted(v for v, n in votes.items() if n >= 2 or (votes[v] >= 1 and -20 < v < 150))
if levels:
report.extend(["", "## Suggested storey elevations (from 剖面/立面 标高 texts)", "",
"- " + ", ".join(f"{v:+.3f}" for v in levels),
"- Interpret with judgment: entries include 室外地坪/女儿墙/雨棚; "
"storey z = consecutive major levels, height = difference."])
# Uniform-step suggestion: the dominant consecutive difference and
# its longest chain. A SUGGESTION for the Agent to verify against
# the 剖面 — stair sections beat at half-storey rhythm (2.25 for a
# 4.5 m storey), so per-frame ladders above are the ground truth.
majors = [v for v in levels if -0.5 <= v <= 200]
diff_votes: Counter = Counter()
for a, b in zip(majors, majors[1:]):
d = round(b - a, 2)
if 2.5 <= d <= 6.5:
diff_votes[d] += 1
if diff_votes:
step = diff_votes.most_common(1)[0][0]
best_chain: list[float] = []
for v0 in majors:
chain, cur = [v0], v0
while True:
nxt = [w for w in majors if abs(w - (cur + step)) <= 0.06]
if not nxt:
break
cur = nxt[0]
chain.append(cur)
if len(chain) > len(best_chain):
best_chain = chain
if len(best_chain) >= 4:
report.append(
f"- suggested storey table: uniform step {step} m x {len(best_chain) - 1} "
f"storeys, z {best_chain[0]:+.3f} → {best_chain[-1]:+.3f} — verify against "
"剖面/立面 per-frame ladders (podium and machine floors may differ)")
Path(args.out_report).write_text("\n".join(report) + "\n", encoding="utf-8")
print(json.dumps({
"config": str(out_config), "report": args.out_report,