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
path: root/source
diff options
context:
space:
mode:
authorTon Roosendaal <ton@blender.org>2005-08-13 23:41:45 +0400
committerTon Roosendaal <ton@blender.org>2005-08-13 23:41:45 +0400
commit109950ada4f58f3b45907075fa9eccb3038a201a (patch)
tree0b3a87f9064f5c2f2c68807be8d1c8becb4bfb39 /source
parent184e4fdaae972f05bd5ad78ea2c9715eea01b21e (diff)
New; Wkey in Armature Editmode. Has option for flipping names too.
(And moved flip_name to armature kernel)
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/BKE_armature.h1
-rw-r--r--source/blender/blenkernel/intern/armature.c129
-rw-r--r--source/blender/include/BIF_editarmature.h1
-rw-r--r--source/blender/src/editarmature.c23
-rw-r--r--source/blender/src/editobject.c6
-rw-r--r--source/blender/src/poseobject.c133
6 files changed, 161 insertions, 132 deletions
diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h
index 6fbf453b469..354b065773c 100644
--- a/source/blender/blenkernel/BKE_armature.h
+++ b/source/blender/blenkernel/BKE_armature.h
@@ -72,6 +72,7 @@ void unlink_armature(struct bArmature *arm);
void free_armature(struct bArmature *arm);
void make_local_armature(struct bArmature *arm);
struct bArmature *copy_armature(struct bArmature *arm);
+void bone_flip_name (char *name);
void calc_armature_deform (struct Object *ob, float *co, int index);
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index 82f1ecefdd8..9268b48ccb2 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -25,6 +25,7 @@
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
+#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
@@ -241,6 +242,133 @@ Bone *get_named_bone (bArmature *arm, const char *name)
return bone;
}
+static char *strcasestr_(register char *s, register char *find)
+{
+ register char c, sc;
+ register size_t len;
+
+ if ((c = *find++) != 0) {
+ c= tolower(c);
+ len = strlen(find);
+ do {
+ do {
+ if ((sc = *s++) == 0)
+ return (NULL);
+ sc= tolower(sc);
+ } while (sc != c);
+ } while (BLI_strncasecmp(s, find, len) != 0);
+ s--;
+ }
+ return ((char *) s);
+}
+
+#define IS_SEPARATOR(a) (a=='.' || a==' ' || a=='-' || a=='_')
+
+/* finds the best possible flipped name, removing number extensions. For renaming; check for unique names afterwards */
+void bone_flip_name (char *name)
+{
+ int len;
+ char prefix[128]={""}; /* The part before the facing */
+ char suffix[128]={""}; /* The part after the facing */
+ char replace[128]={""}; /* The replacement string */
+ char *index=NULL;
+
+ len= strlen(name);
+ if(len<3) return; // we don't do names like .R or .L
+
+ /* We first check the case with a .### extension, let's find the last period */
+ if(isdigit(name[len-1])) {
+ index= strrchr(name, '.'); // last occurrance
+ if (index && isdigit(index[1]) ) { // doesnt handle case bone.1abc2 correct..., whatever!
+ *index= 0;
+ len= strlen(name);
+ }
+ }
+
+ strcpy (prefix, name);
+
+ /* first case; separator . - _ with extensions r R l L */
+ if( IS_SEPARATOR(name[len-2]) ) {
+ switch(name[len-1]) {
+ case 'l':
+ prefix[len-1]= 0;
+ strcpy(replace, "r");
+ break;
+ case 'r':
+ prefix[len-1]= 0;
+ strcpy(replace, "l");
+ break;
+ case 'L':
+ prefix[len-1]= 0;
+ strcpy(replace, "R");
+ break;
+ case 'R':
+ prefix[len-1]= 0;
+ strcpy(replace, "L");
+ break;
+ }
+ }
+ /* case; beginning with r R l L , with separator after it */
+ else if( IS_SEPARATOR(name[1]) ) {
+ switch(name[0]) {
+ case 'l':
+ strcpy(replace, "r");
+ strcpy(suffix, name+1);
+ prefix[0]= 0;
+ break;
+ case 'r':
+ strcpy(replace, "l");
+ strcpy(suffix, name+1);
+ prefix[0]= 0;
+ break;
+ case 'L':
+ strcpy(replace, "R");
+ strcpy(suffix, name+1);
+ prefix[0]= 0;
+ break;
+ case 'R':
+ strcpy(replace, "L");
+ strcpy(suffix, name+1);
+ prefix[0]= 0;
+ break;
+ }
+ }
+ else if(len > 5) {
+ /* hrms, why test for a separator? lets do the rule 'ultimate left or right' */
+ index = strcasestr_(prefix, "right");
+ if (index==prefix || index==prefix+len-5) {
+ if(index[0]=='r')
+ strcpy (replace, "left");
+ else {
+ if(index[1]=='I')
+ strcpy (replace, "LEFT");
+ else
+ strcpy (replace, "Left");
+ }
+ *index= 0;
+ strcpy (suffix, index+5);
+ }
+ else {
+ index = strcasestr_(prefix, "left");
+ if (index==prefix || index==prefix+len-4) {
+ if(index[0]=='l')
+ strcpy (replace, "right");
+ else {
+ if(index[1]=='E')
+ strcpy (replace, "RIGHT");
+ else
+ strcpy (replace, "Right");
+ }
+ *index= 0;
+ strcpy (suffix, index+4);
+ }
+ }
+ }
+
+ sprintf (name, "%s%s%s", prefix, replace, suffix);
+}
+
+
/* ************* B-Bone support ******************* */
#define MAX_BBONE_SUBDIV 32
@@ -515,7 +643,6 @@ void calc_armature_deform (Object *ob, float *co, int index)
void armature_deform_verts(Object *armOb, Object *target, float (*vertexCos)[3], int numVerts)
{
- bArmature *arm = armOb->data;
bPoseChannel **defnrToPC = NULL;
MDeformVert *dverts;
float obinv[4][4], premat[4][4], postmat[4][4];
diff --git a/source/blender/include/BIF_editarmature.h b/source/blender/include/BIF_editarmature.h
index 7fc35197cfe..77c6c5d446d 100644
--- a/source/blender/include/BIF_editarmature.h
+++ b/source/blender/include/BIF_editarmature.h
@@ -124,6 +124,7 @@ int ik_chain_looper(Object *ob, struct Bone *bone, void *data,
void undo_push_armature(char *name);
void armature_bone_rename(struct bArmature *arm, char *oldname, char *newname);
+void armature_flip_names(void);
#define BONESEL_ROOT 0x10000000
diff --git a/source/blender/src/editarmature.c b/source/blender/src/editarmature.c
index 4142d8337d1..16e0c6b61d6 100644
--- a/source/blender/src/editarmature.c
+++ b/source/blender/src/editarmature.c
@@ -2356,5 +2356,26 @@ void armature_bone_rename(bArmature *arm, char *oldnamep, char *newnamep)
}
}
-
+/* context editmode object */
+void armature_flip_names(void)
+{
+ EditBone *ebone;
+ char newname[32];
+
+ for (ebone = G.edbo.first; ebone; ebone=ebone->next) {
+ if(ebone->flag & BONE_SELECTED) {
+ BLI_strncpy(newname, ebone->name, sizeof(newname));
+ bone_flip_name(newname);
+ armature_bone_rename(G.obedit->data, ebone->name, newname);
+ }
+ }
+
+ allqueue(REDRAWVIEW3D, 0);
+ allqueue(REDRAWBUTSEDIT, 0);
+ allqueue(REDRAWBUTSOBJECT, 0);
+ allqueue (REDRAWACTION, 0);
+ allqueue(REDRAWOOPS, 0);
+ BIF_undo_push("Flip names");
+
+}
diff --git a/source/blender/src/editobject.c b/source/blender/src/editobject.c
index f35291575f9..783032b4bda 100644
--- a/source/blender/src/editobject.c
+++ b/source/blender/src/editobject.c
@@ -2129,6 +2129,12 @@ void special_editmenu(void)
DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
}
+ else if(G.obedit->type==OB_ARMATURE) {
+ nr= pupmenu("Specials%t|Flip Left-Right Names%x1");
+ if(nr==1) {
+ armature_flip_names();
+ }
+ }
countall();
allqueue(REDRAWVIEW3D, 0);
diff --git a/source/blender/src/poseobject.c b/source/blender/src/poseobject.c
index 76a0e36c612..91edf21fd6b 100644
--- a/source/blender/src/poseobject.c
+++ b/source/blender/src/poseobject.c
@@ -26,7 +26,6 @@
* support for animation modes - Reevan McKay
*/
-#include <ctype.h>
#include <stdlib.h>
#include <string.h>
@@ -190,7 +189,7 @@ void pose_special_editmenu(void)
if(!ob && !ob->pose) return;
if(ob==G.obedit || (ob->flag & OB_POSEMODE)==0) return;
- nr= pupmenu("Specials%t|Select Constraint Target%x1|Flip Left-Right Names");
+ nr= pupmenu("Specials%t|Select Constraint Target%x1|Flip Left-Right Names%x2");
if(nr==1) {
pose_select_constraint_target();
}
@@ -441,132 +440,6 @@ void copy_posebuf (void)
}
-static char *strcasestr_(register char *s, register char *find)
-{
- register char c, sc;
- register size_t len;
-
- if ((c = *find++) != 0) {
- c= tolower(c);
- len = strlen(find);
- do {
- do {
- if ((sc = *s++) == 0)
- return (NULL);
- sc= tolower(sc);
- } while (sc != c);
- } while (BLI_strncasecmp(s, find, len) != 0);
- s--;
- }
- return ((char *) s);
-}
-
-#define IS_SEPARATOR(a) (a=='.' || a==' ' || a=='-' || a=='_')
-
-/* finds the best possible flipped name, removing number extensions. For renaming; check for unique names afterwards */
-static void flip_name (char *name)
-{
- int len;
- char prefix[128]={""}; /* The part before the facing */
- char suffix[128]={""}; /* The part after the facing */
- char replace[128]={""}; /* The replacement string */
- char *index=NULL;
-
- len= strlen(name);
- if(len<3) return; // we don't do names like .R or .L
-
- /* We first check the case with a .### extension, let's find the last period */
- if(isdigit(name[len-1])) {
- index= strrchr(name, '.'); // last occurrance
- if (index && isdigit(index[1]) ) { // doesnt handle case bone.1abc2 correct..., whatever!
- *index= 0;
- len= strlen(name);
- }
- }
-
- strcpy (prefix, name);
-
- /* first case; separator . - _ with extensions r R l L */
- if( IS_SEPARATOR(name[len-2]) ) {
- switch(name[len-1]) {
- case 'l':
- prefix[len-1]= 0;
- strcpy(replace, "r");
- break;
- case 'r':
- prefix[len-1]= 0;
- strcpy(replace, "l");
- break;
- case 'L':
- prefix[len-1]= 0;
- strcpy(replace, "R");
- break;
- case 'R':
- prefix[len-1]= 0;
- strcpy(replace, "L");
- break;
- }
- }
- /* case; beginning with r R l L , with separator after it */
- else if( IS_SEPARATOR(name[1]) ) {
- switch(name[0]) {
- case 'l':
- strcpy(replace, "r");
- strcpy(suffix, name+1);
- prefix[0]= 0;
- break;
- case 'r':
- strcpy(replace, "l");
- strcpy(suffix, name+1);
- prefix[0]= 0;
- break;
- case 'L':
- strcpy(replace, "R");
- strcpy(suffix, name+1);
- prefix[0]= 0;
- break;
- case 'R':
- strcpy(replace, "L");
- strcpy(suffix, name+1);
- prefix[0]= 0;
- break;
- }
- }
- else if(len > 5) {
- /* hrms, why test for a separator? lets do the rule 'ultimate left or right' */
- index = strcasestr_(prefix, "right");
- if (index==prefix || index==prefix+len-5) {
- if(index[0]=='r')
- strcpy (replace, "left");
- else {
- if(index[1]=='I')
- strcpy (replace, "LEFT");
- else
- strcpy (replace, "Left");
- }
- *index= 0;
- strcpy (suffix, index+5);
- }
- else {
- index = strcasestr_(prefix, "left");
- if (index==prefix || index==prefix+len-4) {
- if(index[0]=='l')
- strcpy (replace, "right");
- else {
- if(index[1]=='E')
- strcpy (replace, "RIGHT");
- else
- strcpy (replace, "Right");
- }
- *index= 0;
- strcpy (suffix, index+4);
- }
- }
- }
-
- sprintf (name, "%s%s%s", prefix, replace, suffix);
-}
-
void paste_posebuf (int flip)
{
Object *ob= OBACT;
@@ -589,7 +462,7 @@ void paste_posebuf (int flip)
if (chan->flag & POSE_KEY) {
BLI_strncpy(name, chan->name, sizeof(name));
if (flip)
- flip_name (name);
+ bone_flip_name (name);
/* only copy when channel exists, poses are not meant to add random channels to anymore */
pchan= get_pose_channel(ob->pose, name);
@@ -671,7 +544,7 @@ void pose_flip_names(void)
for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
if(pchan->bone->flag & (BONE_ACTIVE|BONE_SELECTED)) {
BLI_strncpy(newname, pchan->name, sizeof(newname));
- flip_name(newname);
+ bone_flip_name(newname);
armature_bone_rename(ob->data, pchan->name, newname);
}
}