[Bf-blender-cvs] [5c3dcad7f38] greasepencil-object: New Select Alternate operator

Antonio Vazquez noreply at git.blender.org
Mon Oct 16 12:34:39 CEST 2017


Commit: 5c3dcad7f38055295d50869f8bab99bb399e0f4f
Author: Antonio Vazquez
Date:   Mon Oct 16 12:33:51 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB5c3dcad7f38055295d50869f8bab99bb399e0f4f

New Select Alternate operator

This operator allows to select alternative points in a selected stroke. This can be useful to disolve or modify.

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

M	release/scripts/startup/bl_ui/properties_grease_pencil_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_grease_pencil_common.py b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
index 9b360736bbc..663c519c629 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -186,6 +186,7 @@ class GreasePencilStrokeEditPanel:
             col.operator("gpencil.select_linked")
             col.operator("gpencil.select_more")
             col.operator("gpencil.select_less")
+            col.operator("gpencil.select_alternate")
             col.operator("gpencil.palettecolor_select")
 
         layout.label(text="Edit:")
@@ -665,6 +666,7 @@ class GPENCIL_MT_pie_tool_palette(Menu):
                 col.operator("gpencil.select_border", text="Border Select", icon='BORDER_RECT')
                 col.operator("gpencil.select_circle", text="Circle Select", icon='META_EMPTY')
                 col.operator("gpencil.select_lasso", text="Lasso Select", icon='BORDER_LASSO')
+                col.operator("gpencil.select_alternate", text="Alternate Select", icon='BORDER_LASSO')
 
                 # SW - Edit Tools
                 col = pie.column()
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 6afef8f3e69..39b139c0d3f 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -1044,6 +1044,7 @@ 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("gpencil.select_alternate")
         layout.operator_menu_enum("gpencil.select_grouped", "type", text="Grouped")
 
         layout.separator()
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index 09d3dacf61b..915aaac8658 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -173,6 +173,7 @@ void GPENCIL_OT_select_more(struct wmOperatorType *ot);
 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_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 1970c318849..c4615ca7d07 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -194,6 +194,9 @@ static void ed_keymap_gpencil_selection(wmKeyMap *keymap)
 	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 alternate */
+	WM_keymap_add_item(keymap, "GPENCIL_OT_select_alternate", LKEY, KM_PRESS, KM_SHIFT, 0);
+
 	/* select grouped */
 	WM_keymap_add_item(keymap, "GPENCIL_OT_select_grouped", GKEY, KM_PRESS, KM_SHIFT, 0);
 
@@ -622,7 +625,8 @@ void ED_operatortypes_gpencil(void)
 	WM_operatortype_append(GPENCIL_OT_select_less);
 	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_duplicate);
 	WM_operatortype_append(GPENCIL_OT_delete);
 	WM_operatortype_append(GPENCIL_OT_dissolve);
diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c
index 0ab3b26a3ff..02b4ab93cbc 100644
--- a/source/blender/editors/gpencil/gpencil_select.c
+++ b/source/blender/editors/gpencil/gpencil_select.c
@@ -258,6 +258,81 @@ void GPENCIL_OT_select_linked(wmOperatorType *ot)
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
+/* ********************************************** */
+/* Select Alternate */
+
+static int gpencil_select_alternate_exec(bContext *C, wmOperator *op)
+{
+	const bool unselect_ends = RNA_boolean_get(op->ptr, "unselect_ends");
+	bGPdata *gpd = ED_gpencil_data_get_active(C);
+
+	if (gpd == NULL) {
+		BKE_report(op->reports, RPT_ERROR, "No Grease Pencil data");
+		return OPERATOR_CANCELLED;
+	}
+
+	/* if not edit/sculpt mode, the event is catched but not processed */
+	if (GPENCIL_NONE_EDIT_MODE(gpd)) {
+		return OPERATOR_CANCELLED;
+	}
+
+	/* select all points in selected strokes */
+	CTX_DATA_BEGIN(C, bGPDstroke *, gps, editable_gpencil_strokes)
+	{
+		if ((gps->flag & GP_STROKE_SELECT) && (gps->totpoints > 1)) {
+			bGPDspoint *pt;
+			int row = 0;
+			int start = 0;
+			if (unselect_ends) {
+				start = 1;
+			}
+			
+			for (int i = start; i < gps->totpoints; i++) {
+				pt = &gps->points[i];
+				if ((row % 2) == 0) {
+					pt->flag |= GP_SPOINT_SELECT;
+				}
+				else {
+					pt->flag &= ~GP_SPOINT_SELECT;
+				}
+				++row;
+			}
+
+			/* unselect start and end points */
+			if (unselect_ends) {
+				pt = &gps->points[0];
+				pt->flag &= ~GP_SPOINT_SELECT;
+
+				pt = &gps->points[gps->totpoints - 1];
+				pt->flag &= ~GP_SPOINT_SELECT;
+			}
+		}
+	}
+	CTX_DATA_END;
+
+	/* updates */
+	WM_event_add_notifier(C, NC_GPENCIL | NA_SELECTED, NULL);
+	return OPERATOR_FINISHED;
+}
+
+void GPENCIL_OT_select_alternate(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Alternate";
+	ot->idname = "GPENCIL_OT_select_alternate";
+	ot->description = "Select alternative points in same strokes as already selected points";
+
+	/* callbacks */
+	ot->exec = gpencil_select_alternate_exec;
+	ot->poll = gpencil_select_poll;
+
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+	/* properties */
+	RNA_def_boolean(ot->srna, "unselect_ends", true, "Unselect Ends", "Do not select the first and last point of the stroke");
+}
+
 /* ********************************************** */
 /* Select Grouped */



More information about the Bf-blender-cvs mailing list