Bugfix [#32249] Groups in Dopesheet and Action editor don't get updated after
authorJoshua Leung <aligorith@gmail.com>
Thu, 30 Aug 2012 15:06:13 +0000 (15:06 +0000)
committerJoshua Leung <aligorith@gmail.com>
Thu, 30 Aug 2012 15:06:13 +0000 (15:06 +0000)
bone renaming

* Renaming F-Curves now checks if the corresponding F-Curve's group can also be
renamed accordingly.
* Changed the RNA updates for bone renaming so that they properly update the
channel lists

source/blender/blenkernel/intern/anim_sys.c
source/blender/makesrna/intern/rna_armature.c

index 8e8c98a38e4e2ee3944a2e6a89216daf56a80596..37b49349b8a6e271fc69d47a166955216904399a 100644 (file)
@@ -621,15 +621,30 @@ static char *rna_path_rename_fix(ID *owner_id, const char *prefix, const char *o
 }
 
 /* Check RNA-Paths for a list of F-Curves */
-static void fcurves_path_rename_fix(ID *owner_id, const char *prefix, char *oldName, char *newName, ListBase *curves, int verify_paths)
+static void fcurves_path_rename_fix(ID *owner_id, const char *prefix, const char *oldName, const char *newName, 
+                                    const char *oldKey, const char *newKey, ListBase *curves, int verify_paths)
 {
        FCurve *fcu;
        
        /* we need to check every curve... */
        for (fcu = curves->first; fcu; fcu = fcu->next) {
-               /* firstly, handle the F-Curve's own path */
-               if (fcu->rna_path)
-                       fcu->rna_path = rna_path_rename_fix(owner_id, prefix, oldName, newName, fcu->rna_path, verify_paths);
+               if (fcu->rna_path) {
+                       char *old_path = fcu->rna_path;
+                       
+                       /* firstly, handle the F-Curve's own path */
+                       fcu->rna_path = rna_path_rename_fix(owner_id, prefix, oldKey, newKey, fcu->rna_path, verify_paths);
+                       
+                       /* if path changed and the F-Curve is grouped, check if its group also needs renaming
+                        * (i.e. F-Curve is first of a bone's F-Curves; hence renaming this should also trigger rename)
+                        */
+                       if (fcu->rna_path != old_path) {
+                               bActionGroup *agrp = fcu->grp;
+                               
+                               if ((agrp) && strcmp(oldName, agrp->name)==0) {
+                                       BLI_strncpy(agrp->name, newName, sizeof(agrp->name));
+                               }
+                       }
+               }
        }
 }
 
@@ -675,7 +690,8 @@ static void drivers_path_rename_fix(ID *owner_id, ID *ref_id, const char *prefix
 }
 
 /* Fix all RNA-Paths for Actions linked to NLA Strips */
-static void nlastrips_path_rename_fix(ID *owner_id, const char *prefix, char *oldName, char *newName, ListBase *strips, int verify_paths)
+static void nlastrips_path_rename_fix(ID *owner_id, const char *prefix, const char *oldName, const char *newName, 
+                                      const char *oldKey, const char *newKey, ListBase *strips, int verify_paths)
 {
        NlaStrip *strip;
        
@@ -683,11 +699,11 @@ static void nlastrips_path_rename_fix(ID *owner_id, const char *prefix, char *ol
        for (strip = strips->first; strip; strip = strip->next) {
                /* fix strip's action */
                if (strip->act)
-                       fcurves_path_rename_fix(owner_id, prefix, oldName, newName, &strip->act->curves, verify_paths);
+                       fcurves_path_rename_fix(owner_id, prefix, oldName, newName, oldKey, newKey, &strip->act->curves, verify_paths);
                /* ignore own F-Curves, since those are local...  */
                
                /* check sub-strips (if metas) */
-               nlastrips_path_rename_fix(owner_id, prefix, oldName, newName, &strip->strips, verify_paths);
+               nlastrips_path_rename_fix(owner_id, prefix, oldName, newName, oldKey, newKey, &strip->strips, verify_paths);
        }
 }
 
@@ -717,16 +733,16 @@ void BKE_animdata_fix_paths_rename(ID *owner_id, AnimData *adt, ID *ref_id, cons
        
        /* Active action and temp action */
        if (adt->action)
-               fcurves_path_rename_fix(owner_id, prefix, oldN, newN, &adt->action->curves, verify_paths);
+               fcurves_path_rename_fix(owner_id, prefix, oldName, newName, oldN, newN, &adt->action->curves, verify_paths);
        if (adt->tmpact)
-               fcurves_path_rename_fix(owner_id, prefix, oldN, newN, &adt->tmpact->curves, verify_paths);
+               fcurves_path_rename_fix(owner_id, prefix, oldName, newName, oldN, newN, &adt->tmpact->curves, verify_paths);
                
        /* Drivers - Drivers are really F-Curves */
        drivers_path_rename_fix(owner_id, ref_id, prefix, oldName, newName, oldN, newN, &adt->drivers, verify_paths);
        
        /* NLA Data - Animation Data for Strips */
        for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next)
-               nlastrips_path_rename_fix(owner_id, prefix, oldN, newN, &nlt->strips, verify_paths);
+               nlastrips_path_rename_fix(owner_id, prefix, oldName, newName, oldN, newN, &nlt->strips, verify_paths);
                
        /* free the temp names */
        MEM_freeN(oldN);
index 738e7ad2219b1ff8876bec6c37e1ba3bb091d058..be70405d165e24a35b445cf78d1a01732504fa68 100644 (file)
@@ -146,6 +146,18 @@ static void rna_Armature_redraw_data(Main *UNUSED(bmain), Scene *UNUSED(scene),
        WM_main_add_notifier(NC_GEOM | ND_DATA, id);
 }
 
+/* called whenever a bone is renamed */
+static void rna_Bone_update_renamed(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
+{
+       ID *id = ptr->id.data;
+       
+       /* redraw view */
+       WM_main_add_notifier(NC_GEOM | ND_DATA, id);
+       
+       /* update animation channels */
+       WM_main_add_notifier(NC_ANIMATION | ND_ANIMCHAN, id);
+}
+
 static void rna_Bone_select_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
 {
        ID *id = ptr->id.data;
@@ -470,7 +482,7 @@ static void rna_def_bone_common(StructRNA *srna, int editbone)
        RNA_def_struct_name_property(srna, prop);
        if (editbone) RNA_def_property_string_funcs(prop, NULL, NULL, "rna_EditBone_name_set");
        else RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Bone_name_set");
-       RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
+       RNA_def_property_update(prop, 0, "rna_Bone_update_renamed");
 
        /* flags */
        prop = RNA_def_property(srna, "layers", PROP_BOOLEAN, PROP_LAYER_MEMBER);