CreoOtkPluging/PathDeleteManager.h
root 0e98285a74 实现路径删除功能并修复编译问题
## 新增功能
- 新增PathDeleteManager类,实现按路径批量删除装配体组件
- 支持绝对和相对路径格式的智能解析
- 采用按装配体分组的抑制策略,确保上下文正确匹配
- 完善的异常处理和错误原因追踪机制

## 修复的技术问题
- 解决路径删除"Unknown exception during suppression operation"错误
- 修复特征ID与owner_assembly上下文不匹配问题
- 转换文件为CRLF行尾符,解决Visual Studio编译错误
- 添加UTF-8 BOM确保编码一致性
- 移除C++11语法实现传统C++兼容性

## API端点
- POST /api/creo/path/delete - 路径组件删除接口

## 文件变更
- 新增: PathDeleteManager.h, PathDeleteManager.cpp
- 修改: MFCCreoDll.cpp (集成路径删除接口)
- 修改: 项目配置文件
- 更新: CLAUDE.md (技术文档)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-08 12:29:58 +08:00

114 lines
3.8 KiB
C++

#pragma once
#include <string>
#include <vector>
#include <map>
// 基础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 <wfcSolidInstructions.h>
#include <wfcAssembly.h>
#include <wfcFeatureInstructions.h>
#include <stdcols.h>
class PathDeleteManager {
public:
// 请求数据结构
struct PathDeleteRequest {
std::string software_type;
std::vector<std::string> component_paths; // 支持批量删除路径
bool force_delete = false; // 强制删除选项(暂时保留)
};
// 返回结果数据结构
struct PathDeleteResult {
bool success = false;
std::vector<std::string> successfully_deleted; // 成功删除的组件路径
std::vector<std::string> failed_to_delete; // 删除失败的组件路径
std::map<std::string, std::string> 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<std::string> 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<ComponentMatch>& 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<ComponentMatch>& 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;
};