2023-08-15 16:20:26 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2002-10-12 13:37:38 +02:00
|
|
|
|
2019-02-17 22:08:12 +01:00
|
|
|
/** \file
|
2019-09-05 15:52:38 +02:00
|
|
|
* \ingroup bke
|
2011-02-27 21:37:56 +01:00
|
|
|
*/
|
|
|
|
|
2019-09-05 15:52:38 +02:00
|
|
|
#pragma once
|
2002-10-12 13:37:38 +02:00
|
|
|
|
2020-03-02 15:07:49 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2019-09-09 10:25:04 +02:00
|
|
|
struct Depsgraph;
|
2011-06-24 18:54:30 +02:00
|
|
|
struct ID;
|
2019-01-28 11:08:24 +01:00
|
|
|
struct Main;
|
2019-09-09 10:25:04 +02:00
|
|
|
struct PointerRNA;
|
2011-06-24 18:54:30 +02:00
|
|
|
|
2014-08-29 08:17:31 +02:00
|
|
|
/**
|
2022-04-11 03:41:00 +02:00
|
|
|
* Callbacks for One Off Actions
|
2021-06-02 09:15:05 +02:00
|
|
|
* =============================
|
|
|
|
*
|
|
|
|
* - `{ACTION}` use in cases where only a single callback is required,
|
|
|
|
* `VERSION_UPDATE` and `RENDER_STATS` for example.
|
|
|
|
*
|
|
|
|
* \note avoid single callbacks if there is a chance `PRE/POST` are useful to differentiate
|
|
|
|
* since renaming callbacks may break Python scripts.
|
|
|
|
*
|
|
|
|
* Callbacks for Common Actions
|
|
|
|
* ============================
|
|
|
|
*
|
|
|
|
* - `{ACTION}_PRE` run before the action.
|
|
|
|
* - `{ACTION}_POST` run after the action.
|
|
|
|
*
|
|
|
|
* Optional Additional Callbacks
|
|
|
|
* -----------------------------
|
|
|
|
*
|
|
|
|
* - `{ACTION}_INIT` when the handler may manipulate the context used to run the action.
|
|
|
|
*
|
|
|
|
* Examples where `INIT` functions may be useful are:
|
|
|
|
*
|
|
|
|
* - When rendering, an `INIT` function may change the camera or render settings,
|
|
|
|
* things which a `PRE` function can't support as this information has already been used.
|
|
|
|
* - When saving an `INIT` function could temporarily change the preferences.
|
|
|
|
*
|
|
|
|
* - `{ACTION}_POST_FAIL` should be included if the action may fail.
|
|
|
|
*
|
|
|
|
* Use this so a call to the `PRE` callback always has a matching call to `POST` or `POST_FAIL`.
|
|
|
|
*
|
|
|
|
* \note in most cases only `PRE/POST` are required.
|
|
|
|
*
|
|
|
|
* Callbacks for Background/Modal Tasks
|
|
|
|
* ====================================
|
|
|
|
*
|
|
|
|
* - `{ACTION}_INIT`
|
|
|
|
* - `{ACTION}_COMPLETE` when a background job has finished.
|
|
|
|
* - `{ACTION}_CANCEL` When a background job is canceled partway through.
|
|
|
|
*
|
|
|
|
* While cancellation may be caused by any number of reasons, common causes may include:
|
|
|
|
*
|
|
|
|
* - Explicit user cancellation.
|
|
|
|
* - Exiting Blender.
|
|
|
|
* - Failure to acquire resources (such as disk-full, out of memory ... etc).
|
|
|
|
*
|
|
|
|
* \note `PRE/POST` handlers may be used along side modal task handlers
|
|
|
|
* as is the case for rendering, where rendering an animation uses modal task handlers,
|
|
|
|
* rendering a single frame has `PRE/POST` handlers.
|
|
|
|
*
|
|
|
|
* Python Access
|
|
|
|
* =============
|
|
|
|
*
|
|
|
|
* All callbacks here must be exposed via the Python module `bpy.app.handlers`,
|
2023-07-31 03:50:54 +02:00
|
|
|
* see `bpy_app_handlers.cc`.
|
2014-08-29 08:17:31 +02:00
|
|
|
*/
|
2011-06-24 18:54:30 +02:00
|
|
|
typedef enum {
|
2019-09-05 15:52:38 +02:00
|
|
|
BKE_CB_EVT_FRAME_CHANGE_PRE,
|
|
|
|
BKE_CB_EVT_FRAME_CHANGE_POST,
|
|
|
|
BKE_CB_EVT_RENDER_PRE,
|
|
|
|
BKE_CB_EVT_RENDER_POST,
|
|
|
|
BKE_CB_EVT_RENDER_WRITE,
|
|
|
|
BKE_CB_EVT_RENDER_STATS,
|
|
|
|
BKE_CB_EVT_RENDER_INIT,
|
|
|
|
BKE_CB_EVT_RENDER_COMPLETE,
|
|
|
|
BKE_CB_EVT_RENDER_CANCEL,
|
|
|
|
BKE_CB_EVT_LOAD_PRE,
|
|
|
|
BKE_CB_EVT_LOAD_POST,
|
2023-03-09 00:46:49 +01:00
|
|
|
BKE_CB_EVT_LOAD_POST_FAIL,
|
2019-09-05 15:52:38 +02:00
|
|
|
BKE_CB_EVT_SAVE_PRE,
|
|
|
|
BKE_CB_EVT_SAVE_POST,
|
2023-03-09 00:46:49 +01:00
|
|
|
BKE_CB_EVT_SAVE_POST_FAIL,
|
2019-09-05 15:52:38 +02:00
|
|
|
BKE_CB_EVT_UNDO_PRE,
|
|
|
|
BKE_CB_EVT_UNDO_POST,
|
|
|
|
BKE_CB_EVT_REDO_PRE,
|
|
|
|
BKE_CB_EVT_REDO_POST,
|
|
|
|
BKE_CB_EVT_DEPSGRAPH_UPDATE_PRE,
|
|
|
|
BKE_CB_EVT_DEPSGRAPH_UPDATE_POST,
|
|
|
|
BKE_CB_EVT_VERSION_UPDATE,
|
|
|
|
BKE_CB_EVT_LOAD_FACTORY_USERDEF_POST,
|
|
|
|
BKE_CB_EVT_LOAD_FACTORY_STARTUP_POST,
|
2021-05-15 20:33:10 +02:00
|
|
|
BKE_CB_EVT_XR_SESSION_START_PRE,
|
2022-03-07 12:31:36 +01:00
|
|
|
BKE_CB_EVT_ANNOTATION_PRE,
|
|
|
|
BKE_CB_EVT_ANNOTATION_POST,
|
Expose background job info to Python
Add `bpy.app.is_job_running(job_type)` as high-level indicator. Job
types currently exposed are `WM_JOB_TYPE_RENDER`,
`WM_JOB_TYPE_RENDER_PREVIEW`, and `WM_JOB_TYPE_OBJECT_BAKE`, as strings
with the `WM_JOB_TYPE_` prefix removed. The functions can be polled by
Python code to determine whether such background work is still ongoing
or not.
Furthermore, new app handles are added for
`object_bake_{pre,complete,canceled}`, which are called respectively
before an object baking job starts, completes sucessfully, and stops due
to a cancellation.
Motivation: There are various cases where Python can trigger the
execution of a background job, without getting notification that that
background job is done. As a result, it's hard to do things like
cleanups, or auto-quitting Blender after the work is done.
The approach in this commit can easily be extended with other job types,
when the need arises. The rendering of asset previews is one that's
likely to be added sooner than later, as there have already been
requests about this.
Reviewed By: campbellbarton
Differential Revision: https://developer.blender.org/D14587
2022-06-02 11:20:17 +02:00
|
|
|
BKE_CB_EVT_OBJECT_BAKE_PRE,
|
|
|
|
BKE_CB_EVT_OBJECT_BAKE_COMPLETE,
|
|
|
|
BKE_CB_EVT_OBJECT_BAKE_CANCEL,
|
2022-05-31 10:22:43 +02:00
|
|
|
BKE_CB_EVT_COMPOSITE_PRE,
|
|
|
|
BKE_CB_EVT_COMPOSITE_POST,
|
|
|
|
BKE_CB_EVT_COMPOSITE_CANCEL,
|
2023-06-26 12:11:25 +02:00
|
|
|
BKE_CB_EVT_ANIMATION_PLAYBACK_PRE,
|
|
|
|
BKE_CB_EVT_ANIMATION_PLAYBACK_POST,
|
2023-08-09 12:15:34 +02:00
|
|
|
BKE_CB_EVT_EXTENSION_REPOS_UPDATE_PRE,
|
|
|
|
BKE_CB_EVT_EXTENSION_REPOS_UPDATE_POST,
|
2019-09-05 15:52:38 +02:00
|
|
|
BKE_CB_EVT_TOT,
|
2011-06-24 18:54:30 +02:00
|
|
|
} eCbEvent;
|
|
|
|
|
2013-03-24 02:19:55 +01:00
|
|
|
typedef struct bCallbackFuncStore {
|
2011-06-24 18:54:30 +02:00
|
|
|
struct bCallbackFuncStore *next, *prev;
|
2022-01-07 01:38:08 +01:00
|
|
|
void (*func)(struct Main *, struct PointerRNA **, int num_pointers, void *arg);
|
2011-06-24 18:54:30 +02:00
|
|
|
void *arg;
|
|
|
|
short alloc;
|
|
|
|
} bCallbackFuncStore;
|
|
|
|
|
2019-09-09 10:25:04 +02:00
|
|
|
void BKE_callback_exec(struct Main *bmain,
|
|
|
|
struct PointerRNA **pointers,
|
2022-01-07 01:38:08 +01:00
|
|
|
int num_pointers,
|
2019-09-09 10:25:04 +02:00
|
|
|
eCbEvent evt);
|
|
|
|
void BKE_callback_exec_null(struct Main *bmain, eCbEvent evt);
|
|
|
|
void BKE_callback_exec_id(struct Main *bmain, struct ID *id, eCbEvent evt);
|
|
|
|
void BKE_callback_exec_id_depsgraph(struct Main *bmain,
|
|
|
|
struct ID *id,
|
|
|
|
struct Depsgraph *depsgraph,
|
|
|
|
eCbEvent evt);
|
2023-03-09 00:46:49 +01:00
|
|
|
void BKE_callback_exec_string(struct Main *bmain, eCbEvent evt, const char *str);
|
2019-09-05 15:52:38 +02:00
|
|
|
void BKE_callback_add(bCallbackFuncStore *funcstore, eCbEvent evt);
|
2021-09-24 16:34:13 +02:00
|
|
|
void BKE_callback_remove(bCallbackFuncStore *funcstore, eCbEvent evt);
|
2002-10-12 13:37:38 +02:00
|
|
|
|
2019-09-05 15:52:38 +02:00
|
|
|
void BKE_callback_global_init(void);
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Call on application exit.
|
|
|
|
*/
|
2019-09-05 15:52:38 +02:00
|
|
|
void BKE_callback_global_finalize(void);
|
2011-06-24 18:54:30 +02:00
|
|
|
|
2020-03-02 15:07:49 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|