Merge remote-tracking branch 'origin/tm_sl1_import_fix'
This commit is contained in:
commit
e8af080346
4 changed files with 30 additions and 9 deletions
|
@ -87,7 +87,7 @@ PNGBuffer read_png(const mz_zip_archive_file_stat &entry,
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchiveData extract_sla_archive(const std::string &zipfname,
|
ArchiveData extract_sla_archive(const std::string &zipfname,
|
||||||
const std::string &exclude)
|
const std::string &exclude)
|
||||||
{
|
{
|
||||||
ArchiveData arch;
|
ArchiveData arch;
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ void GUI::Job::run(std::exception_ptr &eptr)
|
||||||
|
|
||||||
void GUI::Job::update_status(int st, const wxString &msg)
|
void GUI::Job::update_status(int st, const wxString &msg)
|
||||||
{
|
{
|
||||||
auto evt = new wxThreadEvent();
|
auto evt = new wxThreadEvent(wxEVT_THREAD, m_thread_evt_id);
|
||||||
evt->SetInt(st);
|
evt->SetInt(st);
|
||||||
evt->SetString(msg);
|
evt->SetString(msg);
|
||||||
wxQueueEvent(this, evt);
|
wxQueueEvent(this, evt);
|
||||||
|
@ -33,7 +33,11 @@ void GUI::Job::update_status(int st, const wxString &msg)
|
||||||
GUI::Job::Job(std::shared_ptr<ProgressIndicator> pri)
|
GUI::Job::Job(std::shared_ptr<ProgressIndicator> pri)
|
||||||
: m_progress(std::move(pri))
|
: m_progress(std::move(pri))
|
||||||
{
|
{
|
||||||
Bind(wxEVT_THREAD, [this](const wxThreadEvent &evt) {
|
m_thread_evt_id = wxNewId();
|
||||||
|
|
||||||
|
Bind(wxEVT_THREAD, [this](const wxThreadEvent &evt) {
|
||||||
|
if (m_finalizing) return;
|
||||||
|
|
||||||
auto msg = evt.GetString();
|
auto msg = evt.GetString();
|
||||||
if (!msg.empty() && !m_worker_error)
|
if (!msg.empty() && !m_worker_error)
|
||||||
m_progress->set_status_text(msg.ToUTF8().data());
|
m_progress->set_status_text(msg.ToUTF8().data());
|
||||||
|
@ -53,13 +57,27 @@ GUI::Job::Job(std::shared_ptr<ProgressIndicator> pri)
|
||||||
m_progress->set_progress(m_range);
|
m_progress->set_progress(m_range);
|
||||||
on_exception(m_worker_error);
|
on_exception(m_worker_error);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
|
// This is an RAII solution to remember that finalization is
|
||||||
|
// running. The run method calls update_status(status_range(), "")
|
||||||
|
// at the end, which queues up a call to this handler in all cases.
|
||||||
|
// If process also calls update_status with maxed out status arg
|
||||||
|
// it will call this handler twice. It is not a problem unless
|
||||||
|
// yield is called inside the finilize() method, which would
|
||||||
|
// jump out of finalize and call this handler again.
|
||||||
|
struct Finalizing {
|
||||||
|
bool &flag;
|
||||||
|
Finalizing (bool &f): flag(f) { flag = true; }
|
||||||
|
~Finalizing() { flag = false; }
|
||||||
|
} fin(m_finalizing);
|
||||||
|
|
||||||
finalize();
|
finalize();
|
||||||
|
}
|
||||||
|
|
||||||
// dont do finalization again for the same process
|
// dont do finalization again for the same process
|
||||||
m_finalized = true;
|
m_finalized = true;
|
||||||
}
|
}
|
||||||
});
|
}, m_thread_evt_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::Job::start()
|
void GUI::Job::start()
|
||||||
|
@ -76,7 +94,8 @@ void GUI::Job::start()
|
||||||
m_progress->set_cancel_callback(
|
m_progress->set_cancel_callback(
|
||||||
[this]() { m_canceled.store(true); });
|
[this]() { m_canceled.store(true); });
|
||||||
|
|
||||||
m_finalized = false;
|
m_finalized = false;
|
||||||
|
m_finalizing = false;
|
||||||
|
|
||||||
// Changing cursor to busy
|
// Changing cursor to busy
|
||||||
wxBeginBusyCursor();
|
wxBeginBusyCursor();
|
||||||
|
|
|
@ -29,9 +29,10 @@ namespace Slic3r { namespace GUI {
|
||||||
class Job : public wxEvtHandler
|
class Job : public wxEvtHandler
|
||||||
{
|
{
|
||||||
int m_range = 100;
|
int m_range = 100;
|
||||||
|
int m_thread_evt_id = wxID_ANY;
|
||||||
boost::thread m_thread;
|
boost::thread m_thread;
|
||||||
std::atomic<bool> m_running{false}, m_canceled{false};
|
std::atomic<bool> m_running{false}, m_canceled{false};
|
||||||
bool m_finalized = false;
|
bool m_finalized = false, m_finalizing = false;
|
||||||
std::shared_ptr<ProgressIndicator> m_progress;
|
std::shared_ptr<ProgressIndicator> m_progress;
|
||||||
std::exception_ptr m_worker_error = nullptr;
|
std::exception_ptr m_worker_error = nullptr;
|
||||||
|
|
||||||
|
|
|
@ -132,7 +132,8 @@ SLAImportJob::~SLAImportJob() = default;
|
||||||
void SLAImportJob::process()
|
void SLAImportJob::process()
|
||||||
{
|
{
|
||||||
auto progr = [this](int s) {
|
auto progr = [this](int s) {
|
||||||
if (s < 100) update_status(int(s), _(L("Importing SLA archive")));
|
if (s < 100)
|
||||||
|
update_status(int(s), _(L("Importing SLA archive")));
|
||||||
return !was_canceled();
|
return !was_canceled();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -178,7 +179,7 @@ void SLAImportJob::prepare()
|
||||||
if (dlg.ShowModal() == wxID_OK) {
|
if (dlg.ShowModal() == wxID_OK) {
|
||||||
auto path = dlg.get_path();
|
auto path = dlg.get_path();
|
||||||
auto nm = wxFileName(path);
|
auto nm = wxFileName(path);
|
||||||
p->path = !nm.Exists(wxFILE_EXISTS_REGULAR) ? "" : path.ToUTF8();
|
p->path = !nm.Exists(wxFILE_EXISTS_REGULAR) ? "" : nm.GetFullPath();
|
||||||
p->sel = dlg.get_selection();
|
p->sel = dlg.get_selection();
|
||||||
p->win = dlg.get_marchsq_windowsize();
|
p->win = dlg.get_marchsq_windowsize();
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue