#pragma once #include #include #include // 基础OTK头文件 - 确保正确的包含顺序 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include class PathDeleteManager { public: // 请求数据结构 struct PathDeleteRequest { std::string software_type; std::vector component_paths; // 支持批量删除路径 bool force_delete = false; // 强制删除选项(暂时保留) }; // 返回结果数据结构 struct PathDeleteResult { bool success = false; std::vector successfully_deleted; // 成功删除的组件路径 std::vector failed_to_delete; // 删除失败的组件路径 std::map deletion_reasons; // 每个路径的删除结果原因 std::string error_message; // 整体错误信息 // 统计信息 int total_requested = 0; int successful = 0; int failed = 0; }; // 组件匹配结果 struct ComponentMatch { pfcFeature_ptr feature; std::string actual_path; bool found = false; wfcWAssembly_ptr owner_assembly; // 记录组件所属的装配体 }; private: // 路径解析结构 struct ParsedPath { std::vector path_segments; // 路径分段:["ASM0001.asm", "SubAsm.asm", "Part.prt"] std::string target_component; // 目标组件名:"Part.prt" bool is_valid = false; }; private: // 路径解析方法 ParsedPath ParseComponentPath(const std::string& full_path); // 递归查找组件方法 bool FindComponentByPath(wfcWAssembly_ptr assembly, const ParsedPath& target_path, const std::string& current_path, int target_depth, int current_depth, std::vector& matches); // 获取会话信息 struct SessionInfo { pfcSession_ptr session; bool is_valid = false; }; SessionInfo GetSessionInfo(); // 字符串工具方法 std::string XStringToString(const xstring& xstr); xstring StringToXString(const std::string& str); // 模型加载方法(复用现有逻辑) pfcModel_ptr LoadComponentModel(pfcComponentFeat_ptr compFeat); // 递归搜索组件的辅助方法 bool RecursiveSearchComponent(wfcWAssembly_ptr currentAssembly, const ParsedPath& target_path, const std::string& pathSoFar, int currentLevel, std::vector& matches); // 大小写不敏感的字符串比较 bool CaseInsensitiveCompare(const std::string& str1, const std::string& str2); public: // 主要接口方法:按路径批量删除组件 PathDeleteResult DeleteComponentsByPaths(const PathDeleteRequest& request); // 单例模式 static PathDeleteManager& Instance() { static PathDeleteManager instance; return instance; } private: // 私有构造函数(单例模式) PathDeleteManager() = default; PathDeleteManager(const PathDeleteManager&) = delete; PathDeleteManager& operator=(const PathDeleteManager&) = delete; };