Three node selection operators added, patch by Michał Ziułek, thanks!
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 14 Sep 2009 08:47:13 +0000 (08:47 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 14 Sep 2009 08:47:13 +0000 (08:47 +0000)
* Select all
* Select linked to
* Select linked from

release/ui/space_node.py
source/blender/editors/space_node/node_edit.c
source/blender/editors/space_node/node_intern.h
source/blender/editors/space_node/node_ops.c
source/blender/editors/space_node/node_select.c

index 6ac1ac84f35e688a329e01a95e29f48893db6232..55b2065084b738cff9be0b1bda0a0743084c05c2 100644 (file)
@@ -74,11 +74,10 @@ class NODE_MT_select(bpy.types.Menu):
 
                layout.itemO("node.select_border")
 
-               # XXX
-               # layout.itemS()
-               # layout.itemO("node.select_all")
-               # layout.itemO("node.select_linked_from")
-               # layout.itemO("node.select_linked_to")
+               layout.itemS()
+               layout.itemO("node.select_all")
+               layout.itemO("node.select_linked_from")
+               layout.itemO("node.select_linked_to")
 
 class NODE_MT_node(bpy.types.Menu):
        __space_type__ = 'NODE_EDITOR'
index bc81c25d106c43010dd9d213e6f3655518eed93e..159a40369145c73988b30dbb8cb8cc3a18268b31 100644 (file)
@@ -1229,27 +1229,14 @@ Material *editnode_get_active_material(Material *ma)
 
 
 /* no undo here! */
-void node_deselectall(SpaceNode *snode, int swap)
+void node_deselectall(SpaceNode *snode)
 {
        bNode *node;
        
-       if(swap) {
-               for(node= snode->edittree->nodes.first; node; node= node->next)
-                       if(node->flag & SELECT)
-                               break;
-               if(node==NULL) {
-                       for(node= snode->edittree->nodes.first; node; node= node->next)
-                               node->flag |= SELECT;
-                       return;
-               }
-               /* else pass on to deselect */
-       }
-       
        for(node= snode->edittree->nodes.first; node; node= node->next)
                node->flag &= ~SELECT;
 }
 
-
 int node_has_hidden_sockets(bNode *node)
 {
        bNodeSocket *sock;
@@ -1606,7 +1593,7 @@ bNode *node_add_node(SpaceNode *snode, Scene *scene, int type, float locx, float
 {
        bNode *node= NULL, *gnode;
        
-       node_deselectall(snode, 0);
+       node_deselectall(snode);
        
        if(type>=NODE_DYNAMIC_MENU) {
                node= nodeAddNodeType(snode->edittree, type, NULL, NULL);
@@ -2091,32 +2078,6 @@ void node_insert_key(SpaceNode *snode)
        }
 }
 
-void node_select_linked(SpaceNode *snode, int out)
-{
-       bNodeLink *link;
-       bNode *node;
-       
-       /* NODE_TEST is the free flag */
-       for(node= snode->edittree->nodes.first; node; node= node->next)
-               node->flag &= ~NODE_TEST;
-
-       for(link= snode->edittree->links.first; link; link= link->next) {
-               if(out) {
-                       if(link->fromnode->flag & NODE_SELECT)
-                               link->tonode->flag |= NODE_TEST;
-               }
-               else {
-                       if(link->tonode->flag & NODE_SELECT)
-                               link->fromnode->flag |= NODE_TEST;
-               }
-       }
-       
-       for(node= snode->edittree->nodes.first; node; node= node->next)
-               if(node->flag & NODE_TEST)
-                       node->flag |= NODE_SELECT;
-       
-}
-
 /* makes a link between selected output and input sockets */
 void node_make_link(SpaceNode *snode)
 {
@@ -2451,9 +2412,6 @@ void winqreadnodespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                if(fromlib) fromlib= -1;
                                else toolbox_n_add();
                        }
-                       else if(G.qual==0) {
-                               node_deselectall(snode, 1);
-                       }
                        break;
                case BKEY:
                        if(G.qual==0)
index 5c66c902797345271b3355e171710703811b605a..6fdaeca7701c31d3bc249dca2c8f4a6213cbc696 100644 (file)
@@ -58,6 +58,9 @@ void node_keymap(wmWindowManager *wm);
 /* node_select.c */
 void NODE_OT_select(struct wmOperatorType *ot);
 void NODE_OT_select_extend(struct wmOperatorType *ot);
+void NODE_OT_select_all(wmOperatorType *ot);
+void NODE_OT_select_linked_to(wmOperatorType *ot);
+void NODE_OT_select_linked_from(wmOperatorType *ot);
 void NODE_OT_visibility_toggle(struct wmOperatorType *ot);
 void NODE_OT_view_all(struct wmOperatorType *ot);
 void NODE_OT_select_border(struct wmOperatorType *ot);
@@ -76,7 +79,7 @@ void snode_set_context(SpaceNode *snode, Scene *scene);
 void snode_make_group_editable(SpaceNode *snode, bNode *gnode);
 void snode_home(ScrArea *sa, ARegion *ar, SpaceNode *snode);
 void node_set_active(SpaceNode *snode, bNode *node);
-void node_deselectall(SpaceNode *snode, int swap);
+void node_deselectall(SpaceNode *snode);
 void snode_composite_job(const struct bContext *C, ScrArea *sa);
 bNode *snode_get_editgroup(SpaceNode *snode);
 void snode_autoconnect(SpaceNode *snode, bNode *node_to, int flag);
index f78abb283130e283a7b6afe4c1407c3b8e477e7d..af857d576348398679dc87c86d34d875ebdfdf61 100644 (file)
@@ -51,6 +51,9 @@ void node_operatortypes(void)
 {
        WM_operatortype_append(NODE_OT_select);
        WM_operatortype_append(NODE_OT_select_extend);
+       WM_operatortype_append(NODE_OT_select_all);
+       WM_operatortype_append(NODE_OT_select_linked_to);
+       WM_operatortype_append(NODE_OT_select_linked_from);
        WM_operatortype_append(NODE_OT_visibility_toggle);
        WM_operatortype_append(NODE_OT_view_all);
        WM_operatortype_append(NODE_OT_select_border);
@@ -59,7 +62,6 @@ void node_operatortypes(void)
        WM_operatortype_append(NODE_OT_resize);
        WM_operatortype_append(NODE_OT_links_cut);
        WM_operatortype_append(NODE_OT_duplicate);
-       
 }
 
 void node_keymap(struct wmWindowManager *wm)
@@ -82,6 +84,10 @@ void node_keymap(struct wmWindowManager *wm)
        WM_keymap_add_item(keymap, "NODE_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "NODE_OT_select_border", BKEY, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "NODE_OT_delete", XKEY, KM_PRESS, 0, 0);
+
+       WM_keymap_add_item(keymap, "NODE_OT_select_all", AKEY, KM_PRESS, 0, 0);
+       WM_keymap_add_item(keymap, "NODE_OT_select_linked_to", LKEY, KM_PRESS, KM_SHIFT, 0);
+       WM_keymap_add_item(keymap, "NODE_OT_select_linked_from", LKEY, KM_PRESS, 0, 0);
        
        transform_keymap_for_space(wm, keymap, SPACE_NODE);
 }
index 73becc1ebe84af8bb3270958e3944f16218694b7..94e17b56a022118e58bbc39e3932b2d4a56b27e0 100644 (file)
@@ -83,7 +83,7 @@ static void node_mouse_select(SpaceNode *snode, ARegion *ar, short *mval, short
        }
        if(node) {
                if((extend & KM_SHIFT)==0)
-                       node_deselectall(snode, 0);
+                       node_deselectall(snode);
                
                if(extend & KM_SHIFT) {
                        if(node->flag & SELECT)
@@ -291,3 +291,121 @@ void NODE_OT_select_border(wmOperatorType *ot)
 
        RNA_def_enum(ot->srna, "type", prop_select_types, 0, "Type", "");
 }
+
+/* ****** Select/Deselect All ****** */
+
+static int node_select_all_exec(bContext *C, wmOperator *op)
+{
+       SpaceNode *snode = CTX_wm_space_node(C);
+       bNode *first = snode->edittree->nodes.first;
+       bNode *node;
+       int count= 0;
+
+       for(node=first; node; node=node->next)
+               if(node->flag & NODE_SELECT)
+                       count++;
+
+       if(count) {
+               for(node=first; node; node=node->next)
+                       node->flag &= ~NODE_SELECT;
+       }
+       else {
+               for(node=first; node; node=node->next)
+                       node->flag |= NODE_SELECT;
+       }
+       
+       WM_event_add_notifier(C, NC_SCENE|ND_NODES, NULL);
+       return OPERATOR_FINISHED;
+}
+
+void NODE_OT_select_all(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name = "Select/Deselect All";
+       ot->description = "(De)select all nodes.";
+       ot->idname = "NODE_OT_select_all";
+       
+       /* api callbacks */
+       ot->exec = node_select_all_exec;
+       ot->poll = ED_operator_node_active;
+       
+       /* flags */
+       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+/* ****** Select Linked To ****** */
+
+static int node_select_linked_to_exec(bContext *C, wmOperator *op)
+{
+       SpaceNode *snode = CTX_wm_space_node(C);
+       bNodeLink *link;
+       bNode *node;
+       
+       for (node=snode->edittree->nodes.first; node; node=node->next)
+               node->flag &= ~NODE_TEST;
+
+       for (link=snode->edittree->links.first; link; link=link->next)
+               if (link->fromnode->flag & NODE_SELECT)
+                       link->tonode->flag |= NODE_TEST;
+       
+       for (node=snode->edittree->nodes.first; node; node=node->next)
+               if (node->flag & NODE_TEST)
+                       node->flag |= NODE_SELECT;
+       
+       WM_event_add_notifier(C, NC_SCENE|ND_NODES, NULL);
+       return OPERATOR_FINISHED;
+}
+
+void NODE_OT_select_linked_to(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name = "Select Linked To";
+       ot->description = "Select nodes linked to the selected ones.";
+       ot->idname = "NODE_OT_select_linked_to";
+       
+       /* api callbacks */
+       ot->exec = node_select_linked_to_exec;
+       ot->poll = ED_operator_node_active;
+       
+       /* flags */
+       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+/* ****** Select Linked From ****** */
+
+static int node_select_linked_from_exec(bContext *C, wmOperator *op)
+{
+       SpaceNode *snode = CTX_wm_space_node(C);
+       bNodeLink *link;
+       bNode *node;
+       
+       for(node=snode->edittree->nodes.first; node; node=node->next)
+               node->flag &= ~NODE_TEST;
+
+       for(link=snode->edittree->links.first; link; link=link->next)
+               if(link->tonode->flag & NODE_SELECT)
+                       link->fromnode->flag |= NODE_TEST;
+       
+       for(node=snode->edittree->nodes.first; node; node=node->next)
+               if(node->flag & NODE_TEST)
+                       node->flag |= NODE_SELECT;
+       
+       WM_event_add_notifier(C, NC_SCENE|ND_NODES, NULL);
+       return OPERATOR_FINISHED;
+}
+
+void NODE_OT_select_linked_from(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name = "Select Linked From";
+       ot->description = "Select nodes linked from the selected ones.";
+       ot->idname = "NODE_OT_select_linked_from";
+       
+       /* api callbacks */
+       ot->exec = node_select_linked_from_exec;
+       ot->poll = ED_operator_node_active;
+       
+       /* flags */
+       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+