Merge branch 'blender2.7' into master.
[blender.git] / source / blender / editors / mesh / mesh_ops.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2009 Blender Foundation.
19  * All rights reserved.
20  *
21  *
22  * Contributor(s): Blender Foundation
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file blender/editors/mesh/mesh_ops.c
28  *  \ingroup edmesh
29  */
30
31 #include "DNA_scene_types.h"
32 #include "DNA_modifier_types.h"
33
34
35 #include "RNA_access.h"
36
37 #include "WM_api.h"
38 #include "WM_types.h"
39
40 #include "ED_object.h"
41 #include "ED_mesh.h"
42 #include "ED_screen.h"
43 #include "ED_select_utils.h"
44
45 #include "mesh_intern.h"  /* own include */
46
47 /**************************** registration **********************************/
48
49 void ED_operatortypes_mesh(void)
50 {
51         WM_operatortype_append(MESH_OT_select_all);
52         WM_operatortype_append(MESH_OT_select_interior_faces);
53         WM_operatortype_append(MESH_OT_select_more);
54         WM_operatortype_append(MESH_OT_select_less);
55         WM_operatortype_append(MESH_OT_select_non_manifold);
56         WM_operatortype_append(MESH_OT_select_linked);
57         WM_operatortype_append(MESH_OT_select_linked_pick);
58         WM_operatortype_append(MESH_OT_select_random);
59         WM_operatortype_append(MESH_OT_select_ungrouped);
60         WM_operatortype_append(MESH_OT_hide);
61         WM_operatortype_append(MESH_OT_reveal);
62         WM_operatortype_append(MESH_OT_select_face_by_sides);
63         WM_operatortype_append(MESH_OT_select_loose);
64         WM_operatortype_append(MESH_OT_select_mirror);
65         WM_operatortype_append(MESH_OT_normals_make_consistent);
66         WM_operatortype_append(MESH_OT_merge);
67         WM_operatortype_append(MESH_OT_subdivide);
68         WM_operatortype_append(MESH_OT_subdivide_edgering);
69         WM_operatortype_append(MESH_OT_unsubdivide);
70         WM_operatortype_append(MESH_OT_faces_select_linked_flat);
71         WM_operatortype_append(MESH_OT_edges_select_sharp);
72         WM_operatortype_append(MESH_OT_primitive_plane_add);
73         WM_operatortype_append(MESH_OT_primitive_cube_add);
74         WM_operatortype_append(MESH_OT_primitive_circle_add);
75         WM_operatortype_append(MESH_OT_primitive_cylinder_add);
76         WM_operatortype_append(MESH_OT_primitive_cone_add);
77         WM_operatortype_append(MESH_OT_primitive_grid_add);
78         WM_operatortype_append(MESH_OT_primitive_monkey_add);
79         WM_operatortype_append(MESH_OT_primitive_uv_sphere_add);
80         WM_operatortype_append(MESH_OT_primitive_ico_sphere_add);
81
82         WM_operatortype_append(MESH_OT_primitive_cube_add_gizmo);
83
84         WM_operatortype_append(MESH_OT_duplicate);
85         WM_operatortype_append(MESH_OT_remove_doubles);
86         WM_operatortype_append(MESH_OT_spin);
87         WM_operatortype_append(MESH_OT_screw);
88
89         WM_operatortype_append(MESH_OT_extrude_region);
90         WM_operatortype_append(MESH_OT_extrude_context);
91         WM_operatortype_append(MESH_OT_extrude_faces_indiv);
92         WM_operatortype_append(MESH_OT_extrude_edges_indiv);
93         WM_operatortype_append(MESH_OT_extrude_verts_indiv);
94
95         WM_operatortype_append(MESH_OT_split);
96         WM_operatortype_append(MESH_OT_extrude_repeat);
97         WM_operatortype_append(MESH_OT_edge_rotate);
98         WM_operatortype_append(MESH_OT_shortest_path_select);
99         WM_operatortype_append(MESH_OT_loop_to_region);
100         WM_operatortype_append(MESH_OT_region_to_loop);
101         WM_operatortype_append(MESH_OT_select_axis);
102
103         WM_operatortype_append(MESH_OT_uvs_rotate);
104         WM_operatortype_append(MESH_OT_uvs_reverse);
105         WM_operatortype_append(MESH_OT_colors_rotate);
106         WM_operatortype_append(MESH_OT_colors_reverse);
107
108         WM_operatortype_append(MESH_OT_fill);
109         WM_operatortype_append(MESH_OT_fill_grid);
110         WM_operatortype_append(MESH_OT_fill_holes);
111         WM_operatortype_append(MESH_OT_beautify_fill);
112         WM_operatortype_append(MESH_OT_quads_convert_to_tris);
113         WM_operatortype_append(MESH_OT_tris_convert_to_quads);
114         WM_operatortype_append(MESH_OT_decimate);
115         WM_operatortype_append(MESH_OT_dissolve_verts);
116         WM_operatortype_append(MESH_OT_dissolve_edges);
117         WM_operatortype_append(MESH_OT_dissolve_faces);
118         WM_operatortype_append(MESH_OT_dissolve_mode);
119         WM_operatortype_append(MESH_OT_dissolve_limited);
120         WM_operatortype_append(MESH_OT_dissolve_degenerate);
121         WM_operatortype_append(MESH_OT_delete_edgeloop);
122         WM_operatortype_append(MESH_OT_faces_shade_smooth);
123         WM_operatortype_append(MESH_OT_faces_shade_flat);
124         WM_operatortype_append(MESH_OT_sort_elements);
125 #ifdef WITH_FREESTYLE
126         WM_operatortype_append(MESH_OT_mark_freestyle_face);
127 #endif
128
129         WM_operatortype_append(MESH_OT_delete);
130         WM_operatortype_append(MESH_OT_delete_loose);
131         WM_operatortype_append(MESH_OT_edge_collapse);
132
133         WM_operatortype_append(MESH_OT_separate);
134         WM_operatortype_append(MESH_OT_dupli_extrude_cursor);
135         WM_operatortype_append(MESH_OT_loop_select);
136         WM_operatortype_append(MESH_OT_edge_face_add);
137         WM_operatortype_append(MESH_OT_shortest_path_pick);
138         WM_operatortype_append(MESH_OT_select_similar);
139         WM_operatortype_append(MESH_OT_select_similar_region);
140         WM_operatortype_append(MESH_OT_select_mode);
141         WM_operatortype_append(MESH_OT_loop_multi_select);
142         WM_operatortype_append(MESH_OT_mark_seam);
143         WM_operatortype_append(MESH_OT_mark_sharp);
144 #ifdef WITH_FREESTYLE
145         WM_operatortype_append(MESH_OT_mark_freestyle_edge);
146 #endif
147         WM_operatortype_append(MESH_OT_vertices_smooth);
148         WM_operatortype_append(MESH_OT_vertices_smooth_laplacian);
149         WM_operatortype_append(MESH_OT_flip_normals);
150         WM_operatortype_append(MESH_OT_rip);
151         WM_operatortype_append(MESH_OT_rip_edge);
152         WM_operatortype_append(MESH_OT_blend_from_shape);
153         WM_operatortype_append(MESH_OT_shape_propagate_to_all);
154
155         /* editmesh_polybuild */
156         WM_operatortype_append(MESH_OT_polybuild_face_at_cursor);
157         WM_operatortype_append(MESH_OT_polybuild_split_at_cursor);
158         WM_operatortype_append(MESH_OT_polybuild_dissolve_at_cursor);
159
160         WM_operatortype_append(MESH_OT_uv_texture_add);
161         WM_operatortype_append(MESH_OT_uv_texture_remove);
162         WM_operatortype_append(MESH_OT_vertex_color_add);
163         WM_operatortype_append(MESH_OT_vertex_color_remove);
164         WM_operatortype_append(MESH_OT_customdata_mask_clear);
165         WM_operatortype_append(MESH_OT_customdata_skin_add);
166         WM_operatortype_append(MESH_OT_customdata_skin_clear);
167         WM_operatortype_append(MESH_OT_customdata_custom_splitnormals_add);
168         WM_operatortype_append(MESH_OT_customdata_custom_splitnormals_clear);
169
170         WM_operatortype_append(MESH_OT_edgering_select);
171         WM_operatortype_append(MESH_OT_loopcut);
172
173         WM_operatortype_append(MESH_OT_solidify);
174         WM_operatortype_append(MESH_OT_select_nth);
175         WM_operatortype_append(MESH_OT_vert_connect);
176         WM_operatortype_append(MESH_OT_vert_connect_path);
177         WM_operatortype_append(MESH_OT_vert_connect_concave);
178         WM_operatortype_append(MESH_OT_vert_connect_nonplanar);
179         WM_operatortype_append(MESH_OT_face_make_planar);
180         WM_operatortype_append(MESH_OT_knife_tool);
181         WM_operatortype_append(MESH_OT_knife_project);
182
183         WM_operatortype_append(MESH_OT_bevel);
184
185         WM_operatortype_append(MESH_OT_bridge_edge_loops);
186         WM_operatortype_append(MESH_OT_inset);
187         WM_operatortype_append(MESH_OT_offset_edge_loops);
188         WM_operatortype_append(MESH_OT_intersect);
189         WM_operatortype_append(MESH_OT_intersect_boolean);
190         WM_operatortype_append(MESH_OT_face_split_by_edges);
191         WM_operatortype_append(MESH_OT_poke);
192         WM_operatortype_append(MESH_OT_wireframe);
193         WM_operatortype_append(MESH_OT_edge_split);
194
195 #ifdef WITH_BULLET
196         WM_operatortype_append(MESH_OT_convex_hull);
197 #endif
198
199         WM_operatortype_append(MESH_OT_bisect);
200         WM_operatortype_append(MESH_OT_symmetrize);
201         WM_operatortype_append(MESH_OT_symmetry_snap);
202
203         WM_operatortype_append(MESH_OT_point_normals);
204         WM_operatortype_append(MESH_OT_merge_normals);
205         WM_operatortype_append(MESH_OT_split_normals);
206         WM_operatortype_append(MESH_OT_normals_tools);
207         WM_operatortype_append(MESH_OT_set_normals_from_faces);
208         WM_operatortype_append(MESH_OT_average_normals);
209         WM_operatortype_append(MESH_OT_smoothen_normals);
210         WM_operatortype_append(MESH_OT_mod_weighted_strength);
211 }
212
213 #if 0 /* UNUSED, remove? */
214 static int ED_operator_editmesh_face_select(bContext *C)
215 {
216         Object *obedit = CTX_data_edit_object(C);
217         if (obedit && obedit->type == OB_MESH) {
218                 BMEditMesh *em = BKE_editmesh_from_object(obedit);
219                 if (em && em->selectmode & SCE_SELECT_FACE) {
220                         return 1;
221                 }
222         }
223         return 0;
224 }
225 #endif
226
227 void ED_operatormacros_mesh(void)
228 {
229         wmOperatorType *ot;
230         wmOperatorTypeMacro *otmacro;
231
232         ot = WM_operatortype_append_macro("MESH_OT_loopcut_slide", "Loop Cut and Slide", "Cut mesh loop and slide it",
233                                           OPTYPE_UNDO | OPTYPE_REGISTER);
234         WM_operatortype_macro_define(ot, "MESH_OT_loopcut");
235         WM_operatortype_macro_define(ot, "TRANSFORM_OT_edge_slide");
236
237         ot = WM_operatortype_append_macro("MESH_OT_offset_edge_loops_slide", "Offset Edge Slide", "Offset edge loop slide",
238                                           OPTYPE_UNDO | OPTYPE_REGISTER);
239         WM_operatortype_macro_define(ot, "MESH_OT_offset_edge_loops");
240         otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_edge_slide");
241         RNA_boolean_set(otmacro->ptr, "single_side", true);
242
243         ot = WM_operatortype_append_macro("MESH_OT_duplicate_move", "Add Duplicate", "Duplicate mesh and move",
244                                           OPTYPE_UNDO | OPTYPE_REGISTER);
245         WM_operatortype_macro_define(ot, "MESH_OT_duplicate");
246         otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
247         RNA_enum_set(otmacro->ptr, "proportional", 0);
248         RNA_boolean_set(otmacro->ptr, "mirror", false);
249
250         ot = WM_operatortype_append_macro("MESH_OT_rip_move", "Rip", "Rip polygons and move the result",
251                                           OPTYPE_UNDO | OPTYPE_REGISTER);
252         otmacro = WM_operatortype_macro_define(ot, "MESH_OT_rip");
253         otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
254         RNA_enum_set(otmacro->ptr, "proportional", 0);
255         RNA_boolean_set(otmacro->ptr, "mirror", false);
256
257         ot = WM_operatortype_append_macro("MESH_OT_rip_edge_move", "Extend Vertices", "Extend vertices and move the result",
258                                           OPTYPE_UNDO | OPTYPE_REGISTER);
259         WM_operatortype_macro_define(ot, "MESH_OT_rip_edge");
260         otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
261         RNA_enum_set(otmacro->ptr, "proportional", 0);
262         RNA_boolean_set(otmacro->ptr, "mirror", false);
263
264         ot = WM_operatortype_append_macro("MESH_OT_extrude_region_move", "Extrude Region and Move",
265                                           "Extrude region and move result", OPTYPE_UNDO | OPTYPE_REGISTER);
266         otmacro = WM_operatortype_macro_define(ot, "MESH_OT_extrude_region");
267         otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
268         RNA_enum_set(otmacro->ptr, "proportional", 0);
269         RNA_boolean_set(otmacro->ptr, "mirror", false);
270
271         ot = WM_operatortype_append_macro("MESH_OT_extrude_context_move", "Extrude Region and Move",
272                                           "Extrude context and move result", OPTYPE_UNDO | OPTYPE_REGISTER);
273         otmacro = WM_operatortype_macro_define(ot, "MESH_OT_extrude_context");
274         otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
275         RNA_enum_set(otmacro->ptr, "proportional", 0);
276         RNA_boolean_set(otmacro->ptr, "mirror", false);
277
278         ot = WM_operatortype_append_macro("MESH_OT_extrude_region_shrink_fatten", "Extrude Region and Shrink/Fatten",
279                                           "Extrude along normals and move result", OPTYPE_UNDO | OPTYPE_REGISTER);
280         otmacro = WM_operatortype_macro_define(ot, "MESH_OT_extrude_region");
281         otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_shrink_fatten");
282         RNA_enum_set(otmacro->ptr, "proportional", 0);
283         RNA_boolean_set(otmacro->ptr, "mirror", false);
284
285         ot = WM_operatortype_append_macro("MESH_OT_extrude_faces_move", "Extrude Individual Faces and Move",
286                                           "Extrude faces and move result", OPTYPE_UNDO | OPTYPE_REGISTER);
287         otmacro = WM_operatortype_macro_define(ot, "MESH_OT_extrude_faces_indiv");
288         otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_shrink_fatten");
289         RNA_enum_set(otmacro->ptr, "proportional", 0);
290         RNA_boolean_set(otmacro->ptr, "mirror", false);
291
292         ot = WM_operatortype_append_macro("MESH_OT_extrude_edges_move", "Extrude Only Edges and Move",
293                                           "Extrude edges and move result", OPTYPE_UNDO | OPTYPE_REGISTER);
294         otmacro = WM_operatortype_macro_define(ot, "MESH_OT_extrude_edges_indiv");
295         otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
296         RNA_enum_set(otmacro->ptr, "proportional", 0);
297         RNA_boolean_set(otmacro->ptr, "mirror", false);
298
299         ot = WM_operatortype_append_macro("MESH_OT_extrude_vertices_move", "Extrude Only Vertices and Move",
300                                           "Extrude vertices and move result", OPTYPE_UNDO | OPTYPE_REGISTER);
301         otmacro = WM_operatortype_macro_define(ot, "MESH_OT_extrude_verts_indiv");
302         otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
303         RNA_enum_set(otmacro->ptr, "proportional", 0);
304         RNA_boolean_set(otmacro->ptr, "mirror", false);
305
306
307         ot = WM_operatortype_append_macro(
308                 "MESH_OT_polybuild_face_at_cursor_move", "Face at Cursor Move", "",
309                 OPTYPE_UNDO | OPTYPE_REGISTER);
310         WM_operatortype_macro_define(ot, "MESH_OT_polybuild_face_at_cursor");
311         otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
312         RNA_enum_set(otmacro->ptr, "proportional", 0);
313         RNA_boolean_set(otmacro->ptr, "mirror", false);
314
315         ot = WM_operatortype_append_macro(
316                 "MESH_OT_polybuild_split_at_cursor_move", "Split at Cursor Move", "",
317                 OPTYPE_UNDO | OPTYPE_REGISTER);
318         WM_operatortype_macro_define(ot, "MESH_OT_polybuild_split_at_cursor");
319         otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
320         RNA_enum_set(otmacro->ptr, "proportional", 0);
321         RNA_boolean_set(otmacro->ptr, "mirror", false);
322 }
323
324 /* note mesh keymap also for other space? */
325 void ED_keymap_mesh(wmKeyConfig *keyconf)
326 {
327         wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Mesh", 0, 0);
328         keymap->poll = ED_operator_editmesh;
329
330         knifetool_modal_keymap(keyconf);
331         point_normals_modal_keymap(keyconf);
332 }