Changes to functions from blender/windowmanager/intern/wm_event_system.c
[blender.git] / source / blender / editors / mesh / mesh_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 #include "BLI_editVert.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_screen.h"
57 #include "ED_mesh.h"
58 #include "ED_view3d.h"
59
60 #include "BIF_transform.h"
61
62 #include "mesh_intern.h"
63
64
65 static int mesh_add_duplicate_exec(bContext *C, wmOperator *op)
66 {
67         Object *ob= CTX_data_edit_object(C);
68         EditMesh *em= ((Mesh *)ob->data)->edit_mesh;
69
70         adduplicateflag(em, SELECT);
71         
72         return OPERATOR_FINISHED;
73 }
74
75 static int mesh_add_duplicate_invoke(bContext *C, wmOperator *op, wmEvent *event)
76 {
77         mesh_add_duplicate_exec(C, op);
78         RNA_int_set(op->ptr, "mode", TFM_TRANSLATION);
79         WM_operator_name_call(C, "TFM_OT_transform", WM_OP_INVOKE_REGION_WIN, op->ptr);
80         
81         return OPERATOR_FINISHED;
82 }
83
84 static void MESH_OT_add_duplicate(wmOperatorType *ot)
85 {
86         
87         /* identifiers */
88         ot->name= "Add Duplicate";
89         ot->idname= "MESH_OT_add_duplicate";
90         
91         /* api callbacks */
92         ot->invoke= mesh_add_duplicate_invoke;
93         ot->exec= mesh_add_duplicate_exec;
94         
95         ot->poll= ED_operator_editmesh;
96         
97         /* to give to transform */
98         RNA_def_int(ot->srna, "mode", TFM_TRANSLATION, 0, INT_MAX, "Mode", "", 0, INT_MAX);
99 }
100
101
102 /* ************************** registration **********************************/
103
104 void ED_operatortypes_mesh(void)
105 {
106         WM_operatortype_append(MESH_OT_de_select_all);
107         WM_operatortype_append(MESH_OT_select_more);
108         WM_operatortype_append(MESH_OT_select_less);
109         WM_operatortype_append(MESH_OT_selectswap_mesh);
110         WM_operatortype_append(MESH_OT_select_non_manifold);
111         WM_operatortype_append(MESH_OT_selectconnected_mesh_all);
112         WM_operatortype_append(MESH_OT_selectconnected_mesh);
113         WM_operatortype_append(MESH_OT_hide_mesh);
114         WM_operatortype_append(MESH_OT_reveal_mesh);
115         WM_operatortype_append(MESH_OT_righthandfaces);
116         WM_operatortype_append(MESH_OT_subdivide);
117         WM_operatortype_append(MESH_OT_subdivide_multi);
118         WM_operatortype_append(MESH_OT_subdivide_multi_fractal);
119         WM_operatortype_append(MESH_OT_subdivide_smooth);
120         WM_operatortype_append(MESH_OT_select_linked_flat_faces);
121         WM_operatortype_append(MESH_OT_select_sharp_edges);
122         WM_operatortype_append(MESH_OT_add_primitive_plane);
123         WM_operatortype_append(MESH_OT_add_primitive_cube);
124         WM_operatortype_append(MESH_OT_add_primitive_circle);
125         WM_operatortype_append(MESH_OT_add_primitive_cylinder);
126         WM_operatortype_append(MESH_OT_add_primitive_tube);
127         WM_operatortype_append(MESH_OT_add_primitive_cone);
128         WM_operatortype_append(MESH_OT_add_primitive_grid);
129         WM_operatortype_append(MESH_OT_add_primitive_monkey);
130         WM_operatortype_append(MESH_OT_add_primitive_uv_sphere);
131         WM_operatortype_append(MESH_OT_add_primitive_ico_sphere);
132         WM_operatortype_append(MESH_OT_add_duplicate);
133
134 }
135
136 /* note mesh keymap also for other space? */
137 void ED_keymap_mesh(wmWindowManager *wm)
138 {       
139         ListBase *keymap= WM_keymap_listbase(wm, "EditMesh", 0, 0);
140         
141         /* selecting */
142         WM_keymap_add_item(keymap, "MESH_OT_de_select_all", AKEY, KM_PRESS, 0, 0);
143         WM_keymap_add_item(keymap, "MESH_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
144         WM_keymap_add_item(keymap, "MESH_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0);
145         WM_keymap_add_item(keymap, "MESH_OT_selectswap_mesh", IKEY, KM_PRESS, KM_CTRL, 0);
146         WM_keymap_add_item(keymap, "MESH_OT_select_non_manifold", MKEY, KM_PRESS, (KM_CTRL|KM_SHIFT|KM_ALT), 0);
147         
148         WM_keymap_add_item(keymap, "MESH_OT_selectconnected_mesh_all", LKEY, KM_PRESS, KM_CTRL, 0);
149         WM_keymap_add_item(keymap, "MESH_OT_selectconnected_mesh", LKEY, KM_PRESS, 0, 0);
150         RNA_boolean_set(WM_keymap_add_item(keymap, "MESH_OT_selectconnected_mesh", LKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "deselect", 1);
151         
152         RNA_float_set(WM_keymap_add_item(keymap, "MESH_OT_select_linked_flat_faces", FKEY, KM_PRESS, (KM_CTRL|KM_SHIFT|KM_ALT), 0)->ptr,"sharpness",135.0);
153         RNA_float_set(WM_keymap_add_item(keymap, "MESH_OT_select_sharp_edges", SKEY, KM_PRESS, (KM_CTRL|KM_SHIFT|KM_ALT), 0)->ptr,"sharpness",135.0);           
154         
155         /* hide */
156         WM_keymap_add_item(keymap, "MESH_OT_hide_mesh", HKEY, KM_PRESS, 0, 0);
157         RNA_boolean_set(WM_keymap_add_item(keymap, "MESH_OT_hide_mesh", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "swap", 1);
158         WM_keymap_add_item(keymap, "MESH_OT_reveal_mesh", HKEY, KM_PRESS, KM_ALT, 0);
159         
160         /* tools */
161         RNA_int_set(WM_keymap_add_item(keymap, "MESH_OT_righthandfaces", NKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "select", 2);
162         RNA_int_set(WM_keymap_add_item(keymap, "MESH_OT_righthandfaces", NKEY, KM_PRESS, KM_CTRL, 0)->ptr, "select", 1);
163         
164         WM_keymap_add_item(keymap, "MESH_OT_subdivide", WKEY, KM_PRESS, 0, 0);
165         WM_keymap_add_item(keymap, "MESH_OT_subdivide_multi", WKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
166         WM_keymap_add_item(keymap, "MESH_OT_subdivide_multi_fractal", WKEY, KM_PRESS, KM_ALT, 0);
167         WM_keymap_add_item(keymap, "MESH_OT_subdivide_smooth", WKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
168
169         /* add */
170         WM_keymap_add_item(keymap, "MESH_OT_add_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);
171         WM_keymap_add_item(keymap, "MESH_OT_add_primitive_plane", ZEROKEY, KM_PRESS, KM_CTRL, 0);
172         WM_keymap_add_item(keymap, "MESH_OT_add_primitive_cube", ONEKEY, KM_PRESS, KM_CTRL, 0);
173         WM_keymap_add_item(keymap, "MESH_OT_add_primitive_circle", TWOKEY, KM_PRESS, KM_CTRL, 0);
174         WM_keymap_add_item(keymap, "MESH_OT_add_primitive_cylinder", THREEKEY, KM_PRESS, KM_CTRL, 0);
175         WM_keymap_add_item(keymap, "MESH_OT_add_primitive_tube", FOURKEY, KM_PRESS, KM_CTRL, 0);
176         WM_keymap_add_item(keymap, "MESH_OT_add_primitive_cone", FIVEKEY, KM_PRESS, KM_CTRL, 0);
177         WM_keymap_add_item(keymap, "MESH_OT_add_primitive_grid", SIXKEY, KM_PRESS, KM_CTRL, 0);
178         WM_keymap_add_item(keymap, "MESH_OT_add_primitive_uv_sphere", SEVENKEY, KM_PRESS, KM_CTRL, 0);
179         WM_keymap_add_item(keymap, "MESH_OT_add_primitive_ico_sphere", EIGHTKEY, KM_PRESS, KM_CTRL, 0);
180         WM_keymap_add_item(keymap, "MESH_OT_add_primitive_monkey", NINEKEY, KM_PRESS, KM_CTRL, 0);
181 }
182