feat: implement complete component path return for shell-analysis API
- 恢复BuildComponentFullPath函数,支持构建组件在装配体层级中的完整路径 - 在ShellAnalysisItem结构中添加path字段,存储组件完整路径信息 - 修改AnalyzeShellFeaturesEnhanced函数,在分析过程中获取和存储路径 - 更新API响应,partPath字段现在返回完整的层级路径(如"Assembly1/SubAssembly1/Part1") - 包含异常处理和fallback机制,确保路径获取失败时的稳定性 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
99c6d17795
commit
7de1e6726c
@ -282,6 +282,56 @@ std::string CreoManager::XStringToString(const xstring& xstr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CreoManager::BuildComponentFullPath(wfcWComponentPath_ptr componentPath, const std::string& assemblyName) {
|
||||||
|
if (!componentPath) return "";
|
||||||
|
|
||||||
|
std::vector<std::string> pathComponents;
|
||||||
|
|
||||||
|
// 添加根装配体名称
|
||||||
|
if (!assemblyName.empty()) {
|
||||||
|
pathComponents.push_back(assemblyName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取路径中的组件ID序列
|
||||||
|
xintsequence_ptr componentIds = componentPath->GetComponentIds();
|
||||||
|
pfcAssembly_ptr rootAsm = componentPath->GetRoot();
|
||||||
|
|
||||||
|
// 遍历每个组件ID,获取对应的名称
|
||||||
|
pfcAssembly_ptr currentAsm = rootAsm;
|
||||||
|
|
||||||
|
for (int i = 0; i < componentIds->getarraysize(); i++) {
|
||||||
|
int compId = componentIds->get(i);
|
||||||
|
|
||||||
|
// 从当前装配体获取组件特征
|
||||||
|
pfcFeature_ptr feat = currentAsm->GetFeatureById(compId);
|
||||||
|
pfcComponentFeat_ptr compFeat = pfcComponentFeat::cast(feat);
|
||||||
|
|
||||||
|
// 获取组件名称
|
||||||
|
pfcModelDescriptor_ptr modelDesc = compFeat->GetModelDescr();
|
||||||
|
xstring nameXStr = modelDesc->GetFileName();
|
||||||
|
std::string compName = XStringToString(nameXStr);
|
||||||
|
pathComponents.push_back(compName);
|
||||||
|
|
||||||
|
// 如果是子装配体,进入下一层
|
||||||
|
if (i < componentIds->getarraysize() - 1) {
|
||||||
|
SessionInfo sessionInfo = GetSessionInfo();
|
||||||
|
pfcModel_ptr nextModel = sessionInfo.session->GetModelFromDescr(modelDesc);
|
||||||
|
if (nextModel->GetType() == pfcMDL_ASSEMBLY) {
|
||||||
|
currentAsm = pfcAssembly::cast(nextModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 连接路径
|
||||||
|
std::string fullPath;
|
||||||
|
for (size_t i = 0; i < pathComponents.size(); i++) {
|
||||||
|
if (i > 0) fullPath += "/";
|
||||||
|
fullPath += pathComponents[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return fullPath;
|
||||||
|
}
|
||||||
|
|
||||||
xstring CreoManager::StringToXString(const std::string& str) {
|
xstring CreoManager::StringToXString(const std::string& str) {
|
||||||
try {
|
try {
|
||||||
if (str.empty()) {
|
if (str.empty()) {
|
||||||
@ -1615,6 +1665,22 @@ CreoManager::ShellAnalysisResult CreoManager::AnalyzeShellFeaturesEnhanced(const
|
|||||||
item.type = "COMPONENT";
|
item.type = "COMPONENT";
|
||||||
item.feature_id = stableFeatureId; // Use stable feature ID
|
item.feature_id = stableFeatureId; // Use stable feature ID
|
||||||
|
|
||||||
|
// Build full path including assembly hierarchy
|
||||||
|
try {
|
||||||
|
pfcModel_ptr currentModel = sessionInfo.session->GetCurrentModel();
|
||||||
|
std::string assemblyName = "";
|
||||||
|
if (currentModel) {
|
||||||
|
xstring assemblyXStr = currentModel->GetFileName();
|
||||||
|
assemblyName = XStringToString(assemblyXStr);
|
||||||
|
}
|
||||||
|
item.path = BuildComponentFullPath(wPath, assemblyName);
|
||||||
|
if (item.path.empty()) {
|
||||||
|
item.path = comp_name; // Fallback to component name
|
||||||
|
}
|
||||||
|
} catch (...) {
|
||||||
|
item.path = comp_name; // Fallback on error
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate visibility ratio for this component
|
// Calculate visibility ratio for this component
|
||||||
double visibilityRatio = 0.0;
|
double visibilityRatio = 0.0;
|
||||||
auto votesIter = visibilityVotes.find(item.feature_id);
|
auto votesIter = visibilityVotes.find(item.feature_id);
|
||||||
@ -1722,7 +1788,7 @@ CreoManager::ShellAnalysisResult CreoManager::AnalyzeShellFeaturesEnhanced(const
|
|||||||
deletion.confidence = item.confidence;
|
deletion.confidence = item.confidence;
|
||||||
deletion.volume_reduction = 0.0; // Not calculated in projection analysis
|
deletion.volume_reduction = 0.0; // Not calculated in projection analysis
|
||||||
deletion.part_file = ""; // Component name is already in 'name'
|
deletion.part_file = ""; // Component name is already in 'name'
|
||||||
deletion.part_path = ""; // Not available in current analysis
|
deletion.part_path = item.path; // Use full component path
|
||||||
deletion.component_type = "COMPONENT";
|
deletion.component_type = "COMPONENT";
|
||||||
|
|
||||||
// Set vote count from projection analysis
|
// Set vote count from projection analysis
|
||||||
|
|||||||
@ -302,6 +302,7 @@ public:
|
|||||||
double confidence;
|
double confidence;
|
||||||
std::string recommendation;
|
std::string recommendation;
|
||||||
std::string reason;
|
std::string reason;
|
||||||
|
std::string path; // 组件完整路径
|
||||||
bool is_deletable = false;
|
bool is_deletable = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -410,7 +411,10 @@ public:
|
|||||||
|
|
||||||
// 字符串转换辅助函数
|
// 字符串转换辅助函数
|
||||||
std::string XStringToString(const xstring& xstr);
|
std::string XStringToString(const xstring& xstr);
|
||||||
|
|
||||||
|
// 组件路径构建函数
|
||||||
|
std::string BuildComponentFullPath(wfcWComponentPath_ptr componentPath, const std::string& assemblyName);
|
||||||
|
|
||||||
// 文件大小统计
|
// 文件大小统计
|
||||||
std::string GetModelFileSize(pfcModel_ptr model);
|
std::string GetModelFileSize(pfcModel_ptr model);
|
||||||
std::string CalculateAssemblyTotalSize(pfcModel_ptr model);
|
std::string CalculateAssemblyTotalSize(pfcModel_ptr model);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user