From 30693e29e45ddd7028743aed700263e3fbf58ee5 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Tue, 24 Nov 2020 14:41:36 +0100 Subject: [PATCH] Stop bed filling if enough instances are generated --- src/libslic3r/Arrange.cpp | 8 +++++--- src/libslic3r/Arrange.hpp | 3 ++- src/slic3r/GUI/Jobs/ArrangeJob.cpp | 4 ++-- src/slic3r/GUI/Jobs/FillBedJob.cpp | 8 ++++++-- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/libslic3r/Arrange.cpp b/src/libslic3r/Arrange.cpp index e4a5c7b42..1036844d7 100644 --- a/src/libslic3r/Arrange.cpp +++ b/src/libslic3r/Arrange.cpp @@ -309,7 +309,7 @@ protected: public: AutoArranger(const TBin & bin, const ArrangeParams ¶ms, - std::function progressind, + std::function progressind, std::function stopcond) : m_pck(bin, params.min_obj_distance) , m_bin(bin) @@ -348,7 +348,9 @@ public: m_pconf.object_function = get_objfn(); - if (progressind) m_pck.progressIndicator(progressind); + if (progressind) m_pck.progressIndicator([this, &progressind](unsigned rem) { + progressind(rem, m_pck.lastResult().size() - 1); + }); if (stopcond) m_pck.stopCondition(stopcond); m_pck.configure(m_pconf); @@ -462,7 +464,7 @@ void _arrange( std::vector & excludes, const BinT & bin, const ArrangeParams ¶ms, - std::function progressfn, + std::function progressfn, std::function stopfn) { // Integer ceiling the min distance from the bed perimeters diff --git a/src/libslic3r/Arrange.hpp b/src/libslic3r/Arrange.hpp index 65c3984d5..ef992f9a4 100644 --- a/src/libslic3r/Arrange.hpp +++ b/src/libslic3r/Arrange.hpp @@ -83,7 +83,8 @@ struct ArrangeParams { /// Progress indicator callback called when an object gets packed. /// The unsigned argument is the number of items remaining to pack. - std::function progressind; + /// Second is the current bed idx being filled. + std::function progressind; /// A predicate returning true if abort is needed. std::function stopcondition; diff --git a/src/slic3r/GUI/Jobs/ArrangeJob.cpp b/src/slic3r/GUI/Jobs/ArrangeJob.cpp index 7a8c21365..7af0b4703 100644 --- a/src/slic3r/GUI/Jobs/ArrangeJob.cpp +++ b/src/slic3r/GUI/Jobs/ArrangeJob.cpp @@ -158,14 +158,14 @@ void ArrangeJob::process() params.stopcondition = [this]() { return was_canceled(); }; try { - params.progressind = [this, count](unsigned st) { + params.progressind = [this, count](unsigned st, unsigned) { st += m_unprintable.size(); if (st > 0) update_status(int(count - st), arrangestr); }; arrangement::arrange(m_selected, m_unselected, bedpts, params); - params.progressind = [this, count](unsigned st) { + params.progressind = [this, count](unsigned st, unsigned) { if (st > 0) update_status(int(count - st), arrangestr); }; diff --git a/src/slic3r/GUI/Jobs/FillBedJob.cpp b/src/slic3r/GUI/Jobs/FillBedJob.cpp index 060528006..9c959ff16 100644 --- a/src/slic3r/GUI/Jobs/FillBedJob.cpp +++ b/src/slic3r/GUI/Jobs/FillBedJob.cpp @@ -90,9 +90,13 @@ void FillBedJob::process() params.min_obj_distance = scaled(settings.distance); params.allow_rotations = settings.enable_rotation; - params.stopcondition = [this]() { return was_canceled(); }; + unsigned curr_bed = 0; + params.stopcondition = [this, &curr_bed]() { + return was_canceled() || curr_bed > 0; + }; - params.progressind = [this](unsigned st) { + params.progressind = [this, &curr_bed](unsigned st, unsigned bed) { + curr_bed = bed; if (st > 0) update_status(int(m_status_range - st), _(L("Filling bed"))); };