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
2 changes: 1 addition & 1 deletion docs/reference/sheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 16 additions & 2 deletions src/draftwright/annotations/_pocket_pad.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
):
Expand All @@ -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(
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion src/draftwright/annotations/from_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
)


Expand Down
7 changes: 7 additions & 0 deletions src/draftwright/model/planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
2 changes: 1 addition & 1 deletion src/draftwright/sheet_layout_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down
52 changes: 52 additions & 0 deletions tests/test_layout_override_lane_issue_1757.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading