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