Merged changes in the trunk up to revision 44039.
[blender-staging.git] / source / blender / editors / mesh / editmesh_mods.c
index 0f374e04378da46828064742ab89146fe1391a3f..d7ec83e64e362a5a24a5053fff35d15a5740bcee 100644 (file)
@@ -700,6 +700,7 @@ static int unified_findnearest(ViewContext *vc, EditVert **eve, EditEdge **eed,
 #define SIMEDGE_SEAM           106
 #define SIMEDGE_SHARP          107
 #define SIMEDGE_TOT                    108
+#define SIMEDGE_FREESTYLE      109
 
 /* FACE GROUP */
 
@@ -722,6 +723,7 @@ static EnumPropertyItem prop_similar_types[] = {
        {SIMEDGE_CREASE, "CREASE", 0, "Crease", ""},
        {SIMEDGE_SEAM, "SEAM", 0, "Seam", ""},
        {SIMEDGE_SHARP, "SHARP", 0, "Sharpness", ""},
+       {SIMEDGE_FREESTYLE, "FREESTYLE", 0, "Freestyle Edge Mark", ""},
        {SIMFACE_MATERIAL, "MATERIAL", 0, "Material", ""},
        {SIMFACE_IMAGE, "IMAGE", 0, "Image", ""},
        {SIMFACE_AREA, "AREA", 0, "Area", ""},
@@ -1072,6 +1074,20 @@ static int similar_edge_select__internal(EditMesh *em, int mode, float thresh)
                                                        return selcount;
                                        }
                                }
+                       } else if (mode==SIMEDGE_FREESTYLE) { /* Freestyle edge mark */
+                               for(eed= em->edges.first; eed; eed= eed->next) {
+                                       if (
+                                               !(eed->f & SELECT) &&
+                                               !eed->h &&
+                                               (eed->freestyle == base_eed->freestyle)
+                                       ) {
+                                               EM_select_edge(eed, 1);
+                                               selcount++;
+                                               deselcount--;
+                                               if (!deselcount) /*have we selected all posible faces?, if so return*/
+                                                       return selcount;
+                                       }
+                               }
                        }
                }
        }       
@@ -2213,6 +2229,9 @@ static void mouse_mesh_shortest_path(bContext *C, const int mval[2])
                        case EDGE_MODE_TAG_BEVEL:
                                me->drawflag |= ME_DRAWBWEIGHTS;
                                break;
+                       case EDGE_MODE_TAG_FREESTYLE:
+                               me->drawflag |= ME_DRAW_FREESTYLE_EDGE;
+                               break;
                }
 
                /* live unwrap while tagging */
@@ -3829,6 +3848,58 @@ void MESH_OT_mark_sharp(wmOperatorType *ot)
        RNA_def_boolean(ot->srna, "clear", 0, "Clear", "");
 }
 
+static int editmesh_mark_freestyle_edge(bContext *C, wmOperator *op)
+{
+       Object *obedit= CTX_data_edit_object(C);
+       EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
+       Mesh *me= ((Mesh *)obedit->data);
+       int clear = RNA_boolean_get(op->ptr, "clear");
+       EditEdge *eed;
+
+       /* auto-enable Freestyle edge mark drawing */
+       if(!clear) {
+               me->drawflag |= ME_DRAW_FREESTYLE_EDGE;
+       }
+
+       if(!clear) {
+               eed= em->edges.first;
+               while(eed) {
+                       if(!eed->h && (eed->f & SELECT)) eed->freestyle = 1;
+                       eed = eed->next;
+               }
+       } else {
+               eed= em->edges.first;
+               while(eed) {
+                       if(!eed->h && (eed->f & SELECT)) eed->freestyle = 0;
+                       eed = eed->next;
+               }
+       }
+
+       BKE_mesh_end_editmesh(obedit->data, em);
+
+       DAG_id_tag_update(obedit->data, 0);
+       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= editmesh_mark_freestyle_edge;
+       ot->poll= ED_operator_editmesh;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       RNA_def_boolean(ot->srna, "clear", 0, "Clear", "");
+}
+
 /* **************** NORMALS ************** */
 
 void EM_recalc_normal_direction(EditMesh *em, int inside, int select)  /* makes faces righthand turning */