[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34021] trunk/blender/source/blender/ editors: Keyframing Operator Code Cleanup:

Joshua Leung aligorith at gmail.com
Mon Jan 3 06:37:08 CET 2011


Revision: 34021
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=34021
Author:   aligorith
Date:     2011-01-03 06:36:52 +0100 (Mon, 03 Jan 2011)

Log Message:
-----------
Keyframing Operator Code Cleanup:

Keyframing operators now use a dynamically-generated enum for their
"type" property, which determines the Keying Set to use for keyframing
instead of the obscure "index" values which were determined
internally. Internally though, these same indices are still being used
:)

Notes:
- I've kept the menu-building function and the special "menu" operator
for now, since it's better to not "pollute" the actual insert
keyframes operator with hardcoded menu-showing logic. Instead, the
menu operator does that, so that if you like, you could write another
such wrapper that works differently.
- The 'type' properties could have the PROP_HIDDEN flags removed,
though I think it's cleaner to leave these without this option for
now.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/animation/keyframing.c
    trunk/blender/source/blender/editors/animation/keyingsets.c
    trunk/blender/source/blender/editors/include/ED_keyframing.h

Modified: trunk/blender/source/blender/editors/animation/keyframing.c
===================================================================
--- trunk/blender/source/blender/editors/animation/keyframing.c	2011-01-03 04:59:57 UTC (rev 34020)
+++ trunk/blender/source/blender/editors/animation/keyframing.c	2011-01-03 05:36:52 UTC (rev 34021)
@@ -72,6 +72,7 @@
 
 #include "RNA_access.h"
 #include "RNA_define.h"
+#include "RNA_enum_types.h"
 
 #include "anim_intern.h"
 
@@ -1074,7 +1075,7 @@
 	Main *bmain= CTX_data_main(C);
 	Scene *scene= CTX_data_scene(C);
 	KeyingSet *ks= NULL;
-	int type= RNA_int_get(op->ptr, "type");
+	int type= RNA_enum_get(op->ptr, "type");
 	float cfra= (float)CFRA; // XXX for now, don't bother about all the yucky offset crap
 	short success;
 	
@@ -1139,11 +1140,12 @@
 	/* flags */
 	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 	
-	/* keyingset to use
-	 *	- here the type is int not enum, since many of the indicies here are determined dynamically
-	 */
-	prop= RNA_def_int(ot->srna, "type", 0, INT_MIN, INT_MAX, "Keying Set Number", "Index (determined internally) of the Keying Set to use", 0, 1);
+	/* keyingset to use (dynamic enum) */
+	prop= RNA_def_enum(ot->srna, "type", DummyRNA_DEFAULT_items, 0, "Keying Set", "The Keying Set to use");
+	RNA_def_enum_funcs(prop, ANIM_keying_sets_enum_itemf);
 	RNA_def_property_flag(prop, PROP_HIDDEN);
+	ot->prop= prop;
+	
 	/* confirm whether a keyframe was added by showing a popup 
 	 *	- by default, this is enabled, since this operator is assumed to be called independently
 	 */
@@ -1168,7 +1170,7 @@
 	}
 	else {
 		/* just call the exec() on the active keyingset */
-		RNA_int_set(op->ptr, "type", 0);
+		RNA_enum_set(op->ptr, "type", 0);
 		RNA_boolean_set(op->ptr, "confirm_success", 1);
 		
 		return op->type->exec(C, op);
@@ -1192,17 +1194,19 @@
 	/* flags */
 	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 	
-	/* keyingset to use
-	 *	- here the type is int not enum, since many of the indicies here are determined dynamically
-	 */
-	prop= RNA_def_int(ot->srna, "type", 0, INT_MIN, INT_MAX, "Keying Set Number", "Index (determined internally) of the Keying Set to use", 0, 1);
+	/* keyingset to use (dynamic enum) */
+	prop= RNA_def_enum(ot->srna, "type", DummyRNA_DEFAULT_items, 0, "Keying Set", "The Keying Set to use");
+	RNA_def_enum_funcs(prop, ANIM_keying_sets_enum_itemf);
 	RNA_def_property_flag(prop, PROP_HIDDEN);
+	ot->prop= prop;
+	
 	/* confirm whether a keyframe was added by showing a popup 
 	 *	- by default, this is disabled so that if a menu is shown, this doesn't come up too
 	 */
 	// XXX should this just be always on?
 	prop= RNA_def_boolean(ot->srna, "confirm_success", 0, "Confirm Successful Insert", "Show a popup when the keyframes get successfully added");
 	RNA_def_property_flag(prop, PROP_HIDDEN);
+	
 	/* whether the menu should always be shown 
 	 *	- by default, the menu should only be shown when there is no active Keying Set (2.5 behaviour),
 	 *	  although in some cases it might be useful to always shown (pre 2.5 behaviour)
@@ -1218,7 +1222,7 @@
 	Main *bmain= CTX_data_main(C);
 	Scene *scene= CTX_data_scene(C);
 	KeyingSet *ks= NULL;	
-	int type= RNA_int_get(op->ptr, "type");
+	int type= RNA_enum_get(op->ptr, "type");
 	float cfra= (float)CFRA; // XXX for now, don't bother about all the yucky offset crap
 	short success;
 	
@@ -1269,6 +1273,8 @@
 
 void ANIM_OT_keyframe_delete (wmOperatorType *ot)
 {
+	PropertyRNA *prop;
+	
 	/* identifiers */
 	ot->name= "Delete Keyframe";
 	ot->idname= "ANIM_OT_keyframe_delete";
@@ -1281,10 +1287,12 @@
 	/* flags */
 	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 	
-	/* keyingset to use
-	 *	- here the type is int not enum, since many of the indicies here are determined dynamically
-	 */
-	RNA_def_int(ot->srna, "type", 0, INT_MIN, INT_MAX, "Keying Set Number", "Index (determined internally) of the Keying Set to use", 0, 1);
+	/* keyingset to use (dynamic enum) */
+	prop= RNA_def_enum(ot->srna, "type", DummyRNA_DEFAULT_items, 0, "Keying Set", "The Keying Set to use");
+	RNA_def_enum_funcs(prop, ANIM_keying_sets_enum_itemf);
+	RNA_def_property_flag(prop, PROP_HIDDEN);
+	ot->prop= prop;
+	
 	/* confirm whether a keyframe was added by showing a popup 
 	 *	- by default, this is enabled, since this operator is assumed to be called independently
 	 */
@@ -1407,7 +1415,7 @@
 	}
 	else if (G.f & G_DEBUG) {
 		printf("ptr.data = %p, prop = %p,", (void *)ptr.data, (void *)prop);
-		if(prop)
+		if (prop)
 			printf("animateable = %d \n", RNA_property_animateable(&ptr, prop));
 		else
 			printf("animateable = NULL \n");
@@ -1416,7 +1424,7 @@
 	if (success) {
 		/* send updates */
 		uiContextAnimUpdate(C);
-
+		
 		DAG_ids_flush_update(bmain, 0);
 		
 		/* send notifiers that keyframes have been changed */
@@ -1488,7 +1496,7 @@
 	if (success) {
 		/* send updates */
 		uiContextAnimUpdate(C);
-
+		
 		DAG_ids_flush_update(bmain, 0);
 		
 		/* send notifiers that keyframes have been changed */

Modified: trunk/blender/source/blender/editors/animation/keyingsets.c
===================================================================
--- trunk/blender/source/blender/editors/animation/keyingsets.c	2011-01-03 04:59:57 UTC (rev 34020)
+++ trunk/blender/source/blender/editors/animation/keyingsets.c	2011-01-03 05:36:52 UTC (rev 34021)
@@ -59,6 +59,7 @@
 
 #include "RNA_access.h"
 #include "RNA_define.h"
+#include "RNA_enum_types.h"
 
 #include "anim_intern.h"
 
@@ -691,6 +692,67 @@
 
 /* Menu of All Keying Sets ----------------------------- */
 
+/* Dynamically populate an enum of Keying Sets */
+EnumPropertyItem *ANIM_keying_sets_enum_itemf (bContext *C, PointerRNA *UNUSED(ptr), int *free)
+{
+	Scene *scene = CTX_data_scene(C);
+	KeyingSet *ks;
+	EnumPropertyItem *item= NULL, item_tmp= {0};
+	int totitem= 0;
+	int i= 0;
+
+	if (C == NULL) {
+		return DummyRNA_DEFAULT_items;
+	}
+	
+	/* active Keying Set 
+	 *	- only include entry if it exists
+	 */
+	if (scene->active_keyingset) {
+		/* active Keying Set */
+		item_tmp.identifier= item_tmp.name= "Active Keying Set";
+		item_tmp.value= i++;
+		RNA_enum_item_add(&item, &totitem, &item_tmp);
+		
+		/* separator */
+		RNA_enum_item_add_separator(&item, &totitem);
+	}
+	else
+		i++;
+		
+	/* user-defined Keying Sets 
+	 *	- these are listed in the order in which they were defined for the active scene
+	 */
+	if (scene->keyingsets.first) {
+		for (ks= scene->keyingsets.first; ks; ks= ks->next) {
+			if (ANIM_keyingset_context_ok_poll(C, ks)) {
+				item_tmp.identifier= item_tmp.name= ks->name;
+				item_tmp.value= i++;
+				RNA_enum_item_add(&item, &totitem, &item_tmp);
+			}
+		}
+		
+		/* separator */
+		RNA_enum_item_add_separator(&item, &totitem);
+	}
+	
+	/* builtin Keying Sets */
+	i= -1;
+	for (ks= builtin_keyingsets.first; ks; ks= ks->next) {
+		/* only show KeyingSet if context is suitable */
+		if (ANIM_keyingset_context_ok_poll(C, ks)) {
+			item_tmp.identifier= item_tmp.name= ks->name;
+			item_tmp.value= i--;
+			RNA_enum_item_add(&item, &totitem, &item_tmp);
+		}
+	}
+
+	RNA_enum_item_end(&item, &totitem);
+	*free= 1;
+
+	return item;
+}
+
 /* Create (and show) a menu containing all the Keying Sets which can be used in the current context */
 void ANIM_keying_sets_menu_setup (bContext *C, const char title[], const char op_name[])
 {

Modified: trunk/blender/source/blender/editors/include/ED_keyframing.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_keyframing.h	2011-01-03 04:59:57 UTC (rev 34020)
+++ trunk/blender/source/blender/editors/include/ED_keyframing.h	2011-01-03 05:36:52 UTC (rev 34021)
@@ -51,6 +51,7 @@
 
 struct PointerRNA;
 struct PropertyRNA;
+struct EnumPropertyItem;
 
 #include "RNA_types.h"
 
@@ -204,6 +205,9 @@
 /* Create (and show) a menu containing all the Keying Sets which can be used in the current context */
 void ANIM_keying_sets_menu_setup(struct bContext *C, const char title[], const char op_name[]);
 
+/* Dynamically populate an enum of Keying Sets */
+struct EnumPropertyItem *ANIM_keying_sets_enum_itemf(struct bContext *C, struct PointerRNA *ptr, int *free);
+
 /* Check if KeyingSet can be used in the current context */
 short ANIM_keyingset_context_ok_poll(struct bContext *C, struct KeyingSet *ks);
 





More information about the Bf-blender-cvs mailing list