Blender  V2.93
rna_context.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include <stdlib.h>
22 
23 #include "DNA_ID.h"
24 #include "DNA_userdef_types.h"
25 
26 #include "BKE_context.h"
27 #include "BLI_utildefines.h"
28 
29 #include "RNA_access.h"
30 #include "RNA_define.h"
31 #include "RNA_enum_types.h"
32 
33 #include "rna_internal.h" /* own include */
34 
36  {CTX_MODE_EDIT_MESH, "EDIT_MESH", 0, "Mesh Edit", ""},
37  {CTX_MODE_EDIT_CURVE, "EDIT_CURVE", 0, "Curve Edit", ""},
38  {CTX_MODE_EDIT_SURFACE, "EDIT_SURFACE", 0, "Surface Edit", ""},
39  {CTX_MODE_EDIT_TEXT, "EDIT_TEXT", 0, "Edit Edit", ""},
40  /* PARSKEL reuse will give issues */
41  {CTX_MODE_EDIT_ARMATURE, "EDIT_ARMATURE", 0, "Armature Edit", ""},
42  {CTX_MODE_EDIT_METABALL, "EDIT_METABALL", 0, "Metaball Edit", ""},
43  {CTX_MODE_EDIT_LATTICE, "EDIT_LATTICE", 0, "Lattice Edit", ""},
44  {CTX_MODE_POSE, "POSE", 0, "Pose", ""},
45  {CTX_MODE_SCULPT, "SCULPT", 0, "Sculpt", ""},
46  {CTX_MODE_PAINT_WEIGHT, "PAINT_WEIGHT", 0, "Weight Paint", ""},
47  {CTX_MODE_PAINT_VERTEX, "PAINT_VERTEX", 0, "Vertex Paint", ""},
48  {CTX_MODE_PAINT_TEXTURE, "PAINT_TEXTURE", 0, "Texture Paint", ""},
49  {CTX_MODE_PARTICLE, "PARTICLE", 0, "Particle", ""},
50  {CTX_MODE_OBJECT, "OBJECT", 0, "Object", ""},
51  {CTX_MODE_PAINT_GPENCIL, "PAINT_GPENCIL", 0, "Grease Pencil Paint", ""},
52  {CTX_MODE_EDIT_GPENCIL, "EDIT_GPENCIL", 0, "Grease Pencil Edit", ""},
53  {CTX_MODE_SCULPT_GPENCIL, "SCULPT_GPENCIL", 0, "Grease Pencil Sculpt", ""},
54  {CTX_MODE_WEIGHT_GPENCIL, "WEIGHT_GPENCIL", 0, "Grease Pencil Weight Paint", ""},
55  {CTX_MODE_VERTEX_GPENCIL, "VERTEX_GPENCIL", 0, "Grease Pencil Vertex Paint", ""},
56  {0, NULL, 0, NULL, NULL},
57 };
58 
59 #ifdef RNA_RUNTIME
60 
61 # ifdef WITH_PYTHON
62 # include "BPY_extern.h"
63 # endif
64 
65 # include "RE_engine.h"
66 
67 static PointerRNA rna_Context_manager_get(PointerRNA *ptr)
68 {
69  bContext *C = (bContext *)ptr->data;
71 }
72 
73 static PointerRNA rna_Context_window_get(PointerRNA *ptr)
74 {
75  bContext *C = (bContext *)ptr->data;
77 }
78 
79 static PointerRNA rna_Context_workspace_get(PointerRNA *ptr)
80 {
81  bContext *C = (bContext *)ptr->data;
83 }
84 
85 static PointerRNA rna_Context_screen_get(PointerRNA *ptr)
86 {
87  bContext *C = (bContext *)ptr->data;
89 }
90 
91 static PointerRNA rna_Context_area_get(PointerRNA *ptr)
92 {
93  bContext *C = (bContext *)ptr->data;
94  PointerRNA newptr;
96  return newptr;
97 }
98 
99 static PointerRNA rna_Context_space_data_get(PointerRNA *ptr)
100 {
101  bContext *C = (bContext *)ptr->data;
102  PointerRNA newptr;
104  return newptr;
105 }
106 
107 static PointerRNA rna_Context_region_get(PointerRNA *ptr)
108 {
109  bContext *C = (bContext *)ptr->data;
110  PointerRNA newptr;
112  return newptr;
113 }
114 
115 static PointerRNA rna_Context_region_data_get(PointerRNA *ptr)
116 {
117  bContext *C = (bContext *)ptr->data;
118 
119  /* only exists for one space still, no generic system yet */
120  if (CTX_wm_view3d(C)) {
121  PointerRNA newptr;
122  RNA_pointer_create((ID *)CTX_wm_screen(C), &RNA_RegionView3D, CTX_wm_region_data(C), &newptr);
123  return newptr;
124  }
125 
126  return PointerRNA_NULL;
127 }
128 
129 static PointerRNA rna_Context_gizmo_group_get(PointerRNA *ptr)
130 {
131  bContext *C = (bContext *)ptr->data;
132  PointerRNA newptr;
133  RNA_pointer_create(NULL, &RNA_GizmoGroup, CTX_wm_gizmo_group(C), &newptr);
134  return newptr;
135 }
136 
137 static PointerRNA rna_Context_main_get(PointerRNA *ptr)
138 {
139  bContext *C = (bContext *)ptr->data;
141 }
142 
143 static PointerRNA rna_Context_scene_get(PointerRNA *ptr)
144 {
145  bContext *C = (bContext *)ptr->data;
147 }
148 
149 static PointerRNA rna_Context_view_layer_get(PointerRNA *ptr)
150 {
151  bContext *C = (bContext *)ptr->data;
153  PointerRNA scene_ptr;
154 
155  RNA_id_pointer_create(&scene->id, &scene_ptr);
157 }
158 
159 static void rna_Context_engine_get(PointerRNA *ptr, char *value)
160 {
161  bContext *C = (bContext *)ptr->data;
162  RenderEngineType *engine_type = CTX_data_engine_type(C);
163  strcpy(value, engine_type->idname);
164 }
165 
166 static int rna_Context_engine_length(PointerRNA *ptr)
167 {
168  bContext *C = (bContext *)ptr->data;
169  RenderEngineType *engine_type = CTX_data_engine_type(C);
170  return strlen(engine_type->idname);
171 }
172 
173 static PointerRNA rna_Context_collection_get(PointerRNA *ptr)
174 {
175  bContext *C = (bContext *)ptr->data;
177 }
178 
179 static PointerRNA rna_Context_layer_collection_get(PointerRNA *ptr)
180 {
181  bContext *C = (bContext *)ptr->data;
184 }
185 
186 static PointerRNA rna_Context_tool_settings_get(PointerRNA *ptr)
187 {
188  bContext *C = (bContext *)ptr->data;
191 }
192 
193 static PointerRNA rna_Context_preferences_get(PointerRNA *UNUSED(ptr))
194 {
195  PointerRNA newptr;
197  return newptr;
198 }
199 
200 static int rna_Context_mode_get(PointerRNA *ptr)
201 {
202  bContext *C = (bContext *)ptr->data;
203  return CTX_data_mode_enum(C);
204 }
205 
206 static struct Depsgraph *rna_Context_evaluated_depsgraph_get(bContext *C)
207 {
208  struct Depsgraph *depsgraph;
209 
210 # ifdef WITH_PYTHON
211  /* Allow drivers to be evaluated */
213 # endif
214 
216 
217 # ifdef WITH_PYTHON
219 # endif
220 
221  return depsgraph;
222 }
223 
224 #else
225 
227 {
228  StructRNA *srna;
229  PropertyRNA *prop;
230 
231  FunctionRNA *func;
232  PropertyRNA *parm;
233 
234  srna = RNA_def_struct(brna, "Context", NULL);
235  RNA_def_struct_ui_text(srna, "Context", "Current windowmanager and data context");
236  RNA_def_struct_sdna(srna, "bContext");
237 
238  /* WM */
239  prop = RNA_def_property(srna, "window_manager", PROP_POINTER, PROP_NONE);
241  RNA_def_property_struct_type(prop, "WindowManager");
242  RNA_def_property_pointer_funcs(prop, "rna_Context_manager_get", NULL, NULL, NULL);
243 
244  prop = RNA_def_property(srna, "window", PROP_POINTER, PROP_NONE);
246  RNA_def_property_struct_type(prop, "Window");
247  RNA_def_property_pointer_funcs(prop, "rna_Context_window_get", NULL, NULL, NULL);
248 
249  prop = RNA_def_property(srna, "workspace", PROP_POINTER, PROP_NONE);
251  RNA_def_property_struct_type(prop, "WorkSpace");
252  RNA_def_property_pointer_funcs(prop, "rna_Context_workspace_get", NULL, NULL, NULL);
253 
254  prop = RNA_def_property(srna, "screen", PROP_POINTER, PROP_NONE);
256  RNA_def_property_struct_type(prop, "Screen");
257  RNA_def_property_pointer_funcs(prop, "rna_Context_screen_get", NULL, NULL, NULL);
258 
259  prop = RNA_def_property(srna, "area", PROP_POINTER, PROP_NONE);
261  RNA_def_property_struct_type(prop, "Area");
262  RNA_def_property_pointer_funcs(prop, "rna_Context_area_get", NULL, NULL, NULL);
263 
264  prop = RNA_def_property(srna, "space_data", PROP_POINTER, PROP_NONE);
266  RNA_def_property_struct_type(prop, "Space");
267  RNA_def_property_pointer_funcs(prop, "rna_Context_space_data_get", NULL, NULL, NULL);
268 
269  prop = RNA_def_property(srna, "region", PROP_POINTER, PROP_NONE);
271  RNA_def_property_struct_type(prop, "Region");
272  RNA_def_property_pointer_funcs(prop, "rna_Context_region_get", NULL, NULL, NULL);
273 
274  prop = RNA_def_property(srna, "region_data", PROP_POINTER, PROP_NONE);
276  RNA_def_property_struct_type(prop, "RegionView3D");
277  RNA_def_property_pointer_funcs(prop, "rna_Context_region_data_get", NULL, NULL, NULL);
278 
279  prop = RNA_def_property(srna, "gizmo_group", PROP_POINTER, PROP_NONE);
281  RNA_def_property_struct_type(prop, "GizmoGroup");
282  RNA_def_property_pointer_funcs(prop, "rna_Context_gizmo_group_get", NULL, NULL, NULL);
283 
284  /* Data */
285  prop = RNA_def_property(srna, "blend_data", PROP_POINTER, PROP_NONE);
287  RNA_def_property_struct_type(prop, "BlendData");
288  RNA_def_property_pointer_funcs(prop, "rna_Context_main_get", NULL, NULL, NULL);
289 
290  prop = RNA_def_property(srna, "scene", PROP_POINTER, PROP_NONE);
292  RNA_def_property_struct_type(prop, "Scene");
293  RNA_def_property_pointer_funcs(prop, "rna_Context_scene_get", NULL, NULL, NULL);
294 
295  prop = RNA_def_property(srna, "view_layer", PROP_POINTER, PROP_NONE);
297  RNA_def_property_struct_type(prop, "ViewLayer");
298  RNA_def_property_pointer_funcs(prop, "rna_Context_view_layer_get", NULL, NULL, NULL);
299 
300  prop = RNA_def_property(srna, "engine", PROP_STRING, PROP_NONE);
302  RNA_def_property_string_funcs(prop, "rna_Context_engine_get", "rna_Context_engine_length", NULL);
303 
304  prop = RNA_def_property(srna, "collection", PROP_POINTER, PROP_NONE);
306  RNA_def_property_struct_type(prop, "Collection");
307  RNA_def_property_pointer_funcs(prop, "rna_Context_collection_get", NULL, NULL, NULL);
308 
309  prop = RNA_def_property(srna, "layer_collection", PROP_POINTER, PROP_NONE);
311  RNA_def_property_struct_type(prop, "LayerCollection");
312  RNA_def_property_pointer_funcs(prop, "rna_Context_layer_collection_get", NULL, NULL, NULL);
313 
314  prop = RNA_def_property(srna, "tool_settings", PROP_POINTER, PROP_NONE);
316  RNA_def_property_struct_type(prop, "ToolSettings");
317  RNA_def_property_pointer_funcs(prop, "rna_Context_tool_settings_get", NULL, NULL, NULL);
318 
319  prop = RNA_def_property(srna, "preferences", PROP_POINTER, PROP_NONE);
321  RNA_def_property_struct_type(prop, "Preferences");
322  RNA_def_property_pointer_funcs(prop, "rna_Context_preferences_get", NULL, NULL, NULL);
323 
324  prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
327  RNA_def_property_enum_funcs(prop, "rna_Context_mode_get", NULL, NULL);
328 
329  func = RNA_def_function(srna, "evaluated_depsgraph_get", "rna_Context_evaluated_depsgraph_get");
331  func,
332  "Get the dependency graph for the current scene and view layer, to access to data-blocks "
333  "with animation and modifiers applied. If any data-blocks have been edited, the dependency "
334  "graph will be updated. This invalidates all references to evaluated data-blocks from the "
335  "dependency graph.");
336  parm = RNA_def_pointer(func, "depsgraph", "Depsgraph", "", "Evaluated dependency graph");
337  RNA_def_function_return(func, parm);
338 }
339 
340 #endif
struct WorkSpace * CTX_wm_workspace(const bContext *C)
Definition: context.c:704
struct ScrArea * CTX_wm_area(const bContext *C)
Definition: context.c:714
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1034
struct RenderEngineType * CTX_data_engine_type(const bContext *C)
Definition: context.c:1064
struct LayerCollection * CTX_data_layer_collection(const bContext *C)
Definition: context.c:1077
struct wmWindowManager * CTX_wm_manager(const bContext *C)
Definition: context.c:689
@ CTX_MODE_EDIT_GPENCIL
Definition: BKE_context.h:130
@ CTX_MODE_EDIT_CURVE
Definition: BKE_context.h:116
@ CTX_MODE_PAINT_TEXTURE
Definition: BKE_context.h:126
@ CTX_MODE_EDIT_SURFACE
Definition: BKE_context.h:117
@ CTX_MODE_WEIGHT_GPENCIL
Definition: BKE_context.h:132
@ CTX_MODE_PARTICLE
Definition: BKE_context.h:127
@ CTX_MODE_SCULPT
Definition: BKE_context.h:123
@ CTX_MODE_VERTEX_GPENCIL
Definition: BKE_context.h:133
@ CTX_MODE_OBJECT
Definition: BKE_context.h:128
@ CTX_MODE_EDIT_MESH
Definition: BKE_context.h:115
@ CTX_MODE_EDIT_TEXT
Definition: BKE_context.h:118
@ CTX_MODE_EDIT_ARMATURE
Definition: BKE_context.h:119
@ CTX_MODE_SCULPT_GPENCIL
Definition: BKE_context.h:131
@ CTX_MODE_EDIT_LATTICE
Definition: BKE_context.h:121
@ CTX_MODE_PAINT_GPENCIL
Definition: BKE_context.h:129
@ CTX_MODE_PAINT_VERTEX
Definition: BKE_context.h:125
@ CTX_MODE_EDIT_METABALL
Definition: BKE_context.h:120
@ CTX_MODE_PAINT_WEIGHT
Definition: BKE_context.h:124
@ CTX_MODE_POSE
Definition: BKE_context.h:122
struct ViewLayer * CTX_data_view_layer(const bContext *C)
Definition: context.c:1044
struct Collection * CTX_data_collection(const bContext *C)
Definition: context.c:1092
struct wmGizmoGroup * CTX_wm_gizmo_group(const bContext *C)
Definition: context.c:741
struct Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
Definition: context.c:1424
struct View3D * CTX_wm_view3d(const bContext *C)
Definition: context.c:760
struct bScreen * CTX_wm_screen(const bContext *C)
Definition: context.c:709
void * CTX_wm_region_data(const bContext *C)
Definition: context.c:730
struct SpaceLink * CTX_wm_space_data(const bContext *C)
Definition: context.c:719
struct ARegion * CTX_wm_region(const bContext *C)
Definition: context.c:725
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1018
struct ToolSettings * CTX_data_tool_settings(const bContext *C)
Definition: context.c:1208
struct wmWindow * CTX_wm_window(const bContext *C)
Definition: context.c:699
enum eContextObjectMode CTX_data_mode_enum(const bContext *C)
Definition: context.c:1174
#define UNUSED(x)
#define BPy_BEGIN_ALLOW_THREADS
Definition: BPY_extern.h:62
#define BPy_END_ALLOW_THREADS
Definition: BPY_extern.h:66
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
ID and Library types, which are fundamental for sdna.
StructRNA RNA_Region
StructRNA RNA_Collection
StructRNA RNA_Scene
StructRNA RNA_ViewLayer
StructRNA RNA_Space
StructRNA RNA_LayerCollection
StructRNA RNA_WindowManager
StructRNA RNA_Screen
StructRNA RNA_WorkSpace
StructRNA RNA_Preferences
StructRNA RNA_Window
StructRNA RNA_ToolSettings
StructRNA RNA_Area
StructRNA RNA_BlendData
@ PROP_ENUM
Definition: RNA_types.h:77
@ PROP_STRING
Definition: RNA_types.h:76
@ PROP_POINTER
Definition: RNA_types.h:78
@ PROP_EDITABLE
Definition: RNA_types.h:175
@ PROP_NONE
Definition: RNA_types.h:113
#define C
Definition: RandGen.cpp:39
unsigned int U
Definition: btGjkEpa3.h:78
Scene scene
const Depsgraph * depsgraph
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
Definition: rna_access.c:146
void RNA_id_pointer_create(ID *id, PointerRNA *r_ptr)
Definition: rna_access.c:122
const PointerRNA PointerRNA_NULL
Definition: rna_access.c:71
PointerRNA rna_pointer_inherit_refine(PointerRNA *ptr, StructRNA *type, void *data)
Definition: rna_access.c:196
const EnumPropertyItem rna_enum_context_mode_items[]
Definition: rna_context.c:35
void RNA_def_context(BlenderRNA *brna)
Definition: rna_context.c:226
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
Definition: rna_define.c:4159
void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set)
Definition: rna_define.c:3312
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
Definition: rna_define.c:4302
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
Definition: rna_define.c:4262
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
Definition: rna_define.c:1259
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
Definition: rna_define.c:1892
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
Definition: rna_define.c:1067
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
Definition: rna_define.c:1792
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
Definition: rna_define.c:4337
void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item)
Definition: rna_define.c:3251
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
Definition: rna_define.c:1279
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1517
void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *type_fn, const char *poll)
Definition: rna_define.c:3373
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
Definition: rna_define.c:1047
Definition: DNA_ID.h:273
void * data
Definition: RNA_types.h:52
struct ID * owner_id
Definition: RNA_types.h:50
PointerRNA * ptr
Definition: wm_files.c:3157