Custom grouping options for user filament presets (All, None, By Vendor, By Type) (#11681)
Some checks are pending
Build all / Build Linux (push) Waiting to run
Build all / Build Non-Linux (push) Waiting to run
Build all / Unit Tests (push) Blocked by required conditions
Build all / Flatpak (push) Waiting to run

* Update PresetComboBoxes.cpp

* add option on preferences

* simplify changes

* update

* Update PresetComboBoxes.cpp

* Update PresetComboBoxes.cpp

* support lowercase on sorting non submenu list

* minor changes

---------

Co-authored-by: Ioannis Giannakas <59056762+igiannakas@users.noreply.github.com>
Co-authored-by: SoftFever <softfeverever@gmail.com>
This commit is contained in:
yw4z 2025-12-29 18:37:36 +03:00 committed by GitHub
parent 3dc80593bd
commit e8af78d032
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 49 additions and 8 deletions

View file

@ -318,6 +318,10 @@ void AppConfig::set_defaults()
set_bool("remember_printer_config", true);
}
if (get("group_filament_presets").empty()) {
set("group_filament_presets", "1"); // All "0" / None "1" / By Type "2" / By Vendor "3"
}
if (get("enable_high_low_temp_mixed_printing").empty()){
set_bool("enable_high_low_temp_mixed_printing", false);
}

View file

@ -78,7 +78,7 @@ std::tuple<wxBoxSizer*, ComboBox*> PreferencesDialog::create_item_combobox_base(
return {m_sizer_combox, combobox};
}
wxBoxSizer* PreferencesDialog::create_item_combobox(wxString title, wxString tooltip, std::string param, std::vector<wxString> vlist)
wxBoxSizer* PreferencesDialog::create_item_combobox(wxString title, wxString tooltip, std::string param, std::vector<wxString> vlist, std::function<void(wxString)> onchange)
{
unsigned int current_index = 0;
@ -90,8 +90,10 @@ wxBoxSizer* PreferencesDialog::create_item_combobox(wxString title, wxString too
auto [sizer, combobox] = create_item_combobox_base(title, tooltip, param, vlist, current_index);
//// save config
combobox->GetDropDown().Bind(wxEVT_COMBOBOX, [this, param](wxCommandEvent& e) {
combobox->GetDropDown().Bind(wxEVT_COMBOBOX, [this, param, onchange](wxCommandEvent& e) {
app_config->set(param, std::to_string(e.GetSelection()));
if (onchange)
onchange(std::to_string(e.GetSelection()));
e.Skip();
});
@ -1289,6 +1291,10 @@ void PreferencesDialog::create_items()
auto item_remember_printer = create_item_checkbox(_L("Remember printer configuration"), _L("If enabled, Orca will remember and switch filament/process configuration for each printer automatically."), "remember_printer_config");
g_sizer->Add(item_remember_printer);
auto item_filament_preset_grouping = create_item_combobox(_L("Group user filament presets"), _L("Group user filament presets based on selection"),
"group_filament_presets", {_L("All"), _L("None"), _L("By type"), _L("By vendor")}, [](wxString value) {wxGetApp().plater()->sidebar().update_presets(Preset::TYPE_FILAMENT);});
g_sizer->Add(item_filament_preset_grouping);
//// GENERAL > Features
g_sizer->Add(create_item_title(_L("Features")), 1, wxEXPAND);

View file

@ -77,7 +77,7 @@ public:
std::vector<wxFlexGridSizer*> f_sizers;
wxBoxSizer *create_item_title(wxString title);
wxBoxSizer *create_item_combobox(wxString title, wxString tooltip, std::string param, std::vector<wxString> vlist);
wxBoxSizer *create_item_combobox(wxString title, wxString tooltip, std::string param, std::vector<wxString> vlist, std::function<void(wxString)> onchange = {});
wxBoxSizer *create_item_combobox(wxString title, wxString tooltip, std::string param, std::vector<wxString> vlist, std::vector<std::string> config_name_index);
wxBoxSizer *create_item_region_combobox(wxString title, wxString tooltip);
wxBoxSizer *create_item_language_combobox(wxString title, wxString tooltip);

View file

@ -1132,6 +1132,7 @@ void PlaterPresetComboBox::update()
std::map<wxString, wxString> preset_descriptions;
std::map<wxString, std::string> preset_filament_vendors;
std::map<wxString, std::string> preset_filament_types;
std::map<wxString, std::string> preset_filament_names; // ORCA
//BBS: move system to the end
wxString selected_system_preset;
wxString selected_user_preset;
@ -1174,7 +1175,8 @@ void PlaterPresetComboBox::update()
bitmap_key += single_bar ? filament_rgb : filament_rgb + extruder_rgb;
#endif
if (preset.is_system) {
// ORCA allow caching vendor and type values for all presets instead just system ones
// if (preset.is_system) {
if (!preset.is_compatible && preset_filament_vendors.count(name) > 0)
continue;
else if (preset.is_compatible && preset_filament_vendors.count(name) > 0)
@ -1183,7 +1185,8 @@ void PlaterPresetComboBox::update()
if (preset_filament_vendors[name] == "Bambu Lab")
preset_filament_vendors[name] = "Bambu";
preset_filament_types[name] = preset.config.option<ConfigOptionStrings>("filament_type")->values.at(0);
}
preset_filament_names[name] = name.ToStdString(); // ORCA
//}
}
wxBitmap* bmp = get_bmp(preset);
assert(bmp);
@ -1251,7 +1254,7 @@ void PlaterPresetComboBox::update()
"Bambu PLA Galaxy", "Bambu PLA Metal", "Bambu PLA Marble", "Bambu PETG-CF", "Bambu PETG Translucent", "Bambu ABS-GF"};
std::vector<std::string> first_vendors = {"", "Bambu", "Generic"}; // Empty vendor for non-system presets
std::vector<std::string> first_types = {"PLA", "PETG", "ABS", "TPU"};
auto add_presets = [this, &preset_descriptions, &filament_orders, &preset_filament_vendors, &first_vendors, &preset_filament_types, &first_types, &selected_in_ams]
auto add_presets = [this, &preset_descriptions, &filament_orders, &preset_filament_vendors, &first_vendors, &preset_filament_types, &preset_filament_names, &first_types, &selected_in_ams]
(std::map<wxString, wxBitmap *> const &presets, wxString const &selected, std::string const &group, wxString const &groupName) {
if (!presets.empty()) {
set_label_marker(Append(_L(group), wxNullBitmap, DD_ITEM_STYLE_SPLIT_ITEM));
@ -1285,9 +1288,31 @@ void PlaterPresetComboBox::update()
}
return l->first < r->first;
});
// ORCA add sorting support for vendor / type for user presets. also non grouped items
if (groupName == "by_vendor" || groupName == "by_type" || groupName == ""){
auto by = groupName == "by_vendor" ? preset_filament_vendors
: groupName == "by_type" ? preset_filament_types
: preset_filament_names;
std::sort(list.begin(), list.end(), [&by](auto *l, auto *r) {
auto get_key = [&](auto* item) -> std::pair<bool, std::string> {
std::string str = by.count(item->first) ? by.at(item->first) : "";
std::transform(str.begin(), str.end(), str.begin(), [](unsigned char c) { return std::tolower(c);});
return {!str.empty(), str}; // is_valid, lower_case
};
auto [l_valid, l_lower] = get_key(l);
auto [r_valid, r_lower] = get_key(r);
return (l_valid != r_valid) ? l_valid > r_valid
: (l_lower != r_lower) ? l_lower < r_lower
: l->first < r->first;
});
}
bool unsupported = group == "Unsupported presets";
for (auto it : list) {
auto groupName2 = groupByGroup ? groupName : preset_filament_vendors[it->first];
// ORCA add sorting support for vendor / type for user presets
auto groupName2 = groupName == "by_type" ? (preset_filament_types[it->first].empty() ? _L("Unspecified") : preset_filament_types[it->first])
: groupName == "by_vendor" ? (preset_filament_vendors[it->first].empty() ? _L("Unspecified") : preset_filament_vendors[it->first])
: groupByGroup ? groupName
: preset_filament_vendors[it->first];
int index = Append(it->first, *it->second, groupName2, nullptr, unsupported ? DD_ITEM_STYLE_DISABLED : 0);
if (unsupported)
set_label_marker(index, LABEL_ITEM_DISABLED);
@ -1311,7 +1336,13 @@ void PlaterPresetComboBox::update()
//BBS: add project embedded preset logic
add_presets(project_embedded_presets, selected_user_preset, L("Project-inside presets"), _L("Project") + " ");
add_presets(nonsys_presets, selected_user_preset, L("User presets"), _L("Custom") + " ");
// ORCA add sorting support for vendor / type for user presets
auto group_filament_presets = wxGetApp().app_config->get("group_filament_presets");
auto group_filament_presets_by = group_filament_presets == "0" ? (_L("Custom") + " ") // Append all to "Custom" sub menu
: group_filament_presets == "2" ? "by_type" // Create sub menus with filament type
: group_filament_presets == "3" ? "by_vendor" // Create sub menus with filament vendor
: ""; // Use without sub menu
add_presets(nonsys_presets, selected_user_preset, L("User presets"), group_filament_presets_by);
// BBS: move system to the end
add_presets(system_presets, selected_system_preset, L("System presets"), _L("System"));
add_presets(uncompatible_presets, {}, L("Unsupported presets"), _L("Unsupported") + " ");