主要特性: - 新接口 /api/analysis/hierarchy-statistics 统计每个层级的组件数量 - 层级0固定为1(根装配体),其他层级统计实际组件数量 - 自动移除值为0的空层级,优化返回数据 - 支持装配体和零件双模式,零件返回单层级结果 - 完善的异常处理和错误信息 技术实现: - 新增 HierarchyStatisticsAnalyzer 类处理层级统计逻辑 - 修改 CreoManager.h 暴露必要的公共接口 - 递归遍历装配体结构,正确统计各层级组件数量 - 所有注释改为英文,避免UTF-8编码冲突 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
47 lines
1.5 KiB
C++
47 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <map>
|
|
#include <vector>
|
|
#include <wfcAssembly.h>
|
|
|
|
// 层级统计请求结构
|
|
struct HierarchyStatisticsRequest {
|
|
std::string project_name; // 可选的项目名称,默认使用当前模型名
|
|
};
|
|
|
|
// 层级统计结果结构
|
|
struct HierarchyStatisticsResult {
|
|
bool success = false;
|
|
std::string message;
|
|
std::string model_name; // 当前模型名称
|
|
std::string model_type; // 模型类型 (assembly/part)
|
|
int total_levels = 0; // 总层级数
|
|
std::map<int, int> level_statistics; // key: 层级号, value: 该层级的直接子节点数量
|
|
std::string analysis_time; // 分析时间
|
|
std::string error_message;
|
|
};
|
|
|
|
// 层级统计分析器类
|
|
class HierarchyStatisticsAnalyzer {
|
|
public:
|
|
static HierarchyStatisticsAnalyzer& Instance();
|
|
|
|
// 执行层级统计分析
|
|
HierarchyStatisticsResult AnalyzeHierarchyStatistics(const HierarchyStatisticsRequest& request);
|
|
|
|
private:
|
|
HierarchyStatisticsAnalyzer() = default;
|
|
~HierarchyStatisticsAnalyzer() = default;
|
|
|
|
// 禁止拷贝
|
|
HierarchyStatisticsAnalyzer(const HierarchyStatisticsAnalyzer&) = delete;
|
|
HierarchyStatisticsAnalyzer& operator=(const HierarchyStatisticsAnalyzer&) = delete;
|
|
|
|
// 递归分析装配体层级
|
|
void AnalyzeAssemblyLevel(wfcWAssembly_ptr assembly, int level, std::map<int, int>& statistics, int& maxLevel);
|
|
|
|
// 获取当前时间字符串
|
|
std::string GetCurrentTimeString();
|
|
};
|