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
43 changes: 43 additions & 0 deletions src/draftwright/model/compiled.py
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,48 @@ def _compile_locations(model: PartModel) -> tuple[list[ApprovedDimension], list[
return approved, omissions


def _authored_bore_axis_location_matches(
source: AuthoredDimension, location: ApprovedDimension
) -> bool:
"""Match an X/Y hole location to a witness on the same physical bore axis.

STEP often locates an axis at an interior Z station, while recognition locates
its mouth. The other in-plane coordinate and the bore's depth still have to
agree; a pattern centre is not a hole and must not cover its own location.
"""
feature = location.id.feature if location.id is not None else None
span = location.span
stations = _authored_linear_stations(source)
if (
not isinstance(feature, HoleFeature)
or feature.frame.axis != "z"
or feature.depth is None
or span is None
or stations is None
or location.discriminator != "xyz"[stations[0]]
or location.discriminator not in ("x", "y")
or abs(source.value - location.value) > 1e-6
):
return False
index = stations[0]
target = span[1]
if not any(
all(abs(member[i] - target[i]) <= 0.01 for i in range(3))
for member in feature.members or (feature.frame.origin,)
):
return False
return any(
abs(point[index] - target[index]) <= 0.01
and abs(other[index] - span[0][index]) <= 0.01
and abs(point[1 - index] - target[1 - index]) <= 0.01
and target[2] - feature.depth - 0.01 <= point[2] <= target[2] + 0.01
for point, other in (
(source.ref_pts[0], source.ref_pts[1]),
(source.ref_pts[1], source.ref_pts[0]),
)
)


def _compile_off_axis_hole_locations(
model: PartModel,
) -> tuple[list[ApprovedDimension], list[Omission]]:
Expand Down Expand Up @@ -2093,6 +2135,7 @@ def compile_dimensions(
or _authored_location_matches(
source, location.span, location.discriminator, location.value
)
or _authored_bore_axis_location_matches(source, location)
)
]
if len(matching) == 1:
Expand Down
48 changes: 47 additions & 1 deletion tests/test_authored_pmi_precedence.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from draftwright import build_drawing
from draftwright.builder import detect_part_model
from draftwright.linting.coverage import _authored_axial_witness_on_profile
from draftwright.model.compiled import compile_dimensions
from draftwright.model.compiled import _authored_bore_axis_location_matches, compile_dimensions
from draftwright.model.ir import (
AuthoredDimension,
CylindricalReference,
Expand Down Expand Up @@ -722,6 +722,52 @@ def test_authored_hole_x_location_covers_only_the_x_component():
)


def test_authored_bore_axis_station_covers_only_its_physical_hole_location():
bbox = (Pos(0, 0, 6) * Box(80, 90, 12)).bounding_box()
deep = HoleFeature(Frame((10, 5, 12), "z"), 4, depth=12, through=True)
shallow = HoleFeature(Frame((10, 5, 12), "z"), 6, depth=4, through=False)
source = AuthoredDimension(
Frame((-7.5, 5, 6), "x"),
"linear",
35,
"35",
"X",
ref_pts=((-25, 5, 6), (10, 5, 6)),
source_id="dimension:bore-x",
)
model = PartModel(
bbox,
"z",
[deep, shallow, source],
datums=[Datum("datum_xy", "point", (-25, -40, 0))],
)
plan = compile_dimensions(model)
assert [(d.id.feature, d.discriminator) for d in plan.locations] == [
(deep, "y"),
(shallow, "x"),
(shallow, "y"),
]
assert any(
omission.feature is deep
and omission.parameter_id.endswith(".x")
and "dimension:bore-x" in omission.reason
for omission in plan.diagnostics
)
wrong_bore = compile_dimensions(
replace(
model, features=[deep, shallow, replace(source, ref_pts=((-25, 6, 6), (10, 6, 6)))]
)
)
assert len([d for d in wrong_bore.locations if d.discriminator == "x"]) == 2
shallow_x = next(
d for d in plan.locations if d.id.feature is shallow and d.discriminator == "x"
)
assert not _authored_bore_axis_location_matches(source, replace(shallow_x, discriminator="z"))
assert not _authored_bore_axis_location_matches(
source, replace(shallow_x, span=((-25, 5, 12), (20, 5, 12)))
)


def test_pattern_member_provenance_is_per_measurement():
hole = HoleFeature(Frame((0, 0, 0), "z"), 4, depth=None, through=True)
pattern = PatternFeature(
Expand Down
Loading