Blender V2.61 - r43446

rna_animation.c

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * Contributor(s): Blender Foundation (2009), Joshua Leung
00019  *
00020  * ***** END GPL LICENSE BLOCK *****
00021  */
00022 
00028 #include <stdlib.h>
00029 
00030 #include "RNA_access.h"
00031 #include "RNA_define.h"
00032 #include "RNA_enum_types.h"
00033 
00034 #include "rna_internal.h"
00035 
00036 #include "DNA_anim_types.h"
00037 #include "DNA_action_types.h"
00038 #include "DNA_scene_types.h"
00039 
00040 #include "MEM_guardedalloc.h"
00041 
00042 #include "ED_keyframing.h"
00043 
00044 #include "WM_types.h"
00045 
00046 /* exported for use in API */
00047 EnumPropertyItem keyingset_path_grouping_items[] = {
00048     {KSP_GROUP_NAMED, "NAMED", 0, "Named Group", ""},
00049     {KSP_GROUP_NONE, "NONE", 0, "None", ""},
00050     {KSP_GROUP_KSNAME, "KEYINGSET", 0, "Keying Set Name", ""},
00051     {0, NULL, 0, NULL, NULL}};
00052 
00053 #ifdef RNA_RUNTIME
00054 
00055 #include "BKE_animsys.h"
00056 #include "BKE_fcurve.h"
00057 #include "BKE_nla.h"
00058 
00059 #include "WM_api.h"
00060 
00061 static int rna_AnimData_action_editable(PointerRNA *ptr)
00062 {
00063     AnimData *adt= (AnimData *)ptr->data;
00064     
00065     /* active action is only editable when it is not a tweaking strip */
00066     if ((adt->flag & ADT_NLA_EDIT_ON) || (adt->actstrip) || (adt->tmpact))
00067         return 0;
00068     else
00069         return 1;
00070 }
00071 
00072 static void rna_AnimData_action_set(PointerRNA *ptr, PointerRNA value)
00073 {
00074     ID *ownerId = (ID *)ptr->id.data;
00075     BKE_animdata_set_action(NULL, ownerId, value.data);
00076 }
00077 
00078 /* ****************************** */
00079 
00080 /* wrapper for poll callback */
00081 static int RKS_POLL_rna_internal(KeyingSetInfo *ksi, bContext *C)
00082 {
00083     extern FunctionRNA rna_KeyingSetInfo_poll_func;
00084 
00085     PointerRNA ptr;
00086     ParameterList list;
00087     FunctionRNA *func;
00088     void *ret;
00089     int ok;
00090 
00091     RNA_pointer_create(NULL, ksi->ext.srna, ksi, &ptr);
00092     func= &rna_KeyingSetInfo_poll_func; /* RNA_struct_find_function(&ptr, "poll"); */
00093 
00094     RNA_parameter_list_create(&list, &ptr, func);
00095         /* hook up arguments */
00096         RNA_parameter_set_lookup(&list, "ksi", &ksi);
00097         RNA_parameter_set_lookup(&list, "context", &C);
00098         
00099         /* execute the function */
00100         ksi->ext.call(C, &ptr, func, &list);
00101         
00102         /* read the result */
00103         RNA_parameter_get_lookup(&list, "ok", &ret);
00104         ok= *(int*)ret;
00105     RNA_parameter_list_free(&list);
00106     
00107     return ok;
00108 }
00109 
00110 /* wrapper for iterator callback */
00111 static void RKS_ITER_rna_internal(KeyingSetInfo *ksi, bContext *C, KeyingSet *ks)
00112 {
00113     extern FunctionRNA rna_KeyingSetInfo_iterator_func;
00114 
00115     PointerRNA ptr;
00116     ParameterList list;
00117     FunctionRNA *func;
00118 
00119     RNA_pointer_create(NULL, ksi->ext.srna, ksi, &ptr);
00120     func= &rna_KeyingSetInfo_iterator_func; /* RNA_struct_find_function(&ptr, "poll"); */
00121 
00122     RNA_parameter_list_create(&list, &ptr, func);
00123         /* hook up arguments */
00124         RNA_parameter_set_lookup(&list, "ksi", &ksi);
00125         RNA_parameter_set_lookup(&list, "context", &C);
00126         RNA_parameter_set_lookup(&list, "ks", &ks);
00127         
00128         /* execute the function */
00129         ksi->ext.call(C, &ptr, func, &list);
00130     RNA_parameter_list_free(&list);
00131 }
00132 
00133 /* wrapper for generator callback */
00134 static void RKS_GEN_rna_internal(KeyingSetInfo *ksi, bContext *C, KeyingSet *ks, PointerRNA *data)
00135 {
00136     extern FunctionRNA rna_KeyingSetInfo_generate_func;
00137 
00138     PointerRNA ptr;
00139     ParameterList list;
00140     FunctionRNA *func;
00141 
00142     RNA_pointer_create(NULL, ksi->ext.srna, ksi, &ptr);
00143     func= &rna_KeyingSetInfo_generate_func; /* RNA_struct_find_generate(&ptr, "poll"); */
00144 
00145     RNA_parameter_list_create(&list, &ptr, func);
00146         /* hook up arguments */
00147         RNA_parameter_set_lookup(&list, "ksi", &ksi);
00148         RNA_parameter_set_lookup(&list, "context", &C);
00149         RNA_parameter_set_lookup(&list, "ks", &ks);
00150         RNA_parameter_set_lookup(&list, "data", data);
00151         
00152         /* execute the function */
00153         ksi->ext.call(C, &ptr, func, &list);
00154     RNA_parameter_list_free(&list);
00155 }
00156 
00157 /* ------ */
00158 
00159 // XXX: the exact purpose of this is not too clear... maybe we want to revise this at some point?
00160 static StructRNA *rna_KeyingSetInfo_refine(PointerRNA *ptr)
00161 {
00162     KeyingSetInfo *ksi= (KeyingSetInfo *)ptr->data;
00163     return (ksi->ext.srna)? ksi->ext.srna: &RNA_KeyingSetInfo;
00164 }
00165 
00166 static void rna_KeyingSetInfo_unregister(Main *bmain, StructRNA *type)
00167 {
00168     KeyingSetInfo *ksi= RNA_struct_blender_type_get(type);
00169 
00170     if (ksi == NULL)
00171         return;
00172     
00173     /* free RNA data referencing this */
00174     RNA_struct_free_extension(type, &ksi->ext);
00175     RNA_struct_free(&BLENDER_RNA, type);
00176     
00177     /* unlink Blender-side data */
00178     ANIM_keyingset_info_unregister(bmain, ksi);
00179 }
00180 
00181 static StructRNA *rna_KeyingSetInfo_register(Main *bmain, ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
00182 {
00183     KeyingSetInfo dummyksi = {NULL};
00184     KeyingSetInfo *ksi;
00185     PointerRNA dummyptr = {{NULL}};
00186     int have_function[3];
00187 
00188     /* setup dummy type info to store static properties in */
00189     // TODO: perhaps we want to get users to register as if they're using 'KeyingSet' directly instead?
00190     RNA_pointer_create(NULL, &RNA_KeyingSetInfo, &dummyksi, &dummyptr);
00191     
00192     /* validate the python class */
00193     if (validate(&dummyptr, data, have_function) != 0)
00194         return NULL;
00195     
00196     if (strlen(identifier) >= sizeof(dummyksi.idname)) {
00197         BKE_reportf(reports, RPT_ERROR, "Registering keying set info class: '%s' is too long, maximum length is %d", identifier, (int)sizeof(dummyksi.idname));
00198         return NULL;
00199     }
00200     
00201     /* check if we have registered this info before, and remove it */
00202     ksi = ANIM_keyingset_info_find_named(dummyksi.idname);
00203     if (ksi && ksi->ext.srna)
00204         rna_KeyingSetInfo_unregister(bmain, ksi->ext.srna);
00205     
00206     /* create a new KeyingSetInfo type */
00207     ksi= MEM_callocN(sizeof(KeyingSetInfo), "python keying set info");
00208     memcpy(ksi, &dummyksi, sizeof(KeyingSetInfo));
00209     
00210     /* set RNA-extensions info */
00211     ksi->ext.srna= RNA_def_struct(&BLENDER_RNA, ksi->idname, "KeyingSetInfo"); 
00212     ksi->ext.data= data;
00213     ksi->ext.call= call;
00214     ksi->ext.free= free;
00215     RNA_struct_blender_type_set(ksi->ext.srna, ksi);
00216     
00217     /* set callbacks */
00218     // NOTE: we really should have all of these... 
00219     ksi->poll= (have_function[0])? RKS_POLL_rna_internal: NULL;
00220     ksi->iter= (have_function[1])? RKS_ITER_rna_internal: NULL;
00221     ksi->generate= (have_function[2])? RKS_GEN_rna_internal: NULL;
00222     
00223     /* add and register with other info as needed */
00224     ANIM_keyingset_info_register(ksi);
00225     
00226     /* return the struct-rna added */
00227     return ksi->ext.srna;
00228 }
00229 
00230 /* ****************************** */
00231 
00232 static StructRNA *rna_ksPath_id_typef(PointerRNA *ptr)
00233 {
00234     KS_Path *ksp= (KS_Path*)ptr->data;
00235     return ID_code_to_RNA_type(ksp->idtype);
00236 }
00237 
00238 static int rna_ksPath_id_editable(PointerRNA *ptr)
00239 {
00240     KS_Path *ksp= (KS_Path*)ptr->data;
00241     return (ksp->idtype)? PROP_EDITABLE : 0;
00242 }
00243 
00244 static void rna_ksPath_id_type_set(PointerRNA *ptr, int value)
00245 {
00246     KS_Path *data= (KS_Path*)(ptr->data);
00247     
00248     /* set the driver type, then clear the id-block if the type is invalid */
00249     data->idtype= value;
00250     if ((data->id) && (GS(data->id->name) != data->idtype))
00251         data->id= NULL;
00252 }
00253 
00254 static void rna_ksPath_RnaPath_get(PointerRNA *ptr, char *value)
00255 {
00256     KS_Path *ksp= (KS_Path *)ptr->data;
00257 
00258     if (ksp->rna_path)
00259         strcpy(value, ksp->rna_path);
00260     else
00261         value[0]= '\0';
00262 }
00263 
00264 static int rna_ksPath_RnaPath_length(PointerRNA *ptr)
00265 {
00266     KS_Path *ksp= (KS_Path *)ptr->data;
00267     
00268     if (ksp->rna_path)
00269         return strlen(ksp->rna_path);
00270     else
00271         return 0;
00272 }
00273 
00274 static void rna_ksPath_RnaPath_set(PointerRNA *ptr, const char *value)
00275 {
00276     KS_Path *ksp= (KS_Path *)ptr->data;
00277 
00278     if (ksp->rna_path)
00279         MEM_freeN(ksp->rna_path);
00280     
00281     if (value[0])
00282         ksp->rna_path= BLI_strdup(value);
00283     else 
00284         ksp->rna_path= NULL;
00285 }
00286 
00287 /* ****************************** */
00288 
00289 static int rna_KeyingSet_active_ksPath_editable(PointerRNA *ptr)
00290 {
00291     KeyingSet *ks= (KeyingSet *)ptr->data;
00292     
00293     /* only editable if there are some paths to change to */
00294     return (ks->paths.first != NULL);
00295 }
00296 
00297 static PointerRNA rna_KeyingSet_active_ksPath_get(PointerRNA *ptr)
00298 {
00299     KeyingSet *ks= (KeyingSet *)ptr->data;
00300     return rna_pointer_inherit_refine(ptr, &RNA_KeyingSetPath, BLI_findlink(&ks->paths, ks->active_path-1));
00301 }
00302 
00303 static void rna_KeyingSet_active_ksPath_set(PointerRNA *ptr, PointerRNA value)
00304 {
00305     KeyingSet *ks= (KeyingSet *)ptr->data;
00306     KS_Path *ksp= (KS_Path*)value.data;
00307     ks->active_path= BLI_findindex(&ks->paths, ksp) + 1;
00308 }
00309 
00310 static int rna_KeyingSet_active_ksPath_index_get(PointerRNA *ptr)
00311 {
00312     KeyingSet *ks= (KeyingSet *)ptr->data;
00313     return MAX2(ks->active_path-1, 0);
00314 }
00315 
00316 static void rna_KeyingSet_active_ksPath_index_set(PointerRNA *ptr, int value)
00317 {
00318     KeyingSet *ks= (KeyingSet *)ptr->data;
00319     ks->active_path= value+1;
00320 }
00321 
00322 static void rna_KeyingSet_active_ksPath_index_range(PointerRNA *ptr, int *min, int *max)
00323 {
00324     KeyingSet *ks= (KeyingSet *)ptr->data;
00325 
00326     *min= 0;
00327     *max= BLI_countlist(&ks->paths)-1;
00328     *max= MAX2(0, *max);
00329 }
00330 
00331 static PointerRNA rna_KeyingSet_typeinfo_get(PointerRNA *ptr)
00332 {
00333     KeyingSet *ks= (KeyingSet *)ptr->data;
00334     KeyingSetInfo *ksi = NULL;
00335     
00336     /* keying set info is only for builtin Keying Sets */
00337     if ((ks->flag & KEYINGSET_ABSOLUTE)==0)
00338         ksi = ANIM_keyingset_info_find_named(ks->typeinfo);
00339     return rna_pointer_inherit_refine(ptr, &RNA_KeyingSetInfo, ksi);
00340 }
00341 
00342 
00343 
00344 static KS_Path *rna_KeyingSet_paths_add(KeyingSet *keyingset, ReportList *reports, 
00345         ID *id, const char rna_path[], int index, int group_method, const char group_name[])
00346 {
00347     KS_Path *ksp = NULL;
00348     short flag = 0;
00349     
00350     /* special case when index = -1, we key the whole array (as with other places where index is used) */
00351     if (index == -1) {
00352         flag |= KSP_FLAG_WHOLE_ARRAY;
00353         index = 0;
00354     }
00355     
00356     /* if data is valid, call the API function for this */
00357     if (keyingset) {
00358         ksp= BKE_keyingset_add_path(keyingset, id, group_name, rna_path, index, flag, group_method);
00359         keyingset->active_path= BLI_countlist(&keyingset->paths); 
00360     }
00361     else {
00362         BKE_report(reports, RPT_ERROR, "Keying Set Path could not be added");
00363     }
00364     
00365     /* return added path */
00366     return ksp;
00367 }
00368 
00369 static void rna_KeyingSet_paths_remove(KeyingSet *keyingset, ReportList *reports, KS_Path *ksp)
00370 {
00371     /* if data is valid, call the API function for this */
00372     if (keyingset && ksp) {
00373         /* remove the active path from the KeyingSet */
00374         BKE_keyingset_free_path(keyingset, ksp);
00375             
00376         /* the active path number will most likely have changed */
00377         // TODO: we should get more fancy and actually check if it was removed, but this will do for now
00378         keyingset->active_path = 0;
00379     }
00380     else {
00381         BKE_report(reports, RPT_ERROR, "Keying Set Path could not be removed");
00382     }
00383 }
00384 
00385 static void rna_KeyingSet_paths_clear(KeyingSet *keyingset, ReportList *reports)
00386 {
00387     /* if data is valid, call the API function for this */
00388     if (keyingset) {
00389         KS_Path *ksp, *kspn;
00390         
00391         /* free each path as we go to avoid looping twice */
00392         for (ksp= keyingset->paths.first; ksp; ksp= kspn) {
00393             kspn= ksp->next;
00394             BKE_keyingset_free_path(keyingset, ksp);
00395         }
00396             
00397         /* reset the active path, since there aren't any left */
00398         keyingset->active_path = 0;
00399     }
00400     else {
00401         BKE_report(reports, RPT_ERROR, "Keying Set Paths could not be removed");
00402     }
00403 }
00404 
00405 /* needs wrapper function to push notifier */
00406 static NlaTrack *rna_NlaTrack_new(AnimData *adt, bContext *C, NlaTrack *track)
00407 {
00408     NlaTrack *new_track = add_nlatrack(adt, track);
00409 
00410     WM_event_add_notifier(C, NC_ANIMATION|ND_NLA|NA_ADDED, NULL);
00411 
00412     return new_track;
00413 }
00414 
00415 static void rna_NlaTrack_remove(AnimData *adt, bContext *C, NlaTrack *track)
00416 {
00417     free_nlatrack(&adt->nla_tracks, track);
00418 
00419     WM_event_add_notifier(C, NC_ANIMATION|ND_NLA|NA_REMOVED, NULL);
00420 }
00421 
00422 static PointerRNA rna_NlaTrack_active_get(PointerRNA *ptr)
00423 {
00424     AnimData *adt= (AnimData*)ptr->data;
00425     NlaTrack *track= BKE_nlatrack_find_active(&adt->nla_tracks);
00426     return rna_pointer_inherit_refine(ptr, &RNA_NlaTrack, track);
00427 }
00428 
00429 static void rna_NlaTrack_active_set(PointerRNA *ptr, PointerRNA value)
00430 {
00431     AnimData *adt= (AnimData*)ptr->data;
00432     NlaTrack *track= (NlaTrack*)value.data;
00433     BKE_nlatrack_set_active(&adt->nla_tracks, track);
00434 }
00435 
00436 
00437 static FCurve *rna_Driver_from_existing(AnimData *adt, bContext *C, FCurve *src_driver)
00438 {
00439     /* verify that we've got a driver to duplicate */
00440     if (ELEM(NULL, src_driver, src_driver->driver)) {
00441         BKE_reportf(CTX_wm_reports(C), RPT_ERROR, "No valid driver data to create copy of");
00442         return NULL;
00443     }
00444     else {
00445         /* just make a copy of the existing one and add to self */
00446         FCurve *new_fcu = copy_fcurve(src_driver);
00447         
00448         // XXX: if we impose any ordering on these someday, this will be problematic
00449         BLI_addtail(&adt->drivers, new_fcu);
00450         return new_fcu;
00451     }
00452 }
00453 
00454 #else
00455 
00456 /* helper function for Keying Set -> keying settings */
00457 static void rna_def_common_keying_flags(StructRNA *srna, short reg)
00458 {
00459     PropertyRNA *prop;
00460 
00461     static EnumPropertyItem keying_flag_items[] = {
00462             {INSERTKEY_NEEDED, "INSERTKEY_NEEDED", 0, "Insert Keyframes - Only Needed", "Only insert keyframes where they're needed in the relevant F-Curves"},
00463             {INSERTKEY_MATRIX, "INSERTKEY_VISUAL", 0, "Insert Keyframes - Visual", "Insert keyframes based on 'visual transforms'"},
00464             {INSERTKEY_XYZ2RGB, "INSERTKEY_XYZ_TO_RGB", 0, "F-Curve Colors - XYZ to RGB", "Color for newly added transformation F-Curves (Location, Rotation, Scale) and also Color is based on the transform axis"},
00465             {0, NULL, 0, NULL, NULL}};
00466 
00467     prop= RNA_def_property(srna, "bl_options", PROP_ENUM, PROP_NONE);
00468     RNA_def_property_enum_sdna(prop, NULL, "keyingflag");
00469     RNA_def_property_enum_items(prop, keying_flag_items);
00470     RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL|PROP_ENUM_FLAG);
00471     RNA_def_property_ui_text(prop, "Options",  "Keying set options");
00472 }
00473 
00474 /* --- */
00475 
00476 static void rna_def_keyingset_info(BlenderRNA *brna)
00477 {
00478     StructRNA *srna;
00479     PropertyRNA *prop;
00480     FunctionRNA *func;
00481     PropertyRNA *parm;
00482     
00483     srna= RNA_def_struct(brna, "KeyingSetInfo", NULL);
00484     RNA_def_struct_sdna(srna, "KeyingSetInfo");
00485     RNA_def_struct_ui_text(srna, "Keying Set Info", "Callback function defines for builtin Keying Sets");
00486     RNA_def_struct_refine_func(srna, "rna_KeyingSetInfo_refine");
00487     RNA_def_struct_register_funcs(srna, "rna_KeyingSetInfo_register", "rna_KeyingSetInfo_unregister", NULL);
00488     
00489     /* Properties --------------------- */
00490     
00491     RNA_define_verify_sdna(0); // not in sdna
00492         
00493     prop= RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
00494     RNA_def_property_string_sdna(prop, NULL, "idname");
00495     RNA_def_property_flag(prop, PROP_REGISTER|PROP_NEVER_CLAMP);
00496         
00497     /* Name */
00498     prop= RNA_def_property(srna, "bl_label", PROP_STRING, PROP_TRANSLATE);
00499     RNA_def_property_string_sdna(prop, NULL, "name");
00500     RNA_def_property_ui_text(prop, "Name", "");
00501     RNA_def_struct_name_property(srna, prop);
00502     RNA_def_property_flag(prop, PROP_REGISTER);
00503     
00504     rna_def_common_keying_flags(srna, 1); /* '1' arg here is to indicate that we need these to be set on registering */
00505     
00506     RNA_define_verify_sdna(1);
00507     
00508     /* Function Callbacks ------------- */
00509         /* poll */
00510     func= RNA_def_function(srna, "poll", NULL);
00511     RNA_def_function_ui_description(func, "Test if Keying Set can be used or not");
00512     RNA_def_function_flag(func, FUNC_REGISTER);
00513     RNA_def_function_return(func, RNA_def_boolean(func, "ok", 1, "", ""));
00514     parm= RNA_def_pointer(func, "context", "Context", "", "");
00515     RNA_def_property_flag(parm, PROP_REQUIRED);
00516     
00517         /* iterator */
00518     func= RNA_def_function(srna, "iterator", NULL);
00519     RNA_def_function_ui_description(func, "Call generate() on the structs which have properties to be keyframed");
00520     RNA_def_function_flag(func, FUNC_REGISTER);
00521     parm= RNA_def_pointer(func, "context", "Context", "", "");
00522     RNA_def_property_flag(parm, PROP_REQUIRED);
00523     parm= RNA_def_pointer(func, "ks", "KeyingSet", "", "");
00524     RNA_def_property_flag(parm, PROP_REQUIRED);
00525     
00526         /* generate */
00527     func= RNA_def_function(srna, "generate", NULL);
00528     RNA_def_function_ui_description(func, "Add Paths to the Keying Set to keyframe the properties of the given data");
00529     RNA_def_function_flag(func, FUNC_REGISTER);
00530     parm= RNA_def_pointer(func, "context", "Context", "", "");
00531     RNA_def_property_flag(parm, PROP_REQUIRED);
00532     parm= RNA_def_pointer(func, "ks", "KeyingSet", "", "");
00533     RNA_def_property_flag(parm, PROP_REQUIRED);
00534     parm= RNA_def_pointer(func, "data", "AnyType", "", ""); 
00535     RNA_def_property_flag(parm, PROP_REQUIRED|PROP_RNAPTR|PROP_NEVER_NULL);
00536 }
00537 
00538 static void rna_def_keyingset_path(BlenderRNA *brna)
00539 {
00540     StructRNA *srna;
00541     PropertyRNA *prop;
00542     
00543     srna= RNA_def_struct(brna, "KeyingSetPath", NULL);
00544     RNA_def_struct_sdna(srna, "KS_Path");
00545     RNA_def_struct_ui_text(srna, "Keying Set Path", "Path to a setting for use in a Keying Set");
00546     
00547     /* ID */
00548     prop= RNA_def_property(srna, "id", PROP_POINTER, PROP_NONE);
00549     RNA_def_property_struct_type(prop, "ID");
00550     RNA_def_property_flag(prop, PROP_EDITABLE);
00551     RNA_def_property_editable_func(prop, "rna_ksPath_id_editable");
00552     RNA_def_property_pointer_funcs(prop, NULL, NULL, "rna_ksPath_id_typef", NULL);
00553     RNA_def_property_ui_text(prop, "ID-Block", "ID-Block that keyframes for Keying Set should be added to (for Absolute Keying Sets only)");
00554     RNA_def_property_update(prop, NC_SCENE|ND_KEYINGSET|NA_EDITED, NULL); // XXX: maybe a bit too noisy
00555     
00556     prop= RNA_def_property(srna, "id_type", PROP_ENUM, PROP_NONE);
00557     RNA_def_property_enum_sdna(prop, NULL, "idtype");
00558     RNA_def_property_enum_items(prop, id_type_items);
00559     RNA_def_property_enum_default(prop, ID_OB);
00560     RNA_def_property_enum_funcs(prop, NULL, "rna_ksPath_id_type_set", NULL);
00561     RNA_def_property_ui_text(prop, "ID Type", "Type of ID-block that can be used");
00562     RNA_def_property_update(prop, NC_SCENE|ND_KEYINGSET|NA_EDITED, NULL); // XXX: maybe a bit too noisy
00563     
00564     /* Group */
00565     prop= RNA_def_property(srna, "group", PROP_STRING, PROP_NONE);
00566     RNA_def_property_ui_text(prop, "Group Name", "Name of Action Group to assign setting(s) for this path to");
00567     RNA_def_property_update(prop, NC_SCENE|ND_KEYINGSET|NA_EDITED, NULL); // XXX: maybe a bit too noisy
00568     
00569     /* Grouping */
00570     prop= RNA_def_property(srna, "group_method", PROP_ENUM, PROP_NONE);
00571     RNA_def_property_enum_sdna(prop, NULL, "groupmode");
00572     RNA_def_property_enum_items(prop, keyingset_path_grouping_items);
00573     RNA_def_property_ui_text(prop, "Grouping Method", "Method used to define which Group-name to use");
00574     RNA_def_property_update(prop, NC_SCENE|ND_KEYINGSET|NA_EDITED, NULL); // XXX: maybe a bit too noisy
00575     
00576     /* Path + Array Index */
00577     prop= RNA_def_property(srna, "data_path", PROP_STRING, PROP_NONE);
00578     RNA_def_property_string_funcs(prop, "rna_ksPath_RnaPath_get", "rna_ksPath_RnaPath_length", "rna_ksPath_RnaPath_set");
00579     RNA_def_property_ui_text(prop, "Data Path", "Path to property setting");
00580     RNA_def_struct_name_property(srna, prop); // XXX this is the best indicator for now...
00581     RNA_def_property_update(prop, NC_SCENE|ND_KEYINGSET|NA_EDITED, NULL);
00582 
00583     /* called 'index' when given as function arg */
00584     prop= RNA_def_property(srna, "array_index", PROP_INT, PROP_NONE);
00585     RNA_def_property_ui_text(prop, "RNA Array Index", "Index to the specific setting if applicable");
00586     RNA_def_property_update(prop, NC_SCENE|ND_KEYINGSET|NA_EDITED, NULL); // XXX: maybe a bit too noisy
00587     
00588     /* Flags */
00589     prop= RNA_def_property(srna, "use_entire_array", PROP_BOOLEAN, PROP_NONE);
00590     RNA_def_property_boolean_sdna(prop, NULL, "flag", KSP_FLAG_WHOLE_ARRAY);
00591     RNA_def_property_ui_text(prop, "Entire Array", "When an 'array/vector' type is chosen (Location, Rotation, Color, etc.), entire array is to be used");
00592     RNA_def_property_update(prop, NC_SCENE|ND_KEYINGSET|NA_EDITED, NULL); // XXX: maybe a bit too noisy
00593     
00594     /* Keyframing Settings */
00595     rna_def_common_keying_flags(srna, 0);
00596 }
00597 
00598 
00599 /* keyingset.paths */
00600 static void rna_def_keyingset_paths(BlenderRNA *brna, PropertyRNA *cprop)
00601 {
00602     StructRNA *srna;
00603 
00604     FunctionRNA *func;
00605     PropertyRNA *parm;
00606     
00607     PropertyRNA *prop;
00608 
00609     RNA_def_property_srna(cprop, "KeyingSetPaths");
00610     srna= RNA_def_struct(brna, "KeyingSetPaths", NULL);
00611     RNA_def_struct_sdna(srna, "KeyingSet");
00612     RNA_def_struct_ui_text(srna, "Keying set paths", "Collection of keying set paths");
00613 
00614     
00615     /* Add Path */
00616     func= RNA_def_function(srna, "add", "rna_KeyingSet_paths_add");
00617     RNA_def_function_ui_description(func, "Add a new path for the Keying Set");
00618     RNA_def_function_flag(func, FUNC_USE_REPORTS);
00619         /* return arg */
00620     parm= RNA_def_pointer(func, "ksp", "KeyingSetPath", "New Path", "Path created and added to the Keying Set");
00621         RNA_def_function_return(func, parm);
00622         /* ID-block for target */
00623     parm= RNA_def_pointer(func, "target_id", "ID", "Target ID", "ID-Datablock for the destination"); 
00624         RNA_def_property_flag(parm, PROP_REQUIRED);
00625         /* rna-path */
00626     parm= RNA_def_string(func, "data_path", "", 256, "Data-Path", "RNA-Path to destination property"); // xxx hopefully this is long enough
00627         RNA_def_property_flag(parm, PROP_REQUIRED);
00628         /* index (defaults to -1 for entire array) */
00629     RNA_def_int(func, "index", -1, -1, INT_MAX, "Index",
00630                 "The index of the destination property (i.e. axis of Location/Rotation/etc.), "
00631                 "or -1 for the entire array", 0, INT_MAX);
00632         /* grouping */
00633     RNA_def_enum(func, "group_method", keyingset_path_grouping_items, KSP_GROUP_KSNAME,
00634                  "Grouping Method", "Method used to define which Group-name to use");
00635     RNA_def_string(func, "group_name", "", 64, "Group Name",
00636                    "Name of Action Group to assign destination to (only if grouping mode is to use this name)");
00637 
00638 
00639     /* Remove Path */
00640     func= RNA_def_function(srna, "remove", "rna_KeyingSet_paths_remove");
00641     RNA_def_function_ui_description(func, "Remove the given path from the Keying Set");
00642     RNA_def_function_flag(func, FUNC_USE_REPORTS);
00643         /* path to remove */
00644     parm= RNA_def_pointer(func, "path", "KeyingSetPath", "Path", ""); 
00645         RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
00646 
00647 
00648     /* Remove All Paths */
00649     func= RNA_def_function(srna, "clear", "rna_KeyingSet_paths_clear");
00650     RNA_def_function_ui_description(func, "Remove all the paths from the Keying Set");
00651     RNA_def_function_flag(func, FUNC_USE_REPORTS);
00652     
00653     prop= RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
00654     RNA_def_property_struct_type(prop, "KeyingSetPath");
00655     RNA_def_property_flag(prop, PROP_EDITABLE);
00656     RNA_def_property_editable_func(prop, "rna_KeyingSet_active_ksPath_editable");
00657     RNA_def_property_pointer_funcs(prop, "rna_KeyingSet_active_ksPath_get", "rna_KeyingSet_active_ksPath_set", NULL, NULL);
00658     RNA_def_property_ui_text(prop, "Active Keying Set", "Active Keying Set used to insert/delete keyframes");
00659 
00660     prop= RNA_def_property(srna, "active_index", PROP_INT, PROP_NONE);
00661     RNA_def_property_int_sdna(prop, NULL, "active_path");
00662     RNA_def_property_int_funcs(prop, "rna_KeyingSet_active_ksPath_index_get", "rna_KeyingSet_active_ksPath_index_set", "rna_KeyingSet_active_ksPath_index_range");
00663     RNA_def_property_ui_text(prop, "Active Path Index", "Current Keying Set index");
00664 }
00665 
00666 static void rna_def_keyingset(BlenderRNA *brna)
00667 {
00668     StructRNA *srna;
00669     PropertyRNA *prop;
00670     
00671     srna= RNA_def_struct(brna, "KeyingSet", NULL);
00672     RNA_def_struct_ui_text(srna, "Keying Set", "Settings that should be keyframed together");
00673     
00674     /* Name */
00675     prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
00676     RNA_def_property_ui_text(prop, "Name", "");
00677     RNA_def_struct_ui_icon(srna, ICON_KEYINGSET);
00678     RNA_def_struct_name_property(srna, prop);
00679     RNA_def_property_update(prop, NC_SCENE|ND_KEYINGSET|NA_RENAME, NULL);
00680     
00681     /* KeyingSetInfo (Type Info) for Builtin Sets only  */
00682     prop= RNA_def_property(srna, "type_info", PROP_POINTER, PROP_NONE);
00683     RNA_def_property_struct_type(prop, "KeyingSetInfo");
00684     RNA_def_property_pointer_funcs(prop, "rna_KeyingSet_typeinfo_get", NULL, NULL, NULL);
00685     RNA_def_property_ui_text(prop, "Type Info", "Callback function defines for built-in Keying Sets");
00686     
00687     /* Paths */
00688     prop= RNA_def_property(srna, "paths", PROP_COLLECTION, PROP_NONE);
00689     RNA_def_property_collection_sdna(prop, NULL, "paths", NULL);
00690     RNA_def_property_struct_type(prop, "KeyingSetPath");
00691     RNA_def_property_ui_text(prop, "Paths", "Keying Set Paths to define settings that get keyframed together");
00692     rna_def_keyingset_paths(brna, prop);
00693 
00694     /* Flags */
00695     prop= RNA_def_property(srna, "is_path_absolute", PROP_BOOLEAN, PROP_NONE);
00696     RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00697     RNA_def_property_boolean_sdna(prop, NULL, "flag", KEYINGSET_ABSOLUTE);
00698     RNA_def_property_ui_text(prop, "Absolute", "Keying Set defines specific paths/settings to be keyframed (i.e. is not reliant on context info)"); 
00699     
00700     /* Keyframing Flags */
00701     rna_def_common_keying_flags(srna, 0);
00702     
00703     
00704     /* Keying Set API */
00705     RNA_api_keyingset(srna);
00706 }
00707 
00708 /* --- */
00709 
00710 static void rna_api_animdata_nla_tracks(BlenderRNA *brna, PropertyRNA *cprop)
00711 {
00712     StructRNA *srna;
00713     PropertyRNA *parm;
00714     FunctionRNA *func;
00715 
00716     PropertyRNA *prop;
00717     
00718     RNA_def_property_srna(cprop, "NlaTracks");
00719     srna= RNA_def_struct(brna, "NlaTracks", NULL);
00720     RNA_def_struct_sdna(srna, "AnimData");
00721     RNA_def_struct_ui_text(srna, "NLA Tracks", "Collection of NLA Tracks");
00722     
00723     func = RNA_def_function(srna, "new", "rna_NlaTrack_new");
00724     RNA_def_function_flag(func, FUNC_USE_CONTEXT);
00725     RNA_def_function_ui_description(func, "Add a new NLA Track");
00726     RNA_def_pointer(func, "prev", "NlaTrack", "", "NLA Track to add the new one after");
00727     /* return type */
00728     parm = RNA_def_pointer(func, "track", "NlaTrack", "", "New NLA Track");
00729     RNA_def_function_return(func, parm);
00730     
00731     func = RNA_def_function(srna, "remove", "rna_NlaTrack_remove");
00732     RNA_def_function_flag(func, FUNC_USE_CONTEXT);
00733     RNA_def_function_ui_description(func, "Remove a NLA Track");
00734     parm = RNA_def_pointer(func, "track", "NlaTrack", "", "NLA Track to remove");
00735     RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
00736 
00737     prop= RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
00738     RNA_def_property_struct_type(prop, "NlaTrack");
00739     RNA_def_property_pointer_funcs(prop, "rna_NlaTrack_active_get", "rna_NlaTrack_active_set", NULL, NULL);
00740     RNA_def_property_flag(prop, PROP_EDITABLE);
00741     RNA_def_property_ui_text(prop, "Active Constraint", "Active Object constraint");
00742     /* XXX: should (but doesn't) update the active track in the NLA window */
00743     RNA_def_property_update(prop, NC_ANIMATION|ND_NLA|NA_SELECTED, NULL);
00744 }
00745 
00746 static void rna_api_animdata_drivers(BlenderRNA *brna, PropertyRNA *cprop)
00747 {
00748     StructRNA *srna;
00749     PropertyRNA *parm;
00750     FunctionRNA *func;
00751 
00752     // PropertyRNA *prop;
00753     
00754     RNA_def_property_srna(cprop, "AnimDataDrivers");
00755     srna= RNA_def_struct(brna, "AnimDataDrivers", NULL);
00756     RNA_def_struct_sdna(srna, "AnimData");
00757     RNA_def_struct_ui_text(srna, "Drivers", "Collection of Driver F-Curves");
00758     
00759     func = RNA_def_function(srna, "from_existing", "rna_Driver_from_existing");
00760     RNA_def_function_flag(func, FUNC_USE_CONTEXT);
00761     RNA_def_function_ui_description(func, "Add a new driver given an existing one");
00762     RNA_def_pointer(func, "src_driver", "FCurve", "", "Existing Driver F-Curve to use as template for a new one");
00763     /* return type */
00764     parm = RNA_def_pointer(func, "driver", "FCurve", "", "New Driver F-Curve");
00765     RNA_def_function_return(func, parm);
00766 }
00767 
00768 void rna_def_animdata_common(StructRNA *srna)
00769 {
00770     PropertyRNA *prop;
00771     
00772     prop= RNA_def_property(srna, "animation_data", PROP_POINTER, PROP_NONE);
00773     RNA_def_property_pointer_sdna(prop, NULL, "adt");
00774     RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00775     RNA_def_property_ui_text(prop, "Animation Data", "Animation data for this datablock");  
00776 }
00777 
00778 void rna_def_animdata(BlenderRNA *brna)
00779 {
00780     StructRNA *srna;
00781     PropertyRNA *prop;
00782     
00783     srna= RNA_def_struct(brna, "AnimData", NULL);
00784     RNA_def_struct_ui_text(srna, "Animation Data", "Animation data for datablock");
00785     
00786     /* NLA */
00787     prop= RNA_def_property(srna, "nla_tracks", PROP_COLLECTION, PROP_NONE);
00788     RNA_def_property_collection_sdna(prop, NULL, "nla_tracks", NULL);
00789     RNA_def_property_struct_type(prop, "NlaTrack");
00790     RNA_def_property_ui_text(prop, "NLA Tracks", "NLA Tracks (i.e. Animation Layers)");
00791 
00792     rna_api_animdata_nla_tracks(brna, prop);
00793     
00794     /* Active Action */
00795     prop= RNA_def_property(srna, "action", PROP_POINTER, PROP_NONE);
00796     RNA_def_property_flag(prop, PROP_EDITABLE); /* this flag as well as the dynamic test must be defined for this to be editable... */
00797     RNA_def_property_pointer_funcs(prop, NULL, "rna_AnimData_action_set", NULL, "rna_Action_id_poll");
00798     RNA_def_property_editable_func(prop, "rna_AnimData_action_editable");
00799     RNA_def_property_ui_text(prop, "Action", "Active Action for this datablock");
00800     RNA_def_property_update(prop, NC_ANIMATION, NULL); /* this will do? */
00801 
00802     /* Active Action Settings */
00803     prop= RNA_def_property(srna, "action_extrapolation", PROP_ENUM, PROP_NONE);
00804     RNA_def_property_enum_sdna(prop, NULL, "act_extendmode");
00805     RNA_def_property_enum_items(prop, nla_mode_extend_items);
00806     RNA_def_property_ui_text(prop, "Action Extrapolation", "Action to take for gaps past the Active Action's range (when evaluating with NLA)");
00807     RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */
00808     
00809     prop= RNA_def_property(srna, "action_blend_type", PROP_ENUM, PROP_NONE);
00810     RNA_def_property_enum_sdna(prop, NULL, "act_blendmode");
00811     RNA_def_property_enum_items(prop, nla_mode_blend_items);
00812     RNA_def_property_ui_text(prop, "Action Blending", "Method used for combining Active Action's result with result of NLA stack");
00813     RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */
00814     
00815     prop= RNA_def_property(srna, "action_influence", PROP_FLOAT, PROP_NONE);
00816     RNA_def_property_float_sdna(prop, NULL, "act_influence");
00817     RNA_def_property_float_default(prop, 1.0f);
00818     RNA_def_property_range(prop, 0.0f, 1.0f);
00819     RNA_def_property_ui_text(prop, "Action Influence", "Amount the Active Action contributes to the result of the NLA stack");
00820     RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */
00821     
00822     /* Drivers */
00823     prop= RNA_def_property(srna, "drivers", PROP_COLLECTION, PROP_NONE);
00824     RNA_def_property_collection_sdna(prop, NULL, "drivers", NULL);
00825     RNA_def_property_struct_type(prop, "FCurve");
00826     RNA_def_property_ui_text(prop, "Drivers", "The Drivers/Expressions for this datablock");
00827     
00828     rna_api_animdata_drivers(brna, prop);
00829     
00830     /* General Settings */
00831     prop= RNA_def_property(srna, "use_nla", PROP_BOOLEAN, PROP_NONE);
00832     RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", ADT_NLA_EVAL_OFF);
00833     RNA_def_property_ui_text(prop, "NLA Evaluation Enabled", "NLA stack is evaluated when evaluating this block");
00834     RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */
00835 }
00836 
00837 /* --- */
00838 
00839 void RNA_def_animation(BlenderRNA *brna)
00840 {
00841     rna_def_animdata(brna);
00842     
00843     rna_def_keyingset(brna);
00844     rna_def_keyingset_path(brna);
00845     rna_def_keyingset_info(brna);
00846 }
00847 
00848 #endif