[Bf-blender-cvs] [f08fdc0] GPencil_EditStrokes: GPencil - Added operator to copy selected strokes

Joshua Leung noreply at git.blender.org
Sun Sep 28 17:26:58 CEST 2014


Commit: f08fdc0b33de6ba200e869e9837cb420fc88cff1
Author: Joshua Leung
Date:   Sun Sep 28 16:37:27 2014 +1300
Branches: GPencil_EditStrokes
https://developer.blender.org/rBf08fdc0b33de6ba200e869e9837cb420fc88cff1

GPencil - Added operator to copy selected strokes

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

M	source/blender/editors/gpencil/gpencil_edit.c
M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_ops.c

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

diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 1333444..1275bb4 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -334,6 +334,78 @@ void GPENCIL_OT_layer_add(wmOperatorType *ot)
 	ot->poll = gp_add_poll;
 }
 
+/* ******************* Copy Selected Strokes *********************** */
+
+static int gp_strokes_copy_poll(bContext *C)
+{
+	bGPdata *gpd = ED_gpencil_data_get_active(C);
+	bGPDlayer *gpl = gpencil_layer_getactive(gpd);
+
+	/* only if there's an active layer with an active frame */
+	/* TODO: we probably require some selected strokes too? */
+	return (gpl && gpl->actframe);
+}
+
+static int gp_strokes_copy_exec(bContext *C, wmOperator *UNUSED(op))
+{
+	bGPdata *gpd = ED_gpencil_data_get_active(C);
+	bGPDlayer *gpl;
+	
+	/* for each visible (and editable) layer's selected strokes,
+	 * copy the strokes into a temporary buffer, then append
+	 * once all done
+	 */
+	for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+		if ((gpl->flag & (GP_LAYER_HIDE | GP_LAYER_LOCKED)) == 0 &&
+		    (gpl->actframe != NULL))
+		{
+			ListBase new_strokes = {NULL, NULL};
+			bGPDframe *gpf = gpl->actframe;
+			bGPDstroke *gps;
+			
+			/* make copies of selected strokes, and deselect these once we're done */
+			for (gps = gpf->strokes.first; gps; gps = gps->next) {
+				if (gps->flag & GP_STROKE_SELECT) {
+					/* make copy of stroke */
+					bGPDstroke *gpsd = MEM_dupallocN(gps);
+					gpsd->points = MEM_dupallocN(gps->points);
+					
+					BLI_addtail(&new_strokes, gpsd);
+					
+					/* deselect original stroke, or else the originals get moved too 
+					 * (when using the copy + move macro)
+					 */
+					gps->flag &= ~GP_STROKE_SELECT;
+				}
+			}
+			
+			/* add all new strokes in temp buffer to the frame (preventing double-copies) */
+			BLI_movelisttolist(&gpf->strokes, &new_strokes);
+			BLI_assert(new_strokes.first == NULL);
+		}
+	}
+	
+	/* updates */
+	WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
+	
+	return OPERATOR_FINISHED;
+}
+
+void GPENCIL_OT_strokes_copy(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Copy Strokes";
+	ot->idname = "GPENCIL_OT_strokes_copy";
+	ot->description = "Duplicate the selected Grease Pencil strokes";
+	
+	/* callbacks */
+	ot->exec = gp_strokes_copy_exec;
+	ot->poll = gp_strokes_copy_poll;
+	
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
 /* ******************* Delete Active Frame ************************ */
 
 static int gp_actframe_delete_poll(bContext *C)
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index 3b2ed2f..8b32b97 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -116,6 +116,8 @@ typedef enum eGPencil_PaintModes {
 void GPENCIL_OT_select_all(struct wmOperatorType *ot);
 void GPENCIL_OT_select_circle(struct wmOperatorType *ot);
 
+void GPENCIL_OT_strokes_copy(struct wmOperatorType *ot);
+
 /* buttons editing --- */
 
 void GPENCIL_OT_data_add(struct wmOperatorType *ot);
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index ea9e2ba..09b2ac9 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -81,6 +81,9 @@ void ED_keymap_gpencil(wmKeyConfig *keyconf)
 	
 	/* circle select */
 	WM_keymap_add_item(keymap, "GPENCIL_OT_select_circle", CKEY, KM_PRESS, 0, DKEY);
+	
+	/* Editing ----------------------------------------- */
+	WM_keymap_add_item(keymap, "GPENCIL_OT_strokes_copy", EKEY, KM_PRESS, 0, DKEY);
 }
 
 /* ****************************************** */
@@ -96,6 +99,8 @@ void ED_operatortypes_gpencil(void)
 	WM_operatortype_append(GPENCIL_OT_select_all);
 	WM_operatortype_append(GPENCIL_OT_select_circle);
 	
+	WM_operatortype_append(GPENCIL_OT_strokes_copy);
+	
 	/* Editing (Buttons) ------------ */
 	
 	WM_operatortype_append(GPENCIL_OT_data_add);




More information about the Bf-blender-cvs mailing list