Rework UI jobs to make them more understandable and flexible.

This commit is contained in:
tamasmeszaros 2021-11-30 16:02:49 +01:00
parent f5e2beeaf4
commit b53ff75cf4
27 changed files with 956 additions and 592 deletions

View file

@ -162,49 +162,42 @@ void ArrangeJob::prepare()
wxGetKeyState(WXK_SHIFT) ? prepare_selected() : prepare_all();
}
void ArrangeJob::on_exception(const std::exception_ptr &eptr)
void ArrangeJob::process(Ctl &ctl)
{
try {
if (eptr)
std::rethrow_exception(eptr);
} catch (libnest2d::GeometryException &) {
show_error(m_plater, _(L("Could not arrange model objects! "
"Some geometries may be invalid.")));
} catch (std::exception &) {
PlaterJob::on_exception(eptr);
}
}
ctl.call_on_main_thread([this]{ prepare(); }).wait();
void ArrangeJob::process()
{
static const auto arrangestr = _(L("Arranging"));
static const auto arrangestr = _u8L("Arranging");
arrangement::ArrangeParams params = get_arrange_params(m_plater);
auto count = unsigned(m_selected.size() + m_unprintable.size());
auto count = unsigned(m_selected.size() + m_unprintable.size());
Points bedpts = get_bed_shape(*m_plater->config());
params.stopcondition = [this]() { return was_canceled(); };
params.progressind = [this, count](unsigned st) {
params.stopcondition = [&ctl]() { return ctl.was_canceled(); };
params.progressind = [this, count, &ctl](unsigned st) {
st += m_unprintable.size();
if (st > 0) update_status(int(count - st), arrangestr);
if (st > 0) ctl.update_status(int(count - st) * 100 / status_range(), arrangestr);
};
ctl.update_status(0, arrangestr);
arrangement::arrange(m_selected, m_unselected, bedpts, params);
params.progressind = [this, count](unsigned st) {
if (st > 0) update_status(int(count - st), arrangestr);
params.progressind = [this, count, &ctl](unsigned st) {
if (st > 0) ctl.update_status(int(count - st) * 100 / status_range(), arrangestr);
};
arrangement::arrange(m_unprintable, {}, bedpts, params);
// finalize just here.
update_status(int(count),
was_canceled() ? _(L("Arranging canceled."))
: _(L("Arranging done.")));
ctl.update_status(int(count) * 100 / status_range(), ctl.was_canceled() ?
_u8L("Arranging canceled.") :
_u8L("Arranging done."));
}
ArrangeJob::ArrangeJob() : m_plater{wxGetApp().plater()} { }
static std::string concat_strings(const std::set<std::string> &strings,
const std::string &delim = "\n")
{
@ -215,10 +208,21 @@ static std::string concat_strings(const std::set<std::string> &strings,
});
}
void ArrangeJob::finalize() {
// Ignore the arrange result if aborted.
if (was_canceled()) return;
void ArrangeJob::finalize(bool canceled, std::exception_ptr &eptr) {
try {
if (eptr)
std::rethrow_exception(eptr);
} catch (libnest2d::GeometryException &) {
show_error(m_plater, _(L("Could not arrange model objects! "
"Some geometries may be invalid.")));
eptr = nullptr;
} catch(...) {
eptr = std::current_exception();
}
if (canceled || eptr)
return;
// Unprintable items go to the last virtual bed
int beds = 0;
@ -250,8 +254,6 @@ void ArrangeJob::finalize() {
_L("Arrangement ignored the following objects which can't fit into a single bed:\n%s"),
concat_strings(names, "\n")));
}
Job::finalize();
}
std::optional<arrangement::ArrangePolygon>