From edb70b06b587689eb93675939a904d05607fa001 Mon Sep 17 00:00:00 2001 From: tao wang Date: Mon, 3 Jul 2023 22:17:17 +0800 Subject: [PATCH] NEW:check printer status Change-Id: If2fec3c693af19bb554efd6f69098a465023ecd5 (cherry picked from commit 8516e7b92eb0073123cacefbd5a256755e6caccc) --- src/slic3r/GUI/CalibrationWizardPage.hpp | 1 + .../GUI/CalibrationWizardPresetPage.cpp | 310 +++++++++++++++++- .../GUI/CalibrationWizardPresetPage.hpp | 30 +- src/slic3r/GUI/SelectMachine.cpp | 1 - 4 files changed, 330 insertions(+), 12 deletions(-) diff --git a/src/slic3r/GUI/CalibrationWizardPage.hpp b/src/slic3r/GUI/CalibrationWizardPage.hpp index 99df3ae76c..105163dbac 100644 --- a/src/slic3r/GUI/CalibrationWizardPage.hpp +++ b/src/slic3r/GUI/CalibrationWizardPage.hpp @@ -249,6 +249,7 @@ protected: wxWindow* m_parent { nullptr }; CaliPageCaption* m_page_caption { nullptr }; CaliPageActionPanel* m_action_panel { nullptr }; + wxStaticText* m_statictext_printer_msg{ nullptr }; private: CalibrationWizardPage* m_prev_page {nullptr}; diff --git a/src/slic3r/GUI/CalibrationWizardPresetPage.cpp b/src/slic3r/GUI/CalibrationWizardPresetPage.cpp index 129fb978fb..71b12b5b4f 100644 --- a/src/slic3r/GUI/CalibrationWizardPresetPage.cpp +++ b/src/slic3r/GUI/CalibrationWizardPresetPage.cpp @@ -699,6 +699,12 @@ void CalibrationPresetPage::create_page(wxWindow* parent) m_custom_range_panel = new CaliPresetCustomRangePanel(parent); } + m_action_panel = new CaliPageActionPanel(parent, m_cali_mode, CaliPageType::CALI_PAGE_PRESET); + + m_statictext_printer_msg = new wxStaticText(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER_HORIZONTAL); + m_statictext_printer_msg->SetFont(::Label::Body_13); + m_statictext_printer_msg->Hide(); + m_top_sizer->Add(m_selection_panel, 0); m_top_sizer->Add(m_filament_list_panel, 0); m_top_sizer->Add(m_ext_spool_panel, 0); @@ -708,18 +714,93 @@ void CalibrationPresetPage::create_page(wxWindow* parent) m_top_sizer->AddSpacer(PRESET_GAP); } m_top_sizer->Add(m_tips_panel, 0); - m_top_sizer->Add(m_sending_panel, 0); - m_top_sizer->AddSpacer(PRESET_GAP); - - m_action_panel = new CaliPageActionPanel(parent, m_cali_mode, CaliPageType::CALI_PAGE_PRESET); - + m_top_sizer->Add(m_statictext_printer_msg, 0, wxALIGN_CENTER_HORIZONTAL, 0); m_top_sizer->Add(m_action_panel, 0, wxEXPAND, 0); Bind(EVT_CALI_TRAY_CHANGED, &CalibrationPresetPage::on_select_tray, this); } +void CalibrationPresetPage::update_print_status_msg(wxString msg, bool is_warning) +{ + update_priner_status_msg(msg, is_warning); +} + +wxString CalibrationPresetPage::format_text(wxString& m_msg) +{ + if (wxGetApp().app_config->get("language") != "zh_CN") { return m_msg; } + + wxString out_txt = m_msg; + wxString count_txt = ""; + int new_line_pos = 0; + + for (int i = 0; i < m_msg.length(); i++) { + auto text_size = m_statictext_printer_msg->GetTextExtent(count_txt); + if (text_size.x < (FromDIP(600))) { + count_txt += m_msg[i]; + } + else { + out_txt.insert(i - 1, '\n'); + count_txt = ""; + } + } + return out_txt; +} + +void CalibrationPresetPage::stripWhiteSpace(std::string& str) +{ + if (str == "") { return; } + + string::iterator cur_it; + cur_it = str.begin(); + + while (cur_it != str.end()) { + if ((*cur_it) == '\n' || (*cur_it) == ' ') { + cur_it = str.erase(cur_it); + } + else { + cur_it++; + } + } +} + +void CalibrationPresetPage::update_priner_status_msg(wxString msg, bool is_warning) +{ + auto colour = is_warning ? wxColour(0xFF, 0x6F, 0x00) : wxColour(0x6B, 0x6B, 0x6B); + m_statictext_printer_msg->SetForegroundColour(colour); + + if (msg.empty()) { + if (!m_statictext_printer_msg->GetLabel().empty()) { + m_statictext_printer_msg->SetLabel(wxEmptyString); + m_statictext_printer_msg->Hide(); + Layout(); + Fit(); + } + } + else { + msg = format_text(msg); + + auto str_new = msg.ToStdString(); + stripWhiteSpace(str_new); + + auto str_old = m_statictext_printer_msg->GetLabel().ToStdString(); + stripWhiteSpace(str_old); + + if (str_new != str_old) { + if (m_statictext_printer_msg->GetLabel() != msg) { + m_statictext_printer_msg->SetLabel(msg); + m_statictext_printer_msg->SetMinSize(wxSize(FromDIP(600), -1)); + m_statictext_printer_msg->SetMaxSize(wxSize(FromDIP(600), -1)); + m_statictext_printer_msg->Wrap(FromDIP(600)); + m_statictext_printer_msg->Show(); + Layout(); + Fit(); + } + } + } +} + void CalibrationPresetPage::on_select_nozzle(wxCommandEvent& evt) { update_combobox_filaments(curr_obj); @@ -914,17 +995,228 @@ void CalibrationPresetPage::update_combobox_filaments(MachineObject* obj) select_default_compatible_filament(); } +bool CalibrationPresetPage::is_blocking_printing() +{ + DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager(); + if (!dev) return true; + + MachineObject* obj_ = dev->get_selected_machine(); + if (obj_ == nullptr) return true; + + PresetBundle* preset_bundle = wxGetApp().preset_bundle; + auto source_model = preset_bundle->printers.get_edited_preset().get_printer_type(preset_bundle); + auto target_model = obj_->printer_type; + + if (source_model != target_model) { + std::vector compatible_machine = dev->get_compatible_machine(target_model); + vector::iterator it = find(compatible_machine.begin(), compatible_machine.end(), source_model); + if (it == compatible_machine.end()) { + return true; + } + } + + return false; +} + +void CalibrationPresetPage::update_show_status() +{ + if (get_status() == CaliPresetPageStatus::CaliPresetStatusSending) + return; + + if (get_status() == CaliPresetPageStatus::CaliPresetStatusSendingCanceled) + return; + + NetworkAgent* agent = Slic3r::GUI::wxGetApp().getAgent(); + DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager(); + if (!agent) {return;} + if (!dev) return; + dev->check_pushing(); + + MachineObject* obj_ = dev->get_selected_machine(); + if (!obj_) { + if (agent->is_user_login()) { + show_status(CaliPresetPageStatus::CaliPresetStatusInvalidPrinter); + } + else { + show_status(CaliPresetPageStatus::CaliPresetStatusNoUserLogin); + } + return; + } + + if (!obj_->is_lan_mode_printer()) { + if (!agent->is_server_connected()) { + agent->refresh_connection(); + show_status(CaliPresetPageStatus::CaliPresetStatusConnectingServer); + return; + } + } + + if (wxGetApp().app_config && wxGetApp().app_config->get("internal_debug").empty()) { + if (obj_->upgrade_force_upgrade) { + show_status(CaliPresetPageStatus::CaliPresetStatusNeedForceUpgrading); + return; + } + + if (obj_->upgrade_consistency_request) { + show_status(CaliPresetStatusNeedConsistencyUpgrading); + return; + } + } + + if (is_blocking_printing()) { + show_status(CaliPresetPageStatus::CaliPresetStatusUnsupportedPrinter); + return; + } + else if (obj_->is_in_upgrading()) { + show_status(CaliPresetPageStatus::CaliPresetStatusInUpgrading); + return; + } + else if (obj_->is_system_printing()) { + show_status(CaliPresetPageStatus::CaliPresetStatusInSystemPrinting); + return; + } + else if (obj_->is_in_printing()) { + show_status(CaliPresetPageStatus::CaliPresetStatusInPrinting); + return; + } + else if (need_check_sdcard(obj_) && obj_->get_sdcard_state() == MachineObject::SdcardState::NO_SDCARD) { + show_status(CaliPresetPageStatus::CaliPresetStatusNoSdcard); + return; + } + + // check sdcard when if lan mode printer + if (obj_->is_lan_mode_printer()) { + if (obj_->get_sdcard_state() == MachineObject::SdcardState::NO_SDCARD) { + show_status(CaliPresetPageStatus::CaliPresetStatusLanModeNoSdcard); + return; + } + } + + show_status(CaliPresetPageStatus::CaliPresetStatusNormal); +} + + +bool CalibrationPresetPage::need_check_sdcard(MachineObject* obj) +{ + bool need_check = false; + if (obj->printer_type == "BL-P001" || obj->printer_type == "BL-P002") { + if (m_cali_mode == CalibMode::Calib_Flow_Rate && m_cali_method == CalibrationMethod::CALI_METHOD_MANUAL) { + need_check = true; + } + else if (m_cali_mode == CalibMode::Calib_Vol_speed_Tower && m_cali_method == CalibrationMethod::CALI_METHOD_MANUAL) + { + need_check = true; + } + } + else if (obj->printer_type == "C11" || obj->printer_type == "C12") { + if (m_cali_mode == CalibMode::Calib_Flow_Rate && m_cali_method == CalibrationMethod::CALI_METHOD_MANUAL) { + need_check = true; + } + else if (m_cali_mode == CalibMode::Calib_Vol_speed_Tower && m_cali_method == CalibrationMethod::CALI_METHOD_MANUAL) { + need_check = true; + } + } + + return need_check; +} + void CalibrationPresetPage::show_status(CaliPresetPageStatus status) { if (status == CaliPresetPageStatus::CaliPresetStatusSending) { - m_sending_panel->Show(); + sending_mode(); } else { - m_sending_panel->Hide(); + prepare_mode(); + } + + if (m_page_status != status) + //BOOST_LOG_TRIVIAL(info) << "CalibrationPresetPage: show_status = " << status << "(" << get_print_status_info(status) << ")"; + m_page_status = status; + + // other + if (status == CaliPresetPageStatus::CaliPresetStatusInit) { + update_print_status_msg(wxEmptyString, false); + Enable_Send_Button(false); + } + else if (status == CaliPresetPageStatus::CaliPresetStatusNormal) { + update_print_status_msg(wxEmptyString, false); + Enable_Send_Button(true); + } + else if (status == CaliPresetPageStatus::CaliPresetStatusNoUserLogin) { + wxString msg_text = _L("No login account, only printers in LAN mode are displayed"); + update_print_status_msg(msg_text, false); + Enable_Send_Button(false); + } + else if (status == CaliPresetPageStatus::CaliPresetStatusInvalidPrinter) { + update_print_status_msg(wxEmptyString, true); + Enable_Send_Button(false); + } + else if (status == CaliPresetPageStatus::CaliPresetStatusConnectingServer) { + wxString msg_text = _L("Connecting to server"); + update_print_status_msg(msg_text, true); + Enable_Send_Button(false); + } + else if (status == CaliPresetPageStatus::CaliPresetStatusInUpgrading) { + wxString msg_text = _L("Cannot send the print job when the printer is updating firmware"); + update_print_status_msg(msg_text, true); + Enable_Send_Button(false); + } + else if (status == CaliPresetPageStatus::CaliPresetStatusInSystemPrinting) { + wxString msg_text = _L("The printer is executing instructions. Please restart printing after it ends"); + update_print_status_msg(msg_text, true); + Enable_Send_Button(false); + } + else if (status == CaliPresetPageStatus::CaliPresetStatusInPrinting) { + wxString msg_text = _L("The printer is busy on other print job"); + update_print_status_msg(msg_text, true); + Enable_Send_Button(false); + } + else if (status == CaliPresetPageStatus::CaliPresetStatusSending) { + m_sending_panel->Show(); + Enable_Send_Button(false); + } + else if (status == CaliPresetPageStatus::CaliPresetStatusSendingCanceled) { + Enable_Send_Button(true); + } + else if (status == CaliPresetPageStatus::CaliPresetStatusLanModeNoSdcard) { + wxString msg_text = _L("An SD card needs to be inserted before printing via LAN."); + update_print_status_msg(msg_text, true); + Enable_Send_Button(true); + } + else if (status == CaliPresetPageStatus::CaliPresetStatusNoSdcard) { + wxString msg_text = _L("An SD card needs to be inserted before printing."); + update_print_status_msg(msg_text, true); + Enable_Send_Button(false); + } + else if (status == CaliPresetPageStatus::CaliPresetStatusNeedForceUpgrading) { + wxString msg_text = _L("Cannot send the print job to a printer whose firmware is required to get updated."); + update_print_status_msg(msg_text, true); + Enable_Send_Button(false); + } + else if (status == CaliPresetPageStatus::CaliPresetStatusNeedConsistencyUpgrading) { + wxString msg_text = _L("Cannot send the print job to a printer whose firmware is required to get updated."); + update_print_status_msg(msg_text, true); + Enable_Send_Button(false); } Layout(); } +void CalibrationPresetPage::Enable_Send_Button(bool enable) +{ + m_action_panel->enable_button(CaliPageActionType::CALI_ACTION_CALI, enable); +} + +void CalibrationPresetPage::prepare_mode() +{ + Enable_Send_Button(true); +} + +void CalibrationPresetPage::sending_mode() +{ + Enable_Send_Button(false); +} + + float CalibrationPresetPage::get_nozzle_value() { double nozzle_value = 0.0; @@ -942,6 +1234,10 @@ float CalibrationPresetPage::get_nozzle_value() void CalibrationPresetPage::update(MachineObject* obj) { curr_obj = obj; + + //update printer status + update_show_status(); + } void CalibrationPresetPage::on_device_connected(MachineObject* obj) diff --git a/src/slic3r/GUI/CalibrationWizardPresetPage.hpp b/src/slic3r/GUI/CalibrationWizardPresetPage.hpp index 22724e82ba..2e06d292b3 100644 --- a/src/slic3r/GUI/CalibrationWizardPresetPage.hpp +++ b/src/slic3r/GUI/CalibrationWizardPresetPage.hpp @@ -101,6 +101,18 @@ enum CaliPresetPageStatus CaliPresetStatusInit = 0, CaliPresetStatusNormal, CaliPresetStatusSending, + CaliPresetStatusNoUserLogin, + CaliPresetStatusInvalidPrinter, + CaliPresetStatusConnectingServer, + CaliPresetStatusInUpgrading, + CaliPresetStatusInSystemPrinting, + CaliPresetStatusInPrinting, + CaliPresetStatusSendingCanceled, + CaliPresetStatusLanModeNoSdcard, + CaliPresetStatusNoSdcard, + CaliPresetStatusNeedForceUpgrading, + CaliPresetStatusNeedConsistencyUpgrading, + CaliPresetStatusUnsupportedPrinter, }; class CalibrationPresetPage : public CalibrationWizardPage @@ -116,6 +128,10 @@ public: void create_page(wxWindow* parent); + void update_print_status_msg(wxString msg, bool is_warning); + wxString format_text(wxString& m_msg); + void stripWhiteSpace(std::string& str); + void update_priner_status_msg(wxString msg, bool is_warning); void update(MachineObject* obj) override; void on_device_connected(MachineObject* obj) override; @@ -188,13 +204,20 @@ protected: std::string& incompatiable_filament_name, std::string& error_tips); - void update_combobox_filaments(MachineObject* obj); - float get_nozzle_value(); + void update_combobox_filaments(MachineObject* obj); + void update_show_status(); void show_status(CaliPresetPageStatus status); + void Enable_Send_Button(bool enable); + void prepare_mode(); + void sending_mode(); + bool is_blocking_printing(); + bool need_check_sdcard(MachineObject* obj); + + CaliPresetPageStatus get_status() { return m_page_status; } - CaliPageStepGuide* m_step_panel { nullptr }; + CaliPageStepGuide* m_step_panel{ nullptr }; CaliPresetCaliStagePanel* m_cali_stage_panel { nullptr }; wxPanel* m_selection_panel { nullptr }; wxPanel* m_filament_from_panel { nullptr }; @@ -238,7 +261,6 @@ protected: CaliPresetPageStatus m_page_status { CaliPresetPageStatus::CaliPresetStatusInit }; bool m_show_custom_range { false }; - MachineObject* curr_obj { nullptr }; }; diff --git a/src/slic3r/GUI/SelectMachine.cpp b/src/slic3r/GUI/SelectMachine.cpp index 028841db48..e6e93b32c5 100644 --- a/src/slic3r/GUI/SelectMachine.cpp +++ b/src/slic3r/GUI/SelectMachine.cpp @@ -875,7 +875,6 @@ static std::string MachineBedTypeString[BED_TYPE_COUNT] = { "pe", }; - void SelectMachineDialog::stripWhiteSpace(std::string& str) { if (str == "") { return; }