Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2010-11-07 11:49:07 +0300
committerCampbell Barton <ideasman42@gmail.com>2010-11-07 11:49:07 +0300
commit20b16e4074eb0b015a94bd5738c76dafaca250db (patch)
tree2b348e906db0a01b2d0b033d0780cfeb05e4f445 /source/blender/editors/armature/editarmature.c
parentfbcaa502ca8e71390e3f43ee9cc18b1ccfe840a2 (diff)
de-duplicate unique naming logic, was used in 7 different places, convert into a function call.
Diffstat (limited to 'source/blender/editors/armature/editarmature.c')
-rw-r--r--source/blender/editors/armature/editarmature.c54
1 files changed, 19 insertions, 35 deletions
diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c
index dcfc2762735..9dd86a96dae 100644
--- a/source/blender/editors/armature/editarmature.c
+++ b/source/blender/editors/armature/editarmature.c
@@ -506,27 +506,20 @@ static EditBone *editbone_name_exists (ListBase *edbo, const char *name)
}
/* note: there's a unique_bone_name() too! */
-void unique_editbone_name (ListBase *edbo, char *name, EditBone *bone)
+static int editbone_unique_check(void *arg, const char *name)
{
- EditBone *dupli;
+ struct {ListBase *lb;void *bone;} *data= arg;
+ EditBone *dupli= editbone_name_exists(data->lb, name);
+ return dupli && dupli != data->bone;
+}
- dupli = editbone_name_exists(edbo, name);
-
- if (dupli && bone != dupli) {
- /* note: this block is used in other places, when changing logic apply to all others, search this message */
- char tempname[sizeof(bone->name)];
- char left[sizeof(bone->name)];
- int number;
- int len= BLI_split_name_num(left, &number, name);
- do { /* nested while loop looks bad but likely it wont run most times */
- while(BLI_snprintf(tempname, sizeof(tempname), "%s.%03d", left, number) >= sizeof(tempname)) {
- if(len > 0) left[--len]= '\0'; /* word too long */
- else number= 0; /* reset, must be a massive number */
- }
- } while(number++, ((dupli= editbone_name_exists(edbo, tempname)) && bone != dupli));
+void unique_editbone_name (ListBase *edbo, char *name, EditBone *bone)
+{
+ struct {ListBase *lb; void *bone;} data;
+ data.lb= edbo;
+ data.bone= bone;
- BLI_strncpy(name, tempname, sizeof(bone->name));
- }
+ BLI_uniquename_cb(editbone_unique_check, &data, "Bone", '.', name, sizeof(bone->name));
}
/* helper for apply_armature_pose2bones - fixes parenting of objects that are bone-parented to armature */
@@ -5398,26 +5391,17 @@ void POSE_OT_reveal(wmOperatorType *ot)
/* ************* RENAMING DISASTERS ************ */
-/* note: there's a unique_editbone_name() too! */
-static void unique_bone_name (bArmature *arm, char *name)
-{
- if (get_named_bone(arm, name)) {
- /* note: this block is used in other places, when changing logic apply to all others, search this message */
- char tempname[sizeof(((Bone *)NULL)->name)];
- char left[sizeof(((Bone *)NULL)->name)];
- int number;
- int len= BLI_split_name_num(left, &number, name);
- do { /* nested while loop looks bad but likely it wont run most times */
- while(BLI_snprintf(tempname, sizeof(tempname), "%s.%03d", left, number) >= sizeof(tempname)) {
- if(len > 0) left[--len]= '\0'; /* word too long */
- else number= 0; /* reset, must be a massive number */
- }
- } while(number++, get_named_bone(arm, tempname));
+static int bone_unique_check(void *arg, const char *name)
+{
+ return get_named_bone((bArmature *)arg, name) != NULL;
+}
- BLI_strncpy(name, tempname, sizeof(tempname));
- }
+void unique_bone_name(bArmature *arm, char *name)
+{
+ BLI_uniquename_cb(bone_unique_check, (void *)arm, "Bone", '.', name, sizeof(((Bone *)NULL)->name));
}
+
#define MAXBONENAME 32
/* helper call for armature_bone_rename */
static void constraint_bone_name_fix(Object *ob, ListBase *conlist, char *oldname, char *newname)