From 908c48ae6a1950eec1cf76840a06ee84e83ea155 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 1 Mar 2021 13:03:43 +0100 Subject: [PATCH] Follow-up of 86d7e1fb907d9841a1d0cf516415fea84e8b5280 -> Fixed update after switching tab after editing custom g-code in settings tabs --- src/slic3r/GUI/MainFrame.cpp | 5 ++--- src/slic3r/GUI/Tab.cpp | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 91357ff6c..6b0dd1ad5 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -549,9 +549,8 @@ void MainFrame::init_tabpanel() wxWindow* panel = m_tabpanel->GetCurrentPage(); if (panel != nullptr) { Tab* tab = dynamic_cast(panel); - if (tab && (tab->type() == Preset::TYPE_FILAMENT || tab->type() == Preset::TYPE_PRINTER)) - if (!tab->validate_custom_gcodes()) - evt.Veto(); + if (tab != nullptr && !tab->validate_custom_gcodes()) + evt.Veto(); } }); #endif // ENABLE_VALIDATE_CUSTOM_GCODE diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index cf1879bb1..eeb420e3e 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -3826,15 +3826,35 @@ void TabPrinter::apply_extruder_cnt_from_cache() #if ENABLE_VALIDATE_CUSTOM_GCODE bool Tab::validate_custom_gcodes() { + if (m_type != Preset::TYPE_FILAMENT && + (m_type != Preset::TYPE_PRINTER || static_cast(this)->m_printer_technology != ptFFF)) + return true; + if (m_active_page->title() != L("Custom G-code")) + return true; + bool valid = true; - if ((m_type == Preset::TYPE_FILAMENT || - (m_type == Preset::TYPE_PRINTER && static_cast(this)->m_printer_technology == ptFFF)) && - m_active_page->title() == "Custom G-code") { - for (auto opt_group : m_active_page->m_optgroups) { - assert(opt_group->opt_map().size() == 1); - std::string key = opt_group->opt_map().begin()->first; - valid &= validate_custom_gcode(opt_group->title, boost::any_cast(opt_group->get_value(key))); - } + for (auto opt_group : m_active_page->m_optgroups) { + assert(opt_group->opt_map().size() == 1); + std::string key = opt_group->opt_map().begin()->first; + std::string value = boost::any_cast(opt_group->get_value(key)); + std::string config_value = m_config->opt_string(key); + valid &= validate_custom_gcode(opt_group->title, value); + Field* field = opt_group->get_field(key); + TextCtrl* text_ctrl = dynamic_cast(field); + if (text_ctrl != nullptr && text_ctrl->m_on_change != nullptr && !text_ctrl->m_disable_change_event) { + Slic3r::GUI::t_change callback = opt_group->m_on_change; + // temporary disable the opt_group->m_on_change callback to avoid multiple validations + opt_group->m_on_change = nullptr; + text_ctrl->m_on_change(key, value); + // restore the opt_group->m_on_change callback + opt_group->m_on_change = callback; + + update_dirty(); + on_value_change(key, value); + } + + if (!valid) + break; } return valid; }