Option not to select with un-hide
[blender.git] / source / blender / editors / gpencil / gpencil_data.c
index 7dcbe2cc24c954f0953f33795037650b674844bf..5bd5c9c74b96b98727c5ef1f53a0482f1798a6c0 100644 (file)
@@ -42,6 +42,7 @@
 #include "BLI_utildefines.h"
 #include "BLI_ghash.h"
 #include "BLI_math.h"
+#include "BLI_string_utils.h"
 
 #include "BLT_translation.h"
 
@@ -84,7 +85,8 @@
 static int gp_data_add_exec(bContext *C, wmOperator *op)
 {
        bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, NULL);
-       
+       ToolSettings *ts = CTX_data_tool_settings(C);
+
        if (gpd_ptr == NULL) {
                BKE_report(op->reports, RPT_ERROR, "Nowhere for grease pencil data to go");
                return OPERATOR_CANCELLED;
@@ -95,6 +97,15 @@ static int gp_data_add_exec(bContext *C, wmOperator *op)
                
                id_us_min(&gpd->id);
                *gpd_ptr = BKE_gpencil_data_addnew(DATA_("GPencil"));
+
+               /* if not exist brushes, create a new set */
+               if (ts) {
+                       if (BLI_listbase_is_empty(&ts->gp_brushes)) {
+                               /* create new brushes */
+                               BKE_gpencil_brush_init_presets(ts);
+                       }
+               }
+
        }
        
        /* notifiers */
@@ -174,7 +185,8 @@ void GPENCIL_OT_data_unlink(wmOperatorType *ot)
 static int gp_layer_add_exec(bContext *C, wmOperator *op)
 {
        bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, NULL);
-       
+       ToolSettings *ts = CTX_data_tool_settings(C);
+
        /* if there's no existing Grease-Pencil data there, add some */
        if (gpd_ptr == NULL) {
                BKE_report(op->reports, RPT_ERROR, "Nowhere for grease pencil data to go");
@@ -183,6 +195,14 @@ static int gp_layer_add_exec(bContext *C, wmOperator *op)
        if (*gpd_ptr == NULL)
                *gpd_ptr = BKE_gpencil_data_addnew(DATA_("GPencil"));
        
+       /* if not exist brushes, create a new set */
+       if (ts) {
+               if (BLI_listbase_is_empty(&ts->gp_brushes)) {
+                       /* create new brushes */
+                       BKE_gpencil_brush_init_presets(ts);
+               }
+       }
+
        /* add new layer now */
        BKE_gpencil_layer_addnew(*gpd_ptr, DATA_("GP_Layer"), true);
        
@@ -282,7 +302,7 @@ static int gp_layer_move_exec(bContext *C, wmOperator *op)
 
 void GPENCIL_OT_layer_move(wmOperatorType *ot)
 {
-       static EnumPropertyItem slot_move[] = {
+       static const EnumPropertyItem slot_move[] = {
                {GP_LAYER_MOVE_UP, "UP", 0, "Up", ""},
                {GP_LAYER_MOVE_DOWN, "DOWN", 0, "Down", ""},
                {0, NULL, 0, NULL, NULL}
@@ -403,18 +423,59 @@ static int gp_reveal_poll(bContext *C)
        return ED_gpencil_data_get_active(C) != NULL;
 }
 
-static int gp_reveal_exec(bContext *C, wmOperator *UNUSED(op))
+static void gp_reveal_select_frame(bContext *C, bGPDframe *frame, bool select)
+{
+       bGPDstroke *gps;
+       for (gps = frame->strokes.first; gps; gps = gps->next) {
+
+               /* only deselect strokes that are valid in this view */
+               if (ED_gpencil_stroke_can_use(C, gps)) {
+
+                       /* (de)select points */
+                       int i;
+                       bGPDspoint *pt;
+                       for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
+                               SET_FLAG_FROM_TEST(pt->flag, select, GP_SPOINT_SELECT);
+                       }
+
+                       /* (de)select stroke */
+                       SET_FLAG_FROM_TEST(gps->flag, select, GP_STROKE_SELECT);
+               }
+       }
+}
+
+static int gp_reveal_exec(bContext *C, wmOperator *op)
 {
        bGPdata *gpd = ED_gpencil_data_get_active(C);
        bGPDlayer *gpl;
-       
+       const bool select = RNA_boolean_get(op->ptr, "select");
+
        /* sanity checks */
        if (gpd == NULL)
                return OPERATOR_CANCELLED;
        
-       /* make all layers visible */
        for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
-               gpl->flag &= ~GP_LAYER_HIDE;
+
+               if (gpl->flag & GP_LAYER_HIDE) {
+                       gpl->flag &= ~GP_LAYER_HIDE;
+
+                       /* select or deselect if requested, only on hidden layers */
+                       if (gpd->flag & GP_DATA_STROKE_EDITMODE) {
+                               if (select) {
+                                       /* select all strokes on active frame only (same as select all operator) */
+                                       if (gpl->actframe) {
+                                               gp_reveal_select_frame(C, gpl->actframe, true);
+                                       }
+                               }
+                               else {
+                                       /* deselect strokes on all frames (same as deselect all operator) */
+                                       bGPDframe *gpf;
+                                       for (gpf = gpl->frames.first; gpf; gpf = gpf->next) {
+                                               gp_reveal_select_frame(C, gpf, false);
+                                       }
+                               }
+                       }
+               }
        }
        
        /* notifiers */
@@ -436,6 +497,9 @@ void GPENCIL_OT_reveal(wmOperatorType *ot)
        
        /* flags */
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+       /* props */
+       RNA_def_boolean(ot->srna, "select", true, "Select", "");
 }
 
 /* ***************** Lock/Unlock All Layers ************************ */
@@ -811,7 +875,7 @@ static int gp_stroke_arrange_exec(bContext *C, wmOperator *op)
 
 void GPENCIL_OT_stroke_arrange(wmOperatorType *ot)
 {
-       static EnumPropertyItem slot_move[] = {
+       static const EnumPropertyItem slot_move[] = {
                {GP_STROKE_MOVE_UP, "UP", 0, "Bring Forward", ""},
                {GP_STROKE_MOVE_DOWN, "DOWN", 0, "Send Backward", ""},
                {GP_STROKE_MOVE_TOP, "TOP", 0, "Bring to Front", ""},
@@ -1145,7 +1209,7 @@ static int gp_brush_move_exec(bContext *C, wmOperator *op)
 
 void GPENCIL_OT_brush_move(wmOperatorType *ot)
 {
-       static EnumPropertyItem slot_move[] = {
+       static const EnumPropertyItem slot_move[] = {
                {GP_BRUSH_MOVE_UP, "UP", 0, "Up", ""},
                {GP_BRUSH_MOVE_DOWN, "DOWN", 0, "Down", ""},
                {0, NULL, 0, NULL, NULL }
@@ -1902,7 +1966,7 @@ static int gp_palettecolor_move_exec(bContext *C, wmOperator *op)
 
 void GPENCIL_OT_palettecolor_move(wmOperatorType *ot)
 {
-       static EnumPropertyItem slot_move[] = {
+       static const EnumPropertyItem slot_move[] = {
                {GP_COLOR_MOVE_UP, "UP", 0, "Up", ""},
                {GP_COLOR_MOVE_DOWN, "DOWN", 0, "Down", ""},
                {0, NULL, 0, NULL, NULL}