Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2008-11-21 22:14:38 +0300
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2008-11-21 22:14:38 +0300
commitc6da2a59d88a75d00890de5ae1d79408e7f9f906 (patch)
tree13491555b978c1ec3e6b99caeceaebb7bbbe28ed /source/blender/makesrna
parent129585285c47a016cf93fb183117eb86ce544461 (diff)
RNA
* Added RNA for operators. This still uses ID properties internally, but through the RNA API now. The OP_get/set_* API that was used is replaced by the RNA API. Currently RNA properties for operators are defined at runtime since it means operator registration can be done in a single function. * Changed the existing operators to use this system, I haven't defined user interface names yet though. I also think there need to be some conventions on which properties to expose to make these operators usable in macros, for example if mouse coordinates should be stored or not. * When using ID properties through defined RNA properties, it now checks that the ID property actually matches the RNA property and removes/overwrites it otherwise. This ensures that you can safely get/set arrays for example without having to worry that some external thing may have changed the length. * Documentation now has some information on RNA + ID properties. http://wiki.blender.org/index.php/BlenderDev/Blender2.5/RNA
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r--source/blender/makesrna/intern/rna_access.c59
1 files changed, 57 insertions, 2 deletions
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index d16a085b0be..86616616f98 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -31,6 +31,7 @@
#include "BLI_dynstr.h"
#include "BKE_idprop.h"
+#include "BKE_utildefines.h"
#include "DNA_ID.h"
#include "DNA_windowmanager_types.h"
@@ -107,6 +108,48 @@ static IDProperty *rna_idproperty_find(PointerRNA *ptr, const char *name)
return NULL;
}
+static int rna_idproperty_verify_valid(PropertyRNA *prop, IDProperty *idprop)
+{
+ /* this verifies if the idproperty actually matches the property
+ * description and otherwise removes it. this is to ensure that
+ * rna property access is type safe, e.g. if you defined the rna
+ * to have a certain array length you can count on that staying so */
+
+ switch(idprop->type) {
+ case IDP_ARRAY:
+ if(prop->arraylength != idprop->len)
+ return 0;
+
+ if(idprop->subtype == IDP_FLOAT && prop->type != PROP_FLOAT)
+ return 0;
+ if(idprop->subtype == IDP_INT && !ELEM3(prop->type, PROP_BOOLEAN, PROP_INT, PROP_ENUM))
+ return 0;
+
+ break;
+ case IDP_INT:
+ if(!ELEM3(prop->type, PROP_BOOLEAN, PROP_INT, PROP_ENUM))
+ return 0;
+ break;
+ case IDP_FLOAT:
+ case IDP_DOUBLE:
+ if(prop->type != PROP_FLOAT)
+ return 0;
+ break;
+ case IDP_STRING:
+ if(prop->type != PROP_STRING)
+ return 0;
+ break;
+ case IDP_GROUP:
+ if(prop->type != PROP_POINTER)
+ return 0;
+ break;
+ default:
+ return 0;
+ }
+
+ return 1;
+}
+
IDProperty *rna_idproperty_check(PropertyRNA **prop, PointerRNA *ptr)
{
/* This is quite a hack, but avoids some complexity in the API. we
@@ -117,8 +160,20 @@ IDProperty *rna_idproperty_check(PropertyRNA **prop, PointerRNA *ptr)
* pointer to the IDProperty. */
if((*prop)->magic == RNA_MAGIC) {
- if((*prop)->flag & PROP_IDPROPERTY)
- return rna_idproperty_find(ptr, (*prop)->identifier);
+ if((*prop)->flag & PROP_IDPROPERTY) {
+ IDProperty *idprop= rna_idproperty_find(ptr, (*prop)->identifier);
+
+ if(idprop && !rna_idproperty_verify_valid(*prop, idprop)) {
+ IDProperty *group= rna_idproperties_get(ptr->type, ptr->data, 0);
+
+ IDP_RemFromGroup(group, idprop);
+ IDP_FreeProperty(idprop);
+ MEM_freeN(idprop);
+ return NULL;
+ }
+
+ return idprop;
+ }
else
return NULL;
}