From e8af78d032a0dadf2e4a8e44a8b4c9ca48912efd Mon Sep 17 00:00:00 2001 From: yw4z Date: Mon, 29 Dec 2025 18:37:36 +0300 Subject: [PATCH] Custom grouping options for user filament presets (All, None, By Vendor, By Type) (#11681) * 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 --- src/libslic3r/AppConfig.cpp | 4 +++ src/slic3r/GUI/Preferences.cpp | 10 +++++-- src/slic3r/GUI/Preferences.hpp | 2 +- src/slic3r/GUI/PresetComboBoxes.cpp | 41 +++++++++++++++++++++++++---- 4 files changed, 49 insertions(+), 8 deletions(-) diff --git a/src/libslic3r/AppConfig.cpp b/src/libslic3r/AppConfig.cpp index 16f6a4a606..f91c83ad82 100644 --- a/src/libslic3r/AppConfig.cpp +++ b/src/libslic3r/AppConfig.cpp @@ -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); } diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index db330f84c8..61352e18dd 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -78,7 +78,7 @@ std::tuple PreferencesDialog::create_item_combobox_base( return {m_sizer_combox, combobox}; } -wxBoxSizer* PreferencesDialog::create_item_combobox(wxString title, wxString tooltip, std::string param, std::vector vlist) +wxBoxSizer* PreferencesDialog::create_item_combobox(wxString title, wxString tooltip, std::string param, std::vector vlist, std::function 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); diff --git a/src/slic3r/GUI/Preferences.hpp b/src/slic3r/GUI/Preferences.hpp index ecd591e089..28ce3afb97 100644 --- a/src/slic3r/GUI/Preferences.hpp +++ b/src/slic3r/GUI/Preferences.hpp @@ -77,7 +77,7 @@ public: std::vector f_sizers; wxBoxSizer *create_item_title(wxString title); - wxBoxSizer *create_item_combobox(wxString title, wxString tooltip, std::string param, std::vector vlist); + wxBoxSizer *create_item_combobox(wxString title, wxString tooltip, std::string param, std::vector vlist, std::function onchange = {}); wxBoxSizer *create_item_combobox(wxString title, wxString tooltip, std::string param, std::vector vlist, std::vector config_name_index); wxBoxSizer *create_item_region_combobox(wxString title, wxString tooltip); wxBoxSizer *create_item_language_combobox(wxString title, wxString tooltip); diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index 5006c5eab0..2e5f83c211 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -1132,6 +1132,7 @@ void PlaterPresetComboBox::update() std::map preset_descriptions; std::map preset_filament_vendors; std::map preset_filament_types; + std::map 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("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 first_vendors = {"", "Bambu", "Generic"}; // Empty vendor for non-system presets std::vector 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 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 { + 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") + " ");