Merge branch 'blender2.7' into master.
[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                                 BM_select_history_store(em->bm, lcd->eed->v1);  /* low priority TODO, get vertrex close to mouse */
226                         if (em->selectmode & SCE_SELECT_EDGE)
227                                 BM_select_history_store(em->bm, lcd->eed);
228
229                         EDBM_selectmode_flush(lcd->em);
230                         DEG_id_tag_update(lcd->ob->data, ID_RECALC_SELECT);
231                         WM_event_add_notifier(C, NC_GEOM | ND_SELECT, lcd->ob->data);
232                 }
233         }
234 }
235
236 /* called when modal loop selection is done... */
237 static void ringsel_exit(bContext *UNUSED(C), wmOperator *op)
238 {
239         RingSelOpData *lcd = op->customdata;
240
241         /* deactivate the extra drawing stuff in 3D-View */
242         ED_region_draw_cb_exit(lcd->ar->type, lcd->draw_handle);
243
244         EDBM_preselect_edgering_destroy(lcd->presel_edgering);
245
246         MEM_freeN(lcd->objects);
247
248         ED_region_tag_redraw(lcd->ar);
249
250         /* free the custom data */
251         MEM_freeN(lcd);
252         op->customdata = NULL;
253 }
254
255
256 /* called when modal loop selection gets set up... */
257 static int ringsel_init(bContext *C, wmOperator *op, bool do_cut)
258 {
259         RingSelOpData *lcd;
260         Scene *scene = CTX_data_scene(C);
261
262         /* alloc new customdata */
263         lcd = op->customdata = MEM_callocN(sizeof(RingSelOpData), "ringsel Modal Op Data");
264
265         em_setup_viewcontext(C, &lcd->vc);
266
267         lcd->depsgraph = CTX_data_depsgraph(C);
268
269         /* assign the drawing handle for drawing preview line... */
270         lcd->ar = CTX_wm_region(C);
271         lcd->draw_handle = ED_region_draw_cb_activate(lcd->ar->type, ringsel_draw, lcd, REGION_DRAW_POST_VIEW);
272         lcd->presel_edgering = EDBM_preselect_edgering_create();
273         /* Initialize once the cursor is over a mesh. */
274         lcd->ob = NULL;
275         lcd->em = NULL;
276         lcd->extend = do_cut ? false : RNA_boolean_get(op->ptr, "extend");
277         lcd->do_cut = do_cut;
278         lcd->cuts = RNA_int_get(op->ptr, "number_cuts");
279         lcd->smoothness = RNA_float_get(op->ptr, "smoothness");
280
281         initNumInput(&lcd->num);
282         lcd->num.idx_max = 1;
283         lcd->num.val_flag[0] |= NUM_NO_NEGATIVE | NUM_NO_FRACTION;
284         /* No specific flags for smoothness. */
285         lcd->num.unit_sys = scene->unit.system;
286         lcd->num.unit_type[0] = B_UNIT_NONE;
287         lcd->num.unit_type[1] = B_UNIT_NONE;
288
289         ED_region_tag_redraw(lcd->ar);
290
291         return 1;
292 }
293
294 static void ringcut_cancel(bContext *C, wmOperator *op)
295 {
296         /* this is just a wrapper around exit() */
297         ringsel_exit(C, op);
298 }
299
300 static void loopcut_update_edge(RingSelOpData *lcd, uint ob_index, BMEdge *e, const int previewlines)
301 {
302         if (e != lcd->eed) {
303                 lcd->eed = e;
304                 lcd->ob = lcd->vc.obedit;
305                 lcd->ob_index = ob_index;
306                 lcd->em = lcd->vc.em;
307                 ringsel_find_edge(lcd, previewlines);
308         }
309         else if (e == NULL) {
310                 lcd->ob = NULL;
311                 lcd->em = NULL;
312                 lcd->ob_index = UINT_MAX;
313         }
314 }
315
316 static void loopcut_mouse_move(RingSelOpData *lcd, const int previewlines)
317 {
318         struct {
319                 Object *ob;
320                 BMEdge *eed;
321                 float dist;
322                 int ob_index;
323         } best = {
324                 .dist = ED_view3d_select_dist_px(),
325         };
326
327         for (uint ob_index = 0; ob_index < lcd->objects_len; ob_index++) {
328                 Object *ob_iter = lcd->objects[ob_index];
329                 ED_view3d_viewcontext_init_object(&lcd->vc, ob_iter);
330                 BMEdge *eed_test = EDBM_edge_find_nearest_ex(&lcd->vc, &best.dist, NULL, false, false, NULL);
331                 if (eed_test) {
332                         best.ob = ob_iter;
333                         best.eed = eed_test;
334                         best.ob_index = ob_index;
335                 }
336         }
337
338         if (best.eed) {
339                 ED_view3d_viewcontext_init_object(&lcd->vc, best.ob);
340         }
341
342         loopcut_update_edge(lcd, best.ob_index, best.eed, previewlines);
343 }
344
345 /* called by both init() and exec() */
346 static int loopcut_init(bContext *C, wmOperator *op, const wmEvent *event)
347 {
348         const bool is_interactive = (event != NULL);
349
350         /* Use for redo - intentionally wrap int to uint. */
351         const struct {
352                 uint ob_index;
353                 uint e_index;
354         } exec_data = {
355                 .ob_index = (uint)RNA_int_get(op->ptr, "object_index"),
356                 .e_index = (uint)RNA_int_get(op->ptr, "edge_index"),
357         };
358
359         ViewLayer *view_layer = CTX_data_view_layer(C);
360
361         uint objects_len;
362         Object **objects = BKE_view_layer_array_from_objects_in_edit_mode(view_layer, CTX_wm_view3d(C), &objects_len);
363
364         if (is_interactive) {
365                 for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
366                         Object *ob_iter = objects[ob_index];
367                         if (modifiers_isDeformedByLattice(ob_iter) || modifiers_isDeformedByArmature(ob_iter)) {
368                                 BKE_report(op->reports, RPT_WARNING, "Loop cut does not work well on deformed edit mesh display");
369                                 break;
370                         }
371                 }
372         }
373
374         view3d_operator_needs_opengl(C);
375
376         /* for re-execution, check edge index is in range before we setup ringsel */
377         bool ok = true;
378         if (is_interactive == false) {
379                 if (exec_data.ob_index >= objects_len) {
380                         return OPERATOR_CANCELLED;
381                         ok = false;
382                 }
383                 else {
384                         Object *ob_iter = objects[exec_data.ob_index];
385                         BMEditMesh *em = BKE_editmesh_from_object(ob_iter);
386                         if (exec_data.e_index >= em->bm->totedge) {
387                                 ok = false;
388                         }
389                 }
390         }
391
392         if (!ok || !ringsel_init(C, op, true)) {
393                 MEM_freeN(objects);
394                 return OPERATOR_CANCELLED;
395         }
396
397         /* add a modal handler for this operator - handles loop selection */
398         if (is_interactive) {
399                 op->flag |= OP_IS_MODAL_CURSOR_REGION;
400                 WM_event_add_modal_handler(C, op);
401         }
402
403         RingSelOpData *lcd = op->customdata;
404
405         lcd->objects = objects;
406         lcd->objects_len = objects_len;
407
408         if (is_interactive) {
409                 copy_v2_v2_int(lcd->vc.mval, event->mval);
410                 loopcut_mouse_move(lcd, is_interactive ? 1 : 0);
411         }
412         else {
413
414                 Object *ob_iter = objects[exec_data.ob_index];
415                 ED_view3d_viewcontext_init_object(&lcd->vc, ob_iter);
416
417                 BMEdge *e;
418                 BM_mesh_elem_table_ensure(lcd->vc.em->bm, BM_EDGE);
419                 e = BM_edge_at_index(lcd->vc.em->bm, exec_data.e_index);
420                 loopcut_update_edge(lcd, exec_data.ob_index, e, 0);
421         }
422
423 #ifdef USE_LOOPSLIDE_HACK
424         /* for use in macro so we can restore, HACK */
425         {
426                 Scene *scene = CTX_data_scene(C);
427                 ToolSettings *settings = scene->toolsettings;
428                 const bool mesh_select_mode[3] = {
429                     (settings->selectmode & SCE_SELECT_VERTEX) != 0,
430                     (settings->selectmode & SCE_SELECT_EDGE)   != 0,
431                     (settings->selectmode & SCE_SELECT_FACE)   != 0,
432                 };
433
434                 RNA_boolean_set_array(op->ptr, "mesh_select_mode_init", mesh_select_mode);
435         }
436 #endif
437
438         if (is_interactive) {
439                 ED_workspace_status_text(C, IFACE_("Select a ring to be cut, use mouse-wheel or page-up/down for number of cuts, "
440                                                "hold Alt for smooth"));
441                 return OPERATOR_RUNNING_MODAL;
442         }
443         else {
444                 ringsel_finish(C, op);
445                 ringsel_exit(C, op);
446                 return OPERATOR_FINISHED;
447         }
448 }
449
450 static int ringcut_invoke(bContext *C, wmOperator *op, const wmEvent *event)
451 {
452         /* When accessed as a tool, get the active edge from the preselection gizmo. */
453         {
454                 ARegion *ar = CTX_wm_region(C);
455                 wmGizmoMap *gzmap = ar->gizmo_map;
456                 wmGizmoGroup *gzgroup = gzmap ? WM_gizmomap_group_find(gzmap, "VIEW3D_GGT_mesh_preselect_edgering") : NULL;
457                 if ((gzgroup != NULL) && gzgroup->gizmos.first) {
458                         wmGizmo *gz = gzgroup->gizmos.first;
459                         const int object_index = RNA_int_get(gz->ptr, "object_index");
460                         const int edge_index = RNA_int_get(gz->ptr, "edge_index");
461
462                         if (object_index != -1 && edge_index != -1) {
463                                 RNA_int_set(op->ptr, "object_index", object_index);
464                                 RNA_int_set(op->ptr, "edge_index", edge_index);
465                                 return loopcut_init(C, op, NULL);
466                         }
467                         return OPERATOR_CANCELLED;
468                 }
469         }
470
471         return loopcut_init(C, op, event);
472 }
473
474 static int loopcut_exec(bContext *C, wmOperator *op)
475 {
476         return loopcut_init(C, op, NULL);
477 }
478
479 static int loopcut_finish(RingSelOpData *lcd, bContext *C, wmOperator *op)
480 {
481         /* finish */
482         ED_region_tag_redraw(lcd->ar);
483         ED_workspace_status_text(C, NULL);
484
485         if (lcd->eed) {
486                 /* set for redo */
487                 BM_mesh_elem_index_ensure(lcd->em->bm, BM_EDGE);
488                 RNA_int_set(op->ptr, "object_index", lcd->ob_index);
489                 RNA_int_set(op->ptr, "edge_index", BM_elem_index_get(lcd->eed));
490
491                 /* execute */
492                 ringsel_finish(C, op);
493                 ringsel_exit(C, op);
494         }
495         else {
496                 ringcut_cancel(C, op);
497                 return OPERATOR_CANCELLED;
498         }
499
500         return OPERATOR_FINISHED;
501 }
502
503 static int loopcut_modal(bContext *C, wmOperator *op, const wmEvent *event)
504 {
505         RingSelOpData *lcd = op->customdata;
506         float cuts = lcd->cuts;
507         float smoothness = lcd->smoothness;
508         bool show_cuts = false;
509         const bool has_numinput = hasNumInput(&lcd->num);
510
511         em_setup_viewcontext(C, &lcd->vc);
512         lcd->ar = lcd->vc.ar;
513
514         view3d_operator_needs_opengl(C);
515
516         /* using the keyboard to input the number of cuts */
517         /* Modal numinput active, try to handle numeric inputs first... */
518         if (event->val == KM_PRESS && has_numinput && handleNumInput(C, &lcd->num, event)) {
519                 float values[2] = {cuts, smoothness};
520                 applyNumInput(&lcd->num, values);
521                 cuts = values[0];
522                 smoothness = values[1];
523         }
524         else {
525                 bool handled = false;
526                 switch (event->type) {
527                         case RETKEY:
528                         case PADENTER:
529                         case LEFTMOUSE: /* confirm */ // XXX hardcoded
530                                 if (event->val == KM_PRESS)
531                                         return loopcut_finish(lcd, C, op);
532
533                                 ED_region_tag_redraw(lcd->ar);
534                                 handled = true;
535                                 break;
536                         case RIGHTMOUSE: /* abort */ // XXX hardcoded
537                                 ED_region_tag_redraw(lcd->ar);
538                                 ringsel_exit(C, op);
539                                 ED_workspace_status_text(C, NULL);
540
541                                 return OPERATOR_CANCELLED;
542                         case ESCKEY:
543                                 if (event->val == KM_RELEASE) {
544                                         /* cancel */
545                                         ED_region_tag_redraw(lcd->ar);
546                                         ED_workspace_status_text(C, NULL);
547
548                                         ringcut_cancel(C, op);
549                                         return OPERATOR_CANCELLED;
550                                 }
551
552                                 ED_region_tag_redraw(lcd->ar);
553                                 handled = true;
554                                 break;
555                         case MOUSEPAN:
556                                 if (event->alt == 0) {
557                                         cuts += 0.02f * (event->y - event->prevy);
558                                         if (cuts < 1 && lcd->cuts >= 1)
559                                                 cuts = 1;
560                                 }
561                                 else {
562                                         smoothness += 0.002f * (event->y - event->prevy);
563                                 }
564                                 handled = true;
565                                 break;
566                         case PADPLUSKEY:
567                         case PAGEUPKEY:
568                         case WHEELUPMOUSE:  /* change number of cuts */
569                                 if (event->val == KM_RELEASE)
570                                         break;
571                                 if (event->alt == 0) {
572                                         cuts += 1;
573                                 }
574                                 else {
575                                         smoothness += 0.05f;
576                                 }
577                                 handled = true;
578                                 break;
579                         case PADMINUS:
580                         case PAGEDOWNKEY:
581                         case WHEELDOWNMOUSE:  /* change number of cuts */
582                                 if (event->val == KM_RELEASE)
583                                         break;
584                                 if (event->alt == 0) {
585                                         cuts = max_ff(cuts - 1, 1);
586                                 }
587                                 else {
588                                         smoothness -= 0.05f;
589                                 }
590                                 handled = true;
591                                 break;
592                         case MOUSEMOVE:  /* mouse moved somewhere to select another loop */
593
594                                 /* This is normally disabled for all modal operators.
595                                  * This is an exception since mouse movement doesn't relate to numeric input.
596                                  *
597                                  * If numeric input changes we'll need to add this back see: D2973 */
598 #if 0
599                                 if (!has_numinput)
600 #endif
601                                 {
602                                         lcd->vc.mval[0] = event->mval[0];
603                                         lcd->vc.mval[1] = event->mval[1];
604                                         loopcut_mouse_move(lcd, (int)lcd->cuts);
605
606                                         ED_region_tag_redraw(lcd->ar);
607                                         handled = true;
608                                 }
609                                 break;
610                 }
611
612                 /* Modal numinput inactive, try to handle numeric inputs last... */
613                 if (!handled && event->val == KM_PRESS && handleNumInput(C, &lcd->num, event)) {
614                         float values[2] = {cuts, smoothness};
615                         applyNumInput(&lcd->num, values);
616                         cuts = values[0];
617                         smoothness = values[1];
618                 }
619         }
620
621         if (cuts != lcd->cuts) {
622                 /* allow zero so you can backspace and type in a value
623                  * otherwise 1 as minimum would make more sense */
624                 lcd->cuts = clamp_i(cuts, 0, SUBD_CUTS_MAX);
625                 RNA_int_set(op->ptr, "number_cuts", (int)lcd->cuts);
626                 ringsel_find_edge(lcd, (int)lcd->cuts);
627                 show_cuts = true;
628                 ED_region_tag_redraw(lcd->ar);
629         }
630
631         if (smoothness != lcd->smoothness) {
632                 lcd->smoothness = clamp_f(smoothness, -SUBD_SMOOTH_MAX, SUBD_SMOOTH_MAX);
633                 RNA_float_set(op->ptr, "smoothness", lcd->smoothness);
634                 show_cuts = true;
635                 ED_region_tag_redraw(lcd->ar);
636         }
637
638         if (show_cuts) {
639                 Scene *sce = CTX_data_scene(C);
640                 char buf[UI_MAX_DRAW_STR];
641                 char str_rep[NUM_STR_REP_LEN * 2];
642                 if (hasNumInput(&lcd->num)) {
643                         outputNumInput(&lcd->num, str_rep, &sce->unit);
644                 }
645                 else {
646                         BLI_snprintf(str_rep, NUM_STR_REP_LEN, "%d", (int)lcd->cuts);
647                         BLI_snprintf(str_rep + NUM_STR_REP_LEN, NUM_STR_REP_LEN, "%.2f", smoothness);
648                 }
649                 BLI_snprintf(buf, sizeof(buf), IFACE_("Number of Cuts: %s, Smooth: %s (Alt)"),
650                              str_rep, str_rep + NUM_STR_REP_LEN);
651                 ED_workspace_status_text(C, buf);
652         }
653
654         /* keep going until the user confirms */
655         return OPERATOR_RUNNING_MODAL;
656 }
657
658 /* for bmesh this tool is in bmesh_select.c */
659 #if 0
660
661 void MESH_OT_edgering_select(wmOperatorType *ot)
662 {
663         /* description */
664         ot->name = "Edge Ring Select";
665         ot->idname = "MESH_OT_edgering_select";
666         ot->description = "Select an edge ring";
667
668         /* callbacks */
669         ot->invoke = ringsel_invoke;
670         ot->poll = ED_operator_editmesh_region_view3d;
671
672         /* flags */
673         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
674
675         RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the selection");
676 }
677
678 #endif
679
680 void MESH_OT_loopcut(wmOperatorType *ot)
681 {
682         PropertyRNA *prop;
683
684         /* description */
685         ot->name = "Loop Cut";
686         ot->idname = "MESH_OT_loopcut";
687         ot->description = "Add a new loop between existing loops";
688
689         /* callbacks */
690         ot->invoke = ringcut_invoke;
691         ot->exec = loopcut_exec;
692         ot->modal = loopcut_modal;
693         ot->cancel = ringcut_cancel;
694         ot->poll = ED_operator_editmesh_region_view3d;
695
696         /* flags */
697         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
698
699         /* properties */
700         prop = RNA_def_int(ot->srna, "number_cuts", 1, 1, 1000000, "Number of Cuts", "", 1, 100);
701         /* avoid re-using last var because it can cause _very_ high poly meshes and annoy users (or worse crash) */
702         RNA_def_property_flag(prop, PROP_SKIP_SAVE);
703
704         prop = RNA_def_float(ot->srna, "smoothness", 0.0f, -1e3f, 1e3f,
705                              "Smoothness", "Smoothness factor", -SUBD_SMOOTH_MAX, SUBD_SMOOTH_MAX);
706         RNA_def_property_flag(prop, PROP_SKIP_SAVE);
707
708         WM_operatortype_props_advanced_begin(ot);
709
710         prop = RNA_def_property(ot->srna, "falloff", PROP_ENUM, PROP_NONE);
711         RNA_def_property_enum_items(prop, rna_enum_proportional_falloff_curve_only_items);
712         RNA_def_property_enum_default(prop, PROP_INVSQUARE);
713         RNA_def_property_ui_text(prop, "Falloff", "Falloff type the feather");
714         RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_CURVE); /* Abusing id_curve :/ */
715
716         /* For redo only. */
717         prop = RNA_def_int(ot->srna, "object_index", -1, -1, INT_MAX, "Object Index", "", 0, INT_MAX);
718         RNA_def_property_flag(prop, PROP_HIDDEN);
719         prop = RNA_def_int(ot->srna, "edge_index", -1, -1, INT_MAX, "Edge Index", "", 0, INT_MAX);
720         RNA_def_property_flag(prop, PROP_HIDDEN);
721
722 #ifdef USE_LOOPSLIDE_HACK
723         prop = RNA_def_boolean_array(ot->srna, "mesh_select_mode_init", 3, NULL, "", "");
724         RNA_def_property_flag(prop, PROP_HIDDEN);
725 #endif
726 }