x
This commit is contained in:
@@ -52,7 +52,7 @@ def verify_with_freecad(stp_path):
|
||||
|
||||
# 方法1: Import.insert (FreeCAD 0.21+)
|
||||
try:
|
||||
Import.insert(stp_path)
|
||||
Import.insert(stp_path, doc.Name)
|
||||
imported = True
|
||||
print("使用 Import.insert 导入成功")
|
||||
except Exception as e1:
|
||||
@@ -63,6 +63,7 @@ def verify_with_freecad(stp_path):
|
||||
try:
|
||||
Import.open(stp_path)
|
||||
imported = True
|
||||
doc = FreeCAD.ActiveDocument
|
||||
print("使用 Import.open 导入成功")
|
||||
except Exception as e2:
|
||||
print(f"Import.open 失败: {e2}")
|
||||
@@ -81,7 +82,7 @@ def verify_with_freecad(stp_path):
|
||||
# 方法4: Part.insert (旧版本)
|
||||
if not imported:
|
||||
try:
|
||||
Part.insert(stp_path)
|
||||
Part.insert(stp_path, doc.Name)
|
||||
imported = True
|
||||
print("使用 Part.insert 导入成功")
|
||||
except Exception as e4:
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user