NLA SoC: Insert Keyframe Operator Tweaks (Anim Editor Versions)
authorJoshua Leung <aligorith@gmail.com>
Mon, 29 Jun 2009 03:02:41 +0000 (03:02 +0000)
committerJoshua Leung <aligorith@gmail.com>
Mon, 29 Jun 2009 03:02:41 +0000 (03:02 +0000)
* 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
source/blender/editors/space_action/action_header.c
source/blender/editors/space_action/action_intern.h
source/blender/editors/space_action/action_ops.c
source/blender/editors/space_graph/graph_edit.c
source/blender/editors/space_graph/graph_header.c
source/blender/editors/space_graph/graph_intern.h
source/blender/editors/space_graph/graph_ops.c

index dd351c92cf25f7600766adb85e993559c89eaea3..505ff18d7bdd7965e564ce60120969f8e8178209 100644 (file)
@@ -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;
index 62e7a2d8e3fc76f87aaf86c965370b0797692ea3..b26144110027fd26ef7ea72b868d9c1ffca89c3b 100644 (file)
@@ -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);
        
index 6ccdc07421b3e0b7d2f43e6e3273adb5fc7df078..266558921763c82ef37981dcbc8ad44fdb84c4c8 100644 (file)
@@ -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);
index c023062453c09483e495e9e1545f96c6dfe13f22..674506ddba01e4060355731641f6eb426aa41421 100644 (file)
@@ -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);
index e38c24ed223ce92f105a780846f05014424f1a68..1fc4572b9c674f0da77a5db10d663a1bf0effd7f 100644 (file)
@@ -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 ************************* */
 
index 0bd08625d683cc8c107ab420aef7addc7e24f903..b07bd4b0ded8c528cb304ecd78793d25ffb66b74 100644 (file)
@@ -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);
index 93e3df1c7287ac755f57202d7914ba14cddefd20..d520a63c1263ad8cfee2e51ef3fb8051d55f630c 100644 (file)
@@ -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);
index f7799023f34e6dd730aa2fd8f50a0c3fa3fdb22d..012bfd944b4f17be762835bab6854845b58d00ff 100644 (file)
@@ -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 */