PrusaSlicer-NonPlainar/src/slic3r/GUI/LambdaObjectDialog.cpp

200 lines
5.5 KiB
C++
Raw Normal View History

2018-06-14 19:48:06 +00:00
#include "LambdaObjectDialog.hpp"
#include <wx/window.h>
#include <wx/button.h>
#include "OptionsGroup.hpp"
namespace Slic3r
{
namespace GUI
{
2018-09-17 13:12:13 +00:00
LambdaObjectDialog::LambdaObjectDialog(wxWindow* parent,
const wxString type_name):
m_type_name(type_name)
2018-06-14 19:48:06 +00:00
{
Create(parent, wxID_ANY, _(L("Lambda Object")),
2018-09-17 13:12:13 +00:00
parent->GetScreenPosition(), wxDefaultSize,
2018-06-14 19:48:06 +00:00
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER);
// instead of double dim[3] = { 1.0, 1.0, 1.0 };
object_parameters.dim[0] = 1.0;
object_parameters.dim[1] = 1.0;
object_parameters.dim[2] = 1.0;
sizer = new wxBoxSizer(wxVERTICAL);
// modificator options
2018-09-17 13:12:13 +00:00
if (m_type_name == wxEmptyString) {
m_modificator_options_book = new wxChoicebook( this, wxID_ANY, wxDefaultPosition,
wxDefaultSize, wxCHB_TOP);
sizer->Add(m_modificator_options_book, 1, wxEXPAND | wxALL, 10);
}
else {
m_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
sizer->Add(m_panel, 1, wxEXPAND | wxALL, 10);
}
ConfigOptionDef def;
def.width = 70;
2018-06-14 19:48:06 +00:00
auto optgroup = init_modificator_options_page(_(L("Box")));
2018-10-31 11:56:08 +00:00
if (optgroup) {
optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) {
int opt_id = opt_key == "l" ? 0 :
opt_key == "w" ? 1 :
opt_key == "h" ? 2 : -1;
2018-06-14 19:48:06 +00:00
if (opt_id < 0) return;
object_parameters.dim[opt_id] = boost::any_cast<double>(value);
};
def.type = coFloat;
def.default_value = new ConfigOptionFloat{ 1.0 };
def.label = L("Length");
2018-06-14 19:48:06 +00:00
Option option(def, "l");
optgroup->append_single_option_line(option);
def.label = L("Width");
2018-06-14 19:48:06 +00:00
option = Option(def, "w");
optgroup->append_single_option_line(option);
def.label = L("Height");
2018-06-14 19:48:06 +00:00
option = Option(def, "h");
optgroup->append_single_option_line(option);
2018-09-17 13:12:13 +00:00
}
2018-06-14 19:48:06 +00:00
optgroup = init_modificator_options_page(_(L("Cylinder")));
2018-10-31 11:56:08 +00:00
if (optgroup) {
optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) {
2018-06-14 19:48:06 +00:00
int val = boost::any_cast<int>(value);
if (opt_key == "cyl_r")
object_parameters.cyl_r = val;
else if (opt_key == "cyl_h")
object_parameters.cyl_h = val;
else return;
};
def.type = coInt;
def.default_value = new ConfigOptionInt{ 1 };
def.label = L("Radius");
2018-09-17 13:12:13 +00:00
auto option = Option(def, "cyl_r");
2018-06-14 19:48:06 +00:00
optgroup->append_single_option_line(option);
def.label = L("Height");
option = Option(def, "cyl_h");
optgroup->append_single_option_line(option);
2018-09-17 13:12:13 +00:00
}
2018-06-14 19:48:06 +00:00
optgroup = init_modificator_options_page(_(L("Sphere")));
2018-10-31 11:56:08 +00:00
if (optgroup) {
optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) {
2018-06-14 19:48:06 +00:00
if (opt_key == "sph_rho")
object_parameters.sph_rho = boost::any_cast<double>(value);
else return;
};
def.type = coFloat;
def.default_value = new ConfigOptionFloat{ 1.0 };
def.label = L("Rho");
2018-09-17 13:12:13 +00:00
auto option = Option(def, "sph_rho");
2018-06-14 19:48:06 +00:00
optgroup->append_single_option_line(option);
2018-09-17 13:12:13 +00:00
}
2018-06-14 19:48:06 +00:00
optgroup = init_modificator_options_page(_(L("Slab")));
2018-10-31 11:56:08 +00:00
if (optgroup) {
optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) {
2018-06-14 19:48:06 +00:00
double val = boost::any_cast<double>(value);
if (opt_key == "slab_z")
object_parameters.slab_z = val;
else if (opt_key == "slab_h")
object_parameters.slab_h = val;
else return;
};
2018-09-17 13:12:13 +00:00
def.type = coFloat;
def.default_value = new ConfigOptionFloat{ 1.0 };
def.label = L("Height");
2018-09-17 13:12:13 +00:00
auto option = Option(def, "slab_h");
2018-06-14 19:48:06 +00:00
optgroup->append_single_option_line(option);
def.label = L("Initial Z");
option = Option(def, "slab_z");
optgroup->append_single_option_line(option);
2018-09-17 13:12:13 +00:00
}
2018-06-14 19:48:06 +00:00
Bind(wxEVT_CHOICEBOOK_PAGE_CHANGED, ([this](wxCommandEvent e)
{
auto page_idx = m_modificator_options_book->GetSelection();
if (page_idx < 0) return;
switch (page_idx)
{
case 0:
object_parameters.type = LambdaTypeBox;
break;
case 1:
object_parameters.type = LambdaTypeCylinder;
break;
case 2:
object_parameters.type = LambdaTypeSphere;
break;
case 3:
object_parameters.type = LambdaTypeSlab;
break;
default:
break;
}
}));
2018-09-17 13:12:13 +00:00
const auto button_sizer = CreateStdDialogButtonSizer(wxOK | wxCANCEL);
2018-06-14 19:48:06 +00:00
wxButton* btn_OK = static_cast<wxButton*>(FindWindowById(wxID_OK, this));
btn_OK->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) {
// validate user input
if (!CanClose())return;
EndModal(wxID_OK);
Destroy();
});
wxButton* btn_CANCEL = static_cast<wxButton*>(FindWindowById(wxID_CANCEL, this));
btn_CANCEL->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) {
// validate user input
if (!CanClose())return;
EndModal(wxID_CANCEL);
Destroy();
});
sizer->Add(button_sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxBOTTOM, 10);
SetSizer(sizer);
sizer->Fit(this);
sizer->SetSizeHints(this);
}
// Called from the constructor.
// Create a panel for a rectangular / circular / custom bed shape.
2018-10-31 11:56:08 +00:00
ConfigOptionsGroupShp LambdaObjectDialog::init_modificator_options_page(const wxString& title)
{
2018-09-17 13:12:13 +00:00
if (!m_type_name.IsEmpty() && m_type_name != title)
return nullptr;
2018-06-14 19:48:06 +00:00
2018-09-17 13:12:13 +00:00
auto panel = m_type_name.IsEmpty() ? new wxPanel(m_modificator_options_book) : m_panel;
2018-06-14 19:48:06 +00:00
ConfigOptionsGroupShp optgroup;
optgroup = std::make_shared<ConfigOptionsGroup>(panel, _(L("Add")) + " " +title + " " +dots);
optgroup->label_width = 100;
m_optgroups.push_back(optgroup);
2018-09-17 13:12:13 +00:00
if (m_type_name.IsEmpty()) {
panel->SetSizerAndFit(optgroup->sizer);
m_modificator_options_book->AddPage(panel, title);
}
else
panel->SetSizer(optgroup->sizer);
2018-06-14 19:48:06 +00:00
return optgroup;
}
} //namespace GUI
} //namespace Slic3r