deving
This commit is contained in:
+58
-8
@@ -15,6 +15,7 @@ from database.database import get_db_session
|
||||
from utils.logger import get_logger
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from core.mold_generator import MoldCavityGenerator
|
||||
from core.mesh_generator import MeshGenerator
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
@@ -27,6 +28,7 @@ file_handler = FileHandler()
|
||||
html_generator = HTMLGenerator()
|
||||
# 初始化模具生成器(可配置不同材料的收缩率)
|
||||
mold_generator = MoldCavityGenerator(shrinkage_rate=0.005) # ABS材料
|
||||
mesh_generator = MeshGenerator(quality="medium")
|
||||
|
||||
# 内存中的任务存储
|
||||
tasks = {}
|
||||
@@ -359,7 +361,55 @@ async def process_file_core(
|
||||
shape = stp_parser.load_step_file(Path(file_path))
|
||||
geometry_data = stp_parser.analyze_geometry(shape)
|
||||
|
||||
# 2. 生成模具型腔(模拟数据)
|
||||
# 2. 生成网格数据并持久化(详细 JSON 存 RustFS,摘要写 PostgreSQL)
|
||||
await storage_service.update_task_status(
|
||||
db_session, task_id, "processing", 30, "生成网格数据"
|
||||
)
|
||||
|
||||
mesh_result = None
|
||||
mesh_json = None
|
||||
try:
|
||||
mesh_result = mesh_generator.generate_mesh_from_shape(shape)
|
||||
|
||||
tri_mesh = mesh_result.get("trimesh_mesh")
|
||||
pointcloud = mesh_result.get("pointcloud") or {}
|
||||
|
||||
if tri_mesh is not None:
|
||||
# 顶点和面转为 JSON 可序列化
|
||||
vertices = tri_mesh.vertices.tolist()
|
||||
faces = tri_mesh.faces.tolist()
|
||||
|
||||
# 使用已计算的几何边界框,避免重复计算
|
||||
bbox = geometry_data.get("bounding_box", {})
|
||||
|
||||
mesh_json = {
|
||||
"metadata": {
|
||||
"file_name": Path(file_path).name,
|
||||
"generated_at": datetime.now().isoformat(),
|
||||
"quality": "medium",
|
||||
"vertex_count": len(vertices),
|
||||
"face_count": len(faces),
|
||||
"point_count": pointcloud.get("count"),
|
||||
},
|
||||
"mesh": {
|
||||
"vertices": vertices,
|
||||
"faces": faces,
|
||||
},
|
||||
"pointcloud": pointcloud,
|
||||
"bounding_box": bbox,
|
||||
}
|
||||
|
||||
await storage_service.save_mesh_data(
|
||||
db_session,
|
||||
stp_file_id=stp_file_id,
|
||||
mesh_json=mesh_json,
|
||||
quality="medium",
|
||||
)
|
||||
except Exception as mesh_err:
|
||||
# 网格失败不影响整体流程,只记录日志
|
||||
logger.warning(f"网格生成或保存失败,不影响主流程: {mesh_err}")
|
||||
|
||||
# 3. 生成模具型腔(模拟数据)
|
||||
await storage_service.update_task_status(
|
||||
db_session, task_id, "processing", 40, "生成模具型腔(模拟)"
|
||||
)
|
||||
@@ -371,7 +421,7 @@ async def process_file_core(
|
||||
"gating_type": "edge_gate"
|
||||
}
|
||||
|
||||
# 3. 生成详细JSON数据(使用计算值)
|
||||
# 4. 生成详细JSON数据(使用计算值)
|
||||
await storage_service.update_task_status(
|
||||
db_session, task_id, "processing", 60, "生成型腔详细数据"
|
||||
)
|
||||
@@ -472,10 +522,10 @@ async def process_file_core(
|
||||
}
|
||||
}
|
||||
|
||||
# 4. 生成关键信息(模拟)
|
||||
# 5. 生成关键信息(模拟)
|
||||
cavity_key_info = detailed_cavity_json["mold_cavities"]["cavity_key_info"]
|
||||
|
||||
# 5. 保存几何数据到数据库
|
||||
# 6. 保存几何数据到数据库
|
||||
await storage_service.update_task_status(
|
||||
db_session, task_id, "processing", 70, "保存几何数据"
|
||||
)
|
||||
@@ -487,14 +537,14 @@ async def process_file_core(
|
||||
geometry_data.get("analysis_method", "mold_cavity")
|
||||
)
|
||||
|
||||
# 6. 保存模具型腔数据
|
||||
# 7. 保存模具型腔数据
|
||||
await storage_service.save_mold_cavity_data(
|
||||
db_session,
|
||||
stp_file_id,
|
||||
detailed_cavity_json
|
||||
)
|
||||
|
||||
# 7. 生成HTML可视化(包含型腔信息)
|
||||
# 8. 生成HTML可视化(包含型腔信息)
|
||||
await storage_service.update_task_status(
|
||||
db_session, task_id, "processing", 85, "生成可视化报告"
|
||||
)
|
||||
@@ -513,10 +563,10 @@ async def process_file_core(
|
||||
html_file_path
|
||||
)
|
||||
|
||||
# 8. 分析模具设计
|
||||
# 9. 分析模具设计
|
||||
analysis_result = geometry_analyzer.analyze_mold_design(geometry_data)
|
||||
|
||||
# 9. 完成处理
|
||||
# 10. 完成处理
|
||||
await storage_service.update_stp_file_status(db_session, stp_file_id, "completed")
|
||||
await storage_service.update_task_status(
|
||||
db_session, task_id, "completed", 100, "模具型腔生成完成"
|
||||
|
||||
Reference in New Issue
Block a user