diff --git a/xs/src/slic3r/GUI/GUI.cpp b/xs/src/slic3r/GUI/GUI.cpp index 1079aa9b0..a0b1bbd09 100644 --- a/xs/src/slic3r/GUI/GUI.cpp +++ b/xs/src/slic3r/GUI/GUI.cpp @@ -464,9 +464,8 @@ void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, b } break; case coPoints:{ - ConfigOptionPoints points; - points.values = boost::any_cast>(value); - config.set_key_value(opt_key, new ConfigOptionPoints(points)); + ConfigOptionPoints* vec_new = new ConfigOptionPoints{ boost::any_cast(value) }; + config.option(opt_key)->set_at(vec_new, opt_index, 0); } break; case coNone: diff --git a/xs/src/slic3r/GUI/OptionsGroup.cpp b/xs/src/slic3r/GUI/OptionsGroup.cpp index dfa3ba3b2..0be24824c 100644 --- a/xs/src/slic3r/GUI/OptionsGroup.cpp +++ b/xs/src/slic3r/GUI/OptionsGroup.cpp @@ -293,6 +293,13 @@ void ConfigOptionsGroup::back_to_initial_value(const std::string opt_key) auto *nozzle_diameter = dynamic_cast(config.option("nozzle_diameter")); value = int(nozzle_diameter->values.size()); } + else if (m_opt_map.find(opt_key) != m_opt_map.end()) + { + auto opt_id = m_opt_map.find(opt_key)->first; + std::string opt_short_key = m_opt_map.at(opt_id).first; + int opt_index = m_opt_map.at(opt_id).second; + value = get_config_value(config, opt_short_key, opt_index); + } else value = get_config_value(config, opt_key); @@ -360,7 +367,7 @@ boost::any ConfigOptionsGroup::get_config_value(DynamicPrintConfig& config, std: double val = opt->type == coFloats ? config.opt_float(opt_key, idx) : opt->type == coFloat ? config.opt_float(opt_key) : - config.option(opt_key)->values.at(idx); + config.option(opt_key)->get_at(idx); ret = double_to_string(val); } break; @@ -406,10 +413,8 @@ boost::any ConfigOptionsGroup::get_config_value(DynamicPrintConfig& config, std: ret = static_cast(config.option>(opt_key)->value); } break; - case coPoints:{ - const auto &value = *config.option(opt_key); - ret = value.values.at(idx); - } + case coPoints: + ret = config.option(opt_key)->get_at(idx); break; case coNone: default: diff --git a/xs/src/slic3r/GUI/Tab.cpp b/xs/src/slic3r/GUI/Tab.cpp index d9f64f120..1a4dadd72 100644 --- a/xs/src/slic3r/GUI/Tab.cpp +++ b/xs/src/slic3r/GUI/Tab.cpp @@ -138,28 +138,62 @@ PageShp Tab::add_options_page(wxString title, std::string icon, bool is_extruder return page; } +template +void add_correct_opts_to_dirty_options(const std::string &opt_key, std::vector *vec, TabPrinter *tab) +{ + auto opt_init = static_cast(tab->m_presets->get_selected_preset().config.option(opt_key)); + auto opt_cur = static_cast(tab->m_config->option(opt_key)); + int opt_init_max_id = opt_init->values.size()-1; + for (int i = 0; i < opt_cur->values.size(); i++) + { + int init_id = i <= opt_init_max_id ? i : 0; + if (opt_cur->values[i] != opt_init->values[init_id]) + vec->emplace_back(opt_key + "#" + std::to_string(i)); + } +} + // Update the combo box label of the selected preset based on its "dirty" state, // comparing the selected preset config with $self->{config}. void Tab::update_dirty(){ m_presets->update_dirty_ui(m_presets_choice); on_presets_changed(); + + // Update UI according to changes auto dirty_options = m_presets->current_dirty_options(); - bool change_extruder_data = false; - if (name() == "printer"){ - TabPrinter* tab_printer = static_cast(this); - if (tab_printer->m_initial_extruders_count != tab_printer->m_extruders_count){ + // Update dirty_options in case changes of Extruder's options + TabPrinter* tab = static_cast(this); + std::vector new_dirty; + for (auto opt_key : dirty_options) + { + switch (m_config->option(opt_key)->type()) + { + case coInts: add_correct_opts_to_dirty_options(opt_key, &new_dirty, tab); break; + case coBools: add_correct_opts_to_dirty_options(opt_key, &new_dirty, tab); break; + case coFloats: add_correct_opts_to_dirty_options(opt_key, &new_dirty, tab); break; + case coStrings: add_correct_opts_to_dirty_options(opt_key, &new_dirty, tab); break; + case coPercents:add_correct_opts_to_dirty_options(opt_key, &new_dirty, tab); break; + case coPoints: add_correct_opts_to_dirty_options(opt_key, &new_dirty, tab); break; + default: new_dirty.emplace_back(opt_key); break; + } + } + + dirty_options.resize(0); + dirty_options = new_dirty; + if (tab->m_initial_extruders_count != tab->m_extruders_count){ dirty_options.emplace_back("extruders_count"); - change_extruder_data = true; } } + // Add new dirty options to m_dirty_options for (auto opt_key : dirty_options){ - Field* field = get_field(opt_key/*, opt_index*/); + Field* field = get_field(opt_key); if (field != nullptr && find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) == m_dirty_options.end()){ - if (field->m_Label != nullptr) + if (field->m_Label != nullptr){ field->m_Label->SetForegroundColour(*get_modified_label_clr()); + field->m_Label->Refresh(true); + } field->m_Undo_btn->SetBitmap(wxBitmap(from_u8(wxMSW ? var("action_undo.png") : var("arrow_undo.png")), wxBITMAP_TYPE_PNG)); field->m_is_modified_value = true; @@ -168,16 +202,17 @@ void Tab::update_dirty(){ } // Delete undirty options from m_dirty_options - size_t cnt = m_dirty_options.size(); for (auto i = 0; i < m_dirty_options.size(); ++i) { const std::string &opt_key = m_dirty_options[i]; - Field* field = get_field(opt_key/*, opt_index*/); + Field* field = get_field(opt_key); if (field != nullptr && find(dirty_options.begin(), dirty_options.end(), opt_key) == dirty_options.end()) { field->m_Undo_btn->SetBitmap(wxBitmap(from_u8(var("Bullet_white.png")), wxBITMAP_TYPE_PNG)); - if (field->m_Label != nullptr) + if (field->m_Label != nullptr){ field->m_Label->SetForegroundColour(wxSYS_COLOUR_WINDOWTEXT); + field->m_Label->Refresh(true); + } field->m_is_modified_value = false; std::vector::iterator itr = find(m_dirty_options.begin(), m_dirty_options.end(), opt_key); if (itr != m_dirty_options.end()){ @@ -271,7 +306,6 @@ void Tab::load_config(DynamicPrintConfig config) } change_opt_value(*m_config, opt_key, value, opt_index); modified = 1; -// get_field(opt_key)->m_Label->SetBackgroundColour(*get_modified_label_clr()); } if (modified) { update_dirty();