ID-Remap - Step one: core work (cleanup and rework of generic ID datablock handling).
[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_PA, "PARTICLE", ICON_PARTICLE_DATA, "Particle", ""},
75         {ID_SCE, "SCENE", ICON_SCENE_DATA, "Scene", ""},
76         {ID_SCR, "SCREEN", ICON_SPLITSCREEN, "Screen", ""},
77         {ID_SO, "SOUND", ICON_PLAY_AUDIO, "Sound", ""},
78         {ID_SPK, "SPEAKER", ICON_SPEAKER, "Speaker", ""},
79         {ID_TXT, "TEXT", ICON_TEXT, "Text", ""},
80         {ID_TE, "TEXTURE", ICON_TEXTURE_DATA, "Texture", ""},
81         {ID_WM, "WINDOWMANAGER", ICON_FULLSCREEN, "Window Manager", ""},
82         {ID_WO, "WORLD", ICON_WORLD_DATA, "World", ""},
83         {0, NULL, 0, NULL, NULL}
84 };
85
86 #ifdef RNA_RUNTIME
87
88 #include "DNA_anim_types.h"
89
90 #include "BKE_font.h"
91 #include "BKE_idprop.h"
92 #include "BKE_library.h"
93 #include "BKE_library_query.h"
94 #include "BKE_animsys.h"
95 #include "BKE_material.h"
96 #include "BKE_depsgraph.h"
97 #include "BKE_global.h"  /* XXX, remove me */
98
99 #include "WM_api.h"
100
101 /* name functions that ignore the first two ID characters */
102 void rna_ID_name_get(PointerRNA *ptr, char *value)
103 {
104         ID *id = (ID *)ptr->data;
105         BLI_strncpy(value, id->name + 2, sizeof(id->name) - 2);
106 }
107
108 int rna_ID_name_length(PointerRNA *ptr)
109 {
110         ID *id = (ID *)ptr->data;
111         return strlen(id->name + 2);
112 }
113
114 void rna_ID_name_set(PointerRNA *ptr, const char *value)
115 {
116         ID *id = (ID *)ptr->data;
117         BLI_strncpy_utf8(id->name + 2, value, sizeof(id->name) - 2);
118         BLI_libblock_ensure_unique_name(G.main, id->name);
119 }
120
121 static int rna_ID_name_editable(PointerRNA *ptr)
122 {
123         ID *id = (ID *)ptr->data;
124         
125         if (GS(id->name) == ID_VF) {
126                 VFont *vfont = (VFont *)id;
127                 if (BKE_vfont_is_builtin(vfont))
128                         return false;
129         }
130         
131         return PROP_EDITABLE;
132 }
133
134 short RNA_type_to_ID_code(StructRNA *type)
135 {
136         if (RNA_struct_is_a(type, &RNA_Action)) return ID_AC;
137         if (RNA_struct_is_a(type, &RNA_Armature)) return ID_AR;
138         if (RNA_struct_is_a(type, &RNA_Brush)) return ID_BR;
139         if (RNA_struct_is_a(type, &RNA_Camera)) return ID_CA;
140         if (RNA_struct_is_a(type, &RNA_Curve)) return ID_CU;
141         if (RNA_struct_is_a(type, &RNA_GreasePencil)) return ID_GD;
142         if (RNA_struct_is_a(type, &RNA_Group)) return ID_GR;
143         if (RNA_struct_is_a(type, &RNA_Image)) return ID_IM;
144         if (RNA_struct_is_a(type, &RNA_Key)) return ID_KE;
145         if (RNA_struct_is_a(type, &RNA_Lamp)) return ID_LA;
146         if (RNA_struct_is_a(type, &RNA_Library)) return ID_LI;
147         if (RNA_struct_is_a(type, &RNA_FreestyleLineStyle)) return ID_LS;
148         if (RNA_struct_is_a(type, &RNA_Lattice)) return ID_LT;
149         if (RNA_struct_is_a(type, &RNA_Material)) return ID_MA;
150         if (RNA_struct_is_a(type, &RNA_MetaBall)) return ID_MB;
151         if (RNA_struct_is_a(type, &RNA_MovieClip)) return ID_MC;
152         if (RNA_struct_is_a(type, &RNA_Mesh)) return ID_ME;
153         if (RNA_struct_is_a(type, &RNA_Mask)) return ID_MSK;
154         if (RNA_struct_is_a(type, &RNA_NodeTree)) return ID_NT;
155         if (RNA_struct_is_a(type, &RNA_Object)) return ID_OB;
156         if (RNA_struct_is_a(type, &RNA_ParticleSettings)) return ID_PA;
157         if (RNA_struct_is_a(type, &RNA_Palette)) return ID_PAL;
158         if (RNA_struct_is_a(type, &RNA_PaintCurve)) return ID_PC;
159         if (RNA_struct_is_a(type, &RNA_Scene)) return ID_SCE;
160         if (RNA_struct_is_a(type, &RNA_Screen)) return ID_SCR;
161         if (RNA_struct_is_a(type, &RNA_Sound)) return ID_SO;
162         if (RNA_struct_is_a(type, &RNA_Speaker)) return ID_SPK;
163         if (RNA_struct_is_a(type, &RNA_Texture)) return ID_TE;
164         if (RNA_struct_is_a(type, &RNA_Text)) return ID_TXT;
165         if (RNA_struct_is_a(type, &RNA_VectorFont)) return ID_VF;
166         if (RNA_struct_is_a(type, &RNA_World)) return ID_WO;
167         if (RNA_struct_is_a(type, &RNA_WindowManager)) return ID_WM;
168
169         return 0;
170 }
171
172 StructRNA *ID_code_to_RNA_type(short idcode)
173 {
174         switch (idcode) {
175                 case ID_AC: return &RNA_Action;
176                 case ID_AR: return &RNA_Armature;
177                 case ID_BR: return &RNA_Brush;
178                 case ID_CA: return &RNA_Camera;
179                 case ID_CU: return &RNA_Curve;
180                 case ID_GD: return &RNA_GreasePencil;
181                 case ID_GR: return &RNA_Group;
182                 case ID_IM: return &RNA_Image;
183                 case ID_KE: return &RNA_Key;
184                 case ID_LA: return &RNA_Lamp;
185                 case ID_LI: return &RNA_Library;
186                 case ID_LS: return &RNA_FreestyleLineStyle;
187                 case ID_LT: return &RNA_Lattice;
188                 case ID_MA: return &RNA_Material;
189                 case ID_MB: return &RNA_MetaBall;
190                 case ID_MC: return &RNA_MovieClip;
191                 case ID_ME: return &RNA_Mesh;
192                 case ID_MSK: return &RNA_Mask;
193                 case ID_NT: return &RNA_NodeTree;
194                 case ID_OB: return &RNA_Object;
195                 case ID_PA: return &RNA_ParticleSettings;
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)
278 {
279         ID *newid;
280
281         if (id_copy(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                                 /* Could add particle updates later */
313 #if 0
314                         case ID_PA:
315                                 if (flag & ~(OB_RECALC_ALL | PSYS_RECALC)) {
316                                         BKE_report(reports, RPT_ERROR, "'Refresh' incompatible with ParticleSettings ID type");
317                                         return;
318                                 }
319                                 break;
320 #endif
321                         default:
322                                 BKE_report(reports, RPT_ERROR, "This ID type is not compatible with any 'refresh' options");
323                                 return;
324                 }
325         }
326
327         DAG_id_tag_update(id, flag);
328 }
329
330 static void rna_ID_user_clear(ID *id)
331 {
332         id_fake_user_clear(id);
333         id->us = 0; /* don't save */
334 }
335
336 static AnimData * rna_ID_animation_data_create(ID *id, Main *bmain)
337 {
338         AnimData *adt = BKE_animdata_add_id(id);
339         DAG_relations_tag_update(bmain);
340         return adt;
341 }
342
343 static void rna_ID_animation_data_free(ID *id, Main *bmain)
344 {
345         BKE_animdata_free(id, true);
346         DAG_relations_tag_update(bmain);
347 }
348
349 static void rna_IDPArray_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
350 {
351         IDProperty *prop = (IDProperty *)ptr->data;
352         rna_iterator_array_begin(iter, IDP_IDPArray(prop), sizeof(IDProperty), prop->len, 0, NULL);
353 }
354
355 static int rna_IDPArray_length(PointerRNA *ptr)
356 {
357         IDProperty *prop = (IDProperty *)ptr->data;
358         return prop->len;
359 }
360
361 int rna_IDMaterials_assign_int(PointerRNA *ptr, int key, const PointerRNA *assign_ptr)
362 {
363         ID *id =           ptr->id.data;
364         short *totcol = give_totcolp_id(id);
365         Material *mat_id = assign_ptr->id.data;
366         if (totcol && (key >= 0 && key < *totcol)) {
367                 assign_material_id(id, mat_id, key + 1);
368                 return 1;
369         }
370         else {
371                 return 0;
372         }
373 }
374
375 static void rna_IDMaterials_append_id(ID *id, Material *ma)
376 {
377         BKE_material_append_id(id, ma);
378
379         WM_main_add_notifier(NC_OBJECT | ND_DRAW, id);
380         WM_main_add_notifier(NC_OBJECT | ND_OB_SHADING, id);
381 }
382
383 static Material *rna_IDMaterials_pop_id(ID *id, ReportList *reports, int index_i, int remove_material_slot)
384 {
385         Material *ma;
386         short *totcol = give_totcolp_id(id);
387         const short totcol_orig = *totcol;
388         if (index_i < 0) {
389                 index_i += (*totcol);
390         }
391
392         if ((index_i < 0) || (index_i >= (*totcol))) {
393                 BKE_report(reports, RPT_ERROR, "Index out of range");
394                 return NULL;
395         }
396
397         ma = BKE_material_pop_id(id, index_i, remove_material_slot);
398
399         if (*totcol == totcol_orig) {
400                 BKE_report(reports, RPT_ERROR, "No material to removed");
401                 return NULL;
402         }
403
404         DAG_id_tag_update(id, OB_RECALC_DATA);
405         WM_main_add_notifier(NC_OBJECT | ND_DRAW, id);
406         WM_main_add_notifier(NC_OBJECT | ND_OB_SHADING, id);
407
408         return ma;
409 }
410
411 static void rna_IDMaterials_clear_id(ID *id, int remove_material_slot)
412 {
413         BKE_material_clear_id(id, remove_material_slot);
414
415         DAG_id_tag_update(id, OB_RECALC_DATA);
416         WM_main_add_notifier(NC_OBJECT | ND_DRAW, id);
417         WM_main_add_notifier(NC_OBJECT | ND_OB_SHADING, id);
418 }
419
420 static void rna_Library_filepath_set(PointerRNA *ptr, const char *value)
421 {
422         Library *lib = (Library *)ptr->data;
423         BKE_library_filepath_set(lib, value);
424 }
425
426 /* ***** ImagePreview ***** */
427
428 static void rna_ImagePreview_is_custom_set(PointerRNA *ptr, int value, enum eIconSizes size)
429 {
430         ID *id = ptr->id.data;
431         PreviewImage *prv_img = (PreviewImage *)ptr->data;
432
433         if (id != NULL) {
434                 BLI_assert(prv_img == BKE_previewimg_id_ensure(id));
435         }
436
437         if ((value && (prv_img->flag[size] & PRV_USER_EDITED)) || (!value && !(prv_img->flag[size] & PRV_USER_EDITED))) {
438                 return;
439         }
440
441         if (value)
442                 prv_img->flag[size] |= PRV_USER_EDITED;
443         else
444                 prv_img->flag[size] &= ~PRV_USER_EDITED;
445
446         prv_img->flag[size] |= PRV_CHANGED;
447
448         BKE_previewimg_clear_single(prv_img, size);
449 }
450
451 static void rna_ImagePreview_size_get(PointerRNA *ptr, int *values, enum eIconSizes size)
452 {
453         ID *id = (ID *)ptr->id.data;
454         PreviewImage *prv_img = (PreviewImage *)ptr->data;
455
456         if (id != NULL) {
457                 BLI_assert(prv_img == BKE_previewimg_id_ensure(id));
458         }
459
460         BKE_previewimg_ensure(prv_img, size);
461
462         values[0] = prv_img->w[size];
463         values[1] = prv_img->h[size];
464 }
465
466 static void rna_ImagePreview_size_set(PointerRNA *ptr, const int *values, enum eIconSizes size)
467 {
468         ID *id = (ID *)ptr->id.data;
469         PreviewImage *prv_img = (PreviewImage *)ptr->data;
470
471         if (id != NULL) {
472                 BLI_assert(prv_img == BKE_previewimg_id_ensure(id));
473         }
474
475         BKE_previewimg_clear_single(prv_img, size);
476
477         if (values[0] && values[1]) {
478                 prv_img->rect[size] = MEM_callocN(values[0] * values[1] * sizeof(unsigned int), "prv_rect");
479
480                 prv_img->w[size] = values[0];
481                 prv_img->h[size] = values[1];
482         }
483
484         prv_img->flag[size] |= (PRV_CHANGED | PRV_USER_EDITED);
485 }
486
487
488 static int rna_ImagePreview_pixels_get_length(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION], enum eIconSizes size)
489 {
490         ID *id = ptr->id.data;
491         PreviewImage *prv_img = (PreviewImage *)ptr->data;
492
493         if (id != NULL) {
494                 BLI_assert(prv_img == BKE_previewimg_id_ensure(id));
495         }
496
497         BKE_previewimg_ensure(prv_img, size);
498
499         length[0] = prv_img->w[size] * prv_img->h[size];
500
501         return length[0];
502 }
503
504 static void rna_ImagePreview_pixels_get(PointerRNA *ptr, int *values, enum eIconSizes size)
505 {
506         ID *id = ptr->id.data;
507         PreviewImage *prv_img = (PreviewImage *)ptr->data;
508
509         if (id != NULL) {
510                 BLI_assert(prv_img == BKE_previewimg_id_ensure(id));
511         }
512
513         BKE_previewimg_ensure(prv_img, size);
514
515         memcpy(values, prv_img->rect[size], prv_img->w[size] * prv_img->h[size] * sizeof(unsigned int));
516 }
517
518 static void rna_ImagePreview_pixels_set(PointerRNA *ptr, const int *values, enum eIconSizes size)
519 {
520         ID *id = ptr->id.data;
521         PreviewImage *prv_img = (PreviewImage *)ptr->data;
522
523         if (id != NULL) {
524                 BLI_assert(prv_img == BKE_previewimg_id_ensure(id));
525         }
526
527         memcpy(prv_img->rect[size], values, prv_img->w[size] * prv_img->h[size] * sizeof(unsigned int));
528         prv_img->flag[size] |= PRV_USER_EDITED;
529 }
530
531
532 static int rna_ImagePreview_pixels_float_get_length(
533         PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION], enum eIconSizes size)
534 {
535         ID *id = ptr->id.data;
536         PreviewImage *prv_img = (PreviewImage *)ptr->data;
537
538         BLI_assert(sizeof(unsigned int) == 4);
539
540         if (id != NULL) {
541                 BLI_assert(prv_img == BKE_previewimg_id_ensure(id));
542         }
543
544         BKE_previewimg_ensure(prv_img, size);
545
546         length[0] = prv_img->w[size] * prv_img->h[size] * 4;
547
548         return length[0];
549 }
550
551 static void rna_ImagePreview_pixels_float_get(PointerRNA *ptr, float *values, enum eIconSizes size)
552 {
553         ID *id = ptr->id.data;
554         PreviewImage *prv_img = (PreviewImage *)ptr->data;
555
556         unsigned char *data = (unsigned char *)prv_img->rect[size];
557         const size_t len = prv_img->w[size] * prv_img->h[size] * 4;
558         size_t i;
559
560         BLI_assert(sizeof(unsigned int) == 4);
561
562         if (id != NULL) {
563                 BLI_assert(prv_img == BKE_previewimg_id_ensure(id));
564         }
565
566         BKE_previewimg_ensure(prv_img, size);
567
568         for (i = 0; i < len; i++) {
569                 values[i] = data[i] * (1.0f / 255.0f);
570         }
571 }
572
573 static void rna_ImagePreview_pixels_float_set(PointerRNA *ptr, const float *values, enum eIconSizes size)
574 {
575         ID *id = ptr->id.data;
576         PreviewImage *prv_img = (PreviewImage *)ptr->data;
577
578         unsigned char *data = (unsigned char *)prv_img->rect[size];
579         const size_t len = prv_img->w[size] * prv_img->h[size] * 4;
580         size_t i;
581
582         BLI_assert(sizeof(unsigned int) == 4);
583
584         if (id != NULL) {
585                 BLI_assert(prv_img == BKE_previewimg_id_ensure(id));
586         }
587
588         for (i = 0; i < len; i++) {
589                 data[i] = FTOCHAR(values[i]);
590         }
591         prv_img->flag[size] |= PRV_USER_EDITED;
592 }
593
594
595 static void rna_ImagePreview_is_image_custom_set(PointerRNA *ptr, int value)
596 {
597         rna_ImagePreview_is_custom_set(ptr, value, ICON_SIZE_PREVIEW);
598 }
599
600 static void rna_ImagePreview_image_size_get(PointerRNA *ptr, int *values)
601 {
602         rna_ImagePreview_size_get(ptr, values, ICON_SIZE_PREVIEW);
603 }
604
605 static void rna_ImagePreview_image_size_set(PointerRNA *ptr, const int *values)
606 {
607         rna_ImagePreview_size_set(ptr, values, ICON_SIZE_PREVIEW);
608 }
609
610 static int rna_ImagePreview_image_pixels_get_length(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION])
611 {
612         return rna_ImagePreview_pixels_get_length(ptr, length, ICON_SIZE_PREVIEW);
613 }
614
615 static void rna_ImagePreview_image_pixels_get(PointerRNA *ptr, int *values)
616 {
617         rna_ImagePreview_pixels_get(ptr, values, ICON_SIZE_PREVIEW);
618 }
619
620 static void rna_ImagePreview_image_pixels_set(PointerRNA *ptr, const int *values)
621 {
622         rna_ImagePreview_pixels_set(ptr, values, ICON_SIZE_PREVIEW);
623 }
624
625 static int rna_ImagePreview_image_pixels_float_get_length(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION])
626 {
627         return rna_ImagePreview_pixels_float_get_length(ptr, length, ICON_SIZE_PREVIEW);
628 }
629
630 static void rna_ImagePreview_image_pixels_float_get(PointerRNA *ptr, float *values)
631 {
632         rna_ImagePreview_pixels_float_get(ptr, values, ICON_SIZE_PREVIEW);
633 }
634
635 static void rna_ImagePreview_image_pixels_float_set(PointerRNA *ptr, const float *values)
636 {
637         rna_ImagePreview_pixels_float_set(ptr, values, ICON_SIZE_PREVIEW);
638 }
639
640
641 static void rna_ImagePreview_is_icon_custom_set(PointerRNA *ptr, int value)
642 {
643         rna_ImagePreview_is_custom_set(ptr, value, ICON_SIZE_ICON);
644 }
645
646 static void rna_ImagePreview_icon_size_get(PointerRNA *ptr, int *values)
647 {
648         rna_ImagePreview_size_get(ptr, values, ICON_SIZE_ICON);
649 }
650
651 static void rna_ImagePreview_icon_size_set(PointerRNA *ptr, const int *values)
652 {
653         rna_ImagePreview_size_set(ptr, values, ICON_SIZE_ICON);
654 }
655
656 static int rna_ImagePreview_icon_pixels_get_length(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION])
657 {
658         return rna_ImagePreview_pixels_get_length(ptr, length, ICON_SIZE_ICON);
659 }
660
661 static void rna_ImagePreview_icon_pixels_get(PointerRNA *ptr, int *values)
662 {
663         rna_ImagePreview_pixels_get(ptr, values, ICON_SIZE_ICON);
664 }
665
666 static void rna_ImagePreview_icon_pixels_set(PointerRNA *ptr, const int *values)
667 {
668         rna_ImagePreview_pixels_set(ptr, values, ICON_SIZE_ICON);
669 }
670
671 static int rna_ImagePreview_icon_pixels_float_get_length(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION])
672 {
673         return rna_ImagePreview_pixels_float_get_length(ptr, length, ICON_SIZE_ICON);
674 }
675
676 static void rna_ImagePreview_icon_pixels_float_get(PointerRNA *ptr, float *values)
677 {
678         rna_ImagePreview_pixels_float_get(ptr, values, ICON_SIZE_ICON);
679 }
680
681 static void rna_ImagePreview_icon_pixels_float_set(PointerRNA *ptr, const float *values)
682 {
683         rna_ImagePreview_pixels_float_set(ptr, values, ICON_SIZE_ICON);
684 }
685
686
687 static int rna_ImagePreview_icon_id_get(PointerRNA *ptr)
688 {
689         /* Using a callback here allows us to only generate icon matching that preview when icon_id is requested. */
690         return BKE_icon_preview_ensure((PreviewImage *)(ptr->data));
691 }
692 static void rna_ImagePreview_icon_reload(PreviewImage *prv)
693 {
694         /* will lazy load on next use, but only in case icon is not user-modified! */
695         if (!(prv->flag[ICON_SIZE_ICON] & PRV_USER_EDITED) && !(prv->flag[ICON_SIZE_PREVIEW] & PRV_USER_EDITED)) {
696                 BKE_previewimg_clear(prv);
697         }
698 }
699
700 static PointerRNA rna_IDPreview_get(PointerRNA *ptr)
701 {
702         ID *id = (ID *)ptr->data;
703         PreviewImage *prv_img = BKE_previewimg_id_ensure(id);
704
705         return rna_pointer_inherit_refine(ptr, &RNA_ImagePreview, prv_img);
706 }
707
708 #else
709
710 static void rna_def_ID_properties(BlenderRNA *brna)
711 {
712         StructRNA *srna;
713         PropertyRNA *prop;
714
715         /* this is struct is used for holding the virtual
716          * PropertyRNA's for ID properties */
717         srna = RNA_def_struct(brna, "PropertyGroupItem", NULL);
718         RNA_def_struct_sdna(srna, "IDProperty");
719         RNA_def_struct_ui_text(srna, "ID Property", "Property that stores arbitrary, user defined properties");
720         
721         /* IDP_STRING */
722         prop = RNA_def_property(srna, "string", PROP_STRING, PROP_NONE);
723         RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
724
725         /* IDP_INT */
726         prop = RNA_def_property(srna, "int", PROP_INT, PROP_NONE);
727         RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
728
729         prop = RNA_def_property(srna, "int_array", PROP_INT, PROP_NONE);
730         RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
731         RNA_def_property_array(prop, 1);
732
733         /* IDP_FLOAT */
734         prop = RNA_def_property(srna, "float", PROP_FLOAT, PROP_NONE);
735         RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
736
737         prop = RNA_def_property(srna, "float_array", PROP_FLOAT, PROP_NONE);
738         RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
739         RNA_def_property_array(prop, 1);
740
741         /* IDP_DOUBLE */
742         prop = RNA_def_property(srna, "double", PROP_FLOAT, PROP_NONE);
743         RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
744
745         prop = RNA_def_property(srna, "double_array", PROP_FLOAT, PROP_NONE);
746         RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
747         RNA_def_property_array(prop, 1);
748
749         /* IDP_GROUP */
750         prop = RNA_def_property(srna, "group", PROP_POINTER, PROP_NONE);
751         RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
752         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
753         RNA_def_property_struct_type(prop, "PropertyGroup");
754
755         prop = RNA_def_property(srna, "collection", PROP_COLLECTION, PROP_NONE);
756         RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
757         RNA_def_property_struct_type(prop, "PropertyGroup");
758
759         prop = RNA_def_property(srna, "idp_array", PROP_COLLECTION, PROP_NONE);
760         RNA_def_property_struct_type(prop, "PropertyGroup");
761         RNA_def_property_collection_funcs(prop, "rna_IDPArray_begin", "rna_iterator_array_next", "rna_iterator_array_end",
762                                           "rna_iterator_array_get", "rna_IDPArray_length", NULL, NULL, NULL);
763         RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
764
765         /* never tested, maybe its useful to have this? */
766 #if 0
767         prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
768         RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
769         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
770         RNA_def_property_ui_text(prop, "Name", "Unique name used in the code and scripting");
771         RNA_def_struct_name_property(srna, prop);
772 #endif
773
774         /* IDP_ID -- not implemented yet in id properties */
775
776         /* ID property groups > level 0, since level 0 group is merged
777          * with native RNA properties. the builtin_properties will take
778          * care of the properties here */
779         srna = RNA_def_struct(brna, "PropertyGroup", NULL);
780         RNA_def_struct_sdna(srna, "IDPropertyGroup");
781         RNA_def_struct_ui_text(srna, "ID Property Group", "Group of ID properties");
782         RNA_def_struct_idprops_func(srna, "rna_PropertyGroup_idprops");
783         RNA_def_struct_register_funcs(srna, "rna_PropertyGroup_register", "rna_PropertyGroup_unregister", NULL);
784         RNA_def_struct_refine_func(srna, "rna_PropertyGroup_refine");
785
786         /* important so python types can have their name used in list views
787          * however this isn't prefect because it overrides how python would set the name
788          * when we only really want this so RNA_def_struct_name_property() is set to something useful */
789         prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
790         RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
791         /*RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
792         RNA_def_property_ui_text(prop, "Name", "Unique name used in the code and scripting");
793         RNA_def_struct_name_property(srna, prop);
794 }
795
796
797 static void rna_def_ID_materials(BlenderRNA *brna)
798 {
799         StructRNA *srna;
800         FunctionRNA *func;
801         PropertyRNA *parm;
802         
803         /* for mesh/mball/curve materials */
804         srna = RNA_def_struct(brna, "IDMaterials", NULL);
805         RNA_def_struct_sdna(srna, "ID");
806         RNA_def_struct_ui_text(srna, "ID Materials", "Collection of materials");
807
808         func = RNA_def_function(srna, "append", "rna_IDMaterials_append_id");
809         RNA_def_function_ui_description(func, "Add a new material to the data block");
810         parm = RNA_def_pointer(func, "material", "Material", "", "Material to add");
811         RNA_def_property_flag(parm, PROP_REQUIRED);
812
813         func = RNA_def_function(srna, "pop", "rna_IDMaterials_pop_id");
814         RNA_def_function_flag(func, FUNC_USE_REPORTS);
815         RNA_def_function_ui_description(func, "Remove a material from the data block");
816         parm = RNA_def_int(func, "index", -1, -MAXMAT, MAXMAT, "", "Index of material to remove", 0, MAXMAT);
817         RNA_def_boolean(func, "update_data", 0, "", "Update data by re-adjusting the material slots assigned");
818         parm = RNA_def_pointer(func, "material", "Material", "", "Material to remove");
819         RNA_def_function_return(func, parm);
820
821         func = RNA_def_function(srna, "clear", "rna_IDMaterials_clear_id");
822         RNA_def_function_ui_description(func, "Remove all materials from the data block");
823         RNA_def_boolean(func, "update_data", 0, "", "Update data by re-adjusting the material slots assigned");
824 }
825
826 static void rna_def_image_preview(BlenderRNA *brna)
827 {
828         StructRNA *srna;
829         FunctionRNA *func;
830         PropertyRNA *prop;
831
832         srna = RNA_def_struct(brna, "ImagePreview", NULL);
833         RNA_def_struct_sdna(srna, "PreviewImage");
834         RNA_def_struct_ui_text(srna, "Image Preview", "Preview image and icon");
835
836         prop = RNA_def_property(srna, "is_image_custom", PROP_BOOLEAN, PROP_NONE);
837         RNA_def_property_boolean_sdna(prop, NULL, "flag[ICON_SIZE_PREVIEW]", PRV_USER_EDITED);
838         RNA_def_property_boolean_funcs(prop, NULL, "rna_ImagePreview_is_image_custom_set");
839         RNA_def_property_ui_text(prop, "Custom Image", "True if this preview image has been modified by py script,"
840                                  "and is no more auto-generated by Blender");
841
842         prop = RNA_def_int_vector(srna, "image_size", 2, NULL, 0, 0, "Image Size",
843                                   "Width and height in pixels", 0, 0);
844         RNA_def_property_subtype(prop, PROP_PIXEL);
845         RNA_def_property_int_funcs(prop, "rna_ImagePreview_image_size_get", "rna_ImagePreview_image_size_set", NULL);
846
847         prop = RNA_def_property(srna, "image_pixels", PROP_INT, PROP_NONE);
848         RNA_def_property_flag(prop, PROP_DYNAMIC);
849         RNA_def_property_multi_array(prop, 1, NULL);
850         RNA_def_property_ui_text(prop, "Image Pixels", "Image pixels, as bytes (always RGBA 32bits)");
851         RNA_def_property_dynamic_array_funcs(prop, "rna_ImagePreview_image_pixels_get_length");
852         RNA_def_property_int_funcs(prop, "rna_ImagePreview_image_pixels_get", "rna_ImagePreview_image_pixels_set", NULL);
853
854         prop = RNA_def_property(srna, "image_pixels_float", PROP_FLOAT, PROP_NONE);
855         RNA_def_property_flag(prop, PROP_DYNAMIC);
856         RNA_def_property_multi_array(prop, 1, NULL);
857         RNA_def_property_ui_text(prop, "Float Image Pixels",
858                                  "Image pixels components, as floats (RGBA concatenated values)");
859         RNA_def_property_dynamic_array_funcs(prop, "rna_ImagePreview_image_pixels_float_get_length");
860         RNA_def_property_float_funcs(prop, "rna_ImagePreview_image_pixels_float_get",
861                                      "rna_ImagePreview_image_pixels_float_set", NULL);
862
863
864         prop = RNA_def_property(srna, "is_icon_custom", PROP_BOOLEAN, PROP_NONE);
865         RNA_def_property_boolean_sdna(prop, NULL, "flag[ICON_SIZE_ICON]", PRV_USER_EDITED);
866         RNA_def_property_boolean_funcs(prop, NULL, "rna_ImagePreview_is_icon_custom_set");
867         RNA_def_property_ui_text(prop, "Custom Icon", "True if this preview icon has been modified by py script,"
868                                  "and is no more auto-generated by Blender");
869
870         prop = RNA_def_int_vector(srna, "icon_size", 2, NULL, 0, 0, "Icon Size",
871                                   "Width and height in pixels", 0, 0);
872         RNA_def_property_subtype(prop, PROP_PIXEL);
873         RNA_def_property_int_funcs(prop, "rna_ImagePreview_icon_size_get", "rna_ImagePreview_icon_size_set", NULL);
874
875         prop = RNA_def_property(srna, "icon_pixels", PROP_INT, PROP_NONE);
876         RNA_def_property_flag(prop, PROP_DYNAMIC);
877         RNA_def_property_multi_array(prop, 1, NULL);
878         RNA_def_property_ui_text(prop, "Icon Pixels", "Icon pixels, as bytes (always RGBA 32bits)");
879         RNA_def_property_dynamic_array_funcs(prop, "rna_ImagePreview_icon_pixels_get_length");
880         RNA_def_property_int_funcs(prop, "rna_ImagePreview_icon_pixels_get", "rna_ImagePreview_icon_pixels_set", NULL);
881
882         prop = RNA_def_property(srna, "icon_pixels_float", PROP_FLOAT, PROP_NONE);
883         RNA_def_property_flag(prop, PROP_DYNAMIC);
884         RNA_def_property_multi_array(prop, 1, NULL);
885         RNA_def_property_ui_text(prop, "Float Icon Pixels", "Icon pixels components, as floats (RGBA concatenated values)");
886         RNA_def_property_dynamic_array_funcs(prop, "rna_ImagePreview_icon_pixels_float_get_length");
887         RNA_def_property_float_funcs(prop, "rna_ImagePreview_icon_pixels_float_get",
888                                      "rna_ImagePreview_icon_pixels_float_set", NULL);
889
890         prop = RNA_def_int(srna, "icon_id", 0, INT_MIN, INT_MAX, "Icon ID",
891                            "Unique integer identifying this preview as an icon (zero means invalid)", INT_MIN, INT_MAX);
892         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
893         RNA_def_property_int_funcs(prop, "rna_ImagePreview_icon_id_get", NULL, NULL);
894
895         func = RNA_def_function(srna, "reload", "rna_ImagePreview_icon_reload");
896         RNA_def_function_ui_description(func, "Reload the preview from its source path");
897 }
898
899 static void rna_def_ID(BlenderRNA *brna)
900 {
901         StructRNA *srna;
902         FunctionRNA *func;
903         PropertyRNA *prop, *parm;
904
905         static EnumPropertyItem update_flag_items[] = {
906                 {OB_RECALC_OB, "OBJECT", 0, "Object", ""},
907                 {OB_RECALC_DATA, "DATA", 0, "Data", ""},
908                 {OB_RECALC_TIME, "TIME", 0, "Time", ""},
909                 {0, NULL, 0, NULL, NULL}
910         };
911
912         srna = RNA_def_struct(brna, "ID", NULL);
913         RNA_def_struct_ui_text(srna, "ID",
914                                "Base type for data-blocks, defining a unique name, linking from other libraries "
915                                "and garbage collection");
916         RNA_def_struct_flag(srna, STRUCT_ID | STRUCT_ID_REFCOUNT);
917         RNA_def_struct_refine_func(srna, "rna_ID_refine");
918         RNA_def_struct_idprops_func(srna, "rna_ID_idprops");
919
920         prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
921         RNA_def_property_ui_text(prop, "Name", "Unique data-block ID name");
922         RNA_def_property_string_funcs(prop, "rna_ID_name_get", "rna_ID_name_length", "rna_ID_name_set");
923         RNA_def_property_string_maxlength(prop, MAX_ID_NAME - 2);
924         RNA_def_property_editable_func(prop, "rna_ID_name_editable");
925         RNA_def_property_update(prop, NC_ID | NA_RENAME, NULL);
926         RNA_def_struct_name_property(srna, prop);
927
928         prop = RNA_def_property(srna, "users", PROP_INT, PROP_UNSIGNED);
929         RNA_def_property_int_sdna(prop, NULL, "us");
930         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
931         RNA_def_property_ui_text(prop, "Users", "Number of times this data-block is referenced");
932
933         prop = RNA_def_property(srna, "use_fake_user", PROP_BOOLEAN, PROP_NONE);
934         RNA_def_property_boolean_sdna(prop, NULL, "flag", LIB_FAKEUSER);
935         RNA_def_property_ui_text(prop, "Fake User", "Save this data-block even if it has no users");
936         RNA_def_property_boolean_funcs(prop, NULL, "rna_ID_fake_user_set");
937
938         prop = RNA_def_property(srna, "tag", PROP_BOOLEAN, PROP_NONE);
939         RNA_def_property_boolean_sdna(prop, NULL, "tag", LIB_TAG_DOIT);
940         RNA_def_property_flag(prop, PROP_LIB_EXCEPTION);
941         RNA_def_property_ui_text(prop, "Tag",
942                                  "Tools can use this to tag data for their own purposes "
943                                  "(initial state is undefined)");
944
945         prop = RNA_def_property(srna, "is_updated", PROP_BOOLEAN, PROP_NONE);
946         RNA_def_property_boolean_sdna(prop, NULL, "tag", LIB_TAG_ID_RECALC);
947         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
948         RNA_def_property_ui_text(prop, "Is Updated", "Datablock is tagged for recalculation");
949
950         prop = RNA_def_property(srna, "is_updated_data", PROP_BOOLEAN, PROP_NONE);
951         RNA_def_property_boolean_sdna(prop, NULL, "tag", LIB_TAG_ID_RECALC_DATA);
952         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
953         RNA_def_property_ui_text(prop, "Is Updated Data", "Datablock data is tagged for recalculation");
954
955         prop = RNA_def_property(srna, "is_library_indirect", PROP_BOOLEAN, PROP_NONE);
956         RNA_def_property_boolean_sdna(prop, NULL, "tag", LIB_TAG_INDIRECT);
957         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
958         RNA_def_property_ui_text(prop, "Is Indirect", "Is this ID block linked indirectly");
959
960         prop = RNA_def_property(srna, "library", PROP_POINTER, PROP_NONE);
961         RNA_def_property_pointer_sdna(prop, NULL, "lib");
962         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
963         RNA_def_property_ui_text(prop, "Library", "Library file the data-block is linked from");
964
965         prop = RNA_def_pointer(srna, "preview", "ImagePreview", "Preview",
966                                "Preview image and icon of this data-block (None if not supported for this type of data)");
967         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
968         RNA_def_property_pointer_funcs(prop, "rna_IDPreview_get", NULL, NULL, NULL);
969
970         /* functions */
971         func = RNA_def_function(srna, "copy", "rna_ID_copy");
972         RNA_def_function_ui_description(func, "Create a copy of this data-block (not supported for all data-blocks)");
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_of_id", "BKE_library_ID_use_ID");
981         RNA_def_function_ui_description(func, "Count the number of times that ID uses/references given one");
982         parm = RNA_def_pointer(func, "id", "ID", "", "ID to count usages");
983         RNA_def_property_flag(parm, PROP_NEVER_NULL);
984         parm = RNA_def_int(func, "count", 0, 0, INT_MAX,
985                            "", "Number of usages/references of given id by current datablock", 0, INT_MAX);
986         RNA_def_function_return(func, parm);
987
988         func = RNA_def_function(srna, "animation_data_create", "rna_ID_animation_data_create");
989         RNA_def_function_flag(func, FUNC_USE_MAIN);
990         RNA_def_function_ui_description(func, "Create animation data to this ID, note that not all ID types support this");
991         parm = RNA_def_pointer(func, "anim_data", "AnimData", "", "New animation data or NULL");
992         RNA_def_function_return(func, parm);
993
994         func = RNA_def_function(srna, "animation_data_clear", "rna_ID_animation_data_free");
995         RNA_def_function_flag(func, FUNC_USE_MAIN);
996         RNA_def_function_ui_description(func, "Clear animation on this this ID");
997
998         func = RNA_def_function(srna, "update_tag", "rna_ID_update_tag");
999         RNA_def_function_flag(func, FUNC_USE_REPORTS);
1000         RNA_def_function_ui_description(func,
1001                                         "Tag the ID to update its display data, "
1002                                         "e.g. when calling :class:`bpy.types.Scene.update`");
1003         RNA_def_enum_flag(func, "refresh", update_flag_items, 0, "", "Type of updates to perform");
1004 }
1005
1006 static void rna_def_library(BlenderRNA *brna)
1007 {
1008         StructRNA *srna;
1009         PropertyRNA *prop;
1010
1011         srna = RNA_def_struct(brna, "Library", "ID");
1012         RNA_def_struct_ui_text(srna, "Library", "External .blend file from which data is linked");
1013         RNA_def_struct_ui_icon(srna, ICON_LIBRARY_DATA_DIRECT);
1014
1015         prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
1016         RNA_def_property_string_sdna(prop, NULL, "name");
1017         RNA_def_property_ui_text(prop, "File Path", "Path to the library .blend file");
1018         RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Library_filepath_set");
1019         
1020         prop = RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
1021         RNA_def_property_struct_type(prop, "Library");
1022         RNA_def_property_ui_text(prop, "Parent", "");
1023
1024         prop = RNA_def_property(srna, "packed_file", PROP_POINTER, PROP_NONE);
1025         RNA_def_property_pointer_sdna(prop, NULL, "packedfile");
1026         RNA_def_property_ui_text(prop, "Packed File", "");
1027 }
1028 void RNA_def_ID(BlenderRNA *brna)
1029 {
1030         StructRNA *srna;
1031
1032         /* built-in unknown type */
1033         srna = RNA_def_struct(brna, "UnknownType", NULL);
1034         RNA_def_struct_ui_text(srna, "Unknown Type", "Stub RNA type used for pointers to unknown or internal data");
1035
1036         /* built-in any type */
1037         srna = RNA_def_struct(brna, "AnyType", NULL);
1038         RNA_def_struct_ui_text(srna, "Any Type", "RNA type used for pointers to any possible data");
1039
1040         rna_def_ID(brna);
1041         rna_def_image_preview(brna);
1042         rna_def_ID_properties(brna);
1043         rna_def_ID_materials(brna);
1044         rna_def_library(brna);
1045 }
1046
1047 #endif