When a bone is renamed, all constraints that point to it are
authorChris Want <cwant@ualberta.ca>
Sat, 3 Jan 2004 06:27:53 +0000 (06:27 +0000)
committerChris Want <cwant@ualberta.ca>
Sat, 3 Jan 2004 06:27:53 +0000 (06:27 +0000)
updated with the new name.

source/blender/include/BIF_editarmature.h
source/blender/src/buttons_editing.c
source/blender/src/editarmature.c

index 8e059159dde895106a0362402209c79f26d55ecf..5d40f71b8510f6c06d8c06462798c609b5bb806f 100644 (file)
@@ -106,6 +106,8 @@ void        selectconnected_armature(void);
 void   selectconnected_posearmature(void);
 void   select_bone_by_name (struct bArmature *arm, char *name, int select);
 void    unique_editbone_name (char* name);
+void    attach_bone_to_parent(EditBone *bone);
+void    attach_bone_to_parent_cb(void *bonev, void *arg2_unused);
 
 struct Bone *get_first_selected_bone (void);
 void auto_align_armature(void);
index 915f4ef456e9285ddcf18b155b0f18f11a21adcf..4197a80d1f81a4a5face69a7383f0b45ce907800 100644 (file)
@@ -1188,34 +1188,6 @@ static int editbone_to_parnr (EditBone *bone)
        return -1;
 }
 
-
-
-static void attach_bone_to_parent(EditBone *bone)
-{
-       EditBone *curbone;
-
-       if (bone->flag & BONE_IK_TOPARENT) {
-
-       /* See if there are any other bones that refer to the same parent and disconnect them */
-               for (curbone = G.edbo.first; curbone; curbone=curbone->next){
-                       if (curbone!=bone){
-                               if (curbone->parent && (curbone->parent == bone->parent) && (curbone->flag & BONE_IK_TOPARENT))
-                                       curbone->flag &= ~BONE_IK_TOPARENT;
-                       }
-               }
-
-       /* Attach this bone to its parent */
-               VECCOPY(bone->head, bone->parent->tail);
-       }
-
-}
-
-static void attach_bone_to_parent_cb(void *bonev, void *arg2_unused)
-{
-       EditBone *curBone= bonev;
-       attach_bone_to_parent(curBone);
-}
-
 static void parnr_to_editbone(EditBone *bone)
 {
        if (bone->parNr == -1){
@@ -1262,6 +1234,20 @@ static void build_bonestring (char *string, EditBone *bone){
        }
 }
 
+static void constraint_ebone_name_fix(ListBase *conlist, EditBone *eBone)
+{
+
+       bConstraint *curcon;
+       char *subtarget;
+
+       for (curcon = conlist->first; curcon; curcon=curcon->next){
+               subtarget = get_con_subtarget_name(curcon, G.obedit);
+               if (subtarget)
+                       if (!strcmp(subtarget,eBone->oldname) )
+                               strcpy(subtarget, eBone->name);
+       }
+}
+
 static void validate_editbonebutton(EditBone *eBone){
        EditBone        *prev;
        bAction         *act=NULL;
@@ -1300,12 +1286,35 @@ static void validate_editbonebutton(EditBone *eBone){
 
        for (base = G.scene->base.first; base; base=base->next){
                Object *ob = base->object;
+               ListBase *conlist;
 
                /* See if an object is parented to this armature */
-               if (ob->parent && ob->partype==PARBONE && (ob->parent->type==OB_ARMATURE) && (ob->parent->data == G.obedit->data)){
+               if (ob->parent && ob->partype==PARBONE && 
+                       (ob->parent->type==OB_ARMATURE) && 
+                       (ob->parent->data == G.obedit->data)){
                        if (!strcmp(ob->parsubstr, eBone->oldname))
                                strcpy(ob->parsubstr, eBone->name);
                }
+
+               /* Update any constraints to use the new bone name */
+               conlist = &ob->constraints;
+               constraint_ebone_name_fix(conlist, eBone);
+
+               switch (ob->type){
+                       case OB_ARMATURE:
+                               if (ob->pose){
+                                       bPoseChannel *pchan;
+                                       for (pchan = ob->pose->chanbase.first; pchan; 
+                                                pchan=pchan->next){
+                                               conlist = &pchan->constraints;
+                                               constraint_ebone_name_fix(conlist, eBone);
+                                       }
+                               }
+                               break;
+                       default:
+                               break;
+        }
+               
        }
 
        exit_editmode(0);       /* To ensure new names make it to the edit armature */
index 85602d58178c932f1a81e27f0acce0229779ddb5..f23ced646947aff7d36301bc614c8502191a1784 100644 (file)
@@ -1705,6 +1705,34 @@ static void add_bone_input (Object *ob)
 
 }
 
+void attach_bone_to_parent_cb(void *bonev, void *arg2_unused)
+{
+       EditBone *curBone= bonev;
+       attach_bone_to_parent(curBone);
+}
+
+void attach_bone_to_parent(EditBone *bone)
+{
+       EditBone *curbone;
+
+       if (bone->flag & BONE_IK_TOPARENT) {
+
+               /* See if there are any other bones that refer to the same 
+                * parent and disconnect them 
+                */
+               for (curbone = G.edbo.first; curbone; curbone=curbone->next){
+                       if (curbone!=bone){
+                               if (curbone->parent && 
+                                       (curbone->parent == bone->parent) && 
+                                       (curbone->flag & BONE_IK_TOPARENT))
+                                       curbone->flag &= ~BONE_IK_TOPARENT;
+                       }
+               }
+
+        /* Attach this bone to its parent */
+               VECCOPY(bone->head, bone->parent->tail);
+       }
+}
 
 void deselectall_armature(void)
 /*     Actually, it toggles selection, deselecting