From a7ec66c29491aa4f56f3ec0bb542038caf7c3ec2 Mon Sep 17 00:00:00 2001 From: "lane.wei" Date: Fri, 16 Jun 2023 09:25:51 +0800 Subject: [PATCH] FIX: fix a slicing state not correct issue in some corner case[Studio-2600] add a new object in other plate when slicing a plate it will stop the background slicing process and it should also send a complete event Change-Id: Ie7cbcb5a97251a002b7448eb8a9c5bbde1680956 (cherry picked from commit 710a2b273424d59313d7053f0f2c2b54b0c849c0) --- src/slic3r/GUI/BackgroundSlicingProcess.cpp | 6 ++++++ src/slic3r/GUI/BackgroundSlicingProcess.hpp | 2 ++ src/slic3r/GUI/Plater.cpp | 20 ++++++++++++-------- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/slic3r/GUI/BackgroundSlicingProcess.cpp b/src/slic3r/GUI/BackgroundSlicingProcess.cpp index 5d20d5feac..d8e824a857 100644 --- a/src/slic3r/GUI/BackgroundSlicingProcess.cpp +++ b/src/slic3r/GUI/BackgroundSlicingProcess.cpp @@ -317,6 +317,8 @@ void BackgroundSlicingProcess::thread_proc() break; // Process the background slicing task. m_state = STATE_RUNNING; + //BBS: internal cancel + m_internal_cancelled = false; lck.unlock(); std::exception_ptr exception; #ifdef _WIN32 @@ -337,6 +339,10 @@ void BackgroundSlicingProcess::thread_proc() BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": send SlicingProcessCompletedEvent to main, status %1%")%evt.status(); wxQueueEvent(GUI::wxGetApp().mainframe->m_plater, evt.Clone()); } + else { + //BBS: internal cancel + m_internal_cancelled = true; + } m_print->restart(); lck.unlock(); // Let the UI thread wake up if it is waiting for the background task to finish. diff --git a/src/slic3r/GUI/BackgroundSlicingProcess.hpp b/src/slic3r/GUI/BackgroundSlicingProcess.hpp index 3222aece7c..7d3ae23970 100644 --- a/src/slic3r/GUI/BackgroundSlicingProcess.hpp +++ b/src/slic3r/GUI/BackgroundSlicingProcess.hpp @@ -184,6 +184,7 @@ public: //BBS: improve the finished logic, also judge the m_gcode_result //bool finished() const { return m_print->finished(); } bool finished() const { return m_print->finished() && !m_gcode_result->moves.empty(); } + bool is_internal_cancelled() { return m_internal_cancelled; } //BBS: add Plater to friend class //need to call stop_internal in ui thread @@ -274,6 +275,7 @@ private: //BBS: partplate related GUI::PartPlate* m_current_plate; PrinterTechnology m_printer_tech = ptUnknown; + bool m_internal_cancelled = false; PrintState m_step_state; bool set_step_started(BackgroundSlicingProcessStep step); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 3b39d2ccf3..3b984eb340 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -4536,14 +4536,18 @@ unsigned int Plater::priv::update_background_process(bool force_validation, bool process_completed_with_error = -1; } - if (invalidated != Print::APPLY_STATUS_UNCHANGED && was_running && ! this->background_process.running() && - (return_state & UPDATE_BACKGROUND_PROCESS_RESTART) == 0) { - // The background processing was killed and it will not be restarted. - // Post the "canceled" callback message, so that it will be processed after any possible pending status bar update messages. - SlicingProcessCompletedEvent evt(EVT_PROCESS_COMPLETED, 0, - SlicingProcessCompletedEvent::Cancelled, nullptr); - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" %1%, post an EVT_PROCESS_COMPLETED to main, status %2%")%__LINE__ %evt.status(); - wxQueueEvent(q, evt.Clone()); + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", Line %1%: was_running = %2%, running %3%, invalidated=%4%, return_state=%5%, internal_cancel=%6%") + % __LINE__ % was_running % this->background_process.running() % invalidated % return_state % this->background_process.is_internal_cancelled(); + if (was_running && ! this->background_process.running() && (return_state & UPDATE_BACKGROUND_PROCESS_RESTART) == 0) { + if (invalidated != Print::APPLY_STATUS_UNCHANGED || this->background_process.is_internal_cancelled()) + { + // The background processing was killed and it will not be restarted. + // Post the "canceled" callback message, so that it will be processed after any possible pending status bar update messages. + SlicingProcessCompletedEvent evt(EVT_PROCESS_COMPLETED, 0, + SlicingProcessCompletedEvent::Cancelled, nullptr); + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" %1%, post an EVT_PROCESS_COMPLETED to main, status %2%")%__LINE__ %evt.status(); + wxQueueEvent(q, evt.Clone()); + } } if ((return_state & UPDATE_BACKGROUND_PROCESS_INVALID) != 0)