From 6f527fd6aa3484323aa97c1d6aac10cd5a8cee3b Mon Sep 17 00:00:00 2001 From: "xin.zhang" Date: Thu, 13 Mar 2025 20:58:18 +0800 Subject: [PATCH] FIX: update while it's print job jira: [STUDIO-10848] Change-Id: I19c96dce7d48d46bdf4ed7861ab2136644195e34 --- src/slic3r/GUI/Jobs/Job.cpp | 2 +- src/slic3r/GUI/Jobs/Job.hpp | 42 +++++++++++++++++--------------- src/slic3r/GUI/Jobs/PrintJob.hpp | 1 + 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/slic3r/GUI/Jobs/Job.cpp b/src/slic3r/GUI/Jobs/Job.cpp index 9c54195ef..b188da03b 100644 --- a/src/slic3r/GUI/Jobs/Job.cpp +++ b/src/slic3r/GUI/Jobs/Job.cpp @@ -47,7 +47,7 @@ GUI::Job::Job(std::shared_ptr pri) Bind(wxEVT_THREAD, [this](const wxThreadEvent &evt) { if (m_finalizing) return; - if (evt.GetInt() >= 100) { update_percent_finish(); } + if (this->is_print_job() && evt.GetInt() >= 100) { update_percent_finish(); } auto msg = evt.GetString(); if (!msg.empty() && !m_worker_error) diff --git a/src/slic3r/GUI/Jobs/Job.hpp b/src/slic3r/GUI/Jobs/Job.hpp index 005a80787..b55ce3b68 100644 --- a/src/slic3r/GUI/Jobs/Job.hpp +++ b/src/slic3r/GUI/Jobs/Job.hpp @@ -35,13 +35,13 @@ class Job : public wxEvtHandler bool m_finalized = false, m_finalizing = false; std::shared_ptr m_progress; std::exception_ptr m_worker_error = nullptr; - + void run(std::exception_ptr &); - + protected: // status range for a particular job virtual int status_range() const { return 100; } - + // status update, to be used from the work thread (process() method) void update_status(int st, const wxString &msg = ""); @@ -56,7 +56,7 @@ protected: // The method where the actual work of the job should be defined. virtual void process() = 0; - + // Launched when the job is finished. It refreshes the 3Dscene by def. virtual void finalize() { m_finalized = true; } @@ -67,7 +67,7 @@ protected: { if (eptr) std::rethrow_exception(eptr); } - + public: enum JobPrepareState { PREPARE_STATE_DEFAULT = 0, @@ -76,24 +76,28 @@ public: }; Job(std::shared_ptr pri); - + bool is_finalized() const { return m_finalized; } - + Job(const Job &) = delete; Job(Job &&) = delete; Job &operator=(const Job &) = delete; Job &operator=(Job &&) = delete; - + void start(); - + // To wait for the running job and join the threads. False is // returned if the timeout has been reached and the job is still // running. Call cancel() before this fn if you want to explicitly // end the job. bool join(int timeout_ms = 0); - + bool is_running() const { return m_running.load(); } void cancel() { m_canceled.store(true); } + + public: + /*type check*/ + virtual bool is_print_job() const { return false; } }; // Jobs defined inside the group class will be managed so that only one can @@ -102,29 +106,29 @@ public: class ExclusiveJobGroup { static const int ABORT_WAIT_MAX_MS = 10000; - + std::vector> m_jobs; - + protected: virtual void before_start() {} - + public: virtual ~ExclusiveJobGroup() = default; - + size_t add_job(std::unique_ptr &&job) { m_jobs.emplace_back(std::move(job)); return m_jobs.size() - 1; } - + void start(size_t jid); - + void cancel_all() { for (auto& j : m_jobs) j->cancel(); } - + void join_all(int wait_ms = 0); - + void stop_all() { cancel_all(); join_all(ABORT_WAIT_MAX_MS); } - + bool is_any_running() const; }; diff --git a/src/slic3r/GUI/Jobs/PrintJob.hpp b/src/slic3r/GUI/Jobs/PrintJob.hpp index d274705af..fbe245210 100644 --- a/src/slic3r/GUI/Jobs/PrintJob.hpp +++ b/src/slic3r/GUI/Jobs/PrintJob.hpp @@ -55,6 +55,7 @@ protected: void on_exception(const std::exception_ptr &) override; public: PrintJob(std::shared_ptr pri, Plater *plater, std::string dev_id = ""); + virtual bool is_print_job() const override { return true; } std::string m_project_name; std::string m_dev_ip;