From e7edb512b81abab0ea9188a55d44c181a42fefee Mon Sep 17 00:00:00 2001 From: YuSanka Date: Fri, 23 Mar 2018 17:27:43 +0100 Subject: [PATCH] Saved bed_shape changes. *code review --- xs/src/slic3r/GUI/BedShapeDialog.cpp | 3 +- xs/src/slic3r/GUI/GUI.cpp | 7 +- xs/src/slic3r/GUI/OptionsGroup.cpp | 10 ++- xs/src/slic3r/GUI/Tab.cpp | 124 ++++++++++++--------------- 4 files changed, 71 insertions(+), 73 deletions(-) diff --git a/xs/src/slic3r/GUI/BedShapeDialog.cpp b/xs/src/slic3r/GUI/BedShapeDialog.cpp index 51dbd6a272..24d84a7df7 100644 --- a/xs/src/slic3r/GUI/BedShapeDialog.cpp +++ b/xs/src/slic3r/GUI/BedShapeDialog.cpp @@ -183,7 +183,8 @@ void BedShapePanel::set_shape(ConfigOptionPoints* points) vertex_distances.push_back(distance); avg_dist += distance; } - + + avg_dist /= vertex_distances.size(); bool defined_value = true; for (auto el: vertex_distances) { diff --git a/xs/src/slic3r/GUI/GUI.cpp b/xs/src/slic3r/GUI/GUI.cpp index 4dea4965a5..7e0296121d 100644 --- a/xs/src/slic3r/GUI/GUI.cpp +++ b/xs/src/slic3r/GUI/GUI.cpp @@ -428,8 +428,7 @@ void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, b std::vector values = boost::any_cast>(value); if (values.size() == 1 && values[0] == "") break; - for (auto el : values) - config.option(opt_key)->values.push_back(el); + config.option(opt_key)->values = values; } else{ ConfigOptionStrings* vec_new = new ConfigOptionStrings{ boost::any_cast(value) }; @@ -465,6 +464,10 @@ void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, b } break; case coPoints:{ + if (opt_key.compare("bed_shape") == 0){ + 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); } diff --git a/xs/src/slic3r/GUI/OptionsGroup.cpp b/xs/src/slic3r/GUI/OptionsGroup.cpp index 2c055c9dd5..24e1ddf2eb 100644 --- a/xs/src/slic3r/GUI/OptionsGroup.cpp +++ b/xs/src/slic3r/GUI/OptionsGroup.cpp @@ -327,8 +327,11 @@ void ConfigOptionsGroup::back_to_config_value(const DynamicPrintConfig& config, int opt_index = m_opt_map.at(opt_id).second; value = get_config_value(config, opt_short_key, opt_index); } - else + else{ value = get_config_value(config, opt_key); + change_opt_value(*m_config, opt_key, value); + return; + } set_value(opt_key, value); on_change_OG(opt_key, get_value(opt_key)); @@ -442,7 +445,10 @@ boost::any ConfigOptionsGroup::get_config_value(const DynamicPrintConfig& config } break; case coPoints: - ret = config.option(opt_key)->get_at(idx); + if (opt_key.compare("bed_shape") == 0) + ret = config.option(opt_key)->values; + else + 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 e15ffa8c2c..babff7d801 100644 --- a/xs/src/slic3r/GUI/Tab.cpp +++ b/xs/src/slic3r/GUI/Tab.cpp @@ -203,31 +203,34 @@ void Tab::update_changed_ui() if (name() == "printer"){ // Update dirty_options in case changes of Extruder's options TabPrinter* tab = static_cast(this); - std::vector new_options; + m_dirty_options.resize(0); for (auto opt_key : dirty_options) { + if (opt_key == "bed_shape"){ m_dirty_options.emplace_back(opt_key); continue; } switch (m_config->option(opt_key)->type()) { - case coInts: add_correct_opts_to_dirty_options(opt_key, &new_options, tab); break; - case coBools: add_correct_opts_to_dirty_options(opt_key, &new_options, tab); break; - case coFloats: add_correct_opts_to_dirty_options(opt_key, &new_options, tab); break; - case coStrings: add_correct_opts_to_dirty_options(opt_key, &new_options, tab); break; - case coPercents:add_correct_opts_to_dirty_options(opt_key, &new_options, tab); break; - case coPoints: add_correct_opts_to_dirty_options(opt_key, &new_options, tab); break; - default: new_options.emplace_back(opt_key); break; + case coInts: add_correct_opts_to_dirty_options(opt_key, &m_dirty_options, tab); break; + case coBools: add_correct_opts_to_dirty_options(opt_key, &m_dirty_options, tab); break; + case coFloats: add_correct_opts_to_dirty_options(opt_key, &m_dirty_options, tab); break; + case coStrings: add_correct_opts_to_dirty_options(opt_key, &m_dirty_options, tab); break; + case coPercents:add_correct_opts_to_dirty_options(opt_key, &m_dirty_options, tab); break; + case coPoints: add_correct_opts_to_dirty_options(opt_key, &m_dirty_options, tab); break; + default: m_dirty_options.emplace_back(opt_key); break; } } - dirty_options.resize(0); - dirty_options = new_options; if (tab->m_initial_extruders_count != tab->m_extruders_count) - dirty_options.emplace_back("extruders_count"); + m_dirty_options.emplace_back("extruders_count"); m_sys_options.resize(0); const auto sys_preset = m_presets->get_selected_preset_parent(); if (sys_preset){ for (auto opt_key : m_config->keys()) { - if (opt_key == "bed_shape"){ m_sys_options.emplace_back(opt_key); continue; } + if (opt_key == "bed_shape"){ + if (*tab->m_config->option(opt_key) == *sys_preset->config.option(opt_key)) + m_sys_options.emplace_back(opt_key); + continue; + } switch (m_config->option(opt_key)->type()) { case coInts: add_correct_opts_to_sys_options(opt_key, &m_sys_options, tab); break; @@ -250,67 +253,38 @@ void Tab::update_changed_ui() m_sys_options.emplace_back("extruders_count"); } } - else + else{ m_sys_options = m_presets->system_equal_options(); - - // Add new dirty options to m_dirty_options - for (auto opt_key : dirty_options){ - Field* field = get_field(opt_key); - if (field != nullptr && - find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) == m_dirty_options.end()){ - // use bouth of temporary_icons till don't have "undo_icon" - 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; - - m_dirty_options.push_back(opt_key); - } - - if (field != nullptr && field->m_Label != nullptr){ - field->m_Label->SetForegroundColour(*get_modified_label_clr()); - field->m_Label->Refresh(true); - } + m_dirty_options = dirty_options; } - // Delete clear options from m_dirty_options - 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); - 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){ - 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()){ - m_dirty_options.erase(itr); - --i; - } - } - } - - //update system options (colored in green) + //update options "decoration" for (const auto opt_key : m_full_options_list) { - Field* field = get_field(opt_key); - if (field == nullptr) continue; - std::string icon = wxMSW ? "sys_lock.png" : "lock.png"; + bool is_nonsys_value = false; + bool is_modified_value = true; + std::string sys_icon = wxMSW ? "sys_lock.png" : "lock.png"; + std::string icon = wxMSW ? "action_undo.png" : "arrow_undo.png"; wxColour& color = *get_sys_label_clr(); - if (find(m_sys_options.begin(), m_sys_options.end(), opt_key) != m_sys_options.end()) { - field->m_is_nonsys_value = false; - } - else { - field->m_is_nonsys_value = true; - icon = m_nonsys_btn_icon; + if (find(m_sys_options.begin(), m_sys_options.end(), opt_key) == m_sys_options.end()) { + is_nonsys_value = true; + sys_icon = m_nonsys_btn_icon; if(find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) == m_dirty_options.end()) color = wxSYS_COLOUR_WINDOWTEXT; else color = *get_modified_label_clr(); } - field->m_Undo_to_sys_btn->SetBitmap(wxBitmap(from_u8(var(icon)), wxBITMAP_TYPE_PNG)); + if (find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) == m_dirty_options.end()) + { + is_modified_value = false; + icon = "bullet_white.png"; + } + Field* field = get_field(opt_key); + if (field == nullptr) continue; + field->m_is_nonsys_value = is_nonsys_value; + field->m_is_modified_value = is_modified_value; + field->m_Undo_btn->SetBitmap(wxBitmap(from_u8(var(icon)), wxBITMAP_TYPE_PNG)); + field->m_Undo_to_sys_btn->SetBitmap(wxBitmap(from_u8(var(sys_icon)), wxBITMAP_TYPE_PNG)); if (field->m_Label != nullptr){ field->m_Label->SetForegroundColour(color); field->m_Label->Refresh(true); @@ -391,10 +365,13 @@ void Tab::update_changed_tree_ui() bool sys_page = true; bool modified_page = false; if (title == _("General")){ - if (sys_page && find(m_sys_options.begin(), m_sys_options.end(), "extruders_count") == m_sys_options.end()) - sys_page = false; - if (!modified_page && find(m_dirty_options.begin(), m_dirty_options.end(), "extruders_count") != m_dirty_options.end()) - modified_page = true; + std::initializer_list optional_keys{ "extruders_count", "bed_shape" }; + for (auto &opt_key : optional_keys) { + if (sys_page && find(m_sys_options.begin(), m_sys_options.end(), opt_key) == m_sys_options.end()) + sys_page = false; + if (!modified_page && find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) != m_dirty_options.end()) + modified_page = true; + } } for (auto group : page->m_optgroups) { @@ -453,6 +430,10 @@ void Tab::on_back_to_initial_value() if (find(m_dirty_options.begin(), m_dirty_options.end(), "extruders_count") != m_dirty_options.end()) group->back_to_initial_value("extruders_count"); } + if (group->title == _("Size and coordinates")){ + if (find(m_dirty_options.begin(), m_dirty_options.end(), "bed_shape") != m_dirty_options.end()) + group->back_to_initial_value("bed_shape"); + } for (t_opt_map::iterator it = group->m_opt_map.begin(); it != group->m_opt_map.end(); ++it) { const std::string& opt_key = it->first; if (find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) != m_dirty_options.end()) @@ -461,7 +442,7 @@ void Tab::on_back_to_initial_value() } break; } - + update_changed_ui(); } void Tab::on_back_to_sys_value() @@ -476,6 +457,10 @@ void Tab::on_back_to_sys_value() if (find(m_sys_options.begin(), m_sys_options.end(), "extruders_count") == m_sys_options.end()) group->back_to_sys_value("extruders_count"); } + if (group->title == _("Size and coordinates")){ + if (find(m_sys_options.begin(), m_sys_options.end(), "bed_shape") == m_sys_options.end()) + group->back_to_sys_value("bed_shape"); + } for (t_opt_map::iterator it = group->m_opt_map.begin(); it != group->m_opt_map.end(); ++it) { const std::string& opt_key = it->first; if (find(m_sys_options.begin(), m_sys_options.end(), opt_key) == m_sys_options.end()) @@ -484,6 +469,7 @@ void Tab::on_back_to_sys_value() } break; } + update_changed_ui(); } // Update the combo box label of the selected preset based on its "dirty" state, @@ -1313,8 +1299,10 @@ void TabPrinter::build() { auto dlg = new BedShapeDialog(this); dlg->build_dialog(m_config->option("bed_shape")); - if (dlg->ShowModal() == wxID_OK) + if (dlg->ShowModal() == wxID_OK){ load_key_value("bed_shape", dlg->GetValue()); + update_changed_ui(); + } })); return sizer;