From 68741d019c3935777e07d902b664b6f6da5d59fd Mon Sep 17 00:00:00 2001 From: "xin.zhang" Date: Thu, 20 Mar 2025 15:10:29 +0800 Subject: [PATCH] FIX: move network hold to MainFrame jira: [STUDIO-10994] Change-Id: I2c30ba3b0f17d52079332634a9a2dd138859e083 (cherry picked from commit 506e82cb02a79d97a30effde53fe85c7d278858c) --- src/slic3r/GUI/CalibrationPanel.cpp | 22 +------- .../GUI/CalibrationWizardPresetPage.cpp | 2 - src/slic3r/GUI/DeviceManager.cpp | 50 +++++++++++++++++++ src/slic3r/GUI/DeviceManager.hpp | 32 +++++++++++- src/slic3r/GUI/MainFrame.cpp | 7 +++ src/slic3r/GUI/Monitor.cpp | 32 +----------- src/slic3r/GUI/SelectMachine.cpp | 4 +- src/slic3r/GUI/SendToPrinter.cpp | 3 -- src/slic3r/GUI/SyncAmsInfoDialog.cpp | 5 -- 9 files changed, 93 insertions(+), 64 deletions(-) diff --git a/src/slic3r/GUI/CalibrationPanel.cpp b/src/slic3r/GUI/CalibrationPanel.cpp index cabcde674c..0e61c0c67e 100644 --- a/src/slic3r/GUI/CalibrationPanel.cpp +++ b/src/slic3r/GUI/CalibrationPanel.cpp @@ -309,7 +309,6 @@ bool SelectMObjectPopup::Show(bool show) { void SelectMObjectPopup::on_timer(wxTimerEvent& event) { BOOST_LOG_TRIVIAL(trace) << "SelectMObjectPopup on_timer"; - wxGetApp().reset_to_active(); wxCommandEvent user_event(EVT_UPDATE_USER_MLIST); user_event.SetEventObject(this); wxPostEvent(this, user_event); @@ -563,25 +562,8 @@ void CalibrationPanel::update_all() { } } - if (wxGetApp().is_user_login()) { - dev->check_pushing(); - try { - m_agent->refresh_connection(); - } - catch (...) { - ; - } - } - - if (obj) { - m_agent->install_device_cert(obj->dev_id, obj->is_lan_mode_printer()); - } - - if (obj) { - wxGetApp().reset_to_active(); - if (obj->connection_type() != last_conn_type) { - last_conn_type = obj->connection_type(); - } + if (obj && obj->connection_type() != last_conn_type) { + last_conn_type = obj->connection_type(); } m_side_tools->update_status(obj); diff --git a/src/slic3r/GUI/CalibrationWizardPresetPage.cpp b/src/slic3r/GUI/CalibrationWizardPresetPage.cpp index 9b1fa4b292..cf433d130c 100644 --- a/src/slic3r/GUI/CalibrationWizardPresetPage.cpp +++ b/src/slic3r/GUI/CalibrationWizardPresetPage.cpp @@ -1716,7 +1716,6 @@ void CalibrationPresetPage::update_show_status() DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager(); if (!agent) {return;} if (!dev) return; - dev->check_pushing(); MachineObject* obj_ = dev->get_selected_machine(); if (!obj_) { @@ -1731,7 +1730,6 @@ void CalibrationPresetPage::update_show_status() if (!obj_->is_lan_mode_printer()) { if (!agent->is_server_connected()) { - agent->refresh_connection(); show_status(CaliPresetPageStatus::CaliPresetStatusConnectingServer); return; } diff --git a/src/slic3r/GUI/DeviceManager.cpp b/src/slic3r/GUI/DeviceManager.cpp index 0e8d83a860..bd3e824637 100644 --- a/src/slic3r/GUI/DeviceManager.cpp +++ b/src/slic3r/GUI/DeviceManager.cpp @@ -6642,6 +6642,7 @@ std::vector nozzle_type_list{ "hardened_steel", "stainless_steel" } DeviceManager::DeviceManager(NetworkAgent* agent) { m_agent = agent; + m_refresher = new DeviceManagerRefresher(this); // Load saved local machines if (agent) { @@ -6689,6 +6690,8 @@ void DeviceManager::update_local_machine(const MachineObject& m) DeviceManager::~DeviceManager() { + delete m_refresher; + for (auto it = localMachineList.begin(); it != localMachineList.end(); it++) { if (it->second) { delete it->second; @@ -6750,6 +6753,8 @@ void DeviceManager::set_agent(NetworkAgent* agent) m_agent = agent; } +void DeviceManager::start_refresher() { m_refresher->Start(); } +void DeviceManager::stop_refresher() { m_refresher->Stop(); } void DeviceManager::keep_alive() { MachineObject* obj = this->get_selected_machine(); @@ -7756,6 +7761,51 @@ std::string DeviceManager::load_gcode(std::string type_str, std::string gcode_fi return ""; } +DeviceManagerRefresher::DeviceManagerRefresher(DeviceManager *manger) : wxObject() { + m_manager = manger; + m_timer = new wxTimer(); + m_timer->Bind(wxEVT_TIMER, &DeviceManagerRefresher::on_timer, this); +} + +DeviceManagerRefresher::~DeviceManagerRefresher() { + m_timer->Stop(); + delete m_timer; +} + +void DeviceManagerRefresher::on_timer(wxTimerEvent &event) { + if (!m_manager) { return;} + + NetworkAgent *agent = m_manager->get_agent(); + if (!agent) { return; } + + // reset to active + Slic3r::GUI::wxGetApp().reset_to_active(); + + MachineObject *obj = m_manager->get_selected_machine(); + if (!obj) { return; } + + // check valid machine + if (obj && m_manager->get_my_machine(obj->dev_id) == nullptr) { + m_manager->set_selected_machine(""); + agent->set_user_selected_machine(""); + return; + } + + // do some refresh + if (Slic3r::GUI::wxGetApp().is_user_login()) + { + m_manager->check_pushing(); + try { + agent->refresh_connection(); + } catch (...) { + ; + } + } + + // certificate + agent->install_device_cert(obj->dev_id, obj->is_lan_mode_printer()); +} + void change_the_opacity(wxColour& colour) { if (colour.Alpha() == 255) { diff --git a/src/slic3r/GUI/DeviceManager.hpp b/src/slic3r/GUI/DeviceManager.hpp index 9106fe9eee..c2345e1a75 100644 --- a/src/slic3r/GUI/DeviceManager.hpp +++ b/src/slic3r/GUI/DeviceManager.hpp @@ -17,6 +17,9 @@ #include "CameraPopup.hpp" #include "libslic3r/calib.hpp" #include "libslic3r/Utils.hpp" + +#include + #define USE_LOCAL_SOCKET_BIND 0 #define DISCONNECT_TIMEOUT 30000.f // milliseconds @@ -1356,15 +1359,19 @@ private: time_t xcam__save_remote_print_file_to_storage_start_time = 0; }; +class DeviceManagerRefresher; class DeviceManager { private: - NetworkAgent* m_agent { nullptr }; + NetworkAgent* m_agent { nullptr }; + DeviceManagerRefresher* m_refresher{nullptr}; + public: static bool EnableMultiMachine; DeviceManager(NetworkAgent* agent = nullptr); ~DeviceManager(); + NetworkAgent *get_agent() const{ return m_agent; } void set_agent(NetworkAgent* agent); std::mutex listMutex; @@ -1373,6 +1380,9 @@ public: std::map localMachineList; /* dev_id -> MachineObject*, localMachine SSDP */ std::map userMachineList; /* dev_id -> MachineObject* cloudMachine of User */ + void start_refresher(); + void stop_refresher(); + void keep_alive(); void check_pushing(); @@ -1468,6 +1478,26 @@ public: static void update_local_machine(const MachineObject& m); }; +class DeviceManagerRefresher : public wxObject +{ + wxTimer *m_timer{nullptr}; + int m_timer_interval_msec = 1000; + + DeviceManager *m_manager{nullptr}; + +public: + DeviceManagerRefresher(DeviceManager* manger); + ~DeviceManagerRefresher(); + +public: + void Start() { m_timer->Start(m_timer_interval_msec); } + void Stop() { m_timer->Stop(); } + +protected: + virtual void on_timer(wxTimerEvent &event); +}; + + // change the opacity void change_the_opacity(wxColour& colour); diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index dc55256c60..cbb4594280 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -599,6 +599,13 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, BORDERLESS_FRAME_ evt.Skip(); }); + Bind(wxEVT_SHOW, [this](wxShowEvent &evt) { + DeviceManager *manger = wxGetApp().getDeviceManager(); + if (manger) { + evt.IsShown() ? manger->start_refresher() : manger->stop_refresher(); + } + }); + #ifdef _MSW_DARK_MODE wxGetApp().UpdateDarkUIWin(this); #endif // _MSW_DARK_MODE diff --git a/src/slic3r/GUI/Monitor.cpp b/src/slic3r/GUI/Monitor.cpp index cdae897902..06fe2fdad3 100644 --- a/src/slic3r/GUI/Monitor.cpp +++ b/src/slic3r/GUI/Monitor.cpp @@ -341,38 +341,9 @@ void MonitorPanel::update_all() { NetworkAgent* m_agent = wxGetApp().getAgent(); Slic3r::DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager(); - if (!dev) - return; + if (!dev) return; obj = dev->get_selected_machine(); - // check valid machine - if (obj && dev->get_my_machine(obj->dev_id) == nullptr) { - dev->set_selected_machine(""); - if (m_agent) - m_agent->set_user_selected_machine(""); - show_status((int)MONITOR_NO_PRINTER); - return; - } - - //BBS check mqtt connections if user is login - if (wxGetApp().is_user_login()) { - dev->check_pushing(); - // check mqtt connection and reconnect if disconnected - try { - m_agent->refresh_connection(); - } - catch (...) { - ; - } - } - - if (obj) { - wxGetApp().reset_to_active(); - if (obj->connection_type() != last_conn_type) { - last_conn_type = obj->connection_type(); - } - } - m_status_info_panel->obj = obj; m_upgrade_panel->update(obj); m_status_info_panel->m_media_play_ctrl->SetMachineObject(obj); @@ -387,6 +358,7 @@ void MonitorPanel::update_all() return; } + if (obj->connection_type() != last_conn_type) { last_conn_type = obj->connection_type(); } if (obj->is_connecting()) { show_status(MONITOR_CONNECTING); return; diff --git a/src/slic3r/GUI/SelectMachine.cpp b/src/slic3r/GUI/SelectMachine.cpp index 9206c6e9d0..f2bae42874 100644 --- a/src/slic3r/GUI/SelectMachine.cpp +++ b/src/slic3r/GUI/SelectMachine.cpp @@ -3036,7 +3036,6 @@ void SelectMachineDialog::update_printer_combobox(wxCommandEvent &event) void SelectMachineDialog::on_timer(wxTimerEvent &event) { - wxGetApp().reset_to_active(); update_show_status(); ///show auto refill @@ -3292,7 +3291,7 @@ void SelectMachineDialog::update_show_status() return; } if (!dev) return; - dev->check_pushing(); + PartPlate* plate = m_plater->get_partplate_list().get_curr_plate(); // blank plate has no valid gcode file @@ -3319,7 +3318,6 @@ void SelectMachineDialog::update_show_status() /* check cloud machine connections */ if (!obj_->is_lan_mode_printer()) { if (!agent->is_server_connected()) { - agent->refresh_connection(); show_status(PrintDialogStatus::PrintStatusConnectingServer); reset_timeout(); return; diff --git a/src/slic3r/GUI/SendToPrinter.cpp b/src/slic3r/GUI/SendToPrinter.cpp index 878f0b0a39..870b69fc01 100644 --- a/src/slic3r/GUI/SendToPrinter.cpp +++ b/src/slic3r/GUI/SendToPrinter.cpp @@ -1101,7 +1101,6 @@ void SendToPrinterDialog::update_printer_combobox(wxCommandEvent &event) void SendToPrinterDialog::on_timer(wxTimerEvent &event) { - wxGetApp().reset_to_active(); update_show_status(); } @@ -1172,7 +1171,6 @@ void SendToPrinterDialog::update_show_status() /* check cloud machine connections */ if (!obj_->is_lan_mode_printer()) { if (!agent->is_server_connected()) { - agent->refresh_connection(); show_status(PrintDialogStatus::PrintStatusConnectingServer); reset_timeout(); return; @@ -1668,7 +1666,6 @@ bool SendToPrinterDialog::Show(bool show) if (show) { m_ability_list.clear(); //update_storage_list(std::vector()); - wxGetApp().reset_to_active(); set_default(); update_user_machine_list(); } diff --git a/src/slic3r/GUI/SyncAmsInfoDialog.cpp b/src/slic3r/GUI/SyncAmsInfoDialog.cpp index a74152a677..1f7ce9cd99 100644 --- a/src/slic3r/GUI/SyncAmsInfoDialog.cpp +++ b/src/slic3r/GUI/SyncAmsInfoDialog.cpp @@ -63,7 +63,6 @@ bool SyncAmsInfoDialog::Show(bool show) } // set default value when show this dialog wxGetApp().UpdateDlgDarkUI(this); - wxGetApp().reset_to_active(); set_default(true); reinit_dialog(); update_user_machine_list(); @@ -2369,7 +2368,6 @@ void SyncAmsInfoDialog::update_printer_combobox(wxCommandEvent &event) void SyncAmsInfoDialog::on_timer(wxTimerEvent &event) { - wxGetApp().reset_to_active(); update_show_status(); /// show auto refill @@ -2419,7 +2417,6 @@ void SyncAmsInfoDialog::update_show_status() return; } if (!dev) return; - dev->check_pushing(); // blank plate has no valid gcode file if (is_must_finish_slice_then_connected_printer()) { return; } @@ -2435,12 +2432,10 @@ void SyncAmsInfoDialog::update_show_status() } return; } - agent->install_device_cert(obj_->dev_id, obj_->is_lan_mode_printer()); /* check cloud machine connections */ if (!obj_->is_lan_mode_printer()) { if (!agent->is_server_connected()) { - agent->refresh_connection(); show_status(PrintDialogStatus::PrintStatusConnectingServer); reset_timeout(); return;