Stop bed filling if enough instances are generated

This commit is contained in:
tamasmeszaros 2020-11-24 14:41:36 +01:00
parent 0fc1929076
commit 30693e29e4
4 changed files with 15 additions and 8 deletions

View file

@ -309,7 +309,7 @@ protected:
public: public:
AutoArranger(const TBin & bin, AutoArranger(const TBin & bin,
const ArrangeParams &params, const ArrangeParams &params,
std::function<void(unsigned)> progressind, std::function<void(unsigned, unsigned /*bins*/)> progressind,
std::function<bool(void)> stopcond) std::function<bool(void)> stopcond)
: m_pck(bin, params.min_obj_distance) : m_pck(bin, params.min_obj_distance)
, m_bin(bin) , m_bin(bin)
@ -348,7 +348,9 @@ public:
m_pconf.object_function = get_objfn(); 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); if (stopcond) m_pck.stopCondition(stopcond);
m_pck.configure(m_pconf); m_pck.configure(m_pconf);
@ -462,7 +464,7 @@ void _arrange(
std::vector<Item> & excludes, std::vector<Item> & excludes,
const BinT & bin, const BinT & bin,
const ArrangeParams &params, const ArrangeParams &params,
std::function<void(unsigned)> progressfn, std::function<void(unsigned, unsigned)> progressfn,
std::function<bool()> stopfn) std::function<bool()> stopfn)
{ {
// Integer ceiling the min distance from the bed perimeters // Integer ceiling the min distance from the bed perimeters

View file

@ -83,7 +83,8 @@ struct ArrangeParams {
/// Progress indicator callback called when an object gets packed. /// Progress indicator callback called when an object gets packed.
/// The unsigned argument is the number of items remaining to pack. /// The unsigned argument is the number of items remaining to pack.
std::function<void(unsigned)> progressind; /// Second is the current bed idx being filled.
std::function<void(unsigned, unsigned /*bed_idx*/)> progressind;
/// A predicate returning true if abort is needed. /// A predicate returning true if abort is needed.
std::function<bool(void)> stopcondition; std::function<bool(void)> stopcondition;

View file

@ -158,14 +158,14 @@ void ArrangeJob::process()
params.stopcondition = [this]() { return was_canceled(); }; params.stopcondition = [this]() { return was_canceled(); };
try { try {
params.progressind = [this, count](unsigned st) { params.progressind = [this, count](unsigned st, unsigned) {
st += m_unprintable.size(); st += m_unprintable.size();
if (st > 0) update_status(int(count - st), arrangestr); if (st > 0) update_status(int(count - st), arrangestr);
}; };
arrangement::arrange(m_selected, m_unselected, bedpts, params); 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); if (st > 0) update_status(int(count - st), arrangestr);
}; };

View file

@ -90,9 +90,13 @@ void FillBedJob::process()
params.min_obj_distance = scaled(settings.distance); params.min_obj_distance = scaled(settings.distance);
params.allow_rotations = settings.enable_rotation; 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) if (st > 0)
update_status(int(m_status_range - st), _(L("Filling bed"))); update_status(int(m_status_range - st), _(L("Filling bed")));
}; };