At last... this merge should finally do the trick!
[blender.git] / source / blender / editors / transform / transform.c
index 4212964ccec98e4c7b24082b9c62e948c164a8eb..ded6edbbb0e278ad656ac731224c63b1648543a7 100644 (file)
@@ -45,6 +45,7 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "DNA_anim_types.h"
 #include "DNA_armature_types.h"
 #include "DNA_action_types.h"  /* for some special action-editor settings */
 #include "DNA_constraint_types.h"
@@ -76,9 +77,9 @@
 //#include "BIF_editmesh.h"
 //#include "BIF_editsima.h"
 //#include "BIF_editparticle.h"
-//#include "BIF_editaction.h" 
 
-#include "BKE_action.h" /* get_action_frame */
+#include "BKE_action.h"
+#include "BKE_nla.h"
 //#include "BKE_bad_level_calls.h"/* popmenu and error */
 #include "BKE_bmesh.h"
 #include "BKE_context.h"
@@ -89,7 +90,6 @@
 #include "BKE_utildefines.h"
 #include "BKE_context.h"
 
-//#include "BSE_editaction_types.h"
 //#include "BSE_view.h"
 
 #include "ED_image.h"
@@ -319,6 +319,9 @@ static void viewRedrawForce(bContext *C, TransInfo *t)
                else 
                        ED_area_tag_redraw(t->sa);
        }
+       else if (t->spacetype == SPACE_NLA) {
+               ED_area_tag_redraw(t->sa); // XXX this should use a notifier instead!
+       }
        else if(t->spacetype == SPACE_NODE)
        {
                //ED_area_tag_redraw(t->sa);
@@ -599,6 +602,7 @@ void transformEvent(TransInfo *t, wmEvent *event)
                                resetTransRestrictions(t); 
                                restoreTransObjects(t);
                                initTranslation(t);
+                               initSnapping(t, NULL); // need to reinit after mode change
                                t->redraw = 1;
                        }
                        break;
@@ -608,6 +612,7 @@ void transformEvent(TransInfo *t, wmEvent *event)
                                resetTransRestrictions(t); 
                                restoreTransObjects(t);
                                initResize(t);
+                               initSnapping(t, NULL); // need to reinit after mode change
                                t->redraw = 1;
                        }
                        break;
@@ -625,6 +630,7 @@ void transformEvent(TransInfo *t, wmEvent *event)
                                        restoreTransObjects(t);
                                        initRotation(t);
                                }
+                               initSnapping(t, NULL); // need to reinit after mode change
                                t->redraw = 1;
                        }
                        break;
@@ -1131,7 +1137,7 @@ void drawTransform(const struct bContext *C, struct ARegion *ar, void *arg)
 
 void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
 {
-       Scene *sce = CTX_data_scene(C);
+       ToolSettings *ts = CTX_data_tool_settings(C);
        int constraint_axis[3] = {0, 0, 0};
        int proportional = 0;
 
@@ -1192,8 +1198,8 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
        // XXX If modal, save settings back in scene
        if (t->flag & T_MODAL)
        {
-               sce->prop_mode = t->prop_mode;
-               sce->proportional = proportional;
+               ts->prop_mode = t->prop_mode;
+               ts->proportional = proportional;
 
                if(t->spacetype == SPACE_VIEW3D)
                {
@@ -2356,7 +2362,7 @@ static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) {
                }
                else if (t->flag & T_EDIT) {
                        
-                       if(t->around==V3D_LOCAL && (t->scene->selectmode & SCE_SELECT_FACE)) {
+                       if(t->around==V3D_LOCAL && (t->settings->selectmode & SCE_SELECT_FACE)) {
                                VECCOPY(center, td->center);
                        }
                        else {
@@ -2657,7 +2663,7 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short
                }
                else {
                        /* !TODO! Make this if not rely on G */
-                       if(around==V3D_LOCAL && (t->scene->selectmode & SCE_SELECT_FACE)) {
+                       if(around==V3D_LOCAL && (t->settings->selectmode & SCE_SELECT_FACE)) {
                                center = td->center;
                        }
                }
@@ -3123,7 +3129,7 @@ static void headerTranslation(TransInfo *t, float vec[3], char *str) {
                sprintf(distvec, "%.4f", dist);
                
        if(t->flag & T_AUTOIK) {
-               short chainlen= t->scene->toolsettings->autoik_chainlen;
+               short chainlen= t->settings->autoik_chainlen;
                
                if(chainlen)
                        sprintf(autoik, "AutoIK-Len: %d", chainlen);
@@ -4248,7 +4254,7 @@ int Align(TransInfo *t, short mval[2])
                        VECCOPY(t->center, td->center);
                }
                else {
-                       if(t->scene->selectmode & SCE_SELECT_FACE) {
+                       if(t->settings->selectmode & SCE_SELECT_FACE) {
                                VECCOPY(t->center, td->center);
                        }
                }
@@ -4348,7 +4354,7 @@ static short getAnimEdit_DrawTime(TransInfo *t)
 /* This function is used by Animation Editor specific transform functions to do 
  * the Snap Keyframe to Nearest Frame/Marker
  */
-static void doAnimEdit_SnapFrame(TransInfo *t, TransData *td, Object *ob, short autosnap)
+static void doAnimEdit_SnapFrame(TransInfo *t, TransData *td, AnimData *adt, short autosnap)
 {
        /* snap key to nearest frame? */
        if (autosnap == SACTSNAP_FRAME) {
@@ -4358,8 +4364,8 @@ static void doAnimEdit_SnapFrame(TransInfo *t, TransData *td, Object *ob, short
                double val;
                
                /* convert frame to nla-action time (if needed) */
-               if (ob
-                       val= get_action_frame_inv(ob, *(td->val));
+               if (adt
+                       val= BKE_nla_tweakedit_remap(adt, *(td->val), 1);
                else
                        val= *(td->val);
                
@@ -4370,8 +4376,8 @@ static void doAnimEdit_SnapFrame(TransInfo *t, TransData *td, Object *ob, short
                        val= (float)( floor(val+0.5f) );
                        
                /* convert frame out of nla-action time */
-               if (ob)
-                       *(td->val)= get_action_frame(ob, val);
+               if (adt)
+                       *(td->val)= BKE_nla_tweakedit_remap(adt, val, 0);
                else
                        *(td->val)= val;
        }
@@ -4380,8 +4386,8 @@ static void doAnimEdit_SnapFrame(TransInfo *t, TransData *td, Object *ob, short
                float val;
                
                /* convert frame to nla-action time (if needed) */
-               if (ob
-                       val= get_action_frame_inv(ob, *(td->val));
+               if (adt
+                       val= BKE_nla_tweakedit_remap(adt, *(td->val), 1);
                else
                        val= *(td->val);
                
@@ -4390,8 +4396,8 @@ static void doAnimEdit_SnapFrame(TransInfo *t, TransData *td, Object *ob, short
                val= (float)ED_markers_find_nearest_marker_time(&t->scene->markers, val);
                
                /* convert frame out of nla-action time */
-               if (ob)
-                       *(td->val)= get_action_frame(ob, val);
+               if (adt)
+                       *(td->val)= BKE_nla_tweakedit_remap(adt, val, 0);
                else
                        *(td->val)= val;
        }
@@ -4464,13 +4470,14 @@ static void applyTimeTranslate(TransInfo *t, float sval)
        
        /* it doesn't matter whether we apply to t->data or t->data2d, but t->data2d is more convenient */
        for (i = 0 ; i < t->total; i++, td++) {
-               /* it is assumed that td->ob is a pointer to the object,
+               /* it is assumed that td->extra is a pointer to the AnimData,
                 * whose active action is where this keyframe comes from 
+                * (this is only valid when not in NLA)
                 */
-               Object *ob= td->ob;
+               AnimData *adt= (t->spacetype != SPACE_NLA) ? td->extra : NULL;
                
-               /* check if any need to apply nla-scaling */
-               if (ob) {
+               /* check if any need to apply nla-mapping */
+               if (adt) {
                        deltax = t->values[0];
                        
                        if (autosnap == SACTSNAP_STEP) {
@@ -4480,9 +4487,9 @@ static void applyTimeTranslate(TransInfo *t, float sval)
                                        deltax= (float)( floor(deltax + 0.5f) );
                        }
                        
-                       val = get_action_frame_inv(ob, td->ival);
+                       val = BKE_nla_tweakedit_remap(adt, td->ival, 1);
                        val += deltax;
-                       *(td->val) = get_action_frame(ob, val);
+                       *(td->val) = BKE_nla_tweakedit_remap(adt, val, 0);
                }
                else {
                        deltax = val = t->values[0];
@@ -4498,7 +4505,7 @@ static void applyTimeTranslate(TransInfo *t, float sval)
                }
                
                /* apply nearest snapping */
-               doAnimEdit_SnapFrame(t, td, ob, autosnap);
+               doAnimEdit_SnapFrame(t, td, adt, autosnap);
        }
 }
 
@@ -4598,15 +4605,16 @@ static void applyTimeSlide(TransInfo *t, float sval)
        
        /* it doesn't matter whether we apply to t->data or t->data2d, but t->data2d is more convenient */
        for (i = 0 ; i < t->total; i++, td++) {
-               /* it is assumed that td->ob is a pointer to the object,
+               /* it is assumed that td->extra is a pointer to the AnimData,
                 * whose active action is where this keyframe comes from 
+                * (this is only valid when not in NLA)
                 */
-               Object *ob= td->ob;
+               AnimData *adt= (t->spacetype != SPACE_NLA) ? td->extra : NULL;
                float cval = t->values[0];
                
-               /* apply scaling to necessary values */
-               if (ob)
-                       cval= get_action_frame(ob, cval);
+               /* apply NLA-mapping to necessary values */
+               if (adt)
+                       cval= BKE_nla_tweakedit_remap(adt, cval, 0);
                
                /* only apply to data if in range */
                if ((sval > minx) && (sval < maxx)) {
@@ -4701,10 +4709,11 @@ static void applyTimeScale(TransInfo *t) {
        
        
        for (i = 0 ; i < t->total; i++, td++) {
-               /* it is assumed that td->ob is a pointer to the object,
+               /* it is assumed that td->extra is a pointer to the AnimData,
                 * whose active action is where this keyframe comes from 
+                * (this is only valid when not in NLA)
                 */
-               Object *ob= td->ob;
+               AnimData *adt= (t->spacetype != SPACE_NLA) ? td->extra : NULL;
                float startx= CFRA;
                float fac= t->values[0];
                
@@ -4715,9 +4724,9 @@ static void applyTimeScale(TransInfo *t) {
                                fac= (float)( floor(fac + 0.5f) );
                }
                
-               /* check if any need to apply nla-scaling */
-               if (ob)
-                       startx= get_action_frame(ob, startx);
+               /* check if any need to apply nla-mapping */
+               if (adt)
+                       startx= BKE_nla_tweakedit_remap(adt, startx, 0);
                        
                /* now, calculate the new value */
                *(td->val) = td->ival - startx;
@@ -4725,7 +4734,7 @@ static void applyTimeScale(TransInfo *t) {
                *(td->val) += startx;
                
                /* apply nearest snapping */
-               doAnimEdit_SnapFrame(t, td, ob, autosnap);
+               doAnimEdit_SnapFrame(t, td, adt, autosnap);
        }
 }
 
@@ -4739,18 +4748,6 @@ int TimeScale(TransInfo *t, short mval[2])
        sval= t->imval[0];
        cval= mval[0];
        
-       // XXX ewww... we need a better factor!
-#if 0 // TRANSFORM_FIX_ME              
-       switch (t->spacetype) {
-               case SPACE_ACTION:
-                       width= ACTWIDTH;
-                       break;
-               case SPACE_NLA:
-                       width= NLAWIDTH;
-                       break;
-       }
-#endif
-       
        /* calculate scaling factor */
        startx= sval-(width/2+(t->ar->winx)/2);
        deltax= cval-(width/2+(t->ar->winx)/2);