From ac406d14ce0cdbccb3e4e4fab84d93dff392ade2 Mon Sep 17 00:00:00 2001 From: "chunmao.guo" Date: Wed, 10 Jan 2024 09:03:34 +0800 Subject: [PATCH] ENH: adjust connect error string Change-Id: I2ec6743fb6a332af8742a229b672737342abb779 Jira: STUDIO-5935 --- src/slic3r/GUI/ImageGrid.cpp | 2 +- src/slic3r/GUI/MediaFilePanel.cpp | 23 +++--- src/slic3r/GUI/MediaPlayCtrl.cpp | 73 +++++++++++++------- src/slic3r/GUI/Printer/PrinterFileSystem.cpp | 12 ++-- 4 files changed, 69 insertions(+), 41 deletions(-) diff --git a/src/slic3r/GUI/ImageGrid.cpp b/src/slic3r/GUI/ImageGrid.cpp index 3f4d515d9..b6755c3e3 100644 --- a/src/slic3r/GUI/ImageGrid.cpp +++ b/src/slic3r/GUI/ImageGrid.cpp @@ -513,7 +513,7 @@ void ImageGrid::render(wxDC& dc) dc.DrawRectangle({ 0, 0, size.x, size.y }); if (!m_status_msg.IsEmpty()) { auto si = m_status_icon.GetBmpSize(); - auto st = dc.GetTextExtent(m_status_msg); + auto st = dc.GetMultiLineTextExtent(m_status_msg); auto rect = wxRect{0, 0, max(st.x, si.x), si.y + 26 + st.y}.CenterIn(wxRect({0, 0}, size)); dc.DrawBitmap(m_status_icon.bmp(), rect.x + (rect.width - si.x) / 2, rect.y); dc.SetTextForeground(wxColor(0x909090)); diff --git a/src/slic3r/GUI/MediaFilePanel.cpp b/src/slic3r/GUI/MediaFilePanel.cpp index 6274a650c..c8f5d75aa 100644 --- a/src/slic3r/GUI/MediaFilePanel.cpp +++ b/src/slic3r/GUI/MediaFilePanel.cpp @@ -242,7 +242,7 @@ void MediaFilePanel::SetMachineObject(MachineObject* obj) m_button_management->Enable(false); SetSelecting(false); if (m_machine.empty()) { - m_image_grid->SetStatus(m_bmp_failed, _L("No printers.")); + m_image_grid->SetStatus(m_bmp_failed, _L("Please confirm if the printer is connected.")); } else { boost::shared_ptr fs(new PrinterFileSystem); fs->Attached(); @@ -282,17 +282,20 @@ void MediaFilePanel::SetMachineObject(MachineObject* obj) switch (status) { case PrinterFileSystem::Initializing: icon = m_bmp_loading; msg = _L("Initializing..."); break; case PrinterFileSystem::Connecting: icon = m_bmp_loading; msg = _L("Connecting..."); break; - case PrinterFileSystem::Failed: icon = m_bmp_failed; if (extra != 1) msg = _L("Connect failed [%d]!"); break; + case PrinterFileSystem::Failed: icon = m_bmp_failed; if (extra != 1) msg = _L("Please check the network and try again, You can restart or update the printer if the issue persists."); break; case PrinterFileSystem::ListSyncing: icon = m_bmp_loading; msg = _L("Loading file list..."); break; case PrinterFileSystem::ListReady: icon = extra == 0 ? m_bmp_empty : m_bmp_failed; msg = extra == 0 ? _L("No files [%d]") : _L("Load failed [%d]"); break; } - if (!e.GetString().IsEmpty()) msg = e.GetString(); + int err = fs->GetLastError(); + if (!e.GetString().IsEmpty()) + msg = e.GetString(); + if (err != 0) + msg += wxString::Format(" [%d]", err); if (fs->GetCount() == 0 && !msg.empty()) m_image_grid->SetStatus(icon, msg); if (e.GetInt() == PrinterFileSystem::Initializing) fetchUrl(boost::weak_ptr(fs)); - int err = fs->GetLastError(); if ((status == PrinterFileSystem::Failed && m_last_errors.find(err) == m_last_errors.end()) || status == PrinterFileSystem::ListReady) { json j; @@ -426,19 +429,19 @@ void MediaFilePanel::fetchUrl(boost::weak_ptr wfs) if (!fs || fs != m_image_grid->GetFileSystem()) return; if (!IsEnabled()) { m_waiting_enable = true; - m_image_grid->SetStatus(m_bmp_failed, _L("Initialize failed (Device connection not ready)!")); + m_image_grid->SetStatus(m_bmp_failed, _L("Please confirm if the printer is connected.")); fs->SetUrl("0"); return; } m_waiting_enable = false; if (!m_local_support && !m_remote_support) { m_waiting_support = true; - m_image_grid->SetStatus(m_bmp_failed, _L("Initialize failed (Not supported on the current printer version)!")); + m_image_grid->SetStatus(m_bmp_failed, _L("Please update the printer firmware and try again.")); fs->SetUrl("0"); return; } if (!m_sdcard_exist) { - m_image_grid->SetStatus(m_bmp_failed, _L("Initialize failed (Storage unavailable, insert SD card.)!")); + m_image_grid->SetStatus(m_bmp_failed, _L("Please check if the SD card is inserted into the printer.\nIf it still cannot be read, you can try formatting the SD card.")); fs->SetUrl("0"); return; } @@ -450,12 +453,12 @@ void MediaFilePanel::fetchUrl(boost::weak_ptr wfs) return; } if (m_lan_mode) { - m_image_grid->SetStatus(m_bmp_failed, _L("Initialize failed (Not accessible in LAN-only mode)!")); + m_image_grid->SetStatus(m_bmp_failed, _L("Problem occured. Please update the printer firmware and try again.")); fs->SetUrl("0"); return; } if (!m_remote_support && m_local_support) { // not support tutk - m_image_grid->SetStatus(m_bmp_failed, _L("Initialize failed (Missing LAN ip of printer)!")); + m_image_grid->SetStatus(m_bmp_failed, _L("Please enter the IP of printer to connect.")); fs->SetUrl("1"); return; } @@ -470,7 +473,7 @@ void MediaFilePanel::fetchUrl(boost::weak_ptr wfs) if (boost::algorithm::starts_with(url, "bambu:///")) { fs->SetUrl(url + "&device=" + m + "&dev_ver=" + v); } else { - m_image_grid->SetStatus(m_bmp_failed, wxString::Format(_L("Initialize failed (%s)!"), url.empty() ? _L("Network unreachable") : from_u8(url))); + m_image_grid->SetStatus(m_bmp_failed, _L("Connection Failed. Please check the network and try again")); fs->SetUrl("3"); } }); diff --git a/src/slic3r/GUI/MediaPlayCtrl.cpp b/src/slic3r/GUI/MediaPlayCtrl.cpp index da0b16bda..60a1ce223 100644 --- a/src/slic3r/GUI/MediaPlayCtrl.cpp +++ b/src/slic3r/GUI/MediaPlayCtrl.cpp @@ -25,6 +25,15 @@ #include #include "wx/evtloop.h" +static std::map error_messages = { + {1, L("The device cannot handle more conversations. Please retry later.")}, + {2, L("Player is malfunctioning. Please reinstall the system player.")}, + {100, L("The player is not loaded, please click \"play\" button to retry.")}, + {101, L("The player is not loaded, please click \"play\" button to retry.")}, + {102, L("The player is not loaded, please click \"play\" button to retry.")}, + {103, L("The player is not loaded, please click \"play\" button to retry.")} +}; + namespace Slic3r { namespace GUI { @@ -140,7 +149,7 @@ void MediaPlayCtrl::SetMachineObject(MachineObject* obj) m_lan_passwd.clear(); m_dev_ver.clear(); m_tutk_state.clear(); - m_remote_support = true; + m_remote_support = false; m_device_busy = false; } Enable(obj && obj->is_connected() && obj->m_push_count > 0); @@ -204,24 +213,23 @@ void MediaPlayCtrl::Play() } m_failed_code = 0; if (m_machine.empty()) { - Stop(_L("Initialize failed (No Device)!")); + Stop(_L("Please confirm if the printer is connected.")); return; } if (!IsEnabled()) { - Stop(_L("Initialize failed (Device connection not ready)!")); + Stop(_L("Please confirm if the printer is connected.")); return; } if (!m_camera_exists) { - Stop(_L("Initialize failed (No Camera Device)!")); + Stop(_L("Printer camera is malfunctioning.")); return; } if (m_device_busy) { - Stop(_L("Printer is busy downloading, Please wait for the downloading to finish.")); + Stop(_L("The printer is currently busy downloading. Please try again after it finishes.")); m_failed_retry = 0; return; } - m_last_state = MEDIASTATE_INITIALIZING; m_button_play->SetIcon("media_stop"); NetworkAgent *agent = wxGetApp().getAgent(); std::string agent_version = agent ? agent->get_version() : ""; @@ -241,25 +249,27 @@ void MediaPlayCtrl::Play() return; } - m_disable_lan = false; - if (m_lan_ip.empty()) - m_failed_code = -1; + // m_lan_mode && m_lan_proto == LVL_None (x) + // !m_lan_mode && m_remote_support + // !m_lan_mode && !m_remote_support && m_lan_proto > LVL_None (use local tunnel) + // !m_lan_mode && !m_remote_support && m_lan_proto == LVL_None (x) - if (m_lan_mode) { - Stop(m_lan_proto < 0 - ? _L("Initialize failed (Not supported on the current printer version)!") - : _L("Initialize failed (Not accessible in LAN-only mode)!")); + if (m_lan_proto == MachineObject::LVL_None && !m_remote_support) { + Stop(_L("Please update the printer firmware and try again.")); return; } + + m_disable_lan = false; + m_failed_code = 0; + m_last_state = MEDIASTATE_INITIALIZING; if (!m_remote_support) { // not support tutk - Stop(m_lan_ip.empty() - ? _L("Initialize failed (Missing LAN ip of printer)!") - : _L("Initialize failed (Not supported on the current printer version)!")); + m_failed_code = -1; + m_url = "bambu:///local/"; + Stop(_L("Please enter the IP of printer to connect.")); return; } - m_failed_code = 0; SetStatus(_L("Initializing...")); if (agent) { @@ -279,7 +289,7 @@ void MediaPlayCtrl::Play() if (m_last_state == MEDIASTATE_INITIALIZING) { if (url.empty() || !boost::algorithm::starts_with(url, "bambu:///")) { m_failed_code = 3; - Stop(wxString::Format(_L("Initialize failed (%s)!"), url.empty() ? _L("Network unreachable") : from_u8(url))); + Stop(_L("Connection Failed. Please check the network and try again")); } else { load(); } @@ -301,13 +311,21 @@ void MediaPlayCtrl::Stop(wxString const &msg) boost::unique_lock lock(m_mutex); m_tasks.push_back(""); m_cond.notify_all(); - m_last_state = MEDIASTATE_IDLE; if (!msg.IsEmpty()) - SetStatus(msg, false); - else if (m_failed_code) - SetStatus(_L("Stopped [%d]!"), true); - else + SetStatus(msg); + else if (m_failed_code) { + auto iter = error_messages.find(m_failed_code); + auto msg2 = iter == error_messages.end() + ? _L("Please check the network and try again, You can restart or update the printer if the issue persists.") + : _L(iter->second.c_str()); + if (m_failed_code == 1) { + if (m_last_state == wxMEDIASTATE_PLAYING) + msg2 = _L("The printer has been logged out and cannot connect."); + } + SetStatus(msg2); + } else SetStatus(_L("Stopped."), false); + m_last_state = MEDIASTATE_IDLE; if (!m_auto_retry || m_failed_code >= 100 || m_failed_code == 1) // not keep retry on local error or EOS m_next_retry = wxDateTime(); } else if (!msg.IsEmpty()) { @@ -530,7 +548,7 @@ void MediaPlayCtrl::onStateChanged(wxMediaEvent &event) } else if (event.GetId()) { if (m_failed_code == 0) m_failed_code = 2; - Stop(_L("Load failed [%d]!")); + Stop(); } } else { m_last_state = state; @@ -539,7 +557,12 @@ void MediaPlayCtrl::onStateChanged(wxMediaEvent &event) void MediaPlayCtrl::SetStatus(wxString const &msg2, bool hyperlink) { - auto msg = wxString::Format(msg2, m_failed_code); + auto msg = msg2; + if (m_failed_code != 0) { + int state2 = m_last_state >= MEDIASTATE_IDLE ? m_last_state - MEDIASTATE_IDLE : + m_last_state + MEDIASTATE_BUFFERING - MEDIASTATE_IDLE; + msg += wxString::Format(" [%d:%d]", state2, m_failed_code); + } BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl::SetStatus: " << msg.ToUTF8().data(); #ifdef __WXMSW__ OutputDebugStringA("MediaPlayCtrl::SetStatus: "); diff --git a/src/slic3r/GUI/Printer/PrinterFileSystem.cpp b/src/slic3r/GUI/Printer/PrinterFileSystem.cpp index d07268767..230eef70a 100644 --- a/src/slic3r/GUI/Printer/PrinterFileSystem.cpp +++ b/src/slic3r/GUI/Printer/PrinterFileSystem.cpp @@ -45,12 +45,12 @@ wxDEFINE_EVENT(EVT_FILE_CALLBACK, wxCommandEvent); static wxBitmap default_thumbnail; static std::map error_messages = { - {PrinterFileSystem::ERROR_PIPE, L("Connection lost. Please retry.")}, - {PrinterFileSystem::ERROR_RES_BUSY, L("The device cannot handle more conversations. Please retry later.")}, + {PrinterFileSystem::ERROR_PIPE, L("The printer has been logged out and cannot connect.")}, + {PrinterFileSystem::ERROR_RES_BUSY, L("Over 4 studio/handy are using remote access, you can close some and try again.")}, {PrinterFileSystem::FILE_NO_EXIST, L("File does not exist.")}, {PrinterFileSystem::FILE_CHECK_ERR, L("File checksum error. Please retry.")}, {PrinterFileSystem::FILE_TYPE_ERR, L("Not supported on the current printer version.")}, - {PrinterFileSystem::STORAGE_UNAVAILABLE, L("Storage unavailable, insert SD card.")} + {PrinterFileSystem::STORAGE_UNAVAILABLE, L("Please check if the SD card is inserted into the printer.\nIf it still cannot be read, you can try formatting the SD card.")} }; struct StaticBambuLib : BambuLib { @@ -1134,8 +1134,7 @@ void PrinterFileSystem::RecvMessageThread() if (n == 0) { HandleResponse(l, sample); } else if (n == Bambu_stream_end) { - if (m_status == ListSyncing) - m_stopped = true; + m_stopped = true; Reconnect(l, m_status == ListSyncing ? ERROR_RES_BUSY : ERROR_PIPE); } else if (n == Bambu_would_block) { m_cond.timed_wait(l, boost::posix_time::milliseconds(m_messages.empty() && m_callbacks.empty() ? 1000 : 20)); @@ -1275,6 +1274,9 @@ void PrinterFileSystem::Reconnect(boost::unique_lock &l, int resul m_session.tunnel = tunnel; wxLogMessage("PrinterFileSystem::Reconnect Connected"); break; + } else if (ret == 1) { + m_stopped = true; + ret = ERROR_RES_BUSY; } if (tunnel) { Bambu_Close(tunnel);