[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [38600] branches/soc-2011-pepper/source/ blender/editors/transform/transform_generics.c: Split up recalcData() function in transform_generics.c into smaller

Joshua Leung aligorith at gmail.com
Fri Jul 22 09:25:52 CEST 2011


Revision: 38600
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38600
Author:   aligorith
Date:     2011-07-22 07:25:52 +0000 (Fri, 22 Jul 2011)
Log Message:
-----------
Split up recalcData() function in transform_generics.c into smaller
functions based on editor types

This could be split up further in future if there's such a need, but
this should already be sufficient. Most notably required since the NLA
recalc stuff was taking quite a few lines within that block

Modified Paths:
--------------
    branches/soc-2011-pepper/source/blender/editors/transform/transform_generics.c

Modified: branches/soc-2011-pepper/source/blender/editors/transform/transform_generics.c
===================================================================
--- branches/soc-2011-pepper/source/blender/editors/transform/transform_generics.c	2011-07-22 05:33:06 UTC (rev 38599)
+++ branches/soc-2011-pepper/source/blender/editors/transform/transform_generics.c	2011-07-22 07:25:52 UTC (rev 38600)
@@ -323,524 +323,548 @@
 	return 0;
 }
 
-/* called for updating while transform acts, once per redraw */
-void recalcData(TransInfo *t)
+/* helper for recalcData() - for Action Editor transforms */
+static void recalcData_actedit(TransInfo *t)
 {
-	Base *base = t->scene->basact;
-
-	if (t->spacetype==SPACE_NODE) {
-		flushTransNodes(t);
+	Scene *scene= t->scene;
+	SpaceAction *saction= (SpaceAction *)t->sa->spacedata.first;
+	
+	bAnimContext ac= {NULL};
+	ListBase anim_data = {NULL, NULL};
+	bAnimListElem *ale;
+	int filter;
+	
+	/* initialise relevant anim-context 'context' data from TransInfo data */
+		/* NOTE: sync this with the code in ANIM_animdata_get_context() */
+	ac.scene= t->scene;
+	ac.obact= OBACT;
+	ac.sa= t->sa;
+	ac.ar= t->ar;
+	ac.sl= (t->sa)? t->sa->spacedata.first : NULL;
+	ac.spacetype= (t->sa)? t->sa->spacetype : 0;
+	ac.regiontype= (t->ar)? t->ar->regiontype : 0;
+	
+	ANIM_animdata_context_getdata(&ac);
+	
+	/* perform flush */
+	if (ac.datatype == ANIMCONT_GPENCIL) {
+		/* flush transform values back to actual coordinates */
+		flushTransGPactionData(t);
 	}
-	else if (t->spacetype==SPACE_SEQ) {
-		flushTransSeq(t);
-	}
-	else if (t->spacetype == SPACE_ACTION) {
-		Scene *scene= t->scene;
-		SpaceAction *saction= (SpaceAction *)t->sa->spacedata.first;
+	else {
+		/* get animdata blocks visible in editor, assuming that these will be the ones where things changed */
+		filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_ANIMDATA);
+		ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
 		
-		bAnimContext ac= {NULL};
-		ListBase anim_data = {NULL, NULL};
-		bAnimListElem *ale;
-		int filter;
-		
-		/* initialise relevant anim-context 'context' data from TransInfo data */
-			/* NOTE: sync this with the code in ANIM_animdata_get_context() */
-		ac.scene= t->scene;
-		ac.obact= OBACT;
-		ac.sa= t->sa;
-		ac.ar= t->ar;
-		ac.sl= (t->sa)? t->sa->spacedata.first : NULL;
-		ac.spacetype= (t->sa)? t->sa->spacetype : 0;
-		ac.regiontype= (t->ar)? t->ar->regiontype : 0;
-		
-		ANIM_animdata_context_getdata(&ac);
-		
-		/* perform flush */
-		if (ac.datatype == ANIMCONT_GPENCIL) {
-			/* flush transform values back to actual coordinates */
-			flushTransGPactionData(t);
-		}
-		else {
-			/* get animdata blocks visible in editor, assuming that these will be the ones where things changed */
-			filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_ANIMDATA);
-			ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
-			
-			/* just tag these animdata-blocks to recalc, assuming that some data there changed 
-			 * BUT only do this if realtime updates are enabled
-			 */
-			if ((saction->flag & SACTION_NOREALTIMEUPDATES) == 0) {
-				for (ale= anim_data.first; ale; ale= ale->next) {
-					/* set refresh tags for objects using this animation */
-					ANIM_list_elem_update(t->scene, ale);
-				}
+		/* just tag these animdata-blocks to recalc, assuming that some data there changed 
+		 * BUT only do this if realtime updates are enabled
+		 */
+		if ((saction->flag & SACTION_NOREALTIMEUPDATES) == 0) {
+			for (ale= anim_data.first; ale; ale= ale->next) {
+				/* set refresh tags for objects using this animation */
+				ANIM_list_elem_update(t->scene, ale);
 			}
-			
-			/* now free temp channels */
-			BLI_freelistN(&anim_data);
 		}
+		
+		/* now free temp channels */
+		BLI_freelistN(&anim_data);
 	}
-	else if (t->spacetype == SPACE_IPO) {
-		Scene *scene;
-		SpaceIpo *sipo= (SpaceIpo *)t->sa->spacedata.first;
+}
+
+/* helper for recalcData() - for Graph Editor transforms */
+static void recalcData_graphedit(TransInfo *t)
+{
+	SpaceIpo *sipo= (SpaceIpo *)t->sa->spacedata.first;
+	Scene *scene;
+	
+	ListBase anim_data = {NULL, NULL};
+	bAnimContext ac= {NULL};
+	int filter;
+	
+	bAnimListElem *ale;
+	int dosort = 0;
+	
+	
+	/* initialise relevant anim-context 'context' data from TransInfo data */
+		/* NOTE: sync this with the code in ANIM_animdata_get_context() */
+	scene= ac.scene= t->scene;
+	ac.obact= OBACT;
+	ac.sa= t->sa;
+	ac.ar= t->ar;
+	ac.sl= (t->sa)? t->sa->spacedata.first : NULL;
+	ac.spacetype= (t->sa)? t->sa->spacetype : 0;
+	ac.regiontype= (t->ar)? t->ar->regiontype : 0;
+	
+	ANIM_animdata_context_getdata(&ac);
+	
+	/* do the flush first */
+	flushTransGraphData(t);
+	
+	/* get curves to check if a re-sort is needed */
+	filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVE_VISIBLE);
+	ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
+	
+	/* now test if there is a need to re-sort */
+	for (ale= anim_data.first; ale; ale= ale->next) {
+		FCurve *fcu= (FCurve *)ale->key_data;
 		
-		ListBase anim_data = {NULL, NULL};
-		bAnimContext ac= {NULL};
-		int filter;
+		/* ignore unselected fcurves */
+		if (!fcu_test_selected(fcu))
+			continue;
 		
-		bAnimListElem *ale;
-		int dosort = 0;
+		// fixme: only do this for selected verts...
+		ANIM_unit_mapping_apply_fcurve(ac.scene, ale->id, ale->key_data, ANIM_UNITCONV_ONLYSEL|ANIM_UNITCONV_SELVERTS|ANIM_UNITCONV_RESTORE);
 		
 		
-		/* initialise relevant anim-context 'context' data from TransInfo data */
-			/* NOTE: sync this with the code in ANIM_animdata_get_context() */
-		scene= ac.scene= t->scene;
-		ac.obact= OBACT;
-		ac.sa= t->sa;
-		ac.ar= t->ar;
-		ac.sl= (t->sa)? t->sa->spacedata.first : NULL;
-		ac.spacetype= (t->sa)? t->sa->spacetype : 0;
-		ac.regiontype= (t->ar)? t->ar->regiontype : 0;
+		/* watch it: if the time is wrong: do not correct handles yet */
+		if (test_time_fcurve(fcu))
+			dosort++;
+		else
+			calchandles_fcurve(fcu);
 		
-		ANIM_animdata_context_getdata(&ac);
+		/* set refresh tags for objects using this animation,
+		 * BUT only if realtime updates are enabled  
+		 */
+		if ((sipo->flag & SIPO_NOREALTIMEUPDATES) == 0)
+			ANIM_list_elem_update(t->scene, ale);
+	}
+	
+	/* do resort and other updates? */
+	if (dosort) remake_graph_transdata(t, &anim_data);
+	
+	/* now free temp channels */
+	BLI_freelistN(&anim_data);
+}
+
+/* helper for recalcData() - for NLA Editor transforms */
+static void recalcData_nla(TransInfo *t)
+{
+	TransDataNla *tdn= (TransDataNla *)t->customData;
+	SpaceNla *snla= (SpaceNla *)t->sa->spacedata.first;
+	Scene *scene= t->scene;
+	double secf= FPS;
+	int i;
+	
+	/* for each strip we've got, perform some additional validation of the values that got set before
+	 * using RNA to set the value (which does some special operations when setting these values to make
+	 * sure that everything works ok)
+	 */
+	for (i = 0; i < t->total; i++, tdn++) {
+		NlaStrip *strip= tdn->strip;
+		PointerRNA strip_ptr;
+		short pExceeded, nExceeded, iter;
+		int delta_y1, delta_y2;
 		
-		/* do the flush first */
-		flushTransGraphData(t);
+		/* if this tdn has no handles, that means it is just a dummy that should be skipped */
+		if (tdn->handle == 0)
+			continue;
 		
-		/* get curves to check if a re-sort is needed */
-		filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVE_VISIBLE);
-		ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
+		/* set refresh tags for objects using this animation,
+		 * BUT only if realtime updates are enabled  
+		 */
+		if ((snla->flag & SNLA_NOREALTIMEUPDATES) == 0)
+			ANIM_id_update(t->scene, tdn->id);
 		
-		/* now test if there is a need to re-sort */
-		for (ale= anim_data.first; ale; ale= ale->next) {
-			FCurve *fcu= (FCurve *)ale->key_data;
+		/* if cancelling transform, just write the values without validating, then move on */
+		if (t->state == TRANS_CANCEL) {
+			/* clear the values by directly overwriting the originals, but also need to restore
+			 * endpoints of neighboring transition-strips
+			 */
 			
-			/* ignore unselected fcurves */
-			if (!fcu_test_selected(fcu))
-				continue;
+			/* start */
+			strip->start= tdn->h1[0];
 			
-			// fixme: only do this for selected verts...
-			ANIM_unit_mapping_apply_fcurve(ac.scene, ale->id, ale->key_data, ANIM_UNITCONV_ONLYSEL|ANIM_UNITCONV_SELVERTS|ANIM_UNITCONV_RESTORE);
+			if ((strip->prev) && (strip->prev->type == NLASTRIP_TYPE_TRANSITION))
+				strip->prev->end= tdn->h1[0];
 			
+			/* end */
+			strip->end= tdn->h2[0];
 			
-			/* watch it: if the time is wrong: do not correct handles yet */
-			if (test_time_fcurve(fcu))
-				dosort++;
-			else
-				calchandles_fcurve(fcu);
+			if ((strip->next) && (strip->next->type == NLASTRIP_TYPE_TRANSITION))
+				strip->next->start= tdn->h2[0];
 			
-			/* set refresh tags for objects using this animation,
-			 * BUT only if realtime updates are enabled  
-			 */
-			if ((sipo->flag & SIPO_NOREALTIMEUPDATES) == 0)
-				ANIM_list_elem_update(t->scene, ale);
+			/* flush transforms to child strips (since this should be a meta) */
+			BKE_nlameta_flush_transforms(strip);
+			
+			/* restore to original track (if needed) */
+			if (tdn->oldTrack != tdn->nlt) {
+				/* just append to end of list for now, since strips get sorted in special_aftertrans_update() */
+				BLI_remlink(&tdn->nlt->strips, strip);
+				BLI_addtail(&tdn->oldTrack->strips, strip);
+			}
+			
+			continue;
 		}
 		
-		/* do resort and other updates? */
-		if (dosort) remake_graph_transdata(t, &anim_data);
-		
-		/* now free temp channels */
-		BLI_freelistN(&anim_data);
-	}
-	else if (t->spacetype == SPACE_NLA) {
-		TransDataNla *tdn= (TransDataNla *)t->customData;
-		SpaceNla *snla= (SpaceNla *)t->sa->spacedata.first;
-		Scene *scene= t->scene;
-		double secf= FPS;
-		int i;
-		
-		/* for each strip we've got, perform some additional validation of the values that got set before
-		 * using RNA to set the value (which does some special operations when setting these values to make
-		 * sure that everything works ok)
+		/* firstly, check if the proposed transform locations would overlap with any neighbouring strips
+		 * (barring transitions) which are absolute barriers since they are not being moved
+		 *
+		 * this is done as a iterative procedure (done 5 times max for now)
 		 */
-		for (i = 0; i < t->total; i++, tdn++) {
-			NlaStrip *strip= tdn->strip;
-			PointerRNA strip_ptr;
-			short pExceeded, nExceeded, iter;
-			int delta_y1, delta_y2;

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list