NLA SoC: F-Modifiers working on NLA Strips
[blender.git] / source / blender / editors / space_graph / graph_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) 2008 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Blender Foundation
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include <stdlib.h>
30 #include <math.h>
31
32 #include "MEM_guardedalloc.h"
33
34 #include "DNA_listBase.h"
35 #include "DNA_action_types.h"
36 #include "DNA_scene_types.h"
37 #include "DNA_screen_types.h"
38 #include "DNA_space_types.h"
39 #include "DNA_windowmanager_types.h"
40
41 #include "BLI_blenlib.h"
42
43 #include "BKE_context.h"
44 #include "BKE_utildefines.h"
45
46 #include "UI_interface.h"
47 #include "UI_view2d.h"
48
49 #include "ED_screen.h"
50
51 #include "BIF_transform.h"
52
53 #include "graph_intern.h"
54
55 #include "RNA_access.h"
56 #include "RNA_define.h"
57
58 #include "WM_api.h"
59 #include "WM_types.h"
60
61 /* ************************** poll callbacks **********************************/
62
63
64
65 /* ************************** view-based operators **********************************/
66 // XXX this probably shouldn't be here..
67
68 /* Toggle Handles ----------------------------------------------------------------- */
69
70 static int view_toggle_handles_exec (bContext *C, wmOperator *op)
71 {
72         SpaceIpo *sipo= (SpaceIpo *)CTX_wm_space_data(C);
73         ARegion *ar= CTX_wm_region(C);
74         
75         if (sipo == NULL)
76                 return OPERATOR_CANCELLED;
77         
78         /* toggle flag to hide handles */
79         sipo->flag ^= SIPO_NOHANDLES;
80         
81         /* request refresh of keys area */
82         ED_region_tag_redraw(ar);
83         
84         return OPERATOR_FINISHED;
85 }
86
87 void GRAPH_OT_view_togglehandles (wmOperatorType *ot)
88 {
89         /* identification */
90         ot->name= "Show/Hide All Handles";
91         ot->idname= "GRAPH_OT_handles_view_toggle";
92         
93         /* callbacks */
94         ot->exec= view_toggle_handles_exec;
95         ot->poll= ED_operator_ipo_active;
96 }
97
98 /* ************************** registration - operator types **********************************/
99
100 void graphedit_operatortypes(void)
101 {
102         /* view */
103         WM_operatortype_append(GRAPH_OT_view_togglehandles);
104         WM_operatortype_append(GRAPH_OT_previewrange_set);
105         WM_operatortype_append(GRAPH_OT_view_all);
106         WM_operatortype_append(GRAPH_OT_properties);
107         
108         WM_operatortype_append(GRAPH_OT_ghost_curves_create);
109         WM_operatortype_append(GRAPH_OT_ghost_curves_clear);
110         
111         /* keyframes */
112                 /* selection */
113         WM_operatortype_append(GRAPH_OT_clickselect);
114         WM_operatortype_append(GRAPH_OT_select_all_toggle);
115         WM_operatortype_append(GRAPH_OT_select_border);
116         WM_operatortype_append(GRAPH_OT_select_column);
117         
118                 /* editing */
119         WM_operatortype_append(GRAPH_OT_snap);
120         WM_operatortype_append(GRAPH_OT_mirror);
121         WM_operatortype_append(GRAPH_OT_frame_jump);
122         WM_operatortype_append(GRAPH_OT_handletype);
123         WM_operatortype_append(GRAPH_OT_interpolation_type);
124         WM_operatortype_append(GRAPH_OT_extrapolation_type);
125         WM_operatortype_append(GRAPH_OT_sample);
126         WM_operatortype_append(GRAPH_OT_bake);
127         WM_operatortype_append(GRAPH_OT_smooth);
128         WM_operatortype_append(GRAPH_OT_clean);
129         WM_operatortype_append(GRAPH_OT_delete);
130         WM_operatortype_append(GRAPH_OT_duplicate);
131         
132         WM_operatortype_append(GRAPH_OT_copy);
133         WM_operatortype_append(GRAPH_OT_paste);
134         
135         WM_operatortype_append(GRAPH_OT_insert_keyframe);
136         WM_operatortype_append(GRAPH_OT_click_insert);
137         
138         /* F-Curve Modifiers */
139         // XXX temporary?
140         WM_operatortype_append(GRAPH_OT_fmodifier_add);
141 }
142
143 /* ************************** registration - keymaps **********************************/
144
145 static void graphedit_keymap_keyframes (wmWindowManager *wm, ListBase *keymap)
146 {
147         wmKeymapItem *kmi;
148         
149         /* view */
150         WM_keymap_add_item(keymap, "GRAPH_OT_handles_view_toggle", HKEY, KM_PRESS, KM_CTRL, 0);
151         
152         /* graph_select.c - selection tools */
153                 /* click-select */
154         WM_keymap_add_item(keymap, "GRAPH_OT_clickselect", SELECTMOUSE, KM_PRESS, 0, 0);
155         kmi= WM_keymap_add_item(keymap, "GRAPH_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_ALT, 0);
156                 RNA_boolean_set(kmi->ptr, "column", 1);
157         kmi= WM_keymap_add_item(keymap, "GRAPH_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
158                 RNA_boolean_set(kmi->ptr, "extend", 1);
159         kmi= WM_keymap_add_item(keymap, "GRAPH_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_ALT|KM_SHIFT, 0);
160                 RNA_boolean_set(kmi->ptr, "extend", 1);
161                 RNA_boolean_set(kmi->ptr, "column", 1);
162         kmi= WM_keymap_add_item(keymap, "GRAPH_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_CTRL, 0);
163                 RNA_enum_set(kmi->ptr, "left_right", GRAPHKEYS_LRSEL_TEST);
164         kmi= WM_keymap_add_item(keymap, "GRAPH_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_CTRL|KM_ALT, 0);
165                 RNA_boolean_set(kmi->ptr, "curves", 1);
166         kmi= WM_keymap_add_item(keymap, "GRAPH_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_CTRL|KM_ALT|KM_SHIFT, 0);
167                 RNA_boolean_set(kmi->ptr, "curves", 1);
168                 RNA_boolean_set(kmi->ptr, "extend", 1);
169         
170                 /* deselect all */
171         WM_keymap_add_item(keymap, "GRAPH_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0);
172         RNA_boolean_set(WM_keymap_add_item(keymap, "GRAPH_OT_select_all_toggle", IKEY, KM_PRESS, KM_CTRL, 0)->ptr, "invert", 1);
173         
174                 /* borderselect */
175         WM_keymap_add_item(keymap, "GRAPH_OT_select_border", BKEY, KM_PRESS, 0, 0);
176         RNA_boolean_set(WM_keymap_add_item(keymap, "GRAPH_OT_select_border", BKEY, KM_PRESS, KM_ALT, 0)->ptr, "axis_range", 1);
177         
178                 /* column select */
179                 // XXX KKEY would be nice to keep for 'keyframe' lines
180         RNA_enum_set(WM_keymap_add_item(keymap, "GRAPH_OT_select_column", KKEY, KM_PRESS, 0, 0)->ptr, "mode", GRAPHKEYS_COLUMNSEL_KEYS);
181         RNA_enum_set(WM_keymap_add_item(keymap, "GRAPH_OT_select_column", KKEY, KM_PRESS, KM_CTRL, 0)->ptr, "mode", GRAPHKEYS_COLUMNSEL_CFRA);
182         RNA_enum_set(WM_keymap_add_item(keymap, "GRAPH_OT_select_column", KKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", GRAPHKEYS_COLUMNSEL_MARKERS_COLUMN);
183         RNA_enum_set(WM_keymap_add_item(keymap, "GRAPH_OT_select_column", KKEY, KM_PRESS, KM_ALT, 0)->ptr, "mode", GRAPHKEYS_COLUMNSEL_MARKERS_BETWEEN);
184         
185         
186         /* graph_edit.c */
187                 /* snap - current frame to selected keys */
188                 // TODO: maybe since this is called jump, we're better to have it on <something>-J?
189         WM_keymap_add_item(keymap, "GRAPH_OT_frame_jump", SKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
190                 
191                 /* menu + single-step transform */
192         WM_keymap_add_item(keymap, "GRAPH_OT_snap", SKEY, KM_PRESS, KM_SHIFT, 0);
193         WM_keymap_add_item(keymap, "GRAPH_OT_mirror", MKEY, KM_PRESS, KM_SHIFT, 0);
194         
195         WM_keymap_add_item(keymap, "GRAPH_OT_handletype", HKEY, KM_PRESS, 0, 0);
196         WM_keymap_add_item(keymap, "GRAPH_OT_interpolation_type", TKEY, KM_PRESS, KM_SHIFT, 0);
197         WM_keymap_add_item(keymap, "GRAPH_OT_extrapolation_type", EKEY, KM_PRESS, KM_SHIFT, 0);
198         
199         
200                 /* destructive */
201         WM_keymap_add_item(keymap, "GRAPH_OT_clean", OKEY, KM_PRESS, 0, 0);
202         WM_keymap_add_item(keymap, "GRAPH_OT_smooth", OKEY, KM_PRESS, KM_ALT, 0);
203         WM_keymap_add_item(keymap, "GRAPH_OT_sample", OKEY, KM_PRESS, KM_SHIFT, 0);
204         
205         WM_keymap_add_item(keymap, "GRAPH_OT_bake", CKEY, KM_PRESS, KM_ALT, 0);
206         
207         WM_keymap_add_item(keymap, "GRAPH_OT_delete", XKEY, KM_PRESS, 0, 0);
208         WM_keymap_add_item(keymap, "GRAPH_OT_delete", DELKEY, KM_PRESS, 0, 0);
209         
210         WM_keymap_add_item(keymap, "GRAPH_OT_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);
211         
212                 /* insertkey */
213         WM_keymap_add_item(keymap, "GRAPH_OT_insert_keyframe", IKEY, KM_PRESS, 0, 0);
214         WM_keymap_add_item(keymap, "GRAPH_OT_click_insert", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
215         
216                 /* copy/paste */
217         WM_keymap_add_item(keymap, "GRAPH_OT_copy", CKEY, KM_PRESS, KM_CTRL, 0);
218         WM_keymap_add_item(keymap, "GRAPH_OT_paste", VKEY, KM_PRESS, KM_CTRL, 0);
219         
220                 /* auto-set range */
221         WM_keymap_add_item(keymap, "GRAPH_OT_previewrange_set", PKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
222         WM_keymap_add_item(keymap, "GRAPH_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
223         
224                 /* F-Modifiers */
225         WM_keymap_add_item(keymap, "GRAPH_OT_fmodifier_add", MKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
226         
227         
228         /* transform system */
229         transform_keymap_for_space(wm, keymap, SPACE_IPO);
230 }
231
232 /* --------------- */
233
234 void graphedit_keymap(wmWindowManager *wm)
235 {
236         ListBase *keymap;
237         
238         /* keymap for all regions */
239         keymap= WM_keymap_listbase(wm, "GraphEdit Generic", SPACE_IPO, 0);
240         WM_keymap_add_item(keymap, "GRAPH_OT_properties", NKEY, KM_PRESS, 0, 0);
241
242         /* channels */
243         /* Channels are not directly handled by the Graph Editor module, but are inherited from the Animation module. 
244          * All the relevant operations, keymaps, drawing, etc. can therefore all be found in that module instead, as these
245          * are all used for the Graph Editor too.
246          */
247         
248         /* keyframes */
249         keymap= WM_keymap_listbase(wm, "GraphEdit Keys", SPACE_IPO, 0);
250         graphedit_keymap_keyframes(wm, keymap);
251 }
252