From fbe4223adae00ee8ad81d4d08ed1fd94ab3d302a Mon Sep 17 00:00:00 2001 From: tao wang Date: Wed, 19 Oct 2022 14:45:18 +0800 Subject: [PATCH] FIX:fixed some issues with sending prints 1. send to printer change to send to print sd card 2. update the default error message 3. display networking error messages on the page Change-Id: I27b67091e9449bb9d469f9ded53148e0b1a74369 --- src/slic3r/GUI/BBLStatusBarSend.cpp | 59 +++++++++++++++++++++++++++-- src/slic3r/GUI/BBLStatusBarSend.hpp | 4 +- src/slic3r/GUI/Jobs/SendJob.cpp | 5 +-- src/slic3r/GUI/ReleaseNote.cpp | 27 +++++++++++-- src/slic3r/GUI/ReleaseNote.hpp | 1 + src/slic3r/GUI/SendToPrinter.cpp | 14 +++++-- src/slic3r/GUI/SendToPrinter.hpp | 1 + 7 files changed, 96 insertions(+), 15 deletions(-) diff --git a/src/slic3r/GUI/BBLStatusBarSend.cpp b/src/slic3r/GUI/BBLStatusBarSend.cpp index 4694d11e885..f75376f4ed2 100644 --- a/src/slic3r/GUI/BBLStatusBarSend.cpp +++ b/src/slic3r/GUI/BBLStatusBarSend.cpp @@ -30,6 +30,10 @@ BBLStatusBarSend::BBLStatusBarSend(wxWindow *parent, int id) m_status_text->SetForegroundColour(wxColour(107, 107, 107)); m_status_text->SetFont(::Label::Body_13); m_status_text->Wrap(m_self->FromDIP(280)); + m_status_text->SetSize(wxSize(m_self->FromDIP(280), m_self->FromDIP(46))); + m_status_text->SetMaxSize(wxSize(m_self->FromDIP(280), m_self->FromDIP(46))); + + //m_status_text->SetSize() m_prog = new wxGauge(m_self, wxID_ANY, 100, wxDefaultPosition, wxSize(-1, m_self->FromDIP(6)), wxGA_HORIZONTAL); @@ -168,15 +172,61 @@ wxPanel* BBLStatusBarSend::get_panel() return m_self; } +bool BBLStatusBarSend::is_english_text(wxString str) +{ + std::regex reg("^[0-9a-zA-Z]+$"); + std::smatch matchResult; + + std::string pattern_Special = "{}[]<>~!@#$%^&*(),.?/ :"; + for (auto i = 0; i < str.Length(); i++) { + std::string regex_str = wxString(str[i]).ToStdString(); + if (std::regex_match(regex_str, matchResult, reg)) { + continue; + } + else { + int result = pattern_Special.find(regex_str.c_str()); + if (result < 0 || result > pattern_Special.length()) { + return false; + } + } + } + return true; +} + +wxString BBLStatusBarSend::format_text(wxStaticText* st, wxString str, int warp) +{ + int index = 0; + if (!str.empty()) { + while ((index = str.find('\n', index)) != string::npos) { + str.erase(index, 1); + } + } + + wxString out_txt = str; + wxString count_txt = ""; + int new_line_pos = 0; + + for (int i = 0; i < str.length(); i++) { + auto text_size = st->GetTextExtent(count_txt); + if (text_size.x < warp) { + count_txt += str[i]; + } + else { + out_txt.insert(i - 1, '\n'); + count_txt = ""; + } + } + return out_txt; +} + void BBLStatusBarSend::set_status_text(const wxString& txt) { //auto txtss = "Sending the printing task has timed out.\nPlease try again!"; //auto txtss = "The printing project is being uploaded... 25%%"; //m_status_text->SetLabelText(txtss); - m_status_text->SetLabelText(txt); - m_status_text->SetSize(wxSize(m_self->FromDIP(280), -1)); - m_status_text->SetMaxSize(wxSize(m_self->FromDIP(280), -1)); - m_status_text->Wrap(m_self->FromDIP(280)); + wxString str = format_text(m_status_text,txt,280); + m_status_text->SetLabelText(str); + //if (is_english_text(str)) m_status_text->Wrap(m_self->FromDIP(280)); } void BBLStatusBarSend::set_percent_text(const wxString &txt) @@ -206,6 +256,7 @@ wxString BBLStatusBarSend::get_status_text() const bool BBLStatusBarSend::update_status(wxString &msg, bool &was_cancel, int percent, bool yield) { + //auto test_txt = _L("Unkown Error.") + _L("status=150, body=Timeout was reached: Connection timed out after 10009 milliseconds [Error 28]"); set_status_text(msg); if (percent >= 0) diff --git a/src/slic3r/GUI/BBLStatusBarSend.hpp b/src/slic3r/GUI/BBLStatusBarSend.hpp index e938308fcdc..d1e24aa08f3 100644 --- a/src/slic3r/GUI/BBLStatusBarSend.hpp +++ b/src/slic3r/GUI/BBLStatusBarSend.hpp @@ -56,7 +56,9 @@ public: void set_cancel_callback(CancelFn = CancelFn()) override; inline void reset_cancel_callback() { set_cancel_callback(); } wxPanel * get_panel(); - void set_status_text(const wxString &txt); + bool is_english_text(wxString str); + wxString format_text(wxStaticText* st, wxString str, int warp); + void set_status_text(const wxString& txt); void set_percent_text(const wxString &txt); void msw_rescale(); void set_status_text(const std::string &txt); diff --git a/src/slic3r/GUI/Jobs/SendJob.cpp b/src/slic3r/GUI/Jobs/SendJob.cpp index 5d4cbc040bd..59d491dcd0d 100644 --- a/src/slic3r/GUI/Jobs/SendJob.cpp +++ b/src/slic3r/GUI/Jobs/SendJob.cpp @@ -12,7 +12,7 @@ namespace GUI { static wxString check_gcode_failed_str = _L("Abnormal print file data. Please slice again"); static wxString printjob_cancel_str = _L("Task canceled"); static wxString timeout_to_upload_str = _L("Upload task timed out. Please check the network problem and try again"); -static wxString failed_in_cloud_service_str = _L("Cloud service connection failed. Please try again."); +static wxString failed_in_cloud_service_str = _L("Send to Printer failed. Please try again."); static wxString file_is_not_exists_str = _L("Print file not found, please slice again"); static wxString file_over_size_str = _L("The print file exceeds the maximum allowable size (1GB). Please simplify the model and slice again"); static wxString print_canceled_str = _L("Task canceled"); @@ -151,8 +151,7 @@ void SendJob::process() BBL::PrintParams params; params.dev_id = m_dev_id; //params.project_name = wxGetApp().plater()->get_project_name().ToUTF8().data(); - params.project_name = wxGetApp().plater()->get_project_name().utf8_string(); - + params.project_name = wxGetApp().plater()->get_export_gcode_filename(".gcode.3mf", true).utf8_string(); params.preset_name = wxGetApp().preset_bundle->prints.get_selected_preset_name(); params.filename = job_data._3mf_path.string(); params.config_filename = job_data._3mf_config_path.string(); diff --git a/src/slic3r/GUI/ReleaseNote.cpp b/src/slic3r/GUI/ReleaseNote.cpp index 28ecd8fd210..ee0a1b771f6 100644 --- a/src/slic3r/GUI/ReleaseNote.cpp +++ b/src/slic3r/GUI/ReleaseNote.cpp @@ -13,6 +13,7 @@ #include "Widgets/StaticBox.hpp" #include "Widgets/WebView.hpp" +#include #include #include #include @@ -420,16 +421,36 @@ void SecondaryCheckDialog::update_text(wxString text) text = format_text(m_staticText_release_note, text, FromDIP(240)); m_staticText_release_note->SetLabelText(text); - m_staticText_release_note->Wrap(FromDIP(240)); + if (is_english_text(text)) m_staticText_release_note->Wrap(FromDIP(240)); sizer_text_release_note->Add(m_staticText_release_note, 0, wxALIGN_CENTER, 5); m_vebview_release_note->SetSizer(sizer_text_release_note); m_vebview_release_note->Layout(); - //Fit(); +} + +bool SecondaryCheckDialog::is_english_text(wxString str) +{ + std::regex reg("^[0-9a-zA-Z]+$"); + std::smatch matchResult; + + std::string pattern_Special = "{}[]<>~!@#$%^&*(),.?/ :"; + for (auto i = 0; i < str.Length(); i++) { + std::string regex_str = wxString(str[i]).ToStdString(); + if(std::regex_match(regex_str, matchResult, reg)){ + continue; + } + else { + int result = pattern_Special.find(regex_str.c_str()); + if (result < 0 || result > pattern_Special.length()) { + return false; + } + } + } + return true; } wxString SecondaryCheckDialog::format_text(wxStaticText* st, wxString str, int warp) { - if (wxGetApp().app_config->get("language") != "zh_CN") { return str; } + if (is_english_text(str)) return str; wxString out_txt = str; wxString count_txt = ""; diff --git a/src/slic3r/GUI/ReleaseNote.hpp b/src/slic3r/GUI/ReleaseNote.hpp index 36466c395b3..dd63e3f69c0 100644 --- a/src/slic3r/GUI/ReleaseNote.hpp +++ b/src/slic3r/GUI/ReleaseNote.hpp @@ -83,6 +83,7 @@ class SecondaryCheckDialog : public DPIDialog public: SecondaryCheckDialog(wxWindow* parent); void update_text(wxString text); + bool is_english_text(wxString str); wxString format_text(wxStaticText* st, wxString str, int warp); ~SecondaryCheckDialog(); void on_dpi_changed(const wxRect& suggested_rect) override; diff --git a/src/slic3r/GUI/SendToPrinter.cpp b/src/slic3r/GUI/SendToPrinter.cpp index 8f619058c3b..9906671ed04 100644 --- a/src/slic3r/GUI/SendToPrinter.cpp +++ b/src/slic3r/GUI/SendToPrinter.cpp @@ -71,7 +71,7 @@ wxString SendToPrinterDialog::format_text(wxString &m_msg) } SendToPrinterDialog::SendToPrinterDialog(Plater *plater) - : DPIDialog(static_cast(wxGetApp().mainframe), wxID_ANY, _L("Send to Printer"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX) + : DPIDialog(static_cast(wxGetApp().mainframe), wxID_ANY, _L("Send to Printer SD card"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX) , m_plater(plater), m_export_3mf_cancel(false) { #ifdef __WINDOWS__ @@ -135,7 +135,7 @@ SendToPrinterDialog::SendToPrinterDialog(Plater *plater) wxBoxSizer *m_sizer_printer = new wxBoxSizer(wxHORIZONTAL); - m_stext_printer_title = new wxStaticText(this, wxID_ANY, L("Printer"), wxDefaultPosition, wxSize(-1, -1), 0); + m_stext_printer_title = new wxStaticText(this, wxID_ANY, _L("Printer"), wxDefaultPosition, wxSize(-1, -1), 0); m_stext_printer_title->SetFont(::Label::Head_14); m_stext_printer_title->Wrap(-1); m_stext_printer_title->SetForegroundColour(m_colour_bold_color); @@ -237,14 +237,17 @@ SendToPrinterDialog::SendToPrinterDialog(Plater *plater) m_scrollable_region->SetSizer(m_sizer_scrollable_region); m_scrollable_region->Layout(); - + //file name + m_file_name = new wxStaticText(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0); m_sizer_main->Add(m_line_top, 0, wxEXPAND, 0); m_sizer_main->Add(0, 0, 0, wxTOP, FromDIP(22)); m_sizer_main->Add(m_scrollable_region, 0, wxALIGN_CENTER_HORIZONTAL, 0); m_sizer_main->Add(0, 0, 0, wxEXPAND | wxTOP, FromDIP(8)); m_sizer_main->Add(0, 0, 0, wxEXPAND | wxTOP, FromDIP(8)); + m_sizer_main->Add(m_file_name, 0, wxALIGN_CENTER_HORIZONTAL, 0); + m_sizer_main->Add(0, 0, 0, wxEXPAND | wxTOP, FromDIP(8)); m_sizer_main->Add(m_line_materia, 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(30)); - m_sizer_main->Add(0, 0, 0, wxEXPAND | wxTOP, FromDIP(14)); + m_sizer_main->Add(0, 0, 0, wxEXPAND | wxTOP, FromDIP(15)); m_sizer_main->Add(m_sizer_printer, 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(30)); m_sizer_main->Add(0, 0, 0, wxEXPAND | wxTOP, FromDIP(5)); m_sizer_main->Add(0, 0, 0, wxEXPAND | wxTOP, FromDIP(8)); @@ -896,6 +899,9 @@ void SendToPrinterDialog::on_dpi_changed(const wxRect &suggested_rect) void SendToPrinterDialog::set_default() { + wxString filename = m_plater->get_export_gcode_filename(".gcode.3mf", true); + m_file_name->SetLabelText(filename); + enable_prepare_mode = true; prepare_mode(); diff --git a/src/slic3r/GUI/SendToPrinter.hpp b/src/slic3r/GUI/SendToPrinter.hpp index 9490d025f2c..ece3ca4326f 100644 --- a/src/slic3r/GUI/SendToPrinter.hpp +++ b/src/slic3r/GUI/SendToPrinter.hpp @@ -92,6 +92,7 @@ protected: wxBoxSizer* sizer_thumbnail; wxBoxSizer* m_sizer_main; wxBoxSizer* m_sizer_bottom; + wxStaticText* m_file_name; bool enable_prepare_mode{true}; bool m_need_adaptation_screen{ false };