Blender  V2.93
bpy_rna_driver.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 
23 #include <Python.h>
24 
25 #include "MEM_guardedalloc.h"
26 
27 #include "BLI_utildefines.h"
28 
29 #include "BKE_fcurve_driver.h"
30 
31 #include "RNA_access.h"
32 
33 #include "bpy_rna.h"
34 
35 #include "bpy_rna_driver.h" /* own include */
36 
40 PyObject *pyrna_driver_get_variable_value(struct ChannelDriver *driver, struct DriverTarget *dtar)
41 {
42  PyObject *driver_arg = NULL;
44  PropertyRNA *prop = NULL;
45  int index;
46 
47  if (driver_get_variable_property(driver, dtar, &ptr, &prop, &index)) {
48  if (prop) {
49  if (index != -1) {
50  if (index < RNA_property_array_length(&ptr, prop) && index >= 0) {
51  /* object, property & index */
52  driver_arg = pyrna_array_index(&ptr, prop, index);
53  }
54  else {
55  /* out of range, pass */
56  }
57  }
58  else {
59  /* object & property */
60  const PropertyType type = RNA_property_type(prop);
61  if (type == PROP_ENUM) {
62  /* Note that enum's are converted to strings by default,
63  * we want to avoid that, see: T52213 */
64  driver_arg = PyLong_FromLong(RNA_property_enum_get(&ptr, prop));
65  }
66  else {
67  driver_arg = pyrna_prop_to_py(&ptr, prop);
68  }
69  }
70  }
71  else {
72  /* object only */
73  driver_arg = pyrna_struct_CreatePyObject(&ptr);
74  }
75  }
76  else {
77  /* can't resolve path, pass */
78  }
79 
80  return driver_arg;
81 }
82 
84 {
85  return pyrna_struct_CreatePyObject(&anim_rna->ptr);
86 }
87 
88 bool pyrna_driver_is_equal_anim_rna(const PathResolvedRNA *anim_rna, const PyObject *py_anim_rna)
89 {
90  if (BPy_StructRNA_Check(py_anim_rna)) {
91  const PointerRNA *ptr_a = &anim_rna->ptr;
92  const PointerRNA *ptr_b = &(((const BPy_StructRNA *)py_anim_rna)->ptr);
93 
94  if ((ptr_a->owner_id == ptr_b->owner_id) && (ptr_a->type == ptr_b->type) &&
95  (ptr_a->data == ptr_b->data)) {
96  return true;
97  }
98  }
99  return false;
100 }
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:72
@ PROP_ENUM
Definition: RNA_types.h:77
PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop)
Definition: bpy_rna.c:1537
PyObject * pyrna_struct_CreatePyObject(PointerRNA *ptr)
Definition: bpy_rna.c:7469
PyObject * pyrna_array_index(PointerRNA *ptr, PropertyRNA *prop, int index)
#define BPy_StructRNA_Check(v)
Definition: bpy_rna.h:80
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:1155
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:1218
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:3543
struct PointerRNA ptr
Definition: RNA_types.h:64
struct StructRNA * type
Definition: RNA_types.h:51
void * data
Definition: RNA_types.h:52
struct ID * owner_id
Definition: RNA_types.h:50
PointerRNA * ptr
Definition: wm_files.c:3157