Blender V4.5
rna_context.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstdlib>
10
11#include "BKE_context.hh"
12
13#include "RNA_define.hh"
14#include "RNA_enum_types.hh"
15
16#include "rna_internal.hh" /* own include */
17
19 {CTX_MODE_EDIT_MESH, "EDIT_MESH", 0, "Mesh Edit", ""},
20 {CTX_MODE_EDIT_CURVE, "EDIT_CURVE", 0, "Curve Edit", ""},
21 {CTX_MODE_EDIT_CURVES, "EDIT_CURVES", 0, "Curves Edit", ""},
22 {CTX_MODE_EDIT_SURFACE, "EDIT_SURFACE", 0, "Surface Edit", ""},
23 {CTX_MODE_EDIT_TEXT, "EDIT_TEXT", 0, "Text Edit", ""},
24 /* PARSKEL reuse will give issues */
25 {CTX_MODE_EDIT_ARMATURE, "EDIT_ARMATURE", 0, "Armature Edit", ""},
26 {CTX_MODE_EDIT_METABALL, "EDIT_METABALL", 0, "Metaball Edit", ""},
27 {CTX_MODE_EDIT_LATTICE, "EDIT_LATTICE", 0, "Lattice Edit", ""},
28 {CTX_MODE_EDIT_GREASE_PENCIL, "EDIT_GREASE_PENCIL", 0, "Grease Pencil Edit", ""},
29 {CTX_MODE_EDIT_POINTCLOUD, "EDIT_POINTCLOUD", 0, "Point Cloud Edit", ""},
30 {CTX_MODE_POSE, "POSE", 0, "Pose", ""},
31 {CTX_MODE_SCULPT, "SCULPT", 0, "Sculpt", ""},
32 {CTX_MODE_PAINT_WEIGHT, "PAINT_WEIGHT", 0, "Weight Paint", ""},
33 {CTX_MODE_PAINT_VERTEX, "PAINT_VERTEX", 0, "Vertex Paint", ""},
34 {CTX_MODE_PAINT_TEXTURE, "PAINT_TEXTURE", 0, "Texture Paint", ""},
35 {CTX_MODE_PARTICLE, "PARTICLE", 0, "Particle", ""},
36 {CTX_MODE_OBJECT, "OBJECT", 0, "Object", ""},
37 {CTX_MODE_PAINT_GPENCIL_LEGACY, "PAINT_GPENCIL", 0, "Grease Pencil Paint", ""},
38 {CTX_MODE_EDIT_GPENCIL_LEGACY, "EDIT_GPENCIL", 0, "Grease Pencil Edit", ""},
39 {CTX_MODE_SCULPT_GPENCIL_LEGACY, "SCULPT_GPENCIL", 0, "Grease Pencil Sculpt", ""},
40 {CTX_MODE_WEIGHT_GPENCIL_LEGACY, "WEIGHT_GPENCIL", 0, "Grease Pencil Weight Paint", ""},
41 {CTX_MODE_VERTEX_GPENCIL_LEGACY, "VERTEX_GPENCIL", 0, "Grease Pencil Vertex Paint", ""},
42 {CTX_MODE_SCULPT_CURVES, "SCULPT_CURVES", 0, "Curves Sculpt", ""},
43 {CTX_MODE_PAINT_GREASE_PENCIL, "PAINT_GREASE_PENCIL", 0, "Grease Pencil Paint", ""},
44 {CTX_MODE_SCULPT_GREASE_PENCIL, "SCULPT_GREASE_PENCIL", 0, "Grease Pencil Sculpt", ""},
45 {CTX_MODE_WEIGHT_GREASE_PENCIL, "WEIGHT_GREASE_PENCIL", 0, "Grease Pencil Weight Paint", ""},
46 {CTX_MODE_VERTEX_GREASE_PENCIL, "VERTEX_GREASE_PENCIL", 0, "Grease Pencil Vertex Paint", ""},
47 {0, nullptr, 0, nullptr, nullptr},
48};
49
50#ifdef RNA_RUNTIME
51
52# include "DNA_asset_types.h"
53# include "DNA_userdef_types.h"
54
55# ifdef WITH_PYTHON
56# include "BPY_extern.hh"
57# endif
58
59# include "RE_engine.h"
60
61static PointerRNA rna_Context_manager_get(PointerRNA *ptr)
62{
63 bContext *C = (bContext *)ptr->data;
64 return RNA_id_pointer_create(reinterpret_cast<ID *>(CTX_wm_manager(C)));
65}
66
67static PointerRNA rna_Context_window_get(PointerRNA *ptr)
68{
69 bContext *C = (bContext *)ptr->data;
71 reinterpret_cast<ID *>(CTX_wm_manager(C)), &RNA_Window, CTX_wm_window(C));
72}
73
74static PointerRNA rna_Context_workspace_get(PointerRNA *ptr)
75{
76 bContext *C = (bContext *)ptr->data;
77 return RNA_id_pointer_create(reinterpret_cast<ID *>(CTX_wm_workspace(C)));
78}
79
80static PointerRNA rna_Context_screen_get(PointerRNA *ptr)
81{
82 bContext *C = (bContext *)ptr->data;
83 return RNA_id_pointer_create(reinterpret_cast<ID *>(CTX_wm_screen(C)));
84}
85
86static PointerRNA rna_Context_area_get(PointerRNA *ptr)
87{
88 bContext *C = (bContext *)ptr->data;
90 (ID *)CTX_wm_screen(C), &RNA_Area, CTX_wm_area(C));
91 return newptr;
92}
93
94static PointerRNA rna_Context_space_data_get(PointerRNA *ptr)
95{
96 bContext *C = (bContext *)ptr->data;
98 (ID *)CTX_wm_screen(C), &RNA_Space, CTX_wm_space_data(C));
99 return newptr;
100}
101
102static PointerRNA rna_Context_region_get(PointerRNA *ptr)
103{
104 bContext *C = (bContext *)ptr->data;
106 (ID *)CTX_wm_screen(C), &RNA_Region, CTX_wm_region(C));
107 return newptr;
108}
109
110static PointerRNA rna_Context_region_data_get(PointerRNA *ptr)
111{
112 bContext *C = (bContext *)ptr->data;
113
114 /* only exists for one space still, no generic system yet */
115 if (CTX_wm_view3d(C)) {
117 (ID *)CTX_wm_screen(C), &RNA_RegionView3D, CTX_wm_region_data(C));
118 return newptr;
119 }
120
121 return PointerRNA_NULL;
122}
123
124static PointerRNA rna_Context_region_popup_get(PointerRNA *ptr)
125{
126 bContext *C = (bContext *)ptr->data;
128 (ID *)CTX_wm_screen(C), &RNA_Region, CTX_wm_region_popup(C));
129 return newptr;
130}
131
132static PointerRNA rna_Context_gizmo_group_get(PointerRNA *ptr)
133{
134 bContext *C = (bContext *)ptr->data;
135 PointerRNA newptr = RNA_pointer_create_discrete(nullptr, &RNA_GizmoGroup, CTX_wm_gizmo_group(C));
136 return newptr;
137}
138
139static PointerRNA rna_Context_asset_get(PointerRNA *ptr)
140{
141 bContext *C = (bContext *)ptr->data;
142 return RNA_pointer_create_discrete(nullptr, &RNA_AssetRepresentation, CTX_wm_asset(C));
143}
144
145static PointerRNA rna_Context_main_get(PointerRNA *ptr)
146{
147 bContext *C = (bContext *)ptr->data;
149}
150
151static PointerRNA rna_Context_scene_get(PointerRNA *ptr)
152{
153 bContext *C = (bContext *)ptr->data;
154 return RNA_id_pointer_create(reinterpret_cast<ID *>(CTX_data_scene(C)));
155}
156
157static PointerRNA rna_Context_view_layer_get(PointerRNA *ptr)
158{
159 bContext *C = (bContext *)ptr->data;
161 *reinterpret_cast<ID *>(CTX_data_scene(C)), &RNA_ViewLayer, CTX_data_view_layer(C));
162}
163
164static void rna_Context_engine_get(PointerRNA *ptr, char *value)
165{
166 bContext *C = (bContext *)ptr->data;
168 strcpy(value, engine_type->idname);
169}
170
171static int rna_Context_engine_length(PointerRNA *ptr)
172{
173 bContext *C = (bContext *)ptr->data;
175 return strlen(engine_type->idname);
176}
177
178static PointerRNA rna_Context_collection_get(PointerRNA *ptr)
179{
180 bContext *C = (bContext *)ptr->data;
181 return RNA_id_pointer_create(reinterpret_cast<ID *>(CTX_data_collection(C)));
182}
183
184static PointerRNA rna_Context_layer_collection_get(PointerRNA *ptr)
185{
186 bContext *C = (bContext *)ptr->data;
187 return RNA_pointer_create_discrete(reinterpret_cast<ID *>(CTX_data_scene(C)),
188 &RNA_LayerCollection,
190}
191
192static PointerRNA rna_Context_tool_settings_get(PointerRNA *ptr)
193{
194 bContext *C = (bContext *)ptr->data;
196 *reinterpret_cast<ID *>(CTX_data_scene(C)), &RNA_ToolSettings, CTX_data_tool_settings(C));
197}
198
199static PointerRNA rna_Context_preferences_get(PointerRNA * /*ptr*/)
200{
201 PointerRNA newptr = RNA_pointer_create_discrete(nullptr, &RNA_Preferences, &U);
202 return newptr;
203}
204
205static int rna_Context_mode_get(PointerRNA *ptr)
206{
207 bContext *C = (bContext *)ptr->data;
208 return CTX_data_mode_enum(C);
209}
210
211static Depsgraph *rna_Context_evaluated_depsgraph_get(bContext *C)
212{
213 Depsgraph *depsgraph;
214
215# ifdef WITH_PYTHON
216 /* Allow drivers to be evaluated */
218# endif
219
221
222# ifdef WITH_PYTHON
224# endif
225
226 return depsgraph;
227}
228
229#else
230
232{
233 StructRNA *srna;
234 PropertyRNA *prop;
235
236 FunctionRNA *func;
237 PropertyRNA *parm;
238
239 srna = RNA_def_struct(brna, "Context", nullptr);
240 RNA_def_struct_ui_text(srna, "Context", "Current windowmanager and data context");
241 RNA_def_struct_sdna(srna, "bContext");
242
243 /* WM */
244 prop = RNA_def_property(srna, "window_manager", PROP_POINTER, PROP_NONE);
246 RNA_def_property_struct_type(prop, "WindowManager");
247 RNA_def_property_pointer_funcs(prop, "rna_Context_manager_get", nullptr, nullptr, nullptr);
248
249 prop = RNA_def_property(srna, "window", PROP_POINTER, PROP_NONE);
251 RNA_def_property_struct_type(prop, "Window");
252 RNA_def_property_pointer_funcs(prop, "rna_Context_window_get", nullptr, nullptr, nullptr);
253
254 prop = RNA_def_property(srna, "workspace", PROP_POINTER, PROP_NONE);
256 RNA_def_property_struct_type(prop, "WorkSpace");
257 RNA_def_property_pointer_funcs(prop, "rna_Context_workspace_get", nullptr, nullptr, nullptr);
258
259 prop = RNA_def_property(srna, "screen", PROP_POINTER, PROP_NONE);
261 RNA_def_property_struct_type(prop, "Screen");
262 RNA_def_property_pointer_funcs(prop, "rna_Context_screen_get", nullptr, nullptr, nullptr);
263
264 prop = RNA_def_property(srna, "area", PROP_POINTER, PROP_NONE);
266 RNA_def_property_struct_type(prop, "Area");
267 RNA_def_property_pointer_funcs(prop, "rna_Context_area_get", nullptr, nullptr, nullptr);
268
269 prop = RNA_def_property(srna, "space_data", PROP_POINTER, PROP_NONE);
271 RNA_def_property_struct_type(prop, "Space");
272 RNA_def_property_pointer_funcs(prop, "rna_Context_space_data_get", nullptr, nullptr, nullptr);
274 "",
275 "The current space, may be None in background-mode, "
276 "when the cursor is outside the window or "
277 "when using menu-search");
278
279 prop = RNA_def_property(srna, "region", PROP_POINTER, PROP_NONE);
281 RNA_def_property_struct_type(prop, "Region");
282 RNA_def_property_pointer_funcs(prop, "rna_Context_region_get", nullptr, nullptr, nullptr);
283
284 prop = RNA_def_property(srna, "region_popup", PROP_POINTER, PROP_NONE);
286 RNA_def_property_struct_type(prop, "Region");
287 RNA_def_property_pointer_funcs(prop, "rna_Context_region_popup_get", nullptr, nullptr, nullptr);
289 prop, "Popup Region", "The temporary region for pop-ups (including menus and pop-overs)");
290
291 prop = RNA_def_property(srna, "region_data", PROP_POINTER, PROP_NONE);
293 RNA_def_property_struct_type(prop, "RegionView3D");
294 RNA_def_property_pointer_funcs(prop, "rna_Context_region_data_get", nullptr, nullptr, nullptr);
295
296 prop = RNA_def_property(srna, "gizmo_group", PROP_POINTER, PROP_NONE);
298 RNA_def_property_struct_type(prop, "GizmoGroup");
299 RNA_def_property_pointer_funcs(prop, "rna_Context_gizmo_group_get", nullptr, nullptr, nullptr);
300
301 prop = RNA_def_property(srna, "asset", PROP_POINTER, PROP_NONE);
303 RNA_def_property_struct_type(prop, "AssetRepresentation");
304 RNA_def_property_pointer_funcs(prop, "rna_Context_asset_get", nullptr, nullptr, nullptr);
305
306 /* Data */
307 prop = RNA_def_property(srna, "blend_data", PROP_POINTER, PROP_NONE);
309 RNA_def_property_struct_type(prop, "BlendData");
310 RNA_def_property_pointer_funcs(prop, "rna_Context_main_get", nullptr, nullptr, nullptr);
311
312 prop = RNA_def_property(srna, "scene", PROP_POINTER, PROP_NONE);
314 RNA_def_property_struct_type(prop, "Scene");
315 RNA_def_property_pointer_funcs(prop, "rna_Context_scene_get", nullptr, nullptr, nullptr);
316
317 prop = RNA_def_property(srna, "view_layer", PROP_POINTER, PROP_NONE);
319 RNA_def_property_struct_type(prop, "ViewLayer");
320 RNA_def_property_pointer_funcs(prop, "rna_Context_view_layer_get", nullptr, nullptr, nullptr);
321
322 prop = RNA_def_property(srna, "engine", PROP_STRING, PROP_NONE);
325 prop, "rna_Context_engine_get", "rna_Context_engine_length", nullptr);
326
327 prop = RNA_def_property(srna, "collection", PROP_POINTER, PROP_NONE);
329 RNA_def_property_struct_type(prop, "Collection");
330 RNA_def_property_pointer_funcs(prop, "rna_Context_collection_get", nullptr, nullptr, nullptr);
331
332 prop = RNA_def_property(srna, "layer_collection", PROP_POINTER, PROP_NONE);
334 RNA_def_property_struct_type(prop, "LayerCollection");
336 prop, "rna_Context_layer_collection_get", nullptr, nullptr, nullptr);
337
338 prop = RNA_def_property(srna, "tool_settings", PROP_POINTER, PROP_NONE);
340 RNA_def_property_struct_type(prop, "ToolSettings");
341 RNA_def_property_pointer_funcs(prop, "rna_Context_tool_settings_get", nullptr, nullptr, nullptr);
342
343 prop = RNA_def_property(srna, "preferences", PROP_POINTER, PROP_NONE);
345 RNA_def_property_struct_type(prop, "Preferences");
346 RNA_def_property_pointer_funcs(prop, "rna_Context_preferences_get", nullptr, nullptr, nullptr);
347
348 prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
351 RNA_def_property_enum_funcs(prop, "rna_Context_mode_get", nullptr, nullptr);
352
353 func = RNA_def_function(srna, "evaluated_depsgraph_get", "rna_Context_evaluated_depsgraph_get");
355 func,
356 "Get the dependency graph for the current scene and view layer, to access to data-blocks "
357 "with animation and modifiers applied. If any data-blocks have been edited, the dependency "
358 "graph will be updated. This invalidates all references to evaluated data-blocks from the "
359 "dependency graph.");
360 parm = RNA_def_pointer(func, "depsgraph", "Depsgraph", "", "Evaluated dependency graph");
361 RNA_def_function_return(func, parm);
362}
363
364#endif
WorkSpace * CTX_wm_workspace(const bContext *C)
bScreen * CTX_wm_screen(const bContext *C)
LayerCollection * CTX_data_layer_collection(const bContext *C)
void * CTX_wm_region_data(const bContext *C)
ARegion * CTX_wm_region_popup(const bContext *C)
@ CTX_MODE_VERTEX_GPENCIL_LEGACY
@ CTX_MODE_WEIGHT_GPENCIL_LEGACY
@ 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_POINTCLOUD
@ 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
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
ScrArea * CTX_wm_area(const bContext *C)
wmWindow * CTX_wm_window(const bContext *C)
RenderEngineType * CTX_data_engine_type(const bContext *C)
SpaceLink * CTX_wm_space_data(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
class blender::asset_system::AssetRepresentation * CTX_wm_asset(const bContext *C)
Main * CTX_data_main(const bContext *C)
wmGizmoGroup * CTX_wm_gizmo_group(const bContext *C)
ToolSettings * CTX_data_tool_settings(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
Collection * CTX_data_collection(const bContext *C)
wmWindowManager * CTX_wm_manager(const bContext *C)
View3D * CTX_wm_view3d(const bContext *C)
enum eContextObjectMode CTX_data_mode_enum(const bContext *C)
ViewLayer * CTX_data_view_layer(const bContext *C)
#define BPy_BEGIN_ALLOW_THREADS
Definition BPY_extern.hh:51
#define BPy_END_ALLOW_THREADS
Definition BPY_extern.hh:55
@ PROP_ENUM
Definition RNA_types.hh:154
@ PROP_STRING
Definition RNA_types.hh:153
@ PROP_POINTER
Definition RNA_types.hh:155
@ PROP_EDITABLE
Definition RNA_types.hh:292
@ PROP_NONE
Definition RNA_types.hh:221
#define C
Definition RandGen.cpp:29
#define U
BPy_StructRNA * depsgraph
PointerRNA RNA_pointer_create_id_subdata(ID &id, StructRNA *type, void *data)
const PointerRNA PointerRNA_NULL
PointerRNA RNA_main_pointer_create(Main *main)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
PointerRNA RNA_id_pointer_create(ID *id)
const EnumPropertyItem rna_enum_context_mode_items[]
void RNA_def_context(BlenderRNA *brna)
void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set)
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item)
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *type_fn, const char *poll)
Definition DNA_ID.h:404
char idname[64]
Definition RE_engine.h:74
PointerRNA * ptr
Definition wm_files.cc:4226