Use python subtypes so bpy.types.Mesh is a subtype of bpy.types.ID
authorCampbell Barton <ideasman42@gmail.com>
Fri, 10 Jul 2009 18:09:53 +0000 (18:09 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 10 Jul 2009 18:09:53 +0000 (18:09 +0000)
This means checks like this work.
 isinstance(bpy.data.meshes[0], bpy.types.ID)

 bpy.types.Mesh.__base__ == bpy.types.ID

source/blender/python/generic/Mathutils.h
source/blender/python/intern/bpy_rna.c

index 6a4e28d6068e5e32d6b76b401c84284f484750b2..5bdd9d9cfe004fd15a2a922d5d542114eeed035a 100644 (file)
@@ -85,6 +85,13 @@ int EXPP_VectorsAreEqual(float *vecA, float *vecB, int size, int floatSteps);
 #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 */
index 8314a3cc89c3c288feed5048d74bd203c163c3f2..c6fbda0caef0ba5255f688090f6b6ceac153727f 100644 (file)
@@ -94,13 +94,14 @@ static int mathutils_rna_vector_set_index(BPy_PropertyRNA *self, int subtype, fl
 }
 
 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 @@ static int mathutils_rna_matrix_set(BPy_PropertyRNA *self, int subtype, float *m
 }
 
 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 @@ static void pyrna_subtype_set_rna(PyObject *newclass, StructRNA *srna)
        /* 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* pyrna_struct_Subtype(PointerRNA *ptr)
                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 @@ PyObject* pyrna_struct_Subtype(PointerRNA *ptr)
        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 )
 {