From 9b69440ae093057a7d0248e094fbbd4463e497e8 Mon Sep 17 00:00:00 2001 From: "zhou.xu" Date: Wed, 18 Sep 2024 14:29:06 +0800 Subject: [PATCH] ENH:support multiple svg import jira: none Change-Id: I1afe671aec6c75cebcc77902b172557ee967475f --- src/libslic3r/Model.cpp | 2 -- src/slic3r/GUI/Plater.cpp | 60 +++++++++++++++++++++++++++++++++++---- src/slic3r/GUI/Plater.hpp | 1 + 3 files changed, 55 insertions(+), 8 deletions(-) diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index dbcd8e976..a5fea3891 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -266,8 +266,6 @@ Model Model::read_from_file(const std::string& input_file, DynamicPrintConfig* c }*/ } } - else if (boost::algorithm::iends_with(input_file, ".svg")) - result = load_svg(input_file.c_str(), &model, message); //BBS: remove the old .amf.xml files //else if (boost::algorithm::iends_with(input_file, ".amf") || boost::algorithm::iends_with(input_file, ".amf.xml")) else if (boost::algorithm::iends_with(input_file, ".amf")) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 41dcc3475..a81b846a0 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -10438,16 +10438,46 @@ bool Plater::load_svg(const wxArrayString &filenames, bool from_toolbar_or_file_ const wxString &filename = filenames.Last(); const wxString file_extension = filename.substr(filename.length() - 4); if (file_extension.CmpNoCase(".svg") == 0) { - // BBS: GUI refactor: move sidebar to the left - /* const wxPoint offset = GetPosition() + p->current_panel->GetPosition(); - Vec2d mouse_position(x - offset.x, y - offset.y);*/ - // Scale for retina displays - // canvas->apply_retina_scale(mouse_position); return emboss_svg(filename, from_toolbar_or_file_menu); } } + else { + const auto loading = _L("Loading") + dots; + ProgressDialog dlg(loading, "", 100, wxGetApp().mainframe, wxPD_AUTO_HIDE | wxPD_CAN_ABORT | wxPD_APP_MODAL); + wxBusyCursor busy; + for (size_t i = 0; i < filenames.size(); i++) { + if (i > 0) { + deselect_all(); + } + wxArrayString temp_filenames; + temp_filenames.push_back(filenames[i]); + const auto dlg_info = _L("Loading file") + ": " + filenames[i]; + int progress_percent = static_cast(100.0f * static_cast(i) / static_cast(filenames.size())); + dlg.Update(progress_percent, dlg_info); + load_svg(temp_filenames,true); + get_ui_job_worker().wait_for_current_job(); + } + return true; + } return false; } + +bool Plater::load_same_type_files(const wxArrayString &filenames) { + if (filenames.size() <= 1) { return true; } + else { + const wxString &filename = filenames.front(); + boost::filesystem::path path(filename.ToStdWstring()); + auto extension =path.extension(); + for (size_t i = 1; i < filenames.size(); i++) { + boost::filesystem::path temp(filenames[i].ToStdWstring()); + auto temp_extension = temp.extension(); + if (extension != temp_extension) { + return false; + } + } + return true; + } +} //BBS: remove GCodeViewer as seperate APP logic bool Plater::load_files(const wxArrayString& filenames) { @@ -10456,7 +10486,12 @@ bool Plater::load_files(const wxArrayString& filenames) std::vector normal_paths; std::vector gcode_paths; - + if (!load_same_type_files(filenames)) { + MessageDialog msg(wxGetApp().mainframe, _L("Please import multiple files with the same suffix."), _L("Warning"), wxYES | wxICON_WARNING); + if (msg.ShowModal() == wxID_YES) { + return true; + } + } if (load_svg(filenames)) { return true; } @@ -10724,6 +10759,19 @@ void Plater::add_file() case LoadFilesType::MultipleOther: { Plater::TakeSnapshot snapshot(this, snapshot_label); + wxArrayString filenames; + for (auto path : paths) { + filenames.push_back(path.wstring()); + } + if (!load_same_type_files(filenames)) { + MessageDialog msg(wxGetApp().mainframe, _L("Please import multiple files with the same suffix."), _L("Warning"), wxYES | wxICON_WARNING); + if (msg.ShowModal() == wxID_YES) { + return; + } + } + if (boost::iends_with(paths[0].string(), ".svg")&& load_svg(filenames)) { + return; + } if (!load_files(paths, LoadStrategy::LoadModel, true).empty()) { if (get_project_name() == _L("Untitled") && paths.size() > 0) { p->set_project_filename(wxString::FromUTF8(paths[0].string())); diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index a2a96ce42..92183fdfa 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -290,6 +290,7 @@ public: // to be called on drag and drop bool emboss_svg(const wxString &svg_file, bool from_toolbar_or_file_menu = false); bool load_svg(const wxArrayString &filenames, bool from_toolbar_or_file_menu = false); + bool load_same_type_files(const wxArrayString &filenames); bool load_files(const wxArrayString& filenames); const wxString& get_last_loaded_gcode() const { return m_last_loaded_gcode; }