[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39412] branches/soc-2011-pepper/source/ blender: Select by Keying Set...

Joshua Leung aligorith at gmail.com
Mon Aug 15 12:37:26 CEST 2011


Revision: 39412
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39412
Author:   aligorith
Date:     2011-08-15 10:37:26 +0000 (Mon, 15 Aug 2011)
Log Message:
-----------
Select by Keying Set...
* Split off code to refresh relative/builtin KeyingSets for the
current context before they get used to a separate function.
* Hooked this up to a new PyAPI/RNA function: KeyingSet.refresh().
Call this before checking the paths that a Keying Set has, especially
if it is not "absolute"

* Added option for "Select Grouped" operator (for Objects), which will
select all objects affected by the active Keying Set. This is probably
more useful for absolute KeyingSets, where changing the selection is
less likely to affect the result.
- The equivalent for bones is currently still in development, but is
likely to be more useful for animators, where rigs are the primary
animation entities they deal with

Modified Paths:
--------------
    branches/soc-2011-pepper/source/blender/editors/animation/keyingsets.c
    branches/soc-2011-pepper/source/blender/editors/include/ED_keyframing.h
    branches/soc-2011-pepper/source/blender/editors/object/object_select.c
    branches/soc-2011-pepper/source/blender/makesrna/intern/rna_animation_api.c

Modified: branches/soc-2011-pepper/source/blender/editors/animation/keyingsets.c
===================================================================
--- branches/soc-2011-pepper/source/blender/editors/animation/keyingsets.c	2011-08-15 10:18:02 UTC (rev 39411)
+++ branches/soc-2011-pepper/source/blender/editors/animation/keyingsets.c	2011-08-15 10:37:26 UTC (rev 39412)
@@ -875,33 +875,19 @@
 
 /* KeyingSet Operations (Insert/Delete Keyframes) ------------ */
 
-/* Given a KeyingSet and context info (if required), modify keyframes for the channels specified
- * by the KeyingSet. This takes into account many of the different combinations of using KeyingSets.
- * Returns the number of channels that keyframes were added to
+/* Given a KeyingSet and context info, validate Keying Set's paths.
+ * This is only really necessary with relative/built-in KeyingSets
+ * where their list of paths is dynamically generated based on the
+ * current context info.
+ *
+ * Returns 0 if succeeded, otherwise an error code: eModifyKey_Returns
  */
-int ANIM_apply_keyingset (bContext *C, ListBase *dsources, bAction *act, KeyingSet *ks, short mode, float cfra)
+short ANIM_validate_keyingset (bContext *C, ListBase *dsources, KeyingSet *ks)
 {
-	Scene *scene= CTX_data_scene(C);
-	ReportList *reports = CTX_wm_reports(C);
-	KS_Path *ksp;
-	int kflag=0, success= 0;
-	char *groupname= NULL;
-	
-	/* sanity checks */
+	/* sanity check */
 	if (ks == NULL)
 		return 0;
 	
-	/* get flags to use */
-	if (mode == MODIFYKEY_MODE_INSERT) {
-		/* use KeyingSet's flags as base */
-		kflag= ks->keyingflag;
-		
-		/* suppliment with info from the context */
-		kflag |= ANIM_get_keyframing_flags(scene, 1);
-	}
-	else if (mode == MODIFYKEY_MODE_DELETE)
-		kflag= 0;
-	
 	/* if relative Keying Sets, poll and build up the paths */
 	if ((ks->flag & KEYINGSET_ABSOLUTE) == 0) {
 		KeyingSetInfo *ksi = ANIM_keyingset_info_find_named(ks->typeinfo);
@@ -936,6 +922,45 @@
 		}
 	}
 	
+	/* succeeded; return 0 to tag error free */
+	return 0;
+} 
+
+/* Given a KeyingSet and context info (if required), modify keyframes for the channels specified
+ * by the KeyingSet. This takes into account many of the different combinations of using KeyingSets.
+ * Returns the number of channels that keyframes were added to
+ */
+int ANIM_apply_keyingset (bContext *C, ListBase *dsources, bAction *act, KeyingSet *ks, short mode, float cfra)
+{
+	Scene *scene= CTX_data_scene(C);
+	ReportList *reports = CTX_wm_reports(C);
+	KS_Path *ksp;
+	int kflag=0, success= 0;
+	char *groupname= NULL;
+	
+	/* sanity checks */
+	if (ks == NULL)
+		return 0;
+	
+	/* get flags to use */
+	if (mode == MODIFYKEY_MODE_INSERT) {
+		/* use KeyingSet's flags as base */
+		kflag= ks->keyingflag;
+		
+		/* suppliment with info from the context */
+		kflag |= ANIM_get_keyframing_flags(scene, 1);
+	}
+	else if (mode == MODIFYKEY_MODE_DELETE)
+		kflag= 0;
+	
+	/* if relative Keying Sets, poll and build up the paths */
+	success = ANIM_validate_keyingset(C, dsources, ks);
+	
+	if (success != 0) {
+		/* return error code if failed */
+		return success;
+	}
+	
 	/* apply the paths as specified in the KeyingSet now */
 	for (ksp= ks->paths.first; ksp; ksp= ksp->next) { 
 		int arraylen, i;

Modified: branches/soc-2011-pepper/source/blender/editors/include/ED_keyframing.h
===================================================================
--- branches/soc-2011-pepper/source/blender/editors/include/ED_keyframing.h	2011-08-15 10:18:02 UTC (rev 39411)
+++ branches/soc-2011-pepper/source/blender/editors/include/ED_keyframing.h	2011-08-15 10:37:26 UTC (rev 39412)
@@ -176,6 +176,9 @@
 	MODIFYKEY_MISSING_TYPEINFO = -2,
 } eModifyKey_Returns;
 
+/* poll the current KeyingSet, updating it's set of paths (if "builtin"/"relative") for context changes */
+short ANIM_validate_keyingset(struct bContext *C, ListBase *dsources, struct KeyingSet *ks);
+
 /* use the specified KeyingSet to add/remove various Keyframes on the specified frame */
 int ANIM_apply_keyingset(struct bContext *C, ListBase *dsources, struct bAction *act, struct KeyingSet *ks, short mode, float cfra);
 

Modified: branches/soc-2011-pepper/source/blender/editors/object/object_select.c
===================================================================
--- branches/soc-2011-pepper/source/blender/editors/object/object_select.c	2011-08-15 10:18:02 UTC (rev 39411)
+++ branches/soc-2011-pepper/source/blender/editors/object/object_select.c	2011-08-15 10:37:26 UTC (rev 39412)
@@ -37,6 +37,7 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "DNA_anim_types.h"
 #include "DNA_group_types.h"
 #include "DNA_material_types.h"
 #include "DNA_modifier_types.h"
@@ -65,6 +66,7 @@
 
 #include "ED_object.h"
 #include "ED_screen.h"
+#include "ED_keyframing.h"
 
 #include "UI_interface.h"
 #include "UI_resources.h"
@@ -363,6 +365,7 @@
 	{9, "PASS", 0, "Pass", "Render pass Index"},
 	{10, "COLOR", 0, "Color", "Object Color"},
 	{11, "PROPERTIES", 0, "Properties", "Game Properties"},
+	{12, "KEYINGSET", 0, "Keying Set", "Objects included in active Keying Set"},
 	{0, NULL, 0, NULL, NULL}
 };
 
@@ -574,6 +577,42 @@
 	return changed;
 }
 
+static short select_grouped_keyingset(bContext *C, Object *UNUSED(ob))
+{
+	KeyingSet *ks = ANIM_scene_get_active_keyingset(CTX_data_scene(C));
+	short changed = 0;
+	
+	/* firstly, validate KeyingSet */
+	if ((ks == NULL) || (ANIM_validate_keyingset(C, NULL, ks) != 0))
+		return 0;
+	
+	/* select each object that Keying Set refers to */
+	// TODO: perhaps to be more in line with the rest of these, we should only take objects 
+	// if the passed in object is included in this too
+	CTX_DATA_BEGIN(C, Base*, base, selectable_bases) 
+	{
+		/* only check for this object if it isn't selected already, to limit time wasted */
+		if ((base->flag & SELECT) == 0) {
+			KS_Path *ksp;
+			
+			/* this is the slow way... we could end up with > 500 items here, 
+			 * with none matching, but end up doing this on 1000 objects...
+			 */
+			for (ksp = ks->paths.first; ksp; ksp = ksp->next) {
+				/* if id matches, select then stop looping (match found) */
+				if (ksp->id == base->object) {
+					ED_base_object_select(base, BA_SELECT);
+					changed = 1;
+					break;
+				}
+			}
+		}
+	}
+	CTX_DATA_END;
+		
+	return changed;
+}
+
 static int object_select_grouped_exec(bContext *C, wmOperator *op)
 {
 	Scene *scene= CTX_data_scene(C);
@@ -608,6 +647,7 @@
 	else if(nr==9)	changed |= select_grouped_index_object(C, ob);
 	else if(nr==10)	changed |= select_grouped_color(C, ob);
 	else if(nr==11)	changed |= select_grouped_gameprops(C, ob);
+	else if(nr==12) changed |= select_grouped_keyingset(C, ob);
 	
 	if (changed) {
 		WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));

Modified: branches/soc-2011-pepper/source/blender/makesrna/intern/rna_animation_api.c
===================================================================
--- branches/soc-2011-pepper/source/blender/makesrna/intern/rna_animation_api.c	2011-08-15 10:18:02 UTC (rev 39411)
+++ branches/soc-2011-pepper/source/blender/makesrna/intern/rna_animation_api.c	2011-08-15 10:37:26 UTC (rev 39412)
@@ -39,16 +39,43 @@
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 
+
 #ifdef RNA_RUNTIME
 
-#include "BKE_animsys.h"
+#include "BKE_context.h"
+#include "BKE_report.h"
 
+#include "ED_keyframing.h"
+
+static void rna_KeyingSet_context_refresh(KeyingSet *ks, bContext *C, ReportList *reports)
+{
+	// TODO: enable access to providing a list of overrides (dsources)?
+	int success = ANIM_validate_keyingset(C, NULL, ks);
+	
+	if (success != 0) {
+		switch (success) {
+			case MODIFYKEY_INVALID_CONTEXT:
+				BKE_report(reports, RPT_ERROR, "Invalid context for Keying Set");
+				break;
+				
+			case MODIFYKEY_MISSING_TYPEINFO:
+				BKE_report(reports, RPT_ERROR, "Incomplete built-in Keying Set. Appears to be missing type info");
+				break;
+		}
+	}
+}
+
 #else
 
 void RNA_api_keyingset(StructRNA *srna)
 {
-//	FunctionRNA *func;
-//	PropertyRNA *parm;
+	FunctionRNA *func;
+	//PropertyRNA *parm;
+	
+	/* validate relative Keying Set (used to ensure paths are ok for context) */
+	func= RNA_def_function(srna, "refresh", "rna_KeyingSet_context_refresh");
+	RNA_def_function_ui_description(func, "Refresh Keying Set to ensure that it is valid for the current context. Call before each use of one");
+	RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
 }
 
 #endif




More information about the Bf-blender-cvs mailing list