Blender V4.3
BKE_context.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
11#include <variant>
12
13/* XXX temporary, until AssetHandle is designed properly and queries can return a pointer to it. */
14#include "DNA_asset_types.h"
15
16#include "BLI_string_ref.hh"
17#include "BLI_utildefines.h"
18#include "BLI_vector.hh"
19
20#include "DNA_listBase.h"
21#include "DNA_object_enums.h"
22#include "RNA_types.hh"
23
24struct ARegion;
25struct Base;
26struct bGPdata;
27struct bGPDframe;
28struct bGPDlayer;
29struct bPoseChannel;
30struct bScreen;
31struct CacheFile;
32struct Collection;
33struct Depsgraph;
34struct EditBone;
35struct ID;
36struct Image;
37struct LayerCollection;
38struct ListBase;
39struct Main;
40struct Mask;
41struct MovieClip;
42struct Object;
43struct PointerRNA;
44struct RegionView3D;
45struct RenderEngineType;
46struct ReportList;
47struct Scene;
48struct ScrArea;
49struct SpaceAction;
50struct SpaceClip;
51struct SpaceClip;
52struct SpaceConsole;
53struct SpaceFile;
54struct SpaceGraph;
55struct SpaceImage;
56struct SpaceInfo;
57struct SpaceLink;
58struct SpaceNla;
59struct SpaceNode;
60struct SpaceOutliner;
61struct SpaceProperties;
62struct SpaceSeq;
63struct SpaceSpreadsheet;
64struct SpaceText;
65struct SpaceTopBar;
66struct SpaceUserPref;
67struct StructRNA;
68struct Text;
69struct ToolSettings;
70struct View3D;
71struct ViewLayer;
72struct wmGizmoGroup;
73struct wmMsgBus;
74struct wmWindow;
75struct wmWindowManager;
76struct WorkSpace;
77
78/* Structs */
79
80struct bContext;
81
83
84/* Result of context lookups.
85 * The specific values are important, and used implicitly in ctx_data_get(). Some functions also
86 * still accept/return `int` instead, to ensure that the compiler uses the correct storage size
87 * when mixing C/C++ code. */
89 /* The context member was found, and its data is available. */
91
92 /* The context member was not found. */
94
95 /* The context member was found, but its data is not available.
96 * For example, "active_bone" is a valid context member, but has not data in Object mode. */
98};
99
100/* Function mapping a context member name to its value. */
101using bContextDataCallback = int /*eContextResult*/ (*)(const bContext *C,
102 const char *member,
103 bContextDataResult *result);
104
106 std::string name;
107 std::variant<PointerRNA, std::string> value;
108};
109
114
115namespace blender::asset_system {
116class AssetRepresentation;
117}
118
119/* for the context's rna mode enum
120 * keep aligned with data_mode_strings in context.cc */
150#define CTX_MODE_NUM (CTX_MODE_VERTEX_GREASE_PENCIL + 1)
151
152/* Context */
153
155void CTX_free(bContext *C);
156
157bContext *CTX_copy(const bContext *C);
158
159/* Stored Context */
160
161bContextStore *CTX_store_add(blender::Vector<std::unique_ptr<bContextStore>> &contexts,
163 const PointerRNA *ptr);
164bContextStore *CTX_store_add(blender::Vector<std::unique_ptr<bContextStore>> &contexts,
167bContextStore *CTX_store_add_all(blender::Vector<std::unique_ptr<bContextStore>> &contexts,
168 const bContextStore *context);
169const bContextStore *CTX_store_get(const bContext *C);
170void CTX_store_set(bContext *C, const bContextStore *store);
173 const StructRNA *type = nullptr);
174std::optional<blender::StringRefNull> CTX_store_string_lookup(const bContextStore *store,
176
177/* need to store if python is initialized or not */
179void CTX_py_init_set(bContext *C, bool value);
180
181void *CTX_py_dict_get(const bContext *C);
182void *CTX_py_dict_get_orig(const bContext *C);
183
188void CTX_py_state_push(bContext *C, bContext_PyState *pystate, void *value);
190
191/* Window Manager Context */
192
197ScrArea *CTX_wm_area(const bContext *C);
200void *CTX_wm_region_data(const bContext *C);
205
206View3D *CTX_wm_view3d(const bContext *C);
224
226void CTX_wm_window_set(bContext *C, wmWindow *win);
227void CTX_wm_screen_set(bContext *C, bScreen *screen); /* to be removed */
228void CTX_wm_area_set(bContext *C, ScrArea *area);
229void CTX_wm_region_set(bContext *C, ARegion *region);
230void CTX_wm_region_popup_set(bContext *C, ARegion *region_popup);
232
240 char *(*get_fn)(bContext *C, void *user_data);
242 void (*free_fn)(bContext *C, void *user_data);
244};
245
246const char *CTX_wm_operator_poll_msg_get(bContext *C, bool *r_free);
247
259void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg);
262
263/* Data Context
264 *
265 * - The dir #ListBase consists of #LinkData items.
266 */
267
268/* data type, needed so we can tell between a NULL pointer and an empty list */
269enum {
274};
275
276PointerRNA CTX_data_pointer_get(const bContext *C, const char *member);
277PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type);
279 const char *member,
280 StructRNA *type);
282
292 const char *propname);
293
294std::optional<blender::StringRefNull> CTX_data_string_get(const bContext *C, const char *member);
295
302ListBase CTX_data_dir_get_ex(const bContext *C, bool use_store, bool use_rna, bool use_all);
304int /*eContextResult*/ CTX_data_get(const bContext *C,
305 const char *member,
306 PointerRNA *r_ptr,
308 PropertyRNA **r_prop,
309 int *r_index,
310 blender::StringRef *r_str,
311 short *r_type);
312
315void CTX_data_pointer_set(bContextDataResult *result, ID *id, StructRNA *type, void *data);
316
319void CTX_data_list_add(bContextDataResult *result, ID *id, StructRNA *type, void *data);
320
328void CTX_data_prop_set(bContextDataResult *result, PropertyRNA *prop, int index);
329
330void CTX_data_dir_set(bContextDataResult *result, const char **dir);
331
332void CTX_data_type_set(bContextDataResult *result, short type);
334
335bool CTX_data_equals(const char *member, const char *str);
336bool CTX_data_dir(const char *member);
337
338#define CTX_DATA_BEGIN(C, Type, instance, member) \
339 { \
340 blender::Vector<PointerRNA> ctx_data_list; \
341 CTX_data_##member(C, &ctx_data_list); \
342 for (PointerRNA & ctx_link : ctx_data_list) { \
343 Type instance = (Type)ctx_link.data;
344
345#define CTX_DATA_END \
346 } \
347 } \
348 (void)0
349
350#define CTX_DATA_BEGIN_WITH_ID(C, Type, instance, member, Type_id, instance_id) \
351 CTX_DATA_BEGIN (C, Type, instance, member) \
352 Type_id instance_id = (Type_id)ctx_link.owner_id;
353
354int ctx_data_list_count(const bContext *C,
355 bool (*func)(const bContext *, blender::Vector<PointerRNA> *));
356
357#define CTX_DATA_COUNT(C, member) ctx_data_list_count(C, CTX_data_##member)
358
359/* Data Context Members */
360
361Main *CTX_data_main(const bContext *C);
362Scene *CTX_data_scene(const bContext *C);
375
376const char *CTX_data_mode_string(const bContext *C);
378 const Object *ob,
379 eObjectMode object_mode);
381
382void CTX_data_main_set(bContext *C, Main *bmain);
383void CTX_data_scene_set(bContext *C, Scene *scene);
384
385/* Only Outliner currently! */
387
390
393
396
399
402
406
408
412
414
416
422
428
431
432bool CTX_wm_interface_locked(const bContext *C);
433
443Depsgraph *CTX_data_depsgraph_pointer(const bContext *C);
444
453
463
464/* Will Return NULL if depsgraph is not allocated yet.
465 * Only used by handful of operators which are run on file load.
466 */
467Depsgraph *CTX_data_depsgraph_on_load(const bContext *C);
short CTX_data_type_get(bContextDataResult *result)
SpaceGraph * CTX_wm_space_graph(const bContext *C)
Image * CTX_data_edit_image(const bContext *C)
blender::Vector< PointerRNA > CTX_data_collection_get(const bContext *C, const char *member)
bool CTX_data_selectable_bases(const bContext *C, blender::Vector< PointerRNA > *list)
Depsgraph * CTX_data_expect_evaluated_depsgraph(const bContext *C)
void CTX_data_main_set(bContext *C, Main *bmain)
PointerRNA CTX_data_pointer_get(const bContext *C, const char *member)
void CTX_wm_gizmo_group_set(bContext *C, wmGizmoGroup *gzgroup)
const char * CTX_data_mode_string(const bContext *C)
void CTX_py_state_push(bContext *C, bContext_PyState *pystate, void *value)
WorkSpace * CTX_wm_workspace(const bContext *C)
bContextStore * CTX_store_add_all(blender::Vector< std::unique_ptr< bContextStore > > &contexts, const bContextStore *context)
bool CTX_data_visible_bones(const bContext *C, blender::Vector< PointerRNA > *list)
bool CTX_wm_interface_locked(const bContext *C)
SpaceText * CTX_wm_space_text(const bContext *C)
void CTX_data_dir_set(bContextDataResult *result, const char **dir)
bool CTX_data_selected_bones(const bContext *C, blender::Vector< PointerRNA > *list)
bPoseChannel * CTX_data_active_pose_bone(const bContext *C)
PointerRNA CTX_data_pointer_get_type_silent(const bContext *C, const char *member, StructRNA *type)
SpaceUserPref * CTX_wm_space_userpref(const bContext *C)
SpaceTopBar * CTX_wm_space_topbar(const bContext *C)
void CTX_data_id_list_add(bContextDataResult *result, ID *id)
SpaceImage * CTX_wm_space_image(const bContext *C)
bContextStore * CTX_store_add(blender::Vector< std::unique_ptr< bContextStore > > &contexts, blender::StringRefNull name, const PointerRNA *ptr)
bool CTX_data_equals(const char *member, const char *str)
ReportList * CTX_wm_reports(const bContext *C)
bScreen * CTX_wm_screen(const bContext *C)
SpaceNla * CTX_wm_space_nla(const bContext *C)
bool CTX_data_visible_bases(const bContext *C, blender::Vector< PointerRNA > *list)
bool CTX_data_visible_objects(const bContext *C, blender::Vector< PointerRNA > *list)
Mask * CTX_data_edit_mask(const bContext *C)
bool CTX_py_init_get(bContext *C)
void CTX_data_prop_set(bContextDataResult *result, PropertyRNA *prop, int index)
void CTX_data_pointer_set(bContextDataResult *result, ID *id, StructRNA *type, void *data)
LayerCollection * CTX_data_layer_collection(const bContext *C)
bool CTX_data_selected_pose_bones_from_active_object(const bContext *C, blender::Vector< PointerRNA > *list)
SpaceOutliner * CTX_wm_space_outliner(const bContext *C)
CacheFile * CTX_data_edit_cachefile(const bContext *C)
MovieClip * CTX_data_edit_movieclip(const bContext *C)
bool CTX_data_dir(const char *member)
void CTX_data_id_pointer_set(bContextDataResult *result, ID *id)
void * CTX_wm_region_data(const bContext *C)
void CTX_py_state_pop(bContext *C, bContext_PyState *pystate)
SpaceAction * CTX_wm_space_action(const bContext *C)
SpaceConsole * CTX_wm_space_console(const bContext *C)
void CTX_wm_manager_set(bContext *C, wmWindowManager *wm)
ARegion * CTX_wm_region_popup(const bContext *C)
void CTX_wm_operator_poll_msg_clear(bContext *C)
void CTX_py_init_set(bContext *C, bool value)
SpaceFile * CTX_wm_space_file(const bContext *C)
eContextObjectMode
@ CTX_MODE_VERTEX_GPENCIL_LEGACY
@ CTX_MODE_WEIGHT_GPENCIL_LEGACY
@ CTX_MODE_EDIT_POINT_CLOUD
@ CTX_MODE_SCULPT_GPENCIL_LEGACY
@ CTX_MODE_PAINT_GREASE_PENCIL
@ CTX_MODE_PAINT_GPENCIL_LEGACY
@ CTX_MODE_EDIT_CURVE
@ CTX_MODE_PAINT_TEXTURE
@ CTX_MODE_EDIT_SURFACE
@ CTX_MODE_SCULPT_GREASE_PENCIL
@ CTX_MODE_PARTICLE
@ CTX_MODE_SCULPT
@ CTX_MODE_OBJECT
@ CTX_MODE_EDIT_MESH
@ CTX_MODE_EDIT_GREASE_PENCIL
@ CTX_MODE_SCULPT_CURVES
@ CTX_MODE_EDIT_TEXT
@ CTX_MODE_EDIT_CURVES
@ CTX_MODE_EDIT_ARMATURE
@ CTX_MODE_EDIT_LATTICE
@ CTX_MODE_WEIGHT_GREASE_PENCIL
@ CTX_MODE_VERTEX_GREASE_PENCIL
@ CTX_MODE_PAINT_VERTEX
@ CTX_MODE_EDIT_METABALL
@ CTX_MODE_PAINT_WEIGHT
@ CTX_MODE_EDIT_GPENCIL_LEGACY
@ CTX_MODE_POSE
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
SpaceNode * CTX_wm_space_node(const bContext *C)
bContext * CTX_copy(const bContext *C)
SpaceProperties * CTX_wm_space_properties(const bContext *C)
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
ScrArea * CTX_wm_area(const bContext *C)
wmWindow * CTX_wm_window(const bContext *C)
bool CTX_data_editable_bones(const bContext *C, blender::Vector< PointerRNA > *list)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
int(*)(const bContext *C, const char *member, bContextDataResult *result) bContextDataCallback
void CTX_free(bContext *C)
Object * CTX_data_active_object(const bContext *C)
ListBase CTX_data_dir_get(const bContext *C)
const AssetLibraryReference * CTX_wm_asset_library_ref(const bContext *C)
void CTX_wm_operator_poll_msg_set_dynamic(bContext *C, const bContextPollMsgDyn_Params *params)
int CTX_data_get(const bContext *C, const char *member, PointerRNA *r_ptr, blender::Vector< PointerRNA > *r_lb, PropertyRNA **r_prop, int *r_index, blender::StringRef *r_str, short *r_type)
Text * CTX_data_edit_text(const bContext *C)
ListBase CTX_data_dir_get_ex(const bContext *C, bool use_store, bool use_rna, bool use_all)
RenderEngineType * CTX_data_engine_type(const bContext *C)
eContextResult
@ CTX_RESULT_MEMBER_NOT_FOUND
@ CTX_RESULT_OK
@ CTX_RESULT_NO_DATA
SpaceLink * CTX_wm_space_data(const bContext *C)
void CTX_wm_screen_set(bContext *C, bScreen *screen)
void CTX_data_scene_set(bContext *C, Scene *scene)
Scene * CTX_data_scene(const bContext *C)
int ctx_data_list_count(const bContext *C, bool(*func)(const bContext *, blender::Vector< PointerRNA > *))
SpaceSeq * CTX_wm_space_seq(const bContext *C)
enum eContextObjectMode CTX_data_mode_enum_ex(const Object *obedit, const Object *ob, eObjectMode object_mode)
class blender::asset_system::AssetRepresentation * CTX_wm_asset(const bContext *C)
Object * CTX_data_edit_object(const bContext *C)
void CTX_data_list_add(bContextDataResult *result, ID *id, StructRNA *type, void *data)
bool CTX_data_selectable_objects(const bContext *C, blender::Vector< PointerRNA > *list)
Base * CTX_data_active_base(const bContext *C)
void CTX_wm_window_set(bContext *C, wmWindow *win)
bool CTX_data_selected_objects(const bContext *C, blender::Vector< PointerRNA > *list)
Main * CTX_data_main(const bContext *C)
bool CTX_data_selected_editable_objects(const bContext *C, blender::Vector< PointerRNA > *list)
bool CTX_data_visible_pose_bones(const bContext *C, blender::Vector< PointerRNA > *list)
bool CTX_data_editable_objects(const bContext *C, blender::Vector< PointerRNA > *list)
@ CTX_DATA_TYPE_PROPERTY
@ CTX_DATA_TYPE_POINTER
@ CTX_DATA_TYPE_COLLECTION
@ CTX_DATA_TYPE_STRING
bool CTX_data_editable_bases(const bContext *C, blender::Vector< PointerRNA > *list)
std::optional< blender::StringRefNull > CTX_store_string_lookup(const bContextStore *store, blender::StringRefNull name)
void * CTX_py_dict_get_orig(const bContext *C)
const bContextStore * CTX_store_get(const bContext *C)
void CTX_data_list_add_ptr(bContextDataResult *result, const PointerRNA *ptr)
const PointerRNA * CTX_store_ptr_lookup(const bContextStore *store, blender::StringRefNull name, const StructRNA *type=nullptr)
bool CTX_data_selected_nodes(const bContext *C, blender::Vector< PointerRNA > *list)
const char * CTX_wm_operator_poll_msg_get(bContext *C, bool *r_free)
void CTX_data_pointer_set_ptr(bContextDataResult *result, const PointerRNA *ptr)
void CTX_store_set(bContext *C, const bContextStore *store)
wmGizmoGroup * CTX_wm_gizmo_group(const bContext *C)
ToolSettings * CTX_data_tool_settings(const bContext *C)
bool CTX_data_selected_editable_bases(const bContext *C, blender::Vector< PointerRNA > *list)
SpaceInfo * CTX_wm_space_info(const bContext *C)
bool CTX_data_selected_pose_bones(const bContext *C, blender::Vector< PointerRNA > *list)
void CTX_data_collection_remap_property(blender::MutableSpan< PointerRNA > collection_pointers, const char *propname)
void CTX_wm_area_set(bContext *C, ScrArea *area)
SpaceClip * CTX_wm_space_clip(const bContext *C)
bool CTX_data_selected_bases(const bContext *C, blender::Vector< PointerRNA > *list)
EditBone * CTX_data_active_bone(const bContext *C)
void CTX_wm_region_set(bContext *C, ARegion *region)
RegionView3D * CTX_wm_region_view3d(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
Collection * CTX_data_collection(const bContext *C)
bool CTX_data_selected_editable_bones(const bContext *C, blender::Vector< PointerRNA > *list)
void * CTX_py_dict_get(const bContext *C)
Depsgraph * CTX_data_depsgraph_on_load(const bContext *C)
SpaceSpreadsheet * CTX_wm_space_spreadsheet(const bContext *C)
wmWindowManager * CTX_wm_manager(const bContext *C)
bContext * CTX_create()
std::optional< blender::StringRefNull > CTX_data_string_get(const bContext *C, const char *member)
wmMsgBus * CTX_wm_message_bus(const bContext *C)
void CTX_data_type_set(bContextDataResult *result, short type)
void CTX_wm_region_popup_set(bContext *C, ARegion *region_popup)
View3D * CTX_wm_view3d(const bContext *C)
enum eContextObjectMode CTX_data_mode_enum(const bContext *C)
ViewLayer * CTX_data_view_layer(const bContext *C)
bool CTX_data_selected_ids(const bContext *C, blender::Vector< PointerRNA > *list)
These structs are the foundation for all linked lists in the library system.
eObjectMode
#define C
Definition RandGen.cpp:29
#define str(s)
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
Definition DNA_ID.h:413
void(* free_fn)(bContext *C, void *user_data)
std::variant< PointerRNA, std::string > value
blender::Vector< bContextStoreEntry > entries
PointerRNA * ptr
Definition wm_files.cc:4126