Brought back select by number of vertices
authorGeoffrey Bantle <hairbat@yahoo.com>
Sun, 26 Jun 2011 20:23:27 +0000 (20:23 +0000)
committerGeoffrey Bantle <hairbat@yahoo.com>
Sun, 26 Jun 2011 20:23:27 +0000 (20:23 +0000)
and select loose verts/edges:
----------------------------------------------
Split select by number of vertices and select
loose verts/edges into seperate functions.

Previously select by number of vertices was
also accessed through two different UI items,
"Select Quads" and "Select Triangles". Now
it is one function with a integer property
for selecting the size of the face you want
selected.

Also added an option to modify the behavior
of the selection. Can now select whether you
want to select faces that have vertices
equal to, less than or greater than the number
of vertices in operator property.

release/scripts/startup/bl_ui/space_view3d.py
source/blender/editors/mesh/bmesh_tools.c
source/blender/editors/mesh/mesh_intern.h
source/blender/editors/mesh/mesh_ops.c

index cb7b5e9aa6927898e239ec847973850042d06587..62e37b996cc7ce8010c9f3ba2a6dee3111f5ad46 100644 (file)
@@ -519,11 +519,10 @@ class VIEW3D_MT_select_edit_mesh(bpy.types.Menu):
 
         layout.separator()
 
-        layout.operator("mesh.select_by_number_vertices", text="Triangles").type = 'TRIANGLES'
-        layout.operator("mesh.select_by_number_vertices", text="Quads").type = 'QUADS'
+        layout.operator("mesh.select_by_number_vertices", text = "By Number of Verts")
         if context.scene.tool_settings.mesh_select_mode[2] == False:
                 layout.operator("mesh.select_non_manifold", text="Non Manifold")
-        layout.operator("mesh.select_by_number_vertices", text="Loose Verts/Edges").type = 'OTHER'
+        layout.operator("mesh.select_loose_verts", text = "Loose Verts/Edges")
         layout.operator("mesh.select_similar", text="Similar")
 
         layout.separator()
index 52bb11addd61757a812e570ff55c07a030306fbd..e4d1a2ee86cbd5ae2b23e387e81cdb9337e6c321 100644 (file)
@@ -4073,48 +4073,47 @@ void MESH_OT_screw(wmOperatorType *ot)
        RNA_def_float_vector(ot->srna, "axis", 3, NULL, -1.0f, 1.0f, "Axis", "Axis in global view space", -FLT_MAX, FLT_MAX);
 }
 
-static int select_by_number_vertices_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
+static int select_by_number_vertices_exec(bContext *C, wmOperator *op)
 {
-#if 0
        Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
-       EditFace *efa;
-       int numverts= RNA_enum_get(op->ptr, "type");
+       BMEditMesh *em= ((Mesh*)obedit->data)->edit_btmesh;
+       BMFace *efa;
+       BMIter iter;
+       int numverts= RNA_int_get(op->ptr, "number");
+       int type = RNA_enum_get(op->ptr, "type");
 
-       /* Selects trias/qiads or isolated verts, and edges that do not have 2 neighboring
-        * faces
-        */
+       for(efa = BMIter_New(&iter, em->bm, BM_FACES_OF_MESH, NULL);
+           efa; efa = BMIter_Step(&iter)){
 
-       /* for loose vertices/edges, we first select all, loop below will deselect */
-       if(numverts==5) {
-               EM_set_flag_all(em, SELECT);
-       }
-       else if(em->selectmode!=SCE_SELECT_FACE) {
-               BKE_report(op->reports, RPT_ERROR, "Only works in face selection mode");
-               return OPERATOR_CANCELLED;
-       }
-       
-       for(efa= em->faces.first; efa; efa= efa->next) {
-               if (efa->e4) {
-                       EM_select_face(efa, (numverts==4) );
+               int select = 0;
+
+               if(type == 0 && efa->len < numverts){
+                       select = 1;
+               }else if(type == 1 && efa->len == numverts){
+                       select = 1;
+               }else if(type == 2 && efa->len > numverts){
+                       select = 1;
                }
-               else {
-                       EM_select_face(efa, (numverts==3) );
+
+               if(select){
+                       BM_Select(em->bm, efa, 1);
                }
        }
 
+       EDBM_selectmode_flush(em);
+
        WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data);
-#endif
        return OPERATOR_FINISHED;
 }
 
 void MESH_OT_select_by_number_vertices(wmOperatorType *ot)
 {
-       static const EnumPropertyItem type_items[]= {
-               {3, "TRIANGLES", 0, "Triangles", NULL},
-               {4, "QUADS", 0, "Triangles", NULL},
-               {5, "OTHER", 0, "Other", NULL},
-               {0, NULL, 0, NULL, NULL}};
+       static const EnumPropertyItem type_items[] = {
+           {0, "LESS", 0, "Less Than", ""},
+           {1, "EQUAL", 0, "Equal To", ""},
+           {2, "GREATER", 0, "Greater Than", ""},
+           {0, NULL, 0, NULL, NULL}
+       };
 
        /* identifiers */
        ot->name= "Select by Number of Vertices";
@@ -4127,11 +4126,56 @@ void MESH_OT_select_by_number_vertices(wmOperatorType *ot)
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       /* props */
-       RNA_def_enum(ot->srna, "type", type_items, 3, "Type", "Type of elements to select.");
+
+       /* properties */
+       RNA_def_int(ot->srna, "number", 4, 3, INT_MAX, "Number of Vertices", "", 3, INT_MAX);
+       RNA_def_enum(ot->srna, "type", type_items, 1, "Type", "Type of comparison to make");
+}
+
+static int select_loose_verts_exec(bContext *C, wmOperator *op)
+{
+       Object *obedit = CTX_data_edit_object(C);
+       BMEditMesh *em = ((Mesh*)obedit->data)->edit_btmesh;
+       BMVert *eve;
+       BMEdge *eed;
+       BMIter iter;
+
+       for(eve = BMIter_New(&iter, em->bm, BM_VERTS_OF_MESH, NULL);
+           eve; eve = BMIter_Step(&iter)){
+
+               if(!eve->e){
+                       BM_Select(em->bm, eve, 1);
+               }
+       }
+
+       for(eed = BMIter_New(&iter, em->bm, BM_EDGES_OF_MESH, NULL);
+           eed; eed = BMIter_Step(&iter)){
+
+               if(!eed->l){
+                       BM_Select(em->bm, eed, 1);
+               }
+       }
+
+       EDBM_selectmode_flush(em);
+
+       WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data);
+       return OPERATOR_FINISHED;
 }
 
+void MESH_OT_select_loose_verts(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name = "Select Loose Vertices/Edges";
+       ot->description = "Select vertices with edges or faces and edges with no faces";
+       ot->idname = "MESH_OT_select_loose_verts";
+
+       /* api callbacks */
+       ot->exec = select_loose_verts_exec;
+       ot->poll = ED_operator_editmesh;
+
+       /* flags */
+       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+}
 
 #define MIRROR_THRESH  1.0f
 
index f4d86ae455ef332ecf8a74025ef60b0eae8348ee..3b33afa8b49394a6d463743c9c20977d31069463 100644 (file)
@@ -216,6 +216,7 @@ void MESH_OT_select_linked_pick(struct wmOperatorType *ot);
 void MESH_OT_hide(struct wmOperatorType *ot);
 void MESH_OT_reveal(struct wmOperatorType *ot);
 void MESH_OT_select_by_number_vertices(struct wmOperatorType *ot);
+void MESH_OT_select_loose_verts(struct wmOperatorType *ot);
 void MESH_OT_select_mirror(struct wmOperatorType *ot);
 void MESH_OT_normals_make_consistent(struct wmOperatorType *ot);
 void MESH_OT_faces_select_linked_flat(struct wmOperatorType *ot);
index 94c9dc87760f4dd6e238272b17c76859661412bc..82d925c4ff3a2f4c430170a506a415aada0e48ac 100644 (file)
@@ -73,6 +73,7 @@ void ED_operatortypes_mesh(void)
        WM_operatortype_append(MESH_OT_hide);
        WM_operatortype_append(MESH_OT_reveal);
        WM_operatortype_append(MESH_OT_select_by_number_vertices);
+       WM_operatortype_append(MESH_OT_select_loose_verts);
        WM_operatortype_append(MESH_OT_select_mirror);
        WM_operatortype_append(MESH_OT_normals_make_consistent);
        WM_operatortype_append(MESH_OT_merge);