Python API
authorCampbell Barton <ideasman42@gmail.com>
Mon, 26 Mar 2007 02:10:24 +0000 (02:10 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 26 Mar 2007 02:10:24 +0000 (02:10 +0000)
made all libdata hashable - use the object type,name and lib for the hash.
added .tag to libdata so we can test if data's been processed without using dictionaries
added libdataseq.tag (write only) setting the tag flag (which can always be dirty)

26 files changed:
source/blender/python/api2_2x/Armature.c
source/blender/python/api2_2x/Curve.c
source/blender/python/api2_2x/Font.c
source/blender/python/api2_2x/Group.c
source/blender/python/api2_2x/Image.c
source/blender/python/api2_2x/Ipo.c
source/blender/python/api2_2x/Key.c
source/blender/python/api2_2x/Lamp.c
source/blender/python/api2_2x/Lattice.c
source/blender/python/api2_2x/Main.c
source/blender/python/api2_2x/Material.c
source/blender/python/api2_2x/Mesh.c
source/blender/python/api2_2x/Metaball.c
source/blender/python/api2_2x/NLA.c
source/blender/python/api2_2x/Object.c
source/blender/python/api2_2x/Scene.c
source/blender/python/api2_2x/Sound.c
source/blender/python/api2_2x/SurfNurb.c
source/blender/python/api2_2x/Text.c
source/blender/python/api2_2x/Text3d.c
source/blender/python/api2_2x/Texture.c
source/blender/python/api2_2x/World.c
source/blender/python/api2_2x/doc/Bpy.py
source/blender/python/api2_2x/doc/id_generics.py
source/blender/python/api2_2x/gen_library.c
source/blender/python/api2_2x/gen_library.h

index 2603ad0c1ac5d8c1fa0a27444a85a97d6a5c6484..d4d687f7306e386fc393671cc24e9747f9b71a7d 100644 (file)
@@ -1087,7 +1087,7 @@ PyTypeObject Armature_Type = {
        0,                                                              //tp_as_number
        0,                                                              //tp_as_sequence
        0,                                                              //tp_as_mapping
-       0,                                                              //tp_hash
+       ( hashfunc ) GenericLib_hash,   //tp_hash
        0,                                                              //tp_call
        0,                                                              //tp_str
        0,                                                              //tp_getattro
index 83435a1da7a3686239f89d89cf66735419213cb2..b107992f77ee77df98fc1b4771e3173638599447 100644 (file)
@@ -1557,7 +1557,7 @@ PyTypeObject Curve_Type = {
 
        /* More standard operations (here for binary compatibility) */
 
-       NULL,                               /* hashfunc tp_hash; */
+       ( hashfunc ) GenericLib_hash,           /* hashfunc tp_hash; */
        NULL,                               /* ternaryfunc tp_call; */
        NULL,                               /* reprfunc tp_str; */
        NULL,                               /* getattrofunc tp_getattro; */
index 6c46e54cfd838e0013f5a3ce884985eb82b91089..667dc6d4e0d12b0e18912d1efda82cc94a5987da 100644 (file)
@@ -288,7 +288,7 @@ PyTypeObject Font_Type = {
 
        /* More standard operations (here for binary compatibility) */
 
-       NULL,                       /* hashfunc tp_hash; */
+       ( hashfunc ) GenericLib_hash,   /* hashfunc tp_hash; */
        NULL,                       /* ternaryfunc tp_call; */
        NULL,                       /* reprfunc tp_str; */
        NULL,                       /* getattrofunc tp_getattro; */
index d9a5fe7e7d98db54da774a60232274035d7fc077..fa43bed58cc134cb3631ebfad31b690b3ab3bd2a 100755 (executable)
@@ -285,7 +285,7 @@ PyTypeObject Group_Type = {
 
        /* More standard operations (here for binary compatibility) */
 
-       NULL,                       /* hashfunc tp_hash; */
+       ( hashfunc ) GenericLib_hash,   /* hashfunc tp_hash; */
        NULL,                       /* ternaryfunc tp_call; */
        NULL,                       /* reprfunc tp_str; */
        NULL,                       /* getattrofunc tp_getattro; */
index 5aa8def8abbe7a00fa047e974da31698e77a29b0..fed54aaed5baab527b3dceec552e55a654144f8d 100644 (file)
@@ -1324,7 +1324,7 @@ PyTypeObject Image_Type = {
 
        /* More standard operations (here for binary compatibility) */
 
-       NULL,                       /* hashfunc tp_hash; */
+       ( hashfunc ) GenericLib_hash,   /* hashfunc tp_hash; */
        NULL,                       /* ternaryfunc tp_call; */
        NULL,                       /* reprfunc tp_str; */
        NULL,                       /* getattrofunc tp_getattro; */
index 4c1865d72b191b8e5123efeef9405b78cb335e1b..8ef4babb415a1b7099ccd355b03520f56ff12b39 100644 (file)
@@ -379,7 +379,7 @@ PyTypeObject Ipo_Type = {
 
        /* More standard operations (here for binary compatibility) */
 
-       NULL,                       /* hashfunc tp_hash; */
+       ( hashfunc ) GenericLib_hash,   /* hashfunc tp_hash; */
        NULL,                       /* ternaryfunc tp_call; */
        NULL,                       /* reprfunc tp_str; */
 #ifdef CURVEATTRS
index 27a92e8c17ef1d844457ff0c25cbbd4578786033..07112c62e17c299f9f5a2e4dd133a2def9d78ab6 100644 (file)
@@ -149,7 +149,7 @@ PyTypeObject Key_Type = {
 
        /* More standard operations (here for binary compatibility) */
 
-       NULL,                       /* hashfunc tp_hash; */
+       ( hashfunc ) GenericLib_hash,   /* hashfunc tp_hash; */
        NULL,                       /* ternaryfunc tp_call; */
        NULL,                       /* reprfunc tp_str; */
        NULL,                       /* getattrofunc tp_getattro; */
index f497dd7ae18ef70a5dc10bb06eb9049d86ca7f2a..26c3bd39ca6af57d290a1a0fb2c6ece51ef7db02 100644 (file)
@@ -538,7 +538,7 @@ PyTypeObject Lamp_Type = {
 
        /* More standard operations (here for binary compatibility) */
 
-       NULL,                       /* hashfunc tp_hash; */
+       ( hashfunc ) GenericLib_hash,   /* hashfunc tp_hash; */
        NULL,                       /* ternaryfunc tp_call; */
        NULL,                       /* reprfunc tp_str; */
        NULL,                       /* getattrofunc tp_getattro; */
index fc32d2158958deff75855a7534cb88d78cd3dbec..7b2ed57bf75b3545e2cfed2a04ee88d679e08d9e 100644 (file)
@@ -754,7 +754,7 @@ PyTypeObject Lattice_Type = {
 
        /* More standard operations (here for binary compatibility) */
 
-       NULL,                       /* hashfunc tp_hash; */
+       ( hashfunc ) GenericLib_hash,   /* hashfunc tp_hash; */
        NULL,                       /* ternaryfunc tp_call; */
        NULL,                       /* reprfunc tp_str; */
        NULL,                       /* getattrofunc tp_getattro; */
index ef0804a9bb4d4e71b182b3d51ecdeb798d6b0a69..3531a6a44279fe1b68162cfbe322e812ca22ecfb 100644 (file)
@@ -350,6 +350,31 @@ static int MainSeq_setActive(BPy_MainSeq *self, PyObject *value)
                        "Only Scene and Image types have the active attribute" );
 }
 
+static int MainSeq_setTag(BPy_MainSeq *self, PyObject *value)
+{
+       int param = PyObject_IsTrue( value );
+       ID *id;
+       
+       if( param == -1 )
+               return EXPP_ReturnIntError( PyExc_TypeError,
+                               "expected int argument in range [0,1]" );
+       
+       id = (ID *)wich_libbase(G.main, self->type)->first;
+       
+       if (param) {
+               for (; id; id = id->next) {
+                       id->flag |= LIB_DOIT;
+               }
+       } else {
+               for (; id; id = id->next) {
+                       id->flag &= ~LIB_DOIT;
+               }
+       }
+       
+       return 0;       
+}
+
+
 /* New Data, internal functions */
 Mesh *add_mesh__internal(char *name)
 {
@@ -640,6 +665,10 @@ static PyGetSetDef MainSeq_getseters[] = {
         (getter)MainSeq_getActive, (setter)MainSeq_setActive,
         "active object",
         NULL},
+       {"tag",
+        (getter)NULL, (setter)MainSeq_setTag,
+        "tag all data in True or False (write only)",
+        NULL},
        {NULL,NULL,NULL,NULL,NULL}  /* Sentinel */
 };
 
index fbe9e69af28bec88bb0730bbe6b4c6b1341094b1..038ab5b43941093aedae35ca8c2706490d6eea9d 100644 (file)
@@ -1102,7 +1102,7 @@ PyTypeObject Material_Type = {
 
        /* More standard operations (here for binary compatibility) */
 
-       NULL,                       /* hashfunc tp_hash; */
+       ( hashfunc ) GenericLib_hash,   /* hashfunc tp_hash; */
        NULL,                       /* ternaryfunc tp_call; */
        NULL,                       /* reprfunc tp_str; */
        NULL,                       /* getattrofunc tp_getattro; */
index 7e8f51f50026fbde15dbdbe85a9176381be25b09..27f53cedd95ab68af79a248fb613b36aa2c659b2 100644 (file)
@@ -7739,7 +7739,7 @@ PyTypeObject Mesh_Type = {
 
        /* More standard operations (here for binary compatibility) */
 
-       NULL,                       /* hashfunc tp_hash; */
+       ( hashfunc ) GenericLib_hash,   /* hashfunc tp_hash; */
        NULL,                       /* ternaryfunc tp_call; */
        NULL,                       /* reprfunc tp_str; */
        NULL,                       /* getattrofunc tp_getattro; */
index baf8ae27ec64a8e2f4a3c5a55e91052dcb5ebfc5..aeb935c72e16e7f0fa180cdc70a3dce48ce5c087 100644 (file)
@@ -243,7 +243,7 @@ PyTypeObject Metaball_Type = {
 
        /* More standard operations (here for binary compatibility) */
 
-       NULL,                       /* hashfunc tp_hash; */
+       ( hashfunc ) GenericLib_hash,   /* hashfunc tp_hash; */
        NULL,                       /* ternaryfunc tp_call; */
        NULL,                       /* reprfunc tp_str; */
        NULL,                       /* getattrofunc tp_getattro; */
index 2c5011f94fcd97c48bcbf93d8f6072299be75b4d..be15e24d193075a7f2e88bab1b121272820b5fae 100644 (file)
@@ -439,7 +439,7 @@ PyTypeObject Action_Type = {
 
        /* More standard operations (here for binary compatibility) */
 
-       NULL,                       /* hashfunc tp_hash; */
+       ( hashfunc ) GenericLib_hash,   /* hashfunc tp_hash; */
        NULL,                       /* ternaryfunc tp_call; */
        NULL,                       /* reprfunc tp_str; */
        NULL,                       /* getattrofunc tp_getattro; */
index 42133c6192f46eca21f2a97858297dbf67a12a87..beeb42af96cdf431b4c262dc7dcd0481a054bfe2 100644 (file)
@@ -5027,7 +5027,7 @@ PyTypeObject Object_Type = {
 
        /* More standard operations (here for binary compatibility) */
 
-       NULL,                       /* hashfunc tp_hash; */
+       ( hashfunc ) GenericLib_hash,   /* hashfunc tp_hash; */
        NULL,                       /* ternaryfunc tp_call; */
        NULL,                       /* reprfunc tp_str; */
        NULL,                       /* getattrofunc tp_getattro; */
index ff0eb3ff20dc07326f7303bd495a2bdc6badf84f..ea470a32911e5a3ba5b415f549acfc0fedbd36ad 100644 (file)
@@ -474,7 +474,7 @@ PyTypeObject Scene_Type = {
 
        /* More standard operations (here for binary compatibility) */
 
-       NULL,                       /* hashfunc tp_hash; */
+       ( hashfunc ) GenericLib_hash,   /* hashfunc tp_hash; */
        NULL,                       /* ternaryfunc tp_call; */
        NULL,                       /* reprfunc tp_str; */
        NULL,                       /* getattrofunc tp_getattro; */
index ed366429ce3206425c5128a6f870fc7240bbd683..75e67f94aae3d946e08cc35da933dea93284e67b 100644 (file)
@@ -563,7 +563,7 @@ PyTypeObject Sound_Type = {
 
        /* More standard operations (here for binary compatibility) */
 
-       NULL,                       /* hashfunc tp_hash; */
+       ( hashfunc ) GenericLib_hash,   /* hashfunc tp_hash; */
        NULL,                       /* ternaryfunc tp_call; */
        NULL,                       /* reprfunc tp_str; */
        NULL,                       /* getattrofunc tp_getattro; */
index 895e3e031ba8e218bc547c9955425c1f86992690..0cac359dcf95b0792d1176d9b7787a33eaadf5f0 100644 (file)
@@ -762,7 +762,7 @@ PyTypeObject SurfNurb_Type = {
 
        /* More standard operations (here for binary compatibility) */
 
-       NULL,                       /* hashfunc tp_hash; */
+       ( hashfunc ) GenericLib_hash,   /* hashfunc tp_hash; */
        NULL,                       /* ternaryfunc tp_call; */
        NULL,                       /* reprfunc tp_str; */
        NULL,                       /* getattrofunc tp_getattro; */
index 23db85f7b360b6a5cc770ced231f0fd04574808a..8741cab1a7f970f156fa67529ec53f5138a4e1fd 100644 (file)
@@ -532,7 +532,7 @@ PyTypeObject Text_Type = {
 
        /* More standard operations (here for binary compatibility) */
 
-       NULL,                       /* hashfunc tp_hash; */
+       ( hashfunc ) GenericLib_hash,   /* hashfunc tp_hash; */
        NULL,                       /* ternaryfunc tp_call; */
        NULL,                       /* reprfunc tp_str; */
        NULL,                       /* getattrofunc tp_getattro; */
@@ -540,7 +540,7 @@ PyTypeObject Text_Type = {
 
        /* Functions to access object as input/output buffer */
        NULL,                       /* PyBufferProcs *tp_as_buffer; */
-
   /*** Flags to define presence of optional/expanded features ***/
        Py_TPFLAGS_DEFAULT,         /* long tp_flags; */
 
index cf825bd242ccb07238c3c003af76b344202d65c7..df152217524a4a32afb0397c22ed8d783ceb4c94 100644 (file)
@@ -31,7 +31,7 @@
  *
  * ***** END GPL/BL DUAL LICENSE BLOCK *****
  */
+
 #include "Text3d.h" /*This must come first*/
  
 #include "DNA_object_types.h"
@@ -372,7 +372,7 @@ PyTypeObject Text3d_Type = {
 
        /* More standard operations (here for binary compatibility) */
 
-       NULL,                       /* hashfunc tp_hash; */
+       ( hashfunc ) GenericLib_hash,   /* hashfunc tp_hash; */
        NULL,                       /* ternaryfunc tp_call; */
        NULL,                       /* reprfunc tp_str; */
        NULL,                       /* getattrofunc tp_getattro; */
index 8d980ddf988f79000171b859d59bbeef8eae12a0..d1636c3d4057571a90c59201224238b8d9ec6646 100644 (file)
@@ -811,7 +811,7 @@ PyTypeObject Texture_Type = {
 
        /* More standard operations (here for binary compatibility) */
 
-       NULL,                       /* hashfunc tp_hash; */
+       ( hashfunc ) GenericLib_hash,   /* hashfunc tp_hash; */
        NULL,                       /* ternaryfunc tp_call; */
        NULL,                       /* reprfunc tp_str; */
        NULL,                       /* getattrofunc tp_getattro; */
index c16d4c3fc97ea1aafa490382560510ec7eb2bcf3..580bb3efcc3e68378754d1fd025126302e5f7f1f 100644 (file)
@@ -281,7 +281,7 @@ PyTypeObject World_Type = {
 
        /* More standard operations (here for binary compatibility) */
 
-       NULL,                       /* hashfunc tp_hash; */
+       ( hashfunc ) GenericLib_hash,   /* hashfunc tp_hash; */
        NULL,                       /* ternaryfunc tp_call; */
        NULL,                       /* reprfunc tp_str; */
        NULL,                       /* getattrofunc tp_getattro; */
index 7bf3afe82495d4bfccf7aed4ad961e2f0ae3a16d..25eca7ab6a802a2ca71340a8d128aee884599267 100644 (file)
@@ -188,6 +188,17 @@ class dataIterator:
                
                >>> ipo_list = list(bpy.ipos)
                
+       @type tag: Bool
+       @ivar tag: A fast way to set the tag value of every member of the sequence to True or False
+       
+               For example
+               
+               >>> bpy.meshes.tag = True
+               
+               Is the same as...
+               
+               >>> for me in bpy.meshes: me.tag = True
+       
        @type active: Datablock or None
        @ivar active: The active member of the datatype
        
index 1d1f52df9cb29e640e5656cffd6fb1d9e1ee57bd..30c7e5d6a3c37a39d1f96e93cff0ae732045029a 100644 (file)
@@ -18,6 +18,9 @@ attributes = """
        @ivar fakeUser: When set to True, this datablock wont be removed, even if nothing is using it.
                All data has this disabled by default except for Actions.       
        @type fakeUser: bool
+       @ivar tag: A temporary tag that to flag data as being used within a loop.
+               always set all tags to True or False before using since blender uses this flag for its own internal operations.
+       @type tag: bool
        @ivar users: The number of users this datablock has. (readonly)
                Zero user datablocks are de-allocated after reloading and saving.
        @type users: int
index af7b031f0fc4391cd2b22bd6603228a8c7c63b7c..a93bb2f879af26351910d785d2bbe7e1450d9e31 100644 (file)
@@ -91,6 +91,35 @@ int GenericLib_setFakeUser( void *self, PyObject *value )
        return 0;
 }
 
+PyObject *GenericLib_getTag( void *self )
+{      
+       ID *id = ((BPy_GenericLib *)self)->id;
+       if (!id) return ( EXPP_ReturnPyObjError( PyExc_RuntimeError, "data has been removed" ) );
+       if (id->flag & LIB_DOIT)
+               Py_RETURN_TRUE;
+       else
+               Py_RETURN_FALSE;
+}
+
+int GenericLib_setTag( void *self, PyObject *value )
+{
+       int param;
+       ID *id = ((BPy_GenericLib *)self)->id;
+       if (!id) return ( EXPP_ReturnIntError( PyExc_RuntimeError, "data has been removed" ) );
+       
+       param = PyObject_IsTrue( value );
+       if( param == -1 )
+               return EXPP_ReturnIntError( PyExc_TypeError,
+                               "expected int argument in range [0,1]" );
+       
+       if (param)
+               id->flag |= LIB_DOIT;
+       else
+               id->flag &= ~LIB_DOIT;
+       return 0;
+}
+
+
 /* read only */
 PyObject *GenericLib_getLib( void *self )
 {      
@@ -306,3 +335,14 @@ PyObject *GetPyObjectFromID( ID * id )
        Py_RETURN_NONE;
 }
 
+/* return a unique tuple for this libdata*/
+long GenericLib_hash(PyObject * pydata)
+{
+       ID *id = ((BPy_GenericLib *)pydata)->id;
+       PyObject *pyhash = PyTuple_New( 2 );
+       PyTuple_SetItem( pyhash, 0, PyString_FromString(id->name) );
+       if (id->lib) PyTuple_SetItem( pyhash, 0, PyString_FromString(id->lib->name) );
+       else            PyTuple_SetItem( pyhash, 1, Py_None );
+       return PyObject_Hash(pyhash);
+}
+
index 5f81424ca3a7efc707ca706487798efa83428511..74f34fd00192382e1bb9585d9b01d8e826a08bd0 100644 (file)
        {"properties",\
         (getter)GenericLib_getProperties, (setter)NULL,\
         "properties",\
+        NULL},\
+       {"tag",\
+        (getter)GenericLib_getTag, (setter)GenericLib_setTag,\
+        "temproary tag",\
         NULL}
 
-
 /* Dummy struct for getting the ID from a libdata BPyObject */
 typedef struct {
        PyObject_HEAD           /* required python macro */
@@ -72,6 +75,8 @@ int GenericLib_setName( void *self, PyObject *value );
 PyObject *GenericLib_getName( void *self );
 PyObject *GenericLib_getFakeUser( void *self );
 int GenericLib_setFakeUser( void *self, PyObject *value );
+PyObject *GenericLib_getTag( void *self );
+int GenericLib_setTag( void *self, PyObject *value );
 PyObject *GenericLib_getLib( void *self );
 PyObject *GenericLib_getUsers( void *self );
 PyObject *GenericLib_getProperties( void *self );
@@ -85,5 +90,5 @@ short GenericLib_getType(PyObject * pydata);
 /* Other ID functions */
 ID                     *GetIdFromList( ListBase * list, char *name );
 PyObject       *GetPyObjectFromID( ID * id );
-
+long GenericLib_hash(PyObject * pydata);
 #endif                         /* EXPP_gen_library_h */