- Change 2 operators from using int properties into enums.
- 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.
This commit is contained in:
@@ -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 **************** */
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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++)
|
||||
|
||||
Reference in New Issue
Block a user