CreoOtkPluging/ShrinkwrapManager.h
sladro 83cf963b9d feat: add automatic file renaming for shrinkwrap exports to avoid overwrites
- Add FileExists() function to check if file already exists in filesystem
- Add GenerateUniqueFilePath() function to generate unique file names with _1, _2, etc. suffixes
- Modify ExecuteOTKShrinkwrap() to check for existing files before saving
- Rename Creo model internally if file name needs to be changed
- Use timestamp as fallback when maximum attempts (999) are exhausted
- Ensure proper .prt extension handling

This prevents accidental overwriting of existing shrinkwrap export files by automatically appending incremental suffixes to duplicate file names.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-20 12:55:01 +08:00

111 lines
3.7 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";
int quality = 8; // 1-10, 质量等级
double chord_height = 0.1; // 弦高控制三角化误差(mm), 0.05-0.2
bool fill_holes = true; // 自动填孔
bool ignore_small_surfaces = true; // 忽略小表面
double small_surface_percentage = 0.5; // 小表面百分比阈值
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 = 30; // 超时时间(秒), 默认30秒最大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);
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);
};