ENH:Optimization of File Transfer System Part2

jira: [STUDIO-11777]

Change-Id: I12744db7d2e3b53425454d632533768c54524677
This commit is contained in:
milk 2025-04-27 15:30:43 +08:00 committed by lane.wei
parent aa52c99076
commit 4358e9ce35
10 changed files with 263 additions and 97 deletions

View File

@ -8,6 +8,8 @@ set(SLIC3R_GUI_SOURCES
pchheader.hpp
GUI/Printer/PrinterFileSystem.cpp
GUI/Printer/PrinterFileSystem.h
GUI/Widgets/AnimaController.hpp
GUI/Widgets/AnimaController.cpp
GUI/Widgets/AxisCtrlButton.cpp
GUI/Widgets/AxisCtrlButton.hpp
GUI/Widgets/Button.cpp

View File

@ -1083,7 +1083,7 @@ public:
bool is_support_filament_setting_inprinting{false};
bool is_support_internal_timelapse { false };// fun[28], support timelapse without SD card
bool is_support_command_homing { false };// fun[32]
bool is_support_brtc { false }; // fun[31], support tcp and upload protocol
bool is_support_brtc{false}; // fun[31], support tcp and upload protocol
bool installed_upgrade_kit{false};
int bed_temperature_limit = -1;

View File

@ -37,6 +37,8 @@ enum PrintDialogStatus : unsigned int {
PrintStatusConnectingServer,
PrintStatusReadingTimeout,
PrintStatusReading,
PrintStatusConnecting,
PrintStatusReconnecting,
PrintStatusInUpgrading,
PrintStatusModeNotFDM,
PrintStatusInSystemPrinting,

View File

@ -1541,7 +1541,7 @@ void PrinterFileSystem::Reconnect(boost::unique_lock<boost::mutex> &l, int resul
while (m_stopped) {
if (m_session.owner == nullptr)
return;
m_status = Status::Stopped;
m_status = Status::Reconnecting;
SendChangedEvent(EVT_STATUS_CHANGED, m_status);
m_cond.wait(l);
}

View File

@ -215,7 +215,7 @@ public:
ListSyncing,
ListReady,
Failed,
Stopped,
Reconnecting,
};
Status GetStatus() const { return m_status; }

View File

@ -268,8 +268,8 @@ SendToPrinterDialog::SendToPrinterDialog(Plater *plater)
m_button_refresh->SetMinSize(SELECT_MACHINE_DIALOG_BUTTON_SIZE);
m_button_refresh->SetCornerRadius(FromDIP(10));
m_button_refresh->Bind(wxEVT_BUTTON, &SendToPrinterDialog::on_refresh, this);
m_sizer_printer->Add(m_button_refresh, 0, wxALL | wxLEFT, FromDIP(5));
m_sizer_printer->Add(m_button_refresh, 0, wxALL | wxLEFT, FromDIP(5));
/*select storage*/
m_storage_panel = new wxPanel(this);
@ -278,11 +278,42 @@ SendToPrinterDialog::SendToPrinterDialog(Plater *plater)
m_storage_panel->SetSizer(m_storage_sizer);
m_storage_panel->Layout();
// try to connect
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->SetForegroundColour(*wxBLACK);
m_statictext_printer_msg->Hide();
wxBoxSizer *m_sizer_connecting = new wxBoxSizer(wxHORIZONTAL);
m_connecting_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
m_connecting_printer_msg = new wxStaticText(m_connecting_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER_HORIZONTAL);
m_connecting_printer_msg->SetFont(::Label::Body_13);
m_connecting_printer_msg->SetForegroundColour(*wxBLACK);
m_connecting_printer_msg->SetLabel("Try to connect");
/*m_connecting_printer_msg->Hide();*/
m_connecting_printer_msg->Show();
std::vector<std::string> list{"ams_rfid_1", "ams_rfid_2", "ams_rfid_3", "ams_rfid_4"};
m_animaicon = new AnimaIcon(m_connecting_panel, wxID_ANY, list, "refresh_printer", 100);
m_sizer_connecting->Add(m_connecting_printer_msg, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, FromDIP(5));
m_sizer_connecting->Add(m_animaicon, 0, wxALIGN_CENTER_VERTICAL);
m_connecting_panel->SetSizer(m_sizer_connecting);
m_connecting_panel->Layout();
m_connecting_panel->Fit();
m_connecting_panel->Hide();
m_animaicon->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) {
if (m_file_sys) {
/* static int i = 0;
i++;
OutputDebugStringA(std::to_string(i).c_str());
OutputDebugStringA("\n");*/
m_file_sys->Retry();
}
});
// line schedule
m_line_schedule = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 1));
m_line_schedule->SetBackgroundColour(wxColour(238, 238, 238));
@ -352,7 +383,6 @@ SendToPrinterDialog::SendToPrinterDialog(Plater *plater)
wxBoxSizer* sizer_print_failed_info = new wxBoxSizer(wxVERTICAL);
m_sw_print_failed_info->SetSizer(sizer_print_failed_info);
wxBoxSizer* sizer_error_code = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer* sizer_error_desc = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer* sizer_extra_info = new wxBoxSizer(wxHORIZONTAL);
@ -374,7 +404,6 @@ SendToPrinterDialog::SendToPrinterDialog(Plater *plater)
sizer_error_code->Add(st_title_error_code_doc, 0, wxALL, 0);
sizer_error_code->Add(m_st_txt_error_code, 0, wxALL, 0);
auto st_title_error_desc = new wxStaticText(m_sw_print_failed_info, wxID_ANY, wxT("Error desc"));
auto st_title_error_desc_doc = new wxStaticText(m_sw_print_failed_info, wxID_ANY, ": ");
m_st_txt_error_desc = new Label(m_sw_print_failed_info, wxEmptyString);
@ -409,7 +438,6 @@ SendToPrinterDialog::SendToPrinterDialog(Plater *plater)
sizer_extra_info->Add(st_title_extra_info_doc, 0, wxALL, 0);
sizer_extra_info->Add(m_st_txt_extra_info, 0, wxALL, 0);
m_link_network_state = new wxHyperlinkCtrl(m_sw_print_failed_info, wxID_ANY,_L("Check the status of current system services"),"");
m_link_network_state->SetFont(::Label::Body_12);
m_link_network_state->Bind(wxEVT_LEFT_DOWN, [this](auto& e) {wxGetApp().link_to_network_check(); });
@ -536,6 +564,7 @@ SendToPrinterDialog::SendToPrinterDialog(Plater *plater)
m_sizer_main->Add(m_storage_panel, 0, wxALIGN_CENTER | wxTOP, FromDIP(8));
m_sizer_main->Add(0, 0, 0, wxEXPAND | wxTOP, FromDIP(11));
m_sizer_main->Add(m_statictext_printer_msg, 0, wxALIGN_CENTER_HORIZONTAL, 0);
m_sizer_main->Add(m_connecting_panel, 0, wxALIGN_CENTER_HORIZONTAL, 0);
m_sizer_main->Add(0, 1, 0, wxTOP, FromDIP(22));
m_sizer_main->Add(m_line_schedule, 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(30));
m_sizer_main->Add(m_simplebook, 0, wxALIGN_CENTER_HORIZONTAL, 0);
@ -750,6 +779,9 @@ void SendToPrinterDialog::on_cancel(wxCloseEvent &event)
}
#endif
m_tcp_try_connect = true;
m_tutk_try_connect = false;
m_ftp_try_connect = false;
m_connect_try_times = 0;
this->EndModal(wxID_CANCEL);
}
@ -1017,6 +1049,7 @@ std::vector<std::string> SendToPrinterDialog::sort_string(std::vector<std::strin
return outputArray;
}
bool SendToPrinterDialog::is_timeout()
{
if (timeout_count > 15 * 1000 / LIST_REFRESH_INTERVAL) {
@ -1127,6 +1160,9 @@ void SendToPrinterDialog::on_selection_changed(wxCommandEvent &event)
DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev) return;
m_tcp_try_connect = true;
m_tutk_try_connect = false;
m_ftp_try_connect = false;
m_connect_try_times = 0;
MachineObject* obj = nullptr;
for (int i = 0; i < m_list.size(); i++) {
if (i == selection) {
@ -1236,7 +1272,7 @@ void SendToPrinterDialog::update_show_status()
return;
}
#else
if (!obj_->is_support_brtc) {
if (!obj_->is_support_brtc || m_ftp_try_connect) {
if (m_file_sys) {
m_device_select.clear();
m_file_sys->Stop(true);
@ -1261,7 +1297,7 @@ void SendToPrinterDialog::update_show_status()
m_file_sys = boost::make_shared<PrinterFileSystem>();
m_file_sys->Attached();
m_file_sys->Bind(EVT_STATUS_CHANGED, [this, wfs = boost::weak_ptr(m_file_sys)](auto e) {
m_file_sys->Bind(EVT_STATUS_CHANGED, [this, wfs = boost::weak_ptr(m_file_sys),obj_](auto e) {
e.Skip();
boost::shared_ptr fs(wfs.lock());
if (!fs) return;
@ -1272,7 +1308,8 @@ void SendToPrinterDialog::update_show_status()
switch (status) {
case PrinterFileSystem::Initializing:
case PrinterFileSystem::Connecting: show_status(PrintDialogStatus::PrintStatusReading); break;
case PrinterFileSystem::Connecting: show_status(PrintDialogStatus::PrintStatusConnecting); break;
case PrinterFileSystem::ListSyncing: {
show_status(PrintDialogStatus::PrintStatusReading);
boost::uint32_t seq = fs->RequestMediaAbility(3);
@ -1292,20 +1329,22 @@ void SendToPrinterDialog::update_show_status()
break;
}
case PrinterFileSystem::Failed: {
if (m_connect_try_times < 3) {
bool is_lan = (obj_->connection_type() == "lan");
m_ftp_try_connect = is_lan || m_tutk_try_connect;
m_tutk_try_connect = !is_lan || m_tutk_try_connect;
m_tcp_try_connect = false;
/*static int i = 0;
OutputDebugStringA(std::to_string(i).c_str());
OutputDebugStringA("\n");
if (i++ < 2)*/
/* msg = _L("Attempting TCP connection, please wait.");
else*/
}
else
msg = _L("Please check the network and try again, You can restart or update the printer if the issue persists.");
//fs->Stop();
fs->Stop();
m_connect_try_times++;
break;
}
case PrinterFileSystem::Stopped: {
// fs->Retry();
}
case PrinterFileSystem::Reconnecting: show_status(PrintDialogStatus::PrintStatusReconnecting);
}
if (!msg.empty()) {
@ -1443,6 +1482,37 @@ void SendToPrinterDialog::show_status(PrintDialogStatus status, std::vector<wxSt
else
m_comboBox_printer->Enable();
//connecting
if(status == PrintDialogStatus::PrintStatusConnecting)
{
m_connecting_printer_msg->SetLabel("Try to connect.");
update_print_status_msg(wxEmptyString, true, true);
m_connecting_panel->Show();
m_animaicon->Play();
Layout();
Enable_Send_Button(false);
Enable_Refresh_Button(true);
return;
} else if (status == PrintDialogStatus::PrintStatusReconnecting) {
m_connecting_printer_msg->SetLabel("Click the spinning icon to retry.");
update_print_status_msg(wxEmptyString, true, true);
m_connecting_panel->Show();
m_animaicon->Stop();
m_animaicon->Enable();
Layout();
Enable_Send_Button(false);
Enable_Refresh_Button(true);
return;
}
else {
m_connecting_panel->Hide();
}
// m_panel_warn m_simplebook
if (status == PrintDialogStatus::PrintStatusSending) {
sending_mode();
@ -1694,9 +1764,12 @@ bool SendToPrinterDialog::Show(bool show)
if (show) {
m_refresh_timer->Start(LIST_REFRESH_INTERVAL);
m_tcp_try_connect = true;
m_ftp_try_connect = false;
m_tutk_try_connect = false;
m_connect_try_times = 0;
} else {
m_refresh_timer->Stop();
m_tcp_try_connect = true;
}
Layout();
@ -1750,14 +1823,11 @@ void SendToPrinterDialog::fetchUrl(boost::weak_ptr<PrinterFileSystem> wfs)
NetworkAgent *agent = wxGetApp().getAgent();
std::string agent_version = agent ? agent->get_version() : "";
if (agent) {
if (obj->connection_type() == "lan") {
// In LAN mode, use TCP connection
if (m_tcp_try_connect) {
std::string devIP = obj->dev_ip;
std::string accessCode = obj->get_access_code();
std::string tcp_url = "bambu:///local/" + devIP + "?port=6000&user=" + "bblp" + "&passwd=" + accessCode;
CallAfter([=] {
boost::shared_ptr fs(wfs.lock());
if (!fs) return;
@ -1767,27 +1837,10 @@ void SendToPrinterDialog::fetchUrl(boost::weak_ptr<PrinterFileSystem> wfs)
fs->SetUrl("3");
}
});
} else {
// In non-LAN mode, try TCP connection first
if (m_tcp_try_connect) {
std::string devIP = obj->dev_ip;
std::string accessCode = obj->get_access_code();
std::string tcp_url = "bambu:///local/" + devIP + "?port=6000&user=" + "bblp" + "&passwd=" + accessCode;
CallAfter([=] {
boost::shared_ptr fs(wfs.lock());
if (!fs) return;
if (boost::algorithm::starts_with(tcp_url, "bambu:///")) {
fs->SetUrl(tcp_url);
}
});
}
else {
// If the TCP connection fails, switch to TUTK connection
else if (m_tutk_try_connect){
std::string protocols[] = {"", "\"tutk\"", "\"agora\"", "\"tutk\",\"agora\""};
agent->get_camera_url(obj->dev_id + "|" + dev_ver + "|" + protocols[1], // ʹÓà "tutk"
[this, wfs, m = dev_id, v = agent->get_version(), dv = dev_ver](std::string url) {
agent->get_camera_url(obj->dev_id + "|" + dev_ver + "|" + protocols[1], [this, wfs, m = dev_id, v = agent->get_version(), dv = dev_ver](std::string url) {
if (boost::algorithm::starts_with(url, "bambu:///")) {
url += "&device=" + m;
url += "&net_ver=" + v;
@ -1808,11 +1861,7 @@ void SendToPrinterDialog::fetchUrl(boost::weak_ptr<PrinterFileSystem> wfs)
}
});
});
}
}
}

View File

@ -39,6 +39,7 @@
#include <wx/simplebook.h>
#include <wx/hashmap.h>
#include "Printer/PrinterFileSystem.h"
#include "Widgets/AnimaController.hpp"
namespace Slic3r {
namespace GUI {
@ -54,6 +55,7 @@ private:
int m_current_filament_id;
int m_print_error_code = 0;
int timeout_count = 0;
int m_connect_try_times = 0;
bool m_is_in_sending_mode{ false };
bool m_is_rename_mode{ false };
bool enable_prepare_mode{ true };
@ -61,6 +63,8 @@ private:
bool m_export_3mf_cancel{ false };
bool m_is_canceled{ false };
bool m_tcp_try_connect{true};
bool m_tutk_try_connect{false};
bool m_ftp_try_connect{false};
std::string m_print_error_msg;
std::string m_print_error_extra;
std::string m_print_info;
@ -89,11 +93,13 @@ private:
wxPanel* m_line_materia{ nullptr };
wxBoxSizer* m_storage_sizer{ nullptr };
wxPanel* m_storage_panel{ nullptr };
wxPanel * m_connecting_panel{nullptr};
wxSimplebook* m_simplebook{ nullptr };
wxStaticText* m_statictext_finish{ nullptr };
wxStaticText* m_stext_sending{ nullptr };
wxStaticText* m_staticText_bed_title{ nullptr };
wxStaticText* m_statictext_printer_msg{ nullptr };
wxStaticText * m_connecting_printer_msg{nullptr};
wxStaticText* m_stext_printer_title{ nullptr };
wxStaticText* m_rename_text{ nullptr };
wxStaticText* m_stext_time{ nullptr };
@ -108,8 +114,10 @@ private:
wxBoxSizer* sizer_thumbnail;
wxBoxSizer* m_sizer_scrollable_region;
wxBoxSizer* m_sizer_main;
wxStaticText* m_file_name;
PrintDialogStatus m_print_status{ PrintStatusInit };
AnimaIcon * m_animaicon{nullptr};
std::shared_ptr<SendJob> m_send_job{nullptr};
std::vector<wxString> m_bedtype_list;

View File

@ -0,0 +1,77 @@
#include "AnimaController.hpp"
#include <wx/dcclient.h>
#include <wx/dcgraph.h>
#ifdef __APPLE__
#include "libslic3r/MacUtils.hpp"
#endif
AnimaIcon::AnimaIcon(wxWindow *parent, wxWindowID id, std::vector<std::string> img_list, std::string img_enable, int ivt)
: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize), m_ivt(ivt)
{
SetBackgroundColour((wxColour(255, 255, 255)));
m_size = 20;
//add ScalableBitmap
for (const auto &filename : img_list) m_images.emplace_back(create_scaled_bitmap(filename, this, m_size));
m_image_enable = create_scaled_bitmap(img_enable, this, m_size-8);
// show first wxStaticBitmap
if (!m_images.empty()) m_bitmap = new wxStaticBitmap(this, wxID_ANY, m_images[0], wxDefaultPosition, wxSize(FromDIP(m_size), FromDIP(m_size)));
m_timer = new wxTimer();
m_timer->SetOwner(this);
Bind(wxEVT_TIMER, [this](wxTimerEvent &) {
if (m_timer->IsRunning() && !m_images.empty()) {
m_current_frame = (m_current_frame + 1) % 4;
m_bitmap->SetBitmap(m_images[m_current_frame]);
}
});
m_bitmap->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) {
wxMouseEvent evt(wxEVT_LEFT_DOWN);
evt.SetEventObject(this);
wxPostEvent(this, evt);
});
m_bitmap->Bind(wxEVT_ENTER_WINDOW, [this](auto &e) {
if (!m_timer->IsRunning())
SetCursor(wxCursor(wxCURSOR_HAND));
else
SetCursor(wxCursor(wxCURSOR_ARROW));
e.Skip();
});
m_bitmap->Bind(wxEVT_LEAVE_WINDOW, [this](auto &e) {
SetCursor(wxCursor(wxCURSOR_ARROW));
e.Skip();
});
SetSize(wxSize(FromDIP(m_size), FromDIP(m_size)));
SetMaxSize(wxSize(FromDIP(m_size), FromDIP(m_size)));
SetMinSize(wxSize(FromDIP(m_size), FromDIP(m_size)));
Refresh();
Play();
}
void AnimaIcon::Play()
{
if (true)
m_timer->Start(m_ivt);
}
void AnimaIcon::Stop()
{
m_timer->Stop();
}
void AnimaIcon::Enable()
{
if (m_bitmap) { m_bitmap->SetBitmap(m_image_enable); }
}

View File

@ -0,0 +1,28 @@
#ifndef slic3r_GUI_AnimaController_hpp_
#define slic3r_GUI_AnimaController_hpp_
#include "../wxExtensions.hpp"
#include "Label.hpp"
class AnimaIcon : public wxPanel
{
public:
AnimaIcon(wxWindow *parent, wxWindowID id, std::vector<std::string> img_list, std::string img_enable, int ivt = 1000);
void Play();
void Stop();
void Enable();
bool IsRunning() const;
private:
wxBitmap m_image_enable;
wxStaticBitmap * m_bitmap{nullptr};
std::vector<wxBitmap> m_images;
wxTimer * m_timer;
int m_current_frame = 0;
int m_ivt;
int m_size;
};
#endif // !slic3r_GUI_AnimaController_hpp_