Bugfix #25636
[blender.git] / source / blender / editors / mesh / editmesh_add.c
index 5dd1b1227a33a219e730bdebfb52f1665985dee9..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"
@@ -114,7 +115,7 @@ static int dupli_extrude_cursor(bContext *C, wmOperator *op, wmEvent *event)
        float min[3], max[3];
        int done= 0;
        short use_proj;
-printf("%d\n", event->val);
+
        em_setup_viewcontext(C, &vc);
 
        use_proj= (vc.scene->toolsettings->snap_flag & SCE_SNAP) &&     (vc.scene->toolsettings->snap_mode==SCE_SNAP_MODE_FACE);
@@ -237,7 +238,8 @@ printf("%d\n", event->val);
                
                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);
                
@@ -260,7 +262,7 @@ printf("%d\n", event->val);
                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;
 }
@@ -358,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;
        }
 
@@ -387,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);
@@ -419,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);
@@ -708,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)
@@ -737,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) {
@@ -745,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;
        }
 
@@ -757,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 */
@@ -809,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) {
@@ -835,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);
@@ -1058,7 +1060,7 @@ static void make_prim(Object *obedit, int type, float mat[4][4], int tot, int se
                        vec[2]= 0.0f;
                        eve= addvertlist(em, vec, NULL);
                        eve->f= 1+2+4;
-                       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;
@@ -1068,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 */
@@ -1201,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++) {
@@ -1312,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";
@@ -1348,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);
 
@@ -1357,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);
 
 
@@ -1552,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);
 }
@@ -1719,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;