From 9926181008af7dd5b1f85317dbba93e3a7161818 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Fri, 27 Oct 2023 11:05:50 +0200 Subject: [PATCH] OptionsGroup : Refactoring * Don't use "m_"prefix for public members * Move change_opt_value() function from GUI to OptionsGroup --- src/slic3r/GUI/BedShapeDialog.cpp | 6 +- src/slic3r/GUI/GUI.cpp | 122 -------------------- src/slic3r/GUI/GUI.hpp | 3 - src/slic3r/GUI/GUI_ObjectSettings.cpp | 2 +- src/slic3r/GUI/OptionsGroup.cpp | 140 +++++++++++++++++++++-- src/slic3r/GUI/OptionsGroup.hpp | 14 ++- src/slic3r/GUI/PhysicalPrinterDialog.cpp | 2 +- src/slic3r/GUI/Plater.cpp | 4 +- src/slic3r/GUI/Preferences.cpp | 12 +- src/slic3r/GUI/Tab.cpp | 66 +++++------ 10 files changed, 183 insertions(+), 188 deletions(-) diff --git a/src/slic3r/GUI/BedShapeDialog.cpp b/src/slic3r/GUI/BedShapeDialog.cpp index a8bbacf6e6..8a6f3dddb7 100644 --- a/src/slic3r/GUI/BedShapeDialog.cpp +++ b/src/slic3r/GUI/BedShapeDialog.cpp @@ -266,7 +266,7 @@ ConfigOptionsGroupShp BedShapePanel::init_shape_options_page(const wxString& tit ConfigOptionsGroupShp optgroup = std::make_shared(panel, _L("Settings")); optgroup->label_width = 10; - optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) { + optgroup->on_change = [this](t_config_option_key opt_key, boost::any value) { update_shape(); }; @@ -290,7 +290,7 @@ wxPanel* BedShapePanel::init_texture_panel() ConfigOptionsGroupShp optgroup = std::make_shared(panel, _L("Texture")); optgroup->label_width = 10; - optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) { + optgroup->on_change = [this](t_config_option_key opt_key, boost::any value) { update_shape(); }; @@ -363,7 +363,7 @@ wxPanel* BedShapePanel::init_model_panel() ConfigOptionsGroupShp optgroup = std::make_shared(panel, _L("Model")); optgroup->label_width = 10; - optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) { + optgroup->on_change = [this](t_config_option_key opt_key, boost::any value) { update_shape(); }; diff --git a/src/slic3r/GUI/GUI.cpp b/src/slic3r/GUI/GUI.cpp index d0c8aa5733..bc64d28084 100644 --- a/src/slic3r/GUI/GUI.cpp +++ b/src/slic3r/GUI/GUI.cpp @@ -107,128 +107,6 @@ const std::string& shortkey_alt_prefix() return str; } -// opt_index = 0, by the reason of zero-index in ConfigOptionVector by default (in case only one element) -void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt_key, const boost::any& value, int opt_index /*= 0*/) -{ - try{ - - if (config.def()->get(opt_key)->type == coBools && config.def()->get(opt_key)->nullable) { - ConfigOptionBoolsNullable* vec_new = new ConfigOptionBoolsNullable{ boost::any_cast(value) }; - config.option(opt_key)->set_at(vec_new, opt_index, 0); - return; - } - - const ConfigOptionDef *opt_def = config.def()->get(opt_key); - switch (opt_def->type) { - case coFloatOrPercent:{ - std::string str = boost::any_cast(value); - bool percent = false; - if (str.back() == '%') { - str.pop_back(); - percent = true; - } - double val = std::stod(str); // locale-dependent (on purpose - the input is the actual content of the field) - config.set_key_value(opt_key, new ConfigOptionFloatOrPercent(val, percent)); - break;} - case coPercent: - config.set_key_value(opt_key, new ConfigOptionPercent(boost::any_cast(value))); - break; - case coFloat:{ - double& val = config.opt_float(opt_key); - val = boost::any_cast(value); - break; - } - case coFloatsOrPercents:{ - std::string str = boost::any_cast(value); - bool percent = false; - if (str.back() == '%') { - str.pop_back(); - percent = true; - } - double val = std::stod(str); // locale-dependent (on purpose - the input is the actual content of the field) - ConfigOptionFloatsOrPercents* vec_new = new ConfigOptionFloatsOrPercents({ {val, percent} }); - config.option(opt_key)->set_at(vec_new, opt_index, opt_index); - break; - } - case coPercents:{ - ConfigOptionPercents* vec_new = new ConfigOptionPercents{ boost::any_cast(value) }; - config.option(opt_key)->set_at(vec_new, opt_index, opt_index); - break; - } - case coFloats:{ - ConfigOptionFloats* vec_new = new ConfigOptionFloats{ boost::any_cast(value) }; - config.option(opt_key)->set_at(vec_new, opt_index, opt_index); - break; - } - case coString: - config.set_key_value(opt_key, new ConfigOptionString(boost::any_cast(value))); - break; - case coStrings:{ - if (opt_key == "compatible_prints" || opt_key == "compatible_printers" || opt_key == "gcode_substitutions") { - config.option(opt_key)->values = - boost::any_cast>(value); - } - else if (config.def()->get(opt_key)->gui_flags.compare("serialized") == 0) { - std::string str = boost::any_cast(value); - std::vector values {}; - if (!str.empty()) { - if (str.back() == ';') str.pop_back(); - // Split a string to multiple strings by a semi - colon.This is the old way of storing multi - string values. - // Currently used for the post_process config value only. - boost::split(values, str, boost::is_any_of(";")); - if (values.size() == 1 && values[0] == "") - values.resize(0); - } - config.option(opt_key)->values = values; - } - else{ - ConfigOptionStrings* vec_new = new ConfigOptionStrings{ boost::any_cast(value) }; - config.option(opt_key)->set_at(vec_new, opt_index, 0); - } - } - break; - case coBool: - config.set_key_value(opt_key, new ConfigOptionBool(boost::any_cast(value))); - break; - case coBools:{ - ConfigOptionBools* vec_new = new ConfigOptionBools{ boost::any_cast(value) != 0 }; - config.option(opt_key)->set_at(vec_new, opt_index, 0); - break;} - case coInt: - config.set_key_value(opt_key, new ConfigOptionInt(boost::any_cast(value))); - break; - case coInts:{ - ConfigOptionInts* vec_new = new ConfigOptionInts{ boost::any_cast(value) }; - config.option(opt_key)->set_at(vec_new, opt_index, 0); - } - break; - case coEnum:{ - auto *opt = opt_def->default_value.get()->clone(); - opt->setInt(boost::any_cast(value)); - config.set_key_value(opt_key, opt); - } - break; - case coPoints:{ - if (opt_key == "bed_shape") { - config.option(opt_key)->values = boost::any_cast>(value); - break; - } - ConfigOptionPoints* vec_new = new ConfigOptionPoints{ boost::any_cast(value) }; - config.option(opt_key)->set_at(vec_new, opt_index, 0); - } - break; - case coNone: - break; - default: - break; - } - } - catch (const std::exception &e) - { - wxLogError(format_wxstr("Internal error when changing value for %1%: %2%", opt_key, e.what())); - } -} - void show_error(wxWindow* parent, const wxString& message, bool monospaced_font) { ErrorDialog msg(parent, message, monospaced_font); diff --git a/src/slic3r/GUI/GUI.hpp b/src/slic3r/GUI/GUI.hpp index 0239c62bcd..70abef3085 100644 --- a/src/slic3r/GUI/GUI.hpp +++ b/src/slic3r/GUI/GUI.hpp @@ -42,9 +42,6 @@ extern AppConfig* get_app_config(); extern void add_menus(wxMenuBar *menu, int event_preferences_changed, int event_language_change); -// Change option value in config -void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt_key, const boost::any& value, int opt_index = 0); - // If monospaced_font is true, the error message is displayed using html
tags, // so that the code formatting will be preserved. This is useful for reporting errors from the placeholder parser. void show_error(wxWindow* parent, const wxString& message, bool monospaced_font = false); diff --git a/src/slic3r/GUI/GUI_ObjectSettings.cpp b/src/slic3r/GUI/GUI_ObjectSettings.cpp index 5a1b1e0ceb..a54383c851 100644 --- a/src/slic3r/GUI/GUI_ObjectSettings.cpp +++ b/src/slic3r/GUI/GUI_ObjectSettings.cpp @@ -127,7 +127,7 @@ bool ObjectSettings::update_settings_list() optgroup->label_width = 15; optgroup->sidetext_width = 5; - optgroup->m_on_change = [this, config](const t_config_option_key& opt_id, const boost::any& value) { + optgroup->on_change = [this, config](const t_config_option_key& opt_id, const boost::any& value) { this->update_config_values(config); wxGetApp().obj_list()->changed_object(); }; diff --git a/src/slic3r/GUI/OptionsGroup.cpp b/src/slic3r/GUI/OptionsGroup.cpp index be5755974a..952f7b5339 100644 --- a/src/slic3r/GUI/OptionsGroup.cpp +++ b/src/slic3r/GUI/OptionsGroup.cpp @@ -138,6 +138,128 @@ OptionsGroup::OptionsGroup( wxWindow* _parent, const wxString& title, { } +// opt_index = 0, by the reason of zero-index in ConfigOptionVector by default (in case only one element) +void OptionsGroup::change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt_key, const boost::any& value, int opt_index /*= 0*/) +{ + try { + + if (config.def()->get(opt_key)->type == coBools && config.def()->get(opt_key)->nullable) { + ConfigOptionBoolsNullable* vec_new = new ConfigOptionBoolsNullable{ boost::any_cast(value) }; + config.option(opt_key)->set_at(vec_new, opt_index, 0); + return; + } + + const ConfigOptionDef* opt_def = config.def()->get(opt_key); + switch (opt_def->type) { + case coFloatOrPercent: { + std::string str = boost::any_cast(value); + bool percent = false; + if (str.back() == '%') { + str.pop_back(); + percent = true; + } + double val = std::stod(str); // locale-dependent (on purpose - the input is the actual content of the field) + config.set_key_value(opt_key, new ConfigOptionFloatOrPercent(val, percent)); + break; } + case coPercent: + config.set_key_value(opt_key, new ConfigOptionPercent(boost::any_cast(value))); + break; + case coFloat: { + double& val = config.opt_float(opt_key); + val = boost::any_cast(value); + break; + } + case coFloatsOrPercents: { + std::string str = boost::any_cast(value); + bool percent = false; + if (str.back() == '%') { + str.pop_back(); + percent = true; + } + double val = std::stod(str); // locale-dependent (on purpose - the input is the actual content of the field) + ConfigOptionFloatsOrPercents* vec_new = new ConfigOptionFloatsOrPercents({ {val, percent} }); + config.option(opt_key)->set_at(vec_new, opt_index, opt_index); + break; + } + case coPercents: { + ConfigOptionPercents* vec_new = new ConfigOptionPercents{ boost::any_cast(value) }; + config.option(opt_key)->set_at(vec_new, opt_index, opt_index); + break; + } + case coFloats: { + ConfigOptionFloats* vec_new = new ConfigOptionFloats{ boost::any_cast(value) }; + config.option(opt_key)->set_at(vec_new, opt_index, opt_index); + break; + } + case coString: + config.set_key_value(opt_key, new ConfigOptionString(boost::any_cast(value))); + break; + case coStrings: { + if (opt_key == "compatible_prints" || opt_key == "compatible_printers" || opt_key == "gcode_substitutions") { + config.option(opt_key)->values = + boost::any_cast>(value); + } + else if (config.def()->get(opt_key)->gui_flags.compare("serialized") == 0) { + std::string str = boost::any_cast(value); + std::vector values{}; + if (!str.empty()) { + if (str.back() == ';') str.pop_back(); + // Split a string to multiple strings by a semi - colon.This is the old way of storing multi - string values. + // Currently used for the post_process config value only. + boost::split(values, str, boost::is_any_of(";")); + if (values.size() == 1 && values[0] == "") + values.resize(0); + } + config.option(opt_key)->values = values; + } + else { + ConfigOptionStrings* vec_new = new ConfigOptionStrings{ boost::any_cast(value) }; + config.option(opt_key)->set_at(vec_new, opt_index, 0); + } + } + break; + case coBool: + config.set_key_value(opt_key, new ConfigOptionBool(boost::any_cast(value))); + break; + case coBools: { + ConfigOptionBools* vec_new = new ConfigOptionBools{ boost::any_cast(value) != 0 }; + config.option(opt_key)->set_at(vec_new, opt_index, 0); + break; } + case coInt: + config.set_key_value(opt_key, new ConfigOptionInt(boost::any_cast(value))); + break; + case coInts: { + ConfigOptionInts* vec_new = new ConfigOptionInts{ boost::any_cast(value) }; + config.option(opt_key)->set_at(vec_new, opt_index, 0); + } + break; + case coEnum: { + auto* opt = opt_def->default_value.get()->clone(); + opt->setInt(boost::any_cast(value)); + config.set_key_value(opt_key, opt); + } + break; + case coPoints: { + if (opt_key == "bed_shape") { + config.option(opt_key)->values = boost::any_cast>(value); + break; + } + ConfigOptionPoints* vec_new = new ConfigOptionPoints{ boost::any_cast(value) }; + config.option(opt_key)->set_at(vec_new, opt_index, 0); + } + break; + case coNone: + break; + default: + break; + } + } + catch (const std::exception& e) + { + wxLogError(format_wxstr("Internal error when changing value for %1%: %2%", opt_key, e.what())); + } +} + Option::Option(const ConfigOptionDef& _opt, t_config_option_key id) : opt(_opt), opt_id(id) { if (!opt.tooltip.empty()) { @@ -571,8 +693,8 @@ void OptionsGroup::clear_fields_except_of(const std::vector left_fi } void OptionsGroup::on_change_OG(const t_config_option_key& opt_id, const boost::any& value) { - if (m_on_change != nullptr) - m_on_change(opt_id, value); + if (on_change != nullptr) + on_change(opt_id, value); } Option ConfigOptionsGroup::get_option(const std::string& opt_key, int opt_index /*= -1*/) @@ -614,18 +736,18 @@ void ConfigOptionsGroup::on_change_OG(const t_config_option_key& opt_id, const b void ConfigOptionsGroup::back_to_initial_value(const std::string& opt_key) { - if (m_get_initial_config == nullptr) + if (get_initial_config == nullptr) return; - back_to_config_value(m_get_initial_config(), opt_key); + back_to_config_value(get_initial_config(), opt_key); } void ConfigOptionsGroup::back_to_sys_value(const std::string& opt_key) { - if (m_get_sys_config == nullptr) + if (get_sys_config == nullptr) return; if (!have_sys_config()) return; - back_to_config_value(m_get_sys_config(), opt_key); + back_to_config_value(get_sys_config(), opt_key); } void ConfigOptionsGroup::back_to_config_value(const DynamicPrintConfig& config, const std::string& opt_key) @@ -663,8 +785,8 @@ void ConfigOptionsGroup::back_to_config_value(const DynamicPrintConfig& config, void ConfigOptionsGroup::on_kill_focus(const std::string& opt_key) { - if (m_fill_empty_value) - m_fill_empty_value(opt_key); + if (fill_empty_value) + fill_empty_value(opt_key); else reload_config(); } @@ -1012,7 +1134,7 @@ std::pair ConfigOptionsGroup::get_custom_ctrl_with_blinki void ConfigOptionsGroup::change_opt_value(const t_config_option_key& opt_key, const boost::any& value, int opt_index /*= 0*/) { - Slic3r::GUI::change_opt_value(const_cast(*m_config), opt_key, value, opt_index); + OptionsGroup::change_opt_value(const_cast(*m_config), opt_key, value, opt_index); if (m_modelconfig) m_modelconfig->touch(); } diff --git a/src/slic3r/GUI/OptionsGroup.hpp b/src/slic3r/GUI/OptionsGroup.hpp index ae500c5d32..65257334f8 100644 --- a/src/slic3r/GUI/OptionsGroup.hpp +++ b/src/slic3r/GUI/OptionsGroup.hpp @@ -122,13 +122,14 @@ public: OG_CustomCtrl* custom_ctrl{ nullptr }; int ctrl_horiz_alignment{ wxALIGN_LEFT}; column_t extra_column {nullptr}; - t_change m_on_change { nullptr }; + t_change on_change { nullptr }; // To be called when the field loses focus, to assign a new initial value to the field. // Used by the relative position / rotation / scale manipulation fields of the Object Manipulation UI. - t_kill_focus m_fill_empty_value { nullptr }; - std::function m_get_initial_config{ nullptr }; - std::function m_get_sys_config{ nullptr }; - std::function have_sys_config{ nullptr }; + t_kill_focus fill_empty_value { nullptr }; + + std::function get_initial_config{ nullptr }; + std::function get_sys_config { nullptr }; + std::function have_sys_config { nullptr }; std::function rescale_extra_column_item { nullptr }; std::function rescale_near_label_widget { nullptr }; @@ -258,6 +259,9 @@ public: static wxString get_url(const std::string& path_end); static bool launch_browser(const std::string& path_end); static bool is_option_without_field(const std::string& opt_key); + + // Change option value in config + static void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt_key, const boost::any& value, int opt_index = 0); }; class ConfigOptionsGroup: public OptionsGroup { diff --git a/src/slic3r/GUI/PhysicalPrinterDialog.cpp b/src/slic3r/GUI/PhysicalPrinterDialog.cpp index 2364c56247..69902545a3 100644 --- a/src/slic3r/GUI/PhysicalPrinterDialog.cpp +++ b/src/slic3r/GUI/PhysicalPrinterDialog.cpp @@ -281,7 +281,7 @@ void PhysicalPrinterDialog::update_printers() void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgroup) { - m_optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) { + m_optgroup->on_change = [this](t_config_option_key opt_key, boost::any value) { if (opt_key == "host_type" || opt_key == "printhost_authorization_type") this->update(); if (opt_key == "print_host") diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index c2b8e8694f..7e32b963a9 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -403,7 +403,7 @@ FreqChangedParams::FreqChangedParams(wxWindow* parent) : m_og->set_config(config); m_og->hide_labels(); - m_og->m_on_change = [config, this](t_config_option_key opt_key, boost::any value) { + m_og->on_change = [config, this](t_config_option_key opt_key, boost::any value) { Tab* tab_print = wxGetApp().get_tab(Preset::TYPE_PRINT); if (!tab_print) return; @@ -559,7 +559,7 @@ FreqChangedParams::FreqChangedParams(wxWindow* parent) : DynamicPrintConfig* config_sla = &wxGetApp().preset_bundle->sla_prints.get_edited_preset().config; m_og_sla->set_config(config_sla); - m_og_sla->m_on_change = [config_sla](t_config_option_key opt_key, boost::any value) { + m_og_sla->on_change = [config_sla](t_config_option_key opt_key, boost::any value) { Tab* tab = wxGetApp().get_tab(Preset::TYPE_SLA_PRINT); if (!tab) return; diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index f3bfe59fb2..b2643db0f1 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -272,7 +272,7 @@ void PreferencesDialog::build() // Add "General" tab m_optgroup_general = create_options_tab(L("General"), tabs); - m_optgroup_general->m_on_change = [this](t_config_option_key opt_key, boost::any value) { + m_optgroup_general->on_change = [this](t_config_option_key opt_key, boost::any value) { if (auto it = m_values.find(opt_key); it != m_values.end()) { m_values.erase(it); // we shouldn't change value, if some of those parameters were selected, and then deselected return; @@ -456,7 +456,7 @@ void PreferencesDialog::build() // Add "Camera" tab m_optgroup_camera = create_options_tab(L("Camera"), tabs); - m_optgroup_camera->m_on_change = [this](t_config_option_key opt_key, boost::any value) { + m_optgroup_camera->on_change = [this](t_config_option_key opt_key, boost::any value) { if (auto it = m_values.find(opt_key);it != m_values.end()) { m_values.erase(it); // we shouldn't change value, if some of those parameters were selected, and then deselected return; @@ -483,7 +483,7 @@ void PreferencesDialog::build() // Add "GUI" tab m_optgroup_gui = create_options_tab(L("GUI"), tabs); - m_optgroup_gui->m_on_change = [this](t_config_option_key opt_key, boost::any value) { + m_optgroup_gui->on_change = [this](t_config_option_key opt_key, boost::any value) { if (opt_key == "notify_release") { int val_int = boost::any_cast(value); for (const auto& item : s_keys_map_NotifyReleaseMode) { @@ -615,7 +615,7 @@ void PreferencesDialog::build() create_settings_mode_color_widget(); m_optgroup_other = create_options_tab(_L("Other"), tabs); - m_optgroup_other->m_on_change = [this](t_config_option_key opt_key, boost::any value) { + m_optgroup_other->on_change = [this](t_config_option_key opt_key, boost::any value) { if (auto it = m_values.find(opt_key); it != m_values.end() && opt_key != "url_downloader_dest") { m_values.erase(it); // we shouldn't change value, if some of those parameters were selected, and then deselected @@ -649,7 +649,7 @@ void PreferencesDialog::build() #if ENABLE_ENVIRONMENT_MAP // Add "Render" tab m_optgroup_render = create_options_tab(L("Render"), tabs); - m_optgroup_render->m_on_change = [this](t_config_option_key opt_key, boost::any value) { + m_optgroup_render->on_change = [this](t_config_option_key opt_key, boost::any value) { if (auto it = m_values.find(opt_key); it != m_values.end()) { m_values.erase(it); // we shouldn't change value, if some of those parameters were selected, and then deselected return; @@ -669,7 +669,7 @@ void PreferencesDialog::build() #ifdef _WIN32 // Add "Dark Mode" tab m_optgroup_dark_mode = create_options_tab(_L("Dark mode"), tabs); - m_optgroup_dark_mode->m_on_change = [this](t_config_option_key opt_key, boost::any value) { + m_optgroup_dark_mode->on_change = [this](t_config_option_key opt_key, boost::any value) { if (auto it = m_values.find(opt_key); it != m_values.end()) { m_values.erase(it); // we shouldn't change value, if some of those parameters were selected, and then deselected return; diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 6f6fb18a69..eef1cc4e51 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -1070,7 +1070,7 @@ void Tab::toggle_option(const std::string& opt_key, bool toggle, int opt_index/* // and value can be some random value because in this case it will not been used void Tab::load_key_value(const std::string& opt_key, const boost::any& value, bool saved_value /*= false*/) { - if (!saved_value) change_opt_value(*m_config, opt_key, value); + if (!saved_value) OptionsGroup::change_opt_value(*m_config, opt_key, value); // Mark the print & filament enabled if they are compatible with the currently selected preset. if (opt_key == "compatible_printers" || opt_key == "compatible_prints") { // Don't select another profile if this profile happens to become incompatible. @@ -1713,7 +1713,7 @@ void TabPrint::build() optgroup->append_single_option_line(option); optgroup->append_single_option_line("gcode_binary"); - optgroup->m_on_change = [this](const t_config_option_key& opt_key, boost::any value) + optgroup->on_change = [this](const t_config_option_key& opt_key, boost::any value) { if (opt_key == "gcode_binary") { const bool is_binary = m_config->opt_bool("gcode_binary"); @@ -2198,7 +2198,7 @@ void TabFilament::build() optgroup->append_single_option_line("filament_cost"); optgroup->append_single_option_line("filament_spool_weight"); - optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) + optgroup->on_change = [this](t_config_option_key opt_key, boost::any value) { update_dirty(); if (opt_key == "filament_spool_weight") { @@ -2327,7 +2327,7 @@ void TabFilament::build() page = add_options_page(L("Custom G-code"), "cog"); optgroup = page->new_optgroup(L("Start G-code"), 0); - optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) { + optgroup->on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) { validate_custom_gcode_cb(this, optgroup_title, opt_key, value); }; optgroup->edit_custom_gcode = [this](const t_config_option_key& opt_key) { edit_custom_gcode(opt_key); }; @@ -2338,7 +2338,7 @@ void TabFilament::build() optgroup->append_single_option_line(option); optgroup = page->new_optgroup(L("End G-code"), 0); - optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) { + optgroup->on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) { validate_custom_gcode_cb(this, optgroup_title, opt_key, value); }; optgroup->edit_custom_gcode = [this](const t_config_option_key& opt_key) { edit_custom_gcode(opt_key); }; @@ -2660,7 +2660,7 @@ void TabPrinter::build_fff() optgroup->append_single_option_line(option); optgroup->append_single_option_line("single_extruder_multi_material"); - optgroup->m_on_change = [this, optgroup_wk = ConfigOptionsGroupWkp(optgroup)](t_config_option_key opt_key, boost::any value) { + optgroup->on_change = [this, optgroup_wk = ConfigOptionsGroupWkp(optgroup)](t_config_option_key opt_key, boost::any value) { auto optgroup_sh = optgroup_wk.lock(); if (!optgroup_sh) return; @@ -2734,7 +2734,7 @@ void TabPrinter::build_fff() optgroup->append_single_option_line("silent_mode"); optgroup->append_single_option_line("remaining_times"); - optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) { + optgroup->on_change = [this](t_config_option_key opt_key, boost::any value) { wxTheApp->CallAfter([this, opt_key, value]() { if (opt_key == "thumbnails" && m_config->has("thumbnails_format")) { // to backward compatibility we need to update "thumbnails_format" from new "thumbnails" @@ -2824,7 +2824,7 @@ void TabPrinter::build_fff() const int notes_field_height = 25; // 250 page = add_options_page(L("Custom G-code"), "cog"); optgroup = page->new_optgroup(L("Start G-code"), 0); - optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) { + optgroup->on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) { validate_custom_gcode_cb(this, optgroup_title, opt_key, value); }; optgroup->edit_custom_gcode = [this](const t_config_option_key& opt_key) { edit_custom_gcode(opt_key); }; @@ -2838,7 +2838,7 @@ void TabPrinter::build_fff() optgroup->append_single_option_line("autoemit_temperature_commands"); optgroup = page->new_optgroup(L("End G-code"), 0); - optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) { + optgroup->on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) { validate_custom_gcode_cb(this, optgroup_title, opt_key, value); }; optgroup->edit_custom_gcode = [this](const t_config_option_key& opt_key) { edit_custom_gcode(opt_key); }; @@ -2849,7 +2849,7 @@ void TabPrinter::build_fff() optgroup->append_single_option_line(option); optgroup = page->new_optgroup(L("Before layer change G-code"), 0); - optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) { + optgroup->on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) { validate_custom_gcode_cb(this, optgroup_title, opt_key, value); }; optgroup->edit_custom_gcode = [this](const t_config_option_key& opt_key) { edit_custom_gcode(opt_key); }; @@ -2860,7 +2860,7 @@ void TabPrinter::build_fff() optgroup->append_single_option_line(option); optgroup = page->new_optgroup(L("After layer change G-code"), 0); - optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) { + optgroup->on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) { validate_custom_gcode_cb(this, optgroup_title, opt_key, value); }; optgroup->edit_custom_gcode = [this](const t_config_option_key& opt_key) { edit_custom_gcode(opt_key); }; @@ -2871,7 +2871,7 @@ void TabPrinter::build_fff() optgroup->append_single_option_line(option); optgroup = page->new_optgroup(L("Tool change G-code"), 0); - optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) { + optgroup->on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) { validate_custom_gcode_cb(this, optgroup_title, opt_key, value); }; optgroup->edit_custom_gcode = [this](const t_config_option_key& opt_key) { edit_custom_gcode(opt_key); }; @@ -2882,7 +2882,7 @@ void TabPrinter::build_fff() optgroup->append_single_option_line(option); optgroup = page->new_optgroup(L("Between objects G-code (for sequential printing)"), 0); - optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) { + optgroup->on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) { validate_custom_gcode_cb(this, optgroup_title, opt_key, value); }; optgroup->edit_custom_gcode = [this](const t_config_option_key& opt_key) { edit_custom_gcode(opt_key); }; @@ -2893,7 +2893,7 @@ void TabPrinter::build_fff() optgroup->append_single_option_line(option); optgroup = page->new_optgroup(L("Color Change G-code"), 0); - optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) { + optgroup->on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) { validate_custom_gcode_cb(this, optgroup_title, opt_key, value); }; optgroup->edit_custom_gcode = [this](const t_config_option_key& opt_key) { edit_custom_gcode(opt_key); }; @@ -2903,7 +2903,7 @@ void TabPrinter::build_fff() optgroup->append_single_option_line(option); optgroup = page->new_optgroup(L("Pause Print G-code"), 0); - optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) { + optgroup->on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) { validate_custom_gcode_cb(this, optgroup_title, opt_key, value); }; optgroup->edit_custom_gcode = [this](const t_config_option_key& opt_key) { edit_custom_gcode(opt_key); }; @@ -2913,7 +2913,7 @@ void TabPrinter::build_fff() optgroup->append_single_option_line(option); optgroup = page->new_optgroup(L("Template Custom G-code"), 0); - optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) { + optgroup->on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) { validate_custom_gcode_cb(this, optgroup_title, opt_key, value); }; optgroup->edit_custom_gcode = [this](const t_config_option_key& opt_key) { edit_custom_gcode(opt_key); }; @@ -3070,7 +3070,7 @@ PageShp TabPrinter::build_kinematics_page() optgroup->append_line(line); } - optgroup->m_on_change = [this](const t_config_option_key& opt_key, boost::any value) + optgroup->on_change = [this](const t_config_option_key& opt_key, boost::any value) { if (opt_key == "machine_limits_usage" && static_cast(boost::any_cast(value)) == MachineLimitsUsage::EmitToGCode && @@ -3164,7 +3164,7 @@ void TabPrinter::build_extruder_pages(size_t n_before_extruders) auto optgroup = page->new_optgroup(L("Size")); optgroup->append_single_option_line("nozzle_diameter", "", extruder_idx); - optgroup->m_on_change = [this, extruder_idx](const t_config_option_key&opt_key, boost::any value) + optgroup->on_change = [this, extruder_idx](const t_config_option_key&opt_key, boost::any value) { const bool is_single_extruder_MM = m_config->opt_bool("single_extruder_multi_material"); const bool is_nozzle_diameter_changed = opt_key.find_first_of("nozzle_diameter") != std::string::npos; @@ -5254,33 +5254,27 @@ ConfigOptionsGroupShp Page::new_optgroup(const wxString& title, int noncommon_la optgroup->label_width = noncommon_label_width; #ifdef __WXOSX__ - auto tab = parent()->GetParent()->GetParent();// GetParent()->GetParent(); + Tab* tab = static_cast(parent()->GetParent()->GetParent()); #else - auto tab = parent()->GetParent();// GetParent(); + Tab* tab = static_cast(parent()->GetParent()); #endif optgroup->set_config_category_and_type(m_title, static_cast(tab)->type()); - optgroup->m_on_change = [tab](t_config_option_key opt_key, boost::any value) { - //! This function will be called from OptionGroup. - //! Using of CallAfter is redundant. - //! And in some cases it causes update() function to be recalled again -//! wxTheApp->CallAfter([this, opt_key, value]() { - static_cast(tab)->update_dirty(); - static_cast(tab)->on_value_change(opt_key, value); -//! }); + optgroup->on_change = [tab](t_config_option_key opt_key, boost::any value) { + // This function will be called from OptionGroup. + tab->update_dirty(); + tab->on_value_change(opt_key, value); }; - optgroup->m_get_initial_config = [tab]() { - DynamicPrintConfig config = static_cast(tab)->m_presets->get_selected_preset().config; - return config; + optgroup->get_initial_config = [tab]() { + return tab->m_presets->get_selected_preset().config; }; - optgroup->m_get_sys_config = [tab]() { - DynamicPrintConfig config = static_cast(tab)->m_presets->get_selected_preset_parent()->config; - return config; + optgroup->get_sys_config = [tab]() { + return tab->m_presets->get_selected_preset_parent()->config; }; optgroup->have_sys_config = [tab]() { - return static_cast(tab)->m_presets->get_selected_preset_parent() != nullptr; + return tab->m_presets->get_selected_preset_parent() != nullptr; }; optgroup->rescale_extra_column_item = [](wxWindow* win) { @@ -5320,7 +5314,7 @@ void TabSLAMaterial::build() optgroup->append_single_option_line("bottle_weight"); optgroup->append_single_option_line("material_density"); - optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) + optgroup->on_change = [this](t_config_option_key opt_key, boost::any value) { if (opt_key == "material_colour") { update_dirty();