diff --git a/src/slic3r/GUI/DeviceManager.cpp b/src/slic3r/GUI/DeviceManager.cpp index 32d2d655f..bf9d1ec5b 100644 --- a/src/slic3r/GUI/DeviceManager.cpp +++ b/src/slic3r/GUI/DeviceManager.cpp @@ -5979,7 +5979,12 @@ void MachineObject::parse_new_info(json print) extder_data.target_extder_id = get_flag_bits(extruder["state"].get(), 8, 4); extder_data.switch_extder_state = (ExtruderSwitchState) get_flag_bits(extruder["state"].get(), 12, 3); - if (extder_data.switch_extder_state != ExtruderSwitchState::ES_SWITCHING && extder_data.target_extder_id == extder_data.current_extder_id) { + if (m_extder_data.current_extder_id != extder_data.current_extder_id) + { + flag_update_nozzle = true; + } + else if (extder_data.switch_extder_state == ES_SWITCHING_FAILED) + { flag_update_nozzle = true; } diff --git a/src/slic3r/GUI/DeviceManager.hpp b/src/slic3r/GUI/DeviceManager.hpp index 7e537a2dc..7b34fa3c7 100644 --- a/src/slic3r/GUI/DeviceManager.hpp +++ b/src/slic3r/GUI/DeviceManager.hpp @@ -41,6 +41,7 @@ #define MAIN_NOZZLE_ID 0 #define DEPUTY_NOZZLE_ID 1 #define UNIQUE_NOZZLE_ID MAIN_NOZZLE_ID +#define INVALID_NOZZLE_ID -1 #define VIRTUAL_TRAY_MAIN_ID 255 #define VIRTUAL_TRAY_DEPUTY_ID 254 diff --git a/src/slic3r/GUI/StatusPanel.cpp b/src/slic3r/GUI/StatusPanel.cpp index 4c2edc305..75822bad3 100644 --- a/src/slic3r/GUI/StatusPanel.cpp +++ b/src/slic3r/GUI/StatusPanel.cpp @@ -229,7 +229,13 @@ void ExtruderImage::setExtruderCount(int nozzle_num) void ExtruderImage::setExtruderUsed(std::string loc) { //current_nozzle_idx = nozzle_id; + if (current_nozzle_loc == loc) + { + return; + } + current_nozzle_loc = loc; + Refresh(); } void ExtruderImage::update(ExtruderState single_state) @@ -1669,6 +1675,7 @@ wxBoxSizer *StatusBasePanel::create_extruder_control(wxWindow *parent) StateColor e_ctrl_bd(std::pair(BUTTON_HOVER_COL, StateColor::Hovered), std::pair(BUTTON_NORMAL1_COL, StateColor::Normal)); m_nozzle_btn_panel = new SwitchBoard(panel, _L("Left"), _L("Right"), wxSize(FromDIP(126), FromDIP(26))); + m_nozzle_btn_panel->SetAutoDisableWhenSwitch(); m_bpButton_e_10 = new Button(panel, "", "monitor_extruder_up", 0, FromDIP(22)); m_bpButton_e_10->SetBorderWidth(2); @@ -2794,15 +2801,6 @@ void StatusPanel::update_misc_ctrl(MachineObject *obj) /*style*/ m_nozzle_btn_panel->Show(); - if (!obj->is_in_printing() && obj->ams_status_main != AMS_STATUS_MAIN_FILAMENT_CHANGE) - { - m_nozzle_btn_panel->Enable(); - } - else - { - m_nozzle_btn_panel->Disable(); - } - m_extruderImage[select_index]->setExtruderCount(m_nozzle_num); assert(obj->m_extder_data.extders.size() > 1); @@ -2826,6 +2824,21 @@ void StatusPanel::update_misc_ctrl(MachineObject *obj) m_extruderImage[select_index]->setExtruderUsed("left"); m_nozzle_btn_panel->updateState("left"); } + + targ_nozzle_id_from_pc = INVALID_NOZZLE_ID;// the switching is finished + obj->flag_update_nozzle = false; + } + + /*enable status*/ + if (obj->is_in_printing() || + obj->ams_status_main == AMS_STATUS_MAIN_FILAMENT_CHANGE || + targ_nozzle_id_from_pc != INVALID_NOZZLE_ID) + { + m_nozzle_btn_panel->Disable(); + } + else + { + m_nozzle_btn_panel->Enable(); } } else { m_nozzle_btn_panel->Hide(); @@ -4653,9 +4666,15 @@ void StatusPanel::on_nozzle_selected(wxCommandEvent &event) return; } - obj->flag_update_nozzle = false; - auto nozzle_id = event.GetInt();obj->command_select_extruder(nozzle_id); + auto nozzle_id = event.GetInt(); + if(obj->command_select_extruder(nozzle_id) == 0) + { + targ_nozzle_id_from_pc = nozzle_id; + return; + } } + + m_nozzle_btn_panel->Enable(); } void StatusPanel::on_show_print_options(wxCommandEvent& event) diff --git a/src/slic3r/GUI/StatusPanel.hpp b/src/slic3r/GUI/StatusPanel.hpp index 906d50df2..baf589fb5 100644 --- a/src/slic3r/GUI/StatusPanel.hpp +++ b/src/slic3r/GUI/StatusPanel.hpp @@ -407,6 +407,9 @@ protected: Button * m_button_clean; wxSimplebook* m_extruder_book; std::vector m_extruderImage; + + /*the target nozzle id from PC-SwitchBoard, default to INVALID_NOZZLE_ID if not switching*/ + int targ_nozzle_id_from_pc = INVALID_NOZZLE_ID; SwitchBoard * m_nozzle_btn_panel; wxStaticText * m_text_tasklist_caption; diff --git a/src/slic3r/GUI/Widgets/SwitchButton.cpp b/src/slic3r/GUI/Widgets/SwitchButton.cpp index df18b7d9b..c08ef9939 100644 --- a/src/slic3r/GUI/Widgets/SwitchButton.cpp +++ b/src/slic3r/GUI/Widgets/SwitchButton.cpp @@ -235,7 +235,7 @@ void SwitchBoard::doRender(wxDC &dc) /*left*/ if (switch_left) { - dc.SetBrush(wxBrush(wxColour(0, 174, 66))); + is_enable ? dc.SetBrush(wxBrush(wxColour(0, 174, 66))) : dc.SetBrush(disable_color); dc.DrawRoundedRectangle(0, 0, GetSize().x / 2, GetSize().y, 8); } @@ -285,9 +285,36 @@ void SwitchBoard::on_left_down(wxMouseEvent &evt) switch_right = true; index = 0; } + + if (auto_disable_when_switch) + { + is_enable = false;// make it disable while switching + } Refresh(); wxCommandEvent event(wxCUSTOMEVT_SELECT_NOZZLE_POS); event.SetInt(index); wxPostEvent(this, event); +} + +void SwitchBoard::Enable() +{ + if (is_enable == true) + { + return; + } + + is_enable = true; + Refresh(); +} + +void SwitchBoard::Disable() +{ + if (is_enable == false) + { + return; + } + + is_enable = false; + Refresh(); } \ No newline at end of file diff --git a/src/slic3r/GUI/Widgets/SwitchButton.hpp b/src/slic3r/GUI/Widgets/SwitchButton.hpp index c45d9101e..8e411a8dc 100644 --- a/src/slic3r/GUI/Widgets/SwitchButton.hpp +++ b/src/slic3r/GUI/Widgets/SwitchButton.hpp @@ -58,13 +58,20 @@ public: bool is_enable {true}; public: - void paintEvent(wxPaintEvent &evt); - void render(wxDC &dc); - void doRender(wxDC &dc); - void on_left_down(wxMouseEvent &evt); - void Enable(){is_enable = true;Refresh();}; - void Disable(){is_enable = false;Refresh();}; + void Enable(); + void Disable(); bool IsEnabled(){return is_enable;}; + + void SetAutoDisableWhenSwitch() { auto_disable_when_switch = true; }; + +protected: + void paintEvent(wxPaintEvent& evt); + void render(wxDC& dc); + void doRender(wxDC& dc); + void on_left_down(wxMouseEvent& evt); + +private: + bool auto_disable_when_switch = false; }; #endif // !slic3r_GUI_SwitchButton_hpp_