(no commit message)
[blender.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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
36 #include "BLI_math.h"
37 #include "BLI_blenlib.h"
38
39 #include "BKE_context.h"
40 #include "BKE_global.h"
41 #include "BKE_utildefines.h"
42
43 #include "RNA_access.h"
44
45 #include "WM_api.h"
46 #include "WM_types.h"
47
48 #include "ED_object.h"
49 #include "ED_screen.h"
50 #include "ED_transform.h"
51
52
53 #include "curve_intern.h"
54
55
56 /************************* registration ****************************/
57
58 void ED_operatortypes_curve(void)
59 {
60         WM_operatortype_append(FONT_OT_text_insert);
61         WM_operatortype_append(FONT_OT_line_break);
62         WM_operatortype_append(FONT_OT_insert_lorem);
63
64         WM_operatortype_append(FONT_OT_case_toggle);
65         WM_operatortype_append(FONT_OT_case_set);
66         WM_operatortype_append(FONT_OT_style_toggle);
67         WM_operatortype_append(FONT_OT_style_set);
68
69         WM_operatortype_append(FONT_OT_text_copy);
70         WM_operatortype_append(FONT_OT_text_cut);
71         WM_operatortype_append(FONT_OT_text_paste);
72         WM_operatortype_append(FONT_OT_file_paste);
73         WM_operatortype_append(FONT_OT_buffer_paste);
74
75         WM_operatortype_append(FONT_OT_move);
76         WM_operatortype_append(FONT_OT_move_select);
77         WM_operatortype_append(FONT_OT_delete);
78
79         WM_operatortype_append(FONT_OT_change_character);
80         WM_operatortype_append(FONT_OT_change_spacing);
81         
82         WM_operatortype_append(FONT_OT_open);
83         WM_operatortype_append(FONT_OT_unlink);
84
85         WM_operatortype_append(CURVE_OT_hide);
86         WM_operatortype_append(CURVE_OT_reveal);
87
88         WM_operatortype_append(CURVE_OT_separate);
89         WM_operatortype_append(CURVE_OT_duplicate);
90         WM_operatortype_append(CURVE_OT_delete);
91
92         WM_operatortype_append(CURVE_OT_spline_type_set);
93         WM_operatortype_append(CURVE_OT_radius_set);
94         WM_operatortype_append(CURVE_OT_spline_weight_set);
95         WM_operatortype_append(CURVE_OT_handle_type_set);
96         WM_operatortype_append(CURVE_OT_shade_smooth);
97         WM_operatortype_append(CURVE_OT_shade_flat);
98         WM_operatortype_append(CURVE_OT_tilt_clear);
99         
100         WM_operatortype_append(CURVE_OT_primitive_bezier_add);
101         WM_operatortype_append(CURVE_OT_primitive_bezier_circle_add);
102         WM_operatortype_append(CURVE_OT_primitive_nurbs_curve_add);
103         WM_operatortype_append(CURVE_OT_primitive_nurbs_circle_add);
104         WM_operatortype_append(CURVE_OT_primitive_curve_path_add);
105
106         WM_operatortype_append(CURVE_OT_smooth);
107         WM_operatortype_append(CURVE_OT_smooth_radius);
108
109         WM_operatortype_append(CURVE_OT_de_select_first);
110         WM_operatortype_append(CURVE_OT_de_select_last);
111         WM_operatortype_append(CURVE_OT_select_all);
112         WM_operatortype_append(CURVE_OT_select_inverse);
113         WM_operatortype_append(CURVE_OT_select_linked);
114         WM_operatortype_append(CURVE_OT_select_row);
115         WM_operatortype_append(CURVE_OT_select_next);
116         WM_operatortype_append(CURVE_OT_select_previous);
117         WM_operatortype_append(CURVE_OT_select_more);
118         WM_operatortype_append(CURVE_OT_select_less);
119         WM_operatortype_append(CURVE_OT_select_random);
120         WM_operatortype_append(CURVE_OT_select_nth);
121
122         WM_operatortype_append(CURVE_OT_switch_direction);
123         WM_operatortype_append(CURVE_OT_subdivide);
124         WM_operatortype_append(CURVE_OT_make_segment);
125         WM_operatortype_append(CURVE_OT_spin);
126         WM_operatortype_append(CURVE_OT_vertex_add);
127         WM_operatortype_append(CURVE_OT_extrude);
128         WM_operatortype_append(CURVE_OT_cyclic_toggle);
129 }
130
131 void ED_keymap_curve(wmKeyConfig *keyconf)
132 {
133         wmKeyMap *keymap;
134 //      wmKeyMapItem *kmi;
135         
136         keymap= WM_keymap_find(keyconf, "Font", 0, 0);
137         keymap->poll= ED_operator_editfont;
138         
139         /* only set in editmode font, by space_view3d listener */
140         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_style_toggle", BKEY, KM_PRESS, KM_CTRL, 0)->ptr, "style", CU_BOLD);
141         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_style_toggle", IKEY, KM_PRESS, KM_CTRL, 0)->ptr, "style", CU_ITALIC);
142         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_style_toggle", UKEY, KM_PRESS, KM_CTRL, 0)->ptr, "style", CU_UNDERLINE);
143
144         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_delete", DELKEY, KM_PRESS, 0, 0)->ptr, "type", DEL_NEXT_SEL);
145         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_delete", BACKSPACEKEY, KM_PRESS, 0, 0)->ptr, "type", DEL_PREV_SEL);
146         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_delete", BACKSPACEKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", DEL_ALL);
147
148         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move", HOMEKEY, KM_PRESS, 0, 0)->ptr, "type", LINE_BEGIN);
149         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move", ENDKEY, KM_PRESS, 0, 0)->ptr, "type", LINE_END);
150         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move", LEFTARROWKEY, KM_PRESS, 0, 0)->ptr, "type", PREV_CHAR);
151         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move", RIGHTARROWKEY, KM_PRESS, 0, 0)->ptr, "type", NEXT_CHAR);
152         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move", LEFTARROWKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", PREV_WORD);
153         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move", RIGHTARROWKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", NEXT_WORD);
154         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move", UPARROWKEY, KM_PRESS, 0, 0)->ptr, "type", PREV_LINE);
155         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move", DOWNARROWKEY, KM_PRESS, 0, 0)->ptr, "type", NEXT_LINE);
156         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move", PAGEUPKEY, KM_PRESS, 0, 0)->ptr, "type", PREV_PAGE);
157         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move", PAGEDOWNKEY, KM_PRESS, 0, 0)->ptr, "type", NEXT_PAGE);
158
159         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move_select", HOMEKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", LINE_BEGIN);
160         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move_select", ENDKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", LINE_END);
161         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move_select", LEFTARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", PREV_CHAR);
162         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move_select", RIGHTARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", NEXT_CHAR);
163         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move_select", LEFTARROWKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0)->ptr, "type", PREV_WORD);
164         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move_select", RIGHTARROWKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0)->ptr, "type", NEXT_WORD);
165         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move_select", UPARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", PREV_LINE);
166         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move_select", DOWNARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", NEXT_LINE);
167         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move_select", PAGEUPKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", PREV_PAGE);
168         RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move_select", PAGEDOWNKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", NEXT_PAGE);
169
170         RNA_int_set(WM_keymap_add_item(keymap, "FONT_OT_change_spacing", LEFTARROWKEY, KM_PRESS, KM_ALT, 0)->ptr, "delta", -1);
171         RNA_int_set(WM_keymap_add_item(keymap, "FONT_OT_change_spacing", RIGHTARROWKEY, KM_PRESS, KM_ALT, 0)->ptr, "delta", 1);
172         RNA_int_set(WM_keymap_add_item(keymap, "FONT_OT_change_character", UPARROWKEY, KM_PRESS, KM_ALT, 0)->ptr, "delta", 1);
173         RNA_int_set(WM_keymap_add_item(keymap, "FONT_OT_change_character", DOWNARROWKEY, KM_PRESS, KM_ALT, 0)->ptr, "delta", -1);
174
175         WM_keymap_add_item(keymap, "FONT_OT_text_copy", CKEY, KM_PRESS, KM_CTRL, 0);
176         WM_keymap_add_item(keymap, "FONT_OT_text_copy", CKEY, KM_PRESS, KM_OSKEY, 0);
177         WM_keymap_add_item(keymap, "FONT_OT_text_cut", XKEY, KM_PRESS, KM_CTRL, 0);
178         WM_keymap_add_item(keymap, "FONT_OT_text_cut", XKEY, KM_PRESS, KM_OSKEY, 0);
179         WM_keymap_add_item(keymap, "FONT_OT_text_paste", VKEY, KM_PRESS, KM_CTRL, 0);
180         WM_keymap_add_item(keymap, "FONT_OT_text_paste", VKEY, KM_PRESS, KM_OSKEY, 0);
181
182         WM_keymap_add_item(keymap, "FONT_OT_line_break", RETKEY, KM_PRESS, 0, 0);
183         WM_keymap_add_item(keymap, "FONT_OT_text_insert", KM_TEXTINPUT, KM_ANY, KM_ANY, 0); // last!
184
185         /* only set in editmode curve, by space_view3d listener */
186         keymap= WM_keymap_find(keyconf, "Curve", 0, 0);
187         keymap->poll= ED_operator_editsurfcurve;
188         
189         WM_keymap_add_item(keymap, "OBJECT_OT_curve_add", AKEY, KM_PRESS, KM_SHIFT, 0);
190         WM_keymap_add_item(keymap, "CURVE_OT_vertex_add", LEFTMOUSE, KM_CLICK, KM_CTRL, 0);
191
192         WM_keymap_add_item(keymap, "CURVE_OT_select_all", AKEY, KM_PRESS, 0, 0);
193         WM_keymap_add_item(keymap, "CURVE_OT_select_row", RKEY, KM_PRESS, KM_SHIFT, 0);
194         WM_keymap_add_item(keymap, "CURVE_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
195         WM_keymap_add_item(keymap, "CURVE_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0);
196         WM_keymap_add_item(keymap, "CURVE_OT_select_linked", LKEY, KM_PRESS, 0, 0);
197         RNA_boolean_set(WM_keymap_add_item(keymap, "CURVE_OT_select_linked", LKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "deselect", 1);
198
199         WM_keymap_add_item(keymap, "CURVE_OT_separate", PKEY, KM_PRESS, 0, 0);
200         WM_keymap_add_item(keymap, "CURVE_OT_extrude", EKEY, KM_PRESS, 0, 0);
201         WM_keymap_add_item(keymap, "CURVE_OT_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);
202         WM_keymap_add_item(keymap, "CURVE_OT_make_segment", FKEY, KM_PRESS, 0, 0);
203         WM_keymap_add_item(keymap, "CURVE_OT_cyclic_toggle", CKEY, KM_PRESS, KM_ALT, 0);
204         WM_keymap_add_item(keymap, "CURVE_OT_delete", XKEY, KM_PRESS, 0, 0);
205         WM_keymap_add_item(keymap, "CURVE_OT_delete", DELKEY, KM_PRESS, 0, 0);
206         WM_keymap_add_item(keymap, "CURVE_OT_delete", BACKSPACEKEY, KM_PRESS, 0, 0);
207
208         WM_keymap_add_item(keymap, "CURVE_OT_tilt_clear", TKEY, KM_PRESS, KM_ALT, 0);
209         WM_keymap_add_item(keymap, "TRANSFORM_OT_tilt", TKEY, KM_PRESS, KM_CTRL, 0);
210         RNA_enum_set(WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, KM_ALT, 0)->ptr, "mode", TFM_CURVE_SHRINKFATTEN);
211         RNA_enum_set(WM_keymap_add_item(keymap, "CURVE_OT_handle_type_set", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", 1);
212         RNA_enum_set(WM_keymap_add_item(keymap, "CURVE_OT_handle_type_set", HKEY, KM_PRESS, 0, 0)->ptr, "type", 3);
213         RNA_enum_set(WM_keymap_add_item(keymap, "CURVE_OT_handle_type_set", VKEY, KM_PRESS, 0, 0)->ptr, "type", 2);
214
215         WM_keymap_add_item(keymap, "CURVE_OT_reveal", HKEY, KM_PRESS, KM_ALT, 0);
216         WM_keymap_add_item(keymap, "CURVE_OT_hide", HKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
217         RNA_enum_set(WM_keymap_add_item(keymap, "CURVE_OT_hide", HKEY, KM_PRESS, KM_ALT|KM_SHIFT, 0)->ptr, "unselected", 1);
218
219         WM_keymap_add_item(keymap, "OBJECT_OT_vertex_parent_set", PKEY, KM_PRESS, KM_CTRL, 0);
220         
221         WM_keymap_add_menu(keymap, "VIEW3D_MT_edit_curve_specials", WKEY, KM_PRESS, 0, 0);
222
223         /* menus */
224         WM_keymap_add_menu(keymap, "VIEW3D_MT_hook", HKEY, KM_PRESS, KM_CTRL, 0);
225
226         ED_object_generic_keymap(keyconf, keymap, 2);
227 }
228