Merging r40653 through r40847 from trunk into soc-2011-tomato
[blender.git] / source / blender / editors / transform / transform_generics.c
index ec76bb3ac3592fc8a8b09dc0af7090ccf7fc080b..cfdd370e568e443c08bfaef1942833c13935a532 100644 (file)
@@ -49,6 +49,7 @@
 #include "DNA_meshdata_types.h"
 #include "DNA_view3d_types.h"
 #include "DNA_modifier_types.h"
+#include "DNA_movieclip_types.h"
 
 #include "RNA_access.h"
 
@@ -72,6 +73,7 @@
 #include "BKE_mesh.h"
 #include "BKE_nla.h"
 #include "BKE_context.h"
+#include "BKE_tracking.h"
 
 #include "ED_anim_api.h"
 #include "ED_armature.h"
@@ -84,7 +86,8 @@
 #include "ED_space_api.h"
 #include "ED_uvedit.h"
 #include "ED_view3d.h"
-#include "ED_curve.h" /* for ED_curve_editnurbs */
+#include "ED_curve.h" /* for curve_editnurbs */
+#include "ED_clip.h"
 
 //#include "BDR_unwrapper.h"
 
@@ -115,9 +118,9 @@ void getViewVector(TransInfo *t, float coord[3], float vec[3])
        {
                float p1[4], p2[4];
                
-               VECCOPY(p1, coord);
+               copy_v3_v3(p1, coord);
                p1[3] = 1.0f;
-               VECCOPY(p2, p1);
+               copy_v3_v3(p2, p1);
                p2[3] = 1.0f;
                mul_m4_v4(t->viewmat, p2);
                
@@ -130,7 +133,7 @@ void getViewVector(TransInfo *t, float coord[3], float vec[3])
                sub_v3_v3v3(vec, p1, p2);
        }
        else {
-               VECCOPY(vec, t->viewinv[2]);
+               copy_v3_v3(vec, t->viewinv[2]);
        }
        normalize_v3(vec);
 }
@@ -144,7 +147,7 @@ static void clipMirrorModifier(TransInfo *t, Object *ob)
        int axis = 0;
        
        for (; md; md=md->next) {
-               if (md->type==eModifierType_Mirror) {
+               if ((md->type==eModifierType_Mirror) && (md->mode & eModifierMode_Realtime)) {
                        MirrorModifierData *mmd = (MirrorModifierData*) md;
                        
                        if(mmd->flag & MOD_MIR_CLIPPING) {
@@ -626,7 +629,7 @@ static void recalcData_view3d(TransInfo *t)
        if (t->obedit) {
                if ELEM(t->obedit->type, OB_CURVE, OB_SURF) {
                        Curve *cu= t->obedit->data;
-                       ListBase *nurbs= ED_curve_editnurbs(cu);
+                       ListBase *nurbs= curve_editnurbs(cu);
                        Nurb *nu= nurbs->first;
                        
                        if(t->state != TRANS_CANCEL) {
@@ -694,12 +697,12 @@ static void recalcData_view3d(TransInfo *t)
                                if ((ebo->flag & BONE_CONNECTED) && ebo->parent){
                                        /* If this bone has a parent tip that has been moved */
                                        if (ebo->parent->flag & BONE_TIPSEL){
-                                               VECCOPY (ebo->head, ebo->parent->tail);
+                                               copy_v3_v3 (ebo->head, ebo->parent->tail);
                                                if(t->mode==TFM_BONE_ENVELOPE) ebo->rad_head= ebo->parent->rad_tail;
                                        }
                                        /* If this bone has a parent tip that has NOT been moved */
                                        else{
-                                               VECCOPY (ebo->parent->tail, ebo->head);
+                                               copy_v3_v3 (ebo->parent->tail, ebo->head);
                                                if(t->mode==TFM_BONE_ENVELOPE) ebo->parent->rad_tail= ebo->rad_head;
                                        }
                                }
@@ -736,7 +739,7 @@ static void recalcData_view3d(TransInfo *t)
                                                float qrot[4];
                                                
                                                ebo = td->extra;
-                                               VECCOPY(up_axis, td->axismtx[2]);
+                                               copy_v3_v3(up_axis, td->axismtx[2]);
                                                
                                                if (t->mode != TFM_ROTATION)
                                                {
@@ -865,6 +868,48 @@ void recalcData(TransInfo *t)
        else if (t->spacetype == SPACE_VIEW3D) {
                recalcData_view3d(t);
        }
+       else if (t->spacetype == SPACE_CLIP) {
+               SpaceClip *sc= t->sa->spacedata.first;
+               MovieClip *clip= ED_space_clip(sc);
+               MovieTrackingTrack *track;
+
+               if(t->state == TRANS_CANCEL) {
+                       track= clip->tracking.tracks.first;
+                       while(track) {
+                               if(TRACK_VIEW_SELECTED(sc, track)) {
+                                       MovieTrackingMarker *marker= BKE_tracking_ensure_marker(track, sc->user.framenr);
+
+                                       marker->flag= track->transflag;
+                               }
+
+                               track= track->next;
+                       }
+               }
+
+               flushTransTracking(t);
+
+               track= clip->tracking.tracks.first;
+               while(track) {
+                       if(TRACK_VIEW_SELECTED(sc, track)) {
+                               if (t->mode == TFM_TRANSLATION) {
+                                       if(TRACK_AREA_SELECTED(track, TRACK_AREA_PAT))
+                                               BKE_tracking_clamp_track(track, CLAMP_PAT_POS);
+                                       if(TRACK_AREA_SELECTED(track, TRACK_AREA_SEARCH))
+                                               BKE_tracking_clamp_track(track, CLAMP_SEARCH_POS);
+                               }
+                               else if (t->mode == TFM_RESIZE) {
+                                       if(TRACK_AREA_SELECTED(track, TRACK_AREA_PAT))
+                                               BKE_tracking_clamp_track(track, CLAMP_PAT_DIM);
+                                       if(TRACK_AREA_SELECTED(track, TRACK_AREA_SEARCH))
+                                               BKE_tracking_clamp_track(track, CLAMP_SEARCH_DIM);
+                               }
+                       }
+
+                       track= track->next;
+               }
+
+               DAG_id_tag_update(&clip->id, 0);
+       }
 }
 
 void drawLine(TransInfo *t, float *center, float *dir, char axis, short options)
@@ -1187,6 +1232,12 @@ int initTransInfo (bContext *C, TransInfo *t, wmOperator *op, wmEvent *event)
                t->options |= CTX_NO_PET;
        }
        
+       // Mirror is not supported with PET, turn it off.
+       if (t->flag & T_PROP_EDIT)
+       {
+               t->flag &= ~T_MIRROR;
+       }
+
        setTransformViewMatrices(t);
        initNumInput(&t->num);
        
@@ -1259,21 +1310,22 @@ void applyTransObjects(TransInfo *t)
        TransData *td;
        
        for (td = t->data; td < t->data + t->total; td++) {
-               VECCOPY(td->iloc, td->loc);
+               copy_v3_v3(td->iloc, td->loc);
                if (td->ext->rot) {
-                       VECCOPY(td->ext->irot, td->ext->rot);
+                       copy_v3_v3(td->ext->irot, td->ext->rot);
                }
                if (td->ext->size) {
-                       VECCOPY(td->ext->isize, td->ext->size);
+                       copy_v3_v3(td->ext->isize, td->ext->size);
                }
        }
        recalcData(t);
 }
 
-static void restoreElement(TransData *td) {
+static void restoreElement(TransData *td)
+{
        /* TransData for crease has no loc */
        if (td->loc) {
-               VECCOPY(td->loc, td->iloc);
+               copy_v3_v3(td->loc, td->iloc);
        }
        if (td->val) {
                *td->val = td->ival;
@@ -1281,17 +1333,17 @@ static void restoreElement(TransData *td) {
 
        if (td->ext && (td->flag&TD_NO_EXT)==0) {
                if (td->ext->rot) {
-                       VECCOPY(td->ext->rot, td->ext->irot);
+                       copy_v3_v3(td->ext->rot, td->ext->irot);
                }
                if(td->ext->rotAngle) {
                        *td->ext->rotAngle= td->ext->irotAngle;
                }
                if(td->ext->rotAxis) {
-                       VECCOPY(td->ext->rotAxis, td->ext->irotAxis);
+                       copy_v3_v3(td->ext->rotAxis, td->ext->irotAxis);
                }
                /* XXX, drotAngle & drotAxis not used yet */
                if (td->ext->size) {
-                       VECCOPY(td->ext->size, td->ext->isize);
+                       copy_v3_v3(td->ext->size, td->ext->isize);
                }
                if (td->ext->quat) {
                        QUATCOPY(td->ext->quat, td->ext->iquat);
@@ -1335,7 +1387,7 @@ void calculateCenter2D(TransInfo *t)
                Object *ob= t->obedit?t->obedit:t->poseobj;
                float vec[3];
                
-               VECCOPY(vec, t->center);
+               copy_v3_v3(vec, t->center);
                mul_m4_v3(ob->obmat, vec);
                projectIntView(t, vec, t->center2d);
        }
@@ -1349,7 +1401,7 @@ void calculateCenterCursor(TransInfo *t)
        float *cursor;
        
        cursor = give_cursor(t->scene, t->view);
-       VECCOPY(t->center, cursor);
+       copy_v3_v3(t->center, cursor);
        
        /* If edit or pose mode, move cursor in local space */
        if (t->flag & (T_EDIT|T_POSE)) {
@@ -1421,7 +1473,7 @@ void calculateCenterMedian(TransInfo *t)
        }
        if(i)
                mul_v3_fl(partial, 1.0f / total);
-       VECCOPY(t->center, partial);
+       copy_v3_v3(t->center, partial);
        
        calculateCenter2D(t);
 }
@@ -1446,8 +1498,8 @@ void calculateCenterBound(TransInfo *t)
                        }
                }
                else {
-                       VECCOPY(max, t->data[i].center);
-                       VECCOPY(min, t->data[i].center);
+                       copy_v3_v3(max, t->data[i].center);
+                       copy_v3_v3(min, t->data[i].center);
                }
        }
        add_v3_v3v3(t->center, min, max);
@@ -1501,7 +1553,7 @@ void calculateCenter(TransInfo *t)
                        Object *ob= OBACT;
                        if(ob)
                        {
-                               VECCOPY(t->center, ob->obmat[3]);
+                               copy_v3_v3(t->center, ob->obmat[3]);
                                projectIntView(t, t->center, t->center2d);
                        }
                }
@@ -1510,7 +1562,7 @@ void calculateCenter(TransInfo *t)
        }
        
        /* setting constraint center */
-       VECCOPY(t->con.center, t->center);
+       copy_v3_v3(t->con.center, t->center);
        if(t->flag & (T_EDIT|T_POSE))
        {
                Object *ob= t->obedit?t->obedit:t->poseobj;
@@ -1530,7 +1582,7 @@ void calculateCenter(TransInfo *t)
                        {
                                float axis[3];
                                /* persinv is nasty, use viewinv instead, always right */
-                               VECCOPY(axis, t->viewinv[2]);
+                               copy_v3_v3(axis, t->viewinv[2]);
                                normalize_v3(axis);
                                
                                /* 6.0 = 6 grid units */
@@ -1543,8 +1595,8 @@ void calculateCenter(TransInfo *t)
                                /* rotate only needs correct 2d center, grab needs initgrabz() value */
                                if(t->mode==TFM_TRANSLATION)
                                {
-                                       VECCOPY(t->center, axis);
-                                       VECCOPY(t->con.center, t->center);
+                                       copy_v3_v3(t->center, axis);
+                                       copy_v3_v3(t->con.center, t->center);
                                }
                        }
                }
@@ -1557,7 +1609,7 @@ void calculateCenter(TransInfo *t)
                        Object *ob= t->obedit?t->obedit:t->poseobj;
                        float vec[3];
                        
-                       VECCOPY(vec, t->center);
+                       copy_v3_v3(vec, t->center);
                        mul_m4_v3(ob->obmat, vec);
                        initgrabz(t->ar->regiondata, vec[0], vec[1], vec[2]);
                }
@@ -1666,13 +1718,13 @@ void calculatePropRatio(TransInfo *t)
                        strcpy(t->proptext, "(Random)");
                        break;
                default:
-                       strcpy(t->proptext, "");
+                       t->proptext[0]= '\0';
                }
        }
        else {
                for(i = 0 ; i < t->total; i++, td++) {
                        td->factor = 1.0;
                }
-               strcpy(t->proptext, "");
+               t->proptext[0]= '\0';
        }
 }