Merged changes in the trunk up to revision 55357.
[blender-staging.git] / source / blender / editors / mesh / editmesh_select.c
index ccf77b70ea00bebb93cd11d7f233169b276aa5b9..a1c302c6a63f102b1211673248e8772070cacd0f 100644 (file)
@@ -64,6 +64,9 @@
 #include "DNA_scene_types.h"
 #include "DNA_object_types.h"
 #include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+
+#include "GPU_extensions.h"
 
 #include "mesh_intern.h"
 
@@ -252,6 +255,9 @@ int EDBM_backbuf_border_mask_init(ViewContext *vc, const int mcords[][2], short
 
        dr = buf->rect;
 
+       if (vc->rv3d->gpuoffscreen)
+               GPU_offscreen_bind(vc->rv3d->gpuoffscreen);
+       
        /* draw the mask */
        glDisable(GL_DEPTH_TEST);
        
@@ -269,6 +275,9 @@ int EDBM_backbuf_border_mask_init(ViewContext *vc, const int mcords[][2], short
        
        glFinish(); /* to be sure readpixels sees mask */
        
+       if (vc->rv3d->gpuoffscreen)
+               GPU_offscreen_unbind(vc->rv3d->gpuoffscreen);
+       
        /* grab mask */
        bufmask = view3d_read_backbuf(vc, xmin, ymin, xmax, ymax);
 
@@ -683,6 +692,9 @@ static EnumPropertyItem prop_similar_types[] = {
        {SIMEDGE_BEVEL, "BEVEL", 0, "Bevel", ""},
        {SIMEDGE_SEAM, "SEAM", 0, "Seam", ""},
        {SIMEDGE_SHARP, "SHARP", 0, "Sharpness", ""},
+#ifdef WITH_FREESTYLE
+       {SIMEDGE_FREESTYLE, "FREESTYLE_EDGE", 0, "Freestyle Edge Marks", ""},
+#endif
 
        {SIMFACE_MATERIAL, "MATERIAL", 0, "Material", ""},
        {SIMFACE_IMAGE, "IMAGE", 0, "Image", ""},
@@ -691,6 +703,9 @@ static EnumPropertyItem prop_similar_types[] = {
        {SIMFACE_PERIMETER, "PERIMETER", 0, "Perimeter", ""},
        {SIMFACE_NORMAL, "NORMAL", 0, "Normal", ""},
        {SIMFACE_COPLANAR, "COPLANAR", 0, "Co-planar", ""},
+#ifdef WITH_FREESTYLE
+       {SIMFACE_FREESTYLE, "FREESTYLE_FACE", 0, "Freestyle Face Marks", ""},
+#endif
 
        {0, NULL, 0, NULL, NULL}
 };
@@ -865,7 +880,11 @@ static EnumPropertyItem *select_similar_type_itemf(bContext *C, PointerRNA *UNUS
                        }
                }
                else if (em->selectmode & SCE_SELECT_FACE) {
+#ifdef WITH_FREESTYLE
+                       for (a = SIMFACE_MATERIAL; a <= SIMFACE_FREESTYLE; a++) {
+#else
                        for (a = SIMFACE_MATERIAL; a <= SIMFACE_COPLANAR; a++) {
+#endif
                                RNA_enum_items_add_value(&item, &totitem, prop_similar_types, a);
                        }
                }
@@ -1162,7 +1181,7 @@ static void mouse_mesh_loop(bContext *C, const int mval[2], short extend, short
                                /* Select the face of eed which is the nearest of mouse. */
                                BMFace *f, *efa = NULL;
                                BMIter iterf;
-                               float best_dist = MAXFLOAT;
+                               float best_dist = FLT_MAX;
 
                                /* We can't be sure this has already been set... */
                                ED_view3d_init_mats_rv3d(vc.obedit, vc.rv3d);
@@ -1325,6 +1344,23 @@ static void edgetag_context_set(BMesh *bm, Scene *scene, BMEdge *e, int val)
                case EDGE_MODE_TAG_BEVEL:
                        BM_elem_float_data_set(&bm->edata, e, CD_BWEIGHT, (val) ? 1.0f : 0.0f);
                        break;
+#ifdef WITH_FREESTYLE
+               case EDGE_MODE_TAG_FREESTYLE:
+                       {
+                               FreestyleEdge *fed;
+
+                               if (!CustomData_has_layer(&bm->pdata, CD_FREESTYLE_FACE)) {
+                                       BM_data_layer_add(bm, &bm->pdata, CD_FREESTYLE_FACE);
+                               }
+
+                               fed = CustomData_bmesh_get(&bm->edata, e->head.data, CD_FREESTYLE_EDGE);
+                               if (!val)
+                                       fed->flag &= ~FREESTYLE_EDGE_MARK;
+                               else
+                                       fed->flag |= FREESTYLE_EDGE_MARK;
+                       }
+                       break;
+#endif
        }
 }
 
@@ -1341,6 +1377,14 @@ static int edgetag_context_check(Scene *scene, BMesh *bm, BMEdge *e)
                        return BM_elem_float_data_get(&bm->edata, e, CD_CREASE) ? TRUE : FALSE;
                case EDGE_MODE_TAG_BEVEL:
                        return BM_elem_float_data_get(&bm->edata, e, CD_BWEIGHT) ? TRUE : FALSE;
+#ifdef WITH_FREESTYLE
+               case EDGE_MODE_TAG_FREESTYLE:
+                       {
+                               FreestyleEdge *fed = CustomData_bmesh_get(&bm->edata, e->head.data, CD_FREESTYLE_EDGE);
+                               return (!fed) ? FALSE : (fed->flag & FREESTYLE_EDGE_MARK) ? TRUE : FALSE;
+                       }
+                       break;
+#endif
        }
        return 0;
 }
@@ -1510,6 +1554,11 @@ static int mouse_mesh_shortest_path_edge(ViewContext *vc)
                        case EDGE_MODE_TAG_BEVEL:
                                me->drawflag |= ME_DRAWBWEIGHTS;
                                break;
+#ifdef WITH_FREESTYLE
+                       case EDGE_MODE_TAG_FREESTYLE:
+                               me->drawflag |= ME_DRAW_FREESTYLE_EDGE;
+                               break;
+#endif
                }
                
                EDBM_update_generic(em, FALSE, FALSE);
@@ -2956,6 +3005,59 @@ void MESH_OT_select_random(wmOperatorType *ot)
        RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend the selection");
 }
 
+static int edbm_select_ungrouped_exec(bContext *C, wmOperator *op)
+{
+       Object *obedit = CTX_data_edit_object(C);
+       BMEditMesh *em = BMEdit_FromObject(obedit);
+       BMVert *eve;
+       BMIter iter;
+
+       if (!em->selectmode == SCE_SELECT_VERTEX) {
+               BKE_report(op->reports, RPT_ERROR, "Does not work out of vertex selection mode");
+               return OPERATOR_CANCELLED;
+       }
+
+       if (obedit->defbase.first == NULL) {
+               BKE_report(op->reports, RPT_ERROR, "No weights/vertex groups on object");
+               return OPERATOR_CANCELLED;
+       }
+
+       if (!RNA_boolean_get(op->ptr, "extend")) {
+               EDBM_flag_disable_all(em, BM_ELEM_SELECT);
+       }
+
+       BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
+               if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
+                       MDeformVert *dv = CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT);
+                       /* no dv or dv set with no weight */
+                       if (dv == NULL || (dv && dv->dw == NULL)) {
+                               BM_vert_select_set(em->bm, eve, true);
+                       }
+               }
+       }
+
+       WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
+
+       return OPERATOR_FINISHED;
+}
+
+void MESH_OT_select_ungrouped(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name = "Select Ungrouped";
+       ot->idname = "MESH_OT_select_ungrouped";
+       ot->description = "Select vertices without a group";
+
+       /* api callbacks */
+       ot->exec = edbm_select_ungrouped_exec;
+       ot->poll = ED_operator_editmesh;
+
+       /* flags */
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+       RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend the selection");
+}
+
 static int edbm_select_next_loop_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Object *obedit = CTX_data_edit_object(C);