doxygen: prevent GPL license block from being parsed as doxygen comment.
[blender.git] / source / blender / editors / space_nla / nla_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) 2009 Blender Foundation, Joshua Leung
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Joshua Leung (major recode)
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include <string.h>
30 #include <stdio.h>
31
32 #include "DNA_scene_types.h"
33
34
35 #include "BLI_blenlib.h"
36 #include "BLI_math.h"
37 #include "BLI_rand.h"
38
39 #include "BKE_context.h"
40 #include "BKE_screen.h"
41
42 #include "ED_anim_api.h"
43 #include "ED_screen.h"
44 #include "ED_transform.h"
45
46 #include "WM_api.h"
47 #include "WM_types.h"
48
49 #include "RNA_access.h"
50
51
52 #include "nla_intern.h" // own include
53
54 /* ************************** poll callbacks for operators **********************************/
55
56 /* tweakmode is NOT enabled */
57 int nlaop_poll_tweakmode_off (bContext *C)
58 {
59         Scene *scene;
60         
61         /* for now, we check 2 things: 
62          *      1) active editor must be NLA
63          *      2) tweakmode is currently set as a 'per-scene' flag 
64          *         so that it will affect entire NLA data-sets,
65          *         but not all AnimData blocks will be in tweakmode for 
66          *         various reasons
67          */
68         if (ED_operator_nla_active(C) == 0)
69                 return 0;
70         
71         scene= CTX_data_scene(C);
72         if ((scene == NULL) || (scene->flag & SCE_NLA_EDIT_ON))
73                 return 0;
74         
75         return 1;
76 }
77
78 /* tweakmode IS enabled */
79 int nlaop_poll_tweakmode_on (bContext *C)
80 {
81         Scene *scene;
82         
83         /* for now, we check 2 things: 
84          *      1) active editor must be NLA
85          *      2) tweakmode is currently set as a 'per-scene' flag 
86          *         so that it will affect entire NLA data-sets,
87          *         but not all AnimData blocks will be in tweakmode for 
88          *         various reasons
89          */
90         if (ED_operator_nla_active(C) == 0)
91                 return 0;
92         
93         scene= CTX_data_scene(C);
94         if ((scene == NULL) || !(scene->flag & SCE_NLA_EDIT_ON))
95                 return 0;
96         
97         return 1;
98 }
99
100 /* is tweakmode enabled - for use in NLA operator code */
101 short nlaedit_is_tweakmode_on (bAnimContext *ac)
102 {
103         if (ac && ac->scene)
104                 return (ac->scene->flag & SCE_NLA_EDIT_ON);
105         return 0;
106 }
107
108 /* ************************** registration - operator types **********************************/
109
110 void nla_operatortypes(void)
111 {
112         /* view */
113         WM_operatortype_append(NLA_OT_properties);
114         
115         /* channels */
116         WM_operatortype_append(NLA_OT_channels_click);
117         
118         WM_operatortype_append(NLA_OT_tracks_add);
119         WM_operatortype_append(NLA_OT_delete_tracks);
120         
121         /* select */
122         WM_operatortype_append(NLA_OT_click_select);
123         WM_operatortype_append(NLA_OT_select_border);
124         WM_operatortype_append(NLA_OT_select_all_toggle);
125         WM_operatortype_append(NLA_OT_select_leftright);
126         
127         /* edit */
128         WM_operatortype_append(NLA_OT_tweakmode_enter);
129         WM_operatortype_append(NLA_OT_tweakmode_exit);
130         
131         WM_operatortype_append(NLA_OT_actionclip_add);
132         WM_operatortype_append(NLA_OT_transition_add);
133         
134         WM_operatortype_append(NLA_OT_meta_add);
135         WM_operatortype_append(NLA_OT_meta_remove);
136         
137         WM_operatortype_append(NLA_OT_duplicate);
138         WM_operatortype_append(NLA_OT_delete);
139         WM_operatortype_append(NLA_OT_split);
140         
141         WM_operatortype_append(NLA_OT_mute_toggle);
142         
143         WM_operatortype_append(NLA_OT_swap);
144         WM_operatortype_append(NLA_OT_move_up);
145         WM_operatortype_append(NLA_OT_move_down);
146         
147         WM_operatortype_append(NLA_OT_action_sync_length);
148         
149         WM_operatortype_append(NLA_OT_apply_scale);
150         WM_operatortype_append(NLA_OT_clear_scale);
151         
152         WM_operatortype_append(NLA_OT_snap);
153         
154         WM_operatortype_append(NLA_OT_fmodifier_add);
155         WM_operatortype_append(NLA_OT_fmodifier_copy);
156         WM_operatortype_append(NLA_OT_fmodifier_paste);
157 }
158
159 /* ************************** registration - keymaps **********************************/
160
161 static void nla_keymap_channels(wmKeyMap *keymap)
162 {
163         /* NLA-specific (different to standard channels keymap) -------------------------- */
164         /* selection */
165                 /* click-select */
166                 // XXX for now, only leftmouse.... 
167         WM_keymap_add_item(keymap, "NLA_OT_channels_click", LEFTMOUSE, KM_PRESS, 0, 0);
168         RNA_boolean_set(WM_keymap_add_item(keymap, "NLA_OT_channels_click", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", 1);
169         
170         /* channel operations */
171                 /* add tracks */
172         WM_keymap_add_item(keymap, "NLA_OT_tracks_add", AKEY, KM_PRESS, KM_SHIFT, 0);
173         RNA_boolean_set(WM_keymap_add_item(keymap, "NLA_OT_tracks_add", AKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "above_selected", 1);
174         
175                 /* delete tracks */
176         WM_keymap_add_item(keymap, "NLA_OT_delete_tracks", XKEY, KM_PRESS, 0, 0);
177         WM_keymap_add_item(keymap, "NLA_OT_delete_tracks", DELKEY, KM_PRESS, 0, 0);
178 }
179
180 static void nla_keymap_main (wmKeyConfig *keyconf, wmKeyMap *keymap)
181 {
182         wmKeyMapItem *kmi;
183         
184         /* selection */
185                 /* click select */
186         WM_keymap_add_item(keymap, "NLA_OT_click_select", SELECTMOUSE, KM_PRESS, 0, 0);
187         kmi= WM_keymap_add_item(keymap, "NLA_OT_click_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
188                 RNA_boolean_set(kmi->ptr, "extend", 1);
189                 
190                 /* select left/right */
191         WM_keymap_add_item(keymap, "NLA_OT_select_leftright", SELECTMOUSE, KM_PRESS, KM_CTRL, 0);
192         kmi= WM_keymap_add_item(keymap, "NLA_OT_select_leftright", SELECTMOUSE, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
193                 RNA_boolean_set(kmi->ptr, "extend", 1);
194         
195         kmi= WM_keymap_add_item(keymap, "NLA_OT_select_leftright", LEFTBRACKETKEY, KM_PRESS, 0, 0);
196                 RNA_enum_set(kmi->ptr, "mode", NLAEDIT_LRSEL_LEFT);
197         kmi= WM_keymap_add_item(keymap, "NLA_OT_select_leftright", RIGHTBRACKETKEY, KM_PRESS, 0, 0);
198                 RNA_enum_set(kmi->ptr, "mode", NLAEDIT_LRSEL_RIGHT);
199                 
200         
201                 /* deselect all */
202         WM_keymap_add_item(keymap, "NLA_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0);
203         RNA_boolean_set(WM_keymap_add_item(keymap, "NLA_OT_select_all_toggle", IKEY, KM_PRESS, KM_CTRL, 0)->ptr, "invert", 1);
204         
205                 /* borderselect */
206         WM_keymap_add_item(keymap, "NLA_OT_select_border", BKEY, KM_PRESS, 0, 0);
207         RNA_boolean_set(WM_keymap_add_item(keymap, "NLA_OT_select_border", BKEY, KM_PRESS, KM_ALT, 0)->ptr, "axis_range", 1);
208         
209         
210         /* editing */
211                 /* tweakmode 
212                  *      - enter and exit are separate operators with the same hotkey... 
213                  *        This works as they use different poll()'s
214                  */
215         WM_keymap_add_item(keymap, "NLA_OT_tweakmode_enter", TABKEY, KM_PRESS, 0, 0);
216         WM_keymap_add_item(keymap, "NLA_OT_tweakmode_exit", TABKEY, KM_PRESS, 0, 0);
217                 
218                 /* add strips */
219         WM_keymap_add_item(keymap, "NLA_OT_actionclip_add", AKEY, KM_PRESS, KM_SHIFT, 0);
220         WM_keymap_add_item(keymap, "NLA_OT_transition_add", TKEY, KM_PRESS, KM_SHIFT, 0);
221         
222                 /* meta-strips */
223         WM_keymap_add_item(keymap, "NLA_OT_meta_add", GKEY, KM_PRESS, KM_SHIFT, 0);
224         WM_keymap_add_item(keymap, "NLA_OT_meta_remove", GKEY, KM_PRESS, KM_ALT, 0);
225                 
226                 /* duplicate */
227         WM_keymap_add_item(keymap, "NLA_OT_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);    
228                 
229                 /* delete */
230         WM_keymap_add_item(keymap, "NLA_OT_delete", XKEY, KM_PRESS, 0, 0);
231         WM_keymap_add_item(keymap, "NLA_OT_delete", DELKEY, KM_PRESS, 0, 0);
232
233                 /* split */
234         WM_keymap_add_item(keymap, "NLA_OT_split", YKEY, KM_PRESS, 0, 0);
235         
236                 /* toggles */
237         WM_keymap_add_item(keymap, "NLA_OT_mute_toggle", HKEY, KM_PRESS, 0, 0);
238         
239                 /* swap */
240         WM_keymap_add_item(keymap, "NLA_OT_swap", FKEY, KM_PRESS, KM_ALT, 0);
241                 
242                 /* move up */
243         WM_keymap_add_item(keymap, "NLA_OT_move_up", PAGEUPKEY, KM_PRESS, 0, 0);
244                 /* move down */
245         WM_keymap_add_item(keymap, "NLA_OT_move_down", PAGEDOWNKEY, KM_PRESS, 0, 0);
246         
247                 /* apply scale */
248         WM_keymap_add_item(keymap, "NLA_OT_apply_scale", AKEY, KM_PRESS, KM_CTRL, 0);
249                 /* clear scale */
250         WM_keymap_add_item(keymap, "NLA_OT_clear_scale", SKEY, KM_PRESS, KM_ALT, 0);
251         
252                 /* snap */
253         WM_keymap_add_item(keymap, "NLA_OT_snap", SKEY, KM_PRESS, KM_SHIFT, 0);
254         
255                 /* add f-modifier */
256         WM_keymap_add_item(keymap, "NLA_OT_fmodifier_add", MKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
257         
258         /* transform system */
259         transform_keymap_for_space(keyconf, keymap, SPACE_NLA);
260 }
261
262 /* --------------- */
263
264 void nla_keymap(wmKeyConfig *keyconf)
265 {
266         wmKeyMap *keymap;
267         
268         /* keymap for all regions */
269         keymap= WM_keymap_find(keyconf, "NLA Generic", SPACE_NLA, 0);
270         WM_keymap_add_item(keymap, "NLA_OT_properties", NKEY, KM_PRESS, 0, 0);
271         
272         /* channels */
273         /* Channels are not directly handled by the NLA Editor module, but are inherited from the Animation module. 
274          * Most of the relevant operations, keymaps, drawing, etc. can therefore all be found in that module instead, as there
275          * are many similarities with the other Animation Editors.
276          *
277          * However, those operations which involve clicking on channels and/or the placement of them in the view are implemented here instead
278          */
279         keymap= WM_keymap_find(keyconf, "NLA Channels", SPACE_NLA, 0);
280         nla_keymap_channels(keymap);
281         
282         /* data */
283         keymap= WM_keymap_find(keyconf, "NLA Editor", SPACE_NLA, 0);
284         nla_keymap_main(keyconf, keymap);
285 }
286