From 2c3e8850a53020310a6a8f5c51b764ca261c24c0 Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Mon, 29 Jun 2009 03:02:41 +0000 Subject: NLA SoC: Insert Keyframe Operator Tweaks (Anim Editor Versions) * Insert Keyframe (IKEY) operator for Graph Editor * Renamed the DopeSheet version to make it more consistent with the other keyframing operators --- source/blender/editors/space_action/action_edit.c | 8 +- .../blender/editors/space_action/action_header.c | 2 +- .../blender/editors/space_action/action_intern.h | 2 +- source/blender/editors/space_action/action_ops.c | 4 +- source/blender/editors/space_graph/graph_edit.c | 98 +++++++++++++++++++++- source/blender/editors/space_graph/graph_header.c | 2 +- source/blender/editors/space_graph/graph_intern.h | 1 + source/blender/editors/space_graph/graph_ops.c | 2 + 8 files changed, 109 insertions(+), 10 deletions(-) (limited to 'source') diff --git a/source/blender/editors/space_action/action_edit.c b/source/blender/editors/space_action/action_edit.c index dd351c92cf2..505ff18d7bd 100644 --- a/source/blender/editors/space_action/action_edit.c +++ b/source/blender/editors/space_action/action_edit.c @@ -433,10 +433,10 @@ static int actkeys_insertkey_exec(bContext *C, wmOperator *op) if (ac.datatype == ANIMCONT_GPENCIL) return OPERATOR_CANCELLED; - /* get snapping mode */ + /* what channels to affect? */ mode= RNA_enum_get(op->ptr, "type"); - /* snap keyframes */ + /* insert keyframes */ insert_action_keys(&ac, mode); /* validate keyframes after editing */ @@ -448,11 +448,11 @@ static int actkeys_insertkey_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -void ACT_OT_insert (wmOperatorType *ot) +void ACT_OT_insert_keyframe (wmOperatorType *ot) { /* identifiers */ ot->name= "Insert Keyframes"; - ot->idname= "ACT_OT_insert"; + ot->idname= "ACT_OT_insert_keyframe"; /* api callbacks */ ot->invoke= WM_menu_invoke; diff --git a/source/blender/editors/space_action/action_header.c b/source/blender/editors/space_action/action_header.c index 62e7a2d8e3f..b2614411002 100644 --- a/source/blender/editors/space_action/action_header.c +++ b/source/blender/editors/space_action/action_header.c @@ -211,7 +211,7 @@ static void act_editmenu(bContext *C, uiLayout *layout, void *arg_unused) uiItemS(layout); - uiItemO(layout, NULL, 0, "ACT_OT_insert"); + uiItemO(layout, NULL, 0, "ACT_OT_insert_keyframe"); uiItemS(layout); diff --git a/source/blender/editors/space_action/action_intern.h b/source/blender/editors/space_action/action_intern.h index 6ccdc07421b..26655892176 100644 --- a/source/blender/editors/space_action/action_intern.h +++ b/source/blender/editors/space_action/action_intern.h @@ -83,7 +83,7 @@ void ACT_OT_view_all(struct wmOperatorType *ot); void ACT_OT_copy(struct wmOperatorType *ot); void ACT_OT_paste(struct wmOperatorType *ot); -void ACT_OT_insert(struct wmOperatorType *ot); +void ACT_OT_insert_keyframe(struct wmOperatorType *ot); void ACT_OT_duplicate(struct wmOperatorType *ot); void ACT_OT_delete(struct wmOperatorType *ot); void ACT_OT_clean(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_action/action_ops.c b/source/blender/editors/space_action/action_ops.c index c023062453c..674506ddba0 100644 --- a/source/blender/editors/space_action/action_ops.c +++ b/source/blender/editors/space_action/action_ops.c @@ -79,7 +79,7 @@ void action_operatortypes(void) WM_operatortype_append(ACT_OT_clean); WM_operatortype_append(ACT_OT_delete); WM_operatortype_append(ACT_OT_duplicate); - WM_operatortype_append(ACT_OT_insert); + WM_operatortype_append(ACT_OT_insert_keyframe); WM_operatortype_append(ACT_OT_copy); WM_operatortype_append(ACT_OT_paste); @@ -142,7 +142,7 @@ static void action_keymap_keyframes (wmWindowManager *wm, ListBase *keymap) WM_keymap_add_item(keymap, "ACT_OT_delete", DELKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "ACT_OT_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0); - WM_keymap_add_item(keymap, "ACT_OT_insert", IKEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "ACT_OT_insert_keyframe", IKEY, KM_PRESS, 0, 0); /* copy/paste */ WM_keymap_add_item(keymap, "ACT_OT_copy", CKEY, KM_PRESS, KM_CTRL, 0); diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c index e38c24ed223..1fc4572b9c6 100644 --- a/source/blender/editors/space_graph/graph_edit.c +++ b/source/blender/editors/space_graph/graph_edit.c @@ -399,7 +399,103 @@ void GRAPH_OT_ghost_curves_clear (wmOperatorType *ot) /* ************************************************************************** */ /* GENERAL STUFF */ -// TODO: insertkey +/* ******************** Insert Keyframes Operator ************************* */ + +/* defines for insert keyframes tool */ +EnumPropertyItem prop_graphkeys_insertkey_types[] = { + {1, "ALL", 0, "All Channels", ""}, + {2, "SEL", 0, "Only Selected Channels", ""}, + {0, NULL, 0, NULL, NULL} +}; + +/* this function is responsible for snapping keyframes to frame-times */ +static void insert_graph_keys(bAnimContext *ac, short mode) +{ + ListBase anim_data = {NULL, NULL}; + bAnimListElem *ale; + int filter; + + Scene *scene= ac->scene; + float cfra= (float)CFRA; + short flag = 0; + + /* filter data */ + filter= (ANIMFILTER_VISIBLE | ANIMFILTER_CURVEVISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY); + if (mode == 2) filter |= ANIMFILTER_SEL; + + ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); + + /* init keyframing flag */ + if (IS_AUTOKEY_FLAG(AUTOMATKEY)) flag |= INSERTKEY_MATRIX; + if (IS_AUTOKEY_FLAG(INSERTNEEDED)) flag |= INSERTKEY_NEEDED; + // if (IS_AUTOKEY_MODE(EDITKEYS)) flag |= INSERTKEY_REPLACE; + + /* insert keyframes */ + for (ale= anim_data.first; ale; ale= ale->next) { + AnimData *adt= ANIM_nla_mapping_get(ac, ale); + FCurve *fcu= (FCurve *)ale->key_data; + + /* adjust current frame for NLA-mapping */ + if (adt) + cfra= BKE_nla_tweakedit_remap(adt, (float)CFRA, NLATIME_CONVERT_UNMAP); + else + cfra= (float)CFRA; + + /* if there's an id */ + if (ale->id) + insert_keyframe(ale->id, NULL, ((fcu->grp)?(fcu->grp->name):(NULL)), fcu->rna_path, fcu->array_index, cfra, flag); + else + insert_vert_fcurve(fcu, cfra, fcu->curval, 0); + } + + BLI_freelistN(&anim_data); +} + +/* ------------------- */ + +static int graphkeys_insertkey_exec(bContext *C, wmOperator *op) +{ + bAnimContext ac; + short mode; + + /* get editor data */ + if (ANIM_animdata_get_context(C, &ac) == 0) + return OPERATOR_CANCELLED; + if (ac.datatype == ANIMCONT_GPENCIL) + return OPERATOR_CANCELLED; + + /* which channels to affect? */ + mode= RNA_enum_get(op->ptr, "type"); + + /* insert keyframes */ + insert_graph_keys(&ac, mode); + + /* validate keyframes after editing */ + ANIM_editkeyframes_refresh(&ac); + + /* set notifier that things have changed */ + ANIM_animdata_send_notifiers(C, &ac, ANIM_CHANGED_KEYFRAMES_VALUES); + + return OPERATOR_FINISHED; +} + +void GRAPH_OT_insert_keyframe (wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Insert Keyframes"; + ot->idname= "GRAPH_OT_insert_keyframe"; + + /* api callbacks */ + ot->invoke= WM_menu_invoke; + ot->exec= graphkeys_insertkey_exec; + ot->poll= ED_operator_ipo_active; // xxx + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + /* id-props */ + RNA_def_enum(ot->srna, "type", prop_graphkeys_insertkey_types, 0, "Type", ""); +} /* ******************** Click-Insert Keyframes Operator ************************* */ diff --git a/source/blender/editors/space_graph/graph_header.c b/source/blender/editors/space_graph/graph_header.c index 0bd08625d68..b07bd4b0ded 100644 --- a/source/blender/editors/space_graph/graph_header.c +++ b/source/blender/editors/space_graph/graph_header.c @@ -201,7 +201,7 @@ static void graph_editmenu(bContext *C, uiLayout *layout, void *arg_unused) uiItemS(layout); - //uiItemO(layout, NULL, 0, "GRAPH_OT_insert"); + uiItemO(layout, NULL, 0, "GRAPH_OT_insert_keyframe"); uiItemO(layout, NULL, 0, "GRAPH_OT_fmodifier_add"); uiItemS(layout); diff --git a/source/blender/editors/space_graph/graph_intern.h b/source/blender/editors/space_graph/graph_intern.h index 93e3df1c728..d520a63c126 100644 --- a/source/blender/editors/space_graph/graph_intern.h +++ b/source/blender/editors/space_graph/graph_intern.h @@ -86,6 +86,7 @@ void GRAPH_OT_previewrange_set(struct wmOperatorType *ot); void GRAPH_OT_view_all(struct wmOperatorType *ot); void GRAPH_OT_click_insert(struct wmOperatorType *ot); +void GRAPH_OT_insert_keyframe(struct wmOperatorType *ot); void GRAPH_OT_copy(struct wmOperatorType *ot); void GRAPH_OT_paste(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_graph/graph_ops.c b/source/blender/editors/space_graph/graph_ops.c index f7799023f34..012bfd944b4 100644 --- a/source/blender/editors/space_graph/graph_ops.c +++ b/source/blender/editors/space_graph/graph_ops.c @@ -132,6 +132,7 @@ void graphedit_operatortypes(void) WM_operatortype_append(GRAPH_OT_copy); WM_operatortype_append(GRAPH_OT_paste); + WM_operatortype_append(GRAPH_OT_insert_keyframe); WM_operatortype_append(GRAPH_OT_click_insert); /* F-Curve Modifiers */ @@ -209,6 +210,7 @@ static void graphedit_keymap_keyframes (wmWindowManager *wm, ListBase *keymap) WM_keymap_add_item(keymap, "GRAPH_OT_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0); /* insertkey */ + WM_keymap_add_item(keymap, "GRAPH_OT_insert_keyframe", IKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "GRAPH_OT_click_insert", LEFTMOUSE, KM_PRESS, KM_CTRL, 0); /* copy/paste */ -- cgit v1.2.3