From 2a378f65907ed523aa125de0073ed3b632f4047f Mon Sep 17 00:00:00 2001 From: YuSanka Date: Fri, 2 Mar 2018 13:41:37 +0100 Subject: [PATCH 1/2] Fixed problem with changing extruders color --- xs/src/slic3r/GUI/GUI.cpp | 8 ++--- xs/src/slic3r/GUI/Tab.cpp | 61 +++++++++++++++++++++++++++++++-------- 2 files changed, 53 insertions(+), 16 deletions(-) diff --git a/xs/src/slic3r/GUI/GUI.cpp b/xs/src/slic3r/GUI/GUI.cpp index b0d3f7629..d96247113 100644 --- a/xs/src/slic3r/GUI/GUI.cpp +++ b/xs/src/slic3r/GUI/GUI.cpp @@ -407,7 +407,7 @@ void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, b } case coPercents: case coFloats:{ - double& val = config.opt_float(opt_key, 0); + double& val = config.opt_float(opt_key, opt_index); val = boost::any_cast(value); break; } @@ -422,7 +422,7 @@ void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, b } else{ ConfigOptionStrings* vec_new = new ConfigOptionStrings{ boost::any_cast(value) }; - config.option(opt_key)->set_at(vec_new, opt_index, opt_index); + config.option(opt_key)->set_at(vec_new, opt_index, 0); } } break; @@ -431,14 +431,14 @@ void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, b break; case coBools:{ ConfigOptionBools* vec_new = new ConfigOptionBools{ boost::any_cast(value) }; - config.option(opt_key)->set_at(vec_new, opt_index, opt_index); + 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, opt_index); + config.option(opt_key)->set_at(vec_new, opt_index, 0); } break; case coEnum:{ diff --git a/xs/src/slic3r/GUI/Tab.cpp b/xs/src/slic3r/GUI/Tab.cpp index 00c749ce3..785a6c165 100644 --- a/xs/src/slic3r/GUI/Tab.cpp +++ b/xs/src/slic3r/GUI/Tab.cpp @@ -153,6 +153,7 @@ void Tab::load_config(DynamicPrintConfig config) { bool modified = 0; boost::any value; + int opt_index = 0; for(auto opt_key : m_config->diff(config)) { switch ( config.def()->get(opt_key)->type ){ case coFloatOrPercent: @@ -167,29 +168,65 @@ void Tab::load_config(DynamicPrintConfig config) case coString: value = config.opt_string(opt_key); break; - case coPercents: - value = config.option(opt_key)->values.at(0); + case coPercents:{ + for (int i = 0; i < config.option(opt_key)->values.size(); i++) + if (config.option(opt_key)->values[i] != + m_config->option(opt_key)->values[i]){ + value = config.option(opt_key)->values[i]; + opt_index = i; + break; + } + } break; - case coFloats: - value = config.opt_float(opt_key, 0); + case coFloats:{ + for (int i = 0; i < config.option(opt_key)->values.size(); i++) + if (config.option(opt_key)->values[i] != + m_config->option(opt_key)->values[i]){ + value = config.option(opt_key)->values[i]; + opt_index = i; + break; + } + } break; - case coStrings: + case coStrings:{ if (config.option(opt_key)->values.empty()) value = ""; - else - value = config.opt_string(opt_key, static_cast(0)); + else{ + for (int i = 0; i < config.option(opt_key)->values.size(); i++) + if (config.option(opt_key)->values[i] != + m_config->option(opt_key)->values[i]){ + value = config.option(opt_key)->values[i]; + opt_index = i; + break; + } + } + } break; case coBool: value = config.opt_bool(opt_key); break; - case coBools: - value = config.opt_bool(opt_key, 0); + case coBools:{ + for (int i = 0; i < config.option(opt_key)->values.size(); i++) + if (config.option(opt_key)->values[i] != + m_config->option(opt_key)->values[i]){ + value = config.option(opt_key)->values[i]; + opt_index = i; + break; + } + } break; case coInt: value = config.opt_int(opt_key); break; - case coInts: - value = config.opt_int(opt_key, 0); + case coInts:{ + for (int i = 0; i < config.option(opt_key)->values.size(); i++) + if (config.option(opt_key)->values[i] != + m_config->option(opt_key)->values[i]){ + value = config.option(opt_key)->values[i]; + opt_index = i; + break; + } + } break; case coEnum:{ if (opt_key.compare("external_fill_pattern") == 0 || @@ -210,7 +247,7 @@ void Tab::load_config(DynamicPrintConfig config) default: break; } - change_opt_value(*m_config, opt_key, value); + change_opt_value(*m_config, opt_key, value, opt_index); modified = 1; } if (modified) { From f750abb9db5c4d5105adb31343f4932f9076db7b Mon Sep 17 00:00:00 2001 From: YuSanka Date: Sun, 4 Mar 2018 15:21:01 +0100 Subject: [PATCH 2/2] Refactor load_config() function --- xs/src/slic3r/GUI/Tab.cpp | 72 +++++++++++++-------------------------- 1 file changed, 23 insertions(+), 49 deletions(-) diff --git a/xs/src/slic3r/GUI/Tab.cpp b/xs/src/slic3r/GUI/Tab.cpp index 785a6c165..d93f09b02 100644 --- a/xs/src/slic3r/GUI/Tab.cpp +++ b/xs/src/slic3r/GUI/Tab.cpp @@ -147,6 +147,18 @@ void Tab::update_tab_ui() m_presets->update_tab_ui(m_presets_choice, m_show_incompatible_presets); } +template +boost::any get_new_value(const DynamicPrintConfig &config_new, const DynamicPrintConfig &config_old, std::string opt_key, int &index) +{ + for (int i = 0; i < config_new.option(opt_key)->values.size(); i++) + if (config_new.option(opt_key)->values[i] != + config_old.option(opt_key)->values[i]){ + index = i; + break; + } + return config_new.option(opt_key)->values[index]; +} + // Load a provied DynamicConfig into the tab, modifying the active preset. // This could be used for example by setting a Wipe Tower position by interactive manipulation in the 3D view. void Tab::load_config(DynamicPrintConfig config) @@ -168,65 +180,27 @@ void Tab::load_config(DynamicPrintConfig config) case coString: value = config.opt_string(opt_key); break; - case coPercents:{ - for (int i = 0; i < config.option(opt_key)->values.size(); i++) - if (config.option(opt_key)->values[i] != - m_config->option(opt_key)->values[i]){ - value = config.option(opt_key)->values[i]; - opt_index = i; - break; - } - } + case coPercents: + value = get_new_value(config, *m_config, opt_key, opt_index); break; - case coFloats:{ - for (int i = 0; i < config.option(opt_key)->values.size(); i++) - if (config.option(opt_key)->values[i] != - m_config->option(opt_key)->values[i]){ - value = config.option(opt_key)->values[i]; - opt_index = i; - break; - } - } + case coFloats: + value = get_new_value(config, *m_config, opt_key, opt_index); break; - case coStrings:{ - if (config.option(opt_key)->values.empty()) - value = ""; - else{ - for (int i = 0; i < config.option(opt_key)->values.size(); i++) - if (config.option(opt_key)->values[i] != - m_config->option(opt_key)->values[i]){ - value = config.option(opt_key)->values[i]; - opt_index = i; - break; - } - } - } + case coStrings: + value = config.option(opt_key)->values.empty() ? "" : + get_new_value(config, *m_config, opt_key, opt_index); break; case coBool: value = config.opt_bool(opt_key); break; - case coBools:{ - for (int i = 0; i < config.option(opt_key)->values.size(); i++) - if (config.option(opt_key)->values[i] != - m_config->option(opt_key)->values[i]){ - value = config.option(opt_key)->values[i]; - opt_index = i; - break; - } - } + case coBools: + value = get_new_value(config, *m_config, opt_key, opt_index); break; case coInt: value = config.opt_int(opt_key); break; - case coInts:{ - for (int i = 0; i < config.option(opt_key)->values.size(); i++) - if (config.option(opt_key)->values[i] != - m_config->option(opt_key)->values[i]){ - value = config.option(opt_key)->values[i]; - opt_index = i; - break; - } - } + case coInts: + value = get_new_value(config, *m_config, opt_key, opt_index); break; case coEnum:{ if (opt_key.compare("external_fill_pattern") == 0 ||