1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 /** \file
18  * \ingroup RNA
19  */
20 
21 #include <stdio.h>
22 #include <stdlib.h>
23 
24 #include "DNA_ID.h"
25 #include "DNA_material_types.h"
26 #include "DNA_object_types.h"
27 #include "DNA_vfont_types.h"
28 
29 #include "BLI_utildefines.h"
30 
31 #include "BKE_icons.h"
32 #include "BKE_lib_id.h"
33 #include "BKE_object.h"
34 
35 #include "RNA_access.h"
36 #include "RNA_define.h"
37 #include "RNA_enum_types.h"
38 
39 #include "WM_types.h"
40 
41 #include "rna_internal.h"
42 
43 /* enum of ID-block types
44  * NOTE: need to keep this in line with the other defines for these
45  */
46 const EnumPropertyItem rna_enum_id_type_items[] = {
47     {ID_AC, "ACTION", ICON_ACTION, "Action", ""},
48     {ID_AR, "ARMATURE", ICON_ARMATURE_DATA, "Armature", ""},
49     {ID_BR, "BRUSH", ICON_BRUSH_DATA, "Brush", ""},
50     {ID_CA, "CAMERA", ICON_CAMERA_DATA, "Camera", ""},
51     {ID_CF, "CACHEFILE", ICON_FILE, "Cache File", ""},
52     {ID_CU, "CURVE", ICON_CURVE_DATA, "Curve", ""},
53     {ID_VF, "FONT", ICON_FONT_DATA, "Font", ""},
54     {ID_GD, "GREASEPENCIL", ICON_GREASEPENCIL, "Grease Pencil", ""},
55     {ID_GR, "COLLECTION", ICON_OUTLINER_COLLECTION, "Collection", ""},
56     {ID_IM, "IMAGE", ICON_IMAGE_DATA, "Image", ""},
57     {ID_KE, "KEY", ICON_SHAPEKEY_DATA, "Key", ""},
58     {ID_LA, "LIGHT", ICON_LIGHT_DATA, "Light", ""},
59     {ID_LI, "LIBRARY", ICON_LIBRARY_DATA_DIRECT, "Library", ""},
60     {ID_LS, "LINESTYLE", ICON_LINE_DATA, "Line Style", ""},
61     {ID_LT, "LATTICE", ICON_LATTICE_DATA, "Lattice", ""},
62     {ID_MSK, "MASK", ICON_MOD_MASK, "Mask", ""},
63     {ID_MA, "MATERIAL", ICON_MATERIAL_DATA, "Material", ""},
64     {ID_MB, "META", ICON_META_DATA, "Metaball", ""},
65     {ID_ME, "MESH", ICON_MESH_DATA, "Mesh", ""},
66     {ID_MC, "MOVIECLIP", ICON_TRACKER, "Movie Clip", ""},
67     {ID_NT, "NODETREE", ICON_NODETREE, "Node Tree", ""},
68     {ID_OB, "OBJECT", ICON_OBJECT_DATA, "Object", ""},
69     {ID_PC, "PAINTCURVE", ICON_CURVE_BEZCURVE, "Paint Curve", ""},
70     {ID_PAL, "PALETTE", ICON_COLOR, "Palette", ""},
71     {ID_PA, "PARTICLE", ICON_PARTICLE_DATA, "Particle", ""},
72     {ID_LP, "LIGHT_PROBE", ICON_LIGHTPROBE_CUBEMAP, "Light Probe", ""},
73     {ID_SCE, "SCENE", ICON_SCENE_DATA, "Scene", ""},
74     {ID_SIM, "SIMULATION", ICON_PHYSICS, "Simulation", ""}, /* TODO: Use correct icon. */
75     {ID_SO, "SOUND", ICON_SOUND, "Sound", ""},
76     {ID_SPK, "SPEAKER", ICON_SPEAKER, "Speaker", ""},
77     {ID_TXT, "TEXT", ICON_TEXT, "Text", ""},
78     {ID_TE, "TEXTURE", ICON_TEXTURE_DATA, "Texture", ""},
79     {ID_HA, "HAIR", ICON_HAIR_DATA, "Hair", ""},
80     {ID_PT, "POINTCLOUD", ICON_POINTCLOUD_DATA, "PointCloud", ""},
81     {ID_VO, "VOLUME", ICON_VOLUME_DATA, "Volume", ""},
82     {ID_WM, "WINDOWMANAGER", ICON_WINDOW, "Window Manager", ""},
83     {ID_WO, "WORLD", ICON_WORLD_DATA, "World", ""},
84     {ID_WS, "WORKSPACE", ICON_WORKSPACE, "Workspace", ""},
85     {0, NULL, 0, NULL, NULL},
86 };
87 
88 #ifdef RNA_RUNTIME
89 
90 #  include "DNA_anim_types.h"
91 
92 #  include "BLI_listbase.h"
93 #  include "BLI_math_base.h"
94 
95 #  include "BKE_anim_data.h"
96 #  include "BKE_font.h"
97 #  include "BKE_global.h" /* XXX, remove me */
98 #  include "BKE_idprop.h"
99 #  include "BKE_idtype.h"
100 #  include "BKE_lib_override.h"
101 #  include "BKE_lib_query.h"
102 #  include "BKE_lib_remap.h"
103 #  include "BKE_library.h"
104 #  include "BKE_material.h"
105 
106 #  include "DEG_depsgraph.h"
107 #  include "DEG_depsgraph_build.h"
108 #  include "DEG_depsgraph_query.h"
109 
110 #  include "WM_api.h"
111 
rna_ID_override_library_property_operation_refname_get(PointerRNA * ptr,char * value)112 void rna_ID_override_library_property_operation_refname_get(PointerRNA *ptr, char *value)
113 {
114   IDOverrideLibraryPropertyOperation *opop = ptr->data;
115   strcpy(value, (opop->subitem_reference_name == NULL) ? "" : opop->subitem_reference_name);
116 }
117 
rna_ID_override_library_property_operation_refname_length(PointerRNA * ptr)118 int rna_ID_override_library_property_operation_refname_length(PointerRNA *ptr)
119 {
120   IDOverrideLibraryPropertyOperation *opop = ptr->data;
121   return (opop->subitem_reference_name == NULL) ? 0 : strlen(opop->subitem_reference_name);
122 }
123 
rna_ID_override_library_property_operation_locname_get(PointerRNA * ptr,char * value)124 void rna_ID_override_library_property_operation_locname_get(PointerRNA *ptr, char *value)
125 {
126   IDOverrideLibraryPropertyOperation *opop = ptr->data;
127   strcpy(value, (opop->subitem_local_name == NULL) ? "" : opop->subitem_local_name);
128 }
129 
rna_ID_override_library_property_operation_locname_length(PointerRNA * ptr)130 int rna_ID_override_library_property_operation_locname_length(PointerRNA *ptr)
131 {
132   IDOverrideLibraryPropertyOperation *opop = ptr->data;
133   return (opop->subitem_local_name == NULL) ? 0 : strlen(opop->subitem_local_name);
134 }
135 
136 /* name functions that ignore the first two ID characters */
rna_ID_name_get(PointerRNA * ptr,char * value)137 void rna_ID_name_get(PointerRNA *ptr, char *value)
138 {
139   ID *id = (ID *)ptr->data;
140   BLI_strncpy(value, id->name + 2, sizeof(id->name) - 2);
141 }
142 
rna_ID_name_length(PointerRNA * ptr)143 int rna_ID_name_length(PointerRNA *ptr)
144 {
145   ID *id = (ID *)ptr->data;
146   return strlen(id->name + 2);
147 }
148 
rna_ID_name_set(PointerRNA * ptr,const char * value)149 void rna_ID_name_set(PointerRNA *ptr, const char *value)
150 {
151   ID *id = (ID *)ptr->data;
152   BLI_strncpy_utf8(id->name + 2, value, sizeof(id->name) - 2);
153   BLI_assert(BKE_id_is_in_global_main(id));
154   BLI_libblock_ensure_unique_name(G_MAIN, id->name);
155 
156   if (GS(id->name) == ID_OB) {
157     Object *ob = (Object *)id;
158     if (ob->type == OB_MBALL) {
159       DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
160     }
161   }
162 }
163 
rna_ID_name_editable(PointerRNA * ptr,const char ** UNUSED (r_info))164 static int rna_ID_name_editable(PointerRNA *ptr, const char **UNUSED(r_info))
165 {
166   ID *id = (ID *)ptr->data;
167 
168   if (GS(id->name) == ID_VF) {
169     VFont *vfont = (VFont *)id;
170     if (BKE_vfont_is_builtin(vfont)) {
171       return 0;
172     }
173   }
174   else if (!BKE_id_is_in_global_main(id)) {
175     return 0;
176   }
177 
178   return PROP_EDITABLE;
179 }
180 
rna_ID_name_full_get(PointerRNA * ptr,char * value)181 void rna_ID_name_full_get(PointerRNA *ptr, char *value)
182 {
183   ID *id = (ID *)ptr->data;
184   BKE_id_full_name_get(value, id, 0);
185 }
186 
rna_ID_name_full_length(PointerRNA * ptr)187 int rna_ID_name_full_length(PointerRNA *ptr)
188 {
189   ID *id = (ID *)ptr->data;
190   char name[MAX_ID_FULL_NAME];
191   BKE_id_full_name_get(name, id, 0);
192   return strlen(name);
193 }
194 
rna_ID_is_evaluated_get(PointerRNA * ptr)195 static int rna_ID_is_evaluated_get(PointerRNA *ptr)
196 {
197   ID *id = (ID *)ptr->data;
198 
199   return (DEG_get_original_id(id) != id);
200 }
201 
rna_ID_original_get(PointerRNA * ptr)202 static PointerRNA rna_ID_original_get(PointerRNA *ptr)
203 {
204   ID *id = (ID *)ptr->data;
205 
206   return rna_pointer_inherit_refine(ptr, &RNA_ID, DEG_get_original_id(id));
207 }
208 
RNA_type_to_ID_code(const StructRNA * type)209 short RNA_type_to_ID_code(const StructRNA *type)
210 {
211   const StructRNA *base_type = RNA_struct_base_child_of(type, &RNA_ID);
212   if (UNLIKELY(base_type == NULL)) {
213     return 0;
214   }
215   if (base_type == &RNA_Action) {
216     return ID_AC;
217   }
218   if (base_type == &RNA_Armature) {
219     return ID_AR;
220   }
221   if (base_type == &RNA_Brush) {
222     return ID_BR;
223   }
224   if (base_type == &RNA_CacheFile) {
225     return ID_CF;
226   }
227   if (base_type == &RNA_Camera) {
228     return ID_CA;
229   }
230   if (base_type == &RNA_Curve) {
231     return ID_CU;
232   }
233   if (base_type == &RNA_GreasePencil) {
234     return ID_GD;
235   }
236   if (base_type == &RNA_Collection) {
237     return ID_GR;
238   }
239   if (base_type == &RNA_Image) {
240     return ID_IM;
241   }
242   if (base_type == &RNA_Key) {
243     return ID_KE;
244   }
245   if (base_type == &RNA_Light) {
246     return ID_LA;
247   }
248   if (base_type == &RNA_Library) {
249     return ID_LI;
250   }
251   if (base_type == &RNA_FreestyleLineStyle) {
252     return ID_LS;
253   }
254 #  ifdef WITH_HAIR_NODES
255   if (base_type == &RNA_Hair) {
256     return ID_HA;
257   }
258 #  endif
259   if (base_type == &RNA_Lattice) {
260     return ID_LT;
261   }
262   if (base_type == &RNA_Material) {
263     return ID_MA;
264   }
265   if (base_type == &RNA_MetaBall) {
266     return ID_MB;
267   }
268   if (base_type == &RNA_MovieClip) {
269     return ID_MC;
270   }
271   if (base_type == &RNA_Mesh) {
272     return ID_ME;
273   }
274   if (base_type == &RNA_Mask) {
275     return ID_MSK;
276   }
277   if (base_type == &RNA_NodeTree) {
278     return ID_NT;
279   }
280   if (base_type == &RNA_Object) {
281     return ID_OB;
282   }
283   if (base_type == &RNA_ParticleSettings) {
284     return ID_PA;
285   }
286   if (base_type == &RNA_Palette) {
287     return ID_PAL;
288   }
289   if (base_type == &RNA_PaintCurve) {
290     return ID_PC;
291   }
292 #  ifdef WITH_POINT_CLOUD
293   if (base_type == &RNA_PointCloud) {
294     return ID_PT;
295   }
296 #  endif
297   if (base_type == &RNA_LightProbe) {
298     return ID_LP;
299   }
300   if (base_type == &RNA_Scene) {
301     return ID_SCE;
302   }
303   if (base_type == &RNA_Screen) {
304     return ID_SCR;
305   }
306 #  ifdef WITH_GEOMETRY_NODES
307   if (base_type == &RNA_Simulation) {
308     return ID_SIM;
309   }
310 #  endif
311   if (base_type == &RNA_Sound) {
312     return ID_SO;
313   }
314   if (base_type == &RNA_Speaker) {
315     return ID_SPK;
316   }
317   if (base_type == &RNA_Texture) {
318     return ID_TE;
319   }
320   if (base_type == &RNA_Text) {
321     return ID_TXT;
322   }
323   if (base_type == &RNA_VectorFont) {
324     return ID_VF;
325   }
326   if (base_type == &RNA_Volume) {
327     return ID_VO;
328   }
329   if (base_type == &RNA_WorkSpace) {
330     return ID_WS;
331   }
332   if (base_type == &RNA_World) {
333     return ID_WO;
334   }
335   if (base_type == &RNA_WindowManager) {
336     return ID_WM;
337   }
338 
339   return 0;
340 }
341 
ID_code_to_RNA_type(short idcode)342 StructRNA *ID_code_to_RNA_type(short idcode)
343 {
344   /* Note, this switch doesn't use a 'default',
345    * so adding new ID's causes a warning. */
346   switch ((ID_Type)idcode) {
347     case ID_AC:
348       return &RNA_Action;
349     case ID_AR:
350       return &RNA_Armature;
351     case ID_BR:
352       return &RNA_Brush;
353     case ID_CA:
354       return &RNA_Camera;
355     case ID_CF:
356       return &RNA_CacheFile;
357     case ID_CU:
358       return &RNA_Curve;
359     case ID_GD:
360       return &RNA_GreasePencil;
361     case ID_GR:
362       return &RNA_Collection;
363     case ID_HA:
364 #  ifdef WITH_HAIR_NODES
365       return &RNA_Hair;
366 #  else
367       return &RNA_ID;
368 #  endif
369     case ID_IM:
370       return &RNA_Image;
371     case ID_KE:
372       return &RNA_Key;
373     case ID_LA:
374       return &RNA_Light;
375     case ID_LI:
376       return &RNA_Library;
377     case ID_LS:
378       return &RNA_FreestyleLineStyle;
379     case ID_LT:
380       return &RNA_Lattice;
381     case ID_MA:
382       return &RNA_Material;
383     case ID_MB:
384       return &RNA_MetaBall;
385     case ID_MC:
386       return &RNA_MovieClip;
387     case ID_ME:
388       return &RNA_Mesh;
389     case ID_MSK:
390       return &RNA_Mask;
391     case ID_NT:
392       return &RNA_NodeTree;
393     case ID_OB:
394       return &RNA_Object;
395     case ID_PA:
396       return &RNA_ParticleSettings;
397     case ID_PAL:
398       return &RNA_Palette;
399     case ID_PC:
400       return &RNA_PaintCurve;
401     case ID_PT:
402 #  ifdef WITH_POINT_CLOUD
403       return &RNA_PointCloud;
404 #  else
405       return &RNA_ID;
406 #  endif
407     case ID_LP:
408       return &RNA_LightProbe;
409     case ID_SCE:
410       return &RNA_Scene;
411     case ID_SCR:
412       return &RNA_Screen;
413     case ID_SIM:
414 #  ifdef WITH_GEOMETRY_NODES
415       return &RNA_Simulation;
416 #  else
417       return &RNA_ID;
418 #  endif
419     case ID_SO:
420       return &RNA_Sound;
421     case ID_SPK:
422       return &RNA_Speaker;
423     case ID_TE:
424       return &RNA_Texture;
425     case ID_TXT:
426       return &RNA_Text;
427     case ID_VF:
428       return &RNA_VectorFont;
429     case ID_VO:
430       return &RNA_Volume;
431     case ID_WM:
432       return &RNA_WindowManager;
433     case ID_WO:
434       return &RNA_World;
435     case ID_WS:
436       return &RNA_WorkSpace;
437 
438     /* deprecated */
439     case ID_IP:
440       break;
441   }
442 
443   return &RNA_ID;
444 }
445 
rna_ID_refine(PointerRNA * ptr)446 StructRNA *rna_ID_refine(PointerRNA *ptr)
447 {
448   ID *id = (ID *)ptr->data;
449 
450   return ID_code_to_RNA_type(GS(id->name));
451 }
452 
rna_ID_idprops(PointerRNA * ptr,bool create)453 IDProperty *rna_ID_idprops(PointerRNA *ptr, bool create)
454 {
455   return IDP_GetProperties(ptr->data, create);
456 }
457 
rna_ID_fake_user_set(PointerRNA * ptr,bool value)458 void rna_ID_fake_user_set(PointerRNA *ptr, bool value)
459 {
460   ID *id = (ID *)ptr->data;
461 
462   if (value) {
463     id_fake_user_set(id);
464   }
465   else {
466     id_fake_user_clear(id);
467   }
468 }
469 
rna_PropertyGroup_idprops(PointerRNA * ptr,bool UNUSED (create))470 IDProperty *rna_PropertyGroup_idprops(PointerRNA *ptr, bool UNUSED(create))
471 {
472   return ptr->data;
473 }
474 
rna_PropertyGroup_unregister(Main * UNUSED (bmain),StructRNA * type)475 void rna_PropertyGroup_unregister(Main *UNUSED(bmain), StructRNA *type)
476 {
477   RNA_struct_free(&BLENDER_RNA, type);
478 }
479 
rna_PropertyGroup_register(Main * UNUSED (bmain),ReportList * reports,void * data,const char * identifier,StructValidateFunc validate,StructCallbackFunc UNUSED (call),StructFreeFunc UNUSED (free))480 StructRNA *rna_PropertyGroup_register(Main *UNUSED(bmain),
481                                       ReportList *reports,
482                                       void *data,
483                                       const char *identifier,
484                                       StructValidateFunc validate,
485                                       StructCallbackFunc UNUSED(call),
486                                       StructFreeFunc UNUSED(free))
487 {
488   PointerRNA dummyptr;
489 
490   /* create dummy pointer */
491   RNA_pointer_create(NULL, &RNA_PropertyGroup, NULL, &dummyptr);
492 
493   /* validate the python class */
494   if (validate(&dummyptr, data, NULL) != 0) {
495     return NULL;
496   }
497 
498   /* note: it looks like there is no length limit on the srna id since its
499    * just a char pointer, but take care here, also be careful that python
500    * owns the string pointer which it could potentially free while blender
501    * is running. */
502   if (BLI_strnlen(identifier, MAX_IDPROP_NAME) == MAX_IDPROP_NAME) {
503     BKE_reportf(reports,
504                 RPT_ERROR,
505                 "Registering id property class: '%s' is too long, maximum length is %d",
506                 identifier,
507                 MAX_IDPROP_NAME);
508     return NULL;
509   }
510 
511   return RNA_def_struct_ptr(&BLENDER_RNA, identifier, &RNA_PropertyGroup); /* XXX */
512 }
513 
rna_PropertyGroup_refine(PointerRNA * ptr)514 StructRNA *rna_PropertyGroup_refine(PointerRNA *ptr)
515 {
516   return ptr->type;
517 }
518 
rna_ID_evaluated_get(ID * id,struct Depsgraph * depsgraph)519 static ID *rna_ID_evaluated_get(ID *id, struct Depsgraph *depsgraph)
520 {
521   return DEG_get_evaluated_id(depsgraph, id);
522 }
523 
rna_ID_copy(ID * id,Main * bmain)524 static ID *rna_ID_copy(ID *id, Main *bmain)
525 {
526   ID *newid = BKE_id_copy(bmain, id);
527 
528   if (newid != NULL) {
529     id_us_min(newid);
530   }
531   return newid;
532 }
533 
rna_ID_override_create(ID * id,Main * bmain,bool remap_local_usages)534 static ID *rna_ID_override_create(ID *id, Main *bmain, bool remap_local_usages)
535 {
536   if (!ID_IS_OVERRIDABLE_LIBRARY(id)) {
537     return NULL;
538   }
539 
540   if (remap_local_usages) {
541     BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, true);
542   }
543 
544   ID *local_id = BKE_lib_override_library_create_from_id(bmain, id, remap_local_usages);
545 
546   if (remap_local_usages) {
547     BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false);
548   }
549   return local_id;
550 }
551 
rna_ID_update_tag(ID * id,Main * bmain,ReportList * reports,int flag)552 static void rna_ID_update_tag(ID *id, Main *bmain, ReportList *reports, int flag)
553 {
554   /* XXX, new function for this! */
555 #  if 0
556   if (ob->type == OB_FONT) {
557     Curve *cu = ob->data;
558     freedisplist(&cu->disp);
559     BKE_vfont_to_curve(bmain, sce, ob, FO_EDIT, NULL);
560   }
561 #  endif
562 
563   if (flag == 0) {
564     /* pass */
565   }
566   else {
567     int allow_flag = 0;
568 
569     /* ensure flag us correct for the type */
570     switch (GS(id->name)) {
571       case ID_OB:
572         /* TODO(sergey): This is kind of difficult to predict since different
573          * object types supports different flags. Maybe does not worth checking
574          * for this at all. Or maybe let dependency graph to return whether
575          * the tag was valid or not. */
576         allow_flag = ID_RECALC_ALL;
577         break;
578         /* Could add particle updates later */
579 #  if 0
580       case ID_PA:
581         allow_flag = OB_RECALC_ALL | PSYS_RECALC;
582         break;
583 #  endif
584       case ID_AC:
585         allow_flag = ID_RECALC_ANIMATION;
586         break;
587       default:
588         if (id_can_have_animdata(id)) {
589           allow_flag = ID_RECALC_ANIMATION;
590         }
591     }
592 
593     if (flag & ~allow_flag) {
594       StructRNA *srna = ID_code_to_RNA_type(GS(id->name));
595       BKE_reportf(reports,
596                   RPT_ERROR,
597                   "%s is not compatible with %s 'refresh' options",
598                   RNA_struct_identifier(srna),
599                   allow_flag ? "the specified" : "any");
600       return;
601     }
602   }
603 
604   DEG_id_tag_update_ex(bmain, id, flag);
605 }
606 
rna_ID_user_clear(ID * id)607 static void rna_ID_user_clear(ID *id)
608 {
609   id_fake_user_clear(id);
610   id->us = 0; /* don't save */
611 }
612 
rna_ID_user_remap(ID * id,Main * bmain,ID * new_id)613 static void rna_ID_user_remap(ID *id, Main *bmain, ID *new_id)
614 {
615   if ((GS(id->name) == GS(new_id->name)) && (id != new_id)) {
616     /* For now, do not allow remapping data in linked data from here... */
617     BKE_libblock_remap(
618         bmain, id, new_id, ID_REMAP_SKIP_INDIRECT_USAGE | ID_REMAP_SKIP_NEVER_NULL_USAGE);
619   }
620 }
621 
rna_ID_make_local(struct ID * self,Main * bmain,bool clear_proxy)622 static struct ID *rna_ID_make_local(struct ID *self, Main *bmain, bool clear_proxy)
623 {
624   BKE_lib_id_make_local(
625       bmain, self, false, clear_proxy ? 0 : LIB_ID_MAKELOCAL_OBJECT_NO_PROXY_CLEARING);
626 
627   ID *ret_id = self->newid ? self->newid : self;
628   BKE_id_clear_newpoin(self);
629   return ret_id;
630 }
631 
rna_ID_animation_data_create(ID * id,Main * bmain)632 static AnimData *rna_ID_animation_data_create(ID *id, Main *bmain)
633 {
634   AnimData *adt = BKE_animdata_add_id(id);
635   DEG_relations_tag_update(bmain);
636   return adt;
637 }
638 
rna_ID_animation_data_free(ID * id,Main * bmain)639 static void rna_ID_animation_data_free(ID *id, Main *bmain)
640 {
641   BKE_animdata_free(id, true);
642   DEG_relations_tag_update(bmain);
643 }
644 
645 #  ifdef WITH_PYTHON
rna_ID_instance(PointerRNA * ptr)646 void **rna_ID_instance(PointerRNA *ptr)
647 {
648   ID *id = (ID *)ptr->data;
649   return &id->py_instance;
650 }
651 #  endif
652 
rna_IDPArray_begin(CollectionPropertyIterator * iter,PointerRNA * ptr)653 static void rna_IDPArray_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
654 {
655   IDProperty *prop = (IDProperty *)ptr->data;
656   rna_iterator_array_begin(iter, IDP_IDPArray(prop), sizeof(IDProperty), prop->len, 0, NULL);
657 }
658 
rna_IDPArray_length(PointerRNA * ptr)659 static int rna_IDPArray_length(PointerRNA *ptr)
660 {
661   IDProperty *prop = (IDProperty *)ptr->data;
662   return prop->len;
663 }
664 
rna_IDMaterials_assign_int(PointerRNA * ptr,int key,const PointerRNA * assign_ptr)665 int rna_IDMaterials_assign_int(PointerRNA *ptr, int key, const PointerRNA *assign_ptr)
666 {
667   ID *id = ptr->owner_id;
668   short *totcol = BKE_id_material_len_p(id);
669   Material *mat_id = (Material *)assign_ptr->owner_id;
670   if (totcol && (key >= 0 && key < *totcol)) {
671     BLI_assert(BKE_id_is_in_global_main(id));
672     BLI_assert(BKE_id_is_in_global_main(&mat_id->id));
673     BKE_id_material_assign(G_MAIN, id, mat_id, key + 1);
674     return 1;
675   }
676   else {
677     return 0;
678   }
679 }
680 
rna_IDMaterials_append_id(ID * id,Main * bmain,Material * ma)681 static void rna_IDMaterials_append_id(ID *id, Main *bmain, Material *ma)
682 {
683   BKE_id_material_append(bmain, id, ma);
684 
685   WM_main_add_notifier(NC_OBJECT | ND_DRAW, id);
686   WM_main_add_notifier(NC_OBJECT | ND_OB_SHADING, id);
687 }
688 
rna_IDMaterials_pop_id(ID * id,Main * bmain,ReportList * reports,int index_i)689 static Material *rna_IDMaterials_pop_id(ID *id, Main *bmain, ReportList *reports, int index_i)
690 {
691   Material *ma;
692   short *totcol = BKE_id_material_len_p(id);
693   const short totcol_orig = *totcol;
694   if (index_i < 0) {
695     index_i += (*totcol);
696   }
697 
698   if ((index_i < 0) || (index_i >= (*totcol))) {
699     BKE_report(reports, RPT_ERROR, "Index out of range");
700     return NULL;
701   }
702 
703   ma = BKE_id_material_pop(bmain, id, index_i);
704 
705   if (*totcol == totcol_orig) {
706     BKE_report(reports, RPT_ERROR, "No material to removed");
707     return NULL;
708   }
709 
710   DEG_id_tag_update(id, ID_RECALC_GEOMETRY);
711   WM_main_add_notifier(NC_OBJECT | ND_DRAW, id);
712   WM_main_add_notifier(NC_OBJECT | ND_OB_SHADING, id);
713 
714   return ma;
715 }
716 
rna_IDMaterials_clear_id(ID * id,Main * bmain)717 static void rna_IDMaterials_clear_id(ID *id, Main *bmain)
718 {
719   BKE_id_material_clear(bmain, id);
720 
721   DEG_id_tag_update(id, ID_RECALC_GEOMETRY);
722   WM_main_add_notifier(NC_OBJECT | ND_DRAW, id);
723   WM_main_add_notifier(NC_OBJECT | ND_OB_SHADING, id);
724 }
725 
rna_Library_filepath_set(PointerRNA * ptr,const char * value)726 static void rna_Library_filepath_set(PointerRNA *ptr, const char *value)
727 {
728   Library *lib = (Library *)ptr->data;
729   BLI_assert(BKE_id_is_in_global_main(&lib->id));
730   BKE_library_filepath_set(G_MAIN, lib, value);
731 }
732 
733 /* ***** ImagePreview ***** */
734 
rna_ImagePreview_is_custom_set(PointerRNA * ptr,int value,enum eIconSizes size)735 static void rna_ImagePreview_is_custom_set(PointerRNA *ptr, int value, enum eIconSizes size)
736 {
737   ID *id = ptr->owner_id;
738   PreviewImage *prv_img = (PreviewImage *)ptr->data;
739 
740   if (id != NULL) {
741     BLI_assert(prv_img == BKE_previewimg_id_ensure(id));
742   }
743 
744   if ((value && (prv_img->flag[size] & PRV_USER_EDITED)) ||
745       (!value && !(prv_img->flag[size] & PRV_USER_EDITED))) {
746     return;
747   }
748 
749   if (value) {
750     prv_img->flag[size] |= PRV_USER_EDITED;
751   }
752   else {
753     prv_img->flag[size] &= ~PRV_USER_EDITED;
754   }
755 
756   prv_img->flag[size] |= PRV_CHANGED;
757 
758   BKE_previewimg_clear_single(prv_img, size);
759 }
760 
rna_ImagePreview_size_get(PointerRNA * ptr,int * values,enum eIconSizes size)761 static void rna_ImagePreview_size_get(PointerRNA *ptr, int *values, enum eIconSizes size)
762 {
763   ID *id = ptr->owner_id;
764   PreviewImage *prv_img = (PreviewImage *)ptr->data;
765 
766   if (id != NULL) {
767     BLI_assert(prv_img == BKE_previewimg_id_ensure(id));
768   }
769 
770   BKE_previewimg_ensure(prv_img, size);
771 
772   values[0] = prv_img->w[size];
773   values[1] = prv_img->h[size];
774 }
775 
rna_ImagePreview_size_set(PointerRNA * ptr,const int * values,enum eIconSizes size)776 static void rna_ImagePreview_size_set(PointerRNA *ptr, const int *values, enum eIconSizes size)
777 {
778   ID *id = ptr->owner_id;
779   PreviewImage *prv_img = (PreviewImage *)ptr->data;
780 
781   if (id != NULL) {
782     BLI_assert(prv_img == BKE_previewimg_id_ensure(id));
783   }
784 
785   BKE_previewimg_clear_single(prv_img, size);
786 
787   if (values[0] && values[1]) {
788     prv_img->rect[size] = MEM_callocN(values[0] * values[1] * sizeof(unsigned int), "prv_rect");
789 
790     prv_img->w[size] = values[0];
791     prv_img->h[size] = values[1];
792   }
793 
794   prv_img->flag[size] |= (PRV_CHANGED | PRV_USER_EDITED);
795 }
796 
rna_ImagePreview_pixels_get_length(PointerRNA * ptr,int length[RNA_MAX_ARRAY_DIMENSION],enum eIconSizes size)797 static int rna_ImagePreview_pixels_get_length(PointerRNA *ptr,
798                                               int length[RNA_MAX_ARRAY_DIMENSION],
799                                               enum eIconSizes size)
800 {
801   ID *id = ptr->owner_id;
802   PreviewImage *prv_img = (PreviewImage *)ptr->data;
803 
804   if (id != NULL) {
805     BLI_assert(prv_img == BKE_previewimg_id_ensure(id));
806   }
807 
808   BKE_previewimg_ensure(prv_img, size);
809 
810   length[0] = prv_img->w[size] * prv_img->h[size];
811 
812   return length[0];
813 }
814 
rna_ImagePreview_pixels_get(PointerRNA * ptr,int * values,enum eIconSizes size)815 static void rna_ImagePreview_pixels_get(PointerRNA *ptr, int *values, enum eIconSizes size)
816 {
817   ID *id = ptr->owner_id;
818   PreviewImage *prv_img = (PreviewImage *)ptr->data;
819 
820   if (id != NULL) {
821     BLI_assert(prv_img == BKE_previewimg_id_ensure(id));
822   }
823 
824   BKE_previewimg_ensure(prv_img, size);
825 
826   memcpy(values, prv_img->rect[size], prv_img->w[size] * prv_img->h[size] * sizeof(unsigned int));
827 }
828 
rna_ImagePreview_pixels_set(PointerRNA * ptr,const int * values,enum eIconSizes size)829 static void rna_ImagePreview_pixels_set(PointerRNA *ptr, const int *values, enum eIconSizes size)
830 {
831   ID *id = ptr->owner_id;
832   PreviewImage *prv_img = (PreviewImage *)ptr->data;
833 
834   if (id != NULL) {
835     BLI_assert(prv_img == BKE_previewimg_id_ensure(id));
836   }
837 
838   memcpy(prv_img->rect[size], values, prv_img->w[size] * prv_img->h[size] * sizeof(unsigned int));
839   prv_img->flag[size] |= PRV_USER_EDITED;
840 }
841 
rna_ImagePreview_pixels_float_get_length(PointerRNA * ptr,int length[RNA_MAX_ARRAY_DIMENSION],enum eIconSizes size)842 static int rna_ImagePreview_pixels_float_get_length(PointerRNA *ptr,
843                                                     int length[RNA_MAX_ARRAY_DIMENSION],
844                                                     enum eIconSizes size)
845 {
846   ID *id = ptr->owner_id;
847   PreviewImage *prv_img = (PreviewImage *)ptr->data;
848 
849   BLI_assert(sizeof(unsigned int) == 4);
850 
851   if (id != NULL) {
852     BLI_assert(prv_img == BKE_previewimg_id_ensure(id));
853   }
854 
855   BKE_previewimg_ensure(prv_img, size);
856 
857   length[0] = prv_img->w[size] * prv_img->h[size] * 4;
858 
859   return length[0];
860 }
861 
rna_ImagePreview_pixels_float_get(PointerRNA * ptr,float * values,enum eIconSizes size)862 static void rna_ImagePreview_pixels_float_get(PointerRNA *ptr, float *values, enum eIconSizes size)
863 {
864   ID *id = ptr->owner_id;
865   PreviewImage *prv_img = (PreviewImage *)ptr->data;
866 
867   unsigned char *data = (unsigned char *)prv_img->rect[size];
868   const size_t len = prv_img->w[size] * prv_img->h[size] * 4;
869   size_t i;
870 
871   BLI_assert(sizeof(unsigned int) == 4);
872 
873   if (id != NULL) {
874     BLI_assert(prv_img == BKE_previewimg_id_ensure(id));
875   }
876 
877   BKE_previewimg_ensure(prv_img, size);
878 
879   for (i = 0; i < len; i++) {
880     values[i] = data[i] * (1.0f / 255.0f);
881   }
882 }
883 
rna_ImagePreview_pixels_float_set(PointerRNA * ptr,const float * values,enum eIconSizes size)884 static void rna_ImagePreview_pixels_float_set(PointerRNA *ptr,
885                                               const float *values,
886                                               enum eIconSizes size)
887 {
888   ID *id = ptr->owner_id;
889   PreviewImage *prv_img = (PreviewImage *)ptr->data;
890 
891   unsigned char *data = (unsigned char *)prv_img->rect[size];
892   const size_t len = prv_img->w[size] * prv_img->h[size] * 4;
893   size_t i;
894 
895   BLI_assert(sizeof(unsigned int) == 4);
896 
897   if (id != NULL) {
898     BLI_assert(prv_img == BKE_previewimg_id_ensure(id));
899   }
900 
901   for (i = 0; i < len; i++) {
902     data[i] = unit_float_to_uchar_clamp(values[i]);
903   }
904   prv_img->flag[size] |= PRV_USER_EDITED;
905 }
906 
rna_ImagePreview_is_image_custom_set(PointerRNA * ptr,bool value)907 static void rna_ImagePreview_is_image_custom_set(PointerRNA *ptr, bool value)
908 {
909   rna_ImagePreview_is_custom_set(ptr, value, ICON_SIZE_PREVIEW);
910 }
911 
rna_ImagePreview_image_size_get(PointerRNA * ptr,int * values)912 static void rna_ImagePreview_image_size_get(PointerRNA *ptr, int *values)
913 {
914   rna_ImagePreview_size_get(ptr, values, ICON_SIZE_PREVIEW);
915 }
916 
rna_ImagePreview_image_size_set(PointerRNA * ptr,const int * values)917 static void rna_ImagePreview_image_size_set(PointerRNA *ptr, const int *values)
918 {
919   rna_ImagePreview_size_set(ptr, values, ICON_SIZE_PREVIEW);
920 }
921 
rna_ImagePreview_image_pixels_get_length(PointerRNA * ptr,int length[RNA_MAX_ARRAY_DIMENSION])922 static int rna_ImagePreview_image_pixels_get_length(PointerRNA *ptr,
923                                                     int length[RNA_MAX_ARRAY_DIMENSION])
924 {
925   return rna_ImagePreview_pixels_get_length(ptr, length, ICON_SIZE_PREVIEW);
926 }
927 
rna_ImagePreview_image_pixels_get(PointerRNA * ptr,int * values)928 static void rna_ImagePreview_image_pixels_get(PointerRNA *ptr, int *values)
929 {
930   rna_ImagePreview_pixels_get(ptr, values, ICON_SIZE_PREVIEW);
931 }
932 
rna_ImagePreview_image_pixels_set(PointerRNA * ptr,const int * values)933 static void rna_ImagePreview_image_pixels_set(PointerRNA *ptr, const int *values)
934 {
935   rna_ImagePreview_pixels_set(ptr, values, ICON_SIZE_PREVIEW);
936 }
937 
rna_ImagePreview_image_pixels_float_get_length(PointerRNA * ptr,int length[RNA_MAX_ARRAY_DIMENSION])938 static int rna_ImagePreview_image_pixels_float_get_length(PointerRNA *ptr,
939                                                           int length[RNA_MAX_ARRAY_DIMENSION])
940 {
941   return rna_ImagePreview_pixels_float_get_length(ptr, length, ICON_SIZE_PREVIEW);
942 }
943 
rna_ImagePreview_image_pixels_float_get(PointerRNA * ptr,float * values)944 static void rna_ImagePreview_image_pixels_float_get(PointerRNA *ptr, float *values)
945 {
946   rna_ImagePreview_pixels_float_get(ptr, values, ICON_SIZE_PREVIEW);
947 }
948 
rna_ImagePreview_image_pixels_float_set(PointerRNA * ptr,const float * values)949 static void rna_ImagePreview_image_pixels_float_set(PointerRNA *ptr, const float *values)
950 {
951   rna_ImagePreview_pixels_float_set(ptr, values, ICON_SIZE_PREVIEW);
952 }
953 
rna_ImagePreview_is_icon_custom_set(PointerRNA * ptr,bool value)954 static void rna_ImagePreview_is_icon_custom_set(PointerRNA *ptr, bool value)
955 {
956   rna_ImagePreview_is_custom_set(ptr, value, ICON_SIZE_ICON);
957 }
958 
rna_ImagePreview_icon_size_get(PointerRNA * ptr,int * values)959 static void rna_ImagePreview_icon_size_get(PointerRNA *ptr, int *values)
960 {
961   rna_ImagePreview_size_get(ptr, values, ICON_SIZE_ICON);
962 }
963 
rna_ImagePreview_icon_size_set(PointerRNA * ptr,const int * values)964 static void rna_ImagePreview_icon_size_set(PointerRNA *ptr, const int *values)
965 {
966   rna_ImagePreview_size_set(ptr, values, ICON_SIZE_ICON);
967 }
968 
rna_ImagePreview_icon_pixels_get_length(PointerRNA * ptr,int length[RNA_MAX_ARRAY_DIMENSION])969 static int rna_ImagePreview_icon_pixels_get_length(PointerRNA *ptr,
970                                                    int length[RNA_MAX_ARRAY_DIMENSION])
971 {
972   return rna_ImagePreview_pixels_get_length(ptr, length, ICON_SIZE_ICON);
973 }
974 
rna_ImagePreview_icon_pixels_get(PointerRNA * ptr,int * values)975 static void rna_ImagePreview_icon_pixels_get(PointerRNA *ptr, int *values)
976 {
977   rna_ImagePreview_pixels_get(ptr, values, ICON_SIZE_ICON);
978 }
979 
rna_ImagePreview_icon_pixels_set(PointerRNA * ptr,const int * values)980 static void rna_ImagePreview_icon_pixels_set(PointerRNA *ptr, const int *values)
981 {
982   rna_ImagePreview_pixels_set(ptr, values, ICON_SIZE_ICON);
983 }
984 
rna_ImagePreview_icon_pixels_float_get_length(PointerRNA * ptr,int length[RNA_MAX_ARRAY_DIMENSION])985 static int rna_ImagePreview_icon_pixels_float_get_length(PointerRNA *ptr,
986                                                          int length[RNA_MAX_ARRAY_DIMENSION])
987 {
988   return rna_ImagePreview_pixels_float_get_length(ptr, length, ICON_SIZE_ICON);
989 }
990 
rna_ImagePreview_icon_pixels_float_get(PointerRNA * ptr,float * values)991 static void rna_ImagePreview_icon_pixels_float_get(PointerRNA *ptr, float *values)
992 {
993   rna_ImagePreview_pixels_float_get(ptr, values, ICON_SIZE_ICON);
994 }
995 
rna_ImagePreview_icon_pixels_float_set(PointerRNA * ptr,const float * values)996 static void rna_ImagePreview_icon_pixels_float_set(PointerRNA *ptr, const float *values)
997 {
998   rna_ImagePreview_pixels_float_set(ptr, values, ICON_SIZE_ICON);
999 }
1000 
rna_ImagePreview_icon_id_get(PointerRNA * ptr)1001 static int rna_ImagePreview_icon_id_get(PointerRNA *ptr)
1002 {
1003   /* Using a callback here allows us to only generate icon matching
1004    * that preview when icon_id is requested. */
1005   return BKE_icon_preview_ensure(ptr->owner_id, (PreviewImage *)(ptr->data));
1006 }
rna_ImagePreview_icon_reload(PreviewImage * prv)1007 static void rna_ImagePreview_icon_reload(PreviewImage *prv)
1008 {
1009   /* will lazy load on next use, but only in case icon is not user-modified! */
1010   if (!(prv->flag[ICON_SIZE_ICON] & PRV_USER_EDITED) &&
1011       !(prv->flag[ICON_SIZE_PREVIEW] & PRV_USER_EDITED)) {
1012     BKE_previewimg_clear(prv);
1013   }
1014 }
1015 
rna_IDPreview_get(PointerRNA * ptr)1016 static PointerRNA rna_IDPreview_get(PointerRNA *ptr)
1017 {
1018   ID *id = (ID *)ptr->data;
1019   PreviewImage *prv_img = BKE_previewimg_id_ensure(id);
1020 
1021   return rna_pointer_inherit_refine(ptr, &RNA_ImagePreview, prv_img);
1022 }
1023 
rna_IDPropertyWrapPtr_idprops(PointerRNA * ptr,bool UNUSED (create))1024 static IDProperty *rna_IDPropertyWrapPtr_idprops(PointerRNA *ptr, bool UNUSED(create))
1025 {
1026   if (ptr == NULL) {
1027     return NULL;
1028   }
1029   return ptr->data;
1030 }
1031 
rna_Library_version_get(PointerRNA * ptr,int * value)1032 static void rna_Library_version_get(PointerRNA *ptr, int *value)
1033 {
1034   Library *lib = (Library *)ptr->data;
1035   value[0] = lib->versionfile / 100;
1036   value[1] = lib->versionfile % 100;
1037   value[2] = lib->subversionfile;
1038 }
1039 
1040 #else
1041 
rna_def_ID_properties(BlenderRNA * brna)1042 static void rna_def_ID_properties(BlenderRNA *brna)
1043 {
1044   StructRNA *srna;
1045   PropertyRNA *prop;
1046 
1047   /* this is struct is used for holding the virtual
1048    * PropertyRNA's for ID properties */
1049   srna = RNA_def_struct(brna, "PropertyGroupItem", NULL);
1050   RNA_def_struct_sdna(srna, "IDProperty");
1051   RNA_def_struct_ui_text(
1052       srna, "ID Property", "Property that stores arbitrary, user defined properties");
1053 
1054   /* IDP_STRING */
1055   prop = RNA_def_property(srna, "string", PROP_STRING, PROP_NONE);
1056   RNA_def_property_flag(prop, PROP_IDPROPERTY);
1057 
1058   /* IDP_INT */
1059   prop = RNA_def_property(srna, "int", PROP_INT, PROP_NONE);
1060   RNA_def_property_flag(prop, PROP_IDPROPERTY);
1061 
1062   prop = RNA_def_property(srna, "int_array", PROP_INT, PROP_NONE);
1063   RNA_def_property_flag(prop, PROP_IDPROPERTY);
1064   RNA_def_property_array(prop, 1);
1065 
1066   /* IDP_FLOAT */
1067   prop = RNA_def_property(srna, "float", PROP_FLOAT, PROP_NONE);
1068   RNA_def_property_flag(prop, PROP_IDPROPERTY);
1069 
1070   prop = RNA_def_property(srna, "float_array", PROP_FLOAT, PROP_NONE);
1071   RNA_def_property_flag(prop, PROP_IDPROPERTY);
1072   RNA_def_property_array(prop, 1);
1073 
1074   /* IDP_DOUBLE */
1075   prop = RNA_def_property(srna, "double", PROP_FLOAT, PROP_NONE);
1076   RNA_def_property_flag(prop, PROP_IDPROPERTY);
1077 
1078   prop = RNA_def_property(srna, "double_array", PROP_FLOAT, PROP_NONE);
1079   RNA_def_property_flag(prop, PROP_IDPROPERTY);
1080   RNA_def_property_array(prop, 1);
1081 
1082   /* IDP_GROUP */
1083   prop = RNA_def_property(srna, "group", PROP_POINTER, PROP_NONE);
1084   RNA_def_property_flag(prop, PROP_IDPROPERTY);
1085   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1086   RNA_def_property_struct_type(prop, "PropertyGroup");
1087 
1088   prop = RNA_def_property(srna, "collection", PROP_COLLECTION, PROP_NONE);
1089   RNA_def_property_flag(prop, PROP_IDPROPERTY);
1090   RNA_def_property_struct_type(prop, "PropertyGroup");
1091 
1092   prop = RNA_def_property(srna, "idp_array", PROP_COLLECTION, PROP_NONE);
1093   RNA_def_property_struct_type(prop, "PropertyGroup");
1094   RNA_def_property_collection_funcs(prop,
1095                                     "rna_IDPArray_begin",
1096                                     "rna_iterator_array_next",
1097                                     "rna_iterator_array_end",
1098                                     "rna_iterator_array_get",
1099                                     "rna_IDPArray_length",
1100                                     NULL,
1101                                     NULL,
1102                                     NULL);
1103   RNA_def_property_flag(prop, PROP_IDPROPERTY);
1104 
1105   /* never tested, maybe its useful to have this? */
1106 #  if 0
1107   prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
1108   RNA_def_property_flag(prop, PROP_IDPROPERTY);
1109   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1110   RNA_def_property_ui_text(prop, "Name", "Unique name used in the code and scripting");
1111   RNA_def_struct_name_property(srna, prop);
1112 #  endif
1113 
1114   /* IDP_ID */
1115   prop = RNA_def_property(srna, "id", PROP_POINTER, PROP_NONE);
1116   RNA_def_property_flag(prop, PROP_IDPROPERTY | PROP_NEVER_UNLINK);
1117   RNA_def_property_struct_type(prop, "ID");
1118 
1119   /* ID property groups > level 0, since level 0 group is merged
1120    * with native RNA properties. the builtin_properties will take
1121    * care of the properties here */
1122   srna = RNA_def_struct(brna, "PropertyGroup", NULL);
1123   RNA_def_struct_sdna(srna, "IDPropertyGroup");
1124   RNA_def_struct_ui_text(srna, "ID Property Group", "Group of ID properties");
1125   RNA_def_struct_idprops_func(srna, "rna_PropertyGroup_idprops");
1126   RNA_def_struct_register_funcs(
1127       srna, "rna_PropertyGroup_register", "rna_PropertyGroup_unregister", NULL);
1128   RNA_def_struct_refine_func(srna, "rna_PropertyGroup_refine");
1129 
1130   /* important so python types can have their name used in list views
1131    * however this isn't prefect because it overrides how python would set the name
1132    * when we only really want this so RNA_def_struct_name_property() is set to something useful */
1133   prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
1134   RNA_def_property_flag(prop, PROP_IDPROPERTY);
1135   /*RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
1136   RNA_def_property_ui_text(prop, "Name", "Unique name used in the code and scripting");
1137   RNA_def_struct_name_property(srna, prop);
1138 }
1139 
rna_def_ID_materials(BlenderRNA * brna)1140 static void rna_def_ID_materials(BlenderRNA *brna)
1141 {
1142   StructRNA *srna;
1143   FunctionRNA *func;
1144   PropertyRNA *parm;
1145 
1146   /* for mesh/mball/curve materials */
1147   srna = RNA_def_struct(brna, "IDMaterials", NULL);
1148   RNA_def_struct_sdna(srna, "ID");
1149   RNA_def_struct_ui_text(srna, "ID Materials", "Collection of materials");
1150 
1151   func = RNA_def_function(srna, "append", "rna_IDMaterials_append_id");
1152   RNA_def_function_flag(func, FUNC_USE_MAIN);
1153   RNA_def_function_ui_description(func, "Add a new material to the data-block");
1154   parm = RNA_def_pointer(func, "material", "Material", "", "Material to add");
1155   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1156 
1157   func = RNA_def_function(srna, "pop", "rna_IDMaterials_pop_id");
1158   RNA_def_function_flag(func, FUNC_USE_REPORTS | FUNC_USE_MAIN);
1159   RNA_def_function_ui_description(func, "Remove a material from the data-block");
1160   parm = RNA_def_int(
1161       func, "index", -1, -MAXMAT, MAXMAT, "", "Index of material to remove", 0, MAXMAT);
1162   parm = RNA_def_pointer(func, "material", "Material", "", "Material to remove");
1163   RNA_def_function_return(func, parm);
1164 
1165   func = RNA_def_function(srna, "clear", "rna_IDMaterials_clear_id");
1166   RNA_def_function_flag(func, FUNC_USE_MAIN);
1167   RNA_def_function_ui_description(func, "Remove all materials from the data-block");
1168 }
1169 
rna_def_image_preview(BlenderRNA * brna)1170 static void rna_def_image_preview(BlenderRNA *brna)
1171 {
1172   StructRNA *srna;
1173   FunctionRNA *func;
1174   PropertyRNA *prop;
1175 
1176   srna = RNA_def_struct(brna, "ImagePreview", NULL);
1177   RNA_def_struct_sdna(srna, "PreviewImage");
1178   RNA_def_struct_ui_text(srna, "Image Preview", "Preview image and icon");
1179 
1180   prop = RNA_def_property(srna, "is_image_custom", PROP_BOOLEAN, PROP_NONE);
1181   RNA_def_property_boolean_sdna(prop, NULL, "flag[ICON_SIZE_PREVIEW]", PRV_USER_EDITED);
1182   RNA_def_property_boolean_funcs(prop, NULL, "rna_ImagePreview_is_image_custom_set");
1183   RNA_def_property_ui_text(prop,
1184                            "Custom Image",
1185                            "True if this preview image has been modified by py script,"
1186                            "and is no more auto-generated by Blender");
1187 
1188   prop = RNA_def_int_vector(
1189       srna, "image_size", 2, NULL, 0, 0, "Image Size", "Width and height in pixels", 0, 0);
1190   RNA_def_property_subtype(prop, PROP_PIXEL);
1191   RNA_def_property_int_funcs(
1192       prop, "rna_ImagePreview_image_size_get", "rna_ImagePreview_image_size_set", NULL);
1193 
1194   prop = RNA_def_property(srna, "image_pixels", PROP_INT, PROP_NONE);
1195   RNA_def_property_flag(prop, PROP_DYNAMIC);
1196   RNA_def_property_multi_array(prop, 1, NULL);
1197   RNA_def_property_ui_text(prop, "Image Pixels", "Image pixels, as bytes (always RGBA 32bits)");
1198   RNA_def_property_dynamic_array_funcs(prop, "rna_ImagePreview_image_pixels_get_length");
1199   RNA_def_property_int_funcs(
1200       prop, "rna_ImagePreview_image_pixels_get", "rna_ImagePreview_image_pixels_set", NULL);
1201 
1202   prop = RNA_def_property(srna, "image_pixels_float", PROP_FLOAT, PROP_NONE);
1203   RNA_def_property_flag(prop, PROP_DYNAMIC);
1204   RNA_def_property_multi_array(prop, 1, NULL);
1205   RNA_def_property_ui_text(
1206       prop, "Float Image Pixels", "Image pixels components, as floats (RGBA concatenated values)");
1207   RNA_def_property_dynamic_array_funcs(prop, "rna_ImagePreview_image_pixels_float_get_length");
1208   RNA_def_property_float_funcs(prop,
1209                                "rna_ImagePreview_image_pixels_float_get",
1210                                "rna_ImagePreview_image_pixels_float_set",
1211                                NULL);
1212 
1213   prop = RNA_def_property(srna, "is_icon_custom", PROP_BOOLEAN, PROP_NONE);
1214   RNA_def_property_boolean_sdna(prop, NULL, "flag[ICON_SIZE_ICON]", PRV_USER_EDITED);
1215   RNA_def_property_boolean_funcs(prop, NULL, "rna_ImagePreview_is_icon_custom_set");
1216   RNA_def_property_ui_text(prop,
1217                            "Custom Icon",
1218                            "True if this preview icon has been modified by py script,"
1219                            "and is no more auto-generated by Blender");
1220 
1221   prop = RNA_def_int_vector(
1222       srna, "icon_size", 2, NULL, 0, 0, "Icon Size", "Width and height in pixels", 0, 0);
1223   RNA_def_property_subtype(prop, PROP_PIXEL);
1224   RNA_def_property_int_funcs(
1225       prop, "rna_ImagePreview_icon_size_get", "rna_ImagePreview_icon_size_set", NULL);
1226 
1227   prop = RNA_def_property(srna, "icon_pixels", PROP_INT, PROP_NONE);
1228   RNA_def_property_flag(prop, PROP_DYNAMIC);
1229   RNA_def_property_multi_array(prop, 1, NULL);
1230   RNA_def_property_ui_text(prop, "Icon Pixels", "Icon pixels, as bytes (always RGBA 32bits)");
1231   RNA_def_property_dynamic_array_funcs(prop, "rna_ImagePreview_icon_pixels_get_length");
1232   RNA_def_property_int_funcs(
1233       prop, "rna_ImagePreview_icon_pixels_get", "rna_ImagePreview_icon_pixels_set", NULL);
1234 
1235   prop = RNA_def_property(srna, "icon_pixels_float", PROP_FLOAT, PROP_NONE);
1236   RNA_def_property_flag(prop, PROP_DYNAMIC);
1237   RNA_def_property_multi_array(prop, 1, NULL);
1238   RNA_def_property_ui_text(
1239       prop, "Float Icon Pixels", "Icon pixels components, as floats (RGBA concatenated values)");
1240   RNA_def_property_dynamic_array_funcs(prop, "rna_ImagePreview_icon_pixels_float_get_length");
1241   RNA_def_property_float_funcs(prop,
1242                                "rna_ImagePreview_icon_pixels_float_get",
1243                                "rna_ImagePreview_icon_pixels_float_set",
1244                                NULL);
1245 
1246   prop = RNA_def_int(srna,
1247                      "icon_id",
1248                      0,
1249                      INT_MIN,
1250                      INT_MAX,
1251                      "Icon ID",
1252                      "Unique integer identifying this preview as an icon (zero means invalid)",
1253                      INT_MIN,
1254                      INT_MAX);
1255   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1256   RNA_def_property_int_funcs(prop, "rna_ImagePreview_icon_id_get", NULL, NULL);
1257 
1258   func = RNA_def_function(srna, "reload", "rna_ImagePreview_icon_reload");
1259   RNA_def_function_ui_description(func, "Reload the preview from its source path");
1260 }
1261 
rna_def_ID_override_library_property_operation(BlenderRNA * brna)1262 static void rna_def_ID_override_library_property_operation(BlenderRNA *brna)
1263 {
1264   StructRNA *srna;
1265   PropertyRNA *prop;
1266 
1267   static const EnumPropertyItem override_library_property_operation_items[] = {
1268       {IDOVERRIDE_LIBRARY_OP_NOOP,
1269        "NOOP",
1270        0,
1271        "No-Op",
1272        "Does nothing, prevents adding actual overrides (NOT USED)"},
1273       {IDOVERRIDE_LIBRARY_OP_REPLACE,
1274        "REPLACE",
1275        0,
1276        "Replace",
1277        "Replace value of reference by overriding one"},
1278       {IDOVERRIDE_LIBRARY_OP_ADD,
1279        "DIFF_ADD",
1280        0,
1281        "Differential",
1282        "Stores and apply difference between reference and local value (NOT USED)"},
1283       {IDOVERRIDE_LIBRARY_OP_SUBTRACT,
1284        "DIFF_SUB",
1285        0,
1286        "Differential",
1287        "Stores and apply difference between reference and local value (NOT USED)"},
1288       {IDOVERRIDE_LIBRARY_OP_MULTIPLY,
1289        "FACT_MULTIPLY",
1290        0,
1291        "Factor",
1292        "Stores and apply multiplication factor between reference and local value (NOT USED)"},
1293       {IDOVERRIDE_LIBRARY_OP_INSERT_AFTER,
1294        "INSERT_AFTER",
1295        0,
1296        "Insert After",
1297        "Insert a new item into collection after the one referenced in subitem_reference_name or "
1298        "_index"},
1299       {IDOVERRIDE_LIBRARY_OP_INSERT_BEFORE,
1300        "INSERT_BEFORE",
1301        0,
1302        "Insert Before",
1303        "Insert a new item into collection after the one referenced in subitem_reference_name or "
1304        "_index (NOT USED)"},
1305       {0, NULL, 0, NULL, NULL},
1306   };
1307 
1308   static const EnumPropertyItem override_library_property_flag_items[] = {
1309       {IDOVERRIDE_LIBRARY_FLAG_MANDATORY,
1310        "MANDATORY",
1311        0,
1312        "Mandatory",
1313        "For templates, prevents the user from removing pre-defined operation (NOT USED)"},
1314       {IDOVERRIDE_LIBRARY_FLAG_LOCKED,
1315        "LOCKED",
1316        0,
1317        "Locked",
1318        "Prevents the user from modifying that override operation (NOT USED)"},
1319       {0, NULL, 0, NULL, NULL},
1320   };
1321 
1322   srna = RNA_def_struct(brna, "IDOverrideLibraryPropertyOperation", NULL);
1323   RNA_def_struct_ui_text(srna,
1324                          "ID Library Override Property Operation",
1325                          "Description of an override operation over an overridden property");
1326 
1327   prop = RNA_def_enum(srna,
1328                       "operation",
1329                       override_library_property_operation_items,
1330                       IDOVERRIDE_LIBRARY_OP_REPLACE,
1331                       "Operation",
1332                       "What override operation is performed");
1333   RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* For now. */
1334 
1335   prop = RNA_def_enum(
1336       srna, "flag", override_library_property_flag_items, 0, "Flags", "Optional flags (NOT USED)");
1337   RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* For now. */
1338 
1339   prop = RNA_def_string(srna,
1340                         "subitem_reference_name",
1341                         NULL,
1342                         INT_MAX,
1343                         "Subitem Reference Name",
1344                         "Used to handle insertions into collection");
1345   RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* For now. */
1346   RNA_def_property_string_funcs(prop,
1347                                 "rna_ID_override_library_property_operation_refname_get",
1348                                 "rna_ID_override_library_property_operation_refname_length",
1349                                 NULL);
1350 
1351   prop = RNA_def_string(srna,
1352                         "subitem_local_name",
1353                         NULL,
1354                         INT_MAX,
1355                         "Subitem Local Name",
1356                         "Used to handle insertions into collection");
1357   RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* For now. */
1358   RNA_def_property_string_funcs(prop,
1359                                 "rna_ID_override_library_property_operation_locname_get",
1360                                 "rna_ID_override_library_property_operation_locname_length",
1361                                 NULL);
1362 
1363   prop = RNA_def_int(srna,
1364                      "subitem_reference_index",
1365                      -1,
1366                      -1,
1367                      INT_MAX,
1368                      "Subitem Reference Index",
1369                      "Used to handle insertions into collection",
1370                      -1,
1371                      INT_MAX);
1372   RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* For now. */
1373 
1374   prop = RNA_def_int(srna,
1375                      "subitem_local_index",
1376                      -1,
1377                      -1,
1378                      INT_MAX,
1379                      "Subitem Local Index",
1380                      "Used to handle insertions into collection",
1381                      -1,
1382                      INT_MAX);
1383   RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* For now. */
1384 }
1385 
rna_def_ID_override_library_property(BlenderRNA * brna)1386 static void rna_def_ID_override_library_property(BlenderRNA *brna)
1387 {
1388   StructRNA *srna;
1389   PropertyRNA *prop;
1390 
1391   srna = RNA_def_struct(brna, "IDOverrideLibraryProperty", NULL);
1392   RNA_def_struct_ui_text(
1393       srna, "ID Library Override Property", "Description of an overridden property");
1394 
1395   /* String pointer, we *should* add get/set/etc.
1396    * But NULL rna_path would be a nasty bug anyway. */
1397   prop = RNA_def_string(srna,
1398                         "rna_path",
1399                         NULL,
1400                         INT_MAX,
1401                         "RNA Path",
1402                         "RNA path leading to that property, from owning ID");
1403   RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* For now. */
1404 
1405   RNA_def_collection(srna,
1406                      "operations",
1407                      "IDOverrideLibraryPropertyOperation",
1408                      "Operations",
1409                      "List of overriding operations for a property");
1410 
1411   rna_def_ID_override_library_property_operation(brna);
1412 }
1413 
rna_def_ID_override_library(BlenderRNA * brna)1414 static void rna_def_ID_override_library(BlenderRNA *brna)
1415 {
1416   StructRNA *srna;
1417 
1418   srna = RNA_def_struct(brna, "IDOverrideLibrary", NULL);
1419   RNA_def_struct_ui_text(
1420       srna, "ID Library Override", "Struct gathering all data needed by overridden linked IDs");
1421 
1422   RNA_def_pointer(
1423       srna, "reference", "ID", "Reference ID", "Linked ID used as reference by this override");
1424 
1425   RNA_def_collection(srna,
1426                      "properties",
1427                      "IDOverrideLibraryProperty",
1428                      "Properties",
1429                      "List of overridden properties");
1430 
1431   rna_def_ID_override_library_property(brna);
1432 }
1433 
rna_def_ID(BlenderRNA * brna)1434 static void rna_def_ID(BlenderRNA *brna)
1435 {
1436   StructRNA *srna;
1437   FunctionRNA *func;
1438   PropertyRNA *prop, *parm;
1439 
1440   static const EnumPropertyItem update_flag_items[] = {
1441       {ID_RECALC_TRANSFORM, "OBJECT", 0, "Object", ""},
1442       {ID_RECALC_GEOMETRY, "DATA", 0, "Data", ""},
1443       {ID_RECALC_ANIMATION, "TIME", 0, "Time", ""},
1444       {0, NULL, 0, NULL, NULL},
1445   };
1446 
1447   srna = RNA_def_struct(brna, "ID", NULL);
1448   RNA_def_struct_ui_text(
1449       srna,
1450       "ID",
1451       "Base type for data-blocks, defining a unique name, linking from other libraries "
1452       "and garbage collection");
1453   RNA_def_struct_flag(srna, STRUCT_ID | STRUCT_ID_REFCOUNT);
1454   RNA_def_struct_refine_func(srna, "rna_ID_refine");
1455   RNA_def_struct_idprops_func(srna, "rna_ID_idprops");
1456 
1457   prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
1458   RNA_def_property_ui_text(prop, "Name", "Unique data-block ID name");
1459   RNA_def_property_string_funcs(prop, "rna_ID_name_get", "rna_ID_name_length", "rna_ID_name_set");
1460   RNA_def_property_string_maxlength(prop, MAX_ID_NAME - 2);
1461   RNA_def_property_editable_func(prop, "rna_ID_name_editable");
1462   RNA_def_property_update(prop, NC_ID | NA_RENAME, NULL);
1463   RNA_def_property_override_flag(prop, PROPOVERRIDE_IGNORE);
1464   RNA_def_struct_name_property(srna, prop);
1465 
1466   prop = RNA_def_property(srna, "name_full", PROP_STRING, PROP_NONE);
1467   RNA_def_property_ui_text(
1468       prop, "Full Name", "Unique data-block ID name, including library one is any");
1469   RNA_def_property_string_funcs(prop, "rna_ID_name_full_get", "rna_ID_name_full_length", NULL);
1470   RNA_def_property_string_maxlength(prop, MAX_ID_FULL_NAME);
1471   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1472 
1473   prop = RNA_def_property(srna, "is_evaluated", PROP_BOOLEAN, PROP_NONE);
1474   RNA_def_property_ui_text(
1475       prop,
1476       "Is Evaluated",
1477       "Whether this ID is runtime-only, evaluated data-block, or actual data from .blend file");
1478   RNA_def_property_boolean_funcs(prop, "rna_ID_is_evaluated_get", NULL);
1479   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1480 
1481   prop = RNA_def_property(srna, "original", PROP_POINTER, PROP_NONE);
1482   RNA_def_property_struct_type(prop, "ID");
1483   RNA_def_property_ui_text(
1484       prop,
1485       "Original ID",
1486       "Actual data-block from .blend file (Main database) that generated that evaluated one");
1487   RNA_def_property_pointer_funcs(prop, "rna_ID_original_get", NULL, NULL, NULL);
1488   RNA_def_property_clear_flag(prop, PROP_EDITABLE | PROP_PTR_NO_OWNERSHIP);
1489   RNA_def_property_override_flag(prop, PROPOVERRIDE_NO_COMPARISON);
1490 
1491   prop = RNA_def_property(srna, "users", PROP_INT, PROP_UNSIGNED);
1492   RNA_def_property_int_sdna(prop, NULL, "us");
1493   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1494   RNA_def_property_ui_text(prop, "Users", "Number of times this data-block is referenced");
1495 
1496   prop = RNA_def_property(srna, "use_fake_user", PROP_BOOLEAN, PROP_NONE);
1497   RNA_def_property_boolean_sdna(prop, NULL, "flag", LIB_FAKEUSER);
1498   RNA_def_property_ui_text(prop, "Fake User", "Save this data-block even if it has no users");
1499   RNA_def_property_ui_icon(prop, ICON_FAKE_USER_OFF, true);
1500   RNA_def_property_boolean_funcs(prop, NULL, "rna_ID_fake_user_set");
1501 
1502   prop = RNA_def_property(srna, "is_embedded_data", PROP_BOOLEAN, PROP_NONE);
1503   RNA_def_property_boolean_sdna(prop, NULL, "flag", LIB_EMBEDDED_DATA);
1504   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1505   RNA_def_property_ui_text(
1506       prop,
1507       "Embedded Data",
1508       "This data-block is not an independent one, but is actually a sub-data of another ID "
1509       "(typical example: root node trees or master collections)");
1510 
1511   prop = RNA_def_property(srna, "tag", PROP_BOOLEAN, PROP_NONE);
1512   RNA_def_property_boolean_sdna(prop, NULL, "tag", LIB_TAG_DOIT);
1513   RNA_def_property_flag(prop, PROP_LIB_EXCEPTION);
1514   RNA_def_property_ui_text(prop,
1515                            "Tag",
1516                            "Tools can use this to tag data for their own purposes "
1517                            "(initial state is undefined)");
1518 
1519   prop = RNA_def_property(srna, "is_library_indirect", PROP_BOOLEAN, PROP_NONE);
1520   RNA_def_property_boolean_sdna(prop, NULL, "tag", LIB_TAG_INDIRECT);
1521   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1522   RNA_def_property_ui_text(prop, "Is Indirect", "Is this ID block linked indirectly");
1523 
1524   prop = RNA_def_property(srna, "library", PROP_POINTER, PROP_NONE);
1525   RNA_def_property_pointer_sdna(prop, NULL, "lib");
1526   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1527   RNA_def_property_override_flag(prop, PROPOVERRIDE_NO_COMPARISON);
1528   RNA_def_property_ui_text(prop, "Library", "Library file the data-block is linked from");
1529 
1530   prop = RNA_def_pointer(
1531       srna, "override_library", "IDOverrideLibrary", "Library Override", "Library override data");
1532   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1533 
1534   prop = RNA_def_pointer(
1535       srna,
1536       "preview",
1537       "ImagePreview",
1538       "Preview",
1539       "Preview image and icon of this data-block (None if not supported for this type of data)");
1540   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1541   RNA_def_property_override_flag(prop, PROPOVERRIDE_NO_COMPARISON);
1542   RNA_def_property_pointer_funcs(prop, "rna_IDPreview_get", NULL, NULL, NULL);
1543 
1544   /* functions */
1545   func = RNA_def_function(srna, "evaluated_get", "rna_ID_evaluated_get");
1546   RNA_def_function_ui_description(
1547       func, "Get corresponding evaluated ID from the given dependency graph");
1548   parm = RNA_def_pointer(
1549       func, "depsgraph", "Depsgraph", "", "Dependency graph to perform lookup in");
1550   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
1551   parm = RNA_def_pointer(func, "id", "ID", "", "New copy of the ID");
1552   RNA_def_function_return(func, parm);
1553 
1554   func = RNA_def_function(srna, "copy", "rna_ID_copy");
1555   RNA_def_function_ui_description(
1556       func, "Create a copy of this data-block (not supported for all data-blocks)");
1557   RNA_def_function_flag(func, FUNC_USE_MAIN);
1558   parm = RNA_def_pointer(func, "id", "ID", "", "New copy of the ID");
1559   RNA_def_function_return(func, parm);
1560 
1561   func = RNA_def_function(srna, "override_create", "rna_ID_override_create");
1562   RNA_def_function_ui_description(func,
1563                                   "Create an overridden local copy of this linked data-block (not "
1564                                   "supported for all data-blocks)");
1565   RNA_def_function_flag(func, FUNC_USE_MAIN);
1566   parm = RNA_def_pointer(func, "id", "ID", "", "New overridden local copy of the ID");
1567   RNA_def_function_return(func, parm);
1568   RNA_def_boolean(func,
1569                   "remap_local_usages",
1570                   false,
1571                   "",
1572                   "Whether local usages of the linked ID should be remapped to the new "
1573                   "library override of it");
1574 
1575   func = RNA_def_function(srna, "user_clear", "rna_ID_user_clear");
1576   RNA_def_function_ui_description(func,
1577                                   "Clear the user count of a data-block so its not saved, "
1578                                   "on reload the data will be removed");
1579 
1580   func = RNA_def_function(srna, "user_remap", "rna_ID_user_remap");
1581   RNA_def_function_ui_description(
1582       func, "Replace all usage in the .blend file of this ID by new given one");
1583   RNA_def_function_flag(func, FUNC_USE_MAIN);
1584   parm = RNA_def_pointer(func, "new_id", "ID", "", "New ID to use");
1585   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
1586 
1587   func = RNA_def_function(srna, "make_local", "rna_ID_make_local");
1588   RNA_def_function_ui_description(
1589       func,
1590       "Make this datablock local, return local one "
1591       "(may be a copy of the original, in case it is also indirectly used)");
1592   RNA_def_function_flag(func, FUNC_USE_MAIN);
1593   parm = RNA_def_boolean(
1594       func,
1595       "clear_proxy",
1596       true,
1597       "",
1598       "Whether to clear proxies (the default behavior, "
1599       "note that if object has to be duplicated to be made local, proxies are always cleared)");
1600   parm = RNA_def_pointer(func, "id", "ID", "", "This ID, or the new ID if it was copied");
1601   RNA_def_function_return(func, parm);
1602 
1603   func = RNA_def_function(srna, "user_of_id", "BKE_library_ID_use_ID");
1604   RNA_def_function_ui_description(func,
1605                                   "Count the number of times that ID uses/references given one");
1606   parm = RNA_def_pointer(func, "id", "ID", "", "ID to count usages");
1607   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
1608   parm = RNA_def_int(func,
1609                      "count",
1610                      0,
1611                      0,
1612                      INT_MAX,
1613                      "",
1614                      "Number of usages/references of given id by current data-block",
1615                      0,
1616                      INT_MAX);
1617   RNA_def_function_return(func, parm);
1618 
1619   func = RNA_def_function(srna, "animation_data_create", "rna_ID_animation_data_create");
1620   RNA_def_function_flag(func, FUNC_USE_MAIN);
1621   RNA_def_function_ui_description(
1622       func, "Create animation data to this ID, note that not all ID types support this");
1623   parm = RNA_def_pointer(func, "anim_data", "AnimData", "", "New animation data or NULL");
1624   RNA_def_function_return(func, parm);
1625 
1626   func = RNA_def_function(srna, "animation_data_clear", "rna_ID_animation_data_free");
1627   RNA_def_function_flag(func, FUNC_USE_MAIN);
1628   RNA_def_function_ui_description(func, "Clear animation on this this ID");
1629 
1630   func = RNA_def_function(srna, "update_tag", "rna_ID_update_tag");
1631   RNA_def_function_flag(func, FUNC_USE_MAIN | FUNC_USE_REPORTS);
1632   RNA_def_function_ui_description(func,
1633                                   "Tag the ID to update its display data, "
1634                                   "e.g. when calling :class:`bpy.types.Scene.update`");
1635   RNA_def_enum_flag(func, "refresh", update_flag_items, 0, "", "Type of updates to perform");
1636 
1637 #  ifdef WITH_PYTHON
1638   RNA_def_struct_register_funcs(srna, NULL, NULL, "rna_ID_instance");
1639 #  endif
1640 }
1641 
rna_def_library(BlenderRNA * brna)1642 static void rna_def_library(BlenderRNA *brna)
1643 {
1644   StructRNA *srna;
1645   FunctionRNA *func;
1646   PropertyRNA *prop;
1647 
1648   srna = RNA_def_struct(brna, "Library", "ID");
1649   RNA_def_struct_ui_text(srna, "Library", "External .blend file from which data is linked");
1650   RNA_def_struct_ui_icon(srna, ICON_LIBRARY_DATA_DIRECT);
1651 
1652   prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
1653   RNA_def_property_string_sdna(prop, NULL, "filepath");
1654   RNA_def_property_ui_text(prop, "File Path", "Path to the library .blend file");
1655   RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Library_filepath_set");
1656 
1657   prop = RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
1658   RNA_def_property_struct_type(prop, "Library");
1659   RNA_def_property_override_flag(prop, PROPOVERRIDE_NO_COMPARISON);
1660   RNA_def_property_ui_text(prop, "Parent", "");
1661 
1662   prop = RNA_def_property(srna, "packed_file", PROP_POINTER, PROP_NONE);
1663   RNA_def_property_pointer_sdna(prop, NULL, "packedfile");
1664   RNA_def_property_ui_text(prop, "Packed File", "");
1665 
1666   prop = RNA_def_int_vector(srna,
1667                             "version",
1668                             3,
1669                             NULL,
1670                             0,
1671                             INT_MAX,
1672                             "Version",
1673                             "Version of Blender the library .blend was saved with",
1674                             0,
1675                             INT_MAX);
1676   RNA_def_property_int_funcs(prop, "rna_Library_version_get", NULL, NULL);
1677   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1678   RNA_def_property_flag(prop, PROP_THICK_WRAP);
1679 
1680   func = RNA_def_function(srna, "reload", "WM_lib_reload");
1681   RNA_def_function_flag(func, FUNC_USE_REPORTS | FUNC_USE_CONTEXT);
1682   RNA_def_function_ui_description(func, "Reload this library and all its linked data-blocks");
1683 }
1684 
1685 /**
1686  * \attention This is separate from the above. It allows for RNA functions to
1687  * return an IDProperty *. See MovieClip.metadata for a usage example.
1688  */
rna_def_idproperty_wrap_ptr(BlenderRNA * brna)1689 static void rna_def_idproperty_wrap_ptr(BlenderRNA *brna)
1690 {
1691   StructRNA *srna;
1692 
1693   srna = RNA_def_struct(brna, "IDPropertyWrapPtr", NULL);
1694   RNA_def_struct_idprops_func(srna, "rna_IDPropertyWrapPtr_idprops");
1695   RNA_def_struct_flag(srna, STRUCT_NO_DATABLOCK_IDPROPERTIES);
1696 }
1697 
RNA_def_ID(BlenderRNA * brna)1698 void RNA_def_ID(BlenderRNA *brna)
1699 {
1700   StructRNA *srna;
1701 
1702   /* built-in unknown type */
1703   srna = RNA_def_struct(brna, "UnknownType", NULL);
1704   RNA_def_struct_ui_text(
1705       srna, "Unknown Type", "Stub RNA type used for pointers to unknown or internal data");
1706 
1707   /* built-in any type */
1708   srna = RNA_def_struct(brna, "AnyType", NULL);
1709   RNA_def_struct_ui_text(srna, "Any Type", "RNA type used for pointers to any possible data");
1710 
1711   rna_def_ID(brna);
1712   rna_def_ID_override_library(brna);
1713   rna_def_image_preview(brna);
1714   rna_def_ID_properties(brna);
1715   rna_def_ID_materials(brna);
1716   rna_def_library(brna);
1717   rna_def_idproperty_wrap_ptr(brna);
1718 }
1719 
1720 #endif
1721