code cleanup: armature functions
authorCampbell Barton <ideasman42@gmail.com>
Sat, 16 Nov 2013 17:30:36 +0000 (04:30 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 16 Nov 2013 18:23:05 +0000 (05:23 +1100)
- added BKE_pose_channel_get_mirrored (matching editmode function ED_armature_bone_get_mirrored)
- editbone_name_exists -> ED_armature_bone_find_name

source/blender/blenkernel/BKE_action.h
source/blender/blenkernel/intern/action.c
source/blender/editors/armature/armature_edit.c
source/blender/editors/armature/armature_intern.h
source/blender/editors/armature/armature_naming.c
source/blender/editors/armature/armature_relations.c
source/blender/editors/armature/armature_utils.c
source/blender/editors/armature/pose_transform.c
source/blender/editors/include/ED_armature.h

index 5c155a461821bed2918b0702554661e706d24926..3ac5c8c9a76979b02089da9a2da6cb7bf3ad76c4 100644 (file)
@@ -146,6 +146,7 @@ void                 BKE_pose_channel_copy_data(struct bPoseChannel *pchan, cons
 struct bPoseChannel *BKE_pose_channel_find_name(const struct bPose *pose, const char *name);
 struct bPoseChannel *BKE_pose_channel_active(struct Object *ob);
 struct bPoseChannel *BKE_pose_channel_verify(struct bPose *pose, const char *name);
+struct bPoseChannel *BKE_pose_channel_get_mirrored(const struct bPose *pose, const char *name);
 
 #ifndef NDEBUG
 bool BKE_pose_channels_is_valid(const struct bPose *pose);
index 94da2a330c1e867a5131241121377c34b8013a45..fe0e3da605f55b6c43d66b10f76f145f99ba621d 100644 (file)
@@ -53,6 +53,7 @@
 #include "BKE_anim.h"
 #include "BKE_animsys.h"
 #include "BKE_constraint.h"
+#include "BKE_deform.h"
 #include "BKE_fcurve.h"
 #include "BKE_global.h"
 #include "BKE_idprop.h"
@@ -539,6 +540,22 @@ bPoseChannel *BKE_pose_channel_active(Object *ob)
        return NULL;
 }
 
+/**
+ * \see #ED_armature_bone_get_mirrored (edit-mode, matching function)
+ */
+bPoseChannel *BKE_pose_channel_get_mirrored(const bPose *pose, const char *name)
+{
+       char name_flip[MAXBONENAME];
+
+       BKE_deform_flip_side_name(name_flip, name, false);
+
+       if (!STREQ(name_flip, name)) {
+               return BKE_pose_channel_find_name(pose, name_flip);
+       }
+
+       return NULL;
+}
+
 const char *BKE_pose_ikparam_get_name(bPose *pose)
 {
        if (pose) {
index 29eebe86afa6031eb6dc8dbf40e43be6db339c71..1bc5bf0fd744786abf36ed625440892cee2807fe 100644 (file)
@@ -1127,7 +1127,7 @@ static int armature_delete_selected_exec(bContext *C, wmOperator *UNUSED(op))
                bPoseChannel *pchan, *pchan_next;
                for (pchan = obedit->pose->chanbase.first; pchan; pchan = pchan_next) {
                        pchan_next = pchan->next;
-                       curBone = editbone_name_exists(arm->edbo, pchan->name);
+                       curBone = ED_armature_bone_find_name(arm->edbo, pchan->name);
                        
                        if (curBone && (curBone->flag & BONE_SELECTED) && (arm->layer & curBone->layer)) {
                                BKE_pose_channel_free(pchan);
@@ -1146,7 +1146,7 @@ static int armature_delete_selected_exec(bContext *C, wmOperator *UNUSED(op))
                                                for (ct = targets.first; ct; ct = ct->next) {
                                                        if (ct->tar == obedit) {
                                                                if (ct->subtarget[0]) {
-                                                                       curBone = editbone_name_exists(arm->edbo, ct->subtarget);
+                                                                       curBone = ED_armature_bone_find_name(arm->edbo, ct->subtarget);
                                                                        if (curBone && (curBone->flag & BONE_SELECTED) && (arm->layer & curBone->layer)) {
                                                                                con->flag |= CONSTRAINT_DISABLE;
                                                                                ct->subtarget[0] = 0;
index 83800e598ba7aa6db07aab12f3341f4b8df7e340..3707e13095b4a845a039f6f822d04dec977e4c2c 100644 (file)
@@ -229,9 +229,6 @@ struct EditBone *duplicateEditBoneObjects(struct EditBone *curBone, const char *
 /* editbones is the source list */
 void updateDuplicateSubtargetObjects(struct EditBone *dupBone, struct ListBase *editbones, struct Object *src_ob, struct Object *dst_ob);
 
-
-EditBone *editbone_name_exists(struct ListBase *edbo, const char *name);
-
 EditBone *add_points_bone(struct Object *obedit, float head[3], float tail[3]);
 void bone_free(struct bArmature *arm, struct EditBone *bone);
 
index 10e9724089807adb6bfeb9c07bd920985d80b7c9..c574fc6a297bdd037ef820985634d6084daaf489 100644 (file)
 /* ************************************************** */
 /* EditBone Names */
 
-/* checks if an EditBone with a matching name already, returning the matching bone if it exists */
-EditBone *editbone_name_exists(ListBase *edbo, const char *name)
-{
-       return BLI_findstring(edbo, name, offsetof(EditBone, name));
-}
-
 /* note: there's a unique_bone_name() too! */
 static bool editbone_unique_check(void *arg, const char *name)
 {
        struct {ListBase *lb; void *bone; } *data = arg;
-       EditBone *dupli = editbone_name_exists(data->lb, name);
+       EditBone *dupli = ED_armature_bone_find_name(data->lb, name);
        return dupli && dupli != data->bone;
 }
 
@@ -155,7 +149,7 @@ void ED_armature_bone_rename(bArmature *arm, const char *oldnamep, const char *n
                
                /* now check if we're in editmode, we need to find the unique name */
                if (arm->edbo) {
-                       EditBone *eBone = editbone_name_exists(arm->edbo, oldname);
+                       EditBone *eBone = ED_armature_bone_find_name(arm->edbo, oldname);
                        
                        if (eBone) {
                                unique_editbone_name(arm->edbo, newname, NULL);
index 79d75c9fcdab327b0385356decfef91c89a32e44..cd24e94f9e93037730e27e97b4cea738ceddb5b8 100644 (file)
@@ -230,7 +230,7 @@ int join_armature_exec(bContext *C, wmOperator *op)
                        /* Copy bones and posechannels from the object to the edit armature */
                        for (pchan = opose->chanbase.first; pchan; pchan = pchann) {
                                pchann = pchan->next;
-                               curbone = editbone_name_exists(curarm->edbo, pchan->name);
+                               curbone = ED_armature_bone_find_name(curarm->edbo, pchan->name);
                                
                                /* Get new name */
                                unique_editbone_name(arm->edbo, curbone->name, NULL);
@@ -414,7 +414,7 @@ static void separate_armature_bones(Object *ob, short sel)
        /* go through pose-channels, checking if a bone should be removed */
        for (pchan = ob->pose->chanbase.first; pchan; pchan = pchann) {
                pchann = pchan->next;
-               curbone = editbone_name_exists(arm->edbo, pchan->name);
+               curbone = ED_armature_bone_find_name(arm->edbo, pchan->name);
                
                /* check if bone needs to be removed */
                if ( (sel && (curbone->flag & BONE_SELECTED)) ||
index 7efeeebcf1de7be7cfab1e74743f278749803b50..2cbfb52db91a80d789eba0fe87d44fc1cba2fac6 100644 (file)
@@ -175,28 +175,35 @@ void ED_armature_ebone_to_mat4(EditBone *ebone, float mat[4][4])
        copy_v3_v3(mat[3], ebone->head);
 }
 
+/**
+ * Return a pointer to the bone of the given name
+ */
+EditBone *ED_armature_bone_find_name(const ListBase *edbo, const char *name)
+{
+       return BLI_findstring(edbo, name, offsetof(EditBone, name));
+}
+
+
 /* *************************************************************** */
 /* Mirroring */
 
-/* context: editmode armature */
-EditBone *ED_armature_bone_get_mirrored(ListBase *edbo, EditBone *ebo)
+/**
+ * \see #BKE_pose_channel_get_mirrored (pose-mode, matching function)
+ */
+EditBone *ED_armature_bone_get_mirrored(const ListBase *edbo, EditBone *ebo)
 {
-       EditBone *eboflip = NULL;
        char name_flip[MAXBONENAME];
-       
+
        if (ebo == NULL)
                return NULL;
        
        BKE_deform_flip_side_name(name_flip, ebo->name, false);
        
-       for (eboflip = edbo->first; eboflip; eboflip = eboflip->next) {
-               if (ebo != eboflip) {
-                       if (!strcmp(name_flip, eboflip->name))
-                               break;
-               }
+       if (!STREQ(name_flip, ebo->name)) {
+               return ED_armature_bone_find_name(edbo, name_flip);
        }
        
-       return eboflip;
+       return NULL;
 }
 
 /* ------------------------------------- */
index 4e66c3290884d7ddf0773b14f9cf5f9fec6c9c65..578f048cb150f028113182cb6f9d56b5a209af9e 100644 (file)
@@ -118,7 +118,7 @@ static int apply_armature_pose2bones_exec(bContext *C, wmOperator *op)
        pose = ob->pose;
        
        for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) {
-               curbone = editbone_name_exists(arm->edbo, pchan->name);
+               curbone = ED_armature_bone_find_name(arm->edbo, pchan->name);
                
                /* simply copy the head/tail values from pchan over to curbone */
                copy_v3_v3(curbone->head, pchan->pose_head);
index bb4640949c197565dbdc2bba4e271b0c9eada783..455378fc2ce7fe827fe1ab2408ec1560a0525b1f 100644 (file)
@@ -128,7 +128,8 @@ bool mouse_armature(struct bContext *C, const int mval[2], bool extend, bool des
 int join_armature_exec(struct bContext *C, struct wmOperator *op);
 struct Bone *get_indexed_bone(struct Object *ob, int index);
 float ED_rollBoneToVector(EditBone *bone, const float new_up_axis[3], const short axis_only);
-EditBone *ED_armature_bone_get_mirrored(struct ListBase *edbo, EditBone *ebo); // XXX this is needed for populating the context iterators
+EditBone *ED_armature_bone_find_name(const ListBase *edbo, const char *name);
+EditBone *ED_armature_bone_get_mirrored(const struct ListBase *edbo, EditBone *ebo);
 void ED_armature_sync_selection(struct ListBase *edbo);
 void ED_armature_validate_active(struct bArmature *arm);