## 主要改进 - 新增动态超时机制:支持timeout_seconds参数(10-300秒) - 增强异常处理:细分OTK异常类型,提供具体错误信息 - 保持向后兼容:新参数可选,不影响现有API ## 技术细节 - ShrinkwrapManager.h: 添加timeout_seconds字段 - ShellExportHandler.cpp: 实现超时参数解析和验证 - MFCCreoDll.cpp: HTTP层支持动态超时控制 - ShrinkwrapManager.cpp: 细分pfcXToolkitError等异常类型 ## 解决问题 - 复杂模型处理超时导致的504错误 - 异常信息不明确难以定位问题 - 固定30秒超时限制了大模型处理能力 ## 文档和测试 - SHRINKWRAP_OPTIMIZATION.md: 完整使用说明 - test_timeout.py/bat: 自动化和手动测试工具 - 更新CLAUDE.md项目文档 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
160 lines
5.8 KiB
C++
160 lines
5.8 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 "pfcExceptions.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 ""
|
||
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;
|
||
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);
|
||
}; |