From aa3291b380b97ebdc78554b99f005a28450db352 Mon Sep 17 00:00:00 2001 From: Lam Wei Lun Date: Wed, 28 Oct 2026 15:55:22 +0800 Subject: [PATCH] Publish per-extruder process settings in the Publish 3MF dialog (#16971) * Publish per-extruder process settings in the Publish 3MF dialog Process settings that differ per extruder (speeds, accelerations, jerk, top surface flow ratio) were published as one row showing extruder 1 and exported as the whole vector, so the dialog could not select an extruder's value and checking the row shipped every extruder's value. - Dialog: one tab per extruder, as in the Printer section. On a multi-extruder printer the tabs sit behind a MultiSwitchButton below the page tabs; each row is keyed "key#N" and reads the uncompacted config. Pre-check follows each row's own key. Single-extruder printers get one "Extruder" page tab. - Export: "key#N" process keys are masked to the checked slot, as printer keys already are. - Import: the file carries the author's print extruder layout. Process keys map by extruder number and nozzle type on multi-extruder receivers. Single-extruder receivers keep the positional import. Files without the layout keep the positional import. - Reopening a file without the layout: its "key#N" process entries select that setting on every extruder, so re-publishing keeps the values it had. - MultiSwitchButton gains Unselect(), which clears the selection without an event. * Fixes clang-tidy * Fix per-extruder masking test to use the nullable outer_wall_speed type outer_wall_speed is ConfigOptionFloatsNullable, so the ConfigOptionFloats casts in the test returned null and the test segfaulted. --- src/libslic3r/PresetBundle.cpp | 17 +- src/libslic3r/PresetBundle.hpp | 3 + src/libslic3r/PublishSettings.cpp | 22 +- src/libslic3r/PublishSettings.hpp | 5 + src/slic3r/GUI/MainFrame.cpp | 6 +- src/slic3r/GUI/Plater.cpp | 32 ++- src/slic3r/GUI/Plater.hpp | 2 +- src/slic3r/GUI/PublishSettingsDialog.cpp | 203 ++++++++++++++---- src/slic3r/GUI/PublishSettingsDialog.hpp | 23 +- src/slic3r/GUI/Tab.cpp | 9 + src/slic3r/GUI/Tab.hpp | 3 + src/slic3r/GUI/Widgets/SwitchButton.cpp | 9 + src/slic3r/GUI/Widgets/SwitchButton.hpp | 2 + tests/libslic3r/test_3mf.cpp | 43 ++++ .../libslic3r/test_preset_bundle_loading.cpp | 28 +++ 15 files changed, 342 insertions(+), 65 deletions(-) diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index 1d8b0edf3c..58afa7d344 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -6446,8 +6446,12 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool // (the author's "left or right" whichever came first), the rest are reported as // skipped. Per-target, so the process and printer passes each track their own bases. std::set collapsed_bases; - // Printer pass only: process keys keep the positional import. - const bool by_identity = allowlist != nullptr && !published_config->printer_layout.extruder_ids.empty(); + // Per-extruder keys map by extruder identity when the file carries this pass's layout. Printer + // keys do so on any receiver; process keys only on a multi-extruder receiver, a single-extruder + // receiver keeps the positional / collapse import. + const bool is_printer_pass = allowlist != nullptr; + const PublishedExtruderLayout& layout = is_printer_pass ? published_config->printer_layout : published_config->print_layout; + const bool by_identity = !layout.extruder_ids.empty() && (is_printer_pass || this->get_printer_extruder_count() >= 2); for (const std::string& key : published_config->published_keys) { if (applied_keys.count(key) != 0) continue; // already applied @@ -6503,9 +6507,12 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool continue; // malformed or out-of-range on the author's side: cannot apply; reported as skipped const size_t dst_size = static_cast(dst_opt)->size(); if (by_identity) { - // Printer keys go to the receiver's extruder with the author's number, in the - // nozzle type it runs now. Anything that does not resolve stays unapplied and is reported. - const int slot = resolve_published_extruder_slot(published_config->printer_layout, idx, target, this->project_config); + // Each key goes to the receiver's extruder with the author's number, in the nozzle + // type it runs now. Anything that does not resolve stays unapplied and is reported. + const int slot = is_printer_pass ? + resolve_published_extruder_slot(layout, idx, target, this->project_config) : + resolve_published_extruder_slot(layout, idx, this->printers.get_edited_preset().config, this->project_config, + target, "print_extruder_id", "print_extruder_variant"); if (slot < 0 || size_t(slot) >= dst_size) continue; static_cast(dst_opt)->set_at(src_opt, size_t(slot), idx); diff --git a/src/libslic3r/PresetBundle.hpp b/src/libslic3r/PresetBundle.hpp index 7e10ddfdae..af2a4302fa 100644 --- a/src/libslic3r/PresetBundle.hpp +++ b/src/libslic3r/PresetBundle.hpp @@ -206,6 +206,9 @@ struct PublishedConfig // The author's printer extruder layout. When set, published printer keys map to the receiver's // extruder with the author's number (see resolve_published_extruder_slot). PublishedExtruderLayout printer_layout; + // The author's process extruder layout (print_extruder_id / print_extruder_variant). Empty for + // files published before per-extruder process keys were exported; those import positionally. + PublishedExtruderLayout print_layout; }; // Bundle of Print + Filament + Printer presets. diff --git a/src/libslic3r/PublishSettings.cpp b/src/libslic3r/PublishSettings.cpp index ca2dc6effe..7e6f3f142e 100644 --- a/src/libslic3r/PublishSettings.cpp +++ b/src/libslic3r/PublishSettings.cpp @@ -234,23 +234,23 @@ DynamicPrintConfig filter_published_config( mask_exempt_keys.insert(key); } - // 3. Process and printer published keys. Printer per-extruder keys carry a "#N" variant - // (e.g. retraction_length#2): mask the base to the author's extruder index so a partial - // publish does not serialize every extruder's value (same slot-masking as the material side). + // 3. Process and printer published keys. Per-extruder keys carry a "#N" variant (e.g. + // retraction_length#2, outer_wall_speed#1): mask the base to the author's extruder index so a + // partial publish does not serialize every extruder's value (same slot-masking as the material side). const std::set &printer_keys = publishable_printer_keys(); for (const std::string &key : published_keys) { const std::string base_key = publish_base_key(key); if (base_key.empty()) continue; base_keys_to_include.insert(base_key); - if (printer_keys.count(base_key) != 0) { + if (printer_keys.count(base_key) != 0 || print_options_with_variant.count(base_key) != 0) { const int variant_idx = publish_variant_index(key, base_key); if (variant_idx >= 0) slot_mask_map[base_key].insert(variant_idx); else - mask_exempt_keys.insert(base_key); // bare printer key or malformed variant: whole vector + mask_exempt_keys.insert(base_key); // bare key or malformed variant: whole vector } else { - mask_exempt_keys.insert(base_key); // process key: whole vector + mask_exempt_keys.insert(base_key); // other process keys: whole vector } } @@ -318,6 +318,14 @@ DynamicPrintConfig filter_published_config( int resolve_published_extruder_slot(const PublishedExtruderLayout &author, size_t author_index, const DynamicPrintConfig &receiver_printer, const DynamicPrintConfig &receiver_project) +{ + return resolve_published_extruder_slot(author, author_index, receiver_printer, receiver_project, receiver_printer, + "printer_extruder_id", "printer_extruder_variant"); +} + +int resolve_published_extruder_slot(const PublishedExtruderLayout &author, size_t author_index, + const DynamicPrintConfig &receiver_printer, const DynamicPrintConfig &receiver_project, + const DynamicPrintConfig &receiver_target, const std::string &id_key, const std::string &variant_key) { if (author_index >= author.extruder_ids.size() || author_index >= author.variants.size()) return -1; @@ -335,7 +343,7 @@ int resolve_published_extruder_slot(const PublishedExtruderLayout &author, size_ const NozzleVolumeType nozzle_type = NozzleVolumeType(volumes->values[e]); if (nozzle_type == nvtHybrid || author.variants[author_index] != get_extruder_variant_string(extruder_type, nozzle_type)) return -1; - return receiver_printer.get_index_for_extruder(author_extruder, "printer_extruder_id", extruder_type, nozzle_type, "printer_extruder_variant"); + return receiver_target.get_index_for_extruder(author_extruder, id_key, extruder_type, nozzle_type, variant_key); } } // namespace Slic3r diff --git a/src/libslic3r/PublishSettings.hpp b/src/libslic3r/PublishSettings.hpp index b61505efda..b8e9d1d45b 100644 --- a/src/libslic3r/PublishSettings.hpp +++ b/src/libslic3r/PublishSettings.hpp @@ -108,6 +108,11 @@ DynamicPrintConfig filter_published_config( // Receiver index for the author's per-variant index: the receiver's extruder with the author's // extruder number, when it currently runs the author's nozzle type. -1 when it does not. +// The overload without a target resolves printer keys; the other looks the index up in +// receiver_target with its id/variant keys (process keys: print_extruder_id / print_extruder_variant). int resolve_published_extruder_slot(const PublishedExtruderLayout &author, size_t author_index, const DynamicPrintConfig &receiver_printer, const DynamicPrintConfig &receiver_project); +int resolve_published_extruder_slot(const PublishedExtruderLayout &author, size_t author_index, + const DynamicPrintConfig &receiver_printer, const DynamicPrintConfig &receiver_project, + const DynamicPrintConfig &receiver_target, const std::string &id_key, const std::string &variant_key); } diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 549b991302..684d63fc45 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -2021,8 +2021,10 @@ void MainFrame::publish_project() // published 3MF); a null pointer means "fresh", keeping the dirty defaults. std::vector pending_keys; std::vector pending_material; - const bool has_prior = m_plater->get_pending_published(pending_keys, pending_material); - PublishSettingsDialog dlg(this, has_prior ? &pending_keys : nullptr, has_prior ? &pending_material : nullptr); + bool pending_legacy_process = false; + const bool has_prior = m_plater->get_pending_published(pending_keys, pending_material, pending_legacy_process); + PublishSettingsDialog dlg(this, has_prior ? &pending_keys : nullptr, has_prior ? &pending_material : nullptr, + pending_legacy_process); if (dlg.ShowModal() != wxID_OK) return; m_plater->set_pending_published(dlg.GetPublishedKeys(), dlg.GetPublishedMaterialKeys()); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 2dab0955b8..32964b77e7 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -7190,6 +7190,9 @@ struct Plater::priv bool m_has_pending_published{false}; std::vector m_pending_published_keys; std::vector m_pending_material_keys; + // The pending keys come from a file published before per-extruder process keys were exported: + // a "key#N" process entry then stands for the whole vector. + bool m_pending_published_legacy_process{false}; // Data Slic3r::DynamicPrintConfig *config; // FIXME: leak? @@ -9198,8 +9201,14 @@ std::vector Plater::priv::load_files(const std::vector& input_ layout.extruder_ids = jl.at("extruder_ids").get>(); layout.variants = jl.at("variants").get>(); published_config.printer_layout = std::move(layout); + if (jl.contains("print_extruder_ids") && jl.contains("print_variants")) { + PublishedExtruderLayout print_layout; + print_layout.extruder_ids = jl.at("print_extruder_ids").get>(); + print_layout.variants = jl.at("print_variants").get>(); + published_config.print_layout = std::move(print_layout); + } } catch (const nlohmann::json::exception&) { - // Malformed layout: the printer keys fall back to the positional import. + // Malformed layout: the keys without a parsed layout fall back to the positional import. } } @@ -9682,6 +9691,7 @@ std::vector Plater::priv::load_files(const std::vector& input_ this->m_has_pending_published = true; this->m_pending_published_keys = published_config.published_keys; this->m_pending_material_keys = published_config.material_keys; + this->m_pending_published_legacy_process = published_config.print_layout.extruder_ids.empty(); } ConfigOption* bed_type_opt = preset_bundle->project_config.option("curr_bed_type"); @@ -10860,6 +10870,7 @@ void Plater::priv::reset(bool apply_presets_change, bool reload_presets) m_has_pending_published = false; m_pending_published_keys.clear(); m_pending_material_keys.clear(); + m_pending_published_legacy_process = false; set_project_filename(""); BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << __LINE__ << " call set_project_filename: empty"; @@ -19884,12 +19895,17 @@ int Plater::export_published_3mf(const std::vector& published_keys, payload += key + " = " + value + "\n"; } model.model_info->metadata_items[ORCA_PUBLISHED_CONFIG_TAG] = std::move(payload); - // The author's extruder layout, so the receiver can place each printer key on the extruder with the same number. + // The author's extruder layouts, so the receiver can place each per-extruder key on the extruder with the same number. const auto *layout_ids = full_cfg.option("printer_extruder_id"); const auto *layout_variants = full_cfg.option("printer_extruder_variant"); - if (layout_ids != nullptr && layout_variants != nullptr) + const auto *print_ids = full_cfg.option("print_extruder_id"); + const auto *print_variants = full_cfg.option("print_extruder_variant"); + if (layout_ids != nullptr && layout_variants != nullptr && print_ids != nullptr && print_variants != nullptr) model.model_info->metadata_items[ORCA_PUBLISHED_LAYOUT_TAG] = - nlohmann::json{{"extruder_ids", layout_ids->values}, {"variants", layout_variants->values}}.dump(); + nlohmann::json{{"extruder_ids", layout_ids->values}, + {"variants", layout_variants->values}, + {"print_extruder_ids", print_ids->values}, + {"print_variants", print_variants->values}}.dump(); // Same file layout as save_project(), plus Silence (so export_3mf does not set the project // filename on success, keeping this a pure export like export_core_3mf()) and MinimalPublished. @@ -19926,12 +19942,13 @@ int Plater::export_published_3mf(const std::vector& published_keys, } bool Plater::get_pending_published(std::vector& out_keys, - std::vector& out_material) const + std::vector& out_material, bool& out_legacy_process) const { if (!p->m_has_pending_published) return false; - out_keys = p->m_pending_published_keys; - out_material = p->m_pending_material_keys; + out_keys = p->m_pending_published_keys; + out_material = p->m_pending_material_keys; + out_legacy_process = p->m_pending_published_legacy_process; return true; } @@ -19941,6 +19958,7 @@ void Plater::set_pending_published(const std::vector& published_key p->m_has_pending_published = true; p->m_pending_published_keys = published_keys; p->m_pending_material_keys = material_keys; + p->m_pending_published_legacy_process = false; } Preset *get_printer_preset(const MachineObject *obj) diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index 9f96f45c59..4f66c7639c 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -586,7 +586,7 @@ public: int export_published_3mf(const std::vector& published_keys, const std::vector& material_keys); // Session-level stash of the last published selection, seeded into the Publish dialog on // open and written on publish or on loading a published 3MF - bool get_pending_published(std::vector& out_keys, std::vector& out_material) const; + bool get_pending_published(std::vector& out_keys, std::vector& out_material, bool& out_legacy_process) const; void set_pending_published(const std::vector& published_keys, const std::vector& material_keys); static TriangleMesh combine_mesh_fff(const ModelObject& mo, int instance_id, std::function notify_func = {}); void export_stl(bool extended = false, bool selection_only = false, bool multi_stls = false, FileType file_type = FT_STL); diff --git a/src/slic3r/GUI/PublishSettingsDialog.cpp b/src/slic3r/GUI/PublishSettingsDialog.cpp index 761ffd3e9f..740f6edff6 100644 --- a/src/slic3r/GUI/PublishSettingsDialog.cpp +++ b/src/slic3r/GUI/PublishSettingsDialog.cpp @@ -644,7 +644,8 @@ PublishSettingsDialog::MixedVisualSpec PublishSettingsDialog::make_mixed_visual_ PublishSettingsDialog::PublishSettingsDialog(wxWindow* parent, const std::vector* published_keys, - const std::vector* material_keys) + const std::vector* material_keys, + bool legacy_process_selection) : DPIDialog(parent ? parent : static_cast(wxGetApp().mainframe), wxID_ANY, _L("Publish 3MF..."), @@ -653,6 +654,7 @@ PublishSettingsDialog::PublishSettingsDialog(wxWindow* parent, wxCAPTION | wxCLOSE_BOX | wxRESIZE_BORDER | wxFULL_REPAINT_ON_RESIZE) , m_search(this, "search", 16) , m_menu(this, "filter", 16) + , m_legacy_process_selection(legacy_process_selection) { SetBackgroundColour(*wxWHITE); @@ -809,7 +811,7 @@ void PublishSettingsDialog::fit_to_content() int strip = m_outer_tabs->GetFullSize(); for (const SectionGroup& section : m_sections) { - strip = std::max(strip, section.tabs->GetFullSize()); + strip = std::max(strip, (section.page_tabs != nullptr ? section.page_tabs : section.tabs)->GetFullSize()); if (section.mixed_tabs != nullptr) strip = std::max(strip, section.mixed_tabs->GetFullSize()); } @@ -844,8 +846,9 @@ void PublishSettingsDialog::build_option_model() PresetBundle* bundle = wxGetApp().preset_bundle; DynamicPrintConfig full = bundle->full_config(); - // Printer rows index the uncompacted variant columns (as the Tab does); full_config() compacts them per extruder. - const DynamicPrintConfig printer_full = bundle->full_config(false); + // Per-extruder rows (printer and process) index the uncompacted variant columns (as the Tabs do); + // full_config() compacts them per extruder. + const DynamicPrintConfig uncompacted = bundle->full_config(false); m_info_nonsel = _L("No selected items..."); m_info_allsel = _L("All items selected..."); @@ -915,9 +918,9 @@ void PublishSettingsDialog::build_option_model() if (!printer_added.insert(opt_id).second) continue; wxString label, value, unit; - if (!option_text(printer_full, opt_id, pure_key, label, value, unit)) + if (!option_text(uncompacted, opt_id, pure_key, label, value, unit)) continue; - size_t cat_index = category_index_for(page_title, Section::Printer, g, extruder_idx); + size_t cat_index = category_index_for(page_title, Section::Printer, g, extruder_idx, PublishMaterialIdentity(), false, true); size_t sub_index = subcategory_index_for(cat_index, subcategory, optgroup->icon); add_row_ui(opt_id, label, value, unit, cat_index, sub_index); } @@ -1021,16 +1024,52 @@ void PublishSettingsDialog::build_option_model() } } - // --- Phase 3: process (print) settings; grouping matches the process tab. + // --- Phase 3: process (print) settings; grouping matches the process tab. Per-extruder settings + // (print_options_with_variant) get one tab per extruder, as the Printer section does, with a row + // per extruder column ("key#N"); the other settings stay on the page tabs. { size_t g = section_group_for(Section::Print); + + // One tab per extruder entry of the Process tab's switch (a single "Extruder" tab for one extruder). + struct ExtruderEntry + { + size_t category{0}; + int variant{-1}; + }; + std::vector extruder_entries; + if (auto* print_tab = dynamic_cast(wxGetApp().get_tab(Preset::TYPE_PRINT))) { + std::vector> entries; // tab title, variant column + const int extruder_count = bundle->get_printer_extruder_count(); + const bool variant_tabs = extruder_count >= 2; + if (variant_tabs) { + const std::vector titles = print_tab->generate_extruder_options(); + for (size_t i = 0; i < titles.size(); ++i) { + int extruder_id = 0; + NozzleVolumeType nozzle_type = NozzleVolumeType::nvtStandard; + print_tab->parse_extruder_selection(int(i), extruder_id, nozzle_type); + entries.emplace_back(titles[i], print_tab->extruder_variant_index(extruder_id, nozzle_type)); + } + } else if (extruder_count == 1) { + entries.emplace_back(Tab::translate_category(wxString("Extruder"), Preset::TYPE_PRINT), + print_tab->extruder_variant_index(0, print_tab->get_actual_nozzle_volume_type(0))); + } + for (const auto& [title, variant] : entries) { + if (variant < 0) + continue; + extruder_entries.push_back( + {category_index_for(title, Section::Print, g, extruder_entries.size(), PublishMaterialIdentity(), false, variant_tabs), variant}); + } + } + + std::set extruder_added; // "key#N" rows already added for (Tab* tab : wxGetApp().tabs_list) { if (tab->m_type != Preset::TYPE_PRINT) continue; size_t page_index = 0; for (const PageShp& page : tab->m_pages) { - wxString category = Tab::translate_category(page->title(), tab->m_type); - const size_t category_index = category_index_for(category, Section::Print, g, page_index); + const wxString category = Tab::translate_category(page->title(), tab->m_type); + // Created with the page's first row, so a page holding only per-extruder settings gets no tab. + size_t category_index = size_t(-1); for (const ConfigOptionsGroupShp& optgroup : page->m_optgroups) { for (const auto& opt : optgroup->opt_map()) { @@ -1038,12 +1077,27 @@ void PublishSettingsDialog::build_option_model() // (pure_opt_key, opt_index). const std::string& opt_id = opt.first; const std::string& pure_key = opt.second.first; + if (!extruder_entries.empty() && opt.second.second >= 0 && print_options_with_variant.count(pure_key) != 0) { + for (const ExtruderEntry& entry : extruder_entries) { + const std::string row_key = pure_key + "#" + std::to_string(entry.variant); + if (!extruder_added.insert(row_key).second) + continue; + wxString label, value, unit; + if (!option_text(uncompacted, row_key, pure_key, label, value, unit)) + continue; + size_t sub_index = subcategory_index_for(entry.category, _(optgroup->title), optgroup->icon); + add_row_ui(row_key, label, value, unit, entry.category, sub_index); + } + continue; + } // A key may appear in more than one page/group; keep the first. if (!added.insert(pure_key).second) continue; wxString label, value, unit; if (!option_text(full, opt_id, pure_key, label, value, unit)) continue; + if (category_index == size_t(-1)) + category_index = category_index_for(category, Section::Print, g, page_index); size_t sub_index = subcategory_index_for(category_index, _(optgroup->title), optgroup->icon); add_row_ui(opt_id, label, value, unit, category_index, sub_index); } @@ -1106,9 +1160,9 @@ void PublishSettingsDialog::build_option_model() for (SectionGroup& section : m_sections) if (!section.categories.empty()) section.tabs->SelectItem(0); - // Orca: the Printer section shows its extruders on the same switch as the printer tab's Extruder page. + // Orca: several extruders are shown on the same switch as the printer tab's Extruder page. for (size_t s = 0; s < m_sections.size(); ++s) - if (m_sections[s].kind == Section::Printer && m_sections[s].categories.size() > 1) + if (m_sections[s].variant_inners.size() > 1) setup_variant_switch(s); if (!m_sections.empty()) { m_outer_tabs->SelectItem(0); @@ -1149,6 +1203,15 @@ size_t PublishSettingsDialog::section_group_for(Section kind) section.tabs->SetFont(Label::Body_14); section.tabs->SetBackgroundColour(GetBackgroundColour()); page_sizer->Add(section.tabs, 0, wxEXPAND); + // Process: the full strip stays hidden as the selection model; the page tabs are shown below the + // extruder switch instead. + if (kind == Section::Print) { + section.page_tabs = new TabCtrl(section.page, wxID_ANY, wxDefaultPosition, wxDefaultSize, s_tab_style); + section.page_tabs->SetFont(Label::Body_14); + section.page_tabs->SetBackgroundColour(GetBackgroundColour()); + page_sizer->Add(section.page_tabs, 0, wxEXPAND); + section.tabs->Hide(); + } // Mixed-color filament slots get a second tab strip below the physical filament tabs; only // the Material section has them. if (kind == Section::Material) { @@ -1178,8 +1241,13 @@ size_t PublishSettingsDialog::section_group_for(Section kind) return new_index; } -size_t PublishSettingsDialog::category_index_for( - const wxString& title, Section section, size_t group, size_t source_index, const PublishMaterialIdentity& identity, bool is_mixed) +size_t PublishSettingsDialog::category_index_for(const wxString& title, + Section section, + size_t group, + size_t source_index, + const PublishMaterialIdentity& identity, + bool is_mixed, + bool is_variant) { // Dedup across both tab rows (physical + mixed); mixed slots are never duplicated anyway. auto match = [&](const Category& existing) { @@ -1280,8 +1348,11 @@ size_t PublishSettingsDialog::category_index_for( // Mixed slots live in a second tab row below the physical filament tabs. if (is_mixed) m_sections[group].mixed_categories.push_back(category_index); - else + else { m_sections[group].categories.push_back(category_index); + if (is_variant) + m_sections[group].variant_inners.push_back(m_sections[group].categories.size() - 1); + } if (section == Section::Material) { TabCtrl* target = is_mixed ? m_sections[group].mixed_tabs : m_sections[group].tabs; if (is_mixed) { @@ -1301,6 +1372,10 @@ size_t PublishSettingsDialog::category_index_for( } } else { m_sections[group].tabs->AppendItem(title); + if (section == Section::Print && !is_variant && m_sections[group].page_tabs != nullptr) { + m_sections[group].page_tabs->AppendItem(title); + m_sections[group].page_inners.push_back(m_sections[group].categories.size() - 1); + } } m_sections[group].page_host_sizer->Add(m_categories[category_index].page, 1, wxEXPAND); if (is_mixed) { @@ -1625,6 +1700,15 @@ void PublishSettingsDialog::show_outer_page(size_t section_index) m_outer_host_sizer->Layout(); } +// Position of `value` in `positions`, or -1. +static int position_of(const std::vector& positions, int value) +{ + for (size_t i = 0; i < positions.size(); ++i) + if (static_cast(positions[i]) == value) + return static_cast(i); + return -1; +} + void PublishSettingsDialog::show_inner_page(size_t section_index, int inner_index) { if (section_index >= m_sections.size()) @@ -1642,8 +1726,19 @@ void PublishSettingsDialog::show_inner_page(size_t section_index, int inner_inde section.selected_mixed = -1; } section.selected_inner = inner_index; - if (section.variant_switch != nullptr) - section.variant_switch->SetSelection(inner_index); // fires its event, which ignores the shown page + // An extruder page selects its switch option; a page tab leaves the switch with no selection. + if (section.variant_switch != nullptr) { + if (const int pos = position_of(section.variant_inners, inner_index); pos >= 0) + section.variant_switch->SetSelection(pos); // fires its event, which ignores the shown page + else + section.variant_switch->Unselect(); + } + if (section.page_tabs != nullptr) { + if (const int pos = position_of(section.page_inners, inner_index); pos >= 0) + section.page_tabs->SelectItem(pos); + else + section.page_tabs->Unselect(); + } Category& category = m_categories[section.categories[inner_index]]; category.page->Show(); category.scroll->FitInside(); @@ -1657,24 +1752,29 @@ void PublishSettingsDialog::setup_variant_switch(size_t section_index) { SectionGroup& section = m_sections[section_index]; std::vector titles; - for (size_t category : section.categories) - titles.push_back(m_categories[category].title); + for (size_t inner : section.variant_inners) + titles.push_back(m_categories[section.categories[inner]].title); section.variant_switch = new MultiSwitchButton(section.page); section.variant_switch->SetFitToOptions(); section.variant_switch->SetOptions(titles); - section.variant_switch->SetSelection(section.selected_inner); + if (const int pos = position_of(section.variant_inners, section.selected_inner); pos >= 0) + section.variant_switch->SetSelection(pos); section.variant_switch->Bind(wxCUSTOMEVT_MULTISWITCH_SELECTION, [this, section_index](wxCommandEvent& evt) { evt.Skip(); // The hidden tab strip stays the selection model; its event shows the page. SectionGroup& sec = m_sections[section_index]; - if (evt.GetInt() != sec.selected_inner) - sec.tabs->SelectItem(evt.GetInt()); + if (evt.GetInt() < 0 || evt.GetInt() >= static_cast(sec.variant_inners.size())) + return; + const int inner = static_cast(sec.variant_inners[evt.GetInt()]); + if (inner != sec.selected_inner) + sec.tabs->SelectItem(inner); }); - // The switch takes the place of the tab strip, centered like on the printer tab. + // The switch takes the place of the printer's tab strip, centered like on the printer tab. On the + // Process section it sits below the page tabs. wxSizer* page_sizer = section.page->GetSizer(); - page_sizer->Insert(1, section.variant_switch, 0, wxALIGN_CENTER_HORIZONTAL | wxTOP, FromDIP(4)); + page_sizer->Insert(section.page_tabs != nullptr ? 2 : 1, section.variant_switch, 0, wxALIGN_CENTER_HORIZONTAL | wxTOP, FromDIP(4)); section.tabs->Hide(); section.page->Layout(); } @@ -1718,6 +1818,17 @@ void PublishSettingsDialog::on_inner_tab_changed(size_t section_index, wxCommand show_inner_page(section_index, selection); } +void PublishSettingsDialog::on_page_tab_changed(size_t section_index, wxCommandEvent& event) +{ + SectionGroup& section = m_sections[section_index]; + const int selection = event.GetInt(); + if (selection < 0 || selection >= static_cast(section.page_inners.size())) + return; + const int inner = static_cast(section.page_inners[selection]); + if (inner != section.selected_inner) + section.tabs->SelectItem(inner); +} + void PublishSettingsDialog::on_mixed_tab_changed(size_t section_index, wxCommandEvent& event) { const int selection = event.GetInt(); @@ -1732,6 +1843,9 @@ void PublishSettingsDialog::bind_tab_events() for (size_t section_index = 0; section_index < m_sections.size(); ++section_index) { m_sections[section_index].tabs->Bind(wxEVT_TAB_SEL_CHANGED, [this, section_index](wxCommandEvent& event) { on_inner_tab_changed(section_index, event); }); + if (m_sections[section_index].page_tabs != nullptr) + m_sections[section_index].page_tabs->Bind(wxEVT_TAB_SEL_CHANGED, + [this, section_index](wxCommandEvent& event) { on_page_tab_changed(section_index, event); }); if (m_sections[section_index].mixed_tabs != nullptr) m_sections[section_index].mixed_tabs->Bind(wxEVT_TAB_SEL_CHANGED, [this, section_index](wxCommandEvent& event) { on_mixed_tab_changed(section_index, event); @@ -1985,13 +2099,20 @@ void PublishSettingsDialog::apply_selection(const std::vector& publ cat.full_check->SetValue(false); } - // Print / printer rows: match by exact row key (the full "#N" opt_id where present). - for (const std::string& key : published_keys) - for (Row& row : m_rows) - if ((row.section == Section::Print || row.section == Section::Printer) && row.check != nullptr && row.key == key) { + // Print / printer rows: match by exact row key (the full "#N" opt_id where present). A process + // "key#N" from a file without the per-extruder process layout carries the whole vector, so it + // selects that setting on every extruder. + for (const std::string& key : published_keys) { + const std::string base_key = publish_base_key(key); + const bool legacy_process = m_legacy_process_selection && key != base_key && print_options_with_variant.count(base_key) != 0; + for (Row& row : m_rows) { + if ((row.section != Section::Print && row.section != Section::Printer) || row.check == nullptr) + continue; + const bool match = legacy_process ? (row.section == Section::Print && publish_base_key(row.key) == base_key) : row.key == key; + if (match) row.check->SetValue(true); - break; - } + } + } // Per-slot material selections, applied positionally by slot. for (const Slic3r::PublishedMaterialEntry& entry : material_keys) { @@ -2224,17 +2345,23 @@ void PublishSettingsDialog::refresh_tab_indicators() for (size_t i = 0; i < section.categories.size(); ++i) { const bool on = category_has_selection(m_categories[section.categories[i]]); section.tabs->SetItemIndicator(static_cast(i), on); - // The switch has no indicator dot; mark its option text instead. - if (section.variant_switch != nullptr) { - const wxString& title = m_categories[section.categories[i]].title; - const wxString text = on ? title + wxString(" ") + wxString(wxUniChar(0x2022)) : title; - if (section.variant_switch->GetOptionText(static_cast(i)) != text) { - section.variant_switch->SetOptionText(static_cast(i), text); + any = any || on; + } + // The switch has no indicator dot; mark its option text instead. + if (section.variant_switch != nullptr) + for (size_t p = 0; p < section.variant_inners.size(); ++p) { + const Category& category = m_categories[section.categories[section.variant_inners[p]]]; + const bool on = category_has_selection(category); + const wxString text = on ? category.title + wxString(" ") + wxString(wxUniChar(0x2022)) : category.title; + if (section.variant_switch->GetOptionText(static_cast(p)) != text) { + section.variant_switch->SetOptionText(static_cast(p), text); section.page->Layout(); } } - any = any || on; - } + if (section.page_tabs != nullptr) + for (size_t j = 0; j < section.page_inners.size(); ++j) + section.page_tabs->SetItemIndicator(static_cast(j), + category_has_selection(m_categories[section.categories[section.page_inners[j]]])); if (section.mixed_tabs != nullptr) for (size_t i = 0; i < section.mixed_categories.size(); ++i) { const bool on = category_has_selection(m_categories[section.mixed_categories[i]]); @@ -2295,6 +2422,8 @@ void PublishSettingsDialog::on_dpi_changed(const wxRect& suggested_rect) if (section.icon_bmp.bmp().IsOk()) m_outer_tabs->SetItemBitmap(s, section.icon_bmp.bmp()); section.tabs->Rescale(); + if (section.page_tabs != nullptr) + section.page_tabs->Rescale(); if (section.mixed_tabs != nullptr) section.mixed_tabs->Rescale(); if (section.variant_switch != nullptr) diff --git a/src/slic3r/GUI/PublishSettingsDialog.hpp b/src/slic3r/GUI/PublishSettingsDialog.hpp index 5e3ef48617..8421e6589c 100644 --- a/src/slic3r/GUI/PublishSettingsDialog.hpp +++ b/src/slic3r/GUI/PublishSettingsDialog.hpp @@ -70,10 +70,13 @@ public: // remembered session selection or the payload of a freshly loaded published 3MF) the dialog // is seeded from it, overriding the dirty-default pre-check. A non-null pointer to an empty // selection means "publish nothing" (an intentional empty state); a null pointer means "no - // remembered selection" (keep the dirty defaults). + // remembered selection" (keep the dirty defaults). legacy_process_selection marks a selection + // read from a file without per-extruder process layout: its "key#N" process entries then select + // that setting on every extruder. PublishSettingsDialog(wxWindow* parent = nullptr, const std::vector* published_keys = nullptr, - const std::vector* material_keys = nullptr); + const std::vector* material_keys = nullptr, + bool legacy_process_selection = false); ~PublishSettingsDialog(); // The selected print/printer setting keys (in display order); printer keys carry a '#N' @@ -195,11 +198,16 @@ private: std::string icon_name; // "printer" / "filament" / "process" ScalableBitmap icon_bmp; // tab icon next to the title; rescaled on DPI change wxPanel* page{nullptr}; + // Holds every category in order and stays the selection model. Hidden on the Process section, + // whose page tabs are shown in `page_tabs` instead. TabCtrl* tabs{nullptr}; - // Printer section with several extruders: the extruder switch shown instead of `tabs`, the - // same MultiSwitchButton (and option names) as the printer tab's Extruder page. One option - // per entry of `categories`, named by its title; `tabs` stays as the hidden selection model. + // Several extruders: the extruder switch, the same MultiSwitchButton (and option names) as the + // printer tab's Extruder page, with one option per entry of `variant_inners`. MultiSwitchButton* variant_switch{nullptr}; + // Process section: the visible strip of page tabs, shown below the extruder switch. + TabCtrl* page_tabs{nullptr}; + std::vector variant_inners; // positions in `categories` of the extruder categories + std::vector page_inners; // positions in `categories` of the categories shown in `page_tabs` // Second tab strip, below the main one, listing only the mixed-color filament slots. // Present on the Material section only (null elsewhere). TabCtrl* mixed_tabs{nullptr}; @@ -261,7 +269,8 @@ private: size_t group, size_t source_index, const PublishMaterialIdentity& identity = PublishMaterialIdentity(), - bool is_mixed = false); + bool is_mixed = false, + bool is_variant = false); size_t subcategory_index_for(size_t category_index, const wxString& title, const wxString& icon); void add_row_ui(const std::string& key, const wxString& label, @@ -278,6 +287,7 @@ private: void show_mixed_page(size_t section_index, int mixed_index); void on_outer_tab_changed(wxCommandEvent& event); void on_inner_tab_changed(size_t section_index, wxCommandEvent& event); + void on_page_tab_changed(size_t section_index, wxCommandEvent& event); void on_mixed_tab_changed(size_t section_index, wxCommandEvent& event); bool row_is_visible(const Row& row) const; void apply_visibility(); @@ -306,6 +316,7 @@ private: ScalableBitmap m_search; ScalableBitmap m_menu; + bool m_legacy_process_selection{false}; std::vector m_rows; std::vector m_categories; diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index efea25d0ec..94978635b5 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -3716,6 +3716,15 @@ void TabPrint::update() } } +int TabPrint::extruder_variant_index(int extruder_id, NozzleVolumeType nozzle_type) +{ + const auto *extruders = m_preset_bundle->printers.get_edited_preset().config.option("extruder_type"); + if (extruders == nullptr || extruder_id < 0 || extruder_id >= int(extruders->size())) + return -1; + return m_config->get_index_for_extruder(extruder_id + 1, "print_extruder_id", ExtruderType(extruders->values[extruder_id]), nozzle_type, + "print_extruder_variant"); +} + void TabPrint::clear_pages() { Tab::clear_pages(); diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index a4ada076b9..8df7d6c84c 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -591,6 +591,9 @@ public: void update() override; void clear_pages() override; bool supports_printer_technology(const PrinterTechnology tech) const override { return tech == ptFFF; } + // Column of the extruder's variant in the per-variant process vectors, as the extruder switch + // selects it; -1 when the printer has no such extruder variant. + int extruder_variant_index(int extruder_id, NozzleVolumeType nozzle_type); private: ogStaticText* m_recommended_thin_wall_thickness_description_line = nullptr; diff --git a/src/slic3r/GUI/Widgets/SwitchButton.cpp b/src/slic3r/GUI/Widgets/SwitchButton.cpp index b5699d5b78..84c2df6e34 100644 --- a/src/slic3r/GUI/Widgets/SwitchButton.cpp +++ b/src/slic3r/GUI/Widgets/SwitchButton.cpp @@ -842,6 +842,15 @@ void MultiSwitchButton::SetSelection(int index) Refresh(); } +void MultiSwitchButton::Unselect() +{ + if (sel < 0) + return; + sel = -1; + update_button_styles(); + Refresh(); +} + wxString MultiSwitchButton::GetSelectedText() const { return sel >= 0 && sel < (int) btns.size() ? btns[sel]->GetLabel() : wxString(); diff --git a/src/slic3r/GUI/Widgets/SwitchButton.hpp b/src/slic3r/GUI/Widgets/SwitchButton.hpp index ed7736ba4f..e2664a6a00 100644 --- a/src/slic3r/GUI/Widgets/SwitchButton.hpp +++ b/src/slic3r/GUI/Widgets/SwitchButton.hpp @@ -148,6 +148,8 @@ public: int GetSelection() const; void SetSelection(int index); + // Clears the selection without sending the selection event. + void Unselect(); wxString GetSelectedText() const; Button* GetButton(unsigned int index) const diff --git a/tests/libslic3r/test_3mf.cpp b/tests/libslic3r/test_3mf.cpp index 00721b952f..c37e5e1d36 100644 --- a/tests/libslic3r/test_3mf.cpp +++ b/tests/libslic3r/test_3mf.cpp @@ -5,6 +5,7 @@ #include #include #include +#include "catch2/generators/catch_generators_range.hpp" #include "libslic3r/Model.hpp" #include "libslic3r/Format/3mf.hpp" #include "libslic3r/Format/bbs_3mf.hpp" @@ -2077,6 +2078,48 @@ SCENARIO("Published per-extruder printer keys mask the other extruders to their } } +// A per-extruder process key ("outer_wall_speed#1") masks the other extruders to their defaults, as +// the printer keys do. A bare process key keeps whole-vector serialization. +TEST_CASE("Published per-extruder process keys mask the other extruders to their defaults", "[3mf]") +{ + // outer_wall_speed is a nullable float vector, so its values and default use ConfigOptionFloatsNullable. + DynamicPrintConfig full_cfg = DynamicPrintConfig::full_print_config(); + full_cfg.opt("outer_wall_speed")->values = { 200., 150., 120. }; + + const ConfigOptionFloatsNullable* default_speed = print_config_def.get("outer_wall_speed")->get_default_value(); + REQUIRE(default_speed != nullptr); + REQUIRE(!default_speed->values.empty()); + const double default_value = default_speed->values.front(); + + SECTION("the selected extruder's value survives and the others hold the default") { + DynamicPrintConfig filtered_cfg = filter_published_config(full_cfg, { "outer_wall_speed#1" }, {}); + const std::vector& values = filtered_cfg.opt("outer_wall_speed")->values; + REQUIRE(values.size() == 3); + CHECK_THAT(values[1], Catch::Matchers::WithinAbs(150., 1e-6)); + CHECK_THAT(values[0], Catch::Matchers::WithinAbs(default_value, 1e-6)); + CHECK_THAT(values[2], Catch::Matchers::WithinAbs(default_value, 1e-6)); + } + + SECTION("the bare key serializes the whole vector") { + DynamicPrintConfig filtered_cfg = filter_published_config(full_cfg, { "outer_wall_speed" }, {}); + const std::vector& values = filtered_cfg.opt("outer_wall_speed")->values; + REQUIRE(values.size() == 3); + CHECK_THAT(values[0], Catch::Matchers::WithinAbs(200., 1e-6)); + CHECK_THAT(values[1], Catch::Matchers::WithinAbs(150., 1e-6)); + CHECK_THAT(values[2], Catch::Matchers::WithinAbs(120., 1e-6)); + } +} + +// Every per-extruder process key needs a default: masking restores the unselected slots with it, +// and a key without one is dropped from the published payload. +TEST_CASE("Every per-extruder process key has a default to mask unused slots with", "[3mf]") +{ + const std::string key = GENERATE(Catch::Generators::from_range(print_options_with_variant)); + const ConfigOptionDef* def = print_config_def.get(key); + REQUIRE(def != nullptr); + CHECK(def->default_value.get() != nullptr); +} + // The extended per-entry fields (full dump list, published type and colour) travel inside the // published_material_keys metadata and round-trip unchanged. SCENARIO("Published 3MF round-trips the extended material metadata", "[3mf]") { diff --git a/tests/libslic3r/test_preset_bundle_loading.cpp b/tests/libslic3r/test_preset_bundle_loading.cpp index 9c18f3c4fb..0dd35a7855 100644 --- a/tests/libslic3r/test_preset_bundle_loading.cpp +++ b/tests/libslic3r/test_preset_bundle_loading.cpp @@ -509,6 +509,34 @@ TEST_CASE("A published printer key is skipped when the receiver's extruder does CHECK(resolve_published_extruder_slot(author, 2, printer, project) == -1); } +// The process layout is resolved against the receiver's print_extruder_id / print_extruder_variant. +TEST_CASE("A published process key lands on the receiver's extruder with the same number", "[Preset][Bundle]") +{ + DynamicPrintConfig printer, project, process; + set_receiver_layout(printer, project, {1, 2}, {"Direct Drive Standard", "Direct Drive Standard"}, {nvtStandard, nvtStandard}); + process.set_key_value("print_extruder_id", new ConfigOptionInts({1, 1, 2, 2})); + process.set_key_value("print_extruder_variant", + new ConfigOptionStrings({"Direct Drive Standard", "Direct Drive High Flow", "Direct Drive Standard", "Direct Drive High Flow"})); + const PublishedExtruderLayout author{{1, 1, 2, 2}, + {"Direct Drive Standard", "Direct Drive High Flow", "Direct Drive Standard", "Direct Drive High Flow"}}; + + CHECK(resolve_published_extruder_slot(author, 2, printer, project, process, "print_extruder_id", "print_extruder_variant") == 2); + CHECK(resolve_published_extruder_slot(author, 1, printer, project, process, "print_extruder_id", "print_extruder_variant") == -1); +} + +TEST_CASE("A published process key is skipped when the receiver has no extruder with its number", "[Preset][Bundle]") +{ + DynamicPrintConfig printer, project, process; + set_receiver_layout(printer, project, {1}, {"Direct Drive Standard"}, {nvtStandard}); + process.set_key_value("print_extruder_id", new ConfigOptionInts({1, 1, 2, 2})); + process.set_key_value("print_extruder_variant", + new ConfigOptionStrings({"Direct Drive Standard", "Direct Drive High Flow", "Direct Drive Standard", "Direct Drive High Flow"})); + const PublishedExtruderLayout author{{1, 1, 2, 2}, + {"Direct Drive Standard", "Direct Drive High Flow", "Direct Drive Standard", "Direct Drive High Flow"}}; + + CHECK(resolve_published_extruder_slot(author, 2, printer, project, process, "print_extruder_id", "print_extruder_variant") == -1); +} + TEST_CASE("Reloading one local bundle preserves unrelated and modified presets", "[Preset][Bundle]") { using Catch::Matchers::WithinAbs;