Removed the internal_select parameter from ntreeCopyTree. This was used just in one place when duplicating nodes, which is not an actual copying of the tree. The node duplicate operator now copies selected nodes itself.

This commit is contained in:
Lukas Toenne 2011-02-11 09:37:58 +00:00
parent a3d142fce0
commit 69e72ea427
7 changed files with 58 additions and 59 deletions

@ -136,7 +136,7 @@ void ntreeInitTypes(struct bNodeTree *ntree);
void ntreeMakeOwnType(struct bNodeTree *ntree); void ntreeMakeOwnType(struct bNodeTree *ntree);
void ntreeUpdateType(struct bNodeTree *ntree, struct bNodeType *ntype); void ntreeUpdateType(struct bNodeTree *ntree, struct bNodeType *ntype);
void ntreeFreeTree(struct bNodeTree *ntree); void ntreeFreeTree(struct bNodeTree *ntree);
struct bNodeTree *ntreeCopyTree(struct bNodeTree *ntree, int internal_select); struct bNodeTree *ntreeCopyTree(struct bNodeTree *ntree);
void ntreeSwitchID(struct bNodeTree *ntree, struct ID *sce_from, struct ID *sce_to); void ntreeSwitchID(struct bNodeTree *ntree, struct ID *sce_from, struct ID *sce_to);
void ntreeMakeLocal(struct bNodeTree *ntree); void ntreeMakeLocal(struct bNodeTree *ntree);

@ -310,7 +310,7 @@ int id_copy(ID *id, ID **newid, int test)
if(!test) *newid= (ID*)copy_action((bAction*)id); if(!test) *newid= (ID*)copy_action((bAction*)id);
return 1; return 1;
case ID_NT: case ID_NT:
if(!test) *newid= (ID*)ntreeCopyTree((bNodeTree*)id, 0); if(!test) *newid= (ID*)ntreeCopyTree((bNodeTree*)id);
return 1; return 1;
case ID_BR: case ID_BR:
if(!test) *newid= (ID*)copy_brush((Brush*)id); if(!test) *newid= (ID*)copy_brush((Brush*)id);

@ -223,7 +223,7 @@ Material *copy_material(Material *ma)
if (ma->preview) man->preview = BKE_previewimg_copy(ma->preview); if (ma->preview) man->preview = BKE_previewimg_copy(ma->preview);
if(ma->nodetree) { if(ma->nodetree) {
man->nodetree= ntreeCopyTree(ma->nodetree, 0); /* 0 == full new tree */ man->nodetree= ntreeCopyTree(ma->nodetree); /* 0 == full new tree */
} }
man->gpumaterial.first= man->gpumaterial.last= NULL; man->gpumaterial.first= man->gpumaterial.last= NULL;
@ -1401,7 +1401,7 @@ void copy_matcopybuf(Material *ma)
matcopybuf.mtex[a]= MEM_dupallocN(mtex); matcopybuf.mtex[a]= MEM_dupallocN(mtex);
} }
} }
matcopybuf.nodetree= ntreeCopyTree(ma->nodetree, 0); matcopybuf.nodetree= ntreeCopyTree(ma->nodetree);
matcopybuf.preview= NULL; matcopybuf.preview= NULL;
matcopybuf.gpumaterial.first= matcopybuf.gpumaterial.last= NULL; matcopybuf.gpumaterial.first= matcopybuf.gpumaterial.last= NULL;
matcopied= 1; matcopied= 1;
@ -1446,5 +1446,5 @@ void paste_matcopybuf(Material *ma)
} }
} }
ma->nodetree= ntreeCopyTree(matcopybuf.nodetree, 0); ma->nodetree= ntreeCopyTree(matcopybuf.nodetree);
} }

@ -826,7 +826,7 @@ int nodeGroupUnGroup(bNodeTree *ntree, bNode *gnode)
* - all of wgroup's nodes are transferred across to their new home * - all of wgroup's nodes are transferred across to their new home
* - ngroup (i.e. the source NodeTree) is left unscathed * - ngroup (i.e. the source NodeTree) is left unscathed
*/ */
wgroup= ntreeCopyTree(ngroup, 0); wgroup= ntreeCopyTree(ngroup);
/* add the nodes into the ntree */ /* add the nodes into the ntree */
for(node= wgroup->nodes.first; node; node= nextn) { for(node= wgroup->nodes.first; node; node= nextn) {
@ -926,7 +926,7 @@ void nodeCopyGroup(bNode *gnode)
bNodeSocket *sock; bNodeSocket *sock;
gnode->id->us--; gnode->id->us--;
gnode->id= (ID *)ntreeCopyTree((bNodeTree *)gnode->id, 0); gnode->id= (ID *)ntreeCopyTree((bNodeTree *)gnode->id);
/* new_sock was set in nodeCopyNode */ /* new_sock was set in nodeCopyNode */
for(sock=gnode->inputs.first; sock; sock=sock->next) for(sock=gnode->inputs.first; sock; sock=sock->next)
@ -1191,12 +1191,11 @@ bNodeTree *ntreeAddTree(const char *name, int type, const short is_group)
} }
/* Warning: this function gets called during some rather unexpected times /* Warning: this function gets called during some rather unexpected times
* - internal_select is only 1 when used for duplicating selected nodes (i.e. Shift-D duplicate operator)
* - this gets called when executing compositing updates (for threaded previews) * - this gets called when executing compositing updates (for threaded previews)
* - when the nodetree datablock needs to be copied (i.e. when users get copied) * - when the nodetree datablock needs to be copied (i.e. when users get copied)
* - for scene duplication use ntreeSwapID() after so we dont have stale pointers. * - for scene duplication use ntreeSwapID() after so we dont have stale pointers.
*/ */
bNodeTree *ntreeCopyTree(bNodeTree *ntree, int internal_select) bNodeTree *ntreeCopyTree(bNodeTree *ntree)
{ {
bNodeTree *newtree; bNodeTree *newtree;
bNode *node, *nnode, *last; bNode *node, *nnode, *last;
@ -1206,7 +1205,6 @@ bNodeTree *ntreeCopyTree(bNodeTree *ntree, int internal_select)
if(ntree==NULL) return NULL; if(ntree==NULL) return NULL;
if(internal_select==0) {
/* is ntree part of library? */ /* is ntree part of library? */
for(newtree=G.main->nodetree.first; newtree; newtree= newtree->id.next) for(newtree=G.main->nodetree.first; newtree; newtree= newtree->id.next)
if(newtree==ntree) break; if(newtree==ntree) break;
@ -1218,22 +1216,15 @@ bNodeTree *ntreeCopyTree(bNodeTree *ntree, int internal_select)
} }
newtree->nodes.first= newtree->nodes.last= NULL; newtree->nodes.first= newtree->nodes.last= NULL;
newtree->links.first= newtree->links.last= NULL; newtree->links.first= newtree->links.last= NULL;
}
else
newtree= ntree;
last = ntree->nodes.last; last = ntree->nodes.last;
for(node= ntree->nodes.first; node; node= node->next) { for(node= ntree->nodes.first; node; node= node->next) {
node->new_node= NULL; node->new_node= NULL;
if(internal_select==0 || (node->flag & NODE_SELECT)) { nnode= nodeCopyNode(newtree, node, 0); /* sets node->new */
nnode= nodeCopyNode(newtree, node, internal_select); /* sets node->new */
if(internal_select) { /* make sure we don't copy new nodes again! */
node->flag &= ~(NODE_SELECT|NODE_ACTIVE); if (node==last)
nnode->flag |= NODE_SELECT; break;
}
}
if(node==last) break;
} }
/* check for copying links */ /* check for copying links */
@ -1257,7 +1248,6 @@ bNodeTree *ntreeCopyTree(bNodeTree *ntree, int internal_select)
} }
/* own type definition for group usage */ /* own type definition for group usage */
if(internal_select==0) {
if(ntree->owntype) { if(ntree->owntype) {
newtree->owntype= MEM_dupallocN(ntree->owntype); newtree->owntype= MEM_dupallocN(ntree->owntype);
if(ntree->owntype->inputs) if(ntree->owntype->inputs)
@ -1265,7 +1255,7 @@ bNodeTree *ntreeCopyTree(bNodeTree *ntree, int internal_select)
if(ntree->owntype->outputs) if(ntree->owntype->outputs)
newtree->owntype->outputs= MEM_dupallocN(ntree->owntype->outputs); newtree->owntype->outputs= MEM_dupallocN(ntree->owntype->outputs);
} }
}
/* weird this is required... there seem to be link pointers wrong still? */ /* weird this is required... there seem to be link pointers wrong still? */
/* anyhoo, doing this solves crashes on copying entire tree (copy scene) and delete nodes */ /* anyhoo, doing this solves crashes on copying entire tree (copy scene) and delete nodes */
ntreeSolveOrder(newtree); ntreeSolveOrder(newtree);
@ -1573,7 +1563,7 @@ void ntreeMakeLocal(bNodeTree *ntree)
} }
else if(local && lib) { else if(local && lib) {
/* this is the mixed case, we copy the tree and assign it to local users */ /* this is the mixed case, we copy the tree and assign it to local users */
bNodeTree *newtree= ntreeCopyTree(ntree, 0); bNodeTree *newtree= ntreeCopyTree(ntree);
newtree->id.us= 0; newtree->id.us= 0;
@ -2741,7 +2731,7 @@ bNodeTree *ntreeLocalize(bNodeTree *ntree)
} }
/* node copy func */ /* node copy func */
ltree= ntreeCopyTree(ntree, 0); ltree= ntreeCopyTree(ntree);
if(adt) { if(adt) {
AnimData *ladt= BKE_animdata_from_id(&ltree->id); AnimData *ladt= BKE_animdata_from_id(&ltree->id);

@ -171,7 +171,7 @@ Scene *copy_scene(Scene *sce, int type)
BKE_keyingsets_copy(&(scen->keyingsets), &(sce->keyingsets)); BKE_keyingsets_copy(&(scen->keyingsets), &(sce->keyingsets));
if(sce->nodetree) { if(sce->nodetree) {
scen->nodetree= ntreeCopyTree(sce->nodetree, 0); /* copies actions */ scen->nodetree= ntreeCopyTree(sce->nodetree); /* copies actions */
ntreeSwitchID(scen->nodetree, &sce->id, &scen->id); ntreeSwitchID(scen->nodetree, &sce->id, &scen->id);
} }

@ -760,7 +760,7 @@ Tex *copy_texture(Tex *tex)
if(tex->nodetree) { if(tex->nodetree) {
ntreeEndExecTree(tex->nodetree); ntreeEndExecTree(tex->nodetree);
texn->nodetree= ntreeCopyTree(tex->nodetree, 0); /* 0 == full new tree */ texn->nodetree= ntreeCopyTree(tex->nodetree); /* 0 == full new tree */
} }
return texn; return texn;

@ -1693,27 +1693,36 @@ bNode *node_add_node(SpaceNode *snode, Scene *scene, int type, float locx, float
static int node_duplicate_exec(bContext *C, wmOperator *UNUSED(op)) static int node_duplicate_exec(bContext *C, wmOperator *UNUSED(op))
{ {
SpaceNode *snode= CTX_wm_space_node(C); SpaceNode *snode= CTX_wm_space_node(C);
bNode *node; bNodeTree *ntree= snode->edittree;
bNode *node, *newnode, *last;
ED_preview_kill_jobs(C); ED_preview_kill_jobs(C);
last = ntree->nodes.last;
for(node= ntree->nodes.first; node; node= node->next) {
if(node->flag & SELECT) {
newnode = nodeCopyNode(ntree, node, 1);
/* deselect old node, select the copy instead */
node->flag &= ~(NODE_SELECT|NODE_ACTIVE);
newnode->flag |= NODE_SELECT;
if(newnode->id) {
/* simple id user adjustment, node internal functions dont touch this /* simple id user adjustment, node internal functions dont touch this
* but operators and readfile.c do. */ * but operators and readfile.c do. */
for(node= snode->edittree->nodes.first; node; node= node->next) { id_us_plus(newnode->id);
if(node->flag & SELECT) {
id_us_plus(node->id);
}
}
ntreeCopyTree(snode->edittree, 1); /* 1 == internally selected nodes */
/* to ensure redraws or rerenders happen */ /* to ensure redraws or rerenders happen */
for(node= snode->edittree->nodes.first; node; node= node->next) ED_node_changed_update(snode->id, newnode);
if(node->flag & SELECT) }
if(node->id) }
ED_node_changed_update(snode->id, node);
/* make sure we don't copy new nodes again! */
if (node==last)
break;
}
ntreeSolveOrder(ntree);
ntreeSolveOrder(snode->edittree);
node_tree_verify_groups(snode->nodetree); node_tree_verify_groups(snode->nodetree);
snode_notify(C, snode); snode_notify(C, snode);