92
PointerRNA PointerRNA_NULL = {{0}, 0, 0};
94
104
void RNA_main_pointer_create(struct Main *main, PointerRNA *r_ptr)
97
r_ptr->type= &RNA_Main;
106
r_ptr->id.data = NULL;
107
r_ptr->type = &RNA_BlendData;
101
111
void RNA_id_pointer_create(ID *id, PointerRNA *r_ptr)
104
StructRNA *type, *idtype= NULL;
113
StructRNA *type, *idtype = NULL;
107
memset(&tmp, 0, sizeof(tmp));
109
idtype= rna_ID_refine(&tmp);
116
PointerRNA tmp = {{NULL}};
118
idtype = rna_ID_refine(&tmp);
111
while(idtype->refine) {
112
type= idtype->refine(&tmp);
120
while (idtype->refine) {
121
type = idtype->refine(&tmp);
131
r_ptr->type = idtype;
126
135
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
129
StructRNA *idtype= NULL;
138
StructRNA *idtype = NULL;
132
memset(&tmp, 0, sizeof(tmp));
134
idtype= rna_ID_refine(&tmp);
141
PointerRNA tmp = {{0}};
143
idtype = rna_ID_refine(&tmp);
142
while(r_ptr->type && r_ptr->type->refine) {
143
StructRNA *rtype= r_ptr->type->refine(r_ptr);
145
if(rtype == r_ptr->type)
152
while (r_ptr->type && r_ptr->type->refine) {
153
StructRNA *rtype = r_ptr->type->refine(r_ptr);
155
if (rtype == r_ptr->type)
153
163
static void rna_pointer_inherit_id(StructRNA *type, PointerRNA *parent, PointerRNA *ptr)
155
if(type && type->flag & STRUCT_ID) {
156
ptr->id.data= ptr->data;
165
if (type && type->flag & STRUCT_ID) {
166
ptr->id.data = ptr->data;
159
ptr->id.data= parent->id.data;
169
ptr->id.data = parent->id.data;
163
173
void RNA_blender_rna_pointer_create(PointerRNA *r_ptr)
165
r_ptr->id.data= NULL;
166
r_ptr->type= &RNA_BlenderRNA;
167
r_ptr->data= &BLENDER_RNA;
175
r_ptr->id.data = NULL;
176
r_ptr->type = &RNA_BlenderRNA;
177
r_ptr->data = &BLENDER_RNA;
170
180
PointerRNA rna_pointer_inherit_refine(PointerRNA *ptr, StructRNA *type, void *data)
177
186
rna_pointer_inherit_id(type, ptr, &result);
179
while(result.type->refine) {
180
type= result.type->refine(&result);
188
while (result.type->refine) {
189
type = result.type->refine(&result);
182
if(type == result.type)
191
if (type == result.type)
189
memset(&result, 0, sizeof(result));
199
return PointerRNA_NULL;
195
204
void RNA_pointer_recast(PointerRNA *ptr, PointerRNA *r_ptr)
197
#if 0 // works but this case if covered by more general code below.
198
if(RNA_struct_is_ID(ptr->type)) {
206
#if 0 /* works but this case if covered by more general code below. */
207
if (RNA_struct_is_ID(ptr->type)) {
199
208
/* simple case */
200
209
RNA_id_pointer_create(ptr->id.data, r_ptr);
218
227
/* ID Properties */
229
static void rna_idproperty_touch(IDProperty *idprop)
231
/* so the property is seen as 'set' by rna */
232
idprop->flag &= ~IDP_FLAG_GHOST;
220
235
/* return a UI local ID prop definition for this prop */
221
236
IDProperty *rna_idproperty_ui(PropertyRNA *prop)
223
238
IDProperty *idprop;
225
for(idprop= ((IDProperty *)prop)->prev; idprop; idprop= idprop->prev) {
226
if (strcmp(RNA_IDP_UI, idprop->name)==0)
240
for (idprop = ((IDProperty *)prop)->prev; idprop; idprop = idprop->prev) {
241
if (strcmp(RNA_IDP_UI, idprop->name) == 0)
231
for(idprop= ((IDProperty *)prop)->next; idprop; idprop= idprop->next) {
232
if (strcmp(RNA_IDP_UI, idprop->name)==0)
245
if (idprop == NULL) {
246
for (idprop = ((IDProperty *)prop)->next; idprop; idprop = idprop->next) {
247
if (strcmp(RNA_IDP_UI, idprop->name) == 0)
238
return IDP_GetPropertyFromGroup(idprop, ((IDProperty *)prop)->name);
253
return IDP_GetPropertyTypeFromGroup(idprop, ((IDProperty *)prop)->name, IDP_GROUP);
243
IDProperty *RNA_struct_idproperties(PointerRNA *ptr, int create)
259
IDProperty *RNA_struct_idprops(PointerRNA *ptr, int create)
245
StructRNA *type= ptr->type;
261
StructRNA *type = ptr->type;
247
if(type && type->idproperties)
263
if (type && type->idproperties)
248
264
return type->idproperties(ptr, create);
253
int RNA_struct_idproperties_check(StructRNA *srna)
269
int RNA_struct_idprops_check(StructRNA *srna)
255
271
return (srna && srna->idproperties) ? 1 : 0;
258
274
static IDProperty *rna_idproperty_find(PointerRNA *ptr, const char *name)
260
IDProperty *group= RNA_struct_idproperties(ptr, 0);
264
for(idprop=group->data.group.first; idprop; idprop=idprop->next)
265
if(strcmp(idprop->name, name) == 0)
276
IDProperty *group = RNA_struct_idprops(ptr, 0);
279
return IDP_GetPropertyFromGroup(group, name);
272
284
static int rna_ensure_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
274
if(prop->magic == RNA_MAGIC) {
286
if (prop->magic == RNA_MAGIC) {
275
287
int arraylen[RNA_MAX_ARRAY_DIMENSION];
276
288
return (prop->getlength && ptr->data)? prop->getlength(ptr, arraylen): prop->totarraylength;
279
IDProperty *idprop= (IDProperty*)prop;
291
IDProperty *idprop = (IDProperty*)prop;
281
if(idprop->type == IDP_ARRAY)
293
if (idprop->type == IDP_ARRAY)
282
294
return idprop->len;
288
static int rna_ensure_property_array_check(PointerRNA *ptr, PropertyRNA *prop)
300
static int rna_ensure_property_array_check(PropertyRNA *prop)
290
if(prop->magic == RNA_MAGIC) {
302
if (prop->magic == RNA_MAGIC) {
291
303
return (prop->getlength || prop->totarraylength) ? 1:0;
294
IDProperty *idprop= (IDProperty*)prop;
306
IDProperty *idprop = (IDProperty*)prop;
296
308
return idprop->type == IDP_ARRAY ? 1:0;
723
829
char RNA_property_array_item_char(PropertyRNA *prop, int index)
725
const char *vectoritem= "XYZW";
726
const char *quatitem= "WXYZ";
727
const char *coloritem= "RGBA";
728
PropertySubType subtype= rna_ensure_property(prop)->subtype;
831
const char *vectoritem = "XYZW";
832
const char *quatitem = "WXYZ";
833
const char *coloritem = "RGBA";
834
PropertySubType subtype = rna_ensure_property(prop)->subtype;
730
836
/* get string to use for array index */
731
if ((index < 4) && ELEM(subtype, PROP_QUATERNION, PROP_AXISANGLE))
837
if ((index < 4) && ELEM(subtype, PROP_QUATERNION, PROP_AXISANGLE)) {
732
838
return quatitem[index];
733
else if((index < 4) && ELEM6(subtype, PROP_TRANSLATION, PROP_DIRECTION, PROP_XYZ, PROP_EULER, PROP_VELOCITY, PROP_ACCELERATION))
840
else if ((index < 4) && ELEM8(subtype, PROP_TRANSLATION, PROP_DIRECTION, PROP_XYZ, PROP_XYZ_LENGTH,
841
PROP_EULER, PROP_VELOCITY, PROP_ACCELERATION, PROP_COORDS))
734
843
return vectoritem[index];
735
else if ((index < 4) && ELEM(subtype, PROP_COLOR, PROP_COLOR_GAMMA))
845
else if ((index < 4) && ELEM(subtype, PROP_COLOR, PROP_COLOR_GAMMA)) {
736
846
return coloritem[index];
741
852
int RNA_property_array_item_index(PropertyRNA *prop, char name)
743
PropertySubType subtype= rna_ensure_property(prop)->subtype;
854
PropertySubType subtype = rna_ensure_property(prop)->subtype;
747
856
/* get index based on string name/alias */
748
857
/* maybe a function to find char index in string would be better than all the switches */
749
858
if (ELEM(subtype, PROP_QUATERNION, PROP_AXISANGLE)) {
761
else if(ELEM6(subtype, PROP_TRANSLATION, PROP_DIRECTION, PROP_XYZ, PROP_EULER, PROP_VELOCITY, PROP_ACCELERATION)) {
870
else if (ELEM6(subtype, PROP_TRANSLATION, PROP_DIRECTION, PROP_XYZ,
871
PROP_EULER, PROP_VELOCITY, PROP_ACCELERATION))
773
884
else if (ELEM(subtype, PROP_COLOR, PROP_COLOR_GAMMA)) {
789
901
void RNA_property_int_range(PointerRNA *ptr, PropertyRNA *prop, int *hardmin, int *hardmax)
791
IntPropertyRNA *iprop= (IntPropertyRNA*)rna_ensure_property(prop);
903
IntPropertyRNA *iprop = (IntPropertyRNA*)rna_ensure_property(prop);
904
int softmin, softmax;
793
if(prop->magic != RNA_MAGIC) {
906
if (prop->magic != RNA_MAGIC) {
794
907
/* attempt to get the local ID values */
795
IDProperty *idp_ui= rna_idproperty_ui(prop);
798
if(idp_ui) { /* TODO, type checking on ID props */
799
item= IDP_GetPropertyFromGroup(idp_ui, "min");
800
*hardmin= item ? item->data.val : INT_MIN;
802
item= IDP_GetPropertyFromGroup(idp_ui, "max");
803
*hardmax= item ? item->data.val : INT_MAX;
908
IDProperty *idp_ui = rna_idproperty_ui(prop);
913
item = IDP_GetPropertyTypeFromGroup(idp_ui, "min", IDP_INT);
914
*hardmin = item ? IDP_Int(item) : INT_MIN;
916
item = IDP_GetPropertyTypeFromGroup(idp_ui, "max", IDP_INT);
917
*hardmax = item ? IDP_Int(item) : INT_MAX;
810
iprop->range(ptr, hardmin, hardmax);
927
iprop->range(ptr, hardmin, hardmax, &softmin, &softmax);
813
*hardmin= iprop->hardmin;
814
*hardmax= iprop->hardmax;
930
*hardmin = iprop->hardmin;
931
*hardmax = iprop->hardmax;
818
935
void RNA_property_int_ui_range(PointerRNA *ptr, PropertyRNA *prop, int *softmin, int *softmax, int *step)
820
IntPropertyRNA *iprop= (IntPropertyRNA*)rna_ensure_property(prop);
937
IntPropertyRNA *iprop = (IntPropertyRNA*)rna_ensure_property(prop);
821
938
int hardmin, hardmax;
823
if(prop->magic != RNA_MAGIC) {
940
if (prop->magic != RNA_MAGIC) {
824
941
/* attempt to get the local ID values */
825
IDProperty *idp_ui= rna_idproperty_ui(prop);
828
if(idp_ui) { /* TODO, type checking on ID props */
829
item= IDP_GetPropertyFromGroup(idp_ui, "soft_min");
830
*softmin= item ? item->data.val : INT_MIN;
832
item= IDP_GetPropertyFromGroup(idp_ui, "soft_max");
833
*softmax= item ? item->data.val : INT_MAX;
835
item= IDP_GetPropertyFromGroup(idp_ui, "step");
836
*step= item ? item->data.val : 1;
942
IDProperty *idp_ui = rna_idproperty_ui(prop);
947
item = IDP_GetPropertyTypeFromGroup(idp_ui, "soft_min", IDP_INT);
948
*softmin = item ? IDP_Int(item) : INT_MIN;
950
item = IDP_GetPropertyTypeFromGroup(idp_ui, "soft_max", IDP_INT);
951
*softmax = item ? IDP_Int(item) : INT_MAX;
953
item = IDP_GetPropertyTypeFromGroup(idp_ui, "step", IDP_INT);
954
*step = item ? IDP_Int(item) : 1;
843
iprop->range(ptr, &hardmin, &hardmax);
844
*softmin= MAX2(iprop->softmin, hardmin);
845
*softmax= MIN2(iprop->softmax, hardmax);
848
*softmin= iprop->softmin;
849
*softmax= iprop->softmax;
960
*softmin = iprop->softmin;
961
*softmax = iprop->softmax;
967
iprop->range(ptr, &hardmin, &hardmax, softmin, softmax);
969
*softmin = MAX2(*softmin, hardmin);
970
*softmax = MIN2(*softmax, hardmax);
855
976
void RNA_property_float_range(PointerRNA *ptr, PropertyRNA *prop, float *hardmin, float *hardmax)
857
FloatPropertyRNA *fprop= (FloatPropertyRNA*)rna_ensure_property(prop);
978
FloatPropertyRNA *fprop = (FloatPropertyRNA*)rna_ensure_property(prop);
979
float softmin, softmax;
859
if(prop->magic != RNA_MAGIC) {
981
if (prop->magic != RNA_MAGIC) {
860
982
/* attempt to get the local ID values */
861
IDProperty *idp_ui= rna_idproperty_ui(prop);
864
if(idp_ui) { /* TODO, type checking on ID props */
865
item= IDP_GetPropertyFromGroup(idp_ui, "min");
866
*hardmin= item ? *(double*)&item->data.val : FLT_MIN;
868
item= IDP_GetPropertyFromGroup(idp_ui, "max");
869
*hardmax= item ? *(double*)&item->data.val : FLT_MAX;
983
IDProperty *idp_ui = rna_idproperty_ui(prop);
988
item = IDP_GetPropertyTypeFromGroup(idp_ui, "min", IDP_DOUBLE);
989
*hardmin = item ? (float)IDP_Double(item) : FLT_MIN;
991
item = IDP_GetPropertyTypeFromGroup(idp_ui, "max", IDP_DOUBLE);
992
*hardmax = item ? (float)IDP_Double(item) : FLT_MAX;
876
fprop->range(ptr, hardmin, hardmax);
1002
fprop->range(ptr, hardmin, hardmax, &softmin, &softmax);
879
*hardmin= fprop->hardmin;
880
*hardmax= fprop->hardmax;
1005
*hardmin = fprop->hardmin;
1006
*hardmax = fprop->hardmax;
884
void RNA_property_float_ui_range(PointerRNA *ptr, PropertyRNA *prop, float *softmin, float *softmax, float *step, float *precision)
1010
void RNA_property_float_ui_range(PointerRNA *ptr, PropertyRNA *prop, float *softmin, float *softmax,
1011
float *step, float *precision)
886
FloatPropertyRNA *fprop= (FloatPropertyRNA*)rna_ensure_property(prop);
1013
FloatPropertyRNA *fprop = (FloatPropertyRNA*)rna_ensure_property(prop);
887
1014
float hardmin, hardmax;
889
if(prop->magic != RNA_MAGIC) {
1016
if (prop->magic != RNA_MAGIC) {
890
1017
/* attempt to get the local ID values */
891
IDProperty *idp_ui= rna_idproperty_ui(prop);
894
if(idp_ui) { /* TODO, type checking on ID props */
895
item= IDP_GetPropertyFromGroup(idp_ui, "soft_min");
896
*softmin= item ? *(double*)&item->data.val : FLT_MIN;
898
item= IDP_GetPropertyFromGroup(idp_ui, "soft_max");
899
*softmax= item ? *(double*)&item->data.val : FLT_MAX;
901
item= IDP_GetPropertyFromGroup(idp_ui, "step");
902
*step= item ? *(double*)&item->data.val : 1.0f;
904
item= IDP_GetPropertyFromGroup(idp_ui, "precision");
905
*precision= item ? *(double*)&item->data.val : 3.0f;
1018
IDProperty *idp_ui = rna_idproperty_ui(prop);
1023
item = IDP_GetPropertyTypeFromGroup(idp_ui, "soft_min", IDP_DOUBLE);
1024
*softmin = item ? (float)IDP_Double(item) : FLT_MIN;
1026
item = IDP_GetPropertyTypeFromGroup(idp_ui, "soft_max", IDP_DOUBLE);
1027
*softmax = item ? (float)IDP_Double(item) : FLT_MAX;
1029
item = IDP_GetPropertyTypeFromGroup(idp_ui, "step", IDP_DOUBLE);
1030
*step = item ? (float)IDP_Double(item) : 1.0f;
1032
item = IDP_GetPropertyTypeFromGroup(idp_ui, "precision", IDP_DOUBLE);
1033
*precision = item ? (float)IDP_Double(item) : 3.0f;
912
fprop->range(ptr, &hardmin, &hardmax);
913
*softmin= MAX2(fprop->softmin, hardmin);
914
*softmax= MIN2(fprop->softmax, hardmax);
917
*softmin= fprop->softmin;
918
*softmax= fprop->softmax;
922
*precision= (float)fprop->precision;
1039
*softmin = fprop->softmin;
1040
*softmax = fprop->softmax;
1046
fprop->range(ptr, &hardmin, &hardmax, softmin, softmax);
1048
*softmin = MAX2(*softmin, hardmin);
1049
*softmax = MIN2(*softmax, hardmax);
1052
*step = fprop->step;
1053
*precision = (float)fprop->precision;
925
1056
int RNA_property_float_clamp(PointerRNA *ptr, PropertyRNA *prop, float *value)
1001
1149
{0, NULL, 0, NULL, NULL}
1004
void RNA_property_enum_items(bContext *C, PointerRNA *ptr, PropertyRNA *prop, EnumPropertyItem **item, int *totitem, int *free)
1152
void RNA_property_enum_items(bContext *C, PointerRNA *ptr, PropertyRNA *prop, EnumPropertyItem **item,
1153
int *totitem, int *free)
1006
EnumPropertyRNA *eprop= (EnumPropertyRNA*)rna_ensure_property(prop);
1010
if(eprop->itemf && (C != NULL || (prop->flag & PROP_ENUM_NO_CONTEXT))) {
1155
EnumPropertyRNA *eprop = (EnumPropertyRNA*)rna_ensure_property(prop);
1159
if (eprop->itemf && (C != NULL || (prop->flag & PROP_ENUM_NO_CONTEXT))) {
1013
1162
if (prop->flag & PROP_ENUM_NO_CONTEXT)
1014
*item= eprop->itemf(NULL, ptr, free);
1163
*item = eprop->itemf(NULL, ptr, prop, free);
1016
*item= eprop->itemf(C, ptr, free);
1165
*item = eprop->itemf(C, ptr, prop, free);
1020
for( ; (*item)[tot].identifier; tot++);
1169
for ( ; (*item)[tot].identifier; tot++);
1029
*totitem= eprop->totitem;
1177
*item = eprop->item;
1179
*totitem = eprop->totitem;
1183
void RNA_property_enum_items_gettexted(bContext *C, PointerRNA *ptr, PropertyRNA *prop,
1184
EnumPropertyItem **item, int *totitem, int *free)
1186
RNA_property_enum_items(C, ptr, prop, item, totitem, free);
1188
#ifdef WITH_INTERNATIONAL
1189
/* Note: keep directly using BLF_gettext here, has we have already done tests like BLF_translate_iface... */
1190
if (BLF_translate_iface()) {
1192
EnumPropertyItem *nitem;
1201
for (i = 0; (*item)[i].identifier; i++)
1204
nitem = MEM_callocN(sizeof(EnumPropertyItem)*(totitem+1), "enum_items_gettexted");
1206
for (i = 0; (*item)[i].identifier; i++)
1207
nitem[i] = (*item)[i];
1212
for (i = 0; nitem[i].identifier; i++) {
1213
if ( nitem[i].name ) {
1214
if (prop->translation_context)
1215
nitem[i].name = BLF_pgettext(prop->translation_context, nitem[i].name);
1217
nitem[i].name = BLF_gettext(nitem[i].name);
1219
if ( nitem[i].description )
1220
nitem[i].description = BLF_gettext(nitem[i].description);
1033
1229
int RNA_property_enum_value(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const char *identifier, int *value)
1035
1231
EnumPropertyItem *item, *item_array;
1036
1232
int free, found;
1038
1234
RNA_property_enum_items(C, ptr, prop, &item_array, NULL, &free);
1040
for(item= item_array; item->identifier; item++) {
1041
if(item->identifier[0] && strcmp(item->identifier, identifier)==0) {
1042
*value = item->value;
1047
found= (item->identifier != NULL); /* could be alloc'd, assign before free */
1050
MEM_freeN(item_array);
1237
for (item = item_array; item->identifier; item++) {
1238
if (item->identifier[0] && strcmp(item->identifier, identifier) == 0) {
1239
*value = item->value;
1244
found = (item->identifier != NULL); /* could be alloc'd, assign before free */
1247
MEM_freeN(item_array);
1055
1256
int RNA_enum_identifier(EnumPropertyItem *item, const int value, const char **identifier)
1057
1258
for (; item->identifier; item++) {
1058
if(item->identifier[0] && item->value==value) {
1259
if (item->identifier[0] && item->value == value) {
1059
1260
*identifier = item->identifier;
1206
1409
if (!id_type_can_have_animdata(ptr->id.data))
1209
prop= rna_ensure_property(prop);
1412
prop = rna_ensure_property(prop);
1211
if(!(prop->flag & PROP_ANIMATABLE))
1414
if (!(prop->flag & PROP_ANIMATABLE))
1214
1417
return (prop->flag & PROP_EDITABLE);
1217
int RNA_property_animated(PointerRNA *ptr, PropertyRNA *prop)
1420
int RNA_property_animated(PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop))
1219
1422
/* would need to ask animation system */
1428
/* this function is to check if its possible to create a valid path from the ID
1429
* its slow so don't call in a loop */
1430
int RNA_property_path_from_ID_check(PointerRNA *ptr, PropertyRNA *prop)
1432
char *path = RNA_path_from_ID_to_property(ptr, prop);
1438
PropertyRNA *r_prop;
1440
RNA_id_pointer_create(ptr->id.data, &id_ptr);
1441
if (RNA_path_resolve(&id_ptr, path, &r_ptr, &r_prop) == TRUE) {
1442
ret = (prop == r_prop);
1224
1454
static void rna_property_update(bContext *C, Main *bmain, Scene *scene, PointerRNA *ptr, PropertyRNA *prop)
1226
1456
int is_rna = (prop->magic == RNA_MAGIC);
1227
prop= rna_ensure_property(prop);
1457
prop = rna_ensure_property(prop);
1231
1461
/* ideally no context would be needed for update, but there's some
1232
parts of the code that need it still, so we have this exception */
1233
if(prop->flag & PROP_CONTEXT_UPDATE) {
1234
if(C) ((ContextUpdateFunc)prop->update)(C, ptr);
1462
* parts of the code that need it still, so we have this exception */
1463
if (prop->flag & PROP_CONTEXT_UPDATE) {
1465
if (prop->flag & PROP_CONTEXT_PROPERTY_UPDATE) {
1466
((ContextPropUpdateFunc)prop->update)(C, ptr, prop);
1469
((ContextUpdateFunc)prop->update)(C, ptr);
1237
1474
prop->update(bmain, scene, ptr);
1240
1477
WM_main_add_notifier(prop->noteflag, ptr->id.data);
1480
if (!is_rna || (prop->flag & PROP_IDPROPERTY)) {
1243
1481
/* WARNING! This is so property drivers update the display!
1244
1482
* not especially nice */
1245
DAG_id_flush_update(ptr->id.data, OB_RECALC_ALL);
1483
DAG_id_tag_update(ptr->id.data, OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME);
1246
1484
WM_main_add_notifier(NC_WINDOW, NULL);
1488
/* must keep in sync with 'rna_property_update'
1489
* note, its possible this returns a false positive in the case of PROP_CONTEXT_UPDATE
1490
* but this isn't likely to be a performance problem. */
1491
int RNA_property_update_check(PropertyRNA *prop)
1493
return (prop->magic != RNA_MAGIC || prop->update || prop->noteflag);
1251
1496
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
1258
1503
rna_property_update(NULL, bmain, scene, ptr, prop);
1507
/* RNA Updates Cache ------------------------ */
1508
/* Overview of RNA Update cache system:
1510
* RNA Update calls need to be cached in order to maintain reasonable performance
1511
* of the animation system (i.e. maintaining a somewhat interactive framerate)
1512
* while still allowing updates to be called (necessary in particular for modifier
1513
* property updates to actually work).
1515
* The cache is structured with a dual-layer structure
1516
* - L1 = PointerRNA used as key; id.data is used (it should always be defined,
1517
* and most updates end up using just that anyways)
1518
* - L2 = Update functions to be called on those PointerRNA's
1522
typedef struct tRnaUpdateCacheElem {
1523
struct tRnaUpdateCacheElem *next, *prev;
1525
PointerRNA ptr; /* L1 key - id as primary, data secondary/ignored? */
1526
ListBase L2Funcs; /* L2 functions (LinkData<RnaUpdateFuncRef>) */
1527
} tRnaUpdateCacheElem;
1529
/* cache global (tRnaUpdateCacheElem's) - only accessible using these API calls */
1530
static ListBase rna_updates_cache = {NULL, NULL};
1532
/* ........................... */
1534
void RNA_property_update_cache_add(PointerRNA *ptr, PropertyRNA *prop)
1536
tRnaUpdateCacheElem *uce = NULL;
1537
UpdateFunc fn = NULL;
1539
short is_rna = (prop->magic == RNA_MAGIC);
1542
if (ELEM(NULL, ptr, prop))
1545
prop = rna_ensure_property(prop);
1547
/* we can only handle update calls with no context args for now (makes animsys updates easier) */
1548
if ((is_rna == 0) || (prop->update == NULL) || (prop->flag & PROP_CONTEXT_UPDATE))
1552
/* find cache element for which key matches... */
1553
for (uce = rna_updates_cache.first; uce; uce = uce->next) {
1554
/* just match by id only for now, since most update calls that we'll encounter only really care about this */
1555
/* TODO: later, the cache might need to have some nesting on L1 to cope better
1556
* with these problems + some tagging to indicate we need this */
1557
if (uce->ptr.id.data == ptr->id.data)
1561
/* create new instance */
1562
uce = MEM_callocN(sizeof(tRnaUpdateCacheElem), "tRnaUpdateCacheElem");
1563
BLI_addtail(&rna_updates_cache, uce);
1566
RNA_pointer_create(ptr->id.data, ptr->type, ptr->data, &uce->ptr);
1569
/* check on the update func */
1570
for (ld = uce->L2Funcs.first; ld; ld = ld->next) {
1571
/* stop on match - function already cached */
1575
/* else... if still here, we need to add it */
1576
BLI_addtail(&uce->L2Funcs, BLI_genericNodeN(fn));
1579
void RNA_property_update_cache_flush(Main *bmain, Scene *scene)
1581
tRnaUpdateCacheElem *uce;
1583
/* TODO: should we check that bmain and scene are valid? The above stuff doesn't! */
1585
/* execute the cached updates */
1586
for (uce = rna_updates_cache.first; uce; uce = uce->next) {
1589
for (ld = uce->L2Funcs.first; ld; ld = ld->next) {
1590
UpdateFunc fn = (UpdateFunc)ld->data;
1591
fn(bmain, scene, &uce->ptr);
1596
void RNA_property_update_cache_free(void)
1598
tRnaUpdateCacheElem *uce, *ucn;
1600
for (uce = rna_updates_cache.first; uce; uce = ucn) {
1604
BLI_freelistN(&uce->L2Funcs);
1607
BLI_freelinkN(&rna_updates_cache, uce);
1611
/* ---------------------------------------------------------------------- */
1261
1613
/* Property Data */
1263
1615
int RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
1265
BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
1617
BoolPropertyRNA *bprop = (BoolPropertyRNA*)prop;
1266
1618
IDProperty *idprop;
1268
if((idprop=rna_idproperty_check(&prop, ptr)))
1620
BLI_assert(RNA_property_type(prop) == PROP_BOOLEAN);
1621
BLI_assert(RNA_property_array_check(prop) == 0);
1623
if ((idprop = rna_idproperty_check(&prop, ptr)))
1269
1624
return IDP_Int(idprop);
1625
else if (bprop->get)
1271
1626
return bprop->get(ptr);
1273
1628
return bprop->defaultvalue;
1276
1631
void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, int value)
1278
BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
1633
BoolPropertyRNA *bprop = (BoolPropertyRNA*)prop;
1279
1634
IDProperty *idprop;
1281
/* just incase other values are passed */
1284
if((idprop=rna_idproperty_check(&prop, ptr)))
1285
IDP_Int(idprop)= value;
1636
BLI_assert(RNA_property_type(prop) == PROP_BOOLEAN);
1637
BLI_assert(RNA_property_array_check(prop) == 0);
1639
/* just in case other values are passed */
1640
if (value) value = 1;
1642
if ((idprop = rna_idproperty_check(&prop, ptr))) {
1643
IDP_Int(idprop) = value;
1644
rna_idproperty_touch(idprop);
1646
else if (bprop->set)
1287
1647
bprop->set(ptr, value);
1288
else if(prop->flag & PROP_EDITABLE) {
1648
else if (prop->flag & PROP_EDITABLE) {
1289
1649
IDPropertyTemplate val = {0};
1290
1650
IDProperty *group;
1294
group= RNA_struct_idproperties(ptr, 1);
1296
IDP_AddToGroup(group, IDP_New(IDP_INT, val, (char*)prop->identifier));
1654
group = RNA_struct_idprops(ptr, 1);
1656
IDP_AddToGroup(group, IDP_New(IDP_INT, &val, prop->identifier));
1300
1660
void RNA_property_boolean_get_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
1302
BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
1662
BoolPropertyRNA *bprop = (BoolPropertyRNA*)prop;
1303
1663
IDProperty *idprop;
1305
if((idprop=rna_idproperty_check(&prop, ptr))) {
1306
if(prop->arraydimension == 0)
1307
values[0]= RNA_property_boolean_get(ptr, prop);
1665
BLI_assert(RNA_property_type(prop) == PROP_BOOLEAN);
1666
BLI_assert(RNA_property_array_check(prop) != 0);
1668
if ((idprop = rna_idproperty_check(&prop, ptr))) {
1669
if (prop->arraydimension == 0)
1670
values[0] = RNA_property_boolean_get(ptr, prop);
1309
1672
memcpy(values, IDP_Array(idprop), sizeof(int)*idprop->len);
1311
else if(prop->arraydimension == 0)
1312
values[0]= RNA_property_boolean_get(ptr, prop);
1313
else if(bprop->getarray)
1674
else if (prop->arraydimension == 0)
1675
values[0] = RNA_property_boolean_get(ptr, prop);
1676
else if (bprop->getarray)
1314
1677
bprop->getarray(ptr, values);
1315
else if(bprop->defaultarray)
1678
else if (bprop->defaultarray)
1316
1679
memcpy(values, bprop->defaultarray, sizeof(int)*prop->totarraylength);
1318
1681
memset(values, 0, sizeof(int)*prop->totarraylength);
1373
1744
void RNA_property_boolean_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, int value)
1375
1746
int tmp[RNA_MAX_ARRAY_LENGTH];
1376
int len= rna_ensure_property_array_length(ptr, prop);
1378
if(len <= RNA_MAX_ARRAY_LENGTH) {
1747
int len = rna_ensure_property_array_length(ptr, prop);
1749
BLI_assert(RNA_property_type(prop) == PROP_BOOLEAN);
1750
BLI_assert(RNA_property_array_check(prop) != 0);
1752
if (len <= RNA_MAX_ARRAY_LENGTH) {
1379
1753
RNA_property_boolean_get_array(ptr, prop, tmp);
1381
1755
RNA_property_boolean_set_array(ptr, prop, tmp);
1386
tmparray= MEM_callocN(sizeof(int)*len, "RNA_property_boolean_get_index");
1760
tmparray = MEM_callocN(sizeof(int)*len, "RNA_property_boolean_get_index");
1387
1761
RNA_property_boolean_get_array(ptr, prop, tmparray);
1388
tmparray[index]= value;
1762
tmparray[index] = value;
1389
1763
RNA_property_boolean_set_array(ptr, prop, tmparray);
1390
1764
MEM_freeN(tmparray);
1394
int RNA_property_boolean_get_default(PointerRNA *ptr, PropertyRNA *prop)
1768
int RNA_property_boolean_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
1396
BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
1770
BoolPropertyRNA *bprop = (BoolPropertyRNA*)prop;
1772
BLI_assert(RNA_property_type(prop) == PROP_BOOLEAN);
1773
BLI_assert(RNA_property_array_check(prop) == 0);
1397
1775
return bprop->defaultvalue;
1400
void RNA_property_boolean_get_default_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
1778
void RNA_property_boolean_get_default_array(PointerRNA *UNUSED(ptr), PropertyRNA *prop, int *values)
1402
BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
1780
BoolPropertyRNA *bprop = (BoolPropertyRNA*)prop;
1404
if(prop->arraydimension == 0)
1405
values[0]= bprop->defaultvalue;
1406
else if(bprop->defaultarray)
1782
BLI_assert(RNA_property_type(prop) == PROP_BOOLEAN);
1783
BLI_assert(RNA_property_array_check(prop) != 0);
1785
if (prop->arraydimension == 0)
1786
values[0] = bprop->defaultvalue;
1787
else if (bprop->defaultarray)
1407
1788
memcpy(values, bprop->defaultarray, sizeof(int)*prop->totarraylength);
1409
1790
memset(values, 0, sizeof(int)*prop->totarraylength);
1446
1833
void RNA_property_int_set(PointerRNA *ptr, PropertyRNA *prop, int value)
1448
IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
1835
IntPropertyRNA *iprop = (IntPropertyRNA*)prop;
1449
1836
IDProperty *idprop;
1451
if((idprop=rna_idproperty_check(&prop, ptr)))
1452
IDP_Int(idprop)= value;
1838
BLI_assert(RNA_property_type(prop) == PROP_INT);
1839
BLI_assert(RNA_property_array_check(prop) == 0);
1840
/* useful to check on bad values but set function should clamp */
1841
/* BLI_assert(RNA_property_int_clamp(ptr, prop, &value) == 0); */
1843
if ((idprop = rna_idproperty_check(&prop, ptr))) {
1844
IDP_Int(idprop) = value;
1845
rna_idproperty_touch(idprop);
1847
else if (iprop->set)
1454
1848
iprop->set(ptr, value);
1455
else if(prop->flag & PROP_EDITABLE) {
1849
else if (prop->flag & PROP_EDITABLE) {
1456
1850
IDPropertyTemplate val = {0};
1457
1851
IDProperty *group;
1461
group= RNA_struct_idproperties(ptr, 1);
1463
IDP_AddToGroup(group, IDP_New(IDP_INT, val, (char*)prop->identifier));
1855
group = RNA_struct_idprops(ptr, 1);
1857
IDP_AddToGroup(group, IDP_New(IDP_INT, &val, prop->identifier));
1467
1861
void RNA_property_int_get_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
1469
IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
1863
IntPropertyRNA *iprop = (IntPropertyRNA*)prop;
1470
1864
IDProperty *idprop;
1472
if((idprop=rna_idproperty_check(&prop, ptr))) {
1473
if(prop->arraydimension == 0)
1474
values[0]= RNA_property_int_get(ptr, prop);
1866
BLI_assert(RNA_property_type(prop) == PROP_INT);
1867
BLI_assert(RNA_property_array_check(prop) != 0);
1869
if ((idprop = rna_idproperty_check(&prop, ptr))) {
1870
if (prop->arraydimension == 0)
1871
values[0] = RNA_property_int_get(ptr, prop);
1476
1873
memcpy(values, IDP_Array(idprop), sizeof(int)*idprop->len);
1478
else if(prop->arraydimension == 0)
1479
values[0]= RNA_property_int_get(ptr, prop);
1480
else if(iprop->getarray)
1875
else if (prop->arraydimension == 0)
1876
values[0] = RNA_property_int_get(ptr, prop);
1877
else if (iprop->getarray)
1481
1878
iprop->getarray(ptr, values);
1482
else if(iprop->defaultarray)
1879
else if (iprop->defaultarray)
1483
1880
memcpy(values, iprop->defaultarray, sizeof(int)*prop->totarraylength);
1485
1882
memset(values, 0, sizeof(int)*prop->totarraylength);
1885
void RNA_property_int_get_array_range(PointerRNA *ptr, PropertyRNA *prop, int values[2])
1887
const int array_len = RNA_property_array_length(ptr, prop);
1889
if (array_len <= 0) {
1893
else if (array_len == 1) {
1894
RNA_property_int_get_array(ptr, prop, values);
1895
values[1] = values[0];
1902
if (array_len > 32) {
1903
arr = MEM_mallocN(sizeof(int) * array_len, "RNA_property_int_get_array_range");
1909
RNA_property_int_get_array(ptr, prop, arr);
1910
values[0] = values[1] = arr[0];
1911
for (i = 1; i < array_len; i++) {
1912
values[0] = MIN2(values[0], arr[i]);
1913
values[1] = MAX2(values[1], arr[i]);
1916
if (arr != arr_stack) {
1488
1922
int RNA_property_int_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
1490
1924
int tmp[RNA_MAX_ARRAY_LENGTH];
1491
int len= rna_ensure_property_array_length(ptr, prop);
1493
if(len <= RNA_MAX_ARRAY_LENGTH) {
1925
int len = rna_ensure_property_array_length(ptr, prop);
1927
BLI_assert(RNA_property_type(prop) == PROP_INT);
1928
BLI_assert(RNA_property_array_check(prop) != 0);
1930
if (len <= RNA_MAX_ARRAY_LENGTH) {
1494
1931
RNA_property_int_get_array(ptr, prop, tmp);
1495
1932
return tmp[index];
1498
1935
int *tmparray, value;
1500
tmparray= MEM_callocN(sizeof(int)*len, "RNA_property_int_get_index");
1937
tmparray = MEM_callocN(sizeof(int)*len, "RNA_property_int_get_index");
1501
1938
RNA_property_int_get_array(ptr, prop, tmparray);
1502
value= tmparray[index];
1939
value = tmparray[index];
1503
1940
MEM_freeN(tmparray);
1509
1946
void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *values)
1511
IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
1948
IntPropertyRNA *iprop = (IntPropertyRNA*)prop;
1512
1949
IDProperty *idprop;
1514
if((idprop=rna_idproperty_check(&prop, ptr))) {
1515
if(prop->arraydimension == 0)
1516
IDP_Int(idprop)= values[0];
1951
BLI_assert(RNA_property_type(prop) == PROP_INT);
1952
BLI_assert(RNA_property_array_check(prop) != 0);
1954
if ((idprop = rna_idproperty_check(&prop, ptr))) {
1955
if (prop->arraydimension == 0)
1956
IDP_Int(idprop) = values[0];
1518
memcpy(IDP_Array(idprop), values, sizeof(int)*idprop->len);\
1958
memcpy(IDP_Array(idprop), values, sizeof(int)*idprop->len);
1960
rna_idproperty_touch(idprop);
1520
else if(prop->arraydimension == 0)
1962
else if (prop->arraydimension == 0)
1521
1963
RNA_property_int_set(ptr, prop, values[0]);
1522
else if(iprop->setarray)
1964
else if (iprop->setarray)
1523
1965
iprop->setarray(ptr, values);
1524
else if(prop->flag & PROP_EDITABLE) {
1966
else if (prop->flag & PROP_EDITABLE) {
1525
1967
IDPropertyTemplate val = {0};
1526
1968
IDProperty *group;
1528
val.array.len= prop->totarraylength;
1529
val.array.type= IDP_INT;
1970
val.array.len = prop->totarraylength;
1971
val.array.type = IDP_INT;
1531
group= RNA_struct_idproperties(ptr, 1);
1533
idprop= IDP_New(IDP_ARRAY, val, (char*)prop->identifier);
1973
group = RNA_struct_idprops(ptr, 1);
1975
idprop = IDP_New(IDP_ARRAY, &val, prop->identifier);
1534
1976
IDP_AddToGroup(group, idprop);
1535
1977
memcpy(IDP_Array(idprop), values, sizeof(int)*idprop->len);
1540
1982
void RNA_property_int_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, int value)
1542
1984
int tmp[RNA_MAX_ARRAY_LENGTH];
1543
int len= rna_ensure_property_array_length(ptr, prop);
1545
if(len <= RNA_MAX_ARRAY_LENGTH) {
1985
int len = rna_ensure_property_array_length(ptr, prop);
1987
BLI_assert(RNA_property_type(prop) == PROP_INT);
1988
BLI_assert(RNA_property_array_check(prop) != 0);
1990
if (len <= RNA_MAX_ARRAY_LENGTH) {
1546
1991
RNA_property_int_get_array(ptr, prop, tmp);
1548
1993
RNA_property_int_set_array(ptr, prop, tmp);
1553
tmparray= MEM_callocN(sizeof(int)*len, "RNA_property_int_get_index");
1998
tmparray = MEM_callocN(sizeof(int)*len, "RNA_property_int_get_index");
1554
1999
RNA_property_int_get_array(ptr, prop, tmparray);
1555
tmparray[index]= value;
2000
tmparray[index] = value;
1556
2001
RNA_property_int_set_array(ptr, prop, tmparray);
1557
2002
MEM_freeN(tmparray);
1561
int RNA_property_int_get_default(PointerRNA *ptr, PropertyRNA *prop)
2006
int RNA_property_int_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
1563
IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
2008
IntPropertyRNA *iprop = (IntPropertyRNA*)prop;
1564
2009
return iprop->defaultvalue;
1567
void RNA_property_int_get_default_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
2012
void RNA_property_int_get_default_array(PointerRNA *UNUSED(ptr), PropertyRNA *prop, int *values)
1569
IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
2014
IntPropertyRNA *iprop = (IntPropertyRNA*)prop;
1571
if(prop->arraydimension == 0)
1572
values[0]= iprop->defaultvalue;
1573
else if(iprop->defaultarray)
2016
BLI_assert(RNA_property_type(prop) == PROP_INT);
2017
BLI_assert(RNA_property_array_check(prop) != 0);
2019
if (prop->arraydimension == 0)
2020
values[0] = iprop->defaultvalue;
2021
else if (iprop->defaultarray)
1574
2022
memcpy(values, iprop->defaultarray, sizeof(int)*prop->totarraylength);
1576
2024
memset(values, 0, sizeof(int)*prop->totarraylength);
1617
2068
void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value)
1619
FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
2070
FloatPropertyRNA *fprop = (FloatPropertyRNA*)prop;
1620
2071
IDProperty *idprop;
1622
if((idprop=rna_idproperty_check(&prop, ptr))) {
1623
if(idprop->type == IDP_FLOAT)
1624
IDP_Float(idprop)= value;
2073
BLI_assert(RNA_property_type(prop) == PROP_FLOAT);
2074
BLI_assert(RNA_property_array_check(prop) == 0);
2075
/* useful to check on bad values but set function should clamp */
2076
/* BLI_assert(RNA_property_float_clamp(ptr, prop, &value) == 0); */
2078
if ((idprop = rna_idproperty_check(&prop, ptr))) {
2079
if (idprop->type == IDP_FLOAT)
2080
IDP_Float(idprop) = value;
1626
IDP_Double(idprop)= value;
2082
IDP_Double(idprop) = value;
2084
rna_idproperty_touch(idprop);
1628
else if(fprop->set) {
2086
else if (fprop->set) {
1629
2087
fprop->set(ptr, value);
1631
else if(prop->flag & PROP_EDITABLE) {
2089
else if (prop->flag & PROP_EDITABLE) {
1632
2090
IDPropertyTemplate val = {0};
1633
2091
IDProperty *group;
1637
group= RNA_struct_idproperties(ptr, 1);
1639
IDP_AddToGroup(group, IDP_New(IDP_FLOAT, val, (char*)prop->identifier));
2095
group = RNA_struct_idprops(ptr, 1);
2097
IDP_AddToGroup(group, IDP_New(IDP_FLOAT, &val, prop->identifier));
1643
2101
void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
1645
FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
2103
FloatPropertyRNA *fprop = (FloatPropertyRNA*)prop;
1646
2104
IDProperty *idprop;
1649
if((idprop=rna_idproperty_check(&prop, ptr))) {
1650
if(prop->arraydimension == 0)
1651
values[0]= RNA_property_float_get(ptr, prop);
1652
else if(idprop->subtype == IDP_FLOAT) {
2107
BLI_assert(RNA_property_type(prop) == PROP_FLOAT);
2108
BLI_assert(RNA_property_array_check(prop) != 0);
2110
if ((idprop = rna_idproperty_check(&prop, ptr))) {
2111
if (prop->arraydimension == 0)
2112
values[0] = RNA_property_float_get(ptr, prop);
2113
else if (idprop->subtype == IDP_FLOAT) {
1653
2114
memcpy(values, IDP_Array(idprop), sizeof(float)*idprop->len);
1656
for(i=0; i<idprop->len; i++)
1657
values[i]= (float)(((double*)IDP_Array(idprop))[i]);
2117
for (i = 0; i<idprop->len; i++)
2118
values[i] = (float)(((double*)IDP_Array(idprop))[i]);
1660
else if(prop->arraydimension == 0)
1661
values[0]= RNA_property_float_get(ptr, prop);
1662
else if(fprop->getarray)
2121
else if (prop->arraydimension == 0)
2122
values[0] = RNA_property_float_get(ptr, prop);
2123
else if (fprop->getarray)
1663
2124
fprop->getarray(ptr, values);
1664
else if(fprop->defaultarray)
2125
else if (fprop->defaultarray)
1665
2126
memcpy(values, fprop->defaultarray, sizeof(float)*prop->totarraylength);
1667
2128
memset(values, 0, sizeof(float)*prop->totarraylength);
2131
void RNA_property_float_get_array_range(PointerRNA *ptr, PropertyRNA *prop, float values[2])
2133
const int array_len = RNA_property_array_length(ptr, prop);
2135
if (array_len <= 0) {
2139
else if (array_len == 1) {
2140
RNA_property_float_get_array(ptr, prop, values);
2141
values[1] = values[0];
2144
float arr_stack[32];
2148
if (array_len > 32) {
2149
arr = MEM_mallocN(sizeof(float) * array_len, "RNA_property_float_get_array_range");
2155
RNA_property_float_get_array(ptr, prop, arr);
2156
values[0] = values[1] = arr[0];
2157
for (i = 1; i < array_len; i++) {
2158
values[0] = MIN2(values[0], arr[i]);
2159
values[1] = MAX2(values[1], arr[i]);
2162
if (arr != arr_stack) {
1670
2168
float RNA_property_float_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
1672
2170
float tmp[RNA_MAX_ARRAY_LENGTH];
1673
int len= rna_ensure_property_array_length(ptr, prop);
1675
if(len <= RNA_MAX_ARRAY_LENGTH) {
2171
int len = rna_ensure_property_array_length(ptr, prop);
2173
BLI_assert(RNA_property_type(prop) == PROP_FLOAT);
2174
BLI_assert(RNA_property_array_check(prop) != 0);
2176
if (len <= RNA_MAX_ARRAY_LENGTH) {
1676
2177
RNA_property_float_get_array(ptr, prop, tmp);
1677
2178
return tmp[index];
1680
2181
float *tmparray, value;
1682
tmparray= MEM_callocN(sizeof(float)*len, "RNA_property_float_get_index");
2183
tmparray = MEM_callocN(sizeof(float)*len, "RNA_property_float_get_index");
1683
2184
RNA_property_float_get_array(ptr, prop, tmparray);
1684
value= tmparray[index];
2185
value = tmparray[index];
1685
2186
MEM_freeN(tmparray);
1692
2193
void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const float *values)
1694
FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
2195
FloatPropertyRNA *fprop = (FloatPropertyRNA*)prop;
1695
2196
IDProperty *idprop;
1698
if((idprop=rna_idproperty_check(&prop, ptr))) {
1699
if(prop->arraydimension == 0) {
1700
if(idprop->type == IDP_FLOAT)
1701
IDP_Float(idprop)= values[0];
2199
BLI_assert(RNA_property_type(prop) == PROP_FLOAT);
2200
BLI_assert(RNA_property_array_check(prop) != 0);
2202
if ((idprop = rna_idproperty_check(&prop, ptr))) {
2203
if (prop->arraydimension == 0) {
2204
if (idprop->type == IDP_FLOAT)
2205
IDP_Float(idprop) = values[0];
1703
IDP_Double(idprop)= values[0];
2207
IDP_Double(idprop) = values[0];
1705
else if(idprop->subtype == IDP_FLOAT) {
2209
else if (idprop->subtype == IDP_FLOAT) {
1706
2210
memcpy(IDP_Array(idprop), values, sizeof(float)*idprop->len);
1709
for(i=0; i<idprop->len; i++)
1710
((double*)IDP_Array(idprop))[i]= values[i];
2213
for (i = 0; i<idprop->len; i++)
2214
((double*)IDP_Array(idprop))[i] = values[i];
2217
rna_idproperty_touch(idprop);
1713
else if(prop->arraydimension == 0)
2219
else if (prop->arraydimension == 0)
1714
2220
RNA_property_float_set(ptr, prop, values[0]);
1715
else if(fprop->setarray) {
2221
else if (fprop->setarray) {
1716
2222
fprop->setarray(ptr, values);
1718
else if(prop->flag & PROP_EDITABLE) {
2224
else if (prop->flag & PROP_EDITABLE) {
1719
2225
IDPropertyTemplate val = {0};
1720
2226
IDProperty *group;
1722
val.array.len= prop->totarraylength;
1723
val.array.type= IDP_FLOAT;
2228
val.array.len = prop->totarraylength;
2229
val.array.type = IDP_FLOAT;
1725
group= RNA_struct_idproperties(ptr, 1);
1727
idprop= IDP_New(IDP_ARRAY, val, (char*)prop->identifier);
2231
group = RNA_struct_idprops(ptr, 1);
2233
idprop = IDP_New(IDP_ARRAY, &val, prop->identifier);
1728
2234
IDP_AddToGroup(group, idprop);
1729
2235
memcpy(IDP_Array(idprop), values, sizeof(float)*idprop->len);
1734
2240
void RNA_property_float_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, float value)
1736
2242
float tmp[RNA_MAX_ARRAY_LENGTH];
1737
int len= rna_ensure_property_array_length(ptr, prop);
1739
if(len <= RNA_MAX_ARRAY_LENGTH) {
2243
int len = rna_ensure_property_array_length(ptr, prop);
2245
BLI_assert(RNA_property_type(prop) == PROP_FLOAT);
2246
BLI_assert(RNA_property_array_check(prop) != 0);
2248
if (len <= RNA_MAX_ARRAY_LENGTH) {
1740
2249
RNA_property_float_get_array(ptr, prop, tmp);
1742
2251
RNA_property_float_set_array(ptr, prop, tmp);
1745
2254
float *tmparray;
1747
tmparray= MEM_callocN(sizeof(float)*len, "RNA_property_float_get_index");
2256
tmparray = MEM_callocN(sizeof(float)*len, "RNA_property_float_get_index");
1748
2257
RNA_property_float_get_array(ptr, prop, tmparray);
1749
tmparray[index]= value;
2258
tmparray[index] = value;
1750
2259
RNA_property_float_set_array(ptr, prop, tmparray);
1751
2260
MEM_freeN(tmparray);
1755
float RNA_property_float_get_default(PointerRNA *ptr, PropertyRNA *prop)
2264
float RNA_property_float_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
1757
FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
2266
FloatPropertyRNA *fprop = (FloatPropertyRNA*)prop;
2268
BLI_assert(RNA_property_type(prop) == PROP_FLOAT);
2269
BLI_assert(RNA_property_array_check(prop) == 0);
1758
2271
return fprop->defaultvalue;
1761
void RNA_property_float_get_default_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
2274
void RNA_property_float_get_default_array(PointerRNA *UNUSED(ptr), PropertyRNA *prop, float *values)
1763
FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
2276
FloatPropertyRNA *fprop = (FloatPropertyRNA*)prop;
1765
if(prop->arraydimension == 0)
1766
values[0]= fprop->defaultvalue;
1767
else if(fprop->defaultarray)
2278
BLI_assert(RNA_property_type(prop) == PROP_FLOAT);
2279
BLI_assert(RNA_property_array_check(prop) != 0);
2281
if (prop->arraydimension == 0)
2282
values[0] = fprop->defaultvalue;
2283
else if (fprop->defaultarray)
1768
2284
memcpy(values, fprop->defaultarray, sizeof(float)*prop->totarraylength);
1770
2286
memset(values, 0, sizeof(float)*prop->totarraylength);
1794
2313
void RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop, char *value)
1796
StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
2315
StringPropertyRNA *sprop = (StringPropertyRNA*)prop;
1797
2316
IDProperty *idprop;
1799
if((idprop=rna_idproperty_check(&prop, ptr)))
1800
strcpy(value, IDP_String(idprop));
2318
BLI_assert(RNA_property_type(prop) == PROP_STRING);
2320
if ((idprop = rna_idproperty_check(&prop, ptr))) {
2321
/* editing bytes is not 100% supported
2322
* since they can contain NIL chars */
2323
if (idprop->subtype == IDP_STRING_SUB_BYTE) {
2324
memcpy(value, IDP_String(idprop), idprop->len);
2325
value[idprop->len] = '\0';
2328
memcpy(value, IDP_String(idprop), idprop->len);
2331
else if (sprop->get) {
1802
2332
sprop->get(ptr, value);
1804
2335
strcpy(value, sprop->defaultvalue);
1807
char *RNA_property_string_get_alloc(PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen)
2339
char *RNA_property_string_get_alloc(PointerRNA *ptr, PropertyRNA *prop,
2340
char *fixedbuf, int fixedlen, int *r_len)
1812
length= RNA_property_string_length(ptr, prop);
1814
if(length+1 < fixedlen)
2345
BLI_assert(RNA_property_type(prop) == PROP_STRING);
2347
length = RNA_property_string_length(ptr, prop);
2349
if (length+1 < fixedlen)
1817
buf= MEM_callocN(sizeof(char)*(length+1), "RNA_string_get_alloc");
2352
buf = MEM_mallocN(sizeof(char)*(length+1), "RNA_string_get_alloc");
2355
/* safety check to ensure the string is actually set */
1819
2359
RNA_property_string_get(ptr, prop, buf);
2362
BLI_assert(buf[length] == '\0');
1824
2372
/* this is the length without \0 terminator */
1825
2373
int RNA_property_string_length(PointerRNA *ptr, PropertyRNA *prop)
1827
StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
2375
StringPropertyRNA *sprop = (StringPropertyRNA*)prop;
1828
2376
IDProperty *idprop;
1830
if((idprop=rna_idproperty_check(&prop, ptr)))
1831
return strlen(IDP_String(idprop));
1832
else if(sprop->length)
2378
BLI_assert(RNA_property_type(prop) == PROP_STRING);
2380
if ((idprop = rna_idproperty_check(&prop, ptr))) {
2381
if (idprop->subtype == IDP_STRING_SUB_BYTE) {
2386
/* these _must_ stay in sync */
2387
BLI_assert(strlen(IDP_String(idprop)) == idprop->len - 1);
2389
return idprop->len - 1;
2392
else if (sprop->length)
1833
2393
return sprop->length(ptr);
1835
2395
return strlen(sprop->defaultvalue);
1899
2474
void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value)
1901
EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
2476
EnumPropertyRNA *eprop = (EnumPropertyRNA*)prop;
1902
2477
IDProperty *idprop;
1904
if((idprop=rna_idproperty_check(&prop, ptr)))
1905
IDP_Int(idprop)= value;
1906
else if(eprop->set) {
2479
BLI_assert(RNA_property_type(prop) == PROP_ENUM);
2481
if ((idprop = rna_idproperty_check(&prop, ptr))) {
2482
IDP_Int(idprop) = value;
2483
rna_idproperty_touch(idprop);
2485
else if (eprop->set) {
1907
2486
eprop->set(ptr, value);
1909
else if(prop->flag & PROP_EDITABLE) {
2488
else if (prop->flag & PROP_EDITABLE) {
1910
2489
IDPropertyTemplate val = {0};
1911
2490
IDProperty *group;
1915
group= RNA_struct_idproperties(ptr, 1);
1917
IDP_AddToGroup(group, IDP_New(IDP_INT, val, (char*)prop->identifier));
2494
group = RNA_struct_idprops(ptr, 1);
2496
IDP_AddToGroup(group, IDP_New(IDP_INT, &val, prop->identifier));
1921
int RNA_property_enum_get_default(PointerRNA *ptr, PropertyRNA *prop)
2500
int RNA_property_enum_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
1923
EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
2502
EnumPropertyRNA *eprop = (EnumPropertyRNA*)prop;
2504
BLI_assert(RNA_property_type(prop) == PROP_ENUM);
1924
2506
return eprop->defaultvalue;
2509
void *RNA_property_enum_py_data_get(PropertyRNA *prop)
2511
EnumPropertyRNA *eprop = (EnumPropertyRNA*)prop;
2513
BLI_assert(RNA_property_type(prop) == PROP_ENUM);
2515
return eprop->py_data;
1928
2518
PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop)
1930
PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
2520
PointerPropertyRNA *pprop = (PointerPropertyRNA*)prop;
1931
2521
IDProperty *idprop;
1933
if((idprop=rna_idproperty_check(&prop, ptr))) {
1934
pprop= (PointerPropertyRNA*)prop;
2523
BLI_assert(RNA_property_type(prop) == PROP_POINTER);
2525
if ((idprop = rna_idproperty_check(&prop, ptr))) {
2526
pprop = (PointerPropertyRNA*)prop;
1936
2528
/* for groups, data is idprop itself */
1937
2529
return rna_pointer_inherit_refine(ptr, pprop->type, idprop);
1939
else if(pprop->get) {
2531
else if (pprop->get) {
1940
2532
return pprop->get(ptr);
1942
else if(prop->flag & PROP_IDPROPERTY) {
2534
else if (prop->flag & PROP_IDPROPERTY) {
1943
2535
/* XXX temporary hack to add it automatically, reading should
1944
never do any write ops, to ensure thread safety etc .. */
2536
* never do any write ops, to ensure thread safety etc .. */
1945
2537
RNA_property_pointer_add(ptr, prop);
1946
2538
return RNA_property_pointer_get(ptr, prop);
1951
memset(&result, 0, sizeof(result));
2541
return PointerRNA_NULL;
1956
2545
void RNA_property_pointer_set(PointerRNA *ptr, PropertyRNA *prop, PointerRNA ptr_value)
1960
if((idprop=rna_idproperty_check(&prop, ptr))) {
2547
/*IDProperty *idprop;*/
2549
BLI_assert(RNA_property_type(prop) == PROP_POINTER);
2551
if ((/*idprop=*/ rna_idproperty_check(&prop, ptr))) {
1961
2552
/* not supported */
2553
/* rna_idproperty_touch(idprop); */
1964
PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
2556
PointerPropertyRNA *pprop = (PointerPropertyRNA*)prop;
1967
2559
!((prop->flag & PROP_NEVER_NULL) && ptr_value.data == NULL) &&
1968
2560
!((prop->flag & PROP_ID_SELF_CHECK) && ptr->id.data == ptr_value.id.data)
2567
PointerRNA RNA_property_pointer_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop))
2569
/*PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop; */
2571
/* BLI_assert(RNA_property_type(prop) == PROP_POINTER); */
2573
return PointerRNA_NULL; /* FIXME: there has to be a way... */
1975
2576
void RNA_property_pointer_add(PointerRNA *ptr, PropertyRNA *prop)
1979
if((idprop=rna_idproperty_check(&prop, ptr))) {
2578
/*IDProperty *idprop;*/
2580
BLI_assert(RNA_property_type(prop) == PROP_POINTER);
2582
if ((/*idprop=*/rna_idproperty_check(&prop, ptr))) {
1980
2583
/* already exists */
1982
else if(prop->flag & PROP_IDPROPERTY) {
2585
else if (prop->flag & PROP_IDPROPERTY) {
1983
2586
IDPropertyTemplate val = {0};
1984
2587
IDProperty *group;
1988
group= RNA_struct_idproperties(ptr, 1);
1990
IDP_AddToGroup(group, IDP_New(IDP_GROUP, val, (char*)prop->identifier));
2591
group = RNA_struct_idprops(ptr, 1);
2593
IDP_AddToGroup(group, IDP_New(IDP_GROUP, &val, prop->identifier));
1993
printf("RNA_property_pointer_add %s.%s: only supported for id properties.\n", ptr->type->identifier, prop->identifier);
2596
printf("%s %s.%s: only supported for id properties.\n", __func__, ptr->type->identifier, prop->identifier);
1996
2599
void RNA_property_pointer_remove(PointerRNA *ptr, PropertyRNA *prop)
1998
2601
IDProperty *idprop, *group;
2000
if((idprop=rna_idproperty_check(&prop, ptr))) {
2001
group= RNA_struct_idproperties(ptr, 0);
2603
BLI_assert(RNA_property_type(prop) == PROP_POINTER);
2605
if ((idprop = rna_idproperty_check(&prop, ptr))) {
2606
group = RNA_struct_idprops(ptr, 0);
2004
2609
IDP_RemFromGroup(group, idprop);
2005
2610
IDP_FreeProperty(idprop);
2006
2611
MEM_freeN(idprop);
2010
printf("RNA_property_pointer_remove %s.%s: only supported for id properties.\n", ptr->type->identifier, prop->identifier);
2615
printf("%s %s.%s: only supported for id properties.\n", __func__, ptr->type->identifier, prop->identifier);
2013
2618
static void rna_property_collection_get_idp(CollectionPropertyIterator *iter)
2015
CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)iter->prop;
2620
CollectionPropertyRNA *cprop = (CollectionPropertyRNA*)iter->prop;
2017
iter->ptr.data= rna_iterator_array_get(iter);
2018
iter->ptr.type= cprop->item_type;
2622
iter->ptr.data = rna_iterator_array_get(iter);
2623
iter->ptr.type = cprop->item_type;
2019
2624
rna_pointer_inherit_id(cprop->item_type, &iter->parent, &iter->ptr);
2096
2705
void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *r_ptr)
2098
2707
IDProperty *idprop;
2099
// CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
2101
if((idprop=rna_idproperty_check(&prop, ptr))) {
2708
/* CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; */
2710
BLI_assert(RNA_property_type(prop) == PROP_COLLECTION);
2712
if ((idprop = rna_idproperty_check(&prop, ptr))) {
2102
2713
IDPropertyTemplate val = {0};
2103
2714
IDProperty *item;
2105
item= IDP_New(IDP_GROUP, val, "");
2716
item = IDP_New(IDP_GROUP, &val, "");
2106
2717
IDP_AppendArray(idprop, item);
2107
// IDP_FreeProperty(item); // IDP_AppendArray does a shallow copy (memcpy), only free memory
2718
/* IDP_FreeProperty(item); *//* IDP_AppendArray does a shallow copy (memcpy), only free memory */
2108
2719
MEM_freeN(item);
2110
else if(prop->flag & PROP_IDPROPERTY) {
2721
else if (prop->flag & PROP_IDPROPERTY) {
2111
2722
IDProperty *group, *item;
2112
2723
IDPropertyTemplate val = {0};
2114
group= RNA_struct_idproperties(ptr, 1);
2116
idprop= IDP_NewIDPArray(prop->identifier);
2725
group = RNA_struct_idprops(ptr, 1);
2727
idprop = IDP_NewIDPArray(prop->identifier);
2117
2728
IDP_AddToGroup(group, idprop);
2119
item= IDP_New(IDP_GROUP, val, "");
2730
item = IDP_New(IDP_GROUP, &val, "");
2120
2731
IDP_AppendArray(idprop, item);
2121
// IDP_FreeProperty(item); // IDP_AppendArray does a shallow copy (memcpy), only free memory
2732
/* IDP_FreeProperty(item); *//* IDP_AppendArray does a shallow copy (memcpy), only free memory */
2122
2733
MEM_freeN(item);
2126
2737
/* py api calls directly */
2128
else if(cprop->add){
2129
if(!(cprop->add->flag & FUNC_USE_CONTEXT)) { /* XXX check for this somewhere else */
2739
else if (cprop->add) {
2740
if (!(cprop->add->flag & FUNC_USE_CONTEXT)) { /* XXX check for this somewhere else */
2130
2741
ParameterList params;
2131
2742
RNA_parameter_list_create(¶ms, ptr, cprop->add);
2132
2743
RNA_function_call(NULL, NULL, ptr, cprop->add, ¶ms);
2284
2904
int RNA_property_collection_lookup_string(PointerRNA *ptr, PropertyRNA *prop, const char *key, PointerRNA *r_ptr)
2286
CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
2288
if(cprop->lookupstring) {
2906
CollectionPropertyRNA *cprop = (CollectionPropertyRNA*)rna_ensure_property(prop);
2908
BLI_assert(RNA_property_type(prop) == PROP_COLLECTION);
2910
if (cprop->lookupstring) {
2289
2911
/* we have a callback defined, use it */
2290
*r_ptr= cprop->lookupstring(ptr, key);
2291
return (r_ptr->data != NULL);
2912
return cprop->lookupstring(ptr, key, r_ptr);
2294
2915
/* no callback defined, compare with name properties if they exist */
2295
2916
CollectionPropertyIterator iter;
2296
2917
PropertyRNA *nameprop;
2297
2918
char name[256], *nameptr;
2920
int keylen = strlen(key);
2300
2923
RNA_property_collection_begin(ptr, prop, &iter);
2301
for(; iter.valid; RNA_property_collection_next(&iter)) {
2302
if(iter.ptr.data && iter.ptr.type->nameproperty) {
2303
nameprop= iter.ptr.type->nameproperty;
2305
nameptr= RNA_property_string_get_alloc(&iter.ptr, nameprop, name, sizeof(name));
2307
if(strcmp(nameptr, key) == 0) {
2924
for (; iter.valid; RNA_property_collection_next(&iter)) {
2925
if (iter.ptr.data && iter.ptr.type->nameproperty) {
2926
nameprop = iter.ptr.type->nameproperty;
2928
nameptr = RNA_property_string_get_alloc(&iter.ptr, nameprop, name, sizeof(name), &namelen);
2930
if ((keylen == namelen) && (strcmp(nameptr, key) == 0)) {
2312
if((char *)&name != nameptr)
2935
if ((char *)&name != nameptr)
2313
2936
MEM_freeN(nameptr);
2319
2942
RNA_property_collection_end(&iter);
2322
2945
memset(r_ptr, 0, sizeof(*r_ptr));
2324
2947
return iter.valid;
2951
/* zero return is an assignment error */
2952
int RNA_property_collection_assign_int(PointerRNA *ptr, PropertyRNA *prop, const int key, const PointerRNA *assign_ptr)
2954
CollectionPropertyRNA *cprop = (CollectionPropertyRNA*)rna_ensure_property(prop);
2956
BLI_assert(RNA_property_type(prop) == PROP_COLLECTION);
2958
if (cprop->assignint) {
2959
/* we have a callback defined, use it */
2960
return cprop->assignint(ptr, key, assign_ptr);
2328
2966
int RNA_property_collection_type_get(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *r_ptr)
2331
return ((r_ptr->type = prop->srna) ? 1:0);
2968
BLI_assert(RNA_property_type(prop) == PROP_COLLECTION);
2971
return ((r_ptr->type = rna_ensure_property(prop)->srna) ? 1:0);
2334
2974
int RNA_property_collection_raw_array(PointerRNA *ptr, PropertyRNA *prop, PropertyRNA *itemprop, RawArray *array)
2405
static int rna_raw_access(ReportList *reports, PointerRNA *ptr, PropertyRNA *prop, char *propname, void *inarray, RawPropertyType intype, int inlen, int set)
3047
static int rna_raw_access(ReportList *reports, PointerRNA *ptr, PropertyRNA *prop, const char *propname,
3048
void *inarray, RawPropertyType intype, int inlen, int set)
2407
3050
StructRNA *ptype;
2408
3051
PointerRNA itemptr;
2409
3052
PropertyRNA *itemprop, *iprop;
2410
PropertyType itemtype=0;
3053
PropertyType itemtype = 0;
2414
3057
/* initialize in array, stride assumed 0 in following code */
2420
ptype= RNA_property_pointer_type(ptr, prop);
3063
ptype = RNA_property_pointer_type(ptr, prop);
2422
3065
/* try to get item property pointer */
2423
3066
RNA_pointer_create(NULL, ptype, NULL, &itemptr);
2424
itemprop= RNA_struct_find_property(&itemptr, propname);
3067
itemprop = RNA_struct_find_property(&itemptr, propname);
2427
3070
/* we have item property pointer */
2430
3073
/* check type */
2431
itemtype= RNA_property_type(itemprop);
3074
itemtype = RNA_property_type(itemprop);
2433
if(!ELEM3(itemtype, PROP_BOOLEAN, PROP_INT, PROP_FLOAT)) {
2434
BKE_report(reports, RPT_ERROR, "Only boolean, int and float properties supported.");
3076
if (!ELEM3(itemtype, PROP_BOOLEAN, PROP_INT, PROP_FLOAT)) {
3077
BKE_report(reports, RPT_ERROR, "Only boolean, int and float properties supported");
2438
3081
/* check item array */
2439
itemlen= RNA_property_array_length(&itemptr, itemprop);
3082
itemlen = RNA_property_array_length(&itemptr, itemprop);
2441
3084
/* try to access as raw array */
2442
if(RNA_property_collection_raw_array(ptr, prop, itemprop, &out)) {
3085
if (RNA_property_collection_raw_array(ptr, prop, itemprop, &out)) {
2443
3086
int arraylen = (itemlen == 0) ? 1 : itemlen;
2444
if(in.len != arraylen*out.len) {
2445
BKE_reportf(reports, RPT_ERROR, "Array length mismatch (expected %d, got %d).", out.len*arraylen, in.len);
3087
if (in.len != arraylen*out.len) {
3088
BKE_reportf(reports, RPT_ERROR, "Array length mismatch (expected %d, got %d)",
3089
out.len * arraylen, in.len);
2449
3093
/* matching raw types */
2450
if(out.type == in.type) {
2451
void *inp= in.array;
2452
void *outp= out.array;
3094
if (out.type == in.type) {
3095
void *inp = in.array;
3096
void *outp = out.array;
2455
size= RNA_raw_type_sizeof(out.type) * arraylen;
3099
size = RNA_raw_type_sizeof(out.type) * arraylen;
2457
for(a=0; a<out.len; a++) {
2458
if(set) memcpy(outp, inp, size);
3101
for (a = 0; a<out.len; a++) {
3102
if (set) memcpy(outp, inp, size);
2459
3103
else memcpy(inp, outp, size);
2461
inp= (char*)inp + size;
2462
outp= (char*)outp + out.stride;
3105
inp = (char*)inp + size;
3106
outp = (char*)outp + out.stride;
2484
3128
/* no item property pointer, can still be id property, or
2485
3129
* property of a type derived from the collection pointer type */
2486
3130
RNA_PROP_BEGIN(ptr, itemptr, prop) {
2489
3133
/* we got the property already */
2493
3137
/* not yet, look it up and verify if it is valid */
2494
iprop= RNA_struct_find_property(&itemptr, propname);
3138
iprop = RNA_struct_find_property(&itemptr, propname);
2497
itemlen= RNA_property_array_length(&itemptr, iprop);
2498
itemtype= RNA_property_type(iprop);
3141
itemlen = RNA_property_array_length(&itemptr, iprop);
3142
itemtype = RNA_property_type(iprop);
2501
BKE_reportf(reports, RPT_ERROR, "Property named %s not found.", propname);
3145
BKE_reportf(reports, RPT_ERROR, "Property named %s not found", propname);
2506
if(!ELEM3(itemtype, PROP_BOOLEAN, PROP_INT, PROP_FLOAT)) {
2507
BKE_report(reports, RPT_ERROR, "Only boolean, int and float properties supported.");
3150
if (!ELEM3(itemtype, PROP_BOOLEAN, PROP_INT, PROP_FLOAT)) {
3151
BKE_report(reports, RPT_ERROR, "Only boolean, int and float properties supported");
2513
3157
/* editable check */
2514
if(RNA_property_editable(&itemptr, iprop)) {
2515
if(a+itemlen > in.len) {
2516
BKE_reportf(reports, RPT_ERROR, "Array length mismatch (got %d, expected more).", in.len);
3158
if (!set || RNA_property_editable(&itemptr, iprop)) {
3159
if (a+itemlen > in.len) {
3160
BKE_reportf(reports, RPT_ERROR, "Array length mismatch (got %d, expected more)", in.len);
2522
3166
/* handle conversions */
2525
3169
case PROP_BOOLEAN: {
2527
3171
RAW_GET(int, b, in, a);
2757
3403
void rna_iterator_listbase_end(CollectionPropertyIterator *iter)
2759
3405
MEM_freeN(iter->internal);
2760
iter->internal= NULL;
3406
iter->internal = NULL;
2763
3409
PointerRNA rna_listbase_lookup_int(PointerRNA *ptr, StructRNA *type, struct ListBase *lb, int index)
2765
void *data= BLI_findlink(lb, index);
3411
void *data = BLI_findlink(lb, index);
2766
3412
return rna_pointer_inherit_refine(ptr, type, data);
2769
void rna_iterator_array_begin(CollectionPropertyIterator *iter, void *ptr, int itemsize, int length, int free_ptr, IteratorSkipFunc skip)
3415
void rna_iterator_array_begin(CollectionPropertyIterator *iter, void *ptr, int itemsize, int length,
3416
int free_ptr, IteratorSkipFunc skip)
2771
3418
ArrayIterator *internal;
2776
internal= MEM_callocN(sizeof(ArrayIterator), "ArrayIterator");
2778
internal->free_ptr= free_ptr ? ptr:NULL;
2779
internal->endptr= ((char*)ptr)+length*itemsize;
2780
internal->itemsize= itemsize;
2781
internal->skip= skip;
2783
iter->internal= internal;
2784
iter->valid= (internal->ptr != internal->endptr);
2786
if(skip && iter->valid && skip(iter, internal->ptr))
3422
else if (length == 0) {
3427
internal = MEM_callocN(sizeof(ArrayIterator), "ArrayIterator");
3428
internal->ptr = ptr;
3429
internal->free_ptr = free_ptr ? ptr:NULL;
3430
internal->endptr = ((char*)ptr)+length*itemsize;
3431
internal->itemsize = itemsize;
3432
internal->skip = skip;
3433
internal->length = length;
3435
iter->internal = internal;
3436
iter->valid = (internal->ptr != internal->endptr);
3438
if (skip && iter->valid && skip(iter, internal->ptr))
2787
3439
rna_iterator_array_next(iter);
2790
3442
void rna_iterator_array_next(CollectionPropertyIterator *iter)
2792
ArrayIterator *internal= iter->internal;
3444
ArrayIterator *internal = iter->internal;
2794
if(internal->skip) {
3446
if (internal->skip) {
2796
3448
internal->ptr += internal->itemsize;
2797
iter->valid= (internal->ptr != internal->endptr);
2798
} while(iter->valid && internal->skip(iter, internal->ptr));
3449
iter->valid = (internal->ptr != internal->endptr);
3450
} while (iter->valid && internal->skip(iter, internal->ptr));
2801
3453
internal->ptr += internal->itemsize;
2802
iter->valid= (internal->ptr != internal->endptr);
3454
iter->valid = (internal->ptr != internal->endptr);
2806
3458
void *rna_iterator_array_get(CollectionPropertyIterator *iter)
2808
ArrayIterator *internal= iter->internal;
3460
ArrayIterator *internal = iter->internal;
2810
3462
return internal->ptr;
2813
3465
void *rna_iterator_array_dereference_get(CollectionPropertyIterator *iter)
2815
ArrayIterator *internal= iter->internal;
3467
ArrayIterator *internal = iter->internal;
2817
3469
/* for ** arrays */
2818
3470
return *(void**)(internal->ptr);
2930
3604
PropertyRNA *prop;
2931
3605
PointerRNA curptr, nextptr;
2932
3606
char fixedbuf[256], *token;
2933
int type, len, intkey;
2938
if(path==NULL || *path=='\0')
3612
if (path == NULL || *path =='\0')
2942
int use_id_prop = (*path=='[') ? 1:0;
3616
int use_id_prop = (*path =='[') ? 1:0;
2943
3617
/* custom property lookup ?
2944
3618
* C.object["someprop"]
2947
3621
/* look up property name in current struct */
2948
token= rna_path_token(&path, fixedbuf, sizeof(fixedbuf), use_id_prop);
3622
token = rna_path_token(&path, fixedbuf, sizeof(fixedbuf), use_id_prop);
2953
if(use_id_prop) { /* look up property name in current struct */
2954
IDProperty *group= RNA_struct_idproperties(&curptr, 0);
2955
if(group && rna_token_strip_quotes(token))
2956
prop= (PropertyRNA *)IDP_GetPropertyFromGroup(group, token+1);
3627
if (use_id_prop) { /* look up property name in current struct */
3628
IDProperty *group = RNA_struct_idprops(&curptr, 0);
3629
if (group && rna_token_strip_quotes(token))
3630
prop = (PropertyRNA *)IDP_GetPropertyFromGroup(group, token+1);
2959
prop= RNA_struct_find_property(&curptr, token);
3633
prop = RNA_struct_find_property(&curptr, token);
2962
if(token != fixedbuf)
3636
if (token != fixedbuf)
2963
3637
MEM_freeN(token);
2968
type= RNA_property_type(prop);
3642
type = RNA_property_type(prop);
2970
3644
/* now look up the value of this property if it is a pointer or
2971
3645
* collection, otherwise return the property rna so that the
2972
3646
* caller can read the value of the property itself */
2973
3647
switch (type) {
2974
3648
case PROP_POINTER:
2975
nextptr= RNA_property_pointer_get(&curptr, prop);
3649
nextptr = RNA_property_pointer_get(&curptr, prop);
3653
prop = NULL; /* now we have a PointerRNA, the prop is our parent so forget it */
3654
if (index) *index = -1;
2983
3660
case PROP_COLLECTION:
2985
/* resolve the lookup with [] brackets */
2986
token= rna_path_token(&path, fixedbuf, sizeof(fixedbuf), 1);
2993
/* check for "" to see if it is a string */
2994
if(rna_token_strip_quotes(token)) {
2995
RNA_property_collection_lookup_string(&curptr, prop, token+1, &nextptr);
2998
/* otherwise do int lookup */
2999
intkey= atoi(token);
3000
RNA_property_collection_lookup_int(&curptr, prop, intkey, &nextptr);
3003
if(token != fixedbuf)
3021
token= rna_path_token(&path, fixedbuf, sizeof(fixedbuf), 1);
3663
/* resolve the lookup with [] brackets */
3664
token = rna_path_token(&path, fixedbuf, sizeof(fixedbuf), 1);
3023
3669
/* check for "" to see if it is a string */
3024
if(rna_token_strip_quotes(token)) {
3025
*index= RNA_property_array_item_index(prop, *(token+1));
3670
if (rna_token_strip_quotes(token)) {
3671
RNA_property_collection_lookup_string(&curptr, prop, token+1, &nextptr);
3028
3674
/* otherwise do int lookup */
3029
*index= atoi(token);
3033
token= rna_path_token(&path, fixedbuf, sizeof(fixedbuf), 0);
3034
*index= RNA_property_array_item_index(prop, *token);
3037
if(token != fixedbuf)
3675
intkey = atoi(token);
3676
if (intkey == 0 && (token[0] != '0' || token[1] != '\0')) {
3677
return 0; /* we can be sure the fixedbuf was used in this case */
3679
RNA_property_collection_lookup_int(&curptr, prop, intkey, &nextptr);
3682
if (token != fixedbuf) {
3689
/* ensure we quit on invalid values */
3690
nextptr.data = NULL;
3692
if (RNA_property_collection_type_get(&curptr, prop, &c_ptr)) {
3699
prop = NULL; /* now we have a PointerRNA, the prop is our parent so forget it */
3700
if (index) *index = -1;
3714
int index_arr[RNA_MAX_ARRAY_DIMENSION] = {0};
3715
int len[RNA_MAX_ARRAY_DIMENSION];
3716
const int dim = RNA_property_array_dimension(&curptr, prop, len);
3719
for (i = 0; i<dim; i++) {
3722
/* multi index resolve */
3724
token = rna_path_token(&path, fixedbuf, sizeof(fixedbuf), 1);
3726
if (token == NULL) {
3727
/* invalid syntax blah[] */
3730
/* check for "" to see if it is a string */
3731
else if (rna_token_strip_quotes(token)) {
3732
temp_index = RNA_property_array_item_index(prop, *(token+1));
3735
/* otherwise do int lookup */
3736
temp_index = atoi(token);
3738
if (temp_index == 0 && (token[0] != '0' || token[1] != '\0')) {
3739
if (token != fixedbuf) {
3747
else if (dim == 1) {
3748
/* location.x || scale.X, single dimension arrays only */
3749
token = rna_path_token(&path, fixedbuf, sizeof(fixedbuf), 0);
3750
if (token == NULL) {
3751
/* invalid syntax blah.. */
3754
temp_index = RNA_property_array_item_index(prop, *token);
3757
if (token != fixedbuf) {
3762
if (temp_index < 0 || temp_index >= len[i])
3765
index_arr[i] = temp_index;
3766
/* end multi index resolve */
3769
/* arrays always contain numbers so further values are not valid */
3777
for (i = dim-1; i >= 0; i--) {
3778
flat_index += index_arr[i] * totdim;
3782
*index = flat_index;
3050
char *RNA_path_append(const char *path, PointerRNA *ptr, PropertyRNA *prop, int intkey, const char *strkey)
3795
char *RNA_path_append(const char *path, PointerRNA *UNUSED(ptr), PropertyRNA *prop, int intkey, const char *strkey)
3052
3797
DynStr *dynstr;
3054
3799
char appendstr[128], *result;
3056
dynstr= BLI_dynstr_new();
3801
dynstr = BLI_dynstr_new();
3058
3803
/* add .identifier */
3060
3805
BLI_dynstr_append(dynstr, (char*)path);
3062
3807
BLI_dynstr_append(dynstr, ".");
3065
BLI_dynstr_append(dynstr, (char*)RNA_property_identifier(prop));
3810
BLI_dynstr_append(dynstr, RNA_property_identifier(prop));
3067
if(RNA_property_type(prop) == PROP_COLLECTION) {
3812
if (RNA_property_type(prop) == PROP_COLLECTION) {
3068
3813
/* add ["strkey"] or [intkey] */
3069
3814
BLI_dynstr_append(dynstr, "[");
3072
3817
BLI_dynstr_append(dynstr, "\"");
3073
for(s=strkey; *s; s++) {
3818
for (s = strkey; *s; s++) {
3820
appendstr[0] = '\\';
3083
3828
BLI_dynstr_append(dynstr, appendstr);
3085
3830
BLI_dynstr_append(dynstr, "\"");
3088
sprintf(appendstr, "%d", intkey);
3833
BLI_snprintf(appendstr, sizeof(appendstr), "%d", intkey);
3089
3834
BLI_dynstr_append(dynstr, appendstr);
3092
3837
BLI_dynstr_append(dynstr, "]");
3095
result= BLI_dynstr_get_cstring(dynstr);
3840
result = BLI_dynstr_get_cstring(dynstr);
3096
3841
BLI_dynstr_free(dynstr);
3105
3850
char *result, *token;
3114
3859
/* parse token by token until the end, then we back up to the previous
3115
3860
* position and strip of the next token to get the path one step back */
3117
token= rna_path_token(¤t, fixedbuf, sizeof(fixedbuf), 0);
3862
token = rna_path_token(¤t, fixedbuf, sizeof(fixedbuf), 0);
3121
if(token != fixedbuf)
3866
if (token != fixedbuf)
3122
3867
MEM_freeN(token);
3124
3869
/* in case of collection we also need to strip off [] */
3125
token= rna_path_token(¤t, fixedbuf, sizeof(fixedbuf), 1);
3126
if(token && token != fixedbuf)
3870
token = rna_path_token(¤t, fixedbuf, sizeof(fixedbuf), 1);
3871
if (token && token != fixedbuf)
3127
3872
MEM_freeN(token);
3138
3883
/* copy and strip off last token */
3140
result= BLI_strdup(path);
3884
i = previous - path;
3885
result = BLI_strdup(path);
3142
if(i > 0 && result[i-1] == '.') i--;
3887
if (i > 0 && result[i-1] == '.') i--;
3893
/* generic path search func
3894
* if its needed this could also reference the IDProperty direct */
3895
typedef struct IDP_Chain {
3896
struct IDP_Chain *up; /* parent member, reverse and set to child for path conversion. */
3903
static char *rna_idp_path_create(IDP_Chain *child_link)
3905
DynStr *dynstr = BLI_dynstr_new();
3910
IDP_Chain *link = child_link;
3912
/* reverse the list */
3913
IDP_Chain *link_prev;
3916
IDP_Chain *link_next = link->up;
3917
link->up = link_prev;
3923
for (link = link_prev; link; link = link->up) {
3925
if (link->index >= 0) {
3926
BLI_dynstr_appendf(dynstr, first ? "%s[%d]" : ".%s[%d]", link->name, link->index);
3929
BLI_dynstr_appendf(dynstr, first ? "%s" : ".%s", link->name);
3935
path = BLI_dynstr_get_cstring(dynstr);
3936
BLI_dynstr_free(dynstr);
3946
static char *rna_idp_path(PointerRNA *ptr, IDProperty *haystack, IDProperty *needle, IDP_Chain *parent_link)
3954
BLI_assert(haystack->type == IDP_GROUP);
3956
link.up = parent_link;
3960
for (i = 0, iter = haystack->data.group.first; iter; iter = iter->next, i++) {
3961
if (needle == iter) { /* found! */
3962
link.name = iter->name;
3963
path = rna_idp_path_create(&link);
3967
if (iter->type == IDP_GROUP) {
3968
/* ensure this is RNA */
3969
PointerRNA child_ptr = RNA_pointer_get(ptr, iter->name);
3970
if (child_ptr.type) {
3971
link.name = iter->name;
3972
if ((path = rna_idp_path(&child_ptr, iter, needle, &link))) {
3977
else if (iter->type == IDP_IDPARRAY) {
3978
PropertyRNA *prop = RNA_struct_find_property(ptr, iter->name);
3979
if (prop && prop->type == PROP_COLLECTION) {
3980
IDProperty *array = IDP_IDPArray(iter);
3981
if (needle >= array && needle < (iter->len + array)) { /* found! */
3982
link.name = iter->name;
3983
link.index = (int)(needle - array);
3984
path = rna_idp_path_create(&link);
3989
link.name = iter->name;
3990
for (i = 0; i < iter->len; i++, array++) {
3991
PointerRNA child_ptr;
3992
if (RNA_property_collection_lookup_int(ptr, prop, i, &child_ptr)) {
3994
if ((path = rna_idp_path(&child_ptr, array, needle, &link))) {
4010
static char *rna_path_from_ID_to_idpgroup(PointerRNA *ptr)
4013
IDProperty *haystack;
4016
BLI_assert(ptr->id.data != NULL);
4018
/* TODO, Support Bones/PoseBones. no pointers stored to the bones from here, only the ID. See example in [#25746]
4019
* Unless this is added only way to find this is to also search all bones and pose bones
4020
* of an armature or object */
4021
RNA_id_pointer_create(ptr->id.data, &id_ptr);
4023
haystack = RNA_struct_idprops(&id_ptr, FALSE);
4024
if (haystack) { /* can fail when called on bones */
4026
return rna_idp_path(&id_ptr, haystack, needle, NULL);
3148
4033
char *RNA_path_from_ID_to_struct(PointerRNA *ptr)
4035
char *ptrpath = NULL;
3152
if(!ptr->id.data || !ptr->data)
4037
if (!ptr->id.data || !ptr->data)
3155
if(!RNA_struct_is_ID(ptr->type)) {
3156
if(ptr->type->path) {
4040
if (!RNA_struct_is_ID(ptr->type)) {
4041
if (ptr->type->path) {
3157
4042
/* if type has a path to some ID, use it */
3158
ptrpath= ptr->type->path(ptr);
4043
ptrpath = ptr->type->path(ptr);
3160
else if(ptr->type->nested && RNA_struct_is_ID(ptr->type->nested)) {
4045
else if (ptr->type->nested && RNA_struct_is_ID(ptr->type->nested)) {
3161
4046
PointerRNA parentptr;
3162
4047
PropertyRNA *userprop;
3164
/* find the property in the struct we're nested in that references this struct, and
4049
/* find the property in the struct we're nested in that references this struct, and
3165
4050
* use its identifier as the first part of the path used...
3167
4052
RNA_id_pointer_create(ptr->id.data, &parentptr);
3168
userprop= RNA_struct_find_nested(&parentptr, ptr->type);
4053
userprop = RNA_struct_find_nested(&parentptr, ptr->type);
3171
ptrpath= BLI_strdup(RNA_property_identifier(userprop));
4056
ptrpath = BLI_strdup(RNA_property_identifier(userprop));
3173
return NULL; // can't do anything about this case yet...
4058
return NULL; /* can't do anything about this case yet... */
4060
else if (RNA_struct_is_a(ptr->type, &RNA_PropertyGroup)) {
4061
/* special case, easier to deal with here then in ptr->type->path() */
4062
return rna_path_from_ID_to_idpgroup(ptr);
3212
4101
int RNA_boolean_get(PointerRNA *ptr, const char *name)
3214
PropertyRNA *prop= RNA_struct_find_property(ptr, name);
4103
PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3217
4106
return RNA_property_boolean_get(ptr, prop);
3220
printf("RNA_boolean_get: %s.%s not found.\n", ptr->type->identifier, name);
4109
printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3225
4114
void RNA_boolean_set(PointerRNA *ptr, const char *name, int value)
3227
PropertyRNA *prop= RNA_struct_find_property(ptr, name);
4116
PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3230
4119
RNA_property_boolean_set(ptr, prop, value);
3232
printf("RNA_boolean_set: %s.%s not found.\n", ptr->type->identifier, name);
4121
printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3235
4124
void RNA_boolean_get_array(PointerRNA *ptr, const char *name, int *values)
3237
PropertyRNA *prop= RNA_struct_find_property(ptr, name);
4126
PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3240
4129
RNA_property_boolean_get_array(ptr, prop, values);
3242
printf("RNA_boolean_get_array: %s.%s not found.\n", ptr->type->identifier, name);
4131
printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3245
4134
void RNA_boolean_set_array(PointerRNA *ptr, const char *name, const int *values)
3247
PropertyRNA *prop= RNA_struct_find_property(ptr, name);
4136
PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3250
4139
RNA_property_boolean_set_array(ptr, prop, values);
3252
printf("RNA_boolean_set_array: %s.%s not found.\n", ptr->type->identifier, name);
4141
printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3255
4144
int RNA_int_get(PointerRNA *ptr, const char *name)
3257
PropertyRNA *prop= RNA_struct_find_property(ptr, name);
4146
PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3260
4149
return RNA_property_int_get(ptr, prop);
3263
printf("RNA_int_get: %s.%s not found.\n", ptr->type->identifier, name);
4152
printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3268
4157
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
3270
PropertyRNA *prop= RNA_struct_find_property(ptr, name);
4159
PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3273
4162
RNA_property_int_set(ptr, prop, value);
3275
printf("RNA_int_set: %s.%s not found.\n", ptr->type->identifier, name);
4164
printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3278
4167
void RNA_int_get_array(PointerRNA *ptr, const char *name, int *values)
3280
PropertyRNA *prop= RNA_struct_find_property(ptr, name);
4169
PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3283
4172
RNA_property_int_get_array(ptr, prop, values);
3285
printf("RNA_int_get_array: %s.%s not found.\n", ptr->type->identifier, name);
4174
printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3288
4177
void RNA_int_set_array(PointerRNA *ptr, const char *name, const int *values)
3290
PropertyRNA *prop= RNA_struct_find_property(ptr, name);
4179
PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3293
4182
RNA_property_int_set_array(ptr, prop, values);
3295
printf("RNA_int_set_array: %s.%s not found.\n", ptr->type->identifier, name);
4184
printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3298
4187
float RNA_float_get(PointerRNA *ptr, const char *name)
3300
PropertyRNA *prop= RNA_struct_find_property(ptr, name);
4189
PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3303
4192
return RNA_property_float_get(ptr, prop);
3306
printf("RNA_float_get: %s.%s not found.\n", ptr->type->identifier, name);
4195
printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3311
4200
void RNA_float_set(PointerRNA *ptr, const char *name, float value)
3313
PropertyRNA *prop= RNA_struct_find_property(ptr, name);
4202
PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3316
4205
RNA_property_float_set(ptr, prop, value);
3318
printf("RNA_float_set: %s.%s not found.\n", ptr->type->identifier, name);
4207
printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3321
4210
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
3323
PropertyRNA *prop= RNA_struct_find_property(ptr, name);
4212
PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3326
4215
RNA_property_float_get_array(ptr, prop, values);
3328
printf("RNA_float_get_array: %s.%s not found.\n", ptr->type->identifier, name);
4217
printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3331
4220
void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
3333
PropertyRNA *prop= RNA_struct_find_property(ptr, name);
4222
PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3336
4225
RNA_property_float_set_array(ptr, prop, values);
3338
printf("RNA_float_set_array: %s.%s not found.\n", ptr->type->identifier, name);
4227
printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3341
4230
int RNA_enum_get(PointerRNA *ptr, const char *name)
3343
PropertyRNA *prop= RNA_struct_find_property(ptr, name);
4232
PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3346
4235
return RNA_property_enum_get(ptr, prop);
3349
printf("RNA_enum_get: %s.%s not found.\n", ptr->type->identifier, name);
4238
printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3354
4243
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
3356
PropertyRNA *prop= RNA_struct_find_property(ptr, name);
4245
PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3359
4248
RNA_property_enum_set(ptr, prop, value);
3361
printf("RNA_enum_set: %s.%s not found.\n", ptr->type->identifier, name);
4250
printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3364
4253
void RNA_enum_set_identifier(PointerRNA *ptr, const char *name, const char *id)
3366
PropertyRNA *prop= RNA_struct_find_property(ptr, name);
4255
PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3370
if(RNA_property_enum_value(NULL, ptr, prop, id, &value))
4259
if (RNA_property_enum_value(NULL, ptr, prop, id, &value))
3371
4260
RNA_property_enum_set(ptr, prop, value);
3373
printf("RNA_enum_set_identifier: %s.%s has no enum id '%s'.\n", ptr->type->identifier, name, id);
3375
printf("RNA_enum_set_identifier: %s.%s not found.\n", ptr->type->identifier, name);
4262
printf("%s: %s.%s has no enum id '%s'.\n", __func__, ptr->type->identifier, name, id);
4265
printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3378
4269
int RNA_enum_is_equal(bContext *C, PointerRNA *ptr, const char *name, const char *enumname)
3380
PropertyRNA *prop= RNA_struct_find_property(ptr, name);
4271
PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3381
4272
EnumPropertyItem *item;
3385
4276
RNA_property_enum_items(C, ptr, prop, &item, NULL, &free);
3387
for(; item->identifier; item++)
3388
if(strcmp(item->identifier, enumname) == 0)
4278
for (; item->identifier; item++)
4279
if (strcmp(item->identifier, enumname) == 0)
3389
4280
return (item->value == RNA_property_enum_get(ptr, prop));
3392
4283
MEM_freeN(item);
3394
printf("RNA_enum_is_equal: %s.%s item %s not found.\n", ptr->type->identifier, name, enumname);
4285
printf("%s: %s.%s item %s not found.\n", __func__, ptr->type->identifier, name, enumname);
3398
printf("RNA_enum_is_equal: %s.%s not found.\n", ptr->type->identifier, name);
4289
printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3403
4294
int RNA_enum_value_from_id(EnumPropertyItem *item, const char *identifier, int *value)
3405
for( ; item->identifier; item++) {
3406
if(strcmp(item->identifier, identifier)==0) {
3407
*value= item->value;
4296
for ( ; item->identifier; item++) {
4297
if (strcmp(item->identifier, identifier) == 0) {
4298
*value = item->value;
3415
4306
int RNA_enum_id_from_value(EnumPropertyItem *item, int value, const char **identifier)
3417
for( ; item->identifier; item++) {
3418
if(item->value==value) {
3419
*identifier= item->identifier;
4308
for ( ; item->identifier; item++) {
4309
if (item->value == value) {
4310
*identifier = item->identifier;
4318
int RNA_enum_icon_from_value(EnumPropertyItem *item, int value, int *icon)
4320
for ( ; item->identifier; item++) {
4321
if (item->value == value) {
3427
4330
void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
3429
PropertyRNA *prop= RNA_struct_find_property(ptr, name);
4332
PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3432
4335
RNA_property_string_get(ptr, prop, value);
3434
printf("RNA_string_get: %s.%s not found.\n", ptr->type->identifier, name);
4338
printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3437
4343
char *RNA_string_get_alloc(PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen)
3439
PropertyRNA *prop= RNA_struct_find_property(ptr, name);
4345
PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3442
return RNA_property_string_get_alloc(ptr, prop, fixedbuf, fixedlen);
4348
return RNA_property_string_get_alloc(ptr, prop, fixedbuf, fixedlen, NULL); /* TODO, pass length */
3445
printf("RNA_string_get_alloc: %s.%s not found.\n", ptr->type->identifier, name);
4351
printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3450
4356
int RNA_string_length(PointerRNA *ptr, const char *name)
3452
PropertyRNA *prop= RNA_struct_find_property(ptr, name);
4358
PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3455
4361
return RNA_property_string_length(ptr, prop);
3458
printf("RNA_string_length: %s.%s not found.\n", ptr->type->identifier, name);
4364
printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3463
4369
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
3465
PropertyRNA *prop= RNA_struct_find_property(ptr, name);
4371
PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3468
4374
RNA_property_string_set(ptr, prop, value);
3470
printf("RNA_string_set: %s.%s not found.\n", ptr->type->identifier, name);
4376
printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3473
4379
PointerRNA RNA_pointer_get(PointerRNA *ptr, const char *name)
3475
PropertyRNA *prop= RNA_struct_find_property(ptr, name);
4381
PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3478
4384
return RNA_property_pointer_get(ptr, prop);
3483
printf("RNA_pointer_get: %s.%s not found.\n", ptr->type->identifier, name);
3485
memset(&result, 0, sizeof(result));
4387
printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
4389
return PointerRNA_NULL;
3490
4393
void RNA_pointer_set(PointerRNA *ptr, const char *name, PointerRNA ptr_value)
3492
PropertyRNA *prop= RNA_struct_find_property(ptr, name);
4395
PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3495
4398
RNA_property_pointer_set(ptr, prop, ptr_value);
3498
printf("RNA_pointer_set: %s.%s not found.\n", ptr->type->identifier, name);
4401
printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3502
4405
void RNA_pointer_add(PointerRNA *ptr, const char *name)
3504
PropertyRNA *prop= RNA_struct_find_property(ptr, name);
4407
PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3507
4410
RNA_property_pointer_add(ptr, prop);
3509
printf("RNA_pointer_set: %s.%s not found.\n", ptr->type->identifier, name);
4412
printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3512
4415
void RNA_collection_begin(PointerRNA *ptr, const char *name, CollectionPropertyIterator *iter)
3514
PropertyRNA *prop= RNA_struct_find_property(ptr, name);
4417
PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3517
4420
RNA_property_collection_begin(ptr, prop, iter);
3519
printf("RNA_collection_begin: %s.%s not found.\n", ptr->type->identifier, name);
4422
printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3522
4425
void RNA_collection_add(PointerRNA *ptr, const char *name, PointerRNA *r_value)
3524
PropertyRNA *prop= RNA_struct_find_property(ptr, name);
4427
PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3527
4430
RNA_property_collection_add(ptr, prop, r_value);
3529
printf("RNA_collection_add: %s.%s not found.\n", ptr->type->identifier, name);
4432
printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3532
4435
void RNA_collection_clear(PointerRNA *ptr, const char *name)
3534
PropertyRNA *prop= RNA_struct_find_property(ptr, name);
4437
PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3537
4440
RNA_property_collection_clear(ptr, prop);
3539
printf("RNA_collection_clear: %s.%s not found.\n", ptr->type->identifier, name);
4442
printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3542
4445
int RNA_collection_length(PointerRNA *ptr, const char *name)
3544
PropertyRNA *prop= RNA_struct_find_property(ptr, name);
4447
PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3547
4450
return RNA_property_collection_length(ptr, prop);
3550
printf("RNA_collection_length: %s.%s not found.\n", ptr->type->identifier, name);
4453
printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3555
int RNA_property_is_set(PointerRNA *ptr, const char *name)
3557
PropertyRNA *prop= RNA_struct_find_property(ptr, name);
3560
if(prop->flag & PROP_IDPROPERTY)
3561
return (rna_idproperty_find(ptr, name) != NULL);
3566
// printf("RNA_property_is_set: %s.%s not found.\n", ptr->type->identifier, name);
4458
int RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
4460
if (prop->flag & PROP_IDPROPERTY) {
4461
IDProperty *idprop = rna_idproperty_find(ptr, prop->identifier);
4462
return ((idprop != NULL) && !(idprop->flag & IDP_FLAG_GHOST));
4469
int RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
4471
PropertyRNA *prop = RNA_struct_find_property(ptr, identifier);
4474
return RNA_property_is_set(ptr, prop);
4477
/* python raises an error */
4478
/* printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name); */
3571
4483
int RNA_property_is_idprop(PropertyRNA *prop)
3573
return (prop->magic!=RNA_MAGIC);
4485
return (prop->magic != RNA_MAGIC);
3576
4488
/* string representation of a property, python
3577
* compatible but can be used for display too*/
3578
char *RNA_pointer_as_string(PointerRNA *ptr)
4489
* compatible but can be used for display too,
4490
* context may be NULL */
4491
char *RNA_pointer_as_string(bContext *C, PointerRNA *ptr)
3580
DynStr *dynstr= BLI_dynstr_new();
4493
DynStr *dynstr = BLI_dynstr_new();
3583
4496
const char *propname;
3588
4501
RNA_STRUCT_BEGIN(ptr, prop) {
3589
4502
propname = RNA_property_identifier(prop);
3591
if(strcmp(propname, "rna_type")==0)
4504
if (strcmp(propname, "rna_type") == 0)
4507
if (first_time == 0)
3595
4508
BLI_dynstr_append(dynstr, ", ");
3598
cstring = RNA_property_as_string(NULL, ptr, prop);
4511
cstring = RNA_property_as_string(C, ptr, prop);
3599
4512
BLI_dynstr_appendf(dynstr, "\"%s\":%s", propname, cstring);
3600
4513
MEM_freeN(cstring);
3602
4515
RNA_STRUCT_END;
3604
BLI_dynstr_append(dynstr, "}");
3607
cstring = BLI_dynstr_get_cstring(dynstr);
3608
BLI_dynstr_free(dynstr);
4517
BLI_dynstr_append(dynstr, "}");
4520
cstring = BLI_dynstr_get_cstring(dynstr);
4521
BLI_dynstr_free(dynstr);
4526
/* context and ptr_default can be NULL */
4527
char *RNA_pointer_as_string_keywords_ex(bContext *C, PointerRNA *ptr, PointerRNA *ptr_default,
4528
const short as_function, const short all_args,
4529
PropertyRNA *iterprop)
4531
const char *arg_name = NULL;
4535
DynStr *dynstr = BLI_dynstr_new();
4536
char *cstring, *buf;
4537
int first_iter = TRUE, ok = TRUE;
4540
/* only to get the orginal props for comparisons */
4541
PropertyRNA *prop_default;
4544
RNA_PROP_BEGIN(ptr, propptr, iterprop) {
4545
prop = propptr.data;
4547
flag = RNA_property_flag(prop);
4549
if (as_function && (flag & PROP_OUTPUT)) {
4553
arg_name = RNA_property_identifier(prop);
4555
if (strcmp(arg_name, "rna_type") == 0) {
4559
if (as_function && (flag & PROP_REQUIRED)) {
4560
/* required args don't have useful defaults */
4561
BLI_dynstr_appendf(dynstr, first_iter ? "%s":", %s", arg_name);
4565
if (as_function && RNA_property_type(prop) == PROP_POINTER) {
4566
/* don't expand pointers for functions */
4567
if (flag & PROP_NEVER_NULL) {
4568
/* we cant really do the right thing here. arg=arg?, hrmf! */
4569
buf = BLI_strdup(arg_name);
4572
buf = BLI_strdup("None");
4576
buf = RNA_property_as_string(C, ptr, prop);
4581
if (all_args == FALSE && ptr_default) {
4582
/* not verbose, so only add in attributes that use non-default values
4583
* slow but good for tooltips */
4584
prop_default = RNA_struct_find_property(ptr_default, arg_name);
4587
buf_default = RNA_property_as_string(C, ptr_default, prop_default);
4589
if (strcmp(buf, buf_default) == 0)
4590
ok = FALSE; /* values match, don't bother printing */
4592
MEM_freeN(buf_default);
4596
BLI_dynstr_appendf(dynstr, first_iter ? "%s=%s":", %s=%s", arg_name, buf);
4605
cstring = BLI_dynstr_get_cstring(dynstr);
4606
BLI_dynstr_free(dynstr);
4610
char *RNA_pointer_as_string_keywords(bContext *C, PointerRNA *ptr, PointerRNA *ptr_default,
4611
const short as_function, const short all_args)
4613
PropertyRNA *iterprop;
4615
iterprop = RNA_struct_iterator_property(ptr->type);
4617
return RNA_pointer_as_string_keywords_ex(C, ptr, ptr_default, as_function, all_args,
4621
char *RNA_function_as_string_keywords(bContext *C, FunctionRNA *func, PointerRNA *ptr_default,
4622
const short as_function, const short all_args)
4625
PropertyRNA *iterprop;
4627
RNA_pointer_create(NULL, &RNA_Function, func, &funcptr);
4629
iterprop = RNA_struct_find_property(&funcptr, "parameters");
4631
RNA_struct_iterator_property(funcptr.type);
4633
return RNA_pointer_as_string_keywords_ex(C, &funcptr, ptr_default, as_function, all_args,
3612
4637
char *RNA_property_as_string(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
3615
4640
int len = RNA_property_array_length(ptr, prop);
3618
DynStr *dynstr= BLI_dynstr_new();
4643
DynStr *dynstr = BLI_dynstr_new();
3622
4647
/* see if we can coorce into a python type - PropertyType */
3623
4648
switch (type) {
3624
4649
case PROP_BOOLEAN:
3626
4651
BLI_dynstr_append(dynstr, RNA_property_boolean_get(ptr, prop) ? "True" : "False");
3629
4654
BLI_dynstr_append(dynstr, "(");
3630
for(i=0; i<len; i++) {
3631
BLI_dynstr_appendf(dynstr, i?", %s":"%s", RNA_property_boolean_get_index(ptr, prop, i) ? "True" : "False");
4655
for (i = 0; i<len; i++) {
4656
BLI_dynstr_appendf(dynstr, i ? ", %s" : "%s",
4657
RNA_property_boolean_get_index(ptr, prop, i) ? "True" : "False");
3634
4660
BLI_dynstr_append(dynstr, ","); /* otherwise python wont see it as a tuple */
3635
4661
BLI_dynstr_append(dynstr, ")");
3640
4666
BLI_dynstr_appendf(dynstr, "%d", RNA_property_int_get(ptr, prop));
3643
4669
BLI_dynstr_append(dynstr, "(");
3644
for(i=0; i<len; i++) {
4670
for (i = 0; i<len; i++) {
3645
4671
BLI_dynstr_appendf(dynstr, i?", %d":"%d", RNA_property_int_get_index(ptr, prop, i));
3648
4674
BLI_dynstr_append(dynstr, ","); /* otherwise python wont see it as a tuple */
3649
4675
BLI_dynstr_append(dynstr, ")");
3652
4678
case PROP_FLOAT:
3654
4680
BLI_dynstr_appendf(dynstr, "%g", RNA_property_float_get(ptr, prop));
3657
4683
BLI_dynstr_append(dynstr, "(");
3658
for(i=0; i<len; i++) {
4684
for (i = 0; i<len; i++) {
3659
4685
BLI_dynstr_appendf(dynstr, i?", %g":"%g", RNA_property_float_get_index(ptr, prop, i));
3662
4688
BLI_dynstr_append(dynstr, ","); /* otherwise python wont see it as a tuple */
3663
4689
BLI_dynstr_append(dynstr, ")");
3666
4692
case PROP_STRING:
3668
/* string arrays dont exist */
3670
buf = RNA_property_string_get_alloc(ptr, prop, NULL, -1);
3671
BLI_dynstr_appendf(dynstr, "\"%s\"", buf);
4698
length = RNA_property_string_length(ptr, prop);
4699
buf = MEM_mallocN(sizeof(char)*(length+1), "RNA_property_as_string");
4700
buf_esc = MEM_mallocN(sizeof(char)*(length*2+1), "RNA_property_as_string esc");
4701
RNA_property_string_get(ptr, prop, buf);
4702
BLI_strescape(buf_esc, buf, length*2+1);
3672
4703
MEM_freeN(buf);
4704
BLI_dynstr_appendf(dynstr, "\"%s\"", buf_esc);
3675
4708
case PROP_ENUM:
3677
/* string arrays dont exist */
4710
/* string arrays don't exist */
3678
4711
const char *identifier;
3679
4712
int val = RNA_property_enum_get(ptr, prop);
3681
if(RNA_property_enum_identifier(C, ptr, prop, val, &identifier)) {
4714
if (RNA_property_flag(prop) & PROP_ENUM_FLAG) {
4715
/* represent as a python set */
4717
EnumPropertyItem *item = NULL;
4720
BLI_dynstr_append(dynstr, "{");
4722
RNA_property_enum_items(C, ptr, prop, &item, NULL, &free);
4724
short is_first = TRUE;
4725
for (; item->identifier; item++) {
4726
if (item->identifier[0] && item->value & val) {
4727
BLI_dynstr_appendf(dynstr, is_first ? "'%s'" : ", '%s'", item->identifier);
4737
BLI_dynstr_append(dynstr, "}");
4740
/* annoying exception, don't confuse with dictionary syntax above: {} */
4741
BLI_dynstr_append(dynstr, "set()");
4744
else if (RNA_property_enum_identifier(C, ptr, prop, val, &identifier)) {
3682
4745
BLI_dynstr_appendf(dynstr, "'%s'", identifier);
3685
BLI_dynstr_appendf(dynstr, "'<UNKNOWN ENUM>'", identifier);
4748
BLI_dynstr_append(dynstr, "'<UNKNOWN ENUM>'");
3689
4752
case PROP_POINTER:
3691
BLI_dynstr_append(dynstr, "'<POINTER>'"); /* TODO */
4754
PointerRNA tptr = RNA_property_pointer_get(ptr, prop);
4755
cstring = RNA_pointer_as_string(C, &tptr);
4756
BLI_dynstr_append(dynstr, cstring);
3694
4760
case PROP_COLLECTION:
3781
ParameterList *RNA_parameter_list_create(ParameterList *parms, PointerRNA *ptr, FunctionRNA *func)
4833
ParameterList *RNA_parameter_list_create(ParameterList *parms, PointerRNA *UNUSED(ptr), FunctionRNA *func)
3783
4835
PropertyRNA *parm;
3785
int alloc_size= 0, size;
3787
parms->arg_count= 0;
3788
parms->ret_count= 0;
4837
int alloc_size = 0, size;
4839
parms->arg_count = 0;
4840
parms->ret_count = 0;
3790
4842
/* allocate data */
3791
for(parm= func->cont.properties.first; parm; parm= parm->next) {
4843
for (parm = func->cont.properties.first; parm; parm = parm->next) {
3792
4844
alloc_size += rna_parameter_size_alloc(parm);
3794
if(parm->flag & PROP_OUTPUT)
4846
if (parm->flag & PROP_OUTPUT)
3800
parms->data= MEM_callocN(alloc_size, "RNA_parameter_list_create");
3802
parms->alloc_size= alloc_size;
4852
parms->data = MEM_callocN(alloc_size, "RNA_parameter_list_create");
4854
parms->alloc_size = alloc_size;
3804
4856
/* set default values */
3807
for(parm= func->cont.properties.first; parm; parm= parm->next) {
3808
size= rna_parameter_size(parm);
3810
if(!(parm->flag & PROP_REQUIRED)) {
3811
switch(parm->type) {
4859
for (parm = func->cont.properties.first; parm; parm = parm->next) {
4860
size = rna_parameter_size(parm);
4862
/* set length to 0, these need to be set later, see bpy_array.c's py_to_array */
4863
if (parm->flag & PROP_DYNAMIC) {
4864
ParameterDynAlloc *data_alloc = data;
4865
data_alloc->array_tot = 0;
4866
data_alloc->array = NULL;
4869
if (!(parm->flag & PROP_REQUIRED) && !(parm->flag & PROP_DYNAMIC)) {
4870
switch (parm->type) {
3812
4871
case PROP_BOOLEAN:
3813
if(parm->arraydimension) memcpy(data, &((BooleanPropertyRNA*)parm)->defaultarray, size);
3814
else memcpy(data, &((BooleanPropertyRNA*)parm)->defaultvalue, size);
4872
if (parm->arraydimension) memcpy(data, ((BoolPropertyRNA*)parm)->defaultarray, size);
4873
else memcpy(data, &((BoolPropertyRNA*)parm)->defaultvalue, size);
3817
if(parm->arraydimension) memcpy(data, &((IntPropertyRNA*)parm)->defaultarray, size);
4876
if (parm->arraydimension) memcpy(data, ((IntPropertyRNA*)parm)->defaultarray, size);
3818
4877
else memcpy(data, &((IntPropertyRNA*)parm)->defaultvalue, size);
3820
4879
case PROP_FLOAT:
3821
if(parm->arraydimension) memcpy(data, &((FloatPropertyRNA*)parm)->defaultarray, size);
4880
if (parm->arraydimension) memcpy(data, ((FloatPropertyRNA*)parm)->defaultarray, size);
3822
4881
else memcpy(data, &((FloatPropertyRNA*)parm)->defaultvalue, size);
3824
4883
case PROP_ENUM:
3825
4884
memcpy(data, &((EnumPropertyRNA*)parm)->defaultvalue, size);
3827
4886
case PROP_STRING: {
3828
const char *defvalue= ((StringPropertyRNA*)parm)->defaultvalue;
3829
if(defvalue && defvalue[0])
4887
const char *defvalue = ((StringPropertyRNA*)parm)->defaultvalue;
4888
if (defvalue && defvalue[0]) {
4889
/* causes bug [#29988], possibly this is only correct for thick wrapped
4890
* need to look further into it - campbell */
4892
BLI_strncpy(data, defvalue, size);
3830
4894
memcpy(data, &defvalue, size);
3833
4899
case PROP_POINTER:
3947
5004
PropertyRNA *parm;
3949
parm= parms->func->cont.properties.first;
3950
for(; parm; parm= parm->next)
3951
if(strcmp(RNA_property_identifier(parm), identifier)==0)
5006
parm = parms->func->cont.properties.first;
5007
for (; parm; parm = parm->next)
5008
if (strcmp(RNA_property_identifier(parm), identifier) == 0)
3955
5012
RNA_parameter_get(parms, parm, value);
3958
void RNA_parameter_set(ParameterList *parms, PropertyRNA *parm, void *value)
5015
void RNA_parameter_set(ParameterList *parms, PropertyRNA *parm, const void *value)
3960
5017
ParameterIterator iter;
3962
5019
RNA_parameter_list_begin(parms, &iter);
3964
for(; iter.valid; RNA_parameter_list_next(&iter))
5021
for (; iter.valid; RNA_parameter_list_next(&iter))
5022
if (iter.parm == parm)
3969
5026
memcpy(iter.data, value, iter.size);
3971
5028
RNA_parameter_list_end(&iter);
3974
void RNA_parameter_set_lookup(ParameterList *parms, const char *identifier, void *value)
5031
void RNA_parameter_set_lookup(ParameterList *parms, const char *identifier, const void *value)
3976
5033
PropertyRNA *parm;
3978
parm= parms->func->cont.properties.first;
3979
for(; parm; parm= parm->next)
3980
if(strcmp(RNA_property_identifier(parm), identifier)==0)
5035
parm = parms->func->cont.properties.first;
5036
for (; parm; parm = parm->next)
5037
if (strcmp(RNA_property_identifier(parm), identifier) == 0)
3984
5041
RNA_parameter_set(parms, parm, value);
3987
5044
int RNA_parameter_length_get(ParameterList *parms, PropertyRNA *parm)
3989
5046
ParameterIterator iter;
3992
5049
RNA_parameter_list_begin(parms, &iter);
3994
for(; iter.valid; RNA_parameter_list_next(&iter))
5051
for (; iter.valid; RNA_parameter_list_next(&iter))
5052
if (iter.parm == parm)
3999
len= RNA_parameter_length_get_data(parms, parm, iter.data);
5056
len = RNA_parameter_length_get_data(parms, parm, iter.data);
4001
5058
RNA_parameter_list_end(&iter);
4043
int RNA_function_call_lookup(bContext *C, ReportList *reports, PointerRNA *ptr, const char *identifier, ParameterList *parms)
5100
int RNA_function_call_lookup(bContext *C, ReportList *reports, PointerRNA *ptr, const char *identifier,
5101
ParameterList *parms)
4045
5103
FunctionRNA *func;
4047
func= RNA_struct_find_function(ptr, identifier);
5105
func = RNA_struct_find_function(ptr, identifier);
4050
5108
return RNA_function_call(C, reports, ptr, func, parms);
4055
int RNA_function_call_direct(bContext *C, ReportList *reports, PointerRNA *ptr, FunctionRNA *func, const char *format, ...)
5113
int RNA_function_call_direct(bContext *C, ReportList *reports, PointerRNA *ptr, FunctionRNA *func,
5114
const char *format, ...)
4060
5119
va_start(args, format);
4062
ret= RNA_function_call_direct_va(C, reports, ptr, func, format, args);
5121
ret = RNA_function_call_direct_va(C, reports, ptr, func, format, args);
4069
int RNA_function_call_direct_lookup(bContext *C, ReportList *reports, PointerRNA *ptr, const char *identifier, const char *format, ...)
5128
int RNA_function_call_direct_lookup(bContext *C, ReportList *reports, PointerRNA *ptr, const char *identifier,
5129
const char *format, ...)
4071
5131
FunctionRNA *func;
4073
func= RNA_struct_find_function(ptr, identifier);
5133
func = RNA_struct_find_function(ptr, identifier);
4079
5139
va_start(args, format);
4081
ret= RNA_function_call_direct_va(C, reports, ptr, func, format, args);
5141
ret = RNA_function_call_direct_va(C, reports, ptr, func, format, args);
4246
int RNA_function_call_direct_va(bContext *C, ReportList *reports, PointerRNA *ptr, FunctionRNA *func, const char *format, va_list args)
5313
int RNA_function_call_direct_va(bContext *C, ReportList *reports, PointerRNA *ptr, FunctionRNA *func,
5314
const char *format, va_list args)
4248
5316
PointerRNA funcptr;
4249
5317
ParameterList parms;
4250
5318
ParameterIterator iter;
4251
5319
PropertyRNA *pret, *parm;
4252
5320
PropertyType type;
4253
int i, ofs, flen, flag, len, alen, err= 0;
4254
const char *tid, *fid, *pid=NULL;
5321
int i, ofs, flen, flag, len, alen, err = 0;
5322
const char *tid, *fid, *pid = NULL;
4256
void **retdata=NULL;
5324
void **retdata = NULL;
4258
5326
RNA_pointer_create(NULL, &RNA_Function, func, &funcptr);
4260
tid= RNA_struct_identifier(ptr->type);
4261
fid= RNA_function_identifier(func);
4263
flen= strlen(format);
5328
tid = RNA_struct_identifier(ptr->type);
5329
fid = RNA_function_identifier(func);
5331
flen = strlen(format);
4265
5333
RNA_parameter_list_create(&parms, ptr, func);
4266
5334
RNA_parameter_list_begin(&parms, &iter);
4268
for(i= 0, ofs= 0; iter.valid; RNA_parameter_list_next(&iter), i++) {
4270
flag= RNA_property_flag(parm);
5336
for (i = 0, ofs = 0; iter.valid; RNA_parameter_list_next(&iter), i++) {
5338
flag = RNA_property_flag(parm);
5341
retdata = iter.data;
4276
5344
else if (flag & PROP_OUTPUT) {
4280
pid= RNA_property_identifier(parm);
5348
pid = RNA_property_identifier(parm);
4282
if (ofs>=flen || format[ofs]=='N') {
5350
if (ofs >= flen || format[ofs] =='N') {
4283
5351
if (flag & PROP_REQUIRED) {
4285
5353
fprintf(stderr, "%s.%s: missing required parameter %s\n", tid, fid, pid);
4306
5377
case PROP_ENUM:
4308
int arg= va_arg(args, int);
4309
err= rna_function_parameter_parse(&funcptr, parm, type, ftype, len, iter.data, &arg, NULL, tid, fid, pid);
5379
int arg = va_arg(args, int);
5380
err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, iter.data, &arg,
5381
NULL, tid, fid, pid);
4312
5384
case PROP_FLOAT:
4314
double arg= va_arg(args, double);
4315
err= rna_function_parameter_parse(&funcptr, parm, type, ftype, len, iter.data, &arg, NULL, tid, fid, pid);
5386
double arg = va_arg(args, double);
5387
err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, iter.data, &arg,
5388
NULL, tid, fid, pid);
4318
5391
case PROP_STRING:
4320
char *arg= va_arg(args, char*);
4321
err= rna_function_parameter_parse(&funcptr, parm, type, ftype, len, iter.data, &arg, NULL, tid, fid, pid);
5393
char *arg = va_arg(args, char*);
5394
err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, iter.data, &arg,
5395
NULL, tid, fid, pid);
4324
5398
case PROP_POINTER:
4326
StructRNA *srna= va_arg(args, StructRNA*);
4327
void *arg= va_arg(args, void*);
4328
err= rna_function_parameter_parse(&funcptr, parm, type, ftype, len, iter.data, &arg, srna, tid, fid, pid);
5400
StructRNA *srna = va_arg(args, StructRNA*);
5401
void *arg = va_arg(args, void*);
5402
err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, iter.data, &arg,
5403
srna, tid, fid, pid);
4331
5406
case PROP_COLLECTION:
4333
StructRNA *srna= va_arg(args, StructRNA*);
4334
ListBase *arg= va_arg(args, ListBase*);
4335
err= rna_function_parameter_parse(&funcptr, parm, type, ftype, len, iter.data, &arg, srna, tid, fid, pid);
5408
StructRNA *srna = va_arg(args, StructRNA*);
5409
ListBase *arg = va_arg(args, ListBase*);
5410
err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, iter.data, &arg,
5411
srna, tid, fid, pid);
4340
5416
/* handle errors */
4341
err= rna_function_parameter_parse(&funcptr, parm, type, ftype, len, iter.data, NULL, NULL, tid, fid, pid);
5417
err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, iter.data, NULL,
5418
NULL, tid, fid, pid);
4351
err= RNA_function_call(C, reports, ptr, func, &parms);
5428
err = RNA_function_call(C, reports, ptr, func, &parms);
4353
5430
/* XXX throw error when more parameters than those needed are passed or leave silent? */
4354
if (err==0 && pret && ofs<flen && format[ofs++]=='R') {
4357
type= RNA_property_type(parm);
4358
ftype= format[ofs++];
4359
len= RNA_property_array_length(&funcptr, parm);
4360
alen= rna_function_format_array_length(format, ofs, flen);
4364
fprintf(stderr, "%s.%s: for return parameter %s, was expecting an array of %i elements, passed %i elements instead\n", tid, fid, pid, len, alen);
5431
if (err == 0 && pret && ofs<flen && format[ofs++] =='R') {
5434
type = RNA_property_type(parm);
5435
ftype = format[ofs++];
5436
len = RNA_property_array_length(&funcptr, parm);
5437
alen = rna_function_format_array_length(format, ofs, flen);
5441
fprintf(stderr, "%s.%s: for return parameter %s, "
5442
"was expecting an array of %i elements, passed %i elements instead\n",
5443
tid, fid, pid, len, alen);
4367
5446
switch (type) {
4370
5449
case PROP_ENUM:
4372
int *arg= va_arg(args, int*);
4373
err= rna_function_parameter_parse(&funcptr, parm, type, ftype, len, arg, retdata, NULL, tid, fid, pid);
5451
int *arg = va_arg(args, int*);
5452
err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, arg, retdata,
5453
NULL, tid, fid, pid);
4376
5456
case PROP_FLOAT:
4378
float *arg= va_arg(args, float*);
4379
err= rna_function_parameter_parse(&funcptr, parm, type, ftype, len, arg, retdata, NULL, tid, fid, pid);
5458
float *arg = va_arg(args, float*);
5459
err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, arg, retdata,
5460
NULL, tid, fid, pid);
4382
5463
case PROP_STRING:
4384
char **arg= va_arg(args, char**);
4385
err= rna_function_parameter_parse(&funcptr, parm, type, ftype, len, arg, retdata, NULL, tid, fid, pid);
5465
char **arg = va_arg(args, char**);
5466
err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, arg, retdata,
5467
NULL, tid, fid, pid);
4388
5470
case PROP_POINTER:
4390
StructRNA *srna= va_arg(args, StructRNA*);
4391
void **arg= va_arg(args, void**);
4392
err= rna_function_parameter_parse(&funcptr, parm, type, ftype, len, arg, retdata, srna, tid, fid, pid);
5472
StructRNA *srna = va_arg(args, StructRNA*);
5473
void **arg = va_arg(args, void**);
5474
err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, arg, retdata,
5475
srna, tid, fid, pid);
4395
5478
case PROP_COLLECTION:
4397
StructRNA *srna= va_arg(args, StructRNA*);
4398
ListBase **arg= va_arg(args, ListBase**);
4399
err= rna_function_parameter_parse(&funcptr, parm, type, ftype, len, arg, retdata, srna, tid, fid, pid);
5480
StructRNA *srna = va_arg(args, StructRNA*);
5481
ListBase **arg = va_arg(args, ListBase**);
5482
err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, arg, retdata,
5483
srna, tid, fid, pid);
4404
5488
/* handle errors */
4405
err= rna_function_parameter_parse(&funcptr, parm, type, ftype, len, NULL, NULL, NULL, tid, fid, pid);
5489
err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, NULL, NULL,
5490
NULL, tid, fid, pid);