diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm index 52ee761b9e..223c067496 100644 --- a/lib/Slic3r/GUI/Tab.pm +++ b/lib/Slic3r/GUI/Tab.pm @@ -442,16 +442,9 @@ sub _load_key_value { $self->{config}->set($opt_key, $value); # Mark the print & filament enabled if they are compatible with the currently selected preset. if ($opt_key eq 'compatible_printers') { - my $was_compatible = $self->{presets}->get_edited_preset->compatible; wxTheApp->{preset_bundle}->update_compatible_with_printer(0); - if ($was_compatible != $self->{presets}->get_edited_preset->compatible) { - # This is certainly not a tab page. - # Trigger the on_presets_changed event so that we also update the "compatible" flag at the plater selector. - $self->_on_presets_changed; - } - } else { - $self->{presets}->update_dirty_ui($self->{presets_choice}); } + $self->{presets}->update_dirty_ui($self->{presets_choice}); $self->_on_presets_changed; $self->_update; } diff --git a/xs/src/slic3r/GUI/Preset.cpp b/xs/src/slic3r/GUI/Preset.cpp index 89a11f1f97..5f4afc8d2c 100644 --- a/xs/src/slic3r/GUI/Preset.cpp +++ b/xs/src/slic3r/GUI/Preset.cpp @@ -484,6 +484,18 @@ bool PresetCollection::update_dirty_ui(wxBitmapComboBox *ui) return was_dirty != is_dirty; } +std::vector PresetCollection::current_dirty_options() const +{ + std::vector changed = this->get_selected_preset().config.diff(this->get_edited_preset().config); + // The "compatible_printers" option key is handled differently from the others: + // It is not mandatory. If the key is missing, it means it is compatible with any printer. + // If the key exists and it is empty, it means it is compatible with no printer. + const char compatible_printers[] = "compatible_printers"; + if (this->get_selected_preset().config.has(compatible_printers) != this->get_edited_preset().config.has(compatible_printers)) + changed.emplace_back(compatible_printers); + return changed; +} + // Select a new preset. This resets all the edits done to the currently selected preset. // If the preset with index idx does not exist, a first visible preset is selected. Preset& PresetCollection::select_preset(size_t idx) diff --git a/xs/src/slic3r/GUI/Preset.hpp b/xs/src/slic3r/GUI/Preset.hpp index 74ae7411ca..196c135991 100644 --- a/xs/src/slic3r/GUI/Preset.hpp +++ b/xs/src/slic3r/GUI/Preset.hpp @@ -159,7 +159,7 @@ public: // Return a preset by an index. If the preset is active, a temporary copy is returned. Preset& preset(size_t idx) { return (int(idx) == m_idx_selected) ? m_edited_preset : m_presets[idx]; } const Preset& preset(size_t idx) const { return const_cast(this)->preset(idx); } - void discard_current_changes() { m_edited_preset = m_presets[m_idx_selected]; } + void discard_current_changes() { m_presets[m_idx_selected].reset_dirty(); m_edited_preset = m_presets[m_idx_selected]; } // Return a preset by its name. If the preset is active, a temporary copy is returned. // If a preset is not found by its name, null is returned. @@ -185,9 +185,9 @@ public: size_t num_visible() const { return std::count_if(m_presets.begin(), m_presets.end(), [](const Preset &preset){return preset.is_visible;}); } // Compare the content of get_selected_preset() with get_edited_preset() configs, return true if they differ. - bool current_is_dirty() { return ! this->current_dirty_options().empty(); } + bool current_is_dirty() const { return ! this->current_dirty_options().empty(); } // Compare the content of get_selected_preset() with get_edited_preset() configs, return the list of keys where they differ. - std::vector current_dirty_options() { return this->get_selected_preset().config.diff(this->get_edited_preset().config); } + std::vector current_dirty_options() const; // Update the choice UI from the list of presets. // If show_incompatible, all presets are shown, otherwise only the compatible presets are shown.