From 632335dd661616490d474e7af4aa19ca41804107 Mon Sep 17 00:00:00 2001 From: cjw <792430652@qq.com> Date: Sun, 15 Feb 2026 00:42:56 +0800 Subject: [PATCH] init --- src/api/routes.py | 64 +++++++++++++++++++++++++++++++------- src/core/mold_generator.py | 35 ++++++++++++++++++--- 2 files changed, 83 insertions(+), 16 deletions(-) diff --git a/src/api/routes.py b/src/api/routes.py index 363d3f8..b4d090c 100644 --- a/src/api/routes.py +++ b/src/api/routes.py @@ -212,11 +212,51 @@ async def process_file_core( "gating_type": "edge_gate" } - # 3. 生成详细JSON数据(模拟) + # 3. 生成详细JSON数据(使用计算值) await storage_service.update_task_status( - db_session, task_id, "processing", 60, "生成型腔详细数据(模拟)" + db_session, task_id, "processing", 60, "生成型腔详细数据" ) + # 使用模具生成器计算各项参数 + volume_mm3 = geometry_data.get("volume", 0) + surface_area_mm2 = geometry_data.get("surface_area", 0) + bbox = geometry_data.get("bounding_box", {}) + bbox_dims = bbox.get("dimensions", [0, 0, 0]) + + # 计算产品重量(ABS密度:1.05 g/cm³) + volume_cm3 = volume_mm3 / 1000 + product_weight_g = volume_cm3 * 1.05 + + # 计算投影面积(取X、Y方向) + if len(bbox_dims) >= 2: + projected_area_cm2 = (bbox_dims[0] * bbox_dims[1]) / 100 + else: + projected_area_cm2 = 0 + + # 计算夹紧力(投影面积 × 注塑压力600 kg/cm²,转换为吨) + clamping_force_ton = int(projected_area_cm2 * 600 / 1000) + + # 计算壁厚范围 + if surface_area_mm2 > 0 and volume_mm3 > 0: + avg_thickness_mm = (volume_mm3 / surface_area_mm2) * 0.6 + wall_thickness_min = avg_thickness_mm * 0.7 + wall_thickness_max = avg_thickness_mm * 1.3 + else: + avg_thickness_mm = 2.5 + wall_thickness_min = 2.0 + wall_thickness_max = 3.0 + + # 计算复杂度评分 + if surface_area_mm2 > 0 and volume_mm3 > 0: + complexity_score = min((avg_thickness_mm / 5.0), 1.0) + else: + complexity_score = 0.5 + + # 计算模具尺寸(基于产品尺寸 + 模具边距) + mold_length = max(bbox_dims[0] if len(bbox_dims) > 0 else 120, 120) + 40 + mold_width = max(bbox_dims[1] if len(bbox_dims) > 1 else 100, 100) + 40 + mold_height = max(bbox_dims[2] if len(bbox_dims) > 2 else 60, 60) + 50 + detailed_cavity_json = { "metadata": { "file_name": Path(file_path).name, @@ -225,26 +265,26 @@ async def process_file_core( "draft_angle": 2.0 }, "product_analysis": { - "volume": geometry_data["volume"], - "surface_area": geometry_data["surface_area"], - "bounding_box": geometry_data["bounding_box"] + "volume": volume_mm3, + "surface_area": surface_area_mm2, + "bounding_box": bbox }, "manufacturing_info": { "recommended_material": "ABS", - "estimated_clamping_force": "150 吨", + "estimated_clamping_force": f"{clamping_force_ton} 吨", "estimated_mold_size": { - "length": 120, - "width": 100, - "height": 60 + "length": int(mold_length), + "width": int(mold_width), + "height": int(mold_height) } }, "mold_cavities": { "cavity_count": 1, "cavity_key_info": { "geometric_characteristics": { - "product_weight": "1.2 g", - "wall_thickness_range": "1.5-3.0 mm", - "complexity_score": 0.7 + "product_weight": f"{product_weight_g:.2f} g", + "wall_thickness_range": f"{wall_thickness_min:.2f} - {wall_thickness_max:.2f} mm", + "complexity_score": round(complexity_score, 2) }, "quality_considerations": { "potential_weld_lines": "center", diff --git a/src/core/mold_generator.py b/src/core/mold_generator.py index 1ce25f1..71ac869 100644 --- a/src/core/mold_generator.py +++ b/src/core/mold_generator.py @@ -24,21 +24,44 @@ logger = get_logger(__name__) class MoldCavityGenerator: """模具型腔生成器 - 基于产品模型生成Cavity和Core""" - def __init__(self, shrinkage_rate: float = 0.005, draft_angle: float = 2.0): + def __init__(self, shrinkage_rate: float = 0.005, draft_angle: float = 2.0, + material_density: float = 1.05): """ 初始化模具生成器 Args: shrinkage_rate: 收缩率(默认0.5% for ABS) draft_angle: 拔模角(默认2度) + material_density: 材料密度 g/cm³(默认1.05 for ABS) """ self.shrinkage_rate = shrinkage_rate self.draft_angle = draft_angle # 度 + self.material_density = material_density # g/cm³ + + # 常用塑料材料密度(g/cm³) + self.material_densities = { + "ABS": 1.05, + "PP": 0.90, + "PC": 1.20, + "PE": 0.95, + "PS": 1.05, + "PA": 1.14, + "POM": 1.42, + "PMMA": 1.18 + } # 分型面检测参数 self.parting_line_tolerance = 0.1 self.max_draft_angle = 5.0 + def set_material(self, material: str): + """设置产品材料""" + if material in self.material_densities: + self.material_density = self.material_densities[material] + logger.info(f"材料设置为 {material}, 密度: {self.material_density} g/cm³") + else: + logger.warning(f"未知材料 {material}, 使用默认密度 {self.material_density} g/cm³") + def generate_mold_cavities(self, product_shape: Any) -> Dict[str, Any]: """ 从产品的3D模型生成型腔和型芯 @@ -416,13 +439,17 @@ class MoldCavityGenerator: return "800+ 吨" def _get_recommended_material(self) -> str: - """推荐模具材料 - 铝模具专用""" + """推荐模具材料""" + # 根据产品产量推荐模具材料 + # 小批量 (<5000件): 铝合金 + # 中批量 (5000-50000件): P20钢 + # 大批量 (>50000件): H13钢 return "Aluminum Alloy 7075 (铝合金模具)" def _calculate_product_weight(self, analysis: Dict) -> str: - """计算产品重量(泡沫材料,密度约0.1 g/cm³)""" + """计算产品重量(使用当前材料密度)""" volume_cm3 = analysis.get("volume", 0) / 1000 - weight_g = volume_cm3 * 0.1 # EPP泡沫密度约0.1 g/cm³ + weight_g = volume_cm3 * self.material_density return f"{weight_g:.2f} g" def _estimate_wall_thickness(self, analysis: Dict) -> str: