This commit is contained in:
2026-03-08 22:34:47 +08:00
parent 41f6498291
commit 3e19e45e9a
2 changed files with 37 additions and 11 deletions
+26 -1
View File
@@ -440,6 +440,9 @@ def main():
stp_path = sys.argv[1] stp_path = sys.argv[1]
# 检查是否跳过 PythonOCC 验证(默认跳过,因为主流程已用 PythonOCC 解析)
skip_pythonocc = os.environ.get('SKIP_PYTHONOCC', 'true').lower() == 'true'
if not os.path.exists(stp_path): if not os.path.exists(stp_path):
print(f"❌ 文件不存在: {stp_path}") print(f"❌ 文件不存在: {stp_path}")
sys.exit(1) sys.exit(1)
@@ -452,20 +455,42 @@ def main():
print(f"# STP文件几何验证报告") print(f"# STP文件几何验证报告")
print(f"# 文件: {stp_path}") print(f"# 文件: {stp_path}")
print(f"# 时间: {verification_result['timestamp']}") print(f"# 时间: {verification_result['timestamp']}")
print(f"# PythonOCC验证: {'跳过' if skip_pythonocc else '启用'}")
print(f"{'#'*70}") print(f"{'#'*70}")
# FreeCAD验证 # FreeCAD验证
freecad_result = verify_with_freecad(stp_path) freecad_result = verify_with_freecad(stp_path)
verification_result["freecad"] = freecad_result or {} verification_result["freecad"] = freecad_result or {}
# PythonOCC验证 # PythonOCC验证(可选,默认跳过以节省时间)
pythonocc_result = None
if not skip_pythonocc:
pythonocc_result = verify_with_pythonocc(stp_path) pythonocc_result = verify_with_pythonocc(stp_path)
verification_result["pythonocc"] = pythonocc_result or {} verification_result["pythonocc"] = pythonocc_result or {}
else:
print("\n⏩ 跳过 PythonOCC 验证(主流程已使用 PythonOCC 解析)")
verification_result["pythonocc"] = {"skipped": True, "reason": "主流程已使用PythonOCC解析"}
# 对比结果 # 对比结果
if pythonocc_result:
comparison = compare_results(freecad_result, pythonocc_result) comparison = compare_results(freecad_result, pythonocc_result)
verification_result["comparison"] = comparison or {} verification_result["comparison"] = comparison or {}
verification_result["status"] = comparison.get('overall_status', 'failed') if comparison else 'failed' verification_result["status"] = comparison.get('overall_status', 'failed') if comparison else 'failed'
else:
# 只有 FreeCAD 验证时,根据 FreeCAD 结果判断
if freecad_result:
verification_result["status"] = "passed"
verification_result["comparison"] = {
"note": "仅执行 FreeCAD 验证",
"freecad_volume_cm3": freecad_result.get('volume_cm3'),
"freecad_surface_area_cm2": freecad_result.get('surface_area_cm2')
}
print(f"\n{'='*70}")
print(f"验证结果: ✅ 通过 (仅FreeCAD验证)")
print(f"{'='*70}\n")
else:
verification_result["status"] = "failed"
verification_result["comparison"] = {"note": "FreeCAD 验证失败"}
# 保存JSON报告 # 保存JSON报告
report_path = Path(stp_path).stem + "_verification_report.json" report_path = Path(stp_path).stem + "_verification_report.json"
+6 -5
View File
@@ -19,13 +19,14 @@ logger = get_logger(__name__)
class GeometryVerificationService: class GeometryVerificationService:
"""几何验证服务""" """几何验证服务"""
def __init__(self): def __init__(self, timeout: int = 60):
# 验证脚本在项目根目录的 scripts 文件夹下 # 验证脚本在项目根目录的 scripts 文件夹下
# __file__ = /path/to/project/src/services/verification_service.py # __file__ = /path/to/project/src/services/verification_service.py
# parent = /path/to/project/src/services # parent = /path/to/project/src/services
# parent.parent = /path/to/project/src # parent.parent = /path/to/project/src
# parent.parent.parent = /path/to/project (正确) # parent.parent.parent = /path/to/project (正确)
self.verification_script = Path(__file__).parent.parent.parent / "scripts" / "verify_stp.py" self.verification_script = Path(__file__).parent.parent.parent / "scripts" / "verify_stp.py"
self.timeout = timeout # 超时时间(秒),默认60秒
async def verify_stp_file(self, stp_path: str) -> Dict[str, Any]: async def verify_stp_file(self, stp_path: str) -> Dict[str, Any]:
""" """
@@ -142,19 +143,19 @@ class GeometryVerificationService:
env=env env=env
) )
# 30秒超时 # 使用配置的超时时间
try: try:
stdout, stderr = await asyncio.wait_for( stdout, stderr = await asyncio.wait_for(
process.communicate(), process.communicate(),
timeout=30.0 timeout=self.timeout
) )
except asyncio.TimeoutError: except asyncio.TimeoutError:
logger.error("验证脚本执行超时(30秒)") logger.error(f"验证脚本执行超时({self.timeout}秒)")
process.kill() process.kill()
await process.wait() await process.wait()
return { return {
"status": "error", "status": "error",
"error": "验证脚本执行超时(30秒)", "error": f"验证脚本执行超时({self.timeout}秒)",
"timestamp": datetime.now().isoformat() "timestamp": datetime.now().isoformat()
} }