From 3f3a3dd190b7b7b6c0fd84a45e2c71236c3460b2 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 11 Oct 2023 11:57:26 +0200 Subject: [PATCH] SPE-1954: Inform the user when loading/importing a project or a config file containing a post-processing script --- src/PrusaSlicer.cpp | 13 +++++++++++++ src/slic3r/GUI/MainFrame.cpp | 14 ++++++++++++++ src/slic3r/GUI/MsgDialog.hpp | 2 ++ src/slic3r/GUI/Plater.cpp | 15 +++++++++++++++ 4 files changed, 44 insertions(+) diff --git a/src/PrusaSlicer.cpp b/src/PrusaSlicer.cpp index f3441a8d62..1204d00356 100644 --- a/src/PrusaSlicer.cpp +++ b/src/PrusaSlicer.cpp @@ -276,6 +276,19 @@ int CLI::run(int argc, char **argv) } } + const auto* post_process = m_print_config.opt("post_process"); + if (post_process != nullptr && !post_process->values.empty()) { + boost::nowide::cout << "\nA post-processing script has been detected in the config data:\n\n"; + for (const auto& s : post_process->values) { + boost::nowide::cout << "> " << s << "\n"; + } + boost::nowide::cout << "\nContinue(Y/N) ? "; + char in; + boost::nowide::cin >> in; + if (in != 'Y' && in != 'y') + return 0; + } + // Apply command line options to a more specific DynamicPrintConfig which provides normalize() // (command line options override --load files) m_print_config.apply(m_extra_config, true); diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 991690a60b..cdf490d8f2 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -1926,6 +1926,20 @@ void MainFrame::load_config_file() if (dlg.ShowModal() == wxID_OK) file = dlg.GetPath(); if (! file.IsEmpty() && this->load_config_file(file.ToUTF8().data())) { + DynamicPrintConfig config = wxGetApp().preset_bundle->full_config(); + const auto* post_process = config.opt("post_process"); + if (post_process != nullptr && !post_process->values.empty()) { + const wxString msg = _L("The selected config file contains a post-processing script") + "\n" + _L("Please review the script carefully before running it."); + wxString text; + for (const auto& s : post_process->values) { + text += s; + } + + InfoDialog msg_dlg(nullptr, msg, text, true, wxOK | wxICON_WARNING); + msg_dlg.set_caption(wxString(SLIC3R_APP_NAME " - ") + _L("Attention!")); + msg_dlg.ShowModal(); + } + wxGetApp().app_config->update_config_dir(get_dir_name(file)); m_last_config = file; } diff --git a/src/slic3r/GUI/MsgDialog.hpp b/src/slic3r/GUI/MsgDialog.hpp index ae0e7f9fec..cde5928425 100644 --- a/src/slic3r/GUI/MsgDialog.hpp +++ b/src/slic3r/GUI/MsgDialog.hpp @@ -320,6 +320,8 @@ public: InfoDialog&operator=(const InfoDialog&) = delete; virtual ~InfoDialog() = default; + void set_caption(const wxString& caption) { this->SetTitle(caption); } + private: wxString msg; }; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 65933ee4f7..1c9c8162c6 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -2574,6 +2574,21 @@ std::vector Plater::priv::load_files(const std::vector& input_ if (load_config) { if (!config.empty()) { + const auto* post_process = config.opt("post_process"); + if (post_process != nullptr && !post_process->values.empty()) { + wxString msg = type_3mf ? _L("The selected 3MF file contains a post-processing script") : + _L("The selected AMF file contains a post-processing script"); + msg += "\n" + _L("Please review the script carefully before running it."); + wxString text; + for (const auto& s : post_process->values) { + text += s; + } + + InfoDialog msg_dlg(nullptr, msg, text, true, wxOK | wxICON_WARNING); + msg_dlg.set_caption(wxString(SLIC3R_APP_NAME " - ") + _L("Attention!")); + msg_dlg.ShowModal(); + } + Preset::normalize(config); PresetBundle* preset_bundle = wxGetApp().preset_bundle; preset_bundle->load_config_model(filename.string(), std::move(config));