Merge remote-tracking branch 'origin/main'

# Conflicts:
#	src/api/routes.py
#	src/core/aluminum_foam_mold.py
#	src/core/geometry_analyzer.py
#	src/core/mold_generator.py
This commit is contained in:
2026-04-19 23:42:02 +08:00
17 changed files with 1369 additions and 33 deletions
+26 -30
View File
@@ -133,10 +133,13 @@ class STPParser:
props = GProp_GProps()
brepgprop.VolumeProperties(shape, props)
return props.Mass()
volume = props.Mass()
if volume <= 0:
raise ValueError("计算得到的体积为0或负数,形状可能无效")
return volume
except Exception as e:
logger.error(f"体积计算失败: {e}")
return 1000000.0
raise RuntimeError(f"体积计算失败: {e}") from e
def _compute_surface_area(self, shape) -> float:
"""计算表面积"""
@@ -147,7 +150,6 @@ class STPParser:
props = GProp_GProps()
brepgprop.SurfaceProperties(shape, props)
area = props.Mass()
logger.info(f"表面积计算成功: {area:.2f} mm²")
# 如果计算结果为0,使用备选估算方法
if area <= 0:
@@ -155,18 +157,23 @@ class STPParser:
raise ValueError("Surface area is zero")
return area
except Exception as e:
logger.error(f"表面积计算失败: {e}")
except ValueError:
# 基于边界框估算表面积
try:
bbox = self._compute_bounding_box(shape)
dims = bbox.get("dimensions", [100, 100, 100])
dims = bbox.get("dimensions", [0, 0, 0])
if any(d <= 0 for d in dims):
raise RuntimeError("边界框尺寸无效,无法估算表面积")
# 简化的估算公式:2*(lw + lh + wh)
estimated_area = 2 * (dims[0]*dims[1] + dims[0]*dims[2] + dims[1]*dims[2])
logger.warning(f"使用边界框估算表面积: {estimated_area:.2f} mm²")
return estimated_area
except:
return 60000.0
except Exception as e:
logger.error(f"表面积估算失败: {e}")
raise RuntimeError(f"表面积计算失败: {e}") from e
except Exception as e:
logger.error(f"表面积计算失败: {e}")
raise RuntimeError(f"表面积计算失败: {e}") from e
def _compute_center_of_mass(self, shape) -> List[float]:
"""计算质心"""
@@ -180,7 +187,12 @@ class STPParser:
return [float(center.X()), float(center.Y()), float(center.Z())]
except Exception as e:
logger.error(f"质心计算失败: {e}")
return [0.0, 0.0, 0.0]
# 回退到边界框中心
try:
bbox = self._compute_bounding_box(shape)
return bbox.get("center", [0.0, 0.0, 0.0])
except Exception:
raise RuntimeError(f"质心计算失败且边界框回退也失败: {e}") from e
def _compute_inertia_properties(self, shape) -> Dict[str, Any]:
"""计算惯性属性"""
@@ -227,30 +239,14 @@ class STPParser:
logger.error(f"拓扑分析失败: {e}")
raise
def _create_dummy_shape(self):
"""创建虚拟形状"""
return "dummy_shape"
def _simulate_analysis(self) -> Dict[str, Any]:
"""模拟分析结果"""
logger.info("使用模拟分析数据")
return {
"bounding_box": self._default_bounding_box(),
"volume": 1000000.0,
"surface_area": 60000.0,
"topology": {"faces": 6, "edges": 12, "vertices": 8},
"center_of_mass": [50.0, 50.0, 50.0],
"inertia_properties": {},
"analysis_method": "simulated"
}
def _default_bounding_box(self) -> Dict[str, Any]:
"""默认边界框"""
"""默认边界框(边界框计算失败时的回退值,标注为估算)"""
return {
"min": [0.0, 0.0, 0.0],
"max": [100.0, 100.0, 100.0],
"dimensions": [100.0, 100.0, 100.0],
"center": [50.0, 50.0, 50.0]
"max": [0.0, 0.0, 0.0],
"dimensions": [0.0, 0.0, 0.0],
"center": [0.0, 0.0, 0.0],
"estimated": True
}
def export_to_json(self, geometry_data: Dict[str, Any], output_path: Path) -> str: