fix [#24499] Consistency Issue with LassoSelect/ExtendOption
[blender.git] / source / blender / editors / armature / editarmature.c
index 9f82275390bffea91979d66f4c1e13045b201a1a..cab2fdc547fe8cc52c9c89469e7bcda94677983a 100644 (file)
@@ -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) 2001-2002 by NaN Holding BV.
  * All rights reserved.
 
 #include <ctype.h>
 #include <stdlib.h>
+#include <stddef.h>
 #include <string.h>
 #include <math.h> 
 #include <float.h> 
 
-#include "MEM_guardedalloc.h"
 
 #include "DNA_anim_types.h"
-#include "DNA_action_types.h"
 #include "DNA_armature_types.h"
 #include "DNA_constraint_types.h"
-#include "DNA_ID.h"
-#include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
-#include "DNA_nla_types.h"
-#include "DNA_object_types.h"
 #include "DNA_scene_types.h"
-#include "DNA_screen_types.h"
-#include "DNA_space_types.h"
-#include "DNA_userdef_types.h"
-#include "DNA_view3d_types.h"
-#include "DNA_modifier_types.h"
-#include "DNA_ipo_types.h"
-#include "DNA_curve_types.h"
+
+#include "MEM_guardedalloc.h"
 
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
 #include "BKE_object.h"
 #include "BKE_report.h"
 #include "BKE_subsurf.h"
-#include "BKE_utildefines.h"
 #include "BKE_modifier.h"
-#include "PIL_time.h"
+#include "DNA_object_types.h"
 
 #include "BIF_gl.h"
-#include "BIF_generate.h"
 
 #include "RNA_access.h"
 #include "RNA_define.h"
@@ -88,7 +76,6 @@
 #include "ED_mesh.h"
 #include "ED_object.h"
 #include "ED_screen.h"
-#include "ED_transform.h"
 #include "ED_util.h"
 #include "ED_view3d.h"
 
 #include "reeb.h"
 #endif
 
-/* ************* XXX *************** */
-static int okee() {return 0;}
-static void BIF_undo_push(const char *msg) {}
-/* ************* XXX *************** */
-
 /* **************** tools on Editmode Armature **************** */
 
 /* Sync selection to parent for connected children */
@@ -154,7 +136,7 @@ static void bone_free(bArmature *arm, EditBone *bone)
        BLI_freelinkN(arm->edbo, bone);
 }
 
-void ED_armature_edit_bone_remove(bArmature *arm, EditBoneexBone)
+void ED_armature_edit_bone_remove(bArmature *arm, EditBone *exBone)
 {
        EditBone *curBone;
 
@@ -192,18 +174,37 @@ EditBone *make_boneList(ListBase *edbo, ListBase *bones, EditBone *parent, Bone
                eBone->flag = curBone->flag;
                
                /* fix selection flags */
+
                if (eBone->flag & BONE_SELECTED) {
+                       /* if the bone is selected the copy its root selection to the parents tip */
                        eBone->flag |= BONE_TIPSEL;
-                       if (eBone->parent && (eBone->flag & BONE_CONNECTED))
+                       if (eBone->parent && (eBone->flag & BONE_CONNECTED)) {
                                eBone->parent->flag |= BONE_TIPSEL;
-                       else 
+                               eBone->flag &= ~BONE_ROOTSEL; /* this is ignored when there is a connected parent, so unset it */
+                       }
+                       else {
                                eBone->flag |= BONE_ROOTSEL;
+                       }
                }
-               else 
-                       eBone->flag &= ~BONE_ROOTSEL;
-               
-               VECCOPY(eBone->head, curBone->arm_head);
-               VECCOPY(eBone->tail, curBone->arm_tail);                
+               else {
+                       /* if the bone is not selected, but connected to its parent
+                        *  copy the parents tip selection state */
+                       if(eBone->parent &&  (eBone->flag & BONE_CONNECTED)) {
+                               /* selecting with the mouse gives this behavior */
+                               if(eBone->parent->flag & BONE_TIPSEL) {
+                                       eBone->flag |= BONE_ROOTSEL;
+                               }
+                               else {
+                                       eBone->flag &= ~BONE_ROOTSEL;
+                               }
+
+                               /* probably not selected but just incase */
+                               eBone->flag &= ~BONE_TIPSEL;
+                       }
+               }
+
+               copy_v3_v3(eBone->head, curBone->arm_head);
+               copy_v3_v3(eBone->tail, curBone->arm_tail);             
                
                eBone->roll= 0.0f;
                
@@ -436,100 +437,95 @@ void ED_armature_apply_transform(Object *ob, float mat[4][4])
 
 /* exported for use in editors/object/ */
 /* 0 == do center, 1 == center new, 2 == center cursor */
-void docenter_armature (Scene *scene, View3D *v3d, Object *ob, int centermode)
+void docenter_armature (Scene *scene, Object *ob, float cursor[3], int centermode, int around)
 {
        Object *obedit= scene->obedit; // XXX get from context
        EditBone *ebone;
        bArmature *arm= ob->data;
-       float cent[3] = {0.0f, 0.0f, 0.0f};
-       float min[3], max[3];
-       float omat[3][3];
+       float cent[3];
 
        /* Put the armature into editmode */
-       if(ob!=obedit)
+       if(ob != obedit) {
                ED_armature_to_edit(ob);
+               obedit= NULL; /* we cant use this so behave as if there is no obedit */
+       }
 
        /* Find the centerpoint */
        if (centermode == 2) {
-               float *fp= give_cursor(scene, v3d);
-               VECCOPY(cent, fp);
+               copy_v3_v3(cent, cursor);
                invert_m4_m4(ob->imat, ob->obmat);
                mul_m4_v3(ob->imat, cent);
        }
        else {
-               INIT_MINMAX(min, max);
-               
-               for (ebone= arm->edbo->first; ebone; ebone=ebone->next) {
-                       DO_MINMAX(ebone->head, min, max);
-                       DO_MINMAX(ebone->tail, min, max);
+               if(around==V3D_CENTROID) {
+                       int total= 0;
+                       zero_v3(cent);
+                       for (ebone= arm->edbo->first; ebone; ebone=ebone->next) {
+                               total+=2;
+                               add_v3_v3(cent, ebone->head);
+                               add_v3_v3(cent, ebone->tail);
+                       }
+                       mul_v3_fl(cent, 1.0f/(float)total);
+               }
+               else {
+                       float min[3], max[3];
+                       INIT_MINMAX(min, max);
+                       for (ebone= arm->edbo->first; ebone; ebone=ebone->next) {
+                               DO_MINMAX(ebone->head, min, max);
+                               DO_MINMAX(ebone->tail, min, max);
+                       }
+                       mid_v3_v3v3(cent, min, max);
                }
-               
-               cent[0]= (min[0] + max[0]) / 2.0f;
-               cent[1]= (min[1] + max[1]) / 2.0f;
-               cent[2]= (min[2] + max[2]) / 2.0f;
        }
        
        /* Do the adjustments */
        for (ebone= arm->edbo->first; ebone; ebone=ebone->next) {
-               sub_v3_v3v3(ebone->head, ebone->head, cent);
-               sub_v3_v3v3(ebone->tail, ebone->tail, cent);
+               sub_v3_v3(ebone->head, cent);
+               sub_v3_v3(ebone->tail, cent);
        }
        
        /* Turn the list into an armature */
-       ED_armature_from_edit(ob);
-       
+       if(obedit==NULL) {
+               ED_armature_from_edit(ob);
+               ED_armature_edit_free(ob);
+       }
+
        /* Adjust object location for new centerpoint */
        if(centermode && obedit==NULL) {
-               copy_m3_m4(omat, ob->obmat);
-               
-               mul_m3_v3(omat, cent);
-               ob->loc[0] += cent[0];
-               ob->loc[1] += cent[1];
-               ob->loc[2] += cent[2];
+               mul_mat3_m4_v3(ob->obmat, cent); /* ommit translation part */
+               add_v3_v3(ob->loc, cent);
        }
-       else 
-               ED_armature_edit_free(ob);
 }
 
 /* ---------------------- */
 
-static EditBone *editbone_name_exists (ListBase *edbo, char *name)
+/* checks if an EditBone with a matching name already, returning the matching bone if it exists */
+static EditBone *editbone_name_exists (ListBase *edbo, const char *name)
 {
-       EditBone        *eBone;
-       
-       for (eBone=edbo->first; eBone; eBone=eBone->next) {
-               if (!strcmp(name, eBone->name))
-                       return eBone;
-       }
-       return NULL;
+       return BLI_findstring(edbo, name, offsetof(EditBone, name));
 }
 
 /* note: there's a unique_bone_name() too! */
 void unique_editbone_name (ListBase *edbo, char *name, EditBone *bone)
 {
        EditBone *dupli;
-       char            tempname[64];
-       int                     number;
-       char            *dot;
 
        dupli = editbone_name_exists(edbo, name);
        
        if (dupli && bone != dupli) {
-               /*      Strip off the suffix, if it's a number */
-               number= strlen(name);
-               if (number && isdigit(name[number-1])) {
-                       dot= strrchr(name, '.');        // last occurrence
-                       if (dot)
-                               *dot=0;
-               }
-               
-               for (number = 1; number <= 999; number++) {
-                       sprintf(tempname, "%s.%03d", name, number);
-                       if (!editbone_name_exists(edbo, tempname)) {
-                               BLI_strncpy(name, tempname, 32);
-                               return;
+               /* note: this block is used in other places, when changing logic apply to all others, search this message */
+               char    tempname[sizeof(bone->name)];
+               char    left[sizeof(bone->name)];
+               int             number;
+               int             len= BLI_split_name_num(left, &number, name);
+               do {    /* nested while loop looks bad but likely it wont run most times */
+                       while(BLI_snprintf(tempname, sizeof(tempname), "%s.%03d", left, number) >= sizeof(tempname)) {
+                               if(len > 0)     left[--len]= '\0';      /* word too long */
+                               else            number= 0;                      /* reset, must be a massive number */
                        }
-               }
+               } while(number++, ((dupli= editbone_name_exists(edbo, tempname)) && bone != dupli));
+
+               BLI_strncpy(name, tempname, sizeof(bone->name));
        }
 }
 
@@ -545,7 +541,7 @@ static void applyarmature_fix_boneparents (Scene *scene, Object *armob)
                        /* apply current transform from parent (not yet destroyed), 
                         * then calculate new parent inverse matrix
                         */
-                       ED_object_apply_obmat(ob);
+                       object_apply_mat4(ob, ob->obmat, FALSE);
                        
                        what_does_parent(scene, ob, &workob);
                        invert_m4_m4(ob->parentinv, workob.obmat);
@@ -557,7 +553,7 @@ static void applyarmature_fix_boneparents (Scene *scene, Object *armob)
 static int apply_armature_pose2bones_exec (bContext *C, wmOperator *op)
 {
        Scene *scene= CTX_data_scene(C);
-       Object *ob= CTX_data_active_object(C); // must be active object, not edit-object
+       Object *ob= ED_object_pose_armature(CTX_data_active_object(C)); // must be active object, not edit-object
        bArmature *arm= get_armature(ob);
        bPose *pose;
        bPoseChannel *pchan;
@@ -584,8 +580,8 @@ static int apply_armature_pose2bones_exec (bContext *C, wmOperator *op)
                curbone= editbone_name_exists(arm->edbo, pchan->name);
                
                /* simply copy the head/tail values from pchan over to curbone */
-               VECCOPY(curbone->head, pchan->pose_head);
-               VECCOPY(curbone->tail, pchan->pose_tail);
+               copy_v3_v3(curbone->head, pchan->pose_head);
+               copy_v3_v3(curbone->tail, pchan->pose_tail);
                
                /* fix roll:
                 *      1. find auto-calculated roll value for this bone now
@@ -637,12 +633,12 @@ static int apply_armature_pose2bones_exec (bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void POSE_OT_apply (wmOperatorType *ot)
+void POSE_OT_armature_apply (wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Apply Pose as Rest Pose";
-       ot->idname= "POSE_OT_apply";
-       ot->description= "Apply the current pose as the new rest pose.";
+       ot->idname= "POSE_OT_armature_apply";
+       ot->description= "Apply the current pose as the new rest pose";
        
        /* callbacks */
        ot->exec= apply_armature_pose2bones_exec;
@@ -652,6 +648,64 @@ void POSE_OT_apply (wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
+
+/* set the current pose as the restpose */
+static int pose_visual_transform_apply_exec (bContext *C, wmOperator *UNUSED(op))
+{
+       Scene *scene= CTX_data_scene(C);
+       Object *ob= ED_object_pose_armature(CTX_data_active_object(C)); // must be active object, not edit-object
+
+       /* don't check if editmode (should be done by caller) */
+       if (ob->type!=OB_ARMATURE)
+               return OPERATOR_CANCELLED;
+
+       /* loop over all selected pchans
+        *
+        * TODO, loop over children before parents if multiple bones
+        * at once are to be predictable*/
+       CTX_DATA_BEGIN(C, bPoseChannel *, pchan, selected_pose_bones)
+       {
+               float delta_mat[4][4], imat[4][4], mat[4][4];
+
+               where_is_pose_bone(scene, ob, pchan, CFRA, 1);
+
+               copy_m4_m4(mat, pchan->pose_mat);
+
+               /* calculate pchan->pose_mat without loc/size/rot & constraints applied */
+               where_is_pose_bone(scene, ob, pchan, CFRA, 0);
+               invert_m4_m4(imat, pchan->pose_mat);
+               mul_m4_m4m4(delta_mat, mat, imat);
+
+               pchan_apply_mat4(pchan, delta_mat, TRUE);
+
+               where_is_pose_bone(scene, ob, pchan, CFRA, 1);
+       }
+       CTX_DATA_END;
+
+       // ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK);
+       DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
+
+       /* note, notifier might evolve */
+       WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob);
+
+       return OPERATOR_FINISHED;
+}
+
+void POSE_OT_visual_transform_apply (wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Apply Visual Transform to Pose";
+       ot->idname= "POSE_OT_visual_transform_apply";
+       ot->description= "Apply final constrained position of pose bones to their transform.";
+       
+       /* callbacks */
+       ot->exec= pose_visual_transform_apply_exec;
+       ot->poll= ED_operator_posemode;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
 /* ---------------------- */
 
 /* Helper function for armature joining - link fixing */
@@ -758,8 +812,9 @@ static void joined_armature_fix_links(Object *tarArm, Object *srcArm, bPoseChann
 }
 
 /* join armature exec is exported for use in object->join objects operator... */
-int join_armature_exec(bContext *C, wmOperator *op)
+int join_armature_exec(bContext *C, wmOperator *UNUSED(op))
 {
+       Main *bmain= CTX_data_main(C);
        Scene *scene= CTX_data_scene(C);
        Object  *ob= CTX_data_active_object(C);
        bArmature *arm= (ob)? ob->data: NULL;
@@ -848,14 +903,16 @@ int join_armature_exec(bContext *C, wmOperator *op)
                                
                                BLI_remlink(&opose->chanbase, pchan);
                                BLI_addtail(&pose->chanbase, pchan);
+                               free_pose_channels_hash(opose);
+                               free_pose_channels_hash(pose);
                        }
                        
-                       ED_base_object_free_and_unlink(scene, base);
+                       ED_base_object_free_and_unlink(bmain, scene, base);
                }
        }
        CTX_DATA_END;
        
-       DAG_scene_sort(scene);  // because we removed object(s)
+       DAG_scene_sort(bmain, scene);   // because we removed object(s)
 
        ED_armature_from_edit(ob);
        ED_armature_edit_free(ob);
@@ -1013,7 +1070,7 @@ static void separated_armature_fix_links(Object *origArm, Object *newArm)
  *     sel: remove selected bones from the armature, otherwise the unselected bones are removed
  *  (ob is not in editmode)
  */
-static void separate_armature_bones (Scene *scene, Object *ob, short sel) 
+static void separate_armature_bones(Object *ob, short sel) 
 {
        bArmature *arm= (bArmature *)ob->data;
        bPoseChannel *pchan, *pchann;
@@ -1051,6 +1108,7 @@ static void separate_armature_bones (Scene *scene, Object *ob, short sel)
                        
                        /* free any of the extra-data this pchan might have */
                        free_pose_channel(pchan);
+                       free_pose_channels_hash(ob->pose);
                        
                        /* get rid of unneeded bone */
                        bone_free(arm, curbone);
@@ -1064,8 +1122,9 @@ static void separate_armature_bones (Scene *scene, Object *ob, short sel)
 }
 
 /* separate selected bones into their armature */
-static int separate_armature_exec (bContext *C, wmOperator *op)
+static int separate_armature_exec (bContext *C, wmOperator *UNUSED(op))
 {
+       Main *bmain= CTX_data_main(C);
        Scene *scene= CTX_data_scene(C);
        Object *obedit= CTX_data_edit_object(C);
        Object *oldob, *newob;
@@ -1106,14 +1165,14 @@ static int separate_armature_exec (bContext *C, wmOperator *op)
        ED_armature_edit_free(obedit);
        
        /* 2) duplicate base */
-       newbase= ED_object_add_duplicate(scene, oldbase, USER_DUP_ARM); /* only duplicate linked armature */
+       newbase= ED_object_add_duplicate(bmain, scene, oldbase, USER_DUP_ARM); /* only duplicate linked armature */
        newob= newbase->object;         
        newbase->flag &= ~SELECT;
        
        
        /* 3) remove bones that shouldn't still be around on both armatures */
-       separate_armature_bones(scene, oldob, 1);
-       separate_armature_bones(scene, newob, 0);
+       separate_armature_bones(oldob, 1);
+       separate_armature_bones(newob, 0);
        
        
        /* 4) fix links before depsgraph flushes */ // err... or after?
@@ -1142,7 +1201,7 @@ void ARMATURE_OT_separate (wmOperatorType *ot)
        /* identifiers */
        ot->name= "Separate Bones";
        ot->idname= "ARMATURE_OT_separate";
-       ot->description= "Isolate selected bones into a separate armature.";
+       ot->description= "Isolate selected bones into a separate armature";
        
        /* callbacks */
        ot->invoke= WM_operator_confirm;
@@ -1300,8 +1359,9 @@ static EditBone *editbone_get_child(bArmature *arm, EditBone *pabone, short use_
        for (curbone= arm->edbo->first; curbone; curbone= curbone->next) {
                if (curbone->parent == pabone) {
                        if (use_visibility) {
-                               if ((arm->layer & curbone->layer) && !(pabone->flag & BONE_HIDDEN_A))
+                               if ((arm->layer & curbone->layer) && !(pabone->flag & BONE_HIDDEN_A)) {
                                        chbone = curbone;
+                               }
                        }
                        else
                                chbone = curbone;
@@ -1325,7 +1385,7 @@ static int pose_setflag_exec (bContext *C, wmOperator *op)
        CTX_DATA_END;
        
        /* note, notifier might evolve */
-       WM_event_add_notifier(C, NC_OBJECT|ND_POSE, CTX_data_active_object(C));
+       WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ED_object_pose_armature(CTX_data_active_object(C)));
        
        return OPERATOR_FINISHED;
 }
@@ -1374,7 +1434,7 @@ void ARMATURE_OT_flags_set (wmOperatorType *ot)
        /* identifiers */
        ot->name= "Set Bone Flags";
        ot->idname= "ARMATURE_OT_flags_set";
-       ot->description= "Set flags for armature bones.";
+       ot->description= "Set flags for armature bones";
        
        /* callbacks */
        ot->invoke= WM_menu_invoke;
@@ -1394,7 +1454,7 @@ void POSE_OT_flags_set (wmOperatorType *ot)
        /* identifiers */
        ot->name= "Set Bone Flags";
        ot->idname= "POSE_OT_flags_set";
-       ot->description= "Set flags for armature bones.";
+       ot->description= "Set flags for armature bones";
        
        /* callbacks */
        ot->invoke= WM_menu_invoke;
@@ -1707,9 +1767,8 @@ EditBone *ED_armature_bone_get_mirrored(ListBase *edbo, EditBone *ebo)
        
        if (ebo == NULL)
                return NULL;
-       
-       BLI_strncpy(name, ebo->name, sizeof(name));
-       bone_flip_name(name, 0);                // 0 = don't strip off number extensions
+
+       flip_side_name(name, ebo->name, FALSE);
        
        for (eboflip= edbo->first; eboflip; eboflip=eboflip->next) {
                if (ebo != eboflip) {
@@ -1724,7 +1783,7 @@ EditBone *ED_armature_bone_get_mirrored(ListBase *edbo, EditBone *ebo)
 
 /* previously delete_armature */
 /* only editmode! */
-static int armature_delete_selected_exec(bContext *C, wmOperator *op)
+static int armature_delete_selected_exec(bContext *C, wmOperator *UNUSED(op))
 {
        bArmature *arm;
        EditBone        *curBone, *next;
@@ -1758,6 +1817,7 @@ static int armature_delete_selected_exec(bContext *C, wmOperator *op)
                        
                        if (curBone && (curBone->flag & BONE_SELECTED) && (arm->layer & curBone->layer)) {
                                free_pose_channel(pchan);
+                               free_pose_channels_hash(obedit->pose);
                                BLI_freelinkN (&obedit->pose->chanbase, pchan);
                        }
                        else {
@@ -1828,7 +1888,7 @@ void ARMATURE_OT_delete(wmOperatorType *ot)
  * toggle==2: only active tag
  * toggle==3: swap (no test)
  */
-void ED_armature_deselectall(Object *obedit, int toggle, int doundo)
+void ED_armature_deselect_all(Object *obedit, int toggle)
 {
        bArmature *arm= obedit->data;
        EditBone        *eBone;
@@ -1855,7 +1915,7 @@ void ED_armature_deselectall(Object *obedit, int toggle, int doundo)
                for (eBone=arm->edbo->first;eBone;eBone=eBone->next) {
                        if (sel==3) {
                                /* invert selection of bone */
-                               if ((arm->layer & eBone->layer) && (eBone->flag & BONE_HIDDEN_A)==0) {
+                               if(EBONE_VISIBLE(arm, eBone)) {
                                        eBone->flag ^= (BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
                                        if(arm->act_edbone==eBone)
                                                arm->act_edbone= NULL;
@@ -1863,7 +1923,7 @@ void ED_armature_deselectall(Object *obedit, int toggle, int doundo)
                        }
                        else if (sel==1) {
                                /* select bone */
-                               if(arm->layer & eBone->layer && (eBone->flag & BONE_HIDDEN_A)==0) {
+                               if(EBONE_VISIBLE(arm, eBone)) {
                                        eBone->flag |= (BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
                                        if(eBone->parent)
                                                eBone->parent->flag |= (BONE_TIPSEL);
@@ -1879,12 +1939,22 @@ void ED_armature_deselectall(Object *obedit, int toggle, int doundo)
        }
        
        ED_armature_sync_selection(arm->edbo);
-       if (doundo) {
-               if (sel==1) BIF_undo_push("Select All");
-               else BIF_undo_push("Deselect All");
-       }
 }
 
+void ED_armature_deselect_all_visible(Object *obedit)
+{
+       bArmature *arm= obedit->data;
+       EditBone        *ebone;
+
+       for (ebone= arm->edbo->first; ebone; ebone= ebone->next) {
+               /* first and foremost, bone must be visible and selected */
+               if (EBONE_VISIBLE(arm, ebone) && (ebone->flag & BONE_UNSELECTABLE)==0) {
+                       ebone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
+               }
+       }
+
+       ED_armature_sync_selection(arm->edbo);
+}
 
 /* context: editmode armature in view3d */
 int mouse_armature(bContext *C, short mval[2], int extend)
@@ -1903,10 +1973,10 @@ int mouse_armature(bContext *C, short mval[2], int extend)
        if (nearBone) {
 
                if (!extend)
-                       ED_armature_deselectall(obedit, 0, 0);
+                       ED_armature_deselect_all(obedit, 0);
                
                /* by definition the non-root connected bones have no root point drawn,
-              so a root selection needs to be delivered to the parent tip */
+                  so a root selection needs to be delivered to the parent tip */
                
                if(selmask & BONE_SELECTED) {
                        if(nearBone->parent && (nearBone->flag & BONE_CONNECTED)) {
@@ -1981,21 +2051,11 @@ void ED_armature_edit_free(struct Object *ob)
 
                        BLI_freelistN(arm->edbo);
                }
-
                MEM_freeN(arm->edbo);
                arm->edbo= NULL;
        }
 }
 
-void ED_armature_edit_remake(Object *obedit)
-{
-       if(okee("Reload original data")==0) return;
-       
-       ED_armature_to_edit(obedit);
-       
-//     BIF_undo_push("Delete bone");
-}
-
 /* Put armature in EditMode */
 void ED_armature_to_edit(Object *ob)
 {
@@ -2021,7 +2081,7 @@ float ED_rollBoneToVector(EditBone *bone, float new_up_axis[3])
        sub_v3_v3v3(nor, bone->tail, bone->head);
        
        vec_roll_to_mat3(nor, 0, mat);
-       VECCOPY(up_axis, mat[2]);
+       copy_v3_v3(up_axis, mat[2]);
        
        roll = angle_normalized_v3v3(new_up_axis, up_axis);
        
@@ -2037,7 +2097,7 @@ float ED_rollBoneToVector(EditBone *bone, float new_up_axis[3])
 
 
 /* Set roll value for given bone -> Z-Axis Point up (original method) */
-static void auto_align_ebone_zaxisup(Scene *scene, View3D *v3d, EditBone *ebone)
+static void auto_align_ebone_zaxisup(Scene *UNUSED(scene), View3D *UNUSED(v3d), EditBone *ebone)
 {
        float   delta[3], curmat[3][3];
        float   xaxis[3]={1.0f, 0.0f, 0.0f}, yaxis[3], zaxis[3]={0.0f, 0.0f, 1.0f};
@@ -2048,12 +2108,12 @@ static void auto_align_ebone_zaxisup(Scene *scene, View3D *v3d, EditBone *ebone)
        vec_roll_to_mat3(delta, 0.0f, curmat);
        
        /* Make new matrix based on y axis & z-up */
-       VECCOPY(yaxis, curmat[1]);
+       copy_v3_v3(yaxis, curmat[1]);
        
        unit_m3(targetmat);
-       VECCOPY(targetmat[0], xaxis);
-       VECCOPY(targetmat[1], yaxis);
-       VECCOPY(targetmat[2], zaxis);
+       copy_v3_v3(targetmat[0], xaxis);
+       copy_v3_v3(targetmat[1], yaxis);
+       copy_v3_v3(targetmat[2], zaxis);
        normalize_m3(targetmat);
        
        /* Find the difference between the two matrices */
@@ -2076,7 +2136,7 @@ void auto_align_ebone_topoint(EditBone *ebone, float *cursor)
        sub_v3_v3v3(delta, ebone->tail, ebone->head);
        vec_roll_to_mat3(delta, ebone->roll, curmat);
        copy_m4_m3(mat, curmat);
-       VECCOPY(mat[3], ebone->head);
+       copy_v3_v3(mat[3], ebone->head);
        
        /* multiply bone-matrix by object matrix (so that bone-matrix is in WorldSpace) */
        invert_m4_m4(imat, mat);
@@ -2195,6 +2255,8 @@ static void undoBones_to_editBones(void *uarmv, void *armv)
                ebo= uarm->act_edbone;
                arm->act_edbone= ebo->temp;
        }
+       else
+               arm->act_edbone= NULL;
 
        /* set pointers */
        for(newebo= arm->edbo->first; newebo; newebo= newebo->next) {
@@ -2295,12 +2357,10 @@ void add_primitive_bone(Scene *scene, View3D *v3d, RegionView3D *rv3d)
        Object *obedit= scene->obedit; // XXX get from context
        float           obmat[3][3], curs[3], viewmat[3][3], totmat[3][3], imat[3][3];
        EditBone        *bone;
-       
-       VECCOPY(curs, give_cursor(scene, v3d)); 
 
        /* Get inverse point for head and orientation for tail */
        invert_m4_m4(obedit->imat, obedit->obmat);
-       mul_m4_v3(obedit->imat, curs);
+       mul_v3_m4v3(curs, obedit->imat, give_cursor(scene, v3d));
 
        if (rv3d && (U.flag & USER_ADD_VIEWALIGNED))
                copy_m3_m4(obmat, rv3d->viewmat);
@@ -2310,12 +2370,12 @@ void add_primitive_bone(Scene *scene, View3D *v3d, RegionView3D *rv3d)
        mul_m3_m3m3(totmat, obmat, viewmat);
        invert_m3_m3(imat, totmat);
        
-       ED_armature_deselectall(obedit, 0, 0);
+       ED_armature_deselect_all(obedit, 0);
        
        /*      Create a bone   */
        bone= ED_armature_edit_bone_add(obedit->data, "Bone");
 
-       VECCOPY(bone->head, curs);
+       copy_v3_v3(bone->head, curs);
        
        if (rv3d && (U.flag & USER_ADD_VIEWALIGNED))
                add_v3_v3v3(bone->tail, bone->head, imat[1]);   // bone with unit length 1
@@ -2327,7 +2387,7 @@ void add_primitive_bone(Scene *scene, View3D *v3d, RegionView3D *rv3d)
 
 /* previously addvert_armature */
 /* the ctrl-click method */
-static int armature_click_extrude_exec(bContext *C, wmOperator *op)
+static int armature_click_extrude_exec(bContext *C, wmOperator *UNUSED(op))
 {
        View3D *v3d;
        bArmature *arm;
@@ -2363,7 +2423,7 @@ static int armature_click_extrude_exec(bContext *C, wmOperator *op)
                to_root= 1;
        }
        
-       ED_armature_deselectall(obedit, 0, 0);
+       ED_armature_deselect_all(obedit, 0);
        
        /* we re-use code for mirror editing... */
        flipbone= NULL;
@@ -2383,19 +2443,19 @@ static int armature_click_extrude_exec(bContext *C, wmOperator *op)
                arm->act_edbone= newbone;
                
                if (to_root) {
-                       VECCOPY(newbone->head, ebone->head);
+                       copy_v3_v3(newbone->head, ebone->head);
                        newbone->rad_head= ebone->rad_tail;
                        newbone->parent= ebone->parent;
                }
                else {
-                       VECCOPY(newbone->head, ebone->tail);
+                       copy_v3_v3(newbone->head, ebone->tail);
                        newbone->rad_head= ebone->rad_tail;
                        newbone->parent= ebone;
                        newbone->flag |= BONE_CONNECTED;
                }
                
                curs= give_cursor(scene, v3d);
-               VECCOPY(newbone->tail, curs);
+               copy_v3_v3(newbone->tail, curs);
                sub_v3_v3v3(newbone->tail, newbone->tail, obedit->obmat[3]);
                
                if (a==1) 
@@ -2439,7 +2499,7 @@ static int armature_click_extrude_invoke(bContext *C, wmOperator *op, wmEvent *e
        
        fp= give_cursor(scene, v3d);
        
-       VECCOPY(oldcurs, fp);
+       copy_v3_v3(oldcurs, fp);
        
        mx= event->x - ar->winrct.xmin;
        my= event->y - ar->winrct.ymin;
@@ -2469,7 +2529,7 @@ static int armature_click_extrude_invoke(bContext *C, wmOperator *op, wmEvent *e
        retv= armature_click_extrude_exec(C, op);
 
        /* restore previous 3d cursor position */
-       VECCOPY(fp, oldcurs);
+       copy_v3_v3(fp, oldcurs);
 
        return retv;
 }
@@ -2498,8 +2558,8 @@ static EditBone *add_points_bone (Object *obedit, float head[], float tail[])
        
        ebo= ED_armature_edit_bone_add(obedit->data, "Bone");
        
-       VECCOPY(ebo->head, head);
-       VECCOPY(ebo->tail, tail);
+       copy_v3_v3(ebo->head, head);
+       copy_v3_v3(ebo->tail, tail);
        
        return ebo;
 }
@@ -2641,7 +2701,7 @@ EditBone *duplicateEditBone(EditBone *curBone, char *name, ListBase *editbones,
 }
 
 /* previously adduplicate_armature */
-static int armature_duplicate_selected_exec(bContext *C, wmOperator *op)
+static int armature_duplicate_selected_exec(bContext *C, wmOperator *UNUSED(op))
 {
        bArmature *arm;
        EditBone        *eBone = NULL;
@@ -2826,10 +2886,10 @@ static void fill_add_joint (EditBone *ebo, short eb_tail, ListBase *points)
        short found= 0;
        
        if (eb_tail) {
-               VECCOPY(vec, ebo->tail);
+               copy_v3_v3(vec, ebo->tail);
        }
        else {
-               VECCOPY(vec, ebo->head);
+               copy_v3_v3(vec, ebo->head);
        }
        
        for (ebp= points->first; ebp; ebp= ebp->next) {
@@ -2858,11 +2918,11 @@ static void fill_add_joint (EditBone *ebo, short eb_tail, ListBase *points)
                ebp= MEM_callocN(sizeof(EditBonePoint), "EditBonePoint");
                
                if (eb_tail) {
-                       VECCOPY(ebp->vec, ebo->tail);
+                       copy_v3_v3(ebp->vec, ebo->tail);
                        ebp->tail_owner= ebo;
                }
                else {
-                       VECCOPY(ebp->vec, ebo->head);
+                       copy_v3_v3(ebp->vec, ebo->head);
                        ebp->head_owner= ebo;
                }
                
@@ -2908,17 +2968,14 @@ static int armature_fill_bones_exec (bContext *C, wmOperator *op)
        }
        else if (count == 1) {
                EditBonePoint *ebp;
-               float *fp, curs[3];
+               float curs[3];
                
                /* Get Points - selected joint */
                ebp= (EditBonePoint *)points.first;
                
                /* Get points - cursor (tail) */
-               fp= give_cursor(scene, v3d);
-               VECCOPY (curs, fp);     
-               
                invert_m4_m4(obedit->imat, obedit->obmat);
-               mul_m4_v3(obedit->imat, curs);
+               mul_v3_m4v3(curs, obedit->imat, give_cursor(scene, v3d));
                
                /* Create a bone */
                newbone= add_points_bone(obedit, ebp->vec, curs);
@@ -2946,15 +3003,13 @@ static int armature_fill_bones_exec (bContext *C, wmOperator *op)
                /* find which one should be the 'head' */
                if ((ebp->head_owner && ebp2->head_owner) || (ebp->tail_owner && ebp2->tail_owner)) {
                        /* rule: whichever one is closer to 3d-cursor */
-                       float curs[3], *fp= give_cursor(scene, v3d);
+                       float curs[3];
                        float vecA[3], vecB[3];
                        float distA, distB;
                        
                        /* get cursor location */
-                       VECCOPY(curs, fp);      
-                       
                        invert_m4_m4(obedit->imat, obedit->obmat);
-                       mul_m4_v3(obedit->imat, curs);
+                       mul_v3_m4v3(curs, obedit->imat, give_cursor(scene, v3d));
                        
                        /* get distances */
                        sub_v3_v3v3(vecA, ebp->vec, curs);
@@ -2974,12 +3029,12 @@ static int armature_fill_bones_exec (bContext *C, wmOperator *op)
                
                /* assign head/tail combinations */
                if (headtail == 2) {
-                       VECCOPY(head, ebp->vec);
-                       VECCOPY(tail, ebp2->vec);
+                       copy_v3_v3(head, ebp->vec);
+                       copy_v3_v3(tail, ebp2->vec);
                }
                else if (headtail == 1) {
-                       VECCOPY(head, ebp2->vec);
-                       VECCOPY(tail, ebp->vec);
+                       copy_v3_v3(head, ebp2->vec);
+                       copy_v3_v3(tail, ebp->vec);
                }
                
                /* add new bone and parent it to the appropriate end */
@@ -3012,6 +3067,9 @@ static int armature_fill_bones_exec (bContext *C, wmOperator *op)
                return OPERATOR_CANCELLED;
        }
        
+       /* updates */
+       WM_event_add_notifier(C, NC_OBJECT|ND_POSE, obedit);
+       
        /* free points */
        BLI_freelistN(&points);
        
@@ -3023,7 +3081,7 @@ void ARMATURE_OT_fill (wmOperatorType *ot)
        /* identifiers */
        ot->name= "Fill Between Joints";
        ot->idname= "ARMATURE_OT_fill";
-       ot->description= "Add bone between selected joint(s) and/or 3D-Cursor.";
+       ot->description= "Add bone between selected joint(s) and/or 3D-Cursor";
        
        /* callbacks */
        ot->exec= armature_fill_bones_exec;
@@ -3059,16 +3117,16 @@ static void bones_merge(Object *obedit, EditBone *start, EditBone *end, EditBone
         *      - parent = parent of start
         */
        if ((start->flag & BONE_TIPSEL) && ((start->flag & BONE_SELECTED) || start==arm->act_edbone)==0) {
-               VECCOPY(head, start->tail);
+               copy_v3_v3(head, start->tail);
        }
        else {
-               VECCOPY(head, start->head);
+               copy_v3_v3(head, start->head);
        }
        if ((end->flag & BONE_ROOTSEL) && ((end->flag & BONE_SELECTED) || end==arm->act_edbone)==0) {
-               VECCOPY(tail, end->head);
+               copy_v3_v3(tail, end->head);
        }
        else {
-               VECCOPY(tail, end->tail);
+               copy_v3_v3(tail, end->tail);
        }
        newbone= add_points_bone(obedit, head, tail);
        newbone->parent = start->parent;
@@ -3076,8 +3134,8 @@ static void bones_merge(Object *obedit, EditBone *start, EditBone *end, EditBone
        /* step 2a: parent children of in-between bones to newbone */
        for (chain= chains->first; chain; chain= chain->next) {
                /* ick: we need to check if parent of each bone in chain is one of the bones in the */
+               short found= 0;
                for (ebo= chain->data; ebo; ebo= ebo->parent) {
-                       short found= 0;
                        
                        /* try to find which bone from the list to be removed, is the parent */
                        for (ebone= end; ebone; ebone= ebone->parent) {
@@ -3093,6 +3151,9 @@ static void bones_merge(Object *obedit, EditBone *start, EditBone *end, EditBone
                                break;
                        }
                }
+               if (found) {
+                       break;
+               }
        }
        
        /* step 2b: parent child of end to newbone (child from this chain) */
@@ -3104,6 +3165,9 @@ static void bones_merge(Object *obedit, EditBone *start, EditBone *end, EditBone
                ebone= (ebo == start) ? (NULL) : (ebo->parent);
                bone_free(arm, ebo);
        }
+       
+       newbone->flag |= (BONE_ROOTSEL|BONE_TIPSEL|BONE_SELECTED);
+       ED_armature_sync_selection(arm->edbo);
 }
 
 
@@ -3191,7 +3255,7 @@ void ARMATURE_OT_merge (wmOperatorType *ot)
        /* identifiers */
        ot->name= "Merge Bones";
        ot->idname= "ARMATURE_OT_merge";
-       ot->description= "Merge continuous chains of selected bones.";
+       ot->description= "Merge continuous chains of selected bones";
        
        /* callbacks */
        ot->invoke= WM_menu_invoke;
@@ -3208,6 +3272,81 @@ void ARMATURE_OT_merge (wmOperatorType *ot)
 /* ************** END Add/Remove stuff in editmode ************ */
 /* *************** Tools in editmode *********** */
 
+static int armature_hide_exec(bContext *C, wmOperator *UNUSED(op))
+{
+       Object *obedit= CTX_data_edit_object(C);
+       bArmature *arm= obedit->data;
+       EditBone *ebone;
+
+       /* cancel if nothing selected */
+       if (CTX_DATA_COUNT(C, selected_bones) == 0)
+               return OPERATOR_CANCELLED;
+
+       for (ebone = arm->edbo->first; ebone; ebone=ebone->next) {
+               if (EBONE_VISIBLE(arm, ebone)) {
+                       if (ebone->flag & BONE_SELECTED) {
+                               ebone->flag &= ~(BONE_TIPSEL|BONE_SELECTED|BONE_ROOTSEL);
+                               ebone->flag |= BONE_HIDDEN_A;
+                       }
+               }
+       }
+       ED_armature_validate_active(arm);
+       ED_armature_sync_selection(arm->edbo);
+
+       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
+
+       return OPERATOR_FINISHED;
+}
+
+void ARMATURE_OT_hide(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Hide Selected Bones";
+       ot->idname= "ARMATURE_OT_hide";
+       
+       /* api callbacks */
+       ot->exec= armature_hide_exec;
+       ot->poll= ED_operator_editarmature;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+static int armature_reveal_exec(bContext *C, wmOperator *UNUSED(op))
+{
+       Object *obedit= CTX_data_edit_object(C);
+       bArmature *arm= obedit->data;
+       EditBone *ebone;
+       
+       for (ebone = arm->edbo->first; ebone; ebone=ebone->next) {
+               if(arm->layer & ebone->layer) {
+                       if (ebone->flag & BONE_HIDDEN_A) {
+                               ebone->flag |= (BONE_TIPSEL|BONE_SELECTED|BONE_ROOTSEL);
+                               ebone->flag &= ~BONE_HIDDEN_A;
+                       }
+               }
+       }
+       ED_armature_validate_active(arm);
+       ED_armature_sync_selection(arm->edbo);
+
+       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
+
+       return OPERATOR_FINISHED;
+}
+
+void ARMATURE_OT_reveal(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Reveal Bones";
+       ot->idname= "ARMATURE_OT_reveal";
+       
+       /* api callbacks */
+       ot->exec= armature_reveal_exec;
+       ot->poll= ED_operator_editarmature;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
 
 void hide_selected_armature_bones(Scene *scene)
 {
@@ -3225,7 +3364,6 @@ void hide_selected_armature_bones(Scene *scene)
        }
        ED_armature_validate_active(arm);
        ED_armature_sync_selection(arm->edbo);
-       BIF_undo_push("Hide Bones");
 }
 
 
@@ -3248,7 +3386,6 @@ static void hide_unselected_armature_bones(Scene *scene)
 
        ED_armature_validate_active(arm);
        ED_armature_sync_selection(arm->edbo);
-       BIF_undo_push("Hide Unselected Bones");
 }
 #endif
 
@@ -3269,7 +3406,6 @@ void show_all_armature_bones(Scene *scene)
        }
        ED_armature_validate_active(arm);
        ED_armature_sync_selection(arm->edbo);
-       BIF_undo_push("Reveal Bones");
 }
 #endif
 
@@ -3340,8 +3476,8 @@ static int armature_extrude_exec(bContext *C, wmOperator *op)
                                        newbone = MEM_callocN(sizeof(EditBone), "extrudebone");
                                        
                                        if (do_extrude==1) {
-                                               VECCOPY (newbone->head, ebone->tail);
-                                               VECCOPY (newbone->tail, newbone->head);
+                                               copy_v3_v3(newbone->head, ebone->tail);
+                                               copy_v3_v3(newbone->tail, newbone->head);
                                                newbone->parent = ebone;
                                                
                                                newbone->flag = ebone->flag & BONE_TIPSEL;      // copies it, in case mirrored bone
@@ -3349,8 +3485,8 @@ static int armature_extrude_exec(bContext *C, wmOperator *op)
                                                if (newbone->parent) newbone->flag |= BONE_CONNECTED;
                                        }
                                        else {
-                                               VECCOPY(newbone->head, ebone->head);
-                                               VECCOPY(newbone->tail, ebone->head);
+                                               copy_v3_v3(newbone->head, ebone->head);
+                                               copy_v3_v3(newbone->tail, ebone->head);
                                                newbone->parent= ebone->parent;
                                                
                                                newbone->flag= BONE_TIPSEL;
@@ -3440,7 +3576,7 @@ static int armature_bone_primitive_add_exec(bContext *C, wmOperator *op)
        
        RNA_string_get(op->ptr, "name", name);
        
-       VECCOPY(curs, give_cursor(CTX_data_scene(C),CTX_wm_view3d(C))); 
+       copy_v3_v3(curs, give_cursor(CTX_data_scene(C),CTX_wm_view3d(C)));      
 
        /* Get inverse point for head and orientation for tail */
        invert_m4_m4(obedit->imat, obedit->obmat);
@@ -3454,12 +3590,12 @@ static int armature_bone_primitive_add_exec(bContext *C, wmOperator *op)
        mul_m3_m3m3(totmat, obmat, viewmat);
        invert_m3_m3(imat, totmat);
        
-       ED_armature_deselectall(obedit, 0, 0);
+       ED_armature_deselect_all(obedit, 0);
        
        /*      Create a bone   */
        bone= ED_armature_edit_bone_add(obedit->data, name);
 
-       VECCOPY(bone->head, curs);
+       copy_v3_v3(bone->head, curs);
        
        if(rv3d && (U.flag & USER_ADD_VIEWALIGNED))
                add_v3_v3v3(bone->tail, bone->head, imat[1]);   // bone with unit length 1
@@ -3506,10 +3642,7 @@ static int armature_subdivide_exec(bContext *C, wmOperator *op)
        int numcuts, i;
        
        /* there may not be a number_cuts property defined (for 'simple' subdivide) */
-       if (RNA_property_is_set(op->ptr, "number_cuts"))
-               numcuts= RNA_int_get(op->ptr, "number_cuts");
-       else
-               numcuts= 1;
+       numcuts= RNA_int_get(op->ptr, "number_cuts");
        
        /* loop over all editable bones */
        // XXX the old code did this in reverse order though!
@@ -3529,17 +3662,17 @@ static int armature_subdivide_exec(bContext *C, wmOperator *op)
                        BLI_addtail(arm->edbo, newbone);
                        
                        /* calculate location of newbone->head */
-                       VECCOPY(val1, ebone->head);
-                       VECCOPY(val2, ebone->tail);
-                       VECCOPY(val3, newbone->head);
+                       copy_v3_v3(val1, ebone->head);
+                       copy_v3_v3(val2, ebone->tail);
+                       copy_v3_v3(val3, newbone->head);
                        
                        val3[0]= val1[0]*cutratio + val2[0]*cutratioI;
                        val3[1]= val1[1]*cutratio + val2[1]*cutratioI;
                        val3[2]= val1[2]*cutratio + val2[2]*cutratioI;
                        
-                       VECCOPY(newbone->head, val3);
-                       VECCOPY(newbone->tail, ebone->tail);
-                       VECCOPY(ebone->tail, newbone->head);
+                       copy_v3_v3(newbone->head, val3);
+                       copy_v3_v3(newbone->tail, ebone->tail);
+                       copy_v3_v3(ebone->tail, newbone->head);
                        
                        newbone->rad_head= 0.5f * (ebone->rad_head + ebone->rad_tail);
                        ebone->rad_tail= newbone->rad_head;
@@ -3564,26 +3697,11 @@ static int armature_subdivide_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-
-void ARMATURE_OT_subdivide_simple(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Subdivide Simple";
-       ot->idname= "ARMATURE_OT_subdivide_simple";
-       
-       /* api callbacks */
-       ot->exec = armature_subdivide_exec;
-       ot->poll = ED_operator_editarmature;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-}
-
-void ARMATURE_OT_subdivide_multi(wmOperatorType *ot)
+void ARMATURE_OT_subdivide(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Subdivide Multi";
-       ot->idname= "ARMATURE_OT_subdivide_multi";
+       ot->idname= "ARMATURE_OT_subdivide";
        
        /* api callbacks */
        ot->exec = armature_subdivide_exec;
@@ -3593,65 +3711,7 @@ void ARMATURE_OT_subdivide_multi(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* Properties */
-       RNA_def_int(ot->srna, "number_cuts", 2, 1, INT_MAX, "Number of Cuts", "", 1, 10);
-}
-
-
-
-static int armature_subdivs_invoke(bContext *C, wmOperator *op, wmEvent *event)
-{
-       uiPopupMenu *pup;
-       uiLayout *layout;
-
-       pup= uiPupMenuBegin(C, "Subdivision Type", 0);
-       layout= uiPupMenuLayout(pup);
-       uiItemsEnumO(layout, "ARMATURE_OT_subdivs", "type");
-       uiPupMenuEnd(C, pup);
-       
-       return OPERATOR_CANCELLED;
-}
-
-static int armature_subdivs_exec(bContext *C, wmOperator *op)
-{      
-       switch (RNA_int_get(op->ptr, "type"))
-       {
-               case 0: /* simple */
-                       RNA_int_set(op->ptr, "number_cuts", 1);
-                       armature_subdivide_exec(C, op);
-                       break;
-               case 1: /* multi */
-                       armature_subdivide_exec(C, op);
-                       break;
-       }
-       
-       return OPERATOR_FINISHED;
-}
-
-void ARMATURE_OT_subdivs(wmOperatorType *ot)
-{
-       static EnumPropertyItem type_items[]= {
-               {0, "SIMPLE", 0, "Simple", ""},
-               {1, "MULTI", 0, "Multi", ""},
-               {0, NULL, 0, NULL, NULL}};
-
-       /* identifiers */
-       ot->name= "subdivs";
-       ot->idname= "ARMATURE_OT_subdivs";
-       
-       /* api callbacks */
-       ot->invoke= armature_subdivs_invoke;
-       ot->exec= armature_subdivs_exec;
-       
-       ot->poll= ED_operator_editarmature;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       /* props */
-       RNA_def_enum(ot->srna, "type", type_items, 0, "Type", "");
-       
-       /* this is temp, the ops are different, but they are called from subdivs, so all the possible props should be here as well*/
-       RNA_def_int(ot->srna, "number_cuts", 2, 1, INT_MAX, "Number of Cuts", "", 1, 10); 
+       RNA_def_int(ot->srna, "number_cuts", 1, 1, INT_MAX, "Number of Cuts", "", 1, 10);
 }
 
 /* ----------- */
@@ -3662,7 +3722,7 @@ void ARMATURE_OT_subdivs(wmOperatorType *ot)
  * this to be done easily.
  */
 
-static int armature_switch_direction_exec(bContext *C, wmOperator *op
+static int armature_switch_direction_exec(bContext *C, wmOperator *UNUSED(op)
 {
        Object *ob= CTX_data_edit_object(C);
        bArmature *arm= (bArmature *)ob->data;
@@ -3757,7 +3817,7 @@ void ARMATURE_OT_switch_direction(wmOperatorType *ot)
 static void bone_connect_to_existing_parent(EditBone *bone)
 {
        bone->flag |= BONE_CONNECTED;
-       VECCOPY(bone->head, bone->parent->tail);
+       copy_v3_v3(bone->head, bone->parent->tail);
        bone->rad_head = bone->parent->rad_tail;
 }
 
@@ -3785,10 +3845,10 @@ static void bone_connect_to_new_parent(ListBase *edbo, EditBone *selbone, EditBo
                selbone->flag |= BONE_CONNECTED;
                sub_v3_v3v3(offset, actbone->tail, selbone->head);
                
-               VECCOPY(selbone->head, actbone->tail);
+               copy_v3_v3(selbone->head, actbone->tail);
                selbone->rad_head= actbone->rad_tail;
                
-               add_v3_v3v3(selbone->tail, selbone->tail, offset);
+               add_v3_v3(selbone->tail, offset);
                
                /* offset for all its children */
                for (ebone = edbo->first; ebone; ebone=ebone->next) {
@@ -3796,8 +3856,8 @@ static void bone_connect_to_new_parent(ListBase *edbo, EditBone *selbone, EditBo
                        
                        for (par= ebone->parent; par; par= par->parent) {
                                if (par==selbone) {
-                                       add_v3_v3v3(ebone->head, ebone->head, offset);
-                                       add_v3_v3v3(ebone->tail, ebone->tail, offset);
+                                       add_v3_v3(ebone->head, offset);
+                                       add_v3_v3(ebone->tail, offset);
                                        break;
                                }
                        }
@@ -3883,7 +3943,7 @@ static int armature_parent_set_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-static int armature_parent_set_invoke(bContext *C, wmOperator *op, wmEvent *event)
+static int armature_parent_set_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *UNUSED(event))
 {
        EditBone *actbone = CTX_data_active_bone(C);
        uiPopupMenu *pup= uiPupMenuBegin(C, "Make Parent ", 0);
@@ -3897,11 +3957,11 @@ static int armature_parent_set_invoke(bContext *C, wmOperator *op, wmEvent *even
        }
        CTX_DATA_END;
 
-       uiItemEnumO(layout, NULL, 0, "ARMATURE_OT_parent_set", "type", ARM_PAR_CONNECT);
+       uiItemEnumO(layout, "ARMATURE_OT_parent_set", NULL, 0, "type", ARM_PAR_CONNECT);
        
        /* ob becomes parent, make the associated menus */
        if (allchildbones)
-               uiItemEnumO(layout, NULL, 0, "ARMATURE_OT_parent_set", "type", ARM_PAR_OFFSET); 
+               uiItemEnumO(layout, "ARMATURE_OT_parent_set", NULL, 0, "type", ARM_PAR_OFFSET); 
                
        uiPupMenuEnd(C, pup);
        
@@ -3980,7 +4040,7 @@ void ARMATURE_OT_parent_clear(wmOperatorType *ot)
 
 /* ****************  Selections  ******************/
 
-static int armature_select_inverse_exec(bContext *C, wmOperator *op)
+static int armature_select_inverse_exec(bContext *C, wmOperator *UNUSED(op))
 {
        /*      Set the flags */
        CTX_DATA_BEGIN(C, EditBone *, ebone, visible_bones) {
@@ -4059,7 +4119,7 @@ void ARMATURE_OT_select_all(wmOperatorType *ot)
 {
        
        /* identifiers */
-       ot->name= "deselect all editbone";
+       ot->name= "Select or Deselect All";
        ot->idname= "ARMATURE_OT_select_all";
        
        /* api callbacks */
@@ -4151,7 +4211,7 @@ void ARMATURE_OT_select_hierarchy(wmOperatorType *ot)
 
        /* props */
        RNA_def_enum(ot->srna, "direction", direction_items,
-                    BONE_SELECT_PARENT, "Direction", "");
+                        BONE_SELECT_PARENT, "Direction", "");
        RNA_def_boolean(ot->srna, "extend", 0, "Add to Selection", "");
 }
 
@@ -4167,8 +4227,8 @@ static void fix_connected_bone(EditBone *ebone)
        
        /* if the parent has moved we translate child's head and tail accordingly*/
        sub_v3_v3v3(diff, ebone->parent->tail, ebone->head);
-       add_v3_v3v3(ebone->head, ebone->head, diff);
-       add_v3_v3v3(ebone->tail, ebone->tail, diff);
+       add_v3_v3(ebone->head, diff);
+       add_v3_v3(ebone->tail, diff);
        return;
 }
 
@@ -4279,7 +4339,7 @@ void ARMATURE_OT_align(wmOperatorType *ot)
        /* identifiers */
        ot->name= "Align Bones";
        ot->idname= "ARMATURE_OT_align";
-       ot->description= "Align selected bones to the active bone (or to their parent).";
+       ot->description= "Align selected bones to the active bone (or to their parent)";
        
        /* api callbacks */
        ot->invoke = WM_operator_confirm;
@@ -4296,28 +4356,28 @@ void ARMATURE_OT_align(wmOperatorType *ot)
 static int bone_looper(Object *ob, Bone *bone, void *data,
                                int (*bone_func)(Object *, Bone *, void *)) 
 {
-    /* We want to apply the function bone_func to every bone 
+       /* We want to apply the function bone_func to every bone 
        * in an armature -- feed bone_looper the first bone and 
        * a pointer to the bone_func and watch it go!. The int count 
        * can be useful for counting bones with a certain property
        * (e.g. skinnable)
        */
-    int count = 0;
+       int count = 0;
        
-    if (bone) {
+       if (bone) {
                /* only do bone_func if the bone is non null */
-        count += bone_func(ob, bone, data);
+               count += bone_func(ob, bone, data);
                
                /* try to execute bone_func for the first child */
-        count += bone_looper(ob, bone->childbase.first, data, bone_func);
+               count += bone_looper(ob, bone->childbase.first, data, bone_func);
                
                /* try to execute bone_func for the next bone at this
                        * depth of the recursion.
                        */
-        count += bone_looper(ob, bone->next, data, bone_func);
-    }
+               count += bone_looper(ob, bone->next, data, bone_func);
+       }
        
-    return count;
+       return count;
 }
 
 /* called from editview.c, for mode-less pose selection */
@@ -4337,7 +4397,7 @@ int ED_do_pose_selectbuffer(Scene *scene, Base *base, unsigned int *buffer, shor
                
                /* since we do unified select, we don't shift+select a bone if the armature object was not active yet */
                if (!(extend) || (base != scene->basact)) {
-                       ED_pose_deselectall(ob, 0, 0);
+                       ED_pose_deselectall(ob, 0);
                        nearBone->flag |= (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL);
                        arm->act_bone= nearBone;
                        
@@ -4384,7 +4444,7 @@ int ED_do_pose_selectbuffer(Scene *scene, Base *base, unsigned int *buffer, shor
    test==2: only clear active tag
    test==3: swap select (no test / inverse selection status of all independently)
 */
-void ED_pose_deselectall (Object *ob, int test, int doundo)
+void ED_pose_deselectall (Object *ob, int test)
 {
        bArmature *arm= ob->data;
        bPoseChannel *pchan;
@@ -4396,7 +4456,7 @@ void ED_pose_deselectall (Object *ob, int test, int doundo)
        /*      Determine if we're selecting or deselecting     */
        if (test==1) {
                for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
-                       if ((pchan->bone->layer & arm->layer) && !(pchan->bone->flag & BONE_HIDDEN_P)) {
+                       if (PBONE_VISIBLE(arm, pchan->bone)) {
                                if (pchan->bone->flag & BONE_SELECTED)
                                        break;
                        }
@@ -4424,39 +4484,32 @@ void ED_pose_deselectall (Object *ob, int test, int doundo)
        
        if(arm->act_bone && (arm->act_bone->flag & BONE_SELECTED)==0)
                arm->act_bone= NULL;
+}
 
-       //countall(); // XXX need an equivalent to this...
-       
-       if (doundo) {
-               if (selectmode==1) BIF_undo_push("Select All");
-               else BIF_undo_push("Deselect All");
-       }
-}
-
-static int bone_skinnable(Object *ob, Bone *bone, void *datap)
-{
-    /* Bones that are deforming
-     * are regarded to be "skinnable" and are eligible for
-     * auto-skinning.
-     *
-     * This function performs 2 functions:
-     *
-     *   a) It returns 1 if the bone is skinnable.
-     *      If we loop over all bones with this 
-     *      function, we can count the number of
-     *      skinnable bones.
-     *   b) If the pointer data is non null,
-     *      it is treated like a handle to a
-     *      bone pointer -- the bone pointer
-     *      is set to point at this bone, and
-     *      the pointer the handle points to
-     *      is incremented to point to the
-     *      next member of an array of pointers
-     *      to bones. This way we can loop using
-     *      this function to construct an array of
-     *      pointers to bones that point to all
-     *      skinnable bones.
-     */
+static int bone_skinnable_cb(Object *ob, Bone *bone, void *datap)
+{
+       /* Bones that are deforming
+        * are regarded to be "skinnable" and are eligible for
+        * auto-skinning.
+        *
+        * This function performs 2 functions:
+        *
+        *   a) It returns 1 if the bone is skinnable.
+        *      If we loop over all bones with this 
+        *      function, we can count the number of
+        *      skinnable bones.
+        *   b) If the pointer data is non null,
+        *      it is treated like a handle to a
+        *      bone pointer -- the bone pointer
+        *      is set to point at this bone, and
+        *      the pointer the handle points to
+        *      is incremented to point to the
+        *      next member of an array of pointers
+        *      to bones. This way we can loop using
+        *      this function to construct an array of
+        *      pointers to bones that point to all
+        *      skinnable bones.
+        */
        Bone ***hbone;
        int a, segments;
        struct { Object *armob; void *list; int heat; } *data = datap;
@@ -4479,62 +4532,65 @@ static int bone_skinnable(Object *ob, Bone *bone, void *datap)
                        return segments;
                }
        }
-    return 0;
+       return 0;
 }
 
-static int ED_vgroup_add_unique_bone(Object *ob, Bone *bone, void *data
+static int vgroup_add_unique_bone_cb(Object *ob, Bone *bone, void *UNUSED(ptr)
 {
-    /* This group creates a vertex group to ob that has the
-      * same name as bone (provided the bone is skinnable). 
+       /* This group creates a vertex group to ob that has the
+         * same name as bone (provided the bone is skinnable). 
         * If such a vertex group aleady exist the routine exits.
-      */
+         */
        if (!(bone->flag & BONE_NO_DEFORM)) {
                if (!defgroup_find_name(ob,bone->name)) {
                        ED_vgroup_add_name(ob, bone->name);
                        return 1;
                }
-    }
-    return 0;
-}
-
-static int dgroup_skinnable(Object *ob, Bone *bone, void *datap) 
-{
-    /* Bones that are deforming
-     * are regarded to be "skinnable" and are eligible for
-     * auto-skinning.
-     *
-     * This function performs 2 functions:
-     *
-     *   a) If the bone is skinnable, it creates 
-     *      a vertex group for ob that has
-     *      the name of the skinnable bone
-     *      (if one doesn't exist already).
-     *   b) If the pointer data is non null,
-     *      it is treated like a handle to a
-     *      bDeformGroup pointer -- the 
-     *      bDeformGroup pointer is set to point
-     *      to the deform group with the bone's
-     *      name, and the pointer the handle 
-     *      points to is incremented to point to the
-     *      next member of an array of pointers
-     *      to bDeformGroups. This way we can loop using
-     *      this function to construct an array of
-     *      pointers to bDeformGroups, all with names
-     *      of skinnable bones.
-     */
-    bDeformGroup ***hgroup, *defgroup;
+       }
+       return 0;
+}
+
+static int dgroup_skinnable_cb(Object *ob, Bone *bone, void *datap) 
+{
+       /* Bones that are deforming
+        * are regarded to be "skinnable" and are eligible for
+        * auto-skinning.
+        *
+        * This function performs 2 functions:
+        *
+        *   a) If the bone is skinnable, it creates 
+        *      a vertex group for ob that has
+        *      the name of the skinnable bone
+        *      (if one doesn't exist already).
+        *   b) If the pointer data is non null,
+        *      it is treated like a handle to a
+        *      bDeformGroup pointer -- the 
+        *      bDeformGroup pointer is set to point
+        *      to the deform group with the bone's
+        *      name, and the pointer the handle 
+        *      points to is incremented to point to the
+        *      next member of an array of pointers
+        *      to bDeformGroups. This way we can loop using
+        *      this function to construct an array of
+        *      pointers to bDeformGroups, all with names
+        *      of skinnable bones.
+        */
+       bDeformGroup ***hgroup, *defgroup= NULL;
        int a, segments;
        struct { Object *armob; void *list; int heat; } *data= datap;
+       int wpmode = (ob->mode & OB_MODE_WEIGHT_PAINT);
+       bArmature *arm= data->armob->data;
 
-       if (!(ob->mode & OB_MODE_WEIGHT_PAINT) || !(bone->flag & BONE_HIDDEN_P)) {
+       if (!wpmode || !(bone->flag & BONE_HIDDEN_P)) {
           if (!(bone->flag & BONE_NO_DEFORM)) {
                        if (data->heat && data->armob->pose && get_pose_channel(data->armob->pose, bone->name))
                                segments = bone->segments;
                        else
                                segments = 1;
-                       
-                       if (!(defgroup = defgroup_find_name(ob, bone->name)))
-                               defgroup = ED_vgroup_add_name(ob, bone->name);
+
+                       if(!wpmode || ((arm->layer & bone->layer) && (bone->flag & BONE_SELECTED)))
+                               if (!(defgroup = defgroup_find_name(ob, bone->name)))
+                                       defgroup = ED_vgroup_add_name(ob, bone->name);
                        
                        if (data->list != NULL) {
                                hgroup = (bDeformGroup ***) &data->list;
@@ -4547,15 +4603,15 @@ static int dgroup_skinnable(Object *ob, Bone *bone, void *datap)
                        return segments;
                }
        }
-    return 0;
+       return 0;
 }
 
-static void add_vgroups__mapFunc(void *userData, int index, float *co, float *no_f, short *no_s)
+static void add_vgroups__mapFunc(void *userData, int index, float *co, float *UNUSED(no_f), short *UNUSED(no_s))
 {
        /* DerivedMesh mapFunc for getting final coords in weight paint mode */
 
        float (*verts)[3] = userData;
-       VECCOPY(verts[index], co);
+       copy_v3_v3(verts[index], co);
 }
 
 static void envelope_bone_weighting(Object *ob, Mesh *mesh, float (*verts)[3], int numbones, Bone **bonelist, bDeformGroup **dgrouplist, bDeformGroup **dgroupflip, float (*root)[3], float (*tip)[3], int *selected, float scale)
@@ -4601,7 +4657,7 @@ static void envelope_bone_weighting(Object *ob, Mesh *mesh, float (*verts)[3], i
        }
 }
 
-void add_verts_to_dgroups(Scene *scene, Object *ob, Object *par, int heat, int mirror)
+void add_verts_to_dgroups(ReportList *reports, Scene *scene, Object *ob, Object *par, int heat, int mirror)
 {
        /* This functions implements the automatic computation of vertex group
         * weights, either through envelopes or using a heat equilibrium.
@@ -4618,7 +4674,7 @@ void add_verts_to_dgroups(Scene *scene, Object *ob, Object *par, int heat, int m
        bArmature *arm= par->data;
        Bone **bonelist, *bone;
        bDeformGroup **dgrouplist, **dgroupflip;
-       bDeformGroup *dgroup, *curdg;
+       bDeformGroup *dgroup;
        bPoseChannel *pchan;
        Mesh *mesh;
        Mat4 *bbone = NULL;
@@ -4633,7 +4689,7 @@ void add_verts_to_dgroups(Scene *scene, Object *ob, Object *par, int heat, int m
        looper_data.list= NULL;
 
        /* count the number of skinnable bones */
-       numbones = bone_looper(ob, arm->bonebase.first, &looper_data, bone_skinnable);
+       numbones = bone_looper(ob, arm->bonebase.first, &looper_data, bone_skinnable_cb);
        
        if (numbones == 0)
                return;
@@ -4642,7 +4698,7 @@ void add_verts_to_dgroups(Scene *scene, Object *ob, Object *par, int heat, int m
         * and fill it with all of the skinnable bones */
        bonelist = MEM_callocN(numbones*sizeof(Bone *), "bonelist");
        looper_data.list= bonelist;
-       bone_looper(ob, arm->bonebase.first, &looper_data, bone_skinnable);
+       bone_looper(ob, arm->bonebase.first, &looper_data, bone_skinnable_cb);
 
        /* create an array of pointers to the deform groups that
         * coorespond to the skinnable bones (creating them
@@ -4651,7 +4707,7 @@ void add_verts_to_dgroups(Scene *scene, Object *ob, Object *par, int heat, int m
        dgroupflip = MEM_callocN(numbones*sizeof(bDeformGroup *), "dgroupflip");
 
        looper_data.list= dgrouplist;
-       bone_looper(ob, arm->bonebase.first, &looper_data, dgroup_skinnable);
+       bone_looper(ob, arm->bonebase.first, &looper_data, dgroup_skinnable_cb);
 
        /* create an array of root and tip positions transformed into
         * global coords */
@@ -4660,7 +4716,7 @@ void add_verts_to_dgroups(Scene *scene, Object *ob, Object *par, int heat, int m
        selected = MEM_callocN(numbones*sizeof(int), "selected");
 
        for (j=0; j < numbones; ++j) {
-               bone = bonelist[j];
+               bone = bonelist[j];
                dgroup = dgrouplist[j];
                
                /* handle bbone */
@@ -4682,18 +4738,17 @@ void add_verts_to_dgroups(Scene *scene, Object *ob, Object *par, int heat, int m
                
                /* compute root and tip */
                if (bbone) {
-                       VECCOPY(root[j], bbone[segments].mat[3]);
-                       mul_m4_v3(bone->arm_mat, root[j]);
+                       mul_v3_m4v3(root[j], bone->arm_mat, bbone[segments].mat[3]);
                        if ((segments+1) < bone->segments) {
-                               VECCOPY(tip[j], bbone[segments+1].mat[3])
-                               mul_m4_v3(bone->arm_mat, tip[j]);
+                               mul_v3_m4v3(tip[j], bone->arm_mat, bbone[segments+1].mat[3]);
+                       }
+                       else {
+                               copy_v3_v3(tip[j], bone->arm_tail);
                        }
-                       else
-                               VECCOPY(tip[j], bone->arm_tail)
                }
                else {
-                       VECCOPY(root[j], bone->arm_head);
-                       VECCOPY(tip[j], bone->arm_tail);
+                       copy_v3_v3(root[j], bone->arm_head);
+                       copy_v3_v3(tip[j], bone->arm_tail);
                }
                
                mul_m4_v3(par->obmat, root[j]);
@@ -4708,24 +4763,17 @@ void add_verts_to_dgroups(Scene *scene, Object *ob, Object *par, int heat, int m
                        selected[j] = 1;
                
                /* find flipped group */
-               if (mirror) {
+               if (dgroup && mirror) {
                        char name[32];
-                       
-                       BLI_strncpy(name, dgroup->name, 32);
+
                        // 0 = don't strip off number extensions
-                       bone_flip_name(name, 0);
-                       
-                       for (curdg = ob->defbase.first; curdg; curdg=curdg->next) {
-                               if (!strcmp(curdg->name, name))
-                                       break;
-                       }
-                       
-                       dgroupflip[j] = curdg;
+                       flip_side_name(name, dgroup->name, FALSE);
+                       dgroupflip[j] = defgroup_find_name(ob, name);
                }
        }
 
        /* create verts */
-    mesh = (Mesh*)ob->data;
+       mesh = (Mesh*)ob->data;
        verts = MEM_callocN(mesh->totvert*sizeof(*verts), "closestboneverts");
 
        if (wpmode) {
@@ -4741,7 +4789,7 @@ void add_verts_to_dgroups(Scene *scene, Object *ob, Object *par, int heat, int m
        }
        else if (modifiers_findByType(ob, eModifierType_Subsurf)) {
                /* is subsurf on? Lets use the verts on the limit surface then.
-                * = same amount of vertices as mesh, but vertices  moved to the
+                 * = same amount of vertices as mesh, but vertices  moved to the
                 * subsurfed position, like for 'optimal'. */
                subsurf_calculate_limit_positions(mesh, verts);
                vertsfilled = 1;
@@ -4750,23 +4798,31 @@ void add_verts_to_dgroups(Scene *scene, Object *ob, Object *par, int heat, int m
        /* transform verts to global space */
        for (i=0; i < mesh->totvert; i++) {
                if (!vertsfilled)
-                       VECCOPY(verts[i], mesh->mvert[i].co)
+                       copy_v3_v3(verts[i], mesh->mvert[i].co);
                mul_m4_v3(ob->obmat, verts[i]);
        }
 
        /* compute the weights based on gathered vertices and bones */
        if (heat) {
+               const char *error= NULL;
                heat_bone_weighting(ob, mesh, verts, numbones, dgrouplist, dgroupflip,
-                       root, tip, selected);
+                       root, tip, selected, &error);
+               
+               if(error) {
+                       BKE_report(reports, RPT_WARNING, error);
+               }
        }
        else {
                envelope_bone_weighting(ob, mesh, verts, numbones, bonelist, dgrouplist,
                        dgroupflip, root, tip, selected, mat4_to_scale(par->obmat));
        }
-       
-    /* free the memory allocated */
-    MEM_freeN(bonelist);
-    MEM_freeN(dgrouplist);
+
+       /* only generated in some cases but can call anyway */
+       mesh_octree_table(ob, NULL, NULL, 'e');
+
+       /* free the memory allocated */
+       MEM_freeN(bonelist);
+       MEM_freeN(dgrouplist);
        MEM_freeN(dgroupflip);
        MEM_freeN(root);
        MEM_freeN(tip);
@@ -4774,7 +4830,7 @@ void add_verts_to_dgroups(Scene *scene, Object *ob, Object *par, int heat, int m
        MEM_freeN(verts);
 }
 
-void create_vgroups_from_armature(Scene *scene, Object *ob, Object *par, int mode, int mirror)
+void create_vgroups_from_armature(ReportList *reports, Scene *scene, Object *ob, Object *par, int mode, int mirror)
 {
        /* Lets try to create some vertex groups 
         * based on the bones of the parent armature.
@@ -4785,7 +4841,7 @@ void create_vgroups_from_armature(Scene *scene, Object *ob, Object *par, int mod
                /* Traverse the bone list, trying to create empty vertex 
                 * groups cooresponding to the bone.
                 */
-               bone_looper(ob, arm->bonebase.first, NULL, ED_vgroup_add_unique_bone);
+               bone_looper(ob, arm->bonebase.first, NULL, vgroup_add_unique_bone_cb);
 
                if (ob->type == OB_MESH)
                        ED_vgroup_data_create(ob->data);
@@ -4795,23 +4851,16 @@ void create_vgroups_from_armature(Scene *scene, Object *ob, Object *par, int mod
                 * that are populated with the vertices for which the
                 * bone is closest.
                 */
-               add_verts_to_dgroups(scene, ob, par, (mode == ARM_GROUPS_AUTO), mirror);
+               add_verts_to_dgroups(reports, scene, ob, par, (mode == ARM_GROUPS_AUTO), mirror);
        }
 } 
 /* ************* Clear Pose *****************************/
 
-static int pose_clear_scale_exec(bContext *C, wmOperator *op
+static int pose_clear_scale_exec(bContext *C, wmOperator *UNUSED(op)
 {
        Scene *scene= CTX_data_scene(C);
-       Object *ob= CTX_data_active_object(C);
-       
-       KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Scaling");
-       bCommonKeySrc cks;
-       ListBase dsources = {&cks, &cks};
-       
-       /* init common-key-source for use by KeyingSets */
-       memset(&cks, 0, sizeof(bCommonKeySrc));
-       cks.id= &ob->id;
+       Object *ob= ED_object_pose_armature(CTX_data_active_object(C));
+       short autokey = 0;
        
        /* only clear those channels that are not locked */
        CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pose_bones) {
@@ -4824,13 +4873,12 @@ static int pose_clear_scale_exec(bContext *C, wmOperator *op)
                        
                /* do auto-keyframing as appropriate */
                if (autokeyframe_cfra_can_key(scene, &ob->id)) {
-                       /* init cks for this PoseChannel, then use the relative KeyingSets to keyframe it */
-                       cks.pchan= pchan;
-                       modify_keyframes(scene, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
-                       
                        /* clear any unkeyed tags */
                        if (pchan->bone)
                                pchan->bone->flag &= ~BONE_UNKEYED;
+                               
+                       /* tag for autokeying later */
+                       autokey = 1;
                }
                else {
                        /* add unkeyed tags */
@@ -4840,6 +4888,19 @@ static int pose_clear_scale_exec(bContext *C, wmOperator *op)
        }
        CTX_DATA_END;
        
+       /* perform autokeying on the bones if needed */
+       if (autokey) {
+               /* get KeyingSet to use */
+               KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, "Scaling");
+               
+               /* insert keyframes */
+               ANIM_apply_keyingset(C, NULL, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
+               
+               /* now recalculate paths */
+               if ((ob->pose->avs.path_bakeflag & MOTIONPATH_BAKE_HAS_PATHS))
+                       ED_pose_recalculate_paths(scene, ob);
+       }
+       
        DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
 
        /* note, notifier might evolve */
@@ -4863,18 +4924,11 @@ void POSE_OT_scale_clear(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
-static int pose_clear_loc_exec(bContext *C, wmOperator *op
+static int pose_clear_loc_exec(bContext *C, wmOperator *UNUSED(op)
 {
        Scene *scene= CTX_data_scene(C);
-       Object *ob= CTX_data_active_object(C);
-       
-       KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Location");
-       bCommonKeySrc cks;
-       ListBase dsources = {&cks, &cks};
-       
-       /* init common-key-source for use by KeyingSets */
-       memset(&cks, 0, sizeof(bCommonKeySrc));
-       cks.id= &ob->id;
+       Object *ob= ED_object_pose_armature(CTX_data_active_object(C));
+       short autokey = 0;
        
        /* only clear those channels that are not locked */
        CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pose_bones) {
@@ -4888,13 +4942,12 @@ static int pose_clear_loc_exec(bContext *C, wmOperator *op)
                        
                /* do auto-keyframing as appropriate */
                if (autokeyframe_cfra_can_key(scene, &ob->id)) {
-                       /* init cks for this PoseChannel, then use the relative KeyingSets to keyframe it */
-                       cks.pchan= pchan;
-                       modify_keyframes(scene, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
-                       
                        /* clear any unkeyed tags */
                        if (pchan->bone)
                                pchan->bone->flag &= ~BONE_UNKEYED;
+                               
+                       /* tag for autokeying later */
+                       autokey = 1;
                }
                else {
                        /* add unkeyed tags */
@@ -4904,6 +4957,19 @@ static int pose_clear_loc_exec(bContext *C, wmOperator *op)
        }
        CTX_DATA_END;
        
+       /* perform autokeying on the bones if needed */
+       if (autokey) {
+               /* get KeyingSet to use */
+               KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, "Location");
+               
+               /* insert keyframes */
+               ANIM_apply_keyingset(C, NULL, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
+               
+               /* now recalculate paths */
+               if ((ob->pose->avs.path_bakeflag & MOTIONPATH_BAKE_HAS_PATHS))
+                       ED_pose_recalculate_paths(scene, ob);
+       }
+       
        DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
 
        /* note, notifier might evolve */
@@ -4927,18 +4993,11 @@ void POSE_OT_loc_clear(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
-static int pose_clear_rot_exec(bContext *C, wmOperator *op
+static int pose_clear_rot_exec(bContext *C, wmOperator *UNUSED(op)
 {
        Scene *scene= CTX_data_scene(C);
-       Object *ob= CTX_data_active_object(C);
-       
-       KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Rotation");
-       bCommonKeySrc cks;
-       ListBase dsources = {&cks, &cks};
-       
-       /* init common-key-source for use by KeyingSets */
-       memset(&cks, 0, sizeof(bCommonKeySrc));
-       cks.id= &ob->id;
+       Object *ob= ED_object_pose_armature(CTX_data_active_object(C));
+       short autokey = 0;
        
        /* only clear those channels that are not locked */
        CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pose_bones) {
@@ -4985,14 +5044,14 @@ static int pose_clear_rot_exec(bContext *C, wmOperator *op)
                                float eul[3], oldeul[3], quat1[4] = {0};
                                
                                if (pchan->rotmode == ROT_MODE_QUAT) {
-                                       QUATCOPY(quat1, pchan->quat);
+                                       copy_qt_qt(quat1, pchan->quat);
                                        quat_to_eul( oldeul,pchan->quat);
                                }
                                else if (pchan->rotmode == ROT_MODE_AXISANGLE) {
                                        axis_angle_to_eulO( oldeul, EULER_ORDER_DEFAULT,pchan->rotAxis, pchan->rotAngle);
                                }
                                else {
-                                       VECCOPY(oldeul, pchan->eul);
+                                       copy_v3_v3(oldeul, pchan->eul);
                                }
                                
                                eul[0]= eul[1]= eul[2]= 0.0f;
@@ -5015,10 +5074,10 @@ static int pose_clear_rot_exec(bContext *C, wmOperator *op)
                                        eulO_to_axis_angle( pchan->rotAxis, &pchan->rotAngle,eul, EULER_ORDER_DEFAULT);
                                }
                                else {
-                                       VECCOPY(pchan->eul, eul);
+                                       copy_v3_v3(pchan->eul, eul);
                                }
                        }
-               }                                               
+               }                                               // Duplicated in source/blender/editors/object/object_transform.c
                else { 
                        if (pchan->rotmode == ROT_MODE_QUAT) {
                                pchan->quat[1]=pchan->quat[2]=pchan->quat[3]= 0.0f; 
@@ -5036,13 +5095,12 @@ static int pose_clear_rot_exec(bContext *C, wmOperator *op)
                
                /* do auto-keyframing as appropriate */
                if (autokeyframe_cfra_can_key(scene, &ob->id)) {
-                       /* init cks for this PoseChannel, then use the relative KeyingSets to keyframe it */
-                       cks.pchan= pchan;
-                       modify_keyframes(scene, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
-                       
                        /* clear any unkeyed tags */
                        if (pchan->bone)
                                pchan->bone->flag &= ~BONE_UNKEYED;
+                               
+                       /* tag for autokeying later */
+                       autokey = 1;
                }
                else {
                        /* add unkeyed tags */
@@ -5052,6 +5110,19 @@ static int pose_clear_rot_exec(bContext *C, wmOperator *op)
        }
        CTX_DATA_END;
        
+       /* perform autokeying on the bones if needed */
+       if (autokey) {
+               /* get KeyingSet to use */
+               KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, "Rotation");
+               
+               /* insert keyframes */
+               ANIM_apply_keyingset(C, NULL, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
+               
+               /* now recalculate paths */
+               if ((ob->pose->avs.path_bakeflag & MOTIONPATH_BAKE_HAS_PATHS))
+                       ED_pose_recalculate_paths(scene, ob);
+       }
+       
        DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
 
        /* note, notifier might evolve */
@@ -5078,7 +5149,7 @@ void POSE_OT_rot_clear(wmOperatorType *ot)
 
 /* ***************** selections ********************** */
 
-static int pose_select_inverse_exec(bContext *C, wmOperator *op)
+static int pose_select_inverse_exec(bContext *C, wmOperator *UNUSED(op))
 {
        
        /*      Set the flags */
@@ -5162,7 +5233,7 @@ void POSE_OT_select_all(wmOperatorType *ot)
 {
        
        /* identifiers */
-       ot->name= "deselect all bones";
+       ot->name= "Select or Deselect All";
        ot->idname= "POSE_OT_select_all";
        
        /* api callbacks */
@@ -5175,9 +5246,9 @@ void POSE_OT_select_all(wmOperatorType *ot)
        WM_operator_properties_select_all(ot);
 }
 
-static int pose_select_parent_exec(bContext *C, wmOperator *op)
+static int pose_select_parent_exec(bContext *C, wmOperator *UNUSED(op))
 {
-       Object *ob= CTX_data_active_object(C);
+       Object *ob= ED_object_pose_armature(CTX_data_active_object(C));
        bPoseChannel *pchan,*parent;
 
        /*      Determine if there is an active bone */
@@ -5219,13 +5290,14 @@ void POSE_OT_select_parent(wmOperatorType *ot)
 
 /* ************* hide/unhide pose bones ******************* */
 
-static int hide_selected_pose_bone(Object *ob, Bone *bone, void *ptr
+static int hide_selected_pose_bone_cb(Object *ob, Bone *bone, void *UNUSED(ptr)
 {
        bArmature *arm= ob->data;
        
        if (arm->layer & bone->layer) {
                if (bone->flag & BONE_SELECTED) {
                        bone->flag |= BONE_HIDDEN_P;
+                       bone->flag &= ~BONE_SELECTED;
                        if(arm->act_bone==bone)
                                arm->act_bone= NULL;
                }
@@ -5233,7 +5305,7 @@ static int hide_selected_pose_bone(Object *ob, Bone *bone, void *ptr)
        return 0;
 }
 
-static int hide_unselected_pose_bone(Object *ob, Bone *bone, void *ptr
+static int hide_unselected_pose_bone_cb(Object *ob, Bone *bone, void *UNUSED(ptr)
 {
        bArmature *arm= ob->data;
        
@@ -5251,15 +5323,13 @@ static int hide_unselected_pose_bone(Object *ob, Bone *bone, void *ptr)
 /* active object is armature in posemode, poll checked */
 static int pose_hide_exec(bContext *C, wmOperator *op) 
 {
-       Object *ob= CTX_data_active_object(C);
+       Object *ob= ED_object_pose_armature(CTX_data_active_object(C));
        bArmature *arm= ob->data;
 
        if(RNA_boolean_get(op->ptr, "unselected"))
-          bone_looper(ob, arm->bonebase.first, NULL, 
-                               hide_unselected_pose_bone);
+          bone_looper(ob, arm->bonebase.first, NULL, hide_unselected_pose_bone_cb);
        else
-          bone_looper(ob, arm->bonebase.first, NULL, 
-                                  hide_selected_pose_bone);
+          bone_looper(ob, arm->bonebase.first, NULL, hide_selected_pose_bone_cb);
        
        /* note, notifier might evolve */
        WM_event_add_notifier(C, NC_OBJECT|ND_BONE_SELECT, ob);
@@ -5284,7 +5354,7 @@ void POSE_OT_hide(wmOperatorType *ot)
        RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "");
 }
 
-static int show_pose_bone(Object *ob, Bone *bone, void *ptr
+static int show_pose_bone_cb(Object *ob, Bone *bone, void *UNUSED(ptr)
 {
        bArmature *arm= ob->data;
        
@@ -5299,12 +5369,12 @@ static int show_pose_bone(Object *ob, Bone *bone, void *ptr)
 }
 
 /* active object is armature in posemode, poll checked */
-static int pose_reveal_exec(bContext *C, wmOperator *op
+static int pose_reveal_exec(bContext *C, wmOperator *UNUSED(op)
 {
-       Object *ob= CTX_data_active_object(C);
+       Object *ob= ED_object_pose_armature(CTX_data_active_object(C));
        bArmature *arm= ob->data;
        
-       bone_looper(ob, arm->bonebase.first, NULL, show_pose_bone);
+       bone_looper(ob, arm->bonebase.first, NULL, show_pose_bone_cb);
        
        /* note, notifier might evolve */
        WM_event_add_notifier(C, NC_OBJECT|ND_BONE_SELECT, ob);
@@ -5329,29 +5399,22 @@ void POSE_OT_reveal(wmOperatorType *ot)
 /* ************* RENAMING DISASTERS ************ */
 
 /* note: there's a unique_editbone_name() too! */
-void unique_bone_name (bArmature *arm, char *name)
-{
-       char            tempname[64];
-       int                     number;
-       char            *dot;
-       
+static void unique_bone_name (bArmature *arm, char *name)
+{      
        if (get_named_bone(arm, name)) {
-               
-               /*      Strip off the suffix, if it's a number */
-               number= strlen(name);
-               if(number && isdigit(name[number-1])) {
-                       dot= strrchr(name, '.');        // last occurrence
-                       if (dot)
-                               *dot=0;
-               }
-               
-               for (number = 1; number <=999; number++) {
-                       sprintf (tempname, "%s.%03d", name, number);
-                       if (!get_named_bone(arm, tempname)) {
-                               BLI_strncpy (name, tempname, 32);
-                               return;
+               /* note: this block is used in other places, when changing logic apply to all others, search this message */
+               char    tempname[sizeof(((Bone *)NULL)->name)];
+               char    left[sizeof(((Bone *)NULL)->name)];
+               int             number;
+               int             len= BLI_split_name_num(left, &number, name);
+               do {    /* nested while loop looks bad but likely it wont run most times */
+                       while(BLI_snprintf(tempname, sizeof(tempname), "%s.%03d", left, number) >= sizeof(tempname)) {
+                               if(len > 0)     left[--len]= '\0';      /* word too long */
+                               else            number= 0;                      /* reset, must be a massive number */
                        }
-               }
+               } while(number++, get_named_bone(arm, tempname));
+
+               BLI_strncpy(name, tempname, sizeof(tempname));
        }
 }
 
@@ -5421,6 +5484,8 @@ void ED_armature_bone_rename(bArmature *arm, char *oldnamep, char *newnamep)
                
                /* do entire dbase - objects */
                for (ob= G.main->object.first; ob; ob= ob->id.next) {
+                       ModifierData *md;
+                       
                        /* we have the object using the armature */
                        if (arm==ob->data) {
                                Object *cob;
@@ -5428,8 +5493,17 @@ void ED_armature_bone_rename(bArmature *arm, char *oldnamep, char *newnamep)
                                /* Rename the pose channel, if it exists */
                                if (ob->pose) {
                                        bPoseChannel *pchan = get_pose_channel(ob->pose, oldname);
-                                       if (pchan)
+                                       if (pchan) {
                                                BLI_strncpy(pchan->name, newname, MAXBONENAME);
+                                               
+                                               if (ob->pose->chanhash) {
+                                                       GHash *gh = ob->pose->chanhash;
+                                                       
+                                                       /* remove the old hash entry, and replace with the new name */
+                                                       BLI_ghash_remove(gh, oldname, NULL, NULL);
+                                                       BLI_ghash_insert(gh, pchan->name, pchan);
+                                               }
+                                       }
                                }
                                
                                /* Update any object constraints to use the new bone name */
@@ -5455,11 +5529,22 @@ void ED_armature_bone_rename(bArmature *arm, char *oldnamep, char *newnamep)
                        }
                        
                        if (modifiers_usesArmature(ob, arm)) { 
-                               bDeformGroup *dg;
-                               /* bone name in defgroup */
-                               for (dg=ob->defbase.first; dg; dg=dg->next) {
-                                       if (!strcmp(dg->name, oldname))
-                                          BLI_strncpy(dg->name, newname, MAXBONENAME);
+                               bDeformGroup *dg= defgroup_find_name(ob, oldname);
+                               if(dg) {
+                                       BLI_strncpy(dg->name, newname, MAXBONENAME);
+                               }
+                       }
+                       
+                       /* fix modifiers that might be using this name */
+                       for (md= ob->modifiers.first; md; md= md->next) {
+                               if (md->type == eModifierType_Hook) {
+                                       HookModifierData *hmd = (HookModifierData *)md;
+                                       
+                                       /* uses armature, so may use the affected bone name */
+                                       if (hmd->object && (hmd->object->data == arm)) {
+                                               if (!strcmp(hmd->subtarget, oldname))
+                                                       BLI_strncpy(hmd->subtarget, newname, MAXBONENAME);
+                                       }
                                }
                        }
                        
@@ -5467,14 +5552,14 @@ void ED_armature_bone_rename(bArmature *arm, char *oldnamep, char *newnamep)
                        // TODO: should we be using the database wide version instead (since drivers may break)
                        if (ob->adt) {
                                /* posechannels only... */
-                               BKE_animdata_fix_paths_rename(&ob->id, ob->adt, "pose.bones", oldname, newname);
+                               BKE_animdata_fix_paths_rename(&ob->id, ob->adt, "pose.bones", oldname, newname, 0, 0, 1);
                        }
                }
        }
 }
 
 
-static int armature_flip_names_exec (bContext *C, wmOperator *op)
+static int armature_flip_names_exec (bContext *C, wmOperator *UNUSED(op))
 {
        Object *ob= CTX_data_edit_object(C);
        bArmature *arm;
@@ -5488,8 +5573,7 @@ static int armature_flip_names_exec (bContext *C, wmOperator *op)
        /* loop through selected bones, auto-naming them */
        CTX_DATA_BEGIN(C, EditBone *, ebone, selected_editable_bones)
        {
-               BLI_strncpy(newname, ebone->name, sizeof(newname));
-               bone_flip_name(newname, 1);             // 1 = do strip off number extensions
+               flip_side_name(newname, ebone->name, TRUE); // 1 = do strip off number extensions
                ED_armature_bone_rename(arm, ebone->name, newname);
        }
        CTX_DATA_END;
@@ -5508,7 +5592,7 @@ void ARMATURE_OT_flip_names (wmOperatorType *ot)
        /* identifiers */
        ot->name= "Flip Names";
        ot->idname= "ARMATURE_OT_flip_names";
-       ot->description= "Flips (and corrects) the names of selected bones.";
+       ot->description= "Flips (and corrects) the names of selected bones";
        
        /* api callbacks */
        ot->exec= armature_flip_names_exec;
@@ -5535,8 +5619,8 @@ static int armature_autoside_names_exec (bContext *C, wmOperator *op)
        CTX_DATA_BEGIN(C, EditBone *, ebone, selected_editable_bones)
        {
                BLI_strncpy(newname, ebone->name, sizeof(newname));
-               bone_autoside_name(newname, 1, axis, ebone->head[axis], ebone->tail[axis]);
-               ED_armature_bone_rename(arm, ebone->name, newname);
+               if(bone_autoside_name(newname, 1, axis, ebone->head[axis], ebone->tail[axis]))
+                       ED_armature_bone_rename(arm, ebone->name, newname);
        }
        CTX_DATA_END;
        
@@ -5552,7 +5636,7 @@ static int armature_autoside_names_exec (bContext *C, wmOperator *op)
 void ARMATURE_OT_autoside_names (wmOperatorType *ot)
 {
        static EnumPropertyItem axis_items[]= {
-               {0, "XAXIS", 0, "X-Axis", "Left/Right"},
+                {0, "XAXIS", 0, "X-Axis", "Left/Right"},
                {1, "YAXIS", 0, "Y-Axis", "Front/Back"},
                {2, "ZAXIS", 0, "Z-Axis", "Top/Bottom"},
                {0, NULL, 0, NULL, NULL}};
@@ -5560,7 +5644,7 @@ void ARMATURE_OT_autoside_names (wmOperatorType *ot)
        /* identifiers */
        ot->name= "AutoName by Axis";
        ot->idname= "ARMATURE_OT_autoside_names";
-       ot->description= "Automatically renames the selected bones according to which side of the target axis they fall on.";
+       ot->description= "Automatically renames the selected bones according to which side of the target axis they fall on";
        
        /* api callbacks */
        ot->invoke= WM_menu_invoke;
@@ -5597,11 +5681,12 @@ void transform_armature_mirror_update(Object *obedit)
                                        eboflip->tail[1]= ebo->tail[1];
                                        eboflip->tail[2]= ebo->tail[2];
                                        eboflip->rad_tail= ebo->rad_tail;
+                                       eboflip->roll= -ebo->roll;
 
                                        /* Also move connected children, in case children's name aren't mirrored properly */
                                        for (children=arm->edbo->first; children; children=children->next) {
                                                if (children->parent == eboflip && children->flag & BONE_CONNECTED) {
-                                                       VECCOPY(children->head, eboflip->tail);
+                                                       copy_v3_v3(children->head, eboflip->tail);
                                                        children->rad_head = ebo->rad_tail;
                                                }
                                        }
@@ -5611,12 +5696,13 @@ void transform_armature_mirror_update(Object *obedit)
                                        eboflip->head[1]= ebo->head[1];
                                        eboflip->head[2]= ebo->head[2];
                                        eboflip->rad_head= ebo->rad_head;
+                                       eboflip->roll= -ebo->roll;
                                        
                                        /* Also move connected parent, in case parent's name isn't mirrored properly */
                                        if (eboflip->parent && eboflip->flag & BONE_CONNECTED)
                                        {
                                                EditBone *parent = eboflip->parent;
-                                               VECCOPY(parent->tail, eboflip->head);
+                                               copy_v3_v3(parent->tail, eboflip->head);
                                                parent->rad_tail = ebo->rad_head;
                                        }
                                }
@@ -5657,7 +5743,7 @@ EditBone * subdivideByAngle(Scene *scene, Object *obedit, ReebArc *arc, ReebNode
                
                parent = ED_armature_edit_bone_add(arm, "Bone");
                parent->flag |= BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL;
-               VECCOPY(parent->head, head->p);
+               copy_v3_v3(parent->head, head->p);
                
                root = parent;
                
@@ -5682,17 +5768,17 @@ EditBone * subdivideByAngle(Scene *scene, Object *obedit, ReebArc *arc, ReebNode
 
                        if (len1 > 0.0f && len2 > 0.0f && dot_v3v3(vec1, vec2) < angleLimit)
                        {
-                               VECCOPY(parent->tail, previous);
+                               copy_v3_v3(parent->tail, previous);
 
                                child = ED_armature_edit_bone_add(arm, "Bone");
-                               VECCOPY(child->head, parent->tail);
+                               copy_v3_v3(child->head, parent->tail);
                                child->parent = parent;
                                child->flag |= BONE_CONNECTED|BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL;
                                
                                parent = child; /* new child is next parent */
                        }
                }
-               VECCOPY(parent->tail, tail->p);
+               copy_v3_v3(parent->tail, tail->p);
                
                /* If the bone wasn't subdivided, delete it and return NULL
                 * to let subsequent subdivision methods do their thing. 
@@ -5732,7 +5818,7 @@ EditBone * test_subdivideByCorrelation(Scene *scene, Object *obedit, ReebArc *ar
                lastBone = subdivideArcBy(arm, arm->edbo, iter, invmat, tmat, nextAdaptativeSubdivision);
        }
        
-       return lastBone;
+         return lastBone;
 }
 
 float arcLengthRatio(ReebArc *arc)
@@ -5811,7 +5897,7 @@ void generateSkeletonFromReebGraph(Scene *scene, ReebGraph *rg)
        obedit= scene->basact->object;
        
        /* Copy orientation from source */
-       VECCOPY(dst->loc, src->obmat[3]);
+       copy_v3_v3(dst->loc, src->obmat[3]);
        mat4_to_eul( dst->rot,src->obmat);
        mat4_to_size( dst->size,src->obmat);
        
@@ -5819,7 +5905,7 @@ void generateSkeletonFromReebGraph(Scene *scene, ReebGraph *rg)
        
        ED_armature_to_edit(obedit);
 
-       arcBoneMap = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp);
+       arcBoneMap = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "SkeletonFromReebGraph gh");
        
        BLI_markdownSymmetry((BGraph*)rg, rg->nodes.first, scene->toolsettings->skgen_symmetry_limit);
        
@@ -5893,8 +5979,8 @@ void generateSkeletonFromReebGraph(Scene *scene, ReebGraph *rg)
                        bone = ED_armature_edit_bone_add(obedit->data, "Bone");
                        bone->flag |= BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL;
                        
-                       VECCOPY(bone->head, head->p);
-                       VECCOPY(bone->tail, tail->p);
+                       copy_v3_v3(bone->head, head->p);
+                       copy_v3_v3(bone->tail, tail->p);
                        
                        /* set first and last bone, since there's only one */
                        lastBone = bone;
@@ -5958,8 +6044,6 @@ void generateSkeletonFromReebGraph(Scene *scene, ReebGraph *rg)
        }
        
        BLI_ghash_free(arcBoneMap, NULL, NULL);
-       
-       BIF_undo_push("Generate Skeleton");
 }
 
 void generateSkeleton(Scene *scene)