~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * $Id: rna_access.c 29962 2010-07-05 03:55:28Z aligorith $
3
 
 *
 
1
/*
4
2
 * ***** BEGIN GPL LICENSE BLOCK *****
5
3
 *
6
4
 * This program is free software; you can redistribute it and/or
22
20
 * ***** END GPL LICENSE BLOCK *****
23
21
 */
24
22
 
 
23
/** \file blender/makesrna/intern/rna_access.c
 
24
 *  \ingroup RNA
 
25
 */
 
26
 
 
27
 
25
28
#include <stdlib.h>
 
29
#include <stddef.h>
26
30
#include <string.h>
27
31
#include <ctype.h>
28
32
 
33
37
#include "DNA_windowmanager_types.h"
34
38
 
35
39
#include "BLI_blenlib.h"
 
40
#include "BLI_utildefines.h"
36
41
#include "BLI_dynstr.h"
37
42
#include "BLI_ghash.h"
38
43
 
 
44
#include "BLF_api.h"
 
45
#include "BLF_translation.h"
 
46
 
39
47
#include "BKE_animsys.h"
40
48
#include "BKE_context.h"
41
49
#include "BKE_idprop.h"
42
50
#include "BKE_main.h"
43
51
#include "BKE_report.h"
44
 
#include "BKE_utildefines.h"
 
52
 
45
53
 
46
54
#include "WM_api.h"
47
55
 
55
63
 
56
64
#include "rna_internal.h"
57
65
 
 
66
const PointerRNA PointerRNA_NULL = {{NULL}};
 
67
 
58
68
/* Init/Exit */
59
69
 
60
 
void RNA_init()
 
70
void RNA_init(void)
61
71
{
62
72
        StructRNA *srna;
63
73
        PropertyRNA *prop;
64
74
 
65
 
        for(srna=BLENDER_RNA.structs.first; srna; srna=srna->cont.next) {
66
 
                if(!srna->cont.prophash) {
67
 
                        srna->cont.prophash= BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "RNA_init gh");
 
75
        for (srna = BLENDER_RNA.structs.first; srna; srna = srna->cont.next) {
 
76
                if (!srna->cont.prophash) {
 
77
                        srna->cont.prophash = BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "RNA_init gh");
68
78
 
69
 
                        for(prop=srna->cont.properties.first; prop; prop=prop->next)
70
 
                                if(!(prop->flag & PROP_BUILTIN))
 
79
                        for (prop = srna->cont.properties.first; prop; prop = prop->next)
 
80
                                if (!(prop->flag & PROP_BUILTIN))
71
81
                                        BLI_ghash_insert(srna->cont.prophash, (void*)prop->identifier, prop);
72
82
                }
73
83
        }
74
84
}
75
85
 
76
 
void RNA_exit()
 
86
void RNA_exit(void)
77
87
{
78
88
        StructRNA *srna;
79
 
 
80
 
        for(srna=BLENDER_RNA.structs.first; srna; srna=srna->cont.next) {
81
 
                if(srna->cont.prophash) {
 
89
        
 
90
        RNA_property_update_cache_free();
 
91
        
 
92
        for (srna = BLENDER_RNA.structs.first; srna; srna = srna->cont.next) {
 
93
                if (srna->cont.prophash) {
82
94
                        BLI_ghash_free(srna->cont.prophash, NULL, NULL);
83
 
                        srna->cont.prophash= NULL;
 
95
                        srna->cont.prophash = NULL;
84
96
                }
85
97
        }
86
98
 
89
101
 
90
102
/* Pointer */
91
103
 
92
 
PointerRNA PointerRNA_NULL = {{0}, 0, 0};
93
 
 
94
104
void RNA_main_pointer_create(struct Main *main, PointerRNA *r_ptr)
95
105
{
96
 
        r_ptr->id.data= NULL;
97
 
        r_ptr->type= &RNA_Main;
98
 
        r_ptr->data= main;
 
106
        r_ptr->id.data = NULL;
 
107
        r_ptr->type = &RNA_BlendData;
 
108
        r_ptr->data = main;
99
109
}
100
110
 
101
111
void RNA_id_pointer_create(ID *id, PointerRNA *r_ptr)
102
112
{
103
 
        PointerRNA tmp;
104
 
        StructRNA *type, *idtype= NULL;
 
113
        StructRNA *type, *idtype = NULL;
105
114
 
106
 
        if(id) {
107
 
                memset(&tmp, 0, sizeof(tmp));
108
 
                tmp.data= id;
109
 
                idtype= rna_ID_refine(&tmp);
 
115
        if (id) {
 
116
                PointerRNA tmp = {{NULL}};
 
117
                tmp.data = id;
 
118
                idtype = rna_ID_refine(&tmp);
110
119
                
111
 
                while(idtype->refine) {
112
 
                        type= idtype->refine(&tmp);
 
120
                while (idtype->refine) {
 
121
                        type = idtype->refine(&tmp);
113
122
 
114
 
                        if(type == idtype)
 
123
                        if (type == idtype)
115
124
                                break;
116
125
                        else
117
 
                                idtype= type;
 
126
                                idtype = type;
118
127
                }
119
128
        }
120
129
        
121
 
        r_ptr->id.data= id;
122
 
        r_ptr->type= idtype;
123
 
        r_ptr->data= id;
 
130
        r_ptr->id.data = id;
 
131
        r_ptr->type = idtype;
 
132
        r_ptr->data = id;
124
133
}
125
134
 
126
135
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
127
136
{
128
 
        PointerRNA tmp;
129
 
        StructRNA *idtype= NULL;
 
137
#if 0 /* UNUSED */
 
138
        StructRNA *idtype = NULL;
130
139
 
131
 
        if(id) {
132
 
                memset(&tmp, 0, sizeof(tmp));
133
 
                tmp.data= id;
134
 
                idtype= rna_ID_refine(&tmp);
 
140
        if (id) {
 
141
                PointerRNA tmp = {{0}};
 
142
                tmp.data = id;
 
143
                idtype = rna_ID_refine(&tmp);
135
144
        }
136
 
 
137
 
        r_ptr->id.data= id;
138
 
        r_ptr->type= type;
139
 
        r_ptr->data= data;
140
 
 
141
 
        if(data) {
142
 
                while(r_ptr->type && r_ptr->type->refine) {
143
 
                        StructRNA *rtype= r_ptr->type->refine(r_ptr);
144
 
 
145
 
                        if(rtype == r_ptr->type)
 
145
#endif
 
146
 
 
147
        r_ptr->id.data = id;
 
148
        r_ptr->type = type;
 
149
        r_ptr->data = data;
 
150
 
 
151
        if (data) {
 
152
                while (r_ptr->type && r_ptr->type->refine) {
 
153
                        StructRNA *rtype = r_ptr->type->refine(r_ptr);
 
154
 
 
155
                        if (rtype == r_ptr->type)
146
156
                                break;
147
157
                        else
148
 
                                r_ptr->type= rtype;
 
158
                                r_ptr->type = rtype;
149
159
                }
150
160
        }
151
161
}
152
162
 
153
163
static void rna_pointer_inherit_id(StructRNA *type, PointerRNA *parent, PointerRNA *ptr)
154
164
{
155
 
        if(type && type->flag & STRUCT_ID) {
156
 
                ptr->id.data= ptr->data;
 
165
        if (type && type->flag & STRUCT_ID) {
 
166
                ptr->id.data = ptr->data;
157
167
        }
158
168
        else {
159
 
                ptr->id.data= parent->id.data;
 
169
                ptr->id.data = parent->id.data;
160
170
        }
161
171
}
162
172
 
163
173
void RNA_blender_rna_pointer_create(PointerRNA *r_ptr)
164
174
{
165
 
        r_ptr->id.data= NULL;
166
 
        r_ptr->type= &RNA_BlenderRNA;
167
 
        r_ptr->data= &BLENDER_RNA;
 
175
        r_ptr->id.data = NULL;
 
176
        r_ptr->type = &RNA_BlenderRNA;
 
177
        r_ptr->data = &BLENDER_RNA;
168
178
}
169
179
 
170
180
PointerRNA rna_pointer_inherit_refine(PointerRNA *ptr, StructRNA *type, void *data)
171
181
{
172
 
        PointerRNA result;
173
 
 
174
 
        if(data) {
175
 
                result.data= data;
176
 
                result.type= type;
 
182
        if (data) {
 
183
                PointerRNA result;
 
184
                result.data = data;
 
185
                result.type = type;
177
186
                rna_pointer_inherit_id(type, ptr, &result);
178
187
 
179
 
                while(result.type->refine) {
180
 
                        type= result.type->refine(&result);
 
188
                while (result.type->refine) {
 
189
                        type = result.type->refine(&result);
181
190
 
182
 
                        if(type == result.type)
 
191
                        if (type == result.type)
183
192
                                break;
184
193
                        else
185
 
                                result.type= type;
 
194
                                result.type = type;
186
195
                }
187
 
        }
188
 
        else
189
 
                memset(&result, 0, sizeof(result));
190
 
        
191
 
        return result;
 
196
                return result;
 
197
        }
 
198
        else {
 
199
                return PointerRNA_NULL;
 
200
        }
192
201
}
193
202
 
194
203
/**/
195
204
void RNA_pointer_recast(PointerRNA *ptr, PointerRNA *r_ptr)
196
205
{
197
 
#if 0 // works but this case if covered by more general code below.
198
 
        if(RNA_struct_is_ID(ptr->type)) {
 
206
#if 0 /* works but this case if covered by more general code below. */
 
207
        if (RNA_struct_is_ID(ptr->type)) {
199
208
                /* simple case */
200
209
                RNA_id_pointer_create(ptr->id.data, r_ptr);
201
210
        }
204
213
        {
205
214
                StructRNA *base;
206
215
                PointerRNA t_ptr;
207
 
                *r_ptr= *ptr; /* initialize as the same incase cant recast */
 
216
                *r_ptr = *ptr; /* initialize as the same in case cant recast */
208
217
 
209
 
                for(base=ptr->type->base; base; base=base->base) {
210
 
                        t_ptr= rna_pointer_inherit_refine(ptr, base, ptr->data);
211
 
                        if(t_ptr.type && t_ptr.type != ptr->type) {
212
 
                                *r_ptr= t_ptr;
 
218
                for (base = ptr->type->base; base; base = base->base) {
 
219
                        t_ptr = rna_pointer_inherit_refine(ptr, base, ptr->data);
 
220
                        if (t_ptr.type && t_ptr.type != ptr->type) {
 
221
                                *r_ptr = t_ptr;
213
222
                        }
214
223
                }
215
224
        }
217
226
 
218
227
/* ID Properties */
219
228
 
 
229
static void rna_idproperty_touch(IDProperty *idprop)
 
230
{
 
231
        /* so the property is seen as 'set' by rna */
 
232
        idprop->flag &= ~IDP_FLAG_GHOST;
 
233
}
 
234
 
220
235
/* return a UI local ID prop definition for this prop */
221
236
IDProperty *rna_idproperty_ui(PropertyRNA *prop)
222
237
{
223
238
        IDProperty *idprop;
224
239
 
225
 
        for(idprop= ((IDProperty *)prop)->prev; idprop; idprop= idprop->prev) {
226
 
                if (strcmp(RNA_IDP_UI, idprop->name)==0)
 
240
        for (idprop = ((IDProperty *)prop)->prev; idprop; idprop = idprop->prev) {
 
241
                if (strcmp(RNA_IDP_UI, idprop->name) == 0)
227
242
                        break;
228
243
        }
229
244
 
230
 
        if(idprop==NULL) {
231
 
                for(idprop= ((IDProperty *)prop)->next; idprop; idprop= idprop->next) {
232
 
                        if (strcmp(RNA_IDP_UI, idprop->name)==0)
 
245
        if (idprop == NULL) {
 
246
                for (idprop = ((IDProperty *)prop)->next; idprop; idprop = idprop->next) {
 
247
                        if (strcmp(RNA_IDP_UI, idprop->name) == 0)
233
248
                                break;
234
249
                }
235
250
        }
236
251
 
237
 
        if (idprop)
238
 
                return IDP_GetPropertyFromGroup(idprop, ((IDProperty *)prop)->name);
 
252
        if (idprop) {
 
253
                return IDP_GetPropertyTypeFromGroup(idprop, ((IDProperty *)prop)->name, IDP_GROUP);
 
254
        }
239
255
 
240
256
        return NULL;
241
257
}
242
258
 
243
 
IDProperty *RNA_struct_idproperties(PointerRNA *ptr, int create)
 
259
IDProperty *RNA_struct_idprops(PointerRNA *ptr, int create)
244
260
{
245
 
        StructRNA *type= ptr->type;
 
261
        StructRNA *type = ptr->type;
246
262
 
247
 
        if(type && type->idproperties)
 
263
        if (type && type->idproperties)
248
264
                return type->idproperties(ptr, create);
249
265
        
250
266
        return NULL;
251
267
}
252
268
 
253
 
int RNA_struct_idproperties_check(StructRNA *srna)
 
269
int RNA_struct_idprops_check(StructRNA *srna)
254
270
{
255
271
        return (srna && srna->idproperties) ? 1 : 0;
256
272
}
257
273
 
258
274
static IDProperty *rna_idproperty_find(PointerRNA *ptr, const char *name)
259
275
{
260
 
        IDProperty *group= RNA_struct_idproperties(ptr, 0);
261
 
        IDProperty *idprop;
262
 
 
263
 
        if(group) {
264
 
                for(idprop=group->data.group.first; idprop; idprop=idprop->next)
265
 
                        if(strcmp(idprop->name, name) == 0)
266
 
                                return idprop;
267
 
        }
268
 
        
 
276
        IDProperty *group = RNA_struct_idprops(ptr, 0);
 
277
 
 
278
        if (group)
 
279
                return IDP_GetPropertyFromGroup(group, name);
 
280
 
269
281
        return NULL;
270
282
}
271
283
 
272
284
static int rna_ensure_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
273
285
{
274
 
        if(prop->magic == RNA_MAGIC) {
 
286
        if (prop->magic == RNA_MAGIC) {
275
287
                int arraylen[RNA_MAX_ARRAY_DIMENSION];
276
288
                return (prop->getlength && ptr->data)? prop->getlength(ptr, arraylen): prop->totarraylength;
277
289
        }
278
290
        else {
279
 
                IDProperty *idprop= (IDProperty*)prop;
 
291
                IDProperty *idprop = (IDProperty*)prop;
280
292
 
281
 
                if(idprop->type == IDP_ARRAY)
 
293
                if (idprop->type == IDP_ARRAY)
282
294
                        return idprop->len;
283
295
                else
284
296
                        return 0;
285
297
        }
286
298
}
287
299
 
288
 
static int rna_ensure_property_array_check(PointerRNA *ptr, PropertyRNA *prop)
 
300
static int rna_ensure_property_array_check(PropertyRNA *prop)
289
301
{
290
 
        if(prop->magic == RNA_MAGIC) {
 
302
        if (prop->magic == RNA_MAGIC) {
291
303
                return (prop->getlength || prop->totarraylength) ? 1:0;
292
304
        }
293
305
        else {
294
 
                IDProperty *idprop= (IDProperty*)prop;
 
306
                IDProperty *idprop = (IDProperty*)prop;
295
307
 
296
308
                return idprop->type == IDP_ARRAY ? 1:0;
297
309
        }
299
311
 
300
312
static void rna_ensure_property_multi_array_length(PointerRNA *ptr, PropertyRNA *prop, int length[])
301
313
{
302
 
        if(prop->magic == RNA_MAGIC) {
303
 
                if(prop->getlength)
 
314
        if (prop->magic == RNA_MAGIC) {
 
315
                if (prop->getlength)
304
316
                        prop->getlength(ptr, length);
305
317
                else
306
318
                        memcpy(length, prop->arraylength, prop->arraydimension*sizeof(int));
307
319
        }
308
320
        else {
309
 
                IDProperty *idprop= (IDProperty*)prop;
 
321
                IDProperty *idprop = (IDProperty*)prop;
310
322
 
311
 
                if(idprop->type == IDP_ARRAY)
312
 
                        length[0]= idprop->len;
 
323
                if (idprop->type == IDP_ARRAY)
 
324
                        length[0] = idprop->len;
313
325
                else
314
 
                        length[0]= 0;
 
326
                        length[0] = 0;
315
327
        }
316
328
}
317
329
 
322
334
         * rna property access is type safe, e.g. if you defined the rna
323
335
         * to have a certain array length you can count on that staying so */
324
336
        
325
 
        switch(idprop->type) {
 
337
        switch (idprop->type) {
326
338
                case IDP_IDPARRAY:
327
 
                        if(prop->type != PROP_COLLECTION)
 
339
                        if (prop->type != PROP_COLLECTION)
328
340
                                return 0;
329
341
                        break;
330
342
                case IDP_ARRAY:
331
 
                        if(rna_ensure_property_array_length(ptr, prop) != idprop->len)
 
343
                        if (rna_ensure_property_array_length(ptr, prop) != idprop->len)
332
344
                                return 0;
333
345
 
334
 
                        if(idprop->subtype == IDP_FLOAT && prop->type != PROP_FLOAT)
 
346
                        if (idprop->subtype == IDP_FLOAT && prop->type != PROP_FLOAT)
335
347
                                return 0;
336
 
                        if(idprop->subtype == IDP_INT && !ELEM3(prop->type, PROP_BOOLEAN, PROP_INT, PROP_ENUM))
 
348
                        if (idprop->subtype == IDP_INT && !ELEM3(prop->type, PROP_BOOLEAN, PROP_INT, PROP_ENUM))
337
349
                                return 0;
338
350
 
339
351
                        break;
340
352
                case IDP_INT:
341
 
                        if(!ELEM3(prop->type, PROP_BOOLEAN, PROP_INT, PROP_ENUM))
 
353
                        if (!ELEM3(prop->type, PROP_BOOLEAN, PROP_INT, PROP_ENUM))
342
354
                                return 0;
343
355
                        break;
344
356
                case IDP_FLOAT:
345
357
                case IDP_DOUBLE:
346
 
                        if(prop->type != PROP_FLOAT)
 
358
                        if (prop->type != PROP_FLOAT)
347
359
                                return 0;
348
360
                        break;
349
361
                case IDP_STRING:
350
 
                        if(prop->type != PROP_STRING)
 
362
                        if (prop->type != PROP_STRING)
351
363
                                return 0;
352
364
                        break;
353
365
                case IDP_GROUP:
354
 
                        if(prop->type != PROP_POINTER)
 
366
                        if (prop->type != PROP_POINTER)
355
367
                                return 0;
356
368
                        break;
357
369
                default:
362
374
}
363
375
 
364
376
static PropertyRNA *typemap[IDP_NUMTYPES] =
365
 
        {(PropertyRNA*)&rna_IDProperty_string,
366
 
         (PropertyRNA*)&rna_IDProperty_int,
367
 
         (PropertyRNA*)&rna_IDProperty_float,
 
377
        {(PropertyRNA*)&rna_PropertyGroupItem_string,
 
378
         (PropertyRNA*)&rna_PropertyGroupItem_int,
 
379
         (PropertyRNA*)&rna_PropertyGroupItem_float,
368
380
         NULL, NULL, NULL,
369
 
         (PropertyRNA*)&rna_IDProperty_group, NULL,
370
 
         (PropertyRNA*)&rna_IDProperty_double};
 
381
         (PropertyRNA*)&rna_PropertyGroupItem_group, NULL,
 
382
         (PropertyRNA*)&rna_PropertyGroupItem_double,
 
383
         (PropertyRNA*)&rna_PropertyGroupItem_idp_array};
371
384
 
372
385
static PropertyRNA *arraytypemap[IDP_NUMTYPES] =
373
 
        {NULL, (PropertyRNA*)&rna_IDProperty_int_array,
374
 
         (PropertyRNA*)&rna_IDProperty_float_array,
 
386
        {NULL, (PropertyRNA*)&rna_PropertyGroupItem_int_array,
 
387
         (PropertyRNA*)&rna_PropertyGroupItem_float_array,
375
388
         NULL, NULL, NULL,
376
 
         (PropertyRNA*)&rna_IDProperty_collection, NULL,
377
 
         (PropertyRNA*)&rna_IDProperty_double_array};
 
389
         (PropertyRNA*)&rna_PropertyGroupItem_collection, NULL,
 
390
         (PropertyRNA*)&rna_PropertyGroupItem_double_array};
378
391
 
379
392
IDProperty *rna_idproperty_check(PropertyRNA **prop, PointerRNA *ptr)
380
393
{
385
398
         * we look up an IDP PropertyRNA based on the type, and set the data
386
399
         * pointer to the IDProperty. */
387
400
 
388
 
        if((*prop)->magic == RNA_MAGIC) {
389
 
                if((*prop)->flag & PROP_IDPROPERTY) {
390
 
                        IDProperty *idprop= rna_idproperty_find(ptr, (*prop)->identifier);
 
401
        if ((*prop)->magic == RNA_MAGIC) {
 
402
                if ((*prop)->flag & PROP_IDPROPERTY) {
 
403
                        IDProperty *idprop = rna_idproperty_find(ptr, (*prop)->identifier);
391
404
 
392
 
                        if(idprop && !rna_idproperty_verify_valid(ptr, *prop, idprop)) {
393
 
                                IDProperty *group= RNA_struct_idproperties(ptr, 0);
 
405
                        if (idprop && !rna_idproperty_verify_valid(ptr, *prop, idprop)) {
 
406
                                IDProperty *group = RNA_struct_idprops(ptr, 0);
394
407
 
395
408
                                IDP_RemFromGroup(group, idprop);
396
409
                                IDP_FreeProperty(idprop);
405
418
        }
406
419
 
407
420
        {
408
 
                IDProperty *idprop= (IDProperty*)(*prop);
 
421
                IDProperty *idprop = (IDProperty*)(*prop);
409
422
 
410
 
                if(idprop->type == IDP_ARRAY)
411
 
                        *prop= arraytypemap[(int)(idprop->subtype)];
412
 
                else 
413
 
                        *prop= typemap[(int)(idprop->type)];
 
423
                if (idprop->type == IDP_ARRAY)
 
424
                        *prop = arraytypemap[(int)(idprop->subtype)];
 
425
                else
 
426
                        *prop = typemap[(int)(idprop->type)];
414
427
 
415
428
                return idprop;
416
429
        }
420
433
{
421
434
        /* the quick version if we don't need the idproperty */
422
435
 
423
 
        if(prop->magic == RNA_MAGIC)
 
436
        if (prop->magic == RNA_MAGIC)
424
437
                return prop;
425
438
 
426
439
        {
427
 
                IDProperty *idprop= (IDProperty*)prop;
 
440
                IDProperty *idprop = (IDProperty*)prop;
428
441
 
429
 
                if(idprop->type == IDP_ARRAY)
 
442
                if (idprop->type == IDP_ARRAY)
430
443
                        return arraytypemap[(int)(idprop->subtype)];
431
 
                else 
 
444
                else
432
445
                        return typemap[(int)(idprop->type)];
433
446
        }
434
447
}
435
448
 
436
449
static const char *rna_ensure_property_identifier(PropertyRNA *prop)
437
450
{
438
 
        if(prop->magic == RNA_MAGIC)
 
451
        if (prop->magic == RNA_MAGIC)
439
452
                return prop->identifier;
440
453
        else
441
454
                return ((IDProperty*)prop)->name;
443
456
 
444
457
static const char *rna_ensure_property_description(PropertyRNA *prop)
445
458
{
446
 
        if(prop->magic == RNA_MAGIC)
447
 
                return prop->description;
 
459
        const char *description = NULL;
 
460
 
 
461
        if (prop->magic == RNA_MAGIC)
 
462
                description = prop->description;
448
463
        else {
449
464
                /* attempt to get the local ID values */
450
 
                IDProperty *idp_ui= rna_idproperty_ui(prop);
451
 
 
452
 
                if(idp_ui) { /* TODO, type checking on ID props */
453
 
 
454
 
                        IDProperty *item= IDP_GetPropertyFromGroup(idp_ui, "description");
455
 
                        if(item)
456
 
                                return (char *)item->data.pointer ;
 
465
                IDProperty *idp_ui = rna_idproperty_ui(prop);
 
466
 
 
467
                if (idp_ui) {
 
468
                        IDProperty *item = IDP_GetPropertyTypeFromGroup(idp_ui, "description", IDP_STRING);
 
469
                        if (item)
 
470
                                description = IDP_String(item);
457
471
                }
458
472
 
459
 
                return ((IDProperty*)prop)->name; /* XXX - not correct */
 
473
                if (description == NULL)
 
474
                        description = ((IDProperty*)prop)->name; /* XXX - not correct */
460
475
        }
 
476
 
 
477
        return TIP_(description);
461
478
}
462
479
 
463
480
static const char *rna_ensure_property_name(PropertyRNA *prop)
464
481
{
465
 
        if(prop->magic == RNA_MAGIC)
466
 
                return prop->name;
 
482
        const char *name;
 
483
 
 
484
        if (prop->magic == RNA_MAGIC)
 
485
                name = prop->name;
467
486
        else
468
 
                return ((IDProperty*)prop)->name;
 
487
                name = ((IDProperty*)prop)->name;
 
488
 
 
489
        return CTX_IFACE_(prop->translation_context, name);
469
490
}
470
491
 
471
492
/* Structs */
472
493
 
 
494
StructRNA *RNA_struct_find(const char *identifier)
 
495
{
 
496
        StructRNA *type;
 
497
        if (identifier) {
 
498
                for (type = BLENDER_RNA.structs.first; type; type = type->cont.next)
 
499
                        if (strcmp(type->identifier, identifier) == 0)
 
500
                                return type;
 
501
        }
 
502
        return NULL;
 
503
}
 
504
 
473
505
const char *RNA_struct_identifier(StructRNA *type)
474
506
{
475
507
        return type->identifier;
477
509
 
478
510
const char *RNA_struct_ui_name(StructRNA *type)
479
511
{
480
 
        return type->name;
 
512
        return CTX_IFACE_(type->translation_context, type->name);
481
513
}
482
514
 
483
515
int RNA_struct_ui_icon(StructRNA *type)
484
516
{
485
 
        if(type)
 
517
        if (type)
486
518
                return type->icon;
487
519
        else
488
520
                return ICON_DOT;
490
522
 
491
523
const char *RNA_struct_ui_description(StructRNA *type)
492
524
{
493
 
        return type->description;
 
525
        return TIP_(type->description);
494
526
}
495
527
 
496
528
PropertyRNA *RNA_struct_name_property(StructRNA *type)
513
545
        return (type->flag & STRUCT_ID) != 0;
514
546
}
515
547
 
 
548
int RNA_struct_undo_check(StructRNA *type)
 
549
{
 
550
        return (type->flag & STRUCT_UNDO) != 0;
 
551
}
 
552
 
 
553
int RNA_struct_idprops_register_check(StructRNA *type)
 
554
{
 
555
        return (type->flag & STRUCT_NO_IDPROPERTIES) == 0;
 
556
}
 
557
 
 
558
/* remove an id-property */
 
559
int RNA_struct_idprops_unset(PointerRNA *ptr, const char *identifier)
 
560
{
 
561
        IDProperty *group = RNA_struct_idprops(ptr, 0);
 
562
 
 
563
        if (group) {
 
564
                IDProperty *idp = IDP_GetPropertyFromGroup(group, identifier);
 
565
                if (idp) {
 
566
                        IDP_RemFromGroup(group, idp);
 
567
                        IDP_FreeProperty(idp);
 
568
                        MEM_freeN(idp);
 
569
 
 
570
                        return 1;
 
571
                }
 
572
        }
 
573
        return 0;
 
574
}
 
575
 
516
576
int RNA_struct_is_a(StructRNA *type, StructRNA *srna)
517
577
{
518
578
        StructRNA *base;
519
579
 
520
 
        if(!type)
 
580
        if (!type)
521
581
                return 0;
522
582
 
523
583
        /* ptr->type is always maximally refined */
524
 
        for(base=type; base; base=base->base)
525
 
                if(base == srna)
 
584
        for (base = type; base; base = base->base)
 
585
                if (base == srna)
526
586
                        return 1;
527
587
        
528
588
        return 0;
530
590
 
531
591
PropertyRNA *RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
532
592
{
533
 
        if(identifier[0]=='[' && identifier[1]=='"') { // "  (dummy comment to avoid confusing some function lists in text editors)
 
593
        if (identifier[0] =='[' && identifier[1] =='"') { /* "  (dummy comment to avoid confusing some
 
594
                                                           * function lists in text editors) */
534
595
                /* id prop lookup, not so common */
535
 
                PropertyRNA *r_prop= NULL;
 
596
                PropertyRNA *r_prop = NULL;
536
597
                PointerRNA r_ptr; /* only support single level props */
537
 
                if(RNA_path_resolve(ptr, identifier, &r_ptr, &r_prop) && r_ptr.type==ptr->type && r_ptr.data==ptr->data)
 
598
                if (RNA_path_resolve(ptr, identifier, &r_ptr, &r_prop) && r_ptr.type == ptr->type && r_ptr.data == ptr->data)
538
599
                        return r_prop;
539
600
        }
540
601
        else {
541
602
                /* most common case */
542
 
                PropertyRNA *iterprop= RNA_struct_iterator_property(ptr->type);
 
603
                PropertyRNA *iterprop = RNA_struct_iterator_property(ptr->type);
543
604
                PointerRNA propptr;
544
605
 
545
 
                if(RNA_property_collection_lookup_string(ptr, iterprop, identifier, &propptr))
 
606
                if (RNA_property_collection_lookup_string(ptr, iterprop, identifier, &propptr))
546
607
                        return propptr.data;
547
608
        }
548
609
        
552
613
/* Find the property which uses the given nested struct */
553
614
PropertyRNA *RNA_struct_find_nested(PointerRNA *ptr, StructRNA *srna)
554
615
{
555
 
        PropertyRNA *prop= NULL;
 
616
        PropertyRNA *prop = NULL;
556
617
 
557
618
        RNA_STRUCT_BEGIN(ptr, iprop) {
558
619
                /* This assumes that there can only be one user of this nested struct */
559
620
                if (RNA_property_pointer_type(ptr, iprop) == srna) {
560
 
                        prop= iprop;
 
621
                        prop = iprop;
561
622
                        break;
562
623
                }
563
624
        }
566
627
        return prop;
567
628
}
568
629
 
569
 
const struct ListBase *RNA_struct_defined_properties(StructRNA *srna)
 
630
int RNA_struct_contains_property(PointerRNA *ptr, PropertyRNA *prop_test)
 
631
{
 
632
        /* note, prop_test could be freed memory, only use for comparison */
 
633
 
 
634
        /* validate the RNA is ok */
 
635
        PropertyRNA *iterprop;
 
636
        int found = FALSE;
 
637
 
 
638
        iterprop = RNA_struct_iterator_property(ptr->type);
 
639
 
 
640
        RNA_PROP_BEGIN(ptr, itemptr, iterprop) {
 
641
                /* PropertyRNA *prop= itemptr.data; */
 
642
                if (prop_test == (PropertyRNA *)itemptr.data) {
 
643
                        found = TRUE;
 
644
                        break;
 
645
                }
 
646
        }
 
647
        RNA_PROP_END;
 
648
 
 
649
        return found;
 
650
}
 
651
 
 
652
/* low level direct access to type->properties, note this ignores parent classes so should be used with care */
 
653
const struct ListBase *RNA_struct_type_properties(StructRNA *srna)
570
654
{
571
655
        return &srna->cont.properties;
572
656
}
573
657
 
 
658
PropertyRNA *RNA_struct_type_find_property(StructRNA *srna, const char *identifier)
 
659
{
 
660
        return BLI_findstring_ptr(&srna->cont.properties, identifier, offsetof(PropertyRNA, identifier));
 
661
}
 
662
 
574
663
FunctionRNA *RNA_struct_find_function(PointerRNA *ptr, const char *identifier)
575
664
{
576
665
#if 1
577
666
        FunctionRNA *func;
578
667
        StructRNA *type;
579
 
        for(type= ptr->type; type; type= type->base) {
580
 
                for(func= type->functions.first; func; func= func->cont.next) {
581
 
                        if(strcmp(func->identifier, identifier)==0)
582
 
                                return func;
 
668
        for (type = ptr->type; type; type = type->base) {
 
669
                func = (FunctionRNA *)BLI_findstring_ptr(&type->functions, identifier, offsetof(FunctionRNA, identifier));
 
670
                if (func) {
 
671
                        return func;
583
672
                }
584
673
        }
585
674
        return NULL;
591
680
        FunctionRNA *func;
592
681
 
593
682
        RNA_pointer_create(NULL, &RNA_Struct, ptr->type, &tptr);
594
 
        iterprop= RNA_struct_find_property(&tptr, "functions");
 
683
        iterprop = RNA_struct_find_property(&tptr, "functions");
595
684
 
596
 
        func= NULL;
 
685
        func = NULL;
597
686
 
598
687
        RNA_PROP_BEGIN(&tptr, funcptr, iterprop) {
599
 
                if(strcmp(identifier, RNA_function_identifier(funcptr.data)) == 0) {
600
 
                        func= funcptr.data;
 
688
                if (strcmp(identifier, RNA_function_identifier(funcptr.data)) == 0) {
 
689
                        func = funcptr.data;
601
690
                        break;
602
691
                }
603
692
        }
607
696
#endif
608
697
}
609
698
 
610
 
const struct ListBase *RNA_struct_defined_functions(StructRNA *srna)
 
699
const struct ListBase *RNA_struct_type_functions(StructRNA *srna)
611
700
{
612
701
        return &srna->functions;
613
702
}
620
709
StructUnregisterFunc RNA_struct_unregister(StructRNA *type)
621
710
{
622
711
        do {
623
 
                if(type->unreg)
 
712
                if (type->unreg)
624
713
                        return type->unreg;
625
 
        } while((type=type->base));
 
714
        } while ((type = type->base));
 
715
 
 
716
        return NULL;
 
717
}
 
718
 
 
719
void **RNA_struct_instance(PointerRNA *ptr)
 
720
{
 
721
        StructRNA *type = ptr->type;
 
722
 
 
723
        do {
 
724
                if (type->instance)
 
725
                        return type->instance(ptr);
 
726
        } while ((type = type->base));
626
727
 
627
728
        return NULL;
628
729
}
634
735
 
635
736
void RNA_struct_py_type_set(StructRNA *srna, void *py_type)
636
737
{
637
 
        srna->py_type= py_type;
 
738
        srna->py_type = py_type;
638
739
}
639
740
 
640
741
void *RNA_struct_blender_type_get(StructRNA *srna)
644
745
 
645
746
void RNA_struct_blender_type_set(StructRNA *srna, void *blender_type)
646
747
{
647
 
        srna->blender_type= blender_type;
 
748
        srna->blender_type = blender_type;
648
749
}
649
750
 
650
 
char *RNA_struct_name_get_alloc(PointerRNA *ptr, char *fixedbuf, int fixedlen)
 
751
char *RNA_struct_name_get_alloc(PointerRNA *ptr, char *fixedbuf, int fixedlen, int *r_len)
651
752
{
652
753
        PropertyRNA *nameprop;
653
754
 
654
 
        if(ptr->data && (nameprop = RNA_struct_name_property(ptr->type)))
655
 
                return RNA_property_string_get_alloc(ptr, nameprop, fixedbuf, fixedlen);
 
755
        if (ptr->data && (nameprop = RNA_struct_name_property(ptr->type)))
 
756
                return RNA_property_string_get_alloc(ptr, nameprop, fixedbuf, fixedlen, r_len);
656
757
 
657
758
        return NULL;
658
759
}
689
790
        return rna_ensure_property(prop)->flag;
690
791
}
691
792
 
 
793
void *RNA_property_py_data_get(PropertyRNA *prop)
 
794
{
 
795
        return prop->py_data;
 
796
}
 
797
 
692
798
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
693
799
{
694
800
        return rna_ensure_property_array_length(ptr, prop);
695
801
}
696
802
 
697
 
int RNA_property_array_check(PointerRNA *ptr, PropertyRNA *prop)
 
803
int RNA_property_array_check(PropertyRNA *prop)
698
804
{
699
 
        return rna_ensure_property_array_check(ptr, prop);
 
805
        return rna_ensure_property_array_check(prop);
700
806
}
701
807
 
702
808
/* used by BPY to make an array from the python object */
703
809
int RNA_property_array_dimension(PointerRNA *ptr, PropertyRNA *prop, int length[])
704
810
{
705
 
        PropertyRNA *rprop= rna_ensure_property(prop);
 
811
        PropertyRNA *rprop = rna_ensure_property(prop);
706
812
 
707
 
        if(length && rprop->arraydimension > 1)
708
 
                rna_ensure_property_multi_array_length(ptr, prop, length);
 
813
        if (length)
 
814
                        rna_ensure_property_multi_array_length(ptr, prop, length);
709
815
 
710
816
        return rprop->arraydimension;
711
817
}
722
828
 
723
829
char RNA_property_array_item_char(PropertyRNA *prop, int index)
724
830
{
725
 
        const char *vectoritem= "XYZW";
726
 
        const char *quatitem= "WXYZ";
727
 
        const char *coloritem= "RGBA";
728
 
        PropertySubType subtype= rna_ensure_property(prop)->subtype;
 
831
        const char *vectoritem = "XYZW";
 
832
        const char *quatitem = "WXYZ";
 
833
        const char *coloritem = "RGBA";
 
834
        PropertySubType subtype = rna_ensure_property(prop)->subtype;
729
835
 
730
836
        /* get string to use for array index */
731
 
        if ((index < 4) && ELEM(subtype, PROP_QUATERNION, PROP_AXISANGLE))
 
837
        if ((index < 4) && ELEM(subtype, PROP_QUATERNION, PROP_AXISANGLE)) {
732
838
                return quatitem[index];
733
 
        else if((index < 4) && ELEM6(subtype, PROP_TRANSLATION, PROP_DIRECTION, PROP_XYZ, PROP_EULER, PROP_VELOCITY, PROP_ACCELERATION))
 
839
        }
 
840
        else if ((index < 4) && ELEM8(subtype, PROP_TRANSLATION, PROP_DIRECTION, PROP_XYZ, PROP_XYZ_LENGTH,
 
841
                                              PROP_EULER, PROP_VELOCITY, PROP_ACCELERATION, PROP_COORDS))
 
842
        {
734
843
                return vectoritem[index];
735
 
        else if ((index < 4) && ELEM(subtype, PROP_COLOR, PROP_COLOR_GAMMA))
 
844
        }
 
845
        else if ((index < 4) && ELEM(subtype, PROP_COLOR, PROP_COLOR_GAMMA)) {
736
846
                return coloritem[index];
 
847
        }
737
848
 
738
849
        return '\0';
739
850
}
740
851
 
741
852
int RNA_property_array_item_index(PropertyRNA *prop, char name)
742
853
{
743
 
        PropertySubType subtype= rna_ensure_property(prop)->subtype;
744
 
 
745
 
        name= toupper(name);
 
854
        PropertySubType subtype = rna_ensure_property(prop)->subtype;
746
855
 
747
856
        /* get index based on string name/alias */
748
857
        /* maybe a function to find char index in string would be better than all the switches */
749
858
        if (ELEM(subtype, PROP_QUATERNION, PROP_AXISANGLE)) {
750
859
                switch (name) {
751
 
                        case 'W':
 
860
                        case 'w':
752
861
                                return 0;
753
 
                        case 'X':
 
862
                        case 'x':
754
863
                                return 1;
755
 
                        case 'Y':
 
864
                        case 'y':
756
865
                                return 2;
757
 
                        case 'Z':
 
866
                        case 'z':
758
867
                                return 3;
759
868
                }
760
869
        }
761
 
        else if(ELEM6(subtype, PROP_TRANSLATION, PROP_DIRECTION, PROP_XYZ, PROP_EULER, PROP_VELOCITY, PROP_ACCELERATION)) {
 
870
        else if (ELEM6(subtype, PROP_TRANSLATION, PROP_DIRECTION, PROP_XYZ,
 
871
                               PROP_EULER, PROP_VELOCITY, PROP_ACCELERATION))
 
872
        {
762
873
                switch (name) {
763
 
                        case 'X':
 
874
                        case 'x':
764
875
                                return 0;
765
 
                        case 'Y':
 
876
                        case 'y':
766
877
                                return 1;
767
 
                        case 'Z':
 
878
                        case 'z':
768
879
                                return 2;
769
 
                        case 'W':
 
880
                        case 'w':
770
881
                                return 3;
771
882
                }
772
883
        }
773
884
        else if (ELEM(subtype, PROP_COLOR, PROP_COLOR_GAMMA)) {
774
885
                switch (name) {
775
 
                        case 'R':
 
886
                        case 'r':
776
887
                                return 0;
777
 
                        case 'G':
 
888
                        case 'g':
778
889
                                return 1;
779
 
                        case 'B':
 
890
                        case 'b':
780
891
                                return 2;
781
 
                        case 'A':
 
892
                        case 'a':
782
893
                                return 3;
783
894
                }
784
895
        }
786
897
        return -1;
787
898
}
788
899
 
 
900
 
789
901
void RNA_property_int_range(PointerRNA *ptr, PropertyRNA *prop, int *hardmin, int *hardmax)
790
902
{
791
 
        IntPropertyRNA *iprop= (IntPropertyRNA*)rna_ensure_property(prop);
 
903
        IntPropertyRNA *iprop = (IntPropertyRNA*)rna_ensure_property(prop);
 
904
        int softmin, softmax;
792
905
 
793
 
        if(prop->magic != RNA_MAGIC) {
 
906
        if (prop->magic != RNA_MAGIC) {
794
907
                /* attempt to get the local ID values */
795
 
                IDProperty *idp_ui= rna_idproperty_ui(prop);
796
 
                IDProperty *item;
797
 
 
798
 
                if(idp_ui) { /* TODO, type checking on ID props */
799
 
                        item= IDP_GetPropertyFromGroup(idp_ui, "min");
800
 
                        *hardmin= item ? item->data.val : INT_MIN;
801
 
 
802
 
                        item= IDP_GetPropertyFromGroup(idp_ui, "max");
803
 
                        *hardmax= item ? item->data.val : INT_MAX;
 
908
                IDProperty *idp_ui = rna_idproperty_ui(prop);
 
909
 
 
910
                if (idp_ui) {
 
911
                        IDProperty *item;
 
912
 
 
913
                        item = IDP_GetPropertyTypeFromGroup(idp_ui, "min", IDP_INT);
 
914
                        *hardmin = item ? IDP_Int(item) : INT_MIN;
 
915
 
 
916
                        item = IDP_GetPropertyTypeFromGroup(idp_ui, "max", IDP_INT);
 
917
                        *hardmax = item ? IDP_Int(item) : INT_MAX;
804
918
 
805
919
                        return;
806
920
                }
807
921
        }
808
922
 
809
 
        if(iprop->range) {
810
 
                iprop->range(ptr, hardmin, hardmax);
 
923
        if (iprop->range) {
 
924
                *hardmin = INT_MIN;
 
925
                *hardmax = INT_MAX;
 
926
 
 
927
                iprop->range(ptr, hardmin, hardmax, &softmin, &softmax);
811
928
        }
812
929
        else {
813
 
                *hardmin= iprop->hardmin;
814
 
                *hardmax= iprop->hardmax;
 
930
                *hardmin = iprop->hardmin;
 
931
                *hardmax = iprop->hardmax;
815
932
        }
816
933
}
817
934
 
818
935
void RNA_property_int_ui_range(PointerRNA *ptr, PropertyRNA *prop, int *softmin, int *softmax, int *step)
819
936
{
820
 
        IntPropertyRNA *iprop= (IntPropertyRNA*)rna_ensure_property(prop);
 
937
        IntPropertyRNA *iprop = (IntPropertyRNA*)rna_ensure_property(prop);
821
938
        int hardmin, hardmax;
822
939
        
823
 
        if(prop->magic != RNA_MAGIC) {
 
940
        if (prop->magic != RNA_MAGIC) {
824
941
                /* attempt to get the local ID values */
825
 
                IDProperty *idp_ui= rna_idproperty_ui(prop);
826
 
                IDProperty *item;
827
 
 
828
 
                if(idp_ui) { /* TODO, type checking on ID props */
829
 
                        item= IDP_GetPropertyFromGroup(idp_ui, "soft_min");
830
 
                        *softmin= item ? item->data.val : INT_MIN;
831
 
 
832
 
                        item= IDP_GetPropertyFromGroup(idp_ui, "soft_max");
833
 
                        *softmax= item ? item->data.val : INT_MAX;
834
 
 
835
 
                        item= IDP_GetPropertyFromGroup(idp_ui, "step");
836
 
                        *step= item ? item->data.val : 1;
 
942
                IDProperty *idp_ui = rna_idproperty_ui(prop);
 
943
 
 
944
                if (idp_ui) {
 
945
                        IDProperty *item;
 
946
 
 
947
                        item = IDP_GetPropertyTypeFromGroup(idp_ui, "soft_min", IDP_INT);
 
948
                        *softmin = item ? IDP_Int(item) : INT_MIN;
 
949
 
 
950
                        item = IDP_GetPropertyTypeFromGroup(idp_ui, "soft_max", IDP_INT);
 
951
                        *softmax = item ? IDP_Int(item) : INT_MAX;
 
952
 
 
953
                        item = IDP_GetPropertyTypeFromGroup(idp_ui, "step", IDP_INT);
 
954
                        *step = item ? IDP_Int(item) : 1;
837
955
 
838
956
                        return;
839
957
                }
840
958
        }
841
959
 
842
 
        if(iprop->range) {
843
 
                iprop->range(ptr, &hardmin, &hardmax);
844
 
                *softmin= MAX2(iprop->softmin, hardmin);
845
 
                *softmax= MIN2(iprop->softmax, hardmax);
846
 
        }
847
 
        else {
848
 
                *softmin= iprop->softmin;
849
 
                *softmax= iprop->softmax;
850
 
        }
851
 
 
852
 
        *step= iprop->step;
 
960
        *softmin = iprop->softmin;
 
961
        *softmax = iprop->softmax;
 
962
 
 
963
        if (iprop->range) {
 
964
                hardmin = INT_MIN;
 
965
                hardmax = INT_MAX;
 
966
 
 
967
                iprop->range(ptr, &hardmin, &hardmax, softmin, softmax);
 
968
 
 
969
                *softmin = MAX2(*softmin, hardmin);
 
970
                *softmax = MIN2(*softmax, hardmax);
 
971
        }
 
972
 
 
973
        *step = iprop->step;
853
974
}
854
975
 
855
976
void RNA_property_float_range(PointerRNA *ptr, PropertyRNA *prop, float *hardmin, float *hardmax)
856
977
{
857
 
        FloatPropertyRNA *fprop= (FloatPropertyRNA*)rna_ensure_property(prop);
 
978
        FloatPropertyRNA *fprop = (FloatPropertyRNA*)rna_ensure_property(prop);
 
979
        float softmin, softmax;
858
980
 
859
 
        if(prop->magic != RNA_MAGIC) {
 
981
        if (prop->magic != RNA_MAGIC) {
860
982
                /* attempt to get the local ID values */
861
 
                IDProperty *idp_ui= rna_idproperty_ui(prop);
862
 
                IDProperty *item;
863
 
 
864
 
                if(idp_ui) { /* TODO, type checking on ID props */
865
 
                        item= IDP_GetPropertyFromGroup(idp_ui, "min");
866
 
                        *hardmin= item ? *(double*)&item->data.val : FLT_MIN;
867
 
 
868
 
                        item= IDP_GetPropertyFromGroup(idp_ui, "max");
869
 
                        *hardmax= item ? *(double*)&item->data.val : FLT_MAX;
 
983
                IDProperty *idp_ui = rna_idproperty_ui(prop);
 
984
 
 
985
                if (idp_ui) {
 
986
                        IDProperty *item;
 
987
 
 
988
                        item = IDP_GetPropertyTypeFromGroup(idp_ui, "min", IDP_DOUBLE);
 
989
                        *hardmin = item ? (float)IDP_Double(item) : FLT_MIN;
 
990
 
 
991
                        item = IDP_GetPropertyTypeFromGroup(idp_ui, "max", IDP_DOUBLE);
 
992
                        *hardmax = item ? (float)IDP_Double(item) : FLT_MAX;
870
993
 
871
994
                        return;
872
995
                }
873
996
        }
874
997
 
875
 
        if(fprop->range) {
876
 
                fprop->range(ptr, hardmin, hardmax);
 
998
        if (fprop->range) {
 
999
                *hardmin = -FLT_MAX;
 
1000
                *hardmax = FLT_MAX;
 
1001
 
 
1002
                fprop->range(ptr, hardmin, hardmax, &softmin, &softmax);
877
1003
        }
878
1004
        else {
879
 
                *hardmin= fprop->hardmin;
880
 
                *hardmax= fprop->hardmax;
 
1005
                *hardmin = fprop->hardmin;
 
1006
                *hardmax = fprop->hardmax;
881
1007
        }
882
1008
}
883
1009
 
884
 
void RNA_property_float_ui_range(PointerRNA *ptr, PropertyRNA *prop, float *softmin, float *softmax, float *step, float *precision)
 
1010
void RNA_property_float_ui_range(PointerRNA *ptr, PropertyRNA *prop, float *softmin, float *softmax,
 
1011
                                 float *step, float *precision)
885
1012
{
886
 
        FloatPropertyRNA *fprop= (FloatPropertyRNA*)rna_ensure_property(prop);
 
1013
        FloatPropertyRNA *fprop = (FloatPropertyRNA*)rna_ensure_property(prop);
887
1014
        float hardmin, hardmax;
888
1015
 
889
 
        if(prop->magic != RNA_MAGIC) {
 
1016
        if (prop->magic != RNA_MAGIC) {
890
1017
                /* attempt to get the local ID values */
891
 
                IDProperty *idp_ui= rna_idproperty_ui(prop);
892
 
                IDProperty *item;
893
 
 
894
 
                if(idp_ui) { /* TODO, type checking on ID props */
895
 
                        item= IDP_GetPropertyFromGroup(idp_ui, "soft_min");
896
 
                        *softmin= item ? *(double*)&item->data.val : FLT_MIN;
897
 
 
898
 
                        item= IDP_GetPropertyFromGroup(idp_ui, "soft_max");
899
 
                        *softmax= item ? *(double*)&item->data.val : FLT_MAX;
900
 
 
901
 
                        item= IDP_GetPropertyFromGroup(idp_ui, "step");
902
 
                        *step= item ? *(double*)&item->data.val : 1.0f;
903
 
 
904
 
                        item= IDP_GetPropertyFromGroup(idp_ui, "precision");
905
 
                        *precision= item ? *(double*)&item->data.val : 3.0f;
 
1018
                IDProperty *idp_ui = rna_idproperty_ui(prop);
 
1019
 
 
1020
                if (idp_ui) {
 
1021
                        IDProperty *item;
 
1022
 
 
1023
                        item = IDP_GetPropertyTypeFromGroup(idp_ui, "soft_min", IDP_DOUBLE);
 
1024
                        *softmin = item ? (float)IDP_Double(item) : FLT_MIN;
 
1025
 
 
1026
                        item = IDP_GetPropertyTypeFromGroup(idp_ui, "soft_max", IDP_DOUBLE);
 
1027
                        *softmax = item ? (float)IDP_Double(item) : FLT_MAX;
 
1028
 
 
1029
                        item = IDP_GetPropertyTypeFromGroup(idp_ui, "step", IDP_DOUBLE);
 
1030
                        *step = item ? (float)IDP_Double(item) : 1.0f;
 
1031
 
 
1032
                        item = IDP_GetPropertyTypeFromGroup(idp_ui, "precision", IDP_DOUBLE);
 
1033
                        *precision = item ? (float)IDP_Double(item) : 3.0f;
906
1034
 
907
1035
                        return;
908
1036
                }
909
1037
        }
910
1038
 
911
 
        if(fprop->range) {
912
 
                fprop->range(ptr, &hardmin, &hardmax);
913
 
                *softmin= MAX2(fprop->softmin, hardmin);
914
 
                *softmax= MIN2(fprop->softmax, hardmax);
915
 
        }
916
 
        else {
917
 
                *softmin= fprop->softmin;
918
 
                *softmax= fprop->softmax;
919
 
        }
920
 
 
921
 
        *step= fprop->step;
922
 
        *precision= (float)fprop->precision;
 
1039
        *softmin = fprop->softmin;
 
1040
        *softmax = fprop->softmax;
 
1041
 
 
1042
        if (fprop->range) {
 
1043
                hardmin = -FLT_MAX;
 
1044
                hardmax = FLT_MAX;
 
1045
 
 
1046
                fprop->range(ptr, &hardmin, &hardmax, softmin, softmax);
 
1047
 
 
1048
                *softmin = MAX2(*softmin, hardmin);
 
1049
                *softmax = MIN2(*softmax, hardmax);
 
1050
        }
 
1051
 
 
1052
        *step = fprop->step;
 
1053
        *precision = (float)fprop->precision;
923
1054
}
924
1055
 
925
1056
int RNA_property_float_clamp(PointerRNA *ptr, PropertyRNA *prop, float *value)
928
1059
 
929
1060
        RNA_property_float_range(ptr, prop, &min, &max);
930
1061
 
931
 
        if(*value < min) {
932
 
                *value= min;
 
1062
        if (*value < min) {
 
1063
                *value = min;
933
1064
                return -1;
934
1065
        }
935
 
        else if(*value > max) {
936
 
                *value= max;
 
1066
        else if (*value > max) {
 
1067
                *value = max;
937
1068
                return 1;
938
1069
        }
939
1070
        else {
947
1078
 
948
1079
        RNA_property_int_range(ptr, prop, &min, &max);
949
1080
 
950
 
        if(*value < min) {
951
 
                *value= min;
 
1081
        if (*value < min) {
 
1082
                *value = min;
952
1083
                return -1;
953
1084
        }
954
 
        else if(*value > max) {
955
 
                *value= max;
 
1085
        else if (*value > max) {
 
1086
                *value = max;
956
1087
                return 1;
957
1088
        }
958
1089
        else {
964
1095
 * '0' used when their is no maximum */
965
1096
int RNA_property_string_maxlength(PropertyRNA *prop)
966
1097
{
967
 
        StringPropertyRNA *sprop= (StringPropertyRNA*)rna_ensure_property(prop);
 
1098
        StringPropertyRNA *sprop = (StringPropertyRNA*)rna_ensure_property(prop);
968
1099
        return sprop->maxlength;
969
1100
}
970
1101
 
971
1102
StructRNA *RNA_property_pointer_type(PointerRNA *ptr, PropertyRNA *prop)
972
1103
{
973
 
        prop= rna_ensure_property(prop);
974
 
 
975
 
        if(prop->type == PROP_POINTER) {
976
 
                PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
977
 
 
978
 
                if(pprop->typef)
 
1104
        prop = rna_ensure_property(prop);
 
1105
 
 
1106
        if (prop->type == PROP_POINTER) {
 
1107
                PointerPropertyRNA *pprop = (PointerPropertyRNA*)prop;
 
1108
 
 
1109
                if (pprop->typef)
979
1110
                        return pprop->typef(ptr);
980
 
                else if(pprop->type)
 
1111
                else if (pprop->type)
981
1112
                        return pprop->type;
982
1113
        }
983
 
        else if(prop->type == PROP_COLLECTION) {
984
 
                CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
 
1114
        else if (prop->type == PROP_COLLECTION) {
 
1115
                CollectionPropertyRNA *cprop = (CollectionPropertyRNA*)prop;
985
1116
 
986
 
                if(cprop->item_type)
 
1117
                if (cprop->item_type)
987
1118
                        return cprop->item_type;
988
1119
        }
 
1120
        /* ignore other types, RNA_struct_find_nested calls with unchecked props */
989
1121
 
990
1122
        return &RNA_UnknownType;
991
1123
}
992
1124
 
 
1125
int RNA_property_pointer_poll(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *value)
 
1126
{
 
1127
        prop = rna_ensure_property(prop);
 
1128
 
 
1129
        if (prop->type == PROP_POINTER) {
 
1130
                PointerPropertyRNA *pprop = (PointerPropertyRNA*)prop;
 
1131
                if (pprop->poll)
 
1132
                        return pprop->poll(ptr, *value);
 
1133
 
 
1134
                return 1;
 
1135
        }
 
1136
 
 
1137
        printf("%s %s: is not a pointer property.\n", __func__, prop->identifier);
 
1138
        return 0;
 
1139
}
 
1140
 
993
1141
/* Reuse for dynamic types  */
994
1142
EnumPropertyItem DummyRNA_NULL_items[] = {
995
1143
        {0, NULL, 0, NULL, NULL}
1001
1149
        {0, NULL, 0, NULL, NULL}
1002
1150
};
1003
1151
 
1004
 
void RNA_property_enum_items(bContext *C, PointerRNA *ptr, PropertyRNA *prop, EnumPropertyItem **item, int *totitem, int *free)
 
1152
void RNA_property_enum_items(bContext *C, PointerRNA *ptr, PropertyRNA *prop, EnumPropertyItem **item,
 
1153
                             int *totitem, int *free)
1005
1154
{
1006
 
        EnumPropertyRNA *eprop= (EnumPropertyRNA*)rna_ensure_property(prop);
1007
 
 
1008
 
        *free= 0;
1009
 
 
1010
 
        if(eprop->itemf && (C != NULL || (prop->flag & PROP_ENUM_NO_CONTEXT))) {
1011
 
                int tot= 0;
 
1155
        EnumPropertyRNA *eprop = (EnumPropertyRNA*)rna_ensure_property(prop);
 
1156
 
 
1157
        *free = 0;
 
1158
 
 
1159
        if (eprop->itemf && (C != NULL || (prop->flag & PROP_ENUM_NO_CONTEXT))) {
 
1160
                int tot = 0;
1012
1161
 
1013
1162
                if (prop->flag & PROP_ENUM_NO_CONTEXT)
1014
 
                        *item= eprop->itemf(NULL, ptr, free);
 
1163
                        *item = eprop->itemf(NULL, ptr, prop, free);
1015
1164
                else
1016
 
                        *item= eprop->itemf(C, ptr, free);
 
1165
                        *item = eprop->itemf(C, ptr, prop, free);
1017
1166
 
1018
 
                if(totitem) {
1019
 
                        if(*item) {
1020
 
                                for( ; (*item)[tot].identifier; tot++);
 
1167
                if (totitem) {
 
1168
                        if (*item) {
 
1169
                                for ( ; (*item)[tot].identifier; tot++);
1021
1170
                        }
1022
1171
 
1023
 
                        *totitem= tot;
 
1172
                        *totitem = tot;
1024
1173
                }
 
1174
 
1025
1175
        }
1026
1176
        else {
1027
 
                *item= eprop->item;
1028
 
                if(totitem)
1029
 
                        *totitem= eprop->totitem;
1030
 
        }
1031
 
}
 
1177
                *item = eprop->item;
 
1178
                if (totitem)
 
1179
                        *totitem = eprop->totitem;
 
1180
        }
 
1181
}
 
1182
 
 
1183
void RNA_property_enum_items_gettexted(bContext *C, PointerRNA *ptr, PropertyRNA *prop,
 
1184
                                       EnumPropertyItem **item, int *totitem, int *free)
 
1185
{
 
1186
        RNA_property_enum_items(C, ptr, prop, item, totitem, free);
 
1187
 
 
1188
#ifdef WITH_INTERNATIONAL
 
1189
        /* Note: keep directly using BLF_gettext here, has we have already done tests like BLF_translate_iface... */
 
1190
        if (BLF_translate_iface()) {
 
1191
                int i;
 
1192
                EnumPropertyItem *nitem;
 
1193
 
 
1194
                if (*free) {
 
1195
                        nitem = *item;
 
1196
                }
 
1197
                else {
 
1198
                        int totitem = 0;
 
1199
 
 
1200
                        /* count */
 
1201
                        for (i = 0; (*item)[i].identifier; i++)
 
1202
                                totitem++;
 
1203
 
 
1204
                        nitem = MEM_callocN(sizeof(EnumPropertyItem)*(totitem+1), "enum_items_gettexted");
 
1205
 
 
1206
                        for (i = 0; (*item)[i].identifier; i++)
 
1207
                                nitem[i] = (*item)[i];
 
1208
 
 
1209
                        *free = 1;
 
1210
                }
 
1211
 
 
1212
                for (i = 0; nitem[i].identifier; i++) {
 
1213
                        if ( nitem[i].name ) {
 
1214
                                if (prop->translation_context)
 
1215
                                        nitem[i].name = BLF_pgettext(prop->translation_context, nitem[i].name);
 
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);
 
1221
                }
 
1222
 
 
1223
                *item = nitem;
 
1224
        }
 
1225
#endif
 
1226
}
 
1227
 
1032
1228
 
1033
1229
int RNA_property_enum_value(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const char *identifier, int *value)
1034
 
{       
 
1230
{
1035
1231
        EnumPropertyItem *item, *item_array;
1036
1232
        int free, found;
1037
 
        
 
1233
 
1038
1234
        RNA_property_enum_items(C, ptr, prop, &item_array, NULL, &free);
1039
 
        
1040
 
        for(item= item_array; item->identifier; item++) {
1041
 
                if(item->identifier[0] && strcmp(item->identifier, identifier)==0) {
1042
 
                        *value = item->value;
1043
 
                        break;
1044
 
                }
1045
 
        }
1046
 
        
1047
 
        found= (item->identifier != NULL); /* could be alloc'd, assign before free */
1048
 
 
1049
 
        if(free)
1050
 
                MEM_freeN(item_array);
1051
 
 
 
1235
 
 
1236
        if (item_array) {
 
1237
                for (item = item_array; item->identifier; item++) {
 
1238
                        if (item->identifier[0] && strcmp(item->identifier, identifier) == 0) {
 
1239
                                *value = item->value;
 
1240
                                break;
 
1241
                        }
 
1242
                }
 
1243
 
 
1244
                found = (item->identifier != NULL); /* could be alloc'd, assign before free */
 
1245
 
 
1246
                if (free) {
 
1247
                        MEM_freeN(item_array);
 
1248
                }
 
1249
        }
 
1250
        else {
 
1251
                found = 0;
 
1252
        }
1052
1253
        return found;
1053
1254
}
1054
1255
 
1055
1256
int RNA_enum_identifier(EnumPropertyItem *item, const int value, const char **identifier)
1056
1257
{
1057
1258
        for (; item->identifier; item++) {
1058
 
                if(item->identifier[0] && item->value==value) {
 
1259
                if (item->identifier[0] && item->value == value) {
1059
1260
                        *identifier = item->identifier;
1060
1261
                        return 1;
1061
1262
                }
1065
1266
 
1066
1267
int RNA_enum_bitflag_identifiers(EnumPropertyItem *item, const int value, const char **identifier)
1067
1268
{
1068
 
        int index= 0;
 
1269
        int index = 0;
1069
1270
        for (; item->identifier; item++) {
1070
 
                if(item->identifier[0] && item->value & value) {
 
1271
                if (item->identifier[0] && item->value & value) {
1071
1272
                        identifier[index++] = item->identifier;
1072
1273
                }
1073
1274
        }
1074
 
        identifier[index]= NULL;
 
1275
        identifier[index] = NULL;
1075
1276
        return index;
1076
1277
}
1077
1278
 
1078
1279
int RNA_enum_name(EnumPropertyItem *item, const int value, const char **name)
1079
1280
{
1080
1281
        for (; item->identifier; item++) {
1081
 
                if(item->identifier[0] && item->value==value) {
 
1282
                if (item->identifier[0] && item->value == value) {
1082
1283
                        *name = item->name;
1083
1284
                        return 1;
1084
1285
                }
1089
1290
int RNA_enum_description(EnumPropertyItem *item, const int value, const char **description)
1090
1291
{
1091
1292
        for (; item->identifier; item++) {
1092
 
                if(item->identifier[0] && item->value==value) {
 
1293
                if (item->identifier[0] && item->value == value) {
1093
1294
                        *description = item->description;
1094
1295
                        return 1;
1095
1296
                }
1097
1298
        return 0;
1098
1299
}
1099
1300
 
1100
 
int RNA_property_enum_identifier(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **identifier)
1101
 
{       
1102
 
        EnumPropertyItem *item= NULL;
 
1301
int RNA_property_enum_identifier(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value,
 
1302
                                 const char **identifier)
 
1303
{
 
1304
        EnumPropertyItem *item = NULL;
1103
1305
        int result, free;
1104
1306
        
1105
1307
        RNA_property_enum_items(C, ptr, prop, &item, NULL, &free);
1106
 
        if(item) {
1107
 
                result= RNA_enum_identifier(item, value, identifier);
1108
 
                if(free)
 
1308
        if (item) {
 
1309
                result = RNA_enum_identifier(item, value, identifier);
 
1310
                if (free)
1109
1311
                        MEM_freeN(item);
1110
1312
 
1111
1313
                return result;
1114
1316
}
1115
1317
 
1116
1318
int RNA_property_enum_name(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **name)
1117
 
{       
1118
 
        EnumPropertyItem *item= NULL;
 
1319
{
 
1320
        EnumPropertyItem *item = NULL;
1119
1321
        int result, free;
1120
1322
        
1121
1323
        RNA_property_enum_items(C, ptr, prop, &item, NULL, &free);
1122
 
        if(item) {
1123
 
                result= RNA_enum_name(item, value, name);
1124
 
                if(free)
 
1324
        if (item) {
 
1325
                result = RNA_enum_name(item, value, name);
 
1326
                if (free)
1125
1327
                        MEM_freeN(item);
1126
1328
                
1127
1329
                return result;
1129
1331
        return 0;
1130
1332
}
1131
1333
 
1132
 
int RNA_property_enum_bitflag_identifiers(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **identifier)
 
1334
int RNA_property_enum_bitflag_identifiers(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value,
 
1335
                                          const char **identifier)
1133
1336
{
1134
 
        EnumPropertyItem *item= NULL;
 
1337
        EnumPropertyItem *item = NULL;
1135
1338
        int result, free;
1136
1339
 
1137
1340
        RNA_property_enum_items(C, ptr, prop, &item, NULL, &free);
1138
 
        if(item) {
1139
 
                result= RNA_enum_bitflag_identifiers(item, value, identifier);
1140
 
                if(free)
 
1341
        if (item) {
 
1342
                result = RNA_enum_bitflag_identifiers(item, value, identifier);
 
1343
                if (free)
1141
1344
                        MEM_freeN(item);
1142
1345
 
1143
1346
                return result;
1162
1365
 
1163
1366
int RNA_property_editable(PointerRNA *ptr, PropertyRNA *prop)
1164
1367
{
1165
 
        ID *id= ptr->id.data;
 
1368
        ID *id = ptr->id.data;
1166
1369
        int flag;
1167
1370
 
1168
 
        prop= rna_ensure_property(prop);
1169
 
        flag= prop->editable ? prop->editable(ptr) : prop->flag;
 
1371
        prop = rna_ensure_property(prop);
 
1372
        flag = prop->editable ? prop->editable(ptr) : prop->flag;
1170
1373
        return (flag & PROP_EDITABLE) && (!id || !id->lib || (prop->flag & PROP_LIB_EXCEPTION));
1171
1374
}
1172
1375
 
1174
1377
{
1175
1378
        int flag;
1176
1379
 
1177
 
        prop= rna_ensure_property(prop);
1178
 
        flag= prop->editable ? prop->editable(ptr) : prop->flag;
 
1380
        prop = rna_ensure_property(prop);
 
1381
        flag = prop->editable ? prop->editable(ptr) : prop->flag;
1179
1382
        return (flag & PROP_EDITABLE);
1180
1383
}
1181
1384
 
1185
1388
        ID *id;
1186
1389
        int flag;
1187
1390
 
1188
 
        prop= rna_ensure_property(prop);
 
1391
        prop = rna_ensure_property(prop);
1189
1392
 
1190
 
        flag= prop->flag;
 
1393
        flag = prop->flag;
1191
1394
        
1192
 
        if(prop->editable)
 
1395
        if (prop->editable)
1193
1396
                flag &= prop->editable(ptr);
1194
1397
 
1195
1398
        if (prop->itemeditable)
1196
1399
                flag &= prop->itemeditable(ptr, index);
1197
1400
 
1198
 
        id= ptr->id.data;
 
1401
        id = ptr->id.data;
1199
1402
 
1200
1403
        return (flag & PROP_EDITABLE) && (!id || !id->lib || (prop->flag & PROP_LIB_EXCEPTION));
1201
1404
}
1206
1409
        if (!id_type_can_have_animdata(ptr->id.data))
1207
1410
                return 0;
1208
1411
        
1209
 
        prop= rna_ensure_property(prop);
 
1412
        prop = rna_ensure_property(prop);
1210
1413
 
1211
 
        if(!(prop->flag & PROP_ANIMATABLE))
 
1414
        if (!(prop->flag & PROP_ANIMATABLE))
1212
1415
                return 0;
1213
1416
 
1214
1417
        return (prop->flag & PROP_EDITABLE);
1215
1418
}
1216
1419
 
1217
 
int RNA_property_animated(PointerRNA *ptr, PropertyRNA *prop)
 
1420
int RNA_property_animated(PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop))
1218
1421
{
1219
1422
        /* would need to ask animation system */
1220
1423
 
1221
1424
        return 0;
1222
1425
}
1223
1426
 
 
1427
 
 
1428
/* this function is to check if its possible to create a valid path from the ID
 
1429
 * its slow so don't call in a loop */
 
1430
int RNA_property_path_from_ID_check(PointerRNA *ptr, PropertyRNA *prop)
 
1431
{
 
1432
        char *path = RNA_path_from_ID_to_property(ptr, prop);
 
1433
        int ret = 0;
 
1434
 
 
1435
        if (path) {
 
1436
                PointerRNA id_ptr;
 
1437
                PointerRNA r_ptr;
 
1438
                PropertyRNA *r_prop;
 
1439
 
 
1440
                RNA_id_pointer_create(ptr->id.data, &id_ptr);
 
1441
                if (RNA_path_resolve(&id_ptr, path, &r_ptr, &r_prop) == TRUE) {
 
1442
                        ret = (prop == r_prop);
 
1443
                }
 
1444
                else {
 
1445
                        ret = FALSE;
 
1446
                }
 
1447
                MEM_freeN(path);
 
1448
        }
 
1449
 
 
1450
        return ret;
 
1451
}
 
1452
 
 
1453
 
1224
1454
static void rna_property_update(bContext *C, Main *bmain, Scene *scene, PointerRNA *ptr, PropertyRNA *prop)
1225
1455
{
1226
1456
        int is_rna = (prop->magic == RNA_MAGIC);
1227
 
        prop= rna_ensure_property(prop);
 
1457
        prop = rna_ensure_property(prop);
1228
1458
 
1229
 
        if(is_rna) {
1230
 
                if(prop->update) {
 
1459
        if (is_rna) {
 
1460
                if (prop->update) {
1231
1461
                        /* ideally no context would be needed for update, but there's some
1232
 
                           parts of the code that need it still, so we have this exception */
1233
 
                        if(prop->flag & PROP_CONTEXT_UPDATE) {
1234
 
                                if(C) ((ContextUpdateFunc)prop->update)(C, ptr);
 
1462
                         * parts of the code that need it still, so we have this exception */
 
1463
                        if (prop->flag & PROP_CONTEXT_UPDATE) {
 
1464
                                if (C) {
 
1465
                                        if (prop->flag & PROP_CONTEXT_PROPERTY_UPDATE) {
 
1466
                                                ((ContextPropUpdateFunc)prop->update)(C, ptr, prop);
 
1467
                                        }
 
1468
                                        else {
 
1469
                                                ((ContextUpdateFunc)prop->update)(C, ptr);
 
1470
                                        }
 
1471
                                }
1235
1472
                        }
1236
1473
                        else
1237
1474
                                prop->update(bmain, scene, ptr);
1238
1475
                }
1239
 
                if(prop->noteflag)
 
1476
                if (prop->noteflag)
1240
1477
                        WM_main_add_notifier(prop->noteflag, ptr->id.data);
1241
1478
        }
1242
 
        else {
 
1479
        
 
1480
        if (!is_rna || (prop->flag & PROP_IDPROPERTY)) {
1243
1481
                /* WARNING! This is so property drivers update the display!
1244
1482
                 * not especially nice  */
1245
 
                DAG_id_flush_update(ptr->id.data, OB_RECALC_ALL);
 
1483
                DAG_id_tag_update(ptr->id.data, OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME);
1246
1484
                WM_main_add_notifier(NC_WINDOW, NULL);
1247
1485
        }
 
1486
}
1248
1487
 
 
1488
/* must keep in sync with 'rna_property_update'
 
1489
 * note, its possible this returns a false positive in the case of PROP_CONTEXT_UPDATE
 
1490
 * but this isn't likely to be a performance problem. */
 
1491
int RNA_property_update_check(PropertyRNA *prop)
 
1492
{
 
1493
        return (prop->magic != RNA_MAGIC || prop->update || prop->noteflag);
1249
1494
}
1250
1495
 
1251
1496
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
1258
1503
        rna_property_update(NULL, bmain, scene, ptr, prop);
1259
1504
}
1260
1505
 
 
1506
 
 
1507
/* RNA Updates Cache ------------------------ */
 
1508
/* Overview of RNA Update cache system:
 
1509
 *
 
1510
 * RNA Update calls need to be cached in order to maintain reasonable performance
 
1511
 * of the animation system (i.e. maintaining a somewhat interactive framerate)
 
1512
 * while still allowing updates to be called (necessary in particular for modifier
 
1513
 * property updates to actually work).
 
1514
 *
 
1515
 * The cache is structured with a dual-layer structure
 
1516
 * - L1 = PointerRNA used as key; id.data is used (it should always be defined,
 
1517
 *               and most updates end up using just that anyways)
 
1518
 * - L2 = Update functions to be called on those PointerRNA's
 
1519
 */
 
1520
 
 
1521
/* cache element */
 
1522
typedef struct tRnaUpdateCacheElem {
 
1523
        struct tRnaUpdateCacheElem *next, *prev;
 
1524
        
 
1525
        PointerRNA ptr;         /* L1 key - id as primary, data secondary/ignored? */
 
1526
        ListBase L2Funcs;       /* L2 functions (LinkData<RnaUpdateFuncRef>) */
 
1527
} tRnaUpdateCacheElem;
 
1528
 
 
1529
/* cache global (tRnaUpdateCacheElem's) - only accessible using these API calls */
 
1530
static ListBase rna_updates_cache = {NULL, NULL};
 
1531
 
 
1532
/* ........................... */
 
1533
 
 
1534
void RNA_property_update_cache_add(PointerRNA *ptr, PropertyRNA *prop)
 
1535
{
 
1536
        tRnaUpdateCacheElem *uce = NULL;
 
1537
        UpdateFunc fn = NULL;
 
1538
        LinkData *ld;
 
1539
        short is_rna = (prop->magic == RNA_MAGIC);
 
1540
        
 
1541
        /* sanity check */
 
1542
        if (ELEM(NULL, ptr, prop))
 
1543
                return;
 
1544
                
 
1545
        prop = rna_ensure_property(prop);
 
1546
        
 
1547
        /* we can only handle update calls with no context args for now (makes animsys updates easier) */
 
1548
        if ((is_rna == 0) || (prop->update == NULL) || (prop->flag & PROP_CONTEXT_UPDATE))
 
1549
                return;
 
1550
        fn = prop->update;
 
1551
                
 
1552
        /* find cache element for which key matches... */
 
1553
        for (uce = rna_updates_cache.first; uce; uce = uce->next) {
 
1554
                /* just match by id only for now, since most update calls that we'll encounter only really care about this */
 
1555
                /* TODO: later, the cache might need to have some nesting on L1 to cope better
 
1556
                 * with these problems + some tagging to indicate we need this */
 
1557
                if (uce->ptr.id.data == ptr->id.data)
 
1558
                        break;
 
1559
        }
 
1560
        if (uce == NULL) {
 
1561
                /* create new instance */
 
1562
                uce = MEM_callocN(sizeof(tRnaUpdateCacheElem), "tRnaUpdateCacheElem");
 
1563
                BLI_addtail(&rna_updates_cache, uce);
 
1564
                
 
1565
                /* copy pointer */
 
1566
                RNA_pointer_create(ptr->id.data, ptr->type, ptr->data, &uce->ptr);
 
1567
        }
 
1568
        
 
1569
        /* check on the update func */
 
1570
        for (ld = uce->L2Funcs.first; ld; ld = ld->next) {
 
1571
                /* stop on match - function already cached */
 
1572
                if (fn == ld->data)
 
1573
                        return;
 
1574
        }
 
1575
        /* else... if still here, we need to add it */
 
1576
        BLI_addtail(&uce->L2Funcs, BLI_genericNodeN(fn));
 
1577
}
 
1578
 
 
1579
void RNA_property_update_cache_flush(Main *bmain, Scene *scene)
 
1580
{
 
1581
        tRnaUpdateCacheElem *uce;
 
1582
        
 
1583
        /* TODO: should we check that bmain and scene are valid? The above stuff doesn't! */
 
1584
        
 
1585
        /* execute the cached updates */
 
1586
        for (uce = rna_updates_cache.first; uce; uce = uce->next) {
 
1587
                LinkData *ld;
 
1588
                
 
1589
                for (ld = uce->L2Funcs.first; ld; ld = ld->next) {
 
1590
                        UpdateFunc fn = (UpdateFunc)ld->data;
 
1591
                        fn(bmain, scene, &uce->ptr);
 
1592
                }
 
1593
        }
 
1594
}
 
1595
 
 
1596
void RNA_property_update_cache_free(void)
 
1597
{
 
1598
        tRnaUpdateCacheElem *uce, *ucn;
 
1599
        
 
1600
        for (uce = rna_updates_cache.first; uce; uce = ucn) {
 
1601
                ucn = uce->next;
 
1602
                
 
1603
                /* free L2 cache */
 
1604
                BLI_freelistN(&uce->L2Funcs);
 
1605
                
 
1606
                /* remove self */
 
1607
                BLI_freelinkN(&rna_updates_cache, uce);
 
1608
        }
 
1609
}
 
1610
 
 
1611
/* ---------------------------------------------------------------------- */
 
1612
 
1261
1613
/* Property Data */
1262
1614
 
1263
1615
int RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
1264
1616
{
1265
 
        BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
 
1617
        BoolPropertyRNA *bprop = (BoolPropertyRNA*)prop;
1266
1618
        IDProperty *idprop;
1267
1619
 
1268
 
        if((idprop=rna_idproperty_check(&prop, ptr)))
 
1620
        BLI_assert(RNA_property_type(prop) == PROP_BOOLEAN);
 
1621
        BLI_assert(RNA_property_array_check(prop) == 0);
 
1622
 
 
1623
        if ((idprop = rna_idproperty_check(&prop, ptr)))
1269
1624
                return IDP_Int(idprop);
1270
 
        else if(bprop->get)
 
1625
        else if (bprop->get)
1271
1626
                return bprop->get(ptr);
1272
1627
        else
1273
1628
                return bprop->defaultvalue;
1275
1630
 
1276
1631
void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, int value)
1277
1632
{
1278
 
        BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
 
1633
        BoolPropertyRNA *bprop = (BoolPropertyRNA*)prop;
1279
1634
        IDProperty *idprop;
1280
1635
 
1281
 
        /* just incase other values are passed */
1282
 
        if(value) value= 1;
1283
 
 
1284
 
        if((idprop=rna_idproperty_check(&prop, ptr)))
1285
 
                IDP_Int(idprop)= value;
1286
 
        else if(bprop->set)
 
1636
        BLI_assert(RNA_property_type(prop) == PROP_BOOLEAN);
 
1637
        BLI_assert(RNA_property_array_check(prop) == 0);
 
1638
 
 
1639
        /* just in case other values are passed */
 
1640
        if (value) value = 1;
 
1641
 
 
1642
        if ((idprop = rna_idproperty_check(&prop, ptr))) {
 
1643
                IDP_Int(idprop) = value;
 
1644
                rna_idproperty_touch(idprop);
 
1645
        }
 
1646
        else if (bprop->set)
1287
1647
                bprop->set(ptr, value);
1288
 
        else if(prop->flag & PROP_EDITABLE) {
 
1648
        else if (prop->flag & PROP_EDITABLE) {
1289
1649
                IDPropertyTemplate val = {0};
1290
1650
                IDProperty *group;
1291
1651
 
1292
 
                val.i= value;
 
1652
                val.i = value;
1293
1653
 
1294
 
                group= RNA_struct_idproperties(ptr, 1);
1295
 
                if(group)
1296
 
                        IDP_AddToGroup(group, IDP_New(IDP_INT, val, (char*)prop->identifier));
 
1654
                group = RNA_struct_idprops(ptr, 1);
 
1655
                if (group)
 
1656
                        IDP_AddToGroup(group, IDP_New(IDP_INT, &val, prop->identifier));
1297
1657
        }
1298
1658
}
1299
1659
 
1300
1660
void RNA_property_boolean_get_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
1301
1661
{
1302
 
        BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
 
1662
        BoolPropertyRNA *bprop = (BoolPropertyRNA*)prop;
1303
1663
        IDProperty *idprop;
1304
1664
 
1305
 
        if((idprop=rna_idproperty_check(&prop, ptr))) {
1306
 
                if(prop->arraydimension == 0)
1307
 
                        values[0]= RNA_property_boolean_get(ptr, prop);
 
1665
        BLI_assert(RNA_property_type(prop) == PROP_BOOLEAN);
 
1666
        BLI_assert(RNA_property_array_check(prop) != 0);
 
1667
 
 
1668
        if ((idprop = rna_idproperty_check(&prop, ptr))) {
 
1669
                if (prop->arraydimension == 0)
 
1670
                        values[0] = RNA_property_boolean_get(ptr, prop);
1308
1671
                else
1309
1672
                        memcpy(values, IDP_Array(idprop), sizeof(int)*idprop->len);
1310
1673
        }
1311
 
        else if(prop->arraydimension == 0)
1312
 
                values[0]= RNA_property_boolean_get(ptr, prop);
1313
 
        else if(bprop->getarray)
 
1674
        else if (prop->arraydimension == 0)
 
1675
                values[0] = RNA_property_boolean_get(ptr, prop);
 
1676
        else if (bprop->getarray)
1314
1677
                bprop->getarray(ptr, values);
1315
 
        else if(bprop->defaultarray)
 
1678
        else if (bprop->defaultarray)
1316
1679
                memcpy(values, bprop->defaultarray, sizeof(int)*prop->totarraylength);
1317
1680
        else
1318
1681
                memset(values, 0, sizeof(int)*prop->totarraylength);
1321
1684
int RNA_property_boolean_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
1322
1685
{
1323
1686
        int tmp[RNA_MAX_ARRAY_LENGTH];
1324
 
        int len= rna_ensure_property_array_length(ptr, prop);
1325
 
 
1326
 
        if(len <= RNA_MAX_ARRAY_LENGTH) {
 
1687
        int len = rna_ensure_property_array_length(ptr, prop);
 
1688
 
 
1689
        BLI_assert(RNA_property_type(prop) == PROP_BOOLEAN);
 
1690
        BLI_assert(RNA_property_array_check(prop) != 0);
 
1691
 
 
1692
        if (len <= RNA_MAX_ARRAY_LENGTH) {
1327
1693
                RNA_property_boolean_get_array(ptr, prop, tmp);
1328
1694
                return tmp[index];
1329
1695
        }
1330
1696
        else {
1331
1697
                int *tmparray, value;
1332
1698
 
1333
 
                tmparray= MEM_callocN(sizeof(int)*len, "RNA_property_boolean_get_index");
 
1699
                tmparray = MEM_callocN(sizeof(int)*len, "RNA_property_boolean_get_index");
1334
1700
                RNA_property_boolean_get_array(ptr, prop, tmparray);
1335
 
                value= tmparray[index];
 
1701
                value = tmparray[index];
1336
1702
                MEM_freeN(tmparray);
1337
1703
 
1338
1704
                return value;
1341
1707
 
1342
1708
void RNA_property_boolean_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *values)
1343
1709
{
1344
 
        BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
 
1710
        BoolPropertyRNA *bprop = (BoolPropertyRNA*)prop;
1345
1711
        IDProperty *idprop;
1346
1712
 
1347
 
        if((idprop=rna_idproperty_check(&prop, ptr))) {
1348
 
                if(prop->arraydimension == 0)
1349
 
                        IDP_Int(idprop)= values[0];
 
1713
        BLI_assert(RNA_property_type(prop) == PROP_BOOLEAN);
 
1714
        BLI_assert(RNA_property_array_check(prop) != 0);
 
1715
 
 
1716
        if ((idprop = rna_idproperty_check(&prop, ptr))) {
 
1717
                if (prop->arraydimension == 0)
 
1718
                        IDP_Int(idprop) = values[0];
1350
1719
                else
1351
1720
                        memcpy(IDP_Array(idprop), values, sizeof(int)*idprop->len);
 
1721
 
 
1722
                rna_idproperty_touch(idprop);
1352
1723
        }
1353
 
        else if(prop->arraydimension == 0)
 
1724
        else if (prop->arraydimension == 0)
1354
1725
                RNA_property_boolean_set(ptr, prop, values[0]);
1355
 
        else if(bprop->setarray)
 
1726
        else if (bprop->setarray)
1356
1727
                bprop->setarray(ptr, values);
1357
 
        else if(prop->flag & PROP_EDITABLE) {
 
1728
        else if (prop->flag & PROP_EDITABLE) {
1358
1729
                IDPropertyTemplate val = {0};
1359
1730
                IDProperty *group;
1360
1731
 
1361
 
                val.array.len= prop->totarraylength;
1362
 
                val.array.type= IDP_INT;
 
1732
                val.array.len = prop->totarraylength;
 
1733
                val.array.type = IDP_INT;
1363
1734
 
1364
 
                group= RNA_struct_idproperties(ptr, 1);
1365
 
                if(group) {
1366
 
                        idprop= IDP_New(IDP_ARRAY, val, (char*)prop->identifier);
 
1735
                group = RNA_struct_idprops(ptr, 1);
 
1736
                if (group) {
 
1737
                        idprop = IDP_New(IDP_ARRAY, &val, prop->identifier);
1367
1738
                        IDP_AddToGroup(group, idprop);
1368
1739
                        memcpy(IDP_Array(idprop), values, sizeof(int)*idprop->len);
1369
1740
                }
1373
1744
void RNA_property_boolean_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, int value)
1374
1745
{
1375
1746
        int tmp[RNA_MAX_ARRAY_LENGTH];
1376
 
        int len= rna_ensure_property_array_length(ptr, prop);
1377
 
 
1378
 
        if(len <= RNA_MAX_ARRAY_LENGTH) {
 
1747
        int len = rna_ensure_property_array_length(ptr, prop);
 
1748
 
 
1749
        BLI_assert(RNA_property_type(prop) == PROP_BOOLEAN);
 
1750
        BLI_assert(RNA_property_array_check(prop) != 0);
 
1751
 
 
1752
        if (len <= RNA_MAX_ARRAY_LENGTH) {
1379
1753
                RNA_property_boolean_get_array(ptr, prop, tmp);
1380
 
                tmp[index]= value;
 
1754
                tmp[index] = value;
1381
1755
                RNA_property_boolean_set_array(ptr, prop, tmp);
1382
1756
        }
1383
1757
        else {
1384
1758
                int *tmparray;
1385
1759
 
1386
 
                tmparray= MEM_callocN(sizeof(int)*len, "RNA_property_boolean_get_index");
 
1760
                tmparray = MEM_callocN(sizeof(int)*len, "RNA_property_boolean_get_index");
1387
1761
                RNA_property_boolean_get_array(ptr, prop, tmparray);
1388
 
                tmparray[index]= value;
 
1762
                tmparray[index] = value;
1389
1763
                RNA_property_boolean_set_array(ptr, prop, tmparray);
1390
1764
                MEM_freeN(tmparray);
1391
1765
        }
1392
1766
}
1393
1767
 
1394
 
int RNA_property_boolean_get_default(PointerRNA *ptr, PropertyRNA *prop)
 
1768
int RNA_property_boolean_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
1395
1769
{
1396
 
        BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
 
1770
        BoolPropertyRNA *bprop = (BoolPropertyRNA*)prop;
 
1771
 
 
1772
        BLI_assert(RNA_property_type(prop) == PROP_BOOLEAN);
 
1773
        BLI_assert(RNA_property_array_check(prop) == 0);
 
1774
 
1397
1775
        return bprop->defaultvalue;
1398
1776
}
1399
1777
 
1400
 
void RNA_property_boolean_get_default_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
 
1778
void RNA_property_boolean_get_default_array(PointerRNA *UNUSED(ptr), PropertyRNA *prop, int *values)
1401
1779
{
1402
 
        BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
 
1780
        BoolPropertyRNA *bprop = (BoolPropertyRNA*)prop;
1403
1781
        
1404
 
        if(prop->arraydimension == 0)
1405
 
                values[0]= bprop->defaultvalue;
1406
 
        else if(bprop->defaultarray)
 
1782
        BLI_assert(RNA_property_type(prop) == PROP_BOOLEAN);
 
1783
        BLI_assert(RNA_property_array_check(prop) != 0);
 
1784
 
 
1785
        if (prop->arraydimension == 0)
 
1786
                values[0] = bprop->defaultvalue;
 
1787
        else if (bprop->defaultarray)
1407
1788
                memcpy(values, bprop->defaultarray, sizeof(int)*prop->totarraylength);
1408
1789
        else
1409
1790
                memset(values, 0, sizeof(int)*prop->totarraylength);
1412
1793
int RNA_property_boolean_get_default_index(PointerRNA *ptr, PropertyRNA *prop, int index)
1413
1794
{
1414
1795
        int tmp[RNA_MAX_ARRAY_LENGTH];
1415
 
        int len= rna_ensure_property_array_length(ptr, prop);
1416
 
 
1417
 
        if(len <= RNA_MAX_ARRAY_LENGTH) {
 
1796
        int len = rna_ensure_property_array_length(ptr, prop);
 
1797
 
 
1798
        BLI_assert(RNA_property_type(prop) == PROP_BOOLEAN);
 
1799
        BLI_assert(RNA_property_array_check(prop) != 0);
 
1800
 
 
1801
        if (len <= RNA_MAX_ARRAY_LENGTH) {
1418
1802
                RNA_property_boolean_get_default_array(ptr, prop, tmp);
1419
1803
                return tmp[index];
1420
1804
        }
1421
1805
        else {
1422
1806
                int *tmparray, value;
1423
1807
 
1424
 
                tmparray= MEM_callocN(sizeof(int)*len, "RNA_property_boolean_get_default_index");
 
1808
                tmparray = MEM_callocN(sizeof(int)*len, "RNA_property_boolean_get_default_index");
1425
1809
                RNA_property_boolean_get_default_array(ptr, prop, tmparray);
1426
 
                value= tmparray[index];
 
1810
                value = tmparray[index];
1427
1811
                MEM_freeN(tmparray);
1428
1812
 
1429
1813
                return value;
1432
1816
 
1433
1817
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
1434
1818
{
1435
 
        IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
 
1819
        IntPropertyRNA *iprop = (IntPropertyRNA*)prop;
1436
1820
        IDProperty *idprop;
1437
1821
 
1438
 
        if((idprop=rna_idproperty_check(&prop, ptr)))
 
1822
        BLI_assert(RNA_property_type(prop) == PROP_INT);
 
1823
        BLI_assert(RNA_property_array_check(prop) == 0);
 
1824
 
 
1825
        if ((idprop = rna_idproperty_check(&prop, ptr)))
1439
1826
                return IDP_Int(idprop);
1440
 
        else if(iprop->get)
 
1827
        else if (iprop->get)
1441
1828
                return iprop->get(ptr);
1442
1829
        else
1443
1830
                return iprop->defaultvalue;
1445
1832
 
1446
1833
void RNA_property_int_set(PointerRNA *ptr, PropertyRNA *prop, int value)
1447
1834
{
1448
 
        IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
 
1835
        IntPropertyRNA *iprop = (IntPropertyRNA*)prop;
1449
1836
        IDProperty *idprop;
1450
1837
 
1451
 
        if((idprop=rna_idproperty_check(&prop, ptr)))
1452
 
                IDP_Int(idprop)= value;
1453
 
        else if(iprop->set)
 
1838
        BLI_assert(RNA_property_type(prop) == PROP_INT);
 
1839
        BLI_assert(RNA_property_array_check(prop) == 0);
 
1840
        /* useful to check on bad values but set function should clamp */
 
1841
        /* BLI_assert(RNA_property_int_clamp(ptr, prop, &value) == 0); */
 
1842
 
 
1843
        if ((idprop = rna_idproperty_check(&prop, ptr))) {
 
1844
                IDP_Int(idprop) = value;
 
1845
                rna_idproperty_touch(idprop);
 
1846
        }
 
1847
        else if (iprop->set)
1454
1848
                iprop->set(ptr, value);
1455
 
        else if(prop->flag & PROP_EDITABLE) {
 
1849
        else if (prop->flag & PROP_EDITABLE) {
1456
1850
                IDPropertyTemplate val = {0};
1457
1851
                IDProperty *group;
1458
1852
 
1459
 
                val.i= value;
 
1853
                val.i = value;
1460
1854
 
1461
 
                group= RNA_struct_idproperties(ptr, 1);
1462
 
                if(group)
1463
 
                        IDP_AddToGroup(group, IDP_New(IDP_INT, val, (char*)prop->identifier));
 
1855
                group = RNA_struct_idprops(ptr, 1);
 
1856
                if (group)
 
1857
                        IDP_AddToGroup(group, IDP_New(IDP_INT, &val, prop->identifier));
1464
1858
        }
1465
1859
}
1466
1860
 
1467
1861
void RNA_property_int_get_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
1468
1862
{
1469
 
        IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
 
1863
        IntPropertyRNA *iprop = (IntPropertyRNA*)prop;
1470
1864
        IDProperty *idprop;
1471
1865
 
1472
 
        if((idprop=rna_idproperty_check(&prop, ptr))) {
1473
 
                if(prop->arraydimension == 0)
1474
 
                        values[0]= RNA_property_int_get(ptr, prop);
 
1866
        BLI_assert(RNA_property_type(prop) == PROP_INT);
 
1867
        BLI_assert(RNA_property_array_check(prop) != 0);
 
1868
 
 
1869
        if ((idprop = rna_idproperty_check(&prop, ptr))) {
 
1870
                if (prop->arraydimension == 0)
 
1871
                        values[0] = RNA_property_int_get(ptr, prop);
1475
1872
                else
1476
1873
                        memcpy(values, IDP_Array(idprop), sizeof(int)*idprop->len);
1477
1874
        }
1478
 
        else if(prop->arraydimension == 0)
1479
 
                values[0]= RNA_property_int_get(ptr, prop);
1480
 
        else if(iprop->getarray)
 
1875
        else if (prop->arraydimension == 0)
 
1876
                values[0] = RNA_property_int_get(ptr, prop);
 
1877
        else if (iprop->getarray)
1481
1878
                iprop->getarray(ptr, values);
1482
 
        else if(iprop->defaultarray)
 
1879
        else if (iprop->defaultarray)
1483
1880
                memcpy(values, iprop->defaultarray, sizeof(int)*prop->totarraylength);
1484
1881
        else
1485
1882
                memset(values, 0, sizeof(int)*prop->totarraylength);
1486
1883
}
1487
1884
 
 
1885
void RNA_property_int_get_array_range(PointerRNA *ptr, PropertyRNA *prop, int values[2])
 
1886
{
 
1887
        const int array_len = RNA_property_array_length(ptr, prop);
 
1888
 
 
1889
        if (array_len <= 0) {
 
1890
                values[0] = 0;
 
1891
                values[1] = 0;
 
1892
        }
 
1893
        else if (array_len == 1) {
 
1894
                RNA_property_int_get_array(ptr, prop, values);
 
1895
                values[1] = values[0];
 
1896
        }
 
1897
        else {
 
1898
                int arr_stack[32];
 
1899
                int *arr;
 
1900
                int i;
 
1901
 
 
1902
                if (array_len > 32) {
 
1903
                        arr = MEM_mallocN(sizeof(int) * array_len, "RNA_property_int_get_array_range");
 
1904
                }
 
1905
                else {
 
1906
                        arr = arr_stack;
 
1907
                }
 
1908
 
 
1909
                RNA_property_int_get_array(ptr, prop, arr);
 
1910
                values[0] = values[1] = arr[0];
 
1911
                for (i = 1; i < array_len; i++) {
 
1912
                        values[0] = MIN2(values[0], arr[i]);
 
1913
                        values[1] = MAX2(values[1], arr[i]);
 
1914
                }
 
1915
 
 
1916
                if (arr != arr_stack) {
 
1917
                        MEM_freeN(arr);
 
1918
                }
 
1919
        }
 
1920
}
 
1921
 
1488
1922
int RNA_property_int_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
1489
1923
{
1490
1924
        int tmp[RNA_MAX_ARRAY_LENGTH];
1491
 
        int len= rna_ensure_property_array_length(ptr, prop);
1492
 
 
1493
 
        if(len <= RNA_MAX_ARRAY_LENGTH) {
 
1925
        int len = rna_ensure_property_array_length(ptr, prop);
 
1926
 
 
1927
        BLI_assert(RNA_property_type(prop) == PROP_INT);
 
1928
        BLI_assert(RNA_property_array_check(prop) != 0);
 
1929
 
 
1930
        if (len <= RNA_MAX_ARRAY_LENGTH) {
1494
1931
                RNA_property_int_get_array(ptr, prop, tmp);
1495
1932
                return tmp[index];
1496
1933
        }
1497
1934
        else {
1498
1935
                int *tmparray, value;
1499
1936
 
1500
 
                tmparray= MEM_callocN(sizeof(int)*len, "RNA_property_int_get_index");
 
1937
                tmparray = MEM_callocN(sizeof(int)*len, "RNA_property_int_get_index");
1501
1938
                RNA_property_int_get_array(ptr, prop, tmparray);
1502
 
                value= tmparray[index];
 
1939
                value = tmparray[index];
1503
1940
                MEM_freeN(tmparray);
1504
1941
 
1505
1942
                return value;
1508
1945
 
1509
1946
void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *values)
1510
1947
{
1511
 
        IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
 
1948
        IntPropertyRNA *iprop = (IntPropertyRNA*)prop;
1512
1949
        IDProperty *idprop;
1513
1950
 
1514
 
        if((idprop=rna_idproperty_check(&prop, ptr))) {
1515
 
                if(prop->arraydimension == 0)
1516
 
                        IDP_Int(idprop)= values[0];
 
1951
        BLI_assert(RNA_property_type(prop) == PROP_INT);
 
1952
        BLI_assert(RNA_property_array_check(prop) != 0);
 
1953
 
 
1954
        if ((idprop = rna_idproperty_check(&prop, ptr))) {
 
1955
                if (prop->arraydimension == 0)
 
1956
                        IDP_Int(idprop) = values[0];
1517
1957
                else
1518
 
                        memcpy(IDP_Array(idprop), values, sizeof(int)*idprop->len);\
 
1958
                        memcpy(IDP_Array(idprop), values, sizeof(int)*idprop->len);
 
1959
 
 
1960
                rna_idproperty_touch(idprop);
1519
1961
        }
1520
 
        else if(prop->arraydimension == 0)
 
1962
        else if (prop->arraydimension == 0)
1521
1963
                RNA_property_int_set(ptr, prop, values[0]);
1522
 
        else if(iprop->setarray)
 
1964
        else if (iprop->setarray)
1523
1965
                iprop->setarray(ptr, values);
1524
 
        else if(prop->flag & PROP_EDITABLE) {
 
1966
        else if (prop->flag & PROP_EDITABLE) {
1525
1967
                IDPropertyTemplate val = {0};
1526
1968
                IDProperty *group;
1527
1969
 
1528
 
                val.array.len= prop->totarraylength;
1529
 
                val.array.type= IDP_INT;
 
1970
                val.array.len = prop->totarraylength;
 
1971
                val.array.type = IDP_INT;
1530
1972
 
1531
 
                group= RNA_struct_idproperties(ptr, 1);
1532
 
                if(group) {
1533
 
                        idprop= IDP_New(IDP_ARRAY, val, (char*)prop->identifier);
 
1973
                group = RNA_struct_idprops(ptr, 1);
 
1974
                if (group) {
 
1975
                        idprop = IDP_New(IDP_ARRAY, &val, prop->identifier);
1534
1976
                        IDP_AddToGroup(group, idprop);
1535
1977
                        memcpy(IDP_Array(idprop), values, sizeof(int)*idprop->len);
1536
1978
                }
1540
1982
void RNA_property_int_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, int value)
1541
1983
{
1542
1984
        int tmp[RNA_MAX_ARRAY_LENGTH];
1543
 
        int len= rna_ensure_property_array_length(ptr, prop);
1544
 
 
1545
 
        if(len <= RNA_MAX_ARRAY_LENGTH) {
 
1985
        int len = rna_ensure_property_array_length(ptr, prop);
 
1986
 
 
1987
        BLI_assert(RNA_property_type(prop) == PROP_INT);
 
1988
        BLI_assert(RNA_property_array_check(prop) != 0);
 
1989
 
 
1990
        if (len <= RNA_MAX_ARRAY_LENGTH) {
1546
1991
                RNA_property_int_get_array(ptr, prop, tmp);
1547
 
                tmp[index]= value;
 
1992
                tmp[index] = value;
1548
1993
                RNA_property_int_set_array(ptr, prop, tmp);
1549
1994
        }
1550
1995
        else {
1551
1996
                int *tmparray;
1552
1997
 
1553
 
                tmparray= MEM_callocN(sizeof(int)*len, "RNA_property_int_get_index");
 
1998
                tmparray = MEM_callocN(sizeof(int)*len, "RNA_property_int_get_index");
1554
1999
                RNA_property_int_get_array(ptr, prop, tmparray);
1555
 
                tmparray[index]= value;
 
2000
                tmparray[index] = value;
1556
2001
                RNA_property_int_set_array(ptr, prop, tmparray);
1557
2002
                MEM_freeN(tmparray);
1558
2003
        }
1559
2004
}
1560
2005
 
1561
 
int RNA_property_int_get_default(PointerRNA *ptr, PropertyRNA *prop)
 
2006
int RNA_property_int_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
1562
2007
{
1563
 
        IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
 
2008
        IntPropertyRNA *iprop = (IntPropertyRNA*)prop;
1564
2009
        return iprop->defaultvalue;
1565
2010
}
1566
2011
 
1567
 
void RNA_property_int_get_default_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
 
2012
void RNA_property_int_get_default_array(PointerRNA *UNUSED(ptr), PropertyRNA *prop, int *values)
1568
2013
{
1569
 
        IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
 
2014
        IntPropertyRNA *iprop = (IntPropertyRNA*)prop;
1570
2015
        
1571
 
        if(prop->arraydimension == 0)
1572
 
                values[0]= iprop->defaultvalue;
1573
 
        else if(iprop->defaultarray)
 
2016
        BLI_assert(RNA_property_type(prop) == PROP_INT);
 
2017
        BLI_assert(RNA_property_array_check(prop) != 0);
 
2018
 
 
2019
        if (prop->arraydimension == 0)
 
2020
                values[0] = iprop->defaultvalue;
 
2021
        else if (iprop->defaultarray)
1574
2022
                memcpy(values, iprop->defaultarray, sizeof(int)*prop->totarraylength);
1575
2023
        else
1576
2024
                memset(values, 0, sizeof(int)*prop->totarraylength);
1579
2027
int RNA_property_int_get_default_index(PointerRNA *ptr, PropertyRNA *prop, int index)
1580
2028
{
1581
2029
        int tmp[RNA_MAX_ARRAY_LENGTH];
1582
 
        int len= rna_ensure_property_array_length(ptr, prop);
 
2030
        int len = rna_ensure_property_array_length(ptr, prop);
1583
2031
 
1584
 
        if(len <= RNA_MAX_ARRAY_LENGTH) {
 
2032
        if (len <= RNA_MAX_ARRAY_LENGTH) {
1585
2033
                RNA_property_int_get_default_array(ptr, prop, tmp);
1586
2034
                return tmp[index];
1587
2035
        }
1588
2036
        else {
1589
2037
                int *tmparray, value;
1590
2038
 
1591
 
                tmparray= MEM_callocN(sizeof(int)*len, "RNA_property_int_get_default_index");
 
2039
                tmparray = MEM_callocN(sizeof(int)*len, "RNA_property_int_get_default_index");
1592
2040
                RNA_property_int_get_default_array(ptr, prop, tmparray);
1593
 
                value= tmparray[index];
 
2041
                value = tmparray[index];
1594
2042
                MEM_freeN(tmparray);
1595
2043
 
1596
2044
                return value;
1599
2047
 
1600
2048
float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop)
1601
2049
{
1602
 
        FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
 
2050
        FloatPropertyRNA *fprop = (FloatPropertyRNA*)prop;
1603
2051
        IDProperty *idprop;
1604
2052
 
1605
 
        if((idprop=rna_idproperty_check(&prop, ptr))) {
1606
 
                if(idprop->type == IDP_FLOAT)
 
2053
        BLI_assert(RNA_property_type(prop) == PROP_FLOAT);
 
2054
        BLI_assert(RNA_property_array_check(prop) == 0);
 
2055
 
 
2056
        if ((idprop = rna_idproperty_check(&prop, ptr))) {
 
2057
                if (idprop->type == IDP_FLOAT)
1607
2058
                        return IDP_Float(idprop);
1608
2059
                else
1609
2060
                        return (float)IDP_Double(idprop);
1610
2061
        }
1611
 
        else if(fprop->get)
 
2062
        else if (fprop->get)
1612
2063
                return fprop->get(ptr);
1613
2064
        else
1614
2065
                return fprop->defaultvalue;
1616
2067
 
1617
2068
void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value)
1618
2069
{
1619
 
        FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
 
2070
        FloatPropertyRNA *fprop = (FloatPropertyRNA*)prop;
1620
2071
        IDProperty *idprop;
1621
2072
 
1622
 
        if((idprop=rna_idproperty_check(&prop, ptr))) {
1623
 
                if(idprop->type == IDP_FLOAT)
1624
 
                        IDP_Float(idprop)= value;
 
2073
        BLI_assert(RNA_property_type(prop) == PROP_FLOAT);
 
2074
        BLI_assert(RNA_property_array_check(prop) == 0);
 
2075
        /* useful to check on bad values but set function should clamp */
 
2076
        /* BLI_assert(RNA_property_float_clamp(ptr, prop, &value) == 0); */
 
2077
 
 
2078
        if ((idprop = rna_idproperty_check(&prop, ptr))) {
 
2079
                if (idprop->type == IDP_FLOAT)
 
2080
                        IDP_Float(idprop) = value;
1625
2081
                else
1626
 
                        IDP_Double(idprop)= value;
 
2082
                        IDP_Double(idprop) = value;
 
2083
 
 
2084
                rna_idproperty_touch(idprop);
1627
2085
        }
1628
 
        else if(fprop->set) {
 
2086
        else if (fprop->set) {
1629
2087
                fprop->set(ptr, value);
1630
2088
        }
1631
 
        else if(prop->flag & PROP_EDITABLE) {
 
2089
        else if (prop->flag & PROP_EDITABLE) {
1632
2090
                IDPropertyTemplate val = {0};
1633
2091
                IDProperty *group;
1634
2092
 
1635
 
                val.f= value;
 
2093
                val.f = value;
1636
2094
 
1637
 
                group= RNA_struct_idproperties(ptr, 1);
1638
 
                if(group)
1639
 
                        IDP_AddToGroup(group, IDP_New(IDP_FLOAT, val, (char*)prop->identifier));
 
2095
                group = RNA_struct_idprops(ptr, 1);
 
2096
                if (group)
 
2097
                        IDP_AddToGroup(group, IDP_New(IDP_FLOAT, &val, prop->identifier));
1640
2098
        }
1641
2099
}
1642
2100
 
1643
2101
void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
1644
2102
{
1645
 
        FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
 
2103
        FloatPropertyRNA *fprop = (FloatPropertyRNA*)prop;
1646
2104
        IDProperty *idprop;
1647
2105
        int i;
1648
2106
 
1649
 
        if((idprop=rna_idproperty_check(&prop, ptr))) {
1650
 
                if(prop->arraydimension == 0)
1651
 
                        values[0]= RNA_property_float_get(ptr, prop);
1652
 
                else if(idprop->subtype == IDP_FLOAT) {
 
2107
        BLI_assert(RNA_property_type(prop) == PROP_FLOAT);
 
2108
        BLI_assert(RNA_property_array_check(prop) != 0);
 
2109
 
 
2110
        if ((idprop = rna_idproperty_check(&prop, ptr))) {
 
2111
                if (prop->arraydimension == 0)
 
2112
                        values[0] = RNA_property_float_get(ptr, prop);
 
2113
                else if (idprop->subtype == IDP_FLOAT) {
1653
2114
                        memcpy(values, IDP_Array(idprop), sizeof(float)*idprop->len);
1654
2115
                }
1655
2116
                else {
1656
 
                        for(i=0; i<idprop->len; i++)
1657
 
                                values[i]=  (float)(((double*)IDP_Array(idprop))[i]);
 
2117
                        for (i = 0; i<idprop->len; i++)
 
2118
                                values[i] =  (float)(((double*)IDP_Array(idprop))[i]);
1658
2119
                }
1659
2120
        }
1660
 
        else if(prop->arraydimension == 0)
1661
 
                values[0]= RNA_property_float_get(ptr, prop);
1662
 
        else if(fprop->getarray)
 
2121
        else if (prop->arraydimension == 0)
 
2122
                values[0] = RNA_property_float_get(ptr, prop);
 
2123
        else if (fprop->getarray)
1663
2124
                fprop->getarray(ptr, values);
1664
 
        else if(fprop->defaultarray)
 
2125
        else if (fprop->defaultarray)
1665
2126
                memcpy(values, fprop->defaultarray, sizeof(float)*prop->totarraylength);
1666
2127
        else
1667
2128
                memset(values, 0, sizeof(float)*prop->totarraylength);
1668
2129
}
1669
2130
 
 
2131
void RNA_property_float_get_array_range(PointerRNA *ptr, PropertyRNA *prop, float values[2])
 
2132
{
 
2133
        const int array_len = RNA_property_array_length(ptr, prop);
 
2134
 
 
2135
        if (array_len <= 0) {
 
2136
                values[0] = 0.0f;
 
2137
                values[1] = 0.0f;
 
2138
        }
 
2139
        else if (array_len == 1) {
 
2140
                RNA_property_float_get_array(ptr, prop, values);
 
2141
                values[1] = values[0];
 
2142
        }
 
2143
        else {
 
2144
                float arr_stack[32];
 
2145
                float *arr;
 
2146
                int i;
 
2147
 
 
2148
                if (array_len > 32) {
 
2149
                        arr = MEM_mallocN(sizeof(float) * array_len, "RNA_property_float_get_array_range");
 
2150
                }
 
2151
                else {
 
2152
                        arr = arr_stack;
 
2153
                }
 
2154
 
 
2155
                RNA_property_float_get_array(ptr, prop, arr);
 
2156
                values[0] = values[1] = arr[0];
 
2157
                for (i = 1; i < array_len; i++) {
 
2158
                        values[0] = MIN2(values[0], arr[i]);
 
2159
                        values[1] = MAX2(values[1], arr[i]);
 
2160
                }
 
2161
 
 
2162
                if (arr != arr_stack) {
 
2163
                        MEM_freeN(arr);
 
2164
                }
 
2165
        }
 
2166
}
 
2167
 
1670
2168
float RNA_property_float_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
1671
2169
{
1672
2170
        float tmp[RNA_MAX_ARRAY_LENGTH];
1673
 
        int len= rna_ensure_property_array_length(ptr, prop);
1674
 
 
1675
 
        if(len <= RNA_MAX_ARRAY_LENGTH) {
 
2171
        int len = rna_ensure_property_array_length(ptr, prop);
 
2172
 
 
2173
        BLI_assert(RNA_property_type(prop) == PROP_FLOAT);
 
2174
        BLI_assert(RNA_property_array_check(prop) != 0);
 
2175
 
 
2176
        if (len <= RNA_MAX_ARRAY_LENGTH) {
1676
2177
                RNA_property_float_get_array(ptr, prop, tmp);
1677
2178
                return tmp[index];
1678
2179
        }
1679
2180
        else {
1680
2181
                float *tmparray, value;
1681
2182
 
1682
 
                tmparray= MEM_callocN(sizeof(float)*len, "RNA_property_float_get_index");
 
2183
                tmparray = MEM_callocN(sizeof(float)*len, "RNA_property_float_get_index");
1683
2184
                RNA_property_float_get_array(ptr, prop, tmparray);
1684
 
                value= tmparray[index];
 
2185
                value = tmparray[index];
1685
2186
                MEM_freeN(tmparray);
1686
2187
 
1687
2188
                return value;
1691
2192
 
1692
2193
void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const float *values)
1693
2194
{
1694
 
        FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
 
2195
        FloatPropertyRNA *fprop = (FloatPropertyRNA*)prop;
1695
2196
        IDProperty *idprop;
1696
2197
        int i;
1697
2198
 
1698
 
        if((idprop=rna_idproperty_check(&prop, ptr))) {
1699
 
                if(prop->arraydimension == 0) {
1700
 
                        if(idprop->type == IDP_FLOAT)
1701
 
                                IDP_Float(idprop)= values[0];
 
2199
        BLI_assert(RNA_property_type(prop) == PROP_FLOAT);
 
2200
        BLI_assert(RNA_property_array_check(prop) != 0);
 
2201
 
 
2202
        if ((idprop = rna_idproperty_check(&prop, ptr))) {
 
2203
                if (prop->arraydimension == 0) {
 
2204
                        if (idprop->type == IDP_FLOAT)
 
2205
                                IDP_Float(idprop) = values[0];
1702
2206
                        else
1703
 
                                IDP_Double(idprop)= values[0];
 
2207
                                IDP_Double(idprop) = values[0];
1704
2208
                }
1705
 
                else if(idprop->subtype == IDP_FLOAT) {
 
2209
                else if (idprop->subtype == IDP_FLOAT) {
1706
2210
                        memcpy(IDP_Array(idprop), values, sizeof(float)*idprop->len);
1707
2211
                }
1708
2212
                else {
1709
 
                        for(i=0; i<idprop->len; i++)
1710
 
                                ((double*)IDP_Array(idprop))[i]= values[i];
 
2213
                        for (i = 0; i<idprop->len; i++)
 
2214
                                ((double*)IDP_Array(idprop))[i] = values[i];
1711
2215
                }
 
2216
 
 
2217
                rna_idproperty_touch(idprop);
1712
2218
        }
1713
 
        else if(prop->arraydimension == 0)
 
2219
        else if (prop->arraydimension == 0)
1714
2220
                RNA_property_float_set(ptr, prop, values[0]);
1715
 
        else if(fprop->setarray) {
 
2221
        else if (fprop->setarray) {
1716
2222
                fprop->setarray(ptr, values);
1717
2223
        }
1718
 
        else if(prop->flag & PROP_EDITABLE) {
 
2224
        else if (prop->flag & PROP_EDITABLE) {
1719
2225
                IDPropertyTemplate val = {0};
1720
2226
                IDProperty *group;
1721
2227
 
1722
 
                val.array.len= prop->totarraylength;
1723
 
                val.array.type= IDP_FLOAT;
 
2228
                val.array.len = prop->totarraylength;
 
2229
                val.array.type = IDP_FLOAT;
1724
2230
 
1725
 
                group= RNA_struct_idproperties(ptr, 1);
1726
 
                if(group) {
1727
 
                        idprop= IDP_New(IDP_ARRAY, val, (char*)prop->identifier);
 
2231
                group = RNA_struct_idprops(ptr, 1);
 
2232
                if (group) {
 
2233
                        idprop = IDP_New(IDP_ARRAY, &val, prop->identifier);
1728
2234
                        IDP_AddToGroup(group, idprop);
1729
2235
                        memcpy(IDP_Array(idprop), values, sizeof(float)*idprop->len);
1730
2236
                }
1734
2240
void RNA_property_float_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, float value)
1735
2241
{
1736
2242
        float tmp[RNA_MAX_ARRAY_LENGTH];
1737
 
        int len= rna_ensure_property_array_length(ptr, prop);
1738
 
 
1739
 
        if(len <= RNA_MAX_ARRAY_LENGTH) {
 
2243
        int len = rna_ensure_property_array_length(ptr, prop);
 
2244
 
 
2245
        BLI_assert(RNA_property_type(prop) == PROP_FLOAT);
 
2246
        BLI_assert(RNA_property_array_check(prop) != 0);
 
2247
 
 
2248
        if (len <= RNA_MAX_ARRAY_LENGTH) {
1740
2249
                RNA_property_float_get_array(ptr, prop, tmp);
1741
 
                tmp[index]= value;
 
2250
                tmp[index] = value;
1742
2251
                RNA_property_float_set_array(ptr, prop, tmp);
1743
2252
        }
1744
2253
        else {
1745
2254
                float *tmparray;
1746
2255
 
1747
 
                tmparray= MEM_callocN(sizeof(float)*len, "RNA_property_float_get_index");
 
2256
                tmparray = MEM_callocN(sizeof(float)*len, "RNA_property_float_get_index");
1748
2257
                RNA_property_float_get_array(ptr, prop, tmparray);
1749
 
                tmparray[index]= value;
 
2258
                tmparray[index] = value;
1750
2259
                RNA_property_float_set_array(ptr, prop, tmparray);
1751
2260
                MEM_freeN(tmparray);
1752
2261
        }
1753
2262
}
1754
2263
 
1755
 
float RNA_property_float_get_default(PointerRNA *ptr, PropertyRNA *prop)
 
2264
float RNA_property_float_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
1756
2265
{
1757
 
        FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
 
2266
        FloatPropertyRNA *fprop = (FloatPropertyRNA*)prop;
 
2267
 
 
2268
        BLI_assert(RNA_property_type(prop) == PROP_FLOAT);
 
2269
        BLI_assert(RNA_property_array_check(prop) == 0);
 
2270
 
1758
2271
        return fprop->defaultvalue;
1759
2272
}
1760
2273
 
1761
 
void RNA_property_float_get_default_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
 
2274
void RNA_property_float_get_default_array(PointerRNA *UNUSED(ptr), PropertyRNA *prop, float *values)
1762
2275
{
1763
 
        FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
 
2276
        FloatPropertyRNA *fprop = (FloatPropertyRNA*)prop;
1764
2277
        
1765
 
        if(prop->arraydimension == 0)
1766
 
                values[0]= fprop->defaultvalue;
1767
 
        else if(fprop->defaultarray)
 
2278
        BLI_assert(RNA_property_type(prop) == PROP_FLOAT);
 
2279
        BLI_assert(RNA_property_array_check(prop) != 0);
 
2280
 
 
2281
        if (prop->arraydimension == 0)
 
2282
                values[0] = fprop->defaultvalue;
 
2283
        else if (fprop->defaultarray)
1768
2284
                memcpy(values, fprop->defaultarray, sizeof(float)*prop->totarraylength);
1769
2285
        else
1770
2286
                memset(values, 0, sizeof(float)*prop->totarraylength);
1773
2289
float RNA_property_float_get_default_index(PointerRNA *ptr, PropertyRNA *prop, int index)
1774
2290
{
1775
2291
        float tmp[RNA_MAX_ARRAY_LENGTH];
1776
 
        int len= rna_ensure_property_array_length(ptr, prop);
1777
 
 
1778
 
        if(len <= RNA_MAX_ARRAY_LENGTH) {
 
2292
        int len = rna_ensure_property_array_length(ptr, prop);
 
2293
 
 
2294
        BLI_assert(RNA_property_type(prop) == PROP_FLOAT);
 
2295
        BLI_assert(RNA_property_array_check(prop) != 0);
 
2296
 
 
2297
        if (len <= RNA_MAX_ARRAY_LENGTH) {
1779
2298
                RNA_property_float_get_default_array(ptr, prop, tmp);
1780
2299
                return tmp[index];
1781
2300
        }
1782
2301
        else {
1783
2302
                float *tmparray, value;
1784
2303
 
1785
 
                tmparray= MEM_callocN(sizeof(float)*len, "RNA_property_float_get_default_index");
 
2304
                tmparray = MEM_callocN(sizeof(float)*len, "RNA_property_float_get_default_index");
1786
2305
                RNA_property_float_get_default_array(ptr, prop, tmparray);
1787
 
                value= tmparray[index];
 
2306
                value = tmparray[index];
1788
2307
                MEM_freeN(tmparray);
1789
2308
 
1790
2309
                return value;
1793
2312
 
1794
2313
void RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop, char *value)
1795
2314
{
1796
 
        StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
 
2315
        StringPropertyRNA *sprop = (StringPropertyRNA*)prop;
1797
2316
        IDProperty *idprop;
1798
2317
 
1799
 
        if((idprop=rna_idproperty_check(&prop, ptr)))
1800
 
                strcpy(value, IDP_String(idprop));
1801
 
        else if(sprop->get)
 
2318
        BLI_assert(RNA_property_type(prop) == PROP_STRING);
 
2319
 
 
2320
        if ((idprop = rna_idproperty_check(&prop, ptr))) {
 
2321
                /* editing bytes is not 100% supported
 
2322
                 * since they can contain NIL chars */
 
2323
                if (idprop->subtype == IDP_STRING_SUB_BYTE) {
 
2324
                        memcpy(value, IDP_String(idprop), idprop->len);
 
2325
                        value[idprop->len] = '\0';
 
2326
                }
 
2327
                else {
 
2328
                        memcpy(value, IDP_String(idprop), idprop->len);
 
2329
                }
 
2330
        }
 
2331
        else if (sprop->get) {
1802
2332
                sprop->get(ptr, value);
1803
 
        else
 
2333
        }
 
2334
        else {
1804
2335
                strcpy(value, sprop->defaultvalue);
 
2336
        }
1805
2337
}
1806
2338
 
1807
 
char *RNA_property_string_get_alloc(PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen)
 
2339
char *RNA_property_string_get_alloc(PointerRNA *ptr, PropertyRNA *prop,
 
2340
                                    char *fixedbuf, int fixedlen, int *r_len)
1808
2341
{
1809
2342
        char *buf;
1810
2343
        int length;
1811
2344
 
1812
 
        length= RNA_property_string_length(ptr, prop);
1813
 
 
1814
 
        if(length+1 < fixedlen)
1815
 
                buf= fixedbuf;
 
2345
        BLI_assert(RNA_property_type(prop) == PROP_STRING);
 
2346
 
 
2347
        length = RNA_property_string_length(ptr, prop);
 
2348
 
 
2349
        if (length+1 < fixedlen)
 
2350
                buf = fixedbuf;
1816
2351
        else
1817
 
                buf= MEM_callocN(sizeof(char)*(length+1), "RNA_string_get_alloc");
 
2352
                buf = MEM_mallocN(sizeof(char)*(length+1), "RNA_string_get_alloc");
 
2353
 
 
2354
#ifndef NDEBUG
 
2355
        /* safety check to ensure the string is actually set */
 
2356
        buf[length] = 255;
 
2357
#endif
1818
2358
 
1819
2359
        RNA_property_string_get(ptr, prop, buf);
1820
2360
 
 
2361
#ifndef NDEBUG
 
2362
        BLI_assert(buf[length] == '\0');
 
2363
#endif
 
2364
 
 
2365
        if (r_len) {
 
2366
                *r_len = length;
 
2367
        }
 
2368
 
1821
2369
        return buf;
1822
2370
}
1823
2371
 
1824
2372
/* this is the length without \0 terminator */
1825
2373
int RNA_property_string_length(PointerRNA *ptr, PropertyRNA *prop)
1826
2374
{
1827
 
        StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
 
2375
        StringPropertyRNA *sprop = (StringPropertyRNA*)prop;
1828
2376
        IDProperty *idprop;
1829
2377
 
1830
 
        if((idprop=rna_idproperty_check(&prop, ptr)))
1831
 
                return strlen(IDP_String(idprop));
1832
 
        else if(sprop->length)
 
2378
        BLI_assert(RNA_property_type(prop) == PROP_STRING);
 
2379
 
 
2380
        if ((idprop = rna_idproperty_check(&prop, ptr))) {
 
2381
                if (idprop->subtype == IDP_STRING_SUB_BYTE) {
 
2382
                        return idprop->len;
 
2383
                }
 
2384
                else {
 
2385
#ifndef NDEBUG
 
2386
                        /* these _must_ stay in sync */
 
2387
                        BLI_assert(strlen(IDP_String(idprop)) == idprop->len - 1);
 
2388
#endif
 
2389
                        return idprop->len - 1;
 
2390
                }
 
2391
        }
 
2392
        else if (sprop->length)
1833
2393
                return sprop->length(ptr);
1834
2394
        else
1835
2395
                return strlen(sprop->defaultvalue);
1837
2397
 
1838
2398
void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *value)
1839
2399
{
1840
 
        StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
 
2400
        StringPropertyRNA *sprop = (StringPropertyRNA*)prop;
1841
2401
        IDProperty *idprop;
1842
2402
 
1843
 
        if((idprop=rna_idproperty_check(&prop, ptr)))
1844
 
                IDP_AssignString(idprop, (char*)value, RNA_property_string_maxlength(prop) - 1);
1845
 
        else if(sprop->set)
 
2403
        BLI_assert(RNA_property_type(prop) == PROP_STRING);
 
2404
 
 
2405
        if ((idprop = rna_idproperty_check(&prop, ptr))) {
 
2406
                /* both IDP_STRING_SUB_BYTE / IDP_STRING_SUB_UTF8 */
 
2407
                IDP_AssignString(idprop, value, RNA_property_string_maxlength(prop) - 1);
 
2408
                rna_idproperty_touch(idprop);
 
2409
        }
 
2410
        else if (sprop->set)
1846
2411
                sprop->set(ptr, value); /* set function needs to clamp its self */
1847
 
        else if(prop->flag & PROP_EDITABLE) {
 
2412
        else if (prop->flag & PROP_EDITABLE) {
1848
2413
                IDProperty *group;
1849
2414
 
1850
 
                group= RNA_struct_idproperties(ptr, 1);
1851
 
                if(group)
1852
 
                        IDP_AddToGroup(group, IDP_NewString((char*)value, (char*)prop->identifier, RNA_property_string_maxlength(prop) - 1));
 
2415
                group = RNA_struct_idprops(ptr, 1);
 
2416
                if (group)
 
2417
                        IDP_AddToGroup(group, IDP_NewString(value, prop->identifier, RNA_property_string_maxlength(prop) - 1));
1853
2418
        }
1854
2419
}
1855
2420
 
1856
 
void RNA_property_string_get_default(PointerRNA *ptr, PropertyRNA *prop, char *value)
 
2421
void RNA_property_string_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop, char *value)
1857
2422
{
1858
 
        StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
 
2423
        StringPropertyRNA *sprop = (StringPropertyRNA*)prop;
 
2424
 
 
2425
        BLI_assert(RNA_property_type(prop) == PROP_STRING);
 
2426
 
1859
2427
        strcpy(value, sprop->defaultvalue);
1860
2428
}
1861
2429
 
1864
2432
        char *buf;
1865
2433
        int length;
1866
2434
 
1867
 
        length= RNA_property_string_default_length(ptr, prop);
1868
 
 
1869
 
        if(length+1 < fixedlen)
1870
 
                buf= fixedbuf;
 
2435
        BLI_assert(RNA_property_type(prop) == PROP_STRING);
 
2436
 
 
2437
        length = RNA_property_string_default_length(ptr, prop);
 
2438
 
 
2439
        if (length+1 < fixedlen)
 
2440
                buf = fixedbuf;
1871
2441
        else
1872
 
                buf= MEM_callocN(sizeof(char)*(length+1), "RNA_string_get_alloc");
 
2442
                buf = MEM_callocN(sizeof(char)*(length+1), "RNA_string_get_alloc");
1873
2443
 
1874
2444
        RNA_property_string_get_default(ptr, prop, buf);
1875
2445
 
1877
2447
}
1878
2448
 
1879
2449
/* this is the length without \0 terminator */
1880
 
int RNA_property_string_default_length(PointerRNA *ptr, PropertyRNA *prop)
 
2450
int RNA_property_string_default_length(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
1881
2451
{
1882
 
        StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
 
2452
        StringPropertyRNA *sprop = (StringPropertyRNA*)prop;
 
2453
 
 
2454
        BLI_assert(RNA_property_type(prop) == PROP_STRING);
 
2455
 
1883
2456
        return strlen(sprop->defaultvalue);
1884
2457
}
1885
2458
 
1886
2459
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
1887
2460
{
1888
 
        EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
 
2461
        EnumPropertyRNA *eprop = (EnumPropertyRNA*)prop;
1889
2462
        IDProperty *idprop;
1890
2463
 
1891
 
        if((idprop=rna_idproperty_check(&prop, ptr)))
 
2464
        BLI_assert(RNA_property_type(prop) == PROP_ENUM);
 
2465
 
 
2466
        if ((idprop = rna_idproperty_check(&prop, ptr)))
1892
2467
                return IDP_Int(idprop);
1893
 
        else if(eprop->get)
 
2468
        else if (eprop->get)
1894
2469
                return eprop->get(ptr);
1895
2470
        else
1896
2471
                return eprop->defaultvalue;
1898
2473
 
1899
2474
void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value)
1900
2475
{
1901
 
        EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
 
2476
        EnumPropertyRNA *eprop = (EnumPropertyRNA*)prop;
1902
2477
        IDProperty *idprop;
1903
2478
 
1904
 
        if((idprop=rna_idproperty_check(&prop, ptr)))
1905
 
                IDP_Int(idprop)= value;
1906
 
        else if(eprop->set) {
 
2479
        BLI_assert(RNA_property_type(prop) == PROP_ENUM);
 
2480
 
 
2481
        if ((idprop = rna_idproperty_check(&prop, ptr))) {
 
2482
                IDP_Int(idprop) = value;
 
2483
                rna_idproperty_touch(idprop);
 
2484
        }
 
2485
        else if (eprop->set) {
1907
2486
                eprop->set(ptr, value);
1908
2487
        }
1909
 
        else if(prop->flag & PROP_EDITABLE) {
 
2488
        else if (prop->flag & PROP_EDITABLE) {
1910
2489
                IDPropertyTemplate val = {0};
1911
2490
                IDProperty *group;
1912
2491
 
1913
 
                val.i= value;
 
2492
                val.i = value;
1914
2493
 
1915
 
                group= RNA_struct_idproperties(ptr, 1);
1916
 
                if(group)
1917
 
                        IDP_AddToGroup(group, IDP_New(IDP_INT, val, (char*)prop->identifier));
 
2494
                group = RNA_struct_idprops(ptr, 1);
 
2495
                if (group)
 
2496
                        IDP_AddToGroup(group, IDP_New(IDP_INT, &val, prop->identifier));
1918
2497
        }
1919
2498
}
1920
2499
 
1921
 
int RNA_property_enum_get_default(PointerRNA *ptr, PropertyRNA *prop)
 
2500
int RNA_property_enum_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
1922
2501
{
1923
 
        EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
 
2502
        EnumPropertyRNA *eprop = (EnumPropertyRNA*)prop;
 
2503
 
 
2504
        BLI_assert(RNA_property_type(prop) == PROP_ENUM);
 
2505
 
1924
2506
        return eprop->defaultvalue;
1925
2507
}
1926
2508
 
 
2509
void *RNA_property_enum_py_data_get(PropertyRNA *prop)
 
2510
{
 
2511
        EnumPropertyRNA *eprop = (EnumPropertyRNA*)prop;
 
2512
 
 
2513
        BLI_assert(RNA_property_type(prop) == PROP_ENUM);
 
2514
 
 
2515
        return eprop->py_data;
 
2516
}
1927
2517
 
1928
2518
PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop)
1929
2519
{
1930
 
        PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
 
2520
        PointerPropertyRNA *pprop = (PointerPropertyRNA*)prop;
1931
2521
        IDProperty *idprop;
1932
2522
 
1933
 
        if((idprop=rna_idproperty_check(&prop, ptr))) {
1934
 
                pprop= (PointerPropertyRNA*)prop;
 
2523
        BLI_assert(RNA_property_type(prop) == PROP_POINTER);
 
2524
 
 
2525
        if ((idprop = rna_idproperty_check(&prop, ptr))) {
 
2526
                pprop = (PointerPropertyRNA*)prop;
1935
2527
 
1936
2528
                /* for groups, data is idprop itself */
1937
2529
                return rna_pointer_inherit_refine(ptr, pprop->type, idprop);
1938
2530
        }
1939
 
        else if(pprop->get) {
 
2531
        else if (pprop->get) {
1940
2532
                return pprop->get(ptr);
1941
2533
        }
1942
 
        else if(prop->flag & PROP_IDPROPERTY) {
 
2534
        else if (prop->flag & PROP_IDPROPERTY) {
1943
2535
                /* XXX temporary hack to add it automatically, reading should
1944
 
                   never do any write ops, to ensure thread safety etc .. */
 
2536
                 * never do any write ops, to ensure thread safety etc .. */
1945
2537
                RNA_property_pointer_add(ptr, prop);
1946
2538
                return RNA_property_pointer_get(ptr, prop);
1947
2539
        }
1948
2540
        else {
1949
 
                PointerRNA result;
1950
 
 
1951
 
                memset(&result, 0, sizeof(result));
1952
 
                return result;
 
2541
                return PointerRNA_NULL;
1953
2542
        }
1954
2543
}
1955
2544
 
1956
2545
void RNA_property_pointer_set(PointerRNA *ptr, PropertyRNA *prop, PointerRNA ptr_value)
1957
2546
{
1958
 
        IDProperty *idprop;
1959
 
 
1960
 
        if((idprop=rna_idproperty_check(&prop, ptr))) {
 
2547
        /*IDProperty *idprop;*/
 
2548
 
 
2549
        BLI_assert(RNA_property_type(prop) == PROP_POINTER);
 
2550
 
 
2551
        if ((/*idprop=*/ rna_idproperty_check(&prop, ptr))) {
1961
2552
                /* not supported */
 
2553
                /* rna_idproperty_touch(idprop); */
1962
2554
        }
1963
2555
        else {
1964
 
                PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
 
2556
                PointerPropertyRNA *pprop = (PointerPropertyRNA*)prop;
1965
2557
 
1966
 
                if(             pprop->set &&
 
2558
                if (            pprop->set &&
1967
2559
                                !((prop->flag & PROP_NEVER_NULL) && ptr_value.data == NULL) &&
1968
2560
                                !((prop->flag & PROP_ID_SELF_CHECK) && ptr->id.data == ptr_value.id.data)
1969
2561
                ) {
1972
2564
        }
1973
2565
}
1974
2566
 
 
2567
PointerRNA RNA_property_pointer_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop))
 
2568
{
 
2569
        /*PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop; */
 
2570
 
 
2571
        /* BLI_assert(RNA_property_type(prop) == PROP_POINTER); */
 
2572
 
 
2573
        return PointerRNA_NULL; /* FIXME: there has to be a way... */
 
2574
}
 
2575
 
1975
2576
void RNA_property_pointer_add(PointerRNA *ptr, PropertyRNA *prop)
1976
2577
{
1977
 
        IDProperty *idprop;
1978
 
 
1979
 
        if((idprop=rna_idproperty_check(&prop, ptr))) {
 
2578
        /*IDProperty *idprop;*/
 
2579
 
 
2580
        BLI_assert(RNA_property_type(prop) == PROP_POINTER);
 
2581
 
 
2582
        if ((/*idprop=*/rna_idproperty_check(&prop, ptr))) {
1980
2583
                /* already exists */
1981
2584
        }
1982
 
        else if(prop->flag & PROP_IDPROPERTY) {
 
2585
        else if (prop->flag & PROP_IDPROPERTY) {
1983
2586
                IDPropertyTemplate val = {0};
1984
2587
                IDProperty *group;
1985
2588
 
1986
 
                val.i= 0;
 
2589
                val.i = 0;
1987
2590
 
1988
 
                group= RNA_struct_idproperties(ptr, 1);
1989
 
                if(group)
1990
 
                        IDP_AddToGroup(group, IDP_New(IDP_GROUP, val, (char*)prop->identifier));
 
2591
                group = RNA_struct_idprops(ptr, 1);
 
2592
                if (group)
 
2593
                        IDP_AddToGroup(group, IDP_New(IDP_GROUP, &val, prop->identifier));
1991
2594
        }
1992
2595
        else
1993
 
                printf("RNA_property_pointer_add %s.%s: only supported for id properties.\n", ptr->type->identifier, prop->identifier);
 
2596
                printf("%s %s.%s: only supported for id properties.\n", __func__, ptr->type->identifier, prop->identifier);
1994
2597
}
1995
2598
 
1996
2599
void RNA_property_pointer_remove(PointerRNA *ptr, PropertyRNA *prop)
1997
2600
{
1998
2601
        IDProperty *idprop, *group;
1999
2602
 
2000
 
        if((idprop=rna_idproperty_check(&prop, ptr))) {
2001
 
                group= RNA_struct_idproperties(ptr, 0);
 
2603
        BLI_assert(RNA_property_type(prop) == PROP_POINTER);
 
2604
 
 
2605
        if ((idprop = rna_idproperty_check(&prop, ptr))) {
 
2606
                group = RNA_struct_idprops(ptr, 0);
2002
2607
                
2003
 
                if(group) {
 
2608
                if (group) {
2004
2609
                        IDP_RemFromGroup(group, idprop);
2005
2610
                        IDP_FreeProperty(idprop);
2006
2611
                        MEM_freeN(idprop);
2007
2612
                }
2008
2613
        }
2009
2614
        else
2010
 
                printf("RNA_property_pointer_remove %s.%s: only supported for id properties.\n", ptr->type->identifier, prop->identifier);
 
2615
                printf("%s %s.%s: only supported for id properties.\n", __func__, ptr->type->identifier, prop->identifier);
2011
2616
}
2012
2617
 
2013
2618
static void rna_property_collection_get_idp(CollectionPropertyIterator *iter)
2014
2619
{
2015
 
        CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)iter->prop;
 
2620
        CollectionPropertyRNA *cprop = (CollectionPropertyRNA*)iter->prop;
2016
2621
 
2017
 
        iter->ptr.data= rna_iterator_array_get(iter);
2018
 
        iter->ptr.type= cprop->item_type;
 
2622
        iter->ptr.data = rna_iterator_array_get(iter);
 
2623
        iter->ptr.type = cprop->item_type;
2019
2624
        rna_pointer_inherit_id(cprop->item_type, &iter->parent, &iter->ptr);
2020
2625
}
2021
2626
 
2023
2628
{
2024
2629
        IDProperty *idprop;
2025
2630
 
 
2631
        BLI_assert(RNA_property_type(prop) == PROP_COLLECTION);
 
2632
 
2026
2633
        memset(iter, 0, sizeof(*iter));
2027
2634
 
2028
 
        if((idprop=rna_idproperty_check(&prop, ptr)) || (prop->flag & PROP_IDPROPERTY)) {
2029
 
                iter->parent= *ptr;
2030
 
                iter->prop= prop;
 
2635
        if ((idprop = rna_idproperty_check(&prop, ptr)) || (prop->flag & PROP_IDPROPERTY)) {
 
2636
                iter->parent = *ptr;
 
2637
                iter->prop = prop;
2031
2638
 
2032
 
                if(idprop)
 
2639
                if (idprop)
2033
2640
                        rna_iterator_array_begin(iter, IDP_IDPArray(idprop), sizeof(IDProperty), idprop->len, 0, NULL);
2034
2641
                else
2035
2642
                        rna_iterator_array_begin(iter, NULL, sizeof(IDProperty), 0, 0, NULL);
2036
2643
 
2037
 
                if(iter->valid)
 
2644
                if (iter->valid)
2038
2645
                        rna_property_collection_get_idp(iter);
2039
2646
 
2040
 
                iter->idprop= 1;
 
2647
                iter->idprop = 1;
2041
2648
        }
2042
2649
        else {
2043
 
                CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
 
2650
                CollectionPropertyRNA *cprop = (CollectionPropertyRNA*)prop;
2044
2651
                cprop->begin(iter, ptr);
2045
2652
        }
2046
2653
}
2047
2654
 
2048
2655
void RNA_property_collection_next(CollectionPropertyIterator *iter)
2049
2656
{
2050
 
        CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)iter->prop;
 
2657
        CollectionPropertyRNA *cprop = (CollectionPropertyRNA*)rna_ensure_property(iter->prop);
2051
2658
 
2052
 
        if(iter->idprop) {
 
2659
        if (iter->idprop) {
2053
2660
                rna_iterator_array_next(iter);
2054
2661
 
2055
 
                if(iter->valid)
 
2662
                if (iter->valid)
2056
2663
                        rna_property_collection_get_idp(iter);
2057
2664
        }
2058
2665
        else
2061
2668
 
2062
2669
void RNA_property_collection_end(CollectionPropertyIterator *iter)
2063
2670
{
2064
 
        CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)iter->prop;
 
2671
        CollectionPropertyRNA *cprop = (CollectionPropertyRNA*)rna_ensure_property(iter->prop);
2065
2672
 
2066
 
        if(iter->idprop)
 
2673
        if (iter->idprop)
2067
2674
                rna_iterator_array_end(iter);
2068
2675
        else
2069
2676
                cprop->end(iter);
2071
2678
 
2072
2679
int RNA_property_collection_length(PointerRNA *ptr, PropertyRNA *prop)
2073
2680
{
2074
 
        CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
 
2681
        CollectionPropertyRNA *cprop = (CollectionPropertyRNA*)prop;
2075
2682
        IDProperty *idprop;
2076
2683
 
2077
 
        if((idprop=rna_idproperty_check(&prop, ptr))) {
 
2684
        BLI_assert(RNA_property_type(prop) == PROP_COLLECTION);
 
2685
 
 
2686
        if ((idprop = rna_idproperty_check(&prop, ptr))) {
2078
2687
                return idprop->len;
2079
2688
        }
2080
 
        else if(cprop->length) {
 
2689
        else if (cprop->length) {
2081
2690
                return cprop->length(ptr);
2082
2691
        }
2083
2692
        else {
2084
2693
                CollectionPropertyIterator iter;
2085
 
                int length= 0;
 
2694
                int length = 0;
2086
2695
 
2087
2696
                RNA_property_collection_begin(ptr, prop, &iter);
2088
 
                for(; iter.valid; RNA_property_collection_next(&iter))
 
2697
                for (; iter.valid; RNA_property_collection_next(&iter))
2089
2698
                        length++;
2090
2699
                RNA_property_collection_end(&iter);
2091
2700
 
2096
2705
void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *r_ptr)
2097
2706
{
2098
2707
        IDProperty *idprop;
2099
 
//      CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
2100
 
 
2101
 
        if((idprop=rna_idproperty_check(&prop, ptr))) {
 
2708
/*      CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; */
 
2709
 
 
2710
        BLI_assert(RNA_property_type(prop) == PROP_COLLECTION);
 
2711
 
 
2712
        if ((idprop = rna_idproperty_check(&prop, ptr))) {
2102
2713
                IDPropertyTemplate val = {0};
2103
2714
                IDProperty *item;
2104
2715
 
2105
 
                item= IDP_New(IDP_GROUP, val, "");
 
2716
                item = IDP_New(IDP_GROUP, &val, "");
2106
2717
                IDP_AppendArray(idprop, item);
2107
 
                // IDP_FreeProperty(item); // IDP_AppendArray does a shallow copy (memcpy), only free memory 
 
2718
                /* IDP_FreeProperty(item);  *//* IDP_AppendArray does a shallow copy (memcpy), only free memory  */
2108
2719
                MEM_freeN(item);
2109
2720
        }
2110
 
        else if(prop->flag & PROP_IDPROPERTY) {
 
2721
        else if (prop->flag & PROP_IDPROPERTY) {
2111
2722
                IDProperty *group, *item;
2112
2723
                IDPropertyTemplate val = {0};
2113
2724
 
2114
 
                group= RNA_struct_idproperties(ptr, 1);
2115
 
                if(group) {
2116
 
                        idprop= IDP_NewIDPArray(prop->identifier);
 
2725
                group = RNA_struct_idprops(ptr, 1);
 
2726
                if (group) {
 
2727
                        idprop = IDP_NewIDPArray(prop->identifier);
2117
2728
                        IDP_AddToGroup(group, idprop);
2118
2729
 
2119
 
                        item= IDP_New(IDP_GROUP, val, "");
 
2730
                        item = IDP_New(IDP_GROUP, &val, "");
2120
2731
                        IDP_AppendArray(idprop, item);
2121
 
                        // IDP_FreeProperty(item); // IDP_AppendArray does a shallow copy (memcpy), only free memory
 
2732
                        /* IDP_FreeProperty(item);  *//* IDP_AppendArray does a shallow copy (memcpy), only free memory */
2122
2733
                        MEM_freeN(item);
2123
2734
                }
2124
2735
        }
2125
2736
 
2126
2737
        /* py api calls directly */
2127
2738
#if 0
2128
 
        else if(cprop->add){
2129
 
                if(!(cprop->add->flag & FUNC_USE_CONTEXT)) { /* XXX check for this somewhere else */
 
2739
        else if (cprop->add) {
 
2740
                if (!(cprop->add->flag & FUNC_USE_CONTEXT)) { /* XXX check for this somewhere else */
2130
2741
                        ParameterList params;
2131
2742
                        RNA_parameter_list_create(&params, ptr, cprop->add);
2132
2743
                        RNA_function_call(NULL, NULL, ptr, cprop->add, &params);
2134
2745
                }
2135
2746
        }
2136
2747
        /*else
2137
 
                printf("RNA_property_collection_add %s.%s: not implemented for this property.\n", ptr->type->identifier, prop->identifier);*/
 
2748
                printf("%s %s.%s: not implemented for this property.\n", __func__, ptr->type->identifier, prop->identifier);*/
2138
2749
#endif
2139
2750
 
2140
 
        if(r_ptr) {
2141
 
                if(idprop) {
2142
 
                        CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
 
2751
        if (r_ptr) {
 
2752
                if (idprop) {
 
2753
                        CollectionPropertyRNA *cprop = (CollectionPropertyRNA*)prop;
2143
2754
 
2144
 
                        r_ptr->data= IDP_GetIndexArray(idprop, idprop->len-1);
2145
 
                        r_ptr->type= cprop->item_type;
 
2755
                        r_ptr->data = IDP_GetIndexArray(idprop, idprop->len-1);
 
2756
                        r_ptr->type = cprop->item_type;
2146
2757
                        rna_pointer_inherit_id(NULL, ptr, r_ptr);
2147
2758
                }
2148
2759
                else
2153
2764
int RNA_property_collection_remove(PointerRNA *ptr, PropertyRNA *prop, int key)
2154
2765
{
2155
2766
        IDProperty *idprop;
2156
 
//      CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
2157
 
 
2158
 
        if((idprop=rna_idproperty_check(&prop, ptr))) {
 
2767
/*      CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; */
 
2768
 
 
2769
        BLI_assert(RNA_property_type(prop) == PROP_COLLECTION);
 
2770
 
 
2771
        if ((idprop = rna_idproperty_check(&prop, ptr))) {
2159
2772
                IDProperty tmp, *array;
2160
2773
                int len;
2161
2774
 
2162
 
                len= idprop->len;
2163
 
                array= IDP_IDPArray(idprop);
 
2775
                len = idprop->len;
 
2776
                array = IDP_IDPArray(idprop);
2164
2777
 
2165
 
                if(key >= 0 && key < len) {
2166
 
                        if(key+1 < len) {
 
2778
                if (key >= 0 && key < len) {
 
2779
                        if (key+1 < len) {
2167
2780
                                /* move element to be removed to the back */
2168
2781
                                memcpy(&tmp, &array[key], sizeof(IDProperty));
2169
2782
                                memmove(array+key, array+key+1, sizeof(IDProperty)*(len-(key+1)));
2175
2788
 
2176
2789
                return 1;
2177
2790
        }
2178
 
        else if(prop->flag & PROP_IDPROPERTY)
 
2791
        else if (prop->flag & PROP_IDPROPERTY)
2179
2792
                return 1;
2180
2793
 
2181
2794
        /* py api calls directly */
2182
2795
#if 0
2183
 
        else if(cprop->remove){
2184
 
                if(!(cprop->remove->flag & FUNC_USE_CONTEXT)) { /* XXX check for this somewhere else */
 
2796
        else if (cprop->remove) {
 
2797
                if (!(cprop->remove->flag & FUNC_USE_CONTEXT)) { /* XXX check for this somewhere else */
2185
2798
                        ParameterList params;
2186
2799
                        RNA_parameter_list_create(&params, ptr, cprop->remove);
2187
2800
                        RNA_function_call(NULL, NULL, ptr, cprop->remove, &params);
2191
2804
                return 0;
2192
2805
        }
2193
2806
        /*else
2194
 
                printf("RNA_property_collection_remove %s.%s: only supported for id properties.\n", ptr->type->identifier, prop->identifier);*/
 
2807
                printf("%s %s.%s: only supported for id properties.\n", __func__, ptr->type->identifier, prop->identifier);*/
2195
2808
#endif
2196
2809
        return 0;
2197
2810
}
2200
2813
{
2201
2814
        IDProperty *idprop;
2202
2815
 
2203
 
        if((idprop=rna_idproperty_check(&prop, ptr))) {
 
2816
        BLI_assert(RNA_property_type(prop) == PROP_COLLECTION);
 
2817
 
 
2818
        if ((idprop = rna_idproperty_check(&prop, ptr))) {
2204
2819
                IDProperty tmp, *array;
2205
2820
                int len;
2206
2821
 
2207
 
                len= idprop->len;
2208
 
                array= IDP_IDPArray(idprop);
 
2822
                len = idprop->len;
 
2823
                array = IDP_IDPArray(idprop);
2209
2824
 
2210
 
                if(key >= 0 && key < len && pos >= 0 && pos < len && key != pos) {
 
2825
                if (key >= 0 && key < len && pos >= 0 && pos < len && key != pos) {
2211
2826
                        memcpy(&tmp, &array[key], sizeof(IDProperty));
2212
 
                        if(pos < key)
 
2827
                        if (pos < key)
2213
2828
                                memmove(array+pos+1, array+pos, sizeof(IDProperty)*(key - pos));
2214
2829
                        else
2215
2830
                                memmove(array+key, array+key+1, sizeof(IDProperty)*(pos - key));
2218
2833
 
2219
2834
                return 1;
2220
2835
        }
2221
 
        else if(prop->flag & PROP_IDPROPERTY)
 
2836
        else if (prop->flag & PROP_IDPROPERTY)
2222
2837
                return 1;
2223
2838
 
2224
2839
        return 0;
2228
2843
{
2229
2844
        IDProperty *idprop;
2230
2845
 
2231
 
        if((idprop=rna_idproperty_check(&prop, ptr)))
 
2846
        BLI_assert(RNA_property_type(prop) == PROP_COLLECTION);
 
2847
 
 
2848
        if ((idprop = rna_idproperty_check(&prop, ptr)))
2232
2849
                IDP_ResizeIDPArray(idprop, 0);
2233
2850
}
2234
2851
 
2235
2852
int RNA_property_collection_lookup_index(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *t_ptr)
2236
2853
{
2237
2854
        CollectionPropertyIterator iter;
2238
 
        int index= 0;
 
2855
        int index = 0;
2239
2856
        
 
2857
        BLI_assert(RNA_property_type(prop) == PROP_COLLECTION);
 
2858
 
2240
2859
        RNA_property_collection_begin(ptr, prop, &iter);
2241
 
        for(index=0; iter.valid; RNA_property_collection_next(&iter), index++) {
 
2860
        for (index = 0; iter.valid; RNA_property_collection_next(&iter), index++) {
2242
2861
                if (iter.ptr.data == t_ptr->data)
2243
2862
                        break;
2244
2863
        }
2253
2872
 
2254
2873
int RNA_property_collection_lookup_int(PointerRNA *ptr, PropertyRNA *prop, int key, PointerRNA *r_ptr)
2255
2874
{
2256
 
        CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
2257
 
 
2258
 
        if(cprop->lookupint) {
 
2875
        CollectionPropertyRNA *cprop = (CollectionPropertyRNA*)rna_ensure_property(prop);
 
2876
 
 
2877
        BLI_assert(RNA_property_type(prop) == PROP_COLLECTION);
 
2878
 
 
2879
        if (cprop->lookupint) {
2259
2880
                /* we have a callback defined, use it */
2260
 
                *r_ptr= cprop->lookupint(ptr, key);
2261
 
                return (r_ptr->data != NULL);
 
2881
                return cprop->lookupint(ptr, key, r_ptr);
2262
2882
        }
2263
2883
        else {
2264
2884
                /* no callback defined, just iterate and find the nth item */
2266
2886
                int i;
2267
2887
 
2268
2888
                RNA_property_collection_begin(ptr, prop, &iter);
2269
 
                for(i=0; iter.valid; RNA_property_collection_next(&iter), i++) {
2270
 
                        if(i == key) {
2271
 
                                *r_ptr= iter.ptr;
 
2889
                for (i = 0; iter.valid; RNA_property_collection_next(&iter), i++) {
 
2890
                        if (i == key) {
 
2891
                                *r_ptr = iter.ptr;
2272
2892
                                break;
2273
2893
                        }
2274
2894
                }
2275
2895
                RNA_property_collection_end(&iter);
2276
2896
 
2277
 
                if(!iter.valid)
 
2897
                if (!iter.valid)
2278
2898
                        memset(r_ptr, 0, sizeof(*r_ptr));
2279
2899
 
2280
2900
                return iter.valid;
2283
2903
 
2284
2904
int RNA_property_collection_lookup_string(PointerRNA *ptr, PropertyRNA *prop, const char *key, PointerRNA *r_ptr)
2285
2905
{
2286
 
        CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
2287
 
 
2288
 
        if(cprop->lookupstring) {
 
2906
        CollectionPropertyRNA *cprop = (CollectionPropertyRNA*)rna_ensure_property(prop);
 
2907
 
 
2908
        BLI_assert(RNA_property_type(prop) == PROP_COLLECTION);
 
2909
 
 
2910
        if (cprop->lookupstring) {
2289
2911
                /* we have a callback defined, use it */
2290
 
                *r_ptr= cprop->lookupstring(ptr, key);
2291
 
                return (r_ptr->data != NULL);
 
2912
                return cprop->lookupstring(ptr, key, r_ptr);
2292
2913
        }
2293
2914
        else {
2294
2915
                /* no callback defined, compare with name properties if they exist */
2295
2916
                CollectionPropertyIterator iter;
2296
2917
                PropertyRNA *nameprop;
2297
2918
                char name[256], *nameptr;
2298
 
                int found= 0;
 
2919
                int found = 0;
 
2920
                int keylen = strlen(key);
 
2921
                int namelen;
2299
2922
 
2300
2923
                RNA_property_collection_begin(ptr, prop, &iter);
2301
 
                for(; iter.valid; RNA_property_collection_next(&iter)) {
2302
 
                        if(iter.ptr.data && iter.ptr.type->nameproperty) {
2303
 
                                nameprop= iter.ptr.type->nameproperty;
2304
 
 
2305
 
                                nameptr= RNA_property_string_get_alloc(&iter.ptr, nameprop, name, sizeof(name));
2306
 
 
2307
 
                                if(strcmp(nameptr, key) == 0) {
2308
 
                                        *r_ptr= iter.ptr;
2309
 
                                        found= 1;
 
2924
                for (; iter.valid; RNA_property_collection_next(&iter)) {
 
2925
                        if (iter.ptr.data && iter.ptr.type->nameproperty) {
 
2926
                                nameprop = iter.ptr.type->nameproperty;
 
2927
 
 
2928
                                nameptr = RNA_property_string_get_alloc(&iter.ptr, nameprop, name, sizeof(name), &namelen);
 
2929
 
 
2930
                                if ((keylen == namelen) && (strcmp(nameptr, key) == 0)) {
 
2931
                                        *r_ptr = iter.ptr;
 
2932
                                        found = 1;
2310
2933
                                }
2311
2934
 
2312
 
                                if((char *)&name != nameptr)
 
2935
                                if ((char *)&name != nameptr)
2313
2936
                                        MEM_freeN(nameptr);
2314
2937
 
2315
 
                                if(found)
 
2938
                                if (found)
2316
2939
                                        break;
2317
2940
                        }
2318
2941
                }
2319
2942
                RNA_property_collection_end(&iter);
2320
2943
 
2321
 
                if(!iter.valid)
 
2944
                if (!iter.valid)
2322
2945
                        memset(r_ptr, 0, sizeof(*r_ptr));
2323
2946
 
2324
2947
                return iter.valid;
2325
2948
        }
2326
2949
}
2327
2950
 
 
2951
/* zero return is an assignment error */
 
2952
int RNA_property_collection_assign_int(PointerRNA *ptr, PropertyRNA *prop, const int key, const PointerRNA *assign_ptr)
 
2953
{
 
2954
        CollectionPropertyRNA *cprop = (CollectionPropertyRNA*)rna_ensure_property(prop);
 
2955
 
 
2956
        BLI_assert(RNA_property_type(prop) == PROP_COLLECTION);
 
2957
 
 
2958
        if (cprop->assignint) {
 
2959
                /* we have a callback defined, use it */
 
2960
                return cprop->assignint(ptr, key, assign_ptr);
 
2961
        }
 
2962
 
 
2963
        return 0;
 
2964
}
 
2965
 
2328
2966
int RNA_property_collection_type_get(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *r_ptr)
2329
2967
{
2330
 
        *r_ptr= *ptr;
2331
 
        return ((r_ptr->type = prop->srna) ? 1:0);
 
2968
        BLI_assert(RNA_property_type(prop) == PROP_COLLECTION);
 
2969
 
 
2970
        *r_ptr = *ptr;
 
2971
        return ((r_ptr->type = rna_ensure_property(prop)->srna) ? 1:0);
2332
2972
}
2333
2973
 
2334
2974
int RNA_property_collection_raw_array(PointerRNA *ptr, PropertyRNA *prop, PropertyRNA *itemprop, RawArray *array)
2337
2977
        ArrayIterator *internal;
2338
2978
        char *arrayp;
2339
2979
 
2340
 
        if(!(prop->flag & PROP_RAW_ARRAY) || !(itemprop->flag & PROP_RAW_ACCESS))
 
2980
        BLI_assert(RNA_property_type(prop) == PROP_COLLECTION);
 
2981
 
 
2982
        if (!(prop->flag & PROP_RAW_ARRAY) || !(itemprop->flag & PROP_RAW_ACCESS))
2341
2983
                return 0;
2342
2984
 
2343
2985
        RNA_property_collection_begin(ptr, prop, &iter);
2344
2986
 
2345
 
        if(iter.valid) {
 
2987
        if (iter.valid) {
2346
2988
                /* get data from array iterator and item property */
2347
 
                internal= iter.internal;
2348
 
                arrayp= (iter.valid)? iter.ptr.data: NULL;
 
2989
                internal = iter.internal;
 
2990
                arrayp = (iter.valid)? iter.ptr.data: NULL;
2349
2991
 
2350
 
                if(internal->skip || !RNA_property_editable(&iter.ptr, itemprop)) {
 
2992
                if (internal->skip || !RNA_property_editable(&iter.ptr, itemprop)) {
2351
2993
                        /* we might skip some items, so it's not a proper array */
2352
2994
                        RNA_property_collection_end(&iter);
2353
2995
                        return 0;
2354
2996
                }
2355
2997
 
2356
 
                array->array= arrayp + itemprop->rawoffset;
2357
 
                array->stride= internal->itemsize;
2358
 
                array->len= ((char*)internal->endptr - arrayp)/internal->itemsize;
2359
 
                array->type= itemprop->rawtype;
 
2998
                array->array = arrayp + itemprop->rawoffset;
 
2999
                array->stride = internal->itemsize;
 
3000
                array->len = ((char*)internal->endptr - arrayp)/internal->itemsize;
 
3001
                array->type = itemprop->rawtype;
2360
3002
        }
2361
3003
        else
2362
3004
                memset(array, 0, sizeof(RawArray));
2366
3008
        return 1;
2367
3009
}
2368
3010
 
2369
 
#define RAW_GET(dtype, var, raw, a) \
2370
 
{ \
2371
 
        switch(raw.type) { \
2372
 
                case PROP_RAW_CHAR: var = (dtype)((char*)raw.array)[a]; break; \
2373
 
                case PROP_RAW_SHORT: var = (dtype)((short*)raw.array)[a]; break; \
2374
 
                case PROP_RAW_INT: var = (dtype)((int*)raw.array)[a]; break; \
2375
 
                case PROP_RAW_FLOAT: var = (dtype)((float*)raw.array)[a]; break; \
2376
 
                case PROP_RAW_DOUBLE: var = (dtype)((double*)raw.array)[a]; break; \
2377
 
                default: var = (dtype)0; \
2378
 
        } \
 
3011
#define RAW_GET(dtype, var, raw, a)                                           \
 
3012
{                                                                             \
 
3013
        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;    \
 
3019
                default: var = (dtype)0;                                              \
 
3020
        }                                                                         \
2379
3021
}
2380
3022
 
2381
 
#define RAW_SET(dtype, raw, a, var) \
2382
 
{ \
2383
 
        switch(raw.type) { \
2384
 
                case PROP_RAW_CHAR: ((char*)raw.array)[a] = (char)var; break; \
2385
 
                case PROP_RAW_SHORT: ((short*)raw.array)[a] = (short)var; break; \
2386
 
                case PROP_RAW_INT: ((int*)raw.array)[a] = (int)var; break; \
2387
 
                case PROP_RAW_FLOAT: ((float*)raw.array)[a] = (float)var; break; \
2388
 
                case PROP_RAW_DOUBLE: ((double*)raw.array)[a] = (double)var; break; \
2389
 
                default: break; \
2390
 
        } \
 
3023
#define RAW_SET(dtype, raw, a, var)                                           \
 
3024
{                                                                             \
 
3025
        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;   \
 
3031
                default: break;                                                       \
 
3032
        }                                                                         \
2391
3033
}
2392
3034
 
2393
3035
int RNA_raw_type_sizeof(RawPropertyType type)
2394
3036
{
2395
 
        switch(type) {
 
3037
        switch (type) {
2396
3038
                case PROP_RAW_CHAR: return sizeof(char);
2397
3039
                case PROP_RAW_SHORT: return sizeof(short);
2398
3040
                case PROP_RAW_INT: return sizeof(int);
2402
3044
        }
2403
3045
}
2404
3046
 
2405
 
static int rna_raw_access(ReportList *reports, PointerRNA *ptr, PropertyRNA *prop, char *propname, void *inarray, RawPropertyType intype, int inlen, int set)
 
3047
static int rna_raw_access(ReportList *reports, PointerRNA *ptr, PropertyRNA *prop, const char *propname,
 
3048
                          void *inarray, RawPropertyType intype, int inlen, int set)
2406
3049
{
2407
3050
        StructRNA *ptype;
2408
3051
        PointerRNA itemptr;
2409
3052
        PropertyRNA *itemprop, *iprop;
2410
 
        PropertyType itemtype=0;
 
3053
        PropertyType itemtype = 0;
2411
3054
        RawArray in;
2412
 
        int itemlen= 0;
 
3055
        int itemlen = 0;
2413
3056
 
2414
3057
        /* initialize in array, stride assumed 0 in following code */
2415
 
        in.array= inarray;
2416
 
        in.type= intype;
2417
 
        in.len= inlen;
2418
 
        in.stride= 0;
 
3058
        in.array = inarray;
 
3059
        in.type = intype;
 
3060
        in.len = inlen;
 
3061
        in.stride = 0;
2419
3062
 
2420
 
        ptype= RNA_property_pointer_type(ptr, prop);
 
3063
        ptype = RNA_property_pointer_type(ptr, prop);
2421
3064
 
2422
3065
        /* try to get item property pointer */
2423
3066
        RNA_pointer_create(NULL, ptype, NULL, &itemptr);
2424
 
        itemprop= RNA_struct_find_property(&itemptr, propname);
 
3067
        itemprop = RNA_struct_find_property(&itemptr, propname);
2425
3068
 
2426
 
        if(itemprop) {
 
3069
        if (itemprop) {
2427
3070
                /* we have item property pointer */
2428
3071
                RawArray out;
2429
3072
 
2430
3073
                /* check type */
2431
 
                itemtype= RNA_property_type(itemprop);
 
3074
                itemtype = RNA_property_type(itemprop);
2432
3075
 
2433
 
                if(!ELEM3(itemtype, PROP_BOOLEAN, PROP_INT, PROP_FLOAT)) {
2434
 
                        BKE_report(reports, RPT_ERROR, "Only boolean, int and float properties supported.");
 
3076
                if (!ELEM3(itemtype, PROP_BOOLEAN, PROP_INT, PROP_FLOAT)) {
 
3077
                        BKE_report(reports, RPT_ERROR, "Only boolean, int and float properties supported");
2435
3078
                        return 0;
2436
3079
                }
2437
3080
 
2438
3081
                /* check item array */
2439
 
                itemlen= RNA_property_array_length(&itemptr, itemprop);
 
3082
                itemlen = RNA_property_array_length(&itemptr, itemprop);
2440
3083
 
2441
3084
                /* try to access as raw array */
2442
 
                if(RNA_property_collection_raw_array(ptr, prop, itemprop, &out)) {
 
3085
                if (RNA_property_collection_raw_array(ptr, prop, itemprop, &out)) {
2443
3086
                        int arraylen = (itemlen == 0) ? 1 : itemlen;
2444
 
                        if(in.len != arraylen*out.len) {
2445
 
                                BKE_reportf(reports, RPT_ERROR, "Array length mismatch (expected %d, got %d).", out.len*arraylen, in.len);
 
3087
                        if (in.len != arraylen*out.len) {
 
3088
                                BKE_reportf(reports, RPT_ERROR, "Array length mismatch (expected %d, got %d)",
 
3089
                                            out.len * arraylen, in.len);
2446
3090
                                return 0;
2447
3091
                        }
2448
3092
                        
2449
3093
                        /* matching raw types */
2450
 
                        if(out.type == in.type) {
2451
 
                                void *inp= in.array;
2452
 
                                void *outp= out.array;
 
3094
                        if (out.type == in.type) {
 
3095
                                void *inp = in.array;
 
3096
                                void *outp = out.array;
2453
3097
                                int a, size;
2454
3098
 
2455
 
                                size= RNA_raw_type_sizeof(out.type) * arraylen;
 
3099
                                size = RNA_raw_type_sizeof(out.type) * arraylen;
2456
3100
 
2457
 
                                for(a=0; a<out.len; a++) {
2458
 
                                        if(set) memcpy(outp, inp, size);
 
3101
                                for (a = 0; a<out.len; a++) {
 
3102
                                        if (set) memcpy(outp, inp, size);
2459
3103
                                        else memcpy(inp, outp, size);
2460
3104
 
2461
 
                                        inp= (char*)inp + size;
2462
 
                                        outp= (char*)outp + out.stride;
 
3105
                                        inp = (char*)inp + size;
 
3106
                                        outp = (char*)outp + out.stride;
2463
3107
                                }
2464
3108
 
2465
3109
                                return 1;
2471
3115
        }
2472
3116
 
2473
3117
        {
2474
 
                void *tmparray= NULL;
2475
 
                int tmplen= 0;
2476
 
                int err= 0, j, a= 0;
 
3118
                void *tmparray = NULL;
 
3119
                int tmplen = 0;
 
3120
                int err = 0, j, a = 0;
2477
3121
                int needconv = 1;
2478
3122
 
2479
3123
                if (((itemtype == PROP_BOOLEAN || itemtype == PROP_INT) && in.type == PROP_RAW_INT) ||
2484
3128
                /* no item property pointer, can still be id property, or
2485
3129
                 * property of a type derived from the collection pointer type */
2486
3130
                RNA_PROP_BEGIN(ptr, itemptr, prop) {
2487
 
                        if(itemptr.data) {
2488
 
                                if(itemprop) {
 
3131
                        if (itemptr.data) {
 
3132
                                if (itemprop) {
2489
3133
                                        /* we got the property already */
2490
 
                                        iprop= itemprop;
 
3134
                                        iprop = itemprop;
2491
3135
                                }
2492
3136
                                else {
2493
3137
                                        /* not yet, look it up and verify if it is valid */
2494
 
                                        iprop= RNA_struct_find_property(&itemptr, propname);
 
3138
                                        iprop = RNA_struct_find_property(&itemptr, propname);
2495
3139
 
2496
 
                                        if(iprop) {
2497
 
                                                itemlen= RNA_property_array_length(&itemptr, iprop);
2498
 
                                                itemtype= RNA_property_type(iprop);
 
3140
                                        if (iprop) {
 
3141
                                                itemlen = RNA_property_array_length(&itemptr, iprop);
 
3142
                                                itemtype = RNA_property_type(iprop);
2499
3143
                                        }
2500
3144
                                        else {
2501
 
                                                BKE_reportf(reports, RPT_ERROR, "Property named %s not found.", propname);
2502
 
                                                err= 1;
 
3145
                                                BKE_reportf(reports, RPT_ERROR, "Property named %s not found", propname);
 
3146
                                                err = 1;
2503
3147
                                                break;
2504
3148
                                        }
2505
3149
 
2506
 
                                        if(!ELEM3(itemtype, PROP_BOOLEAN, PROP_INT, PROP_FLOAT)) {
2507
 
                                                BKE_report(reports, RPT_ERROR, "Only boolean, int and float properties supported.");
2508
 
                                                err= 1;
 
3150
                                        if (!ELEM3(itemtype, PROP_BOOLEAN, PROP_INT, PROP_FLOAT)) {
 
3151
                                                BKE_report(reports, RPT_ERROR, "Only boolean, int and float properties supported");
 
3152
                                                err = 1;
2509
3153
                                                break;
2510
3154
                                        }
2511
3155
                                }
2512
3156
 
2513
3157
                                /* editable check */
2514
 
                                if(RNA_property_editable(&itemptr, iprop)) {
2515
 
                                        if(a+itemlen > in.len) {
2516
 
                                                BKE_reportf(reports, RPT_ERROR, "Array length mismatch (got %d, expected more).", in.len);
2517
 
                                                err= 1;
 
3158
                                if (!set || RNA_property_editable(&itemptr, iprop)) {
 
3159
                                        if (a+itemlen > in.len) {
 
3160
                                                BKE_reportf(reports, RPT_ERROR, "Array length mismatch (got %d, expected more)", in.len);
 
3161
                                                err = 1;
2518
3162
                                                break;
2519
3163
                                        }
2520
3164
 
2521
 
                                        if(itemlen == 0) {
 
3165
                                        if (itemlen == 0) {
2522
3166
                                                /* handle conversions */
2523
 
                                                if(set) {
2524
 
                                                        switch(itemtype) {
 
3167
                                                if (set) {
 
3168
                                                        switch (itemtype) {
2525
3169
                                                                case PROP_BOOLEAN: {
2526
3170
                                                                        int b;
2527
3171
                                                                        RAW_GET(int, b, in, a);
2545
3189
                                                        }
2546
3190
                                                }
2547
3191
                                                else {
2548
 
                                                        switch(itemtype) {
 
3192
                                                        switch (itemtype) {
2549
3193
                                                                case PROP_BOOLEAN: {
2550
 
                                                                        int b= RNA_property_boolean_get(&itemptr, iprop);
 
3194
                                                                        int b = RNA_property_boolean_get(&itemptr, iprop);
2551
3195
                                                                        RAW_SET(int, in, a, b);
2552
3196
                                                                        break;
2553
3197
                                                                }
2554
3198
                                                                case PROP_INT: {
2555
 
                                                                        int i= RNA_property_int_get(&itemptr, iprop);
 
3199
                                                                        int i = RNA_property_int_get(&itemptr, iprop);
2556
3200
                                                                        RAW_SET(int, in, a, i);
2557
3201
                                                                        break;
2558
3202
                                                                }
2559
3203
                                                                case PROP_FLOAT: {
2560
 
                                                                        float f= RNA_property_float_get(&itemptr, iprop);
 
3204
                                                                        float f = RNA_property_float_get(&itemptr, iprop);
2561
3205
                                                                        RAW_SET(float, in, a, f);
2562
3206
                                                                        break;
2563
3207
                                                                }
2569
3213
                                        }
2570
3214
                                        else if (needconv == 1) {
2571
3215
                                                /* allocate temporary array if needed */
2572
 
                                                if(tmparray && tmplen != itemlen) {
 
3216
                                                if (tmparray && tmplen != itemlen) {
2573
3217
                                                        MEM_freeN(tmparray);
2574
 
                                                        tmparray= NULL;
 
3218
                                                        tmparray = NULL;
2575
3219
                                                }
2576
 
                                                if(!tmparray) {
2577
 
                                                        tmparray= MEM_callocN(sizeof(float)*itemlen, "RNA tmparray\n");
2578
 
                                                        tmplen= itemlen;
 
3220
                                                if (!tmparray) {
 
3221
                                                        tmparray = MEM_callocN(sizeof(float)*itemlen, "RNA tmparray\n");
 
3222
                                                        tmplen = itemlen;
2579
3223
                                                }
2580
3224
 
2581
3225
                                                /* handle conversions */
2582
 
                                                if(set) {
2583
 
                                                        switch(itemtype) {
 
3226
                                                if (set) {
 
3227
                                                        switch (itemtype) {
2584
3228
                                                                case PROP_BOOLEAN: {
2585
 
                                                                        for(j=0; j<itemlen; j++, a++)
 
3229
                                                                        for (j = 0; j<itemlen; j++, a++)
2586
3230
                                                                                RAW_GET(int, ((int*)tmparray)[j], in, a);
2587
3231
                                                                        RNA_property_boolean_set_array(&itemptr, iprop, tmparray);
2588
3232
                                                                        break;
2589
3233
                                                                }
2590
3234
                                                                case PROP_INT: {
2591
 
                                                                        for(j=0; j<itemlen; j++, a++)
 
3235
                                                                        for (j = 0; j<itemlen; j++, a++)
2592
3236
                                                                                RAW_GET(int, ((int*)tmparray)[j], in, a);
2593
3237
                                                                        RNA_property_int_set_array(&itemptr, iprop, tmparray);
2594
3238
                                                                        break;
2595
3239
                                                                }
2596
3240
                                                                case PROP_FLOAT: {
2597
 
                                                                        for(j=0; j<itemlen; j++, a++)
 
3241
                                                                        for (j = 0; j<itemlen; j++, a++)
2598
3242
                                                                                RAW_GET(float, ((float*)tmparray)[j], in, a);
2599
3243
                                                                        RNA_property_float_set_array(&itemptr, iprop, tmparray);
2600
3244
                                                                        break;
2604
3248
                                                        }
2605
3249
                                                }
2606
3250
                                                else {
2607
 
                                                        switch(itemtype) {
 
3251
                                                        switch (itemtype) {
2608
3252
                                                                case PROP_BOOLEAN: {
2609
3253
                                                                        RNA_property_boolean_get_array(&itemptr, iprop, tmparray);
2610
 
                                                                        for(j=0; j<itemlen; j++, a++)
 
3254
                                                                        for (j = 0; j<itemlen; j++, a++)
2611
3255
                                                                                RAW_SET(int, in, a, ((int*)tmparray)[j]);
2612
3256
                                                                        break;
2613
3257
                                                                }
2614
3258
                                                                case PROP_INT: {
2615
3259
                                                                        RNA_property_int_get_array(&itemptr, iprop, tmparray);
2616
 
                                                                        for(j=0; j<itemlen; j++, a++)
 
3260
                                                                        for (j = 0; j<itemlen; j++, a++)
2617
3261
                                                                                RAW_SET(int, in, a, ((int*)tmparray)[j]);
2618
3262
                                                                        break;
2619
3263
                                                                }
2620
3264
                                                                case PROP_FLOAT: {
2621
3265
                                                                        RNA_property_float_get_array(&itemptr, iprop, tmparray);
2622
 
                                                                        for(j=0; j<itemlen; j++, a++)
 
3266
                                                                        for (j = 0; j<itemlen; j++, a++)
2623
3267
                                                                                RAW_SET(float, in, a, ((float*)tmparray)[j]);
2624
3268
                                                                        break;
2625
3269
                                                                }
2629
3273
                                                }
2630
3274
                                        }
2631
3275
                                        else {
2632
 
                                                if(set) {
2633
 
                                                        switch(itemtype) {
 
3276
                                                if (set) {
 
3277
                                                        switch (itemtype) {
2634
3278
                                                                case PROP_BOOLEAN: {
2635
3279
                                                                        RNA_property_boolean_set_array(&itemptr, iprop, &((int*)in.array)[a]);
2636
3280
                                                                        a += itemlen;
2651
3295
                                                        }
2652
3296
                                                }
2653
3297
                                                else {
2654
 
                                                        switch(itemtype) {
 
3298
                                                        switch (itemtype) {
2655
3299
                                                                case PROP_BOOLEAN: {
2656
3300
                                                                        RNA_property_boolean_get_array(&itemptr, iprop, &((int*)in.array)[a]);
2657
3301
                                                                        a += itemlen;
2677
3321
                }
2678
3322
                RNA_PROP_END;
2679
3323
 
2680
 
                if(tmparray)
 
3324
                if (tmparray)
2681
3325
                        MEM_freeN(tmparray);
2682
3326
 
2683
3327
                return !err;
2704
3348
        return prop->rawtype;
2705
3349
}
2706
3350
 
2707
 
int RNA_property_collection_raw_get(ReportList *reports, PointerRNA *ptr, PropertyRNA *prop, char *propname, void *array, RawPropertyType type, int len)
 
3351
int RNA_property_collection_raw_get(ReportList *reports, PointerRNA *ptr, PropertyRNA *prop, const char *propname,
 
3352
                                    void *array, RawPropertyType type, int len)
2708
3353
{
2709
3354
        return rna_raw_access(reports, ptr, prop, propname, array, type, len, 0);
2710
3355
}
2711
3356
 
2712
 
int RNA_property_collection_raw_set(ReportList *reports, PointerRNA *ptr, PropertyRNA *prop, char *propname, void *array, RawPropertyType type, int len)
 
3357
int RNA_property_collection_raw_set(ReportList *reports, PointerRNA *ptr, PropertyRNA *prop, const char *propname,
 
3358
                                    void *array, RawPropertyType type, int len)
2713
3359
{
2714
3360
        return rna_raw_access(reports, ptr, prop, propname, array, type, len, 1);
2715
3361
}
2720
3366
{
2721
3367
        ListBaseIterator *internal;
2722
3368
 
2723
 
        internal= MEM_callocN(sizeof(ListBaseIterator), "ListBaseIterator");
2724
 
        internal->link= (lb)? lb->first: NULL;
2725
 
        internal->skip= skip;
2726
 
 
2727
 
        iter->internal= internal;
2728
 
        iter->valid= (internal->link != NULL);
2729
 
 
2730
 
        if(skip && iter->valid && skip(iter, internal->link))
 
3369
        internal = MEM_callocN(sizeof(ListBaseIterator), "ListBaseIterator");
 
3370
        internal->link = (lb)? lb->first: NULL;
 
3371
        internal->skip = skip;
 
3372
 
 
3373
        iter->internal = internal;
 
3374
        iter->valid = (internal->link != NULL);
 
3375
 
 
3376
        if (skip && iter->valid && skip(iter, internal->link))
2731
3377
                rna_iterator_listbase_next(iter);
2732
3378
}
2733
3379
 
2734
3380
void rna_iterator_listbase_next(CollectionPropertyIterator *iter)
2735
3381
{
2736
 
        ListBaseIterator *internal= iter->internal;
 
3382
        ListBaseIterator *internal = iter->internal;
2737
3383
 
2738
 
        if(internal->skip) {
 
3384
        if (internal->skip) {
2739
3385
                do {
2740
 
                        internal->link= internal->link->next;
2741
 
                        iter->valid= (internal->link != NULL);
2742
 
                } while(iter->valid && internal->skip(iter, internal->link));
 
3386
                        internal->link = internal->link->next;
 
3387
                        iter->valid = (internal->link != NULL);
 
3388
                } while (iter->valid && internal->skip(iter, internal->link));
2743
3389
        }
2744
3390
        else {
2745
 
                internal->link= internal->link->next;
2746
 
                iter->valid= (internal->link != NULL);
 
3391
                internal->link = internal->link->next;
 
3392
                iter->valid = (internal->link != NULL);
2747
3393
        }
2748
3394
}
2749
3395
 
2750
3396
void *rna_iterator_listbase_get(CollectionPropertyIterator *iter)
2751
3397
{
2752
 
        ListBaseIterator *internal= iter->internal;
 
3398
        ListBaseIterator *internal = iter->internal;
2753
3399
 
2754
3400
        return internal->link;
2755
3401
}
2757
3403
void rna_iterator_listbase_end(CollectionPropertyIterator *iter)
2758
3404
{
2759
3405
        MEM_freeN(iter->internal);
2760
 
        iter->internal= NULL;
 
3406
        iter->internal = NULL;
2761
3407
}
2762
3408
 
2763
3409
PointerRNA rna_listbase_lookup_int(PointerRNA *ptr, StructRNA *type, struct ListBase *lb, int index)
2764
3410
{
2765
 
        void *data= BLI_findlink(lb, index);
 
3411
        void *data = BLI_findlink(lb, index);
2766
3412
        return rna_pointer_inherit_refine(ptr, type, data);
2767
3413
}
2768
3414
 
2769
 
void rna_iterator_array_begin(CollectionPropertyIterator *iter, void *ptr, int itemsize, int length, int free_ptr, IteratorSkipFunc skip)
 
3415
void rna_iterator_array_begin(CollectionPropertyIterator *iter, void *ptr, int itemsize, int length,
 
3416
                              int free_ptr, IteratorSkipFunc skip)
2770
3417
{
2771
3418
        ArrayIterator *internal;
2772
3419
 
2773
 
        if(ptr == NULL)
2774
 
                length= 0;
2775
 
 
2776
 
        internal= MEM_callocN(sizeof(ArrayIterator), "ArrayIterator");
2777
 
        internal->ptr= ptr;
2778
 
        internal->free_ptr= free_ptr ? ptr:NULL;
2779
 
        internal->endptr= ((char*)ptr)+length*itemsize;
2780
 
        internal->itemsize= itemsize;
2781
 
        internal->skip= skip;
2782
 
 
2783
 
        iter->internal= internal;
2784
 
        iter->valid= (internal->ptr != internal->endptr);
2785
 
 
2786
 
        if(skip && iter->valid && skip(iter, internal->ptr))
 
3420
        if (ptr == NULL)
 
3421
                length = 0;
 
3422
        else if (length == 0) {
 
3423
                ptr = NULL;
 
3424
                itemsize = 0;
 
3425
        }
 
3426
 
 
3427
        internal = MEM_callocN(sizeof(ArrayIterator), "ArrayIterator");
 
3428
        internal->ptr = ptr;
 
3429
        internal->free_ptr = free_ptr ? ptr:NULL;
 
3430
        internal->endptr = ((char*)ptr)+length*itemsize;
 
3431
        internal->itemsize = itemsize;
 
3432
        internal->skip = skip;
 
3433
        internal->length = length;
 
3434
        
 
3435
        iter->internal = internal;
 
3436
        iter->valid = (internal->ptr != internal->endptr);
 
3437
 
 
3438
        if (skip && iter->valid && skip(iter, internal->ptr))
2787
3439
                rna_iterator_array_next(iter);
2788
3440
}
2789
3441
 
2790
3442
void rna_iterator_array_next(CollectionPropertyIterator *iter)
2791
3443
{
2792
 
        ArrayIterator *internal= iter->internal;
 
3444
        ArrayIterator *internal = iter->internal;
2793
3445
 
2794
 
        if(internal->skip) {
 
3446
        if (internal->skip) {
2795
3447
                do {
2796
3448
                        internal->ptr += internal->itemsize;
2797
 
                        iter->valid= (internal->ptr != internal->endptr);
2798
 
                } while(iter->valid && internal->skip(iter, internal->ptr));
 
3449
                        iter->valid = (internal->ptr != internal->endptr);
 
3450
                } while (iter->valid && internal->skip(iter, internal->ptr));
2799
3451
        }
2800
3452
        else {
2801
3453
                internal->ptr += internal->itemsize;
2802
 
                iter->valid= (internal->ptr != internal->endptr);
 
3454
                iter->valid = (internal->ptr != internal->endptr);
2803
3455
        }
2804
3456
}
2805
3457
 
2806
3458
void *rna_iterator_array_get(CollectionPropertyIterator *iter)
2807
3459
{
2808
 
        ArrayIterator *internal= iter->internal;
 
3460
        ArrayIterator *internal = iter->internal;
2809
3461
 
2810
3462
        return internal->ptr;
2811
3463
}
2812
3464
 
2813
3465
void *rna_iterator_array_dereference_get(CollectionPropertyIterator *iter)
2814
3466
{
2815
 
        ArrayIterator *internal= iter->internal;
 
3467
        ArrayIterator *internal = iter->internal;
2816
3468
 
2817
3469
        /* for ** arrays */
2818
3470
        return *(void**)(internal->ptr);
2820
3472
 
2821
3473
void rna_iterator_array_end(CollectionPropertyIterator *iter)
2822
3474
{
2823
 
        ArrayIterator *internal= iter->internal;
 
3475
        ArrayIterator *internal = iter->internal;
2824
3476
        
2825
 
        if(internal->free_ptr) {
 
3477
        if (internal->free_ptr) {
2826
3478
                MEM_freeN(internal->free_ptr);
2827
 
                internal->free_ptr= NULL;
 
3479
                internal->free_ptr = NULL;
2828
3480
        }
2829
3481
        MEM_freeN(iter->internal);
2830
 
        iter->internal= NULL;
 
3482
        iter->internal = NULL;
2831
3483
}
2832
3484
 
2833
3485
PointerRNA rna_array_lookup_int(PointerRNA *ptr, StructRNA *type, void *data, int itemsize, int length, int index)
2834
3486
{
2835
 
        if(index < 0 || index >= length)
 
3487
        if (index < 0 || index >= length)
2836
3488
                return PointerRNA_NULL;
2837
3489
 
2838
3490
        return rna_pointer_inherit_refine(ptr, type, ((char*)data) + index*itemsize);
2844
3496
{
2845
3497
        const char *p;
2846
3498
        char *buf;
 
3499
        char quote = '\0';
2847
3500
        int i, j, len, escape;
2848
3501
 
2849
 
        len= 0;
 
3502
        len = 0;
2850
3503
 
2851
 
        if(bracket) {
 
3504
        if (bracket) {
2852
3505
                /* get data between [], check escaping ] with \] */
2853
 
                if(**path == '[') (*path)++;
 
3506
                if (**path == '[') (*path)++;
2854
3507
                else return NULL;
2855
3508
 
2856
 
                p= *path;
2857
 
 
2858
 
                escape= 0;
2859
 
                while(*p && (*p != ']' || escape)) {
2860
 
                        escape= (*p == '\\');
2861
 
                        len++;
2862
 
                        p++;
2863
 
                }
2864
 
 
2865
 
                if(*p != ']') return NULL;
 
3509
                p = *path;
 
3510
 
 
3511
                /* 2 kinds of lookups now, quoted or unquoted */
 
3512
                quote = *p;
 
3513
 
 
3514
                if (quote != '"') /* " - this comment is hack for Aligorith's text editor's sanity */
 
3515
                        quote = 0;
 
3516
 
 
3517
                if (quote == 0) {
 
3518
                        while (*p && (*p != ']')) {
 
3519
                                len++;
 
3520
                                p++;
 
3521
                        }
 
3522
                }
 
3523
                else {
 
3524
                        escape = 0;
 
3525
                        /* skip the first quote */
 
3526
                        len++;
 
3527
                        p++;
 
3528
                        while (*p && (*p != quote || escape)) {
 
3529
                                escape = (*p == '\\');
 
3530
                                len++;
 
3531
                                p++;
 
3532
                        }
 
3533
                        
 
3534
                        /* skip the last quoted char to get the ']' */
 
3535
                        len++;
 
3536
                        p++;
 
3537
                }
 
3538
 
 
3539
                if (*p != ']') return NULL;
2866
3540
        }
2867
3541
        else {
2868
3542
                /* get data until . or [ */
2869
 
                p= *path;
 
3543
                p = *path;
2870
3544
 
2871
 
                while(*p && *p != '.' && *p != '[') {
 
3545
                while (*p && *p != '.' && *p != '[') {
2872
3546
                        len++;
2873
3547
                        p++;
2874
3548
                }
2875
3549
        }
2876
3550
        
2877
3551
        /* empty, return */
2878
 
        if(len == 0)
 
3552
        if (len == 0)
2879
3553
                return NULL;
2880
3554
        
2881
3555
        /* try to use fixed buffer if possible */
2882
 
        if(len+1 < fixedlen)
2883
 
                buf= fixedbuf;
 
3556
        if (len+1 < fixedlen)
 
3557
                buf = fixedbuf;
2884
3558
        else
2885
 
                buf= MEM_callocN(sizeof(char)*(len+1), "rna_path_token");
 
3559
                buf = MEM_callocN(sizeof(char)*(len+1), "rna_path_token");
2886
3560
 
2887
3561
        /* copy string, taking into account escaped ] */
2888
 
        if(bracket) {
2889
 
                for(p=*path, i=0, j=0; i<len; i++, p++) {
2890
 
                        if(*p == '\\' && *(p+1) == ']');
2891
 
                        else buf[j++]= *p;
 
3562
        if (bracket) {
 
3563
                for (p = *path, i = 0, j = 0; i<len; i++, p++) {
 
3564
                        if (*p == '\\' && *(p+1) == quote);
 
3565
                        else buf[j++] = *p;
2892
3566
                }
2893
3567
 
2894
 
                buf[j]= 0;
 
3568
                buf[j] = 0;
2895
3569
        }
2896
3570
        else {
2897
3571
                memcpy(buf, *path, sizeof(char)*len);
2898
 
                buf[len]= '\0';
 
3572
                buf[len] = '\0';
2899
3573
        }
2900
3574
 
2901
3575
        /* set path to start of next token */
2902
 
        if(*p == ']') p++;
2903
 
        if(*p == '.') p++;
2904
 
        *path= p;
 
3576
        if (*p == ']') p++;
 
3577
        if (*p == '.') p++;
 
3578
        *path = p;
2905
3579
 
2906
3580
        return buf;
2907
3581
}
2908
3582
 
2909
3583
static int rna_token_strip_quotes(char *token)
2910
3584
{
2911
 
        if(token[0]=='"') {
 
3585
        if (token[0] =='"') {
2912
3586
                int len = strlen(token);
2913
 
                if (len >= 2 && token[len-1]=='"') {
 
3587
                if (len >= 2 && token[len-1] =='"') {
2914
3588
                        /* strip away "" */
2915
 
                        token[len-1]= '\0';
 
3589
                        token[len-1] = '\0';
2916
3590
                        return 1;
2917
3591
                }
2918
3592
        }
2930
3604
        PropertyRNA *prop;
2931
3605
        PointerRNA curptr, nextptr;
2932
3606
        char fixedbuf[256], *token;
2933
 
        int type, len, intkey;
2934
 
 
2935
 
        prop= NULL;
2936
 
        curptr= *ptr;
2937
 
 
2938
 
        if(path==NULL || *path=='\0')
 
3607
        int type, intkey;
 
3608
 
 
3609
        prop = NULL;
 
3610
        curptr = *ptr;
 
3611
 
 
3612
        if (path == NULL || *path =='\0')
2939
3613
                return 0;
2940
3614
 
2941
 
        while(*path) {
2942
 
                int use_id_prop = (*path=='[') ? 1:0;
 
3615
        while (*path) {
 
3616
                int use_id_prop = (*path =='[') ? 1:0;
2943
3617
                /* custom property lookup ?
2944
3618
                 * C.object["someprop"]
2945
3619
                 */
2946
3620
 
2947
3621
                /* look up property name in current struct */
2948
 
                token= rna_path_token(&path, fixedbuf, sizeof(fixedbuf), use_id_prop);
 
3622
                token = rna_path_token(&path, fixedbuf, sizeof(fixedbuf), use_id_prop);
2949
3623
 
2950
 
                if(!token)
 
3624
                if (!token)
2951
3625
                        return 0;
2952
3626
 
2953
 
                if(use_id_prop) { /* look up property name in current struct */
2954
 
                        IDProperty *group= RNA_struct_idproperties(&curptr, 0);
2955
 
                        if(group && rna_token_strip_quotes(token))
2956
 
                                prop= (PropertyRNA *)IDP_GetPropertyFromGroup(group, token+1);
 
3627
                if (use_id_prop) { /* look up property name in current struct */
 
3628
                        IDProperty *group = RNA_struct_idprops(&curptr, 0);
 
3629
                        if (group && rna_token_strip_quotes(token))
 
3630
                                prop = (PropertyRNA *)IDP_GetPropertyFromGroup(group, token+1);
2957
3631
                }
2958
3632
                else {
2959
 
                        prop= RNA_struct_find_property(&curptr, token);
 
3633
                        prop = RNA_struct_find_property(&curptr, token);
2960
3634
                }
2961
3635
 
2962
 
                if(token != fixedbuf)
 
3636
                if (token != fixedbuf)
2963
3637
                        MEM_freeN(token);
2964
3638
 
2965
 
                if(!prop)
 
3639
                if (!prop)
2966
3640
                        return 0;
2967
3641
 
2968
 
                type= RNA_property_type(prop);
 
3642
                type = RNA_property_type(prop);
2969
3643
 
2970
3644
                /* now look up the value of this property if it is a pointer or
2971
3645
                 * collection, otherwise return the property rna so that the
2972
3646
                 * caller can read the value of the property itself */
2973
3647
                switch (type) {
2974
3648
                case PROP_POINTER:
2975
 
                        nextptr= RNA_property_pointer_get(&curptr, prop);
 
3649
                        nextptr = RNA_property_pointer_get(&curptr, prop);
2976
3650
 
2977
 
                        if(nextptr.data)
2978
 
                                curptr= nextptr;
 
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
                        }
2979
3656
                        else
2980
3657
                                return 0;
2981
3658
 
2982
3659
                        break;
2983
3660
                case PROP_COLLECTION:
2984
 
                        if(*path) {
2985
 
                                /* resolve the lookup with [] brackets */
2986
 
                                token= rna_path_token(&path, fixedbuf, sizeof(fixedbuf), 1);
2987
 
 
2988
 
                                if(!token)
2989
 
                                        return 0;
2990
 
 
2991
 
                                len= strlen(token);
2992
 
 
2993
 
                                /* check for "" to see if it is a string */
2994
 
                                if(rna_token_strip_quotes(token)) {
2995
 
                                        RNA_property_collection_lookup_string(&curptr, prop, token+1, &nextptr);
2996
 
                                }
2997
 
                                else {
2998
 
                                        /* otherwise do int lookup */
2999
 
                                        intkey= atoi(token);
3000
 
                                        RNA_property_collection_lookup_int(&curptr, prop, intkey, &nextptr);
3001
 
                                }
3002
 
 
3003
 
                                if(token != fixedbuf)
3004
 
                                        MEM_freeN(token);
3005
 
 
3006
 
                                if(nextptr.data)
3007
 
                                        curptr= nextptr;
3008
 
                                else
3009
 
                                        return 0;
3010
 
                        }
3011
 
 
3012
 
                        break;
3013
 
                default:
3014
 
                        if (index==NULL)
3015
 
                                break;
3016
 
 
3017
 
                        *index= -1;
3018
 
 
3019
3661
                        if (*path) {
3020
 
                                if (*path=='[') {
3021
 
                                        token= rna_path_token(&path, fixedbuf, sizeof(fixedbuf), 1);
3022
 
 
 
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
        
3023
3669
                                        /* check for "" to see if it is a string */
3024
 
                                        if(rna_token_strip_quotes(token)) {
3025
 
                                                *index= RNA_property_array_item_index(prop, *(token+1));
 
3670
                                        if (rna_token_strip_quotes(token)) {
 
3671
                                                RNA_property_collection_lookup_string(&curptr, prop, token+1, &nextptr);
3026
3672
                                        }
3027
3673
                                        else {
3028
3674
                                                /* otherwise do int lookup */
3029
 
                                                *index= atoi(token);
3030
 
                                        }
3031
 
                                }
3032
 
                                else {
3033
 
                                        token= rna_path_token(&path, fixedbuf, sizeof(fixedbuf), 0);
3034
 
                                        *index= RNA_property_array_item_index(prop, *token);
3035
 
                                }
3036
 
 
3037
 
                                if(token != fixedbuf)
3038
 
                                        MEM_freeN(token);
 
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
                                }
 
3696
 
 
3697
                                if (nextptr.data) {
 
3698
                                        curptr = nextptr;
 
3699
                                        prop = NULL;  /* now we have a PointerRNA, the prop is our parent so forget it */
 
3700
                                        if (index) *index = -1;
 
3701
                                }
 
3702
                                else
 
3703
                                        return 0;
 
3704
                        }
 
3705
                        
 
3706
                        break;
 
3707
                default:
 
3708
                        if (index == NULL)
 
3709
                                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 =='[') {
 
3724
                                                token = rna_path_token(&path, fixedbuf, sizeof(fixedbuf), 1);
 
3725
        
 
3726
                                                if (token == NULL) {
 
3727
                                                        /* invalid syntax blah[] */
 
3728
                                                        return 0;
 
3729
                                                }
 
3730
                                                /* check for "" to see if it is a string */
 
3731
                                                else if (rna_token_strip_quotes(token)) {
 
3732
                                                        temp_index = RNA_property_array_item_index(prop, *(token+1));
 
3733
                                                }
 
3734
                                                else {
 
3735
                                                        /* 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
                                        }
 
3756
        
 
3757
                                        if (token != fixedbuf) {
 
3758
                                                MEM_freeN(token);
 
3759
                                        }
 
3760
                                        
 
3761
                                        /* out of range */
 
3762
                                        if (temp_index < 0 || temp_index >= len[i])
 
3763
                                                return 0;
 
3764
 
 
3765
                                        index_arr[i] = temp_index;
 
3766
                                        /* end multi index resolve */
 
3767
                                }
 
3768
 
 
3769
                                /* arrays always contain numbers so further values are not valid */
 
3770
                                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
                                }
3039
3784
                        }
3040
3785
                }
3041
3786
        }
3042
3787
 
3043
 
        *r_ptr= curptr;
3044
 
        *r_prop= prop;
 
3788
        *r_ptr = curptr;
 
3789
        *r_prop = prop;
3045
3790
 
3046
3791
        return 1;
3047
3792
}
3048
3793
 
3049
3794
 
3050
 
char *RNA_path_append(const char *path, PointerRNA *ptr, PropertyRNA *prop, int intkey, const char *strkey)
 
3795
char *RNA_path_append(const char *path, PointerRNA *UNUSED(ptr), PropertyRNA *prop, int intkey, const char *strkey)
3051
3796
{
3052
3797
        DynStr *dynstr;
3053
3798
        const char *s;
3054
3799
        char appendstr[128], *result;
3055
3800
        
3056
 
        dynstr= BLI_dynstr_new();
 
3801
        dynstr = BLI_dynstr_new();
3057
3802
 
3058
3803
        /* add .identifier */
3059
 
        if(path) {
 
3804
        if (path) {
3060
3805
                BLI_dynstr_append(dynstr, (char*)path);
3061
 
                if(*path)
 
3806
                if (*path)
3062
3807
                        BLI_dynstr_append(dynstr, ".");
3063
3808
        }
3064
3809
 
3065
 
        BLI_dynstr_append(dynstr, (char*)RNA_property_identifier(prop));
 
3810
        BLI_dynstr_append(dynstr, RNA_property_identifier(prop));
3066
3811
 
3067
 
        if(RNA_property_type(prop) == PROP_COLLECTION) {
 
3812
        if (RNA_property_type(prop) == PROP_COLLECTION) {
3068
3813
                /* add ["strkey"] or [intkey] */
3069
3814
                BLI_dynstr_append(dynstr, "[");
3070
3815
 
3071
 
                if(strkey) {
 
3816
                if (strkey) {
3072
3817
                        BLI_dynstr_append(dynstr, "\"");
3073
 
                        for(s=strkey; *s; s++) {
3074
 
                                if(*s == '[') {
3075
 
                                        appendstr[0]= '\\';
3076
 
                                        appendstr[1]= *s;
3077
 
                                        appendstr[2]= 0;
 
3818
                        for (s = strkey; *s; s++) {
 
3819
                                if (*s == '[') {
 
3820
                                        appendstr[0] = '\\';
 
3821
                                        appendstr[1] = *s;
 
3822
                                        appendstr[2] = 0;
3078
3823
                                }
3079
3824
                                else {
3080
 
                                        appendstr[0]= *s;
3081
 
                                        appendstr[1]= 0;
 
3825
                                        appendstr[0] = *s;
 
3826
                                        appendstr[1] = 0;
3082
3827
                                }
3083
3828
                                BLI_dynstr_append(dynstr, appendstr);
3084
3829
                        }
3085
3830
                        BLI_dynstr_append(dynstr, "\"");
3086
3831
                }
3087
3832
                else {
3088
 
                        sprintf(appendstr, "%d", intkey);
 
3833
                        BLI_snprintf(appendstr, sizeof(appendstr), "%d", intkey);
3089
3834
                        BLI_dynstr_append(dynstr, appendstr);
3090
3835
                }
3091
3836
 
3092
3837
                BLI_dynstr_append(dynstr, "]");
3093
3838
        }
3094
3839
 
3095
 
        result= BLI_dynstr_get_cstring(dynstr);
 
3840
        result = BLI_dynstr_get_cstring(dynstr);
3096
3841
        BLI_dynstr_free(dynstr);
3097
3842
 
3098
3843
        return result;
3105
3850
        char *result, *token;
3106
3851
        int i;
3107
3852
 
3108
 
        if(!path)
 
3853
        if (!path)
3109
3854
                return NULL;
3110
3855
 
3111
 
        previous= NULL;
3112
 
        current= path;
 
3856
        previous = NULL;
 
3857
        current = path;
3113
3858
 
3114
3859
        /* parse token by token until the end, then we back up to the previous
3115
3860
         * position and strip of the next token to get the path one step back */
3116
 
        while(*current) {
3117
 
                token= rna_path_token(&current, fixedbuf, sizeof(fixedbuf), 0);
 
3861
        while (*current) {
 
3862
                token = rna_path_token(&current, fixedbuf, sizeof(fixedbuf), 0);
3118
3863
 
3119
 
                if(!token)
 
3864
                if (!token)
3120
3865
                        return NULL;
3121
 
                if(token != fixedbuf)
 
3866
                if (token != fixedbuf)
3122
3867
                        MEM_freeN(token);
3123
3868
 
3124
3869
                /* in case of collection we also need to strip off [] */
3125
 
                token= rna_path_token(&current, fixedbuf, sizeof(fixedbuf), 1);
3126
 
                if(token && token != fixedbuf)
 
3870
                token = rna_path_token(&current, fixedbuf, sizeof(fixedbuf), 1);
 
3871
                if (token && token != fixedbuf)
3127
3872
                        MEM_freeN(token);
3128
3873
                
3129
 
                if(!*current)
 
3874
                if (!*current)
3130
3875
                        break;
3131
3876
 
3132
 
                previous= current;
 
3877
                previous = current;
3133
3878
        }
3134
3879
 
3135
 
        if(!previous)
 
3880
        if (!previous)
3136
3881
                return NULL;
3137
3882
 
3138
3883
        /* copy and strip off last token */
3139
 
        i= previous - path;
3140
 
        result= BLI_strdup(path);
 
3884
        i = previous - path;
 
3885
        result = BLI_strdup(path);
3141
3886
 
3142
 
        if(i > 0 && result[i-1] == '.') i--;
3143
 
        result[i]= 0;
 
3887
        if (i > 0 && result[i-1] == '.') i--;
 
3888
        result[i] = 0;
3144
3889
 
3145
3890
        return result;
3146
3891
}
3147
3892
 
 
3893
/* generic path search func
 
3894
 * if its needed this could also reference the IDProperty direct */
 
3895
typedef struct IDP_Chain {
 
3896
        struct IDP_Chain *up; /* parent member, reverse and set to child for path conversion. */
 
3897
 
 
3898
        const char *name;
 
3899
        int index;
 
3900
 
 
3901
} IDP_Chain;
 
3902
 
 
3903
static char *rna_idp_path_create(IDP_Chain *child_link)
 
3904
{
 
3905
        DynStr *dynstr = BLI_dynstr_new();
 
3906
        char *path;
 
3907
        short first = TRUE;
 
3908
 
 
3909
        int tot = 0;
 
3910
        IDP_Chain *link = child_link;
 
3911
 
 
3912
        /* reverse the list */
 
3913
        IDP_Chain *link_prev;
 
3914
        link_prev = NULL;
 
3915
        while (link) {
 
3916
                IDP_Chain *link_next = link->up;
 
3917
                link->up = link_prev;
 
3918
                link_prev = link;
 
3919
                link = link_next;
 
3920
                tot++;
 
3921
        }
 
3922
 
 
3923
        for (link = link_prev; link; link = link->up) {
 
3924
                /* pass */
 
3925
                if (link->index >= 0) {
 
3926
                        BLI_dynstr_appendf(dynstr, first ? "%s[%d]" : ".%s[%d]", link->name, link->index);
 
3927
                }
 
3928
                else {
 
3929
                        BLI_dynstr_appendf(dynstr, first ? "%s" : ".%s", link->name);
 
3930
                }
 
3931
 
 
3932
                first = FALSE;
 
3933
        }
 
3934
 
 
3935
        path = BLI_dynstr_get_cstring(dynstr);
 
3936
        BLI_dynstr_free(dynstr);
 
3937
 
 
3938
        if (*path =='\0') {
 
3939
                MEM_freeN(path);
 
3940
                path = NULL;
 
3941
        }
 
3942
 
 
3943
        return path;
 
3944
}
 
3945
 
 
3946
static char *rna_idp_path(PointerRNA *ptr, IDProperty *haystack, IDProperty *needle, IDP_Chain *parent_link)
 
3947
{
 
3948
        char *path = NULL;
 
3949
        IDP_Chain link;
 
3950
 
 
3951
        IDProperty *iter;
 
3952
        int i;
 
3953
 
 
3954
        BLI_assert(haystack->type == IDP_GROUP);
 
3955
 
 
3956
        link.up = parent_link;
 
3957
        link.name = NULL;
 
3958
        link.index = -1;
 
3959
 
 
3960
        for (i = 0, iter = haystack->data.group.first; iter; iter = iter->next, i++) {
 
3961
                if (needle == iter) {  /* found! */
 
3962
                        link.name = iter->name;
 
3963
                        path = rna_idp_path_create(&link);
 
3964
                        break;
 
3965
                }
 
3966
                else {
 
3967
                        if (iter->type == IDP_GROUP) {
 
3968
                                /* ensure this is RNA */
 
3969
                                PointerRNA child_ptr = RNA_pointer_get(ptr, iter->name);
 
3970
                                if (child_ptr.type) {
 
3971
                                        link.name = iter->name;
 
3972
                                        if ((path = rna_idp_path(&child_ptr, iter, needle, &link))) {
 
3973
                                                break;
 
3974
                                        }
 
3975
                                }
 
3976
                        }
 
3977
                        else if (iter->type == IDP_IDPARRAY) {
 
3978
                                PropertyRNA *prop = RNA_struct_find_property(ptr, iter->name);
 
3979
                                if (prop && prop->type == PROP_COLLECTION) {
 
3980
                                        IDProperty *array = IDP_IDPArray(iter);
 
3981
                                        if (needle >= array && needle < (iter->len + array)) { /* found! */
 
3982
                                                link.name = iter->name;
 
3983
                                                link.index = (int)(needle - array);
 
3984
                                                path = rna_idp_path_create(&link);
 
3985
                                                break;
 
3986
                                        }
 
3987
                                        else {
 
3988
                                                int i;
 
3989
                                                link.name = iter->name;
 
3990
                                                for (i = 0; i < iter->len; i++, array++) {
 
3991
                                                        PointerRNA child_ptr;
 
3992
                                                        if (RNA_property_collection_lookup_int(ptr, prop, i, &child_ptr)) {
 
3993
                                                                link.index = i;
 
3994
                                                                if ((path = rna_idp_path(&child_ptr, array, needle, &link))) {
 
3995
                                                                        break;
 
3996
                                                                }
 
3997
                                                        }
 
3998
                                                }
 
3999
                                                if (path)
 
4000
                                                        break;
 
4001
                                        }
 
4002
                                }
 
4003
                        }
 
4004
                }
 
4005
        }
 
4006
 
 
4007
        return path;
 
4008
}
 
4009
 
 
4010
static char *rna_path_from_ID_to_idpgroup(PointerRNA *ptr)
 
4011
{
 
4012
        PointerRNA id_ptr;
 
4013
        IDProperty *haystack;
 
4014
        IDProperty *needle;
 
4015
 
 
4016
        BLI_assert(ptr->id.data != NULL);
 
4017
 
 
4018
        /* TODO, Support Bones/PoseBones. no pointers stored to the bones from here, only the ID. See example in [#25746]
 
4019
         *       Unless this is added only way to find this is to also search all bones and pose bones
 
4020
         *       of an armature or object */
 
4021
        RNA_id_pointer_create(ptr->id.data, &id_ptr);
 
4022
 
 
4023
        haystack = RNA_struct_idprops(&id_ptr, FALSE);
 
4024
        if (haystack) { /* can fail when called on bones */
 
4025
                needle = ptr->data;
 
4026
                return rna_idp_path(&id_ptr, haystack, needle, NULL);
 
4027
        }
 
4028
        else {
 
4029
                return NULL;
 
4030
        }
 
4031
}
 
4032
 
3148
4033
char *RNA_path_from_ID_to_struct(PointerRNA *ptr)
3149
4034
{
3150
 
        char *ptrpath=NULL;
 
4035
        char *ptrpath = NULL;
3151
4036
 
3152
 
        if(!ptr->id.data || !ptr->data)
 
4037
        if (!ptr->id.data || !ptr->data)
3153
4038
                return NULL;
3154
4039
        
3155
 
        if(!RNA_struct_is_ID(ptr->type)) {
3156
 
                if(ptr->type->path) {
 
4040
        if (!RNA_struct_is_ID(ptr->type)) {
 
4041
                if (ptr->type->path) {
3157
4042
                        /* if type has a path to some ID, use it */
3158
 
                        ptrpath= ptr->type->path(ptr);
 
4043
                        ptrpath = ptr->type->path(ptr);
3159
4044
                }
3160
 
                else if(ptr->type->nested && RNA_struct_is_ID(ptr->type->nested)) {
 
4045
                else if (ptr->type->nested && RNA_struct_is_ID(ptr->type->nested)) {
3161
4046
                        PointerRNA parentptr;
3162
4047
                        PropertyRNA *userprop;
3163
4048
                        
3164
 
                        /* find the property in the struct we're nested in that references this struct, and 
 
4049
                        /* find the property in the struct we're nested in that references this struct, and
3165
4050
                         * use its identifier as the first part of the path used...
3166
4051
                         */
3167
4052
                        RNA_id_pointer_create(ptr->id.data, &parentptr);
3168
 
                        userprop= RNA_struct_find_nested(&parentptr, ptr->type); 
 
4053
                        userprop = RNA_struct_find_nested(&parentptr, ptr->type);
3169
4054
                        
3170
 
                        if(userprop)
3171
 
                                ptrpath= BLI_strdup(RNA_property_identifier(userprop));
 
4055
                        if (userprop)
 
4056
                                ptrpath = BLI_strdup(RNA_property_identifier(userprop));
3172
4057
                        else
3173
 
                                return NULL; // can't do anything about this case yet...
 
4058
                                return NULL; /* can't do anything about this case yet... */
 
4059
                }
 
4060
                else if (RNA_struct_is_a(ptr->type, &RNA_PropertyGroup)) {
 
4061
                        /* special case, easier to deal with here then in ptr->type->path() */
 
4062
                        return rna_path_from_ID_to_idpgroup(ptr);
3174
4063
                }
3175
4064
                else
3176
4065
                        return NULL;
3185
4074
        const char *propname;
3186
4075
        char *ptrpath, *path;
3187
4076
 
3188
 
        if(!ptr->id.data || !ptr->data || !prop)
 
4077
        if (!ptr->id.data || !ptr->data || !prop)
3189
4078
                return NULL;
3190
4079
        
3191
4080
        /* path from ID to the struct holding this property */
3192
 
        ptrpath= RNA_path_from_ID_to_struct(ptr);
3193
 
 
3194
 
        propname= RNA_property_identifier(prop);
3195
 
 
3196
 
        if(ptrpath) {
3197
 
                path= BLI_sprintfN(is_rna ? "%s.%s":"%s[\"%s\"]", ptrpath, propname);
 
4081
        ptrpath = RNA_path_from_ID_to_struct(ptr);
 
4082
 
 
4083
        propname = RNA_property_identifier(prop);
 
4084
 
 
4085
        if (ptrpath) {
 
4086
                path = BLI_sprintfN(is_rna ? "%s.%s":"%s[\"%s\"]", ptrpath, propname);
3198
4087
                MEM_freeN(ptrpath);
3199
4088
        }
3200
4089
        else {
3201
 
                if(is_rna)
3202
 
                        path= BLI_strdup(propname);
 
4090
                if (is_rna)
 
4091
                        path = BLI_strdup(propname);
3203
4092
                else
3204
 
                        path= BLI_sprintfN("[\"%s\"]", propname);
 
4093
                        path = BLI_sprintfN("[\"%s\"]", propname);
3205
4094
        }
3206
4095
 
3207
4096
        return path;
3211
4100
 
3212
4101
int RNA_boolean_get(PointerRNA *ptr, const char *name)
3213
4102
{
3214
 
        PropertyRNA *prop= RNA_struct_find_property(ptr, name);
 
4103
        PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3215
4104
 
3216
 
        if(prop) {
 
4105
        if (prop) {
3217
4106
                return RNA_property_boolean_get(ptr, prop);
3218
4107
        }
3219
4108
        else {
3220
 
                printf("RNA_boolean_get: %s.%s not found.\n", ptr->type->identifier, name);
 
4109
                printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3221
4110
                return 0;
3222
4111
        }
3223
4112
}
3224
4113
 
3225
4114
void RNA_boolean_set(PointerRNA *ptr, const char *name, int value)
3226
4115
{
3227
 
        PropertyRNA *prop= RNA_struct_find_property(ptr, name);
 
4116
        PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3228
4117
 
3229
 
        if(prop)
 
4118
        if (prop)
3230
4119
                RNA_property_boolean_set(ptr, prop, value);
3231
4120
        else
3232
 
                printf("RNA_boolean_set: %s.%s not found.\n", ptr->type->identifier, name);
 
4121
                printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3233
4122
}
3234
4123
 
3235
4124
void RNA_boolean_get_array(PointerRNA *ptr, const char *name, int *values)
3236
4125
{
3237
 
        PropertyRNA *prop= RNA_struct_find_property(ptr, name);
 
4126
        PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3238
4127
 
3239
 
        if(prop)
 
4128
        if (prop)
3240
4129
                RNA_property_boolean_get_array(ptr, prop, values);
3241
4130
        else
3242
 
                printf("RNA_boolean_get_array: %s.%s not found.\n", ptr->type->identifier, name);
 
4131
                printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3243
4132
}
3244
4133
 
3245
4134
void RNA_boolean_set_array(PointerRNA *ptr, const char *name, const int *values)
3246
4135
{
3247
 
        PropertyRNA *prop= RNA_struct_find_property(ptr, name);
 
4136
        PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3248
4137
 
3249
 
        if(prop)
 
4138
        if (prop)
3250
4139
                RNA_property_boolean_set_array(ptr, prop, values);
3251
4140
        else
3252
 
                printf("RNA_boolean_set_array: %s.%s not found.\n", ptr->type->identifier, name);
 
4141
                printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3253
4142
}
3254
4143
 
3255
4144
int RNA_int_get(PointerRNA *ptr, const char *name)
3256
4145
{
3257
 
        PropertyRNA *prop= RNA_struct_find_property(ptr, name);
 
4146
        PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3258
4147
 
3259
 
        if(prop) {
 
4148
        if (prop) {
3260
4149
                return RNA_property_int_get(ptr, prop);
3261
4150
        }
3262
4151
        else {
3263
 
                printf("RNA_int_get: %s.%s not found.\n", ptr->type->identifier, name);
 
4152
                printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3264
4153
                return 0;
3265
4154
        }
3266
4155
}
3267
4156
 
3268
4157
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
3269
4158
{
3270
 
        PropertyRNA *prop= RNA_struct_find_property(ptr, name);
 
4159
        PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3271
4160
 
3272
 
        if(prop)
 
4161
        if (prop)
3273
4162
                RNA_property_int_set(ptr, prop, value);
3274
4163
        else
3275
 
                printf("RNA_int_set: %s.%s not found.\n", ptr->type->identifier, name);
 
4164
                printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3276
4165
}
3277
4166
 
3278
4167
void RNA_int_get_array(PointerRNA *ptr, const char *name, int *values)
3279
4168
{
3280
 
        PropertyRNA *prop= RNA_struct_find_property(ptr, name);
 
4169
        PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3281
4170
 
3282
 
        if(prop)
 
4171
        if (prop)
3283
4172
                RNA_property_int_get_array(ptr, prop, values);
3284
4173
        else
3285
 
                printf("RNA_int_get_array: %s.%s not found.\n", ptr->type->identifier, name);
 
4174
                printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3286
4175
}
3287
4176
 
3288
4177
void RNA_int_set_array(PointerRNA *ptr, const char *name, const int *values)
3289
4178
{
3290
 
        PropertyRNA *prop= RNA_struct_find_property(ptr, name);
 
4179
        PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3291
4180
 
3292
 
        if(prop)
 
4181
        if (prop)
3293
4182
                RNA_property_int_set_array(ptr, prop, values);
3294
4183
        else
3295
 
                printf("RNA_int_set_array: %s.%s not found.\n", ptr->type->identifier, name);
 
4184
                printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3296
4185
}
3297
4186
 
3298
4187
float RNA_float_get(PointerRNA *ptr, const char *name)
3299
4188
{
3300
 
        PropertyRNA *prop= RNA_struct_find_property(ptr, name);
 
4189
        PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3301
4190
 
3302
 
        if(prop) {
 
4191
        if (prop) {
3303
4192
                return RNA_property_float_get(ptr, prop);
3304
4193
        }
3305
4194
        else {
3306
 
                printf("RNA_float_get: %s.%s not found.\n", ptr->type->identifier, name);
 
4195
                printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3307
4196
                return 0;
3308
4197
        }
3309
4198
}
3310
4199
 
3311
4200
void RNA_float_set(PointerRNA *ptr, const char *name, float value)
3312
4201
{
3313
 
        PropertyRNA *prop= RNA_struct_find_property(ptr, name);
 
4202
        PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3314
4203
 
3315
 
        if(prop)
 
4204
        if (prop)
3316
4205
                RNA_property_float_set(ptr, prop, value);
3317
4206
        else
3318
 
                printf("RNA_float_set: %s.%s not found.\n", ptr->type->identifier, name);
 
4207
                printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3319
4208
}
3320
4209
 
3321
4210
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
3322
4211
{
3323
 
        PropertyRNA *prop= RNA_struct_find_property(ptr, name);
 
4212
        PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3324
4213
 
3325
 
        if(prop)
 
4214
        if (prop)
3326
4215
                RNA_property_float_get_array(ptr, prop, values);
3327
4216
        else
3328
 
                printf("RNA_float_get_array: %s.%s not found.\n", ptr->type->identifier, name);
 
4217
                printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3329
4218
}
3330
4219
 
3331
4220
void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
3332
4221
{
3333
 
        PropertyRNA *prop= RNA_struct_find_property(ptr, name);
 
4222
        PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3334
4223
 
3335
 
        if(prop)
 
4224
        if (prop)
3336
4225
                RNA_property_float_set_array(ptr, prop, values);
3337
4226
        else
3338
 
                printf("RNA_float_set_array: %s.%s not found.\n", ptr->type->identifier, name);
 
4227
                printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3339
4228
}
3340
4229
 
3341
4230
int RNA_enum_get(PointerRNA *ptr, const char *name)
3342
4231
{
3343
 
        PropertyRNA *prop= RNA_struct_find_property(ptr, name);
 
4232
        PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3344
4233
 
3345
 
        if(prop) {
 
4234
        if (prop) {
3346
4235
                return RNA_property_enum_get(ptr, prop);
3347
4236
        }
3348
4237
        else {
3349
 
                printf("RNA_enum_get: %s.%s not found.\n", ptr->type->identifier, name);
 
4238
                printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3350
4239
                return 0;
3351
4240
        }
3352
4241
}
3353
4242
 
3354
4243
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
3355
4244
{
3356
 
        PropertyRNA *prop= RNA_struct_find_property(ptr, name);
 
4245
        PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3357
4246
 
3358
 
        if(prop)
 
4247
        if (prop)
3359
4248
                RNA_property_enum_set(ptr, prop, value);
3360
4249
        else
3361
 
                printf("RNA_enum_set: %s.%s not found.\n", ptr->type->identifier, name);
 
4250
                printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3362
4251
}
3363
4252
 
3364
4253
void RNA_enum_set_identifier(PointerRNA *ptr, const char *name, const char *id)
3365
4254
{
3366
 
        PropertyRNA *prop= RNA_struct_find_property(ptr, name);
 
4255
        PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3367
4256
 
3368
 
        if(prop) {
 
4257
        if (prop) {
3369
4258
                int value;
3370
 
                if(RNA_property_enum_value(NULL, ptr, prop, id, &value))
 
4259
                if (RNA_property_enum_value(NULL, ptr, prop, id, &value))
3371
4260
                        RNA_property_enum_set(ptr, prop, value);
3372
4261
                else
3373
 
                        printf("RNA_enum_set_identifier: %s.%s has no enum id '%s'.\n", ptr->type->identifier, name, id);
3374
 
        } else
3375
 
                printf("RNA_enum_set_identifier: %s.%s not found.\n", ptr->type->identifier, name);
 
4262
                        printf("%s: %s.%s has no enum id '%s'.\n", __func__, ptr->type->identifier, name, id);
 
4263
        }
 
4264
        else {
 
4265
                printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
 
4266
        }
3376
4267
}
3377
4268
 
3378
4269
int RNA_enum_is_equal(bContext *C, PointerRNA *ptr, const char *name, const char *enumname)
3379
4270
{
3380
 
        PropertyRNA *prop= RNA_struct_find_property(ptr, name);
 
4271
        PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3381
4272
        EnumPropertyItem *item;
3382
4273
        int free;
3383
4274
 
3384
 
        if(prop) {
 
4275
        if (prop) {
3385
4276
                RNA_property_enum_items(C, ptr, prop, &item, NULL, &free);
3386
4277
 
3387
 
                for(; item->identifier; item++)
3388
 
                        if(strcmp(item->identifier, enumname) == 0)
 
4278
                for (; item->identifier; item++)
 
4279
                        if (strcmp(item->identifier, enumname) == 0)
3389
4280
                                return (item->value == RNA_property_enum_get(ptr, prop));
3390
4281
 
3391
 
                if(free)
 
4282
                if (free)
3392
4283
                        MEM_freeN(item);
3393
4284
 
3394
 
                printf("RNA_enum_is_equal: %s.%s item %s not found.\n", ptr->type->identifier, name, enumname);
 
4285
                printf("%s: %s.%s item %s not found.\n", __func__, ptr->type->identifier, name, enumname);
3395
4286
                return 0;
3396
4287
        }
3397
4288
        else {
3398
 
                printf("RNA_enum_is_equal: %s.%s not found.\n", ptr->type->identifier, name);
 
4289
                printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3399
4290
                return 0;
3400
4291
        }
3401
4292
}
3402
4293
 
3403
4294
int RNA_enum_value_from_id(EnumPropertyItem *item, const char *identifier, int *value)
3404
4295
{
3405
 
        for( ; item->identifier; item++) {
3406
 
                if(strcmp(item->identifier, identifier)==0) {
3407
 
                        *value= item->value;
 
4296
        for ( ; item->identifier; item++) {
 
4297
                if (strcmp(item->identifier, identifier) == 0) {
 
4298
                        *value = item->value;
3408
4299
                        return 1;
3409
4300
                }
3410
4301
        }
3414
4305
 
3415
4306
int     RNA_enum_id_from_value(EnumPropertyItem *item, int value, const char **identifier)
3416
4307
{
3417
 
        for( ; item->identifier; item++) {
3418
 
                if(item->value==value) {
3419
 
                        *identifier= item->identifier;
3420
 
                        return 1;
3421
 
                }
3422
 
        }
3423
 
 
 
4308
        for ( ; item->identifier; item++) {
 
4309
                if (item->value == value) {
 
4310
                        *identifier = item->identifier;
 
4311
                        return 1;
 
4312
                }
 
4313
        }
 
4314
 
 
4315
        return 0;
 
4316
}
 
4317
 
 
4318
int RNA_enum_icon_from_value(EnumPropertyItem *item, int value, int *icon)
 
4319
{
 
4320
        for ( ; item->identifier; item++) {
 
4321
                if (item->value == value) {
 
4322
                        *icon = item->icon;
 
4323
                        return 1;
 
4324
                }
 
4325
        }
 
4326
        
3424
4327
        return 0;
3425
4328
}
3426
4329
 
3427
4330
void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
3428
4331
{
3429
 
        PropertyRNA *prop= RNA_struct_find_property(ptr, name);
 
4332
        PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3430
4333
 
3431
 
        if(prop)
 
4334
        if (prop) {
3432
4335
                RNA_property_string_get(ptr, prop, value);
3433
 
        else
3434
 
                printf("RNA_string_get: %s.%s not found.\n", ptr->type->identifier, name);
 
4336
        }
 
4337
        else {
 
4338
                printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
 
4339
                value[0] = '\0';
 
4340
        }
3435
4341
}
3436
4342
 
3437
4343
char *RNA_string_get_alloc(PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen)
3438
4344
{
3439
 
        PropertyRNA *prop= RNA_struct_find_property(ptr, name);
 
4345
        PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3440
4346
 
3441
 
        if(prop) {
3442
 
                return RNA_property_string_get_alloc(ptr, prop, fixedbuf, fixedlen);
 
4347
        if (prop) {
 
4348
                return RNA_property_string_get_alloc(ptr, prop, fixedbuf, fixedlen, NULL); /* TODO, pass length */
3443
4349
        }
3444
4350
        else {
3445
 
                printf("RNA_string_get_alloc: %s.%s not found.\n", ptr->type->identifier, name);
3446
 
                return 0;
 
4351
                printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
 
4352
                return NULL;
3447
4353
        }
3448
4354
}
3449
4355
 
3450
4356
int RNA_string_length(PointerRNA *ptr, const char *name)
3451
4357
{
3452
 
        PropertyRNA *prop= RNA_struct_find_property(ptr, name);
 
4358
        PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3453
4359
 
3454
 
        if(prop) {
 
4360
        if (prop) {
3455
4361
                return RNA_property_string_length(ptr, prop);
3456
4362
        }
3457
4363
        else {
3458
 
                printf("RNA_string_length: %s.%s not found.\n", ptr->type->identifier, name);
 
4364
                printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3459
4365
                return 0;
3460
4366
        }
3461
4367
}
3462
4368
 
3463
4369
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
3464
4370
{
3465
 
        PropertyRNA *prop= RNA_struct_find_property(ptr, name);
 
4371
        PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3466
4372
 
3467
 
        if(prop)
 
4373
        if (prop)
3468
4374
                RNA_property_string_set(ptr, prop, value);
3469
4375
        else
3470
 
                printf("RNA_string_set: %s.%s not found.\n", ptr->type->identifier, name);
 
4376
                printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3471
4377
}
3472
4378
 
3473
4379
PointerRNA RNA_pointer_get(PointerRNA *ptr, const char *name)
3474
4380
{
3475
 
        PropertyRNA *prop= RNA_struct_find_property(ptr, name);
 
4381
        PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3476
4382
 
3477
 
        if(prop) {
 
4383
        if (prop) {
3478
4384
                return RNA_property_pointer_get(ptr, prop);
3479
4385
        }
3480
4386
        else {
3481
 
                PointerRNA result;
3482
 
 
3483
 
                printf("RNA_pointer_get: %s.%s not found.\n", ptr->type->identifier, name);
3484
 
 
3485
 
                memset(&result, 0, sizeof(result));
3486
 
                return result;
 
4387
                printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
 
4388
 
 
4389
                return PointerRNA_NULL;
3487
4390
        }
3488
4391
}
3489
4392
 
3490
4393
void RNA_pointer_set(PointerRNA *ptr, const char *name, PointerRNA ptr_value)
3491
4394
{
3492
 
        PropertyRNA *prop= RNA_struct_find_property(ptr, name);
 
4395
        PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3493
4396
 
3494
 
        if(prop) {
 
4397
        if (prop) {
3495
4398
                RNA_property_pointer_set(ptr, prop, ptr_value);
3496
4399
        }
3497
4400
        else {
3498
 
                printf("RNA_pointer_set: %s.%s not found.\n", ptr->type->identifier, name);
 
4401
                printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3499
4402
        }
3500
4403
}
3501
4404
 
3502
4405
void RNA_pointer_add(PointerRNA *ptr, const char *name)
3503
4406
{
3504
 
        PropertyRNA *prop= RNA_struct_find_property(ptr, name);
 
4407
        PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3505
4408
 
3506
 
        if(prop)
 
4409
        if (prop)
3507
4410
                RNA_property_pointer_add(ptr, prop);
3508
4411
        else
3509
 
                printf("RNA_pointer_set: %s.%s not found.\n", ptr->type->identifier, name);
 
4412
                printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3510
4413
}
3511
4414
 
3512
4415
void RNA_collection_begin(PointerRNA *ptr, const char *name, CollectionPropertyIterator *iter)
3513
4416
{
3514
 
        PropertyRNA *prop= RNA_struct_find_property(ptr, name);
 
4417
        PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3515
4418
 
3516
 
        if(prop)
 
4419
        if (prop)
3517
4420
                RNA_property_collection_begin(ptr, prop, iter);
3518
4421
        else
3519
 
                printf("RNA_collection_begin: %s.%s not found.\n", ptr->type->identifier, name);
 
4422
                printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3520
4423
}
3521
4424
 
3522
4425
void RNA_collection_add(PointerRNA *ptr, const char *name, PointerRNA *r_value)
3523
4426
{
3524
 
        PropertyRNA *prop= RNA_struct_find_property(ptr, name);
 
4427
        PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3525
4428
 
3526
 
        if(prop)
 
4429
        if (prop)
3527
4430
                RNA_property_collection_add(ptr, prop, r_value);
3528
4431
        else
3529
 
                printf("RNA_collection_add: %s.%s not found.\n", ptr->type->identifier, name);
 
4432
                printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3530
4433
}
3531
4434
 
3532
4435
void RNA_collection_clear(PointerRNA *ptr, const char *name)
3533
4436
{
3534
 
        PropertyRNA *prop= RNA_struct_find_property(ptr, name);
 
4437
        PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3535
4438
 
3536
 
        if(prop)
 
4439
        if (prop)
3537
4440
                RNA_property_collection_clear(ptr, prop);
3538
4441
        else
3539
 
                printf("RNA_collection_clear: %s.%s not found.\n", ptr->type->identifier, name);
 
4442
                printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3540
4443
}
3541
4444
 
3542
4445
int RNA_collection_length(PointerRNA *ptr, const char *name)
3543
4446
{
3544
 
        PropertyRNA *prop= RNA_struct_find_property(ptr, name);
 
4447
        PropertyRNA *prop = RNA_struct_find_property(ptr, name);
3545
4448
 
3546
 
        if(prop) {
 
4449
        if (prop) {
3547
4450
                return RNA_property_collection_length(ptr, prop);
3548
4451
        }
3549
4452
        else {
3550
 
                printf("RNA_collection_length: %s.%s not found.\n", ptr->type->identifier, name);
 
4453
                printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
3551
4454
                return 0;
3552
4455
        }
3553
4456
}
3554
4457
 
3555
 
int RNA_property_is_set(PointerRNA *ptr, const char *name)
3556
 
{
3557
 
        PropertyRNA *prop= RNA_struct_find_property(ptr, name);
3558
 
 
3559
 
        if(prop) {
3560
 
                if(prop->flag & PROP_IDPROPERTY)
3561
 
                        return (rna_idproperty_find(ptr, name) != NULL);
3562
 
                else
3563
 
                        return 1;
3564
 
        }
3565
 
        else {
3566
 
                // printf("RNA_property_is_set: %s.%s not found.\n", ptr->type->identifier, name);
 
4458
int RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
 
4459
{
 
4460
        if (prop->flag & PROP_IDPROPERTY) {
 
4461
                IDProperty *idprop = rna_idproperty_find(ptr, prop->identifier);
 
4462
                return ((idprop != NULL) && !(idprop->flag & IDP_FLAG_GHOST));
 
4463
        }
 
4464
        else {
 
4465
                return 1;
 
4466
        }
 
4467
}
 
4468
 
 
4469
int RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
 
4470
{
 
4471
        PropertyRNA *prop = RNA_struct_find_property(ptr, identifier);
 
4472
 
 
4473
        if (prop) {
 
4474
                return RNA_property_is_set(ptr, prop);
 
4475
        }
 
4476
        else {
 
4477
                /* python raises an error */
 
4478
                /* printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name); */
3567
4479
                return 0;
3568
4480
        }
3569
4481
}
3570
4482
 
3571
4483
int RNA_property_is_idprop(PropertyRNA *prop)
3572
4484
{
3573
 
        return (prop->magic!=RNA_MAGIC);
 
4485
        return (prop->magic != RNA_MAGIC);
3574
4486
}
3575
4487
 
3576
4488
/* string representation of a property, python
3577
 
 * compatible but can be used for display too*/
3578
 
char *RNA_pointer_as_string(PointerRNA *ptr)
 
4489
 * compatible but can be used for display too,
 
4490
 * context may be NULL */
 
4491
char *RNA_pointer_as_string(bContext *C, PointerRNA *ptr)
3579
4492
{
3580
 
        DynStr *dynstr= BLI_dynstr_new();
 
4493
        DynStr *dynstr = BLI_dynstr_new();
3581
4494
        char *cstring;
3582
4495
        
3583
4496
        const char *propname;
3588
4501
        RNA_STRUCT_BEGIN(ptr, prop) {
3589
4502
                propname = RNA_property_identifier(prop);
3590
4503
                
3591
 
                if(strcmp(propname, "rna_type")==0)
 
4504
                if (strcmp(propname, "rna_type") == 0)
3592
4505
                        continue;
3593
4506
                
3594
 
                if(first_time==0)
 
4507
                if (first_time == 0)
3595
4508
                        BLI_dynstr_append(dynstr, ", ");
3596
 
                first_time= 0;
 
4509
                first_time = 0;
3597
4510
                
3598
 
                cstring = RNA_property_as_string(NULL, ptr, prop);
 
4511
                cstring = RNA_property_as_string(C, ptr, prop);
3599
4512
                BLI_dynstr_appendf(dynstr, "\"%s\":%s", propname, cstring);
3600
4513
                MEM_freeN(cstring);
3601
4514
        }
3602
4515
        RNA_STRUCT_END;
3603
4516
 
3604
 
        BLI_dynstr_append(dynstr, "}"); 
3605
 
        
3606
 
        
3607
 
        cstring = BLI_dynstr_get_cstring(dynstr);
3608
 
        BLI_dynstr_free(dynstr);
3609
 
        return cstring;
 
4517
        BLI_dynstr_append(dynstr, "}");
 
4518
        
 
4519
        
 
4520
        cstring = BLI_dynstr_get_cstring(dynstr);
 
4521
        BLI_dynstr_free(dynstr);
 
4522
        return cstring;
 
4523
}
 
4524
 
 
4525
 
 
4526
/* context and ptr_default can be NULL */
 
4527
char *RNA_pointer_as_string_keywords_ex(bContext *C, PointerRNA *ptr, PointerRNA *ptr_default,
 
4528
                                        const short as_function, const short all_args,
 
4529
                                        PropertyRNA *iterprop)
 
4530
{
 
4531
        const char *arg_name = NULL;
 
4532
 
 
4533
        PropertyRNA *prop;
 
4534
 
 
4535
        DynStr *dynstr = BLI_dynstr_new();
 
4536
        char *cstring, *buf;
 
4537
        int first_iter = TRUE, ok = TRUE;
 
4538
        int flag;
 
4539
 
 
4540
        /* only to get the orginal props for comparisons */
 
4541
        PropertyRNA *prop_default;
 
4542
        char *buf_default;
 
4543
 
 
4544
        RNA_PROP_BEGIN(ptr, propptr, iterprop) {
 
4545
                prop = propptr.data;
 
4546
 
 
4547
                flag = RNA_property_flag(prop);
 
4548
 
 
4549
                if (as_function && (flag & PROP_OUTPUT)) {
 
4550
                        continue;
 
4551
                }
 
4552
 
 
4553
                arg_name = RNA_property_identifier(prop);
 
4554
 
 
4555
                if (strcmp(arg_name, "rna_type") == 0) {
 
4556
                        continue;
 
4557
                }
 
4558
 
 
4559
                if (as_function && (flag & PROP_REQUIRED)) {
 
4560
                        /* required args don't have useful defaults */
 
4561
                        BLI_dynstr_appendf(dynstr, first_iter ? "%s":", %s", arg_name);
 
4562
                        first_iter = FALSE;
 
4563
                }
 
4564
                else {
 
4565
                        if (as_function && RNA_property_type(prop) == PROP_POINTER) {
 
4566
                                /* don't expand pointers for functions */
 
4567
                                if (flag & PROP_NEVER_NULL) {
 
4568
                                        /* we cant really do the right thing here. arg=arg?, hrmf! */
 
4569
                                        buf = BLI_strdup(arg_name);
 
4570
                                }
 
4571
                                else {
 
4572
                                        buf = BLI_strdup("None");
 
4573
                                }
 
4574
                        }
 
4575
                        else {
 
4576
                                buf = RNA_property_as_string(C, ptr, prop);
 
4577
                        }
 
4578
 
 
4579
                        ok = TRUE;
 
4580
 
 
4581
                        if (all_args == FALSE && ptr_default) {
 
4582
                                /* not verbose, so only add in attributes that use non-default values
 
4583
                                 * slow but good for tooltips */
 
4584
                                prop_default = RNA_struct_find_property(ptr_default, arg_name);
 
4585
 
 
4586
                                if (prop_default) {
 
4587
                                        buf_default = RNA_property_as_string(C, ptr_default, prop_default);
 
4588
 
 
4589
                                        if (strcmp(buf, buf_default) == 0)
 
4590
                                                ok = FALSE; /* values match, don't bother printing */
 
4591
 
 
4592
                                        MEM_freeN(buf_default);
 
4593
                                }
 
4594
                        }
 
4595
                        if (ok) {
 
4596
                                BLI_dynstr_appendf(dynstr, first_iter ? "%s=%s":", %s=%s", arg_name, buf);
 
4597
                                first_iter = FALSE;
 
4598
                        }
 
4599
 
 
4600
                        MEM_freeN(buf);
 
4601
                }
 
4602
        }
 
4603
        RNA_PROP_END;
 
4604
 
 
4605
        cstring = BLI_dynstr_get_cstring(dynstr);
 
4606
        BLI_dynstr_free(dynstr);
 
4607
        return cstring;
 
4608
}
 
4609
 
 
4610
char *RNA_pointer_as_string_keywords(bContext *C, PointerRNA *ptr, PointerRNA *ptr_default,
 
4611
                                     const short as_function, const short all_args)
 
4612
{
 
4613
        PropertyRNA *iterprop;
 
4614
 
 
4615
        iterprop = RNA_struct_iterator_property(ptr->type);
 
4616
 
 
4617
        return RNA_pointer_as_string_keywords_ex(C, ptr, ptr_default, as_function, all_args,
 
4618
                                                 iterprop);
 
4619
}
 
4620
 
 
4621
char *RNA_function_as_string_keywords(bContext *C, FunctionRNA *func, PointerRNA *ptr_default,
 
4622
                                     const short as_function, const short all_args)
 
4623
{
 
4624
        PointerRNA funcptr;
 
4625
        PropertyRNA *iterprop;
 
4626
 
 
4627
        RNA_pointer_create(NULL, &RNA_Function, func, &funcptr);
 
4628
 
 
4629
        iterprop = RNA_struct_find_property(&funcptr, "parameters");
 
4630
 
 
4631
        RNA_struct_iterator_property(funcptr.type);
 
4632
 
 
4633
        return RNA_pointer_as_string_keywords_ex(C, &funcptr, ptr_default, as_function, all_args,
 
4634
                                                 iterprop);
3610
4635
}
3611
4636
 
3612
4637
char *RNA_property_as_string(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
3615
4640
        int len = RNA_property_array_length(ptr, prop);
3616
4641
        int i;
3617
4642
 
3618
 
        DynStr *dynstr= BLI_dynstr_new();
 
4643
        DynStr *dynstr = BLI_dynstr_new();
3619
4644
        char *cstring;
3620
4645
        
3621
4646
 
3622
4647
        /* see if we can coorce into a python type - PropertyType */
3623
4648
        switch (type) {
3624
4649
        case PROP_BOOLEAN:
3625
 
                if(len==0) {
 
4650
                if (len == 0) {
3626
4651
                        BLI_dynstr_append(dynstr, RNA_property_boolean_get(ptr, prop) ? "True" : "False");
3627
4652
                }
3628
4653
                else {
3629
4654
                        BLI_dynstr_append(dynstr, "(");
3630
 
                        for(i=0; i<len; i++) {
3631
 
                                BLI_dynstr_appendf(dynstr, i?", %s":"%s", RNA_property_boolean_get_index(ptr, prop, i) ? "True" : "False");
 
4655
                        for (i = 0; i<len; i++) {
 
4656
                                BLI_dynstr_appendf(dynstr, i ? ", %s" : "%s",
 
4657
                                                   RNA_property_boolean_get_index(ptr, prop, i) ? "True" : "False");
3632
4658
                        }
3633
 
                        if(len==1)
 
4659
                        if (len == 1)
3634
4660
                                BLI_dynstr_append(dynstr, ","); /* otherwise python wont see it as a tuple */
3635
4661
                        BLI_dynstr_append(dynstr, ")");
3636
4662
                }
3637
4663
                break;
3638
4664
        case PROP_INT:
3639
 
                if(len==0) {
 
4665
                if (len == 0) {
3640
4666
                        BLI_dynstr_appendf(dynstr, "%d", RNA_property_int_get(ptr, prop));
3641
4667
                }
3642
4668
                else {
3643
4669
                        BLI_dynstr_append(dynstr, "(");
3644
 
                        for(i=0; i<len; i++) {
 
4670
                        for (i = 0; i<len; i++) {
3645
4671
                                BLI_dynstr_appendf(dynstr, i?", %d":"%d", RNA_property_int_get_index(ptr, prop, i));
3646
4672
                        }
3647
 
                        if(len==1)
 
4673
                        if (len == 1)
3648
4674
                                BLI_dynstr_append(dynstr, ","); /* otherwise python wont see it as a tuple */
3649
4675
                        BLI_dynstr_append(dynstr, ")");
3650
4676
                }
3651
4677
                break;
3652
4678
        case PROP_FLOAT:
3653
 
                if(len==0) {
 
4679
                if (len == 0) {
3654
4680
                        BLI_dynstr_appendf(dynstr, "%g", RNA_property_float_get(ptr, prop));
3655
4681
                }
3656
4682
                else {
3657
4683
                        BLI_dynstr_append(dynstr, "(");
3658
 
                        for(i=0; i<len; i++) {
 
4684
                        for (i = 0; i<len; i++) {
3659
4685
                                BLI_dynstr_appendf(dynstr, i?", %g":"%g", RNA_property_float_get_index(ptr, prop, i));
3660
4686
                        }
3661
 
                        if(len==1)
 
4687
                        if (len == 1)
3662
4688
                                BLI_dynstr_append(dynstr, ","); /* otherwise python wont see it as a tuple */
3663
4689
                        BLI_dynstr_append(dynstr, ")");
3664
4690
                }
3665
4691
                break;
3666
4692
        case PROP_STRING:
3667
4693
        {
3668
 
                /* string arrays dont exist */
 
4694
                char *buf_esc;
3669
4695
                char *buf;
3670
 
                buf = RNA_property_string_get_alloc(ptr, prop, NULL, -1);
3671
 
                BLI_dynstr_appendf(dynstr, "\"%s\"", 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);
3672
4703
                MEM_freeN(buf);
 
4704
                BLI_dynstr_appendf(dynstr, "\"%s\"", buf_esc);
 
4705
                MEM_freeN(buf_esc);
3673
4706
                break;
3674
4707
        }
3675
4708
        case PROP_ENUM:
3676
4709
        {
3677
 
                /* string arrays dont exist */
 
4710
                /* string arrays don't exist */
3678
4711
                const char *identifier;
3679
4712
                int val = RNA_property_enum_get(ptr, prop);
3680
4713
 
3681
 
                if(RNA_property_enum_identifier(C, ptr, prop, val, &identifier)) {
 
4714
                if (RNA_property_flag(prop) & PROP_ENUM_FLAG) {
 
4715
                        /* represent as a python set */
 
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)) {
3682
4745
                        BLI_dynstr_appendf(dynstr, "'%s'", identifier);
3683
4746
                }
3684
4747
                else {
3685
 
                        BLI_dynstr_appendf(dynstr, "'<UNKNOWN ENUM>'", identifier);
 
4748
                        BLI_dynstr_append(dynstr, "'<UNKNOWN ENUM>'");
3686
4749
                }
3687
4750
                break;
3688
4751
        }
3689
4752
        case PROP_POINTER:
3690
4753
        {
3691
 
                BLI_dynstr_append(dynstr, "'<POINTER>'"); /* TODO */
 
4754
                PointerRNA tptr = RNA_property_pointer_get(ptr, prop);
 
4755
                cstring = RNA_pointer_as_string(C, &tptr);
 
4756
                BLI_dynstr_append(dynstr, cstring);
 
4757
                MEM_freeN(cstring);
3692
4758
                break;
3693
4759
        }
3694
4760
        case PROP_COLLECTION:
3697
4763
                CollectionPropertyIterator collect_iter;
3698
4764
                BLI_dynstr_append(dynstr, "[");
3699
4765
                
3700
 
                for(RNA_property_collection_begin(ptr, prop, &collect_iter); collect_iter.valid; RNA_property_collection_next(&collect_iter)) {
3701
 
                        PointerRNA itemptr= collect_iter.ptr;
 
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;
3702
4769
                        
3703
 
                        if(first_time==0)
 
4770
                        if (first_time == 0)
3704
4771
                                BLI_dynstr_append(dynstr, ", ");
3705
 
                        first_time= 0;
 
4772
                        first_time = 0;
3706
4773
                        
3707
4774
                        /* now get every prop of the collection */
3708
 
                        cstring= RNA_pointer_as_string(&itemptr);
 
4775
                        cstring = RNA_pointer_as_string(C, &itemptr);
3709
4776
                        BLI_dynstr_append(dynstr, cstring);
3710
4777
                        MEM_freeN(cstring);
3711
4778
                }
3746
4813
        return func->call != NULL;
3747
4814
}
3748
4815
 
3749
 
PropertyRNA *RNA_function_get_parameter(PointerRNA *ptr, FunctionRNA *func, int index)
 
4816
PropertyRNA *RNA_function_get_parameter(PointerRNA *UNUSED(ptr), FunctionRNA *func, int index)
3750
4817
{
3751
 
        PropertyRNA *parm;
3752
 
        int i;
3753
 
 
3754
 
        parm= func->cont.properties.first;
3755
 
        for(i= 0; parm; parm= parm->next, i++)
3756
 
                if(i==index)
3757
 
                        return parm;
3758
 
 
3759
 
        return NULL;
 
4818
        return BLI_findlink(&func->cont.properties, index);
3760
4819
}
3761
4820
 
3762
 
PropertyRNA *RNA_function_find_parameter(PointerRNA *ptr, FunctionRNA *func, const char *identifier)
 
4821
PropertyRNA *RNA_function_find_parameter(PointerRNA *UNUSED(ptr), FunctionRNA *func, const char *identifier)
3763
4822
{
3764
 
        PropertyRNA *parm;
3765
 
 
3766
 
        parm= func->cont.properties.first;
3767
 
        for(; parm; parm= parm->next)
3768
 
                if(strcmp(parm->identifier, identifier)==0)
3769
 
                        return parm;
3770
 
 
3771
 
        return NULL;
 
4823
        return BLI_findstring(&func->cont.properties, identifier, offsetof(PropertyRNA, identifier));
3772
4824
}
3773
4825
 
3774
4826
const struct ListBase *RNA_function_defined_parameters(FunctionRNA *func)
3778
4830
 
3779
4831
/* Utility */
3780
4832
 
3781
 
ParameterList *RNA_parameter_list_create(ParameterList *parms, PointerRNA *ptr, FunctionRNA *func)
 
4833
ParameterList *RNA_parameter_list_create(ParameterList *parms, PointerRNA *UNUSED(ptr), FunctionRNA *func)
3782
4834
{
3783
4835
        PropertyRNA *parm;
3784
4836
        void *data;
3785
 
        int alloc_size= 0, size;
3786
 
 
3787
 
    parms->arg_count= 0;
3788
 
    parms->ret_count= 0;
3789
 
    
 
4837
        int alloc_size = 0, size;
 
4838
 
 
4839
        parms->arg_count = 0;
 
4840
        parms->ret_count = 0;
 
4841
 
3790
4842
        /* allocate data */
3791
 
        for(parm= func->cont.properties.first; parm; parm= parm->next) {
 
4843
        for (parm = func->cont.properties.first; parm; parm = parm->next) {
3792
4844
                alloc_size += rna_parameter_size_alloc(parm);
3793
4845
 
3794
 
        if(parm->flag & PROP_OUTPUT)
3795
 
            parms->ret_count++;
3796
 
        else
3797
 
            parms->arg_count++;
3798
 
    }
 
4846
                if (parm->flag & PROP_OUTPUT)
 
4847
                        parms->ret_count++;
 
4848
                else
 
4849
                        parms->arg_count++;
 
4850
        }
3799
4851
 
3800
 
        parms->data= MEM_callocN(alloc_size, "RNA_parameter_list_create");
3801
 
        parms->func= func;
3802
 
        parms->alloc_size= alloc_size;
 
4852
        parms->data = MEM_callocN(alloc_size, "RNA_parameter_list_create");
 
4853
        parms->func = func;
 
4854
        parms->alloc_size = alloc_size;
3803
4855
 
3804
4856
        /* set default values */
3805
 
        data= parms->data;
3806
 
 
3807
 
        for(parm= func->cont.properties.first; parm; parm= parm->next) {
3808
 
                size= rna_parameter_size(parm);
3809
 
 
3810
 
                if(!(parm->flag & PROP_REQUIRED)) {
3811
 
                        switch(parm->type) {
 
4857
        data = parms->data;
 
4858
 
 
4859
        for (parm = func->cont.properties.first; parm; parm = parm->next) {
 
4860
                size = rna_parameter_size(parm);
 
4861
 
 
4862
                /* set length to 0, these need to be set later, see bpy_array.c's py_to_array */
 
4863
                if (parm->flag & PROP_DYNAMIC) {
 
4864
                        ParameterDynAlloc *data_alloc = data;
 
4865
                        data_alloc->array_tot = 0;
 
4866
                        data_alloc->array = NULL;
 
4867
                }
 
4868
                
 
4869
                if (!(parm->flag & PROP_REQUIRED) && !(parm->flag & PROP_DYNAMIC)) {
 
4870
                        switch (parm->type) {
3812
4871
                                case PROP_BOOLEAN:
3813
 
                                        if(parm->arraydimension) memcpy(data, &((BooleanPropertyRNA*)parm)->defaultarray, size);
3814
 
                                        else memcpy(data, &((BooleanPropertyRNA*)parm)->defaultvalue, size);
 
4872
                                        if (parm->arraydimension) memcpy(data, ((BoolPropertyRNA*)parm)->defaultarray, size);
 
4873
                                        else memcpy(data, &((BoolPropertyRNA*)parm)->defaultvalue, size);
3815
4874
                                        break;
3816
4875
                                case PROP_INT:
3817
 
                                        if(parm->arraydimension) memcpy(data, &((IntPropertyRNA*)parm)->defaultarray, size);
 
4876
                                        if (parm->arraydimension) memcpy(data, ((IntPropertyRNA*)parm)->defaultarray, size);
3818
4877
                                        else memcpy(data, &((IntPropertyRNA*)parm)->defaultvalue, size);
3819
4878
                                        break;
3820
4879
                                case PROP_FLOAT:
3821
 
                                        if(parm->arraydimension) memcpy(data, &((FloatPropertyRNA*)parm)->defaultarray, size);
 
4880
                                        if (parm->arraydimension) memcpy(data, ((FloatPropertyRNA*)parm)->defaultarray, size);
3822
4881
                                        else memcpy(data, &((FloatPropertyRNA*)parm)->defaultvalue, size);
3823
4882
                                        break;
3824
4883
                                case PROP_ENUM:
3825
4884
                                        memcpy(data, &((EnumPropertyRNA*)parm)->defaultvalue, size);
3826
4885
                                        break;
3827
4886
                                case PROP_STRING: {
3828
 
                                        const char *defvalue= ((StringPropertyRNA*)parm)->defaultvalue;
3829
 
                                        if(defvalue && defvalue[0])
 
4887
                                        const char *defvalue = ((StringPropertyRNA*)parm)->defaultvalue;
 
4888
                                        if (defvalue && defvalue[0]) {
 
4889
                                                /* causes bug [#29988], possibly this is only correct for thick wrapped
 
4890
                                                 * need to look further into it - campbell */
 
4891
#if 0
 
4892
                                                BLI_strncpy(data, defvalue, size);
 
4893
#else
3830
4894
                                                memcpy(data, &defvalue, size);
 
4895
#endif
 
4896
                                        }
3831
4897
                                        break;
3832
4898
                                }
3833
4899
                                case PROP_POINTER:
3836
4902
                        }
3837
4903
                }
3838
4904
 
3839
 
                /* set length to 0 */
3840
 
                if (parm->flag & PROP_DYNAMIC)
3841
 
                        *((int *)(((char *)data) + size))= 0;
3842
 
 
3843
 
                data= ((char*)data) + rna_parameter_size_alloc(parm);
 
4905
                data = ((char*)data) + rna_parameter_size_alloc(parm);
3844
4906
        }
3845
4907
 
3846
4908
        return parms;
3851
4913
        PropertyRNA *parm;
3852
4914
        int tot;
3853
4915
 
3854
 
        parm= parms->func->cont.properties.first;
3855
 
        for(tot= 0; parm; parm= parm->next) {
3856
 
                if(parm->type == PROP_COLLECTION)
 
4916
        parm = parms->func->cont.properties.first;
 
4917
        for (tot = 0; parm; parm = parm->next) {
 
4918
                if (parm->type == PROP_COLLECTION)
3857
4919
                        BLI_freelistN((ListBase*)((char*)parms->data+tot));
3858
4920
                else if (parm->flag & PROP_DYNAMIC) {
3859
4921
                        /* for dynamic arrays and strings, data is a pointer to an array */
3860
 
                        char *array= *(char**)((char*)parms->data+tot);
3861
 
                        if(array)
3862
 
                                MEM_freeN(array);
 
4922
                        ParameterDynAlloc *data_alloc = (void *)(((char *)parms->data) + tot);
 
4923
                        if (data_alloc->array)
 
4924
                                MEM_freeN(data_alloc->array);
3863
4925
                }
3864
4926
 
3865
 
                tot+= rna_parameter_size_alloc(parm);
 
4927
                tot += rna_parameter_size_alloc(parm);
3866
4928
        }
3867
4929
 
3868
4930
        MEM_freeN(parms->data);
3869
 
        parms->data= NULL;
 
4931
        parms->data = NULL;
3870
4932
 
3871
 
        parms->func= NULL;
 
4933
        parms->func = NULL;
3872
4934
}
3873
4935
 
3874
4936
int  RNA_parameter_list_size(ParameterList *parms)
3888
4950
 
3889
4951
void RNA_parameter_list_begin(ParameterList *parms, ParameterIterator *iter)
3890
4952
{
3891
 
        PropertyType ptype;
3892
 
 
3893
 
        RNA_pointer_create(NULL, &RNA_Function, parms->func, &iter->funcptr);
3894
 
 
3895
 
        iter->parms= parms;
3896
 
        iter->parm= parms->func->cont.properties.first;
3897
 
        iter->valid= iter->parm != NULL;
3898
 
        iter->offset= 0;
3899
 
 
3900
 
        if(iter->valid) {
3901
 
                iter->size= rna_parameter_size_alloc(iter->parm);
3902
 
                iter->data= (((char*)iter->parms->data)+iter->offset);
3903
 
                ptype= RNA_property_type(iter->parm);
 
4953
        /* may be useful but unused now */
 
4954
        /* RNA_pointer_create(NULL, &RNA_Function, parms->func, &iter->funcptr); */ /*UNUSED*/
 
4955
 
 
4956
        iter->parms = parms;
 
4957
        iter->parm = parms->func->cont.properties.first;
 
4958
        iter->valid = iter->parm != NULL;
 
4959
        iter->offset = 0;
 
4960
 
 
4961
        if (iter->valid) {
 
4962
                iter->size = rna_parameter_size_alloc(iter->parm);
 
4963
                iter->data = (((char*)iter->parms->data)); /* +iter->offset, always 0 */
3904
4964
        }
3905
4965
}
3906
4966
 
3907
4967
void RNA_parameter_list_next(ParameterIterator *iter)
3908
4968
{
3909
 
        PropertyType ptype;
3910
 
 
3911
 
        iter->offset+= iter->size;
3912
 
        iter->parm= iter->parm->next;
3913
 
        iter->valid= iter->parm != NULL;
3914
 
 
3915
 
        if(iter->valid) {
3916
 
                iter->size= rna_parameter_size_alloc(iter->parm);
3917
 
                iter->data= (((char*)iter->parms->data)+iter->offset);
3918
 
                ptype= RNA_property_type(iter->parm);
 
4969
        iter->offset += iter->size;
 
4970
        iter->parm = iter->parm->next;
 
4971
        iter->valid = iter->parm != NULL;
 
4972
 
 
4973
        if (iter->valid) {
 
4974
                iter->size = rna_parameter_size_alloc(iter->parm);
 
4975
                iter->data = (((char*)iter->parms->data)+iter->offset);
3919
4976
        }
3920
4977
}
3921
4978
 
3922
 
void RNA_parameter_list_end(ParameterIterator *iter)
 
4979
void RNA_parameter_list_end(ParameterIterator *UNUSED(iter))
3923
4980
{
3924
4981
        /* nothing to do */
3925
4982
}
3930
4987
 
3931
4988
        RNA_parameter_list_begin(parms, &iter);
3932
4989
 
3933
 
        for(; iter.valid; RNA_parameter_list_next(&iter))
3934
 
                if(iter.parm==parm) 
 
4990
        for (; iter.valid; RNA_parameter_list_next(&iter))
 
4991
                if (iter.parm == parm)
3935
4992
                        break;
3936
4993
 
3937
 
        if(iter.valid)
3938
 
                *value= iter.data;
 
4994
        if (iter.valid)
 
4995
                *value = iter.data;
3939
4996
        else
3940
 
                *value= NULL;
 
4997
                *value = NULL;
3941
4998
 
3942
4999
        RNA_parameter_list_end(&iter);
3943
5000
}
3946
5003
{
3947
5004
        PropertyRNA *parm;
3948
5005
 
3949
 
        parm= parms->func->cont.properties.first;
3950
 
        for(; parm; parm= parm->next)
3951
 
                if(strcmp(RNA_property_identifier(parm), identifier)==0)
 
5006
        parm = parms->func->cont.properties.first;
 
5007
        for (; parm; parm = parm->next)
 
5008
                if (strcmp(RNA_property_identifier(parm), identifier) == 0)
3952
5009
                        break;
3953
5010
 
3954
 
        if(parm)
 
5011
        if (parm)
3955
5012
                RNA_parameter_get(parms, parm, value);
3956
5013
}
3957
5014
 
3958
 
void RNA_parameter_set(ParameterList *parms, PropertyRNA *parm, void *value)
 
5015
void RNA_parameter_set(ParameterList *parms, PropertyRNA *parm, const void *value)
3959
5016
{
3960
5017
        ParameterIterator iter;
3961
5018
 
3962
5019
        RNA_parameter_list_begin(parms, &iter);
3963
5020
 
3964
 
        for(; iter.valid; RNA_parameter_list_next(&iter))
3965
 
                if(iter.parm==parm) 
 
5021
        for (; iter.valid; RNA_parameter_list_next(&iter))
 
5022
                if (iter.parm == parm)
3966
5023
                        break;
3967
5024
 
3968
 
        if(iter.valid)
 
5025
        if (iter.valid)
3969
5026
                memcpy(iter.data, value, iter.size);
3970
5027
 
3971
5028
        RNA_parameter_list_end(&iter);
3972
5029
}
3973
5030
 
3974
 
void RNA_parameter_set_lookup(ParameterList *parms, const char *identifier, void *value)
 
5031
void RNA_parameter_set_lookup(ParameterList *parms, const char *identifier, const void *value)
3975
5032
{
3976
5033
        PropertyRNA *parm;
3977
5034
 
3978
 
        parm= parms->func->cont.properties.first;
3979
 
        for(; parm; parm= parm->next)
3980
 
                if(strcmp(RNA_property_identifier(parm), identifier)==0)
 
5035
        parm = parms->func->cont.properties.first;
 
5036
        for (; parm; parm = parm->next)
 
5037
                if (strcmp(RNA_property_identifier(parm), identifier) == 0)
3981
5038
                        break;
3982
5039
 
3983
 
        if(parm)
 
5040
        if (parm)
3984
5041
                RNA_parameter_set(parms, parm, value);
3985
5042
}
3986
5043
 
3987
5044
int RNA_parameter_length_get(ParameterList *parms, PropertyRNA *parm)
3988
5045
{
3989
5046
        ParameterIterator iter;
3990
 
        int len= 0;
 
5047
        int len = 0;
3991
5048
 
3992
5049
        RNA_parameter_list_begin(parms, &iter);
3993
5050
 
3994
 
        for(; iter.valid; RNA_parameter_list_next(&iter))
3995
 
                if(iter.parm==parm)
 
5051
        for (; iter.valid; RNA_parameter_list_next(&iter))
 
5052
                if (iter.parm == parm)
3996
5053
                        break;
3997
5054
 
3998
 
        if(iter.valid)
3999
 
                len= RNA_parameter_length_get_data(parms, parm, iter.data);
 
5055
        if (iter.valid)
 
5056
                len = RNA_parameter_length_get_data(parms, parm, iter.data);
4000
5057
 
4001
5058
        RNA_parameter_list_end(&iter);
4002
5059
 
4009
5066
 
4010
5067
        RNA_parameter_list_begin(parms, &iter);
4011
5068
 
4012
 
        for(; iter.valid; RNA_parameter_list_next(&iter))
4013
 
                if(iter.parm==parm)
 
5069
        for (; iter.valid; RNA_parameter_list_next(&iter))
 
5070
                if (iter.parm == parm)
4014
5071
                        break;
4015
5072
 
4016
 
        if(iter.valid)
 
5073
        if (iter.valid)
4017
5074
                RNA_parameter_length_set_data(parms, parm, iter.data, length);
4018
5075
 
4019
5076
        RNA_parameter_list_end(&iter);
4020
5077
}
4021
5078
 
4022
 
int RNA_parameter_length_get_data(ParameterList *parms, PropertyRNA *parm, void *data)
 
5079
int RNA_parameter_length_get_data(ParameterList *UNUSED(parms), PropertyRNA *UNUSED(parm), void *data)
4023
5080
{
4024
 
        return *((int *)(((char *)data) + rna_parameter_size(parm)));
 
5081
        return *((int *)((char *)data));
4025
5082
}
4026
5083
 
4027
 
void RNA_parameter_length_set_data(ParameterList *parms, PropertyRNA *parm, void *data, int length)
 
5084
void RNA_parameter_length_set_data(ParameterList *UNUSED(parms), PropertyRNA *UNUSED(parm), void *data, int length)
4028
5085
{
4029
 
        *((int *)(((char *)data) + rna_parameter_size(parm)))= length;
 
5086
        *((int *)data) = length;
4030
5087
}
4031
5088
 
4032
5089
int RNA_function_call(bContext *C, ReportList *reports, PointerRNA *ptr, FunctionRNA *func, ParameterList *parms)
4033
5090
{
4034
 
        if(func->call) {
 
5091
        if (func->call) {
4035
5092
                func->call(C, reports, ptr, parms);
4036
5093
 
4037
5094
                return 0;
4040
5097
        return -1;
4041
5098
}
4042
5099
 
4043
 
int RNA_function_call_lookup(bContext *C, ReportList *reports, PointerRNA *ptr, const char *identifier, ParameterList *parms)
 
5100
int RNA_function_call_lookup(bContext *C, ReportList *reports, PointerRNA *ptr, const char *identifier,
 
5101
                             ParameterList *parms)
4044
5102
{
4045
5103
        FunctionRNA *func;
4046
5104
 
4047
 
        func= RNA_struct_find_function(ptr, identifier);
 
5105
        func = RNA_struct_find_function(ptr, identifier);
4048
5106
 
4049
 
        if(func)
 
5107
        if (func)
4050
5108
                return RNA_function_call(C, reports, ptr, func, parms);
4051
5109
 
4052
5110
        return -1;
4053
5111
}
4054
5112
 
4055
 
int RNA_function_call_direct(bContext *C, ReportList *reports, PointerRNA *ptr, FunctionRNA *func, const char *format, ...)
 
5113
int RNA_function_call_direct(bContext *C, ReportList *reports, PointerRNA *ptr, FunctionRNA *func,
 
5114
                             const char *format, ...)
4056
5115
{
4057
5116
        va_list args;
4058
5117
        int ret;
4059
5118
 
4060
5119
        va_start(args, format);
4061
5120
 
4062
 
        ret= RNA_function_call_direct_va(C, reports, ptr, func, format, args);
 
5121
        ret = RNA_function_call_direct_va(C, reports, ptr, func, format, args);
4063
5122
 
4064
5123
        va_end(args);
4065
5124
 
4066
5125
        return ret;
4067
5126
}
4068
5127
 
4069
 
int RNA_function_call_direct_lookup(bContext *C, ReportList *reports, PointerRNA *ptr, const char *identifier, const char *format, ...)
 
5128
int RNA_function_call_direct_lookup(bContext *C, ReportList *reports, PointerRNA *ptr, const char *identifier,
 
5129
                                    const char *format, ...)
4070
5130
{
4071
5131
        FunctionRNA *func;
4072
5132
 
4073
 
        func= RNA_struct_find_function(ptr, identifier);
 
5133
        func = RNA_struct_find_function(ptr, identifier);
4074
5134
 
4075
 
        if(func) {
 
5135
        if (func) {
4076
5136
                va_list args;
4077
5137
                int ret;
4078
5138
 
4079
5139
                va_start(args, format);
4080
5140
 
4081
 
                ret= RNA_function_call_direct_va(C, reports, ptr, func, format, args);
 
5141
                ret = RNA_function_call_direct_va(C, reports, ptr, func, format, args);
4082
5142
 
4083
5143
                va_end(args);
4084
5144
 
4091
5151
static int rna_function_format_array_length(const char *format, int ofs, int flen)
4092
5152
{
4093
5153
        char lenbuf[16];
4094
 
        int idx= 0;
4095
 
 
4096
 
        if (format[ofs++]=='[')
4097
 
                for (; ofs<flen && format[ofs]!=']' && idx<sizeof(*lenbuf)-1; idx++, ofs++)
4098
 
                        lenbuf[idx]= format[ofs];
4099
 
 
4100
 
        if (ofs<flen && format[ofs++]==']') {
 
5154
        int idx = 0;
 
5155
 
 
5156
        if (format[ofs++] =='[')
 
5157
                for (; ofs<flen && format[ofs] !=']' && idx<sizeof(*lenbuf)-1; idx++, ofs++)
 
5158
                        lenbuf[idx] = format[ofs];
 
5159
 
 
5160
        if (ofs<flen && format[ofs+1] ==']') {
4101
5161
                /* XXX put better error reporting for ofs>=flen or idx over lenbuf capacity */
4102
 
                lenbuf[idx]= '\0';
 
5162
                lenbuf[idx] = '\0';
4103
5163
                return atoi(lenbuf);
4104
5164
        }
4105
5165
 
4106
5166
        return 0;
4107
5167
}
4108
5168
 
4109
 
static int rna_function_parameter_parse(PointerRNA *ptr, PropertyRNA *prop, PropertyType type, char ftype, int len, void *dest, void *src, StructRNA *srna, const char *tid, const char *fid, const char *pid)
 
5169
static int rna_function_parameter_parse(PointerRNA *ptr, PropertyRNA *prop, PropertyType type,
 
5170
                                        char ftype, int len, void *dest, void *src, StructRNA *srna,
 
5171
                                        const char *tid, const char *fid, const char *pid)
4110
5172
{
4111
5173
        /* ptr is always a function pointer, prop always a parameter */
4112
5174
 
4113
5175
        switch (type) {
4114
5176
        case PROP_BOOLEAN:
4115
5177
                {
4116
 
                        if (ftype!='b') {
 
5178
                        if (ftype !='b') {
4117
5179
                                fprintf(stderr, "%s.%s: wrong type for parameter %s, a boolean was expected\n", tid, fid, pid);
4118
5180
                                return -1;
4119
5181
                        }
4120
5182
 
4121
 
                        if (len==0)
4122
 
                                *((int*)dest)= *((int*)src);
 
5183
                        if (len == 0)
 
5184
                                *((int*)dest) = *((int*)src);
4123
5185
                        else
4124
5186
                                memcpy(dest, src, len*sizeof(int));
4125
5187
 
4127
5189
                }
4128
5190
        case PROP_INT:
4129
5191
                {
4130
 
                        if (ftype!='i') {
 
5192
                        if (ftype !='i') {
4131
5193
                                fprintf(stderr, "%s.%s: wrong type for parameter %s, an integer was expected\n", tid, fid, pid);
4132
5194
                                return -1;
4133
5195
                        }
4134
5196
 
4135
 
                        if (len==0)
4136
 
                                *((int*)dest)= *((int*)src);
 
5197
                        if (len == 0)
 
5198
                                *((int*)dest) = *((int*)src);
4137
5199
                        else
4138
5200
                                memcpy(dest, src, len*sizeof(int));
4139
5201
 
4141
5203
                }
4142
5204
        case PROP_FLOAT:
4143
5205
                {
4144
 
                        if (ftype!='f') {
 
5206
                        if (ftype !='f') {
4145
5207
                                fprintf(stderr, "%s.%s: wrong type for parameter %s, a float was expected\n", tid, fid, pid);
4146
5208
                                return -1;
4147
5209
                        }
4148
5210
 
4149
 
                        if (len==0)
4150
 
                                *((float*)dest)= *((float*)src);
 
5211
                        if (len == 0)
 
5212
                                *((float*)dest) = *((float*)src);
4151
5213
                        else
4152
5214
                                memcpy(dest, src, len*sizeof(float));
4153
5215
 
4155
5217
                }
4156
5218
        case PROP_STRING:
4157
5219
                {
4158
 
                        if (ftype!='s') {
 
5220
                        if (ftype !='s') {
4159
5221
                                fprintf(stderr, "%s.%s: wrong type for parameter %s, a string was expected\n", tid, fid, pid);
4160
5222
                                return -1;
4161
5223
                        }
4162
5224
 
4163
 
                        *((char**)dest)= *((char**)src);
 
5225
                        *((char**)dest) = *((char**)src);
4164
5226
 
4165
5227
                        break;
4166
5228
                }
4167
5229
        case PROP_ENUM:
4168
5230
                {
4169
 
                        if (ftype!='e') {
 
5231
                        if (ftype !='e') {
4170
5232
                                fprintf(stderr, "%s.%s: wrong type for parameter %s, an enum was expected\n", tid, fid, pid);
4171
5233
                                return -1;
4172
5234
                        }
4173
5235
 
4174
 
                        *((int*)dest)= *((int*)src);
 
5236
                        *((int*)dest) = *((int*)src);
4175
5237
 
4176
5238
                        break;
4177
5239
                }
4179
5241
                {
4180
5242
                        StructRNA *ptype;
4181
5243
 
4182
 
                        if (ftype!='O') {
 
5244
                        if (ftype !='O') {
4183
5245
                                fprintf(stderr, "%s.%s: wrong type for parameter %s, an object was expected\n", tid, fid, pid);
4184
5246
                                return -1;
4185
5247
                        }
4186
5248
 
4187
 
                        ptype= RNA_property_pointer_type(ptr, prop);
 
5249
                        ptype = RNA_property_pointer_type(ptr, prop);
4188
5250
 
4189
 
                        if(prop->flag & PROP_RNAPTR) {
4190
 
                                *((PointerRNA*)dest)= *((PointerRNA*)src);
 
5251
                        if (prop->flag & PROP_RNAPTR) {
 
5252
                                *((PointerRNA*)dest) = *((PointerRNA*)src);
4191
5253
                                break;
4192
5254
                         }
4193
5255
                        
4194
 
                        if (ptype!=srna && !RNA_struct_is_a(srna, ptype)) {
4195
 
                                fprintf(stderr, "%s.%s: wrong type for parameter %s, an object of type %s was expected, passed an object of type %s\n", tid, fid, pid, RNA_struct_identifier(ptype), RNA_struct_identifier(srna));
 
5256
                        if (ptype != srna && !RNA_struct_is_a(srna, ptype)) {
 
5257
                                fprintf(stderr, "%s.%s: wrong type for parameter %s, "
 
5258
                                        "an object of type %s was expected, passed an object of type %s\n",
 
5259
                                        tid, fid, pid, RNA_struct_identifier(ptype), RNA_struct_identifier(srna));
4196
5260
                                return -1;
4197
5261
                        }
4198
5262
 
4199
 
                        *((void**)dest)= *((void**)src);
 
5263
                        *((void**)dest) = *((void**)src);
4200
5264
 
4201
5265
                        break;
4202
5266
                }
4207
5271
                        Link *link;
4208
5272
                        CollectionPointerLink *clink;
4209
5273
 
4210
 
                        if (ftype!='C') {
 
5274
                        if (ftype !='C') {
4211
5275
                                fprintf(stderr, "%s.%s: wrong type for parameter %s, a collection was expected\n", tid, fid, pid);
4212
5276
                                return -1;
4213
5277
                        }
4214
5278
 
4215
 
                        lb= (ListBase *)src;
4216
 
                        clb= (ListBase *)dest;
4217
 
                        ptype= RNA_property_pointer_type(ptr, prop);
 
5279
                        lb = (ListBase *)src;
 
5280
                        clb = (ListBase *)dest;
 
5281
                        ptype = RNA_property_pointer_type(ptr, prop);
4218
5282
                        
4219
 
                        if (ptype!=srna && !RNA_struct_is_a(srna, ptype)) {
4220
 
                                fprintf(stderr, "%s.%s: wrong type for parameter %s, a collection of objects of type %s was expected, passed a collection of objects of type %s\n", tid, fid, pid, RNA_struct_identifier(ptype), RNA_struct_identifier(srna));
 
5283
                        if (ptype != srna && !RNA_struct_is_a(srna, ptype)) {
 
5284
                                fprintf(stderr, "%s.%s: wrong type for parameter %s, "
 
5285
                                        "a collection of objects of type %s was expected, "
 
5286
                                        "passed a collection of objects of type %s\n",
 
5287
                                        tid, fid, pid, RNA_struct_identifier(ptype), RNA_struct_identifier(srna));
4221
5288
                                return -1;
4222
5289
                        }
4223
5290
 
4224
 
                        for (link= lb->first; link; link= link->next) {
4225
 
                                clink= MEM_callocN(sizeof(CollectionPointerLink), "CCollectionPointerLink");
 
5291
                        for (link = lb->first; link; link = link->next) {
 
5292
                                clink = MEM_callocN(sizeof(CollectionPointerLink), "CCollectionPointerLink");
4226
5293
                                RNA_pointer_create(NULL, srna, link, &clink->ptr);
4227
5294
                                BLI_addtail(clb, clink);
4228
5295
                        }
4229
5296
 
4230
5297
                        break;
4231
5298
                }
4232
 
        default: 
 
5299
        default:
4233
5300
                {
4234
 
                        if (len==0)
 
5301
                        if (len == 0)
4235
5302
                                fprintf(stderr, "%s.%s: unknown type for parameter %s\n", tid, fid, pid);
4236
5303
                        else
4237
5304
                                fprintf(stderr, "%s.%s: unknown array type for parameter %s\n", tid, fid, pid);
4243
5310
        return 0;
4244
5311
}
4245
5312
 
4246
 
int RNA_function_call_direct_va(bContext *C, ReportList *reports, PointerRNA *ptr, FunctionRNA *func, const char *format, va_list args)
 
5313
int RNA_function_call_direct_va(bContext *C, ReportList *reports, PointerRNA *ptr, FunctionRNA *func,
 
5314
                                const char *format, va_list args)
4247
5315
{
4248
5316
        PointerRNA funcptr;
4249
5317
        ParameterList parms;
4250
5318
        ParameterIterator iter;
4251
5319
        PropertyRNA *pret, *parm;
4252
5320
        PropertyType type;
4253
 
        int i, ofs, flen, flag, len, alen, err= 0;
4254
 
        const char *tid, *fid, *pid=NULL;
 
5321
        int i, ofs, flen, flag, len, alen, err = 0;
 
5322
        const char *tid, *fid, *pid = NULL;
4255
5323
        char ftype;
4256
 
        void **retdata=NULL;
 
5324
        void **retdata = NULL;
4257
5325
 
4258
5326
        RNA_pointer_create(NULL, &RNA_Function, func, &funcptr);
4259
5327
 
4260
 
        tid= RNA_struct_identifier(ptr->type);
4261
 
        fid= RNA_function_identifier(func);
4262
 
        pret= func->c_ret;
4263
 
        flen= strlen(format);
 
5328
        tid = RNA_struct_identifier(ptr->type);
 
5329
        fid = RNA_function_identifier(func);
 
5330
        pret = func->c_ret;
 
5331
        flen = strlen(format);
4264
5332
 
4265
5333
        RNA_parameter_list_create(&parms, ptr, func);
4266
5334
        RNA_parameter_list_begin(&parms, &iter);
4267
5335
 
4268
 
        for(i= 0, ofs= 0; iter.valid; RNA_parameter_list_next(&iter), i++) {
4269
 
                parm= iter.parm;
4270
 
                flag= RNA_property_flag(parm);
 
5336
        for (i = 0, ofs = 0; iter.valid; RNA_parameter_list_next(&iter), i++) {
 
5337
                parm = iter.parm;
 
5338
                flag = RNA_property_flag(parm);
4271
5339
 
4272
 
                if(parm==pret) {
4273
 
                        retdata= iter.data;
 
5340
                if (parm == pret) {
 
5341
                        retdata = iter.data;
4274
5342
                        continue;
4275
5343
                }
4276
5344
                else if (flag & PROP_OUTPUT) {
4277
5345
                        continue;
4278
5346
                }
4279
5347
 
4280
 
                pid= RNA_property_identifier(parm);
 
5348
                pid = RNA_property_identifier(parm);
4281
5349
 
4282
 
                if (ofs>=flen || format[ofs]=='N') {
 
5350
                if (ofs >= flen || format[ofs] =='N') {
4283
5351
                        if (flag & PROP_REQUIRED) {
4284
 
                                err= -1;
 
5352
                                err = -1;
4285
5353
                                fprintf(stderr, "%s.%s: missing required parameter %s\n", tid, fid, pid);
4286
5354
                                break;
4287
5355
                        }
4289
5357
                        continue;
4290
5358
                }
4291
5359
 
4292
 
                type= RNA_property_type(parm);
4293
 
                ftype= format[ofs++];
4294
 
                len= RNA_property_array_length(&funcptr, parm);
4295
 
                alen= rna_function_format_array_length(format, ofs, flen);
 
5360
                type = RNA_property_type(parm);
 
5361
                ftype = format[ofs++];
 
5362
                len = RNA_property_array_length(&funcptr, parm);
 
5363
                alen = rna_function_format_array_length(format, ofs, flen);
4296
5364
 
4297
 
                if (len!=alen) {
4298
 
                        err= -1;
4299
 
                        fprintf(stderr, "%s.%s: for parameter %s, was expecting an array of %i elements, passed %i elements instead\n", tid, fid, pid, len, alen);
 
5365
                if (len != alen) {
 
5366
                        err = -1;
 
5367
                        fprintf(stderr, "%s.%s: for parameter %s, "
 
5368
                                "was expecting an array of %i elements, "
 
5369
                                "passed %i elements instead\n",
 
5370
                                tid, fid, pid, len, alen);
4300
5371
                        break;
4301
5372
                }
4302
5373
 
4305
5376
                case PROP_INT:
4306
5377
                case PROP_ENUM:
4307
5378
                        {
4308
 
                                int arg= va_arg(args, int);
4309
 
                                err= rna_function_parameter_parse(&funcptr, parm, type, ftype, len, iter.data, &arg, NULL, tid, fid, pid);
 
5379
                                int arg = va_arg(args, int);
 
5380
                                err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, iter.data, &arg,
 
5381
                                                                   NULL, tid, fid, pid);
4310
5382
                                break;
4311
5383
                        }
4312
5384
                case PROP_FLOAT:
4313
5385
                        {
4314
 
                                double arg= va_arg(args, double);
4315
 
                                err= rna_function_parameter_parse(&funcptr, parm, type, ftype, len, iter.data, &arg, NULL, tid, fid, pid);
 
5386
                                double arg = va_arg(args, double);
 
5387
                                err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, iter.data, &arg,
 
5388
                                                                   NULL, tid, fid, pid);
4316
5389
                                break;
4317
5390
                        }
4318
5391
                case PROP_STRING:
4319
5392
                        {
4320
 
                                char *arg= va_arg(args, char*);
4321
 
                                err= rna_function_parameter_parse(&funcptr, parm, type, ftype, len, iter.data, &arg, NULL, tid, fid, pid);
 
5393
                                char *arg = va_arg(args, char*);
 
5394
                                err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, iter.data, &arg,
 
5395
                                                                   NULL, tid, fid, pid);
4322
5396
                                break;
4323
5397
                        }
4324
5398
                case PROP_POINTER:
4325
5399
                        {
4326
 
                                StructRNA *srna= va_arg(args, StructRNA*);
4327
 
                                void *arg= va_arg(args, void*);
4328
 
                                err= rna_function_parameter_parse(&funcptr, parm, type, ftype, len, iter.data, &arg, srna, tid, fid, pid);
 
5400
                                StructRNA *srna = va_arg(args, StructRNA*);
 
5401
                                void *arg = va_arg(args, void*);
 
5402
                                err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, iter.data, &arg,
 
5403
                                                                   srna, tid, fid, pid);
4329
5404
                                break;
4330
5405
                        }
4331
5406
                case PROP_COLLECTION:
4332
5407
                        {
4333
 
                                StructRNA *srna= va_arg(args, StructRNA*);
4334
 
                                ListBase *arg= va_arg(args, ListBase*);
4335
 
                                err= rna_function_parameter_parse(&funcptr, parm, type, ftype, len, iter.data, &arg, srna, tid, fid, pid);
 
5408
                                StructRNA *srna = va_arg(args, StructRNA*);
 
5409
                                ListBase *arg = va_arg(args, ListBase*);
 
5410
                                err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, iter.data, &arg,
 
5411
                                                                   srna, tid, fid, pid);
4336
5412
                                break;
4337
5413
                        }
4338
5414
                default:
4339
5415
                        {
4340
5416
                                /* handle errors */
4341
 
                                err= rna_function_parameter_parse(&funcptr, parm, type, ftype, len, iter.data, NULL, NULL, tid, fid, pid);
 
5417
                                err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, iter.data, NULL,
 
5418
                                                                   NULL, tid, fid, pid);
4342
5419
                                break;
4343
5420
                        }
4344
5421
                }
4345
5422
 
4346
 
                if (err!=0)
 
5423
                if (err != 0)
4347
5424
                        break;
4348
5425
        }
4349
5426
 
4350
 
        if (err==0)
4351
 
                err= RNA_function_call(C, reports, ptr, func, &parms);
 
5427
        if (err == 0)
 
5428
                err = RNA_function_call(C, reports, ptr, func, &parms);
4352
5429
 
4353
5430
        /* XXX throw error when more parameters than those needed are passed or leave silent? */
4354
 
        if (err==0 && pret && ofs<flen && format[ofs++]=='R') {
4355
 
                parm= pret;
4356
 
 
4357
 
                type= RNA_property_type(parm);
4358
 
                ftype= format[ofs++];
4359
 
                len= RNA_property_array_length(&funcptr, parm);
4360
 
                alen= rna_function_format_array_length(format, ofs, flen);
4361
 
 
4362
 
                if (len!=alen) {
4363
 
                        err= -1;
4364
 
                        fprintf(stderr, "%s.%s: for return parameter %s, was expecting an array of %i elements, passed %i elements instead\n", tid, fid, pid, len, alen);
 
5431
        if (err == 0 && pret && ofs<flen && format[ofs++] =='R') {
 
5432
                parm = pret;
 
5433
 
 
5434
                type = RNA_property_type(parm);
 
5435
                ftype = format[ofs++];
 
5436
                len = RNA_property_array_length(&funcptr, parm);
 
5437
                alen = rna_function_format_array_length(format, ofs, flen);
 
5438
 
 
5439
                if (len != alen) {
 
5440
                        err = -1;
 
5441
                        fprintf(stderr, "%s.%s: for return parameter %s, "
 
5442
                                "was expecting an array of %i elements, passed %i elements instead\n",
 
5443
                                tid, fid, pid, len, alen);
4365
5444
                }
4366
5445
                else {
4367
5446
                        switch (type) {
4369
5448
                        case PROP_INT:
4370
5449
                        case PROP_ENUM:
4371
5450
                                {
4372
 
                                        int *arg= va_arg(args, int*);
4373
 
                                        err= rna_function_parameter_parse(&funcptr, parm, type, ftype, len, arg, retdata, NULL, tid, fid, pid);
 
5451
                                        int *arg = va_arg(args, int*);
 
5452
                                        err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, arg, retdata,
 
5453
                                                                           NULL, tid, fid, pid);
4374
5454
                                        break;
4375
5455
                                }
4376
5456
                        case PROP_FLOAT:
4377
5457
                                {
4378
 
                                        float *arg= va_arg(args, float*);
4379
 
                                        err= rna_function_parameter_parse(&funcptr, parm, type, ftype, len, arg, retdata, NULL, tid, fid, pid);
 
5458
                                        float *arg = va_arg(args, float*);
 
5459
                                        err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, arg, retdata,
 
5460
                                                                           NULL, tid, fid, pid);
4380
5461
                                        break;
4381
5462
                                }
4382
5463
                        case PROP_STRING:
4383
5464
                                {
4384
 
                                        char **arg= va_arg(args, char**);
4385
 
                                        err= rna_function_parameter_parse(&funcptr, parm, type, ftype, len, arg, retdata, NULL, tid, fid, pid);
 
5465
                                        char **arg = va_arg(args, char**);
 
5466
                                        err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, arg, retdata,
 
5467
                                                                           NULL, tid, fid, pid);
4386
5468
                                        break;
4387
5469
                                }
4388
5470
                        case PROP_POINTER:
4389
5471
                                {
4390
 
                                        StructRNA *srna= va_arg(args, StructRNA*);
4391
 
                                        void **arg= va_arg(args, void**);
4392
 
                                        err= rna_function_parameter_parse(&funcptr, parm, type, ftype, len, arg, retdata, srna, tid, fid, pid);
 
5472
                                        StructRNA *srna = va_arg(args, StructRNA*);
 
5473
                                        void **arg = va_arg(args, void**);
 
5474
                                        err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, arg, retdata,
 
5475
                                                                           srna, tid, fid, pid);
4393
5476
                                        break;
4394
5477
                                }
4395
5478
                        case PROP_COLLECTION:
4396
5479
                                {
4397
 
                                        StructRNA *srna= va_arg(args, StructRNA*);
4398
 
                                        ListBase **arg= va_arg(args, ListBase**);
4399
 
                                        err= rna_function_parameter_parse(&funcptr, parm, type, ftype, len, arg, retdata, srna, tid, fid, pid);
 
5480
                                        StructRNA *srna = va_arg(args, StructRNA*);
 
5481
                                        ListBase **arg = va_arg(args, ListBase**);
 
5482
                                        err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, arg, retdata,
 
5483
                                                                           srna, tid, fid, pid);
4400
5484
                                        break;
4401
 
                                }                       
 
5485
                                }
4402
5486
                        default:
4403
5487
                                {
4404
5488
                                        /* handle errors */
4405
 
                                        err= rna_function_parameter_parse(&funcptr, parm, type, ftype, len, NULL, NULL, NULL, tid, fid, pid);
 
5489
                                        err = rna_function_parameter_parse(&funcptr, parm, type, ftype, len, NULL, NULL,
 
5490
                                                                           NULL, tid, fid, pid);
4406
5491
                                        break;
4407
5492
                                }
4408
5493
                        }
4415
5500
        return err;
4416
5501
}
4417
5502
 
4418
 
int RNA_function_call_direct_va_lookup(bContext *C, ReportList *reports, PointerRNA *ptr, const char *identifier, const char *format, va_list args)
 
5503
int RNA_function_call_direct_va_lookup(bContext *C, ReportList *reports, PointerRNA *ptr,
 
5504
                                       const char *identifier, const char *format, va_list args)
4419
5505
{
4420
5506
        FunctionRNA *func;
4421
5507
 
4422
 
        func= RNA_struct_find_function(ptr, identifier);
 
5508
        func = RNA_struct_find_function(ptr, identifier);
4423
5509
 
4424
 
        if(func)
 
5510
        if (func)
4425
5511
                return RNA_function_call_direct_va(C, reports, ptr, func, format, args);
4426
5512
 
4427
5513
        return 0;
4432
5518
        int len;
4433
5519
 
4434
5520
        /* get the length of the array to work with */
4435
 
        len= RNA_property_array_length(ptr, prop);
 
5521
        len = RNA_property_array_length(ptr, prop);
4436
5522
        
4437
5523
        /* get and set the default values as appropriate for the various types */
4438
5524
        switch (RNA_property_type(prop)) {
4439
5525
                case PROP_BOOLEAN:
4440
5526
                        if (len) {
4441
5527
                                if (index == -1) {
4442
 
                                        int *tmparray= MEM_callocN(sizeof(int)*len, "reset_defaults - boolean");
 
5528
                                        int *tmparray = MEM_callocN(sizeof(int)*len, "reset_defaults - boolean");
4443
5529
                                        
4444
5530
                                        RNA_property_boolean_get_default_array(ptr, prop, tmparray);
4445
5531
                                        RNA_property_boolean_set_array(ptr, prop, tmparray);
4447
5533
                                        MEM_freeN(tmparray);
4448
5534
                                }
4449
5535
                                else {
4450
 
                                        int value= RNA_property_boolean_get_default_index(ptr, prop, index);
 
5536
                                        int value = RNA_property_boolean_get_default_index(ptr, prop, index);
4451
5537
                                        RNA_property_boolean_set_index(ptr, prop, index, value);
4452
5538
                                }
4453
5539
                        }
4454
5540
                        else {
4455
 
                                int value= RNA_property_boolean_get_default(ptr, prop);
 
5541
                                int value = RNA_property_boolean_get_default(ptr, prop);
4456
5542
                                RNA_property_boolean_set(ptr, prop, value);
4457
5543
                        }
4458
5544
                        return 1;
4459
5545
                case PROP_INT:
4460
5546
                        if (len) {
4461
5547
                                if (index == -1) {
4462
 
                                        int *tmparray= MEM_callocN(sizeof(int)*len, "reset_defaults - int");
 
5548
                                        int *tmparray = MEM_callocN(sizeof(int)*len, "reset_defaults - int");
4463
5549
                                        
4464
5550
                                        RNA_property_int_get_default_array(ptr, prop, tmparray);
4465
5551
                                        RNA_property_int_set_array(ptr, prop, tmparray);
4467
5553
                                        MEM_freeN(tmparray);
4468
5554
                                }
4469
5555
                                else {
4470
 
                                        int value= RNA_property_int_get_default_index(ptr, prop, index);
 
5556
                                        int value = RNA_property_int_get_default_index(ptr, prop, index);
4471
5557
                                        RNA_property_int_set_index(ptr, prop, index, value);
4472
5558
                                }
4473
5559
                        }
4474
5560
                        else {
4475
 
                                int value= RNA_property_int_get_default(ptr, prop);
 
5561
                                int value = RNA_property_int_get_default(ptr, prop);
4476
5562
                                RNA_property_int_set(ptr, prop, value);
4477
5563
                        }
4478
5564
                        return 1;
4479
5565
                case PROP_FLOAT:
4480
5566
                        if (len) {
4481
5567
                                if (index == -1) {
4482
 
                                        float *tmparray= MEM_callocN(sizeof(float)*len, "reset_defaults - float");
 
5568
                                        float *tmparray = MEM_callocN(sizeof(float)*len, "reset_defaults - float");
4483
5569
                                        
4484
5570
                                        RNA_property_float_get_default_array(ptr, prop, tmparray);
4485
5571
                                        RNA_property_float_set_array(ptr, prop, tmparray);
4487
5573
                                        MEM_freeN(tmparray);
4488
5574
                                }
4489
5575
                                else {
4490
 
                                        float value= RNA_property_float_get_default_index(ptr, prop, index);
 
5576
                                        float value = RNA_property_float_get_default_index(ptr, prop, index);
4491
5577
                                        RNA_property_float_set_index(ptr, prop, index, value);
4492
5578
                                }
4493
5579
                        }
4494
5580
                        else {
4495
 
                                float value= RNA_property_float_get_default(ptr, prop);
 
5581
                                float value = RNA_property_float_get_default(ptr, prop);
4496
5582
                                RNA_property_float_set(ptr, prop, value);
4497
5583
                        }
4498
5584
                        return 1;
4499
5585
                case PROP_ENUM:
4500
5586
                {
4501
 
                        int value= RNA_property_enum_get_default(ptr, prop);
 
5587
                        int value = RNA_property_enum_get_default(ptr, prop);
4502
5588
                        RNA_property_enum_set(ptr, prop, value);
4503
5589
                        return 1;
4504
5590
                }
4505
5591
                
4506
5592
                case PROP_STRING:
4507
5593
                {
4508
 
                        char *value= RNA_property_string_get_default_alloc(ptr, prop, NULL, 0);
 
5594
                        char *value = RNA_property_string_get_default_alloc(ptr, prop, NULL, 0);
4509
5595
                        RNA_property_string_set(ptr, prop, value);
4510
5596
                        MEM_freeN(value);
4511
5597
                        return 1;
4512
5598
                }
4513
5599
                
4514
 
                //case PROP_POINTER:
4515
 
                default: 
4516
 
                        // FIXME: many of the other types such as strings and pointers need this implemented too!
 
5600
                case PROP_POINTER:
 
5601
                {
 
5602
                        PointerRNA value = RNA_property_pointer_get_default(ptr, prop);
 
5603
                        RNA_property_pointer_set(ptr, prop, value);
 
5604
                        return 1;
 
5605
                }
 
5606
                
 
5607
                default:
 
5608
                        /* FIXME: are there still any cases that haven't been handled? comment out "default" block to check :) */
4517
5609
                        return 0;
4518
5610
        }
4519
5611
}
4523
5615
        int len, fromlen;
4524
5616
 
4525
5617
        /* get the length of the array to work with */
4526
 
        len= RNA_property_array_length(ptr, prop);
4527
 
        fromlen= RNA_property_array_length(ptr, prop);
 
5618
        len = RNA_property_array_length(ptr, prop);
 
5619
        fromlen = RNA_property_array_length(ptr, prop);
4528
5620
 
4529
 
        if(len != fromlen)
 
5621
        if (len != fromlen)
4530
5622
                return 0;
4531
5623
        
4532
5624
        /* get and set the default values as appropriate for the various types */
4534
5626
                case PROP_BOOLEAN:
4535
5627
                        if (len) {
4536
5628
                                if (index == -1) {
4537
 
                                        int *tmparray= MEM_callocN(sizeof(int)*len, "copy - boolean");
 
5629
                                        int *tmparray = MEM_callocN(sizeof(int)*len, "copy - boolean");
4538
5630
                                        
4539
5631
                                        RNA_property_boolean_get_array(fromptr, prop, tmparray);
4540
5632
                                        RNA_property_boolean_set_array(ptr, prop, tmparray);
4542
5634
                                        MEM_freeN(tmparray);
4543
5635
                                }
4544
5636
                                else {
4545
 
                                        int value= RNA_property_boolean_get_index(fromptr, prop, index);
 
5637
                                        int value = RNA_property_boolean_get_index(fromptr, prop, index);
4546
5638
                                        RNA_property_boolean_set_index(ptr, prop, index, value);
4547
5639
                                }
4548
5640
                        }
4549
5641
                        else {
4550
 
                                int value= RNA_property_boolean_get(fromptr, prop);
 
5642
                                int value = RNA_property_boolean_get(fromptr, prop);
4551
5643
                                RNA_property_boolean_set(ptr, prop, value);
4552
5644
                        }
4553
5645
                        return 1;
4554
5646
                case PROP_INT:
4555
5647
                        if (len) {
4556
5648
                                if (index == -1) {
4557
 
                                        int *tmparray= MEM_callocN(sizeof(int)*len, "copy - int");
 
5649
                                        int *tmparray = MEM_callocN(sizeof(int)*len, "copy - int");
4558
5650
                                        
4559
5651
                                        RNA_property_int_get_array(fromptr, prop, tmparray);
4560
5652
                                        RNA_property_int_set_array(ptr, prop, tmparray);
4562
5654
                                        MEM_freeN(tmparray);
4563
5655
                                }
4564
5656
                                else {
4565
 
                                        int value= RNA_property_int_get_index(fromptr, prop, index);
 
5657
                                        int value = RNA_property_int_get_index(fromptr, prop, index);
4566
5658
                                        RNA_property_int_set_index(ptr, prop, index, value);
4567
5659
                                }
4568
5660
                        }
4569
5661
                        else {
4570
 
                                int value= RNA_property_int_get(fromptr, prop);
 
5662
                                int value = RNA_property_int_get(fromptr, prop);
4571
5663
                                RNA_property_int_set(ptr, prop, value);
4572
5664
                        }
4573
5665
                        return 1;
4574
5666
                case PROP_FLOAT:
4575
5667
                        if (len) {
4576
5668
                                if (index == -1) {
4577
 
                                        float *tmparray= MEM_callocN(sizeof(float)*len, "copy - float");
 
5669
                                        float *tmparray = MEM_callocN(sizeof(float)*len, "copy - float");
4578
5670
                                        
4579
5671
                                        RNA_property_float_get_array(fromptr, prop, tmparray);
4580
5672
                                        RNA_property_float_set_array(ptr, prop, tmparray);
4582
5674
                                        MEM_freeN(tmparray);
4583
5675
                                }
4584
5676
                                else {
4585
 
                                        float value= RNA_property_float_get_index(fromptr, prop, index);
 
5677
                                        float value = RNA_property_float_get_index(fromptr, prop, index);
4586
5678
                                        RNA_property_float_set_index(ptr, prop, index, value);
4587
5679
                                }
4588
5680
                        }
4589
5681
                        else {
4590
 
                                float value= RNA_property_float_get(fromptr, prop);
 
5682
                                float value = RNA_property_float_get(fromptr, prop);
4591
5683
                                RNA_property_float_set(ptr, prop, value);
4592
5684
                        }
4593
5685
                        return 1;
4594
5686
                case PROP_ENUM:
4595
5687
                {
4596
 
                        int value= RNA_property_enum_get(fromptr, prop);
 
5688
                        int value = RNA_property_enum_get(fromptr, prop);
4597
5689
                        RNA_property_enum_set(ptr, prop, value);
4598
5690
                        return 1;
4599
5691
                }
4600
5692
                case PROP_POINTER:
4601
5693
                {
4602
 
                        PointerRNA value= RNA_property_pointer_get(fromptr, prop);
 
5694
                        PointerRNA value = RNA_property_pointer_get(fromptr, prop);
4603
5695
                        RNA_property_pointer_set(ptr, prop, value);
4604
5696
                        return 1;
4605
5697
                }
4606
5698
                case PROP_STRING:
4607
5699
                {
4608
 
                        char *value= RNA_property_string_get_alloc(fromptr, prop, NULL, 0);
 
5700
                        char *value = RNA_property_string_get_alloc(fromptr, prop, NULL, 0, NULL);
4609
5701
                        RNA_property_string_set(ptr, prop, value);
4610
5702
                        MEM_freeN(value);
4611
5703
                        return 1;
4617
5709
        return 0;
4618
5710
}
4619
5711
 
 
5712
/* use RNA_warning macro which includes __func__ suffix */
 
5713
void _RNA_warning(const char *format, ...)
 
5714
{
 
5715
        va_list args;
 
5716
 
 
5717
        va_start(args, format);
 
5718
        vprintf(format, args);
 
5719
        va_end(args);
 
5720
 
 
5721
        /* gcc macro adds '\n', but cant use for other compilers */
 
5722
#ifndef __GNUC__
 
5723
        fputc('\n', stdout);
 
5724
#endif
 
5725
 
 
5726
#ifdef WITH_PYTHON
 
5727
        {
 
5728
                extern void PyC_LineSpit(void);
 
5729
                PyC_LineSpit();
 
5730
        }
 
5731
#endif
 
5732
}