Fixes for Path-Renaming Fix:

* 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.
This commit is contained in:
Joshua Leung
2009-10-20 04:07:57 +00:00
parent 7f133f65b2
commit 8bc1087e2e
7 changed files with 23 additions and 90 deletions

View 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)

View 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"

View 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);

View 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)
{

View 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"

View 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"

View 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 */