核心改动: - 在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>
250 lines
9.3 KiB
C++
250 lines
9.3 KiB
C++
#pragma once
|
||
|
||
// 基础OTK头文件 - 确保正确的包含顺序
|
||
#include <pfcGlobal.h>
|
||
#include <pfcSession.h>
|
||
#include <wfcSession.h>
|
||
#include <wfcGlobal.h>
|
||
#include <pfcModel.h>
|
||
#include <pfcExceptions.h>
|
||
#include <pfcFeature.h>
|
||
#include <pfcComponentFeat.h>
|
||
#include <pfcFeature_s.h>
|
||
#include <pfcSolid.h>
|
||
#include <wfcSolid.h>
|
||
#include <pfcGeometry.h>
|
||
#include <string>
|
||
#include <vector>
|
||
#include <map>
|
||
#include <set>
|
||
#include <algorithm>
|
||
#include <cmath>
|
||
#include <ctime>
|
||
#include <chrono>
|
||
#include <cstdint>
|
||
|
||
// 几何复杂度信息结构
|
||
struct GeometryComplexityInfo {
|
||
std::string part_name; // 零件名称
|
||
std::string part_path; // 零件路径
|
||
std::string file_size; // 文件大小
|
||
double complexity_score; // 总体复杂度评分 (0-100)
|
||
std::string complexity_level; // 复杂度等级 ("Low", "Medium", "High", "Very High")
|
||
|
||
// 多维复杂度分类评估
|
||
double geometric_complexity; // 几何复杂度 (0-100) - 拓扑、曲面复杂度
|
||
double manufacturing_complexity; // 制造复杂度 (0-100) - 加工工艺难度
|
||
double assembly_complexity; // 装配复杂度 (0-100) - 约束和层级关系
|
||
double analysis_complexity; // 分析复杂度 (0-100) - 计算负载
|
||
|
||
// 详细复杂度指标
|
||
int feature_count; // 特征数量
|
||
int surface_count; // 表面数量
|
||
int curved_surface_count; // 曲面数量
|
||
int hole_count; // 孔数量
|
||
int fillet_count; // 圆角数量
|
||
int pattern_count; // 阵列数量
|
||
int sketch_count; // 草图数量
|
||
|
||
// 扩展特征类型 - 高复杂度特征
|
||
int chamfer_count; // 倒角数量
|
||
int shell_count; // 壳体数量
|
||
int draft_count; // 拔模数量
|
||
int cut_count; // 切除特征数量
|
||
int protrusion_count; // 凸台特征数量
|
||
|
||
// 几何数据
|
||
double volume; // 体积
|
||
double surface_area; // 表面积
|
||
double bounding_box_volume; // 包络盒体积
|
||
|
||
// 复杂度影响因素
|
||
std::vector<std::string> complexity_factors;
|
||
|
||
// 构造函数
|
||
GeometryComplexityInfo() :
|
||
complexity_score(0.0),
|
||
geometric_complexity(0.0),
|
||
manufacturing_complexity(0.0),
|
||
assembly_complexity(0.0),
|
||
analysis_complexity(0.0),
|
||
feature_count(0),
|
||
surface_count(0),
|
||
curved_surface_count(0),
|
||
hole_count(0),
|
||
fillet_count(0),
|
||
pattern_count(0),
|
||
sketch_count(0),
|
||
chamfer_count(0),
|
||
shell_count(0),
|
||
draft_count(0),
|
||
cut_count(0),
|
||
protrusion_count(0),
|
||
volume(0.0),
|
||
surface_area(0.0),
|
||
bounding_box_volume(0.0)
|
||
{
|
||
}
|
||
};
|
||
|
||
// 几何复杂度分析请求结构
|
||
struct GeometryComplexityRequest {
|
||
std::string software_type; // 软件类型 "creo"
|
||
std::string project_name; // 项目名称
|
||
int max_results; // 最大返回结果数(默认20)
|
||
bool include_details; // 是否包含详细信息
|
||
std::string sort_order; // 排序方式 "desc" 或 "asc"
|
||
double complexity_threshold; // 复杂度阈值过滤
|
||
|
||
// 多目标排序参数
|
||
std::string sort_strategy; // 排序策略: "overall", "geometric", "manufacturing", "pareto"
|
||
double geometric_weight; // 几何复杂度权重 (0.0-1.0)
|
||
double manufacturing_weight; // 制造复杂度权重 (0.0-1.0)
|
||
double assembly_weight; // 装配复杂度权重 (0.0-1.0)
|
||
double analysis_weight; // 分析复杂度权重 (0.0-1.0)
|
||
|
||
// 构造函数设置默认值
|
||
GeometryComplexityRequest() :
|
||
max_results(20),
|
||
include_details(true),
|
||
sort_order("desc"),
|
||
complexity_threshold(0.0),
|
||
sort_strategy("overall"),
|
||
geometric_weight(0.3),
|
||
manufacturing_weight(0.4),
|
||
assembly_weight(0.2),
|
||
analysis_weight(0.1)
|
||
{
|
||
}
|
||
};
|
||
|
||
// 几何复杂度分析结果结构
|
||
struct GeometryComplexityResult {
|
||
bool success = false;
|
||
std::string message;
|
||
std::vector<GeometryComplexityInfo> parts; // 按复杂度排序的零件
|
||
int total_parts_analyzed; // 总分析零件数
|
||
std::string analysis_time; // 分析时间
|
||
std::string error_message;
|
||
|
||
// 统计信息
|
||
double average_complexity; // 平均复杂度
|
||
double max_complexity; // 最高复杂度
|
||
double min_complexity; // 最低复杂度
|
||
|
||
GeometryComplexityResult() :
|
||
total_parts_analyzed(0),
|
||
average_complexity(0.0),
|
||
max_complexity(0.0),
|
||
min_complexity(0.0)
|
||
{
|
||
}
|
||
};
|
||
|
||
// 几何复杂度分析器类
|
||
class GeometryAnalyzer {
|
||
public:
|
||
// 获取单例实例
|
||
static GeometryAnalyzer& Instance();
|
||
|
||
// 主要分析方法
|
||
GeometryComplexityResult AnalyzeGeometryComplexity(const GeometryComplexityRequest& request);
|
||
|
||
// 辅助方法
|
||
std::string GetCurrentTimeString();
|
||
std::string GetCurrentTimeStringISO();
|
||
|
||
private:
|
||
GeometryAnalyzer();
|
||
~GeometryAnalyzer() = default;
|
||
GeometryAnalyzer(const GeometryAnalyzer&) = delete;
|
||
GeometryAnalyzer& operator=(const GeometryAnalyzer&) = delete;
|
||
|
||
// 核心分析方法
|
||
GeometryComplexityInfo AnalyzePart(pfcModel_ptr model, const std::string& part_path);
|
||
|
||
// 复杂度计算方法
|
||
double CalculateComplexityScore(const GeometryComplexityInfo& info);
|
||
std::string DetermineComplexityLevel(double score);
|
||
std::vector<std::string> AnalyzeComplexityFactors(const GeometryComplexityInfo& info);
|
||
|
||
// 多维复杂度计算方法
|
||
double CalculateGeometricComplexity(const GeometryComplexityInfo& info);
|
||
double CalculateManufacturingComplexity(const GeometryComplexityInfo& info);
|
||
double CalculateAssemblyComplexity(const GeometryComplexityInfo& info);
|
||
double CalculateAnalysisComplexity(const GeometryComplexityInfo& info);
|
||
|
||
// 非线性评分函数
|
||
double SaturationFunction(double value, double max_value, double steepness = 1.0);
|
||
double FeatureInteractionWeight(const GeometryComplexityInfo& info);
|
||
|
||
// 上下文感知算法
|
||
double CalculateScaleNormalizationFactor(const GeometryComplexityInfo& info);
|
||
double CalculateRelativeImportanceWeight(const GeometryComplexityInfo& info);
|
||
void ApplyContextualAdjustments(GeometryComplexityInfo& info);
|
||
|
||
// 多目标排序算法
|
||
void MultiObjectiveSort(std::vector<GeometryComplexityInfo>& parts, const GeometryComplexityRequest& request);
|
||
double CalculateWeightedComplexityScore(const GeometryComplexityInfo& info, const GeometryComplexityRequest& request);
|
||
bool DominatesInPareto(const GeometryComplexityInfo& a, const GeometryComplexityInfo& b);
|
||
|
||
// 特征分析方法
|
||
int CountAllFeatures(pfcModel_ptr model);
|
||
int CountHoles(pfcModel_ptr model);
|
||
int CountFillets(pfcModel_ptr model);
|
||
int CountPatterns(pfcModel_ptr model);
|
||
int CountSketches(pfcModel_ptr model);
|
||
|
||
// 新增特征类型计数方法
|
||
int CountChamfers(pfcModel_ptr model);
|
||
int CountShellFeatures(pfcModel_ptr model);
|
||
int CountDraftFeatures(pfcModel_ptr model);
|
||
int CountCutFeatures(pfcModel_ptr model);
|
||
int CountProtrusionFeatures(pfcModel_ptr model);
|
||
|
||
// 几何计算方法
|
||
double CalculateVolume(pfcModel_ptr model);
|
||
double CalculateSurfaceArea(pfcModel_ptr model);
|
||
double CalculateBoundingBoxVolume(pfcModel_ptr model);
|
||
int CountSurfaces(pfcModel_ptr model);
|
||
int CountCurvedSurfaces(pfcModel_ptr model);
|
||
|
||
// 装配体遍历方法
|
||
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::set<std::string>& processed_parts);
|
||
|
||
// 工具方法
|
||
std::string GetModelFileSize(pfcModel_ptr model);
|
||
bool IsValidPart(pfcModel_ptr model);
|
||
std::string XStringToString(const xstring& xstr);
|
||
|
||
// 缓存管理方法
|
||
std::string GenerateCacheKey(pfcModel_ptr model);
|
||
bool IsCacheValid(const std::string& cache_key, pfcModel_ptr model);
|
||
void ClearExpiredCache();
|
||
|
||
// 缓存管理结构
|
||
struct CacheEntry {
|
||
GeometryComplexityInfo complexity_info;
|
||
std::time_t timestamp;
|
||
std::string model_modification_time;
|
||
|
||
CacheEntry() : timestamp(0) {}
|
||
};
|
||
|
||
// 缓存存储 - 使用模型路径作为键
|
||
std::map<std::string, CacheEntry> complexity_cache;
|
||
static const int CACHE_EXPIRY_SECONDS = 300; // 5分钟缓存过期
|
||
|
||
// 会话管理
|
||
struct SessionInfo {
|
||
pfcSession_ptr session;
|
||
wfcWSession_ptr wSession;
|
||
bool is_valid;
|
||
};
|
||
SessionInfo GetSessionInfo();
|
||
};
|