[Bf-blender-cvs] [2ab1485cb57] greasepencil-object: GPencil: New Select by Color operator

Antonio Vazquez noreply at git.blender.org
Sat Nov 9 12:09:51 CET 2019


Commit: 2ab1485cb5739dc1b69d569643725d0f9230bcc3
Author: Antonio Vazquez
Date:   Sat Nov 9 11:53:12 2019 +0100
Branches: greasepencil-object
https://developer.blender.org/rB2ab1485cb5739dc1b69d569643725d0f9230bcc3

GPencil: New Select by Color operator

===================================================================

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

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_paint_common.py b/release/scripts/startup/bl_ui/properties_paint_common.py
index b7ea36717ac..3d81662affe 100644
--- a/release/scripts/startup/bl_ui/properties_paint_common.py
+++ b/release/scripts/startup/bl_ui/properties_paint_common.py
@@ -501,15 +501,15 @@ def brush_basic_gpencil_vertex_settings(layout, _context, brush, tool, *, compac
     gp_settings = brush.gpencil_settings
 
     # Brush details
+    row = layout.row(align=True)
+    row.prop(brush, "size", text="Radius")
+    row.prop(gp_settings, "use_pressure", text="", icon='STYLUS_PRESSURE')
+
     if brush.gpencil_vertex_tool == 'DRAW':
-        row = layout.row(align=True)
-        row.prop(brush, "size", text="Radius")
-        row.prop(gp_settings, "use_pressure", text="", icon='STYLUS_PRESSURE')
         row = layout.row(align=True)
         row.prop(gp_settings, "pen_strength", slider=True)
         row.prop(gp_settings, "use_strength_pressure", text="", icon='STYLUS_PRESSURE')
 
-
 classes = (
     VIEW3D_MT_tools_projectpaint_clone,
 )
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 346bce38bf2..ef810cca0b3 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -833,6 +833,8 @@ class VIEW3D_MT_editor_menus(Menu):
                 layout.menu("VIEW3D_MT_edit_gpencil_point")
             elif obj and obj.mode == 'WEIGHT_GPENCIL':
                 layout.menu("VIEW3D_MT_weight_gpencil")
+            elif obj and obj.mode == 'VERTEX_GPENCIL':
+                layout.menu("VIEW3D_MT_vertex_gpencil")
 
         elif edit_object:
             layout.menu("VIEW3D_MT_edit_%s" % edit_object.type.lower())
@@ -4715,6 +4717,15 @@ class VIEW3D_MT_weight_gpencil(Menu):
         layout.menu("VIEW3D_MT_gpencil_autoweights")
 
 
+class VIEW3D_MT_vertex_gpencil(Menu):
+    bl_label = "Vertex Paint"
+
+    def draw(self, _context):
+        layout = self.layout
+
+        layout.operator("gpencil.select_color", text="Select Color")
+
+
 class VIEW3D_MT_gpencil_animation(Menu):
     bl_label = "Animation"
 
@@ -6923,6 +6934,7 @@ classes = (
     VIEW3D_MT_edit_gpencil_delete,
     VIEW3D_MT_edit_gpencil_showhide,
     VIEW3D_MT_weight_gpencil,
+    VIEW3D_MT_vertex_gpencil,
     VIEW3D_MT_gpencil_animation,
     VIEW3D_MT_gpencil_simplify,
     VIEW3D_MT_gpencil_copy_layer,
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index c63ff173261..e7efe1998fa 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -406,6 +406,7 @@ void GPENCIL_OT_select_less(struct wmOperatorType *ot);
 void GPENCIL_OT_select_first(struct wmOperatorType *ot);
 void GPENCIL_OT_select_last(struct wmOperatorType *ot);
 void GPENCIL_OT_select_alternate(struct wmOperatorType *ot);
+void GPENCIL_OT_select_color(struct wmOperatorType *ot);
 
 void GPENCIL_OT_duplicate(struct wmOperatorType *ot);
 void GPENCIL_OT_delete(struct wmOperatorType *ot);
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index f5b530161e6..b0e348be277 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -376,6 +376,7 @@ void ED_operatortypes_gpencil(void)
   WM_operatortype_append(GPENCIL_OT_select_first);
   WM_operatortype_append(GPENCIL_OT_select_last);
   WM_operatortype_append(GPENCIL_OT_select_alternate);
+  WM_operatortype_append(GPENCIL_OT_select_color);
 
   WM_operatortype_append(GPENCIL_OT_duplicate);
   WM_operatortype_append(GPENCIL_OT_delete);
diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c
index f38961db07b..9800869ba53 100644
--- a/source/blender/editors/gpencil/gpencil_select.c
+++ b/source/blender/editors/gpencil/gpencil_select.c
@@ -1655,4 +1655,99 @@ void GPENCIL_OT_select(wmOperatorType *ot)
   RNA_def_property_flag(prop, PROP_HIDDEN);
 }
 
+/* Select by Vertex Color. */
+static bool gpencil_select_color_poll(bContext *C)
+{
+  ToolSettings *ts = CTX_data_tool_settings(C);
+  Object *ob = CTX_data_active_object(C);
+  if ((ob == NULL) || (ob->type != OB_GPENCIL)) {
+    return false;
+  }
+  bGPdata *gpd = (bGPdata *)ob->data;
+
+  if (GPENCIL_VERTEX_MODE(gpd)) {
+    if (!(GPENCIL_ANY_VERTEX_MASK(ts->gpencil_selectmode_vertex))) {
+      return false;
+    }
+
+    /* Any data to use. */
+    if (gpd->layers.first) {
+      return true;
+    }
+  }
+
+  return false;
+}
+
+static int gpencil_select_color_exec(bContext *C, wmOperator *op)
+{
+  const float threshold = RNA_float_get(op->ptr, "threshold");
+
+  ToolSettings *ts = CTX_data_tool_settings(C);
+  Object *ob = CTX_data_active_object(C);
+  bGPdata *gpd = (bGPdata *)ob->data;
+  if (!GPENCIL_VERTEX_MODE(gpd)) {
+    return OPERATOR_CANCELLED;
+  }
+
+  Paint *paint = &ts->gp_vertexpaint->paint;
+  Brush *brush = paint->brush;
+  bool done = false;
+
+  /* Select any visible stroke that uses this color */
+  CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) {
+    bGPDspoint *pt;
+    int i;
+    bool gps_selected = false;
+    /* Check all stroke points. */
+    for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
+      if (compare_v3v3(pt->mix_color, brush->rgb, threshold)) {
+        pt->flag |= GP_SPOINT_SELECT;
+        gps_selected = true;
+      }
+    }
+
+    if (gps_selected) {
+      gps->flag |= GP_STROKE_SELECT;
+      done = true;
+    }
+  }
+  CTX_DATA_END;
+
+  if (done) {
+    /* updates */
+    DEG_id_tag_update(&gpd->id, ID_RECALC_GEOMETRY);
+
+    /* copy on write tag is needed, or else no refresh happens */
+    DEG_id_tag_update(&gpd->id, ID_RECALC_COPY_ON_WRITE);
+
+    WM_event_add_notifier(C, NC_GPENCIL | NA_SELECTED, NULL);
+    WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL);
+  }
+
+  return OPERATOR_FINISHED;
+}
+
+void GPENCIL_OT_select_color(wmOperatorType *ot)
+{
+  PropertyRNA *prop;
+
+  /* identifiers */
+  ot->name = "Select Color";
+  ot->idname = "GPENCIL_OT_select_color";
+  ot->description = "Select all strokes with same color";
+
+  /* callbacks */
+  ot->exec = gpencil_select_color_exec;
+  ot->poll = gpencil_select_color_poll;
+
+  /* flags */
+  ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+  /* properties */
+  prop = RNA_def_float(ot->srna, "threshold", 0.01f, 0.0f, 1.0f, "Threshold", "", 0.0f, 1.0f);
+  /* avoid re-using last var */
+  RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+}
+
 /** \} */



More information about the Bf-blender-cvs mailing list