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