=bmesh= merge from trunk at r36529
[blender.git] / source / blender / editors / transform / transform_generics.c
index 92de95252c3643351b6527466966750935c85342..9a19f1f3205ab9a9387e41ab6e3d5aef7b0e5acb 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
  * ***** END GPL LICENSE BLOCK *****
  */
 
+/** \file blender/editors/transform/transform_generics.c
+ *  \ingroup edtransform
+ */
+
+
 #include <string.h>
 #include <math.h>
 
@@ -88,7 +93,7 @@
 #include "BLI_blenlib.h"
 #include "BLI_editVert.h"
 #include "BLI_rand.h"
-
+#include "BLI_utildefines.h"
 
 #include "WM_types.h"
 #include "WM_api.h"
@@ -270,7 +275,7 @@ static void animrecord_check_state (Scene *scene, ID *id, wmTimer *animtimer)
         *      - we're not only keying for available channels
         *      - the option to add new actions for each round is not enabled
         */
-       if (IS_AUTOKEY_FLAG(INSERTAVAIL)==0 && (scene->toolsettings->autokey_flag & ANIMRECORD_FLAG_WITHNLA)) {
+       if (IS_AUTOKEY_FLAG(scene, INSERTAVAIL)==0 && (scene->toolsettings->autokey_flag & ANIMRECORD_FLAG_WITHNLA)) {
                /* if playback has just looped around, we need to add a new NLA track+strip to allow a clean pass to occur */
                if ((sad) && (sad->flag & ANIMPLAY_FLAG_JUMPED)) {
                        AnimData *adt= BKE_animdata_from_id(id);
@@ -307,7 +312,7 @@ static void animrecord_check_state (Scene *scene, ID *id, wmTimer *animtimer)
 static int fcu_test_selected(FCurve *fcu)
 {
        BezTriple *bezt= fcu->bezt;
-       int i;
+       unsigned int i;
 
        if (bezt==NULL) /* ignore baked */
                return 0;
@@ -322,8 +327,7 @@ static int fcu_test_selected(FCurve *fcu)
 /* called for updating while transform acts, once per redraw */
 void recalcData(TransInfo *t)
 {
-       Scene *scene = t->scene;
-       Base *base = scene->basact;
+       Base *base = t->scene->basact;
 
        if (t->spacetype==SPACE_NODE) {
                flushTransNodes(t);
@@ -335,15 +339,13 @@ void recalcData(TransInfo *t)
                Scene *scene= t->scene;
                SpaceAction *saction= (SpaceAction *)t->sa->spacedata.first;
                
-               bAnimContext ac;
+               bAnimContext ac= {NULL};
                ListBase anim_data = {NULL, NULL};
                bAnimListElem *ale;
                int filter;
                
                /* initialise relevant anim-context 'context' data from TransInfo data */
                        /* NOTE: sync this with the code in ANIM_animdata_get_context() */
-               memset(&ac, 0, sizeof(bAnimContext));
-               
                ac.scene= t->scene;
                ac.obact= OBACT;
                ac.sa= t->sa;
@@ -353,22 +355,29 @@ void recalcData(TransInfo *t)
                
                ANIM_animdata_context_getdata(&ac);
                
-               /* get animdata blocks visible in editor, assuming that these will be the ones where things changed */
-               filter= (ANIMFILTER_VISIBLE | ANIMFILTER_ANIMDATA);
-               ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
-               
-               /* just tag these animdata-blocks to recalc, assuming that some data there changed 
-                * BUT only do this if realtime updates are enabled
-                */
-               if ((saction->flag & SACTION_NOREALTIMEUPDATES) == 0) {
-                       for (ale= anim_data.first; ale; ale= ale->next) {
-                               /* set refresh tags for objects using this animation */
-                               ANIM_list_elem_update(t->scene, ale);
+               /* perform flush */
+               if (ac.datatype == ANIMCONT_GPENCIL) {
+                       /* flush transform values back to actual coordinates */
+                       flushTransGPactionData(t);
+               }
+               else {
+                       /* get animdata blocks visible in editor, assuming that these will be the ones where things changed */
+                       filter= (ANIMFILTER_VISIBLE | ANIMFILTER_ANIMDATA);
+                       ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
+                       
+                       /* just tag these animdata-blocks to recalc, assuming that some data there changed 
+                        * BUT only do this if realtime updates are enabled
+                        */
+                       if ((saction->flag & SACTION_NOREALTIMEUPDATES) == 0) {
+                               for (ale= anim_data.first; ale; ale= ale->next) {
+                                       /* set refresh tags for objects using this animation */
+                                       ANIM_list_elem_update(t->scene, ale);
+                               }
                        }
+                       
+                       /* now free temp channels */
+                       BLI_freelistN(&anim_data);
                }
-               
-               /* now free temp channels */
-               BLI_freelistN(&anim_data);
        }
        else if (t->spacetype == SPACE_IPO) {
                Scene *scene;
@@ -585,7 +594,7 @@ void recalcData(TransInfo *t)
                                                        BKE_nlatrack_add_strip(track, strip);
                                                        
                                                        tdn->nlt= track;
-                                                       tdn->trackIndex += (n + 1); /* + 1, since n==0 would mean that we didn't change track */
+                                                       tdn->trackIndex++;
                                                }
                                                else /* can't move any further */
                                                        break;
@@ -603,7 +612,7 @@ void recalcData(TransInfo *t)
                                                        BKE_nlatrack_add_strip(track, strip);
                                                        
                                                        tdn->nlt= track;
-                                                       tdn->trackIndex -= (n - 1); /* - 1, since n==0 would mean that we didn't change track */
+                                                       tdn->trackIndex--;
                                                }
                                                else /* can't move any further */
                                                        break;
@@ -620,16 +629,11 @@ void recalcData(TransInfo *t)
                        if(sima->flag & SI_LIVE_UNWRAP)
                                ED_uvedit_live_unwrap_re_solve();
                        
-                       DAG_id_flush_update(t->obedit->data, OB_RECALC_DATA);
+                       DAG_id_tag_update(t->obedit->data, 0);
                }
        }
        else if (t->spacetype == SPACE_VIEW3D) {
                
-               /* project */
-               if(t->state != TRANS_CANCEL) {
-                       applyProject(t);
-               }
-               
                if (t->obedit) {
                        if ELEM(t->obedit->type, OB_CURVE, OB_SURF) {
                                Curve *cu= t->obedit->data;
@@ -638,8 +642,11 @@ void recalcData(TransInfo *t)
 
                                if(t->state != TRANS_CANCEL) {
                                        clipMirrorModifier(t, t->obedit);
+                                       applyProject(t);
                                }
-#if 0 //XXX - possibly merged out? check if in trunk - joeedh
+
+                               DAG_id_tag_update(t->obedit->data, 0);  /* sets recalc flags */
+
                                if (t->state == TRANS_CANCEL) {
                                        while(nu) {
                                                calchandlesNurb(nu); /* Cant do testhandlesNurb here, it messes up the h1 and h2 flags */
@@ -653,10 +660,14 @@ void recalcData(TransInfo *t)
                                                nu= nu->next;
                                        }
                                }
-#endif
                        } else if(t->obedit->type==OB_LATTICE) {
                                Lattice *la= t->obedit->data;
-                               DAG_id_flush_update(t->obedit->data, OB_RECALC_DATA);  /* sets recalc flags */
+
+                               if(t->state != TRANS_CANCEL) {
+                                       applyProject(t);
+                               }
+
+                               DAG_id_tag_update(t->obedit->data, 0);  /* sets recalc flags */
        
                                if(la->editlatt->latt->flag & LT_OUTSIDE) outside_lattice(la->editlatt->latt);
                        }
@@ -666,11 +677,12 @@ void recalcData(TransInfo *t)
                                /* mirror modifier clipping? */
                                if(t->state != TRANS_CANCEL) {
                                        clipMirrorModifier(t, t->obedit);
+                                       applyProject(t);
                                }
                                if((t->options & CTX_NO_MIRROR) == 0 && (t->flag & T_MIRROR))
                                        editbmesh_apply_to_mirror(t);
 
-                               DAG_id_flush_update(t->obedit->data, OB_RECALC_DATA);  /* sets recalc flags */
+                               DAG_id_tag_update(t->obedit->data, 0);  /* sets recalc flags */
 
                                EDBM_RecalcNormals(em);
                                BMEdit_RecalcTesselation(em);
@@ -682,6 +694,10 @@ void recalcData(TransInfo *t)
                                TransData *td = t->data;
                                int i;
                                
+                               if(t->state != TRANS_CANCEL) {
+                                       applyProject(t);
+                               }
+
                                /* Ensure all bones are correctly adjusted */
                                for (ebo = edbo->first; ebo; ebo = ebo->next){
                                        
@@ -744,7 +760,7 @@ void recalcData(TransInfo *t)
                                                                mul_m3_v3(t->mat, up_axis);
                                                        }
                                                        
-                                                       ebo->roll = ED_rollBoneToVector(ebo, up_axis);
+                                                       ebo->roll = ED_rollBoneToVector(ebo, up_axis, FALSE);
                                                }
                                        }
                                }
@@ -754,7 +770,12 @@ void recalcData(TransInfo *t)
                                
                        }
                        else
-                               DAG_id_flush_update(t->obedit->data, OB_RECALC_DATA);  /* sets recalc flags */
+                       {
+                               if(t->state != TRANS_CANCEL) {
+                                       applyProject(t);
+                               }
+                               DAG_id_tag_update(t->obedit->data, 0);  /* sets recalc flags */
+                       }
        
                }
                else if( (t->flag & T_POSE) && t->poseobj) {
@@ -764,28 +785,37 @@ void recalcData(TransInfo *t)
                        /* if animtimer is running, and the object already has animation data,
                         * check if the auto-record feature means that we should record 'samples'
                         * (i.e. uneditable animation values)
+                        *
+                        * context is needed for keying set poll() functions.
                         */
                        // TODO: autokeyframe calls need some setting to specify to add samples (FPoints) instead of keyframes?
-                       if ((t->animtimer) && IS_AUTOKEY_ON(t->scene)) {
+                       if ((t->animtimer) && (t->context) && IS_AUTOKEY_ON(t->scene)) {
                                int targetless_ik= (t->flag & T_AUTOIK); // XXX this currently doesn't work, since flags aren't set yet!
                                
                                animrecord_check_state(t->scene, &ob->id, t->animtimer);
-                               autokeyframe_pose_cb_func(NULL, t->scene, (View3D *)t->view, ob, t->mode, targetless_ik);
+                               autokeyframe_pose_cb_func(t->context, t->scene, (View3D *)t->view, ob, t->mode, targetless_ik);
                        }
                        
                        /* old optimize trick... this enforces to bypass the depgraph */
                        if (!(arm->flag & ARM_DELAYDEFORM)) {
-                               DAG_id_flush_update(&ob->id, OB_RECALC_DATA);  /* sets recalc flags */
+                               DAG_id_tag_update(&ob->id, OB_RECALC_DATA);  /* sets recalc flags */
                        }
                        else
-                               where_is_pose(scene, ob);
+                               where_is_pose(t->scene, ob);
                }
-               else if(base && (base->object->mode & OB_MODE_PARTICLE_EDIT) && PE_get_current(scene, base->object)) {
+               else if(base && (base->object->mode & OB_MODE_PARTICLE_EDIT) && PE_get_current(t->scene, base->object)) {
+                       if(t->state != TRANS_CANCEL) {
+                               applyProject(t);
+                       }
                        flushTransParticles(t);
                }
                else {
                        int i;
                        
+                       if(t->state != TRANS_CANCEL) {
+                               applyProject(t);
+                       }
+
                        for (i = 0; i < t->total; i++) {
                                TransData *td = t->data + i;
                                Object *ob = td->ob;
@@ -803,13 +833,13 @@ void recalcData(TransInfo *t)
                                // TODO: autokeyframe calls need some setting to specify to add samples (FPoints) instead of keyframes?
                                if ((t->animtimer) && IS_AUTOKEY_ON(t->scene)) {
                                        animrecord_check_state(t->scene, &ob->id, t->animtimer);
-                                       autokeyframe_ob_cb_func(NULL, t->scene, (View3D *)t->view, ob, t->mode);
+                                       autokeyframe_ob_cb_func(t->context, t->scene, (View3D *)t->view, ob, t->mode);
                                }
                                
                                /* sets recalc flags fully, instead of flushing existing ones 
                                 * otherwise proxies don't function correctly
                                 */
-                               DAG_id_flush_update(&ob->id, OB_RECALC_OB);
+                               DAG_id_tag_update(&ob->id, OB_RECALC_OB);
                        }
                }
                
@@ -821,7 +851,7 @@ void recalcData(TransInfo *t)
 void drawLine(TransInfo *t, float *center, float *dir, char axis, short options)
 {
        float v1[3], v2[3], v3[3];
-       char col[3], col2[3];
+       unsigned char col[3], col2[3];
 
        if (t->spacetype == SPACE_VIEW3D)
        {
@@ -845,7 +875,7 @@ void drawLine(TransInfo *t, float *center, float *dir, char axis, short options)
                        UI_GetThemeColor3ubv(TH_GRID, col);
                }
                UI_make_axis_color(col, col2, axis);
-               glColor3ubv((GLubyte *)col2);
+               glColor3ubv(col2);
 
                setlinestyle(0);
                glBegin(GL_LINE_STRIP);
@@ -937,7 +967,22 @@ int initTransInfo (bContext *C, TransInfo *t, wmOperator *op, wmEvent *event)
                t->options |= CTX_EDGE;
        }
 
-       t->spacetype = sa->spacetype;
+
+       /* Assign the space type, some exceptions for running in different mode */
+       if(sa == NULL) {
+               /* background mode */
+               t->spacetype= SPACE_EMPTY;
+       }
+       else if ((ar == NULL) && (sa->spacetype == SPACE_VIEW3D)) {
+               /* running in the text editor */
+               t->spacetype= SPACE_EMPTY;
+       }
+       else {
+               /* normal operation */
+               t->spacetype= sa->spacetype;
+       }
+
+
        if(t->spacetype == SPACE_VIEW3D)
        {
                View3D *v3d = sa->spacedata.first;
@@ -968,14 +1013,27 @@ int initTransInfo (bContext *C, TransInfo *t, wmOperator *op, wmEvent *event)
                {
                        t->current_orientation = v3d->twmode;
                }
+
+               /* exceptional case */
+               if(t->around==V3D_LOCAL && (t->settings->selectmode & SCE_SELECT_FACE)) {
+                       if(ELEM3(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL)) {
+                               t->options |= CTX_NO_PET;
+                       }
+               }
        }
-       else if(t->spacetype==SPACE_IMAGE || t->spacetype==SPACE_NODE)
+       else if(t->spacetype==SPACE_IMAGE)
        {
                SpaceImage *sima = sa->spacedata.first;
-               // XXX for now, get View2D  from the active region
+               // XXX for now, get View2D from the active region
                t->view = &ar->v2d;
                t->around = sima->around;
        }
+       else if(t->spacetype==SPACE_NODE)
+       {
+               // XXX for now, get View2D from the active region
+               t->view = &ar->v2d;
+               t->around = V3D_CENTER;
+       }
        else if(t->spacetype==SPACE_IPO) 
        {
                SpaceIpo *sipo= sa->spacedata.first;
@@ -1070,8 +1128,9 @@ int initTransInfo (bContext *C, TransInfo *t, wmOperator *op, wmEvent *event)
                
                
                /* TRANSFORM_FIX_ME rna restrictions */
-               if (t->prop_size <= 0)
+               if (t->prop_size <= 0.00001f)
                {
+                       printf("Proportional size (%f) under 0.00001, reseting to 1!\n", t->prop_size);
                        t->prop_size = 1.0f;
                }
                
@@ -1143,6 +1202,13 @@ void postTrans (bContext *C, TransInfo *t)
                if(sima->flag & SI_LIVE_UNWRAP)
                        ED_uvedit_live_unwrap_end(t->state == TRANS_CANCEL);
        }
+       else if(t->spacetype==SPACE_VIEW3D) {
+               View3D *v3d = t->sa->spacedata.first;
+               /* restore manipulator */
+               if (t->flag & T_MODAL) {
+                       v3d->twtype = t->twtype;
+               }
+       }
        
        if (t->mouse.data)
        {
@@ -1186,6 +1252,13 @@ static void restoreElement(TransData *td) {
                if (td->ext->rot) {
                        VECCOPY(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);
+               }
+               /* XXX, drotAngle & drotAxis not used yet */
                if (td->ext->size) {
                        VECCOPY(td->ext->size, td->ext->isize);
                }
@@ -1281,7 +1354,7 @@ void calculateCenterCursor2D(TransInfo *t)
        calculateCenter2D(t);
 }
 
-void calculateCenterCursorGraph2D(TransInfo *t)
+static void calculateCenterCursorGraph2D(TransInfo *t)
 {
        SpaceIpo *sipo= (SpaceIpo *)t->sa->spacedata.first;
        Scene *scene= t->scene;
@@ -1331,7 +1404,7 @@ void calculateCenterBound(TransInfo *t)
                if (i) {
                        if (t->data[i].flag & TD_SELECTED) {
                                if (!(t->data[i].flag & TD_NOCENTER))
-                                       minmax_v3_v3v3(min, max, t->data[i].center);
+                                       minmax_v3v3_v3(min, max, t->data[i].center);
                        }
                        else {
                                /*
@@ -1572,25 +1645,3 @@ void calculatePropRatio(TransInfo *t)
                strcpy(t->proptext, "");
        }
 }
-
-float get_drawsize(ARegion *ar, float *co)
-{
-       RegionView3D *rv3d= ar->regiondata;
-       float size, vec[3], len1, len2;
-
-       /* size calculus, depending ortho/persp settings, like initgrabz() */
-       size= rv3d->persmat[0][3]*co[0]+ rv3d->persmat[1][3]*co[1]+ rv3d->persmat[2][3]*co[2]+ rv3d->persmat[3][3];
-
-       VECCOPY(vec, rv3d->persinv[0]);
-       len1= normalize_v3(vec);
-       VECCOPY(vec, rv3d->persinv[1]);
-       len2= normalize_v3(vec);
-
-       size*= 0.01f*(len1>len2?len1:len2);
-
-       /* correct for window size to make widgets appear fixed size */
-       if(ar->winx > ar->winy) size*= 1000.0f/(float)ar->winx;
-       else size*= 1000.0f/(float)ar->winy;
-
-       return size;
-}