Removed the internal_select parameter from ntreeCopyTree. This was used just in one...
authorLukas Toenne <lukas.toenne@googlemail.com>
Fri, 11 Feb 2011 09:37:58 +0000 (09:37 +0000)
committerLukas Toenne <lukas.toenne@googlemail.com>
Fri, 11 Feb 2011 09:37:58 +0000 (09:37 +0000)
source/blender/blenkernel/BKE_node.h
source/blender/blenkernel/intern/library.c
source/blender/blenkernel/intern/material.c
source/blender/blenkernel/intern/node.c
source/blender/blenkernel/intern/scene.c
source/blender/blenkernel/intern/texture.c
source/blender/editors/space_node/node_edit.c

index 8428716ef1a10ca49eeaa8c7838bbd13058a794a..57d18f58e2d18589317c342aa6cf629246c62864 100644 (file)
@@ -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);
 
index 66b6d43d259a89d6f6c17cd43cd9892243ac3385..6eb5399404a3f12cf527c9157f33359d13363737 100644 (file)
@@ -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);
index c49d8310789d1712ebe26c3045d2cbc98a90bd83..152323dfb4d8dc5000e4d90e73860616b70e244a 100644 (file)
@@ -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);
 }
index d9e7680a2d89a55214cfee675b6a2dec9851efc0..218539b311ab8a631759f36196d49e9b49eb7ad9 100644 (file)
@@ -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(&ltree->id);
index b6768a746fb66e40ccce6b80e04d3027fcbf381b..1611116f0af569059282b684dc2954a5aedee03a 100644 (file)
@@ -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);
                }
 
index de08a3b1813d0b9c04dbae687b0d9cf21e9bb472..57c629d5544372e552ff30eb8eb7356f15dc6374 100644 (file)
@@ -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;
index 7827058f886ec9eb983c28c856c3e107020ab04d..624630b98464832bf7b2212ff616486b3d417c7a 100644 (file)
@@ -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);