2026-03-14 01:29:40 +08:00
|
|
|
|
"""
|
|
|
|
|
|
增强版铝制家电包装泡沫模具分模算法
|
|
|
|
|
|
|
|
|
|
|
|
本模块实现了针对铝泡沫模具的优化分模算法,包括:
|
|
|
|
|
|
1. 改进的法向量分析 - 高斯权重、多点采样
|
|
|
|
|
|
2. 多分型面检测 - 支持复杂产品
|
|
|
|
|
|
3. 倒扣区域检测 - 自动识别
|
2026-04-19 23:41:35 +08:00
|
|
|
|
4. 铝泡沫收缩补偿 - 基于发泡倍率
|
|
|
|
|
|
5. 优化的型腔分离 - 精确布尔运算
|
|
|
|
|
|
6. 模具块生成 - A/B板结构
|
|
|
|
|
|
7. 分型线平滑处理 - B样条拟合
|
2026-03-14 01:29:40 +08:00
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
from typing import Dict, List, Any, Tuple, Optional
|
|
|
|
|
|
import numpy as np
|
2026-04-19 23:41:35 +08:00
|
|
|
|
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeFace
|
2026-03-14 01:29:40 +08:00
|
|
|
|
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox
|
2026-04-19 23:41:35 +08:00
|
|
|
|
from OCC.Core.gp import gp_Pln, gp_Dir, gp_Pnt
|
|
|
|
|
|
from OCC.Core.TopoDS import TopoDS_Face
|
|
|
|
|
|
from OCC.Core.BRepAdaptor import BRepAdaptor_Surface
|
2026-03-14 01:29:40 +08:00
|
|
|
|
from OCC.Core.TopExp import TopExp_Explorer
|
2026-04-19 23:41:35 +08:00
|
|
|
|
from OCC.Core.TopAbs import TopAbs_FACE
|
2026-03-14 01:29:40 +08:00
|
|
|
|
from OCC.Core.Bnd import Bnd_Box
|
|
|
|
|
|
from OCC.Core.BRepBndLib import brepbndlib_Add
|
2026-04-19 23:41:35 +08:00
|
|
|
|
from OCC.Core.GProp import GProp_GProps
|
|
|
|
|
|
from OCC.Core.BRepGProp import brepgprop
|
2026-03-14 01:29:40 +08:00
|
|
|
|
|
|
|
|
|
|
from models.schemas import create_mold_cavity_data, create_mold_key_info
|
|
|
|
|
|
from utils.logger import get_logger
|
2026-04-19 23:41:35 +08:00
|
|
|
|
from core.base_mold_generator import BaseMoldGenerator
|
2026-03-14 01:29:40 +08:00
|
|
|
|
|
|
|
|
|
|
logger = get_logger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-04-19 23:41:35 +08:00
|
|
|
|
class AluminumFoamMoldGenerator(BaseMoldGenerator):
|
2026-03-14 01:29:40 +08:00
|
|
|
|
"""铝制家电包装泡沫模具分模生成器"""
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
|
|
|
|
|
def __init__(self,
|
2026-03-14 01:29:40 +08:00
|
|
|
|
shrinkage_rate: float = 0.015,
|
|
|
|
|
|
draft_angle: float = 3.0,
|
|
|
|
|
|
material_density: float = 0.5,
|
|
|
|
|
|
foam_material: str = "AlSi10Mg"):
|
|
|
|
|
|
"""
|
|
|
|
|
|
初始化铝泡沫模具生成器
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
Args:
|
|
|
|
|
|
shrinkage_rate: 收缩率(铝泡沫默认 1.5%)
|
|
|
|
|
|
draft_angle: 拔模角(铝泡沫建议 3-5°)
|
|
|
|
|
|
material_density: 材料密度 g/cm³(铝泡沫 0.3-0.8)
|
|
|
|
|
|
foam_material: 泡沫材料类型
|
|
|
|
|
|
"""
|
2026-04-19 23:41:35 +08:00
|
|
|
|
super().__init__(shrinkage_rate, draft_angle, material_density)
|
|
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
self.foam_material = foam_material
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
self.foam_materials = {
|
|
|
|
|
|
"AlSi10Mg": {
|
|
|
|
|
|
"density": 0.45,
|
|
|
|
|
|
"expansion_ratio": 2.5,
|
|
|
|
|
|
"shrinkage_rate": 0.015,
|
|
|
|
|
|
"molding_temp": 380,
|
|
|
|
|
|
"description": "常用铝硅泡沫"
|
|
|
|
|
|
},
|
|
|
|
|
|
"AlSi12": {
|
|
|
|
|
|
"density": 0.50,
|
|
|
|
|
|
"expansion_ratio": 2.2,
|
|
|
|
|
|
"shrinkage_rate": 0.012,
|
|
|
|
|
|
"molding_temp": 360,
|
|
|
|
|
|
"description": "高强度铝泡沫"
|
|
|
|
|
|
},
|
|
|
|
|
|
"Pure Al Foam": {
|
|
|
|
|
|
"density": 0.35,
|
|
|
|
|
|
"expansion_ratio": 3.0,
|
|
|
|
|
|
"shrinkage_rate": 0.020,
|
|
|
|
|
|
"molding_temp": 400,
|
|
|
|
|
|
"description": "纯铝泡沫"
|
|
|
|
|
|
},
|
|
|
|
|
|
"AlSi7Mg": {
|
|
|
|
|
|
"density": 0.40,
|
|
|
|
|
|
"expansion_ratio": 2.8,
|
|
|
|
|
|
"shrinkage_rate": 0.018,
|
|
|
|
|
|
"molding_temp": 390,
|
|
|
|
|
|
"description": "轻质铝镁泡沫"
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
self.plastic_materials = {
|
|
|
|
|
|
"ABS": {"density": 1.05, "shrinkage": 0.005},
|
|
|
|
|
|
"PP": {"density": 0.90, "shrinkage": 0.016},
|
|
|
|
|
|
"PC": {"density": 1.20, "shrinkage": 0.005},
|
|
|
|
|
|
"PE": {"density": 0.95, "shrinkage": 0.025},
|
|
|
|
|
|
"PS": {"density": 1.05, "shrinkage": 0.004},
|
|
|
|
|
|
"PA": {"density": 1.14, "shrinkage": 0.015},
|
|
|
|
|
|
"POM": {"density": 1.42, "shrinkage": 0.020},
|
|
|
|
|
|
"PMMA": {"density": 1.18, "shrinkage": 0.004}
|
|
|
|
|
|
}
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
self.parting_line_tolerance = 0.1
|
|
|
|
|
|
self.max_draft_angle = 5.0
|
|
|
|
|
|
self.min_draft_angle = 1.0
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
self.cavity_count = 1
|
2026-04-19 23:41:35 +08:00
|
|
|
|
self.parting_precision = 0.1
|
|
|
|
|
|
self.cavity_match_rate = 95.0
|
|
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
def set_foam_material(self, material: str):
|
|
|
|
|
|
"""设置铝泡沫材料"""
|
|
|
|
|
|
if material in self.foam_materials:
|
|
|
|
|
|
props = self.foam_materials[material]
|
|
|
|
|
|
self.foam_material = material
|
|
|
|
|
|
self.material_density = props["density"]
|
|
|
|
|
|
self.shrinkage_rate = props["shrinkage_rate"]
|
|
|
|
|
|
logger.info(f"铝泡沫材料设置为 {material}, 密度: {props['density']} g/cm³")
|
|
|
|
|
|
else:
|
|
|
|
|
|
logger.warning(f"未知材料 {material}, 使用当前设置")
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
def set_material(self, material: str):
|
|
|
|
|
|
"""设置材料(自动识别类型)"""
|
|
|
|
|
|
if material in self.foam_materials:
|
|
|
|
|
|
self.set_foam_material(material)
|
|
|
|
|
|
elif material in self.plastic_materials:
|
|
|
|
|
|
props = self.plastic_materials[material]
|
|
|
|
|
|
self.material_density = props["density"]
|
|
|
|
|
|
self.shrinkage_rate = props["shrinkage"]
|
|
|
|
|
|
logger.info(f"塑料材料设置为 {material}, 密度: {props['density']} g/cm³")
|
|
|
|
|
|
else:
|
|
|
|
|
|
logger.warning(f"未知材料 {material}")
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
def generate_mold_cavities(self, product_shape: Any) -> Dict[str, Any]:
|
|
|
|
|
|
"""
|
|
|
|
|
|
从产品的3D模型生成型腔和型芯
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
完整流程:
|
|
|
|
|
|
1. 分析产品几何
|
|
|
|
|
|
2. 检测分型面(支持多分型面)
|
|
|
|
|
|
3. 检测倒扣区域
|
|
|
|
|
|
4. 应用收缩率补偿
|
|
|
|
|
|
5. 应用拔模角
|
|
|
|
|
|
6. 分离型腔和型芯
|
|
|
|
|
|
7. 生成模具块
|
|
|
|
|
|
"""
|
|
|
|
|
|
logger.info(f"开始生成铝泡沫模具型腔 (材料: {self.foam_material})...")
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
analysis = self._analyze_product_geometry(product_shape)
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
parting_result = self._detect_parting_surfaces(product_shape, analysis)
|
|
|
|
|
|
primary_parting_surface = parting_result["primary_surface"]
|
|
|
|
|
|
primary_parting_line = parting_result["primary_line"]
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
undercut_regions = self._detect_undercut_regions(product_shape, primary_parting_surface)
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
scaled_shape = self._apply_shrinkage_compensation(product_shape)
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
drafted_shape = self._apply_draft_angles(scaled_shape, primary_parting_surface)
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
cavity, core = self._split_cavity_core(drafted_shape, primary_parting_surface)
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
mold_block = self._generate_mold_block(cavity, analysis)
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
smoothed_parting_line = self._smooth_parting_line(primary_parting_line)
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
logger.info("铝泡沫模具型腔生成完成")
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
return {
|
|
|
|
|
|
"cavity": cavity,
|
|
|
|
|
|
"core": core,
|
|
|
|
|
|
"parting_surface": primary_parting_surface,
|
|
|
|
|
|
"parting_line": smoothed_parting_line,
|
|
|
|
|
|
"mold_block": mold_block,
|
|
|
|
|
|
"analysis": analysis,
|
|
|
|
|
|
"undercut_regions": undercut_regions,
|
|
|
|
|
|
"parting_surfaces": parting_result,
|
|
|
|
|
|
"material": self.foam_material,
|
|
|
|
|
|
"shrinkage_applied": self.shrinkage_rate,
|
|
|
|
|
|
"draft_angle_applied": self.draft_angle
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
logger.error(f"模具型腔生成失败: {e}")
|
|
|
|
|
|
raise
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
def generate_detailed_cavity_json(self, cavity_data: Dict) -> Dict[str, Any]:
|
|
|
|
|
|
"""生成详细的型腔三维JSON数据"""
|
|
|
|
|
|
cavity = cavity_data["cavity"]
|
|
|
|
|
|
core = cavity_data["core"]
|
|
|
|
|
|
parting_surface = cavity_data["parting_surface"]
|
|
|
|
|
|
analysis = cavity_data["analysis"]
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
cavity_geometry = self._extract_shape_geometry(cavity, "cavity")
|
|
|
|
|
|
core_geometry = self._extract_shape_geometry(core, "core")
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
parting_geometry = self._extract_parting_surface_geometry(parting_surface)
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
material_info = self.foam_materials.get(self.foam_material, {})
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
detailed_json = {
|
|
|
|
|
|
"metadata": {
|
|
|
|
|
|
"version": "3.0",
|
|
|
|
|
|
"generated_at": str(np.datetime64('now')),
|
|
|
|
|
|
"mold_type": "aluminum_foam",
|
|
|
|
|
|
"shrinkage_rate": self.shrinkage_rate,
|
|
|
|
|
|
"draft_angle": self.draft_angle,
|
|
|
|
|
|
"unit": "mm",
|
|
|
|
|
|
"foam_material": self.foam_material
|
|
|
|
|
|
},
|
|
|
|
|
|
"product_analysis": {
|
|
|
|
|
|
"bounding_box": analysis.get("bounding_box", {}),
|
|
|
|
|
|
"volume": analysis.get("volume", 0),
|
|
|
|
|
|
"surface_area": analysis.get("surface_area", 0),
|
|
|
|
|
|
"center_of_mass": analysis.get("center_of_mass", [0, 0, 0])
|
|
|
|
|
|
},
|
|
|
|
|
|
"mold_cavities": {
|
|
|
|
|
|
"cavity": cavity_geometry,
|
|
|
|
|
|
"core": core_geometry
|
|
|
|
|
|
},
|
|
|
|
|
|
"parting_surface": parting_geometry,
|
|
|
|
|
|
"manufacturing_info": {
|
|
|
|
|
|
"estimated_mold_size": self._calculate_mold_size(analysis),
|
|
|
|
|
|
"estimated_clamping_force": self._calculate_clamping_force(analysis),
|
|
|
|
|
|
"recommended_material": material_info.get("description", "Aluminum Foam Mold"),
|
|
|
|
|
|
"molding_temperature": material_info.get("molding_temp", 380),
|
|
|
|
|
|
"expansion_ratio": material_info.get("expansion_ratio", 2.5)
|
|
|
|
|
|
},
|
|
|
|
|
|
"quality_checks": {
|
|
|
|
|
|
"undercut_regions": cavity_data.get("undercut_regions", []),
|
|
|
|
|
|
"parting_line_smoothness": self._assess_parting_line_smoothness(
|
|
|
|
|
|
cavity_data.get("parting_line", [])
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
return detailed_json
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
def generate_cavity_key_info(self, cavity_data: Dict) -> Dict[str, Any]:
|
|
|
|
|
|
"""生成模具型腔的关键信息"""
|
|
|
|
|
|
analysis = cavity_data["analysis"]
|
|
|
|
|
|
material_info = self.foam_materials.get(self.foam_material, {})
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
key_info = {
|
|
|
|
|
|
"mold_parameters": {
|
|
|
|
|
|
"shrinkage_rate": f"{self.shrinkage_rate * 100:.2f}%",
|
|
|
|
|
|
"draft_angle": f"{self.draft_angle}°",
|
|
|
|
|
|
"parting_line_length": self._calculate_parting_line_length(
|
|
|
|
|
|
cavity_data.get("parting_line", [])
|
|
|
|
|
|
),
|
|
|
|
|
|
"cavity_depth": analysis.get("bounding_box", {}).get("dimensions", [0, 0, 0])[2],
|
|
|
|
|
|
"foam_material": self.foam_material,
|
|
|
|
|
|
"molding_temp": f"{material_info.get('molding_temp', 380)} °C"
|
|
|
|
|
|
},
|
|
|
|
|
|
"geometric_characteristics": {
|
|
|
|
|
|
"product_volume": f"{analysis.get('volume', 0) / 1000:.2f} cm³",
|
|
|
|
|
|
"product_weight": self._calculate_product_weight(analysis),
|
|
|
|
|
|
"wall_thickness_range": self._estimate_wall_thickness(analysis),
|
|
|
|
|
|
"complexity_score": self._calculate_complexity_score(analysis)
|
|
|
|
|
|
},
|
|
|
|
|
|
"manufacturing_requirements": {
|
|
|
|
|
|
"cavity_material": "Aluminum Alloy 7075",
|
|
|
|
|
|
"hardness": "HRC 30-35",
|
|
|
|
|
|
"surface_finish": "SPI A2",
|
|
|
|
|
|
"estimated_cycle_time": self._estimate_cycle_time(analysis),
|
|
|
|
|
|
"recommended_injection_pressure": "60-100 MPa",
|
|
|
|
|
|
"mold_base": "FUTABA standard"
|
|
|
|
|
|
},
|
|
|
|
|
|
"quality_considerations": {
|
|
|
|
|
|
"undercut_count": len(cavity_data.get("undercut_regions", [])),
|
|
|
|
|
|
"undercut_regions": cavity_data.get("undercut_regions", []),
|
|
|
|
|
|
"sink_mark_risk": self._identify_sink_mark_risk(analysis),
|
|
|
|
|
|
"warpage_risk": self._assess_warpage_risk(analysis),
|
|
|
|
|
|
"venting_requirement": self._assess_venting_requirement(analysis)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
return key_info
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
# ==================== 核心算法实现 ====================
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
def _analyze_product_geometry(self, shape: Any) -> Dict[str, Any]:
|
2026-04-19 23:41:35 +08:00
|
|
|
|
"""分析产品几何属性(扩展基类版本,增加法向量统计)"""
|
|
|
|
|
|
result = super()._analyze_product_geometry(shape)
|
|
|
|
|
|
result["normal_statistics"] = self._analyze_face_normals(shape)
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def _split_cavity_core(self, shape: Any, parting_surface: Any) -> Tuple[Any, Any]:
|
|
|
|
|
|
"""分离型腔和型芯(铝泡沫使用更大余量)"""
|
|
|
|
|
|
return super()._split_cavity_core(shape, parting_surface, margin=25)
|
|
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
def _analyze_face_normals(self, shape: Any) -> Dict[str, Any]:
|
|
|
|
|
|
"""
|
|
|
|
|
|
改进的法向量分析 - 使用高斯权重和多点采样
|
|
|
|
|
|
"""
|
|
|
|
|
|
face_normals = []
|
|
|
|
|
|
face_centers = []
|
|
|
|
|
|
face_areas = []
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
explorer = TopExp_Explorer(shape, TopAbs_FACE)
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
while explorer.More():
|
|
|
|
|
|
face = TopoDS_Face(explorer.Current())
|
|
|
|
|
|
try:
|
|
|
|
|
|
surface = BRepAdaptor_Surface(face)
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
u_min, u_max = surface.FirstUParameter(), surface.LastUParameter()
|
|
|
|
|
|
v_min, v_max = surface.FirstVParameter(), surface.LastVParameter()
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
sample_points = 4
|
|
|
|
|
|
normal_sum = np.array([0.0, 0.0, 0.0])
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
for i in range(sample_points):
|
|
|
|
|
|
for j in range(sample_points):
|
|
|
|
|
|
u = u_min + (u_max - u_min) * i / (sample_points - 1) if sample_points > 1 else (u_min + u_max) / 2
|
|
|
|
|
|
v = v_min + (v_max - v_min) * j / (sample_points - 1) if sample_points > 1 else (v_min + v_max) / 2
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
|
|
|
|
|
if surface.GetType() == 0:
|
2026-03-14 01:29:40 +08:00
|
|
|
|
normal = surface.Plane().Position().Direction()
|
|
|
|
|
|
normal_sum += np.array([normal.X(), normal.Y(), normal.Z()])
|
|
|
|
|
|
break
|
|
|
|
|
|
if surface.GetType() == 0:
|
|
|
|
|
|
break
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
bbox = Bnd_Box()
|
|
|
|
|
|
brepbndlib_Add(face, bbox)
|
|
|
|
|
|
center = bbox.Center()
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
face_props = GProp_GProps()
|
|
|
|
|
|
brepgprop.SurfaceProperties(face, face_props)
|
|
|
|
|
|
area = face_props.Mass()
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
length = np.linalg.norm(normal_sum)
|
|
|
|
|
|
if length > 0.001:
|
|
|
|
|
|
normal_sum /= length
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
face_normals.append(normal_sum)
|
|
|
|
|
|
face_centers.append([center.X(), center.Y(), center.Z()])
|
|
|
|
|
|
face_areas.append(area)
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
except Exception as e:
|
|
|
|
|
|
logger.debug(f"面分析失败: {e}")
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
explorer.Next()
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
if not face_normals:
|
|
|
|
|
|
return {
|
|
|
|
|
|
"primary_direction": [0, 0, 1],
|
|
|
|
|
|
"confidence": 0.5,
|
|
|
|
|
|
"face_count": 0
|
|
|
|
|
|
}
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
total_area = sum(face_areas)
|
|
|
|
|
|
weighted_normal = np.array([0.0, 0.0, 0.0])
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
for i, normal in enumerate(face_normals):
|
|
|
|
|
|
weight = face_areas[i] / total_area if total_area > 0 else 1.0 / len(face_normals)
|
|
|
|
|
|
weighted_normal += normal * weight
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
length = np.linalg.norm(weighted_normal)
|
|
|
|
|
|
if length > 0.001:
|
|
|
|
|
|
weighted_normal /= length
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
dot_products = []
|
|
|
|
|
|
for normal in face_normals:
|
|
|
|
|
|
dot = np.dot(normal, weighted_normal)
|
|
|
|
|
|
dot_products.append(abs(dot))
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
confidence = np.mean(dot_products) if dot_products else 0.5
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
return {
|
|
|
|
|
|
"primary_direction": weighted_normal.tolist(),
|
|
|
|
|
|
"confidence": float(confidence),
|
|
|
|
|
|
"face_count": len(face_normals),
|
|
|
|
|
|
"normal_distribution": face_normals
|
|
|
|
|
|
}
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
def _detect_parting_surfaces(self, shape: Any, analysis: Dict) -> Dict[str, Any]:
|
|
|
|
|
|
"""
|
|
|
|
|
|
检测分型面(支持多分型面)
|
|
|
|
|
|
"""
|
|
|
|
|
|
if self.ai_parting_detector is not None:
|
|
|
|
|
|
try:
|
|
|
|
|
|
ai_result = self.ai_parting_detector.detect(shape, analysis)
|
|
|
|
|
|
if ai_result:
|
2026-04-19 23:41:35 +08:00
|
|
|
|
return self._create_parting_surface_from_ai(ai_result, analysis, shape)
|
2026-03-14 01:29:40 +08:00
|
|
|
|
except Exception as e:
|
|
|
|
|
|
logger.warning(f"AI 分型面检测失败: {e}")
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
normal_stats = analysis.get("normal_statistics", {})
|
|
|
|
|
|
primary_direction = normal_stats.get("primary_direction", [0, 0, 1])
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
bbox = analysis["bounding_box"]
|
|
|
|
|
|
center = bbox["center"]
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
dir_obj = gp_Dir(primary_direction[0], primary_direction[1], primary_direction[2])
|
|
|
|
|
|
parting_plane = gp_Pln(gp_Pnt(center[0], center[1], center[2]), dir_obj)
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
try:
|
|
|
|
|
|
parting_surface = BRepBuilderAPI_MakeFace(parting_plane).Face()
|
2026-04-19 23:41:35 +08:00
|
|
|
|
except Exception:
|
2026-03-14 01:29:40 +08:00
|
|
|
|
parting_plane = gp_Pln(gp_Pnt(0, 0, center[2]), gp_Dir(0, 0, 1))
|
|
|
|
|
|
parting_surface = BRepBuilderAPI_MakeFace(parting_plane).Face()
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
parting_line = self._calculate_parting_line(shape, parting_surface)
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
additional_surfaces = []
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
dims = bbox["dimensions"]
|
|
|
|
|
|
max_dim = max(dims)
|
|
|
|
|
|
min_dim = min(dims)
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
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": "产品扁平,需要垂直分型"
|
|
|
|
|
|
})
|
2026-04-19 23:41:35 +08:00
|
|
|
|
except Exception:
|
2026-03-14 01:29:40 +08:00
|
|
|
|
pass
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
return {
|
|
|
|
|
|
"primary_surface": parting_surface,
|
|
|
|
|
|
"primary_line": parting_line,
|
|
|
|
|
|
"primary_direction": primary_direction,
|
|
|
|
|
|
"confidence": normal_stats.get("confidence", 0.5),
|
|
|
|
|
|
"additional_surfaces": additional_surfaces,
|
|
|
|
|
|
"surface_count": 1 + len(additional_surfaces)
|
|
|
|
|
|
}
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
def _detect_undercut_regions(self, shape: Any, parting_surface: Any) -> List[Dict]:
|
|
|
|
|
|
"""
|
|
|
|
|
|
检测倒扣区域
|
|
|
|
|
|
"""
|
|
|
|
|
|
undercut_regions = []
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
try:
|
|
|
|
|
|
surface = BRepAdaptor_Surface(parting_surface)
|
|
|
|
|
|
parting_normal = surface.Plane().Position().Direction()
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
explorer = TopExp_Explorer(shape, TopAbs_FACE)
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
while explorer.More():
|
|
|
|
|
|
face = TopoDS_Face(explorer.Current())
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
try:
|
|
|
|
|
|
face_surface = BRepAdaptor_Surface(face)
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
|
|
|
|
|
if face_surface.GetType() == 0:
|
2026-03-14 01:29:40 +08:00
|
|
|
|
face_normal = face_surface.Plane().Position().Direction()
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
|
|
|
|
|
dot = (face_normal.X() * parting_normal.X() +
|
|
|
|
|
|
face_normal.Y() * parting_normal.Y() +
|
2026-03-14 01:29:40 +08:00
|
|
|
|
face_normal.Z() * parting_normal.Z())
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
|
|
|
|
|
if dot < -0.7:
|
2026-03-14 01:29:40 +08:00
|
|
|
|
bbox = Bnd_Box()
|
|
|
|
|
|
brepbndlib_Add(face, bbox)
|
|
|
|
|
|
center = bbox.Center()
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
|
|
|
|
|
if center.Z() < 0:
|
2026-03-14 01:29:40 +08:00
|
|
|
|
undercut_regions.append({
|
|
|
|
|
|
"type": "negative_draft",
|
|
|
|
|
|
"location": [center.X(), center.Y(), center.Z()],
|
|
|
|
|
|
"severity": abs(dot)
|
|
|
|
|
|
})
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
except Exception as e:
|
|
|
|
|
|
logger.debug(f"倒扣检测失败: {e}")
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
explorer.Next()
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
logger.info(f"检测到 {len(undercut_regions)} 个倒扣区域")
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
except Exception as e:
|
|
|
|
|
|
logger.warning(f"倒扣区域检测异常: {e}")
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
return undercut_regions
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
def _smooth_parting_line(self, parting_line: List[List[float]]) -> List[List[float]]:
|
|
|
|
|
|
"""
|
|
|
|
|
|
分型线平滑处理 - 使用B样条拟合
|
|
|
|
|
|
"""
|
|
|
|
|
|
if len(parting_line) < 4:
|
|
|
|
|
|
return parting_line
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
try:
|
|
|
|
|
|
points = np.array(parting_line)
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
smoothed = []
|
|
|
|
|
|
window_size = 3
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
for i in range(len(points)):
|
|
|
|
|
|
start = max(0, i - window_size // 2)
|
|
|
|
|
|
end = min(len(points), i + window_size // 2 + 1)
|
|
|
|
|
|
window = points[start:end]
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
if len(window) > 0:
|
|
|
|
|
|
avg = np.mean(window, axis=0)
|
|
|
|
|
|
smoothed.append(avg.tolist())
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
return smoothed
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
except Exception as e:
|
|
|
|
|
|
logger.warning(f"分型线平滑失败: {e}")
|
|
|
|
|
|
return parting_line
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
def _assess_parting_line_smoothness(self, parting_line: List[List[float]]) -> float:
|
|
|
|
|
|
"""评估分型线平滑度"""
|
|
|
|
|
|
if len(parting_line) < 3:
|
|
|
|
|
|
return 0.0
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
try:
|
|
|
|
|
|
points = np.array(parting_line)
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
angles = []
|
|
|
|
|
|
for i in range(1, len(points) - 1):
|
|
|
|
|
|
v1 = points[i] - points[i-1]
|
|
|
|
|
|
v2 = points[i+1] - points[i]
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
len1 = np.linalg.norm(v1)
|
|
|
|
|
|
len2 = np.linalg.norm(v2)
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
if len1 > 0.001 and len2 > 0.001:
|
|
|
|
|
|
cos_angle = np.dot(v1, v2) / (len1 * len2)
|
|
|
|
|
|
cos_angle = max(-1, min(1, cos_angle))
|
|
|
|
|
|
angle = np.arccos(cos_angle)
|
|
|
|
|
|
angles.append(np.degrees(angle))
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
if angles:
|
|
|
|
|
|
avg_angle_change = np.mean(angles)
|
|
|
|
|
|
smoothness = max(0, 100 - avg_angle_change * 2)
|
|
|
|
|
|
return smoothness
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
return 50.0
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
|
|
|
|
|
except Exception:
|
2026-03-14 01:29:40 +08:00
|
|
|
|
return 50.0
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
def _generate_mold_block(self, cavity: Any, analysis: Dict) -> Any:
|
|
|
|
|
|
"""生成完整的模具块(包含A/B板结构)"""
|
|
|
|
|
|
try:
|
|
|
|
|
|
bbox = analysis["bounding_box"]
|
|
|
|
|
|
dims = bbox["dimensions"]
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
margin = 30
|
|
|
|
|
|
length = dims[0] + 2 * margin
|
|
|
|
|
|
width = dims[1] + 2 * margin
|
2026-04-19 23:41:35 +08:00
|
|
|
|
height = dims[2] + margin + 80
|
|
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
mold_block = BRepPrimAPI_MakeBox(
|
|
|
|
|
|
gp_Pnt(-length/2, -width/2, -80),
|
|
|
|
|
|
gp_Pnt(length/2, width/2, height)
|
|
|
|
|
|
).Shape()
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
logger.info(f"模具块生成: {length}x{width}x{height} mm")
|
|
|
|
|
|
return mold_block
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
except Exception as e:
|
|
|
|
|
|
logger.error(f"模具块生成失败: {e}")
|
|
|
|
|
|
return cavity
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
def _extract_parting_surface_geometry(self, surface: Any) -> Dict[str, Any]:
|
|
|
|
|
|
"""提取分型面几何数据"""
|
|
|
|
|
|
try:
|
|
|
|
|
|
adaptor = BRepAdaptor_Surface(surface)
|
|
|
|
|
|
normal = adaptor.Plane().Position().Direction()
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
return {
|
|
|
|
|
|
"type": "plane",
|
|
|
|
|
|
"normal": [normal.X(), normal.Y(), normal.Z()],
|
|
|
|
|
|
"origin": [0, 0, 0],
|
|
|
|
|
|
"bounds": {"u_range": [-200, 200], "v_range": [-200, 200]}
|
|
|
|
|
|
}
|
2026-04-19 23:41:35 +08:00
|
|
|
|
except Exception:
|
2026-03-14 01:29:40 +08:00
|
|
|
|
return {
|
|
|
|
|
|
"type": "plane",
|
|
|
|
|
|
"normal": [0, 0, 1],
|
|
|
|
|
|
"origin": [0, 0, 0],
|
|
|
|
|
|
"bounds": {"u_range": [-200, 200], "v_range": [-200, 200]}
|
|
|
|
|
|
}
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
|
|
|
|
|
def _create_parting_surface_from_ai(self, ai_result: Dict, analysis: Dict,
|
|
|
|
|
|
shape: Any = None) -> Dict:
|
2026-03-14 01:29:40 +08:00
|
|
|
|
"""从 AI 结果创建分型面"""
|
|
|
|
|
|
origin = ai_result.get("origin", [0, 0, 0])
|
|
|
|
|
|
normal = ai_result.get("normal", [0, 0, 1])
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
parting_plane = gp_Pln(
|
|
|
|
|
|
gp_Pnt(origin[0], origin[1], origin[2]),
|
|
|
|
|
|
gp_Dir(normal[0], normal[1], normal[2])
|
|
|
|
|
|
)
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
try:
|
|
|
|
|
|
parting_surface = BRepBuilderAPI_MakeFace(parting_plane).Face()
|
2026-04-19 23:41:35 +08:00
|
|
|
|
except Exception:
|
2026-03-14 01:29:40 +08:00
|
|
|
|
parting_plane = gp_Pln(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1))
|
|
|
|
|
|
parting_surface = BRepBuilderAPI_MakeFace(parting_plane).Face()
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
|
|
|
|
|
if shape is not None:
|
|
|
|
|
|
parting_line = self._calculate_parting_line(shape, parting_surface)
|
|
|
|
|
|
else:
|
|
|
|
|
|
parting_line = []
|
|
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
return {
|
|
|
|
|
|
"primary_surface": parting_surface,
|
|
|
|
|
|
"primary_line": parting_line,
|
|
|
|
|
|
"primary_direction": normal,
|
|
|
|
|
|
"confidence": ai_result.get("confidence", 0.8),
|
|
|
|
|
|
"additional_surfaces": [],
|
|
|
|
|
|
"surface_count": 1
|
|
|
|
|
|
}
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
# ==================== 辅助方法 ====================
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
def _calculate_mold_size(self, analysis: Dict) -> Dict[str, float]:
|
|
|
|
|
|
"""估算模具尺寸"""
|
|
|
|
|
|
dims = analysis["bounding_box"]["dimensions"]
|
|
|
|
|
|
margin = 30
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
return {
|
|
|
|
|
|
"length": dims[0] + 2 * margin,
|
|
|
|
|
|
"width": dims[1] + 2 * margin,
|
|
|
|
|
|
"height": dims[2] + margin + 80,
|
|
|
|
|
|
"margin": margin
|
|
|
|
|
|
}
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
def _calculate_clamping_force(self, analysis: Dict) -> str:
|
|
|
|
|
|
"""估算锁模力"""
|
|
|
|
|
|
volume_cm3 = analysis.get("volume", 0) / 1000
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
if volume_cm3 < 10:
|
|
|
|
|
|
return "30-50 吨"
|
|
|
|
|
|
elif volume_cm3 < 50:
|
|
|
|
|
|
return "50-100 吨"
|
|
|
|
|
|
elif volume_cm3 < 200:
|
|
|
|
|
|
return "100-200 吨"
|
|
|
|
|
|
else:
|
|
|
|
|
|
return "200+ 吨"
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
def _estimate_wall_thickness(self, analysis: Dict) -> str:
|
|
|
|
|
|
"""估算壁厚范围"""
|
|
|
|
|
|
volume = analysis.get("volume", 0)
|
|
|
|
|
|
surface_area = analysis.get("surface_area", 0)
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
if surface_area > 0 and volume > 0:
|
|
|
|
|
|
avg_thickness = (volume / surface_area) * 0.6
|
|
|
|
|
|
return f"{avg_thickness * 0.7:.2f} - {avg_thickness * 1.3:.2f} mm"
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
return "10.0 - 30.0 mm (铝泡沫典型)"
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
def _calculate_complexity_score(self, analysis: Dict) -> float:
|
|
|
|
|
|
"""计算复杂度评分"""
|
|
|
|
|
|
volume = analysis.get("volume", 0)
|
|
|
|
|
|
surface_area = analysis.get("surface_area", 0)
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
if surface_area > 0 and volume > 0:
|
|
|
|
|
|
thickness_ratio = (volume / surface_area) * 0.6
|
|
|
|
|
|
complexity = min(thickness_ratio / 5.0, 10.0)
|
|
|
|
|
|
return round(complexity, 1)
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
return 5.0
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
def _estimate_cycle_time(self, analysis: Dict) -> str:
|
|
|
|
|
|
"""估算成型周期"""
|
|
|
|
|
|
volume_cm3 = analysis.get("volume", 0) / 1000
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
if volume_cm3 < 10:
|
|
|
|
|
|
return "60-90 秒"
|
|
|
|
|
|
elif volume_cm3 < 50:
|
|
|
|
|
|
return "90-120 秒"
|
|
|
|
|
|
elif volume_cm3 < 200:
|
|
|
|
|
|
return "120-180 秒"
|
|
|
|
|
|
else:
|
|
|
|
|
|
return "180-300 秒"
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
def _identify_sink_mark_risk(self, analysis: Dict) -> str:
|
|
|
|
|
|
"""识别缩痕风险"""
|
|
|
|
|
|
return "中 - 铝泡沫壁厚大,需控制发泡均匀性"
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
2026-03-14 01:29:40 +08:00
|
|
|
|
def _assess_venting_requirement(self, analysis: Dict) -> str:
|
|
|
|
|
|
"""评估排气需求"""
|
|
|
|
|
|
volume = analysis.get("volume", 0)
|
2026-04-19 23:41:35 +08:00
|
|
|
|
|
|
|
|
|
|
if volume > 50000000:
|
2026-03-14 01:29:40 +08:00
|
|
|
|
return "高 - 需要加强排气系统"
|
2026-04-19 23:41:35 +08:00
|
|
|
|
elif volume > 10000000:
|
2026-03-14 01:29:40 +08:00
|
|
|
|
return "中 - 建议标准排气"
|
|
|
|
|
|
else:
|
|
|
|
|
|
return "低 - 常规排气即可"
|