mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-15 00:45:57 +08:00
check of stop thread without lambda
This commit is contained in:
parent
2c6f57cc5c
commit
a0983276b4
@ -17,7 +17,7 @@ namespace Priv {
|
|||||||
static void finalize(const EmbossData &input, const indexed_triangle_set &result);
|
static void finalize(const EmbossData &input, const indexed_triangle_set &result);
|
||||||
} // namespace Priv
|
} // namespace Priv
|
||||||
|
|
||||||
void EmbossJob::process(std::unique_ptr<EmbossData> input, StopCondition is_stop)
|
void EmbossJob::process(std::unique_ptr<EmbossData> input)
|
||||||
{
|
{
|
||||||
// Changing cursor to busy
|
// Changing cursor to busy
|
||||||
wxBeginBusyCursor();
|
wxBeginBusyCursor();
|
||||||
@ -37,7 +37,7 @@ void EmbossJob::process(std::unique_ptr<EmbossData> input, StopCondition is_stop
|
|||||||
const FontProp &prop = cfg.font_prop;
|
const FontProp &prop = cfg.font_prop;
|
||||||
ExPolygons shapes = Emboss::text2shapes(*input->font, text.c_str(), prop);
|
ExPolygons shapes = Emboss::text2shapes(*input->font, text.c_str(), prop);
|
||||||
|
|
||||||
if (is_stop()) return;
|
if (is_stoping()) return;
|
||||||
|
|
||||||
// exist 2d shape made by text ?
|
// exist 2d shape made by text ?
|
||||||
// (no shape means that font hasn't any of text symbols)
|
// (no shape means that font hasn't any of text symbols)
|
||||||
@ -48,7 +48,7 @@ void EmbossJob::process(std::unique_ptr<EmbossData> input, StopCondition is_stop
|
|||||||
Emboss::ProjectScale project(std::move(projectZ), scale);
|
Emboss::ProjectScale project(std::move(projectZ), scale);
|
||||||
auto its = std::make_unique<indexed_triangle_set>(Emboss::polygons2model(shapes, project));
|
auto its = std::make_unique<indexed_triangle_set>(Emboss::polygons2model(shapes, project));
|
||||||
|
|
||||||
if (is_stop()) return;
|
if (is_stoping()) return;
|
||||||
|
|
||||||
// for sure that some object is created from shape
|
// for sure that some object is created from shape
|
||||||
if (its->indices.empty()) return;
|
if (its->indices.empty()) return;
|
||||||
|
@ -27,7 +27,7 @@ struct EmbossData
|
|||||||
class EmbossJob : public StopableJob<EmbossData>
|
class EmbossJob : public StopableJob<EmbossData>
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
void process(std::unique_ptr<EmbossData> input, StopCondition is_stop) override;
|
void process(std::unique_ptr<EmbossData> input) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Slic3r::GUI
|
} // namespace Slic3r::GUI
|
||||||
|
@ -8,10 +8,8 @@
|
|||||||
namespace Slic3r::GUI {
|
namespace Slic3r::GUI {
|
||||||
|
|
||||||
// inspired by Job.hpp
|
// inspired by Job.hpp
|
||||||
// All public function can be call only from UI thread
|
|
||||||
// Mechanism to stack processing and do only last one
|
// Mechanism to stack processing and do only last one
|
||||||
// Ability to stop processing developer must add check into m_func
|
// Ability to stop processing developer must add check is_stopping() into process()
|
||||||
using StopCondition = std::function<bool(void)>;
|
|
||||||
template<typename TIn> class StopableJob
|
template<typename TIn> class StopableJob
|
||||||
{
|
{
|
||||||
std::mutex m_mutex;
|
std::mutex m_mutex;
|
||||||
@ -63,11 +61,10 @@ protected:
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Thread job of processing input data
|
/// Thread job of processing input data
|
||||||
|
/// Note: Use check function is_stoping(), when true than interupt processing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input">input data to process</param>
|
/// <param name="input">input data to process</param>
|
||||||
/// <param name="stop_condition">When lambda is true, quit processing,
|
virtual void process(std::unique_ptr<TIn> input) = 0;
|
||||||
/// keep in mind check is under mutex so do it occasionally</param>
|
|
||||||
virtual void process(std::unique_ptr<TIn> input, StopCondition stop_condition) = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//////
|
//////
|
||||||
@ -107,7 +104,7 @@ void StopableJob<TIn>::run(std::unique_ptr<TIn> input)
|
|||||||
m_thread = std::thread(
|
m_thread = std::thread(
|
||||||
[this](std::unique_ptr<TIn> input) {
|
[this](std::unique_ptr<TIn> input) {
|
||||||
do {
|
do {
|
||||||
process(std::move(input), [this]() { return is_stoping(); });
|
process(std::move(input));
|
||||||
|
|
||||||
std::lock_guard lg(m_mutex);
|
std::lock_guard lg(m_mutex);
|
||||||
m_stop = false;
|
m_stop = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user