svn merge -r36603:36628 https://svn.blender.org/svnroot/bf-blender/trunk/blender
[blender.git] / source / blender / editors / space_action / action_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
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 /** \file blender/editors/space_action/action_ops.c
30  *  \ingroup spaction
31  */
32
33
34 #include <stdlib.h>
35 #include <math.h>
36
37
38 #include "DNA_space_types.h"
39
40 #include "BLI_blenlib.h"
41
42 #include "ED_anim_api.h"
43 #include "ED_transform.h"
44
45 #include "action_intern.h"
46
47 #include "RNA_access.h"
48
49 #include "WM_api.h"
50 #include "WM_types.h"
51
52 /* ************************** registration - operator types **********************************/
53
54 void action_operatortypes(void)
55 {
56         /* keyframes */
57                 /* selection */
58         WM_operatortype_append(ACTION_OT_clickselect);
59         WM_operatortype_append(ACTION_OT_select_all_toggle);
60         WM_operatortype_append(ACTION_OT_select_border);
61         WM_operatortype_append(ACTION_OT_select_column);
62         WM_operatortype_append(ACTION_OT_select_linked);
63         WM_operatortype_append(ACTION_OT_select_more);
64         WM_operatortype_append(ACTION_OT_select_less);
65         WM_operatortype_append(ACTION_OT_select_leftright);
66         
67                 /* editing */
68         WM_operatortype_append(ACTION_OT_snap);
69         WM_operatortype_append(ACTION_OT_mirror);
70         WM_operatortype_append(ACTION_OT_frame_jump);
71         WM_operatortype_append(ACTION_OT_handle_type);
72         WM_operatortype_append(ACTION_OT_interpolation_type);
73         WM_operatortype_append(ACTION_OT_extrapolation_type);
74         WM_operatortype_append(ACTION_OT_keyframe_type);
75         WM_operatortype_append(ACTION_OT_sample);
76         WM_operatortype_append(ACTION_OT_clean);
77         WM_operatortype_append(ACTION_OT_delete);
78         WM_operatortype_append(ACTION_OT_duplicate);
79         WM_operatortype_append(ACTION_OT_keyframe_insert);
80         WM_operatortype_append(ACTION_OT_copy);
81         WM_operatortype_append(ACTION_OT_paste);
82         WM_operatortype_append(ACTION_OT_new);
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", OPTYPE_UNDO|OPTYPE_REGISTER);
97         if (ot) {
98                 WM_operatortype_macro_define(ot, "ACTION_OT_duplicate");
99                 otmacro= WM_operatortype_macro_define(ot, "TRANSFORM_OT_transform");
100                 RNA_enum_set(otmacro->ptr, "mode", TFM_TIME_DUPLICATE);
101         }
102         
103 }
104
105 /* ************************** registration - keymaps **********************************/
106
107 static void action_keymap_keyframes (wmKeyConfig *keyconf, wmKeyMap *keymap)
108 {
109         wmKeyMapItem *kmi;
110         
111         /* action_select.c - selection tools */
112                 /* click-select */
113         WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, 0, 0);
114         kmi= WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_ALT, 0);
115                 RNA_boolean_set(kmi->ptr, "column", 1);
116         kmi= WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
117                 RNA_boolean_set(kmi->ptr, "extend", 1);
118         kmi= WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_ALT|KM_SHIFT, 0);
119                 RNA_boolean_set(kmi->ptr, "extend", 1);
120                 RNA_boolean_set(kmi->ptr, "column", 1);
121                 
122                 /* select left/right */
123         WM_keymap_add_item(keymap, "ACTION_OT_select_leftright", SELECTMOUSE, KM_PRESS, KM_CTRL, 0);
124         kmi= WM_keymap_add_item(keymap, "ACTION_OT_select_leftright", SELECTMOUSE, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
125                 RNA_boolean_set(kmi->ptr, "extend", 1);
126         
127         kmi= WM_keymap_add_item(keymap, "ACTION_OT_select_leftright", LEFTBRACKETKEY, KM_PRESS, 0, 0);
128                 RNA_enum_set(kmi->ptr, "mode", ACTKEYS_LRSEL_LEFT);
129         kmi= WM_keymap_add_item(keymap, "ACTION_OT_select_leftright", RIGHTBRACKETKEY, KM_PRESS, 0, 0);
130                 RNA_enum_set(kmi->ptr, "mode", ACTKEYS_LRSEL_RIGHT);
131         
132                 /* deselect all */
133         WM_keymap_add_item(keymap, "ACTION_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0);
134         RNA_boolean_set(WM_keymap_add_item(keymap, "ACTION_OT_select_all_toggle", IKEY, KM_PRESS, KM_CTRL, 0)->ptr, "invert", 1);
135         
136                 /* borderselect */
137         WM_keymap_add_item(keymap, "ACTION_OT_select_border", BKEY, KM_PRESS, 0, 0);
138         RNA_boolean_set(WM_keymap_add_item(keymap, "ACTION_OT_select_border", BKEY, KM_PRESS, KM_ALT, 0)->ptr, "axis_range", 1);
139         
140                 /* column select */
141         RNA_enum_set(WM_keymap_add_item(keymap, "ACTION_OT_select_column", KKEY, KM_PRESS, 0, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_KEYS);
142         RNA_enum_set(WM_keymap_add_item(keymap, "ACTION_OT_select_column", KKEY, KM_PRESS, KM_CTRL, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_CFRA);
143         RNA_enum_set(WM_keymap_add_item(keymap, "ACTION_OT_select_column", KKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_MARKERS_COLUMN);
144         RNA_enum_set(WM_keymap_add_item(keymap, "ACTION_OT_select_column", KKEY, KM_PRESS, KM_ALT, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_MARKERS_BETWEEN);
145         
146                 /* select more/less */
147         WM_keymap_add_item(keymap, "ACTION_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
148         WM_keymap_add_item(keymap, "ACTION_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0);
149         
150                 /* select linekd */
151         WM_keymap_add_item(keymap, "ACTION_OT_select_linked", LKEY, KM_PRESS, 0, 0);
152         
153         
154         /* action_edit.c */
155                 /* snap - current frame to selected keys */
156                 // TODO: maybe since this is called jump, we're better to have it on <something>-J?
157         WM_keymap_add_item(keymap, "ACTION_OT_frame_jump", SKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
158                 
159                 /* menu + single-step transform */
160         WM_keymap_add_item(keymap, "ACTION_OT_snap", SKEY, KM_PRESS, KM_SHIFT, 0);
161         WM_keymap_add_item(keymap, "ACTION_OT_mirror", MKEY, KM_PRESS, KM_SHIFT, 0);
162         
163                 /* menu + set setting */
164         WM_keymap_add_item(keymap, "ACTION_OT_handle_type", VKEY, KM_PRESS, 0, 0);
165         WM_keymap_add_item(keymap, "ACTION_OT_interpolation_type", TKEY, KM_PRESS, KM_SHIFT, 0);
166         WM_keymap_add_item(keymap, "ACTION_OT_extrapolation_type", EKEY, KM_PRESS, KM_SHIFT, 0); 
167         WM_keymap_add_item(keymap, "ACTION_OT_keyframe_type", RKEY, KM_PRESS, 0, 0); 
168         
169                 /* destructive */
170         WM_keymap_add_item(keymap, "ACTION_OT_clean", OKEY, KM_PRESS, 0, 0);
171         WM_keymap_add_item(keymap, "ACTION_OT_sample", OKEY, KM_PRESS, KM_SHIFT, 0);
172         
173         WM_keymap_add_item(keymap, "ACTION_OT_delete", XKEY, KM_PRESS, 0, 0);
174         WM_keymap_add_item(keymap, "ACTION_OT_delete", DELKEY, KM_PRESS, 0, 0);
175         
176         WM_keymap_add_item(keymap, "ACTION_OT_duplicate_move", DKEY, KM_PRESS, KM_SHIFT, 0);
177         WM_keymap_add_item(keymap, "ACTION_OT_keyframe_insert", IKEY, KM_PRESS, 0, 0);
178         
179                 /* copy/paste */
180         WM_keymap_add_item(keymap, "ACTION_OT_copy", CKEY, KM_PRESS, KM_CTRL, 0);
181         WM_keymap_add_item(keymap, "ACTION_OT_paste", VKEY, KM_PRESS, KM_CTRL, 0);
182         
183                 /* auto-set range */
184         WM_keymap_add_item(keymap, "ACTION_OT_previewrange_set", PKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
185         WM_keymap_add_item(keymap, "ACTION_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
186         WM_keymap_add_item(keymap, "ACTION_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
187         
188         /* animation module */
189                 /* channels list 
190                  * NOTE: these operators were originally for the channels list, but are added here too for convenience...
191                  */
192         WM_keymap_add_item(keymap, "ANIM_OT_channels_editable_toggle", TABKEY, KM_PRESS, 0, 0);
193         
194         /* transform system */
195         transform_keymap_for_space(keyconf, keymap, SPACE_ACTION);
196 }
197
198 /* --------------- */
199
200 void action_keymap(wmKeyConfig *keyconf)
201 {
202         wmKeyMap *keymap;
203         
204         /* channels */
205         /* Channels are not directly handled by the Action Editor module, but are inherited from the Animation module. 
206          * All the relevant operations, keymaps, drawing, etc. can therefore all be found in that module instead, as these
207          * are all used for the Graph-Editor too.
208          */
209         
210         /* keyframes */
211         keymap= WM_keymap_find(keyconf, "Dopesheet", SPACE_ACTION, 0);
212         action_keymap_keyframes(keyconf, keymap);
213 }
214