Cleaning up manipulator code a bit
authorMartin Poirier <theeth@yahoo.com>
Sun, 12 Jul 2009 02:01:13 +0000 (02:01 +0000)
committerMartin Poirier <theeth@yahoo.com>
Sun, 12 Jul 2009 02:01:13 +0000 (02:01 +0000)
Made transform confirm or cancel on mouse up. More inline with button clicking and better for tablets.

Add operator params to make sure Rip and Extrude turn off PET and Mirror correctly.

Note: sorry for all the whitespace changes, I need to reconfigure this editor not to do autocleanup.

source/blender/editors/include/ED_transform.h
source/blender/editors/mesh/editmesh_tools.c
source/blender/editors/transform/transform.c
source/blender/editors/transform/transform.h
source/blender/editors/transform/transform_constraints.c
source/blender/editors/transform/transform_conversions.c
source/blender/editors/transform/transform_generics.c
source/blender/editors/transform/transform_manipulator.c

index d218585..7680405 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * $Id: ED_transform.h 21450 2009-07-09 02:45:48Z theeth $
+ * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
@@ -119,12 +119,16 @@ struct EnumPropertyItem *BIF_enumTransformOrientation(struct bContext *C);
 char * BIF_menustringTransformOrientation(const struct bContext *C, char *title); /* the returned value was allocated and needs to be freed after use */
 int BIF_countTransformOrientation(const struct bContext *C);
 
-void BIF_getPropCenter(float *center);
-
 void BIF_TransformSetUndo(char *str);
 
 void BIF_selectOrientation(void);
 
+/* to be able to add operator properties to other operators */
+
+void Properties_Proportional(struct wmOperatorType *ot);
+void Properties_Snapping(struct wmOperatorType *ot, short align);
+void Properties_Constraints(struct wmOperatorType *ot);
+
 /* view3d manipulators */
 void initManipulator(int mode);
 void ManipulatorTransform();
index 682b1ee..eab0644 100644 (file)
@@ -1,4 +1,4 @@
- /* $Id: 
+ /* $Id:
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
@@ -133,7 +133,7 @@ struct facesort {
 static int vergface(const void *v1, const void *v2)
 {
        const struct facesort *x1=v1, *x2=v2;
-       
+
        if( x1->x > x2->x ) return 1;
        else if( x1->x < x2->x) return -1;
        return 0;
@@ -146,7 +146,7 @@ void convert_to_triface(EditMesh *em, int direction)
 {
        EditFace *efa, *efan, *next;
        float fac;
-       
+
        efa= em->faces.last;
        while(efa) {
                next= efa->prev;
@@ -167,17 +167,17 @@ void convert_to_triface(EditMesh *em, int direction)
                                        efan= EM_face_from_faces(em, efa, NULL, 1, 2, 3, -1);
                                        if(efa->f & SELECT) EM_select_face(efan, 1);
                                }
-                               
+
                                BLI_remlink(&em->faces, efa);
                                free_editface(em, efa);
                        }
                }
                efa= next;
        }
-       
+
        EM_fgon_flags(em);      // redo flags and indices for fgons
 
-       
+
 }
 
 int removedoublesflag(EditMesh *em, short flag, short automerge, float limit)          /* return amount */
@@ -188,7 +188,7 @@ int removedoublesflag(EditMesh *em, short flag, short automerge, float limit)               /
                                        Used for "Auto Weld" mode. warning.
                limit -         Quick manhattan distance between verts.
        */
-       
+
        /* all verts with (flag & 'flag') are being evaluated */
        EditVert *eve, *v1, *nextve;
        EditEdge *eed, *e1, *nexted;
@@ -196,8 +196,8 @@ int removedoublesflag(EditMesh *em, short flag, short automerge, float limit)               /
        xvertsort *sortblock, *sb, *sb1;
        struct facesort *vlsortblock, *vsb, *vsb1;
        int a, b, test, amount;
-       
-       
+
+
        /* flag 128 is cleared, count */
 
        /* Normal non weld operation */
@@ -223,9 +223,9 @@ int removedoublesflag(EditMesh *em, short flag, short automerge, float limit)               /
        }
        qsort(sortblock, amount, sizeof(xvertsort), vergxco);
 
-       
+
        /* test for doubles */
-       sb= sortblock;  
+       sb= sortblock;
        if (automerge) {
                for(a=0; a<amount; a++, sb++) {
                        eve= sb->v1;
@@ -233,12 +233,12 @@ int removedoublesflag(EditMesh *em, short flag, short automerge, float limit)             /
                                sb1= sb+1;
                                for(b=a+1; b<amount && (eve->f & 128)==0; b++, sb1++) {
                                        if(sb1->x - sb->x > limit) break;
-                                       
+
                                        /* when automarge, only allow unselected->selected */
                                        v1= sb1->v1;
                                        if( (v1->f & 128)==0 ) {
                                                if ((eve->f & flag)==0 && (v1->f & flag)==1) {
-                                                       if(     (float)fabs(v1->co[0]-eve->co[0])<=limit && 
+                                                       if(     (float)fabs(v1->co[0]-eve->co[0])<=limit &&
                                                                (float)fabs(v1->co[1]-eve->co[1])<=limit &&
                                                                (float)fabs(v1->co[2]-eve->co[2])<=limit)
                                                        {       /* unique bit */
@@ -246,7 +246,7 @@ int removedoublesflag(EditMesh *em, short flag, short automerge, float limit)               /
                                                                eve->tmp.v = v1;
                                                        }
                                                } else if(      (eve->f & flag)==1 && (v1->f & flag)==0 ) {
-                                                       if(     (float)fabs(v1->co[0]-eve->co[0])<=limit && 
+                                                       if(     (float)fabs(v1->co[0]-eve->co[0])<=limit &&
                                                                (float)fabs(v1->co[1]-eve->co[1])<=limit &&
                                                                (float)fabs(v1->co[2]-eve->co[2])<=limit)
                                                        {       /* unique bit */
@@ -267,10 +267,10 @@ int removedoublesflag(EditMesh *em, short flag, short automerge, float limit)             /
                                        /* first test: simpel dist */
                                        if(sb1->x - sb->x > limit) break;
                                        v1= sb1->v1;
-                                       
+
                                        /* second test: is vertex allowed */
                                        if( (v1->f & 128)==0 ) {
-                                               if(     (float)fabs(v1->co[0]-eve->co[0])<=limit && 
+                                               if(     (float)fabs(v1->co[0]-eve->co[0])<=limit &&
                                                        (float)fabs(v1->co[1]-eve->co[1])<=limit &&
                                                        (float)fabs(v1->co[2]-eve->co[2])<=limit)
                                                {
@@ -283,12 +283,12 @@ int removedoublesflag(EditMesh *em, short flag, short automerge, float limit)             /
                }
        }
        MEM_freeN(sortblock);
-       
+
        if (!automerge)
                for(eve = em->verts.first; eve; eve=eve->next)
                        if((eve->f & flag) && (eve->f & 128))
                                EM_data_interp_from_verts(em, eve, eve->tmp.v, eve->tmp.v, 0.5f);
-       
+
        /* test edges and insert again */
        eed= em->edges.first;
        while(eed) {
@@ -327,7 +327,7 @@ int removedoublesflag(EditMesh *em, short flag, short automerge, float limit)               /
                else if(efa->v2->f & 128) efa->f1= 1;
                else if(efa->v3->f & 128) efa->f1= 1;
                else if(efa->v4 && (efa->v4->f & 128)) efa->f1= 1;
-               
+
                if(efa->f1==1) amount++;
                efa= efa->next;
        }
@@ -337,12 +337,12 @@ int removedoublesflag(EditMesh *em, short flag, short automerge, float limit)             /
        while(efa) {
                nextvl= efa->next;
                if(efa->f1==1) {
-                       
+
                        if(efa->v1->f & 128) efa->v1= efa->v1->tmp.v;
                        if(efa->v2->f & 128) efa->v2= efa->v2->tmp.v;
                        if(efa->v3->f & 128) efa->v3= efa->v3->tmp.v;
                        if(efa->v4 && (efa->v4->f & 128)) efa->v4= efa->v4->tmp.v;
-               
+
                        test= 0;
                        if(efa->v1==efa->v2) test+=1;
                        if(efa->v2==efa->v3) test+=2;
@@ -350,7 +350,7 @@ int removedoublesflag(EditMesh *em, short flag, short automerge, float limit)               /
                        if(efa->v4==efa->v1) test+=8;
                        if(efa->v3==efa->v4) test+=16;
                        if(efa->v2==efa->v4) test+=32;
-                       
+
                        if(test) {
                                if(efa->v4) {
                                        if(test==1 || test==2) {
@@ -378,7 +378,7 @@ int removedoublesflag(EditMesh *em, short flag, short automerge, float limit)               /
                                        amount--;
                                }
                        }
-                       
+
                        if(test==0) {
                                /* set edge pointers */
                                efa->e1= findedgelist(em, efa->v1, efa->v2);
@@ -423,9 +423,9 @@ int removedoublesflag(EditMesh *em, short flag, short automerge, float limit)               /
                        }
                        efa= efa->next;
                }
-               
+
                qsort(vlsortblock, amount, sizeof(struct facesort), vergface);
-                       
+
                vsb= vlsortblock;
                for(a=0; a<amount; a++) {
                        efa= vsb->efa;
@@ -433,24 +433,24 @@ int removedoublesflag(EditMesh *em, short flag, short automerge, float limit)             /
                                vsb1= vsb+1;
 
                                for(b=a+1; b<amount; b++) {
-                               
+
                                        /* first test: same pointer? */
                                        if(vsb->x != vsb1->x) break;
-                                       
+
                                        /* second test: is test permitted? */
                                        efa= vsb1->efa;
                                        if( (efa->f1 & 128)==0 ) {
                                                if( compareface(efa, vsb->efa)) efa->f1 |= 128;
-                                               
+
                                        }
                                        vsb1++;
                                }
                        }
                        vsb++;
                }
-               
+
                MEM_freeN(vlsortblock);
-               
+
                /* remove double faces */
                efa= (struct EditFace *)em->faces.first;
                while(efa) {
@@ -462,7 +462,7 @@ int removedoublesflag(EditMesh *em, short flag, short automerge, float limit)               /
                        efa= nextvl;
                }
        }
-       
+
        /* remove double vertices */
        a= 0;
        eve= (struct EditVert *)em->verts.first;
@@ -495,12 +495,12 @@ static int removedoublesflag_exec(bContext *C, wmOperator *op)
                sprintf(msg, "Removed %d vertices", cnt);
                BKE_report(op->reports, RPT_INFO, msg);
        }
-               
+
        DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
        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_remove_doubles(wmOperatorType *ot)
@@ -508,11 +508,11 @@ void MESH_OT_remove_doubles(wmOperatorType *ot)
        /* identifiers */
        ot->name= "Remove Doubles";
        ot->idname= "MESH_OT_remove_doubles";
-       
+
        /* api callbacks */
        ot->exec= removedoublesflag_exec;
        ot->poll= ED_operator_editmesh;
-       
+
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
@@ -534,18 +534,18 @@ void xsortvert_flag(bContext *C, int flag)
        xvertsort *sortblock;
        ListBase tbase;
        int i, amount;
-       
+
        em_setup_viewcontext(C, &vc);
-       
+
        amount = BLI_countlist(&vc.em->verts);
        sortblock = MEM_callocN(sizeof(xvertsort)*amount,"xsort");
        for (i=0,eve= vc.em->verts.first; eve; i++,eve=eve->next)
                if(eve->f & flag)
                        sortblock[i].v1 = eve;
-       
+
        mesh_foreachScreenVert(&vc, xsortvert_flag__doSetX, sortblock, 0);
        qsort(sortblock, amount, sizeof(xvertsort), vergxco);
-       
+
                /* make temporal listbase */
        tbase.first= tbase.last= 0;
        for (i=0; i<amount; i++) {
@@ -556,9 +556,9 @@ void xsortvert_flag(bContext *C, int flag)
                        BLI_addtail(&tbase, eve);
                }
        }
-       
+
        addlisttolist(&vc.em->verts, &tbase);
-       
+
        MEM_freeN(sortblock);
 
 }
@@ -571,7 +571,7 @@ void hashvert_flag(EditMesh *em, int flag)
        struct xvertsort *sortblock, *sb, onth, *newsort;
        ListBase tbase;
        int amount, a, b;
-       
+
        /* count */
        eve= em->verts.first;
        amount= 0;
@@ -580,7 +580,7 @@ void hashvert_flag(EditMesh *em, int flag)
                eve= eve->next;
        }
        if(amount==0) return;
-       
+
        /* allocate memory */
        sb= sortblock= (struct xvertsort *)MEM_mallocN(sizeof(struct xvertsort)*amount,"sortremovedoub");
        eve= em->verts.first;
@@ -593,7 +593,7 @@ void hashvert_flag(EditMesh *em, int flag)
        }
 
        BLI_srand(1);
-       
+
        sb= sortblock;
        for(a=0; a<amount; a++, sb++) {
                b= (int)(amount*BLI_drand());
@@ -614,9 +614,9 @@ void hashvert_flag(EditMesh *em, int flag)
                BLI_addtail(&tbase, eve);
                sb++;
        }
-       
+
        addlisttolist(&em->verts, &tbase);
-       
+
        MEM_freeN(sortblock);
 
 }
@@ -632,11 +632,11 @@ void extrude_mesh(Object *obedit, EditMesh *em, wmOperator *op)
                if(em->totvertsel==0) nr= 0;
                else if(em->totvertsel==1) nr= 4;
                else if(em->totedgesel==0) nr= 4;
-               else if(em->totfacesel==0) 
+               else if(em->totfacesel==0)
                        nr= 3; // pupmenu("Extrude %t|Only Edges%x3|Only Vertices%x4");
                else if(em->totfacesel==1)
                        nr= 1; // pupmenu("Extrude %t|Region %x1|Only Edges%x3|Only Vertices%x4");
-               else 
+               else
                        nr= 1; // pupmenu("Extrude %t|Region %x1||Individual Faces %x2|Only Edges%x3|Only Vertices%x4");
        }
        else if(em->selectmode & SCE_SELECT_EDGE) {
@@ -654,27 +654,27 @@ void extrude_mesh(Object *obedit, EditMesh *em, wmOperator *op)
                else
                        nr= 1; // pupmenu("Extrude %t|Region %x1||Individual Faces %x2");
        }
-               
+
        if(nr<1) return;
 
        if(nr==1)  transmode= extrudeflag(obedit, em, SELECT, nor);
        else if(nr==4) transmode= extrudeflag_verts_indiv(em, SELECT, nor);
        else if(nr==3) transmode= extrudeflag_edges_indiv(em, SELECT, nor);
        else transmode= extrudeflag_face_indiv(em, SELECT, nor);
-       
+
        if(transmode==0) {
                BKE_report(op->reports, RPT_ERROR, "Not a valid selection for extrude");
        }
        else {
                EM_fgon_flags(em);
-               
-                       /* We need to force immediate calculation here because 
+
+                       /* We need to force immediate calculation here because
                        * transform may use derived objects (which are now stale).
                        *
                        * This shouldn't be necessary, derived queries should be
                        * automatically building this data if invalid. Or something.
                        */
-//             DAG_object_flush_update(scene, obedit, OB_RECALC_DATA); 
+//             DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
                object_handle_update(scene, obedit);
 
                /* individual faces? */
@@ -709,11 +709,12 @@ static int mesh_extrude_invoke(bContext *C, wmOperator *op, wmEvent *event)
 
        DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
-       
-       RNA_int_set(op->ptr, "mode", TFM_TRANSLATION);
-       WM_operator_name_call(C, "TFM_OT_transform", WM_OP_INVOKE_REGION_WIN, op->ptr);
-       
-       return OPERATOR_FINISHED;       
+
+       RNA_enum_set(op->ptr, "proportional", 0);
+       RNA_boolean_set(op->ptr, "mirror", 0);
+       WM_operator_name_call(C, "TFM_OT_translation", WM_OP_INVOKE_REGION_WIN, op->ptr);
+
+       return OPERATOR_FINISHED;
 }
 
 /* extrude without transform */
@@ -722,14 +723,14 @@ static int mesh_extrude_exec(bContext *C, wmOperator *op)
        Scene *scene= CTX_data_scene(C);
        Object *obedit= CTX_data_edit_object(C);
        EditMesh *em= BKE_mesh_get_editmesh(obedit->data);
-       
+
        extrude_mesh(obedit,em, op);
-       
+
        DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
-       
+
        BKE_mesh_end_editmesh(obedit->data, em);
-       return OPERATOR_FINISHED;       
+       return OPERATOR_FINISHED;
 }
 
 
@@ -738,17 +739,18 @@ void MESH_OT_extrude(wmOperatorType *ot)
        /* identifiers */
        ot->name= "Extrude";
        ot->idname= "MESH_OT_extrude";
-       
+
        /* api callbacks */
        ot->invoke= mesh_extrude_invoke;
        ot->exec= mesh_extrude_exec;
        ot->poll= ED_operator_editmesh;
-       
+
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
        /* to give to transform */
-       RNA_def_int(ot->srna, "mode", TFM_TRANSLATION, 0, INT_MAX, "Mode", "", 0, INT_MAX);
+       Properties_Proportional(ot);
+       RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
 }
 
 static int split_mesh(bContext *C, wmOperator *op)
@@ -779,11 +781,11 @@ void MESH_OT_split(wmOperatorType *ot)
        /* identifiers */
        ot->name= "Split";
        ot->idname= "MESH_OT_split";
-       
+
        /* api callbacks */
        ot->exec= split_mesh;
        ot->poll= ED_operator_editmesh;
-       
+
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
@@ -795,10 +797,10 @@ static int extrude_repeat_mesh(bContext *C, wmOperator *op)
        Object *obedit= CTX_data_edit_object(C);
        EditMesh *em= BKE_mesh_get_editmesh((Mesh *)obedit->data);
 
-       RegionView3D *rv3d = ED_view3d_context_rv3d(C);         
-               
+       RegionView3D *rv3d = ED_view3d_context_rv3d(C);
+
        int steps = RNA_int_get(op->ptr,"steps");
-       
+
        float offs = RNA_float_get(op->ptr,"offset");
 
        float dvec[3], tmat[3][3], bmat[3][3], nor[3]= {0.0, 0.0, 0.0};
@@ -822,11 +824,11 @@ static int extrude_repeat_mesh(bContext *C, wmOperator *op)
                extrudeflag(obedit, em, SELECT, nor);
                translateflag(em, SELECT, dvec);
        }
-       
+
        recalc_editnormals(em);
-       
+
        EM_fgon_flags(em);
-       
+
        DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
 
@@ -839,14 +841,14 @@ void MESH_OT_extrude_repeat(wmOperatorType *ot)
        /* identifiers */
        ot->name= "Extrude Repeat Mesh";
        ot->idname= "MESH_OT_extrude_repeat";
-       
+
        /* api callbacks */
        ot->exec= extrude_repeat_mesh;
        ot->poll= ED_operator_editmesh;
-       
+
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
+
        /* props */
        RNA_def_float(ot->srna, "offset", 2.0f, 0.0f, 100.0f, "Offset", "", 0.0f, FLT_MAX);
        RNA_def_int(ot->srna, "steps", 10, 0, 180, "Steps", "", 0, INT_MAX);
@@ -868,7 +870,7 @@ static int spin_mesh(bContext *C, wmOperator *op, float *dvec, int steps, float
        short a, ok= 1;
 
        RNA_float_get_array(op->ptr, "center", cent);
-       
+
        /* imat and center and size */
        Mat3CpyMat4(bmat, obedit->obmat);
        Mat3Inv(imat,bmat);
@@ -895,14 +897,14 @@ static int spin_mesh(bContext *C, wmOperator *op, float *dvec, int steps, float
        Mat3MulMat3(tmat,cmat,bmat);
        Mat3MulMat3(bmat,imat,tmat);
 
-       if(dupli==0) 
-               if(scene->toolsettings->editbutflag & B_KEEPORIG) 
+       if(dupli==0)
+               if(scene->toolsettings->editbutflag & B_KEEPORIG)
                        adduplicateflag(em, 1);
 
        for(a=0; a<steps; a++) {
                if(dupli==0) ok= extrudeflag(obedit, em, SELECT, nor);
                else adduplicateflag(em, SELECT);
-               
+
                if(ok==0)
                        break;
 
@@ -932,7 +934,7 @@ static int spin_mesh(bContext *C, wmOperator *op, float *dvec, int steps, float
 
                DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
        }
-       
+
        BKE_mesh_end_editmesh(obedit->data, em);
        return ok;
 }
@@ -942,7 +944,7 @@ static int spin_mesh_exec(bContext *C, wmOperator *op)
        Scene *scene= CTX_data_scene(C);
        Object *obedit= CTX_data_edit_object(C);
        int ok;
-       
+
        ok= spin_mesh(C, op, NULL, RNA_int_get(op->ptr,"steps"), RNA_float_get(op->ptr,"degrees"), RNA_boolean_get(op->ptr,"dupli"));
        if(ok==0) {
                BKE_report(op->reports, RPT_ERROR, "No valid vertices are selected");
@@ -961,10 +963,10 @@ static int spin_mesh_invoke(bContext *C, wmOperator *op, wmEvent *event)
        Scene *scene = CTX_data_scene(C);
        View3D *v3d = CTX_wm_view3d(C);
        RegionView3D *rv3d= ED_view3d_context_rv3d(C);
-       
+
        RNA_float_set_array(op->ptr, "center", give_cursor(scene, v3d));
        RNA_float_set_array(op->ptr, "axis", rv3d->viewinv[2]);
-       
+
        return spin_mesh_exec(C, op);
 }
 
@@ -973,20 +975,20 @@ void MESH_OT_spin(wmOperatorType *ot)
        /* identifiers */
        ot->name= "Spin";
        ot->idname= "MESH_OT_spin";
-       
+
        /* api callbacks */
        ot->invoke= spin_mesh_invoke;
        ot->exec= spin_mesh_exec;
        ot->poll= EM_view3d_poll;
-       
+
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
+
        /* props */
        RNA_def_int(ot->srna, "steps", 9, 0, INT_MAX, "Steps", "Steps", 0, INT_MAX);
        RNA_def_boolean(ot->srna, "dupli", 0, "Dupli", "Make Duplicates");
        RNA_def_float(ot->srna, "degrees", 90.0f, -FLT_MAX, FLT_MAX, "Degrees", "Degrees", -360.0f, 360.0f);
-       
+
        RNA_def_float_vector(ot->srna, "center", 3, NULL, -FLT_MAX, FLT_MAX, "Center", "Center in global view space", -FLT_MAX, FLT_MAX);
        RNA_def_float_vector(ot->srna, "axis", 3, NULL, -1.0f, 1.0f, "Axis", "Axis in global view space", -FLT_MAX, FLT_MAX);
 
@@ -1004,7 +1006,7 @@ static int screw_mesh_exec(bContext *C, wmOperator *op)
 
        turns= RNA_int_get(op->ptr, "turns");
        steps= RNA_int_get(op->ptr, "steps");
-       
+
        /* clear flags */
        for(eve= em->verts.first; eve; eve= eve->next)
                eve->f1= 0;
@@ -1048,12 +1050,12 @@ static int screw_mesh_exec(bContext *C, wmOperator *op)
                dvec[1]= -dvec[1];
                dvec[2]= -dvec[2];
        }
-       
+
        if(spin_mesh(C, op, dvec, turns*steps, 360.0f*turns, 0)) {
                DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
                WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
 
-               BKE_mesh_end_editmesh(obedit->data, em);                
+               BKE_mesh_end_editmesh(obedit->data, em);
                return OPERATOR_FINISHED;
        }
        else {
@@ -1069,10 +1071,10 @@ static int screw_mesh_invoke(bContext *C, wmOperator *op, wmEvent *event)
        Scene *scene = CTX_data_scene(C);
        View3D *v3d = CTX_wm_view3d(C);
        RegionView3D *rv3d= ED_view3d_context_rv3d(C);
-       
+
        RNA_float_set_array(op->ptr, "center", give_cursor(scene, v3d));
        RNA_float_set_array(op->ptr, "axis", rv3d->viewinv[1]);
-       
+
        return screw_mesh_exec(C, op);
 }
 
@@ -1081,15 +1083,15 @@ void MESH_OT_screw(wmOperatorType *ot)
        /* identifiers */
        ot->name= "Screw";
        ot->idname= "MESH_OT_screw";
-       
+
        /* api callbacks */
        ot->invoke= screw_mesh_invoke;
        ot->exec= screw_mesh_exec;
        ot->poll= EM_view3d_poll;
-       
+
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
+
        /*props */
        RNA_def_int(ot->srna, "steps", 9, 0, INT_MAX, "Steps", "Steps", 0, 256);
        RNA_def_int(ot->srna, "turns", 1, 0, INT_MAX, "Turns", "Turns", 0, 256);
@@ -1101,7 +1103,7 @@ void MESH_OT_screw(wmOperatorType *ot)
 static void erase_edges(EditMesh *em, ListBase *l)
 {
        EditEdge *ed, *nexted;
-       
+
        ed = (EditEdge *) l->first;
        while(ed) {
                nexted= ed->next;
@@ -1127,7 +1129,7 @@ static void erase_faces(EditMesh *em, ListBase *l)
                }
                f = nextf;
        }
-}      
+}
 
 static void erase_vertices(EditMesh *em, ListBase *l)
 {
@@ -1152,7 +1154,7 @@ void delete_mesh(Object *obedit, EditMesh *em, wmOperator *op, int event)
        int count;
        char *str="Erase";
 
-       
+
        if(event<1) return;
 
        if(event==10 ) {
@@ -1160,7 +1162,7 @@ void delete_mesh(Object *obedit, EditMesh *em, wmOperator *op, int event)
                erase_edges(em, &em->edges);
                erase_faces(em, &em->faces);
                erase_vertices(em, &em->verts);
-       } 
+       }
        else if(event==6) {
                if(!EdgeLoopDelete(em, op))
                        return;
@@ -1201,14 +1203,14 @@ void delete_mesh(Object *obedit, EditMesh *em, wmOperator *op, int event)
                        if( efa->v2->f & SELECT) event++;
                        if( efa->v3->f & SELECT) event++;
                        if(efa->v4 && (efa->v4->f & SELECT)) event++;
-                       
+
                        if(event>1) {
                                BLI_remlink(&em->faces, efa);
                                free_editface(em, efa);
                        }
                        efa= nextvl;
                }
-       } 
+       }
        else if(event==1) {
                str= "Erase Edges";
                // faces first
@@ -1220,7 +1222,7 @@ void delete_mesh(Object *obedit, EditMesh *em, wmOperator *op, int event)
                        if( efa->e2->f & SELECT) event++;
                        if( efa->e3->f & SELECT) event++;
                        if(efa->e4 && (efa->e4->f & SELECT)) event++;
-                       
+
                        if(event) {
                                BLI_remlink(&em->faces, efa);
                                free_editface(em, efa);
@@ -1298,12 +1300,12 @@ static int delete_mesh_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);
-       
+
        delete_mesh(obedit, em, op, RNA_enum_get(op->ptr, "type"));
-       
+
        DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
-       
+
        BKE_mesh_end_editmesh(obedit->data, em);
        return OPERATOR_FINISHED;
 }
@@ -1313,16 +1315,16 @@ void MESH_OT_delete(wmOperatorType *ot)
        /* identifiers */
        ot->name= "Delete";
        ot->idname= "MESH_OT_delete";
-       
+
        /* api callbacks */
        ot->invoke= WM_menu_invoke;
        ot->exec= delete_mesh_exec;
-       
+
        ot->poll= ED_operator_editmesh;
-       
+
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
+
        /*props */
        RNA_def_enum(ot->srna, "type", prop_mesh_delete_types, 10, "Type", "Method used for deleting mesh data");
 }
@@ -1344,38 +1346,38 @@ void MESH_OT_delete(wmOperatorType *ot)
 static void alter_co(float *co, EditEdge *edge, float smooth, float fractal, int beauty, float perc)
 {
        float vec1[3], fac;
-       
+
        if(beauty & B_SMOOTH) {
                /* we calculate an offset vector vec1[], to be added to *co */
                float len, fac, nor[3], nor1[3], nor2[3];
-               
+
                VecSubf(nor, edge->v1->co, edge->v2->co);
                len= 0.5f*Normalize(nor);
-       
+
                VECCOPY(nor1, edge->v1->no);
                VECCOPY(nor2, edge->v2->no);
-       
+
                /* cosine angle */
                fac= nor[0]*nor1[0] + nor[1]*nor1[1] + nor[2]*nor1[2] ;
-               
+
                vec1[0]= fac*nor1[0];
                vec1[1]= fac*nor1[1];
                vec1[2]= fac*nor1[2];
-       
+
                /* cosine angle */
                fac= -nor[0]*nor2[0] - nor[1]*nor2[1] - nor[2]*nor2[2] ;
-               
+
                vec1[0]+= fac*nor2[0];
                vec1[1]+= fac*nor2[1];
                vec1[2]+= fac*nor2[2];
 
                /* falloff for multi subdivide */
                smooth *= sqrt(fabs(1.0f - 2.0f*fabs(0.5f-perc)));
-               
+
                vec1[0]*= smooth*len;
                vec1[1]*= smooth*len;
                vec1[2]*= smooth*len;
-               
+
                co[0] += vec1[0];
                co[1] += vec1[1];
                co[2] += vec1[2];
@@ -1403,14 +1405,14 @@ static EditVert *subdivide_edge_addvert(EditMesh *em, EditEdge *edge, float smoo
 {
        EditVert *ev;
        float co[3];
-       
+
        co[0] = (edge->v2->co[0]-edge->v1->co[0])*percent + edge->v1->co[0];
        co[1] = (edge->v2->co[1]-edge->v1->co[1])*percent + edge->v1->co[1];
-       co[2] = (edge->v2->co[2]-edge->v1->co[2])*percent + edge->v1->co[2];                                    
-       
+       co[2] = (edge->v2->co[2]-edge->v1->co[2])*percent + edge->v1->co[2];
+
        /* offset for smooth or sphere or fractal */
        alter_co(co, edge, smooth, fractal, beauty, percent);
-       
+
        /* clip if needed by mirror modifier */
        if (edge->v1->f2) {
                if ( edge->v1->f2 & edge->v2->f2 & 1) {
@@ -1423,18 +1425,18 @@ static EditVert *subdivide_edge_addvert(EditMesh *em, EditEdge *edge, float smoo
                        co[2]= 0.0f;
                }
        }
-       
+
        ev = addvertlist(em, co, NULL);
-       
+
        /* vert data (vgroups, ..) */
        EM_data_interp_from_verts(em, edge->v1, edge->v2, ev, percent);
-       
+
        /* normal */
        ev->no[0] = (edge->v2->no[0]-edge->v1->no[0])*percent + edge->v1->no[0];
        ev->no[1] = (edge->v2->no[1]-edge->v1->no[1])*percent + edge->v1->no[1];
        ev->no[2] = (edge->v2->no[2]-edge->v1->no[2])*percent + edge->v1->no[2];
        Normalize(ev->no);
-       
+
        return ev;
 }
 
@@ -1442,11 +1444,11 @@ static void flipvertarray(EditVert** arr, short size)
 {
        EditVert *hold;
        int i;
-       
+
        for(i=0; i<size/2; i++) {
                hold = arr[i];
                arr[i] = arr[size-i-1];
-               arr[size-i-1] = hold;   
+               arr[size-i-1] = hold;
        }
 }
 
@@ -1459,15 +1461,15 @@ static void facecopy(EditMesh *em, EditFace *source, EditFace *target)
        CustomData_em_copy_data(&em->fdata, &em->fdata, source->data, &target->data);
 
        target->mat_nr = source->mat_nr;
-       target->flag   = source->flag;  
+       target->flag   = source->flag;
        target->h          = source->h;
-       
+
        InterpWeightsQ3Dfl(v1, v2, v3, v4, target->v1->co, w[0]);
        InterpWeightsQ3Dfl(v1, v2, v3, v4, target->v2->co, w[1]);
        InterpWeightsQ3Dfl(v1, v2, v3, v4, target->v3->co, w[2]);
        if (target->v4)
                InterpWeightsQ3Dfl(v1, v2, v3, v4, target->v4->co, w[3]);
-       
+
        CustomData_em_interp(&em->fdata, &source->data, NULL, (float*)w, 1, target->data);
 }
 
@@ -1476,17 +1478,17 @@ static void fill_quad_single(EditMesh *em, EditFace *efa, struct GHash *gh, int
        EditEdge *cedge=NULL;
        EditVert *v[4], **verts;
        EditFace *hold;
-       short start=0, end, left, right, vertsize,i;   
-                                                       
+       short start=0, end, left, right, vertsize,i;
+
        v[0] = efa->v1;
        v[1] = efa->v2;
        v[2] = efa->v3;
-       v[3] = efa->v4;  
+       v[3] = efa->v4;
 
        if(efa->e1->f & SELECT)   { cedge = efa->e1; start = 0;}
-       else if(efa->e2->f & SELECT) { cedge = efa->e2; start = 1;}        
-       else if(efa->e3->f & SELECT) { cedge = efa->e3; start = 2;}        
-       else if(efa->e4->f & SELECT) { cedge = efa->e4; start = 3;}              
+       else if(efa->e2->f & SELECT) { cedge = efa->e2; start = 1;}
+       else if(efa->e3->f & SELECT) { cedge = efa->e3; start = 2;}
+       else if(efa->e4->f & SELECT) { cedge = efa->e4; start = 3;}
 
        // Point verts to the array of new verts for cedge
        verts = BLI_ghash_lookup(gh, cedge);
@@ -1500,30 +1502,30 @@ static void fill_quad_single(EditMesh *em, EditFace *efa, struct GHash *gh, int
        if(verts[0] != v[start]) {flipvertarray(verts,numcuts+2);}
        end     = (start+1)%4;
        left   = (start+2)%4;
-       right  = (start+3)%4; 
-                  
+       right  = (start+3)%4;
+
        /*
        We should have something like this now
 
-                         end            start                           
-                          3   2   1   0   
+                         end            start
+                          3   2   1   0
                           |---*---*---|
                           |               |
-                          |               |       
                           |               |
-                          -------------           
+                          |               |
+                          -------------
                          left     right
 
        where start,end,left, right are indexes of EditFace->v1, etc (stored in v)
        and 0,1,2... are the indexes of the new verts stored in verts
 
        We will fill this case like this or this depending on even or odd cuts
-        
+
                           |---*---*---|                  |---*---|
                           |  /  \  |             |  / \  |
-                          | /     \ |            | /   \ |      
+                          | /     \ |            | /   \ |
                           |/            \|               |/     \|
-                          -------------                  ---------  
+                          -------------                  ---------
        */
 
        // Make center face
@@ -1532,7 +1534,7 @@ static void fill_quad_single(EditMesh *em, EditFace *efa, struct GHash *gh, int
                hold->e2->f2 |= EDGEINNER;
                hold->e4->f2 |= EDGEINNER;
        }else{
-               hold = addfacelist(em, verts[(vertsize-1)/2],v[left],v[right],NULL, NULL,NULL);  
+               hold = addfacelist(em, verts[(vertsize-1)/2],v[left],v[right],NULL, NULL,NULL);
                hold->e1->f2 |= EDGEINNER;
                hold->e3->f2 |= EDGEINNER;
        }
@@ -1540,21 +1542,21 @@ static void fill_quad_single(EditMesh *em, EditFace *efa, struct GHash *gh, int
 
        // Make side faces
        for(i=0;i<(vertsize-1)/2;i++) {
-               hold = addfacelist(em, verts[i],verts[i+1],v[right],NULL,NULL,NULL);  
+               hold = addfacelist(em, verts[i],verts[i+1],v[right],NULL,NULL,NULL);
                facecopy(em, efa,hold);
                if(i+1 != (vertsize-1)/2) {
             if(seltype == SUBDIV_SELECT_INNER) {
                           hold->e2->f2 |= EDGEINNER;
             }
                }
-               hold = addfacelist(em, verts[vertsize-2-i],verts[vertsize-1-i],v[left],NULL,NULL,NULL); 
+               hold = addfacelist(em, verts[vertsize-2-i],verts[vertsize-1-i],v[left],NULL,NULL,NULL);
                facecopy(em, efa,hold);
                if(i+1 != (vertsize-1)/2) {
             if(seltype == SUBDIV_SELECT_INNER) {
                                hold->e3->f2 |= EDGEINNER;
             }
                }
-       }        
+       }
 }
 
 static void fill_tri_single(EditMesh *em, EditFace *efa, struct GHash *gh, int numcuts, int seltype)
@@ -1562,15 +1564,15 @@ static void fill_tri_single(EditMesh *em, EditFace *efa, struct GHash *gh, int n
        EditEdge *cedge=NULL;
        EditVert *v[3], **verts;
        EditFace *hold;
-       short start=0, end, op, vertsize,i;   
-                                                       
+       short start=0, end, op, vertsize,i;
+
        v[0] = efa->v1;
        v[1] = efa->v2;
-       v[2] = efa->v3; 
+       v[2] = efa->v3;
 
        if(efa->e1->f & SELECT)   { cedge = efa->e1; start = 0;}
-       else if(efa->e2->f & SELECT) { cedge = efa->e2; start = 1;}        
-       else if(efa->e3->f & SELECT) { cedge = efa->e3; start = 2;}              
+       else if(efa->e2->f & SELECT) { cedge = efa->e2; start = 1;}
+       else if(efa->e3->f & SELECT) { cedge = efa->e3; start = 2;}
 
        // Point verts to the array of new verts for cedge
        verts = BLI_ghash_lookup(gh, cedge);
@@ -1584,30 +1586,30 @@ static void fill_tri_single(EditMesh *em, EditFace *efa, struct GHash *gh, int n
        if(verts[0] != v[start]) {flipvertarray(verts,numcuts+2);}
           end  = (start+1)%3;
           op    = (start+2)%3;
-                  
+
        /*
        We should have something like this now
 
-                         end            start                           
-                          3   2   1   0   
+                         end            start
+                          3   2   1   0
                           |---*---*---|
                           \               |
-                                \               |         
+                                \               |
                                   \       |
                                         \       |
                                           \   |
                                                 \ |
                                                   |op
-                                                  
+
        where start,end,op are indexes of EditFace->v1, etc (stored in v)
        and 0,1,2... are the indexes of the new verts stored in verts
 
        We will fill this case like this or this depending on even or odd cuts
-        
-                          3   2   1   0   
+
+                          3   2   1   0
                           |---*---*---|
                           \    \  \   |
-                                \      \ \  |     
+                                \      \ \  |
                                   \   \ \ |
                                         \  \ \|
                                           \ \\|
@@ -1617,14 +1619,14 @@ static void fill_tri_single(EditMesh *em, EditFace *efa, struct GHash *gh, int n
 
        // Make side faces
        for(i=0;i<(vertsize-1);i++) {
-               hold = addfacelist(em, verts[i],verts[i+1],v[op],NULL,NULL,NULL);  
+               hold = addfacelist(em, verts[i],verts[i+1],v[op],NULL,NULL,NULL);
                if(i+1 != vertsize-1) {
             if(seltype == SUBDIV_SELECT_INNER) {
                                hold->e2->f2 |= EDGEINNER;
             }
                }
                facecopy(em, efa,hold);
-       }         
+       }
 }
 
 static void fill_quad_double_op(EditMesh *em, EditFace *efa, struct GHash *gh, int numcuts)
@@ -1633,11 +1635,11 @@ static void fill_quad_double_op(EditMesh *em, EditFace *efa, struct GHash *gh, i
        EditVert *v[4], **verts[2];
        EditFace *hold;
        short start=0, end, left, right, vertsize,i;
-                                                       
+
        v[0] = efa->v1;
        v[1] = efa->v2;
        v[2] = efa->v3;
-       v[3] = efa->v4;  
+       v[3] = efa->v4;
 
        if(efa->e1->f & SELECT)   { cedge[0] = efa->e1;  cedge[1] = efa->e3; start = 0;}
        else if(efa->e2->f & SELECT)      { cedge[0] = efa->e2;  cedge[1] = efa->e4; start = 1;}
@@ -1655,39 +1657,39 @@ static void fill_quad_double_op(EditMesh *em, EditFace *efa, struct GHash *gh, i
        if(verts[0][0] != v[start]) {flipvertarray(verts[0],numcuts+2);}
        end     = (start+1)%4;
        left   = (start+2)%4;
-       right  = (start+3)%4; 
-       if(verts[1][0] != v[left]) {flipvertarray(verts[1],numcuts+2);} 
+       right  = (start+3)%4;
+       if(verts[1][0] != v[left]) {flipvertarray(verts[1],numcuts+2);}
        /*
        We should have something like this now
 
-                         end            start                           
-                          3   2   1   0   
+                         end            start
+                          3   2   1   0
                           |---*---*---|
                           |               |
-                          |               |       
                           |               |
-                          |---*---*---|          
+                          |               |
+                          |---*---*---|
                           0   1   2   3
                          left     right
 
        We will fill this case like this or this depending on even or odd cuts
-        
+
                           |---*---*---|
                           |   |   |   |
-                          |   |   |   |           
                           |   |   |   |
-                          |---*---*---| 
+                          |   |   |   |
+                          |---*---*---|
        */
-          
+
        // Make side faces
        for(i=0;i<vertsize-1;i++) {
-               hold = addfacelist(em, verts[0][i],verts[0][i+1],verts[1][vertsize-2-i],verts[1][vertsize-1-i],NULL,NULL);  
+               hold = addfacelist(em, verts[0][i],verts[0][i+1],verts[1][vertsize-2-i],verts[1][vertsize-1-i],NULL,NULL);
                if(i < vertsize-2) {
                        hold->e2->f2 |= EDGEINNER;
                        hold->e2->f2 |= DOUBLEOPFILL;
                }
                facecopy(em, efa,hold);
-       }         
+       }
 }
 
 static void fill_quad_double_adj_path(EditMesh *em, EditFace *efa, struct GHash *gh, int numcuts)
@@ -1697,11 +1699,11 @@ static void fill_quad_double_adj_path(EditMesh *em, EditFace *efa, struct GHash
        EditFace *hold;
        short start=0, start2=0, vertsize,i;
        int ctrl= 0; // XXX
-       
+
        v[0] = efa->v1;
        v[1] = efa->v2;
        v[2] = efa->v3;
-       v[3] = efa->v4;  
+       v[3] = efa->v4;
 
        if(efa->e1->f & SELECT && efa->e2->f & SELECT) {cedge[0] = efa->e1;  cedge[1] = efa->e2; start = 0; start2 = 1;}
        if(efa->e2->f & SELECT && efa->e3->f & SELECT) {cedge[0] = efa->e2;  cedge[1] = efa->e3; start = 1; start2 = 2;}
@@ -1719,53 +1721,53 @@ static void fill_quad_double_adj_path(EditMesh *em, EditFace *efa, struct GHash
        // the array to the correct direction
 
        if(verts[0][0] != v[start]) {flipvertarray(verts[0],numcuts+2);}
-       if(verts[1][0] != v[start2]) {flipvertarray(verts[1],numcuts+2);}       
+       if(verts[1][0] != v[start2]) {flipvertarray(verts[1],numcuts+2);}
        /*
        We should have something like this now
 
-                          end           start                           
-                               3   2   1   0   
+                          end           start
+                               3   2   1   0
                start2 0|---*---*---|
                                |                  |
                           1*              |
                                |                  |
-                          2*              |       
+                          2*              |
                                |                  |
-                end2  3|-----------|   
+                end2  3|-----------|
 
        We will fill this case like this or this depending on even or odd cuts
                           |---*---*---|
                           | /   /   / |
                           *   /   /   |
                           | /   /       |
-                          *   /           |       
+                          *   /           |
                           | /           |
-                          |-----------|  
+                          |-----------|
        */
 
        // Make outside tris
-       hold = addfacelist(em, verts[0][vertsize-2],verts[0][vertsize-1],verts[1][1],NULL,NULL,NULL);  
+       hold = addfacelist(em, verts[0][vertsize-2],verts[0][vertsize-1],verts[1][1],NULL,NULL,NULL);
        /* when ctrl is depressed, only want verts on the cutline selected */
        if (ctrl)
                hold->e3->f2 |= EDGEINNER;
-       facecopy(em, efa,hold);    
+       facecopy(em, efa,hold);
        hold = addfacelist(em, verts[0][0],verts[1][vertsize-1],v[(start2+2)%4],NULL,NULL,NULL);
        /* when ctrl is depressed, only want verts on the cutline selected */
        if (ctrl)
-               hold->e1->f2 |= EDGEINNER;  
-       facecopy(em, efa,hold);                    
+               hold->e1->f2 |= EDGEINNER;
+       facecopy(em, efa,hold);
        //if(scene->toolsettings->editbutflag & B_AUTOFGON) {
        //      hold->e1->h |= EM_FGON;
-       //}     
+       //}
        // Make side faces
 
        for(i=0;i<numcuts;i++) {
-               hold = addfacelist(em, verts[0][i],verts[0][i+1],verts[1][vertsize-1-(i+1)],verts[1][vertsize-1-i],NULL,NULL);  
+               hold = addfacelist(em, verts[0][i],verts[0][i+1],verts[1][vertsize-1-(i+1)],verts[1][vertsize-1-i],NULL,NULL);
                hold->e2->f2 |= EDGEINNER;
                facecopy(em, efa,hold);
        }
        //EM_fgon_flags(em);
-                 
+
 }
 
 static void fill_quad_double_adj_fan(EditMesh *em, EditFace *efa, struct GHash *gh, int numcuts)
@@ -1774,18 +1776,18 @@ static void fill_quad_double_adj_fan(EditMesh *em, EditFace *efa, struct GHash *
        EditVert *v[4], *op=NULL, **verts[2];
        EditFace *hold;
        short start=0, start2=0, vertsize,i;
-                                                       
+
        v[0] = efa->v1;
        v[1] = efa->v2;
        v[2] = efa->v3;
-       v[3] = efa->v4;  
+       v[3] = efa->v4;
 
        if(efa->e1->f & SELECT && efa->e2->f & SELECT) {cedge[0] = efa->e1;  cedge[1] = efa->e2; start = 0; start2 = 1; op = efa->v4;}
        if(efa->e2->f & SELECT && efa->e3->f & SELECT) {cedge[0] = efa->e2;  cedge[1] = efa->e3; start = 1; start2 = 2; op = efa->v1;}
        if(efa->e3->f & SELECT && efa->e4->f & SELECT) {cedge[0] = efa->e3;  cedge[1] = efa->e4; start = 2; start2 = 3; op = efa->v2;}
        if(efa->e4->f & SELECT && efa->e1->f & SELECT) {cedge[0] = efa->e4;  cedge[1] = efa->e1; start = 3; start2 = 0; op = efa->v3;}
 
-       
+
        // Point verts[0] and [1] to the array of new verts for cedge[0] and cedge[1]
        verts[0] = BLI_ghash_lookup(gh, cedge[0]);
        verts[1] = BLI_ghash_lookup(gh, cedge[1]);
@@ -1797,39 +1799,39 @@ static void fill_quad_double_adj_fan(EditMesh *em, EditFace *efa, struct GHash *
        // the array to the correct direction
 
        if(verts[0][0] != v[start]) {flipvertarray(verts[0],numcuts+2);}
-       if(verts[1][0] != v[start2]) {flipvertarray(verts[1],numcuts+2);}       
+       if(verts[1][0] != v[start2]) {flipvertarray(verts[1],numcuts+2);}
        /*
        We should have something like this now
 
-                          end           start                           
-                               3   2   1   0   
+                          end           start
+                               3   2   1   0
                start2 0|---*---*---|
                                |                  |
                           1*              |
                                |                  |
-                          2*              |       
+                          2*              |
                                |                  |
-                end2  3|-----------|op   
+                end2  3|-----------|op
 
        We will fill this case like this or this (warning horrible ascii art follows)
                           |---*---*---|
                           | \  \   \  |
                           *---\  \  \ |
                           |   \ \ \  \|
-                          *---- \ \  \ |          
+                          *---- \ \  \ |
                           |    ---  \\\|
-                          |-----------|  
+                          |-----------|
        */
 
        for(i=0;i<=numcuts;i++) {
-               hold = addfacelist(em, op,verts[1][numcuts-i],verts[1][numcuts-i+1],NULL,NULL,NULL);  
+               hold = addfacelist(em, op,verts[1][numcuts-i],verts[1][numcuts-i+1],NULL,NULL,NULL);
                hold->e1->f2 |= EDGEINNER;
                facecopy(em, efa,hold);
 
-               hold = addfacelist(em, op,verts[0][i],verts[0][i+1],NULL,NULL,NULL);  
+               hold = addfacelist(em, op,verts[0][i],verts[0][i+1],NULL,NULL,NULL);
                hold->e3->f2 |= EDGEINNER;
                facecopy(em, efa,hold);
-       }         
+       }
 }
 
 static void fill_quad_double_adj_inner(EditMesh *em, EditFace *efa, struct GHash *gh, int numcuts)
@@ -1839,18 +1841,18 @@ static void fill_quad_double_adj_inner(EditMesh *em, EditFace *efa, struct GHash
        EditFace *hold;
        short start=0, start2=0, vertsize,i;
        float co[3];
-                                               
+
        v[0] = efa->v1;
        v[1] = efa->v2;
        v[2] = efa->v3;
-       v[3] = efa->v4;  
+       v[3] = efa->v4;
 
        if(efa->e1->f & SELECT && efa->e2->f & SELECT) {cedge[0] = efa->e1;  cedge[1] = efa->e2; start = 0; start2 = 1; op = efa->v4;}
        if(efa->e2->f & SELECT && efa->e3->f & SELECT) {cedge[0] = efa->e2;  cedge[1] = efa->e3; start = 1; start2 = 2; op = efa->v1;}
        if(efa->e3->f & SELECT && efa->e4->f & SELECT) {cedge[0] = efa->e3;  cedge[1] = efa->e4; start = 2; start2 = 3; op = efa->v2;}
        if(efa->e4->f & SELECT && efa->e1->f & SELECT) {cedge[0] = efa->e4;  cedge[1] = efa->e1; start = 3; start2 = 0; op = efa->v3;}
 
-       
+
        // Point verts[0] and [1] to the array of new verts for cedge[0] and cedge[1]
        verts[0] = BLI_ghash_lookup(gh, cedge[0]);
        verts[1] = BLI_ghash_lookup(gh, cedge[1]);
@@ -1862,19 +1864,19 @@ static void fill_quad_double_adj_inner(EditMesh *em, EditFace *efa, struct GHash
        // the array to the correct direction
 
        if(verts[0][0] != v[start]) {flipvertarray(verts[0],numcuts+2);}
-       if(verts[1][0] != v[start2]) {flipvertarray(verts[1],numcuts+2);}       
+       if(verts[1][0] != v[start2]) {flipvertarray(verts[1],numcuts+2);}
        /*
        We should have something like this now
 
-                          end           start                           
-                               3   2   1   0   
+                          end           start
+                               3   2   1   0
                start2 0|---*---*---|
                                |                  |
                           1*              |
                                |                  |
-                          2*              |       
+                          2*              |
                                |                  |
-                end2  3|-----------|op   
+                end2  3|-----------|op
 
        We will fill this case like this or this (warning horrible ascii art follows)
                           |---*-----*---|
@@ -1882,14 +1884,14 @@ static void fill_quad_double_adj_inner(EditMesh *em, EditFace *efa, struct GHash
                           *   \ /       |
                           |    *        |
                           | /    \          |
-                          *        \    |         
+                          *        \    |
                           |           \ |
-                          |-------------|  
+                          |-------------|
        */
 
        // Add Inner Vert(s)
        inner = MEM_mallocN(sizeof(EditVert*)*numcuts,"New inner verts");
-       
+
        for(i=0;i<numcuts;i++) {
                co[0] = (verts[0][numcuts-i]->co[0] + verts[1][i+1]->co[0] ) / 2 ;
                co[1] = (verts[0][numcuts-i]->co[1] + verts[1][i+1]->co[1] ) / 2 ;
@@ -1899,45 +1901,45 @@ static void fill_quad_double_adj_inner(EditMesh *em, EditFace *efa, struct GHash
 
                EM_data_interp_from_verts(em, verts[0][numcuts-i], verts[1][i+1], inner[i], 0.5f);
        }
-       
+
        // Add Corner Quad
-       hold = addfacelist(em, verts[0][numcuts+1],verts[1][1],inner[0],verts[0][numcuts],NULL,NULL);  
+       hold = addfacelist(em, verts[0][numcuts+1],verts[1][1],inner[0],verts[0][numcuts],NULL,NULL);
        hold->e2->f2 |= EDGEINNER;
        hold->e3->f2 |= EDGEINNER;
-       facecopy(em, efa,hold); 
+       facecopy(em, efa,hold);
        // Add Bottom Quads
-       hold = addfacelist(em, verts[0][0],verts[0][1],inner[numcuts-1],op,NULL,NULL);  
+       hold = addfacelist(em, verts[0][0],verts[0][1],inner[numcuts-1],op,NULL,NULL);
        hold->e2->f2 |= EDGEINNER;
-       facecopy(em, efa,hold); 
+       facecopy(em, efa,hold);
 
-       hold = addfacelist(em, op,inner[numcuts-1],verts[1][numcuts],verts[1][numcuts+1],NULL,NULL);  
+       hold = addfacelist(em, op,inner[numcuts-1],verts[1][numcuts],verts[1][numcuts+1],NULL,NULL);
        hold->e2->f2 |= EDGEINNER;
-       facecopy(em, efa,hold);         
-       
+       facecopy(em, efa,hold);
+
        //if(scene->toolsettings->editbutflag & B_AUTOFGON) {
        //      hold->e1->h |= EM_FGON;
-       //}     
+       //}
        // Add Fill Quads (if # cuts > 1)
 
        for(i=0;i<numcuts-1;i++) {
-               hold = addfacelist(em, inner[i],verts[1][i+1],verts[1][i+2],inner[i+1],NULL,NULL);  
+               hold = addfacelist(em, inner[i],verts[1][i+1],verts[1][i+2],inner[i+1],NULL,NULL);
                hold->e1->f2 |= EDGEINNER;
                hold->e3->f2 |= EDGEINNER;
                facecopy(em, efa,hold);
 
-               hold = addfacelist(em, inner[i],inner[i+1],verts[0][numcuts-1-i],verts[0][numcuts-i],NULL,NULL);  
+               hold = addfacelist(em, inner[i],inner[i+1],verts[0][numcuts-1-i],verts[0][numcuts-i],NULL,NULL);
                hold->e2->f2 |= EDGEINNER;
                hold->e4->f2 |= EDGEINNER;
-               facecopy(em, efa,hold); 
-               
+               facecopy(em, efa,hold);
+
                //if(scene->toolsettings->editbutflag & B_AUTOFGON) {
                //      hold->e1->h |= EM_FGON;
-               //}     
-       }       
-       
+               //}
+       }
+
        //EM_fgon_flags(em);
-       
-       MEM_freeN(inner);  
+
+       MEM_freeN(inner);
 }
 
 static void fill_tri_double(EditMesh *em, EditFace *efa, struct GHash *gh, int numcuts)
@@ -1946,7 +1948,7 @@ static void fill_tri_double(EditMesh *em, EditFace *efa, struct GHash *gh, int n
        EditVert *v[3], **verts[2];
        EditFace *hold;
        short start=0, start2=0, vertsize,i;
-                                                       
+
        v[0] = efa->v1;
        v[1] = efa->v2;
        v[2] = efa->v3;
@@ -1966,41 +1968,41 @@ static void fill_tri_double(EditMesh *em, EditFace *efa, struct GHash *gh, int n
        // the array to the correct direction
 
        if(verts[0][0] != v[start]) {flipvertarray(verts[0],numcuts+2);}
-       if(verts[1][0] != v[start2]) {flipvertarray(verts[1],numcuts+2);}       
+       if(verts[1][0] != v[start2]) {flipvertarray(verts[1],numcuts+2);}
        /*
        We should have something like this now
 
-                          end           start                           
-                               3   2   1   0   
+                          end           start
+                               3   2   1   0
                start2 0|---*---*---|
-                               |                /       
-                          1*      /            
-                               |        /               
-                          2*   /                                
-                               | /                
-                end2  3|  
+                               |                /
+                          1*      /
+                               |        /
+                          2*   /
+                               | /
+                end2  3|
 
        We will fill this case like this or this depending on even or odd cuts
                           |---*---*---|
-                          | /   /   / 
-                          *   /   /   
-                          | /   /       
-                          *   /                          
-                          | /           
+                          | /   /   /
+                          *   /   /
+                          | /   /
+                          *   /
+                          | /
                           |
        */
 
        // Make outside tri
-       hold = addfacelist(em, verts[0][vertsize-2],verts[0][vertsize-1],verts[1][1],NULL,NULL,NULL);  
+       hold = addfacelist(em, verts[0][vertsize-2],verts[0][vertsize-1],verts[1][1],NULL,NULL,NULL);
        hold->e3->f2 |= EDGEINNER;
-       facecopy(em, efa,hold);                   
+       facecopy(em, efa,hold);
        // Make side faces
 
        for(i=0;i<numcuts;i++) {
-               hold = addfacelist(em, verts[0][i],verts[0][i+1],verts[1][vertsize-1-(i+1)],verts[1][vertsize-1-i],NULL,NULL);  
+               hold = addfacelist(em, verts[0][i],verts[0][i+1],verts[1][vertsize-1-(i+1)],verts[1][vertsize-1-i],NULL,NULL);
                hold->e2->f2 |= EDGEINNER;
                facecopy(em, efa,hold);
-       }         
+       }
 }
 
 static void fill_quad_triple(EditMesh *em, EditFace *efa, struct GHash *gh, int numcuts)
@@ -2009,133 +2011,133 @@ static void fill_quad_triple(EditMesh *em, EditFace *efa, struct GHash *gh, int
        EditVert *v[4], **verts[3];
        EditFace *hold;
        short start=0, start2=0, start3=0, vertsize, i, repeats;
-       
+
        v[0] = efa->v1;
        v[1] = efa->v2;
        v[2] = efa->v3;
-       v[3] = efa->v4;  
-          
+       v[3] = efa->v4;
+
        if(!(efa->e1->f & SELECT)) {
-               cedge[0] = efa->e2;  
-               cedge[1] = efa->e3; 
+               cedge[0] = efa->e2;
+               cedge[1] = efa->e3;
                cedge[2] = efa->e4;
-               start = 1;start2 = 2;start3 = 3;   
+               start = 1;start2 = 2;start3 = 3;
        }
        if(!(efa->e2->f & SELECT)) {
-               cedge[0] = efa->e3;  
-               cedge[1] = efa->e4; 
+               cedge[0] = efa->e3;
+               cedge[1] = efa->e4;
                cedge[2] = efa->e1;
-               start = 2;start2 = 3;start3 = 0;   
+               start = 2;start2 = 3;start3 = 0;
        }
        if(!(efa->e3->f & SELECT)) {
-               cedge[0] = efa->e4;  
-               cedge[1] = efa->e1; 
+               cedge[0] = efa->e4;
+               cedge[1] = efa->e1;
                cedge[2] = efa->e2;
-               start = 3;start2 = 0;start3 = 1;   
+               start = 3;start2 = 0;start3 = 1;
        }
        if(!(efa->e4->f & SELECT)) {
-               cedge[0] = efa->e1;  
-               cedge[1] = efa->e2; 
+               cedge[0] = efa->e1;
+               cedge[1] = efa->e2;
                cedge[2] = efa->e3;
-               start = 0;start2 = 1;start3 = 2;   
-       }          
+               start = 0;start2 = 1;start3 = 2;
+       }
        // Point verts[0] and [1] to the array of new verts for cedge[0] and cedge[1]
        verts[0] = BLI_ghash_lookup(gh, cedge[0]);
        verts[1] = BLI_ghash_lookup(gh, cedge[1]);
        verts[2] = BLI_ghash_lookup(gh, cedge[2]);
        //This is the index size of the verts array
        vertsize = numcuts+2;
-       
+
        // Is the original v1 the same as the first vert on the selected edge?
        // if not, the edge is running the opposite direction in this face so flip
        // the array to the correct direction
-       
+
        if(verts[0][0] != v[start]) {flipvertarray(verts[0],numcuts+2);}
-       if(verts[1][0] != v[start2]) {flipvertarray(verts[1],numcuts+2);}  
-       if(verts[2][0] != v[start3]) {flipvertarray(verts[2],numcuts+2);}   
+       if(verts[1][0] != v[start2]) {flipvertarray(verts[1],numcuts+2);}
+       if(verts[2][0] != v[start3]) {flipvertarray(verts[2],numcuts+2);}
        /*
         We should have something like this now
-        
-        start2                          
-        3   2   1   0   
-        start3 0|---*---*---|3 
+
+        start2
+        3   2   1   0
+        start3 0|---*---*---|3
         |                 |
         1*                *2
         |                 |
-        2*                *1      
+        2*                *1
         |                 |
-        3|-----------|0 start   
-        
-        We will fill this case like this or this depending on even or odd cuts  
+        3|-----------|0 start
+
+        We will fill this case like this or this depending on even or odd cuts
         there are a couple of differences. For odd cuts, there is a tri in the
         middle as well as 1 quad at the bottom (not including the extra quads
-        for odd cuts > 1                 
-        
+        for odd cuts > 1
+
         For even cuts, there is a quad in the middle and 2 quads on the bottom
-        
+
         they are numbered here for clarity
-        
+
         1 outer tris and bottom quads
         2 inner tri or quad
         3 repeating quads
-        
+
         |---*---*---*---|
         |1/   /  \   \ 1|
         |/ 3 / \  3 \|
         *  /   2   \   *
         | /              \  |
-        |/                     \ | 
+        |/                     \ |
         *---------------*
         |        3             |
-        |                         |  
+        |                         |
         *---------------*
         |                         |
-        |        1             |                                 
+        |        1             |
         |                         |
         |---------------|
-        
+
         |---*---*---*---*---|
-        | 1/   /        \   \ 1|   
-        | /   /           \   \ |  
+        | 1/   /        \   \ 1|
+        | /   /           \   \ |
         |/ 3 /          \ 3 \|
         *   /             \   *
-        |  /                    \  |   
-        | /       2       \ |   
+        |  /                    \  |
+        | /       2       \ |
         |/                              \|
         *-------------------*
         |                                 |
         |               3               |
-        |                                 | 
+        |                                 |
         *-------------------*
         |                                 |
         |               1               |
-        |                                 | 
+        |                                 |
         *-------------------*
         |                                 |
         |              1                 |
-        |                                 | 
+        |                                 |
         |-------------------|
-        
+
         */
 
        // Make outside tris
-       hold = addfacelist(em, verts[0][vertsize-2],verts[0][vertsize-1],verts[1][1],NULL,NULL,NULL);  
+       hold = addfacelist(em, verts[0][vertsize-2],verts[0][vertsize-1],verts[1][1],NULL,NULL,NULL);
        hold->e3->f2 |= EDGEINNER;
-       facecopy(em, efa,hold);   
-       hold = addfacelist(em, verts[1][vertsize-2],verts[1][vertsize-1],verts[2][1],NULL,NULL,NULL);  
+       facecopy(em, efa,hold);
+       hold = addfacelist(em, verts[1][vertsize-2],verts[1][vertsize-1],verts[2][1],NULL,NULL,NULL);
        hold->e3->f2 |= EDGEINNER;
-       facecopy(em, efa,hold);                   
+       facecopy(em, efa,hold);
        // Make bottom quad
-       hold = addfacelist(em, verts[0][0],verts[0][1],verts[2][vertsize-2],verts[2][vertsize-1],NULL,NULL);  
+       hold = addfacelist(em, verts[0][0],verts[0][1],verts[2][vertsize-2],verts[2][vertsize-1],NULL,NULL);
        hold->e2->f2 |= EDGEINNER;
-       facecopy(em, efa,hold);          
+       facecopy(em, efa,hold);
        //If it is even cuts, add the 2nd lower quad
        if(numcuts % 2 == 0) {
-               hold = addfacelist(em, verts[0][1],verts[0][2],verts[2][vertsize-3],verts[2][vertsize-2],NULL,NULL);  
+               hold = addfacelist(em, verts[0][1],verts[0][2],verts[2][vertsize-3],verts[2][vertsize-2],NULL,NULL);
                hold->e2->f2 |= EDGEINNER;
-               facecopy(em, efa,hold);          
+               facecopy(em, efa,hold);
                // Also Make inner quad
-               hold = addfacelist(em, verts[1][numcuts/2],verts[1][(numcuts/2)+1],verts[2][numcuts/2],verts[0][(numcuts/2)+1],NULL,NULL);                 
+               hold = addfacelist(em, verts[1][numcuts/2],verts[1][(numcuts/2)+1],verts[2][numcuts/2],verts[0][(numcuts/2)+1],NULL,NULL);
                hold->e3->f2 |= EDGEINNER;
                //if(scene->toolsettings->editbutflag & B_AUTOFGON) {
                //      hold->e3->h |= EM_FGON;
@@ -2143,47 +2145,47 @@ static void fill_quad_triple(EditMesh *em, EditFace *efa, struct GHash *gh, int
                facecopy(em, efa,hold);
                repeats = (numcuts / 2) -1;
        } else {
-               // Make inner tri        
-               hold = addfacelist(em, verts[1][(numcuts/2)+1],verts[2][(numcuts/2)+1],verts[0][(numcuts/2)+1],NULL,NULL,NULL);            
+               // Make inner tri
+               hold = addfacelist(em, verts[1][(numcuts/2)+1],verts[2][(numcuts/2)+1],verts[0][(numcuts/2)+1],NULL,NULL,NULL);
                hold->e2->f2 |= EDGEINNER;
                //if(scene->toolsettings->editbutflag & B_AUTOFGON) {
                //      hold->e2->h |= EM_FGON;
                //}
-               facecopy(em, efa,hold);   
+               facecopy(em, efa,hold);
                repeats = ((numcuts+1) / 2)-1;
        }
-       
+
        // cuts for 1 and 2 do not have the repeating quads
        if(numcuts < 3) {repeats = 0;}
        for(i=0;i<repeats;i++) {
                //Make side repeating Quads
-               hold = addfacelist(em, verts[1][i+1],verts[1][i+2],verts[0][vertsize-i-3],verts[0][vertsize-i-2],NULL,NULL);  
-               hold->e2->f2 |= EDGEINNER;               
-               facecopy(em, efa,hold);                    
-               hold = addfacelist(em, verts[1][vertsize-i-3],verts[1][vertsize-i-2],verts[2][i+1],verts[2][i+2],NULL,NULL);               
+               hold = addfacelist(em, verts[1][i+1],verts[1][i+2],verts[0][vertsize-i-3],verts[0][vertsize-i-2],NULL,NULL);
+               hold->e2->f2 |= EDGEINNER;
+               facecopy(em, efa,hold);
+               hold = addfacelist(em, verts[1][vertsize-i-3],verts[1][vertsize-i-2],verts[2][i+1],verts[2][i+2],NULL,NULL);
                hold->e4->f2 |= EDGEINNER;
-               facecopy(em, efa,hold); 
+               facecopy(em, efa,hold);
        }
-       // Do repeating bottom quads 
+       // Do repeating bottom quads
        for(i=0;i<repeats;i++) {
-               if(numcuts % 2 == 1) {   
-                       hold = addfacelist(em, verts[0][1+i],verts[0][2+i],verts[2][vertsize-3-i],verts[2][vertsize-2-i],NULL,NULL);  
+               if(numcuts % 2 == 1) {
+                       hold = addfacelist(em, verts[0][1+i],verts[0][2+i],verts[2][vertsize-3-i],verts[2][vertsize-2-i],NULL,NULL);
                } else {
-                       hold = addfacelist(em, verts[0][2+i],verts[0][3+i],verts[2][vertsize-4-i],verts[2][vertsize-3-i],NULL,NULL);                              
+                       hold = addfacelist(em, verts[0][2+i],verts[0][3+i],verts[2][vertsize-4-i],verts[2][vertsize-3-i],NULL,NULL);
                }
                hold->e2->f2 |= EDGEINNER;
-               facecopy(em, efa,hold);                         
-       }       
+               facecopy(em, efa,hold);
+       }
        //EM_fgon_flags(em);
 }
 
 static void fill_quad_quadruple(EditMesh *em, EditFace *efa, struct GHash *gh, int numcuts, float smooth, float fractal, int beauty)
 {
        EditVert **verts[4], ***innerverts;
-       EditFace *hold; 
+       EditFace *hold;
        EditEdge temp;
        short vertsize, i, j;
-       
+
        // Point verts[0] and [1] to the array of new verts for cedge[0] and cedge[1]
        verts[0] = BLI_ghash_lookup(gh, efa->e1);
        verts[1] = BLI_ghash_lookup(gh, efa->e2);
@@ -2198,79 +2200,79 @@ static void fill_quad_quadruple(EditMesh *em, EditFace *efa, struct GHash *gh, i
        // the array to the correct direction
 
        if(verts[0][0] != efa->v1) {flipvertarray(verts[0],numcuts+2);}
-       if(verts[1][0] != efa->v2) {flipvertarray(verts[1],numcuts+2);}  
+       if(verts[1][0] != efa->v2) {flipvertarray(verts[1],numcuts+2);}
        if(verts[2][0] == efa->v3) {flipvertarray(verts[2],numcuts+2);}
-       if(verts[3][0] == efa->v4) {flipvertarray(verts[3],numcuts+2);}  
+       if(verts[3][0] == efa->v4) {flipvertarray(verts[3],numcuts+2);}
        /*
        We should have something like this now
                                          1
-                                                                                 
-                               3   2   1   0   
-                          0|---*---*---|0 
+
+                               3   2   1   0
+                          0|---*---*---|0
                                |           |
                           1*           *1
                     2  |           |   4
-                          2*           *2         
+                          2*           *2
                                |           |
-                          3|---*---*---|3      
+                          3|---*---*---|3
                                3   2   1   0
 
                                          3
        // we will fill a 2 dim array of editvert*s to make filling easier
        //  the innervert order is shown
 
-                               0   0---1---2---3 
+                               0   0---1---2---3
                                        |   |   |   |
-                               1   0---1---2---3 
+                               1   0---1---2---3
                                        |   |   |   |
-                               2   0---1---2---3               
+                               2   0---1---2---3
                                        |   |   |   |
-                               3   0---1---2---3  
-                 
+                               3   0---1---2---3
+
         */
-       innerverts = MEM_mallocN(sizeof(EditVert*)*(numcuts+2),"quad-quad subdiv inner verts outer array"); 
+       innerverts = MEM_mallocN(sizeof(EditVert*)*(numcuts+2),"quad-quad subdiv inner verts outer array");
        for(i=0;i<numcuts+2;i++) {
                innerverts[i] = MEM_mallocN(sizeof(EditVert*)*(numcuts+2),"quad-quad subdiv inner verts inner array");
-       }  
-       
+       }
+
        // first row is e1 last row is e3
        for(i=0;i<numcuts+2;i++) {
                innerverts[0][i]                  = verts[0][(numcuts+1)-i];
                innerverts[numcuts+1][i]  = verts[2][(numcuts+1)-i];
        }
-       
+
        for(i=1;i<=numcuts;i++) {
                /* we create a fake edge for the next loop */
                temp.v2 = innerverts[i][0]                      = verts[1][i];
                temp.v1 = innerverts[i][numcuts+1]  = verts[3][i];
-               
-               for(j=1;j<=numcuts;j++) { 
+
+               for(j=1;j<=numcuts;j++) {
                        float percent= (float)j/(float)(numcuts+1);
 
                        innerverts[i][(numcuts+1)-j]= subdivide_edge_addvert(em, &temp, smooth, fractal, beauty, percent);
-               }       
-       }       
+               }
+       }
        // Fill with faces
        for(i=0;i<numcuts+1;i++) {
                for(j=0;j<numcuts+1;j++) {
-                       hold = addfacelist(em, innerverts[i][j+1],innerverts[i][j],innerverts[i+1][j],innerverts[i+1][j+1],NULL,NULL);   
-                       hold->e1->f2 = EDGENEW;   
-                       hold->e2->f2 = EDGENEW;  
-                       hold->e3->f2 = EDGENEW;                 
-                       hold->e4->f2 = EDGENEW;   
-                       
+                       hold = addfacelist(em, innerverts[i][j+1],innerverts[i][j],innerverts[i+1][j],innerverts[i+1][j+1],NULL,NULL);
+                       hold->e1->f2 = EDGENEW;
+                       hold->e2->f2 = EDGENEW;
+                       hold->e3->f2 = EDGENEW;
+                       hold->e4->f2 = EDGENEW;
+
                        if(i != 0) { hold->e1->f2 |= EDGEINNER; }
                        if(j != 0) { hold->e2->f2 |= EDGEINNER; }
                        if(i != numcuts) { hold->e3->f2 |= EDGEINNER; }
                        if(j != numcuts) { hold->e4->f2 |= EDGEINNER; }
-                       
-                       facecopy(em, efa,hold);         
-               }               
+
+                       facecopy(em, efa,hold);
+               }
        }
        // Clean up our dynamic multi-dim array
        for(i=0;i<numcuts+2;i++) {
-          MEM_freeN(innerverts[i]);   
-       }       
+          MEM_freeN(innerverts[i]);
+       }
        MEM_freeN(innerverts);
 }
 
@@ -2278,7 +2280,7 @@ static void fill_tri_triple(EditMesh *em, EditFace *efa, struct GHash *gh, int n
 {
        EditVert **verts[3], ***innerverts;
        short vertsize, i, j;
-       EditFace *hold;  
+       EditFace *hold;
        EditEdge temp;
 
        // Point verts[0] and [1] to the array of new verts for cedge[0] and cedge[1]
@@ -2294,20 +2296,20 @@ static void fill_tri_triple(EditMesh *em, EditFace *efa, struct GHash *gh, int n
        // the array to the correct direction
 
        if(verts[0][0] != efa->v1) {flipvertarray(verts[0],numcuts+2);}
-       if(verts[1][0] != efa->v2) {flipvertarray(verts[1],numcuts+2);}  
-       if(verts[2][0] != efa->v3) {flipvertarray(verts[2],numcuts+2);}   
+       if(verts[1][0] != efa->v2) {flipvertarray(verts[1],numcuts+2);}
+       if(verts[2][0] != efa->v3) {flipvertarray(verts[2],numcuts+2);}
        /*
        We should have something like this now
                                           3
-                                                                                 
-                               3   2   1   0   
-                          0|---*---*---|3 
-                               |                 /     
-                 1     1*              *2   
-                               |         /       
-                          2*   *1         2             
-                               |  /               
-                          3|/ 
+
+                               3   2   1   0
+                          0|---*---*---|3
+                               |                 /
+                 1     1*              *2
+                               |         /
+                          2*   *1         2
+                               |  /
+                          3|/
                                 0
 
        we will fill a 2 dim array of editvert*s to make filling easier
@@ -2315,33 +2317,33 @@ static void fill_tri_triple(EditMesh *em, EditFace *efa, struct GHash *gh, int n
                                                3
 
                         0  0---1---2---3---4
-                               | / | /  |/  | /        
-                        1  0---1----2---3 
-          1            | /  | / | /    
+                               | / | /  |/  | /
+                        1  0---1----2---3
+          1            | /  | / | /
                         2  0----1---2   2
-                               |  / |  /          
-                               |/   |/   
-                        3  0---1 
+                               |  / |  /
+                               |/   |/
+                        3  0---1
                                |  /
                                |/
-                        4  0  
-         
+                        4  0
+
        */
-       
-       innerverts = MEM_mallocN(sizeof(EditVert*)*(numcuts+2),"tri-tri subdiv inner verts outer array"); 
+
+       innerverts = MEM_mallocN(sizeof(EditVert*)*(numcuts+2),"tri-tri subdiv inner verts outer array");
        for(i=0;i<numcuts+2;i++) {
                  innerverts[i] = MEM_mallocN(sizeof(EditVert*)*((numcuts+2)-i),"tri-tri subdiv inner verts inner array");
        }
        //top row is e3 backwards
        for(i=0;i<numcuts+2;i++) {
                  innerverts[0][i]                = verts[2][(numcuts+1)-i];
-       }   
-                  
+       }
+
        for(i=1;i<=numcuts+1;i++) {
                //fake edge, first vert is from e1, last is from e2
                temp.v1= innerverts[i][0]                         = verts[0][i];
                temp.v2= innerverts[i][(numcuts+1)-i]  = verts[1][(numcuts+1)-i];
-               
+
                for(j=1;j<(numcuts+1)-i;j++) {
                        float percent= (float)j/(float)((numcuts+1)-i);
 
@@ -2351,32 +2353,32 @@ static void fill_tri_triple(EditMesh *em, EditFace *efa, struct GHash *gh, int n
 
        // Now fill the verts with happy little tris :)
        for(i=0;i<=numcuts+1;i++) {
-               for(j=0;j<(numcuts+1)-i;j++) {   
+               for(j=0;j<(numcuts+1)-i;j++) {
                        //We always do the first tri
-                       hold = addfacelist(em, innerverts[i][j+1],innerverts[i][j],innerverts[i+1][j],NULL,NULL,NULL);  
-                       hold->e1->f2 |= EDGENEW;          
-                       hold->e2->f2 |= EDGENEW;  
-                       hold->e3->f2 |= EDGENEW;  
+                       hold = addfacelist(em, innerverts[i][j+1],innerverts[i][j],innerverts[i+1][j],NULL,NULL,NULL);
+                       hold->e1->f2 |= EDGENEW;
+                       hold->e2->f2 |= EDGENEW;
+                       hold->e3->f2 |= EDGENEW;
                        if(i != 0) { hold->e1->f2 |= EDGEINNER; }
                        if(j != 0) { hold->e2->f2 |= EDGEINNER; }
                        if(j+1 != (numcuts+1)-i) {hold->e3->f2 |= EDGEINNER;}
-                       
-                       facecopy(em, efa,hold);         
-                       //if there are more to come, we do the 2nd       
+
+                       facecopy(em, efa,hold);
+                       //if there are more to come, we do the 2nd
                        if(j+1 <= numcuts-i) {
-                               hold = addfacelist(em, innerverts[i+1][j],innerverts[i+1][j+1],innerverts[i][j+1],NULL,NULL,NULL);                 
-                               facecopy(em, efa,hold); 
-                               hold->e1->f2 |= EDGENEW;          
-                               hold->e2->f2 |= EDGENEW;  
-                               hold->e3->f2 |= EDGENEW;        
+                               hold = addfacelist(em, innerverts[i+1][j],innerverts[i+1][j+1],innerverts[i][j+1],NULL,NULL,NULL);
+                               facecopy(em, efa,hold);
+                               hold->e1->f2 |= EDGENEW;
+                               hold->e2->f2 |= EDGENEW;
+                               hold->e3->f2 |= EDGENEW;
                        }
-               } 
+               }
        }
 
        // Clean up our dynamic multi-dim array
        for(i=0;i<numcuts+2;i++) {
-               MEM_freeN(innerverts[i]);   
-       }       
+               MEM_freeN(innerverts[i]);
+       }
        MEM_freeN(innerverts);
 }
 
@@ -2394,7 +2396,7 @@ static void fill_quad_doublevert(EditMesh *em, EditFace *efa, int v1, int v2)
                                |         \     |       | /         |
                                --------X       X--------
        */
-       
+
        if(v1 == 1 && v2 == 3){
                hold= addfacelist(em, efa->v1, efa->v2, efa->v3, 0, efa, NULL);
                hold->e1->f2 |= EDGENEW;
@@ -2402,7 +2404,7 @@ static void fill_quad_doublevert(EditMesh *em, EditFace *efa, int v1, int v2)
                hold->e3->f2 |= EDGENEW;
                hold->e3->f2 |= EDGEINNER;
                facecopy(em, efa, hold);
-               
+
                hold= addfacelist(em, efa->v1, efa->v3, efa->v4, 0, efa, NULL);
                hold->e1->f2 |= EDGENEW;
                hold->e2->f2 |= EDGENEW;
@@ -2417,7 +2419,7 @@ static void fill_quad_doublevert(EditMesh *em, EditFace *efa, int v1, int v2)
                hold->e3->f2 |= EDGENEW;
                hold->e2->f2 |= EDGEINNER;
                facecopy(em, efa, hold);
-               
+
                hold= addfacelist(em, efa->v2, efa->v3, efa->v4, 0, efa, NULL);
                hold->e1->f2 |= EDGENEW;
                hold->e2->f2 |= EDGENEW;
@@ -2432,17 +2434,17 @@ static void fill_quad_singlevert(EditMesh *em, EditFace *efa, struct GHash *gh)
        EditEdge *cedge=NULL;
        EditVert *v[4], **verts;
        EditFace *hold;
-       short start=0, end, left, right, vertsize;   
-                                                       
+       short start=0, end, left, right, vertsize;
+
        v[0] = efa->v1;
        v[1] = efa->v2;
        v[2] = efa->v3;
-       v[3] = efa->v4;  
+       v[3] = efa->v4;
 
        if(efa->e1->f & SELECT)   { cedge = efa->e1; start = 0;}
-       else if(efa->e2->f & SELECT) { cedge = efa->e2; start = 1;}        
-       else if(efa->e3->f & SELECT) { cedge = efa->e3; start = 2;}        
-       else if(efa->e4->f & SELECT) { cedge = efa->e4; start = 3;}              
+       else if(efa->e2->f & SELECT) { cedge = efa->e2; start = 1;}
+       else if(efa->e3->f & SELECT) { cedge = efa->e3; start = 2;}
+       else if(efa->e4->f & SELECT) { cedge = efa->e4; start = 3;}
 
        // Point verts to the array of new verts for cedge
        verts = BLI_ghash_lookup(gh, cedge);
@@ -2456,25 +2458,25 @@ static void fill_quad_singlevert(EditMesh *em, EditFace *efa, struct GHash *gh)
        if(verts[0] != v[start]) {flipvertarray(verts,3);}
        end     = (start+1)%4;
        left   = (start+2)%4;
-       right  = (start+3)%4; 
+       right  = (start+3)%4;
 
 /*
        We should have something like this now
 
-                         end            start                           
-                          2     1     0   
+                         end            start
+                          2     1     0
                           |-----*-----|
                           |               |
-                          |               |       
                           |               |
-                          -------------           
+                          |               |
+                          -------------
                          left     right
 
        where start,end,left, right are indexes of EditFace->v1, etc (stored in v)
        and 0,1,2 are the indexes of the new verts stored in verts. We fill like
        this, depending on whether its vertex 'left' or vertex 'right' thats
        been knifed through...
-                               
+
                                |---*---|       |---*---|
                                |  /    |       |    \  |
                                | /             |       |         \ |
@@ -2490,7 +2492,7 @@ static void fill_quad_singlevert(EditMesh *em, EditFace *efa, struct GHash *gh)
                hold->e3->f2 |= EDGENEW;
                hold->e3->f2 |= EDGEINNER;
                facecopy(em, efa, hold);
-               
+
                //quad is composed of cutvert, left, right and start
                hold = addfacelist(em, verts[1],v[left],v[right],v[start], NULL, NULL);
                hold->e1->f2 |= EDGENEW;
@@ -2517,17 +2519,17 @@ static void fill_quad_singlevert(EditMesh *em, EditFace *efa, struct GHash *gh)
                hold->e4->f2 |= EDGEINNER;
                facecopy(em, efa, hold);
        }
-       
-}      
 
-// This function takes an example edge, the current point to create and 
+}
+
+// This function takes an example edge, the current point to create and
 // the total # of points to create, then creates the point and return the
 // editvert pointer to it.
 static EditVert *subdivideedgenum(EditMesh *em, EditEdge *edge, int curpoint, int totpoint, float smooth, float fractal, int beauty)
 {
        EditVert *ev;
        float percent;
-        
+
        if (beauty & (B_PERCENTSUBD) && totpoint == 1)
                //percent=(float)(edge->tmp.l)/32768.0f;
                percent= edge->tmp.fp;
@@ -2536,7 +2538,7 @@ static EditVert *subdivideedgenum(EditMesh *em, EditEdge *edge, int curpoint, in
 
        ev= subdivide_edge_addvert(em, edge, smooth, fractal, beauty, percent);
        ev->f = edge->v1->f;
-       
+
        return ev;
 }
 
@@ -2550,7 +2552,7 @@ void esubdivideflag(Object *obedit, EditMesh *em, int flag, float smooth, float
        int i, j, edgecount, touchcount, facetype,hold;
        ModifierData *md= obedit->modifiers.first;
        int ctrl= 0; // XXX
-       
+
        //Set faces f1 to 0 cause we need it later
        for(ef=em->faces.first;ef;ef = ef->next) ef->f1 = 0;
        for(eve=em->verts.first; eve; eve=eve->next) {
@@ -2561,8 +2563,8 @@ void esubdivideflag(Object *obedit, EditMesh *em, int flag, float smooth, float
 
        for (; md; md=md->next) {
                if (md->type==eModifierType_Mirror) {
-                       MirrorModifierData *mmd = (MirrorModifierData*) md;     
-               
+                       MirrorModifierData *mmd = (MirrorModifierData*) md;
+
                        if(mmd->flag & MOD_MIR_CLIPPING) {
                                for (eve= em->verts.first; eve; eve= eve->next) {
                                        eve->f2= 0;
@@ -2584,23 +2586,23 @@ void esubdivideflag(Object *obedit, EditMesh *em, int flag, float smooth, float
                        }
                }
        }
-       
+
        //Flush vertex flags upward to the edges
        for(eed = em->edges.first;eed;eed = eed->next) {
                //if(eed->f & flag && eed->v1->f == eed->v2->f) {
-               //      eed->f |= eed->v1->f;   
+               //      eed->f |= eed->v1->f;
                // }
-               eed->f2 = 0;   
+               eed->f2 = 0;
                if(eed->f & flag) {
                        eed->f2 |= EDGEOLD;
                }
        }
-       
+
        // We store an array of verts for each edge that is subdivided,
        // we put this array as a value in a ghash which is keyed by the EditEdge*
 
        // Now for beauty subdivide deselect edges based on length
-       if(beauty & B_BEAUTY) { 
+       if(beauty & B_BEAUTY) {
                for(ef = em->faces.first;ef;ef = ef->next) {
                        if(!ef->v4) {
                                continue;
@@ -2609,12 +2611,12 @@ void esubdivideflag(Object *obedit, EditMesh *em, int flag, float smooth, float
                                VECCOPY(v1mat, ef->v1->co);
                                VECCOPY(v2mat, ef->v2->co);
                                VECCOPY(v3mat, ef->v3->co);
-                               VECCOPY(v4mat, ef->v4->co);                                             
+                               VECCOPY(v4mat, ef->v4->co);
                                Mat4Mul3Vecfl(obedit->obmat, v1mat);
-                               Mat4Mul3Vecfl(obedit->obmat, v2mat);                                                                                    
+                               Mat4Mul3Vecfl(obedit->obmat, v2mat);
                                Mat4Mul3Vecfl(obedit->obmat, v3mat);
                                Mat4Mul3Vecfl(obedit->obmat, v4mat);
-                               
+
                                length[0] = VecLenf(v1mat, v2mat);
                                length[1] = VecLenf(v2mat, v3mat);
                                length[2] = VecLenf(v3mat, v4mat);
@@ -2623,20 +2625,20 @@ void esubdivideflag(Object *obedit, EditMesh *em, int flag, float smooth, float
                                sort[1] = ef->e2;
                                sort[2] = ef->e3;
                                sort[3] = ef->e4;
-                                                                                                 
-                                                                                               
+
+
                                // Beauty Short Edges
                                if(beauty & B_BEAUTY_SHORT) {
                                        for(j=0;j<2;j++) {
                                                hold = -1;
                                                for(i=0;i<4;i++) {
                                                        if(length[i] < 0) {
-                                                               continue;                                                       
-                                                       } else if(hold == -1) {  
-                                                               hold = i; 
+                                                               continue;
+                                                       } else if(hold == -1) {
+                                                               hold = i;
                                                        } else {
                                                                if(length[hold] < length[i]) {
-                                                                       hold = i;   
+                                                                       hold = i;
                                                                }
                                                        }
                                                }
@@ -2647,19 +2649,19 @@ void esubdivideflag(Object *obedit, EditMesh *em, int flag, float smooth, float
                                                }
                                        }
                                }
-                               
+
                                // Beauty Long Edges
                                else {
                                         for(j=0;j<2;j++) {
                                                hold = -1;
                                                for(i=0;i<4;i++) {
                                                        if(length[i] < 0) {
-                                                               continue;                                                       
-                                                       } else if(hold == -1) {  
-                                                               hold = i; 
+                                                               continue;
+                                                       } else if(hold == -1) {
+                                                               hold = i;
                                                        } else {
                                                                if(length[hold] > length[i]) {
-                                                                       hold = i;   
+                                                                       hold = i;
                                                                }
                                                        }
                                                }
@@ -2674,18 +2676,18 @@ void esubdivideflag(Object *obedit, EditMesh *em, int flag, float smooth, float
                }
        }
 
-       gh = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp); 
+       gh = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp);
 
        // If we are knifing, We only need the selected edges that were cut, so deselect if it was not cut
-       if(beauty & B_KNIFE) {  
-               for(eed= em->edges.first;eed;eed=eed->next) {   
+       if(beauty & B_KNIFE) {
+               for(eed= em->edges.first;eed;eed=eed->next) {
                        if( eed->tmp.fp == 0 ) {
                                EM_select_edge(eed,0);
                        }
                }
-       }  
+       }
        // So for each edge, if it is selected, we allocate an array of size cuts+2
-       // so we can have a place for the v1, the new verts and v2  
+       // so we can have a place for the v1, the new verts and v2
        for(eed=em->edges.first;eed;eed = eed->next) {
                if(eed->f & flag) {
                        templist = MEM_mallocN(sizeof(EditVert*)*(numcuts+2),"vertlist");
@@ -2703,9 +2705,9 @@ void esubdivideflag(Object *obedit, EditMesh *em, int flag, float smooth, float
                        //Do the last edge too
                        cedge = addedgelist(em, templist[i],templist[i+1],eed);
                        cedge->f2 = EDGENEW;
-                       // Now that the edge is subdivided, we can put its verts in the ghash 
-                       BLI_ghash_insert(gh, eed, templist);                       
-               }                                                                 
+                       // Now that the edge is subdivided, we can put its verts in the ghash
+                       BLI_ghash_insert(gh, eed, templist);
+               }
        }
 
 //     DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
@@ -2720,7 +2722,7 @@ void esubdivideflag(Object *obedit, EditMesh *em, int flag, float smooth, float
                if(ef->v4) {
                        facetype = 4;
                        if(ef->e4->f & flag) {edgecount++;}
-               }  
+               }
                if(facetype == 4) {
                        switch(edgecount) {
                                case 0:
@@ -2732,9 +2734,9 @@ void esubdivideflag(Object *obedit, EditMesh *em, int flag, float smooth, float
                                                if(ef->v3->f1) touchcount++;
                                                if(ef->v4->f1) touchcount++;
                                                if(touchcount == 2){
-                                                       if(ef->v1->f1 && ef->v3->f1){ 
+                                                       if(ef->v1->f1 && ef->v3->f1){
                                                                ef->f1 = SELECT;
-                                                               fill_quad_doublevert(em, ef, 1, 3); 
+                                                               fill_quad_doublevert(em, ef, 1, 3);
                                                        }
                                                        else if(ef->v2->f1 && ef->v4->f1){
                                                                ef->f1 = SELECT;
@@ -2742,9 +2744,9 @@ void esubdivideflag(Object *obedit, EditMesh *em, int flag, float smooth, float
                                                        }
                                                }
                                        }
-                                       break; 
-                               
-                               case 1: 
+                                       break;
+
+                               case 1:
                                        if(beauty & B_KNIFE && numcuts == 1){
                                                /*Test for when knifing through an edge and one vert*/
                                                touchcount = 0;
@@ -2752,14 +2754,14 @@ void esubdivideflag(Object *obedit, EditMesh *em, int flag, float smooth, float
                                                if(ef->v2->f1) touchcount++;
                                                if(ef->v3->f1) touchcount++;
                                                if(ef->v4->f1) touchcount++;
-                                               
+
                                                if(touchcount == 1){
                                                        if( (ef->e1->f & flag && ( !ef->e1->v1->f1 && !ef->e1->v2->f1 )) ||
                                                                (ef->e2->f & flag && ( !ef->e2->v1->f1 && !ef->e2->v2->f1 )) ||
                                                                (ef->e3->f & flag && ( !ef->e3->v1->f1 && !ef->e3->v2->f1 )) ||
                                                                (ef->e4->f & flag && ( !ef->e4->v1->f1 && !ef->e4->v2->f1 )) ){
-                                                               
-                                                               ef->f1 = SELECT; 
+
+                                                               ef->f1 = SELECT;
                                                                fill_quad_singlevert(em, ef, gh);
                                                        }
                                                        else{
@@ -2767,64 +2769,64 @@ void esubdivideflag(Object *obedit, EditMesh *em, int flag, float smooth, float
                                                                fill_quad_single(em, ef, gh, numcuts, seltype);
                                                        }
                                                }
-                                               else{ 
-                                                       ef->f1 = SELECT; 
+                                               else{
+                                                       ef->f1 = SELECT;
                                                        fill_quad_single(em, ef, gh, numcuts, seltype);
                                                }
                                        }
-                                       else{ 
+                                       else{
                                                ef->f1 = SELECT;
                                                fill_quad_single(em, ef, gh, numcuts, seltype);
                                        }
-                                       break;   
+                                       break;
                                case 2: ef->f1 = SELECT;
                                        // if there are 2, we check if edge 1 and 3 are either both on or off that way
                                        // we can tell if the selected pair is Adjacent or Opposite of each other
-                                       if((ef->e1->f & flag && ef->e3->f & flag) || 
+                                       if((ef->e1->f & flag && ef->e3->f & flag) ||
                                           (ef->e2->f & flag && ef->e4->f & flag)) {
-                                               fill_quad_double_op(em, ef, gh, numcuts);                                                         
+                                               fill_quad_double_op(em, ef, gh, numcuts);
                                        }else{
                                                switch(0) { // XXX scene->toolsettings->cornertype) {
                                                        case 0: fill_quad_double_adj_path(em, ef, gh, numcuts); break;
                                                        case 1: fill_quad_double_adj_inner(em, ef, gh, numcuts); break;
                                                        case 2: fill_quad_double_adj_fan(em, ef, gh, numcuts); break;
                                                }
-                                                                                                 
+
                                        }
-                                               break;  
+                                               break;
                                case 3: ef->f1 = SELECT;
-                                       fill_quad_triple(em, ef, gh, numcuts); 
-                                       break;  
+                                       fill_quad_triple(em, ef, gh, numcuts);
+                                       break;
                                case 4: ef->f1 = SELECT;
-                                       fill_quad_quadruple(em, ef, gh, numcuts, smooth, fractal, beauty); 
-                                       break;  
+                                       fill_quad_quadruple(em, ef, gh, numcuts, smooth, fractal, beauty);
+                                       break;
                        }
                } else {
                        switch(edgecount) {
                                case 0: break;
                                case 1: ef->f1 = SELECT;
                                        fill_tri_single(em, ef, gh, numcuts, seltype);
-                                       break;   
+                                       break;
                                case 2: ef->f1 = SELECT;
                                        fill_tri_double(em, ef, gh, numcuts);
-                                       break;  
+                                       break;
                                case 3: ef->f1 = SELECT;
                                        fill_tri_triple(em, ef, gh, numcuts, smooth, fractal, beauty);
-                                       break;  
-                       }       
-               }       
-       }
-       
+                                       break;
+                       }
+               }
+       }
+
        // Delete Old Edges and Faces
        for(eed = em->edges.first;eed;eed = eed->next) {
                if(BLI_ghash_haskey(gh,eed)) {
-                       eed->f1 = SELECT; 
+                       eed->f1 = SELECT;
                } else {
-                       eed->f1 = 0;   
+                       eed->f1 = 0;
                }
-       } 
-       free_tagged_edges_faces(em, em->edges.first, em->faces.first); 
-       
+       }
+       free_tagged_edges_faces(em, em->edges.first, em->faces.first);
+
        if(seltype == SUBDIV_SELECT_ORIG  && !ctrl) {
                /* bugfix: vertex could get flagged as "not-selected"
                // solution: clear flags before, not at the same time as setting SELECT flag -dg
@@ -2832,7 +2834,7 @@ void esubdivideflag(Object *obedit, EditMesh *em, int flag, float smooth, float
                for(eed = em->edges.first;eed;eed = eed->next) {
                        if(!(eed->f2 & EDGENEW || eed->f2 & EDGEOLD)) {
                                eed->f &= !flag;
-                               EM_select_edge(eed,0); 
+                               EM_select_edge(eed,0);
                        }
                }
                for(eed = em->edges.first;eed;eed = eed->next) {
@@ -2845,14 +2847,14 @@ void esubdivideflag(Object *obedit, EditMesh *em, int flag, float smooth, float
                for(eed = em->edges.first;eed;eed = eed->next) {
                        if(eed->f2 & EDGEINNER) {
                                eed->f |= flag;
-                               EM_select_edge(eed,1);   
+                               EM_select_edge(eed,1);
                                if(eed->v1->f & EDGEINNER) eed->v1->f |= SELECT;
                                if(eed->v2->f & EDGEINNER) eed->v2->f |= SELECT;
                        }else{
                                eed->f &= !flag;
-                               EM_select_edge(eed,0); 
+                               EM_select_edge(eed,0);
                        }
-               }                 
+               }
        } else if(seltype == SUBDIV_SELECT_LOOPCUT){
                for(eed = em->edges.first;eed;eed = eed->next) {
                        if(eed->f2 & DOUBLEOPFILL){
@@ -2863,16 +2865,16 @@ void esubdivideflag(Object *obedit, EditMesh *em, int flag, float smooth, float
                                EM_select_edge(eed,0);
                        }
                }
-       } 
+       }
         if(em->selectmode & SCE_SELECT_VERTEX) {
                 for(eed = em->edges.first;eed;eed = eed->next) {
                        if(eed->f & SELECT) {
                                eed->v1->f |= SELECT;
                                eed->v2->f |= SELECT;
                        }
-               }       
+               }
        }
-       
+
        //fix hide flags for edges. First pass, hide edges of hidden faces
        for(ef=em->faces.first; ef; ef=ef->next){
                if(ef->h){
@@ -2891,25 +2893,25 @@ void esubdivideflag(Object *obedit, EditMesh *em, int flag, float smooth, float
                        if(ef->e4) ef->e4->h &= ~1;
                }
        }
-       
-       // Free the ghash and call MEM_freeN on all the value entries to return 
+
+       // Free the ghash and call MEM_freeN on all the value entries to return
        // that memory
-       BLI_ghash_free(gh, NULL, (GHashValFreeFP)MEM_freeN);   
-       
+       BLI_ghash_free(gh, NULL, (GHashValFreeFP)MEM_freeN);
+
        EM_selectmode_flush(em);
        for(ef=em->faces.first;ef;ef = ef->next) {
                if(ef->e4) {
                        if(  (ef->e1->f & SELECT && ef->e2->f & SELECT) &&
                         (ef->e3->f & SELECT && ef->e4->f & SELECT) ) {
-                               ef->f |= SELECT;                         
-                       }                                  
+                               ef->f |= SELECT;
+                       }
                } else {
                        if(  (ef->e1->f & SELECT && ef->e2->f & SELECT) && ef->e3->f & SELECT) {
-                               ef->f |= SELECT;                         
+                               ef->f |= SELECT;
                        }
                }
        }
-       
+
        recalc_editnormals(em);
 }
 
@@ -2948,15 +2950,15 @@ static int collect_quadedges(EVPTuple *efaa, EditEdge *eed, EditFace *efa)
                        i++;
                }
                else eed->tmp.p = NULL;
-               
+
                eed= eed->next;
        }
-               
-       
+
+
        /* find edges pointing to 2 faces by procedure:
-       
+
        - run through faces and their edges, increase
-         face counter e->f1 for each face 
+         face counter e->f1 for each face
        */
 
        while(efa) {
@@ -3001,20 +3003,20 @@ static int collect_quadedges(EVPTuple *efaa, EditEdge *eed, EditFace *efa)
 }
 
 
-/* returns vertices of two adjacent triangles forming a quad 
+/* returns vertices of two adjacent triangles forming a quad
    - can be righthand or lefthand
 
                        4-----3
                        |\      |
                        | \ 2 | <- efa1
-                       |  \  | 
-         efa-> | 1 \ | 
-                       |       \| 
+                       |  \  |
+         efa-> | 1 \ |
+                       |       \|
                        1-----2
 
 */
 #define VTEST(face, num, other) \
-       (face->v##num != other->v1 && face->v##num != other->v2 && face->v##num != other->v3) 
+       (face->v##num != other->v1 && face->v##num != other->v2 && face->v##num != other->v3)
 
 static void givequadverts(EditFace *efa, EditFace *efa1, EditVert **v1, EditVert **v2, EditVert **v3, EditVert **v4, int *vindex)
 {
@@ -3036,7 +3038,7 @@ static void givequadverts(EditFace *efa, EditFace *efa1, EditVert **v1, EditVert
                vindex[0]= 2;
                vindex[1]= 0;
        }
-       
+
        if VTEST(efa1, 1, efa) {
                *v3= efa1->v1;
                *v4= efa1->v2;
@@ -3093,65 +3095,65 @@ static void free_tagged_edges_faces(EditMesh *em, EditEdge *eed, EditFace *efa)
                        free_editedge(em, eed);
                }
                eed= nexted;
-       }       
-}      
+       }
+}
 
 
 /* ******************** BEGIN TRIANGLE TO QUAD ************************************* */
 static float measure_facepair(EditVert *v1, EditVert *v2, EditVert *v3, EditVert *v4, float limit)
 {
-       
+
        /*gives a 'weight' to a pair of triangles that join an edge to decide how good a join they would make*/
        /*Note: this is more complicated than it needs to be and should be cleaned up...*/
        float   measure = 0.0, noA1[3], noA2[3], noB1[3], noB2[3], normalADiff, normalBDiff,
                        edgeVec1[3], edgeVec2[3], edgeVec3[3], edgeVec4[3], diff,
                        minarea, maxarea, areaA, areaB;
-       
+
        /*First Test: Normal difference*/
        CalcNormFloat(v1->co, v2->co, v3->co, noA1);
        CalcNormFloat(v1->co, v3->co, v4->co, noA2);
-       
+
        if(noA1[0] == noA2[0] && noA1[1] == noA2[1] && noA1[2] == noA2[2]) normalADiff = 0.0;
        else normalADiff = VecAngle2(noA1, noA2);
                //if(!normalADiff) normalADiff = 179;
        CalcNormFloat(v2->co, v3->co, v4->co, noB1);
        CalcNormFloat(v4->co, v1->co, v2->co, noB2);
-       
+
        if(noB1[0] == noB2[0] && noB1[1] == noB2[1] && noB1[2] == noB2[2]) normalBDiff = 0.0;
        else normalBDiff = VecAngle2(noB1, noB2);
                //if(!normalBDiff) normalBDiff = 179;
-       
+
        measure += (normalADiff/360) + (normalBDiff/360);
        if(measure > limit) return measure;
-       
+
        /*Second test: Colinearity*/
        VecSubf(edgeVec1, v1->co, v2->co);
        VecSubf(edgeVec2, v2->co, v3->co);
        VecSubf(edgeVec3, v3->co, v4->co);
        VecSubf(edgeVec4, v4->co, v1->co);
-       
+
        diff = 0.0;
-       
+
        diff = (
                fabs(VecAngle2(edgeVec1, edgeVec2) - 90) +
-               fabs(VecAngle2(edgeVec2, edgeVec3) - 90) + 
-               fabs(VecAngle2(edgeVec3, edgeVec4) - 90) + 
+               fabs(VecAngle2(edgeVec2, edgeVec3) - 90) +
+               fabs(VecAngle2(edgeVec3, edgeVec4) - 90) +
                fabs(VecAngle2(edgeVec4, edgeVec1) - 90)) / 360;
        if(!diff) return 0.0;
-       
+
        measure +=  diff;
        if(measure > limit) return measure;
 
        /*Third test: Concavity*/
        areaA = AreaT3Dfl(v1->co, v2->co, v3->co) + AreaT3Dfl(v1->co, v3->co, v4->co);
        areaB = AreaT3Dfl(v2->co, v3->co, v4->co) + AreaT3Dfl(v4->co, v1->co, v2->co);
-       
+
        if(areaA <= areaB) minarea = areaA;
        else minarea = areaB;
-       
+
        if(areaA >= areaB) maxarea = areaA;
        else maxarea = areaB;
-       
+
        if(!maxarea) measure += 1;
        else measure += (1 - (minarea / maxarea));
 
@@ -3160,38 +3162,38 @@ static float measure_facepair(EditVert *v1, EditVert *v2, EditVert *v3, EditVert
 
 #define T2QUV_LIMIT 0.005
 #define T2QCOL_LIMIT 3
-static int compareFaceAttribs(EditMesh *em, EditFace *f1, EditFace *f2, EditEdge *eed) 
+static int compareFaceAttribs(EditMesh *em, EditFace *f1, EditFace *f2, EditEdge *eed)
 {
-       /*Test to see if the per-face attributes for the joining edge match within limit*/      
+       /*Test to see if the per-face attributes for the joining edge match within limit*/
        MTFace *tf1, *tf2;
        unsigned int *col1, *col2;
        short i,attrok=0, flag = 0, /* XXX scene->toolsettings->editbutflag,*/ fe1[2], fe2[2];
-       
+
        tf1 = CustomData_em_get(&em->fdata, f1->data, CD_MTFACE);
        tf2 = CustomData_em_get(&em->fdata, f2->data, CD_MTFACE);
 
        col1 = CustomData_em_get(&em->fdata, f1->data, CD_MCOL);
        col2 = CustomData_em_get(&em->fdata, f2->data, CD_MCOL);
-       
+
        /*store indices for faceedges*/
        f1->v1->f1 = 0;
        f1->v2->f1 = 1;
        f1->v3->f1 = 2;
-       
+
        fe1[0] = eed->v1->f1;
        fe1[1] = eed->v2->f1;
-       
+
        f2->v1->f1 = 0;
        f2->v2->f1 = 1;
        f2->v3->f1 = 2;
-       
+
        fe2[0] = eed->v1->f1;
        fe2[1] = eed->v2->f1;
-       
+
        /*compare faceedges for each face attribute. Additional per face attributes can be added later*/
        /*do UVs*/
        if(flag & B_JOINTRIA_UV){
-               
+
                if(tf1 == NULL || tf2 == NULL) attrok |= B_JOINTRIA_UV;
                else if(tf1->tpage != tf2->tpage); /*do nothing*/
                else{
@@ -3201,7 +3203,7 @@ static int compareFaceAttribs(EditMesh *em, EditFace *f1, EditFace *f2, EditEdge
                        }
                }
        }
-       
+
        /*do VCOLs*/
        if(flag & B_JOINTRIA_VCOL){
                if(!col1 || !col2) attrok |= B_JOINTRIA_VCOL;
@@ -3210,7 +3212,7 @@ static int compareFaceAttribs(EditMesh *em, EditFace *f1, EditFace *f2, EditEdge
                        for(i = 0; i < 2; i++){
                                f1vcol = (char *)&(col1[fe1[i]]);
                                f2vcol = (char *)&(col2[fe2[i]]);
-               
+
                                /*compare f1vcol with f2vcol*/
                                if(     f1vcol[1] + T2QCOL_LIMIT > f2vcol[1] && f1vcol[1] - T2QCOL_LIMIT < f2vcol[1] &&
                                        f1vcol[2] + T2QCOL_LIMIT > f2vcol[2] && f1vcol[2] - T2QCOL_LIMIT < f2vcol[2] &&
@@ -3218,18 +3220,18 @@ static int compareFaceAttribs(EditMesh *em, EditFace *f1, EditFace *f2, EditEdge
                        }
                }
        }
-       
+
        if( ((attrok & B_JOINTRIA_UV) == (flag & B_JOINTRIA_UV)) && ((attrok & B_JOINTRIA_VCOL) == (flag & B_JOINTRIA_VCOL)) ) return 1;
        return 0;
-}      
-       
+}
+
 static int fplcmp(const void *v1, const void *v2)
 {
        const EditEdge *e1= *((EditEdge**)v1), *e2=*((EditEdge**)v2);
-       
+
        if( e1->crease > e2->crease) return 1;
        else if( e1->crease < e2->crease) return -1;
-       
+
        return 0;
 }
 
@@ -3248,21 +3250,21 @@ void join_triangles(EditMesh *em)
        float measure; /*Used to set tolerance*/
        float limit = 0.0f; // XXX scene->toolsettings->jointrilimit;
        int i, ok, totedge=0, totseledge=0, complexedges, vindex[4];
-       
+
        /*if we take a long time on very dense meshes we want waitcursor to display*/
        waitcursor(1);
-       
+
        totseledge = count_selected_edges(em->edges.first);
        if(totseledge==0) return;
-       
+
        /*abusing crease value to store weights for edge pairs. Nasty*/
        for(eed=em->edges.first; eed; eed=eed->next) totedge++;
-       if(totedge) creases = MEM_callocN(sizeof(float) * totedge, "Join Triangles Crease Array"); 
+       if(totedge) creases = MEM_callocN(sizeof(float) * totedge, "Join Triangles Crease Array");
        for(eed=em->edges.first, i = 0; eed; eed=eed->next, i++){
-               creases[i] = eed->crease; 
+               creases[i] = eed->crease;
                eed->crease = 0.0;
        }
-       
+
        /*clear temp flags*/
        for(eve=em->verts.first; eve; eve=eve->next) eve->f1 = eve->f2 = 0;
        for(eed=em->edges.first; eed; eed=eed->next) eed->f2 = eed->f1 = 0;
@@ -3272,11 +3274,11 @@ void join_triangles(EditMesh *em)
        efaar= (EVPTuple *) MEM_callocN(totseledge * sizeof(EVPTuple), "Tri2Quad");
        ok = collect_quadedges(efaar, em->edges.first, em->faces.first);
        complexedges = 0;
-       
+
        if(ok){
-               
-               
-               /*clear tmp.l flag and store number of faces that are selected and coincident to current face here.*/  
+
+
+               /*clear tmp.l flag and store number of faces that are selected and coincident to current face here.*/
                for(eed=em->edges.first; eed; eed=eed->next){
                        /* eed->f2 is 2 only if this edge is part of exactly two
                           triangles, and both are selected, and it has EVPTuple assigned */
@@ -3286,7 +3288,7 @@ void join_triangles(EditMesh *em)
                                efaa[1]->tmp.l++;
                        }
                }
-               
+
                for(eed=em->edges.first; eed; eed=eed->next){
                        if(eed->f2 == 2){
                                efaa= (EVPtr *) eed->tmp.p;
@@ -3299,30 +3301,30 @@ void join_triangles(EditMesh *em)
                                                efaa[0]->f1 = 1; //mark for join
                                                efaa[1]->f1 = 1; //mark for join
                                        }
-                                       else{ 
-                                               
+                                       else{
+
                                                /*      The face pair is part of a 'complex' island, so the rules for dealing with it are more involved.
                                                        Depending on what options the user has chosen, this face pair can be 'thrown out' based upon the following criteria:
-                                                       
+
                                                        1: the two faces do not share the same material
                                                        2: the edge joining the two faces is marked as sharp.
                                                        3: the two faces UV's do not make a good match
                                                        4: the two faces Vertex colors do not make a good match
-                                                       
+
                                                        If the face pair passes all the applicable tests, it is then given a 'weight' with the measure_facepair() function.
                                                        This measures things like concavity, colinearity ect. If this weight is below the threshold set by the user
                                                        the edge joining them is marked as being 'complex' and will be compared against other possible pairs which contain one of the
                                                        same faces in the current pair later.
-                                               
+
                                                        This technique is based upon an algorithm that Campbell Barton developed for his Tri2Quad script that was previously part of
                                                        the python scripts bundled with Blender releases.
                                                */
-                                               
+
 // XXX                                         if(scene->toolsettings->editbutflag & B_JOINTRIA_SHARP && eed->sharp); /*do nothing*/
 //                                             else if(scene->toolsettings->editbutflag & B_JOINTRIA_MAT && efaa[0]->mat_nr != efaa[1]->mat_nr); /*do nothing*/
 //                                             else if(((scene->toolsettings->editbutflag & B_JOINTRIA_UV) || (scene->toolsettings->editbutflag & B_JOINTRIA_VCOL)) &&
                                                compareFaceAttribs(em, efaa[0], efaa[1], eed); // XXX == 0); /*do nothing*/
-//                                             else{   
+//                                             else{
                                                        measure = measure_facepair(v1, v2, v3, v4, limit);
                                                        if(measure < limit){
                                                                complexedges++;
@@ -3334,7 +3336,7 @@ void join_triangles(EditMesh *em)
                                }
                        }
                }
-               
+
                /*Quicksort the complex edges according to their weighting*/
                if(complexedges){
                        edsortblock = edb = MEM_callocN(sizeof(EditEdge*) * complexedges, "Face Pairs quicksort Array");
@@ -3346,7 +3348,7 @@ void join_triangles(EditMesh *em)
                        }
                        qsort(edsortblock, complexedges, sizeof(EditEdge*), fplcmp);
                        /*now go through and mark the edges who get the highest weighting*/
-                       for(edb=edsortblock, i=0; i < complexedges; edb++, i++){ 
+                       for(edb=edsortblock, i=0; i < complexedges; edb++, i++){
                                efaa = (EVPtr *)((*edb)->tmp.p); /*suspect!*/
                                if( !efaa[0]->f1 && !efaa[1]->f1){
                                        efaa[0]->f1 = 1; //mark for join
@@ -3355,8 +3357,8 @@ void join_triangles(EditMesh *em)
                                }
                        }
                }
-               
-               /*finally go through all edges marked for join (simple and complex) and create new faces*/ 
+
+               /*finally go through all edges marked for join (simple and complex) and create new faces*/
                for(eed=em->edges.first; eed; eed=eed->next){
                        if(eed->f1 & T2QJOIN){
                                efaa= (EVPtr *)eed->tmp.p;
@@ -3376,10 +3378,10 @@ void join_triangles(EditMesh *em)
                        }
                }
        }
-       
+
        /*free data and cleanup*/
        if(creases){
-               for(eed=em->edges.first, i = 0; eed; eed=eed->next, i++) eed->crease = creases[i]; 
+               for(eed=em->edges.first, i = 0; eed; eed=eed->next, i++) eed->crease = creases[i];
                MEM_freeN(creases);
        }
        for(eed=em->edges.first; eed; eed=eed->next){
@@ -3389,7 +3391,7 @@ void join_triangles(EditMesh *em)
        free_tagged_edges_faces(em, em->edges.first, em->faces.first);
        if(efaar) MEM_freeN(efaar);
        if(edsortblock) MEM_freeN(edsortblock);
-               
+
        EM_selectmode_flush(em);
 
 }
@@ -3407,7 +3409,7 @@ void edge_flip(EditMesh *em)
        EVPTuple *efaar;
        EVPtr *efaa;
        int totedge, ok, vindex[4];
-       
+
        /* - all selected edges with two faces
         * - find the faces: store them in edges (using datablock)
         * - per edge: - test convex
@@ -3415,7 +3417,7 @@ void edge_flip(EditMesh *em)
                                                - if true: remedge,  addedge, all edges at the edge get new face pointers
         */
 
-       EM_selectmode_flush(em);        // makes sure in selectmode 'face' the edges of selected faces are selected too 
+       EM_selectmode_flush(em);        // makes sure in selectmode 'face' the edges of selected faces are selected too
 
        totedge = count_selected_edges(em->edges.first);
        if(totedge==0) return;
@@ -3424,15 +3426,15 @@ void edge_flip(EditMesh *em)
        efaar= (EVPTuple *) MEM_callocN(totedge * sizeof(EVPTuple), "edgeflip");
 
        ok = collect_quadedges(efaar, em->edges.first, em->faces.first);
-       
+
        eed= em->edges.first;
        while(eed) {
                nexted= eed->next;
-               
+
                if(eed->f2==2) {  /* points to 2 faces */
-                       
+
                        efaa= (EVPtr *) eed->tmp.p;
-                       
+
                        /* don't do it if flagged */
 
                        ok= 1;
@@ -3440,7 +3442,7 @@ void edge_flip(EditMesh *em)
                        if(efa->e1->f1 || efa->e2->f1 || efa->e3->f1) ok= 0;
                        efa= efaa[1];
                        if(efa->e1->f1 || efa->e2->f1 || efa->e3->f1) ok= 0;
-                       
+
                        if(ok) {
                                /* test convex */
                                givequadverts(efaa[0], efaa[1], &v1, &v2, &v3, &v4, vindex);
@@ -3449,8 +3451,8 @@ void edge_flip(EditMesh *em)
                4-----3         4-----3
                |\      |               |       /|
                | \ 1 |         | 1 / |
-               |  \  |  ->     |  /  | 
-               | 0 \ |         | / 0 | 
+               |  \  |  ->     |  /  |
+               | 0 \ |         | / 0 |
                |       \|              |/      |
                1-----2         1-----2
 */
@@ -3458,7 +3460,7 @@ void edge_flip(EditMesh *em)
                                if (v1 && v2 && v3) {
                                        if( convex(v1->co, v2->co, v3->co, v4->co) ) {
                                                if(exist_face(em, v1, v2, v3, v4)==0) {
-                                                       /* outch this may break seams */ 
+                                                       /* outch this may break seams */
                                                        w= EM_face_from_faces(em, efaa[0], efaa[1], vindex[0],
                                                                vindex[1], 4+vindex[2], -1);
 
@@ -3473,8 +3475,8 @@ void edge_flip(EditMesh *em)
                                                /* tag as to-be-removed */
                                                FACE_MARKCLEAR(efaa[1]);
                                                FACE_MARKCLEAR(efaa[0]);
-                                               eed->f1 = 1; 
-                                               
+                                               eed->f1 = 1;
+
                                        } /* endif test convex */
                                }
                        }
@@ -3484,7 +3486,7 @@ void edge_flip(EditMesh *em)
 
        /* clear tagged edges and faces: */
        free_tagged_edges_faces(em, em->edges.first, em->faces.first);
-       
+
        MEM_freeN(efaar);
 }
 
@@ -3511,7 +3513,7 @@ static void edge_rotate(EditMesh *em, wmOperator *op, EditEdge *eed, int dir)
        EditEdge **edges[2], **hiddenedges, *srchedge;
        int facecount, p1, p2, p3, p4, fac1, fac2, i, j;
        int numhidden, numshared, p[2][4];
-       
+
        /* check to make sure that the edge is only part of 2 faces */
        facecount = 0;
        for(efa = em->faces.first;efa;efa = efa->next) {
@@ -3526,7 +3528,7 @@ static void edge_rotate(EditMesh *em, wmOperator *op, EditEdge *eed, int dir)
                        }
                }
        }
+
        if(facecount < 2)
                return;
 
@@ -3536,7 +3538,7 @@ static void edge_rotate(EditMesh *em, wmOperator *op, EditEdge *eed, int dir)
 
        if(face[1]->e4) fac2= 4;
        else fac2= 3;
-       
+
        /* make a handy array for verts and edges */
        verts[0]= &face[0]->v1;
        edges[0]= &face[0]->e1;
@@ -3552,7 +3554,7 @@ static void edge_rotate(EditMesh *em, wmOperator *op, EditEdge *eed, int dir)
 
        if(numshared > 1)
                return;
-       
+
        /* we want to construct an array of vertex indicis in both faces, starting at
           the last vertex of the edge being rotated.
           - first we find the two vertices that lie on the rotating edge
@@ -3566,12 +3568,12 @@ static void edge_rotate(EditMesh *em, wmOperator *op, EditEdge *eed, int dir)
                if(eed->v1 == verts[1][i]) p3 = i;
                if(eed->v2 == verts[1][i]) p4 = i;
        }
-       
+
        if((p1+1)%fac1 == p2)
                SWAP(int, p1, p2);
        if((p3+1)%fac2 == p4)
                SWAP(int, p3, p4);
-       
+
        for (i = 0; i < 4; i++) {
                p[0][i]= (p1 + i)%fac1;
                p[1][i]= (p3 + i)%fac2;
@@ -3586,7 +3588,7 @@ static void edge_rotate(EditMesh *em, wmOperator *op, EditEdge *eed, int dir)
        hiddenedges = MEM_mallocN(sizeof(EditVert*)*numhidden+1, "RotateEdgeHiddenVerts");
        if(!hiddenedges) {
         BKE_report(op->reports, RPT_ERROR, "Memory allocation failed");
-        return;   
+        return;
     }
 
     numhidden = 0;
@@ -3608,9 +3610,9 @@ static void edge_rotate(EditMesh *em, wmOperator *op, EditEdge *eed, int dir)
                } else if (dir == DIRECTION_CCW) {
                        newFace[0]= EM_face_from_faces(em, face[0], face[1], p[0][2], 4+p[1][1], p[0][0], p[0][1]);
                        newFace[1]= EM_face_from_faces(em, face[1], face[0], 4+p[0][2], p[1][0], p[1][1], -1);
-                       
+
                        verts[0][p[0][2]]->f |= SELECT;
-                       verts[1][p[1][1]]->f |= SELECT;         
+                       verts[1][p[1][1]]->f |= SELECT;
                }
        }
        else if(fac1 == 3 && fac2 == 4) {
@@ -3620,11 +3622,11 @@ static void edge_rotate(EditMesh *em, wmOperator *op, EditEdge *eed, int dir)
                } else if (dir == DIRECTION_CCW) {
                        newFace[0]= EM_face_from_faces(em, face[0], face[1], p[0][0], p[0][1], 4+p[1][2], -1);
                        newFace[1]= EM_face_from_faces(em, face[1], face[0], p[1][1], p[1][2], 4+p[0][1], 4+p[0][2]);
-                       
+
                        verts[0][p[0][1]]->f |= SELECT;
-                       verts[1][p[1][2]]->f |= SELECT; 
+                       verts[1][p[1][2]]->f |= SELECT;
                }
-       
+
        }
        else if(fac1 == 4 && fac2 == 4) {
                if(dir == DIRECTION_CW) {
@@ -3633,11 +3635,11 @@ static void edge_rotate(EditMesh *em, wmOperator *op, EditEdge *eed, int dir)
                } else if (dir == DIRECTION_CCW) {
                        newFace[0]= EM_face_from_faces(em, face[0], face[1], p[0][2], p[0][3], 4+p[1][1], 4+p[1][2]);
                        newFace[1]= EM_face_from_faces(em, face[1], face[0], p[1][2], p[1][3], 4+p[0][1], 4+p[0][2]);
-                       
+
                        verts[0][p[0][2]]->f |= SELECT;
-                       verts[1][p[1][2]]->f |= SELECT; 
+                       verts[1][p[1][2]]->f |= SELECT;
                }
-       }               
+       }
        else
                return; /* This should never happen */
 
@@ -3645,7 +3647,7 @@ static void edge_rotate(EditMesh *em, wmOperator *op, EditEdge *eed, int dir)
                verts[0][p[0][1]]->f |= SELECT;
                verts[1][p[1][1]]->f |= SELECT;
        }
-       
+
        /* copy old edge's flags to new center edge*/
        for(srchedge=em->edges.first;srchedge;srchedge=srchedge->next) {
                if((srchedge->v1->f & SELECT) && (srchedge->v2->f & SELECT)) {
@@ -3657,25 +3659,25 @@ static void edge_rotate(EditMesh *em, wmOperator *op, EditEdge *eed, int dir)
                        srchedge->bweight = eed->bweight;
                }
        }
-       
+
        /* resetting hidden flag */
        for(numhidden--; numhidden>=0; numhidden--)
                hiddenedges[numhidden]->h= 1;
-       
+
        /* check for orhphan edges */
        for(srchedge=em->edges.first; srchedge; srchedge=srchedge->next)
-               srchedge->f1= -1;   
-       
+               srchedge->f1= -1;
+
        /* cleanup */
        MEM_freeN(hiddenedges);
-       
+
        /* get rid of the old edge and faces*/
        remedge(em, eed);
-       free_editedge(em, eed); 
+       free_editedge(em, eed);
        BLI_remlink(&em->faces, face[0]);
-       free_editface(em, face[0]);     
+       free_editface(em, face[0]);
        BLI_remlink(&em->faces, face[1]);
-       free_editface(em, face[1]);             
+       free_editface(em, face[1]);
 }
 
 // XXX ton please check
@@ -3689,14 +3691,14 @@ static int edge_rotate_selected(bContext *C, wmOperator *op)
        EditFace *efa;
        int dir = RNA_int_get(op->ptr, "direction"); // dir == 2 when clockwise and ==1 for counter CW.
        short edgeCount = 0;
-       
+
        /*clear new flag for new edges, count selected edges */
        for(eed= em->edges.first; eed; eed= eed->next) {
                eed->f1= 0;
                eed->f2 &= ~2;
-               if(eed->f & SELECT) edgeCount++;        
+               if(eed->f & SELECT) edgeCount++;
        }
-       
+
        if(edgeCount>1) {
                /* more selected edges, check faces */
                for(efa= em->faces.first; efa; efa= efa->next) {
@@ -3719,7 +3721,7 @@ static int edge_rotate_selected(bContext *C, wmOperator *op)
                                }
                        }
                }
-               else 
+               else
                {
                        BKE_report(op->reports, RPT_ERROR, "Select one edge or two adjacent faces");
                        BKE_mesh_end_editmesh(obedit->data, em);
@@ -3735,7 +3737,7 @@ static int edge_rotate_selected(bContext *C, wmOperator *op)
                        }
                }
        }
-       else  { 
+       else  {
                BKE_report(op->reports, RPT_ERROR, "Select one edge or two adjacent faces");
                BKE_mesh_end_editmesh(obedit->data, em);
                return OPERATOR_CANCELLED;
@@ -3743,7 +3745,7 @@ static int edge_rotate_selected(bContext *C, wmOperator *op)
 
        /* flush selected vertices (again) to edges/faces */
        EM_select_flush(em);
-       
+
        BKE_mesh_end_editmesh(obedit->data, em);
 
        DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
@@ -3757,14 +3759,14 @@ void MESH_OT_edge_rotate(wmOperatorType *ot)
        /* identifiers */
        ot->name= "Rotate Selected Edge";
        ot->idname= "MESH_OT_edge_rotate";
-       
+
        /* api callbacks */
        ot->exec= edge_rotate_selected;
        ot->poll= ED_operator_editmesh;
-       
+
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
+
        /* props */
        RNA_def_enum(ot->srna, "direction", direction_items, DIRECTION_CW, "direction", "direction to rotate edge around.");
 }
@@ -3774,7 +3776,7 @@ void MESH_OT_edge_rotate(wmOperatorType *ot)
 
   /* XXX old bevel not ported yet */
 
-void bevel_menu(EditMesh *em) 
+void bevel_menu(EditMesh *em)
 {
        BME_Mesh *bm;
        BME_TransData_Head *td;
@@ -3829,7 +3831,7 @@ returns 0 if they do not, or if the function is passed the same edge 2 times
 short sharesFace(EditMesh *em, EditEdge* e1, EditEdge* e2)
 {
        EditFace *search=NULL;
-       
+
        search = em->faces.first;
        if (e1 == e2){
                return 0 ;
@@ -3880,38 +3882,38 @@ useless:
        float shiftlabda= 0.0f,len = 0.0f;
        int i = 0,j, numsel, numadded=0, timesthrough = 0, vertsel=0, prop=1, cancel = 0,flip=0;
        int wasshift = 0;
-       
+
        /* UV correction vars */
        GHash **uvarray= NULL;
        int  uvlay_tot= CustomData_number_of_layers(&em->fdata, CD_MTFACE);
        int uvlay_idx;
-       SlideUv *slideuvs=NULL, *suv=NULL, *suv_last=NULL;      
+       SlideUv *slideuvs=NULL, *suv=NULL, *suv_last=NULL;
        float uv_tmp[2];
        LinkNode *fuv_link;
-       
+
        short event, draw=1;
        short mval[2], mvalo[2];
-       char str[128]; 
+       char str[128];
        float labda = 0.0f;
-       
+
 //     initNumInput(&num);
-               
+
 //     view3d_get_object_project_mat(curarea, obedit, projectMat);
-       
-       mvalo[0] = -1; mvalo[1] = -1; 
-       numsel =0;  
-       
+
+       mvalo[0] = -1; mvalo[1] = -1;
+       numsel =0;
+
        // Get number of selected edges and clear some flags
        for(eed=em->edges.first;eed;eed=eed->next) {
                eed->f1 = 0;
-               eed->f2 = 0;   
+               eed->f2 = 0;
                if(eed->f & SELECT) numsel++;
        }
-       
+
        for(ev=em->verts.first;ev;ev=ev->next) {
-               ev->f1 = 0;   
-       } 
-       
+               ev->f1 = 0;
+       }
+
        //Make sure each edge only has 2 faces
        // make sure loop doesn't cross face
        for(efa=em->faces.first;efa;efa=efa->next) {
@@ -3921,7 +3923,7 @@ useless:
                        efa->e1->f1++;
                        if(efa->e1->f1 > 2) {
                                BKE_report(op->reports, RPT_ERROR, "3+ face edge");
-                               return 0;                                
+                               return 0;
                        }
                }
                if(efa->e2->f & SELECT) {
@@ -3929,7 +3931,7 @@ useless:
                        efa->e2->f1++;
                        if(efa->e2->f1 > 2) {
                                BKE_report(op->reports, RPT_ERROR, "3+ face edge");
-                               return 0;                                
+                               return 0;
                        }
                }
                if(efa->e3->f & SELECT) {
@@ -3937,7 +3939,7 @@ useless:
                        efa->e3->f1++;
                        if(efa->e3->f1 > 2) {
                                BKE_report(op->reports, RPT_ERROR, "3+ face edge");
-                               return 0;                                
+                               return 0;
                        }
                }
                if(efa->e4 && efa->e4->f & SELECT) {
@@ -3945,26 +3947,26 @@ useless:
                        efa->e4->f1++;
                        if(efa->e4->f1 > 2) {
                                BKE_report(op->reports, RPT_ERROR, "3+ face edge");
-                               return 0;                                
+                               return 0;
                        }
-               }       
-               // Make sure loop is not 2 edges of same face   
+               }
+               // Make sure loop is not 2 edges of same face
                if(ct > 1) {
                   BKE_report(op->reports, RPT_ERROR, "Loop crosses itself");
-                  return 0;   
+                  return 0;
                }
-       }          
+       }
        // Get # of selected verts
-       for(ev=em->verts.first;ev;ev=ev->next) { 
+       for(ev=em->verts.first;ev;ev=ev->next) {
                if(ev->f & SELECT) vertsel++;
-       }       
-          
+       }
+
        // Test for multiple segments
        if(vertsel > numsel+1) {
                BKE_report(op->reports, RPT_ERROR, "Please choose a single edge loop");
-               return 0;                  
-       }  
-       
+               return 0;
+       }
+
        // Get the edgeloop in order - mark f1 with SELECT once added
        for(eed=em->edges.first;eed;eed=eed->next) {
                if((eed->f & SELECT) && !(eed->f1 & SELECT)) {
@@ -3973,35 +3975,35 @@ useless:
                                BLI_linklist_prepend(&edgelist,eed);
                                numadded++;
                                first = eed;
-                               last  = eed; 
+                               last  = eed;
                                eed->f1 = SELECT;
-                       } else {  
+                       } else {
                                if(editedge_getSharedVert(eed, last)) {
                                        BLI_linklist_append(&edgelist,eed);
                                        eed->f1 = SELECT;
                                        numadded++;
-                                       last = eed;                                       
+                                       last = eed;
                                }  else if(editedge_getSharedVert(eed, first)) {
                                        BLI_linklist_prepend(&edgelist,eed);
                                        eed->f1 = SELECT;
                                        numadded++;
-                                       first = eed;                                      
-                               }   
+                                       first = eed;
+                               }
                        }
-               }   
+               }
                if(eed->next == NULL && numadded != numsel) {
-                       eed=em->edges.first;    
+                       eed=em->edges.first;
                        timesthrough++;
                }
-               
+
                // It looks like there was an unexpected case - Hopefully should not happen
                if(timesthrough >= numsel*2) {
-                       BLI_linklist_free(edgelist,NULL); 
+                       BLI_linklist_free(edgelist,NULL);
                        BKE_report(op->reports, RPT_ERROR, "Could not order loop");
-                       return 0;   
+                       return 0;
                }
        }
-       
+
        // Put the verts in order in a linklist
        look = edgelist;
        while(look) {
@@ -4012,33 +4014,33 @@ useless:
 
                                //This is the first entry takes care of extra vert
                                if(eed->v1 != temp->v1 && eed->v1 != temp->v2) {
-                                       BLI_linklist_append(&vertlist,eed->v1); 
-                                       eed->v1->f1 = 1; 
+                                       BLI_linklist_append(&vertlist,eed->v1);
+                                       eed->v1->f1 = 1;
                                } else {
-                                       BLI_linklist_append(&vertlist,eed->v2);  
-                                       eed->v2->f1 = 1; 
-                               }                        
+                                       BLI_linklist_append(&vertlist,eed->v2);
+                                       eed->v2->f1 = 1;
+                               }
                        } else {
                                //This is the case that we only have 1 edge
-                               BLI_linklist_append(&vertlist,eed->v1); 
-                               eed->v1->f1 = 1;                                        
+                               BLI_linklist_append(&vertlist,eed->v1);
+                               eed->v1->f1 = 1;
                        }
-               }               
+               }
                // for all the entries
                if(eed->v1->f1 != 1) {
-                       BLI_linklist_append(&vertlist,eed->v1); 
-                       eed->v1->f1 = 1;                   
+                       BLI_linklist_append(&vertlist,eed->v1);
+                       eed->v1->f1 = 1;
                } else  if(eed->v2->f1 != 1) {
-                       BLI_linklist_append(&vertlist,eed->v2); 
-                       eed->v2->f1 = 1;                                        
-               } 
-               look = look->next;   
-       }                
-       
+                       BLI_linklist_append(&vertlist,eed->v2);
+                       eed->v2->f1 = 1;
+               }
+               look = look->next;
+       }
+
        // populate the SlideVerts
-       
-       vertgh = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp); 
-       look = vertlist;          
+
+       vertgh = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp);
+       look = vertlist;
        while(look) {
                i=0;
                j=0;
@@ -4054,14 +4056,14 @@ useless:
                tempsv->origvert.no[2] = ev->no[2];
                // i is total edges that vert is on
                // j is total selected edges that vert is on
-               
+
                for(eed=em->edges.first;eed;eed=eed->next) {
                        if(eed->v1 == ev || eed->v2 == ev) {
-                               i++;    
+                               i++;
                                if(eed->f & SELECT) {
-                                        j++;   
+                                        j++;
                                }
-                       }               
+                       }
                }
                // If the vert is in the middle of an edge loop, it touches 2 selected edges and 2 unselected edges
                if(i == 4 && j == 2) {
@@ -4071,11 +4073,11 @@ useless:
                                                 if(!tempsv->up) {
                                                         tempsv->up = eed;
                                                 } else if (!(tempsv->down)) {
-                                                        tempsv->down = eed;  
+                                                        tempsv->down = eed;
                                                 }
                                        }
-                               }               
-                       }                       
+                               }
+                       }
                }
                // If it is on the end of the loop, it touches 1 selected and as least 2 more unselected
                if(i >= 3 && j == 1) {
@@ -4087,63 +4089,63 @@ useless:
                                                                 if(!tempsv->up) {
                                                                         tempsv->up = efa->e1;
                                                                 } else if (!(tempsv->down)) {
-                                                                        tempsv->down = efa->e1;  
-                                                                }                                                                 
+                                                                        tempsv->down = efa->e1;
+                                                                }
                                                        }
                                                        if(editedge_containsVert(efa->e2, ev) && efa->e2 != eed) {
                                                                 if(!tempsv->up) {
                                                                         tempsv->up = efa->e2;
                                                                 } else if (!(tempsv->down)) {
-                                                                        tempsv->down = efa->e2;  
-                                                                }                                                                 
-                                                       }                                                       
+                                                                        tempsv->down = efa->e2;
+                                                                }
+                                                       }
                                                        if(editedge_containsVert(efa->e3, ev) && efa->e3 != eed) {
                                                                 if(!tempsv->up) {
                                                                         tempsv->up = efa->e3;
                                                                 } else if (!(tempsv->down)) {
-                                                                        tempsv->down = efa->e3;  
-                                                                }                                                                 
-                                                       }  
+                                                                        tempsv->down = efa->e3;
+                                                                }
+                                                       }
                                                        if(efa->e4) {
                                                                if(editedge_containsVert(efa->e4, ev) && efa->e4 != eed) {
                                                                         if(!tempsv->up) {
                                                                                 tempsv->up = efa->e4;
                                                                         } else if (!(tempsv->down)) {
-                                                                                tempsv->down = efa->e4;  
-                                                                        }                                                                 
+                                                                                tempsv->down = efa->e4;
+                                                                        }
                                                                }
-                                                       }                                                                                                                 
-                                                       
+                                                       }
+
                                                }
                                        }
-                               }               
-                       }                       
-               }               
+                               }
+                       }
+               }
                if(i > 4 && j == 2) {
                        BLI_ghash_free(vertgh, NULL, (GHashValFreeFP)MEM_freeN);
-                       BLI_linklist_free(vertlist,NULL); 
-                       BLI_linklist_free(edgelist,NULL); 
-                       return 0;   
+                       BLI_linklist_free(vertlist,NULL);
+                       BLI_linklist_free(edgelist,NULL);
+                       return 0;
                }
                BLI_ghash_insert(vertgh,ev,tempsv);
-               
-               look = look->next;   
-       }                 
-   
+
+               look = look->next;
+       }
+
        // make sure the UPs nad DOWNs are 'faceloops'
        // Also find the nearest slidevert to the cursor
 // XXX getmouseco_areawin(mval);
-       look = vertlist;        
+       look = vertlist;
        nearest = NULL;
-       vertdist = -1;  
-       while(look) {   
+       vertdist = -1;
+       while(look) {
                tempsv  = BLI_ghash_lookup(vertgh,(EditVert*)look->link);
-               
+
                if(!tempsv->up || !tempsv->down) {
                        BKE_report(op->reports, RPT_ERROR, "Missing rails");
                        BLI_ghash_free(vertgh, NULL, (GHashValFreeFP)MEM_freeN);
-                       BLI_linklist_free(vertlist,NULL); 
-                       BLI_linklist_free(edgelist,NULL); 
+                       BLI_linklist_free(vertlist,NULL);
+                       BLI_linklist_free(edgelist,NULL);
                        return 0;
                }
 
@@ -4174,39 +4176,39 @@ useless:
                                        EditEdge *swap;
                                        swap = sv->up;
                                        sv->up = sv->down;
-                                       sv->down = swap; 
+                                       sv->down = swap;
                                }
 
 //                             view3d_project_float(curarea, tempsv->origvert.co, co, projectMat);
-                               
+
                                tempdist = sqrt(pow(co[0] - mval[0],2)+pow(co[1]  - mval[1],2));
 
                                if(vertdist < 0) {
                                        vertdist = tempdist;
-                                       nearest  = (EditVert*)look->link;   
+                                       nearest  = (EditVert*)look->link;
                                } else if ( tempdist < vertdist ) {
                                        vertdist = tempdist;
-                                       nearest  = (EditVert*)look->link;       
-                               }               
-                       }
-               }               
-               
-               
-               
-               look = look->next;   
-       }          
-       
-       
+                                       nearest  = (EditVert*)look->link;
+                               }
+                       }
+               }
+
+
+
+               look = look->next;
+       }
+
+
        if (uvlay_tot) { // XXX && (scene->toolsettings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT)) {
                int maxnum = 0;
                uvarray = MEM_callocN( uvlay_tot * sizeof(GHash *), "SlideUVs Array");
                suv_last = slideuvs = MEM_callocN( uvlay_tot * (numadded+1) * sizeof(SlideUv), "SlideUVs"); /* uvLayers * verts */
                suv = NULL;
-               
+
                for (uvlay_idx=0; uvlay_idx<uvlay_tot; uvlay_idx++) {
-                       
-                       uvarray[uvlay_idx] = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp); 
-                       
+
+                       uvarray[uvlay_idx] = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp);
+
                        for(ev=em->verts.first;ev;ev=ev->next) {
                                ev->tmp.l = 0;
                        }
@@ -4214,25 +4216,25 @@ useless:
                        while(look) {
                                float *uv_new;
                                tempsv  = BLI_ghash_lookup(vertgh,(EditVert*)look->link);
-                               
+
                                ev = look->link;
                                suv = NULL;
                                for(efa = em->faces.first;efa;efa=efa->next) {
                                        if (ev->tmp.l != -1) { /* test for self, in this case its invalid */
                                                int k=-1; /* face corner */
-                                       
+
                                                /* Is this vert in the faces corner? */
                                                if              (efa->v1==ev)                           k=0;
                                                else if (efa->v2==ev)                           k=1;
                                                else if (efa->v3==ev)                           k=2;
                                                else if (efa->v4 && efa->v4==ev)        k=3;
-                                               
+
                                                if (k != -1) {
                                                        MTFace *tf = CustomData_em_get_n(&em->fdata, efa->data, CD_MTFACE, uvlay_idx);
                                                        EditVert *ev_up, *ev_down;
-                                                       
+
                                                        uv_new = tf->uv[k];
-                               
+
                                                        if (ev->tmp.l) {
                                                                if (fabs(suv->origuv[0]-uv_new[0]) > 0.0001 || fabs(suv->origuv[1]-uv_new[1])) {
                                                                        ev->tmp.l = -1; /* Tag as invalid */
@@ -4250,14 +4252,14 @@ useless:
                                                                suv->uv_up = suv->uv_down = NULL;
                                                                suv->origuv[0] = uv_new[0];
                                                                suv->origuv[1] = uv_new[1];
-                                                               
+
                                                                BLI_linklist_prepend(&suv->fuv_list, uv_new);
                                                                BLI_ghash_insert(uvarray[uvlay_idx],ev,suv);
-                                                               
+
                                                                suv_last++; /* advance to next slide UV */
                                                                maxnum++;
                                                        }
-                               
+
                                                        /* Now get the uvs along the up or down edge if we can */
                                                        if (suv) {
                                                                if (!suv->uv_up) {
@@ -4274,7 +4276,7 @@ useless:
                                                                        else if (efa->v3==ev_down)                              suv->uv_down = tf->uv[2];
                                                                        else if (efa->v4 && efa->v4==ev_down)   suv->uv_down = tf->uv[3];
                                                                }
-                                       
+
                                                                /* Copy the pointers to the face UV's */
                                                                BLI_linklist_prepend(&suv->fuv_list, uv_new);
                                                        }
@@ -4285,32 +4287,32 @@ useless:
                        }
                } /* end uv layer loop */
        } /* end uvlay_tot */
-       
-       
-       
+
+
+
        // we should have enough info now to slide
 
-       len = 0.0f; 
-       
+       len = 0.0f;
+
        percp = -1;
        while(draw) {
-                /* For the % calculation */   
-               short mval[2];   
+                /* For the % calculation */
+               short mval[2];
                float rc[2];
                float v2[2], v3[2];
                EditVert *centerVert, *upVert, *downVert;
-               
-// XXX         getmouseco_areawin(mval);  
-               
+
+// XXX         getmouseco_areawin(mval);
+
                if (!immediate && (mval[0] == mvalo[0] && mval[1] ==  mvalo[1])) {
                        PIL_sleep_ms(10);
                } else {
                        char *p = str;
                        int ctrl= 0, shift= 0; // XXX
-                       
+
                        mvalo[0] = mval[0];
                        mvalo[1] = mval[1];
-                       
+
 
                        tempsv = BLI_ghash_lookup(vertgh,nearest);
 
@@ -4321,31 +4323,31 @@ useless:
 //                     view3d_project_float(curarea, upVert->co, v2, projectMat);
 //                     view3d_project_float(curarea, downVert->co, v3, projectMat);
 
-                       /* Determine the % on which the loop should be cut */   
+                       /* Determine the % on which the loop should be cut */
 
-                       rc[0]= v3[0]-v2[0];   
-                       rc[1]= v3[1]-v2[1];   
+                       rc[0]= v3[0]-v2[0];
+                       rc[1]= v3[1]-v2[1];
                        len= rc[0]*rc[0]+ rc[1]*rc[1];
                        if (len==0) {len = 0.0001;}
 
                        if (shift) {
                                wasshift = 0;
-                               labda= ( rc[0]*((mval[0]-v2[0])) + rc[1]*((mval[1]-v2[1])) )/len;   
+                               labda= ( rc[0]*((mval[0]-v2[0])) + rc[1]*((mval[1]-v2[1])) )/len;
                        }
                        else {
                                if (wasshift==0) {
                                        wasshift = 1;
                                        shiftlabda = labda;
-                               }                                                       
-                               labda= ( rc[0]*((mval[0]-v2[0])) + rc[1]*((mval[1]-v2[1])) )/len / 10.0 + shiftlabda;                           
+                               }
+                               labda= ( rc[0]*((mval[0]-v2[0])) + rc[1]*((mval[1]-v2[1])) )/len / 10.0 + shiftlabda;
                        }
-                       
 
-                       if(labda<=0.0) labda=0.0;   
-                       else if(labda>=1.0)labda=1.0;   
 
-                       perc=((1-labda)*2)-1;             
-                       
+                       if(labda<=0.0) labda=0.0;
+                       else if(labda>=1.0)labda=1.0;
+
+                       perc=((1-labda)*2)-1;
+
                        if(shift == 0 && ctrl==0) {
                                perc *= 100;
                                perc = floor(perc);
@@ -4353,20 +4355,20 @@ useless:
                        } else if (ctrl) {
                                perc *= 10;
                                perc = floor(perc);
-                               perc /= 10;                                
-                       }                       
-                       
+                               perc /= 10;
+                       }
+
                        if(prop == 0) {
                                len = VecLenf(upVert->co,downVert->co)*((perc+1)/2);
                                if(flip == 1) {
                                        len = VecLenf(upVert->co,downVert->co) - len;
-                               } 
+                               }
                        }
-                       
+
                        if (0) // XXX hasNumInput(&num))
                        {
 // XXX                         applyNumInput(&num, &perc);
-                               
+
                                if (prop)
                                {
                                        perc = MIN2(perc, 1);
@@ -4381,19 +4383,19 @@ useless:
 
                        //Adjust Edgeloop
                        if(immediate) {
-                               perc = imperc;   
+                               perc = imperc;
                        }
                        percp = perc;
                        if(prop) {
-                               look = vertlist;          
-                               while(look) { 
+                               look = vertlist;
+                               while(look) {
                                        EditVert *tempev;
                                        ev = look->link;
                                        tempsv = BLI_ghash_lookup(vertgh,ev);
-                                       
+
                                        tempev = editedge_getOtherVert((perc>=0)?tempsv->up:tempsv->down, ev);
                                        VecLerpf(ev->co, tempsv->origvert.co, tempev->co, fabs(perc));
-                                       
+
                                        if (0) { // XXX scene->toolsettings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT) {
                                                for (uvlay_idx=0; uvlay_idx<uvlay_tot; uvlay_idx++) {
                                                        suv = BLI_ghash_lookup( uvarray[uvlay_idx], ev );
@@ -4407,14 +4409,14 @@ useless:
                                                        }
                                                }
                                        }
-                                       
-                                       look = look->next;       
+
+                                       look = look->next;
                                }
                        }
                        else {
-                               //Non prop code  
-                               look = vertlist;          
-                               while(look) { 
+                               //Non prop code
+                               look = vertlist;
+                               while(look) {
                                        float newlen;
                                        ev = look->link;
                                        tempsv = BLI_ghash_lookup(vertgh,ev);
@@ -4422,7 +4424,7 @@ useless:
                                        if(newlen > 1.0) {newlen = 1.0;}
                                        if(newlen < 0.0) {newlen = 0.0;}
                                        if(flip == 0) {
-                                               VecLerpf(ev->co, editedge_getOtherVert(tempsv->down,ev)->co, editedge_getOtherVert(tempsv->up,ev)->co, fabs(newlen));                                                                   
+                                               VecLerpf(ev->co, editedge_getOtherVert(tempsv->down,ev)->co, editedge_getOtherVert(tempsv->up,ev)->co, fabs(newlen));
                                                if (0) { // XXX scene->toolsettings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT) {
                                                        /* dont do anything if no UVs */
                                                        for (uvlay_idx=0; uvlay_idx<uvlay_tot; uvlay_idx++) {
@@ -4438,8 +4440,8 @@ useless:
                                                        }
                                                }
                                        } else{
-                                               VecLerpf(ev->co, editedge_getOtherVert(tempsv->up,ev)->co, editedge_getOtherVert(tempsv->down,ev)->co, fabs(newlen));                           
-                                               
+                                               VecLerpf(ev->co, editedge_getOtherVert(tempsv->up,ev)->co, editedge_getOtherVert(tempsv->down,ev)->co, fabs(newlen));
+
                                                if (0) { // XXX scene->toolsettings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT) {
                                                        /* dont do anything if no UVs */
                                                        for (uvlay_idx=0; uvlay_idx<uvlay_tot; uvlay_idx++) {
@@ -4455,23 +4457,23 @@ useless:
                                                        }
                                                }
                                        }
-                                       look = look->next;       
+                                       look = look->next;
                                }
 
                        }
-                       
+
                         // Highlight the Control Edges
-//                     scrarea_do_windraw(curarea);   
-//                     persp(PERSP_VIEW);   
-//                     glPushMatrix();   
+//                     scrarea_do_windraw(curarea);
+//                     persp(PERSP_VIEW);
+//                     glPushMatrix();
 //                     mymultmatrix(obedit->obmat);
 
-                       glColor3ub(0, 255, 0);   
+                       glColor3ub(0, 255, 0);
                        glBegin(GL_LINES);
                        glVertex3fv(upVert->co);
                        glVertex3fv(downVert->co);
-                       glEnd(); 
-                       
+                       glEnd();
+
                        if(prop == 0) {
                                // draw start edge for non-prop
                                glPointSize(5);
@@ -4480,24 +4482,24 @@ useless:
                                if(flip) {
                                        glVertex3fv(upVert->co);
                                } else {
-                                       glVertex3fv(downVert->co);                                      
+                                       glVertex3fv(downVert->co);
                                }
-                               glEnd();        
+                               glEnd();
                        }
-                       
-                       
-                       glPopMatrix();           
+
+
+                       glPopMatrix();
 
                        if(prop) {
                                p += sprintf(str, "(P)ercentage: ");
                        } else {
                                p += sprintf(str, "Non (P)rop Length: ");
                        }
-                       
+
                        if (0) // XXX hasNumInput(&num))
                        {
                                char num_str[20];
-                               
+
                                // XX outputNumInput(&num, num_str);
                                p += sprintf(p, "%s", num_str);
                        }
@@ -4512,20 +4514,20 @@ useless:
                                        p += sprintf(p, "%f", len);
                                }
                        }
-                       
-                       
+
+
                        if (prop == 0) {
                                p += sprintf(p, ", Press (F) to flip control side");
                        }
 
 //                     headerprint(str);
-//                     screen_swapbuffers();                   
+//                     screen_swapbuffers();
                }
                if(!immediate) {
                        while(qtest()) {
-                               short val=0;                    
-                               event= extern_qread(&val);      // extern_qread stores important events for the mainloop to handle 
-                                       
+                               short val=0;
+                               event= extern_qread(&val);      // extern_qread stores important events for the mainloop to handle
+
                                /* val==0 on key-release event */
                                if (val) {
                                        if(ELEM(event, ESCKEY, RIGHTMOUSE)) {
@@ -4537,7 +4539,7 @@ useless:
                                        } else if(ELEM3(event, PADENTER, LEFTMOUSE, RETKEY)) {
                                                        draw = 0; // End looping now
                                        } else if(event==MIDDLEMOUSE) {
-                                                       perc = 0;  
+                                                       perc = 0;
                                                        immediate = 1;
                                        } else if(event==PKEY) {
 // XXX                                                 initNumInput(&num); /* reset num input */
@@ -4548,61 +4550,61 @@ useless:
                                                        else {
                                                                prop = 1;
                                                        }
-                                                       mvalo[0] = -1;  
+                                                       mvalo[0] = -1;
                                        } else if(event==FKEY) {
-                                                       (flip == 1) ? (flip = 0):(flip = 1); 
-                                                       mvalo[0] = -1; 
+                                                       (flip == 1) ? (flip = 0):(flip = 1);
+                                                       mvalo[0] = -1;
                                        } else if(ELEM(event, RIGHTARROWKEY, WHEELUPMOUSE)) { // Scroll through Control Edges
-                                               look = vertlist;        
-                                               while(look) {   
+                                               look = vertlist;
+                                               while(look) {
                                                        if(nearest == (EditVert*)look->link) {
                                                                if(look->next == NULL) {
-                                                                       nearest =  (EditVert*)vertlist->link;  
+                                                                       nearest =  (EditVert*)vertlist->link;
                                                                } else {
                                                                        nearest = (EditVert*)look->next->link;
-                                                               }        
+                                                               }
                                                                mvalo[0] = -1;
-                                                               break;                          
+                                                               break;
                                                        }
-                                                       look = look->next;   
-                                               }         
+                                                       look = look->next;
+                                               }
                                        } else if(ELEM(event, LEFTARROWKEY, WHEELDOWNMOUSE)) { // Scroll through Control Edges
-                                               look = vertlist;        
-                                               while(look) {   
+                                               look = vertlist;
+                                               while(look) {
                                                        if(look->next) {
                                                                if(look->next->link == nearest) {
                                                                        nearest = (EditVert*)look->link;
                                                                        mvalo[0] = -1;
                                                                        break;
-                                                               }         
+                                                               }
                                                        } else {
                                                                if((EditVert*)vertlist->link == nearest) {
                                                                        nearest = look->link;
                                                                        mvalo[0] = -1;
-                                                                       break;                                                   
-                                                               }          
-                                                       }   
-                                                       look = look->next;   
-                                               }         
+                                                                       break;
+                                                               }
+                                                       }
+                                                       look = look->next;
+                                               }
                                        }
-                                       
+
 // XXX                                 if (handleNumInput(&num, event))
                                        {
                                                mvalo[0] = -1; /* NEED A BETTER WAY TO TRIGGER REDRAW */
                                        }
                                }
-                               
-                       } 
+
+                       }
                } else {
                        draw = 0;
                }
-//             DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);  
+//             DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
        }
-       
-       
+
+
        if(me->drawflag & ME_DRAW_EDGELEN) {
                look = vertlist;
-               while(look) {   
+               while(look) {
                        tempsv  = BLI_ghash_lookup(vertgh,(EditVert*)look->link);
                        if(tempsv != NULL) {
                                tempsv->up->f &= !SELECT;
@@ -4611,26 +4613,26 @@ useless:
                        look = look->next;
                }
        }
-       
+
 //     force_draw(0);
-       
+
        if(!immediate)
                EM_automerge(0);
 //     DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
-//     scrarea_queue_winredraw(curarea);                
-       
-       //BLI_ghash_free(edgesgh, freeGHash, NULL); 
+//     scrarea_queue_winredraw(curarea);
+
+       //BLI_ghash_free(edgesgh, freeGHash, NULL);
        BLI_ghash_free(vertgh, NULL, (GHashValFreeFP)MEM_freeN);
-       BLI_linklist_free(vertlist,NULL); 
-       BLI_linklist_free(edgelist,NULL); 
-       
+       BLI_linklist_free(vertlist,NULL);
+       BLI_linklist_free(edgelist,NULL);
+
        if (uvlay_tot) { // XXX  && (scene->toolsettings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT)) {
                for (uvlay_idx=0; uvlay_idx<uvlay_tot; uvlay_idx++) {
                        BLI_ghash_free(uvarray[uvlay_idx], NULL, NULL);
                }
                MEM_freeN(uvarray);
                MEM_freeN(slideuvs);
-               
+
                suv = suv_last-1;
                while (suv >= slideuvs) {
                        if (suv->fuv_list) {
@@ -4648,21 +4650,21 @@ useless:
 #endif // END OF XXX
 }
 
-int EdgeLoopDelete(EditMesh *em, wmOperator *op) 
+int EdgeLoopDelete(EditMesh *em, wmOperator *op)
 {
-       
+
        /* temporal flag setting so we keep UVs when deleting edge loops,
        * this is a bit of a hack but it works how you would want in almost all cases */
-       //      short uvcalc_flag_orig = 0; // XXX scene->toolsettings->uvcalc_flag; 
+       //      short uvcalc_flag_orig = 0; // XXX scene->toolsettings->uvcalc_flag;
        //      scene->toolsettings->uvcalc_flag |= UVCALC_TRANSFORM_CORRECT;
-       
+
        if(!EdgeSlide(em, op, 1, 1)) {
                return 0;
        }
-       
+
        /* restore uvcalc flag */
        //      scene->toolsettings->uvcalc_flag = uvcalc_flag_orig;
-       
+
        EM_select_more(em);
        removedoublesflag(em, 1,0, 0.001);
        EM_select_flush(em);
@@ -4683,12 +4685,12 @@ void mesh_set_face_flags(EditMesh *em, short mode)
                        m_billboard=0, m_shadow=0, m_text=0,
                        m_sort=0;
        short flag = 0, change = 0;
-       
+
 // XXX if (!EM_texFaceCheck()) {
 //             error("not a mesh with uv/image layers");
 //             return;
 //     }
-       
+
        add_numbut(0, TOG|SHO, "Texture", 0, 0, &m_tex, NULL);
        add_numbut(2, TOG|SHO, "Light", 0, 0, &m_light, NULL);
        add_numbut(3, TOG|SHO, "Invisible", 0, 0, &m_invis, NULL);
@@ -4701,15 +4703,15 @@ void mesh_set_face_flags(EditMesh *em, short mode)
        add_numbut(10, TOG|SHO, "Shadow", 0, 0, &m_shadow, NULL);
        add_numbut(11, TOG|SHO, "Text", 0, 0, &m_text, NULL);
        add_numbut(12, TOG|SHO, "Sort", 0, 0, &m_sort, NULL);
-       
+
        if (!do_clever_numbuts((mode ? "Set Flags" : "Clear Flags"), 13, REDRAW))
                return;
-       
+
        /* these 2 cant both be on */
        if (mode) /* are we seeting*/
                if (m_halo)
                        m_billboard = 0;
-       
+
        if (m_tex)                      flag |= TF_TEX;
        if (m_shared)           flag |= TF_SHAREDCOL;
        if (m_light)            flag |= TF_LIGHT;
@@ -4722,10 +4724,10 @@ void mesh_set_face_flags(EditMesh *em, short mode)
        if (m_shadow)           flag |= TF_SHADOW;
        if (m_text)                     flag |= TF_BMFONT;
        if (m_sort)                     flag |= TF_ALPHASORT;
-       
+
        if (flag==0)
                return;
-       
+
        efa= em->faces.first;
        while(efa) {
                if(efa->f & SELECT) {
@@ -4736,7 +4738,7 @@ void mesh_set_face_flags(EditMesh *em, short mode)
                }
                efa= efa->next;
        }
-       
+
 }
 #endif
 
@@ -4746,12 +4748,12 @@ void mesh_set_face_flags(EditMesh *em, short mode)
 static float mesh_rip_edgedist(ARegion *ar, float mat[][4], float *co1, float *co2, short *mval)
 {
        float vec1[3], vec2[3], mvalf[2];
-       
+
        view3d_project_float(ar, co1, vec1, mat);
        view3d_project_float(ar, co2, vec2, mat);
        mvalf[0]= (float)mval[0];
        mvalf[1]= (float)mval[1];
-       
+
        return PdistVL2Dfl(mvalf, vec1, vec2);
 }
 
@@ -4763,16 +4765,16 @@ static void mesh_rip_setface(EditMesh *em, EditFace *sefa)
        if(sefa->v2->tmp.v) sefa->v2= sefa->v2->tmp.v;
        if(sefa->v3->tmp.v) sefa->v3= sefa->v3->tmp.v;
        if(sefa->v4 && sefa->v4->tmp.v) sefa->v4= sefa->v4->tmp.v;
-       
+
        sefa->e1= addedgelist(em, sefa->v1, sefa->v2, sefa->e1);
        sefa->e2= addedgelist(em, sefa->v2, sefa->v3, sefa->e2);
        if(sefa->v4) {
                sefa->e3= addedgelist(em, sefa->v3, sefa->v4, sefa->e3);
                sefa->e4= addedgelist(em, sefa->v4, sefa->v1, sefa->e4);
        }
-       else 
+       else
                sefa->e3= addedgelist(em, sefa->v3, sefa->v1, sefa->e3);
-       
+
 }
 
 /* based on mouse cursor position, it defines how is being ripped */
@@ -4787,32 +4789,26 @@ static int mesh_rip_invoke(bContext *C, wmOperator *op, wmEvent *event)
        EditEdge *eed, *seed= NULL;
        EditFace *efa, *sefa= NULL;
        float projectMat[4][4], vec[3], dist, mindist;
-       short doit= 1, *mval= event->mval; // XXX ,propmode,prop;
-       
-       
-// XXX propmode = scene->prop_mode;
-//     scene->prop_mode = 0;
-//     prop = scene->proportional;
-//     scene->proportional = 0;
-       
+       short doit= 1, *mval= event->mval;
+
        /* select flush... vertices are important */
        EM_selectmode_set(em);
-       
+
        view3d_get_object_project_mat(rv3d, obedit, projectMat);
 
        /* find best face, exclude triangles and break on face select or faces with 2 edges select */
        mindist= 1000000.0f;
        for(efa= em->faces.first; efa; efa=efa->next) {
-               if( efa->f & 1) 
+               if( efa->f & 1)
                        break;
                if(efa->v4 && faceselectedOR(efa, SELECT) ) {
                        int totsel=0;
-                       
+
                        if(efa->e1->f & SELECT) totsel++;
                        if(efa->e2->f & SELECT) totsel++;
                        if(efa->e3->f & SELECT) totsel++;
                        if(efa->e4->f & SELECT) totsel++;
-                       
+
                        if(totsel>1)
                                break;
                        view3d_project_float(ar, efa->cent, vec, projectMat);
@@ -4823,7 +4819,7 @@ static int mesh_rip_invoke(bContext *C, wmOperator *op, wmEvent *event)
                        }
                }
        }
-       
+
        if(efa) {
                BKE_report(op->reports, RPT_ERROR, "Can't perform ripping with faces selected this way");
                BKE_mesh_end_editmesh(obedit->data, em);
@@ -4834,7 +4830,7 @@ static int mesh_rip_invoke(bContext *C, wmOperator *op, wmEvent *event)
                BKE_mesh_end_editmesh(obedit->data, em);
                return OPERATOR_CANCELLED;
        }
-       
+
 
        /* duplicate vertices, new vertices get selected */
        for(eve = em->verts.last; eve; eve= eve->prev) {
@@ -4845,20 +4841,20 @@ static int mesh_rip_invoke(bContext *C, wmOperator *op, wmEvent *event)
                        eve->tmp.v->f |= SELECT;
                }
        }
-       
+
        /* find the best candidate edge */
        /* or one of sefa edges is selected... */
        if(sefa->e1->f & SELECT) seed= sefa->e2;
        if(sefa->e2->f & SELECT) seed= sefa->e1;
        if(sefa->e3->f & SELECT) seed= sefa->e2;
        if(sefa->e4 && sefa->e4->f & SELECT) seed= sefa->e3;
-       
+
        /* or we do the distance trick */
        if(seed==NULL) {
                mindist= 1000000.0f;
                if(sefa->e1->v1->tmp.v || sefa->e1->v2->tmp.v) {
-                       dist = mesh_rip_edgedist(ar, projectMat, 
-                                                                        sefa->e1->v1->co, 
+                       dist = mesh_rip_edgedist(ar, projectMat,
+                                                                        sefa->e1->v1->co,
                                                                         sefa->e1->v2->co, mval);
                        if(dist<mindist) {
                                seed= sefa->e1;
@@ -4867,7 +4863,7 @@ static int mesh_rip_invoke(bContext *C, wmOperator *op, wmEvent *event)
                }
                if(sefa->e2->v1->tmp.v || sefa->e2->v2->tmp.v) {
                        dist = mesh_rip_edgedist(ar, projectMat,
-                                                                        sefa->e2->v1->co, 
+                                                                        sefa->e2->v1->co,
                                                                         sefa->e2->v2->co, mval);
                        if(dist<mindist) {
                                seed= sefa->e2;
@@ -4875,8 +4871,8 @@ static int mesh_rip_invoke(bContext *C, wmOperator *op, wmEvent *event)
                        }
                }
                if(sefa->e3->v1->tmp.v || sefa->e3->v2->tmp.v) {
-                       dist= mesh_rip_edgedist(ar, projectMat, 
-                                                                       sefa->e3->v1->co, 
+                       dist= mesh_rip_edgedist(ar, projectMat,
+                                                                       sefa->e3->v1->co,
                                                                        sefa->e3->v2->co, mval);
                        if(dist<mindist) {
                                seed= sefa->e3;
@@ -4884,8 +4880,8 @@ static int mesh_rip_invoke(bContext *C, wmOperator *op, wmEvent *event)
                        }
                }
                if(sefa->e4 && (sefa->e4->v1->tmp.v || sefa->e4->v2->tmp.v)) {
-                       dist= mesh_rip_edgedist(ar, projectMat, 
-                                                                       sefa->e4->v1->co, 
+                       dist= mesh_rip_edgedist(ar, projectMat,
+                                                                       sefa->e4->v1->co,
                                                                        sefa->e4->v2->co, mval);
                        if(dist<mindist) {
                                seed= sefa->e4;
@@ -4893,13 +4889,13 @@ static int mesh_rip_invoke(bContext *C, wmOperator *op, wmEvent *event)
                        }
                }
        }
-       
+
        if(seed==NULL) {        // never happens?
                BKE_report(op->reports, RPT_ERROR, "No proper edge found to start");
                BKE_mesh_end_editmesh(obedit->data, em);
                return OPERATOR_CANCELLED;
        }
-       
+
        faceloop_select(em, seed, 2);   // tmp abuse for finding all edges that need duplicated, returns OK faces with f1
 
        /* duplicate edges in the loop, with at least 1 vertex selected, needed for selection flip */
@@ -4907,8 +4903,8 @@ static int mesh_rip_invoke(bContext *C, wmOperator *op, wmEvent *event)
                eed->tmp.v = NULL;
                if((eed->v1->tmp.v) || (eed->v2->tmp.v)) {
                        EditEdge *newed;
-                       
-                       newed= addedgelist(em, eed->v1->tmp.v?eed->v1->tmp.v:eed->v1, 
+
+                       newed= addedgelist(em, eed->v1->tmp.v?eed->v1->tmp.v:eed->v1,
                                                           eed->v2->tmp.v?eed->v2->tmp.v:eed->v2, eed);
                        if(eed->f & SELECT) {
                                EM_select_edge(eed, 0);
@@ -4924,16 +4920,16 @@ static int mesh_rip_invoke(bContext *C, wmOperator *op, wmEvent *event)
 
        /* put new vertices & edges && flag in best face */
        mesh_rip_setface(em, sefa);
-       
+
        /* starting with neighbours of best face, we loop over the seam */
        sefa->f1= 2;
        doit= 1;
        while(doit) {
                doit= 0;
-               
+
                for(efa= em->faces.first; efa; efa=efa->next) {
                        /* new vert in face */
-                       if (efa->v1->tmp.v || efa->v2->tmp.v || 
+                       if (efa->v1->tmp.v || efa->v2->tmp.v ||
                                efa->v3->tmp.v || (efa->v4 && efa->v4->tmp.v)) {
                                /* face is tagged with loop */
                                if(efa->f1==1) {
@@ -4942,9 +4938,9 @@ static int mesh_rip_invoke(bContext *C, wmOperator *op, wmEvent *event)
                                        doit= 1;
                                }
                        }
-               }               
+               }
        }
-       
+
        /* remove loose edges, that were part of a ripped face */
        for(eve = em->verts.first; eve; eve= eve->next) eve->f1= 0;
        for(eed = em->edges.last; eed; eed= eed->prev) eed->f1= 0;
@@ -4954,11 +4950,11 @@ static int mesh_rip_invoke(bContext *C, wmOperator *op, wmEvent *event)
                efa->e3->f1= 1;
                if(efa->e4) efa->e4->f1= 1;
        }
-       
+
        for(eed = em->edges.last; eed; eed= seed) {
                seed= eed->prev;
                if(eed->f1==0) {
-                       if(eed->v1->tmp.v || eed->v2->tmp.v || 
+                       if(eed->v1->tmp.v || eed->v2->tmp.v ||
                           (eed->v1->f & SELECT) || (eed->v2->f & SELECT)) {
                                remedge(em, eed);
                                free_editedge(em, eed);
@@ -4970,7 +4966,7 @@ static int mesh_rip_invoke(bContext *C, wmOperator *op, wmEvent *event)
                        eed->v2->f1= 1;
                }
        }
-       
+
        /* and remove loose selected vertices, that got duplicated accidentally */
        for(eve = em->verts.first; eve; eve= nextve) {
                nextve= eve->next;
@@ -4979,17 +4975,15 @@ static int mesh_rip_invoke(bContext *C, wmOperator *op, wmEvent *event)
                        free_editvert(em, eve);
                }
        }
-       
+
        DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
 
        BKE_mesh_end_editmesh(obedit->data, em);
 
-       RNA_int_set(op->ptr, "mode", TFM_TRANSLATION);
-       WM_operator_name_call(C, "TFM_OT_transform", WM_OP_INVOKE_REGION_WIN, op->ptr);
-
-//     scene->prop_mode = propmode;
-// XXX scene->proportional = prop;
+       RNA_enum_set(op->ptr, "proportional", 0);
+       RNA_boolean_set(op->ptr, "mirror", 0);
+       WM_operator_name_call(C, "TFM_OT_translation", WM_OP_INVOKE_REGION_WIN, op->ptr);
 
        return OPERATOR_FINISHED;
 }
@@ -4999,16 +4993,17 @@ void MESH_OT_rip(wmOperatorType *ot)
        /* identifiers */
        ot->name= "Rip";
        ot->idname= "MESH_OT_rip";
-       
+
        /* api callbacks */
        ot->invoke= mesh_rip_invoke;
        ot->poll= EM_view3d_poll;
-       
+
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
+
        /* to give to transform */
-       RNA_def_int(ot->srna, "mode", TFM_TRANSLATION, 0, INT_MAX, "Mode", "", 0, INT_MAX);
+       Properties_Proportional(ot);
+       RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
 }
 
 
@@ -5021,39 +5016,39 @@ void shape_propagate(Scene *scene, Object *obedit, EditMesh *em, wmOperator *op)
        Key*  ky = NULL;
        KeyBlock* kb = NULL;
        Base* base=NULL;
-       
-       
+
+
        if(me->key){
                ky = me->key;
        } else {
-               BKE_report(op->reports, RPT_ERROR, "Object Has No Key");        
+               BKE_report(op->reports, RPT_ERROR, "Object Has No Key");
                return;
-       }       
+       }
 
        if(ky->block.first){
                for(ev = em->verts.first; ev ; ev = ev->next){
                        if(ev->f & SELECT){
                                for(kb=ky->block.first;kb;kb = kb->next){
-                                       float *data;            
-                                       data = kb->data;                        
-                                       VECCOPY(data+(ev->keyindex*3),ev->co);                          
+                                       float *data;
+                                       data = kb->data;
+                                       VECCOPY(data+(ev->keyindex*3),ev->co);
                                }
-                       }               
-               }                                               
+                       }
+               }
        } else {
-               BKE_report(op->reports, RPT_ERROR, "Object Has No Blendshapes");        
-               return;                 
+               BKE_report(op->reports, RPT_ERROR, "Object Has No Blendshapes");
+               return;
        }
-       
+
        //TAG Mesh Objects that share this data
        for(base = scene->base.first; base; base = base->next){
                if(base->object && base->object->data == me){
                        base->object->recalc = OB_RECALC_DATA;
                }
-       }               
+       }
 
        DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
-       return; 
+       return;
 }
 
 void shape_copy_from_lerp(EditMesh *em, KeyBlock* thisBlock, KeyBlock* fromBlock)
@@ -5063,10 +5058,10 @@ void shape_copy_from_lerp(EditMesh *em, KeyBlock* thisBlock, KeyBlock* fromBlock
        float perc = 0;
        char str[64];
        float *data, *odata;
-                               
+
        data  = fromBlock->data;
        odata = thisBlock->data;
-       
+
 // XXX getmouseco_areawin(mval);
        curval[0] = mval[0] + 1; curval[1] = mval[1] + 1;
 
@@ -5075,55 +5070,55 @@ void shape_copy_from_lerp(EditMesh *em, KeyBlock* thisBlock, KeyBlock* fromBlock
 // XXX         getmouseco_areawin(mval);
                if (mval[0] != curval[0] || mval[1] != curval[1])
                {
-                       
+
                        if(mval[0] > curval[0])
                                perc += 0.1;
                        else if(mval[0] < curval[0])
                                perc -= 0.1;
-                               
+
                        if(perc < 0) perc = 0;
                        if(perc > 1) perc = 1;
-                       
+
                        curval[0] = mval[0];
                        curval[1] = mval[1];
 
                        if(fullcopy == 1){
-                               perc = 1;       
+                               perc = 1;
                        }
 
                        for(ev = em->verts.first; ev ; ev = ev->next){
                                if(ev->f & SELECT){
                                        VecLerpf(ev->co,odata+(ev->keyindex*3),data+(ev->keyindex*3),perc);
-                               }               
-                       }       
+                               }
+                       }
                        sprintf(str,"Blending at %d%c  MMB to Copy at 100%c",(int)(perc*100),'%','%');
 //                     DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
 //                     headerprint(str);
-//                     force_draw(0);                  
+//                     force_draw(0);
 
                        if(fullcopy == 1){
-                               break;  
+                               break;
                        }
 
                } else {
-                       PIL_sleep_ms(10);       
+                       PIL_sleep_ms(10);
                }
 
                while(qtest()) {
-                       short val=0;                    
-                       event= extern_qread(&val);      
+                       short val=0;
+                       event= extern_qread(&val);
                        if(val){
                                if(ELEM3(event, PADENTER, LEFTMOUSE, RETKEY)){
                                        finished = 1;
                                }
                                else if (event == MIDDLEMOUSE){
-                                       fullcopy = 1;   
+                                       fullcopy = 1;
                                }
                                else if (ELEM3(event,ESCKEY,RIGHTMOUSE,RIGHTMOUSE)){
                                        canceled = 1;
                                        finished = 1;
                                }
-                       } 
+                       }
                }
        }
        if(!canceled);
@@ -5131,7 +5126,7 @@ void shape_copy_from_lerp(EditMesh *em, KeyBlock* thisBlock, KeyBlock* fromBlock
                for(ev = em->verts.first; ev ; ev = ev->next){
                        if(ev->f & SELECT){
                                VECCOPY(ev->co, odata+(ev->keyindex*3));
-                       }               
+                       }
                }
        return;
 }
@@ -5143,63 +5138,63 @@ void shape_copy_select_from(Object *obedit, EditMesh *em, wmOperator *op)
        Mesh* me = (Mesh*)obedit->data;
        EditVert *ev = NULL;
        int totverts = 0,curshape = obedit->shapenr;
-       
+
        Key*  ky = NULL;
        KeyBlock *kb = NULL,*thisBlock = NULL;
        int maxlen=32, nr=0, a=0;
        char *menu;
-       
+
        if(me->key){
                ky = me->key;
        } else {
-               BKE_report(op->reports, RPT_ERROR, "Object Has No Key");        
+               BKE_report(op->reports, RPT_ERROR, "Object Has No Key");
                return;
        }
-       
+
        if(ky->block.first){
                for(kb=ky->block.first;kb;kb = kb->next){
                        maxlen += 40; // Size of a block name
                        if(a == curshape-1){
-                                       thisBlock = kb;         
+                                       thisBlock = kb;
                        }
-                       
+
                        a++;
                }
                a=0;
                menu = MEM_callocN(maxlen, "Copy Shape Menu Text");
                strcpy(menu, "Copy Vert Positions from Shape %t|");
                for(kb=ky->block.first;kb;kb = kb->next){
-                       if(a != curshape-1){ 
+                       if(a != curshape-1){
                                sprintf(menu,"%s %s %cx%d|",menu,kb->name,'%',a);
                        }
                        a++;
                }
 // XXX         nr = pupmenu_col(menu, 20);
-               MEM_freeN(menu);                
+               MEM_freeN(menu);
        } else {
-               BKE_report(op->reports, RPT_ERROR, "Object Has No Blendshapes");        
-               return;                 
+               BKE_report(op->reports, RPT_ERROR, "Object Has No Blendshapes");
+               return;
        }
-       
+
        a = 0;
-       
+
        for(kb=ky->block.first;kb;kb = kb->next){
                if(a == nr){
-                       
+
                        for(ev = em->verts.first;ev;ev = ev->next){
                                totverts++;
                        }
-                       
+
                        if(me->totvert != totverts){
                                BKE_report(op->reports, RPT_ERROR, "Shape Has had Verts Added/Removed, please cycle editmode before copying");
-                               return; 
+                               return;
                        }
-                       shape_copy_from_lerp(em, thisBlock,kb);         
-                                       
+                       shape_copy_from_lerp(em, thisBlock,kb);
+
                        return;
                }
                a++;
-       }               
+       }
        return;
 }
 
@@ -5228,17 +5223,17 @@ static void build_edgecollection(EditMesh *em, ListBase *allcollections)
        EditEdge *eed;
        Collection *edgecollection, *newcollection;
        CollectedEdge *newedge;
-       
+
        int currtag = 1;
        short ebalanced = 0;
        short collectionfound = 0;
-       
-       for (eed=em->edges.first; eed; eed = eed->next){        
+
+       for (eed=em->edges.first; eed; eed = eed->next){
                eed->tmp.l = 0;
                eed->v1->tmp.l = 0;
                eed->v2->tmp.l = 0;
        }
-       
+
        /*1st pass*/
        for(eed=em->edges.first; eed; eed=eed->next){
                        if(eed->f&SELECT){
@@ -5247,26 +5242,26 @@ static void build_edgecollection(EditMesh *em, ListBase *allcollections)
                                currtag +=1;
                        }
        }
-                       
+
        /*2nd pass - Brute force. Loop through selected faces until there are no 'unbalanced' edges left (those with both vertices 'tmp.l' tag matching */
        while(ebalanced == 0){
                ebalanced = 1;
                for(eed=em->edges.first; eed; eed = eed->next){
                        if(eed->f&SELECT){
                                if(eed->v1->tmp.l != eed->v2->tmp.l) /*unbalanced*/{
-                                       if(eed->v1->tmp.l > eed->v2->tmp.l && eed->v2->tmp.l !=0) eed->v1->tmp.l = eed->v2->tmp.l; 
-                                       else if(eed->v1 != 0) eed->v2->tmp.l = eed->v1->tmp.l; 
+                                       if(eed->v1->tmp.l > eed->v2->tmp.l && eed->v2->tmp.l !=0) eed->v1->tmp.l = eed->v2->tmp.l;
+                                       else if(eed->v1 != 0) eed->v2->tmp.l = eed->v1->tmp.l;
                                        ebalanced = 0;
                                }
                        }
                }
        }
-       
+
        /*3rd pass, set all the edge flags (unnessecary?)*/
        for(eed=em->edges.first; eed; eed = eed->next){
                if(eed->f&SELECT) eed->tmp.l = eed->v1->tmp.l;
        }
-       
+
        for(eed=em->edges.first; eed; eed=eed->next){
                if(eed->f&SELECT){
                        if(allcollections->first){
@@ -5286,28 +5281,28 @@ static void build_edgecollection(EditMesh *em, ListBase *allcollections)
                                newcollection->index = eed->tmp.l;
                                newcollection->collectionbase.first = 0;
                                newcollection->collectionbase.last = 0;
-                               
+
                                newedge = MEM_mallocN(sizeof(CollectedEdge), "collected edge");
                                newedge->eed = eed;
-                                       
+
                                BLI_addtail(&(newcollection->collectionbase), newedge);
                                BLI_addtail(allcollections, newcollection);
                        }
                }
-               
+
        }
 }
 
 static void freecollections(ListBase *allcollections)
 {
        struct Collection *curcollection;
-       
+
        for(curcollection = allcollections->first; curcollection; curcollection = curcollection->next)
                BLI_freelistN(&(curcollection->collectionbase));
        BLI_freelistN(allcollections);
 }
 
-/*Begin UV Edge Collapse Code 
+/*Begin UV Edge Collapse Code
        Like Edge subdivide, Edge Collapse should handle UV's intelligently, but since UV's are a per-face attribute, normal edge collapse will fail
        in areas such as the boundries of 'UV islands'. So for each edge collection we need to build a set of 'welded' UV vertices and edges for it.
        The welded UV edges can then be sorted and collapsed.
@@ -5337,7 +5332,7 @@ typedef struct wUVEdge{
 typedef struct wUVEdgeCollect{ /*used for grouping*/
        struct wUVEdgeCollect *next, *prev;
        wUVEdge *uved;
-       int id; 
+       int id;
 } wUVEdgeCollect;
 
 static void append_weldedUV(EditMesh *em, EditFace *efa, EditVert *eve, int tfindex, ListBase *uvverts)
@@ -5346,9 +5341,9 @@ static void append_weldedUV(EditMesh *em, EditFace *efa, EditVert *eve, int tfin
        wUVNode *newnode;
        int found;
        MTFace *tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
-       
+
        found = 0;
-       
+
        for(curwvert=uvverts->first; curwvert; curwvert=curwvert->next){
                if(curwvert->eve == eve && curwvert->u == tf->uv[tfindex][0] && curwvert->v == tf->uv[tfindex][1]){
                        newnode = MEM_callocN(sizeof(wUVNode), "Welded UV Vert Node");
@@ -5359,20 +5354,20 @@ static void append_weldedUV(EditMesh *em, EditFace *efa, EditVert *eve, int tfin
                        break;
                }
        }
-       
+
        if(!found){
                newnode = MEM_callocN(sizeof(wUVNode), "Welded UV Vert Node");
                newnode->u = &(tf->uv[tfindex][0]);
                newnode->v = &(tf->uv[tfindex][1]);
-               
+
                newwvert = MEM_callocN(sizeof(wUV), "Welded UV Vert");
                newwvert->u = *(newnode->u);
                newwvert->v = *(newnode->v);
                newwvert->eve = eve;
-               
+
                BLI_addtail(&(newwvert->nodes), newnode);
                BLI_addtail(uvverts, newwvert);
-               
+
        }
 }
 
@@ -5392,14 +5387,14 @@ static void append_weldedUVEdge(EditMesh *em, EditFace *efa, EditEdge *eed, List
        wUVEdge *curwedge, *newwedge;
        int v1tfindex, v2tfindex, found;
        MTFace *tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
-       
+
        found = 0;
-       
+
        if(eed->v1 == efa->v1) v1tfindex = 0;
        else if(eed->v1 == efa->v2) v1tfindex = 1;
        else if(eed->v1 == efa->v3) v1tfindex = 2;
        else /* if(eed->v1 == efa->v4) */ v1tfindex = 3;
-                       
+
        if(eed->v2 == efa->v1) v2tfindex = 0;
        else if(eed->v2 == efa->v2) v2tfindex = 1;
        else if(eed->v2 == efa->v3) v2tfindex = 2;
@@ -5411,7 +5406,7 @@ static void append_weldedUVEdge(EditMesh *em, EditFace *efa, EditEdge *eed, List
                                break; //do nothing, we don't need another welded uv edge
                        }
        }
-       
+
        if(!found){
                newwedge = MEM_callocN(sizeof(wUVEdge), "Welded UV Edge");
                newwedge->v1uv[0] = tf->uv[v1tfindex][0];
@@ -5419,7 +5414,7 @@ static void append_weldedUVEdge(EditMesh *em, EditFace *efa, EditEdge *eed, List
                newwedge->v2uv[0] = tf->uv[v2tfindex][0];
                newwedge->v2uv[1] = tf->uv[v2tfindex][1];
                newwedge->eed = eed;
-               
+
                BLI_addtail(uvedges, newwedge);
        }
 }
@@ -5429,15 +5424,15 @@ static void build_weldedUVEdges(EditMesh *em, ListBase *uvedges, ListBase *uvver
        wUV *curwvert;
        wUVEdge *curwedge;
        EditFace *efa;
-       
+
        for(efa=em->faces.first; efa; efa=efa->next){
                if(efa->e1->f1) append_weldedUVEdge(em, efa, efa->e1, uvedges);
                if(efa->e2->f1) append_weldedUVEdge(em, efa, efa->e2, uvedges);
                if(efa->e3->f1) append_weldedUVEdge(em, efa, efa->e3, uvedges);
                if(efa->e4 && efa->e4->f1) append_weldedUVEdge(em, efa, efa->e4, uvedges);
        }
-       
-       
+
+
        //link vertices: for each uvedge, search uvverts to populate v1 and v2 pointers
        for(curwedge=uvedges->first; curwedge; curwedge=curwedge->next){
                for(curwvert=uvverts->first; curwvert; curwvert=curwvert->next){
@@ -5474,20 +5469,20 @@ static void collapse_edgeuvs(EditMesh *em)
 
        if (!EM_texFaceCheck(em))
                return;
-       
+
        uvverts.first = uvverts.last = uvedges.first = uvedges.last = allcollections.first = allcollections.last = NULL;
-       
+
        build_weldedUVs(em, &uvverts);
        build_weldedUVEdges(em, &uvedges, &uvverts);
-       
+
        curtag = 0;
-       
+
        for(curwedge=uvedges.first; curwedge; curwedge=curwedge->next){
                curwedge->v1->f = curtag;
                curwedge->v2->f = curtag;
                curtag +=1;
        }
-       
+
        balanced = 0;
        while(!balanced){
                balanced = 1;
@@ -5499,10 +5494,10 @@ static void collapse_edgeuvs(EditMesh *em)
                        }
                }
        }
-       
+
        for(curwedge=uvedges.first; curwedge; curwedge=curwedge->next) curwedge->f = curwedge->v1->f;
-       
-       
+
+
        for(curwedge=uvedges.first; curwedge; curwedge=curwedge->next){
                if(allcollections.first){
                        for(wuvecollection = allcollections.first; wuvecollection; wuvecollection=wuvecollection->next){
@@ -5513,7 +5508,7 @@ static void collapse_edgeuvs(EditMesh *em)
                                        collectionfound = 1;
                                        break;
                                }
-                               
+
                                else collectionfound = 0;
                        }
                }
@@ -5522,32 +5517,32 @@ static void collapse_edgeuvs(EditMesh *em)
                        newcollection->index = curwedge->f;
                        newcollection->collectionbase.first = 0;
                        newcollection->collectionbase.last = 0;
-                               
+
                        newcollectedwuve = MEM_callocN(sizeof(wUVEdgeCollect), "Collected Welded UV Edge");
                        newcollectedwuve->uved = curwedge;
-                                       
+
                        BLI_addtail(&(newcollection->collectionbase), newcollectedwuve);
                        BLI_addtail(&allcollections, newcollection);
                }
        }
-               
+
        for(wuvecollection=allcollections.first; wuvecollection; wuvecollection=wuvecollection->next){
-               
+
                vcount = avg[0] = avg[1] = 0;
-               
+
                for(collectedwuve= wuvecollection->collectionbase.first; collectedwuve; collectedwuve = collectedwuve->next){
                        avg[0] += collectedwuve->uved->v1uv[0];
                        avg[1] += collectedwuve->uved->v1uv[1];
-                       
+
                        avg[0] += collectedwuve->uved->v2uv[0];
                        avg[1] += collectedwuve->uved->v2uv[1];
-                       
+
                        vcount +=2;
-               
+
                }
-               
+
                avg[0] /= vcount; avg[1] /= vcount;
-               
+
                for(collectedwuve= wuvecollection->collectionbase.first; collectedwuve; collectedwuve = collectedwuve->next){
                        for(curwnode=collectedwuve->uved->v1->nodes.first; curwnode; curwnode=curwnode->next){
                                *(curwnode->u) = avg[0];
@@ -5559,7 +5554,7 @@ static void collapse_edgeuvs(EditMesh *em)
                        }
                }
        }
-       
+
        free_weldedUVs(&uvverts);
        BLI_freelistN(&uvedges);
        freecollections(&allcollections);
@@ -5576,11 +5571,11 @@ static void collapseuvs(EditMesh *em, EditVert *mergevert)
 
        if (!EM_texFaceCheck(em))
                return;
-       
+
        uvcount = 0;
        uvav[0] = 0;
        uvav[1] = 0;
-       
+
        for(efa = em->faces.first; efa; efa=efa->next){
                tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
 
@@ -5590,7 +5585,7 @@ static void collapseuvs(EditMesh *em, EditVert *mergevert)
                        uvcount += 1;
                }
                if(efa->v2->f1 && ELEM(mergevert, NULL, efa->v2)){
-                       uvav[0] += tf->uv[1][0];                
+                       uvav[0] += tf->uv[1][0];
                        uvav[1] += tf->uv[1][1];
                        uvcount += 1;
                }
@@ -5605,11 +5600,11 @@ static void collapseuvs(EditMesh *em, EditVert *mergevert)
                        uvcount += 1;
                }
        }
-       
+
        if(uvcount > 0) {
-               uvav[0] /= uvcount; 
+               uvav[0] /= uvcount;
                uvav[1] /= uvcount;
-       
+
                for(efa = em->faces.first; efa; efa=efa->next){
                        tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
 
@@ -5618,7 +5613,7 @@ static void collapseuvs(EditMesh *em, EditVert *mergevert)
                                tf->uv[0][1] = uvav[1];
                        }
                        if(efa->v2->f1){
-                               tf->uv[1][0] = uvav[0];         
+                               tf->uv[1][0] = uvav[0];
                                tf->uv[1][1] = uvav[1];
                        }
                        if(efa->v3->f1){
@@ -5637,49 +5632,49 @@ int collapseEdges(EditMesh *em)
 {
        EditVert *eve;
        EditEdge *eed;
-       
+
        ListBase allcollections;
        CollectedEdge *curredge;
        Collection *edgecollection;
-       
+
        int totedges, groupcount, mergecount,vcount;
        float avgcount[3];
-       
+
        allcollections.first = 0;
        allcollections.last = 0;
-       
+
        mergecount = 0;
-       
+
        build_edgecollection(em, &allcollections);
        groupcount = BLI_countlist(&allcollections);
-       
-       
+
+
        for(edgecollection = allcollections.first; edgecollection; edgecollection = edgecollection->next){
                totedges = BLI_countlist(&(edgecollection->collectionbase));
                mergecount += totedges;
                avgcount[0] = 0; avgcount[1] = 0; avgcount[2] = 0;
-               
+
                vcount = 0;
-               
+
                for(curredge = edgecollection->collectionbase.first; curredge; curredge = curredge->next){
                        avgcount[0] += ((EditEdge*)curredge->eed)->v1->co[0];
                        avgcount[1] += ((EditEdge*)curredge->eed)->v1->co[1];
                        avgcount[2] += ((EditEdge*)curredge->eed)->v1->co[2];
-                       
+
                        avgcount[0] += ((EditEdge*)curredge->eed)->v2->co[0];
                        avgcount[1] += ((EditEdge*)curredge->eed)->v2->co[1];
                        avgcount[2] += ((EditEdge*)curredge->eed)->v2->co[2];
-                       
+
                        vcount +=2;
                }
-               
+
                avgcount[0] /= vcount; avgcount[1] /=vcount; avgcount[2] /= vcount;
-               
+
                for(curredge = edgecollection->collectionbase.first; curredge; curredge = curredge->next){
                        VECCOPY(((EditEdge*)curredge->eed)->v1->co,avgcount);
                        VECCOPY(((EditEdge*)curredge->eed)->v2->co,avgcount);
                }
-               
+
                if (EM_texFaceCheck(em)) {
                        /*uv collapse*/
                        for(eve=em->verts.first; eve; eve=eve->next) eve->f1 = 0;
@@ -5691,7 +5686,7 @@ int collapseEdges(EditMesh *em)
                        }
                        collapse_edgeuvs(em);
                }
-               
+
        }
        freecollections(&allcollections);
        removedoublesflag(em, 1, 0, MERGELIMIT);
@@ -5703,44 +5698,44 @@ int merge_firstlast(EditMesh *em, int first, int uvmerge)
 {
        EditVert *eve,*mergevert;
        EditSelection *ese;
-       
+
        /* do sanity check in mergemenu in edit.c ?*/
-       if(first == 0){ 
+       if(first == 0){
                ese = em->selected.last;
                mergevert= (EditVert*)ese->data;
        }
-       else{ 
+       else{
                ese = em->selected.first;
                mergevert = (EditVert*)ese->data;
        }
-       
+
        if(mergevert->f&SELECT){
                for (eve=em->verts.first; eve; eve=eve->next){
                        if (eve->f&SELECT)
                        VECCOPY(eve->co,mergevert->co);
                }
        }
-       
+
        if(uvmerge && CustomData_has_layer(&em->fdata, CD_MTFACE)){
-               
+
                for(eve=em->verts.first; eve; eve=eve->next) eve->f1 = 0;
                for(eve=em->verts.first; eve; eve=eve->next){
                        if(eve->f&SELECT) eve->f1 = 1;
                }
                collapseuvs(em, mergevert);
        }
-       
+
        return removedoublesflag(em, 1, 0, MERGELIMIT);
 }
 
 int merge_target(EditMesh *em, int target, int uvmerge)
 {
        EditVert *eve;
-       
+
        // XXX not working
        if(target) snap_sel_to_curs();
        else snap_to_center();
-       
+
        if(uvmerge && CustomData_has_layer(&em->fdata, CD_MTFACE)){
                for(eve=em->verts.first; eve; eve=eve->next) eve->f1 = 0;
                for(eve=em->verts.first; eve; eve=eve->next){
@@ -5804,19 +5799,19 @@ static EnumPropertyItem *merge_type_itemf(bContext *C, PointerRNA *ptr, int *fre
        Object *obedit= CTX_data_edit_object(C);
 
        if(obedit && obedit->type == OB_MESH) {
-               EditMesh *em= BKE_mesh_get_editmesh(obedit->data); 
+               EditMesh *em= BKE_mesh_get_editmesh(obedit->data);
                EnumPropertyItem *item= NULL;
                int totitem= 0;
 
                if(em->selectmode & SCE_SELECT_VERTEX) {
-                       if(em->selected.first && em->selected.last && 
+                       if(em->selected.first && em->selected.last &&
                                ((EditSelection*)em->selected.first)->type == EDITVERT && ((EditSelection*)em->selected.last)->type == EDITVERT) {
                                RNA_enum_item_add(&item, &totitem, &merge_type_items[0]);
                                RNA_enum_item_add(&item, &totitem, &merge_type_items[1]);
                        }
-                       else if(em->selected.first && ((EditSelection*)em->selected.first)->type == EDITVERT) 
+                       else if(em->selected.first && ((EditSelection*)em->selected.first)->type == EDITVERT)
                                RNA_enum_item_add(&item, &totitem, &merge_type_items[1]);
-                       else if(em->selected.last && ((EditSelection*)em->selected.last)->type == EDITVERT) 
+                       else if(em->selected.last && ((EditSelection*)em->selected.last)->type == EDITVERT)
                                RNA_enum_item_add(&item, &totitem, &merge_type_items[0]);
                }
 
@@ -5840,12 +5835,12 @@ void MESH_OT_merge(wmOperatorType *ot)
        /* identifiers */
        ot->name= "Merge";
        ot->idname= "MESH_OT_merge";
-       
+
        /* api callbacks */
        ot->exec= merge_exec;
        ot->invoke= WM_menu_invoke;
        ot->poll= ED_operator_editmesh;
-       
+
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
@@ -5887,30 +5882,30 @@ int select_vertex_path_exec(bContext *C, wmOperator *op)
        short physical;
        float *cost;
        Heap *heap; /*binary heap for sorting pointers to PathNodes based upon a 'cost'*/
-       
+
        s = t = NULL;
-       
+
        ese = ((EditSelection*)em->selected.last);
        if(ese && ese->type == EDITVERT && ese->prev && ese->prev->type == EDITVERT){
                physical= pupmenu("Distance Method? %t|Edge Length%x1|Topological%x0");
-               
+
                t = (EditVert*)ese->data;
                s = (EditVert*)ese->prev->data;
-               
+
                /*need to find out if t is actually reachable by s....*/
-               for(eve=em->verts.first; eve; eve=eve->next){ 
+               for(eve=em->verts.first; eve; eve=eve->next){
                        eve->f1 = 0;
                }
-               
+
                s->f1 = 1;
-               
+
                unbalanced = 1;
                totnodes = 1;
                while(unbalanced){
                        unbalanced = 0;
                        for(eed=em->edges.first; eed; eed=eed->next){
                                if(!eed->h){
-                                       if(eed->v1->f1 && !eed->v2->f1){ 
+                                       if(eed->v1->f1 && !eed->v2->f1){
                                                        eed->v2->f1 = 1;
                                                        totnodes++;
                                                        unbalanced = 1;
@@ -5923,7 +5918,7 @@ int select_vertex_path_exec(bContext *C, wmOperator *op)
                                }
                        }
                }
-               
+
                if(s->f1 && t->f1){ /* t can be reached by s */
                        Q = MEM_callocN(sizeof(PathNode)*totnodes, "Path Select Nodes");
                        totnodes = 0;
@@ -5938,12 +5933,12 @@ int select_vertex_path_exec(bContext *C, wmOperator *op)
                                }
                                else eve->tmp.p = NULL;
                        }
-                       
+
                        for(eed=em->edges.first; eed; eed=eed->next){
                                if(!eed->h){
                                        if(eed->v1->f1){
                                                currpn = ((PathNode*)eed->v1->tmp.p);
-                                               
+
                                                newpe = MEM_mallocN(sizeof(PathEdge), "Path Edge");
                                                newpe->v = ((PathNode*)eed->v2->tmp.p)->u;
                                                if(physical){
@@ -5953,9 +5948,9 @@ int select_vertex_path_exec(bContext *C, wmOperator *op)
                                                newpe->next = 0;
                                                newpe->prev = 0;
                                                BLI_addtail(&(currpn->edges), newpe);
-                                       } 
+                                       }
                                        if(eed->v2->f1){
-                                               currpn = ((PathNode*)eed->v2->tmp.p); 
+                                               currpn = ((PathNode*)eed->v2->tmp.p);
                                                newpe = MEM_mallocN(sizeof(PathEdge), "Path Edge");
                                                newpe->v = ((PathNode*)eed->v1->tmp.p)->u;
                                                if(physical){
@@ -5968,28 +5963,28 @@ int select_vertex_path_exec(bContext *C, wmOperator *op)
                                        }
                                }
                        }
-                       
+
                        heap = BLI_heap_new();
                        cost = MEM_callocN(sizeof(float)*totnodes, "Path Select Costs");
                        previous = MEM_callocN(sizeof(int)*totnodes, "PathNode indices");
-                       
+
                        for(v=0; v < totnodes; v++){
                                cost[v] = 1000000;
                                previous[v] = -1; /*array of indices*/
                        }
-                       
+
                        pnindex = ((PathNode*)s->tmp.p)->u;
                        cost[pnindex] = 0;
                        BLI_heap_insert(heap,  0.0f, SET_INT_IN_POINTER(pnindex));
-                                               
+
                        while( !BLI_heap_empty(heap) ){
-                               
+
                                pnindex = GET_INT_FROM_POINTER(BLI_heap_popmin(heap));
                                currpn = &(Q[pnindex]);
-                               
+
                                if(currpn == (PathNode*)t->tmp.p) /*target has been reached....*/
                                        break;
-                               
+
                                for(currpe=currpn->edges.first; currpe; currpe=currpe->next){
                                        if(!Q[currpe->v].visited){
                                                if( cost[currpe->v] > (cost[currpn->u ] + currpe->w) ){
@@ -6001,7 +5996,7 @@ int select_vertex_path_exec(bContext *C, wmOperator *op)
                                        }
                                }
                        }
-                       
+
                        pathvert = ((PathNode*)t->tmp.p)->u;
                        while(pathvert != -1){
                                for(eve=em->verts.first; eve; eve=eve->next){
@@ -6011,7 +6006,7 @@ int select_vertex_path_exec(bContext *C, wmOperator *op)
                                }
                                pathvert = previous[pathvert];
                        }
-                       
+
                        for(v=0; v < totnodes; v++) BLI_freelistN(&(Q[v].edges));
                        MEM_freeN(Q);
                        MEM_freeN(cost);
@@ -6025,7 +6020,7 @@ int select_vertex_path_exec(bContext *C, wmOperator *op)
                BKE_report(op->reports, RPT_ERROR, "Path Selection requires that exactly two vertices be selected");
                return OPERATOR_CANCELLED;
        }
-       
+
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
        BKE_mesh_end_editmesh(obedit->data, em);
 
@@ -6042,12 +6037,12 @@ void MESH_OT_select_vertex_path(wmOperatorType *ot)
        /* identifiers */
        ot->name= "Select Vertex Path";
        ot->idname= "MESH_OT_select_vertex_path";
-       
+
        /* api callbacks */
        ot->exec= select_vertex_path_exec;
        ot->invoke= WM_menu_invoke;
        ot->poll= ED_operator_editmesh;
-       
+
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
@@ -6064,9 +6059,9 @@ static int region_to_loop(bContext *C, wmOperator *op)
        EditEdge *eed;
        EditFace *efa;
        int selected= 0;
-       
+
        for(eed=em->edges.first; eed; eed=eed->next) eed->f1 = 0;
-       
+
        for(efa=em->faces.first; efa; efa=efa->next){
                if(efa->f&SELECT){
                        efa->e1->f1++;
@@ -6081,20 +6076,20 @@ static int region_to_loop(bContext *C, wmOperator *op)
 
        if(!selected)
                return OPERATOR_CANCELLED;
-       
+
        EM_clear_flag_all(em, SELECT);
-       
+
        for(eed=em->edges.first; eed; eed=eed->next){
                if(eed->f1 == 1) EM_select_edge(eed, 1);
        }
-       
+
        em->selectmode = SCE_SELECT_EDGE;
        EM_selectmode_set(em);
-       
+
        BKE_mesh_end_editmesh(obedit->data, em);
 
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
-       
+
        return OPERATOR_FINISHED;
 }
 
@@ -6103,11 +6098,11 @@ void MESH_OT_region_to_loop(wmOperatorType *ot)
        /* identifiers */
        ot->name= "Region to Loop";
        ot->idname= "MESH_OT_region_to_loop";
-       
+
        /* api callbacks */
        ot->exec= region_to_loop;
        ot->poll= ED_operator_editmesh;
-       
+
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
@@ -6117,7 +6112,7 @@ static int validate_loop(EditMesh *em, Collection *edgecollection)
        EditEdge *eed;
        EditFace *efa;
        CollectedEdge *curredge;
-       
+
        /*1st test*/
        for(curredge = (CollectedEdge*)edgecollection->collectionbase.first; curredge; curredge=curredge->next){
                curredge->eed->v1->f1 = 0;
@@ -6131,7 +6126,7 @@ static int validate_loop(EditMesh *em, Collection *edgecollection)
                if(curredge->eed->v1->f1 > 2) return(0); else
                if(curredge->eed->v2->f1 > 2) return(0);
        }
-       
+
        /*2nd test*/
        for(eed = em->edges.first; eed; eed=eed->next) eed->f1 = 0;
        for(efa=em->faces.first; efa; efa=efa->next){
@@ -6147,20 +6142,20 @@ static int validate_loop(EditMesh *em, Collection *edgecollection)
 }
 
 static int loop_bisect(EditMesh *em, Collection *edgecollection){
-       
+
        EditFace *efa, *sf1, *sf2;
        EditEdge *eed, *sed;
        CollectedEdge *curredge;
        int totsf1, totsf2, unbalanced,balancededges;
-       
+
        for(eed=em->edges.first; eed; eed=eed->next) eed->f1 = eed->f2 = 0;
-       for(efa=em->faces.first; efa; efa=efa->next) efa->f1 = 0;       
-       
+       for(efa=em->faces.first; efa; efa=efa->next) efa->f1 = 0;
+
        for(curredge = (CollectedEdge*)edgecollection->collectionbase.first; curredge; curredge=curredge->next) curredge->eed->f1 = 1;
-       
+
        sf1 = sf2 = NULL;
        sed = ((CollectedEdge*)edgecollection->collectionbase.first)->eed;
-       
+
        for(efa=em->faces.first; efa; efa=efa->next){
                if(sf2) break;
                else if(sf1){
@@ -6170,24 +6165,24 @@ static int loop_bisect(EditMesh *em, Collection *edgecollection){
                        if(efa->e1 == sed || efa->e2 == sed || efa->e3 == sed || ( (efa->e4) ? efa->e4 == sed : 0) ) sf1 = efa;
                }
        }
-       
+
        if(sf1==NULL || sf2==NULL)
                return(-1);
-       
+
        if(!(sf1->e1->f1)) sf1->e1->f2 = 1;
        if(!(sf1->e2->f1)) sf1->e2->f2 = 1;
        if(!(sf1->e3->f1)) sf1->e3->f2 = 1;
        if(sf1->e4 && !(sf1->e4->f1)) sf1->e4->f2 = 1;
        sf1->f1 = 1;
        totsf1 = 1;
-       
+
        if(!(sf2->e1->f1)) sf2->e1->f2 = 2;
        if(!(sf2->e2->f1)) sf2->e2->f2 = 2;
        if(!(sf2->e3->f1)) sf2->e3->f2 = 2;
        if(sf2->e4 && !(sf2->e4->f1)) sf2->e4->f2 = 2;
        sf2->f1 = 2;
        totsf2 = 1;
-       
+
        /*do sf1*/
        unbalanced = 1;
        while(unbalanced){
@@ -6209,7 +6204,7 @@ static int loop_bisect(EditMesh *em, Collection *edgecollection){
                        }
                }
        }
-       
+
        /*do sf2*/
        unbalanced = 1;
        while(unbalanced){
@@ -6231,7 +6226,7 @@ static int loop_bisect(EditMesh *em, Collection *edgecollection){
                        }
                }
        }
-               
+
        if(totsf1 < totsf2) return(1);
        else return(2);
 }
@@ -6246,9 +6241,9 @@ static int loop_to_region(bContext *C, wmOperator *op)
        ListBase allcollections={NULL,NULL};
        Collection *edgecollection;
        int testflag;
-       
+
        build_edgecollection(em, &allcollections);
-       
+
        for(edgecollection = (Collection *)allcollections.first; edgecollection; edgecollection=edgecollection->next){
                if(validate_loop(em, edgecollection)){
                        testflag = loop_bisect(em, edgecollection);
@@ -6260,11 +6255,11 @@ static int loop_to_region(bContext *C, wmOperator *op)
                        }
                }
        }
-       
+
        for(efa=em->faces.first; efa; efa=efa->next){ /*fix this*/
                if(efa->f&SELECT) EM_select_face(efa,1);
        }