From 2b25f55f8b9bba814660c388c94a842407bddab9 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Mon, 18 Sep 2023 14:48:38 +0200 Subject: [PATCH] Follow up 2c9a21c - Fixed SubstitutionManager::delete_substitution() + Fixed visibility of the "Match single line" CheckBoxes, when preset is switched and values are transferred to new selected preset. + Fixed typos in some functions names --- src/slic3r/GUI/Tab.cpp | 40 +++++++++++++++++++++------------------- src/slic3r/GUI/Tab.hpp | 5 +++-- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 95bbdf1363..c3872334f8 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -1799,7 +1799,7 @@ void TabPrint::update_description_lines() _L("Post processing scripts shall modify G-code file in place.")); m_post_process_explanation->SetPathEnd("post-processing-scripts_283913"); } - // upadte G-code substitutions from the current configuration + // update G-code substitutions from the current configuration { m_subst_manager.update_from_config(); if (m_del_all_substitutions_btn) @@ -4548,7 +4548,7 @@ void SubstitutionManager::init(DynamicPrintConfig* config, wxWindow* parent, wxF m_substitutions = m_config->option("gcode_substitutions")->values; } -void SubstitutionManager::validate_lenth() +void SubstitutionManager::validate_length() { if ((m_substitutions.size() % 4) != 0) { WarningDialog(m_parent, "Value of gcode_substitutions parameter will be cut to valid length", @@ -4559,7 +4559,7 @@ void SubstitutionManager::validate_lenth() } } -bool SubstitutionManager::is_compatibile_with_ui() +bool SubstitutionManager::is_compatible_with_ui() { if (int(m_substitutions.size() / 4) != m_grid_sizer->GetEffectiveRowsCount() - 1) { ErrorDialog(m_parent, "Invalid compatibility between UI and BE", false).ShowModal(); @@ -4596,15 +4596,13 @@ void SubstitutionManager::create_legend() // delete substitution_id from substitutions void SubstitutionManager::delete_substitution(int substitution_id) { - validate_lenth(); + validate_length(); if (!is_valid_id(substitution_id, "Invalid substitution_id to delete")) return; // delete substitution - m_substitutions.erase(std::next(m_substitutions.begin(), substitution_id * 4), std::next(m_substitutions.begin(), substitution_id * 4 + 4)); - - // save changes from m_substitutions to config - m_config->option("gcode_substitutions")->values = m_substitutions; + std::vector& substitutions = m_config->option("gcode_substitutions")->values; + substitutions.erase(std::next(substitutions.begin(), substitution_id * 4), std::next(substitutions.begin(), substitution_id * 4 + 4)); call_ui_update(); @@ -4695,13 +4693,7 @@ void SubstitutionManager::add_substitution( int substitution_id, auto chb_match_single_line = new wxCheckBox(m_parent, wxID_ANY, _L("Match single line")); chb_match_single_line->SetValue(match_single_line); chb_match_single_line->Show(regexp); - - chb_match_single_line->Bind(wxEVT_SHOW, [chb_match_single_line, chb_regexp](wxShowEvent& evt) { - if (evt.IsShown() && !chb_regexp->GetValue()) { - // To avoid a case, when ShowAll() is called for m_grid_sizer but chb_match_single_line have to be hidden - chb_match_single_line->Hide(); - } - }); + m_chb_match_single_lines.emplace_back(chb_match_single_line); params_sizer->Add(chb_match_single_line, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxLEFT, m_em); @@ -4740,21 +4732,31 @@ void SubstitutionManager::update_from_config() { std::vector& subst = m_config->option("gcode_substitutions")->values; if (m_substitutions == subst && m_grid_sizer->IsShown(1)) { + // just update visibility for chb_match_single_lines + int subst_id = 0; + for (size_t i = 0; i < subst.size(); i += 4) { + const std::string& params = subst[i + 2]; + const bool regexp = strchr(params.c_str(), 'r') != nullptr || strchr(params.c_str(), 'R') != nullptr; + m_chb_match_single_lines[subst_id++]->Show(regexp); + } + // "gcode_substitutions" values didn't changed in config. There is no need to update/recreate controls return; } m_substitutions = subst; - if (!m_grid_sizer->IsEmpty()) + if (!m_grid_sizer->IsEmpty()) { m_grid_sizer->Clear(true); + m_chb_match_single_lines.clear(); + } if (subst.empty()) hide_delete_all_btn(); else create_legend(); - validate_lenth(); + validate_length(); int subst_id = 0; for (size_t i = 0; i < subst.size(); i += 4) @@ -4777,8 +4779,8 @@ void SubstitutionManager::delete_all() void SubstitutionManager::edit_substitution(int substitution_id, int opt_pos, const std::string& value) { - validate_lenth(); - if(!is_compatibile_with_ui() || !is_valid_id(substitution_id, "Invalid substitution_id to edit")) + validate_length(); + if(!is_compatible_with_ui() || !is_valid_id(substitution_id, "Invalid substitution_id to edit")) return; m_substitutions[substitution_id * 4 + opt_pos] = value; diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index 69a544ad7a..1b8dc99bc5 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -71,9 +71,10 @@ class SubstitutionManager std::function m_cb_hide_delete_all_btn{ nullptr }; std::vector m_substitutions; + std::vector m_chb_match_single_lines; - void validate_lenth(); - bool is_compatibile_with_ui(); + void validate_length(); + bool is_compatible_with_ui(); bool is_valid_id(int substitution_id, const wxString& message); public: