doxygen: prevent GPL license block from being parsed as doxygen comment.
[blender.git] / source / blender / editors / space_view3d / view3d_buttons.c
index ec72d72..0e4e1ad 100644 (file)
@@ -1,5 +1,5 @@
-/**
- * $Id:
+/*
+ * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
@@ -15,7 +15,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  * The Original Code is Copyright (C) 2009 Blender Foundation.
  * All rights reserved.
 #include <math.h>
 #include <float.h>
 
-#include "DNA_ID.h"
-#include "DNA_action_types.h"
 #include "DNA_armature_types.h"
 #include "DNA_curve_types.h"
-#include "DNA_camera_types.h"
-#include "DNA_gpencil_types.h"
-#include "DNA_lamp_types.h"
 #include "DNA_lattice_types.h"
 #include "DNA_meta_types.h"
-#include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
 #include "DNA_object_types.h"
-#include "DNA_space_types.h"
 #include "DNA_scene_types.h"
-#include "DNA_screen_types.h"
-#include "DNA_userdef_types.h"
-#include "DNA_view3d_types.h"
-#include "DNA_world_types.h"
 
 #include "MEM_guardedalloc.h"
 
-#include "BLI_arithb.h"
+#include "BLI_math.h"
 #include "BLI_blenlib.h"
 #include "BLI_editVert.h"
 #include "BLI_rand.h"
+#include "BLI_utildefines.h"
 
 #include "BKE_action.h"
-#include "BKE_brush.h"
 #include "BKE_context.h"
 #include "BKE_curve.h"
 #include "BKE_customdata.h"
 #include "BKE_depsgraph.h"
-#include "BKE_idprop.h"
+#include "BKE_main.h"
 #include "BKE_mesh.h"
-#include "BKE_object.h"
-#include "BKE_global.h"
-#include "BKE_scene.h"
 #include "BKE_screen.h"
-#include "BKE_utildefines.h"
-
-#include "BIF_gl.h"
+#include "BKE_deform.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
 
 #include "RNA_access.h"
-#include "RNA_define.h"
 
 #include "ED_armature.h"
-#include "ED_curve.h"
-#include "ED_image.h"
 #include "ED_gpencil.h"
-#include "ED_keyframing.h"
 #include "ED_mesh.h"
-#include "ED_object.h"
-#include "ED_particle.h"
 #include "ED_screen.h"
 #include "ED_transform.h"
-#include "ED_types.h"
-#include "ED_util.h"
+#include "ED_curve.h"
 
 #include "UI_interface.h"
 #include "UI_resources.h"
-#include "UI_view2d.h"
 
 #include "view3d_intern.h"     // own include
 
@@ -145,23 +121,24 @@ typedef struct {
        float ob_scale[3]; // need temp space due to linked values
        float ob_dims[3];
        short link_scale;
-       float ve_median[5];
+       float ve_median[6];
        int curdef;
        float *defweightp;
 } TransformProperties;
 
 
 /* is used for both read and write... */
-static void v3d_editvertex_buts(const bContext *C, uiBlock *block, View3D *v3d, Object *ob, float lim)
+static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float lim)
 {
+       uiBlock *block= (layout)? uiLayoutAbsoluteBlock(layout): NULL;
        MDeformVert *dvert=NULL;
        TransformProperties *tfp= v3d->properties_storage;
-       float median[5], ve_median[5];
-       int tot, totw, totweight, totedge;
+       float median[6], ve_median[6];
+       int tot, totw, totweight, totedge, totradius;
        char defstr[320];
        
-       median[0]= median[1]= median[2]= median[3]= median[4]= 0.0;
-       tot= totw= totweight= totedge= 0;
+       median[0]= median[1]= median[2]= median[3]= median[4]= median[5]= 0.0;
+       tot= totw= totweight= totedge= totradius= 0;
        defstr[0]= 0;
 
        if(ob->type==OB_MESH) {
@@ -175,7 +152,7 @@ static void v3d_editvertex_buts(const bContext *C, uiBlock *block, View3D *v3d,
                        if(eve->f & SELECT) {
                                evedef= eve;
                                tot++;
-                               VecAddf(median, median, eve->co);
+                               add_v3_v3(median, eve->co);
                        }
                        eve= eve->next;
                }
@@ -202,7 +179,7 @@ static void v3d_editvertex_buts(const bContext *C, uiBlock *block, View3D *v3d,
                                        max+= BLI_snprintf(str, sizeof(str), "%s %%x%d|", dg->name, dvert->dw[i].def_nr); 
                                        if(max<320) strcat(defstr, str);
                                }
-                               else printf("oh no!\n");
+
                                if(tfp->curdef==dvert->dw[i].def_nr) {
                                        init= 0;
                                        tfp->defweightp= &dvert->dw[i].weight;
@@ -223,26 +200,29 @@ static void v3d_editvertex_buts(const bContext *C, uiBlock *block, View3D *v3d,
                BPoint *bp;
                BezTriple *bezt;
                int a;
-               
-               nu= cu->editnurb->first;
+               ListBase *nurbs= ED_curve_editnurbs(cu);
+
+               nu= nurbs->first;
                while(nu) {
                        if(nu->type == CU_BEZIER) {
                                bezt= nu->bezt;
                                a= nu->pntsu;
                                while(a--) {
                                        if(bezt->f2 & SELECT) {
-                                               VecAddf(median, median, bezt->vec[1]);
+                                               add_v3_v3(median, bezt->vec[1]);
                                                tot++;
                                                median[4]+= bezt->weight;
                                                totweight++;
+                                               median[5]+= bezt->radius;
+                                               totradius++;
                                        }
                                        else {
                                                if(bezt->f1 & SELECT) {
-                                                       VecAddf(median, median, bezt->vec[0]);
+                                                       add_v3_v3(median, bezt->vec[0]);
                                                        tot++;
                                                }
                                                if(bezt->f3 & SELECT) {
-                                                       VecAddf(median, median, bezt->vec[2]);
+                                                       add_v3_v3(median, bezt->vec[2]);
                                                        tot++;
                                                }
                                        }
@@ -254,12 +234,14 @@ static void v3d_editvertex_buts(const bContext *C, uiBlock *block, View3D *v3d,
                                a= nu->pntsu*nu->pntsv;
                                while(a--) {
                                        if(bp->f1 & SELECT) {
-                                               VecAddf(median, median, bp->vec);
+                                               add_v3_v3(median, bp->vec);
                                                median[3]+= bp->vec[3];
                                                totw++;
                                                tot++;
                                                median[4]+= bp->weight;
                                                totweight++;
+                                               median[5]+= bp->radius;
+                                               totradius++;
                                        }
                                        bp++;
                                }
@@ -272,11 +254,11 @@ static void v3d_editvertex_buts(const bContext *C, uiBlock *block, View3D *v3d,
                BPoint *bp;
                int a;
                
-               a= lt->editlatt->pntsu*lt->editlatt->pntsv*lt->editlatt->pntsw;
-               bp= lt->editlatt->def;
+               a= lt->editlatt->latt->pntsu*lt->editlatt->latt->pntsv*lt->editlatt->latt->pntsw;
+               bp= lt->editlatt->latt->def;
                while(a--) {
                        if(bp->f1 & SELECT) {
-                               VecAddf(median, median, bp->vec);
+                               add_v3_v3(median, bp->vec);
                                tot++;
                                median[4]+= bp->weight;
                                totweight++;
@@ -293,35 +275,38 @@ static void v3d_editvertex_buts(const bContext *C, uiBlock *block, View3D *v3d,
        if(totedge) median[3] /= (float)totedge;
        else if(totw) median[3] /= (float)totw;
        if(totweight) median[4] /= (float)totweight;
+       if(totradius) median[5] /= (float)totradius;
        
        if(v3d->flag & V3D_GLOBAL_STATS)
-               Mat4MulVecfl(ob->obmat, median);
+               mul_m4_v3(ob->obmat, median);
        
        if(block) {     // buttons
-               int but_y;
-               if((ob->parent) && (ob->partype == PARBONE))    but_y = 135;
-               else                                                                                    but_y = 150;
-               
-               
-               
+               uiBut *but;
+
                memcpy(tfp->ve_median, median, sizeof(tfp->ve_median));
                
                uiBlockBeginAlign(block);
                if(tot==1) {
                        uiDefBut(block, LABEL, 0, "Vertex:",                                    0, 130, 200, 20, 0, 0, 0, 0, 0, "");
                        uiBlockBeginAlign(block);
-                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "X:",                0, 110, 200, 20, &(tfp->ve_median[0]), -lim, lim, 10, 3, "");
-                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Y:",                0, 90, 200, 20, &(tfp->ve_median[1]), -lim, lim, 10, 3, "");
-                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Z:",                0, 70, 200, 20, &(tfp->ve_median[2]), -lim, lim, 10, 3, "");
-                       
+
+                       but= uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "X:",           0, 110, 200, 20, &(tfp->ve_median[0]), -lim, lim, 10, 3, "");
+                       uiButSetUnitType(but, PROP_UNIT_LENGTH);
+                       but= uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Y:",           0, 90, 200, 20, &(tfp->ve_median[1]), -lim, lim, 10, 3, "");
+                       uiButSetUnitType(but, PROP_UNIT_LENGTH);
+                       but= uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Z:",           0, 70, 200, 20, &(tfp->ve_median[2]), -lim, lim, 10, 3, "");
+                       uiButSetUnitType(but, PROP_UNIT_LENGTH);
+
                        if(totw==1) {
-                               uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "W:",        0, 50, 200, 20, &(tfp->ve_median[3]), 0.01, 100.0, 10, 3, "");
+                               uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "W:",        0, 50, 200, 20, &(tfp->ve_median[3]), 0.01, 100.0, 1, 3, "");
                                uiBlockBeginAlign(block);
                                uiDefButBitS(block, TOG, V3D_GLOBAL_STATS, B_REDR, "Global",            0, 25, 100, 20, &v3d->flag, 0, 0, 0, 0, "Displays global values");
                                uiDefButBitS(block, TOGN, V3D_GLOBAL_STATS, B_REDR, "Local",            100, 25, 100, 20, &v3d->flag, 0, 0, 0, 0, "Displays local values");
                                uiBlockEndAlign(block);
                                if(totweight)
-                                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Weight:",   0, 0, 200, 20, &(tfp->ve_median[4]), 0.0, 1.0, 10, 3, "");
+                                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Weight:",   0, 0, 200, 20, &(tfp->ve_median[4]), 0.0, 1.0, 1, 3, "");
+                               if(totradius)
+                                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Radius:",   0, 0, 200, 20, &(tfp->ve_median[5]), 0.0, 100.0, 1, 3, "Radius of curve CPs");
                                }
                        else {
                                uiBlockBeginAlign(block);
@@ -330,16 +315,21 @@ static void v3d_editvertex_buts(const bContext *C, uiBlock *block, View3D *v3d,
                                uiBlockEndAlign(block);
                                if(totweight)
                                        uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Weight:",   0, 20, 200, 20, &(tfp->ve_median[4]), 0.0, 1.0, 10, 3, "");
+                               if(totradius)
+                                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Radius:",   0, 20, 200, 20, &(tfp->ve_median[5]), 0.0, 100.0, 10, 3, "Radius of curve CPs");
                        }
                }
                else {
                        uiDefBut(block, LABEL, 0, "Median:",                                    0, 130, 200, 20, 0, 0, 0, 0, 0, "");
                        uiBlockBeginAlign(block);
-                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "X:",                0, 110, 200, 20, &(tfp->ve_median[0]), -lim, lim, 10, 3, "");
-                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Y:",                0, 90, 200, 20, &(tfp->ve_median[1]), -lim, lim, 10, 3, "");
-                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Z:",                0, 70, 200, 20, &(tfp->ve_median[2]), -lim, lim, 10, 3, "");
+                       but= uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "X:",           0, 110, 200, 20, &(tfp->ve_median[0]), -lim, lim, 10, 3, "");
+                       uiButSetUnitType(but, PROP_UNIT_LENGTH);
+                       but= uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Y:",           0, 90, 200, 20, &(tfp->ve_median[1]), -lim, lim, 10, 3, "");
+                       uiButSetUnitType(but, PROP_UNIT_LENGTH);
+                       but= uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Z:",           0, 70, 200, 20, &(tfp->ve_median[2]), -lim, lim, 10, 3, "");
+                       uiButSetUnitType(but, PROP_UNIT_LENGTH);
                        if(totw==tot) {
-                               uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "W:",        0, 50, 200, 20, &(tfp->ve_median[3]), 0.01, 100.0, 10, 3, "");
+                               uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "W:",        0, 50, 200, 20, &(tfp->ve_median[3]), 0.01, 100.0, 1, 3, "");
                                uiBlockEndAlign(block);
                                uiBlockBeginAlign(block);
                                uiDefButBitS(block, TOG, V3D_GLOBAL_STATS, B_REDR, "Global",            0, 25, 100, 20, &v3d->flag, 0, 0, 0, 0, "Displays global values");
@@ -347,6 +337,8 @@ static void v3d_editvertex_buts(const bContext *C, uiBlock *block, View3D *v3d,
                                uiBlockEndAlign(block);
                                if(totweight)
                                        uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Weight:",   0, 0, 200, 20, &(tfp->ve_median[4]), 0.0, 1.0, 10, 3, "Weight is used for SoftBody Goal");
+                               if(totradius)
+                                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Radius:",   0, 0, 200, 20, &(tfp->ve_median[5]), 0.0, 100.0, 10, 3, "Radius of curve CPs");
                                uiBlockEndAlign(block);
                        }
                        else {
@@ -355,56 +347,95 @@ static void v3d_editvertex_buts(const bContext *C, uiBlock *block, View3D *v3d,
                                uiDefButBitS(block, TOGN, V3D_GLOBAL_STATS, B_REDR, "Local",            100, 45, 100, 20, &v3d->flag, 0, 0, 0, 0, "Displays local values");
                                uiBlockEndAlign(block);
                                if(totweight)
-                                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Weight:",   0, 20, 200, 20, &(tfp->ve_median[4]), 0.0, 1.0, 10, 3, "Weight is used for SoftBody Goal");
+                                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Weight:",   0, 20, 200, 20, &(tfp->ve_median[4]), 0.0, 1.0, 1, 3, "Weight is used for SoftBody Goal");
+                               if(totradius)
+                                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Radius:",   0, 0, 200, 20, &(tfp->ve_median[5]), 0.0, 100.0, 1, 3, "Radius of curve CPs");
                                uiBlockEndAlign(block);
                        }
                }
                                
                if(totedge==1)
-                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Crease:",   0, 20, 200, 20, &(tfp->ve_median[3]), 0.0, 1.0, 10, 3, "");
+                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Crease:",   0, 20, 200, 20, &(tfp->ve_median[3]), 0.0, 1.0, 1, 3, "");
                else if(totedge>1)
-                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Median Crease:",    0, 20, 200, 20, &(tfp->ve_median[3]), 0.0, 1.0, 10, 3, "");
+                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Mean Crease:",      0, 20, 200, 20, &(tfp->ve_median[3]), 0.0, 1.0, 1, 3, "");
                
        }
        else {  // apply
                memcpy(ve_median, tfp->ve_median, sizeof(tfp->ve_median));
                
                if(v3d->flag & V3D_GLOBAL_STATS) {
-                       Mat4Invert(ob->imat, ob->obmat);
-                       Mat4MulVecfl(ob->imat, median);
-                       Mat4MulVecfl(ob->imat, ve_median);
+                       invert_m4_m4(ob->imat, ob->obmat);
+                       mul_m4_v3(ob->imat, median);
+                       mul_m4_v3(ob->imat, ve_median);
                }
-               VecSubf(median, ve_median, median);
+               sub_v3_v3v3(median, ve_median, median);
                median[3]= ve_median[3]-median[3];
                median[4]= ve_median[4]-median[4];
+               median[5]= ve_median[5]-median[5];
                
                if(ob->type==OB_MESH) {
                        Mesh *me= ob->data;
                        EditMesh *em = BKE_mesh_get_editmesh(me);
-                       EditVert *eve;
-                       EditEdge *eed;
-                       
-                       eve= em->verts.first;
-                       while(eve) {
-                               if(eve->f & SELECT) {
-                                       VecAddf(eve->co, eve->co, median);
+
+                       /* allow for some rounding error becasue of matrix transform */
+                       if(len_v3(median) > 0.000001) {
+                               EditVert *eve;
+
+                               for(eve= em->verts.first; eve; eve= eve->next) {
+                                       if(eve->f & SELECT) {
+                                               add_v3_v3(eve->co, median);
+                                       }
                                }
-                               eve= eve->next;
+
+                               recalc_editnormals(em);
                        }
-                       
-                       for(eed= em->edges.first; eed; eed= eed->next) {
-                               if(eed->f & SELECT) {
-                                       /* ensure the median can be set to zero or one */
-                                       if(ve_median[3]==0.0f) eed->crease= 0.0f;
-                                       else if(ve_median[3]==1.0f) eed->crease= 1.0f;
+
+                       if(median[3] != 0.0f) {
+                               EditEdge *eed;
+                               const float fixed_crease= (ve_median[3] <= 0.0f ? 0.0 : (ve_median[3] >= 1.0f ? 1.0 : FLT_MAX));
+                               
+                               if(fixed_crease != FLT_MAX) {
+                                       /* simple case */
+
+                                       for(eed= em->edges.first; eed; eed= eed->next) {
+                                               if(eed->f & SELECT) {
+                                                       eed->crease= fixed_crease;
+                                               }
+                                       }
+                               }
+                               else {
+                                       /* scale crease to target median */
+                                       float median_new= ve_median[3];
+                                       float median_orig= ve_median[3] - median[3]; /* previous median value */
+
+                                       /* incase of floating point error */
+                                       CLAMP(median_orig, 0.0, 1.0);
+                                       CLAMP(median_new, 0.0, 1.0);
+
+                                       if(median_new < median_orig) {
+                                               /* scale down */
+                                               const float sca= median_new / median_orig;
+                                               
+                                               for(eed= em->edges.first; eed; eed= eed->next) {
+                                                       if(eed->f & SELECT) {
+                                                               eed->crease *= sca;
+                                                               CLAMP(eed->crease, 0.0, 1.0);
+                                                       }
+                                               }
+                                       }
                                        else {
-                                               eed->crease+= median[3];
-                                               CLAMP(eed->crease, 0.0, 1.0);
+                                               /* scale up */
+                                               const float sca= (1.0f - median_new) / (1.0f - median_orig);
+
+                                               for(eed= em->edges.first; eed; eed= eed->next) {
+                                                       if(eed->f & SELECT) {
+                                                               eed->crease = 1.0f - ((1.0f - eed->crease) * sca);
+                                                               CLAMP(eed->crease, 0.0, 1.0);
+                                                       }
+                                               }
                                        }
                                }
                        }
-                       
-                       recalc_editnormals(em);
 
                        BKE_mesh_end_editmesh(me, em);
                }
@@ -414,25 +445,27 @@ static void v3d_editvertex_buts(const bContext *C, uiBlock *block, View3D *v3d,
                        BPoint *bp;
                        BezTriple *bezt;
                        int a;
-                       
-                       nu= cu->editnurb->first;
+                       ListBase *nurbs= ED_curve_editnurbs(cu);
+
+                       nu= nurbs->first;
                        while(nu) {
                                if(nu->type == CU_BEZIER) {
                                        bezt= nu->bezt;
                                        a= nu->pntsu;
                                        while(a--) {
                                                if(bezt->f2 & SELECT) {
-                                                       VecAddf(bezt->vec[0], bezt->vec[0], median);
-                                                       VecAddf(bezt->vec[1], bezt->vec[1], median);
-                                                       VecAddf(bezt->vec[2], bezt->vec[2], median);
+                                                       add_v3_v3(bezt->vec[0], median);
+                                                       add_v3_v3(bezt->vec[1], median);
+                                                       add_v3_v3(bezt->vec[2], median);
                                                        bezt->weight+= median[4];
+                                                       bezt->radius+= median[5];
                                                }
                                                else {
                                                        if(bezt->f1 & SELECT) {
-                                                               VecAddf(bezt->vec[0], bezt->vec[0], median);
+                                                               add_v3_v3(bezt->vec[0], median);
                                                        }
                                                        if(bezt->f3 & SELECT) {
-                                                               VecAddf(bezt->vec[2], bezt->vec[2], median);
+                                                               add_v3_v3(bezt->vec[2], median);
                                                        }
                                                }
                                                bezt++;
@@ -443,9 +476,10 @@ static void v3d_editvertex_buts(const bContext *C, uiBlock *block, View3D *v3d,
                                        a= nu->pntsu*nu->pntsv;
                                        while(a--) {
                                                if(bp->f1 & SELECT) {
-                                                       VecAddf(bp->vec, bp->vec, median);
+                                                       add_v3_v3(bp->vec, median);
                                                        bp->vec[3]+= median[3];
                                                        bp->weight+= median[4];
+                                                       bp->radius+= median[5];
                                                }
                                                bp++;
                                        }
@@ -461,11 +495,11 @@ static void v3d_editvertex_buts(const bContext *C, uiBlock *block, View3D *v3d,
                        BPoint *bp;
                        int a;
                        
-                       a= lt->editlatt->pntsu*lt->editlatt->pntsv*lt->editlatt->pntsw;
-                       bp= lt->editlatt->def;
+                       a= lt->editlatt->latt->pntsu*lt->editlatt->latt->pntsv*lt->editlatt->latt->pntsw;
+                       bp= lt->editlatt->latt->def;
                        while(a--) {
                                if(bp->f1 & SELECT) {
-                                       VecAddf(bp->vec, bp->vec, median);
+                                       add_v3_v3(bp->vec, median);
                                        bp->weight+= median[4];
                                }
                                bp++;
@@ -475,67 +509,385 @@ static void v3d_editvertex_buts(const bContext *C, uiBlock *block, View3D *v3d,
 //             ED_undo_push(C, "Transform properties");
        }
 }
+#define B_VGRP_PNL_COPY 1
+#define B_VGRP_PNL_NORMALIZE 2
+#define B_VGRP_PNL_EDIT_SINGLE 8 /* or greater */
+#define B_VGRP_PNL_COPY_SINGLE 16384 /* or greater */
 
-#if 0
-/* assumes armature active */
-static void validate_bonebutton_cb(bContext *C, void *bonev, void *namev)
+static void act_vert_def(Object *ob, EditVert **eve, MDeformVert **dvert)
+{
+       if(ob && ob->mode & OB_MODE_EDIT && ob->type==OB_MESH && ob->defbase.first) {
+               Mesh *me= ob->data;
+               EditMesh *em = BKE_mesh_get_editmesh(me);
+               EditSelection *ese = ((EditSelection*)em->selected.last);
+
+               if(ese && ese->type == EDITVERT) {
+                       *eve= (EditVert*)ese->data;
+                       *dvert= CustomData_em_get(&em->vdata, (*eve)->data, CD_MDEFORMVERT);
+                       return;
+               }
+
+               BKE_mesh_end_editmesh(me, em);
+       }
+
+       *eve= NULL;
+       *dvert= NULL;
+}
+
+static void editvert_mirror_update(Object *ob, EditVert *eve, int def_nr, int index)
+{
+       Mesh *me= ob->data;
+       EditMesh *em = BKE_mesh_get_editmesh(me);
+       EditVert *eve_mirr;
+
+       eve_mirr= editmesh_get_x_mirror_vert(ob, em, eve, eve->co, index);
+
+       if(eve_mirr && eve_mirr != eve) {
+               MDeformVert *dvert_src= CustomData_em_get(&em->vdata, eve->data, CD_MDEFORMVERT);
+               MDeformVert *dvert_dst= CustomData_em_get(&em->vdata, eve_mirr->data, CD_MDEFORMVERT);
+               if(dvert_dst) {
+                       if(def_nr == -1) {
+                               /* all vgroups, add groups where neded  */
+
+                               int *flip_map= defgroup_flip_map(ob, 1);
+                               defvert_sync_mapped(dvert_dst, dvert_src, flip_map, 1);
+                               MEM_freeN(flip_map);
+                       }
+                       else {
+                               /* single vgroup */
+                               MDeformWeight *dw= defvert_verify_index(dvert_dst, defgroup_flip_index(ob, def_nr, 1));
+                               if(dw) {
+                                       dw->weight= defvert_find_weight(dvert_src, def_nr);
+                               }
+                       }
+               }
+       }
+}
+
+static void vgroup_adjust_active(Object *ob, int def_nr)
+{
+       EditVert *eve_act;
+       MDeformVert *dvert_act;
+
+       act_vert_def(ob, &eve_act, &dvert_act);
+
+       if(dvert_act) {
+               if(((Mesh *)ob->data)->editflag & ME_EDIT_MIRROR_X)
+                       editvert_mirror_update(ob, eve_act, def_nr, -1);
+       }
+}
+
+static void vgroup_copy_active_to_sel(Object *ob)
+{
+       EditVert *eve_act;
+       MDeformVert *dvert_act;
+
+       act_vert_def(ob, &eve_act, &dvert_act);
+
+       if(dvert_act==NULL) {
+               return;
+       }
+       else {
+               Mesh *me= ob->data;
+               EditMesh *em = BKE_mesh_get_editmesh(me);
+               EditVert *eve;
+               MDeformVert *dvert;
+               int index= 0;
+
+               for(eve= em->verts.first; eve; eve= eve->next, index++) {
+                       if(eve->f & SELECT && eve != eve_act) {
+                               dvert= CustomData_em_get(&em->vdata, eve->data, CD_MDEFORMVERT);
+                               if(dvert) {
+                                       defvert_copy(dvert, dvert_act);
+
+                                       if(me->editflag & ME_EDIT_MIRROR_X)
+                                               editvert_mirror_update(ob, eve, -1, index);
+
+                               }
+                       }
+               }
+       }
+}
+
+static void vgroup_copy_active_to_sel_single(Object *ob, int def_nr)
 {
-       Object *ob= CTX_data_active_object(C);
+       EditVert *eve_act;
+       MDeformVert *dvert_act;
+
+       act_vert_def(ob, &eve_act, &dvert_act);
+
+       if(dvert_act==NULL) {
+               return;
+       }
+       else {
+               Mesh *me= ob->data;
+               EditMesh *em = BKE_mesh_get_editmesh(me);
+               EditVert *eve;
+               MDeformVert *dvert;
+               MDeformWeight *dw;
+               float act_weight = -1.0f;
+               int i;
+               int index= 0;
+
+               for(i=0, dw=dvert_act->dw; i < dvert_act->totweight; i++, dw++) {
+                       if(def_nr == dw->def_nr) {
+                               act_weight= dw->weight;
+                               break;
+                       }
+               }
+
+               if(act_weight < -0.5f)
+                       return;
+
+               for(eve= em->verts.first; eve; eve= eve->next, index++) {
+                       if(eve->f & SELECT && eve != eve_act) {
+                               dvert= CustomData_em_get(&em->vdata, eve->data, CD_MDEFORMVERT);
+                               if(dvert) {
+                                       for(i=0, dw=dvert->dw; i < dvert->totweight; i++, dw++) {
+                                               if(def_nr == dw->def_nr) {
+                                                       dw->weight= act_weight;
+
+                                                       if(me->editflag & ME_EDIT_MIRROR_X)
+                                                               editvert_mirror_update(ob, eve, -1, index);
+
+                                                       break;
+                                               }
+                                       }
+                               }
+                       }
+               }
+
+               if(me->editflag & ME_EDIT_MIRROR_X)
+                       editvert_mirror_update(ob, eve_act, -1, -1);
+
+       }
+}
+
+static void vgroup_normalize_active(Object *ob)
+{
+       EditVert *eve_act;
+       MDeformVert *dvert_act;
+
+       act_vert_def(ob, &eve_act, &dvert_act);
+
+       if(dvert_act==NULL)
+               return;
+
+       defvert_normalize(dvert_act);
+
+       if(((Mesh *)ob->data)->editflag & ME_EDIT_MIRROR_X)
+               editvert_mirror_update(ob, eve_act, -1, -1);
+
+
+
+}
+
+static void do_view3d_vgroup_buttons(bContext *C, void *UNUSED(arg), int event)
+{
+       Scene *scene= CTX_data_scene(C);
+       Object *ob= OBACT;
+
+       if(event==B_VGRP_PNL_NORMALIZE) {
+               vgroup_normalize_active(ob);
+       }
+       else if(event == B_VGRP_PNL_COPY) {
+               vgroup_copy_active_to_sel(ob);
+       }
+       else if(event >= B_VGRP_PNL_COPY_SINGLE) {
+               vgroup_copy_active_to_sel_single(ob, event - B_VGRP_PNL_COPY_SINGLE);
+       }
+       else if(event >= B_VGRP_PNL_EDIT_SINGLE) {
+               vgroup_adjust_active(ob, event - B_VGRP_PNL_EDIT_SINGLE);
+       }
+
+//  todo
+//     if(((Mesh *)ob->data)->editflag & ME_EDIT_MIRROR_X)
+//             ED_vgroup_mirror(ob, 1, 1, 0);
+
+       /* default for now */
+       DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+       WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data);
+}
+
+static int view3d_panel_vgroup_poll(const bContext *C, PanelType *UNUSED(pt))
+{
+       Scene *scene= CTX_data_scene(C);
+       Object *ob= OBACT;
+       EditVert *eve_act;
+       MDeformVert *dvert_act;
+
+       act_vert_def(ob, &eve_act, &dvert_act);
+
+       return dvert_act ? dvert_act->totweight : 0;
+}
+
+
+static void view3d_panel_vgroup(const bContext *C, Panel *pa)
+{
+       uiBlock *block= uiLayoutAbsoluteBlock(pa->layout);
+       Scene *scene= CTX_data_scene(C);
+       Object *ob= OBACT;
+
+       EditVert *eve;
+       MDeformVert *dvert;
+
+       act_vert_def(ob, &eve, &dvert);
+
+       if(dvert && dvert->totweight) {
+               uiLayout *col;
+               bDeformGroup *dg;
+               int i;
+               int yco = 0;
+
+               uiBlockSetHandleFunc(block, do_view3d_vgroup_buttons, NULL);
+
+               col= uiLayoutColumn(pa->layout, 0);
+               block= uiLayoutAbsoluteBlock(col);
+
+               uiBlockBeginAlign(block);
+
+               for (i=0; i<dvert->totweight; i++){
+                       dg = BLI_findlink (&ob->defbase, dvert->dw[i].def_nr);
+                       if(dg) {
+                               uiDefButF(block, NUM, B_VGRP_PNL_EDIT_SINGLE + dvert->dw[i].def_nr, dg->name,   0, yco, 180, 20, &dvert->dw[i].weight, 0.0, 1.0, 1, 3, "");
+                               uiDefBut(block, BUT, B_VGRP_PNL_COPY_SINGLE + dvert->dw[i].def_nr, "C", 180,yco,20,20, 0, 0, 0, 0, 0, "Copy this groups weight to other selected verts");
+                               yco -= 20;
+                       }
+               }
+               yco-=2;
+
+               uiBlockEndAlign(block);
+               uiBlockBeginAlign(block);
+               uiDefBut(block, BUT, B_VGRP_PNL_NORMALIZE, "Normalize", 0, yco,100,20, 0, 0, 0, 0, 0, "Normalize active vertex weights");
+               uiDefBut(block, BUT, B_VGRP_PNL_COPY, "Copy", 100,yco,100,20, 0, 0, 0, 0, 0, "Copy active vertex to other seleted verts");
+               uiBlockEndAlign(block);
+       }
+}
+
+static void v3d_transform_butsR(uiLayout *layout, PointerRNA *ptr)
+{
+       uiLayout *split, *colsub;
        
-       if(ob && ob->type==OB_ARMATURE) {
-               Bone *bone= bonev;
-               char oldname[32], newname[32];
-               
-               /* need to be on the stack */
-               BLI_strncpy(newname, bone->name, 32);
-               BLI_strncpy(oldname, (char *)namev, 32);
-               /* restore */
-               BLI_strncpy(bone->name, oldname, 32);
+       split = uiLayoutSplit(layout, 0.8, 0);
+       
+       if (ptr->type == &RNA_PoseBone) {
+               PointerRNA boneptr;
+               Bone *bone;
                
-               ED_armature_bone_rename(ob->data, oldname, newname); // editarmature.c
+               boneptr = RNA_pointer_get(ptr, "bone");
+               bone = boneptr.data;
+               uiLayoutSetActive(split, !(bone->parent && bone->flag & BONE_CONNECTED));
+       }
+       colsub = uiLayoutColumn(split, 1);
+       uiItemR(colsub, ptr, "location", 0, "Location", ICON_NULL);
+       colsub = uiLayoutColumn(split, 1);
+       uiItemL(colsub, "", ICON_NULL);
+       uiItemR(colsub, ptr, "lock_location", UI_ITEM_R_TOGGLE+UI_ITEM_R_ICON_ONLY, "", ICON_NULL);
+       
+       split = uiLayoutSplit(layout, 0.8, 0);
+       
+       switch(RNA_enum_get(ptr, "rotation_mode")) {
+               case ROT_MODE_QUAT: /* quaternion */
+                       colsub = uiLayoutColumn(split, 1);
+                       uiItemR(colsub, ptr, "rotation_quaternion", 0, "Rotation", ICON_NULL);
+                       colsub = uiLayoutColumn(split, 1);
+                       uiItemR(colsub, ptr, "lock_rotations_4d", UI_ITEM_R_TOGGLE, "4L", ICON_NULL);
+                       if (RNA_boolean_get(ptr, "lock_rotations_4d"))
+                               uiItemR(colsub, ptr, "lock_rotation_w", UI_ITEM_R_TOGGLE+UI_ITEM_R_ICON_ONLY, "", ICON_NULL);
+                       else
+                               uiItemL(colsub, "", ICON_NULL);
+                       uiItemR(colsub, ptr, "lock_rotation", UI_ITEM_R_TOGGLE+UI_ITEM_R_ICON_ONLY, "", ICON_NULL);
+                       break;
+               case ROT_MODE_AXISANGLE: /* axis angle */
+                       colsub = uiLayoutColumn(split, 1);
+                       uiItemR(colsub, ptr, "rotation_axis_angle", 0, "Rotation", ICON_NULL);
+                       colsub = uiLayoutColumn(split, 1);
+                       uiItemR(colsub, ptr, "lock_rotations_4d", UI_ITEM_R_TOGGLE, "4L", ICON_NULL);
+                       if (RNA_boolean_get(ptr, "lock_rotations_4d"))
+                               uiItemR(colsub, ptr, "lock_rotation_w", UI_ITEM_R_TOGGLE+UI_ITEM_R_ICON_ONLY, "", ICON_NULL);
+                       else
+                               uiItemL(colsub, "", ICON_NULL);
+                       uiItemR(colsub, ptr, "lock_rotation", UI_ITEM_R_TOGGLE+UI_ITEM_R_ICON_ONLY, "", ICON_NULL);
+                       break;
+               default: /* euler rotations */
+                       colsub = uiLayoutColumn(split, 1);
+                       uiItemR(colsub, ptr, "rotation_euler", 0, "Rotation", ICON_NULL);
+                       colsub = uiLayoutColumn(split, 1);
+                       uiItemL(colsub, "", ICON_NULL);
+                       uiItemR(colsub, ptr, "lock_rotation", UI_ITEM_R_TOGGLE+UI_ITEM_R_ICON_ONLY, "", ICON_NULL);
+                       break;
+       }
+       uiItemR(layout, ptr, "rotation_mode", 0, "", ICON_NULL);
+       
+       split = uiLayoutSplit(layout, 0.8, 0);
+       colsub = uiLayoutColumn(split, 1);
+       uiItemR(colsub, ptr, "scale", 0, "Scale", ICON_NULL);
+       colsub = uiLayoutColumn(split, 1);
+       uiItemL(colsub, "", ICON_NULL);
+       uiItemR(colsub, ptr, "lock_scale", UI_ITEM_R_TOGGLE+UI_ITEM_R_ICON_ONLY, "", ICON_NULL);
+       
+       if (ptr->type == &RNA_Object) {
+               Object *ob = ptr->data;
+               if (ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL))
+                       uiItemR(layout, ptr, "dimensions", 0, "Dimensions", ICON_NULL);
        }
 }
-#endif
 
-static void v3d_posearmature_buts(uiBlock *block, View3D *v3d, Object *ob, float lim)
+static void v3d_posearmature_buts(uiLayout *layout, Object *ob)
 {
-       bArmature *arm;
+//     uiBlock *block= uiLayoutGetBlock(layout);
+//     bArmature *arm;
        bPoseChannel *pchan;
-       Bone *bone= NULL;
-       TransformProperties *tfp= v3d->properties_storage;
+//     TransformProperties *tfp= v3d->properties_storage;
+       PointerRNA pchanptr;
+       uiLayout *col;
+//     uiLayout *row;
+//     uiBut *but;
 
-       arm = ob->data;
-       if (!arm || !ob->pose) return;
+       pchan= get_active_posechannel(ob);
 
-       for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
-               bone = pchan->bone;
-               if(bone && (bone->flag & BONE_ACTIVE) && (bone->layer & arm->layer))
-                       break;
-       }
+//     row= uiLayoutRow(layout, 0);
+       
        if (!pchan)     {
-               uiDefBut(block, LABEL, 0, "No Bone Active",                     0, 240, 100, 20, 0, 0, 0, 0, 0, "");
+               uiItemL(layout, "No Bone Active", ICON_NULL);
                return; 
        }
+
+       RNA_pointer_create(&ob->id, &RNA_PoseBone, pchan, &pchanptr);
+
+       col= uiLayoutColumn(layout, 0);
        
+       /* XXX: RNA buts show data in native types (i.e. quats, 4-component axis/angle, etc.)
+        * but oldskool UI shows in eulers always. Do we want to be able to still display in Eulers?
+        * Maybe needs RNA/ui options to display rotations as different types... */
+       v3d_transform_butsR(col, &pchanptr);
+
+#if 0
+       uiLayoutAbsoluteBlock(layout);
+
        if (pchan->rotmode == ROT_MODE_AXISANGLE) {
                float quat[4];
                /* convert to euler, passing through quats... */
-               AxisAngleToQuat(quat, &pchan->quat[1], pchan->quat[0]);
-               QuatToEul(quat, tfp->ob_eul);
+               axis_angle_to_quat(quat, pchan->rotAxis, pchan->rotAngle);
+               quat_to_eul( tfp->ob_eul,quat);
        }
        else if (pchan->rotmode == ROT_MODE_QUAT)
-               QuatToEul(pchan->quat, tfp->ob_eul);
+               quat_to_eul( tfp->ob_eul,pchan->quat);
        else
-               VecCopyf(tfp->ob_eul, pchan->eul);
+               copy_v3_v3(tfp->ob_eul, pchan->eul);
        tfp->ob_eul[0]*= 180.0/M_PI;
        tfp->ob_eul[1]*= 180.0/M_PI;
        tfp->ob_eul[2]*= 180.0/M_PI;
        
        uiDefBut(block, LABEL, 0, "Location:",                  0, 240, 100, 20, 0, 0, 0, 0, 0, "");
        uiBlockBeginAlign(block);
-       uiDefButF(block, NUM, B_ARMATUREPANEL2, "X:",   0, 220, 120, 19, pchan->loc, -lim, lim, 100, 3, "");
-       uiDefButF(block, NUM, B_ARMATUREPANEL2, "Y:",   0, 200, 120, 19, pchan->loc+1, -lim, lim, 100, 3, "");
-       uiDefButF(block, NUM, B_ARMATUREPANEL2, "Z:",   0, 180, 120, 19, pchan->loc+2, -lim, lim, 100, 3, "");
+       
+       but= uiDefButF(block, NUM, B_ARMATUREPANEL2, "X:",      0, 220, 120, 19, pchan->loc, -lim, lim, 100, 3, "");
+       uiButSetUnitType(but, PROP_UNIT_LENGTH);
+       but= uiDefButF(block, NUM, B_ARMATUREPANEL2, "Y:",      0, 200, 120, 19, pchan->loc+1, -lim, lim, 100, 3, "");
+       uiButSetUnitType(but, PROP_UNIT_LENGTH);
+       but= uiDefButF(block, NUM, B_ARMATUREPANEL2, "Z:",      0, 180, 120, 19, pchan->loc+2, -lim, lim, 100, 3, "");
+       uiButSetUnitType(but, PROP_UNIT_LENGTH);
        uiBlockEndAlign(block);
        
        uiBlockBeginAlign(block);
@@ -569,95 +921,110 @@ static void v3d_posearmature_buts(uiBlock *block, View3D *v3d, Object *ob, float
        uiDefIconButBitS(block, ICONTOG, OB_LOCK_SCALEY, B_REDR, ICON_UNLOCKED, 125, 40, 25, 19, &(pchan->protectflag), 0, 0, 0, 0, "Protects Y Scale value from being Transformed");
        uiDefIconButBitS(block, ICONTOG, OB_LOCK_SCALEZ, B_REDR, ICON_UNLOCKED, 125, 20, 25, 19, &(pchan->protectflag), 0, 0, 0, 0, "Protects z Scale value from being Transformed");
        uiBlockEndAlign(block);
+#endif
 }
 
 /* assumes armature editmode */
-void validate_editbonebutton_cb(bContext *C, void *bonev, void *namev)
+#if 0
+static void validate_editbonebutton_cb(bContext *C, void *bonev, void *namev)
 {
        EditBone *eBone= bonev;
-       char oldname[32], newname[32];
-       
+       char oldname[sizeof(eBone->name)], newname[sizeof(eBone->name)];
+
        /* need to be on the stack */
-       BLI_strncpy(newname, eBone->name, 32);
-       BLI_strncpy(oldname, (char *)namev, 32);
+       BLI_strncpy(newname, eBone->name, sizeof(eBone->name));
+       BLI_strncpy(oldname, (char *)namev, sizeof(eBone->name));
        /* restore */
-       BLI_strncpy(eBone->name, oldname, 32);
-       
+       BLI_strncpy(eBone->name, oldname, sizeof(eBone->name));
+
        ED_armature_bone_rename(CTX_data_edit_object(C)->data, oldname, newname); // editarmature.c
        WM_event_add_notifier(C, NC_OBJECT|ND_BONE_SELECT, CTX_data_edit_object(C)); // XXX fix
 }
+#endif
 
-static void v3d_editarmature_buts(uiBlock *block, View3D *v3d, Object *ob, float lim)
+static void v3d_editarmature_buts(uiLayout *layout, Object *ob)
 {
+//     uiBlock *block= uiLayoutGetBlock(layout);
        bArmature *arm= ob->data;
        EditBone *ebone;
-       TransformProperties *tfp= v3d->properties_storage;
+//     TransformProperties *tfp= v3d->properties_storage;
+//     uiLayout *row;
+       uiLayout *col;
+       PointerRNA eboneptr;
        
-       ebone= arm->edbo->first;
-
-       for (ebone = arm->edbo->first; ebone; ebone=ebone->next){
-               if ((ebone->flag & BONE_ACTIVE) && (ebone->layer & arm->layer))
-                       break;
-       }
+       ebone= arm->act_edbone;
 
-       if (!ebone)
+       if (!ebone || (ebone->layer & arm->layer)==0)
                return;
        
-       uiDefBut(block, LABEL, 0, "Head:",                                      0, 210, 100, 20, 0, 0, 0, 0, 0, "");
-       uiBlockBeginAlign(block);
-       uiDefButF(block, NUM, B_ARMATUREPANEL1, "X:",           0, 190, 100, 19, ebone->head, -lim, lim, 10, 3, "X Location of the head end of the bone");
-       uiDefButF(block, NUM, B_ARMATUREPANEL1, "Y:",           0, 170, 100, 19, ebone->head+1, -lim, lim, 10, 3, "Y Location of the head end of the bone");
-       uiDefButF(block, NUM, B_ARMATUREPANEL1, "Z:",           0, 150, 100, 19, ebone->head+2, -lim, lim, 10, 3, "Z Location of the head end of the bone");
-       if (ebone->parent && ebone->flag & BONE_CONNECTED )
-               uiDefButF(block, NUM, B_ARMATUREPANEL1, "Radius:",      0, 130, 100, 19, &ebone->parent->rad_tail, 0, lim, 10, 3, "Head radius. Visualize with the Envelope display option");
-       else
-               uiDefButF(block, NUM, B_ARMATUREPANEL1, "Radius:",      0, 130, 100, 19, &ebone->rad_head, 0, lim, 10, 3, "Head radius. Visualize with the Envelope display option");
-       uiBlockEndAlign(block);
-       
-       uiBlockEndAlign(block);
-       uiDefBut(block, LABEL, 0, "Tail:",                                      0, 110, 100, 20, 0, 0, 0, 0, 0, "");
-       uiBlockBeginAlign(block);
-       uiDefButF(block, NUM, B_ARMATUREPANEL1, "X:",           0, 90, 100, 19, ebone->tail, -lim, lim, 10, 3, "X Location of the tail end of the bone");
-       uiDefButF(block, NUM, B_ARMATUREPANEL1, "Y:",           0, 70, 100, 19, ebone->tail+1, -lim, lim, 10, 3, "Y Location of the tail end of the bone");
-       uiDefButF(block, NUM, B_ARMATUREPANEL1, "Z:",           0, 50, 100, 19, ebone->tail+2, -lim, lim, 10, 3, "Z Location of the tail end of the bone");
-       uiDefButF(block, NUM, B_ARMATUREPANEL1, "Radius:",      0, 30, 100, 19, &ebone->rad_tail, 0, lim, 10, 3, "Tail radius. Visualize with the Envelope display option");
-       uiBlockEndAlign(block);
-       
-       tfp->ob_eul[0]= 180.0*ebone->roll/M_PI;
-       uiDefButF(block, NUM, B_ARMATUREPANEL1, "Roll:",        0, 0, 100, 19, tfp->ob_eul, -lim, lim, 1000, 3, "Bone rotation around head-tail axis");
-       uiBlockBeginAlign(block);
+//     row= uiLayoutRow(layout, 0);
+       RNA_pointer_create(&arm->id, &RNA_EditBone, ebone, &eboneptr);
+
+
+       col= uiLayoutColumn(layout, 0);
+       uiItemR(col, &eboneptr, "head", 0, "Head", ICON_NULL);
+       if (ebone->parent && ebone->flag & BONE_CONNECTED ) {
+               PointerRNA parptr = RNA_pointer_get(&eboneptr, "parent");
+               uiItemR(col, &parptr, "tail_radius", 0, "Radius (Parent)", ICON_NULL);
+       } else {
+               uiItemR(col, &eboneptr, "head_radius", 0, "Radius", ICON_NULL);
+       }
        
+       uiItemR(col, &eboneptr, "tail", 0, "Tail", ICON_NULL);
+       uiItemR(col, &eboneptr, "tail_radius", 0, "Radius", ICON_NULL);
        
+       uiItemR(col, &eboneptr, "roll", 0, "Roll", ICON_NULL);
 }
 
-static void v3d_editmetaball_buts(uiBlock *block, Object *ob, float lim)
+static void v3d_editmetaball_buts(uiLayout *layout, Object *ob)
 {
-       MetaElem *lastelem= NULL; // XXX
-
-       if(lastelem) {
-               uiBlockBeginAlign(block);
-               uiDefButF(block, NUM, B_RECALCMBALL, "LocX:", 10, 70, 140, 19, &lastelem->x, -lim, lim, 100, 3, "");
-               uiDefButF(block, NUM, B_RECALCMBALL, "LocY:", 10, 50, 140, 19, &lastelem->y, -lim, lim, 100, 3, "");
-               uiDefButF(block, NUM, B_RECALCMBALL, "LocZ:", 10, 30, 140, 19, &lastelem->z, -lim, lim, 100, 3, "");
-
-               uiBlockBeginAlign(block);
-               if(lastelem->type!=MB_BALL)
-                       uiDefButF(block, NUM, B_RECALCMBALL, "dx:", 160, 70, 140, 19, &lastelem->expx, 0, lim, 100, 3, "");
-               if((lastelem->type!=MB_BALL) && (lastelem->type!=MB_TUBE))
-                       uiDefButF(block, NUM, B_RECALCMBALL, "dy:", 160, 50, 140, 19, &lastelem->expy, 0, lim, 100, 3, "");
-               if((lastelem->type==MB_ELIPSOID) || (lastelem->type==MB_CUBE))
-                       uiDefButF(block, NUM, B_RECALCMBALL, "dz:", 160, 30, 140, 19, &lastelem->expz, 0, lim, 100, 3, "");
-
-               uiBlockEndAlign(block); 
+       PointerRNA mbptr, ptr;
+       MetaBall *mball= ob->data;
+//     uiLayout *row;
+       uiLayout *col;
+       
+       if (!mball || !(mball->lastelem)) return;
+       
+       RNA_pointer_create(&mball->id, &RNA_MetaBall, mball, &mbptr);
+       
+//     row= uiLayoutRow(layout, 0);
 
-               uiBlockBeginAlign(block);
-               uiDefButF(block, NUM, B_RECALCMBALL, "Radius:", 10, 120, 140, 19, &lastelem->rad, 0, lim, 100, 3, "Size of the active metaball");
-               uiDefButF(block, NUM, B_RECALCMBALL, "Stiffness:", 10, 100, 140, 19, &lastelem->s, 0, 10, 100, 3, "Stiffness of the active metaball");
-               uiBlockEndAlign(block);
-               
-               uiDefButS(block, MENU, B_RECALCMBALL, "Type%t|Ball%x0|Tube%x4|Plane%x5|Elipsoid%x6|Cube%x7", 160, 120, 140, 19, &lastelem->type, 0.0, 0.0, 0, 0, "Set active element type");
-               
-       }
+       RNA_pointer_create(&mball->id, &RNA_MetaElement, mball->lastelem, &ptr);
+       
+       col= uiLayoutColumn(layout, 0);
+       uiItemR(col, &ptr, "co", 0, "Location", ICON_NULL);
+       
+       uiItemR(col, &ptr, "radius", 0, "Radius", ICON_NULL);
+       uiItemR(col, &ptr, "stiffness", 0, "Stiffness", ICON_NULL);
+       
+       uiItemR(col, &ptr, "type", 0, "Type", ICON_NULL);
+       
+       col= uiLayoutColumn(layout, 1);
+       switch (RNA_enum_get(&ptr, "type")) {
+               case MB_BALL:
+                       break;
+               case MB_CUBE:
+                       uiItemL(col, "Size:", ICON_NULL);
+                       uiItemR(col, &ptr, "size_x", 0, "X", ICON_NULL);
+                       uiItemR(col, &ptr, "size_y", 0, "Y", ICON_NULL);
+                       uiItemR(col, &ptr, "size_z", 0, "Z", ICON_NULL);
+                       break;
+               case MB_TUBE:
+                       uiItemL(col, "Size:", ICON_NULL);
+                       uiItemR(col, &ptr, "size_x", 0, "X", ICON_NULL);
+                       break;
+               case MB_PLANE:
+                       uiItemL(col, "Size:", ICON_NULL);
+                       uiItemR(col, &ptr, "size_x", 0, "X", ICON_NULL);
+                       uiItemR(col, &ptr, "size_y", 0, "Y", ICON_NULL);
+                       break;
+               case MB_ELIPSOID:
+                       uiItemL(col, "Size:", ICON_NULL);
+                       uiItemR(col, &ptr, "size_x", 0, "X", ICON_NULL);
+                       uiItemR(col, &ptr, "size_y", 0, "Y", ICON_NULL);
+                       uiItemR(col, &ptr, "size_z", 0, "Z", ICON_NULL);
+                       break;             
+       }       
 }
 
 /* test if 'ob' is a parent somewhere in par's parents */
@@ -668,12 +1035,13 @@ static int test_parent_loop(Object *par, Object *ob)
        return test_parent_loop(par->parent, ob);
 }
 
-static void do_view3d_region_buttons(bContext *C, void *arg, int event)
+static void do_view3d_region_buttons(bContext *C, void *UNUSED(index), int event)
 {
+       Main *bmain= CTX_data_main(C);
        Scene *scene= CTX_data_scene(C);
-       Object *obedit= CTX_data_edit_object(C);
+//     Object *obedit= CTX_data_edit_object(C);
        View3D *v3d= CTX_wm_view3d(C);
-       BoundBox *bb;
+//     BoundBox *bb;
        Object *ob= OBACT;
        TransformProperties *tfp= v3d->properties_storage;
        
@@ -684,106 +1052,14 @@ static void do_view3d_region_buttons(bContext *C, void *arg, int event)
                return; /* no notifier! */
                
        case B_OBJECTPANEL:
-               DAG_id_flush_update(&ob->id, OB_RECALC_OB);
-               break;
-               
-       case B_OBJECTPANELROT:
-               if(ob) {
-                       ob->rot[0]= M_PI*tfp->ob_eul[0]/180.0;
-                       ob->rot[1]= M_PI*tfp->ob_eul[1]/180.0;
-                       ob->rot[2]= M_PI*tfp->ob_eul[2]/180.0;
-                       DAG_id_flush_update(&ob->id, OB_RECALC_OB);
-               }
+               DAG_id_tag_update(&ob->id, OB_RECALC_OB);
                break;
 
-       case B_OBJECTPANELSCALE:
-               if(ob) {
-
-                       /* link scale; figure out which axis changed */
-                       if (tfp->link_scale) {
-                               float ratio, tmp, max = 0.0;
-                               int axis;
-                               
-                               axis = 0;
-                               max = fabs(tfp->ob_scale[0] - ob->size[0]);
-                               tmp = fabs(tfp->ob_scale[1] - ob->size[1]);
-                               if (tmp > max) {
-                                       axis = 1;
-                                       max = tmp;
-                               }
-                               tmp = fabs(tfp->ob_scale[2] - ob->size[2]);
-                               if (tmp > max) {
-                                       axis = 2;
-                                       max = tmp;
-                               }
-                       
-                               if (ob->size[axis] != tfp->ob_scale[axis]) {
-                                       if (fabs(ob->size[axis]) > FLT_EPSILON) {
-                                               ratio = tfp->ob_scale[axis] / ob->size[axis];
-                                               ob->size[0] *= ratio;
-                                               ob->size[1] *= ratio;
-                                               ob->size[2] *= ratio;
-                                       }
-                               }
-                       }
-                       else {
-                               VECCOPY(ob->size, tfp->ob_scale);
-                               
-                       }
-                       DAG_id_flush_update(&ob->id, OB_RECALC_OB);
-               }
-               break;
-
-       case B_OBJECTPANELDIMS:
-               bb= object_get_boundbox(ob);
-               if(bb) {
-                       float old_dims[3], scale[3], ratio, len[3];
-                       int axis;
-
-                       Mat4ToSize(ob->obmat, scale);
-
-                       len[0] = bb->vec[4][0] - bb->vec[0][0];
-                       len[1] = bb->vec[2][1] - bb->vec[0][1];
-                       len[2] = bb->vec[1][2] - bb->vec[0][2];
-
-                       old_dims[0] = fabs(scale[0]) * len[0];
-                       old_dims[1] = fabs(scale[1]) * len[1];
-                       old_dims[2] = fabs(scale[2]) * len[2];
-
-                       /* for each axis changed */
-                       for (axis = 0; axis<3; axis++) {
-                               if (fabs(old_dims[axis] - tfp->ob_dims[axis]) > 0.0001) {
-                                       if (old_dims[axis] > 0.0) {
-                                               ratio = tfp->ob_dims[axis] / old_dims[axis]; 
-                                               if (tfp->link_scale) {
-                                                       ob->size[0] *= ratio;
-                                                       ob->size[1] *= ratio;
-                                                       ob->size[2] *= ratio;
-                                                       break;
-                                               }
-                                               else {
-                                                       ob->size[axis] *= ratio;
-                                               }
-                                       }
-                                       else {
-                                               if (len[axis] > 0) {
-                                                       ob->size[axis] = tfp->ob_dims[axis] / len[axis];
-                                               }
-                                       }
-                               }
-                       }
-                       
-                       /* prevent multiple B_OBJECTPANELDIMS events to keep scaling, cycling with TAB on buttons can cause that */
-                       VECCOPY(tfp->ob_dims, old_dims);
-                       
-                       DAG_id_flush_update(&ob->id, OB_RECALC_OB);
-               }
-               break;
        
        case B_OBJECTPANELMEDIAN:
                if(ob) {
-                       v3d_editvertex_buts(C, NULL, v3d, ob, 1.0);
-                       DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
+                       v3d_editvertex_buts(NULL, v3d, ob, 1.0);
+                       DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
                }
                break;
                
@@ -793,72 +1069,19 @@ static void do_view3d_region_buttons(bContext *C, void *arg, int event)
                        if(ob->id.lib || test_parent_loop(ob->parent, ob) ) 
                                ob->parent= NULL;
                        else {
-                               DAG_scene_sort(scene);
-                               DAG_id_flush_update(&ob->id, OB_RECALC_OB);
+                               DAG_scene_sort(bmain, scene);
+                               DAG_id_tag_update(&ob->id, OB_RECALC_OB);
                        }
                }
                break;
                
-       case B_ARMATUREPANEL1:
-               {
-                       bArmature *arm= obedit->data;
-                       EditBone *ebone, *child;
-                       
-                       for (ebone = arm->edbo->first; ebone; ebone=ebone->next){
-                               if ((ebone->flag & BONE_ACTIVE) && (ebone->layer & arm->layer))
-                                       break;
-                       }
-                       if (ebone) {
-                               ebone->roll= M_PI*tfp->ob_eul[0]/180.0;
-                               //      Update our parent
-                               if (ebone->parent && ebone->flag & BONE_CONNECTED){
-                                       VECCOPY (ebone->parent->tail, ebone->head);
-                               }
-                       
-                               //      Update our children if necessary
-                               for (child = arm->edbo->first; child; child=child->next){
-                                       if (child->parent == ebone && (child->flag & BONE_CONNECTED)){
-                                               VECCOPY (child->head, ebone->tail);
-                                       }
-                               }
-                               if(arm->flag & ARM_MIRROR_EDIT) {
-                                       EditBone *eboflip= ED_armature_bone_get_mirrored(arm->edbo, ebone);
-                                       if(eboflip) {
-                                               eboflip->roll= -ebone->roll;
-                                               eboflip->head[0]= -ebone->head[0];
-                                               eboflip->tail[0]= -ebone->tail[0];
-                                               
-                                               //      Update our parent
-                                               if (eboflip->parent && eboflip->flag & BONE_CONNECTED){
-                                                       VECCOPY (eboflip->parent->tail, eboflip->head);
-                                               }
-                                               
-                                               //      Update our children if necessary
-                                               for (child = arm->edbo->first; child; child=child->next){
-                                                       if (child->parent == eboflip && (child->flag & BONE_CONNECTED)){
-                                                               VECCOPY (child->head, eboflip->tail);
-                                                       }
-                                               }
-                                       }
-                               }
-                       }
-               }
-               break;
+
        case B_ARMATUREPANEL3:  // rotate button on channel
                {
-                       bArmature *arm;
                        bPoseChannel *pchan;
-                       Bone *bone;
                        float eul[3];
                        
-                       arm = ob->data;
-                       if (!arm || !ob->pose) return;
-                               
-                       for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
-                               bone = pchan->bone;
-                               if(bone && (bone->flag & BONE_ACTIVE) && (bone->layer & arm->layer))
-                                       break;
-                       }
+                       pchan= get_active_posechannel(ob);
                        if (!pchan) return;
                        
                        /* make a copy to eul[3], to allow TAB on buttons to work */
@@ -869,25 +1092,27 @@ static void do_view3d_region_buttons(bContext *C, void *arg, int event)
                        if (pchan->rotmode == ROT_MODE_AXISANGLE) {
                                float quat[4];
                                /* convert to axis-angle, passing through quats  */
-                               EulToQuat(eul, quat);
-                               QuatToAxisAngle(quat, &pchan->quat[1], &pchan->quat[0]);
+                               eul_to_quat( quat,eul);
+                               quat_to_axis_angle( pchan->rotAxis, &pchan->rotAngle,quat);
                        }
                        else if (pchan->rotmode == ROT_MODE_QUAT)
-                               EulToQuat(eul, pchan->quat);
+                               eul_to_quat( pchan->quat,eul);
                        else
-                               VecCopyf(pchan->eul, eul);
-                       
+                               copy_v3_v3(pchan->eul, eul);
                }
                /* no break, pass on */
        case B_ARMATUREPANEL2:
                {
                        ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK);
-                       DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
+                       DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
                }
                break;
        case B_TRANSFORMSPACEADD:
-               BIF_createTransformOrientation(C, NULL, "", 1, 0);
+       {
+               char names[sizeof(((TransformOrientation *)NULL)->name)]= "";
+               BIF_createTransformOrientation(C, NULL, names, 1, 0);
                break;
+       }
        case B_TRANSFORMSPACECLEAR:
                BIF_clearTransformOrientation(C);
                break;
@@ -935,7 +1160,7 @@ static void do_view3d_region_buttons(bContext *C, void *arg, int event)
                                int a;
                                for(a=0; a<me->totvert; a++)
                                        ED_vgroup_vert_remove (ob, defGroup, a);
-                               DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
+                               DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
                        }
                }
                break;
@@ -973,104 +1198,8 @@ static void do_view3d_region_buttons(bContext *C, void *arg, int event)
        }
 
        /* default for now */
-       WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, ob);
-}
-
-void removeTransformOrientation_func(bContext *C, void *target, void *unused)
-{
-       BIF_removeTransformOrientation(C, (TransformOrientation *) target);
-}
-
-void selectTransformOrientation_func(bContext *C, void *target, void *unused)
-{
-       BIF_selectTransformOrientation(C, (TransformOrientation *) target);
-}
-
-#if 0 // XXX not used
-static void view3d_panel_transform_spaces(const bContext *C, Panel *pa)
-{
-       Scene *scene= CTX_data_scene(C);
-       Object *obedit= CTX_data_edit_object(C);
-       View3D *v3d= CTX_wm_view3d(C);
-       ListBase *transform_spaces = &scene->transform_spaces;
-       TransformOrientation *ts = transform_spaces->first;
-       uiBlock *block;
-       uiBut *but;
-       int xco = 20, yco = 70;
-       int index;
-
-       block= uiLayoutFreeBlock(pa->layout);
-
-       uiBlockBeginAlign(block);
-       
-       if (obedit)
-               uiDefBut(block, BUT, B_TRANSFORMSPACEADD, "Add", xco,120,80,20, 0, 0, 0, 0, 0, "Add the selected element as a Transform Orientation");
-       else
-               uiDefBut(block, BUT, B_TRANSFORMSPACEADD, "Add", xco,120,80,20, 0, 0, 0, 0, 0, "Add the active object as a Transform Orientation");
-
-       uiDefBut(block, BUT, B_TRANSFORMSPACECLEAR, "Clear", xco + 80,120,80,20, 0, 0, 0, 0, 0, "Removal all Transform Orientations");
-       
-       uiBlockEndAlign(block);
-       
-       uiBlockBeginAlign(block);
-       
-       uiDefButS(block, ROW, B_REDR, "Global", xco,            90, 40,20, &v3d->twmode, 5.0, (float)V3D_MANIP_GLOBAL,0, 0, "Global Transform Orientation");
-       uiDefButS(block, ROW, B_REDR, "Local",  xco + 40,       90, 40,20, &v3d->twmode, 5.0, (float)V3D_MANIP_LOCAL, 0, 0, "Local Transform Orientation");
-       uiDefButS(block, ROW, B_REDR, "Normal", xco + 80,       90, 40,20, &v3d->twmode, 5.0, (float)V3D_MANIP_NORMAL,0, 0, "Normal Transform Orientation");
-       uiDefButS(block, ROW, B_REDR, "View",           xco + 120,      90, 40,20, &v3d->twmode, 5.0, (float)V3D_MANIP_VIEW,    0, 0, "View Transform Orientation");
-       
-       for (index = V3D_MANIP_CUSTOM, ts = transform_spaces->first ; ts ; ts = ts->next, index++) {
-
-               if (v3d->twmode == index) {
-                       but = uiDefIconButS(block,ROW, B_REDR, ICON_CHECKBOX_HLT, xco,yco,XIC,YIC, &v3d->twmode, 5.0, (float)index, 0, 0, "Use this Custom Transform Orientation");
-               }
-               else {
-                       but = uiDefIconButS(block,ROW, B_REDR, ICON_CHECKBOX_DEHLT, xco,yco,XIC,YIC, &v3d->twmode, 5.0, (float)index, 0, 0, "Use this Custom Transform Orientation");
-               }
-               uiButSetFunc(but, selectTransformOrientation_func, ts, NULL);
-               uiDefBut(block, TEX, 0, "", xco+=XIC, yco,100+XIC,20, &ts->name, 0, 30, 0, 0, "Edits the name of this Transform Orientation");
-               but = uiDefIconBut(block, BUT, B_REDR, ICON_X, xco+=100+XIC,yco,XIC,YIC, 0, 0, 0, 0, 0, "Deletes this Transform Orientation");
-               uiButSetFunc(but, removeTransformOrientation_func, ts, NULL);
-
-               xco = 20;
-               yco -= 25;
-       }
-       uiBlockEndAlign(block);
-}
-#endif // XXX not used
-
-#if 0
-static void brush_idpoin_handle(bContext *C, ID *id, int event)
-{
-       Brush **br = current_brush_source(CTX_data_scene(C));
-
-       if(!br)
-               return;
-
-       switch(event) {
-       case UI_ID_BROWSE:
-               (*br) = (Brush*)id;
-               break;
-       case UI_ID_DELETE:
-               brush_delete(br);
-               break;
-       case UI_ID_RENAME:
-               /* XXX ? */
-               break;
-       case UI_ID_ADD_NEW:
-               if(id) {
-                       (*br) = copy_brush((Brush*)id);
-                       id->us--;
-               }
-               else
-                       (*br) = add_brush("Brush");
-               break;
-       case UI_ID_OPEN:
-               /* XXX not implemented */
-               break;
-       }
+       WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, ob);
 }
-#endif
 
 static void view3d_panel_object(const bContext *C, Panel *pa)
 {
@@ -1081,6 +1210,8 @@ static void view3d_panel_object(const bContext *C, Panel *pa)
        //uiBut *bt;
        Object *ob= OBACT;
        TransformProperties *tfp;
+       PointerRNA obptr;
+       uiLayout *col, *row;
        float lim;
        
        if(ob==NULL) return;
@@ -1090,129 +1221,37 @@ static void view3d_panel_object(const bContext *C, Panel *pa)
                v3d->properties_storage= MEM_callocN(sizeof(TransformProperties), "TransformProperties");
        tfp= v3d->properties_storage;
        
-       block= uiLayoutFreeBlock(pa->layout);
-       uiBlockSetHandleFunc(block, do_view3d_region_buttons, NULL);
-
 // XXX uiSetButLock(object_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
-       
+       /*
        if(ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT)) {
        }
        else {
                if((ob->mode & OB_MODE_PARTICLE_EDIT)==0) {
-                       strcpy(ob->parsubstr, "");
                        uiBlockEndAlign(block);
                }
        }
+       */
 
        lim= 10000.0f*MAX2(1.0, v3d->grid);
 
+       block= uiLayoutGetBlock(pa->layout);
+       uiBlockSetHandleFunc(block, do_view3d_region_buttons, NULL);
+
+       col= uiLayoutColumn(pa->layout, 0);
+       row= uiLayoutRow(col, 0);
+       RNA_id_pointer_create(&ob->id, &obptr);
+
        if(ob==obedit) {
-               if(ob->type==OB_ARMATURE) v3d_editarmature_buts(block, v3d, ob, lim);
-               if(ob->type==OB_MBALL) v3d_editmetaball_buts(block, ob, lim);
-               else v3d_editvertex_buts(C, block, v3d, ob, lim);
+               if(ob->type==OB_ARMATURE) v3d_editarmature_buts(col, ob);
+               if(ob->type==OB_MBALL) v3d_editmetaball_buts(col, ob);
+               else v3d_editvertex_buts(col, v3d, ob, lim);
        }
        else if(ob->mode & OB_MODE_POSE) {
-               v3d_posearmature_buts(block, v3d, ob, lim);
+               v3d_posearmature_buts(col, ob);
        }
        else {
-               BoundBox *bb = NULL;
-               
-               uiDefBut(block, LABEL, 0, "Location:",                                                                          0, 300, 100, 20, 0, 0, 0, 0, 0, "");
-               uiBlockBeginAlign(block);       
-               uiDefButF(block, NUM, B_OBJECTPANEL, "X:",                                                                      0, 280, 120, 19, &(ob->loc[0]), -lim, lim, 100, 3, "");         
-               uiDefButF(block, NUM, B_OBJECTPANEL, "Y:",                                                                      0, 260, 120, 19, &(ob->loc[1]), -lim, lim, 100, 3, "");
-               uiDefButF(block, NUM, B_OBJECTPANEL, "Z:",                                                                      0, 240, 120, 19, &(ob->loc[2]), -lim, lim, 100, 3, "");
-               uiBlockEndAlign(block);
-               
-               uiBlockBeginAlign(block);
-               uiDefIconButBitS(block, ICONTOG, OB_LOCK_LOCX, B_REDR, ICON_UNLOCKED,           125, 280, 25, 19, &(ob->protectflag), 0, 0, 0, 0, "Protects X Location value from being Transformed");
-               uiDefIconButBitS(block, ICONTOG, OB_LOCK_LOCY, B_REDR, ICON_UNLOCKED,           125, 260, 25, 19, &(ob->protectflag), 0, 0, 0, 0, "Protects Y Location value from being Transformed");
-               uiDefIconButBitS(block, ICONTOG, OB_LOCK_LOCZ, B_REDR, ICON_UNLOCKED,           125, 240, 25, 19, &(ob->protectflag), 0, 0, 0, 0, "Protects Z Location value from being Transformed");
-               uiBlockEndAlign(block);
-               
-               tfp->ob_eul[0]= 180.0*ob->rot[0]/M_PI;
-               tfp->ob_eul[1]= 180.0*ob->rot[1]/M_PI;
-               tfp->ob_eul[2]= 180.0*ob->rot[2]/M_PI;
-               
-               uiBlockBeginAlign(block);
-               if ((ob->parent) && (ob->partype == PARBONE)) {
-                       uiDefBut(block, LABEL, 0, "Rotation:",                                                                  0, 220, 100, 20, 0, 0, 0, 0, 0, "");
-                       uiBlockBeginAlign(block);
-                       uiDefButF(block, NUM, B_OBJECTPANELROT, "X:",                                                   0, 200, 120, 19, &(tfp->ob_eul[0]), -lim, lim, 1000, 3, "");
-                       uiDefButF(block, NUM, B_OBJECTPANELROT, "Y:",                                                   0, 180, 120, 19, &(tfp->ob_eul[1]), -lim, lim, 1000, 3, "");
-                       uiDefButF(block, NUM, B_OBJECTPANELROT, "Z:",                                                   0, 160, 120, 19, &(tfp->ob_eul[2]), -lim, lim, 1000, 3, "");
-                       uiBlockEndAlign(block);
-                       
-                       uiBlockBeginAlign(block);
-                       uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTX, B_REDR, ICON_UNLOCKED,   125, 200, 25, 19, &(ob->protectflag), 0, 0, 0, 0, "Protects X Rotation from being Transformed");
-                       uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTY, B_REDR, ICON_UNLOCKED,   125, 180, 25, 19, &(ob->protectflag), 0, 0, 0, 0, "Protects Y Rotation value from being Transformed");
-                       uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTZ, B_REDR, ICON_UNLOCKED,   125, 160, 25, 19, &(ob->protectflag), 0, 0, 0, 0, "Protects Z Rotation value from being Transformed");
-                       uiBlockEndAlign(block);
 
-               }
-               else {
-                       uiDefBut(block, LABEL, 0, "Rotation:",                                                                  0, 220, 100, 20, 0, 0, 0, 0, 0, "");
-                       uiBlockBeginAlign(block);
-                       uiDefButF(block, NUM, B_OBJECTPANELROT, "X:",                                                   0, 200, 120, 19, &(tfp->ob_eul[0]), -lim, lim, 1000, 3, "");                    
-                       uiDefButF(block, NUM, B_OBJECTPANELROT, "Y:",                                                   0, 180, 120, 19, &(tfp->ob_eul[1]), -lim, lim, 1000, 3, "");
-                       uiDefButF(block, NUM, B_OBJECTPANELROT, "Z:",                                                   0, 160, 120, 19, &(tfp->ob_eul[2]), -lim, lim, 1000, 3, "");
-                       uiBlockEndAlign(block);
-                       
-                       uiBlockBeginAlign(block);
-                       uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTX, B_REDR, ICON_UNLOCKED,   125, 200, 25, 19, &(ob->protectflag), 0, 0, 0, 0, "Protects X Rotation value from being Transformed");
-                       uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTY, B_REDR, ICON_UNLOCKED,   125, 180, 25, 19, &(ob->protectflag), 0, 0, 0, 0, "Protects Y Rotation value from being Transformed");
-                       uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTZ, B_REDR, ICON_UNLOCKED,   125, 160, 25, 19, &(ob->protectflag), 0, 0, 0, 0, "Protects Z Rotation value from being Transformed");
-                       uiBlockEndAlign(block);
-               }
-
-               tfp->ob_scale[0]= ob->size[0];
-               tfp->ob_scale[1]= ob->size[1];
-               tfp->ob_scale[2]= ob->size[2];
-
-               uiDefBut(block, LABEL, 0, "Scale:",                                                                                     0, 140, 100, 20, 0, 0, 0, 0, 0, "");
-               uiDefButS(block, OPTION, B_REDR, "Link",                                                                        60, 140, 50, 19, &(tfp->link_scale), 0, 1, 0, 0, "Scale values vary proportionally in all directions");
-               uiBlockBeginAlign(block);
-               uiDefButF(block, NUM, B_OBJECTPANELSCALE, "X:",                                                         0, 120, 120, 19, &(tfp->ob_scale[0]), -lim, lim, 10, 3, "");
-               uiDefButF(block, NUM, B_OBJECTPANELSCALE, "Y:",                                                         0, 100, 120, 19, &(tfp->ob_scale[1]), -lim, lim, 10, 3, "");
-               uiDefButF(block, NUM, B_OBJECTPANELSCALE, "Z:",                                                         0, 80, 120, 19, &(tfp->ob_scale[2]), -lim, lim, 10, 3, "");
-               uiBlockEndAlign(block);
-               
-               uiBlockBeginAlign(block);
-               uiDefIconButBitS(block, ICONTOG, OB_LOCK_SCALEX, B_REDR, ICON_UNLOCKED,         125, 120, 25, 19, &(ob->protectflag), 0, 0, 0, 0, "Protects X Scale value from being Transformed");
-               uiDefIconButBitS(block, ICONTOG, OB_LOCK_SCALEY, B_REDR, ICON_UNLOCKED,         125, 100, 25, 19, &(ob->protectflag), 0, 0, 0, 0, "Protects Y Scale value from being Transformed");
-               uiDefIconButBitS(block, ICONTOG, OB_LOCK_SCALEZ, B_REDR, ICON_UNLOCKED,         125, 80, 25, 19, &(ob->protectflag), 0, 0, 0, 0, "Protects Z Scale value from being Transformed");
-               
-               
-
-               bb= object_get_boundbox(ob);
-               if (bb) {
-                       float scale[3];
-
-                       Mat4ToSize(ob->obmat, scale);
-
-                       tfp->ob_dims[0] = fabs(scale[0]) * (bb->vec[4][0] - bb->vec[0][0]);
-                       tfp->ob_dims[1] = fabs(scale[1]) * (bb->vec[2][1] - bb->vec[0][1]);
-                       tfp->ob_dims[2] = fabs(scale[2]) * (bb->vec[1][2] - bb->vec[0][2]);
-
-                       
-                       if ((ob->parent) && (ob->partype == PARBONE)) {
-                               uiDefBut(block, LABEL, 0, "Dimensions:",                        0, 60, 100, 20, 0, 0, 0, 0, 0, "");
-                               uiBlockBeginAlign(block);
-                               uiDefButF(block, NUM, B_OBJECTPANELDIMS, "X:",          0, 40, 150, 19, &(tfp->ob_dims[0]), 0.0, lim, 10, 3, "Manipulate X bounding box size");
-                               uiDefButF(block, NUM, B_OBJECTPANELDIMS, "Y:",          0, 20, 150, 19, &(tfp->ob_dims[1]), 0.0, lim, 10, 3, "Manipulate Y bounding box size");
-                               uiDefButF(block, NUM, B_OBJECTPANELDIMS, "Z:",          0, 0, 150, 19, &(tfp->ob_dims[2]), 0.0, lim, 10, 3, "Manipulate Z bounding box size");
-
-                       }
-                       else {
-                               uiDefBut(block, LABEL, 0, "Dimensions:",                        0, 60, 100, 20, 0, 0, 0, 0, 0, "");
-                               uiBlockBeginAlign(block);
-                               uiDefButF(block, NUM, B_OBJECTPANELDIMS, "X:",          0, 40, 150, 19, &(tfp->ob_dims[0]), 0.0, lim, 10, 3, "Manipulate X bounding box size");
-                               uiDefButF(block, NUM, B_OBJECTPANELDIMS, "Y:",          0, 20, 150, 19, &(tfp->ob_dims[1]), 0.0, lim, 10, 3, "Manipulate Y bounding box size");
-                               uiDefButF(block, NUM, B_OBJECTPANELDIMS, "Z:",          0, 0, 150, 19, &(tfp->ob_dims[2]), 0.0, lim, 10, 3, "Manipulate Z bounding box size");
-                       }
-
-                       uiBlockEndAlign(block);
-               }
+               v3d_transform_butsR(col, &obptr);
        }
 }
 
@@ -1242,6 +1281,7 @@ static void view3d_panel_preview(bContext *C, ARegion *ar, short cntrl)   // VIEW3
 }
 #endif
 
+#if 0 // XXX not used
 static void delete_sketch_armature(bContext *C, void *arg1, void *arg2)
 {
        BIF_deleteSketch(C);
@@ -1258,6 +1298,7 @@ static void assign_template_sketch_armature(bContext *C, void *arg1, void *arg2)
        BIF_setTemplate(C, index);
 }
 
+
 static int view3d_panel_bonesketch_spaces_poll(const bContext *C, PanelType *pt)
 {
        Object *obedit = CTX_data_edit_object(C);
@@ -1283,7 +1324,7 @@ static void view3d_panel_bonesketch_spaces(const bContext *C, Panel *pa)
                };
 
        
-       block= uiLayoutFreeBlock(pa->layout);
+       block= uiLayoutAbsoluteBlock(pa->layout);
        uiBlockSetHandleFunc(block, do_view3d_region_buttons, NULL);
 
        uiBlockBeginAlign(block);
@@ -1374,53 +1415,6 @@ static void view3d_panel_bonesketch_spaces(const bContext *C, Panel *pa)
        uiBlockEndAlign(block);
 }
 
-#if 0 // XXX not used
-
-/* op->invoke */
-static void redo_cb(bContext *C, void *arg_op, void *arg2)
-{
-       wmOperator *lastop= arg_op;
-       
-       if(lastop) {
-               int retval;
-               
-               printf("operator redo %s\n", lastop->type->name);
-               ED_undo_pop(C);
-               retval= WM_operator_repeat(C, lastop);
-               if((retval & OPERATOR_FINISHED)==0) {
-                       printf("operator redo failed %s\n", lastop->type->name);
-                       ED_undo_redo(C);
-               }
-       }
-}
-
-static void view3d_panel_operator_redo(const bContext *C, Panel *pa)
-{
-       wmWindowManager *wm= CTX_wm_manager(C);
-       wmOperator *op;
-       PointerRNA ptr;
-       uiBlock *block;
-       
-       block= uiLayoutGetBlock(pa->layout);
-
-       /* only for operators that are registered and did an undo push */
-       for(op= wm->operators.last; op; op= op->prev)
-               if((op->type->flag & OPTYPE_REGISTER) && (op->type->flag & OPTYPE_UNDO))
-                       break;
-       
-       if(op==NULL)
-               return;
-       
-       uiBlockSetFunc(block, redo_cb, op, NULL);
-       
-       if(!op->properties) {
-               IDPropertyTemplate val = {0};
-               op->properties= IDP_New(IDP_GROUP, val, "wmOperatorProperties");
-       }
-       
-       RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
-       uiDefAutoButsRNA(C, pa->layout, &ptr, 2);
-}
 #endif // XXX not used
 
 void view3d_buttons_register(ARegionType *art)
@@ -1438,30 +1432,18 @@ void view3d_buttons_register(ARegionType *art)
        strcpy(pt->label, "Grease Pencil");
        pt->draw= gpencil_panel_standard;
        BLI_addtail(&art->paneltypes, pt);
-/*
-       pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel properties");
-       strcpy(pt->idname, "VIEW3D_PT_properties");
-       strcpy(pt->label, "View Properties");
-       pt->draw= view3d_panel_properties;
-       BLI_addtail(&art->paneltypes, pt);
 
-       pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel transform spaces");
-       strcpy(pt->idname, "VIEW3D_PT_transform spaces");
-       strcpy(pt->label, "Transform Orientations");
-       pt->draw= view3d_panel_transform_spaces;
+       pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel vgroup");
+       strcpy(pt->idname, "VIEW3D_PT_vgroup");
+       strcpy(pt->label, "Vertex Groups");
+       pt->draw= view3d_panel_vgroup;
+       pt->poll= view3d_panel_vgroup_poll;
        BLI_addtail(&art->paneltypes, pt);
 
-       pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel bonesketch spaces");
-       strcpy(pt->idname, "VIEW3D_PT_bonesketch_spaces");
-       strcpy(pt->label, "Bone Sketching");
-       pt->draw= view3d_panel_bonesketch_spaces;
-       pt->poll= view3d_panel_bonesketch_spaces_poll;
-       BLI_addtail(&art->paneltypes, pt);
-*/
        // XXX view3d_panel_preview(C, ar, 0);
 }
 
-static int view3d_properties(bContext *C, wmOperator *op)
+static int view3d_properties(bContext *C, wmOperator *UNUSED(op))
 {
        ScrArea *sa= CTX_wm_area(C);
        ARegion *ar= view3d_has_buttons_region(sa);
@@ -1475,7 +1457,7 @@ static int view3d_properties(bContext *C, wmOperator *op)
 void VIEW3D_OT_properties(wmOperatorType *ot)
 {
        ot->name= "Properties";
-       ot->description= "Toggles the properties panel display.";
+       ot->description= "Toggles the properties panel display";
        ot->idname= "VIEW3D_OT_properties";
        
        ot->exec= view3d_properties;