code cleanup: use const float and define array size
[blender.git] / source / blender / editors / mesh / editmesh_add.c
index ea9dc73ee945b8ae16d6d72c026ac31c01a81a77..f9eb8770012f0c6fd7495783a5a711aa19a004cc 100644 (file)
 #include "ED_screen.h"
 #include "ED_object.h"
 
+#include "mesh_intern.h"
+
 /* uses context to figure out transform for primitive */
 /* returns standard diameter */
-static float new_primitive_matrix(bContext *C, float *loc, float *rot, float primmat[][4])
+static float new_primitive_matrix(bContext *C, const float loc[3], const float rot[3], float primmat[][4])
 {
-       Object *obedit= CTX_data_edit_object(C);
-       View3D *v3d =CTX_wm_view3d(C);
+       Object *obedit = CTX_data_edit_object(C);
+       View3D *v3d = CTX_wm_view3d(C);
        float mat[3][3], rmat[3][3], cmat[3][3], imat[3][3];
        
        unit_m4(primmat);
@@ -83,48 +85,41 @@ static float new_primitive_matrix(bContext *C, float *loc, float *rot, float pri
 
 static void make_prim_init(bContext *C, const char *idname,
                            float *dia, float mat[][4],
-                           int *state, float *loc, float *rot, unsigned int layer)
+                           int *state, const float loc[3], const float rot[3], const unsigned int layer)
 {
-       Object *obedit= CTX_data_edit_object(C);
+       Object *obedit = CTX_data_edit_object(C);
 
        *state = 0;
-       if(obedit==NULL || obedit->type!=OB_MESH) {
-               obedit= ED_object_add_type(C, OB_MESH, loc, rot, FALSE, layer);
+       if (obedit == NULL || obedit->type != OB_MESH) {
+               obedit = ED_object_add_type(C, OB_MESH, loc, rot, FALSE, layer);
                
                rename_id((ID *)obedit, idname);
                rename_id((ID *)obedit->data, idname);
 
                /* create editmode */
-               ED_object_enter_editmode(C, EM_DO_UNDO|EM_IGNORE_LAYER); /* rare cases the active layer is messed up */
+               ED_object_enter_editmode(C, EM_DO_UNDO | EM_IGNORE_LAYER); /* rare cases the active layer is messed up */
                *state = 1;
        }
-       else DAG_id_tag_update(&obedit->id, OB_RECALC_DATA);
 
-       *dia *= new_primitive_matrix(C, loc, rot, mat);
+       *dia = new_primitive_matrix(C, loc, rot, mat);
 }
 
 static void make_prim_finish(bContext *C, int *state, int enter_editmode)
 {
-       Object *obedit;
-       Mesh *me;
-       BMEditMesh *em;
-
-       obedit = CTX_data_edit_object(C);
-       me = obedit->data;
-       em = me->edit_btmesh;
+       Object *obedit = CTX_data_edit_object(C);
+       BMEditMesh *em = BMEdit_FromObject(obedit);
 
        /* Primitive has all verts selected, use vert select flush
         * to push this up to edges & faces. */
        EDBM_selectmode_flush_ex(em, SCE_SELECT_VERTEX);
 
-       DAG_id_tag_update(obedit->data, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
+       EDBM_update_generic(C, em, TRUE);
 
        /* userdef */
        if (*state && !enter_editmode) {
                ED_object_exit_editmode(C, EM_FREEDATA); /* adding EM_DO_UNDO messes up operator redo */
        }
-       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
+       WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, obedit);
 }
 
 static int add_primitive_plane_exec(bContext *C, wmOperator *op)
@@ -132,7 +127,7 @@ static int add_primitive_plane_exec(bContext *C, wmOperator *op)
        Object *obedit;
        Mesh *me;
        BMEditMesh *em;
-       float loc[3], rot[3], mat[4][4], dia = 1.0f;
+       float loc[3], rot[3], mat[4][4], dia;
        int enter_editmode;
        int state;
        unsigned int layer;
@@ -144,29 +139,31 @@ static int add_primitive_plane_exec(bContext *C, wmOperator *op)
        me = obedit->data;
        em = me->edit_btmesh;
 
-       if (!EDBM_CallAndSelectOpf(em, op, "vertout", 
-                       "create_grid xsegments=%i ysegments=%i size=%f mat=%m4", 1, 1, dia, mat))
+       if (!EDBM_op_call_and_selectf(em, op, "vertout",
+                                     "create_grid xsegments=%i ysegments=%i size=%f mat=%m4", 1, 1, dia, mat))
+       {
                return OPERATOR_CANCELLED;
+       }
 
        make_prim_finish(C, &state, enter_editmode);
 
-       return OPERATOR_FINISHED;       
+       return OPERATOR_FINISHED;
 }
 
 void MESH_OT_primitive_plane_add(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Add Plane";
-       ot->description= "Construct a filled planar mesh with 4 vertices";
-       ot->idname= "MESH_OT_primitive_plane_add";
+       ot->name = "Add Plane";
+       ot->description = "Construct a filled planar mesh with 4 vertices";
+       ot->idname = "MESH_OT_primitive_plane_add";
        
        /* api callbacks */
-       ot->invoke= ED_object_add_generic_invoke;
-       ot->exec= add_primitive_plane_exec;
-       ot->poll= ED_operator_scene_editable;
+       ot->invoke = ED_object_add_generic_invoke;
+       ot->exec = add_primitive_plane_exec;
+       ot->poll = ED_operator_scene_editable;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
        ED_object_add_generic_props(ot, TRUE);
 }
@@ -184,12 +181,13 @@ static int add_primitive_cube_exec(bContext *C, wmOperator *op)
        ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL);
        make_prim_init(C, "Cube", &dia, mat, &state, loc, rot, layer);
 
-       obedit= CTX_data_edit_object(C);
+       obedit = CTX_data_edit_object(C);
        me = obedit->data;
        em = me->edit_btmesh;
 
-       if (!EDBM_CallAndSelectOpf(em, op, "vertout", "create_cube mat=%m4 size=%f", mat, 2.0f)) 
+       if (!EDBM_op_call_and_selectf(em, op, "vertout", "create_cube mat=%m4 size=%f", mat, dia * 2.0f)) {
                return OPERATOR_CANCELLED;
+       }
        
        /* BMESH_TODO make plane side this: M_SQRT2 - plane (diameter of 1.41 makes it unit size) */
        make_prim_finish(C, &state, enter_editmode);
@@ -200,22 +198,22 @@ static int add_primitive_cube_exec(bContext *C, wmOperator *op)
 void MESH_OT_primitive_cube_add(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Add Cube";
-       ot->description= "Construct a cube mesh";
-       ot->idname= "MESH_OT_primitive_cube_add";
+       ot->name = "Add Cube";
+       ot->description = "Construct a cube mesh";
+       ot->idname = "MESH_OT_primitive_cube_add";
        
        /* api callbacks */
-       ot->invoke= ED_object_add_generic_invoke;
-       ot->exec= add_primitive_cube_exec;
-       ot->poll= ED_operator_scene_editable;
+       ot->invoke = ED_object_add_generic_invoke;
+       ot->exec = add_primitive_cube_exec;
+       ot->poll = ED_operator_scene_editable;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
        ED_object_add_generic_props(ot, TRUE);
 }
 
-static const EnumPropertyItem fill_type_items[]= {
+static const EnumPropertyItem fill_type_items[] = {
        {0, "NOTHING", 0, "Nothing", "Don't fill at all"},
        {1, "NGON", 0, "Ngon", "Use ngons"},
        {2, "TRIFAN", 0, "Triangle Fan", "Use triangle fans"},
@@ -232,7 +230,7 @@ static int add_primitive_circle_exec(bContext *C, wmOperator *op)
        unsigned int layer;
        
        cap_end = RNA_enum_get(op->ptr, "fill_type");
-       cap_tri = cap_end==2;
+       cap_tri = (cap_end == 2);
        
        ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL);
        make_prim_init(C, "Circle", &dia, mat, &state, loc, rot, layer);
@@ -241,11 +239,13 @@ static int add_primitive_circle_exec(bContext *C, wmOperator *op)
        me = obedit->data;
        em = me->edit_btmesh;
 
-       if (!EDBM_CallAndSelectOpf(em, op, "vertout", 
-                       "create_circle segments=%i diameter=%f cap_ends=%i cap_tris=%i mat=%m4", 
-                       RNA_int_get(op->ptr, "vertices"), RNA_float_get(op->ptr, "radius"), 
-                       cap_end, cap_tri, mat))
+       if (!EDBM_op_call_and_selectf(em, op, "vertout",
+                                     "create_circle segments=%i diameter=%f cap_ends=%b cap_tris=%b mat=%m4",
+                                     RNA_int_get(op->ptr, "vertices"), RNA_float_get(op->ptr, "radius"),
+                                     cap_end, cap_tri, mat))
+       {
                return OPERATOR_CANCELLED;
+       }
        
        make_prim_finish(C, &state, enter_editmode);
        
@@ -257,17 +257,17 @@ void MESH_OT_primitive_circle_add(wmOperatorType *ot)
        PropertyRNA *prop;
 
        /* identifiers */
-       ot->name= "Add Circle";
-       ot->description= "Construct a circle mesh";
-       ot->idname= "MESH_OT_primitive_circle_add";
+       ot->name = "Add Circle";
+       ot->description = "Construct a circle mesh";
+       ot->idname = "MESH_OT_primitive_circle_add";
        
        /* api callbacks */
-       ot->invoke= ED_object_add_generic_invoke;
-       ot->exec= add_primitive_circle_exec;
-       ot->poll= ED_operator_scene_editable;
+       ot->invoke = ED_object_add_generic_invoke;
+       ot->exec = add_primitive_circle_exec;
+       ot->poll = ED_operator_scene_editable;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
        
        /* props */
        RNA_def_int(ot->srna, "vertices", 32, 3, INT_MAX, "Vertices", "", 3, 500);
@@ -289,7 +289,7 @@ static int add_primitive_cylinder_exec(bContext *C, wmOperator *op)
        unsigned int layer;
        
        cap_end = RNA_enum_get(op->ptr, "end_fill_type");
-       cap_tri = cap_end==2;
+       cap_tri = (cap_end == 2);
        
        ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL);
        make_prim_init(C, "Cylinder", &dia, mat, &state, loc, rot, layer);
@@ -298,11 +298,17 @@ static int add_primitive_cylinder_exec(bContext *C, wmOperator *op)
        me = obedit->data;
        em = me->edit_btmesh;
 
-       if (!EDBM_CallAndSelectOpf(em, op, "vertout", 
-                       "create_cone segments=%i diameter1=%f diameter2=%f cap_ends=%i cap_tris=%i depth=%f mat=%m4", 
-                       RNA_int_get(op->ptr, "vertices"), RNA_float_get(op->ptr, "radius"), 
-                       RNA_float_get(op->ptr, "radius"), cap_end, cap_tri, RNA_float_get(op->ptr, "depth"), mat))
+       if (!EDBM_op_call_and_selectf(
+               em, op, "vertout",
+               "create_cone segments=%i diameter1=%f diameter2=%f cap_ends=%b cap_tris=%b depth=%f mat=%m4",
+               RNA_int_get(op->ptr, "vertices"),
+               RNA_float_get(op->ptr, "radius"),
+               RNA_float_get(op->ptr, "radius"),
+               cap_end, cap_tri,
+               RNA_float_get(op->ptr, "depth"), mat))
+       {
                return OPERATOR_CANCELLED;
+       }
        
        make_prim_finish(C, &state, enter_editmode);
        
@@ -314,20 +320,20 @@ void MESH_OT_primitive_cylinder_add(wmOperatorType *ot)
        PropertyRNA *prop;
 
        /* identifiers */
-       ot->name= "Add Cylinder";
-       ot->description= "Construct a cylinder mesh";
-       ot->idname= "MESH_OT_primitive_cylinder_add";
+       ot->name = "Add Cylinder";
+       ot->description = "Construct a cylinder mesh";
+       ot->idname = "MESH_OT_primitive_cylinder_add";
        
        /* api callbacks */
-       ot->invoke= ED_object_add_generic_invoke;
-       ot->exec= add_primitive_cylinder_exec;
-       ot->poll= ED_operator_scene_editable;
+       ot->invoke = ED_object_add_generic_invoke;
+       ot->exec = add_primitive_cylinder_exec;
+       ot->poll = ED_operator_scene_editable;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
        
        /* props */
-       RNA_def_int(ot->srna, "vertices", 32, 2, INT_MAX, "Vertices", "", 2, 500);
+       RNA_def_int(ot->srna, "vertices", 32, 3, INT_MAX, "Vertices", "", 3, 500);
        prop = RNA_def_float(ot->srna, "radius", 1.0f, 0.0, FLT_MAX, "Radius", "", 0.001, 100.00);
        RNA_def_property_subtype(prop, PROP_DISTANCE);
        prop = RNA_def_float(ot->srna, "depth", 2.0f, 0.0, FLT_MAX, "Depth", "", 0.001, 100.00);
@@ -348,7 +354,7 @@ static int add_primitive_cone_exec(bContext *C, wmOperator *op)
        unsigned int layer;
        
        cap_end = RNA_enum_get(op->ptr, "end_fill_type");
-       cap_tri = cap_end==2;
+       cap_tri = (cap_end == 2);
        
        ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL);
        make_prim_init(C, "Cone", &dia, mat, &state, loc, rot, layer);
@@ -357,15 +363,18 @@ static int add_primitive_cone_exec(bContext *C, wmOperator *op)
        me = obedit->data;
        em = me->edit_btmesh;
 
-       if (!EDBM_CallAndSelectOpf(em, op, "vertout", 
-                       "create_cone segments=%i diameter1=%f diameter2=%f cap_ends=%i cap_tris=%i depth=%f mat=%m4", 
-                       RNA_int_get(op->ptr, "vertices"), RNA_float_get(op->ptr, "radius1"), 
-                       RNA_float_get(op->ptr, "radius2"), cap_end, cap_tri, RNA_float_get(op->ptr, "depth"), mat))
+       if (!EDBM_op_call_and_selectf(
+               em, op, "vertout",
+               "create_cone segments=%i diameter1=%f diameter2=%f cap_ends=%b cap_tris=%b depth=%f mat=%m4",
+               RNA_int_get(op->ptr, "vertices"), RNA_float_get(op->ptr, "radius1"),
+               RNA_float_get(op->ptr, "radius2"), cap_end, cap_tri, RNA_float_get(op->ptr, "depth"), mat))
+       {
                return OPERATOR_CANCELLED;
+       }
        
        make_prim_finish(C, &state, enter_editmode);
 
-       return OPERATOR_FINISHED;       
+       return OPERATOR_FINISHED;
 }
 
 void MESH_OT_primitive_cone_add(wmOperatorType *ot)
@@ -373,20 +382,20 @@ void MESH_OT_primitive_cone_add(wmOperatorType *ot)
        PropertyRNA *prop;
 
        /* identifiers */
-       ot->name= "Add Cone";
-       ot->description= "Construct a conic mesh (ends filled)";
-       ot->idname= "MESH_OT_primitive_cone_add";
+       ot->name = "Add Cone";
+       ot->description = "Construct a conic mesh";
+       ot->idname = "MESH_OT_primitive_cone_add";
        
        /* api callbacks */
-       ot->invoke= ED_object_add_generic_invoke;
-       ot->exec= add_primitive_cone_exec;
-       ot->poll= ED_operator_scene_editable;
+       ot->invoke = ED_object_add_generic_invoke;
+       ot->exec = add_primitive_cone_exec;
+       ot->poll = ED_operator_scene_editable;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
        
        /* props */
-       RNA_def_int(ot->srna, "vertices", 32, 2, INT_MAX, "Vertices", "", 2, 500);
+       RNA_def_int(ot->srna, "vertices", 32, 3, INT_MAX, "Vertices", "", 3, 500);
        prop = RNA_def_float(ot->srna, "radius1", 1.0f, 0.0, FLT_MAX, "Radius 1", "", 0.001, 100.00);
        RNA_def_property_subtype(prop, PROP_DISTANCE);
        prop = RNA_def_float(ot->srna, "radius2", 0.0f, 0.0, FLT_MAX, "Radius 2", "", 0.001, 100.00);
@@ -403,7 +412,7 @@ static int add_primitive_grid_exec(bContext *C, wmOperator *op)
        Object *obedit;
        Mesh *me;
        BMEditMesh *em;
-       float loc[3], rot[3], mat[4][4], dia = 1.0f;
+       float loc[3], rot[3], mat[4][4], dia;
        int enter_editmode;
        int state;
        unsigned int layer;
@@ -415,11 +424,11 @@ static int add_primitive_grid_exec(bContext *C, wmOperator *op)
        me = obedit->data;
        em = me->edit_btmesh;
 
-       if (!EDBM_CallAndSelectOpf(em, op, "vertout", 
-                       "create_grid xsegments=%i ysegments=%i size=%f mat=%m4",
-                       RNA_int_get(op->ptr, "x_subdivisions"), 
-                       RNA_int_get(op->ptr, "y_subdivisions"), 
-                       RNA_float_get(op->ptr, "size") * dia, mat))
+       if (!EDBM_op_call_and_selectf(em, op, "vertout",
+                                     "create_grid xsegments=%i ysegments=%i size=%f mat=%m4",
+                                     RNA_int_get(op->ptr, "x_subdivisions"),
+                                     RNA_int_get(op->ptr, "y_subdivisions"),
+                                     RNA_float_get(op->ptr, "size") * dia, mat))
        {
                return OPERATOR_CANCELLED;
        }
@@ -433,17 +442,17 @@ void MESH_OT_primitive_grid_add(wmOperatorType *ot)
        PropertyRNA *prop;
 
        /* identifiers */
-       ot->name= "Add Grid";
-       ot->description= "Construct a grid mesh";
-       ot->idname= "MESH_OT_primitive_grid_add";
+       ot->name = "Add Grid";
+       ot->description = "Construct a grid mesh";
+       ot->idname = "MESH_OT_primitive_grid_add";
        
        /* api callbacks */
-       ot->invoke= ED_object_add_generic_invoke;
-       ot->exec= add_primitive_grid_exec;
-       ot->poll= ED_operator_scene_editable;
+       ot->invoke = ED_object_add_generic_invoke;
+       ot->exec = add_primitive_grid_exec;
+       ot->poll = ED_operator_scene_editable;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
        
        /* props */
        RNA_def_int(ot->srna, "x_subdivisions", 10, 3, INT_MAX, "X Subdivisions", "", 3, 1000);
@@ -466,7 +475,7 @@ static int add_primitive_monkey_exec(bContext *C, wmOperator *op)
        
        ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, &view_aligned);
        if (!view_aligned)
-               rot[0] += M_PI/2.0f;
+               rot[0] += (float)M_PI / 2.0f;
        
        make_prim_init(C, "Monkey", &dia, mat, &state, loc, rot, layer);
 
@@ -474,7 +483,7 @@ static int add_primitive_monkey_exec(bContext *C, wmOperator *op)
        me = obedit->data;
        em = me->edit_btmesh;
 
-       if (!EDBM_CallAndSelectOpf(em, op, "vertout", "create_monkey mat=%m4", mat)) {
+       if (!EDBM_op_call_and_selectf(em, op, "vertout", "create_monkey mat=%m4", mat)) {
                return OPERATOR_CANCELLED;
        }
        
@@ -485,17 +494,17 @@ static int add_primitive_monkey_exec(bContext *C, wmOperator *op)
 void MESH_OT_primitive_monkey_add(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Add Monkey";
-       ot->description= "Construct a Suzanne mesh";
-       ot->idname= "MESH_OT_primitive_monkey_add";
+       ot->name = "Add Monkey";
+       ot->description = "Construct a Suzanne mesh";
+       ot->idname = "MESH_OT_primitive_monkey_add";
        
        /* api callbacks */
-       ot->invoke= ED_object_add_generic_invoke;
-       ot->exec= add_primitive_monkey_exec;
-       ot->poll= ED_operator_scene_editable;
+       ot->invoke = ED_object_add_generic_invoke;
+       ot->exec = add_primitive_monkey_exec;
+       ot->poll = ED_operator_scene_editable;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
        ED_object_add_generic_props(ot, TRUE);
 }
@@ -517,11 +526,13 @@ static int add_primitive_uvsphere_exec(bContext *C, wmOperator *op)
        me = obedit->data;
        em = me->edit_btmesh;
 
-       if (!EDBM_CallAndSelectOpf(em, op, "vertout", 
-                       "create_uvsphere segments=%i revolutions=%i diameter=%f mat=%m4", 
-                       RNA_int_get(op->ptr, "ring_count"), RNA_int_get(op->ptr, "segments"),
-                       RNA_float_get(op->ptr,"size"), mat)) 
+       if (!EDBM_op_call_and_selectf(em, op, "vertout",
+                                     "create_uvsphere segments=%i revolutions=%i diameter=%f mat=%m4",
+                                     RNA_int_get(op->ptr, "segments"), RNA_int_get(op->ptr, "ring_count"),
+                                     RNA_float_get(op->ptr, "size"), mat))
+       {
                return OPERATOR_CANCELLED;
+       }
        
        make_prim_finish(C, &state, enter_editmode);
 
@@ -533,17 +544,17 @@ void MESH_OT_primitive_uv_sphere_add(wmOperatorType *ot)
        PropertyRNA *prop;
 
        /* identifiers */
-       ot->name= "Add UV Sphere";
-       ot->description= "Construct a UV sphere mesh";
-       ot->idname= "MESH_OT_primitive_uv_sphere_add";
+       ot->name = "Add UV Sphere";
+       ot->description = "Construct a UV sphere mesh";
+       ot->idname = "MESH_OT_primitive_uv_sphere_add";
        
        /* api callbacks */
-       ot->invoke= ED_object_add_generic_invoke;
-       ot->exec= add_primitive_uvsphere_exec;
-       ot->poll= ED_operator_scene_editable;
+       ot->invoke = ED_object_add_generic_invoke;
+       ot->exec = add_primitive_uvsphere_exec;
+       ot->poll = ED_operator_scene_editable;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
        
        /* props */
        RNA_def_int(ot->srna, "segments", 32, 3, INT_MAX, "Segments", "", 3, 500);
@@ -571,10 +582,12 @@ static int add_primitive_icosphere_exec(bContext *C, wmOperator *op)
        me = obedit->data;
        em = me->edit_btmesh;
 
-       if (!EDBM_CallAndSelectOpf(em, op, "vertout", 
-                       "create_icosphere subdivisions=%i diameter=%f mat=%m4", 
-                       RNA_int_get(op->ptr, "subdivisions"),
-                       RNA_float_get(op->ptr, "size"), mat)) {
+       if (!EDBM_op_call_and_selectf(
+               em, op, "vertout",
+               "create_icosphere subdivisions=%i diameter=%f mat=%m4",
+               RNA_int_get(op->ptr, "subdivisions"),
+               RNA_float_get(op->ptr, "size"), mat))
+       {
                return OPERATOR_CANCELLED;
        }
        
@@ -588,17 +601,17 @@ void MESH_OT_primitive_ico_sphere_add(wmOperatorType *ot)
        PropertyRNA *prop;
 
        /* identifiers */
-       ot->name= "Add Ico Sphere";
-       ot->description= "Construct an Icosphere mesh";
-       ot->idname= "MESH_OT_primitive_ico_sphere_add";
+       ot->name = "Add Ico Sphere";
+       ot->description = "Construct an Icosphere mesh";
+       ot->idname = "MESH_OT_primitive_ico_sphere_add";
        
        /* api callbacks */
-       ot->invoke= ED_object_add_generic_invoke;
-       ot->exec= add_primitive_icosphere_exec;
-       ot->poll= ED_operator_scene_editable;
+       ot->invoke = ED_object_add_generic_invoke;
+       ot->exec = add_primitive_icosphere_exec;
+       ot->poll = ED_operator_scene_editable;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
        
        /* props */
        RNA_def_int(ot->srna, "subdivisions", 2, 1, INT_MAX, "Subdivisions", "", 1, 8);