Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions docs/reference/sheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,11 @@ for a Y-axis end-on feature. The solve may report the requested side unplaceable
does not silently switch sides.

Dimension-side overrides currently cover native hole/pattern callouts, step/boss diameter
leaders, pocket depth leaders, slot widths/lengths, and envelope height;
unsupported renderers are not advertised as movable. The side surface accepts `above`,
`below`, `left`, and `right` where the selected renderer supports them;
leaders, pocket depth leaders, slot widths/lengths, and envelope height.
Source-authored `measured_dimension(...)` declarations also expose a side control even when
their original `side` is unset; the options list only corridors their dimension kind and
projection can render. Unsupported dimension kinds are not advertised as movable. The side
surface accepts `above`, `below`, `left`, and `right` where the selected renderer supports them;
`validate_layout_override()` returns
structured `invalid_declaration`, `unsupported_declaration`, `unsupported_control`, or
`unsupported_value` refusals, plus `invalid_control_combination` when side and lane addressing
Expand Down
28 changes: 26 additions & 2 deletions src/draftwright/sheet_layout_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,15 @@ def layout_options(
"controls": controls,
}
side = getattr(feature, "side", None)
if side not in PLACEMENT_SIDES:
if feature.kind == "authored_dimension":
supported_sides = sorted(
candidate
for candidate in PLACEMENT_SIDES
if _authored_dimension_accepts_side(feature, candidate)
)
else:
supported_sides = sorted(PLACEMENT_SIDES) if side in PLACEMENT_SIDES else []
if not supported_sides:
raise ValueError(
f"declaration {declaration_id!r} does not expose a supported side control"
)
Expand All @@ -155,12 +163,28 @@ def layout_options(
"controls": {
"side": {
"current": side,
"supported_values": sorted(PLACEMENT_SIDES),
"supported_values": supported_sides,
}
},
}


def _authored_dimension_accepts_side(feature, side: str) -> bool:
"""Use the IR's renderer-compatible placement validator, not a second side table."""

if feature.dimension_kind not in {"linear", "thickness", "diameter", "radius", "angular"}:
return False
if feature.dimension_kind == "angular" and not (
feature.angular_reference or feature.angular_references
):
return False
try:
replace(feature, side=side)
except (TypeError, ValueError):
return False
return True


def validate_layout_override(
sheet: Sheet,
declaration_id: str,
Expand Down
72 changes: 72 additions & 0 deletions tests/test_layout_override_side_issue_1757.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,78 @@ def test_options_and_validation_are_available_before_build() -> None:
}


def test_unset_authored_dimension_side_is_editable_and_replayable() -> None:
part = Box(40, 20, 10)
sheet = Sheet(part, page="A4", scale=2).authored_dimensions()
sheet.measured_dimension(
kind="linear",
value=40,
label="40",
dominant_axis="X",
ref_pts=((-20, 0, 0), (20, 0, 0)),
).identify("declaration:source-width", provenance="pmi")

options = sheet.layout_options("declaration:source-width")
assert options["controls"]["side"] == {
"current": None,
"supported_values": ["above", "below"],
}
assert (
sheet.validate_layout_override("declaration:source-width", side="right")["issues"][0][
"code"
]
== "unsupported_value"
)
assert sheet.validate_layout_override("declaration:source-width", side="below")["supported"]
sheet.layout_override("declaration:source-width", side="below")

model = sheet.model()
assert model.features[0].side == "below"
assert model.layout_overrides == (LayoutOverride("declaration:source-width", "below"),)
source = emit_sheet_script(
model, "part = source_part", "authored-side", title="authored-side", number="2211"
)
assert 'sheet.layout_override("declaration:source-width", side="below")' in source
namespace = {"source_part": part}
exec( # noqa: S102 - generated Sheet script is the subject of this replay test
compile(source[: source.index("drawing = sheet.build()")], "<authored-side>", "exec"),
namespace,
)
assert namespace["sheet"].model().layout_overrides == model.layout_overrides

drawing = sheet.build()
ink = drawing.annotations_of(model.features[0])
assert len(ink) == 1
_, front_bottom, _, _ = drawing.view_bounds("front")
assert next(iter(ink.values())).label_bbox[3] <= front_bottom
assert drawing.report()["layout"]["overrides"] == [
{
"declaration_id": "declaration:source-width",
"control": "side",
"authored_value": "below",
"resolved_value": "below",
"intent_class": "layout-only",
"status": "applied",
}
]


@pytest.mark.parametrize("kind", ["curve_length", "angular"])
def test_unsupported_authored_dimension_kind_does_not_advertise_side(kind) -> None:
sheet = Sheet(Box(40, 20, 10)).authored_dimensions()
sheet.measured_dimension(
kind=kind,
value=40,
label="40 ARC",
dominant_axis="X",
ref_pts=((-20, 0, 0), (20, 0, 0)),
).identify("declaration:arc")
assert (
sheet.validate_layout_override("declaration:arc", side="below")["issues"][0]["code"]
== "unsupported_declaration"
)


def test_duplicate_live_identity_is_refused_but_withdrawn_identity_can_be_reused() -> None:
sheet = _sheet()
replacement = sheet.add(DatumRef(Frame((-20, 0, 5), "z"), "B", "plan", "above"))
Expand Down
Loading