Fixes for Path-Renaming Fix:
authorJoshua Leung <aligorith@gmail.com>
Tue, 20 Oct 2009 04:07:57 +0000 (04:07 +0000)
committerJoshua Leung <aligorith@gmail.com>
Tue, 20 Oct 2009 04:07:57 +0000 (04:07 +0000)
* Now the old/new names get tagged with [" "] before the search and replace operation, which should alleviate problems with searching for 'bone' and ending up with all instances of 'boney' 'boney.r' etc. also getting renamed.

* Cleaned up some compiler warnings, and removed an unused function from an earlier attempt at this work.

source/blender/blenkernel/intern/anim_sys.c
source/blender/editors/armature/editarmature.c
source/blender/makesrna/RNA_access.h
source/blender/makesrna/intern/rna_access.c
source/blender/makesrna/intern/rna_constraint.c
source/blender/makesrna/intern/rna_key.c
source/blender/makesrna/intern/rna_modifier.c

index 316ac48448436303dc1342b99cdfa6ec6440e331..7088081d66f2283c42dcb4eabd51694e6d27f91f 100644 (file)
@@ -239,9 +239,7 @@ void BKE_animdata_make_local(AnimData *adt)
 /* Path Validation -------------------------------------------- */
 
 /* Check if some given RNA Path needs fixing - free the given path and set a new one as appropriate 
- *
- * NOTE: it is assumed that the structure we're replacing is <prefix><["><name><"]>
- *             i.e. pose.pose_channels["Bone"]
+ * NOTE: we assume that oldName and newName have [" "] padding around them
  */
 static char *rna_path_rename_fix (ID *owner_id, char *prefix, char *oldName, char *newName, char *oldpath)
 {
@@ -253,9 +251,9 @@ static char *rna_path_rename_fix (ID *owner_id, char *prefix, char *oldName, cha
        /* only start fixing the path if the prefix and oldName feature in the path,
         * and prefix occurs immediately before oldName (the +2 should take care of any [")
         */
-       if ( (prefixPtr && oldNamePtr) && (prefixPtr+prefixLen+2 == oldNamePtr) ) {
+       if ( (prefixPtr && oldNamePtr) && (prefixPtr+prefixLen == oldNamePtr) ) {
                DynStr *ds= BLI_dynstr_new();
-               char *postfixPtr= oldNamePtr+oldNameLen+2;
+               char *postfixPtr= oldNamePtr+oldNameLen;
                char *newPath = NULL;
                char oldChar;
                
@@ -267,15 +265,13 @@ static char *rna_path_rename_fix (ID *owner_id, char *prefix, char *oldName, cha
                        prefixPtr[0]= oldChar;
                }
                
-               /* add the prefix, and opening brackets */
+               /* add the prefix */
                BLI_dynstr_append(ds, prefix);
-               BLI_dynstr_append(ds, "[\"");
                
-               /* add the new name */
+               /* add the new name (complete with brackets) */
                BLI_dynstr_append(ds, newName);
                
-               /* add the closing brackets, then the postfix */
-               BLI_dynstr_append(ds, "\"]");
+               /* add the postfix */
                BLI_dynstr_append(ds, postfixPtr);
                
                /* create new path, and cleanup old data */
@@ -339,23 +335,32 @@ static void nlastrips_path_rename_fix (ID *owner_id, char *prefix, char *oldName
 void BKE_animdata_fix_paths_rename (ID *owner_id, AnimData *adt, char *prefix, char *oldName, char *newName)
 {
        NlaTrack *nlt;
+       char *oldN, *newN;
        
        /* if no AnimData, no need to proceed */
        if (ELEM4(NULL, owner_id, adt, oldName, newName))
                return;
        
+       /* pad the names with [" "] so that only exact matches are made */
+       oldN= BLI_sprintfN("[\"%s\"]", oldName);
+       newN= BLI_sprintfN("[\"%s\"]", newName);
+       
        /* Active action and temp action */
        if (adt->action)
-               fcurves_path_rename_fix(owner_id, prefix, oldName, newName, &adt->action->curves);
+               fcurves_path_rename_fix(owner_id, prefix, oldN, newN, &adt->action->curves);
        if (adt->tmpact)
-               fcurves_path_rename_fix(owner_id, prefix, oldName, newName, &adt->tmpact->curves);
+               fcurves_path_rename_fix(owner_id, prefix, oldN, newN, &adt->tmpact->curves);
                
        /* Drivers - Drivers are really F-Curves */
-       fcurves_path_rename_fix(owner_id, prefix, oldName, newName, &adt->drivers);
+       fcurves_path_rename_fix(owner_id, prefix, oldN, newN, &adt->drivers);
        
        /* NLA Data - Animation Data for Strips */
        for (nlt= adt->nla_tracks.first; nlt; nlt= nlt->next)
-               nlastrips_path_rename_fix(owner_id, prefix, oldName, newName, &nlt->strips);
+               nlastrips_path_rename_fix(owner_id, prefix, oldN, newN, &nlt->strips);
+               
+       /* free the temp names */
+       MEM_freeN(oldN);
+       MEM_freeN(newN);
 }
 
 /* Fix all RNA-Paths throughout the database (directly access the Global.main version)
index 1c2ec920d413eec53c52c22345388d6bcefe06df..b92b69c4e8e966d72754c2f7fded971fe0db2de0 100644 (file)
@@ -55,6 +55,7 @@
 #include "BLI_editVert.h"
 #include "BLI_ghash.h"
 
+#include "BKE_animsys.h"
 #include "BKE_action.h"
 #include "BKE_armature.h"
 #include "BKE_constraint.h"
index a3cdf29669f329bbf8f89faddc27903f98931119..810fb110f7a0add232fe8484257be46a9b1e30b6 100644 (file)
@@ -704,8 +704,6 @@ char *RNA_path_back(const char *path);
 
 int RNA_path_resolve(PointerRNA *ptr, const char *path,
        PointerRNA *r_ptr, PropertyRNA **r_prop);
-int RNA_path_resolve_next(PointerRNA *ptr, char **path, 
-       PointerRNA *r_ptr, PropertyRNA **r_prop);
 
 char *RNA_path_from_ID_to_struct(PointerRNA *ptr);
 char *RNA_path_from_ID_to_property(PointerRNA *ptr, PropertyRNA *prop);
index a2202b36c0c3cf977cb8f6d84af44fa2490e1ceb..525218c5185bf264f0e86c21d00500c2a057bece 100644 (file)
@@ -2216,80 +2216,6 @@ static char *rna_path_token(const char **path, char *fixedbuf, int fixedlen, int
        return buf;
 }
 
-/* Resolve the given RNA path to find the next pointer+property pointed to in the path */
-// NOTE: this is the same as the code below, except that we don't have the while() loop to traverse the entire path
-int RNA_path_resolve_next(PointerRNA *ptr, char **path, PointerRNA *r_ptr, PropertyRNA **r_prop)
-{
-       PropertyRNA *prop;
-       PointerRNA curptr, nextptr;
-       char fixedbuf[256], *token;
-       int len, intkey;
-
-       prop= NULL;
-       curptr= *ptr;
-
-       if ((path == NULL) || (*path == 0))
-               return 0;
-       
-       /* look up property name in current struct */
-       token= rna_path_token(&path, fixedbuf, sizeof(fixedbuf), 0);
-       if (!token)
-               return 0;
-
-       prop= RNA_struct_find_property(&curptr, token);
-       
-       if(token != fixedbuf)
-               MEM_freeN(token);
-       if (!prop)
-               return 0;
-       
-       /* now look up the value of this property if it is a pointer or
-        * collection, otherwise return the property rna so that the
-        * caller can read the value of the property itself */
-       if(RNA_property_type(prop) == PROP_POINTER) {
-               nextptr= RNA_property_pointer_get(&curptr, prop);
-               
-               if(nextptr.data)
-                       curptr= nextptr;
-               else
-                       return 0;
-       }
-       else if(RNA_property_type(prop) == PROP_COLLECTION && *path) {
-               /* resolve the lookup with [] brackets */
-               token= rna_path_token(&path, fixedbuf, sizeof(fixedbuf), 1);
-               
-               if(!token)
-                       return 0;
-               
-               len= strlen(token);
-               
-               /* check for "" to see if it is a string */
-               if(len >= 2 && token[0] == '"' && token[len-1] == '"') {
-                       /* strip away "" */
-                       token[len-1]= 0;
-                       RNA_property_collection_lookup_string(&curptr, prop, token+1, &nextptr);
-               }
-               else {
-                       /* otherwise do int lookup */
-                       intkey= atoi(token);
-                       RNA_property_collection_lookup_int(&curptr, prop, intkey, &nextptr);
-               }
-               
-               if(token != fixedbuf)
-                       MEM_freeN(token);
-               
-               if(nextptr.data)
-                       curptr= nextptr;
-               else
-                       return 0;
-       }
-
-       *r_ptr= curptr;
-       *r_prop= prop;
-
-       return 1;
-}
-
 /* Resolve the given RNA path to find the pointer+property indicated at the end of the path */
 int RNA_path_resolve(PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
 {
index 54097f25b9990d23d16761260365e34c45a31c88..a820073d3856827e77420519fe51926404b8cfdc 100644 (file)
@@ -95,6 +95,7 @@ EnumPropertyItem constraint_ik_axisref_items[] ={
 
 #ifdef RNA_RUNTIME
 
+#include "BKE_animsys.h"
 #include "BKE_action.h"
 #include "BKE_constraint.h"
 #include "BKE_context.h"
index 1e1eb9b055fdd359de08c3adcd31e3a83a03b9ae..9daf1155149505c92812b2286b92d291c105958a 100644 (file)
@@ -42,6 +42,7 @@
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 
+#include "BKE_animsys.h"
 #include "BKE_depsgraph.h"
 #include "BKE_key.h"
 #include "BKE_main.h"
index 91df780015615651dfcd8e18f8c9b4e6e72b64c3..6f45c8c2e20ecc283419727ee0b8d1a0a4a5ad40 100644 (file)
@@ -37,6 +37,7 @@
 #include "DNA_object_force.h"
 #include "DNA_scene_types.h"
 
+#include "BKE_animsys.h"
 #include "BKE_bmesh.h" /* For BevelModifierData */
 #include "BKE_smoke.h" /* For smokeModifier_free & smokeModifier_createType */