mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-08-10 03:27:35 +00:00
Show current filaments at top of AMS filament dropdown (#11293)
* Move currently active filaments added to the Prepare sidebar to the top of the AMS Material Selection combo box. It is likely the user wants to set the material to the currently active filament. * Reduce logging verbosity. * Refactor current active preset filament finding to find nested preset inheritance. * Initialize pointer to null before usage. * Remove old commit code * Remove new line --------- Co-authored-by: Ioannis Giannakas <59056762+igiannakas@users.noreply.github.com> Co-authored-by: yw4z <ywsyildiz@gmail.com>
This commit is contained in:
@@ -1075,7 +1075,7 @@ void AMSMaterialsSetting::Popup(wxString filament, wxString sn, wxString temp_mi
|
||||
|
||||
// Sort the filaments
|
||||
{
|
||||
static std::unordered_map<wxString, int> sorted_names
|
||||
std::unordered_map<wxString, int> sorted_names =
|
||||
{ {"Bambu PLA Basic", 0},
|
||||
{"Bambu PLA Matte", 1},
|
||||
{"Bambu PETG HF", 2},
|
||||
@@ -1090,9 +1090,58 @@ void AMSMaterialsSetting::Popup(wxString filament, wxString sn, wxString temp_mi
|
||||
{"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.
|
||||
auto find_filament_by_name = [](const std::string& wanted, const PresetCollection& filaments) -> const Preset* {
|
||||
for (auto it = filaments.begin(); it != filaments.end(); ++it) {
|
||||
if (it->name == wanted) {
|
||||
return &(*it);
|
||||
}
|
||||
}
|
||||
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
|
||||
auto bundle = wxGetApp().preset_bundle;
|
||||
const auto& preset_names = bundle->filament_presets;
|
||||
for (size_t i = preset_names.size(); i-- > 0; ) {
|
||||
std::string wanted = preset_names[i];
|
||||
const int sort_rank = -((int)preset_names.size() - i);
|
||||
|
||||
const Preset* match = nullptr;
|
||||
|
||||
do {
|
||||
auto find_result = find_filament_by_name(wanted, bundle->filaments);
|
||||
if (!find_result) {
|
||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " No available filament name matches " << wanted;
|
||||
break;
|
||||
}
|
||||
|
||||
match = find_result;
|
||||
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Found available filament matching current preset name " << wanted
|
||||
<< " - Name: " << match->name << " - Alias: " << match->alias
|
||||
<< " - Inherits: " << match->inherits();
|
||||
|
||||
if (match->inherits().length() == 0) {
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " No more inherits so we reached the base filament";
|
||||
break;
|
||||
}
|
||||
|
||||
wanted = match->inherits();
|
||||
} while (1); // Or loop while (match->alias.length() == 0) because existence of alias and inherits on a Preset seem to be exclusive
|
||||
|
||||
if (!match) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Update filament rank to " + std::to_string(sort_rank) + " for preset Name: "
|
||||
<< match->name << " - Alias: " << match->alias;
|
||||
sorted_names.insert_or_assign(match->alias, sort_rank);
|
||||
}
|
||||
|
||||
static std::vector<wxString> sorted_vendors { "Bambu Lab", "Generic" };
|
||||
static std::vector<wxString> sorted_types { "PLA", "PETG", "ABS", "TPU" };
|
||||
auto _filament_sorter = [&query_filament_vendors, &query_filament_types](const wxString& left, const wxString& right) -> bool
|
||||
auto _filament_sorter = [&query_filament_vendors, &query_filament_types, &sorted_names](const wxString& left, const wxString& right) -> bool
|
||||
{
|
||||
{ // Compare name order
|
||||
const auto& iter1 = sorted_names.find(left);
|
||||
|
||||
Reference in New Issue
Block a user