ENH: filament actions and dual extruder filaments

Change-Id: I12a83f29c96887fc910976ac8e025c4f1508d945
(cherry picked from commit 0065ea986fc41132df43cca6704c8c98318e6b71)
This commit is contained in:
chunmao.guo
2024-06-26 15:20:47 +08:00
committed by Noisyfox
parent 4861fc7e6b
commit 2fe654587b
6 changed files with 98 additions and 44 deletions

View File

@@ -1467,6 +1467,20 @@ void MenuFactory::create_bbl_assemble_part_menu()
menu->AppendSeparator();
}
void MenuFactory::create_filament_action_menu()
{
wxMenu *menu = &m_filament_action_menu;
append_menu_item(
menu, wxID_ANY, _L("Edit"), "", [](wxCommandEvent &) {
plater()->sidebar().edit_filament(); }, "", nullptr,
[]() { return true; }, m_parent);
append_menu_item(
menu, wxID_ANY, _L("Delete"), _L("Delete this filament"), [](wxCommandEvent &) {
plater()->sidebar().delete_filament(-2); }, "menu_delete", nullptr,
[]() { return plater()->sidebar().combos_filament().size() > 1; }, m_parent);
}
//BBS: add part plate related logic
void MenuFactory::create_plate_menu()
{
@@ -1586,6 +1600,8 @@ void MenuFactory::init(wxWindow* parent)
//BBS: add part plate related logic
create_plate_menu();
create_filament_action_menu();
// create "Instance to Object" menu item
append_menu_item_instance_to_object(&m_instance_menu);
}
@@ -1743,6 +1759,8 @@ wxMenu* MenuFactory::assemble_multi_selection_menu()
return menu;
}
wxMenu *MenuFactory::filament_action_menu() { return &m_filament_action_menu; }
//BBS: add partplate related logic
wxMenu* MenuFactory::plate_menu()

View File

@@ -78,6 +78,8 @@ public:
wxMenu* assemble_part_menu();
wxMenu* assemble_multi_selection_menu();
wxMenu *filament_action_menu();
private:
enum MenuType {
mtObjectFFF = 0,
@@ -98,6 +100,8 @@ private:
MenuWithSeparators m_plate_menu;
MenuWithSeparators m_assemble_object_menu;
MenuWithSeparators m_assemble_part_menu;
wxMenu m_filament_action_menu;
// Removed/Prepended Items according to the view mode
@@ -120,6 +124,8 @@ private:
void create_bbl_assemble_object_menu();
void create_bbl_assemble_part_menu();
void create_filament_action_menu();
wxMenu* append_submenu_add_generic(wxMenu* menu, ModelVolumeType type);
// Orca: add submenu for adding handy models
wxMenu* append_submenu_add_handy_model(wxMenu* menu, ModelVolumeType type);

View File

@@ -351,6 +351,7 @@ struct Sidebar::priv
ScalableButton * m_bpButton_del_filament;
ScalableButton * m_bpButton_ams_filament;
ScalableButton * m_bpButton_set_filament;
int m_menu_filament_id = -1;
wxPanel* m_panel_filament_content;
wxScrolledWindow* m_scrolledWindow_filament_content;
wxStaticLine* m_staticline2;
@@ -1107,20 +1108,20 @@ Sidebar::Sidebar(Plater *parent)
// ORCA Moved add button after delete button to prevent add button position change when remove icon automatically hidden
ScalableButton* del_btn = new ScalableButton(p->m_panel_filament_title, wxID_ANY, "delete_filament");
del_btn->SetToolTip(_L("Remove last filament"));
del_btn->Bind(wxEVT_BUTTON, [this, scrolled_sizer](wxCommandEvent &e) {
delete_filament();
});
p->m_bpButton_del_filament = del_btn;
//ScalableButton* del_btn = new ScalableButton(p->m_panel_filament_title, wxID_ANY, "delete_filament");
//del_btn->SetToolTip(_L("Remove last filament"));
//del_btn->Bind(wxEVT_BUTTON, [this, scrolled_sizer](wxCommandEvent &e) {
// delete_filament();
//});
//p->m_bpButton_del_filament = del_btn;
bSizer39->Add(del_btn, 0, wxALIGN_CENTER | wxLEFT, FromDIP(SidebarProps::IconSpacing()));
//bSizer39->Add(del_btn, 0, wxALIGN_CENTER | wxLEFT, FromDIP(SidebarProps::IconSpacing()));
bSizer39->Add(add_btn, 0, wxALIGN_CENTER | wxLEFT, FromDIP(SidebarProps::IconSpacing())); // ORCA Moved add button after delete button to prevent add button position change when remove icon automatically hidden
bSizer39->AddSpacer(FromDIP(20));
if (p->combos_filament.size() <= 1) { // ORCA Fix Flushing button and Delete filament button not hidden on launch while only 1 filament exist
bSizer39->Hide(p->m_flushing_volume_btn);
bSizer39->Hide(p->m_bpButton_del_filament); // ORCA: Hide delete filament button if there is only one filament
//bSizer39->Hide(p->m_bpButton_del_filament); // ORCA: Hide delete filament button if there is only one filament
}
ams_btn = new ScalableButton(p->m_panel_filament_title, wxID_ANY, "ams_fila_sync", wxEmptyString, wxDefaultSize, wxDefaultPosition,
@@ -1318,16 +1319,18 @@ void Sidebar::init_filament_combo(PlaterPresetComboBox **combo, const int filame
combo_and_btn_sizer->Add(32 * em / 10, 0, 0, 0, 0);
combo_and_btn_sizer->Add(del_btn, 0, wxALIGN_CENTER_VERTICAL, 5 * em / 10);
*/
ScalableButton* edit_btn = new ScalableButton(p->m_panel_filament_content, wxID_ANY, "edit");
ScalableButton* edit_btn = new ScalableButton(p->m_panel_filament_content, wxID_ANY, "menu_filament");
edit_btn->SetToolTip(_L("Click to edit preset"));
PlaterPresetComboBox* combobox = (*combo);
edit_btn->Bind(wxEVT_BUTTON, [this, combobox, filament_idx](wxCommandEvent)
{
p->editing_filament = -1;
if (combobox->switch_to_tab())
p->editing_filament = filament_idx; // sync with TabPresetComboxBox's m_filament_idx
});
edit_btn->Bind(wxEVT_BUTTON, [this, edit_btn, filament_idx](wxCommandEvent) {
auto menu = p->plater->filament_action_menu();
wxPoint pt { 0, edit_btn->GetSize().GetHeight() + 10 };
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);
});
combobox->edit_btn = edit_btn;
combo_and_btn_sizer->Add(edit_btn, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, FromDIP(SidebarProps::ElementSpacing()) - FromDIP(2)); // ElementSpacing - 2 (from combo box))
@@ -1865,6 +1868,9 @@ void Sidebar::delete_filament(size_t filament_id) {
if (p->combos_filament.size() <= 1) return;
size_t filament_count = p->combos_filament.size() - 1;
if (filament_id == size_t(-2)) {
filament_id = p->m_menu_filament_id;
}
if (filament_id == size_t(-1)) {
filament_id = filament_count;
}
@@ -1887,6 +1893,14 @@ void Sidebar::delete_filament(size_t filament_id) {
wxGetApp().preset_bundle->export_selections(*wxGetApp().app_config);
}
void Sidebar::edit_filament()
{
p->editing_filament = -1;
if (p->m_menu_filament_id >= 0 && p->m_menu_filament_id < p->combos_filament.size()
&& p->combos_filament[p->m_menu_filament_id]->switch_to_tab())
p->editing_filament = p->m_menu_filament_id; // sync with TabPresetComboxBox's m_filament_idx
}
void Sidebar::add_custom_filament(wxColour new_col) {
if (p->combos_filament.size() >= MAXIMUM_EXTRUDER_NUMBER) return;
@@ -1912,43 +1926,41 @@ std::map<int, DynamicPrintConfig> Sidebar::build_filament_ams_list(MachineObject
std::map<int, DynamicPrintConfig> filament_ams_list;
if (!obj) return filament_ams_list;
auto vt_tray = obj->vt_slot[0];
if (obj->ams_support_virtual_tray) {
DynamicPrintConfig vt_tray_config;
vt_tray_config.set_key_value("filament_id", new ConfigOptionStrings{ vt_tray.setting_id });
vt_tray_config.set_key_value("tag_uid", new ConfigOptionStrings{ vt_tray.tag_uid });
vt_tray_config.set_key_value("filament_type", new ConfigOptionStrings{ vt_tray.type });
vt_tray_config.set_key_value("tray_name", new ConfigOptionStrings{ std::string("Ext") });
vt_tray_config.set_key_value("filament_colour", new ConfigOptionStrings{ into_u8(wxColour("#" + vt_tray.color).GetAsString(wxC2S_HTML_SYNTAX)) });
vt_tray_config.set_key_value("filament_exist", new ConfigOptionBools{ true });
auto build_tray_config = [](AmsTray const & tray, std::string const & name) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": name %1% setting_id %2% color %3%") % name % tray.setting_id % tray.color;
DynamicPrintConfig tray_config;
tray_config.set_key_value("filament_id", new ConfigOptionStrings{tray.setting_id});
tray_config.set_key_value("tag_uid", new ConfigOptionStrings{tray.tag_uid});
tray_config.set_key_value("filament_type", new ConfigOptionStrings{tray.type});
tray_config.set_key_value("tray_name", new ConfigOptionStrings{ name });
tray_config.set_key_value("filament_colour", new ConfigOptionStrings{into_u8(wxColour("#" + tray.color).GetAsString(wxC2S_HTML_SYNTAX))});
tray_config.set_key_value("filament_exist", new ConfigOptionBools{tray.is_exists});
vt_tray_config.set_key_value("filament_multi_colors", new ConfigOptionStrings{});
for (int i = 0; i < vt_tray.cols.size(); ++i) {
vt_tray_config.opt<ConfigOptionStrings>("filament_multi_colors")->values.push_back(into_u8(wxColour("#" + vt_tray.cols[i]).GetAsString(wxC2S_HTML_SYNTAX)));
tray_config.set_key_value("filament_multi_colors", new ConfigOptionStrings{});
for (int i = 0; i < tray.cols.size(); ++i) {
tray_config.opt<ConfigOptionStrings>("filament_multi_colors")->values.push_back(into_u8(wxColour("#" + tray.cols[i]).GetAsString(wxC2S_HTML_SYNTAX)));
}
filament_ams_list.emplace(VIRTUAL_TRAY_MAIN_ID, std::move(vt_tray_config));
return tray_config;
};
auto vt_tray = obj->vt_tray;
if (obj->ams_support_virtual_tray) {
int extruder = 0x10000;
//for (auto &vt_tray : obj->vt_slot) {
filament_ams_list.emplace(extruder + VIRTUAL_TRAY_ID, build_tray_config(vt_tray, "Ext"));
extruder = 0;
//}
}
auto list = obj->amsList;
for (auto ams : list) {
char n = ams.first.front() - '0' + 'A';
int extruder = /*ams.nozzle ? 0 :*/ 0x10000;
for (auto tray : ams.second->trayList) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__
<< boost::format(": ams %1% tray %2% id %3% color %4%") % ams.first % tray.first % tray.second->setting_id % tray.second->color;
char t = tray.first.front() - '0' + '1';
DynamicPrintConfig tray_config;
tray_config.set_key_value("filament_id", new ConfigOptionStrings{ tray.second->setting_id });
tray_config.set_key_value("tag_uid", new ConfigOptionStrings{ tray.second->tag_uid });
tray_config.set_key_value("filament_type", new ConfigOptionStrings{ tray.second->type });
tray_config.set_key_value("tray_name", new ConfigOptionStrings{ std::string(1, n) + std::string(1, t) });
tray_config.set_key_value("filament_colour", new ConfigOptionStrings{ into_u8(wxColour("#" + tray.second->color).GetAsString(wxC2S_HTML_SYNTAX)) });
tray_config.set_key_value("filament_exist", new ConfigOptionBools{ tray.second->is_exists });
tray_config.set_key_value("filament_multi_colors", new ConfigOptionStrings{});
for (int i = 0; i < tray.second->cols.size(); ++i) {
tray_config.opt<ConfigOptionStrings>("filament_multi_colors")->values.push_back(into_u8(wxColour("#" + tray.second->cols[i]).GetAsString(wxC2S_HTML_SYNTAX)));
}
filament_ams_list.emplace(((n - 'A') * 4 + t - '1'), std::move(tray_config));
filament_ams_list.emplace(extruder + ((n - 'A') * 4 + t - '1'),
build_tray_config(*tray.second, std::string(1, n) + std::string(1, t)));
extruder = 0;
}
}
return filament_ams_list;
@@ -15077,6 +15089,7 @@ wxMenu* Plater::default_menu() { return p->menus.default_menu();
wxMenu* Plater::instance_menu() { return p->menus.instance_menu(); }
wxMenu* Plater::layer_menu() { return p->menus.layer_menu(); }
wxMenu* Plater::multi_selection_menu() { return p->menus.multi_selection_menu(); }
wxMenu *Plater::filament_action_menu() { return p->menus.filament_action_menu(); }
int Plater::GetPlateIndexByRightMenuInLeftUI() { return p->m_is_RightClickInLeftUI; }
void Plater::SetPlateIndexByRightMenuInLeftUI(int index) { p->m_is_RightClickInLeftUI = index; }
SuppressBackgroundProcessingUpdate::SuppressBackgroundProcessingUpdate() :

View File

@@ -153,6 +153,7 @@ public:
void add_filament();
void delete_filament(size_t filament_id = size_t(-1));
void edit_filament();
void add_custom_filament(wxColour new_col);
// BBS
void on_bed_type_change(BedType bed_type);
@@ -782,6 +783,7 @@ public:
wxMenu* instance_menu();
wxMenu* layer_menu();
wxMenu* multi_selection_menu();
wxMenu* filament_action_menu();
int GetPlateIndexByRightMenuInLeftUI();
void SetPlateIndexByRightMenuInLeftUI(int);
static bool has_illegal_filename_characters(const wxString& name);

View File

@@ -398,10 +398,15 @@ void PresetComboBox::add_ams_filaments(std::string selected, bool alias_name)
{
bool is_bbl_vendor_preset = m_preset_bundle->is_bbl_vendor();
if (is_bbl_vendor_preset && !m_preset_bundle->filament_ams_list.empty()) {
set_label_marker(Append(separator(L("AMS filaments")), wxNullBitmap));
bool dual_extruder = (--m_preset_bundle->filament_ams_list.end())->first & 0x10000;
set_label_marker(Append(separator(dual_extruder ? L("Left filaments") : L("AMS filaments")), wxNullBitmap));
m_first_ams_filament = GetCount();
auto &filaments = m_collection->get_presets();
for (auto &entry : m_preset_bundle->filament_ams_list) {
if (dual_extruder && (entry.first & 0x10000)) {
dual_extruder = false;
set_label_marker(Append(separator(L("Right filaments")), wxNullBitmap));
}
auto & tray = entry.second;
std::string filament_id = tray.opt_string("filament_id", 0u);
if (filament_id.empty()) continue;