From 5a78f7ade139ee68dd1be319a843ce3a0d1dcd50 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 files 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: Ib82f952486d18ff481ac377aa607b5455b31564b --- src/slic3r/GUI/BBLStatusBarSend.cpp | 59 +++++++++++++++++++++++++++-- src/slic3r/GUI/BBLStatusBarSend.hpp | 4 +- src/slic3r/GUI/Jobs/SendJob.cpp | 2 +- src/slic3r/GUI/MainFrame.cpp | 22 +++++------ src/slic3r/GUI/ReleaseNote.cpp | 1 + src/slic3r/GUI/SendToPrinter.cpp | 4 +- src/slic3r/GUI/SendToPrinter.hpp | 1 + 7 files changed, 74 insertions(+), 19 deletions(-) diff --git a/src/slic3r/GUI/BBLStatusBarSend.cpp b/src/slic3r/GUI/BBLStatusBarSend.cpp index 2b99d274c..480addb60 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); @@ -170,15 +174,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) @@ -208,6 +258,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 e938308fc..d1e24aa08 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 dcb1feee0..27369b7b0 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"); diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index a35bce25f..bad3032bc 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -1411,7 +1411,7 @@ wxBoxSizer* MainFrame::create_side_tools() }); // upload only - /*SideButton* upload_gcode_btn = new SideButton(p, _L("Send"), ""); + SideButton* upload_gcode_btn = new SideButton(p, _L("Send"), ""); upload_gcode_btn->SetCornerRadius(0); upload_gcode_btn->Bind(wxEVT_BUTTON, [this, p](wxCommandEvent&) { m_print_btn->SetLabel(_L("Send")); @@ -1420,10 +1420,10 @@ wxBoxSizer* MainFrame::create_side_tools() m_print_btn->Enable(m_print_enable); this->Layout(); p->Dismiss(); - });*/ + }); p->append_button(send_gcode_btn); - //p->append_button(upload_gcode_btn); + p->append_button(upload_gcode_btn); p->append_button(export_gcode_btn); } else { @@ -1431,8 +1431,8 @@ wxBoxSizer* MainFrame::create_side_tools() SideButton* print_plate_btn = new SideButton(p, _L("Print plate"), ""); print_plate_btn->SetCornerRadius(0); - /*SideButton* send_to_printer_btn = new SideButton(p, _L("Send"), ""); - send_to_printer_btn->SetCornerRadius(0);*/ + SideButton* send_to_printer_btn = new SideButton(p, _L("Send"), ""); + send_to_printer_btn->SetCornerRadius(0); SideButton* export_sliced_file_btn = new SideButton(p, _L("Export plate sliced file"), ""); export_sliced_file_btn->SetCornerRadius(0); @@ -1460,16 +1460,16 @@ wxBoxSizer* MainFrame::create_side_tools() p->Dismiss(); }); - /*send_to_printer_btn->Bind(wxEVT_BUTTON, [this, p](wxCommandEvent&) { + send_to_printer_btn->Bind(wxEVT_BUTTON, [this, p](wxCommandEvent&) { m_print_btn->SetLabel(_L("Send")); m_print_select = eSendToPrinter; m_print_enable = get_enable_print_status(); m_print_btn->Enable(m_print_enable); this->Layout(); p->Dismiss(); - });*/ + }); - /*SideButton* send_to_printer_all_btn = new SideButton(p, _L("Send all"), ""); + SideButton* send_to_printer_all_btn = new SideButton(p, _L("Send all"), ""); send_to_printer_all_btn->SetCornerRadius(0); send_to_printer_all_btn->Bind(wxEVT_BUTTON, [this, p](wxCommandEvent&) { m_print_btn->SetLabel(_L("Send all")); @@ -1478,7 +1478,7 @@ wxBoxSizer* MainFrame::create_side_tools() m_print_btn->Enable(m_print_enable); this->Layout(); p->Dismiss(); - });*/ + }); export_sliced_file_btn->Bind(wxEVT_BUTTON, [this, p](wxCommandEvent&) { m_print_btn->SetLabel(_L("Export plate sliced file")); @@ -1500,8 +1500,8 @@ wxBoxSizer* MainFrame::create_side_tools() p->append_button(print_plate_btn); p->append_button(print_all_btn); - //p->append_button(send_to_printer_btn); - //p->append_button(send_to_printer_all_btn); + p->append_button(send_to_printer_btn); + p->append_button(send_to_printer_all_btn); p->append_button(export_sliced_file_btn); p->append_button(export_all_sliced_file_btn); } diff --git a/src/slic3r/GUI/ReleaseNote.cpp b/src/slic3r/GUI/ReleaseNote.cpp index 36e131d5c..f0eb3230a 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 diff --git a/src/slic3r/GUI/SendToPrinter.cpp b/src/slic3r/GUI/SendToPrinter.cpp index 6507e9461..831580df7 100644 --- a/src/slic3r/GUI/SendToPrinter.cpp +++ b/src/slic3r/GUI/SendToPrinter.cpp @@ -157,7 +157,7 @@ void SendToPrinterDialog::on_rename_enter() } 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__ @@ -221,7 +221,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); diff --git a/src/slic3r/GUI/SendToPrinter.hpp b/src/slic3r/GUI/SendToPrinter.hpp index 4be2898ce..ced9ce2a4 100644 --- a/src/slic3r/GUI/SendToPrinter.hpp +++ b/src/slic3r/GUI/SendToPrinter.hpp @@ -100,6 +100,7 @@ protected: wxBoxSizer* sizer_thumbnail; wxBoxSizer* m_sizer_main; wxBoxSizer* m_sizer_bottom; + wxStaticText* m_file_name; bool m_is_rename_mode{false}; bool enable_prepare_mode{true};