- Change 2 operators from using int properties into enums.
authorCampbell Barton <ideasman42@gmail.com>
Sun, 1 Feb 2009 02:37:12 +0000 (02:37 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 1 Feb 2009 02:37:12 +0000 (02:37 +0000)
- Renamed MESH_OT_mesh_selection_mode_menu to MESH_OT_mesh_selection_type since the operator doesnt have to be accessed from a menu.

Shaul, you might want to look over this, using enums means WM_menu_invoke can be used instead of writing an invoke function for each operator.

Added error messages to WM_menu_invoke if no enum "type" property is found.

source/blender/editors/mesh/editmesh_mods.c
source/blender/editors/mesh/editmesh_tools.c
source/blender/editors/mesh/mesh_intern.h
source/blender/editors/mesh/mesh_ops.c
source/blender/windowmanager/intern/wm_operators.c

index 8cce61a7a3f8e5d01e8e845e6260d0392f713f8b..ecac2dc264707cef77457ff8376ee9c3ebc5c2d2 100644 (file)
@@ -3686,25 +3686,12 @@ void mesh_selection_mode_menu(EditMesh *em, int val)
        }
 }
 
-static int mesh_selection_mode_menu_invoke(bContext *C, wmOperator *op, wmEvent *event)
-{
-       int items;
-       char *menu, *p;
-       
-       items = 3;
-       
-       menu= MEM_callocN(items * OP_MAX_TYPENAME, "string");
-       
-       p= menu + sprintf(menu, "%s %%t", "Selection Mode");
-       p+= sprintf(p, "|%s %%x%d", "Vertices", 1);
-       p+= sprintf(p, "|%s %%x%d", "Edges", 2);
-       p+= sprintf(p, "|%s %%x%d", "Faces", 3);
-       
-       uiPupMenuOperator(C, 20, op, "index", menu);
-       MEM_freeN(menu);
-       
-       return OPERATOR_RUNNING_MODAL;
-}
+static EnumPropertyItem prop_mesh_edit_types[] = {
+       {1, "VERT", "Vertices", ""},
+       {2, "EDGE", "Edges", ""},
+       {3, "FACE", "Faces", ""},
+       {0, NULL, NULL, NULL}
+};
 
 static int mesh_selection_mode_menu_exec(bContext *C, wmOperator *op)
 {              
@@ -3712,21 +3699,21 @@ static int mesh_selection_mode_menu_exec(bContext *C, wmOperator *op)
        Object *obedit= CTX_data_edit_object(C);
        EditMesh *em= ((Mesh *)obedit->data)->edit_mesh;
 
-       mesh_selection_mode_menu(em, RNA_int_get(op->ptr,"index"));
+       mesh_selection_mode_menu(em, RNA_enum_get(op->ptr,"type"));
 
        WM_event_add_notifier(C, NC_WINDOW, obedit);
 
        return OPERATOR_FINISHED;
 }
 
-void MESH_OT_mesh_selection_mode_menu(wmOperatorType *ot)
+void MESH_OT_mesh_selection_type(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Selection Mode";
-       ot->idname= "MESH_OT_mesh_selection_mode_menu";
+       ot->idname= "MESH_OT_mesh_selection_type";
        
        /* api callbacks */
-       ot->invoke= mesh_selection_mode_menu_invoke;
+       ot->invoke= WM_menu_invoke;
        ot->exec= mesh_selection_mode_menu_exec;
        
        ot->poll= ED_operator_editmesh;
@@ -3734,8 +3721,8 @@ void MESH_OT_mesh_selection_mode_menu(wmOperatorType *ot)
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
-       /*props */
-       RNA_def_int(ot->srna, "index", 1, 0, INT_MAX, "Index", "", 0, 4);
+       /* props */
+       RNA_def_enum(ot->srna, "type", prop_mesh_edit_types, 0, "Type", "Select the mesh selection type");
        
 }
 /* ************************* SEAMS AND EDGES **************** */
index b3085a6705fd92574f81c05f78d9786ab573bda2..50e84bdd507b1751eab455b3faefcaab04ff21c4 100644 (file)
@@ -1096,52 +1096,38 @@ void delete_mesh(Object *obedit, EditMesh *em, int event)
 //     DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
 }
 
+/* Note, these values must match delete_mesh() event values */
+static EnumPropertyItem prop_mesh_delete_types[] = {
+       {10,"VERT",             "Vertices", ""},
+       {1, "EDGE",             "Edges", ""},
+       {2, "FACE",             "Faces", ""},
+       {3, "ALL",              "All", ""},
+       {4, "EDGE_FACE","Edges & Faces", ""},
+       {5, "ONLY_FACE","Only Faces", ""},
+       {6, "EDGE_LOOP","Edge Loop", ""},
+       {0, NULL, NULL, NULL}
+};
+
 static int delete_mesh_exec(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
        EditMesh *em= ((Mesh *)obedit->data)->edit_mesh;
        
-       delete_mesh(obedit,em,RNA_int_get(op->ptr, "event"));
+       delete_mesh(obedit,em,RNA_enum_get(op->ptr, "type"));
        
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
        
        return OPERATOR_FINISHED;
 }
 
-static int delete_mesh_invoke(bContext *C, wmOperator *op, wmEvent *event)
-{
-       int items;
-       char *menu, *p;
-       
-       items = 6;
-       
-       menu= MEM_callocN(items * OP_MAX_TYPENAME, "string");
-       
-       p= menu + sprintf(menu, "%s %%t", "Erase");
-       p+= sprintf(p, "|%s %%x%d", "Vertices", 10);
-       p+= sprintf(p, "|%s %%x%d", "Edges", 1);
-       p+= sprintf(p, "|%s %%x%d", "Faces", 2);
-       p+= sprintf(p, "|%s %%x%d", "All", 3);
-       p+= sprintf(p, "|%s %%x%d", "Edges & Faces", 4);
-       p+= sprintf(p, "|%s %%x%d", "Only Faces", 5);
-       p+= sprintf(p, "|%s %%x%d", "Edge Loop", 6);
-       
-       
-       uiPupMenuOperator(C, 20, op, "event", menu);
-       MEM_freeN(menu);
-       
-       return OPERATOR_RUNNING_MODAL;
-}
-
-
 void MESH_OT_delete_mesh(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "delete mesh";
+       ot->name= "Delete Mesh";
        ot->idname= "MESH_OT_delete_mesh";
        
        /* api callbacks */
-       ot->invoke= delete_mesh_invoke;
+       ot->invoke= WM_menu_invoke;
        ot->exec= delete_mesh_exec;
        
        ot->poll= ED_operator_editmesh;
@@ -1150,7 +1136,7 @@ void MESH_OT_delete_mesh(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /*props */
-       RNA_def_int(ot->srna, "event", 0, 0, INT_MAX, "event", "", 0, 1000);
+       RNA_def_enum(ot->srna, "type", prop_mesh_delete_types, 10, "Type", "Method used for deleting mesh data");
 }
 
 /* Got this from scanfill.c. You will need to juggle around the
index 5d99600863a328ee22a2750b760dbb0be3d69b7c..225939684019d9a0553212274e5aee8cad482b8a 100644 (file)
@@ -191,7 +191,7 @@ void MESH_OT_similar_edge_select(struct wmOperatorType *ot);
 void MESH_OT_similar_face_select(struct wmOperatorType *ot);
 void MESH_OT_selectrandom_mesh(struct wmOperatorType *ot);
 void MESH_OT_vertices_to_sphere(struct wmOperatorType *ot);
-void MESH_OT_mesh_selection_mode_menu(struct wmOperatorType *ot);
+void MESH_OT_mesh_selection_type(struct wmOperatorType *ot);
 
 extern EditEdge *findnearestedge(ViewContext *vc, int *dist);
 extern void EM_automerge(int update);
index 8cbc3b9747e01723f9bebc2315664666062da25e..606d778bd512185d4bcde9ff265a190b7b0e4039 100644 (file)
@@ -114,7 +114,7 @@ void ED_operatortypes_mesh(void)
        WM_operatortype_append(MESH_OT_selectconnected_mesh_all);
        WM_operatortype_append(MESH_OT_selectconnected_mesh);
        WM_operatortype_append(MESH_OT_selectrandom_mesh);
-       WM_operatortype_append(MESH_OT_mesh_selection_mode_menu);
+       WM_operatortype_append(MESH_OT_mesh_selection_type);
        WM_operatortype_append(MESH_OT_hide_mesh);
        WM_operatortype_append(MESH_OT_reveal_mesh);
        WM_operatortype_append(MESH_OT_consistant_normals);
index 50de3a03b8254a7b7a45a08ac248942dbc54f228..0ae47c029c2a925fb0520f9907a56fd5e1c21868 100644 (file)
@@ -204,8 +204,14 @@ int WM_menu_invoke(bContext *C, wmOperator *op, wmEvent *event)
        const EnumPropertyItem *item;
        int totitem, i, len= strlen(op->type->name) + 8;
        char *menu, *p;
-       
-       if(prop) {
+
+       if(prop==NULL) {
+               printf("WM_menu_invoke: %s has no \"type\" enum property\n", op->type->idname);
+       }
+       else if (RNA_property_type(op->ptr, prop) != PROP_ENUM) {
+               printf("WM_menu_invoke: %s \"type\" is not an enum property\n", op->type->idname);
+       }
+       else {
                RNA_property_enum_items(op->ptr, prop, &item, &totitem);
                
                for (i=0; i<totitem; i++)