- the dir listbase consits of LinkData items */
PointerRNA CTX_data_pointer_get(const bContext *C, const char *member);
+PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type);
ListBase CTX_data_collection_get(const bContext *C, const char *member);
ListBase CTX_data_dir_get(const bContext *C);
void CTX_data_get(const bContext *C, const char *member, PointerRNA *r_ptr, ListBase *r_lb);
{
bContextDataResult result;
- if(ctx_data_get((bContext*)C, member, &result)) {
+ if(ctx_data_get((bContext*)C, member, &result))
return result.ptr;
- }
- else {
- PointerRNA ptr;
- memset(&ptr, 0, sizeof(ptr));
- return ptr;
- }
+ else
+ return PointerRNA_NULL;
+}
+
+PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
+{
+ PointerRNA ptr = CTX_data_pointer_get(C, member);
+ if(ptr.data && ptr.type == type)
+ return ptr;
+
+ return PointerRNA_NULL;
}
ListBase CTX_data_collection_get(const bContext *C, const char *member)
else if(type == PROP_POINTER) {
/* RNA pointer */
PointerRNA ptr= RNA_property_pointer_get(&but->rnapoin, but->rnaprop);
- PropertyRNA *nameprop;
-
- if(ptr.data && (nameprop = RNA_struct_name_property(ptr.type)))
- buf= RNA_property_string_get_alloc(&ptr, nameprop, str, maxlen);
- else
- BLI_strncpy(str, "", maxlen);
+ buf= RNA_struct_name_get_alloc(&ptr, str, maxlen);
}
- else
- BLI_strncpy(str, "", maxlen);
- if(buf && buf != str) {
+ if(!buf) {
+ BLI_strncpy(str, "", maxlen);
+ }
+ else if(buf && buf != str) {
/* string was too long, we have to truncate */
BLI_strncpy(str, buf, maxlen);
MEM_freeN(buf);
AutoComplete *autocpl;
CollectionPropertyIterator iter;
PointerRNA ptr;
- PropertyRNA *prop, *nameprop;
+ PropertyRNA *prop;
char *name;
if(str[0]==0) return;
/* loop over items in collection */
for(; iter.valid; RNA_property_collection_next(&iter)) {
- if(iter.ptr.data && (nameprop = RNA_struct_name_property(iter.ptr.type))) {
- name= RNA_property_string_get_alloc(&iter.ptr, nameprop, NULL, 0);
+ name= RNA_struct_name_get_alloc(&iter.ptr, NULL, 0);
- if(name) {
- /* test item name */
- autocomplete_do_name(autocpl, name);
- MEM_freeN(name);
- }
+ /* test item name */
+ if(name) {
+ autocomplete_do_name(autocpl, name);
+ MEM_freeN(name);
}
}
uiBlock *block;
uiBut *but;
PointerRNA *ptr;
- PropertyRNA *nameprop;
char namebuf[128], *name;
int a, icon;
if(ptr->data) {
icon= RNA_struct_ui_icon(ptr->type);
- nameprop= RNA_struct_name_property(ptr->type);
+ name= RNA_struct_name_get_alloc(ptr, namebuf, sizeof(namebuf));
#if 0
if(sbuts->mainb != BCONTEXT_SCENE && ptr->type == &RNA_Scene) {
}
else
#endif
- if(nameprop) {
- name= RNA_property_string_get_alloc(ptr, nameprop, namebuf, sizeof(namebuf));
-
+ if(name) {
uiItemL(row, name, icon);
if(name != namebuf)
}
else if(ELEM3(type, TSE_RNA_STRUCT, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM)) {
PointerRNA pptr, propptr, *ptr= (PointerRNA*)idv;
- PropertyRNA *prop, *iterprop, *nameprop;
+ PropertyRNA *prop, *iterprop;
PropertyType proptype;
PropertySubType propsubtype;
int a, tot;
}
else if(type == TSE_RNA_STRUCT) {
/* struct */
- nameprop= RNA_struct_name_property(ptr->type);
+ te->name= RNA_struct_name_get_alloc(ptr, NULL, 0);
- if(nameprop) {
- te->name= RNA_property_string_get_alloc(ptr, nameprop, NULL, 0);
+ if(te->name)
te->flag |= TE_FREE_NAME;
- }
else
te->name= (char*)RNA_struct_ui_name(ptr->type);
TreeElement *tem, *temnext, *temsub;
TreeStoreElem *tse, *tsenext;
PointerRNA *ptr, *nextptr;
- PropertyRNA *prop, *nameprop;
+ PropertyRNA *prop;
char *newpath=NULL;
/* optimise tricks:
newpath= RNA_path_append(*path, ptr, prop, 0, NULL);
}
else if(RNA_property_type(prop) == PROP_COLLECTION) {
+ char buf[128], *name;
+
temnext= (TreeElement*)(ld->next->data);
tsenext= TREESTORE(temnext);
nextptr= &temnext->rnaptr;
- nameprop= RNA_struct_name_property(nextptr->type);
+ name= RNA_struct_name_get_alloc(nextptr, buf, sizeof(buf));
- if(nameprop) {
+ if(name) {
/* if possible, use name as a key in the path */
- char buf[128], *name;
- name= RNA_property_string_get_alloc(nextptr, nameprop, buf, sizeof(buf));
-
newpath= RNA_path_append(*path, NULL, prop, 0, name);
if(name != buf)
FunctionRNA *RNA_struct_find_function(PointerRNA *ptr, const char *identifier);
const struct ListBase *RNA_struct_defined_functions(StructRNA *srna);
+char *RNA_struct_name_get_alloc(PointerRNA *ptr, char *fixedbuf, int fixedlen);
+
/* Properties
*
* Access to struct properties. All this works with RNA pointers rather than
srna->blender_type= blender_type;
}
+char *RNA_struct_name_get_alloc(PointerRNA *ptr, char *fixedbuf, int fixedlen)
+{
+ PropertyRNA *nameprop;
+
+ if(ptr->data && (nameprop = RNA_struct_name_property(ptr->type)))
+ return RNA_property_string_get_alloc(ptr, nameprop, fixedbuf, fixedlen);
+
+ return NULL;
+}
+
/* Property Information */
const char *RNA_property_identifier(PropertyRNA *prop)
int RNA_property_enum_value(PointerRNA *ptr, PropertyRNA *prop, const char *identifier, int *value)
{
const EnumPropertyItem *item;
- int i;
RNA_property_enum_items(ptr, prop, &item, NULL);
/*----------------------repr--------------------------------------------*/
static PyObject *pyrna_struct_repr( BPy_StructRNA * self )
{
- PropertyRNA *prop;
- char str[512];
+ PyObject *pyob;
+ char *name;
/* print name if available */
- prop= RNA_struct_name_property(self->ptr.type);
- if(prop) {
- RNA_property_string_get(&self->ptr, prop, str);
- return PyUnicode_FromFormat( "[BPy_StructRNA \"%s\" -> \"%s\"]", RNA_struct_identifier(self->ptr.type), str);
+ name= RNA_struct_name_get_alloc(&self->ptr, NULL, 0);
+ if(name) {
+ pyob= PyUnicode_FromFormat( "[BPy_StructRNA \"%s\" -> \"%s\"]", RNA_struct_identifier(self->ptr.type), name);
+ MEM_freeN(name);
+ return pyob;
}
return PyUnicode_FromFormat( "[BPy_StructRNA \"%s\"]", RNA_struct_identifier(self->ptr.type));
static PyObject *pyrna_prop_repr( BPy_PropertyRNA * self )
{
- PropertyRNA *prop;
+ PyObject *pyob;
PointerRNA ptr;
- char str[512];
+ char *name;
/* if a pointer, try to print name of pointer target too */
if(RNA_property_type(self->prop) == PROP_POINTER) {
ptr= RNA_property_pointer_get(&self->ptr, self->prop);
+ name= RNA_struct_name_get_alloc(&ptr, NULL, 0);
- if(ptr.data) {
- prop= RNA_struct_name_property(ptr.type);
- if(prop) {
- RNA_property_string_get(&ptr, prop, str);
- return PyUnicode_FromFormat( "[BPy_PropertyRNA \"%s\" -> \"%s\" -> \"%s\" ]", RNA_struct_identifier(self->ptr.type), RNA_property_identifier(self->prop), str);
- }
+ if(name) {
+ pyob= PyUnicode_FromFormat( "[BPy_PropertyRNA \"%s\" -> \"%s\" -> \"%s\" ]", RNA_struct_identifier(self->ptr.type), RNA_property_identifier(self->prop), name);
+ MEM_freeN(name);
+ return pyob;
}
}
static char *pyrna_enum_as_string(PointerRNA *ptr, PropertyRNA *prop)
{
const EnumPropertyItem *item;
- int totitem;
RNA_property_enum_items(ptr, prop, &item, NULL);
return (char*)BPy_enum_as_string((EnumPropertyItem*)item);
/*
* Collect RNA attributes
*/
- PropertyRNA *nameprop;
char name[256], *nameptr;
iterprop= RNA_struct_iterator_property(self->ptr.type);
RNA_property_collection_begin(&self->ptr, iterprop, &iter);
for(; iter.valid; RNA_property_collection_next(&iter)) {
- if(iter.ptr.data && (nameprop = RNA_struct_name_property(iter.ptr.type))) {
- nameptr= RNA_property_string_get_alloc(&iter.ptr, nameprop, name, sizeof(name));
-
+ nameptr= RNA_struct_name_get_alloc(&iter.ptr, name, sizeof(name));
+
+ if(nameptr) {
pystring = PyUnicode_FromString(nameptr);
PyList_Append(ret, pystring);
Py_DECREF(pystring);
- if ((char *)&name != nameptr)
+ if(name != nameptr)
MEM_freeN(nameptr);
}
}
RNA_property_collection_begin(&self->ptr, self->prop, &iter);
for(; iter.valid; RNA_property_collection_next(&iter)) {
- if(iter.ptr.data && (nameprop = RNA_struct_name_property(iter.ptr.type))) {
+ nameptr= RNA_struct_name_get_alloc(&iter.ptr, name, sizeof(name));
+
+ if(nameptr) {
nameptr= RNA_property_string_get_alloc(&iter.ptr, nameprop, name, sizeof(name));
/* add to python list */
Py_DECREF(item);
/* done */
- if ((char *)&name != nameptr)
+ if(name != nameptr)
MEM_freeN(nameptr);
}
}
} else {
PyObject *item;
CollectionPropertyIterator iter;
- PropertyRNA *nameprop;
char name[256], *nameptr;
int i= 0;
if(iter.ptr.data) {
/* add to python list */
item= PyTuple_New(2);
- if(nameprop = RNA_struct_name_property(iter.ptr.type)) {
- nameptr= RNA_property_string_get_alloc(&iter.ptr, nameprop, name, sizeof(name));
+ nameptr= RNA_struct_name_get_alloc(&iter.ptr, name, sizeof(name));
+ if(nameptr) {
PyTuple_SET_ITEM(item, 0, PyUnicode_FromString( nameptr ));
- if ((char *)&name != nameptr)
+ if(name != nameptr)
MEM_freeN(nameptr);
}
else {
} else {
PyObject *item;
CollectionPropertyIterator iter;
- PropertyRNA *iterprop;
ret = PyList_New(0);
- //iterprop= RNA_struct_iterator_property(self->ptr.type);
RNA_property_collection_begin(&self->ptr, self->prop, &iter);
for(; iter.valid; RNA_property_collection_next(&iter)) {
item = pyrna_struct_CreatePyObject(&iter.ptr);