2.5 - Restored 'AutoSide Name' and 'Flip Names' operators for both PoseMode and Edit...
authorJoshua Leung <aligorith@gmail.com>
Fri, 24 Jul 2009 13:02:16 +0000 (13:02 +0000)
committerJoshua Leung <aligorith@gmail.com>
Fri, 24 Jul 2009 13:02:16 +0000 (13:02 +0000)
Only the PoseMode menus work for now (since these use operators)

source/blender/editors/armature/armature_intern.h
source/blender/editors/armature/armature_ops.c
source/blender/editors/armature/editarmature.c
source/blender/editors/armature/poseobject.c
source/blender/editors/include/ED_armature.h
source/blender/editors/space_view3d/view3d_header.c

index c37f6803d5811b39da1d392f745d58a89ab94f2b..b4ab58930fa051fefe0f271347d4f5c6925ab6d2 100644 (file)
@@ -55,6 +55,9 @@ void ARMATURE_OT_duplicate_selected(struct wmOperatorType *ot);
 void ARMATURE_OT_extrude(struct wmOperatorType *ot);
 void ARMATURE_OT_click_extrude(struct wmOperatorType *ot);
 
+void ARMATURE_OT_autoside_names(struct wmOperatorType *ot);
+void ARMATURE_OT_flip_names(struct wmOperatorType *ot);
+
 /* ******************************************************* */
 /* Pose-Mode Operators */
 void POSE_OT_hide(struct wmOperatorType *ot);
@@ -67,9 +70,6 @@ void POSE_OT_scale_clear(struct wmOperatorType *ot);
 void POSE_OT_copy(struct wmOperatorType *ot);
 void POSE_OT_paste(struct wmOperatorType *ot);
 
-void POSE_OT_paths_calculate(struct wmOperatorType *ot);
-void POSE_OT_paths_clear(struct wmOperatorType *ot);
-
 void POSE_OT_select_all_toggle(struct wmOperatorType *ot);
 void POSE_OT_select_inverse(struct wmOperatorType *ot);
 void POSE_OT_select_parent(struct wmOperatorType *ot);
@@ -84,6 +84,12 @@ void POSE_OT_group_remove(struct wmOperatorType *ot);
 void POSE_OT_group_assign(struct wmOperatorType *ot);
 void POSE_OT_group_unassign(struct wmOperatorType *ot);
 
+void POSE_OT_paths_calculate(struct wmOperatorType *ot);
+void POSE_OT_paths_clear(struct wmOperatorType *ot);
+
+void POSE_OT_autoside_names(struct wmOperatorType *ot);
+void POSE_OT_flip_names(struct wmOperatorType *ot);
+
 /* ******************************************************* */
 /* Etch-A-Ton */
 
index 5495147acb00b8c783bfbc03296a49ea16cab6de..9d44e8efc349caef0ab0265fa5630a67787dea59 100644 (file)
@@ -129,6 +129,9 @@ void ED_operatortypes_armature(void)
        WM_operatortype_append(ARMATURE_OT_duplicate_selected);
        WM_operatortype_append(ARMATURE_OT_extrude);
        WM_operatortype_append(ARMATURE_OT_click_extrude);
+       
+       WM_operatortype_append(ARMATURE_OT_autoside_names);
+       WM_operatortype_append(ARMATURE_OT_flip_names);
 
        /* SKETCH */    
        WM_operatortype_append(SKETCH_OT_gesture);
@@ -150,9 +153,6 @@ void ED_operatortypes_armature(void)
        WM_operatortype_append(POSE_OT_copy);
        WM_operatortype_append(POSE_OT_paste);
        
-       WM_operatortype_append(POSE_OT_paths_calculate);
-       WM_operatortype_append(POSE_OT_paths_clear);
-       
        WM_operatortype_append(POSE_OT_select_all_toggle);
        WM_operatortype_append(POSE_OT_select_inverse);
 
@@ -167,6 +167,13 @@ void ED_operatortypes_armature(void)
        WM_operatortype_append(POSE_OT_group_assign);
        WM_operatortype_append(POSE_OT_group_unassign);
        
+       WM_operatortype_append(POSE_OT_paths_calculate);
+       WM_operatortype_append(POSE_OT_paths_clear);
+       
+       WM_operatortype_append(POSE_OT_autoside_names);
+       WM_operatortype_append(POSE_OT_flip_names);
+       
+       
        /* POSELIB */
        WM_operatortype_append(POSELIB_OT_browse_interactive);
        
index 68d8ffbc11d86ef7e52927470d5b2337eb6ea473..2da49731a9585fa20e9a4ac2cae0a71bf3fd2eab 100644 (file)
@@ -5227,48 +5227,111 @@ void ED_armature_bone_rename(bArmature *arm, char *oldnamep, char *newnamep)
        }
 }
 
-/* context editmode object */
-void armature_flip_names(Scene *scene)
+
+static int armature_flip_names_exec (bContext *C, wmOperator *op)
 {
-       Object *obedit= scene->obedit; // XXX get from context
-       bArmature *arm= obedit->data;
-       EditBone *ebone;
+       Scene *scene= CTX_data_scene(C);
+       Object *ob= CTX_data_edit_object(C);
+       bArmature *arm;
        char newname[32];
        
-       for (ebone = arm->edbo->first; ebone; ebone=ebone->next) {
-               if (arm->layer & ebone->layer) {
-                       if (ebone->flag & BONE_SELECTED) {
-                               BLI_strncpy(newname, ebone->name, sizeof(newname));
-                               bone_flip_name(newname, 1);             // 1 = do strip off number extensions
-                               ED_armature_bone_rename(arm, ebone->name, newname);
-                       }
-               }
+       /* paranoia checks */
+       if (ELEM(NULL, ob, ob->pose)) 
+               return OPERATOR_CANCELLED;
+       arm= ob->data;
+       
+       /* 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
+               ED_armature_bone_rename(arm, ebone->name, newname);
        }
+       CTX_DATA_END;
+       
+       /* since we renamed stuff... */
+       DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
+
+       /* note, notifier might evolve */
+       WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob);
        
-       BIF_undo_push("Flip names");
+       return OPERATOR_FINISHED;
 }
 
-/* context: edtimode armature */
-void armature_autoside_names(Scene *scene, short axis)
+void ARMATURE_OT_flip_names (wmOperatorType *ot)
 {
-       Object *obedit= scene->obedit; // XXX get from context
-       bArmature *arm= obedit->data;
-       EditBone *ebone;
+       /* identifiers */
+       ot->name= "Flip Names";
+       ot->idname= "ARMATURE_OT_flip_names";
+       ot->description= "Flips (and corrects) the names of selected bones.";
+       
+       /* api callbacks */
+       ot->exec= armature_flip_names_exec;
+       ot->poll= ED_operator_editarmature;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+
+static int armature_autoside_names_exec (bContext *C, wmOperator *op)
+{
+       Scene *scene= CTX_data_scene(C);
+       Object *ob= CTX_data_edit_object(C);
+       bArmature *arm;
        char newname[32];
+       short axis= RNA_enum_get(op->ptr, "axis");
        
-       for (ebone = arm->edbo->first; ebone; ebone=ebone->next) {
-               if (arm->layer & ebone->layer) {
-                       if (ebone->flag & BONE_SELECTED) {
-                               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);
-                       }
-               }
+       /* paranoia checks */
+       if (ELEM(NULL, ob, ob->pose)) 
+               return OPERATOR_CANCELLED;
+       arm= ob->data;
+       
+       /* loop through selected bones, auto-naming them */
+       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);
        }
+       CTX_DATA_END;
+       
+       /* since we renamed stuff... */
+       DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
+
+       /* note, notifier might evolve */
+       WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob);
        
-       BIF_undo_push("Auto-side name");
+       return OPERATOR_FINISHED;
 }
 
+void ARMATURE_OT_autoside_names (wmOperatorType *ot)
+{
+       static EnumPropertyItem axis_items[]= {
+               {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}};
+       
+       /* 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.";
+       
+       /* api callbacks */
+       ot->invoke= WM_menu_invoke;
+       ot->exec= armature_autoside_names_exec;
+       ot->poll= ED_operator_editarmature;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       /* settings */
+       RNA_def_enum(ot->srna, "axis", axis_items, 0, "Axis", "Axis tag names with.");
+}
+
+
+
 /* if editbone (partial) selected, copy data */
 /* context; editmode armature, with mirror editing enabled */
 void transform_armature_mirror_update(Object *obedit)
index d0bc36b5f09b84f5429da6a9300765694d10f1da..e9ebdb87a3cd04b02b470359fee285e18032b877 100644 (file)
@@ -1534,64 +1534,111 @@ void pose_select_grouped_menu (Scene *scene)
 
 /* ********************************************** */
 
-/* context active object */
-void pose_flip_names(Scene *scene)
+static int pose_flip_names_exec (bContext *C, wmOperator *op)
 {
-       Object *obedit= scene->obedit; // XXX context
-       Object *ob= OBACT;
-       bArmature *arm= ob->data;
-       bPoseChannel *pchan;
+       Scene *scene= CTX_data_scene(C);
+       Object *ob= CTX_data_active_object(C);
+       bArmature *arm;
        char newname[32];
        
        /* paranoia checks */
-       if(!ob && !ob->pose) return;
-       if(ob==obedit || (ob->flag & OB_POSEMODE)==0) return;
-       
-       if(pose_has_protected_selected(ob, 0, 1))
-               return;
+       if (ELEM(NULL, ob, ob->pose)) 
+               return OPERATOR_CANCELLED;
+       arm= ob->data;
        
-       for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
-               if(arm->layer & pchan->bone->layer) {
-                       if(pchan->bone->flag & (BONE_ACTIVE|BONE_SELECTED)) {
-                               BLI_strncpy(newname, pchan->name, sizeof(newname));
-                               bone_flip_name(newname, 1);     // 1 = do strip off number extensions
-                               ED_armature_bone_rename(arm, pchan->name, newname);
-                       }
-               }
+       /* loop through selected bones, auto-naming them */
+       CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pchans)
+       {
+               BLI_strncpy(newname, pchan->name, sizeof(newname));
+               bone_flip_name(newname, 1);     // 1 = do strip off number extensions
+               ED_armature_bone_rename(arm, pchan->name, newname);
        }
+       CTX_DATA_END;
        
-       BIF_undo_push("Flip names");
+       /* since we renamed stuff... */
+       DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
+
+       /* note, notifier might evolve */
+       WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob);
+       
+       return OPERATOR_FINISHED;
 }
 
-/* context active object */
-void pose_autoside_names(Scene *scene, short axis)
+void POSE_OT_flip_names (wmOperatorType *ot)
 {
-       Object *obedit= scene->obedit; // XXX context
-       Object *ob= OBACT;
-       bArmature *arm= ob->data;
-       bPoseChannel *pchan;
+       /* identifiers */
+       ot->name= "Flip Names";
+       ot->idname= "POSE_OT_flip_names";
+       ot->description= "Flips (and corrects) the names of selected bones.";
+       
+       /* api callbacks */
+       ot->exec= pose_flip_names_exec;
+       ot->poll= ED_operator_posemode;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+/* ------------------ */
+
+static int pose_autoside_names_exec (bContext *C, wmOperator *op)
+{
+       Scene *scene= CTX_data_scene(C);
+       Object *ob= CTX_data_active_object(C);
+       bArmature *arm;
        char newname[32];
+       short axis= RNA_enum_get(op->ptr, "axis");
        
        /* paranoia checks */
-       if (ELEM(NULL, ob, ob->pose)) return;
-       if (ob==obedit || (ob->flag & OB_POSEMODE)==0) return;
-       
-       if (pose_has_protected_selected(ob, 0, 1))
-               return;
+       if (ELEM(NULL, ob, ob->pose)) 
+               return OPERATOR_CANCELLED;
+       arm= ob->data;
        
-       for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
-               if(arm->layer & pchan->bone->layer) {
-                       if(pchan->bone->flag & (BONE_ACTIVE|BONE_SELECTED)) {
-                               BLI_strncpy(newname, pchan->name, sizeof(newname));
-                               bone_autoside_name(newname, 1, axis, pchan->bone->head[axis], pchan->bone->tail[axis]);
-                               ED_armature_bone_rename(arm, pchan->name, newname);
-                       }
-               }
+       /* loop through selected bones, auto-naming them */
+       CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pchans)
+       {
+               BLI_strncpy(newname, pchan->name, sizeof(newname));
+               bone_autoside_name(newname, 1, axis, pchan->bone->head[axis], pchan->bone->tail[axis]);
+               ED_armature_bone_rename(arm, pchan->name, newname);
        }
+       CTX_DATA_END;
+       
+       /* since we renamed stuff... */
+       DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
+
+       /* note, notifier might evolve */
+       WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob);
        
-       BIF_undo_push("Flip names");
+       return OPERATOR_FINISHED;
 }
 
+void POSE_OT_autoside_names (wmOperatorType *ot)
+{
+       static EnumPropertyItem axis_items[]= {
+               {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}};
+       
+       /* identifiers */
+       ot->name= "AutoName by Axis";
+       ot->idname= "POSE_OT_autoside_names";
+       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;
+       ot->exec= pose_autoside_names_exec;
+       ot->poll= ED_operator_posemode;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       /* settings */
+       RNA_def_enum(ot->srna, "axis", axis_items, 0, "Axis", "Axis tag names with.");
+}
+
+/* ********************************************** */
+
 /* context active object, or weightpainted object with armature in posemode */
 void pose_activate_flipped_bone(Scene *scene)
 {
index 8c19f2c3ecfca325142d6602ab902ac7bc09f9a2..05ea4d2b50606f9fef81bf89397b97eac941496b 100644 (file)
@@ -126,6 +126,7 @@ void ED_armature_exit_posemode(struct bContext *C, struct Base *base);
 void ED_armature_enter_posemode(struct bContext *C, struct Base *base);
 int ED_pose_channel_in_IK_chain(struct Object *ob, struct bPoseChannel *pchan);
 void ED_pose_deselectall(struct Object *ob, int test, int doundo);
+void ED_pose_recalculate_paths(struct bContext *C, struct Scene *scene, struct Object *ob);
 
 /* sketch */
 
index b5c1e8bb9f6a593ff79a834b1bb5bdb4a144250e..a00b79e4139f213ffbca42fd02ac051b7c088acb 100644 (file)
@@ -3168,14 +3168,19 @@ 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);
+       
+       uiItemO(layout, "Flip L/R Names", 0, "POSE_OT_flip_names");
+       
+       //separator + move layer operators...
+       
+       uiItemS(layout);
+       
        uiItemMenuF(layout, "Show/Hide Bones", 0, view3d_pose_armature_showhidemenu);
        
 #if 0
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "AutoName Left-Right|W",                  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 16, "");
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "AutoName Front-Back|W",                  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 17, "");
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "AutoName Top-Bottom|W",                  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 18, "");
-       
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Flip L/R Names|W",                       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 9, "");
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Copy Attributes...|Ctrl C",                      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
 
        uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");