Merged changes in the trunk up to revision 46045.
[blender-staging.git] / source / blender / editors / mesh / editmesh_tools.c
index 7eae8b4d67e2e508b5811e3af8f4054a8585106f..e3916d0aa51570d7a1d8713e9061f16ed3abcf5e 100644 (file)
@@ -4266,3 +4266,106 @@ void MESH_OT_inset(wmOperatorType *ot)
        RNA_def_boolean(ot->srna, "use_select_inset", TRUE, "Select Outer", "Select the new inset faces");
 }
 
+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", "");
+}
+