~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/makesrna/intern/rna_access.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
#include "BLI_utildefines.h"
41
41
#include "BLI_dynstr.h"
42
42
#include "BLI_ghash.h"
 
43
#include "BLI_math.h"
43
44
 
44
45
#include "BLF_api.h"
45
46
#include "BLF_translation.h"
46
47
 
47
48
#include "BKE_animsys.h"
48
49
#include "BKE_context.h"
 
50
#include "BKE_idcode.h"
49
51
#include "BKE_idprop.h"
50
52
#include "BKE_main.h"
51
53
#include "BKE_report.h"
74
76
 
75
77
        for (srna = BLENDER_RNA.structs.first; srna; srna = srna->cont.next) {
76
78
                if (!srna->cont.prophash) {
77
 
                        srna->cont.prophash = BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "RNA_init gh");
 
79
                        srna->cont.prophash = BLI_ghash_str_new("RNA_init gh");
78
80
 
79
81
                        for (prop = srna->cont.properties.first; prop; prop = prop->next)
80
82
                                if (!(prop->flag & PROP_BUILTIN))
81
 
                                        BLI_ghash_insert(srna->cont.prophash, (void*)prop->identifier, prop);
 
83
                                        BLI_ghash_insert(srna->cont.prophash, (void *)prop->identifier, prop);
82
84
                }
83
85
        }
84
86
}
233
235
}
234
236
 
235
237
/* return a UI local ID prop definition for this prop */
236
 
IDProperty *rna_idproperty_ui(PropertyRNA *prop)
 
238
static IDProperty *rna_idproperty_ui(PropertyRNA *prop)
237
239
{
238
240
        IDProperty *idprop;
239
241
 
285
287
{
286
288
        if (prop->magic == RNA_MAGIC) {
287
289
                int arraylen[RNA_MAX_ARRAY_DIMENSION];
288
 
                return (prop->getlength && ptr->data)? prop->getlength(ptr, arraylen): prop->totarraylength;
 
290
                return (prop->getlength && ptr->data) ? prop->getlength(ptr, arraylen) : prop->totarraylength;
289
291
        }
290
292
        else {
291
 
                IDProperty *idprop = (IDProperty*)prop;
 
293
                IDProperty *idprop = (IDProperty *)prop;
292
294
 
293
295
                if (idprop->type == IDP_ARRAY)
294
296
                        return idprop->len;
300
302
static int rna_ensure_property_array_check(PropertyRNA *prop)
301
303
{
302
304
        if (prop->magic == RNA_MAGIC) {
303
 
                return (prop->getlength || prop->totarraylength) ? 1:0;
 
305
                return (prop->getlength || prop->totarraylength) ? 1 : 0;
304
306
        }
305
307
        else {
306
 
                IDProperty *idprop = (IDProperty*)prop;
 
308
                IDProperty *idprop = (IDProperty *)prop;
307
309
 
308
 
                return idprop->type == IDP_ARRAY ? 1:0;
 
310
                return idprop->type == IDP_ARRAY ? 1 : 0;
309
311
        }
310
312
}
311
313
 
315
317
                if (prop->getlength)
316
318
                        prop->getlength(ptr, length);
317
319
                else
318
 
                        memcpy(length, prop->arraylength, prop->arraydimension*sizeof(int));
 
320
                        memcpy(length, prop->arraylength, prop->arraydimension * sizeof(int));
319
321
        }
320
322
        else {
321
 
                IDProperty *idprop = (IDProperty*)prop;
 
323
                IDProperty *idprop = (IDProperty *)prop;
322
324
 
323
325
                if (idprop->type == IDP_ARRAY)
324
326
                        length[0] = idprop->len;
373
375
        return 1;
374
376
}
375
377
 
376
 
static PropertyRNA *typemap[IDP_NUMTYPES] =
377
 
        {(PropertyRNA*)&rna_PropertyGroupItem_string,
378
 
         (PropertyRNA*)&rna_PropertyGroupItem_int,
379
 
         (PropertyRNA*)&rna_PropertyGroupItem_float,
380
 
         NULL, NULL, NULL,
381
 
         (PropertyRNA*)&rna_PropertyGroupItem_group, NULL,
382
 
         (PropertyRNA*)&rna_PropertyGroupItem_double,
383
 
         (PropertyRNA*)&rna_PropertyGroupItem_idp_array};
 
378
static PropertyRNA *typemap[IDP_NUMTYPES] = {
 
379
        (PropertyRNA *)&rna_PropertyGroupItem_string,
 
380
        (PropertyRNA *)&rna_PropertyGroupItem_int,
 
381
        (PropertyRNA *)&rna_PropertyGroupItem_float,
 
382
        NULL, NULL, NULL,
 
383
        (PropertyRNA *)&rna_PropertyGroupItem_group, NULL,
 
384
        (PropertyRNA *)&rna_PropertyGroupItem_double,
 
385
        (PropertyRNA *)&rna_PropertyGroupItem_idp_array
 
386
};
384
387
 
385
 
static PropertyRNA *arraytypemap[IDP_NUMTYPES] =
386
 
        {NULL, (PropertyRNA*)&rna_PropertyGroupItem_int_array,
387
 
         (PropertyRNA*)&rna_PropertyGroupItem_float_array,
388
 
         NULL, NULL, NULL,
389
 
         (PropertyRNA*)&rna_PropertyGroupItem_collection, NULL,
390
 
         (PropertyRNA*)&rna_PropertyGroupItem_double_array};
 
388
static PropertyRNA *arraytypemap[IDP_NUMTYPES] = {
 
389
        NULL, (PropertyRNA *)&rna_PropertyGroupItem_int_array,
 
390
        (PropertyRNA *)&rna_PropertyGroupItem_float_array,
 
391
        NULL, NULL, NULL,
 
392
        (PropertyRNA *)&rna_PropertyGroupItem_collection, NULL,
 
393
        (PropertyRNA *)&rna_PropertyGroupItem_double_array
 
394
};
391
395
 
392
396
IDProperty *rna_idproperty_check(PropertyRNA **prop, PointerRNA *ptr)
393
397
{
418
422
        }
419
423
 
420
424
        {
421
 
                IDProperty *idprop = (IDProperty*)(*prop);
 
425
                IDProperty *idprop = (IDProperty *)(*prop);
422
426
 
423
427
                if (idprop->type == IDP_ARRAY)
424
428
                        *prop = arraytypemap[(int)(idprop->subtype)];
437
441
                return prop;
438
442
 
439
443
        {
440
 
                IDProperty *idprop = (IDProperty*)prop;
 
444
                IDProperty *idprop = (IDProperty *)prop;
441
445
 
442
446
                if (idprop->type == IDP_ARRAY)
443
447
                        return arraytypemap[(int)(idprop->subtype)];
451
455
        if (prop->magic == RNA_MAGIC)
452
456
                return prop->identifier;
453
457
        else
454
 
                return ((IDProperty*)prop)->name;
 
458
                return ((IDProperty *)prop)->name;
455
459
}
456
460
 
457
461
static const char *rna_ensure_property_description(PropertyRNA *prop)
471
475
                }
472
476
 
473
477
                if (description == NULL)
474
 
                        description = ((IDProperty*)prop)->name; /* XXX - not correct */
 
478
                        description = ((IDProperty *)prop)->name;  /* XXX - not correct */
475
479
        }
476
480
 
477
481
        return TIP_(description);
484
488
        if (prop->magic == RNA_MAGIC)
485
489
                name = prop->name;
486
490
        else
487
 
                name = ((IDProperty*)prop)->name;
 
491
                name = ((IDProperty *)prop)->name;
488
492
 
489
493
        return CTX_IFACE_(prop->translation_context, name);
490
494
}
525
529
        return TIP_(type->description);
526
530
}
527
531
 
 
532
const char *RNA_struct_translation_context(StructRNA *type)
 
533
{
 
534
        return type->translation_context ? type->translation_context : BLF_I18NCONTEXT_DEFAULT;
 
535
}
 
536
 
528
537
PropertyRNA *RNA_struct_name_property(StructRNA *type)
529
538
{
530
539
        return type->nameproperty;
590
599
 
591
600
PropertyRNA *RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
592
601
{
593
 
        if (identifier[0] =='[' && identifier[1] =='"') { /* "  (dummy comment to avoid confusing some
594
 
                                                           * function lists in text editors) */
 
602
        if (identifier[0] == '[' && identifier[1] == '"') { /* "  (dummy comment to avoid confusing some
 
603
                                                                 * function lists in text editors) */
595
604
                /* id prop lookup, not so common */
596
605
                PropertyRNA *r_prop = NULL;
597
606
                PointerRNA r_ptr; /* only support single level props */
611
620
}
612
621
 
613
622
/* Find the property which uses the given nested struct */
614
 
PropertyRNA *RNA_struct_find_nested(PointerRNA *ptr, StructRNA *srna)
 
623
static PropertyRNA *RNA_struct_find_nested(PointerRNA *ptr, StructRNA *srna)
615
624
{
616
625
        PropertyRNA *prop = NULL;
617
626
 
618
 
        RNA_STRUCT_BEGIN(ptr, iprop) {
 
627
        RNA_STRUCT_BEGIN(ptr, iprop)
 
628
        {
619
629
                /* This assumes that there can only be one user of this nested struct */
620
630
                if (RNA_property_pointer_type(ptr, iprop) == srna) {
621
631
                        prop = iprop;
637
647
 
638
648
        iterprop = RNA_struct_iterator_property(ptr->type);
639
649
 
640
 
        RNA_PROP_BEGIN(ptr, itemptr, iterprop) {
641
 
                /* PropertyRNA *prop= itemptr.data; */
 
650
        RNA_PROP_BEGIN(ptr, itemptr, iterprop)
 
651
        {
 
652
                /* PropertyRNA *prop = itemptr.data; */
642
653
                if (prop_test == (PropertyRNA *)itemptr.data) {
643
654
                        found = TRUE;
644
655
                        break;
660
671
        return BLI_findstring_ptr(&srna->cont.properties, identifier, offsetof(PropertyRNA, identifier));
661
672
}
662
673
 
663
 
FunctionRNA *RNA_struct_find_function(PointerRNA *ptr, const char *identifier)
 
674
FunctionRNA *RNA_struct_find_function(StructRNA *srna, const char *identifier)
664
675
{
665
676
#if 1
666
677
        FunctionRNA *func;
667
678
        StructRNA *type;
668
 
        for (type = ptr->type; type; type = type->base) {
 
679
        for (type = srna; type; type = type->base) {
669
680
                func = (FunctionRNA *)BLI_findstring_ptr(&type->functions, identifier, offsetof(FunctionRNA, identifier));
670
681
                if (func) {
671
682
                        return func;
679
690
        PropertyRNA *iterprop;
680
691
        FunctionRNA *func;
681
692
 
682
 
        RNA_pointer_create(NULL, &RNA_Struct, ptr->type, &tptr);
 
693
        RNA_pointer_create(NULL, &RNA_Struct, srna, &tptr);
683
694
        iterprop = RNA_struct_find_property(&tptr, "functions");
684
695
 
685
696
        func = NULL;
686
697
 
687
 
        RNA_PROP_BEGIN(&tptr, funcptr, iterprop) {
 
698
        RNA_PROP_BEGIN(&tptr, funcptr, iterprop)
 
699
        {
688
700
                if (strcmp(identifier, RNA_function_identifier(funcptr.data)) == 0) {
689
701
                        func = funcptr.data;
690
702
                        break;
696
708
#endif
697
709
}
698
710
 
699
 
const struct ListBase *RNA_struct_type_functions(StructRNA *srna)
 
711
const ListBase *RNA_struct_type_functions(StructRNA *srna)
700
712
{
701
713
        return &srna->functions;
702
714
}
811
823
        PropertyRNA *rprop = rna_ensure_property(prop);
812
824
 
813
825
        if (length)
814
 
                        rna_ensure_property_multi_array_length(ptr, prop, length);
 
826
                rna_ensure_property_multi_array_length(ptr, prop, length);
815
827
 
816
828
        return rprop->arraydimension;
817
829
}
838
850
                return quatitem[index];
839
851
        }
840
852
        else if ((index < 4) && ELEM8(subtype, PROP_TRANSLATION, PROP_DIRECTION, PROP_XYZ, PROP_XYZ_LENGTH,
841
 
                                              PROP_EULER, PROP_VELOCITY, PROP_ACCELERATION, PROP_COORDS))
 
853
                                      PROP_EULER, PROP_VELOCITY, PROP_ACCELERATION, PROP_COORDS))
842
854
        {
843
855
                return vectoritem[index];
844
856
        }
868
880
                }
869
881
        }
870
882
        else if (ELEM6(subtype, PROP_TRANSLATION, PROP_DIRECTION, PROP_XYZ,
871
 
                               PROP_EULER, PROP_VELOCITY, PROP_ACCELERATION))
 
883
                       PROP_EULER, PROP_VELOCITY, PROP_ACCELERATION))
872
884
        {
873
885
                switch (name) {
874
886
                        case 'x':
900
912
 
901
913
void RNA_property_int_range(PointerRNA *ptr, PropertyRNA *prop, int *hardmin, int *hardmax)
902
914
{
903
 
        IntPropertyRNA *iprop = (IntPropertyRNA*)rna_ensure_property(prop);
 
915
        IntPropertyRNA *iprop = (IntPropertyRNA *)rna_ensure_property(prop);
904
916
        int softmin, softmax;
905
917
 
906
918
        if (prop->magic != RNA_MAGIC) {
926
938
 
927
939
                iprop->range(ptr, hardmin, hardmax, &softmin, &softmax);
928
940
        }
 
941
        else if (iprop->range_ex) {
 
942
                *hardmin = INT_MIN;
 
943
                *hardmax = INT_MAX;
 
944
 
 
945
                iprop->range_ex(ptr, prop, hardmin, hardmax, &softmin, &softmax);
 
946
        }
929
947
        else {
930
948
                *hardmin = iprop->hardmin;
931
949
                *hardmax = iprop->hardmax;
934
952
 
935
953
void RNA_property_int_ui_range(PointerRNA *ptr, PropertyRNA *prop, int *softmin, int *softmax, int *step)
936
954
{
937
 
        IntPropertyRNA *iprop = (IntPropertyRNA*)rna_ensure_property(prop);
 
955
        IntPropertyRNA *iprop = (IntPropertyRNA *)rna_ensure_property(prop);
938
956
        int hardmin, hardmax;
939
957
        
940
958
        if (prop->magic != RNA_MAGIC) {
966
984
 
967
985
                iprop->range(ptr, &hardmin, &hardmax, softmin, softmax);
968
986
 
969
 
                *softmin = MAX2(*softmin, hardmin);
970
 
                *softmax = MIN2(*softmax, hardmax);
 
987
                *softmin = max_ii(*softmin, hardmin);
 
988
                *softmax = min_ii(*softmax, hardmax);
 
989
        }
 
990
        else if (iprop->range_ex) {
 
991
                hardmin = INT_MIN;
 
992
                hardmax = INT_MAX;
 
993
 
 
994
                iprop->range_ex(ptr, prop, &hardmin, &hardmax, softmin, softmax);
 
995
 
 
996
                *softmin = max_ii(*softmin, hardmin);
 
997
                *softmax = min_ii(*softmax, hardmax);
971
998
        }
972
999
 
973
1000
        *step = iprop->step;
975
1002
 
976
1003
void RNA_property_float_range(PointerRNA *ptr, PropertyRNA *prop, float *hardmin, float *hardmax)
977
1004
{
978
 
        FloatPropertyRNA *fprop = (FloatPropertyRNA*)rna_ensure_property(prop);
 
1005
        FloatPropertyRNA *fprop = (FloatPropertyRNA *)rna_ensure_property(prop);
979
1006
        float softmin, softmax;
980
1007
 
981
1008
        if (prop->magic != RNA_MAGIC) {
986
1013
                        IDProperty *item;
987
1014
 
988
1015
                        item = IDP_GetPropertyTypeFromGroup(idp_ui, "min", IDP_DOUBLE);
989
 
                        *hardmin = item ? (float)IDP_Double(item) : FLT_MIN;
 
1016
                        *hardmin = item ? (float)IDP_Double(item) : -FLT_MAX;
990
1017
 
991
1018
                        item = IDP_GetPropertyTypeFromGroup(idp_ui, "max", IDP_DOUBLE);
992
1019
                        *hardmax = item ? (float)IDP_Double(item) : FLT_MAX;
1001
1028
 
1002
1029
                fprop->range(ptr, hardmin, hardmax, &softmin, &softmax);
1003
1030
        }
 
1031
        else if (fprop->range_ex) {
 
1032
                *hardmin = -FLT_MAX;
 
1033
                *hardmax = FLT_MAX;
 
1034
 
 
1035
                fprop->range_ex(ptr, prop, hardmin, hardmax, &softmin, &softmax);
 
1036
        }
1004
1037
        else {
1005
1038
                *hardmin = fprop->hardmin;
1006
1039
                *hardmax = fprop->hardmax;
1010
1043
void RNA_property_float_ui_range(PointerRNA *ptr, PropertyRNA *prop, float *softmin, float *softmax,
1011
1044
                                 float *step, float *precision)
1012
1045
{
1013
 
        FloatPropertyRNA *fprop = (FloatPropertyRNA*)rna_ensure_property(prop);
 
1046
        FloatPropertyRNA *fprop = (FloatPropertyRNA *)rna_ensure_property(prop);
1014
1047
        float hardmin, hardmax;
1015
1048
 
1016
1049
        if (prop->magic != RNA_MAGIC) {
1021
1054
                        IDProperty *item;
1022
1055
 
1023
1056
                        item = IDP_GetPropertyTypeFromGroup(idp_ui, "soft_min", IDP_DOUBLE);
1024
 
                        *softmin = item ? (float)IDP_Double(item) : FLT_MIN;
 
1057
                        *softmin = item ? (float)IDP_Double(item) : -FLT_MAX;
1025
1058
 
1026
1059
                        item = IDP_GetPropertyTypeFromGroup(idp_ui, "soft_max", IDP_DOUBLE);
1027
1060
                        *softmax = item ? (float)IDP_Double(item) : FLT_MAX;
1045
1078
 
1046
1079
                fprop->range(ptr, &hardmin, &hardmax, softmin, softmax);
1047
1080
 
1048
 
                *softmin = MAX2(*softmin, hardmin);
1049
 
                *softmax = MIN2(*softmax, hardmax);
 
1081
                *softmin = max_ff(*softmin, hardmin);
 
1082
                *softmax = min_ff(*softmax, hardmax);
 
1083
        }
 
1084
        else if (fprop->range_ex) {
 
1085
                hardmin = -FLT_MAX;
 
1086
                hardmax = FLT_MAX;
 
1087
 
 
1088
                fprop->range_ex(ptr, prop, &hardmin, &hardmax, softmin, softmax);
 
1089
 
 
1090
                *softmin = max_ff(*softmin, hardmin);
 
1091
                *softmax = min_ff(*softmax, hardmax);
1050
1092
        }
1051
1093
 
1052
1094
        *step = fprop->step;
1095
1137
 * '0' used when their is no maximum */
1096
1138
int RNA_property_string_maxlength(PropertyRNA *prop)
1097
1139
{
1098
 
        StringPropertyRNA *sprop = (StringPropertyRNA*)rna_ensure_property(prop);
 
1140
        StringPropertyRNA *sprop = (StringPropertyRNA *)rna_ensure_property(prop);
1099
1141
        return sprop->maxlength;
1100
1142
}
1101
1143
 
1104
1146
        prop = rna_ensure_property(prop);
1105
1147
 
1106
1148
        if (prop->type == PROP_POINTER) {
1107
 
                PointerPropertyRNA *pprop = (PointerPropertyRNA*)prop;
 
1149
                PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
1108
1150
 
1109
1151
                if (pprop->typef)
1110
1152
                        return pprop->typef(ptr);
1112
1154
                        return pprop->type;
1113
1155
        }
1114
1156
        else if (prop->type == PROP_COLLECTION) {
1115
 
                CollectionPropertyRNA *cprop = (CollectionPropertyRNA*)prop;
 
1157
                CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop;
1116
1158
 
1117
1159
                if (cprop->item_type)
1118
1160
                        return cprop->item_type;
1127
1169
        prop = rna_ensure_property(prop);
1128
1170
 
1129
1171
        if (prop->type == PROP_POINTER) {
1130
 
                PointerPropertyRNA *pprop = (PointerPropertyRNA*)prop;
 
1172
                PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
1131
1173
                if (pprop->poll)
1132
1174
                        return pprop->poll(ptr, *value);
1133
1175
 
1152
1194
void RNA_property_enum_items(bContext *C, PointerRNA *ptr, PropertyRNA *prop, EnumPropertyItem **item,
1153
1195
                             int *totitem, int *free)
1154
1196
{
1155
 
        EnumPropertyRNA *eprop = (EnumPropertyRNA*)rna_ensure_property(prop);
 
1197
        EnumPropertyRNA *eprop = (EnumPropertyRNA *)rna_ensure_property(prop);
1156
1198
 
1157
1199
        *free = 0;
1158
1200
 
1166
1208
 
1167
1209
                if (totitem) {
1168
1210
                        if (*item) {
1169
 
                                for ( ; (*item)[tot].identifier; tot++);
 
1211
                                for (; (*item)[tot].identifier; tot++) ;
1170
1212
                        }
1171
1213
 
1172
1214
                        *totitem = tot;
1186
1228
        RNA_property_enum_items(C, ptr, prop, item, totitem, free);
1187
1229
 
1188
1230
#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()) {
 
1231
        {
1191
1232
                int i;
 
1233
                /* Note: Only do those tests once, and then use BLF_pgettext. */
 
1234
                int do_iface = BLF_translate_iface();
 
1235
                int do_tooltip = BLF_translate_tooltips();
1192
1236
                EnumPropertyItem *nitem;
1193
1237
 
 
1238
                if (!(do_iface || do_tooltip))
 
1239
                        return;
 
1240
 
1194
1241
                if (*free) {
1195
1242
                        nitem = *item;
1196
1243
                }
1201
1248
                        for (i = 0; (*item)[i].identifier; i++)
1202
1249
                                totitem++;
1203
1250
 
1204
 
                        nitem = MEM_callocN(sizeof(EnumPropertyItem)*(totitem+1), "enum_items_gettexted");
 
1251
                        nitem = MEM_callocN(sizeof(EnumPropertyItem) * (totitem + 1), "enum_items_gettexted");
1205
1252
 
1206
1253
                        for (i = 0; (*item)[i].identifier; i++)
1207
1254
                                nitem[i] = (*item)[i];
1208
1255
 
1209
 
                        *free = 1;
 
1256
                        *free = TRUE;
1210
1257
                }
1211
1258
 
1212
1259
                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);
1216
 
                                else
1217
 
                                        nitem[i].name = BLF_gettext(nitem[i].name);
1218
 
                        }
1219
 
                        if ( nitem[i].description )
1220
 
                                nitem[i].description = BLF_gettext(nitem[i].description);
 
1260
                        if (nitem[i].name && do_iface) {
 
1261
                                /* note: prop->translation_context may be NULL, this just means we use the default "" context */
 
1262
                                nitem[i].name = BLF_pgettext(prop->translation_context, nitem[i].name);
 
1263
                        }
 
1264
                        if (nitem[i].description && do_tooltip) {
 
1265
                                nitem[i].description = BLF_pgettext(NULL, nitem[i].description);
 
1266
                        }
1221
1267
                }
1222
1268
 
1223
1269
                *item = nitem;
1358
1404
        return rna_ensure_property_description(prop);
1359
1405
}
1360
1406
 
 
1407
const char *RNA_property_translation_context(PropertyRNA *_prop)
 
1408
{
 
1409
        PropertyRNA *prop = rna_ensure_property(_prop);
 
1410
        return prop->translation_context ? prop->translation_context : BLF_I18NCONTEXT_DEFAULT;
 
1411
}
 
1412
 
1361
1413
int RNA_property_ui_icon(PropertyRNA *prop)
1362
1414
{
1363
1415
        return rna_ensure_property(prop)->icon;
1453
1505
 
1454
1506
static void rna_property_update(bContext *C, Main *bmain, Scene *scene, PointerRNA *ptr, PropertyRNA *prop)
1455
1507
{
1456
 
        int is_rna = (prop->magic == RNA_MAGIC);
 
1508
        const bool is_rna = (prop->magic == RNA_MAGIC);
1457
1509
        prop = rna_ensure_property(prop);
1458
1510
 
1459
1511
        if (is_rna) {
1480
1532
        if (!is_rna || (prop->flag & PROP_IDPROPERTY)) {
1481
1533
                /* WARNING! This is so property drivers update the display!
1482
1534
                 * not especially nice  */
1483
 
                DAG_id_tag_update(ptr->id.data, OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME);
 
1535
                DAG_id_tag_update(ptr->id.data, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
1484
1536
                WM_main_add_notifier(NC_WINDOW, NULL);
1485
1537
        }
1486
1538
}
1514
1566
 *
1515
1567
 * The cache is structured with a dual-layer structure
1516
1568
 * - L1 = PointerRNA used as key; id.data is used (it should always be defined,
1517
 
 *               and most updates end up using just that anyways)
 
1569
 *        and most updates end up using just that anyways)
1518
1570
 * - L2 = Update functions to be called on those PointerRNA's
1519
1571
 */
1520
1572
 
1522
1574
typedef struct tRnaUpdateCacheElem {
1523
1575
        struct tRnaUpdateCacheElem *next, *prev;
1524
1576
        
1525
 
        PointerRNA ptr;         /* L1 key - id as primary, data secondary/ignored? */
1526
 
        ListBase L2Funcs;       /* L2 functions (LinkData<RnaUpdateFuncRef>) */
 
1577
        PointerRNA ptr;     /* L1 key - id as primary, data secondary/ignored? */
 
1578
        ListBase L2Funcs;   /* L2 functions (LinkData<RnaUpdateFuncRef>) */
1527
1579
} tRnaUpdateCacheElem;
1528
1580
 
1529
1581
/* cache global (tRnaUpdateCacheElem's) - only accessible using these API calls */
1533
1585
 
1534
1586
void RNA_property_update_cache_add(PointerRNA *ptr, PropertyRNA *prop)
1535
1587
{
 
1588
        const bool is_rna = (prop->magic == RNA_MAGIC);
1536
1589
        tRnaUpdateCacheElem *uce = NULL;
1537
1590
        UpdateFunc fn = NULL;
1538
1591
        LinkData *ld;
1539
 
        short is_rna = (prop->magic == RNA_MAGIC);
1540
1592
        
1541
1593
        /* sanity check */
1542
 
        if (ELEM(NULL, ptr, prop))
 
1594
        if (NULL == ptr)
1543
1595
                return;
1544
1596
                
1545
1597
        prop = rna_ensure_property(prop);
1546
1598
        
1547
1599
        /* 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))
 
1600
        if ((is_rna == false) || (prop->update == NULL) || (prop->flag & PROP_CONTEXT_UPDATE))
1549
1601
                return;
1550
1602
        fn = prop->update;
1551
1603
                
1614
1666
 
1615
1667
int RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
1616
1668
{
1617
 
        BoolPropertyRNA *bprop = (BoolPropertyRNA*)prop;
 
1669
        BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
1618
1670
        IDProperty *idprop;
1619
1671
 
1620
1672
        BLI_assert(RNA_property_type(prop) == PROP_BOOLEAN);
1624
1676
                return IDP_Int(idprop);
1625
1677
        else if (bprop->get)
1626
1678
                return bprop->get(ptr);
 
1679
        else if (bprop->get_ex)
 
1680
                return bprop->get_ex(ptr, prop);
1627
1681
        else
1628
1682
                return bprop->defaultvalue;
1629
1683
}
1630
1684
 
1631
1685
void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, int value)
1632
1686
{
1633
 
        BoolPropertyRNA *bprop = (BoolPropertyRNA*)prop;
 
1687
        BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
1634
1688
        IDProperty *idprop;
1635
1689
 
1636
1690
        BLI_assert(RNA_property_type(prop) == PROP_BOOLEAN);
1643
1697
                IDP_Int(idprop) = value;
1644
1698
                rna_idproperty_touch(idprop);
1645
1699
        }
1646
 
        else if (bprop->set)
 
1700
        else if (bprop->set) {
1647
1701
                bprop->set(ptr, value);
 
1702
        }
 
1703
        else if (bprop->set_ex) {
 
1704
                bprop->set_ex(ptr, prop, value);
 
1705
        }
1648
1706
        else if (prop->flag & PROP_EDITABLE) {
1649
1707
                IDPropertyTemplate val = {0};
1650
1708
                IDProperty *group;
1659
1717
 
1660
1718
void RNA_property_boolean_get_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
1661
1719
{
1662
 
        BoolPropertyRNA *bprop = (BoolPropertyRNA*)prop;
 
1720
        BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
1663
1721
        IDProperty *idprop;
1664
1722
 
1665
1723
        BLI_assert(RNA_property_type(prop) == PROP_BOOLEAN);
1669
1727
                if (prop->arraydimension == 0)
1670
1728
                        values[0] = RNA_property_boolean_get(ptr, prop);
1671
1729
                else
1672
 
                        memcpy(values, IDP_Array(idprop), sizeof(int)*idprop->len);
 
1730
                        memcpy(values, IDP_Array(idprop), sizeof(int) * idprop->len);
1673
1731
        }
1674
1732
        else if (prop->arraydimension == 0)
1675
1733
                values[0] = RNA_property_boolean_get(ptr, prop);
1676
1734
        else if (bprop->getarray)
1677
1735
                bprop->getarray(ptr, values);
 
1736
        else if (bprop->getarray_ex)
 
1737
                bprop->getarray_ex(ptr, prop, values);
1678
1738
        else if (bprop->defaultarray)
1679
 
                memcpy(values, bprop->defaultarray, sizeof(int)*prop->totarraylength);
 
1739
                memcpy(values, bprop->defaultarray, sizeof(int) * prop->totarraylength);
1680
1740
        else
1681
 
                memset(values, 0, sizeof(int)*prop->totarraylength);
 
1741
                memset(values, 0, sizeof(int) * prop->totarraylength);
1682
1742
}
1683
1743
 
1684
1744
int RNA_property_boolean_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
1696
1756
        else {
1697
1757
                int *tmparray, value;
1698
1758
 
1699
 
                tmparray = MEM_callocN(sizeof(int)*len, "RNA_property_boolean_get_index");
 
1759
                tmparray = MEM_callocN(sizeof(int) * len, "RNA_property_boolean_get_index");
1700
1760
                RNA_property_boolean_get_array(ptr, prop, tmparray);
1701
1761
                value = tmparray[index];
1702
1762
                MEM_freeN(tmparray);
1707
1767
 
1708
1768
void RNA_property_boolean_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *values)
1709
1769
{
1710
 
        BoolPropertyRNA *bprop = (BoolPropertyRNA*)prop;
 
1770
        BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
1711
1771
        IDProperty *idprop;
1712
1772
 
1713
1773
        BLI_assert(RNA_property_type(prop) == PROP_BOOLEAN);
1717
1777
                if (prop->arraydimension == 0)
1718
1778
                        IDP_Int(idprop) = values[0];
1719
1779
                else
1720
 
                        memcpy(IDP_Array(idprop), values, sizeof(int)*idprop->len);
 
1780
                        memcpy(IDP_Array(idprop), values, sizeof(int) * idprop->len);
1721
1781
 
1722
1782
                rna_idproperty_touch(idprop);
1723
1783
        }
1725
1785
                RNA_property_boolean_set(ptr, prop, values[0]);
1726
1786
        else if (bprop->setarray)
1727
1787
                bprop->setarray(ptr, values);
 
1788
        else if (bprop->setarray_ex)
 
1789
                bprop->setarray_ex(ptr, prop, values);
1728
1790
        else if (prop->flag & PROP_EDITABLE) {
1729
1791
                IDPropertyTemplate val = {0};
1730
1792
                IDProperty *group;
1736
1798
                if (group) {
1737
1799
                        idprop = IDP_New(IDP_ARRAY, &val, prop->identifier);
1738
1800
                        IDP_AddToGroup(group, idprop);
1739
 
                        memcpy(IDP_Array(idprop), values, sizeof(int)*idprop->len);
 
1801
                        memcpy(IDP_Array(idprop), values, sizeof(int) * idprop->len);
1740
1802
                }
1741
1803
        }
1742
1804
}
1757
1819
        else {
1758
1820
                int *tmparray;
1759
1821
 
1760
 
                tmparray = MEM_callocN(sizeof(int)*len, "RNA_property_boolean_get_index");
 
1822
                tmparray = MEM_callocN(sizeof(int) * len, "RNA_property_boolean_get_index");
1761
1823
                RNA_property_boolean_get_array(ptr, prop, tmparray);
1762
1824
                tmparray[index] = value;
1763
1825
                RNA_property_boolean_set_array(ptr, prop, tmparray);
1767
1829
 
1768
1830
int RNA_property_boolean_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
1769
1831
{
1770
 
        BoolPropertyRNA *bprop = (BoolPropertyRNA*)prop;
 
1832
        BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
1771
1833
 
1772
1834
        BLI_assert(RNA_property_type(prop) == PROP_BOOLEAN);
1773
1835
        BLI_assert(RNA_property_array_check(prop) == 0);
1777
1839
 
1778
1840
void RNA_property_boolean_get_default_array(PointerRNA *UNUSED(ptr), PropertyRNA *prop, int *values)
1779
1841
{
1780
 
        BoolPropertyRNA *bprop = (BoolPropertyRNA*)prop;
 
1842
        BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
1781
1843
        
1782
1844
        BLI_assert(RNA_property_type(prop) == PROP_BOOLEAN);
1783
1845
        BLI_assert(RNA_property_array_check(prop) != 0);
1785
1847
        if (prop->arraydimension == 0)
1786
1848
                values[0] = bprop->defaultvalue;
1787
1849
        else if (bprop->defaultarray)
1788
 
                memcpy(values, bprop->defaultarray, sizeof(int)*prop->totarraylength);
 
1850
                memcpy(values, bprop->defaultarray, sizeof(int) * prop->totarraylength);
1789
1851
        else
1790
 
                memset(values, 0, sizeof(int)*prop->totarraylength);
 
1852
                memset(values, 0, sizeof(int) * prop->totarraylength);
1791
1853
}
1792
1854
 
1793
1855
int RNA_property_boolean_get_default_index(PointerRNA *ptr, PropertyRNA *prop, int index)
1805
1867
        else {
1806
1868
                int *tmparray, value;
1807
1869
 
1808
 
                tmparray = MEM_callocN(sizeof(int)*len, "RNA_property_boolean_get_default_index");
 
1870
                tmparray = MEM_callocN(sizeof(int) * len, "RNA_property_boolean_get_default_index");
1809
1871
                RNA_property_boolean_get_default_array(ptr, prop, tmparray);
1810
1872
                value = tmparray[index];
1811
1873
                MEM_freeN(tmparray);
1816
1878
 
1817
1879
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
1818
1880
{
1819
 
        IntPropertyRNA *iprop = (IntPropertyRNA*)prop;
 
1881
        IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
1820
1882
        IDProperty *idprop;
1821
1883
 
1822
1884
        BLI_assert(RNA_property_type(prop) == PROP_INT);
1826
1888
                return IDP_Int(idprop);
1827
1889
        else if (iprop->get)
1828
1890
                return iprop->get(ptr);
 
1891
        else if (iprop->get_ex)
 
1892
                return iprop->get_ex(ptr, prop);
1829
1893
        else
1830
1894
                return iprop->defaultvalue;
1831
1895
}
1832
1896
 
1833
1897
void RNA_property_int_set(PointerRNA *ptr, PropertyRNA *prop, int value)
1834
1898
{
1835
 
        IntPropertyRNA *iprop = (IntPropertyRNA*)prop;
 
1899
        IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
1836
1900
        IDProperty *idprop;
1837
1901
 
1838
1902
        BLI_assert(RNA_property_type(prop) == PROP_INT);
1846
1910
        }
1847
1911
        else if (iprop->set)
1848
1912
                iprop->set(ptr, value);
 
1913
        else if (iprop->set_ex)
 
1914
                iprop->set_ex(ptr, prop, value);
1849
1915
        else if (prop->flag & PROP_EDITABLE) {
1850
1916
                IDPropertyTemplate val = {0};
1851
1917
                IDProperty *group;
1852
1918
 
 
1919
                RNA_property_int_clamp(ptr, prop, &value);
 
1920
 
1853
1921
                val.i = value;
1854
1922
 
1855
1923
                group = RNA_struct_idprops(ptr, 1);
1860
1928
 
1861
1929
void RNA_property_int_get_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
1862
1930
{
1863
 
        IntPropertyRNA *iprop = (IntPropertyRNA*)prop;
 
1931
        IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
1864
1932
        IDProperty *idprop;
1865
1933
 
1866
1934
        BLI_assert(RNA_property_type(prop) == PROP_INT);
1870
1938
                if (prop->arraydimension == 0)
1871
1939
                        values[0] = RNA_property_int_get(ptr, prop);
1872
1940
                else
1873
 
                        memcpy(values, IDP_Array(idprop), sizeof(int)*idprop->len);
 
1941
                        memcpy(values, IDP_Array(idprop), sizeof(int) * idprop->len);
1874
1942
        }
1875
1943
        else if (prop->arraydimension == 0)
1876
1944
                values[0] = RNA_property_int_get(ptr, prop);
1877
1945
        else if (iprop->getarray)
1878
1946
                iprop->getarray(ptr, values);
 
1947
        else if (iprop->getarray_ex)
 
1948
                iprop->getarray_ex(ptr, prop, values);
1879
1949
        else if (iprop->defaultarray)
1880
 
                memcpy(values, iprop->defaultarray, sizeof(int)*prop->totarraylength);
 
1950
                memcpy(values, iprop->defaultarray, sizeof(int) * prop->totarraylength);
1881
1951
        else
1882
 
                memset(values, 0, sizeof(int)*prop->totarraylength);
 
1952
                memset(values, 0, sizeof(int) * prop->totarraylength);
1883
1953
}
1884
1954
 
1885
1955
void RNA_property_int_get_array_range(PointerRNA *ptr, PropertyRNA *prop, int values[2])
1934
2004
        else {
1935
2005
                int *tmparray, value;
1936
2006
 
1937
 
                tmparray = MEM_callocN(sizeof(int)*len, "RNA_property_int_get_index");
 
2007
                tmparray = MEM_callocN(sizeof(int) * len, "RNA_property_int_get_index");
1938
2008
                RNA_property_int_get_array(ptr, prop, tmparray);
1939
2009
                value = tmparray[index];
1940
2010
                MEM_freeN(tmparray);
1945
2015
 
1946
2016
void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *values)
1947
2017
{
1948
 
        IntPropertyRNA *iprop = (IntPropertyRNA*)prop;
 
2018
        IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
1949
2019
        IDProperty *idprop;
1950
2020
 
1951
2021
        BLI_assert(RNA_property_type(prop) == PROP_INT);
1955
2025
                if (prop->arraydimension == 0)
1956
2026
                        IDP_Int(idprop) = values[0];
1957
2027
                else
1958
 
                        memcpy(IDP_Array(idprop), values, sizeof(int)*idprop->len);
 
2028
                        memcpy(IDP_Array(idprop), values, sizeof(int) * idprop->len);
1959
2029
 
1960
2030
                rna_idproperty_touch(idprop);
1961
2031
        }
1963
2033
                RNA_property_int_set(ptr, prop, values[0]);
1964
2034
        else if (iprop->setarray)
1965
2035
                iprop->setarray(ptr, values);
 
2036
        else if (iprop->setarray_ex)
 
2037
                iprop->setarray_ex(ptr, prop, values);
1966
2038
        else if (prop->flag & PROP_EDITABLE) {
1967
2039
                IDPropertyTemplate val = {0};
1968
2040
                IDProperty *group;
1969
2041
 
 
2042
                /* TODO: RNA_property_int_clamp_array(ptr, prop, &value); */
 
2043
 
1970
2044
                val.array.len = prop->totarraylength;
1971
2045
                val.array.type = IDP_INT;
1972
2046
 
1974
2048
                if (group) {
1975
2049
                        idprop = IDP_New(IDP_ARRAY, &val, prop->identifier);
1976
2050
                        IDP_AddToGroup(group, idprop);
1977
 
                        memcpy(IDP_Array(idprop), values, sizeof(int)*idprop->len);
 
2051
                        memcpy(IDP_Array(idprop), values, sizeof(int) * idprop->len);
1978
2052
                }
1979
2053
        }
1980
2054
}
1995
2069
        else {
1996
2070
                int *tmparray;
1997
2071
 
1998
 
                tmparray = MEM_callocN(sizeof(int)*len, "RNA_property_int_get_index");
 
2072
                tmparray = MEM_callocN(sizeof(int) * len, "RNA_property_int_get_index");
1999
2073
                RNA_property_int_get_array(ptr, prop, tmparray);
2000
2074
                tmparray[index] = value;
2001
2075
                RNA_property_int_set_array(ptr, prop, tmparray);
2005
2079
 
2006
2080
int RNA_property_int_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
2007
2081
{
2008
 
        IntPropertyRNA *iprop = (IntPropertyRNA*)prop;
 
2082
        IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
2009
2083
        return iprop->defaultvalue;
2010
2084
}
2011
2085
 
2012
2086
void RNA_property_int_get_default_array(PointerRNA *UNUSED(ptr), PropertyRNA *prop, int *values)
2013
2087
{
2014
 
        IntPropertyRNA *iprop = (IntPropertyRNA*)prop;
 
2088
        IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
2015
2089
        
2016
2090
        BLI_assert(RNA_property_type(prop) == PROP_INT);
2017
2091
        BLI_assert(RNA_property_array_check(prop) != 0);
2019
2093
        if (prop->arraydimension == 0)
2020
2094
                values[0] = iprop->defaultvalue;
2021
2095
        else if (iprop->defaultarray)
2022
 
                memcpy(values, iprop->defaultarray, sizeof(int)*prop->totarraylength);
 
2096
                memcpy(values, iprop->defaultarray, sizeof(int) * prop->totarraylength);
2023
2097
        else
2024
 
                memset(values, 0, sizeof(int)*prop->totarraylength);
 
2098
                memset(values, 0, sizeof(int) * prop->totarraylength);
2025
2099
}
2026
2100
 
2027
2101
int RNA_property_int_get_default_index(PointerRNA *ptr, PropertyRNA *prop, int index)
2036
2110
        else {
2037
2111
                int *tmparray, value;
2038
2112
 
2039
 
                tmparray = MEM_callocN(sizeof(int)*len, "RNA_property_int_get_default_index");
 
2113
                tmparray = MEM_callocN(sizeof(int) * len, "RNA_property_int_get_default_index");
2040
2114
                RNA_property_int_get_default_array(ptr, prop, tmparray);
2041
2115
                value = tmparray[index];
2042
2116
                MEM_freeN(tmparray);
2047
2121
 
2048
2122
float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop)
2049
2123
{
2050
 
        FloatPropertyRNA *fprop = (FloatPropertyRNA*)prop;
 
2124
        FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
2051
2125
        IDProperty *idprop;
2052
2126
 
2053
2127
        BLI_assert(RNA_property_type(prop) == PROP_FLOAT);
2061
2135
        }
2062
2136
        else if (fprop->get)
2063
2137
                return fprop->get(ptr);
 
2138
        else if (fprop->get_ex)
 
2139
                return fprop->get_ex(ptr, prop);
2064
2140
        else
2065
2141
                return fprop->defaultvalue;
2066
2142
}
2067
2143
 
2068
2144
void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value)
2069
2145
{
2070
 
        FloatPropertyRNA *fprop = (FloatPropertyRNA*)prop;
 
2146
        FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
2071
2147
        IDProperty *idprop;
2072
2148
 
2073
2149
        BLI_assert(RNA_property_type(prop) == PROP_FLOAT);
2086
2162
        else if (fprop->set) {
2087
2163
                fprop->set(ptr, value);
2088
2164
        }
 
2165
        else if (fprop->set_ex) {
 
2166
                fprop->set_ex(ptr, prop, value);
 
2167
        }
2089
2168
        else if (prop->flag & PROP_EDITABLE) {
2090
2169
                IDPropertyTemplate val = {0};
2091
2170
                IDProperty *group;
2092
2171
 
 
2172
                RNA_property_float_clamp(ptr, prop, &value);
 
2173
 
2093
2174
                val.f = value;
2094
2175
 
2095
2176
                group = RNA_struct_idprops(ptr, 1);
2100
2181
 
2101
2182
void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
2102
2183
{
2103
 
        FloatPropertyRNA *fprop = (FloatPropertyRNA*)prop;
 
2184
        FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
2104
2185
        IDProperty *idprop;
2105
2186
        int i;
2106
2187
 
2111
2192
                if (prop->arraydimension == 0)
2112
2193
                        values[0] = RNA_property_float_get(ptr, prop);
2113
2194
                else if (idprop->subtype == IDP_FLOAT) {
2114
 
                        memcpy(values, IDP_Array(idprop), sizeof(float)*idprop->len);
 
2195
                        memcpy(values, IDP_Array(idprop), sizeof(float) * idprop->len);
2115
2196
                }
2116
2197
                else {
2117
 
                        for (i = 0; i<idprop->len; i++)
2118
 
                                values[i] =  (float)(((double*)IDP_Array(idprop))[i]);
 
2198
                        for (i = 0; i < idprop->len; i++)
 
2199
                                values[i] =  (float)(((double *)IDP_Array(idprop))[i]);
2119
2200
                }
2120
2201
        }
2121
2202
        else if (prop->arraydimension == 0)
2122
2203
                values[0] = RNA_property_float_get(ptr, prop);
2123
2204
        else if (fprop->getarray)
2124
2205
                fprop->getarray(ptr, values);
 
2206
        else if (fprop->getarray_ex)
 
2207
                fprop->getarray_ex(ptr, prop, values);
2125
2208
        else if (fprop->defaultarray)
2126
 
                memcpy(values, fprop->defaultarray, sizeof(float)*prop->totarraylength);
 
2209
                memcpy(values, fprop->defaultarray, sizeof(float) * prop->totarraylength);
2127
2210
        else
2128
 
                memset(values, 0, sizeof(float)*prop->totarraylength);
 
2211
                memset(values, 0, sizeof(float) * prop->totarraylength);
2129
2212
}
2130
2213
 
2131
2214
void RNA_property_float_get_array_range(PointerRNA *ptr, PropertyRNA *prop, float values[2])
2180
2263
        else {
2181
2264
                float *tmparray, value;
2182
2265
 
2183
 
                tmparray = MEM_callocN(sizeof(float)*len, "RNA_property_float_get_index");
 
2266
                tmparray = MEM_callocN(sizeof(float) * len, "RNA_property_float_get_index");
2184
2267
                RNA_property_float_get_array(ptr, prop, tmparray);
2185
2268
                value = tmparray[index];
2186
2269
                MEM_freeN(tmparray);
2192
2275
 
2193
2276
void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const float *values)
2194
2277
{
2195
 
        FloatPropertyRNA *fprop = (FloatPropertyRNA*)prop;
 
2278
        FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
2196
2279
        IDProperty *idprop;
2197
2280
        int i;
2198
2281
 
2207
2290
                                IDP_Double(idprop) = values[0];
2208
2291
                }
2209
2292
                else if (idprop->subtype == IDP_FLOAT) {
2210
 
                        memcpy(IDP_Array(idprop), values, sizeof(float)*idprop->len);
 
2293
                        memcpy(IDP_Array(idprop), values, sizeof(float) * idprop->len);
2211
2294
                }
2212
2295
                else {
2213
 
                        for (i = 0; i<idprop->len; i++)
2214
 
                                ((double*)IDP_Array(idprop))[i] = values[i];
 
2296
                        for (i = 0; i < idprop->len; i++)
 
2297
                                ((double *)IDP_Array(idprop))[i] = values[i];
2215
2298
                }
2216
2299
 
2217
2300
                rna_idproperty_touch(idprop);
2221
2304
        else if (fprop->setarray) {
2222
2305
                fprop->setarray(ptr, values);
2223
2306
        }
 
2307
        else if (fprop->setarray_ex) {
 
2308
                fprop->setarray_ex(ptr, prop, values);
 
2309
        }
2224
2310
        else if (prop->flag & PROP_EDITABLE) {
2225
2311
                IDPropertyTemplate val = {0};
2226
2312
                IDProperty *group;
2227
2313
 
 
2314
                /* TODO: RNA_property_float_clamp_array(ptr, prop, &value); */
 
2315
 
2228
2316
                val.array.len = prop->totarraylength;
2229
2317
                val.array.type = IDP_FLOAT;
2230
2318
 
2232
2320
                if (group) {
2233
2321
                        idprop = IDP_New(IDP_ARRAY, &val, prop->identifier);
2234
2322
                        IDP_AddToGroup(group, idprop);
2235
 
                        memcpy(IDP_Array(idprop), values, sizeof(float)*idprop->len);
 
2323
                        memcpy(IDP_Array(idprop), values, sizeof(float) * idprop->len);
2236
2324
                }
2237
2325
        }
2238
2326
}
2253
2341
        else {
2254
2342
                float *tmparray;
2255
2343
 
2256
 
                tmparray = MEM_callocN(sizeof(float)*len, "RNA_property_float_get_index");
 
2344
                tmparray = MEM_callocN(sizeof(float) * len, "RNA_property_float_get_index");
2257
2345
                RNA_property_float_get_array(ptr, prop, tmparray);
2258
2346
                tmparray[index] = value;
2259
2347
                RNA_property_float_set_array(ptr, prop, tmparray);
2263
2351
 
2264
2352
float RNA_property_float_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
2265
2353
{
2266
 
        FloatPropertyRNA *fprop = (FloatPropertyRNA*)prop;
 
2354
        FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
2267
2355
 
2268
2356
        BLI_assert(RNA_property_type(prop) == PROP_FLOAT);
2269
2357
        BLI_assert(RNA_property_array_check(prop) == 0);
2273
2361
 
2274
2362
void RNA_property_float_get_default_array(PointerRNA *UNUSED(ptr), PropertyRNA *prop, float *values)
2275
2363
{
2276
 
        FloatPropertyRNA *fprop = (FloatPropertyRNA*)prop;
 
2364
        FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
2277
2365
        
2278
2366
        BLI_assert(RNA_property_type(prop) == PROP_FLOAT);
2279
2367
        BLI_assert(RNA_property_array_check(prop) != 0);
2281
2369
        if (prop->arraydimension == 0)
2282
2370
                values[0] = fprop->defaultvalue;
2283
2371
        else if (fprop->defaultarray)
2284
 
                memcpy(values, fprop->defaultarray, sizeof(float)*prop->totarraylength);
 
2372
                memcpy(values, fprop->defaultarray, sizeof(float) * prop->totarraylength);
2285
2373
        else
2286
 
                memset(values, 0, sizeof(float)*prop->totarraylength);
 
2374
                memset(values, 0, sizeof(float) * prop->totarraylength);
2287
2375
}
2288
2376
 
2289
2377
float RNA_property_float_get_default_index(PointerRNA *ptr, PropertyRNA *prop, int index)
2301
2389
        else {
2302
2390
                float *tmparray, value;
2303
2391
 
2304
 
                tmparray = MEM_callocN(sizeof(float)*len, "RNA_property_float_get_default_index");
 
2392
                tmparray = MEM_callocN(sizeof(float) * len, "RNA_property_float_get_default_index");
2305
2393
                RNA_property_float_get_default_array(ptr, prop, tmparray);
2306
2394
                value = tmparray[index];
2307
2395
                MEM_freeN(tmparray);
2312
2400
 
2313
2401
void RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop, char *value)
2314
2402
{
2315
 
        StringPropertyRNA *sprop = (StringPropertyRNA*)prop;
 
2403
        StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
2316
2404
        IDProperty *idprop;
2317
2405
 
2318
2406
        BLI_assert(RNA_property_type(prop) == PROP_STRING);
2331
2419
        else if (sprop->get) {
2332
2420
                sprop->get(ptr, value);
2333
2421
        }
 
2422
        else if (sprop->get_ex) {
 
2423
                sprop->get_ex(ptr, prop, value);
 
2424
        }
2334
2425
        else {
2335
2426
                strcpy(value, sprop->defaultvalue);
2336
2427
        }
2346
2437
 
2347
2438
        length = RNA_property_string_length(ptr, prop);
2348
2439
 
2349
 
        if (length+1 < fixedlen)
 
2440
        if (length + 1 < fixedlen)
2350
2441
                buf = fixedbuf;
2351
2442
        else
2352
 
                buf = MEM_mallocN(sizeof(char)*(length+1), "RNA_string_get_alloc");
 
2443
                buf = MEM_mallocN(sizeof(char) * (length + 1), "RNA_string_get_alloc");
2353
2444
 
2354
2445
#ifndef NDEBUG
2355
2446
        /* safety check to ensure the string is actually set */
2372
2463
/* this is the length without \0 terminator */
2373
2464
int RNA_property_string_length(PointerRNA *ptr, PropertyRNA *prop)
2374
2465
{
2375
 
        StringPropertyRNA *sprop = (StringPropertyRNA*)prop;
 
2466
        StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
2376
2467
        IDProperty *idprop;
2377
2468
 
2378
2469
        BLI_assert(RNA_property_type(prop) == PROP_STRING);
2391
2482
        }
2392
2483
        else if (sprop->length)
2393
2484
                return sprop->length(ptr);
 
2485
        else if (sprop->length_ex)
 
2486
                return sprop->length_ex(ptr, prop);
2394
2487
        else
2395
2488
                return strlen(sprop->defaultvalue);
2396
2489
}
2397
2490
 
2398
2491
void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *value)
2399
2492
{
2400
 
        StringPropertyRNA *sprop = (StringPropertyRNA*)prop;
 
2493
        StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
2401
2494
        IDProperty *idprop;
2402
2495
 
2403
2496
        BLI_assert(RNA_property_type(prop) == PROP_STRING);
2408
2501
                rna_idproperty_touch(idprop);
2409
2502
        }
2410
2503
        else if (sprop->set)
2411
 
                sprop->set(ptr, value); /* set function needs to clamp its self */
 
2504
                sprop->set(ptr, value);  /* set function needs to clamp its self */
 
2505
        else if (sprop->set_ex)
 
2506
                sprop->set_ex(ptr, prop, value);  /* set function needs to clamp its self */
2412
2507
        else if (prop->flag & PROP_EDITABLE) {
2413
2508
                IDProperty *group;
2414
2509
 
2420
2515
 
2421
2516
void RNA_property_string_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop, char *value)
2422
2517
{
2423
 
        StringPropertyRNA *sprop = (StringPropertyRNA*)prop;
 
2518
        StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
2424
2519
 
2425
2520
        BLI_assert(RNA_property_type(prop) == PROP_STRING);
2426
2521
 
2436
2531
 
2437
2532
        length = RNA_property_string_default_length(ptr, prop);
2438
2533
 
2439
 
        if (length+1 < fixedlen)
 
2534
        if (length + 1 < fixedlen)
2440
2535
                buf = fixedbuf;
2441
2536
        else
2442
 
                buf = MEM_callocN(sizeof(char)*(length+1), "RNA_string_get_alloc");
 
2537
                buf = MEM_callocN(sizeof(char) * (length + 1), "RNA_string_get_alloc");
2443
2538
 
2444
2539
        RNA_property_string_get_default(ptr, prop, buf);
2445
2540
 
2449
2544
/* this is the length without \0 terminator */
2450
2545
int RNA_property_string_default_length(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
2451
2546
{
2452
 
        StringPropertyRNA *sprop = (StringPropertyRNA*)prop;
 
2547
        StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
2453
2548
 
2454
2549
        BLI_assert(RNA_property_type(prop) == PROP_STRING);
2455
2550
 
2458
2553
 
2459
2554
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
2460
2555
{
2461
 
        EnumPropertyRNA *eprop = (EnumPropertyRNA*)prop;
 
2556
        EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
2462
2557
        IDProperty *idprop;
2463
2558
 
2464
2559
        BLI_assert(RNA_property_type(prop) == PROP_ENUM);
2467
2562
                return IDP_Int(idprop);
2468
2563
        else if (eprop->get)
2469
2564
                return eprop->get(ptr);
 
2565
        else if (eprop->get_ex)
 
2566
                return eprop->get_ex(ptr, prop);
2470
2567
        else
2471
2568
                return eprop->defaultvalue;
2472
2569
}
2473
2570
 
2474
2571
void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value)
2475
2572
{
2476
 
        EnumPropertyRNA *eprop = (EnumPropertyRNA*)prop;
 
2573
        EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
2477
2574
        IDProperty *idprop;
2478
2575
 
2479
2576
        BLI_assert(RNA_property_type(prop) == PROP_ENUM);
2485
2582
        else if (eprop->set) {
2486
2583
                eprop->set(ptr, value);
2487
2584
        }
 
2585
        else if (eprop->set_ex) {
 
2586
                eprop->set_ex(ptr, prop, value);
 
2587
        }
2488
2588
        else if (prop->flag & PROP_EDITABLE) {
2489
2589
                IDPropertyTemplate val = {0};
2490
2590
                IDProperty *group;
2499
2599
 
2500
2600
int RNA_property_enum_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
2501
2601
{
2502
 
        EnumPropertyRNA *eprop = (EnumPropertyRNA*)prop;
 
2602
        EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
2503
2603
 
2504
2604
        BLI_assert(RNA_property_type(prop) == PROP_ENUM);
2505
2605
 
2508
2608
 
2509
2609
void *RNA_property_enum_py_data_get(PropertyRNA *prop)
2510
2610
{
2511
 
        EnumPropertyRNA *eprop = (EnumPropertyRNA*)prop;
 
2611
        EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
2512
2612
 
2513
2613
        BLI_assert(RNA_property_type(prop) == PROP_ENUM);
2514
2614
 
2517
2617
 
2518
2618
PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop)
2519
2619
{
2520
 
        PointerPropertyRNA *pprop = (PointerPropertyRNA*)prop;
 
2620
        PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
2521
2621
        IDProperty *idprop;
2522
2622
 
2523
2623
        BLI_assert(RNA_property_type(prop) == PROP_POINTER);
2524
2624
 
2525
2625
        if ((idprop = rna_idproperty_check(&prop, ptr))) {
2526
 
                pprop = (PointerPropertyRNA*)prop;
 
2626
                pprop = (PointerPropertyRNA *)prop;
2527
2627
 
2528
2628
                /* for groups, data is idprop itself */
2529
 
                return rna_pointer_inherit_refine(ptr, pprop->type, idprop);
 
2629
                if (pprop->typef)
 
2630
                        return rna_pointer_inherit_refine(ptr, pprop->typef(ptr), idprop);
 
2631
                else
 
2632
                        return rna_pointer_inherit_refine(ptr, pprop->type, idprop);
2530
2633
        }
2531
2634
        else if (pprop->get) {
2532
2635
                return pprop->get(ptr);
2548
2651
 
2549
2652
        BLI_assert(RNA_property_type(prop) == PROP_POINTER);
2550
2653
 
2551
 
        if ((/*idprop=*/ rna_idproperty_check(&prop, ptr))) {
 
2654
        if ((/*idprop = */ rna_idproperty_check(&prop, ptr))) {
2552
2655
                /* not supported */
2553
2656
                /* rna_idproperty_touch(idprop); */
2554
2657
        }
2555
2658
        else {
2556
 
                PointerPropertyRNA *pprop = (PointerPropertyRNA*)prop;
 
2659
                PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
2557
2660
 
2558
 
                if (            pprop->set &&
2559
 
                                !((prop->flag & PROP_NEVER_NULL) && ptr_value.data == NULL) &&
2560
 
                                !((prop->flag & PROP_ID_SELF_CHECK) && ptr->id.data == ptr_value.id.data)
2561
 
                ) {
 
2661
                if (pprop->set &&
 
2662
                    !((prop->flag & PROP_NEVER_NULL) && ptr_value.data == NULL) &&
 
2663
                    !((prop->flag & PROP_ID_SELF_CHECK) && ptr->id.data == ptr_value.id.data))
 
2664
                {
2562
2665
                        pprop->set(ptr, ptr_value);
2563
2666
                }
2564
2667
        }
2566
2669
 
2567
2670
PointerRNA RNA_property_pointer_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop))
2568
2671
{
2569
 
        /*PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop; */
 
2672
        /*PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop; */
2570
2673
 
2571
2674
        /* BLI_assert(RNA_property_type(prop) == PROP_POINTER); */
2572
2675
 
2579
2682
 
2580
2683
        BLI_assert(RNA_property_type(prop) == PROP_POINTER);
2581
2684
 
2582
 
        if ((/*idprop=*/rna_idproperty_check(&prop, ptr))) {
 
2685
        if ((/*idprop=*/ rna_idproperty_check(&prop, ptr))) {
2583
2686
                /* already exists */
2584
2687
        }
2585
2688
        else if (prop->flag & PROP_IDPROPERTY) {
2617
2720
 
2618
2721
static void rna_property_collection_get_idp(CollectionPropertyIterator *iter)
2619
2722
{
2620
 
        CollectionPropertyRNA *cprop = (CollectionPropertyRNA*)iter->prop;
 
2723
        CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)iter->prop;
2621
2724
 
2622
2725
        iter->ptr.data = rna_iterator_array_get(iter);
2623
2726
        iter->ptr.type = cprop->item_type;
2647
2750
                iter->idprop = 1;
2648
2751
        }
2649
2752
        else {
2650
 
                CollectionPropertyRNA *cprop = (CollectionPropertyRNA*)prop;
 
2753
                CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop;
2651
2754
                cprop->begin(iter, ptr);
2652
2755
        }
2653
2756
}
2654
2757
 
2655
2758
void RNA_property_collection_next(CollectionPropertyIterator *iter)
2656
2759
{
2657
 
        CollectionPropertyRNA *cprop = (CollectionPropertyRNA*)rna_ensure_property(iter->prop);
 
2760
        CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)rna_ensure_property(iter->prop);
2658
2761
 
2659
2762
        if (iter->idprop) {
2660
2763
                rna_iterator_array_next(iter);
2668
2771
 
2669
2772
void RNA_property_collection_end(CollectionPropertyIterator *iter)
2670
2773
{
2671
 
        CollectionPropertyRNA *cprop = (CollectionPropertyRNA*)rna_ensure_property(iter->prop);
 
2774
        CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)rna_ensure_property(iter->prop);
2672
2775
 
2673
2776
        if (iter->idprop)
2674
2777
                rna_iterator_array_end(iter);
2678
2781
 
2679
2782
int RNA_property_collection_length(PointerRNA *ptr, PropertyRNA *prop)
2680
2783
{
2681
 
        CollectionPropertyRNA *cprop = (CollectionPropertyRNA*)prop;
 
2784
        CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop;
2682
2785
        IDProperty *idprop;
2683
2786
 
2684
2787
        BLI_assert(RNA_property_type(prop) == PROP_COLLECTION);
2705
2808
void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *r_ptr)
2706
2809
{
2707
2810
        IDProperty *idprop;
2708
 
/*      CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; */
 
2811
/*      CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop; */
2709
2812
 
2710
2813
        BLI_assert(RNA_property_type(prop) == PROP_COLLECTION);
2711
2814
 
2745
2848
                }
2746
2849
        }
2747
2850
        /*else
2748
 
                printf("%s %s.%s: not implemented for this property.\n", __func__, ptr->type->identifier, prop->identifier);*/
 
2851
            printf("%s %s.%s: not implemented for this property.\n", __func__, ptr->type->identifier, prop->identifier);*/
2749
2852
#endif
2750
2853
 
2751
2854
        if (r_ptr) {
2752
2855
                if (idprop) {
2753
 
                        CollectionPropertyRNA *cprop = (CollectionPropertyRNA*)prop;
 
2856
                        CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop;
2754
2857
 
2755
 
                        r_ptr->data = IDP_GetIndexArray(idprop, idprop->len-1);
 
2858
                        r_ptr->data = IDP_GetIndexArray(idprop, idprop->len - 1);
2756
2859
                        r_ptr->type = cprop->item_type;
2757
2860
                        rna_pointer_inherit_id(NULL, ptr, r_ptr);
2758
2861
                }
2764
2867
int RNA_property_collection_remove(PointerRNA *ptr, PropertyRNA *prop, int key)
2765
2868
{
2766
2869
        IDProperty *idprop;
2767
 
/*      CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; */
 
2870
/*      CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop; */
2768
2871
 
2769
2872
        BLI_assert(RNA_property_type(prop) == PROP_COLLECTION);
2770
2873
 
2776
2879
                array = IDP_IDPArray(idprop);
2777
2880
 
2778
2881
                if (key >= 0 && key < len) {
2779
 
                        if (key+1 < len) {
 
2882
                        if (key + 1 < len) {
2780
2883
                                /* move element to be removed to the back */
2781
2884
                                memcpy(&tmp, &array[key], sizeof(IDProperty));
2782
 
                                memmove(array+key, array+key+1, sizeof(IDProperty)*(len-(key+1)));
2783
 
                                memcpy(&array[len-1], &tmp, sizeof(IDProperty));
 
2885
                                memmove(array + key, array + key + 1, sizeof(IDProperty) * (len - (key + 1)));
 
2886
                                memcpy(&array[len - 1], &tmp, sizeof(IDProperty));
2784
2887
                        }
2785
2888
 
2786
 
                        IDP_ResizeIDPArray(idprop, len-1);
 
2889
                        IDP_ResizeIDPArray(idprop, len - 1);
2787
2890
                }
2788
2891
 
2789
2892
                return 1;
2804
2907
                return 0;
2805
2908
        }
2806
2909
        /*else
2807
 
                printf("%s %s.%s: only supported for id properties.\n", __func__, ptr->type->identifier, prop->identifier);*/
 
2910
            printf("%s %s.%s: only supported for id properties.\n", __func__, ptr->type->identifier, prop->identifier);*/
2808
2911
#endif
2809
2912
        return 0;
2810
2913
}
2825
2928
                if (key >= 0 && key < len && pos >= 0 && pos < len && key != pos) {
2826
2929
                        memcpy(&tmp, &array[key], sizeof(IDProperty));
2827
2930
                        if (pos < key)
2828
 
                                memmove(array+pos+1, array+pos, sizeof(IDProperty)*(key - pos));
 
2931
                                memmove(array + pos + 1, array + pos, sizeof(IDProperty) * (key - pos));
2829
2932
                        else
2830
 
                                memmove(array+key, array+key+1, sizeof(IDProperty)*(pos - key));
 
2933
                                memmove(array + key, array + key + 1, sizeof(IDProperty) * (pos - key));
2831
2934
                        memcpy(&array[pos], &tmp, sizeof(IDProperty));
2832
2935
                }
2833
2936
 
2872
2975
 
2873
2976
int RNA_property_collection_lookup_int(PointerRNA *ptr, PropertyRNA *prop, int key, PointerRNA *r_ptr)
2874
2977
{
2875
 
        CollectionPropertyRNA *cprop = (CollectionPropertyRNA*)rna_ensure_property(prop);
 
2978
        CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)rna_ensure_property(prop);
2876
2979
 
2877
2980
        BLI_assert(RNA_property_type(prop) == PROP_COLLECTION);
2878
2981
 
2903
3006
 
2904
3007
int RNA_property_collection_lookup_string(PointerRNA *ptr, PropertyRNA *prop, const char *key, PointerRNA *r_ptr)
2905
3008
{
2906
 
        CollectionPropertyRNA *cprop = (CollectionPropertyRNA*)rna_ensure_property(prop);
 
3009
        CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)rna_ensure_property(prop);
2907
3010
 
2908
3011
        BLI_assert(RNA_property_type(prop) == PROP_COLLECTION);
2909
3012
 
2951
3054
/* zero return is an assignment error */
2952
3055
int RNA_property_collection_assign_int(PointerRNA *ptr, PropertyRNA *prop, const int key, const PointerRNA *assign_ptr)
2953
3056
{
2954
 
        CollectionPropertyRNA *cprop = (CollectionPropertyRNA*)rna_ensure_property(prop);
 
3057
        CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)rna_ensure_property(prop);
2955
3058
 
2956
3059
        BLI_assert(RNA_property_type(prop) == PROP_COLLECTION);
2957
3060
 
2968
3071
        BLI_assert(RNA_property_type(prop) == PROP_COLLECTION);
2969
3072
 
2970
3073
        *r_ptr = *ptr;
2971
 
        return ((r_ptr->type = rna_ensure_property(prop)->srna) ? 1:0);
 
3074
        return ((r_ptr->type = rna_ensure_property(prop)->srna) ? 1 : 0);
2972
3075
}
2973
3076
 
2974
3077
int RNA_property_collection_raw_array(PointerRNA *ptr, PropertyRNA *prop, PropertyRNA *itemprop, RawArray *array)
2987
3090
        if (iter.valid) {
2988
3091
                /* get data from array iterator and item property */
2989
3092
                internal = iter.internal;
2990
 
                arrayp = (iter.valid)? iter.ptr.data: NULL;
 
3093
                arrayp = (iter.valid) ? iter.ptr.data : NULL;
2991
3094
 
2992
3095
                if (internal->skip || !RNA_property_editable(&iter.ptr, itemprop)) {
2993
3096
                        /* we might skip some items, so it's not a proper array */
2997
3100
 
2998
3101
                array->array = arrayp + itemprop->rawoffset;
2999
3102
                array->stride = internal->itemsize;
3000
 
                array->len = ((char*)internal->endptr - arrayp)/internal->itemsize;
 
3103
                array->len = ((char *)internal->endptr - arrayp) / internal->itemsize;
3001
3104
                array->type = itemprop->rawtype;
3002
3105
        }
3003
3106
        else
3011
3114
#define RAW_GET(dtype, var, raw, a)                                           \
3012
3115
{                                                                             \
3013
3116
        switch (raw.type) {                                                       \
3014
 
                case PROP_RAW_CHAR: var = (dtype)((char*)raw.array)[a]; break;        \
3015
 
                case PROP_RAW_SHORT: var = (dtype)((short*)raw.array)[a]; break;      \
3016
 
                case PROP_RAW_INT: var = (dtype)((int*)raw.array)[a]; break;          \
3017
 
                case PROP_RAW_FLOAT: var = (dtype)((float*)raw.array)[a]; break;      \
3018
 
                case PROP_RAW_DOUBLE: var = (dtype)((double*)raw.array)[a]; break;    \
 
3117
                case PROP_RAW_CHAR: var = (dtype)((char *)raw.array)[a]; break;       \
 
3118
                case PROP_RAW_SHORT: var = (dtype)((short *)raw.array)[a]; break;     \
 
3119
                case PROP_RAW_INT: var = (dtype)((int *)raw.array)[a]; break;         \
 
3120
                case PROP_RAW_FLOAT: var = (dtype)((float *)raw.array)[a]; break;     \
 
3121
                case PROP_RAW_DOUBLE: var = (dtype)((double *)raw.array)[a]; break;   \
3019
3122
                default: var = (dtype)0;                                              \
3020
3123
        }                                                                         \
3021
 
}
 
3124
} (void)0
3022
3125
 
3023
3126
#define RAW_SET(dtype, raw, a, var)                                           \
3024
3127
{                                                                             \
3025
3128
        switch (raw.type) {                                                       \
3026
 
                case PROP_RAW_CHAR: ((char*)raw.array)[a] = (char)var; break;         \
3027
 
                case PROP_RAW_SHORT: ((short*)raw.array)[a] = (short)var; break;      \
3028
 
                case PROP_RAW_INT: ((int*)raw.array)[a] = (int)var; break;            \
3029
 
                case PROP_RAW_FLOAT: ((float*)raw.array)[a] = (float)var; break;      \
3030
 
                case PROP_RAW_DOUBLE: ((double*)raw.array)[a] = (double)var; break;   \
 
3129
                case PROP_RAW_CHAR: ((char *)raw.array)[a] = (char)var; break;        \
 
3130
                case PROP_RAW_SHORT: ((short *)raw.array)[a] = (short)var; break;     \
 
3131
                case PROP_RAW_INT: ((int *)raw.array)[a] = (int)var; break;           \
 
3132
                case PROP_RAW_FLOAT: ((float *)raw.array)[a] = (float)var; break;     \
 
3133
                case PROP_RAW_DOUBLE: ((double *)raw.array)[a] = (double)var; break;  \
3031
3134
                default: break;                                                       \
3032
3135
        }                                                                         \
3033
 
}
 
3136
} (void)0
3034
3137
 
3035
3138
int RNA_raw_type_sizeof(RawPropertyType type)
3036
3139
{
3044
3147
        }
3045
3148
}
3046
3149
 
 
3150
static int rna_property_array_length_all_dimensions(PointerRNA *ptr, PropertyRNA *prop)
 
3151
{
 
3152
        int i, len[RNA_MAX_ARRAY_DIMENSION];
 
3153
        const int dim = RNA_property_array_dimension(ptr, prop, len);
 
3154
        int size;
 
3155
 
 
3156
        if (dim == 0)
 
3157
                return 0;
 
3158
 
 
3159
        for (size = 1, i = 0; i < dim; i++)
 
3160
                size *= len[i];
 
3161
        
 
3162
        return size;
 
3163
}
 
3164
 
3047
3165
static int rna_raw_access(ReportList *reports, PointerRNA *ptr, PropertyRNA *prop, const char *propname,
3048
3166
                          void *inarray, RawPropertyType intype, int inlen, int set)
3049
3167
{
3081
3199
                /* check item array */
3082
3200
                itemlen = RNA_property_array_length(&itemptr, itemprop);
3083
3201
 
 
3202
                /* dynamic array? need to get length per item */
 
3203
                if (itemprop->getlength) {
 
3204
                        itemprop = NULL;
 
3205
                }
3084
3206
                /* try to access as raw array */
3085
 
                if (RNA_property_collection_raw_array(ptr, prop, itemprop, &out)) {
 
3207
                else if (RNA_property_collection_raw_array(ptr, prop, itemprop, &out)) {
3086
3208
                        int arraylen = (itemlen == 0) ? 1 : itemlen;
3087
 
                        if (in.len != arraylen*out.len) {
 
3209
                        if (in.len != arraylen * out.len) {
3088
3210
                                BKE_reportf(reports, RPT_ERROR, "Array length mismatch (expected %d, got %d)",
3089
3211
                                            out.len * arraylen, in.len);
3090
3212
                                return 0;
3098
3220
 
3099
3221
                                size = RNA_raw_type_sizeof(out.type) * arraylen;
3100
3222
 
3101
 
                                for (a = 0; a<out.len; a++) {
 
3223
                                for (a = 0; a < out.len; a++) {
3102
3224
                                        if (set) memcpy(outp, inp, size);
3103
3225
                                        else memcpy(inp, outp, size);
3104
3226
 
3105
 
                                        inp = (char*)inp + size;
3106
 
                                        outp = (char*)outp + out.stride;
 
3227
                                        inp = (char *)inp + size;
 
3228
                                        outp = (char *)outp + out.stride;
3107
3229
                                }
3108
3230
 
3109
3231
                                return 1;
3121
3243
                int needconv = 1;
3122
3244
 
3123
3245
                if (((itemtype == PROP_BOOLEAN || itemtype == PROP_INT) && in.type == PROP_RAW_INT) ||
3124
 
                        (itemtype == PROP_FLOAT && in.type == PROP_RAW_FLOAT))
 
3246
                    (itemtype == PROP_FLOAT && in.type == PROP_RAW_FLOAT))
 
3247
                {
3125
3248
                        /* avoid creating temporary buffer if the data type match */
3126
3249
                        needconv = 0;
3127
 
 
 
3250
                }
3128
3251
                /* no item property pointer, can still be id property, or
3129
3252
                 * property of a type derived from the collection pointer type */
3130
 
                RNA_PROP_BEGIN(ptr, itemptr, prop) {
 
3253
                RNA_PROP_BEGIN(ptr, itemptr, prop)
 
3254
                {
3131
3255
                        if (itemptr.data) {
3132
3256
                                if (itemprop) {
3133
3257
                                        /* we got the property already */
3138
3262
                                        iprop = RNA_struct_find_property(&itemptr, propname);
3139
3263
 
3140
3264
                                        if (iprop) {
3141
 
                                                itemlen = RNA_property_array_length(&itemptr, iprop);
 
3265
                                                itemlen = rna_property_array_length_all_dimensions(&itemptr, iprop);
3142
3266
                                                itemtype = RNA_property_type(iprop);
3143
3267
                                        }
3144
3268
                                        else {
3145
 
                                                BKE_reportf(reports, RPT_ERROR, "Property named %s not found", propname);
 
3269
                                                BKE_reportf(reports, RPT_ERROR, "Property named '%s' not found", propname);
3146
3270
                                                err = 1;
3147
3271
                                                break;
3148
3272
                                        }
3156
3280
 
3157
3281
                                /* editable check */
3158
3282
                                if (!set || RNA_property_editable(&itemptr, iprop)) {
3159
 
                                        if (a+itemlen > in.len) {
 
3283
                                        if (a + itemlen > in.len) {
3160
3284
                                                BKE_reportf(reports, RPT_ERROR, "Array length mismatch (got %d, expected more)", in.len);
3161
3285
                                                err = 1;
3162
3286
                                                break;
3166
3290
                                                /* handle conversions */
3167
3291
                                                if (set) {
3168
3292
                                                        switch (itemtype) {
3169
 
                                                                case PROP_BOOLEAN: {
 
3293
                                                                case PROP_BOOLEAN:
 
3294
                                                                {
3170
3295
                                                                        int b;
3171
3296
                                                                        RAW_GET(int, b, in, a);
3172
3297
                                                                        RNA_property_boolean_set(&itemptr, iprop, b);
3173
3298
                                                                        break;
3174
3299
                                                                }
3175
 
                                                                case PROP_INT: {
 
3300
                                                                case PROP_INT:
 
3301
                                                                {
3176
3302
                                                                        int i;
3177
3303
                                                                        RAW_GET(int, i, in, a);
3178
3304
                                                                        RNA_property_int_set(&itemptr, iprop, i);
3179
3305
                                                                        break;
3180
3306
                                                                }
3181
 
                                                                case PROP_FLOAT: {
 
3307
                                                                case PROP_FLOAT:
 
3308
                                                                {
3182
3309
                                                                        float f;
3183
3310
                                                                        RAW_GET(float, f, in, a);
3184
3311
                                                                        RNA_property_float_set(&itemptr, iprop, f);
3190
3317
                                                }
3191
3318
                                                else {
3192
3319
                                                        switch (itemtype) {
3193
 
                                                                case PROP_BOOLEAN: {
 
3320
                                                                case PROP_BOOLEAN:
 
3321
                                                                {
3194
3322
                                                                        int b = RNA_property_boolean_get(&itemptr, iprop);
3195
3323
                                                                        RAW_SET(int, in, a, b);
3196
3324
                                                                        break;
3197
3325
                                                                }
3198
 
                                                                case PROP_INT: {
 
3326
                                                                case PROP_INT:
 
3327
                                                                {
3199
3328
                                                                        int i = RNA_property_int_get(&itemptr, iprop);
3200
3329
                                                                        RAW_SET(int, in, a, i);
3201
3330
                                                                        break;
3202
3331
                                                                }
3203
 
                                                                case PROP_FLOAT: {
 
3332
                                                                case PROP_FLOAT:
 
3333
                                                                {
3204
3334
                                                                        float f = RNA_property_float_get(&itemptr, iprop);
3205
3335
                                                                        RAW_SET(float, in, a, f);
3206
3336
                                                                        break;
3218
3348
                                                        tmparray = NULL;
3219
3349
                                                }
3220
3350
                                                if (!tmparray) {
3221
 
                                                        tmparray = MEM_callocN(sizeof(float)*itemlen, "RNA tmparray\n");
 
3351
                                                        tmparray = MEM_callocN(sizeof(float) * itemlen, "RNA tmparray\n");
3222
3352
                                                        tmplen = itemlen;
3223
3353
                                                }
3224
3354
 
3225
3355
                                                /* handle conversions */
3226
3356
                                                if (set) {
3227
3357
                                                        switch (itemtype) {
3228
 
                                                                case PROP_BOOLEAN: {
3229
 
                                                                        for (j = 0; j<itemlen; j++, a++)
3230
 
                                                                                RAW_GET(int, ((int*)tmparray)[j], in, a);
 
3358
                                                                case PROP_BOOLEAN:
 
3359
                                                                {
 
3360
                                                                        for (j = 0; j < itemlen; j++, a++)
 
3361
                                                                                RAW_GET(int, ((int *)tmparray)[j], in, a);
3231
3362
                                                                        RNA_property_boolean_set_array(&itemptr, iprop, tmparray);
3232
3363
                                                                        break;
3233
3364
                                                                }
3234
 
                                                                case PROP_INT: {
3235
 
                                                                        for (j = 0; j<itemlen; j++, a++)
3236
 
                                                                                RAW_GET(int, ((int*)tmparray)[j], in, a);
 
3365
                                                                case PROP_INT:
 
3366
                                                                {
 
3367
                                                                        for (j = 0; j < itemlen; j++, a++)
 
3368
                                                                                RAW_GET(int, ((int *)tmparray)[j], in, a);
3237
3369
                                                                        RNA_property_int_set_array(&itemptr, iprop, tmparray);
3238
3370
                                                                        break;
3239
3371
                                                                }
3240
 
                                                                case PROP_FLOAT: {
3241
 
                                                                        for (j = 0; j<itemlen; j++, a++)
3242
 
                                                                                RAW_GET(float, ((float*)tmparray)[j], in, a);
 
3372
                                                                case PROP_FLOAT:
 
3373
                                                                {
 
3374
                                                                        for (j = 0; j < itemlen; j++, a++)
 
3375
                                                                                RAW_GET(float, ((float *)tmparray)[j], in, a);
3243
3376
                                                                        RNA_property_float_set_array(&itemptr, iprop, tmparray);
3244
3377
                                                                        break;
3245
3378
                                                                }
3249
3382
                                                }
3250
3383
                                                else {
3251
3384
                                                        switch (itemtype) {
3252
 
                                                                case PROP_BOOLEAN: {
 
3385
                                                                case PROP_BOOLEAN:
 
3386
                                                                {
3253
3387
                                                                        RNA_property_boolean_get_array(&itemptr, iprop, tmparray);
3254
 
                                                                        for (j = 0; j<itemlen; j++, a++)
3255
 
                                                                                RAW_SET(int, in, a, ((int*)tmparray)[j]);
 
3388
                                                                        for (j = 0; j < itemlen; j++, a++)
 
3389
                                                                                RAW_SET(int, in, a, ((int *)tmparray)[j]);
3256
3390
                                                                        break;
3257
3391
                                                                }
3258
 
                                                                case PROP_INT: {
 
3392
                                                                case PROP_INT:
 
3393
                                                                {
3259
3394
                                                                        RNA_property_int_get_array(&itemptr, iprop, tmparray);
3260
 
                                                                        for (j = 0; j<itemlen; j++, a++)
3261
 
                                                                                RAW_SET(int, in, a, ((int*)tmparray)[j]);
 
3395
                                                                        for (j = 0; j < itemlen; j++, a++)
 
3396
                                                                                RAW_SET(int, in, a, ((int *)tmparray)[j]);
3262
3397
                                                                        break;
3263
3398
                                                                }
3264
 
                                                                case PROP_FLOAT: {
 
3399
                                                                case PROP_FLOAT:
 
3400
                                                                {
3265
3401
                                                                        RNA_property_float_get_array(&itemptr, iprop, tmparray);
3266
 
                                                                        for (j = 0; j<itemlen; j++, a++)
3267
 
                                                                                RAW_SET(float, in, a, ((float*)tmparray)[j]);
 
3402
                                                                        for (j = 0; j < itemlen; j++, a++)
 
3403
                                                                                RAW_SET(float, in, a, ((float *)tmparray)[j]);
3268
3404
                                                                        break;
3269
3405
                                                                }
3270
3406
                                                                default:
3275
3411
                                        else {
3276
3412
                                                if (set) {
3277
3413
                                                        switch (itemtype) {
3278
 
                                                                case PROP_BOOLEAN: {
3279
 
                                                                        RNA_property_boolean_set_array(&itemptr, iprop, &((int*)in.array)[a]);
3280
 
                                                                        a += itemlen;
3281
 
                                                                        break;
3282
 
                                                                }
3283
 
                                                                case PROP_INT: {
3284
 
                                                                        RNA_property_int_set_array(&itemptr, iprop, &((int*)in.array)[a]);
3285
 
                                                                        a += itemlen;
3286
 
                                                                        break;
3287
 
                                                                }
3288
 
                                                                case PROP_FLOAT: {
3289
 
                                                                        RNA_property_float_set_array(&itemptr, iprop, &((float*)in.array)[a]);
 
3414
                                                                case PROP_BOOLEAN:
 
3415
                                                                {
 
3416
                                                                        RNA_property_boolean_set_array(&itemptr, iprop, &((int *)in.array)[a]);
 
3417
                                                                        a += itemlen;
 
3418
                                                                        break;
 
3419
                                                                }
 
3420
                                                                case PROP_INT:
 
3421
                                                                {
 
3422
                                                                        RNA_property_int_set_array(&itemptr, iprop, &((int *)in.array)[a]);
 
3423
                                                                        a += itemlen;
 
3424
                                                                        break;
 
3425
                                                                }
 
3426
                                                                case PROP_FLOAT:
 
3427
                                                                {
 
3428
                                                                        RNA_property_float_set_array(&itemptr, iprop, &((float *)in.array)[a]);
3290
3429
                                                                        a += itemlen;
3291
3430
                                                                        break;
3292
3431
                                                                }
3296
3435
                                                }
3297
3436
                                                else {
3298
3437
                                                        switch (itemtype) {
3299
 
                                                                case PROP_BOOLEAN: {
3300
 
                                                                        RNA_property_boolean_get_array(&itemptr, iprop, &((int*)in.array)[a]);
3301
 
                                                                        a += itemlen;
3302
 
                                                                        break;
3303
 
                                                                }
3304
 
                                                                case PROP_INT: {
3305
 
                                                                        RNA_property_int_get_array(&itemptr, iprop, &((int*)in.array)[a]);
3306
 
                                                                        a += itemlen;
3307
 
                                                                        break;
3308
 
                                                                }
3309
 
                                                                case PROP_FLOAT: {
3310
 
                                                                        RNA_property_float_get_array(&itemptr, iprop, &((float*)in.array)[a]);
 
3438
                                                                case PROP_BOOLEAN:
 
3439
                                                                {
 
3440
                                                                        RNA_property_boolean_get_array(&itemptr, iprop, &((int *)in.array)[a]);
 
3441
                                                                        a += itemlen;
 
3442
                                                                        break;
 
3443
                                                                }
 
3444
                                                                case PROP_INT:
 
3445
                                                                {
 
3446
                                                                        RNA_property_int_get_array(&itemptr, iprop, &((int *)in.array)[a]);
 
3447
                                                                        a += itemlen;
 
3448
                                                                        break;
 
3449
                                                                }
 
3450
                                                                case PROP_FLOAT:
 
3451
                                                                {
 
3452
                                                                        RNA_property_float_get_array(&itemptr, iprop, &((float *)in.array)[a]);
3311
3453
                                                                        a += itemlen;
3312
3454
                                                                        break;
3313
3455
                                                                }
3333
3475
        if (prop->rawtype == PROP_RAW_UNSET) {
3334
3476
                /* this property has no raw access, yet we try to provide a raw type to help building the array */
3335
3477
                switch (prop->type) {
3336
 
                case PROP_BOOLEAN:
3337
 
                        return PROP_RAW_INT;
3338
 
                case PROP_INT:
3339
 
                        return PROP_RAW_INT;
3340
 
                case PROP_FLOAT:
3341
 
                        return PROP_RAW_FLOAT;
3342
 
                case PROP_ENUM:
3343
 
                        return PROP_RAW_INT;
3344
 
                default:
3345
 
                        break;
 
3478
                        case PROP_BOOLEAN:
 
3479
                                return PROP_RAW_INT;
 
3480
                        case PROP_INT:
 
3481
                                return PROP_RAW_INT;
 
3482
                        case PROP_FLOAT:
 
3483
                                return PROP_RAW_FLOAT;
 
3484
                        case PROP_ENUM:
 
3485
                                return PROP_RAW_INT;
 
3486
                        default:
 
3487
                                break;
3346
3488
                }
3347
3489
        }
3348
3490
        return prop->rawtype;
3367
3509
        ListBaseIterator *internal;
3368
3510
 
3369
3511
        internal = MEM_callocN(sizeof(ListBaseIterator), "ListBaseIterator");
3370
 
        internal->link = (lb)? lb->first: NULL;
 
3512
        internal->link = (lb) ? lb->first : NULL;
3371
3513
        internal->skip = skip;
3372
3514
 
3373
3515
        iter->internal = internal;
3426
3568
 
3427
3569
        internal = MEM_callocN(sizeof(ArrayIterator), "ArrayIterator");
3428
3570
        internal->ptr = ptr;
3429
 
        internal->free_ptr = free_ptr ? ptr:NULL;
3430
 
        internal->endptr = ((char*)ptr)+length*itemsize;
 
3571
        internal->free_ptr = free_ptr ? ptr : NULL;
 
3572
        internal->endptr = ((char *)ptr) + length * itemsize;
3431
3573
        internal->itemsize = itemsize;
3432
3574
        internal->skip = skip;
3433
3575
        internal->length = length;
3467
3609
        ArrayIterator *internal = iter->internal;
3468
3610
 
3469
3611
        /* for ** arrays */
3470
 
        return *(void**)(internal->ptr);
 
3612
        return *(void **)(internal->ptr);
3471
3613
}
3472
3614
 
3473
3615
void rna_iterator_array_end(CollectionPropertyIterator *iter)
3487
3629
        if (index < 0 || index >= length)
3488
3630
                return PointerRNA_NULL;
3489
3631
 
3490
 
        return rna_pointer_inherit_refine(ptr, type, ((char*)data) + index*itemsize);
 
3632
        return rna_pointer_inherit_refine(ptr, type, ((char *)data) + index * itemsize);
3491
3633
}
3492
3634
 
3493
3635
/* RNA Path - Experiment */
3553
3695
                return NULL;
3554
3696
        
3555
3697
        /* try to use fixed buffer if possible */
3556
 
        if (len+1 < fixedlen)
 
3698
        if (len + 1 < fixedlen)
3557
3699
                buf = fixedbuf;
3558
3700
        else
3559
 
                buf = MEM_callocN(sizeof(char)*(len+1), "rna_path_token");
 
3701
                buf = MEM_callocN(sizeof(char) * (len + 1), "rna_path_token");
3560
3702
 
3561
3703
        /* copy string, taking into account escaped ] */
3562
3704
        if (bracket) {
3563
 
                for (p = *path, i = 0, j = 0; i<len; i++, p++) {
3564
 
                        if (*p == '\\' && *(p+1) == quote);
 
3705
                for (p = *path, i = 0, j = 0; i < len; i++, p++) {
 
3706
                        if (*p == '\\' && *(p + 1) == quote) {}
3565
3707
                        else buf[j++] = *p;
3566
3708
                }
3567
3709
 
3568
3710
                buf[j] = 0;
3569
3711
        }
3570
3712
        else {
3571
 
                memcpy(buf, *path, sizeof(char)*len);
 
3713
                memcpy(buf, *path, sizeof(char) * len);
3572
3714
                buf[len] = '\0';
3573
3715
        }
3574
3716
 
3582
3724
 
3583
3725
static int rna_token_strip_quotes(char *token)
3584
3726
{
3585
 
        if (token[0] =='"') {
 
3727
        if (token[0] == '"') {
3586
3728
                int len = strlen(token);
3587
 
                if (len >= 2 && token[len-1] =='"') {
 
3729
                if (len >= 2 && token[len - 1] == '"') {
3588
3730
                        /* strip away "" */
3589
 
                        token[len-1] = '\0';
 
3731
                        token[len - 1] = '\0';
3590
3732
                        return 1;
3591
3733
                }
3592
3734
        }
3602
3744
int RNA_path_resolve_full(PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, int *index)
3603
3745
{
3604
3746
        PropertyRNA *prop;
3605
 
        PointerRNA curptr, nextptr;
 
3747
        PointerRNA curptr;
 
3748
        PointerRNA nextptr;  /* keep uninitialized, helps expose bugs in collection accessor functions */
3606
3749
        char fixedbuf[256], *token;
3607
3750
        int type, intkey;
3608
3751
 
3609
3752
        prop = NULL;
3610
3753
        curptr = *ptr;
3611
3754
 
3612
 
        if (path == NULL || *path =='\0')
 
3755
        if (path == NULL || *path == '\0')
3613
3756
                return 0;
3614
3757
 
3615
3758
        while (*path) {
3616
 
                int use_id_prop = (*path =='[') ? 1:0;
 
3759
                int use_id_prop = (*path == '[') ? 1 : 0;
3617
3760
                /* custom property lookup ?
3618
3761
                 * C.object["someprop"]
3619
3762
                 */
3627
3770
                if (use_id_prop) { /* look up property name in current struct */
3628
3771
                        IDProperty *group = RNA_struct_idprops(&curptr, 0);
3629
3772
                        if (group && rna_token_strip_quotes(token))
3630
 
                                prop = (PropertyRNA *)IDP_GetPropertyFromGroup(group, token+1);
 
3773
                                prop = (PropertyRNA *)IDP_GetPropertyFromGroup(group, token + 1);
3631
3774
                }
3632
3775
                else {
3633
3776
                        prop = RNA_struct_find_property(&curptr, token);
3645
3788
                 * collection, otherwise return the property rna so that the
3646
3789
                 * caller can read the value of the property itself */
3647
3790
                switch (type) {
3648
 
                case PROP_POINTER:
3649
 
                        nextptr = RNA_property_pointer_get(&curptr, prop);
3650
 
 
3651
 
                        if (nextptr.data) {
3652
 
                                curptr = nextptr;
3653
 
                                prop = NULL; /* now we have a PointerRNA, the prop is our parent so forget it */
3654
 
                                if (index) *index = -1;
3655
 
                        }
3656
 
                        else
3657
 
                                return 0;
3658
 
 
3659
 
                        break;
3660
 
                case PROP_COLLECTION:
3661
 
                        if (*path) {
3662
 
                                if (*path == '[') {
3663
 
                                        /* resolve the lookup with [] brackets */
3664
 
                                        token = rna_path_token(&path, fixedbuf, sizeof(fixedbuf), 1);
3665
 
        
3666
 
                                        if (!token)
3667
 
                                                return 0;
3668
 
        
3669
 
                                        /* check for "" to see if it is a string */
3670
 
                                        if (rna_token_strip_quotes(token)) {
3671
 
                                                RNA_property_collection_lookup_string(&curptr, prop, token+1, &nextptr);
3672
 
                                        }
3673
 
                                        else {
3674
 
                                                /* otherwise do int lookup */
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 */
3678
 
                                                }
3679
 
                                                RNA_property_collection_lookup_int(&curptr, prop, intkey, &nextptr);
3680
 
                                        }
3681
 
 
3682
 
                                        if (token != fixedbuf) {
3683
 
                                                MEM_freeN(token);
3684
 
                                        }
3685
 
                                }
3686
 
                                else {
3687
 
                                        PointerRNA c_ptr;
3688
 
                                        
3689
 
                                        /* ensure we quit on invalid values */
3690
 
                                        nextptr.data = NULL;
3691
 
 
3692
 
                                        if (RNA_property_collection_type_get(&curptr, prop, &c_ptr)) {
3693
 
                                                nextptr = c_ptr;
3694
 
                                        }
3695
 
                                }
 
3791
                        case PROP_POINTER:
 
3792
                                nextptr = RNA_property_pointer_get(&curptr, prop);
3696
3793
 
3697
3794
                                if (nextptr.data) {
3698
3795
                                        curptr = nextptr;
3699
 
                                        prop = NULL;  /* now we have a PointerRNA, the prop is our parent so forget it */
 
3796
                                        prop = NULL; /* now we have a PointerRNA, the prop is our parent so forget it */
3700
3797
                                        if (index) *index = -1;
3701
3798
                                }
3702
3799
                                else
3703
3800
                                        return 0;
3704
 
                        }
3705
3801
                        
3706
 
                        break;
3707
 
                default:
3708
 
                        if (index == NULL)
3709
3802
                                break;
3710
 
 
3711
 
                        *index = -1;
3712
 
 
3713
 
                        if (*path) {
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);
3717
 
                                int i, temp_index;
3718
 
 
3719
 
                                for (i = 0; i<dim; i++) {
3720
 
                                        temp_index = -1;
3721
 
 
3722
 
                                        /* multi index resolve */
3723
 
                                        if (*path =='[') {
 
3803
                        case PROP_COLLECTION:
 
3804
                                if (*path) {
 
3805
                                        if (*path == '[') {
 
3806
                                                /* resolve the lookup with [] brackets */
3724
3807
                                                token = rna_path_token(&path, fixedbuf, sizeof(fixedbuf), 1);
3725
3808
        
3726
 
                                                if (token == NULL) {
3727
 
                                                        /* invalid syntax blah[] */
 
3809
                                                if (!token)
3728
3810
                                                        return 0;
3729
 
                                                }
 
3811
 
3730
3812
                                                /* 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));
 
3813
                                                if (rna_token_strip_quotes(token)) {
 
3814
                                                        if (RNA_property_collection_lookup_string(&curptr, prop, token + 1, &nextptr)) {
 
3815
                                                                /* pass */
 
3816
                                                        }
 
3817
                                                        else {
 
3818
                                                                nextptr.data = NULL;
 
3819
                                                        }
3733
3820
                                                }
3734
3821
                                                else {
3735
3822
                                                        /* otherwise do int lookup */
3736
 
                                                        temp_index = atoi(token);
3737
 
 
3738
 
                                                        if (temp_index == 0 && (token[0] != '0' || token[1] != '\0')) {
3739
 
                                                                if (token != fixedbuf) {
3740
 
                                                                        MEM_freeN(token);
3741
 
                                                                }
3742
 
 
3743
 
                                                                return 0;
3744
 
                                                        }
3745
 
                                                }
3746
 
                                        }
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.. */
3752
 
                                                        return 0;
3753
 
                                                }
3754
 
                                                temp_index = RNA_property_array_item_index(prop, *token);
3755
 
                                        }
 
3823
                                                        intkey = atoi(token);
 
3824
                                                        if (intkey == 0 && (token[0] != '0' || token[1] != '\0')) {
 
3825
                                                                return 0; /* we can be sure the fixedbuf was used in this case */
 
3826
                                                        }
 
3827
                                                        if (RNA_property_collection_lookup_int(&curptr, prop, intkey, &nextptr)) {
 
3828
                                                                /* pass */
 
3829
                                                        }
 
3830
                                                        else {
 
3831
                                                                nextptr.data = NULL;
 
3832
                                                        }
 
3833
                                                }
 
3834
 
 
3835
                                                if (token != fixedbuf) {
 
3836
                                                        MEM_freeN(token);
 
3837
                                                }
 
3838
                                        }
 
3839
                                        else {
 
3840
                                                PointerRNA c_ptr;
3756
3841
        
3757
 
                                        if (token != fixedbuf) {
3758
 
                                                MEM_freeN(token);
 
3842
                                                if (RNA_property_collection_type_get(&curptr, prop, &c_ptr)) {
 
3843
                                                        nextptr = c_ptr;
 
3844
                                                }
 
3845
                                                else {
 
3846
                                                        /* ensure we quit on invalid values */
 
3847
                                                        nextptr.data = NULL;
 
3848
                                                }
3759
3849
                                        }
3760
3850
                                        
3761
 
                                        /* out of range */
3762
 
                                        if (temp_index < 0 || temp_index >= len[i])
 
3851
                                        if (nextptr.data) {
 
3852
                                                curptr = nextptr;
 
3853
                                                prop = NULL; /* now we have a PointerRNA, the prop is our parent so forget it */
 
3854
                                                if (index) *index = -1;
 
3855
                                        }
 
3856
                                        else
3763
3857
                                                return 0;
3764
 
 
3765
 
                                        index_arr[i] = temp_index;
3766
 
                                        /* end multi index resolve */
3767
3858
                                }
3768
3859
 
3769
 
                                /* arrays always contain numbers so further values are not valid */
 
3860
                                break;
 
3861
                        default:
 
3862
                                if (index == NULL)
 
3863
                                        break;
 
3864
 
 
3865
                                *index = -1;
 
3866
 
3770
3867
                                if (*path) {
3771
 
                                        return 0;
3772
 
                                }
3773
 
                                else {
3774
 
                                        int totdim = 1;
3775
 
                                        int flat_index = 0;
3776
 
 
3777
 
                                        for (i = dim-1; i >= 0; i--) {
3778
 
                                                flat_index += index_arr[i] * totdim;
3779
 
                                                totdim *= len[i];
3780
 
                                        }
3781
 
 
3782
 
                                        *index = flat_index;
3783
 
                                }
3784
 
                        }
 
3868
                                        int index_arr[RNA_MAX_ARRAY_DIMENSION] = {0};
 
3869
                                        int len[RNA_MAX_ARRAY_DIMENSION];
 
3870
                                        const int dim = RNA_property_array_dimension(&curptr, prop, len);
 
3871
                                        int i, temp_index;
 
3872
 
 
3873
                                        for (i = 0; i < dim; i++) {
 
3874
                                                temp_index = -1;
 
3875
 
 
3876
                                                /* multi index resolve */
 
3877
                                                if (*path == '[') {
 
3878
                                                        token = rna_path_token(&path, fixedbuf, sizeof(fixedbuf), 1);
 
3879
 
 
3880
                                                        if (token == NULL) {
 
3881
                                                                /* invalid syntax blah[] */
 
3882
                                                                return 0;
 
3883
                                                        }
 
3884
                                                        /* check for "" to see if it is a string */
 
3885
                                                        else if (rna_token_strip_quotes(token)) {
 
3886
                                                                temp_index = RNA_property_array_item_index(prop, *(token + 1));
 
3887
                                                        }
 
3888
                                                        else {
 
3889
                                                                /* otherwise do int lookup */
 
3890
                                                                temp_index = atoi(token);
 
3891
 
 
3892
                                                                if (temp_index == 0 && (token[0] != '0' || token[1] != '\0')) {
 
3893
                                                                        if (token != fixedbuf) {
 
3894
                                                                                MEM_freeN(token);
 
3895
                                                                        }
 
3896
 
 
3897
                                                                        return 0;
 
3898
                                                                }
 
3899
                                                        }
 
3900
                                                }
 
3901
                                                else if (dim == 1) {
 
3902
                                                        /* location.x || scale.X, single dimension arrays only */
 
3903
                                                        token = rna_path_token(&path, fixedbuf, sizeof(fixedbuf), 0);
 
3904
                                                        if (token == NULL) {
 
3905
                                                                /* invalid syntax blah.. */
 
3906
                                                                return 0;
 
3907
                                                        }
 
3908
                                                        temp_index = RNA_property_array_item_index(prop, *token);
 
3909
                                                }
 
3910
 
 
3911
                                                if (token != fixedbuf) {
 
3912
                                                        MEM_freeN(token);
 
3913
                                                }
 
3914
 
 
3915
                                                /* out of range */
 
3916
                                                if (temp_index < 0 || temp_index >= len[i])
 
3917
                                                        return 0;
 
3918
 
 
3919
                                                index_arr[i] = temp_index;
 
3920
                                                /* end multi index resolve */
 
3921
                                        }
 
3922
 
 
3923
                                        /* arrays always contain numbers so further values are not valid */
 
3924
                                        if (*path) {
 
3925
                                                return 0;
 
3926
                                        }
 
3927
                                        else {
 
3928
                                                int totdim = 1;
 
3929
                                                int flat_index = 0;
 
3930
 
 
3931
                                                for (i = dim - 1; i >= 0; i--) {
 
3932
                                                        flat_index += index_arr[i] * totdim;
 
3933
                                                        totdim *= len[i];
 
3934
                                                }
 
3935
 
 
3936
                                                *index = flat_index;
 
3937
                                        }
 
3938
                                }
3785
3939
                }
3786
3940
        }
3787
3941
 
3802
3956
 
3803
3957
        /* add .identifier */
3804
3958
        if (path) {
3805
 
                BLI_dynstr_append(dynstr, (char*)path);
 
3959
                BLI_dynstr_append(dynstr, (char *)path);
3806
3960
                if (*path)
3807
3961
                        BLI_dynstr_append(dynstr, ".");
3808
3962
        }
3884
4038
        i = previous - path;
3885
4039
        result = BLI_strdup(path);
3886
4040
 
3887
 
        if (i > 0 && result[i-1] == '.') i--;
 
4041
        if (i > 0 && result[i - 1] == '.') i--;
3888
4042
        result[i] = 0;
3889
4043
 
3890
4044
        return result;
3935
4089
        path = BLI_dynstr_get_cstring(dynstr);
3936
4090
        BLI_dynstr_free(dynstr);
3937
4091
 
3938
 
        if (*path =='\0') {
 
4092
        if (*path == '\0') {
3939
4093
                MEM_freeN(path);
3940
4094
                path = NULL;
3941
4095
        }
3954
4108
        BLI_assert(haystack->type == IDP_GROUP);
3955
4109
 
3956
4110
        link.up = parent_link;
 
4111
        /* always set both name and index,
 
4112
         * else a stale value might get used */
3957
4113
        link.name = NULL;
3958
4114
        link.index = -1;
3959
4115
 
3960
4116
        for (i = 0, iter = haystack->data.group.first; iter; iter = iter->next, i++) {
3961
4117
                if (needle == iter) {  /* found! */
3962
4118
                        link.name = iter->name;
 
4119
                        link.index = -1;
3963
4120
                        path = rna_idp_path_create(&link);
3964
4121
                        break;
3965
4122
                }
3966
4123
                else {
3967
4124
                        if (iter->type == IDP_GROUP) {
3968
4125
                                /* ensure this is RNA */
3969
 
                                PointerRNA child_ptr = RNA_pointer_get(ptr, iter->name);
3970
 
                                if (child_ptr.type) {
 
4126
                                PropertyRNA *prop = RNA_struct_find_property(ptr, iter->name);
 
4127
                                if (prop && prop->type == PROP_POINTER) {
 
4128
                                        PointerRNA child_ptr = RNA_property_pointer_get(ptr, prop);
3971
4129
                                        link.name = iter->name;
 
4130
                                        link.index = -1;
3972
4131
                                        if ((path = rna_idp_path(&child_ptr, iter, needle, &link))) {
3973
4132
                                                break;
3974
4133
                                        }
4055
4214
                        if (userprop)
4056
4215
                                ptrpath = BLI_strdup(RNA_property_identifier(userprop));
4057
4216
                        else
4058
 
                                return NULL; /* can't do anything about this case yet... */
 
4217
                                return NULL;  /* can't do anything about this case yet... */
4059
4218
                }
4060
4219
                else if (RNA_struct_is_a(ptr->type, &RNA_PropertyGroup)) {
4061
4220
                        /* special case, easier to deal with here then in ptr->type->path() */
4070
4229
 
4071
4230
char *RNA_path_from_ID_to_property(PointerRNA *ptr, PropertyRNA *prop)
4072
4231
{
4073
 
        int is_rna = (prop->magic == RNA_MAGIC);
 
4232
        const bool is_rna = (prop->magic == RNA_MAGIC);
4074
4233
        const char *propname;
4075
4234
        char *ptrpath, *path;
4076
4235
 
4077
 
        if (!ptr->id.data || !ptr->data || !prop)
 
4236
        if (!ptr->id.data || !ptr->data)
4078
4237
                return NULL;
4079
4238
        
4080
4239
        /* path from ID to the struct holding this property */
4083
4242
        propname = RNA_property_identifier(prop);
4084
4243
 
4085
4244
        if (ptrpath) {
4086
 
                path = BLI_sprintfN(is_rna ? "%s.%s":"%s[\"%s\"]", ptrpath, propname);
 
4245
                path = BLI_sprintfN(is_rna ? "%s.%s" : "%s[\"%s\"]", ptrpath, propname);
4087
4246
                MEM_freeN(ptrpath);
4088
4247
        }
4089
 
        else {
 
4248
        else if (RNA_struct_is_ID(ptr->type)) {
4090
4249
                if (is_rna)
4091
4250
                        path = BLI_strdup(propname);
4092
4251
                else
4093
4252
                        path = BLI_sprintfN("[\"%s\"]", propname);
4094
4253
        }
 
4254
        else {
 
4255
                path = NULL;
 
4256
        }
4095
4257
 
4096
4258
        return path;
4097
4259
}
4098
4260
 
 
4261
/**
 
4262
 * Get the ID as a python representation, eg:
 
4263
 *   bpy.data.foo["bar"]
 
4264
 */
 
4265
char *RNA_path_full_ID_py(ID *id)
 
4266
{
 
4267
        char id_esc[(sizeof(id->name) - 2) * 2];
 
4268
 
 
4269
        BLI_strescape(id_esc, id->name + 2, sizeof(id_esc));
 
4270
 
 
4271
        return BLI_sprintfN("bpy.data.%s[\"%s\"]", BKE_idcode_to_name_plural(GS(id->name)), id_esc);
 
4272
}
 
4273
 
 
4274
/**
 
4275
 * Get the ID.struct as a python representation, eg:
 
4276
 *   bpy.data.foo["bar"].some_struct
 
4277
 */
 
4278
char *RNA_path_full_struct_py(struct PointerRNA *ptr)
 
4279
{
 
4280
        char *id_path;
 
4281
        char *data_path;
 
4282
 
 
4283
        char *ret;
 
4284
 
 
4285
        if (!ptr->id.data) {
 
4286
                return NULL;
 
4287
        }
 
4288
 
 
4289
        /* never fails */
 
4290
        id_path = RNA_path_full_ID_py(ptr->id.data);
 
4291
 
 
4292
        data_path = RNA_path_from_ID_to_struct(ptr);
 
4293
 
 
4294
        ret = BLI_sprintfN("%s.%s",
 
4295
                           id_path, data_path);
 
4296
 
 
4297
        MEM_freeN(data_path);
 
4298
 
 
4299
        return ret;
 
4300
}
 
4301
 
 
4302
/**
 
4303
 * Get the ID.struct.property as a python representation, eg:
 
4304
 *   bpy.data.foo["bar"].some_struct.some_prop[10]
 
4305
 */
 
4306
char *RNA_path_full_property_py(PointerRNA *ptr, PropertyRNA *prop, int index)
 
4307
{
 
4308
        char *id_path;
 
4309
        char *data_path;
 
4310
 
 
4311
        char *ret;
 
4312
 
 
4313
        if (!ptr->id.data) {
 
4314
                return NULL;
 
4315
        }
 
4316
 
 
4317
        /* never fails */
 
4318
        id_path = RNA_path_full_ID_py(ptr->id.data);
 
4319
 
 
4320
        data_path = RNA_path_from_ID_to_property(ptr, prop);
 
4321
 
 
4322
        if ((index == -1) || (RNA_property_array_check(prop) == FALSE)) {
 
4323
                ret = BLI_sprintfN("%s.%s",
 
4324
                                   id_path, data_path);
 
4325
        }
 
4326
        else {
 
4327
                ret = BLI_sprintfN("%s.%s[%d]",
 
4328
                                   id_path, data_path, index);
 
4329
        }
 
4330
        MEM_freeN(id_path);
 
4331
        if (data_path) {
 
4332
                MEM_freeN(data_path);
 
4333
        }
 
4334
 
 
4335
        return ret;
 
4336
}
 
4337
 
 
4338
/**
 
4339
 * Get the struct.property as a python representation, eg:
 
4340
 *   some_struct.some_prop[10]
 
4341
 */
 
4342
char *RNA_path_struct_property_py(PointerRNA *ptr, PropertyRNA *prop, int index)
 
4343
{
 
4344
        char *data_path;
 
4345
 
 
4346
        char *ret;
 
4347
 
 
4348
        if (!ptr->id.data) {
 
4349
                return NULL;
 
4350
        }
 
4351
 
 
4352
        data_path = RNA_path_from_ID_to_property(ptr, prop);
 
4353
 
 
4354
        if ((index == -1) || (RNA_property_array_check(prop) == FALSE)) {
 
4355
                ret = BLI_sprintfN("%s",
 
4356
                                   data_path);
 
4357
        }
 
4358
        else {
 
4359
                ret = BLI_sprintfN("%s[%d]",
 
4360
                                   data_path, index);
 
4361
        }
 
4362
 
 
4363
        if (data_path) {
 
4364
                MEM_freeN(data_path);
 
4365
        }
 
4366
 
 
4367
        return ret;
 
4368
}
 
4369
 
 
4370
/**
 
4371
 * Get the struct.property as a python representation, eg:
 
4372
 *   some_prop[10]
 
4373
 */
 
4374
char *RNA_path_property_py(PointerRNA *UNUSED(ptr), PropertyRNA *prop, int index)
 
4375
{
 
4376
        char *ret;
 
4377
 
 
4378
        if ((index == -1) || (RNA_property_array_check(prop) == FALSE)) {
 
4379
                ret = BLI_sprintfN("%s",
 
4380
                                   RNA_property_identifier(prop));
 
4381
        }
 
4382
        else {
 
4383
                ret = BLI_sprintfN("%s[%d]",
 
4384
                                   RNA_property_identifier(prop), index);
 
4385
        }
 
4386
 
 
4387
        return ret;
 
4388
}
 
4389
 
4099
4390
/* Quick name based property access */
4100
4391
 
4101
4392
int RNA_boolean_get(PointerRNA *ptr, const char *name)
4293
4584
 
4294
4585
int RNA_enum_value_from_id(EnumPropertyItem *item, const char *identifier, int *value)
4295
4586
{
4296
 
        for ( ; item->identifier; item++) {
 
4587
        for (; item->identifier; item++) {
4297
4588
                if (strcmp(item->identifier, identifier) == 0) {
4298
4589
                        *value = item->value;
4299
4590
                        return 1;
4303
4594
        return 0;
4304
4595
}
4305
4596
 
4306
 
int     RNA_enum_id_from_value(EnumPropertyItem *item, int value, const char **identifier)
 
4597
int RNA_enum_id_from_value(EnumPropertyItem *item, int value, const char **identifier)
4307
4598
{
4308
 
        for ( ; item->identifier; item++) {
 
4599
        for (; item->identifier; item++) {
4309
4600
                if (item->value == value) {
4310
4601
                        *identifier = item->identifier;
4311
4602
                        return 1;
4317
4608
 
4318
4609
int RNA_enum_icon_from_value(EnumPropertyItem *item, int value, int *icon)
4319
4610
{
4320
 
        for ( ; item->identifier; item++) {
 
4611
        for (; item->identifier; item++) {
4321
4612
                if (item->value == value) {
4322
4613
                        *icon = item->icon;
4323
4614
                        return 1;
4327
4618
        return 0;
4328
4619
}
4329
4620
 
 
4621
int RNA_enum_name_from_value(EnumPropertyItem *item, int value, const char **name)
 
4622
{
 
4623
        for (; item->identifier; item++) {
 
4624
                if (item->value == value) {
 
4625
                        *name = item->name;
 
4626
                        return 1;
 
4627
                }
 
4628
        }
 
4629
        
 
4630
        return 0;
 
4631
}
 
4632
 
4330
4633
void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
4331
4634
{
4332
4635
        PropertyRNA *prop = RNA_struct_find_property(ptr, name);
4455
4758
        }
4456
4759
}
4457
4760
 
 
4761
int RNA_property_is_set_ex(PointerRNA *ptr, PropertyRNA *prop, int use_ghost)
 
4762
{
 
4763
        if (prop->flag & PROP_IDPROPERTY) {
 
4764
                IDProperty *idprop = rna_idproperty_find(ptr, prop->identifier);
 
4765
                return ((idprop != NULL) && (use_ghost == FALSE || !(idprop->flag & IDP_FLAG_GHOST)));
 
4766
        }
 
4767
        else {
 
4768
                return 1;
 
4769
        }
 
4770
}
 
4771
 
4458
4772
int RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
4459
4773
{
4460
4774
        if (prop->flag & PROP_IDPROPERTY) {
4466
4780
        }
4467
4781
}
4468
4782
 
 
4783
int RNA_struct_property_is_set_ex(PointerRNA *ptr, const char *identifier, int use_ghost)
 
4784
{
 
4785
        PropertyRNA *prop = RNA_struct_find_property(ptr, identifier);
 
4786
 
 
4787
        if (prop) {
 
4788
                return RNA_property_is_set_ex(ptr, prop, use_ghost);
 
4789
        }
 
4790
        else {
 
4791
                /* python raises an error */
 
4792
                /* printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name); */
 
4793
                return 0;
 
4794
        }
 
4795
}
 
4796
 
4469
4797
int RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
4470
4798
{
4471
4799
        PropertyRNA *prop = RNA_struct_find_property(ptr, identifier);
4488
4816
/* string representation of a property, python
4489
4817
 * compatible but can be used for display too,
4490
4818
 * context may be NULL */
4491
 
char *RNA_pointer_as_string(bContext *C, PointerRNA *ptr)
 
4819
static char *rna_pointer_as_string__idprop(bContext *C, PointerRNA *ptr)
4492
4820
{
4493
4821
        DynStr *dynstr = BLI_dynstr_new();
4494
4822
        char *cstring;
4498
4826
        
4499
4827
        BLI_dynstr_append(dynstr, "{");
4500
4828
        
4501
 
        RNA_STRUCT_BEGIN(ptr, prop) {
 
4829
        RNA_STRUCT_BEGIN(ptr, prop)
 
4830
        {
4502
4831
                propname = RNA_property_identifier(prop);
4503
4832
                
4504
4833
                if (strcmp(propname, "rna_type") == 0)
4508
4837
                        BLI_dynstr_append(dynstr, ", ");
4509
4838
                first_time = 0;
4510
4839
                
4511
 
                cstring = RNA_property_as_string(C, ptr, prop);
 
4840
                cstring = RNA_property_as_string(C, ptr, prop, -1);
4512
4841
                BLI_dynstr_appendf(dynstr, "\"%s\":%s", propname, cstring);
4513
4842
                MEM_freeN(cstring);
4514
4843
        }
4522
4851
        return cstring;
4523
4852
}
4524
4853
 
 
4854
static char *rna_pointer_as_string__bldata(PointerRNA *ptr)
 
4855
{
 
4856
        if (ptr->type == NULL) {
 
4857
                return BLI_strdup("None");
 
4858
        }
 
4859
        else if (RNA_struct_is_ID(ptr->type)) {
 
4860
                return RNA_path_full_ID_py(ptr->id.data);
 
4861
        }
 
4862
        else {
 
4863
                return RNA_path_full_struct_py(ptr);
 
4864
        }
 
4865
}
 
4866
 
 
4867
char *RNA_pointer_as_string(bContext *C, PointerRNA *ptr, PropertyRNA *prop_ptr, PointerRNA *ptr_prop)
 
4868
{
 
4869
        if (RNA_property_flag(prop_ptr) & PROP_IDPROPERTY) {
 
4870
                return rna_pointer_as_string__idprop(C, ptr_prop);
 
4871
        }
 
4872
        else {
 
4873
                return rna_pointer_as_string__bldata(ptr_prop);
 
4874
        }
 
4875
}
4525
4876
 
4526
4877
/* context and ptr_default can be NULL */
4527
4878
char *RNA_pointer_as_string_keywords_ex(bContext *C, PointerRNA *ptr, PointerRNA *ptr_default,
4541
4892
        PropertyRNA *prop_default;
4542
4893
        char *buf_default;
4543
4894
 
4544
 
        RNA_PROP_BEGIN(ptr, propptr, iterprop) {
 
4895
        RNA_PROP_BEGIN(ptr, propptr, iterprop)
 
4896
        {
4545
4897
                prop = propptr.data;
4546
4898
 
4547
4899
                flag = RNA_property_flag(prop);
4558
4910
 
4559
4911
                if (as_function && (flag & PROP_REQUIRED)) {
4560
4912
                        /* required args don't have useful defaults */
4561
 
                        BLI_dynstr_appendf(dynstr, first_iter ? "%s":", %s", arg_name);
 
4913
                        BLI_dynstr_appendf(dynstr, first_iter ? "%s" : ", %s", arg_name);
4562
4914
                        first_iter = FALSE;
4563
4915
                }
4564
4916
                else {
4573
4925
                                }
4574
4926
                        }
4575
4927
                        else {
4576
 
                                buf = RNA_property_as_string(C, ptr, prop);
 
4928
                                buf = RNA_property_as_string(C, ptr, prop, -1);
4577
4929
                        }
4578
4930
 
4579
4931
                        ok = TRUE;
4584
4936
                                prop_default = RNA_struct_find_property(ptr_default, arg_name);
4585
4937
 
4586
4938
                                if (prop_default) {
4587
 
                                        buf_default = RNA_property_as_string(C, ptr_default, prop_default);
 
4939
                                        buf_default = RNA_property_as_string(C, ptr_default, prop_default, -1);
4588
4940
 
4589
4941
                                        if (strcmp(buf, buf_default) == 0)
4590
 
                                                ok = FALSE; /* values match, don't bother printing */
 
4942
                                                ok = FALSE;  /* values match, don't bother printing */
4591
4943
 
4592
4944
                                        MEM_freeN(buf_default);
4593
4945
                                }
4594
4946
                        }
4595
4947
                        if (ok) {
4596
 
                                BLI_dynstr_appendf(dynstr, first_iter ? "%s=%s":", %s=%s", arg_name, buf);
 
4948
                                BLI_dynstr_appendf(dynstr, first_iter ? "%s=%s" : ", %s=%s", arg_name, buf);
4597
4949
                                first_iter = FALSE;
4598
4950
                        }
4599
4951
 
4619
4971
}
4620
4972
 
4621
4973
char *RNA_function_as_string_keywords(bContext *C, FunctionRNA *func, PointerRNA *ptr_default,
4622
 
                                     const short as_function, const short all_args)
 
4974
                                      const short as_function, const short all_args)
4623
4975
{
4624
4976
        PointerRNA funcptr;
4625
4977
        PropertyRNA *iterprop;
4634
4986
                                                 iterprop);
4635
4987
}
4636
4988
 
4637
 
char *RNA_property_as_string(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
 
4989
static const char *bool_as_py_string(const int var)
 
4990
{
 
4991
        return var ? "True" : "False";
 
4992
}
 
4993
 
 
4994
char *RNA_property_as_string(bContext *C, PointerRNA *ptr, PropertyRNA *prop, int index)
4638
4995
{
4639
4996
        int type = RNA_property_type(prop);
4640
4997
        int len = RNA_property_array_length(ptr, prop);
4646
5003
 
4647
5004
        /* see if we can coorce into a python type - PropertyType */
4648
5005
        switch (type) {
4649
 
        case PROP_BOOLEAN:
4650
 
                if (len == 0) {
4651
 
                        BLI_dynstr_append(dynstr, RNA_property_boolean_get(ptr, prop) ? "True" : "False");
4652
 
                }
4653
 
                else {
4654
 
                        BLI_dynstr_append(dynstr, "(");
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");
4658
 
                        }
4659
 
                        if (len == 1)
4660
 
                                BLI_dynstr_append(dynstr, ","); /* otherwise python wont see it as a tuple */
4661
 
                        BLI_dynstr_append(dynstr, ")");
4662
 
                }
4663
 
                break;
4664
 
        case PROP_INT:
4665
 
                if (len == 0) {
4666
 
                        BLI_dynstr_appendf(dynstr, "%d", RNA_property_int_get(ptr, prop));
4667
 
                }
4668
 
                else {
4669
 
                        BLI_dynstr_append(dynstr, "(");
4670
 
                        for (i = 0; i<len; i++) {
4671
 
                                BLI_dynstr_appendf(dynstr, i?", %d":"%d", RNA_property_int_get_index(ptr, prop, i));
4672
 
                        }
4673
 
                        if (len == 1)
4674
 
                                BLI_dynstr_append(dynstr, ","); /* otherwise python wont see it as a tuple */
4675
 
                        BLI_dynstr_append(dynstr, ")");
4676
 
                }
4677
 
                break;
4678
 
        case PROP_FLOAT:
4679
 
                if (len == 0) {
4680
 
                        BLI_dynstr_appendf(dynstr, "%g", RNA_property_float_get(ptr, prop));
4681
 
                }
4682
 
                else {
4683
 
                        BLI_dynstr_append(dynstr, "(");
4684
 
                        for (i = 0; i<len; i++) {
4685
 
                                BLI_dynstr_appendf(dynstr, i?", %g":"%g", RNA_property_float_get_index(ptr, prop, i));
4686
 
                        }
4687
 
                        if (len == 1)
4688
 
                                BLI_dynstr_append(dynstr, ","); /* otherwise python wont see it as a tuple */
4689
 
                        BLI_dynstr_append(dynstr, ")");
4690
 
                }
4691
 
                break;
4692
 
        case PROP_STRING:
4693
 
        {
4694
 
                char *buf_esc;
4695
 
                char *buf;
4696
 
                int length;
4697
 
 
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);
4703
 
                MEM_freeN(buf);
4704
 
                BLI_dynstr_appendf(dynstr, "\"%s\"", buf_esc);
4705
 
                MEM_freeN(buf_esc);
4706
 
                break;
4707
 
        }
4708
 
        case PROP_ENUM:
4709
 
        {
4710
 
                /* string arrays don't exist */
4711
 
                const char *identifier;
4712
 
                int val = RNA_property_enum_get(ptr, prop);
4713
 
 
4714
 
                if (RNA_property_flag(prop) & PROP_ENUM_FLAG) {
4715
 
                        /* represent as a python set */
4716
 
                        if (val) {
4717
 
                                EnumPropertyItem *item = NULL;
4718
 
                                int free;
4719
 
 
4720
 
                                BLI_dynstr_append(dynstr, "{");
4721
 
 
4722
 
                                RNA_property_enum_items(C, ptr, prop, &item, NULL, &free);
4723
 
                                if (item) {
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);
4728
 
                                                        is_first = FALSE;
4729
 
                                                }
4730
 
                                        }
4731
 
 
4732
 
                                        if (free) {
4733
 
                                                MEM_freeN(item);
4734
 
                                        }
4735
 
                                }
4736
 
 
4737
 
                                BLI_dynstr_append(dynstr, "}");
4738
 
                        }
4739
 
                        else {
4740
 
                                /* annoying exception, don't confuse with dictionary syntax above: {} */
4741
 
                                BLI_dynstr_append(dynstr, "set()");
4742
 
                        }
4743
 
                }
4744
 
                else if (RNA_property_enum_identifier(C, ptr, prop, val, &identifier)) {
4745
 
                        BLI_dynstr_appendf(dynstr, "'%s'", identifier);
4746
 
                }
4747
 
                else {
4748
 
                        BLI_dynstr_append(dynstr, "'<UNKNOWN ENUM>'");
4749
 
                }
4750
 
                break;
4751
 
        }
4752
 
        case PROP_POINTER:
4753
 
        {
4754
 
                PointerRNA tptr = RNA_property_pointer_get(ptr, prop);
4755
 
                cstring = RNA_pointer_as_string(C, &tptr);
4756
 
                BLI_dynstr_append(dynstr, cstring);
4757
 
                MEM_freeN(cstring);
4758
 
                break;
4759
 
        }
4760
 
        case PROP_COLLECTION:
4761
 
        {
4762
 
                int first_time = 1;
4763
 
                CollectionPropertyIterator collect_iter;
4764
 
                BLI_dynstr_append(dynstr, "[");
4765
 
                
4766
 
                for (RNA_property_collection_begin(ptr, prop, &collect_iter); collect_iter.valid;
4767
 
                     RNA_property_collection_next(&collect_iter)) {
4768
 
                        PointerRNA itemptr = collect_iter.ptr;
4769
 
                        
4770
 
                        if (first_time == 0)
4771
 
                                BLI_dynstr_append(dynstr, ", ");
4772
 
                        first_time = 0;
4773
 
                        
4774
 
                        /* now get every prop of the collection */
4775
 
                        cstring = RNA_pointer_as_string(C, &itemptr);
 
5006
                case PROP_BOOLEAN:
 
5007
                        if (len == 0) {
 
5008
                                BLI_dynstr_append(dynstr, bool_as_py_string(RNA_property_boolean_get(ptr, prop)));
 
5009
                        }
 
5010
                        else {
 
5011
                                if (index != -1) {
 
5012
                                        BLI_dynstr_append(dynstr, bool_as_py_string(RNA_property_boolean_get_index(ptr, prop, index)));
 
5013
                                }
 
5014
                                else {
 
5015
                                        BLI_dynstr_append(dynstr, "(");
 
5016
                                        for (i = 0; i < len; i++) {
 
5017
                                                BLI_dynstr_appendf(dynstr, i ? ", %s" : "%s",
 
5018
                                                                   bool_as_py_string(RNA_property_boolean_get_index(ptr, prop, i)));
 
5019
                                        }
 
5020
                                        if (len == 1)
 
5021
                                                BLI_dynstr_append(dynstr, ",");  /* otherwise python wont see it as a tuple */
 
5022
                                        BLI_dynstr_append(dynstr, ")");
 
5023
                                }
 
5024
                        }
 
5025
                        break;
 
5026
                case PROP_INT:
 
5027
                        if (len == 0) {
 
5028
                                BLI_dynstr_appendf(dynstr, "%d", RNA_property_int_get(ptr, prop));
 
5029
                        }
 
5030
                        else {
 
5031
                                if (index != -1) {
 
5032
                                        BLI_dynstr_appendf(dynstr, "%d", RNA_property_int_get_index(ptr, prop, index));
 
5033
                                }
 
5034
                                else {
 
5035
                                        BLI_dynstr_append(dynstr, "(");
 
5036
                                        for (i = 0; i < len; i++) {
 
5037
                                                BLI_dynstr_appendf(dynstr, i ? ", %d" : "%d", RNA_property_int_get_index(ptr, prop, i));
 
5038
                                        }
 
5039
                                        if (len == 1)
 
5040
                                                BLI_dynstr_append(dynstr, ",");  /* otherwise python wont see it as a tuple */
 
5041
                                        BLI_dynstr_append(dynstr, ")");
 
5042
                                }
 
5043
                        }
 
5044
                        break;
 
5045
                case PROP_FLOAT:
 
5046
                        if (len == 0) {
 
5047
                                BLI_dynstr_appendf(dynstr, "%g", RNA_property_float_get(ptr, prop));
 
5048
                        }
 
5049
                        else {
 
5050
                                if (index != -1) {
 
5051
                                        BLI_dynstr_appendf(dynstr, "%g", RNA_property_float_get_index(ptr, prop, index));
 
5052
                                }
 
5053
                                else {
 
5054
                                        BLI_dynstr_append(dynstr, "(");
 
5055
                                        for (i = 0; i < len; i++) {
 
5056
                                                BLI_dynstr_appendf(dynstr, i ? ", %g" : "%g", RNA_property_float_get_index(ptr, prop, i));
 
5057
                                        }
 
5058
                                        if (len == 1)
 
5059
                                                BLI_dynstr_append(dynstr, ",");  /* otherwise python wont see it as a tuple */
 
5060
                                        BLI_dynstr_append(dynstr, ")");
 
5061
                                }
 
5062
                        }
 
5063
                        break;
 
5064
                case PROP_STRING:
 
5065
                {
 
5066
                        char *buf_esc;
 
5067
                        char *buf;
 
5068
                        int length;
 
5069
 
 
5070
                        length = RNA_property_string_length(ptr, prop);
 
5071
                        buf = MEM_mallocN(sizeof(char) * (length + 1), "RNA_property_as_string");
 
5072
                        buf_esc = MEM_mallocN(sizeof(char) * (length * 2 + 1), "RNA_property_as_string esc");
 
5073
                        RNA_property_string_get(ptr, prop, buf);
 
5074
                        BLI_strescape(buf_esc, buf, length * 2 + 1);
 
5075
                        MEM_freeN(buf);
 
5076
                        BLI_dynstr_appendf(dynstr, "\"%s\"", buf_esc);
 
5077
                        MEM_freeN(buf_esc);
 
5078
                        break;
 
5079
                }
 
5080
                case PROP_ENUM:
 
5081
                {
 
5082
                        /* string arrays don't exist */
 
5083
                        const char *identifier;
 
5084
                        int val = RNA_property_enum_get(ptr, prop);
 
5085
 
 
5086
                        if (RNA_property_flag(prop) & PROP_ENUM_FLAG) {
 
5087
                                /* represent as a python set */
 
5088
                                if (val) {
 
5089
                                        EnumPropertyItem *item = NULL;
 
5090
                                        int free;
 
5091
 
 
5092
                                        BLI_dynstr_append(dynstr, "{");
 
5093
 
 
5094
                                        RNA_property_enum_items(C, ptr, prop, &item, NULL, &free);
 
5095
                                        if (item) {
 
5096
                                                short is_first = TRUE;
 
5097
                                                for (; item->identifier; item++) {
 
5098
                                                        if (item->identifier[0] && item->value & val) {
 
5099
                                                                BLI_dynstr_appendf(dynstr, is_first ? "'%s'" : ", '%s'", item->identifier);
 
5100
                                                                is_first = FALSE;
 
5101
                                                        }
 
5102
                                                }
 
5103
 
 
5104
                                                if (free) {
 
5105
                                                        MEM_freeN(item);
 
5106
                                                }
 
5107
                                        }
 
5108
 
 
5109
                                        BLI_dynstr_append(dynstr, "}");
 
5110
                                }
 
5111
                                else {
 
5112
                                        /* annoying exception, don't confuse with dictionary syntax above: {} */
 
5113
                                        BLI_dynstr_append(dynstr, "set()");
 
5114
                                }
 
5115
                        }
 
5116
                        else if (RNA_property_enum_identifier(C, ptr, prop, val, &identifier)) {
 
5117
                                BLI_dynstr_appendf(dynstr, "'%s'", identifier);
 
5118
                        }
 
5119
                        else {
 
5120
                                BLI_dynstr_append(dynstr, "'<UNKNOWN ENUM>'");
 
5121
                        }
 
5122
                        break;
 
5123
                }
 
5124
                case PROP_POINTER:
 
5125
                {
 
5126
                        PointerRNA tptr = RNA_property_pointer_get(ptr, prop);
 
5127
                        cstring = RNA_pointer_as_string(C, ptr, prop, &tptr);
4776
5128
                        BLI_dynstr_append(dynstr, cstring);
4777
5129
                        MEM_freeN(cstring);
 
5130
                        break;
4778
5131
                }
 
5132
                case PROP_COLLECTION:
 
5133
                {
 
5134
                        int first_time = 1;
 
5135
                        CollectionPropertyIterator collect_iter;
 
5136
                        BLI_dynstr_append(dynstr, "[");
 
5137
 
 
5138
                        for (RNA_property_collection_begin(ptr, prop, &collect_iter); collect_iter.valid;
 
5139
                             RNA_property_collection_next(&collect_iter))
 
5140
                        {
 
5141
                                PointerRNA itemptr = collect_iter.ptr;
 
5142
 
 
5143
                                if (first_time == 0)
 
5144
                                        BLI_dynstr_append(dynstr, ", ");
 
5145
                                first_time = 0;
 
5146
 
 
5147
                                /* now get every prop of the collection */
 
5148
                                cstring = RNA_pointer_as_string(C, ptr, prop, &itemptr);
 
5149
                                BLI_dynstr_append(dynstr, cstring);
 
5150
                                MEM_freeN(cstring);
 
5151
                        }
4779
5152
                
4780
 
                RNA_property_collection_end(&collect_iter);
4781
 
                BLI_dynstr_append(dynstr, "]");
4782
 
                break;
4783
 
        }
4784
 
        default:
4785
 
                BLI_dynstr_append(dynstr, "'<UNKNOWN TYPE>'"); /* TODO */
4786
 
                break;
 
5153
                        RNA_property_collection_end(&collect_iter);
 
5154
                        BLI_dynstr_append(dynstr, "]");
 
5155
                        break;
 
5156
                }
 
5157
                default:
 
5158
                        BLI_dynstr_append(dynstr, "'<UNKNOWN TYPE>'"); /* TODO */
 
5159
                        break;
4787
5160
        }
4788
5161
 
4789
5162
        cstring = BLI_dynstr_get_cstring(dynstr);
4823
5196
        return BLI_findstring(&func->cont.properties, identifier, offsetof(PropertyRNA, identifier));
4824
5197
}
4825
5198
 
4826
 
const struct ListBase *RNA_function_defined_parameters(FunctionRNA *func)
 
5199
const ListBase *RNA_function_defined_parameters(FunctionRNA *func)
4827
5200
{
4828
5201
        return &func->cont.properties;
4829
5202
}
4869
5242
                if (!(parm->flag & PROP_REQUIRED) && !(parm->flag & PROP_DYNAMIC)) {
4870
5243
                        switch (parm->type) {
4871
5244
                                case PROP_BOOLEAN:
4872
 
                                        if (parm->arraydimension) memcpy(data, ((BoolPropertyRNA*)parm)->defaultarray, size);
4873
 
                                        else memcpy(data, &((BoolPropertyRNA*)parm)->defaultvalue, size);
 
5245
                                        if (parm->arraydimension) memcpy(data, ((BoolPropertyRNA *)parm)->defaultarray, size);
 
5246
                                        else memcpy(data, &((BoolPropertyRNA *)parm)->defaultvalue, size);
4874
5247
                                        break;
4875
5248
                                case PROP_INT:
4876
 
                                        if (parm->arraydimension) memcpy(data, ((IntPropertyRNA*)parm)->defaultarray, size);
4877
 
                                        else memcpy(data, &((IntPropertyRNA*)parm)->defaultvalue, size);
 
5249
                                        if (parm->arraydimension) memcpy(data, ((IntPropertyRNA *)parm)->defaultarray, size);
 
5250
                                        else memcpy(data, &((IntPropertyRNA *)parm)->defaultvalue, size);
4878
5251
                                        break;
4879
5252
                                case PROP_FLOAT:
4880
 
                                        if (parm->arraydimension) memcpy(data, ((FloatPropertyRNA*)parm)->defaultarray, size);
4881
 
                                        else memcpy(data, &((FloatPropertyRNA*)parm)->defaultvalue, size);
 
5253
                                        if (parm->arraydimension) memcpy(data, ((FloatPropertyRNA *)parm)->defaultarray, size);
 
5254
                                        else memcpy(data, &((FloatPropertyRNA *)parm)->defaultvalue, size);
4882
5255
                                        break;
4883
5256
                                case PROP_ENUM:
4884
 
                                        memcpy(data, &((EnumPropertyRNA*)parm)->defaultvalue, size);
 
5257
                                        memcpy(data, &((EnumPropertyRNA *)parm)->defaultvalue, size);
4885
5258
                                        break;
4886
 
                                case PROP_STRING: {
4887
 
                                        const char *defvalue = ((StringPropertyRNA*)parm)->defaultvalue;
 
5259
                                case PROP_STRING:
 
5260
                                {
 
5261
                                        const char *defvalue = ((StringPropertyRNA *)parm)->defaultvalue;
4888
5262
                                        if (defvalue && defvalue[0]) {
4889
5263
                                                /* causes bug [#29988], possibly this is only correct for thick wrapped
4890
5264
                                                 * need to look further into it - campbell */
4902
5276
                        }
4903
5277
                }
4904
5278
 
4905
 
                data = ((char*)data) + rna_parameter_size_alloc(parm);
 
5279
                data = ((char *)data) + rna_parameter_size_alloc(parm);
4906
5280
        }
4907
5281
 
4908
5282
        return parms;
4916
5290
        parm = parms->func->cont.properties.first;
4917
5291
        for (tot = 0; parm; parm = parm->next) {
4918
5292
                if (parm->type == PROP_COLLECTION)
4919
 
                        BLI_freelistN((ListBase*)((char*)parms->data+tot));
 
5293
                        BLI_freelistN((ListBase *)((char *)parms->data + tot));
4920
5294
                else if (parm->flag & PROP_DYNAMIC) {
4921
5295
                        /* for dynamic arrays and strings, data is a pointer to an array */
4922
5296
                        ParameterDynAlloc *data_alloc = (void *)(((char *)parms->data) + tot);
4960
5334
 
4961
5335
        if (iter->valid) {
4962
5336
                iter->size = rna_parameter_size_alloc(iter->parm);
4963
 
                iter->data = (((char*)iter->parms->data)); /* +iter->offset, always 0 */
 
5337
                iter->data = (((char *)iter->parms->data)); /* +iter->offset, always 0 */
4964
5338
        }
4965
5339
}
4966
5340
 
4972
5346
 
4973
5347
        if (iter->valid) {
4974
5348
                iter->size = rna_parameter_size_alloc(iter->parm);
4975
 
                iter->data = (((char*)iter->parms->data)+iter->offset);
 
5349
                iter->data = (((char *)iter->parms->data) + iter->offset);
4976
5350
        }
4977
5351
}
4978
5352
 
5102
5476
{
5103
5477
        FunctionRNA *func;
5104
5478
 
5105
 
        func = RNA_struct_find_function(ptr, identifier);
 
5479
        func = RNA_struct_find_function(ptr->type, identifier);
5106
5480
 
5107
5481
        if (func)
5108
5482
                return RNA_function_call(C, reports, ptr, func, parms);
5130
5504
{
5131
5505
        FunctionRNA *func;
5132
5506
 
5133
 
        func = RNA_struct_find_function(ptr, identifier);
 
5507
        func = RNA_struct_find_function(ptr->type, identifier);
5134
5508
 
5135
5509
        if (func) {
5136
5510
                va_list args;
5153
5527
        char lenbuf[16];
5154
5528
        int idx = 0;
5155
5529
 
5156
 
        if (format[ofs++] =='[')
5157
 
                for (; ofs<flen && format[ofs] !=']' && idx<sizeof(*lenbuf)-1; idx++, ofs++)
 
5530
        if (format[ofs++] == '[')
 
5531
                for (; ofs < flen && format[ofs] != ']' && idx < sizeof(*lenbuf) - 1; idx++, ofs++)
5158
5532
                        lenbuf[idx] = format[ofs];
5159
5533
 
5160
 
        if (ofs<flen && format[ofs+1] ==']') {
5161
 
                /* XXX put better error reporting for ofs>=flen or idx over lenbuf capacity */
 
5534
        if (ofs < flen && format[ofs + 1] == ']') {
 
5535
                /* XXX put better error reporting for (ofs >= flen) or idx over lenbuf capacity */
5162
5536
                lenbuf[idx] = '\0';
5163
5537
                return atoi(lenbuf);
5164
5538
        }
5173
5547
        /* ptr is always a function pointer, prop always a parameter */
5174
5548
 
5175
5549
        switch (type) {
5176
 
        case PROP_BOOLEAN:
 
5550
                case PROP_BOOLEAN:
5177
5551
                {
5178
 
                        if (ftype !='b') {
 
5552
                        if (ftype != 'b') {
5179
5553
                                fprintf(stderr, "%s.%s: wrong type for parameter %s, a boolean was expected\n", tid, fid, pid);
5180
5554
                                return -1;
5181
5555
                        }
5182
5556
 
5183
5557
                        if (len == 0)
5184
 
                                *((int*)dest) = *((int*)src);
 
5558
                                *((int *)dest) = *((int *)src);
5185
5559
                        else
5186
 
                                memcpy(dest, src, len*sizeof(int));
 
5560
                                memcpy(dest, src, len * sizeof(int));
5187
5561
 
5188
5562
                        break;
5189
5563
                }
5190
 
        case PROP_INT:
 
5564
                case PROP_INT:
5191
5565
                {
5192
 
                        if (ftype !='i') {
 
5566
                        if (ftype != 'i') {
5193
5567
                                fprintf(stderr, "%s.%s: wrong type for parameter %s, an integer was expected\n", tid, fid, pid);
5194
5568
                                return -1;
5195
5569
                        }
5196
5570
 
5197
5571
                        if (len == 0)
5198
 
                                *((int*)dest) = *((int*)src);
 
5572
                                *((int *)dest) = *((int *)src);
5199
5573
                        else
5200
 
                                memcpy(dest, src, len*sizeof(int));
 
5574
                                memcpy(dest, src, len * sizeof(int));
5201
5575
 
5202
5576
                        break;
5203
5577
                }
5204
 
        case PROP_FLOAT:
 
5578
                case PROP_FLOAT:
5205
5579
                {
5206
 
                        if (ftype !='f') {
 
5580
                        if (ftype != 'f') {
5207
5581
                                fprintf(stderr, "%s.%s: wrong type for parameter %s, a float was expected\n", tid, fid, pid);
5208
5582
                                return -1;
5209
5583
                        }
5210
5584
 
5211
5585
                        if (len == 0)
5212
 
                                *((float*)dest) = *((float*)src);
 
5586
                                *((float *)dest) = *((float *)src);
5213
5587
                        else
5214
 
                                memcpy(dest, src, len*sizeof(float));
 
5588
                                memcpy(dest, src, len * sizeof(float));
5215
5589
 
5216
5590
                        break;
5217
5591
                }
5218
 
        case PROP_STRING:
 
5592
                case PROP_STRING:
5219
5593
                {
5220
 
                        if (ftype !='s') {
 
5594
                        if (ftype != 's') {
5221
5595
                                fprintf(stderr, "%s.%s: wrong type for parameter %s, a string was expected\n", tid, fid, pid);
5222
5596
                                return -1;
5223
5597
                        }
5224
5598
 
5225
 
                        *((char**)dest) = *((char**)src);
 
5599
                        *((char **)dest) = *((char **)src);
5226
5600
 
5227
5601
                        break;
5228
5602
                }
5229
 
        case PROP_ENUM:
 
5603
                case PROP_ENUM:
5230
5604
                {
5231
 
                        if (ftype !='e') {
 
5605
                        if (ftype != 'e') {
5232
5606
                                fprintf(stderr, "%s.%s: wrong type for parameter %s, an enum was expected\n", tid, fid, pid);
5233
5607
                                return -1;
5234
5608
                        }
5235
5609
 
5236
 
                        *((int*)dest) = *((int*)src);
 
5610
                        *((int *)dest) = *((int *)src);
5237
5611
 
5238
5612
                        break;
5239
5613
                }
5240
 
        case PROP_POINTER:
 
5614
                case PROP_POINTER:
5241
5615
                {
5242
5616
                        StructRNA *ptype;
5243
5617
 
5244
 
                        if (ftype !='O') {
 
5618
                        if (ftype != 'O') {
5245
5619
                                fprintf(stderr, "%s.%s: wrong type for parameter %s, an object was expected\n", tid, fid, pid);
5246
5620
                                return -1;
5247
5621
                        }
5249
5623
                        ptype = RNA_property_pointer_type(ptr, prop);
5250
5624
 
5251
5625
                        if (prop->flag & PROP_RNAPTR) {
5252
 
                                *((PointerRNA*)dest) = *((PointerRNA*)src);
 
5626
                                *((PointerRNA *)dest) = *((PointerRNA *)src);
5253
5627
                                break;
5254
 
                         }
 
5628
                        }
5255
5629
                        
5256
5630
                        if (ptype != srna && !RNA_struct_is_a(srna, ptype)) {
5257
5631
                                fprintf(stderr, "%s.%s: wrong type for parameter %s, "
5260
5634
                                return -1;
5261
5635
                        }
5262
5636
 
5263
 
                        *((void**)dest) = *((void**)src);
 
5637
                        *((void **)dest) = *((void **)src);
5264
5638
 
5265
5639
                        break;
5266
5640
                }
5267
 
        case PROP_COLLECTION:
 
5641
                case PROP_COLLECTION:
5268
5642
                {
5269
5643
                        StructRNA *ptype;
5270
5644
                        ListBase *lb, *clb;
5271
5645
                        Link *link;
5272
5646
                        CollectionPointerLink *clink;
5273
5647
 
5274
 
                        if (ftype !='C') {
 
5648
                        if (ftype != 'C') {
5275
5649
                                fprintf(stderr, "%s.%s: wrong type for parameter %s, a collection was expected\n", tid, fid, pid);
5276
5650
                                return -1;
5277
5651
                        }
5296
5670
 
5297
5671
                        break;
5298
5672
                }
5299
 
        default:
 
5673
                default:
5300
5674
                {
5301
5675
                        if (len == 0)
5302
5676
                                fprintf(stderr, "%s.%s: unknown type for parameter %s\n", tid, fid, pid);
5347
5721
 
5348
5722
                pid = RNA_property_identifier(parm);
5349
5723
 
5350
 
                if (ofs >= flen || format[ofs] =='N') {
 
5724
                if (ofs >= flen || format[ofs] == 'N') {
5351
5725
                        if (flag & PROP_REQUIRED) {
5352
5726
                                err = -1;
5353
5727
                                fprintf(stderr, "%s.%s: missing required parameter %s\n", tid, fid, pid);
5372
5746
                }
5373
5747
 
5374
5748
                switch (type) {
5375
 
                case PROP_BOOLEAN:
5376
 
                case PROP_INT:
5377
 
                case PROP_ENUM:
 
5749
                        case PROP_BOOLEAN:
 
5750
                        case PROP_INT:
 
5751
                        case PROP_ENUM:
5378
5752
                        {
5379
5753
                                int arg = va_arg(args, int);
5380
5754
                                err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, iter.data, &arg,
5381
5755
                                                                   NULL, tid, fid, pid);
5382
5756
                                break;
5383
5757
                        }
5384
 
                case PROP_FLOAT:
 
5758
                        case PROP_FLOAT:
5385
5759
                        {
5386
5760
                                double arg = va_arg(args, double);
5387
5761
                                err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, iter.data, &arg,
5388
5762
                                                                   NULL, tid, fid, pid);
5389
5763
                                break;
5390
5764
                        }
5391
 
                case PROP_STRING:
 
5765
                        case PROP_STRING:
5392
5766
                        {
5393
 
                                char *arg = va_arg(args, char*);
 
5767
                                char *arg = va_arg(args, char *);
5394
5768
                                err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, iter.data, &arg,
5395
5769
                                                                   NULL, tid, fid, pid);
5396
5770
                                break;
5397
5771
                        }
5398
 
                case PROP_POINTER:
5399
 
                        {
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);
5404
 
                                break;
5405
 
                        }
5406
 
                case PROP_COLLECTION:
5407
 
                        {
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);
5412
 
                                break;
5413
 
                        }
5414
 
                default:
 
5772
                        case PROP_POINTER:
 
5773
                        {
 
5774
                                StructRNA *srna = va_arg(args, StructRNA *);
 
5775
                                void *arg = va_arg(args, void *);
 
5776
                                err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, iter.data, &arg,
 
5777
                                                                   srna, tid, fid, pid);
 
5778
                                break;
 
5779
                        }
 
5780
                        case PROP_COLLECTION:
 
5781
                        {
 
5782
                                StructRNA *srna = va_arg(args, StructRNA *);
 
5783
                                ListBase *arg = va_arg(args, ListBase *);
 
5784
                                err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, iter.data, &arg,
 
5785
                                                                   srna, tid, fid, pid);
 
5786
                                break;
 
5787
                        }
 
5788
                        default:
5415
5789
                        {
5416
5790
                                /* handle errors */
5417
5791
                                err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, iter.data, NULL,
5428
5802
                err = RNA_function_call(C, reports, ptr, func, &parms);
5429
5803
 
5430
5804
        /* XXX throw error when more parameters than those needed are passed or leave silent? */
5431
 
        if (err == 0 && pret && ofs<flen && format[ofs++] =='R') {
 
5805
        if (err == 0 && pret && ofs < flen && format[ofs++] == 'R') {
5432
5806
                parm = pret;
5433
5807
 
5434
5808
                type = RNA_property_type(parm);
5444
5818
                }
5445
5819
                else {
5446
5820
                        switch (type) {
5447
 
                        case PROP_BOOLEAN:
5448
 
                        case PROP_INT:
5449
 
                        case PROP_ENUM:
5450
 
                                {
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);
5454
 
                                        break;
5455
 
                                }
5456
 
                        case PROP_FLOAT:
5457
 
                                {
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);
5461
 
                                        break;
5462
 
                                }
5463
 
                        case PROP_STRING:
5464
 
                                {
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);
5468
 
                                        break;
5469
 
                                }
5470
 
                        case PROP_POINTER:
5471
 
                                {
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);
5476
 
                                        break;
5477
 
                                }
5478
 
                        case PROP_COLLECTION:
5479
 
                                {
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);
5484
 
                                        break;
5485
 
                                }
5486
 
                        default:
 
5821
                                case PROP_BOOLEAN:
 
5822
                                case PROP_INT:
 
5823
                                case PROP_ENUM:
 
5824
                                {
 
5825
                                        int *arg = va_arg(args, int *);
 
5826
                                        err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, arg, retdata,
 
5827
                                                                           NULL, tid, fid, pid);
 
5828
                                        break;
 
5829
                                }
 
5830
                                case PROP_FLOAT:
 
5831
                                {
 
5832
                                        float *arg = va_arg(args, float *);
 
5833
                                        err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, arg, retdata,
 
5834
                                                                           NULL, tid, fid, pid);
 
5835
                                        break;
 
5836
                                }
 
5837
                                case PROP_STRING:
 
5838
                                {
 
5839
                                        char **arg = va_arg(args, char **);
 
5840
                                        err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, arg, retdata,
 
5841
                                                                           NULL, tid, fid, pid);
 
5842
                                        break;
 
5843
                                }
 
5844
                                case PROP_POINTER:
 
5845
                                {
 
5846
                                        StructRNA *srna = va_arg(args, StructRNA *);
 
5847
                                        void **arg = va_arg(args, void **);
 
5848
                                        err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, arg, retdata,
 
5849
                                                                           srna, tid, fid, pid);
 
5850
                                        break;
 
5851
                                }
 
5852
                                case PROP_COLLECTION:
 
5853
                                {
 
5854
                                        StructRNA *srna = va_arg(args, StructRNA *);
 
5855
                                        ListBase **arg = va_arg(args, ListBase * *);
 
5856
                                        err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, arg, retdata,
 
5857
                                                                           srna, tid, fid, pid);
 
5858
                                        break;
 
5859
                                }
 
5860
                                default:
5487
5861
                                {
5488
5862
                                        /* handle errors */
5489
5863
                                        err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, NULL, NULL,
5505
5879
{
5506
5880
        FunctionRNA *func;
5507
5881
 
5508
 
        func = RNA_struct_find_function(ptr, identifier);
 
5882
        func = RNA_struct_find_function(ptr->type, identifier);
5509
5883
 
5510
5884
        if (func)
5511
5885
                return RNA_function_call_direct_va(C, reports, ptr, func, format, args);
5525
5899
                case PROP_BOOLEAN:
5526
5900
                        if (len) {
5527
5901
                                if (index == -1) {
5528
 
                                        int *tmparray = MEM_callocN(sizeof(int)*len, "reset_defaults - boolean");
 
5902
                                        int *tmparray = MEM_callocN(sizeof(int) * len, "reset_defaults - boolean");
5529
5903
                                        
5530
5904
                                        RNA_property_boolean_get_default_array(ptr, prop, tmparray);
5531
5905
                                        RNA_property_boolean_set_array(ptr, prop, tmparray);
5545
5919
                case PROP_INT:
5546
5920
                        if (len) {
5547
5921
                                if (index == -1) {
5548
 
                                        int *tmparray = MEM_callocN(sizeof(int)*len, "reset_defaults - int");
 
5922
                                        int *tmparray = MEM_callocN(sizeof(int) * len, "reset_defaults - int");
5549
5923
                                        
5550
5924
                                        RNA_property_int_get_default_array(ptr, prop, tmparray);
5551
5925
                                        RNA_property_int_set_array(ptr, prop, tmparray);
5565
5939
                case PROP_FLOAT:
5566
5940
                        if (len) {
5567
5941
                                if (index == -1) {
5568
 
                                        float *tmparray = MEM_callocN(sizeof(float)*len, "reset_defaults - float");
 
5942
                                        float *tmparray = MEM_callocN(sizeof(float) * len, "reset_defaults - float");
5569
5943
                                        
5570
5944
                                        RNA_property_float_get_default_array(ptr, prop, tmparray);
5571
5945
                                        RNA_property_float_set_array(ptr, prop, tmparray);
5616
5990
 
5617
5991
        /* get the length of the array to work with */
5618
5992
        len = RNA_property_array_length(ptr, prop);
5619
 
        fromlen = RNA_property_array_length(ptr, prop);
 
5993
        fromlen = RNA_property_array_length(fromptr, prop);
5620
5994
 
5621
5995
        if (len != fromlen)
5622
5996
                return 0;
5626
6000
                case PROP_BOOLEAN:
5627
6001
                        if (len) {
5628
6002
                                if (index == -1) {
5629
 
                                        int *tmparray = MEM_callocN(sizeof(int)*len, "copy - boolean");
 
6003
                                        int *tmparray = MEM_callocN(sizeof(int) * len, "copy - boolean");
5630
6004
                                        
5631
6005
                                        RNA_property_boolean_get_array(fromptr, prop, tmparray);
5632
6006
                                        RNA_property_boolean_set_array(ptr, prop, tmparray);
5646
6020
                case PROP_INT:
5647
6021
                        if (len) {
5648
6022
                                if (index == -1) {
5649
 
                                        int *tmparray = MEM_callocN(sizeof(int)*len, "copy - int");
 
6023
                                        int *tmparray = MEM_callocN(sizeof(int) * len, "copy - int");
5650
6024
                                        
5651
6025
                                        RNA_property_int_get_array(fromptr, prop, tmparray);
5652
6026
                                        RNA_property_int_set_array(ptr, prop, tmparray);
5666
6040
                case PROP_FLOAT:
5667
6041
                        if (len) {
5668
6042
                                if (index == -1) {
5669
 
                                        float *tmparray = MEM_callocN(sizeof(float)*len, "copy - float");
 
6043
                                        float *tmparray = MEM_callocN(sizeof(float) * len, "copy - float");
5670
6044
                                        
5671
6045
                                        RNA_property_float_get_array(fromptr, prop, tmparray);
5672
6046
                                        RNA_property_float_set_array(ptr, prop, tmparray);
5730
6104
        }
5731
6105
#endif
5732
6106
}
 
6107
 
 
6108
int RNA_property_equals(PointerRNA *a, PointerRNA *b, PropertyRNA *prop)
 
6109
{
 
6110
        /* get the length of the array to work with */
 
6111
        int len = RNA_property_array_length(a, prop);
 
6112
        int fromlen = RNA_property_array_length(b, prop);
 
6113
 
 
6114
        if (len != fromlen)
 
6115
                return 0;
 
6116
 
 
6117
        /* get and set the default values as appropriate for the various types */
 
6118
        switch (RNA_property_type(prop)) {
 
6119
                case PROP_BOOLEAN:
 
6120
                {
 
6121
                        if (len) {
 
6122
                                int fixed_a[16], fixed_b[16];
 
6123
                                int *array_a, *array_b;
 
6124
                                int equals;
 
6125
 
 
6126
                                array_a = (len > 16)? MEM_callocN(sizeof(int) * len, "RNA equals"): fixed_a;
 
6127
                                array_b = (len > 16)? MEM_callocN(sizeof(int) * len, "RNA equals"): fixed_b;
 
6128
 
 
6129
                                RNA_property_boolean_get_array(a, prop, array_a);
 
6130
                                RNA_property_boolean_get_array(b, prop, array_b);
 
6131
 
 
6132
                                equals = memcmp(array_a, array_b, sizeof(int) * len) == 0;
 
6133
 
 
6134
                                if (array_a != fixed_a) MEM_freeN(array_a);
 
6135
                                if (array_b != fixed_b) MEM_freeN(array_b);
 
6136
 
 
6137
                                return equals;
 
6138
                        }
 
6139
                        else {
 
6140
                                int value = RNA_property_boolean_get(a, prop);
 
6141
                                return value == RNA_property_boolean_get(b, prop);
 
6142
                        }
 
6143
                }
 
6144
 
 
6145
                case PROP_INT:
 
6146
                {
 
6147
                        if (len) {
 
6148
                                int fixed_a[16], fixed_b[16];
 
6149
                                int *array_a, *array_b;
 
6150
                                int equals;
 
6151
 
 
6152
                                array_a = (len > 16)? MEM_callocN(sizeof(int) * len, "RNA equals"): fixed_a;
 
6153
                                array_b = (len > 16)? MEM_callocN(sizeof(int) * len, "RNA equals"): fixed_b;
 
6154
 
 
6155
                                RNA_property_int_get_array(a, prop, array_a);
 
6156
                                RNA_property_int_get_array(b, prop, array_b);
 
6157
 
 
6158
                                equals = memcmp(array_a, array_b, sizeof(int) * len) == 0;
 
6159
 
 
6160
                                if (array_a != fixed_a) MEM_freeN(array_a);
 
6161
                                if (array_b != fixed_b) MEM_freeN(array_b);
 
6162
 
 
6163
                                return equals;
 
6164
                        }
 
6165
                        else {
 
6166
                                int value = RNA_property_int_get(a, prop);
 
6167
                                return value == RNA_property_int_get(b, prop);
 
6168
                        }
 
6169
                }
 
6170
 
 
6171
                case PROP_FLOAT:
 
6172
                {
 
6173
                        if (len) {
 
6174
                                float fixed_a[16], fixed_b[16];
 
6175
                                float *array_a, *array_b;
 
6176
                                int equals;
 
6177
 
 
6178
                                array_a = (len > 16)? MEM_callocN(sizeof(float) * len, "RNA equals"): fixed_a;
 
6179
                                array_b = (len > 16)? MEM_callocN(sizeof(float) * len, "RNA equals"): fixed_b;
 
6180
 
 
6181
                                RNA_property_float_get_array(a, prop, array_a);
 
6182
                                RNA_property_float_get_array(b, prop, array_b);
 
6183
 
 
6184
                                equals = memcmp(array_a, array_b, sizeof(float) * len) == 0;
 
6185
 
 
6186
                                if (array_a != fixed_a) MEM_freeN(array_a);
 
6187
                                if (array_b != fixed_b) MEM_freeN(array_b);
 
6188
 
 
6189
                                return equals;
 
6190
                        }
 
6191
                        else {
 
6192
                                float value = RNA_property_float_get(a, prop);
 
6193
                                return value == RNA_property_float_get(b, prop);
 
6194
                        }
 
6195
                }
 
6196
 
 
6197
                case PROP_ENUM:
 
6198
                {
 
6199
                        int value = RNA_property_enum_get(a, prop);
 
6200
                        return value == RNA_property_enum_get(b, prop);
 
6201
                }
 
6202
 
 
6203
                case PROP_STRING:
 
6204
                {
 
6205
                        char fixed_a[128], fixed_b[128];
 
6206
                        int len_a, len_b;
 
6207
                        char *value_a = RNA_property_string_get_alloc(a, prop, fixed_a, sizeof(fixed_a), &len_a);
 
6208
                        char *value_b = RNA_property_string_get_alloc(b, prop, fixed_b, sizeof(fixed_b), &len_b);
 
6209
                        int equals = strcmp(value_a, value_b) == 0;
 
6210
 
 
6211
                        if (value_a != fixed_a) MEM_freeN(value_a);
 
6212
                        if (value_b != fixed_b) MEM_freeN(value_b);
 
6213
 
 
6214
                        return equals;
 
6215
                }
 
6216
 
 
6217
                default:
 
6218
                        break;
 
6219
        }
 
6220
 
 
6221
        return 1;
 
6222
}
 
6223
 
 
6224
int RNA_struct_equals(PointerRNA *a, PointerRNA *b)
 
6225
{
 
6226
        CollectionPropertyIterator iter;
 
6227
//      CollectionPropertyRNA *citerprop;  /* UNUSED */
 
6228
        PropertyRNA *iterprop;
 
6229
        int equals = 1;
 
6230
 
 
6231
        if (a == NULL && b == NULL)
 
6232
                return 1;
 
6233
        else if (a == NULL || b == NULL)
 
6234
                return 0;
 
6235
        else if (a->type != b->type)
 
6236
                return 0;
 
6237
 
 
6238
        iterprop = RNA_struct_iterator_property(a->type);
 
6239
//      citerprop = (CollectionPropertyRNA *)rna_ensure_property(iterprop);  /* UNUSED */
 
6240
 
 
6241
        RNA_property_collection_begin(a, iterprop, &iter);
 
6242
        for (; iter.valid; RNA_property_collection_next(&iter)) {
 
6243
                PropertyRNA *prop = iter.ptr.data;
 
6244
 
 
6245
                if (!RNA_property_equals(a, b, prop)) {
 
6246
                        equals = 0;
 
6247
                        break;
 
6248
                }
 
6249
        }
 
6250
        RNA_property_collection_end(&iter);
 
6251
 
 
6252
        return equals;
 
6253
}
 
6254