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.
This commit is contained in:
2009-09-25 12:20:31 +00:00
parent ff7157d6f8
commit f49a18f30b
2 changed files with 33 additions and 22 deletions

View File

@@ -1710,13 +1710,18 @@ static int graph_fmodifier_add_invoke (bContext *C, wmOperator *op, wmEvent *eve
/* 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_invoke (bContext *C, wmOperator *op, wmEvent *eve
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 @@ void GRAPH_OT_fmodifier_add (wmOperatorType *ot)
/* 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.");
}
/* ************************************************************************** */

View File

@@ -221,7 +221,7 @@ static void graphedit_keymap_keyframes (wmWindowManager *wm, wmKeyMap *keymap)
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 */