[Bf-blender-cvs] [6b42183120f] greasepencil-object: 3D Annotations: Restore ability to access annotations from the 3D view

Joshua Leung noreply at git.blender.org
Thu Jun 28 09:14:03 CEST 2018


Commit: 6b42183120f162c32d41bfc47c1bc3ccbacf52f3
Author: Joshua Leung
Date:   Thu Jun 28 16:15:31 2018 +1200
Branches: greasepencil-object
https://developer.blender.org/rB6b42183120f162c32d41bfc47c1bc3ccbacf52f3

3D Annotations: Restore ability to access annotations from the 3D view

For now, the "gpencil" context properties work as follows:
* If the active object is a GP Object, the GP data associated with
  that is returned
* Otherwise, the Scene's GP data (i.e. annotations) are used

We may need to revise this later. But in the meantime, I'm restoring
this so that we have a quick way of figuring out what parts of the
annotation tool workflow are currently broken.

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

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

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

diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index da785792367..88c5848f09b 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -88,7 +88,7 @@
 /* Get pointer to active Grease Pencil datablock, and an RNA-pointer to trace back to whatever owns it,
  * when context info is not available.
  */
-bGPdata **ED_gpencil_data_get_pointers_direct(ID *screen_id, ScrArea *sa, Object *ob, PointerRNA *r_ptr)
+bGPdata **ED_gpencil_data_get_pointers_direct(ID *screen_id, ScrArea *sa, Scene *scene, Object *ob, PointerRNA *r_ptr)
 {
 	/* if there's an active area, check if the particular editor may
 	 * have defined any special Grease Pencil context for editing...
@@ -97,13 +97,13 @@ bGPdata **ED_gpencil_data_get_pointers_direct(ID *screen_id, ScrArea *sa, Object
 		SpaceLink *sl = sa->spacedata.first;
 
 		switch (sa->spacetype) {
-			case SPACE_VIEW3D: /* 3D-View */
+			/* XXX: Should we reduce reliance on context.gpencil_data for these cases? */
 			case SPACE_BUTS: /* properties */
 			case SPACE_INFO: /* header info (needed after workspaces merge) */
 			case SPACE_TOPBAR: /* Topbar (needed after topbar merge) */
 			{
-				/* return obgpencil datablock */
 				if (ob && (ob->type == OB_GPENCIL)) {
+					/* GP Object */
 					if (r_ptr) RNA_id_pointer_create(&ob->id, r_ptr);
 					return (bGPdata **)&ob->data;
 				}
@@ -113,6 +113,23 @@ bGPdata **ED_gpencil_data_get_pointers_direct(ID *screen_id, ScrArea *sa, Object
 
 				break;
 			}
+
+			case SPACE_VIEW3D: /* 3D-View */
+			{
+				if (ob && (ob->type == OB_GPENCIL)) {
+					/* GP Object */
+					if (r_ptr) RNA_id_pointer_create(&ob->id, r_ptr);
+					return (bGPdata **)&ob->data;
+				}
+				else {
+					/* Annotations */
+					/* XXX: */
+					if (r_ptr) RNA_id_pointer_create(&scene->id, r_ptr);
+					return &scene->gpd;
+				}
+
+				break;
+			}
 			case SPACE_NODE: /* Nodes Editor */
 			{
 				SpaceNode *snode = (SpaceNode *)sl;
@@ -179,18 +196,19 @@ bGPdata **ED_gpencil_data_get_pointers_direct(ID *screen_id, ScrArea *sa, Object
 bGPdata **ED_gpencil_data_get_pointers(const bContext *C, PointerRNA *r_ptr)
 {
 	ID *screen_id = (ID *)CTX_wm_screen(C);
+	Scene *scene = CTX_data_scene(C);
 	ScrArea *sa = CTX_wm_area(C);
 	Object *ob = CTX_data_active_object(C);
 
-	return ED_gpencil_data_get_pointers_direct(screen_id, sa, ob, r_ptr);
+	return ED_gpencil_data_get_pointers_direct(screen_id, sa, scene, ob, r_ptr);
 }
 
 /* -------------------------------------------------------- */
 
 /* Get the active Grease Pencil datablock, when context is not available */
-bGPdata *ED_gpencil_data_get_active_direct(ID *screen_id, ScrArea *sa, Object *ob)
+bGPdata *ED_gpencil_data_get_active_direct(ID *screen_id, ScrArea *sa, Scene *scene, Object *ob)
 {
-	bGPdata **gpd_ptr = ED_gpencil_data_get_pointers_direct(screen_id, sa, ob, NULL);
+	bGPdata **gpd_ptr = ED_gpencil_data_get_pointers_direct(screen_id, sa, scene, ob, NULL);
 	return (gpd_ptr) ? *(gpd_ptr) : NULL;
 }
 
@@ -219,11 +237,12 @@ bGPdata *ED_gpencil_data_get_active_evaluated(const bContext *C)
 	ScrArea *sa = CTX_wm_area(C);
 
 	const Depsgraph *depsgraph = CTX_data_depsgraph(C);
+	Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
 	Object *ob = CTX_data_active_object(C);
 	Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
 
 	/* if (ob && ob->type == OB_GPENCIL) BLI_assert(ob_eval->data == DEG_get_evaluated_id(ob->data)); */
-	return ED_gpencil_data_get_active_direct(screen_id, sa, ob_eval);
+	return ED_gpencil_data_get_active_direct(screen_id, sa, scene_eval, ob_eval);
 }
 
 /* -------------------------------------------------------- */
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index ee405227ad0..d9a826e7f9c 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -99,11 +99,15 @@ struct bGPdata  *ED_gpencil_data_get_active_evaluated(const struct bContext *C);
 /* Context independent (i.e. each required part is passed in instead) */
 struct bGPdata **ED_gpencil_data_get_pointers_direct(
         struct ID *screen_id,
-        struct ScrArea *sa, struct Object *ob,
+        struct ScrArea *sa,
+        struct Scene *scene,
+        struct Object *ob,
         struct PointerRNA *r_ptr);
 struct bGPdata *ED_gpencil_data_get_active_direct(
         struct ID *screen_id,
-        struct ScrArea *sa, struct Object *ob);
+        struct ScrArea *sa,
+        struct Scene *scene,
+        struct Object *ob);
 
 /* 3D View */
 struct bGPdata  *ED_gpencil_data_get_active_v3d(struct ViewLayer *view_layer);
diff --git a/source/blender/editors/screen/screen_context.c b/source/blender/editors/screen/screen_context.c
index 55761fe8dbd..04f678dbc8f 100644
--- a/source/blender/editors/screen/screen_context.c
+++ b/source/blender/editors/screen/screen_context.c
@@ -471,7 +471,7 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
 		 * (as outlined above - see Campbell's #ifdefs). That causes the get_active function to fail when
 		 * called from context. For that reason, we end up using an alternative where we pass everything in!
 		 */
-		bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, sa, obact);
+		bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, sa, scene, obact);
 
 		if (gpd) {
 			CTX_data_id_pointer_set(result, &gpd->id);
@@ -486,7 +486,7 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
 		PointerRNA ptr;
 
 		/* get pointer to Grease Pencil Data */
-		gpd_ptr = ED_gpencil_data_get_pointers_direct((ID *)sc, sa, obact, &ptr);
+		gpd_ptr = ED_gpencil_data_get_pointers_direct((ID *)sc, sa, scene, obact, &ptr);
 
 		if (gpd_ptr) {
 			CTX_data_pointer_set(result, ptr.id.data, ptr.type, ptr.data);
@@ -495,7 +495,7 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
 	}
 	else if (CTX_data_equals(member, "active_gpencil_layer")) {
 		/* XXX: see comment for gpencil_data case... */
-		bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, sa, obact);
+		bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, sa, scene, obact);
 
 		if (gpd) {
 			bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
@@ -516,7 +516,7 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
 	}
 	else if (CTX_data_equals(member, "active_gpencil_frame")) {
 		/* XXX: see comment for gpencil_data case... */
-		bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, sa, obact);
+		bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, sa, scene, obact);
 
 		if (gpd) {
 			bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
@@ -529,7 +529,7 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
 	}
 	else if (CTX_data_equals(member, "visible_gpencil_layers")) {
 		/* XXX: see comment for gpencil_data case... */
-		bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, sa, obact);
+		bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, sa, scene, obact);
 
 		if (gpd) {
 			bGPDlayer *gpl;
@@ -545,7 +545,7 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
 	}
 	else if (CTX_data_equals(member, "editable_gpencil_layers")) {
 		/* XXX: see comment for gpencil_data case... */
-		bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, sa, obact);
+		bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, sa, scene, obact);
 
 		if (gpd) {
 			bGPDlayer *gpl;
@@ -561,7 +561,7 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
 	}
 	else if (CTX_data_equals(member, "editable_gpencil_strokes")) {
 		/* XXX: see comment for gpencil_data case... */
-		bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, sa, obact);
+		bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, sa, scene, obact);
 		bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
 
 		if (gpd) {



More information about the Bf-blender-cvs mailing list