At last... this merge should finally do the trick!
[blender.git] / source / blender / editors / space_action / action_edit.c
index a0f1adbd97e0895d2bb009dc5b241caaa699a169..61dbc41e7c8c2fd4cb8a1d70b2f7982bb7289215 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * $Id: editaction.c 17746 2008-12-08 11:19:44Z aligorith $
+ * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
@@ -67,6 +67,7 @@
 #include "BKE_fcurve.h"
 #include "BKE_key.h"
 #include "BKE_material.h"
+#include "BKE_nla.h"
 #include "BKE_object.h"
 #include "BKE_context.h"
 #include "BKE_report.h"
@@ -112,16 +113,16 @@ static void get_keyframe_extents (bAnimContext *ac, float *min, float *max)
        if (anim_data.first) {
                /* go through channels, finding max extents */
                for (ale= anim_data.first; ale; ale= ale->next) {
-                       Object *nob= ANIM_nla_mapping_get(ac, ale);
+                       AnimData *adt= ANIM_nla_mapping_get(ac, ale);
                        FCurve *fcu= (FCurve *)ale->key_data;
                        float tmin, tmax;
                        
                        /* get range and apply necessary scaling before */
                        calc_fcurve_range(fcu, &tmin, &tmax);
                        
-                       if (nob) {
-                               tmin= get_action_frame_inv(nob, tmin);
-                               tmax= get_action_frame_inv(nob, tmax);
+                       if (adt) {
+                               tmin= BKE_nla_tweakedit_remap(adt, tmin, 1);
+                               tmax= BKE_nla_tweakedit_remap(adt, tmax, 1);
                        }
                        
                        /* try to set cur using these values, if they're more extreme than previously set values */
@@ -181,7 +182,7 @@ void ACT_OT_previewrange_set (wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= actkeys_previewrange_exec;
-       ot->poll= ED_operator_areaactive;
+       ot->poll= ED_operator_action_active;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -228,7 +229,7 @@ void ACT_OT_view_all (wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= actkeys_viewall_exec;
-       ot->poll= ED_operator_areaactive;
+       ot->poll= ED_operator_action_active;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -307,15 +308,15 @@ static int actkeys_copy_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
  
-void ACT_OT_keyframes_copy (wmOperatorType *ot)
+void ACT_OT_copy (wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Copy Keyframes";
-       ot->idname= "ACT_OT_keyframes_copy";
+       ot->idname= "ACT_OT_copy";
        
        /* api callbacks */
        ot->exec= actkeys_copy_exec;
-       ot->poll= ED_operator_areaactive;
+       ot->poll= ED_operator_action_active;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -351,15 +352,15 @@ static int actkeys_paste_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
  
-void ACT_OT_keyframes_paste (wmOperatorType *ot)
+void ACT_OT_paste (wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Paste Keyframes";
-       ot->idname= "ACT_OT_keyframes_paste";
+       ot->idname= "ACT_OT_paste";
        
        /* api callbacks */
        ot->exec= actkeys_paste_exec;
-       ot->poll= ED_operator_areaactive;
+       ot->poll= ED_operator_action_active;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -400,14 +401,14 @@ static void insert_action_keys(bAnimContext *ac, short mode)
        
        /* insert keyframes */
        for (ale= anim_data.first; ale; ale= ale->next) {
-               //Object *nob= ANIM_nla_mapping_get(ac, ale);
+               AnimData *adt= ANIM_nla_mapping_get(ac, ale);
                FCurve *fcu= (FCurve *)ale->key_data;
                
                /* adjust current frame for NLA-scaling */
-               //if (nob)
-               //      cfra= get_action_frame(nob, CFRA);
-               //else 
-               //      cfra= (float)CFRA;
+               if (adt)
+                       cfra= BKE_nla_tweakedit_remap(adt, (float)CFRA, 0);
+               else 
+                       cfra= (float)CFRA;
                        
                /* if there's an id */
                if (ale->id)
@@ -447,16 +448,16 @@ static int actkeys_insertkey_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void ACT_OT_keyframes_insert (wmOperatorType *ot)
+void ACT_OT_insert (wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Insert Keyframes";
-       ot->idname= "ACT_OT_keyframes_insert";
+       ot->idname= "ACT_OT_insert";
        
        /* api callbacks */
        ot->invoke= WM_menu_invoke;
        ot->exec= actkeys_insertkey_exec;
-       ot->poll= ED_operator_areaactive;
+       ot->poll= ED_operator_action_active;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -524,16 +525,16 @@ static int actkeys_duplicate_invoke(bContext *C, wmOperator *op, wmEvent *event)
        return OPERATOR_FINISHED;
 }
  
-void ACT_OT_keyframes_duplicate (wmOperatorType *ot)
+void ACT_OT_duplicate (wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Duplicate Keyframes";
-       ot->idname= "ACT_OT_keyframes_duplicate";
+       ot->idname= "ACT_OT_duplicate";
        
        /* api callbacks */
        ot->invoke= actkeys_duplicate_invoke;
        ot->exec= actkeys_duplicate_exec;
-       ot->poll= ED_operator_areaactive;
+       ot->poll= ED_operator_action_active;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -591,16 +592,16 @@ static int actkeys_delete_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
  
-void ACT_OT_keyframes_delete (wmOperatorType *ot)
+void ACT_OT_delete (wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Delete Keyframes";
-       ot->idname= "ACT_OT_keyframes_delete";
+       ot->idname= "ACT_OT_delete";
        
        /* api callbacks */
        ot->invoke= WM_operator_confirm;
        ot->exec= actkeys_delete_exec;
-       ot->poll= ED_operator_areaactive;
+       ot->poll= ED_operator_action_active;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -654,16 +655,16 @@ static int actkeys_clean_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
  
-void ACT_OT_keyframes_clean (wmOperatorType *ot)
+void ACT_OT_clean (wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Clean Keyframes";
-       ot->idname= "ACT_OT_keyframes_clean";
+       ot->idname= "ACT_OT_clean";
        
        /* api callbacks */
        //ot->invoke=  // XXX we need that number popup for this! 
        ot->exec= actkeys_clean_exec;
-       ot->poll= ED_operator_areaactive;
+       ot->poll= ED_operator_action_active;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -778,15 +779,15 @@ static int actkeys_sample_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
  
-void ACT_OT_keyframes_sample (wmOperatorType *ot)
+void ACT_OT_sample (wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Sample Keyframes";
-       ot->idname= "ACT_OT_keyframes_sample";
+       ot->idname= "ACT_OT_sample";
        
        /* api callbacks */
        ot->exec= actkeys_sample_exec;
-       ot->poll= ED_operator_areaactive;
+       ot->poll= ED_operator_action_active;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -853,16 +854,16 @@ static int actkeys_expo_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
  
-void ACT_OT_keyframes_extrapolation_type_set (wmOperatorType *ot)
+void ACT_OT_extrapolation_type (wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Set Keyframe Extrapolation";
-       ot->idname= "ACT_OT_keyframes_extrapolation_type_set";
+       ot->idname= "ACT_OT_extrapolation_type";
        
        /* api callbacks */
        ot->invoke= WM_menu_invoke;
        ot->exec= actkeys_expo_exec;
-       ot->poll= ED_operator_areaactive;
+       ot->poll= ED_operator_action_active;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -923,16 +924,16 @@ static int actkeys_ipo_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
  
-void ACT_OT_keyframes_interpolation_type (wmOperatorType *ot)
+void ACT_OT_interpolation_type (wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Set Keyframe Interpolation";
-       ot->idname= "ACT_OT_keyframes_interpolation_type";
+       ot->idname= "ACT_OT_interpolation_type";
        
        /* api callbacks */
        ot->invoke= WM_menu_invoke;
        ot->exec= actkeys_ipo_exec;
-       ot->poll= ED_operator_areaactive;
+       ot->poll= ED_operator_action_active;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -1011,16 +1012,16 @@ static int actkeys_handletype_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
  
-void ACT_OT_keyframes_handle_type_set (wmOperatorType *ot)
+void ACT_OT_handle_type (wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Set Keyframe Handle Type";
-       ot->idname= "ACT_OT_keyframes_handle_type_set";
+       ot->idname= "ACT_OT_handle_type";
        
        /* api callbacks */
        ot->invoke= WM_menu_invoke;
        ot->exec= actkeys_handletype_exec;
-       ot->poll= ED_operator_areaactive;
+       ot->poll= ED_operator_action_active;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -1032,10 +1033,10 @@ void ACT_OT_keyframes_handle_type_set (wmOperatorType *ot)
 /* ************************************************************************** */
 /* TRANSFORM STUFF */
 
-/* ***************** Snap Current Frame Operator *********************** */
+/* ***************** Jump to Selected Frames Operator *********************** */
 
 /* snap current-frame indicator to 'average time' of selected keyframe */
-static int actkeys_cfrasnap_exec(bContext *C, wmOperator *op)
+static int actkeys_framejump_exec(bContext *C, wmOperator *op)
 {
        bAnimContext ac;
        ListBase anim_data= {NULL, NULL};
@@ -1054,8 +1055,17 @@ static int actkeys_cfrasnap_exec(bContext *C, wmOperator *op)
        filter= (ANIMFILTER_VISIBLE | ANIMFILTER_CURVESONLY);
        ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
        
-       for (ale= anim_data.first; ale; ale= ale->next)
-               ANIM_fcurve_keys_bezier_loop(&bed, ale->key_data, NULL, bezt_calc_average, NULL);
+       for (ale= anim_data.first; ale; ale= ale->next) {
+               AnimData *adt= ANIM_nla_mapping_get(&ac, ale);
+               
+               if (adt) {
+                       ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1); 
+                       ANIM_fcurve_keys_bezier_loop(&bed, ale->key_data, NULL, bezt_calc_average, NULL);
+                       ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1);
+               }
+               else
+                       ANIM_fcurve_keys_bezier_loop(&bed, ale->key_data, NULL, bezt_calc_average, NULL);
+       }
        
        BLI_freelistN(&anim_data);
        
@@ -1071,15 +1081,15 @@ static int actkeys_cfrasnap_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void ACT_OT_keyframes_cfrasnap (wmOperatorType *ot)
+void ACT_OT_frame_jump (wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Snap Current Frame to Keys";
-       ot->idname= "ACT_OT_keyframes_cfrasnap";
+       ot->name= "Jump to Frame";
+       ot->idname= "ACT_OT_frame_jump";
        
        /* api callbacks */
-       ot->exec= actkeys_cfrasnap_exec;
-       ot->poll= ED_operator_areaactive;
+       ot->exec= actkeys_framejump_exec;
+       ot->poll= ED_operator_action_active;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -1125,12 +1135,12 @@ static void snap_action_keys(bAnimContext *ac, short mode)
        
        /* snap keyframes */
        for (ale= anim_data.first; ale; ale= ale->next) {
-               Object *nob= ANIM_nla_mapping_get(ac, ale);
+               AnimData *adt= ANIM_nla_mapping_get(ac, ale);
                
-               if (nob) {
-                       ANIM_nla_mapping_apply_fcurve(nob, ale->key_data, 0, 1); 
+               if (adt) {
+                       ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1); 
                        ANIM_fcurve_keys_bezier_loop(&bed, ale->key_data, NULL, edit_cb, calchandles_fcurve);
-                       ANIM_nla_mapping_apply_fcurve(nob, ale->key_data, 1, 1);
+                       ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1);
                }
                //else if (ale->type == ACTTYPE_GPLAYER)
                //      snap_gplayer_frames(ale->data, mode);
@@ -1166,16 +1176,16 @@ static int actkeys_snap_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
  
-void ACT_OT_keyframes_snap (wmOperatorType *ot)
+void ACT_OT_snap (wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Snap Keys";
-       ot->idname= "ACT_OT_keyframes_snap";
+       ot->idname= "ACT_OT_snap";
        
        /* api callbacks */
        ot->invoke= WM_menu_invoke;
        ot->exec= actkeys_snap_exec;
-       ot->poll= ED_operator_areaactive;
+       ot->poll= ED_operator_action_active;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -1241,12 +1251,12 @@ static void mirror_action_keys(bAnimContext *ac, short mode)
        
        /* mirror keyframes */
        for (ale= anim_data.first; ale; ale= ale->next) {
-               Object *nob= ANIM_nla_mapping_get(ac, ale);
+               AnimData *adt= ANIM_nla_mapping_get(ac, ale);
                
-               if (nob) {
-                       ANIM_nla_mapping_apply_fcurve(nob, ale->key_data, 0, 1); 
+               if (adt) {
+                       ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1); 
                        ANIM_fcurve_keys_bezier_loop(&bed, ale->key_data, NULL, edit_cb, calchandles_fcurve);
-                       ANIM_nla_mapping_apply_fcurve(nob, ale->key_data, 1, 1);
+                       ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1);
                }
                //else if (ale->type == ACTTYPE_GPLAYER)
                //      snap_gplayer_frames(ale->data, mode);
@@ -1282,16 +1292,16 @@ static int actkeys_mirror_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
  
-void ACT_OT_keyframes_mirror (wmOperatorType *ot)
+void ACT_OT_mirror (wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Mirror Keys";
-       ot->idname= "ACT_OT_keyframes_mirror";
+       ot->idname= "ACT_OT_mirror";
        
        /* api callbacks */
        ot->invoke= WM_menu_invoke;
        ot->exec= actkeys_mirror_exec;
-       ot->poll= ED_operator_areaactive;
+       ot->poll= ED_operator_action_active;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;