[Bf-blender-cvs] [3e0a73e] GPencil_EditStrokes: Setting "select" property on GP Points via RNA now syncs the selection status with the stroke

Joshua Leung noreply at git.blender.org
Fri Oct 10 12:26:07 CEST 2014


Commit: 3e0a73e45af03026c0b4f0a3b69be8a1c091f074
Author: Joshua Leung
Date:   Fri Oct 10 19:45:19 2014 +1300
Branches: GPencil_EditStrokes
https://developer.blender.org/rB3e0a73e45af03026c0b4f0a3b69be8a1c091f074

Setting "select" property on GP Points via RNA now syncs the selection status with the stroke

This is a bit clumsy as RNA doesn't give us this info on a plate...

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

M	source/blender/editors/gpencil/gpencil_select.c
M	source/blender/makesrna/intern/rna_gpencil.c

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

diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c
index 96d066c..6875014 100644
--- a/source/blender/editors/gpencil/gpencil_select.c
+++ b/source/blender/editors/gpencil/gpencil_select.c
@@ -168,6 +168,7 @@ void GPENCIL_OT_select_all(wmOperatorType *ot)
 }
 
 /* ********************************************** */
+/* Circle Select Operator */
 
 /* Helper to check if a given stroke is within the area */
 /* NOTE: Code here is adapted (i.e. copied directly) from gpencil_paint.c::gp_stroke_eraser_dostroke()
diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c
index b1a7d1e..db9718e 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -115,6 +115,73 @@ static void rna_GPencilLayer_info_set(PointerRNA *ptr, const char *value)
 	BLI_uniquename(&gpd->layers, gpl, DATA_("GP_Layer"), '.', offsetof(bGPDlayer, info), sizeof(gpl->info));
 }
 
+
+static bGPDstroke *rna_GPencil_stroke_point_find_stroke(const bGPdata *gpd, const bGPDspoint *pt, bGPDlayer **r_gpl, bGPDframe **r_gpf)
+{
+	bGPDlayer *gpl;
+	bGPDstroke *gps;
+	
+	/* sanity checks */
+	if (ELEM(NULL, gpd, pt)) {
+		return NULL;
+	}
+	
+	if (r_gpl) *r_gpl = NULL;
+	if (r_gpf) *r_gpf = NULL;
+	
+	/* there's no faster alternative than just looping over everything... */
+	for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+		if (gpl->actframe) {
+			for (gps = gpl->actframe->strokes.first; gps; gps = gps->next) {
+				if ((pt >= gps->points) && (pt < &gps->points[gps->totpoints])) {
+					/* found it */
+					if (r_gpl) *r_gpl = gpl;
+					if (r_gpf) *r_gpf = gpl->actframe;
+					
+					return gps;
+				}
+			}
+		}
+	}
+	
+	/* didn't find it */
+	return NULL;
+}
+
+static void rna_GPencil_stroke_point_select_set(PointerRNA *ptr, const int value)
+{
+	bGPdata *gpd = ptr->id.data;
+	bGPDspoint *pt = ptr->data;
+	bGPDstroke *gps = NULL;
+	
+	/* Ensure that corresponding stroke is set 
+	 * - Since we don't have direct access, we're going to have to search
+	 * - We don't apply selection value unless we can find the corresponding
+	 *   stroke, so that they don't get out of sync
+	 */
+	gps = rna_GPencil_stroke_point_find_stroke(gpd, pt, NULL, NULL);
+	if (gps) {
+		bGPDspoint *spt;
+		int i;
+		
+		/* Set the new selection state for the point */
+		if (value)
+			pt->flag |= GP_SPOINT_SELECT;
+		else
+			pt->flag &= ~GP_SPOINT_SELECT;
+		
+		/* Check if the stroke should be selected or not... */
+		gps->flag &= ~GP_STROKE_SELECT;
+		
+		for (i = 0, spt = gps->points; i < gps->totpoints; i++, spt++) {
+			if (spt->flag & GP_SPOINT_SELECT) {
+				gps->flag |= GP_STROKE_SELECT;
+				break;
+			}
+		}
+	}
+}
+
 static void rna_GPencil_stroke_point_add(bGPDstroke *stroke, int count)
 {
 	if (count > 0) {
@@ -292,6 +359,7 @@ static void rna_def_gpencil_stroke_point(BlenderRNA *brna)
 	
 	prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_SPOINT_SELECT);
+	RNA_def_property_boolean_funcs(prop, NULL, "rna_GPencil_stroke_point_select_set");
 	RNA_def_property_ui_text(prop, "Select", "Point is selected for viewport editing");
 	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
 }




More information about the Bf-blender-cvs mailing list