diff --git a/CLAUDE.md b/CLAUDE.md index 11b3615..8c3a7b4 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -87,6 +87,11 @@ POST /api/creo/shrinkwrap/shell # Shrinkwrap导出(支持动态超 - **向后兼容**: 新参数可选,不影响现有API调用 - **详细错误信息**: 为不同异常类型提供具体错误描述和解决建议 +### 几何复杂度分析优化 +- **装配体去重机制**: 使用std::set跟踪已处理零件,避免重复分析相同零件 +- **基于文件名去重**: 使用模型文件名作为唯一标识符进行重复检测 +- **递归装配体支持**: 正确处理多层级装配体中的重复零件 + ## 构建环境 - **IDE**: Visual Studio 2022 (v143工具集) @@ -110,6 +115,7 @@ POST /api/creo/shrinkwrap/shell # Shrinkwrap导出(支持动态超 - 字符编码冲突 → UTF-8 BOM标准化 - Socket超时阻塞 → 30秒超时机制 - Shrinkwrap复杂模型500错误 → 动态超时和详细异常处理 +- 几何复杂度分析重复零件 → 装配体遍历去重机制 ## 下一步计划 diff --git a/GeometryAnalyzer.cpp b/GeometryAnalyzer.cpp index d4f4025..c0836f6 100644 --- a/GeometryAnalyzer.cpp +++ b/GeometryAnalyzer.cpp @@ -755,16 +755,18 @@ void GeometryAnalyzer::CollectAllParts(pfcModel_ptr model, const std::string& ba parts.push_back(std::make_pair(model, base_path)); } else if (model_type == pfcMDL_ASSEMBLY) { - // 装配体:递归遍历所有组件 + // 装配体:递归遍历所有组件,使用去重集合 + std::set processed_parts; wfcWAssembly_ptr assembly = wfcWAssembly::cast(model); if (assembly) { - CollectAssemblyParts(assembly, base_path, parts); + CollectAssemblyParts(assembly, base_path, parts, processed_parts); } } } void GeometryAnalyzer::CollectAssemblyParts(wfcWAssembly_ptr assembly, const std::string& base_path, - std::vector>& parts) { + std::vector>& parts, + std::set& processed_parts) { if (!assembly) return; try { @@ -794,14 +796,18 @@ void GeometryAnalyzer::CollectAssemblyParts(wfcWAssembly_ptr assembly, const std pfcModelType comp_type = comp_model->GetType(); if (comp_type == pfcMDL_PART) { - // 零件:添加到列表 - parts.push_back(std::make_pair(comp_model, comp_path)); + // 零件:检查是否已处理过 + if (processed_parts.find(comp_name) == processed_parts.end()) { + // 未处理过的零件,添加到列表和已处理集合 + parts.push_back(std::make_pair(comp_model, comp_path)); + processed_parts.insert(comp_name); + } } else if (comp_type == pfcMDL_ASSEMBLY) { // 子装配体:递归处理 wfcWAssembly_ptr sub_assembly = wfcWAssembly::cast(comp_model); if (sub_assembly) { - CollectAssemblyParts(sub_assembly, comp_path, parts); + CollectAssemblyParts(sub_assembly, comp_path, parts, processed_parts); } } diff --git a/GeometryAnalyzer.h b/GeometryAnalyzer.h index 6ccce68..fd40816 100644 --- a/GeometryAnalyzer.h +++ b/GeometryAnalyzer.h @@ -213,7 +213,8 @@ private: void CollectAllParts(pfcModel_ptr model, const std::string& base_path, std::vector>& parts); void CollectAssemblyParts(wfcWAssembly_ptr assembly, const std::string& base_path, - std::vector>& parts); + std::vector>& parts, + std::set& processed_parts); // 工具方法 std::string GetModelFileSize(pfcModel_ptr model);