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