Blender V5.3
interface_template_running_jobs.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <fmt/format.h>
10
11#include "AS_asset_library.hh"
12#include "AS_remote_library.hh"
13
14#include "BKE_context.hh"
15#include "BKE_global.hh"
16#include "BKE_main.hh"
17
18#include "BLI_listbase.hh"
19#include "BLI_string_utf8.hh"
20#include "BLI_time.hh"
21
22#include "BLI_timecode.hh"
23#include "BLT_translation.hh"
24
25#include "ED_screen.hh"
26
27#include "UI_resources.hh"
28#include "WM_api.hh"
29
30#include "UI_interface_c.hh"
32#include "interface_intern.hh"
33
34namespace blender::ui {
35
40
41static std::string progress_tooltip_func(bContext * /*C*/, void *argN, const StringRef /*tip*/)
42{
43 ProgressTooltip_Store *arg = static_cast<ProgressTooltip_Store *>(argN);
44 wmWindowManager *wm = arg->wm;
45 void *owner = arg->owner;
46
47 const float progress = WM_jobs_progress(wm, owner);
48
49 /* create tooltip text and associate it with the job */
50 char elapsed_str[32];
51 char remaining_str[32];
52 const double elapsed = BLI_time_now_seconds() - WM_jobs_starttime(wm, owner);
53 BLI_timecode_string_from_time_simple(elapsed_str, sizeof(elapsed_str), elapsed);
54
55 if (progress) {
56 const double remaining = (elapsed / double(progress)) - elapsed;
57 BLI_timecode_string_from_time_simple(remaining_str, sizeof(remaining_str), remaining);
58 }
59
60 return fmt::format(fmt::runtime(TIP_("Time Remaining: {}\n"
61 "Time Elapsed: {}")),
62 progress ? remaining_str : TIP_("Unknown"),
63 elapsed_str);
64}
65
70
75
77{
78 Main *bmain = CTX_data_main(C);
80 ScrArea *area = CTX_wm_area(C);
81
82 void *owner = nullptr;
83 int icon = 0;
84 std::function<void(bContext &)> cancel_fn = nullptr;
85 const char *op_name = nullptr;
86 const char *op_description = nullptr;
87
88 Block *block = layout->block();
89 block_layout_set_current(block, layout);
90
91 /* another scene can be rendering too, for example via compositor */
92 for (Scene &scene : bmain->scenes) {
94 cancel_fn = set_global_break;
95 icon = ICON_NONE;
96 owner = &scene;
97 }
98 else {
99 continue;
100 }
101
103 cancel_fn = cancel_all_scene_jobs;
104 icon = ICON_SEQUENCE;
105 owner = &scene;
106 break;
107 }
109 cancel_fn = cancel_all_scene_jobs;
110 icon = ICON_SEQUENCE;
111 break;
112 }
114 cancel_fn = cancel_all_scene_jobs;
115 icon = ICON_SEQUENCE;
116 break;
117 }
119 cancel_fn = cancel_all_scene_jobs;
120 icon = ICON_TRACKER;
121 break;
122 }
124 cancel_fn = cancel_all_scene_jobs;
125 icon = ICON_TRACKER;
126 break;
127 }
129 cancel_fn = cancel_all_scene_jobs;
130 icon = ICON_TRACKER;
131 break;
132 }
134 cancel_fn = cancel_all_scene_jobs;
135 icon = ICON_TRACKER;
136 break;
137 }
139 cancel_fn = set_global_break;
140 icon = ICON_SCENE;
141 if (U.render_display_type != USER_RENDER_DISPLAY_NONE) {
142 op_name = "RENDER_OT_view_show";
143 op_description = "Show the render window";
144 }
145 break;
146 }
148 cancel_fn = cancel_all_scene_jobs;
149 icon = ICON_RENDERLAYERS;
150 break;
151 }
154 {
155 /* Skip bake jobs in compositor to avoid compo header displaying progress bar
156 * which is not being updated (bake jobs only need to update NC_IMAGE context). */
157 if (area->spacetype != SPACE_NODE) {
158 cancel_fn = set_global_break;
159 icon = ICON_IMAGE;
160 break;
161 }
162 continue;
163 }
165 cancel_fn = set_global_break;
166 icon = ICON_MOD_DYNAMICPAINT;
167 break;
168 }
170 cancel_fn = set_global_break;
171 icon = ICON_PHYSICS;
172 break;
173 }
175 cancel_fn = set_global_break;
176 icon = ICON_MOD_FLUIDSIM;
177 break;
178 }
180 cancel_fn = set_global_break;
181 icon = ICON_MOD_OCEAN;
182 break;
183 }
185 cancel_fn = set_global_break;
186 icon = ICON_FILE_SOUND;
187 break;
188 }
189 }
190 if (!owner) {
191 for (wmWindow &win : wm->windows) {
192 const bScreen *screen = WM_window_get_active_screen(&win);
193 for (ScrArea &area : screen->areabase) {
194 if (area.spacetype != SPACE_FILE) {
195 continue;
196 }
197 const SpaceFile *sfile = area.spacedata.first_as<SpaceFile>();
198
200 icon = ICON_FILEBROWSER;
201 owner = sfile->files;
202 cancel_fn = [sfile](bContext &C) {
204 };
205 break;
206 }
207
209 const bool needs_cancelling_online_assets =
212 icon = ICON_ASSET_MANAGER;
213 owner = sfile->files;
214 cancel_fn = [sfile, needs_cancelling_online_assets](bContext &C) {
216 if (needs_cancelling_online_assets) {
218 }
219 };
220 break;
221 }
222 }
223 if (owner) {
224 break;
225 }
226 }
227 }
228
229 /* Blend file wide jobs. */
230 if (owner == nullptr) {
232 owner = bmain;
233 cancel_fn = set_global_break;
234 icon = ICON_TEXTURE;
235 }
236 }
237
238 if (owner) {
239 const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
240 const bool active = !(G.is_break || WM_jobs_is_stopped(wm, owner));
241
242 Layout *row = &layout->row(false);
243 block = row->block();
244
245 /* get percentage done and set it as the UI text */
246 const float progress = WM_jobs_progress(wm, owner);
247 char text[8];
248 SNPRINTF_UTF8(text, "%d%%", int(progress * 100));
249
250 const char *name = active ? RPT_(WM_jobs_name(wm, owner)) : RPT_("Canceling...");
251
252 /* job icon as a button */
253 if (op_name) {
254 uiDefIconButO(block,
256 op_name,
258 icon,
259 0,
260 0,
261 UI_UNIT_X,
262 UI_UNIT_Y,
263 TIP_(op_description));
264 }
265
266 /* job name and icon if not previously set */
267 const int textwidth = fontstyle_string_width(fstyle, name);
268 uiDefIconTextBut(block,
270 op_name ? 0 : icon,
271 name,
272 0,
273 0,
274 textwidth + UI_UNIT_X * 1.5f,
275 UI_UNIT_Y,
276 nullptr,
277 "");
278
279 /* stick progress bar and cancel button together */
280 row = &layout->row(true);
281 row->active_set(active);
282 block = row->block();
283
284 {
286 tip_arg->wm = wm;
287 tip_arg->owner = owner;
288 ButtonProgress *but_progress = static_cast<ButtonProgress *>(
289 uiDefIconTextBut(block,
291 ICON_NONE,
292 text,
293 UI_UNIT_X,
294 0,
295 UI_UNIT_X * 6.0f,
296 UI_UNIT_Y,
297 nullptr,
298 nullptr));
299
300 but_progress->progress_factor = progress;
302 }
303
304 if (cancel_fn && !wm->runtime->is_interface_locked) {
305 Button *but = uiDefIconTextBut(block,
307 ICON_PANEL_CLOSE,
308 "",
309 0,
310 0,
311 UI_UNIT_X,
312 UI_UNIT_Y,
313 nullptr,
314 TIP_("Stop this job"));
315 button_func_set(but, std::move(cancel_fn));
316 }
317 }
318
320 Button *but = uiDefIconTextBut(block,
322 ICON_STATUS_ERROR_FILLED,
323 IFACE_("Anim Player"),
324 0,
325 0,
326 UI_UNIT_X * 5.0f,
327 UI_UNIT_Y,
328 nullptr,
329 TIP_("Stop animation playback"));
330 button_func_set(but, [](bContext &C) {
332 &C, "SCREEN_OT_animation_play", wm::OpCallContext::InvokeScreen, nullptr, nullptr);
333 });
334 }
335
336 /* Not using the jobs system, but should be shown everywhere where jobs are shown too. */
338 uiDefIconTextBut(block,
340 ICON_ASSET_MANAGER,
341 IFACE_("Downloading Assets"),
342 0,
343 0,
344 UI_UNIT_X,
345 UI_UNIT_Y,
346 nullptr,
347 "");
348
349 Layout *row = &layout->row(false);
350 block = row->block();
351 row = &layout->row(true);
352
354 char text[8];
355 SNPRINTF_UTF8(text, "%d%%", int(progress * 100));
356
357 ButtonProgress *but_progress = static_cast<ButtonProgress *>(
358 uiDefIconTextBut(block,
360 ICON_NONE,
361 text,
362 UI_UNIT_X,
363 0,
364 UI_UNIT_X * 6.0f,
365 UI_UNIT_Y,
366 nullptr,
367 nullptr));
368 but_progress->progress_factor = progress;
369
370 Button *but = uiDefIconTextBut(block,
372 ICON_PANEL_CLOSE,
373 "",
374 0,
375 0,
376 UI_UNIT_X,
377 UI_UNIT_Y,
378 nullptr,
379 TIP_("Cancel all asset downloads"));
382 }
383}
384
385} // namespace blender::ui
#define SNPRINTF_UTF8(dst, format,...)
Platform independent time functions.
#define RPT_(msgid)
#define TIP_(msgid)
#define IFACE_(msgid)
#define C
Definition RandGen.cpp:29
#define UI_UNIT_Y
#define UI_FSTYLE_WIDGET
#define UI_UNIT_X
bool remote_library_has_unfinished_asset_downloads()
float remote_library_total_asset_downloads_progress()
bool is_or_contains_remote_libraries(const AssetLibraryReference &reference)
void remote_library_cancel_all_listing_downloads(const bContext &C)
void remote_library_cancel_all_asset_downloads(bContext &C)
Button * uiDefIconTextBut(Block *block, ButtonTypeWithPointerType but_and_ptr_type, int icon, StringRef str, int x, int y, short width, short height, void *poin, std::optional< StringRef > tip)
static void cancel_all_scene_jobs(bContext &C)
static std::string progress_tooltip_func(bContext *, void *argN, const StringRef)
void button_func_set(Button *but, std::function< void(bContext &)> func)
int fontstyle_string_width(const uiFontStyle *fs, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
void template_running_jobs(Layout *layout, bContext *C)
Button * uiDefIconButO(Block *block, ButtonType type, StringRefNull opname, wm::OpCallContext opcontext, int icon, int x, int y, short width, short height, std::optional< StringRef > tip)
void button_func_tooltip_set(Button *but, ButtonToolTipFunc func, void *arg, FreeArgFunc free_arg)
static void set_global_break(bContext &C)
void block_layout_set_current(Block *block, Layout *layout)
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
UserDef U
Definition blender.cc:58
ScrArea * CTX_wm_area(const bContext *C)
@ WM_JOB_TYPE_SEQ_BUILD_PROXY
Definition WM_api.hh:2032
@ WM_JOB_TYPE_SOUND_MIXDOWN
Definition WM_api.hh:2053
@ WM_JOB_TYPE_CLIP_SOLVE_CAMERA
Definition WM_api.hh:2030
@ WM_JOB_TYPE_ASSET_LIBRARY_LOAD
Definition WM_api.hh:2020
@ WM_JOB_TYPE_SEQ_DRAW_THUMBNAIL
Definition WM_api.hh:2047
@ WM_JOB_TYPE_OBJECT_SIM_FLUID
Definition WM_api.hh:2016
@ WM_JOB_TYPE_OBJECT_SIM_OCEAN
Definition WM_api.hh:2015
@ WM_JOB_TYPE_RENDER
Definition WM_api.hh:2011
@ WM_JOB_TYPE_COMPOSITE
Definition WM_api.hh:2010
@ WM_JOB_TYPE_OBJECT_BAKE
Definition WM_api.hh:2018
@ WM_JOB_TYPE_OBJECT_BAKE_TEXTURE
Definition WM_api.hh:2017
@ WM_JOB_TYPE_CLIP_TRACK_MARKERS
Definition WM_api.hh:2029
@ WM_JOB_TYPE_CLIP_PREFETCH
Definition WM_api.hh:2031
@ WM_JOB_TYPE_SEQ_BUILD_PREVIEW
Definition WM_api.hh:2033
@ WM_JOB_TYPE_ANY
Definition WM_api.hh:2008
@ WM_JOB_TYPE_GENERATE_TEXTURE_CACHE
Definition WM_api.hh:2052
@ WM_JOB_TYPE_DPAINT_BAKE
Definition WM_api.hh:2035
@ WM_JOB_TYPE_FILESEL_READDIR
Definition WM_api.hh:2019
@ WM_JOB_TYPE_POINTCACHE
Definition WM_api.hh:2034
@ WM_JOB_TYPE_CLIP_BUILD_PROXY
Definition WM_api.hh:2028
void MEM_delete_void(void *vmemh)
bool WM_jobs_progress_test(const wmWindowManager *wm, const void *owner, int job_type)
Definition wm_jobs.cc:264
Global G
Definition blender.cc:57
const char * WM_jobs_name(const wmWindowManager *wm, const void *owner)
Definition wm_jobs.cc:336
wmWindowManager * CTX_wm_manager(const bContext *C)
wmOperatorStatus WM_operator_name_call(bContext *C, const char *opstring, wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
bScreen * ED_screen_animation_no_scrub(const wmWindowManager *wm)
Main * CTX_data_main(const bContext *C)
double BLI_time_now_seconds()
Definition time.cc:30
Scene * CTX_data_scene(const bContext *C)
bool WM_jobs_is_stopped(const wmWindowManager *wm, const void *owner)
Definition wm_jobs.cc:363
void WM_jobs_stop_all_from_owner(wmWindowManager *wm, const void *owner)
Definition wm_jobs.cc:682
bScreen * WM_window_get_active_screen(const wmWindow *win)
size_t BLI_timecode_string_from_time_simple(char *str, size_t maxncpy, double time_seconds) ATTR_NONNULL()
Definition timecode.cc:172
float WM_jobs_progress(const wmWindowManager *wm, const void *owner)
Definition wm_jobs.cc:284
double WM_jobs_starttime(const wmWindowManager *wm, const void *owner)
Definition wm_jobs.cc:325
AssetLibraryReference asset_library_ref
ListBaseT< Scene > scenes
Definition BKE_main.hh:386
ListBaseT< SpaceLink > spacedata
FileAssetSelectParams * asset_params
struct FileList * files
ListBaseT< struct ScrArea > areabase
void active_set(bool active)
Layout & row(bool align)