From 068a254ef03d12c378f4332cf8f0cf87f90769a2 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Tue, 20 Oct 2020 10:35:48 +0200 Subject: [PATCH] configuration wizard: added Checked information to sorting algortihm on filaments page. Fix of #4922 --- src/slic3r/GUI/ConfigWizard.cpp | 39 +++++++++++++++---------- src/slic3r/GUI/ConfigWizard_private.hpp | 10 ++++++- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/slic3r/GUI/ConfigWizard.cpp b/src/slic3r/GUI/ConfigWizard.cpp index b186cefdd..cd944f689 100644 --- a/src/slic3r/GUI/ConfigWizard.cpp +++ b/src/slic3r/GUI/ConfigWizard.cpp @@ -909,7 +909,7 @@ void PageMaterials::update_lists(int sel_printer, int sel_type, int sel_vendor) const std::string& type = list_type->get_data(sel_type); const std::string& vendor = list_vendor->get_data(sel_vendor); // finst printer preset - std::vector, bool>> to_list; + std::vector to_list; for (size_t i = 0; i < sel_printers_count; i++) { const std::string& printer_name = list_printer->get_data(sel_printers[i]); const Preset* printer = nullptr; @@ -924,16 +924,19 @@ void PageMaterials::update_lists(int sel_printer, int sel_type, int sel_vendor) bool was_checked = false; //size_t printer_counter = materials->get_printer_counter(p); int cur_i = list_profile->find(p->alias); + bool emplace_to_to_list = false; if (cur_i == wxNOT_FOUND) { cur_i = list_profile->append(p->alias + (materials->get_omnipresent(p) ? "" : " *"), &p->alias); - to_list.emplace_back(p->alias, materials->get_omnipresent(p)); + emplace_to_to_list = true; } else was_checked = list_profile->IsChecked(cur_i); const std::string& section = materials->appconfig_section(); const bool checked = wizard_p()->appconfig_new.has(section, p->name); - list_profile->Check(cur_i, checked | was_checked); + list_profile->Check(cur_i, checked || was_checked); + if (emplace_to_to_list) + to_list.emplace_back(p->alias, materials->get_omnipresent(p), checked || was_checked); /* Update preset selection in config. * If one preset from aliases bundle is selected, @@ -1011,33 +1014,39 @@ void PageMaterials::sort_list_data(StringList* list, bool add_All_item, bool mat list->append(item, &const_cast(item.get())); } -void PageMaterials::sort_list_data(PresetList* list, const std::vector, bool>>& data) +void PageMaterials::sort_list_data(PresetList* list, const std::vector& data) { // sort data // then prusa profiles // then the rest // in alphabetical order - std::vector, bool>> prusa_profiles; - std::vector, bool>> other_profiles; + std::vector prusa_profiles; + std::vector other_profiles; //for (int i = 0; i < data.size(); ++i) { for (const auto& item : data) { - const std::string& name = item.first; + const std::string& name = item.name; if (name.find("Prusa") != std::string::npos) prusa_profiles.emplace_back(item); else other_profiles.emplace_back(item); } - std::sort(prusa_profiles.begin(), prusa_profiles.end(), [](std::pair, bool> a, std::pair, bool> b) { - return a.first.get() < b.first.get(); + 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(), [](std::pair, bool> a, std::pair, bool> b) { - return a.first.get() < b.first.get(); + std::sort(other_profiles.begin(), other_profiles.end(), [](ProfilePrintData a, ProfilePrintData b) { + return a.name.get() < b.name.get(); }); list->Clear(); - for (const auto& item : prusa_profiles) - list->append(std::string(item.first) + (item.second ? "" : " *"), &const_cast(item.first.get())); - for (const auto& item : other_profiles) - list->append(std::string(item.first) + (item.second ? "" : " *"), &const_cast(item.first.get())); + //for (const auto& item : prusa_profiles) + for (int i = 0; i < prusa_profiles.size(); ++i) { + list->append(std::string(prusa_profiles[i].name) + (prusa_profiles[i].omnipresent ? "" : " *"), &const_cast(prusa_profiles[i].name.get())); + list->Check(i, prusa_profiles[i].checked); + } + //for (const auto& item : other_profiles) + for (int i = 0; i < other_profiles.size(); ++i) { + list->append(std::string(other_profiles[i].name) + (other_profiles[i].omnipresent ? "" : " *"), &const_cast(other_profiles[i].name.get())); + list->Check(i + prusa_profiles.size(), other_profiles[i].checked); + } } void PageMaterials::select_material(int i) diff --git a/src/slic3r/GUI/ConfigWizard_private.hpp b/src/slic3r/GUI/ConfigWizard_private.hpp index ac076ec91..0f0febe91 100644 --- a/src/slic3r/GUI/ConfigWizard_private.hpp +++ b/src/slic3r/GUI/ConfigWizard_private.hpp @@ -314,6 +314,14 @@ template struct DataList : public T typedef DataList StringList; typedef DataList PresetList; +struct ProfilePrintData +{ + std::reference_wrapper name; + bool omnipresent; + bool checked; + ProfilePrintData(const std::string& n, bool o, bool c) : name(n), omnipresent(o), checked(c) {} +}; + struct PageMaterials: ConfigWizardPage { Materials *materials; @@ -344,7 +352,7 @@ struct PageMaterials: ConfigWizardPage void clear_compatible_printers_label(); void sort_list_data(StringList* list, bool add_All_item, bool material_type_ordering); - void sort_list_data(PresetList* list, const std::vector, bool>>& data); + void sort_list_data(PresetList* list, const std::vector& data); void on_paint(); void on_mouse_move_on_profiles(wxMouseEvent& evt);