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 @@ -360,7 +360,7 @@ witness, not a distance. The shared measured-candidate solve may resolve it into
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 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
overall width/depth/height 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
69 changes: 69 additions & 0 deletions src/draftwright/annotations/_height_ladder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
_SIZE_SUBCHAIN,
PRIORITY,
CorridorCandidate,
InteriorDimensionJob,
PlacementContext,
dim_footprint,
dimension_candidate_geometry,
full_strip_message,
)
from draftwright.annotations._common import (
Expand Down Expand Up @@ -100,6 +102,69 @@ def drop(self, _name: str) -> None:
)


def _queue_declared_height_lane(
rung: _HeightRungCandidate, lane: int, tier: float, feature
) -> None:
"""Submit one bounded height lane as a complete measured dimension candidate."""

rejections: list[str] = []

def drop(_name: str) -> None:
rung.solved.pop(rung.name, None)
blockers = sorted(set(rejections)) or ["no_admissible_candidate"]
rung.ctx.record_issue(
"error",
"placement_unsatisfiable",
f"overall height dimension not placed (requested lane {lane} unavailable "
f"beside the {rung.view}; blockers: {', '.join(blockers)})",
measurement=rung.measurement,
measurement_span=rung.measurement_span,
evidence_reason=f"requested_lane_unavailable:{lane}:{','.join(blockers)}",
outcome_stage="placement",
)

jobs = rung.ctx.interior_dimensions
if jobs is None:
rejections.append("measured_lane_solve_unavailable")
drop(rung.name)
return
lane_step = tier + rung.strip.spacing
position = rung.edge + rung.direction * (2 * rung.draft.extension_gap + lane * lane_step)
label = rung.label + _tol_suffix(rung.tolerance, rung.draft)

def geometry(pos):
base = rung.witness_base(pos)
return dimension_candidate_geometry(
(base, rung.zbase, 0),
(base, rung.ztop, 0),
rung.side,
rung.direction * (pos - base),
rung.draft,
label,
)

jobs.append(
InteriorDimensionJob(
name=rung.name,
view=rung.view,
side=rung.side,
build=rung.build,
on_place=lambda _name: None,
on_drop=drop,
lane_step=lane_step,
priority=PRIORITY.PRINCIPAL,
feature=feature,
measurement=rung.measurement,
measurement_span=rung.measurement_span,
interior_build=rung.build,
analytical_geometry=geometry,
explicit_position=position,
requested_lane=lane,
rejection_reasons=rejections,
)
)


def register_height_ladder_candidates(
dwg,
frame,
Expand Down Expand Up @@ -192,6 +257,10 @@ def register_height_ladder_candidates(
solved=solved,
)

if name == "dim_height" and overall is not None and overall.rungs[0].lane is not None:
_queue_declared_height_lane(rung, overall.rungs[0].lane, tier, overall.ref)
continue

register_corridor(
ctx,
(view, side),
Expand Down
3 changes: 3 additions & 0 deletions src/draftwright/model/compiled.py
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,7 @@ def _compile_overall_height(
height_tol = None
height_side = None
height_view = None
height_lane = None
if env is not None:
height_param = next(pm for pm in env.parameters() if pm.role == "height")
height_tol = _decorated(model, env, height_param).tolerance
Expand All @@ -1320,6 +1321,7 @@ def _compile_overall_height(
if height_intent is not None:
height_side = height_intent.side
height_view = height_intent.view
height_lane = height_intent.lane
ladder = ApprovedLadder(
"overall_height",
(
Expand All @@ -1333,6 +1335,7 @@ def _compile_overall_height(
tolerance=height_tol,
side=height_side,
view=height_view,
lane=height_lane,
# `rendered_label` is the BARE value while `tolerance` is set beside it, so for
# a toleranced rung this field is not the "complete compiler-owned label" its
# own docstring promises — the renderer composes the suffix. It has to:
Expand Down
1 change: 1 addition & 0 deletions src/draftwright/model/planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ def _is_zero_step_position(value: float) -> bool:
("envelope", "depth.length"),
("pocket", "pocket_width.length"),
("pocket", "pocket_length.length"),
("envelope", "height.length"),
}
)

Expand Down
48 changes: 48 additions & 0 deletions tests/test_layout_override_lane_issue_1757.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
from draftwright.annotations._common import PlacementContext
from draftwright.annotations._diameters import _render_diameter_controls
from draftwright.annotations._envelope import _EnvelopeLaneDrop, _queue_declared_envelope_lane
from draftwright.annotations._height_ladder import _queue_declared_height_lane
from draftwright.annotations.from_model import _record_slot_drop
from draftwright.model.compiled import compile_dimensions
from draftwright.model.ir import LayoutOverride, RequestedDimension
from draftwright.registry import AnnotationRegistry
from draftwright.sheet_emit import emit_sheet_script
Expand Down Expand Up @@ -87,6 +89,35 @@ def test_lane_capability_targets_one_declared_parameter() -> None:
assert unsupported["issues"][0]["code"] == "unsupported_declaration"


def test_envelope_height_lane_moves_the_complete_dimension_and_replays() -> None:
positions = []
for lane in (1, 2):
sheet = Sheet(Box(50, 30, 10), page="A4", scale=2).authored_dimensions()
envelope = sheet.envelope().identify("declaration:overall")
sheet.dimension(envelope, "height.length")
assert (
"lane"
in sheet.layout_options("declaration:overall", parameter="height.length")["controls"]
)
sheet.layout_override("declaration:overall", parameter="height.length", lane=lane)
model = sheet.model()
overall = compile_dimensions(model).ladder("overall_height")
assert overall is not None and overall.rungs[0].lane == lane
source = emit_sheet_script(model, "part", "height", title="height", number="H")
assert (
f'sheet.layout_override("declaration:overall", parameter="height.length", lane={lane})'
in source
)
drawing = sheet.build()
assert not any(issue.code == "placement_unsatisfiable" for issue in drawing.lint())
dimension = drawing.get_annotation("dim_height")
assert dimension is not None
positions.append(dimension.bounding_box().max.X)
report = drawing.report()
assert report["layout"]["overrides"][0]["resolved_value"] == lane
assert positions[1] > positions[0]


@pytest.mark.parametrize(
("axis", "rotation"),
[("z", (0, 0, 0)), ("x", (0, 90, 0)), ("y", (90, 0, 0))],
Expand Down Expand Up @@ -692,6 +723,23 @@ def test_envelope_lane_without_batch_solve_reports_refusal() -> None:
assert issue.evidence_reason == "requested_lane_unavailable:2:measured_lane_solve_unavailable"


def test_height_lane_without_batch_solve_reports_refusal() -> None:
context = PlacementContext(registry=AnnotationRegistry())
rung = SimpleNamespace(
ctx=context,
name="dim_height",
solved={},
view="front",
measurement=None,
measurement_span=None,
)
_queue_declared_height_lane(rung, 2, 1.0, None)

(issue,) = context.registry.issues
assert issue.code == "placement_unsatisfiable"
assert issue.evidence_reason == "requested_lane_unavailable:2:measured_lane_solve_unavailable"


def test_lane_override_round_trips_and_reports_layout_only_evidence() -> None:
sheet = _slot_sheet()
sheet.layout_override("declaration:slot", parameter="slot_width.length", lane=4)
Expand Down
Loading