Merged changes in the trunk up to revision 54992.
[blender-staging.git] / source / blender / editors / mesh / editmesh_tools.c
index 9d58e91b744cc131bc920b9aea8e52bf767c9403..92e1dbf433f69bc5dc8ce67bf517e691ac0ce0f1 100644 (file)
@@ -5599,3 +5599,109 @@ void MESH_OT_symmetrize(struct wmOperatorType *ot)
                                BMO_SYMMETRIZE_NEGATIVE_X,
                                "Direction", "Which sides to copy from and to");
 }
+
+#ifdef WITH_FREESTYLE
+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", "");
+}
+#endif
\ No newline at end of file