OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::detail Namespace Reference

Functions

template<typename Run, typename OnFinish>
void run_off_thread_with_progress (Run &&run, OnFinish &&on_finish, wxWindow *parent, const wxString &title, const wxString &message, int maximum, int style, std::shared_ptr< std::atomic< bool > > alive, bool finish_after_dialog_destroyed, std::function< void()> restore)
template<typename Run>
std::invoke_result_t< std::decay_t< Run > & > run_wait_with_progress (Run &&run, wxWindow *parent, const wxString &title, const wxString &message, int maximum, int style, std::shared_ptr< std::atomic< bool > > alive, std::function< void()> restore)

Function Documentation

◆ run_off_thread_with_progress()

template<typename Run, typename OnFinish>
void Slic3r::GUI::detail::run_off_thread_with_progress ( Run && run,
OnFinish && on_finish,
wxWindow * parent,
const wxString & title,
const wxString & message,
int maximum,
int style,
std::shared_ptr< std::atomic< bool > > alive,
bool finish_after_dialog_destroyed,
std::function< void()> restore )
79{
80 wxProgressDialog* progress = new wxProgressDialog(title, message, maximum, parent, style);
81 wxTimer* timer = new wxTimer();
82
83 timer->Bind(wxEVT_TIMER, [alive, progress, message](wxTimerEvent&) {
84 if ((!alive || alive->load(std::memory_order_acquire)) && progress)
85 progress->Pulse(message);
86 });
87
88 timer->Start(100);
89
90 std::thread([alive,
91 progress,
92 timer,
93 run = std::forward<Run>(run),
94 on_finish = std::forward<OnFinish>(on_finish),
95 finish_after_dialog_destroyed,
96 restore = std::move(restore)]() mutable {
97 try {
98 run();
99 } catch (const std::exception& ex) {
100 BOOST_LOG_TRIVIAL(error) << "Plugin dialog worker failed: " << ex.what();
101 } catch (...) {
102 BOOST_LOG_TRIVIAL(error) << "Plugin dialog worker failed with an unknown exception";
103 }
104
105 if (wxTheApp == nullptr)
106 return;
107
108 wxTheApp->CallAfter([alive,
109 progress,
110 timer,
111 on_finish = std::move(on_finish),
112 finish_after_dialog_destroyed,
113 restore = std::move(restore)]() mutable {
114 timer->Stop();
115 delete timer;
116
117 if (!alive || alive->load(std::memory_order_acquire)) {
118 progress->Destroy();
119 if (restore)
120 restore();
121 on_finish();
122 } else if (finish_after_dialog_destroyed) {
123 on_finish();
124 }
125 });
126 }).detach();
127}
#define style
Definition WipeTowerDialog.cpp:101

References style.

Referenced by run_wait_with_progress(), and Slic3r::GUI::PluginsDialog::run_with_dialog().

Here is the caller graph for this function:

◆ run_wait_with_progress()

template<typename Run>
std::invoke_result_t< std::decay_t< Run > & > Slic3r::GUI::detail::run_wait_with_progress ( Run && run,
wxWindow * parent,
const wxString & title,
const wxString & message,
int maximum,
int style,
std::shared_ptr< std::atomic< bool > > alive,
std::function< void()> restore )
140{
141 using Result = std::invoke_result_t<std::decay_t<Run>&>;
142
143 bool finished = false;
144 wxEventLoop loop;
145 auto on_finish = [&finished, &loop]() {
146 finished = true;
147 if (loop.IsRunning())
148 loop.Exit();
149 };
150
151 if constexpr (std::is_void_v<Result>) {
152 struct WaitState
153 {
154 std::mutex mutex;
155 std::exception_ptr exception;
156 };
157
158 auto state = std::make_shared<WaitState>();
160 [run = std::forward<Run>(run), state]() mutable {
161 try {
162 run();
163 } catch (...) {
164 std::lock_guard<std::mutex> lock(state->mutex);
165 state->exception = std::current_exception();
166 }
167 },
168 on_finish, parent, title, message, maximum, style, std::move(alive), /*finish_after_dialog_destroyed=*/true, std::move(restore));
169
170 if (!finished)
171 loop.Run();
172
173 std::exception_ptr exception;
174 {
175 std::lock_guard<std::mutex> lock(state->mutex);
176 exception = state->exception;
177 }
178 if (exception)
179 std::rethrow_exception(exception);
180 } else {
181 using StoredResult = std::decay_t<Result>;
182 struct WaitState
183 {
184 std::mutex mutex;
185 std::optional<StoredResult> result;
186 std::exception_ptr exception;
187 };
188
189 auto state = std::make_shared<WaitState>();
191 [run = std::forward<Run>(run), state]() mutable {
192 try {
193 StoredResult result = run();
194 std::lock_guard<std::mutex> lock(state->mutex);
195 state->result.emplace(std::move(result));
196 } catch (...) {
197 std::lock_guard<std::mutex> lock(state->mutex);
198 state->exception = std::current_exception();
199 }
200 },
201 on_finish, parent, title, message, maximum, style, std::move(alive), /*finish_after_dialog_destroyed=*/true, std::move(restore));
202
203 if (!finished)
204 loop.Run();
205
206 std::optional<StoredResult> result;
207 std::exception_ptr exception;
208 {
209 std::lock_guard<std::mutex> lock(state->mutex);
210 if (state->result)
211 result.emplace(std::move(*state->result));
212 exception = state->exception;
213 }
214 if (exception)
215 std::rethrow_exception(exception);
216 return std::move(*result);
217 }
218}
class WXDLLIMPEXP_FWD_CORE wxEventLoop
Definition ProgressDialog.hpp:28
AppActionRunResult run(const std::string &key, const std::string &param={})
Definition NativeCommands.cpp:668
void run_off_thread_with_progress(Run &&run, OnFinish &&on_finish, wxWindow *parent, const wxString &title, const wxString &message, int maximum, int style, std::shared_ptr< std::atomic< bool > > alive, bool finish_after_dialog_destroyed, std::function< void()> restore)
Definition PluginsDialog.hpp:69
@ lock
Definition GLGizmoEmboss.cpp:209

References run_off_thread_with_progress(), style, and wxEventLoop.

Referenced by Slic3r::GUI::install_local_plugin_package(), and Slic3r::GUI::PluginsDialog::run_with_dialog_wait().

Here is the call graph for this function:
Here is the caller graph for this function: