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>2021-09-02 04:41:01 +0300
committerCampbell Barton <ideasman42@gmail.com>2021-09-02 04:41:01 +0300
commit011d3a95e0188543f43e0373637eb7e51381f503 (patch)
tree9c6f71b96d085428af6e18864f7f103cb66dbeb9 /source/blender/python/intern
parent6c177838f30a171c6b69b66d885cdefd01669a33 (diff)
Cleanup: de-duplicate logic in bpy keyframing logic
Diffstat (limited to 'source/blender/python/intern')
-rw-r--r--source/blender/python/intern/bpy_rna_anim.c76
1 files changed, 30 insertions, 46 deletions
diff --git a/source/blender/python/intern/bpy_rna_anim.c b/source/blender/python/intern/bpy_rna_anim.c
index f4fe5838c6e..2096734ef96 100644
--- a/source/blender/python/intern/bpy_rna_anim.c
+++ b/source/blender/python/intern/bpy_rna_anim.c
@@ -335,6 +335,11 @@ PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyOb
return NULL;
}
+ ReportList reports;
+ bool result = false;
+
+ BKE_reports_init(&reports, RPT_STORE);
+
/* This assumes that keyframes are only added on original data & using the active depsgraph. If
* it turns out to be necessary for some reason to insert keyframes on evaluated objects, we can
* revisit this and add an explicit `depsgraph` keyword argument to the function call.
@@ -352,15 +357,11 @@ PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyOb
* strips themselves. These are stored separately or else the properties will
* not have any effect.
*/
- ReportList reports;
- bool result = false;
PointerRNA ptr = self->ptr;
PropertyRNA *prop = NULL;
const char *prop_name;
- BKE_reports_init(&reports, RPT_STORE);
-
/* Retrieve the property identifier from the full path, since we can't get it any other way */
prop_name = strrchr(path_full, '.');
if ((prop_name >= path_full) && (prop_name + 1 < path_full + strlen(path_full))) {
@@ -376,33 +377,24 @@ PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyOb
else {
BKE_reportf(&reports, RPT_ERROR, "Could not resolve path (%s)", path_full);
}
- MEM_freeN((void *)path_full);
-
- if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) {
- return NULL;
- }
-
- return PyBool_FromLong(result);
}
+ else {
+ ID *id = self->ptr.owner_id;
- ID *id = self->ptr.owner_id;
- ReportList reports;
- bool result;
-
- BKE_reports_init(&reports, RPT_STORE);
+ BLI_assert(BKE_id_is_in_global_main(id));
+ result = (insert_keyframe(G_MAIN,
+ &reports,
+ id,
+ NULL,
+ group_name,
+ path_full,
+ index,
+ &anim_eval_context,
+ keytype,
+ NULL,
+ options) != 0);
+ }
- BLI_assert(BKE_id_is_in_global_main(id));
- result = (insert_keyframe(G_MAIN,
- &reports,
- id,
- NULL,
- group_name,
- path_full,
- index,
- &anim_eval_context,
- keytype,
- NULL,
- options) != 0);
MEM_freeN((void *)path_full);
if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) {
@@ -453,20 +445,22 @@ PyObject *pyrna_struct_keyframe_delete(BPy_StructRNA *self, PyObject *args, PyOb
NULL) == -1) {
return NULL;
}
+
+ ReportList reports;
+ bool result = false;
+
+ BKE_reports_init(&reports, RPT_STORE);
+
if (self->ptr.type == &RNA_NlaStrip) {
/* Handle special properties for NLA Strips, whose F-Curves are stored on the
* strips themselves. These are stored separately or else the properties will
* not have any effect.
*/
- ReportList reports;
- bool result = false;
PointerRNA ptr = self->ptr;
PropertyRNA *prop = NULL;
const char *prop_name;
- BKE_reports_init(&reports, RPT_STORE);
-
/* Retrieve the property identifier from the full path, since we can't get it any other way */
prop_name = strrchr(path_full, '.');
if ((prop_name >= path_full) && (prop_name + 1 < path_full + strlen(path_full))) {
@@ -510,22 +504,12 @@ PyObject *pyrna_struct_keyframe_delete(BPy_StructRNA *self, PyObject *args, PyOb
else {
BKE_reportf(&reports, RPT_ERROR, "Could not resolve path (%s)", path_full);
}
- MEM_freeN((void *)path_full);
-
- if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) {
- return NULL;
- }
-
- return PyBool_FromLong(result);
+ }
+ else {
+ result = (delete_keyframe(
+ G.main, &reports, self->ptr.owner_id, NULL, path_full, index, cfra) != 0);
}
- bool result;
- ReportList reports;
-
- BKE_reports_init(&reports, RPT_STORE);
-
- result = (delete_keyframe(G.main, &reports, self->ptr.owner_id, NULL, path_full, index, cfra) !=
- 0);
MEM_freeN((void *)path_full);
if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) {