Show filament edit button or action menu dynamically depends on single / multi materilal usage (#12651)

* init

* fix build error

* add guards

* Update Plater.cpp
This commit is contained in:
yw4z
2026-05-18 08:59:22 +03:00
committed by GitHub
parent 3ca7c4b752
commit f0392ab226
4 changed files with 61 additions and 51 deletions

View File

@@ -1644,17 +1644,6 @@ void MenuFactory::create_filament_action_menu(bool init, int active_filament_men
[]() { return true; }, m_parent); []() { return true; }, m_parent);
} }
if (init) {
append_menu_item(
menu, wxID_ANY, _L("Delete"), _L("Delete this filament"), [](wxCommandEvent&) {
plater()->sidebar().delete_filament(-2); }, "", nullptr,
[]() {
return plater()->sidebar().combos_filament().size() > 1
// Orca: only show delete filament option for SEMM machines unless is BBL
&& Sidebar::should_show_SEMM_buttons();
}, m_parent);
}
const int item_id = menu->FindItem(_L("Merge with")); const int item_id = menu->FindItem(_L("Merge with"));
if (item_id != wxNOT_FOUND) if (item_id != wxNOT_FOUND)
menu->Destroy(item_id); menu->Destroy(item_id);
@@ -1675,6 +1664,20 @@ void MenuFactory::create_filament_action_menu(bool init, int active_filament_men
} }
append_submenu(menu, sub_menu, wxID_ANY, _L("Merge with"), "", "", append_submenu(menu, sub_menu, wxID_ANY, _L("Merge with"), "", "",
[filaments_cnt]() { return filaments_cnt > 1; }, m_parent); [filaments_cnt]() { return filaments_cnt > 1; }, m_parent);
// ORCA use delete item on end of menu to prevent accidental clicks. clicking to submenus(merge) already not allowed by OS
const int delete_id = menu->FindItem(_L("Delete"));
if (delete_id != wxNOT_FOUND)
menu->Destroy(delete_id);
append_menu_item(
menu, wxID_ANY, _L("Delete"), _L("Delete this filament"), [](wxCommandEvent&) {
plater()->sidebar().delete_filament(-2); }, "", nullptr,
[]() {
return plater()->sidebar().combos_filament().size() > 1
// Orca: only show delete filament option for SEMM machines unless is BBL
&& Sidebar::should_show_SEMM_buttons();
}, m_parent);
} }
//BBS: add part plate related logic //BBS: add part plate related logic

View File

@@ -2403,13 +2403,23 @@ void Sidebar::init_filament_combo(PlaterPresetComboBox **combo, const int filame
edit_btn->SetToolTip(_L("Click to edit preset")); edit_btn->SetToolTip(_L("Click to edit preset"));
PlaterPresetComboBox* combobox = (*combo); PlaterPresetComboBox* combobox = (*combo);
edit_btn->Bind(wxEVT_BUTTON, [this, edit_btn, filament_idx](wxCommandEvent) { edit_btn->Bind(wxEVT_BUTTON, [this, edit_btn, combobox, filament_idx](wxCommandEvent) {
auto menu = p->plater->filament_action_menu(filament_idx); bool single_or_bbl = should_show_SEMM_buttons();
wxPoint pt { 0, edit_btn->GetSize().GetHeight() + 10 }; bool is_multi_material = p->combos_filament.size() > 1;
pt = edit_btn->ClientToScreen(pt); if(single_or_bbl && is_multi_material) {
pt = wxGetApp().mainframe->ScreenToClient(pt); // MULTI MATERIAL Show menu
p->m_menu_filament_id = filament_idx; auto menu = p->plater->filament_action_menu(filament_idx);
p->plater->PopupMenu(menu, (int) pt.x, pt.y); wxPoint pt { 0, edit_btn->GetSize().GetHeight() + FromDIP(2) };
pt = edit_btn->ClientToScreen(pt);
pt = wxGetApp().mainframe->ScreenToClient(pt);
p->m_menu_filament_id = filament_idx;
p->plater->PopupMenu(menu, (int) pt.x, pt.y);
}
else {
// SINGLE MATERIAL / MULTI EXTRUDER / TOOLCHANGER / IDEX Opens Dialog directly
p->editing_filament = filament_idx;
combobox->switch_to_tab();
}
}); });
combobox->edit_btn = edit_btn; combobox->edit_btn = edit_btn;
@@ -2510,7 +2520,7 @@ void Sidebar::update_all_preset_comboboxes()
p->m_filament_icon->SetBitmap_("filament"); p->m_filament_icon->SetBitmap_("filament");
} }
show_SEMM_buttons(should_show_SEMM_buttons()); show_SEMM_buttons();
//p->m_staticText_filament_settings->Update(); //p->m_staticText_filament_settings->Update();
@@ -3112,16 +3122,7 @@ void Sidebar::on_filament_count_change(size_t num_filaments)
// remove unused choices if any // remove unused choices if any
remove_unused_filament_combos(num_filaments); remove_unused_filament_combos(num_filaments);
auto sizer = p->m_panel_filament_title->GetSizer(); show_SEMM_buttons(); // ORCA
if (p->m_flushing_volume_btn != nullptr && sizer != nullptr) {
if (num_filaments > 1) {
sizer->Show(p->m_flushing_volume_btn);
sizer->Show(p->m_bpButton_del_filament); // ORCA: Show delete filament button if multiple filaments
} else {
sizer->Hide(p->m_flushing_volume_btn);
sizer->Hide(p->m_bpButton_del_filament); // ORCA: Hide delete filament button if there is only one filament
}
}
update_filaments_area_height(); // ORCA update_filaments_area_height(); // ORCA
@@ -3168,16 +3169,7 @@ void Sidebar::on_filaments_delete(size_t filament_id)
} }
} }
auto sizer = p->m_panel_filament_title->GetSizer(); show_SEMM_buttons(); // ORCA
if (p->m_flushing_volume_btn != nullptr && sizer != nullptr) {
if (p->combos_filament.size() > 1) {
sizer->Show(p->m_flushing_volume_btn);
sizer->Show(p->m_bpButton_del_filament); // ORCA: Show delete filament button if multiple filaments
} else {
sizer->Hide(p->m_flushing_volume_btn);
sizer->Hide(p->m_bpButton_del_filament); // ORCA: Hide delete filament button if there is only one filament
}
}
for (size_t idx = filament_id ; idx < p->combos_filament.size(); ++idx) { for (size_t idx = filament_id ; idx < p->combos_filament.size(); ++idx) {
p->combos_filament[idx]->update(); p->combos_filament[idx]->update();
@@ -3736,14 +3728,31 @@ bool Sidebar::should_show_SEMM_buttons()
return cfg.opt_bool("single_extruder_multi_material") || is_bbl_vendor; return cfg.opt_bool("single_extruder_multi_material") || is_bbl_vendor;
} }
void Sidebar::show_SEMM_buttons(bool bshow) void Sidebar::show_SEMM_buttons()
{ {
if(p->m_bpButton_add_filament) // ORCA
p->m_bpButton_add_filament->Show(bshow); if (!p || p->combos_filament.empty() || !p->m_bpButton_add_filament || !p->m_bpButton_del_filament || !p->m_flushing_volume_btn)
if (p->m_bpButton_del_filament && p->combos_filament.size() > 1) // ORCA add filament count as condition to prevent showing Flushing volumes and Del Filament icon visible while only 1 filament exist return;
p->m_bpButton_del_filament->Show(bshow);
if (p->m_flushing_volume_btn && p->combos_filament.size() > 1) // ORCA add filament count as condition to prevent showing Flushing volumes and Del Filament icon visible while only 1 filament exist bool is_multi_material = p->combos_filament.size() > 1;
p->m_flushing_volume_btn->Show(bshow); bool single_or_bbl = should_show_SEMM_buttons();
bool is_single = single_or_bbl && !is_multi_material; // SINGLE EXTRUDER / BBL WITH 1 MATERIAL
bool is_multi = single_or_bbl && is_multi_material; // MULTI MATERIAL WITH SINGLE EXTRUDER
bool is_fixed = !is_single && !is_multi; // MULTI EXTRUDER / TOOLCHANGER / IDEX WITH FIXED MATERIAL
p->m_bpButton_add_filament->Show(single_or_bbl);
p->m_bpButton_del_filament->Show(is_multi);
p->m_flushing_volume_btn->Show( is_multi);
if (is_multi) {
for (auto &c : p->combos_filament)
c->edit_btn->SetBitmap_("menu_filament");
}
else if (is_single || is_fixed) {
for (auto &c : p->combos_filament)
c->edit_btn->SetBitmap_("edit");
}
Layout(); Layout();
} }

View File

@@ -203,7 +203,7 @@ public:
void get_small_btn_sync_pos_size(wxPoint &pt, wxSize &size); void get_small_btn_sync_pos_size(wxPoint &pt, wxSize &size);
// Orca // Orca
static bool should_show_SEMM_buttons(); static bool should_show_SEMM_buttons();
void show_SEMM_buttons(bool bshow); void show_SEMM_buttons();
void update_dynamic_filament_list(); void update_dynamic_filament_list();
PlaterPresetComboBox * printer_combox(); PlaterPresetComboBox * printer_combox();

View File

@@ -1554,8 +1554,7 @@ void Tab::on_value_change(const std::string& opt_key, const boost::any& value)
if (opt_key == "single_extruder_multi_material" ){ if (opt_key == "single_extruder_multi_material" ){
const auto bSEMM = m_config->opt_bool("single_extruder_multi_material"); wxGetApp().sidebar().show_SEMM_buttons();
wxGetApp().sidebar().show_SEMM_buttons(bSEMM);
wxGetApp().get_tab(Preset::TYPE_PRINT)->update(); wxGetApp().get_tab(Preset::TYPE_PRINT)->update();
} }
@@ -1606,8 +1605,7 @@ void Tab::on_value_change(const std::string& opt_key, const boost::any& value)
if (opt_key == "single_extruder_multi_material" ){ if (opt_key == "single_extruder_multi_material" ){
const auto bSEMM = m_config->opt_bool("single_extruder_multi_material"); wxGetApp().sidebar().show_SEMM_buttons();
wxGetApp().sidebar().show_SEMM_buttons(bSEMM);
wxGetApp().get_tab(Preset::TYPE_PRINT)->update(); wxGetApp().get_tab(Preset::TYPE_PRINT)->update();
} }