feat(arch): SECTION 25 opens - walls, openings, stairs and exterior chains as tools

engineering/arch/draw.py is the only module of the track that touches a
backend. It draws through draw_prims(role_layer=ARCH_ROLE_LAYER) and the
generic contract members, so it runs on both engines as written, and it writes
the plan onto the drawing: each element's ACADMCP_ARCH record on one of its own
entities (a wall's first face line, a door's leaf, a window's frame, a stair's
first riser) and, beside it under ACADMCP_ARCH_H, the handles that element
owns. read_plan reads the records back and never modifies the drawing.

arch_wall computes the whole network before and after the new walls and
redraws only the drawn walls whose outline changes - erasing exactly the
entities they own - and says which under redrawn. arch_opening hosts a door or
a window in a drawn wall found by id and redraws that wall cut; its tag
defaults to the next D1/W1 (K1/P1 in Turkish). A new wall that would leave a
drawn opening uncuttable, and an opening that runs into a junction, are refused
before anything is erased. arch_stair reports the Blondel value; it does not
enforce it.

exterior_chains gives each side up to three rows, nearest first: every jamb in
that facade, both faces of every wall meeting it, and the overall - from the
wall engine's own faces. A row that would only restate a farther one is not
emitted (ISO 129-1: each measurement once). The 10 mm / 8 mm row spacing is a
declared drafting default times the plot scale, not a standard value.

The arch tag is ranked after mech so the four tools file under a new
architecture group; alias records carry WALLADD/MLINE, DOORADD/WINDOWADD and
STAIRADD with English and Turkish shop words. Inventory regenerated; README
snapshot 233 tools (228 advertised) in 26 groups; registry snapshot
architecture: 4.

No new ActiveX member is called. Measured on AutoCAD 2026 in a scratch
document through ComBackend: shell + teed partition, D1 + W1, a straight 17-riser stair
and the bottom chains gave the same 20 wall LINEs (identical endpoints),
9 poche HATCHes, 1+1 door, 4 window lines, 11 dimensions and a read_plan
round trip as the headless engine.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FKFStjEFzpGyLq5bMpWxTd
This commit is contained in:
Umut CAN
2026-09-23 23:00:05 +03:00
co-authored by Claude Opus 5.5
parent b68fe7ef66
commit cd1ae3529c
12 changed files with 1511 additions and 8 deletions
+107
View File
@@ -0,0 +1,107 @@
"""Exterior dimension chains: three rows per side, from the wall engine's own faces.
The plan: a closed 8200 x 6200 axis rectangle of 200 mm walls (outer faces
-100..8300 x -100..6300), a 100 mm partition on x = 4100 teed into the bottom
and top walls (faces x = 4050 / 4150), a 1200 window at 1500 and a 1000 door
at 5500 in the bottom wall. Every point below is hand-computed from those
numbers; at 1:50 the rows sit 500, 900 and 1300 mm outside the building.
"""
from __future__ import annotations
import pytest
from engineering.arch.dimension import (
FIRST_OFFSET_PAPER_MM,
ROWS,
SIDES,
STEP_PAPER_MM,
exterior_chains,
)
from engineering.arch.model import Opening, Wall
from engineering.mech.primitives import DimIntent
SHELL = Wall(
id="shell",
axis=((0.0, 0.0), (8200.0, 0.0), (8200.0, 6200.0), (0.0, 6200.0)),
thickness=200.0,
closed=True,
)
PARTITION = Wall(id="p", axis=((4100.0, 0.0), (4100.0, 6200.0)), thickness=100.0)
WINDOW = Opening(id="w1", wall="shell", kind="window", offset=1500.0, width=1200.0)
DOOR = Opening(id="d1", wall="shell", kind="door", offset=5500.0, width=1000.0)
def row(intents, feature) -> list[tuple]:
out = []
for intent in intents:
if intent.feature == feature:
out.append(
(
tuple(round(v, 9) + 0.0 for v in intent.p1),
tuple(round(v, 9) + 0.0 for v in intent.p2),
tuple(round(v, 9) + 0.0 for v in intent.text_at),
)
)
return out
def test_the_rows_and_the_offsets_are_declared():
assert SIDES == ("bottom", "top", "left", "right")
assert ROWS == ("openings", "walls", "overall")
assert (FIRST_OFFSET_PAPER_MM, STEP_PAPER_MM) == (10.0, 8.0)
def test_the_bottom_side_carries_openings_walls_and_overall():
intents = exterior_chains([SHELL, PARTITION], [WINDOW, DOOR], sides=("bottom",), scale=50)
assert all(isinstance(i, DimIntent) and i.kind == "linear" for i in intents)
assert row(intents, "bottom:openings") == [
((-100.0, -100.0), (1500.0, -100.0), (700.0, -600.0)),
((1500.0, -100.0), (2700.0, -100.0), (2100.0, -600.0)),
((2700.0, -100.0), (5500.0, -100.0), (4100.0, -600.0)),
((5500.0, -100.0), (6500.0, -100.0), (6000.0, -600.0)),
((6500.0, -100.0), (8300.0, -100.0), (7400.0, -600.0)),
]
assert row(intents, "bottom:walls") == [
((-100.0, -100.0), (100.0, -100.0), (0.0, -1000.0)),
((100.0, -100.0), (4050.0, -100.0), (2075.0, -1000.0)),
((4050.0, -100.0), (4150.0, -100.0), (4100.0, -1000.0)),
((4150.0, -100.0), (8100.0, -100.0), (6125.0, -1000.0)),
((8100.0, -100.0), (8300.0, -100.0), (8200.0, -1000.0)),
]
assert row(intents, "bottom:overall") == [
((-100.0, -100.0), (8300.0, -100.0), (4100.0, -1400.0)),
]
assert len(intents) == 11
def test_a_row_that_repeats_a_farther_one_is_not_emitted():
intents = exterior_chains([SHELL, PARTITION], [WINDOW, DOOR], sides=("left",), scale=50)
# no opening in the left wall: that row would only restate the overall one
assert row(intents, "left:openings") == []
assert row(intents, "left:walls") == [
((-100.0, -100.0), (-100.0, 100.0), (-1000.0, 0.0)),
((-100.0, 100.0), (-100.0, 6100.0), (-1000.0, 3100.0)),
((-100.0, 6100.0), (-100.0, 6300.0), (-1000.0, 6200.0)),
]
assert row(intents, "left:overall") == [((-100.0, -100.0), (-100.0, 6300.0), (-1400.0, 3100.0))]
def test_explicit_offsets_override_the_plot_scale_defaults():
intents = exterior_chains(
[SHELL], [], sides=("top",), first_offset=300.0, step=250.0, scale=100
)
# the top: the extremes only, so the walls row is the corner walls' faces
assert row(intents, "top:overall") == [((-100.0, 6300.0), (8300.0, 6300.0), (4100.0, 7100.0))]
assert {i.text_at[1] for i in intents if i.feature == "top:walls"} == {6850.0}
def test_bad_sides_and_scales_are_refused_by_name():
with pytest.raises(ValueError, match=r"sides\[0\]: 'north'"):
exterior_chains([SHELL], [], sides=("north",))
with pytest.raises(ValueError, match="named twice"):
exterior_chains([SHELL], [], sides=("left", "left"))
with pytest.raises(ValueError, match="scale"):
exterior_chains([SHELL], [], scale=0)
with pytest.raises(ValueError, match="sides"):
exterior_chains([SHELL], [], sides="bottom")
+207
View File
@@ -0,0 +1,207 @@
"""The async layer: walls, openings, stairs and chains drawn through the ezdxf backend.
The same code runs on the live engine: `engineering/arch/draw.py` composes only
generic contract members (entity_create_*, dimension_linear, entity_set_xdata,
entity_list, entity_delete), like the mechanical track's draw layer.
"""
from __future__ import annotations
import pytest
from engineering.arch.draw import (
HANDLES_APP,
add_opening,
add_stair,
add_walls,
assign_tags,
draw_chains,
draw_stair,
draw_walls,
read_plan,
)
from engineering.arch.layers import ARCH_ROLE_LAYER
from engineering.arch.model import APP_ID, Opening, Stair, Wall
pytestmark = pytest.mark.asyncio
WALL_A = {"id": "a", "axis": [[0.0, 0.0], [5000.0, 0.0]], "thickness": 200.0}
WALL_B = {"id": "b", "axis": [[2500.0, 0.0], [2500.0, 3000.0]], "thickness": 100.0}
async def on(backend, role, type_filter=None):
return await backend.entity_list(
type_filter=type_filter, layer_filter=ARCH_ROLE_LAYER[role], limit=10000
)
def ends(info) -> tuple:
a = tuple(round(v, 6) + 0.0 for v in info.properties["start"][:2])
b = tuple(round(v, 6) + 0.0 for v in info.properties["end"][:2])
return tuple(sorted((a, b)))
async def test_draw_walls_puts_faces_jambs_and_poche_on_their_layers(backend):
wall = Wall(id="a", axis=((0.0, 0.0), (5000.0, 0.0)), thickness=200.0)
door = Opening(id="d1", wall="a", kind="door", offset=1000.0, width=900.0, tag="D1")
result = await draw_walls(backend, [wall], [door])
lines = await on(backend, "wall", "LINE")
assert {ends(e) for e in lines} == {
((0.0, 100.0), (1000.0, 100.0)),
((1900.0, 100.0), (5000.0, 100.0)),
((0.0, -100.0), (1000.0, -100.0)),
((1900.0, -100.0), (5000.0, -100.0)),
((0.0, -100.0), (0.0, 100.0)),
((5000.0, -100.0), (5000.0, 100.0)),
((1000.0, -100.0), (1000.0, 100.0)),
((1900.0, -100.0), (1900.0, 100.0)),
}
assert len(await on(backend, "wall_hatch", "HATCH")) == 2
assert len(await on(backend, "door", "LINE")) == 1
assert len(await on(backend, "door", "ARC")) == 1
assert [w["id"] for w in result["walls"]] == ["a"]
assert [o["id"] for o in result["openings"]] == ["d1"]
assert result["omitted"] == []
async def test_the_records_round_trip_through_xdata(backend):
wall = Wall(id="a", axis=((0.0, 0.0), (5000.0, 0.0)), thickness=200.0, material="aac")
window = Opening(id="w1", wall="a", kind="window", offset=2000.0, width=1200.0, tag="W1")
drawn = await draw_walls(backend, [wall], [window])
plan = await read_plan(backend)
assert plan["walls"] == [wall]
assert plan["openings"] == [window]
assert plan["carriers"]["wall:a"] == drawn["walls"][0]["record"]
carrier = drawn["openings"][0]["record"]
assert plan["carriers"]["opening:w1"] == carrier
# the window's record sits on its left-face frame line, with its four lines owned
raw = await backend.entity_get_xdata(carrier, HANDLES_APP)
assert len(raw["xdata"][HANDLES_APP]) == 4
assert (await backend.entity_get_xdata(carrier, APP_ID))["xdata"][APP_ID]
async def test_add_walls_redraws_only_the_wall_the_new_one_joins(backend):
await add_walls(
backend,
[WALL_A, {"id": "c", "axis": [[0.0, 2000.0], [5000.0, 2000.0]], "thickness": 200.0}],
)
result = await add_walls(
backend, [{"id": "b", "axis": [[2500.0, 0.0], [2500.0, 1000.0]], "thickness": 100.0}]
)
assert result["added"] == ["b"]
assert result["redrawn"] == ["a"] # c is not touched by b
faces = {ends(e) for e in await on(backend, "wall", "LINE")}
# a's near face is now cut where b meets it; its far face is still one line
assert ((0.0, 100.0), (2450.0, 100.0)) in faces
assert ((2550.0, 100.0), (5000.0, 100.0)) in faces
assert ((0.0, -100.0), (5000.0, -100.0)) in faces
assert ((0.0, 100.0), (5000.0, 100.0)) not in faces # the old, uncut face was erased
plan = await read_plan(backend)
assert sorted(w.id for w in plan["walls"]) == ["a", "b", "c"]
async def test_an_opening_added_later_cuts_its_wall(backend):
await add_walls(backend, [WALL_A])
before = {ends(e) for e in await on(backend, "wall", "LINE")}
assert ((0.0, 100.0), (5000.0, 100.0)) in before
result = await add_opening(
backend, {"wall": "a", "kind": "door", "offset": 1000.0, "width": 900.0}
)
assert result["opening"] == "D1" and result["tag"] == "D1"
assert result["redrawn"] == ["a"]
after = {ends(e) for e in await on(backend, "wall", "LINE")}
assert ((0.0, 100.0), (5000.0, 100.0)) not in after
assert {((0.0, 100.0), (1000.0, 100.0)), ((1900.0, 100.0), (5000.0, 100.0))} <= after
assert len(await on(backend, "door", "ARC")) == 1
second = await add_opening(
backend, {"wall": "a", "kind": "door", "offset": 3000.0, "width": 800.0}
)
assert second["tag"] == "D2"
assert len(await on(backend, "door", "ARC")) == 2 # the first door was redrawn, not lost
plan = await read_plan(backend)
assert sorted(op.tag for op in plan["openings"]) == ["D1", "D2"]
async def test_an_opening_in_an_unknown_wall_or_overlapping_is_refused_untouched(backend):
await add_walls(backend, [WALL_A])
count = len(await backend.entity_list(limit=10000))
with pytest.raises(ValueError, match="'zz' is not a wall"):
await add_opening(backend, {"wall": "zz", "kind": "door", "offset": 0.0, "width": 900.0})
await add_opening(backend, {"wall": "a", "kind": "window", "offset": 1000.0, "width": 1200.0})
count = len(await backend.entity_list(limit=10000))
with pytest.raises(ValueError):
await add_opening(backend, {"wall": "a", "kind": "door", "offset": 1500.0, "width": 900.0})
assert len(await backend.entity_list(limit=10000)) == count
async def test_a_wall_id_already_drawn_is_refused(backend):
await add_walls(backend, [WALL_A])
with pytest.raises(ValueError, match=r"walls\[0\]\.id: 'a' is already drawn"):
await add_walls(backend, [WALL_A])
async def test_a_new_wall_that_would_swallow_an_opening_is_refused(backend):
await add_walls(backend, [WALL_A])
await add_opening(backend, {"wall": "a", "kind": "door", "offset": 2200.0, "width": 900.0})
count = len(await backend.entity_list(limit=10000))
with pytest.raises(ValueError, match="uncuttable"):
await add_walls(backend, [WALL_B])
assert len(await backend.entity_list(limit=10000)) == count
async def test_draw_stair_writes_its_record_and_reports_blondel(backend):
stair = Stair(
id="s1",
start=(0.0, 0.0),
direction_deg=0.0,
width=1000.0,
risers=17,
riser_height=170.0,
going=290.0,
)
result = await draw_stair(backend, stair)
assert result["blondel"] == {"value": 630.0, "ok": True, "range": [600.0, 650.0]}
assert result["treads"] == 16
assert len(await on(backend, "stair", "LINE")) == 17 + 2 + 2
assert (await read_plan(backend))["stairs"] == [stair]
with pytest.raises(ValueError, match="'s1' is already drawn"):
await add_stair(
backend,
{
"id": "s1",
"start": [0, 0],
"direction_deg": 0.0, # required by Task 1's stair_from_dict
"width": 1000.0,
"risers": 17,
"riser_height": 170.0,
"going": 290.0,
},
)
async def test_draw_chains_puts_real_dimensions_on_the_dimension_layer(backend):
shell = Wall(
id="shell",
axis=((0.0, 0.0), (8200.0, 0.0), (8200.0, 6200.0), (0.0, 6200.0)),
thickness=200.0,
closed=True,
)
result = await draw_chains(backend, [shell], [], sides=("bottom", "left"), scale=50)
dims = await on(backend, "dim", "DIMENSION")
assert len(dims) == result["count"] == 8 # per side: walls (3) + overall (1)
assert {row["row"] for row in result["dimensions"]} == {
"bottom:walls",
"bottom:overall",
"left:walls",
"left:overall",
}
async def test_assign_tags_numbers_each_kind_in_the_chosen_language():
ops = [
Opening(id="1", wall="a", kind="door", offset=0.0, width=900.0),
Opening(id="2", wall="a", kind="window", offset=2000.0, width=900.0),
Opening(id="3", wall="a", kind="door", offset=4000.0, width=900.0, tag="D1"),
]
assert [op.tag for op in assign_tags(ops)] == ["D2", "W1", "D1"]
assert [op.tag for op in assign_tags(ops[:2], lang="tr")] == ["K1", "P1"]
+124
View File
@@ -0,0 +1,124 @@
"""SECTION 25's first four tools, called the way a client calls them.
In-memory client on a fresh headless document; the env var pins ezdxf so no
test here can reach an operator's live drawing (tests/conftest.py).
"""
from __future__ import annotations
import pytest
import pytest_asyncio
from fastmcp import Client
from fastmcp.exceptions import ToolError
import server
pytestmark = pytest.mark.asyncio
ARCH_TOOLS = {"arch_wall", "arch_opening", "arch_stair", "arch_dimension_chains"}
@pytest_asyncio.fixture
async def client(monkeypatch):
monkeypatch.setenv("AUTOCAD_MCP_BACKEND", "ezdxf")
async with Client(server.mcp) as connected:
status = (await connected.call_tool("system_status", {})).structured_content or {}
assert status.get("backend") == "ezdxf", "these tests must never touch live AutoCAD"
await connected.call_tool("drawing_new", {})
yield connected
async def call(client, name, args) -> dict:
return (await client.call_tool(name, args)).structured_content
async def test_the_four_tools_are_registered_under_the_architecture_group():
tools = {tool.name: tool for tool in await server._registered_tools()}
assert ARCH_TOOLS <= set(tools)
groups = await server._tool_groups()
assert set(groups["architecture"]) == ARCH_TOOLS
for name in ARCH_TOOLS:
card = (tools[name].meta or {})["cad"]
assert card["cost"] == "mutate"
assert card["synonyms"], f"{name} needs an alias record"
async def test_a_plan_built_tool_by_tool(client):
walls = await call(
client,
"arch_wall",
{
"walls": [
{
"id": "shell",
"axis": [[0, 0], [8200, 0], [8200, 6200], [0, 6200]],
"thickness": 200,
"closed": True,
}
]
},
)
assert walls["added"] == ["shell"] and walls["redrawn"] == []
partition = await call(
client,
"arch_wall",
{"walls": [{"id": "p", "axis": [[4100, 0], [4100, 6200]], "thickness": 100}]},
)
assert partition["redrawn"] == ["shell"]
door = await call(
client, "arch_opening", {"wall": "shell", "offset": 5500, "width": 1000, "swing": "in"}
)
assert door["tag"] == "D1"
window = await call(
client, "arch_opening", {"wall": "shell", "kind": "window", "offset": 1500, "width": 1200}
)
assert window["tag"] == "W1"
stair = await call(
client,
"arch_stair",
{
"stair_id": "s1",
"start_x": 1000,
"start_y": 1500,
"width": 1000,
"risers": 17,
"riser_height": 170,
"going": 290,
"direction_deg": 90,
},
)
assert stair["blondel"]["ok"] is True
chains = await call(client, "arch_dimension_chains", {"sides": ["bottom"]})
# 5 openings + 5 walls + 1 overall, hand-counted in tests/test_arch_dimension.py
assert chains["count"] == 11
async def test_refusals_come_back_as_tool_errors_that_name_the_cause(client):
with pytest.raises(ToolError, match="no architectural walls"):
await call(client, "arch_dimension_chains", {})
with pytest.raises(ToolError, match="'nowhere' is not a wall"):
await call(client, "arch_opening", {"wall": "nowhere", "offset": 0, "width": 900})
await call(
client, "arch_wall", {"walls": [{"id": "a", "axis": [[0, 0], [5000, 0]], "thickness": 200}]}
)
with pytest.raises(ToolError, match="5°"):
await call(
client,
"arch_wall",
{"walls": [{"id": "b", "axis": [[-2000, -150], [2000, 0]], "thickness": 200}]},
)
with pytest.raises(ToolError, match="at least 4"):
await call(
client,
"arch_stair",
{
"stair_id": "s",
"start_x": 0,
"start_y": 0,
"width": 900,
"risers": 3,
"riser_height": 170,
"going": 290,
"kind": "u",
},
)
+1 -1
View File
@@ -246,7 +246,7 @@ async def test_the_three_track_e_sections_file_under_their_own_groups():
assert set(groups["environment"]) == SETTINGS_TOOLS
assert set(groups["mechanical"]) == MECH_TOOLS
assert set(groups["sheet"]) == SHEET_TOOLS
assert len(groups) == 25
assert len(groups) == 26 # + architecture (SECTION 25, track F)
async def test_system_about_reports_packs():
+9 -2
View File
@@ -495,7 +495,7 @@ async def test_tool_groups_is_byte_identical_to_the_source_declared_grouping():
async def test_tool_group_sizes_are_unchanged():
"""Frozen snapshot of the surface (229 tools, 25 groups).
"""Frozen snapshot of the surface (233 tools, 26 groups).
Taken before @cad_tool landed at 131 tools; `batch` moved 2 -> 3 when
v1.5.0's `cad_batch` joined `entity_batch_create`/`entity_batch_modify`, and
@@ -581,10 +581,17 @@ async def test_tool_group_sizes_are_unchanged():
`sheet`, so pack, group and SECTION are one list again: `engineering`
returned 17 -> 10, `blocks` 11 -> 9, `entity_creation` 19 -> 18 and
`drawing` 12 -> 11 — every one of them its pre-SECTION-24 value.
`architecture` appeared with v1.6's track F: SECTION 25 opened with the
plan model's wall engine (`arch_wall` / `arch_opening` / `arch_stair` /
`arch_dimension_chains`); the `arch` tag is ranked directly after `mech` in
`_GROUP_TAG_PRIORITY`, so those tools file under `architecture` rather
than under their secondary `create` / `dimension` tags.
"""
sizes = {label: len(names) for label, names in (await server._tool_groups()).items()}
assert sizes == {
"analysis": 12,
"architecture": 4,
"batch": 3,
"blocks": 9,
"corner_ops": 4,
@@ -610,4 +617,4 @@ async def test_tool_group_sizes_are_unchanged():
"validation": 1,
"view": 4,
}
assert sum(sizes.values()) == 229
assert sum(sizes.values()) == 233