#include "OptionsGroup.hpp" #include "ConfigExceptions.hpp" #include "Plater.hpp" #include "GUI_App.hpp" #include "MainFrame.hpp" #include "OG_CustomCtrl.hpp" #include "MsgDialog.hpp" #include "format.hpp" #include "Widgets/StaticLine.hpp" #include #include #include #include #include #include "libslic3r/Exception.hpp" #include "libslic3r/Utils.hpp" #include "libslic3r/AppConfig.hpp" #include "I18N.hpp" namespace Slic3r { namespace GUI { // BBS: new layout constexpr int titleWidth = 20; // get the param index of cur_exturder int get_extruder_idx(const DynamicPrintConfig& config, const std::string &opt_key, int cur_extruder_id) { if (printer_extruder_options.find(opt_key) != printer_extruder_options.end()) { return cur_extruder_id; } int extruder_count = wxGetApp().preset_bundle->get_printer_extruder_count(); if (extruder_count == 1 || cur_extruder_id == -1) return 0; assert(cur_extruder_id < extruder_count); const DynamicPrintConfig& cur_printer_config = wxGetApp().preset_bundle->printers.get_selected_preset().config; auto opt_extruder_type = dynamic_cast(cur_printer_config.option("extruder_type")); auto opt_nozzle_volume_type = dynamic_cast(cur_printer_config.option("nozzle_volume_type")); if (!opt_extruder_type || !opt_nozzle_volume_type) return 0; ExtruderType extruder_type = (ExtruderType) (opt_extruder_type->get_at(cur_extruder_id)); NozzleVolumeType nozzle_volume_type = (NozzleVolumeType) (opt_nozzle_volume_type->get_at(cur_extruder_id)); std::string id_name, variant_name; unsigned int stride = 1; if (printer_options_with_variant_1.count(opt_key) > 0) { // printer parameter id_name = "printer_extruder_id"; variant_name = "printer_extruder_variant"; } else if (printer_options_with_variant_2.count(opt_key) > 0) { id_name = "printer_extruder_id"; variant_name = "printer_extruder_variant"; stride = 2; } else if (filament_options_with_variant.count(opt_key) > 0) { //filament don't use id anymore //id_name = "filament_extruder_id"; variant_name = "filament_extruder_variant"; } else if (print_options_with_variant.count(opt_key) > 0) { id_name = "print_extruder_id"; variant_name = "print_extruder_variant"; } else { return 0; } // variant index int variant_index = config.get_index_for_extruder(cur_extruder_id + 1, id_name, extruder_type, nozzle_volume_type, variant_name, stride); if (variant_index < 0) { assert(false); return 0; } return variant_index; } 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 coFloatsOrPercents: 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: case coEnums: m_fields.emplace(id, Choice::Create(this->ctrl_parent(), opt, id)); break; case coPoint: 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, const wxString &icon, bool is_tab_opt /* = false */, column_t extra_clmn /* = nullptr */) : m_parent(_parent), title(title), icon(icon), m_use_custom_ctrl(is_tab_opt), // BBS: new layout staticbox(!is_tab_opt), extra_column(extra_clmn) { } wxWindow* OptionsGroup::ctrl_parent() const { // BBS: new layout return this->custom_ctrl && m_use_custom_ctrl_as_parent ? static_cast(this->custom_ctrl) : (staticbox ? static_cast(this->stb) : this->parent()); } bool OptionsGroup::is_legend_line() { if (m_lines.size() == 1) { const std::vector