feat: 完善Face保持关系守门与大模型预判
This commit is contained in:
@@ -32,6 +32,22 @@ def _write_triangular_prism(path: Path) -> None:
|
||||
_write_step(prism, path)
|
||||
|
||||
|
||||
def _write_trapezoid_prism(path: Path) -> None:
|
||||
polygon = BRepBuilderAPI_MakePolygon()
|
||||
polygon.Add(gp_Pnt(0.0, 0.0, 0.0))
|
||||
polygon.Add(gp_Pnt(12.0, 0.0, 0.0))
|
||||
polygon.Add(gp_Pnt(10.0, 0.0, 6.0))
|
||||
polygon.Add(gp_Pnt(0.0, 0.0, 8.0))
|
||||
polygon.Close()
|
||||
if hasattr(polygon, "IsDone") and not polygon.IsDone():
|
||||
raise RuntimeError("Could not create trapezoid prism profile.")
|
||||
face_maker = BRepBuilderAPI_MakeFace(polygon.Wire())
|
||||
if hasattr(face_maker, "IsDone") and not face_maker.IsDone():
|
||||
raise RuntimeError("Could not create trapezoid prism face.")
|
||||
prism = BRepPrimAPI_MakePrism(face_maker.Face(), gp_Vec(0.0, 6.0, 0.0)).Shape()
|
||||
_write_step(prism, path)
|
||||
|
||||
|
||||
def _triangle_face_id(model: StepModel) -> int:
|
||||
for face_id in range(len(model.faces)):
|
||||
info = model.face_info(face_id)
|
||||
@@ -42,6 +58,19 @@ def _triangle_face_id(model: StepModel) -> int:
|
||||
raise SystemExit("no triangular planar Face was found")
|
||||
|
||||
|
||||
def _sloped_quad_face_id(model: StepModel) -> int:
|
||||
for face_id in range(len(model.faces)):
|
||||
info = model.face_info(face_id)
|
||||
if info.get("surface") != "plane":
|
||||
continue
|
||||
normal = info.get("normal") or info.get("push_pull_outward_direction")
|
||||
if not isinstance(normal, tuple) or len(normal) != 3:
|
||||
continue
|
||||
if abs(float(normal[0])) > 0.1 and abs(float(normal[2])) > 0.1:
|
||||
return face_id
|
||||
raise SystemExit("no sloped quadrilateral planar Face was found")
|
||||
|
||||
|
||||
def _triangle_infos(model: StepModel) -> list[dict[str, object]]:
|
||||
infos: list[dict[str, object]] = []
|
||||
for face_id in range(len(model.faces)):
|
||||
@@ -89,6 +118,20 @@ def _assert_not_blocked(plan: dict[str, object], label: str) -> None:
|
||||
raise SystemExit(f"{label} should be available for a simple triangular Face: {plan}")
|
||||
|
||||
|
||||
def _assert_keep_relations_blocked_for_angled(plan: dict[str, object], label: str) -> None:
|
||||
if plan.get("status") != "blocked":
|
||||
raise SystemExit(f"{label} should be blocked before execution: {plan}")
|
||||
if plan.get("face_push_pull_planar_relation_constraint_requested") is not True:
|
||||
raise SystemExit(f"{label} should record the requested keep-relation constraint: {plan}")
|
||||
if plan.get("face_push_pull_planar_constraint_status") != "blocked":
|
||||
raise SystemExit(f"{label} should expose blocked keep-relation constraint status: {plan}")
|
||||
if int(plan.get("face_push_pull_planar_constraint_angled_count", 0) or 0) <= 0:
|
||||
raise SystemExit(f"{label} should count at least one angled relation: {plan}")
|
||||
message = str(plan.get("message") or "") + " " + str(plan.get("blockers") or "")
|
||||
if "斜交" not in message:
|
||||
raise SystemExit(f"{label} blocker should explain angled first-level planar relations: {plan}")
|
||||
|
||||
|
||||
def _assert_single_solid(model: StepModel, label: str) -> None:
|
||||
stats = model.stats()
|
||||
if stats.solids != 1:
|
||||
@@ -162,6 +205,15 @@ def main() -> int:
|
||||
model.push_pull_face(face_id, 1.0)
|
||||
_assert_single_solid(model, "triangular Face push/pull")
|
||||
|
||||
wedge_path = Path(temp_dir) / "trapezoid_prism.step"
|
||||
_write_trapezoid_prism(wedge_path)
|
||||
wedge = StepModel.load(wedge_path)
|
||||
wedge_face_id = _sloped_quad_face_id(wedge)
|
||||
plan = wedge.push_pull_plan(wedge_face_id, 0.5)
|
||||
_assert_not_blocked(plan, "sloped planar Face push/pull")
|
||||
keep_plan = wedge.push_pull_keep_relations_plan(wedge_face_id, 0.5)
|
||||
_assert_keep_relations_blocked_for_angled(keep_plan, "sloped planar Face keep-relations push/pull")
|
||||
|
||||
model, face_id, info = _fresh_model(path)
|
||||
current_area = float(info.get("area") or 0.0)
|
||||
target_area = current_area * 1.44
|
||||
|
||||
Reference in New Issue
Block a user