Merge remote-tracking branch 'remotes/origin/gui_change_extruders_color'

This commit is contained in:
bubnikv 2018-03-05 11:47:13 +01:00
commit 91b5853aa3
2 changed files with 24 additions and 13 deletions

View file

@ -407,7 +407,7 @@ void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, b
} }
case coPercents: case coPercents:
case coFloats:{ case coFloats:{
double& val = config.opt_float(opt_key, 0); double& val = config.opt_float(opt_key, opt_index);
val = boost::any_cast<double>(value); val = boost::any_cast<double>(value);
break; break;
} }
@ -422,7 +422,7 @@ void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, b
} }
else{ else{
ConfigOptionStrings* vec_new = new ConfigOptionStrings{ boost::any_cast<std::string>(value) }; ConfigOptionStrings* vec_new = new ConfigOptionStrings{ boost::any_cast<std::string>(value) };
config.option<ConfigOptionStrings>(opt_key)->set_at(vec_new, opt_index, opt_index); config.option<ConfigOptionStrings>(opt_key)->set_at(vec_new, opt_index, 0);
} }
} }
break; break;
@ -431,14 +431,14 @@ void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, b
break; break;
case coBools:{ case coBools:{
ConfigOptionBools* vec_new = new ConfigOptionBools{ boost::any_cast<bool>(value) }; ConfigOptionBools* vec_new = new ConfigOptionBools{ boost::any_cast<bool>(value) };
config.option<ConfigOptionBools>(opt_key)->set_at(vec_new, opt_index, opt_index); config.option<ConfigOptionBools>(opt_key)->set_at(vec_new, opt_index, 0);
break;} break;}
case coInt: case coInt:
config.set_key_value(opt_key, new ConfigOptionInt(boost::any_cast<int>(value))); config.set_key_value(opt_key, new ConfigOptionInt(boost::any_cast<int>(value)));
break; break;
case coInts:{ case coInts:{
ConfigOptionInts* vec_new = new ConfigOptionInts{ boost::any_cast<int>(value) }; ConfigOptionInts* vec_new = new ConfigOptionInts{ boost::any_cast<int>(value) };
config.option<ConfigOptionInts>(opt_key)->set_at(vec_new, opt_index, opt_index); config.option<ConfigOptionInts>(opt_key)->set_at(vec_new, opt_index, 0);
} }
break; break;
case coEnum:{ case coEnum:{

View file

@ -147,12 +147,25 @@ void Tab::update_tab_ui()
m_presets->update_tab_ui(m_presets_choice, m_show_incompatible_presets); m_presets->update_tab_ui(m_presets_choice, m_show_incompatible_presets);
} }
template<class T>
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<T>(opt_key)->values.size(); i++)
if (config_new.option<T>(opt_key)->values[i] !=
config_old.option<T>(opt_key)->values[i]){
index = i;
break;
}
return config_new.option<T>(opt_key)->values[index];
}
// Load a provied DynamicConfig into the tab, modifying the active preset. // 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. // 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) void Tab::load_config(DynamicPrintConfig config)
{ {
bool modified = 0; bool modified = 0;
boost::any value; boost::any value;
int opt_index = 0;
for(auto opt_key : m_config->diff(config)) { for(auto opt_key : m_config->diff(config)) {
switch ( config.def()->get(opt_key)->type ){ switch ( config.def()->get(opt_key)->type ){
case coFloatOrPercent: case coFloatOrPercent:
@ -168,28 +181,26 @@ void Tab::load_config(DynamicPrintConfig config)
value = config.opt_string(opt_key); value = config.opt_string(opt_key);
break; break;
case coPercents: case coPercents:
value = config.option<ConfigOptionPercents>(opt_key)->values.at(0); value = get_new_value<ConfigOptionPercents>(config, *m_config, opt_key, opt_index);
break; break;
case coFloats: case coFloats:
value = config.opt_float(opt_key, 0); value = get_new_value<ConfigOptionFloats>(config, *m_config, opt_key, opt_index);
break; break;
case coStrings: case coStrings:
if (config.option<ConfigOptionStrings>(opt_key)->values.empty()) value = config.option<ConfigOptionStrings>(opt_key)->values.empty() ? "" :
value = ""; get_new_value<ConfigOptionStrings>(config, *m_config, opt_key, opt_index);
else
value = config.opt_string(opt_key, static_cast<unsigned int>(0));
break; break;
case coBool: case coBool:
value = config.opt_bool(opt_key); value = config.opt_bool(opt_key);
break; break;
case coBools: case coBools:
value = config.opt_bool(opt_key, 0); value = get_new_value<ConfigOptionBools>(config, *m_config, opt_key, opt_index);
break; break;
case coInt: case coInt:
value = config.opt_int(opt_key); value = config.opt_int(opt_key);
break; break;
case coInts: case coInts:
value = config.opt_int(opt_key, 0); value = get_new_value<ConfigOptionInts>(config, *m_config, opt_key, opt_index);
break; break;
case coEnum:{ case coEnum:{
if (opt_key.compare("external_fill_pattern") == 0 || if (opt_key.compare("external_fill_pattern") == 0 ||
@ -210,7 +221,7 @@ void Tab::load_config(DynamicPrintConfig config)
default: default:
break; break;
} }
change_opt_value(*m_config, opt_key, value); change_opt_value(*m_config, opt_key, value, opt_index);
modified = 1; modified = 1;
} }
if (modified) { if (modified) {