diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-11-01 10:19:41 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-11-01 10:19:41 +0300 |
commit | daa4feaaeae4312eb23f66b948b668a7e9dc1959 (patch) | |
tree | dabd2bedd213f9fdfbfc31e6710b2913707dfa1f /source/blender/editors | |
parent | 8bbcef4c7a377045f6b93580efda93eb4adf800d (diff) |
bugfix [#24477] Can easily create bones with duplicate names
- fixed this error 7 different functions (deform groups, uv layers & similar).
- support for numbers over 999.
- renamed splitIDname() to BLI_split_name_num(), moved to BLI_path_utils
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/armature/editarmature.c | 64 | ||||
-rw-r--r-- | source/blender/editors/object/object_vgroup.c | 21 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/space_view3d.c | 6 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_orientations.c | 36 |
4 files changed, 48 insertions, 79 deletions
diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index fd747cc32aa..0be27e943f4 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -509,28 +509,23 @@ static EditBone *editbone_name_exists (ListBase *edbo, const char *name) void unique_editbone_name (ListBase *edbo, char *name, EditBone *bone) { EditBone *dupli; - char tempname[64]; - int number; - char *dot; dupli = editbone_name_exists(edbo, name); if (dupli && bone != dupli) { - /* Strip off the suffix, if it's a number */ - number= strlen(name); - if (number && isdigit(name[number-1])) { - dot= strrchr(name, '.'); // last occurrence - if (dot) - *dot=0; - } - - for (number = 1; number <= 999; number++) { - sprintf(tempname, "%s.%03d", name, number); - if (!editbone_name_exists(edbo, tempname)) { - BLI_strncpy(name, tempname, 32); - return; + /* 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)); + + BLI_strncpy(name, tempname, sizeof(bone->name)); } } @@ -5389,29 +5384,22 @@ void POSE_OT_reveal(wmOperatorType *ot) /* ************* RENAMING DISASTERS ************ */ /* note: there's a unique_editbone_name() too! */ -void unique_bone_name (bArmature *arm, char *name) -{ - char tempname[64]; - int number; - char *dot; - +static void unique_bone_name (bArmature *arm, char *name) +{ if (get_named_bone(arm, name)) { - - /* Strip off the suffix, if it's a number */ - number= strlen(name); - if(number && isdigit(name[number-1])) { - dot= strrchr(name, '.'); // last occurrence - if (dot) - *dot=0; - } - - for (number = 1; number <=999; number++) { - sprintf (tempname, "%s.%03d", name, number); - if (!get_named_bone(arm, tempname)) { - BLI_strncpy (name, tempname, 32); - return; + /* 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)); + + BLI_strncpy(name, tempname, sizeof(tempname)); } } diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 015fab05828..dd4864f928f 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -596,7 +596,7 @@ static void vgroup_select_verts(Object *ob, int select) static void vgroup_duplicate(Object *ob) { bDeformGroup *dg, *cdg; - char name[32], s[32]; + char name[sizeof(dg->name)]; MDeformWeight *org, *cpy; MDeformVert *dvert, **dvert_array=NULL; int i, idg, icdg, dvert_tot=0; @@ -605,26 +605,17 @@ static void vgroup_duplicate(Object *ob) if(!dg) return; - if(strstr(dg->name, "_copy")) { - BLI_strncpy(name, dg->name, 32); /* will be renamed _copy.001... etc */ + if(!strstr(dg->name, "_copy")) { + BLI_snprintf(name, sizeof(name), "%s_copy", dg->name); } else { - BLI_snprintf(name, 32, "%s_copy", dg->name); - while(defgroup_find_name(ob, name)) { - if((strlen(name) + 6) > 32) { - if (G.f & G_DEBUG) - printf("Internal error: the name for the new vertex group is > 32 characters"); - return; - } - strcpy(s, name); - BLI_snprintf(name, 32, "%s_copy", s); - } - } + BLI_snprintf(name, sizeof(name), "%s", dg->name); + } cdg = defgroup_duplicate(dg); strcpy(cdg->name, name); defgroup_unique_name(cdg, ob); - + BLI_addtail(&ob->defbase, cdg); idg = (ob->actdef-1); diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c index 22143db7769..f5c1612f786 100644 --- a/source/blender/editors/space_view3d/space_view3d.c +++ b/source/blender/editors/space_view3d/space_view3d.c @@ -191,7 +191,7 @@ static SpaceLink *view3d_new(const bContext *C) v3d->lay= v3d->layact= scene->lay; v3d->camera= scene->camera; } - v3d->scenelock= 1; + v3d->scenelock= TRUE; v3d->grid= 1.0f; v3d->gridlines= 16; v3d->gridsubdiv = 10; @@ -250,8 +250,8 @@ static SpaceLink *view3d_new(const bContext *C) ar->regiondata= MEM_callocN(sizeof(RegionView3D), "region view3d"); rv3d= ar->regiondata; rv3d->viewquat[0]= 1.0f; - rv3d->persp= 1; - rv3d->view= 7; + rv3d->persp= RV3D_PERSP; + rv3d->view= RV3D_VIEW_PERSPORTHO; rv3d->dist= 10.0; return (SpaceLink *)v3d; diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c index a01a3b17cd2..2d936460c53 100644 --- a/source/blender/editors/transform/transform_orientations.c +++ b/source/blender/editors/transform/transform_orientations.c @@ -86,33 +86,23 @@ TransformOrientation* findOrientationName(bContext *C, char *name) return NULL; } -void uniqueOrientationName(bContext *C, char *name) +static void uniqueOrientationName(bContext *C, char *name) { if (findOrientationName(C, name) != NULL) { - char tempname[64]; - int number; - char *dot; - - - number = strlen(name); - - if (number && isdigit(name[number-1])) - { - dot = strrchr(name, '.'); // last occurrence - if (dot) - *dot=0; - } - - for (number = 1; number <= 999; number++) - { - sprintf(tempname, "%s.%03d", name, number); - if (findOrientationName(C, tempname) == NULL) - { - BLI_strncpy(name, tempname, 32); - break; + /* note: this block is used in other places, when changing logic apply to all others, search this message */ + char tempname[sizeof(((TransformOrientation *)NULL)->name)]; + char left[sizeof(((TransformOrientation *)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++, findOrientationName(C, tempname)); + + BLI_strncpy(name, tempname, sizeof(tempname)); } } |