Blender V2.61 - r43446

bpy_rna.h

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * Contributor(s): Campbell Barton
00019  *
00020  * ***** END GPL LICENSE BLOCK *****
00021  */
00022 
00027 #ifndef BPY_RNA_H
00028 #define BPY_RNA_H
00029 
00030 /* --- bpy build options --- */
00031 #ifdef WITH_PYTHON_SAFETY
00032 
00033 /* play it safe and keep optional for now, need to test further now this affects looping on 10000's of verts for eg. */
00034 #define USE_WEAKREFS
00035 
00036 /* method to invalidate removed py data, XXX, slow to remove objects, otherwise no overhead */
00037 /* #define USE_PYRNA_INVALIDATE_GC */
00038 
00039 /* different method */
00040 #define USE_PYRNA_INVALIDATE_WEAKREF
00041 
00042 /* support for inter references, currently only needed for corner case */
00043 #define USE_PYRNA_STRUCT_REFERENCE
00044 
00045 #else /* WITH_PYTHON_SAFETY */
00046 
00047  /* default, no defines! */
00048 
00049 #endif /* !WITH_PYTHON_SAFETY */
00050 
00051 
00052 /* sanity checks on above defs */
00053 #if defined(USE_PYRNA_INVALIDATE_WEAKREF) && !defined(USE_WEAKREFS)
00054 #define USE_WEAKREFS
00055 #endif
00056 
00057 #if defined(USE_PYRNA_INVALIDATE_GC) && defined(USE_PYRNA_INVALIDATE_WEAKREF)
00058 #error "Only 1 reference check method at a time!"
00059 #endif
00060 
00061 /* only used by operator introspection get_rna(), this is only used for doc gen
00062  * so prefer the leak to the memory bloat for now. */
00063 // #define PYRNA_FREE_SUPPORT
00064 
00065 /* use real collection iterators rather than faking with a list
00066  * this is needed so enums can be iterated over without crashing,
00067  * since finishing the iteration frees temp allocated enums */
00068 #define USE_PYRNA_ITER
00069 
00070 /* --- end bpy build options --- */
00071 
00072 struct ID;
00073 
00074 extern PyTypeObject pyrna_struct_meta_idprop_Type;
00075 extern PyTypeObject pyrna_struct_Type;
00076 extern PyTypeObject pyrna_prop_Type;
00077 extern PyTypeObject pyrna_prop_array_Type;
00078 extern PyTypeObject pyrna_prop_collection_Type;
00079 extern PyTypeObject pyrna_func_Type;
00080 
00081 #define BPy_StructRNA_Check(v)          (PyObject_TypeCheck(v, &pyrna_struct_Type))
00082 #define BPy_StructRNA_CheckExact(v)     (Py_TYPE(v) == &pyrna_struct_Type)
00083 #define BPy_PropertyRNA_Check(v)        (PyObject_TypeCheck(v, &pyrna_prop_Type))
00084 #define BPy_PropertyRNA_CheckExact(v)   (Py_TYPE(v) == &pyrna_prop_Type)
00085 
00086 #define PYRNA_STRUCT_CHECK_OBJ(obj) if(pyrna_struct_validity_check(obj) == -1) { return NULL; }
00087 #define PYRNA_STRUCT_CHECK_INT(obj) if(pyrna_struct_validity_check(obj) == -1) { return -1; }
00088 
00089 #define PYRNA_PROP_CHECK_OBJ(obj) if(pyrna_prop_validity_check(obj) == -1) { return NULL; }
00090 #define PYRNA_PROP_CHECK_INT(obj) if(pyrna_prop_validity_check(obj) == -1) { return -1; }
00091 
00092 #define PYRNA_STRUCT_IS_VALID(pysrna) (((BPy_StructRNA *)(pysrna))->ptr.type != NULL)
00093 #define PYRNA_PROP_IS_VALID(pysrna) (((BPy_PropertyRNA *)(pysrna))->ptr.type != NULL)
00094 
00095 /* 'in_weakreflist' MUST be aligned */
00096 
00097 typedef struct {
00098     PyObject_HEAD /* required python macro   */
00099 #ifdef USE_WEAKREFS
00100     PyObject *in_weakreflist;
00101 #endif
00102     PointerRNA  ptr;
00103 } BPy_DummyPointerRNA;
00104 
00105 typedef struct {
00106     PyObject_HEAD /* required python macro   */
00107 #ifdef USE_WEAKREFS
00108     PyObject *in_weakreflist;
00109 #endif
00110     PointerRNA ptr;
00111 #ifdef USE_PYRNA_STRUCT_REFERENCE
00112     /* generic PyObject we hold a reference to, example use:
00113      * hold onto the collection iterator to prevent it from freeing allocated data we may use */
00114     PyObject *reference;
00115 #endif /* !USE_PYRNA_STRUCT_REFERENCE */
00116 
00117 #ifdef PYRNA_FREE_SUPPORT
00118     int freeptr; /* needed in some cases if ptr.data is created on the fly, free when deallocing */
00119 #endif /* PYRNA_FREE_SUPPORT */
00120 } BPy_StructRNA;
00121 
00122 typedef struct {
00123     PyObject_HEAD /* required python macro   */
00124 #ifdef USE_WEAKREFS
00125     PyObject *in_weakreflist;
00126 #endif
00127     PointerRNA ptr;
00128     PropertyRNA *prop;
00129 } BPy_PropertyRNA;
00130 
00131 typedef struct {
00132     PyObject_HEAD /* required python macro   */
00133 #ifdef USE_WEAKREFS
00134     PyObject *in_weakreflist;
00135 #endif
00136     PointerRNA ptr;
00137     PropertyRNA *prop;
00138 
00139     /* Arystan: this is a hack to allow sub-item r/w access like: face.uv[n][m] */
00140     int arraydim; /* array dimension, e.g: 0 for face.uv, 2 for face.uv[n][m], etc. */
00141     int arrayoffset; /* array first item offset, e.g. if face.uv is [4][2], arrayoffset for face.uv[n] is 2n */
00142 } BPy_PropertyArrayRNA;
00143 
00144 typedef struct {
00145     PyObject_HEAD /* required python macro   */
00146 #ifdef USE_WEAKREFS
00147     PyObject *in_weakreflist;
00148 #endif
00149 
00150     /* collection iterator specific parts */
00151     CollectionPropertyIterator iter;
00152 } BPy_PropertyCollectionIterRNA;
00153 
00154 typedef struct {
00155     PyObject_HEAD /* required python macro   */
00156 #ifdef USE_WEAKREFS
00157     PyObject *in_weakreflist;
00158 #endif
00159     PointerRNA ptr;
00160     FunctionRNA *func;
00161 } BPy_FunctionRNA;
00162 
00163 /* cheap trick */
00164 #define BPy_BaseTypeRNA BPy_PropertyRNA
00165 
00166 StructRNA *srna_from_self(PyObject *self, const char *error_prefix);
00167 StructRNA *pyrna_struct_as_srna(PyObject *self, int parent, const char *error_prefix);
00168 
00169 void      BPY_rna_init(void);
00170 PyObject *BPY_rna_module(void);
00171 void      BPY_update_rna_module(void);
00172 /*PyObject *BPY_rna_doc(void);*/
00173 PyObject *BPY_rna_types(void);
00174 
00175 PyObject *pyrna_struct_CreatePyObject(PointerRNA *ptr);
00176 PyObject *pyrna_prop_CreatePyObject(PointerRNA *ptr, PropertyRNA *prop);
00177 
00178 /* operators also need this to set args */
00179 int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, int all_args, const char *error_prefix);
00180 PyObject *pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop);
00181 
00182 PyObject *pyrna_enum_bitfield_to_py(struct EnumPropertyItem *items, int value);
00183 int pyrna_set_to_enum_bitfield(EnumPropertyItem *items, PyObject *value, int *r_value, const char *error_prefix);
00184 
00185 int pyrna_enum_value_from_id(EnumPropertyItem *item, const char *identifier, int *value, const char *error_prefix);
00186 
00187 int pyrna_deferred_register_class(struct StructRNA *srna, PyObject *py_class);
00188 
00189 /* called before stopping python */
00190 void pyrna_alloc_types(void);
00191 void pyrna_free_types(void);
00192 
00193 /* primitive type conversion */
00194 int pyrna_py_to_array(PointerRNA *ptr, PropertyRNA *prop, char *param_data, PyObject *py, const char *error_prefix);
00195 int pyrna_py_to_array_index(PointerRNA *ptr, PropertyRNA *prop, int arraydim, int arrayoffset, int index, PyObject *py, const char *error_prefix);
00196 PyObject *pyrna_array_index(PointerRNA *ptr, PropertyRNA *prop, int index);
00197 
00198 PyObject *pyrna_py_from_array(PointerRNA *ptr, PropertyRNA *prop);
00199 PyObject *pyrna_py_from_array_index(BPy_PropertyArrayRNA *self, PointerRNA *ptr, PropertyRNA *prop, int index);
00200 PyObject *pyrna_math_object_from_array(PointerRNA *ptr, PropertyRNA *prop);
00201 int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value);
00202 
00203 int pyrna_write_check(void);
00204 void pyrna_write_set(int val);
00205 
00206 int pyrna_struct_validity_check(BPy_StructRNA *pysrna);
00207 int pyrna_prop_validity_check(BPy_PropertyRNA *self);
00208 
00209 /* bpy.utils.(un)register_class */
00210 extern PyMethodDef meth_bpy_register_class;
00211 extern PyMethodDef meth_bpy_unregister_class;
00212 
00213 #endif