Cleanup: remove unused mtexpoly array
[blender.git] / source / blender / makesrna / intern / rna_rna.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_rna.c
24  *  \ingroup RNA
25  */
26
27 #include <stdlib.h>
28
29 #include "DNA_ID.h"
30
31 #include "BLI_utildefines.h"
32
33 #include "RNA_access.h"
34 #include "RNA_define.h"
35 #include "RNA_enum_types.h"
36
37 #include "rna_internal.h"
38
39 const EnumPropertyItem rna_enum_property_type_items[] = {
40         {PROP_BOOLEAN, "BOOLEAN", 0, "Boolean", ""},
41         {PROP_INT, "INT", 0, "Integer", ""},
42         {PROP_FLOAT, "FLOAT", 0, "Float", ""},
43         {PROP_STRING, "STRING", 0, "String", ""},
44         {PROP_ENUM, "ENUM", 0, "Enumeration", ""},
45         {PROP_POINTER, "POINTER", 0, "Pointer", ""},
46         {PROP_COLLECTION, "COLLECTION", 0, "Collection", ""},
47         {0, NULL, 0, NULL, NULL}
48 };
49
50 /* XXX Keep in sync with bpy_props.c's property_subtype_xxx_items ???
51  *     Currently it is not...
52  */
53 const EnumPropertyItem rna_enum_property_subtype_items[] = {
54         {PROP_NONE, "NONE", 0, "None", ""},
55
56         /* strings */
57         {PROP_FILEPATH, "FILEPATH", 0, "File Path", ""},
58         {PROP_DIRPATH, "DIRPATH", 0, "Directory Path", ""},
59         {PROP_FILENAME, "FILENAME", 0, "File Name", ""},
60         {PROP_PASSWORD, "PASSWORD", 0, "Password", "A string that is displayed hidden ('********')"},
61
62         /* numbers */
63         {PROP_PIXEL, "PIXEL", 0, "Pixel", ""},
64         {PROP_UNSIGNED, "UNSIGNED", 0, "Unsigned", ""},
65         {PROP_PERCENTAGE, "PERCENTAGE", 0, "Percentage", ""},
66         {PROP_FACTOR, "FACTOR", 0, "Factor", ""},
67         {PROP_ANGLE, "ANGLE", 0, "Angle", ""},
68         {PROP_TIME, "TIME", 0, "Time", ""},
69         {PROP_DISTANCE, "DISTANCE", 0, "Distance", ""},
70         {PROP_DISTANCE_CAMERA, "DISTANCE_CAMERA", 0, "Camera Distance", ""},
71
72         /* number arrays */
73         {PROP_COLOR, "COLOR", 0, "Color", ""},
74         {PROP_TRANSLATION, "TRANSLATION", 0, "Translation", ""},
75         {PROP_DIRECTION, "DIRECTION", 0, "Direction", ""},
76         {PROP_VELOCITY, "VELOCITY", 0, "Velocity", ""},
77         {PROP_ACCELERATION, "ACCELERATION", 0, "Acceleration", ""},
78         {PROP_MATRIX, "MATRIX", 0, "Matrix", ""},
79         {PROP_EULER, "EULER", 0, "Euler Angles", ""},
80         {PROP_QUATERNION, "QUATERNION", 0, "Quaternion", ""},
81         {PROP_AXISANGLE, "AXISANGLE", 0, "Axis-Angle", ""},
82         {PROP_XYZ, "XYZ", 0, "XYZ", ""},
83         {PROP_XYZ_LENGTH, "XYZ_LENGTH", 0, "XYZ Length", ""},
84         {PROP_COLOR_GAMMA, "COLOR_GAMMA", 0, "Color", ""},
85         {PROP_COORDS, "COORDS", 0, "Coordinates", ""},
86
87         /* booleans */
88         {PROP_LAYER, "LAYER", 0, "Layer", ""},
89         {PROP_LAYER_MEMBER, "LAYER_MEMBER", 0, "Layer Member", ""},
90         {0, NULL, 0, NULL, NULL}
91 };
92
93 const EnumPropertyItem rna_enum_property_unit_items[] = {
94         {PROP_UNIT_NONE, "NONE", 0, "None", ""},
95         {PROP_UNIT_LENGTH, "LENGTH", 0, "Length", ""},
96         {PROP_UNIT_AREA, "AREA", 0, "Area", ""},
97         {PROP_UNIT_VOLUME, "VOLUME", 0, "Volume", ""},
98         {PROP_UNIT_ROTATION, "ROTATION", 0, "Rotation", ""},
99         {PROP_UNIT_TIME, "TIME", 0, "Time", ""},
100         {PROP_UNIT_VELOCITY, "VELOCITY", 0, "Velocity", ""},
101         {PROP_UNIT_ACCELERATION, "ACCELERATION", 0, "Acceleration", ""},
102         {PROP_UNIT_CAMERA, "CAMERA", 0, "Camera", ""},
103         {0, NULL, 0, NULL, NULL}
104 };
105
106 #ifdef RNA_RUNTIME
107 #include "MEM_guardedalloc.h"
108 #include "BLI_ghash.h"
109
110 #include "BKE_library_override.h"
111
112 /* Struct */
113
114 static void rna_Struct_identifier_get(PointerRNA *ptr, char *value)
115 {
116         strcpy(value, ((StructRNA *)ptr->data)->identifier);
117 }
118
119 static int rna_Struct_identifier_length(PointerRNA *ptr)
120 {
121         return strlen(((StructRNA *)ptr->data)->identifier);
122 }
123
124 static void rna_Struct_description_get(PointerRNA *ptr, char *value)
125 {
126         strcpy(value, ((StructRNA *)ptr->data)->description);
127 }
128
129 static int rna_Struct_description_length(PointerRNA *ptr)
130 {
131         return strlen(((StructRNA *)ptr->data)->description);
132 }
133
134 static void rna_Struct_name_get(PointerRNA *ptr, char *value)
135 {
136         strcpy(value, ((StructRNA *)ptr->data)->name);
137 }
138
139 static int rna_Struct_name_length(PointerRNA *ptr)
140 {
141         return strlen(((StructRNA *)ptr->data)->name);
142 }
143
144 static void rna_Struct_translation_context_get(PointerRNA *ptr, char *value)
145 {
146         strcpy(value, ((StructRNA *)ptr->data)->translation_context);
147 }
148
149 static int rna_Struct_translation_context_length(PointerRNA *ptr)
150 {
151         return strlen(((StructRNA *)ptr->data)->translation_context);
152 }
153
154 static PointerRNA rna_Struct_base_get(PointerRNA *ptr)
155 {
156         return rna_pointer_inherit_refine(ptr, &RNA_Struct, ((StructRNA *)ptr->data)->base);
157 }
158
159 static PointerRNA rna_Struct_nested_get(PointerRNA *ptr)
160 {
161         return rna_pointer_inherit_refine(ptr, &RNA_Struct, ((StructRNA *)ptr->data)->nested);
162 }
163
164 static PointerRNA rna_Struct_name_property_get(PointerRNA *ptr)
165 {
166         return rna_pointer_inherit_refine(ptr, &RNA_Property, ((StructRNA *)ptr->data)->nameproperty);
167 }
168
169 /* Struct property iteration. This is quite complicated, the purpose is to
170  * iterate over properties of all inheritance levels, and for each struct to
171  * also iterator over id properties not known by RNA. */
172
173 static int rna_idproperty_known(CollectionPropertyIterator *iter, void *data)
174 {
175         IDProperty *idprop = (IDProperty *)data;
176         PropertyRNA *prop;
177         StructRNA *ptype = iter->builtin_parent.type;
178
179         /* function to skip any id properties that are already known by RNA,
180          * for the second loop where we go over unknown id properties */
181         do {
182                 for (prop = ptype->cont.properties.first; prop; prop = prop->next)
183                         if ((prop->flag_internal & PROP_INTERN_BUILTIN) == 0 && STREQ(prop->identifier, idprop->name))
184                                 return 1;
185         } while ((ptype = ptype->base));
186
187         return 0;
188 }
189
190 static int rna_property_builtin(CollectionPropertyIterator *UNUSED(iter), void *data)
191 {
192         PropertyRNA *prop = (PropertyRNA *)data;
193
194         /* function to skip builtin rna properties */
195
196         return (prop->flag_internal & PROP_INTERN_BUILTIN);
197 }
198
199 static int rna_function_builtin(CollectionPropertyIterator *UNUSED(iter), void *data)
200 {
201         FunctionRNA *func = (FunctionRNA *)data;
202
203         /* function to skip builtin rna functions */
204
205         return (func->flag & FUNC_BUILTIN);
206 }
207
208 static void rna_inheritance_next_level_restart(CollectionPropertyIterator *iter, IteratorSkipFunc skip, int funcs)
209 {
210         /* RNA struct inheritance */
211         while (!iter->valid && iter->level > 0) {
212                 StructRNA *srna;
213                 int i;
214
215                 srna = (StructRNA *)iter->parent.data;
216                 iter->level--;
217                 for (i = iter->level; i > 0; i--)
218                         srna = srna->base;
219
220                 rna_iterator_listbase_end(iter);
221
222                 if (funcs)
223                         rna_iterator_listbase_begin(iter, &srna->functions, skip);
224                 else
225                         rna_iterator_listbase_begin(iter, &srna->cont.properties, skip);
226         }
227 }
228
229 static void rna_inheritance_properties_listbase_begin(CollectionPropertyIterator *iter, ListBase *lb,
230                                                       IteratorSkipFunc skip)
231 {
232         rna_iterator_listbase_begin(iter, lb, skip);
233         rna_inheritance_next_level_restart(iter, skip, 0);
234 }
235
236 static void rna_inheritance_properties_listbase_next(CollectionPropertyIterator *iter, IteratorSkipFunc skip)
237 {
238         rna_iterator_listbase_next(iter);
239         rna_inheritance_next_level_restart(iter, skip, 0);
240 }
241
242 static void rna_inheritance_functions_listbase_begin(CollectionPropertyIterator *iter, ListBase *lb,
243                                                      IteratorSkipFunc skip)
244 {
245         rna_iterator_listbase_begin(iter, lb, skip);
246         rna_inheritance_next_level_restart(iter, skip, 1);
247 }
248
249 static void rna_inheritance_functions_listbase_next(CollectionPropertyIterator *iter, IteratorSkipFunc skip)
250 {
251         rna_iterator_listbase_next(iter);
252         rna_inheritance_next_level_restart(iter, skip, 1);
253 }
254
255 static void rna_Struct_properties_next(CollectionPropertyIterator *iter)
256 {
257         ListBaseIterator *internal = &iter->internal.listbase;
258         IDProperty *group;
259
260         if (internal->flag) {
261                 /* id properties */
262                 rna_iterator_listbase_next(iter);
263         }
264         else {
265                 /* regular properties */
266                 rna_inheritance_properties_listbase_next(iter, rna_property_builtin);
267
268                 /* try id properties */
269                 if (!iter->valid) {
270                         group = RNA_struct_idprops(&iter->builtin_parent, 0);
271
272                         if (group) {
273                                 rna_iterator_listbase_end(iter);
274                                 rna_iterator_listbase_begin(iter, &group->data.group, rna_idproperty_known);
275                                 internal = &iter->internal.listbase;
276                                 internal->flag = 1;
277                         }
278                 }
279         }
280 }
281
282 static void rna_Struct_properties_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
283 {
284         StructRNA *srna;
285
286         /* here ptr->data should always be the same as iter->parent.type */
287         srna = (StructRNA *)ptr->data;
288
289         while (srna->base) {
290                 iter->level++;
291                 srna = srna->base;
292         }
293
294         rna_inheritance_properties_listbase_begin(iter, &srna->cont.properties, rna_property_builtin);
295 }
296
297 static PointerRNA rna_Struct_properties_get(CollectionPropertyIterator *iter)
298 {
299         ListBaseIterator *internal = &iter->internal.listbase;
300
301         /* we return either PropertyRNA* or IDProperty*, the rna_access.c
302          * functions can handle both as PropertyRNA* with some tricks */
303         return rna_pointer_inherit_refine(&iter->parent, &RNA_Property, internal->link);
304 }
305
306 static void rna_Struct_functions_next(CollectionPropertyIterator *iter)
307 {
308         rna_inheritance_functions_listbase_next(iter, rna_function_builtin);
309 }
310
311 static void rna_Struct_functions_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
312 {
313         StructRNA *srna;
314
315         /* here ptr->data should always be the same as iter->parent.type */
316         srna = (StructRNA *)ptr->data;
317
318         while (srna->base) {
319                 iter->level++;
320                 srna = srna->base;
321         }
322
323         rna_inheritance_functions_listbase_begin(iter, &srna->functions, rna_function_builtin);
324 }
325
326 static PointerRNA rna_Struct_functions_get(CollectionPropertyIterator *iter)
327 {
328         ListBaseIterator *internal = &iter->internal.listbase;
329
330         /* we return either PropertyRNA* or IDProperty*, the rna_access.c
331          * functions can handle both as PropertyRNA* with some tricks */
332         return rna_pointer_inherit_refine(&iter->parent, &RNA_Function, internal->link);
333 }
334
335 static void rna_Struct_property_tags_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
336 {
337         /* here ptr->data should always be the same as iter->parent.type */
338         StructRNA *srna = (StructRNA *)ptr->data;
339         const EnumPropertyItem *tag_defines = RNA_struct_property_tag_defines(srna);
340         unsigned int tag_count = tag_defines ? RNA_enum_items_count(tag_defines) : 0;
341
342         rna_iterator_array_begin(iter, (void *)tag_defines, sizeof(EnumPropertyItem), tag_count, 0, NULL);
343 }
344
345 /* Builtin properties iterator re-uses the Struct properties iterator, only
346  * difference is that we need to set the ptr data to the type of the struct
347  * whose properties we want to iterate over. */
348
349 void rna_builtin_properties_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
350 {
351         PointerRNA newptr;
352
353         /* we create a new pointer with the type as the data */
354         newptr.type = &RNA_Struct;
355         newptr.data = ptr->type;
356
357         if (ptr->type->flag & STRUCT_ID)
358                 newptr.id.data = ptr->data;
359         else
360                 newptr.id.data = NULL;
361
362         iter->parent = newptr;
363         iter->builtin_parent = *ptr;
364
365         rna_Struct_properties_begin(iter, &newptr);
366 }
367
368 void rna_builtin_properties_next(CollectionPropertyIterator *iter)
369 {
370         rna_Struct_properties_next(iter);
371 }
372
373 PointerRNA rna_builtin_properties_get(CollectionPropertyIterator *iter)
374 {
375         return rna_Struct_properties_get(iter);
376 }
377
378 int rna_builtin_properties_lookup_string(PointerRNA *ptr, const char *key, PointerRNA *r_ptr)
379 {
380         StructRNA *srna;
381         PropertyRNA *prop;
382         PointerRNA propptr = {{NULL}};
383
384         srna = ptr->type;
385
386         do {
387                 if (srna->cont.prophash) {
388                         prop = BLI_ghash_lookup(srna->cont.prophash, (void *)key);
389
390                         if (prop) {
391                                 propptr.type = &RNA_Property;
392                                 propptr.data = prop;
393
394                                 *r_ptr = propptr;
395                                 return true;
396                         }
397                 }
398                 else {
399                         for (prop = srna->cont.properties.first; prop; prop = prop->next) {
400                                 if (!(prop->flag_internal & PROP_INTERN_BUILTIN) && STREQ(prop->identifier, key)) {
401                                         propptr.type = &RNA_Property;
402                                         propptr.data = prop;
403
404                                         *r_ptr = propptr;
405                                         return true;
406                                 }
407                         }
408                 }
409         } while ((srna = srna->base));
410
411         /* this was used pre 2.5beta0, now ID property access uses python's
412          * getitem style access
413          * - ob["foo"] rather than ob.foo */
414 #if 0
415         if (ptr->data) {
416                 IDProperty *group, *idp;
417
418                 group = RNA_struct_idprops(ptr, 0);
419
420                 if (group) {
421                         for (idp = group->data.group.first; idp; idp = idp->next) {
422                                 if (STREQ(idp->name, key)) {
423                                         propptr.type = &RNA_Property;
424                                         propptr.data = idp;
425
426                                         *r_ptr = propptr;
427                                         return true;
428                                 }
429                         }
430                 }
431         }
432 #endif
433         return false;
434 }
435
436 PointerRNA rna_builtin_type_get(PointerRNA *ptr)
437 {
438         return rna_pointer_inherit_refine(ptr, &RNA_Struct, ptr->type);
439 }
440
441 /* Property */
442
443 static StructRNA *rna_Property_refine(PointerRNA *ptr)
444 {
445         PropertyRNA *prop = (PropertyRNA *)ptr->data;
446
447         rna_idproperty_check(&prop, ptr); /* XXX ptr? */
448
449         switch (prop->type) {
450                 case PROP_BOOLEAN: return &RNA_BoolProperty;
451                 case PROP_INT: return &RNA_IntProperty;
452                 case PROP_FLOAT: return &RNA_FloatProperty;
453                 case PROP_STRING: return &RNA_StringProperty;
454                 case PROP_ENUM: return &RNA_EnumProperty;
455                 case PROP_POINTER: return &RNA_PointerProperty;
456                 case PROP_COLLECTION: return &RNA_CollectionProperty;
457                 default: return &RNA_Property;
458         }
459 }
460
461 static void rna_Property_identifier_get(PointerRNA *ptr, char *value)
462 {
463         PropertyRNA *prop = (PropertyRNA *)ptr->data;
464         rna_idproperty_check(&prop, ptr);
465         strcpy(value, ((PropertyRNA *)prop)->identifier);
466 }
467
468 static int rna_Property_identifier_length(PointerRNA *ptr)
469 {
470         PropertyRNA *prop = (PropertyRNA *)ptr->data;
471         rna_idproperty_check(&prop, ptr);
472         return strlen(prop->identifier);
473 }
474
475 static void rna_Property_name_get(PointerRNA *ptr, char *value)
476 {
477         PropertyRNA *prop = (PropertyRNA *)ptr->data;
478         rna_idproperty_check(&prop, ptr);
479         strcpy(value, prop->name ? prop->name : "");
480 }
481
482 static int rna_Property_name_length(PointerRNA *ptr)
483 {
484         PropertyRNA *prop = (PropertyRNA *)ptr->data;
485         rna_idproperty_check(&prop, ptr);
486         return prop->name ? strlen(prop->name) : 0;
487 }
488
489 static void rna_Property_description_get(PointerRNA *ptr, char *value)
490 {
491         PropertyRNA *prop = (PropertyRNA *)ptr->data;
492         rna_idproperty_check(&prop, ptr);
493         strcpy(value, prop->description ? prop->description : "");
494 }
495 static int rna_Property_description_length(PointerRNA *ptr)
496 {
497         PropertyRNA *prop = (PropertyRNA *)ptr->data;
498         rna_idproperty_check(&prop, ptr);
499         return prop->description ? strlen(prop->description) : 0;
500 }
501
502 static void rna_Property_translation_context_get(PointerRNA *ptr, char *value)
503 {
504         PropertyRNA *prop = (PropertyRNA *)ptr->data;
505         rna_idproperty_check(&prop, ptr);
506         strcpy(value, prop->translation_context);
507 }
508
509 static int rna_Property_translation_context_length(PointerRNA *ptr)
510 {
511         PropertyRNA *prop = (PropertyRNA *)ptr->data;
512         rna_idproperty_check(&prop, ptr);
513         return strlen(prop->translation_context);
514 }
515
516 static int rna_Property_type_get(PointerRNA *ptr)
517 {
518         PropertyRNA *prop = (PropertyRNA *)ptr->data;
519         rna_idproperty_check(&prop, ptr);
520         return prop->type;
521 }
522
523 static int rna_Property_subtype_get(PointerRNA *ptr)
524 {
525         PropertyRNA *prop = (PropertyRNA *)ptr->data;
526         rna_idproperty_check(&prop, ptr);
527         return prop->subtype;
528 }
529
530 static PointerRNA rna_Property_srna_get(PointerRNA *ptr)
531 {
532         PropertyRNA *prop = (PropertyRNA *)ptr->data;
533         rna_idproperty_check(&prop, ptr);
534         return rna_pointer_inherit_refine(ptr, &RNA_Struct, prop->srna);
535 }
536
537 static int rna_Property_unit_get(PointerRNA *ptr)
538 {
539         PropertyRNA *prop = (PropertyRNA *)ptr->data;
540         rna_idproperty_check(&prop, ptr);
541         return RNA_SUBTYPE_UNIT(prop->subtype);
542 }
543
544 static int rna_Property_icon_get(PointerRNA *ptr)
545 {
546         PropertyRNA *prop = (PropertyRNA *)ptr->data;
547         rna_idproperty_check(&prop, ptr);
548         return prop->icon;
549 }
550
551 static int rna_Property_readonly_get(PointerRNA *ptr)
552 {
553         PropertyRNA *prop = (PropertyRNA *)ptr->data;
554
555         /* don't use this because it will call functions that check the internal
556          * data for introspection we only need to know if it can be edited so the
557          * flag is better for this */
558 /*      return RNA_property_editable(ptr, prop); */
559         return (prop->flag & PROP_EDITABLE) == 0;
560 }
561
562 static int rna_Property_animatable_get(PointerRNA *ptr)
563 {
564         PropertyRNA *prop = (PropertyRNA *)ptr->data;
565
566         return (prop->flag & PROP_ANIMATABLE) != 0;
567 }
568
569 static int rna_Property_overridable_get(PointerRNA *ptr)
570 {
571         PropertyRNA *prop = (PropertyRNA *)ptr->data;
572
573         return (prop->flag & PROP_OVERRIDABLE_STATIC) != 0;
574 }
575
576 static int rna_Property_use_output_get(PointerRNA *ptr)
577 {
578         PropertyRNA *prop = (PropertyRNA *)ptr->data;
579         return (prop->flag_parameter & PARM_OUTPUT) != 0;
580 }
581
582 static int rna_Property_is_required_get(PointerRNA *ptr)
583 {
584         PropertyRNA *prop = (PropertyRNA *)ptr->data;
585         return (prop->flag_parameter & PARM_REQUIRED) != 0;
586 }
587
588 static int rna_Property_is_argument_optional_get(PointerRNA *ptr)
589 {
590         PropertyRNA *prop = (PropertyRNA *)ptr->data;
591         return (prop->flag_parameter & PARM_PYFUNC_OPTIONAL) != 0;
592 }
593
594 static int rna_Property_is_never_none_get(PointerRNA *ptr)
595 {
596         PropertyRNA *prop = (PropertyRNA *)ptr->data;
597         return (prop->flag & PROP_NEVER_NULL) != 0;
598 }
599
600 static int rna_Property_is_hidden_get(PointerRNA *ptr)
601 {
602         PropertyRNA *prop = (PropertyRNA *)ptr->data;
603         return (prop->flag & PROP_HIDDEN) != 0;
604 }
605
606 static int rna_Property_is_skip_save_get(PointerRNA *ptr)
607 {
608         PropertyRNA *prop = (PropertyRNA *)ptr->data;
609         return (prop->flag & PROP_SKIP_SAVE) != 0;
610 }
611
612
613 static int rna_Property_is_enum_flag_get(PointerRNA *ptr)
614 {
615         PropertyRNA *prop = (PropertyRNA *)ptr->data;
616         return (prop->flag & PROP_ENUM_FLAG) != 0;
617 }
618
619 static int rna_Property_is_library_editable_flag_get(PointerRNA *ptr)
620 {
621         PropertyRNA *prop = (PropertyRNA *)ptr->data;
622         return (prop->flag & PROP_LIB_EXCEPTION) != 0;
623 }
624
625 static int rna_Property_tags_get(PointerRNA *ptr)
626 {
627         return RNA_property_tags(ptr->data);
628 }
629
630 static const EnumPropertyItem *rna_Property_tags_itemf(
631         bContext *UNUSED(C), PointerRNA *ptr,
632         PropertyRNA *UNUSED(prop), bool *r_free)
633 {
634         PropertyRNA *this_prop = (PropertyRNA *)ptr->data;
635         const StructRNA *srna = RNA_property_pointer_type(ptr, this_prop);
636         EnumPropertyItem *prop_tags;
637         EnumPropertyItem tmp = {0, "", 0, "", ""};
638         int totitem = 0;
639
640         for (const EnumPropertyItem *struct_tags = RNA_struct_property_tag_defines(srna);
641              struct_tags->identifier;
642              struct_tags++)
643         {
644                 memcpy(&tmp, struct_tags, sizeof(tmp));
645                 RNA_enum_item_add(&prop_tags, &totitem, &tmp);
646         }
647         RNA_enum_item_end(&prop_tags, &totitem);
648         *r_free = true;
649
650         return prop_tags;
651 }
652
653 static int rna_Property_array_length_get(PointerRNA *ptr)
654 {
655         PropertyRNA *prop = (PropertyRNA *)ptr->data;
656         rna_idproperty_check(&prop, ptr);
657         return prop->totarraylength;
658 }
659
660 static void rna_Property_array_dimensions_get(PointerRNA *ptr, int dimensions[RNA_MAX_ARRAY_DIMENSION])
661 {
662         PropertyRNA *prop = (PropertyRNA *)ptr->data;
663         rna_idproperty_check(&prop, ptr);
664
665         if (prop->arraydimension > 1) {
666                 for (int i = RNA_MAX_ARRAY_DIMENSION; i--; ) {
667                         dimensions[i] = (i >= prop->arraydimension) ? 0 : prop->arraylength[i];
668                 }
669         }
670         else {
671                 memset(dimensions, 0, sizeof(*dimensions) * RNA_MAX_ARRAY_DIMENSION);
672                 dimensions[0] = prop->totarraylength;
673         }
674 }
675
676 static int rna_Property_is_registered_get(PointerRNA *ptr)
677 {
678         PropertyRNA *prop = (PropertyRNA *)ptr->data;
679         return (prop->flag & PROP_REGISTER) != 0;
680 }
681
682 static int rna_Property_is_registered_optional_get(PointerRNA *ptr)
683 {
684         PropertyRNA *prop = (PropertyRNA *)ptr->data;
685         return (prop->flag & PROP_REGISTER_OPTIONAL) != 0;
686 }
687
688 static int rna_Property_is_runtime_get(PointerRNA *ptr)
689 {
690         PropertyRNA *prop = (PropertyRNA *)ptr->data;
691         return (prop->flag_internal & PROP_INTERN_RUNTIME) != 0;
692 }
693
694
695 static int rna_BoolProperty_default_get(PointerRNA *ptr)
696 {
697         PropertyRNA *prop = (PropertyRNA *)ptr->data;
698         rna_idproperty_check(&prop, ptr);
699         return ((BoolPropertyRNA *)prop)->defaultvalue;
700 }
701
702 static int rna_IntProperty_default_get(PointerRNA *ptr)
703 {
704         PropertyRNA *prop = (PropertyRNA *)ptr->data;
705         rna_idproperty_check(&prop, ptr);
706         return ((IntPropertyRNA *)prop)->defaultvalue;
707 }
708 /* int/float/bool */
709 static int rna_NumberProperty_default_array_get_length(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION])
710 {
711         PropertyRNA *prop = (PropertyRNA *)ptr->data;
712         rna_idproperty_check(&prop, ptr);
713
714         length[0] = prop->totarraylength;
715
716         return length[0];
717 }
718 static int rna_NumberProperty_is_array_get(PointerRNA *ptr)
719 {
720         PropertyRNA *prop = (PropertyRNA *)ptr->data;
721
722         return RNA_property_array_check(prop);
723 }
724
725 static void rna_IntProperty_default_array_get(PointerRNA *ptr, int *values)
726 {
727         PropertyRNA *prop = (PropertyRNA *)ptr->data;
728         IntPropertyRNA *nprop = (IntPropertyRNA *)prop;
729         rna_idproperty_check(&prop, ptr);
730
731         if (nprop->defaultarray) {
732                 memcpy(values, nprop->defaultarray, prop->totarraylength * sizeof(int));
733         }
734         else {
735                 int i;
736                 for (i = 0; i < prop->totarraylength; i++)
737                         values[i] = nprop->defaultvalue;
738         }
739 }
740 static void rna_BoolProperty_default_array_get(PointerRNA *ptr, int *values)
741 {
742         PropertyRNA *prop = (PropertyRNA *)ptr->data;
743         BoolPropertyRNA *nprop = (BoolPropertyRNA *)prop;
744         rna_idproperty_check(&prop, ptr);
745
746         if (nprop->defaultarray) {
747                 memcpy(values, nprop->defaultarray, prop->totarraylength * sizeof(int));
748         }
749         else {
750                 int i;
751                 for (i = 0; i < prop->totarraylength; i++)
752                         values[i] = nprop->defaultvalue;
753         }
754 }
755 static void rna_FloatProperty_default_array_get(PointerRNA *ptr, float *values)
756 {
757         PropertyRNA *prop = (PropertyRNA *)ptr->data;
758         FloatPropertyRNA *nprop = (FloatPropertyRNA *)prop;
759         rna_idproperty_check(&prop, ptr);
760
761         if (nprop->defaultarray) {
762                 memcpy(values, nprop->defaultarray, prop->totarraylength * sizeof(float));
763         }
764         else {
765                 int i;
766                 for (i = 0; i < prop->totarraylength; i++)
767                         values[i] = nprop->defaultvalue;
768         }
769 }
770
771 static int rna_IntProperty_hard_min_get(PointerRNA *ptr)
772 {
773         PropertyRNA *prop = (PropertyRNA *)ptr->data;
774         rna_idproperty_check(&prop, ptr);
775         return ((IntPropertyRNA *)prop)->hardmin;
776 }
777
778 static int rna_IntProperty_hard_max_get(PointerRNA *ptr)
779 {
780         PropertyRNA *prop = (PropertyRNA *)ptr->data;
781         rna_idproperty_check(&prop, ptr);
782         return ((IntPropertyRNA *)prop)->hardmax;
783 }
784
785 static int rna_IntProperty_soft_min_get(PointerRNA *ptr)
786 {
787         PropertyRNA *prop = (PropertyRNA *)ptr->data;
788         rna_idproperty_check(&prop, ptr);
789         return ((IntPropertyRNA *)prop)->softmin;
790 }
791
792 static int rna_IntProperty_soft_max_get(PointerRNA *ptr)
793 {
794         PropertyRNA *prop = (PropertyRNA *)ptr->data;
795         rna_idproperty_check(&prop, ptr);
796         return ((IntPropertyRNA *)prop)->softmax;
797 }
798
799 static int rna_IntProperty_step_get(PointerRNA *ptr)
800 {
801         PropertyRNA *prop = (PropertyRNA *)ptr->data;
802         rna_idproperty_check(&prop, ptr);
803         return ((IntPropertyRNA *)prop)->step;
804 }
805
806 static float rna_FloatProperty_default_get(PointerRNA *ptr)
807 {
808         PropertyRNA *prop = (PropertyRNA *)ptr->data;
809         rna_idproperty_check(&prop, ptr);
810         return ((FloatPropertyRNA *)prop)->defaultvalue;
811 }
812 static float rna_FloatProperty_hard_min_get(PointerRNA *ptr)
813 {
814         PropertyRNA *prop = (PropertyRNA *)ptr->data;
815         rna_idproperty_check(&prop, ptr);
816         return ((FloatPropertyRNA *)prop)->hardmin;
817 }
818
819 static float rna_FloatProperty_hard_max_get(PointerRNA *ptr)
820 {
821         PropertyRNA *prop = (PropertyRNA *)ptr->data;
822         rna_idproperty_check(&prop, ptr);
823         return ((FloatPropertyRNA *)prop)->hardmax;
824 }
825
826 static float rna_FloatProperty_soft_min_get(PointerRNA *ptr)
827 {
828         PropertyRNA *prop = (PropertyRNA *)ptr->data;
829         rna_idproperty_check(&prop, ptr);
830         return ((FloatPropertyRNA *)prop)->softmin;
831 }
832
833 static float rna_FloatProperty_soft_max_get(PointerRNA *ptr)
834 {
835         PropertyRNA *prop = (PropertyRNA *)ptr->data;
836         rna_idproperty_check(&prop, ptr);
837         return ((FloatPropertyRNA *)prop)->softmax;
838 }
839
840 static float rna_FloatProperty_step_get(PointerRNA *ptr)
841 {
842         PropertyRNA *prop = (PropertyRNA *)ptr->data;
843         rna_idproperty_check(&prop, ptr);
844         return ((FloatPropertyRNA *)prop)->step;
845 }
846
847 static int rna_FloatProperty_precision_get(PointerRNA *ptr)
848 {
849         PropertyRNA *prop = (PropertyRNA *)ptr->data;
850         rna_idproperty_check(&prop, ptr);
851         return ((FloatPropertyRNA *)prop)->precision;
852 }
853
854 static void rna_StringProperty_default_get(PointerRNA *ptr, char *value)
855 {
856         PropertyRNA *prop = (PropertyRNA *)ptr->data;
857         rna_idproperty_check(&prop, ptr);
858         strcpy(value, ((StringPropertyRNA *)prop)->defaultvalue);
859 }
860 static int rna_StringProperty_default_length(PointerRNA *ptr)
861 {
862         PropertyRNA *prop = (PropertyRNA *)ptr->data;
863         rna_idproperty_check(&prop, ptr);
864         return strlen(((StringPropertyRNA *)prop)->defaultvalue);
865 }
866
867 static int rna_StringProperty_max_length_get(PointerRNA *ptr)
868 {
869         PropertyRNA *prop = (PropertyRNA *)ptr->data;
870         rna_idproperty_check(&prop, ptr);
871         return ((StringPropertyRNA *)prop)->maxlength;
872 }
873
874 static const EnumPropertyItem *rna_EnumProperty_default_itemf(bContext *C, PointerRNA *ptr,
875                                                         PropertyRNA *prop_parent, bool *r_free)
876 {
877         PropertyRNA *prop = (PropertyRNA *)ptr->data;
878         EnumPropertyRNA *eprop;
879
880         rna_idproperty_check(&prop, ptr);
881         eprop = (EnumPropertyRNA *)prop;
882
883         /* incompatible default attributes */
884         if ((prop_parent->flag & PROP_ENUM_FLAG) != (prop->flag & PROP_ENUM_FLAG)) {
885                 return DummyRNA_NULL_items;
886         }
887
888         if ((eprop->itemf == NULL) ||
889             (eprop->itemf == rna_EnumProperty_default_itemf) ||
890             (ptr->type == &RNA_EnumProperty) ||
891             (C == NULL))
892         {
893                 if (eprop->item) {
894                         return eprop->item;
895                 }
896         }
897
898         return eprop->itemf(C, ptr, prop, r_free);
899 }
900
901 /* XXX - not sure this is needed? */
902 static int rna_EnumProperty_default_get(PointerRNA *ptr)
903 {
904         PropertyRNA *prop = (PropertyRNA *)ptr->data;
905         rna_idproperty_check(&prop, ptr);
906         return ((EnumPropertyRNA *)prop)->defaultvalue;
907 }
908
909 static int rna_enum_check_separator(CollectionPropertyIterator *UNUSED(iter), void *data)
910 {
911         EnumPropertyItem *item = (EnumPropertyItem *)data;
912
913         return (item->identifier[0] == 0);
914 }
915
916 static void rna_EnumProperty_items_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
917 {
918         PropertyRNA *prop = (PropertyRNA *)ptr->data;
919         /* EnumPropertyRNA *eprop;  *//* UNUSED */
920         const EnumPropertyItem *item = NULL;
921         int totitem;
922         bool free;
923         
924         rna_idproperty_check(&prop, ptr);
925         /* eprop = (EnumPropertyRNA *)prop; */
926         
927         RNA_property_enum_items_ex(
928                     NULL, ptr, prop, STREQ(iter->prop->identifier, "enum_items_static"), &item, &totitem, &free);
929         rna_iterator_array_begin(iter, (void *)item, sizeof(EnumPropertyItem), totitem, free, rna_enum_check_separator);
930 }
931
932 static void rna_EnumPropertyItem_identifier_get(PointerRNA *ptr, char *value)
933 {
934         strcpy(value, ((EnumPropertyItem *)ptr->data)->identifier);
935 }
936
937 static int rna_EnumPropertyItem_identifier_length(PointerRNA *ptr)
938 {
939         return strlen(((EnumPropertyItem *)ptr->data)->identifier);
940 }
941
942 static void rna_EnumPropertyItem_name_get(PointerRNA *ptr, char *value)
943 {
944         strcpy(value, ((EnumPropertyItem *)ptr->data)->name);
945 }
946
947 static int rna_EnumPropertyItem_name_length(PointerRNA *ptr)
948 {
949         return strlen(((EnumPropertyItem *)ptr->data)->name);
950 }
951
952 static void rna_EnumPropertyItem_description_get(PointerRNA *ptr, char *value)
953 {
954         EnumPropertyItem *eprop = (EnumPropertyItem *)ptr->data;
955
956         if (eprop->description)
957                 strcpy(value, eprop->description);
958         else
959                 value[0] = '\0';
960 }
961
962 static int rna_EnumPropertyItem_description_length(PointerRNA *ptr)
963 {
964         EnumPropertyItem *eprop = (EnumPropertyItem *)ptr->data;
965
966         if (eprop->description)
967                 return strlen(eprop->description);
968         else
969                 return 0;
970 }
971
972 static int rna_EnumPropertyItem_value_get(PointerRNA *ptr)
973 {
974         return ((EnumPropertyItem *)ptr->data)->value;
975 }
976
977 static int rna_EnumPropertyItem_icon_get(PointerRNA *ptr)
978 {
979         return ((EnumPropertyItem *)ptr->data)->icon;
980 }
981
982 static PointerRNA rna_PointerProperty_fixed_type_get(PointerRNA *ptr)
983 {
984         PropertyRNA *prop = (PropertyRNA *)ptr->data;
985         rna_idproperty_check(&prop, ptr);
986         return rna_pointer_inherit_refine(ptr, &RNA_Struct, ((PointerPropertyRNA *)prop)->type);
987 }
988
989 static PointerRNA rna_CollectionProperty_fixed_type_get(PointerRNA *ptr)
990 {
991         PropertyRNA *prop = (PropertyRNA *)ptr->data;
992         rna_idproperty_check(&prop, ptr);
993         return rna_pointer_inherit_refine(ptr, &RNA_Struct, ((CollectionPropertyRNA *)prop)->item_type);
994 }
995
996 /* Function */
997
998 static void rna_Function_identifier_get(PointerRNA *ptr, char *value)
999 {
1000         strcpy(value, ((FunctionRNA *)ptr->data)->identifier);
1001 }
1002
1003 static int rna_Function_identifier_length(PointerRNA *ptr)
1004 {
1005         return strlen(((FunctionRNA *)ptr->data)->identifier);
1006 }
1007
1008 static void rna_Function_description_get(PointerRNA *ptr, char *value)
1009 {
1010         strcpy(value, ((FunctionRNA *)ptr->data)->description);
1011 }
1012
1013 static int rna_Function_description_length(PointerRNA *ptr)
1014 {
1015         return strlen(((FunctionRNA *)ptr->data)->description);
1016 }
1017
1018 static void rna_Function_parameters_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
1019 {
1020         rna_iterator_listbase_begin(iter, &((FunctionRNA *)ptr->data)->cont.properties, rna_property_builtin);
1021 }
1022
1023 static int rna_Function_registered_get(PointerRNA *ptr)
1024 {
1025         FunctionRNA *func = (FunctionRNA *)ptr->data;
1026         return 0 != (func->flag & FUNC_REGISTER);
1027 }
1028
1029 static int rna_Function_registered_optional_get(PointerRNA *ptr)
1030 {
1031         FunctionRNA *func = (FunctionRNA *)ptr->data;
1032         return 0 != (func->flag & (FUNC_REGISTER_OPTIONAL & ~FUNC_REGISTER));
1033 }
1034
1035 static int rna_Function_no_self_get(PointerRNA *ptr)
1036 {
1037         FunctionRNA *func = (FunctionRNA *)ptr->data;
1038         return !(func->flag & FUNC_NO_SELF);
1039 }
1040
1041 static int rna_Function_use_self_type_get(PointerRNA *ptr)
1042 {
1043         FunctionRNA *func = (FunctionRNA *)ptr->data;
1044         return 0 != (func->flag & FUNC_USE_SELF_TYPE);
1045 }
1046
1047 /* Blender RNA */
1048
1049 static int rna_struct_is_publc(CollectionPropertyIterator *UNUSED(iter), void *data)
1050 {
1051         StructRNA *srna = data;
1052
1053         return !(srna->flag & STRUCT_PUBLIC_NAMESPACE);
1054 }
1055
1056
1057 static void rna_BlenderRNA_structs_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
1058 {
1059         BlenderRNA *brna = ptr->data;
1060         rna_iterator_listbase_begin(iter, &brna->structs, rna_struct_is_publc);
1061 }
1062
1063 /* optional, for faster lookups */
1064 static int rna_BlenderRNA_structs_length(PointerRNA *ptr)
1065 {
1066         BlenderRNA *brna = ptr->data;
1067         BLI_assert(brna->structs_len == BLI_listbase_count(&brna->structs));
1068         return brna->structs_len;
1069 }
1070 static int rna_BlenderRNA_structs_lookup_int(PointerRNA *ptr, int index, PointerRNA *r_ptr)
1071 {
1072         BlenderRNA *brna = ptr->data;
1073         StructRNA *srna = index < brna->structs_len ? BLI_findlink(&brna->structs, index) : NULL;
1074         if (srna != NULL) {
1075                 RNA_pointer_create(NULL, &RNA_Struct, srna, r_ptr);
1076                 return true;
1077         }
1078         else {
1079                 return false;
1080         }
1081 }
1082 static int rna_BlenderRNA_structs_lookup_string(PointerRNA *ptr, const char *key, PointerRNA *r_ptr)
1083 {
1084         BlenderRNA *brna = ptr->data;
1085         StructRNA *srna = BLI_ghash_lookup(brna->structs_map, (void *)key);
1086         if (srna != NULL) {
1087                 RNA_pointer_create(NULL, &RNA_Struct, srna, r_ptr);
1088                 return true;
1089         }
1090
1091         return false;
1092 }
1093
1094 /* Default override (and compare) callbacks. */
1095
1096 /* Used for both Pointer and Collection properties. */
1097 static int rna_property_override_diff_propptr(
1098         PointerRNA *propptr_a, PointerRNA *propptr_b, eRNACompareMode mode, const bool no_ownership,
1099         IDOverrideStatic *override, const char *rna_path, const int flags, bool *r_override_changed)
1100 {
1101         const bool do_create = override != NULL && (flags & RNA_OVERRIDE_COMPARE_CREATE) != 0 && rna_path != NULL;
1102
1103         bool is_id = false;
1104         bool is_type_null = false;
1105
1106         /* Beware, PointerRNA_NULL has no type and is considered a 'blank page'! */
1107         if (propptr_a->type == NULL) {
1108                 if (propptr_b->type == NULL) {
1109                         if (r_override_changed) {
1110                                 *r_override_changed = false;
1111                         }
1112                         return 0;
1113                 }
1114                 is_id = RNA_struct_is_ID(propptr_b->type);
1115                 is_type_null = true;
1116         }
1117         else {
1118                 is_id = RNA_struct_is_ID(propptr_a->type);
1119                 is_type_null = (propptr_b->type == NULL);
1120         }
1121
1122         if (is_id) {
1123                 BLI_assert(propptr_a->data == propptr_a->id.data && propptr_b->data == propptr_b->id.data);
1124                 BLI_assert(no_ownership);  /* For now, once we deal with nodetrees we'll want to get rid of that one. */
1125         }
1126
1127         if (override) {
1128                 if (no_ownership /* || is_id */ || is_type_null) {
1129                         /* In case this pointer prop does not own its data (or one is NULL), do not compare structs!
1130                          * This is a quite safe path to infinite loop, among other nasty issues.
1131                          * Instead, just compare pointers themselves. */
1132                         const int comp = (propptr_a->data != propptr_b->data);
1133
1134                         if (do_create && comp != 0) {
1135                                 bool created = false;
1136                                 IDOverrideStaticProperty *op = BKE_override_static_property_get(override, rna_path, &created);
1137
1138                                 if (op != NULL && created) {  /* If not yet overridden... */
1139                                         BKE_override_static_property_operation_get(
1140                                                     op, IDOVERRIDESTATIC_OP_REPLACE, NULL, NULL, -1, -1, true, NULL, NULL);
1141                                         if (r_override_changed) {
1142                                                 *r_override_changed = created;
1143                                         }
1144                                 }
1145                         }
1146
1147                         return comp;
1148                 }
1149                 else {
1150                         eRNAOverrideMatchResult report_flags = 0;
1151                         const bool match = RNA_struct_override_matches(propptr_a, propptr_b, rna_path, override, flags, &report_flags);
1152                         if (r_override_changed && (report_flags & RNA_OVERRIDE_MATCH_RESULT_CREATED) != 0) {
1153                                 *r_override_changed = true;
1154                         }
1155                         return !match;
1156                 }
1157         }
1158         else {
1159                 return !RNA_struct_equals(propptr_a, propptr_b, mode);
1160         }
1161 }
1162
1163 static char *rna_path_collection_prop_item_extend(const char *rna_path_prop, const char *item_name)
1164 {
1165         const size_t esc_item_name_len = strlen(item_name) * 2;
1166         char *esc_item_name = alloca(sizeof(*esc_item_name) * esc_item_name_len);
1167         BLI_strescape(esc_item_name, item_name, esc_item_name_len);
1168         return BLI_sprintfN("%s[\"%s\"]", rna_path_prop, esc_item_name);
1169 }
1170
1171 int rna_property_override_diff_default(PointerRNA *ptr_a, PointerRNA *ptr_b,
1172         PropertyRNA *prop_a, PropertyRNA *prop_b,
1173         const int len_a, const int len_b,
1174         const int mode,
1175         IDOverrideStatic *override, const char *rna_path,
1176         const int flags, bool *r_override_changed)
1177 {
1178         BLI_assert(len_a == len_b);
1179
1180         /* Note: at this point, we are sure that when len_a is zero, we are not handling an (empty) array. */
1181
1182         const bool do_create = override != NULL && (flags & RNA_OVERRIDE_COMPARE_CREATE) != 0 && rna_path != NULL;
1183
1184         switch (RNA_property_type(prop_a)) {
1185                 case PROP_BOOLEAN:
1186                 {
1187                         if (len_a) {
1188                                 int array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
1189                                 int *array_a, *array_b;
1190
1191                                 array_a = (len_a > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(int) * len_a, "RNA equals") : array_stack_a;
1192                                 array_b = (len_b > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(int) * len_b, "RNA equals") : array_stack_b;
1193
1194                                 RNA_property_boolean_get_array(ptr_a, prop_a, array_a);
1195                                 RNA_property_boolean_get_array(ptr_b, prop_b, array_b);
1196
1197                                 const int comp = memcmp(array_a, array_b, sizeof(int) * len_a);
1198
1199                                 if (do_create && comp != 0) {
1200                                         /* XXX TODO this will have to be refined to handle array items */
1201                                         bool created = false;
1202                                         IDOverrideStaticProperty *op = BKE_override_static_property_get(override, rna_path, &created);
1203
1204                                         if (op != NULL && created) {
1205                                                 BKE_override_static_property_operation_get(
1206                                                             op, IDOVERRIDESTATIC_OP_REPLACE, NULL, NULL, -1, -1, true, NULL, NULL);
1207                                                 if (r_override_changed) {
1208                                                         *r_override_changed = created;
1209                                                 }
1210                                         }
1211                                         else {
1212                                                 /* Already overriden prop, we'll have to check arrays items etc. */
1213                                         }
1214                                 }
1215
1216                                 if (array_a != array_stack_a) MEM_freeN(array_a);
1217                                 if (array_b != array_stack_b) MEM_freeN(array_b);
1218
1219                                 return comp;
1220                         }
1221                         else {
1222                                 const int value_a = RNA_property_boolean_get(ptr_a, prop_a);
1223                                 const int value_b = RNA_property_boolean_get(ptr_b, prop_b);
1224                                 const int comp = (value_a < value_b) ? -1 : (value_a > value_b) ? 1 : 0;
1225
1226                                 if (do_create && comp != 0) {
1227                                         bool created = false;
1228                                         IDOverrideStaticProperty *op = BKE_override_static_property_get(override, rna_path, &created);
1229
1230                                         if (op != NULL && created) {  /* If not yet overridden... */
1231                                                 BKE_override_static_property_operation_get(
1232                                                             op, IDOVERRIDESTATIC_OP_REPLACE, NULL, NULL, -1, -1, true, NULL, NULL);
1233                                                 if (r_override_changed) {
1234                                                         *r_override_changed = created;
1235                                                 }
1236                                         }
1237                                 }
1238
1239                                 return comp;
1240                         }
1241                 }
1242
1243                 case PROP_INT:
1244                 {
1245                         if (len_a) {
1246                                 int array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
1247                                 int *array_a, *array_b;
1248
1249                                 array_a = (len_a > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(int) * len_a, "RNA equals") : array_stack_a;
1250                                 array_b = (len_b > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(int) * len_b, "RNA equals") : array_stack_b;
1251
1252                                 RNA_property_int_get_array(ptr_a, prop_a, array_a);
1253                                 RNA_property_int_get_array(ptr_b, prop_b, array_b);
1254
1255                                 const int comp = memcmp(array_a, array_b, sizeof(int) * len_a);
1256
1257                                 if (do_create && comp != 0) {
1258                                         /* XXX TODO this will have to be refined to handle array items */
1259                                         bool created = false;
1260                                         IDOverrideStaticProperty *op = BKE_override_static_property_get(override, rna_path, &created);
1261
1262                                         if (op != NULL && created) {
1263                                                 BKE_override_static_property_operation_get(
1264                                                             op, IDOVERRIDESTATIC_OP_REPLACE, NULL, NULL, -1, -1, true, NULL, NULL);
1265                                                 if (r_override_changed) {
1266                                                         *r_override_changed = created;
1267                                                 }
1268                                         }
1269                                         else {
1270                                                 /* Already overriden prop, we'll have to check arrays items etc. */
1271                                         }
1272                                 }
1273
1274                                 if (array_a != array_stack_a) MEM_freeN(array_a);
1275                                 if (array_b != array_stack_b) MEM_freeN(array_b);
1276
1277                                 return comp;
1278                         }
1279                         else {
1280                                 const int value_a = RNA_property_int_get(ptr_a, prop_a);
1281                                 const int value_b = RNA_property_int_get(ptr_b, prop_b);
1282                                 const int comp = (value_a < value_b) ? -1 : (value_a > value_b) ? 1 : 0;
1283
1284                                 if (do_create && comp != 0) {
1285                                         bool created = false;
1286                                         IDOverrideStaticProperty *op = BKE_override_static_property_get(override, rna_path, &created);
1287
1288                                         if (op != NULL && created) {  /* If not yet overridden... */
1289                                                 BKE_override_static_property_operation_get(
1290                                                             op, IDOVERRIDESTATIC_OP_REPLACE, NULL, NULL, -1, -1, true, NULL, NULL);
1291                                                 if (r_override_changed) {
1292                                                         *r_override_changed = created;
1293                                                 }
1294                                         }
1295                                 }
1296
1297                                 return comp;
1298                         }
1299                 }
1300
1301                 case PROP_FLOAT:
1302                 {
1303                         const bool is_proportional = (prop_a->flag & PROP_PROPORTIONAL) != 0;
1304                         if (len_a) {
1305                                 float array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
1306                                 float *array_a, *array_b;
1307
1308                                 array_a = (len_a > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(float) * len_a, "RNA equals") : array_stack_a;
1309                                 array_b = (len_b > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(float) * len_b, "RNA equals") : array_stack_b;
1310
1311                                 RNA_property_float_get_array(ptr_a, prop_a, array_a);
1312                                 RNA_property_float_get_array(ptr_b, prop_b, array_b);
1313
1314                                 const int comp = memcmp(array_a, array_b, sizeof(float) * len_a);
1315
1316                                 if (do_create && comp != 0) {
1317                                         /* XXX TODO this will have to be refined to handle array items */
1318                                         bool created = false;
1319                                         IDOverrideStaticProperty *op = BKE_override_static_property_get(override, rna_path, &created);
1320
1321                                         if (op != NULL && created) {
1322                                                 BKE_override_static_property_operation_get(
1323                                                             op, is_proportional ? IDOVERRIDESTATIC_OP_MULTIPLY : IDOVERRIDESTATIC_OP_REPLACE,
1324                                                             NULL, NULL, -1, -1, true, NULL, NULL);
1325                                                 if (r_override_changed) {
1326                                                         *r_override_changed = created;
1327                                                 }
1328                                         }
1329                                         else {
1330                                                 /* Already overriden prop, we'll have to check arrays items etc. */
1331                                         }
1332                                 }
1333
1334                                 if (array_a != array_stack_a) MEM_freeN(array_a);
1335                                 if (array_b != array_stack_b) MEM_freeN(array_b);
1336
1337                                 return comp;
1338                         }
1339                         else {
1340                                 const float value_a = RNA_property_float_get(ptr_a, prop_a);
1341                                 const float value_b = RNA_property_float_get(ptr_b, prop_b);
1342                                 const int comp = (value_a < value_b) ? -1 : (value_a > value_b) ? 1 : 0;
1343
1344                                 if (do_create && comp != 0) {
1345                                         bool created = false;
1346                                         IDOverrideStaticProperty *op = BKE_override_static_property_get(override, rna_path, &created);
1347
1348                                         if (op != NULL && created) {  /* If not yet overridden... */
1349                                                 BKE_override_static_property_operation_get(
1350                                                             op, is_proportional ? IDOVERRIDESTATIC_OP_MULTIPLY : IDOVERRIDESTATIC_OP_REPLACE,
1351                                                             NULL, NULL, -1, -1, true, NULL, NULL);
1352                                                 if (r_override_changed) {
1353                                                         *r_override_changed = created;
1354                                                 }
1355                                         }
1356                                 }
1357
1358                                 return comp ;
1359                         }
1360                 }
1361
1362                 case PROP_ENUM:
1363                 {
1364                         const int value_a = RNA_property_enum_get(ptr_a, prop_a);
1365                         const int value_b = RNA_property_enum_get(ptr_b, prop_b);
1366                         const int comp = value_a != value_b;
1367
1368                         if (do_create && comp != 0) {
1369                                 bool created = false;
1370                                 IDOverrideStaticProperty *op = BKE_override_static_property_get(override, rna_path, &created);
1371
1372                                 if (op != NULL && created) {  /* If not yet overridden... */
1373                                         BKE_override_static_property_operation_get(
1374                                                     op, IDOVERRIDESTATIC_OP_REPLACE, NULL, NULL, -1, -1, true, NULL, NULL);
1375                                         if (r_override_changed) {
1376                                                 *r_override_changed = created;
1377                                         }
1378                                 }
1379                         }
1380
1381                         return comp;
1382                 }
1383
1384                 case PROP_STRING:
1385                 {
1386                         char fixed_a[128], fixed_b[128];
1387                         int len_str_a, len_str_b;
1388                         char *value_a = RNA_property_string_get_alloc(ptr_a, prop_a, fixed_a, sizeof(fixed_a), &len_str_a);
1389                         char *value_b = RNA_property_string_get_alloc(ptr_b, prop_b, fixed_b, sizeof(fixed_b), &len_str_b);
1390                         const int comp = strcmp(value_a, value_b);
1391
1392                         if (do_create && comp != 0) {
1393                                 bool created = false;
1394                                 IDOverrideStaticProperty *op = BKE_override_static_property_get(override, rna_path, &created);
1395
1396                                 if (op != NULL && created) {  /* If not yet overridden... */
1397                                         BKE_override_static_property_operation_get(
1398                                                     op, IDOVERRIDESTATIC_OP_REPLACE, NULL, NULL, -1, -1, true, NULL, NULL);
1399                                         if (r_override_changed) {
1400                                                 *r_override_changed = created;
1401                                         }
1402                                 }
1403                         }
1404
1405                         if (value_a != fixed_a) MEM_freeN(value_a);
1406                         if (value_b != fixed_b) MEM_freeN(value_b);
1407
1408                         return comp;
1409                 }
1410
1411                 case PROP_POINTER:
1412                 {
1413                         if (STREQ(RNA_property_identifier(prop_a), "rna_type")) {
1414                                 /* Dummy 'pass' answer, this is a meta-data and must be ignored... */
1415                                 return 0;
1416                         }
1417                         else {
1418                                 PointerRNA propptr_a = RNA_property_pointer_get(ptr_a, prop_a);
1419                                 PointerRNA propptr_b = RNA_property_pointer_get(ptr_b, prop_b);
1420                                 const bool no_ownership = (RNA_property_flag(prop_a) & PROP_PTR_NO_OWNERSHIP) != 0;
1421                                 return rna_property_override_diff_propptr(
1422                                             &propptr_a, &propptr_b, mode, no_ownership,
1423                                             override, rna_path, flags, r_override_changed);
1424                         }
1425                         break;
1426                 }
1427
1428                 case PROP_COLLECTION:
1429                 {
1430                         bool equals = true;
1431                         int idx = 0;
1432
1433                         CollectionPropertyIterator iter_a, iter_b;
1434                         RNA_property_collection_begin(ptr_a, prop_a, &iter_a);
1435                         RNA_property_collection_begin(ptr_b, prop_b, &iter_b);
1436
1437                         for (; iter_a.valid && iter_b.valid;
1438                              RNA_property_collection_next(&iter_a), RNA_property_collection_next(&iter_b), idx++)
1439                         {
1440                                 char *extended_rna_path = NULL;
1441
1442                                 if (iter_a.ptr.type != iter_b.ptr.type) {
1443                                         /* nothing we can do (for until we support adding/removing from collections), skip it. */
1444                                         equals = false;
1445                                         continue;
1446                                 }
1447                                 else if (iter_a.ptr.type == NULL) {
1448                                         /* NULL RNA pointer... */
1449                                         BLI_assert(iter_a.ptr.data == NULL);
1450                                         BLI_assert(iter_b.ptr.data == NULL);
1451                                         continue;
1452                                 }
1453
1454                                 PropertyRNA *propname = RNA_struct_name_property(iter_a.ptr.type);
1455                                 char propname_buff_a[256], propname_buff_b[256];
1456                                 char *propname_a = NULL, *propname_b = NULL;
1457
1458                                 if (propname != NULL) {
1459                                         propname_a = RNA_property_string_get_alloc(&iter_a.ptr, propname, propname_buff_a, sizeof(propname_buff_a), NULL);
1460                                         propname_b = RNA_property_string_get_alloc(&iter_b.ptr, propname, propname_buff_b, sizeof(propname_buff_b), NULL);
1461                                 }
1462                                 /* There may be a propname defined in some cases, while no actual name set
1463                                  * (e.g. happens with point cache), in that case too we want to fall back to index. */
1464                                 if ((propname_a != NULL && propname_a[0] != '\0') || (propname_b != NULL && propname_b[0] != '\0')) {
1465                                         if (!STREQ(propname_a, propname_b)) {
1466                                                 /* Same as above, not same structs. */
1467                                                 equals = false;
1468                                         }
1469                                         else if (rna_path) {
1470                                                 extended_rna_path = rna_path_collection_prop_item_extend(rna_path, propname_a);
1471                                         }
1472                                 }
1473                                 else {  /* Based on index... */
1474                                         if (rna_path) {
1475                                                 extended_rna_path = BLI_sprintfN("%s[%d]", rna_path, idx);
1476                                         }
1477                                 }
1478
1479                                 if (equals || do_create) {
1480                                         const bool no_ownership = (RNA_property_flag(prop_a) & PROP_PTR_NO_OWNERSHIP) != 0;
1481                                         const int eq = rna_property_override_diff_propptr(
1482                                                       &iter_a.ptr, &iter_b.ptr, mode, no_ownership,
1483                                                       override, extended_rna_path, flags, r_override_changed);
1484                                         equals = equals && eq;
1485                                 }
1486
1487                                 if (propname_a != propname_buff_a) {
1488                                         MEM_SAFE_FREE(propname_a);
1489                                 }
1490                                 if (propname_b != propname_buff_b) {
1491                                         MEM_SAFE_FREE(propname_b);
1492                                 }
1493                                 MEM_SAFE_FREE(extended_rna_path);
1494
1495                                 if (!rna_path && !equals) {
1496                                         break;  /* Early out in case we do not want to loop over whole collection. */
1497                                 }
1498                         }
1499
1500                         equals = equals && !(iter_a.valid || iter_b.valid);  /* Not same number of items in both collections... */
1501                         RNA_property_collection_end(&iter_a);
1502                         RNA_property_collection_end(&iter_b);
1503
1504                         return (equals == false);
1505                 }
1506
1507                 default:
1508                         break;
1509         }
1510
1511         return 0;
1512 }
1513
1514 bool rna_property_override_store_default(
1515         PointerRNA *ptr_local, PointerRNA *ptr_reference, PointerRNA *ptr_storage,
1516         PropertyRNA *prop_local, PropertyRNA *prop_reference, PropertyRNA *prop_storage,
1517         const int len_local, const int len_reference, const int len_storage,
1518         IDOverrideStaticPropertyOperation *opop)
1519 {
1520         BLI_assert(len_local == len_reference && (!ptr_storage || len_local == len_storage));
1521         UNUSED_VARS_NDEBUG(len_reference, len_storage);
1522
1523         bool changed = false;
1524         const int index = opop->subitem_reference_index;
1525
1526         if (!ELEM(opop->operation, IDOVERRIDESTATIC_OP_ADD, IDOVERRIDESTATIC_OP_SUBTRACT, IDOVERRIDESTATIC_OP_MULTIPLY)) {
1527                 return changed;
1528         }
1529
1530         /* XXX TODO About range limits.
1531          * Ideally, it woudl be great to get rid of RNA range in that specific case.
1532          * However, this won't be that easy and will add yet another layer of complexity in generated code,
1533          * not to mention that we could most likely *not* bypass custom setters anyway.
1534          * So for now, if needed second operand value is not in valid range, we simply fall back
1535          * to a mere REPLACE operation.
1536          * Time will say whether this is acceptable limitation or not. */
1537         switch (RNA_property_type(prop_local)) {
1538                 case PROP_BOOLEAN:
1539                         /* TODO support boolean ops? Really doubt this would ever be useful though... */
1540                         BLI_assert(0 && "Boolean properties support no override diff operation");
1541                         break;
1542                 case PROP_INT:
1543                 {
1544                         int prop_min, prop_max;
1545                         RNA_property_int_range(ptr_local, prop_local, &prop_min, &prop_max);
1546
1547                         if (len_local) {
1548                                 if (index == -1) {
1549                                         int array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
1550                                         int *array_a, *array_b;
1551
1552                                         array_a = (len_local > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_a) * len_local, __func__) : array_stack_a;
1553                                         RNA_property_int_get_array(ptr_reference, prop_reference, array_a);
1554
1555                                         switch (opop->operation) {
1556                                                 case IDOVERRIDESTATIC_OP_ADD:
1557                                                 case IDOVERRIDESTATIC_OP_SUBTRACT:
1558                                                 {
1559                                                         const int fac = opop->operation == IDOVERRIDESTATIC_OP_ADD ? 1 : -1;
1560                                                         const int other_op = opop->operation == IDOVERRIDESTATIC_OP_ADD ? IDOVERRIDESTATIC_OP_SUBTRACT : IDOVERRIDESTATIC_OP_ADD;
1561                                                         bool do_set = true;
1562                                                         array_b = (len_local > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_b) * len_local, __func__) : array_stack_b;
1563                                                         RNA_property_int_get_array(ptr_local, prop_local, array_b);
1564                                                         for (int i = len_local; i--;) {
1565                                                                 array_b[i] = fac * (array_b[i] - array_a[i]);
1566                                                                 if (array_b[i] < prop_min || array_b[i] > prop_max) {
1567                                                                         opop->operation = other_op;
1568                                                                         for (int j = len_local; j--;) {
1569                                                                                 array_b[j] = j >= i ? -array_b[j] : fac * (array_a[j] - array_b[j]);
1570                                                                                 if (array_b[j] < prop_min || array_b[j] > prop_max) {
1571                                                                                         /* We failed to  find a suitable diff op,
1572                                                                                          * fall back to plain REPLACE one. */
1573                                                                                         opop->operation = IDOVERRIDESTATIC_OP_REPLACE;
1574                                                                                         do_set = false;
1575                                                                                         break;
1576                                                                                 }
1577                                                                         }
1578                                                                         break;
1579                                                                 }
1580                                                         }
1581                                                         if (do_set) {
1582                                                                 changed = true;
1583                                                                 RNA_property_int_set_array(ptr_storage, prop_storage, array_b);
1584                                                         }
1585                                                         if (array_b != array_stack_b) MEM_freeN(array_b);
1586                                                         break;
1587                                                 }
1588                                                 default:
1589                                                         BLI_assert(0 && "Unsupported RNA override diff operation on integer");
1590                                                         break;
1591                                         }
1592
1593                                         if (array_a != array_stack_a) MEM_freeN(array_a);
1594                                 }
1595                                 else {
1596                                         const int value = RNA_property_int_get_index(ptr_reference, prop_reference, index);
1597
1598                                         switch (opop->operation) {
1599                                                 case IDOVERRIDESTATIC_OP_ADD:
1600                                                 case IDOVERRIDESTATIC_OP_SUBTRACT:
1601                                                 {
1602                                                         const int fac = opop->operation == IDOVERRIDESTATIC_OP_ADD ? 1 : -1;
1603                                                         const int other_op = opop->operation == IDOVERRIDESTATIC_OP_ADD ? IDOVERRIDESTATIC_OP_SUBTRACT : IDOVERRIDESTATIC_OP_ADD;
1604                                                         int b = fac * (RNA_property_int_get_index(ptr_local, prop_local, index) - value);
1605                                                         if (b < prop_min || b > prop_max) {
1606                                                                 opop->operation = other_op;
1607                                                                 b = -b;
1608                                                                 if (b < prop_min || b > prop_max) {
1609                                                                         opop->operation = IDOVERRIDESTATIC_OP_REPLACE;
1610                                                                         break;
1611                                                                 }
1612                                                         }
1613                                                         changed = true;
1614                                                         RNA_property_int_set_index(ptr_storage, prop_storage, index, b);
1615                                                         break;
1616                                                 }
1617                                                 default:
1618                                                         BLI_assert(0 && "Unsupported RNA override diff operation on integer");
1619                                                         break;
1620                                         }
1621                                 }
1622                         }
1623                         else {
1624                                 const int value = RNA_property_int_get(ptr_reference, prop_reference);
1625
1626                                 switch (opop->operation) {
1627                                         case IDOVERRIDESTATIC_OP_ADD:
1628                                         case IDOVERRIDESTATIC_OP_SUBTRACT:
1629                                         {
1630                                                 const int fac = opop->operation == IDOVERRIDESTATIC_OP_ADD ? 1 : -1;
1631                                                 const int other_op = opop->operation == IDOVERRIDESTATIC_OP_ADD ? IDOVERRIDESTATIC_OP_SUBTRACT : IDOVERRIDESTATIC_OP_ADD;
1632                                                 int b = fac * (RNA_property_int_get(ptr_local, prop_local) - value);
1633                                                 if (b < prop_min || b > prop_max) {
1634                                                         opop->operation = other_op;
1635                                                         b = -b;
1636                                                         if (b < prop_min || b > prop_max) {
1637                                                                 opop->operation = IDOVERRIDESTATIC_OP_REPLACE;
1638                                                                 break;
1639                                                         }
1640                                                 }
1641                                                 changed = true;
1642                                                 RNA_property_int_set(ptr_storage, prop_storage, b);
1643                                                 break;
1644                                         }
1645                                         default:
1646                                                 BLI_assert(0 && "Unsupported RNA override diff operation on integer");
1647                                                 break;
1648                                 }
1649                         }
1650                         break;
1651                 }
1652                 case PROP_FLOAT:
1653                 {
1654                         float prop_min, prop_max;
1655                         RNA_property_float_range(ptr_local, prop_local, &prop_min, &prop_max);
1656
1657                         if (len_local) {
1658                                 if (index == -1) {
1659                                         float array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
1660                                         float *array_a, *array_b;
1661
1662                                         array_a = (len_local > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_a) * len_local, __func__) : array_stack_a;
1663
1664                                         RNA_property_float_get_array(ptr_reference, prop_reference, array_a);
1665                                         switch (opop->operation) {
1666                                                 case IDOVERRIDESTATIC_OP_ADD:
1667                                                 case IDOVERRIDESTATIC_OP_SUBTRACT:
1668                                                 {
1669                                                         const float fac = opop->operation == IDOVERRIDESTATIC_OP_ADD ? 1.0 : -1.0;
1670                                                         const int other_op = opop->operation == IDOVERRIDESTATIC_OP_ADD ? IDOVERRIDESTATIC_OP_SUBTRACT : IDOVERRIDESTATIC_OP_ADD;
1671                                                         bool do_set = true;
1672                                                         array_b = (len_local > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_b) * len_local, __func__) : array_stack_b;
1673                                                         RNA_property_float_get_array(ptr_local, prop_local, array_b);
1674                                                         for (int i = len_local; i--;) {
1675                                                                 array_b[i] = fac * (array_b[i] - array_a[i]);
1676                                                                 if (array_b[i] < prop_min || array_b[i] > prop_max) {
1677                                                                         opop->operation = other_op;
1678                                                                         for (int j = len_local; j--;) {
1679                                                                                 array_b[j] = j >= i ? -array_b[j] : fac * (array_a[j] - array_b[j]);
1680                                                                                 if (array_b[j] < prop_min || array_b[j] > prop_max) {
1681                                                                                         /* We failed to  find a suitable diff op,
1682                                                                                          * fall back to plain REPLACE one. */
1683                                                                                         opop->operation = IDOVERRIDESTATIC_OP_REPLACE;
1684                                                                                         do_set = false;
1685                                                                                         break;
1686                                                                                 }
1687                                                                         }
1688                                                                         break;
1689                                                                 }
1690                                                         }
1691                                                         if (do_set) {
1692                                                                 changed = true;
1693                                                                 RNA_property_float_set_array(ptr_storage, prop_storage, array_b);
1694                                                         }
1695                                                         if (array_b != array_stack_b) MEM_freeN(array_b);
1696                                                         break;
1697                                                 }
1698                                                 case IDOVERRIDESTATIC_OP_MULTIPLY:
1699                                                 {
1700                                                         bool do_set = true;
1701                                                         array_b = (len_local > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_b) * len_local, __func__) : array_stack_b;
1702                                                         RNA_property_float_get_array(ptr_local, prop_local, array_b);
1703                                                         for (int i = len_local; i--;) {
1704                                                                 array_b[i] = array_a[i] == 0.0f ? array_b[i] : array_b[i] / array_a[i];
1705                                                                 if (array_b[i] < prop_min || array_b[i] > prop_max) {
1706                                                                         opop->operation = IDOVERRIDESTATIC_OP_REPLACE;
1707                                                                         do_set = false;
1708                                                                         break;
1709                                                                 }
1710                                                         }
1711                                                         if (do_set) {
1712                                                                 changed = true;
1713                                                                 RNA_property_float_set_array(ptr_storage, prop_storage, array_b);
1714                                                         }
1715                                                         if (array_b != array_stack_b) MEM_freeN(array_b);
1716                                                         break;
1717                                                 }
1718                                                 default:
1719                                                         BLI_assert(0 && "Unsupported RNA override diff operation on float");
1720                                                         break;
1721                                         }
1722
1723                                         if (array_a != array_stack_a) MEM_freeN(array_a);
1724                                 }
1725                                 else {
1726                                         const float value = RNA_property_float_get_index(ptr_reference, prop_reference, index);
1727
1728                                         switch (opop->operation) {
1729                                                 case IDOVERRIDESTATIC_OP_ADD:
1730                                                 case IDOVERRIDESTATIC_OP_SUBTRACT:
1731                                                 {
1732                                                         const float fac = opop->operation == IDOVERRIDESTATIC_OP_ADD ? 1.0f : -1.0f;
1733                                                         const int other_op = opop->operation == IDOVERRIDESTATIC_OP_ADD ? IDOVERRIDESTATIC_OP_SUBTRACT : IDOVERRIDESTATIC_OP_ADD;
1734                                                         float b = fac * (RNA_property_float_get_index(ptr_local, prop_local, index) - value);
1735                                                         if (b < prop_min || b > prop_max) {
1736                                                                 opop->operation = other_op;
1737                                                                 b = -b;
1738                                                                 if (b < prop_min || b > prop_max) {
1739                                                                         opop->operation = IDOVERRIDESTATIC_OP_REPLACE;
1740                                                                         break;
1741                                                                 }
1742                                                         }
1743                                                         changed = true;
1744                                                         RNA_property_float_set_index(ptr_storage, prop_storage, index, b);
1745                                                         break;
1746                                                 }
1747                                                 case IDOVERRIDESTATIC_OP_MULTIPLY:
1748                                                 {
1749                                                         const float b = RNA_property_float_get_index(ptr_local, prop_local, index) / (value == 0.0f ?  1.0f : value);
1750                                                         if (b < prop_min || b > prop_max) {
1751                                                                 opop->operation = IDOVERRIDESTATIC_OP_REPLACE;
1752                                                                 break;
1753                                                         }
1754                                                         changed = true;
1755                                                         RNA_property_float_set_index(ptr_storage, prop_storage, index, b);
1756                                                         break;
1757                                                 }
1758                                                 default:
1759                                                         BLI_assert(0 && "Unsupported RNA override diff operation on float");
1760                                                         break;
1761                                         }
1762                                 }
1763                         }
1764                         else {
1765                                 const float value = RNA_property_float_get(ptr_reference, prop_reference);
1766
1767                                 switch (opop->operation) {
1768                                         case IDOVERRIDESTATIC_OP_ADD:
1769                                         case IDOVERRIDESTATIC_OP_SUBTRACT:
1770                                         {
1771                                                 const float fac = opop->operation == IDOVERRIDESTATIC_OP_ADD ? 1.0f : -1.0f;
1772                                                 const int other_op = opop->operation == IDOVERRIDESTATIC_OP_ADD ? IDOVERRIDESTATIC_OP_SUBTRACT : IDOVERRIDESTATIC_OP_ADD;
1773                                                 float b = fac * (RNA_property_float_get(ptr_local, prop_local) - value);
1774                                                 if (b < prop_min || b > prop_max) {
1775                                                         opop->operation = other_op;
1776                                                         b = -b;
1777                                                         if (b < prop_min || b > prop_max) {
1778                                                                 opop->operation = IDOVERRIDESTATIC_OP_REPLACE;
1779                                                                 break;
1780                                                         }
1781                                                 }
1782                                                 changed = true;
1783                                                 RNA_property_float_set(ptr_storage, prop_storage, b);
1784                                                 break;
1785                                         }
1786                                         case IDOVERRIDESTATIC_OP_MULTIPLY:
1787                                         {
1788                                                 const float b = RNA_property_float_get(ptr_local, prop_local) / (value == 0.0f ?  1.0f : value);
1789                                                 if (b < prop_min || b > prop_max) {
1790                                                         opop->operation = IDOVERRIDESTATIC_OP_REPLACE;
1791                                                         break;
1792                                                 }
1793                                                 changed = true;
1794                                                 RNA_property_float_set(ptr_storage, prop_storage, b);
1795                                                 break;
1796                                         }
1797                                         default:
1798                                                 BLI_assert(0 && "Unsupported RNA override diff operation on float");
1799                                                 break;
1800                                 }
1801                         }
1802                         return true;
1803                 }
1804                 case PROP_ENUM:
1805                         /* TODO support add/sub, for bitflags? */
1806                         BLI_assert(0 && "Enum properties support no override diff operation");
1807                         break;
1808                 case PROP_POINTER:
1809                         BLI_assert(0 && "Pointer properties support no override diff operation");
1810                         break;
1811                 case PROP_STRING:
1812                         BLI_assert(0 && "String properties support no override diff operation");
1813                         break;
1814                 case PROP_COLLECTION:
1815                         /* XXX TODO support this of course... */
1816                         BLI_assert(0 && "Collection properties support no override diff operation");
1817                         break;
1818                 default:
1819                         break;
1820         }
1821
1822         return changed;
1823 }
1824
1825 bool rna_property_override_apply_default(
1826         PointerRNA *ptr_dst, PointerRNA *ptr_src, PointerRNA *ptr_storage,
1827         PropertyRNA *prop_dst, PropertyRNA *prop_src, PropertyRNA *prop_storage,
1828         const int len_dst, const int len_src, const int len_storage,
1829         IDOverrideStaticPropertyOperation *opop)
1830 {
1831         BLI_assert(len_dst == len_src && (!ptr_storage || len_dst == len_storage));
1832         UNUSED_VARS_NDEBUG(len_src, len_storage);
1833
1834         const int index = opop->subitem_reference_index;
1835         const short override_op = opop->operation;
1836
1837         switch (RNA_property_type(prop_dst)) {
1838                 case PROP_BOOLEAN:
1839                         if (len_dst) {
1840                                 if (index == -1) {
1841                                         int array_stack_a[RNA_STACK_ARRAY];
1842                                         int *array_a;
1843
1844                                         array_a = (len_dst > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_a) * len_dst, __func__) : array_stack_a;
1845
1846                                         RNA_property_boolean_get_array(ptr_src, prop_src, array_a);
1847
1848                                         switch (override_op) {
1849                                                 case IDOVERRIDESTATIC_OP_REPLACE:
1850                                                         RNA_property_boolean_set_array(ptr_dst, prop_dst, array_a);
1851                                                         break;
1852                                                 default:
1853                                                         BLI_assert(0 && "Unsupported RNA override operation on boolean");
1854                                                         return false;
1855                                         }
1856
1857                                         if (array_a != array_stack_a) MEM_freeN(array_a);
1858                                 }
1859                                 else {
1860                                         const int value = RNA_property_boolean_get_index(ptr_src, prop_src, index);
1861
1862                                         switch (override_op) {
1863                                                 case IDOVERRIDESTATIC_OP_REPLACE:
1864                                                         RNA_property_boolean_set_index(ptr_dst, prop_dst, index, value);
1865                                                         break;
1866                                                 default:
1867                                                         BLI_assert(0 && "Unsupported RNA override operation on boolean");
1868                                                         return false;
1869                                         }
1870                                 }
1871                         }
1872                         else {
1873                                 const int value = RNA_property_boolean_get(ptr_src, prop_src);
1874
1875                                 switch (override_op) {
1876                                         case IDOVERRIDESTATIC_OP_REPLACE:
1877                                                 RNA_property_boolean_set(ptr_dst, prop_dst, value);
1878                                                 break;
1879                                         default:
1880                                                 BLI_assert(0 && "Unsupported RNA override operation on boolean");
1881                                                 return false;
1882                                 }
1883                         }
1884                         return true;
1885                 case PROP_INT:
1886                         if (len_dst) {
1887                                 if (index == -1) {
1888                                         int array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
1889                                         int *array_a, *array_b;
1890
1891                                         array_a = (len_dst > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_a) * len_dst, __func__) : array_stack_a;
1892
1893                                         switch (override_op) {
1894                                                 case IDOVERRIDESTATIC_OP_REPLACE:
1895                                                         RNA_property_int_get_array(ptr_src, prop_src, array_a);
1896                                                         RNA_property_int_set_array(ptr_dst, prop_dst, array_a);
1897                                                         break;
1898                                                 case IDOVERRIDESTATIC_OP_ADD:
1899                                                 case IDOVERRIDESTATIC_OP_SUBTRACT:
1900                                                         RNA_property_int_get_array(ptr_dst, prop_dst, array_a);
1901                                                         array_b = (len_dst > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_b) * len_dst, __func__) : array_stack_b;
1902                                                         RNA_property_int_get_array(ptr_storage, prop_storage, array_b);
1903                                                         if (override_op == IDOVERRIDESTATIC_OP_ADD) {
1904                                                                 for (int i = len_dst; i--;) array_a[i] += array_b[i];
1905                                                         }
1906                                                         else {
1907                                                                 for (int i = len_dst; i--;) array_a[i] -= array_b[i];
1908                                                         }
1909                                                         RNA_property_int_set_array(ptr_dst, prop_dst, array_a);
1910                                                         if (array_b != array_stack_b) MEM_freeN(array_b);
1911                                                         break;
1912                                                 default:
1913                                                         BLI_assert(0 && "Unsupported RNA override operation on integer");
1914                                                         return false;
1915                                         }
1916
1917                                         if (array_a != array_stack_a) MEM_freeN(array_a);
1918                                 }
1919                                 else {
1920                                         const int storage_value = ptr_storage ? RNA_property_int_get_index(ptr_storage, prop_storage, index) : 0;
1921
1922                                         switch (override_op) {
1923                                                 case IDOVERRIDESTATIC_OP_REPLACE:
1924                                                         RNA_property_int_set_index(ptr_dst, prop_dst, index,
1925                                                                                    RNA_property_int_get_index(ptr_src, prop_src, index));
1926                                                         break;
1927                                                 case IDOVERRIDESTATIC_OP_ADD:
1928                                                         RNA_property_int_set_index(ptr_dst, prop_dst, index,
1929                                                                                    RNA_property_int_get_index(ptr_dst, prop_dst, index) - storage_value);
1930                                                         break;
1931                                                 case IDOVERRIDESTATIC_OP_SUBTRACT:
1932                                                         RNA_property_int_set_index(ptr_dst, prop_dst, index,
1933                                                                                    RNA_property_int_get_index(ptr_dst, prop_dst, index) - storage_value);
1934                                                         break;
1935                                                 default:
1936                                                         BLI_assert(0 && "Unsupported RNA override operation on integer");
1937                                                         return false;
1938                                         }
1939                                 }
1940                         }
1941                         else {
1942                                 const int storage_value = ptr_storage ? RNA_property_int_get(ptr_storage, prop_storage) : 0;
1943
1944                                 switch (override_op) {
1945                                         case IDOVERRIDESTATIC_OP_REPLACE:
1946                                                 RNA_property_int_set(ptr_dst, prop_dst, RNA_property_int_get(ptr_src, prop_src));
1947                                                 break;
1948                                         case IDOVERRIDESTATIC_OP_ADD:
1949                                                 RNA_property_int_set(ptr_dst, prop_dst, RNA_property_int_get(ptr_dst, prop_dst) + storage_value);
1950                                                 break;
1951                                         case IDOVERRIDESTATIC_OP_SUBTRACT:
1952                                                 RNA_property_int_set(ptr_dst, prop_dst, RNA_property_int_get(ptr_dst, prop_dst) - storage_value);
1953                                                 break;
1954                                         default:
1955                                                 BLI_assert(0 && "Unsupported RNA override operation on integer");
1956                                                 return false;
1957                                 }
1958                         }
1959                         return true;
1960                 case PROP_FLOAT:
1961                         if (len_dst) {
1962                                 if (index == -1) {
1963                                         float array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
1964                                         float *array_a, *array_b;
1965
1966                                         array_a = (len_dst > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_a) * len_dst, __func__) : array_stack_a;
1967
1968                                         switch (override_op) {
1969                                                 case IDOVERRIDESTATIC_OP_REPLACE:
1970                                                         RNA_property_float_get_array(ptr_src, prop_src, array_a);
1971                                                         RNA_property_float_set_array(ptr_dst, prop_dst, array_a);
1972                                                         break;
1973                                                 case IDOVERRIDESTATIC_OP_ADD:
1974                                                 case IDOVERRIDESTATIC_OP_SUBTRACT:
1975                                                 case IDOVERRIDESTATIC_OP_MULTIPLY:
1976                                                         RNA_property_float_get_array(ptr_dst, prop_dst, array_a);
1977                                                         array_b = (len_dst > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_b) * len_dst, __func__) : array_stack_b;
1978                                                         RNA_property_float_get_array(ptr_storage, prop_storage, array_b);
1979                                                         if (override_op == IDOVERRIDESTATIC_OP_ADD) {
1980                                                                 for (int i = len_dst; i--;) array_a[i] += array_b[i];
1981                                                         }
1982                                                         else if (override_op == IDOVERRIDESTATIC_OP_SUBTRACT) {
1983                                                                 for (int i = len_dst; i--;) array_a[i] -= array_b[i];
1984                                                         }
1985                                                         else {
1986                                                                 for (int i = len_dst; i--;) array_a[i] *= array_b[i];
1987                                                         }
1988                                                         RNA_property_float_set_array(ptr_dst, prop_dst, array_a);
1989                                                         if (array_b != array_stack_b) MEM_freeN(array_b);
1990                                                         break;
1991                                                 default:
1992                                                         BLI_assert(0 && "Unsupported RNA override operation on float");
1993                                                         return false;
1994                                         }
1995
1996                                         if (array_a != array_stack_a) MEM_freeN(array_a);
1997                                 }
1998                                 else {
1999                                         const float storage_value = ptr_storage ? RNA_property_float_get_index(ptr_storage, prop_storage, index) : 0.0f;
2000
2001                                         switch (override_op) {
2002                                                 case IDOVERRIDESTATIC_OP_REPLACE:
2003                                                         RNA_property_float_set_index(ptr_dst, prop_dst, index,
2004                                                                                      RNA_property_float_get_index(ptr_src, prop_src, index));
2005                                                         break;
2006                                                 case IDOVERRIDESTATIC_OP_ADD:
2007                                                         RNA_property_float_set_index(ptr_dst, prop_dst, index,
2008                                                                                      RNA_property_float_get_index(ptr_dst, prop_dst, index) + storage_value);
2009                                                         break;
2010                                                 case IDOVERRIDESTATIC_OP_SUBTRACT:
2011                                                         RNA_property_float_set_index(ptr_dst, prop_dst, index,
2012                                                                                      RNA_property_float_get_index(ptr_dst, prop_dst, index) - storage_value);
2013                                                         break;
2014                                                 case IDOVERRIDESTATIC_OP_MULTIPLY:
2015                                                         RNA_property_float_set_index(ptr_dst, prop_dst, index,
2016                                                                                      RNA_property_float_get_index(ptr_dst, prop_dst, index) * storage_value);
2017                                                         break;
2018                                                 default:
2019                                                         BLI_assert(0 && "Unsupported RNA override operation on float");
2020                                                         return false;
2021                                         }
2022                                 }
2023                         }
2024                         else {
2025                                 const float storage_value = ptr_storage ? RNA_property_float_get(ptr_storage, prop_storage) : 0.0f;
2026
2027                                 switch (override_op) {
2028                                         case IDOVERRIDESTATIC_OP_REPLACE:
2029                                                 RNA_property_float_set(ptr_dst, prop_dst, RNA_property_float_get(ptr_src, prop_src));
2030                                                 break;
2031                                         case IDOVERRIDESTATIC_OP_ADD:
2032                                                 RNA_property_float_set(ptr_dst, prop_dst, RNA_property_float_get(ptr_dst, prop_dst) + storage_value);
2033                                                 break;
2034                                         case IDOVERRIDESTATIC_OP_SUBTRACT:
2035                                                 RNA_property_float_set(ptr_dst, prop_dst, RNA_property_float_get(ptr_dst, prop_dst) - storage_value);
2036                                                 break;
2037                                         case IDOVERRIDESTATIC_OP_MULTIPLY:
2038                                                 RNA_property_float_set(ptr_dst, prop_dst, RNA_property_float_get(ptr_dst, prop_dst) * storage_value);
2039                                                 break;
2040                                         default:
2041                                                 BLI_assert(0 && "Unsupported RNA override operation on float");
2042                                                 return false;
2043                                 }
2044                         }
2045                         return true;
2046                 case PROP_ENUM:
2047                 {
2048                         const int value = RNA_property_enum_get(ptr_src, prop_src);
2049
2050                         switch (override_op) {
2051                                 case IDOVERRIDESTATIC_OP_REPLACE:
2052                                         RNA_property_enum_set(ptr_dst, prop_dst, value);
2053                                         break;
2054                                 /* TODO support add/sub, for bitflags? */
2055                                 default:
2056                                         BLI_assert(0 && "Unsupported RNA override operation on enum");
2057                                         return false;
2058                         }
2059                         return true;
2060                 }
2061                 case PROP_POINTER:
2062                 {
2063                         PointerRNA value = RNA_property_pointer_get(ptr_src, prop_src);
2064
2065                         switch (override_op) {
2066                                 case IDOVERRIDESTATIC_OP_REPLACE:
2067                                         RNA_property_pointer_set(ptr_dst, prop_dst, value);
2068                                         break;
2069                                 default:
2070                                         BLI_assert(0 && "Unsupported RNA override operation on pointer");
2071                                         return false;
2072                         }
2073                         return true;
2074                 }
2075                 case PROP_STRING:
2076                 {
2077                         char buff[256];
2078                         char *value = RNA_property_string_get_alloc(ptr_src, prop_src, buff, sizeof(buff), NULL);
2079
2080                         switch (override_op) {
2081                                 case IDOVERRIDESTATIC_OP_REPLACE:
2082                                         RNA_property_string_set(ptr_dst, prop_dst, value);
2083                                         break;
2084                                 default:
2085                                         BLI_assert(0 && "Unsupported RNA override operation on string");
2086                                         return false;
2087                         }
2088
2089                         if (value != buff) MEM_freeN(value);
2090                         return true;
2091                 }
2092                 default:
2093                         /* TODO PROP_COLLECTION of course! */
2094                         return false;
2095         }
2096
2097         return false;
2098 }
2099
2100
2101
2102 #else
2103
2104 static void rna_def_struct(BlenderRNA *brna)
2105 {
2106         StructRNA *srna;
2107         PropertyRNA *prop;
2108
2109         srna = RNA_def_struct(brna, "Struct", NULL);
2110         RNA_def_struct_ui_text(srna, "Struct Definition", "RNA structure definition");
2111         RNA_def_struct_ui_icon(srna, ICON_RNA);
2112
2113         prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
2114         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2115         RNA_def_property_string_funcs(prop, "rna_Struct_name_get", "rna_Struct_name_length", NULL);
2116         RNA_def_property_ui_text(prop, "Name", "Human readable name");
2117
2118         prop = RNA_def_property(srna, "identifier", PROP_STRING, PROP_NONE);
2119         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2120         RNA_def_property_string_funcs(prop, "rna_Struct_identifier_get", "rna_Struct_identifier_length", NULL);
2121         RNA_def_property_ui_text(prop, "Identifier", "Unique name used in the code and scripting");
2122         RNA_def_struct_name_property(srna, prop);
2123         
2124         prop = RNA_def_property(srna, "description", PROP_STRING, PROP_NONE);
2125         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2126         RNA_def_property_string_funcs(prop, "rna_Struct_description_get", "rna_Struct_description_length", NULL);
2127         RNA_def_property_ui_text(prop, "Description", "Description of the Struct's purpose");
2128         
2129         prop = RNA_def_property(srna, "translation_context", PROP_STRING, PROP_NONE);
2130         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2131         RNA_def_property_string_funcs(prop, "rna_Struct_translation_context_get",
2132                                       "rna_Struct_translation_context_length", NULL);
2133         RNA_def_property_ui_text(prop, "Translation Context", "Translation context of the struct's name");
2134         
2135         prop = RNA_def_property(srna, "base", PROP_POINTER, PROP_NONE);
2136         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2137         RNA_def_property_struct_type(prop, "Struct");
2138         RNA_def_property_pointer_funcs(prop, "rna_Struct_base_get", NULL, NULL, NULL);
2139         RNA_def_property_ui_text(prop, "Base", "Struct definition this is derived from");
2140
2141         prop = RNA_def_property(srna, "nested", PROP_POINTER, PROP_NONE);
2142         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2143         RNA_def_property_struct_type(prop, "Struct");
2144         RNA_def_property_pointer_funcs(prop, "rna_Struct_nested_get", NULL, NULL, NULL);
2145         RNA_def_property_ui_text(prop, "Nested",
2146                                  "Struct in which this struct is always nested, and to which it logically belongs");
2147
2148         prop = RNA_def_property(srna, "name_property", PROP_POINTER, PROP_NONE);
2149         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2150         RNA_def_property_struct_type(prop, "StringProperty");
2151         RNA_def_property_pointer_funcs(prop, "rna_Struct_name_property_get", NULL, NULL, NULL);
2152         RNA_def_property_ui_text(prop, "Name Property", "Property that gives the name of the struct");
2153
2154         prop = RNA_def_property(srna, "properties", PROP_COLLECTION, PROP_NONE);
2155         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2156         RNA_def_property_struct_type(prop, "Property");
2157         RNA_def_property_collection_funcs(prop, "rna_Struct_properties_begin", "rna_Struct_properties_next",
2158                                           "rna_iterator_listbase_end", "rna_Struct_properties_get",
2159                                           NULL, NULL, NULL, NULL);
2160         RNA_def_property_ui_text(prop, "Properties", "Properties in the struct");
2161
2162         prop = RNA_def_property(srna, "functions", PROP_COLLECTION, PROP_NONE);
2163         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2164         RNA_def_property_struct_type(prop, "Function");
2165         RNA_def_property_collection_funcs(prop, "rna_Struct_functions_begin", "rna_Struct_functions_next",
2166                                           "rna_iterator_listbase_end", "rna_Struct_functions_get",
2167                                           NULL, NULL, NULL, NULL);
2168         RNA_def_property_ui_text(prop, "Functions", "");
2169
2170         prop = RNA_def_property(srna, "property_tags", PROP_COLLECTION, PROP_NONE);
2171         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2172         RNA_def_property_struct_type(prop, "EnumPropertyItem");
2173         RNA_def_property_collection_funcs(prop, "rna_Struct_property_tags_begin", "rna_iterator_array_next",
2174                                           "rna_iterator_array_end", "rna_iterator_array_get",
2175                                           NULL, NULL, NULL, NULL);
2176         RNA_def_property_ui_text(prop, "Property Tags", "Tags that properties can use to influence behavior");
2177 }
2178
2179 static void rna_def_property(BlenderRNA *brna)
2180 {
2181         StructRNA *srna;
2182         PropertyRNA *prop;
2183         static const EnumPropertyItem subtype_items[] = {
2184                 {PROP_NONE, "NONE", 0, "None", ""},
2185                 {PROP_FILEPATH, "FILE_PATH", 0, "File Path", ""},
2186                 {PROP_DIRPATH, "DIR_PATH", 0, "Directory Path", ""},
2187                 {PROP_PIXEL, "PIXEL", 0, "Pixel", ""},
2188                 {PROP_UNSIGNED, "UNSIGNED", 0, "Unsigned Number", ""},
2189                 {PROP_PERCENTAGE, "PERCENTAGE", 0, "Percentage", ""},
2190                 {PROP_FACTOR, "FACTOR", 0, "Factor", ""},
2191                 {PROP_ANGLE, "ANGLE", 0, "Angle", ""},
2192                 {PROP_TIME, "TIME", 0, "Time", ""},
2193                 {PROP_DISTANCE, "DISTANCE", 0, "Distance", ""},
2194                 {PROP_COLOR, "COLOR", 0, "Color", ""},
2195                 {PROP_TRANSLATION, "TRANSLATION", 0, "Translation", ""},
2196                 {PROP_DIRECTION, "DIRECTION", 0, "Direction", ""},
2197                 {PROP_MATRIX, "MATRIX", 0, "Matrix", ""},
2198                 {PROP_EULER, "EULER", 0, "Euler", ""},
2199                 {PROP_QUATERNION, "QUATERNION", 0, "Quaternion", ""},
2200                 {PROP_XYZ, "XYZ", 0, "XYZ", ""},
2201                 {PROP_COLOR_GAMMA, "COLOR_GAMMA", 0, "Gamma Corrected Color", ""},
2202                 {PROP_COORDS, "COORDINATES", 0, "Vector Coordinates", ""},
2203                 {PROP_LAYER, "LAYER", 0, "Layer", ""},
2204                 {PROP_LAYER_MEMBER, "LAYER_MEMBERSHIP", 0, "Layer Membership", ""},
2205                 {0, NULL, 0, NULL, NULL}
2206         };
2207         EnumPropertyItem dummy_prop_tags[] = {
2208                 {0, NULL, 0, NULL, NULL}
2209         };
2210
2211         srna = RNA_def_struct(brna, "Property", NULL);
2212         RNA_def_struct_ui_text(srna, "Property Definition", "RNA property definition");
2213         RNA_def_struct_refine_func(srna, "rna_Property_refine");
2214         RNA_def_struct_ui_icon(srna, ICON_RNA);
2215
2216         prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
2217         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2218         RNA_def_property_string_funcs(prop, "rna_Property_name_get", "rna_Property_name_length", NULL);
2219         RNA_def_property_ui_text(prop, "Name", "Human readable name");
2220
2221         prop = RNA_def_property(srna, "identifier", PROP_STRING, PROP_NONE);
2222         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2223         RNA_def_property_string_funcs(prop, "rna_Property_identifier_get", "rna_Property_identifier_length", NULL);
2224         RNA_def_property_ui_text(prop, "Identifier", "Unique name used in the code and scripting");
2225         RNA_def_struct_name_property(srna, prop);
2226                 
2227         prop = RNA_def_property(srna, "description", PROP_STRING, PROP_NONE);
2228         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2229         RNA_def_property_string_funcs(prop, "rna_Property_description_get", "rna_Property_description_length", NULL);
2230         RNA_def_property_ui_text(prop, "Description", "Description of the property for tooltips");
2231
2232         prop = RNA_def_property(srna, "translation_context", PROP_STRING, PROP_NONE);
2233         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2234         RNA_def_property_string_funcs(prop, "rna_Property_translation_context_get",
2235                                       "rna_Property_translation_context_length", NULL);
2236         RNA_def_property_ui_text(prop, "Translation Context", "Translation context of the property's name");
2237
2238         prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
2239         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2240         RNA_def_property_enum_items(prop, rna_enum_property_type_items);
2241         RNA_def_property_enum_funcs(prop, "rna_Property_type_get", NULL, NULL);
2242         RNA_def_property_ui_text(prop, "Type", "Data type of the property");
2243
2244         prop = RNA_def_property(srna, "subtype", PROP_ENUM, PROP_NONE);
2245         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2246         RNA_def_property_enum_items(prop, subtype_items);
2247         RNA_def_property_enum_funcs(prop, "rna_Property_subtype_get", NULL, NULL);
2248         RNA_def_property_ui_text(prop, "Subtype", "Semantic interpretation of the property");
2249
2250         prop = RNA_def_property(srna, "srna", PROP_POINTER, PROP_NONE);
2251         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2252         RNA_def_property_struct_type(prop, "Struct");
2253         RNA_def_property_pointer_funcs(prop, "rna_Property_srna_get", NULL, NULL, NULL);
2254         RNA_def_property_ui_text(prop, "Base", "Struct definition used for properties assigned to this item");
2255
2256         prop = RNA_def_property(srna, "unit", PROP_ENUM, PROP_NONE);
2257         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2258         RNA_def_property_enum_items(prop, rna_enum_property_unit_items);
2259         RNA_def_property_enum_funcs(prop, "rna_Property_unit_get", NULL, NULL);
2260         RNA_def_property_ui_text(prop, "Unit", "Type of units for this property");
2261
2262         prop = RNA_def_property(srna, "icon", PROP_ENUM, PROP_NONE);
2263         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2264         RNA_def_property_enum_items(prop, rna_enum_icon_items);
2265         RNA_def_property_enum_funcs(prop, "rna_Property_icon_get", NULL, NULL);
2266         RNA_def_property_ui_text(prop, "Icon", "Icon of the item");
2267
2268         prop = RNA_def_property(srna, "is_readonly", PROP_BOOLEAN, PROP_NONE);
2269         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2270         RNA_def_property_boolean_funcs(prop, "rna_Property_readonly_get", NULL);
2271         RNA_def_property_ui_text(prop, "Read Only", "Property is editable through RNA");
2272
2273         prop = RNA_def_property(srna, "is_animatable", PROP_BOOLEAN, PROP_NONE);
2274         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2275         RNA_def_property_boolean_funcs(prop, "rna_Property_animatable_get", NULL);
2276         RNA_def_property_ui_text(prop, "Animatable", "Property is animatable through RNA");
2277
2278         prop = RNA_def_property(srna, "is_overridable", PROP_BOOLEAN, PROP_NONE);
2279         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2280         RNA_def_property_boolean_funcs(prop, "rna_Property_overridable_get", NULL);
2281         RNA_def_property_ui_text(prop, "Overridable", "Property is overridable through RNA");
2282
2283         prop = RNA_def_property(srna, "is_required", PROP_BOOLEAN, PROP_NONE);
2284         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2285         RNA_def_property_boolean_funcs(prop, "rna_Property_is_required_get", NULL);
2286         RNA_def_property_ui_text(prop, "Required", "False when this property is an optional argument in an RNA function");
2287
2288         prop = RNA_def_property(srna, "is_argument_optional", PROP_BOOLEAN, PROP_NONE);
2289         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2290         RNA_def_property_boolean_funcs(prop, "rna_Property_is_argument_optional_get", NULL);
2291         RNA_def_property_ui_text(prop, "Optional Argument",
2292                                  "True when the property is optional in a Python function implementing an RNA function");
2293
2294         prop = RNA_def_property(srna, "is_never_none", PROP_BOOLEAN, PROP_NONE);
2295         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2296         RNA_def_property_boolean_funcs(prop, "rna_Property_is_never_none_get", NULL);
2297         RNA_def_property_ui_text(prop, "Never None", "True when this value can't be set to None");
2298
2299         prop = RNA_def_property(srna, "is_hidden", PROP_BOOLEAN, PROP_NONE);
2300         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2301         RNA_def_property_boolean_funcs(prop, "rna_Property_is_hidden_get", NULL);
2302         RNA_def_property_ui_text(prop, "Hidden", "True when the property is hidden");
2303
2304         prop = RNA_def_property(srna, "is_skip_save", PROP_BOOLEAN, PROP_NONE);
2305         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2306         RNA_def_property_boolean_funcs(prop, "rna_Property_is_skip_save_get", NULL);
2307         RNA_def_property_ui_text(prop, "Skip Save", "True when the property is not saved in presets");
2308
2309         prop = RNA_def_property(srna, "is_output", PROP_BOOLEAN, PROP_NONE);
2310         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2311         RNA_def_property_boolean_funcs(prop, "rna_Property_use_output_get", NULL);
2312         RNA_def_property_ui_text(prop, "Return", "True when this property is an output value from an RNA function");
2313
2314         prop = RNA_def_property(srna, "is_registered", PROP_BOOLEAN, PROP_NONE);
2315         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2316         RNA_def_property_boolean_funcs(prop, "rna_Property_is_registered_get", NULL);
2317         RNA_def_property_ui_text(prop, "Registered", "Property is registered as part of type registration");
2318
2319         prop = RNA_def_property(srna, "is_registered_optional", PROP_BOOLEAN, PROP_NONE);
2320         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2321         RNA_def_property_boolean_funcs(prop, "rna_Property_is_registered_optional_get", NULL);
2322         RNA_def_property_ui_text(prop, "Registered Optionally",
2323                                  "Property is optionally registered as part of type registration");
2324         
2325         prop = RNA_def_property(srna, "is_runtime", PROP_BOOLEAN, PROP_NONE);
2326         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2327         RNA_def_property_boolean_funcs(prop, "rna_Property_is_runtime_get", NULL);
2328         RNA_def_property_ui_text(prop, "Runtime", "Property has been dynamically created at runtime");
2329
2330         prop = RNA_def_property(srna, "is_enum_flag", PROP_BOOLEAN, PROP_NONE);
2331         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2332         RNA_def_property_boolean_funcs(prop, "rna_Property_is_enum_flag_get", NULL);
2333         RNA_def_property_ui_text(prop, "Enum Flag", "True when multiple enums ");
2334
2335         prop = RNA_def_property(srna, "is_library_editable", PROP_BOOLEAN, PROP_NONE);
2336         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2337         RNA_def_property_boolean_funcs(prop, "rna_Property_is_library_editable_flag_get", NULL);
2338         RNA_def_property_ui_text(prop, "Library Editable", "Property is editable from linked instances (changes not saved)");
2339
2340         prop = RNA_def_property(srna, "tags", PROP_ENUM, PROP_NONE);
2341         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2342         RNA_def_property_enum_items(prop, dummy_prop_tags);
2343         RNA_def_property_enum_funcs(prop, "rna_Property_tags_get", NULL, "rna_Property_tags_itemf");
2344         RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL | PROP_ENUM_FLAG);
2345         RNA_def_property_ui_text(prop, "Tags", "Subset of tags (defined in parent struct) that are set for this property");
2346 }
2347
2348 static void rna_def_function(BlenderRNA *brna)
2349 {
2350         StructRNA *srna;
2351         PropertyRNA *prop;
2352
2353         srna = RNA_def_struct(brna, "Function", NULL);
2354         RNA_def_struct_ui_text(srna, "Function Definition", "RNA function definition");
2355         RNA_def_struct_ui_icon(srna, ICON_RNA);
2356
2357         prop = RNA_def_property(srna, "identifier", PROP_STRING, PROP_NONE);
2358         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2359         RNA_def_property_string_funcs(prop, "rna_Function_identifier_get", "rna_Function_identifier_length", NULL);
2360         RNA_def_property_ui_text(prop, "Identifier", "Unique name used in the code and scripting");
2361         RNA_def_struct_name_property(srna, prop);
2362
2363         prop = RNA_def_property(srna, "description", PROP_STRING, PROP_NONE);
2364         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2365         RNA_def_property_string_funcs(prop, "rna_Function_description_get", "rna_Function_description_length", NULL);
2366         RNA_def_property_ui_text(prop, "Description", "Description of the Function's purpose");
2367
2368         prop = RNA_def_property(srna, "parameters", PROP_COLLECTION, PROP_NONE);
2369         /*RNA_def_property_clear_flag(prop, PROP_EDITABLE);*/
2370         RNA_def_property_struct_type(prop, "Property");
2371         RNA_def_property_collection_funcs(prop, "rna_Function_parameters_begin", "rna_iterator_listbase_next",
2372                                           "rna_iterator_listbase_end", "rna_iterator_listbase_get",
2373                                           NULL, NULL, NULL, NULL);
2374         RNA_def_property_ui_text(prop, "Parameters", "Parameters for the function");
2375
2376         prop = RNA_def_property(srna, "is_registered", PROP_BOOLEAN, PROP_NONE);
2377         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2378         RNA_def_property_boolean_funcs(prop, "rna_Function_registered_get", NULL);
2379         RNA_def_property_ui_text(prop, "Registered", "Function is registered as callback as part of type registration");
2380
2381         prop = RNA_def_property(srna, "is_registered_optional", PROP_BOOLEAN, PROP_NONE);
2382         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2383         RNA_def_property_boolean_funcs(prop, "rna_Function_registered_optional_get", NULL);
2384         RNA_def_property_ui_text(prop, "Registered Optionally",
2385                                  "Function is optionally registered as callback part of type registration");
2386
2387         prop = RNA_def_property(srna, "use_self", PROP_BOOLEAN, PROP_NONE);
2388         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2389         RNA_def_property_boolean_funcs(prop, "rna_Function_no_self_get", NULL);
2390         RNA_def_property_ui_text(prop, "No Self",
2391                                  "Function does not pass its self as an argument (becomes a static method in python)");
2392         
2393         prop = RNA_def_property(srna, "use_self_type", PROP_BOOLEAN, PROP_NONE);
2394         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2395         RNA_def_property_boolean_funcs(prop, "rna_Function_use_self_type_get", NULL);
2396         RNA_def_property_ui_text(prop, "Use Self Type",
2397                                  "Function passes its self type as an argument (becomes a class method in python if use_self is false)");
2398 }
2399
2400 static void rna_def_number_property(StructRNA *srna, PropertyType type)
2401 {
2402         PropertyRNA *prop;
2403
2404         prop = RNA_def_property(srna, "default", type, PROP_NONE);
2405         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2406         RNA_def_property_ui_text(prop, "Default", "Default value for this number");
2407
2408         switch (type) {
2409                 case PROP_BOOLEAN:
2410                         RNA_def_property_boolean_funcs(prop, "rna_BoolProperty_default_get", NULL);
2411                         break;
2412                 case PROP_INT:
2413                         RNA_def_property_int_funcs(prop, "rna_IntProperty_default_get", NULL, NULL);
2414                         break;
2415                 case PROP_FLOAT:
2416                         RNA_def_property_float_funcs(prop, "rna_FloatProperty_default_get", NULL, NULL);
2417                         break;
2418                 default:
2419                         break;
2420         }
2421
2422
2423         prop = RNA_def_property(srna, "default_array", type, PROP_NONE);
2424         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2425         RNA_def_property_array(prop, RNA_MAX_ARRAY_DIMENSION); /* no fixed default length, important its not 0 though */
2426         RNA_def_property_flag(prop, PROP_DYNAMIC);
2427         RNA_def_property_dynamic_array_funcs(prop, "rna_NumberProperty_default_array_get_length"); /* same for all types */
2428
2429         switch (type) {
2430                 case PROP_BOOLEAN:
2431                         RNA_def_property_boolean_funcs(prop, "rna_BoolProperty_default_array_get", NULL);
2432                         break;
2433                 case PROP_INT:
2434                         RNA_def_property_int_funcs(prop, "rna_IntProperty_default_array_get", NULL, NULL);
2435                         break;
2436                 case PROP_FLOAT:
2437                         RNA_def_property_float_funcs(prop, "rna_FloatProperty_default_array_get", NULL, NULL);
2438                         break;
2439                 default:
2440                         break;
2441         }
2442         RNA_def_property_ui_text(prop, "Default Array", "Default value for this array");
2443
2444
2445         prop = RNA_def_property(srna, "array_length", PROP_INT, PROP_UNSIGNED);
2446         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2447         RNA_def_property_int_funcs(prop, "rna_Property_array_length_get", NULL, NULL);
2448         RNA_def_property_ui_text(prop, "Array Length", "Maximum length of the array, 0 means unlimited");
2449
2450         prop = RNA_def_property(srna, "array_dimensions", PROP_INT, PROP_UNSIGNED);
2451         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2452         RNA_def_property_array(prop, RNA_MAX_ARRAY_DIMENSION);
2453         RNA_def_property_int_funcs(prop, "rna_Property_array_dimensions_get", NULL, NULL);
2454         RNA_def_property_ui_text(prop, "Array Dimensions", "Length of each dimension of the array");
2455
2456         prop = RNA_def_property(srna, "is_array", PROP_BOOLEAN, PROP_NONE);
2457         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2458         RNA_def_property_boolean_funcs(prop, "rna_NumberProperty_is_array_get", NULL);
2459         RNA_def_property_ui_text(prop, "Is Array", "");
2460
2461         if (type == PROP_BOOLEAN)
2462                 return;
2463
2464         prop = RNA_def_property(srna, "hard_min", type, PROP_NONE);
2465         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2466         if (type == PROP_INT) RNA_def_property_int_funcs(prop, "rna_IntProperty_hard_min_get", NULL, NULL);
2467         else RNA_def_property_float_funcs(prop, "rna_FloatProperty_hard_min_get", NULL, NULL);
2468         RNA_def_property_ui_text(prop, "Hard Minimum", "Minimum value used by buttons");
2469
2470         prop = RNA_def_property(srna, "hard_max", type, PROP_NONE);
2471         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2472         if (type == PROP_INT) RNA_def_property_int_funcs(prop, "rna_IntProperty_hard_max_get", NULL, NULL);
2473         else RNA_def_property_float_funcs(prop, "rna_FloatProperty_hard_max_get", NULL, NULL);
2474         RNA_def_property_ui_text(prop, "Hard Maximum", "Maximum value used by buttons");
2475
2476         prop = RNA_def_property(srna, "soft_min", type, PROP_NONE);
2477         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2478         if (type == PROP_INT) RNA_def_property_int_funcs(prop, "rna_IntProperty_soft_min_get", NULL, NULL);
2479         else RNA_def_property_float_funcs(prop, "rna_FloatProperty_soft_min_get", NULL, NULL);
2480         RNA_def_property_ui_text(prop, "Soft Minimum", "Minimum value used by buttons");
2481
2482         prop = RNA_def_property(srna, "soft_max", type, PROP_NONE);
2483         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2484         if (type == PROP_INT) RNA_def_property_int_funcs(prop, "rna_IntProperty_soft_max_get", NULL, NULL);
2485         else RNA_def_property_float_funcs(prop, "rna_FloatProperty_soft_max_get", NULL, NULL);
2486         RNA_def_property_ui_text(prop, "Soft Maximum", "Maximum value used by buttons");
2487
2488         prop = RNA_def_property(srna, "step", type, PROP_UNSIGNED);
2489         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2490         if (type == PROP_INT) RNA_def_property_int_funcs(prop, "rna_IntProperty_step_get", NULL, NULL);
2491         else RNA_def_property_float_funcs(prop, "rna_FloatProperty_step_get", NULL, NULL);
2492         RNA_def_property_ui_text(prop, "Step", "Step size used by number buttons, for floats 1/100th of the step size");
2493
2494         if (type == PROP_FLOAT) {
2495                 prop = RNA_def_property(srna, "precision", PROP_INT, PROP_UNSIGNED);
2496                 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2497                 RNA_def_property_int_funcs(prop, "rna_FloatProperty_precision_get", NULL, NULL);
2498                 RNA_def_property_ui_text(prop, "Precision", "Number of digits after the dot used by buttons");
2499         }
2500 }
2501
2502 static void rna_def_string_property(StructRNA *srna)
2503 {
2504         PropertyRNA *prop;
2505
2506         prop = RNA_def_property(srna, "default", PROP_STRING, PROP_NONE);
2507         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2508         RNA_def_property_string_funcs(prop, "rna_StringProperty_default_get", "rna_StringProperty_default_length", NULL);
2509         RNA_def_property_ui_text(prop, "Default", "string default value");
2510
2511         prop = RNA_def_property(srna, "length_max", PROP_INT, PROP_UNSIGNED);
2512         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2513         RNA_def_property_int_funcs(prop, "rna_StringProperty_max_length_get", NULL, NULL);
2514         RNA_def_property_ui_text(prop, "Maximum Length", "Maximum length of the string, 0 means unlimited");
2515 }
2516
2517 static void rna_def_enum_property(BlenderRNA *brna, StructRNA *srna)
2518 {
2519         PropertyRNA *prop;
2520
2521         /* the itemf func is used instead, keep blender happy */
2522         static const EnumPropertyItem default_dummy_items[] = {
2523                 {PROP_NONE, "DUMMY", 0, "Dummy", ""},
2524                 {0, NULL, 0, NULL, NULL}
2525         };
2526
2527         prop = RNA_def_property(srna, "default", PROP_ENUM, PROP_NONE);
2528         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2529         RNA_def_property_enum_items(prop, default_dummy_items);
2530         RNA_def_property_enum_funcs(prop, "rna_EnumProperty_default_get", NULL, "rna_EnumProperty_default_itemf");
2531         RNA_def_property_ui_text(prop, "Default", "Default value for this enum");
2532
2533         /* same 'default' but uses 'PROP_ENUM_FLAG' */
2534         prop = RNA_def_property(srna, "default_flag", PROP_ENUM, PROP_NONE);
2535         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2536         RNA_def_property_flag(prop, PROP_ENUM_FLAG);
2537         RNA_def_property_enum_items(prop, default_dummy_items);
2538         RNA_def_property_enum_funcs(prop, "rna_EnumProperty_default_get", NULL, "rna_EnumProperty_default_itemf");
2539         RNA_def_property_ui_text(prop, "Default", "Default value for this enum");
2540
2541         prop = RNA_def_property(srna, "enum_items", PROP_COLLECTION, PROP_NONE);
2542         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2543         RNA_def_property_struct_type(prop, "EnumPropertyItem");
2544         RNA_def_property_collection_funcs(prop, "rna_EnumProperty_items_begin", "rna_iterator_array_next",
2545                                           "rna_iterator_array_end", "rna_iterator_array_get", NULL, NULL, NULL, NULL);
2546         RNA_def_property_ui_text(prop, "Items", "Possible values for the property");
2547
2548         prop = RNA_def_property(srna, "enum_items_static", PROP_COLLECTION, PROP_NONE);
2549         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2550         RNA_def_property_struct_type(prop, "EnumPropertyItem");
2551         RNA_def_property_collection_funcs(prop, "rna_EnumProperty_items_begin", "rna_iterator_array_next",
2552                                           "rna_iterator_array_end", "rna_iterator_array_get", NULL, NULL, NULL, NULL);
2553         RNA_def_property_ui_text(prop, "Static Items",
2554                                  "Possible values for the property (never calls optional dynamic generation of those)");
2555
2556         srna = RNA_def_struct(brna, "EnumPropertyItem", NULL);
2557         RNA_def_struct_ui_text(srna, "Enum Item Definition", "Definition of a choice in an RNA enum property");
2558         RNA_def_struct_ui_icon(srna, ICON_RNA);
2559
2560         prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
2561         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2562         RNA_def_property_string_funcs(prop, "rna_EnumPropertyItem_name_get", "rna_EnumPropertyItem_name_length", NULL);
2563         RNA_def_property_ui_text(prop, "Name", "Human readable name");
2564
2565         prop = RNA_def_property(srna, "description", PROP_STRING, PROP_NONE);
2566         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2567         RNA_def_property_string_funcs(prop, "rna_EnumPropertyItem_description_get",
2568                                       "rna_EnumPropertyItem_description_length", NULL);
2569         RNA_def_property_ui_text(prop, "Description", "Description of the item's purpose");
2570
2571         prop = RNA_def_property(srna, "identifier", PROP_STRING, PROP_NONE);
2572         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2573         RNA_def_property_string_funcs(prop, "rna_EnumPropertyItem_identifier_get",
2574                                       "rna_EnumPropertyItem_identifier_length", NULL);
2575         RNA_def_property_ui_text(prop, "Identifier", "Unique name used in the code and scripting");
2576         RNA_def_struct_name_property(srna, prop);
2577
2578         prop = RNA_def_property(srna, "value", PROP_INT, PROP_UNSIGNED);
2579         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2580         RNA_def_property_int_funcs(prop, "rna_EnumPropertyItem_value_get", NULL, NULL);
2581         RNA_def_property_ui_text(prop, "Value", "Value of the item");
2582
2583         prop = RNA_def_property(srna, "icon", PROP_ENUM, PROP_NONE);
2584         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2585         RNA_def_property_enum_items(prop, rna_enum_icon_items);
2586         RNA_def_property_enum_funcs(prop, "rna_EnumPropertyItem_icon_get", NULL, NULL);
2587         RNA_def_property_ui_text(prop, "Icon", "Icon of the item");
2588 }
2589
2590 static void rna_def_pointer_property(StructRNA *srna, PropertyType type)
2591 {
2592         PropertyRNA *prop;
2593
2594         prop = RNA_def_property(srna, "fixed_type", PROP_POINTER, PROP_NONE);
2595         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2596         RNA_def_property_struct_type(prop, "Struct");
2597         if (type == PROP_POINTER)
2598                 RNA_def_property_pointer_funcs(prop, "rna_PointerProperty_fixed_type_get", NULL, NULL, NULL);
2599         else
2600                 RNA_def_property_pointer_funcs(prop, "rna_CollectionProperty_fixed_type_get", NULL, NULL, NULL);
2601         RNA_def_property_ui_text(prop, "Pointer Type", "Fixed pointer type, empty if variable type");
2602 }
2603
2604 void RNA_def_rna(BlenderRNA *brna)
2605 {
2606         StructRNA *srna;
2607         PropertyRNA *prop;
2608
2609         /* Struct*/
2610         rna_def_struct(brna);
2611
2612         /* Property */
2613         rna_def_property(brna);
2614
2615         /* BoolProperty */
2616         srna = RNA_def_struct(brna, "BoolProperty", "Property");
2617         RNA_def_struct_ui_text(srna, "Boolean Definition", "RNA boolean property definition");
2618         rna_def_number_property(srna, PROP_BOOLEAN);
2619
2620         /* IntProperty */
2621         srna = RNA_def_struct(brna, "IntProperty", "Property");
2622         RNA_def_struct_ui_text(srna, "Int Definition", "RNA integer number property definition");
2623         rna_def_number_property(srna, PROP_INT);
2624
2625         /* FloatProperty */
2626         srna = RNA_def_struct(brna, "FloatProperty", "Property");
2627         RNA_def_struct_ui_text(srna, "Float Definition", "RNA floating pointer number property definition");
2628         rna_def_number_property(srna, PROP_FLOAT);
2629
2630         /* StringProperty */
2631         srna = RNA_def_struct(brna, "StringProperty", "Property");
2632         RNA_def_struct_ui_text(srna, "String Definition", "RNA text string property definition");
2633         rna_def_string_property(srna);
2634
2635         /* EnumProperty */
2636         srna = RNA_def_struct(brna, "EnumProperty", "Property");
2637         RNA_def_struct_ui_text(srna, "Enum Definition",
2638                                "RNA enumeration property definition, to choose from a number of predefined options");
2639         rna_def_enum_property(brna, srna);
2640
2641         /* PointerProperty */
2642         srna = RNA_def_struct(brna, "PointerProperty", "Property");
2643         RNA_def_struct_ui_text(srna, "Pointer Definition", "RNA pointer property to point to another RNA struct");
2644         rna_def_pointer_property(srna, PROP_POINTER);
2645
2646         /* CollectionProperty */
2647         srna = RNA_def_struct(brna, "CollectionProperty", "Property");
2648         RNA_def_struct_ui_text(srna, "Collection Definition",
2649                                "RNA collection property to define lists, arrays and mappings");
2650         rna_def_pointer_property(srna, PROP_COLLECTION);
2651         
2652         /* Function */
2653         rna_def_function(brna);
2654
2655         /* Blender RNA */
2656         srna = RNA_def_struct(brna, "BlenderRNA", NULL);
2657         RNA_def_struct_ui_text(srna, "Blender RNA", "Blender RNA structure definitions");
2658         RNA_def_struct_ui_icon(srna, ICON_RNA);
2659
2660         prop = RNA_def_property(srna, "structs", PROP_COLLECTION, PROP_NONE);
2661         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2662         RNA_def_property_struct_type(prop, "Struct");
2663         RNA_def_property_collection_funcs(prop, "rna_BlenderRNA_structs_begin", "rna_iterator_listbase_next",
2664                                           "rna_iterator_listbase_end", "rna_iterator_listbase_get",
2665                                           /* included for speed, can be removed */
2666 #if 0
2667                                           NULL, NULL, NULL, NULL);
2668 #else
2669                                           "rna_BlenderRNA_structs_length", "rna_BlenderRNA_structs_lookup_int",
2670                                           "rna_BlenderRNA_structs_lookup_string", NULL);
2671 #endif
2672
2673         RNA_def_property_ui_text(prop, "Structs", "");
2674 }
2675
2676 #endif