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