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)
This commit is contained in:
Joshua Leung
2009-07-24 13:02:16 +00:00
parent 2f8a19e5bc
commit fbad147b76
6 changed files with 211 additions and 82 deletions

View 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 */

View 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);

View 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;
BIF_undo_push("Flip names");
/* 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);
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;
char newname[32];
/* identifiers */
ot->name= "Flip Names";
ot->idname= "ARMATURE_OT_flip_names";
ot->description= "Flips (and corrects) the names of selected bones.";
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);
}
}
}
/* api callbacks */
ot->exec= armature_flip_names_exec;
ot->poll= ED_operator_editarmature;
BIF_undo_push("Auto-side name");
/* 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");
/* 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);
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)

View 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 (ELEM(NULL, ob, ob->pose))
return OPERATOR_CANCELLED;
arm= ob->data;
if(pose_has_protected_selected(ob, 0, 1))
return;
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 (ELEM(NULL, ob, ob->pose))
return OPERATOR_CANCELLED;
arm= ob->data;
if (pose_has_protected_selected(ob, 0, 1))
return;
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;
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;
}
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)
{

View 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 */

View 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, "");