#pragma once // 基础OTK头文件 - 确保正确的包含顺序 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // Creo状态信息结构 struct CreoStatus { bool is_connected = false; std::string version; std::string build; std::string working_directory; int session_id = 0; }; // 模型状态信息结构 struct ModelStatus { bool has_model = false; std::string name; std::string filename; std::string type; std::string software; // 从OTK API获取,不设默认值 std::string version; // 从OTK API获取,不设默认值 std::string connection_time; bool is_assembly = false; int total_parts = 0; int assembly_levels = 0; std::string file_size; std::string connection_status; std::string open_time; }; // 导出结果结构 struct ExportResult { bool success = false; std::string export_path; std::string file_size; std::string format; std::string export_time; std::string software; std::string original_file; std::string dirname; std::string filename; std::string error_message; }; // 层级分析组件信息结构 struct ComponentInfo { std::string id; std::string name; std::string type; // "assembly" 或 "part" int level; int children_count; std::string path; std::string file_size; std::string deletion_safety; // "forbidden", "risky", "moderate" bool is_visible; std::string model_type; // "MDL_ASSEMBLY", "MDL_PART", "MDL_DRAWING" 等 std::string full_path; // 完整的组件路径 }; // 层级分析请求结构 struct HierarchyAnalysisRequest { std::string software_type; std::string project_name; int max_depth; bool include_geometry; std::map analysis_options; }; // 删除建议结构 struct DeletionRecommendation { std::string component_id; std::string component_name; int level; std::string reason; std::vector risk_factors; double confidence; }; // 层级分析结果结构 struct HierarchyAnalysisResult { bool success = false; std::string message; std::string project_name; int total_levels; int total_components; std::vector> hierarchy; std::vector safe_deletions; std::vector risky_deletions; std::string error_message; }; // Creo管理器类 class CreoManager { public: static CreoManager& Instance(); // 状态检测 CreoStatus GetCreoStatus(); ModelStatus GetModelStatus(); // 基础操作 bool ShowMessage(const std::string& message); // 导出功能 ExportResult ExportModelToSTEP(const std::string& export_path, const std::string& geom_flags = "solids"); // 层级分析功能 HierarchyAnalysisResult AnalyzeModelHierarchy(const HierarchyAnalysisRequest& request); // 层级删除功能 struct HierarchyDeleteResult { bool success = false; std::string message; int original_levels; int target_level; int final_levels; std::map> deleted_components; int total_deleted; int successful; int failed; std::string error_message; }; HierarchyDeleteResult DeleteHierarchyComponents(const std::string& project_name, int target_level); // 辅助功能 std::string GetCurrentTimeString(); std::string GetCurrentTimeStringISO(); std::string GetFileSize(const std::string& filepath); int SafeCalculateAssemblyLevels(wfcWAssembly_ptr assembly); // 文件大小统计 std::string GetModelFileSize(pfcModel_ptr model); std::string CalculateAssemblyTotalSize(pfcModel_ptr model); double ParseMBFromSizeString(const std::string& size_str); private: CreoManager(); // 需要自定义构造函数来设置配置 ~CreoManager() = default; CreoManager(const CreoManager&) = delete; CreoManager& operator=(const CreoManager&) = delete; // 辅助函数 std::string XStringToString(const xstring& xstr); xstring StringToXString(const std::string& str); // 层级分析私有方法 (新SOTA算法) void AnalyzeAssemblyNode(wfcWAssembly_ptr assembly, int level, const std::string& parentName, const std::string& currentPath, HierarchyAnalysisResult& result); ComponentInfo CreateComponentFromFeature(pfcComponentFeat_ptr compFeat, int level, const std::string& parentName, const std::string& currentPath, pfcModel_ptr preloadedModel = nullptr); pfcModel_ptr LoadComponentModel(pfcComponentFeat_ptr compFeat); // 旧方法 (保留用于兼容) void TraverseAssemblyLevels(wfcWAssembly_ptr assembly, int current_level, const std::string& parent_path, std::vector>& hierarchy_levels, std::vector& all_components); void ClearStaticVisitedModels(); ComponentInfo CreateComponentInfo(wfcWComponentPath_ptr component_path, int level, const std::string& parent_path); // 新增CREOSON风格的安全方法 ComponentInfo CreateComponentInfoSafe(wfcWComponentPath_ptr component_path, int level, const std::string& parent_path); bool CheckCanRecurseSafely(wfcWComponentPath_ptr component_path); wfcWAssembly_ptr GetSubAssemblySafely(wfcWComponentPath_ptr component_path); std::string GetComponentTypeSafe(wfcWComponentPath_ptr component_path); std::string GenerateComponentPathId(wfcWComponentPath_ptr component_path); std::string EvaluateDeletionSafety(const ComponentInfo& component); std::string GetComponentFileSize(wfcWComponentPath_ptr component_path); std::string GetModelTypeString(pfcModelType model_type); int CountChildComponents(wfcWComponentPath_ptr component_path); // 会话管理(避免重复代码) struct SessionInfo { pfcSession_ptr session; wfcWSession_ptr wSession; bool is_valid; std::string version; std::string build; }; SessionInfo GetSessionInfo(); };