From 1f206dc8892a1b9bfef289089c02915c6a093a7f Mon Sep 17 00:00:00 2001 From: alves Date: Wed, 4 Feb 2026 16:35:07 +0800 Subject: [PATCH] feature add download file for wcp logic. --- src/slic3r/GUI/DownloadManager.cpp | 4 --- src/slic3r/GUI/GenericDownloadDialog.cpp | 5 +-- src/slic3r/GUI/MainFrame.cpp | 40 +++++++++++++++++++----- src/slic3r/GUI/MainFrame.hpp | 6 +++- src/slic3r/GUI/SSWCP.cpp | 17 ++-------- 5 files changed, 42 insertions(+), 30 deletions(-) diff --git a/src/slic3r/GUI/DownloadManager.cpp b/src/slic3r/GUI/DownloadManager.cpp index 568776afa8..3e203a960d 100644 --- a/src/slic3r/GUI/DownloadManager.cpp +++ b/src/slic3r/GUI/DownloadManager.cpp @@ -134,7 +134,6 @@ size_t DownloadManager::start_internal_download(const std::string& file_url, boost::filesystem::path dest_path_obj(dest_path); - // Check if dest_path is a directory or a complete file path boost::filesystem::path dest_file_path; if (boost::filesystem::is_directory(dest_path_obj) || dest_path_obj.filename().empty()) { // dest_path is a directory, need to append file_name @@ -148,11 +147,8 @@ size_t DownloadManager::start_internal_download(const std::string& file_url, dest_file_path = dest_path_obj; } - // Create parent directory if it doesn't exist boost::filesystem::create_directories(dest_file_path.parent_path()); - // Generate unique file path if file already exists - // dest_file_path should now be the complete absolute path: directory + filename std::string unique_dest_path = get_unique_file_path(dest_file_path); auto task = std::make_shared(task_id, diff --git a/src/slic3r/GUI/GenericDownloadDialog.cpp b/src/slic3r/GUI/GenericDownloadDialog.cpp index 4607027942..cc98f5b451 100644 --- a/src/slic3r/GUI/GenericDownloadDialog.cpp +++ b/src/slic3r/GUI/GenericDownloadDialog.cpp @@ -383,8 +383,9 @@ void GenericDownloadDialog::show_progress_page() void GenericDownloadDialog::show_complete_page() { - m_simplebook_status->SetSelection(1); - m_status_bar->hide_cancel_button(); + //m_simplebook_status->SetSelection(1); + //m_status_bar->hide_cancel_button(); + EndModal(wxID_OK); } void GenericDownloadDialog::show_error_page(const std::string& error_msg) diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index ca732fb3a6..a2771f4b5c 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -2252,14 +2252,6 @@ static wxMenu* generate_help_menu() append_menu_item( helpMenu, wxID_ANY, _L("Check for Update"), _L("Check for Update"), [](wxCommandEvent&) { - std::string fileUrl = "https://public.resource.snapmaker.com/model/public/3mf/test_for_download.3mf"; - //std::string fileUrl = "https://github.com/Snapmaker/OrcaSlicer/releases/download/v2.2.1/Snapmaker_Orca_Windows_Installer_V2.2.1.exe"; - std::string filename = "test_for_download.3mf"; - std::string downloadPath = "C:/tmp"; - - GenericDownloadDialog dlg(_L("importing the model"), fileUrl, filename, downloadPath); - dlg.ShowModal(); - return; wxGetApp().check_new_version_sf(true, UPDATE_BUSER); }, "", nullptr, []() { return true; @@ -4015,6 +4007,38 @@ void MainFrame::RunScript(wxString js) m_webview->RunScript(js); } +void MainFrame::downloadOpenProject(const std::string& fileUrl, const std::string& fileName, std::string completeFilePath) +{ + // std::string fileUrl = "https://public.resource.snapmaker.com/model/public/3mf/test_for_download.3mf"; + // std::string filename = "test_for_download.3mf"; + + GenericDownloadDialog dlg(_L("downloading the model"), fileUrl, fileName, completeFilePath); + dlg.ShowModal(); + + if (completeFilePath.empty()) { + auto downloadPath = wxGetApp().app_config->get("download_path"); + completeFilePath = downloadPath + "/" + fileName; + } + if (!boost::filesystem::exists(completeFilePath)) + { + BOOST_LOG_TRIVIAL(warning) << boost::format("the file '%1%' not exists") % completeFilePath; + return; + } + + // Auto-open project if it's a .3mf file + boost::filesystem::path path(completeFilePath); + std::string extension = boost::algorithm::to_lower_copy(path.extension().string()); + if (extension == ".3mf") { + BOOST_LOG_TRIVIAL(info) << boost::format("GenericDownloadDialog: Auto-opening project file '%1%'") % completeFilePath; + wxString wx_file_path = wxString::FromUTF8(completeFilePath.c_str()); + if (wxGetApp().can_load_project() && wxGetApp().mainframe && wxGetApp().mainframe->plater()) { + wxGetApp().mainframe->plater()->load_project(wx_file_path); + } + } + + +} + void MainFrame::technology_changed() { // update menu titles diff --git a/src/slic3r/GUI/MainFrame.hpp b/src/slic3r/GUI/MainFrame.hpp index 095f1f7ea1..661fe3ca4b 100644 --- a/src/slic3r/GUI/MainFrame.hpp +++ b/src/slic3r/GUI/MainFrame.hpp @@ -348,7 +348,11 @@ public: void load_printer_url(); bool is_printer_view() const; void refresh_plugin_tips(); - void RunScript(wxString js); + void RunScript(wxString js); + + void downloadOpenProject(const std::string& fileUrl, + const std::string& fileName, + std::string completeFilePath = ""); //SoftFever void show_device(bool bBBLPrinter); diff --git a/src/slic3r/GUI/SSWCP.cpp b/src/slic3r/GUI/SSWCP.cpp index e8aac1accb..3e7f33c33e 100644 --- a/src/slic3r/GUI/SSWCP.cpp +++ b/src/slic3r/GUI/SSWCP.cpp @@ -3187,14 +3187,10 @@ void SSWCP_MachineOption_Instance::sw_GetFileFilamentMapping() response["thumbnails"] = thumbnails; - - // file name response["filename"] = SSWCP::get_display_filename(); response["filepath"] = SSWCP::get_active_filename(); - - m_res_data = response; send_to_js(); finish_job(); @@ -4404,18 +4400,9 @@ void SSWCP_UserLogin_Instance::sw_DownloadFile() handle_general_fail(-1, "Download Manager not available"); return; } + + wxGetApp().mainframe->downloadOpenProject(fileUrl, fileName, ""); - size_t task_id = download_mgr->start_wcp_download(fileUrl, - fileName, - shared_from_this(), - false); // use_original_event_id = false (sw_DownloadFile: finish immediately) - - // Return task ID to Flutter - json response; - response["task_id"] = task_id; - response["file_name"] = fileName; - response["file_url"] = fileUrl; - m_res_data = response; m_status = 0; m_msg = "Download started"; send_to_js();