2.5: Particle Edit, work in progress commit.
[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         WM_cursor_wait(1);
78         mesh_add_duplicate_exec(C, op);
79         WM_cursor_wait(0);
80         
81         RNA_int_set(op->ptr, "mode", TFM_TRANSLATION);
82         WM_operator_name_call(C, "TFM_OT_transform", WM_OP_INVOKE_REGION_WIN, op->ptr);
83         
84         return OPERATOR_FINISHED;
85 }
86
87 static void MESH_OT_add_duplicate(wmOperatorType *ot)
88 {
89         
90         /* identifiers */
91         ot->name= "Add Duplicate";
92         ot->idname= "MESH_OT_add_duplicate";
93         
94         /* api callbacks */
95         ot->invoke= mesh_add_duplicate_invoke;
96         ot->exec= mesh_add_duplicate_exec;
97         
98         ot->poll= ED_operator_editmesh;
99         
100         /* to give to transform */
101         RNA_def_int(ot->srna, "mode", TFM_TRANSLATION, 0, INT_MAX, "Mode", "", 0, INT_MAX);
102 }
103
104
105 /* ************************** registration **********************************/
106
107 void ED_operatortypes_mesh(void)
108 {
109         WM_operatortype_append(MESH_OT_de_select_all);
110         WM_operatortype_append(MESH_OT_select_more);
111         WM_operatortype_append(MESH_OT_select_less);
112         WM_operatortype_append(MESH_OT_select_invert);
113         WM_operatortype_append(MESH_OT_select_non_manifold);
114         WM_operatortype_append(MESH_OT_select_linked);
115         WM_operatortype_append(MESH_OT_select_linked_pick);
116         WM_operatortype_append(MESH_OT_select_random);
117         WM_operatortype_append(MESH_OT_selection_type);
118         WM_operatortype_append(MESH_OT_hide);
119         WM_operatortype_append(MESH_OT_reveal);
120         WM_operatortype_append(MESH_OT_consistant_normals);
121         WM_operatortype_append(MESH_OT_subdivide);
122         WM_operatortype_append(MESH_OT_subdivide_multi);
123         WM_operatortype_append(MESH_OT_subdivide_multi_fractal);
124         WM_operatortype_append(MESH_OT_subdivide_smooth);
125         WM_operatortype_append(MESH_OT_subdivs);
126         WM_operatortype_append(MESH_OT_select_linked_flat_faces);
127         WM_operatortype_append(MESH_OT_select_sharp_edges);
128         WM_operatortype_append(MESH_OT_add_primitive_plane);
129         WM_operatortype_append(MESH_OT_add_primitive_cube);
130         WM_operatortype_append(MESH_OT_add_primitive_circle);
131         WM_operatortype_append(MESH_OT_add_primitive_cylinder);
132         WM_operatortype_append(MESH_OT_add_primitive_tube);
133         WM_operatortype_append(MESH_OT_add_primitive_cone);
134         WM_operatortype_append(MESH_OT_add_primitive_grid);
135         WM_operatortype_append(MESH_OT_add_primitive_monkey);
136         WM_operatortype_append(MESH_OT_add_primitive_uv_sphere);
137         WM_operatortype_append(MESH_OT_add_primitive_ico_sphere);
138         WM_operatortype_append(MESH_OT_clear_fgon);
139         WM_operatortype_append(MESH_OT_make_fgon);
140         WM_operatortype_append(MESH_OT_add_duplicate);
141         WM_operatortype_append(MESH_OT_removedoublesflag);
142         WM_operatortype_append(MESH_OT_extrude);
143         WM_operatortype_append(MESH_OT_spin);
144         WM_operatortype_append(MESH_OT_screw);
145         
146         WM_operatortype_append(MESH_OT_vertices_to_sphere);
147         WM_operatortype_append(MESH_OT_split_mesh);
148         WM_operatortype_append(MESH_OT_extrude_repeat);
149         WM_operatortype_append(MESH_OT_edge_rotate_selected);
150         WM_operatortype_append(MESH_OT_loop_to_region);
151         WM_operatortype_append(MESH_OT_region_to_loop);
152         
153         WM_operatortype_append(MESH_OT_rotate_uvs);
154         WM_operatortype_append(MESH_OT_mirror_uvs);
155         WM_operatortype_append(MESH_OT_rotate_colors);
156         WM_operatortype_append(MESH_OT_mirror_colors);
157         
158         WM_operatortype_append(MESH_OT_fill);
159         WM_operatortype_append(MESH_OT_beauty_fill);
160         WM_operatortype_append(MESH_OT_convert_quads_to_tris);
161         WM_operatortype_append(MESH_OT_convert_tris_to_quads);
162         WM_operatortype_append(MESH_OT_edge_flip);
163         WM_operatortype_append(MESH_OT_faces_shade_smooth);
164         WM_operatortype_append(MESH_OT_faces_shade_solid);
165
166         WM_operatortype_append(MESH_OT_delete);
167
168         WM_operatortype_append(MESH_OT_separate);
169         WM_operatortype_append(MESH_OT_dupli_extrude_cursor);
170         WM_operatortype_append(MESH_OT_loop_select);
171         WM_operatortype_append(MESH_OT_add_edge_face);
172         WM_operatortype_append(MESH_OT_shortest_path_select);
173         WM_operatortype_append(MESH_OT_similar_vertex_select);
174         WM_operatortype_append(MESH_OT_similar_edge_select);
175         WM_operatortype_append(MESH_OT_similar_face_select);
176         WM_operatortype_append(MESH_OT_select_multi_loop);
177         WM_operatortype_append(MESH_OT_mark_seam);
178         WM_operatortype_append(MESH_OT_mark_sharp);
179         WM_operatortype_append(MESH_OT_smooth_vertex);
180         WM_operatortype_append(MESH_OT_flip_editnormals);
181         WM_operatortype_append(MESH_OT_knife_cut);
182         WM_operatortype_append(MESH_OT_rip);
183         
184 }
185
186 /* note mesh keymap also for other space? */
187 void ED_keymap_mesh(wmWindowManager *wm)
188 {       
189         ListBase *keymap= WM_keymap_listbase(wm, "EditMesh", 0, 0);
190         wmKeymapItem *kmi;
191         
192         /* selecting */
193         /* standard mouse selection goes via space_view3d */
194         WM_keymap_add_item(keymap, "MESH_OT_loop_select", SELECTMOUSE, KM_PRESS, KM_ALT, 0);
195         kmi= WM_keymap_add_item(keymap, "MESH_OT_loop_select", SELECTMOUSE, KM_PRESS, KM_SHIFT|KM_ALT, 0);
196         RNA_boolean_set(kmi->ptr, "extend", 1);
197         kmi= WM_keymap_add_item(keymap, "MESH_OT_loop_select", SELECTMOUSE, KM_PRESS, KM_ALT|KM_CTRL, 0);
198         RNA_boolean_set(kmi->ptr, "ring", 1);
199         kmi= WM_keymap_add_item(keymap, "MESH_OT_loop_select", SELECTMOUSE, KM_PRESS, KM_SHIFT|KM_ALT|KM_CTRL, 0);
200         RNA_boolean_set(kmi->ptr, "extend", 1);
201         RNA_boolean_set(kmi->ptr, "ring", 1);
202
203         WM_keymap_add_item(keymap, "MESH_OT_shortest_path_select", SELECTMOUSE, KM_PRESS, KM_CTRL, 0);
204         
205         WM_keymap_add_item(keymap, "MESH_OT_de_select_all", AKEY, KM_PRESS, 0, 0);
206         WM_keymap_add_item(keymap, "MESH_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
207         WM_keymap_add_item(keymap, "MESH_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0);
208         WM_keymap_add_item(keymap, "MESH_OT_select_invert", IKEY, KM_PRESS, KM_CTRL, 0);
209         WM_keymap_add_item(keymap, "MESH_OT_select_non_manifold", MKEY, KM_PRESS, (KM_CTRL|KM_SHIFT|KM_ALT), 0);
210         
211         WM_keymap_add_item(keymap, "MESH_OT_select_linked", LKEY, KM_PRESS, KM_CTRL, 0);
212         WM_keymap_add_item(keymap, "MESH_OT_select_linked_pick", LKEY, KM_PRESS, 0, 0);
213         RNA_boolean_set(WM_keymap_add_item(keymap, "MESH_OT_select_linked_pick", LKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "deselect", 1);
214         
215         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);
216         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);
217         
218         WM_keymap_add_item(keymap, "MESH_OT_select_random", SPACEKEY, KM_PRESS, 0, 0);
219         WM_keymap_add_item(keymap, "MESH_OT_vertices_to_sphere", SKEY, KM_PRESS, KM_CTRL|KM_SHIFT , 0);
220
221         WM_keymap_add_item(keymap, "MESH_OT_mark_seam", ONEKEY, KM_PRESS, KM_CTRL , 0);
222         RNA_boolean_set(WM_keymap_add_item(keymap, "MESH_OT_mark_seam", ONEKEY, KM_PRESS, KM_ALT , 0)->ptr,"clear",1);
223
224         WM_keymap_add_item(keymap, "MESH_OT_mark_sharp", TWOKEY, KM_PRESS, KM_CTRL , 0);
225         RNA_boolean_set(WM_keymap_add_item(keymap, "MESH_OT_mark_sharp", TWOKEY, KM_PRESS, KM_ALT , 0)->ptr,"set",1);
226
227         /* temp hotkeys! */
228         WM_keymap_add_item(keymap, "MESH_OT_similar_vertex_select", GKEY, KM_PRESS, KM_SHIFT, 0);
229         WM_keymap_add_item(keymap, "MESH_OT_similar_edge_select", GKEY, KM_PRESS, KM_SHIFT2|KM_CTRL, 0);
230         WM_keymap_add_item(keymap, "MESH_OT_similar_face_select", GKEY, KM_PRESS, KM_SHIFT|KM_CTRL2, 0);
231         
232         /* selection mode */
233         WM_keymap_add_item(keymap, "MESH_OT_selection_type", TABKEY, KM_PRESS, KM_CTRL, 0);
234         
235         /* hide */
236         WM_keymap_add_item(keymap, "MESH_OT_hide", HKEY, KM_PRESS, 0, 0);
237         RNA_boolean_set(WM_keymap_add_item(keymap, "MESH_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "unselected", 1);
238         WM_keymap_add_item(keymap, "MESH_OT_reveal", HKEY, KM_PRESS, KM_ALT, 0);
239         
240         /* tools */
241         WM_keymap_add_item(keymap, "MESH_OT_consistant_normals", NKEY, KM_PRESS, KM_CTRL, 0);
242         RNA_boolean_set(WM_keymap_add_item(keymap, "MESH_OT_consistant_normals", NKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0)->ptr, "inside", 1);
243         WM_keymap_add_item(keymap, "MESH_OT_smooth_vertex", THREEKEY, KM_PRESS, KM_CTRL , 0);
244         WM_keymap_add_item(keymap, "MESH_OT_flip_editnormals", THREEKEY, KM_PRESS, KM_ALT , 0);
245         
246         WM_keymap_add_item(keymap, "MESH_OT_subdivs", WKEY, KM_PRESS, 0, 0); // this is the menu
247         /*WM_keymap_add_item(keymap, "MESH_OT_subdivide_multi", WKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
248         WM_keymap_add_item(keymap, "MESH_OT_subdivide_multi_fractal", WKEY, KM_PRESS, KM_ALT, 0);
249         WM_keymap_add_item(keymap, "MESH_OT_subdivide_smooth", WKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);*/
250         WM_keymap_add_item(keymap, "MESH_OT_removedoublesflag", VKEY, KM_PRESS, KM_CTRL, 0);
251         WM_keymap_add_item(keymap, "MESH_OT_extrude", EKEY, KM_PRESS, 0, 0);
252         
253         WM_keymap_add_item(keymap, "MESH_OT_spin", RKEY, KM_PRESS, KM_ALT, 0);
254         WM_keymap_add_item(keymap, "MESH_OT_screw", NINEKEY, KM_PRESS, KM_CTRL, 0);
255         
256         WM_keymap_add_item(keymap, "VIEW3D_OT_editmesh_face_toolbox", FKEY, KM_PRESS, KM_CTRL, 0); /* operators below are in this toolbox */
257         WM_keymap_add_item(keymap, "MESH_OT_fill", FKEY, KM_PRESS, KM_SHIFT, 0);
258         WM_keymap_add_item(keymap, "MESH_OT_beauty_fill", FKEY, KM_PRESS, KM_ALT, 0);
259         WM_keymap_add_item(keymap, "MESH_OT_convert_quads_to_tris", TKEY, KM_PRESS, KM_CTRL, 0);
260         WM_keymap_add_item(keymap, "MESH_OT_convert_tris_to_quads", JKEY, KM_PRESS, KM_ALT, 0);
261         
262         WM_keymap_add_item(keymap, "MESH_OT_split_mesh", FOURKEY, KM_PRESS, KM_CTRL, 0);
263         WM_keymap_add_item(keymap, "MESH_OT_extrude_repeat", FOURKEY, KM_PRESS, KM_ALT, 0);
264         WM_keymap_add_item(keymap, "MESH_OT_edge_rotate_selected", FIVEKEY, KM_PRESS, KM_CTRL, 0);
265         
266         WM_keymap_add_item(keymap, "MESH_OT_loop_to_region",SIXKEY, KM_PRESS, KM_CTRL, 0);
267         WM_keymap_add_item(keymap, "MESH_OT_region_to_loop",SIXKEY, KM_PRESS, KM_ALT, 0);
268         
269         WM_keymap_add_item(keymap, "MESH_OT_rotate_uvs",SEVENKEY, KM_PRESS, KM_CTRL, 0);
270         WM_keymap_add_item(keymap, "MESH_OT_mirror_uvs",SEVENKEY, KM_PRESS, KM_ALT, 0);
271         WM_keymap_add_item(keymap, "MESH_OT_rotate_colors",EIGHTKEY, KM_PRESS, KM_CTRL, 0);
272         WM_keymap_add_item(keymap, "MESH_OT_mirror_colors",EIGHTKEY, KM_PRESS, KM_ALT, 0);
273
274         WM_keymap_add_item(keymap, "MESH_OT_rip",VKEY, KM_PRESS, 0, 0);
275
276         /* add/remove */
277         WM_keymap_add_item(keymap, "MESH_OT_add_edge_face", FKEY, KM_PRESS, 0, 0);
278         WM_keymap_add_item(keymap, "MESH_OT_add_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);
279         WM_keymap_add_item(keymap, "OBJECT_OT_mesh_add", AKEY, KM_PRESS, KM_SHIFT, 0);
280         WM_keymap_add_item(keymap, "MESH_OT_separate", PKEY, KM_PRESS, KM_SHIFT, 0);
281                                                 /* use KM_RELEASE because same key is used for tweaks */
282         WM_keymap_add_item(keymap, "MESH_OT_dupli_extrude_cursor", LEFTMOUSE, KM_RELEASE, KM_CTRL, 0);
283         
284         WM_keymap_add_item(keymap, "MESH_OT_delete", XKEY, KM_PRESS, 0, 0);
285         
286         WM_keymap_add_item(keymap, "MESH_OT_make_fgon", FKEY, KM_PRESS, KM_ALT, 0);
287         WM_keymap_add_item(keymap, "MESH_OT_clear_fgon", FKEY, KM_PRESS, KM_SHIFT|KM_ALT, 0);
288         
289         WM_keymap_add_item(keymap, "MESH_OT_knife_cut", LEFTMOUSE, KM_PRESS, KM_ALT|KM_CTRL, 0);
290         
291         /* UV's */
292         WM_keymap_add_item(keymap, "UV_OT_mapping_menu", UKEY, KM_PRESS, 0, 0);
293 }
294