Changeset View
Changeset View
Standalone View
Standalone View
source/blender/makesrna/intern/rna_access.c
| Show First 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| StructRNA *srna; | StructRNA *srna; | ||||
| PropertyRNA *prop; | PropertyRNA *prop; | ||||
| for (srna = BLENDER_RNA.structs.first; srna; srna = srna->cont.next) { | for (srna = BLENDER_RNA.structs.first; srna; srna = srna->cont.next) { | ||||
| if (!srna->cont.prophash) { | if (!srna->cont.prophash) { | ||||
| srna->cont.prophash = BLI_ghash_str_new("RNA_init gh"); | srna->cont.prophash = BLI_ghash_str_new("RNA_init gh"); | ||||
| for (prop = srna->cont.properties.first; prop; prop = prop->next) | for (prop = srna->cont.properties.first; prop; prop = prop->next) { | ||||
| if (!(prop->flag & PROP_BUILTIN)) | if (!(prop->flag_internal & PROP_INTERN_BUILTIN)) { | ||||
| BLI_ghash_insert(srna->cont.prophash, (void *)prop->identifier, prop); | BLI_ghash_insert(srna->cont.prophash, (void *)prop->identifier, prop); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| } | |||||
| void RNA_exit(void) | void RNA_exit(void) | ||||
| { | { | ||||
| StructRNA *srna; | StructRNA *srna; | ||||
| RNA_property_update_cache_free(); | RNA_property_update_cache_free(); | ||||
| for (srna = BLENDER_RNA.structs.first; srna; srna = srna->cont.next) { | for (srna = BLENDER_RNA.structs.first; srna; srna = srna->cont.next) { | ||||
| ▲ Show 20 Lines • Show All 723 Lines • ▼ Show 20 Lines | PropertyUnit RNA_property_unit(PropertyRNA *prop) | ||||
| return RNA_SUBTYPE_UNIT(rna_ensure_property(prop)->subtype); | return RNA_SUBTYPE_UNIT(rna_ensure_property(prop)->subtype); | ||||
| } | } | ||||
| int RNA_property_flag(PropertyRNA *prop) | int RNA_property_flag(PropertyRNA *prop) | ||||
| { | { | ||||
| return rna_ensure_property(prop)->flag; | return rna_ensure_property(prop)->flag; | ||||
| } | } | ||||
| bool RNA_property_builtin(PropertyRNA *prop) | |||||
| { | |||||
| return (rna_ensure_property(prop)->flag_internal & PROP_INTERN_BUILTIN) != 0; | |||||
| } | |||||
| void *RNA_property_py_data_get(PropertyRNA *prop) | void *RNA_property_py_data_get(PropertyRNA *prop) | ||||
| { | { | ||||
| return prop->py_data; | return prop->py_data; | ||||
| } | } | ||||
| int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop) | int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop) | ||||
| { | { | ||||
| return rna_ensure_property_array_length(ptr, prop); | return rna_ensure_property_array_length(ptr, prop); | ||||
| ▲ Show 20 Lines • Show All 2,267 Lines • ▼ Show 20 Lines | else | ||||
| cprop->next(iter); | cprop->next(iter); | ||||
| } | } | ||||
| void RNA_property_collection_skip(CollectionPropertyIterator *iter, int num) | void RNA_property_collection_skip(CollectionPropertyIterator *iter, int num) | ||||
| { | { | ||||
| CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)rna_ensure_property(iter->prop); | CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)rna_ensure_property(iter->prop); | ||||
| int i; | int i; | ||||
| if (num > 1 && (iter->idprop || (cprop->property.flag & PROP_RAW_ARRAY))) { | if (num > 1 && (iter->idprop || (cprop->property.flag_internal & PROP_INTERN_RAW_ARRAY))) { | ||||
| /* fast skip for array */ | /* fast skip for array */ | ||||
| ArrayIterator *internal = &iter->internal.array; | ArrayIterator *internal = &iter->internal.array; | ||||
| if (!internal->skip) { | if (!internal->skip) { | ||||
| internal->ptr += internal->itemsize * (num - 1); | internal->ptr += internal->itemsize * (num - 1); | ||||
| iter->valid = (internal->ptr < internal->endptr); | iter->valid = (internal->ptr < internal->endptr); | ||||
| if (iter->valid) | if (iter->valid) | ||||
| RNA_property_collection_next(iter); | RNA_property_collection_next(iter); | ||||
| ▲ Show 20 Lines • Show All 325 Lines • ▼ Show 20 Lines | |||||
| int RNA_property_collection_raw_array(PointerRNA *ptr, PropertyRNA *prop, PropertyRNA *itemprop, RawArray *array) | int RNA_property_collection_raw_array(PointerRNA *ptr, PropertyRNA *prop, PropertyRNA *itemprop, RawArray *array) | ||||
| { | { | ||||
| CollectionPropertyIterator iter; | CollectionPropertyIterator iter; | ||||
| ArrayIterator *internal; | ArrayIterator *internal; | ||||
| char *arrayp; | char *arrayp; | ||||
| BLI_assert(RNA_property_type(prop) == PROP_COLLECTION); | BLI_assert(RNA_property_type(prop) == PROP_COLLECTION); | ||||
| if (!(prop->flag & PROP_RAW_ARRAY) || !(itemprop->flag & PROP_RAW_ACCESS)) | if (!(prop->flag_internal & PROP_INTERN_RAW_ARRAY) || !(itemprop->flag_internal & PROP_INTERN_RAW_ACCESS)) | ||||
| return 0; | return 0; | ||||
| RNA_property_collection_begin(ptr, prop, &iter); | RNA_property_collection_begin(ptr, prop, &iter); | ||||
| if (iter.valid) { | if (iter.valid) { | ||||
| /* get data from array iterator and item property */ | /* get data from array iterator and item property */ | ||||
| internal = &iter.internal.array; | internal = &iter.internal.array; | ||||
| arrayp = (iter.valid) ? iter.ptr.data : NULL; | arrayp = (iter.valid) ? iter.ptr.data : NULL; | ||||
| ▲ Show 20 Lines • Show All 2,104 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| const char *arg_name = NULL; | const char *arg_name = NULL; | ||||
| PropertyRNA *prop; | PropertyRNA *prop; | ||||
| DynStr *dynstr = BLI_dynstr_new(); | DynStr *dynstr = BLI_dynstr_new(); | ||||
| char *cstring, *buf; | char *cstring, *buf; | ||||
| bool first_iter = true; | bool first_iter = true; | ||||
| int flag; | int flag, flag_parameter; | ||||
| RNA_PROP_BEGIN (ptr, propptr, iterprop) | RNA_PROP_BEGIN (ptr, propptr, iterprop) | ||||
| { | { | ||||
| prop = propptr.data; | prop = propptr.data; | ||||
| flag = RNA_property_flag(prop); | flag = RNA_property_flag(prop); | ||||
| flag_parameter = RNA_parameter_flag(prop); | |||||
| if (as_function && (flag & PROP_OUTPUT)) { | if (as_function && (flag_parameter & PARM_OUTPUT)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| arg_name = RNA_property_identifier(prop); | arg_name = RNA_property_identifier(prop); | ||||
| if (STREQ(arg_name, "rna_type")) { | if (STREQ(arg_name, "rna_type")) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if ((nested_args == false) && (RNA_property_type(prop) == PROP_POINTER)) { | if ((nested_args == false) && (RNA_property_type(prop) == PROP_POINTER)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (as_function && (flag & PROP_REQUIRED)) { | if (as_function && (prop->flag_parameter & PARM_REQUIRED)) { | ||||
| /* required args don't have useful defaults */ | /* required args don't have useful defaults */ | ||||
| BLI_dynstr_appendf(dynstr, first_iter ? "%s" : ", %s", arg_name); | BLI_dynstr_appendf(dynstr, first_iter ? "%s" : ", %s", arg_name); | ||||
| first_iter = false; | first_iter = false; | ||||
| } | } | ||||
| else { | else { | ||||
| bool ok = true; | bool ok = true; | ||||
| if (all_args == true) { | if (all_args == true) { | ||||
| ▲ Show 20 Lines • Show All 304 Lines • ▼ Show 20 Lines | |||||
| const ListBase *RNA_function_defined_parameters(FunctionRNA *func) | const ListBase *RNA_function_defined_parameters(FunctionRNA *func) | ||||
| { | { | ||||
| return &func->cont.properties; | return &func->cont.properties; | ||||
| } | } | ||||
| /* Utility */ | /* Utility */ | ||||
| int RNA_parameter_flag(PropertyRNA *prop) | |||||
| { | |||||
| return (int)rna_ensure_property(prop)->flag_parameter; | |||||
| } | |||||
| ParameterList *RNA_parameter_list_create(ParameterList *parms, PointerRNA *UNUSED(ptr), FunctionRNA *func) | ParameterList *RNA_parameter_list_create(ParameterList *parms, PointerRNA *UNUSED(ptr), FunctionRNA *func) | ||||
| { | { | ||||
| PropertyRNA *parm; | PropertyRNA *parm; | ||||
| void *data; | void *data; | ||||
| int alloc_size = 0, size; | int alloc_size = 0, size; | ||||
| parms->arg_count = 0; | parms->arg_count = 0; | ||||
| parms->ret_count = 0; | parms->ret_count = 0; | ||||
| /* allocate data */ | /* allocate data */ | ||||
| for (parm = func->cont.properties.first; parm; parm = parm->next) { | for (parm = func->cont.properties.first; parm; parm = parm->next) { | ||||
| alloc_size += rna_parameter_size(parm); | alloc_size += rna_parameter_size(parm); | ||||
| if (parm->flag & PROP_OUTPUT) | if (parm->flag_parameter & PARM_OUTPUT) | ||||
| parms->ret_count++; | parms->ret_count++; | ||||
| else | else | ||||
| parms->arg_count++; | parms->arg_count++; | ||||
| } | } | ||||
| parms->data = MEM_callocN(alloc_size, "RNA_parameter_list_create"); | parms->data = MEM_callocN(alloc_size, "RNA_parameter_list_create"); | ||||
| parms->func = func; | parms->func = func; | ||||
| parms->alloc_size = alloc_size; | parms->alloc_size = alloc_size; | ||||
| /* set default values */ | /* set default values */ | ||||
| data = parms->data; | data = parms->data; | ||||
| for (parm = func->cont.properties.first; parm; parm = parm->next) { | for (parm = func->cont.properties.first; parm; parm = parm->next) { | ||||
| size = rna_parameter_size(parm); | size = rna_parameter_size(parm); | ||||
| /* set length to 0, these need to be set later, see bpy_array.c's py_to_array */ | /* set length to 0, these need to be set later, see bpy_array.c's py_to_array */ | ||||
| if (parm->flag & PROP_DYNAMIC) { | if (parm->flag & PROP_DYNAMIC) { | ||||
| ParameterDynAlloc *data_alloc = data; | ParameterDynAlloc *data_alloc = data; | ||||
| data_alloc->array_tot = 0; | data_alloc->array_tot = 0; | ||||
| data_alloc->array = NULL; | data_alloc->array = NULL; | ||||
| } | } | ||||
| if (!(parm->flag & PROP_REQUIRED) && !(parm->flag & PROP_DYNAMIC)) { | if (!(parm->flag_parameter & PARM_REQUIRED) && !(parm->flag & PROP_DYNAMIC)) { | ||||
| switch (parm->type) { | switch (parm->type) { | ||||
| case PROP_BOOLEAN: | case PROP_BOOLEAN: | ||||
| if (parm->arraydimension) memcpy(data, ((BoolPropertyRNA *)parm)->defaultarray, size); | if (parm->arraydimension) memcpy(data, ((BoolPropertyRNA *)parm)->defaultarray, size); | ||||
| else memcpy(data, &((BoolPropertyRNA *)parm)->defaultvalue, size); | else memcpy(data, &((BoolPropertyRNA *)parm)->defaultvalue, size); | ||||
| break; | break; | ||||
| case PROP_INT: | case PROP_INT: | ||||
| if (parm->arraydimension) memcpy(data, ((IntPropertyRNA *)parm)->defaultarray, size); | if (parm->arraydimension) memcpy(data, ((IntPropertyRNA *)parm)->defaultarray, size); | ||||
| else memcpy(data, &((IntPropertyRNA *)parm)->defaultvalue, size); | else memcpy(data, &((IntPropertyRNA *)parm)->defaultvalue, size); | ||||
| ▲ Show 20 Lines • Show All 407 Lines • ▼ Show 20 Lines | case PROP_POINTER: | ||||
| if (ftype != 'O') { | if (ftype != 'O') { | ||||
| fprintf(stderr, "%s.%s: wrong type for parameter %s, an object was expected\n", tid, fid, pid); | fprintf(stderr, "%s.%s: wrong type for parameter %s, an object was expected\n", tid, fid, pid); | ||||
| return -1; | return -1; | ||||
| } | } | ||||
| ptype = RNA_property_pointer_type(ptr, prop); | ptype = RNA_property_pointer_type(ptr, prop); | ||||
| if (prop->flag & PROP_RNAPTR) { | if (prop->flag_parameter & PARM_RNAPTR) { | ||||
| *((PointerRNA *)dest) = *((PointerRNA *)src); | *((PointerRNA *)dest) = *((PointerRNA *)src); | ||||
| break; | break; | ||||
| } | } | ||||
| if (ptype != srna && !RNA_struct_is_a(srna, ptype)) { | if (ptype != srna && !RNA_struct_is_a(srna, ptype)) { | ||||
| fprintf(stderr, "%s.%s: wrong type for parameter %s, " | fprintf(stderr, "%s.%s: wrong type for parameter %s, " | ||||
| "an object of type %s was expected, passed an object of type %s\n", | "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)); | tid, fid, pid, RNA_struct_identifier(ptype), RNA_struct_identifier(srna)); | ||||
| ▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | |||||
| int RNA_function_call_direct_va(bContext *C, ReportList *reports, PointerRNA *ptr, FunctionRNA *func, | int RNA_function_call_direct_va(bContext *C, ReportList *reports, PointerRNA *ptr, FunctionRNA *func, | ||||
| const char *format, va_list args) | const char *format, va_list args) | ||||
| { | { | ||||
| PointerRNA funcptr; | PointerRNA funcptr; | ||||
| ParameterList parms; | ParameterList parms; | ||||
| ParameterIterator iter; | ParameterIterator iter; | ||||
| PropertyRNA *pret, *parm; | PropertyRNA *pret, *parm; | ||||
| PropertyType type; | PropertyType type; | ||||
| int i, ofs, flen, flag, len, alen, err = 0; | int i, ofs, flen, flag_parameter, len, alen, err = 0; | ||||
| const char *tid, *fid, *pid = NULL; | const char *tid, *fid, *pid = NULL; | ||||
| char ftype; | char ftype; | ||||
| void **retdata = NULL; | void **retdata = NULL; | ||||
| RNA_pointer_create(NULL, &RNA_Function, func, &funcptr); | RNA_pointer_create(NULL, &RNA_Function, func, &funcptr); | ||||
| tid = RNA_struct_identifier(ptr->type); | tid = RNA_struct_identifier(ptr->type); | ||||
| fid = RNA_function_identifier(func); | fid = RNA_function_identifier(func); | ||||
| pret = func->c_ret; | pret = func->c_ret; | ||||
| flen = strlen(format); | flen = strlen(format); | ||||
| RNA_parameter_list_create(&parms, ptr, func); | RNA_parameter_list_create(&parms, ptr, func); | ||||
| RNA_parameter_list_begin(&parms, &iter); | RNA_parameter_list_begin(&parms, &iter); | ||||
| for (i = 0, ofs = 0; iter.valid; RNA_parameter_list_next(&iter), i++) { | for (i = 0, ofs = 0; iter.valid; RNA_parameter_list_next(&iter), i++) { | ||||
| parm = iter.parm; | parm = iter.parm; | ||||
| flag = RNA_property_flag(parm); | flag_parameter = RNA_parameter_flag(parm); | ||||
| if (parm == pret) { | if (parm == pret) { | ||||
| retdata = iter.data; | retdata = iter.data; | ||||
| continue; | continue; | ||||
| } | } | ||||
| else if (flag & PROP_OUTPUT) { | else if (flag_parameter & PARM_OUTPUT) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| pid = RNA_property_identifier(parm); | pid = RNA_property_identifier(parm); | ||||
| if (ofs >= flen || format[ofs] == 'N') { | if (ofs >= flen || format[ofs] == 'N') { | ||||
| if (flag & PROP_REQUIRED) { | if (parm->flag_parameter & PARM_REQUIRED) { | ||||
| err = -1; | err = -1; | ||||
| fprintf(stderr, "%s.%s: missing required parameter %s\n", tid, fid, pid); | fprintf(stderr, "%s.%s: missing required parameter %s\n", tid, fid, pid); | ||||
| break; | break; | ||||
| } | } | ||||
| ofs++; | ofs++; | ||||
| continue; | continue; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 580 Lines • Show Last 20 Lines | |||||