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:
authorSybren A. Stüvel <sybren@stuvel.eu>2015-07-21 17:01:26 +0300
committerSybren A. Stüvel <sybren@stuvel.eu>2015-07-21 17:01:26 +0300
commit89e5c756665c1e7e622ddbd5deece0dda4ce7724 (patch)
tree4d9f772983c7a4aa7fe06859b51be0b147b08f35 /source/blender/makesrna/intern/rna_action.c
parente7fc8d98f5eb28d26d9a2a6be816dc5e57a1d678 (diff)
Added Action.fcurves.find(data_path, array_index=0)
Finding a specific F-Curve is often needed in Python, and usually consists of a construct like: ``` [fcurve for fcurve in ob.animation_data.action.fcurves if fcurve.data_path == "location"][1] ``` This can now be written as `ob.animation_data.action.fcurves.find('location', 1)` This new function `Action.fcurves.find()` is still O(N) in the number of FCurves in the Action, but at least it allows us to remove boiler-plate code. It is also faster than the Python equivalent, as only the found F-Curve is converted to Python. Reviewers: campbellbarton, aligorith Reviewed By: aligorith Differential Revision: https://developer.blender.org/D1427
Diffstat (limited to 'source/blender/makesrna/intern/rna_action.c')
-rw-r--r--source/blender/makesrna/intern/rna_action.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_action.c b/source/blender/makesrna/intern/rna_action.c
index d121e1f5cfc..424e2004749 100644
--- a/source/blender/makesrna/intern/rna_action.c
+++ b/source/blender/makesrna/intern/rna_action.c
@@ -119,6 +119,17 @@ static FCurve *rna_Action_fcurve_new(bAction *act, ReportList *reports, const ch
return verify_fcurve(act, group, NULL, data_path, index, 1);
}
+static FCurve *rna_Action_fcurve_find(bAction *act, ReportList *reports, const char *data_path, int index)
+{
+ if (data_path[0] == '\0') {
+ BKE_report(reports, RPT_ERROR, "F-Curve data path empty, invalid argument");
+ return NULL;
+ }
+
+ /* Returns NULL if not found. */
+ return list_find_fcurve(&act->curves, data_path, index);
+}
+
static void rna_Action_fcurve_remove(bAction *act, ReportList *reports, PointerRNA *fcu_ptr)
{
FCurve *fcu = fcu_ptr->data;
@@ -576,6 +587,7 @@ static void rna_def_action_fcurves(BlenderRNA *brna, PropertyRNA *cprop)
RNA_def_struct_sdna(srna, "bAction");
RNA_def_struct_ui_text(srna, "Action F-Curves", "Collection of action F-Curves");
+ /* Action.fcurves.new(...) */
func = RNA_def_function(srna, "new", "rna_Action_fcurve_new");
RNA_def_function_ui_description(func, "Add an F-Curve to the action");
RNA_def_function_flag(func, FUNC_USE_REPORTS);
@@ -587,7 +599,19 @@ static void rna_def_action_fcurves(BlenderRNA *brna, PropertyRNA *cprop)
parm = RNA_def_pointer(func, "fcurve", "FCurve", "", "Newly created F-Curve");
RNA_def_function_return(func, parm);
+ /* Action.fcurves.find(...) */
+ func = RNA_def_function(srna, "find", "rna_Action_fcurve_find");
+ RNA_def_function_ui_description(func, "Find an F-Curve. Note that this function performs a linear scan "
+ "of all F-Curves in the action.");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ parm = RNA_def_string(func, "data_path", NULL, 0, "Data Path", "F-Curve data path");
+ RNA_def_property_flag(parm, PROP_REQUIRED);
+ RNA_def_int(func, "index", 0, 0, INT_MAX, "Index", "Array index", 0, INT_MAX);
+
+ parm = RNA_def_pointer(func, "fcurve", "FCurve", "", "The found F-Curve, or None if it doesn't exist");
+ RNA_def_function_return(func, parm);
+ /* Action.fcurves.remove(...) */
func = RNA_def_function(srna, "remove", "rna_Action_fcurve_remove");
RNA_def_function_ui_description(func, "Remove action group");
RNA_def_function_flag(func, FUNC_USE_REPORTS);