moved python functions that deal with blender libdata into gen_library.c from gen_uti...
authorCampbell Barton <ideasman42@gmail.com>
Sun, 11 Mar 2007 04:05:45 +0000 (04:05 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 11 Mar 2007 04:05:45 +0000 (04:05 +0000)
small cleanup, removed unused functions and explicetly cast pointers..

32 files changed:
source/blender/python/BPY_interface.c
source/blender/python/api2_2x/Armature.c
source/blender/python/api2_2x/Camera.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/MTex.c
source/blender/python/api2_2x/Main.c
source/blender/python/api2_2x/Main.h
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/Modifier.c
source/blender/python/api2_2x/NLA.c
source/blender/python/api2_2x/Object.c
source/blender/python/api2_2x/Pose.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/gen_library.c [new file with mode: 0644]
source/blender/python/api2_2x/gen_library.h [new file with mode: 0644]
source/blender/python/api2_2x/gen_utils.c
source/blender/python/api2_2x/gen_utils.h

index 17f73898857e79a63723a15b0ac60355def4af5b..5bd2fa2496ab67d12ec20a5897a95139edc3862a 100644 (file)
 #include "BKE_library.h"
 #include "BKE_object.h"                /* during_scriptlink() */
 #include "BKE_text.h"
+
 #include "DNA_curve_types.h" /* for struct IpoDriver */
+#include "DNA_ID.h" /* ipo driver */
+#include "DNA_object_types.h" /* ipo driver */
+
 #include "DNA_screen_types.h"
 #include "DNA_userdef_types.h" /* for U.pythondir */
 #include "MEM_guardedalloc.h"
@@ -55,6 +59,7 @@
 #include "api2_2x/EXPP_interface.h"
 #include "api2_2x/constant.h"
 #include "api2_2x/gen_utils.h"
+#include "api2_2x/gen_library.h" /* GetPyObjectFromID */
 #include "api2_2x/BGL.h" 
 #include "api2_2x/Blender.h"
 #include "api2_2x/Camera.h"
 #include "api2_2x/Registry.h"
 #include "api2_2x/Main.h" /* for the "bpy" default module */
 
-/* ID_asPyObject */
-#include "api2_2x/Object.h"
-#include "api2_2x/Camera.h"
-#include "api2_2x/Armature.h"
-#include "api2_2x/Lamp.h"
-/*#include "api2_2x/ CurNurb.h" do we need this ? */
-#include "api2_2x/Curve.h"
-#include "api2_2x/NMesh.h"
-#include "api2_2x/Mesh.h"
-#include "api2_2x/Lattice.h"
-#include "api2_2x/Metaball.h"
-#include "api2_2x/Text3d.h"
-#include "api2_2x/Font.h"
-#include "api2_2x/Group.h"
-#include "api2_2x/World.h"
-#include "api2_2x/Texture.h"
-#include "api2_2x/Ipo.h"
-#include "api2_2x/Text.h"
-#include "api2_2x/Sound.h"
-#include "api2_2x/NLA.h"
-#include "api2_2x/Main.h"
-#include "api2_2x/Scene.h"
-
+/* for scriptlinks */
+#include "DNA_lamp_types.h"
+#include "DNA_camera_types.h"
+#include "DNA_world_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_material_types.h"
 
 /* bpy_registryDict is declared in api2_2x/Registry.h and defined
  * in api2_2x/Registry.c
@@ -1354,70 +1342,6 @@ static ScriptLink *ID_getScriptlink( ID * id )
        }
 }
 
-PyObject *ID_asPyObject( ID * id )
-{
-       switch ( MAKE_ID2( id->name[0], id->name[1] ) ) {
-       case ID_SCE:
-               return Scene_CreatePyObject( ( Scene *) id );
-               break;
-       case ID_OB:
-               return Object_CreatePyObject( (Object *) id );
-               break;
-       case ID_ME:
-               return Mesh_CreatePyObject( (Mesh *)id, NULL );
-               break;
-       case ID_CU: /*todo, support curnurbs?*/
-               return Curve_CreatePyObject((Curve *)id);
-               break;
-       case ID_MB:
-               return Metaball_CreatePyObject((MetaBall *)id);
-               break;
-       case ID_MA:
-               return Material_CreatePyObject((Material *)id);
-               break;
-       case ID_TE:
-               return Texture_CreatePyObject((Tex *)id);
-               break;
-       case ID_IM:
-               return Image_CreatePyObject((Image *)id);
-               break;
-       case ID_LT:
-               return Lattice_CreatePyObject((Lattice *)id);
-               break;
-       case ID_LA:
-               return Lamp_CreatePyObject((Lamp *)id);
-               break;
-       case ID_CA:
-               return Camera_CreatePyObject((Camera *)id);
-               break;
-       case ID_IP:
-               return Ipo_CreatePyObject((Ipo *)id);
-               break;
-       case ID_WO:
-               return World_CreatePyObject((World *)id);
-               break;
-       case ID_VF:
-               return Font_CreatePyObject((VFont *)id);
-               break;
-       case ID_TXT:
-               return Text_CreatePyObject((Text *)id);
-               break;
-       case ID_SO:
-               return Sound_CreatePyObject((bSound *)id);
-               break;
-       case ID_GR:
-               return Group_CreatePyObject((Group *)id);
-               break;
-       case ID_AR:
-               return Armature_CreatePyObject((bArmature *)id);
-               break;
-       case ID_AC:
-               return Action_CreatePyObject((bAction *)id);
-               break;
-       }
-       Py_RETURN_NONE;
-}
-
 int BPY_has_onload_script( void )
 {
        ScriptLink *slink = &G.scene->scriptlink;
@@ -1461,7 +1385,7 @@ void BPY_do_pyscript( ID * id, short event )
                /* set globals in Blender module to identify scriptlink */
                EXPP_dict_set_item_str( g_blenderdict, "bylink", EXPP_incr_ret_True() );
                EXPP_dict_set_item_str( g_blenderdict, "link",
-                                     ID_asPyObject( id ) );
+                                     GetPyObjectFromID( id ) );
                EXPP_dict_set_item_str( g_blenderdict, "event",
                                      PyString_FromString( event_to_name
                                                           ( event ) ) );
index 6ce4f7123818e7f73cc48c9fe00d879e75d6cf47..409a0b90643807288832d1cc7dc3b90a075dc3c0 100644 (file)
@@ -42,6 +42,7 @@
 #include "Bone.h"
 #include "NLA.h"
 #include "gen_utils.h"
+#include "gen_library.h"
 
 #include "DNA_object_types.h" //This must come before BIF_editarmature.h...
 #include "BIF_editarmature.h"
index 0bd73e11500708708f0caaf7e9b74bad5a4fe92d..9f5b48000e903b0747e24888d920cc2bed748d2d 100644 (file)
@@ -41,6 +41,7 @@
 #include "BIF_space.h"
 #include "mydevice.h"
 #include "gen_utils.h"
+#include "gen_library.h"
 #include "Ipo.h"
 
 
@@ -369,16 +370,6 @@ Camera *Camera_FromPyObject( PyObject * pyobj )
 /* Python BPy_Camera methods:                                               */
 /*****************************************************************************/
 
-static PyObject *Camera_oldgetIpo( BPy_Camera * self )
-{
-       struct Ipo *ipo = self->camera->ipo;
-
-       if( !ipo )
-               Py_RETURN_NONE;
-
-       return Ipo_CreatePyObject( ipo );
-}
-
 static PyObject *Camera_oldgetType( BPy_Camera * self )
 {
        PyObject *attr = PyInt_FromLong( self->camera->type );
index f72851e115e32ee9f3717fc89926cb1283378c34..21c4708490ff214af9bd932dbb66d65dafb7ef49 100644 (file)
@@ -44,6 +44,7 @@
 #include "Object.h"
 #include "Key.h"
 #include "gen_utils.h"
+#include "gen_library.h"
 #include "mydevice.h"
 
 
index 44fa7ff01589ff7246db54338da8ac17f3a9b46e..1d2a1e58bd4a4ffec7996b506dd9171d209a688c 100644 (file)
@@ -36,6 +36,7 @@
 #include "BKE_library.h" /* for rename_id() */
 #include "BLI_blenlib.h"
 #include "gen_utils.h"
+#include "gen_library.h"
 
 #include "BKE_main.h" /* so we can access G.main->vfont.first */
 #include "DNA_space_types.h" /* for FILE_MAXDIR only */
index 65d68c51721ba5655920b3c0bda28605c97e89d1..b5fe226bf2c516bde4c5acf7dfa027be6d21e480 100755 (executable)
@@ -47,6 +47,7 @@
 #include "blendef.h"
 #include "Object.h"
 #include "gen_utils.h"
+#include "gen_library.h"
 
 /* checks for the group being removed */
 #define GROUP_DEL_CHECK_PY(bpy_group) if (!(bpy_group->group)) return ( EXPP_ReturnPyObjError( PyExc_RuntimeError, "Group has been removed" ) )
index 6304964132fdb9d0d11744f4d1f480135f6b04f7..41714e2cdf7c2d310a5cd2871f119feb0e05602b 100644 (file)
@@ -44,6 +44,7 @@
 #include "IMB_imbuf_types.h"   /* for the IB_rect define */
 #include "BIF_gl.h"
 #include "gen_utils.h"
+#include "gen_library.h"
 #include "BKE_packedFile.h"
 #include "DNA_packedFile_types.h"
 #include "BKE_icons.h"
index 6f270839ce245580c189d50d671e125e26808d58..8bbcc1dce6b94f595d82db13ca85613208a10470 100644 (file)
@@ -45,6 +45,7 @@
 #include "mydevice.h"
 #include "Ipocurve.h"
 #include "gen_utils.h"
+#include "gen_library.h"
 
 extern int ob_ar[];
 extern int la_ar[];
index 87edb8f4e5b4523f26007ace1c1b022009902a1c..f867545ce167e63d6a17241e5b2d0758f23eeccd 100644 (file)
@@ -52,6 +52,7 @@
 #include "blendef.h"
 #include "constant.h"
 #include "gen_utils.h"
+#include "gen_library.h"
 
 #define KEY_TYPE_MESH    0
 #define KEY_TYPE_CURVE   1
index c7ec3de5892918e004d80f097e2b9ac7934e1a32..535a13a843171881ad7d93947ff45316e10c7481 100644 (file)
@@ -44,6 +44,7 @@
 #include "Ipo.h"
 #include "constant.h"
 #include "gen_utils.h"
+#include "gen_library.h"
 
 /*****************************************************************************/
 /* Python BPy_Lamp defaults:                                                 */
index 0405b40a2c67c075a4d565bfbbb5bbd2728a26f3..5357fc2e64710d537c51484be2260aeae39fbb03 100644 (file)
@@ -49,6 +49,7 @@
 #include "BIF_space.h"
 #include "blendef.h"
 #include "gen_utils.h"
+#include "gen_library.h"
 
 #include "Key.h"
 
index c345cf30fc06eb2910937e90720c152bb8defc60..9e3e1883c7b26d3fd483d3a75e1555fe0ca6ff0a 100644 (file)
@@ -36,6 +36,7 @@
 #include "Texture.h"
 #include "Object.h"
 #include "gen_utils.h"
+#include "gen_library.h"
 
 #include <DNA_material_types.h>
 
index 8680dcbebba4ccbe305e8f42957cc0042277acd5..a5def464acdeb6a3658b5968970006a9d4b2ceed 100644 (file)
 #include "BIF_editsound.h" /* sound_new_sound */
 
 /* python types */
-#include "../BPY_extern.h" /* clearing scriptlinks and ID_asPyObject */
+#include "../BPY_extern.h" /* clearing scriptlinks */
 
 #include "gen_utils.h"
+#include "gen_library.h" /* generic ID functions */
 
 #include "Object.h"
 #include "Camera.h"
@@ -167,7 +168,7 @@ static PyObject * MainSeq_subscript(BPy_MainSeq * self, PyObject *key)
                                (lib && use_lib && id->lib && (!strcmp( id->lib->name, lib))) /* only external lib */
                        )
                        {
-                               return ID_asPyObject(id);
+                               return GetPyObjectFromID(id);
                        }
                }
        }
@@ -226,7 +227,7 @@ static PyObject *MainSeq_nextIter( BPy_MainSeq * self )
                                "iterator at end" );
        }
        
-       object = ID_asPyObject((ID *)self->iter);
+       object = GetPyObjectFromID((ID *)self->iter);
        
        link= self->iter->next;
        self->iter= link;
@@ -564,7 +565,7 @@ PyObject *MainSeq_new(BPy_MainSeq *self, PyObject * args)
                break;
        }
        
-       if (id) return ID_asPyObject(id);
+       if (id) return GetPyObjectFromID(id);
        Py_RETURN_NONE;
 }
 
index a76b9fc51604e37b5abcc07077109383b1b237f3..f1dd6c0782e8af62515993f979cd9a9e718bc8e7 100644 (file)
@@ -38,9 +38,6 @@
 /* The Main PyType Object defined in Main.c */
 extern PyTypeObject MainSeq_Type;
 
- /* BPY_interface.c */
-extern PyObject *ID_asPyObject( ID * id );
-
 #define BPy_MainSeq_Check(v) \
     ((v)->ob_type == &MainSeq_Type)
 
index 25eebaa860e70db75b2220200765769f9600d465..6a2ee287e9a2df063b91953ee7bf9484555cb058 100644 (file)
@@ -53,6 +53,7 @@
 #include "Ipo.h"
 #include "Group.h"
 #include "gen_utils.h"
+#include "gen_library.h"
 #include "IDProp.h"
 
 /*****************************************************************************/
index 963c1051662b480f1cc510e8a5f2f4f717b31e4e..f7006d9e95af930c9d5c91b3f40ddd099a2e06c8 100644 (file)
@@ -87,6 +87,7 @@
 #include "meshPrimitive.h"
 #include "constant.h"
 #include "gen_utils.h"
+#include "gen_library.h"
 #include "multires.h"
 
 /* EXPP Mesh defines */
index 6cef3227943f5ac44cbf97bcea7f4ff2773e8bbf..94b5535c520269c6df64f8725fc76f874c2ff5ff 100644 (file)
@@ -42,6 +42,7 @@
 #include "Mathutils.h"
 #include "Material.h"
 #include "gen_utils.h"
+#include "gen_library.h"
 
 /* for dealing with materials */
 #include "MEM_guardedalloc.h"
index 8ddbb2f9dcf16b00567f3c479800c545022ce0fe..a18b12ece8d36a4076ada77848c75f8f0113a6ca 100644 (file)
@@ -51,6 +51,7 @@
 #include "Texture.h"
 #include "Mathutils.h"
 #include "gen_utils.h"
+#include "gen_library.h"
 
 /* checks for the scene being removed */
 #define MODIFIER_DEL_CHECK_PY(bpy_modifier) if (!(bpy_modifier->md)) return ( EXPP_ReturnPyObjError( PyExc_RuntimeError, "Modifier has been removed" ) )
index 5cfed7b4e294a2be474295dd9b6728f1e1ea8dab..2c7f466cb5648ed2c977f3cab8c8ca891653b303 100644 (file)
@@ -43,6 +43,7 @@
 #include "Object.h"
 #include "Ipo.h"
 #include "gen_utils.h"
+#include "gen_library.h"
 #include "blendef.h"
 #include "MEM_guardedalloc.h"
 
index 9014a923ccea4c5230ec07d3600294a3983ace78..543702a8054eee4397126b8904412e4e3f9b741a 100644 (file)
@@ -113,6 +113,7 @@ struct rctf;
 #include "Modifier.h"
 #include "Constraint.h"
 #include "gen_utils.h"
+#include "gen_library.h"
 #include "EXPP_interface.h"
 #include "BIF_editkey.h"
 #include "IDProp.h"
index 364b37d3e67cffb99ee523fe39046edbd881b63b..2b4f67c9b8c1aff80c13195cb869db0aae5da256 100644 (file)
@@ -53,6 +53,7 @@
 #include "Constraint.h"
 #include "NLA.h"
 #include "gen_utils.h"
+#include "gen_library.h"
 
 #include "DNA_armature_types.h" /*used for pose bone select*/
 
@@ -352,15 +353,15 @@ static char BPy_Pose_doc[] = "This object wraps a Blender Pose object.";
 PyTypeObject Pose_Type = {
        PyObject_HEAD_INIT(NULL)   //tp_head
        0,                                                                              //tp_internal
-       "Pose",                                                         //tp_name
-       sizeof(BPy_Pose),                                       //tp_basicsize
+       "Pose",                                                                 //tp_name
+       sizeof(BPy_Pose),                                               //tp_basicsize
        0,                                                                              //tp_itemsize
-       (destructor)Pose_dealloc,               //tp_dealloc
+       (destructor)Pose_dealloc,                               //tp_dealloc
        0,                                                                              //tp_print
        0,                                                                              //tp_getattr
        0,                                                                              //tp_setattr
-       0,                                                                              //tp_compare
-       (reprfunc)Pose_repr,                            //tp_repr
+       (cmpfunc)Pose_compare,                                  //tp_compare
+       (reprfunc)Pose_repr,                                    //tp_repr
        0,                                                                              //tp_as_number
        0,                                                                              //tp_as_sequence
        0,                                                                              //tp_as_mapping
@@ -370,17 +371,17 @@ PyTypeObject Pose_Type = {
        0,                                                                              //tp_getattro
        0,                                                                              //tp_setattro
        0,                                                                              //tp_as_buffer
-       Py_TPFLAGS_DEFAULT,         //tp_flags
-       BPy_Pose_doc,                                   //tp_doc
+       Py_TPFLAGS_DEFAULT,                                 //tp_flags
+       BPy_Pose_doc,                                                   //tp_doc
        0,                                                                              //tp_traverse
        0,                                                                              //tp_clear
        0,                                                                              //tp_richcompare
        0,                                                                              //tp_weaklistoffset
        0,                                                                              //tp_iter
        0,                                                                              //tp_iternext
-       BPy_Pose_methods,                               //tp_methods
+       BPy_Pose_methods,                                               //tp_methods
        0,                                                                              //tp_members
-       BPy_Pose_getset,                                        //tp_getset
+       BPy_Pose_getset,                                                //tp_getset
        0,                                                                              //tp_base
        0,                                                                              //tp_dict
        0,                                                                              //tp_descr_get
index 4924cc8c9e48e54550e2dd8e7f9d2fe96e5a21b1..89efe42ef283539be5ac518f7b152432284dd658 100644 (file)
@@ -74,6 +74,7 @@ struct View3D;
 #include "Text3d.h"
 
 #include "gen_utils.h"
+#include "gen_library.h"
 #include "sceneRender.h"
 #include "sceneRadio.h"
 #include "sceneTimeLine.h"
index 6c6841aa4c5bda73ac4a1a6a5ee04bb006b1598e..04cca0bd3c29e34e693504003a32efa993927205 100644 (file)
@@ -41,6 +41,7 @@
 #include "BKE_packedFile.h"
 #include "mydevice.h"          /* redraw defines */
 #include "gen_utils.h"
+#include "gen_library.h"
 #include "DNA_space_types.h" /* for FILE_MAXDIR only */
 
 /*****************************************************************************/
index 701fe4c6531797611847dabd383976d9f832fa30..cea8df325b290026e8bd55f51d25f478a0d71540 100644 (file)
@@ -35,6 +35,7 @@
 #include "BDR_editcurve.h"     /* for convertspline */
 #include "MEM_guardedalloc.h"
 #include "gen_utils.h"
+#include "gen_library.h"
 #include "BezTriple.h"
 
 /*
index f94ebafeee70113bc6d623060b4c5ecdc633922b..5aae39fb336944f2328d5cdeb797419559b8c6e4 100644 (file)
@@ -41,6 +41,7 @@
 #include "BLI_blenlib.h"
 #include "DNA_space_types.h"
 #include "gen_utils.h"
+#include "gen_library.h"
 #include "../BPY_extern.h"
 
 /* used only for makeCurrent, this may be deprecated when Blender.Base is implimented */
index 1a3a765c75674c94101891e8768580492d82cf01..c91a55e1e2416cca11b844d579b1caee680ce452 100644 (file)
@@ -45,6 +45,7 @@
 #include "constant.h"
 #include "Font.h"
 #include "gen_utils.h"
+#include "gen_library.h"
 
 
 enum t3d_consts {
index 1f2f54aadd3f5a1fef5cc365fd97933be598f39d..ffa61d3794f8ff92cc57c91487f354b33cc85c55 100644 (file)
@@ -52,6 +52,7 @@
 #include "constant.h"
 #include "blendef.h"
 #include "gen_utils.h"
+#include "gen_library.h"
 
 #include "vector.h" /* for Texture_evaluate(vec) */
 #include "Material.h" /* for EXPP_Colorband_fromPyList and EXPP_PyList_fromColorband */
index 95436027f8ce9e4834ccc6047dc431abd40c5d53..32cc16c73bad5db90df521b091d39dbd7cb10fcf 100644 (file)
@@ -56,7 +56,7 @@
 #include "mydevice.h"
 #include "Ipo.h"
 #include "gen_utils.h"
-
+#include "gen_library.h"
 
 #define IPOKEY_ZENITH   0
 #define IPOKEY_HORIZON  1
@@ -406,7 +406,6 @@ static PyObject *M_World_Get( PyObject * self, PyObject * args )
        char *name = NULL;
        World *world_iter;
        PyObject *worldlist;
-       BPy_World *wanted_world = NULL;
        char error_msg[64];
 
        if( !PyArg_ParseTuple( args, "|s", &name ) )
diff --git a/source/blender/python/api2_2x/gen_library.c b/source/blender/python/api2_2x/gen_library.c
new file mode 100644 (file)
index 0000000..af7b031
--- /dev/null
@@ -0,0 +1,308 @@
+#include "gen_library.h"
+#include "gen_utils.h" /*This must come first*/
+
+/* use for GenericLib_getProperties */
+#include "BKE_idprop.h"
+#include "IDProp.h"
+
+#include "BKE_global.h"
+#include "BKE_main.h"
+#include "BKE_library.h"
+
+/* GenericLib */
+#include "World.h"
+#include "Font.h"
+#include "Metaball.h"
+#include "Curve.h"
+#include "Camera.h"
+#include "NLA.h"
+#include "Lattice.h"
+#include "Armature.h"
+#include "Lamp.h"
+#include "Text.h"
+#include "Sound.h"
+#include "Scene.h"
+#include "Mesh.h"
+#include "Group.h"
+#include "Object.h"
+#include "Texture.h"
+#include "Ipo.h"
+#include "DNA_object_types.h"
+#include "DNA_ipo_types.h"
+
+
+
+/* Generic get/set attrs */
+PyObject *GenericLib_getName( void *self )
+{      
+       ID *id = ((BPy_GenericLib *)self)->id;
+       if (!id) return ( EXPP_ReturnPyObjError( PyExc_RuntimeError, "data has been removed" ) );
+       return PyString_FromString( id->name + 2 );
+}
+
+int GenericLib_setName( void *self, PyObject *value )
+{
+       ID *id = ((BPy_GenericLib *)self)->id;
+       char *name = NULL;
+       if (!id) return ( EXPP_ReturnIntError( PyExc_RuntimeError, "data has been removed" ) );
+       
+       name = PyString_AsString ( value );
+       if( !name )
+               return EXPP_ReturnIntError( PyExc_TypeError,
+                                             "expected string argument" );
+
+       rename_id( id, name );
+
+       return 0;
+}
+
+PyObject *GenericLib_getFakeUser( void *self )
+{      
+       ID *id = ((BPy_GenericLib *)self)->id;
+       if (!id) return ( EXPP_ReturnPyObjError( PyExc_RuntimeError, "data has been removed" ) );
+       if (id->flag & LIB_FAKEUSER)
+               Py_RETURN_TRUE;
+       else
+               Py_RETURN_FALSE;
+}
+
+int GenericLib_setFakeUser( 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) {
+               if (!(id->flag & LIB_FAKEUSER)) {
+                       id->flag |= LIB_FAKEUSER;
+                       id_us_plus(id);
+               }
+       } else {
+               if (id->flag & LIB_FAKEUSER) {
+                       id->flag &= ~LIB_FAKEUSER;
+                       id->us--;
+               }
+       }
+       return 0;
+}
+
+/* read only */
+PyObject *GenericLib_getLib( void *self )
+{      
+       ID *id = ((BPy_GenericLib *)self)->id;
+       if (!id) return ( EXPP_ReturnPyObjError( PyExc_RuntimeError, "data has been removed" ) );
+       
+       if (id->lib)
+               return PyString_FromString(id->lib->name);
+       else
+               return EXPP_incr_ret( Py_None );
+}
+
+PyObject *GenericLib_getUsers( void *self )
+{      
+       ID *id = ((BPy_GenericLib *)self)->id;
+       if (!id) return ( EXPP_ReturnPyObjError( PyExc_RuntimeError, "data has been removed" ) );
+       return PyInt_FromLong(id->us);
+}
+
+PyObject *GenericLib_getProperties( void *self )
+{      
+       ID *id = ((BPy_GenericLib *)self)->id;
+       if (!id) return ( EXPP_ReturnPyObjError( PyExc_RuntimeError, "data has been removed" ) );
+       return BPy_Wrap_IDProperty( id, IDP_GetProperties(id, 1), NULL );
+}
+
+/* use for any.setName("name")*/
+PyObject * GenericLib_setName_with_method( void *self, PyObject *args )
+{
+       return EXPP_setterWrapper( (void *)self, args, (setter)GenericLib_setName );
+}
+
+
+/* 
+ * returns the Blender lib type code from a PyObject
+ * -1 for no match, only give this function libdata
+ * 
+ * At the moment this is only used by GenericLib_assignData
+ * so not all types are needed.
+ */
+short GenericLib_getType(PyObject * pydata)
+{
+       //~ if (BPy_Scene_Check(pydata))        return ID_SCE;
+       if (BPy_Object_Check(pydata))   return ID_OB;
+       if (BPy_Mesh_Check(pydata))             return ID_ME;
+       //~ if (BPy_Curve_Check(pydata))        return ID_CU;
+       //~ if (BPy_Metaball_Check(pydata))     return ID_MB;
+       //~ if (BPy_Material_Check(pydata))     return ID_MA;
+       if (BPy_Texture_Check(pydata))  return ID_TE;
+       //~ if (BPy_Image_Check(pydata))        return ID_IM;
+               //~ //if (BPy_Lattice_Check(pydata))    return ID_LT;
+       //~ if (BPy_Lamp_Check(pydata))         return ID_LA;
+       //~ if (BPy_Camera_Check(pydata))       return ID_CA;
+       if (BPy_Ipo_Check(pydata))              return ID_IP;
+       if (BPy_World_Check(pydata))    return ID_WO;
+               //~ //if (BPy_Font_Check(pydata))               return ID_VF;
+       //~ if (BPy_Text_Check(pydata))         return ID_TXT;
+       //~ if (BPy_Sound_Check(pydata))        return ID_SO;
+       if (BPy_Group_Check(pydata))    return ID_GR;
+       //~ if (BPy_Armature_Check(pydata))     return ID_AR;
+       //~ if (BPy_Action_Check(pydata))       return ID_AC;
+       
+       return -1;
+}
+
+
+/*
+ * This function is used to assign a PyObject representing
+ * blender libdata to a pointer.
+ * 
+ * Python examples of this are...
+ *             ob.DupGroup = dupliGroup
+ *             mesh.texMesh = texme
+ *             ob.ipo = None 
+ * 
+ * This function deals with type checking, data usercounts,
+ * and raising errors.
+ * 
+ * value - python value
+ * data - Blender pointer to assign value to
+ * ndata - Use this if there is a value data cannot be.
+ *             for instance, a curve's curve modifier cant point to its self.
+ * refcount - non zero values will modify blenders user count.
+ * type - ID type.
+ * subtype - used only for objects and IPO's to stop the wrong types of obs/ipos
+ *             being assigned.
+ * 
+ */
+int GenericLib_assignData(PyObject *value, void **data, void **ndata, short refcount, short type, short subtype)
+{
+       ID *id=NULL;
+       
+       if (*data && ndata && *data == *ndata) {
+               return EXPP_ReturnIntError( PyExc_TypeError,
+                       "Cannot set this data to its self" );
+               
+               id = ((ID*)*data);
+       }
+       if (value == Py_None) {
+               *data = NULL;
+               if (refcount && id) id->us--;
+       } else if (GenericLib_getType(value) == type) {
+               
+               /* object subtypes */
+               if (subtype != 0) {
+                       if (type == ID_OB) {
+                               Object *ob= (Object *)(((BPy_GenericLib *)value)->id);
+                               if (ob->type != subtype)
+                                       return EXPP_ReturnIntError( PyExc_TypeError,
+                                               "Object type not supported" );
+                       }
+                       
+                       if (type == ID_IP) {
+                               Ipo *ipo = (Ipo *)(((BPy_GenericLib *)value)->id);
+                               if (ipo->blocktype != subtype)
+                                       return EXPP_ReturnIntError( PyExc_TypeError,
+                                               "Ipo type does is not compatible" );
+                       }
+                       
+                       
+               }
+               if (refcount && id) id->us--;
+               id = ((BPy_GenericLib *)value)->id;
+               id->us++;
+               *data = id;
+       } else {
+               return EXPP_ReturnIntError( PyExc_TypeError,
+                               "Could not assign Python Type - None or Library Object" );
+       }
+       return 0;
+} 
+
+
+/*
+ * returns the ID of the object with given name
+ * from a given list.
+ */
+ID *GetIdFromList( ListBase * list, char *name )
+{
+       ID *id = list->first;
+
+       while( id ) {
+               if( strcmp( name, id->name + 2 ) == 0 )
+                       break;
+               id = id->next;
+       }
+
+       return id;
+}
+
+
+PyObject *GetPyObjectFromID( ID * id )
+{
+       switch ( MAKE_ID2( id->name[0], id->name[1] ) ) {
+       case ID_SCE:
+               return Scene_CreatePyObject( ( Scene *) id );
+               break;
+       case ID_OB:
+               return Object_CreatePyObject( (Object *) id );
+               break;
+       case ID_ME:
+               return Mesh_CreatePyObject( (Mesh *)id, NULL );
+               break;
+       case ID_CU: /*todo, support curnurbs?*/
+               return Curve_CreatePyObject((Curve *)id);
+               break;
+       case ID_MB:
+               return Metaball_CreatePyObject((MetaBall *)id);
+               break;
+       case ID_MA:
+               return Material_CreatePyObject((Material *)id);
+               break;
+       case ID_TE:
+               return Texture_CreatePyObject((Tex *)id);
+               break;
+       case ID_IM:
+               return Image_CreatePyObject((Image *)id);
+               break;
+       case ID_LT:
+               return Lattice_CreatePyObject((Lattice *)id);
+               break;
+       case ID_LA:
+               return Lamp_CreatePyObject((Lamp *)id);
+               break;
+       case ID_CA:
+               return Camera_CreatePyObject((Camera *)id);
+               break;
+       case ID_IP:
+               return Ipo_CreatePyObject((Ipo *)id);
+               break;
+       case ID_WO:
+               return World_CreatePyObject((World *)id);
+               break;
+       case ID_VF:
+               return Font_CreatePyObject((VFont *)id);
+               break;
+       case ID_TXT:
+               return Text_CreatePyObject((Text *)id);
+               break;
+       case ID_SO:
+               return Sound_CreatePyObject((bSound *)id);
+               break;
+       case ID_GR:
+               return Group_CreatePyObject((Group *)id);
+               break;
+       case ID_AR:
+               return Armature_CreatePyObject((bArmature *)id);
+               break;
+       case ID_AC:
+               return Action_CreatePyObject((bAction *)id);
+               break;
+       }
+       Py_RETURN_NONE;
+}
+
diff --git a/source/blender/python/api2_2x/gen_library.h b/source/blender/python/api2_2x/gen_library.h
new file mode 100644 (file)
index 0000000..5f81424
--- /dev/null
@@ -0,0 +1,89 @@
+/* 
+ * $Id$
+ *
+ * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. The Blender
+ * Foundation also sells licenses for use in proprietary software under
+ * the Blender License.  See http://www.blender.org/BL/ for information
+ * about this.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA       02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * This is a new part of Blender.
+ *
+ * Contributor(s): Michel Selten, Willian P. Germano, Alex Mole, Joseph Gilbert
+ *
+ * ***** END GPL/BL DUAL LICENSE BLOCK *****
+*/
+
+#ifndef EXPP_gen_library_h
+#define EXPP_gen_library_h
+
+#include <Python.h>
+
+#include "DNA_ID.h"
+#include "DNA_listBase.h"
+
+/* ID functions for all libdata */
+#define        GENERIC_LIB_GETSETATTR \
+       {"name",\
+        (getter)GenericLib_getName, (setter)GenericLib_setName,\
+        "name",\
+        NULL},\
+       {"lib",\
+        (getter)GenericLib_getLib, (setter)NULL,\
+        "external library path",\
+        NULL},\
+       {"users",\
+        (getter)GenericLib_getUsers, (setter)NULL,\
+        "user count",\
+        NULL},\
+       {"fakeUser",\
+        (getter)GenericLib_getFakeUser, (setter)GenericLib_setFakeUser,\
+        "fake user state",\
+        NULL},\
+       {"properties",\
+        (getter)GenericLib_getProperties, (setter)NULL,\
+        "properties",\
+        NULL}
+
+
+/* Dummy struct for getting the ID from a libdata BPyObject */
+typedef struct {
+       PyObject_HEAD           /* required python macro */
+       ID *id;
+} BPy_GenericLib;
+
+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_getLib( void *self );
+PyObject *GenericLib_getUsers( void *self );
+PyObject *GenericLib_getProperties( void *self );
+
+/* use this for oldstyle somedata.getName("name") */
+PyObject * GenericLib_setName_with_method( void *self, PyObject *value ); 
+
+int GenericLib_assignData(PyObject *value, void **data, void **ndata, short refcount, short type, short subtype);
+short GenericLib_getType(PyObject * pydata);
+
+/* Other ID functions */
+ID                     *GetIdFromList( ListBase * list, char *name );
+PyObject       *GetPyObjectFromID( ID * id );
+
+#endif                         /* EXPP_gen_library_h */
index 2a4a57f80211db600b96ded71088210d3cd1cfd9..4cebcfcb0564faa5860ca5b900fec25c57c84948 100644 (file)
 #include "BKE_main.h"
 #include "BKE_library.h"
 
-/* use for GenericLib_getProperties */
-#include "BKE_idprop.h"
-#include "IDProp.h"
-
 #include "Mathutils.h"
 
 #include "constant.h"
 
-/* GenericLib */
-#include "World.h"
-#include "Mesh.h"
-#include "Group.h"
-#include "Object.h"
-#include "Texture.h"
-#include "Ipo.h"
-#include "DNA_object_types.h"
-#include "DNA_ipo_types.h"
-
 /*---------------------- EXPP_FloatsAreEqual -------------------------
   Floating point comparisons 
   floatStep = number of representable floats allowable in between
@@ -148,31 +134,6 @@ int StringEqual( const char *string1, const char *string2 )
        return ( strcmp( string1, string2 ) == 0 );
 }
 
-/*****************************************************************************/
-/* Description: This function returns the name of the given ID struct   */
-/*              without the Object type identifying characters prepended.   */
-/*****************************************************************************/
-char *GetIdName( ID * id )
-{
-       return ( ( id->name ) + 2 );
-}
-
-/*****************************************************************************/
-/* Description: This function returns the ID of the object with given name   */
-/*             from a given list.                                          */
-/*****************************************************************************/
-ID *GetIdFromList( ListBase * list, char *name )
-{
-       ID *id = list->first;
-
-       while( id ) {
-               if( strcmp( name, id->name + 2 ) == 0 )
-                       break;
-               id = id->next;
-       }
-
-       return id;
-}
 
 /*****************************************************************************/
 /* Description: These functions set an internal string with the given type   */
@@ -191,7 +152,6 @@ int EXPP_ReturnIntError( PyObject * type, char *error_msg )
        return -1;
 }
 
-
 int EXPP_intError(PyObject *type, const char *format, ...)
 {
        PyObject *error;
@@ -951,176 +911,3 @@ int EXPP_dict_set_item_str( PyObject *dict, char *key, PyObject *value)
        Py_DECREF( value ); /* delete original */
        return ret;
 }
-
-
-
-
-
-
-
-/* Generic get/set attrs */
-PyObject *GenericLib_getName( void *self )
-{      
-       ID *id = ((BPy_GenericLib *)self)->id;
-       if (!id) return ( EXPP_ReturnPyObjError( PyExc_RuntimeError, "data has been removed" ) );
-       return PyString_FromString( id->name + 2 );
-}
-
-int GenericLib_setName( void *self, PyObject *value )
-{
-       ID *id = ((BPy_GenericLib *)self)->id;
-       char *name = NULL;
-       if (!id) return ( EXPP_ReturnIntError( PyExc_RuntimeError, "data has been removed" ) );
-       
-       name = PyString_AsString ( value );
-       if( !name )
-               return EXPP_ReturnIntError( PyExc_TypeError,
-                                             "expected string argument" );
-
-       rename_id( id, name );
-
-       return 0;
-}
-
-PyObject *GenericLib_getFakeUser( void *self )
-{      
-       ID *id = ((BPy_GenericLib *)self)->id;
-       if (!id) return ( EXPP_ReturnPyObjError( PyExc_RuntimeError, "data has been removed" ) );
-       if (id->flag & LIB_FAKEUSER)
-               Py_RETURN_TRUE;
-       else
-               Py_RETURN_FALSE;
-}
-
-int GenericLib_setFakeUser( 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) {
-               if (!(id->flag & LIB_FAKEUSER)) {
-                       id->flag |= LIB_FAKEUSER;
-                       id_us_plus(id);
-               }
-       } else {
-               if (id->flag & LIB_FAKEUSER) {
-                       id->flag &= ~LIB_FAKEUSER;
-                       id->us--;
-               }
-       }
-       return 0;
-}
-
-/* read only */
-PyObject *GenericLib_getLib( void *self )
-{      
-       ID *id = ((BPy_GenericLib *)self)->id;
-       if (!id) return ( EXPP_ReturnPyObjError( PyExc_RuntimeError, "data has been removed" ) );
-       
-       if (id->lib)
-               return PyString_FromString(id->lib->name);
-       else
-               return EXPP_incr_ret( Py_None );
-}
-
-PyObject *GenericLib_getUsers( void *self )
-{      
-       ID *id = ((BPy_GenericLib *)self)->id;
-       if (!id) return ( EXPP_ReturnPyObjError( PyExc_RuntimeError, "data has been removed" ) );
-       return PyInt_FromLong(id->us);
-}
-
-PyObject *GenericLib_getProperties( void *self )
-{      
-       ID *id = ((BPy_GenericLib *)self)->id;
-       if (!id) return ( EXPP_ReturnPyObjError( PyExc_RuntimeError, "data has been removed" ) );
-       return BPy_Wrap_IDProperty( id, IDP_GetProperties(id, 1), NULL );
-}
-
-/* use for any.setName("name")*/
-PyObject * GenericLib_setName_with_method( void *self, PyObject *args )
-{
-       return EXPP_setterWrapper( (void *)self, args, (setter)GenericLib_setName );
-}
-
-
-/* returns the Blender lib type code from a PyObject
-   -1 for no match, only give this function libdata */
-short GenericLib_getType(PyObject * pydata)
-{
-       //~ if (BPy_Scene_Check(pydata))        return ID_SCE;
-       if (BPy_Object_Check(pydata))   return ID_OB;
-       if (BPy_Mesh_Check(pydata))             return ID_ME;
-       //~ if (BPy_Curve_Check(pydata))        return ID_CU;
-       //~ if (BPy_Metaball_Check(pydata))     return ID_MB;
-       //~ if (BPy_Material_Check(pydata))     return ID_MA;
-       if (BPy_Texture_Check(pydata))  return ID_TE;
-       //~ if (BPy_Image_Check(pydata))        return ID_IM;
-               //~ //if (BPy_Lattice_Check(pydata))    return ID_LT;
-       //~ if (BPy_Lamp_Check(pydata))         return ID_LA;
-       //~ if (BPy_Camera_Check(pydata))       return ID_CA;
-       if (BPy_Ipo_Check(pydata))              return ID_IP;
-       if (BPy_World_Check(pydata))    return ID_WO;
-               //~ //if (BPy_Font_Check(pydata))               return ID_VF;
-       //~ if (BPy_Text_Check(pydata))         return ID_TXT;
-       //~ if (BPy_Sound_Check(pydata))        return ID_SO;
-       if (BPy_Group_Check(pydata))    return ID_GR;
-       //~ if (BPy_Armature_Check(pydata))     return ID_AR;
-       //~ if (BPy_Action_Check(pydata))       return ID_AC;
-               
-       
-       
-       
-       return -1;
-}
-
-
-int GenericLib_assignData(PyObject *value, void **data, void **ndata, short refcount, short type, short subtype)
-{
-       ID *id=NULL;
-       
-       if (*data && ndata && *data == *ndata) {
-               return EXPP_ReturnIntError( PyExc_TypeError,
-                       "Cannot set this data to its self" );
-               
-               id = ((ID*)*data);
-       }
-       if (value == Py_None) {
-               *data = NULL;
-               if (refcount && id) id->us--;
-       } else if (GenericLib_getType(value) == type) {
-               
-               /* object subtypes */
-               if (subtype != 0) {
-                       if (type == ID_OB) {
-                               Object *ob= ((BPy_GenericLib *)value)->id;
-                               if (ob->type != subtype)
-                                       return EXPP_ReturnIntError( PyExc_TypeError,
-                                               "Object type not supported" );
-                       }
-                       
-                       if (type == ID_IP) {
-                               Ipo *ipo = ((BPy_GenericLib *)value)->id;
-                               if (ipo->blocktype != subtype)
-                                       return EXPP_ReturnIntError( PyExc_TypeError,
-                                               "Ipo type does is not compatible" );
-                       }
-                       
-                       
-               }
-               if (refcount && id) id->us--;
-               id = ((BPy_GenericLib *)value)->id;
-               id->us++;
-               *data = id;
-       } else {
-               return EXPP_ReturnIntError( PyExc_TypeError,
-                               "Could not assign Python Type - None or Library Object" );
-       }
-       return 0;
-} 
index 2e4a52a286b214ada132f3797591122374146d39..636e45b609eccd5a3354815a89c5cbd92a6ce88c 100644 (file)
@@ -68,10 +68,6 @@ int EXPP_VectorsAreEqual(float *vecA, float *vecB, int size, int floatSteps);
 PyObject *EXPP_GetModuleConstant(char *module, char *constant);
 
 int StringEqual( const char *string1, const char *string2 );
-char *GetIdName( ID * id );
-int SetIdFakeUser( ID * id, PyObject *value);
-
-ID *GetIdFromList( ListBase * list, char *name );
 
 PyObject *PythonReturnErrorObject( PyObject * type, char *error_msg );
 PyObject *PythonIncRef( PyObject * object );
@@ -158,53 +154,5 @@ void EXPP_allqueue(unsigned short event, short val);
 /* helper to keep dictionaries from causing memory leaks */
 int EXPP_dict_set_item_str( PyObject *dict, char *key, PyObject *value);
 
-
-
-
-
-/* Dummy struct for getting the ID from a libdata BPyObject */
-typedef struct {
-       PyObject_HEAD           /* required python macro */
-       ID *id;
-} BPy_GenericLib;
-
-
-/* ID functions for all libdata */
-#define        GENERIC_LIB_GETSETATTR \
-       {"name",\
-        (getter)GenericLib_getName, (setter)GenericLib_setName,\
-        "name",\
-        NULL},\
-       {"lib",\
-        (getter)GenericLib_getLib, (setter)NULL,\
-        "external library path",\
-        NULL},\
-       {"users",\
-        (getter)GenericLib_getUsers, (setter)NULL,\
-        "user count",\
-        NULL},\
-       {"fakeUser",\
-        (getter)GenericLib_getFakeUser, (setter)GenericLib_setFakeUser,\
-        "fake user state",\
-        NULL},\
-       {"properties",\
-        (getter)GenericLib_getProperties, (setter)NULL,\
-        "properties",\
-        NULL}
-
-
-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_getLib( void *self );
-PyObject *GenericLib_getUsers( void *self );
-PyObject *GenericLib_getProperties( void *self );
-
-/* use this for oldstyle somedata.getName("name") */
-PyObject * GenericLib_setName_with_method( void *self, PyObject *value ); 
-
-int GenericLib_assignData(PyObject *value, void **data, void **ndata, short refcount, short type, short subtype);
-short GenericLib_getType(PyObject * pydata);
-
 #endif                         /* EXPP_gen_utils_h */
+