Blender  V2.59
rna_ID.c
Go to the documentation of this file.
00001 /*
00002  * $Id: rna_ID.c 38881 2011-07-31 12:43:41Z campbellbarton $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * Contributor(s): Blender Foundation (2008).
00021  *
00022  * ***** END GPL LICENSE BLOCK *****
00023  */
00024 
00030 #include <stdlib.h>
00031 #include <stdio.h>
00032 
00033 #include "RNA_access.h"
00034 #include "RNA_define.h"
00035 
00036 #include "DNA_ID.h"
00037 #include "DNA_vfont_types.h"
00038 #include "DNA_material_types.h"
00039 #include "DNA_object_types.h"
00040 
00041 #include "WM_types.h"
00042 
00043 #include "rna_internal.h"
00044 
00045 /* enum of ID-block types 
00046  * NOTE: need to keep this in line with the other defines for these
00047  */
00048 EnumPropertyItem id_type_items[] = {
00049         {ID_AC, "ACTION", ICON_ACTION, "Action", ""},
00050         {ID_AR, "ARMATURE", ICON_ARMATURE_DATA, "Armature", ""},
00051         {ID_BR, "BRUSH", ICON_BRUSH_DATA, "Brush", ""},
00052         {ID_CA, "CAMERA", ICON_CAMERA_DATA, "Camera", ""},
00053         {ID_CU, "CURVE", ICON_CURVE_DATA, "Curve", ""},
00054         {ID_VF, "FONT", ICON_FONT_DATA, "Font", ""},
00055         {ID_GD, "GREASEPENCIL", ICON_GREASEPENCIL, "Grease Pencil", ""},
00056         {ID_GR, "GROUP", ICON_GROUP, "Group", ""},
00057         {ID_IM, "IMAGE", ICON_IMAGE_DATA, "Image", ""},
00058         {ID_KE, "KEY", ICON_SHAPEKEY_DATA, "Key", ""},
00059         {ID_LA, "LAMP", ICON_LAMP_DATA, "Lamp", ""},
00060         {ID_LI, "LIBRARY", ICON_LIBRARY_DATA_DIRECT, "Library", ""},
00061         {ID_LT, "LATTICE", ICON_LATTICE_DATA, "Lattice", ""},
00062         {ID_MA, "MATERIAL", ICON_MATERIAL_DATA, "Material", ""},
00063         {ID_MB, "META", ICON_META_DATA, "MetaBall", ""},
00064         {ID_ME, "MESH", ICON_MESH_DATA, "Mesh", ""},
00065         {ID_NT, "NODETREE", ICON_NODETREE, "NodeTree", ""},
00066         {ID_OB, "OBJECT", ICON_OBJECT_DATA, "Object", ""},
00067         {ID_PA, "PARTICLE", ICON_PARTICLE_DATA, "Particle", ""},
00068         {ID_SCE, "SCENE", ICON_SCENE_DATA, "Scene", ""},
00069         {ID_SCR, "SCREEN", ICON_SPLITSCREEN, "Screen", ""},
00070         {ID_SO, "SOUND", ICON_PLAY_AUDIO, "Sound", ""},
00071         {ID_TXT, "TEXT", ICON_TEXT, "Text", ""},
00072         {ID_TE, "TEXTURE", ICON_TEXTURE_DATA, "Texture", ""},
00073         {ID_WO, "WORLD", ICON_WORLD_DATA, "World", ""},
00074         {ID_WM, "WINDOWMANAGER", ICON_FULLSCREEN, "Window Manager", ""},
00075         {0, NULL, 0, NULL, NULL}};
00076 
00077 #ifdef RNA_RUNTIME
00078 
00079 #include "BKE_idprop.h"
00080 #include "BKE_library.h"
00081 #include "BKE_animsys.h"
00082 #include "BKE_material.h"
00083 #include "BKE_depsgraph.h"
00084 
00085 /* name functions that ignore the first two ID characters */
00086 void rna_ID_name_get(PointerRNA *ptr, char *value)
00087 {
00088         ID *id= (ID*)ptr->data;
00089         BLI_strncpy(value, id->name+2, sizeof(id->name)-2);
00090 }
00091 
00092 int rna_ID_name_length(PointerRNA *ptr)
00093 {
00094         ID *id= (ID*)ptr->data;
00095         return strlen(id->name+2);
00096 }
00097 
00098 void rna_ID_name_set(PointerRNA *ptr, const char *value)
00099 {
00100         ID *id= (ID*)ptr->data;
00101         BLI_strncpy(id->name+2, value, sizeof(id->name)-2);
00102         test_idbutton(id->name+2);
00103 }
00104 
00105 static int rna_ID_name_editable(PointerRNA *ptr)
00106 {
00107         ID *id= (ID*)ptr->data;
00108         
00109         if (GS(id->name) == ID_VF) {
00110                 VFont *vf= (VFont *)id;
00111                 if (strcmp(vf->name, FO_BUILTIN_NAME)==0)
00112                         return 0;
00113         }
00114         
00115         return 1;
00116 }
00117 
00118 short RNA_type_to_ID_code(StructRNA *type)
00119 {
00120         if(RNA_struct_is_a(type, &RNA_Action)) return ID_AC;
00121         if(RNA_struct_is_a(type, &RNA_Armature)) return ID_AR;
00122         if(RNA_struct_is_a(type, &RNA_Brush)) return ID_BR;
00123         if(RNA_struct_is_a(type, &RNA_Camera)) return ID_CA;
00124         if(RNA_struct_is_a(type, &RNA_Curve)) return ID_CU;
00125         if(RNA_struct_is_a(type, &RNA_GreasePencil)) return ID_GD;
00126         if(RNA_struct_is_a(type, &RNA_Group)) return ID_GR;
00127         if(RNA_struct_is_a(type, &RNA_Image)) return ID_IM;
00128         if(RNA_struct_is_a(type, &RNA_Key)) return ID_KE;
00129         if(RNA_struct_is_a(type, &RNA_Lamp)) return ID_LA;
00130         if(RNA_struct_is_a(type, &RNA_Library)) return ID_LI;
00131         if(RNA_struct_is_a(type, &RNA_Lattice)) return ID_LT;
00132         if(RNA_struct_is_a(type, &RNA_Material)) return ID_MA;
00133         if(RNA_struct_is_a(type, &RNA_MetaBall)) return ID_MB;
00134         if(RNA_struct_is_a(type, &RNA_NodeTree)) return ID_NT;
00135         if(RNA_struct_is_a(type, &RNA_Mesh)) return ID_ME;
00136         if(RNA_struct_is_a(type, &RNA_Object)) return ID_OB;
00137         if(RNA_struct_is_a(type, &RNA_ParticleSettings)) return ID_PA;
00138         if(RNA_struct_is_a(type, &RNA_Scene)) return ID_SCE;
00139         if(RNA_struct_is_a(type, &RNA_Screen)) return ID_SCR;
00140         if(RNA_struct_is_a(type, &RNA_Sound)) return ID_SO;
00141         if(RNA_struct_is_a(type, &RNA_Text)) return ID_TXT;
00142         if(RNA_struct_is_a(type, &RNA_Texture)) return ID_TE;
00143         if(RNA_struct_is_a(type, &RNA_VectorFont)) return ID_VF;
00144         if(RNA_struct_is_a(type, &RNA_World)) return ID_WO;
00145         if(RNA_struct_is_a(type, &RNA_WindowManager)) return ID_WM;
00146 
00147         return 0;
00148 }
00149 
00150 StructRNA *ID_code_to_RNA_type(short idcode)
00151 {
00152         switch(idcode) {
00153                 case ID_AC: return &RNA_Action;
00154                 case ID_AR: return &RNA_Armature;
00155                 case ID_BR: return &RNA_Brush;
00156                 case ID_CA: return &RNA_Camera;
00157                 case ID_CU: return &RNA_Curve;
00158                 case ID_GD: return &RNA_GreasePencil;
00159                 case ID_GR: return &RNA_Group;
00160                 case ID_IM: return &RNA_Image;
00161                 case ID_KE: return &RNA_Key;
00162                 case ID_LA: return &RNA_Lamp;
00163                 case ID_LI: return &RNA_Library;
00164                 case ID_LT: return &RNA_Lattice;
00165                 case ID_MA: return &RNA_Material;
00166                 case ID_MB: return &RNA_MetaBall;
00167                 case ID_NT: return &RNA_NodeTree;
00168                 case ID_ME: return &RNA_Mesh;
00169                 case ID_OB: return &RNA_Object;
00170                 case ID_PA: return &RNA_ParticleSettings;
00171                 case ID_SCE: return &RNA_Scene;
00172                 case ID_SCR: return &RNA_Screen;
00173                 case ID_SO: return &RNA_Sound;
00174                 case ID_TXT: return &RNA_Text;
00175                 case ID_TE: return &RNA_Texture;
00176                 case ID_VF: return &RNA_VectorFont;
00177                 case ID_WO: return &RNA_World;
00178                 case ID_WM: return &RNA_WindowManager;
00179                 default: return &RNA_ID;
00180         }
00181 }
00182 
00183 StructRNA *rna_ID_refine(PointerRNA *ptr)
00184 {
00185         ID *id= (ID*)ptr->data;
00186 
00187         return ID_code_to_RNA_type(GS(id->name));
00188 }
00189 
00190 IDProperty *rna_ID_idprops(PointerRNA *ptr, int create)
00191 {
00192         return IDP_GetProperties(ptr->data, create);
00193 }
00194 
00195 void rna_ID_fake_user_set(PointerRNA *ptr, int value)
00196 {
00197         ID *id= (ID*)ptr->data;
00198 
00199         if(value && !(id->flag & LIB_FAKEUSER)) {
00200                 id->flag |= LIB_FAKEUSER;
00201                 id_us_plus(id);
00202         }
00203         else if(!value && (id->flag & LIB_FAKEUSER)) {
00204                 id->flag &= ~LIB_FAKEUSER;
00205                 id_us_min(id);
00206         }
00207 }
00208 
00209 IDProperty *rna_PropertyGroup_idprops(PointerRNA *ptr, int UNUSED(create))
00210 {
00211         return ptr->data;
00212 }
00213 
00214 void rna_PropertyGroup_unregister(Main *UNUSED(bmain), StructRNA *type)
00215 {
00216         RNA_struct_free(&BLENDER_RNA, type);
00217 }
00218 
00219 StructRNA *rna_PropertyGroup_register(Main *UNUSED(bmain), ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc UNUSED(call), StructFreeFunc UNUSED(free))
00220 {
00221         PointerRNA dummyptr;
00222 
00223         /* create dummy pointer */
00224         RNA_pointer_create(NULL, &RNA_PropertyGroup, NULL, &dummyptr);
00225 
00226         /* validate the python class */
00227         if(validate(&dummyptr, data, NULL) != 0)
00228                 return NULL;
00229 
00230         /* note: it looks like there is no length limit on the srna id since its
00231          * just a char pointer, but take care here, also be careful that python
00232          * owns the string pointer which it could potentually free while blender
00233          * is running. */
00234         if(BLI_strnlen(identifier, MAX_IDPROP_NAME) == MAX_IDPROP_NAME) {
00235                 BKE_reportf(reports, RPT_ERROR, "registering id property class: '%s' is too long, maximum length is " STRINGIFY(MAX_IDPROP_NAME) ".", identifier);
00236                 return NULL;
00237         }
00238 
00239         return RNA_def_struct(&BLENDER_RNA, identifier, "PropertyGroup");  // XXX
00240 }
00241 
00242 StructRNA* rna_PropertyGroup_refine(PointerRNA *ptr)
00243 {
00244         return ptr->type;
00245 }
00246 
00247 ID *rna_ID_copy(ID *id)
00248 {
00249         ID *newid;
00250 
00251         if(id_copy(id, &newid, 0)) {
00252                 if(newid) id_us_min(newid);
00253                 return newid;
00254         }
00255         
00256         return NULL;
00257 }
00258 
00259 static void rna_ID_update_tag(ID *id, ReportList *reports, int flag)
00260 {
00261         /* XXX, new function for this! */
00262         /*if (ob->type == OB_FONT) {
00263                 Curve *cu = ob->data;
00264                 freedisplist(&cu->disp);
00265                 BKE_text_to_curve(sce, ob, CU_LEFT);
00266         }*/
00267 
00268         if(flag == 0) {
00269                 /* pass */
00270         }
00271         else {
00272                 /* ensure flag us correct for the type */
00273                 switch(GS(id->name)) {
00274                 case ID_OB:
00275                         if(flag & ~(OB_RECALC_ALL)) {
00276                                 BKE_report(reports, RPT_ERROR, "'refresh' incompatible with Object ID type");
00277                                 return;
00278                         }
00279                         break;
00280                 /* Could add particle updates later */
00281 /*              case ID_PA:
00282                         if(flag & ~(OB_RECALC_ALL|PSYS_RECALC)) {
00283                                 BKE_report(reports, RPT_ERROR, "'refresh' incompatible with ParticleSettings ID type");
00284                                 return;
00285                         }
00286                         break; */
00287                 default:
00288                         BKE_report(reports, RPT_ERROR, "This ID type is not compatible with any 'refresh' options");
00289                         return;
00290                 }
00291         }
00292 
00293         DAG_id_tag_update(id, flag);
00294 }
00295 
00296 void rna_ID_user_clear(ID *id)
00297 {
00298         id->us= 0; /* dont save */
00299         id->flag &= ~LIB_FAKEUSER;
00300 }
00301 
00302 static void rna_IDPArray_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
00303 {
00304         IDProperty *prop= (IDProperty *)ptr->data;
00305         rna_iterator_array_begin(iter, IDP_IDPArray(prop), sizeof(IDProperty), prop->len, 0, NULL);
00306 }
00307 
00308 static int rna_IDPArray_length(PointerRNA *ptr)
00309 {
00310         IDProperty *prop= (IDProperty *)ptr->data;
00311         return prop->len;
00312 }
00313 
00314 #else
00315 
00316 static void rna_def_ID_properties(BlenderRNA *brna)
00317 {
00318         StructRNA *srna;
00319         PropertyRNA *prop;
00320 
00321         /* this is struct is used for holding the virtual
00322          * PropertyRNA's for ID properties */
00323         srna= RNA_def_struct(brna, "PropertyGroupItem", NULL);
00324         RNA_def_struct_sdna(srna, "IDProperty");
00325         RNA_def_struct_ui_text(srna, "ID Property", "Property that stores arbitrary, user defined properties");
00326         
00327         /* IDP_STRING */
00328         prop= RNA_def_property(srna, "string", PROP_STRING, PROP_NONE);
00329         RNA_def_property_flag(prop, PROP_EXPORT|PROP_IDPROPERTY);
00330 
00331         /* IDP_INT */
00332         prop= RNA_def_property(srna, "int", PROP_INT, PROP_NONE);
00333         RNA_def_property_flag(prop, PROP_EXPORT|PROP_IDPROPERTY);
00334 
00335         prop= RNA_def_property(srna, "int_array", PROP_INT, PROP_NONE);
00336         RNA_def_property_flag(prop, PROP_EXPORT|PROP_IDPROPERTY);
00337         RNA_def_property_array(prop, 1);
00338 
00339         /* IDP_FLOAT */
00340         prop= RNA_def_property(srna, "float", PROP_FLOAT, PROP_NONE);
00341         RNA_def_property_flag(prop, PROP_EXPORT|PROP_IDPROPERTY);
00342 
00343         prop= RNA_def_property(srna, "float_array", PROP_FLOAT, PROP_NONE);
00344         RNA_def_property_flag(prop, PROP_EXPORT|PROP_IDPROPERTY);
00345         RNA_def_property_array(prop, 1);
00346 
00347         /* IDP_DOUBLE */
00348         prop= RNA_def_property(srna, "double", PROP_FLOAT, PROP_NONE);
00349         RNA_def_property_flag(prop, PROP_EXPORT|PROP_IDPROPERTY);
00350 
00351         prop= RNA_def_property(srna, "double_array", PROP_FLOAT, PROP_NONE);
00352         RNA_def_property_flag(prop, PROP_EXPORT|PROP_IDPROPERTY);
00353         RNA_def_property_array(prop, 1);
00354 
00355         /* IDP_GROUP */
00356         prop= RNA_def_property(srna, "group", PROP_POINTER, PROP_NONE);
00357         RNA_def_property_flag(prop, PROP_EXPORT|PROP_IDPROPERTY);
00358         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00359         RNA_def_property_struct_type(prop, "PropertyGroup");
00360 
00361         prop= RNA_def_property(srna, "collection", PROP_COLLECTION, PROP_NONE);
00362         RNA_def_property_flag(prop, PROP_EXPORT|PROP_IDPROPERTY);
00363         RNA_def_property_struct_type(prop, "PropertyGroup");
00364 
00365         prop= RNA_def_property(srna, "idp_array", PROP_COLLECTION, PROP_NONE);
00366         RNA_def_property_struct_type(prop, "PropertyGroup");
00367         RNA_def_property_collection_funcs(prop, "rna_IDPArray_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", "rna_IDPArray_length", NULL, NULL);
00368         RNA_def_property_flag(prop, PROP_EXPORT|PROP_IDPROPERTY);
00369 
00370         // never tested, maybe its useful to have this?
00371 #if 0
00372         prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
00373         RNA_def_property_flag(prop, PROP_EXPORT|PROP_IDPROPERTY);
00374         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00375         RNA_def_property_ui_text(prop, "Name", "Unique name used in the code and scripting");
00376         RNA_def_struct_name_property(srna, prop);
00377 #endif
00378 
00379         /* IDP_ID -- not implemented yet in id properties */
00380 
00381         /* ID property groups > level 0, since level 0 group is merged
00382          * with native RNA properties. the builtin_properties will take
00383          * care of the properties here */
00384         srna= RNA_def_struct(brna, "PropertyGroup", NULL);
00385         RNA_def_struct_sdna(srna, "IDPropertyGroup");
00386         RNA_def_struct_ui_text(srna, "ID Property Group", "Group of ID properties");
00387         RNA_def_struct_idprops_func(srna, "rna_PropertyGroup_idprops");
00388         RNA_def_struct_register_funcs(srna, "rna_PropertyGroup_register", "rna_PropertyGroup_unregister", NULL);
00389         RNA_def_struct_refine_func(srna, "rna_PropertyGroup_refine");
00390 
00391         /* important so python types can have their name used in list views
00392          * however this isnt prefect because it overrides how python would set the name
00393          * when we only really want this so RNA_def_struct_name_property() is set to something useful */
00394         prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
00395         RNA_def_property_flag(prop, PROP_EXPORT|PROP_IDPROPERTY);
00396         //RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00397         RNA_def_property_ui_text(prop, "Name", "Unique name used in the code and scripting");
00398         RNA_def_struct_name_property(srna, prop);
00399 }
00400 
00401 
00402 static void rna_def_ID_materials(BlenderRNA *brna)
00403 {
00404         StructRNA *srna;
00405         FunctionRNA *func;
00406         PropertyRNA *parm;
00407         
00408         /* for mesh/mball/curve materials */
00409         srna= RNA_def_struct(brna, "IDMaterials", NULL);
00410         RNA_def_struct_sdna(srna, "ID");
00411         RNA_def_struct_ui_text(srna, "ID Materials", "Collection of materials");
00412 
00413         func= RNA_def_function(srna, "append", "material_append_id");
00414         RNA_def_function_ui_description(func, "Add a new material to the data block.");
00415         parm= RNA_def_pointer(func, "material", "Material", "", "Material to add.");
00416         RNA_def_property_flag(parm, PROP_REQUIRED);
00417         
00418         func= RNA_def_function(srna, "pop", "material_pop_id");
00419         RNA_def_function_ui_description(func, "Remove a material from the data block.");
00420         parm= RNA_def_int(func, "index", 0, 0, MAXMAT, "", "Index of material to remove.", 0, MAXMAT);
00421         RNA_def_property_flag(parm, PROP_REQUIRED);
00422         RNA_def_boolean(func, "update_data", 0, "", "Update data by re-adjusting the material slots assigned.");
00423         parm= RNA_def_pointer(func, "material", "Material", "", "Material to remove.");
00424         RNA_def_function_return(func, parm);
00425 }
00426 
00427 static void rna_def_ID(BlenderRNA *brna)
00428 {
00429         StructRNA *srna;
00430         FunctionRNA *func;
00431         PropertyRNA *prop, *parm;
00432 
00433         static EnumPropertyItem update_flag_items[] = {
00434                 {OB_RECALC_OB, "OBJECT", 0, "Object", ""},
00435                 {OB_RECALC_DATA, "DATA", 0, "Data", ""},
00436                 {OB_RECALC_TIME, "TIME", 0, "Time", ""},
00437                 {0, NULL, 0, NULL, NULL}};
00438 
00439         srna= RNA_def_struct(brna, "ID", NULL);
00440         RNA_def_struct_ui_text(srna, "ID", "Base type for datablocks, defining a unique name, linking from other libraries and garbage collection");
00441         RNA_def_struct_flag(srna, STRUCT_ID|STRUCT_ID_REFCOUNT);
00442         RNA_def_struct_refine_func(srna, "rna_ID_refine");
00443         RNA_def_struct_idprops_func(srna, "rna_ID_idprops");
00444 
00445         prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
00446         RNA_def_property_ui_text(prop, "Name", "Unique datablock ID name");
00447         RNA_def_property_string_funcs(prop, "rna_ID_name_get", "rna_ID_name_length", "rna_ID_name_set");
00448         RNA_def_property_string_maxlength(prop, MAX_ID_NAME-2);
00449         RNA_def_property_editable_func(prop, "rna_ID_name_editable");
00450         RNA_def_property_update(prop, NC_ID|NA_RENAME, NULL);
00451         RNA_def_struct_name_property(srna, prop);
00452 
00453         prop= RNA_def_property(srna, "users", PROP_INT, PROP_UNSIGNED);
00454         RNA_def_property_int_sdna(prop, NULL, "us");
00455         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00456         RNA_def_property_ui_text(prop, "Users", "Number of times this datablock is referenced");
00457 
00458         prop= RNA_def_property(srna, "use_fake_user", PROP_BOOLEAN, PROP_NONE);
00459         RNA_def_property_boolean_sdna(prop, NULL, "flag", LIB_FAKEUSER);
00460         RNA_def_property_ui_text(prop, "Fake User", "Saves this datablock even if it has no users");
00461         RNA_def_property_boolean_funcs(prop, NULL, "rna_ID_fake_user_set");
00462 
00463         prop= RNA_def_property(srna, "tag", PROP_BOOLEAN, PROP_NONE);
00464         RNA_def_property_boolean_sdna(prop, NULL, "flag", LIB_DOIT);
00465         RNA_def_property_flag(prop, PROP_LIB_EXCEPTION);
00466         RNA_def_property_ui_text(prop, "Tag", "Tools can use this to tag data, (initial state is undefined)");
00467 
00468         prop= RNA_def_property(srna, "library", PROP_POINTER, PROP_NONE);
00469         RNA_def_property_pointer_sdna(prop, NULL, "lib");
00470         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00471         RNA_def_property_ui_text(prop, "Library", "Library file the datablock is linked from");
00472 
00473         /* functions */
00474         func= RNA_def_function(srna, "copy", "rna_ID_copy");
00475         RNA_def_function_ui_description(func, "Create a copy of this datablock (not supported for all datablocks).");
00476         parm= RNA_def_pointer(func, "id", "ID", "", "New copy of the ID.");
00477         RNA_def_function_return(func, parm);
00478 
00479         func= RNA_def_function(srna, "user_clear", "rna_ID_user_clear");
00480         RNA_def_function_ui_description(func, "Clears the user count of a datablock so its not saved, on reload the data will be removed.");
00481 
00482         func= RNA_def_function(srna, "animation_data_create", "BKE_id_add_animdata");
00483         RNA_def_function_ui_description(func, "Create animation data to this ID, note that not all ID types support this.");
00484         parm= RNA_def_pointer(func, "anim_data", "AnimData", "", "New animation data or NULL.");
00485         RNA_def_function_return(func, parm);
00486 
00487         func= RNA_def_function(srna, "animation_data_clear", "BKE_free_animdata");
00488         RNA_def_function_ui_description(func, "Clear animation on this this ID.");
00489 
00490         func= RNA_def_function(srna, "update_tag", "rna_ID_update_tag");
00491         RNA_def_function_flag(func, FUNC_USE_REPORTS);
00492         RNA_def_function_ui_description(func, "Tag the id to update its display data.");
00493         RNA_def_enum_flag(func, "refresh", update_flag_items, 0, "", "Type of updates to perform.");
00494 }
00495 
00496 static void rna_def_library(BlenderRNA *brna)
00497 {
00498         StructRNA *srna;
00499         PropertyRNA *prop;
00500 
00501         srna= RNA_def_struct(brna, "Library", "ID");
00502         RNA_def_struct_ui_text(srna, "Library", "External .blend file from which data is linked");
00503         RNA_def_struct_ui_icon(srna, ICON_LIBRARY_DATA_DIRECT);
00504 
00505         prop= RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
00506         RNA_def_property_string_sdna(prop, NULL, "name");
00507         RNA_def_property_ui_text(prop, "File Path", "Path to the library .blend file");
00508         /* TODO - lib->filename isnt updated, however the outliner also skips this, probably only needed on read. */
00509         
00510         prop= RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
00511         RNA_def_property_struct_type(prop, "Library");
00512         RNA_def_property_ui_text(prop, "Parent", "");   
00513 }
00514 void RNA_def_ID(BlenderRNA *brna)
00515 {
00516         StructRNA *srna;
00517 
00518         /* built-in unknown type */
00519         srna= RNA_def_struct(brna, "UnknownType", NULL);
00520         RNA_def_struct_ui_text(srna, "Unknown Type", "Stub RNA type used for pointers to unknown or internal data");
00521 
00522         /* built-in any type */
00523         srna= RNA_def_struct(brna, "AnyType", NULL);
00524         RNA_def_struct_ui_text(srna, "Any Type", "RNA type used for pointers to any possible data");
00525 
00526         rna_def_ID(brna);
00527         rna_def_ID_properties(brna);
00528         rna_def_ID_materials(brna);
00529         rna_def_library(brna);
00530 }
00531 
00532 #endif
00533