mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-09 18:27:00 +00:00
Move Generic vendor above Bambu vendor in AMS material setting. (#11306)
* Move Generic vendor above Bambu vendor in AMS material setting. * Remove hardcoded sorted_names. Alphabetically sort Bambu with all vendors * Fix sorting with case insensitive comparison * Use arithmetic to get rank distance because priorities are stored in a vector. This lets us remove the <interator> include.
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
#include "GUI_App.hpp"
|
#include "GUI_App.hpp"
|
||||||
#include "libslic3r/Preset.hpp"
|
#include "libslic3r/Preset.hpp"
|
||||||
#include "I18N.hpp"
|
#include "I18N.hpp"
|
||||||
|
#include <algorithm>
|
||||||
#include <boost/log/trivial.hpp>
|
#include <boost/log/trivial.hpp>
|
||||||
#include <wx/colordlg.h>
|
#include <wx/colordlg.h>
|
||||||
#include <wx/dcgraph.h>
|
#include <wx/dcgraph.h>
|
||||||
@@ -1075,20 +1076,7 @@ void AMSMaterialsSetting::Popup(wxString filament, wxString sn, wxString temp_mi
|
|||||||
|
|
||||||
// Sort the filaments
|
// Sort the filaments
|
||||||
{
|
{
|
||||||
std::unordered_map<wxString, int> sorted_names =
|
std::unordered_map<wxString, int> selected_filament_ranks;
|
||||||
{ {"Bambu PLA Basic", 0},
|
|
||||||
{"Bambu PLA Matte", 1},
|
|
||||||
{"Bambu PETG HF", 2},
|
|
||||||
{"Bambu ABS", 3},
|
|
||||||
{"Bambu PLA Silk", 4},
|
|
||||||
{"Bambu PLA-CF" , 5},
|
|
||||||
{"Bambu PLA Galaxy", 6},
|
|
||||||
{"Bambu PLA Metal", 7},
|
|
||||||
{"Bambu PLA Marble", 8},
|
|
||||||
{"Bambu PETG-CF", 9},
|
|
||||||
{"Bambu PETG Translucent", 10},
|
|
||||||
{"Bambu ABS-GF", 11}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Helper lambda to find a filament Preset by name. We can call this multiple times to walk the inheritance chain and find the base filament.
|
// Helper lambda to find a filament Preset by name. We can call this multiple times to walk the inheritance chain and find the base filament.
|
||||||
auto find_filament_by_name = [](const std::string& wanted, const PresetCollection& filaments) -> const Preset* {
|
auto find_filament_by_name = [](const std::string& wanted, const PresetCollection& filaments) -> const Preset* {
|
||||||
@@ -1100,12 +1088,12 @@ void AMSMaterialsSetting::Popup(wxString filament, wxString sn, wxString temp_mi
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
// For each active filament preset, find matching Preset in bundle->filaments and add the base filament alias to sorted_names in highest rank in extruder order
|
// For each active filament preset, find its base filament alias and promote it in extruder order.
|
||||||
auto bundle = wxGetApp().preset_bundle;
|
auto bundle = wxGetApp().preset_bundle;
|
||||||
const auto& preset_names = bundle->filament_presets;
|
const auto& preset_names = bundle->filament_presets;
|
||||||
for (size_t i = preset_names.size(); i-- > 0; ) {
|
for (size_t i = preset_names.size(); i-- > 0; ) {
|
||||||
std::string wanted = preset_names[i];
|
std::string wanted = preset_names[i];
|
||||||
const int sort_rank = -((int)preset_names.size() - i);
|
const int sort_rank = -static_cast<int>(preset_names.size() - i);
|
||||||
|
|
||||||
const Preset* match = nullptr;
|
const Preset* match = nullptr;
|
||||||
|
|
||||||
@@ -1136,42 +1124,57 @@ void AMSMaterialsSetting::Popup(wxString filament, wxString sn, wxString temp_mi
|
|||||||
|
|
||||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Update filament rank to " + std::to_string(sort_rank) + " for preset Name: "
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Update filament rank to " + std::to_string(sort_rank) + " for preset Name: "
|
||||||
<< match->name << " - Alias: " << match->alias;
|
<< match->name << " - Alias: " << match->alias;
|
||||||
sorted_names.insert_or_assign(match->alias, sort_rank);
|
selected_filament_ranks.insert_or_assign(match->alias, sort_rank);
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::vector<wxString> sorted_vendors { "Bambu Lab", "Generic" };
|
static const std::vector<wxString> sorted_vendors { "Generic" };
|
||||||
static std::vector<wxString> sorted_types { "PLA", "PETG", "ABS", "TPU" };
|
static const std::vector<wxString> sorted_types { "PLA", "PETG", "ABS", "TPU" };
|
||||||
auto _filament_sorter = [&query_filament_vendors, &query_filament_types, &sorted_names](const wxString& left, const wxString& right) -> bool
|
auto priority_rank = [](const std::vector<wxString>& priorities, const wxString& value) {
|
||||||
|
const auto iter = std::find_if(priorities.begin(), priorities.end(), [&value](const wxString& priority) {
|
||||||
|
return priority.CmpNoCase(value) == 0;
|
||||||
|
});
|
||||||
|
return iter - priorities.begin();
|
||||||
|
};
|
||||||
|
auto _filament_sorter = [&query_filament_vendors, &query_filament_types, &selected_filament_ranks, &priority_rank](const wxString& left, const wxString& right) -> bool
|
||||||
{
|
{
|
||||||
{ // Compare name order
|
{ // Compare selected filament order
|
||||||
const auto& iter1 = sorted_names.find(left);
|
const auto& iter1 = selected_filament_ranks.find(left);
|
||||||
int name_order1 = (iter1 != sorted_names.end()) ? iter1->second : INT_MAX;
|
int selected_order1 = (iter1 != selected_filament_ranks.end()) ? iter1->second : INT_MAX;
|
||||||
|
|
||||||
const auto& iter2 = sorted_names.find(right);
|
const auto& iter2 = selected_filament_ranks.find(right);
|
||||||
int name_order2 = (iter2 != sorted_names.end()) ? iter2->second : INT_MAX;
|
int selected_order2 = (iter2 != selected_filament_ranks.end()) ? iter2->second : INT_MAX;
|
||||||
if (name_order1 != name_order2)
|
if (selected_order1 != selected_order2)
|
||||||
{
|
{
|
||||||
return name_order1 < name_order2;
|
return selected_order1 < selected_order2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{ // Compare vendor
|
{ // Compare vendor
|
||||||
auto iter1 = std::find(sorted_vendors.begin(), sorted_vendors.end(), query_filament_vendors[left]);
|
const wxString& vendor1 = query_filament_vendors.at(left);
|
||||||
auto iter2 = std::find(sorted_vendors.begin(), sorted_vendors.end(), query_filament_vendors[right]);
|
const wxString& vendor2 = query_filament_vendors.at(right);
|
||||||
if (iter1 != iter2)
|
const auto rank1 = priority_rank(sorted_vendors, vendor1);
|
||||||
{
|
const auto rank2 = priority_rank(sorted_vendors, vendor2);
|
||||||
return iter1 < iter2;
|
if (rank1 != rank2)
|
||||||
};
|
return rank1 < rank2;
|
||||||
|
|
||||||
|
const int vendor_compare = vendor1.CmpNoCase(vendor2);
|
||||||
|
if (vendor_compare != 0)
|
||||||
|
return vendor_compare < 0;
|
||||||
}
|
}
|
||||||
{ // Compare type
|
{ // Compare type
|
||||||
auto iter1 = std::find(sorted_types.begin(), sorted_types.end(), query_filament_types[left]);
|
const wxString& type1 = query_filament_types.at(left);
|
||||||
auto iter2 = std::find(sorted_types.begin(), sorted_types.end(), query_filament_types[right]);
|
const wxString& type2 = query_filament_types.at(right);
|
||||||
if (iter1 != iter2)
|
const auto rank1 = priority_rank(sorted_types, type1);
|
||||||
{
|
const auto rank2 = priority_rank(sorted_types, type2);
|
||||||
return iter1 < iter2;
|
if (rank1 != rank2)
|
||||||
}
|
return rank1 < rank2;
|
||||||
|
|
||||||
|
const int type_compare = type1.CmpNoCase(type2);
|
||||||
|
if (type_compare != 0)
|
||||||
|
return type_compare < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return left < right;
|
const int name_compare = left.CmpNoCase(right);
|
||||||
|
return name_compare != 0 ? name_compare < 0 : left < right;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::sort(filament_items.begin(), filament_items.end(), _filament_sorter);
|
std::sort(filament_items.begin(), filament_items.end(), _filament_sorter);
|
||||||
|
|||||||
Reference in New Issue
Block a user