=bmesh= merge from trunk at r36529
[blender.git] / source / blender / editors / transform / transform_generics.c
index 98ecb07660f91ed6fdd7f0bf69b13cd59ed97007..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>
 
 #include "DNA_lattice_types.h"
 #include "DNA_screen_types.h"
 #include "DNA_space_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_object_types.h"
+#include "DNA_meshdata_types.h"
 #include "DNA_view3d_types.h"
+#include "DNA_modifier_types.h"
 
 #include "RNA_access.h"
 
 
 #include "BKE_animsys.h"
 #include "BKE_action.h"
-#include "BKE_anim.h"
 #include "BKE_armature.h"
-#include "BKE_cloth.h"
 #include "BKE_curve.h"
 #include "BKE_depsgraph.h"
 #include "BKE_displist.h"
-#include "BKE_depsgraph.h"
 #include "BKE_fcurve.h"
-#include "BKE_global.h"
-#include "BKE_group.h"
 #include "BKE_lattice.h"
-#include "BKE_key.h"
 #include "BKE_mesh.h"
-#include "BKE_modifier.h"
 #include "BKE_nla.h"
-#include "BKE_object.h"
-#include "BKE_utildefines.h"
 #include "BKE_context.h"
+#include "BKE_tessmesh.h"
 
 #include "ED_anim_api.h"
 #include "ED_armature.h"
@@ -84,6 +85,7 @@
 #include "ED_space_api.h"
 #include "ED_uvedit.h"
 #include "ED_view3d.h"
+#include "ED_curve.h" /* for ED_curve_editnurbs */
 
 //#include "BDR_unwrapper.h"
 
@@ -91,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"
@@ -113,19 +115,19 @@ void getViewVector(TransInfo *t, float coord[3], float vec[3])
        if (t->persp != RV3D_ORTHO)
        {
                float p1[4], p2[4];
-               
+
                VECCOPY(p1, coord);
                p1[3] = 1.0f;
                VECCOPY(p2, p1);
                p2[3] = 1.0f;
                mul_m4_v4(t->viewmat, p2);
-               
+
                p2[0] = 2.0f * p2[0];
                p2[1] = 2.0f * p2[1];
                p2[2] = 2.0f * p2[2];
-               
+
                mul_m4_v4(t->viewinv, p2);
-               
+
                sub_v3_v3v3(vec, p1, p2);
        }
        else {
@@ -141,11 +143,11 @@ static void clipMirrorModifier(TransInfo *t, Object *ob)
        ModifierData *md= ob->modifiers.first;
        float tolerance[3] = {0.0f, 0.0f, 0.0f};
        int axis = 0;
-       
+
        for (; md; md=md->next) {
                if (md->type==eModifierType_Mirror) {
                        MirrorModifierData *mmd = (MirrorModifierData*) md;
-                       
+
                        if(mmd->flag & MOD_MIR_CLIPPING) {
                                axis = 0;
                                if(mmd->flag & MOD_MIR_AXIS_X) {
@@ -164,35 +166,35 @@ static void clipMirrorModifier(TransInfo *t, Object *ob)
                                        float mtx[4][4], imtx[4][4];
                                        int i;
                                        TransData *td = t->data;
-                                       
+
                                        if (mmd->mirror_ob) {
                                                float obinv[4][4];
-                                               
+
                                                invert_m4_m4(obinv, mmd->mirror_ob->obmat);
                                                mul_m4_m4m4(mtx, ob->obmat, obinv);
                                                invert_m4_m4(imtx, mtx);
                                        }
-                                       
+
                                        for(i = 0 ; i < t->total; i++, td++) {
                                                int clip;
                                                float loc[3], iloc[3];
-                                               
+
                                                if (td->flag & TD_NOACTION)
                                                        break;
                                                if (td->loc==NULL)
                                                        break;
-                                               
+
                                                if (td->flag & TD_SKIP)
                                                        continue;
-                                               
+
                                                copy_v3_v3(loc,  td->loc);
                                                copy_v3_v3(iloc, td->iloc);
-                                               
+
                                                if (mmd->mirror_ob) {
                                                        mul_m4_v3(mtx, loc);
                                                        mul_m4_v3(mtx, iloc);
                                                }
-                                               
+
                                                clip = 0;
                                                if(axis & 1) {
                                                        if(fabs(iloc[0])<=tolerance[0] ||
@@ -201,7 +203,7 @@ static void clipMirrorModifier(TransInfo *t, Object *ob)
                                                                clip = 1;
                                                        }
                                                }
-                                               
+
                                                if(axis & 2) {
                                                        if(fabs(iloc[1])<=tolerance[1] ||
                                                           loc[1]*iloc[1]<0.0f) {
@@ -224,19 +226,19 @@ static void clipMirrorModifier(TransInfo *t, Object *ob)
                                                }
                                        }
                                }
-                               
+
                        }
                }
        }
 }
 
 /* assumes obedit set to mesh object */
-static void editmesh_apply_to_mirror(TransInfo *t)
+static void editbmesh_apply_to_mirror(TransInfo *t)
 {
        TransData *td = t->data;
-       EditVert *eve;
+       BMVert *eve;
        int i;
-       
+
        for(i = 0 ; i < t->total; i++, td++) {
                if (td->flag & TD_NOACTION)
                        break;
@@ -244,7 +246,7 @@ static void editmesh_apply_to_mirror(TransInfo *t)
                        break;
                if (td->flag & TD_SKIP)
                        continue;
-               
+
                eve = td->extra;
                if (eve) {
                        eve->co[0]= -td->loc[0];
@@ -273,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);
@@ -310,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;
@@ -325,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);
@@ -338,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;
@@ -356,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;
@@ -588,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;
@@ -606,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;
@@ -623,27 +629,24 @@ 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;
-                               Nurb *nu= cu->editnurb->first;
+                               ListBase *nurbs= ED_curve_editnurbs(cu);
+                               Nurb *nu= nurbs->first;
 
                                if(t->state != TRANS_CANCEL) {
                                        clipMirrorModifier(t, t->obedit);
+                                       applyProject(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 */
+
                                if (t->state == TRANS_CANCEL) {
                                        while(nu) {
                                                calchandlesNurb(nu); /* Cant do testhandlesNurb here, it messes up the h1 and h2 flags */
@@ -657,25 +660,32 @@ void recalcData(TransInfo *t)
                                                nu= nu->next;
                                        }
                                }
-                       }
-                       else if(t->obedit->type==OB_LATTICE) {
+                       } 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->flag & LT_OUTSIDE) outside_lattice(la->editlatt);
+                               if(la->editlatt->latt->flag & LT_OUTSIDE) outside_lattice(la->editlatt->latt);
                        }
                        else if (t->obedit->type == OB_MESH) {
-                               EditMesh *em = ((Mesh*)t->obedit->data)->edit_mesh;
+                               BMEditMesh *em = ((Mesh*)t->obedit->data)->edit_btmesh;
+
                                /* 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))
-                                       editmesh_apply_to_mirror(t);
-                                       
-                               DAG_id_flush_update(t->obedit->data, OB_RECALC_DATA);  /* sets recalc flags */
-                               
-                               recalc_editnormals(em);
+                                       editbmesh_apply_to_mirror(t);
+
+                               DAG_id_tag_update(t->obedit->data, 0);  /* sets recalc flags */
+
+                               EDBM_RecalcNormals(em);
+                               BMEdit_RecalcTesselation(em);
                        }
                        else if(t->obedit->type==OB_ARMATURE) { /* no recalc flag, does pose */
                                bArmature *arm= t->obedit->data;
@@ -684,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){
                                        
@@ -746,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);
                                                }
                                        }
                                }
@@ -756,7 +770,13 @@ 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) {
                        Object *ob= t->poseobj;
@@ -765,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;
@@ -804,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);
                        }
                }
                
@@ -822,23 +851,23 @@ 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)
        {
                View3D *v3d = t->view;
-               
+
                glPushMatrix();
-               
+
                //if(t->obedit) glLoadMatrixf(t->obedit->obmat);        // sets opengl viewing
-               
-               
+
+
                copy_v3_v3(v3, dir);
                mul_v3_fl(v3, v3d->far);
-               
+
                sub_v3_v3v3(v2, center, v3);
                add_v3_v3v3(v1, center, v3);
-               
+
                if (options & DRAWLIGHT) {
                        col[0] = col[1] = col[2] = 220;
                }
@@ -846,14 +875,14 @@ 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);
                        glVertex3fv(v1);
                        glVertex3fv(v2);
                glEnd();
-               
+
                glPopMatrix();
        }
 }
@@ -870,33 +899,33 @@ int initTransInfo (bContext *C, TransInfo *t, wmOperator *op, wmEvent *event)
        ARegion *ar = CTX_wm_region(C);
        ScrArea *sa = CTX_wm_area(C);
        Object *obedit = CTX_data_edit_object(C);
-       
+
        /* moving: is shown in drawobject() (transform color) */
 //  TRANSFORM_FIX_ME
 //     if(obedit || (t->flag & T_POSE) ) G.moving= G_TRANSFORM_EDIT;
 //     else if(G.f & G_PARTICLEEDIT) G.moving= G_TRANSFORM_PARTICLE;
 //     else G.moving= G_TRANSFORM_OBJ;
-       
+
        t->scene = sce;
        t->sa = sa;
        t->ar = ar;
        t->obedit = obedit;
        t->settings = ts;
-       
+
        t->data = NULL;
        t->ext = NULL;
-       
+
        t->helpline = HLP_NONE;
-       
+
        t->flag = 0;
-       
+
        t->redraw = 1; /* redraw first time */
-       
+
        if (event)
        {
                t->imval[0] = event->x - t->ar->winrct.xmin;
                t->imval[1] = event->y - t->ar->winrct.ymin;
-               
+
                t->event_type = event->type;
        }
        else
@@ -904,30 +933,30 @@ int initTransInfo (bContext *C, TransInfo *t, wmOperator *op, wmEvent *event)
                t->imval[0] = 0;
                t->imval[1] = 0;
        }
-       
+
        t->con.imval[0] = t->imval[0];
        t->con.imval[1] = t->imval[1];
-       
+
        t->mval[0] = t->imval[0];
        t->mval[1] = t->imval[1];
-       
+
        t->transform            = NULL;
        t->handleEvent          = NULL;
-       
+
        t->total                        = 0;
-       
+
        t->val = 0.0f;
-       
+
        t->vec[0]                       =
                t->vec[1]               =
                t->vec[2]               = 0.0f;
-       
+
        t->center[0]            =
                t->center[1]    =
                t->center[2]    = 0.0f;
-       
+
        unit_m3(t->mat);
-       
+
        /* if there's an event, we're modal */
        if (event) {
                t->flag |= T_MODAL;
@@ -938,14 +967,29 @@ 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;
-               
+
                t->view = v3d;
                t->animtimer= CTX_wm_screen(C)->animtimer;
-               
+
                /* turn manipulator off during transform */
                // FIXME: but don't do this when USING the manipulator...
                if (t->flag & T_MODAL) {
@@ -955,11 +999,11 @@ int initTransInfo (bContext *C, TransInfo *t, wmOperator *op, wmEvent *event)
 
                if(v3d->flag & V3D_ALIGN) t->flag |= T_V3D_ALIGN;
                t->around = v3d->around;
-               
+
                if (op && RNA_struct_find_property(op->ptr, "constraint_orientation") && RNA_property_is_set(op->ptr, "constraint_orientation"))
                {
                        t->current_orientation = RNA_enum_get(op->ptr, "constraint_orientation");
-                       
+
                        if (t->current_orientation >= V3D_MANIP_CUSTOM + BIF_countTransformOrientation(C))
                        {
                                t->current_orientation = V3D_MANIP_GLOBAL;
@@ -969,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;
@@ -987,10 +1044,11 @@ int initTransInfo (bContext *C, TransInfo *t, wmOperator *op, wmEvent *event)
        {
                // XXX for now, get View2D  from the active region
                t->view = &ar->v2d;
+
                // XXX for now, the center point is the midpoint of the data
                t->around = V3D_CENTER;
        }
-       
+
        if (op && RNA_property_is_set(op->ptr, "release_confirm"))
        {
                if (RNA_boolean_get(op->ptr, "release_confirm"))
@@ -1023,17 +1081,16 @@ int initTransInfo (bContext *C, TransInfo *t, wmOperator *op, wmEvent *event)
                        t->mirror = 1;
                }
        }
-       
-       /* setting PET flag only if property exist in operator. Otherwise, assume it's not supported */
+
        if (op && RNA_struct_find_property(op->ptr, "proportional"))
        {
                if (RNA_property_is_set(op->ptr, "proportional"))
                {
                        switch(RNA_enum_get(op->ptr, "proportional"))
                        {
-                       case 2: /* XXX connected constant */
+                       case PROP_EDIT_CONNECTED:
                                t->flag |= T_PROP_CONNECTED;
-                       case 1: /* XXX prop on constant */
+                       case PROP_EDIT_ON:
                                t->flag |= T_PROP_EDIT;
                                break;
                        }
@@ -1043,11 +1100,19 @@ int initTransInfo (bContext *C, TransInfo *t, wmOperator *op, wmEvent *event)
                        /* use settings from scene only if modal */
                        if (t->flag & T_MODAL)
                        {
-                               if ((t->options & CTX_NO_PET) == 0 && (ts->proportional != PROP_EDIT_OFF)) {
-                                       t->flag |= T_PROP_EDIT;
+                               if ((t->options & CTX_NO_PET) == 0)
+                               {
+                                       if (t->obedit && ts->proportional != PROP_EDIT_OFF)
+                                       {
+                                               t->flag |= T_PROP_EDIT;
 
-                                       if(ts->proportional == PROP_EDIT_CONNECTED)
-                                               t->flag |= T_PROP_CONNECTED;
+                                               if(ts->proportional == PROP_EDIT_CONNECTED)
+                                                       t->flag |= T_PROP_CONNECTED;
+                                       }
+                                       else if (t->obedit == NULL && ts->proportional_objects)
+                                       {
+                                               t->flag |= T_PROP_EDIT;
+                                       }
                                }
                        }
                }
@@ -1063,14 +1128,15 @@ 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;
                }
                
-               if (op && RNA_struct_find_property(op->ptr, "proportional_editing_falloff") && RNA_property_is_set(op->ptr, "proportional_editing_falloff"))
+               if (op && RNA_struct_find_property(op->ptr, "proportional_edit_falloff") && RNA_property_is_set(op->ptr, "proportional_edit_falloff"))
                {
-                       t->prop_mode = RNA_enum_get(op->ptr, "proportional_editing_falloff");
+                       t->prop_mode = RNA_enum_get(op->ptr, "proportional_edit_falloff");
                }
                else
                {
@@ -1085,7 +1151,7 @@ int initTransInfo (bContext *C, TransInfo *t, wmOperator *op, wmEvent *event)
        setTransformViewMatrices(t);
        initNumInput(&t->num);
        initNDofInput(&t->ndof);
-       
+
        return 1;
 }
 
@@ -1093,7 +1159,7 @@ int initTransInfo (bContext *C, TransInfo *t, wmOperator *op, wmEvent *event)
 void postTrans (bContext *C, TransInfo *t)
 {
        TransData *td;
-       
+
        if (t->draw_handle_view)
                ED_region_draw_cb_exit(t->ar->type, t->draw_handle_view);
        if (t->draw_handle_apply)
@@ -1114,7 +1180,7 @@ void postTrans (bContext *C, TransInfo *t)
        /* postTrans can be called when nothing is selected, so data is NULL already */
        if (t->data) {
                int a;
-               
+
                /* free data malloced per trans-data */
                for(a=0, td= t->data; a<t->total; a++, td++) {
                        if (td->flag & TD_BEZTRIPLE) 
@@ -1122,7 +1188,7 @@ void postTrans (bContext *C, TransInfo *t)
                }
                MEM_freeN(t->data);
        }
-       
+
        BLI_freelistN(&t->tsnap.points);
 
        if (t->ext) MEM_freeN(t->ext);
@@ -1130,23 +1196,37 @@ void postTrans (bContext *C, TransInfo *t)
                MEM_freeN(t->data2d);
                t->data2d= NULL;
        }
-       
+
        if(t->spacetype==SPACE_IMAGE) {
                SpaceImage *sima= t->sa->spacedata.first;
                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)
        {
                MEM_freeN(t->mouse.data);
        }
+
+       if (t->customFree) {
+               t->customFree(t);
+       }
+       else if (t->customData) {
+               MEM_freeN(t->customData);
+       }
 }
 
 void applyTransObjects(TransInfo *t)
 {
        TransData *td;
-       
+
        for (td = t->data; td < t->data + t->total; td++) {
                VECCOPY(td->iloc, td->loc);
                if (td->ext->rot) {
@@ -1172,19 +1252,26 @@ 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);
                }
-               if (td->ext->quat) {
-                       QUATCOPY(td->ext->quat, td->ext->iquat);
+                       if (td->ext->quat) {
+                               QUATCOPY(td->ext->quat, td->ext->iquat);
+                       }
                }
-       }
-       
+
        if (td->flag & TD_BEZTRIPLE) {
                *(td->hdata->h1) = td->hdata->ih1;
                *(td->hdata->h2) = td->hdata->ih2;
        }
-}
+       }
 
 void restoreTransObjects(TransInfo *t)
 {
@@ -1194,7 +1281,7 @@ void restoreTransObjects(TransInfo *t)
        for (td = t->data; td < t->data + t->total; td++) {
                restoreElement(td);
        }
-       
+
        for (td2d=t->data2d; t->data2d && td2d < t->data2d + t->total; td2d++) {
                if (td2d->h1) {
                        td2d->h1[0] = td2d->ih1[0];
@@ -1207,7 +1294,7 @@ void restoreTransObjects(TransInfo *t)
        }
 
        unit_m3(t->mat);
-       
+
        recalcData(t);
 }
 
@@ -1216,7 +1303,7 @@ void calculateCenter2D(TransInfo *t)
        if (t->flag & (T_EDIT|T_POSE)) {
                Object *ob= t->obedit?t->obedit:t->poseobj;
                float vec[3];
-               
+
                VECCOPY(vec, t->center);
                mul_m4_v3(ob->obmat, vec);
                projectIntView(t, vec, t->center2d);
@@ -1229,21 +1316,21 @@ void calculateCenter2D(TransInfo *t)
 void calculateCenterCursor(TransInfo *t)
 {
        float *cursor;
-       
+
        cursor = give_cursor(t->scene, t->view);
        VECCOPY(t->center, cursor);
-       
+
        /* If edit or pose mode, move cursor in local space */
        if (t->flag & (T_EDIT|T_POSE)) {
                Object *ob = t->obedit?t->obedit:t->poseobj;
                float mat[3][3], imat[3][3];
-               
+
                sub_v3_v3v3(t->center, t->center, ob->obmat[3]);
                copy_m3_m4(mat, ob->obmat);
                invert_m3_m3(imat, mat);
                mul_m3_v3(imat, t->center);
        }
-       
+
        calculateCenter2D(t);
 }
 
@@ -1258,16 +1345,16 @@ void calculateCenterCursor2D(TransInfo *t)
                ED_space_image_uv_aspect(sima, &aspx, &aspy);
                cursor = sima->cursor;
        }
-       
+
        if (cursor) {
                t->center[0] = cursor[0] * aspx;
                t->center[1] = cursor[1] * aspy;
        }
-       
+
        calculateCenter2D(t);
 }
 
-void calculateCenterCursorGraph2D(TransInfo *t)
+static void calculateCenterCursorGraph2D(TransInfo *t)
 {
        SpaceIpo *sipo= (SpaceIpo *)t->sa->spacedata.first;
        Scene *scene= t->scene;
@@ -1284,7 +1371,7 @@ void calculateCenterMedian(TransInfo *t)
        float partial[3] = {0.0f, 0.0f, 0.0f};
        int total = 0;
        int i;
-       
+
        for(i = 0; i < t->total; i++) {
                if (t->data[i].flag & TD_SELECTED) {
                        if (!(t->data[i].flag & TD_NOCENTER))
@@ -1304,7 +1391,7 @@ void calculateCenterMedian(TransInfo *t)
        if(i)
                mul_v3_fl(partial, 1.0f / total);
        VECCOPY(t->center, partial);
-       
+
        calculateCenter2D(t);
 }
 
@@ -1317,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 {
                                /*
@@ -1334,7 +1421,7 @@ void calculateCenterBound(TransInfo *t)
        }
        add_v3_v3v3(t->center, min, max);
        mul_v3_fl(t->center, 0.5);
-       
+
        calculateCenter2D(t);
 }
 
@@ -1366,16 +1453,16 @@ void calculateCenter(TransInfo *t)
                /* EDIT MODE ACTIVE EDITMODE ELEMENT */
 
                if (t->obedit && t->obedit->type == OB_MESH) {
-                       EditSelection ese;
-                       EditMesh *em = BKE_mesh_get_editmesh(t->obedit->data);
+                       BMEditSelection ese;
+                       BMEditMesh *em = ((Mesh*)t->obedit->data)->edit_btmesh;
                        
-                       if (EM_get_actSelection(em, &ese)) {
-                               EM_editselection_center(t->center, &ese);
-                               calculateCenter2D(t);
-                               break;
+                       if (EDBM_get_actSelection(em, &ese)) {
+                       EDBM_editselection_center(em, t->center, &ese);
+                       calculateCenter2D(t);
+                       break;
                        }
                } /* END EDIT MODE ACTIVE ELEMENT */
-               
+
                calculateCenterMedian(t);
                if((t->flag & (T_EDIT|T_POSE))==0)
                {
@@ -1387,10 +1474,10 @@ void calculateCenter(TransInfo *t)
                                projectIntView(t, t->center, t->center2d);
                        }
                }
-               
+
                }
        }
-       
+
        /* setting constraint center */
        VECCOPY(t->con.center, t->center);
        if(t->flag & (T_EDIT|T_POSE))
@@ -1398,7 +1485,7 @@ void calculateCenter(TransInfo *t)
                Object *ob= t->obedit?t->obedit:t->poseobj;
                mul_m4_v3(ob->obmat, t->con.center);
        }
-       
+
        /* for panning from cameraview */
        if(t->flag & T_OBJECT)
        {
@@ -1407,21 +1494,21 @@ void calculateCenter(TransInfo *t)
                        View3D *v3d = t->view;
                        Scene *scene = t->scene;
                        RegionView3D *rv3d = t->ar->regiondata;
-                       
+
                        if(v3d->camera == OBACT && rv3d->persp==RV3D_CAMOB)
                        {
                                float axis[3];
                                /* persinv is nasty, use viewinv instead, always right */
                                VECCOPY(axis, t->viewinv[2]);
                                normalize_v3(axis);
-                               
+
                                /* 6.0 = 6 grid units */
                                axis[0]= t->center[0]- 6.0f*axis[0];
                                axis[1]= t->center[1]- 6.0f*axis[1];
                                axis[2]= t->center[2]- 6.0f*axis[2];
-                               
+
                                projectIntView(t, axis, t->center2d);
-                               
+
                                /* rotate only needs correct 2d center, grab needs initgrabz() value */
                                if(t->mode==TFM_TRANSLATION)
                                {
@@ -1431,14 +1518,14 @@ void calculateCenter(TransInfo *t)
                        }
                }
        }
-       
+
        if(t->spacetype==SPACE_VIEW3D)
        {
                /* initgrabz() defines a factor for perspective depth correction, used in window_to_3d_delta() */
                if(t->flag & (T_EDIT|T_POSE)) {
                        Object *ob= t->obedit?t->obedit:t->poseobj;
                        float vec[3];
-                       
+
                        VECCOPY(vec, t->center);
                        mul_m4_v3(ob->obmat, vec);
                        initgrabz(t->ar->regiondata, vec[0], vec[1], vec[2]);
@@ -1483,7 +1570,7 @@ void calculatePropRatio(TransInfo *t)
                        else {
                                /* Use rdist for falloff calculations, it is the real distance */
                                td->flag &= ~TD_NOACTION;
-                               
+
                                if (connected)
                                        dist= (t->prop_size-td->dist)/t->prop_size;
                                else
@@ -1496,7 +1583,7 @@ void calculatePropRatio(TransInfo *t)
                                 */
                                if (dist < 0.0f)
                                        dist = 0.0f;
-                               
+
                                switch(t->prop_mode) {
                                case PROP_SHARP:
                                        td->factor= dist*dist;
@@ -1558,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;
-}