diff options
author | Joshua Leung <aligorith@gmail.com> | 2009-07-24 17:02:16 +0400 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2009-07-24 17:02:16 +0400 |
commit | fbad147b7624cb65399bbea09068e8871e5fb227 (patch) | |
tree | 09d4b91c101451d6cffa747b6699901bc78dd303 /source/blender/editors/armature | |
parent | 2f8a19e5bca068344b5b5dcb85b447180ec8e29e (diff) |
2.5 - Restored 'AutoSide Name' and 'Flip Names' operators for both PoseMode and Edit Mode (Armatures).
Only the PoseMode menus work for now (since these use operators)
Diffstat (limited to 'source/blender/editors/armature')
-rw-r--r-- | source/blender/editors/armature/armature_intern.h | 12 | ||||
-rw-r--r-- | source/blender/editors/armature/armature_ops.c | 13 | ||||
-rw-r--r-- | source/blender/editors/armature/editarmature.c | 119 | ||||
-rw-r--r-- | source/blender/editors/armature/poseobject.c | 127 |
4 files changed, 197 insertions, 74 deletions
diff --git a/source/blender/editors/armature/armature_intern.h b/source/blender/editors/armature/armature_intern.h index c37f6803d58..b4ab58930fa 100644 --- a/source/blender/editors/armature/armature_intern.h +++ b/source/blender/editors/armature/armature_intern.h @@ -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 */ diff --git a/source/blender/editors/armature/armature_ops.c b/source/blender/editors/armature/armature_ops.c index 5495147acb0..9d44e8efc34 100644 --- a/source/blender/editors/armature/armature_ops.c +++ b/source/blender/editors/armature/armature_ops.c @@ -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); diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index 68d8ffbc11d..2da49731a95 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -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) diff --git a/source/blender/editors/armature/poseobject.c b/source/blender/editors/armature/poseobject.c index d0bc36b5f09..e9ebdb87a3c 100644 --- a/source/blender/editors/armature/poseobject.c +++ b/source/blender/editors/armature/poseobject.c @@ -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) { |