Merged changes in the trunk up to revision 52690.
[blender.git] / source / blender / editors / mesh / editmesh_tools.c
index ad1077156baa9874da4ec31de41961930e38c66d..3ff33b79f556139e67249ab98f16c92a08405da8 100644 (file)
@@ -1271,11 +1271,11 @@ static int edbm_vert_connect(bContext *C, wmOperator *op)
        }
        else {
                EDBM_selectmode_flush(em);  /* so newly created edges get the selection state from the vertex */
+       
+       EDBM_update_generic(C, em, TRUE);
 
-               EDBM_update_generic(C, em, TRUE);
-
-               return len ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
-       }
+       return len ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
+}
 }
 
 void MESH_OT_vert_connect(wmOperatorType *ot)
@@ -5762,3 +5762,107 @@ void MESH_OT_symmetrize(struct wmOperatorType *ot)
                                BMO_SYMMETRIZE_NEGATIVE_X,
                                "Direction", "Which sides to copy from and to");
 }
+
+static int edbm_mark_freestyle_edge(bContext *C, wmOperator *op)
+{
+       Object *obedit = CTX_data_edit_object(C);
+       Mesh *me = ((Mesh *)obedit->data);
+       BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh;
+       BMEdge *eed;
+       BMIter iter;
+       int clear = RNA_boolean_get(op->ptr, "clear");
+
+       if (em == NULL) return OPERATOR_FINISHED;
+
+       /* auto-enable seams drawing */
+       if (clear == 0) {
+               me->drawflag |= ME_DRAW_FREESTYLE_EDGE;
+       }
+
+       if (clear) {
+               BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) {
+                       if (BM_elem_flag_test(eed, BM_ELEM_SELECT) && !BM_elem_flag_test(eed, BM_ELEM_HIDDEN))
+                               BM_elem_flag_disable(eed, BM_ELEM_FREESTYLE);
+               }
+       }
+       else {
+               BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) {
+                       if (BM_elem_flag_test(eed, BM_ELEM_SELECT) && !BM_elem_flag_test(eed, BM_ELEM_HIDDEN))
+                               BM_elem_flag_enable(eed, BM_ELEM_FREESTYLE);
+               }
+       }
+
+       DAG_id_tag_update(obedit->data, OB_RECALC_DATA);
+       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
+
+       return OPERATOR_FINISHED;
+}
+
+void MESH_OT_mark_freestyle_edge(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name = "Mark Freestyle Edge";
+       ot->description = "(un)mark selected edges as Freestyle feature edges";
+       ot->idname = "MESH_OT_mark_freestyle_edge";
+
+       /* api callbacks */
+       ot->exec = edbm_mark_freestyle_edge;
+       ot->poll = ED_operator_editmesh;
+
+       /* flags */
+       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       RNA_def_boolean(ot->srna, "clear", 0, "Clear", "");
+}
+
+static int edbm_mark_freestyle_face_exec(bContext *C, wmOperator *op)
+{
+       Object *obedit = CTX_data_edit_object(C);
+       Mesh *me = ((Mesh *)obedit->data);
+       BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh;
+       BMFace *efa;
+       BMIter iter;
+       int clear = RNA_boolean_get(op->ptr, "clear");
+
+       if (em == NULL) return OPERATOR_FINISHED;
+
+       /* auto-enable Freestyle face mark drawing */
+       if(!clear) {
+               me->drawflag |= ME_DRAW_FREESTYLE_FACE;
+       }
+
+       if(clear) {
+               BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
+                       if (BM_elem_flag_test(efa, BM_ELEM_SELECT) && !BM_elem_flag_test(efa, BM_ELEM_HIDDEN))
+                               BM_elem_flag_disable(efa, BM_ELEM_FREESTYLE);
+               }
+       } else {
+               BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
+                       if (BM_elem_flag_test(efa, BM_ELEM_SELECT) && !BM_elem_flag_test(efa, BM_ELEM_HIDDEN))
+                               BM_elem_flag_enable(efa, BM_ELEM_FREESTYLE);
+               }
+       }
+
+       DAG_id_tag_update(obedit->data, OB_RECALC_DATA);
+       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
+
+       return OPERATOR_FINISHED;
+}
+
+void MESH_OT_mark_freestyle_face(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name = "Mark Freestyle Face";
+       ot->description = "(un)mark selected faces for exclusion from Freestyle feature edge detection";
+       ot->idname = "MESH_OT_mark_freestyle_face";
+
+       /* api callbacks */
+       ot->exec = edbm_mark_freestyle_face_exec;
+       ot->poll = ED_operator_editmesh;
+
+       /* flags */
+       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       RNA_def_boolean(ot->srna, "clear", 0, "Clear", "");
+}
+