From c740ddf0a62e0f5dc21f9e1d6af128fcb2c5b8a2 Mon Sep 17 00:00:00 2001 From: SoftFever Date: Wed, 7 Oct 2026 01:45:24 +0800 Subject: [PATCH] Publish each extruder's own retraction and Z-hop values --- src/slic3r/GUI/PublishSettingsDialog.cpp | 4 +++- src/slic3r/GUI/Tab.cpp | 24 ++++++++++++------------ src/slic3r/GUI/Tab.hpp | 3 +++ 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/slic3r/GUI/PublishSettingsDialog.cpp b/src/slic3r/GUI/PublishSettingsDialog.cpp index 70cdfe51c9..7beb3bd9dd 100644 --- a/src/slic3r/GUI/PublishSettingsDialog.cpp +++ b/src/slic3r/GUI/PublishSettingsDialog.cpp @@ -882,6 +882,8 @@ void PublishSettingsDialog::build_option_model() const size_t extruders_count = printer_tab->m_extruders_count; for (size_t extruder_idx = 0; extruder_idx < extruders_count; ++extruder_idx) { const wxString page_title = Tab::translate_category(extruders_count > 1 ? wxString::Format("Extruder %d", int(extruder_idx + 1)) : wxString("Extruder"), tab->m_type); + // Retraction and Z-Hop values are stored per variant column, not per extruder. + const int variant_index = printer_tab->extruder_variant_index(int(extruder_idx)); for (const ConfigOptionsGroupShp& optgroup : page->m_optgroups) { // Allowlist on the untranslated optgroup title; the "Retraction when // switching material" group is intentionally skipped. @@ -893,7 +895,7 @@ void PublishSettingsDialog::build_option_model() // Rows are keyed by the full per-extruder "#N" opt_id so each extruder // tab publishes its own value; GetPublishedKeys() emits the checked rows // as-is. - const std::string opt_id = pure_key + "#" + std::to_string(extruder_idx); + const std::string opt_id = pure_key + "#" + std::to_string(variant_index); if (!printer_added.insert(opt_id).second) continue; wxString label, value, unit; diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 2c6fbff835..80b930c35e 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -6225,12 +6225,6 @@ void TabPrinter::toggle_options() return; auto nozzle_volumes = m_preset_bundle->project_config.option("nozzle_volume_type"); - auto extruders = m_config->option("extruder_type"); - auto get_index_for_extruder = - [this, &extruders](int extruder_id, int stride = 1) { - return m_config->get_index_for_extruder(extruder_id + 1, "printer_extruder_id", - ExtruderType(extruders->values[extruder_id]), get_actual_nozzle_volume_type(extruder_id), "printer_extruder_variant", stride); - }; //BBS: whether the preset is Bambu Lab printer bool is_BBL_printer = false; @@ -6311,9 +6305,7 @@ void TabPrinter::toggle_options() // controls carry field index 0 (i), the values are read for `extruder`. const size_t i = 0; const size_t extruder = std::min(size_t(get_current_active_extruder()), m_extruders_count - 1); - int variant_index = get_index_for_extruder(extruder); - if (variant_index < 0) - variant_index = int(extruder); + const int variant_index = extruder_variant_index(int(extruder)); bool have_retract_length = m_config->opt_float("retraction_length", variant_index) > 0; toggle_option("extruder_printable_area", false, i); // disable @@ -8452,6 +8444,16 @@ int TabPrinter::extruder_page_data_index(const std::string &field_id) const return -1; } +int TabPrinter::extruder_variant_index(int extruder) +{ + const auto *extruders = m_config->option("extruder_type"); + const int index = extruder < int(extruders->size()) ? + m_config->get_index_for_extruder(extruder + 1, "printer_extruder_id", ExtruderType(extruders->values[extruder]), + get_actual_nozzle_volume_type(extruder), "printer_extruder_variant") : + -1; + return index < 0 ? extruder : index; +} + void TabPrinter::update_custom_dirty(std::vector &dirty_options, std::vector &nonsys_options) { drop_unchanged_added_entries(dirty_options, *m_config, &m_presets->get_selected_preset()); @@ -8641,9 +8643,7 @@ void Tab::switch_excluder(int extruder_id, bool reload) if (m_type == Preset::TYPE_PRINTER) { if (page->title() == "Extruder") { is_extruder = true; - page_index = page_extruder < int(extruders->size()) ? get_index_for_extruder(page_extruder) : -1; - if (page_index < 0) - page_index = page_extruder; + page_index = static_cast(this)->extruder_variant_index(page_extruder); } else if (page->title().StartsWith("Motion ability")) { page_index = get_index_for_extruder(common_extruder, 2); } diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index c02ef74823..f7ebafcbe3 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -726,6 +726,9 @@ public: Page* extruder_page() const; // Config index an "Extruder" page field (e.g. "retraction_length#0") currently edits, -1 if not on that page. int extruder_page_data_index(const std::string& field_id) const; + // Config index of an extruder's per-variant options (Retraction, Z-Hop, ...): its variant column + // for the nozzle selected on the switch, or the extruder index on a printer without variants. + int extruder_variant_index(int extruder); // After the config was restored (roll back): follow its extruder count, if it differs. void sync_extruders_count(); // Search jump to "Extruder N" / "key#N": selects extruder N on the switch, then activates the