added boolean type for bmesh operators, will make python wrapping clearer and also...
[blender.git] / source / blender / editors / mesh / loopcut.c
index 313ebb310dee140c2509d931d07f3ca2936ffc51..dbcc0447a8918034bb32bbfac6ef062dd13572b6 100644 (file)
@@ -13,7 +13,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  * The Original Code is Copyright (C) 2007 Blender Foundation.
  * All rights reserved.
@@ -38,6 +38,7 @@
 
 #include "DNA_ID.h"
 #include "DNA_object_types.h"
+#include "DNA_mesh_types.h"
 #include "DNA_screen_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_userdef_types.h"
 
 #include "PIL_time.h"
 
+#include "BLI_array.h"
 #include "BLI_blenlib.h"
+#include "BLI_math.h"
 #include "BLI_dynstr.h" /*for WM_operator_pystring */
-#include "BLI_editVert.h"
-#include "BLI_array.h"
 #include "BLI_utildefines.h"
 
 #include "BKE_blender.h"
@@ -59,7 +60,6 @@
 #include "BKE_modifier.h"
 #include "BKE_report.h"
 #include "BKE_scene.h"
-#include "BKE_array_mallocn.h"
 #include "BKE_tessmesh.h"
 #include "BKE_depsgraph.h"
 
@@ -145,9 +145,9 @@ static void edgering_find_order(BMEditMesh *em, BMEdge *lasteed, BMEdge *eed,
        l = eed->l;
 
        /*find correct order for v[1]*/
-       if (!(BM_Edge_In_Face(l->f, eed) && BM_Edge_In_Face(l->f, lasteed))) {
+       if (!(BM_edge_in_face(l->f, eed) && BM_edge_in_face(l->f, lasteed))) {
                BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_LOOP, l) {
-                       if (BM_Edge_In_Face(l->f, eed) && BM_Edge_In_Face(l->f, lasteed))
+                       if (BM_edge_in_face(l->f, eed) && BM_edge_in_face(l->f, lasteed))
                                break;
                }
        }
@@ -161,7 +161,7 @@ static void edgering_find_order(BMEditMesh *em, BMEdge *lasteed, BMEdge *eed,
                return;
        }
        
-       l2 = BM_OtherFaceLoop(l->e, l->f, eed->v1);
+       l2 = BM_face_other_loop(l->e, l->f, eed->v1);
        rev = (l2 == l->prev);
        while (l2->v != lasteed->v1 && l2->v != lasteed->v2) {
                l2 = rev ? l2->prev : l2->next;
@@ -200,24 +200,30 @@ static void edgering_sel(tringselOpData *lcd, int previewlines, int select)
        }
 
        if (!lcd->extend) {
-               EDBM_clear_flag_all(lcd->em, BM_SELECT);
+               EDBM_flag_disable_all(lcd->em, BM_ELEM_SELECT);
        }
 
        if (select) {
-               BMW_Init(&walker, em->bm, BMW_EDGERING,  0,0,0,0,  BMW_NIL_LAY);
-               eed = BMW_Begin(&walker, startedge);
-               for (; eed; eed=BMW_Step(&walker)) {
-                       BM_Select(em->bm, eed, 1);
+               BMW_init(&walker, em->bm, BMW_EDGERING,
+                        BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP,
+                        BMW_NIL_LAY);
+
+               eed = BMW_begin(&walker, startedge);
+               for (; eed; eed=BMW_step(&walker)) {
+                       BM_elem_select_set(em->bm, eed, TRUE);
                }
-               BMW_End(&walker);
+               BMW_end(&walker);
 
                return;
        }
 
-       BMW_Init(&walker, em->bm, BMW_EDGERING,  0,0,0,0,  BMW_NIL_LAY);
-       eed = startedge = BMW_Begin(&walker, startedge);
+       BMW_init(&walker, em->bm, BMW_EDGERING,
+                BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP,
+                BMW_NIL_LAY);
+
+       eed = startedge = BMW_begin(&walker, startedge);
        lastv1 = NULL;
-       for (lasteed=NULL; eed; eed=BMW_Step(&walker)) {
+       for (lasteed=NULL; eed; eed=BMW_step(&walker)) {
                if (lasteed) {
                        if (lastv1) {
                                v[1][0] = v[0][0];
@@ -239,17 +245,17 @@ static void edgering_sel(tringselOpData *lcd, int previewlines, int select)
                                co[1][0] = (v[1][1]->co[0] - v[1][0]->co[0])*(i/((float)previewlines+1))+v[1][0]->co[0];
                                co[1][1] = (v[1][1]->co[1] - v[1][0]->co[1])*(i/((float)previewlines+1))+v[1][0]->co[1];
                                co[1][2] = (v[1][1]->co[2] - v[1][0]->co[2])*(i/((float)previewlines+1))+v[1][0]->co[2];                                        
-                               
+
                                BLI_array_growone(edges);
-                               VECCOPY(edges[tot][0], co[0]);
-                               VECCOPY(edges[tot][1], co[1]);
+                               copy_v3_v3(edges[tot][0], co[0]);
+                               copy_v3_v3(edges[tot][1], co[1]);
                                tot++;
                        }
                }
                lasteed = eed;
        }
        
-       if (lasteed != startedge && BM_Edge_Share_Faces(lasteed, startedge)) {
+       if (lasteed != startedge && BM_edge_share_faces(lasteed, startedge)) {
                v[1][0] = v[0][0];
                v[1][1] = v[0][1];
 
@@ -268,13 +274,13 @@ static void edgering_sel(tringselOpData *lcd, int previewlines, int select)
                        co[1][2] = (v[1][1]->co[2] - v[1][0]->co[2])*(i/((float)previewlines+1))+v[1][0]->co[2];                                        
                        
                        BLI_array_growone(edges);
-                       VECCOPY(edges[tot][0], co[0]);
-                       VECCOPY(edges[tot][1], co[1]);
+                       copy_v3_v3(edges[tot][0], co[0]);
+                       copy_v3_v3(edges[tot][1], co[1]);
                        tot++;
                }
        }
 
-       BMW_End(&walker);
+       BMW_end(&walker);
        lcd->edges = edges;
        lcd->totedge = tot;
 }
@@ -302,9 +308,9 @@ static void ringsel_finish(bContext *C, wmOperator *op)
                edgering_sel(lcd, cuts, 1);
                
                if (lcd->do_cut) {
-                       BM_esubdivideflag(lcd->ob, em->bm, BM_SELECT, 0.0f, 
+                       BM_mesh_esubdivideflag(lcd->ob, em->bm, BM_ELEM_SELECT, 0.0f, 
                                          0.0f, 0, cuts, SUBDIV_SELECT_LOOPCUT, 
-                                         SUBD_PATH, 0, 0, 0);
+                                         SUBD_PATH, 0, FALSE, 0);
                        
                        /* force edge slide to edge select mode in in face select mode */
                        if (em->selectmode & SCE_SELECT_FACE) {
@@ -327,9 +333,9 @@ static void ringsel_finish(bContext *C, wmOperator *op)
                        
                        /* sets as active, useful for other tools */
                        if(em->selectmode & SCE_SELECT_VERTEX)
-                               EDBM_selectmode_flush(em);
+                               EDBM_store_selection(em, lcd->eed->v1); /* low priority TODO, get vertrex close to mouse */
                        if(em->selectmode & SCE_SELECT_EDGE)
-                               EDBM_selectmode_flush(em);
+                               EDBM_store_selection(em, lcd->eed);
                        
                        EDBM_selectmode_flush(lcd->em);
                        WM_event_add_notifier(C, NC_GEOM|ND_SELECT, lcd->ob->data);
@@ -341,7 +347,7 @@ static void ringsel_finish(bContext *C, wmOperator *op)
 static void ringsel_exit(bContext *UNUSED(C), wmOperator *op)
 {
        tringselOpData *lcd= op->customdata;
-       
+
        /* deactivate the extra drawing stuff in 3D-View */
        ED_region_draw_cb_exit(lcd->ar->type, lcd->draw_handle);
        
@@ -389,6 +395,56 @@ static int ringcut_cancel (bContext *C, wmOperator *op)
        return OPERATOR_CANCELLED;
 }
 
+/* for bmesh this tool is in bmesh_select.c */
+#if 0
+
+static int ringsel_invoke (bContext *C, wmOperator *op, wmEvent *evt)
+{
+       tringselOpData *lcd;
+       EditEdge *edge;
+       int dist = 75;
+       
+       view3d_operator_needs_opengl(C);
+
+       if (!ringsel_init(C, op, 0))
+               return OPERATOR_CANCELLED;
+       
+       lcd = op->customdata;
+       
+       if (lcd->em->selectmode == SCE_SELECT_FACE) {
+               PointerRNA props_ptr;
+               int extend = RNA_boolean_get(op->ptr, "extend");
+
+               ringsel_exit(op);
+
+               WM_operator_properties_create(&props_ptr, "MESH_OT_loop_select");
+               RNA_boolean_set(&props_ptr, "extend", extend);
+               WM_operator_name_call(C, "MESH_OT_loop_select", WM_OP_INVOKE_REGION_WIN, &props_ptr);
+               WM_operator_properties_free(&props_ptr);
+
+               return OPERATOR_CANCELLED;
+       }
+
+       lcd->vc.mval[0] = evt->mval[0];
+       lcd->vc.mval[1] = evt->mval[1];
+       
+       edge = findnearestedge(&lcd->vc, &dist);
+       if(!edge) {
+               ringsel_exit(op);
+               return OPERATOR_CANCELLED;
+       }
+
+       lcd->eed = edge;
+       ringsel_find_edge(lcd, 1);
+
+       ringsel_finish(C, op);
+       ringsel_exit(op);
+
+       return OPERATOR_FINISHED;
+}
+
+#endif
+
 static int ringcut_invoke (bContext *C, wmOperator *op, wmEvent *evt)
 {
        Object *obedit= CTX_data_edit_object(C);
@@ -525,6 +581,28 @@ static int loopcut_modal (bContext *C, wmOperator *op, wmEvent *event)
        return OPERATOR_RUNNING_MODAL;
 }
 
+/* for bmesh this tool is in bmesh_select.c */
+#if 0
+
+void MESH_OT_edgering_select (wmOperatorType *ot)
+{
+       /* description */
+       ot->name= "Edge Ring Select";
+       ot->idname= "MESH_OT_edgering_select";
+       ot->description= "Select an edge ring";
+       
+       /* callbacks */
+       ot->invoke= ringsel_invoke;
+       ot->poll= ED_operator_editmesh_region_view3d; 
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the selection");
+}
+
+#endif
+
 void MESH_OT_loopcut (wmOperatorType *ot)
 {
        /* description */