diff --git a/src/GUI/Plater/PresetChooser.cpp b/src/GUI/Plater/PresetChooser.cpp index 4d79f0923..9cdaa229e 100644 --- a/src/GUI/Plater/PresetChooser.cpp +++ b/src/GUI/Plater/PresetChooser.cpp @@ -39,12 +39,23 @@ PresetChooser::PresetChooser(wxWindow* parent, Print& print, Settings& external_ } void PresetChooser::load(std::array presets) { - for (const auto& group : { preset_t::Print, preset_t::Material, preset_t::Printer }) { + + wxString selected_printer_name {""}; + for (const auto& group : { preset_t::Printer, preset_t::Material, preset_t::Print }) { auto current_list = presets.at(get_preset(group)); + // Filter out profiles not compatible with this printer + current_list = grep(presets.at(get_preset(group)), [selected_printer_name] (const Preset& x) -> bool { return x.compatible(selected_printer_name); }); + + // show default names if no other presets visible. if (current_list.size() > 1) { current_list = grep(presets.at(get_preset(group)), [] (const Preset& x) -> bool { return !x.default_preset; }); } - + + // # Read the current defaults from the settings file + auto settings_defaults {_settings.default_presets.at(get_preset(group))}; + + size_t i {0}; + std::vector preset_names {}; // populate the chooser for (auto* chooser : this->preset_choosers[get_preset(group)]) { chooser->Clear(); @@ -70,10 +81,37 @@ void PresetChooser::load(std::array presets) { chooser->Append(preset.name, bitmap); __chooser_names[get_preset(group)].push_back(preset.name); } + // Apply default options from settings + if (settings_defaults.size() > i) { // only apply if there is a value from Settings + this->select_preset_by_name(settings_defaults.at(i), chooser); + } else { + chooser->SetSelection(0); + } + + if (group == preset_t::Printer) { + selected_printer_name = chooser->GetString(chooser->GetSelection()); + } + ++i; } } } +void PresetChooser::select_preset_by_name(wxString name, preset_t group, size_t index = 0) { + auto& ps_list = this->preset_choosers.at(get_preset(group)); + if (ps_list.size() > index) { + select_preset_by_name(name, ps_list.at(index)); + } + this->_on_select_preset(group); +} + +void PresetChooser::select_preset_by_name(wxString name, wxBitmapComboBox* chooser) { + auto index { chooser->FindString(name) }; + if (index != wxNOT_FOUND) { + chooser->SetSelection(index); + } + +} + void PresetChooser::_on_select_preset(preset_t preset) { if (preset == preset_t::Printer) { this->load(); // reload print/filament settings to honor compatible printers diff --git a/src/GUI/Plater/PresetChooser.hpp b/src/GUI/Plater/PresetChooser.hpp index 8afcba0c7..20eef20bd 100644 --- a/src/GUI/Plater/PresetChooser.hpp +++ b/src/GUI/Plater/PresetChooser.hpp @@ -8,9 +8,12 @@ #include #endif +#include "Print.hpp" + #include "misc_ui.hpp" #include "Preset.hpp" #include "GUI.hpp" +#include "Settings.hpp" namespace Slic3r { namespace GUI { @@ -37,10 +40,31 @@ public: /// Const reference to internal name map (used for testing) const chooser_name_map& _chooser_names() const { return this->__chooser_names; } + /// Set the selection of one of the preset lists to the entry matching the + /// supplied name. + /// @param[in] name Name of preset to select. Case-sensitive. + /// @param[in] group Type of preset to change. + /// @param[in] index Preset chooser index to operate on (default is 0) + /// + /// Note: If index is greater than the number of active presets, nothing + /// happens. + /// Note: If name is not found, nothing happens. + void select_preset_by_name(wxString name, preset_t group, size_t index); + + /// Set the selection of one of the preset lists to the entry matching the + /// supplied name. + /// @param[in] name Name of preset to select. Case-sensitive. + /// @param[in] chooser Direct pointer to the appropriate wxBitmapComboBox + /// + /// Note: If name is not found, nothing happens. + void select_preset_by_name(wxString name, wxBitmapComboBox* chooser); + + /// Cycle through active presets and prompt user to save dirty configs, if necessary. + bool prompt_unsaved_changes(); private: wxSizer* local_sizer {}; void _on_change_combobox(preset_t preset, wxBitmapComboBox* choice); - chooser_name_map __chooser_names; + chooser_name_map __chooser_names; /// Reference to a Slic3r::Settings object. Settings& _settings;