diff --git a/docs/reference/sheet.md b/docs/reference/sheet.md index 4749a814..9a496369 100644 --- a/docs/reference/sheet.md +++ b/docs/reference/sheet.md @@ -358,9 +358,9 @@ the dimension renderer actually consumes. A lane is an integer from 1 through 8: a one-based drafting-spaced rank from that dimension's physical witness, not a distance. The shared measured-candidate solve may resolve it into proven whitespace inside or outside the view and records that candidate's region explicitly. The -current lane-capable slice is the linear width/length dimensions of slots, the -overall OD diameter of a rotational feature, step diameter leaders, and the overall -width/depth dimensions of an envelope. Capability is +current lane-capable slice is the linear width/length dimensions of slots and rectangular +pockets, the overall OD diameter of a rotational feature, step diameter leaders, and the +overall width/depth dimensions of an envelope. Capability is declared in one compiler-owned registry so another dimension family is added deliberately, not by teaching each renderer a private spelling. For a declared step or boss diameter, `side=` can instead select a bounded leader hemisphere: diff --git a/src/draftwright/annotations/_pocket_pad.py b/src/draftwright/annotations/_pocket_pad.py index 62a4ca49..28b519ae 100644 --- a/src/draftwright/annotations/_pocket_pad.py +++ b/src/draftwright/annotations/_pocket_pad.py @@ -105,8 +105,12 @@ def pocket_jobs(dwg, plan, *, only=None, leader_callout_reach, radial_candidates if only is not None and g.ref not in only: continue # #426 Ph2b subset (finalize): skip in place — i stays the model index by_key = {(pd.role, pd.kind): pd for pd in g.dims} - wpd = by_key.get(("pocket_width", "length")) - lpd = by_key.get(("pocket_length", "length")) + width = by_key.get(("pocket_width", "length")) + length = by_key.get(("pocket_length", "length")) + # A size carrying a declared lane is rendered as a linear dimension by + # _slots. Never repeat that measurement in the pocket's combined leader. + wpd = width if width is not None and width.lane is None else None + lpd = length if length is not None and length.lane is None else None dpd = by_key.get(("pocket_depth", "length")) or by_key.get(("pocket_max_depth", "length")) dimensions = tuple(d for d in (wpd, lpd, dpd) if d is not None) if not dimensions: @@ -155,10 +159,10 @@ def pocket_jobs(dwg, plan, *, only=None, leader_callout_reach, radial_candidates pk, long_axis=pk.long_axis, width_axis=pk.width_axis, - length=lpd.value, - width=wpd.value, + length=length.value, + width=width.value, ) - if wpd is not None and lpd is not None + if width is not None and length is not None else None, directions=directions, provenance=g.ref, diff --git a/src/draftwright/annotations/_slots.py b/src/draftwright/annotations/_slots.py index 5e22b474..b5978ecb 100644 --- a/src/draftwright/annotations/_slots.py +++ b/src/draftwright/annotations/_slots.py @@ -448,6 +448,14 @@ def _shared_placed(nm, _owners=shared_owners): return True # deferred — the callback owns the drop; caller's else must not fire +def _footprint_size(group, feature, role): + """Select an approved linear size; a pocket moves out of its leader only by lane.""" + approved = group.dim(role=f"{feature.kind}_{role}", kind="length") + if feature.kind == "pocket" and approved is not None and approved.lane is None: + return None + return approved + + def _render_slot_dimensions(dwg, plan, a: Analysis, *, ctx, only=None, reach) -> tuple[int, list]: """Build compiled slot-family dimensions and collect late radius jobs. @@ -543,9 +551,8 @@ def _shared_width_key(slot, approved): ) # Bind each approved dim explicitly by (role, kind) — never positionally. - role_prefix = s.kind if s.kind in ("pad", "slot") else "" - wpd = g.dim(role=f"{role_prefix}_width", kind="length") - lpd = g.dim(role=f"{role_prefix}_length", kind="length") + wpd = _footprint_size(g, s, "width") + lpd = _footprint_size(g, s, "length") rpd = g.dim(role="slot_end_radius", kind="radius") if s.kind == "slot" else None half = s.width / 2 if wpd is not None: diff --git a/src/draftwright/model/planner.py b/src/draftwright/model/planner.py index 17d7b26c..adceec03 100644 --- a/src/draftwright/model/planner.py +++ b/src/draftwright/model/planner.py @@ -610,6 +610,8 @@ def _is_zero_step_position(value: float) -> bool: ("step", "step.diameter"), ("envelope", "width.length"), ("envelope", "depth.length"), + ("pocket", "pocket_width.length"), + ("pocket", "pocket_length.length"), } ) diff --git a/tests/test_layout_override_lane_issue_1757.py b/tests/test_layout_override_lane_issue_1757.py index 46cc43f8..4e23fd50 100644 --- a/tests/test_layout_override_lane_issue_1757.py +++ b/tests/test_layout_override_lane_issue_1757.py @@ -444,6 +444,88 @@ def test_envelope_lane_is_witness_relative_and_reported(parameter, label, name) assert drawing.report()["layout"]["overrides"][0]["resolved_value"] == 1 +@pytest.mark.parametrize( + ("parameter", "label", "name"), + [ + ("pocket_width.length", "8", "m_pocket0_width"), + ("pocket_length.length", "14", "m_pocket0_length"), + ], +) +def test_rectangular_pocket_size_lanes_use_shared_dimension_solve(parameter, label, name) -> None: + part = Box(80, 50, 20) - Pos(0, 0, 4) * Box(14, 8, 12) + sheet = Sheet(part, page="A4", scale=2).authored_dimensions() + pocket = sheet.pocket( + width=8, + length=14, + depth=12, + long_axis="x", + width_axis="y", + depth_axis="z", + lo=-7, + hi=7, + w_center=0, + at=(0, 0, 4), + ).identify("declaration:pocket") + sheet.dimension(pocket, parameter) + options = sheet.layout_options("declaration:pocket", parameter=parameter) + assert options["controls"]["lane"]["current"] is None + sheet.layout_override("declaration:pocket", parameter=parameter, lane=1) + + drawing = sheet.build() + dimension = drawing.get_annotation(name) + assert dimension.label == label + assert drawing.report()["layout"]["overrides"][0]["parameter_id"] == parameter + + +def test_pocket_lane_moves_only_its_size_out_of_the_combined_leader() -> None: + part = Box(80, 50, 20) - Pos(0, 0, 4) * Box(14, 8, 12) + sheet = Sheet(part, page="A3", scale=2).authored_dimensions() + pocket = sheet.pocket( + width=8, + length=14, + depth=12, + long_axis="x", + width_axis="y", + depth_axis="z", + lo=-7, + hi=7, + w_center=0, + at=(0, 0, 4), + ).identify("declaration:pocket") + for parameter in ("pocket_width.length", "pocket_length.length", "pocket_depth.length"): + sheet.dimension(pocket, parameter) + sheet.layout_override("declaration:pocket", parameter="pocket_width.length", lane=1) + + drawing = sheet.build() + assert drawing.get_annotation("m_pocket0_width").label == "8" + assert drawing.get_annotation("m_pocket_yx0").label == "POCKET 14 LONG, 12 DEEP" + assert not any(issue.code == "pocket_dim_dropped" for issue in drawing.lint()) + + +def test_pocket_without_lane_keeps_the_combined_leader() -> None: + part = Box(80, 50, 20) - Pos(0, 0, 4) * Box(14, 8, 12) + sheet = Sheet(part).authored_dimensions() + pocket = sheet.pocket( + width=8, + length=14, + depth=12, + long_axis="x", + width_axis="y", + depth_axis="z", + lo=-7, + hi=7, + w_center=0, + at=(0, 0, 4), + ) + for parameter in ("pocket_width.length", "pocket_length.length", "pocket_depth.length"): + sheet.dimension(pocket, parameter) + + drawing = sheet.build() + assert drawing.get_annotation("m_pocket_yx0").label == "8 × 14 × 12 DEEP" + assert drawing.get_annotation("m_pocket0_width") is None + assert drawing.get_annotation("m_pocket0_length") is None + + 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)