76b08012c5619400d6cf33c71840c25e7f24f31a
[blender-staging.git] / source / blender / editors / space_action / action_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
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file blender/editors/space_action/action_ops.c
28  *  \ingroup spaction
29  */
30
31
32 #include <stdlib.h>
33 #include <math.h>
34
35
36 #include "DNA_space_types.h"
37
38
39 #include "ED_anim_api.h"
40 #include "ED_markers.h"
41 #include "ED_transform.h"
42
43 #include "action_intern.h"
44
45 #include "RNA_access.h"
46
47 #include "WM_api.h"
48 #include "WM_types.h"
49
50 /* ************************** registration - operator types **********************************/
51
52 void action_operatortypes(void)
53 {
54         /* keyframes */
55         /* selection */
56         WM_operatortype_append(ACTION_OT_clickselect);
57         WM_operatortype_append(ACTION_OT_select_all_toggle);
58         WM_operatortype_append(ACTION_OT_select_border);
59         WM_operatortype_append(ACTION_OT_select_column);
60         WM_operatortype_append(ACTION_OT_select_linked);
61         WM_operatortype_append(ACTION_OT_select_more);
62         WM_operatortype_append(ACTION_OT_select_less);
63         WM_operatortype_append(ACTION_OT_select_leftright);
64         
65         /* editing */
66         WM_operatortype_append(ACTION_OT_snap);
67         WM_operatortype_append(ACTION_OT_mirror);
68         WM_operatortype_append(ACTION_OT_frame_jump);
69         WM_operatortype_append(ACTION_OT_handle_type);
70         WM_operatortype_append(ACTION_OT_interpolation_type);
71         WM_operatortype_append(ACTION_OT_extrapolation_type);
72         WM_operatortype_append(ACTION_OT_keyframe_type);
73         WM_operatortype_append(ACTION_OT_sample);
74         WM_operatortype_append(ACTION_OT_clean);
75         WM_operatortype_append(ACTION_OT_delete);
76         WM_operatortype_append(ACTION_OT_duplicate);
77         WM_operatortype_append(ACTION_OT_keyframe_insert);
78         WM_operatortype_append(ACTION_OT_copy);
79         WM_operatortype_append(ACTION_OT_paste);
80         
81         WM_operatortype_append(ACTION_OT_new);
82         WM_operatortype_append(ACTION_OT_push_down);
83         
84         WM_operatortype_append(ACTION_OT_previewrange_set);
85         WM_operatortype_append(ACTION_OT_view_all);
86         WM_operatortype_append(ACTION_OT_view_selected);
87         
88         WM_operatortype_append(ACTION_OT_markers_make_local);
89 }
90
91 void ED_operatormacros_action(void)
92 {
93         wmOperatorType *ot;
94         wmOperatorTypeMacro *otmacro;
95         
96         ot = WM_operatortype_append_macro("ACTION_OT_duplicate_move", "Duplicate",
97                                           "Make a copy of all selected keyframes and move them",
98                                           OPTYPE_UNDO | OPTYPE_REGISTER);
99         WM_operatortype_macro_define(ot, "ACTION_OT_duplicate");
100         otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_transform");
101         RNA_enum_set(otmacro->ptr, "mode", TFM_TIME_DUPLICATE);
102 }
103
104 /* ************************** registration - keymaps **********************************/
105
106 static void action_keymap_keyframes(wmKeyConfig *keyconf, wmKeyMap *keymap)
107 {
108         wmKeyMapItem *kmi;
109         
110         /* action_select.c - selection tools */
111         /* click-select: keyframe (replace) */
112         kmi = WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, 0, 0);
113         RNA_boolean_set(kmi->ptr, "extend", false);
114         RNA_boolean_set(kmi->ptr, "column", false);
115         RNA_boolean_set(kmi->ptr, "channel", false);
116         /* click-select: all on same frame (replace) */
117         kmi = WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_ALT, 0);
118         RNA_boolean_set(kmi->ptr, "extend", false);
119         RNA_boolean_set(kmi->ptr, "column", true);
120         RNA_boolean_set(kmi->ptr, "channel", false);
121         /* click-select: keyframe (add) */
122         kmi = WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
123         RNA_boolean_set(kmi->ptr, "extend", true);
124         RNA_boolean_set(kmi->ptr, "column", false);
125         RNA_boolean_set(kmi->ptr, "channel", false);
126         /* click-select: all on same frame (add) */
127         kmi = WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_ALT | KM_SHIFT, 0);
128         RNA_boolean_set(kmi->ptr, "extend", true);
129         RNA_boolean_set(kmi->ptr, "column", true);
130         RNA_boolean_set(kmi->ptr, "channel", false);
131         /* click-select: all on same channel (replace) */
132         kmi = WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_CTRL | KM_ALT, 0);
133         RNA_boolean_set(kmi->ptr, "extend", false);
134         RNA_boolean_set(kmi->ptr, "column", false);
135         RNA_boolean_set(kmi->ptr, "channel", true);
136         /* click-select: all on same channel (add) */
137         kmi = WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_CTRL | KM_ALT | KM_SHIFT, 0);
138         RNA_boolean_set(kmi->ptr, "extend", true);
139         RNA_boolean_set(kmi->ptr, "column", false);
140         RNA_boolean_set(kmi->ptr, "channel", true);
141                 
142         /* click-select: left/right */
143         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_leftright", SELECTMOUSE, KM_PRESS, KM_CTRL, 0);
144         RNA_boolean_set(kmi->ptr, "extend", false);
145         RNA_enum_set(kmi->ptr, "mode", ACTKEYS_LRSEL_TEST);
146         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_leftright", SELECTMOUSE, KM_PRESS, KM_CTRL | KM_SHIFT, 0);
147         RNA_boolean_set(kmi->ptr, "extend", true);
148         RNA_enum_set(kmi->ptr, "mode", ACTKEYS_LRSEL_TEST);
149         
150         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_leftright", LEFTBRACKETKEY, KM_PRESS, 0, 0);
151         RNA_boolean_set(kmi->ptr, "extend", false);
152         RNA_enum_set(kmi->ptr, "mode", ACTKEYS_LRSEL_LEFT);
153         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_leftright", RIGHTBRACKETKEY, KM_PRESS, 0, 0);
154         RNA_boolean_set(kmi->ptr, "extend", false);
155         RNA_enum_set(kmi->ptr, "mode", ACTKEYS_LRSEL_RIGHT);
156         
157         /* deselect all */
158         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0);
159         RNA_boolean_set(kmi->ptr, "invert", false);
160         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_all_toggle", IKEY, KM_PRESS, KM_CTRL, 0);
161         RNA_boolean_set(kmi->ptr, "invert", true);
162         
163         /* borderselect */
164         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_border", BKEY, KM_PRESS, 0, 0);
165         RNA_boolean_set(kmi->ptr, "axis_range", false);
166         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_border", BKEY, KM_PRESS, KM_ALT, 0);
167         RNA_boolean_set(kmi->ptr, "axis_range", true);
168         
169         /* column select */
170         RNA_enum_set(WM_keymap_add_item(keymap, "ACTION_OT_select_column", KKEY, KM_PRESS, 0, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_KEYS);
171         RNA_enum_set(WM_keymap_add_item(keymap, "ACTION_OT_select_column", KKEY, KM_PRESS, KM_CTRL, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_CFRA);
172         RNA_enum_set(WM_keymap_add_item(keymap, "ACTION_OT_select_column", KKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_MARKERS_COLUMN);
173         RNA_enum_set(WM_keymap_add_item(keymap, "ACTION_OT_select_column", KKEY, KM_PRESS, KM_ALT, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_MARKERS_BETWEEN);
174         
175         /* select more/less */
176         WM_keymap_add_item(keymap, "ACTION_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
177         WM_keymap_add_item(keymap, "ACTION_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0);
178         
179         /* select linked */
180         WM_keymap_add_item(keymap, "ACTION_OT_select_linked", LKEY, KM_PRESS, 0, 0);
181         
182         
183         /* action_edit.c */
184         /* jump to selected keyframes */
185         WM_keymap_add_item(keymap, "ACTION_OT_frame_jump", GKEY, KM_PRESS, KM_CTRL, 0);
186                 
187         /* menu + single-step transform */
188         WM_keymap_add_item(keymap, "ACTION_OT_snap", SKEY, KM_PRESS, KM_SHIFT, 0);
189         WM_keymap_add_item(keymap, "ACTION_OT_mirror", MKEY, KM_PRESS, KM_SHIFT, 0);
190         
191         /* menu + set setting */
192         WM_keymap_add_item(keymap, "ACTION_OT_handle_type", VKEY, KM_PRESS, 0, 0);
193         WM_keymap_add_item(keymap, "ACTION_OT_interpolation_type", TKEY, KM_PRESS, 0, 0);
194         WM_keymap_add_item(keymap, "ACTION_OT_extrapolation_type", EKEY, KM_PRESS, KM_SHIFT, 0); 
195         WM_keymap_add_item(keymap, "ACTION_OT_keyframe_type", RKEY, KM_PRESS, 0, 0); 
196         
197         /* destructive */
198         WM_keymap_add_item(keymap, "ACTION_OT_clean", OKEY, KM_PRESS, 0, 0);
199         WM_keymap_add_item(keymap, "ACTION_OT_sample", OKEY, KM_PRESS, KM_SHIFT, 0);
200         
201         WM_keymap_add_item(keymap, "ACTION_OT_delete", XKEY, KM_PRESS, 0, 0);
202         WM_keymap_add_item(keymap, "ACTION_OT_delete", DELKEY, KM_PRESS, 0, 0);
203         
204         WM_keymap_add_item(keymap, "ACTION_OT_duplicate_move", DKEY, KM_PRESS, KM_SHIFT, 0);
205         WM_keymap_add_item(keymap, "ACTION_OT_keyframe_insert", IKEY, KM_PRESS, 0, 0);
206         
207         /* copy/paste */
208         WM_keymap_add_item(keymap, "ACTION_OT_copy", CKEY, KM_PRESS, KM_CTRL, 0);
209         WM_keymap_add_item(keymap, "ACTION_OT_paste", VKEY, KM_PRESS, KM_CTRL, 0);
210         kmi = WM_keymap_add_item(keymap, "ACTION_OT_paste", VKEY, KM_PRESS, KM_CTRL | KM_SHIFT, 0);
211         RNA_boolean_set(kmi->ptr, "flipped", true);
212 #ifdef __APPLE__
213         WM_keymap_add_item(keymap, "ACTION_OT_copy", CKEY, KM_PRESS, KM_OSKEY, 0);
214         WM_keymap_add_item(keymap, "ACTION_OT_paste", VKEY, KM_PRESS, KM_OSKEY, 0);
215         kmi = WM_keymap_add_item(keymap, "ACTION_OT_paste", VKEY, KM_PRESS, KM_OSKEY | KM_SHIFT, 0);
216         RNA_boolean_set(kmi->ptr, "flipped", true);
217 #endif
218
219         /* auto-set range */
220         WM_keymap_add_item(keymap, "ACTION_OT_previewrange_set", PKEY, KM_PRESS, KM_CTRL | KM_ALT, 0);
221         WM_keymap_add_item(keymap, "ACTION_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
222         WM_keymap_add_item(keymap, "ACTION_OT_view_all", NDOF_BUTTON_FIT, KM_PRESS, 0, 0);
223         WM_keymap_add_item(keymap, "ACTION_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
224         
225         /* animation module */
226         /* channels list
227          * NOTE: these operators were originally for the channels list, but are added here too for convenience...
228          */
229         WM_keymap_add_item(keymap, "ANIM_OT_channels_editable_toggle", TABKEY, KM_PRESS, 0, 0);
230         
231         /* find (i.e. a shortcut for setting the name filter) */
232         WM_keymap_add_item(keymap, "ANIM_OT_channels_find", FKEY, KM_PRESS, KM_CTRL, 0);
233         
234         /* transform system */
235         transform_keymap_for_space(keyconf, keymap, SPACE_ACTION);
236         
237         /* special markers hotkeys for anim editors: see note in definition of this function */
238         ED_marker_keymap_animedit_conflictfree(keymap);
239 }
240
241 /* --------------- */
242
243 void action_keymap(wmKeyConfig *keyconf)
244 {
245         wmKeyMap *keymap;
246         
247         /* channels */
248         /* Channels are not directly handled by the Action Editor module, but are inherited from the Animation module. 
249          * All the relevant operations, keymaps, drawing, etc. can therefore all be found in that module instead, as these
250          * are all used for the Graph-Editor too.
251          */
252         
253         /* keyframes */
254         keymap = WM_keymap_find(keyconf, "Dopesheet", SPACE_ACTION, 0);
255         action_keymap_keyframes(keyconf, keymap);
256 }
257