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 <yw4z@outlook.com>

* 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 <yw4z@outlook.com>
This commit is contained in:
Ian Bassi
2026-02-13 01:24:24 -03:00
committed by GitHub
parent 6c900535e5
commit f38324d521
2 changed files with 21 additions and 6 deletions

View File

@@ -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<const ConfigOptionFloats*>(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) {

View File

@@ -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)