CreoOtkPluging/ShrinkwrapManager.h
2026-01-04 15:51:54 +08:00

115 lines
4.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include "pfcGlobal.h"
#include "pfcSession.h"
#include "pfcModel.h"
#include "pfcSolid.h"
#include "pfcShrinkwrap.h"
#include "pfcAssembly.h"
#include "wfcAssembly.h"
#include "wfcSession.h"
#include "xstring.h"
#include "pfcExceptions.h"
#include <string>
#include <vector>
#include <map>
#include <memory>
// Simplified data structures for Shrinkwrap
// Shrinkwrap特定的数据结构
struct ShrinkwrapShellRequest {
std::string software_type = "creo";
std::string project_name = "Shrinkwrap Shell Export";
std::string method = "outer_shell";
std::string component_path = ""; // 可选:子装配体路径,如 "TopAsm.asm/SubAsm.asm",为空则使用当前模型
int quality = 5; // 1-10, 质量等级(降低默认值避免大模型卡死)
double chord_height = 0.1; // 弦高控制三角化误差(mm), 0.05-0.2
bool fill_holes = false; // 自动填孔(关闭以提高稳定性)
bool ignore_small_surfaces = false; // 忽略小表面(关闭避免卡死)
double small_surface_percentage = 0.0; // 小表面百分比阈值设为0不过滤
std::string output_file_path; // 输出文件路径
std::string output_type = "solid_surface"; // "solid_surface" or "facet"
bool ignore_quilts = true; // 忽略面片
bool ignore_skeleton = true; // 忽略骨架
bool assign_mass_properties = false; // 分配质量属性
std::string preset = ""; // "fast", "balanced", "tight" or ""
int timeout_seconds = 60; // 超时时间(秒), 默认60秒最大300秒
};
struct ShrinkwrapShellParameters {
std::string method;
int quality;
double chord_height;
bool fill_holes;
bool ignore_small_surfaces;
double small_surface_percentage;
std::string output_type;
bool ignore_quilts;
bool ignore_skeleton;
bool assign_mass_properties;
std::string output_file_path;
std::string output_file_size;
std::string shrinkwrap_time;
std::string preset_used;
};
struct ShrinkwrapShellResult {
bool success = false;
ShrinkwrapShellParameters parameters;
std::string message;
std::string error_message;
};
// 会话信息结构复用CreoManager的设计模式
struct SessionInfo {
pfcSession_ptr session;
wfcWSession_ptr wSession;
bool is_valid;
std::string version;
std::string build;
};
class ShrinkwrapManager {
private:
static ShrinkwrapManager* instance;
ShrinkwrapManager() = default;
// 核心辅助方法
SessionInfo GetSessionInfo();
std::string StringToStdString(const xstring& xstr);
xstring StringToXString(const std::string& str);
std::string GetCurrentTimeString();
std::string CalculateFileSize(const std::string& file_path);
std::string GenerateSafePartName(pfcModel_ptr source_model);
// OTK Shrinkwrap执行方法
pfcModel_ptr ExecuteOTKShrinkwrap(pfcModel_ptr source_model,
const ShrinkwrapShellRequest& request);
// 质量属性计算
double CalculateModelVolume(pfcModel_ptr model);
// File system operations
bool FileExists(const std::string& filepath);
std::string GenerateUniqueFilePath(const std::string& base_path, const std::string& file_name);
// Component path parsing and finding
pfcModel_ptr FindComponentByPath(wfcWAssembly_ptr assembly, const std::string& component_path, const SessionInfo& session_info);
public:
// 单例模式
static ShrinkwrapManager& Instance();
// 主要功能接口
ShrinkwrapShellResult ExecuteShrinkwrapShell(const ShrinkwrapShellRequest& request);
// 验证和辅助接口
bool ValidateRequest(const ShrinkwrapShellRequest& request, std::string& error_message);
std::string GetSupportedFormats();
bool IsCreoSessionAvailable();
// 预设参数处理
void ApplyPresetParameters(ShrinkwrapShellRequest& request);
};