From 9aac1b6fa5cdac84130f124343dc8744c959ae36 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Wed, 7 Apr 2021 12:37:49 +0200 Subject: [PATCH 1/2] Fix issue with importing sl1 files with non-ascii filenames. --- src/libslic3r/Format/SL1.cpp | 2 +- src/slic3r/GUI/Jobs/SLAImportJob.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/Format/SL1.cpp b/src/libslic3r/Format/SL1.cpp index f04855182..64cb8b815 100644 --- a/src/libslic3r/Format/SL1.cpp +++ b/src/libslic3r/Format/SL1.cpp @@ -87,7 +87,7 @@ PNGBuffer read_png(const mz_zip_archive_file_stat &entry, } ArchiveData extract_sla_archive(const std::string &zipfname, - const std::string &exclude) + const std::string &exclude) { ArchiveData arch; diff --git a/src/slic3r/GUI/Jobs/SLAImportJob.cpp b/src/slic3r/GUI/Jobs/SLAImportJob.cpp index f9fbef8a8..d9f261fce 100644 --- a/src/slic3r/GUI/Jobs/SLAImportJob.cpp +++ b/src/slic3r/GUI/Jobs/SLAImportJob.cpp @@ -178,7 +178,7 @@ void SLAImportJob::prepare() if (dlg.ShowModal() == wxID_OK) { auto path = dlg.get_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->win = dlg.get_marchsq_windowsize(); } else { From 3135e471804c53d0b9b9b7f7772d43aa7ce044f4 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Wed, 7 Apr 2021 12:40:33 +0200 Subject: [PATCH 2/2] Fix duplicated error message dialog from GUI jobs. --- src/slic3r/GUI/Jobs/Job.cpp | 29 +++++++++++++++++++++++----- src/slic3r/GUI/Jobs/Job.hpp | 3 ++- src/slic3r/GUI/Jobs/SLAImportJob.cpp | 3 ++- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/slic3r/GUI/Jobs/Job.cpp b/src/slic3r/GUI/Jobs/Job.cpp index 1f7f58875..6346227aa 100644 --- a/src/slic3r/GUI/Jobs/Job.cpp +++ b/src/slic3r/GUI/Jobs/Job.cpp @@ -24,7 +24,7 @@ void GUI::Job::run(std::exception_ptr &eptr) 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->SetString(msg); wxQueueEvent(this, evt); @@ -33,7 +33,11 @@ void GUI::Job::update_status(int st, const wxString &msg) GUI::Job::Job(std::shared_ptr 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(); if (!msg.empty() && !m_worker_error) m_progress->set_status_text(msg.ToUTF8().data()); @@ -53,13 +57,27 @@ GUI::Job::Job(std::shared_ptr pri) m_progress->set_progress(m_range); 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(); + } // dont do finalization again for the same process m_finalized = true; } - }); + }, m_thread_evt_id); } void GUI::Job::start() @@ -76,7 +94,8 @@ void GUI::Job::start() m_progress->set_cancel_callback( [this]() { m_canceled.store(true); }); - m_finalized = false; + m_finalized = false; + m_finalizing = false; // Changing cursor to busy wxBeginBusyCursor(); diff --git a/src/slic3r/GUI/Jobs/Job.hpp b/src/slic3r/GUI/Jobs/Job.hpp index cb73fe74d..082e5f4e8 100644 --- a/src/slic3r/GUI/Jobs/Job.hpp +++ b/src/slic3r/GUI/Jobs/Job.hpp @@ -29,9 +29,10 @@ namespace Slic3r { namespace GUI { class Job : public wxEvtHandler { int m_range = 100; + int m_thread_evt_id = wxID_ANY; boost::thread m_thread; std::atomic m_running{false}, m_canceled{false}; - bool m_finalized = false; + bool m_finalized = false, m_finalizing = false; std::shared_ptr m_progress; std::exception_ptr m_worker_error = nullptr; diff --git a/src/slic3r/GUI/Jobs/SLAImportJob.cpp b/src/slic3r/GUI/Jobs/SLAImportJob.cpp index d9f261fce..3da937f0a 100644 --- a/src/slic3r/GUI/Jobs/SLAImportJob.cpp +++ b/src/slic3r/GUI/Jobs/SLAImportJob.cpp @@ -132,7 +132,8 @@ SLAImportJob::~SLAImportJob() = default; void SLAImportJob::process() { 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(); };