[Bf-blender-cvs] [26fa13e] master: Code Cleanup: Reshuffling some of the GPencil code

Joshua Leung noreply at git.blender.org
Thu Apr 2 05:36:46 CEST 2015


Commit: 26fa13e6f8d9a6bf64aa50070c5f146461520f96
Author: Joshua Leung
Date:   Thu Apr 2 16:29:33 2015 +1300
Branches: master
https://developer.blender.org/rB26fa13e6f8d9a6bf64aa50070c5f146461520f96

Code Cleanup: Reshuffling some of the GPencil code

* Moved the context handling stuff into gpencil_utils.c

* Moved the datablock and layer operators out into their own file too. Again,
  these weren't related to the other stuff that much

* Split the GPencil to Curves operator out into its own file (gpencil_convert.c).
  This was quite a massive blob of code (48kb) that was not that related to the
  other operators still in that file (gpencil_edit.c)

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

M	source/blender/editors/gpencil/CMakeLists.txt
A	source/blender/editors/gpencil/gpencil_convert.c
A	source/blender/editors/gpencil/gpencil_data.c
M	source/blender/editors/gpencil/gpencil_edit.c
M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_utils.c

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

diff --git a/source/blender/editors/gpencil/CMakeLists.txt b/source/blender/editors/gpencil/CMakeLists.txt
index 58192f5..56b8d28 100644
--- a/source/blender/editors/gpencil/CMakeLists.txt
+++ b/source/blender/editors/gpencil/CMakeLists.txt
@@ -39,6 +39,8 @@ set(INC_SYS
 set(SRC
 	drawgpencil.c
 	editaction_gpencil.c
+	gpencil_convert.c
+	gpencil_data.c
 	gpencil_edit.c
 	gpencil_ops.c
 	gpencil_paint.c
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_convert.c
similarity index 58%
copy from source/blender/editors/gpencil/gpencil_edit.c
copy to source/blender/editors/gpencil/gpencil_convert.c
index 212d384..2c8f864 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_convert.c
@@ -15,15 +15,18 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
- * The Original Code is Copyright (C) 2008, Blender Foundation, Joshua Leung
+ * The Original Code is Copyright (C) 2008, Blender Foundation
  * This is a new part of Blender
  *
  * Contributor(s): Joshua Leung
+ *                 Bastien Montagne
  *
  * ***** END GPL LICENSE BLOCK *****
+ *
+ * Operator for converting Grease Pencil data to geometry
  */
 
-/** \file blender/editors/gpencil/gpencil_edit.c
+/** \file blender/editors/gpencil/gpencil_convert.c
  *  \ingroup edgpencil
  */
 
@@ -83,1178 +86,6 @@
 
 #include "gpencil_intern.h"
 
-
-/* ************************************************ */
-/* Context Wrangling... */
-
-/* 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, Scene *scene, ScrArea *sa, Object *ob, PointerRNA *ptr)
-{
-	/* if there's an active area, check if the particular editor may
-	 * have defined any special Grease Pencil context for editing...
-	 */
-	if (sa) {
-		SpaceLink *sl = sa->spacedata.first;
-		
-		switch (sa->spacetype) {
-			case SPACE_VIEW3D: /* 3D-View */
-			case SPACE_TIME:   /* Timeline - XXX: this is a hack to get it to show GP keyframes for 3D view */
-			case SPACE_ACTION: /* DepeSheet - XXX: this is a hack to get the keyframe jump operator to take GP Keyframes into account */
-			{
-				BLI_assert(scene && ELEM(scene->toolsettings->gpencil_src,
-				                         GP_TOOL_SOURCE_SCENE, GP_TOOL_SOURCE_OBJECT));
-				
-				if (scene->toolsettings->gpencil_src == GP_TOOL_SOURCE_OBJECT) {
-					/* legacy behaviour for usage with old addons requiring object-linked to objects */
-					
-					/* just in case no active/selected object... */
-					if (ob && (ob->flag & SELECT)) {
-						/* for now, as long as there's an object, default to using that in 3D-View */
-						if (ptr) RNA_id_pointer_create(&ob->id, ptr);
-						return &ob->gpd;
-					}
-					/* else: defaults to scene... */
-				}
-				else {
-					if (ptr) RNA_id_pointer_create(&scene->id, ptr);
-					return &scene->gpd;
-				}
-				break;
-			}
-			case SPACE_NODE: /* Nodes Editor */
-			{
-				SpaceNode *snode = (SpaceNode *)sl;
-				
-				/* return the GP data for the active node block/node */
-				if (snode && snode->nodetree) {
-					/* for now, as long as there's an active node tree, default to using that in the Nodes Editor */
-					if (ptr) RNA_id_pointer_create(&snode->nodetree->id, ptr);
-					return &snode->nodetree->gpd;
-				}
-				
-				/* even when there is no node-tree, don't allow this to flow to scene */
-				return NULL;
-			}
-			case SPACE_SEQ: /* Sequencer */
-			{
-				SpaceSeq *sseq = (SpaceSeq *)sl;
-			
-				/* for now, Grease Pencil data is associated with the space (actually preview region only) */
-				/* XXX our convention for everything else is to link to data though... */
-				if (ptr) RNA_pointer_create(screen_id, &RNA_SpaceSequenceEditor, sseq, ptr);
-				return &sseq->gpd;
-			}
-			case SPACE_IMAGE: /* Image/UV Editor */
-			{
-				SpaceImage *sima = (SpaceImage *)sl;
-				
-				/* for now, Grease Pencil data is associated with the space... */
-				/* XXX our convention for everything else is to link to data though... */
-				if (ptr) RNA_pointer_create(screen_id, &RNA_SpaceImageEditor, sima, ptr);
-				return &sima->gpd;
-			}
-			case SPACE_CLIP: /* Nodes Editor */
-			{
-				SpaceClip *sc = (SpaceClip *)sl;
-				MovieClip *clip = ED_space_clip_get_clip(sc);
-				
-				if (clip) {
-					if (sc->gpencil_src == SC_GPENCIL_SRC_TRACK) {
-						MovieTrackingTrack *track = BKE_tracking_track_get_active(&clip->tracking);
-						
-						if (!track)
-							return NULL;
-						
-						if (ptr)
-							RNA_pointer_create(&clip->id, &RNA_MovieTrackingTrack, track, ptr);
-						
-						return &track->gpd;
-					}
-					else {
-						if (ptr)
-							RNA_id_pointer_create(&clip->id, ptr);
-						
-						return &clip->gpd;
-					}
-				}
-				break;
-			}
-			default: /* unsupported space */
-				return NULL;
-		}
-	}
-	
-	/* just fall back on the scene's GP data */
-	if (ptr) RNA_id_pointer_create((ID *)scene, ptr);
-	return (scene) ? &scene->gpd : NULL;
-}
-
-/* Get pointer to active Grease Pencil datablock, and an RNA-pointer to trace back to whatever owns it */
-bGPdata **ED_gpencil_data_get_pointers(const bContext *C, PointerRNA *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, scene, sa, ob, ptr);
-}
-
-/* -------------------------------------------------------- */
-
-/* Get the active Grease Pencil datablock, when context is not available */
-bGPdata *ED_gpencil_data_get_active_direct(ID *screen_id, Scene *scene, ScrArea *sa, Object *ob)
-{
-	bGPdata **gpd_ptr = ED_gpencil_data_get_pointers_direct(screen_id, scene, sa, ob, NULL);
-	return (gpd_ptr) ? *(gpd_ptr) : NULL;
-}
-
-/* Get the active Grease Pencil datablock */
-bGPdata *ED_gpencil_data_get_active(const bContext *C)
-{
-	bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, NULL);
-	return (gpd_ptr) ? *(gpd_ptr) : NULL;
-}
-
-/* -------------------------------------------------------- */
-
-// 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;
-	bGPdata *gpd = NULL;
-	/* We have to make sure active object is actually visible and selected, else we must use default scene gpd,
-	 * to be consistent with ED_gpencil_data_get_active's behavior.
-	 */
-	
-	if (base && TESTBASE(v3d, base)) {
-		gpd = base->object->gpd;
-	}
-	return gpd ? gpd : scene->gpd;
-}
-
-/* ************************************************ */
-/* Panel Operators */
-
-/* poll callback for adding data/layers - special */
-static int gp_add_poll(bContext *C)
-{
-	/* the base line we have is that we have somewhere to add Grease Pencil data */
-	return ED_gpencil_data_get_pointers(C, NULL) != NULL;
-}
-
-/* poll callback for checking if there is an active layer */
-static int gp_active_layer_poll(bContext *C)
-{
-	bGPdata *gpd = ED_gpencil_data_get_active(C);
-	bGPDlayer *gpl = gpencil_layer_getactive(gpd);
-	
-	return (gpl != NULL);
-}
-
-/* ******************* Add New Data ************************ */
-
-/* add new datablock - wrapper around API */
-static int gp_data_add_exec(bContext *C, wmOperator *op)
-{
-	bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, NULL);
-	
-	if (gpd_ptr == NULL) {
-		BKE_report(op->reports, RPT_ERROR, "Nowhere for grease pencil data to go");
-		return OPERATOR_CANCELLED;
-	}
-	else {
-		/* decrement user count and add new datablock */
-		bGPdata *gpd = (*gpd_ptr);
-		
-		id_us_min(&gpd->id);
-		*gpd_ptr = gpencil_data_addnew(DATA_("GPencil"));
-	}
-	
-	/* notifiers */
-	WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
-	
-	return OPERATOR_FINISHED;
-}
-
-void GPENCIL_OT_data_add(wmOperatorType *ot)
-{
-	/* identifiers */
-	ot->name = "Grease Pencil Add New";
-	ot->idname = "GPENCIL_OT_data_add";
-	ot->description = "Add new Grease Pencil datablock";
-	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-	
-	/* callbacks */
-	ot->exec = gp_data_add_exec;
-	ot->poll = gp_add_poll;
-}
-
-/* ******************* Unlink Data ************************ */
-
-/* poll callback for adding data/layers - special */
-static int gp_data_unlink_poll(bContext *C)
-{
-	bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, NULL);
-	
-	/* if we have access to some active data, make sure there's a datablock before enabling this */
-	return (gpd_ptr && *gpd_ptr);
-}
-
-
-/* unlink datablock - wrapper around API */
-static int gp_data_unlink_exec(bContext *C, wmOperator *op)
-{
-	bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, NULL);
-	
-	if (gpd_ptr == NULL) {
-		BKE_report(op->reports, RPT_ERROR, "Nowhere for grease pencil data to go");
-		return OPERATOR_CANCELLED;
-	}
-	else {
-		/* just unlink datablock now, decreasing its user count */
-		bGPdata *gpd = (*gpd_ptr);
-
-		id_us_min(&gpd->id);
-		*gpd_ptr = NULL;
-	}
-	
-	/* notifiers */
-	WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
-	
-	return OPERATOR_FINISHED;
-}
-
-void GPENCIL_OT_data_unlink(wmOperatorType *ot)
-{
-	/* identifiers */
-	ot->name = "Grease Pencil Unlink";
-	ot->idname = "GPENCIL_OT_data_unlink";
-	ot->description = "Unlink active Grease Pencil datablock";
-	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-	
-	/* callbacks */
-	ot->exec = gp_data_unlink_exec;
-	ot->poll = gp_data_unlink_poll;
-}
-
-/* ******************* Add New Layer ************************ */
-
-/* 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);
-	
-	/* 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;
-	}
-	if (*gpd_ptr == NULL)
-		*gpd_ptr = gpencil_data_addnew(DATA_("GPencil"));
-	
-	/* add new layer now */
-	gpencil_layer_addnew(*gpd_ptr, DATA_("GP_Layer"), 1);
-	
-	/

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list