[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [33127] trunk/blender/source/blender: Keyframing Operators: Improved Error Messages

Joshua Leung aligorith at gmail.com
Wed Nov 17 13:02:37 CET 2010


Revision: 33127
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33127
Author:   aligorith
Date:     2010-11-17 13:02:36 +0100 (Wed, 17 Nov 2010)

Log Message:
-----------
Keyframing Operators: Improved Error Messages

* Keyframing operators now use the reports system for displaying all its error messages. 
- The benefit of this is that users no longer need to check the console for error messages if keyframing fails.
- Unfortunately, reports are not currently viewable in any space/view in Blender, so...

* Added a temporary operator (UI_OT_reports_to_textblock), which can be accessed in the UI from the button which appears in place of the icon when more than one report exists. This dumps the current list of reports to a textblock "Recent Reports", from which they can be viewed. 

This isn't really nice, but at least we now have a way to view these again, which makes debugging some things a pain.

* Bugfix #24606 - when trying to add keyframes to F-Curves with F-Modifiers already which alter the curve significantly enough that the keyframes will have no effect, there are now warnings which aim to alleviate any confusion. 

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_fcurve.h
    trunk/blender/source/blender/blenkernel/intern/fcurve.c
    trunk/blender/source/blender/editors/animation/anim_channels_defines.c
    trunk/blender/source/blender/editors/animation/keyframing.c
    trunk/blender/source/blender/editors/animation/keyingsets.c
    trunk/blender/source/blender/editors/include/ED_anim_api.h
    trunk/blender/source/blender/editors/include/ED_keyframing.h
    trunk/blender/source/blender/editors/interface/interface_anim.c
    trunk/blender/source/blender/editors/interface/interface_ops.c
    trunk/blender/source/blender/editors/interface/interface_templates.c
    trunk/blender/source/blender/editors/space_action/action_edit.c
    trunk/blender/source/blender/editors/space_graph/graph_draw.c
    trunk/blender/source/blender/editors/space_graph/graph_edit.c
    trunk/blender/source/blender/editors/space_graph/graph_utils.c
    trunk/blender/source/blender/editors/transform/transform_conversions.c
    trunk/blender/source/blender/python/intern/bpy_rna.c

Modified: trunk/blender/source/blender/blenkernel/BKE_fcurve.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_fcurve.h	2010-11-17 11:09:07 UTC (rev 33126)
+++ trunk/blender/source/blender/blenkernel/BKE_fcurve.h	2010-11-17 12:02:36 UTC (rev 33127)
@@ -214,6 +214,14 @@
 /* get the bounding-box extents for F-Curve */
 void calc_fcurve_bounds(struct FCurve *fcu, float *xmin, float *xmax, float *ymin, float *ymax);
 
+/* .............. */
+
+/* Are keyframes on F-Curve of any use (to final result, and to show in editors)? */
+short fcurve_are_keyframes_usable(struct FCurve *fcu);
+
+/* Can keyframes be added to F-Curve? */
+short fcurve_is_keyframable(struct FCurve *fcu);
+
 /* -------- Curve Sanity --------  */
 
 void calchandles_fcurve(struct FCurve *fcu);

Modified: trunk/blender/source/blender/blenkernel/intern/fcurve.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/fcurve.c	2010-11-17 11:09:07 UTC (rev 33126)
+++ trunk/blender/source/blender/blenkernel/intern/fcurve.c	2010-11-17 12:02:36 UTC (rev 33127)
@@ -163,7 +163,7 @@
 	}
 }
 
-/* --------------------- Finding -------------------------- */
+/* ----------------- Finding F-Curves -------------------------- */
 
 /* high level function to get an fcurve from C without having the rna */
 FCurve *id_data_find_fcurve(ID *id, void *data, StructRNA *type, char *prop_name, int index)
@@ -298,36 +298,36 @@
 	return matches;
 }
 
-FCurve *rna_get_fcurve(PointerRNA *ptr, PropertyRNA *prop, int rnaindex, bAction **action, int *driven)
+FCurve *rna_get_fcurve (PointerRNA *ptr, PropertyRNA *prop, int rnaindex, bAction **action, int *driven)
 {
 	FCurve *fcu= NULL;
 	
 	*driven= 0;
 	
 	/* there must be some RNA-pointer + property combon */
-	if(prop && ptr->id.data && RNA_property_animateable(ptr, prop)) {
+	if (prop && ptr->id.data && RNA_property_animateable(ptr, prop)) {
 		AnimData *adt= BKE_animdata_from_id(ptr->id.data);
 		char *path;
 		
-		if(adt) {
-			if((adt->action && adt->action->curves.first) || (adt->drivers.first)) {
+		if (adt) {
+			if ((adt->action && adt->action->curves.first) || (adt->drivers.first)) {
 				/* XXX this function call can become a performance bottleneck */
 				path= RNA_path_from_ID_to_property(ptr, prop);
 				
-				if(path) {
+				if (path) {
 					/* animation takes priority over drivers */
-					if(adt->action && adt->action->curves.first)
+					if (adt->action && adt->action->curves.first)
 						fcu= list_find_fcurve(&adt->action->curves, path, rnaindex);
 					
 					/* if not animated, check if driven */
-					if(!fcu && (adt->drivers.first)) {
+					if (!fcu && (adt->drivers.first)) {
 						fcu= list_find_fcurve(&adt->drivers, path, rnaindex);
 						
-						if(fcu)
+						if (fcu)
 							*driven= 1;
 					}
 					
-					if(fcu && action)
+					if (fcu && action)
 						*action= adt->action;
 					
 					MEM_freeN(path);
@@ -339,6 +339,8 @@
 	return fcu;
 }
 
+/* ----------------- Finding Keyframes/Extents -------------------------- */
+
 /* threshold for binary-searching keyframes - threshold here should be good enough for now, but should become userpref */
 #define BEZT_BINARYSEARCH_THRESH 	0.01f /* was 0.00001, but giving errors */
 
@@ -520,6 +522,87 @@
 	}
 }
 
+/* ----------------- Status Checks -------------------------- */
+
+/* Are keyframes on F-Curve of any use? 
+ * Usability of keyframes refers to whether they should be displayed,
+ * and also whether they will have any influence on the final result.
+ */
+short fcurve_are_keyframes_usable (FCurve *fcu)
+{
+	/* F-Curve must exist */
+	if (fcu == NULL)
+		return 0;
+		
+	/* F-Curve must not have samples - samples are mutually exclusive of keyframes */
+	if (fcu->fpt)
+		return 0;
+	
+	/* if it has modifiers, none of these should "drastically" alter the curve */
+	if (fcu->modifiers.first) {
+		FModifier *fcm;
+		
+		/* check modifiers from last to first, as last will be more influential */
+		// TODO: optionally, only check modifier if it is the active one...
+		for (fcm = fcu->modifiers.last; fcm; fcm = fcm->prev) {
+			/* ignore if muted/disabled */
+			if (fcm->flag & (FMODIFIER_FLAG_DISABLED|FMODIFIER_FLAG_MUTED))
+				continue;
+				
+			/* type checks */
+			switch (fcm->type) {
+				/* clearly harmless - do nothing */
+				case FMODIFIER_TYPE_CYCLES:
+				case FMODIFIER_TYPE_STEPPED:
+				case FMODIFIER_TYPE_NOISE:
+					break;
+					
+				/* sometimes harmful - depending on whether they're "additive" or not */
+				case FMODIFIER_TYPE_GENERATOR:
+				{
+					FMod_Generator *data = (FMod_Generator *)fcm->data;
+					
+					if ((data->flag & FCM_GENERATOR_ADDITIVE) == 0)
+						return 0;
+				}
+					break;
+				case FMODIFIER_TYPE_FN_GENERATOR:
+				{
+					FMod_FunctionGenerator *data = (FMod_FunctionGenerator *)fcm->data;
+					
+					if ((data->flag & FCM_GENERATOR_ADDITIVE) == 0)
+						return 0;
+				}
+					break;
+					
+				/* always harmful - cannot allow */
+				default:
+					return 0;
+			}
+		}
+	}
+	
+	/* keyframes are usable */
+	return 1;
+}
+
+/* Can keyframes be added to F-Curve? 
+ * Keyframes can only be added if they are already visible
+ */
+short fcurve_is_keyframable (FCurve *fcu)
+{
+	/* F-Curve's keyframes must be "usable" (i.e. visible + have an effect on final result) */
+	if (fcurve_are_keyframes_usable(fcu) == 0)
+		return 0;
+		
+	/* F-Curve must currently be editable too */
+	if ( (fcu->flag & FCURVE_PROTECTED) || ((fcu->grp) && (fcu->grp->flag & AGRP_PROTECTED)) )
+		return 0;
+	
+	/* F-Curve is keyframable */
+	return 1;
+}
+
 /* ***************************** Keyframe Column Tools ********************************* */
 
 /* add a BezTriple to a column */

Modified: trunk/blender/source/blender/editors/animation/anim_channels_defines.c
===================================================================
--- trunk/blender/source/blender/editors/animation/anim_channels_defines.c	2010-11-17 11:09:07 UTC (rev 33126)
+++ trunk/blender/source/blender/editors/animation/anim_channels_defines.c	2010-11-17 12:02:36 UTC (rev 33127)
@@ -2917,6 +2917,7 @@
 	ID *id= (ID *)id_poin;
 	FCurve *fcu= (FCurve *)fcu_poin;
 	
+	ReportList *reports = CTX_wm_reports(C);
 	Scene *scene= CTX_data_scene(C);
 	PointerRNA id_ptr, ptr;
 	PropertyRNA *prop;
@@ -2940,7 +2941,7 @@
 			flag |= INSERTKEY_REPLACE;
 		
 		/* insert a keyframe for this F-Curve */
-		done= insert_keyframe_direct(ptr, prop, fcu, cfra, flag);
+		done= insert_keyframe_direct(reports, ptr, prop, fcu, cfra, flag);
 		
 		if (done)
 			WM_event_add_notifier(C, NC_ANIMATION|ND_ANIMCHAN|NA_EDITED, NULL);
@@ -2954,6 +2955,7 @@
 	KeyBlock *kb= (KeyBlock *)kb_poin;
 	char *rna_path= key_get_curValue_rnaPath(key, kb);
 	
+	ReportList *reports = CTX_wm_reports(C);
 	Scene *scene= CTX_data_scene(C);
 	PointerRNA id_ptr, ptr;
 	PropertyRNA *prop;
@@ -2982,7 +2984,7 @@
 			flag |= INSERTKEY_REPLACE;
 		
 		/* insert a keyframe for this F-Curve */
-		done= insert_keyframe_direct(ptr, prop, fcu, cfra, flag);
+		done= insert_keyframe_direct(reports, ptr, prop, fcu, cfra, flag);
 		
 		if (done)
 			WM_event_add_notifier(C, NC_ANIMATION|ND_ANIMCHAN|NA_EDITED, NULL);

Modified: trunk/blender/source/blender/editors/animation/keyframing.c
===================================================================
--- trunk/blender/source/blender/editors/animation/keyframing.c	2010-11-17 11:09:07 UTC (rev 33126)
+++ trunk/blender/source/blender/editors/animation/keyframing.c	2010-11-17 12:02:36 UTC (rev 33127)
@@ -697,25 +697,26 @@
  *	the keyframe insertion. These include the 'visual' keyframing modes, quick refresh,
  *	and extra keyframe filtering.
  */
-short insert_keyframe_direct (PointerRNA ptr, PropertyRNA *prop, FCurve *fcu, float cfra, short flag)
+short insert_keyframe_direct (ReportList *reports, PointerRNA ptr, PropertyRNA *prop, FCurve *fcu, float cfra, short flag)
 {
 	float curval= 0.0f;
 	
 	/* no F-Curve to add keyframe to? */
 	if (fcu == NULL) {
-		printf("ERROR: no F-Curve to add keyframes to \n");
+		BKE_report(reports, RPT_ERROR, "No F-Curve to add keyframes to");
 		return 0;
 	}
 	/* F-Curve not editable? */
-	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");
+	if (fcurve_is_keyframable(fcu) == 0) {
+		BKE_reportf(reports, RPT_ERROR, 
+			"F-Curve with path = '%s' [%d] cannot be keyframed. Ensure that it is not locked or sampled. Also, try removing F-Modifiers.",
+			fcu->rna_path, fcu->array_index);
 		return 0;
 	}
 	
 	/* if no property given yet, try to validate from F-Curve info */
 	if ((ptr.id.data == NULL) && (ptr.data==NULL)) {
-		printf("ERROR: no RNA-pointer available to retrieve values for keyframing from\n");
+		BKE_report(reports, RPT_ERROR, "No RNA-pointer available to retrieve values for keyframing from");
 		return 0;
 	}
 	if (prop == NULL) {
@@ -726,7 +727,9 @@
 			/* property not found... */
 			char *idname= (ptr.id.data) ? ((ID *)ptr.id.data)->name : "<No ID-Pointer>";
 			
-			printf("Insert Key: Could not insert keyframe, as RNA Path is invalid for the given ID (ID = %s, Path = %s)\n", idname, fcu->rna_path);
+			BKE_reportf(reports, RPT_ERROR,
+				"Could not insert keyframe, as RNA Path is invalid for the given ID (ID = %s, Path = %s)", 
+				idname, fcu->rna_path);
 			return 0;
 		}
 		else {
@@ -815,7 +818,7 @@
  *
  *	index of -1 keys all array indices
  */
-short insert_keyframe (ID *id, bAction *act, const char group[], const char rna_path[], int array_index, float cfra, short flag)
+short insert_keyframe (ReportList *reports, ID *id, bAction *act, const char group[], const char rna_path[], int array_index, float cfra, short flag)
 {	
 	PointerRNA id_ptr, ptr;
 	PropertyRNA *prop = NULL;
@@ -825,13 +828,14 @@
 	
 	/* validate pointer first - exit if failure */
 	if (id == NULL) {
-		printf("Insert Key: no ID-block to insert keyframe in (Path = %s) \n", rna_path);
+		BKE_reportf(reports, RPT_ERROR, "No ID-block to insert keyframe in (Path = %s)", rna_path);
 		return 0;
 	}
 	
 	RNA_id_pointer_create(id, &id_ptr);
 	if ((RNA_path_resolve(&id_ptr, rna_path, &ptr, &prop) == 0) || (prop == NULL)) {
-		printf("Insert Key: Could not insert keyframe, as RNA Path is invalid for the given ID (ID = %s, Path = %s)\n", 
+		BKE_reportf(reports, RPT_ERROR,

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list