[Bf-blender-cvs] [b1c6ddb] master: Also apply similar fixes to .keyframe_delete()

Joshua Leung noreply at git.blender.org
Wed Dec 28 13:47:53 CET 2016


Commit: b1c6ddb107cfe5bff3e3f0da986fe14c694727bc
Author: Joshua Leung
Date:   Wed Dec 28 23:27:46 2016 +1300
Branches: master
https://developer.blender.org/rBb1c6ddb107cfe5bff3e3f0da986fe14c694727bc

Also apply similar fixes to .keyframe_delete()

- T49816

===================================================================

M	source/blender/python/intern/bpy_rna_anim.c

===================================================================

diff --git a/source/blender/python/intern/bpy_rna_anim.c b/source/blender/python/intern/bpy_rna_anim.c
index 893f137..5fbe1ab 100644
--- a/source/blender/python/intern/bpy_rna_anim.c
+++ b/source/blender/python/intern/bpy_rna_anim.c
@@ -36,12 +36,15 @@
 
 #include "DNA_scene_types.h"
 #include "DNA_anim_types.h"
+
 #include "ED_keyframing.h"
+#include "ED_keyframes_edit.h"
 
 #include "BKE_report.h"
 #include "BKE_context.h"
 #include "BKE_animsys.h"
 #include "BKE_fcurve.h"
+#include "BKE_idcode.h"
 
 #include "RNA_access.h"
 #include "RNA_enum_types.h"
@@ -310,6 +313,67 @@ PyObject *pyrna_struct_keyframe_delete(BPy_StructRNA *self, PyObject *args, PyOb
 	{
 		return NULL;
 	}
+	else 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;
+		short result = 0;
+		
+		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)))
+		{
+			prop = RNA_struct_find_property(&ptr, prop_name + 1);
+		}
+		
+		if (prop) {
+			ID *id = ptr.id.data;
+			NlaStrip *strip = (NlaStrip *)ptr.data;
+			FCurve *fcu = list_find_fcurve(&strip->fcurves, RNA_property_identifier(prop), index);
+			
+			BLI_assert(fcu != NULL); /* NOTE: This should be true, or else we wouldn't be able to get here */
+			
+			if (BKE_fcurve_is_protected(fcu)) {
+				BKE_reportf(&reports, RPT_WARNING,
+				            "Not deleting keyframe for locked F-Curve for NLA Strip influence on %s - %s '%s'",
+				            strip->name, BKE_idcode_to_name(GS(id->name)), id->name + 2);
+			}
+			else {
+				/* remove the keyframe directly
+				 * NOTE: cannot use delete_keyframe_fcurve(), as that will free the curve,
+				 *       and delete_keyframe() expects the FCurve to be part of an action
+				 */
+				bool found = false;
+				int i;
+				
+				/* try to find index of beztriple to get rid of */
+				i = binarysearch_bezt_index(fcu->bezt, cfra, fcu->totvert, &found);
+				if (found) {
+					/* delete the key at the index (will sanity check + do recalc afterwards) */
+					delete_fcurve_key(fcu, i, 1);
+					result = true;
+				}
+			}
+		}
+		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 {
 		short result;
 		ReportList reports;




More information about the Bf-blender-cvs mailing list