493f4747387b44b97b5c435da72628dc6e523e39
[blender-staging.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 #include "DNA_scene_types.h"
34
35 #include "BKE_context.h"
36
37 #include "BLI_utildefines.h"
38
39 #include "ED_node.h"
40 #include "ED_screen.h"
41 #include "ED_transform.h"
42
43 #include "RNA_access.h"
44
45 #include "WM_api.h"
46 #include "WM_types.h"
47
48 #include "node_intern.h"
49
50 void node_operatortypes(void)
51 {
52         WM_operatortype_append(NODE_OT_properties);
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_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
65         WM_operatortype_append(NODE_OT_mute_toggle);
66         WM_operatortype_append(NODE_OT_hide_toggle);
67         WM_operatortype_append(NODE_OT_preview_toggle);
68         WM_operatortype_append(NODE_OT_options_toggle);
69         WM_operatortype_append(NODE_OT_hide_socket_toggle);
70         WM_operatortype_append(NODE_OT_show_cyclic_dependencies);
71         
72         WM_operatortype_append(NODE_OT_duplicate);
73         WM_operatortype_append(NODE_OT_delete);
74         WM_operatortype_append(NODE_OT_delete_reconnect);
75         WM_operatortype_append(NODE_OT_resize);
76         
77         WM_operatortype_append(NODE_OT_link);
78         WM_operatortype_append(NODE_OT_link_make);
79         WM_operatortype_append(NODE_OT_links_cut);
80
81         WM_operatortype_append(NODE_OT_group_make);
82         WM_operatortype_append(NODE_OT_group_ungroup);
83         WM_operatortype_append(NODE_OT_group_edit);
84         WM_operatortype_append(NODE_OT_group_socket_add);
85         WM_operatortype_append(NODE_OT_group_socket_remove);
86         WM_operatortype_append(NODE_OT_group_socket_move_up);
87         WM_operatortype_append(NODE_OT_group_socket_move_down);
88         
89         WM_operatortype_append(NODE_OT_link_viewer);
90         
91         WM_operatortype_append(NODE_OT_read_renderlayers);
92         WM_operatortype_append(NODE_OT_read_fullsamplelayers);
93         WM_operatortype_append(NODE_OT_render_changed);
94         
95         WM_operatortype_append(NODE_OT_backimage_move);
96         WM_operatortype_append(NODE_OT_backimage_zoom);
97         WM_operatortype_append(NODE_OT_backimage_sample);
98         
99         WM_operatortype_append(NODE_OT_add_file);
100         
101         WM_operatortype_append(NODE_OT_new_node_tree);
102         
103         WM_operatortype_append(NODE_OT_output_multi_file_add_socket);
104         WM_operatortype_append(NODE_OT_output_multi_file_remove_active_socket);
105 }
106
107 void ED_operatormacros_node(void)
108 {
109         wmOperatorType *ot;
110         wmOperatorTypeMacro *mot;
111         
112         ot= WM_operatortype_append_macro("NODE_OT_duplicate_move", "Duplicate", OPTYPE_UNDO|OPTYPE_REGISTER);
113         ot->description = "Duplicate selected nodes and move them";
114         WM_operatortype_macro_define(ot, "NODE_OT_duplicate");
115         WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
116
117         /* modified operator call for duplicating with input links */
118         ot= WM_operatortype_append_macro("NODE_OT_duplicate_move_keep_inputs", "Duplicate", OPTYPE_UNDO|OPTYPE_REGISTER);
119         ot->description = "Duplicate selected nodes keeping input links and move them";
120
121         mot = WM_operatortype_macro_define(ot, "NODE_OT_duplicate");
122         RNA_boolean_set(mot->ptr, "keep_inputs", TRUE);
123
124         WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
125
126         ot= WM_operatortype_append_macro("NODE_OT_select_link_viewer", "Link Viewer", OPTYPE_UNDO);
127         ot->description = "Select node and link it to a viewer node";
128         WM_operatortype_macro_define(ot, "NODE_OT_select");
129         WM_operatortype_macro_define(ot, "NODE_OT_link_viewer");
130 }
131
132 void node_keymap(struct wmKeyConfig *keyconf)
133 {
134         wmKeyMap *keymap;
135         wmKeyMapItem *kmi;
136         
137         /* Entire Editor only ----------------- */
138         keymap= WM_keymap_find(keyconf, "Node Generic", SPACE_NODE, 0);
139         
140         WM_keymap_add_item(keymap, "NODE_OT_properties", NKEY, KM_PRESS, 0, 0);
141         
142         /* Main Area only ----------------- */
143         keymap= WM_keymap_find(keyconf, "Node Editor", SPACE_NODE, 0);
144         
145         /* mouse select in nodes used to be both keys, but perhaps this should be reduced? 
146          * NOTE: mouse-clicks on left-mouse will fall through to allow transform-tweak, but also link/resize
147          */
148         kmi = WM_keymap_add_item(keymap, "NODE_OT_select", ACTIONMOUSE, KM_PRESS, 0, 0);
149                 RNA_boolean_set(kmi->ptr, "extend", FALSE);
150         kmi = WM_keymap_add_item(keymap, "NODE_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
151                 RNA_boolean_set(kmi->ptr, "extend", FALSE);
152         kmi = WM_keymap_add_item(keymap, "NODE_OT_select", ACTIONMOUSE, KM_PRESS, KM_SHIFT, 0);
153                 RNA_boolean_set(kmi->ptr, "extend", TRUE);
154         kmi = WM_keymap_add_item(keymap, "NODE_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
155                 RNA_boolean_set(kmi->ptr, "extend", TRUE);
156         kmi = WM_keymap_add_item(keymap, "NODE_OT_select_border", EVT_TWEAK_S, KM_ANY, 0, 0);
157                 RNA_boolean_set(kmi->ptr, "tweak", TRUE);
158         
159         /* each of these falls through if not handled... */
160         WM_keymap_add_item(keymap, "NODE_OT_link", LEFTMOUSE, KM_PRESS, 0, 0);
161         WM_keymap_add_item(keymap, "NODE_OT_resize", LEFTMOUSE, KM_PRESS, 0, 0);
162         
163         WM_keymap_add_item(keymap, "NODE_OT_links_cut", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
164         WM_keymap_add_item(keymap, "NODE_OT_select_link_viewer", LEFTMOUSE, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
165         
166         WM_keymap_add_item(keymap, "NODE_OT_backimage_move", MIDDLEMOUSE, KM_PRESS, KM_ALT, 0);
167         kmi= WM_keymap_add_item(keymap, "NODE_OT_backimage_zoom", VKEY, KM_PRESS, 0, 0);
168                 RNA_float_set(kmi->ptr, "factor", 0.83333f);
169         kmi= WM_keymap_add_item(keymap, "NODE_OT_backimage_zoom", VKEY, KM_PRESS, KM_ALT, 0);
170                 RNA_float_set(kmi->ptr, "factor", 1.2f);
171         WM_keymap_add_item(keymap, "NODE_OT_backimage_sample", ACTIONMOUSE, KM_PRESS, KM_ALT, 0);
172
173         kmi = WM_keymap_add_item(keymap, "NODE_OT_link_make", FKEY, KM_PRESS, 0, 0);
174         RNA_boolean_set(kmi->ptr, "replace", FALSE);
175         kmi = WM_keymap_add_item(keymap, "NODE_OT_link_make", FKEY, KM_PRESS, KM_CTRL, 0);
176         RNA_boolean_set(kmi->ptr, "replace", TRUE);
177
178         WM_keymap_add_menu(keymap, "NODE_MT_add", AKEY, KM_PRESS, KM_SHIFT, 0);
179         WM_keymap_add_item(keymap, "NODE_OT_duplicate_move", DKEY, KM_PRESS, KM_SHIFT, 0);
180         /* modified operator call for duplicating with input links */
181         WM_keymap_add_item(keymap, "NODE_OT_duplicate_move_keep_inputs", DKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
182         
183         WM_keymap_add_item(keymap, "NODE_OT_hide_toggle", HKEY, KM_PRESS, 0, 0);
184         WM_keymap_add_item(keymap, "NODE_OT_mute_toggle", MKEY, KM_PRESS, 0, 0);
185         WM_keymap_add_item(keymap, "NODE_OT_preview_toggle", HKEY, KM_PRESS, KM_SHIFT, 0);
186         WM_keymap_add_item(keymap, "NODE_OT_hide_socket_toggle", HKEY, KM_PRESS, KM_CTRL, 0);
187         
188         WM_keymap_add_item(keymap, "NODE_OT_show_cyclic_dependencies", CKEY, KM_PRESS, 0, 0);
189         
190         WM_keymap_add_item(keymap, "NODE_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
191
192         kmi = WM_keymap_add_item(keymap, "NODE_OT_select_border", BKEY, KM_PRESS, 0, 0);
193         RNA_boolean_set(kmi->ptr, "tweak", FALSE);
194
195         WM_keymap_add_item(keymap, "NODE_OT_delete", XKEY, KM_PRESS, 0, 0);
196         WM_keymap_add_item(keymap, "NODE_OT_delete", DELKEY, KM_PRESS, 0, 0);
197         WM_keymap_add_item(keymap, "NODE_OT_delete_reconnect", XKEY, KM_PRESS, KM_CTRL, 0);
198
199         WM_keymap_add_item(keymap, "NODE_OT_select_all", AKEY, KM_PRESS, 0, 0);
200         WM_keymap_add_item(keymap, "NODE_OT_select_linked_to", LKEY, KM_PRESS, KM_SHIFT, 0);
201         WM_keymap_add_item(keymap, "NODE_OT_select_linked_from", LKEY, KM_PRESS, 0, 0);
202         WM_keymap_add_item(keymap, "NODE_OT_select_same_type", GKEY, KM_PRESS, KM_SHIFT, 0);
203         WM_keymap_add_item(keymap, "NODE_OT_select_same_type_next", RIGHTBRACKETKEY, KM_PRESS, KM_SHIFT, 0);
204         WM_keymap_add_item(keymap, "NODE_OT_select_same_type_prev", LEFTBRACKETKEY, KM_PRESS, KM_SHIFT, 0);
205
206         WM_keymap_add_item(keymap, "NODE_OT_group_make", GKEY, KM_PRESS, KM_CTRL, 0);
207         WM_keymap_add_item(keymap, "NODE_OT_group_ungroup", GKEY, KM_PRESS, KM_ALT, 0);
208         WM_keymap_add_item(keymap, "NODE_OT_group_edit", TABKEY, KM_PRESS, 0, 0);
209         
210         WM_keymap_add_item(keymap, "NODE_OT_read_renderlayers", RKEY, KM_PRESS, KM_CTRL, 0);
211         WM_keymap_add_item(keymap, "NODE_OT_read_fullsamplelayers", RKEY, KM_PRESS, KM_SHIFT, 0);
212         WM_keymap_add_item(keymap, "NODE_OT_render_changed", ZKEY, KM_PRESS, 0, 0);
213         
214         transform_keymap_for_space(keyconf, keymap, SPACE_NODE);
215 }