feat: 完善特征编辑和选择稳定性

This commit is contained in:
2026-07-29 15:43:28 +08:00
parent 720c2dc970
commit c937e13d43
13 changed files with 8294 additions and 290 deletions
+68 -3
View File
@@ -8,7 +8,7 @@ from OCC.Core.BRepAdaptor import BRepAdaptor_Curve, BRepAdaptor_Surface
from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Defeaturing
from OCC.Core.BRepBndLib import brepbndlib
from OCC.Core.BOPAlgo import BOPAlgo_GlueFull
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_Transform
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_GTransform, BRepBuilderAPI_Transform
from OCC.Core.BRepCheck import BRepCheck_Analyzer
from OCC.Core.BRepClass3d import BRepClass3d_SolidClassifier
from OCC.Core.BRepGProp import brepgprop
@@ -34,7 +34,7 @@ from OCC.Core.TopExp import TopExp_Explorer
from OCC.Core.TopLoc import TopLoc_Location
from OCC.Core.TopoDS import TopoDS_Compound, TopoDS_Shape, topods
from OCC.Core.TopTools import TopTools_IndexedDataMapOfShapeListOfShape
from OCC.Core.gp import gp_Ax1, gp_Dir, gp_Pnt, gp_Trsf, gp_Vec
from OCC.Core.gp import gp_Ax1, gp_Dir, gp_GTrsf, gp_Pnt, gp_Trsf, gp_Vec, gp_XYZ
from OCC.Extend.TopologyUtils import TopologyExplorer
from .constants import CURVE_TYPES, ORIENTATION_TYPES
@@ -341,6 +341,58 @@ def _rotated_shape(
return BRepBuilderAPI_Transform(shape, trsf, True).Shape()
def _scaled_shape(shape: TopoDS_Shape, scale: float, center: tuple[float, float, float]) -> TopoDS_Shape:
if abs(scale - 1.0) <= 1e-12:
return shape
if scale <= 0:
raise ValueError("Scale factor must be greater than 0.")
trsf = gp_Trsf()
trsf.SetScale(gp_Pnt(*center), float(scale))
return BRepBuilderAPI_Transform(shape, trsf, True).Shape()
def _axis_scaled_shape(
shape: TopoDS_Shape,
axis_name: str,
scale: float,
center: tuple[float, float, float],
) -> TopoDS_Shape:
if abs(scale - 1.0) <= 1e-12:
return shape
if scale <= 0:
raise ValueError("Scale factor must be greater than 0.")
axis = axis_name.upper()
axis_index = {"X": 0, "Y": 1, "Z": 2}.get(axis)
if axis_index is None:
raise ValueError("Scale axis must be X, Y or Z.")
matrix = [
[1.0, 0.0, 0.0],
[0.0, 1.0, 0.0],
[0.0, 0.0, 1.0],
]
matrix[axis_index][axis_index] = float(scale)
cx, cy, cz = center
moved_center = (
matrix[0][0] * cx + matrix[0][1] * cy + matrix[0][2] * cz,
matrix[1][0] * cx + matrix[1][1] * cy + matrix[1][2] * cz,
matrix[2][0] * cx + matrix[2][1] * cy + matrix[2][2] * cz,
)
translation = (cx - moved_center[0], cy - moved_center[1], cz - moved_center[2])
transform = gp_GTrsf()
for row in range(3):
for column in range(3):
transform.SetValue(row + 1, column + 1, matrix[row][column])
transform.SetTranslationPart(gp_XYZ(*translation))
builder = BRepBuilderAPI_GTransform(shape, transform, True)
builder.Build()
if not builder.IsDone():
raise RuntimeError("Axis scale transform failed.")
result = builder.Shape()
if result.IsNull():
raise RuntimeError("Axis scale transform produced an empty shape.")
return result
def _axis_dir_from_name(axis_name: str) -> gp_Dir:
axis = axis_name.upper()
if axis == "X":
@@ -365,10 +417,23 @@ def _tuple_or_none(value: object) -> tuple[float, float, float] | None:
return None
def _float_or_none(value: object) -> float | None:
if value is None or value == "":
return None
try:
return float(value)
except (TypeError, ValueError):
return None
def _tuple_sub(left: tuple[float, float, float], right: tuple[float, float, float]) -> tuple[float, float, float]:
return (left[0] - right[0], left[1] - right[1], left[2] - right[2])
def _tuple_add(left: tuple[float, float, float], right: tuple[float, float, float]) -> tuple[float, float, float]:
return (left[0] + right[0], left[1] + right[1], left[2] + right[2])
def _tuple_scale(values: tuple[float, float, float], scale: float) -> tuple[float, float, float]:
return (values[0] * scale, values[1] * scale, values[2] * scale)
@@ -937,7 +1002,7 @@ def _cylinder_depth_readiness(
status = "caution"
if not warnings and not blockers:
note = "可以尝试调整盲孔深度。"
note = "可以尝试调整盲孔/盲槽深度。"
else:
note = " ".join(blockers + warnings)
return {