mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2026-01-28 20:01:16 -07:00
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.
This commit is contained in:
parent
a036de042b
commit
5ce5e8df37
3 changed files with 13 additions and 14 deletions
|
|
@ -2422,7 +2422,7 @@ std::map<std::string, std::vector<Preset const *>> 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<ConfigOptionStrings>("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;
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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<Preset*>(&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<Preset*>(&wxGetApp().preset_bundle->printers.get_selected_preset_base());
|
||||
ConfigOptionStrings* compatible_printers = m_config->option<ConfigOptionStrings>("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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue