优化几何算法
This commit is contained in:
parent
16f414e2a7
commit
6072faa67f
@ -127,13 +127,14 @@ VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
|
||||
// 检查是否已超时,若超时则清理内存并跳过
|
||||
if (item->timed_out) {
|
||||
// HTTP请求已超时返回,清理堆分配的MessageItem
|
||||
// 注意:response 是栈上的局部变量,不需要 delete
|
||||
delete item;
|
||||
pending_message_item = nullptr;
|
||||
has_pending_item = false;
|
||||
return; // 直接返回,不设置completed
|
||||
}
|
||||
|
||||
// 保存结果
|
||||
// 保存结果(正常完成)
|
||||
item->result_ptr = new HttpResponse(response);
|
||||
item->completed = true;
|
||||
}
|
||||
|
||||
@ -97,6 +97,7 @@
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<ProgramDataBaseFileName>$(IntDir)vc143.pdb</ProgramDataBaseFileName>
|
||||
</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.
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.
Binary file not shown.
@ -401,67 +401,181 @@ pfcModel_ptr ShrinkwrapManager::FindComponentByPath(wfcWAssembly_ptr assembly, c
|
||||
}
|
||||
}
|
||||
|
||||
pfcModel_ptr ShrinkwrapManager::ExecuteOTKShrinkwrap(pfcModel_ptr source_model, const ShrinkwrapShellRequest& request) {
|
||||
if (!source_model) return nullptr;
|
||||
pfcModel_ptr ShrinkwrapManager::ExecuteOTKShrinkwrap(pfcModel_ptr source_model, const ShrinkwrapShellRequest& request, std::string& error_detail) {
|
||||
if (!source_model) {
|
||||
error_detail = "Source model is null";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SessionInfo session_info = GetSessionInfo();
|
||||
if (!session_info.is_valid) return nullptr;
|
||||
if (!session_info.is_valid) {
|
||||
error_detail = "Creo session is not valid";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
try {
|
||||
pfcSolid_ptr source_solid = pfcSolid::cast(source_model);
|
||||
if (!source_solid) return nullptr;
|
||||
// Step 1: Cast to Solid
|
||||
pfcSolid_ptr source_solid = nullptr;
|
||||
try {
|
||||
source_solid = pfcSolid::cast(source_model);
|
||||
} catch (...) {
|
||||
error_detail = "Exception when casting source model to Solid";
|
||||
return nullptr;
|
||||
}
|
||||
if (!source_solid) {
|
||||
error_detail = "Failed to cast source model to Solid. Model type may not support Shrinkwrap.";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Generate safe Part name based on source model
|
||||
std::string base_name = GenerateSafePartName(source_model);
|
||||
// Step 2: Generate safe Part name
|
||||
std::string base_name;
|
||||
try {
|
||||
base_name = GenerateSafePartName(source_model);
|
||||
} catch (...) {
|
||||
error_detail = "Exception when generating safe part name";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Ensure unique name by checking existing models
|
||||
// Step 3: Ensure unique name by checking existing models
|
||||
std::string unique_filename = base_name;
|
||||
int counter = 1;
|
||||
xstring test_name = StringToXString(unique_filename);
|
||||
|
||||
// Check if name already exists, add counter if necessary
|
||||
while (true) {
|
||||
try {
|
||||
pfcModel_ptr existing_model = session_info.session->GetModel(test_name, pfcMDL_PART);
|
||||
if (existing_model) {
|
||||
// Name exists, try next counter
|
||||
unique_filename = base_name + "_" + std::to_string(counter);
|
||||
test_name = StringToXString(unique_filename);
|
||||
counter++;
|
||||
} else {
|
||||
// Name doesn't exist, can use it
|
||||
break;
|
||||
}
|
||||
} catch (...) {
|
||||
// GetModel throws exception if model doesn't exist, name is available
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
xstring output_name = StringToXString(unique_filename);
|
||||
pfcPart_ptr output_part = session_info.session->CreatePart(output_name);
|
||||
if (!output_part) return nullptr;
|
||||
// Step 4: Create output Part with unique name
|
||||
// Get working directory first to check for existing files
|
||||
std::string working_dir;
|
||||
try {
|
||||
xstring working_dir_xstr = session_info.session->GetCurrentDirectory();
|
||||
working_dir = StringToStdString(working_dir_xstr);
|
||||
} catch (...) {
|
||||
working_dir = "";
|
||||
}
|
||||
|
||||
// Generate unique filename by checking both session and disk
|
||||
int name_counter = 0;
|
||||
const int max_name_attempts = 100;
|
||||
std::string final_filename = base_name;
|
||||
|
||||
while (name_counter < max_name_attempts) {
|
||||
if (name_counter > 0) {
|
||||
final_filename = base_name + "_" + std::to_string(name_counter);
|
||||
}
|
||||
|
||||
// Ensure filename is not too long (Creo limit is 31 characters)
|
||||
if (final_filename.length() > 31) {
|
||||
final_filename = final_filename.substr(0, 25) + "_" + std::to_string(name_counter);
|
||||
}
|
||||
|
||||
// Check if file exists on disk
|
||||
std::string file_path = working_dir + "\\" + final_filename + ".prt";
|
||||
bool file_exists_on_disk = FileExists(file_path);
|
||||
|
||||
// Check if model exists in session
|
||||
bool model_exists_in_session = false;
|
||||
try {
|
||||
xstring check_name = StringToXString(final_filename);
|
||||
pfcModel_ptr existing_model = session_info.session->GetModel(check_name, pfcMDL_PART);
|
||||
if (existing_model) {
|
||||
model_exists_in_session = true;
|
||||
// Try to erase from session
|
||||
try {
|
||||
existing_model->Erase();
|
||||
model_exists_in_session = false;
|
||||
} catch (...) {
|
||||
// Erase failed
|
||||
}
|
||||
}
|
||||
} catch (...) {
|
||||
// GetModel throws exception if model doesn't exist
|
||||
}
|
||||
|
||||
if (!file_exists_on_disk && !model_exists_in_session) {
|
||||
break; // Found a unique name
|
||||
}
|
||||
|
||||
name_counter++;
|
||||
}
|
||||
|
||||
if (name_counter >= max_name_attempts) {
|
||||
error_detail = "Could not find unique filename after " + std::to_string(max_name_attempts) + " attempts";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
xstring output_name = StringToXString(final_filename);
|
||||
pfcPart_ptr output_part = nullptr;
|
||||
|
||||
try {
|
||||
output_part = session_info.session->CreatePart(output_name);
|
||||
} catch (...) {
|
||||
error_detail = "Exception when creating output Part: " + final_filename + ". Working dir: " + working_dir;
|
||||
return nullptr;
|
||||
}
|
||||
if (!output_part) {
|
||||
error_detail = "Failed to create output Part: " + final_filename;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
pfcModel_ptr output_model = pfcModel::cast(output_part);
|
||||
if (!output_model) return nullptr;
|
||||
if (!output_model) {
|
||||
error_detail = "Failed to cast output Part to Model";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
pfcShrinkwrapSurfaceSubsetInstructions_ptr instructions =
|
||||
pfcShrinkwrapSurfaceSubsetInstructions::Create(output_model);
|
||||
// Step 5: Create Shrinkwrap instructions
|
||||
pfcShrinkwrapSurfaceSubsetInstructions_ptr instructions = nullptr;
|
||||
try {
|
||||
instructions = pfcShrinkwrapSurfaceSubsetInstructions::Create(output_model);
|
||||
} catch (...) {
|
||||
error_detail = "Exception when creating ShrinkwrapSurfaceSubsetInstructions";
|
||||
return nullptr;
|
||||
}
|
||||
if (!instructions) {
|
||||
error_detail = "Failed to create ShrinkwrapSurfaceSubsetInstructions";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!instructions) return nullptr;
|
||||
|
||||
// 使用用户提交的参数设置
|
||||
instructions->SetQuality(request.quality);
|
||||
instructions->SetAutoHoleFilling(request.fill_holes);
|
||||
instructions->SetIgnoreSmallSurfaces(request.ignore_small_surfaces);
|
||||
instructions->SetSmallSurfPercentage(request.small_surface_percentage);
|
||||
instructions->SetIgnoreQuilts(request.ignore_quilts);
|
||||
instructions->SetIgnoreSkeleton(request.ignore_skeleton);
|
||||
instructions->SetAssignMassProperties(request.assign_mass_properties);
|
||||
// Step 6: Set parameters
|
||||
try {
|
||||
instructions->SetQuality(request.quality);
|
||||
instructions->SetAutoHoleFilling(request.fill_holes);
|
||||
instructions->SetIgnoreSmallSurfaces(request.ignore_small_surfaces);
|
||||
instructions->SetSmallSurfPercentage(request.small_surface_percentage);
|
||||
instructions->SetIgnoreQuilts(request.ignore_quilts);
|
||||
instructions->SetIgnoreSkeleton(request.ignore_skeleton);
|
||||
instructions->SetAssignMassProperties(request.assign_mass_properties);
|
||||
} catch (...) {
|
||||
error_detail = "Exception when setting Shrinkwrap parameters";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Step 7: Cast to export instructions
|
||||
pfcShrinkwrapExportInstructions_ptr export_instructions = pfcShrinkwrapExportInstructions::cast(instructions);
|
||||
if (export_instructions) {
|
||||
if (!export_instructions) {
|
||||
error_detail = "Failed to cast instructions to ShrinkwrapExportInstructions";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Step 8: Execute ExportShrinkwrap
|
||||
try {
|
||||
source_solid->ExportShrinkwrap(export_instructions);
|
||||
} catch (...) {
|
||||
error_detail = "Exception during ExportShrinkwrap execution - model may be too complex";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
try {
|
||||
@ -518,22 +632,25 @@ pfcModel_ptr ShrinkwrapManager::ExecuteOTKShrinkwrap(pfcModel_ptr source_model,
|
||||
return pfcModel::cast(output_part);
|
||||
|
||||
} catch (const pfcXToolkitError& e) {
|
||||
// OTK工具包错误
|
||||
error_detail = "OTK Toolkit Error during ExportShrinkwrap";
|
||||
return nullptr;
|
||||
} catch (const pfcXBadArgument& e) {
|
||||
// 参数错误
|
||||
error_detail = "Bad Argument Error: Invalid parameter passed to Shrinkwrap API";
|
||||
return nullptr;
|
||||
} catch (const pfcXToolkitOutOfMemory& e) {
|
||||
// OTK内存不足错误
|
||||
error_detail = "Out of Memory Error during Shrinkwrap operation";
|
||||
return nullptr;
|
||||
} catch (const pfcXToolkitGeneralError& e) {
|
||||
error_detail = "General OTK Error during ExportShrinkwrap - model may be too complex or have invalid geometry";
|
||||
return nullptr;
|
||||
} catch (const std::bad_alloc& e) {
|
||||
// 标准库内存错误
|
||||
error_detail = "System memory allocation failed";
|
||||
return nullptr;
|
||||
} catch (const std::exception& e) {
|
||||
// 标准异常
|
||||
error_detail = std::string("Standard exception: ") + e.what();
|
||||
return nullptr;
|
||||
} catch (...) {
|
||||
// 未知异常
|
||||
error_detail = "Unknown exception during Shrinkwrap operation";
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
@ -616,8 +733,9 @@ ShrinkwrapShellResult ShrinkwrapManager::ExecuteShrinkwrapShell(const Shrinkwrap
|
||||
|
||||
// Execute Shrinkwrap on target model
|
||||
pfcModel_ptr shrinkwrap_model = nullptr;
|
||||
std::string shrinkwrap_error_detail;
|
||||
try {
|
||||
shrinkwrap_model = ExecuteOTKShrinkwrap(target_model, processed_request);
|
||||
shrinkwrap_model = ExecuteOTKShrinkwrap(target_model, processed_request, shrinkwrap_error_detail);
|
||||
} catch (const pfcXToolkitError& e) {
|
||||
result.success = false;
|
||||
result.error_message = "OTK Toolkit Error: Creo operation failed. This may indicate model corruption or invalid geometry.";
|
||||
@ -642,7 +760,7 @@ ShrinkwrapShellResult ShrinkwrapManager::ExecuteShrinkwrapShell(const Shrinkwrap
|
||||
|
||||
if (!shrinkwrap_model) {
|
||||
result.success = false;
|
||||
result.error_message = "Shrinkwrap Processing Failed: Unable to generate shrinkwrap model. Check if the current model is valid and not corrupted.";
|
||||
result.error_message = "Shrinkwrap Processing Failed: " + shrinkwrap_error_detail;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@ -86,7 +86,8 @@ private:
|
||||
|
||||
// OTK Shrinkwrap执行方法
|
||||
pfcModel_ptr ExecuteOTKShrinkwrap(pfcModel_ptr source_model,
|
||||
const ShrinkwrapShellRequest& request);
|
||||
const ShrinkwrapShellRequest& request,
|
||||
std::string& error_detail);
|
||||
|
||||
// 质量属性计算
|
||||
double CalculateModelVolume(pfcModel_ptr model);
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user