More assorted Keying Sets changes for Cessen (mainly api stuff):

* Added operator (Ctrl Shift Alt I) to show menu for changing the active Keying Set in the 3D view (todo item from last commit)

* KeyingSetInfo (i.e. the Builtin Keying Set classes) can now be accessed from Keying Set instances with  ks.type_info
* Added ks.remove_all_paths() function to remove all the paths for a Keying Set. 

---

These two changes mean that builtin Keying Sets could be refreshed in response to context changes by doing:
<code>
ks = bpy.context.scene.active_keying_set
if ks.absolute==False and ks.type_info:
    ksi = ks.type_info

    # remove existing paths to fill with new
    ks.remove_all_paths()

    # check if Keying Set can be used in current context
    if ksi.poll(bpy.context):
        # call iterator() which calls generate() and re-populates paths list
        ksi.iterator(bpy.context, ks) 
</code>

And then, once this has been done, the paths that the Keying Set will operate on can be accessed as
<code>
paths = bpy.context.scene.active_keying_set.paths
</code>
This commit is contained in:
2010-03-25 11:34:18 +00:00
parent 57b2ea62ab
commit b88278b62b
9 changed files with 158 additions and 63 deletions

View File

@@ -65,6 +65,9 @@ void ANIM_OT_keying_set_remove(struct wmOperatorType *ot);
void ANIM_OT_keying_set_path_add(struct wmOperatorType *ot);
void ANIM_OT_keying_set_path_remove(struct wmOperatorType *ot);
/* KeyingSet general operators */
void ANIM_OT_keying_set_active_set(struct wmOperatorType *ot);
/* .......... */
/* Driver management operators for UI buttons (RMB menu) */

View File

@@ -361,6 +361,8 @@ void ED_operatortypes_anim(void)
WM_operatortype_append(ANIM_OT_keying_set_remove);
WM_operatortype_append(ANIM_OT_keying_set_path_add);
WM_operatortype_append(ANIM_OT_keying_set_path_remove);
WM_operatortype_append(ANIM_OT_keying_set_active_set);
}
void ED_keymap_anim(wmKeyConfig *keyconf)

View File

@@ -1144,52 +1144,9 @@ void ANIM_OT_keyframe_insert (wmOperatorType *ot)
/* Insert Key Operator (With Menu) ------------------------ */
/* This operator checks if a menu should be shown for choosing the KeyingSet to use,
* then calls the
* then calls the menu if necessary before
*/
static void insert_key_menu_prompt (bContext *C)
{
Scene *scene= CTX_data_scene(C);
KeyingSet *ks;
uiPopupMenu *pup;
uiLayout *layout;
int i = 0;
pup= uiPupMenuBegin(C, "Insert Keyframe", 0);
layout= uiPupMenuLayout(pup);
/* active Keying Set
* - only include entry if it exists
*/
if (scene->active_keyingset) {
uiItemIntO(layout, "Active Keying Set", 0, "ANIM_OT_keyframe_insert_menu", "type", i++);
uiItemS(layout);
}
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))
uiItemIntO(layout, ks->name, 0, "ANIM_OT_keyframe_insert_menu", "type", i++);
}
uiItemS(layout);
}
/* 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))
uiItemIntO(layout, ks->name, 0, "ANIM_OT_keyframe_insert_menu", "type", i--);
}
uiPupMenuEnd(C, pup);
}
static int insert_key_menu_invoke (bContext *C, wmOperator *op, wmEvent *event)
{
Scene *scene= CTX_data_scene(C);
@@ -1197,7 +1154,7 @@ static int insert_key_menu_invoke (bContext *C, wmOperator *op, wmEvent *event)
/* if prompting or no active Keying Set, show the menu */
if ((scene->active_keyingset == 0) || RNA_boolean_get(op->ptr, "always_prompt")) {
/* call the menu, which will call this operator again, hence the cancelled */
insert_key_menu_prompt(C);
ANIM_keying_sets_menu_setup(C, op->type->name, "ANIM_OT_keyframe_insert_menu");
return OPERATOR_CANCELLED;
}
else {

View File

@@ -45,6 +45,7 @@
#include "BKE_animsys.h"
#include "BKE_action.h"
#include "BKE_context.h"
#include "BKE_constraint.h"
#include "BKE_depsgraph.h"
#include "BKE_fcurve.h"
@@ -55,6 +56,7 @@
#include "BKE_material.h"
#include "ED_keyframing.h"
#include "ED_screen.h"
#include "UI_interface.h"
@@ -449,6 +451,55 @@ void ANIM_OT_keyingset_button_remove (wmOperatorType *ot)
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
/* ******************************************* */
/* Change Active KeyingSet Operator ------------------------ */
/* This operator checks if a menu should be shown for choosing the KeyingSet to make the active one */
static int keyingset_active_menu_invoke (bContext *C, wmOperator *op, wmEvent *event)
{
/* call the menu, which will call this operator again, hence the cancelled */
ANIM_keying_sets_menu_setup(C, op->type->name, "ANIM_OT_keying_set_active_set");
return OPERATOR_CANCELLED;
}
static int keyingset_active_menu_exec (bContext *C, wmOperator *op)
{
Scene *scene= CTX_data_scene(C);
int type= RNA_int_get(op->ptr, "type");
/* simply set the scene's active keying set index, unless the type == 0
* (i.e. which happens if we want the current active to be maintained)
*/
if (type)
scene->active_keyingset= type;
/* send notifiers */
WM_event_add_notifier(C, NC_SCENE|ND_KEYINGSET, NULL);
return OPERATOR_FINISHED;
}
void ANIM_OT_keying_set_active_set (wmOperatorType *ot)
{
/* identifiers */
ot->name= "Set Active Keying Set";
ot->idname= "ANIM_OT_keying_set_active_set";
/* callbacks */
ot->invoke= keyingset_active_menu_invoke;
ot->exec= keyingset_active_menu_exec;
ot->poll= ED_operator_areaactive;
/* 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);
}
/* ******************************************* */
/* REGISTERED KEYING SETS */
@@ -569,6 +620,8 @@ void ANIM_keyingset_infos_exit ()
/* ******************************************* */
/* KEYING SETS API (for UI) */
/* Getters for Active/Indices ----------------------------- */
/* Get the active Keying Set for the Scene provided */
KeyingSet *ANIM_scene_get_active_keyingset (Scene *scene)
{
@@ -617,6 +670,57 @@ int ANIM_scene_get_keyingset_index (Scene *scene, KeyingSet *ks)
return 0;
}
/* Menu of All Keying Sets ----------------------------- */
/* 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, char title[], char op_name[])
{
Scene *scene= CTX_data_scene(C);
KeyingSet *ks;
uiPopupMenu *pup;
uiLayout *layout;
int i = 0;
pup= uiPupMenuBegin(C, title, 0);
layout= uiPupMenuLayout(pup);
/* active Keying Set
* - only include entry if it exists
*/
if (scene->active_keyingset) {
uiItemIntO(layout, "Active Keying Set", 0, op_name, "type", i++);
uiItemS(layout);
}
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))
uiItemIntO(layout, ks->name, 0, op_name, "type", i++);
}
uiItemS(layout);
}
/* 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))
uiItemIntO(layout, ks->name, 0, op_name, "type", i--);
}
uiPupMenuEnd(C, pup);
}
/* ******************************************* */
/* KEYFRAME MODIFICATION */
/* Polling API ----------------------------------------------- */
/* Check if KeyingSet can be used in the current context */
short ANIM_keyingset_context_ok_poll (bContext *C, KeyingSet *ks)
{
@@ -635,9 +739,6 @@ short ANIM_keyingset_context_ok_poll (bContext *C, KeyingSet *ks)
return 1;
}
/* ******************************************* */
/* KEYFRAME MODIFICATION */
/* Special 'Overrides' Iterator for Relative KeyingSets ------ */
/* 'Data Sources' for relative Keying Set 'overrides'

View File

@@ -339,6 +339,7 @@ void ED_keymap_armature(wmKeyConfig *keyconf)
// XXX this should probably be in screen instead... here for testing purposes in the meantime... - Aligorith
WM_keymap_verify_item(keymap, "ANIM_OT_keyframe_insert_menu", IKEY, KM_PRESS, 0, 0);
WM_keymap_verify_item(keymap, "ANIM_OT_keyframe_delete_v3d", IKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_verify_item(keymap, "ANIM_OT_keying_set_active_set", IKEY, KM_PRESS, KM_CTRL|KM_SHIFT|KM_ALT, 0);
/* Pose -> PoseLib ------------- */
/* only set in posemode, by space_view3d listener */

View File

@@ -193,6 +193,9 @@ struct KeyingSet *ANIM_scene_get_active_keyingset(struct Scene *scene);
/* Get the index of the Keying Set provided, for the given Scene */
int ANIM_scene_get_keyingset_index(struct Scene *scene, struct KeyingSet *ks);
/* 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, char title[], char op_name[]);
/* Check if KeyingSet can be used in the current context */
short ANIM_keyingset_context_ok_poll(struct bContext *C, struct KeyingSet *ks);

View File

@@ -337,6 +337,7 @@ void ED_keymap_object(wmKeyConfig *keyconf)
// XXX this should probably be in screen instead... here for testing purposes in the meantime... - Aligorith
WM_keymap_verify_item(keymap, "ANIM_OT_keyframe_insert_menu", IKEY, KM_PRESS, 0, 0);
WM_keymap_verify_item(keymap, "ANIM_OT_keyframe_delete_v3d", IKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_verify_item(keymap, "ANIM_OT_keying_set_active_set", IKEY, KM_PRESS, KM_CTRL|KM_SHIFT|KM_ALT, 0);
WM_keymap_verify_item(keymap, "GROUP_OT_create", GKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_verify_item(keymap, "GROUP_OT_objects_remove", GKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);

View File

@@ -269,14 +269,6 @@ static void rna_ksPath_RnaPath_set(PointerRNA *ptr, const char *value)
/* ****************************** */
static int rna_KeyingSet_typeinfo_name_editable(PointerRNA *ptr)
{
KeyingSet *ks= (KeyingSet *)ptr->data;
/* only editable if we're using relative paths */
return ((ks->flag & KEYINGSET_ABSOLUTE)==0);
}
static int rna_KeyingSet_active_ksPath_editable(PointerRNA *ptr)
{
KeyingSet *ks= (KeyingSet *)ptr->data;
@@ -319,6 +311,17 @@ static void rna_KeyingSet_active_ksPath_index_range(PointerRNA *ptr, int *min, i
*max= MAX2(0, *max);
}
static PointerRNA rna_KeyingSet_typeinfo_get(PointerRNA *ptr)
{
KeyingSet *ks= (KeyingSet *)ptr->data;
KeyingSetInfo *ksi = NULL;
/* keying set info is only for builtin Keying Sets */
if ((ks->flag & KEYINGSET_ABSOLUTE)==0)
ksi = ANIM_keyingset_info_find_named(ks->typeinfo);
return rna_pointer_inherit_refine(ptr, &RNA_KeyingSetInfo, ksi);
}
#else
/* helper function for Keying Set -> keying settings */
@@ -353,7 +356,7 @@ static void rna_def_keyingset_info(BlenderRNA *brna)
srna= RNA_def_struct(brna, "KeyingSetInfo", NULL);
RNA_def_struct_sdna(srna, "KeyingSetInfo");
RNA_def_struct_ui_text(srna, "Keying Set Info", "Callback function defines for relative Keying Sets");
RNA_def_struct_ui_text(srna, "Keying Set Info", "Callback function defines for builtin Keying Sets");
RNA_def_struct_refine_func(srna, "rna_KeyingSetInfo_refine");
RNA_def_struct_register_funcs(srna, "rna_KeyingSetInfo_register", "rna_KeyingSetInfo_unregister");
@@ -472,12 +475,11 @@ static void rna_def_keyingset(BlenderRNA *brna)
RNA_def_struct_ui_icon(srna, ICON_KEY_HLT); // TODO: we need a dedicated icon
RNA_def_struct_name_property(srna, prop);
/* TypeInfo associated with Relative KeyingSet (only) */
prop= RNA_def_property(srna, "typeinfo_name", PROP_STRING, PROP_NONE);
RNA_def_property_flag(prop, PROP_EDITABLE);
RNA_def_property_string_sdna(prop, NULL, "typeinfo");
RNA_def_property_editable_func(prop, "rna_KeyingSet_typeinfo_name_editable");
RNA_def_property_ui_text(prop, "TypeInfo Name", "");
/* KeyingSetInfo (Type Info) for Builtin Sets only */
prop= RNA_def_property(srna, "type_info", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "KeyingSetInfo");
RNA_def_property_pointer_funcs(prop, "rna_KeyingSet_typeinfo_get", NULL, NULL);
RNA_def_property_ui_text(prop, "Type Info", "Callback function defines for builtin Keying Sets");
/* Paths */
prop= RNA_def_property(srna, "paths", PROP_COLLECTION, PROP_NONE);

View File

@@ -81,6 +81,26 @@ static void rna_KeyingSet_remove_path(KeyingSet *keyingset, ReportList *reports,
}
}
static void rna_KeyingSet_remove_all_paths(KeyingSet *keyingset, ReportList *reports)
{
/* if data is valid, call the API function for this */
if (keyingset) {
KS_Path *ksp, *kspn;
/* free each path as we go to avoid looping twice */
for (ksp= keyingset->paths.first; ksp; ksp= kspn) {
kspn= ksp->next;
BKE_keyingset_free_path(keyingset, ksp);
}
/* reset the active path, since there aren't any left */
keyingset->active_path = 0;
}
else {
BKE_report(reports, RPT_ERROR, "Keying Set Paths could not be removed.");
}
}
#else
void RNA_api_keyingset(StructRNA *srna)
@@ -114,6 +134,11 @@ void RNA_api_keyingset(StructRNA *srna)
/* path to remove */
parm= RNA_def_pointer(func, "path", "KeyingSetPath", "Path", "");
RNA_def_property_flag(parm, PROP_REQUIRED);
/* Remove All Paths */
func= RNA_def_function(srna, "remove_all_paths", "rna_KeyingSet_remove_all_paths");
RNA_def_function_ui_description(func, "Remove all the paths from the Keying Set.");
RNA_def_function_flag(func, FUNC_USE_REPORTS);
}
#endif