Bugfix #25636
[blender.git] / source / blender / editors / mesh / editmesh_add.c
index 7b23b556994c52a18ce2142236cfa68e0d336283..d9db1e99bfa68d2f5167be467b6e4f72b2b8f1e8 100644 (file)
@@ -44,6 +44,7 @@
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
 #include "BLI_editVert.h"
+#include "BLI_utildefines.h"
 
 #include "BKE_context.h"
 #include "BKE_depsgraph.h"
@@ -116,10 +117,6 @@ static int dupli_extrude_cursor(bContext *C, wmOperator *op, wmEvent *event)
        short use_proj;
 
        em_setup_viewcontext(C, &vc);
-       wmWindow *win= CTX_wm_window(C);
-
-       printf("\n%d %d\n", event->x, event->y);
-       printf("%d %d\n", win->eventstate->x, win->eventstate->y);
 
        use_proj= (vc.scene->toolsettings->snap_flag & SCE_SNAP) &&     (vc.scene->toolsettings->snap_mode==SCE_SNAP_MODE_FACE);
        
@@ -142,8 +139,11 @@ static int dupli_extrude_cursor(bContext *C, wmOperator *op, wmEvent *event)
                float nor[3]= {0.0, 0.0, 0.0};
                
                /* 2D normal calc */
-               float mval_f[2]= {(float)event->mval[0], (float)event->mval[1]};
-               
+               float mval_f[2];
+
+               mval_f[0]= (float)event->mval[0];
+               mval_f[1]= (float)event->mval[1];
+
                done= 0;
 
                /* calculate the normal for selected edges */
@@ -238,7 +238,8 @@ static int dupli_extrude_cursor(bContext *C, wmOperator *op, wmEvent *event)
                
                recalc_editnormals(vc.em);
        }
-       else {
+       else if(vc.em->selectmode & SCE_SELECT_VERTEX) {
+
                float mat[3][3],imat[3][3];
                float *curs= give_cursor(vc.scene, vc.v3d);
                
@@ -261,7 +262,7 @@ static int dupli_extrude_cursor(bContext *C, wmOperator *op, wmEvent *event)
                EM_project_snap_verts(C, vc.ar, vc.obedit, vc.em);
 
        WM_event_add_notifier(C, NC_GEOM|ND_DATA, vc.obedit->data); 
-       DAG_id_flush_update(vc.obedit->data, OB_RECALC_DATA);
+       DAG_id_tag_update(vc.obedit->data, 0);
        
        return OPERATOR_FINISHED;
 }
@@ -359,13 +360,13 @@ int make_fgon(EditMesh *em, wmOperator *op, int make)
                if(eve->f1==1) break;
        }
        if(eve) {
-               BKE_report(op->reports, RPT_ERROR, "Cannot make a polygon with interior vertices");
+               BKE_report(op->reports, RPT_WARNING, "Cannot make a polygon with interior vertices");
                return 0;
        }
        
        // check for faces
        if(nor==NULL) {
-               BKE_report(op->reports, RPT_ERROR, "No faces were selected to make FGon");
+               BKE_report(op->reports, RPT_WARNING, "No faces were selected to make FGon");
                return 0;
        }
 
@@ -388,7 +389,7 @@ static int make_fgon_exec(bContext *C, wmOperator *op)
        EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
 
        if( make_fgon(em, op, 1) ) {
-               DAG_id_flush_update(obedit->data, OB_RECALC_DATA);      
+               DAG_id_tag_update(obedit->data, 0);
                WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
 
                BKE_mesh_end_editmesh(obedit->data, em);
@@ -420,7 +421,7 @@ static int clear_fgon_exec(bContext *C, wmOperator *op)
        EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
        
        if( make_fgon(em, op, 0) ) {
-               DAG_id_flush_update(obedit->data, OB_RECALC_DATA);      
+               DAG_id_tag_update(obedit->data, 0);
                WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
                
                BKE_mesh_end_editmesh(obedit->data, em);
@@ -709,7 +710,7 @@ void addfaces_from_edgenet(EditMesh *em)
 
        EM_select_flush(em);
        
-// XXX DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
+// XXX DAG_id_tag_update(obedit->data, 0);
 }
 
 static void addedgeface_mesh(EditMesh *em, wmOperator *op)
@@ -738,7 +739,7 @@ static void addedgeface_mesh(EditMesh *em, wmOperator *op)
                eed= addedgelist(em, neweve[0], neweve[1], NULL);
                EM_select_edge(eed, 1);
 
-               // XXX          DAG_id_flush_update(obedit->data, OB_RECALC_DATA);      
+               // XXX          DAG_id_tag_update(obedit->data, 0);
                return;
        }
        else if(amount > 4) {
@@ -746,7 +747,7 @@ static void addedgeface_mesh(EditMesh *em, wmOperator *op)
                return;
        }
        else if(amount<2) {
-               BKE_report(op->reports, RPT_ERROR, "More vertices are needed to make an edge/face");
+               BKE_report(op->reports, RPT_WARNING, "More vertices are needed to make an edge/face");
                return;
        }
 
@@ -758,7 +759,7 @@ static void addedgeface_mesh(EditMesh *em, wmOperator *op)
                        efa= addfacelist(em, neweve[0], neweve[1], neweve[2], 0, NULL, NULL);
                        EM_select_face(efa, 1);
                }
-               else BKE_report(op->reports, RPT_ERROR, "The selected vertices already form a face");
+               else BKE_report(op->reports, RPT_WARNING, "The selected vertices already form a face");
        }
        else if(amount==4) {
                /* this test survives when theres 2 triangles */
@@ -810,14 +811,14 @@ static void addedgeface_mesh(EditMesh *em, wmOperator *op)
                                                else if( convex(neweve[0]->co, neweve[3]->co, neweve[1]->co, neweve[2]->co) ) {
                                                        efa= addfacelist(em, neweve[0], neweve[3], neweve[1], neweve[2], NULL, NULL);
                                                }
-                                               else BKE_report(op->reports, RPT_ERROR, "cannot find nice quad from concave set of vertices");
+                                               else BKE_report(op->reports, RPT_WARNING, "cannot find nice quad from concave set of vertices");
 
                                        }
                                }
                        }
-                       else BKE_report(op->reports, RPT_ERROR, "The selected vertices already form a face");
+                       else BKE_report(op->reports, RPT_WARNING, "The selected vertices already form a face");
                }
-               else BKE_report(op->reports, RPT_ERROR, "The selected vertices already form a face");
+               else BKE_report(op->reports, RPT_WARNING, "The selected vertices already form a face");
        }
        
        if(efa) {
@@ -836,7 +837,7 @@ static int addedgeface_mesh_exec(bContext *C, wmOperator *op)
        
        addedgeface_mesh(em, op);
        
-       DAG_id_flush_update(obedit->data, OB_RECALC_DATA);      
+       DAG_id_tag_update(obedit->data, 0);
        WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
        
        BKE_mesh_end_editmesh(obedit->data, em);
@@ -1053,15 +1054,13 @@ static void make_prim(Object *obedit, int type, float mat[4][4], int tot, int se
                /* one segment first: the X axis */             
                phi = (2*dia)/(float)(tot-1);
                phid = (2*dia)/(float)(seg-1);
-               for(a=0;a<tot;a++) {
+               for(a=tot-1;a>=0;a--) {
                        vec[0] = (phi*a) - dia;
                        vec[1]= - dia;
                        vec[2]= 0.0f;
                        eve= addvertlist(em, vec, NULL);
                        eve->f= 1+2+4;
-                       if (a) {
-                               addedgelist(em, eve->prev, eve, NULL);
-                       }
+                       if(a < tot -1) addedgelist(em, eve->prev, eve, NULL);
                }
                /* extrude and translate */
                vec[0]= vec[2]= 0.0;
@@ -1071,7 +1070,17 @@ static void make_prim(Object *obedit, int type, float mat[4][4], int tot, int se
                        extrudeflag_vert(obedit, em, 2, nor, 0);        // nor unused
                        translateflag(em, 2, vec);
                }
+                       
+               /* and now do imat */
+               eve= em->verts.first;
+               while(eve) {
+                       if(eve->f & SELECT) {
+                               mul_m4_v3(mat,eve->co);
+                       }
+                       eve= eve->next;
+               }
                break;
+                       
        case PRIM_UVSPHERE: /*  UVsphere */
                
                /* clear all flags */
@@ -1204,7 +1213,10 @@ static void make_prim(Object *obedit, int type, float mat[4][4], int tot, int se
                else if(ext==0) 
                        depth= 0.0f;
        
-               /* vertices */
+               /* first vertex at 0° for circular objects */
+               if( ELEM3(type, PRIM_CIRCLE,PRIM_CYLINDER,PRIM_CONE) )
+                       phi = 0.0f;
+                       
                vtop= vdown= v1= v2= 0;
                for(b=0; b<=ext; b++) {
                        for(a=0; a<tot; a++) {
@@ -1315,7 +1327,7 @@ static void make_prim(Object *obedit, int type, float mat[4][4], int tot, int se
 
 /* ********* add primitive operators ************* */
 
-static char *get_mesh_defname(int type)
+static const char *get_mesh_defname(int type)
 {
        switch (type) {
                case PRIM_PLANE: return "Plane";
@@ -1351,7 +1363,7 @@ static void make_prim_ext(bContext *C, float *loc, float *rot, int enter_editmod
                ED_object_enter_editmode(C, EM_DO_UNDO|EM_IGNORE_LAYER); /* rare cases the active layer is messed up */
                newob = 1;
        }
-       else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
+       else DAG_id_tag_update(&obedit->id, OB_RECALC_DATA);
 
        scale= ED_object_new_primitive_matrix(C, obedit, loc, rot, mat);
 
@@ -1360,7 +1372,7 @@ static void make_prim_ext(bContext *C, float *loc, float *rot, int enter_editmod
 
        make_prim(obedit, type, mat, tot, seg, subdiv, dia, depth, ext, fill);
 
-       DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
+       DAG_id_tag_update(obedit->data, 0);
        WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
 
 
@@ -1555,7 +1567,7 @@ void MESH_OT_primitive_cone_add(wmOperatorType *ot)
        RNA_def_int(ot->srna, "vertices", 32, INT_MIN, INT_MAX, "Vertices", "", 2, 500);
        RNA_def_float(ot->srna, "radius", 1.0f, 0.0, FLT_MAX, "Radius", "", 0.001, 100.00);
        RNA_def_float(ot->srna, "depth", 2.0f, 0.0, FLT_MAX, "Depth", "", 0.001, 100.00);
-       RNA_def_boolean(ot->srna, "cap_end", 0, "Cap End", "");
+       RNA_def_boolean(ot->srna, "cap_end", 1, "Cap End", "");
 
        ED_object_add_generic_props(ot, TRUE);
 }
@@ -1722,7 +1734,7 @@ static int mesh_duplicate_exec(bContext *C, wmOperator *UNUSED(op))
 
        BKE_mesh_end_editmesh(ob->data, em);
 
-       DAG_id_flush_update(ob->data, OB_RECALC_DATA);
+       DAG_id_tag_update(ob->data, 0);
        WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data);
        
        return OPERATOR_FINISHED;