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