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