lasso select works in the node editor again, Ctrl+Alt+LMB, Ctrl+Alt+Shif+LMB to deselect
[blender.git] / source / blender / editors / space_node / node_ops.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version. 
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2008 Blender Foundation.
19  * All rights reserved.
20  *
21  * 
22  * Contributor(s): Blender Foundation, Nathan Letwory
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file blender/editors/space_node/node_ops.c
28  *  \ingroup spnode
29  */
30
31
32 #include "DNA_node_types.h"
33
34 #include "BKE_context.h"
35
36 #include "BLI_utildefines.h"
37
38 #include "ED_node.h"  /* own include */
39 #include "ED_screen.h"
40 #include "ED_transform.h"
41
42 #include "RNA_access.h"
43
44 #include "WM_api.h"
45 #include "WM_types.h"
46
47 #include "node_intern.h"  /* own include */
48
49 void node_operatortypes(void)
50 {
51         WM_operatortype_append(NODE_OT_properties);
52         
53         WM_operatortype_append(NODE_OT_select);
54         WM_operatortype_append(NODE_OT_select_all);
55         WM_operatortype_append(NODE_OT_select_linked_to);
56         WM_operatortype_append(NODE_OT_select_linked_from);
57         WM_operatortype_append(NODE_OT_select_border);
58         WM_operatortype_append(NODE_OT_select_lasso);
59         WM_operatortype_append(NODE_OT_select_same_type);
60         WM_operatortype_append(NODE_OT_select_same_type_next);
61         WM_operatortype_append(NODE_OT_select_same_type_prev);
62
63         WM_operatortype_append(NODE_OT_view_all);
64         WM_operatortype_append(NODE_OT_view_selected);
65
66         WM_operatortype_append(NODE_OT_mute_toggle);
67         WM_operatortype_append(NODE_OT_hide_toggle);
68         WM_operatortype_append(NODE_OT_preview_toggle);
69         WM_operatortype_append(NODE_OT_options_toggle);
70         WM_operatortype_append(NODE_OT_hide_socket_toggle);
71         WM_operatortype_append(NODE_OT_show_cyclic_dependencies);
72         WM_operatortype_append(NODE_OT_node_copy_color);
73         
74         WM_operatortype_append(NODE_OT_duplicate);
75         WM_operatortype_append(NODE_OT_delete);
76         WM_operatortype_append(NODE_OT_delete_reconnect);
77         WM_operatortype_append(NODE_OT_resize);
78         
79         WM_operatortype_append(NODE_OT_link);
80         WM_operatortype_append(NODE_OT_link_make);
81         WM_operatortype_append(NODE_OT_links_cut);
82         WM_operatortype_append(NODE_OT_links_detach);
83         WM_operatortype_append(NODE_OT_add_reroute);
84
85         WM_operatortype_append(NODE_OT_group_make);
86         WM_operatortype_append(NODE_OT_group_ungroup);
87         WM_operatortype_append(NODE_OT_group_separate);
88         WM_operatortype_append(NODE_OT_group_edit);
89         WM_operatortype_append(NODE_OT_group_socket_add);
90         WM_operatortype_append(NODE_OT_group_socket_remove);
91         WM_operatortype_append(NODE_OT_group_socket_move_up);
92         WM_operatortype_append(NODE_OT_group_socket_move_down);
93         
94         WM_operatortype_append(NODE_OT_link_viewer);
95         
96         WM_operatortype_append(NODE_OT_read_renderlayers);
97         WM_operatortype_append(NODE_OT_read_fullsamplelayers);
98         WM_operatortype_append(NODE_OT_render_changed);
99         
100         WM_operatortype_append(NODE_OT_backimage_move);
101         WM_operatortype_append(NODE_OT_backimage_zoom);
102         WM_operatortype_append(NODE_OT_backimage_sample);
103         
104         WM_operatortype_append(NODE_OT_add_file);
105         
106         WM_operatortype_append(NODE_OT_new_node_tree);
107         
108         WM_operatortype_append(NODE_OT_output_file_add_socket);
109         WM_operatortype_append(NODE_OT_output_file_remove_active_socket);
110         WM_operatortype_append(NODE_OT_output_file_move_active_socket);
111         
112         WM_operatortype_append(NODE_OT_parent_set);
113         WM_operatortype_append(NODE_OT_parent_clear);
114         WM_operatortype_append(NODE_OT_join);
115         WM_operatortype_append(NODE_OT_attach);
116         WM_operatortype_append(NODE_OT_detach);
117         
118         WM_operatortype_append(NODE_OT_clipboard_copy);
119         WM_operatortype_append(NODE_OT_clipboard_paste);
120 }
121
122 void ED_operatormacros_node(void)
123 {
124         wmOperatorType *ot;
125         wmOperatorTypeMacro *mot;
126         
127         ot = WM_operatortype_append_macro("NODE_OT_select_link_viewer", "Link Viewer",
128                                           "Select node and link it to a viewer node",
129                                           OPTYPE_UNDO);
130         WM_operatortype_macro_define(ot, "NODE_OT_select");
131         WM_operatortype_macro_define(ot, "NODE_OT_link_viewer");
132
133         ot = WM_operatortype_append_macro("NODE_OT_translate_attach", "Move and Attach",
134                                           "Move nodes and attach to frame",
135                                           OPTYPE_UNDO | OPTYPE_REGISTER);
136         mot = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
137         RNA_boolean_set(mot->ptr, "release_confirm", TRUE);
138         WM_operatortype_macro_define(ot, "NODE_OT_attach");
139
140         ot = WM_operatortype_append_macro("NODE_OT_detach_translate_attach", "Detach and Move",
141                                           "Detach nodes, move and attach to frame",
142                                           OPTYPE_UNDO | OPTYPE_REGISTER);
143         WM_operatortype_macro_define(ot, "NODE_OT_detach");
144         mot = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
145         RNA_boolean_set(mot->ptr, "release_confirm", TRUE);
146         WM_operatortype_macro_define(ot, "NODE_OT_attach");
147
148         ot = WM_operatortype_append_macro("NODE_OT_duplicate_move", "Duplicate",
149                                           "Duplicate selected nodes and move them",
150                                           OPTYPE_UNDO | OPTYPE_REGISTER);
151         WM_operatortype_macro_define(ot, "NODE_OT_duplicate");
152         WM_operatortype_macro_define(ot, "NODE_OT_translate_attach");
153
154         /* modified operator call for duplicating with input links */
155         ot = WM_operatortype_append_macro("NODE_OT_duplicate_move_keep_inputs", "Duplicate",
156                                           "Duplicate selected nodes keeping input links and move them",
157                                           OPTYPE_UNDO | OPTYPE_REGISTER);
158         mot = WM_operatortype_macro_define(ot, "NODE_OT_duplicate");
159         RNA_boolean_set(mot->ptr, "keep_inputs", TRUE);
160         WM_operatortype_macro_define(ot, "NODE_OT_translate_attach");
161
162         ot = WM_operatortype_append_macro("NODE_OT_move_detach_links", "Detach", "Move a node to detach links",
163                                           OPTYPE_UNDO | OPTYPE_REGISTER);
164         WM_operatortype_macro_define(ot, "NODE_OT_links_detach");
165         WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
166
167         ot = WM_operatortype_append_macro("NODE_OT_move_detach_links_release", "Detach", "Move a node to detach links",
168                                           OPTYPE_UNDO | OPTYPE_REGISTER);
169         WM_operatortype_macro_define(ot, "NODE_OT_links_detach");
170         mot = WM_operatortype_macro_define(ot, "NODE_OT_translate_attach");
171 }
172
173 /* helper function for repetitive select operator keymap */
174 static void node_select_keymap(wmKeyMap *keymap, int extend)
175 {
176         /* modifier combinations */
177         const int mod_single[] = { 0, KM_CTRL, KM_ALT, KM_CTRL | KM_ALT,
178                                    -1 /* terminator */
179         };
180         const int mod_extend[] = { KM_SHIFT, KM_SHIFT | KM_CTRL,
181                                    KM_SHIFT | KM_ALT, KM_SHIFT | KM_CTRL | KM_ALT,
182                                    -1 /* terminator */
183         };
184         const int *mod = (extend ? mod_extend : mod_single);
185         wmKeyMapItem *kmi;
186         int i;
187         
188         for (i = 0; mod[i] >= 0; ++i) {
189                 kmi = WM_keymap_add_item(keymap, "NODE_OT_select", ACTIONMOUSE, KM_PRESS, mod[i], 0);
190                 RNA_boolean_set(kmi->ptr, "extend", extend);
191                 kmi = WM_keymap_add_item(keymap, "NODE_OT_select", SELECTMOUSE, KM_PRESS, mod[i], 0);
192                 RNA_boolean_set(kmi->ptr, "extend", extend);
193         }
194 }
195
196 void node_keymap(struct wmKeyConfig *keyconf)
197 {
198         wmKeyMap *keymap;
199         wmKeyMapItem *kmi;
200         
201         /* Entire Editor only ----------------- */
202         keymap = WM_keymap_find(keyconf, "Node Generic", SPACE_NODE, 0);
203         
204         WM_keymap_add_item(keymap, "NODE_OT_properties", NKEY, KM_PRESS, 0, 0);
205         
206         /* Main Area only ----------------- */
207         keymap = WM_keymap_find(keyconf, "Node Editor", SPACE_NODE, 0);
208         
209         /* mouse select in nodes used to be both keys, but perhaps this should be reduced? 
210          * NOTE: mouse-clicks on left-mouse will fall through to allow transform-tweak, but also link/resize
211          * NOTE 2: socket select is part of the node select operator, to handle overlapping cases
212          * NOTE 3: select op is registered for various combinations of modifier key, so the specialized
213          *         grab operators (unlink, attach, etc.) can work easily on single nodes.
214          */
215         node_select_keymap(keymap, FALSE);
216         node_select_keymap(keymap, TRUE);
217         
218         kmi = WM_keymap_add_item(keymap, "NODE_OT_select_border", EVT_TWEAK_S, KM_ANY, 0, 0);
219         RNA_boolean_set(kmi->ptr, "tweak", TRUE);
220         
221         kmi = WM_keymap_add_item(keymap, "NODE_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL | KM_ALT, 0);
222         RNA_boolean_set(kmi->ptr, "deselect", FALSE);
223         kmi = WM_keymap_add_item(keymap, "NODE_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL | KM_SHIFT | KM_ALT, 0);
224         RNA_boolean_set(kmi->ptr, "deselect", TRUE);
225
226         /* each of these falls through if not handled... */
227         WM_keymap_add_item(keymap, "NODE_OT_link", LEFTMOUSE, KM_PRESS, 0, 0);
228         kmi = WM_keymap_add_item(keymap, "NODE_OT_link", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
229         RNA_boolean_set(kmi->ptr, "detach", TRUE);
230         WM_keymap_add_item(keymap, "NODE_OT_resize", LEFTMOUSE, KM_PRESS, 0, 0);
231         
232         WM_keymap_add_item(keymap, "NODE_OT_add_reroute", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
233         WM_keymap_add_item(keymap, "NODE_OT_links_cut", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
234         WM_keymap_add_item(keymap, "NODE_OT_select_link_viewer", LEFTMOUSE, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
235         
236         WM_keymap_add_item(keymap, "NODE_OT_backimage_move", MIDDLEMOUSE, KM_PRESS, KM_ALT, 0);
237         kmi = WM_keymap_add_item(keymap, "NODE_OT_backimage_zoom", VKEY, KM_PRESS, 0, 0);
238         RNA_float_set(kmi->ptr, "factor", 0.83333f);
239         kmi = WM_keymap_add_item(keymap, "NODE_OT_backimage_zoom", VKEY, KM_PRESS, KM_ALT, 0);
240         RNA_float_set(kmi->ptr, "factor", 1.2f);
241         WM_keymap_add_item(keymap, "NODE_OT_backimage_sample", ACTIONMOUSE, KM_PRESS, KM_ALT, 0);
242
243         kmi = WM_keymap_add_item(keymap, "NODE_OT_link_make", FKEY, KM_PRESS, 0, 0);
244         RNA_boolean_set(kmi->ptr, "replace", FALSE);
245         kmi = WM_keymap_add_item(keymap, "NODE_OT_link_make", FKEY, KM_PRESS, KM_CTRL, 0);
246         RNA_boolean_set(kmi->ptr, "replace", TRUE);
247
248         WM_keymap_add_menu(keymap, "NODE_MT_add", AKEY, KM_PRESS, KM_SHIFT, 0);
249         WM_keymap_add_item(keymap, "NODE_OT_duplicate_move", DKEY, KM_PRESS, KM_SHIFT, 0);
250         /* modified operator call for duplicating with input links */
251         WM_keymap_add_item(keymap, "NODE_OT_duplicate_move_keep_inputs", DKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
252         
253         WM_keymap_add_item(keymap, "NODE_OT_parent_set", PKEY, KM_PRESS, KM_CTRL, 0);
254         WM_keymap_add_item(keymap, "NODE_OT_parent_clear", PKEY, KM_PRESS, KM_ALT, 0);
255         WM_keymap_add_item(keymap, "NODE_OT_join", JKEY, KM_PRESS, KM_CTRL, 0);
256         
257         WM_keymap_add_item(keymap, "NODE_OT_hide_toggle", HKEY, KM_PRESS, 0, 0);
258         WM_keymap_add_item(keymap, "NODE_OT_mute_toggle", MKEY, KM_PRESS, 0, 0);
259         WM_keymap_add_item(keymap, "NODE_OT_preview_toggle", HKEY, KM_PRESS, KM_SHIFT, 0);
260         WM_keymap_add_item(keymap, "NODE_OT_hide_socket_toggle", HKEY, KM_PRESS, KM_CTRL, 0);
261         
262         WM_keymap_add_item(keymap, "NODE_OT_show_cyclic_dependencies", CKEY, KM_PRESS, 0, 0);
263         
264         WM_keymap_add_item(keymap, "NODE_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
265         WM_keymap_add_item(keymap, "NODE_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
266
267         kmi = WM_keymap_add_item(keymap, "NODE_OT_select_border", BKEY, KM_PRESS, 0, 0);
268         RNA_boolean_set(kmi->ptr, "tweak", FALSE);
269
270         WM_keymap_add_item(keymap, "NODE_OT_delete", XKEY, KM_PRESS, 0, 0);
271         WM_keymap_add_item(keymap, "NODE_OT_delete", DELKEY, KM_PRESS, 0, 0);
272         WM_keymap_add_item(keymap, "NODE_OT_delete_reconnect", XKEY, KM_PRESS, KM_CTRL, 0);
273
274         kmi = WM_keymap_add_item(keymap, "NODE_OT_select_all", AKEY, KM_PRESS, 0, 0);
275         RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE);
276         kmi = WM_keymap_add_item(keymap, "NODE_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0);
277         RNA_enum_set(kmi->ptr, "action", SEL_INVERT);
278
279         WM_keymap_add_item(keymap, "NODE_OT_select_linked_to", LKEY, KM_PRESS, KM_SHIFT, 0);
280         WM_keymap_add_item(keymap, "NODE_OT_select_linked_from", LKEY, KM_PRESS, 0, 0);
281         WM_keymap_add_item(keymap, "NODE_OT_select_same_type", GKEY, KM_PRESS, KM_SHIFT, 0);
282         WM_keymap_add_item(keymap, "NODE_OT_select_same_type_next", RIGHTBRACKETKEY, KM_PRESS, KM_SHIFT, 0);
283         WM_keymap_add_item(keymap, "NODE_OT_select_same_type_prev", LEFTBRACKETKEY, KM_PRESS, KM_SHIFT, 0);
284
285         WM_keymap_add_item(keymap, "NODE_OT_group_make", GKEY, KM_PRESS, KM_CTRL, 0);
286         WM_keymap_add_item(keymap, "NODE_OT_group_ungroup", GKEY, KM_PRESS, KM_ALT, 0);
287         WM_keymap_add_item(keymap, "NODE_OT_group_separate", PKEY, KM_PRESS, 0, 0);
288         WM_keymap_add_item(keymap, "NODE_OT_group_edit", TABKEY, KM_PRESS, 0, 0);
289         
290         WM_keymap_add_item(keymap, "NODE_OT_read_renderlayers", RKEY, KM_PRESS, KM_CTRL, 0);
291         WM_keymap_add_item(keymap, "NODE_OT_read_fullsamplelayers", RKEY, KM_PRESS, KM_SHIFT, 0);
292         WM_keymap_add_item(keymap, "NODE_OT_render_changed", ZKEY, KM_PRESS, 0, 0);
293         
294         WM_keymap_add_item(keymap, "NODE_OT_clipboard_copy", CKEY, KM_PRESS, KM_CTRL, 0);
295         WM_keymap_add_item(keymap, "NODE_OT_clipboard_paste", VKEY, KM_PRESS, KM_CTRL, 0);
296         
297         transform_keymap_for_space(keyconf, keymap, SPACE_NODE);
298 }