small merge needed for testing new animsys in 2.5 BGE, mixing own changes with merge...
[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 /* ************************** view-based operators **********************************/
62 // XXX this probably shouldn't be here..
63
64 /* Toggle Handles ----------------------------------------------------------------- */
65
66 static int view_toggle_handles_exec (bContext *C, wmOperator *op)
67 {
68         SpaceIpo *sipo= (SpaceIpo *)CTX_wm_space_data(C);
69         ARegion *ar= CTX_wm_region(C);
70         
71         if (sipo == NULL)
72                 return OPERATOR_CANCELLED;
73         
74         /* toggle flag to hide handles */
75         sipo->flag ^= SIPO_NOHANDLES;
76         
77         /* request refresh of keys area */
78         ED_region_tag_redraw(ar);
79         
80         return OPERATOR_FINISHED;
81 }
82
83 void GRAPHEDIT_OT_view_togglehandles (wmOperatorType *ot)
84 {
85         /* identification */
86         ot->name= "Show/Hide All Handles";
87         ot->idname= "GRAPHEDIT_OT_handles_view_toggle";
88         
89         /* callbacks */
90         ot->exec= view_toggle_handles_exec;
91         ot->poll= ED_operator_areaactive;
92 }
93
94 /* ************************** registration - operator types **********************************/
95
96 void graphedit_operatortypes(void)
97 {
98         /* view */
99         WM_operatortype_append(GRAPHEDIT_OT_view_togglehandles);
100         WM_operatortype_append(GRAPHEDIT_OT_previewrange_set);
101         WM_operatortype_append(GRAPHEDIT_OT_view_all);
102         WM_operatortype_append(GRAPHEDIT_OT_properties);
103         
104         WM_operatortype_append(GRAPHEDIT_OT_ghost_curves_create);
105         WM_operatortype_append(GRAPHEDIT_OT_ghost_curves_clear);
106         
107         /* keyframes */
108                 /* selection */
109         WM_operatortype_append(GRAPHEDIT_OT_keyframes_clickselect);
110         WM_operatortype_append(GRAPHEDIT_OT_keyframes_select_all_toggle);
111         WM_operatortype_append(GRAPHEDIT_OT_keyframes_select_border);
112         WM_operatortype_append(GRAPHEDIT_OT_keyframes_columnselect);
113         
114                 /* editing */
115         WM_operatortype_append(GRAPHEDIT_OT_keyframes_snap);
116         WM_operatortype_append(GRAPHEDIT_OT_keyframes_mirror);
117         WM_operatortype_append(GRAPHEDIT_OT_keyframes_cfrasnap);
118         WM_operatortype_append(GRAPHEDIT_OT_keyframes_handletype);
119         WM_operatortype_append(GRAPHEDIT_OT_keyframes_interpolation_type);
120         WM_operatortype_append(GRAPHEDIT_OT_keyframes_extrapolation_type);
121         WM_operatortype_append(GRAPHEDIT_OT_keyframes_sample);
122         WM_operatortype_append(GRAPHEDIT_OT_keyframes_bake);
123         WM_operatortype_append(GRAPHEDIT_OT_keyframes_smooth);
124         WM_operatortype_append(GRAPHEDIT_OT_keyframes_clean);
125         WM_operatortype_append(GRAPHEDIT_OT_keyframes_delete);
126         WM_operatortype_append(GRAPHEDIT_OT_keyframes_duplicate);
127         
128         WM_operatortype_append(GRAPHEDIT_OT_keyframes_copy);
129         WM_operatortype_append(GRAPHEDIT_OT_keyframes_paste);
130         
131         WM_operatortype_append(GRAPHEDIT_OT_keyframes_click_insert);
132         
133         //TODO: insertkey...
134         
135         /* F-Curve Modifiers */
136         // XXX temporary?
137         WM_operatortype_append(GRAPHEDIT_OT_fmodifier_add);
138 }
139
140 /* ************************** registration - keymaps **********************************/
141
142 static void graphedit_keymap_keyframes (wmWindowManager *wm, ListBase *keymap)
143 {
144         wmKeymapItem *kmi;
145         
146         /* view */
147         WM_keymap_add_item(keymap, "GRAPHEDIT_OT_handles_view_toggle", HKEY, KM_PRESS, KM_CTRL, 0);
148         
149         /* graph_select.c - selection tools */
150                 /* click-select */
151         WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_clickselect", SELECTMOUSE, KM_PRESS, 0, 0);
152         kmi= WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_clickselect", SELECTMOUSE, KM_PRESS, KM_ALT, 0);
153                 RNA_boolean_set(kmi->ptr, "column", 1);
154         kmi= WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_clickselect", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
155                 RNA_boolean_set(kmi->ptr, "extend", 1);
156         kmi= WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_clickselect", SELECTMOUSE, KM_PRESS, KM_ALT|KM_SHIFT, 0);
157                 RNA_boolean_set(kmi->ptr, "extend", 1);
158                 RNA_boolean_set(kmi->ptr, "column", 1);
159         kmi= WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_clickselect", SELECTMOUSE, KM_PRESS, KM_CTRL, 0);
160                 RNA_enum_set(kmi->ptr, "left_right", GRAPHKEYS_LRSEL_TEST);
161         kmi= WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_clickselect", SELECTMOUSE, KM_PRESS, KM_CTRL|KM_ALT, 0);
162                 RNA_boolean_set(kmi->ptr, "curves", 1);
163         kmi= WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_clickselect", SELECTMOUSE, KM_PRESS, KM_CTRL|KM_ALT|KM_SHIFT, 0);
164                 RNA_boolean_set(kmi->ptr, "curves", 1);
165                 RNA_boolean_set(kmi->ptr, "extend", 1);
166         
167                 /* deselect all */
168         WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_select_all_toggle", AKEY, KM_PRESS, 0, 0);
169         RNA_boolean_set(WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_select_all_toggle", IKEY, KM_PRESS, KM_CTRL, 0)->ptr, "invert", 1);
170         
171                 /* borderselect */
172         WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_select_border", BKEY, KM_PRESS, 0, 0);
173         RNA_boolean_set(WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_select_border", BKEY, KM_PRESS, KM_ALT, 0)->ptr, "axis_range", 1);
174         
175                 /* column select */
176                 // XXX KKEY would be nice to keep for 'keyframe' lines
177         RNA_enum_set(WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_columnselect", KKEY, KM_PRESS, 0, 0)->ptr, "mode", GRAPHKEYS_COLUMNSEL_KEYS);
178         RNA_enum_set(WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_columnselect", KKEY, KM_PRESS, KM_CTRL, 0)->ptr, "mode", GRAPHKEYS_COLUMNSEL_CFRA);
179         RNA_enum_set(WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_columnselect", KKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", GRAPHKEYS_COLUMNSEL_MARKERS_COLUMN);
180         RNA_enum_set(WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_columnselect", KKEY, KM_PRESS, KM_ALT, 0)->ptr, "mode", GRAPHKEYS_COLUMNSEL_MARKERS_BETWEEN);
181         
182         
183         /* graph_edit.c */
184                 /* snap - current frame to selected keys */
185         WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_cfrasnap", SKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
186                 
187                 /* menu + single-step transform */
188         WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_snap", SKEY, KM_PRESS, KM_SHIFT, 0);
189         WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_mirror", MKEY, KM_PRESS, KM_SHIFT, 0);
190         
191         WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_handletype", HKEY, KM_PRESS, 0, 0);
192         WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_interpolation_type", TKEY, KM_PRESS, KM_SHIFT, 0);
193         WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_extrapolation_type", EKEY, KM_PRESS, KM_SHIFT, 0);
194         
195         
196                 /* destructive */
197         WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_clean", OKEY, KM_PRESS, 0, 0);
198         WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_smooth", OKEY, KM_PRESS, KM_ALT, 0);
199         WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_sample", OKEY, KM_PRESS, KM_SHIFT, 0);
200         
201         WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_bake", CKEY, KM_PRESS, KM_ALT, 0);
202         
203         WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_delete", XKEY, KM_PRESS, 0, 0);
204         WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_delete", DELKEY, KM_PRESS, 0, 0);
205         
206         WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);
207         
208                 /* insertkey */
209         WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_click_insert", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
210         
211                 /* copy/paste */
212         WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_copy", CKEY, KM_PRESS, KM_CTRL, 0);
213         WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_paste", VKEY, KM_PRESS, KM_CTRL, 0);
214         
215                 /* auto-set range */
216         WM_keymap_add_item(keymap, "GRAPHEDIT_OT_previewrange_set", PKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
217         WM_keymap_add_item(keymap, "GRAPHEDIT_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
218         
219                 /* F-Curve Modifiers */
220                 // XXX these are temporary? operators...
221         WM_keymap_add_item(keymap, "GRAPHEDIT_OT_fmodifier_add", MKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
222         
223         
224         /* transform system */
225         transform_keymap_for_space(wm, keymap, SPACE_IPO);
226 }
227
228 /* --------------- */
229
230 void graphedit_keymap(wmWindowManager *wm)
231 {
232         ListBase *keymap;
233         
234         /* keymap for all regions */
235         keymap= WM_keymap_listbase(wm, "GraphEdit Generic", SPACE_IPO, 0);
236         WM_keymap_add_item(keymap, "GRAPHEDIT_OT_properties", NKEY, KM_PRESS, 0, 0);
237
238         /* channels */
239         /* Channels are not directly handled by the Graph Editor module, but are inherited from the Animation module. 
240          * All the relevant operations, keymaps, drawing, etc. can therefore all be found in that module instead, as these
241          * are all used for the Graph Editor too.
242          */
243         
244         /* keyframes */
245         keymap= WM_keymap_listbase(wm, "GraphEdit Keys", SPACE_IPO, 0);
246         graphedit_keymap_keyframes(wm, keymap);
247 }
248