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/reference/draftwright-report-v8.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@
"properties": {
"declaration_id": { "type": "string", "minLength": 1 },
"parameter_id": { "type": "string", "minLength": 1 },
"axis": { "enum": ["x", "y"] },
"member": { "oneOf": [{ "type": "integer", "minimum": 0 }, { "const": "centre" }] },
"control": { "enum": ["side", "lane"] },
"authored_value": {},
"resolved_value": {},
Expand Down
3 changes: 2 additions & 1 deletion docs/reference/reports.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ When a generated or hand-authored sheet uses `sheet.layout_override(...)`,
`intent_class: "layout-only"`. The corresponding feature still carries its complete semantic
content and the ordinary shared placement solve still owns coordinates and feasibility. The
side form records a corridor; a dimension-targeted side or lane additionally records the exact
`parameter_id`, and a lane records its one-based feature-relative rank. The field is emitted as an empty array when no override
`parameter_id`, and a lane records its one-based feature-relative rank. Exact location overrides
also record `axis` and `member`, so X and Y locations remain distinct. The field is emitted as an empty array when no override
exists; it is optional in the version-8
schema so previously written version-8 documents remain valid.

Expand Down
15 changes: 14 additions & 1 deletion docs/reference/sheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,15 @@ if side_check["supported"]:
sheet.layout_override(
"declaration:hole", parameter="bore.diameter", side="left"
)

# A location needs both its axis and pattern/hole member to select one component.
location_check = sheet.validate_layout_override(
"declaration:hole", parameter="location", axis="x", member=0, lane=2
)
if location_check["supported"]:
sheet.layout_override(
"declaration:hole", parameter="location", axis="x", member=0, lane=2
)
```

Without `parameter=`, `layout_options()` reports the declaration's current side and supported
Expand All @@ -360,7 +369,9 @@ 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/height dimensions of an envelope. Capability is
overall width/depth/height dimensions of an envelope, plus exact X/Y locations on
Z-normal holes and patterns. For a location, `axis` and `member` are required and
X and Y can have independent lanes. 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 Expand Up @@ -391,6 +402,8 @@ other engineering semantics. Generated scripts
emit the override as a separate line after the identity-bearing declarations. A declared report
records the requested and resolved value under `layout.overrides` with
`intent_class: "layout-only"`; dimension-targeted rows also retain `parameter_id`. An infeasible lane drops
with a `location_ref_dropped` issue for exact locations, retaining the requested lane and blockers.
Other infeasible lanes drop
honestly with the requested lane in the lint message. Omitting the override retains the existing
placement behaviour.

Expand Down
120 changes: 96 additions & 24 deletions src/draftwright/annotations/_locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from build123d_drafting.helpers import CenterMark

from draftwright._core import (
_STRIP_SPACING,
Analysis,
_concentric_with_axis,
_first_free_index,
Expand All @@ -20,6 +21,7 @@
PRIORITY,
CorridorCandidate,
Escalation,
InteriorDimensionJob,
_hole_location_coverage_fact,
_same_location_ordinate,
_with_hole_location_coverage,
Expand Down Expand Up @@ -276,6 +278,69 @@ def _drop(nm):
)


def _submit_location(
dwg,
ctx,
register,
key,
strip,
view,
axis,
tier,
candidate,
*,
lane,
witness,
side,
hole_requirements=(),
):
"""Route an exact declared lane through the shared whole-dimension solve."""
if lane is None:
register(ctx, key, strip, view, axis, tier, candidate)
return
rejections: list[str] = []

def drop(name):
blockers = sorted(set(rejections)) or ["no_admissible_candidate"]
ctx.record_issue(
"warning",
"location_ref_dropped",
f"{name} not placed (requested lane {lane} unavailable beside the {view}; "
f"blockers: {', '.join(blockers)})",
measurement=candidate.measurement,
hole_requirements=hole_requirements,
evidence_reason=f"requested_lane_unavailable:{lane}:{','.join(blockers)}",
)
ctx.escalations.append(Escalation("location", view, name, "requested_lane_unavailable"))

jobs = ctx.interior_dimensions
if jobs is None:
rejections.append("measured_lane_solve_unavailable")
drop(candidate.name)
return
lane_step = tier + (strip.spacing if strip is not None else _STRIP_SPACING)
direction = 1 if side in {"above", "right"} else -1
position = witness + direction * (2 * dwg.draft.extension_gap + lane * lane_step)
jobs.append(
InteriorDimensionJob(
name=candidate.name,
view=view,
side=side,
build=candidate.build,
on_place=candidate.on_place,
on_drop=drop,
lane_step=lane_step,
priority=candidate.priority,
feature=candidate.feature,
measurement=candidate.measurement,
interior_build=candidate.build,
explicit_position=position,
requested_lane=lane,
rejection_reasons=rejections,
)
)


def _circular_channel_axis_marks(dwg, ctx, dimensions):
"""Give approved axis coordinates a visible natural reference in each projection."""
existing = {
Expand Down Expand Up @@ -525,7 +590,7 @@ def _discard_short_refs(refs, coordinate, datum, view):
if r[4] not in (None, "x"):
continue
for u in x_refs:
if _same_location_ordinate(r[0], u[0]):
if _same_location_ordinate(r[0], u[0]) and r[6].lane == u[6][0].lane:
u[6].append(r[6])
u[3] = u[3] or r[2] in pinned_set
# Collapsing coincident Xs into one dim must ACCUMULATE what it draws
Expand Down Expand Up @@ -568,11 +633,7 @@ def _discard_short_refs(refs, coordinate, datum, view):
)
ctx.escalations.append(Escalation("location", "plan", None, "illegible"))
x_refs = [r for r in x_refs if r[0] not in _x_drawable or r[0] in _kept_x_set]
# Register X locations with slot dimensions in the shared plan-above corridor;
# this dedups coincident slot positions and orders the whole ladder instead
# of passes carving around each other. A plan-X location has no alternate
# view, so Policy B force-keeps a blocked dim; only a physically full strip
# drops (location_ref_dropped) and escalates the hole table.
# Share the plan corridor with slots; blocked dimensions escalate to a hole table.
for i, (rx, ry, feat, pin_ref, mids, location_facts, location_entries) in enumerate(
sorted(x_refs, key=lambda r: abs(r[0] - datum_x))
):
Expand All @@ -583,25 +644,17 @@ def _discard_short_refs(refs, coordinate, datum, view):
label_offset = short_dimension_label_offset(
(PX(datum_x), PY(ry), 0), (PX(rx), PY(ry), 0), draft, label
)
# A single X-location dim shared by two *distinct* features at this X belongs to
# neither exclusively — leave it unowned so drop cannot over-strip a sibling's
# dimension and annotations_of never over-claims it (ADR 5 (was 0010)).
# Shared dimensions have no single feature owner (ADR 5).
_shared_x = any(
o[4] in (None, "x") and _same_location_ordinate(o[0], rx) and o[2] != feat
o[4] in (None, "x")
and _same_location_ordinate(o[0], rx)
and o[2] != feat
and o[6].lane == location_entries[0].lane
for o in refs
)
_xfeat = None if _shared_x else feat
# The measurement does NOT follow the feature. Feature-unowned is an
# ADR 5 (was 0010) *ownership* rule — it stops drop(feature) stripping a sibling's dim. It
# says nothing about what the dim measures, and a shared dim measures BOTH features'
# X location. Record every approved measurement in the tuple-valued
# channel (ADR 4 (was 0016)) so audit can credit all owners.
# One ADR 4 (was 0016) feature-level location identity per collapsed owner; the structured
# location facts below carry that this particular visible member is X.
_xmid = tuple(mids)
# On the experimental staggered layout the plan can abut the top sheet margin.
# The farther X stations may use the free exterior strip below the plan while
# the nearest station keeps its established tier. Both are solver-owned strips.
# A staggered plan may route farther X stations into the free lower strip.
x_below = (
layout_flag("plan_x_below", "DRAFTWRIGHT_EXPERIMENTAL_PLAN_X_BELOW")
and i > 0
Expand All @@ -613,8 +666,10 @@ def _discard_short_refs(refs, coordinate, datum, view):
geometry = _XLocationGeometry(
PX, PY, datum_x, rx, ry, x_side, label, label_offset, draft, dim_builder
)
register(
_submit_location(
dwg,
ctx,
register,
("plan", x_side),
x_zone,
"plan",
Expand All @@ -640,6 +695,12 @@ def _discard_short_refs(refs, coordinate, datum, view):
interior_build=geometry.interior_build,
interior_geometry=geometry.interior_geometry,
),
lane=location_entries[0].lane,
witness=PY(ry),
side=x_side,
hole_requirements=tuple(
(feature, parameter) for feature, parameter, _point in location_facts
),
)

return _register_y_locations(
Expand Down Expand Up @@ -698,7 +759,7 @@ def _register_y_locations(
if r[4] not in (None, "y"):
continue
for u in y_refs:
if _same_location_ordinate(r[1], u[1]):
if _same_location_ordinate(r[1], u[1]) and r[6].lane == u[6][0].lane:
u[6].append(r[6])
u[3] = u[3] or r[2] in pinned_set
if r[4] in (None, "y") and r[3] is not None and r[3] not in u[4]:
Expand Down Expand Up @@ -762,7 +823,10 @@ def _register_y_locations(
n += 1
# A shared Y location is unowned for the same reason as shared X.
_shared_y = any(
o[4] in (None, "y") and _same_location_ordinate(o[1], ry) and o[2] != feat
o[4] in (None, "y")
and _same_location_ordinate(o[1], ry)
and o[2] != feat
and o[6].lane == location_entries[0].lane
for o in refs
)
_yfeat = None if _shared_y else feat
Expand Down Expand Up @@ -797,8 +861,10 @@ def _register_y_locations(
geometry = _YLocationGeometry(
pa, pb, direction, interior_direction, edge, label, label_offset, draft, dim_builder
)
register(
_submit_location(
dwg,
ctx,
register,
(view, direction),
strip,
view,
Expand All @@ -825,5 +891,11 @@ def _register_y_locations(
interior_build=geometry.interior_build,
interior_geometry=geometry.interior_geometry,
),
lane=location_entries[0].lane,
witness=edge,
side=direction,
hole_requirements=tuple(
(feature, parameter) for feature, parameter, _point in location_facts
),
)
return n
8 changes: 8 additions & 0 deletions src/draftwright/model/compiled.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
authored_location_omitted,
hole_location_parameter_id,
hole_location_references,
location_component_lane,
location_datum,
location_display_decimals,
plan_dimensions,
Expand Down Expand Up @@ -1564,6 +1565,13 @@ def _compile_locations(model: PartModel) -> tuple[list[ApprovedDimension], list[
)
if isinstance(feature, HoleFeature | PatternFeature)
else None,
lane=(
location_component_lane(
model, feature, pd.location_member, measured_axis
)
if isinstance(feature, HoleFeature | PatternFeature)
else None
),
)
)
continue
Expand Down
44 changes: 32 additions & 12 deletions src/draftwright/model/ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -2659,10 +2659,19 @@ def __post_init__(self) -> None:
"placement intent is unavailable for location dimensions: one location "
"may compile into multiple directional values"
)
if self.role == "location" and self.lane is not None:
if (
self.role == "location"
and self.lane is not None
and not (
isinstance(self.feature, HoleFeature | PatternFeature)
and self.feature.frame.axis == "z"
and self.discriminator in {"x", "y"}
and self.member is not None
)
):
raise ValueError(
"lane intent is unavailable for location dimensions: one location may "
"compile into multiple directional values"
"location lane requires one Z-normal hole or pattern component "
"selected by both axis and member"
)
decimals = self.display_decimals
if decimals is None:
Expand Down Expand Up @@ -2715,19 +2724,14 @@ def __post_init__(self) -> None:

@dataclass(frozen=True)
class LayoutOverride:
"""One append-only layout-only edit against a build-scoped declaration.

The record carries a feature corridor side, one exact dimension's corridor side,
or one exact dimension's relative lane, never page coordinates. The matching feature/request in :class:`PartModel`
contains the resolved value used by the renderer; retaining this separate intent
record makes generated replay and assessment evidence explicit without turning layout
policy into engineering meaning.
"""
"""Append-only, coordinate-free layout edit against a build-scoped declaration."""

declaration_id: str
side: str | None = None
parameter_id: str | None = None
lane: int | None = None
axis: str | None = None
member: int | Literal["centre"] | None = None

def __post_init__(self) -> None:
if (
Expand All @@ -2741,6 +2745,17 @@ def __post_init__(self) -> None:
)
if (self.side is None) == (self.lane is None):
raise ValueError("layout override requires exactly one of side or lane")
if self.parameter_id != "location" and (self.axis is not None or self.member is not None):
raise ValueError("layout override axis and member select only location")
if self.parameter_id == "location" and (
self.axis not in {"x", "y"} or self.member is None
):
raise ValueError("location layout override requires exact axis and member")
valid_member = self.member == "centre" or (
isinstance(self.member, int) and not isinstance(self.member, bool) and self.member >= 0
)
if self.parameter_id == "location" and (self.side is not None or not valid_member):
raise ValueError("location layout override requires a valid member and lane")
if self.side is not None:
if self.parameter_id is not None and (
not isinstance(self.parameter_id, str)
Expand Down Expand Up @@ -2887,7 +2902,8 @@ def __post_init__(self) -> None:
):
raise ValueError("PartModel.layout_overrides requires LayoutOverride entries")
override_targets = [
(override.declaration_id, override.parameter_id) for override in self.layout_overrides
(override.declaration_id, override.parameter_id, override.axis, override.member)
for override in self.layout_overrides
]
if len(set(override_targets)) != len(override_targets):
raise ValueError("PartModel.layout_overrides requires unique layout targets")
Expand All @@ -2914,6 +2930,8 @@ def __post_init__(self) -> None:
)
if request.feature is feature
and request.role == override.parameter_id
and request.discriminator == override.axis
and request.member == override.member
and request.side == override.side
]
if len(matching_side) != 1:
Expand All @@ -2935,6 +2953,8 @@ def __post_init__(self) -> None:
for request in (*self.requested_dimensions, *(self.authored_dimensions or ()))
if request.feature is feature
and request.role == override.parameter_id
and request.discriminator == override.axis
and request.member == override.member
and request.lane == override.lane
]
if len(matching) != 1:
Expand Down
Loading
Loading