125 lines
3.4 KiB
C++
125 lines
3.4 KiB
C++
#include "pch.h"
|
|
|
|
#include "ShrinkwrapCommand.h"
|
|
#include "Creo90Manager.h"
|
|
#include "Shrinkwrap90Manager.h"
|
|
|
|
#include "CreoOtk.h"
|
|
|
|
#include <chrono>
|
|
#include <sstream>
|
|
|
|
namespace {
|
|
|
|
void ShowMessage(pfcSession_ptr session, const std::string& msg) {
|
|
try {
|
|
pfcMessageDialogOptions_ptr opts = pfcMessageDialogOptions::Create();
|
|
opts->SetMessageDialogType(pfcMESSAGE_INFO);
|
|
opts->SetDialogLabel("Shrinkwrap");
|
|
session->UIShowMessageDialog(msg.c_str(), opts);
|
|
} catch (...) {
|
|
}
|
|
}
|
|
|
|
std::string PromptForOutputPath(pfcSession_ptr session) {
|
|
try {
|
|
Creo90Manager creo;
|
|
pfcModel_ptr mdl = creo.GetCurrentModel();
|
|
std::string defaultName = "shrinkwrap";
|
|
if (mdl) {
|
|
xstring name = mdl->GetFileName();
|
|
const char* namePtr = static_cast<const char*>(name);
|
|
if (namePtr && namePtr[0]) {
|
|
defaultName = namePtr;
|
|
size_t dotPos = defaultName.rfind('.');
|
|
if (dotPos != std::string::npos) {
|
|
defaultName = defaultName.substr(0, dotPos);
|
|
}
|
|
defaultName += "_shrinkwrap";
|
|
}
|
|
}
|
|
|
|
pfcFileSaveOptions_ptr opts = pfcFileSaveOptions::Create("*.prt");
|
|
opts->SetPreselectedItem((defaultName + ".prt").c_str());
|
|
|
|
xstring result = session->UISaveFile(opts);
|
|
const char* resultPtr = static_cast<const char*>(result);
|
|
if (resultPtr && resultPtr[0]) {
|
|
return std::string(resultPtr);
|
|
}
|
|
} catch (...) {
|
|
}
|
|
return std::string();
|
|
}
|
|
|
|
} // namespace
|
|
|
|
void ShrinkwrapActionListener::OnCommand() {
|
|
try {
|
|
pfcSession_ptr session = pfcGetProESession();
|
|
if (!session) return;
|
|
|
|
Creo90Manager creo;
|
|
pfcSolid_ptr solid = creo.GetCurrentSolid();
|
|
if (!solid) {
|
|
ShowMessage(session, "No active part or assembly. Please open a model first.");
|
|
return;
|
|
}
|
|
|
|
std::string outPath = PromptForOutputPath(session);
|
|
if (outPath.empty()) {
|
|
return;
|
|
}
|
|
|
|
ShrinkwrapShellRequest req;
|
|
req.output_file_path = outPath;
|
|
req.quality = 5;
|
|
req.ignore_quilts = true;
|
|
req.ignore_skeleton = true;
|
|
req.assign_mass_properties = false;
|
|
|
|
auto start = std::chrono::steady_clock::now();
|
|
Shrinkwrap90Manager mgr;
|
|
ShrinkwrapShellResult result = mgr.ExportShell(req);
|
|
auto end = std::chrono::steady_clock::now();
|
|
|
|
auto secs = std::chrono::duration_cast<std::chrono::seconds>(end - start).count();
|
|
result.execution_time = Shrinkwrap90Manager::FormatHhMmSs(secs);
|
|
|
|
std::ostringstream oss;
|
|
oss << "Shrinkwrap export completed!\n\n";
|
|
oss << "Output: " << result.output_path << "\n";
|
|
oss << "File Size: " << result.file_size << "\n";
|
|
oss << "Time: " << result.execution_time;
|
|
|
|
ShowMessage(session, oss.str());
|
|
|
|
} catch (pfcXPFC& ex) {
|
|
try {
|
|
pfcSession_ptr session = pfcGetProESession();
|
|
xstring msg = ex.GetMessage();
|
|
const char* msgPtr = static_cast<const char*>(msg);
|
|
std::ostringstream oss;
|
|
oss << "Creo OTK Error: ";
|
|
if (msgPtr && msgPtr[0]) {
|
|
oss << msgPtr;
|
|
} else {
|
|
oss << "Unknown OTK error";
|
|
}
|
|
ShowMessage(session, oss.str());
|
|
} catch (...) {}
|
|
} catch (const std::exception& ex) {
|
|
try {
|
|
pfcSession_ptr session = pfcGetProESession();
|
|
std::ostringstream oss;
|
|
oss << "Error: " << ex.what();
|
|
ShowMessage(session, oss.str());
|
|
} catch (...) {}
|
|
} catch (...) {
|
|
try {
|
|
pfcSession_ptr session = pfcGetProESession();
|
|
ShowMessage(session, "Unknown error occurred");
|
|
} catch (...) {}
|
|
}
|
|
}
|