From f38324d52187650ff57120d4d52d7d8339aaeaff Mon Sep 17 00:00:00 2001 From: Ian Bassi Date: Fri, 13 Feb 2026 01:24:24 -0300 Subject: [PATCH] Fix: Nozzle list (#11836) * Fix extruder_id out-of-bounds in switch_excluder Added a check to reset extruder_id to 0 if it exceeds the size of nozzle_volumes or extruders, preventing potential out-of-bounds access. Co-Authored-By: Christopher R. Palmer <1305033+crpalmer@users.noreply.github.com> * Add custom nozzle diameter option in sidebar Ensures that if the actual nozzle diameter is not present in the list, it is added as a custom option. This improves user experience by allowing selection of non-standard nozzle diameters. Refactor nozzle diameter selection logic in Sidebar Simplified the logic for updating the extruder nozzle diameter combo box by removing redundant checks and streamlining the addition of custom nozzle diameters. This improves code clarity and ensures the actual nozzle diameter from the printer config is always considered. Co-Authored-By: yw4z * Prevent profile switch if selected diameter matches nozzle Adds a check in Sidebar::priv::switch_diameter to avoid switching printer profiles when the selected diameter matches the current nozzle diameter in the configuration. This prevents unnecessary profile changes and improves user experience. --------- Co-authored-by: Christopher R. Palmer <1305033+crpalmer@users.noreply.github.com> Co-authored-by: yw4z --- src/slic3r/GUI/Plater.cpp | 25 +++++++++++++++++++------ src/slic3r/GUI/Tab.cpp | 2 ++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index c1b042a34e..4ceca9a260 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1236,6 +1236,18 @@ bool Sidebar::priv::switch_diameter(bool single) diameter = diameter_left; } } + + // ORCA: Check if the selected diameter matches the current nozzle diameter in the config + Preset& printer_preset = wxGetApp().preset_bundle->printers.get_edited_preset(); + auto* nozzle_diameter = dynamic_cast(printer_preset.config.option("nozzle_diameter")); + if (nozzle_diameter && nozzle_diameter->size() > 0) { + auto current_nozzle_dia = get_diameter_string(nozzle_diameter->values[0]); + // If the selected diameter is the same as current nozzle, don't switch profiles + if (current_nozzle_dia == diameter.ToStdString()) { + return true; + } + } + auto preset = wxGetApp().preset_bundle->get_similar_printer_preset({}, diameter.ToStdString()); if (preset == nullptr) { // ORCA add a text. this appears when user tries to change nozzle value but config doesnt have a inherited or compatible preset @@ -2563,22 +2575,23 @@ void Sidebar::update_presets(Preset::Type preset_type) auto update_extruder_diameter = [&diameters, &diameter, &nozzle_diameter](int extruder_index,ExtruderGroup & extruder) { extruder.combo_diameter->Clear(); int select = -1; - // ORCA if user defined a custom nozzle in printer config select it instead inherited one. this will show correct nozzle diameter in combobox if its exist in nozzle diameters list + // ORCA get the actual nozzle diameter from printer config auto nozzle_dia = get_diameter_string(nozzle_diameter->values[extruder_index]); - if(nozzle_dia != diameter && std::find(diameters.begin(), diameters.end(), nozzle_dia) != diameters.end()) - diameter = nozzle_dia; // ORCA try to add nozzle diameter from config if list is empty. fixes blank nozzle combo box when preset has no alias if(diameters[0].empty() && !nozzle_dia.empty()){ diameters[0] = nozzle_dia; - diameter = nozzle_dia; + } + // Orca: Check if the actual nozzle diameter exists in the list, if not add it as a custom option + if (std::find(diameters.begin(), diameters.end(), nozzle_dia) == diameters.end() && !nozzle_dia.empty()) { + diameters.push_back(nozzle_dia); } for (size_t i = 0; i < diameters.size(); ++i) { - if (diameters[i] == diameter) + if (diameters[i] == nozzle_dia) select = extruder.combo_diameter->GetCount(); extruder.combo_diameter->Append(diameters[i], {}); } extruder.combo_diameter->SetSelection(select); - extruder.diameter = diameter; + extruder.diameter = nozzle_dia; }; auto image_path = get_cur_select_bed_image(); if (is_dual_extruder) { diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 75b6dbb54e..029b585f60 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -6961,6 +6961,8 @@ void Tab::switch_excluder(int extruder_id) {}, {"", "filament_extruder_variant"}, // Preset::TYPE_FILAMENT filament don't use id anymore {}, {"printer_extruder_id", "printer_extruder_variant"}, // Preset::TYPE_PRINTER }; + if (extruder_id >= nozzle_volumes->size() || extruder_id >= extruders->size()) + extruder_id = 0; if (m_extruder_switch && m_type != Preset::TYPE_PRINTER) { int current_extruder = m_extruder_switch->GetValue() ? 1 : 0; if (extruder_id == -1)