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
6 changes: 3 additions & 3 deletions docs/reference/sheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 9 additions & 5 deletions src/draftwright/annotations/_pocket_pad.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 10 additions & 3 deletions src/draftwright/annotations/_slots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions src/draftwright/model/planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
)

Expand Down
82 changes: 82 additions & 0 deletions tests/test_layout_override_lane_issue_1757.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading