From cee66b8cc0bf6d5419af3187ccd9392b770a6c2f Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Wed, 28 Feb 2018 16:53:14 +0100 Subject: Fix T52685: Flip names for bones its not working. Flip names operator changed in rB702bc5ba26d5, to some sensible behavior. But this breaks common workflow of 'duplicate part of the bones, scale-mirror new ones, and flip their names'. So now, instead of doing this in two steps, trying to guesstimate which bones should get which name, just add option to flip names to duplicate operator itself. Simpler, safer, and much, much more consitent behavior and predictable results. --- source/blender/editors/armature/armature_add.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'source/blender/editors') diff --git a/source/blender/editors/armature/armature_add.c b/source/blender/editors/armature/armature_add.c index 368d54fc3ad..48436a979a2 100644 --- a/source/blender/editors/armature/armature_add.c +++ b/source/blender/editors/armature/armature_add.c @@ -472,7 +472,7 @@ EditBone *duplicateEditBone(EditBone *curBone, const char *name, ListBase *editb return duplicateEditBoneObjects(curBone, name, editbones, ob, ob); } -static int armature_duplicate_selected_exec(bContext *C, wmOperator *UNUSED(op)) +static int armature_duplicate_selected_exec(bContext *C, wmOperator *op) { bArmature *arm; EditBone *ebone_iter; @@ -484,7 +484,9 @@ static int armature_duplicate_selected_exec(bContext *C, wmOperator *UNUSED(op)) /* cancel if nothing selected */ if (CTX_DATA_COUNT(C, selected_bones) == 0) return OPERATOR_CANCELLED; - + + const bool do_flip_names = RNA_boolean_get(op->ptr, "do_flip_names"); + ED_armature_sync_selection(arm->edbo); // XXX why is this needed? preEditBoneDuplicate(arm->edbo); @@ -512,8 +514,20 @@ static int armature_duplicate_selected_exec(bContext *C, wmOperator *UNUSED(op)) (ebone_iter->flag & BONE_SELECTED)) { EditBone *ebone; + char new_bone_name_buff[MAXBONENAME]; + char *new_bone_name = ebone_iter->name; + + if (do_flip_names) { + BLI_string_flip_side_name(new_bone_name_buff, ebone_iter->name, false, sizeof(new_bone_name_buff)); - ebone = duplicateEditBone(ebone_iter, ebone_iter->name, arm->edbo, obedit); + /* Only use flipped name if not yet in use. Otherwise we'd get again inconsistent namings + * (different numbers), better keep default behavior in this case. */ + if (ED_armature_bone_find_name(arm->edbo, new_bone_name_buff) == NULL) { + new_bone_name = new_bone_name_buff; + } + } + + ebone = duplicateEditBone(ebone_iter, new_bone_name, arm->edbo, obedit); if (!ebone_first_dupe) { ebone_first_dupe = ebone; @@ -590,6 +604,10 @@ void ARMATURE_OT_duplicate(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + RNA_def_boolean( + ot->srna, "do_flip_names", false, + "Flip Names", "Try to flip names of the bones, if possible, instead of adding a number extension"); } /** -- cgit v1.2.3