merge with 2.5 (not trunk, last merge message said that on accident) at r22252
[blender.git] / source / blender / editors / mesh / editmesh_add.c
index 54445f8715043d20116d976b79d766e79768cc85..ff0814661ebd84cb6a5cfff6434a16e01a6eca2b 100644 (file)
 #include "BKE_mesh.h"
 #include "BKE_object.h"
 #include "BKE_utildefines.h"
-
-#include "BIF_retopo.h"
+#include "BKE_report.h"
+#include "BKE_tessmesh.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
 
 #include "ED_mesh.h"
+#include "ED_retopo.h"
+#include "ED_screen.h"
+#include "ED_transform.h"
 #include "ED_util.h"
 #include "ED_view3d.h"
-#include "ED_screen.h"
+
+#include "bmesh.h"
 
 #include "mesh_intern.h"
 
 /* bpymenu removed XXX */
 
 /* XXX */
-static void BIF_undo_push() {}
-static void error() {}
-static int pupmenu() {return 0;}
 #define add_numbut(a, b, c, d, e, f, g) {}
 /* XXX */
 
 static float icovert[12][3] = {
-       {0,0,-200}, 
-       {144.72, -105.144,-89.443},
-       {-55.277, -170.128,-89.443}, 
-       {-178.885,0,-89.443},
-       {-55.277,170.128,-89.443}, 
-       {144.72,105.144,-89.443},
-       {55.277,-170.128,89.443},
-       {-144.72,-105.144,89.443},
-       {-144.72,105.144,89.443},
-       {55.277,170.128,89.443},
-       {178.885,0,89.443},
-       {0,0,200}
+       {0.0f,0.0f,-200.0f}, 
+       {144.72f, -105.144f,-89.443f},
+       {-55.277f, -170.128,-89.443f}, 
+       {-178.885f,0.0f,-89.443f},
+       {-55.277f,170.128f,-89.443f}, 
+       {144.72f,105.144f,-89.443f},
+       {55.277f,-170.128f,89.443f},
+       {-144.72f,-105.144f,89.443f},
+       {-144.72f,105.144f,89.443f},
+       {55.277f,170.128f,89.443f},
+       {178.885f,0.0f,89.443f},
+       {0.0f,0.0f,200.0f}
 };
 static short icoface[20][3] = {
        {1,0,2},
@@ -118,131 +119,11 @@ static short icoface[20][3] = {
        {10,9,11}
 };
 
-static void get_view_aligned_coordinate(ViewContext *vc, float *fp, short mval[2])
-{
-       float dvec[3];
-       short mx, my;
-       
-       mx= mval[0];
-       my= mval[1];
-       
-       project_short_noclip(vc->ar, fp, mval);
-       
-       initgrabz(vc->rv3d, fp[0], fp[1], fp[2]);
-       
-       if(mval[0]!=IS_CLIPPED) {
-               window_to_3d_delta(vc->ar, dvec, mval[0]-mx, mval[1]-my);
-               VecSubf(fp, fp, dvec);
-       }
-}
 
-void add_click_mesh(bContext *C)
-{
-       ViewContext vc;
-       EditVert *eve, *v1;
-       float min[3], max[3];
-       int done= 0;
-       
-       em_setup_viewcontext(C, &vc);
-       
-       INIT_MINMAX(min, max);
-       
-       for(v1= vc.em->verts.first;v1; v1=v1->next) {
-               if(v1->f & SELECT) {
-                       DO_MINMAX(v1->co, min, max);
-                       done= 1;
-               }
-       }
-
-       /* call extrude? */
-       if(done) {
-               EditEdge *eed;
-               float vec[3], cent[3], mat[3][3];
-               float nor[3]= {0.0, 0.0, 0.0};
-               short mval[2];
-               
-               /* check for edges that are half selected, use for rotation */
-               done= 0;
-               for(eed= vc.em->edges.first; eed; eed= eed->next) {
-                       if( (eed->v1->f & SELECT)+(eed->v2->f & SELECT) == SELECT ) {
-                               if(eed->v1->f & SELECT) VecSubf(vec, eed->v1->co, eed->v2->co);
-                               else VecSubf(vec, eed->v2->co, eed->v1->co);
-                               VecAddf(nor, nor, vec);
-                               done= 1;
-                       }
-               }
-               if(done) Normalize(nor);
-               
-               /* center */
-               VecAddf(cent, min, max);
-               VecMulf(cent, 0.5f);
-               VECCOPY(min, cent);
-               
-               Mat4MulVecfl(vc.obedit->obmat, min);    // view space
-               get_view_aligned_coordinate(&vc, min, mval);
-               Mat4Invert(vc.obedit->imat, vc.obedit->obmat); 
-               Mat4MulVecfl(vc.obedit->imat, min); // back in object space
-               
-               VecSubf(min, min, cent);
-               
-               /* calculate rotation */
-               Mat3One(mat);
-               if(done) {
-                       float dot;
-                       
-                       VECCOPY(vec, min);
-                       Normalize(vec);
-                       dot= INPR(vec, nor);
-
-                       if( fabs(dot)<0.999) {
-                               float cross[3], si, q1[4];
-                               
-                               Crossf(cross, nor, vec);
-                               Normalize(cross);
-                               dot= 0.5f*saacos(dot);
-                               si= (float)sin(dot);
-                               q1[0]= (float)cos(dot);
-                               q1[1]= cross[0]*si;
-                               q1[2]= cross[1]*si;
-                               q1[3]= cross[2]*si;
-                               
-                               QuatToMat3(q1, mat);
-                       }
-               }
-               
-               extrudeflag(vc.obedit, vc.em, SELECT, nor);
-               rotateflag(vc.em, SELECT, cent, mat);
-               translateflag(vc.em, SELECT, min);
-               
-               recalc_editnormals(vc.em);
-       }
-       else {
-               float mat[3][3],imat[3][3];
-               float *curs= give_cursor(vc.scene, vc.v3d);
-               
-               eve= addvertlist(vc.em, 0, NULL);
-
-               Mat3CpyMat4(mat, vc.obedit->obmat);
-               Mat3Inv(imat, mat);
-               
-               VECCOPY(eve->co, curs);
-               VecSubf(eve->co, eve->co, vc.obedit->obmat[3]);
-
-               Mat3MulVecfl(imat, eve->co);
-               
-               eve->f= SELECT;
-       }
-       
-       //retopo_do_all();
-       
-       BIF_undo_push("Add vertex/edge/face");
-       DAG_object_flush_update(vc.scene, vc.obedit, OB_RECALC_DATA);   
-       
-
-}
+/* ********************** */
 
 /* selected faces get hidden edges */
-static void make_fgon(EditMesh *em, int make)
+int make_fgon(EditMesh *em, wmOperator *op, int make)
 {
        EditFace *efa;
        EditEdge *eed;
@@ -250,7 +131,7 @@ static void make_fgon(EditMesh *em, int make)
        float *nor=NULL;        // reference
        int done=0;
        
-       if(!make) {
+       if(make==0) {
                for(efa= em->faces.first; efa; efa= efa->next) {
                        if(efa->f & SELECT) {
                                efa->fgonf= 0;
@@ -258,12 +139,12 @@ static void make_fgon(EditMesh *em, int make)
                                efa->e2->h &= ~EM_FGON;
                                efa->e3->h &= ~EM_FGON;
                                if(efa->e4) efa->e4->h &= ~EM_FGON;
+                               done= 1;
                        }
                }
                EM_fgon_flags(em);      // redo flags and indices for fgons
-// XXX         DAG_object_flush_update(scene, obedit, OB_RECALC_DATA); 
-               BIF_undo_push("Clear FGon");
-               return;
+               
+               return done;
        }
 
        /* tagging edges. rule is:
@@ -314,14 +195,14 @@ static void make_fgon(EditMesh *em, int make)
                if(eve->f1==1) break;
        }
        if(eve) {
-               error("Cannot make polygon with interior vertices");
-               return;
+               BKE_report(op->reports, RPT_ERROR, "Cannot make a polygon with interior vertices");
+               return 0;
        }
        
        // check for faces
        if(nor==NULL) {
-               error("No faces selected to make FGon");
-               return;
+               BKE_report(op->reports, RPT_ERROR, "No faces were selected to make FGon");
+               return 0;
        }
 
        // and there we go
@@ -332,15 +213,73 @@ static void make_fgon(EditMesh *em, int make)
                }
        }
        
-       if(done==0) {
-               error("Didn't find FGon to create");
-       }
-       else {
+       if(done)
                EM_fgon_flags(em);      // redo flags and indices for fgons
+       return done;
+}
+
+static int make_fgon_exec(bContext *C, wmOperator *op)
+{
+       Object *obedit= CTX_data_edit_object(C);
+       EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
+
+       if( make_fgon(em, op, 1) ) {
+               DAG_object_flush_update(CTX_data_scene(C), 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;
+       }
+
+       BKE_mesh_end_editmesh(obedit->data, em);
+       return OPERATOR_CANCELLED;
+}
+
+void MESH_OT_fgon_make(struct wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Make F-gon";
+       ot->idname= "MESH_OT_fgon_make";
+       
+       /* api callbacks */
+       ot->exec= make_fgon_exec;
+       ot->poll= ED_operator_editmesh;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
 
-// XXX         DAG_object_flush_update(scene, obedit, OB_RECALC_DATA); 
-               BIF_undo_push("Make FGon");
+static int clear_fgon_exec(bContext *C, wmOperator *op)
+{
+       Object *obedit= CTX_data_edit_object(C);
+       EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
+       
+       if( make_fgon(em, op, 0) ) {
+               DAG_object_flush_update(CTX_data_scene(C), 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;
        }
+
+       BKE_mesh_end_editmesh(obedit->data, em);
+       return OPERATOR_CANCELLED;
+}
+
+void MESH_OT_fgon_clear(struct wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Clear F-gon";
+       ot->idname= "MESH_OT_fgon_clear";
+       
+       /* api callbacks */
+       ot->exec= clear_fgon_exec;
+       ot->poll= ED_operator_editmesh;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
 /* precondition; 4 vertices selected, check for 4 edges and create face */
@@ -389,6 +328,8 @@ static EditFace *addface_from_edges(EditMesh *em)
        return NULL;
 }
 
+/* ******************************* */
+
 /* this also allows to prevent triangles being made in quads */
 static int compareface_overlaps(EditFace *vl1, EditFace *vl2)
 {
@@ -604,16 +545,56 @@ void addfaces_from_edgenet(EditMesh *em)
 
        EM_select_flush(em);
        
-       BIF_undo_push("Add faces");
 // XXX DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
 }
 
-void addedgeface_mesh(EditMesh *em)
+static void addedgeface_mesh(Mesh *me, BMEditMesh *bem, wmOperator *op)
 {
+       EditMesh *em;
        EditVert *eve, *neweve[4];
        EditEdge *eed;
        EditFace *efa;
        short amount=0;
+       
+       /*return if bmesh vert connect does anything.*/
+       if (bem->selectmode & SCE_SELECT_VERTEX) {
+               BMesh *bm = bem->bm;
+               BMOperator bmop;
+               int len, ok;
+               
+               EDBM_InitOpf(bem, &bmop, op, "connectverts verts=%hv", BM_SELECT);
+               BMO_Exec_Op(bem->bm, &bmop);
+
+               len = BMO_GetSlot(&bmop, "edgeout")->len;               
+
+               ok = EDBM_FinishOp(bem, &bmop, op, 1);
+               if (!ok) return OPERATOR_CANCELLED;
+
+               if (len) return;        
+       }
+
+       /*return if bmesh face dissolve finds stuff to
+         dissolve.  this entire tool should be
+         bmeshafied eventually, but until then
+         hacks like this to integrate with it
+         are necassary.*/
+       if (bem->selectmode & SCE_SELECT_VERTEX) {
+               BMesh *bm = bem->bm;
+               BMOperator bmop;
+               int len, ok;
+               
+               EDBM_InitOpf(bem, &bmop, op, "dissolvefaces faces=%hf", BM_SELECT);
+               BMO_Exec_Op(bem->bm, &bmop);
+
+               len = BMO_GetSlot(&bmop, "regionout")->len;             
+               
+               ok = EDBM_FinishOp(bem, &bmop, op, 1);
+               if (!ok) return OPERATOR_CANCELLED;
+
+               if (len) return;        
+       }
+
+       em = BKE_mesh_get_editmesh(me);
 
        /* how many selected ? */
        if(em->selectmode & SCE_SELECT_EDGE) {
@@ -633,29 +614,19 @@ void addedgeface_mesh(EditMesh *em)
        if(amount==2) {
                eed= addedgelist(em, neweve[0], neweve[1], NULL);
                EM_select_edge(eed, 1);
-               BIF_undo_push("Add edge");
-
+               
+               BKE_mesh_end_editmesh(me, em);
                // XXX          DAG_object_flush_update(scene, obedit, OB_RECALC_DATA); 
                return;
        }
        else if(amount > 4) {
-               
-               /* Python Menu removed XXX */
-               int ret;
-               
-               /* facemenu, will add python items */
-               char facemenu[4096]= "Make Faces%t|Auto%x1|Make FGon%x2|Clear FGon%x3";
-               
-               ret= pupmenu(facemenu);
-               
-               if(ret==1) addfaces_from_edgenet(em);
-               else if(ret==2) make_fgon(em, 1);
-               else if(ret==3) make_fgon(em, 0);
-               
+               addfaces_from_edgenet(em);
+               BKE_mesh_end_editmesh(me, em);
                return;
        }
        else if(amount<2) {
-               error("Incorrect number of vertices to make edge/face");
+               BKE_report(op->reports, RPT_ERROR, "More vertices are needed to make an edge/face");
+               BKE_mesh_end_editmesh(me, em);
                return;
        }
 
@@ -667,7 +638,7 @@ void addedgeface_mesh(EditMesh *em)
                        efa= addfacelist(em, neweve[0], neweve[1], neweve[2], 0, NULL, NULL);
                        EM_select_face(efa, 1);
                }
-               else error("The selected vertices already form a face");
+               else BKE_report(op->reports, RPT_ERROR, "The selected vertices already form a face");
        }
        else if(amount==4) {
                /* this test survives when theres 2 triangles */
@@ -694,6 +665,7 @@ void addedgeface_mesh(EditMesh *em)
                                
                                if(count++ > 4){
                                        addfaces_from_edgenet(em);
+                                       BKE_mesh_end_editmesh(me, em);
                                        return;
                                } else {
                                /* if 4 edges exist, we just create the face, convex or not */
@@ -723,9 +695,9 @@ void addedgeface_mesh(EditMesh *em)
                                        }
                                }
                        }
-                       else error("The selected vertices already form a face");
+                       else BKE_report(op->reports, RPT_ERROR, "The selected vertices already form a face");
                }
-               else error("The selected vertices already form a face");
+               else BKE_report(op->reports, RPT_ERROR, "The selected vertices already form a face");
        }
        
        if(efa) {
@@ -734,12 +706,12 @@ void addedgeface_mesh(EditMesh *em)
                fix_new_face(em, efa);
                
                recalc_editnormals(em);
-               BIF_undo_push("Add face");
        }
-       
-// XXX DAG_object_flush_update(scene, obedit, OB_RECALC_DATA); 
+
+       BKE_mesh_end_editmesh(me, em);
 }
 
+/* ************************ primitives ******************* */
 
 // HACK: these can also be found in cmoview.tga.c, but are here so that they can be found by linker
 // this hack is only used so that scons+mingw + split-sources hack works
@@ -908,7 +880,7 @@ static void make_prim(Object *obedit, int type, float mat[4][4], int tot, int se
         * fill - end capping, and option to fill in circle
         * cent[3] - center of the data. 
         * */
-       EditMesh *em= ((Mesh *)obedit->data)->edit_mesh;
+       EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
        EditVert *eve, *v1=NULL, *v2, *v3, *v4=NULL, *vtop, *vdown;
        float phi, phid, vec[3];
        float q[4], cmat[3][3], nor[3]= {0.0, 0.0, 0.0};
@@ -916,8 +888,8 @@ static void make_prim(Object *obedit, int type, float mat[4][4], int tot, int se
        
        EM_clear_flag_all(em, SELECT);
 
-       phid= 2*M_PI/tot;
-       phi= .25*M_PI;
+       phid= 2.0f*(float)M_PI/tot;
+       phi= .25f*(float)M_PI;
 
        switch(type) {
        case PRIM_GRID: /*  grid */
@@ -1029,7 +1001,9 @@ static void make_prim(Object *obedit, int type, float mat[4][4], int tot, int se
                        }
 
                        dia*=200;
-                       for(a=1; a<subdiv; a++) esubdivideflag(obedit, em, 2, dia, 0,1,0);
+
+                       for(a=1; a<subdiv; a++) esubdivideflag(obedit, em, 2, dia, 0.0, 0, 1, 0);
+                       
                        /* and now do imat */
                        eve= em->verts.first;
                        while(eve) {
@@ -1189,6 +1163,8 @@ static void make_prim(Object *obedit, int type, float mat[4][4], int tot, int se
        
        if(type!=0 && type!=13)
                righthandfaces(em, 1);  /* otherwise monkey has eyes in wrong direction */
+
+       BKE_mesh_end_editmesh(obedit->data, em);
 }
 
 
@@ -1199,14 +1175,14 @@ static float new_primitive_matrix(bContext *C, float primmat[][4])
        Object *obedit= CTX_data_edit_object(C);
        Scene *scene = CTX_data_scene(C);
        View3D *v3d =CTX_wm_view3d(C);
-       ARegion *ar= CTX_wm_region(C);
+       RegionView3D *rv3d= ED_view3d_context_rv3d(C);
        float *curs, mat[3][3], vmat[3][3], cmat[3][3], imat[3][3];
        
        Mat4One(primmat);
        
-       if(ar)
-               Mat3CpyMat4(vmat, ((RegionView3D *)ar->regiondata)->viewmat);
-       else
+       if(rv3d && (U.flag & USER_ADD_VIEWALIGNED)) {
+               Mat3CpyMat4(vmat, rv3d->viewmat);
+       else
                Mat3One(vmat);
        
        /* inverse transform for view and object */
@@ -1218,9 +1194,9 @@ static float new_primitive_matrix(bContext *C, float primmat[][4])
        /* center */
        curs= give_cursor(scene, v3d);
        VECCOPY(primmat[3], curs);
+       VECSUB(primmat[3], primmat[3], obedit->obmat[3]);
        Mat3Inv(imat, mat);
        Mat3MulVecfl(imat, primmat[3]);
-       VECSUB(primmat[3], primmat[3], obedit->obmat[3]);
        
        if(v3d) return v3d->grid;
        return 1.0f;
@@ -1230,6 +1206,7 @@ static float new_primitive_matrix(bContext *C, float primmat[][4])
 
 static int add_primitive_plane_exec(bContext *C, wmOperator *op)
 {
+       Scene *scene= CTX_data_scene(C);
        Object *obedit= CTX_data_edit_object(C);
        float dia, mat[4][4];
        
@@ -1239,28 +1216,29 @@ static int add_primitive_plane_exec(bContext *C, wmOperator *op)
        
        make_prim(obedit, PRIM_PLANE, mat, 4, 0, 0, dia, 0.0f, 0, 1);
        
-       ED_undo_push(C, "Add Plane");   // Note this will become depricated 
+       DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
        
        return OPERATOR_FINISHED;       
 }
 
-void MESH_OT_add_primitive_plane(wmOperatorType *ot)
+void MESH_OT_primitive_plane_add(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Add Plane";
-       ot->idname= "MESH_OT_add_primitive_plane";
+       ot->idname= "MESH_OT_primitive_plane_add";
        
        /* api callbacks */
        ot->exec= add_primitive_plane_exec;
        ot->poll= ED_operator_editmesh;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER;
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
 static int add_primitive_cube_exec(bContext *C, wmOperator *op)
 {
+       Scene *scene = CTX_data_scene(C);
        Object *obedit= CTX_data_edit_object(C);
        float dia, mat[4][4];
        
@@ -1270,28 +1248,29 @@ static int add_primitive_cube_exec(bContext *C, wmOperator *op)
        
        make_prim(obedit, PRIM_CUBE, mat, 4, 0, 0, dia, 1.0f, 1, 1);
        
-       ED_undo_push(C, "Add Cube");    // Note this will become depricated 
+       DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
        
        return OPERATOR_FINISHED;       
 }
 
-void MESH_OT_add_primitive_cube(wmOperatorType *ot)
+void MESH_OT_primitive_cube_add(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Add Cube";
-       ot->idname= "MESH_OT_add_primitive_cube";
+       ot->idname= "MESH_OT_primitive_cube_add";
        
        /* api callbacks */
        ot->exec= add_primitive_cube_exec;
        ot->poll= ED_operator_editmesh;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER;
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
 static int add_primitive_circle_exec(bContext *C, wmOperator *op)
 {
+       Scene *scene = CTX_data_scene(C);
        Object *obedit= CTX_data_edit_object(C);
        float dia, mat[4][4];
        
@@ -1301,24 +1280,24 @@ static int add_primitive_circle_exec(bContext *C, wmOperator *op)
        make_prim(obedit, PRIM_CIRCLE, mat, RNA_int_get(op->ptr, "vertices"), 0, 0, dia, 0.0f, 0, 
                          RNA_boolean_get(op->ptr, "fill"));
        
-       ED_undo_push(C, "Add Circle");  // Note this will become depricated 
+       DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
        
        return OPERATOR_FINISHED;       
 }
 
-void MESH_OT_add_primitive_circle(wmOperatorType *ot)
+void MESH_OT_primitive_circle_add(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Add Circle";
-       ot->idname= "MESH_OT_add_primitive_circle";
+       ot->idname= "MESH_OT_primitive_circle_add";
        
        /* api callbacks */
        ot->exec= add_primitive_circle_exec;
        ot->poll= ED_operator_editmesh;
-
+       
        /* flags */
-       ot->flag= OPTYPE_REGISTER/*|OPTYPE_UNDO*/;
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* props */
        RNA_def_int(ot->srna, "vertices", 32, INT_MIN, INT_MAX, "Vertices", "", 3, 500);
@@ -1328,6 +1307,7 @@ void MESH_OT_add_primitive_circle(wmOperatorType *ot)
 
 static int add_primitive_cylinder_exec(bContext *C, wmOperator *op)
 {
+       Scene *scene = CTX_data_scene(C);
        Object *obedit= CTX_data_edit_object(C);
        float dia, mat[4][4];
        
@@ -1337,24 +1317,24 @@ static int add_primitive_cylinder_exec(bContext *C, wmOperator *op)
        make_prim(obedit, PRIM_CYLINDER, mat, RNA_int_get(op->ptr, "vertices"), 0, 0, dia, 
                          RNA_float_get(op->ptr, "depth"), 1, 1);
        
-       ED_undo_push(C, "Add Cylinder");        // Note this will become depricated 
+       DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
        
        return OPERATOR_FINISHED;       
 }
 
-void MESH_OT_add_primitive_cylinder(wmOperatorType *ot)
+void MESH_OT_primitive_cylinder_add(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Add Cylinder";
-       ot->idname= "MESH_OT_add_primitive_cylinder";
+       ot->idname= "MESH_OT_primitive_cylinder_add";
        
        /* api callbacks */
        ot->exec= add_primitive_cylinder_exec;
        ot->poll= ED_operator_editmesh;
-
+       
        /* flags */
-       ot->flag= OPTYPE_REGISTER/*|OPTYPE_UNDO*/;
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* props */
        RNA_def_int(ot->srna, "vertices", 32, INT_MIN, INT_MAX, "Vertices", "", 2, 500);
@@ -1364,6 +1344,7 @@ void MESH_OT_add_primitive_cylinder(wmOperatorType *ot)
 
 static int add_primitive_tube_exec(bContext *C, wmOperator *op)
 {
+       Scene *scene = CTX_data_scene(C);
        Object *obedit= CTX_data_edit_object(C);
        float dia, mat[4][4];
        
@@ -1373,24 +1354,24 @@ static int add_primitive_tube_exec(bContext *C, wmOperator *op)
        make_prim(obedit, PRIM_CYLINDER, mat, RNA_int_get(op->ptr, "vertices"), 0, 0, dia, 
                          RNA_float_get(op->ptr, "depth"), 1, 0);
        
-       ED_undo_push(C, "Add Tube");    // Note this will become depricated 
+       DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
        
        return OPERATOR_FINISHED;       
 }
 
-void MESH_OT_add_primitive_tube(wmOperatorType *ot)
+void MESH_OT_primitive_tube_add(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Add Tube";
-       ot->idname= "MESH_OT_add_primitive_tube";
+       ot->idname= "MESH_OT_primitive_tube_add";
        
        /* api callbacks */
        ot->exec= add_primitive_tube_exec;
        ot->poll= ED_operator_editmesh;
-
+       
        /* flags */
-       ot->flag= OPTYPE_REGISTER/*|OPTYPE_UNDO*/;
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* props */
        RNA_def_int(ot->srna, "vertices", 32, INT_MIN, INT_MAX, "Vertices", "", 2, 500);
@@ -1400,6 +1381,7 @@ void MESH_OT_add_primitive_tube(wmOperatorType *ot)
 
 static int add_primitive_cone_exec(bContext *C, wmOperator *op)
 {
+       Scene *scene = CTX_data_scene(C);
        Object *obedit= CTX_data_edit_object(C);
        float dia, mat[4][4];
        
@@ -1409,24 +1391,24 @@ static int add_primitive_cone_exec(bContext *C, wmOperator *op)
        make_prim(obedit, PRIM_CONE, mat, RNA_int_get(op->ptr, "vertices"), 0, 0, dia, 
                          RNA_float_get(op->ptr, "depth"), 0, RNA_boolean_get(op->ptr, "cap_end"));
        
-       ED_undo_push(C, "Add Cone");    // Note this will become depricated 
+       DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
        
        return OPERATOR_FINISHED;       
 }
 
-void MESH_OT_add_primitive_cone(wmOperatorType *ot)
+void MESH_OT_primitive_cone_add(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Add Cone";
-       ot->idname= "MESH_OT_add_primitive_cone";
+       ot->idname= "MESH_OT_primitive_cone_add";
        
        /* api callbacks */
        ot->exec= add_primitive_cone_exec;
        ot->poll= ED_operator_editmesh;
-
+       
        /* flags */
-       ot->flag= OPTYPE_REGISTER/*|OPTYPE_UNDO*/;
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* props */
        RNA_def_int(ot->srna, "vertices", 32, INT_MIN, INT_MAX, "Vertices", "", 2, 500);
@@ -1438,6 +1420,7 @@ void MESH_OT_add_primitive_cone(wmOperatorType *ot)
 
 static int add_primitive_grid_exec(bContext *C, wmOperator *op)
 {
+       Scene *scene = CTX_data_scene(C);
        Object *obedit= CTX_data_edit_object(C);
        float dia, mat[4][4];
        
@@ -1447,24 +1430,24 @@ static int add_primitive_grid_exec(bContext *C, wmOperator *op)
        make_prim(obedit, PRIM_GRID, mat, RNA_int_get(op->ptr, "x_subdivisions"), 
                          RNA_int_get(op->ptr, "y_subdivisions"), 0, dia, 0.0f, 0, 1);
        
-       ED_undo_push(C, "Add Grid");    // Note this will become depricated 
+       DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
        
        return OPERATOR_FINISHED;       
 }
 
-void MESH_OT_add_primitive_grid(wmOperatorType *ot)
+void MESH_OT_primitive_grid_add(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Add Grid";
-       ot->idname= "MESH_OT_add_primitive_grid";
+       ot->idname= "MESH_OT_primitive_grid_add";
        
        /* api callbacks */
        ot->exec= add_primitive_grid_exec;
        ot->poll= ED_operator_editmesh;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER;
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* props */
        RNA_def_int(ot->srna, "x_subdivisions", 10, INT_MIN, INT_MAX, "X Subdivisions", "", 3, 1000);
@@ -1474,6 +1457,7 @@ void MESH_OT_add_primitive_grid(wmOperatorType *ot)
 
 static int add_primitive_monkey_exec(bContext *C, wmOperator *op)
 {
+       Scene *scene = CTX_data_scene(C);
        Object *obedit= CTX_data_edit_object(C);
        float mat[4][4];
        
@@ -1481,28 +1465,29 @@ static int add_primitive_monkey_exec(bContext *C, wmOperator *op)
        
        make_prim(obedit, PRIM_MONKEY, mat, 0, 0, 2, 0.0f, 0.0f, 0, 0);
        
-       ED_undo_push(C, "Add Monkey");  // Note this will become depricated 
+       DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
        
        return OPERATOR_FINISHED;       
 }
 
-void MESH_OT_add_primitive_monkey(wmOperatorType *ot)
+void MESH_OT_primitive_monkey_add(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Add Monkey";
-       ot->idname= "MESH_OT_add_primitive_monkey";
+       ot->idname= "MESH_OT_primitive_monkey_add";
        
        /* api callbacks */
        ot->exec= add_primitive_monkey_exec;
        ot->poll= ED_operator_editmesh;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER;
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
 static int add_primitive_uvsphere_exec(bContext *C, wmOperator *op)
 {
+       Scene *scene = CTX_data_scene(C);
        Object *obedit= CTX_data_edit_object(C);
        float dia, mat[4][4];
        
@@ -1512,23 +1497,24 @@ static int add_primitive_uvsphere_exec(bContext *C, wmOperator *op)
        make_prim(obedit, PRIM_UVSPHERE, mat, RNA_int_get(op->ptr, "rings"), 
                          RNA_int_get(op->ptr, "segments"), 0, dia, 0.0f, 0, 0);
        
+       DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
        
        return OPERATOR_FINISHED;       
 }
 
-void MESH_OT_add_primitive_uv_sphere(wmOperatorType *ot)
+void MESH_OT_primitive_uv_sphere_add(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Add UV Sphere";
-       ot->idname= "MESH_OT_add_primitive_uv_sphere";
+       ot->idname= "MESH_OT_primitive_uv_sphere_add";
        
        /* api callbacks */
        ot->exec= add_primitive_uvsphere_exec;
        ot->poll= ED_operator_editmesh;
-
+       
        /* flags */
-       ot->flag= OPTYPE_REGISTER;
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* props */
        RNA_def_int(ot->srna, "segments", 32, INT_MIN, INT_MAX, "Segments", "", 3, 500);
@@ -1538,6 +1524,7 @@ void MESH_OT_add_primitive_uv_sphere(wmOperatorType *ot)
 
 static int add_primitive_icosphere_exec(bContext *C, wmOperator *op)
 {
+       Scene *scene = CTX_data_scene(C);
        Object *obedit= CTX_data_edit_object(C);
        float dia, mat[4][4];
        
@@ -1547,26 +1534,26 @@ static int add_primitive_icosphere_exec(bContext *C, wmOperator *op)
        make_prim(obedit, PRIM_ICOSPHERE, mat, 0, 0, 
                          RNA_int_get(op->ptr, "subdivisions"), dia, 0.0f, 0, 0);
        
+       DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
        
        return OPERATOR_FINISHED;       
 }
 
-void MESH_OT_add_primitive_ico_sphere(wmOperatorType *ot)
+void MESH_OT_primitive_ico_sphere_add(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Add Ico Sphere";
-       ot->idname= "MESH_OT_add_primitive_ico_sphere";
+       ot->idname= "MESH_OT_primitive_ico_sphere_add";
        
        /* api callbacks */
        ot->exec= add_primitive_icosphere_exec;
        ot->poll= ED_operator_editmesh;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER;
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* props */
        RNA_def_int(ot->srna, "subdivisions", 2, 0, 6, "Subdivisions", "", 0, 8);
        RNA_def_float(ot->srna, "size", 1.0f, 0.0f, FLT_MAX, "Size", "", 0.001f, 100.00);
 }
-