[Bf-blender-cvs] [13a0dce] master: Action Stashing: Don't allow an action to get stashed more than once

Joshua Leung noreply at git.blender.org
Sat Feb 28 14:37:21 CET 2015


Commit: 13a0dce51c949e09842876da1c4dc68c047d6ed0
Author: Joshua Leung
Date:   Sat Feb 28 12:57:17 2015 +1300
Branches: master
https://developer.blender.org/rB13a0dce51c949e09842876da1c4dc68c047d6ed0

Action Stashing: Don't allow an action to get stashed more than once

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

M	source/blender/blenkernel/BKE_nla.h
M	source/blender/blenkernel/intern/nla.c
M	source/blender/editors/space_action/action_edit.c

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

diff --git a/source/blender/blenkernel/BKE_nla.h b/source/blender/blenkernel/BKE_nla.h
index d9f6182..c3fc29e 100644
--- a/source/blender/blenkernel/BKE_nla.h
+++ b/source/blender/blenkernel/BKE_nla.h
@@ -105,9 +105,13 @@ void BKE_nla_validate_state(struct AnimData *adt);
 
 /* ............ */
 
-void BKE_nla_action_pushdown(struct AnimData *adt);
+bool BKE_nla_action_is_stashed(struct AnimData *adt, struct bAction *act);
 bool BKE_nla_action_stash(struct AnimData *adt);
 
+/* ............ */
+
+void BKE_nla_action_pushdown(struct AnimData *adt);
+
 bool BKE_nla_tweakmode_enter(struct AnimData *adt);
 void BKE_nla_tweakmode_exit(struct AnimData *adt);
 
diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c
index 9be413d..4af1f4c 100644
--- a/source/blender/blenkernel/intern/nla.c
+++ b/source/blender/blenkernel/intern/nla.c
@@ -1525,17 +1525,45 @@ void BKE_nla_validate_state(AnimData *adt)
 
 /* Action Stashing -------------------------------------- */
 
+/* name of stashed tracks - the translation stuff is included here to save extra work */
+#define STASH_TRACK_NAME  DATA_("[Action Stash]")
+
+/* Check if an action is "stashed" in the NLA already
+ *
+ * The criteria for this are:
+ *   1) The action in question lives in a "stash" track
+ *   2) We only check first-level strips. That is, we will not check inside meta strips.
+ */
+bool BKE_nla_action_is_stashed(AnimData *adt, bAction *act)
+{
+	NlaTrack *nlt;
+	NlaStrip *strip;
+	
+	for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) {
+		if (strstr(nlt->name, STASH_TRACK_NAME)) {
+			for (strip = nlt->strips.first; strip; strip = strip->next) {
+				if (strip->act == act)
+					return true;
+			}
+		}
+	}
+	
+	return false;
+}
+
 /* "Stash" an action (i.e. store it as a track/layer in the NLA, but non-contributing)
  * to retain it in the file for future uses
  */
 bool BKE_nla_action_stash(AnimData *adt)
 {
-	const char *STASH_TRACK_NAME = DATA_("[Action Stash]");
-	
 	NlaTrack *prev_track = NULL;
 	NlaTrack *nlt;
 	NlaStrip *strip;
 	
+	/* do not add if it is already stashed */
+	if (BKE_nla_action_is_stashed(adt, adt->action))
+		return false;
+	
 	/* create a new track, and add this immediately above the previous stashing track */
 	for (prev_track = adt->nla_tracks.last; prev_track; prev_track = prev_track->prev) {
 		if (strstr(prev_track->name, STASH_TRACK_NAME)) {
diff --git a/source/blender/editors/space_action/action_edit.c b/source/blender/editors/space_action/action_edit.c
index c4ed44c..ba06c7c 100644
--- a/source/blender/editors/space_action/action_edit.c
+++ b/source/blender/editors/space_action/action_edit.c
@@ -327,6 +327,11 @@ static int action_stash_exec(bContext *C, wmOperator *op)
 				saction->action = NULL;
 				actedit_change_action(C, new_action);
 			}
+			else {
+				/* action has already been added - simply warn about this, and clear */
+				BKE_report(op->reports, RPT_ERROR, "Action has already been stashed");
+				actedit_change_action(C, NULL);
+			}
 		}
 	}




More information about the Bf-blender-cvs mailing list