diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 585634acf..27d4fc565 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -7741,12 +7741,12 @@ void Plater::priv::on_select_preset(wxCommandEvent &evt) else if (select_preset) { if (preset_type == Preset::TYPE_PRINTER) { PhysicalPrinterCollection& physical_printers = wxGetApp().preset_bundle->physical_printers; - if(combo->is_selected_physical_printer()) + if (marker == PresetComboBox::LABEL_ITEM_PHYSICAL_PRINTER) preset_name = physical_printers.get_selected_printer_preset_name(); else physical_printers.unselect_printer(); - if (combo->is_selected_printer_model()) { + if (marker == PresetComboBox::LABEL_ITEM_PRINTER_MODELS) { auto preset = wxGetApp().preset_bundle->get_similar_printer_preset(preset_name, {}); if (preset == nullptr) { MessageDialog dlg(this->sidebar, _L(""), _L("")); diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index e35eda6df..b4c8fca64 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -288,7 +288,7 @@ wxString PresetComboBox::get_tooltip(const Preset &preset) wxString PresetComboBox::get_preset_item_name(unsigned int index) { if (m_type == Preset::TYPE_PRINTER) { - int idx = selected_connected_printer(); + int idx = selected_connected_printer(index); if (idx < 0) { return GetString(index); } @@ -305,12 +305,14 @@ wxString PresetComboBox::get_preset_item_name(unsigned int index) return GetString(index); } - auto iter = machine_list.begin(); + auto iter = m_backup_dev_list_sorted.begin(); std::advance(iter, idx); - Preset* machine_preset = get_printer_preset(iter->second); - if (machine_preset) { - dev->set_selected_machine(iter->first); - return from_u8(machine_preset->name); + if (iter != m_backup_dev_list_sorted.end() && machine_list.find(*iter) != machine_list.end()) { + Preset* machine_preset = get_printer_preset(machine_list[*iter]); + if (machine_preset) { + dev->set_selected_machine(*iter); + return from_u8(machine_preset->name); + } } } } @@ -460,6 +462,11 @@ void PresetComboBox::add_connected_printers(std::string selected, bool alias_nam return false; }); + m_backup_dev_list_sorted.clear(); + for (auto &it : user_machine_list) { + m_backup_dev_list_sorted.push_back(it.first); + } + for (auto iter = user_machine_list.begin(); iter != user_machine_list.end(); ++iter) { Preset* printer_preset = get_printer_preset(iter->second); if (!printer_preset) @@ -473,10 +480,10 @@ void PresetComboBox::add_connected_printers(std::string selected, bool alias_nam m_last_printer_idx = GetCount(); } -int PresetComboBox::selected_connected_printer() const +int PresetComboBox::selected_connected_printer(int index) const { - if (m_first_printer_idx && m_last_selected >= m_first_printer_idx && m_last_selected < m_last_printer_idx) { - return reinterpret_cast(GetClientData(m_last_selected)) - &m_first_printer_idx; + if (m_first_printer_idx && index >= m_first_printer_idx && index < m_last_printer_idx) { + return reinterpret_cast(GetClientData(index)) - &m_first_printer_idx; } return -1; } diff --git a/src/slic3r/GUI/PresetComboBoxes.hpp b/src/slic3r/GUI/PresetComboBoxes.hpp index f09af04ee..86b884f1b 100644 --- a/src/slic3r/GUI/PresetComboBoxes.hpp +++ b/src/slic3r/GUI/PresetComboBoxes.hpp @@ -72,7 +72,7 @@ public: // BBS: printer bool update_printer_list(); void add_connected_printers(std::string selected, bool alias_name = false); - int selected_connected_printer() const; + int selected_connected_printer(int index) const; // BBS: ams void add_ams_filaments(std::string selected, bool alias_name = false); @@ -137,6 +137,7 @@ protected: int m_last_printer_idx = 0; std::vector m_backup_dev_list; + std::vector m_backup_dev_list_sorted; PrinterTechnology printer_technology {ptAny};