From 5ce5e8df37720c6d0465537cbd2c94cdec082d7c Mon Sep 17 00:00:00 2001 From: Sabriel-Koh <52443698+Sabriel-Koh@users.noreply.github.com> Date: Wed, 21 Jan 2026 21:32:18 +0800 Subject: [PATCH] Refactor: move Printer dependencies data validation from Preset to Tab (#12026) # Description When creating a new filament preset and setting the Printer Dependencies to "All", the preset does not save this setting. This issue only occurs on creation due to code that is meant to validate the data to prevent a case where the filament is compatible with none of the printers. EDIT: While I considered redoing the data validation for this tab overall, I have now preserved the original purpose of the code, which is to add the current printer as a compatible printer only if: - the base preset is a System preset - the user has not specified any compatible printers Notably, this seems to be the cause of #11959 Moving the data validation from `Preset::save_current_preset` to `Tab::save_preset` allows the Preset function to be simplified through removal of the current printer parameter. # Screenshots/Recordings/Graphs There is no visible change on the UI. ## Tests Tested the following combinations of filament presets: - System->new User - User->new User - User->same User Tried to set them to All, where the System->new User should be the only case where this is replaced by a default. In any case where there are printers already set, those settings should be kept. --- src/libslic3r/Preset.cpp | 9 +-------- src/libslic3r/Preset.hpp | 2 +- src/slic3r/GUI/Tab.cpp | 16 +++++++++++----- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 4e78b31b46..a1d5f576cb 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -2422,7 +2422,7 @@ std::map> PresetCollection::get_filamen } //BBS: add project embedded preset logic -void PresetCollection::save_current_preset(const std::string &new_name, bool detach, bool save_to_project, Preset* _curr_preset, const Preset* _current_printer) +void PresetCollection::save_current_preset(const std::string &new_name, bool detach, bool save_to_project, Preset* _curr_preset) { Preset curr_preset = _curr_preset ? *_curr_preset : m_edited_preset; //BBS: add lock logic for sync preset in background @@ -2490,13 +2490,6 @@ void PresetCollection::save_current_preset(const std::string &new_name, bool det } else if (is_base_preset(preset)) { inherits = old_name; } - // Orca: check if compatible_printers exists and is not empty, set it to the current printer if it is empty - if (nullptr != _current_printer && preset.is_system && m_type == Preset::TYPE_FILAMENT) { - ConfigOptionStrings* compatible_printers = preset.config.option("compatible_printers"); - if (compatible_printers && compatible_printers->values.empty()) { - compatible_printers->values.push_back(_current_printer->name); - } - } preset.is_default = false; preset.is_system = false; diff --git a/src/libslic3r/Preset.hpp b/src/libslic3r/Preset.hpp index da3fb7edac..6afda07426 100644 --- a/src/libslic3r/Preset.hpp +++ b/src/libslic3r/Preset.hpp @@ -538,7 +538,7 @@ public: // a new preset is stored into the list of presets. // All presets are marked as not modified and the new preset is activated. //BBS: add project embedded preset logic - void save_current_preset(const std::string &new_name, bool detach = false, bool save_to_project = false, Preset* _curr_preset = nullptr, const Preset* _current_printer = nullptr); + void save_current_preset(const std::string &new_name, bool detach = false, bool save_to_project = false, Preset* _curr_preset = nullptr); // Delete the current preset, activate the first visible preset. // returns true if the preset was deleted successfully. diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index d4d31a3573..d79b151b55 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -6387,7 +6387,8 @@ void Tab::save_preset(std::string name /*= ""*/, bool detach, bool save_to_proje } //BBS record current preset name - std::string curr_preset_name = m_presets->get_edited_preset().name; + Preset& edited_preset = m_presets->get_edited_preset(); + std::string curr_preset_name = edited_preset.name; bool exist_preset = false; Preset* new_preset = m_presets->find_preset(name, false); @@ -6395,12 +6396,17 @@ void Tab::save_preset(std::string name /*= ""*/, bool detach, bool save_to_proje exist_preset = true; } - Preset* _current_printer = nullptr; - if (m_presets->type() == Preset::TYPE_FILAMENT) { - _current_printer = const_cast(&wxGetApp().preset_bundle->printers.get_selected_preset_base()); + // Orca: check if compatible_printers exists and is not empty, set it to the current printer if it is empty + // Ensures that custom filaments based on system are not accidentally allowed for all printers + // Can still be set for all after creation + if (m_presets->type() == Preset::TYPE_FILAMENT && !exist_preset && edited_preset.is_system) { + Preset* _curr_printer = const_cast(&wxGetApp().preset_bundle->printers.get_selected_preset_base()); + ConfigOptionStrings* compatible_printers = m_config->option("compatible_printers"); + if (nullptr != _curr_printer && compatible_printers && compatible_printers->values.empty()) + compatible_printers->values.push_back(_curr_printer->name); } // Save the preset into Slic3r::data_dir / presets / section_name / preset_name.json - m_presets->save_current_preset(name, detach, save_to_project, nullptr, _current_printer); + m_presets->save_current_preset(name, detach, save_to_project, nullptr); //BBS create new settings new_preset = m_presets->find_preset(name, false, true);