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: 2 additions & 0 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ and re-exports the existing private helper names.
- **`build_policy.py`** — rank-6 finished-drawing scale and arrangement decisions:
required-outcome blockers, structural validity, candidate quality, and stable
decision records. `builder.py` keeps the automatic retry ladder and its constants.
- **`section_scale_recovery.py`** — rank-6 bounded same-sheet scale recovery after an
optional section drops, including a finished requirement comparison.
- **`explicit_scale.py`** — rank-6 resolution of a caller-requested scale:
automatic-view veto, strict and permissive decisions, and bounded standard-scale
fallback. The builder supplies its build and critique seams and current scale ladder.
Expand Down
92 changes: 60 additions & 32 deletions src/draftwright/annotations/_axial_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
_tol_suffix,
supported_secondary_crop,
)
from draftwright.annotations._baseline_step_ladder import register_vertical_baseline_steps
from draftwright.annotations._common import (
_LOC_SUBCHAIN,
CROSSABLE_TYPES,
Expand Down Expand Up @@ -136,6 +137,42 @@ def _record_step_chain_drop(why: str, *, ctx, measurement=()) -> None:
)


def _horizontal_step_tiers(segments, labels, draft):
centres_and_widths = [
(
(segment.pa[0] + segment.pb[0]) / 2,
len(label) * draft.font_size * _EST_CHAR_WIDTH_EM,
)
for segment, label in zip(segments, labels, strict=True)
]

def clear(items):
return all(
second_centre - first_centre
>= (first_width + second_width) / 2 + draft.pad_around_text
for (first_centre, first_width), (second_centre, second_width) in zip(
items, items[1:], strict=False
)
)

if clear(centres_and_widths):
return [0] * len(segments)
if clear(centres_and_widths[0::2]) and clear(centres_and_widths[1::2]):
return [index % 2 for index in range(len(segments))]
return None


def _drop_dense_step_chain(ctx, segments, event, prefix):
_log.info("step-length chain skipped: too dense even when staggered")
_record_step_chain_drop(
"shoulders too dense to dimension even when staggered",
ctx=ctx,
measurement=_step_measurements(segments),
)
if event is not None:
event["items"].append({"name": prefix, "outcome": "dropped", "reason": "too_dense"})


def _draw_step_chain(
dwg,
view,
Expand All @@ -148,6 +185,7 @@ def _draw_step_chain(
start=0,
profile_bounds=None,
placement_bounds=None,
baseline_positions=False,
) -> int:
"""Place a turned step-length chain in *view* from structured *segs*, each already
projected to *view*'s page coords in axis order. Orientation is
Expand Down Expand Up @@ -183,6 +221,24 @@ def _draw_step_chain(
else _step_value_text(seg) + _tol_suffix(seg.tolerance, draft)
for seg in segs
]
if baseline_positions and not horizontal:
registered = register_vertical_baseline_steps(
dwg,
view,
segs,
labels,
name_prefix,
start,
vb,
ctx,
lambda measurements: _record_step_chain_drop(
"right-hand datum ladder has no clear tier",
ctx=ctx,
measurement=measurements,
),
)
if registered is not None:
return registered
mean_v = sum(vals) / len(vals)
explicit_display = any(seg.display_decimals is not None for seg in segs)
tier_step = draft.font_size + 2 * draft.pad_around_text
Expand All @@ -209,38 +265,10 @@ def _draw_step_chain(
typ_name = f"{name_prefix}_typ" if start == 0 else f"{name_prefix}_typ{start}"
candidates = [(typ_name, dim, _step_measurements(segs))]
else:
tiers = [0] * len(segs)
if horizontal:
cw = [
(
(seg.pa[0] + seg.pb[0]) / 2,
len(labels[i]) * draft.font_size * _EST_CHAR_WIDTH_EM,
)
for i, seg in enumerate(segs)
]

def _clear(items):
return all(
c2 - c1 >= (w1 + w2) / 2 + draft.pad_around_text
for (c1, w1), (c2, w2) in zip(items, items[1:], strict=False)
)

if _clear(cw):
pass
elif _clear(cw[0::2]) and _clear(cw[1::2]):
tiers = [i % 2 for i in range(len(segs))]
else:
_log.info("step-length chain skipped: too dense even when staggered")
_record_step_chain_drop(
"shoulders too dense to dimension even when staggered",
ctx=ctx,
measurement=_step_measurements(segs),
)
if ev is not None:
ev["items"].append(
{"name": name_prefix, "outcome": "dropped", "reason": "too_dense"}
)
return 0
tiers = _horizontal_step_tiers(segs, labels, draft) if horizontal else [0] * len(segs)
if tiers is None:
_drop_dense_step_chain(ctx, segs, ev, name_prefix)
return 0
# A short vertical shoulder is not a density test for the whole chain.
# Helpers can draw outside arrows, and the shared batch solver below
# checks actual labels/ink and offers the same far tier on either axis.
Expand Down
71 changes: 71 additions & 0 deletions src/draftwright/annotations/_baseline_step_ladder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""Datum-referenced turned steps in the shared vertical dimension corridor."""

from draftwright._core import _dim
from draftwright.annotations._common import (
_LOC_SUBCHAIN,
PRIORITY,
CorridorCandidate,
dim_footprint,
register_corridor,
)


def register_vertical_baseline_steps(
dwg, view, segments, labels, prefix, start, bounds, ctx, report_drop
) -> int | None:
analysis = ctx.analysis
zones = getattr(analysis, {"front": "fv_zones", "side": "sv_zones"}.get(view, ""), None)
strip = getattr(zones, "right", None) if zones is not None else None
if strip is None:
return None

draft = dwg.draft
base_x = bounds[2] + 2.0
tier = draft.font_size + 2 * draft.pad_around_text
for index, (segment, label) in enumerate(zip(segments, labels, strict=True)):
name = f"{prefix}{start + index}"
low, high = sorted((segment.pa[1], segment.pb[1]))

def build(position, low=low, high=high, label=label):
return _dim(
(base_x, low, 0),
(base_x, high, 0),
"right",
position - base_x,
draft,
label=label,
)

def footprint(position, low=low, high=high, label=label):
return dim_footprint(
(base_x, low, 0),
(base_x, high, 0),
"right",
position - base_x,
draft,
label,
)

def drop(_name, measurements=segment.measurements):
report_drop(measurements)

register_corridor(
ctx,
(view, "right"),
strip,
view,
"x",
tier,
CorridorCandidate(
name=name,
build=build,
order=(_LOC_SUBCHAIN, abs(high - low), name),
on_place=lambda _name: None,
on_drop=drop,
force=True,
priority=PRIORITY.PRINCIPAL,
measurement=segment.measurements,
footprint=footprint,
),
)
return len(segments)
3 changes: 3 additions & 0 deletions src/draftwright/annotations/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,9 @@ class PlacementContext:
# The drawing's render list: :meth:`place` appends here, so a render pass places an
# annotation through the ctx seam (``ctx.place(...)``) instead of reaching into the drawing.
items: Any = None
# Build analysis is passed to render passes explicitly, never read from a
# Drawing private. The baseline step ladder uses its shared view strips.
analysis: Any = None
# The ensured PartModel (ADR 1 (was 0008) IR) the run's passes read, threaded off the drawing so
# they do not reach into ``dwg._part_model``. Both entry paths set it from the
# PUBLIC ``dwg.model()`` after the model is ensured/attached.
Expand Down
7 changes: 4 additions & 3 deletions src/draftwright/annotations/_pmi_dimensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
_segments_cross_or_overlap,
)
from draftwright.annotations._common import (
_LOC_SUBCHAIN,
CROSSABLE_TYPES,
PRIORITY,
CorridorCandidate,
Expand Down Expand Up @@ -154,7 +155,8 @@ def _bore_span_offsets(pmi_kind: str, value: float) -> tuple[float, float]:

# PMI is pre-authored manufacturing intent from the STEP file. When a strip is over
# capacity it should survive ahead of auto-generated dims (priority 0), like declared
# GD&T. It still lives in the outer run so it does not land between size/location dims.
# GD&T. Linear PMI shares the location ladder when its witness spans that axis;
# other authored PMI retains the outer run.
_PMI_SUBCHAIN = 3
_PMI_CORRIDOR_PRIORITY = PRIORITY.AUTHORED
_PMI_SLOT = 10.0 # mm — slot size for PMI dim lines in the strip
Expand Down Expand Up @@ -502,7 +504,6 @@ def _pmi_dim_spec(
if side in ("below", "left") and lo >= witness:
return None

order_coord = min(perp)
spec = {
"name": name,
"build": _PmiDimensionBuild(q1, q2, side, witness, label, draft, basic),
Expand All @@ -511,7 +512,7 @@ def _pmi_dim_spec(
"side": side,
"axis": axis,
"perp": perp,
"order": (_PMI_SUBCHAIN, order_coord, name),
"order": (_LOC_SUBCHAIN, abs(perp[1] - perp[0]), name),
}
if leader_fallback:

Expand Down
1 change: 1 addition & 0 deletions src/draftwright/annotations/_step_lengths.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ def _render_single_profile(
start=start,
profile_bounds=profile_bounds,
placement_bounds=_profile_bounds_hint,
baseline_positions=True,
)

y_result = _render_y_profile(
Expand Down
2 changes: 1 addition & 1 deletion src/draftwright/annotations/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,7 @@ def _auto_annotate(dwg: DrawingPort, a: Analysis, *, detail_view: bool = False):
registry=dwg.registry,
coverage=dwg.coverage,
items=dwg.items, # passes place via ctx.place, not dwg.add
analysis=a,
# The opt-in solve-trace recorder is attached to the drawing's build state
# by the builder; getattr because dwg is duck-typed in tests. None = off.
trace=getattr(dwg, "solve_trace", None),
Expand All @@ -1070,7 +1071,6 @@ def _auto_annotate(dwg: DrawingPort, a: Analysis, *, detail_view: bool = False):
# not accumulate duplicate drop records.
ctx.reset_issues()
ctx.coverage.reset_dropped()

# Tighten right-strip outer_limits to the actual iso view left edge now
# that the iso has been projected and fitted. Always apply so that any
# future allocations are bounded; warn when the cursor has already passed
Expand Down
15 changes: 14 additions & 1 deletion src/draftwright/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@
_project_iso,
)
from draftwright.recognition_cache import RecognitionCache
from draftwright.section_scale_recovery import (
preserves_recognized_requirements,
recover_dropped_section_scale,
)
from draftwright.view_plan import (
ARRANGEMENTS,
PRINCIPAL_VIEW_NAMES,
Expand Down Expand Up @@ -1706,7 +1710,9 @@ def try_larger_standard_pages(
)
return None, None

def try_scales_on_selected_page(self, candidate_scales, *, reason, require_axial_coverage):
def try_scales_on_selected_page(
self, candidate_scales, *, reason, require_axial_coverage, requirement_floor=None
):
"""Try a bounded scale sequence on the already selected sheet."""
for candidate_scale in candidate_scales:
analysis = self.latest_analysis()
Expand Down Expand Up @@ -1769,6 +1775,12 @@ def try_scales_on_selected_page(self, candidate_scales, *, reason, require_axial
candidate_drawing,
require_axial_coverage=require_axial_coverage,
)
if (
rejection is None
and requirement_floor is not None
and not preserves_recognized_requirements(requirement_floor, candidate_drawing)
):
rejection = "recognized_requirement_regression"
if rejection is None:
self.record_attempt(
candidate_scale, "complete", reason=reason, candidate=candidate_drawing
Expand Down Expand Up @@ -2654,6 +2666,7 @@ def run(self) -> Drawing:
self.settle_arrangement()
self.prepare_trials()
self.recover_detail()
recover_dropped_section_scale(self)
self.recover_hard_layout()
self.recover_required_no_iso()
self.recover_optional_iso()
Expand Down
Loading
Loading