主要功能: - 新增Shrinkwrap外壳导出API (/api/creo/shrinkwrap/shell) - 使用OTK SurfaceSubsetInstructions实现真正的外壳导出 - 智能重名处理,自动生成唯一文件名 - 完全使用用户参数配置,无硬编码限制 性能优化: - 移除耗时的装配体分析和差异计算 - 简化文件保存逻辑,统一保存到工作目录 - 精简API响应格式,专注核心导出功能 - 大幅提升导出速度和系统稳定性 技术突破: - 解决Windows API宏冲突问题 (GetCurrentDirectory) - 实现SurfaceSubset vs MergedSolid性能差异优化 - 建立稳定的跨线程OTK操作机制 - 支持装配体和零件的统一外壳导出 文件变更: + ShrinkwrapManager.h/cpp - 核心Shrinkwrap功能实现 + ShellExportHandler.h/cpp - HTTP API处理逻辑 * MFCCreoDll.cpp - 集成新的消息处理和路由 * CLAUDE.md - 更新项目文档 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
158 lines
5.6 KiB
C++
158 lines
5.6 KiB
C++
#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 <string>
|
||
#include <vector>
|
||
#include <map>
|
||
#include <memory>
|
||
|
||
// 复用CreoManager的数据结构定义
|
||
struct FeatureDeletion {
|
||
int id;
|
||
std::string name;
|
||
std::string type;
|
||
std::string reason;
|
||
double confidence;
|
||
int volume_reduction;
|
||
std::string part_file;
|
||
std::string part_path;
|
||
std::string component_type = "COMPONENT";
|
||
};
|
||
|
||
struct EstimatedReduction {
|
||
std::string volume_reduction;
|
||
std::string file_size_reduction;
|
||
std::string performance_improvement;
|
||
};
|
||
|
||
// 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 ""
|
||
};
|
||
|
||
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;
|
||
int original_components_count;
|
||
int preserved_components_count;
|
||
int removed_components_count;
|
||
std::string preset_used;
|
||
};
|
||
|
||
struct ShrinkwrapComponentInfo {
|
||
std::string id;
|
||
std::string name;
|
||
std::string type;
|
||
std::string path;
|
||
std::string file_size;
|
||
double volume;
|
||
bool is_external; // 是否接触外表面
|
||
};
|
||
|
||
struct ShrinkwrapShellResult {
|
||
bool success = false;
|
||
std::vector<FeatureDeletion> safe_deletions; // 被移除的内部组件
|
||
std::vector<FeatureDeletion> suggested_deletions; // 建议删除的组件
|
||
std::vector<FeatureDeletion> preserve_list; // 保留的外表面组件
|
||
EstimatedReduction estimated_reduction;
|
||
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::vector<ShrinkwrapComponentInfo> AnalyzeAssemblyComponents(pfcModel_ptr model);
|
||
void CollectComponentsRecursively(wfcWAssembly_ptr assembly,
|
||
const std::string& parent_path,
|
||
std::vector<ShrinkwrapComponentInfo>& components);
|
||
ShrinkwrapComponentInfo CreateComponentInfo(pfcComponentFeat_ptr comp_feat,
|
||
const std::string& path);
|
||
|
||
// 差异分析方法
|
||
void AnalyzeShrinkwrapDifferences(const std::vector<ShrinkwrapComponentInfo>& original_components,
|
||
pfcModel_ptr shrinkwrap_model,
|
||
ShrinkwrapShellResult& result);
|
||
|
||
// OTK Shrinkwrap执行方法
|
||
pfcModel_ptr ExecuteOTKShrinkwrap(pfcModel_ptr source_model,
|
||
const ShrinkwrapShellRequest& request);
|
||
|
||
// 结果格式化方法
|
||
void FormatShrinkwrapResults(const std::vector<ShrinkwrapComponentInfo>& original_components,
|
||
const std::vector<ShrinkwrapComponentInfo>& preserved_components,
|
||
const ShrinkwrapShellRequest& request,
|
||
ShrinkwrapShellResult& result);
|
||
|
||
// 质量属性计算
|
||
double CalculateModelVolume(pfcModel_ptr model);
|
||
EstimatedReduction CalculateReductionEstimates(const std::vector<ShrinkwrapComponentInfo>& original,
|
||
const std::vector<ShrinkwrapComponentInfo>& preserved);
|
||
|
||
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);
|
||
}; |