diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 99b778b549e..400284d87f4 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -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; diff --git a/source/blender/include/BIF_editconstraint.h b/source/blender/include/BIF_editconstraint.h index 5db034f57de..db55bc5c7d7 100644 --- a/source/blender/include/BIF_editconstraint.h +++ b/source/blender/include/BIF_editconstraint.h @@ -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 diff --git a/source/blender/src/buttons_object.c b/source/blender/src/buttons_object.c index eac032640fb..65cf065bd66 100644 --- a/source/blender/src/buttons_object.c +++ b/source/blender/src/buttons_object.c @@ -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); diff --git a/source/blender/src/editconstraint.c b/source/blender/src/editconstraint.c index aefec006930..10a930b9ebc 100644 --- a/source/blender/src/editconstraint.c +++ b/source/blender/src/editconstraint.c @@ -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)); + } + } + +} +