分模候选方案

This commit is contained in:
2026-04-23 23:37:39 +08:00
parent 0bdfc7f7d5
commit c1f6b6e827
16 changed files with 1302 additions and 497 deletions
+28 -180
View File
@@ -310,43 +310,6 @@ class AluminumFoamMoldGenerator(BaseMoldGenerator):
1. 优先选择 Z 轴方向分型(上下开模)
2. 分型面位置选在产品的最大轮廓处,即包围盒的 Z 方向中心
"""
<<<<<<< HEAD
primary_parting = self._detect_primary_parting(shape, analysis)
parting_surface = primary_parting["surface"]
parting_line = self.optimize_parting_line(primary_parting["line"])
primary_direction = primary_parting["direction"]
additional_surfaces = []
bbox = analysis["bounding_box"]
center = bbox["center"]
dims = bbox["dimensions"]
max_dim = max(dims)
min_dim = min(dims)
if max_dim / min_dim > 5:
vertical_plane = gp_Pln(gp_Pnt(center[0], center[1], center[2]), gp_Dir(1, 0, 0))
try:
vertical_surface = BRepBuilderAPI_MakeFace(vertical_plane).Face()
additional_surfaces.append({
"surface": vertical_surface,
"direction": [1, 0, 0],
"reason": "产品扁平,需要垂直分型"
})
except Exception:
pass
=======
# 1. 尝试 AI 模型
if self.ai_parting_detector is not None:
try:
ai_result = self.ai_parting_detector.detect(shape, analysis)
if ai_result:
return self._create_parting_surface_from_ai(ai_result, analysis)
except Exception as e:
logger.warning(f"AI 分型面检测失败: {e}")
# 2. 泡沫模具强制 Z 轴方向分型(上下开模)
bbox = analysis["bounding_box"]
center = bbox["center"]
primary_direction = [0, 0, 1] # Z 轴方向
@@ -364,26 +327,40 @@ class AluminumFoamMoldGenerator(BaseMoldGenerator):
logger.info(f"泡沫模具 Z 轴分型面: Z={parting_z:.2f} mm (包围盒中心)")
# 3. 计算分型线
parting_line = self._calculate_parting_line(shape, parting_surface)
>>>>>>> 77c4885a4020b609f4964184661f42e936814c4f
parting_line = self.optimize_parting_line(
self._calculate_parting_line(shape, parting_surface)
)
additional_surfaces = []
dims = bbox["dimensions"]
max_dim = max(dims)
min_dim = min(dims)
if min_dim > 0 and max_dim / min_dim > 5:
vertical_plane = gp_Pln(
gp_Pnt(center[0], center[1], center[2]),
gp_Dir(1, 0, 0),
)
try:
vertical_surface = BRepBuilderAPI_MakeFace(vertical_plane).Face()
additional_surfaces.append({
"surface": vertical_surface,
"direction": [1, 0, 0],
"reason": "产品扁平,需要辅助垂直分型参考",
})
except Exception:
pass
return {
"primary_surface": parting_surface,
"primary_line": parting_line,
"primary_direction": primary_direction,
<<<<<<< HEAD
"confidence": primary_parting["confidence"],
"method": primary_parting["method"],
"additional_surfaces": additional_surfaces,
"surface_count": 1 + len(additional_surfaces)
=======
"confidence": 0.95, # Z 轴分型置信度高
"additional_surfaces": [],
"surface_count": 1,
"method": "z_axis_rule",
"additional_surfaces": additional_surfaces,
"surface_count": 1 + len(additional_surfaces),
"parting_direction": "Z",
"parting_position_z": parting_z,
>>>>>>> 77c4885a4020b609f4964184661f42e936814c4f
}
def _build_undercut_regions(self, undercut_analysis: Dict[str, Any]) -> List[Dict[str, Any]]:
@@ -463,120 +440,6 @@ class AluminumFoamMoldGenerator(BaseMoldGenerator):
except Exception:
return 50.0
<<<<<<< HEAD
=======
def _apply_shrinkage_compensation(self, shape: Any) -> Any:
"""应用收缩率补偿(铝泡沫版本)"""
# 铝泡沫收缩率通常较大
scale_factor = 1.0 + self.shrinkage_rate
trsf = gp_Trsf()
trsf.SetScale(gp_Pnt(0, 0, 0), scale_factor)
try:
scaled_shape = BRepBuilderAPI_Transform(shape, trsf, True).Shape()
logger.info(f"收缩率补偿应用: {self.shrinkage_rate*100:.2f}%")
return scaled_shape
except Exception as e:
logger.error(f"收缩补偿失败: {e}")
return shape
def _apply_draft_angles(self, shape: Any, parting_surface: Any) -> Any:
"""应用拔模角(改进版)"""
# 获取分型面法向量作为拔模方向
try:
surface = BRepAdaptor_Surface(parting_surface)
draft_direction = surface.Plane().Position().Direction()
logger.info(f"应用拔模角: {self.draft_angle}°, 方向: ({draft_direction.X():.3f}, {draft_direction.Y():.3f}, {draft_direction.Z():.3f})")
# 注意:完整的拔模实现需要更复杂的 BRepOffsetAPI_DraftAngle
# 这里简化处理,返回原始形状
return shape
except Exception as e:
logger.warning(f"拔模角处理失败: {e}")
return shape
def _split_cavity_core(self, shape: Any, parting_surface: Any) -> Tuple[Any, Any]:
"""
按分型面将模具分为 A 板(定模/型腔侧)和 B 板(动模/型芯侧)
流程:
1. 创建模具块(包围产品的长方体)
2. 用分型面水平切出上半块和下半块
3. 从上半块减去产品 → A 板(含型腔负形)
4. 从下半块减去产品 → B 板(含型芯负形)
"""
try:
# 获取产品边界框
bbox = Bnd_Box()
brepbndlib_Add(shape, bbox)
xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get()
# 获取分型面 Z 位置(包围盒 Z 中心)
parting_z = (zmin + zmax) / 2
# 模具块尺寸(比产品大一圈余量)
margin = 25
mold_xmin = xmin - margin
mold_ymin = ymin - margin
mold_zmin = zmin - margin
mold_xmax = xmax + margin
mold_ymax = ymax + margin
mold_zmax = zmax + margin
# Step 1: 创建整块模具
mold_block = BRepPrimAPI_MakeBox(
gp_Pnt(mold_xmin, mold_ymin, mold_zmin),
gp_Pnt(mold_xmax, mold_ymax, mold_zmax)
).Shape()
# Step 2: 用分型面切出上下半块
# 创建一个足够大的水平切割面(分型面 Z 位置)
cutting_plane = gp_Pln(gp_Pnt(0, 0, parting_z), gp_Dir(0, 0, 1))
cutting_face = BRepBuilderAPI_MakeFace(cutting_plane).Face()
# 创建上半空间和下半空间的实体
# 上半块: 从 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()
# 下半块: 从 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()
# Step 3: 从上半块减去产品 → 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("A板布尔减法失败,使用上半块")
a_plate = upper_block
# Step 4: 从下半块减去产品 → 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}")
return shape, shape
>>>>>>> 77c4885a4020b609f4964184661f42e936814c4f
def _generate_mold_block(self, cavity: Any, analysis: Dict) -> Any:
"""生成完整的模具块(包含A/B板结构)"""
try:
@@ -656,20 +519,6 @@ class AluminumFoamMoldGenerator(BaseMoldGenerator):
}
def _calculate_clamping_force(self, analysis: Dict) -> str:
<<<<<<< HEAD
"""估算锁模力"""
volume_cm3 = analysis.get("volume", 0) / 1000
if volume_cm3 < 10:
return "30-50 吨"
elif volume_cm3 < 50:
return "50-100 吨"
elif volume_cm3 < 200:
return "100-200 吨"
else:
return "200+ 吨"
=======
"""
估算锁模力(泡沫模具专用)
@@ -687,14 +536,13 @@ class AluminumFoamMoldGenerator(BaseMoldGenerator):
clamping_force_ton = max(30, clamping_force_ton)
return f"{clamping_force_ton} 吨 (投影面积 {projected_area_cm2:.1f} cm² × 0.3)"
def _calculate_product_weight(self, analysis: Dict) -> str:
"""计算产品重量"""
volume_cm3 = analysis.get("volume", 0) / 1000
weight_g = volume_cm3 * self.material_density
return f"{weight_g:.2f} g"
>>>>>>> 77c4885a4020b609f4964184661f42e936814c4f
def _estimate_wall_thickness(self, analysis: Dict) -> str:
"""估算壁厚范围"""
volume = analysis.get("volume", 0)