Revision: 21499
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21499
Author:   campbellbarton
Date:     2009-07-10 20:09:53 +0200 (Fri, 10 Jul 2009)

Log Message:
-----------
Use python subtypes so bpy.types.Mesh is a subtype of bpy.types.ID

This means checks like this work.
 isinstance(bpy.data.meshes[0], bpy.types.ID)
 
 bpy.types.Mesh.__base__ == bpy.types.ID
 

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/python/generic/Mathutils.h
    branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c

Modified: branches/blender2.5/blender/source/blender/python/generic/Mathutils.h
===================================================================
--- branches/blender2.5/blender/source/blender/python/generic/Mathutils.h       
2009-07-10 17:41:49 UTC (rev 21498)
+++ branches/blender2.5/blender/source/blender/python/generic/Mathutils.h       
2009-07-10 18:09:53 UTC (rev 21499)
@@ -85,6 +85,13 @@
 #endif
 
 typedef struct Mathutils_Callback Mathutils_Callback;
+
+typedef int (*BaseMathCheckFunc)(PyObject *);
+typedef int (*BaseMathGetFunc)(PyObject *, int, float *);
+typedef int (*BaseMathSetFunc)(PyObject *, int, float *);
+typedef int (*BaseMathGetIndexFunc)(PyObject *, int, float *, int);
+typedef int (*BaseMathSetIndexFunc)(PyObject *, int, float *, int);
+
 struct Mathutils_Callback {
        int             (*check)(PyObject *user);                               
        /* checks the user is still valid */
        int             (*get)(PyObject *user, int subtype, float *from);       
/* gets the vector from the user */

Modified: branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c  
2009-07-10 17:41:49 UTC (rev 21498)
+++ branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c  
2009-07-10 18:09:53 UTC (rev 21499)
@@ -94,13 +94,14 @@
 }
 
 Mathutils_Callback mathutils_rna_array_cb = {
-       mathutils_rna_generic_check,
-       mathutils_rna_vector_get,
-       mathutils_rna_vector_set,
-       mathutils_rna_vector_get_index,
-       mathutils_rna_vector_set_index
+       (BaseMathCheckFunc)             mathutils_rna_generic_check,
+       (BaseMathGetFunc)               mathutils_rna_vector_get,
+       (BaseMathSetFunc)               mathutils_rna_vector_set,
+       (BaseMathGetIndexFunc)  mathutils_rna_vector_get_index,
+       (BaseMathSetIndexFunc)  mathutils_rna_vector_set_index
 };
 
+
 /* bpyrna matrix callbacks */
 static int mathutils_rna_matrix_cb_index= -1; /* index for our callbacks */
 
@@ -123,11 +124,11 @@
 }
 
 Mathutils_Callback mathutils_rna_matrix_cb = {
-       mathutils_rna_generic_check,
-       mathutils_rna_matrix_get,
-       mathutils_rna_matrix_set,
-       NULL,
-       NULL
+       (BaseMathCheckFunc)             mathutils_rna_generic_check,
+       (BaseMathGetFunc)               mathutils_rna_matrix_get,
+       (BaseMathSetFunc)               mathutils_rna_matrix_set,
+       (BaseMathGetIndexFunc)  NULL,
+       (BaseMathSetIndexFunc)  NULL
 };
 
 #endif
@@ -2172,21 +2173,17 @@
        /* done with rna instance */
 }
 
-PyObject* pyrna_struct_Subtype(PointerRNA *ptr)
+PyObject* pyrna_srna_Subtype(StructRNA *srna)
 {
        PyObject *newclass = NULL;
-       StructRNA *srna, *base;
-       
-       if(ptr->type == &RNA_Struct)
-               srna= ptr->data;
-       else
-               srna= ptr->type;
 
        if (srna == NULL) {
                newclass= NULL; /* Nothing to do */
        } else if ((newclass= RNA_struct_py_type_get(srna))) {
                Py_INCREF(newclass);
        } else {
+               StructRNA *base;
+               
                /* for now, return the base RNA type rather then a real module 
*/
                
                /* Assume RNA_struct_py_type_get(srna) was alredy checked */
@@ -2203,22 +2200,21 @@
                PyObject *py_base= NULL;
                PyObject *dict = PyDict_New();
                PyObject *item;
+       
                
-               
                // arg 1
                //PyTuple_SET_ITEM(args, 0, PyUnicode_FromString(tp_name));
                PyTuple_SET_ITEM(args, 0, 
PyUnicode_FromString(RNA_struct_identifier(srna)));
                
                // arg 2
-#if 0  // XXX - This should be possible but for some reason it does a 
recursive call for MirrorModifier
                base= RNA_struct_base(srna);
                if(base && base != srna) {
-                       // printf("debug subtype %s\n", 
RNA_struct_identifier(srna));
-                       py_base= pyrna_struct_Subtype(base);
+                       /*/printf("debug subtype %s %p\n", 
RNA_struct_identifier(srna), srna); */
+                       py_base= pyrna_srna_Subtype(base);
                }
-#endif
+               
                if(py_base==NULL) {
-                       py_base= &pyrna_struct_Type;
+                       py_base= (PyObject *)&pyrna_struct_Type;
                        Py_INCREF(py_base);
                }
                
@@ -2264,6 +2260,11 @@
        return newclass;
 }
 
+PyObject* pyrna_struct_Subtype(PointerRNA *ptr)
+{
+       return pyrna_srna_Subtype((ptr->type == &RNA_Struct) ? ptr->data : 
ptr->type);
+}
+
 /*-----------------------CreatePyObject---------------------------------*/
 PyObject *pyrna_struct_CreatePyObject( PointerRNA *ptr )
 {


_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to