[Bf-blender-cvs] [6d2c23b] master: NLA Pushdown Operator: Active animdata option + More error handling

Joshua Leung noreply at git.blender.org
Mon May 5 04:19:02 CEST 2014


Commit: 6d2c23bf70c550ead52a5e518d9e4846c5d3f23f
Author: Joshua Leung
Date:   Mon May 5 14:15:28 2014 +1200
https://developer.blender.org/rB6d2c23bf70c550ead52a5e518d9e4846c5d3f23f

NLA Pushdown Operator: Active animdata option + More error handling

* If channel_index = -1, the pushdown operator will try to use the active AnimData
  block. To see which one this will be, check the properties (NKEY) region in NLA Editor.
* Added more detailed error handling for the various cases where things are not
  in a valid state for pushing down an action. This is notably to stop scripters
  from putting the NLA into an inconsistent state.

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

M	source/blender/editors/space_nla/nla_buttons.c
M	source/blender/editors/space_nla/nla_channels.c
M	source/blender/editors/space_nla/nla_intern.h

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

diff --git a/source/blender/editors/space_nla/nla_buttons.c b/source/blender/editors/space_nla/nla_buttons.c
index a39783c..808bd62 100644
--- a/source/blender/editors/space_nla/nla_buttons.c
+++ b/source/blender/editors/space_nla/nla_buttons.c
@@ -80,19 +80,19 @@ static void do_nla_region_buttons(bContext *C, void *UNUSED(arg), int UNUSED(eve
 	WM_event_add_notifier(C, NC_SCENE | ND_TRANSFORM, NULL);
 }
 
-static int nla_panel_context(const bContext *C, PointerRNA *adt_ptr, PointerRNA *nlt_ptr, PointerRNA *strip_ptr)
+bool nla_panel_context(const bContext *C, PointerRNA *adt_ptr, PointerRNA *nlt_ptr, PointerRNA *strip_ptr)
 {
 	bAnimContext ac;
 	bAnimListElem *ale = NULL;
 	ListBase anim_data = {NULL, NULL};
-	short found = 0;
+	short found = 0; /* not bool, since we need to indicate "found but not ideal" status */
 	int filter;
 	
 	/* for now, only draw if we could init the anim-context info (necessary for all animation-related tools) 
 	 * to work correctly is able to be correctly retrieved. There's no point showing empty panels?
 	 */
 	if (ANIM_animdata_get_context(C, &ac) == 0) 
-		return 0;
+		return false;
 	
 	/* extract list of active channel(s), of which we should only take the first one 
 	 *	- we need the channels flag to get the active AnimData block when there are no NLA Tracks
@@ -176,7 +176,7 @@ static int nla_panel_context(const bContext *C, PointerRNA *adt_ptr, PointerRNA
 	/* free temp data */
 	BLI_freelistN(&anim_data);
 	
-	return found;
+	return (found != 0);
 }
 
 #if 0
diff --git a/source/blender/editors/space_nla/nla_channels.c b/source/blender/editors/space_nla/nla_channels.c
index 06bf755..be4d197 100644
--- a/source/blender/editors/space_nla/nla_channels.c
+++ b/source/blender/editors/space_nla/nla_channels.c
@@ -412,10 +412,17 @@ static int nlachannels_pushdown_exec(bContext *C, wmOperator *op)
 		
 	/* get anim-channel to use (or more specifically, the animdata block behind it) */
 	if (channel_index == -1) {
+		PointerRNA adt_ptr = {{NULL}};
+		
 		/* active animdata block */
-		// FIXME
-		BKE_report(op->reports, RPT_WARNING, "Pushdown for active AnimData block is currently not yet implemented");
-		return OPERATOR_CANCELLED;
+		if (nla_panel_context(C, &adt_ptr, NULL, NULL) == 0 || (adt_ptr.data == NULL)) {
+			BKE_report(op->reports, RPT_ERROR, "No active AnimData block to use. " 
+			           "Select a datablock expander first or set the appropriate flags on an AnimData block");
+			return OPERATOR_CANCELLED;
+		}
+		else {
+			adt = adt_ptr.data;
+		}
 	}
 	else {
 		/* indexed channel */
@@ -448,7 +455,19 @@ static int nlachannels_pushdown_exec(bContext *C, wmOperator *op)
 	}
 	
 	/* double-check that we are free to push down here... */
-	if (adt && nlaedit_is_tweakmode_on(&ac) == 0) {
+	if (adt == NULL) {
+		BKE_report(op->reports, RPT_WARNING, "Internal Error - AnimData block is not valid");
+		return OPERATOR_CANCELLED;
+	}
+	else if (nlaedit_is_tweakmode_on(&ac)) {
+		BKE_report(op->reports, RPT_WARNING, "Cannot push down actions while tweaking a strip's action. Exit tweakmode first");
+		return OPERATOR_CANCELLED;
+	}
+	else if (adt->action == NULL) {
+		BKE_report(op->reports, RPT_WARNING, "No active action to push down");
+		return OPERATOR_CANCELLED;
+	}
+	else {
 		/* 'push-down' action - only usable when not in TweakMode */
 		BKE_nla_action_pushdown(adt);
 	}
diff --git a/source/blender/editors/space_nla/nla_intern.h b/source/blender/editors/space_nla/nla_intern.h
index b89d816..766ae28 100644
--- a/source/blender/editors/space_nla/nla_intern.h
+++ b/source/blender/editors/space_nla/nla_intern.h
@@ -41,6 +41,8 @@
 
 ARegion *nla_has_buttons_region(ScrArea *sa);
 
+bool nla_panel_context(const bContext *C, PointerRNA *adt_ptr, PointerRNA *nlt_ptr, PointerRNA *strip_ptr);
+
 void nla_buttons_register(ARegionType *art);
 void NLA_OT_properties(wmOperatorType *ot);




More information about the Bf-blender-cvs mailing list