[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21511] branches/soc-2009-aligorith/source /blender: NLA SoC: Names for NLA Strips

Joshua Leung aligorith at gmail.com
Sat Jul 11 01:25:30 CEST 2009


Revision: 21511
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21511
Author:   aligorith
Date:     2009-07-11 01:25:30 +0200 (Sat, 11 Jul 2009)

Log Message:
-----------
NLA SoC: Names for NLA Strips 

In order to be able to better identify NLA Strips (and to reduce the complexity of the text on them), I've implemented a name property for the strips. The names are made to be unique within the AnimData block the strip comes from, though this may not always happen if not enough relevant context info is present to validate this.

Modified Paths:
--------------
    branches/soc-2009-aligorith/source/blender/blenkernel/BKE_nla.h
    branches/soc-2009-aligorith/source/blender/blenkernel/intern/nla.c
    branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_buttons.c
    branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_draw.c
    branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_edit.c
    branches/soc-2009-aligorith/source/blender/makesdna/DNA_anim_types.h
    branches/soc-2009-aligorith/source/blender/makesrna/intern/rna_nla.c

Modified: branches/soc-2009-aligorith/source/blender/blenkernel/BKE_nla.h
===================================================================
--- branches/soc-2009-aligorith/source/blender/blenkernel/BKE_nla.h	2009-07-10 22:16:25 UTC (rev 21510)
+++ branches/soc-2009-aligorith/source/blender/blenkernel/BKE_nla.h	2009-07-10 23:25:30 UTC (rev 21511)
@@ -83,6 +83,10 @@
 
 short BKE_nlastrip_within_bounds(struct NlaStrip *strip, float min, float max);
 
+void BKE_nlastrip_validate_name(struct AnimData *adt, struct NlaStrip *strip);
+
+/* ............ */
+
 short BKE_nlatrack_has_animated_strips(struct NlaTrack *nlt);
 short BKE_nlatracks_have_animated_strips(ListBase *tracks);
 void BKE_nlastrip_validate_fcurves(struct NlaStrip *strip);

Modified: branches/soc-2009-aligorith/source/blender/blenkernel/intern/nla.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/blenkernel/intern/nla.c	2009-07-10 22:16:25 UTC (rev 21510)
+++ branches/soc-2009-aligorith/source/blender/blenkernel/intern/nla.c	2009-07-10 23:25:30 UTC (rev 21511)
@@ -30,12 +30,14 @@
 #include <stdlib.h>
 #include <stddef.h>
 #include <stdio.h>
+#include <string.h>
 #include <math.h>
 #include <float.h>
 
 #include "MEM_guardedalloc.h"
 
 #include "BLI_blenlib.h"
+#include "BLI_ghash.h"
 
 #include "DNA_anim_types.h"
 #include "DNA_action_types.h"
@@ -326,6 +328,9 @@
 		BKE_nlatrack_add_strip(nlt, strip);
 	}
 	
+	/* automatically name it too */
+	BKE_nlastrip_validate_name(adt, strip);
+	
 	/* returns the strip added */
 	return strip;
 }
@@ -503,7 +508,7 @@
 }
 
 /* *************************************************** */
-/* Basic Utilities */
+/* NLA API */
 
 /* List of Strips ------------------------------------ */
 /* (these functions are used for NLA-Tracks and also for nested/meta-strips) */
@@ -1140,9 +1145,91 @@
 		}
 	}
 }
- 
-/* Tools ------------------------------------------- */
 
+/* Sanity Validation ------------------------------------ */
+
+/* Find (and set) a unique name for a strip from the whole AnimData block 
+ * Uses a similar method to the BLI method, but is implemented differently
+ * as we need to ensure that the name is unique over several lists of tracks,
+ * not just a single track.
+ */
+void BKE_nlastrip_validate_name (AnimData *adt, NlaStrip *strip)
+{
+	GHash *gh;
+	NlaStrip *tstrip;
+	NlaTrack *nlt;
+	
+	/* sanity checks */
+	if ELEM(NULL, adt, strip)
+		return;
+		
+	/* give strip a default name if none already */
+	if (strip->name[0]==0) {
+		switch (strip->type) {
+			case NLASTRIP_TYPE_CLIP: /* act-clip */
+				sprintf(strip->name, "Act: %s", (strip->act)?(strip->act->id.name+2):("<None>"));
+				break;
+			case NLASTRIP_TYPE_TRANSITION: /* transition */
+				sprintf(strip->name, "Transition");
+				break;
+			case NLASTRIP_TYPE_META: /* meta */
+				sprintf(strip->name, "Meta");
+				break;
+			default:
+				sprintf(strip->name, "NLA Strip");
+				break;
+		}
+	}
+	
+	/* build a hash-table of all the strips in the tracks 
+	 *	- this is easier than iterating over all the tracks+strips hierarchy everytime
+	 *	  (and probably faster)
+	 */
+	gh= BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp);
+	
+	for (nlt= adt->nla_tracks.first; nlt; nlt= nlt->next) {
+		for (tstrip= nlt->strips.first; tstrip; tstrip= tstrip->next) {
+			/* don't add the strip of interest */
+			if (tstrip == strip) 
+				continue;
+			
+			/* use the name of the strip as the key, and the strip as the value, since we're mostly interested in the keys */
+			BLI_ghash_insert(gh, tstrip->name, tstrip);
+		}
+	}
+	
+	/* if the hash-table has a match for this name, try other names... 
+	 *	- in an extreme case, it might not be able to find a name, but then everything else in Blender would fail too :)
+	 */
+	if (BLI_ghash_haskey(gh, strip->name)) {
+		char tempname[128];
+		int	number = 1;
+		char *dot;
+		
+		/* Strip off the suffix */
+		dot = strchr(strip->name, '.');
+		if (dot) *dot=0;
+		
+		/* Try different possibilities */
+		for (number = 1; number <= 999; number++) {
+			/* assemble alternative name */
+			BLI_snprintf(tempname, 128, "%s%c%03d", strip->name, ".", number);
+			
+			/* if hash doesn't have this, set it */
+			if (BLI_ghash_haskey(gh, tempname) == 0) {
+				BLI_strncpy(strip->name, tempname, sizeof(strip->name));
+				break;
+			}
+		}
+	}
+	
+	/* free the hash... */
+	BLI_ghash_free(gh, NULL, NULL);
+}
+
+
+/* Core Tools ------------------------------------------- */
+
 /* For the given AnimData block, add the active action to the NLA
  * stack (i.e. 'push-down' action). The UI should only allow this 
  * for normal editing only (i.e. not in editmode for some strip's action),

Modified: branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_buttons.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_buttons.c	2009-07-10 22:16:25 UTC (rev 21510)
+++ branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_buttons.c	2009-07-10 23:25:30 UTC (rev 21511)
@@ -215,7 +215,8 @@
 	
 	/* Strip Properties ------------------------------------- */
 	/* strip type */
-	row= uiLayoutRow(layout, 1);
+	row= uiLayoutColumn(layout, 1);
+		uiItemR(row, NULL, ICON_NLA, &strip_ptr, "name", 0, 0, 0); // XXX icon?
 		uiItemR(row, NULL, 0, &strip_ptr, "type", 0, 0, 0);
 	
 	/* strip extents */

Modified: branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_draw.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_draw.c	2009-07-10 22:16:25 UTC (rev 21510)
+++ branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_draw.c	2009-07-10 23:25:30 UTC (rev 21511)
@@ -445,26 +445,11 @@
 	else
 		sprintf(dir, "->");
 	
-	/* for now, just init the string with fixed-formats */
-	switch (strip->type) {
-		case NLASTRIP_TYPE_TRANSITION: /* Transition */
-			sprintf(str, "%d | Transition | %.2f %s %.2f", 
-				index, strip->start, dir, strip->end);
-			break;
-			
-		case NLASTRIP_TYPE_META: /* Meta */
-			sprintf(str, "%d | %sMeta | %.2f %s %.2f", 
-				index, ((strip->flag & NLASTRIP_FLAG_TEMP_META)?"Temp-":""), 
-				strip->start, dir, strip->end);
-			break;
-		
-		case NLASTRIP_TYPE_CLIP:	/* Action-Clip (default) */
-		default:
-			sprintf(str, "%d | Act: %s | %.2f %s %.2f", 
-				index, ((strip->act)?strip->act->id.name+2:"<NONE>"), 
-				strip->start, dir, strip->end);
-			break;
-	}
+	/* just print the name and the range */
+	if (strip->flag & NLASTRIP_FLAG_TEMP_META)
+		sprintf(str, "Temp-Meta | %.2f %s %.2f", strip->start, dir, strip->end);
+	else
+		sprintf(str, "%s | %.2f %s %.2f", strip->name, strip->start, dir, strip->end);
 	
 	/* set text colour - if colours (see above) are light, draw black text, otherwise draw white */
 	if (strip->flag & (NLASTRIP_FLAG_ACTIVE|NLASTRIP_FLAG_SELECT|NLASTRIP_FLAG_TWEAKUSER))

Modified: branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_edit.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_edit.c	2009-07-10 22:16:25 UTC (rev 21510)
+++ branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_edit.c	2009-07-10 23:25:30 UTC (rev 21511)
@@ -307,6 +307,9 @@
 			nlt= add_nlatrack(adt, NULL);
 			BKE_nlatrack_add_strip(nlt, strip);
 		}
+		
+		/* auto-name it */
+		BKE_nlastrip_validate_name(adt, strip);
 	}
 	
 	/* free temp data */
@@ -363,6 +366,7 @@
 	/* for each track, find pairs of strips to add transitions to */
 	for (ale= anim_data.first; ale; ale= ale->next) {
 		NlaTrack *nlt= (NlaTrack *)ale->data;
+		AnimData *adt= BKE_animdata_from_id(ale->id);
 		NlaStrip *s1, *s2;
 		
 		/* get initial pair of strips */
@@ -410,6 +414,9 @@
 			strip->scale= 1.0f;
 			strip->repeat = 1.0f;
 			
+			/* auto-name it */
+			BKE_nlastrip_validate_name(adt, strip);
+			
 			/* make note of this */
 			done++;
 		}
@@ -470,9 +477,18 @@
 	/* for each track, find pairs of strips to add transitions to */
 	for (ale= anim_data.first; ale; ale= ale->next) {
 		NlaTrack *nlt= (NlaTrack *)ale->data;
+		AnimData *adt= BKE_animdata_from_id(ale->id);
+		NlaStrip *strip;
 		
 		/* create meta-strips from the continuous chains of selected strips */
 		BKE_nlastrips_make_metas(&nlt->strips, 0);
+		
+		/* name the metas */
+		for (strip= nlt->strips.first; strip; strip= strip->next) {
+			/* auto-name this strip if selected (that means it is a meta) */
+			if (strip->flag & NLASTRIP_FLAG_SELECT)
+				BKE_nlastrip_validate_name(adt, strip);
+		}
 	}
 	
 	/* free temp data */
@@ -605,6 +621,9 @@
 				/* deselect the original and the active flag */
 				strip->flag &= ~(NLASTRIP_FLAG_SELECT|NLASTRIP_FLAG_ACTIVE);
 				
+				/* auto-name it */
+				BKE_nlastrip_validate_name(adt, strip);
+				
 				done++;
 			}
 		}
@@ -728,7 +747,7 @@
 //	- variable-length splits?
 
 /* split a given Action-Clip strip */
-static void nlaedit_split_strip_actclip (NlaTrack *nlt, NlaStrip *strip)
+static void nlaedit_split_strip_actclip (AnimData *adt, NlaTrack *nlt, NlaStrip *strip)
 {
 	NlaStrip *nstrip;
 	float midframe, midaframe, len;
@@ -765,10 +784,13 @@
 	
 	/* clear the active flag from the copy */
 	nstrip->flag &= ~NLASTRIP_FLAG_ACTIVE;
+	
+	/* auto-name the new strip */
+	BKE_nlastrip_validate_name(adt, nstrip);
 }
 
 /* split a given Meta strip */
-static void nlaedit_split_strip_meta (NlaTrack *nlt, NlaStrip *strip)
+static void nlaedit_split_strip_meta (AnimData *adt, NlaTrack *nlt, NlaStrip *strip)
 {
 	/* simply ungroup it for now...  */
 	BKE_nlastrips_clear_metastrip(&nlt->strips, strip);
@@ -795,6 +817,7 @@
 	/* for each NLA-Track, split all selected strips into two strips */
 	for (ale= anim_data.first; ale; ale= ale->next) {
 		NlaTrack *nlt= (NlaTrack *)ale->data;
+		AnimData *adt= BKE_animdata_from_id(ale->id);
 		NlaStrip *strip, *next;
 		
 		for (strip= nlt->strips.first; strip; strip= next) {
@@ -805,11 +828,11 @@
 				/* splitting method depends on the type of strip */
 				switch (strip->type) {
 					case NLASTRIP_TYPE_CLIP: /* action-clip */
-						nlaedit_split_strip_actclip(nlt, strip);
+						nlaedit_split_strip_actclip(adt, nlt, strip);
 						break;
 						
 					case NLASTRIP_TYPE_META: /* meta-strips need special handling */
-						nlaedit_split_strip_meta(nlt, strip);
+						nlaedit_split_strip_meta(adt, nlt, strip);
 						break;
 					

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list