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