be52952b474576997181640eceff135bdd2448a6
[blender-staging.git] / source / blender / editors / curve / curve_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.
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_curve_types.h"
35 #include "DNA_object_types.h"
36 #include "DNA_scene_types.h"
37 #include "DNA_screen_types.h"
38 #include "DNA_space_types.h"
39 #include "DNA_userdef_types.h"
40 #include "DNA_view3d_types.h"
41 #include "DNA_windowmanager_types.h"
42
43 #include "BLI_math.h"
44 #include "BLI_blenlib.h"
45
46 #include "BKE_context.h"
47 #include "BKE_global.h"
48 #include "BKE_utildefines.h"
49
50 #include "RNA_access.h"
51 #include "RNA_define.h"
52
53 #include "WM_api.h"
54 #include "WM_types.h"
55
56 #include "ED_object.h"
57 #include "ED_screen.h"
58 #include "ED_transform.h"
59
60 #include "UI_interface.h"
61
62 #include "curve_intern.h"
63
64
65 /**************************** menus *****************************/
66
67 static int specials_menu_invoke(bContext *C, wmOperator *op, wmEvent *event)
68 {
69         uiPopupMenu *pup;
70         uiLayout *layout;
71
72         pup= uiPupMenuBegin(C, "Specials", 0);
73         layout= uiPupMenuLayout(pup);
74         uiItemO(layout, NULL, 0, "CURVE_OT_subdivide");
75         uiItemO(layout, NULL, 0, "CURVE_OT_switch_direction");
76         uiItemO(layout, NULL, 0, "CURVE_OT_spline_weight_set");
77         uiItemO(layout, NULL, 0, "CURVE_OT_radius_set");
78         uiItemO(layout, NULL, 0, "CURVE_OT_smooth");
79         uiItemO(layout, NULL, 0, "CURVE_OT_smooth_radius");
80         uiPupMenuEnd(C, pup);
81
82         return OPERATOR_CANCELLED;
83 }
84
85 void CURVE_OT_specials_menu(wmOperatorType *ot)
86 {
87         /* identifiers */
88         ot->name= "Specials Menu";
89         ot->idname= "CURVE_OT_specials_menu";
90         
91         /* api clastbacks */
92         ot->invoke= specials_menu_invoke;
93         ot->poll= ED_operator_editsurfcurve;
94 }
95
96 /************************* registration ****************************/
97
98 void ED_operatortypes_curve(void)
99 {
100         WM_operatortype_append(FONT_OT_text_insert);
101         WM_operatortype_append(FONT_OT_line_break);
102         WM_operatortype_append(FONT_OT_insert_lorem);
103
104         WM_operatortype_append(FONT_OT_case_toggle);
105         WM_operatortype_append(FONT_OT_case_set);
106         WM_operatortype_append(FONT_OT_style_toggle);
107         WM_operatortype_append(FONT_OT_style_set);
108
109         WM_operatortype_append(FONT_OT_text_copy);
110         WM_operatortype_append(FONT_OT_text_cut);
111         WM_operatortype_append(FONT_OT_text_paste);
112         WM_operatortype_append(FONT_OT_file_paste);
113         WM_operatortype_append(FONT_OT_buffer_paste);
114
115         WM_operatortype_append(FONT_OT_move);
116         WM_operatortype_append(FONT_OT_move_select);
117         WM_operatortype_append(FONT_OT_delete);
118
119         WM_operatortype_append(FONT_OT_change_character);
120         WM_operatortype_append(FONT_OT_change_spacing);
121
122         WM_operatortype_append(CURVE_OT_hide);
123         WM_operatortype_append(CURVE_OT_reveal);
124
125         WM_operatortype_append(CURVE_OT_separate);
126         WM_operatortype_append(CURVE_OT_duplicate);
127         WM_operatortype_append(CURVE_OT_delete);
128
129         WM_operatortype_append(CURVE_OT_spline_type_set);
130         WM_operatortype_append(CURVE_OT_radius_set);
131         WM_operatortype_append(CURVE_OT_spline_weight_set);
132         WM_operatortype_append(CURVE_OT_handle_type_set);
133         WM_operatortype_append(CURVE_OT_shade_smooth);
134         WM_operatortype_append(CURVE_OT_shade_flat);
135         WM_operatortype_append(CURVE_OT_tilt_clear);
136
137         WM_operatortype_append(CURVE_OT_smooth);
138         WM_operatortype_append(CURVE_OT_smooth_radius);
139
140         WM_operatortype_append(CURVE_OT_de_select_first);
141         WM_operatortype_append(CURVE_OT_de_select_last);
142         WM_operatortype_append(CURVE_OT_select_all);
143         WM_operatortype_append(CURVE_OT_select_inverse);
144         WM_operatortype_append(CURVE_OT_select_linked);
145         WM_operatortype_append(CURVE_OT_select_row);
146         WM_operatortype_append(CURVE_OT_select_next);
147         WM_operatortype_append(CURVE_OT_select_previous);
148         WM_operatortype_append(CURVE_OT_select_more);
149         WM_operatortype_append(CURVE_OT_select_less);
150         WM_operatortype_append(CURVE_OT_select_random);
151         WM_operatortype_append(CURVE_OT_select_every_nth);
152
153         WM_operatortype_append(CURVE_OT_switch_direction);
154         WM_operatortype_append(CURVE_OT_subdivide);
155         WM_operatortype_append(CURVE_OT_make_segment);
156         WM_operatortype_append(CURVE_OT_spin);
157         WM_operatortype_append(CURVE_OT_vertex_add);
158         WM_operatortype_append(CURVE_OT_extrude);
159         WM_operatortype_append(CURVE_OT_cyclic_toggle);
160
161         WM_operatortype_append(CURVE_OT_specials_menu);
162 }
163
164 void ED_keymap_curve(wmKeyConfig *keyconf)
165 {
166         wmKeyMap *keymap;
167 //      wmKeyMapItem *kmi;
168         
169         keymap= WM_keymap_find(keyconf, "Font", 0, 0);
170         keymap->poll= ED_operator_editfont;
171         
172         /* only set in editmode font, by space_view3d listener */
173         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_style_toggle", BKEY, KM_PRESS, KM_CTRL, 0)->ptr, "style", CU_BOLD);
174         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_style_toggle", IKEY, KM_PRESS, KM_CTRL, 0)->ptr, "style", CU_ITALIC);
175         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_style_toggle", UKEY, KM_PRESS, KM_CTRL, 0)->ptr, "style", CU_UNDERLINE);
176
177         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_delete", DELKEY, KM_PRESS, 0, 0)->ptr, "type", DEL_NEXT_SEL);
178         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_delete", BACKSPACEKEY, KM_PRESS, 0, 0)->ptr, "type", DEL_PREV_SEL);
179         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_delete", BACKSPACEKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", DEL_ALL);
180
181         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move", HOMEKEY, KM_PRESS, 0, 0)->ptr, "type", LINE_BEGIN);
182         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move", ENDKEY, KM_PRESS, 0, 0)->ptr, "type", LINE_END);
183         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move", LEFTARROWKEY, KM_PRESS, 0, 0)->ptr, "type", PREV_CHAR);
184         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move", RIGHTARROWKEY, KM_PRESS, 0, 0)->ptr, "type", NEXT_CHAR);
185         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move", LEFTARROWKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", PREV_WORD);
186         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move", RIGHTARROWKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", NEXT_WORD);
187         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move", UPARROWKEY, KM_PRESS, 0, 0)->ptr, "type", PREV_LINE);
188         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move", DOWNARROWKEY, KM_PRESS, 0, 0)->ptr, "type", NEXT_LINE);
189         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move", PAGEUPKEY, KM_PRESS, 0, 0)->ptr, "type", PREV_PAGE);
190         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move", PAGEDOWNKEY, KM_PRESS, 0, 0)->ptr, "type", NEXT_PAGE);
191
192         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move_select", HOMEKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", LINE_BEGIN);
193         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move_select", ENDKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", LINE_END);
194         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move_select", LEFTARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", PREV_CHAR);
195         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move_select", RIGHTARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", NEXT_CHAR);
196         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move_select", LEFTARROWKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0)->ptr, "type", PREV_WORD);
197         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move_select", RIGHTARROWKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0)->ptr, "type", NEXT_WORD);
198         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move_select", UPARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", PREV_LINE);
199         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move_select", DOWNARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", NEXT_LINE);
200         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move_select", PAGEUPKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", PREV_PAGE);
201         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move_select", PAGEDOWNKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", NEXT_PAGE);
202
203         RNA_int_set(WM_keymap_add_item(keymap, "FONT_OT_change_spacing", LEFTARROWKEY, KM_PRESS, KM_ALT, 0)->ptr, "delta", -1);
204         RNA_int_set(WM_keymap_add_item(keymap, "FONT_OT_change_spacing", RIGHTARROWKEY, KM_PRESS, KM_ALT, 0)->ptr, "delta", 1);
205         RNA_int_set(WM_keymap_add_item(keymap, "FONT_OT_change_character", UPARROWKEY, KM_PRESS, KM_ALT, 0)->ptr, "delta", 1);
206         RNA_int_set(WM_keymap_add_item(keymap, "FONT_OT_change_character", DOWNARROWKEY, KM_PRESS, KM_ALT, 0)->ptr, "delta", -1);
207
208         WM_keymap_add_item(keymap, "FONT_OT_text_copy", CKEY, KM_PRESS, KM_CTRL, 0);
209         WM_keymap_add_item(keymap, "FONT_OT_text_copy", CKEY, KM_PRESS, KM_OSKEY, 0);
210         WM_keymap_add_item(keymap, "FONT_OT_text_cut", XKEY, KM_PRESS, KM_CTRL, 0);
211         WM_keymap_add_item(keymap, "FONT_OT_text_cut", XKEY, KM_PRESS, KM_OSKEY, 0);
212         WM_keymap_add_item(keymap, "FONT_OT_text_paste", VKEY, KM_PRESS, KM_CTRL, 0);
213         WM_keymap_add_item(keymap, "FONT_OT_text_paste", VKEY, KM_PRESS, KM_OSKEY, 0);
214
215         WM_keymap_add_item(keymap, "FONT_OT_line_break", RETKEY, KM_PRESS, 0, 0);
216         WM_keymap_add_item(keymap, "FONT_OT_text_insert", KM_TEXTINPUT, KM_ANY, KM_ANY, 0); // last!
217
218         /* only set in editmode curve, by space_view3d listener */
219         keymap= WM_keymap_find(keyconf, "Curve", 0, 0);
220         keymap->poll= ED_operator_editsurfcurve;
221         
222         WM_keymap_add_item(keymap, "OBJECT_OT_curve_add", AKEY, KM_PRESS, KM_SHIFT, 0);
223         WM_keymap_add_item(keymap, "CURVE_OT_vertex_add", LEFTMOUSE, KM_CLICK, KM_CTRL, 0);
224
225         WM_keymap_add_item(keymap, "CURVE_OT_select_all", AKEY, KM_PRESS, 0, 0);
226         WM_keymap_add_item(keymap, "CURVE_OT_select_row", RKEY, KM_PRESS, KM_SHIFT, 0);
227         WM_keymap_add_item(keymap, "CURVE_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
228         WM_keymap_add_item(keymap, "CURVE_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0);
229         WM_keymap_add_item(keymap, "CURVE_OT_select_linked", LKEY, KM_PRESS, 0, 0);
230         RNA_boolean_set(WM_keymap_add_item(keymap, "CURVE_OT_select_linked", LKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "deselect", 1);
231
232         WM_keymap_add_item(keymap, "CURVE_OT_separate", PKEY, KM_PRESS, 0, 0);
233         WM_keymap_add_item(keymap, "CURVE_OT_extrude", EKEY, KM_PRESS, 0, 0);
234         WM_keymap_add_item(keymap, "CURVE_OT_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);
235         WM_keymap_add_item(keymap, "CURVE_OT_make_segment", FKEY, KM_PRESS, 0, 0);
236         WM_keymap_add_item(keymap, "CURVE_OT_cyclic_toggle", CKEY, KM_PRESS, 0, 0);
237         WM_keymap_add_item(keymap, "CURVE_OT_delete", XKEY, KM_PRESS, 0, 0);
238         WM_keymap_add_item(keymap, "CURVE_OT_delete", DELKEY, KM_PRESS, 0, 0);
239
240         WM_keymap_add_item(keymap, "CURVE_OT_tilt_clear", TKEY, KM_PRESS, KM_ALT, 0);
241         WM_keymap_add_item(keymap, "TRANSFORM_OT_tilt", TKEY, KM_PRESS, KM_CTRL, 0);
242         RNA_enum_set(WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, KM_ALT, 0)->ptr, "mode", TFM_CURVE_SHRINKFATTEN);
243         RNA_enum_set(WM_keymap_add_item(keymap, "CURVE_OT_handle_type_set", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", 1);
244         RNA_enum_set(WM_keymap_add_item(keymap, "CURVE_OT_handle_type_set", HKEY, KM_PRESS, 0, 0)->ptr, "type", 3);
245         RNA_enum_set(WM_keymap_add_item(keymap, "CURVE_OT_handle_type_set", VKEY, KM_PRESS, 0, 0)->ptr, "type", 2);
246
247         WM_keymap_add_item(keymap, "CURVE_OT_reveal", HKEY, KM_PRESS, KM_ALT, 0);
248         WM_keymap_add_item(keymap, "CURVE_OT_hide", HKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
249         RNA_enum_set(WM_keymap_add_item(keymap, "CURVE_OT_hide", HKEY, KM_PRESS, KM_ALT|KM_SHIFT, 0)->ptr, "unselected", 1);
250
251         WM_keymap_add_item(keymap, "CURVE_OT_specials_menu", WKEY, KM_PRESS, 0, 0);
252
253         /* menus */
254         WM_keymap_add_menu(keymap, "VIEW3D_MT_hook", HKEY, KM_PRESS, KM_CTRL, 0);
255
256         ED_object_generic_keymap(keyconf, keymap, TRUE);
257 }
258