Rename any instance of scene layer or render layer in code with view layer
[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 "BLI_utildefines.h"
35
36 #include "BKE_context.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         WM_operatortype_append(NODE_OT_toolbar);
53         
54         WM_operatortype_append(NODE_OT_select);
55         WM_operatortype_append(NODE_OT_select_all);
56         WM_operatortype_append(NODE_OT_select_linked_to);
57         WM_operatortype_append(NODE_OT_select_linked_from);
58         WM_operatortype_append(NODE_OT_select_border);
59         WM_operatortype_append(NODE_OT_select_circle);
60         WM_operatortype_append(NODE_OT_select_lasso);
61         WM_operatortype_append(NODE_OT_select_grouped);
62         WM_operatortype_append(NODE_OT_select_same_type_step);
63         
64         WM_operatortype_append(NODE_OT_find_node);
65         
66         WM_operatortype_append(NODE_OT_view_all);
67         WM_operatortype_append(NODE_OT_view_selected);
68
69         WM_operatortype_append(NODE_OT_mute_toggle);
70         WM_operatortype_append(NODE_OT_hide_toggle);
71         WM_operatortype_append(NODE_OT_preview_toggle);
72         WM_operatortype_append(NODE_OT_options_toggle);
73         WM_operatortype_append(NODE_OT_hide_socket_toggle);
74         WM_operatortype_append(NODE_OT_node_copy_color);
75         
76         WM_operatortype_append(NODE_OT_duplicate);
77         WM_operatortype_append(NODE_OT_delete);
78         WM_operatortype_append(NODE_OT_delete_reconnect);
79         WM_operatortype_append(NODE_OT_resize);
80         
81         WM_operatortype_append(NODE_OT_link);
82         WM_operatortype_append(NODE_OT_link_make);
83         WM_operatortype_append(NODE_OT_links_cut);
84         WM_operatortype_append(NODE_OT_links_detach);
85         WM_operatortype_append(NODE_OT_add_reroute);
86
87         WM_operatortype_append(NODE_OT_group_make);
88         WM_operatortype_append(NODE_OT_group_insert);
89         WM_operatortype_append(NODE_OT_group_ungroup);
90         WM_operatortype_append(NODE_OT_group_separate);
91         WM_operatortype_append(NODE_OT_group_edit);
92         
93         WM_operatortype_append(NODE_OT_link_viewer);
94         
95         WM_operatortype_append(NODE_OT_insert_offset);
96         
97         WM_operatortype_append(NODE_OT_read_viewlayers);
98         WM_operatortype_append(NODE_OT_read_fullsamplelayers);
99         WM_operatortype_append(NODE_OT_render_changed);
100         
101         WM_operatortype_append(NODE_OT_backimage_move);
102         WM_operatortype_append(NODE_OT_backimage_zoom);
103         WM_operatortype_append(NODE_OT_backimage_fit);
104         WM_operatortype_append(NODE_OT_backimage_sample);
105         
106         WM_operatortype_append(NODE_OT_add_file);
107         WM_operatortype_append(NODE_OT_add_mask);
108         
109         WM_operatortype_append(NODE_OT_new_node_tree);
110         
111         WM_operatortype_append(NODE_OT_output_file_add_socket);
112         WM_operatortype_append(NODE_OT_output_file_remove_active_socket);
113         WM_operatortype_append(NODE_OT_output_file_move_active_socket);
114         
115         WM_operatortype_append(NODE_OT_parent_set);
116         WM_operatortype_append(NODE_OT_join);
117         WM_operatortype_append(NODE_OT_attach);
118         WM_operatortype_append(NODE_OT_detach);
119         
120         WM_operatortype_append(NODE_OT_clipboard_copy);
121         WM_operatortype_append(NODE_OT_clipboard_paste);
122         
123         WM_operatortype_append(NODE_OT_shader_script_update);
124
125         WM_operatortype_append(NODE_OT_viewer_border);
126         WM_operatortype_append(NODE_OT_clear_viewer_border);
127
128         WM_operatortype_append(NODE_OT_switch_view_update);
129
130         WM_operatortype_append(NODE_OT_tree_socket_add);
131         WM_operatortype_append(NODE_OT_tree_socket_remove);
132         WM_operatortype_append(NODE_OT_tree_socket_move);
133 }
134
135 void ED_operatormacros_node(void)
136 {
137         wmOperatorType *ot;
138         wmOperatorTypeMacro *mot;
139         
140         ot = WM_operatortype_append_macro("NODE_OT_select_link_viewer", "Link Viewer",
141                                           "Select node and link it to a viewer node",
142                                           OPTYPE_UNDO);
143         WM_operatortype_macro_define(ot, "NODE_OT_select");
144         WM_operatortype_macro_define(ot, "NODE_OT_link_viewer");
145
146         ot = WM_operatortype_append_macro("NODE_OT_translate_attach", "Move and Attach",
147                                           "Move nodes and attach to frame",
148                                           OPTYPE_UNDO | OPTYPE_REGISTER);
149         mot = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
150         RNA_boolean_set(mot->ptr, "release_confirm", true);
151         WM_operatortype_macro_define(ot, "NODE_OT_attach");
152         WM_operatortype_macro_define(ot, "NODE_OT_insert_offset");
153         
154         /* NODE_OT_translate_attach with remove_on_canel set to true */
155         ot = WM_operatortype_append_macro("NODE_OT_translate_attach_remove_on_cancel", "Move and Attach",
156                                           "Move nodes and attach to frame",
157                                           OPTYPE_UNDO | OPTYPE_REGISTER);
158         mot = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
159         RNA_boolean_set(mot->ptr, "release_confirm", true);
160         RNA_boolean_set(mot->ptr, "remove_on_cancel", true);
161         WM_operatortype_macro_define(ot, "NODE_OT_attach");
162         WM_operatortype_macro_define(ot, "NODE_OT_insert_offset");
163
164         /* Note: Currently not in a default keymap or menu due to messy keymaps
165          * and tricky invoke functionality.
166          * Kept around in case users want to make own shortcuts.
167          */
168         ot = WM_operatortype_append_macro("NODE_OT_detach_translate_attach", "Detach and Move",
169                                           "Detach nodes, move and attach to frame",
170                                           OPTYPE_UNDO | OPTYPE_REGISTER);
171         WM_operatortype_macro_define(ot, "NODE_OT_detach");
172         mot = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
173         RNA_boolean_set(mot->ptr, "release_confirm", true);
174         WM_operatortype_macro_define(ot, "NODE_OT_attach");
175
176         ot = WM_operatortype_append_macro("NODE_OT_duplicate_move", "Duplicate",
177                                           "Duplicate selected nodes and move them",
178                                           OPTYPE_UNDO | OPTYPE_REGISTER);
179         WM_operatortype_macro_define(ot, "NODE_OT_duplicate");
180         WM_operatortype_macro_define(ot, "NODE_OT_translate_attach");
181
182         /* modified operator call for duplicating with input links */
183         ot = WM_operatortype_append_macro("NODE_OT_duplicate_move_keep_inputs", "Duplicate",
184                                           "Duplicate selected nodes keeping input links and move them",
185                                           OPTYPE_UNDO | OPTYPE_REGISTER);
186         mot = WM_operatortype_macro_define(ot, "NODE_OT_duplicate");
187         RNA_boolean_set(mot->ptr, "keep_inputs", true);
188         WM_operatortype_macro_define(ot, "NODE_OT_translate_attach");
189
190         ot = WM_operatortype_append_macro("NODE_OT_move_detach_links", "Detach", "Move a node to detach links",
191                                           OPTYPE_UNDO | OPTYPE_REGISTER);
192         WM_operatortype_macro_define(ot, "NODE_OT_links_detach");
193         WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
194         WM_operatortype_macro_define(ot, "NODE_OT_insert_offset");
195
196         ot = WM_operatortype_append_macro("NODE_OT_move_detach_links_release", "Detach", "Move a node to detach links",
197                                           OPTYPE_UNDO | OPTYPE_REGISTER);
198         WM_operatortype_macro_define(ot, "NODE_OT_links_detach");
199         WM_operatortype_macro_define(ot, "NODE_OT_translate_attach");
200 }
201
202 /* helper function for repetitive select operator keymap */
203 static void node_select_keymap(wmKeyMap *keymap, int extend)
204 {
205         /* modifier combinations */
206         const int mod_single[] = { 0, KM_CTRL, KM_ALT, KM_CTRL | KM_ALT,
207                                    -1 /* terminator */
208         };
209         const int mod_extend[] = { KM_SHIFT, KM_SHIFT | KM_CTRL,
210                                    KM_SHIFT | KM_ALT, KM_SHIFT | KM_CTRL | KM_ALT,
211                                    -1 /* terminator */
212         };
213         const int *mod = (extend ? mod_extend : mod_single);
214         wmKeyMapItem *kmi;
215         int i;
216         
217         for (i = 0; mod[i] >= 0; ++i) {
218                 kmi = WM_keymap_add_item(keymap, "NODE_OT_select", ACTIONMOUSE, KM_PRESS, mod[i], 0);
219                 RNA_boolean_set(kmi->ptr, "extend", extend);
220                 kmi = WM_keymap_add_item(keymap, "NODE_OT_select", SELECTMOUSE, KM_PRESS, mod[i], 0);
221                 RNA_boolean_set(kmi->ptr, "extend", extend);
222         }
223 }
224
225 void node_keymap(struct wmKeyConfig *keyconf)
226 {
227         wmKeyMap *keymap;
228         wmKeyMapItem *kmi;
229         
230         /* Entire Editor only ----------------- */
231         keymap = WM_keymap_find(keyconf, "Node Generic", SPACE_NODE, 0);
232         
233         WM_keymap_add_item(keymap, "NODE_OT_properties", NKEY, KM_PRESS, 0, 0);
234         WM_keymap_add_item(keymap, "NODE_OT_toolbar", TKEY, KM_PRESS, 0, 0);
235         
236         /* Main Region only ----------------- */
237         keymap = WM_keymap_find(keyconf, "Node Editor", SPACE_NODE, 0);
238         
239         /* mouse select in nodes used to be both keys, but perhaps this should be reduced? 
240          * NOTE: mouse-clicks on left-mouse will fall through to allow transform-tweak, but also link/resize
241          * NOTE 2: socket select is part of the node select operator, to handle overlapping cases
242          * NOTE 3: select op is registered for various combinations of modifier key, so the specialized
243          *         grab operators (unlink, attach, etc.) can work easily on single nodes.
244          */
245         node_select_keymap(keymap, false);
246         node_select_keymap(keymap, true);
247         
248         kmi = WM_keymap_add_item(keymap, "NODE_OT_select_border", EVT_TWEAK_S, KM_ANY, 0, 0);
249         RNA_boolean_set(kmi->ptr, "tweak", true);
250         
251         kmi = WM_keymap_add_item(keymap, "NODE_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL | KM_ALT, 0);
252         RNA_boolean_set(kmi->ptr, "deselect", false);
253         kmi = WM_keymap_add_item(keymap, "NODE_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL | KM_SHIFT | KM_ALT, 0);
254         RNA_boolean_set(kmi->ptr, "deselect", true);
255
256         WM_keymap_add_item(keymap, "NODE_OT_select_circle", CKEY, KM_PRESS, 0, 0);
257
258         /* each of these falls through if not handled... */
259         kmi = WM_keymap_add_item(keymap, "NODE_OT_link", LEFTMOUSE, KM_PRESS, 0, 0);
260         RNA_boolean_set(kmi->ptr, "detach", false);
261         kmi = WM_keymap_add_item(keymap, "NODE_OT_link", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
262         RNA_boolean_set(kmi->ptr, "detach", true);
263         
264         WM_keymap_add_item(keymap, "NODE_OT_resize", LEFTMOUSE, KM_PRESS, 0, 0);
265         
266         WM_keymap_add_item(keymap, "NODE_OT_add_reroute", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
267         WM_keymap_add_item(keymap, "NODE_OT_links_cut", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
268         WM_keymap_add_item(keymap, "NODE_OT_select_link_viewer", LEFTMOUSE, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
269         
270         WM_keymap_add_item(keymap, "NODE_OT_backimage_move", MIDDLEMOUSE, KM_PRESS, KM_ALT, 0);
271         kmi = WM_keymap_add_item(keymap, "NODE_OT_backimage_zoom", VKEY, KM_PRESS, 0, 0);
272         RNA_float_set(kmi->ptr, "factor", 0.83333f);
273         kmi = WM_keymap_add_item(keymap, "NODE_OT_backimage_zoom", VKEY, KM_PRESS, KM_ALT, 0);
274         RNA_float_set(kmi->ptr, "factor", 1.2f);
275         WM_keymap_add_item(keymap, "NODE_OT_backimage_fit", HOMEKEY, KM_PRESS, KM_ALT, 0);
276         WM_keymap_add_item(keymap, "NODE_OT_backimage_sample", ACTIONMOUSE, KM_PRESS, KM_ALT, 0);
277
278         kmi = WM_keymap_add_item(keymap, "NODE_OT_link_make", FKEY, KM_PRESS, 0, 0);
279         RNA_boolean_set(kmi->ptr, "replace", false);
280         kmi = WM_keymap_add_item(keymap, "NODE_OT_link_make", FKEY, KM_PRESS, KM_SHIFT, 0);
281         RNA_boolean_set(kmi->ptr, "replace", true);
282
283         WM_keymap_add_menu(keymap, "NODE_MT_add", AKEY, KM_PRESS, KM_SHIFT, 0);
284         WM_keymap_add_item(keymap, "NODE_OT_duplicate_move", DKEY, KM_PRESS, KM_SHIFT, 0);
285         /* modified operator call for duplicating with input links */
286         WM_keymap_add_item(keymap, "NODE_OT_duplicate_move_keep_inputs", DKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
287         
288         WM_keymap_add_item(keymap, "NODE_OT_parent_set", PKEY, KM_PRESS, KM_CTRL, 0);
289         WM_keymap_add_item(keymap, "NODE_OT_detach", PKEY, KM_PRESS, KM_ALT, 0);
290         WM_keymap_add_item(keymap, "NODE_OT_join", JKEY, KM_PRESS, KM_CTRL, 0);
291         
292         WM_keymap_add_item(keymap, "NODE_OT_hide_toggle", HKEY, KM_PRESS, 0, 0);
293         WM_keymap_add_item(keymap, "NODE_OT_mute_toggle", MKEY, KM_PRESS, 0, 0);
294         WM_keymap_add_item(keymap, "NODE_OT_preview_toggle", HKEY, KM_PRESS, KM_SHIFT, 0);
295         WM_keymap_add_item(keymap, "NODE_OT_hide_socket_toggle", HKEY, KM_PRESS, KM_CTRL, 0);
296         
297         WM_keymap_add_item(keymap, "NODE_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
298 #ifdef WITH_INPUT_NDOF
299         WM_keymap_add_item(keymap, "NODE_OT_view_all", NDOF_BUTTON_FIT, KM_PRESS, 0, 0);
300 #endif
301         WM_keymap_add_item(keymap, "NODE_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
302
303         kmi = WM_keymap_add_item(keymap, "NODE_OT_select_border", BKEY, KM_PRESS, 0, 0);
304         RNA_boolean_set(kmi->ptr, "tweak", false);
305
306         WM_keymap_add_item(keymap, "NODE_OT_delete", XKEY, KM_PRESS, 0, 0);
307         WM_keymap_add_item(keymap, "NODE_OT_delete", DELKEY, KM_PRESS, 0, 0);
308         WM_keymap_add_item(keymap, "NODE_OT_delete_reconnect", XKEY, KM_PRESS, KM_CTRL, 0);
309
310         kmi = WM_keymap_add_item(keymap, "NODE_OT_select_all", AKEY, KM_PRESS, 0, 0);
311         RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE);
312         kmi = WM_keymap_add_item(keymap, "NODE_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0);
313         RNA_enum_set(kmi->ptr, "action", SEL_INVERT);
314
315         WM_keymap_add_item(keymap, "NODE_OT_select_linked_to", LKEY, KM_PRESS, KM_SHIFT, 0);
316         WM_keymap_add_item(keymap, "NODE_OT_select_linked_from", LKEY, KM_PRESS, 0, 0);
317         kmi = WM_keymap_add_item(keymap, "NODE_OT_select_grouped", GKEY, KM_PRESS, KM_SHIFT, 0);
318         RNA_boolean_set(kmi->ptr, "extend", false);
319         kmi = WM_keymap_add_item(keymap, "NODE_OT_select_grouped", GKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
320         RNA_boolean_set(kmi->ptr, "extend", true);
321
322         kmi = WM_keymap_add_item(keymap, "NODE_OT_select_same_type_step", RIGHTBRACKETKEY, KM_PRESS, KM_SHIFT, 0);
323         RNA_boolean_set(kmi->ptr, "prev", false);
324         kmi = WM_keymap_add_item(keymap, "NODE_OT_select_same_type_step", LEFTBRACKETKEY, KM_PRESS, KM_SHIFT, 0);
325         RNA_boolean_set(kmi->ptr, "prev", true);
326         
327         WM_keymap_add_item(keymap, "NODE_OT_find_node", FKEY, KM_PRESS, KM_CTRL, 0);
328         
329         /* node group operators */
330         WM_keymap_add_item(keymap, "NODE_OT_group_make", GKEY, KM_PRESS, KM_CTRL, 0);
331         WM_keymap_add_item(keymap, "NODE_OT_group_ungroup", GKEY, KM_PRESS, KM_ALT, 0);
332         WM_keymap_add_item(keymap, "NODE_OT_group_separate", PKEY, KM_PRESS, 0, 0);
333         kmi = WM_keymap_add_item(keymap, "NODE_OT_group_edit", TABKEY, KM_PRESS, 0, 0);
334         RNA_boolean_set(kmi->ptr, "exit", false);
335         kmi = WM_keymap_add_item(keymap, "NODE_OT_group_edit", TABKEY, KM_PRESS, KM_CTRL, 0);
336         RNA_boolean_set(kmi->ptr, "exit", true);
337
338         WM_keymap_add_item(keymap, "NODE_OT_read_viewlayers", RKEY, KM_PRESS, KM_CTRL, 0);
339         WM_keymap_add_item(keymap, "NODE_OT_read_fullsamplelayers", RKEY, KM_PRESS, KM_SHIFT, 0);
340         WM_keymap_add_item(keymap, "NODE_OT_render_changed", ZKEY, KM_PRESS, 0, 0);
341         
342         WM_keymap_add_item(keymap, "NODE_OT_clipboard_copy", CKEY, KM_PRESS, KM_CTRL, 0);
343         WM_keymap_add_item(keymap, "NODE_OT_clipboard_paste", VKEY, KM_PRESS, KM_CTRL, 0);
344 #ifdef __APPLE__
345         WM_keymap_add_item(keymap, "NODE_OT_clipboard_copy", CKEY, KM_PRESS, KM_OSKEY, 0);
346         WM_keymap_add_item(keymap, "NODE_OT_clipboard_paste", VKEY, KM_PRESS, KM_OSKEY, 0);
347 #endif
348         WM_keymap_add_item(keymap, "NODE_OT_viewer_border", BKEY, KM_PRESS, KM_CTRL, 0);
349         WM_keymap_add_item(keymap, "NODE_OT_clear_viewer_border", BKEY, KM_PRESS, KM_ALT | KM_CTRL, 0);
350
351         transform_keymap_for_space(keyconf, keymap, SPACE_NODE);
352 }