NLA SoC: 'Split' Operator (YKEY)
[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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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_anim_types.h"
33 #include "DNA_action_types.h"
34 #include "DNA_nla_types.h"
35 #include "DNA_object_types.h"
36 #include "DNA_space_types.h"
37 #include "DNA_scene_types.h"
38 #include "DNA_screen_types.h"
39 #include "DNA_windowmanager_types.h"
40
41 #include "MEM_guardedalloc.h"
42
43 #include "BLI_blenlib.h"
44 #include "BLI_arithb.h"
45 #include "BLI_rand.h"
46
47 #include "BKE_animsys.h"
48 #include "BKE_nla.h"
49 #include "BKE_context.h"
50 #include "BKE_report.h"
51 #include "BKE_screen.h"
52
53 #include "ED_anim_api.h"
54 #include "ED_space_api.h"
55 #include "ED_screen.h"
56
57 #include "BIF_transform.h"
58
59 #include "WM_api.h"
60 #include "WM_types.h"
61
62 #include "RNA_access.h"
63
64 #include "UI_interface.h"
65 #include "UI_resources.h"
66 #include "UI_view2d.h"
67
68 #include "nla_intern.h" // own include
69
70 /* ************************** poll callbacks for operators **********************************/
71
72 /* tweakmode is NOT enabled */
73 int nlaop_poll_tweakmode_off (bContext *C)
74 {
75         Scene *scene;
76         
77         /* for now, we check 2 things: 
78          *      1) active editor must be NLA
79          *      2) tweakmode is currently set as a 'per-scene' flag 
80          *         so that it will affect entire NLA data-sets,
81          *         but not all AnimData blocks will be in tweakmode for 
82          *         various reasons
83          */
84         if (ED_operator_nla_active(C) == 0)
85                 return 0;
86         
87         scene= CTX_data_scene(C);
88         if ((scene == NULL) || (scene->flag & SCE_NLA_EDIT_ON))
89                 return 0;
90         
91         return 1;
92 }
93
94 /* tweakmode IS enabled */
95 int nlaop_poll_tweakmode_on (bContext *C)
96 {
97         Scene *scene;
98         
99         /* for now, we check 2 things: 
100          *      1) active editor must be NLA
101          *      2) tweakmode is currently set as a 'per-scene' flag 
102          *         so that it will affect entire NLA data-sets,
103          *         but not all AnimData blocks will be in tweakmode for 
104          *         various reasons
105          */
106         if (ED_operator_nla_active(C) == 0)
107                 return 0;
108         
109         scene= CTX_data_scene(C);
110         if ((scene == NULL) || !(scene->flag & SCE_NLA_EDIT_ON))
111                 return 0;
112         
113         return 1;
114 }
115
116 /* ************************** registration - operator types **********************************/
117
118 void nla_operatortypes(void)
119 {
120         /* view */
121         WM_operatortype_append(NLAEDIT_OT_properties);
122         
123         /* channels */
124         WM_operatortype_append(NLA_OT_channels_click);
125         WM_operatortype_append(NLA_OT_channels_select_border);
126         
127         /* select */
128         WM_operatortype_append(NLAEDIT_OT_click_select);
129         WM_operatortype_append(NLAEDIT_OT_select_border);
130         WM_operatortype_append(NLAEDIT_OT_select_all_toggle);
131         
132         /* edit */
133         WM_operatortype_append(NLAEDIT_OT_tweakmode_enter);
134         WM_operatortype_append(NLAEDIT_OT_tweakmode_exit);
135         
136         WM_operatortype_append(NLAEDIT_OT_delete);
137         WM_operatortype_append(NLAEDIT_OT_split);
138 }
139
140 /* ************************** registration - keymaps **********************************/
141
142 static void nla_keymap_channels (wmWindowManager *wm, ListBase *keymap)
143 {
144         /* NLA-specific (different to standard channels keymap) -------------------------- */
145         /* selection */
146                 /* click-select */
147                 // XXX for now, only leftmouse.... 
148         WM_keymap_add_item(keymap, "NLA_OT_channels_click", LEFTMOUSE, KM_PRESS, 0, 0);
149         RNA_boolean_set(WM_keymap_add_item(keymap, "NLA_OT_channels_click", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", 1);
150         
151         /* borderselect */ 
152         WM_keymap_add_item(keymap, "NLA_OT_channels_select_border", BKEY, KM_PRESS, 0, 0);
153         
154         /* General Animation Channels keymap (see anim_channels.c) ----------------------- */
155                 /* deselect all */
156         WM_keymap_add_item(keymap, "ANIM_OT_channels_select_all_toggle", AKEY, KM_PRESS, 0, 0);
157         RNA_boolean_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_select_all_toggle", IKEY, KM_PRESS, KM_CTRL, 0)->ptr, "invert", 1);
158         
159         /* settings */
160         WM_keymap_add_item(keymap, "ANIM_OT_channels_setting_toggle", WKEY, KM_PRESS, KM_SHIFT, 0);
161         WM_keymap_add_item(keymap, "ANIM_OT_channels_setting_enable", WKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
162         WM_keymap_add_item(keymap, "ANIM_OT_channels_setting_disable", WKEY, KM_PRESS, KM_ALT, 0);
163         
164         /* settings - specialised hotkeys */
165         WM_keymap_add_item(keymap, "ANIM_OT_channels_editable_toggle", TABKEY, KM_PRESS, 0, 0);
166         
167         /* expand/collapse */
168         WM_keymap_add_item(keymap, "ANIM_OT_channels_expand", PADPLUSKEY, KM_PRESS, 0, 0);
169         WM_keymap_add_item(keymap, "ANIM_OT_channels_collapse", PADMINUS, KM_PRESS, 0, 0);
170         
171         RNA_boolean_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_expand", PADPLUSKEY, KM_PRESS, KM_CTRL, 0)->ptr, "all", 1);
172         RNA_boolean_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_collapse", PADMINUS, KM_PRESS, KM_CTRL, 0)->ptr, "all", 1);
173 }
174
175 static void nla_keymap_main (wmWindowManager *wm, ListBase *keymap)
176 {
177         wmKeymapItem *kmi;
178         
179         /* selection */
180                 /* click select */
181         WM_keymap_add_item(keymap, "NLAEDIT_OT_click_select", SELECTMOUSE, KM_PRESS, 0, 0);
182         kmi= WM_keymap_add_item(keymap, "NLAEDIT_OT_click_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
183                 RNA_boolean_set(kmi->ptr, "extend", 1);
184         kmi= WM_keymap_add_item(keymap, "NLAEDIT_OT_click_select", SELECTMOUSE, KM_PRESS, KM_CTRL, 0);
185                 RNA_enum_set(kmi->ptr, "left_right", NLAEDIT_LRSEL_TEST);       
186         
187                 /* deselect all */
188         WM_keymap_add_item(keymap, "NLAEDIT_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0);
189         RNA_boolean_set(WM_keymap_add_item(keymap, "NLAEDIT_OT_select_all_toggle", IKEY, KM_PRESS, KM_CTRL, 0)->ptr, "invert", 1);
190         
191                 /* borderselect */
192         WM_keymap_add_item(keymap, "NLAEDIT_OT_select_border", BKEY, KM_PRESS, 0, 0);
193         RNA_boolean_set(WM_keymap_add_item(keymap, "NLAEDIT_OT_select_border", BKEY, KM_PRESS, KM_ALT, 0)->ptr, "axis_range", 1);
194         
195         
196         /* editing */
197                 /* tweakmode 
198                  *      - enter and exit are separate operators with the same hotkey... 
199                  *        This works as they use different poll()'s
200                  */
201         WM_keymap_add_item(keymap, "NLAEDIT_OT_tweakmode_enter", TABKEY, KM_PRESS, 0, 0);
202         WM_keymap_add_item(keymap, "NLAEDIT_OT_tweakmode_exit", TABKEY, KM_PRESS, 0, 0);
203                 
204                 /* delete */
205         WM_keymap_add_item(keymap, "NLAEDIT_OT_delete", XKEY, KM_PRESS, 0, 0);
206         WM_keymap_add_item(keymap, "NLAEDIT_OT_delete", DELKEY, KM_PRESS, 0, 0);
207         
208                 /* split */
209         WM_keymap_add_item(keymap, "NLAEDIT_OT_split", YKEY, KM_PRESS, 0, 0);
210         
211         /* transform system */
212         transform_keymap_for_space(wm, keymap, SPACE_NLA);
213 }
214
215 /* --------------- */
216
217 void nla_keymap(wmWindowManager *wm)
218 {
219         ListBase *keymap;
220         
221         /* keymap for all regions */
222         keymap= WM_keymap_listbase(wm, "NLA Generic", SPACE_NLA, 0);
223         WM_keymap_add_item(keymap, "NLAEDIT_OT_properties", NKEY, KM_PRESS, 0, 0);
224         
225         /* channels */
226         /* Channels are not directly handled by the NLA Editor module, but are inherited from the Animation module. 
227          * Most of the relevant operations, keymaps, drawing, etc. can therefore all be found in that module instead, as there
228          * are many similarities with the other Animation Editors.
229          *
230          * However, those operations which involve clicking on channels and/or the placement of them in the view are implemented here instead
231          */
232         keymap= WM_keymap_listbase(wm, "NLA Channels", SPACE_NLA, 0);
233         nla_keymap_channels(wm, keymap);
234         
235         /* data */
236         keymap= WM_keymap_listbase(wm, "NLA Data", SPACE_NLA, 0);
237         nla_keymap_main(wm, keymap);
238 }
239