From 7de1e6726cbdb8e203e2a7bc5c5e6d36fdeb203a Mon Sep 17 00:00:00 2001 From: sladro Date: Fri, 19 Sep 2025 16:51:19 +0800 Subject: [PATCH] feat: implement complete component path return for shell-analysis API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 恢复BuildComponentFullPath函数,支持构建组件在装配体层级中的完整路径 - 在ShellAnalysisItem结构中添加path字段,存储组件完整路径信息 - 修改AnalyzeShellFeaturesEnhanced函数,在分析过程中获取和存储路径 - 更新API响应,partPath字段现在返回完整的层级路径(如"Assembly1/SubAssembly1/Part1") - 包含异常处理和fallback机制,确保路径获取失败时的稳定性 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- CreoManager.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++++++- CreoManager.h | 6 ++++- 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/CreoManager.cpp b/CreoManager.cpp index 83437ee..602f8ce 100644 --- a/CreoManager.cpp +++ b/CreoManager.cpp @@ -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 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) { try { if (str.empty()) { @@ -1615,6 +1665,22 @@ CreoManager::ShellAnalysisResult CreoManager::AnalyzeShellFeaturesEnhanced(const item.type = "COMPONENT"; 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 double visibilityRatio = 0.0; auto votesIter = visibilityVotes.find(item.feature_id); @@ -1722,7 +1788,7 @@ CreoManager::ShellAnalysisResult CreoManager::AnalyzeShellFeaturesEnhanced(const deletion.confidence = item.confidence; deletion.volume_reduction = 0.0; // Not calculated in projection analysis 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"; // Set vote count from projection analysis diff --git a/CreoManager.h b/CreoManager.h index 3be65ef..4c8a964 100644 --- a/CreoManager.h +++ b/CreoManager.h @@ -302,6 +302,7 @@ public: double confidence; std::string recommendation; std::string reason; + std::string path; // 组件完整路径 bool is_deletable = false; }; @@ -410,7 +411,10 @@ public: // 字符串转换辅助函数 std::string XStringToString(const xstring& xstr); - + + // 组件路径构建函数 + std::string BuildComponentFullPath(wfcWComponentPath_ptr componentPath, const std::string& assemblyName); + // 文件大小统计 std::string GetModelFileSize(pfcModel_ptr model); std::string CalculateAssemblyTotalSize(pfcModel_ptr model);