[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34270] trunk/blender/source/blender/ makesrna/intern: Patch [#24763] NLA Track & Strip methods

Joshua Leung aligorith at gmail.com
Wed Jan 12 02:17:13 CET 2011


Revision: 34270
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=34270
Author:   aligorith
Date:     2011-01-12 01:17:13 +0000 (Wed, 12 Jan 2011)
Log Message:
-----------
Patch [#24763] NLA Track & Strip methods
Submitted by: Dan Eicher (dna)

<quote>
Adds:

AnimData.nla_tracks.new(prev)
* (optional) prev -- add new track after this track

AnimData.nla_tracks.remove(track)

AnimData.nla_tracks.active(track)
* (optional) track -- track to set active
* returns active track

NlaTrack.strips.new(name, start, action)
NOTE: fails if the strip can't fit in the track as opposed to the
operator which will create a new track and add the strip to that.
* name -- name for new strip
* start -- start frame of new strip
* action -- action to assign to strip

NlaTrack.strips.remove(strip)
</quote>

---

I've resolved the issue (noted in the original patch) regarding the
validation of the created strip by creating and using a "dummy
AnimData" block to solve the missing dependencies.

Modified Paths:
--------------
    trunk/blender/source/blender/makesrna/intern/rna_animation.c
    trunk/blender/source/blender/makesrna/intern/rna_nla.c

Modified: trunk/blender/source/blender/makesrna/intern/rna_animation.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_animation.c	2011-01-11 22:32:18 UTC (rev 34269)
+++ trunk/blender/source/blender/makesrna/intern/rna_animation.c	2011-01-12 01:17:13 UTC (rev 34270)
@@ -48,7 +48,11 @@
 #ifdef RNA_RUNTIME
 
 #include "BKE_animsys.h"
+#include "BKE_nla.h"
 
+#include "WM_api.h"
+#include "WM_types.h"
+
 static int rna_AnimData_action_editable(PointerRNA *ptr)
 {
 	AnimData *adt= (AnimData *)ptr->data;
@@ -381,7 +385,33 @@
 	}
 }
 
+/* needs wrapper function to push notifier */
+static NlaTrack *rna_NlaTrack_new(AnimData *adt, bContext *C, NlaTrack *track)
+{
+	NlaTrack *new_track = add_nlatrack(adt, track);
 
+	WM_event_add_notifier(C, NC_ANIMATION|ND_NLA|NA_ADDED, NULL);
+
+	return new_track;
+}
+
+static void rna_NlaTrack_remove(AnimData *adt, bContext *C, NlaTrack *track)
+{
+	free_nlatrack(&adt->nla_tracks, track);
+
+	WM_event_add_notifier(C, NC_ANIMATION|ND_NLA|NA_REMOVED, NULL);
+}
+
+static NlaTrack *rna_NlaTrack_active(AnimData *adt, bContext *C, NlaTrack *track)
+{
+	if (track != NULL) {
+		BKE_nlatrack_set_active(&adt->nla_tracks, track);
+		/* XXX: should (but doesn't) update the active track in the NLA window */
+		WM_event_add_notifier(C, NC_ANIMATION|ND_NLA|NA_SELECTED, NULL);
+	}
+	return BKE_nlatrack_find_active(&adt->nla_tracks);
+}
+
 #else
 
 /* helper function for Keying Set -> keying settings */
@@ -625,6 +655,40 @@
 
 /* --- */
 
+static void rna_api_animdata_nla_tracks(BlenderRNA *brna, PropertyRNA *cprop)
+{
+	StructRNA *srna;
+	PropertyRNA *parm;
+	FunctionRNA *func;
+	
+	RNA_def_property_srna(cprop, "NlaTracks");
+	srna= RNA_def_struct(brna, "NlaTracks", NULL);
+	RNA_def_struct_sdna(srna, "AnimData");
+	RNA_def_struct_ui_text(srna, "NLA Tracks", "Collection of NLA Tracks");
+	
+	func = RNA_def_function(srna, "new", "rna_NlaTrack_new");
+	RNA_def_function_flag(func, FUNC_USE_CONTEXT);
+	RNA_def_function_ui_description(func, "Add a new NLA Tracks");
+	parm = RNA_def_pointer(func, "prev", "NlaTrack", "", "NLA Track to add the new one after.");
+	/* return type */
+	parm = RNA_def_pointer(func, "track", "NlaTrack", "", "New NLA Track.");
+	RNA_def_function_return(func, parm);
+	
+	func = RNA_def_function(srna, "remove", "rna_NlaTrack_remove");
+	RNA_def_function_flag(func, FUNC_USE_CONTEXT);
+	RNA_def_function_ui_description(func, "Remove a NLA Track.");
+	parm = RNA_def_pointer(func, "track", "NlaTrack", "", "NLA Track to remove.");
+	RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
+	
+	func = RNA_def_function(srna, "active", "rna_NlaTrack_active");
+	RNA_def_function_flag(func, FUNC_USE_CONTEXT);
+	RNA_def_function_ui_description(func, "Set active NLA Track");
+	parm = RNA_def_pointer(func, "track", "NlaTrack", "", "NLA Track set active.");
+	/* return type */
+	parm = RNA_def_pointer(func, "active_track", "NlaTrack", "", "Active NLA Track.");
+	RNA_def_function_return(func, parm);
+}
+
 void rna_def_animdata_common(StructRNA *srna)
 {
 	PropertyRNA *prop;
@@ -648,6 +712,8 @@
 	RNA_def_property_collection_sdna(prop, NULL, "nla_tracks", NULL);
 	RNA_def_property_struct_type(prop, "NlaTrack");
 	RNA_def_property_ui_text(prop, "NLA Tracks", "NLA Tracks (i.e. Animation Layers)");
+
+	rna_api_animdata_nla_tracks(brna, prop);
 	
 	/* Active Action */
 	prop= RNA_def_property(srna, "action", PROP_POINTER, PROP_NONE);
@@ -655,7 +721,6 @@
 	RNA_def_property_editable_func(prop, "rna_AnimData_action_editable");
 	RNA_def_property_ui_text(prop, "Action", "Active Action for this datablock");
 
-	
 	/* Active Action Settings */
 	prop= RNA_def_property(srna, "action_extrapolation", PROP_ENUM, PROP_NONE);
 	RNA_def_property_enum_sdna(prop, NULL, "act_extendmode");

Modified: trunk/blender/source/blender/makesrna/intern/rna_nla.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_nla.c	2011-01-11 22:32:18 UTC (rev 34269)
+++ trunk/blender/source/blender/makesrna/intern/rna_nla.c	2011-01-12 01:17:13 UTC (rev 34270)
@@ -43,6 +43,11 @@
 #include "BKE_animsys.h"
 #include "BKE_nla.h"
 
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "ED_anim_api.h"
+
 /* temp constant defined for these funcs only... */
 #define NLASTRIP_MIN_LEN_THRESH 	0.1f
 
@@ -263,6 +268,60 @@
 		data->flag &= ~NLASTRIP_FLAG_USR_TIME;
 }
 
+static NlaStrip *rna_NlaStrip_new(NlaTrack *track, bContext *C, ReportList *reports, const char *name, int start, bAction *action)
+{
+	NlaStrip *strip = add_nlastrip(action);
+	
+	if (strip == NULL) {
+		BKE_reportf(reports, RPT_ERROR, "Unable to create new strip.");
+		return NULL;
+	}
+	
+	strip->end += (start - strip->start);
+	strip->start = start;
+	
+	if (BKE_nlastrips_add_strip(&track->strips, strip) == 0) {
+		BKE_reportf(reports, RPT_ERROR, "Unable to add strip. Track doesn't have any space to accommodate this new strip.");
+		free_nlastrip(NULL, strip);
+		return NULL;
+	}
+	
+	/* create dummy AnimData block so that BKE_nlastrip_validate_name() 
+	 * can be used to ensure a valid name, as we don't have one here...
+	 * 	- only the nla_tracks list is needed there, which we aim to reverse engineer here...
+	 */
+	{
+		AnimData adt = {0};
+		NlaTrack *nlt, *nlt_p;
+		
+		/* 'first' NLA track is found by going back up chain of given track's parents until we fall off */
+		nlt_p = track; nlt = track;
+		while ((nlt = nlt->prev) != NULL)
+			nlt_p = nlt;
+		adt.nla_tracks.first = nlt_p;
+		
+		/* do the same thing to find the last track */
+		nlt_p = track; nlt = track;
+		while ((nlt = nlt->next) != NULL)
+			nlt_p = nlt;
+		adt.nla_tracks.last = nlt_p;
+		
+		/* now we can just auto-name as usual */
+		BKE_nlastrip_validate_name(&adt, strip);
+	}
+	
+	WM_event_add_notifier(C, NC_ANIMATION|ND_NLA|NA_ADDED, NULL);
+	
+	return strip;
+}
+
+static void rna_NlaStrip_remove(NlaTrack *track, bContext *C, ReportList *reports, NlaStrip *strip)
+{
+	free_nlastrip(&track->strips, strip);
+
+	WM_event_add_notifier(C, NC_ANIMATION|ND_NLA|NA_REMOVED, NULL);
+}
+
 #else
 
 /* enum defines exported for rna_animation.c */
@@ -438,6 +497,37 @@
 	// - sync length
 }
 
+static void rna_api_nlatrack_strips(BlenderRNA *brna, PropertyRNA *cprop)
+{
+	StructRNA *srna;
+	PropertyRNA *parm;
+	FunctionRNA *func;
+
+	RNA_def_property_srna(cprop, "NlaStrips");
+	srna= RNA_def_struct(brna, "NlaStrips", NULL);
+	RNA_def_struct_sdna(srna, "NlaTrack");
+	RNA_def_struct_ui_text(srna, "Nla Strips", "Collection of Nla Strips");
+
+	func = RNA_def_function(srna, "new", "rna_NlaStrip_new");
+	RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
+	RNA_def_function_ui_description(func, "Add a new Action-Clip strip to the track");
+	parm= RNA_def_string(func, "name", "NlaStrip", 0, "", "Name for the NLA Strips.");
+	RNA_def_property_flag(parm, PROP_REQUIRED);
+	parm = RNA_def_int(func, "start", 0, INT_MIN, INT_MAX, "Start Frame", "Start frame for this strip.", INT_MIN, INT_MAX);
+	RNA_def_property_flag(parm, PROP_REQUIRED);
+	parm = RNA_def_pointer(func, "action", "Action", "", "Action to assign to this strip.");
+	RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
+	/* return type */
+	parm = RNA_def_pointer(func, "strip", "NlaStrip", "", "New NLA Strip.");
+	RNA_def_function_return(func, parm);
+
+	func = RNA_def_function(srna, "remove", "rna_NlaStrip_remove");
+	RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
+	RNA_def_function_ui_description(func, "Remove a NLA Strip.");
+	parm = RNA_def_pointer(func, "strip", "NlaStrip", "", "NLA Strip to remove.");
+	RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
+}
+
 static void rna_def_nlatrack(BlenderRNA *brna)
 {
 	StructRNA *srna;
@@ -451,7 +541,9 @@
 	prop= RNA_def_property(srna, "strips", PROP_COLLECTION, PROP_NONE);
 	RNA_def_property_struct_type(prop, "NlaStrip");
 	RNA_def_property_ui_text(prop, "NLA Strips", "NLA Strips on this NLA-track");
-	
+
+	rna_api_nlatrack_strips(brna, prop);
+
 	/* name property */
 	prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
 	RNA_def_property_ui_text(prop, "Name", "");




More information about the Bf-blender-cvs mailing list