Blender  V3.3
bpy_rna_driver.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
9 #include <Python.h>
10 
11 #include "MEM_guardedalloc.h"
12 
13 #include "BLI_utildefines.h"
14 
15 #include "BKE_fcurve_driver.h"
16 
17 #include "RNA_access.h"
18 
19 #include "bpy_rna.h"
20 
21 #include "bpy_rna_driver.h" /* own include */
22 
23 PyObject *pyrna_driver_get_variable_value(struct ChannelDriver *driver, struct DriverTarget *dtar)
24 {
25  PyObject *driver_arg = NULL;
27  PropertyRNA *prop = NULL;
28  int index;
29 
30  if (driver_get_variable_property(driver, dtar, &ptr, &prop, &index)) {
31  if (prop) {
32  if (index != -1) {
33  if (index < RNA_property_array_length(&ptr, prop) && index >= 0) {
34  /* object, property & index */
35  driver_arg = pyrna_array_index(&ptr, prop, index);
36  }
37  else {
38  /* out of range, pass */
39  }
40  }
41  else {
42  /* object & property */
43  const PropertyType type = RNA_property_type(prop);
44  if (type == PROP_ENUM) {
45  /* Note that enum's are converted to strings by default,
46  * we want to avoid that, see: T52213 */
47  driver_arg = PyLong_FromLong(RNA_property_enum_get(&ptr, prop));
48  }
49  else {
50  driver_arg = pyrna_prop_to_py(&ptr, prop);
51  }
52  }
53  }
54  else {
55  /* object only */
56  driver_arg = pyrna_struct_CreatePyObject(&ptr);
57  }
58  }
59  else {
60  /* can't resolve path, pass */
61  }
62 
63  return driver_arg;
64 }
65 
67 {
68  return pyrna_struct_CreatePyObject(&anim_rna->ptr);
69 }
70 
71 bool pyrna_driver_is_equal_anim_rna(const PathResolvedRNA *anim_rna, const PyObject *py_anim_rna)
72 {
73  if (BPy_StructRNA_Check(py_anim_rna)) {
74  const PointerRNA *ptr_a = &anim_rna->ptr;
75  const PointerRNA *ptr_b = &(((const BPy_StructRNA *)py_anim_rna)->ptr);
76 
77  if ((ptr_a->owner_id == ptr_b->owner_id) && (ptr_a->type == ptr_b->type) &&
78  (ptr_a->data == ptr_b->data)) {
79  return true;
80  }
81  }
82  return false;
83 }
bool driver_get_variable_property(struct ChannelDriver *driver, struct DriverTarget *dtar, struct PointerRNA *r_ptr, struct PropertyRNA **r_prop, int *r_index)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Read Guarded memory(de)allocation.
PropertyType
Definition: RNA_types.h:58
@ PROP_ENUM
Definition: RNA_types.h:63
PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop)
Definition: bpy_rna.c:1372
PyObject * pyrna_struct_CreatePyObject(PointerRNA *ptr)
Definition: bpy_rna.c:7505
PyObject * pyrna_array_index(PointerRNA *ptr, PropertyRNA *prop, int index)
#define BPy_StructRNA_Check(v)
Definition: bpy_rna.h:66
PyObject * pyrna_driver_self_from_anim_rna(PathResolvedRNA *anim_rna)
PyObject * pyrna_driver_get_variable_value(struct ChannelDriver *driver, struct DriverTarget *dtar)
bool pyrna_driver_is_equal_anim_rna(const PathResolvedRNA *anim_rna, const PyObject *py_anim_rna)
PropertyType RNA_property_type(PropertyRNA *prop)
Definition: rna_access.c:1010
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:1075
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:3402
struct PointerRNA ptr
Definition: RNA_types.h:50
struct StructRNA * type
Definition: RNA_types.h:37
void * data
Definition: RNA_types.h:38
struct ID * owner_id
Definition: RNA_types.h:36
PointerRNA * ptr
Definition: wm_files.c:3480