#include "OptionsGroup.hpp" #include "ConfigExceptions.hpp" #include #include #include #include #include "libslic3r/Utils.hpp" #include "I18N.hpp" namespace Slic3r { namespace GUI { const t_field& OptionsGroup::build_field(const Option& opt, wxStaticText* label/* = nullptr*/) { return build_field(opt.opt_id, opt.opt, label); } const t_field& OptionsGroup::build_field(const t_config_option_key& id, wxStaticText* label/* = nullptr*/) { const ConfigOptionDef& opt = m_options.at(id).opt; return build_field(id, opt, label); } const t_field& OptionsGroup::build_field(const t_config_option_key& id, const ConfigOptionDef& opt, wxStaticText* label/* = nullptr*/) { // Check the gui_type field first, fall through // is the normal type. if (opt.gui_type.compare("select") == 0) { } else if (opt.gui_type.compare("select_open") == 0) { m_fields.emplace(id, std::move(Choice::Create(this->ctrl_parent(), opt, id))); } else if (opt.gui_type.compare("color") == 0) { m_fields.emplace(id, std::move(ColourPicker::Create(this->ctrl_parent(), opt, id))); } else if (opt.gui_type.compare("f_enum_open") == 0 || opt.gui_type.compare("i_enum_open") == 0 || opt.gui_type.compare("i_enum_closed") == 0) { m_fields.emplace(id, std::move(Choice::Create(this->ctrl_parent(), opt, id))); } else if (opt.gui_type.compare("slider") == 0) { m_fields.emplace(id, std::move(SliderCtrl::Create(this->ctrl_parent(), opt, id))); } else if (opt.gui_type.compare("i_spin") == 0) { // Spinctrl } else if (opt.gui_type.compare("legend") == 0) { // StaticText m_fields.emplace(id, std::move(StaticText::Create(this->ctrl_parent(), opt, id))); } else { switch (opt.type) { case coFloatOrPercent: case coFloat: case coFloats: case coPercent: case coPercents: case coString: case coStrings: m_fields.emplace(id, std::move(TextCtrl::Create(this->ctrl_parent(), opt, id))); break; case coBool: case coBools: m_fields.emplace(id, std::move(CheckBox::Create(this->ctrl_parent(), opt, id))); break; case coInt: case coInts: m_fields.emplace(id, std::move(SpinCtrl::Create(this->ctrl_parent(), opt, id))); break; case coEnum: m_fields.emplace(id, std::move(Choice::Create(this->ctrl_parent(), opt, id))); break; case coPoints: m_fields.emplace(id, std::move(PointCtrl::Create(this->ctrl_parent(), opt, id))); break; case coNone: break; default: throw /*//!ConfigGUITypeError("")*/std::logic_error("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_on_set_focus = [this](const std::string& opt_id) { //! This function will be called from Field. if (!m_disabled) this->on_set_focus(opt_id); }; field->m_parent = parent(); //! Label to change background color, when option is modified field->m_Label = label; 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; } void OptionsGroup::add_undo_buttuns_to_sizer(wxSizer* sizer, const t_field& field, std::vector* widget_idx_in_sizer) { if (!m_show_modified_btns) { field->m_Undo_btn->set_as_hidden(); field->m_Undo_to_sys_btn->set_as_hidden(); return; } if(widget_idx_in_sizer) widget_idx_in_sizer->push_back(sizer->GetItemCount()); sizer->Add(field->m_Undo_to_sys_btn, 0, wxALIGN_CENTER_VERTICAL); if (widget_idx_in_sizer) widget_idx_in_sizer->push_back(sizer->GetItemCount()); sizer->Add(field->m_Undo_btn, 0, wxALIGN_CENTER_VERTICAL); } void OptionsGroup::append_line(const Line& line, wxStaticText** full_Label/* = nullptr*/) { if ( (line.sizer != nullptr || line.widget != nullptr) && line.full_width) { if (line.sizer != nullptr) { sizer->Add(line.sizer, 0, wxEXPAND | wxALL, wxOSX ? 0 : 15); return; } if (line.widget != nullptr) { sizer->Add(line.widget(this->ctrl_parent()), 0, wxEXPAND | wxALL, wxOSX ? 0 : 15); return; } } const std::vector