Files
pythonocc-step-editor/scripts/verify_feature_parameter_policy.py
T

133 lines
3.5 KiB
Python
Raw Normal View History

from __future__ import annotations
import math
from pathlib import Path
import sys
PROJECT_ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(PROJECT_ROOT))
from step_editor.window_state import WindowStateMixin, _feature_dimension_keys
def assert_keys(info: dict[str, object], expected: tuple[str, ...]) -> None:
actual = _feature_dimension_keys(info)
if actual != expected:
raise AssertionError(f"expected {expected}, got {actual} for {info}")
def main() -> int:
assert_keys(
{
"surface": "cylinder",
"feature_guess": "hole/groove candidate",
"angular_span": math.tau,
},
("diameter", "hole_depth_estimate"),
)
assert_keys(
{
"surface": "cylinder",
"feature_guess": "hole/groove candidate",
"angular_span": math.pi,
},
(
"slot_chord_width_estimate",
"slot_sagitta_depth_estimate",
"slot_total_length_estimate",
),
)
assert_keys(
{
"surface": "cylinder",
"feature_guess": "boss/outer-round candidate",
"angular_span": math.tau,
},
("boss_diameter", "boss_height"),
)
assert_keys(
{
"surface": "cylinder",
"feature_guess": "round/fillet candidate",
"angular_span": math.pi / 2.0,
},
("existing_fillet_radius_estimate", "existing_fillet_arc_length_estimate"),
)
assert_keys(
{"surface": "plane"},
(
"local_face_width",
"local_face_height",
"face_center_position",
"face_target_normal_position",
),
)
assert_keys(
{"surface": "plane", "shell_region_status": "candidate"},
(
"local_face_width",
"local_face_height",
"face_center_position",
"face_target_normal_position",
"shell_thickness_estimate",
),
)
assert_keys(
{
"surface": "plane",
"prismatic_profile_status": "candidate",
"prismatic_extrusion_status": "candidate",
},
("local_face_width", "local_face_height", "shell_thickness_estimate"),
)
assert_keys(
{"surface": "torus"},
("torus_major_radius", "torus_minor_radius"),
)
specs = [
{
"key": "area",
"editable": True,
"enabled": True,
"label": "area",
},
{
"key": "diameter",
"editable": True,
"enabled": True,
"label": "diameter",
},
{
"key": "hole_depth_estimate",
"editable": True,
"enabled": False,
"label": "depth",
},
{
"key": "hole_edit_semantics",
"editable": False,
"enabled": False,
"label": "semantics",
},
]
filtered = WindowStateMixin._feature_property_specs(
object(),
specs,
{
"surface": "cylinder",
"feature_guess": "hole/groove candidate",
"angular_span": math.tau,
},
)
filtered_keys = tuple(str(spec.get("key")) for spec in filtered)
if filtered_keys != ("diameter",):
raise AssertionError(f"unexpected filtered feature parameters: {filtered_keys}")
print("feature parameter policy ok")
return 0
if __name__ == "__main__":
raise SystemExit(main())