diff --git a/src/slic3r/GUI/Printer/PrinterFileSystem.cpp b/src/slic3r/GUI/Printer/PrinterFileSystem.cpp index c212d5e72..789a93f72 100644 --- a/src/slic3r/GUI/Printer/PrinterFileSystem.cpp +++ b/src/slic3r/GUI/Printer/PrinterFileSystem.cpp @@ -419,6 +419,13 @@ std::string PrinterFileSystem::File::Metadata(std::string const &key, std::strin return iter == metadata.end() || iter->second.empty() ? dflt : iter->second; } +PrinterFileSystem::UploadFile::~UploadFile() +{ + if (upload && upload->ifs.is_open()) { + upload->ifs.close(); + } +} + size_t PrinterFileSystem::GetIndexAtTime(boost::uint32_t time) { auto iter = std::upper_bound(m_file_list.begin(), m_file_list.end(), File{"", "", time}); @@ -1144,6 +1151,9 @@ void PrinterFileSystem::RequestUploadFile() // reset m_upload_file if (m_upload_file) { + if (m_upload_file->upload->ifs.is_open()) { + m_upload_file->upload->ifs.close(); + } m_upload_file.reset(); } return result; @@ -1248,6 +1258,16 @@ void PrinterFileSystem::CancelUploadTask(bool send_cancel_req) if (!m_upload_file) return; + { + boost::unique_lock l(m_mutex); + if (m_produce_message_cb_map.find(m_upload_seq) != m_produce_message_cb_map.end()) + m_produce_message_cb_map.erase(m_upload_seq); + if (m_upload_file->upload->ifs.is_open()) { + m_upload_file->upload->ifs.close(); + } + m_upload_file.reset(); + } + if (send_cancel_req) { CancelRequest(m_upload_seq); } else { @@ -1426,8 +1446,8 @@ void PrinterFileSystem::HandleResponse(boost::unique_lock &l, Bamb json_end = end; std::string msg((char const *) sample.buffer, json_end - sample.buffer); json root; - //OutputDebugStringA(msg.c_str()); - //OutputDebugStringA("\n"); + // OutputDebugStringA(msg.c_str()); + // OutputDebugStringA("\n"); wxLogInfo("PrinterFileSystem::HandleResponse <<<: \n%s\n", wxString::FromUTF8(msg)); std::istringstream iss(msg); int cmd = 0; @@ -1673,5 +1693,4 @@ void StaticBambuLib::release() } extern "C" BambuLib *bambulib_get() { - return &StaticBambuLib::get(); -} \ No newline at end of file + return &StaticBambuLib::get(); } diff --git a/src/slic3r/GUI/Printer/PrinterFileSystem.h b/src/slic3r/GUI/Printer/PrinterFileSystem.h index c86d3bf51..86171d9e8 100644 --- a/src/slic3r/GUI/Printer/PrinterFileSystem.h +++ b/src/slic3r/GUI/Printer/PrinterFileSystem.h @@ -169,6 +169,7 @@ public: std::unique_ptr upload; bool IsUploading() const { return flags & FF_UPLOADING; } + ~UploadFile(); }; struct Void {}; diff --git a/src/slic3r/GUI/SendToPrinter.cpp b/src/slic3r/GUI/SendToPrinter.cpp index e5ab4eced..f1cb0283d 100644 --- a/src/slic3r/GUI/SendToPrinter.cpp +++ b/src/slic3r/GUI/SendToPrinter.cpp @@ -157,6 +157,11 @@ void SendToPrinterDialog::on_rename_enter() m_valid_type = NoValid; } + if (m_valid_type == Valid && new_file_name.size() >= 100) { + info_line = _L("The name length exceeds the limit."); + m_valid_type = NoValid; + } + if (m_valid_type != Valid) { MessageDialog msg_wingow(nullptr, info_line, "", wxICON_WARNING | wxOK); if (msg_wingow.ShowModal() == wxID_OK) { @@ -732,6 +737,8 @@ void SendToPrinterDialog::on_cancel(wxCloseEvent &event) m_send_job->join(); } } + +#if !BBL_RELEASE_TO_PUBLIC if (m_file_sys) { m_file_sys->CancelUploadTask(); @@ -740,6 +747,7 @@ void SendToPrinterDialog::on_cancel(wxCloseEvent &event) m_task_timer.reset(); } } +#endif this->EndModal(wxID_CANCEL); } @@ -784,6 +792,7 @@ void SendToPrinterDialog::on_ok(wxCommandEvent &event) } m_send_job->join(); } +#if !BBL_RELEASE_TO_PUBLIC if (m_file_sys) { m_file_sys->CancelUploadTask(); if (m_task_timer && m_task_timer->IsRunning()) { @@ -791,6 +800,7 @@ void SendToPrinterDialog::on_ok(wxCommandEvent &event) m_task_timer.reset(); } } +#endif m_is_canceled = true; wxCommandEvent* event = new wxCommandEvent(EVT_PRINT_JOB_CANCEL); wxQueueEvent(this, event); @@ -845,6 +855,7 @@ void SendToPrinterDialog::on_ok(wxCommandEvent &event) fs::path default_output_file_path = boost::filesystem::path(default_output_file.c_str()); file_name = default_output_file_path.filename().string(); }*/ +#if !BBL_RELEASE_TO_PUBLIC if (!obj_->is_lan_mode_printer()) { update_print_status_msg(wxEmptyString, false, false); if (m_file_sys) { @@ -852,7 +863,17 @@ void SendToPrinterDialog::on_ok(wxCommandEvent &event) m_plater->get_print_job_data(&print_data); std::string project_name = m_current_project_name.utf8_string() + ".3mf"; std::string _3mf_path = print_data._3mf_path.string(); - m_file_sys->SetUploadFile(_3mf_path, project_name, get_storage_selected()); + + std::string storage; + auto it = std::find_if(m_ability_list.begin(), m_ability_list.end(), [](const std::string& s) { + return s != EMMC_STORAGE; + }); + + if (it != m_ability_list.end()) + m_file_sys->SetUploadFile(_3mf_path, project_name, *it); + else { + BOOST_LOG_TRIVIAL(info) << "SendToPrinter::send job: The printer media capability set is incorrect."; + } m_file_sys->RequestUploadFile(); // time out @@ -876,6 +897,7 @@ void SendToPrinterDialog::on_ok(wxCommandEvent &event) m_task_timer->StartOnce(timeout_period); } } else { +#endif m_send_job = std::make_shared(m_status_bar, m_plater, m_printer_last_select); m_send_job->m_dev_ip = obj_->dev_ip; m_send_job->m_access_code = obj_->get_access_code(); @@ -909,7 +931,10 @@ void SendToPrinterDialog::on_ok(wxCommandEvent &event) } else { m_send_job->start(); } +#if !BBL_RELEASE_TO_PUBLIC } +#endif + BOOST_LOG_TRIVIAL(info) << "send_job: send print job"; } @@ -951,10 +976,10 @@ void SendToPrinterDialog::update_user_machine_list() void SendToPrinterDialog::on_refresh(wxCommandEvent &event) { BOOST_LOG_TRIVIAL(info) << "m_printer_last_select: on_refresh"; - /* show_status(PrintDialogStatus::PrintStatusRefreshingMachineList); - update_user_machine_list();*/ + show_status(PrintDialogStatus::PrintStatusRefreshingMachineList); + update_user_machine_list(); /*todo refresh*/ - if (m_file_sys) { m_file_sys->Retry(); } + /*if (m_file_sys) { m_file_sys->Retry(); }*/ } void SendToPrinterDialog::on_print_job_cancel(wxCommandEvent &evt) @@ -1101,12 +1126,16 @@ 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, true); +#if !BBL_RELEASE_TO_PUBLIC if (m_file_sys) m_file_sys.reset(); +#endif }else if (dev->get_selected_machine()->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, true); +#if !BBL_RELEASE_TO_PUBLIC if (m_file_sys) m_file_sys.reset(); +#endif } } else { @@ -1190,6 +1219,11 @@ void SendToPrinterDialog::update_show_status() } if (!m_is_in_sending_mode) { +#if BBL_RELEASE_PUPBLIC + show_status(PrintDialogStatus::PrintStatusReadingFinished); + return; + } +#else if (obj_->connection_type() == "lan") { show_status(PrintDialogStatus::PrintStatusReadingFinished); return; @@ -1201,6 +1235,8 @@ void SendToPrinterDialog::update_show_status() if ((m_waiting_enable && IsEnabled()) || (m_waiting_support && obj_->get_file_remote())) m_file_sys->Retry(); return; + } else { + m_file_sys->Stop(true); } } @@ -1269,7 +1305,7 @@ void SendToPrinterDialog::update_show_status() m_ability_list = fs->GetMediaAbilityList(); if (e.GetInt() == PrinterFileSystem::RequestMediaAbilityStatus::S_SUCCESS) { - update_storage_list(m_ability_list); + //update_storage_list(m_ability_list); show_status(PrintDialogStatus::PrintStatusReadingFinished); } else { show_status(PrintDialogStatus::PrintStatusPublicInitFailed); @@ -1281,7 +1317,9 @@ void SendToPrinterDialog::update_show_status() boost::shared_ptr fs(wfs.lock()); if (!fs) return; int progress = e.GetInt(); - m_status_bar->set_progress(10 + std::floor(progress * 0.9)); + 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(); @@ -1296,7 +1334,7 @@ void SendToPrinterDialog::update_show_status() boost::shared_ptr fs(wfs.lock()); if (!fs) return; fs->CancelUploadTask(false); - update_print_status_msg(_L("Upload file timeout, please check if the firmware version supports it."), false, true); + 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); @@ -1306,6 +1344,8 @@ void SendToPrinterDialog::update_show_status() 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()); @@ -1322,6 +1362,7 @@ void SendToPrinterDialog::update_show_status() m_file_sys->Start(); } } +#endif } bool SendToPrinterDialog::is_blocking_printing(MachineObject* obj_) @@ -1622,7 +1663,7 @@ 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()); wxGetApp().reset_to_active(); set_default(); update_user_machine_list(); @@ -1638,9 +1679,14 @@ bool SendToPrinterDialog::Show(bool show) Fit(); if (show) { CenterOnParent(); } - if (m_file_sys) { - show ? m_file_sys->Start() : m_file_sys->Stop(); +#if !BBL_RELEASE_TO_PUBLIC + if (m_file_sys && !show) { + m_file_sys->Stop(true); + m_waiting_enable = false; + m_waiting_support = false; + m_file_sys.reset(); } +#endif return DPIDialog::Show(show); }