x
This commit is contained in:
+41
-23
@@ -315,10 +315,14 @@ class MoldCavityGenerator:
|
||||
return shape
|
||||
|
||||
def _split_cavity_core(self, shape: Any, parting_surface: Any) -> Tuple[Any, Any]:
|
||||
"""分离型腔和型芯
|
||||
|
||||
型腔(Cavity): 模具中形成产品外表面的部分,是产品形状的负形
|
||||
型芯(Core): 模具中形成产品内表面的部分,是产品形状的正形
|
||||
"""
|
||||
按分型面将模具分为 A 板(定模/型腔侧)和 B 板(动模/型芯侧)
|
||||
|
||||
流程:
|
||||
1. 创建模具块(包围产品的长方体)
|
||||
2. 用分型面 Z 位置切出上半块和下半块
|
||||
3. 从上半块减去产品 → A 板(含型腔负形)
|
||||
4. 从下半块减去产品 → B 板(含型芯负形)
|
||||
"""
|
||||
try:
|
||||
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox
|
||||
@@ -333,6 +337,9 @@ class MoldCavityGenerator:
|
||||
brepbndlib.Add(shape, bbox)
|
||||
xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get()
|
||||
|
||||
# 获取分型面 Z 位置(包围盒 Z 中心)
|
||||
parting_z = (zmin + zmax) / 2
|
||||
|
||||
# 计算模具块尺寸(比产品大一定余量)
|
||||
margin = 20 # mm
|
||||
mold_xmin = xmin - margin
|
||||
@@ -341,30 +348,41 @@ class MoldCavityGenerator:
|
||||
mold_xmax = xmax + margin
|
||||
mold_ymax = ymax + margin
|
||||
mold_zmax = zmax + margin
|
||||
|
||||
# 创建模具块
|
||||
mold_block = BRepPrimAPI_MakeBox(
|
||||
gp_Pnt(mold_xmin, mold_ymin, mold_zmin),
|
||||
|
||||
# 上半块: 从 parting_z 到 mold_zmax
|
||||
upper_block = BRepPrimAPI_MakeBox(
|
||||
gp_Pnt(mold_xmin, mold_ymin, parting_z),
|
||||
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("型腔生成成功(模具块减去产品)")
|
||||
|
||||
# 下半块: 从 mold_zmin 到 parting_z
|
||||
lower_block = BRepPrimAPI_MakeBox(
|
||||
gp_Pnt(mold_xmin, mold_ymin, mold_zmin),
|
||||
gp_Pnt(mold_xmax, mold_ymax, parting_z)
|
||||
).Shape()
|
||||
|
||||
# A 板(定模)= 上半块 - 产品
|
||||
a_plate_op = BRepAlgoAPI_Cut(upper_block, shape)
|
||||
if a_plate_op.IsDone():
|
||||
a_plate = a_plate_op.Shape()
|
||||
logger.info(f"A板(定模)生成成功: Z={parting_z:.1f} ~ {mold_zmax:.1f}")
|
||||
else:
|
||||
logger.warning("型腔布尔运算失败,使用原始形状")
|
||||
cavity = mold_block
|
||||
|
||||
# 型芯 = 产品形状本身(收缩补偿后)
|
||||
core = shape
|
||||
logger.info("型芯 = 产品形状")
|
||||
|
||||
return cavity, core
|
||||
logger.warning("A板布尔减法失败,使用上半块")
|
||||
a_plate = upper_block
|
||||
|
||||
# B 板(动模)= 下半块 - 产品
|
||||
b_plate_op = BRepAlgoAPI_Cut(lower_block, shape)
|
||||
if b_plate_op.IsDone():
|
||||
b_plate = b_plate_op.Shape()
|
||||
logger.info(f"B板(动模)生成成功: Z={mold_zmin:.1f} ~ {parting_z:.1f}")
|
||||
else:
|
||||
logger.warning("B板布尔减法失败,使用下半块")
|
||||
b_plate = lower_block
|
||||
|
||||
return a_plate, b_plate
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"型腔分离失败: {e}")
|
||||
logger.error(f"分模失败: {e}")
|
||||
return shape, shape
|
||||
|
||||
def _extract_shape_geometry(self, shape: Any, shape_type: str) -> Dict[str, Any]:
|
||||
|
||||
Reference in New Issue
Block a user