2.5 - Restored most of the remaining Armature/Pose Operators
authorJoshua Leung <aligorith@gmail.com>
Sat, 25 Jul 2009 05:11:28 +0000 (05:11 +0000)
committerJoshua Leung <aligorith@gmail.com>
Sat, 25 Jul 2009 05:11:28 +0000 (05:11 +0000)
* Armature:
- added: fill, merge, separate
- renamed: duplicate, align

* Pose:
- added: apply pose

* Armature Edit menu has been converted to use operators/layout now

release/ui/space_view3d_toolbar.py
source/blender/editors/armature/armature_intern.h
source/blender/editors/armature/armature_ops.c
source/blender/editors/armature/editarmature.c
source/blender/editors/space_view3d/view3d_header.c

index e53b599ee8329009ca69cd35ed0d580051f418fd..0612439f7cfac41775d532dbf77bee2b629afcf6 100644 (file)
@@ -199,7 +199,7 @@ class VIEW3D_PT_tools_editmode_armature(View3DPanel):
 
                col = layout.column(align=True)
                col.itemO("armature.bone_primitive_add", text="Add")
-               col.itemO("armature.duplicate_selected", text="Duplicate")
+               col.itemO("armature.duplicate", text="Duplicate")
                col.itemO("armature.delete", text="Delete")
                
                layout.itemL(text="Modeling:")
index b4ab58930fa051fefe0f271347d4f5c6925ab6d2..471ea6a6ccda29c82f796c0c2232d9bb117175b3 100644 (file)
@@ -34,7 +34,7 @@ struct wmOperatorType;
 /* editarmature.c operators */
 void ARMATURE_OT_bone_primitive_add(struct wmOperatorType *ot);
 
-void ARMATURE_OT_bones_align(struct wmOperatorType *ot);
+void ARMATURE_OT_align(struct wmOperatorType *ot);
 void ARMATURE_OT_calculate_roll(struct wmOperatorType *ot);
 void ARMATURE_OT_switch_direction(struct wmOperatorType *ot);
 
@@ -51,9 +51,13 @@ void ARMATURE_OT_select_hierarchy(struct wmOperatorType *ot);
 void ARMATURE_OT_select_linked(struct wmOperatorType *ot);
 
 void ARMATURE_OT_delete(struct wmOperatorType *ot);
-void ARMATURE_OT_duplicate_selected(struct wmOperatorType *ot);
+void ARMATURE_OT_duplicate(struct wmOperatorType *ot);
 void ARMATURE_OT_extrude(struct wmOperatorType *ot);
 void ARMATURE_OT_click_extrude(struct wmOperatorType *ot);
+void ARMATURE_OT_fill(struct wmOperatorType *ot);
+void ARMATURE_OT_merge(struct wmOperatorType *ot);
+
+void ARMATURE_OT_separate(struct wmOperatorType *ot);
 
 void ARMATURE_OT_autoside_names(struct wmOperatorType *ot);
 void ARMATURE_OT_flip_names(struct wmOperatorType *ot);
@@ -63,6 +67,8 @@ void ARMATURE_OT_flip_names(struct wmOperatorType *ot);
 void POSE_OT_hide(struct wmOperatorType *ot);
 void POSE_OT_reveal(struct wmOperatorType *ot);
 
+void POSE_OT_apply(struct wmOperatorType *ot);
+
 void POSE_OT_rot_clear(struct wmOperatorType *ot);
 void POSE_OT_loc_clear(struct wmOperatorType *ot);
 void POSE_OT_scale_clear(struct wmOperatorType *ot);
index 9d44e8efc349caef0ab0265fa5630a67787dea59..757430a281a96ab8348cd21d8de133637abc5199 100644 (file)
@@ -110,7 +110,7 @@ void ED_operatortypes_armature(void)
        /* EDIT ARMATURE */
        WM_operatortype_append(ARMATURE_OT_bone_primitive_add);
        
-       WM_operatortype_append(ARMATURE_OT_bones_align);
+       WM_operatortype_append(ARMATURE_OT_align);
        WM_operatortype_append(ARMATURE_OT_calculate_roll);
        WM_operatortype_append(ARMATURE_OT_switch_direction);
        WM_operatortype_append(ARMATURE_OT_subdivs);
@@ -126,9 +126,13 @@ void ED_operatortypes_armature(void)
        WM_operatortype_append(ARMATURE_OT_select_linked);
 
        WM_operatortype_append(ARMATURE_OT_delete);
-       WM_operatortype_append(ARMATURE_OT_duplicate_selected);
+       WM_operatortype_append(ARMATURE_OT_duplicate);
        WM_operatortype_append(ARMATURE_OT_extrude);
        WM_operatortype_append(ARMATURE_OT_click_extrude);
+       WM_operatortype_append(ARMATURE_OT_fill);
+       WM_operatortype_append(ARMATURE_OT_merge);
+       
+       WM_operatortype_append(ARMATURE_OT_separate);
        
        WM_operatortype_append(ARMATURE_OT_autoside_names);
        WM_operatortype_append(ARMATURE_OT_flip_names);
@@ -146,6 +150,8 @@ void ED_operatortypes_armature(void)
        WM_operatortype_append(POSE_OT_hide);
        WM_operatortype_append(POSE_OT_reveal);
        
+       WM_operatortype_append(POSE_OT_apply);
+       
        WM_operatortype_append(POSE_OT_rot_clear);
        WM_operatortype_append(POSE_OT_loc_clear);
        WM_operatortype_append(POSE_OT_scale_clear);
@@ -173,7 +179,6 @@ void ED_operatortypes_armature(void)
        WM_operatortype_append(POSE_OT_autoside_names);
        WM_operatortype_append(POSE_OT_flip_names);
        
-       
        /* POSELIB */
        WM_operatortype_append(POSELIB_OT_browse_interactive);
        
@@ -195,7 +200,7 @@ void ED_keymap_armature(wmWindowManager *wm)
        
        /* only set in editmode armature, by space_view3d listener */
 //     WM_keymap_add_item(keymap, "ARMATURE_OT_hide", HKEY, KM_PRESS, 0, 0);
-       WM_keymap_add_item(keymap, "ARMATURE_OT_bones_align", AKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
+       WM_keymap_add_item(keymap, "ARMATURE_OT_align", AKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
        WM_keymap_add_item(keymap, "ARMATURE_OT_calculate_roll", NKEY, KM_PRESS, KM_CTRL, 0);
        
        WM_keymap_add_item(keymap, "ARMATURE_OT_switch_direction", FKEY, KM_PRESS, KM_ALT, 0);
@@ -225,12 +230,17 @@ void ED_keymap_armature(wmWindowManager *wm)
                RNA_boolean_set(kmi->ptr, "extend", 1);
 
        WM_keymap_add_item(keymap, "ARMATURE_OT_select_linked", LKEY, KM_PRESS, 0, 0);
+       
        WM_keymap_add_item(keymap, "ARMATURE_OT_delete", XKEY, KM_PRESS, 0, 0);
-       WM_keymap_add_item(keymap, "ARMATURE_OT_duplicate_selected", DKEY, KM_PRESS, KM_SHIFT, 0);
+       WM_keymap_add_item(keymap, "ARMATURE_OT_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);
        WM_keymap_add_item(keymap, "ARMATURE_OT_extrude", EKEY, KM_PRESS, 0, 0);
        kmi= WM_keymap_add_item(keymap, "ARMATURE_OT_extrude", EKEY, KM_PRESS, KM_SHIFT, 0);
                RNA_boolean_set(kmi->ptr, "forked", 1);
        WM_keymap_add_item(keymap, "ARMATURE_OT_click_extrude", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
+       WM_keymap_add_item(keymap, "ARMATURE_OT_fill", FKEY, KM_PRESS, 0, 0);
+       WM_keymap_add_item(keymap, "ARMATURE_OT_merge", MKEY, KM_PRESS, KM_ALT, 0);
+       
+       WM_keymap_add_item(keymap, "ARMATURE_OT_separate", PKEY, KM_PRESS, /*KM_CTRL|KM_ALT*/0, 0);
        
        /* Armature -> Etch-A-Ton ------------------------ */
        WM_keymap_add_item(keymap, "SKETCH_OT_delete", XKEY, KM_PRESS, 0, 0);
@@ -246,6 +256,9 @@ void ED_keymap_armature(wmWindowManager *wm)
        kmi= WM_keymap_add_item(keymap, "POSE_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0);
                RNA_boolean_set(kmi->ptr, "unselected", 1);
        WM_keymap_add_item(keymap, "POSE_OT_reveal", HKEY, KM_PRESS, KM_ALT, 0);
+       
+       WM_keymap_add_item(keymap, "POSE_OT_apply", AKEY, KM_PRESS, KM_CTRL, 0);
+       
        /*clear pose*/
        WM_keymap_add_item(keymap, "POSE_OT_rot_clear", RKEY, KM_PRESS, KM_ALT, 0);
        WM_keymap_add_item(keymap, "POSE_OT_loc_clear", GKEY, KM_PRESS, KM_ALT, 0);
index cfae8ebb3a9c6f07ab78c5ea085cf09761a314c9..c47b86f326ceb90d0bc02a068ae2e5d7036fb001 100644 (file)
 /* ************* XXX *************** */
 static int okee() {return 0;}
 static int pupmenu() {return 0;}
-static void waitcursor() {};
-static void error() {};
-static void error_libdata() {}
 static void BIF_undo_push() {}
 static void adduplicate() {}
 /* ************* XXX *************** */
@@ -430,25 +427,7 @@ void docenter_armature (Scene *scene, View3D *v3d, Object *ob, int centermode)
                ED_armature_edit_free(ob);
 }
 
-/* helper for apply_armature_pose2bones - fixes parenting of objects that are bone-parented to armature */
-static void applyarmature_fix_boneparents (Scene *scene, Object *armob)
-{
-       Object workob, *ob;
-       
-       /* go through all objects in database */
-       for (ob= G.main->object.first; ob; ob= ob->id.next) {
-               /* if parent is bone in this armature, apply corrections */
-               if ((ob->parent == armob) && (ob->partype == PARBONE)) {
-                       /* apply current transform from parent (not yet destroyed), 
-                        * then calculate new parent inverse matrix
-                        */
-                       ED_object_apply_obmat(ob);
-                       
-                       what_does_parent(scene, ob, &workob);
-                       Mat4Invert(ob->parentinv, workob.obmat);
-               }
-       }
-}
+/* ---------------------- */
 
 static EditBone *editbone_name_exists (ListBase *edbo, char *name)
 {
@@ -490,28 +469,52 @@ void unique_editbone_name (ListBase *edbo, char *name, EditBone *bone)
        }
 }
 
+/* helper for apply_armature_pose2bones - fixes parenting of objects that are bone-parented to armature */
+static void applyarmature_fix_boneparents (Scene *scene, Object *armob)
+{
+       Object workob, *ob;
+       
+       /* go through all objects in database */
+       for (ob= G.main->object.first; ob; ob= ob->id.next) {
+               /* if parent is bone in this armature, apply corrections */
+               if ((ob->parent == armob) && (ob->partype == PARBONE)) {
+                       /* apply current transform from parent (not yet destroyed), 
+                        * then calculate new parent inverse matrix
+                        */
+                       ED_object_apply_obmat(ob);
+                       
+                       what_does_parent(scene, ob, &workob);
+                       Mat4Invert(ob->parentinv, workob.obmat);
+               }
+       }
+}
+
 /* set the current pose as the restpose */
-void apply_armature_pose2bones(Scene *scene, Object *obedit)
+static int apply_armature_pose2bones_exec (bContext *C, wmOperator *op)
 {
-       bArmature *arm= obedit->data;
+       Scene *scene= CTX_data_scene(C);
+       Object *ob= CTX_data_active_object(C); // must be active object, not edit-object
+       bArmature *arm= get_armature(ob);
        bPose *pose;
        bPoseChannel *pchan;
        EditBone *curbone;
        
        /* don't check if editmode (should be done by caller) */
-       if (object_data_is_libdata(obedit)) {
-               error_libdata();
-               return;
+       if (ob->type!=OB_ARMATURE)
+               return OPERATOR_CANCELLED;
+       if (object_data_is_libdata(ob)) {
+               BKE_report(op->reports, RPT_ERROR, "Cannot apply pose to lib-linked armature."); //error_libdata();
+               return OPERATOR_CANCELLED;
        }
        
        /* helpful warnings... */
        // TODO: add warnings to be careful about actions, applying deforms first, etc.
        
        /* Get editbones of active armature to alter */
-       ED_armature_to_edit(obedit);    
+       ED_armature_to_edit(ob);        
        
        /* get pose of active object and move it out of posemode */
-       pose= obedit->pose;
+       pose= ob->pose;
        
        for (pchan=pose->chanbase.first; pchan; pchan=pchan->next) {
                curbone= editbone_name_exists(arm->edbo, pchan->name);
@@ -530,7 +533,7 @@ void apply_armature_pose2bones(Scene *scene, Object *obedit)
                        
                        /* obtain new auto y-rotation */
                        VecSubf(delta, curbone->tail, curbone->head);
-                       vec_roll_to_mat3(delta, 0.0, premat);
+                       vec_roll_to_mat3(delta, 0.0f, premat);
                        Mat3Inv(imat, premat);
                        
                        /* get pchan 'visual' matrix */
@@ -545,26 +548,46 @@ void apply_armature_pose2bones(Scene *scene, Object *obedit)
                }
                
                /* clear transform values for pchan */
-               pchan->loc[0]= pchan->loc[1]= pchan->loc[2]= 0;
-               pchan->quat[1]= pchan->quat[2]= pchan->quat[3]= 0;
-               pchan->quat[0]= pchan->size[0]= pchan->size[1]= pchan->size[2]= 1;
+               pchan->loc[0]= pchan->loc[1]= pchan->loc[2]= 0.0f;
+               pchan->eul[0]= pchan->eul[1]= pchan->eul[2]= 0.0f;
+               pchan->quat[1]= pchan->quat[2]= pchan->quat[3]= 0.0f;
+               pchan->quat[0]= pchan->size[0]= pchan->size[1]= pchan->size[2]= 1.0f;
                
                /* set anim lock */
                curbone->flag |= BONE_UNKEYED;
        }
        
        /* convert editbones back to bones */
-       ED_armature_from_edit(scene, obedit);
+       ED_armature_from_edit(scene, ob);
        
        /* flush positions of posebones */
-       where_is_pose(scene, obedit);
+       where_is_pose(scene, ob);
        
        /* fix parenting of objects which are bone-parented */
-       applyarmature_fix_boneparents(scene, obedit);
+       applyarmature_fix_boneparents(scene, ob);
+       
+       /* note, notifier might evolve */
+       WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, ob);
        
-       BIF_undo_push("Apply new restpose");
+       return OPERATOR_FINISHED;
+}
+
+void POSE_OT_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.";
+       
+       /* callbacks */
+       ot->exec= apply_armature_pose2bones_exec;
+       ot->poll= ED_operator_posemode;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
+/* ---------------------- */
 
 /* Helper function for armature joining - link fixing */
 static void joined_armature_fix_links(Object *tarArm, Object *srcArm, bPoseChannel *pchan, EditBone *curbone)
@@ -669,6 +692,7 @@ 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)
 {
        Scene *scene= CTX_data_scene(C);
@@ -776,6 +800,8 @@ int join_armature_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
+/* ---------------------- */
+
 /* Helper function for armature separating - link fixing */
 static void separated_armature_fix_links(Object *origArm, Object *newArm)
 {
@@ -974,19 +1000,22 @@ static void separate_armature_bones (Scene *scene, Object *ob, short sel)
 }
 
 /* separate selected bones into their armature */
-void separate_armature (Scene *scene, View3D *v3d)
+static int separate_armature_exec (bContext *C, wmOperator *op)
 {
-       Object *obedit= scene->obedit; // XXX get from context
+       Scene *scene= CTX_data_scene(C);
+       Object *obedit= CTX_data_edit_object(C);
        Object *oldob, *newob;
-       Base *base, *oldbase, *newbase;
+       Base *oldbase, *newbase;
        bArmature *arm;
        
-       if ( okee("Separate")==0 ) return;
-
-       waitcursor(1);
-       
+       /* sanity checks */
+       if (obedit == NULL)
+               return OPERATOR_CANCELLED;
        arm= obedit->data;
        
+       /* set wait cursor in case this takes a while */
+       WM_cursor_wait(1);
+       
        /* we are going to do this as follows (unlike every other instance of separate):
         *      1. exit editmode +posemode for active armature/base. Take note of what this is.
         *      2. duplicate base - BASACT is the new one now
@@ -996,13 +1025,12 @@ void separate_armature (Scene *scene, View3D *v3d)
         */
        
        /* 1) only edit-base selected */
-       base= FIRSTBASE;
-       for (base= FIRSTBASE; base; base= base->next) {
-               if (base->lay & v3d->lay) {
-                       if (base->object==obedit) base->flag |= 1;
-                       else base->flag &= ~1;
-               }
+       // TODO: use context iterators for this?
+       CTX_DATA_BEGIN(C, Base *, base, visible_bases) {
+               if (base->object==obedit) base->flag |= 1;
+               else base->flag &= ~1;
        }
+       CTX_DATA_END;
        
        /* 1) store starting settings and exit editmode */
        oldob= obedit;
@@ -1040,10 +1068,29 @@ void separate_armature (Scene *scene, View3D *v3d)
        
        ED_armature_to_edit(obedit);
        
+       /* note, notifier might evolve */
+       WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, obedit);
+       
        /* recalc/redraw + cleanup */
-       waitcursor(0);
+       WM_cursor_wait(0);
        
-       BIF_undo_push("Separate Armature");
+       return OPERATOR_FINISHED;
+}
+
+void ARMATURE_OT_separate (wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Separate Armature";
+       ot->idname= "ARMATURE_OT_separate";
+       ot->description= "Isolate selected bones into a separate armature.";
+       
+       /* callbacks */
+       ot->invoke= WM_operator_confirm;
+       ot->exec= separate_armature_exec;
+       ot->poll= ED_operator_editarmature;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
 /* **************** END tools on Editmode Armature **************** */
@@ -2640,11 +2687,11 @@ static int armature_duplicate_selected_invoke(bContext *C, wmOperator *op, wmEve
        return retv;
 }
 
-void ARMATURE_OT_duplicate_selected(wmOperatorType *ot)
+void ARMATURE_OT_duplicate(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Duplicate Selected Bone(s)";
-       ot->idname= "ARMATURE_OT_duplicate_selected";
+       ot->idname= "ARMATURE_OT_duplicate";
        
        /* api callbacks */
        ot->invoke = armature_duplicate_selected_invoke;
@@ -2719,6 +2766,7 @@ static void chains_find_tips (ListBase *edbo, ListBase *list)
        }
 }
 
+/* --------------------- */
 
 static void fill_add_joint (EditBone *ebo, short eb_tail, ListBase *points)
 {
@@ -2772,23 +2820,29 @@ static void fill_add_joint (EditBone *ebo, short eb_tail, ListBase *points)
 }
 
 /* bone adding between selected joints */
-void fill_bones_armature(Scene *scene, View3D *v3d)
+static int armature_fill_bones_exec (bContext *C, wmOperator *op)
 {
-       Object *obedit= scene->obedit; // XXX get from context
-       bArmature *arm= obedit->data;
-       EditBone *ebo, *newbone=NULL;
+       Object *obedit= CTX_data_edit_object(C);
+       bArmature *arm= (obedit) ? obedit->data : NULL;
+       Scene *scene= CTX_data_scene(C);
+       View3D *v3d= (View3D *)CTX_wm_space_data(C);
+       EditBone *newbone=NULL;
        ListBase points = {NULL, NULL};
        int count;
        
+       /* sanity checks */
+       if ELEM(NULL, obedit, arm)
+               return OPERATOR_CANCELLED;
+       
        /* loop over all bones, and only consider if visible */
-       for (ebo= arm->edbo->first; ebo; ebo= ebo->next) {
-               if (EBONE_VISIBLE(arm, ebo)) {
-                       if (!(ebo->flag & BONE_CONNECTED) && (ebo->flag & BONE_ROOTSEL))
-                               fill_add_joint(ebo, 0, &points);
-                       if (ebo->flag & BONE_TIPSEL) 
-                               fill_add_joint(ebo, 1, &points);
-               }
+       CTX_DATA_BEGIN(C, EditBone *, ebone, visible_bones)
+       {
+               if (!(ebone->flag & BONE_CONNECTED) && (ebone->flag & BONE_ROOTSEL))
+                       fill_add_joint(ebone, 0, &points);
+               if (ebone->flag & BONE_TIPSEL) 
+                       fill_add_joint(ebone, 1, &points);
        }
+       CTX_DATA_END;
        
        /* the number of joints determines how we fill:
         *      1) between joint and cursor (joint=head, cursor=tail)
@@ -2798,8 +2852,8 @@ void fill_bones_armature(Scene *scene, View3D *v3d)
        count= BLI_countlist(&points);
        
        if (count == 0) {
-               error("No joints selected");
-               return;
+               BKE_report(op->reports, RPT_ERROR, "No joints selected");
+               return OPERATOR_CANCELLED;
        }
        else if (count == 1) {
                EditBonePoint *ebp;
@@ -2828,14 +2882,14 @@ void fill_bones_armature(Scene *scene, View3D *v3d)
                ebp2= ebp->next;
                
                if ((ebp->head_owner==ebp2->tail_owner) && (ebp->head_owner!=NULL)) {
-                       error("Same bone selected...");
+                       BKE_report(op->reports, RPT_ERROR, "Same bone selected...");
                        BLI_freelistN(&points);
-                       return;
+                       return OPERATOR_CANCELLED;
                }
                if ((ebp->tail_owner==ebp2->head_owner) && (ebp->tail_owner!=NULL)) {
-                       error("Same bone selected...");
+                       BKE_report(op->reports, RPT_ERROR, "Same bone selected...");
                        BLI_freelistN(&points);
-                       return;
+                       return OPERATOR_CANCELLED;
                }
                
                /* find which one should be the 'head' */
@@ -2902,19 +2956,35 @@ void fill_bones_armature(Scene *scene, View3D *v3d)
        }
        else {
                // FIXME.. figure out a method for multiple bones
-               error("Too many points selected"); 
+               BKE_report(op->reports, RPT_ERROR, "Too many points selected"); 
                printf("Points selected: %d \n", count);
                BLI_freelistN(&points);
-               return;
+               return OPERATOR_CANCELLED;
        }
        
        /* free points */
        BLI_freelistN(&points);
        
-       /* undo + updates */
-       BIF_undo_push("Fill Bones");
+       return OPERATOR_FINISHED;
 }
 
+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.";
+       
+       /* callbacks */
+       ot->exec= armature_fill_bones_exec;
+       ot->poll= ED_operator_editarmature;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+/* --------------------- */
+
 /* this function merges between two bones, removes them and those in-between, 
  * and adjusts the parent relationships for those in-between
  */
@@ -2984,19 +3054,19 @@ static void bones_merge(Object *obedit, EditBone *start, EditBone *end, EditBone
        }
 }
 
-/* bone merging - has a menu! */
-void merge_armature(Scene *scene)
+
+static int armature_merge_exec (bContext *C, wmOperator *op)
 {
-       Object *obedit= scene->obedit; // XXX get from context
-       bArmature *arm= obedit->data;
-       short val= 0;
+       Object *obedit= CTX_data_edit_object(C);
+       bArmature *arm= (obedit) ? obedit->data : NULL;
+       short type= RNA_enum_get(op->ptr, "type");
        
-       /* process a menu to determine how to merge */
-       // TODO: there's room for more modes of merging stuff...
-       val= pupmenu("Merge Selected Bones%t|Within Chains%x1");
-       if (val <= 0) return;
+       /* sanity checks */
+       if ELEM(NULL, obedit, arm)
+               return OPERATOR_CANCELLED;
        
-       if (val == 1) {
+       /* for now, there's only really one type of merging that's performed... */
+       if (type == 1) {
                /* go down chains, merging bones */
                ListBase chains = {NULL, NULL};
                LinkData *chain, *nchain;
@@ -3004,7 +3074,7 @@ void merge_armature(Scene *scene)
                
                /* get chains (ends on chains) */
                chains_find_tips(arm->edbo, &chains);
-               if (chains.first == NULL) return;
+               if (chains.first == NULL) return OPERATOR_CANCELLED;
                
                /* each 'chain' is the last bone in the chain (with no children) */
                for (chain= chains.first; chain; chain= nchain) {
@@ -3052,9 +3122,35 @@ void merge_armature(Scene *scene)
                BLI_freelistN(&chains);
        }
        
-       /* undo + updates */
+       /* updates */
        ED_armature_sync_selection(arm->edbo);
-       BIF_undo_push("Merge Bones");
+       WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, obedit);
+       
+       return OPERATOR_FINISHED;
+}
+
+void ARMATURE_OT_merge (wmOperatorType *ot)
+{
+       static EnumPropertyItem merge_types[] = {
+               {1, "WITHIN_CHAIN", 0, "Within Chains", ""},
+               {0, NULL, 0, NULL, NULL}
+       };
+
+       /* identifiers */
+       ot->name= "Merge Bones";
+       ot->idname= "ARMATURE_OT_merge";
+       ot->description= "Merge continuous chains of selected bones.";
+       
+       /* callbacks */
+       ot->invoke= WM_menu_invoke;
+       ot->exec= armature_merge_exec;
+       ot->poll= ED_operator_editarmature;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       /* properties */
+       RNA_def_enum(ot->srna, "type", merge_types, 0, "Type", "");
 }
 
 /* ************** END Add/Remove stuff in editmode ************ */
@@ -4109,11 +4205,12 @@ static int armature_align_bones_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void ARMATURE_OT_bones_align(wmOperatorType *ot)
+void ARMATURE_OT_align(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Align Bones";
-       ot->idname= "ARMATURE_OT_bones_align";
+       ot->idname= "ARMATURE_OT_align";
+       ot->description= "Align selected bones to the active bone (or to their parent).";
        
        /* api callbacks */
        ot->invoke = WM_operator_confirm;
index a00b79e4139f213ffbca42fd02ac051b7c088acb..abf170c9549fb4f315f577094ab51f0cdfa55d35 100644 (file)
@@ -2738,70 +2738,34 @@ static void view3d_edit_latticemenu(bContext *C, uiLayout *layout, void *arg_unu
        uiItemMenuEnumR(layout, NULL, 0, &tsptr, "proportional_editing_falloff"); // |Shift O
 }
 
-void do_view3d_edit_armature_parentmenu(bContext *C, void *arg, int event)
-{
-#if 0
-       switch(event) {
-       case 1:
-               make_bone_parent();
-               break;
-       case 2:
-               clear_bone_parent();
-               break;
-               }
-#endif
-}
 
-static uiBlock *view3d_edit_armature_parentmenu(bContext *C, ARegion *ar, void *arg_unused)
+static void view3d_edit_armature_parentmenu(bContext *C, uiLayout *layout, void *arg_unused)
 {
-       uiBlock *block;
-       short yco = 20, menuwidth = 120;
-
-       block= uiBeginBlock(C, ar, "view3d_edit_armature_parentmenu", UI_EMBOSSP);
-       uiBlockSetButmFunc(block, do_view3d_edit_armature_parentmenu, NULL);
-       
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Make Parent...|Ctrl P",  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Clear Parent...|Alt P",  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
-
-       uiBlockSetDirection(block, UI_RIGHT);
-       uiTextBoundsBlock(block, 60);
-       return block;
+       uiItemO(layout, NULL, 0, "ARMATURE_OT_parent_set");
+       uiItemO(layout, NULL, 0, "ARMATURE_OT_parent_clear");
 }
 
+#if 0
 void do_view3d_edit_armature_rollmenu(bContext *C, void *arg, int event)
 {
-#if 0
-       if (event == 1 || event == 2)
-               /* set roll based on aligning z-axis */
-               auto_align_armature(event);
-       else if (event == 3) {
-               /* interactively set bone roll */
+               /* "Set Roll|Ctrl R" - interactively set bone roll */
                initTransform(TFM_BONE_ROLL, CTX_NONE);
                Transform();
-       }
-#endif
 }
+#endif
 
-static uiBlock *view3d_edit_armature_rollmenu(bContext *C, ARegion *ar, void *arg_unused)
+static void view3d_edit_armature_rollmenu(bContext *C, uiLayout *layout, void *arg_unused)
 {
-       uiBlock *block;
-       short yco = 20, menuwidth = 120;
-
-       block= uiBeginBlock(C, ar, "view3d_edit_armature_rollmenu", UI_EMBOSSP);
-       uiBlockSetButmFunc(block, do_view3d_edit_armature_rollmenu, NULL);
-       
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Clear Roll (Z-Axis Up)|Ctrl N, 1",       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Roll to Cursor|Ctrl N, 2", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
-
-       uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
-       
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Set Roll|Ctrl R", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
+       /* 0 = 'Global', 1 = 'Cursor' */
+       // TODO: keep these in sync...
+       uiItemEnumO(layout, "Clear Roll (Z-Axis Up)", 0, "ARMATURE_OT_calculate_roll", "type", 0);
+       uiItemEnumO(layout, "Roll to Cursor", 0, "ARMATURE_OT_calculate_roll", "type", 1);
        
-       uiBlockSetDirection(block, UI_RIGHT);
-       uiTextBoundsBlock(block, 60);
-       return block;
+       //uiDefBut(block, SEPR, 0, "",                          0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
+       //uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Set Roll|Ctrl R", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
 }
 
+#if 0
 static void do_view3d_edit_armaturemenu(bContext *C, void *arg, int event)
 {
 #if 0
@@ -2811,18 +2775,7 @@ static void do_view3d_edit_armaturemenu(bContext *C, void *arg, int event)
        case 0: /* Undo Editing */
                remake_editArmature();
                break;
-       case 1: /* transformation properties */
-// XXX         mainqenter(NKEY, 1);
-               break;
-       case 3: /* extrude */
-               extrude_armature(0);
-               break;
-       case 4: /* duplicate */
-               duplicate_context_selected();
-               break;
-       case 5: /* delete */
-               delete_context_selected();
-               break;
+       
        case 6: /* Shear */
                initTransform(TFM_SHEAR, CTX_NONE);
                Transform();
@@ -2833,17 +2786,7 @@ static void do_view3d_edit_armaturemenu(bContext *C, void *arg, int event)
        case 10: /* forked! */
                extrude_armature(1);
                break;
-       case 12: /* subdivide */
-               subdivide_armature(1);
-               break;
-       case 13: /* flip left and right names */
-               armature_flip_names();
-               break;
-       case 15: /* subdivide multi */
-               if(button(&numcuts, 1, 128, "Number of Cuts:")==0) return;
-               waitcursor(1);
-               subdivide_armature(numcuts);
-               break;
+       
        case 16: /* Alt-S transform (BoneSize) */
                initTransform(TFM_BONESIZE, CTX_NONE);
                Transform();
@@ -2851,17 +2794,7 @@ static void do_view3d_edit_armaturemenu(bContext *C, void *arg, int event)
        case 17: /* move to layer */
                pose_movetolayer();
                break;
-       case 18: /* merge bones */
-               merge_armature();
-               break;
-       case 19: /* auto-extensions */
-       case 20:
-       case 21:
-               armature_autoside_names(event-19);      
-               break;
-       case 22: /* separate */
-               separate_armature();
-               break;
+       
        case 23: /* bone sketching panel */
                add_blockhandler(curarea, VIEW3D_HANDLER_BONESKETCH, UI_PNL_UNSTOW);
                break;
@@ -2927,81 +2860,73 @@ static uiBlock *view3d_armature_settingsmenu(bContext *C, ARegion *ar, void *arg
 
        return block;
 }
+#endif
 
-static uiBlock *view3d_edit_armaturemenu(bContext *C, ARegion *ar, void *arg_unused)
+static void view3d_edit_armaturemenu(bContext *C, uiLayout *layout, void *arg_unused)
 {
        Object *obedit = CTX_data_edit_object(C);
        bArmature *arm= obedit->data;
-       uiBlock *block;
-       short yco= 0, menuwidth=120;
-       
-       block= uiBeginBlock(C, ar, "view3d_edit_armaturemenu", UI_EMBOSSP);
-       uiBlockSetButmFunc(block, do_view3d_edit_armaturemenu, NULL);
-       
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Undo Editing|U",         0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
-       
-       uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
        
+       //uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Undo Editing|U",               0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
+
+#if 0
        uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Transform Properties|N", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
        uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Bone Sketching|P", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 23, "");
        uiDefIconTextBlockBut(block, view3d_transformmenu, NULL, ICON_RIGHTARROW_THIN, "Transform", 0, yco-=20, 120, 19, "");
        uiDefIconTextBlockBut(block, view3d_edit_mirrormenu, NULL, ICON_RIGHTARROW_THIN, "Mirror", 0, yco-=20, menuwidth, 19, "");
        // XXX uiDefIconTextBlockBut(block, view3d_edit_snapmenu, NULL, ICON_RIGHTARROW_THIN, "Snap", 0, yco-=20, 120, 19, "");
-       uiDefIconTextBlockBut(block, view3d_edit_armature_rollmenu, NULL, ICON_RIGHTARROW_THIN, "Bone Roll", 0, yco-=20, 120, 19, "");
+#endif
+       uiItemMenuF(layout, "Bone Roll", 0, view3d_edit_armature_rollmenu);
        
+#if 0
        if (arm->drawtype==ARM_ENVELOPE)
                uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Scale Envelope Distance|Alt S",  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 16, "");
        else if (arm->drawtype==ARM_B_BONE)
                uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Scale B-Bone Width|Alt S",       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 16, "");
+#endif 
        
-       uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
-
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Extrude|E",                              0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
+       uiItemS(layout);
+       
+       uiItemO(layout, "Extrude", 0, "ARMATURE_OT_extrude");
        if (arm->flag & ARM_MIRROR_EDIT)
-               uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Extrude Forked|Shift E", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 10, "");
-               
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Duplicate|Shift D",              0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Merge|Alt M",                            0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 18, "");
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Fill Between Joints|F",                          0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 18, "");
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Delete|X",                               0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
+               uiItemBooleanO(layout, "Extrude Forked", 0, "ARMATURE_OT_extrude", "forked", 1);
        
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Separate|Ctrl Alt P",                            0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 22, "");
+       uiItemO(layout, NULL, 0, "ARMATURE_OT_duplicate");
+       uiItemO(layout, NULL, 0, "ARMATURE_OT_merge");
+       uiItemO(layout, NULL, 0, "ARMATURE_OT_fill");
+       uiItemO(layout, NULL, 0, "ARMATURE_OT_delete");
+       uiItemO(layout, NULL, 0, "ARMATURE_OT_separate");
        
-       uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
+       uiItemS(layout);
        
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Subdivide|W, 1",                 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 12, "");
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Subdivide Multi|W, 2",                   0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 15, "");
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Flip Left & Right Names|W, 3",   0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 13, "");
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "AutoName Left-Right|W, 4",                       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 19, "");
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "AutoName Front-Back|W, 5",                       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 20, "");
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "AutoName Top-Bottom|W, 6",                       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 21, "");
+       uiItemO(layout, NULL, 0, "ARMATURE_OT_subdivide_simple");
+       uiItemO(layout, NULL, 0, "ARMATURE_OT_subdivide_multi");
        
-       uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
+       uiItemEnumO(layout, "AutoName Left/Right", 0, "ARMATURE_OT_autoside_names", "axis", 0);
+       uiItemEnumO(layout, "AutoName Front/Back", 0, "ARMATURE_OT_autoside_names", "axis", 1);
+       uiItemEnumO(layout, "AutoName Top/Bottom", 0, "ARMATURE_OT_autoside_names", "axis", 2);
+       
+       uiItemO(layout, "Flip Left/Right Names", 0, "ARMATURE_OT_flip_names");
        
+       uiItemS(layout);
+       
+#if 0
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Switch Armature Layers|Shift M", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 17, "");
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Move Bone To Layer|M",   0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 17, "");
                
        uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
+#endif
        
-       uiDefIconTextBlockBut(block, view3d_edit_armature_parentmenu, NULL, ICON_RIGHTARROW_THIN, "Parent", 0, yco-=20, 120, 19, "");
-       uiDefIconTextBlockBut(block, view3d_armature_settingsmenu, NULL, ICON_RIGHTARROW_THIN, "Bone Settings", 0, yco-=20, 120, 19, "");
+       uiItemMenuF(layout, "Parent", 0, view3d_edit_armature_parentmenu);
+       //uiDefIconTextBlockBut(block, view3d_armature_settingsmenu, NULL, ICON_RIGHTARROW_THIN, "Bone Settings", 0, yco-=20, 120, 19, "");
        
+#if 0
 #ifndef DISABLE_PYTHON
        uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
        
        uiDefIconTextBlockBut(block, view3d_scripts_armaturemenu, NULL, ICON_RIGHTARROW_THIN, "Scripts", 0, yco-=20, 120, 19, "");
 #endif
-       if(ar->alignment==RGN_ALIGN_TOP) {
-               uiBlockSetDirection(block, UI_DOWN);
-       }
-       else {
-               uiBlockSetDirection(block, UI_TOP);
-               uiBlockFlipOrder(block);
-       }
-
-       uiTextBoundsBlock(block, 50);
-       
-       return block;
+#endif
 }
 
 
@@ -3146,10 +3071,10 @@ static void view3d_pose_armaturemenu(bContext *C, uiLayout *layout, void *arg_un
        
 #if 0
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Relax Pose|W",                           0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 15, "");
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Apply Pose as Restpose|Ctrl A",          0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 19, "");
-
-       uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
 #endif
+       uiItemO(layout, NULL, 0, "POSE_OT_apply");
+       
+       uiItemS(layout);
        
        uiItemO(layout, "Copy Current Pose", 0, "POSE_OT_copy");
        uiItemO(layout, "Paste Pose", 0, "POSE_OT_paste");
@@ -3168,11 +3093,11 @@ static void view3d_pose_armaturemenu(bContext *C, uiLayout *layout, void *arg_un
        
        uiItemS(layout);
        
-       uiItemEnumO(layout, "AutoName Left-Right", 0, "POSE_OT_autoside_names", "axis", 0);
-       uiItemEnumO(layout, "AutoName Front-Back", 0, "POSE_OT_autoside_names", "axis", 1);
-       uiItemEnumO(layout, "AutoName Top-Bottom", 0, "POSE_OT_autoside_names", "axis", 2);
+       uiItemEnumO(layout, "AutoName Left/Right", 0, "POSE_OT_autoside_names", "axis", 0);
+       uiItemEnumO(layout, "AutoName Front/Back", 0, "POSE_OT_autoside_names", "axis", 1);
+       uiItemEnumO(layout, "AutoName Top/Bottom", 0, "POSE_OT_autoside_names", "axis", 2);
        
-       uiItemO(layout, "Flip L/R Names", 0, "POSE_OT_flip_names");
+       uiItemO(layout, "Flip Left/Right Names", 0, "POSE_OT_flip_names");
        
        //separator + move layer operators...
        
@@ -4143,7 +4068,7 @@ static void view3d_header_pulldowns(const bContext *C, uiBlock *block, Object *o
                        xco+= xmax;
                } else if (ob && ob->type == OB_ARMATURE) {
                        xmax= GetButStringLength("Armature");
-                       uiDefPulldownBut(block, view3d_edit_armaturemenu, NULL, "Armature",     xco,yco, xmax-3, 20, "");
+                       uiDefMenuBut(block, view3d_edit_armaturemenu, NULL, "Armature", xco,yco, xmax-3, 20, "");
                        xco+= xmax;
                }