Simplify the unified Extruder page and its Publish dialog switch

This commit is contained in:
SoftFever committed 2026-10-07 01:40:10 +08:00
1 parent 67e29f69e7
commit d068468bbb
4 files changed
+126 -159

No files matched your search

+43 -52
View File
@@ -865,47 +865,43 @@ void PublishSettingsDialog::build_option_model()
};
// --- Phase 1: printer per-extruder retraction settings (first, mirroring the sidebar's
// Printer group), from the printer tab's "Extruder"/"Extruder N" pages. One inner tab per
// extruder (e.g. "Left Extruder"/"Right Extruder" via Tab::translate_category), each holding
// that extruder's Retraction and Z-Hop rows with per-extruder "#N" values.
// Printer group), from the printer tab's "Extruder" page. One inner tab per extruder (named
// as on the printer tab's switch, e.g. "Left Extruder"/"Right Extruder" via
// Tab::translate_category), each holding that extruder's Retraction and Z-Hop rows with
// per-extruder "#N" values.
{
size_t g = section_group_for(Section::Printer);
std::set<std::string> printer_added;
for (Tab* tab : wxGetApp().tabs_list) {
if (tab->m_type != Preset::TYPE_PRINTER)
// The page's controls edit the extruder chosen on the printer tab's switch, so its
// option list is read once per extruder.
auto* printer_tab = dynamic_cast<TabPrinter*>(tab);
const Page* page = printer_tab ? printer_tab->extruder_page() : nullptr;
if (page == nullptr)
continue;
// Orca: the printer tab has a single "Extruder" page whose controls are re-targeted to the
// extruder chosen on its switch, so build one inner tab per extruder from that page's
// option list, keyed "<key>#<extruder index>" as the former "Extruder N" pages were.
auto* printer_tab = dynamic_cast<TabPrinter*>(tab);
const size_t extruders_count = printer_tab ? printer_tab->m_extruders_count : 1;
for (const PageShp& page : tab->m_pages) {
if (page->title() != "Extruder")
continue;
// One tab per extruder, named as on the printer tab's switch.
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);
for (const ConfigOptionsGroupShp& optgroup : page->m_optgroups) {
// Allowlist on the untranslated optgroup title; the "Retraction when
// switching material" group is intentionally skipped.
if (optgroup->title != "Retraction" && optgroup->title != "Z-Hop")
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);
for (const ConfigOptionsGroupShp& optgroup : page->m_optgroups) {
// Allowlist on the untranslated optgroup title; the "Retraction when
// switching material" group is intentionally skipped.
if (optgroup->title != "Retraction" && optgroup->title != "Z-Hop")
continue;
const wxString subcategory = _(optgroup->title);
for (const auto& opt : optgroup->opt_map()) {
const std::string& pure_key = opt.second.first;
// 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);
if (!printer_added.insert(opt_id).second)
continue;
const wxString subcategory = _(optgroup->title);
for (const auto& opt : optgroup->opt_map()) {
const std::string& pure_key = opt.second.first;
// 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);
if (!printer_added.insert(opt_id).second)
continue;
wxString label, value, unit;
if (!option_text(opt_id, pure_key, label, value, unit))
continue;
size_t cat_index = category_index_for(page_title, Section::Printer, g, extruder_idx);
size_t sub_index = subcategory_index_for(cat_index, subcategory, optgroup->icon);
add_row_ui(opt_id, label, value, unit, cat_index, sub_index);
}
wxString label, value, unit;
if (!option_text(opt_id, pure_key, label, value, unit))
continue;
size_t cat_index = category_index_for(page_title, Section::Printer, g, extruder_idx);
size_t sub_index = subcategory_index_for(cat_index, subcategory, optgroup->icon);
add_row_ui(opt_id, label, value, unit, cat_index, sub_index);
}
}
}
@@ -1628,7 +1624,7 @@ 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->GetSelection() != inner_index)
if (section.variant_switch != nullptr)
section.variant_switch->SetSelection(inner_index); // fires its event, which ignores the shown page
Category& category = m_categories[section.categories[inner_index]];
category.page->Show();
@@ -1642,26 +1638,20 @@ void PublishSettingsDialog::show_inner_page(size_t section_index, int inner_inde
void PublishSettingsDialog::setup_variant_switch(size_t section_index)
{
SectionGroup& section = m_sections[section_index];
if (section.variant_switch != nullptr || section.categories.size() < 2)
return;
section.variant_titles.clear();
std::vector<wxString> titles;
for (size_t category : section.categories)
section.variant_titles.push_back(m_categories[category].title);
titles.push_back(m_categories[category].title);
section.variant_switch = new MultiSwitchButton(section.page);
section.variant_switch->SetFitToOptions();
section.variant_switch->SetOptions(section.variant_titles);
section.variant_switch->SetSelection(std::max(section.selected_inner, 0));
section.variant_switch->SetOptions(titles);
section.variant_switch->SetSelection(section.selected_inner);
section.variant_switch->Bind(wxCUSTOMEVT_MULTISWITCH_SELECTION, [this, section_index](wxCommandEvent& evt) {
evt.Skip();
const int selection = evt.GetInt();
SectionGroup& sec = m_sections[section_index];
if (selection >= 0 && selection < static_cast<int>(sec.categories.size()) && selection != sec.selected_inner) {
sec.tabs->SelectItem(selection); // keep the hidden tab strip in step; its event shows the page
if (sec.selected_inner != selection)
show_inner_page(section_index, selection);
}
// 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());
});
// The switch takes the place of the tab strip, centered like on the printer tab.
@@ -2217,8 +2207,9 @@ void PublishSettingsDialog::refresh_tab_indicators()
const bool on = category_has_selection(m_categories[section.categories[i]]);
section.tabs->SetItemIndicator(static_cast<unsigned int>(i), on);
// The switch has no indicator dot; mark its option text instead.
if (section.variant_switch != nullptr && i < section.variant_titles.size()) {
const wxString text = on ? section.variant_titles[i] + wxString(" ") + wxString(wxUniChar(0x2022)) : section.variant_titles[i];
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<unsigned int>(i)) != text)
section.variant_switch->SetOptionText(static_cast<unsigned int>(i), text);
}