diff --git a/src/slic3r/GUI/BackgroundSlicingProcess.cpp b/src/slic3r/GUI/BackgroundSlicingProcess.cpp index 5d20d5fea..d8e824a85 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 3222aece7..7d3ae2397 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 3b39d2ccf..3b984eb34 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)