This commit is contained in:
2026-03-08 02:14:07 +08:00
parent 1b7b5b1049
commit db01a4ee6d
2 changed files with 159 additions and 32 deletions
+47 -9
View File
@@ -5,6 +5,7 @@ import numpy as np
from OCC.Core.BRepOffsetAPI import BRepOffsetAPI_MakeThickSolid
from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Cut, BRepAlgoAPI_Fuse
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeFace, BRepBuilderAPI_Transform
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox
from OCC.Core.Geom import Geom_Plane
from OCC.Core.gp import gp_Pln, gp_Dir, gp_Pnt, gp_Vec, gp_Trsf
from OCC.Core.TopTools import TopTools_ListOfShape
@@ -283,16 +284,53 @@ class MoldCavityGenerator:
return shape
def _split_cavity_core(self, shape: Any, parting_surface: Any) -> Tuple[Any, Any]:
"""分离型腔和型芯"""
"""分离型腔和型芯
型腔(Cavity): 模具中形成产品外表面的部分,是产品形状的负形
型芯(Core): 模具中形成产品内表面的部分,是产品形状的正形
"""
try:
# 使用分型面切割产品
# 上半部分为型腔(Cavity)
# 下半部分为型芯(Core)
# 这里需要实现BRepAlgoAPI_Section或类似的切割操作
# 简化:返回相同的形状(实际需实现切割逻辑)
return shape, shape # (cavity, core)
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox
from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Cut
from OCC.Core.TopExp import TopExp_Explorer
from OCC.Core.TopAbs import TopAbs_SOLID
# 获取产品边界框
from OCC.Core.Bnd import Bnd_Box
from OCC.Core.BRepBndLib import brepbndlib
bbox = Bnd_Box()
brepbndlib.Add(shape, bbox)
xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get()
# 计算模具块尺寸(比产品大一定余量)
margin = 20 # mm
mold_xmin = xmin - margin
mold_ymin = ymin - margin
mold_zmin = zmin - margin
mold_xmax = xmax + margin
mold_ymax = ymax + margin
mold_zmax = zmax + margin
# 创建模具块
mold_block = BRepPrimAPI_MakeBox(
gp_Pnt(mold_xmin, mold_ymin, mold_zmin),
gp_Pnt(mold_xmax, mold_ymax, mold_zmax)
).Shape()
# 型腔 = 模具块 - 产品(布尔减法)
cavity_operation = BRepAlgoAPI_Cut(mold_block, shape)
if cavity_operation.IsDone():
cavity = cavity_operation.Shape()
logger.info("型腔生成成功(模具块减去产品)")
else:
logger.warning("型腔布尔运算失败,使用原始形状")
cavity = mold_block
# 型芯 = 产品形状本身(收缩补偿后)
core = shape
logger.info("型芯 = 产品形状")
return cavity, core
except Exception as e:
logger.error(f"型腔分离失败: {e}")