1 /* SPDX-FileCopyrightText: 2023 Blender Authors
3 * SPDX-License-Identifier: GPL-2.0-or-later */
6 * \ingroup pythonintern
8 * This file defines utility functions that use the RNA API, from PyDrivers.
13 #include "DNA_anim_types.h"
15 #include "BKE_fcurve_driver.h"
17 #include "RNA_access.hh"
21 #include "bpy_rna_driver.hh" /* own include */
23 PyObject
*pyrna_driver_get_variable_value(const AnimationEvalContext
*anim_eval_context
,
24 ChannelDriver
*driver
,
29 PropertyRNA
*prop
= nullptr;
32 switch (driver_get_variable_property(
33 anim_eval_context
, driver
, dvar
, dtar
, true, &ptr
, &prop
, &index
))
35 case DRIVER_VAR_PROPERTY_SUCCESS
:
38 return pyrna_struct_CreatePyObject(&ptr
);
41 /* object, property & index */
43 return pyrna_array_index(&ptr
, prop
, index
);
46 /* object & property (enum) */
47 if (RNA_property_type(prop
) == PROP_ENUM
) {
48 /* Note that enum's are converted to strings by default,
49 * we want to avoid that, see: #52213 */
50 return PyLong_FromLong(RNA_property_enum_get(&ptr
, prop
));
53 /* object & property */
54 return pyrna_prop_to_py(&ptr
, prop
);
56 case DRIVER_VAR_PROPERTY_FALLBACK
:
57 return PyFloat_FromDouble(dtar
->fallback_value
);
59 case DRIVER_VAR_PROPERTY_INVALID
:
60 case DRIVER_VAR_PROPERTY_INVALID_INDEX
:
61 /* can't resolve path, pass */
68 PyObject
*pyrna_driver_self_from_anim_rna(PathResolvedRNA
*anim_rna
)
70 return pyrna_struct_CreatePyObject(&anim_rna
->ptr
);
73 bool pyrna_driver_is_equal_anim_rna(const PathResolvedRNA
*anim_rna
, const PyObject
*py_anim_rna
)
75 if (BPy_StructRNA_Check(py_anim_rna
)) {
76 const PointerRNA
*ptr_a
= &anim_rna
->ptr
;
77 const PointerRNA
*ptr_b
= &reinterpret_cast<const BPy_StructRNA
*>(py_anim_rna
)->ptr
.value();
79 if ((ptr_a
->owner_id
== ptr_b
->owner_id
) && (ptr_a
->type
== ptr_b
->type
) &&
80 (ptr_a
->data
== ptr_b
->data
))