This commit is contained in:
2026-03-08 15:49:41 +08:00
parent 22496d2b5e
commit 9a6585b72e
2 changed files with 20 additions and 13 deletions
+17 -11
View File
@@ -69,14 +69,14 @@ class GeometryVerificationService:
cmd = None
# 尝试多种 FreeCAD 命令名称
# PPA 版本通常使用 freecad 或 freecadcmd
# snap 版本使用 freecad.cmd
for cmd_name in ['freecadcmd', 'freecad-cmd', 'freecad', '/usr/bin/freecad', '/usr/bin/freecadcmd', '/snap/bin/freecad.cmd']:
# AppImage 版本使用 freecad
# PPA 版本通常使用 freecadcmd
for cmd_name in ['freecad', 'freecadcmd', 'freecad-cmd', '/usr/local/bin/freecad', '/usr/bin/freecad', '/snap/bin/freecad.cmd']:
try:
result = subprocess.run(['which', cmd_name], capture_output=True, text=True)
if result.returncode == 0 and result.stdout.strip():
# 使用绝对路径
cmd = [cmd_name, str(self.verification_script), str(Path(stp_path_str).absolute())]
# 使用绝对路径,添加 -c 参数使用命令行模式(无图形界面)
cmd = [cmd_name, '-c', str(self.verification_script), str(Path(stp_path_str).absolute())]
logger.info(f"找到 FreeCAD 命令: {cmd_name}")
break
except:
@@ -84,9 +84,10 @@ class GeometryVerificationService:
# 如果 which 找不到,尝试直接检查常见路径
if not cmd:
for cmd_path in ['/usr/bin/freecad', '/usr/bin/freecadcmd', '/usr/local/bin/freecad', '/snap/bin/freecad.cmd']:
for cmd_path in ['/usr/local/bin/freecad', '/usr/bin/freecad', '/usr/local/bin/freecadcmd', '/usr/bin/freecadcmd', '/snap/bin/freecad.cmd']:
if Path(cmd_path).exists():
cmd = [cmd_path, str(self.verification_script), str(Path(stp_path_str).absolute())]
# 添加 -c 参数使用命令行模式(无图形界面)
cmd = [cmd_path, '-c', str(self.verification_script), str(Path(stp_path_str).absolute())]
logger.info(f"找到 FreeCAD 命令路径: {cmd_path}")
break
@@ -168,8 +169,12 @@ class GeometryVerificationService:
)
if has_error:
logger.warning("FreeCAD 验证失败,使用 PythonOCC 验证")
return self._verify_with_pythonocc_only(stp_path_str)
logger.error("FreeCAD 验证失败,无法进行交叉验证")
return {
"status": "error",
"reason": "FreeCAD 无法读取 STP 文件,无法进行交叉验证",
"timestamp": datetime.now().isoformat()
}
if process.returncode == 0:
# 尝试读取生成的报告文件(在 STP 文件目录下)
@@ -327,8 +332,9 @@ class GeometryVerificationService:
return count
return {
"status": "skipped",
"reason": "FreeCAD 无法访问文件(snap 沙盒限制),仅使用 PythonOCC 验证",
"status": "passed",
"method": "pythonocc_only",
"reason": "FreeCAD 验证失败,仅使用 PythonOCC 验证",
"timestamp": datetime.now().isoformat(),
"pythonocc": {
"volume_mm3": float(volume_mm3),