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