RNA
* RNA_struct_name_get_alloc function to get the name from a pointer, instead of having to deal with name property. * CTX_data_pointer_get_type to get data from context with a check for the RNA type.
This commit is contained in:
@@ -131,6 +131,7 @@ void CTX_wm_menu_set(bContext *C, struct ARegion *menu);
|
||||
- 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);
|
||||
|
||||
@@ -365,15 +365,20 @@ PointerRNA CTX_data_pointer_get(const bContext *C, const char *member)
|
||||
{
|
||||
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)
|
||||
|
||||
@@ -1282,17 +1282,13 @@ void ui_get_but_string(uiBut *but, char *str, int maxlen)
|
||||
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);
|
||||
@@ -1375,7 +1371,7 @@ static void ui_rna_ID_autocomplete(bContext *C, char *str, void *arg_but)
|
||||
AutoComplete *autocpl;
|
||||
CollectionPropertyIterator iter;
|
||||
PointerRNA ptr;
|
||||
PropertyRNA *prop, *nameprop;
|
||||
PropertyRNA *prop;
|
||||
char *name;
|
||||
|
||||
if(str[0]==0) return;
|
||||
@@ -1389,14 +1385,12 @@ static void ui_rna_ID_autocomplete(bContext *C, char *str, void *arg_but)
|
||||
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -668,7 +668,6 @@ void buttons_context_draw(const bContext *C, uiLayout *layout)
|
||||
uiBlock *block;
|
||||
uiBut *but;
|
||||
PointerRNA *ptr;
|
||||
PropertyRNA *nameprop;
|
||||
char namebuf[128], *name;
|
||||
int a, icon;
|
||||
|
||||
@@ -688,7 +687,7 @@ void buttons_context_draw(const bContext *C, uiLayout *layout)
|
||||
|
||||
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) {
|
||||
@@ -696,9 +695,7 @@ void buttons_context_draw(const bContext *C, uiLayout *layout)
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if(nameprop) {
|
||||
name= RNA_property_string_get_alloc(ptr, nameprop, namebuf, sizeof(namebuf));
|
||||
|
||||
if(name) {
|
||||
uiItemL(row, name, icon);
|
||||
|
||||
if(name != namebuf)
|
||||
|
||||
@@ -1031,7 +1031,7 @@ static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *i
|
||||
}
|
||||
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;
|
||||
@@ -1043,12 +1043,10 @@ static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *i
|
||||
}
|
||||
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);
|
||||
|
||||
@@ -3075,7 +3073,7 @@ static void tree_element_to_path(SpaceOops *soops, TreeElement *te, TreeStoreEle
|
||||
TreeElement *tem, *temnext, *temsub;
|
||||
TreeStoreElem *tse, *tsenext;
|
||||
PointerRNA *ptr, *nextptr;
|
||||
PropertyRNA *prop, *nameprop;
|
||||
PropertyRNA *prop;
|
||||
char *newpath=NULL;
|
||||
|
||||
/* optimise tricks:
|
||||
@@ -3119,17 +3117,16 @@ static void tree_element_to_path(SpaceOops *soops, TreeElement *te, TreeStoreEle
|
||||
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)
|
||||
|
||||
@@ -514,6 +514,8 @@ const struct ListBase *RNA_struct_defined_properties(StructRNA *srna);
|
||||
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
|
||||
|
||||
@@ -518,6 +518,16 @@ void RNA_struct_blender_type_set(StructRNA *srna, void *blender_type)
|
||||
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)
|
||||
@@ -658,7 +668,6 @@ void RNA_property_enum_items(PointerRNA *ptr, PropertyRNA *prop, const EnumPrope
|
||||
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);
|
||||
|
||||
|
||||
@@ -161,14 +161,15 @@ static PyObject *pyrna_prop_richcmp(BPy_PropertyRNA * a, BPy_PropertyRNA * b, in
|
||||
/*----------------------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));
|
||||
@@ -176,20 +177,19 @@ static PyObject *pyrna_struct_repr( BPy_StructRNA * self )
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,7 +218,6 @@ static void pyrna_struct_dealloc( BPy_StructRNA * self )
|
||||
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);
|
||||
@@ -971,21 +970,20 @@ static PyObject *pyrna_struct_dir(BPy_StructRNA * self)
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
@@ -1132,7 +1130,9 @@ PyObject *pyrna_prop_keys(BPy_PropertyRNA *self)
|
||||
|
||||
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 */
|
||||
@@ -1141,7 +1141,7 @@ PyObject *pyrna_prop_keys(BPy_PropertyRNA *self)
|
||||
Py_DECREF(item);
|
||||
/* done */
|
||||
|
||||
if ((char *)&name != nameptr)
|
||||
if(name != nameptr)
|
||||
MEM_freeN(nameptr);
|
||||
}
|
||||
}
|
||||
@@ -1160,7 +1160,6 @@ PyObject *pyrna_prop_items(BPy_PropertyRNA *self)
|
||||
} else {
|
||||
PyObject *item;
|
||||
CollectionPropertyIterator iter;
|
||||
PropertyRNA *nameprop;
|
||||
char name[256], *nameptr;
|
||||
int i= 0;
|
||||
|
||||
@@ -1171,10 +1170,10 @@ PyObject *pyrna_prop_items(BPy_PropertyRNA *self)
|
||||
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 {
|
||||
@@ -1205,10 +1204,8 @@ PyObject *pyrna_prop_values(BPy_PropertyRNA *self)
|
||||
} 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);
|
||||
|
||||
Reference in New Issue
Block a user