Commit: 3ba28a2609dd97c658e815c3a89be69b63ef20f9
Author: Campbell Barton
Date:   Mon Aug 25 23:53:34 2014 +1000
Branches: master
https://developer.blender.org/rB3ba28a2609dd97c658e815c3a89be69b63ef20f9

Python API: support thick wrapped int arrays

add bpy.data.version, needed for Python versioning code.

===================================================================

M       source/blender/makesrna/intern/rna_main.c
M       source/blender/python/intern/bpy_rna.c

===================================================================

diff --git a/source/blender/makesrna/intern/rna_main.c 
b/source/blender/makesrna/intern/rna_main.c
index f163808..65d8135 100644
--- a/source/blender/makesrna/intern/rna_main.c
+++ b/source/blender/makesrna/intern/rna_main.c
@@ -281,6 +281,14 @@ static void 
rna_Main_linestyle_begin(CollectionPropertyIterator *iter, PointerRN
        rna_iterator_listbase_begin(iter, &bmain->linestyle, NULL);
 }
 
+static void rna_Main_version_get(PointerRNA *ptr, int *value)
+{
+       Main *bmain = (Main *)ptr->data;
+       value[0] = bmain->versionfile / 100;
+       value[1] = bmain->versionfile % 100;
+       value[2] = bmain->subversionfile;
+}
+
 #ifdef UNIT_TEST
 
 static PointerRNA rna_Test_test_get(PointerRNA *ptr)
@@ -376,6 +384,12 @@ void RNA_def_main(BlenderRNA *brna)
        RNA_def_property_boolean_funcs(prop, "rna_Main_use_autopack_get", 
"rna_Main_use_autopack_set");
        RNA_def_property_ui_text(prop, "Use Autopack", "Automatically pack all 
external data into .blend file");
 
+       prop = RNA_def_int_vector(srna, "version", 3, NULL, 0, INT_MAX,
+                          "Version", "Version of the blender the .blend was 
saved with", 0, INT_MAX);
+       RNA_def_property_int_funcs(prop, "rna_Main_version_get", NULL, NULL);
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+       RNA_def_property_flag(prop, PROP_THICK_WRAP);
+
        for (i = 0; lists[i].name; i++) {
                prop = RNA_def_property(srna, lists[i].identifier, 
PROP_COLLECTION, PROP_NONE);
                RNA_def_property_struct_type(prop, lists[i].type);
diff --git a/source/blender/python/intern/bpy_rna.c 
b/source/blender/python/intern/bpy_rna.c
index 3fdc364..a24f73c 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -604,18 +604,34 @@ PyObject *pyrna_math_object_from_array(PointerRNA *ptr, 
PropertyRNA *prop)
 #ifdef USE_MATHUTILS
        int subtype, totdim;
        int len;
-       bool is_thick;
        const int flag = RNA_property_flag(prop);
+       const int type = RNA_property_type(prop);
+       const bool is_thick = (flag & PROP_THICK_WRAP) != 0;
 
        /* disallow dynamic sized arrays to be wrapped since the size could 
change
         * to a size mathutils does not support */
-       if ((RNA_property_type(prop) != PROP_FLOAT) || (flag & PROP_DYNAMIC))
+       if (flag & PROP_DYNAMIC) {
                return NULL;
+       }
 
        len = RNA_property_array_length(ptr, prop);
+       if (type == PROP_FLOAT) {
+               /* pass */
+       }
+       else if (type == PROP_INT) {
+               if (is_thick) {
+                       goto thick_wrap_slice;
+               }
+               else {
+                       return NULL;
+               }
+       }
+       else {
+               return NULL;
+       }
+
        subtype = RNA_property_subtype(prop);
        totdim = RNA_property_array_dimension(ptr, prop, NULL);
-       is_thick = (flag & PROP_THICK_WRAP) != 0;
 
        if (totdim == 1 || (totdim == 2 && subtype == PROP_MATRIX)) {
                if (!is_thick)
@@ -712,6 +728,7 @@ PyObject *pyrna_math_object_from_array(PointerRNA *ptr, 
PropertyRNA *prop)
                if (is_thick) {
                        /* this is an array we cant reference (since its not 
thin wrappable)
                         * and cannot be coerced into a mathutils type, so 
return as a list */
+thick_wrap_slice:
                        ret = pyrna_prop_array_subscript_slice(NULL, ptr, prop, 
0, len, len);
                }
                else {
@@ -2312,12 +2329,11 @@ static PyObject 
*pyrna_prop_array_subscript_slice(BPy_PropertyArrayRNA *self, Po
        int count, totdim;
        PyObject *tuple;
 
-       PYRNA_PROP_CHECK_OBJ((BPy_PropertyRNA *)self);
+       /* isn't needed, internal use only */
+       // PYRNA_PROP_CHECK_OBJ((BPy_PropertyRNA *)self);
 
        tuple = PyTuple_New(stop - start);
 
-       /* PYRNA_PROP_CHECK_OBJ(self); isn't needed, internal use only */
-
        totdim = RNA_property_array_dimension(ptr, prop, NULL);
 
        if (totdim > 1) {

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to