[Bf-blender-cvs] [a3a3141] master: NLA Editor: Make Single User for NLA Strips

Joshua Leung noreply at git.blender.org
Mon Apr 28 16:00:49 CEST 2014


Commit: a3a3141f53e5341cc4c669297ed1d894ad1d89e1
Author: Joshua Leung
Date:   Tue Apr 29 01:59:15 2014 +1200
https://developer.blender.org/rBa3a3141f53e5341cc4c669297ed1d894ad1d89e1

NLA Editor: Make Single User for NLA Strips

This operator is used to make sure that if/when you have multiple strips
using the same action, if you select these and run this operator, each
strip will be given its own copy of the action. This is useful if you
decide later that you want to start using an existing action as a base.

NOTE: This does not recursively go inside meta's, so care is still advised
in that case.

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

M	release/scripts/startup/bl_ui/space_nla.py
M	source/blender/editors/space_nla/nla_edit.c
M	source/blender/editors/space_nla/nla_intern.h
M	source/blender/editors/space_nla/nla_ops.c

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

diff --git a/release/scripts/startup/bl_ui/space_nla.py b/release/scripts/startup/bl_ui/space_nla.py
index ae5d308..06fe73a 100644
--- a/release/scripts/startup/bl_ui/space_nla.py
+++ b/release/scripts/startup/bl_ui/space_nla.py
@@ -147,6 +147,9 @@ class NLA_MT_edit(Menu):
         layout.operator("nla.action_sync_length").active = False
 
         layout.separator()
+        layout.operator("nla.make_single_user")
+
+        layout.separator()
         layout.operator("nla.swap")
         layout.operator("nla.move_up")
         layout.operator("nla.move_down")
diff --git a/source/blender/editors/space_nla/nla_edit.c b/source/blender/editors/space_nla/nla_edit.c
index bb1e0e4..4eea5de 100644
--- a/source/blender/editors/space_nla/nla_edit.c
+++ b/source/blender/editors/space_nla/nla_edit.c
@@ -49,6 +49,7 @@
 #include "BKE_fcurve.h"
 #include "BKE_nla.h"
 #include "BKE_context.h"
+#include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_report.h"
 #include "BKE_screen.h"
@@ -1709,6 +1710,80 @@ void NLA_OT_action_sync_length(wmOperatorType *ot)
 	ot->prop = RNA_def_boolean(ot->srna, "active", 1, "Active Strip Only", "Only sync the active length for the active strip");
 }
 
+/* ******************** Make Single User ********************************* */
+/* Ensure that each strip has its own action */
+
+static int nlaedit_make_single_user_exec(bContext *C, wmOperator *UNUSED(op))
+{
+	bAnimContext ac;
+	
+	ListBase anim_data = {NULL, NULL};
+	bAnimListElem *ale;
+	int filter;
+	
+	/* get editor data */
+	if (ANIM_animdata_get_context(C, &ac) == 0)
+		return OPERATOR_CANCELLED;
+		
+	/* get a list of the editable tracks being shown in the NLA */
+	filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT);
+	ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
+	
+	/* Ensure that each action used only has a single user
+	 *   - This is done in reverse order so that the original strips are
+	 *     likely to still get to keep their action
+	 */
+	for (ale = anim_data.last; ale; ale = ale->prev) {
+		NlaTrack *nlt = (NlaTrack *)ale->data;
+		NlaStrip *strip;
+		
+		for (strip = nlt->strips.last; strip; strip = strip->prev) {
+			/* must be action-clip only (as only these have actions) */
+			if ((strip->flag & NLASTRIP_FLAG_SELECT) && (strip->type == NLASTRIP_TYPE_CLIP)) {
+				if (strip->act == NULL) 
+					continue;
+				
+				/* multi-user? */
+				if (ID_REAL_USERS(strip->act) > 1) {
+					/* make a new copy of the action for us to use (it will have 1 user already) */
+					bAction *new_action = BKE_action_copy(strip->act);
+					
+					/* decrement user count of our existing action */
+					id_us_min(&strip->act->id);
+					
+					/* switch to the new copy */
+					strip->act = new_action;
+				}
+			}
+		}
+	}
+	
+	/* free temp data */
+	BLI_freelistN(&anim_data);
+	
+	/* set notifier that things have changed */
+	WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_EDITED, NULL);
+	
+	/* done */
+	return OPERATOR_FINISHED;
+}
+
+void NLA_OT_make_single_user(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Make Single User";
+	ot->idname = "NLA_OT_make_single_user";
+	ot->description = "Ensure that each action is only used once in the set of strips selected";
+	
+	/* api callbacks */
+	ot->invoke = WM_operator_confirm;
+	ot->exec = nlaedit_make_single_user_exec;
+	ot->poll = nlaop_poll_tweakmode_off;
+	
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
 /* ******************** Apply Scale Operator ***************************** */
 /* Reset the scaling of the selected strips to 1.0f */
 
diff --git a/source/blender/editors/space_nla/nla_intern.h b/source/blender/editors/space_nla/nla_intern.h
index 8d49d54..ad1a4df 100644
--- a/source/blender/editors/space_nla/nla_intern.h
+++ b/source/blender/editors/space_nla/nla_intern.h
@@ -112,6 +112,8 @@ void NLA_OT_move_down(wmOperatorType *ot);
 
 void NLA_OT_action_sync_length(wmOperatorType *ot);
 
+void NLA_OT_make_single_user(wmOperatorType *ot);
+
 void NLA_OT_apply_scale(wmOperatorType *ot);
 void NLA_OT_clear_scale(wmOperatorType *ot);
 
diff --git a/source/blender/editors/space_nla/nla_ops.c b/source/blender/editors/space_nla/nla_ops.c
index 9dc598b..4749668 100644
--- a/source/blender/editors/space_nla/nla_ops.c
+++ b/source/blender/editors/space_nla/nla_ops.c
@@ -158,6 +158,8 @@ void nla_operatortypes(void)
 	
 	WM_operatortype_append(NLA_OT_action_sync_length);
 	
+	WM_operatortype_append(NLA_OT_make_single_user);
+	
 	WM_operatortype_append(NLA_OT_apply_scale);
 	WM_operatortype_append(NLA_OT_clear_scale);
 	
@@ -261,6 +263,9 @@ static void nla_keymap_main(wmKeyConfig *keyconf, wmKeyMap *keymap)
 	
 	kmi = WM_keymap_add_item(keymap, "NLA_OT_duplicate", DKEY, KM_PRESS, KM_ALT, 0);
 	RNA_boolean_set(kmi->ptr, "linked", true);
+	
+	/* single user */
+	WM_keymap_add_item(keymap, "NLA_OT_make_single_user", UKEY, KM_PRESS, 0, 0);
 		
 	/* delete */
 	WM_keymap_add_item(keymap, "NLA_OT_delete", XKEY, KM_PRESS, 0, 0);




More information about the Bf-blender-cvs mailing list