优化几何算法

This commit is contained in:
sladro 2026-01-04 15:51:54 +08:00
parent 20467b2c72
commit 16f414e2a7
32 changed files with 35 additions and 20 deletions

View File

@ -31,13 +31,14 @@ static UINT_PTR timer_id = 0;
// 无锁消息队列项
struct MessageItem {
std::string type; // "SHOW_MESSAGE", "OPEN_MODEL_REQUEST", "SHRINKWRAP_SHELL_REQUEST"
std::string type; // "SHOW_MESSAGE", "OPEN_MODEL_REQUEST", "SHRINKWRAP_SHELL_REQUEST", 或 "TIMEOUT_CLEANUP"
std::string data; // 消息内容或文件路径或JSON数据
std::string extra; // 额外参数如open_mode
volatile bool completed; // 完成标志
volatile bool timed_out; // 超时标志用于指示HTTP请求已超时返回
void* result_ptr; // 结果指针
MessageItem() : completed(false), result_ptr(nullptr) {}
MessageItem() : completed(false), timed_out(false), result_ptr(nullptr) {}
};
// 无锁同步机制
@ -123,6 +124,15 @@ VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
// 执行Shrinkwrap处理
HttpResponse response = ShellExportHandler::HandleShrinkwrapShellRequest(shrinkwrap_request);
// 检查是否已超时,若超时则清理内存并跳过
if (item->timed_out) {
// HTTP请求已超时返回清理堆分配的MessageItem
delete item;
pending_message_item = nullptr;
has_pending_item = false;
return; // 直接返回不设置completed
}
// 保存结果
item->result_ptr = new HttpResponse(response);
item->completed = true;
@ -1624,7 +1634,7 @@ HttpResponse ShrinkwrapShellHandler(const HttpRequest& request) {
try {
// 解析请求获取超时参数
int timeout_seconds = 30; // 默认值
int timeout_seconds = 60; // 默认值改为60秒
try {
// 简单解析JSON获取timeout_seconds
std::string json_body = request.body;
@ -1639,33 +1649,37 @@ HttpResponse ShrinkwrapShellHandler(const HttpRequest& request) {
}
} catch (...) {
// 解析失败,使用默认值
timeout_seconds = 30;
timeout_seconds = 60;
}
// 使用无锁消息机制
MessageItem shrinkwrap_message_item;
shrinkwrap_message_item.type = "SHRINKWRAP_SHELL_REQUEST";
shrinkwrap_message_item.data = request.body;
// 使用堆分配的MessageItem避免超时后悬空指针问题
MessageItem* shrinkwrap_message_item = new MessageItem();
shrinkwrap_message_item->type = "SHRINKWRAP_SHELL_REQUEST";
shrinkwrap_message_item->data = request.body;
// 原子设置(无锁)
pending_message_item = &shrinkwrap_message_item;
pending_message_item = shrinkwrap_message_item;
has_pending_item = true;
// 等待主线程完成操作(带动态超时)
int timeout_ms = timeout_seconds * 1000; // 转换为毫秒
while (!shrinkwrap_message_item.completed && timeout_ms > 0) {
while (!shrinkwrap_message_item->completed && timeout_ms > 0) {
Sleep(100); // 稍长的间隔因为Shrinkwrap是重操作
timeout_ms -= 100;
}
if (shrinkwrap_message_item.completed && shrinkwrap_message_item.result_ptr) {
HttpResponse result = *static_cast<HttpResponse*>(shrinkwrap_message_item.result_ptr);
delete static_cast<HttpResponse*>(shrinkwrap_message_item.result_ptr); // 清理内存
if (shrinkwrap_message_item->completed && shrinkwrap_message_item->result_ptr) {
// 操作成功完成
HttpResponse result = *static_cast<HttpResponse*>(shrinkwrap_message_item->result_ptr);
delete static_cast<HttpResponse*>(shrinkwrap_message_item->result_ptr); // 清理结果内存
delete shrinkwrap_message_item; // 清理MessageItem内存
return result;
} else {
// 超时处理
// 超时处理标记为已超时让TimerProc负责清理
shrinkwrap_message_item->timed_out = true;
response.status_code = 504;
response.body = "{\"success\": false, \"error\": \"Operation timeout: Shrinkwrap export exceeded " + std::to_string(timeout_seconds) + " seconds limit\"}";
response.body = "{\"success\": false, \"error\": \"Operation timeout: Shrinkwrap export exceeded "
+ std::to_string(timeout_seconds) + " seconds limit\", \"note\": \"The Creo operation may still complete in background. Check Creo for results.\"}";
return response;
}

View File

@ -96,6 +96,7 @@
<PreprocessorDefinitions>_WINDOWS;_USRDLL;USE_ANSI_IOSTREAMS;PRO_USE_VAR_ARGS;PRO_MACHINE=36;HYCOMMONWINAPI_EXPORTS;_WIN32_WINNT=0x0601;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -23,18 +23,18 @@ struct ShrinkwrapShellRequest {
std::string project_name = "Shrinkwrap Shell Export";
std::string method = "outer_shell";
std::string component_path = ""; // 可选:子装配体路径,如 "TopAsm.asm/SubAsm.asm",为空则使用当前模型
int quality = 8; // 1-10, 质量等级
int quality = 5; // 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; // 小表面百分比阈值
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 = 30; // 超时时间(秒), 默认30秒最大300秒
int timeout_seconds = 60; // 超时时间(秒), 默认60秒最大300秒
};
struct ShrinkwrapShellParameters {

Binary file not shown.

Binary file not shown.