Bugfix #26317
[blender.git] / source / blender / editors / space_node / node_ops.c
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2008 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Blender Foundation, Nathan Letwory
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 /** \file blender/editors/space_node/node_ops.c
30  *  \ingroup spnode
31  */
32
33
34 #include "DNA_node_types.h"
35 #include "DNA_scene_types.h"
36
37 #include "BKE_context.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         WM_operatortype_append(NODE_OT_visibility_toggle);
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_hide_socket_toggle);
69         WM_operatortype_append(NODE_OT_show_cyclic_dependencies);
70         
71         WM_operatortype_append(NODE_OT_duplicate);
72         WM_operatortype_append(NODE_OT_delete);
73         WM_operatortype_append(NODE_OT_resize);
74         
75         WM_operatortype_append(NODE_OT_link);
76         WM_operatortype_append(NODE_OT_link_make);
77         WM_operatortype_append(NODE_OT_links_cut);
78         
79         WM_operatortype_append(NODE_OT_group_make);
80         WM_operatortype_append(NODE_OT_group_ungroup);
81         WM_operatortype_append(NODE_OT_group_edit);
82         WM_operatortype_append(NODE_OT_group_socket_add);
83         WM_operatortype_append(NODE_OT_group_socket_remove);
84         WM_operatortype_append(NODE_OT_group_socket_move_up);
85         WM_operatortype_append(NODE_OT_group_socket_move_down);
86         
87         WM_operatortype_append(NODE_OT_link_viewer);
88         
89         WM_operatortype_append(NODE_OT_read_renderlayers);
90         WM_operatortype_append(NODE_OT_read_fullsamplelayers);
91         WM_operatortype_append(NODE_OT_render_changed);
92         
93         WM_operatortype_append(NODE_OT_backimage_move);
94         WM_operatortype_append(NODE_OT_backimage_zoom);
95         WM_operatortype_append(NODE_OT_backimage_sample);
96         
97         WM_operatortype_append(NODE_OT_add_file);
98 }
99
100 void ED_operatormacros_node(void)
101 {
102         wmOperatorType *ot;
103         
104         ot= WM_operatortype_append_macro("NODE_OT_duplicate_move", "Duplicate", OPTYPE_UNDO|OPTYPE_REGISTER);
105         WM_operatortype_macro_define(ot, "NODE_OT_duplicate");
106         WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
107
108         ot= WM_operatortype_append_macro("NODE_OT_select_link_viewer", "Link Viewer", OPTYPE_UNDO);
109         WM_operatortype_macro_define(ot, "NODE_OT_select");
110         WM_operatortype_macro_define(ot, "NODE_OT_link_viewer");
111         
112 }
113
114 void node_keymap(struct wmKeyConfig *keyconf)
115 {
116         wmKeyMap *keymap;
117         wmKeyMapItem *kmi;
118         
119         /* Entire Editor only ----------------- */
120         keymap= WM_keymap_find(keyconf, "Node Generic", SPACE_NODE, 0);
121         
122         WM_keymap_add_item(keymap, "NODE_OT_properties", NKEY, KM_PRESS, 0, 0);
123         
124         /* Main Area only ----------------- */
125         keymap= WM_keymap_find(keyconf, "Node Editor", SPACE_NODE, 0);
126         
127         /* mouse select in nodes used to be both keys, but perhaps this should be reduced? 
128          * NOTE: mouse-clicks on left-mouse will fall through to allow transform-tweak, but also link/resize
129          */
130         WM_keymap_add_item(keymap, "NODE_OT_select", ACTIONMOUSE, KM_PRESS, 0, 0);
131         WM_keymap_add_item(keymap, "NODE_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
132         kmi= WM_keymap_add_item(keymap, "NODE_OT_select", ACTIONMOUSE, KM_PRESS, KM_SHIFT, 0);
133                 RNA_boolean_set(kmi->ptr, "extend", 1);
134         kmi= WM_keymap_add_item(keymap, "NODE_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
135                 RNA_boolean_set(kmi->ptr, "extend", 1);
136         RNA_boolean_set(WM_keymap_add_item(keymap, "NODE_OT_select_border", EVT_TWEAK_S, KM_ANY, 0, 0)->ptr, "tweak", 1);
137         
138         /* each of these falls through if not handled... */
139         WM_keymap_add_item(keymap, "NODE_OT_link", LEFTMOUSE, KM_PRESS, 0, 0);
140         WM_keymap_add_item(keymap, "NODE_OT_resize", LEFTMOUSE, KM_PRESS, 0, 0);
141         WM_keymap_add_item(keymap, "NODE_OT_visibility_toggle", LEFTMOUSE, KM_PRESS, 0, 0);
142         
143         WM_keymap_add_item(keymap, "NODE_OT_links_cut", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
144         WM_keymap_add_item(keymap, "NODE_OT_select_link_viewer", LEFTMOUSE, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
145         
146         WM_keymap_add_item(keymap, "NODE_OT_backimage_move", MIDDLEMOUSE, KM_PRESS, KM_ALT, 0);
147         kmi= WM_keymap_add_item(keymap, "NODE_OT_backimage_zoom", VKEY, KM_PRESS, 0, 0);
148                 RNA_float_set(kmi->ptr, "factor", 0.83333f);
149         kmi= WM_keymap_add_item(keymap, "NODE_OT_backimage_zoom", VKEY, KM_PRESS, KM_ALT, 0);
150                 RNA_float_set(kmi->ptr, "factor", 1.2f);
151         WM_keymap_add_item(keymap, "NODE_OT_backimage_sample", ACTIONMOUSE, KM_PRESS, KM_ALT, 0);
152         
153         WM_keymap_add_item(keymap, "NODE_OT_link_make", FKEY, KM_PRESS, 0, 0);
154         RNA_boolean_set(WM_keymap_add_item(keymap, "NODE_OT_link_make", FKEY, KM_PRESS, KM_CTRL, 0)->ptr, "replace", 1);
155         
156         WM_keymap_add_menu(keymap, "NODE_MT_add", AKEY, KM_PRESS, KM_SHIFT, 0);
157         WM_keymap_add_item(keymap, "NODE_OT_duplicate_move", DKEY, KM_PRESS, KM_SHIFT, 0);
158         
159         WM_keymap_add_item(keymap, "NODE_OT_hide_toggle", HKEY, KM_PRESS, 0, 0);
160         WM_keymap_add_item(keymap, "NODE_OT_mute_toggle", MKEY, KM_PRESS, 0, 0);
161         WM_keymap_add_item(keymap, "NODE_OT_preview_toggle", HKEY, KM_PRESS, KM_SHIFT, 0);
162         WM_keymap_add_item(keymap, "NODE_OT_hide_socket_toggle", HKEY, KM_PRESS, KM_CTRL, 0);
163         
164         WM_keymap_add_item(keymap, "NODE_OT_show_cyclic_dependencies", CKEY, KM_PRESS, 0, 0);
165         
166         WM_keymap_add_item(keymap, "NODE_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
167         WM_keymap_add_item(keymap, "NODE_OT_select_border", BKEY, KM_PRESS, 0, 0);
168         WM_keymap_add_item(keymap, "NODE_OT_delete", XKEY, KM_PRESS, 0, 0);
169         WM_keymap_add_item(keymap, "NODE_OT_delete", DELKEY, KM_PRESS, 0, 0);
170
171         WM_keymap_add_item(keymap, "NODE_OT_select_all", AKEY, KM_PRESS, 0, 0);
172         WM_keymap_add_item(keymap, "NODE_OT_select_linked_to", LKEY, KM_PRESS, KM_SHIFT, 0);
173         WM_keymap_add_item(keymap, "NODE_OT_select_linked_from", LKEY, KM_PRESS, 0, 0);
174         WM_keymap_add_item(keymap, "NODE_OT_select_same_type", GKEY, KM_PRESS, KM_SHIFT, 0);
175         WM_keymap_add_item(keymap, "NODE_OT_select_same_type_next", RIGHTBRACKETKEY, KM_PRESS, KM_SHIFT, 0);
176         WM_keymap_add_item(keymap, "NODE_OT_select_same_type_prev", LEFTBRACKETKEY, KM_PRESS, KM_SHIFT, 0);
177
178         WM_keymap_add_item(keymap, "NODE_OT_group_make", GKEY, KM_PRESS, KM_CTRL, 0);
179         WM_keymap_add_item(keymap, "NODE_OT_group_ungroup", GKEY, KM_PRESS, KM_ALT, 0);
180         WM_keymap_add_item(keymap, "NODE_OT_group_edit", TABKEY, KM_PRESS, 0, 0);
181         
182         WM_keymap_add_item(keymap, "NODE_OT_read_renderlayers", RKEY, KM_PRESS, KM_CTRL, 0);
183         WM_keymap_add_item(keymap, "NODE_OT_read_fullsamplelayers", RKEY, KM_PRESS, KM_SHIFT, 0);
184         WM_keymap_add_item(keymap, "NODE_OT_render_changed", ZKEY, KM_PRESS, 0, 0);
185         
186         
187         transform_keymap_for_space(keyconf, keymap, SPACE_NODE);
188 }