修复几何复杂度分析重复零件问题 - 添加装配体遍历去重机制

核心改动:
- 在CollectAssemblyParts方法中添加std::set<string>去重逻辑
- 基于零件文件名进行重复检测,确保每个零件只被分析一次
- 递归遍历装配体时正确传递去重集合
- 解决标准件等重复使用零件的重复分析问题

技术实现:
- 修改GeometryAnalyzer.h: CollectAssemblyParts添加processed_parts参数
- 修改GeometryAnalyzer.cpp: 在CollectAllParts中创建去重集合
- 在CollectAssemblyParts中检查零件是否已处理,避免重复添加

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
sladro 2025-08-28 16:58:15 +08:00
parent 444307aea3
commit d5accfe24a
3 changed files with 20 additions and 7 deletions

View File

@ -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错误 → 动态超时和详细异常处理
- 几何复杂度分析重复零件 → 装配体遍历去重机制
## 下一步计划

View File

@ -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<std::string> 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<std::pair<pfcModel_ptr, std::string>>& parts) {
std::vector<std::pair<pfcModel_ptr, std::string>>& parts,
std::set<std::string>& 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);
}
}

View File

@ -213,7 +213,8 @@ private:
void CollectAllParts(pfcModel_ptr model, const std::string& base_path,
std::vector<std::pair<pfcModel_ptr, std::string>>& parts);
void CollectAssemblyParts(wfcWAssembly_ptr assembly, const std::string& base_path,
std::vector<std::pair<pfcModel_ptr, std::string>>& parts);
std::vector<std::pair<pfcModel_ptr, std::string>>& parts,
std::set<std::string>& processed_parts);
// 工具方法
std::string GetModelFileSize(pfcModel_ptr model);