[Bf-blender-cvs] [d5f3aee] master: Operator to duplicate the active Grease Pencil layer

Joshua Leung noreply at git.blender.org
Wed Dec 31 05:38:29 CET 2014


Commit: d5f3aee41fc78388e4f11e23647c6734e5b37ace
Author: Joshua Leung
Date:   Wed Dec 31 14:20:44 2014 +1300
Branches: master
https://developer.blender.org/rBd5f3aee41fc78388e4f11e23647c6734e5b37ace

Operator to duplicate the active Grease Pencil layer

TODO: this needs a proper "duplicate" icon, without the "ID" label

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

M	release/scripts/startup/bl_ui/properties_grease_pencil_common.py
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/release/scripts/startup/bl_ui/properties_grease_pencil_common.py b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
index 75f6921..6b4bccd 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -361,6 +361,8 @@ class GreasePencilDataPanel():
 
         gpl = context.active_gpencil_layer
         if gpl:
+            sub.operator("gpencil.layer_duplicate", icon='COPY_ID', text="") # XXX: needs a dedicated icon
+
             col.separator()
 
             sub = col.column(align=True)
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 1932126..a0a9419 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -219,6 +219,7 @@ bGPdata *ED_gpencil_data_get_active(const bContext *C)
 
 /* -------------------------------------------------------- */
 
+// XXX: this should be removed... We really shouldn't duplicate logic like this!
 bGPdata *ED_gpencil_data_get_active_v3d(Scene *scene, View3D *v3d)
 {
 	Base *base = scene->basact;
@@ -483,6 +484,47 @@ void GPENCIL_OT_layer_move(wmOperatorType *ot)
 	ot->prop = RNA_def_enum(ot->srna, "type", slot_move, 0, "Type", "");
 }
 
+/* ********************* Duplicate Layer ************************** */
+
+static int gp_layer_copy_exec(bContext *C, wmOperator *op)
+{
+	bGPdata *gpd = ED_gpencil_data_get_active(C);
+	bGPDlayer *gpl = gpencil_layer_getactive(gpd);
+	bGPDlayer *new_layer;
+	
+	/* sanity checks */
+	if (ELEM(NULL, gpd, gpl))
+		return OPERATOR_CANCELLED;
+	
+	/* make copy of layer, and add it immediately after the existing layer */
+	new_layer = gpencil_layer_duplicate(gpl);
+	BLI_insertlinkafter(&gpd->layers, gpl, new_layer);
+	
+	/* ensure new layer has a unique name, and is now the active layer */
+	BLI_uniquename(&gpd->layers, new_layer, DATA_("GP_Layer"), '.', offsetof(bGPDlayer, info), sizeof(new_layer->info));
+	gpencil_layer_setactive(gpd, new_layer);
+	
+	/* notifiers */
+	WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
+	
+	return OPERATOR_FINISHED;
+}
+
+void GPENCIL_OT_layer_duplicate(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Duplicate Layer";
+	ot->idname = "GPENCIL_OT_layer_duplicate";
+	ot->description = "Make a copy of the active Grease Pencil layer";
+	
+	/* callbacks */
+	ot->exec = gp_layer_copy_exec;
+	ot->poll = gp_active_layer_poll;
+	
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
 /* ************************************************ */
 /* Stroke Editing Operators */
 
@@ -630,6 +672,10 @@ void GPENCIL_OT_duplicate(wmOperatorType *ot)
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
+/* ******************* Copy/Paste Strokes ************************* */
+
+// TODO:
+
 /* ******************* 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 ce4a81c..3bf6355 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -134,6 +134,7 @@ void GPENCIL_OT_data_unlink(struct wmOperatorType *ot);
 void GPENCIL_OT_layer_add(struct wmOperatorType *ot);
 void GPENCIL_OT_layer_remove(struct wmOperatorType *ot);
 void GPENCIL_OT_layer_move(struct wmOperatorType *ot);
+void GPENCIL_OT_layer_duplicate(struct wmOperatorType *ot);
 
 void GPENCIL_OT_active_frame_delete(struct wmOperatorType *ot);
 
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index 02c354e..e477673 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -233,6 +233,7 @@ void ED_operatortypes_gpencil(void)
 	WM_operatortype_append(GPENCIL_OT_layer_add);
 	WM_operatortype_append(GPENCIL_OT_layer_remove);
 	WM_operatortype_append(GPENCIL_OT_layer_move);
+	WM_operatortype_append(GPENCIL_OT_layer_duplicate);
 	
 	WM_operatortype_append(GPENCIL_OT_active_frame_delete);




More information about the Bf-blender-cvs mailing list