From 106e520a104e5487f91a79a920af5df17c9c6ec5 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 11 Jan 2022 16:49:28 +0100 Subject: [PATCH] Invalidate print when G-code substitution is changed + DiffDialog: Fixed get_string_value() for "gcode_substitution" + some code refactoring : For PresetCollection added is_independent_from_extruder_number_option(opt_key) to check if option is from the list of options with vector variable, which is independent from number of extruders --- src/libslic3r/Preset.cpp | 16 +++++++++++++++- src/libslic3r/Preset.hpp | 1 + src/slic3r/GUI/OptionsGroup.cpp | 4 ++-- src/slic3r/GUI/Tab.cpp | 9 ++++----- src/slic3r/GUI/UnsavedChangesDialog.cpp | 8 ++++++++ 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index b3ed6f57f..ba1c440a3 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -1133,6 +1133,20 @@ void add_correct_opts_to_diff(const std::string &opt_key, t_config_option_keys& } } +// list of options with vector variable, which is independent from number of extruders +static const std::vector independent_from_extruder_number_options = { + "bed_shape", + "filament_ramming_parameters", + "gcode_substitutions", + "compatible_prints", + "compatible_printers" +}; + +bool PresetCollection::is_independent_from_extruder_number_option(const std::string& opt_key) +{ + return std::find(independent_from_extruder_number_options.begin(), independent_from_extruder_number_options.end(), opt_key) != independent_from_extruder_number_options.end(); +} + // Use deep_diff to correct return of changed options, considering individual options for each extruder. inline t_config_option_keys deep_diff(const ConfigBase &config_this, const ConfigBase &config_other) { @@ -1142,7 +1156,7 @@ inline t_config_option_keys deep_diff(const ConfigBase &config_this, const Confi const ConfigOption *other_opt = config_other.option(opt_key); if (this_opt != nullptr && other_opt != nullptr && *this_opt != *other_opt) { - if (opt_key == "bed_shape" || opt_key == "thumbnails" || opt_key == "compatible_prints" || opt_key == "compatible_printers") { + if (PresetCollection::is_independent_from_extruder_number_option(opt_key)) { // Scalar variable, or a vector variable, which is independent from number of extruders, // thus the vector is presented to the user as a single input. diff.emplace_back(opt_key); diff --git a/src/libslic3r/Preset.hpp b/src/libslic3r/Preset.hpp index 6764b197d..f4e4c1471 100644 --- a/src/libslic3r/Preset.hpp +++ b/src/libslic3r/Preset.hpp @@ -556,6 +556,7 @@ private: public: static bool is_dirty(const Preset *edited, const Preset *reference); static std::vector dirty_options(const Preset *edited, const Preset *reference, const bool deep_compare = false); + static bool is_independent_from_extruder_number_option(const std::string& opt_key); private: // Type of this PresetCollection: TYPE_PRINT, TYPE_FILAMENT or TYPE_PRINTER. Preset::Type m_type; diff --git a/src/slic3r/GUI/OptionsGroup.cpp b/src/slic3r/GUI/OptionsGroup.cpp index 0cd924001..828806a1f 100644 --- a/src/slic3r/GUI/OptionsGroup.cpp +++ b/src/slic3r/GUI/OptionsGroup.cpp @@ -15,6 +15,7 @@ #include "libslic3r/Exception.hpp" #include "libslic3r/Utils.hpp" #include "libslic3r/AppConfig.hpp" +#include "libslic3r/Preset.hpp" #include "I18N.hpp" namespace Slic3r { namespace GUI { @@ -596,8 +597,7 @@ void ConfigOptionsGroup::back_to_config_value(const DynamicPrintConfig& config, } else if (m_opt_map.find(opt_key) == m_opt_map.end() || // This option don't have corresponded field - opt_key == "bed_shape" || opt_key == "filament_ramming_parameters" || opt_key == "gcode_substitutions" || - opt_key == "compatible_printers" || opt_key == "compatible_prints" ) { + PresetCollection::is_independent_from_extruder_number_option(opt_key) ) { value = get_config_value(config, opt_key); this->change_opt_value(opt_key, value); return; diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index ee85a55b6..23787f4b7 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -532,8 +532,7 @@ void Tab::update_label_colours() else color = &m_modified_label_clr; } - if (opt.first == "bed_shape" || opt.first == "filament_ramming_parameters" || - opt.first == "compatible_prints" || opt.first == "compatible_printers" ) { + if (PresetCollection::is_independent_from_extruder_number_option(opt.first)) { if (m_colored_Label_colors.find(opt.first) != m_colored_Label_colors.end()) m_colored_Label_colors.at(opt.first) = *color; continue; @@ -574,8 +573,7 @@ void Tab::decorate() Field* field = nullptr; wxColour* colored_label_clr = nullptr; - if (opt.first == "bed_shape" || opt.first == "filament_ramming_parameters" || - opt.first == "compatible_prints" || opt.first == "compatible_printers") + if(PresetCollection::is_independent_from_extruder_number_option(opt.first)) colored_label_clr = (m_colored_Label_colors.find(opt.first) == m_colored_Label_colors.end()) ? nullptr : &m_colored_Label_colors.at(opt.first); if (!colored_label_clr) { @@ -4115,7 +4113,8 @@ wxSizer* TabPrint::create_substitutions_widget(wxWindow* parent) m_subst_manager.init(m_config, parent, grid_sizer); m_subst_manager.set_cb_edited_substitution([this]() { - update_changed_ui(); + update_dirty(); + wxGetApp().mainframe->on_config_changed(m_config); // invalidate print }); auto sizer = new wxBoxSizer(wxHORIZONTAL); diff --git a/src/slic3r/GUI/UnsavedChangesDialog.cpp b/src/slic3r/GUI/UnsavedChangesDialog.cpp index f9fb2c468..608721203 100644 --- a/src/slic3r/GUI/UnsavedChangesDialog.cpp +++ b/src/slic3r/GUI/UnsavedChangesDialog.cpp @@ -1156,6 +1156,14 @@ static wxString get_string_value(std::string opt_key, const DynamicPrintConfig& out.RemoveLast(1); return out; } + if (opt_key == "gcode_substitutions") { + if (!strings->empty()) + for (size_t id = 0; id < strings->size(); id += 3) + out += from_u8(strings->get_at(id)) + ";\t" + + from_u8(strings->get_at(id + 1)) + ";\t" + + from_u8(strings->get_at(id + 2)) + ";\n"; + return out; + } if (!strings->empty() && opt_idx < strings->values.size()) return from_u8(strings->get_at(opt_idx)); }