233 lines
8.9 KiB
C++
233 lines
8.9 KiB
C++
#include "pch.h"
|
|
#include "ShrinkwrapDialog.h"
|
|
#include <string>
|
|
#include <sstream>
|
|
#include <uifcSlider.h>
|
|
#include <uifcLabel.h>
|
|
#include <uifcCheckButton.h>
|
|
#include <uifcInputPanel.h>
|
|
#include <uifcPushButton.h>
|
|
#include <uifcDialog.h>
|
|
#include <uifcDefaultListeners.h>
|
|
#include <uifcExceptions.h>
|
|
#include <uifcRadioGroup.h>
|
|
|
|
xstring ShrinkwrapDialog::DIALOG_NAME = "shrinkwrap_params";
|
|
|
|
class ShrinkwrapDialog::DialogListener : public uifcDefaultDialogListener {
|
|
public:
|
|
// This listener handles generic dialog events if needed.
|
|
// For now we just implement it to satisfy the requirements if attached.
|
|
};
|
|
|
|
class ShrinkwrapDialog::SliderListener : public uifcDefaultSliderListener {
|
|
public:
|
|
void OnChange(uifcSlider_ptr handle) override {
|
|
OnDragMove(handle); // Re-use logic
|
|
}
|
|
|
|
void OnDragMove(uifcSlider_ptr handle) override {
|
|
try {
|
|
int val = handle->GetIntegerValue(); // uifcSlider inherits GetIntegerValue
|
|
uifcLabel_ptr lbl = uifcLabelFind(ShrinkwrapDialog::DIALOG_NAME, "quality_val_lbl");
|
|
if (lbl) {
|
|
std::stringstream ss;
|
|
ss << val;
|
|
lbl->SetText(ss.str().c_str());
|
|
}
|
|
} catch (...) {}
|
|
}
|
|
};
|
|
|
|
class ShrinkwrapDialog::CheckButtonListener : public uifcDefaultCheckButtonListener {
|
|
public:
|
|
void OnActivate(uifcCheckButton_ptr handle) override {
|
|
try {
|
|
uifcCheckState state = handle->GetCheckedState();
|
|
bool checked = (state == uifcCHECK_STATE_SET);
|
|
uifcInputPanel_ptr ip = uifcInputPanelFind(ShrinkwrapDialog::DIALOG_NAME, "small_surf_pct_ip");
|
|
if (ip) {
|
|
// uifcInputPanel inherits uifcComponent which has SetEnabled
|
|
// Let's check uifcComponent methods or if it's SetEnabled vs SetEnable
|
|
// uifcSlider.h shows SetEnabled(xbool). Let's assume InputPanel has it too via Component.
|
|
// The error "SetEnable is not a member" suggests it's likely SetEnabled.
|
|
ip->SetEnabled(checked);
|
|
}
|
|
} catch (...) {}
|
|
}
|
|
};
|
|
|
|
// ... ButtonListener removed as we use specific listeners below ...
|
|
|
|
class OKButtonListener : public uifcDefaultPushButtonListener {
|
|
public:
|
|
OKButtonListener(bool& res) : result(res) {}
|
|
void OnActivate(uifcPushButton_ptr handle) override {
|
|
result = true;
|
|
uifcExitDialog(handle->GetDialog(), 0);
|
|
}
|
|
private:
|
|
bool& result;
|
|
};
|
|
|
|
class CancelButtonListener : public uifcDefaultPushButtonListener {
|
|
public:
|
|
void OnActivate(uifcPushButton_ptr handle) override {
|
|
uifcExitDialog(handle->GetDialog(), 0);
|
|
}
|
|
};
|
|
|
|
class QualitySliderListener : public uifcDefaultSliderListener {
|
|
public:
|
|
void OnDragMove(uifcSlider_ptr handle) override {
|
|
UpdateLabel(handle);
|
|
}
|
|
void OnChange(uifcSlider_ptr handle) override {
|
|
UpdateLabel(handle);
|
|
}
|
|
|
|
private:
|
|
void UpdateLabel(uifcSlider_ptr handle) {
|
|
try {
|
|
int val = handle->GetIntegerValue(); // Use GetIntegerValue
|
|
uifcLabel_ptr lbl = uifcLabelFind(handle->GetDialog(), "quality_val_lbl");
|
|
if (lbl) {
|
|
std::stringstream ss;
|
|
ss << val;
|
|
lbl->SetText(ss.str().c_str());
|
|
}
|
|
} catch (...) {}
|
|
}
|
|
};
|
|
|
|
class SmallSurfCheckListener : public uifcDefaultCheckButtonListener {
|
|
public:
|
|
void OnActivate(uifcCheckButton_ptr handle) override {
|
|
try {
|
|
uifcCheckState state = handle->GetCheckedState();
|
|
bool checked = (state == uifcCHECK_STATE_SET);
|
|
uifcInputPanel_ptr ip = uifcInputPanelFind(handle->GetDialog(), "small_surf_pct_ip");
|
|
if (ip) ip->SetEnabled(checked); // Use SetEnabled
|
|
} catch (...) {}
|
|
}
|
|
};
|
|
|
|
void ShrinkwrapDialog::InitValues(const ShrinkwrapShellRequest& request) {
|
|
try {
|
|
uifcRadioGroup_ptr methodRg = uifcRadioGroupFind(DIALOG_NAME, "method_rg");
|
|
if (methodRg) {
|
|
xstringsequence_ptr sel = xstringsequence::create();
|
|
std::stringstream ss;
|
|
ss << request.method;
|
|
sel->append(ss.str().c_str());
|
|
methodRg->SetSelectedItemNameArray(sel); // SetSelectedItemNameArray
|
|
}
|
|
|
|
uifcCheckButtonFind(DIALOG_NAME, "fill_holes_cb")->SetCheckedState(request.fill_holes ? uifcCHECK_STATE_SET : uifcCHECK_STATE_UNSET);
|
|
uifcCheckButtonFind(DIALOG_NAME, "ignore_quilts_cb")->SetCheckedState(request.ignore_quilts ? uifcCHECK_STATE_SET : uifcCHECK_STATE_UNSET);
|
|
uifcCheckButtonFind(DIALOG_NAME, "ignore_skeleton_cb")->SetCheckedState(request.ignore_skeleton ? uifcCHECK_STATE_SET : uifcCHECK_STATE_UNSET);
|
|
uifcCheckButtonFind(DIALOG_NAME, "assign_mass_cb")->SetCheckedState(request.assign_mass_properties ? uifcCHECK_STATE_SET : uifcCHECK_STATE_UNSET);
|
|
|
|
uifcCheckButton_ptr smallCb = uifcCheckButtonFind(DIALOG_NAME, "ignore_small_cb");
|
|
smallCb->SetCheckedState(request.ignore_small_surfaces ? uifcCHECK_STATE_SET : uifcCHECK_STATE_UNSET);
|
|
|
|
uifcInputPanel_ptr smallIp = uifcInputPanelFind(DIALOG_NAME, "small_surf_pct_ip");
|
|
smallIp->SetDoubleValue(request.small_surface_percentage);
|
|
smallIp->SetEnabled(request.ignore_small_surfaces);
|
|
|
|
uifcSlider_ptr slider = uifcSliderFind(DIALOG_NAME, "quality_slider");
|
|
slider->SetMinimumIntegerValue(1);
|
|
slider->SetMaximumIntegerValue(10);
|
|
slider->SetIntegerValue(request.quality); // SetIntegerValue
|
|
|
|
uifcLabel_ptr qLbl = uifcLabelFind(DIALOG_NAME, "quality_val_lbl");
|
|
std::stringstream ss;
|
|
ss << request.quality;
|
|
qLbl->SetText(ss.str().c_str());
|
|
|
|
} catch (...) {}
|
|
}
|
|
|
|
void ShrinkwrapDialog::UpdateRequest(ShrinkwrapShellRequest& request) {
|
|
try {
|
|
uifcRadioGroup_ptr methodRg = uifcRadioGroupFind(DIALOG_NAME, "method_rg");
|
|
if (methodRg) {
|
|
xstringsequence_ptr sel = methodRg->GetSelectedItemNameArray(); // GetSelectedItemNameArray
|
|
if (sel && sel->getarraysize() > 0) {
|
|
std::string s = (const char*)sel->get(0);
|
|
try {
|
|
request.method = std::stoi(s);
|
|
} catch (...) {}
|
|
}
|
|
}
|
|
|
|
request.fill_holes = (uifcCheckButtonFind(DIALOG_NAME, "fill_holes_cb")->GetCheckedState() == uifcCHECK_STATE_SET);
|
|
request.ignore_quilts = (uifcCheckButtonFind(DIALOG_NAME, "ignore_quilts_cb")->GetCheckedState() == uifcCHECK_STATE_SET);
|
|
request.ignore_skeleton = (uifcCheckButtonFind(DIALOG_NAME, "ignore_skeleton_cb")->GetCheckedState() == uifcCHECK_STATE_SET);
|
|
request.assign_mass_properties = (uifcCheckButtonFind(DIALOG_NAME, "assign_mass_cb")->GetCheckedState() == uifcCHECK_STATE_SET);
|
|
|
|
request.ignore_small_surfaces = (uifcCheckButtonFind(DIALOG_NAME, "ignore_small_cb")->GetCheckedState() == uifcCHECK_STATE_SET);
|
|
if (request.ignore_small_surfaces) {
|
|
request.small_surface_percentage = uifcInputPanelFind(DIALOG_NAME, "small_surf_pct_ip")->GetDoubleValue();
|
|
}
|
|
|
|
request.quality = uifcSliderFind(DIALOG_NAME, "quality_slider")->GetIntegerValue();
|
|
} catch (...) {}
|
|
}
|
|
|
|
|
|
bool ShrinkwrapDialog::Show(ShrinkwrapShellRequest& request) {
|
|
bool isOk = false;
|
|
|
|
// Debug point 1: Confirm entry
|
|
/*
|
|
pfcSession_ptr session = pfcGetProESession();
|
|
if (session) session->UIShowMessageDialog("Entering ShrinkwrapDialog::Show", NULL);
|
|
*/
|
|
|
|
try {
|
|
int status = uifcCreateDialog(DIALOG_NAME, DIALOG_NAME);
|
|
if (status != 0) {
|
|
// Debug point 2: Creation failed (if status implies failure, though uifc usually throws)
|
|
}
|
|
|
|
InitValues(request);
|
|
|
|
uifcPushButtonFind(DIALOG_NAME, "ok_pb")->AddActionListener(new OKButtonListener(isOk));
|
|
uifcPushButtonFind(DIALOG_NAME, "cancel_pb")->AddActionListener(new CancelButtonListener());
|
|
uifcSliderFind(DIALOG_NAME, "quality_slider")->AddActionListener(new QualitySliderListener());
|
|
uifcCheckButtonFind(DIALOG_NAME, "ignore_small_cb")->AddActionListener(new SmallSurfCheckListener());
|
|
|
|
uifcActivateDialog(DIALOG_NAME);
|
|
|
|
if (isOk) {
|
|
UpdateRequest(request);
|
|
}
|
|
|
|
uifcDestroyDialog(DIALOG_NAME);
|
|
} catch (pfcXToolkitError& e) {
|
|
// Log OTK errors or show a message
|
|
pfcSession_ptr session = pfcGetProESession();
|
|
if (session) {
|
|
xstring msg = e.GetMessage();
|
|
std::stringstream ss;
|
|
ss << "OTK Error: " << msg;
|
|
session->UIShowMessageDialog(ss.str().c_str(), NULL);
|
|
}
|
|
try {
|
|
uifcDestroyDialog(DIALOG_NAME);
|
|
} catch (...) {}
|
|
return false;
|
|
} catch (...) {
|
|
pfcSession_ptr session = pfcGetProESession();
|
|
if (session) {
|
|
session->UIShowMessageDialog("Unknown exception in dialog creation", NULL);
|
|
}
|
|
try {
|
|
uifcDestroyDialog(DIALOG_NAME);
|
|
} catch (...) {}
|
|
return false;
|
|
}
|
|
return isOk;
|
|
}
|