From 7dabcf0646865ab597108538430f84f053fe7b9b Mon Sep 17 00:00:00 2001 From: David Kocik Date: Mon, 20 Sep 2021 11:22:00 +0200 Subject: [PATCH] Slicing progress notification cancel button hides notification if process is idle. --- src/slic3r/GUI/NotificationManager.cpp | 6 ++++-- src/slic3r/GUI/NotificationManager.hpp | 9 +++++---- src/slic3r/GUI/Plater.cpp | 9 +++++++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/slic3r/GUI/NotificationManager.cpp b/src/slic3r/GUI/NotificationManager.cpp index 0841efcb0..bf43b7645 100644 --- a/src/slic3r/GUI/NotificationManager.cpp +++ b/src/slic3r/GUI/NotificationManager.cpp @@ -1176,7 +1176,9 @@ void NotificationManager::SlicingProgressNotification::set_sidebar_collapsed(boo void NotificationManager::SlicingProgressNotification::on_cancel_button() { if (m_cancel_callback){ - m_cancel_callback(); + if (!m_cancel_callback()) { + set_progress_state(SlicingProgressState::SP_NO_SLICING); + } } } int NotificationManager::SlicingProgressNotification::get_duration() @@ -1681,7 +1683,7 @@ void NotificationManager::upload_job_notification_show_error(int id, const std:: } } -void NotificationManager::init_slicing_progress_notification(std::function cancel_callback) +void NotificationManager::init_slicing_progress_notification(std::function cancel_callback) { for (std::unique_ptr& notification : m_pop_notifications) { if (notification->get_type() == NotificationType::SlicingProgress) { diff --git a/src/slic3r/GUI/NotificationManager.hpp b/src/slic3r/GUI/NotificationManager.hpp index 76dc9a688..ee510b112 100644 --- a/src/slic3r/GUI/NotificationManager.hpp +++ b/src/slic3r/GUI/NotificationManager.hpp @@ -188,7 +188,7 @@ public: void upload_job_notification_show_canceled(int id, const std::string& filename, const std::string& host); void upload_job_notification_show_error(int id, const std::string& filename, const std::string& host); // slicing progress - void init_slicing_progress_notification(std::function cancel_callback); + void init_slicing_progress_notification(std::function cancel_callback); // percentage negative = canceled, <0-1) = progress, 1 = completed void set_slicing_progress_percentage(const std::string& text, float percentage); // hides slicing progress notification imidietly @@ -496,7 +496,7 @@ private: SP_CANCELLED, // fades after 10 seconds, simple message SP_COMPLETED // Has export hyperlink and print info, fades after 20 sec if sidebar is shown, otherwise no fade out }; - SlicingProgressNotification(const NotificationData& n, NotificationIDProvider& id_provider, wxEvtHandler* evt_handler, std::function callback) + SlicingProgressNotification(const NotificationData& n, NotificationIDProvider& id_provider, wxEvtHandler* evt_handler, std::function callback) : ProgressBarNotification(n, id_provider, evt_handler) , m_cancel_callback(callback) { @@ -507,7 +507,7 @@ private: // sets text of notification - call after setting progress state void set_status_text(const std::string& text); // sets cancel button callback - void set_cancel_callback(std::function callback) { m_cancel_callback = callback; } + void set_cancel_callback(std::function callback) { m_cancel_callback = callback; } bool has_cancel_callback() const { return m_cancel_callback != nullptr; } // sets SlicingProgressState, negative percent means canceled void set_progress_state(float percent); @@ -545,7 +545,8 @@ private: const float win_pos_x, const float win_pos_y) override; void on_cancel_button(); int get_duration() override; - std::function m_cancel_callback; + // if returns false, process was already canceled + std::function m_cancel_callback; SlicingProgressState m_sp_state { SlicingProgressState::SP_PROGRESS }; bool m_has_print_info { false }; std::string m_print_info; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index c7728e551..9dd08b6fe 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -4019,12 +4019,14 @@ void Plater::priv::on_process_completed(SlicingProcessCompletedEvent &evt) if (evt.error()) { std::pair message = evt.format_error_message(); if (evt.critical_error()) { - if (q->m_tracking_popup_menu) + if (q->m_tracking_popup_menu) { // We don't want to pop-up a message box when tracking a pop-up menu. // We postpone the error message instead. q->m_tracking_popup_menu_error_message = message.first; - else + } else { show_error(q, message.first, message.second); + notification_manager->set_slicing_progress_hidden(); + } } else notification_manager->push_slicing_error_notification(message.first); // this->statusbar()->set_status_text(from_u8(message.first)); @@ -4252,7 +4254,10 @@ void Plater::priv::init_notification_manager() notification_manager->init(); auto cancel_callback = [this]() { + if (this->background_process.idle()) + return false; this->background_process.stop(); + return true; }; notification_manager->init_slicing_progress_notification(cancel_callback); notification_manager->set_fff(printer_technology == ptFFF);