feat: optimize hierarchy analysis with target_level=0 for total counts
- Add special handling for target_level=0 to return only total part count and hierarchy levels - Use ListDisplayedComponents() for total component counting (same as GetModelStatus) - Use SafeCalculateAssemblyLevels() for hierarchy level counting (same as GetModelStatus) - Remove unnecessary recursive counting methods (CountTotalParts, CountMaxLevels) - Improve performance by avoiding full hierarchy tree construction when only counts are needed - Ensure consistency with existing model status API results 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
8fd63500f2
commit
d5f87e5457
@ -1032,7 +1032,58 @@ HierarchyAnalysisResult CreoManager::AnalyzeModelHierarchy(const HierarchyAnalys
|
||||
result.error_message = "Failed to cast model to assembly";
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// Special handling for target_level=0: return only total counts
|
||||
if (request.target_level == 0) {
|
||||
result.project_name = request.project_name.empty() ?
|
||||
XStringToString(current_model->GetFileName()) : request.project_name;
|
||||
|
||||
// Use ListDisplayedComponents (same as GetModelStatus) for total count
|
||||
wfcWComponentPaths_ptr components = assembly->ListDisplayedComponents();
|
||||
if (components) {
|
||||
result.total_components = components->getarraysize() + 1; // +1 for root assembly
|
||||
} else {
|
||||
result.total_components = 1; // At least the root assembly
|
||||
}
|
||||
|
||||
result.total_levels = SafeCalculateAssemblyLevels(assembly);
|
||||
|
||||
// Create minimal hierarchy with just the root assembly
|
||||
result.hierarchy.clear();
|
||||
result.hierarchy.push_back(std::vector<ComponentInfo>());
|
||||
|
||||
ComponentInfo root_component;
|
||||
try {
|
||||
xstring filename_xstr = current_model->GetFileName();
|
||||
root_component.id = XStringToString(filename_xstr);
|
||||
} catch (...) {
|
||||
root_component.id = "root_assembly.asm";
|
||||
}
|
||||
|
||||
root_component.name = root_component.id;
|
||||
root_component.type = "assembly";
|
||||
root_component.level = 0;
|
||||
root_component.path = root_component.id;
|
||||
root_component.full_path = root_component.id;
|
||||
root_component.file_size = GetModelFileSize(current_model);
|
||||
root_component.deletion_safety = "forbidden";
|
||||
root_component.is_visible = true;
|
||||
root_component.model_type = "MDL_ASSEMBLY";
|
||||
|
||||
// Count direct children for root assembly
|
||||
try {
|
||||
pfcFeatures_ptr features = assembly->ListFeaturesByType(xfalse, pfcFEATTYPE_COMPONENT);
|
||||
root_component.children_count = features ? features->getarraysize() : 0;
|
||||
} catch (...) {
|
||||
root_component.children_count = 0;
|
||||
}
|
||||
|
||||
result.hierarchy[0].push_back(root_component);
|
||||
result.success = true;
|
||||
result.message = "Total count analysis completed";
|
||||
return result;
|
||||
}
|
||||
|
||||
// 初始化结果(SOTA算法)
|
||||
result.project_name = request.project_name.empty() ?
|
||||
XStringToString(current_model->GetFileName()) : request.project_name;
|
||||
@ -1384,6 +1435,8 @@ pfcModel_ptr CreoManager::LoadComponentModel(pfcComponentFeat_ptr compFeat) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 层级删除功能实现
|
||||
CreoManager::HierarchyDeleteResult CreoManager::DeleteHierarchyComponents(const std::string& project_name, int target_level) {
|
||||
HierarchyDeleteResult result;
|
||||
|
||||
@ -465,7 +465,8 @@ private:
|
||||
pfcModel_ptr preloadedModel = nullptr);
|
||||
|
||||
pfcModel_ptr LoadComponentModel(pfcComponentFeat_ptr compFeat);
|
||||
|
||||
|
||||
|
||||
// 薄壳化分析递归方法
|
||||
void CollectAllComponentsForShellAnalysis(wfcWAssembly_ptr assembly,
|
||||
const std::string& parentPath,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user