From a4c12b90f19786c00efb909819718f4801c47170 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 23 Jul 2020 12:17:18 +0200 Subject: [PATCH] PhysicalPrinterCollection: Use select_preset() instead of select_preset_by_name() + changed signature for select_preset() --- src/libslic3r/Preset.cpp | 31 +++++++++++------------------ src/libslic3r/Preset.hpp | 14 ++++++------- src/libslic3r/PresetBundle.cpp | 2 +- src/slic3r/GUI/PresetComboBoxes.cpp | 4 ++-- src/slic3r/GUI/Tab.cpp | 2 +- 5 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index ae74bffd7..7e30831fe 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -1731,34 +1731,27 @@ std::string PhysicalPrinterCollection::get_selected_full_printer_name() const return (m_idx_selected == size_t(-1)) ? std::string() : this->get_selected_printer().get_full_name(m_selected_preset); } -PhysicalPrinter& PhysicalPrinterCollection::select_printer_by_name(const std::string& full_name) +void PhysicalPrinterCollection::select_printer(const std::string& full_name) { std::string printer_name = PhysicalPrinter::get_short_name(full_name); auto it = this->find_printer_internal(printer_name); - assert(it != m_printers.end()); + if (it == m_printers.end()) { + unselect_printer(); + return; + } // update idx_selected - m_idx_selected = it - m_printers.begin(); + m_idx_selected = it - m_printers.begin(); + // update name of the currently selected preset - m_selected_preset = it->get_preset_name(full_name); - if (m_selected_preset.empty()) + if (printer_name == full_name) + // use first preset in the list m_selected_preset = *it->preset_names.begin(); - return *it; + else + m_selected_preset = it->get_preset_name(full_name); } -PhysicalPrinter& PhysicalPrinterCollection::select_printer(const std::string& printer_name) -{ - auto it = this->find_printer_internal(printer_name); - assert(it != m_printers.end()); - - // update idx_selected - m_idx_selected = it - m_printers.begin(); - // update name of the currently selected preset - m_selected_preset = *it->preset_names.begin(); - return *it; -} - -PhysicalPrinter& PhysicalPrinterCollection::select_printer(const PhysicalPrinter& printer) +void PhysicalPrinterCollection::select_printer(const PhysicalPrinter& printer) { return select_printer(printer.name); } diff --git a/src/libslic3r/Preset.hpp b/src/libslic3r/Preset.hpp index 98b805b4e..6b5a2a511 100644 --- a/src/libslic3r/Preset.hpp +++ b/src/libslic3r/Preset.hpp @@ -666,13 +666,13 @@ public: // Returns the printer model of the selected preset, or an empty string if no preset is selected. std::string get_selected_printer_preset_name() const { return (m_idx_selected == size_t(-1)) ? std::string() : m_selected_preset; } - // select printer with name and return reference on it - PhysicalPrinter& select_printer_by_name(const std::string& full_name); - PhysicalPrinter& select_printer(const std::string &printer_name); - PhysicalPrinter& select_printer(const PhysicalPrinter& printer); - bool has_selection() const; - void unselect_printer() ; - bool is_selected(ConstIterator it, const std::string &preset_name) const; + // Select printer by the full printer name, which contains name of printer, separator and name of selected preset + // If full_name doesn't contain name of selected preset, then select first preset in the list for this printer + void select_printer(const std::string& full_name); + void select_printer(const PhysicalPrinter& printer); + bool has_selection() const; + void unselect_printer() ; + bool is_selected(ConstIterator it, const std::string &preset_name) const; // Return a printer by an index. If the printer is active, a temporary copy is returned. PhysicalPrinter& printer(size_t idx) { return m_printers[idx]; } diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index d074c77d7..108985704 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -436,7 +436,7 @@ void PresetBundle::load_selections(AppConfig &config, const std::string &preferr // Activate physical printer from the config if (!initial_physical_printer_name.empty()) - physical_printers.select_printer_by_name(initial_physical_printer_name); + physical_printers.select_printer(initial_physical_printer_name); } // Export selections (current print, current filaments, current printer) into config.ini diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index 2c2b1d7a3..f6a2a036b 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -366,7 +366,7 @@ bool PresetComboBox::selection_is_changed_according_to_physical_printers() else old_printer_preset = m_collection->get_edited_preset().name; // Select related printer preset on the Printer Settings Tab - physical_printers.select_printer_by_name(selected_string); + physical_printers.select_printer(selected_string); std::string preset_name = physical_printers.get_selected_printer_preset_name(); // if new preset wasn't selected, there is no need to call update preset selection @@ -1031,7 +1031,7 @@ void TabPresetComboBox::update_physical_printers( const std::string& preset_name dialog.ShowModal(); } - physical_printers.select_printer_by_name(printer.get_full_name(preset_name)); + physical_printers.select_printer(printer.get_full_name(preset_name)); } } else diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index e498f56b7..dd63dc141 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -3100,7 +3100,7 @@ void Tab::select_preset(std::string preset_name, bool delete_current /*=false*/, if (!last_selected_ph_printer_name.empty() && m_presets->get_edited_preset().name == PhysicalPrinter::get_preset_name(last_selected_ph_printer_name)) { // If preset selection was canceled and previously was selected physical printer, we should select it back - m_preset_bundle->physical_printers.select_printer_by_name(last_selected_ph_printer_name); + m_preset_bundle->physical_printers.select_printer(last_selected_ph_printer_name); } }