diff options
Diffstat (limited to 'source/blender/blenkernel/intern/deform.c')
-rw-r--r-- | source/blender/blenkernel/intern/deform.c | 94 |
1 files changed, 35 insertions, 59 deletions
diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c index be28553f347..616bcb17f90 100644 --- a/source/blender/blenkernel/intern/deform.c +++ b/source/blender/blenkernel/intern/deform.c @@ -51,7 +51,7 @@ void defgroup_copy_list (ListBase *outbase, ListBase *inbase) { bDeformGroup *defgroup, *defgroupn; - outbase->first= outbase->last= 0; + outbase->first= outbase->last= NULL; for (defgroup = inbase->first; defgroup; defgroup=defgroup->next){ defgroupn= defgroup_duplicate(defgroup); @@ -305,89 +305,65 @@ int defgroup_flip_index(Object *ob, int index, int use_default) return (flip_index==-1 && use_default) ? index : flip_index; } -void defgroup_unique_name (bDeformGroup *dg, Object *ob) +static int defgroup_find_name_dupe(const char *name, bDeformGroup *dg, Object *ob) { bDeformGroup *curdef; - int number; - int exists = 0; - char tempname[64]; - char *dot; - if (!ob) - return; - - /* See if we are given an empty string */ - if (dg->name[0] == '\0') { - /* give it default name first */ - strcpy (dg->name, "Group"); - } - - /* See if we even need to do this */ for (curdef = ob->defbase.first; curdef; curdef=curdef->next) { if (dg!=curdef) { - if (!strcmp(curdef->name, dg->name)) { - exists = 1; - break; + if (!strcmp(curdef->name, name)) { + return 1; } } } - - if (!exists) - return; - /* Strip off the suffix */ - dot=strchr(dg->name, '.'); - if (dot) - *dot=0; - - for (number = 1; number <=999; number++) { - sprintf (tempname, "%s.%03d", dg->name, number); - - exists = 0; - for (curdef=ob->defbase.first; curdef; curdef=curdef->next) { - if (dg!=curdef) { - if (!strcmp (curdef->name, tempname)) { - exists = 1; - break; - } - } - } - if (!exists) { - BLI_strncpy (dg->name, tempname, 32); - return; - } - } + return 0; } +static int defgroup_unique_check(void *arg, const char *name) +{ + struct {Object *ob; void *dg;} *data= arg; + return defgroup_find_name_dupe(name, data->dg, data->ob); +} + +void defgroup_unique_name (bDeformGroup *dg, Object *ob) +{ + struct {Object *ob; void *dg;} data; + data.ob= ob; + data.dg= dg; + + BLI_uniquename_cb(defgroup_unique_check, &data, "Group", '.', dg->name, sizeof(dg->name)); +} /* finds the best possible flipped name. For renaming; check for unique names afterwards */ -/* if strip_number: removes number extensions */ -void flip_side_name (char *name, const char *from_name, int strip_number) +/* if strip_number: removes number extensions + * note: dont use sizeof() for 'name' or 'from_name' */ +void flip_side_name (char name[MAX_VGROUP_NAME], const char from_name[MAX_VGROUP_NAME], int strip_number) { int len; - char prefix[sizeof(((bDeformGroup *)NULL)->name)]= {""}; /* The part before the facing */ - char suffix[sizeof(((bDeformGroup *)NULL)->name)]= {""}; /* The part after the facing */ - char replace[sizeof(((bDeformGroup *)NULL)->name)]= {""}; /* The replacement string */ - char number[sizeof(((bDeformGroup *)NULL)->name)]= {""}; /* The number extension string */ + char prefix[MAX_VGROUP_NAME]= ""; /* The part before the facing */ + char suffix[MAX_VGROUP_NAME]= ""; /* The part after the facing */ + char replace[MAX_VGROUP_NAME]= ""; /* The replacement string */ + char number[MAX_VGROUP_NAME]= ""; /* The number extension string */ char *index=NULL; - len= strlen(from_name); + len= BLI_strnlen(from_name, MAX_VGROUP_NAME); if(len<3) return; // we don't do names like .R or .L - strcpy(name, from_name); + BLI_strncpy(name, from_name, MAX_VGROUP_NAME); /* We first check the case with a .### extension, let's find the last period */ if(isdigit(name[len-1])) { index= strrchr(name, '.'); // last occurrence if (index && isdigit(index[1]) ) { // doesnt handle case bone.1abc2 correct..., whatever! if(strip_number==0) - strcpy(number, index); + BLI_strncpy(number, index, sizeof(number)); *index= 0; - len= strlen(name); + len= BLI_strnlen(name, MAX_VGROUP_NAME); } } - strcpy (prefix, name); + BLI_strncpy(prefix, name, sizeof(prefix)); #define IS_SEPARATOR(a) ((a)=='.' || (a)==' ' || (a)=='-' || (a)=='_') @@ -471,10 +447,10 @@ void flip_side_name (char *name, const char *from_name, int strip_number) #undef IS_SEPARATOR - sprintf (name, "%s%s%s%s", prefix, replace, suffix, number); + BLI_snprintf (name, MAX_VGROUP_NAME, "%s%s%s%s", prefix, replace, suffix, number); } -float defvert_find_weight(const struct MDeformVert *dvert, int group_num) +float defvert_find_weight(const struct MDeformVert *dvert, const int group_num) { MDeformWeight *dw= defvert_find_index(dvert, group_num); return dw ? dw->weight : 0.0f; @@ -489,7 +465,7 @@ float defvert_array_find_weight_safe(const struct MDeformVert *dvert, int index, } -MDeformWeight *defvert_find_index(const MDeformVert *dvert, int defgroup) +MDeformWeight *defvert_find_index(const MDeformVert *dvert, const int defgroup) { if(dvert && defgroup >= 0) { MDeformWeight *dw = dvert->dw; @@ -505,7 +481,7 @@ MDeformWeight *defvert_find_index(const MDeformVert *dvert, int defgroup) /* Ensures that mv has a deform weight entry for the specified defweight group */ /* Note this function is mirrored in editmesh_tools.c, for use for editvertices */ -MDeformWeight *defvert_verify_index(MDeformVert *dv, int defgroup) +MDeformWeight *defvert_verify_index(MDeformVert *dv, const int defgroup) { MDeformWeight *newdw; |