Bugfix #5022
If you rename a Constraint, the used Constraint Channels (Ipo curves) were not renamed as well, making animations not work anymore. Now renaming works up to this level: - own object constraints - own object Action constraints This is identical to Bone renaming. Note that other actions (like in NLA) are not corrected for renaming. Have to look at ways to provide that once.
This commit is contained in:
@@ -1292,7 +1292,7 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree)
|
||||
bNodeSocket *sock;
|
||||
bNodeLink *link;
|
||||
|
||||
ntree->init= 0; /* to set callbacks */
|
||||
ntree->init= 0; /* to set callbacks and force setting types */
|
||||
ntree->owntype= NULL;
|
||||
ntree->timecursor= NULL;
|
||||
|
||||
|
||||
@@ -55,5 +55,8 @@ void ob_clear_constraints(void);
|
||||
|
||||
char *get_con_subtarget_name(struct bConstraint *con, struct Object *target);
|
||||
|
||||
void rename_constraint(struct Object *ob, struct bConstraint *con, char *newname);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -300,18 +300,22 @@ static void del_constraint_func (void *ob_v, void *con_v)
|
||||
allqueue(REDRAWIPO, 0);
|
||||
}
|
||||
|
||||
static void verify_constraint_name_func (void *ob_v, void *con_v)
|
||||
static void verify_constraint_name_func (void *con_v, void *name_v)
|
||||
{
|
||||
ListBase *conlist;
|
||||
Object *ob= OBACT;
|
||||
bConstraint *con= con_v;
|
||||
char oldname[32];
|
||||
|
||||
if (!con)
|
||||
return;
|
||||
|
||||
conlist = get_active_constraints(ob_v);
|
||||
unique_constraint_name (con, conlist);
|
||||
constraint_active_func(ob_v, con);
|
||||
/* put on the stack */
|
||||
BLI_strncpy(oldname, (char *)name_v, 32);
|
||||
|
||||
rename_constraint(ob, con, oldname);
|
||||
|
||||
constraint_active_func(ob, con);
|
||||
allqueue(REDRAWACTION, 0);
|
||||
}
|
||||
|
||||
void get_constraint_typestring (char *str, void *con_v)
|
||||
@@ -585,7 +589,7 @@ static void draw_constraint (uiBlock *block, ListBase *list, bConstraint *con, s
|
||||
uiDefBut(block, LABEL, B_CONSTRAINT_TEST, typestr, *xco+10, *yco, 100, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
|
||||
|
||||
but = uiDefBut(block, TEX, B_CONSTRAINT_TEST, "", *xco+120, *yco, 85, 18, con->name, 0.0, 29.0, 0.0, 0.0, "Constraint name");
|
||||
uiButSetFunc(but, verify_constraint_name_func, ob, con);
|
||||
uiButSetFunc(but, verify_constraint_name_func, con, NULL);
|
||||
}
|
||||
else{
|
||||
uiBlockSetEmboss(block, UI_EMBOSSN);
|
||||
|
||||
@@ -817,3 +817,66 @@ void ob_clear_constraints(void)
|
||||
|
||||
}
|
||||
|
||||
/* con already has the new name */
|
||||
void rename_constraint(Object *ob, bConstraint *con, char *oldname)
|
||||
{
|
||||
bConstraint *tcon;
|
||||
bConstraintChannel *conchan;
|
||||
ListBase *conlist= NULL;
|
||||
int from_object= 0;
|
||||
char *channame;
|
||||
|
||||
/* get context by searching for con (primitive...) */
|
||||
for(tcon= ob->constraints.first; tcon; tcon= tcon->next)
|
||||
if(tcon==con)
|
||||
break;
|
||||
|
||||
if(tcon) {
|
||||
conlist= &ob->constraints;
|
||||
channame= "Object";
|
||||
from_object= 1;
|
||||
}
|
||||
else if(ob->pose) {
|
||||
bPoseChannel *pchan;
|
||||
|
||||
for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
|
||||
for(tcon= pchan->constraints.first; tcon; tcon= tcon->next) {
|
||||
if(tcon==con)
|
||||
break;
|
||||
}
|
||||
if(tcon)
|
||||
break;
|
||||
}
|
||||
if(tcon) {
|
||||
conlist= &pchan->constraints;
|
||||
channame= pchan->name;
|
||||
}
|
||||
}
|
||||
|
||||
if(conlist==NULL) {
|
||||
printf("rename constraint failed\n"); /* should not happen in UI */
|
||||
return;
|
||||
}
|
||||
|
||||
/* first make sure it's a unique name within context */
|
||||
unique_constraint_name (con, conlist);
|
||||
|
||||
/* own channels */
|
||||
if(from_object) {
|
||||
for(conchan= ob->constraintChannels.first; conchan; conchan= conchan->next) {
|
||||
if( strcmp(oldname, conchan->name)==0 )
|
||||
BLI_strncpy(conchan->name, con->name, sizeof(conchan->name));
|
||||
}
|
||||
}
|
||||
/* own action */
|
||||
if(ob->action) {
|
||||
bActionChannel *achan= get_action_channel(ob->action, channame);
|
||||
if(achan) {
|
||||
conchan= get_constraint_channel(&achan->constraintChannels, oldname);
|
||||
if(conchan)
|
||||
BLI_strncpy(conchan->name, con->name, sizeof(conchan->name));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user