[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [27205] trunk/blender/source/blender: Delete keyframe API method now takes array_index = -1 to delete keyframes from entire arrays, as for insert keyframe.

Joshua Leung aligorith at gmail.com
Mon Mar 1 11:43:02 CET 2010


Revision: 27205
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=27205
Author:   aligorith
Date:     2010-03-01 11:43:02 +0100 (Mon, 01 Mar 2010)

Log Message:
-----------
Delete keyframe API method now takes array_index = -1 to delete keyframes from entire arrays, as for insert keyframe.

Enabled the 'keyframe_delete' method for RNA structs.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/animation/keyframing.c
    trunk/blender/source/blender/python/intern/bpy_rna.c

Modified: trunk/blender/source/blender/editors/animation/keyframing.c
===================================================================
--- trunk/blender/source/blender/editors/animation/keyframing.c	2010-03-01 10:34:54 UTC (rev 27204)
+++ trunk/blender/source/blender/editors/animation/keyframing.c	2010-03-01 10:43:02 UTC (rev 27205)
@@ -865,7 +865,7 @@
 		/* get action to add F-Curve+keyframe to */
 		act= verify_adt_action(id, 1);
 		
-		if(act==NULL) {
+		if (act == NULL) {
 			printf("Insert Key: Could not insert keyframe, as this type does not support animation data (ID = %s, Path = %s)\n", id->name, rna_path);
 			return 0;
 		}
@@ -936,7 +936,10 @@
 short delete_keyframe (ID *id, bAction *act, const char group[], const char rna_path[], int array_index, float cfra, short flag)
 {
 	AnimData *adt= BKE_animdata_from_id(id);
-	FCurve *fcu = NULL;
+	PointerRNA id_ptr, ptr;
+	PropertyRNA *prop;
+	int array_index_max= array_index+1;
+	int ret= 0;
 	
 	/* sanity checks */
 	if ELEM(NULL, id, adt) {
@@ -944,45 +947,74 @@
 		return 0;
 	}	
 	
+	/* validate pointer first - exit if failure */
+	RNA_id_pointer_create(id, &id_ptr);
+	if ((RNA_path_resolve(&id_ptr, rna_path, &ptr, &prop) == 0) || (prop == NULL)) {
+		printf("Delete Key: Could not delete keyframe, as RNA Path is invalid for the given ID (ID = %s, Path = %s)\n", id->name, rna_path);
+		return 0;
+	}
+	
 	/* get F-Curve
 	 * Note: here is one of the places where we don't want new Action + F-Curve added!
 	 * 		so 'add' var must be 0
 	 */
 	if (act == NULL) {
-		/* if no action is provided, use the default one attached to this ID-block */
-		act= adt->action;
+		/* if no action is provided, use the default one attached to this ID-block 
+		 * 	- if it doesn't exist, then we're out of options...
+		 */
+		if (adt->action) {
+			act= adt->action;
+			
+			/* apply NLA-mapping to frame to use (if applicable) */
+			cfra= BKE_nla_tweakedit_remap(adt, cfra, NLATIME_CONVERT_UNMAP); 
+		}
+		else {
+			printf("ERROR: no Action to delete keyframes from for ID = %s \n", id->name);
+			return 0;
+		}
+	}
+	
+#if 0
+	/* apply special time tweaking */
+		// XXX check on this stuff...
+	if (GS(id->name) == ID_OB) {
+		//Object *ob= (Object *)id;
 		
-		/* apply NLA-mapping to frame to use (if applicable) */
-		cfra= BKE_nla_tweakedit_remap(adt, cfra, NLATIME_CONVERT_UNMAP); 
+		/* ancient time-offset cruft */
+		//if ( (ob->ipoflag & OB_OFFS_OB) && (give_timeoffset(ob)) ) {
+		//	/* actually frametofloat calc again! */
+		//	cfra-= give_timeoffset(ob)*scene->r.framelen;
+		//}
 	}
-	/* we don't check the validity of the path here yet, but it should be ok... */
-	fcu= verify_fcurve(act, group, rna_path, array_index, 0);
+#endif
 	
-	/* check if F-Curve exists and/or whether it can be edited */
-	if ELEM(NULL, act, fcu) {
-		printf("ERROR: no F-Curve and/or Action to delete keyframe from \n");
-		return 0;
+	/* key entire array convenience method */
+	if (array_index == -1) { 
+		array_index= 0;
+		array_index_max= RNA_property_array_length(&ptr, prop);
+		
+		/* for single properties, increase max_index so that the property itself gets included,
+		 * but don't do this for standard arrays since that can cause corruption issues 
+		 * (extra unused curves)
+		 */
+		if (array_index_max == array_index)
+			array_index_max++;
 	}
-	if ( (fcu->flag & FCURVE_PROTECTED) || ((fcu->grp) && (fcu->grp->flag & AGRP_PROTECTED)) ) {
-		if (G.f & G_DEBUG)
-			printf("WARNING: not inserting keyframe for locked F-Curve \n");
-		return 0;
-	}
 	
-	/* it should be fine to continue now... */
-	{
+	/* will only loop once unless the array index was -1 */
+	for (; array_index < array_index_max; array_index++) {
+		FCurve *fcu= verify_fcurve(act, group, rna_path, array_index, 0);
 		short found = -1;
 		int i;
 		
-		/* apply special time tweaking */
-		if (GS(id->name) == ID_OB) {
-			//Object *ob= (Object *)id;
+		/* check if F-Curve exists and/or whether it can be edited */
+		if (fcu == NULL)
+			continue;
 			
-			/* ancient time-offset cruft */
-			//if ( (ob->ipoflag & OB_OFFS_OB) && (give_timeoffset(ob)) ) {
-			//	/* actually frametofloat calc again! */
-			//	cfra-= give_timeoffset(ob)*scene->r.framelen;
-			//}
+		if ( (fcu->flag & FCURVE_PROTECTED) || ((fcu->grp) && (fcu->grp->flag & AGRP_PROTECTED)) ) {
+			if (G.f & G_DEBUG)
+				printf("WARNING: not inserting keyframe for locked F-Curve \n");
+			continue;
 		}
 		
 		/* try to find index of beztriple to get rid of */
@@ -996,12 +1028,12 @@
 				ANIM_fcurve_delete_from_animdata(NULL, adt, fcu);
 			
 			/* return success */
-			return 1;
+			ret++;
 		}
 	}
 	
-	/* return failure */
-	return 0;
+	/* return success/failure */
+	return ret;
 }
 
 /* ******************************************* */

Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c	2010-03-01 10:34:54 UTC (rev 27204)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c	2010-03-01 10:43:02 UTC (rev 27205)
@@ -2663,7 +2663,7 @@
 
 	/* maybe this become and ID function */
 	{"keyframe_insert", (PyCFunction)pyrna_struct_keyframe_insert, METH_VARARGS, NULL},
-//	{"keyframe_delete", (PyCFunction)pyrna_struct_keyframe_delete, METH_VARARGS, NULL}, // WIP
+	{"keyframe_delete", (PyCFunction)pyrna_struct_keyframe_delete, METH_VARARGS, NULL},
 	{"driver_add", (PyCFunction)pyrna_struct_driver_add, METH_VARARGS, NULL},
 	{"is_property_set", (PyCFunction)pyrna_struct_is_property_set, METH_VARARGS, NULL},
 	{"is_property_hidden", (PyCFunction)pyrna_struct_is_property_hidden, METH_VARARGS, NULL},





More information about the Bf-blender-cvs mailing list