Merge branch 'master' into blender2.8
[blender.git] / source / blender / makesrna / intern / rna_ID.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor(s): Blender Foundation (2008).
19  *
20  * ***** END GPL LICENSE BLOCK *****
21  */
22
23 /** \file blender/makesrna/intern/rna_ID.c
24  *  \ingroup RNA
25  */
26
27 #include <stdlib.h>
28 #include <stdio.h>
29
30 #include "DNA_ID.h"
31 #include "DNA_vfont_types.h"
32 #include "DNA_material_types.h"
33 #include "DNA_object_types.h"
34
35 #include "BLI_utildefines.h"
36
37 #include "BKE_icons.h"
38
39 #include "RNA_access.h"
40 #include "RNA_define.h"
41 #include "RNA_enum_types.h"
42
43 #include "WM_types.h"
44
45 #include "rna_internal.h"
46
47 /* enum of ID-block types
48  * NOTE: need to keep this in line with the other defines for these
49  */
50 EnumPropertyItem rna_enum_id_type_items[] = {
51         {ID_AC, "ACTION", ICON_ACTION, "Action", ""},
52         {ID_AR, "ARMATURE", ICON_ARMATURE_DATA, "Armature", ""},
53         {ID_BR, "BRUSH", ICON_BRUSH_DATA, "Brush", ""},
54         {ID_CA, "CAMERA", ICON_CAMERA_DATA, "Camera", ""},
55         {ID_CU, "CURVE", ICON_CURVE_DATA, "Curve", ""},
56         {ID_VF, "FONT", ICON_FONT_DATA, "Font", ""},
57         {ID_GD, "GREASEPENCIL", ICON_GREASEPENCIL, "Grease Pencil", ""},
58         {ID_GR, "GROUP", ICON_GROUP, "Group", ""},
59         {ID_IM, "IMAGE", ICON_IMAGE_DATA, "Image", ""},
60         {ID_KE, "KEY", ICON_SHAPEKEY_DATA, "Key", ""},
61         {ID_LA, "LAMP", ICON_LAMP_DATA, "Lamp", ""},
62         {ID_LI, "LIBRARY", ICON_LIBRARY_DATA_DIRECT, "Library", ""},
63         {ID_LS, "LINESTYLE", ICON_LINE_DATA, "Line Style", ""},
64         {ID_LT, "LATTICE", ICON_LATTICE_DATA, "Lattice", ""},
65         {ID_MSK, "MASK", ICON_MOD_MASK, "Mask", ""},
66         {ID_MA, "MATERIAL", ICON_MATERIAL_DATA, "Material", ""},
67         {ID_MB, "META", ICON_META_DATA, "MetaBall", ""},
68         {ID_ME, "MESH", ICON_MESH_DATA, "Mesh", ""},
69         {ID_MC, "MOVIECLIP", ICON_CLIP, "MovieClip", ""},
70         {ID_NT, "NODETREE", ICON_NODETREE, "NodeTree", ""},
71         {ID_OB, "OBJECT", ICON_OBJECT_DATA, "Object", ""},
72         {ID_PC, "PAINTCURVE", ICON_CURVE_BEZCURVE, "Paint Curve", ""},
73         {ID_PAL, "PALETTE", ICON_COLOR, "Palette", ""},
74         {ID_SCE, "SCENE", ICON_SCENE_DATA, "Scene", ""},
75         {ID_SCR, "SCREEN", ICON_SPLITSCREEN, "Screen", ""},
76         {ID_SO, "SOUND", ICON_PLAY_AUDIO, "Sound", ""},
77         {ID_SPK, "SPEAKER", ICON_SPEAKER, "Speaker", ""},
78         {ID_TXT, "TEXT", ICON_TEXT, "Text", ""},
79         {ID_TE, "TEXTURE", ICON_TEXTURE_DATA, "Texture", ""},
80         {ID_WM, "WINDOWMANAGER", ICON_FULLSCREEN, "Window Manager", ""},
81         {ID_WO, "WORLD", ICON_WORLD_DATA, "World", ""},
82         {0, NULL, 0, NULL, NULL}
83 };
84
85 #ifdef RNA_RUNTIME
86
87 #include "DNA_anim_types.h"
88
89 #include "BLI_listbase.h"
90
91 #include "BKE_font.h"
92 #include "BKE_idprop.h"
93 #include "BKE_library.h"
94 #include "BKE_library_query.h"
95 #include "BKE_library_remap.h"
96 #include "BKE_animsys.h"
97 #include "BKE_material.h"
98 #include "BKE_depsgraph.h"
99 #include "BKE_global.h"  /* XXX, remove me */
100
101 #include "WM_api.h"
102
103 /* name functions that ignore the first two ID characters */
104 void rna_ID_name_get(PointerRNA *ptr, char *value)
105 {
106         ID *id = (ID *)ptr->data;
107         BLI_strncpy(value, id->name + 2, sizeof(id->name) - 2);
108 }
109
110 int rna_ID_name_length(PointerRNA *ptr)
111 {
112         ID *id = (ID *)ptr->data;
113         return strlen(id->name + 2);
114 }
115
116 void rna_ID_name_set(PointerRNA *ptr, const char *value)
117 {
118         ID *id = (ID *)ptr->data;
119         BLI_strncpy_utf8(id->name + 2, value, sizeof(id->name) - 2);
120         BLI_libblock_ensure_unique_name(G.main, id->name);
121 }
122
123 static int rna_ID_name_editable(PointerRNA *ptr)
124 {
125         ID *id = (ID *)ptr->data;
126         
127         if (GS(id->name) == ID_VF) {
128                 VFont *vfont = (VFont *)id;
129                 if (BKE_vfont_is_builtin(vfont))
130                         return false;
131         }
132         
133         return PROP_EDITABLE;
134 }
135
136 short RNA_type_to_ID_code(StructRNA *type)
137 {
138         if (RNA_struct_is_a(type, &RNA_Action)) return ID_AC;
139         if (RNA_struct_is_a(type, &RNA_Armature)) return ID_AR;
140         if (RNA_struct_is_a(type, &RNA_Brush)) return ID_BR;
141         if (RNA_struct_is_a(type, &RNA_Camera)) return ID_CA;
142         if (RNA_struct_is_a(type, &RNA_Curve)) return ID_CU;
143         if (RNA_struct_is_a(type, &RNA_GreasePencil)) return ID_GD;
144         if (RNA_struct_is_a(type, &RNA_Group)) return ID_GR;
145         if (RNA_struct_is_a(type, &RNA_Image)) return ID_IM;
146         if (RNA_struct_is_a(type, &RNA_Key)) return ID_KE;
147         if (RNA_struct_is_a(type, &RNA_Lamp)) return ID_LA;
148         if (RNA_struct_is_a(type, &RNA_Library)) return ID_LI;
149         if (RNA_struct_is_a(type, &RNA_FreestyleLineStyle)) return ID_LS;
150         if (RNA_struct_is_a(type, &RNA_Lattice)) return ID_LT;
151         if (RNA_struct_is_a(type, &RNA_Material)) return ID_MA;
152         if (RNA_struct_is_a(type, &RNA_MetaBall)) return ID_MB;
153         if (RNA_struct_is_a(type, &RNA_MovieClip)) return ID_MC;
154         if (RNA_struct_is_a(type, &RNA_Mesh)) return ID_ME;
155         if (RNA_struct_is_a(type, &RNA_Mask)) return ID_MSK;
156         if (RNA_struct_is_a(type, &RNA_NodeTree)) return ID_NT;
157         if (RNA_struct_is_a(type, &RNA_Object)) return ID_OB;
158         if (RNA_struct_is_a(type, &RNA_Palette)) return ID_PAL;
159         if (RNA_struct_is_a(type, &RNA_PaintCurve)) return ID_PC;
160         if (RNA_struct_is_a(type, &RNA_Scene)) return ID_SCE;
161         if (RNA_struct_is_a(type, &RNA_Screen)) return ID_SCR;
162         if (RNA_struct_is_a(type, &RNA_Sound)) return ID_SO;
163         if (RNA_struct_is_a(type, &RNA_Speaker)) return ID_SPK;
164         if (RNA_struct_is_a(type, &RNA_Texture)) return ID_TE;
165         if (RNA_struct_is_a(type, &RNA_Text)) return ID_TXT;
166         if (RNA_struct_is_a(type, &RNA_VectorFont)) return ID_VF;
167         if (RNA_struct_is_a(type, &RNA_World)) return ID_WO;
168         if (RNA_struct_is_a(type, &RNA_WindowManager)) return ID_WM;
169
170         return 0;
171 }
172
173 StructRNA *ID_code_to_RNA_type(short idcode)
174 {
175         switch (idcode) {
176                 case ID_AC: return &RNA_Action;
177                 case ID_AR: return &RNA_Armature;
178                 case ID_BR: return &RNA_Brush;
179                 case ID_CA: return &RNA_Camera;
180                 case ID_CU: return &RNA_Curve;
181                 case ID_GD: return &RNA_GreasePencil;
182                 case ID_GR: return &RNA_Group;
183                 case ID_IM: return &RNA_Image;
184                 case ID_KE: return &RNA_Key;
185                 case ID_LA: return &RNA_Lamp;
186                 case ID_LI: return &RNA_Library;
187                 case ID_LS: return &RNA_FreestyleLineStyle;
188                 case ID_LT: return &RNA_Lattice;
189                 case ID_MA: return &RNA_Material;
190                 case ID_MB: return &RNA_MetaBall;
191                 case ID_MC: return &RNA_MovieClip;
192                 case ID_ME: return &RNA_Mesh;
193                 case ID_MSK: return &RNA_Mask;
194                 case ID_NT: return &RNA_NodeTree;
195                 case ID_OB: return &RNA_Object;
196                 case ID_PAL: return &RNA_Palette;
197                 case ID_PC: return &RNA_PaintCurve;
198                 case ID_SCE: return &RNA_Scene;
199                 case ID_SCR: return &RNA_Screen;
200                 case ID_SO: return &RNA_Sound;
201                 case ID_SPK: return &RNA_Speaker;
202                 case ID_TE: return &RNA_Texture;
203                 case ID_TXT: return &RNA_Text;
204                 case ID_VF: return &RNA_VectorFont;
205                 case ID_WM: return &RNA_WindowManager;
206                 case ID_WO: return &RNA_World;
207
208                 default: return &RNA_ID;
209         }
210 }
211
212 StructRNA *rna_ID_refine(PointerRNA *ptr)
213 {
214         ID *id = (ID *)ptr->data;
215
216         return ID_code_to_RNA_type(GS(id->name));
217 }
218
219 IDProperty *rna_ID_idprops(PointerRNA *ptr, bool create)
220 {
221         return IDP_GetProperties(ptr->data, create);
222 }
223
224 void rna_ID_fake_user_set(PointerRNA *ptr, int value)
225 {
226         ID *id = (ID *)ptr->data;
227
228         if (value) {
229                 id_fake_user_set(id);
230         }
231         else {
232                 id_fake_user_clear(id);
233         }
234 }
235
236 IDProperty *rna_PropertyGroup_idprops(PointerRNA *ptr, bool UNUSED(create))
237 {
238         return ptr->data;
239 }
240
241 void rna_PropertyGroup_unregister(Main *UNUSED(bmain), StructRNA *type)
242 {
243         RNA_struct_free(&BLENDER_RNA, type);
244 }
245
246 StructRNA *rna_PropertyGroup_register(Main *UNUSED(bmain), ReportList *reports, void *data, const char *identifier,
247                                       StructValidateFunc validate, StructCallbackFunc UNUSED(call),
248                                       StructFreeFunc UNUSED(free))
249 {
250         PointerRNA dummyptr;
251
252         /* create dummy pointer */
253         RNA_pointer_create(NULL, &RNA_PropertyGroup, NULL, &dummyptr);
254
255         /* validate the python class */
256         if (validate(&dummyptr, data, NULL) != 0)
257                 return NULL;
258
259         /* note: it looks like there is no length limit on the srna id since its
260          * just a char pointer, but take care here, also be careful that python
261          * owns the string pointer which it could potentially free while blender
262          * is running. */
263         if (BLI_strnlen(identifier, MAX_IDPROP_NAME) == MAX_IDPROP_NAME) {
264                 BKE_reportf(reports, RPT_ERROR, "Registering id property class: '%s' is too long, maximum length is %d",
265                             identifier, MAX_IDPROP_NAME);
266                 return NULL;
267         }
268
269         return RNA_def_struct_ptr(&BLENDER_RNA, identifier, &RNA_PropertyGroup);  /* XXX */
270 }
271
272 StructRNA *rna_PropertyGroup_refine(PointerRNA *ptr)
273 {
274         return ptr->type;
275 }
276
277 static ID *rna_ID_copy(ID *id, Main *bmain)
278 {
279         ID *newid;
280
281         if (id_copy(bmain, id, &newid, false)) {
282                 if (newid) id_us_min(newid);
283                 return newid;
284         }
285         
286         return NULL;
287 }
288
289 static void rna_ID_update_tag(ID *id, ReportList *reports, int flag)
290 {
291         /* XXX, new function for this! */
292 #if 0
293         if (ob->type == OB_FONT) {
294                 Curve *cu = ob->data;
295                 freedisplist(&cu->disp);
296                 BKE_vfont_to_curve(bmain, sce, ob, FO_EDIT, NULL);
297         }
298 #endif
299
300         if (flag == 0) {
301                 /* pass */
302         }
303         else {
304                 /* ensure flag us correct for the type */
305                 switch (GS(id->name)) {
306                         case ID_OB:
307                                 if (flag & ~(OB_RECALC_ALL)) {
308                                         BKE_report(reports, RPT_ERROR, "'Refresh' incompatible with Object ID type");
309                                         return;
310                                 }
311                                 break;
312                         default:
313                                 BKE_report(reports, RPT_ERROR, "This ID type is not compatible with any 'refresh' options");
314                                 return;
315                 }
316         }
317
318         DAG_id_tag_update(id, flag);
319 }
320
321 static void rna_ID_user_clear(ID *id)
322 {
323         id_fake_user_clear(id);
324         id->us = 0; /* don't save */
325 }
326
327 static void rna_ID_user_remap(ID *id, Main *bmain, ID *new_id)
328 {
329         if (GS(id->name) == GS(new_id->name)) {
330                 /* For now, do not allow remapping data in linked data from here... */
331                 BKE_libblock_remap(bmain, id, new_id, ID_REMAP_SKIP_INDIRECT_USAGE | ID_REMAP_SKIP_NEVER_NULL_USAGE);
332         }
333 }
334
335 static AnimData * rna_ID_animation_data_create(ID *id, Main *bmain)
336 {
337         AnimData *adt = BKE_animdata_add_id(id);
338         DAG_relations_tag_update(bmain);
339         return adt;
340 }
341
342 static void rna_ID_animation_data_free(ID *id, Main *bmain)
343 {
344         BKE_animdata_free(id, true);
345         DAG_relations_tag_update(bmain);
346 }
347
348 static void rna_IDPArray_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
349 {
350         IDProperty *prop = (IDProperty *)ptr->data;
351         rna_iterator_array_begin(iter, IDP_IDPArray(prop), sizeof(IDProperty), prop->len, 0, NULL);
352 }
353
354 static int rna_IDPArray_length(PointerRNA *ptr)
355 {
356         IDProperty *prop = (IDProperty *)ptr->data;
357         return prop->len;
358 }
359
360 int rna_IDMaterials_assign_int(PointerRNA *ptr, int key, const PointerRNA *assign_ptr)
361 {
362         ID *id =           ptr->id.data;
363         short *totcol = give_totcolp_id(id);
364         Material *mat_id = assign_ptr->id.data;
365         if (totcol && (key >= 0 && key < *totcol)) {
366                 assign_material_id(id, mat_id, key + 1);
367                 return 1;
368         }
369         else {
370                 return 0;
371         }
372 }
373
374 static void rna_IDMaterials_append_id(ID *id, Material *ma)
375 {
376         BKE_material_append_id(id, ma);
377
378         WM_main_add_notifier(NC_OBJECT | ND_DRAW, id);
379         WM_main_add_notifier(NC_OBJECT | ND_OB_SHADING, id);
380 }
381
382 static Material *rna_IDMaterials_pop_id(ID *id, ReportList *reports, int index_i, int remove_material_slot)
383 {
384         Material *ma;
385         short *totcol = give_totcolp_id(id);
386         const short totcol_orig = *totcol;
387         if (index_i < 0) {
388                 index_i += (*totcol);
389         }
390
391         if ((index_i < 0) || (index_i >= (*totcol))) {
392                 BKE_report(reports, RPT_ERROR, "Index out of range");
393                 return NULL;
394         }
395
396         ma = BKE_material_pop_id(id, index_i, remove_material_slot);
397
398         if (*totcol == totcol_orig) {
399                 BKE_report(reports, RPT_ERROR, "No material to removed");
400                 return NULL;
401         }
402
403         DAG_id_tag_update(id, OB_RECALC_DATA);
404         WM_main_add_notifier(NC_OBJECT | ND_DRAW, id);
405         WM_main_add_notifier(NC_OBJECT | ND_OB_SHADING, id);
406
407         return ma;
408 }
409
410 static void rna_IDMaterials_clear_id(ID *id, int remove_material_slot)
411 {
412         BKE_material_clear_id(id, remove_material_slot);
413
414         DAG_id_tag_update(id, OB_RECALC_DATA);
415         WM_main_add_notifier(NC_OBJECT | ND_DRAW, id);
416         WM_main_add_notifier(NC_OBJECT | ND_OB_SHADING, id);
417 }
418
419 static void rna_Library_filepath_set(PointerRNA *ptr, const char *value)
420 {
421         Library *lib = (Library *)ptr->data;
422         BKE_library_filepath_set(lib, value);
423 }
424
425 /* ***** ImagePreview ***** */
426
427 static void rna_ImagePreview_is_custom_set(PointerRNA *ptr, int value, enum eIconSizes size)
428 {
429         ID *id = ptr->id.data;
430         PreviewImage *prv_img = (PreviewImage *)ptr->data;
431
432         if (id != NULL) {
433                 BLI_assert(prv_img == BKE_previewimg_id_ensure(id));
434         }
435
436         if ((value && (prv_img->flag[size] & PRV_USER_EDITED)) || (!value && !(prv_img->flag[size] & PRV_USER_EDITED))) {
437                 return;
438         }
439
440         if (value)
441                 prv_img->flag[size] |= PRV_USER_EDITED;
442         else
443                 prv_img->flag[size] &= ~PRV_USER_EDITED;
444
445         prv_img->flag[size] |= PRV_CHANGED;
446
447         BKE_previewimg_clear_single(prv_img, size);
448 }
449
450 static void rna_ImagePreview_size_get(PointerRNA *ptr, int *values, enum eIconSizes size)
451 {
452         ID *id = (ID *)ptr->id.data;
453         PreviewImage *prv_img = (PreviewImage *)ptr->data;
454
455         if (id != NULL) {
456                 BLI_assert(prv_img == BKE_previewimg_id_ensure(id));
457         }
458
459         BKE_previewimg_ensure(prv_img, size);
460
461         values[0] = prv_img->w[size];
462         values[1] = prv_img->h[size];
463 }
464
465 static void rna_ImagePreview_size_set(PointerRNA *ptr, const int *values, enum eIconSizes size)
466 {
467         ID *id = (ID *)ptr->id.data;
468         PreviewImage *prv_img = (PreviewImage *)ptr->data;
469
470         if (id != NULL) {
471                 BLI_assert(prv_img == BKE_previewimg_id_ensure(id));
472         }
473
474         BKE_previewimg_clear_single(prv_img, size);
475
476         if (values[0] && values[1]) {
477                 prv_img->rect[size] = MEM_callocN(values[0] * values[1] * sizeof(unsigned int), "prv_rect");
478
479                 prv_img->w[size] = values[0];
480                 prv_img->h[size] = values[1];
481         }
482
483         prv_img->flag[size] |= (PRV_CHANGED | PRV_USER_EDITED);
484 }
485
486
487 static int rna_ImagePreview_pixels_get_length(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION], enum eIconSizes size)
488 {
489         ID *id = ptr->id.data;
490         PreviewImage *prv_img = (PreviewImage *)ptr->data;
491
492         if (id != NULL) {
493                 BLI_assert(prv_img == BKE_previewimg_id_ensure(id));
494         }
495
496         BKE_previewimg_ensure(prv_img, size);
497
498         length[0] = prv_img->w[size] * prv_img->h[size];
499
500         return length[0];
501 }
502
503 static void rna_ImagePreview_pixels_get(PointerRNA *ptr, int *values, enum eIconSizes size)
504 {
505         ID *id = ptr->id.data;
506         PreviewImage *prv_img = (PreviewImage *)ptr->data;
507
508         if (id != NULL) {
509                 BLI_assert(prv_img == BKE_previewimg_id_ensure(id));
510         }
511
512         BKE_previewimg_ensure(prv_img, size);
513
514         memcpy(values, prv_img->rect[size], prv_img->w[size] * prv_img->h[size] * sizeof(unsigned int));
515 }
516
517 static void rna_ImagePreview_pixels_set(PointerRNA *ptr, const int *values, enum eIconSizes size)
518 {
519         ID *id = ptr->id.data;
520         PreviewImage *prv_img = (PreviewImage *)ptr->data;
521
522         if (id != NULL) {
523                 BLI_assert(prv_img == BKE_previewimg_id_ensure(id));
524         }
525
526         memcpy(prv_img->rect[size], values, prv_img->w[size] * prv_img->h[size] * sizeof(unsigned int));
527         prv_img->flag[size] |= PRV_USER_EDITED;
528 }
529
530
531 static int rna_ImagePreview_pixels_float_get_length(
532         PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION], enum eIconSizes size)
533 {
534         ID *id = ptr->id.data;
535         PreviewImage *prv_img = (PreviewImage *)ptr->data;
536
537         BLI_assert(sizeof(unsigned int) == 4);
538
539         if (id != NULL) {
540                 BLI_assert(prv_img == BKE_previewimg_id_ensure(id));
541         }
542
543         BKE_previewimg_ensure(prv_img, size);
544
545         length[0] = prv_img->w[size] * prv_img->h[size] * 4;
546
547         return length[0];
548 }
549
550 static void rna_ImagePreview_pixels_float_get(PointerRNA *ptr, float *values, enum eIconSizes size)
551 {
552         ID *id = ptr->id.data;
553         PreviewImage *prv_img = (PreviewImage *)ptr->data;
554
555         unsigned char *data = (unsigned char *)prv_img->rect[size];
556         const size_t len = prv_img->w[size] * prv_img->h[size] * 4;
557         size_t i;
558
559         BLI_assert(sizeof(unsigned int) == 4);
560
561         if (id != NULL) {
562                 BLI_assert(prv_img == BKE_previewimg_id_ensure(id));
563         }
564
565         BKE_previewimg_ensure(prv_img, size);
566
567         for (i = 0; i < len; i++) {
568                 values[i] = data[i] * (1.0f / 255.0f);
569         }
570 }
571
572 static void rna_ImagePreview_pixels_float_set(PointerRNA *ptr, const float *values, enum eIconSizes size)
573 {
574         ID *id = ptr->id.data;
575         PreviewImage *prv_img = (PreviewImage *)ptr->data;
576
577         unsigned char *data = (unsigned char *)prv_img->rect[size];
578         const size_t len = prv_img->w[size] * prv_img->h[size] * 4;
579         size_t i;
580
581         BLI_assert(sizeof(unsigned int) == 4);
582
583         if (id != NULL) {
584                 BLI_assert(prv_img == BKE_previewimg_id_ensure(id));
585         }
586
587         for (i = 0; i < len; i++) {
588                 data[i] = FTOCHAR(values[i]);
589         }
590         prv_img->flag[size] |= PRV_USER_EDITED;
591 }
592
593
594 static void rna_ImagePreview_is_image_custom_set(PointerRNA *ptr, int value)
595 {
596         rna_ImagePreview_is_custom_set(ptr, value, ICON_SIZE_PREVIEW);
597 }
598
599 static void rna_ImagePreview_image_size_get(PointerRNA *ptr, int *values)
600 {
601         rna_ImagePreview_size_get(ptr, values, ICON_SIZE_PREVIEW);
602 }
603
604 static void rna_ImagePreview_image_size_set(PointerRNA *ptr, const int *values)
605 {
606         rna_ImagePreview_size_set(ptr, values, ICON_SIZE_PREVIEW);
607 }
608
609 static int rna_ImagePreview_image_pixels_get_length(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION])
610 {
611         return rna_ImagePreview_pixels_get_length(ptr, length, ICON_SIZE_PREVIEW);
612 }
613
614 static void rna_ImagePreview_image_pixels_get(PointerRNA *ptr, int *values)
615 {
616         rna_ImagePreview_pixels_get(ptr, values, ICON_SIZE_PREVIEW);
617 }
618
619 static void rna_ImagePreview_image_pixels_set(PointerRNA *ptr, const int *values)
620 {
621         rna_ImagePreview_pixels_set(ptr, values, ICON_SIZE_PREVIEW);
622 }
623
624 static int rna_ImagePreview_image_pixels_float_get_length(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION])
625 {
626         return rna_ImagePreview_pixels_float_get_length(ptr, length, ICON_SIZE_PREVIEW);
627 }
628
629 static void rna_ImagePreview_image_pixels_float_get(PointerRNA *ptr, float *values)
630 {
631         rna_ImagePreview_pixels_float_get(ptr, values, ICON_SIZE_PREVIEW);
632 }
633
634 static void rna_ImagePreview_image_pixels_float_set(PointerRNA *ptr, const float *values)
635 {
636         rna_ImagePreview_pixels_float_set(ptr, values, ICON_SIZE_PREVIEW);
637 }
638
639
640 static void rna_ImagePreview_is_icon_custom_set(PointerRNA *ptr, int value)
641 {
642         rna_ImagePreview_is_custom_set(ptr, value, ICON_SIZE_ICON);
643 }
644
645 static void rna_ImagePreview_icon_size_get(PointerRNA *ptr, int *values)
646 {
647         rna_ImagePreview_size_get(ptr, values, ICON_SIZE_ICON);
648 }
649
650 static void rna_ImagePreview_icon_size_set(PointerRNA *ptr, const int *values)
651 {
652         rna_ImagePreview_size_set(ptr, values, ICON_SIZE_ICON);
653 }
654
655 static int rna_ImagePreview_icon_pixels_get_length(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION])
656 {
657         return rna_ImagePreview_pixels_get_length(ptr, length, ICON_SIZE_ICON);
658 }
659
660 static void rna_ImagePreview_icon_pixels_get(PointerRNA *ptr, int *values)
661 {
662         rna_ImagePreview_pixels_get(ptr, values, ICON_SIZE_ICON);
663 }
664
665 static void rna_ImagePreview_icon_pixels_set(PointerRNA *ptr, const int *values)
666 {
667         rna_ImagePreview_pixels_set(ptr, values, ICON_SIZE_ICON);
668 }
669
670 static int rna_ImagePreview_icon_pixels_float_get_length(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION])
671 {
672         return rna_ImagePreview_pixels_float_get_length(ptr, length, ICON_SIZE_ICON);
673 }
674
675 static void rna_ImagePreview_icon_pixels_float_get(PointerRNA *ptr, float *values)
676 {
677         rna_ImagePreview_pixels_float_get(ptr, values, ICON_SIZE_ICON);
678 }
679
680 static void rna_ImagePreview_icon_pixels_float_set(PointerRNA *ptr, const float *values)
681 {
682         rna_ImagePreview_pixels_float_set(ptr, values, ICON_SIZE_ICON);
683 }
684
685
686 static int rna_ImagePreview_icon_id_get(PointerRNA *ptr)
687 {
688         /* Using a callback here allows us to only generate icon matching that preview when icon_id is requested. */
689         return BKE_icon_preview_ensure((PreviewImage *)(ptr->data));
690 }
691 static void rna_ImagePreview_icon_reload(PreviewImage *prv)
692 {
693         /* will lazy load on next use, but only in case icon is not user-modified! */
694         if (!(prv->flag[ICON_SIZE_ICON] & PRV_USER_EDITED) && !(prv->flag[ICON_SIZE_PREVIEW] & PRV_USER_EDITED)) {
695                 BKE_previewimg_clear(prv);
696         }
697 }
698
699 static PointerRNA rna_IDPreview_get(PointerRNA *ptr)
700 {
701         ID *id = (ID *)ptr->data;
702         PreviewImage *prv_img = BKE_previewimg_id_ensure(id);
703
704         return rna_pointer_inherit_refine(ptr, &RNA_ImagePreview, prv_img);
705 }
706
707 #else
708
709 static void rna_def_ID_properties(BlenderRNA *brna)
710 {
711         StructRNA *srna;
712         PropertyRNA *prop;
713
714         /* this is struct is used for holding the virtual
715          * PropertyRNA's for ID properties */
716         srna = RNA_def_struct(brna, "PropertyGroupItem", NULL);
717         RNA_def_struct_sdna(srna, "IDProperty");
718         RNA_def_struct_ui_text(srna, "ID Property", "Property that stores arbitrary, user defined properties");
719         
720         /* IDP_STRING */
721         prop = RNA_def_property(srna, "string", PROP_STRING, PROP_NONE);
722         RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
723
724         /* IDP_INT */
725         prop = RNA_def_property(srna, "int", PROP_INT, PROP_NONE);
726         RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
727
728         prop = RNA_def_property(srna, "int_array", PROP_INT, PROP_NONE);
729         RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
730         RNA_def_property_array(prop, 1);
731
732         /* IDP_FLOAT */
733         prop = RNA_def_property(srna, "float", PROP_FLOAT, PROP_NONE);
734         RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
735
736         prop = RNA_def_property(srna, "float_array", PROP_FLOAT, PROP_NONE);
737         RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
738         RNA_def_property_array(prop, 1);
739
740         /* IDP_DOUBLE */
741         prop = RNA_def_property(srna, "double", PROP_FLOAT, PROP_NONE);
742         RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
743
744         prop = RNA_def_property(srna, "double_array", PROP_FLOAT, PROP_NONE);
745         RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
746         RNA_def_property_array(prop, 1);
747
748         /* IDP_GROUP */
749         prop = RNA_def_property(srna, "group", PROP_POINTER, PROP_NONE);
750         RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
751         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
752         RNA_def_property_struct_type(prop, "PropertyGroup");
753
754         prop = RNA_def_property(srna, "collection", PROP_COLLECTION, PROP_NONE);
755         RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
756         RNA_def_property_struct_type(prop, "PropertyGroup");
757
758         prop = RNA_def_property(srna, "idp_array", PROP_COLLECTION, PROP_NONE);
759         RNA_def_property_struct_type(prop, "PropertyGroup");
760         RNA_def_property_collection_funcs(prop, "rna_IDPArray_begin", "rna_iterator_array_next", "rna_iterator_array_end",
761                                           "rna_iterator_array_get", "rna_IDPArray_length", NULL, NULL, NULL);
762         RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
763
764         /* never tested, maybe its useful to have this? */
765 #if 0
766         prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
767         RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
768         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
769         RNA_def_property_ui_text(prop, "Name", "Unique name used in the code and scripting");
770         RNA_def_struct_name_property(srna, prop);
771 #endif
772
773         /* IDP_ID -- not implemented yet in id properties */
774
775         /* ID property groups > level 0, since level 0 group is merged
776          * with native RNA properties. the builtin_properties will take
777          * care of the properties here */
778         srna = RNA_def_struct(brna, "PropertyGroup", NULL);
779         RNA_def_struct_sdna(srna, "IDPropertyGroup");
780         RNA_def_struct_ui_text(srna, "ID Property Group", "Group of ID properties");
781         RNA_def_struct_idprops_func(srna, "rna_PropertyGroup_idprops");
782         RNA_def_struct_register_funcs(srna, "rna_PropertyGroup_register", "rna_PropertyGroup_unregister", NULL);
783         RNA_def_struct_refine_func(srna, "rna_PropertyGroup_refine");
784
785         /* important so python types can have their name used in list views
786          * however this isn't prefect because it overrides how python would set the name
787          * when we only really want this so RNA_def_struct_name_property() is set to something useful */
788         prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
789         RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
790         /*RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
791         RNA_def_property_ui_text(prop, "Name", "Unique name used in the code and scripting");
792         RNA_def_struct_name_property(srna, prop);
793 }
794
795
796 static void rna_def_ID_materials(BlenderRNA *brna)
797 {
798         StructRNA *srna;
799         FunctionRNA *func;
800         PropertyRNA *parm;
801         
802         /* for mesh/mball/curve materials */
803         srna = RNA_def_struct(brna, "IDMaterials", NULL);
804         RNA_def_struct_sdna(srna, "ID");
805         RNA_def_struct_ui_text(srna, "ID Materials", "Collection of materials");
806
807         func = RNA_def_function(srna, "append", "rna_IDMaterials_append_id");
808         RNA_def_function_ui_description(func, "Add a new material to the data block");
809         parm = RNA_def_pointer(func, "material", "Material", "", "Material to add");
810         RNA_def_property_flag(parm, PROP_REQUIRED);
811
812         func = RNA_def_function(srna, "pop", "rna_IDMaterials_pop_id");
813         RNA_def_function_flag(func, FUNC_USE_REPORTS);
814         RNA_def_function_ui_description(func, "Remove a material from the data block");
815         parm = RNA_def_int(func, "index", -1, -MAXMAT, MAXMAT, "", "Index of material to remove", 0, MAXMAT);
816         RNA_def_boolean(func, "update_data", 0, "", "Update data by re-adjusting the material slots assigned");
817         parm = RNA_def_pointer(func, "material", "Material", "", "Material to remove");
818         RNA_def_function_return(func, parm);
819
820         func = RNA_def_function(srna, "clear", "rna_IDMaterials_clear_id");
821         RNA_def_function_ui_description(func, "Remove all materials from the data block");
822         RNA_def_boolean(func, "update_data", 0, "", "Update data by re-adjusting the material slots assigned");
823 }
824
825 static void rna_def_image_preview(BlenderRNA *brna)
826 {
827         StructRNA *srna;
828         FunctionRNA *func;
829         PropertyRNA *prop;
830
831         srna = RNA_def_struct(brna, "ImagePreview", NULL);
832         RNA_def_struct_sdna(srna, "PreviewImage");
833         RNA_def_struct_ui_text(srna, "Image Preview", "Preview image and icon");
834
835         prop = RNA_def_property(srna, "is_image_custom", PROP_BOOLEAN, PROP_NONE);
836         RNA_def_property_boolean_sdna(prop, NULL, "flag[ICON_SIZE_PREVIEW]", PRV_USER_EDITED);
837         RNA_def_property_boolean_funcs(prop, NULL, "rna_ImagePreview_is_image_custom_set");
838         RNA_def_property_ui_text(prop, "Custom Image", "True if this preview image has been modified by py script,"
839                                  "and is no more auto-generated by Blender");
840
841         prop = RNA_def_int_vector(srna, "image_size", 2, NULL, 0, 0, "Image Size",
842                                   "Width and height in pixels", 0, 0);
843         RNA_def_property_subtype(prop, PROP_PIXEL);
844         RNA_def_property_int_funcs(prop, "rna_ImagePreview_image_size_get", "rna_ImagePreview_image_size_set", NULL);
845
846         prop = RNA_def_property(srna, "image_pixels", PROP_INT, PROP_NONE);
847         RNA_def_property_flag(prop, PROP_DYNAMIC);
848         RNA_def_property_multi_array(prop, 1, NULL);
849         RNA_def_property_ui_text(prop, "Image Pixels", "Image pixels, as bytes (always RGBA 32bits)");
850         RNA_def_property_dynamic_array_funcs(prop, "rna_ImagePreview_image_pixels_get_length");
851         RNA_def_property_int_funcs(prop, "rna_ImagePreview_image_pixels_get", "rna_ImagePreview_image_pixels_set", NULL);
852
853         prop = RNA_def_property(srna, "image_pixels_float", PROP_FLOAT, PROP_NONE);
854         RNA_def_property_flag(prop, PROP_DYNAMIC);
855         RNA_def_property_multi_array(prop, 1, NULL);
856         RNA_def_property_ui_text(prop, "Float Image Pixels",
857                                  "Image pixels components, as floats (RGBA concatenated values)");
858         RNA_def_property_dynamic_array_funcs(prop, "rna_ImagePreview_image_pixels_float_get_length");
859         RNA_def_property_float_funcs(prop, "rna_ImagePreview_image_pixels_float_get",
860                                      "rna_ImagePreview_image_pixels_float_set", NULL);
861
862
863         prop = RNA_def_property(srna, "is_icon_custom", PROP_BOOLEAN, PROP_NONE);
864         RNA_def_property_boolean_sdna(prop, NULL, "flag[ICON_SIZE_ICON]", PRV_USER_EDITED);
865         RNA_def_property_boolean_funcs(prop, NULL, "rna_ImagePreview_is_icon_custom_set");
866         RNA_def_property_ui_text(prop, "Custom Icon", "True if this preview icon has been modified by py script,"
867                                  "and is no more auto-generated by Blender");
868
869         prop = RNA_def_int_vector(srna, "icon_size", 2, NULL, 0, 0, "Icon Size",
870                                   "Width and height in pixels", 0, 0);
871         RNA_def_property_subtype(prop, PROP_PIXEL);
872         RNA_def_property_int_funcs(prop, "rna_ImagePreview_icon_size_get", "rna_ImagePreview_icon_size_set", NULL);
873
874         prop = RNA_def_property(srna, "icon_pixels", PROP_INT, PROP_NONE);
875         RNA_def_property_flag(prop, PROP_DYNAMIC);
876         RNA_def_property_multi_array(prop, 1, NULL);
877         RNA_def_property_ui_text(prop, "Icon Pixels", "Icon pixels, as bytes (always RGBA 32bits)");
878         RNA_def_property_dynamic_array_funcs(prop, "rna_ImagePreview_icon_pixels_get_length");
879         RNA_def_property_int_funcs(prop, "rna_ImagePreview_icon_pixels_get", "rna_ImagePreview_icon_pixels_set", NULL);
880
881         prop = RNA_def_property(srna, "icon_pixels_float", PROP_FLOAT, PROP_NONE);
882         RNA_def_property_flag(prop, PROP_DYNAMIC);
883         RNA_def_property_multi_array(prop, 1, NULL);
884         RNA_def_property_ui_text(prop, "Float Icon Pixels", "Icon pixels components, as floats (RGBA concatenated values)");
885         RNA_def_property_dynamic_array_funcs(prop, "rna_ImagePreview_icon_pixels_float_get_length");
886         RNA_def_property_float_funcs(prop, "rna_ImagePreview_icon_pixels_float_get",
887                                      "rna_ImagePreview_icon_pixels_float_set", NULL);
888
889         prop = RNA_def_int(srna, "icon_id", 0, INT_MIN, INT_MAX, "Icon ID",
890                            "Unique integer identifying this preview as an icon (zero means invalid)", INT_MIN, INT_MAX);
891         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
892         RNA_def_property_int_funcs(prop, "rna_ImagePreview_icon_id_get", NULL, NULL);
893
894         func = RNA_def_function(srna, "reload", "rna_ImagePreview_icon_reload");
895         RNA_def_function_ui_description(func, "Reload the preview from its source path");
896 }
897
898 static void rna_def_ID(BlenderRNA *brna)
899 {
900         StructRNA *srna;
901         FunctionRNA *func;
902         PropertyRNA *prop, *parm;
903
904         static EnumPropertyItem update_flag_items[] = {
905                 {OB_RECALC_OB, "OBJECT", 0, "Object", ""},
906                 {OB_RECALC_DATA, "DATA", 0, "Data", ""},
907                 {OB_RECALC_TIME, "TIME", 0, "Time", ""},
908                 {0, NULL, 0, NULL, NULL}
909         };
910
911         srna = RNA_def_struct(brna, "ID", NULL);
912         RNA_def_struct_ui_text(srna, "ID",
913                                "Base type for data-blocks, defining a unique name, linking from other libraries "
914                                "and garbage collection");
915         RNA_def_struct_flag(srna, STRUCT_ID | STRUCT_ID_REFCOUNT);
916         RNA_def_struct_refine_func(srna, "rna_ID_refine");
917         RNA_def_struct_idprops_func(srna, "rna_ID_idprops");
918
919         prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
920         RNA_def_property_ui_text(prop, "Name", "Unique data-block ID name");
921         RNA_def_property_string_funcs(prop, "rna_ID_name_get", "rna_ID_name_length", "rna_ID_name_set");
922         RNA_def_property_string_maxlength(prop, MAX_ID_NAME - 2);
923         RNA_def_property_editable_func(prop, "rna_ID_name_editable");
924         RNA_def_property_update(prop, NC_ID | NA_RENAME, NULL);
925         RNA_def_struct_name_property(srna, prop);
926
927         prop = RNA_def_property(srna, "users", PROP_INT, PROP_UNSIGNED);
928         RNA_def_property_int_sdna(prop, NULL, "us");
929         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
930         RNA_def_property_ui_text(prop, "Users", "Number of times this data-block is referenced");
931
932         prop = RNA_def_property(srna, "use_fake_user", PROP_BOOLEAN, PROP_NONE);
933         RNA_def_property_boolean_sdna(prop, NULL, "flag", LIB_FAKEUSER);
934         RNA_def_property_ui_text(prop, "Fake User", "Save this data-block even if it has no users");
935         RNA_def_property_boolean_funcs(prop, NULL, "rna_ID_fake_user_set");
936
937         prop = RNA_def_property(srna, "tag", PROP_BOOLEAN, PROP_NONE);
938         RNA_def_property_boolean_sdna(prop, NULL, "tag", LIB_TAG_DOIT);
939         RNA_def_property_flag(prop, PROP_LIB_EXCEPTION);
940         RNA_def_property_ui_text(prop, "Tag",
941                                  "Tools can use this to tag data for their own purposes "
942                                  "(initial state is undefined)");
943
944         prop = RNA_def_property(srna, "is_updated", PROP_BOOLEAN, PROP_NONE);
945         RNA_def_property_boolean_sdna(prop, NULL, "tag", LIB_TAG_ID_RECALC);
946         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
947         RNA_def_property_ui_text(prop, "Is Updated", "Datablock is tagged for recalculation");
948
949         prop = RNA_def_property(srna, "is_updated_data", PROP_BOOLEAN, PROP_NONE);
950         RNA_def_property_boolean_sdna(prop, NULL, "tag", LIB_TAG_ID_RECALC_DATA);
951         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
952         RNA_def_property_ui_text(prop, "Is Updated Data", "Datablock data is tagged for recalculation");
953
954         prop = RNA_def_property(srna, "is_library_indirect", PROP_BOOLEAN, PROP_NONE);
955         RNA_def_property_boolean_sdna(prop, NULL, "tag", LIB_TAG_INDIRECT);
956         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
957         RNA_def_property_ui_text(prop, "Is Indirect", "Is this ID block linked indirectly");
958
959         prop = RNA_def_property(srna, "library", PROP_POINTER, PROP_NONE);
960         RNA_def_property_pointer_sdna(prop, NULL, "lib");
961         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
962         RNA_def_property_ui_text(prop, "Library", "Library file the data-block is linked from");
963
964         prop = RNA_def_pointer(srna, "preview", "ImagePreview", "Preview",
965                                "Preview image and icon of this data-block (None if not supported for this type of data)");
966         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
967         RNA_def_property_pointer_funcs(prop, "rna_IDPreview_get", NULL, NULL, NULL);
968
969         /* functions */
970         func = RNA_def_function(srna, "copy", "rna_ID_copy");
971         RNA_def_function_ui_description(func, "Create a copy of this data-block (not supported for all data-blocks)");
972         RNA_def_function_flag(func, FUNC_USE_MAIN);
973         parm = RNA_def_pointer(func, "id", "ID", "", "New copy of the ID");
974         RNA_def_function_return(func, parm);
975
976         func = RNA_def_function(srna, "user_clear", "rna_ID_user_clear");
977         RNA_def_function_ui_description(func, "Clear the user count of a data-block so its not saved, "
978                                         "on reload the data will be removed");
979
980         func = RNA_def_function(srna, "user_remap", "rna_ID_user_remap");
981         RNA_def_function_ui_description(func, "Replace all usage in the .blend file of this ID by new given one");
982         RNA_def_function_flag(func, FUNC_USE_MAIN);
983         parm = RNA_def_pointer(func, "new_id", "ID", "", "New ID to use");
984         RNA_def_property_flag(parm, PROP_NEVER_NULL);
985
986         func = RNA_def_function(srna, "user_of_id", "BKE_library_ID_use_ID");
987         RNA_def_function_ui_description(func, "Count the number of times that ID uses/references given one");
988         parm = RNA_def_pointer(func, "id", "ID", "", "ID to count usages");
989         RNA_def_property_flag(parm, PROP_NEVER_NULL);
990         parm = RNA_def_int(func, "count", 0, 0, INT_MAX,
991                            "", "Number of usages/references of given id by current datablock", 0, INT_MAX);
992         RNA_def_function_return(func, parm);
993
994         func = RNA_def_function(srna, "animation_data_create", "rna_ID_animation_data_create");
995         RNA_def_function_flag(func, FUNC_USE_MAIN);
996         RNA_def_function_ui_description(func, "Create animation data to this ID, note that not all ID types support this");
997         parm = RNA_def_pointer(func, "anim_data", "AnimData", "", "New animation data or NULL");
998         RNA_def_function_return(func, parm);
999
1000         func = RNA_def_function(srna, "animation_data_clear", "rna_ID_animation_data_free");
1001         RNA_def_function_flag(func, FUNC_USE_MAIN);
1002         RNA_def_function_ui_description(func, "Clear animation on this this ID");
1003
1004         func = RNA_def_function(srna, "update_tag", "rna_ID_update_tag");
1005         RNA_def_function_flag(func, FUNC_USE_REPORTS);
1006         RNA_def_function_ui_description(func,
1007                                         "Tag the ID to update its display data, "
1008                                         "e.g. when calling :class:`bpy.types.Scene.update`");
1009         RNA_def_enum_flag(func, "refresh", update_flag_items, 0, "", "Type of updates to perform");
1010 }
1011
1012 static void rna_def_library(BlenderRNA *brna)
1013 {
1014         StructRNA *srna;
1015         PropertyRNA *prop;
1016
1017         srna = RNA_def_struct(brna, "Library", "ID");
1018         RNA_def_struct_ui_text(srna, "Library", "External .blend file from which data is linked");
1019         RNA_def_struct_ui_icon(srna, ICON_LIBRARY_DATA_DIRECT);
1020
1021         prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
1022         RNA_def_property_string_sdna(prop, NULL, "name");
1023         RNA_def_property_ui_text(prop, "File Path", "Path to the library .blend file");
1024         RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Library_filepath_set");
1025         
1026         prop = RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
1027         RNA_def_property_struct_type(prop, "Library");
1028         RNA_def_property_ui_text(prop, "Parent", "");
1029
1030         prop = RNA_def_property(srna, "packed_file", PROP_POINTER, PROP_NONE);
1031         RNA_def_property_pointer_sdna(prop, NULL, "packedfile");
1032         RNA_def_property_ui_text(prop, "Packed File", "");
1033 }
1034 void RNA_def_ID(BlenderRNA *brna)
1035 {
1036         StructRNA *srna;
1037
1038         /* built-in unknown type */
1039         srna = RNA_def_struct(brna, "UnknownType", NULL);
1040         RNA_def_struct_ui_text(srna, "Unknown Type", "Stub RNA type used for pointers to unknown or internal data");
1041
1042         /* built-in any type */
1043         srna = RNA_def_struct(brna, "AnyType", NULL);
1044         RNA_def_struct_ui_text(srna, "Any Type", "RNA type used for pointers to any possible data");
1045
1046         rna_def_ID(brna);
1047         rna_def_image_preview(brna);
1048         rna_def_ID_properties(brna);
1049         rna_def_ID_materials(brna);
1050         rna_def_library(brna);
1051 }
1052
1053 #endif