code cleanup: use const float and define array size
[blender.git] / source / blender / editors / mesh / editmesh_add.c
index b7700623d80312fe4538d05b79c3e5ec0d3f8669..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);
+       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];
        
@@ -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,15 +139,15 @@ 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)
@@ -168,7 +163,7 @@ void MESH_OT_primitive_plane_add(wmOperatorType *ot)
        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);
 }
@@ -186,11 +181,11 @@ 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;
        }
        
@@ -213,12 +208,12 @@ void MESH_OT_primitive_cube_add(wmOperatorType *ot)
        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"},
@@ -235,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);
@@ -244,10 +239,10 @@ 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=%b cap_tris=%b 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;
        }
@@ -272,7 +267,7 @@ void MESH_OT_primitive_circle_add(wmOperatorType *ot)
        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);
@@ -294,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);
@@ -303,7 +298,7 @@ static int add_primitive_cylinder_exec(bContext *C, wmOperator *op)
        me = obedit->data;
        em = me->edit_btmesh;
 
-       if (!EDBM_CallAndSelectOpf(
+       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"),
@@ -335,10 +330,10 @@ void MESH_OT_primitive_cylinder_add(wmOperatorType *ot)
        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);
@@ -359,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);
@@ -368,7 +363,7 @@ static int add_primitive_cone_exec(bContext *C, wmOperator *op)
        me = obedit->data;
        em = me->edit_btmesh;
 
-       if (!EDBM_CallAndSelectOpf(
+       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"),
@@ -397,10 +392,10 @@ void MESH_OT_primitive_cone_add(wmOperatorType *ot)
        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);
@@ -417,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;
@@ -429,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;
        }
@@ -457,7 +452,7 @@ void MESH_OT_primitive_grid_add(wmOperatorType *ot)
        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);
@@ -480,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);
 
@@ -488,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;
        }
        
@@ -509,7 +504,7 @@ void MESH_OT_primitive_monkey_add(wmOperatorType *ot)
        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);
 }
@@ -531,10 +526,10 @@ 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, "segments"), RNA_int_get(op->ptr, "ring_count"),
-                                  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;
        }
@@ -559,7 +554,7 @@ void MESH_OT_primitive_uv_sphere_add(wmOperatorType *ot)
        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);
@@ -587,7 +582,7 @@ static int add_primitive_icosphere_exec(bContext *C, wmOperator *op)
        me = obedit->data;
        em = me->edit_btmesh;
 
-       if (!EDBM_CallAndSelectOpf(
+       if (!EDBM_op_call_and_selectf(
                em, op, "vertout",
                "create_icosphere subdivisions=%i diameter=%f mat=%m4",
                RNA_int_get(op->ptr, "subdivisions"),
@@ -616,7 +611,7 @@ void MESH_OT_primitive_ico_sphere_add(wmOperatorType *ot)
        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);