From 8431595db8d162c6face433dd12d8bd5eef9a77e Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Fri, 12 May 2023 10:20:09 +0200 Subject: [PATCH] Allow multiple warnings to be emitted from Print::validate --- src/libslic3r/Print.cpp | 6 +++--- src/libslic3r/Print.hpp | 2 +- src/libslic3r/PrintBase.hpp | 2 +- src/libslic3r/SLAPrint.cpp | 2 +- src/libslic3r/SLAPrint.hpp | 2 +- src/slic3r/GUI/BackgroundSlicingProcess.cpp | 4 ++-- src/slic3r/GUI/BackgroundSlicingProcess.hpp | 2 +- src/slic3r/GUI/Plater.cpp | 20 ++++++++++---------- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 458671e5b..68dcb2f03 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -468,7 +468,7 @@ static inline bool sequential_print_vertical_clearance_valid(const Print &print) boost::regex regex_g92e0 { "^[ \\t]*[gG]92[ \\t]*[eE](0(\\.0*)?|\\.0+)[ \\t]*(;.*)?$" }; // Precondition: Print::validate() requires the Print::apply() to be called its invocation. -std::string Print::validate(std::string* warning) const +std::string Print::validate(std::vector* warnings) const { std::vector extruders = this->extruders(); @@ -691,12 +691,12 @@ std::string Print::validate(std::string* warning) const // Do we have custom support data that would not be used? // Notify the user in that case. - if (! object->has_support() && warning) { + if (! object->has_support() && warnings) { for (const ModelVolume* mv : object->model_object()->volumes) { bool has_enforcers = mv->is_support_enforcer() || (mv->is_model_part() && mv->supported_facets.has_facets(*mv, EnforcerBlockerType::ENFORCER)); if (has_enforcers) { - *warning = "_SUPPORTS_OFF"; + warnings->emplace_back("_SUPPORTS_OFF"); break; } } diff --git a/src/libslic3r/Print.hpp b/src/libslic3r/Print.hpp index c96b0ca9a..5c42709b1 100644 --- a/src/libslic3r/Print.hpp +++ b/src/libslic3r/Print.hpp @@ -547,7 +547,7 @@ public: bool has_brim() const; // Returns an empty string if valid, otherwise returns an error message. - std::string validate(std::string* warning = nullptr) const override; + std::string validate(std::vector* warnings = nullptr) const override; double skirt_first_layer_height() const; Flow brim_flow() const; Flow skirt_flow() const; diff --git a/src/libslic3r/PrintBase.hpp b/src/libslic3r/PrintBase.hpp index 4c009cac8..9c95255d4 100644 --- a/src/libslic3r/PrintBase.hpp +++ b/src/libslic3r/PrintBase.hpp @@ -418,7 +418,7 @@ public: virtual std::vector print_object_ids() const = 0; // Validate the print, return empty string if valid, return error if process() cannot (or should not) be started. - virtual std::string validate(std::string* warning = nullptr) const { return std::string(); } + virtual std::string validate(std::vector* warnings = nullptr) const { return std::string(); } enum ApplyStatus { // No change after the Print::apply() call. diff --git a/src/libslic3r/SLAPrint.cpp b/src/libslic3r/SLAPrint.cpp index c4947851b..1598cd46b 100644 --- a/src/libslic3r/SLAPrint.cpp +++ b/src/libslic3r/SLAPrint.cpp @@ -534,7 +534,7 @@ std::string SLAPrint::output_filename(const std::string &filename_base) const return this->PrintBase::output_filename(m_print_config.output_filename_format.value, ".sl1", filename_base, &config); } -std::string SLAPrint::validate(std::string*) const +std::string SLAPrint::validate(std::vector*) const { for(SLAPrintObject * po : m_objects) { diff --git a/src/libslic3r/SLAPrint.hpp b/src/libslic3r/SLAPrint.hpp index 126941d82..96ac6f40f 100644 --- a/src/libslic3r/SLAPrint.hpp +++ b/src/libslic3r/SLAPrint.hpp @@ -494,7 +494,7 @@ public: const SLAPrintStatistics& print_statistics() const { return m_print_statistics; } - std::string validate(std::string* warning = nullptr) const override; + std::string validate(std::vector* warnings = nullptr) const override; // An aggregation of SliceRecord-s from all the print objects for each // occupied layer. Slice record levels dont have to match exactly. diff --git a/src/slic3r/GUI/BackgroundSlicingProcess.cpp b/src/slic3r/GUI/BackgroundSlicingProcess.cpp index 763ce5174..8067a6e39 100644 --- a/src/slic3r/GUI/BackgroundSlicingProcess.cpp +++ b/src/slic3r/GUI/BackgroundSlicingProcess.cpp @@ -549,10 +549,10 @@ bool BackgroundSlicingProcess::empty() const return m_print->empty(); } -std::string BackgroundSlicingProcess::validate(std::string* warning) +std::string BackgroundSlicingProcess::validate(std::vector* warnings) { assert(m_print != nullptr); - return m_print->validate(warning); + return m_print->validate(warnings); } // Apply config over the print. Returns false, if the new config values caused any of the already diff --git a/src/slic3r/GUI/BackgroundSlicingProcess.hpp b/src/slic3r/GUI/BackgroundSlicingProcess.hpp index 00a3ab6d0..2b049a4f1 100644 --- a/src/slic3r/GUI/BackgroundSlicingProcess.hpp +++ b/src/slic3r/GUI/BackgroundSlicingProcess.hpp @@ -132,7 +132,7 @@ public: bool empty() const; // Validate the print. Returns an empty string if valid, returns an error message if invalid. // Call validate before calling start(). - std::string validate(std::string* warning = nullptr); + std::string validate(std::vector* warnings = nullptr); // Set the export path of the G-code. // Once the path is set, the G-code diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 84582f895..cbf64aadd 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1849,7 +1849,7 @@ struct Plater::priv void suppress_snapshots() { m_prevent_snapshots++; } void allow_snapshots() { m_prevent_snapshots--; } - void process_validation_warning(const std::string& warning) const; + void process_validation_warning(const std::vector& warning) const; bool background_processing_enabled() const { return this->get_config_bool("background_processing"); } void update_print_volume_state(); @@ -3198,12 +3198,12 @@ void Plater::priv::update_print_volume_state() this->q->model().update_print_volume_state(this->bed.build_volume()); } -void Plater::priv::process_validation_warning(const std::string& warning) const +void Plater::priv::process_validation_warning(const std::vector& warnings) const { - if (warning.empty()) + if (warnings.empty()) notification_manager->close_notification_of_type(NotificationType::ValidateWarning); else { - std::string text = warning; + std::string text = warnings.front(); std::string hypertext = ""; std::function action_fn = [](wxEvtHandler*){ return false; }; @@ -3279,8 +3279,8 @@ unsigned int Plater::priv::update_background_process(bool force_validation, bool // The delayed error message is no more valid. delayed_error_message.clear(); // The state of the Print changed, and it is non-zero. Let's validate it and give the user feedback on errors. - std::string warning; - std::string err = background_process.validate(&warning); + std::vector warnings; + std::string err = background_process.validate(&warnings); if (err.empty()) { notification_manager->set_all_slicing_errors_gray(true); notification_manager->close_notification_of_type(NotificationType::ValidateError); @@ -3289,7 +3289,7 @@ unsigned int Plater::priv::update_background_process(bool force_validation, bool // Pass a warning from validation and either show a notification, // or hide the old one. - process_validation_warning(warning); + process_validation_warning(warnings); if (printer_technology == ptFFF) { GLCanvas3D* canvas = view3D->get_canvas3d(); canvas->reset_sequential_print_clearance(); @@ -3328,8 +3328,8 @@ unsigned int Plater::priv::update_background_process(bool force_validation, bool canvas->request_extra_frame(); } } - std::string warning; - std::string err = background_process.validate(&warning); + std::vector warnings; + std::string err = background_process.validate(&warnings); if (!err.empty()) return return_state; } @@ -3342,7 +3342,7 @@ unsigned int Plater::priv::update_background_process(bool force_validation, bool //actualizate warnings if (invalidated != Print::APPLY_STATUS_UNCHANGED || background_process.empty()) { if (background_process.empty()) - process_validation_warning(std::string()); + process_validation_warning(std::vector()); actualize_slicing_warnings(*this->background_process.current_print()); actualize_object_warnings(*this->background_process.current_print()); show_warning_dialog = false;