diff --git a/docs/reference/sheet.md b/docs/reference/sheet.md index 168e0796..4749a814 100644 --- a/docs/reference/sheet.md +++ b/docs/reference/sheet.md @@ -359,8 +359,8 @@ integer from 1 through 8: a one-based drafting-spaced rank from that dimension's 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, and step diameter leaders. -Capability is +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/_common.py b/src/draftwright/annotations/_common.py index daf34eff..1c922999 100644 --- a/src/draftwright/annotations/_common.py +++ b/src/draftwright/annotations/_common.py @@ -1505,16 +1505,7 @@ def register_corridor(ctx, key, strip, view, axis, tier, cand): def _drain_interior_dimensions(ctx, dwg) -> None: - """Place automatic fallbacks and declared lanes as one whole-annotation batch. - - Automatic jobs enter only after a genuine exterior failure. Declared jobs contribute - one compiler-derived feature-relative position. The stage moves complete dimensions, - admits candidates only when their label is wholly interior or wholly exterior, and - requires the complete annotation to clear fixed ink. The generic exact assignment - then arbitrates pairwise conflicts; a job with no survivor calls its original drop - handler unchanged. When tracing is enabled, the same stage records candidate - positions and rejection categories without running a second placement solve. - """ + """Validate whole ink and jointly assign automatic fallbacks and declared lanes.""" jobs = getattr(ctx, "interior_dimensions", None) if not jobs: @@ -1601,8 +1592,15 @@ def record(job, job_candidates, job_costs, choice, outcome, reason=None) -> None if box[0] < page[0] or box[1] < page[1] or box[2] > page[2] or box[3] > page[3]: reject(job, "page_bounds") continue - if region is DimensionCandidateRegion.INTERIOR and not label_clear(label): - reject(job, "projected_view_ink") + if region is DimensionCandidateRegion.INTERIOR and ( + ctx.exterior_dimensions_only or not label_clear(label) + ): + reject( + job, + "profile_exterior_only" + if ctx.exterior_dimensions_only + else "projected_view_ink", + ) continue # View ownership is provenance, not a clipping boundary: ink owned # by an adjacent projection may still cross this view in page space. diff --git a/src/draftwright/annotations/_envelope.py b/src/draftwright/annotations/_envelope.py index 6e936310..e340c05b 100644 --- a/src/draftwright/annotations/_envelope.py +++ b/src/draftwright/annotations/_envelope.py @@ -18,6 +18,7 @@ _WITNESS_LIFT_MM, Analysis, Strip, + _dim, _tol_suffix, ) from draftwright.annotations._common import ( @@ -160,6 +161,78 @@ def _interior_build(pos, _l=lift): self.report(name) +@dataclass(frozen=True, slots=True) +class _EnvelopeLaneDrop: + """Preserve exact lane and blocker evidence when a declared extent cannot fit.""" + + ctx: PlacementContext + role: str + view: str + lane: int + measurement: DimensionId | None + measurement_span: tuple[Point, Point] | None + rejections: list[str] + + def __call__(self, _name: str) -> None: + reasons = sorted(set(self.rejections)) or ["no_admissible_candidate"] + blockers = ", ".join(reasons) + self.ctx.record_issue( + "error", + "overall_dim_withheld", + f"overall {self.role} dimension not placed (requested lane {self.lane} " + f"unavailable beside the {self.view}; blockers: {blockers})", + measurement=self.measurement, + measurement_span=self.measurement_span, + evidence_reason=f"requested_lane_unavailable:{self.lane}:{','.join(reasons)}", + outcome_stage="placement", + ) + + +def _queue_declared_envelope_lane( + dwg, ctx, env, extent, role, view, zones, slot, name, p1, p2, label +): + """Offer one witness-relative lane to the shared whole-dimension solve.""" + + assert extent.lane is not None + rejections: list[str] = [] + drop = _EnvelopeLaneDrop(ctx, role, view, extent.lane, extent.id, extent.span, rejections) + jobs = getattr(ctx, "interior_dimensions", None) + if jobs is None: + rejections.append("measured_lane_solve_unavailable") + drop(name) + return + witness = p1[1] - _WITNESS_LIFT_MM + lane_step = slot + (zones.below.spacing if zones.below is not None else _STRIP_SPACING) + position = witness - (2 * dwg.draft.extension_gap + extent.lane * lane_step) + start, end = (p1[0], witness, 0), (p2[0], witness, 0) + + def build(pos): + return _dim(start, end, "below", witness - pos, dwg.draft, label=label) + + jobs.append( + InteriorDimensionJob( + name=name, + view=view, + side="below", + build=build, + on_place=lambda _name: None, + on_drop=drop, + lane_step=lane_step, + priority=_MANDATORY_OVERALL_PRIORITY, + feature=env.ref, + measurement=extent.id, + measurement_span=extent.span, + interior_build=build, + analytical_geometry=lambda pos: dimension_candidate_geometry( + start, end, "below", witness - pos, dwg.draft, label + ), + explicit_position=position, + requested_lane=extent.lane, + rejection_reasons=rejections, + ) + ) + + def render_envelope( dwg, plan, @@ -301,6 +374,12 @@ def _one_tier_fits(strip, slot=slot): witness = p1[1] - _WITNESS_LIFT_MM zones = frame.zones(view) label = _env_label(extent, dwg.draft) + if getattr(extent, "lane", None) is not None: + _queue_declared_envelope_lane( + dwg, ctx, env, extent, role, view, zones, slot, ann_name, p1, p2, label + ) + n += 1 + continue _queue( ann_name, zones.below, diff --git a/src/draftwright/annotations/_slots.py b/src/draftwright/annotations/_slots.py index d6dcd3c4..5e22b474 100644 --- a/src/draftwright/annotations/_slots.py +++ b/src/draftwright/annotations/_slots.py @@ -328,7 +328,7 @@ def _shared_placed(nm, _owners=shared_owners): # coordinate. Automatic dimensions retain their established exterior path. if approved.lane is not None: jobs = getattr(ctx, "interior_dimensions", None) - if jobs is None or ctx.exterior_dimensions_only: + if jobs is None: return False _candidate_name, lane_build = _cand_for(near_side, near_hi) witness = perp_proj(perp_hi if near_hi else perp_lo) diff --git a/src/draftwright/model/planner.py b/src/draftwright/model/planner.py index 70e8dfd5..17d7b26c 100644 --- a/src/draftwright/model/planner.py +++ b/src/draftwright/model/planner.py @@ -608,6 +608,8 @@ def _is_zero_step_position(value: float) -> bool: ("slot", "slot_length.length"), ("rotational", "od.diameter"), ("step", "step.diameter"), + ("envelope", "width.length"), + ("envelope", "depth.length"), } ) diff --git a/tests/test_interior_label_placement.py b/tests/test_interior_label_placement.py index c950f041..3de91610 100644 --- a/tests/test_interior_label_placement.py +++ b/tests/test_interior_label_placement.py @@ -423,6 +423,46 @@ def dimension(position): ) +def test_exterior_only_profile_refuses_an_interior_declared_lane(monkeypatch): + dropped = [] + rejections = [] + + def dimension(position): + return SimpleNamespace( + label_bbox=(position - 2.0, 15.0, position + 2.0, 18.0), + box=(position - 3.0, 10.0, position + 3.0, 22.0), + ) + + ctx = _common.PlacementContext( + exterior_dimensions_only=True, + interior_dimensions=[ + _common.InteriorDimensionJob( + name="inside", + view="front", + side="right", + build=dimension, + on_place=lambda _name: pytest.fail("interior lane was placed"), + on_drop=dropped.append, + lane_step=5.0, + interior_build=dimension, + explicit_position=20.0, + requested_lane=3, + rejection_reasons=rejections, + ) + ], + ) + drawing = SimpleNamespace(view_bounds=lambda _view: (0.0, 0.0, 40.0, 40.0)) + monkeypatch.setattr(_common, "_drawing_bounds", lambda _drawing: (0.0, 0.0, 50.0, 50.0)) + monkeypatch.setattr(_common, "view_label_clearance", lambda *_args: lambda _box: True) + monkeypatch.setattr(_common, "annotation_ink_clear", lambda *_args, **_kwargs: True) + monkeypatch.setattr(_common, "_geom_box", lambda annotation: annotation.box) + + _common._drain_interior_dimensions(ctx, drawing) + + assert dropped == ["inside"] + assert rejections == ["profile_exterior_only"] + + def test_declared_lane_that_straddles_the_view_boundary_fails_closed(monkeypatch): dropped = [] rejection_reasons = [] diff --git a/tests/test_layout_override_lane_issue_1757.py b/tests/test_layout_override_lane_issue_1757.py index 72f72098..46cc43f8 100644 --- a/tests/test_layout_override_lane_issue_1757.py +++ b/tests/test_layout_override_lane_issue_1757.py @@ -15,6 +15,7 @@ from draftwright.annotations._axial_render import _place_or_queue_rotational_od 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.from_model import _record_slot_drop from draftwright.model.ir import LayoutOverride, RequestedDimension from draftwright.registry import AnnotationRegistry @@ -414,6 +415,35 @@ def test_upright_slot_side_options_follow_projected_axes(width_axis) -> None: ]["supported_values"] == ["left", "right"] +@pytest.mark.parametrize( + ("parameter", "label", "name"), + [ + ("width.length", "50", "m_env_width"), + ("depth.length", "30", "m_env_depth"), + ], +) +def test_envelope_lane_is_witness_relative_and_reported(parameter, label, name) -> None: + sheet = Sheet(Box(50, 30, 10), page="A4", scale=2).authored_dimensions() + envelope = sheet.envelope().identify("declaration:overall") + sheet.dimension(envelope, parameter) + options = sheet.layout_options("declaration:overall", parameter=parameter) + assert options["controls"]["lane"]["current"] is None + assert sheet.validate_layout_override("declaration:overall", parameter=parameter, lane=1)[ + "supported" + ] + + sheet.layout_override("declaration:overall", parameter=parameter, lane=1) + drawing = sheet.build() + dimension = drawing.get_annotation(name) + assert dimension.label == label + view = drawing.registry.view_of(name) + assert view is not None + _, bottom, _, _ = drawing.view_bounds(view) + assert dimension.label_bbox[3] <= bottom + assert drawing.report()["layout"]["overrides"][0]["parameter_id"] == parameter + assert drawing.report()["layout"]["overrides"][0]["resolved_value"] == 1 + + 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) @@ -555,6 +585,31 @@ def test_impossible_lane_drop_retains_bounded_blocker_evidence() -> None: ) +def test_impossible_envelope_lane_reports_the_missing_measurement() -> None: + context = PlacementContext(registry=AnnotationRegistry()) + blockers = ["view_boundary_straddle", "page_bounds", "page_bounds"] + _EnvelopeLaneDrop(context, "width", "plan", 8, None, None, blockers)("m_env_width") + + (issue,) = context.registry.issues + assert issue.code == "overall_dim_withheld" + assert "requested lane 8 unavailable" in issue.message + assert ( + issue.evidence_reason == "requested_lane_unavailable:8:page_bounds,view_boundary_straddle" + ) + + +def test_envelope_lane_without_batch_solve_reports_refusal() -> None: + context = PlacementContext(registry=AnnotationRegistry()) + extent = SimpleNamespace(lane=2, id=None, span=None) + _queue_declared_envelope_lane( + None, context, None, extent, "width", "plan", None, None, "m_env_width", None, None, None + ) + + (issue,) = context.registry.issues + assert issue.code == "overall_dim_withheld" + 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)