[Bf-blender-cvs] [cee66b8cc0b] master: Fix T52685: Flip names for bones its not working.

Bastien Montagne noreply at git.blender.org
Wed Feb 28 17:16:02 CET 2018


Commit: cee66b8cc0bf6d5419af3187ccd9392b770a6c2f
Author: Bastien Montagne
Date:   Wed Feb 28 16:53:14 2018 +0100
Branches: master
https://developer.blender.org/rBcee66b8cc0bf6d5419af3187ccd9392b770a6c2f

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.

===================================================================

M	source/blender/editors/armature/armature_add.c

===================================================================

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");
 }
 
 /**



More information about the Bf-blender-cvs mailing list