[Bf-blender-cvs] [9521de5583a] greasepencil-object: Fix: Ensure correct names when using the "New Layer" operator for GP Object and Annotations

Joshua Leung noreply at git.blender.org
Mon Jul 2 16:02:37 CEST 2018


Commit: 9521de5583aa76b705f661e75b5b28b111d85855
Author: Joshua Leung
Date:   Tue Jul 3 01:41:09 2018 +1200
Branches: greasepencil-object
https://developer.blender.org/rB9521de5583aa76b705f661e75b5b28b111d85855

Fix: Ensure correct names when using the "New Layer" operator for GP Object and Annotations

This replaces what 7931a1357a0f93ac0d7b8e6a564faa0b735a96ff
tried to do.  We may still need to make these separate operators
to simplify things even further.

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

M	source/blender/editors/gpencil/gpencil_data.c
M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/editors/include/ED_gpencil.h

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

diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c
index 2676107bc21..11f2f5e3458 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -198,23 +198,42 @@ void GPENCIL_OT_data_unlink(wmOperatorType *ot)
 /* add new layer - wrapper around API */
 static int gp_layer_add_exec(bContext *C, wmOperator *op)
 {
-	bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, NULL);
+	PointerRNA gpd_owner = {{NULL}};
+	bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, &gpd_owner);
+	bool is_annotation = false;
 
 	/* if there's no existing Grease-Pencil data there, add some */
 	if (gpd_ptr == NULL) {
 		BKE_report(op->reports, RPT_ERROR, "Nowhere for grease pencil data to go");
 		return OPERATOR_CANCELLED;
 	}
+	else {
+		is_annotation = ED_gpencil_data_owner_is_annotation(&gpd_owner);
+	}
+
 	if (*gpd_ptr == NULL) {
 		Main *bmain = CTX_data_main(C);
-		*gpd_ptr = BKE_gpencil_data_addnew(bmain, DATA_("GPencil"));
-	}
+		if (is_annotation) {
+			/* Annotations */
+			*gpd_ptr = BKE_gpencil_data_addnew(bmain, DATA_("Notes"));
+		}
+		else {
+			/* GP Object */
+			/* NOTE: This shouldn't actually happen in practice */
+			*gpd_ptr = BKE_gpencil_data_addnew(bmain, DATA_("GPencil"));
 
-	/* add default sets of colors and brushes */
-	ED_gpencil_add_defaults(C);
+			/* add default sets of colors and brushes */
+			ED_gpencil_add_defaults(C);
+		}
+	}
 
 	/* add new layer now */
-	BKE_gpencil_layer_addnew(*gpd_ptr, DATA_("GP_Layer"), true);
+	if (is_annotation) {
+		BKE_gpencil_layer_addnew(*gpd_ptr, DATA_("Note"), true);
+	}
+	else {
+		BKE_gpencil_layer_addnew(*gpd_ptr, DATA_("GP_Layer"), true);
+	}
 
 	/* notifiers */
 	WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
@@ -227,7 +246,7 @@ void GPENCIL_OT_layer_add(wmOperatorType *ot)
 	/* identifiers */
 	ot->name = "Add New Layer";
 	ot->idname = "GPENCIL_OT_layer_add";
-	ot->description = "Add new Grease Pencil layer for the active Grease Pencil data-block";
+	ot->description = "Add new layer or note for the active data-block";
 
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index af6e45bc114..c305f05fca1 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -247,6 +247,20 @@ bGPdata *ED_gpencil_data_get_active_evaluated(const bContext *C)
 
 /* -------------------------------------------------------- */
 
+/**
+ * Utility to check whether the r_ptr output of ED_gpencil_data_get_pointers()
+ * is for annotation usage.
+ */
+bool ED_gpencil_data_owner_is_annotation(PointerRNA *owner_ptr)
+{
+	/* Key Assumption: If the pointer is an object, we're dealing with a GP Object's data.
+	 * Otherwise, the GP datablock is being used for annotations (i.e. everywhere else)
+	 */
+	return ((owner_ptr) && (owner_ptr->type != &RNA_Object));
+}
+
+/* -------------------------------------------------------- */
+
 // XXX: this should be removed... We really shouldn't duplicate logic like this!
 bGPdata *ED_gpencil_data_get_active_v3d(ViewLayer *view_layer)
 {
@@ -259,8 +273,6 @@ bGPdata *ED_gpencil_data_get_active_v3d(ViewLayer *view_layer)
 	if (base && TESTBASE(base)) {
 		if (base->object->type == OB_GPENCIL)
 			gpd = base->object->data;
-		else
-			gpd = base->object->gpd;
 	}
 	return gpd ? gpd : NULL;
 }
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index b324b6a927a..91d6385ee73 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -109,6 +109,8 @@ struct bGPdata *ED_gpencil_data_get_active_direct(
         struct Scene *scene,
         struct Object *ob);
 
+bool ED_gpencil_data_owner_is_annotation(struct PointerRNA *owner_ptr);
+
 /* 3D View */
 struct bGPdata  *ED_gpencil_data_get_active_v3d(struct ViewLayer *view_layer);



More information about the Bf-blender-cvs mailing list