diff --git a/docs/reference/sheet.md b/docs/reference/sheet.md index aeb7f52b..ed2129d5 100644 --- a/docs/reference/sheet.md +++ b/docs/reference/sheet.md @@ -369,7 +369,7 @@ 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, and envelope height; +leaders, pocket depth leaders, 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; `validate_layout_override()` returns diff --git a/src/draftwright/annotations/_pocket_pad.py b/src/draftwright/annotations/_pocket_pad.py index 8caeceb3..62a4ca49 100644 --- a/src/draftwright/annotations/_pocket_pad.py +++ b/src/draftwright/annotations/_pocket_pad.py @@ -97,6 +97,7 @@ def pocket_jobs(dwg, plan, *, only=None, leader_callout_reach, radial_candidates view_of = _END_ON pocket_groups = list(plan.of_kind("pocket")) jobs = [] + requested_sides = {} for i, g in enumerate( sorted(pocket_groups, key=lambda g: (g.facts.width_axis, g.facts.frame.origin)) ): @@ -116,9 +117,21 @@ def pocket_jobs(dwg, plan, *, only=None, leader_callout_reach, radial_candidates vb = dwg.view_bounds(view) if vb is None: continue + name = f"m_pocket_{pk.width_axis}{pk.long_axis}{i}" + if g.side is not None: + requested_sides[name] = g.side + directions = tuple( + (dx, dy) + for dx, dy in _POCKET_LEAD_DIRS + if g.side is None + or (g.side == "left" and dx < 0) + or (g.side == "right" and dx > 0) + or (g.side == "above" and dy > 0) + or (g.side == "below" and dy < 0) + ) jobs.append( ( - f"m_pocket_{pk.width_axis}{pk.long_axis}{i}", + name, view, vb, _pocket_label( @@ -147,12 +160,13 @@ def pocket_jobs(dwg, plan, *, only=None, leader_callout_reach, radial_candidates ) if wpd is not None and lpd is not None else None, + directions=directions, provenance=g.ref, ), tuple(d.id for d in dimensions), ) ) - return jobs + return jobs, requested_sides def pad_height_jobs(dwg, plan, *, only=None, leader_callout_reach, radial_candidates): diff --git a/src/draftwright/annotations/from_model.py b/src/draftwright/annotations/from_model.py index 07954dda..25e31d20 100644 --- a/src/draftwright/annotations/from_model.py +++ b/src/draftwright/annotations/from_model.py @@ -1689,7 +1689,7 @@ def _oriented_slot_rim_polygon(dwg, view, feature): def render_pockets(dwg, plan, a, *, ctx, only=None) -> int: """Submit compiler-approved pocket leader jobs to the shared late assignment.""" - jobs = _pocket_jobs( + jobs, requested_sides = _pocket_jobs( dwg, plan, only=only, @@ -1704,6 +1704,7 @@ def render_pockets(dwg, plan, a, *, ctx, only=None) -> int: drop_code="pocket_dropped", ctx=ctx, joint=True, + requested_sides=requested_sides, ) diff --git a/src/draftwright/model/planner.py b/src/draftwright/model/planner.py index 2fa2914c..c889e7ef 100644 --- a/src/draftwright/model/planner.py +++ b/src/draftwright/model/planner.py @@ -1819,6 +1819,13 @@ def _check_intent_policy_conflicts(model: PartModel) -> None: def _validate_compound_callout_side(feature, approved, selected_view, requested_side) -> None: """Check a compound callout's requested corridor against its renderer.""" + if feature.kind == "pocket": + if requested_side in {"above", "below", "left", "right"} and all( + pd.side is None or pd.param.role in {"pocket_depth", "pocket_max_depth"} + for pd in approved + ): + return + raise ValueError("pocket leader side is available only for its depth callout") if feature.kind in {"step", "boss"}: diameter_sides = { "x": {"above", "below"}, diff --git a/src/draftwright/sheet_layout_controls.py b/src/draftwright/sheet_layout_controls.py index 3fbab7d1..d3353839 100644 --- a/src/draftwright/sheet_layout_controls.py +++ b/src/draftwright/sheet_layout_controls.py @@ -114,7 +114,7 @@ def layout_options( } # Only advertise sides whose renderer consumes the authored corridor. Other # planner-accepted sides are not an editor actuator until that renderer uses them. - if feature.kind in {"hole", "pattern", "envelope", "step", "boss"}: + if feature.kind in {"hole", "pattern", "envelope", "step", "boss", "pocket"}: placements = sheet.dimension_options(handle, parameter)["placements"] sides = sorted( { diff --git a/tests/test_layout_override_lane_issue_1757.py b/tests/test_layout_override_lane_issue_1757.py index 66fb0c05..dcb61429 100644 --- a/tests/test_layout_override_lane_issue_1757.py +++ b/tests/test_layout_override_lane_issue_1757.py @@ -304,6 +304,58 @@ def test_boss_height_does_not_advertise_diameter_callout_side() -> None: assert result["supported"] is False +@pytest.mark.parametrize( + ("side", "coordinate", "sign"), + [("left", 0, -1), ("right", 0, 1), ("below", 1, -1), ("above", 1, 1)], +) +def test_pocket_callout_side_override_uses_requested_hemisphere(side, coordinate, sign) -> None: + part = Box(100, 80, 10) - Pos(0, 0, 2.5) * Box(40, 20, 5) + sheet = Sheet(part, page="A3", scale=1).authored_dimensions() + pocket = sheet.pocket( + width=20, + length=40, + depth=5, + long_axis="x", + width_axis="y", + depth_axis="z", + lo=-20, + hi=20, + w_center=0, + at=(0, 0, 2.5), + ).identify("declaration:pocket") + sheet.dimension(pocket, "pocket_depth.length") + options = sheet.layout_options("declaration:pocket", parameter="pocket_depth.length") + assert side in options["controls"]["side"]["supported_values"] + sheet.layout_override("declaration:pocket", parameter="pocket_depth.length", side=side) + + drawing = sheet.build() + mark = drawing.get_annotation("m_pocket_yx0") + assert mark is not None + assert sign * (mark.elbow[coordinate] - mark.tip[coordinate]) > 0 + assert not any(issue.code == "placement_unsatisfiable" for issue in drawing.lint()) + + +def test_pocket_width_does_not_advertise_depth_leader_side() -> None: + sheet = Sheet(Box(100, 80, 10)).authored_dimensions() + pocket = sheet.pocket( + width=20, + length=40, + depth=5, + long_axis="x", + width_axis="y", + depth_axis="z", + lo=-20, + hi=20, + w_center=0, + at=(0, 0, 2.5), + ).identify("declaration:pocket") + sheet.dimension(pocket, "pocket_width.length") + result = sheet.validate_layout_override( + "declaration:pocket", parameter="pocket_width.length", side="left" + ) + assert result["supported"] is False + + def test_lane_override_changes_only_the_exact_dimension_policy() -> None: sheet = _slot_sheet() sheet.layout_override("declaration:slot", parameter="slot_width.length", lane=4)