GPencil: Select Grouped (Shift G)
authorJoshua Leung <aligorith@gmail.com>
Fri, 22 Jan 2016 02:31:20 +0000 (15:31 +1300)
committerJoshua Leung <aligorith@gmail.com>
Fri, 22 Jan 2016 02:31:42 +0000 (15:31 +1300)
This commit adds a "Select Grouped" operator. Although it is set up to
allow more types of "grouping" in future, it current only supports
a single mode (i.e. "Same Layer"). As a result, it does not pop up
any menus/submenus in all the usual places.

release/scripts/startup/bl_ui/space_view3d.py
source/blender/editors/gpencil/gpencil_intern.h
source/blender/editors/gpencil/gpencil_ops.c
source/blender/editors/gpencil/gpencil_select.c

index 0c41675658f03a2ad7a6f5a96165ce2db7b42c7a..808909a38852f2648fb5c7802b13242f9e1abbcd 100644 (file)
@@ -983,6 +983,8 @@ class VIEW3D_MT_select_gpencil(Menu):
         layout.operator("gpencil.select_all", text="(De)select All").action = 'TOGGLE'
         layout.operator("gpencil.select_all", text="Inverse").action = 'INVERT'
         layout.operator("gpencil.select_linked", text="Linked")
+        #layout.operator_menu_enum("gpencil.select_grouped", "type", text="Grouped")
+        layout.operator("gpencil.select_grouped", text="Grouped")
 
         layout.separator()
 
index d9a6441c00e9b5458bc968a0067afb9723abc98c..45dfb36b9d947f858d559a177a492b3e52605545 100644 (file)
@@ -157,6 +157,7 @@ void GPENCIL_OT_select_border(struct wmOperatorType *ot);
 void GPENCIL_OT_select_lasso(struct wmOperatorType *ot);
 
 void GPENCIL_OT_select_linked(struct wmOperatorType *ot);
+void GPENCIL_OT_select_grouped(struct wmOperatorType *ot);
 void GPENCIL_OT_select_more(struct wmOperatorType *ot);
 void GPENCIL_OT_select_less(struct wmOperatorType *ot);
 
index 25012ab6d64c44fbd30754cc9faf314827b73323..9f5633ae6685bf2f891bd75876cfce1a469ad88c 100644 (file)
@@ -176,11 +176,13 @@ static void ed_keymap_gpencil_editing(wmKeyConfig *keyconf)
        WM_keymap_add_item(keymap, "GPENCIL_OT_select_linked", LKEY, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "GPENCIL_OT_select_linked", LKEY, KM_PRESS, KM_CTRL, 0);
        
+       /* select grouped */
+       WM_keymap_add_item(keymap, "GPENCIL_OT_select_grouped", GKEY, KM_PRESS, KM_SHIFT, 0);
+               
        /* select more/less */
        WM_keymap_add_item(keymap, "GPENCIL_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
        WM_keymap_add_item(keymap, "GPENCIL_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0);
        
-       
        /* Editing ----------------------------------------- */
        
        /* duplicate and move selected points */
@@ -309,6 +311,7 @@ void ED_operatortypes_gpencil(void)
        WM_operatortype_append(GPENCIL_OT_select_lasso);
        
        WM_operatortype_append(GPENCIL_OT_select_linked);
+       WM_operatortype_append(GPENCIL_OT_select_grouped);
        WM_operatortype_append(GPENCIL_OT_select_more);
        WM_operatortype_append(GPENCIL_OT_select_less);
        
index 83a1f2458ebb48e7e037de1b1830595292650390..0a36df471f17c3e3dfb323207fbe38df49441125 100644 (file)
@@ -41,6 +41,7 @@
 #include "BLI_math_vector.h"
 
 #include "DNA_gpencil_types.h"
+#include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
 
 #include "BKE_context.h"
@@ -244,6 +245,109 @@ void GPENCIL_OT_select_linked(wmOperatorType *ot)
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
+/* ********************************************** */
+/* Select Grouped */
+
+typedef enum eGP_SelectGrouped {
+       /* Select strokes in the same layer */
+       GP_SEL_SAME_LAYER     = 0,
+       
+       /* TODO: All with same prefix - Useful for isolating all layers for a particular character for instance */
+       /* TODO: All with same appearance - colour/opacity/volumetric/fills ? */
+} eGP_SelectGrouped;
+
+/* ----------------------------------- */
+
+/* On each visible layer, check for selected strokes - if found, select all others */
+static void gp_select_same_layer(bContext *C)
+{
+       Scene *scene = CTX_data_scene(C);
+       
+       CTX_DATA_BEGIN(C, bGPDlayer *, gpl, editable_gpencil_layers)
+       {
+               bGPDframe *gpf = gpencil_layer_getframe(gpl, CFRA, 0);
+               bGPDstroke *gps;
+               bool found = false;
+               
+               if (gpf == NULL)
+                       continue;
+               
+               /* Search for a selected stroke */
+               for (gps = gpf->strokes.first; gps; gps = gps->next) {
+                       if (ED_gpencil_stroke_can_use(C, gps)) {
+                               if (gps->flag & GP_STROKE_SELECT) {
+                                       found = true;
+                                       break;
+                               }
+                       }
+               }
+               
+               /* Select all if found */
+               if (found) {
+                       for (gps = gpf->strokes.first; gps; gps = gps->next) {
+                               if (ED_gpencil_stroke_can_use(C, gps)) {
+                                       bGPDspoint *pt;
+                                       int i;
+                                       
+                                       for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
+                                               pt->flag |= GP_SPOINT_SELECT;
+                                       }
+                                       
+                                       gps->flag |= GP_STROKE_SELECT;
+                               }
+                       }
+               }
+       }
+       CTX_DATA_END;
+}
+
+
+
+/* ----------------------------------- */
+
+static int gpencil_select_grouped_exec(bContext *C, wmOperator *op)
+{
+       eGP_SelectGrouped mode = RNA_enum_get(op->ptr, "type");
+       
+       switch (mode) {
+               case GP_SEL_SAME_LAYER:
+                       gp_select_same_layer(C);
+                       break;
+                       
+               default:
+                       BLI_assert(!"unhandled select grouped gpencil mode");
+                       break;
+       }
+       
+       /* updates */
+       WM_event_add_notifier(C, NC_GPENCIL | NA_SELECTED, NULL);
+       return OPERATOR_FINISHED;
+}
+
+void GPENCIL_OT_select_grouped(wmOperatorType *ot)
+{
+       static EnumPropertyItem prop_select_grouped_types[] = {
+               {GP_SEL_SAME_LAYER, "LAYER", 0, "Layer", "Shared layers"},
+               {0, NULL, 0, NULL, NULL}
+       };
+       
+       /* identifiers */
+       ot->name = "Select Grouped";
+       ot->idname = "GPENCIL_OT_select_grouped";
+       ot->description = "Select all strokes with similar characteristics";
+       
+       /* callbacks */
+       //ot->invoke = WM_menu_invoke;
+       ot->exec = gpencil_select_grouped_exec;
+       ot->poll = gpencil_select_poll;
+       
+       /* flags */
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+       
+       /* props */
+       ot->prop = RNA_def_enum(ot->srna, "type", prop_select_grouped_types, GP_SEL_SAME_LAYER, "Type", "");
+}
+
 /* ********************************************** */
 /* Select More */