diff --git a/src/slic3r/GUI/ConfigWizard.cpp b/src/slic3r/GUI/ConfigWizard.cpp index 265d256dc..4f211323a 100644 --- a/src/slic3r/GUI/ConfigWizard.cpp +++ b/src/slic3r/GUI/ConfigWizard.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -1162,7 +1163,7 @@ void PageMaterials::sort_list_data(StringList* list, bool add_All_item, bool mat // in alphabetical order std::vector> prusa_profiles; - std::vector> other_profiles; + std::vector>> other_profiles; // first is lower case id for sorting bool add_TEMPLATES_item = false; for (int i = 0 ; i < list->size(); ++i) { const std::string& data = list->get_data(i); @@ -1175,7 +1176,7 @@ void PageMaterials::sort_list_data(StringList* list, bool add_All_item, bool mat if (!material_type_ordering && data.find("Prusa") != std::string::npos) prusa_profiles.push_back(data); else - other_profiles.push_back(data); + other_profiles.emplace_back(boost::algorithm::to_lower_copy(boost::nowide::widen(data)),data); } if (material_type_ordering) { @@ -1185,10 +1186,10 @@ void PageMaterials::sort_list_data(StringList* list, bool add_All_item, bool mat for (size_t profs = end_of_sorted; profs < other_profiles.size(); profs++) { // find instead compare because PET vs PETG - if (other_profiles[profs].get().find(value) != std::string::npos) { + if (other_profiles[profs].second.get().find(value) != std::string::npos) { //swap if(profs != end_of_sorted) { - std::reference_wrapper aux = other_profiles[end_of_sorted]; + std::pair> aux = other_profiles[end_of_sorted]; other_profiles[end_of_sorted] = other_profiles[profs]; other_profiles[profs] = aux; } @@ -1201,8 +1202,8 @@ void PageMaterials::sort_list_data(StringList* list, bool add_All_item, bool mat std::sort(prusa_profiles.begin(), prusa_profiles.end(), [](std::reference_wrapper a, std::reference_wrapper b) { return a.get() < b.get(); }); - std::sort(other_profiles.begin(), other_profiles.end(), [](std::reference_wrapper a, std::reference_wrapper b) { - return a.get() < b.get(); + std::sort(other_profiles.begin(), other_profiles.end(), [](const std::pair>& a, const std::pair>& b) { + return a.first append(item, &const_cast(item.get())); for (const auto& item : other_profiles) - list->append(item, &const_cast(item.get())); + list->append(item.second, &const_cast(item.second.get())); } @@ -1225,20 +1226,19 @@ void PageMaterials::sort_list_data(PresetList* list, const std::vector prusa_profiles; - std::vector other_profiles; - //for (int i = 0; i < data.size(); ++i) { + std::vector> other_profiles; // first is lower case id for sorting for (const auto& item : data) { const std::string& name = item.name; if (name.find("Prusa") != std::string::npos) prusa_profiles.emplace_back(item); else - other_profiles.emplace_back(item); + other_profiles.emplace_back(boost::algorithm::to_lower_copy(boost::nowide::widen(name)), item); } std::sort(prusa_profiles.begin(), prusa_profiles.end(), [](ProfilePrintData a, ProfilePrintData b) { return a.name.get() < b.name.get(); }); - std::sort(other_profiles.begin(), other_profiles.end(), [](ProfilePrintData a, ProfilePrintData b) { - return a.name.get() < b.name.get(); + std::sort(other_profiles.begin(), other_profiles.end(), [](const std::pair& a, const std::pair& b) { + return a.first < b.first; }); list->Clear(); for (size_t i = 0; i < prusa_profiles.size(); ++i) { @@ -1246,8 +1246,8 @@ void PageMaterials::sort_list_data(PresetList* list, const std::vectorCheck(i, prusa_profiles[i].checked); } for (size_t i = 0; i < other_profiles.size(); ++i) { - list->append(std::string(other_profiles[i].name) + (other_profiles[i].omnipresent || template_shown ? "" : " *"), &const_cast(other_profiles[i].name.get())); - list->Check(i + prusa_profiles.size(), other_profiles[i].checked); + list->append(std::string(other_profiles[i].second.name) + (other_profiles[i].second.omnipresent || template_shown ? "" : " *"), &const_cast(other_profiles[i].second.name.get())); + list->Check(i + prusa_profiles.size(), other_profiles[i].second.checked); } } @@ -1670,9 +1670,17 @@ PageVendors::PageVendors(ConfigWizard *parent) auto boldfont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); boldfont.SetWeight(wxFONTWEIGHT_BOLD); + // Copy vendors from bundle map to vector, so we can sort it without case sensitivity + std::vector> vendors; + for (const auto& pair : wizard_p()->bundles) { + vendors.emplace_back(boost::algorithm::to_lower_copy(boost::nowide::widen(pair.second.vendor_profile->name)),pair.second.vendor_profile); + } + std::sort(vendors.begin(), vendors.end(), [](const std::pair& a, const std::pair& b) { + return a.first < b.first; + }); - for (const auto &pair : wizard_p()->bundles) { - const VendorProfile *vendor = pair.second.vendor_profile; + for (const std::pair& v : vendors) { + const VendorProfile* vendor = v.second; if (vendor->id == PresetBundle::PRUSA_BUNDLE) { continue; } if (vendor && vendor->templates_profile) continue; @@ -1682,8 +1690,8 @@ PageVendors::PageVendors(ConfigWizard *parent) wizard_p()->on_3rdparty_install(vendor, cbox->IsChecked()); }); - const auto &vendors = appconfig.vendors(); - const bool enabled = vendors.find(pair.first) != vendors.end(); + const auto &acvendors = appconfig.vendors(); + const bool enabled = acvendors.find(vendor->id) != acvendors.end(); if (enabled) { cbox->SetValue(true); @@ -2316,8 +2324,21 @@ void ConfigWizard::priv::load_pages() index->add_page(page_msla); if (!only_sla_mode) { index->add_page(page_vendors); - for (const auto &pages : pages_3rdparty) { - for ( PagePrinters* page : { pages.second.first, pages.second.second }) + + // Copy pages names from map to vector, so we can sort it without case sensitivity + std::vector> sorted_vendors; + for (const auto& pages : pages_3rdparty) { + sorted_vendors.emplace_back(boost::algorithm::to_lower_copy(boost::nowide::widen(pages.first)), pages.first); + } + std::sort(sorted_vendors.begin(), sorted_vendors.end(), [](const std::pair& a, const std::pair& b) { + return a.first < b.first; + }); + + for (const std::pair v : sorted_vendors) { + const auto& pages = pages_3rdparty.find(v.second); + if (pages == pages_3rdparty.end()) + continue; // Should not happen + for ( PagePrinters* page : { pages->second.first, pages->second.second }) if (page && page->install) index->add_page(page); } diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index 7a2e0de69..25beb87bc 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -246,8 +246,15 @@ void PresetComboBox::update(std::string select_preset_name) const std::deque& presets = m_collection->get_presets(); - std::map> nonsys_presets; - std::map incomp_presets; + struct PresetData { + wxString name; + wxString lower_name; + wxBitmapBundle* bitmap; + bool enabled; // not used in incomp_presets + }; + std::vector system_presets; + std::vector nonsys_presets; + std::vector incomp_presets; wxString selected = ""; if (!presets.front().is_visible) @@ -276,28 +283,31 @@ void PresetComboBox::update(std::string select_preset_name) assert(bmp); if (!is_enabled) { - incomp_presets.emplace(get_preset_name(preset), bmp); + incomp_presets.push_back({get_preset_name(preset), get_preset_name(preset).Lower(), bmp, false}); if (preset.is_dirty && m_show_modif_preset_separately) - incomp_presets.emplace(get_preset_name_with_suffix(preset), bmp); + incomp_presets.push_back({get_preset_name_with_suffix(preset), get_preset_name_with_suffix(preset).Lower(), bmp, false}); } else if (preset.is_default || preset.is_system) { - Append(get_preset_name(preset), *bmp); - validate_selection(preset.name == select_preset_name); + system_presets.push_back({get_preset_name(preset), get_preset_name(preset).Lower(), bmp, is_enabled}); + if (preset.name == select_preset_name) + selected = preset.name; + if (preset.is_dirty && m_show_modif_preset_separately) { wxString preset_name = get_preset_name_with_suffix(preset); - Append(preset_name, *bmp); - validate_selection(into_u8(preset_name) == select_preset_name); + system_presets.push_back({preset_name, preset_name.Lower(), bmp, is_enabled}); + if (into_u8(preset_name) == select_preset_name) + selected = preset_name; } } else { - nonsys_presets.emplace(get_preset_name(preset), std::pair(bmp, is_enabled)); + nonsys_presets.push_back({get_preset_name(preset), get_preset_name(preset).Lower(), bmp, is_enabled}); if (preset.name == select_preset_name || (select_preset_name.empty() && is_enabled)) selected = get_preset_name(preset); if (preset.is_dirty && m_show_modif_preset_separately) { wxString preset_name = get_preset_name_with_suffix(preset); - nonsys_presets.emplace(preset_name, std::pair(bmp, is_enabled)); + nonsys_presets.push_back({preset_name, preset_name.Lower(), bmp, is_enabled}); if (preset_name == select_preset_name || (select_preset_name.empty() && is_enabled)) selected = preset_name; } @@ -305,25 +315,46 @@ void PresetComboBox::update(std::string select_preset_name) if (i + 1 == m_collection->num_default_presets()) set_label_marker(Append(separator(L("System presets")), NullBitmapBndl())); } + + if (!system_presets.empty()) + { + std::sort(system_presets.begin(), system_presets.end(), [](const PresetData& a, const PresetData& b) { + return a.lower_name < b.lower_name; + }); + + for (std::vector::iterator it = system_presets.begin(); it != system_presets.end(); ++it) { + int item_id = Append(it->name, *it->bitmap); + if (!it->enabled) + set_label_marker(item_id, LABEL_ITEM_DISABLED); + validate_selection(it->name == selected); + } + } if (!nonsys_presets.empty()) { + std::sort(nonsys_presets.begin(), nonsys_presets.end(), [](const PresetData& a, const PresetData& b) { + return a.lower_name < b.lower_name; + }); + set_label_marker(Append(separator(L("User presets")), NullBitmapBndl())); - for (std::map>::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) { - int item_id = Append(it->first, *it->second.first); - bool is_enabled = it->second.second; - if (!is_enabled) + for (std::vector::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) { + int item_id = Append(it->name, *it->bitmap); + if (!it->enabled) set_label_marker(item_id, LABEL_ITEM_DISABLED); - validate_selection(it->first == selected); + validate_selection(it->name == selected); } } if (!incomp_presets.empty()) { + std::sort(incomp_presets.begin(), incomp_presets.end(), [](const PresetData& a, const PresetData& b) { + return a.lower_name < b.lower_name; + }); + set_label_marker(Append(separator(L("Incompatible presets")), NullBitmapBndl())); - for (std::map::iterator it = incomp_presets.begin(); it != incomp_presets.end(); ++it) { - set_label_marker(Append(it->first, *it->second), LABEL_ITEM_DISABLED); + for (std::vector ::iterator it = incomp_presets.begin(); it != incomp_presets.end(); ++it) { + set_label_marker(Append(it->name, *it->bitmap), LABEL_ITEM_DISABLED); } } - + update_selection(); Thaw(); } @@ -833,8 +864,14 @@ void PlaterPresetComboBox::update() null_icon_width = (wide_icons ? 3 : 2) * norm_icon_width + thin_space_icon_width + wide_space_icon_width; - std::map nonsys_presets; - std::map template_presets; + struct PresetData { + wxString name; + wxString lower_name; + wxBitmapBundle* bitmap; + }; + std::vector system_presets; + std::vector nonsys_presets; + std::vector template_presets; const bool allow_templates = !wxGetApp().app_config->get_bool("no_templates"); @@ -888,22 +925,23 @@ void PlaterPresetComboBox::update() if (preset.is_default || preset.is_system) { if (preset.vendor && preset.vendor->templates_profile) { if (allow_templates) { - template_presets.emplace(get_preset_name(preset), bmp); + template_presets.push_back({get_preset_name(preset), get_preset_name(preset).Lower(), bmp}); if (is_selected) { selected_user_preset = get_preset_name(preset); tooltip = from_u8(preset.name); } } } else { - Append(get_preset_name(preset), *bmp); - validate_selection(is_selected); - if (is_selected) + system_presets.push_back({ get_preset_name(preset), get_preset_name(preset).Lower(), bmp }); + if (is_selected) { + selected_user_preset = get_preset_name(preset); tooltip = from_u8(preset.name); + } } } else { - nonsys_presets.emplace(get_preset_name(preset), bmp); + nonsys_presets.push_back({ get_preset_name(preset), get_preset_name(preset).Lower(), bmp }); if (is_selected) { selected_user_preset = get_preset_name(preset); tooltip = from_u8(preset.name); @@ -912,22 +950,41 @@ void PlaterPresetComboBox::update() if (i + 1 == m_collection->num_default_presets()) set_label_marker(Append(separator(L("System presets")), NullBitmapBndl())); } - + + if(!system_presets.empty()) + { + std::sort(system_presets.begin(), system_presets.end(), [](const PresetData& a, const PresetData& b) { + return a.lower_name < b.lower_name; + }); + + for (std::vector::iterator it = system_presets.begin(); it != system_presets.end(); ++it) { + Append(it->name, *it->bitmap); + validate_selection(it->name == selected_user_preset); + } + } if (!nonsys_presets.empty()) { + std::sort(nonsys_presets.begin(), nonsys_presets.end(), [](const PresetData& a, const PresetData& b) { + return a.lower_name < b.lower_name; + }); + set_label_marker(Append(separator(L("User presets")), NullBitmapBndl())); - for (std::map::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) { - Append(it->first, *it->second); - validate_selection(it->first == selected_user_preset); + for (std::vector::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) { + Append(it->name, *it->bitmap); + validate_selection(it->name == selected_user_preset); } } if (!template_presets.empty()) { + std::sort(template_presets.begin(), template_presets.end(), [](const PresetData& a, const PresetData& b) { + return a.lower_name < b.lower_name; + }); + set_label_marker(Append(separator(L("Template presets")), wxNullBitmap)); - for (std::map::iterator it = template_presets.begin(); it != template_presets.end(); ++it) { - Append(it->first, *it->second); - validate_selection(it->first == selected_user_preset); + for (std::vector::iterator it = template_presets.begin(); it != template_presets.end(); ++it) { + Append(it->name, *it->bitmap); + validate_selection(it->name == selected_user_preset); } } @@ -938,19 +995,37 @@ void PlaterPresetComboBox::update() set_label_marker(Append(separator(L("Physical printers")), NullBitmapBndl())); const PhysicalPrinterCollection& ph_printers = m_preset_bundle->physical_printers; + // Sort Physical printers in preset_data vector and than Append it in correct order + struct PhysicalPrinterPresetData + { + wxString lower_name; // just for sorting + std::string name; // preset_name + std::string fullname; // full name + bool selected; // is selected + }; + std::vector preset_data; for (PhysicalPrinterCollection::ConstIterator it = ph_printers.begin(); it != ph_printers.end(); ++it) { for (const std::string& preset_name : it->get_preset_names()) { - Preset* preset = m_collection->find_preset(preset_name); - if (!preset || !preset->is_visible) - continue; - std::string main_icon_name, bitmap_key = main_icon_name = preset->printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name; - auto bmp = get_bmp(main_icon_name, wide_icons, main_icon_name); - assert(bmp); - - set_label_marker(Append(from_u8(it->get_full_name(preset_name) + suffix(preset)), *bmp), LABEL_ITEM_PHYSICAL_PRINTER); - validate_selection(ph_printers.is_selected(it, preset_name)); + preset_data.push_back({ wxString::FromUTF8(it->get_full_name(preset_name)).Lower(), preset_name, it->get_full_name(preset_name), ph_printers.is_selected(it, preset_name) }); } } + std::sort(preset_data.begin(), preset_data.end(), [](const PhysicalPrinterPresetData& a, const PhysicalPrinterPresetData& b) { + return a.lower_name < b.lower_name; + }); + + for (const PhysicalPrinterPresetData& data : preset_data) + { + Preset* preset = m_collection->find_preset(data.name); + if (!preset || !preset->is_visible) + continue; + std::string main_icon_name = preset->printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name; + + auto bmp = get_bmp(main_icon_name, main_icon_name, "", true, true, false); + assert(bmp); + + set_label_marker(Append(from_u8(data.fullname + suffix(preset)), *bmp), LABEL_ITEM_PHYSICAL_PRINTER); + validate_selection(data.selected); + } } } @@ -1069,12 +1144,18 @@ void TabPresetComboBox::update() const ExtruderFilaments& extruder_filaments = m_preset_bundle->extruders_filaments[m_active_extruder_idx]; const std::deque& presets = m_collection->get_presets(); - - std::map> nonsys_presets; - std::map> template_presets; + + struct PresetData { + wxString name; + wxString lower_name; + wxBitmapBundle* bitmap; + bool enabled; + }; + std::vector system_presets; + std::vector nonsys_presets; + std::vector template_presets; const bool allow_templates = !wxGetApp().app_config->get_bool("no_templates"); - wxString selected = ""; if (!presets.front().is_visible) set_label_marker(Append(separator(L("System presets")), NullBitmapBndl())); @@ -1113,23 +1194,20 @@ void TabPresetComboBox::update() if (preset.is_default || preset.is_system) { if (preset.vendor && preset.vendor->templates_profile) { if (allow_templates) { - template_presets.emplace(get_preset_name(preset), std::pair(bmp, is_enabled)); + template_presets.push_back({get_preset_name(preset), get_preset_name(preset).Lower(), bmp, is_enabled}); if (i == idx_selected) selected = get_preset_name(preset); } } else { - int item_id = Append(get_preset_name(preset), *bmp); - if (!is_enabled) - set_label_marker(item_id, LABEL_ITEM_DISABLED); - validate_selection(i == idx_selected); + system_presets.push_back({get_preset_name(preset), get_preset_name(preset).Lower(), bmp, is_enabled}); + if (i == idx_selected) + selected = get_preset_name(preset); } - - } else { std::pair pair(bmp, is_enabled); - nonsys_presets.emplace(get_preset_name(preset), std::pair(bmp, is_enabled)); + nonsys_presets.push_back({get_preset_name(preset), get_preset_name(preset).Lower(), bmp, is_enabled}); if (i == idx_selected) selected = get_preset_name(preset); } @@ -1137,26 +1215,47 @@ void TabPresetComboBox::update() set_label_marker(Append(separator(L("System presets")), NullBitmapBndl())); } + if (!system_presets.empty()) + { + std::sort(system_presets.begin(), system_presets.end(), [](const PresetData& a, const PresetData& b) { + return a.lower_name < b.lower_name; + }); + + for (std::vector::iterator it = system_presets.begin(); it != system_presets.end(); ++it) { + int item_id = Append(it->name, *it->bitmap); + if (!it->enabled) + set_label_marker(item_id, LABEL_ITEM_DISABLED); + validate_selection(it->name == selected); + } + } + if (!nonsys_presets.empty()) { + std::sort(nonsys_presets.begin(), nonsys_presets.end(), [](const PresetData& a, const PresetData& b) { + return a.lower_name < b.lower_name; + }); + set_label_marker(Append(separator(L("User presets")), NullBitmapBndl())); - for (std::map>::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) { - int item_id = Append(it->first, *it->second.first); - bool is_enabled = it->second.second; - if (!is_enabled) + for (std::vector::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) { + int item_id = Append(it->name, *it->bitmap); + if (!it->enabled) set_label_marker(item_id, LABEL_ITEM_DISABLED); - validate_selection(it->first == selected); + validate_selection(it->name == selected); } } - if (!template_presets.empty()) { + if (!template_presets.empty()) + { + std::sort(template_presets.begin(), template_presets.end(), [](const PresetData& a, const PresetData& b) { + return a.lower_name < b.lower_name; + }); + set_label_marker(Append(separator(L("Template presets")), wxNullBitmap)); - for (std::map>::iterator it = template_presets.begin(); it != template_presets.end(); ++it) { - int item_id = Append(it->first, *it->second.first); - bool is_enabled = it->second.second; - if (!is_enabled) + for (std::vector::iterator it = template_presets.begin(); it != template_presets.end(); ++it) { + int item_id = Append(it->name, *it->bitmap); + if (!it->enabled) set_label_marker(item_id, LABEL_ITEM_DISABLED); - validate_selection(it->first == selected); + validate_selection(it->name == selected); } } @@ -1167,20 +1266,36 @@ void TabPresetComboBox::update() set_label_marker(Append(separator(L("Physical printers")), NullBitmapBndl())); const PhysicalPrinterCollection& ph_printers = m_preset_bundle->physical_printers; + // Sort Physical printers in preset_data vector and than Append it in correct order + struct PhysicalPrinterPresetData + { + wxString lower_name; // just for sorting + std::string name; // preset_name + std::string fullname; // full name + bool selected; // is selected + }; + std::vector preset_data; for (PhysicalPrinterCollection::ConstIterator it = ph_printers.begin(); it != ph_printers.end(); ++it) { for (const std::string& preset_name : it->get_preset_names()) { - Preset* preset = m_collection->find_preset(preset_name); - if (!preset || !preset->is_visible) - continue; - std::string main_icon_name = preset->printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name; - - auto bmp = get_bmp(main_icon_name, main_icon_name, "", true, true, false); - assert(bmp); - - set_label_marker(Append(from_u8(it->get_full_name(preset_name) + suffix(preset)), *bmp), LABEL_ITEM_PHYSICAL_PRINTER); - validate_selection(ph_printers.is_selected(it, preset_name)); + preset_data.push_back({wxString::FromUTF8(it->get_full_name(preset_name)).Lower(), preset_name, it->get_full_name(preset_name), ph_printers.is_selected(it, preset_name)}); } } + std::sort(preset_data.begin(), preset_data.end(), [](const PhysicalPrinterPresetData& a, const PhysicalPrinterPresetData& b) { + return a.lower_name < b.lower_name; + }); + for (const PhysicalPrinterPresetData& data : preset_data) + { + Preset* preset = m_collection->find_preset(data.name); + if (!preset || !preset->is_visible) + continue; + std::string main_icon_name = preset->printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name; + + auto bmp = get_bmp(main_icon_name, main_icon_name, "", true, true, false); + assert(bmp); + + set_label_marker(Append(from_u8(data.fullname + suffix(preset)), *bmp), LABEL_ITEM_PHYSICAL_PRINTER); + validate_selection(data.selected); + } } // add "Add/Remove printers" item