Merge branch 'blender2.7'
[blender.git] / source / blender / editors / mesh / editmesh_loopcut.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) 2007 Blender Foundation.
19  * All rights reserved.
20  *
21  *
22  * Contributor(s): Joseph Eagar, Joshua Leung
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file blender/editors/mesh/editmesh_loopcut.c
28  *  \ingroup edmesh
29  */
30
31 #include "DNA_object_types.h"
32
33 #include "MEM_guardedalloc.h"
34
35 #include "BLI_stack.h"
36 #include "BLI_string.h"
37 #include "BLI_math.h"
38
39 #include "BLT_translation.h"
40
41 #include "DNA_mesh_types.h"
42
43 #include "BKE_context.h"
44 #include "BKE_modifier.h"
45 #include "BKE_report.h"
46 #include "BKE_editmesh.h"
47 #include "BKE_unit.h"
48 #include "BKE_layer.h"
49
50 #include "GPU_immediate.h"
51 #include "GPU_matrix.h"
52 #include "GPU_state.h"
53
54 #include "UI_interface.h"
55
56 #include "ED_screen.h"
57 #include "ED_space_api.h"
58 #include "ED_view3d.h"
59 #include "ED_mesh.h"
60 #include "ED_numinput.h"
61
62 #include "RNA_access.h"
63 #include "RNA_define.h"
64 #include "RNA_enum_types.h"
65
66 #include "WM_api.h"
67 #include "WM_types.h"
68
69 #include "DEG_depsgraph.h"
70 #include "DEG_depsgraph_query.h"
71
72 #include "mesh_intern.h"  /* own include */
73
74 #define SUBD_SMOOTH_MAX 4.0f
75 #define SUBD_CUTS_MAX 500
76
77 /* ringsel operator */
78
79 /* struct for properties used while drawing */
80 typedef struct RingSelOpData {
81         ARegion *ar;        /* region that ringsel was activated in */
82         void *draw_handle;  /* for drawing preview loop */
83
84         struct EditMesh_PreSelEdgeRing *presel_edgering;
85
86         ViewContext vc;
87
88         Depsgraph *depsgraph;
89
90         Object **objects;
91         uint     objects_len;
92
93         /* These values switch objects based on the object under the cursor. */
94         uint ob_index;
95         Object *ob;
96         BMEditMesh *em;
97         BMEdge *eed;
98
99         NumInput num;
100
101         bool extend;
102         bool do_cut;
103
104         float cuts;         /* cuts as float so smooth mouse pan works in small increments */
105         float smoothness;
106 } RingSelOpData;
107
108 /* modal loop selection drawing callback */
109 static void ringsel_draw(const bContext *UNUSED(C), ARegion *UNUSED(ar), void *arg)
110 {
111         RingSelOpData *lcd = arg;
112         EDBM_preselect_edgering_draw(lcd->presel_edgering, lcd->ob->obmat);
113 }
114
115 static void edgering_select(RingSelOpData *lcd)
116 {
117         if (!lcd->eed) {
118                 return;
119         }
120
121         if (!lcd->extend) {
122                 for (uint ob_index = 0; ob_index < lcd->objects_len; ob_index++) {
123                         Object *ob_iter = lcd->objects[ob_index];
124                         BMEditMesh *em = BKE_editmesh_from_object(ob_iter);
125                         EDBM_flag_disable_all(em, BM_ELEM_SELECT);
126                         DEG_id_tag_update(ob_iter->data, ID_RECALC_SELECT);
127                         WM_main_add_notifier(NC_GEOM | ND_SELECT, ob_iter->data);
128                 }
129         }
130
131         BMEditMesh *em = lcd->em;
132         BMEdge *eed_start = lcd->eed;
133         BMWalker walker;
134         BMEdge *eed;
135         BMW_init(&walker, em->bm, BMW_EDGERING,
136                  BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP,
137                  BMW_FLAG_TEST_HIDDEN,
138                  BMW_NIL_LAY);
139
140         for (eed = BMW_begin(&walker, eed_start); eed; eed = BMW_step(&walker)) {
141                 BM_edge_select_set(em->bm, eed, true);
142         }
143         BMW_end(&walker);
144 }
145
146 static void ringsel_find_edge(RingSelOpData *lcd, const int previewlines)
147 {
148         if (lcd->eed) {
149                 const float (*coords)[3] = NULL;
150                 {
151                         Mesh *me_eval = (Mesh *)DEG_get_evaluated_id(lcd->depsgraph, lcd->ob->data);
152                         if (me_eval->runtime.edit_data) {
153                                 coords = me_eval->runtime.edit_data->vertexCos;
154                         }
155                 }
156                 EDBM_preselect_edgering_update_from_edge(lcd->presel_edgering, lcd->em->bm, lcd->eed, previewlines, coords);
157         }
158         else {
159                 EDBM_preselect_edgering_clear(lcd->presel_edgering);
160         }
161 }
162
163 static void ringsel_finish(bContext *C, wmOperator *op)
164 {
165         RingSelOpData *lcd = op->customdata;
166         const int cuts = RNA_int_get(op->ptr, "number_cuts");
167         const float smoothness = RNA_float_get(op->ptr, "smoothness");
168         const int smooth_falloff = RNA_enum_get(op->ptr, "falloff");
169 #ifdef BMW_EDGERING_NGON
170         const bool use_only_quads = false;
171 #else
172         const bool use_only_quads = false;
173 #endif
174
175         if (lcd->eed) {
176                 BMEditMesh *em = lcd->em;
177                 BMVert *v_eed_orig[2] = {lcd->eed->v1, lcd->eed->v2};
178
179                 edgering_select(lcd);
180
181                 if (lcd->do_cut) {
182                         const bool is_macro = (op->opm != NULL);
183                         /* a single edge (rare, but better support) */
184                         const bool is_single = (BM_edge_is_wire(lcd->eed));
185                         const int seltype = is_single ? SUBDIV_SELECT_INNER : SUBDIV_SELECT_LOOPCUT;
186
187                         /* Enable gridfill, so that intersecting loopcut works as one would expect.
188                          * Note though that it will break edgeslide in this specific case.
189                          * See [#31939]. */
190                         BM_mesh_esubdivide(em->bm, BM_ELEM_SELECT,
191                                            smoothness, smooth_falloff, true,
192                                            0.0f, 0.0f,
193                                            cuts, seltype, SUBD_CORNER_PATH, 0, true,
194                                            use_only_quads, 0);
195
196                         /* when used in a macro the tessfaces will be recalculated anyway,
197                          * this is needed here because modifiers depend on updated tessellation, see T45920 */
198                         EDBM_update_generic(em, true, true);
199
200                         if (is_single) {
201                                 /* de-select endpoints */
202                                 BM_vert_select_set(em->bm, v_eed_orig[0], false);
203                                 BM_vert_select_set(em->bm, v_eed_orig[1], false);
204
205                                 EDBM_selectmode_flush_ex(lcd->em, SCE_SELECT_VERTEX);
206                         }
207                         /* we cant slide multiple edges in vertex select mode */
208                         else if (is_macro && (cuts > 1) && (em->selectmode & SCE_SELECT_VERTEX)) {
209                                 EDBM_selectmode_disable(lcd->vc.scene, em, SCE_SELECT_VERTEX, SCE_SELECT_EDGE);
210                         }
211                         /* force edge slide to edge select mode in in face select mode */
212                         else if (EDBM_selectmode_disable(lcd->vc.scene, em, SCE_SELECT_FACE, SCE_SELECT_EDGE)) {
213                                 /* pass, the change will flush selection */
214                         }
215                         else {
216                                 /* else flush explicitly */
217                                 EDBM_selectmode_flush(lcd->em);
218                         }
219                 }
220                 else {
221                         /* XXX Is this piece of code ever used now? Simple loop select is now
222                          *     in editmesh_select.c (around line 1000)... */
223                         /* sets as active, useful for other tools */
224                         if (em->selectmode & SCE_SELECT_VERTEX) {
225                                 /* low priority TODO, get vertrex close to mouse */
226                                 BM_select_history_store(em->bm, lcd->eed->v1);
227                         }
228                         if (em->selectmode & SCE_SELECT_EDGE) {
229                                 BM_select_history_store(em->bm, lcd->eed);
230                         }
231
232                         EDBM_selectmode_flush(lcd->em);
233                         DEG_id_tag_update(lcd->ob->data, ID_RECALC_SELECT);
234                         WM_event_add_notifier(C, NC_GEOM | ND_SELECT, lcd->ob->data);
235                 }
236         }
237 }
238
239 /* called when modal loop selection is done... */
240 static void ringsel_exit(bContext *UNUSED(C), wmOperator *op)
241 {
242         RingSelOpData *lcd = op->customdata;
243
244         /* deactivate the extra drawing stuff in 3D-View */
245         ED_region_draw_cb_exit(lcd->ar->type, lcd->draw_handle);
246
247         EDBM_preselect_edgering_destroy(lcd->presel_edgering);
248
249         MEM_freeN(lcd->objects);
250
251         ED_region_tag_redraw(lcd->ar);
252
253         /* free the custom data */
254         MEM_freeN(lcd);
255         op->customdata = NULL;
256 }
257
258
259 /* called when modal loop selection gets set up... */
260 static int ringsel_init(bContext *C, wmOperator *op, bool do_cut)
261 {
262         RingSelOpData *lcd;
263         Scene *scene = CTX_data_scene(C);
264
265         /* alloc new customdata */
266         lcd = op->customdata = MEM_callocN(sizeof(RingSelOpData), "ringsel Modal Op Data");
267
268         em_setup_viewcontext(C, &lcd->vc);
269
270         lcd->depsgraph = CTX_data_depsgraph(C);
271
272         /* assign the drawing handle for drawing preview line... */
273         lcd->ar = CTX_wm_region(C);
274         lcd->draw_handle = ED_region_draw_cb_activate(lcd->ar->type, ringsel_draw, lcd, REGION_DRAW_POST_VIEW);
275         lcd->presel_edgering = EDBM_preselect_edgering_create();
276         /* Initialize once the cursor is over a mesh. */
277         lcd->ob = NULL;
278         lcd->em = NULL;
279         lcd->extend = do_cut ? false : RNA_boolean_get(op->ptr, "extend");
280         lcd->do_cut = do_cut;
281         lcd->cuts = RNA_int_get(op->ptr, "number_cuts");
282         lcd->smoothness = RNA_float_get(op->ptr, "smoothness");
283
284         initNumInput(&lcd->num);
285         lcd->num.idx_max = 1;
286         lcd->num.val_flag[0] |= NUM_NO_NEGATIVE | NUM_NO_FRACTION;
287         /* No specific flags for smoothness. */
288         lcd->num.unit_sys = scene->unit.system;
289         lcd->num.unit_type[0] = B_UNIT_NONE;
290         lcd->num.unit_type[1] = B_UNIT_NONE;
291
292         ED_region_tag_redraw(lcd->ar);
293
294         return 1;
295 }
296
297 static void ringcut_cancel(bContext *C, wmOperator *op)
298 {
299         /* this is just a wrapper around exit() */
300         ringsel_exit(C, op);
301 }
302
303 static void loopcut_update_edge(RingSelOpData *lcd, uint ob_index, BMEdge *e, const int previewlines)
304 {
305         if (e != lcd->eed) {
306                 lcd->eed = e;
307                 lcd->ob = lcd->vc.obedit;
308                 lcd->ob_index = ob_index;
309                 lcd->em = lcd->vc.em;
310                 ringsel_find_edge(lcd, previewlines);
311         }
312         else if (e == NULL) {
313                 lcd->ob = NULL;
314                 lcd->em = NULL;
315                 lcd->ob_index = UINT_MAX;
316         }
317 }
318
319 static void loopcut_mouse_move(RingSelOpData *lcd, const int previewlines)
320 {
321         struct {
322                 Object *ob;
323                 BMEdge *eed;
324                 float dist;
325                 int ob_index;
326         } best = {
327                 .dist = ED_view3d_select_dist_px(),
328         };
329
330         for (uint ob_index = 0; ob_index < lcd->objects_len; ob_index++) {
331                 Object *ob_iter = lcd->objects[ob_index];
332                 ED_view3d_viewcontext_init_object(&lcd->vc, ob_iter);
333                 BMEdge *eed_test = EDBM_edge_find_nearest_ex(&lcd->vc, &best.dist, NULL, false, false, NULL);
334                 if (eed_test) {
335                         best.ob = ob_iter;
336                         best.eed = eed_test;
337                         best.ob_index = ob_index;
338                 }
339         }
340
341         if (best.eed) {
342                 ED_view3d_viewcontext_init_object(&lcd->vc, best.ob);
343         }
344
345         loopcut_update_edge(lcd, best.ob_index, best.eed, previewlines);
346 }
347
348 /* called by both init() and exec() */
349 static int loopcut_init(bContext *C, wmOperator *op, const wmEvent *event)
350 {
351         const bool is_interactive = (event != NULL);
352
353         /* Use for redo - intentionally wrap int to uint. */
354         const struct {
355                 uint ob_index;
356                 uint e_index;
357         } exec_data = {
358                 .ob_index = (uint)RNA_int_get(op->ptr, "object_index"),
359                 .e_index = (uint)RNA_int_get(op->ptr, "edge_index"),
360         };
361
362         ViewLayer *view_layer = CTX_data_view_layer(C);
363
364         uint objects_len;
365         Object **objects = BKE_view_layer_array_from_objects_in_edit_mode(view_layer, CTX_wm_view3d(C), &objects_len);
366
367         if (is_interactive) {
368                 for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
369                         Object *ob_iter = objects[ob_index];
370                         if (modifiers_isDeformedByLattice(ob_iter) || modifiers_isDeformedByArmature(ob_iter)) {
371                                 BKE_report(op->reports, RPT_WARNING, "Loop cut does not work well on deformed edit mesh display");
372                                 break;
373                         }
374                 }
375         }
376
377         view3d_operator_needs_opengl(C);
378
379         /* for re-execution, check edge index is in range before we setup ringsel */
380         bool ok = true;
381         if (is_interactive == false) {
382                 if (exec_data.ob_index >= objects_len) {
383                         return OPERATOR_CANCELLED;
384                         ok = false;
385                 }
386                 else {
387                         Object *ob_iter = objects[exec_data.ob_index];
388                         BMEditMesh *em = BKE_editmesh_from_object(ob_iter);
389                         if (exec_data.e_index >= em->bm->totedge) {
390                                 ok = false;
391                         }
392                 }
393         }
394
395         if (!ok || !ringsel_init(C, op, true)) {
396                 MEM_freeN(objects);
397                 return OPERATOR_CANCELLED;
398         }
399
400         /* add a modal handler for this operator - handles loop selection */
401         if (is_interactive) {
402                 op->flag |= OP_IS_MODAL_CURSOR_REGION;
403                 WM_event_add_modal_handler(C, op);
404         }
405
406         RingSelOpData *lcd = op->customdata;
407
408         lcd->objects = objects;
409         lcd->objects_len = objects_len;
410
411         if (is_interactive) {
412                 copy_v2_v2_int(lcd->vc.mval, event->mval);
413                 loopcut_mouse_move(lcd, is_interactive ? 1 : 0);
414         }
415         else {
416
417                 Object *ob_iter = objects[exec_data.ob_index];
418                 ED_view3d_viewcontext_init_object(&lcd->vc, ob_iter);
419
420                 BMEdge *e;
421                 BM_mesh_elem_table_ensure(lcd->vc.em->bm, BM_EDGE);
422                 e = BM_edge_at_index(lcd->vc.em->bm, exec_data.e_index);
423                 loopcut_update_edge(lcd, exec_data.ob_index, e, 0);
424         }
425
426 #ifdef USE_LOOPSLIDE_HACK
427         /* for use in macro so we can restore, HACK */
428         {
429                 Scene *scene = CTX_data_scene(C);
430                 ToolSettings *settings = scene->toolsettings;
431                 const bool mesh_select_mode[3] = {
432                     (settings->selectmode & SCE_SELECT_VERTEX) != 0,
433                     (settings->selectmode & SCE_SELECT_EDGE)   != 0,
434                     (settings->selectmode & SCE_SELECT_FACE)   != 0,
435                 };
436
437                 RNA_boolean_set_array(op->ptr, "mesh_select_mode_init", mesh_select_mode);
438         }
439 #endif
440
441         if (is_interactive) {
442                 ED_workspace_status_text(C, IFACE_("Select a ring to be cut, use mouse-wheel or page-up/down for number of cuts, "
443                                                "hold Alt for smooth"));
444                 return OPERATOR_RUNNING_MODAL;
445         }
446         else {
447                 ringsel_finish(C, op);
448                 ringsel_exit(C, op);
449                 return OPERATOR_FINISHED;
450         }
451 }
452
453 static int ringcut_invoke(bContext *C, wmOperator *op, const wmEvent *event)
454 {
455         /* When accessed as a tool, get the active edge from the preselection gizmo. */
456         {
457                 ARegion *ar = CTX_wm_region(C);
458                 wmGizmoMap *gzmap = ar->gizmo_map;
459                 wmGizmoGroup *gzgroup = gzmap ? WM_gizmomap_group_find(gzmap, "VIEW3D_GGT_mesh_preselect_edgering") : NULL;
460                 if ((gzgroup != NULL) && gzgroup->gizmos.first) {
461                         wmGizmo *gz = gzgroup->gizmos.first;
462                         const int object_index = RNA_int_get(gz->ptr, "object_index");
463                         const int edge_index = RNA_int_get(gz->ptr, "edge_index");
464
465                         if (object_index != -1 && edge_index != -1) {
466                                 RNA_int_set(op->ptr, "object_index", object_index);
467                                 RNA_int_set(op->ptr, "edge_index", edge_index);
468                                 return loopcut_init(C, op, NULL);
469                         }
470                         return OPERATOR_CANCELLED;
471                 }
472         }
473
474         return loopcut_init(C, op, event);
475 }
476
477 static int loopcut_exec(bContext *C, wmOperator *op)
478 {
479         return loopcut_init(C, op, NULL);
480 }
481
482 static int loopcut_finish(RingSelOpData *lcd, bContext *C, wmOperator *op)
483 {
484         /* finish */
485         ED_region_tag_redraw(lcd->ar);
486         ED_workspace_status_text(C, NULL);
487
488         if (lcd->eed) {
489                 /* set for redo */
490                 BM_mesh_elem_index_ensure(lcd->em->bm, BM_EDGE);
491                 RNA_int_set(op->ptr, "object_index", lcd->ob_index);
492                 RNA_int_set(op->ptr, "edge_index", BM_elem_index_get(lcd->eed));
493
494                 /* execute */
495                 ringsel_finish(C, op);
496                 ringsel_exit(C, op);
497         }
498         else {
499                 ringcut_cancel(C, op);
500                 return OPERATOR_CANCELLED;
501         }
502
503         return OPERATOR_FINISHED;
504 }
505
506 static int loopcut_modal(bContext *C, wmOperator *op, const wmEvent *event)
507 {
508         RingSelOpData *lcd = op->customdata;
509         float cuts = lcd->cuts;
510         float smoothness = lcd->smoothness;
511         bool show_cuts = false;
512         const bool has_numinput = hasNumInput(&lcd->num);
513
514         em_setup_viewcontext(C, &lcd->vc);
515         lcd->ar = lcd->vc.ar;
516
517         view3d_operator_needs_opengl(C);
518
519         /* using the keyboard to input the number of cuts */
520         /* Modal numinput active, try to handle numeric inputs first... */
521         if (event->val == KM_PRESS && has_numinput && handleNumInput(C, &lcd->num, event)) {
522                 float values[2] = {cuts, smoothness};
523                 applyNumInput(&lcd->num, values);
524                 cuts = values[0];
525                 smoothness = values[1];
526         }
527         else {
528                 bool handled = false;
529                 switch (event->type) {
530                         case RETKEY:
531                         case PADENTER:
532                         case LEFTMOUSE: /* confirm */ // XXX hardcoded
533                                 if (event->val == KM_PRESS)
534                                         return loopcut_finish(lcd, C, op);
535
536                                 ED_region_tag_redraw(lcd->ar);
537                                 handled = true;
538                                 break;
539                         case RIGHTMOUSE: /* abort */ // XXX hardcoded
540                                 ED_region_tag_redraw(lcd->ar);
541                                 ringsel_exit(C, op);
542                                 ED_workspace_status_text(C, NULL);
543
544                                 return OPERATOR_CANCELLED;
545                         case ESCKEY:
546                                 if (event->val == KM_RELEASE) {
547                                         /* cancel */
548                                         ED_region_tag_redraw(lcd->ar);
549                                         ED_workspace_status_text(C, NULL);
550
551                                         ringcut_cancel(C, op);
552                                         return OPERATOR_CANCELLED;
553                                 }
554
555                                 ED_region_tag_redraw(lcd->ar);
556                                 handled = true;
557                                 break;
558                         case MOUSEPAN:
559                                 if (event->alt == 0) {
560                                         cuts += 0.02f * (event->y - event->prevy);
561                                         if (cuts < 1 && lcd->cuts >= 1)
562                                                 cuts = 1;
563                                 }
564                                 else {
565                                         smoothness += 0.002f * (event->y - event->prevy);
566                                 }
567                                 handled = true;
568                                 break;
569                         case PADPLUSKEY:
570                         case PAGEUPKEY:
571                         case WHEELUPMOUSE:  /* change number of cuts */
572                                 if (event->val == KM_RELEASE)
573                                         break;
574                                 if (event->alt == 0) {
575                                         cuts += 1;
576                                 }
577                                 else {
578                                         smoothness += 0.05f;
579                                 }
580                                 handled = true;
581                                 break;
582                         case PADMINUS:
583                         case PAGEDOWNKEY:
584                         case WHEELDOWNMOUSE:  /* change number of cuts */
585                                 if (event->val == KM_RELEASE)
586                                         break;
587                                 if (event->alt == 0) {
588                                         cuts = max_ff(cuts - 1, 1);
589                                 }
590                                 else {
591                                         smoothness -= 0.05f;
592                                 }
593                                 handled = true;
594                                 break;
595                         case MOUSEMOVE:  /* mouse moved somewhere to select another loop */
596
597                                 /* This is normally disabled for all modal operators.
598                                  * This is an exception since mouse movement doesn't relate to numeric input.
599                                  *
600                                  * If numeric input changes we'll need to add this back see: D2973 */
601 #if 0
602                                 if (!has_numinput)
603 #endif
604                                 {
605                                         lcd->vc.mval[0] = event->mval[0];
606                                         lcd->vc.mval[1] = event->mval[1];
607                                         loopcut_mouse_move(lcd, (int)lcd->cuts);
608
609                                         ED_region_tag_redraw(lcd->ar);
610                                         handled = true;
611                                 }
612                                 break;
613                 }
614
615                 /* Modal numinput inactive, try to handle numeric inputs last... */
616                 if (!handled && event->val == KM_PRESS && handleNumInput(C, &lcd->num, event)) {
617                         float values[2] = {cuts, smoothness};
618                         applyNumInput(&lcd->num, values);
619                         cuts = values[0];
620                         smoothness = values[1];
621                 }
622         }
623
624         if (cuts != lcd->cuts) {
625                 /* allow zero so you can backspace and type in a value
626                  * otherwise 1 as minimum would make more sense */
627                 lcd->cuts = clamp_i(cuts, 0, SUBD_CUTS_MAX);
628                 RNA_int_set(op->ptr, "number_cuts", (int)lcd->cuts);
629                 ringsel_find_edge(lcd, (int)lcd->cuts);
630                 show_cuts = true;
631                 ED_region_tag_redraw(lcd->ar);
632         }
633
634         if (smoothness != lcd->smoothness) {
635                 lcd->smoothness = clamp_f(smoothness, -SUBD_SMOOTH_MAX, SUBD_SMOOTH_MAX);
636                 RNA_float_set(op->ptr, "smoothness", lcd->smoothness);
637                 show_cuts = true;
638                 ED_region_tag_redraw(lcd->ar);
639         }
640
641         if (show_cuts) {
642                 Scene *sce = CTX_data_scene(C);
643                 char buf[UI_MAX_DRAW_STR];
644                 char str_rep[NUM_STR_REP_LEN * 2];
645                 if (hasNumInput(&lcd->num)) {
646                         outputNumInput(&lcd->num, str_rep, &sce->unit);
647                 }
648                 else {
649                         BLI_snprintf(str_rep, NUM_STR_REP_LEN, "%d", (int)lcd->cuts);
650                         BLI_snprintf(str_rep + NUM_STR_REP_LEN, NUM_STR_REP_LEN, "%.2f", smoothness);
651                 }
652                 BLI_snprintf(buf, sizeof(buf), IFACE_("Number of Cuts: %s, Smooth: %s (Alt)"),
653                              str_rep, str_rep + NUM_STR_REP_LEN);
654                 ED_workspace_status_text(C, buf);
655         }
656
657         /* keep going until the user confirms */
658         return OPERATOR_RUNNING_MODAL;
659 }
660
661 /* for bmesh this tool is in bmesh_select.c */
662 #if 0
663
664 void MESH_OT_edgering_select(wmOperatorType *ot)
665 {
666         /* description */
667         ot->name = "Edge Ring Select";
668         ot->idname = "MESH_OT_edgering_select";
669         ot->description = "Select an edge ring";
670
671         /* callbacks */
672         ot->invoke = ringsel_invoke;
673         ot->poll = ED_operator_editmesh_region_view3d;
674
675         /* flags */
676         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
677
678         RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the selection");
679 }
680
681 #endif
682
683 void MESH_OT_loopcut(wmOperatorType *ot)
684 {
685         PropertyRNA *prop;
686
687         /* description */
688         ot->name = "Loop Cut";
689         ot->idname = "MESH_OT_loopcut";
690         ot->description = "Add a new loop between existing loops";
691
692         /* callbacks */
693         ot->invoke = ringcut_invoke;
694         ot->exec = loopcut_exec;
695         ot->modal = loopcut_modal;
696         ot->cancel = ringcut_cancel;
697         ot->poll = ED_operator_editmesh_region_view3d;
698
699         /* flags */
700         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
701
702         /* properties */
703         prop = RNA_def_int(ot->srna, "number_cuts", 1, 1, 1000000, "Number of Cuts", "", 1, 100);
704         /* avoid re-using last var because it can cause
705          * _very_ high poly meshes and annoy users (or worse crash) */
706         RNA_def_property_flag(prop, PROP_SKIP_SAVE);
707
708         prop = RNA_def_float(ot->srna, "smoothness", 0.0f, -1e3f, 1e3f,
709                              "Smoothness", "Smoothness factor", -SUBD_SMOOTH_MAX, SUBD_SMOOTH_MAX);
710         RNA_def_property_flag(prop, PROP_SKIP_SAVE);
711
712         WM_operatortype_props_advanced_begin(ot);
713
714         prop = RNA_def_property(ot->srna, "falloff", PROP_ENUM, PROP_NONE);
715         RNA_def_property_enum_items(prop, rna_enum_proportional_falloff_curve_only_items);
716         RNA_def_property_enum_default(prop, PROP_INVSQUARE);
717         RNA_def_property_ui_text(prop, "Falloff", "Falloff type the feather");
718         RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_CURVE); /* Abusing id_curve :/ */
719
720         /* For redo only. */
721         prop = RNA_def_int(ot->srna, "object_index", -1, -1, INT_MAX, "Object Index", "", 0, INT_MAX);
722         RNA_def_property_flag(prop, PROP_HIDDEN);
723         prop = RNA_def_int(ot->srna, "edge_index", -1, -1, INT_MAX, "Edge Index", "", 0, INT_MAX);
724         RNA_def_property_flag(prop, PROP_HIDDEN);
725
726 #ifdef USE_LOOPSLIDE_HACK
727         prop = RNA_def_boolean_array(ot->srna, "mesh_select_mode_init", 3, NULL, "", "");
728         RNA_def_property_flag(prop, PROP_HIDDEN);
729 #endif
730 }