重构路由
This commit is contained in:
+17
-15
@@ -471,13 +471,6 @@ class MoldCavityGenerator:
|
||||
"bounds": bounds
|
||||
}
|
||||
|
||||
return {
|
||||
"type": "plane",
|
||||
"normal": [0, 0, 1],
|
||||
"origin": [0, 0, 0],
|
||||
"bounds": bounds
|
||||
}
|
||||
|
||||
def _calculate_mold_size(self, analysis: Dict) -> Dict[str, float]:
|
||||
"""估算模具尺寸"""
|
||||
product_bbox = analysis["bounding_box"]["dimensions"]
|
||||
@@ -531,14 +524,14 @@ class MoldCavityGenerator:
|
||||
return f"{avg_thickness * 0.7:.2f} - {avg_thickness * 1.3:.2f} mm"
|
||||
elif volume > 0:
|
||||
# 如果没有surface_area,基于体积估算
|
||||
bbox_dims = analysis.get("bounding_box", {}).get("dimensions", [1, 1, 1])
|
||||
bbox_dims = analysis.get("bounding_box", {}).get("dimensions", [0, 0, 0])
|
||||
bbox_volume = bbox_dims[0] * bbox_dims[1] * bbox_dims[2]
|
||||
if bbox_volume > 0:
|
||||
efficiency = volume / bbox_volume
|
||||
avg_thickness = (bbox_dims[0] + bbox_dims[1]) / 2 * efficiency
|
||||
return f"{avg_thickness * 0.7:.2f} - {avg_thickness * 1.3:.2f} mm"
|
||||
|
||||
return "2.0 - 4.0 mm (默认)"
|
||||
return "无法估算 (缺少几何数据)"
|
||||
|
||||
def _calculate_complexity_score(self, analysis: Dict) -> float:
|
||||
"""计算复杂度评分(0-10)"""
|
||||
@@ -552,14 +545,14 @@ class MoldCavityGenerator:
|
||||
return round(complexity, 1)
|
||||
elif volume > 0:
|
||||
# 如果没有surface_area,基于拓扑复杂度评分
|
||||
bbox_dims = analysis.get("bounding_box", {}).get("dimensions", [100, 100, 100])
|
||||
bbox_dims = analysis.get("bounding_box", {}).get("dimensions", [0, 0, 0])
|
||||
bbox_volume = bbox_dims[0] * bbox_dims[1] * bbox_dims[2]
|
||||
if bbox_volume > 0:
|
||||
volume_ratio = volume / bbox_volume
|
||||
complexity = (1.0 - volume_ratio) * 10
|
||||
return round(min(max(complexity, 0), 10), 1)
|
||||
|
||||
return 5.0
|
||||
return 0.0
|
||||
|
||||
def _estimate_cycle_time(self, analysis: Dict) -> str:
|
||||
"""估算成型周期"""
|
||||
@@ -594,7 +587,7 @@ class MoldCavityGenerator:
|
||||
|
||||
def _assess_warpage_risk(self, analysis: Dict) -> str:
|
||||
"""评估翘曲风险"""
|
||||
bbox = analysis.get("bounding_box", {}).get("dimensions", [1, 1, 1])
|
||||
bbox = analysis.get("bounding_box", {}).get("dimensions", [0, 0, 0])
|
||||
aspect_ratio = max(bbox) / min(bbox)
|
||||
|
||||
if aspect_ratio > 5:
|
||||
@@ -715,6 +708,15 @@ class MoldCavityGenerator:
|
||||
|
||||
使用 BRepAlgoAPI_Section 进行布尔运算求交
|
||||
"""
|
||||
# 获取实际边界框作为回退
|
||||
try:
|
||||
bbox_fallback = Bnd_Box()
|
||||
brepbndlib.Add(shape, bbox_fallback)
|
||||
xmin, ymin, zmin, xmax, ymax, zmax = bbox_fallback.Get()
|
||||
fallback_bbox = {"bounding_box": {"min": [xmin, ymin, zmin], "max": [xmax, ymax, zmax], "center": [(xmin+xmax)/2, (ymin+ymax)/2, (zmin+zmax)/2]}}
|
||||
except Exception:
|
||||
fallback_bbox = {"bounding_box": {"min": [0, 0, 0], "max": [0, 0, 0], "center": [0, 0, 0]}}
|
||||
|
||||
try:
|
||||
# 创建截面运算
|
||||
section = BRepAlgoAPI_Section(shape, parting_surface)
|
||||
@@ -724,7 +726,7 @@ class MoldCavityGenerator:
|
||||
logger.warning("截面运算未完成,使用简化分型线")
|
||||
return self._simple_parting_line(
|
||||
parting_surface,
|
||||
{"bounding_box": {"min": [-50, -50, 0], "max": [50, 50, 100]}}
|
||||
fallback_bbox
|
||||
)
|
||||
|
||||
# 提取交线(边)
|
||||
@@ -755,7 +757,7 @@ class MoldCavityGenerator:
|
||||
logger.warning("未找到交线,使用简化分型线")
|
||||
return self._simple_parting_line(
|
||||
parting_surface,
|
||||
{"bounding_box": {"min": [-50, -50, 0], "max": [50, 50, 100]}}
|
||||
fallback_bbox
|
||||
)
|
||||
|
||||
logger.info(f"计算得到 {len(edges)} 个分型线点")
|
||||
@@ -765,7 +767,7 @@ class MoldCavityGenerator:
|
||||
logger.error(f"分型线计算失败:{e}")
|
||||
return self._simple_parting_line(
|
||||
parting_surface,
|
||||
{"bounding_box": {"min": [-50, -50, 0], "max": [50, 50, 100]}}
|
||||
fallback_bbox
|
||||
)
|
||||
|
||||
def _simple_parting_surface(self, analysis: Dict) -> Tuple[Any, List]:
|
||||
|
||||
Reference in New Issue
Block a user