2.5: Curve edit mode add vertex and add menus now work. Also
[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., 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_object_types.h"
35 #include "DNA_scene_types.h"
36 #include "DNA_screen_types.h"
37 #include "DNA_space_types.h"
38 #include "DNA_userdef_types.h"
39 #include "DNA_view3d_types.h"
40 #include "DNA_windowmanager_types.h"
41
42 #include "BLI_arithb.h"
43 #include "BLI_blenlib.h"
44
45 #include "BKE_context.h"
46 #include "BKE_global.h"
47 #include "BKE_utildefines.h"
48
49 #include "RNA_access.h"
50 #include "RNA_define.h"
51
52 #include "WM_api.h"
53 #include "WM_types.h"
54
55 #include "ED_screen.h"
56 #include "ED_object.h"
57
58 #include "BIF_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         uiMenuItem *head;
70
71         head= uiPupMenuBegin("Specials", 0);
72         uiMenuItemO(head, 0, "CURVE_OT_subdivide");
73         uiMenuItemO(head, 0, "CURVE_OT_switch_direction");
74         uiMenuItemO(head, 0, "CURVE_OT_set_weight");
75         uiMenuItemO(head, 0, "CURVE_OT_set_radius");
76         uiMenuItemO(head, 0, "CURVE_OT_smooth");
77         uiMenuItemO(head, 0, "CURVE_OT_smooth_radius");
78         uiPupMenuEnd(C, head);
79
80         return OPERATOR_CANCELLED;
81 }
82
83 void CURVE_OT_specials_menu(wmOperatorType *ot)
84 {
85         /* identifiers */
86         ot->name= "Specials Menu";
87         ot->idname= "CURVE_OT_specials_menu";
88         
89         /* api clastbacks */
90         ot->invoke= specials_menu_invoke;
91         ot->poll= ED_operator_editsurfcurve;
92 }
93
94 /************************* registration ****************************/
95
96 void ED_operatortypes_curve(void)
97 {
98         WM_operatortype_append(FONT_OT_textedit);
99
100         WM_operatortype_append(CURVE_OT_hide);
101         WM_operatortype_append(CURVE_OT_reveal);
102
103         WM_operatortype_append(CURVE_OT_separate);
104         WM_operatortype_append(CURVE_OT_duplicate);
105         WM_operatortype_append(CURVE_OT_delete);
106
107         WM_operatortype_append(CURVE_OT_set_weight);
108         WM_operatortype_append(CURVE_OT_set_radius);
109         WM_operatortype_append(CURVE_OT_set_spline_type);
110         WM_operatortype_append(CURVE_OT_set_handle_type);
111         WM_operatortype_append(CURVE_OT_set_smooth);
112         WM_operatortype_append(CURVE_OT_clear_tilt);
113
114         WM_operatortype_append(CURVE_OT_smooth);
115         WM_operatortype_append(CURVE_OT_smooth_radius);
116
117         WM_operatortype_append(CURVE_OT_de_select_first);
118         WM_operatortype_append(CURVE_OT_de_select_last);
119         WM_operatortype_append(CURVE_OT_de_select_all);
120         WM_operatortype_append(CURVE_OT_select_inverse);
121         WM_operatortype_append(CURVE_OT_select_linked);
122         WM_operatortype_append(CURVE_OT_select_row);
123         WM_operatortype_append(CURVE_OT_select_next);
124         WM_operatortype_append(CURVE_OT_select_previous);
125         WM_operatortype_append(CURVE_OT_select_more);
126         WM_operatortype_append(CURVE_OT_select_less);
127         WM_operatortype_append(CURVE_OT_select_random);
128         WM_operatortype_append(CURVE_OT_select_every_nth);
129
130         WM_operatortype_append(CURVE_OT_switch_direction);
131         WM_operatortype_append(CURVE_OT_subdivide);
132         WM_operatortype_append(CURVE_OT_make_segment);
133         WM_operatortype_append(CURVE_OT_spin);
134         WM_operatortype_append(CURVE_OT_add_vertex);
135         WM_operatortype_append(CURVE_OT_extrude);
136         WM_operatortype_append(CURVE_OT_toggle_cyclic);
137
138         WM_operatortype_append(CURVE_OT_specials_menu);
139 }
140
141 void ED_keymap_curve(wmWindowManager *wm)
142 {
143         ListBase *keymap= WM_keymap_listbase(wm, "Font", 0, 0);
144         
145         /* only set in editmode font, by space_view3d listener */
146         WM_keymap_add_item(keymap, "FONT_OT_textedit", KM_TEXTINPUT, KM_ANY, KM_ANY, 0);
147
148         /* only set in editmode curve, by space_view3d listener */
149         keymap= WM_keymap_listbase(wm, "Curve", 0, 0);
150         
151         WM_keymap_add_item(keymap, "OBJECT_OT_curve_add", AKEY, KM_PRESS, KM_SHIFT, 0);
152         WM_keymap_add_item(keymap, "CURVE_OT_add_vertex", ACTIONMOUSE, KM_PRESS, KM_CTRL, 0);
153
154         WM_keymap_add_item(keymap, "CURVE_OT_de_select_all", AKEY, KM_PRESS, 0, 0);
155         WM_keymap_add_item(keymap, "CURVE_OT_select_row", RKEY, KM_PRESS, KM_SHIFT, 0);
156         WM_keymap_add_item(keymap, "CURVE_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
157         WM_keymap_add_item(keymap, "CURVE_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0);
158         WM_keymap_add_item(keymap, "CURVE_OT_select_linked", LKEY, KM_PRESS, 0, 0);
159         RNA_boolean_set(WM_keymap_add_item(keymap, "CURVE_OT_select_linked", LKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "deselect", 1);
160
161         WM_keymap_add_item(keymap, "CURVE_OT_separate", PKEY, KM_PRESS, 0, 0);
162         WM_keymap_add_item(keymap, "CURVE_OT_extrude", EKEY, KM_PRESS, 0, 0);
163         WM_keymap_add_item(keymap, "CURVE_OT_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);
164         WM_keymap_add_item(keymap, "CURVE_OT_make_segment", FKEY, KM_PRESS, 0, 0);
165         WM_keymap_add_item(keymap, "CURVE_OT_toggle_cyclic", CKEY, KM_PRESS, 0, 0);
166         WM_keymap_add_item(keymap, "CURVE_OT_delete", XKEY, KM_PRESS, 0, 0);
167         WM_keymap_add_item(keymap, "CURVE_OT_delete", DELKEY, KM_PRESS, 0, 0);
168
169         WM_keymap_add_item(keymap, "CURVE_OT_clear_tilt", TKEY, KM_PRESS, KM_ALT, 0);
170         RNA_enum_set(WM_keymap_add_item(keymap, "TFM_OT_transform", TKEY, KM_PRESS, 0, 0)->ptr, "mode", TFM_TILT);
171         RNA_enum_set(WM_keymap_add_item(keymap, "CURVE_OT_set_handle_type", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", 1);
172         RNA_enum_set(WM_keymap_add_item(keymap, "CURVE_OT_set_handle_type", HKEY, KM_PRESS, 0, 0)->ptr, "type", 3);
173         RNA_enum_set(WM_keymap_add_item(keymap, "CURVE_OT_set_handle_type", VKEY, KM_PRESS, 0, 0)->ptr, "type", 2);
174
175         WM_keymap_add_item(keymap, "CURVE_OT_reveal", HKEY, KM_PRESS, KM_ALT, 0);
176         WM_keymap_add_item(keymap, "CURVE_OT_hide", HKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
177         RNA_enum_set(WM_keymap_add_item(keymap, "CURVE_OT_hide", HKEY, KM_PRESS, KM_ALT|KM_SHIFT, 0)->ptr, "deselected", 1);
178
179         WM_keymap_add_item(keymap, "CURVE_OT_specials_menu", WKEY, KM_PRESS, 0, 0);
180 }
181