diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-04-30 12:24:44 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-04-30 12:24:44 +0400 |
commit | 60c9addf79fdd68ceda48e451260a74f403f9e15 (patch) | |
tree | 1c90761d07c2012efbd19fe1be7e19b68ae8bd99 /source/blender/blenkernel | |
parent | 238af29b39f7a059c5bfd4124d8976cf34534a78 (diff) |
- improve select grouped prefix/suffix from recent patch
- added select similar direction (Y axis)
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_deform.h | 5 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/deform.c | 46 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 1 |
3 files changed, 48 insertions, 4 deletions
diff --git a/source/blender/blenkernel/BKE_deform.h b/source/blender/blenkernel/BKE_deform.h index d3d66967ebb..b59fc9af37c 100644 --- a/source/blender/blenkernel/BKE_deform.h +++ b/source/blender/blenkernel/BKE_deform.h @@ -71,7 +71,10 @@ void defvert_normalize_lock(struct MDeformVert *dvert, const int def_nr_lock); /* utility function, note that 32 chars is the maximum string length since its only * used with defgroups currently */ -int BKE_deform_is_char_sep(const char c); + +void BKE_deform_split_suffix(const char string[MAX_VGROUP_NAME], char base[MAX_VGROUP_NAME], char ext[MAX_VGROUP_NAME]); +void BKE_deform_split_prefix(const char string[MAX_VGROUP_NAME], char base[MAX_VGROUP_NAME], char ext[MAX_VGROUP_NAME]); + void flip_side_name(char name[64], const char from_name[64], int strip_number); #endif diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c index a14456845b9..ebf5735c1cd 100644 --- a/source/blender/blenkernel/intern/deform.c +++ b/source/blender/blenkernel/intern/deform.c @@ -437,11 +437,51 @@ void defgroup_unique_name(bDeformGroup *dg, Object *ob) BLI_uniquename_cb(defgroup_unique_check, &data, "Group", '.', dg->name, sizeof(dg->name)); } -int BKE_deform_is_char_sep(const char c) +static int is_char_sep(const char c) { return ELEM4(c, '.', ' ', '-', '_'); } +/* based on BLI_split_dirfile() / os.path.splitext(), "a.b.c" -> ("a.b", ".c") */ + +void BKE_deform_split_suffix(const char string[MAX_VGROUP_NAME], char body[MAX_VGROUP_NAME], char suf[MAX_VGROUP_NAME]) +{ + size_t len = BLI_strnlen(string, MAX_VGROUP_NAME); + size_t i; + + body[0] = suf[0] = '\0'; + + for (i = len - 1; i > 1; i--) { + if (is_char_sep(string[i])) { + BLI_strncpy(body, string, i + 1); + BLI_strncpy(suf, string + i, (len + 1) - i); + return; + } + } + + BLI_strncpy(body, string, len); +} + +/* "a.b.c" -> ("a.", "b.c") */ +void BKE_deform_split_prefix(const char string[MAX_VGROUP_NAME], char pre[MAX_VGROUP_NAME], char body[MAX_VGROUP_NAME]) +{ + size_t len = BLI_strnlen(string, MAX_VGROUP_NAME); + size_t i; + + body[0] = pre[0] = '\0'; + + for (i = 1; i < len; i++) { + if (is_char_sep(string[i])) { + i++; + BLI_strncpy(pre, string, i + 1); + BLI_strncpy(body, string + i, (len + 1) - i); + return; + } + } + + BLI_strncpy(body, string, len); +} + /* finds the best possible flipped name. For renaming; check for unique names afterwards */ /* if strip_number: removes number extensions * note: don't use sizeof() for 'name' or 'from_name' */ @@ -478,7 +518,7 @@ void flip_side_name(char name[MAX_VGROUP_NAME], const char from_name[MAX_VGROUP_ BLI_strncpy(prefix, name, sizeof(prefix)); /* first case; separator . - _ with extensions r R l L */ - if (BKE_deform_is_char_sep(name[len - 2])) { + if (is_char_sep(name[len - 2])) { switch (name[len - 1]) { case 'l': prefix[len - 1] = 0; @@ -499,7 +539,7 @@ void flip_side_name(char name[MAX_VGROUP_NAME], const char from_name[MAX_VGROUP_ } } /* case; beginning with r R l L , with separator after it */ - else if (BKE_deform_is_char_sep(name[1])) { + else if (is_char_sep(name[1])) { switch (name[0]) { case 'l': strcpy(replace, "r"); diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 474d1e5b442..9959edaac16 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -56,6 +56,7 @@ #include "DNA_space_types.h" #include "DNA_view3d_types.h" #include "DNA_world_types.h" +#include "DNA_object_types.h" #include "BLI_blenlib.h" #include "BLI_bpath.h" |