Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-01-07 06:03:34 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-01-07 06:06:36 +0300
commitabe32d2a35e4d3ca86caca7e5f7d212d8802107f (patch)
tree56bc56372dff5caf631801bbca532078bf401688 /source/blender/makesrna/intern/rna_animation.c
parent96f762500ef99ec495b77599449ed258bf691763 (diff)
PyAPI: Add AnimationData.drivers.new/remove methods
Low level functions to directly create and remove drivers, use when high level functions aren't flexible enough, see: T58964.
Diffstat (limited to 'source/blender/makesrna/intern/rna_animation.c')
-rw-r--r--source/blender/makesrna/intern/rna_animation.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_animation.c b/source/blender/makesrna/intern/rna_animation.c
index e43b62e8a75..d97fdd111b6 100644
--- a/source/blender/makesrna/intern/rna_animation.c
+++ b/source/blender/makesrna/intern/rna_animation.c
@@ -579,6 +579,33 @@ static FCurve *rna_Driver_from_existing(AnimData *adt, bContext *C, FCurve *src_
}
}
+static FCurve *rna_Driver_new(ID *id, AnimData *adt, ReportList *reports, const char *rna_path, int array_index)
+{
+ if (rna_path[0] == '\0') {
+ BKE_report(reports, RPT_ERROR, "F-Curve data path empty, invalid argument");
+ return NULL;
+ }
+
+ if (list_find_fcurve(&adt->drivers, rna_path, array_index)) {
+ BKE_reportf(reports, RPT_ERROR, "Driver '%s[%d]' already exists", rna_path, array_index);
+ return NULL;
+ }
+
+ short add_mode = 1;
+ FCurve *fcu = verify_driver_fcurve(id, rna_path, array_index, add_mode);
+ BLI_assert(fcu != NULL);
+ return fcu;
+}
+
+static void rna_Driver_remove(AnimData *adt, ReportList *reports, FCurve *fcu)
+{
+ if (!BLI_remlink_safe(&adt->drivers, fcu)) {
+ BKE_report(reports, RPT_ERROR, "Driver not found in this animation data");
+ return;
+ }
+ free_fcurve(fcu);
+}
+
static FCurve *rna_Driver_find(AnimData *adt, ReportList *reports, const char *data_path, int index)
{
if (data_path[0] == '\0') {
@@ -1005,6 +1032,24 @@ static void rna_api_animdata_drivers(BlenderRNA *brna, PropertyRNA *cprop)
RNA_def_struct_sdna(srna, "AnimData");
RNA_def_struct_ui_text(srna, "Drivers", "Collection of Driver F-Curves");
+ /* Match: ActionFCurves.new/remove */
+
+ /* AnimData.drivers.new(...) */
+ func = RNA_def_function(srna, "new", "rna_Driver_new");
+ RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_REPORTS);
+ parm = RNA_def_string(func, "data_path", NULL, 0, "Data Path", "F-Curve data path to use");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+ RNA_def_int(func, "index", 0, 0, INT_MAX, "Index", "Array index", 0, INT_MAX);
+ /* return type */
+ parm = RNA_def_pointer(func, "driver", "FCurve", "", "Newly Driver F-Curve");
+ RNA_def_function_return(func, parm);
+
+ /* AnimData.drivers.remove(...) */
+ func = RNA_def_function(srna, "remove", "rna_Driver_remove");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ parm = RNA_def_pointer(func, "driver", "FCurve", "", "");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
+
/* AnimData.drivers.from_existing(...) */
func = RNA_def_function(srna, "from_existing", "rna_Driver_from_existing");
RNA_def_function_flag(func, FUNC_USE_CONTEXT);