#include "OptionsGroup.hpp" #include "ConfigExceptions.hpp" #include "Plater.hpp" #include "GUI_App.hpp" #include "OG_CustomCtrl.hpp" #include #include #include #include #include "libslic3r/Exception.hpp" #include "libslic3r/Utils.hpp" #include "I18N.hpp" namespace Slic3r { namespace GUI { const t_field& OptionsGroup::build_field(const Option& opt) { return build_field(opt.opt_id, opt.opt); } const t_field& OptionsGroup::build_field(const t_config_option_key& id) { const ConfigOptionDef& opt = m_options.at(id).opt; return build_field(id, opt); } const t_field& OptionsGroup::build_field(const t_config_option_key& id, const ConfigOptionDef& opt) { // Check the gui_type field first, fall through // is the normal type. switch (opt.gui_type) { case ConfigOptionDef::GUIType::select_open: m_fields.emplace(id, Choice::Create(this->ctrl_parent(), opt, id)); break; case ConfigOptionDef::GUIType::color: m_fields.emplace(id, ColourPicker::Create(this->ctrl_parent(), opt, id)); break; case ConfigOptionDef::GUIType::f_enum_open: case ConfigOptionDef::GUIType::i_enum_open: m_fields.emplace(id, Choice::Create(this->ctrl_parent(), opt, id)); break; case ConfigOptionDef::GUIType::slider: m_fields.emplace(id, SliderCtrl::Create(this->ctrl_parent(), opt, id)); break; case ConfigOptionDef::GUIType::legend: // StaticText m_fields.emplace(id, StaticText::Create(this->ctrl_parent(), opt, id)); break; case ConfigOptionDef::GUIType::one_string: m_fields.emplace(id, TextCtrl::Create(this->ctrl_parent(), opt, id)); break; default: switch (opt.type) { case coFloatOrPercent: case coFloat: case coFloats: case coPercent: case coPercents: case coString: case coStrings: m_fields.emplace(id, TextCtrl::Create(this->ctrl_parent(), opt, id)); break; case coBool: case coBools: m_fields.emplace(id, CheckBox::Create(this->ctrl_parent(), opt, id)); break; case coInt: case coInts: m_fields.emplace(id, SpinCtrl::Create(this->ctrl_parent(), opt, id)); break; case coEnum: m_fields.emplace(id, Choice::Create(this->ctrl_parent(), opt, id)); break; case coPoints: m_fields.emplace(id, PointCtrl::Create(this->ctrl_parent(), opt, id)); break; case coNone: break; default: throw Slic3r::LogicError("This control doesn't exist till now"); break; } } // Grab a reference to fields for convenience const t_field& field = m_fields[id]; field->m_on_change = [this](const std::string& opt_id, const boost::any& value) { //! This function will be called from Field. //! Call OptionGroup._on_change(...) if (!m_disabled) this->on_change_OG(opt_id, value); }; field->m_on_kill_focus = [this](const std::string& opt_id) { //! This function will be called from Field. if (!m_disabled) this->on_kill_focus(opt_id); }; field->m_parent = parent(); field->m_back_to_initial_value = [this](std::string opt_id) { if (!m_disabled) this->back_to_initial_value(opt_id); }; field->m_back_to_sys_value = [this](std::string opt_id) { if (!this->m_disabled) this->back_to_sys_value(opt_id); }; // assign function objects for callbacks, etc. return field; } OptionsGroup::OptionsGroup( wxWindow* _parent, const wxString& title, bool is_tab_opt /* = false */, column_t extra_clmn /* = nullptr */) : m_parent(_parent), title(title), m_use_custom_ctrl(is_tab_opt), staticbox(title!=""), extra_column(extra_clmn) { } wxWindow* OptionsGroup::ctrl_parent() const { return this->custom_ctrl && m_use_custom_ctrl_as_parent ? static_cast(this->custom_ctrl) : (this->stb ? static_cast(this->stb) : this->parent()); } bool OptionsGroup::is_legend_line() { if (m_lines.size() == 1) { const std::vector