4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * Contributor(s): Blender Foundation (2008).
22 * ***** END GPL LICENSE BLOCK *****
28 #include "MEM_guardedalloc.h"
31 #include "DNA_windowmanager_types.h"
33 #include "BLI_blenlib.h"
34 #include "BLI_dynstr.h"
35 #include "BLI_ghash.h"
37 #include "BKE_context.h"
38 #include "BKE_idprop.h"
39 #include "BKE_report.h"
40 #include "BKE_utildefines.h"
44 #include "RNA_access.h"
45 #include "RNA_define.h"
46 #include "RNA_types.h"
49 #include "DNA_object_types.h"
50 #include "BKE_depsgraph.h"
53 #include "rna_internal.h"
62 for(srna=BLENDER_RNA.structs.first; srna; srna=srna->cont.next) {
63 if(!srna->cont.prophash) {
64 srna->cont.prophash= BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp);
66 for(prop=srna->cont.properties.first; prop; prop=prop->next)
67 if(!(prop->flag & PROP_BUILTIN))
68 BLI_ghash_insert(srna->cont.prophash, (void*)prop->identifier, prop);
77 for(srna=BLENDER_RNA.structs.first; srna; srna=srna->cont.next) {
78 if(srna->cont.prophash) {
79 BLI_ghash_free(srna->cont.prophash, NULL, NULL);
80 srna->cont.prophash= NULL;
84 RNA_free(&BLENDER_RNA);
89 PointerRNA PointerRNA_NULL = {{0}, 0, 0};
91 void RNA_main_pointer_create(struct Main *main, PointerRNA *r_ptr)
94 r_ptr->type= &RNA_Main;
98 void RNA_id_pointer_create(ID *id, PointerRNA *r_ptr)
101 StructRNA *type, *idtype= NULL;
104 memset(&tmp, 0, sizeof(tmp));
106 idtype= rna_ID_refine(&tmp);
108 while(idtype->refine) {
109 type= idtype->refine(&tmp);
123 void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
126 StructRNA *idtype= NULL;
129 memset(&tmp, 0, sizeof(tmp));
131 idtype= rna_ID_refine(&tmp);
139 while(r_ptr->type && r_ptr->type->refine) {
140 StructRNA *rtype= r_ptr->type->refine(r_ptr);
142 if(rtype == r_ptr->type)
150 static void rna_pointer_inherit_id(StructRNA *type, PointerRNA *parent, PointerRNA *ptr)
152 if(type && type->flag & STRUCT_ID) {
153 ptr->id.data= ptr->data;
156 ptr->id.data= parent->id.data;
160 void RNA_blender_rna_pointer_create(PointerRNA *r_ptr)
162 r_ptr->id.data= NULL;
163 r_ptr->type= &RNA_BlenderRNA;
164 r_ptr->data= &BLENDER_RNA;
167 PointerRNA rna_pointer_inherit_refine(PointerRNA *ptr, StructRNA *type, void *data)
174 rna_pointer_inherit_id(type, ptr, &result);
176 while(result.type->refine) {
177 type= result.type->refine(&result);
179 if(type == result.type)
186 memset(&result, 0, sizeof(result));
193 /* return a UI local ID prop definition for this prop */
194 IDProperty *rna_idproperty_ui(PropertyRNA *prop)
198 for(idprop= ((IDProperty *)prop)->prev; idprop; idprop= idprop->prev) {
199 if (strcmp(RNA_IDP_UI, idprop->name)==0)
204 for(idprop= ((IDProperty *)prop)->next; idprop; idprop= idprop->next) {
205 if (strcmp(RNA_IDP_UI, idprop->name)==0)
211 return IDP_GetPropertyFromGroup(idprop, ((IDProperty *)prop)->name);
216 IDProperty *RNA_struct_idproperties(PointerRNA *ptr, int create)
218 StructRNA *type= ptr->type;
220 if(type && type->idproperties)
221 return type->idproperties(ptr, create);
226 int RNA_struct_idproperties_check(PointerRNA *ptr)
228 StructRNA *type= ptr->type;
229 return (type && type->idproperties) ? 1 : 0;
232 static IDProperty *rna_idproperty_find(PointerRNA *ptr, const char *name)
234 IDProperty *group= RNA_struct_idproperties(ptr, 0);
238 for(idprop=group->data.group.first; idprop; idprop=idprop->next)
239 if(strcmp(idprop->name, name) == 0)
246 static int rna_ensure_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
248 if(prop->magic == RNA_MAGIC) {
249 int arraylen[RNA_MAX_ARRAY_DIMENSION];
250 return (prop->getlength)? prop->getlength(ptr, arraylen): prop->totarraylength;
253 IDProperty *idprop= (IDProperty*)prop;
255 if(idprop->type == IDP_ARRAY)
262 static int rna_ensure_property_array_check(PointerRNA *ptr, PropertyRNA *prop)
264 if(prop->magic == RNA_MAGIC) {
265 return (prop->getlength || prop->totarraylength) ? 1:0;
268 IDProperty *idprop= (IDProperty*)prop;
270 return idprop->type == IDP_ARRAY ? 1:0;
274 static void rna_ensure_property_multi_array_length(PointerRNA *ptr, PropertyRNA *prop, int length[])
276 if(prop->magic == RNA_MAGIC) {
278 prop->getlength(ptr, length);
280 memcpy(length, prop->arraylength, prop->arraydimension*sizeof(int));
283 IDProperty *idprop= (IDProperty*)prop;
285 if(idprop->type == IDP_ARRAY)
286 length[0]= idprop->len;
292 static int rna_idproperty_verify_valid(PointerRNA *ptr, PropertyRNA *prop, IDProperty *idprop)
294 /* this verifies if the idproperty actually matches the property
295 * description and otherwise removes it. this is to ensure that
296 * rna property access is type safe, e.g. if you defined the rna
297 * to have a certain array length you can count on that staying so */
299 switch(idprop->type) {
301 if(prop->type != PROP_COLLECTION)
305 if(rna_ensure_property_array_length(ptr, prop) != idprop->len)
308 if(idprop->subtype == IDP_FLOAT && prop->type != PROP_FLOAT)
310 if(idprop->subtype == IDP_INT && !ELEM3(prop->type, PROP_BOOLEAN, PROP_INT, PROP_ENUM))
315 if(!ELEM3(prop->type, PROP_BOOLEAN, PROP_INT, PROP_ENUM))
320 if(prop->type != PROP_FLOAT)
324 if(prop->type != PROP_STRING)
328 if(prop->type != PROP_POINTER)
338 static PropertyRNA *typemap[IDP_NUMTYPES] =
339 {(PropertyRNA*)&rna_IDProperty_string,
340 (PropertyRNA*)&rna_IDProperty_int,
341 (PropertyRNA*)&rna_IDProperty_float,
343 (PropertyRNA*)&rna_IDProperty_group, NULL,
344 (PropertyRNA*)&rna_IDProperty_double};
346 static PropertyRNA *arraytypemap[IDP_NUMTYPES] =
347 {NULL, (PropertyRNA*)&rna_IDProperty_int_array,
348 (PropertyRNA*)&rna_IDProperty_float_array,
350 (PropertyRNA*)&rna_IDProperty_collection, NULL,
351 (PropertyRNA*)&rna_IDProperty_double_array};
353 IDProperty *rna_idproperty_check(PropertyRNA **prop, PointerRNA *ptr)
355 /* This is quite a hack, but avoids some complexity in the API. we
356 * pass IDProperty structs as PropertyRNA pointers to the outside.
357 * We store some bytes in PropertyRNA structs that allows us to
358 * distinguish it from IDProperty structs. If it is an ID property,
359 * we look up an IDP PropertyRNA based on the type, and set the data
360 * pointer to the IDProperty. */
362 if((*prop)->magic == RNA_MAGIC) {
363 if((*prop)->flag & PROP_IDPROPERTY) {
364 IDProperty *idprop= rna_idproperty_find(ptr, (*prop)->identifier);
366 if(idprop && !rna_idproperty_verify_valid(ptr, *prop, idprop)) {
367 IDProperty *group= RNA_struct_idproperties(ptr, 0);
369 IDP_RemFromGroup(group, idprop);
370 IDP_FreeProperty(idprop);
382 IDProperty *idprop= (IDProperty*)(*prop);
384 if(idprop->type == IDP_ARRAY)
385 *prop= arraytypemap[(int)(idprop->subtype)];
387 *prop= typemap[(int)(idprop->type)];
393 static PropertyRNA *rna_ensure_property(PropertyRNA *prop)
395 /* the quick version if we don't need the idproperty */
397 if(prop->magic == RNA_MAGIC)
401 IDProperty *idprop= (IDProperty*)prop;
403 if(idprop->type == IDP_ARRAY)
404 return arraytypemap[(int)(idprop->subtype)];
406 return typemap[(int)(idprop->type)];
410 static const char *rna_ensure_property_identifier(PropertyRNA *prop)
412 if(prop->magic == RNA_MAGIC)
413 return prop->identifier;
415 return ((IDProperty*)prop)->name;
418 static const char *rna_ensure_property_description(PropertyRNA *prop)
420 if(prop->magic == RNA_MAGIC)
421 return prop->description;
423 /* attempt to get the local ID values */
424 IDProperty *idp_ui= rna_idproperty_ui(prop);
426 if(idp_ui) { /* TODO, type checking on ID props */
427 IDProperty *item= IDP_GetPropertyFromGroup(idp_ui, "description");
428 return item ? ((IDProperty*)prop)->name : item->data.pointer;
431 return ((IDProperty*)prop)->name; /* XXX - not correct */
435 static const char *rna_ensure_property_name(PropertyRNA *prop)
437 if(prop->magic == RNA_MAGIC)
440 return ((IDProperty*)prop)->name;
445 const char *RNA_struct_identifier(StructRNA *type)
447 return type->identifier;
450 const char *RNA_struct_ui_name(StructRNA *type)
455 int RNA_struct_ui_icon(StructRNA *type)
463 const char *RNA_struct_ui_description(StructRNA *type)
465 return type->description;
468 PropertyRNA *RNA_struct_name_property(StructRNA *type)
470 return type->nameproperty;
473 PropertyRNA *RNA_struct_iterator_property(StructRNA *type)
475 return type->iteratorproperty;
478 StructRNA *RNA_struct_base(StructRNA *type)
483 int RNA_struct_is_ID(StructRNA *type)
485 return (type->flag & STRUCT_ID) != 0;
488 int RNA_struct_is_a(StructRNA *type, StructRNA *srna)
495 /* ptr->type is always maximally refined */
496 for(base=type; base; base=base->base)
503 PropertyRNA *RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
505 if(identifier[0]=='[' && identifier[1]=='"') {
506 /* id prop lookup, not so common */
507 PropertyRNA *r_prop= NULL;
508 PointerRNA r_ptr; /* only support single level props */
509 if(RNA_path_resolve(ptr, identifier, &r_ptr, &r_prop) && r_ptr.type==ptr->type && r_ptr.data==ptr->data)
513 /* most common case */
514 PropertyRNA *iterprop= RNA_struct_iterator_property(ptr->type);
517 if(RNA_property_collection_lookup_string(ptr, iterprop, identifier, &propptr))
524 /* Find the property which uses the given nested struct */
525 PropertyRNA *RNA_struct_find_nested(PointerRNA *ptr, StructRNA *srna)
527 PropertyRNA *prop= NULL;
529 RNA_STRUCT_BEGIN(ptr, iprop) {
530 /* This assumes that there can only be one user of this nested struct */
531 if (RNA_property_pointer_type(ptr, iprop) == srna) {
541 const struct ListBase *RNA_struct_defined_properties(StructRNA *srna)
543 return &srna->cont.properties;
546 FunctionRNA *RNA_struct_find_function(PointerRNA *ptr, const char *identifier)
549 PropertyRNA *iterprop;
552 RNA_pointer_create(NULL, &RNA_Struct, ptr->type, &tptr);
553 iterprop= RNA_struct_find_property(&tptr, "functions");
557 RNA_PROP_BEGIN(&tptr, funcptr, iterprop) {
558 if(strcmp(identifier, RNA_function_identifier(funcptr.data)) == 0) {
568 const struct ListBase *RNA_struct_defined_functions(StructRNA *srna)
570 return &srna->functions;
573 StructRegisterFunc RNA_struct_register(StructRNA *type)
578 StructUnregisterFunc RNA_struct_unregister(StructRNA *type)
583 } while((type=type->base));
588 void *RNA_struct_py_type_get(StructRNA *srna)
590 return srna->py_type;
593 void RNA_struct_py_type_set(StructRNA *srna, void *py_type)
595 srna->py_type= py_type;
598 void *RNA_struct_blender_type_get(StructRNA *srna)
600 return srna->blender_type;
603 void RNA_struct_blender_type_set(StructRNA *srna, void *blender_type)
605 srna->blender_type= blender_type;
608 char *RNA_struct_name_get_alloc(PointerRNA *ptr, char *fixedbuf, int fixedlen)
610 PropertyRNA *nameprop;
612 if(ptr->data && (nameprop = RNA_struct_name_property(ptr->type)))
613 return RNA_property_string_get_alloc(ptr, nameprop, fixedbuf, fixedlen);
618 /* Property Information */
620 const char *RNA_property_identifier(PropertyRNA *prop)
622 return rna_ensure_property_identifier(prop);
625 const char *RNA_property_description(PropertyRNA *prop)
627 return rna_ensure_property_description(prop);
630 PropertyType RNA_property_type(PropertyRNA *prop)
632 return rna_ensure_property(prop)->type;
635 PropertySubType RNA_property_subtype(PropertyRNA *prop)
637 return rna_ensure_property(prop)->subtype;
640 PropertyUnit RNA_property_unit(PropertyRNA *prop)
642 return RNA_SUBTYPE_UNIT(rna_ensure_property(prop)->subtype);
645 int RNA_property_flag(PropertyRNA *prop)
647 return rna_ensure_property(prop)->flag;
650 int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
652 return rna_ensure_property_array_length(ptr, prop);
655 int RNA_property_array_check(PointerRNA *ptr, PropertyRNA *prop)
657 return rna_ensure_property_array_check(ptr, prop);
660 /* used by BPY to make an array from the python object */
661 int RNA_property_array_dimension(PointerRNA *ptr, PropertyRNA *prop, int length[])
663 PropertyRNA *rprop= rna_ensure_property(prop);
665 if(length && rprop->arraydimension > 1)
666 rna_ensure_property_multi_array_length(ptr, prop, length);
668 return rprop->arraydimension;
671 /* Return the size of Nth dimension. */
672 int RNA_property_multi_array_length(PointerRNA *ptr, PropertyRNA *prop, int dim)
674 int len[RNA_MAX_ARRAY_DIMENSION];
676 rna_ensure_property_multi_array_length(ptr, prop, len);
681 char RNA_property_array_item_char(PropertyRNA *prop, int index)
683 const char *vectoritem= "XYZW";
684 const char *quatitem= "WXYZ";
685 const char *coloritem= "RGBA";
686 PropertySubType subtype= rna_ensure_property(prop)->subtype;
688 /* get string to use for array index */
689 if ((index < 4) && ELEM(subtype, PROP_QUATERNION, PROP_AXISANGLE))
690 return quatitem[index];
691 else if((index < 4) && ELEM6(subtype, PROP_TRANSLATION, PROP_DIRECTION, PROP_XYZ, PROP_EULER, PROP_VELOCITY, PROP_ACCELERATION))
692 return vectoritem[index];
693 else if ((index < 4) && ELEM(subtype, PROP_COLOR, PROP_RGB))
694 return coloritem[index];
699 void RNA_property_int_range(PointerRNA *ptr, PropertyRNA *prop, int *hardmin, int *hardmax)
701 IntPropertyRNA *iprop= (IntPropertyRNA*)rna_ensure_property(prop);
703 if(prop->magic != RNA_MAGIC) {
704 /* attempt to get the local ID values */
705 IDProperty *idp_ui= rna_idproperty_ui(prop);
708 if(idp_ui) { /* TODO, type checking on ID props */
709 item= IDP_GetPropertyFromGroup(idp_ui, "min");
710 *hardmin= item ? item->data.val : INT_MIN;
712 item= IDP_GetPropertyFromGroup(idp_ui, "max");
713 *hardmax= item ? item->data.val : INT_MAX;
720 iprop->range(ptr, hardmin, hardmax);
723 *hardmin= iprop->hardmin;
724 *hardmax= iprop->hardmax;
728 void RNA_property_int_ui_range(PointerRNA *ptr, PropertyRNA *prop, int *softmin, int *softmax, int *step)
730 IntPropertyRNA *iprop= (IntPropertyRNA*)rna_ensure_property(prop);
731 int hardmin, hardmax;
733 if(prop->magic != RNA_MAGIC) {
734 /* attempt to get the local ID values */
735 IDProperty *idp_ui= rna_idproperty_ui(prop);
738 if(idp_ui) { /* TODO, type checking on ID props */
739 item= IDP_GetPropertyFromGroup(idp_ui, "soft_min");
740 *softmin= item ? item->data.val : INT_MIN;
742 item= IDP_GetPropertyFromGroup(idp_ui, "soft_max");
743 *softmax= item ? item->data.val : INT_MAX;
745 item= IDP_GetPropertyFromGroup(idp_ui, "step");
746 *step= item ? item->data.val : 1;
753 iprop->range(ptr, &hardmin, &hardmax);
754 *softmin= MAX2(iprop->softmin, hardmin);
755 *softmax= MIN2(iprop->softmax, hardmax);
758 *softmin= iprop->softmin;
759 *softmax= iprop->softmax;
765 void RNA_property_float_range(PointerRNA *ptr, PropertyRNA *prop, float *hardmin, float *hardmax)
767 FloatPropertyRNA *fprop= (FloatPropertyRNA*)rna_ensure_property(prop);
769 if(prop->magic != RNA_MAGIC) {
770 /* attempt to get the local ID values */
771 IDProperty *idp_ui= rna_idproperty_ui(prop);
774 if(idp_ui) { /* TODO, type checking on ID props */
775 item= IDP_GetPropertyFromGroup(idp_ui, "min");
776 *hardmin= item ? *(double*)&item->data.val : FLT_MIN;
778 item= IDP_GetPropertyFromGroup(idp_ui, "max");
779 *hardmax= item ? *(double*)&item->data.val : FLT_MAX;
786 fprop->range(ptr, hardmin, hardmax);
789 *hardmin= fprop->hardmin;
790 *hardmax= fprop->hardmax;
794 void RNA_property_float_ui_range(PointerRNA *ptr, PropertyRNA *prop, float *softmin, float *softmax, float *step, float *precision)
796 FloatPropertyRNA *fprop= (FloatPropertyRNA*)rna_ensure_property(prop);
797 float hardmin, hardmax;
799 if(prop->magic != RNA_MAGIC) {
800 /* attempt to get the local ID values */
801 IDProperty *idp_ui= rna_idproperty_ui(prop);
804 if(idp_ui) { /* TODO, type checking on ID props */
805 item= IDP_GetPropertyFromGroup(idp_ui, "soft_min");
806 *softmin= item ? *(double*)&item->data.val : FLT_MIN;
808 item= IDP_GetPropertyFromGroup(idp_ui, "soft_max");
809 *softmax= item ? *(double*)&item->data.val : FLT_MAX;
811 item= IDP_GetPropertyFromGroup(idp_ui, "step");
812 *step= item ? *(double*)&item->data.val : 1.0f;
814 item= IDP_GetPropertyFromGroup(idp_ui, "precision");
815 *precision= item ? *(double*)&item->data.val : 3.0f;
822 fprop->range(ptr, &hardmin, &hardmax);
823 *softmin= MAX2(fprop->softmin, hardmin);
824 *softmax= MIN2(fprop->softmax, hardmax);
827 *softmin= fprop->softmin;
828 *softmax= fprop->softmax;
832 *precision= (float)fprop->precision;
835 int RNA_property_string_maxlength(PropertyRNA *prop)
837 StringPropertyRNA *sprop= (StringPropertyRNA*)rna_ensure_property(prop);
838 return sprop->maxlength;
841 StructRNA *RNA_property_pointer_type(PointerRNA *ptr, PropertyRNA *prop)
843 prop= rna_ensure_property(prop);
845 if(prop->type == PROP_POINTER) {
846 PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
849 return pprop->typef(ptr);
853 else if(prop->type == PROP_COLLECTION) {
854 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
857 return cprop->item_type;
860 return &RNA_UnknownType;
863 /* Reuse for dynamic types */
864 EnumPropertyItem DummyRNA_NULL_items[] = {
865 {0, NULL, 0, NULL, NULL}
868 void RNA_property_enum_items(bContext *C, PointerRNA *ptr, PropertyRNA *prop, EnumPropertyItem **item, int *totitem, int *free)
870 EnumPropertyRNA *eprop= (EnumPropertyRNA*)rna_ensure_property(prop);
874 if(eprop->itemf && C) {
876 *item= eprop->itemf(C, ptr, free);
880 for( ; (*item)[tot].identifier; tot++);
889 *totitem= eprop->totitem;
893 int RNA_property_enum_value(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const char *identifier, int *value)
895 EnumPropertyItem *item;
898 RNA_property_enum_items(C, ptr, prop, &item, NULL, &free);
900 for(; item->identifier; item++) {
901 if(item->identifier[0] && strcmp(item->identifier, identifier)==0) {
902 *value = item->value;
913 int RNA_enum_identifier(EnumPropertyItem *item, const int value, const char **identifier)
915 for (; item->identifier; item++) {
916 if(item->identifier[0] && item->value==value) {
917 *identifier = item->identifier;
924 int RNA_enum_name(EnumPropertyItem *item, const int value, const char **name)
926 for (; item->identifier; item++) {
927 if(item->identifier[0] && item->value==value) {
935 int RNA_property_enum_identifier(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **identifier)
937 EnumPropertyItem *item= NULL;
940 RNA_property_enum_items(C, ptr, prop, &item, NULL, &free);
942 result= RNA_enum_identifier(item, value, identifier);
951 const char *RNA_property_ui_name(PropertyRNA *prop)
953 return rna_ensure_property_name(prop);
956 const char *RNA_property_ui_description(PropertyRNA *prop)
958 return rna_ensure_property(prop)->description;
961 int RNA_property_ui_icon(PropertyRNA *prop)
963 return rna_ensure_property(prop)->icon;
966 int RNA_property_editable(PointerRNA *ptr, PropertyRNA *prop)
971 prop= rna_ensure_property(prop);
974 flag= prop->editable(ptr);
980 return (flag & PROP_EDITABLE) && (!id || !id->lib || (flag & PROP_LIB_EXCEPTION));
983 int RNA_property_animateable(PointerRNA *ptr, PropertyRNA *prop)
987 prop= rna_ensure_property(prop);
989 if(!(prop->flag & PROP_ANIMATEABLE))
993 flag= prop->editable(ptr);
997 return (flag & PROP_EDITABLE);
1000 int RNA_property_animated(PointerRNA *ptr, PropertyRNA *prop)
1002 /* would need to ask animation system */
1007 void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
1009 int is_rna = (prop->magic == RNA_MAGIC);
1010 prop= rna_ensure_property(prop);
1014 prop->update(C, ptr);
1016 WM_event_add_notifier(C, prop->noteflag, ptr->id.data);
1019 /* WARNING! This is so property drivers update the display!
1020 * not especially nice */
1021 DAG_id_flush_update(ptr->id.data, OB_RECALC_OB);
1022 WM_event_add_notifier(C, NC_WINDOW, NULL);
1028 int RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
1030 BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
1033 if((idprop=rna_idproperty_check(&prop, ptr)))
1034 return IDP_Int(idprop);
1036 return bprop->get(ptr);
1038 return bprop->defaultvalue;
1041 void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, int value)
1043 BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
1046 /* just incase other values are passed */
1049 if((idprop=rna_idproperty_check(&prop, ptr)))
1050 IDP_Int(idprop)= value;
1052 bprop->set(ptr, value);
1053 else if(prop->flag & PROP_EDITABLE) {
1054 IDPropertyTemplate val = {0};
1059 group= RNA_struct_idproperties(ptr, 1);
1061 IDP_AddToGroup(group, IDP_New(IDP_INT, val, (char*)prop->identifier));
1065 void RNA_property_boolean_get_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
1067 BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
1070 if((idprop=rna_idproperty_check(&prop, ptr))) {
1071 if(prop->arraydimension == 0)
1072 values[0]= RNA_property_boolean_get(ptr, prop);
1074 memcpy(values, IDP_Array(idprop), sizeof(int)*idprop->len);
1076 else if(prop->arraydimension == 0)
1077 values[0]= RNA_property_boolean_get(ptr, prop);
1078 else if(bprop->getarray)
1079 bprop->getarray(ptr, values);
1080 else if(bprop->defaultarray)
1081 memcpy(values, bprop->defaultarray, sizeof(int)*prop->totarraylength);
1083 memset(values, 0, sizeof(int)*prop->totarraylength);
1086 int RNA_property_boolean_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
1088 int tmp[RNA_MAX_ARRAY_LENGTH];
1089 int len= rna_ensure_property_array_length(ptr, prop);
1091 if(len <= RNA_MAX_ARRAY_LENGTH) {
1092 RNA_property_boolean_get_array(ptr, prop, tmp);
1096 int *tmparray, value;
1098 tmparray= MEM_callocN(sizeof(int)*len, "RNA_property_boolean_get_index");
1099 RNA_property_boolean_get_array(ptr, prop, tmparray);
1100 value= tmparray[index];
1101 MEM_freeN(tmparray);
1107 void RNA_property_boolean_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *values)
1109 BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
1112 if((idprop=rna_idproperty_check(&prop, ptr))) {
1113 if(prop->arraydimension == 0)
1114 IDP_Int(idprop)= values[0];
1116 memcpy(IDP_Array(idprop), values, sizeof(int)*idprop->len);
1118 else if(prop->arraydimension == 0)
1119 RNA_property_boolean_set(ptr, prop, values[0]);
1120 else if(bprop->setarray)
1121 bprop->setarray(ptr, values);
1122 else if(prop->flag & PROP_EDITABLE) {
1123 IDPropertyTemplate val = {0};
1126 val.array.len= prop->totarraylength;
1127 val.array.type= IDP_INT;
1129 group= RNA_struct_idproperties(ptr, 1);
1131 idprop= IDP_New(IDP_ARRAY, val, (char*)prop->identifier);
1132 IDP_AddToGroup(group, idprop);
1133 memcpy(IDP_Array(idprop), values, sizeof(int)*idprop->len);
1138 void RNA_property_boolean_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, int value)
1140 int tmp[RNA_MAX_ARRAY_LENGTH];
1141 int len= rna_ensure_property_array_length(ptr, prop);
1143 if(len <= RNA_MAX_ARRAY_LENGTH) {
1144 RNA_property_boolean_get_array(ptr, prop, tmp);
1146 RNA_property_boolean_set_array(ptr, prop, tmp);
1151 tmparray= MEM_callocN(sizeof(int)*len, "RNA_property_boolean_get_index");
1152 RNA_property_boolean_get_array(ptr, prop, tmparray);
1153 tmparray[index]= value;
1154 RNA_property_boolean_set_array(ptr, prop, tmparray);
1155 MEM_freeN(tmparray);
1159 int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
1161 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
1164 if((idprop=rna_idproperty_check(&prop, ptr)))
1165 return IDP_Int(idprop);
1167 return iprop->get(ptr);
1169 return iprop->defaultvalue;
1172 void RNA_property_int_set(PointerRNA *ptr, PropertyRNA *prop, int value)
1174 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
1177 if((idprop=rna_idproperty_check(&prop, ptr)))
1178 IDP_Int(idprop)= value;
1180 iprop->set(ptr, value);
1181 else if(prop->flag & PROP_EDITABLE) {
1182 IDPropertyTemplate val = {0};
1187 group= RNA_struct_idproperties(ptr, 1);
1189 IDP_AddToGroup(group, IDP_New(IDP_INT, val, (char*)prop->identifier));
1193 void RNA_property_int_get_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
1195 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
1198 if((idprop=rna_idproperty_check(&prop, ptr))) {
1199 if(prop->arraydimension == 0)
1200 values[0]= RNA_property_int_get(ptr, prop);
1202 memcpy(values, IDP_Array(idprop), sizeof(int)*idprop->len);
1204 else if(prop->arraydimension == 0)
1205 values[0]= RNA_property_int_get(ptr, prop);
1206 else if(iprop->getarray)
1207 iprop->getarray(ptr, values);
1208 else if(iprop->defaultarray)
1209 memcpy(values, iprop->defaultarray, sizeof(int)*prop->totarraylength);
1211 memset(values, 0, sizeof(int)*prop->totarraylength);
1214 int RNA_property_int_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
1216 int tmp[RNA_MAX_ARRAY_LENGTH];
1217 int len= rna_ensure_property_array_length(ptr, prop);
1219 if(len <= RNA_MAX_ARRAY_LENGTH) {
1220 RNA_property_int_get_array(ptr, prop, tmp);
1224 int *tmparray, value;
1226 tmparray= MEM_callocN(sizeof(int)*len, "RNA_property_int_get_index");
1227 RNA_property_int_get_array(ptr, prop, tmparray);
1228 value= tmparray[index];
1229 MEM_freeN(tmparray);
1235 void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *values)
1237 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
1240 if((idprop=rna_idproperty_check(&prop, ptr))) {
1241 if(prop->arraydimension == 0)
1242 IDP_Int(idprop)= values[0];
1244 memcpy(IDP_Array(idprop), values, sizeof(int)*idprop->len);\
1246 else if(prop->arraydimension == 0)
1247 RNA_property_int_set(ptr, prop, values[0]);
1248 else if(iprop->setarray)
1249 iprop->setarray(ptr, values);
1250 else if(prop->flag & PROP_EDITABLE) {
1251 IDPropertyTemplate val = {0};
1254 val.array.len= prop->totarraylength;
1255 val.array.type= IDP_INT;
1257 group= RNA_struct_idproperties(ptr, 1);
1259 idprop= IDP_New(IDP_ARRAY, val, (char*)prop->identifier);
1260 IDP_AddToGroup(group, idprop);
1261 memcpy(IDP_Array(idprop), values, sizeof(int)*idprop->len);
1266 void RNA_property_int_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, int value)
1268 int tmp[RNA_MAX_ARRAY_LENGTH];
1269 int len= rna_ensure_property_array_length(ptr, prop);
1271 if(len <= RNA_MAX_ARRAY_LENGTH) {
1272 RNA_property_int_get_array(ptr, prop, tmp);
1274 RNA_property_int_set_array(ptr, prop, tmp);
1279 tmparray= MEM_callocN(sizeof(int)*len, "RNA_property_int_get_index");
1280 RNA_property_int_get_array(ptr, prop, tmparray);
1281 tmparray[index]= value;
1282 RNA_property_int_set_array(ptr, prop, tmparray);
1283 MEM_freeN(tmparray);
1287 float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop)
1289 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
1292 if((idprop=rna_idproperty_check(&prop, ptr))) {
1293 if(idprop->type == IDP_FLOAT)
1294 return IDP_Float(idprop);
1296 return (float)IDP_Double(idprop);
1299 return fprop->get(ptr);
1301 return fprop->defaultvalue;
1304 void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value)
1306 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
1309 if((idprop=rna_idproperty_check(&prop, ptr))) {
1310 if(idprop->type == IDP_FLOAT)
1311 IDP_Float(idprop)= value;
1313 IDP_Double(idprop)= value;
1315 else if(fprop->set) {
1316 fprop->set(ptr, value);
1318 else if(prop->flag & PROP_EDITABLE) {
1319 IDPropertyTemplate val = {0};
1324 group= RNA_struct_idproperties(ptr, 1);
1326 IDP_AddToGroup(group, IDP_New(IDP_FLOAT, val, (char*)prop->identifier));
1330 void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
1332 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
1336 if((idprop=rna_idproperty_check(&prop, ptr))) {
1337 if(prop->arraydimension == 0)
1338 values[0]= RNA_property_float_get(ptr, prop);
1339 else if(idprop->subtype == IDP_FLOAT) {
1340 memcpy(values, IDP_Array(idprop), sizeof(float)*idprop->len);
1343 for(i=0; i<idprop->len; i++)
1344 values[i]= (float)(((double*)IDP_Array(idprop))[i]);
1347 else if(prop->arraydimension == 0)
1348 values[0]= RNA_property_float_get(ptr, prop);
1349 else if(fprop->getarray)
1350 fprop->getarray(ptr, values);
1351 else if(fprop->defaultarray)
1352 memcpy(values, fprop->defaultarray, sizeof(float)*prop->totarraylength);
1354 memset(values, 0, sizeof(float)*prop->totarraylength);
1357 float RNA_property_float_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
1359 float tmp[RNA_MAX_ARRAY_LENGTH];
1360 int len= rna_ensure_property_array_length(ptr, prop);
1362 if(len <= RNA_MAX_ARRAY_LENGTH) {
1363 RNA_property_float_get_array(ptr, prop, tmp);
1367 float *tmparray, value;
1369 tmparray= MEM_callocN(sizeof(float)*len, "RNA_property_float_get_index");
1370 RNA_property_float_get_array(ptr, prop, tmparray);
1371 value= tmparray[index];
1372 MEM_freeN(tmparray);
1379 void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const float *values)
1381 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
1385 if((idprop=rna_idproperty_check(&prop, ptr))) {
1386 if(prop->arraydimension == 0) {
1387 if(idprop->type == IDP_FLOAT)
1388 IDP_Float(idprop)= values[0];
1390 IDP_Double(idprop)= values[0];
1392 else if(idprop->subtype == IDP_FLOAT) {
1393 memcpy(IDP_Array(idprop), values, sizeof(float)*idprop->len);
1396 for(i=0; i<idprop->len; i++)
1397 ((double*)IDP_Array(idprop))[i]= values[i];
1400 else if(prop->arraydimension == 0)
1401 RNA_property_float_set(ptr, prop, values[0]);
1402 else if(fprop->setarray) {
1403 fprop->setarray(ptr, values);
1405 else if(prop->flag & PROP_EDITABLE) {
1406 IDPropertyTemplate val = {0};
1409 val.array.len= prop->totarraylength;
1410 val.array.type= IDP_FLOAT;
1412 group= RNA_struct_idproperties(ptr, 1);
1414 idprop= IDP_New(IDP_ARRAY, val, (char*)prop->identifier);
1415 IDP_AddToGroup(group, idprop);
1416 memcpy(IDP_Array(idprop), values, sizeof(float)*idprop->len);
1421 void RNA_property_float_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, float value)
1423 float tmp[RNA_MAX_ARRAY_LENGTH];
1424 int len= rna_ensure_property_array_length(ptr, prop);
1426 if(len <= RNA_MAX_ARRAY_LENGTH) {
1427 RNA_property_float_get_array(ptr, prop, tmp);
1429 RNA_property_float_set_array(ptr, prop, tmp);
1434 tmparray= MEM_callocN(sizeof(float)*len, "RNA_property_float_get_index");
1435 RNA_property_float_get_array(ptr, prop, tmparray);
1436 tmparray[index]= value;
1437 RNA_property_float_set_array(ptr, prop, tmparray);
1438 MEM_freeN(tmparray);
1442 void RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop, char *value)
1444 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
1447 if((idprop=rna_idproperty_check(&prop, ptr)))
1448 strcpy(value, IDP_String(idprop));
1450 sprop->get(ptr, value);
1452 strcpy(value, sprop->defaultvalue);
1455 char *RNA_property_string_get_alloc(PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen)
1460 length= RNA_property_string_length(ptr, prop);
1462 if(length+1 < fixedlen)
1465 buf= MEM_callocN(sizeof(char)*(length+1), "RNA_string_get_alloc");
1467 RNA_property_string_get(ptr, prop, buf);
1472 int RNA_property_string_length(PointerRNA *ptr, PropertyRNA *prop)
1474 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
1477 if((idprop=rna_idproperty_check(&prop, ptr)))
1478 return strlen(IDP_String(idprop));
1479 else if(sprop->length)
1480 return sprop->length(ptr);
1482 return strlen(sprop->defaultvalue);
1485 void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *value)
1487 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
1490 if((idprop=rna_idproperty_check(&prop, ptr)))
1491 IDP_AssignString(idprop, (char*)value);
1493 sprop->set(ptr, value);
1494 else if(prop->flag & PROP_EDITABLE) {
1495 IDPropertyTemplate val = {0};
1498 val.str= (char*)value;
1500 group= RNA_struct_idproperties(ptr, 1);
1502 IDP_AddToGroup(group, IDP_New(IDP_STRING, val, (char*)prop->identifier));
1506 int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
1508 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
1511 if((idprop=rna_idproperty_check(&prop, ptr)))
1512 return IDP_Int(idprop);
1514 return eprop->get(ptr);
1516 return eprop->defaultvalue;
1520 void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value)
1522 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
1525 if((idprop=rna_idproperty_check(&prop, ptr)))
1526 IDP_Int(idprop)= value;
1527 else if(eprop->set) {
1528 eprop->set(ptr, value);
1530 else if(prop->flag & PROP_EDITABLE) {
1531 IDPropertyTemplate val = {0};
1536 group= RNA_struct_idproperties(ptr, 1);
1538 IDP_AddToGroup(group, IDP_New(IDP_INT, val, (char*)prop->identifier));
1542 PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop)
1544 PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
1547 if((idprop=rna_idproperty_check(&prop, ptr))) {
1548 pprop= (PointerPropertyRNA*)prop;
1550 /* for groups, data is idprop itself */
1551 return rna_pointer_inherit_refine(ptr, pprop->type, idprop);
1553 else if(pprop->get) {
1554 return pprop->get(ptr);
1556 else if(prop->flag & PROP_IDPROPERTY) {
1557 /* XXX temporary hack to add it automatically, reading should
1558 never do any write ops, to ensure thread safety etc .. */
1559 RNA_property_pointer_add(ptr, prop);
1560 return RNA_property_pointer_get(ptr, prop);
1565 memset(&result, 0, sizeof(result));
1570 void RNA_property_pointer_set(PointerRNA *ptr, PropertyRNA *prop, PointerRNA ptr_value)
1574 if((idprop=rna_idproperty_check(&prop, ptr))) {
1578 PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
1580 if(pprop->set && !((prop->flag & PROP_NEVER_NULL) && ptr_value.data == NULL))
1581 pprop->set(ptr, ptr_value);
1585 void RNA_property_pointer_add(PointerRNA *ptr, PropertyRNA *prop)
1589 if((idprop=rna_idproperty_check(&prop, ptr))) {
1590 /* already exists */
1592 else if(prop->flag & PROP_IDPROPERTY) {
1593 IDPropertyTemplate val = {0};
1598 group= RNA_struct_idproperties(ptr, 1);
1600 IDP_AddToGroup(group, IDP_New(IDP_GROUP, val, (char*)prop->identifier));
1603 printf("RNA_property_pointer_add %s.%s: only supported for id properties.\n", ptr->type->identifier, prop->identifier);
1606 void RNA_property_pointer_remove(PointerRNA *ptr, PropertyRNA *prop)
1608 IDProperty *idprop, *group;
1610 if((idprop=rna_idproperty_check(&prop, ptr))) {
1611 group= RNA_struct_idproperties(ptr, 0);
1614 IDP_RemFromGroup(group, idprop);
1615 IDP_FreeProperty(idprop);
1620 printf("RNA_property_pointer_remove %s.%s: only supported for id properties.\n", ptr->type->identifier, prop->identifier);
1623 static void rna_property_collection_get_idp(CollectionPropertyIterator *iter)
1625 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)iter->prop;
1627 iter->ptr.data= rna_iterator_array_get(iter);
1628 iter->ptr.type= cprop->item_type;
1629 rna_pointer_inherit_id(cprop->item_type, &iter->parent, &iter->ptr);
1632 void RNA_property_collection_begin(PointerRNA *ptr, PropertyRNA *prop, CollectionPropertyIterator *iter)
1636 memset(iter, 0, sizeof(*iter));
1638 if((idprop=rna_idproperty_check(&prop, ptr)) || (prop->flag & PROP_IDPROPERTY)) {
1643 rna_iterator_array_begin(iter, IDP_IDPArray(idprop), sizeof(IDProperty), idprop->len, 0, NULL);
1645 rna_iterator_array_begin(iter, NULL, sizeof(IDProperty), 0, 0, NULL);
1648 rna_property_collection_get_idp(iter);
1653 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
1654 cprop->begin(iter, ptr);
1658 void RNA_property_collection_next(CollectionPropertyIterator *iter)
1660 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)iter->prop;
1663 rna_iterator_array_next(iter);
1666 rna_property_collection_get_idp(iter);
1672 void RNA_property_collection_end(CollectionPropertyIterator *iter)
1674 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)iter->prop;
1677 rna_iterator_array_end(iter);
1682 int RNA_property_collection_length(PointerRNA *ptr, PropertyRNA *prop)
1684 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
1687 if((idprop=rna_idproperty_check(&prop, ptr))) {
1690 else if(cprop->length) {
1691 return cprop->length(ptr);
1694 CollectionPropertyIterator iter;
1697 RNA_property_collection_begin(ptr, prop, &iter);
1698 for(; iter.valid; RNA_property_collection_next(&iter))
1700 RNA_property_collection_end(&iter);
1706 void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *r_ptr)
1709 // CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
1711 if((idprop=rna_idproperty_check(&prop, ptr))) {
1712 IDPropertyTemplate val = {0};
1715 item= IDP_New(IDP_GROUP, val, "");
1716 IDP_AppendArray(idprop, item);
1717 IDP_FreeProperty(item);
1720 else if(prop->flag & PROP_IDPROPERTY) {
1721 IDProperty *group, *item;
1722 IDPropertyTemplate val = {0};
1724 group= RNA_struct_idproperties(ptr, 1);
1726 idprop= IDP_NewIDPArray(prop->identifier);
1727 IDP_AddToGroup(group, idprop);
1729 item= IDP_New(IDP_GROUP, val, "");
1730 IDP_AppendArray(idprop, item);
1731 IDP_FreeProperty(item);
1736 /* py api calls directly */
1738 else if(cprop->add){
1739 if(!(cprop->add->flag & FUNC_USE_CONTEXT)) { /* XXX check for this somewhere else */
1740 ParameterList params;
1741 RNA_parameter_list_create(¶ms, ptr, cprop->add);
1742 RNA_function_call(NULL, NULL, ptr, cprop->add, ¶ms);
1743 RNA_parameter_list_free(¶ms);
1747 printf("RNA_property_collection_add %s.%s: not implemented for this property.\n", ptr->type->identifier, prop->identifier);*/
1752 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
1754 r_ptr->data= IDP_GetIndexArray(idprop, idprop->len-1);
1755 r_ptr->type= cprop->item_type;
1756 rna_pointer_inherit_id(NULL, ptr, r_ptr);
1759 memset(r_ptr, 0, sizeof(*r_ptr));
1763 int RNA_property_collection_remove(PointerRNA *ptr, PropertyRNA *prop, int key)
1766 // CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
1768 if((idprop=rna_idproperty_check(&prop, ptr))) {
1769 IDProperty tmp, *array;
1773 array= IDP_IDPArray(idprop);
1775 if(key >= 0 && key < len) {
1777 /* move element to be removed to the back */
1778 memcpy(&tmp, &array[key], sizeof(IDProperty));
1779 memmove(array+key, array+key+1, sizeof(IDProperty)*(len-key+1));
1780 memcpy(&array[len-1], &tmp, sizeof(IDProperty));
1783 IDP_ResizeIDPArray(idprop, len-1);
1788 else if(prop->flag & PROP_IDPROPERTY)
1791 /* py api calls directly */
1793 else if(cprop->remove){
1794 if(!(cprop->remove->flag & FUNC_USE_CONTEXT)) { /* XXX check for this somewhere else */
1795 ParameterList params;
1796 RNA_parameter_list_create(¶ms, ptr, cprop->remove);
1797 RNA_function_call(NULL, NULL, ptr, cprop->remove, ¶ms);
1798 RNA_parameter_list_free(¶ms);
1804 printf("RNA_property_collection_remove %s.%s: only supported for id properties.\n", ptr->type->identifier, prop->identifier);*/
1809 void RNA_property_collection_clear(PointerRNA *ptr, PropertyRNA *prop)
1813 if((idprop=rna_idproperty_check(&prop, ptr)))
1814 IDP_ResizeIDPArray(idprop, 0);
1817 int RNA_property_collection_lookup_index(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *t_ptr)
1819 CollectionPropertyIterator iter;
1822 RNA_property_collection_begin(ptr, prop, &iter);
1823 for(index=0; iter.valid; RNA_property_collection_next(&iter), index++) {
1824 if (iter.ptr.data == t_ptr->data)
1827 RNA_property_collection_end(&iter);
1829 /* did we find it? */
1836 int RNA_property_collection_lookup_int(PointerRNA *ptr, PropertyRNA *prop, int key, PointerRNA *r_ptr)
1838 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
1840 if(cprop->lookupint) {
1841 /* we have a callback defined, use it */
1842 *r_ptr= cprop->lookupint(ptr, key);
1843 return (r_ptr->data != NULL);
1846 /* no callback defined, just iterate and find the nth item */
1847 CollectionPropertyIterator iter;
1850 RNA_property_collection_begin(ptr, prop, &iter);
1851 for(i=0; iter.valid; RNA_property_collection_next(&iter), i++) {
1857 RNA_property_collection_end(&iter);
1860 memset(r_ptr, 0, sizeof(*r_ptr));
1866 int RNA_property_collection_lookup_string(PointerRNA *ptr, PropertyRNA *prop, const char *key, PointerRNA *r_ptr)
1868 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
1870 if(cprop->lookupstring) {
1871 /* we have a callback defined, use it */
1872 *r_ptr= cprop->lookupstring(ptr, key);
1873 return (r_ptr->data != NULL);
1876 /* no callback defined, compare with name properties if they exist */
1877 CollectionPropertyIterator iter;
1878 PropertyRNA *nameprop;
1879 char name[256], *nameptr;
1882 RNA_property_collection_begin(ptr, prop, &iter);
1883 for(; iter.valid; RNA_property_collection_next(&iter)) {
1884 if(iter.ptr.data && iter.ptr.type->nameproperty) {
1885 nameprop= iter.ptr.type->nameproperty;
1887 nameptr= RNA_property_string_get_alloc(&iter.ptr, nameprop, name, sizeof(name));
1889 if(strcmp(nameptr, key) == 0) {
1894 if((char *)&name != nameptr)
1901 RNA_property_collection_end(&iter);
1904 memset(r_ptr, 0, sizeof(*r_ptr));
1910 int RNA_property_collection_type_get(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *r_ptr)
1913 return ((r_ptr->type = prop->srna) ? 1:0);
1916 int RNA_property_collection_raw_array(PointerRNA *ptr, PropertyRNA *prop, PropertyRNA *itemprop, RawArray *array)
1918 CollectionPropertyIterator iter;
1919 ArrayIterator *internal;
1922 if(!(prop->flag & PROP_RAW_ARRAY) || !(itemprop->flag & PROP_RAW_ACCESS))
1925 RNA_property_collection_begin(ptr, prop, &iter);
1928 /* get data from array iterator and item property */
1929 internal= iter.internal;
1930 arrayp= (iter.valid)? iter.ptr.data: NULL;
1932 if(internal->skip || !RNA_property_editable(&iter.ptr, itemprop)) {
1933 /* we might skip some items, so it's not a proper array */
1934 RNA_property_collection_end(&iter);
1938 array->array= arrayp + itemprop->rawoffset;
1939 array->stride= internal->itemsize;
1940 array->len= ((char*)internal->endptr - arrayp)/internal->itemsize;
1941 array->type= itemprop->rawtype;
1944 memset(array, 0, sizeof(RawArray));
1946 RNA_property_collection_end(&iter);
1951 #define RAW_GET(dtype, var, raw, a) \
1953 switch(raw.type) { \
1954 case PROP_RAW_CHAR: var = (dtype)((char*)raw.array)[a]; break; \
1955 case PROP_RAW_SHORT: var = (dtype)((short*)raw.array)[a]; break; \
1956 case PROP_RAW_INT: var = (dtype)((int*)raw.array)[a]; break; \
1957 case PROP_RAW_FLOAT: var = (dtype)((float*)raw.array)[a]; break; \
1958 case PROP_RAW_DOUBLE: var = (dtype)((double*)raw.array)[a]; break; \
1959 default: var = (dtype)0; \
1963 #define RAW_SET(dtype, raw, a, var) \
1965 switch(raw.type) { \
1966 case PROP_RAW_CHAR: ((char*)raw.array)[a] = (char)var; break; \
1967 case PROP_RAW_SHORT: ((short*)raw.array)[a] = (short)var; break; \
1968 case PROP_RAW_INT: ((int*)raw.array)[a] = (int)var; break; \
1969 case PROP_RAW_FLOAT: ((float*)raw.array)[a] = (float)var; break; \
1970 case PROP_RAW_DOUBLE: ((double*)raw.array)[a] = (double)var; break; \
1974 int RNA_raw_type_sizeof(RawPropertyType type)
1977 case PROP_RAW_CHAR: return sizeof(char);
1978 case PROP_RAW_SHORT: return sizeof(short);
1979 case PROP_RAW_INT: return sizeof(int);
1980 case PROP_RAW_FLOAT: return sizeof(float);
1981 case PROP_RAW_DOUBLE: return sizeof(double);
1986 static int rna_raw_access(ReportList *reports, PointerRNA *ptr, PropertyRNA *prop, char *propname, void *inarray, RawPropertyType intype, int inlen, int set)
1990 PropertyRNA *itemprop, *iprop;
1991 PropertyType itemtype=0;
1995 /* initialize in array, stride assumed 0 in following code */
2001 ptype= RNA_property_pointer_type(ptr, prop);
2003 /* try to get item property pointer */
2004 RNA_pointer_create(NULL, ptype, NULL, &itemptr);
2005 itemprop= RNA_struct_find_property(&itemptr, propname);
2008 /* we have item property pointer */
2012 itemtype= RNA_property_type(itemprop);
2014 if(!ELEM3(itemtype, PROP_BOOLEAN, PROP_INT, PROP_FLOAT)) {
2015 BKE_report(reports, RPT_ERROR, "Only boolean, int and float properties supported.");
2019 /* check item array */
2020 itemlen= RNA_property_array_length(&itemptr, itemprop);
2022 /* try to access as raw array */
2023 if(RNA_property_collection_raw_array(ptr, prop, itemprop, &out)) {
2024 if(in.len != itemlen*out.len) {
2025 BKE_reportf(reports, RPT_ERROR, "Array length mismatch (expected %d, got %d).", out.len*itemlen, in.len);
2029 /* matching raw types */
2030 if(out.type == in.type) {
2031 void *inp= in.array;
2032 void *outp= out.array;
2035 itemlen= (itemlen == 0)? 1: itemlen;
2036 size= RNA_raw_type_sizeof(out.type) * itemlen;
2038 for(a=0; a<out.len; a++) {
2039 if(set) memcpy(outp, inp, size);
2040 else memcpy(inp, outp, size);
2042 inp= (char*)inp + size;
2043 outp= (char*)outp + out.stride;
2049 /* could also be faster with non-matching types,
2050 * for now we just do slower loop .. */
2055 void *tmparray= NULL;
2057 int err= 0, j, a= 0;
2059 /* no item property pointer, can still be id property, or
2060 * property of a type derived from the collection pointer type */
2061 RNA_PROP_BEGIN(ptr, itemptr, prop) {
2064 /* we got the property already */
2068 /* not yet, look it up and verify if it is valid */
2069 iprop= RNA_struct_find_property(&itemptr, propname);
2072 itemlen= RNA_property_array_length(&itemptr, iprop);
2073 itemtype= RNA_property_type(iprop);
2076 BKE_reportf(reports, RPT_ERROR, "Property named %s not found.", propname);
2081 if(!ELEM3(itemtype, PROP_BOOLEAN, PROP_INT, PROP_FLOAT)) {
2082 BKE_report(reports, RPT_ERROR, "Only boolean, int and float properties supported.");
2088 /* editable check */
2089 if(RNA_property_editable(&itemptr, iprop)) {
2090 if(a+itemlen > in.len) {
2091 BKE_reportf(reports, RPT_ERROR, "Array length mismatch (got %d, expected more).", in.len);
2097 /* handle conversions */
2100 case PROP_BOOLEAN: {
2102 RAW_GET(int, b, in, a);
2103 RNA_property_boolean_set(&itemptr, iprop, b);
2108 RAW_GET(int, i, in, a);
2109 RNA_property_int_set(&itemptr, iprop, i);
2114 RAW_GET(float, f, in, a);
2115 RNA_property_float_set(&itemptr, iprop, f);
2124 case PROP_BOOLEAN: {
2125 int b= RNA_property_boolean_get(&itemptr, iprop);
2126 RAW_SET(int, in, a, b);
2130 int i= RNA_property_int_get(&itemptr, iprop);
2131 RAW_SET(int, in, a, i);
2135 float f= RNA_property_float_get(&itemptr, iprop);
2136 RAW_SET(float, in, a, f);
2146 /* allocate temporary array if needed */
2147 if(tmparray && tmplen != itemlen) {
2148 MEM_freeN(tmparray);
2152 tmparray= MEM_callocN(sizeof(float)*itemlen, "RNA tmparray\n");
2156 /* handle conversions */
2159 case PROP_BOOLEAN: {
2160 for(j=0; j<itemlen; j++, a++)
2161 RAW_GET(int, ((int*)tmparray)[j], in, a);
2162 RNA_property_boolean_set_array(&itemptr, iprop, tmparray);
2166 for(j=0; j<itemlen; j++, a++)
2167 RAW_GET(int, ((int*)tmparray)[j], in, a);
2168 RNA_property_int_set_array(&itemptr, iprop, tmparray);
2172 for(j=0; j<itemlen; j++, a++)
2173 RAW_GET(float, ((float*)tmparray)[j], in, a);
2174 RNA_property_float_set_array(&itemptr, iprop, tmparray);
2183 case PROP_BOOLEAN: {
2184 RNA_property_boolean_get_array(&itemptr, iprop, tmparray);
2185 for(j=0; j<itemlen; j++, a++)
2186 RAW_SET(int, in, a, ((int*)tmparray)[j]);
2190 RNA_property_int_get_array(&itemptr, iprop, tmparray);
2191 for(j=0; j<itemlen; j++, a++)
2192 RAW_SET(int, in, a, ((int*)tmparray)[j]);
2196 RNA_property_float_get_array(&itemptr, iprop, tmparray);
2197 for(j=0; j<itemlen; j++, a++)
2198 RAW_SET(float, in, a, ((float*)tmparray)[j]);
2212 MEM_freeN(tmparray);
2218 RawPropertyType RNA_property_raw_type(PropertyRNA *prop)
2220 return prop->rawtype;
2223 int RNA_property_collection_raw_get(ReportList *reports, PointerRNA *ptr, PropertyRNA *prop, char *propname, void *array, RawPropertyType type, int len)
2225 return rna_raw_access(reports, ptr, prop, propname, array, type, len, 0);
2228 int RNA_property_collection_raw_set(ReportList *reports, PointerRNA *ptr, PropertyRNA *prop, char *propname, void *array, RawPropertyType type, int len)
2230 return rna_raw_access(reports, ptr, prop, propname, array, type, len, 1);
2233 /* Standard iterator functions */
2235 void rna_iterator_listbase_begin(CollectionPropertyIterator *iter, ListBase *lb, IteratorSkipFunc skip)
2237 ListBaseIterator *internal;
2239 internal= MEM_callocN(sizeof(ListBaseIterator), "ListBaseIterator");
2240 internal->link= (lb)? lb->first: NULL;
2241 internal->skip= skip;
2243 iter->internal= internal;
2244 iter->valid= (internal->link != NULL);
2246 if(skip && iter->valid && skip(iter, internal->link))
2247 rna_iterator_listbase_next(iter);
2250 void rna_iterator_listbase_next(CollectionPropertyIterator *iter)
2252 ListBaseIterator *internal= iter->internal;
2254 if(internal->skip) {
2256 internal->link= internal->link->next;
2257 iter->valid= (internal->link != NULL);
2258 } while(iter->valid && internal->skip(iter, internal->link));
2261 internal->link= internal->link->next;
2262 iter->valid= (internal->link != NULL);
2266 void *rna_iterator_listbase_get(CollectionPropertyIterator *iter)
2268 ListBaseIterator *internal= iter->internal;
2270 return internal->link;
2273 void rna_iterator_listbase_end(CollectionPropertyIterator *iter)
2275 MEM_freeN(iter->internal);
2276 iter->internal= NULL;
2279 void rna_iterator_array_begin(CollectionPropertyIterator *iter, void *ptr, int itemsize, int length, int free_ptr, IteratorSkipFunc skip)
2281 ArrayIterator *internal;
2286 internal= MEM_callocN(sizeof(ArrayIterator), "ArrayIterator");
2288 internal->free_ptr= free_ptr ? ptr:NULL;
2289 internal->endptr= ((char*)ptr)+length*itemsize;
2290 internal->itemsize= itemsize;
2291 internal->skip= skip;
2293 iter->internal= internal;
2294 iter->valid= (internal->ptr != internal->endptr);
2296 if(skip && iter->valid && skip(iter, internal->ptr))
2297 rna_iterator_array_next(iter);
2300 void rna_iterator_array_next(CollectionPropertyIterator *iter)
2302 ArrayIterator *internal= iter->internal;
2304 if(internal->skip) {
2306 internal->ptr += internal->itemsize;
2307 iter->valid= (internal->ptr != internal->endptr);
2308 } while(iter->valid && internal->skip(iter, internal->ptr));
2311 internal->ptr += internal->itemsize;
2312 iter->valid= (internal->ptr != internal->endptr);
2316 void *rna_iterator_array_get(CollectionPropertyIterator *iter)
2318 ArrayIterator *internal= iter->internal;
2320 return internal->ptr;
2323 void *rna_iterator_array_dereference_get(CollectionPropertyIterator *iter)
2325 ArrayIterator *internal= iter->internal;
2328 return *(void**)(internal->ptr);
2331 void rna_iterator_array_end(CollectionPropertyIterator *iter)
2333 ArrayIterator *internal= iter->internal;
2335 if(internal->free_ptr) {
2336 MEM_freeN(internal->free_ptr);
2337 internal->free_ptr= NULL;
2339 MEM_freeN(iter->internal);
2340 iter->internal= NULL;
2343 /* RNA Path - Experiment */
2345 static char *rna_path_token(const char **path, char *fixedbuf, int fixedlen, int bracket)
2349 int i, j, len, escape;
2354 /* get data between [], check escaping ] with \] */
2355 if(**path == '[') (*path)++;
2361 while(*p && (*p != ']' || escape)) {
2362 escape= (*p == '\\');
2367 if(*p != ']') return NULL;
2370 /* get data until . or [ */
2373 while(*p && *p != '.' && *p != '[') {
2383 /* try to use fixed buffer if possible */
2384 if(len+1 < fixedlen)
2387 buf= MEM_callocN(sizeof(char)*(len+1), "rna_path_token");
2389 /* copy string, taking into account escaped ] */
2391 for(p=*path, i=0, j=0; i<len; i++, p++) {
2392 if(*p == '\\' && *(p+1) == ']');
2399 memcpy(buf, *path, sizeof(char)*len);
2403 /* set path to start of next token */
2411 static int rna_token_strip_quotes(char *token)
2414 int len = strlen(token);
2415 if (len >= 2 && token[len-1]=='"') {
2424 /* Resolve the given RNA path to find the pointer+property indicated at the end of the path */
2425 int RNA_path_resolve(PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
2428 PointerRNA curptr, nextptr;
2429 char fixedbuf[256], *token;
2435 if(path==NULL || *path=='\0')
2439 int use_id_prop = (*path=='[') ? 1:0;
2440 /* custom property lookup ?
2441 * C.object["someprop"]
2444 /* look up property name in current struct */
2445 token= rna_path_token(&path, fixedbuf, sizeof(fixedbuf), use_id_prop);
2450 if(use_id_prop) { /* look up property name in current struct */
2451 IDProperty *group= RNA_struct_idproperties(&curptr, 0);
2452 if(group && rna_token_strip_quotes(token))
2453 prop= (PropertyRNA *)IDP_GetPropertyFromGroup(group, token+1);
2456 prop= RNA_struct_find_property(&curptr, token);
2459 if(token != fixedbuf)
2465 /* now look up the value of this property if it is a pointer or
2466 * collection, otherwise return the property rna so that the
2467 * caller can read the value of the property itself */
2468 if(RNA_property_type(prop) == PROP_POINTER) {
2469 nextptr= RNA_property_pointer_get(&curptr, prop);
2476 else if(RNA_property_type(prop) == PROP_COLLECTION && *path) {
2477 /* resolve the lookup with [] brackets */
2478 token= rna_path_token(&path, fixedbuf, sizeof(fixedbuf), 1);
2485 /* check for "" to see if it is a string */
2486 if(rna_token_strip_quotes(token)) {
2487 RNA_property_collection_lookup_string(&curptr, prop, token+1, &nextptr);
2490 /* otherwise do int lookup */
2491 intkey= atoi(token);
2492 RNA_property_collection_lookup_int(&curptr, prop, intkey, &nextptr);
2495 if(token != fixedbuf)
2512 char *RNA_path_append(const char *path, PointerRNA *ptr, PropertyRNA *prop, int intkey, const char *strkey)
2516 char appendstr[128], *result;
2518 dynstr= BLI_dynstr_new();
2520 /* add .identifier */
2522 BLI_dynstr_append(dynstr, (char*)path);
2524 BLI_dynstr_append(dynstr, ".");
2527 BLI_dynstr_append(dynstr, (char*)RNA_property_identifier(prop));
2529 if(RNA_property_type(prop) == PROP_COLLECTION) {
2530 /* add ["strkey"] or [intkey] */
2531 BLI_dynstr_append(dynstr, "[");
2534 BLI_dynstr_append(dynstr, "\"");
2535 for(s=strkey; *s; s++) {
2545 BLI_dynstr_append(dynstr, appendstr);
2547 BLI_dynstr_append(dynstr, "\"");
2550 sprintf(appendstr, "%d", intkey);
2551 BLI_dynstr_append(dynstr, appendstr);
2554 BLI_dynstr_append(dynstr, "]");
2557 result= BLI_dynstr_get_cstring(dynstr);
2558 BLI_dynstr_free(dynstr);
2563 char *RNA_path_back(const char *path)
2566 const char *previous, *current;
2567 char *result, *token;
2576 /* parse token by token until the end, then we back up to the previous
2577 * position and strip of the next token to get the path one step back */
2579 token= rna_path_token(¤t, fixedbuf, sizeof(fixedbuf), 0);
2583 if(token != fixedbuf)
2586 /* in case of collection we also need to strip off [] */
2587 token= rna_path_token(¤t, fixedbuf, sizeof(fixedbuf), 1);
2588 if(token && token != fixedbuf)
2600 /* copy and strip off last token */
2602 result= BLI_strdup(path);
2604 if(i > 0 && result[i-1] == '.') i--;
2610 char *RNA_path_from_ID_to_struct(PointerRNA *ptr)
2614 if(!ptr->id.data || !ptr->data)
2617 if(!RNA_struct_is_ID(ptr->type)) {
2618 if(ptr->type->path) {
2619 /* if type has a path to some ID, use it */
2620 ptrpath= ptr->type->path(ptr);
2622 else if(ptr->type->nested && RNA_struct_is_ID(ptr->type->nested)) {
2623 PointerRNA parentptr;
2624 PropertyRNA *userprop;
2626 /* find the property in the struct we're nested in that references this struct, and
2627 * use its identifier as the first part of the path used...
2629 RNA_id_pointer_create(ptr->id.data, &parentptr);
2630 userprop= RNA_struct_find_nested(&parentptr, ptr->type);
2633 ptrpath= BLI_strdup(RNA_property_identifier(userprop));
2635 return NULL; // can't do anything about this case yet...
2644 char *RNA_path_from_ID_to_property(PointerRNA *ptr, PropertyRNA *prop)
2646 int is_rna = (prop->magic == RNA_MAGIC);
2647 const char *propname;
2648 char *ptrpath, *path;
2650 if(!ptr->id.data || !ptr->data || !prop)
2653 /* path from ID to the struct holding this property */
2654 ptrpath= RNA_path_from_ID_to_struct(ptr);
2656 propname= RNA_property_identifier(prop);
2659 path= BLI_sprintfN(is_rna ? "%s.%s":"%s[\"%s\"]", ptrpath, propname);
2664 path= BLI_strdup(propname);
2666 path= BLI_sprintfN("[\"%s\"]", propname);
2672 /* Quick name based property access */
2674 int RNA_boolean_get(PointerRNA *ptr, const char *name)
2676 PropertyRNA *prop= RNA_struct_find_property(ptr, name);
2679 return RNA_property_boolean_get(ptr, prop);
2682 printf("RNA_boolean_get: %s.%s not found.\n", ptr->type->identifier, name);
2687 void RNA_boolean_set(PointerRNA *ptr, const char *name, int value)
2689 PropertyRNA *prop= RNA_struct_find_property(ptr, name);
2692 RNA_property_boolean_set(ptr, prop, value);
2694 printf("RNA_boolean_set: %s.%s not found.\n", ptr->type->identifier, name);
2697 void RNA_boolean_get_array(PointerRNA *ptr, const char *name, int *values)
2699 PropertyRNA *prop= RNA_struct_find_property(ptr, name);
2702 RNA_property_boolean_get_array(ptr, prop, values);
2704 printf("RNA_boolean_get_array: %s.%s not found.\n", ptr->type->identifier, name);
2707 void RNA_boolean_set_array(PointerRNA *ptr, const char *name, const int *values)
2709 PropertyRNA *prop= RNA_struct_find_property(ptr, name);
2712 RNA_property_boolean_set_array(ptr, prop, values);
2714 printf("RNA_boolean_set_array: %s.%s not found.\n", ptr->type->identifier, name);
2717 int RNA_int_get(PointerRNA *ptr, const char *name)
2719 PropertyRNA *prop= RNA_struct_find_property(ptr, name);
2722 return RNA_property_int_get(ptr, prop);
2725 printf("RNA_int_get: %s.%s not found.\n", ptr->type->identifier, name);
2730 void RNA_int_set(PointerRNA *ptr, const char *name, int value)
2732 PropertyRNA *prop= RNA_struct_find_property(ptr, name);
2735 RNA_property_int_set(ptr, prop, value);
2737 printf("RNA_int_set: %s.%s not found.\n", ptr->type->identifier, name);
2740 void RNA_int_get_array(PointerRNA *ptr, const char *name, int *values)
2742 PropertyRNA *prop= RNA_struct_find_property(ptr, name);
2745 RNA_property_int_get_array(ptr, prop, values);
2747 printf("RNA_int_get_array: %s.%s not found.\n", ptr->type->identifier, name);
2750 void RNA_int_set_array(PointerRNA *ptr, const char *name, const int *values)
2752 PropertyRNA *prop= RNA_struct_find_property(ptr, name);
2755 RNA_property_int_set_array(ptr, prop, values);
2757 printf("RNA_int_set_array: %s.%s not found.\n", ptr->type->identifier, name);
2760 float RNA_float_get(PointerRNA *ptr, const char *name)
2762 PropertyRNA *prop= RNA_struct_find_property(ptr, name);
2765 return RNA_property_float_get(ptr, prop);
2768 printf("RNA_float_get: %s.%s not found.\n", ptr->type->identifier, name);
2773 void RNA_float_set(PointerRNA *ptr, const char *name, float value)
2775 PropertyRNA *prop= RNA_struct_find_property(ptr, name);
2778 RNA_property_float_set(ptr, prop, value);
2780 printf("RNA_float_set: %s.%s not found.\n", ptr->type->identifier, name);
2783 void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
2785 PropertyRNA *prop= RNA_struct_find_property(ptr, name);
2788 RNA_property_float_get_array(ptr, prop, values);
2790 printf("RNA_float_get_array: %s.%s not found.\n", ptr->type->identifier, name);
2793 void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
2795 PropertyRNA *prop= RNA_struct_find_property(ptr, name);
2798 RNA_property_float_set_array(ptr, prop, values);
2800 printf("RNA_float_set_array: %s.%s not found.\n", ptr->type->identifier, name);
2803 int RNA_enum_get(PointerRNA *ptr, const char *name)
2805 PropertyRNA *prop= RNA_struct_find_property(ptr, name);
2808 return RNA_property_enum_get(ptr, prop);
2811 printf("RNA_enum_get: %s.%s not found.\n", ptr->type->identifier, name);
2816 void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
2818 PropertyRNA *prop= RNA_struct_find_property(ptr, name);
2821 RNA_property_enum_set(ptr, prop, value);
2823 printf("RNA_enum_set: %s.%s not found.\n", ptr->type->identifier, name);
2826 int RNA_enum_is_equal(bContext *C, PointerRNA *ptr, const char *name, const char *enumname)
2828 PropertyRNA *prop= RNA_struct_find_property(ptr, name);
2829 EnumPropertyItem *item;
2833 RNA_property_enum_items(C, ptr, prop, &item, NULL, &free);
2835 for(; item->identifier; item++)
2836 if(strcmp(item->identifier, enumname) == 0)
2837 return (item->value == RNA_property_enum_get(ptr, prop));
2842 printf("RNA_enum_is_equal: %s.%s item %s not found.\n", ptr->type->identifier, name, enumname);
2846 printf("RNA_enum_is_equal: %s.%s not found.\n", ptr->type->identifier, name);
2851 int RNA_enum_value_from_id(EnumPropertyItem *item, const char *identifier, int *value)
2853 for( ; item->identifier; item++) {
2854 if(strcmp(item->identifier, identifier)==0) {
2855 *value= item->value;
2863 int RNA_enum_id_from_value(EnumPropertyItem *item, int value, const char **identifier)
2865 for( ; item->identifier; item++) {
2866 if(item->value==value) {
2867 *identifier= item->identifier;
2875 void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
2877 PropertyRNA *prop= RNA_struct_find_property(ptr, name);
2880 RNA_property_string_get(ptr, prop, value);
2882 printf("RNA_string_get: %s.%s not found.\n", ptr->type->identifier, name);
2885 char *RNA_string_get_alloc(PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen)
2887 PropertyRNA *prop= RNA_struct_find_property(ptr, name);
2890 return RNA_property_string_get_alloc(ptr, prop, fixedbuf, fixedlen);
2893 printf("RNA_string_get_alloc: %s.%s not found.\n", ptr->type->identifier, name);
2898 int RNA_string_length(PointerRNA *ptr, const char *name)
2900 PropertyRNA *prop= RNA_struct_find_property(ptr, name);
2903 return RNA_property_string_length(ptr, prop);
2906 printf("RNA_string_length: %s.%s not found.\n", ptr->type->identifier, name);
2911 void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
2913 PropertyRNA *prop= RNA_struct_find_property(ptr, name);
2916 RNA_property_string_set(ptr, prop, value);
2918 printf("RNA_string_set: %s.%s not found.\n", ptr->type->identifier, name);
2921 PointerRNA RNA_pointer_get(PointerRNA *ptr, const char *name)
2923 PropertyRNA *prop= RNA_struct_find_property(ptr, name);
2926 return RNA_property_pointer_get(ptr, prop);
2931 printf("RNA_pointer_get: %s.%s not found.\n", ptr->type->identifier, name);
2933 memset(&result, 0, sizeof(result));
2938 void RNA_pointer_set(PointerRNA *ptr, const char *name, PointerRNA ptr_value)
2940 PropertyRNA *prop= RNA_struct_find_property(ptr, name);
2943 RNA_property_pointer_set(ptr, prop, ptr_value);
2946 printf("RNA_pointer_set: %s.%s not found.\n", ptr->type->identifier, name);
2950 void RNA_pointer_add(PointerRNA *ptr, const char *name)
2952 PropertyRNA *prop= RNA_struct_find_property(ptr, name);
2955 RNA_property_pointer_add(ptr, prop);
2957 printf("RNA_pointer_set: %s.%s not found.\n", ptr->type->identifier, name);
2960 void RNA_collection_begin(PointerRNA *ptr, const char *name, CollectionPropertyIterator *iter)
2962 PropertyRNA *prop= RNA_struct_find_property(ptr, name);
2965 RNA_property_collection_begin(ptr, prop, iter);
2967 printf("RNA_collection_begin: %s.%s not found.\n", ptr->type->identifier, name);
2970 void RNA_collection_add(PointerRNA *ptr, const char *name, PointerRNA *r_value)
2972 PropertyRNA *prop= RNA_struct_find_property(ptr, name);
2975 RNA_property_collection_add(ptr, prop, r_value);
2977 printf("RNA_collection_add: %s.%s not found.\n", ptr->type->identifier, name);
2980 void RNA_collection_clear(PointerRNA *ptr, const char *name)
2982 PropertyRNA *prop= RNA_struct_find_property(ptr, name);
2985 RNA_property_collection_clear(ptr, prop);
2987 printf("RNA_collection_clear: %s.%s not found.\n", ptr->type->identifier, name);
2990 int RNA_collection_length(PointerRNA *ptr, const char *name)
2992 PropertyRNA *prop= RNA_struct_find_property(ptr, name);
2995 return RNA_property_collection_length(ptr, prop);
2998 printf("RNA_collection_length: %s.%s not found.\n", ptr->type->identifier, name);
3003 int RNA_property_is_set(PointerRNA *ptr, const char *name)
3005 PropertyRNA *prop= RNA_struct_find_property(ptr, name);
3008 if(prop->flag & PROP_IDPROPERTY)
3009 return (rna_idproperty_find(ptr, name) != NULL);
3014 // printf("RNA_property_is_set: %s.%s not found.\n", ptr->type->identifier, name);
3019 int RNA_property_is_idprop(PropertyRNA *prop)
3021 return (prop->magic!=RNA_MAGIC);
3024 /* string representation of a property, python
3025 * compatible but can be used for display too*/
3026 char *RNA_pointer_as_string(PointerRNA *ptr)
3028 DynStr *dynstr= BLI_dynstr_new();
3031 const char *propname;
3034 BLI_dynstr_append(dynstr, "{");
3036 RNA_STRUCT_BEGIN(ptr, prop) {
3037 propname = RNA_property_identifier(prop);
3039 if(strcmp(propname, "rna_type")==0)
3043 BLI_dynstr_append(dynstr, ", ");
3046 cstring = RNA_property_as_string(NULL, ptr, prop);
3047 BLI_dynstr_appendf(dynstr, "\"%s\":%s", propname, cstring);
3052 BLI_dynstr_append(dynstr, "}");
3055 cstring = BLI_dynstr_get_cstring(dynstr);
3056 BLI_dynstr_free(dynstr);
3060 char *RNA_property_as_string(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
3062 int type = RNA_property_type(prop);
3063 int len = RNA_property_array_length(ptr, prop);
3066 DynStr *dynstr= BLI_dynstr_new();
3070 /* see if we can coorce into a python type - PropertyType */
3074 BLI_dynstr_append(dynstr, RNA_property_boolean_get(ptr, prop) ? "True" : "False");
3077 BLI_dynstr_append(dynstr, "(");
3078 for(i=0; i<len; i++) {
3079 BLI_dynstr_appendf(dynstr, i?", %s":"%s", RNA_property_boolean_get_index(ptr, prop, i) ? "True" : "False");
3082 BLI_dynstr_append(dynstr, ","); /* otherwise python wont see it as a tuple */
3083 BLI_dynstr_append(dynstr, ")");
3088 BLI_dynstr_appendf(dynstr, "%d", RNA_property_int_get(ptr, prop));
3091 BLI_dynstr_append(dynstr, "(");
3092 for(i=0; i<len; i++) {
3093 BLI_dynstr_appendf(dynstr, i?", %d":"%d", RNA_property_int_get_index(ptr, prop, i));
3096 BLI_dynstr_append(dynstr, ","); /* otherwise python wont see it as a tuple */
3097 BLI_dynstr_append(dynstr, ")");
3102 BLI_dynstr_appendf(dynstr, "%g", RNA_property_float_get(ptr, prop));
3105 BLI_dynstr_append(dynstr, "(");
3106 for(i=0; i<len; i++) {
3107 BLI_dynstr_appendf(dynstr, i?", %g":"%g", RNA_property_float_get_index(ptr, prop, i));
3110 BLI_dynstr_append(dynstr, ","); /* otherwise python wont see it as a tuple */
3111 BLI_dynstr_append(dynstr, ")");
3116 /* string arrays dont exist */
3118 buf = RNA_property_string_get_alloc(ptr, prop, NULL, -1);
3119 BLI_dynstr_appendf(dynstr, "\"%s\"", buf);
3125 /* string arrays dont exist */
3126 const char *identifier;
3127 int val = RNA_property_enum_get(ptr, prop);
3129 if(RNA_property_enum_identifier(C, ptr, prop, val, &identifier)) {
3130 BLI_dynstr_appendf(dynstr, "'%s'", identifier);
3133 BLI_dynstr_appendf(dynstr, "'<UNKNOWN ENUM>'", identifier);
3139 BLI_dynstr_append(dynstr, "'<POINTER>'"); /* TODO */
3142 case PROP_COLLECTION:
3145 CollectionPropertyIterator collect_iter;
3146 BLI_dynstr_append(dynstr, "[");
3148 for(RNA_property_collection_begin(ptr, prop, &collect_iter); collect_iter.valid; RNA_property_collection_next(&collect_iter)) {
3149 PointerRNA itemptr= collect_iter.ptr;
3152 BLI_dynstr_append(dynstr, ", ");
3155 /* now get every prop of the collection */
3156 cstring= RNA_pointer_as_string(&itemptr);
3157 BLI_dynstr_append(dynstr, cstring);
3161 RNA_property_collection_end(&collect_iter);
3162 BLI_dynstr_append(dynstr, "]");
3166 BLI_dynstr_append(dynstr, "'<UNKNOWN TYPE>'"); /* TODO */
3170 cstring = BLI_dynstr_get_cstring(dynstr);
3171 BLI_dynstr_free(dynstr);
3177 const char *RNA_function_identifier(FunctionRNA *func)
3179 return func->identifier;
3182 PropertyRNA *RNA_function_return(FunctionRNA *func)
3187 const char *RNA_function_ui_description(FunctionRNA *func)
3189 return func->description;
3192 int RNA_function_flag(FunctionRNA *func)
3197 PropertyRNA *RNA_function_get_parameter(PointerRNA *ptr, FunctionRNA *func, int index)
3202 parm= func->cont.properties.first;
3203 for(i= 0; parm; parm= parm->next, i++)
3210 PropertyRNA *RNA_function_find_parameter(PointerRNA *ptr, FunctionRNA *func, const char *identifier)
3214 parm= func->cont.properties.first;
3215 for(; parm; parm= parm->next)
3216 if(strcmp(parm->identifier, identifier)==0)
3222 const struct ListBase *RNA_function_defined_parameters(FunctionRNA *func)
3224 return &func->cont.properties;
3229 ParameterList *RNA_parameter_list_create(ParameterList *parms, PointerRNA *ptr, FunctionRNA *func)
3236 for(parm= func->cont.properties.first; parm; parm= parm->next)
3237 tot+= rna_parameter_size(parm);
3239 parms->data= MEM_callocN(tot, "RNA_parameter_list_create");
3243 /* set default values */
3246 for(parm= func->cont.properties.first; parm; parm= parm->next) {
3247 size= rna_parameter_size(parm);
3249 if(!(parm->flag & PROP_REQUIRED)) {
3250 switch(parm->type) {
3252 if(parm->arraydimension) memcpy(data, &((BooleanPropertyRNA*)parm)->defaultarray, size);
3253 else memcpy(data, &((BooleanPropertyRNA*)parm)->defaultvalue, size);
3256 if(parm->arraydimension) memcpy(data, &((IntPropertyRNA*)parm)->defaultarray, size);
3257 else memcpy(data, &((IntPropertyRNA*)parm)->defaultvalue, size);
3260 if(parm->arraydimension) memcpy(data, &((FloatPropertyRNA*)parm)->defaultarray, size);
3261 else memcpy(data, &((FloatPropertyRNA*)parm)->defaultvalue, size);
3264 memcpy(data, &((EnumPropertyRNA*)parm)->defaultvalue, size);
3267 const char *defvalue= ((StringPropertyRNA*)parm)->defaultvalue;
3268 if(defvalue && defvalue[0])
3269 memcpy(data, &defvalue, size);
3273 case PROP_COLLECTION: