merge with 2.5 (not trunk, last merge message said that on accident) at r22252
[blender.git] / source / blender / editors / mesh / editmesh_mods.c
index 8691070654067b96693208203aefb066e5957ddf..97c72dc49ca30c18be3fe8a732582dfbb3722a75 100644 (file)
@@ -83,6 +83,7 @@ editmesh_mods.c, UI level access, no geometry changes
 #include "ED_mesh.h"
 #include "ED_screen.h"
 #include "ED_view3d.h"
+#include "bmesh.h"
 
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
@@ -99,6 +100,7 @@ static int pupmenu() {return 0;}
 
 void EM_select_mirrored(Object *obedit, EditMesh *em)
 {
+#if 0
        if(em->selectmode & SCE_SELECT_VERTEX) {
                EditVert *eve, *v1;
                
@@ -112,6 +114,7 @@ void EM_select_mirrored(Object *obedit, EditMesh *em)
                        }
                }
        }
+#endif
 }
 
 void EM_automerge(int update) 
@@ -326,320 +329,6 @@ int EM_init_backbuf_circle(ViewContext *vc, short xs, short ys, short rads)
        
 }
 
-static void findnearestvert__doClosest(void *userData, EditVert *eve, int x, int y, int index)
-{
-       struct { short mval[2], pass, select, strict; int dist, lastIndex, closestIndex; EditVert *closest; } *data = userData;
-
-       if (data->pass==0) {
-               if (index<=data->lastIndex)
-                       return;
-       } else {
-               if (index>data->lastIndex)
-                       return;
-       }
-
-       if (data->dist>3) {
-               int temp = abs(data->mval[0] - x) + abs(data->mval[1]- y);
-               if ((eve->f&1) == data->select) {
-                       if (data->strict == 1)
-                               return;
-                       else
-                               temp += 5;
-               }
-
-               if (temp<data->dist) {
-                       data->dist = temp;
-                       data->closest = eve;
-                       data->closestIndex = index;
-               }
-       }
-}
-
-
-
-
-static unsigned int findnearestvert__backbufIndextest(void *handle, unsigned int index)
-{
-       EditMesh *em= (EditMesh *)handle;
-       EditVert *eve = BLI_findlink(&em->verts, index-1);
-
-       if(eve && (eve->f & SELECT)) return 0;
-       return 1; 
-}
-/**
- * findnearestvert
- * 
- * dist (in/out): minimal distance to the nearest and at the end, actual distance
- * sel: selection bias
- *             if SELECT, selected vertice are given a 5 pixel bias to make them farter than unselect verts
- *             if 0, unselected vertice are given the bias
- * strict: if 1, the vertice corresponding to the sel parameter are ignored and not just biased 
- */
-EditVert *findnearestvert(ViewContext *vc, int *dist, short sel, short strict)
-{
-       if(vc->v3d->drawtype>OB_WIRE && (vc->v3d->flag & V3D_ZBUF_SELECT)){
-               int distance;
-               unsigned int index;
-               EditVert *eve;
-               
-               if(strict) index = view3d_sample_backbuf_rect(vc, vc->mval, 50, em_wireoffs, 0xFFFFFF, &distance, strict, vc->em, findnearestvert__backbufIndextest); 
-               else index = view3d_sample_backbuf_rect(vc, vc->mval, 50, em_wireoffs, 0xFFFFFF, &distance, 0, NULL, NULL); 
-               
-               eve = BLI_findlink(&vc->em->verts, index-1);
-               
-               if(eve && distance < *dist) {
-                       *dist = distance;
-                       return eve;
-               } else {
-                       return NULL;
-               }
-                       
-       }
-       else {
-               struct { short mval[2], pass, select, strict; int dist, lastIndex, closestIndex; EditVert *closest; } data;
-               static int lastSelectedIndex=0;
-               static EditVert *lastSelected=NULL;
-
-               if (lastSelected && BLI_findlink(&vc->em->verts, lastSelectedIndex)!=lastSelected) {
-                       lastSelectedIndex = 0;
-                       lastSelected = NULL;
-               }
-
-               data.lastIndex = lastSelectedIndex;
-               data.mval[0] = vc->mval[0];
-               data.mval[1] = vc->mval[1];
-               data.select = sel;
-               data.dist = *dist;
-               data.strict = strict;
-               data.closest = NULL;
-               data.closestIndex = 0;
-
-               data.pass = 0;
-               mesh_foreachScreenVert(vc, findnearestvert__doClosest, &data, 1);
-
-               if (data.dist>3) {
-                       data.pass = 1;
-                       mesh_foreachScreenVert(vc, findnearestvert__doClosest, &data, 1);
-               }
-
-               *dist = data.dist;
-               lastSelected = data.closest;
-               lastSelectedIndex = data.closestIndex;
-
-               return data.closest;
-       }
-}
-
-/* returns labda for closest distance v1 to line-piece v2-v3 */
-static float labda_PdistVL2Dfl( float *v1, float *v2, float *v3) 
-{
-       float rc[2], len;
-       
-       rc[0]= v3[0]-v2[0];
-       rc[1]= v3[1]-v2[1];
-       len= rc[0]*rc[0]+ rc[1]*rc[1];
-       if(len==0.0f)
-               return 0.0f;
-       
-       return ( rc[0]*(v1[0]-v2[0]) + rc[1]*(v1[1]-v2[1]) )/len;
-}
-
-/* note; uses v3d, so needs active 3d window */
-static void findnearestedge__doClosest(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index)
-{
-       struct { ViewContext vc; float mval[2]; int dist; EditEdge *closest; } *data = userData;
-       float v1[2], v2[2];
-       int distance;
-               
-       v1[0] = x0;
-       v1[1] = y0;
-       v2[0] = x1;
-       v2[1] = y1;
-               
-       distance= PdistVL2Dfl(data->mval, v1, v2);
-               
-       if(eed->f & SELECT) distance+=5;
-       if(distance < data->dist) {
-               if(data->vc.rv3d->rflag & RV3D_CLIPPING) {
-                       float labda= labda_PdistVL2Dfl(data->mval, v1, v2);
-                       float vec[3];
-
-                       vec[0]= eed->v1->co[0] + labda*(eed->v2->co[0] - eed->v1->co[0]);
-                       vec[1]= eed->v1->co[1] + labda*(eed->v2->co[1] - eed->v1->co[1]);
-                       vec[2]= eed->v1->co[2] + labda*(eed->v2->co[2] - eed->v1->co[2]);
-                       Mat4MulVecfl(data->vc.obedit->obmat, vec);
-
-                       if(view3d_test_clipping(data->vc.rv3d, vec)==0) {
-                               data->dist = distance;
-                               data->closest = eed;
-                       }
-               }
-               else {
-                       data->dist = distance;
-                       data->closest = eed;
-               }
-       }
-}
-EditEdge *findnearestedge(ViewContext *vc, int *dist)
-{
-
-       if(vc->v3d->drawtype>OB_WIRE && (vc->v3d->flag & V3D_ZBUF_SELECT)) {
-               int distance;
-               unsigned int index = view3d_sample_backbuf_rect(vc, vc->mval, 50, em_solidoffs, em_wireoffs, &distance,0, NULL, NULL);
-               EditEdge *eed = BLI_findlink(&vc->em->edges, index-1);
-
-               if (eed && distance<*dist) {
-                       *dist = distance;
-                       return eed;
-               } else {
-                       return NULL;
-               }
-       }
-       else {
-               struct { ViewContext vc; float mval[2]; int dist; EditEdge *closest; } data;
-
-               data.vc= *vc;
-               data.mval[0] = vc->mval[0];
-               data.mval[1] = vc->mval[1];
-               data.dist = *dist;
-               data.closest = NULL;
-
-               mesh_foreachScreenEdge(vc, findnearestedge__doClosest, &data, 2);
-
-               *dist = data.dist;
-               return data.closest;
-       }
-}
-
-static void findnearestface__getDistance(void *userData, EditFace *efa, int x, int y, int index)
-{
-       struct { short mval[2]; int dist; EditFace *toFace; } *data = userData;
-
-       if (efa==data->toFace) {
-               int temp = abs(data->mval[0]-x) + abs(data->mval[1]-y);
-
-               if (temp<data->dist)
-                       data->dist = temp;
-       }
-}
-static void findnearestface__doClosest(void *userData, EditFace *efa, int x, int y, int index)
-{
-       struct { short mval[2], pass; int dist, lastIndex, closestIndex; EditFace *closest; } *data = userData;
-
-       if (data->pass==0) {
-               if (index<=data->lastIndex)
-                       return;
-       } else {
-               if (index>data->lastIndex)
-                       return;
-       }
-
-       if (data->dist>3) {
-               int temp = abs(data->mval[0]-x) + abs(data->mval[1]-y);
-
-               if (temp<data->dist) {
-                       data->dist = temp;
-                       data->closest = efa;
-                       data->closestIndex = index;
-               }
-       }
-}
-static EditFace *findnearestface(ViewContext *vc, int *dist)
-{
-
-       if(vc->v3d->drawtype>OB_WIRE && (vc->v3d->flag & V3D_ZBUF_SELECT)) {
-               unsigned int index = view3d_sample_backbuf(vc, vc->mval[0], vc->mval[1]);
-               EditFace *efa = BLI_findlink(&vc->em->faces, index-1);
-
-               if (efa) {
-                       struct { short mval[2]; int dist; EditFace *toFace; } data;
-
-                       data.mval[0] = vc->mval[0];
-                       data.mval[1] = vc->mval[1];
-                       data.dist = 0x7FFF;             /* largest short */
-                       data.toFace = efa;
-
-                       mesh_foreachScreenFace(vc, findnearestface__getDistance, &data);
-
-                       if(vc->em->selectmode == SCE_SELECT_FACE || data.dist<*dist) {  /* only faces, no dist check */
-                               *dist= data.dist;
-                               return efa;
-                       }
-               }
-               
-               return NULL;
-       }
-       else {
-               struct { short mval[2], pass; int dist, lastIndex, closestIndex; EditFace *closest; } data;
-               static int lastSelectedIndex=0;
-               static EditFace *lastSelected=NULL;
-
-               if (lastSelected && BLI_findlink(&vc->em->faces, lastSelectedIndex)!=lastSelected) {
-                       lastSelectedIndex = 0;
-                       lastSelected = NULL;
-               }
-
-               data.lastIndex = lastSelectedIndex;
-               data.mval[0] = vc->mval[0];
-               data.mval[1] = vc->mval[1];
-               data.dist = *dist;
-               data.closest = NULL;
-               data.closestIndex = 0;
-
-               data.pass = 0;
-               mesh_foreachScreenFace(vc, findnearestface__doClosest, &data);
-
-               if (data.dist>3) {
-                       data.pass = 1;
-                       mesh_foreachScreenFace(vc, findnearestface__doClosest, &data);
-               }
-
-               *dist = data.dist;
-               lastSelected = data.closest;
-               lastSelectedIndex = data.closestIndex;
-
-               return data.closest;
-       }
-}
-
-/* best distance based on screen coords. 
-   use em->selectmode to define how to use 
-   selected vertices and edges get disadvantage
-   return 1 if found one
-*/
-static int unified_findnearest(ViewContext *vc, EditVert **eve, EditEdge **eed, EditFace **efa) 
-{
-       EditMesh *em= vc->em;
-       int dist= 75;
-       
-       *eve= NULL;
-       *eed= NULL;
-       *efa= NULL;
-       
-       /* no afterqueue (yet), so we check it now, otherwise the em_xxxofs indices are bad */
-       view3d_validate_backbuf(vc);
-       
-       if(em->selectmode & SCE_SELECT_VERTEX)
-               *eve= findnearestvert(vc, &dist, SELECT, 0);
-       if(em->selectmode & SCE_SELECT_FACE)
-               *efa= findnearestface(vc, &dist);
-
-       dist-= 20;      /* since edges select lines, we give dots advantage of 20 pix */
-       if(em->selectmode & SCE_SELECT_EDGE)
-               *eed= findnearestedge(vc, &dist);
-
-       /* return only one of 3 pointers, for frontbuffer redraws */
-       if(*eed) {
-               *efa= NULL; *eve= NULL;
-       }
-       else if(*efa) {
-               *eve= NULL;
-       }
-       
-       return (*eve || *eed || *efa);
-}
-
-
 /* ****************  SIMILAR "group" SELECTS. FACE, EDGE AND VERTEX ************** */
 
 /* selects new faces/edges/verts based on the existing selection */
@@ -1715,9 +1404,9 @@ void mesh_copy_menu(EditMesh *em, wmOperator *op)
        }
 }
 
-
 /* ****************  LOOP SELECTS *************** */
 
+#if 0
 /* selects quads in loop direction of indicated edge */
 /* only flush over edges with valence <= 2 */
 void faceloop_select(EditMesh *em, EditEdge *startedge, int select)
@@ -1787,6 +1476,7 @@ void faceloop_select(EditMesh *em, EditEdge *startedge, int select)
                }
        }
 }
+#endif
 
 
 /* helper for edgeloop_select, checks for eed->f2 tag in faces */
@@ -1818,6 +1508,34 @@ static int edge_not_in_tagged_face(EditMesh *em, EditEdge *eed)
        - has vertices with valence 2
 */
 static void edgeloop_select(EditMesh *em, EditEdge *starteed, int select)
+{
+       BMesh *bm;
+       BMEdge *e;
+       EditMesh *em2;
+       BMOperator op;
+       BMWalker walker;
+
+       bm = init_editmesh_to_bmesh(em, &op);
+       BMO_Exec_Op(bm, &op);
+
+       e = BMO_Get_MapPointer(bm, &op, "map", starteed);
+
+       BMW_Init(&walker, bm, BMW_LOOP, 0);
+       e = BMW_Begin(&walker, e);
+       for (; e; e=BMW_Step(&walker)) {
+               BM_Select(bm, e, 1);
+       }
+       BMW_End(&walker);
+       
+       BMO_Finish_Op(bm, &op);
+       
+       em2 = bmesh_to_editmesh(bm);
+       BM_Free_Mesh(bm);
+       set_editMesh(em, em2);
+       MEM_freeN(em2);
+}
+
+static void edgeloop_select_old(EditMesh *em, EditEdge *starteed, int select)
 {
        EditVert *eve;
        EditEdge *eed;
@@ -1995,6 +1713,7 @@ static int loop_multiselect(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;       
 }
 
+#if 0 //moved to bmeshutils_mods.c
 void MESH_OT_loop_multi_select(wmOperatorType *ot)
 {
        /* identifiers */
@@ -2011,255 +1730,15 @@ void MESH_OT_loop_multi_select(wmOperatorType *ot)
        /* properties */
        RNA_def_boolean(ot->srna, "ring", 0, "Ring", "");
 }
-
+#endif
                
 /* ***************** MAIN MOUSE SELECTION ************** */
 
 
-/* ***************** loop select (non modal) ************** */
-
-static void mouse_mesh_loop(bContext *C, short mval[2], short extend, short ring)
-{
-       ViewContext vc;
-       EditMesh *em;
-       EditEdge *eed;
-       int select= 1;
-       int dist= 50;
-       
-       em_setup_viewcontext(C, &vc);
-       vc.mval[0]= mval[0];
-       vc.mval[1]= mval[1];
-       em= vc.em;
-       
-       eed= findnearestedge(&vc, &dist);
-       if(eed) {
-               if(extend==0) EM_clear_flag_all(em, SELECT);
-       
-               if((eed->f & SELECT)==0) select=1;
-               else if(extend) select=0;
-
-               if(em->selectmode & SCE_SELECT_FACE) {
-                       faceloop_select(em, eed, select);
-               }
-               else if(em->selectmode & SCE_SELECT_EDGE) {
-                       if(ring)
-                               edgering_select(em, eed, select);
-                       else
-                               edgeloop_select(em, eed, select);
-               }
-               else if(em->selectmode & SCE_SELECT_VERTEX) {
-                       if(ring)
-                               edgering_select(em, eed, select);
-                       else 
-                               edgeloop_select(em, eed, select);
-               }
-
-               EM_selectmode_flush(em);
-//                     if (EM_texFaceCheck())
-               
-               WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, vc.obedit);
-       }
-}
-
-static int mesh_select_loop_invoke(bContext *C, wmOperator *op, wmEvent *event)
-{
-       
-       view3d_operator_needs_opengl(C);
-       
-       mouse_mesh_loop(C, event->mval, RNA_boolean_get(op->ptr, "extend"),
-                                       RNA_boolean_get(op->ptr, "ring"));
-       
-       /* cannot do tweaks for as long this keymap is after transform map */
-       return OPERATOR_FINISHED;
-}
-
-void MESH_OT_loop_select(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Loop Select";
-       ot->idname= "MESH_OT_loop_select";
-       
-       /* api callbacks */
-       ot->invoke= mesh_select_loop_invoke;
-       ot->poll= ED_operator_editmesh;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       /* properties */
-       RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", "");
-       RNA_def_boolean(ot->srna, "ring", 0, "Select Ring", "");
-}
-
 /* ******************* mesh shortest path select, uses prev-selected edge ****************** */
 
-/* since you want to create paths with multiple selects, it doesn't have extend option */
-static void mouse_mesh_shortest_path(bContext *C, short mval[2])
-{
-       ViewContext vc;
-       EditMesh *em;
-       EditEdge *eed;
-       int dist= 50;
-       
-       em_setup_viewcontext(C, &vc);
-       vc.mval[0]= mval[0];
-       vc.mval[1]= mval[1];
-       em= vc.em;
-       
-       eed= findnearestedge(&vc, &dist);
-       if(eed) {
-               Mesh *me= vc.obedit->data;
-               int path = 0;
-               
-               if (em->selected.last) {
-                       EditSelection *ese = em->selected.last;
-                       
-                       if(ese && ese->type == EDITEDGE) {
-                               EditEdge *eed_act;
-                               eed_act = (EditEdge*)ese->data;
-                               if (eed_act != eed) {
-                                       if (edgetag_shortest_path(vc.scene, em, eed_act, eed)) {
-                                               EM_remove_selection(em, eed_act, EDITEDGE);
-                                               path = 1;
-                                       }
-                               }
-                       }
-               }
-               if (path==0) {
-                       int act = (edgetag_context_check(vc.scene, eed)==0);
-                       edgetag_context_set(vc.scene, eed, act); /* switch the edge option */
-               }
-               
-               EM_selectmode_flush(em);
-
-               /* even if this is selected it may not be in the selection list */
-               if(edgetag_context_check(vc.scene, eed)==0)
-                       EM_remove_selection(em, eed, EDITEDGE);
-               else
-                       EM_store_selection(em, eed, EDITEDGE);
-       
-               /* force drawmode for mesh */
-               switch (vc.scene->toolsettings->edge_mode) {
-                       
-                       case EDGE_MODE_TAG_SEAM:
-                               me->drawflag |= ME_DRAWSEAMS;
-                               break;
-                       case EDGE_MODE_TAG_SHARP:
-                               me->drawflag |= ME_DRAWSHARP;
-                               break;
-                       case EDGE_MODE_TAG_CREASE:      
-                               me->drawflag |= ME_DRAWCREASES;
-                               break;
-                       case EDGE_MODE_TAG_BEVEL:
-                               me->drawflag |= ME_DRAWBWEIGHTS;
-                               break;
-               }
-               
-               DAG_object_flush_update(vc.scene, vc.obedit, OB_RECALC_DATA);
-       
-               WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, vc.obedit);
-       }
-}
-
-
-static int mesh_shortest_path_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
-{
-       
-       view3d_operator_needs_opengl(C);
-
-       mouse_mesh_shortest_path(C, event->mval);
-       
-       return OPERATOR_FINISHED;
-}
-       
-void MESH_OT_select_shortest_path(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Shortest Path Select";
-       ot->idname= "MESH_OT_select_shortest_path";
-       
-       /* api callbacks */
-       ot->invoke= mesh_shortest_path_select_invoke;
-       ot->poll= ED_operator_editmesh;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       /* properties */
-       RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", "");
-}
-
-
 /* ************************************************** */
 
-
-/* here actual select happens */
-/* gets called via generic mouse select operator */
-void mouse_mesh(bContext *C, short mval[2], short extend)
-{
-       ViewContext vc;
-       EditVert *eve;
-       EditEdge *eed;
-       EditFace *efa;
-       
-       /* setup view context for argument to callbacks */
-       em_setup_viewcontext(C, &vc);
-       vc.mval[0]= mval[0];
-       vc.mval[1]= mval[1];
-       
-       if(unified_findnearest(&vc, &eve, &eed, &efa)) {
-               
-               if(extend==0) EM_clear_flag_all(vc.em, SELECT);
-               
-               if(efa) {
-                       /* set the last selected face */
-                       EM_set_actFace(vc.em, efa);
-                       
-                       if( (efa->f & SELECT)==0 ) {
-                               EM_store_selection(vc.em, efa, EDITFACE);
-                               EM_select_face_fgon(vc.em, efa, 1);
-                       }
-                       else if(extend) {
-                               EM_remove_selection(vc.em, efa, EDITFACE);
-                               EM_select_face_fgon(vc.em, efa, 0);
-                       }
-               }
-               else if(eed) {
-                       if((eed->f & SELECT)==0) {
-                               EM_store_selection(vc.em, eed, EDITEDGE);
-                               EM_select_edge(eed, 1);
-                       }
-                       else if(extend) {
-                               EM_remove_selection(vc.em, eed, EDITEDGE);
-                               EM_select_edge(eed, 0);
-                       }
-               }
-               else if(eve) {
-                       if((eve->f & SELECT)==0) {
-                               eve->f |= SELECT;
-                               EM_store_selection(vc.em, eve, EDITVERT);
-                       }
-                       else if(extend){ 
-                               EM_remove_selection(vc.em, eve, EDITVERT);
-                               eve->f &= ~SELECT;
-                       }
-               }
-               
-               EM_selectmode_flush(vc.em);
-                 
-//             if (EM_texFaceCheck()) {
-
-               if (efa && efa->mat_nr != vc.obedit->actcol-1) {
-                       vc.obedit->actcol= efa->mat_nr+1;
-                       vc.em->mat_nr= efa->mat_nr;
-//                     BIF_preview_changed(ID_MA);
-               }
-       }
-
-       WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, vc.obedit);
-       
-}
-
 /* *********** select linked ************* */
 
 /* for use with selectconnected_delimit_mesh only! */
@@ -2277,6 +1756,7 @@ else              efa->tmp.l=             efa->e1->tmp.l= efa->e2->tmp.l= efa->e3->tmp.l= 1;
 /* legacy warning, this function combines too much :) */
 static int select_linked_limited_invoke(ViewContext *vc, short all, short sel)
 {
+#if 0 //BMESH_TODO
        EditMesh *em= vc->em;
        EditFace *efa;
        EditEdge *eed;
@@ -2367,7 +1847,7 @@ static int select_linked_limited_invoke(ViewContext *vc, short all, short sel)
                                EM_select_face(efa, 1);
        
        //      if (EM_texFaceCheck())
-       
+#endif
        return OPERATOR_FINISHED;
 }
 
@@ -2375,121 +1855,15 @@ static int select_linked_limited_invoke(ViewContext *vc, short all, short sel)
 #undef is_face_tag
 #undef face_tag
 
-static int select_linked_pick_invoke(bContext *C, wmOperator *op, wmEvent *event)
+/* ************************* */
+
+void selectconnected_mesh_all(EditMesh *em)
 {
-       Object *obedit= CTX_data_edit_object(C);
-       ViewContext vc;
-       EditVert *eve, *v1, *v2;
+       EditVert *v1,*v2;
        EditEdge *eed;
-       EditFace *efa;
        short done=1, toggle=0;
-       int sel= !RNA_boolean_get(op->ptr, "deselect");
-       int limit= RNA_boolean_get(op->ptr, "limit");
-       
-       /* unified_finednearest needs ogl */
-       view3d_operator_needs_opengl(C);
-       
-       /* setup view context for argument to callbacks */
-       em_setup_viewcontext(C, &vc);
-       
-       if(vc.em->edges.first==0) return OPERATOR_CANCELLED;
-       
-       vc.mval[0]= event->mval[0];
-       vc.mval[1]= event->mval[1];
-       
-       /* return warning! */
-       if(limit) {
-               int retval= select_linked_limited_invoke(&vc, 0, sel);
-               WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
-               return retval;
-       }
-       
-       if( unified_findnearest(&vc, &eve, &eed, &efa)==0 ) {
-               WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
-       
-               return OPERATOR_CANCELLED;
-       }
-
-       /* clear test flags */
-       for(v1= vc.em->verts.first; v1; v1= v1->next) v1->f1= 0;
        
-       /* start vertex/face/edge */
-       if(eve) eve->f1= 1;
-       else if(eed) eed->v1->f1= eed->v2->f1= 1;
-       else efa->v1->f1= efa->v2->f1= efa->v3->f1= 1;
-       
-       /* set flag f1 if affected */
-       while(done==1) {
-               done= 0;
-               toggle++;
-               
-               if(toggle & 1) eed= vc.em->edges.first;
-               else eed= vc.em->edges.last;
-               
-               while(eed) {
-                       v1= eed->v1;
-                       v2= eed->v2;
-                       
-                       if(eed->h==0) {
-                               if(v1->f1 && v2->f1==0) {
-                                       v2->f1= 1;
-                                       done= 1;
-                               }
-                               else if(v1->f1==0 && v2->f1) {
-                                       v1->f1= 1;
-                                       done= 1;
-                               }
-                       }
-                       
-                       if(toggle & 1) eed= eed->next;
-                       else eed= eed->prev;
-               }
-       }
-       
-       /* now use vertex f1 flag to select/deselect */
-       for(eed= vc.em->edges.first; eed; eed= eed->next) {
-               if(eed->v1->f1 && eed->v2->f1) 
-                       EM_select_edge(eed, sel);
-       }
-       for(efa= vc.em->faces.first; efa; efa= efa->next) {
-               if(efa->v1->f1 && efa->v2->f1 && efa->v3->f1 && (efa->v4==NULL || efa->v4->f1)) 
-                       EM_select_face(efa, sel);
-       }
-       /* no flush needed, connected geometry is done */
-       
-//     if (EM_texFaceCheck())
-       
-       WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
-       return OPERATOR_FINISHED;       
-}
-
-void MESH_OT_select_linked_pick(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Select Linked";
-       ot->idname= "MESH_OT_select_linked_pick";
-       
-       /* api callbacks */
-       ot->invoke= select_linked_pick_invoke;
-       ot->poll= ED_operator_editmesh;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       RNA_def_boolean(ot->srna, "deselect", 0, "Deselect", "");
-       RNA_def_boolean(ot->srna, "limit", 0, "Limit by Seams", "");
-}
-
-
-/* ************************* */
-
-void selectconnected_mesh_all(EditMesh *em)
-{
-       EditVert *v1,*v2;
-       EditEdge *eed;
-       short done=1, toggle=0;
-       
-       if(em->edges.first==0) return;
+       if(em->edges.first==0) return;
        
        while(done==1) {
                done= 0;
@@ -2526,240 +1900,8 @@ void selectconnected_mesh_all(EditMesh *em)
        //      if (EM_texFaceCheck())
 }
 
-static int select_linked_exec(bContext *C, wmOperator *op)
-{
-       Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= BKE_mesh_get_editmesh(obedit->data);
-       
-       if( RNA_boolean_get(op->ptr, "limit") ) {
-               ViewContext vc;
-               em_setup_viewcontext(C, &vc);
-               select_linked_limited_invoke(&vc, 1, 1);
-       }
-       else
-               selectconnected_mesh_all(em);
-       
-       WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
-
-       BKE_mesh_end_editmesh(obedit->data, em);
-       return OPERATOR_FINISHED;       
-}
-
-void MESH_OT_select_linked(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Select Linked All";
-       ot->idname= "MESH_OT_select_linked";
-       
-       /* api callbacks */
-       ot->exec= select_linked_exec;
-       ot->poll= ED_operator_editmesh;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       RNA_def_boolean(ot->srna, "limit", 0, "Limit by Seams", "");
-}
-
-
 /* ************************* */
 
-/* swap is 0 or 1, if 1 it hides not selected */
-void EM_hide_mesh(EditMesh *em, int swap)
-{
-       EditVert *eve;
-       EditEdge *eed;
-       EditFace *efa;
-       int a;
-       
-       if(em==NULL) return;
-
-       /* hide happens on least dominant select mode, and flushes up, not down! (helps preventing errors in subsurf) */
-       /*  - vertex hidden, always means edge is hidden too
-               - edge hidden, always means face is hidden too
-               - face hidden, only set face hide
-               - then only flush back down what's absolute hidden
-       */
-       if(em->selectmode & SCE_SELECT_VERTEX) {
-               for(eve= em->verts.first; eve; eve= eve->next) {
-                       if((eve->f & SELECT)!=swap) {
-                               eve->f &= ~SELECT;
-                               eve->h= 1;
-                       }
-               }
-       
-               for(eed= em->edges.first; eed; eed= eed->next) {
-                       if(eed->v1->h || eed->v2->h) {
-                               eed->h |= 1;
-                               eed->f &= ~SELECT;
-                       }
-               }
-       
-               for(efa= em->faces.first; efa; efa= efa->next) {
-                       if(efa->e1->h & 1 || efa->e2->h & 1 || efa->e3->h & 1 || (efa->e4 && efa->e4->h & 1)) {
-                               efa->h= 1;
-                               efa->f &= ~SELECT;
-                       }
-               }
-       }
-       else if(em->selectmode & SCE_SELECT_EDGE) {
-
-               for(eed= em->edges.first; eed; eed= eed->next) {
-                       if((eed->f & SELECT)!=swap) {
-                               eed->h |= 1;
-                               EM_select_edge(eed, 0);
-                       }
-               }
-
-               for(efa= em->faces.first; efa; efa= efa->next) {
-                       if(efa->e1->h & 1 || efa->e2->h & 1 || efa->e3->h & 1 || (efa->e4 && efa->e4->h & 1)) {
-                               efa->h= 1;
-                               efa->f &= ~SELECT;
-                       }
-               }
-       }
-       else {
-
-               for(efa= em->faces.first; efa; efa= efa->next) {
-                       if((efa->f & SELECT)!=swap) {
-                               efa->h= 1;
-                               EM_select_face(efa, 0);
-                       }
-               }
-       }
-       
-       /* flush down, only whats 100% hidden */
-       for(eve= em->verts.first; eve; eve= eve->next) eve->f1= 0;
-       for(eed= em->edges.first; eed; eed= eed->next) eed->f1= 0;
-       
-       if(em->selectmode & SCE_SELECT_FACE) {
-               for(efa= em->faces.first; efa; efa= efa->next) {
-                       if(efa->h) a= 1; else a= 2;
-                       efa->e1->f1 |= a;
-                       efa->e2->f1 |= a;
-                       efa->e3->f1 |= a;
-                       if(efa->e4) efa->e4->f1 |= a;
-                       /* When edges are not delt with in their own loop, we need to explicitly re-selct select edges that are joined to unselected faces */
-                       if (swap && (em->selectmode == SCE_SELECT_FACE) && (efa->f & SELECT)) {
-                               EM_select_face(efa, 1);
-                       }
-               }
-       }
-       
-       if(em->selectmode >= SCE_SELECT_EDGE) {
-               for(eed= em->edges.first; eed; eed= eed->next) {
-                       if(eed->f1==1) eed->h |= 1;
-                       if(eed->h & 1) a= 1; else a= 2;
-                       eed->v1->f1 |= a;
-                       eed->v2->f1 |= a;
-               }
-       }
-
-       if(em->selectmode >= SCE_SELECT_VERTEX) {
-               for(eve= em->verts.first; eve; eve= eve->next) {
-                       if(eve->f1==1) eve->h= 1;
-               }
-       }
-       
-       em->totedgesel= em->totfacesel= em->totvertsel= 0;
-//     if(EM_texFaceCheck())
-
-       //      DAG_object_flush_update(scene, obedit, OB_RECALC_DATA); 
-}
-
-static int hide_mesh_exec(bContext *C, wmOperator *op)
-{
-       Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
-       
-       EM_hide_mesh(em, RNA_boolean_get(op->ptr, "unselected"));
-               
-       WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
-
-       BKE_mesh_end_editmesh(obedit->data, em);
-       return OPERATOR_FINISHED;       
-}
-
-void MESH_OT_hide(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Hide Selection";
-       ot->idname= "MESH_OT_hide";
-       
-       /* api callbacks */
-       ot->exec= hide_mesh_exec;
-       ot->poll= ED_operator_editmesh;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       /* props */
-       RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected.");
-}
-
-void EM_reveal_mesh(EditMesh *em)
-{
-       EditVert *eve;
-       EditEdge *eed;
-       EditFace *efa;
-       
-       if(em==NULL) return;
-
-       for(eve= em->verts.first; eve; eve= eve->next) {
-               if(eve->h) {
-                       eve->h= 0;
-                       eve->f |= SELECT;
-               }
-       }
-       for(eed= em->edges.first; eed; eed= eed->next) {
-               if(eed->h & 1) {
-                       eed->h &= ~1;
-                       if(em->selectmode & SCE_SELECT_VERTEX); 
-                       else EM_select_edge(eed, 1);
-               }
-       }
-       for(efa= em->faces.first; efa; efa= efa->next) {
-               if(efa->h) {
-                       efa->h= 0;
-                       if(em->selectmode & (SCE_SELECT_EDGE|SCE_SELECT_VERTEX)); 
-                       else EM_select_face(efa, 1);
-               }
-       }
-
-       EM_fgon_flags(em);      /* redo flags and indices for fgons */
-       EM_selectmode_flush(em);
-
-//     if (EM_texFaceCheck())
-//     DAG_object_flush_update(scene, obedit, OB_RECALC_DATA); 
-}
-
-static int reveal_mesh_exec(bContext *C, wmOperator *op)
-{
-       Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
-       
-       EM_reveal_mesh(em);
-
-       WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
-
-       BKE_mesh_end_editmesh(obedit->data, em);
-       return OPERATOR_FINISHED;       
-}
-
-void MESH_OT_reveal(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Reveal Hidden";
-       ot->idname= "MESH_OT_reveal";
-       
-       /* api callbacks */
-       ot->exec= reveal_mesh_exec;
-       ot->poll= ED_operator_editmesh;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-}
-
 int select_by_number_vertices_exec(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
@@ -3150,316 +2292,76 @@ void select_non_manifold(EditMesh *em, wmOperator *op )
        }
 
        /* select verts that are attached to an edge that does not
-        * have 2 neighboring faces */
-       eed= em->edges.first;
-       while(eed) {
-               if (eed->h==0 && eed->f1 != 2) {
-                       EM_select_edge(eed, 1);
-               }
-               eed= eed->next;
-       }
-
-       /* select isolated verts */
-       if(em->selectmode & SCE_SELECT_VERTEX) {
-               eve= em->verts.first;
-               while(eve) {
-                       if (eve->f1 == 0) {
-                               if (!eve->h) eve->f |= SELECT;
-                       }
-                       eve= eve->next;
-               }
-       }
-
-//     if (EM_texFaceCheck())
-
-}
-
-static int select_non_manifold_exec(bContext *C, wmOperator *op)
-{
-       Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
-       
-       select_non_manifold(em, op);
-       
-       WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
-
-       BKE_mesh_end_editmesh(obedit->data, em);
-       return OPERATOR_FINISHED;       
-}
-
-void MESH_OT_select_non_manifold(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Select Non Manifold";
-       ot->idname= "MESH_OT_select_non_manifold";
-       
-       /* api callbacks */
-       ot->exec= select_non_manifold_exec;
-       ot->poll= ED_operator_editmesh;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-}
-
-void EM_select_swap(EditMesh *em) /* exported for UV */
-{
-       EditVert *eve;
-       EditEdge *eed;
-       EditFace *efa;
-       
-       if(em->selectmode & SCE_SELECT_VERTEX) {
-
-               for(eve= em->verts.first; eve; eve= eve->next) {
-                       if(eve->h==0) {
-                               if(eve->f & SELECT) eve->f &= ~SELECT;
-                               else eve->f|= SELECT;
-                       }
-               }
-       }
-       else if(em->selectmode & SCE_SELECT_EDGE) {
-               for(eed= em->edges.first; eed; eed= eed->next) {
-                       if(eed->h==0) {
-                               EM_select_edge(eed, !(eed->f & SELECT));
-                       }
-               }
-       }
-       else {
-               for(efa= em->faces.first; efa; efa= efa->next) {
-                       if(efa->h==0) {
-                               EM_select_face(efa, !(efa->f & SELECT));
-                       }
-               }
-       }
-
-       EM_selectmode_flush(em);
-       
-//     if (EM_texFaceCheck())
-
-}
-
-static int select_inverse_mesh_exec(bContext *C, wmOperator *op)
-{
-       Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
-       
-       EM_select_swap(em);
-       
-       WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
-
-       BKE_mesh_end_editmesh(obedit->data, em);
-       return OPERATOR_FINISHED;       
-}
-
-void MESH_OT_select_inverse(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Select Inverse";
-       ot->idname= "MESH_OT_select_inverse";
-       
-       /* api callbacks */
-       ot->exec= select_inverse_mesh_exec;
-       ot->poll= ED_operator_editmesh;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-}
-       
-/* ******************** (de)select all operator **************** */
-
-void EM_toggle_select_all(EditMesh *em) /* exported for UV */
-{
-       if(EM_nvertices_selected(em))
-               EM_clear_flag_all(em, SELECT);
-       else 
-               EM_set_flag_all(em, SELECT);
-}
-
-static int toggle_select_all_exec(bContext *C, wmOperator *op)
-{
-       Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
-       
-       EM_toggle_select_all(em);
-       
-       WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);     
-       BKE_mesh_end_editmesh(obedit->data, em);
-
-       return OPERATOR_FINISHED;
-}
-
-void MESH_OT_select_all_toggle(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Select/Deselect All";
-       ot->idname= "MESH_OT_select_all_toggle";
-       
-       /* api callbacks */
-       ot->exec= toggle_select_all_exec;
-       ot->poll= ED_operator_editmesh;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-}
-
-/* ******************** **************** */
-
-void EM_select_more(EditMesh *em)
-{
-       EditVert *eve;
-       EditEdge *eed;
-       EditFace *efa;
-       
-       for(eve= em->verts.first; eve; eve= eve->next) {
-               if(eve->f & SELECT) eve->f1= 1;
-               else eve->f1 = 0;
-       }
-       
-       /* set f1 flags in vertices to select 'more' */
-       for(eed= em->edges.first; eed; eed= eed->next) {
-               if(eed->h==0) {
-                       if (eed->v1->f & SELECT)
-                               eed->v2->f1 = 1;
-                       if (eed->v2->f & SELECT)
-                               eed->v1->f1 = 1;
+        * have 2 neighboring faces */
+       eed= em->edges.first;
+       while(eed) {
+               if (eed->h==0 && eed->f1 != 2) {
+                       EM_select_edge(eed, 1);
                }
+               eed= eed->next;
        }
 
-       /* new selected edges, but not in facemode */
-       if(em->selectmode <= SCE_SELECT_EDGE) {
-               
-               for(eed= em->edges.first; eed; eed= eed->next) {
-                       if(eed->h==0) {
-                               if(eed->v1->f1 && eed->v2->f1) EM_select_edge(eed, 1);
+       /* select isolated verts */
+       if(em->selectmode & SCE_SELECT_VERTEX) {
+               eve= em->verts.first;
+               while(eve) {
+                       if (eve->f1 == 0) {
+                               if (!eve->h) eve->f |= SELECT;
                        }
+                       eve= eve->next;
                }
        }
-       /* new selected faces */
-       for(efa= em->faces.first; efa; efa= efa->next) {
-               if(efa->h==0) {
-                       if(efa->v1->f1 && efa->v2->f1 && efa->v3->f1 && (efa->v4==NULL || efa->v4->f1)) 
-                               EM_select_face(efa, 1);
-               }
-       }
+
+//     if (EM_texFaceCheck())
+
 }
 
-static int select_more(bContext *C, wmOperator *op)
+static int select_non_manifold_exec(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data)) ;
-
-       EM_select_more(em);
-
-//     if (EM_texFaceCheck(em))
-
+       EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
+       
+       select_non_manifold(em, op);
+       
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
 
        BKE_mesh_end_editmesh(obedit->data, em);
-       return OPERATOR_FINISHED;
+       return OPERATOR_FINISHED;       
 }
 
-void MESH_OT_select_more(wmOperatorType *ot)
+void MESH_OT_select_non_manifold(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Select More";
-       ot->idname= "MESH_OT_select_more";
-
+       ot->name= "Select Non Manifold";
+       ot->idname= "MESH_OT_select_non_manifold";
+       
        /* api callbacks */
-       ot->exec= select_more;
+       ot->exec= select_non_manifold_exec;
        ot->poll= ED_operator_editmesh;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
-void EM_select_less(EditMesh *em)
-{
-       EditEdge *eed;
-       EditFace *efa;
-
-       if(em->selectmode <= SCE_SELECT_EDGE) {
-               /* eed->f1 == 1:  edge with a selected and deselected vert */ 
-
-               for(eed= em->edges.first; eed; eed= eed->next) {
-                       eed->f1= 0;
-                       if(eed->h==0) {
-                               
-                               if ( !(eed->v1->f & SELECT) && (eed->v2->f & SELECT) ) 
-                                       eed->f1= 1;
-                               if ( (eed->v1->f & SELECT) && !(eed->v2->f & SELECT) ) 
-                                       eed->f1= 1;
-                       }
-               }
-               
-               /* deselect edges with flag set */
-               for(eed= em->edges.first; eed; eed= eed->next) {
-                       if (eed->h==0 && eed->f1 == 1) {
-                               EM_select_edge(eed, 0);
-                       }
-               }
-               EM_deselect_flush(em);
-               
-       }
-       else {
-               /* deselect faces with 1 or more deselect edges */
-               /* eed->f1 == mixed selection edge */
-               for(eed= em->edges.first; eed; eed= eed->next) eed->f1= 0;
-
-               for(efa= em->faces.first; efa; efa= efa->next) {
-                       if(efa->h==0) {
-                               if(efa->f & SELECT) {
-                                       efa->e1->f1 |= 1;
-                                       efa->e2->f1 |= 1;
-                                       efa->e3->f1 |= 1;
-                                       if(efa->e4) efa->e4->f1 |= 1;
-                               }
-                               else {
-                                       efa->e1->f1 |= 2;
-                                       efa->e2->f1 |= 2;
-                                       efa->e3->f1 |= 2;
-                                       if(efa->e4) efa->e4->f1 |= 2;
-                               }
-                       }
-               }
-               for(efa= em->faces.first; efa; efa= efa->next) {
-                       if(efa->h==0) {
-                               if(efa->e1->f1==3 || efa->e2->f1==3 || efa->e3->f1==3 || (efa->e4 && efa->e4->f1==3)) { 
-                                       EM_select_face(efa, 0);
-                               }
-                       }
-               }
-               EM_selectmode_flush(em);
-               
-       }
-}
-
-static int select_less(bContext *C, wmOperator *op)
+static int bmesh_test_exec(bContext *C, wmOperator *op)
 {
-       Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
-
-       EM_select_less(em);
-
-//     if (EM_texFaceCheck(em))
-       WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
-
-       BKE_mesh_end_editmesh(obedit->data, em);
        return OPERATOR_FINISHED;
 }
 
-void MESH_OT_select_less(wmOperatorType *ot)
+void MESH_OT_bmesh_test(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Select Less";
-       ot->idname= "MESH_OT_select_less";
-
+       ot->name= "bmesh test op";
+       ot->idname= "MESH_OT_bmesh_test";
+       
        /* api callbacks */
-       ot->exec= select_less;
+       ot->exec= bmesh_test_exec;
        ot->poll= ED_operator_editmesh;
-       
-       /* flags */
+
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
+
 static void selectrandom_mesh(EditMesh *em, float perc) /* randomly selects a user-set % of vertices/edges/faces */
 {
        EditVert *eve;
@@ -3585,157 +2487,6 @@ static void mesh_selection_type(Scene *scene, EditMesh *em, int val)
        }
 }
 
-static EnumPropertyItem prop_mesh_edit_types[] = {
-       {1, "VERT", 0, "Vertices", ""},
-       {2, "EDGE", 0, "Edges", ""},
-       {3, "FACE", 0, "Faces", ""},
-       {0, NULL, 0, NULL, NULL}
-};
-
-static int mesh_selection_type_exec(bContext *C, wmOperator *op)
-{              
-       
-       Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
-
-       mesh_selection_type(CTX_data_scene(C), em, RNA_enum_get(op->ptr,"type"));
-
-       WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
-       
-       BKE_mesh_end_editmesh(obedit->data, em);
-       return OPERATOR_FINISHED;
-}
-
-void MESH_OT_selection_type(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Selection Mode";
-       ot->idname= "MESH_OT_selection_type";
-       
-       /* api callbacks */
-       ot->invoke= WM_menu_invoke;
-       ot->exec= mesh_selection_type_exec;
-       
-       ot->poll= ED_operator_editmesh;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       /* props */
-       RNA_def_enum(ot->srna, "type", prop_mesh_edit_types, 0, "Type", "Set the mesh selection type");
-       
-}
-/* ************************* SEAMS AND EDGES **************** */
-
-static int editmesh_mark_seam(bContext *C, wmOperator *op)
-{
-       Scene *scene = CTX_data_scene(C);
-       Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
-       Mesh *me= ((Mesh *)obedit->data);
-       EditEdge *eed;
-       int clear = RNA_boolean_get(op->ptr, "clear");
-       
-       /* auto-enable seams drawing */
-       if(clear==0) {
-               me->drawflag |= ME_DRAWSEAMS;
-       }
-
-       if(clear) {
-               eed= em->edges.first;
-               while(eed) {
-                       if((eed->h==0) && (eed->f & SELECT)) {
-                               eed->seam = 0;
-                       }
-                       eed= eed->next;
-               }
-       }
-       else {
-               eed= em->edges.first;
-               while(eed) {
-                       if((eed->h==0) && (eed->f & SELECT)) {
-                               eed->seam = 1;
-                       }
-                       eed= eed->next;
-               }
-       }
-
-       BKE_mesh_end_editmesh(obedit->data, em);
-
-       DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
-
-       return OPERATOR_FINISHED;
-}
-
-void MESH_OT_mark_seam(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Mark Seam";
-       ot->idname= "MESH_OT_mark_seam";
-       
-       /* api callbacks */
-       ot->exec= editmesh_mark_seam;
-       ot->poll= ED_operator_editmesh;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       RNA_def_boolean(ot->srna, "clear", 0, "Clear", "");
-}
-
-static int editmesh_mark_sharp(bContext *C, wmOperator *op)
-{
-       Scene *scene = CTX_data_scene(C);
-       Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
-       Mesh *me= ((Mesh *)obedit->data);
-       int clear = RNA_boolean_get(op->ptr, "clear");
-       EditEdge *eed;
-
-       /* auto-enable sharp edge drawing */
-       if(clear == 0) {
-               me->drawflag |= ME_DRAWSHARP;
-       }
-
-       if(!clear) {
-               eed= em->edges.first;
-               while(eed) {
-                       if(!eed->h && (eed->f & SELECT)) eed->sharp = 1;
-                       eed = eed->next;
-               }
-       } else {
-               eed= em->edges.first;
-               while(eed) {
-                       if(!eed->h && (eed->f & SELECT)) eed->sharp = 0;
-                       eed = eed->next;
-               }
-       }
-
-       BKE_mesh_end_editmesh(obedit->data, em);
-
-       DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
-
-       return OPERATOR_FINISHED;
-}
-
-void MESH_OT_mark_sharp(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Mark Sharp";
-       ot->idname= "MESH_OT_mark_sharp";
-       
-       /* api callbacks */
-       ot->exec= editmesh_mark_sharp;
-       ot->poll= ED_operator_editmesh;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       RNA_def_boolean(ot->srna, "clear", 0, "Clear", "");
-}
-
 /* **************** NORMALS ************** */
 
 /* XXX value of select is messed up, it means two things */
@@ -3949,45 +2700,7 @@ void righthandfaces(EditMesh *em, int select)    /* makes faces righthand turning *
        waitcursor(0);
 }
 
-
-static int righthandfaces_exec(bContext *C, wmOperator *op)
-{
-       Scene *scene = CTX_data_scene(C);
-       Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
-       
-       /* 'standard' behaviour - check if selected, then apply relevant selection */
-       
-       // XXX  need other args
-       righthandfaces(em, RNA_boolean_get(op->ptr, "inside"));
-       
-       BKE_mesh_end_editmesh(obedit->data, em);
-
-       DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit); //TODO is this needed ?
-
-       return OPERATOR_FINISHED;       
-}
-
-void MESH_OT_normals_make_consistent(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Make Normals Consistent";
-       ot->idname= "MESH_OT_normals_make_consistent";
-       
-       /* api callbacks */
-       ot->exec= righthandfaces_exec;
-       ot->poll= ED_operator_editmesh;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       RNA_def_boolean(ot->srna, "inside", 0, "Inside", "");
-}
-
 /* ********** ALIGN WITH VIEW **************** */
-
-
 static void editmesh_calc_selvert_center(EditMesh *em, float cent_r[3])
 {
        EditVert *eve;
@@ -4163,6 +2876,7 @@ void editmesh_align_view_to_selected(Object *obedit, EditMesh *em, wmOperator *o
 
 static int smooth_vertex(bContext *C, wmOperator *op)
 {
+#if 0 //BMESH_TODO
        Scene *scene= CTX_data_scene(C);
        Object *obedit= CTX_data_edit_object(C);
        EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
@@ -4173,12 +2887,18 @@ static int smooth_vertex(bContext *C, wmOperator *op)
        int teller=0;
        ModifierData *md;
 
+       if(em==NULL) {
+               BKE_mesh_end_editmesh(obedit->data, em);
+               return OPERATOR_CANCELLED;
+       }
+
        /* count */
        eve= em->verts.first;
        while(eve) {
                if(eve->f & SELECT) teller++;
                eve= eve->next;
        }
+
        if(teller==0) {
                BKE_mesh_end_editmesh(obedit->data, em);
                return OPERATOR_CANCELLED;
@@ -4296,6 +3016,7 @@ static int smooth_vertex(bContext *C, wmOperator *op)
        DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
 
+#endif
        return OPERATOR_FINISHED;
 }
 
@@ -4467,45 +3188,3 @@ void flipface(EditMesh *em, EditFace *efa)
        if(efa->v4) CalcNormFloat4(efa->v1->co, efa->v2->co, efa->v3->co, efa->v4->co, efa->n);
        else CalcNormFloat(efa->v1->co, efa->v2->co, efa->v3->co, efa->n);
 }
-
-
-static int flip_normals(bContext *C, wmOperator *op)
-{
-       Scene *scene = CTX_data_scene(C);
-       Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
-       EditFace *efa;
-       
-       efa= em->faces.first;
-       while(efa) {
-               if( efa->f & SELECT ){
-                       flipface(em, efa);
-               }
-               efa= efa->next;
-       }
-       
-       /* update vertex normals too */
-       recalc_editnormals(em);
-
-       BKE_mesh_end_editmesh(obedit->data, em);
-
-       DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
-
-       return OPERATOR_FINISHED;
-}
-
-void MESH_OT_flip_normals(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Flip Normals";
-       ot->idname= "MESH_OT_flip_normals";
-       
-       /* api callbacks */
-       ot->exec= flip_normals;
-       ot->poll= ED_operator_editmesh;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-}
-