From 9e1b142ed588866acc061226120a9cf3b4a5de41 Mon Sep 17 00:00:00 2001 From: milk Date: Fri, 10 Oct 2025 10:05:39 +0800 Subject: [PATCH] ENH:change send mode(master three patchs merged in this) jira:[STUDIO-14427] Change-Id: I1081e5252be3d932b2ffa29f70cbf93fee57eef9 (cherry picked from commit 662b7fdac8a999e54942cc9be0e5e2c2b8a90f06) --- src/slic3r/GUI/SendToPrinter.cpp | 814 +++++++++++++++++-------------- src/slic3r/GUI/SendToPrinter.hpp | 213 ++++---- 2 files changed, 571 insertions(+), 456 deletions(-) diff --git a/src/slic3r/GUI/SendToPrinter.cpp b/src/slic3r/GUI/SendToPrinter.cpp index 8b4b027586..224623f24a 100644 --- a/src/slic3r/GUI/SendToPrinter.cpp +++ b/src/slic3r/GUI/SendToPrinter.cpp @@ -25,6 +25,7 @@ #include "DeviceCore/DevManager.h" #include "DeviceCore/DevStorage.h" +#include "slic3r/Utils/FileTransferUtils.hpp" namespace Slic3r { @@ -35,13 +36,38 @@ namespace GUI { #define MACHINE_LIST_REFRESH_INTERVAL 2000 #define EMMC_STORAGE "emmc" -constexpr int timeout_period = 15000; // ms +constexpr int timeout_period = 200000; // ms wxDEFINE_EVENT(EVT_UPDATE_USER_MACHINE_LIST, wxCommandEvent); wxDEFINE_EVENT(EVT_PRINT_JOB_CANCEL, wxCommandEvent); wxDEFINE_EVENT(EVT_SEND_JOB_SUCCESS, wxCommandEvent); wxDEFINE_EVENT(EVT_CLEAR_IPADDRESS, wxCommandEvent); +static const std::map error_messages = { + {SendToPrinterDialog::ERROR_PIPE, L("Reconnecting the printer, the operation cannot be completed immediately, please try again later.")}, + {SendToPrinterDialog::ERROR_RES_BUSY, L("The device cannot handle more conversations. Please retry later.")}, + {SendToPrinterDialog::ERROR_TIME_OUT, L("Timeout, please try again.")}, + {SendToPrinterDialog::FILE_NO_EXIST, L("File does not exist.")}, + {SendToPrinterDialog::FILE_CHECK_ERR, L("File checksum error. Please retry.")}, + {SendToPrinterDialog::FILE_TYPE_ERR, L("Not supported on the current printer version.")}, + {SendToPrinterDialog::STORAGE_UNAVAILABLE, L("Current firmware does not support file transfer to internal storage.")}, + {SendToPrinterDialog::API_VERSION_UNSUPPORT, L("The firmware version of the printer is too low. Please update the firmware and try again.")}, + {SendToPrinterDialog::FILE_EXIST, L("The file already exists, do you want to replace it?")}, + {SendToPrinterDialog::STORAGE_SPACE_NOT_ENOUGH, L("Insufficient storage space, please clear the space and try again.")}, + {SendToPrinterDialog::FILE_CREATE_ERR, L("File creation failed, please try again.")}, + {SendToPrinterDialog::FILE_WRITE_ERR, L("File write failed, please try again.")}, + {SendToPrinterDialog::MD5_COMPARE_ERR, L("MD5 verification failed, please try again.")}, + {SendToPrinterDialog::FILE_RENAME_ERR, L("File renaming failed, please try again.")}, + {SendToPrinterDialog::SEND_ERR, L("File upload failed, please try again.")} +}; + +static std::string ParseErrorCode(int errorcde) +{ + auto it = error_messages.find(errorcde); + if (it != error_messages.end()) { return it->second; } + return ""; +} + void SendToPrinterDialog::stripWhiteSpace(std::string& str) { if (str == "") { return; } @@ -306,17 +332,6 @@ SendToPrinterDialog::SendToPrinterDialog(Plater *plater) 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(); - wxLogMessage(_L("click to retry")); - } - }); - // line schedule m_line_schedule = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 1)); m_line_schedule->SetBackgroundColour(wxColour(238, 238, 238)); @@ -566,7 +581,7 @@ SendToPrinterDialog::SendToPrinterDialog(Plater *plater) m_sizer_main->Add(m_line_materia, 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(30)); m_sizer_main->Add(0, 0, 0, wxEXPAND | wxTOP, FromDIP(12)); m_sizer_main->Add(m_sizer_printer, 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(30)); - m_sizer_main->Add(m_storage_panel, 0, wxALIGN_CENTER | wxTOP, FromDIP(8)); + m_sizer_main->Add(m_storage_panel, 0, wxALIGN_CENTER_HORIZONTAL | 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); @@ -576,6 +591,7 @@ SendToPrinterDialog::SendToPrinterDialog(Plater *plater) m_sizer_main->Add(m_sw_print_failed_info, 0, wxALIGN_CENTER, 0); m_sizer_main->Add(0, 0, 0, wxEXPAND | wxTOP, FromDIP(13)); + m_last_refresh_time = wxDateTime::Now(); show_print_failed_info(false); SetSizer(m_sizer_main); Layout(); @@ -591,6 +607,9 @@ SendToPrinterDialog::SendToPrinterDialog(Plater *plater) std::string SendToPrinterDialog::get_storage_selected() { + if (!m_selected_storage.empty()) + return m_selected_storage; + for (const auto& radio : m_storage_radioBox) { if (radio->GetValue()) { return radio->GetLabel().ToStdString(); @@ -599,22 +618,37 @@ std::string SendToPrinterDialog::get_storage_selected() return ""; } -void SendToPrinterDialog::update_storage_list(const std::vector& storages) +void SendToPrinterDialog::update_storage_list(const std::vector &storages) { m_storage_sizer->Clear(); m_storage_radioBox.clear(); m_storage_panel->DestroyChildren(); for (int i=0; i < storages.size(); i++) { - if (storages[i] == EMMC_STORAGE) continue; RadioBox* radiobox = new RadioBox(m_storage_panel); - Label* storage_text = new Label(m_storage_panel, storages[i]); - radiobox->SetLabel(storages[i]); - radiobox->Bind(wxEVT_LEFT_DOWN, [this, radiobox](auto& e) { + Label *storage_text = new Label(m_storage_panel); + + if (storages[i] == "emmc") + storage_text->SetLabel(_L("Internal Storage")); + else + storage_text->SetLabel(_L("Enternal Storage")); + + //radiobox->SetLabel(storages[i]); + if (storages[i] != "emmc" && m_if_has_sdcard == false) + { + storage_text->SetLabel(_L("No Enternal Storage")); + radiobox->Disable(); + } + else + { + radiobox->Enable(); + } + radiobox->Bind(wxEVT_LEFT_DOWN, [this, radiobox, selectd_storage = storages[i]](auto& e) { for (const auto& radio : m_storage_radioBox) { radio->SetValue(false); } radiobox->SetValue(true); + m_selected_storage = selectd_storage; }); m_storage_sizer->Add(radiobox, 0, wxALIGN_CENTER, 0); @@ -627,6 +661,8 @@ void SendToPrinterDialog::update_storage_list(const std::vector& st m_storage_sizer->Add(0, 0, 0, wxEXPAND, FromDIP(6)); auto radio = m_storage_radioBox.front(); radio->SetValue(true); + if (storages.size() > 0) + m_selected_storage = storages[0]; } m_storage_panel->Layout(); @@ -765,21 +801,13 @@ void SendToPrinterDialog::init_timer() void SendToPrinterDialog::on_cancel(wxCloseEvent &event) { m_worker->cancel_all(); - if (m_file_sys) { - m_file_sys->CancelUploadTask(); - if (m_task_timer && m_task_timer->IsRunning()) { - m_task_timer->Stop(); - m_task_timer.reset(); - } - m_file_sys->Stop(true); - m_file_sys.reset(); + if (m_task_timer && m_task_timer->IsRunning()) { + m_task_timer->Stop(); + m_task_timer.reset(); } - m_tcp_try_connect = true; - m_tutk_try_connect = false; - m_ftp_try_connect = false; - m_connect_try_times = 0; + Reset(); this->EndModal(wxID_CANCEL); } @@ -817,12 +845,15 @@ void SendToPrinterDialog::on_ok(wxCommandEvent &event) BOOST_LOG_TRIVIAL(info) << "print_job: enter canceled"; m_worker->cancel_all(); - if (m_file_sys) { - m_file_sys->CancelUploadTask(); - if (m_task_timer && m_task_timer->IsRunning()) { - m_task_timer->Stop(); - m_task_timer.reset(); - } + if (m_task_timer && m_task_timer->IsRunning()) { + m_task_timer->Stop(); + m_task_timer.reset(); + } + + if (m_filetransfer_uploadfile_job) { + m_filetransfer_uploadfile_job->cancel(); + m_filetransfer_uploadfile_job.reset(); + m_filetransfer_uploadfile_job = nullptr; } m_is_canceled = true; @@ -854,12 +885,14 @@ void SendToPrinterDialog::on_ok(wxCommandEvent &event) } if (m_is_canceled || m_export_3mf_cancel) { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": send progress 10"; BOOST_LOG_TRIVIAL(info) << "send_job: m_export_3mf_cancel or m_is_canceled"; //m_status_bar->set_status_text(task_canceled_text); return; } if (result < 0) { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": Abnormal print file data. Please slice again"; wxString msg = _L("Abnormal print file data. Please slice again"); m_status_bar->set_status_text(msg); return; @@ -891,87 +924,43 @@ void SendToPrinterDialog::on_ok(wxCommandEvent &event) if (obj_->is_support_brtc && (m_tcp_try_connect || m_tutk_try_connect)) { update_print_status_msg(wxEmptyString, false, false); - if (m_file_sys) { - PrintPrepareData print_data; + PrintPrepareData print_data; - m_plater->get_print_job_data(&print_data); - std::string project_name = m_current_project_name.utf8_string() + ".gcode.3mf"; + m_plater->get_print_job_data(&print_data); + std::string project_name = m_current_project_name.utf8_string() + ".gcode.3mf"; - std::string _3mf_path; - if (wxGetApp().plater()->using_exported_file()) - _3mf_path = wxGetApp().plater()->get_3mf_filename(); - else - _3mf_path = print_data._3mf_path.string(); + std::string _3mf_path; + if (wxGetApp().plater()->using_exported_file()) + _3mf_path = wxGetApp().plater()->get_3mf_filename(); + else + _3mf_path = print_data._3mf_path.string(); - auto it = std::find_if(m_ability_list.begin(), m_ability_list.end(), [](const std::string& s) { - return s != EMMC_STORAGE; - }); + CreateUploadFileJob(_3mf_path, project_name); - if (it != m_ability_list.end()) { - m_file_sys->SetUploadFile(_3mf_path, project_name, *it); - m_file_sys->RequestUploadFile(); + // time out + if (m_task_timer && m_task_timer->IsRunning()) m_task_timer->Stop(); - // time out - if (m_task_timer && m_task_timer->IsRunning()) m_task_timer->Stop(); + m_task_timer.reset(new wxTimer()); + m_task_timer->SetOwner(this); - m_task_timer.reset(new wxTimer()); - m_task_timer->SetOwner(this); - - this->Bind( - wxEVT_TIMER, - [this, wfs = boost::weak_ptr(m_file_sys), obj_](auto e) { - show_status(PrintDialogStatus::PrintStatusPublicUploadFiled); - boost::shared_ptr fs(wfs.lock()); - if (!fs) return; - fs->CancelUploadTask(false); - - //first time use tcp, second time use tutk , secnod time use ftp - if (m_connect_try_times < 2) { - bool is_lan = (obj_->connection_type() == "lan"); - m_tcp_try_connect = false; - - if (is_lan) { - m_ftp_try_connect = true; - m_tutk_try_connect = false; - } else { - if (m_connect_try_times == 0) { - m_ftp_try_connect = false; - m_tutk_try_connect = true; - } else { - m_ftp_try_connect = true; - m_tutk_try_connect = false; - } - } - BOOST_LOG_TRIVIAL(info) << "send failed"; - BOOST_LOG_TRIVIAL(info) << "m_ftp_try_connect is " << m_ftp_try_connect ; - BOOST_LOG_TRIVIAL(info) << "m_tutk_try_connect is " << m_tutk_try_connect ; - BOOST_LOG_TRIVIAL(info) << "m_tcp_try_connect is " << m_tcp_try_connect ; - } else - update_print_status_msg(_L("Upload file timeout, please check if the firmware version supports it."), false, true); - m_connect_try_times++; - }, - m_task_timer->GetId()); - m_task_timer->StartOnce(timeout_period); - } - else { - BOOST_LOG_TRIVIAL(error) << "SendToPrinter::send job: The printer media capability set is incorrect."; + this->Bind(wxEVT_TIMER, [this](auto e){ show_status(PrintDialogStatus::PrintStatusPublicUploadFiled); - update_print_status_msg(_L("No available external storage was obtained. Please confirm and try again."), true, true); - } - } - } else { - + m_filetransfer_uploadfile_job->cancel(); + update_print_status_msg(_L("Upload file timeout, please check if the firmware version supports it."), false, true); + },m_task_timer->GetId()); + m_task_timer->StartOnce(timeout_period); + } + else + { auto m_send_job = std::make_unique(m_printer_last_select); m_send_job->m_dev_ip = obj_->get_dev_ip(); m_send_job->m_access_code = obj_->get_access_code(); - BOOST_LOG_TRIVIAL(info) << "send_job: use ftp send job"; - #if !BBL_RELEASE_TO_PUBLIC m_send_job->m_local_use_ssl_for_ftp = wxGetApp().app_config->get("enable_ssl_for_ftp") == "true" ? true : false; m_send_job->m_local_use_ssl_for_mqtt = wxGetApp().app_config->get("enable_ssl_for_mqtt") == "true" ? true : false; @@ -1013,7 +1002,6 @@ void SendToPrinterDialog::on_ok(wxCommandEvent &event) replace_job(*m_worker, std::move(m_send_job)); } - BOOST_LOG_TRIVIAL(info) << "send_job: send print job"; } @@ -1054,14 +1042,16 @@ void SendToPrinterDialog::update_user_machine_list() void SendToPrinterDialog::on_refresh(wxCommandEvent &event) { + wxDateTime now = wxDateTime::Now(); + wxTimeSpan elapsed = now - m_last_refresh_time; + + if (elapsed.GetMilliseconds() < 500) return; + + m_last_refresh_time = now; + BOOST_LOG_TRIVIAL(info) << "m_printer_last_select: on_refresh"; - show_status(PrintDialogStatus::PrintStatusRefreshingMachineList); - update_user_machine_list(); - /*todo refresh*/ - if (m_file_sys) { - m_file_sys->Stop(true); - m_file_sys.reset(); - } + show_status(PrintDialogStatus::PrintStatusRefreshingMachineList); + update_user_machine_list(); } void SendToPrinterDialog::on_print_job_cancel(wxCommandEvent &evt) @@ -1197,11 +1187,8 @@ void SendToPrinterDialog::on_selection_changed(wxCommandEvent &event) auto selection = m_comboBox_printer->GetSelection(); 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; + Reset(); MachineObject* obj = nullptr; for (int i = 0; i < m_list.size(); i++) { @@ -1218,12 +1205,10 @@ void SendToPrinterDialog::on_selection_changed(wxCommandEvent &event) obj->command_request_push_all(); if (!dev->get_selected_machine()) { dev->set_selected_machine(m_printer_last_select); - if (m_file_sys) m_file_sys.reset(); + }else if (dev->get_selected_machine()->get_dev_id() != m_printer_last_select) { - m_ability_list.clear(); - //update_storage_list(std::vector()); + update_storage_list(std::vector()); dev->set_selected_machine(m_printer_last_select); - if (m_file_sys) m_file_sys.reset(); } } else { @@ -1251,7 +1236,6 @@ void SendToPrinterDialog::update_show_status() return; } - /* check cloud machine connections */ if (!obj_->is_lan_mode_printer()) { if (!agent->is_server_connected()) { @@ -1293,199 +1277,51 @@ void SendToPrinterDialog::update_show_status() // check sdcard when if lan mode printer /* if (obj_->is_lan_mode_printer()) { }*/ - if (obj_->GetStorage()->get_sdcard_state() == DevStorage::SdcardState::NO_SDCARD) { - show_status(PrintDialogStatus::PrintStatusNoSdcard); - return; - } - - if (!obj_->is_support_send_to_sdcard) { show_status(PrintDialogStatus::PrintStatusNotSupportedSendToSDCard); return; } - - - if (!m_is_in_sending_mode) { - if (!obj_->is_support_brtc || m_ftp_try_connect) { - if (m_file_sys) { - m_device_select.clear(); - m_file_sys->Stop(true); - m_file_sys.reset(); - } - BOOST_LOG_TRIVIAL(info) << "m_ftp_try_connect is ok" << m_ftp_try_connect; - - // add log - show_status(PrintDialogStatus::PrintStatusReadingFinished); - return; - } else/* if (obj_->connection_type() == "cloud")*/ { + if (!m_is_in_sending_mode) + { + if (obj_->is_support_brtc && !m_ftp_try_connect) + { std::string dev_id = obj_->get_dev_ip(); - if (m_file_sys) { - if (dev_id == m_device_select) { - if ((m_waiting_enable && IsEnabled()) || (m_waiting_support && obj_->get_file_remote())) - { - m_file_sys->Retry(); - BOOST_LOG_TRIVIAL(info) << "m_file_sys Retry success!" ; - } - return; - } else { - m_file_sys->Stop(true); + if (m_device_select != dev_id) + { + show_status(PrintDialogStatus::PrintStatusConnecting); + m_device_select.swap(dev_id); + if (obj_->GetStorage()->get_sdcard_state() == DevStorage::SdcardState::NO_SDCARD) + m_if_has_sdcard = false; + else + m_if_has_sdcard = true; + + if (m_filetransfer_tunnel) { + m_filetransfer_tunnel.reset(); + m_filetransfer_tunnel = nullptr; } + + GetConnection(); } - - m_device_select.swap(dev_id); - m_file_sys = boost::make_shared(); - m_file_sys->Attached(); - - 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; - - wxString msg; - int status = e.GetInt(); - int extra = e.GetExtraLong(); - - switch (status) { - case PrinterFileSystem::Initializing: - case PrinterFileSystem::Connecting: show_status(PrintDialogStatus::PrintStatusConnecting); break; - - case PrinterFileSystem::ListSyncing: { - show_status(PrintDialogStatus::PrintStatusReading); - boost::uint32_t seq = fs->RequestMediaAbility(3); - - if (m_task_timer && m_task_timer->IsRunning()) - m_task_timer->Stop(); - - m_task_timer.reset(new wxTimer()); - m_task_timer->SetOwner(this); - - this->Bind(wxEVT_TIMER, [this, wfs_1 = boost::weak_ptr(fs), seq](auto e) { - show_status(PrintDialogStatus::PrintStatusPublicInitFailed); - update_print_status_msg(_L("Media capability acquisition timeout, please check if the firmware version supports it."), true, true); - }, m_task_timer->GetId()); - m_task_timer->StartOnce(timeout_period); - - break; - } - case PrinterFileSystem::Failed: { - if (m_connect_try_times < 2) { - bool is_lan = (obj_->connection_type() == "lan"); - - m_tcp_try_connect = false; - - if (is_lan) { - m_ftp_try_connect = true; - m_tutk_try_connect = false; - } else { - if (m_connect_try_times == 0) { - m_ftp_try_connect = false; - m_tutk_try_connect = true; - } else { - m_ftp_try_connect = true; - m_tutk_try_connect = false; - } - } - BOOST_LOG_TRIVIAL(info) << "connect failed" ; - BOOST_LOG_TRIVIAL(info) << "m_ftp_try_connect1 is " << m_ftp_try_connect; - BOOST_LOG_TRIVIAL(info) << "m_tutk_try_connect1 is " << m_tutk_try_connect ; - BOOST_LOG_TRIVIAL(info) << "m_tcp_try_connect1 is " << m_tcp_try_connect; - } - else - msg = _L("Please check the network and try again, You can restart or update the printer if the issue persists."); - - fs->Stop(); - m_connect_try_times++; - BOOST_LOG_TRIVIAL(info) << "m_connect_try_times is " << m_connect_try_times; - - break; - } - - case PrinterFileSystem::Reconnecting: show_status(PrintDialogStatus::PrintStatusReconnecting); - - } - - if (!msg.empty()) { - show_status(PrintDialogStatus::PrintStatusPublicInitFailed); - update_print_status_msg(msg, false, true); - } - - if (e.GetInt() == PrinterFileSystem::Initializing) { - CallAfter([=] { - boost::shared_ptr fs(wfs.lock()); - if (!fs) return; - fetchUrl(boost::weak_ptr(fs)); - }); - } - }); - - m_file_sys->Bind(EVT_MEDIA_ABILITY_CHANGED, [this, wfs = boost::weak_ptr(m_file_sys)](auto e) { - boost::shared_ptr fs(wfs.lock()); - if (!fs) return; - - if (m_task_timer && m_task_timer->IsRunning()) { - m_task_timer->Stop(); - m_task_timer.reset(); - } - - m_ability_list = fs->GetMediaAbilityList(); - - if (e.GetInt() == PrinterFileSystem::RequestMediaAbilityStatus::S_SUCCESS) { - //update_storage_list(m_ability_list); - show_status(PrintDialogStatus::PrintStatusReadingFinished); - } else { + } + else + { + if (obj_->is_support_brtc && !obj_->is_lan_mode_printer()) + { show_status(PrintDialogStatus::PrintStatusPublicInitFailed); - update_print_status_msg(e.GetString(), false, true); + update_print_status_msg(_L("Connection timed out, please check your network."), true, true); } - }); + else + { + //use ftp + if (obj_->GetStorage()->get_sdcard_state() == DevStorage::SdcardState::NO_SDCARD) { + show_status(PrintDialogStatus::PrintStatusNoSdcard); + return; + } - m_file_sys->Bind(EVT_UPLOADING, [this, wfs = boost::weak_ptr(m_file_sys)](auto e) { - boost::shared_ptr fs(wfs.lock()); - if (!fs) return; - int progress = e.GetInt(); - bool cancelled = false; - wxString msg = _L("Sending..."); - m_status_bar->update_status(msg, cancelled, 10 + std::floor(progress * 0.9), true); - - if (m_task_timer && m_task_timer->IsRunning()) m_task_timer->Stop(); - - if (progress == 99) { - m_task_timer.reset(new wxTimer()); - m_task_timer->SetOwner(this); - - this->Bind( - wxEVT_TIMER, - [this, wfs = boost::weak_ptr(m_file_sys)](auto e) { - show_status(PrintDialogStatus::PrintStatusPublicUploadFiled); - boost::shared_ptr fs(wfs.lock()); - if (!fs) return; - fs->CancelUploadTask(false); - update_print_status_msg(_L("File upload timed out. Please check if the firmware version supports this operation or verify if the printer is functioning properly."), false, true); - }, - m_task_timer->GetId()); - m_task_timer->StartOnce(timeout_period); - } - }); - m_file_sys->Bind(EVT_UPLOAD_CHANGED, [this, wfs = boost::weak_ptr(m_file_sys)](auto e) { - boost::shared_ptr fs(wfs.lock()); - if (!fs) return; - - if (m_task_timer && m_task_timer->IsRunning()) m_task_timer->Stop(); - - if (e.GetInt() == PrinterFileSystem::FF_UPLOADDONE) { show_status(PrintDialogStatus::PrintStatusReadingFinished); - wxCommandEvent *evt = new wxCommandEvent(m_plater->get_send_finished_event()); - evt->SetString(from_u8(m_current_project_name.utf8_string())); - wxQueueEvent(m_plater, evt); - } else if (e.GetInt() == PrinterFileSystem::FF_UPLOADCANCEL) { - show_status(PrintDialogStatus::PrintStatusPublicUploadFiled); - wxString err_msg = e.GetString(); - if (err_msg.IsEmpty()) - err_msg = _L("Sending failed, please try again!"); - update_print_status_msg(err_msg, false, true); + return; } - }); - m_file_sys->Start(); } } } @@ -1813,21 +1649,12 @@ bool SendToPrinterDialog::Show(bool show) // set default value when show this dialog if (show) { - m_ability_list.clear(); - //update_storage_list(std::vector()); + update_storage_list(std::vector()); set_default(); update_user_machine_list(); - } - - - - if (show) { + Reset(); m_refresh_timer->Start(LIST_REFRESH_INTERVAL); - m_tcp_try_connect = true; - m_ftp_try_connect = false; - m_tutk_try_connect = false; - //BOOST_LOG_TRIVIAL(info) << "m_ftp_try_connect is " << m_ftp_try_connect << boost::stacktrace::stacktrace(); - m_connect_try_times = 0; + } else { m_refresh_timer->Stop(); } @@ -1836,100 +1663,337 @@ bool SendToPrinterDialog::Show(bool show) Fit(); if (show) { CenterOnParent(); } - if (m_file_sys) { - m_waiting_enable = false; - m_waiting_support = false; - show ? m_file_sys->Start() : m_file_sys->Stop(); - } return DPIDialog::Show(show); } extern wxString hide_passwd(wxString url, std::vector const &passwords); extern void refresh_agora_url(char const *device, char const *dev_ver, char const *channel, void *context, void (*callback)(void *context, char const *url)); -void SendToPrinterDialog::fetchUrl(boost::weak_ptr wfs) +void SendToPrinterDialog::GetConnection() { - boost::shared_ptr fs(wfs.lock()); - if (!fs) return; + DeviceManager *dm = GUI::wxGetApp().getDeviceManager(); - if (!IsEnabled()) { - m_waiting_enable = true; - fs->SetUrl("0"); - return; - } - - m_waiting_enable = false; - DeviceManager *dm = GUI::wxGetApp().getDeviceManager(); MachineObject *obj = dm->get_selected_machine(); - if (obj == nullptr) { - fs->SetUrl("0"); - return; + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " : obj is empty"; + m_connection_status = ConnectionStatus::NOT_START; } - std::string dev_ver = obj->get_ota_version(); - std::string dev_id = obj->get_dev_id(); int remote_proto = obj->get_file_remote(); if (!remote_proto) { - m_waiting_support = true; - fs->SetUrl("0"); - return; + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " : remote_proto is not support"; + m_connection_status = ConnectionStatus::NOT_START; } if (obj->is_camera_busy_off()) { - fs->SetUrl("0"); - return; + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " : camera is busy"; + m_connection_status = ConnectionStatus::NOT_START; } - m_waiting_support = false; NetworkAgent *agent = wxGetApp().getAgent(); std::string agent_version = agent ? agent->get_version() : ""; + std::string dev_ver = obj->get_ota_version(); + std::string dev_id = obj->get_dev_id(); + if (m_url_timer && m_url_timer->IsRunning()) + { + m_url_timer->Stop(); + } + m_url_timer.reset(new wxTimer()); + m_url_timer->SetOwner(this); + this->Bind( + wxEVT_TIMER, + [this](wxTimerEvent &e) { + BOOST_LOG_TRIVIAL(info) << "Timer callback triggered!"; + m_connection_status = ConnectionStatus::CONNECTION_FAILED; + m_ftp_try_connect = true; + if (m_filetransfer_tunnel) + { + m_filetransfer_tunnel.reset(); + m_filetransfer_tunnel = nullptr; + } - if (agent) { - if (m_tcp_try_connect) { - std::string devIP = obj->get_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 { - fs->SetUrl("3"); - } + }, + m_url_timer->GetId()); + m_url_timer->StartOnce(8000); + + if (agent) { + if (m_tcp_try_connect) { + std::string devIP = obj->get_dev_ip(); + std::string accessCode = obj->get_access_code(); + std::string url = "bambu:///local/" + devIP + "?port=6000&user=" + "bblp" + "&passwd=" + accessCode; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": Connect method tcp"; + m_filetransfer_tunnel = std::make_unique(module(), url); + m_filetransfer_tunnel->on_connection([this](bool is_success, int err_code, std::string error_msg) { + CallAfter([this, is_success, err_code, error_msg]() { + OnConnection(is_success, err_code, error_msg); }); - } - else if (m_tutk_try_connect){ - std::string protocols[] = {"", "\"tutk\"", "\"agora\"", "\"tutk\",\"agora\""}; - agent->get_camera_url(obj->get_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; - url += "&dev_ver=" + dv; - url += "&refresh_url=" + boost::lexical_cast(&refresh_agora_url); - url += "&cli_id=" + wxGetApp().app_config->get("slicer_uuid"); - url += "&cli_ver=" + std::string(SLIC3R_VERSION); - } - BOOST_LOG_TRIVIAL(info) << "SendToPrinter::fetchUrl: camera_url: " << hide_passwd(url, {"?uid=", "authkey=", "passwd="}); - std::cout << "SendToPrinter::fetchUrl: camera_url: " << hide_passwd(url, {"?uid=", "authkey=", "passwd="}); - CallAfter([=] { - boost::shared_ptr fs(wfs.lock()); - if (!fs) return; - if (boost::algorithm::starts_with(url, "bambu:///")) { - fs->SetUrl(url); - } else { - fs->SetUrl("3"); - } + }); + m_filetransfer_tunnel->start_connect(); + } + else if (m_tutk_try_connect) + { + std::string protocols[] = {"", "\"tutk\"", "\"agora\"", "\"tutk\",\"agora\""}; + agent->get_camera_url(obj->get_dev_id() + "|" + dev_ver + "|" + protocols[1], [this, 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; + url += "&dev_ver=" + dv; + url += "&refresh_url=" + boost::lexical_cast(&refresh_agora_url); + url += "&cli_id=" + wxGetApp().app_config->get("slicer_uuid"); + url += "&cli_ver=" + std::string(SLIC3R_VERSION); + } + + if (m_url_timer && m_url_timer->IsRunning()) + { + m_url_timer->Stop(); + } + + #if !BBL_RELEASE_TO_PUBLIC + BOOST_LOG_TRIVIAL(info) << "SendToPrinter::camera_url: " << hide_passwd(url, {"?uid=", "authkey=", "passwd="}); + #endif + + + if (boost::algorithm::starts_with(url, "bambu:///")) + { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": Connect method tutk"; + m_filetransfer_tunnel = std::make_unique(module(), url); + m_filetransfer_tunnel->on_connection([this](bool is_success, int err_code, std::string error_msg) { + CallAfter([this, is_success, err_code, error_msg]() { OnConnection(is_success, err_code, error_msg); }); }); - }); + m_filetransfer_tunnel->start_connect(); + } + else + { + std::string res = ""; + if (!url.empty() && boost::ends_with(url, "]")) + { + size_t n = url.find_last_of('['); + if (n != std::string::npos) + res = url.substr(n + 1, url.length() - n - 2); + } + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " : Tutk url error: ress = " << res; + } + }); + } + } +} + +void SendToPrinterDialog::OnConnection(bool is_success, int error_code, std::string error_msg) { + if (is_success) + { + if (m_url_timer && m_url_timer->IsRunning()) { m_url_timer->Stop(); } + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "Connect success"; + m_connection_status = ConnectionStatus::CONNECTED; + CreateMediaAbilityJob(); + } + else + { + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Connect failed, error_code is:" << error_code << "error_msg is :" << error_msg; + m_connection_status = ConnectionStatus::CONNECTION_FAILED; + ChangeConnectMethod(); + if (!m_tcp_try_connect && !m_tutk_try_connect) { + show_status(PrintDialogStatus::PrintStatusPublicInitFailed); + return; + } + m_filetransfer_tunnel.reset(); + m_filetransfer_tunnel = nullptr; + GetConnection(); + } +} + +void SendToPrinterDialog::ChangeConnectMethod() +{ + DeviceManager *dev = Slic3r::GUI::wxGetApp().getDeviceManager(); + if (!dev) return; + MachineObject *obj = dev->get_my_machine(m_printer_last_select); + if (!obj) return; + + bool is_lan = (obj->connection_type() == "lan"); + + m_tcp_try_connect = false; + + if (is_lan) { + m_ftp_try_connect = true; + m_tutk_try_connect = false; + } else { + if (m_connect_try_times == 0) { + m_ftp_try_connect = false; + m_tutk_try_connect = true; + } else { + m_ftp_try_connect = true; + m_tutk_try_connect = false; + } + } + m_connect_try_times++; +} + +void SendToPrinterDialog::ResetConnectMethod() +{ + m_tcp_try_connect = true; + m_ftp_try_connect = false; + m_tutk_try_connect = false; + m_connect_try_times = 0; +} + + +void SendToPrinterDialog::ResetTunnelAndJob() +{ + if (m_filetransfer_uploadfile_job) + { + m_filetransfer_uploadfile_job->cancel(); + m_filetransfer_uploadfile_job.reset(); + m_filetransfer_uploadfile_job = nullptr; + } + if (m_filetransfer_mediability_job) + { + m_filetransfer_mediability_job->cancel(); + m_filetransfer_mediability_job.reset(); + m_filetransfer_mediability_job = nullptr; + } + if (m_filetransfer_tunnel) + { + m_filetransfer_tunnel.reset(); + m_filetransfer_tunnel = nullptr; + } +} + +void SendToPrinterDialog::CreateMediaAbilityJob() +{ + nlohmann::json media_ability = {{"cmd_type", 7}}; + m_filetransfer_mediability_job = std::make_unique(module(), std::string(media_ability.dump())); + m_filetransfer_mediability_job->on_result([this](int res, int resp_ec, std::string json_res, std::vector bin_res) { + //this pl + CallAfter([this, res, resp_ec, json_res] { + if (res == 0) // 0 is success + { + show_status(PrintDialogStatus::PrintStatusReadingFinished); + try + { + auto media_set = nlohmann::json::parse(json_res); + for (const auto &it : media_set) + m_ability_list.push_back(it.get()); + update_storage_list(m_ability_list); + BOOST_LOG_TRIVIAL(info) << "CreateMediaAbilityJob::" << "request mediaability success." << json_res; + } + catch (const nlohmann::json::exception &e) + { + BOOST_LOG_TRIVIAL(error) << "CreateMediaAbilityJob::" << ": " << e.what(); + } + catch (...) + { + BOOST_LOG_TRIVIAL(error) << "CreateMediaAbilityJob::" << ": " << "parse error!"; + } + } + else + { + BOOST_LOG_TRIVIAL(error) << "CreateMediaAbilityJob::" << ":request mediaability failed. res =" << res << "resp_ec is:" << resp_ec; + show_status(PrintDialogStatus::PrintStatusPublicInitFailed); + update_print_status_msg(ParseErrorCode(resp_ec), false, true); + } + }); + }); + m_filetransfer_mediability_job->start_on(*m_filetransfer_tunnel); +} + +void SendToPrinterDialog::CreateUploadFileJob(const std::string &path, const std::string &name) +{ + nlohmann::json upload_params = { + {"cmd_type", 5}, + }; + upload_params["dest_storage"] = m_selected_storage; + upload_params["dest_name"] = name; // filenme no path + upload_params["file_path"] = path; + + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": Begin CreateUploadFileJob"; + m_filetransfer_uploadfile_job = std::make_unique(module(), std::string(upload_params.dump())); + m_filetransfer_uploadfile_job->on_result([this](int res, int resp_ec, std::string json_res, std::vector bin_res) { // + CallAfter([this, res, resp_ec, json_res, bin_res] { + UploadFileRessultCallback(res, resp_ec,json_res, bin_res); + }); + }); + + m_filetransfer_uploadfile_job->on_msg([this](int kind, std::string json_res) { + CallAfter([this, kind, json_res] { + if (kind == 0) { + try + { + auto js = nlohmann::json::parse(json_res); + int progress = js["progress"].get(); + UploadFileProgressCallback(progress); + } + catch (const nlohmann::json::exception& e) + { + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": " << e.what(); + } + catch (...) + { + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": " << "parse_json failed! "; } } + }); + }); + m_filetransfer_uploadfile_job->start_on(*m_filetransfer_tunnel); +} +void SendToPrinterDialog::UploadFileProgressCallback(int progress) +{ + bool cancelled = false; + wxString msg = _L("Sending..."); + m_status_bar->update_status(msg, cancelled, 10 + std::floor(progress * 0.9), true); + + if (m_task_timer && m_task_timer->IsRunning()) m_task_timer->Stop(); + + if (progress == 99) { + m_task_timer.reset(new wxTimer()); + m_task_timer->SetOwner(this); + + this->Bind( + wxEVT_TIMER, + [this](auto e) { + show_status(PrintDialogStatus::PrintStatusPublicUploadFiled); + update_print_status_msg( + _L("File upload timed out. Please check if the firmware version supports this operation or verify if the printer is functioning properly."), false, true); + }, + m_task_timer->GetId()); + m_task_timer->StartOnce(timeout_period); + } +} + +void SendToPrinterDialog::UploadFileRessultCallback(int res, int resp_ec, std::string json_res, std::vector bin_res) +{ + if (m_task_timer && m_task_timer->IsRunning()) m_task_timer->Stop(); + + if (res == 0) + { + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":upload success to:" << m_selected_storage ; + show_status(PrintDialogStatus::PrintStatusReadingFinished); + wxCommandEvent *evt = new wxCommandEvent(m_plater->get_send_finished_event()); + evt->SetString(from_u8(m_current_project_name.utf8_string())); + wxQueueEvent(m_plater, evt); + } + else { + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":upload failed to:"<< m_selected_storage << "res:" << res << "resp_ec is:" << resp_ec; + show_status(PrintDialogStatus::PrintStatusPublicUploadFiled) ; + // if (err_msg.IsEmpty()) err_msg = _L("Sending failed, please try again!"); // TODO error code + if (ParseErrorCode(resp_ec) != "") + update_print_status_msg(ParseErrorCode(resp_ec), false, true); + else + update_print_status_msg("Sending failed, please try again!", false, true); + m_filetransfer_uploadfile_job.reset(); + m_filetransfer_uploadfile_job = nullptr; + } +} + +void SendToPrinterDialog::Reset() { + if (m_url_timer && m_url_timer->IsRunning()) { m_url_timer->Stop(); } + m_ability_list.clear(); + update_storage_list(std::vector()); + m_device_select.clear(); + ResetConnectMethod(); + ResetTunnelAndJob(); - return; } SendToPrinterDialog::~SendToPrinterDialog() @@ -1937,6 +2001,8 @@ SendToPrinterDialog::~SendToPrinterDialog() delete m_refresh_timer; if (m_task_timer && m_task_timer->IsRunning()) m_task_timer->Stop(); + if (m_url_timer && m_url_timer->IsRunning()) + m_url_timer->Stop(); } } diff --git a/src/slic3r/GUI/SendToPrinter.hpp b/src/slic3r/GUI/SendToPrinter.hpp index 23c1f3c580..de284e31d6 100644 --- a/src/slic3r/GUI/SendToPrinter.hpp +++ b/src/slic3r/GUI/SendToPrinter.hpp @@ -38,112 +38,150 @@ #include "Widgets/ScrolledWindow.hpp" #include #include -#include "Printer/PrinterFileSystem.h" #include "Widgets/AnimaController.hpp" #include "Widgets/RadioBox.hpp" + namespace Slic3r { +class FileTransferTunnel; +class FileTransferJob; + namespace GUI { class SendToPrinterDialog : public DPIDialog { private: - void init_bind(); - void init_timer(); + void init_bind(); + void init_timer(); - - int m_print_plate_idx; - int m_current_filament_id; + int m_print_plate_idx; + int m_current_filament_id; int m_print_error_code = 0; - int timeout_count = 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 }; - bool m_need_adaptation_screen{ false }; - bool m_export_3mf_cancel{ false }; - bool m_is_canceled{ false }; + bool m_is_in_sending_mode{ false }; + bool m_is_rename_mode{ false }; + bool enable_prepare_mode{ true }; + bool m_need_adaptation_screen{ false }; + 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; - std::string m_printer_last_select; + std::string m_print_info; + std::string m_printer_last_select; std::string m_device_select; - wxString m_current_project_name; + wxString m_current_project_name; - TextInput* m_rename_input{ nullptr }; - wxSimplebook* m_rename_switch_panel{ nullptr }; - Plater* m_plater{ nullptr }; - wxStaticBitmap* m_staticbitmap{ nullptr }; - ThumbnailPanel* m_thumbnailPanel{ nullptr }; - ComboBox* m_comboBox_printer{ nullptr }; - ComboBox* m_comboBox_bed{ nullptr }; - Button* m_rename_button{ nullptr }; - Button* m_button_refresh{ nullptr }; - Button* m_button_ensure{ nullptr }; - wxPanel* m_scrollable_region; - wxPanel* m_line_schedule{ nullptr }; - wxPanel* m_panel_sending{ nullptr }; - wxPanel* m_panel_prepare{ nullptr }; - wxPanel* m_panel_finish{ nullptr }; - wxPanel* m_line_top{ nullptr }; - wxPanel* m_panel_image{ nullptr }; - wxPanel* m_rename_normal_panel{ nullptr }; - wxPanel* m_line_materia{ nullptr }; + TextInput* m_rename_input{ nullptr }; + wxSimplebook* m_rename_switch_panel{ nullptr }; + Plater* m_plater{ nullptr }; + wxStaticBitmap* m_staticbitmap{ nullptr }; + ThumbnailPanel* m_thumbnailPanel{ nullptr }; + ComboBox* m_comboBox_printer{ nullptr }; + ComboBox* m_comboBox_bed{ nullptr }; + Button* m_rename_button{ nullptr }; + Button* m_button_refresh{ nullptr }; + Button* m_button_ensure{ nullptr }; + wxPanel* m_scrollable_region; + wxPanel* m_line_schedule{ nullptr }; + wxPanel* m_panel_sending{ nullptr }; + wxPanel* m_panel_prepare{ nullptr }; + wxPanel* m_panel_finish{ nullptr }; + wxPanel* m_line_top{ nullptr }; + wxPanel* m_panel_image{ nullptr }; + wxPanel* m_rename_normal_panel{ nullptr }; + 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 }; + 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 }; - wxStaticText* m_stext_weight{ nullptr }; + wxStaticText* m_stext_printer_title{ nullptr }; + wxStaticText* m_rename_text{ nullptr }; + wxStaticText* m_stext_time{ nullptr }; + wxStaticText* m_stext_weight{ nullptr }; Label* m_st_txt_error_code{ nullptr }; Label* m_st_txt_error_desc{ nullptr }; Label* m_st_txt_extra_info{ nullptr }; wxHyperlinkCtrl* m_link_network_state{ nullptr }; - StateColor btn_bg_enable; - wxBoxSizer* rename_sizer_v{ nullptr }; - wxBoxSizer* rename_sizer_h{ nullptr }; - wxBoxSizer* sizer_thumbnail; - wxBoxSizer* m_sizer_scrollable_region; - wxBoxSizer* m_sizer_main; - - wxStaticText* m_file_name; - PrintDialogStatus m_print_status{ PrintStatusInit }; + StateColor btn_bg_enable; + wxBoxSizer* rename_sizer_v{ nullptr }; + wxBoxSizer* rename_sizer_h{ nullptr }; + 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::vector m_bedtype_list; - std::map m_checkbox_list; - std::vector m_list; - wxColour m_colour_def_color{ wxColour(255, 255, 255) }; - wxColour m_colour_bold_color{ wxColour(38, 46, 48) }; - wxTimer* m_refresh_timer{ nullptr }; + std::map m_checkbox_list; + std::vector m_list; + wxColour m_colour_def_color{ wxColour(255, 255, 255) }; + wxColour m_colour_bold_color{ wxColour(38, 46, 48) }; + wxTimer* m_refresh_timer{ nullptr }; std::unique_ptr m_task_timer{ nullptr }; + std::unique_ptr m_url_timer{nullptr}; std::shared_ptr m_status_bar; std::unique_ptr m_worker; - wxScrolledWindow* m_sw_print_failed_info{nullptr}; + wxScrolledWindow *m_sw_print_failed_info{nullptr}; std::shared_ptr m_token = std::make_shared(0); - std::vector m_storage_radioBox; - - bool m_waiting_support{ false }; - bool m_waiting_enable{ false }; - boost::shared_ptr m_file_sys; - std::vector m_ability_list; + std::vector m_storage_radioBox; + std::string m_selected_storage; + bool m_if_has_sdcard; + bool m_waiting_support{ false }; + bool m_waiting_enable{ false }; + std::vector m_ability_list; public: - SendToPrinterDialog(Plater* plater = nullptr); + enum { + SUCCESS = 0, + CONTINUE = 1, + ERROR_JSON = 2, + ERROR_PIPE = 3, + ERROR_CANCEL = 4, + ERROR_RES_BUSY = 5, + ERROR_TIME_OUT = 6, + FILE_NO_EXIST = 10, + FILE_NAME_INVALID = 11, + FILE_SIZE_ERR = 12, + FILE_OPEN_ERR = 13, + FILE_READ_WRITE_ERR = 14, + FILE_CHECK_ERR = 15, + FILE_TYPE_ERR = 16, + STORAGE_UNAVAILABLE = 17, + API_VERSION_UNSUPPORT = 18, + FILE_EXIST = 19, + STORAGE_SPACE_NOT_ENOUGH = 20, + FILE_CREATE_ERR = 21, + FILE_WRITE_ERR = 22, + MD5_COMPARE_ERR = 23, + FILE_RENAME_ERR = 24, + SEND_ERR = 25, +}; + +private: + enum ConnectionStatus { NOT_START, CONNECTING, CONNECTED, CONNECTION_FAILED, DISCONNECTED }; + ConnectionStatus m_connection_status{ConnectionStatus::NOT_START}; + + std::unique_ptr m_filetransfer_tunnel; + std::unique_ptr m_filetransfer_mediability_job; + std::unique_ptr m_filetransfer_uploadfile_job; + wxDateTime m_last_refresh_time; + +public: + SendToPrinterDialog(Plater *plater = nullptr); ~SendToPrinterDialog(); - bool Show(bool show); - bool is_timeout(); + bool Show(bool show); + bool is_timeout(); void on_rename_click(wxCommandEvent& event); void on_rename_enter(); void stripWhiteSpace(std::string& str); @@ -158,19 +196,19 @@ public: void check_fcous_state(wxWindow* window); void update_priner_status_msg(wxString msg, bool is_warning = false); void update_print_status_msg(wxString msg, bool is_warning = false, bool is_printer = true); - void update_printer_combobox(wxCommandEvent& event); - void on_cancel(wxCloseEvent& event); - void on_ok(wxCommandEvent& event); - void clear_ip_address_config(wxCommandEvent& e); - void on_refresh(wxCommandEvent& event); - void on_print_job_cancel(wxCommandEvent& evt); - void set_default(); - void on_timer(wxTimerEvent& event); - void on_selection_changed(wxCommandEvent& event); - void Enable_Refresh_Button(bool en); - void show_status(PrintDialogStatus status, std::vector params = std::vector()); - void Enable_Send_Button(bool en); - void on_dpi_changed(const wxRect& suggested_rect) override; + void update_printer_combobox(wxCommandEvent& event); + void on_cancel(wxCloseEvent& event); + void on_ok(wxCommandEvent& event); + void clear_ip_address_config(wxCommandEvent& e); + void on_refresh(wxCommandEvent& event); + void on_print_job_cancel(wxCommandEvent& evt); + void set_default(); + void on_timer(wxTimerEvent& event); + void on_selection_changed(wxCommandEvent& event); + void Enable_Refresh_Button(bool en); + void show_status(PrintDialogStatus status, std::vector params = std::vector()); + void Enable_Send_Button(bool en); + void on_dpi_changed(const wxRect& suggested_rect) override; void update_user_machine_list(); void show_print_failed_info(bool show, int code = 0, wxString description = wxEmptyString, wxString extra = wxEmptyString); void update_print_error_info(int code, std::string msg, std::string extra); @@ -180,10 +218,21 @@ public: wxString format_text(wxString& m_msg); std::vector sort_string(std::vector strArray); + void GetConnection(); - void fetchUrl(boost::weak_ptr wfs); +private: + void ResetConnectMethod(); + void ResetTunnelAndJob(); + void OnConnection(bool is_success, int error_code, std::string error_msg); + void CreateMediaAbilityJob(); + void CreateUploadFileJob(const std::string &path, const std::string &name); + void ChangeConnectMethod(); + void UploadFileProgressCallback(int progress); + void UploadFileRessultCallback(int res, int resp_ec, std::string json_res, std::vector bin_res); + void Reset(); }; + wxDECLARE_EVENT(EVT_CLEAR_IPADDRESS, wxCommandEvent); } }