[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [23485] trunk/blender/source/blender/ editors/space_graph: Graph Editor: F-Modifiers can now be added to multiple selected F-Curves at once with the Ctrl-Shift-M hotkey .

Joshua Leung aligorith at gmail.com
Fri Sep 25 14:20:43 CEST 2009


Revision: 23485
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23485
Author:   aligorith
Date:     2009-09-25 14:20:31 +0200 (Fri, 25 Sep 2009)

Log Message:
-----------
Graph Editor: F-Modifiers can now be added to multiple selected F-Curves at once with the Ctrl-Shift-M hotkey. 

* All the selected F-Curves will get the same type of F-Modifier added.
* The button in the properties region will still only added the F-Modifier to the active F-Curve though
* For now, there must be an active F-Curve in either case, otherwise the poll() callback fails.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_graph/graph_edit.c
    trunk/blender/source/blender/editors/space_graph/graph_ops.c

Modified: trunk/blender/source/blender/editors/space_graph/graph_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_graph/graph_edit.c	2009-09-25 11:24:33 UTC (rev 23484)
+++ trunk/blender/source/blender/editors/space_graph/graph_edit.c	2009-09-25 12:20:31 UTC (rev 23485)
@@ -1710,13 +1710,18 @@
 	/* start from 1 to skip the 'Invalid' modifier type */
 	for (i = 1; i < FMODIFIER_NUM_TYPES; i++) {
 		FModifierTypeInfo *fmi= get_fmodifier_typeinfo(i);
+		PointerRNA props_ptr;
 		
 		/* check if modifier is valid for this context */
 		if (fmi == NULL)
 			continue;
 		
-		/* add entry to add this type of modifier */
-		uiItemEnumO(layout, fmi->name, 0, "GRAPH_OT_fmodifier_add", "type", i);
+		/* create operator menu item with relevant properties filled in */
+		props_ptr= uiItemFullO(layout, fmi->name, 0, "GRAPH_OT_fmodifier_add", NULL, WM_OP_EXEC_REGION_WIN, UI_ITEM_O_RETURN_PROPS);
+			/* the only thing that gets set from the menu is the type of F-Modifier to add */
+		RNA_enum_set(&props_ptr, "type", i);
+			/* the following properties are just repeats of existing ones... */
+		RNA_boolean_set(&props_ptr, "only_active", RNA_boolean_get(op->ptr, "only_active"));
 	}
 	uiItemS(layout);
 	
@@ -1728,36 +1733,41 @@
 static int graph_fmodifier_add_exec(bContext *C, wmOperator *op)
 {
 	bAnimContext ac;
+	ListBase anim_data = {NULL, NULL};
 	bAnimListElem *ale;
-	FCurve *fcu;
-	FModifier *fcm;
+	int filter;
 	short type;
 	
 	/* get editor data */
 	if (ANIM_animdata_get_context(C, &ac) == 0)
 		return OPERATOR_CANCELLED;
-		
-		// xxx call the raw methods here instead?
-	ale= get_active_fcurve_channel(&ac);
-	if (ale == NULL) 
-		return OPERATOR_CANCELLED;
 	
-	fcu= (FCurve *)ale->data;
-	MEM_freeN(ale);
-	if (fcu == NULL) 
-		return OPERATOR_CANCELLED;
-		
 	/* get type of modifier to add */
 	type= RNA_enum_get(op->ptr, "type");
 	
-	/* add F-Modifier of specified type to active F-Curve, and make it the active one */
-	fcm= add_fmodifier(&fcu->modifiers, type);
-	if (fcm)
-		set_active_fmodifier(&fcu->modifiers, fcm);
-	else {
-		BKE_report(op->reports, RPT_ERROR, "Modifier couldn't be added. See console for details.");
-		return OPERATOR_CANCELLED;
+	/* filter data */
+	filter= (ANIMFILTER_VISIBLE | ANIMFILTER_CURVEVISIBLE| ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY);
+	if (RNA_boolean_get(op->ptr, "only_active"))
+		filter |= ANIMFILTER_ACTIVE;
+	else
+		filter |= ANIMFILTER_SEL;
+	ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
+	
+	/* smooth keyframes */
+	for (ale= anim_data.first; ale; ale= ale->next) {
+		FCurve *fcu= (FCurve *)ale->data;
+		FModifier *fcm;
+		
+		/* add F-Modifier of specified type to active F-Curve, and make it the active one */
+		fcm= add_fmodifier(&fcu->modifiers, type);
+		if (fcm)
+			set_active_fmodifier(&fcu->modifiers, fcm);
+		else { // TODO: stop when this happens?
+			BKE_report(op->reports, RPT_ERROR, "Modifier couldn't be added. See console for details.");
+			break;
+		}
 	}
+	BLI_freelistN(&anim_data);
 	
 	/* validate keyframes after editing */
 	ANIM_editkeyframes_refresh(&ac);
@@ -1786,6 +1796,7 @@
 	
 	/* id-props */
 	RNA_def_enum(ot->srna, "type", fmodifier_type_items, 0, "Type", "");
+	RNA_def_boolean(ot->srna, "only_active", 1, "Only Active", "Only add F-Modifier to active F-Curve.");
 }
 
 /* ************************************************************************** */

Modified: trunk/blender/source/blender/editors/space_graph/graph_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_graph/graph_ops.c	2009-09-25 11:24:33 UTC (rev 23484)
+++ trunk/blender/source/blender/editors/space_graph/graph_ops.c	2009-09-25 12:20:31 UTC (rev 23485)
@@ -221,7 +221,7 @@
 	WM_keymap_add_item(keymap, "GRAPH_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
 	
 		/* F-Modifiers */
-	WM_keymap_add_item(keymap, "GRAPH_OT_fmodifier_add", MKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
+	RNA_boolean_set(WM_keymap_add_item(keymap, "GRAPH_OT_fmodifier_add", MKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "only_active", 0);
 	
 	
 	/* transform system */





More information about the Bf-blender-cvs mailing list