diff options
author | Lukas Toenne <lukas.toenne@googlemail.com> | 2011-02-11 12:37:58 +0300 |
---|---|---|
committer | Lukas Toenne <lukas.toenne@googlemail.com> | 2011-02-11 12:37:58 +0300 |
commit | 69e72ea42790e5db142365cba46adbd23ecf3b4c (patch) | |
tree | b13ebed9bb751fae1f7ac46c43fc72a8199803c8 | |
parent | a3d142fce05634d9cf12d0ad12493d0625579732 (diff) |
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.
-rw-r--r-- | source/blender/blenkernel/BKE_node.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/library.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/material.c | 6 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/node.c | 66 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/scene.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/texture.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_edit.c | 37 |
7 files changed, 58 insertions, 59 deletions
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 8428716ef1a..57d18f58e2d 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -136,7 +136,7 @@ void ntreeInitTypes(struct bNodeTree *ntree); void ntreeMakeOwnType(struct bNodeTree *ntree); void ntreeUpdateType(struct bNodeTree *ntree, struct bNodeType *ntype); 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 ntreeMakeLocal(struct bNodeTree *ntree); diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 66b6d43d259..6eb5399404a 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -310,7 +310,7 @@ int id_copy(ID *id, ID **newid, int test) if(!test) *newid= (ID*)copy_action((bAction*)id); return 1; case ID_NT: - if(!test) *newid= (ID*)ntreeCopyTree((bNodeTree*)id, 0); + if(!test) *newid= (ID*)ntreeCopyTree((bNodeTree*)id); return 1; case ID_BR: if(!test) *newid= (ID*)copy_brush((Brush*)id); diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index c49d8310789..152323dfb4d 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -223,7 +223,7 @@ Material *copy_material(Material *ma) if (ma->preview) man->preview = BKE_previewimg_copy(ma->preview); 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; @@ -1401,7 +1401,7 @@ void copy_matcopybuf(Material *ma) matcopybuf.mtex[a]= MEM_dupallocN(mtex); } } - matcopybuf.nodetree= ntreeCopyTree(ma->nodetree, 0); + matcopybuf.nodetree= ntreeCopyTree(ma->nodetree); matcopybuf.preview= NULL; matcopybuf.gpumaterial.first= matcopybuf.gpumaterial.last= NULL; matcopied= 1; @@ -1446,5 +1446,5 @@ void paste_matcopybuf(Material *ma) } } - ma->nodetree= ntreeCopyTree(matcopybuf.nodetree, 0); + ma->nodetree= ntreeCopyTree(matcopybuf.nodetree); } diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index d9e7680a2d8..218539b311a 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -826,7 +826,7 @@ int nodeGroupUnGroup(bNodeTree *ntree, bNode *gnode) * - all of wgroup's nodes are transferred across to their new home * - ngroup (i.e. the source NodeTree) is left unscathed */ - wgroup= ntreeCopyTree(ngroup, 0); + wgroup= ntreeCopyTree(ngroup); /* add the nodes into the ntree */ for(node= wgroup->nodes.first; node; node= nextn) { @@ -926,7 +926,7 @@ void nodeCopyGroup(bNode *gnode) bNodeSocket *sock; gnode->id->us--; - gnode->id= (ID *)ntreeCopyTree((bNodeTree *)gnode->id, 0); + gnode->id= (ID *)ntreeCopyTree((bNodeTree *)gnode->id); /* new_sock was set in nodeCopyNode */ 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 - * - 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) * - 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. */ -bNodeTree *ntreeCopyTree(bNodeTree *ntree, int internal_select) +bNodeTree *ntreeCopyTree(bNodeTree *ntree) { bNodeTree *newtree; bNode *node, *nnode, *last; @@ -1206,34 +1205,26 @@ bNodeTree *ntreeCopyTree(bNodeTree *ntree, int internal_select) if(ntree==NULL) return NULL; - if(internal_select==0) { - /* is ntree part of library? */ - for(newtree=G.main->nodetree.first; newtree; newtree= newtree->id.next) - if(newtree==ntree) break; - if(newtree) { - newtree= copy_libblock(ntree); - } else { - newtree= MEM_dupallocN(ntree); - copy_libblock_data(&newtree->id, &ntree->id, TRUE); /* copy animdata and ID props */ - } - newtree->nodes.first= newtree->nodes.last= NULL; - newtree->links.first= newtree->links.last= NULL; + /* is ntree part of library? */ + for(newtree=G.main->nodetree.first; newtree; newtree= newtree->id.next) + if(newtree==ntree) break; + if(newtree) { + newtree= copy_libblock(ntree); + } else { + newtree= MEM_dupallocN(ntree); + copy_libblock_data(&newtree->id, &ntree->id, TRUE); /* copy animdata and ID props */ } - else - newtree= ntree; + newtree->nodes.first= newtree->nodes.last= NULL; + newtree->links.first= newtree->links.last= NULL; - last= ntree->nodes.last; + last = ntree->nodes.last; for(node= ntree->nodes.first; node; node= node->next) { - node->new_node= NULL; - if(internal_select==0 || (node->flag & NODE_SELECT)) { - nnode= nodeCopyNode(newtree, node, internal_select); /* sets node->new */ - if(internal_select) { - node->flag &= ~(NODE_SELECT|NODE_ACTIVE); - nnode->flag |= NODE_SELECT; - } - } - if(node==last) break; + nnode= nodeCopyNode(newtree, node, 0); /* sets node->new */ + + /* make sure we don't copy new nodes again! */ + if (node==last) + break; } /* check for copying links */ @@ -1257,15 +1248,14 @@ bNodeTree *ntreeCopyTree(bNodeTree *ntree, int internal_select) } /* own type definition for group usage */ - if(internal_select==0) { - if(ntree->owntype) { - newtree->owntype= MEM_dupallocN(ntree->owntype); - if(ntree->owntype->inputs) - newtree->owntype->inputs= MEM_dupallocN(ntree->owntype->inputs); - if(ntree->owntype->outputs) - newtree->owntype->outputs= MEM_dupallocN(ntree->owntype->outputs); - } + if(ntree->owntype) { + newtree->owntype= MEM_dupallocN(ntree->owntype); + if(ntree->owntype->inputs) + newtree->owntype->inputs= MEM_dupallocN(ntree->owntype->inputs); + if(ntree->owntype->outputs) + newtree->owntype->outputs= MEM_dupallocN(ntree->owntype->outputs); } + /* 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 */ ntreeSolveOrder(newtree); @@ -1573,7 +1563,7 @@ void ntreeMakeLocal(bNodeTree *ntree) } else if(local && lib) { /* 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; @@ -2741,7 +2731,7 @@ bNodeTree *ntreeLocalize(bNodeTree *ntree) } /* node copy func */ - ltree= ntreeCopyTree(ntree, 0); + ltree= ntreeCopyTree(ntree); if(adt) { AnimData *ladt= BKE_animdata_from_id(<ree->id); diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index b6768a746fb..1611116f0af 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -171,7 +171,7 @@ Scene *copy_scene(Scene *sce, int type) BKE_keyingsets_copy(&(scen->keyingsets), &(sce->keyingsets)); 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); } diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index de08a3b1813..57c629d5544 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -760,7 +760,7 @@ Tex *copy_texture(Tex *tex) if(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; diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c index 7827058f886..624630b9846 100644 --- a/source/blender/editors/space_node/node_edit.c +++ b/source/blender/editors/space_node/node_edit.c @@ -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)) { SpaceNode *snode= CTX_wm_space_node(C); - bNode *node; + bNodeTree *ntree= snode->edittree; + bNode *node, *newnode, *last; ED_preview_kill_jobs(C); - - /* simple id user adjustment, node internal functions dont touch this - * but operators and readfile.c do. */ - for(node= snode->edittree->nodes.first; node; node= node->next) { + + last = ntree->nodes.last; + for(node= ntree->nodes.first; node; node= node->next) { if(node->flag & SELECT) { - id_us_plus(node->id); + 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 + * but operators and readfile.c do. */ + id_us_plus(newnode->id); + /* to ensure redraws or rerenders happen */ + ED_node_changed_update(snode->id, newnode); + } } + + /* make sure we don't copy new nodes again! */ + if (node==last) + break; } - - ntreeCopyTree(snode->edittree, 1); /* 1 == internally selected nodes */ - /* to ensure redraws or rerenders happen */ - for(node= snode->edittree->nodes.first; node; node= node->next) - if(node->flag & SELECT) - if(node->id) - ED_node_changed_update(snode->id, node); + ntreeSolveOrder(ntree); - ntreeSolveOrder(snode->edittree); node_tree_verify_groups(snode->nodetree); snode_notify(C, snode); |