Revision: 19048
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19048
Author:   aligorith
Date:     2009-02-20 06:42:09 +0100 (Fri, 20 Feb 2009)

Log Message:
-----------
KeyingSets: Added two operators which wrap the internal (blenkernel) KeyingSets 
API functions

These operators - ANIM_OT_keyingset_add_new() and 
ANIM_OT_keyingset_add_destination() - are designed for use from PyAPI or 
through some other means, and as such, have not been assigned any hotkeys. 
They should only be used when all the relevant settings can be supplied to 
them, which in ideal circumstances would be through some script used by a 
rigger to define all the necessary Keying Sets for their rig for example.

Whether we will be building many of the utilities for the PyAPI like this 
remains to be seen. 

Note: the second one doesn't work yet, as there are problems with accessing 
certain operator props.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/editors/animation/anim_ops.c
    branches/blender2.5/blender/source/blender/editors/animation/keyframing.c
    branches/blender2.5/blender/source/blender/editors/include/ED_keyframing.h

Modified: 
branches/blender2.5/blender/source/blender/editors/animation/anim_ops.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/animation/anim_ops.c     
2009-02-19 23:53:40 UTC (rev 19047)
+++ branches/blender2.5/blender/source/blender/editors/animation/anim_ops.c     
2009-02-20 05:42:09 UTC (rev 19048)
@@ -382,6 +382,9 @@
        WM_operatortype_append(ANIM_OT_delete_keyframe);
        WM_operatortype_append(ANIM_OT_insert_keyframe_old);
        WM_operatortype_append(ANIM_OT_delete_keyframe_old);
+       
+       WM_operatortype_append(ANIM_OT_keyingset_add_new);
+       WM_operatortype_append(ANIM_OT_keyingset_add_destination);
 }
 
 void ED_keymap_anim(wmWindowManager *wm)

Modified: 
branches/blender2.5/blender/source/blender/editors/animation/keyframing.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/animation/keyframing.c   
2009-02-19 23:53:40 UTC (rev 19047)
+++ branches/blender2.5/blender/source/blender/editors/animation/keyframing.c   
2009-02-20 05:42:09 UTC (rev 19048)
@@ -870,15 +870,140 @@
 }
 
 /* ******************************************* */
-/* KEYFRAME MODIFICATION */
+/* KEYINGSETS */
 
-/* mode for common_modifykey */
-enum {
-       COMMONKEY_MODE_INSERT = 0,
-       COMMONKEY_MODE_DELETE,
-} eCommonModifyKey_Modes;
+/* Operators ------------------------------------------- */
 
+/* These operators are only provided for scripting/macro usage, not for direct
+ * calling from the UI since they wrap some of the data-access API code for 
these
+ * (defined in blenkernel) which have quite a few properties.
+ */
 
+/* ----- */
+
+static int keyingset_add_destination_exec (bContext *C, wmOperator *op)
+{
+       //PointerRNA *ptr;
+       KeyingSet *ks= NULL;
+       ID *id= NULL;
+       char rna_path[256], group_name[64]; // xxx
+       short groupmode=0, flag=0;
+       int array_index=0;
+       
+       /* get settings from operator properties */
+#if 0 // XXX - why can't we have something like this in the RNA-access API?
+       if ( (ptr = RNA_property_pointer_get(op->ptr, "keyingset")) )
+               ks= (KeyingSet *)ptr->data;
+       if ( (ptr = RNA_property_pointer_get(op->ptr, "id")) )
+               id= (ID *)ptr->id;
+#endif 
+       
+       groupmode= RNA_enum_get(op->ptr, "grouping_method");
+       RNA_string_get(op->ptr, "group_name", group_name);              
+       
+       RNA_string_get(op->ptr, "rna_path", rna_path);
+       array_index= RNA_int_get(op->ptr, "array_index");
+       
+       if (RNA_boolean_get(op->ptr, "entire_array"))
+               flag |= KSP_FLAG_WHOLE_ARRAY;
+       
+       /* if enough args are provided, call API method */
+       if (ks) {
+               BKE_keyingset_add_destination(ks, id, group_name, rna_path, 
array_index, flag, groupmode);
+               return OPERATOR_FINISHED;
+       }
+       else {
+               BKE_report(op->reports, RPT_ERROR, "Keying Set could not be 
added.");
+               return OPERATOR_CANCELLED;
+       }       
+}
+
+void ANIM_OT_keyingset_add_destination (wmOperatorType *ot)
+{
+       // XXX: this is also defined in rna_animation.c
+       static EnumPropertyItem prop_mode_grouping_items[] = {
+               {KSP_GROUP_NAMED, "NAMED", "Named Group", ""},
+               {KSP_GROUP_NONE, "NONE", "None", ""},
+               {KSP_GROUP_KSNAME, "KEYINGSET", "Keying Set Name", ""},
+               {0, NULL, NULL, NULL}};
+       
+       /* identifiers */
+       ot->name= "Add Keying Set Destination";
+       ot->idname= "ANIM_OT_keyingset_add_destination";
+       
+       /* callbacks */
+       ot->exec= keyingset_add_destination_exec;
+       ot->poll= ED_operator_scene_editable;
+       
+       /* props */
+               /* pointers */ // xxx - do we want to directly expose these?
+       RNA_def_pointer_runtime(ot->srna, "keyingset", &RNA_KeyingSet, "Keying 
Set", "Keying Set to add destination to.");
+       RNA_def_pointer_runtime(ot->srna, "id", &RNA_ID, "ID", "ID-block for 
the destination.");
+               /* grouping */
+       RNA_def_enum(ot->srna, "grouping_method", prop_mode_grouping_items, 
KSP_GROUP_NAMED, "Grouping Method", "Method used to define which Group-name to 
use.");
+       RNA_def_string(ot->srna, "group_name", "", 64, "Group Name", "Name of 
Action Group to assign destination to (only if grouping mode is to use this 
name).");
+               /* rna-path */
+       RNA_def_string(ot->srna, "rna_path", "", 256, "RNA-Path", "RNA-Path to 
destination property."); // xxx hopefully this is long enough
+       RNA_def_int(ot->srna, "array_index", 0, 0, INT_MAX, "Array Index", "If 
applicable, the index ", 0, INT_MAX);
+               /* flags */
+       RNA_def_boolean(ot->srna, "entire_array", 1, "Entire Array", "hen an 
'array/vector' type is chosen (Location, Rotation, Color, etc.), entire array 
is to be used.");
+       
+}
+ 
+/* ----- */
+
+static int keyingset_add_new_exec (bContext *C, wmOperator *op)
+{
+       Scene *sce= CTX_data_scene(C);
+       KeyingSet *ks= NULL;
+       short flag=0, keyingflag=0;
+       char name[64];
+       
+       /* get settings from operator properties */
+       RNA_string_get(op->ptr, "name", name);
+       
+       if (RNA_boolean_get(op->ptr, "absolute"))
+               flag |= KEYINGSET_ABSOLUTE;
+       if (RNA_boolean_get(op->ptr, "insertkey_needed"))
+               keyingflag |= INSERTKEY_NEEDED;
+       if (RNA_boolean_get(op->ptr, "insertkey_visual"))
+               keyingflag |= INSERTKEY_MATRIX;
+               
+       /* call the API func, and set the active keyingset index */
+       ks= BKE_keyingset_add(&sce->keyingsets, name, flag, keyingflag);
+       
+       if (ks) {
+               sce->active_keyingset= BLI_countlist(&sce->keyingsets);
+               return OPERATOR_FINISHED;
+       }
+       else {
+               BKE_report(op->reports, RPT_ERROR, "Keying Set could not be 
added.");
+               return OPERATOR_CANCELLED;
+       }
+}
+
+void ANIM_OT_keyingset_add_new (wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Add Keying Set";
+       ot->idname= "ANIM_OT_keyingset_add_new";
+       
+       /* callbacks */
+       ot->exec= keyingset_add_new_exec;
+       ot->poll= ED_operator_scene_editable;
+       
+       /* props */
+               /* name */
+       RNA_def_string(ot->srna, "name", "KeyingSet", 64, "Name", "Name of 
Keying Set");
+               /* flags */
+       RNA_def_boolean(ot->srna, "absolute", 1, "Absolute", "Keying Set 
defines specifc paths/settings to be keyframed (i.e. is not reliant on context 
info)");
+               /* keying flags */
+       RNA_def_boolean(ot->srna, "insertkey_needed", 0, "Insert Keyframes - 
Only Needed", "Only insert keyframes where they're needed in the relevant 
F-Curves.");
+       RNA_def_boolean(ot->srna, "insertkey_visual", 0, "Insert Keyframes - 
Visual", "Insert keyframes based on 'visual transforms'.");
+}
+
+/* UI API --------------------------------------------- */
+
 /* Build menu-string of available keying-sets (allocates memory for string)
  * NOTE: mode must not be longer than 64 chars
  */
@@ -918,6 +1043,17 @@
        return str;
 }
 
+
+
+/* ******************************************* */
+/* KEYFRAME MODIFICATION */
+
+/* mode for common_modifykey */
+enum {
+       COMMONKEY_MODE_INSERT = 0,
+       COMMONKEY_MODE_DELETE,
+} eCommonModifyKey_Modes;
+
 #if 0 // XXX old keyingsets code based on adrcodes... to be restored in due 
course
 
 /* --------- KeyingSet Adrcode Getters ------------ */

Modified: 
branches/blender2.5/blender/source/blender/editors/include/ED_keyframing.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/include/ED_keyframing.h  
2009-02-19 23:53:40 UTC (rev 19047)
+++ branches/blender2.5/blender/source/blender/editors/include/ED_keyframing.h  
2009-02-20 05:42:09 UTC (rev 19048)
@@ -69,6 +69,13 @@
 /* Generate menu of KeyingSets */
 char *ANIM_build_keyingsets_menu(struct ListBase *list, short for_edit);
 
+/* KeyingSet Editing Operators:
+ *     These can add a new KeyingSet and/or add 'destinations' to the 
KeyingSets,
+ *     acting as a means by which they can be added outside the Outliner.
+ */
+void ANIM_OT_keyingset_add_new(struct wmOperatorType *ot);
+void ANIM_OT_keyingset_add_destination(struct wmOperatorType *ot);
+
 /* Main Keyframe Management operators: 
  *     These handle keyframes management from various spaces. They only make 
use of
  *     Keying Sets.


_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to