feat(sheet): ISO 5457 frames and ISO 7200 title blocks for A4-A0
SECTION 24 opens with sheet_frame and titleblock_apply. engineering/sheet/frames.py transcribes ISO 216's trimmed sizes, ISO 5457's 20 mm filing margin and 10 mm edges, the grid reference system (an even number of divisions per side, that side of the frame over 50 mm; letters from the top, numbers from the left), the centring marks (trimmed edge to 5 mm inside the frame) and the 10 x 5 mm corner trimming marks. Every one of those numbers is pinned by a test against the clause it comes from, because a wrong margin is visible on every drawing this server makes. engineering/sheet/titleblock.py draws the ISO 7200 block -- 180 mm wide, which is exactly the drawing-space width of a portrait A4, which is why one block fits every size -- and carries the ISO 128-30 projection-angle symbol. Which symbol is which is derived rather than remembered: first-angle projection puts the view seen from the left on the right, and the view of the cone from its small end is the small circle inside the large one, so first angle draws the cone left and the circles right. The old A3 module folds in. apply_iso_a3_titleblock now forwards to apply_titleblock(size="A3", projection=None, zones=False, marks=False), which is the geometry it always drew, and tests/test_engineering_titleblock.py passes unchanged -- that is the regression gate for the fold. No new ActiveX member is called: both tools reach the drawing only through contract members the A3 title block has used on both engines since v1.0 (entity_create_polyline / _line / _circle / _text, layout_list, layout_set_current), so there was nothing to probe live. Declared, not glossed: the zone divisions drawn here are equal, so ISO 5457's allowance for shorter corner fields is not implemented; the division counts, which are what a zone reference quotes, are the standard's. ISO 7200's full optional-field list is not transcribed, only the fields this block has a cell for. Coverage is A4-A0; an unknown size is refused by name with the five it has. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FKFStjEFzpGyLq5bMpWxTd
This commit is contained in:
co-authored by
Claude Opus 5
parent
2bb8044144
commit
56e6ff7206
+73
-289
@@ -1,57 +1,71 @@
|
||||
"""ISO 7200 / A3 (420 x 297 mm) title block generator.
|
||||
"""ISO 7200 / A3 title block -- the historical entry point.
|
||||
|
||||
Deterministic — the title text is written verbatim from metadata.
|
||||
The layout moved to `engineering.sheet.titleblock`, which draws every ISO 5457
|
||||
size from A4 to A0. What is left here is the A3 alias: `apply_iso_a3_titleblock`
|
||||
forwards to `apply_titleblock(size="A3", projection=None, zones=False,
|
||||
marks=False)`, which is bit-for-bit the geometry this module drew before -- no
|
||||
projection-angle symbol, no zone grid, no trimming marks -- so every caller and
|
||||
every test that pinned it keeps working. The module-level constants are
|
||||
re-exported for the same reason.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import asdict, dataclass
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from engineering.sheet.frames import (
|
||||
EDGE_MARGIN,
|
||||
FILING_MARGIN,
|
||||
SHEET_LAYER,
|
||||
SHEET_TEXT_LAYER,
|
||||
sheet_size,
|
||||
)
|
||||
from engineering.sheet.titleblock import (
|
||||
LABEL_HEIGHT,
|
||||
ROW1_H,
|
||||
ROW2_H,
|
||||
ROW3_H,
|
||||
ROW4_H,
|
||||
TB_HEIGHT,
|
||||
TB_WIDTH,
|
||||
TITLE_HEIGHT,
|
||||
VALUE_HEIGHT,
|
||||
TitleBlockMetadata,
|
||||
apply_titleblock,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from backends.base import AutoCADBackend
|
||||
|
||||
__all__ = [
|
||||
"BOTTOM_MARGIN",
|
||||
"LABEL_HEIGHT",
|
||||
"LAYER_BORDER",
|
||||
"LAYER_TEXT",
|
||||
"LEFT_MARGIN",
|
||||
"RIGHT_MARGIN",
|
||||
"ROW1_H",
|
||||
"ROW2_H",
|
||||
"ROW3_H",
|
||||
"ROW4_H",
|
||||
"SHEET_H",
|
||||
"SHEET_W",
|
||||
"TB_HEIGHT",
|
||||
"TB_WIDTH",
|
||||
"TITLE_HEIGHT",
|
||||
"TOP_MARGIN",
|
||||
"VALUE_HEIGHT",
|
||||
"TitleBlockMetadata",
|
||||
"apply_iso_a3_titleblock",
|
||||
]
|
||||
|
||||
# A3 paper, ISO 7200 layout constants (mm)
|
||||
SHEET_W = 420.0
|
||||
SHEET_H = 297.0
|
||||
LEFT_MARGIN = 20.0
|
||||
RIGHT_MARGIN = 10.0
|
||||
TOP_MARGIN = 10.0
|
||||
BOTTOM_MARGIN = 10.0
|
||||
|
||||
TB_WIDTH = 180.0
|
||||
TB_HEIGHT = 60.0
|
||||
|
||||
ROW1_H = 20.0 # title
|
||||
ROW2_H = 15.0 # drawing_no | revision | sheet
|
||||
ROW3_H = 15.0 # part_no | material | scale
|
||||
ROW4_H = 10.0 # drawn_by | checked_by | date | company
|
||||
|
||||
LABEL_HEIGHT = 2.0
|
||||
VALUE_HEIGHT = 3.5
|
||||
TITLE_HEIGHT = 5.0
|
||||
|
||||
LAYER_BORDER = "TITLEBLOCK"
|
||||
LAYER_TEXT = "TEXT"
|
||||
|
||||
|
||||
@dataclass
|
||||
class TitleBlockMetadata:
|
||||
"""ISO 7200 title block fields (all strings — no LLM transformation)."""
|
||||
|
||||
title: str
|
||||
drawing_no: str
|
||||
part_no: str = ""
|
||||
material: str = ""
|
||||
scale: str = "1:1"
|
||||
units: str = "mm"
|
||||
drawn_by: str = ""
|
||||
checked_by: str = ""
|
||||
date: str = ""
|
||||
sheet: str = "1/1"
|
||||
revision: str = "A"
|
||||
company: str = "Anka-Makine"
|
||||
SHEET_W, SHEET_H = sheet_size("A3", "landscape")
|
||||
LEFT_MARGIN = FILING_MARGIN
|
||||
RIGHT_MARGIN = EDGE_MARGIN
|
||||
TOP_MARGIN = EDGE_MARGIN
|
||||
BOTTOM_MARGIN = EDGE_MARGIN
|
||||
LAYER_BORDER = SHEET_LAYER
|
||||
LAYER_TEXT = SHEET_TEXT_LAYER
|
||||
|
||||
|
||||
async def apply_iso_a3_titleblock(
|
||||
@@ -63,255 +77,25 @@ async def apply_iso_a3_titleblock(
|
||||
) -> dict:
|
||||
"""Draw a 420x297 ISO 7200 title block at `origin` (lower-left of sheet).
|
||||
|
||||
With `layout`, the sheet is drawn on that paper-space layout — which is
|
||||
With `layout`, the sheet is drawn on that paper-space layout -- which is
|
||||
where a title block belongs, since the border frames the printed sheet
|
||||
rather than the model. The caller's current space is restored afterwards, so
|
||||
asking for a sheet border does not silently move them onto the sheet.
|
||||
Without `layout` it draws in whatever space is current, as it always did.
|
||||
|
||||
Equivalent to `titleblock_apply(size="A3")` with the projection-angle
|
||||
symbol, the zone grid and the trimming marks switched off. Reach for
|
||||
`titleblock_apply` for any other size, or for the symbol.
|
||||
"""
|
||||
|
||||
ox, oy = float(origin[0]), float(origin[1])
|
||||
|
||||
previous_space = "Model"
|
||||
if layout is not None:
|
||||
listing = await backend.layout_list()
|
||||
names = {str(entry) for entry in (listing.get("layouts") or [])}
|
||||
if layout not in names:
|
||||
raise RuntimeError(
|
||||
f"apply_iso_a3_titleblock: layout {layout!r} does not exist "
|
||||
f"(have: {', '.join(sorted(str(n) for n in names))}). Create it with "
|
||||
"layout_create first."
|
||||
)
|
||||
previous_space = getattr(backend, "_current_space", "Model")
|
||||
switched = await backend.layout_set_current(layout)
|
||||
if not switched.get("ok", True):
|
||||
raise RuntimeError(f"apply_iso_a3_titleblock: {switched.get('error')}")
|
||||
|
||||
try:
|
||||
return await _draw_titleblock(backend, metadata=metadata, ox=ox, oy=oy, layout=layout)
|
||||
finally:
|
||||
if layout is not None:
|
||||
await backend.layout_set_current(previous_space)
|
||||
|
||||
|
||||
async def _draw_titleblock(
|
||||
backend: AutoCADBackend,
|
||||
*,
|
||||
metadata: TitleBlockMetadata,
|
||||
ox: float,
|
||||
oy: float,
|
||||
layout: str | None,
|
||||
) -> dict:
|
||||
|
||||
# ---- outer + inner borders -------------------------------------------------
|
||||
outer_pts = [
|
||||
[ox, oy],
|
||||
[ox + SHEET_W, oy],
|
||||
[ox + SHEET_W, oy + SHEET_H],
|
||||
[ox, oy + SHEET_H],
|
||||
]
|
||||
outer = await backend.entity_create_polyline(
|
||||
points=outer_pts,
|
||||
closed=True,
|
||||
layer=LAYER_BORDER,
|
||||
return await apply_titleblock(
|
||||
backend,
|
||||
size="A3",
|
||||
metadata=metadata,
|
||||
origin=origin,
|
||||
orientation="landscape",
|
||||
projection=None,
|
||||
frame=True,
|
||||
zones=False,
|
||||
marks=False,
|
||||
layout=layout,
|
||||
)
|
||||
|
||||
inner_x0 = ox + LEFT_MARGIN
|
||||
inner_y0 = oy + BOTTOM_MARGIN
|
||||
inner_x1 = ox + SHEET_W - RIGHT_MARGIN
|
||||
inner_y1 = oy + SHEET_H - TOP_MARGIN
|
||||
inner_pts = [
|
||||
[inner_x0, inner_y0],
|
||||
[inner_x1, inner_y0],
|
||||
[inner_x1, inner_y1],
|
||||
[inner_x0, inner_y1],
|
||||
]
|
||||
inner = await backend.entity_create_polyline(
|
||||
points=inner_pts,
|
||||
closed=True,
|
||||
layer=LAYER_BORDER,
|
||||
)
|
||||
|
||||
# ---- title block (lower-right corner of inner border) ----------------------
|
||||
tb_x0 = inner_x1 - TB_WIDTH
|
||||
tb_y0 = inner_y0
|
||||
tb_x1 = inner_x1
|
||||
tb_y1 = inner_y0 + TB_HEIGHT
|
||||
|
||||
# Title block frame (closed polyline)
|
||||
tb_frame_pts = [
|
||||
[tb_x0, tb_y0],
|
||||
[tb_x1, tb_y0],
|
||||
[tb_x1, tb_y1],
|
||||
[tb_x0, tb_y1],
|
||||
]
|
||||
tb_frame = await backend.entity_create_polyline(
|
||||
points=tb_frame_pts,
|
||||
closed=True,
|
||||
layer=LAYER_BORDER,
|
||||
)
|
||||
|
||||
# Row baselines (from bottom up): row4_top, row3_top, row2_top
|
||||
row4_top = tb_y0 + ROW4_H
|
||||
row3_top = row4_top + ROW3_H
|
||||
row2_top = row3_top + ROW2_H # == tb_y1 - ROW1_H
|
||||
|
||||
titleblock_lines: list[str] = [tb_frame.handle]
|
||||
|
||||
async def hline(y: float) -> str:
|
||||
ent = await backend.entity_create_line(
|
||||
tb_x0,
|
||||
y,
|
||||
tb_x1,
|
||||
y,
|
||||
layer=LAYER_BORDER,
|
||||
)
|
||||
return ent.handle
|
||||
|
||||
async def vline(x: float, y0: float, y1: float) -> str:
|
||||
ent = await backend.entity_create_line(
|
||||
x,
|
||||
y0,
|
||||
x,
|
||||
y1,
|
||||
layer=LAYER_BORDER,
|
||||
)
|
||||
return ent.handle
|
||||
|
||||
titleblock_lines.append(await hline(row4_top))
|
||||
titleblock_lines.append(await hline(row3_top))
|
||||
titleblock_lines.append(await hline(row2_top))
|
||||
|
||||
# Row 2 splits: left half = drawing_no, then quarter rev, quarter sheet
|
||||
r2_split1 = tb_x0 + TB_WIDTH * 0.5
|
||||
r2_split2 = tb_x0 + TB_WIDTH * 0.75
|
||||
titleblock_lines.append(await vline(r2_split1, row3_top, row2_top))
|
||||
titleblock_lines.append(await vline(r2_split2, row3_top, row2_top))
|
||||
|
||||
# Row 3 splits: thirds — part_no | material | scale
|
||||
r3_split1 = tb_x0 + TB_WIDTH / 3.0
|
||||
r3_split2 = tb_x0 + TB_WIDTH * 2.0 / 3.0
|
||||
titleblock_lines.append(await vline(r3_split1, row4_top, row3_top))
|
||||
titleblock_lines.append(await vline(r3_split2, row4_top, row3_top))
|
||||
|
||||
# Row 4 splits: quarters — drawn_by | checked_by | date | company
|
||||
r4_split1 = tb_x0 + TB_WIDTH * 0.25
|
||||
r4_split2 = tb_x0 + TB_WIDTH * 0.50
|
||||
r4_split3 = tb_x0 + TB_WIDTH * 0.75
|
||||
titleblock_lines.append(await vline(r4_split1, tb_y0, row4_top))
|
||||
titleblock_lines.append(await vline(r4_split2, tb_y0, row4_top))
|
||||
titleblock_lines.append(await vline(r4_split3, tb_y0, row4_top))
|
||||
|
||||
# ---- text content ----------------------------------------------------------
|
||||
label_pad_x = 1.5
|
||||
label_pad_y = 1.5
|
||||
value_pad_x = 3.0
|
||||
value_pad_y = 5.0
|
||||
|
||||
async def label(text: str, x: float, y: float) -> str:
|
||||
ent = await backend.entity_create_text(
|
||||
text=text,
|
||||
x=x,
|
||||
y=y,
|
||||
height=LABEL_HEIGHT,
|
||||
layer=LAYER_TEXT,
|
||||
)
|
||||
return ent.handle
|
||||
|
||||
async def value(text: str, x: float, y: float, height: float = VALUE_HEIGHT) -> str:
|
||||
ent = await backend.entity_create_text(
|
||||
text=text,
|
||||
x=x,
|
||||
y=y,
|
||||
height=height,
|
||||
layer=LAYER_TEXT,
|
||||
)
|
||||
return ent.handle
|
||||
|
||||
# Row 1 — TITLE (verbatim)
|
||||
title_x = tb_x0 + TB_WIDTH * 0.5 - (len(metadata.title) * TITLE_HEIGHT * 0.3)
|
||||
title_y = row2_top + (ROW1_H - TITLE_HEIGHT) / 2.0
|
||||
title_text_handle = await value(metadata.title, title_x, title_y, height=TITLE_HEIGHT)
|
||||
|
||||
value_texts: dict[str, str] = {}
|
||||
|
||||
# Row 2: drawing_no (left half) | revision (3rd qtr) | sheet (4th qtr)
|
||||
await label("DWG NO", tb_x0 + label_pad_x, row2_top - LABEL_HEIGHT - label_pad_y)
|
||||
value_texts["drawing_no"] = await value(
|
||||
metadata.drawing_no,
|
||||
tb_x0 + value_pad_x,
|
||||
row3_top + value_pad_y,
|
||||
)
|
||||
await label("REV", r2_split1 + label_pad_x, row2_top - LABEL_HEIGHT - label_pad_y)
|
||||
value_texts["revision"] = await value(
|
||||
metadata.revision,
|
||||
r2_split1 + value_pad_x,
|
||||
row3_top + value_pad_y,
|
||||
)
|
||||
await label("SHEET", r2_split2 + label_pad_x, row2_top - LABEL_HEIGHT - label_pad_y)
|
||||
value_texts["sheet"] = await value(
|
||||
metadata.sheet,
|
||||
r2_split2 + value_pad_x,
|
||||
row3_top + value_pad_y,
|
||||
)
|
||||
|
||||
# Row 3: part_no | material | scale
|
||||
await label("PART NO", tb_x0 + label_pad_x, row3_top - LABEL_HEIGHT - label_pad_y)
|
||||
value_texts["part_no"] = await value(
|
||||
metadata.part_no,
|
||||
tb_x0 + value_pad_x,
|
||||
row4_top + value_pad_y,
|
||||
)
|
||||
await label("MATERIAL", r3_split1 + label_pad_x, row3_top - LABEL_HEIGHT - label_pad_y)
|
||||
value_texts["material"] = await value(
|
||||
metadata.material,
|
||||
r3_split1 + value_pad_x,
|
||||
row4_top + value_pad_y,
|
||||
)
|
||||
await label("SCALE", r3_split2 + label_pad_x, row3_top - LABEL_HEIGHT - label_pad_y)
|
||||
value_texts["scale"] = await value(
|
||||
metadata.scale,
|
||||
r3_split2 + value_pad_x,
|
||||
row4_top + value_pad_y,
|
||||
)
|
||||
|
||||
# Row 4: drawn_by | checked_by | date | company
|
||||
await label("DRAWN", tb_x0 + label_pad_x, row4_top - LABEL_HEIGHT - label_pad_y)
|
||||
value_texts["drawn_by"] = await value(
|
||||
metadata.drawn_by,
|
||||
tb_x0 + value_pad_x,
|
||||
tb_y0 + 1.5,
|
||||
)
|
||||
await label("CHECKED", r4_split1 + label_pad_x, row4_top - LABEL_HEIGHT - label_pad_y)
|
||||
value_texts["checked_by"] = await value(
|
||||
metadata.checked_by,
|
||||
r4_split1 + value_pad_x,
|
||||
tb_y0 + 1.5,
|
||||
)
|
||||
await label("DATE", r4_split2 + label_pad_x, row4_top - LABEL_HEIGHT - label_pad_y)
|
||||
value_texts["date"] = await value(
|
||||
metadata.date,
|
||||
r4_split2 + value_pad_x,
|
||||
tb_y0 + 1.5,
|
||||
)
|
||||
await label("COMPANY", r4_split3 + label_pad_x, row4_top - LABEL_HEIGHT - label_pad_y)
|
||||
value_texts["company"] = await value(
|
||||
metadata.company,
|
||||
r4_split3 + value_pad_x,
|
||||
tb_y0 + 1.5,
|
||||
)
|
||||
|
||||
return {
|
||||
"ok": True,
|
||||
"layout": layout or "Model",
|
||||
"outer_border": outer.handle,
|
||||
"inner_border": inner.handle,
|
||||
"titleblock_lines": titleblock_lines,
|
||||
"title_text": title_text_handle,
|
||||
"value_texts": value_texts,
|
||||
"metadata": asdict(metadata),
|
||||
"bbox": {
|
||||
"min": [ox, oy],
|
||||
"max": [ox + SHEET_W, oy + SHEET_H],
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user