Keep mixed-color filaments intact when the extruder count changes (#15385)

* Keep mixed-color filaments intact when the extruder count changes

The extruder-count spinner resized the filament arrays in bulk at the tail,
which is where mixed-color slots live, so a new filament landed behind the
mix and the sidebar skipped a slot number. It now adds and removes one slot
at a time through the same calls the sidebar's +/- buttons use, so a new
slot opens ahead of the mixed tail and a removal renumbers object filament
ids, painted facets, custom g-code and mixed components rather than
clamping them away.

Drops the vector overload of set_num_filaments(), which this leaves without
callers.
This commit is contained in:
SoftFever
2026-08-26 19:06:33 +08:00
committed by GitHub
parent 9dc9b42475
commit 5552ed6cf1
6 changed files with 246 additions and 88 deletions
+7 -4
View File
@@ -5506,12 +5506,15 @@ void Sidebar::add_custom_filament(wxColour new_col, const std::string& preset_na
// Mixed-color slots are kept at the tail of the filament arrays, so a new physical
// filament has to be inserted just after the last physical one rather than appended.
// total == every slot (physical + mixed); insert_pos == the physical slot count.
size_t total = wxGetApp().preset_bundle->filament_presets.size();
size_t insert_pos = p->combos_filament.size();
// Count off filament_is_mixed, not filament_presets or the combos: the extruder-count spinner
// reaches this before the sidebar has rebuilt, and update_multi_material_filament_presets()
// can have grown filament_presets alone.
auto *bundle = wxGetApp().preset_bundle;
size_t insert_pos = bundle->num_physical_filaments();
size_t total = insert_pos + bundle->num_mixed_filaments();
int filament_count = (int)(total + 1);
std::string new_color = new_col.GetAsString(wxC2S_HTML_SYNTAX).ToStdString();
wxGetApp().preset_bundle->set_num_filaments(filament_count, new_color);
bundle->set_num_filaments(filament_count, new_color);
// Maintain physical-first ordering: rotate the new slot from end to insert_pos.
// No mixed slots -> insert_pos == total -> every rotate below is a no-op.