From 46975f8bcbb19fe7bd7d8c639683967b56735057 Mon Sep 17 00:00:00 2001 From: Paul Fremantle Date: Wed, 7 Oct 2026 00:44:14 +0000 Subject: [PATCH] Expose bounded overall height lanes --- docs/reference/sheet.md | 2 +- src/draftwright/annotations/_height_ladder.py | 69 +++++++++++++++++++ src/draftwright/model/compiled.py | 3 + src/draftwright/model/planner.py | 1 + tests/test_layout_override_lane_issue_1757.py | 48 +++++++++++++ 5 files changed, 122 insertions(+), 1 deletion(-) diff --git a/docs/reference/sheet.md b/docs/reference/sheet.md index 9a496369..8aa8d364 100644 --- a/docs/reference/sheet.md +++ b/docs/reference/sheet.md @@ -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: diff --git a/src/draftwright/annotations/_height_ladder.py b/src/draftwright/annotations/_height_ladder.py index 54fb48c9..0ebcbd81 100644 --- a/src/draftwright/annotations/_height_ladder.py +++ b/src/draftwright/annotations/_height_ladder.py @@ -9,8 +9,10 @@ _SIZE_SUBCHAIN, PRIORITY, CorridorCandidate, + InteriorDimensionJob, PlacementContext, dim_footprint, + dimension_candidate_geometry, full_strip_message, ) from draftwright.annotations._common import ( @@ -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, @@ -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), diff --git a/src/draftwright/model/compiled.py b/src/draftwright/model/compiled.py index fec8b4d4..8c3ceaeb 100644 --- a/src/draftwright/model/compiled.py +++ b/src/draftwright/model/compiled.py @@ -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 @@ -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", ( @@ -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: diff --git a/src/draftwright/model/planner.py b/src/draftwright/model/planner.py index adceec03..d4698511 100644 --- a/src/draftwright/model/planner.py +++ b/src/draftwright/model/planner.py @@ -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"), } ) diff --git a/tests/test_layout_override_lane_issue_1757.py b/tests/test_layout_override_lane_issue_1757.py index 4e23fd50..2a551b06 100644 --- a/tests/test_layout_override_lane_issue_1757.py +++ b/tests/test_layout_override_lane_issue_1757.py @@ -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 @@ -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))], @@ -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)