From d8e39519f2d8d7c5eeed190cd0276471a2eedec2 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Tue, 23 May 2023 11:13:06 +0200 Subject: [PATCH] Concider projects with .zip extension that are 3mf projects as it would have .3mf extension. --- src/libslic3r/Model.cpp | 4 ++-- src/slic3r/GUI/Plater.cpp | 14 +++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index 10ef9127c..9fd24c377 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -121,7 +121,7 @@ Model Model::read_from_file(const std::string& input_file, DynamicPrintConfig* c result = load_step(input_file.c_str(), &model); else if (boost::algorithm::iends_with(input_file, ".amf") || boost::algorithm::iends_with(input_file, ".amf.xml")) result = load_amf(input_file.c_str(), config, config_substitutions, &model, options & LoadAttribute::CheckVersion); - else if (boost::algorithm::iends_with(input_file, ".3mf")) + else if (boost::algorithm::iends_with(input_file, ".3mf") || boost::algorithm::iends_with(input_file, ".zip")) //FIXME options & LoadAttribute::CheckVersion ? result = load_3mf(input_file.c_str(), *config, *config_substitutions, &model, false); else @@ -155,7 +155,7 @@ Model Model::read_from_archive(const std::string& input_file, DynamicPrintConfig Model model; bool result = false; - if (boost::algorithm::iends_with(input_file, ".3mf")) + if (boost::algorithm::iends_with(input_file, ".3mf") || boost::algorithm::iends_with(input_file, ".zip")) result = load_3mf(input_file.c_str(), *config, *config_substitutions, &model, options & LoadAttribute::CheckVersion); else if (boost::algorithm::iends_with(input_file, ".zip.amf")) result = load_amf(input_file.c_str(), config, config_substitutions, &model, options & LoadAttribute::CheckVersion); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 9574f6ea6..6e6b72f9a 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1702,6 +1702,7 @@ struct Plater::priv static const std::regex pattern_zip_amf; static const std::regex pattern_any_amf; static const std::regex pattern_prusa; + static const std::regex pattern_zip; priv(Plater *q, MainFrame *main_frame); ~priv(); @@ -1998,6 +1999,7 @@ const std::regex Plater::priv::pattern_3mf(".*3mf", std::regex::icase); const std::regex Plater::priv::pattern_zip_amf(".*[.]zip[.]amf", std::regex::icase); const std::regex Plater::priv::pattern_any_amf(".*[.](amf|amf[.]xml|zip[.]amf)", std::regex::icase); const std::regex Plater::priv::pattern_prusa(".*prusa", std::regex::icase); +const std::regex Plater::priv::pattern_zip(".*zip", std::regex::icase); Plater::priv::priv(Plater *q, MainFrame *main_frame) : q(q) @@ -2423,7 +2425,7 @@ void Plater::check_selected_presets_visibility(PrinterTechnology loaded_printer_ std::vector Plater::priv::load_files(const std::vector& input_files, bool load_model, bool load_config, bool imperial_units/* = false*/) { - if (input_files.empty()) { return std::vector(); } + if (input_files.empty()) { return std::vector(); } auto *nozzle_dmrs = config->opt("nozzle_diameter"); @@ -2484,7 +2486,7 @@ std::vector Plater::priv::load_files(const std::vector& input_ progress_dlg->Fit(); } - const bool type_3mf = std::regex_match(path.string(), pattern_3mf); + const bool type_3mf = std::regex_match(path.string(), pattern_3mf) || std::regex_match(path.string(), pattern_zip); const bool type_zip_amf = !type_3mf && std::regex_match(path.string(), pattern_zip_amf); const bool type_any_amf = !type_3mf && std::regex_match(path.string(), pattern_any_amf); const bool type_prusa = std::regex_match(path.string(), pattern_prusa); @@ -5935,7 +5937,13 @@ bool Plater::load_files(const wxArrayString& filenames, bool delete_after_load/* // searches for project files for (std::vector::const_reverse_iterator it = paths.rbegin(); it != paths.rend(); ++it) { std::string filename = (*it).filename().string(); - if (boost::algorithm::iends_with(filename, ".3mf") || boost::algorithm::iends_with(filename, ".amf")) { + + bool handle_as_project = (boost::algorithm::iends_with(filename, ".3mf") || boost::algorithm::iends_with(filename, ".amf")); + if (boost::algorithm::iends_with(filename, ".zip") && is_project_3mf(it->string())) { + BOOST_LOG_TRIVIAL(warning) << "File with .zip extension is 3mf project, opening as it would have .3mf extension: " << *it; + handle_as_project = true; + } + if (handle_as_project) { ProjectDropDialog::LoadType load_type = ProjectDropDialog::LoadType::Unknown; { if ((boost::algorithm::iends_with(filename, ".3mf") && !is_project_3mf(it->string())) ||