diff --git a/src/draftwright/annotations/orchestrator.py b/src/draftwright/annotations/orchestrator.py index 77c5e7df..fcb6e00b 100644 --- a/src/draftwright/annotations/orchestrator.py +++ b/src/draftwright/annotations/orchestrator.py @@ -402,6 +402,9 @@ def _place_manufacturing_schedule(dwg: DrawingPort, schedule, ctx) -> bool: # emitted, so restore its speculative drop and use full direct labels. ctx.registry.restore_issues(issues) return False + # This schedule precedes PMI/GD&T and the corridor drain. Late general + # notes, gear tables and hole tables cannot block those source candidates. + table.precedes_source_placement = True table.source_ids = schedule.source_ids table.manufacturing_source_ids = schedule.source_ids_by_tag ctx.manufacturing_tags = schedule.tags_by_source diff --git a/src/draftwright/build_policy.py b/src/draftwright/build_policy.py index c299d02a..f512a9de 100644 --- a/src/draftwright/build_policy.py +++ b/src/draftwright/build_policy.py @@ -537,8 +537,10 @@ def _principal_view_exceeds_page(scale, page, bounds, views) -> bool: Use only the part's world-space box and the *full* page: omitting even the mandatory gutters, margins and annotation footprints makes this a necessary - bound, never a speculative fit verdict. No ink solve can rescue a rejected - scale. + bound, never a speculative fit verdict. Front and side occupy separate + horizontal bands; front and plan occupy separate vertical bands. Even if + every gap shrank to zero, their combined bare spans must fit. No ink solve + can rescue a rejected scale. """ extents = { "x": bounds.max.X - bounds.min.X, @@ -547,12 +549,17 @@ def _principal_view_exceeds_page(scale, page, bounds, views) -> bool: } axes = {"front": ("x", "z"), "plan": ("x", "y"), "side": ("y", "z")} page_w, page_h = page - return any( + if any( extents[horizontal] * scale > page_w + 1e-9 or extents[vertical] * scale > page_h + 1e-9 for view in views if (pair := axes.get(view)) is not None for horizontal, vertical in (pair,) - ) + ): + return True + selected = set(views) + return ( + {"front", "side"} <= selected and (extents["x"] + extents["y"]) * scale > page_w + 1e-9 + ) or ({"front", "plan"} <= selected and (extents["z"] + extents["y"]) * scale > page_h + 1e-9) def _has_detail_view(views) -> bool: diff --git a/src/draftwright/builder.py b/src/draftwright/builder.py index 6dfe04bf..1b2a5093 100644 --- a/src/draftwright/builder.py +++ b/src/draftwright/builder.py @@ -1128,10 +1128,11 @@ def _needs_repack(dwg, a) -> bool: def _source_placement_drop_with_table(dwg) -> bool: - """A table may take required annotation space after the seed layout. + """A pre-solve table may take required source-annotation space. - Repack the measured blocks when that happens. An unselected view's geometry - cannot act as the accidental trigger: it has no ink on the finished sheet. + Late tables fit around already placed annotation ink, so their presence + cannot explain an earlier source drop. Repack only for a table committed + before those placements. """ if not any( getattr(issue, "outcome_stage", None) == "placement" @@ -1142,6 +1143,7 @@ def _source_placement_drop_with_table(dwg) -> bool: return False return any( getattr(annotation, "table_rows", None) is not None + and getattr(annotation, "precedes_source_placement", False) for _name, annotation in dwg.iter_annotations() ) diff --git a/tests/test_issue_1146_scale_completeness.py b/tests/test_issue_1146_scale_completeness.py index 565b5bd1..24791394 100644 --- a/tests/test_issue_1146_scale_completeness.py +++ b/tests/test_issue_1146_scale_completeness.py @@ -567,7 +567,23 @@ def test_principal_projection_must_fit_inside_the_physical_page(): page = (1189.0, 841.0) assert not builder._principal_view_exceeds_page(0.5, page, bounds, ("front", "plan", "side")) assert builder._principal_view_exceeds_page(1.0, page, bounds, ("front", "plan", "side")) - assert not builder._principal_view_exceeds_page(1.0, page, bounds, ("front", "side")) + assert builder._principal_view_exceeds_page(1.0, page, bounds, ("front", "side")) + assert not builder._principal_view_exceeds_page(1.0, page, bounds, ("side",)) + + +def test_orthographic_pair_cannot_fit_when_each_projection_alone_would_fit(): + import draftwright.builder as builder + + bounds = SimpleNamespace( + min=SimpleNamespace(X=0, Y=0, Z=0), + max=SimpleNamespace(X=28.7, Y=10, Z=20), + ) + page = (297.0, 210.0) + assert not builder._principal_view_exceeds_page(10.0, page, bounds, ("front",)) + assert not builder._principal_view_exceeds_page(10.0, page, bounds, ("side",)) + assert not builder._principal_view_exceeds_page(10.0, page, bounds, ("plan",)) + assert builder._principal_view_exceeds_page(10.0, page, bounds, ("front", "side")) + assert builder._principal_view_exceeds_page(10.0, page, bounds, ("front", "plan")) @pytest.mark.slow diff --git a/tests/test_issue_1155_grm04_sheet_use.py b/tests/test_issue_1155_grm04_sheet_use.py index 986efc36..c05cc151 100644 --- a/tests/test_issue_1155_grm04_sheet_use.py +++ b/tests/test_issue_1155_grm04_sheet_use.py @@ -10,8 +10,8 @@ def test_grm04_measured_replan_keeps_diameter_and_location_on_a_clean_sheet(): drawing = build_drawing(_FIXTURE, title="GRM-04") - # The A4/2:1 sheet carries both requirements. Larger scales on that page - # intersect the title block or other view ink, so they are rejected. + # The A4/2:1 sheet carries both requirements. At 5:1 the layout conflicts + # with other ink; at 10:1 the bare principal views cannot fit on A4. assert (drawing.page_w, drawing.page_h) == (297.0, 210.0) assert drawing.scale == 2.0 assert drawing.scale_decision["status"] == "automatic" @@ -24,7 +24,7 @@ def test_grm04_measured_replan_keeps_diameter_and_location_on_a_clean_sheet(): ] == [ (2.0, "detail_reservation_conservative", None), (5.0, "rejected", "structural_error"), - (10.0, "rejected", "structural_error"), + (10.0, "skipped", "principal_view_exceeds_page"), ] hole = next( diff --git a/tests/test_issue_1338_scale_before_page_escalation.py b/tests/test_issue_1338_scale_before_page_escalation.py index 083a9011..84271fc4 100644 --- a/tests/test_issue_1338_scale_before_page_escalation.py +++ b/tests/test_issue_1338_scale_before_page_escalation.py @@ -63,6 +63,7 @@ def test_ap242_pmi_side_hole_survives_selected_page_upscale_issue_2177(): assert not [issue for issue in drawing.lint() if issue.severity in {"warning", "error"}] table = drawing.get_annotation("manufacturing_requirements") + assert table.precedes_source_placement (reserved,) = _annotation_fixed_ink(drawing, "manufacturing_requirements", table) table_box = _geom_box(table) assert reserved.box == table_box @@ -112,8 +113,13 @@ def test_table_repack_trigger_ignores_unrelated_and_clean_outcomes_issue_2177(): issue.source_ids = ("source:1",) drawing.iter_annotations = lambda: iter(()) assert not builder._source_placement_drop_with_table(drawing) + table.precedes_source_placement = True drawing.iter_annotations = lambda: iter((("schedule", table),)) assert builder._source_placement_drop_with_table(drawing) + table.precedes_source_placement = False + assert not builder._source_placement_drop_with_table(drawing) + table.precedes_source_placement = True + assert builder._source_placement_drop_with_table(drawing) def test_unselected_view_geometry_cannot_force_repack_issue_2177(monkeypatch):