This commit is contained in:
2026-05-02 00:39:04 +08:00
parent f9acdb767b
commit d1a3f22785
16 changed files with 1181 additions and 113 deletions
+33 -5
View File
@@ -398,14 +398,42 @@ class BaseMoldGenerator:
core = self._subtract_product_from_plate(b_plate, shape, "B板(回退)")
return cavity or a_plate, core or b_plate
logger.warning("回退方案也失败,使用最简方法")
cavity_op = BRepAlgoAPI_Cut(mold_block, shape)
cavity = cavity_op.Shape() if cavity_op.IsDone() else mold_block
return cavity, shape
logger.warning("回退方案也失败,使用最简A/B板切分(避免返回产品本体)")
center_z = (zmin + zmax) / 2
margin = 20
a_plate = BRepPrimAPI_MakeBox(
gp_Pnt(xmin - margin, ymin - margin, center_z),
gp_Pnt(xmax + margin, ymax + margin, zmax + margin)
).Shape()
b_plate = BRepPrimAPI_MakeBox(
gp_Pnt(xmin - margin, ymin - margin, zmin - margin),
gp_Pnt(xmax + margin, ymax + margin, center_z)
).Shape()
cavity = self._subtract_product_from_plate(a_plate, shape, "A板(最简)")
core = self._subtract_product_from_plate(b_plate, shape, "B板(最简)")
return cavity or a_plate, core or b_plate
except Exception as e:
logger.error(f"分模回退方案失败: {e}")
return shape, shape
# 最后兜底也返回模具半板,而不是产品本体,避免预览出现“三份产品”
try:
bbox = Bnd_Box()
brepbndlib.Add(shape, bbox)
xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get()
center_z = (zmin + zmax) / 2
margin = 20
a_plate = BRepPrimAPI_MakeBox(
gp_Pnt(xmin - margin, ymin - margin, center_z),
gp_Pnt(xmax + margin, ymax + margin, zmax + margin)
).Shape()
b_plate = BRepPrimAPI_MakeBox(
gp_Pnt(xmin - margin, ymin - margin, zmin - margin),
gp_Pnt(xmax + margin, ymax + margin, center_z)
).Shape()
return a_plate, b_plate
except Exception:
return shape, shape
def detect_insert_regions(self, shape: Any, analysis: Dict,
depth_threshold: float = 30.0,