From 333c9f4cab725a980f4cce5e35028457c4a7bf29 Mon Sep 17 00:00:00 2001 From: Paul Fremantle Date: Tue, 6 Oct 2026 23:32:14 +0000 Subject: [PATCH] Expose supported side controls for authored PMI dimensions --- docs/reference/sheet.md | 8 ++- src/draftwright/sheet_layout_controls.py | 28 +++++++- tests/test_layout_override_side_issue_1757.py | 72 +++++++++++++++++++ 3 files changed, 103 insertions(+), 5 deletions(-) diff --git a/docs/reference/sheet.md b/docs/reference/sheet.md index e48b9460..168e0796 100644 --- a/docs/reference/sheet.md +++ b/docs/reference/sheet.md @@ -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 diff --git a/src/draftwright/sheet_layout_controls.py b/src/draftwright/sheet_layout_controls.py index 946eee14..d50d0771 100644 --- a/src/draftwright/sheet_layout_controls.py +++ b/src/draftwright/sheet_layout_controls.py @@ -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" ) @@ -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, diff --git a/tests/test_layout_override_side_issue_1757.py b/tests/test_layout_override_side_issue_1757.py index 179037fd..22cd6a15 100644 --- a/tests/test_layout_override_side_issue_1757.py +++ b/tests/test_layout_override_side_issue_1757.py @@ -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()")], "", "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"))