[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19068] branches/blender2.5/blender/source /blender/editors: * Added back 'Insert Key' operator for DopeSheet editor

Joshua Leung aligorith at gmail.com
Sat Feb 21 06:04:25 CET 2009


Revision: 19068
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19068
Author:   aligorith
Date:     2009-02-21 06:04:12 +0100 (Sat, 21 Feb 2009)

Log Message:
-----------
* Added back 'Insert Key' operator for DopeSheet editor 
* Fixed button spacing problems in TimeLine

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/editors/animation/anim_channels.c
    branches/blender2.5/blender/source/blender/editors/space_action/action_edit.c
    branches/blender2.5/blender/source/blender/editors/space_action/action_intern.h
    branches/blender2.5/blender/source/blender/editors/space_action/action_ops.c
    branches/blender2.5/blender/source/blender/editors/space_time/time_header.c

Modified: branches/blender2.5/blender/source/blender/editors/animation/anim_channels.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/animation/anim_channels.c	2009-02-21 04:42:46 UTC (rev 19067)
+++ branches/blender2.5/blender/source/blender/editors/animation/anim_channels.c	2009-02-21 05:04:12 UTC (rev 19068)
@@ -1211,6 +1211,7 @@
 				/* if group is selected now, and we're in Action Editor mode (so that we have pointer to active action),
 				 * we can make this group the 'active' one in that action
 				 */
+				// TODO: we should be able to do this through dopesheet + f-curves editor too...
 				if ((agrp->flag & AGRP_SELECTED) && (ac->datatype == ANIMCONT_ACTION))
 					action_set_active_agrp((bAction *)ac->data, agrp);
 			}

Modified: branches/blender2.5/blender/source/blender/editors/space_action/action_edit.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_action/action_edit.c	2009-02-21 04:42:46 UTC (rev 19067)
+++ branches/blender2.5/blender/source/blender/editors/space_action/action_edit.c	2009-02-21 05:04:12 UTC (rev 19068)
@@ -235,9 +235,6 @@
 /* ************************************************************************** */
 /* GENERAL STUFF */
 
-// TODO:
-//	- insert key
-
 /* ******************** Copy/Paste Keyframes Operator ************************* */
 /* - The copy/paste buffer currently stores a set of temporary F-Curves containing only the keyframes 
  *   that were selected in each of the original F-Curves
@@ -575,6 +572,188 @@
 	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
+/* ******************** Insert Keyframes Operator ************************* */
+
+/* defines for insert keyframes tool */
+EnumPropertyItem prop_actkeys_insertkey_types[] = {
+	{1, "ALL", "All Channels", ""},
+	{2, "SEL", "Only Selected Channels", ""},
+	{3, "GROUP", "In Active Group", ""}, // xxx not in all cases
+	{0, NULL, NULL, NULL}
+};
+
+#if 0
+void insertkey_action(void)
+{
+	void *data;
+	short datatype;
+	
+	short mode;
+	float cfra;
+	
+	/* get data */
+	data= get_action_context(&datatype);
+	if (data == NULL) return;
+	cfra = frame_to_float(CFRA);
+	
+	if (ELEM(datatype, ACTCONT_ACTION, ACTCONT_DOPESHEET)) {
+		ListBase act_data = {NULL, NULL};
+		bActListElem *ale;
+		int filter;
+		
+		/* ask user what to keyframe */
+		if (datatype == ACTCONT_ACTION)
+			mode = pupmenu("Insert Key%t|All Channels%x1|Only Selected Channels%x2|In Active Group%x3");
+		else
+			mode = pupmenu("Insert Key%t|All Channels%x1|Only Selected Channels%x2");
+		if (mode <= 0) return;
+		
+		/* filter data */
+		filter= (ACTFILTER_VISIBLE | ACTFILTER_FOREDIT | ACTFILTER_ONLYICU );
+		if (mode == 2) 			filter |= ACTFILTER_SEL;
+		else if (mode == 3) 	filter |= ACTFILTER_ACTGROUPED;
+		
+		actdata_filter(&act_data, filter, data, datatype);
+		
+		/* loop through ipo curves retrieved */
+		for (ale= act_data.first; ale; ale= ale->next) {
+			/* verify that this is indeed an ipo curve */
+			if ((ale->key_data) && ((ale->owner) || (ale->id))) {
+				bActionChannel *achan= (ale->ownertype==ACTTYPE_ACHAN) ? ((bActionChannel *)ale->owner) : (NULL);
+				bConstraintChannel *conchan= (ale->type==ACTTYPE_CONCHAN) ? ale->data : NULL;
+				IpoCurve *icu= (IpoCurve *)ale->key_data;
+				ID *id= NULL;
+				
+				if (datatype == ACTCONT_ACTION) {
+					if (ale->owner) 
+						id= ale->owner;
+				}
+				else if (datatype == ACTCONT_DOPESHEET) {
+					if (ale->id)
+						id= ale->id;
+				}
+				
+				if (id)
+					insertkey(id, icu->blocktype, ((achan)?(achan->name):(NULL)), ((conchan)?(conchan->name):(NULL)), icu->adrcode, 0);
+				else
+					insert_vert_icu(icu, cfra, icu->curval, 0);
+			}
+		}
+		
+		/* cleanup */
+		BLI_freelistN(&act_data);
+	}
+	else if (datatype == ACTCONT_SHAPEKEY) {
+		Key *key= (Key *)data;
+		IpoCurve *icu;
+		
+		/* ask user if they want to insert a keyframe */
+		mode = okee("Insert Keyframe?");
+		if (mode <= 0) return;
+		
+		if (key->ipo) {
+			for (icu= key->ipo->curve.first; icu; icu=icu->next) {
+				insert_vert_icu(icu, cfra, icu->curval, 0);
+			}
+		}
+	}
+	else {
+		/* this tool is not supported in this mode */
+		return;
+	}
+}
+#endif
+
+/* this function is responsible for snapping keyframes to frame-times */
+static void insert_action_keys(bAnimContext *ac, short mode) 
+{
+	ListBase anim_data = {NULL, NULL};
+	bAnimListElem *ale;
+	int filter;
+	
+	Scene *scene= ac->scene;
+	float cfra= (float)CFRA;
+	short flag = 0;
+	
+	/* filter data */
+	filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY);
+	if (mode == 2) 			filter |= ANIMFILTER_SEL;
+	else if (mode == 3) 	filter |= ANIMFILTER_ACTGROUPED;
+	
+	ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
+	
+	/* init keyframing flag */
+	if (IS_AUTOKEY_FLAG(AUTOMATKEY)) flag |= INSERTKEY_MATRIX;
+	if (IS_AUTOKEY_FLAG(INSERTNEEDED)) flag |= INSERTKEY_NEEDED;
+	// if (IS_AUTOKEY_MODE(EDITKEYS)) flag |= INSERTKEY_REPLACE;
+	
+	/* insert keyframes */
+	for (ale= anim_data.first; ale; ale= ale->next) {
+		//Object *nob= ANIM_nla_mapping_get(ac, ale);
+		FCurve *fcu= (FCurve *)ale->key_data;
+		
+		/* adjust current frame for NLA-scaling */
+		//if (nob)
+		//	cfra= get_action_frame(nob, CFRA);
+		//else 
+		//	cfra= (float)CFRA;
+			
+		/* if there's an id */
+		if (ale->id)
+			insertkey(ale->id, ((fcu->grp)?(fcu->grp->name):(NULL)), fcu->rna_path, fcu->array_index, cfra, flag);
+		else
+			insert_vert_fcurve(fcu, cfra, fcu->curval, 0);
+	}
+	
+	BLI_freelistN(&anim_data);
+}
+
+/* ------------------- */
+
+static int actkeys_insertkey_exec(bContext *C, wmOperator *op)
+{
+	bAnimContext ac;
+	short mode;
+	
+	/* get editor data */
+	if (ANIM_animdata_get_context(C, &ac) == 0)
+		return OPERATOR_CANCELLED;
+	if (ac.datatype == ANIMCONT_GPENCIL)
+		return OPERATOR_CANCELLED;
+		
+	/* get snapping mode */
+	mode= RNA_enum_get(op->ptr, "type");
+	
+	/* snap keyframes */
+	insert_action_keys(&ac, mode);
+	
+	/* validate keyframes after editing */
+	ANIM_editkeyframes_refresh(&ac);
+	
+	/* set notifier tha things have changed */
+	ANIM_animdata_send_notifiers(C, &ac, ANIM_CHANGED_KEYFRAMES_VALUES);
+	
+	return OPERATOR_FINISHED;
+}
+
+void ACT_OT_keyframes_insert (wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name= "Insert Keyframes";
+	ot->idname= "ACT_OT_keyframes_insert";
+	
+	/* api callbacks */
+	ot->invoke= WM_menu_invoke;
+	ot->exec= actkeys_insertkey_exec;
+	ot->poll= ED_operator_areaactive;
+	
+	/* flags */
+	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+	
+	/* id-props */
+	RNA_def_enum(ot->srna, "type", prop_actkeys_insertkey_types, 0, "Type", "");
+}
+
 /* ******************** Duplicate Keyframes Operator ************************* */
 
 static void duplicate_action_keys (bAnimContext *ac)

Modified: branches/blender2.5/blender/source/blender/editors/space_action/action_intern.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_action/action_intern.h	2009-02-21 04:42:46 UTC (rev 19067)
+++ branches/blender2.5/blender/source/blender/editors/space_action/action_intern.h	2009-02-21 05:04:12 UTC (rev 19068)
@@ -83,6 +83,7 @@
 void ACT_OT_keyframes_copy(struct wmOperatorType *ot);
 void ACT_OT_keyframes_paste(struct wmOperatorType *ot);
 
+void ACT_OT_keyframes_insert(struct wmOperatorType *ot);
 void ACT_OT_keyframes_duplicate(struct wmOperatorType *ot);
 void ACT_OT_keyframes_delete(struct wmOperatorType *ot);
 void ACT_OT_keyframes_clean(struct wmOperatorType *ot);

Modified: branches/blender2.5/blender/source/blender/editors/space_action/action_ops.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_action/action_ops.c	2009-02-21 04:42:46 UTC (rev 19067)
+++ branches/blender2.5/blender/source/blender/editors/space_action/action_ops.c	2009-02-21 05:04:12 UTC (rev 19068)
@@ -79,6 +79,7 @@
 	WM_operatortype_append(ACT_OT_keyframes_clean);
 	WM_operatortype_append(ACT_OT_keyframes_delete);
 	WM_operatortype_append(ACT_OT_keyframes_duplicate);
+	WM_operatortype_append(ACT_OT_keyframes_insert);
 	WM_operatortype_append(ACT_OT_keyframes_copy);
 	WM_operatortype_append(ACT_OT_keyframes_paste);
 	
@@ -133,6 +134,7 @@
 	WM_keymap_add_item(keymap, "ACT_OT_keyframes_delete", DELKEY, KM_PRESS, 0, 0);
 	
 	WM_keymap_add_item(keymap, "ACT_OT_keyframes_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);
+	WM_keymap_add_item(keymap, "ACT_OT_keyframes_insert", IKEY, KM_PRESS, 0, 0);
 	
 		/* copy/paste */
 	WM_keymap_add_item(keymap, "ACT_OT_keyframes_copy", CKEY, KM_PRESS, KM_CTRL, 0);

Modified: branches/blender2.5/blender/source/blender/editors/space_time/time_header.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_time/time_header.c	2009-02-21 04:42:46 UTC (rev 19067)
+++ branches/blender2.5/blender/source/blender/editors/space_time/time_header.c	2009-02-21 05:04:12 UTC (rev 19068)
@@ -554,7 +554,9 @@
 	
 	uiBlockBeginAlign(block);
 		uiDefIconButO(block, BUT, "ANIM_OT_delete_keyframe", WM_OP_INVOKE_REGION_WIN, ICON_KEY_DEHLT, xco,yco,XIC,YIC, "Delete Keyframes for the Active Keying Set (Alt-I)");
+		xco += XIC;
 		uiDefIconButO(block, BUT, "ANIM_OT_insert_keyframe", WM_OP_INVOKE_REGION_WIN, ICON_KEY_HLT, xco,yco,XIC,YIC, "Insert Keyframes for the Active Keying Set (I)");
+		xco += XIC;
 	uiBlockEndAlign(block);
 	
 	xco+= 16;





More information about the Bf-blender-cvs mailing list