diff options
author | Campbell Barton <ideasman42@gmail.com> | 2007-03-11 07:05:45 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2007-03-11 07:05:45 +0300 |
commit | 1135434ed18b4d89505ce0ce9673bf801e4b48e7 (patch) | |
tree | e28fbb3300ca1e5013ea2719bfae0c6173d15176 /source/blender/python/api2_2x | |
parent | 36eba6eb6c733bae0283758e7689595af023c401 (diff) |
moved python functions that deal with blender libdata into gen_library.c from gen_utils and BPY_interface
small cleanup, removed unused functions and explicetly cast pointers..
Diffstat (limited to 'source/blender/python/api2_2x')
31 files changed, 437 insertions, 294 deletions
diff --git a/source/blender/python/api2_2x/Armature.c b/source/blender/python/api2_2x/Armature.c index 6ce4f712381..409a0b90643 100644 --- a/source/blender/python/api2_2x/Armature.c +++ b/source/blender/python/api2_2x/Armature.c @@ -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" diff --git a/source/blender/python/api2_2x/Camera.c b/source/blender/python/api2_2x/Camera.c index 0bd73e11500..9f5b48000e9 100644 --- a/source/blender/python/api2_2x/Camera.c +++ b/source/blender/python/api2_2x/Camera.c @@ -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 ); diff --git a/source/blender/python/api2_2x/Curve.c b/source/blender/python/api2_2x/Curve.c index f72851e115e..21c4708490f 100644 --- a/source/blender/python/api2_2x/Curve.c +++ b/source/blender/python/api2_2x/Curve.c @@ -44,6 +44,7 @@ #include "Object.h" #include "Key.h" #include "gen_utils.h" +#include "gen_library.h" #include "mydevice.h" diff --git a/source/blender/python/api2_2x/Font.c b/source/blender/python/api2_2x/Font.c index 44fa7ff0158..1d2a1e58bd4 100644 --- a/source/blender/python/api2_2x/Font.c +++ b/source/blender/python/api2_2x/Font.c @@ -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 */ diff --git a/source/blender/python/api2_2x/Group.c b/source/blender/python/api2_2x/Group.c index 65d68c51721..b5fe226bf2c 100755 --- a/source/blender/python/api2_2x/Group.c +++ b/source/blender/python/api2_2x/Group.c @@ -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" ) ) diff --git a/source/blender/python/api2_2x/Image.c b/source/blender/python/api2_2x/Image.c index 6304964132f..41714e2cdf7 100644 --- a/source/blender/python/api2_2x/Image.c +++ b/source/blender/python/api2_2x/Image.c @@ -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" diff --git a/source/blender/python/api2_2x/Ipo.c b/source/blender/python/api2_2x/Ipo.c index 6f270839ce2..8bbcc1dce6b 100644 --- a/source/blender/python/api2_2x/Ipo.c +++ b/source/blender/python/api2_2x/Ipo.c @@ -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[]; diff --git a/source/blender/python/api2_2x/Key.c b/source/blender/python/api2_2x/Key.c index 87edb8f4e5b..f867545ce16 100644 --- a/source/blender/python/api2_2x/Key.c +++ b/source/blender/python/api2_2x/Key.c @@ -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 diff --git a/source/blender/python/api2_2x/Lamp.c b/source/blender/python/api2_2x/Lamp.c index c7ec3de5892..535a13a8431 100644 --- a/source/blender/python/api2_2x/Lamp.c +++ b/source/blender/python/api2_2x/Lamp.c @@ -44,6 +44,7 @@ #include "Ipo.h" #include "constant.h" #include "gen_utils.h" +#include "gen_library.h" /*****************************************************************************/ /* Python BPy_Lamp defaults: */ diff --git a/source/blender/python/api2_2x/Lattice.c b/source/blender/python/api2_2x/Lattice.c index 0405b40a2c6..5357fc2e647 100644 --- a/source/blender/python/api2_2x/Lattice.c +++ b/source/blender/python/api2_2x/Lattice.c @@ -49,6 +49,7 @@ #include "BIF_space.h" #include "blendef.h" #include "gen_utils.h" +#include "gen_library.h" #include "Key.h" diff --git a/source/blender/python/api2_2x/MTex.c b/source/blender/python/api2_2x/MTex.c index c345cf30fc0..9e3e1883c7b 100644 --- a/source/blender/python/api2_2x/MTex.c +++ b/source/blender/python/api2_2x/MTex.c @@ -36,6 +36,7 @@ #include "Texture.h" #include "Object.h" #include "gen_utils.h" +#include "gen_library.h" #include <DNA_material_types.h> diff --git a/source/blender/python/api2_2x/Main.c b/source/blender/python/api2_2x/Main.c index 8680dcbebba..a5def464acd 100644 --- a/source/blender/python/api2_2x/Main.c +++ b/source/blender/python/api2_2x/Main.c @@ -76,9 +76,10 @@ #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; } diff --git a/source/blender/python/api2_2x/Main.h b/source/blender/python/api2_2x/Main.h index a76b9fc5160..f1dd6c0782e 100644 --- a/source/blender/python/api2_2x/Main.h +++ b/source/blender/python/api2_2x/Main.h @@ -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) diff --git a/source/blender/python/api2_2x/Material.c b/source/blender/python/api2_2x/Material.c index 25eebaa860e..6a2ee287e9a 100644 --- a/source/blender/python/api2_2x/Material.c +++ b/source/blender/python/api2_2x/Material.c @@ -53,6 +53,7 @@ #include "Ipo.h" #include "Group.h" #include "gen_utils.h" +#include "gen_library.h" #include "IDProp.h" /*****************************************************************************/ diff --git a/source/blender/python/api2_2x/Mesh.c b/source/blender/python/api2_2x/Mesh.c index 963c1051662..f7006d9e95a 100644 --- a/source/blender/python/api2_2x/Mesh.c +++ b/source/blender/python/api2_2x/Mesh.c @@ -87,6 +87,7 @@ #include "meshPrimitive.h" #include "constant.h" #include "gen_utils.h" +#include "gen_library.h" #include "multires.h" /* EXPP Mesh defines */ diff --git a/source/blender/python/api2_2x/Metaball.c b/source/blender/python/api2_2x/Metaball.c index 6cef3227943..94b5535c520 100644 --- a/source/blender/python/api2_2x/Metaball.c +++ b/source/blender/python/api2_2x/Metaball.c @@ -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" diff --git a/source/blender/python/api2_2x/Modifier.c b/source/blender/python/api2_2x/Modifier.c index 8ddbb2f9dcf..a18b12ece8d 100644 --- a/source/blender/python/api2_2x/Modifier.c +++ b/source/blender/python/api2_2x/Modifier.c @@ -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" ) ) diff --git a/source/blender/python/api2_2x/NLA.c b/source/blender/python/api2_2x/NLA.c index 5cfed7b4e29..2c7f466cb56 100644 --- a/source/blender/python/api2_2x/NLA.c +++ b/source/blender/python/api2_2x/NLA.c @@ -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" diff --git a/source/blender/python/api2_2x/Object.c b/source/blender/python/api2_2x/Object.c index 9014a923cce..543702a8054 100644 --- a/source/blender/python/api2_2x/Object.c +++ b/source/blender/python/api2_2x/Object.c @@ -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" diff --git a/source/blender/python/api2_2x/Pose.c b/source/blender/python/api2_2x/Pose.c index 364b37d3e67..2b4f67c9b8c 100644 --- a/source/blender/python/api2_2x/Pose.c +++ b/source/blender/python/api2_2x/Pose.c @@ -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 diff --git a/source/blender/python/api2_2x/Scene.c b/source/blender/python/api2_2x/Scene.c index 4924cc8c9e4..89efe42ef28 100644 --- a/source/blender/python/api2_2x/Scene.c +++ b/source/blender/python/api2_2x/Scene.c @@ -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" diff --git a/source/blender/python/api2_2x/Sound.c b/source/blender/python/api2_2x/Sound.c index 6c6841aa4c5..04cca0bd3c2 100644 --- a/source/blender/python/api2_2x/Sound.c +++ b/source/blender/python/api2_2x/Sound.c @@ -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 */ /*****************************************************************************/ diff --git a/source/blender/python/api2_2x/SurfNurb.c b/source/blender/python/api2_2x/SurfNurb.c index 701fe4c6531..cea8df325b2 100644 --- a/source/blender/python/api2_2x/SurfNurb.c +++ b/source/blender/python/api2_2x/SurfNurb.c @@ -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" /* diff --git a/source/blender/python/api2_2x/Text.c b/source/blender/python/api2_2x/Text.c index f94ebafeee7..5aae39fb336 100644 --- a/source/blender/python/api2_2x/Text.c +++ b/source/blender/python/api2_2x/Text.c @@ -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 */ diff --git a/source/blender/python/api2_2x/Text3d.c b/source/blender/python/api2_2x/Text3d.c index 1a3a765c756..c91a55e1e24 100644 --- a/source/blender/python/api2_2x/Text3d.c +++ b/source/blender/python/api2_2x/Text3d.c @@ -45,6 +45,7 @@ #include "constant.h" #include "Font.h" #include "gen_utils.h" +#include "gen_library.h" enum t3d_consts { diff --git a/source/blender/python/api2_2x/Texture.c b/source/blender/python/api2_2x/Texture.c index 1f2f54aadd3..ffa61d3794f 100644 --- a/source/blender/python/api2_2x/Texture.c +++ b/source/blender/python/api2_2x/Texture.c @@ -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 */ diff --git a/source/blender/python/api2_2x/World.c b/source/blender/python/api2_2x/World.c index 95436027f8c..32cc16c73ba 100644 --- a/source/blender/python/api2_2x/World.c +++ b/source/blender/python/api2_2x/World.c @@ -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 index 00000000000..af7b031f0fc --- /dev/null +++ b/source/blender/python/api2_2x/gen_library.c @@ -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 index 00000000000..5f81424ca3a --- /dev/null +++ b/source/blender/python/api2_2x/gen_library.h @@ -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 */ diff --git a/source/blender/python/api2_2x/gen_utils.c b/source/blender/python/api2_2x/gen_utils.c index 2a4a57f8021..4cebcfcb056 100644 --- a/source/blender/python/api2_2x/gen_utils.c +++ b/source/blender/python/api2_2x/gen_utils.c @@ -41,24 +41,10 @@ #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; -} diff --git a/source/blender/python/api2_2x/gen_utils.h b/source/blender/python/api2_2x/gen_utils.h index 2e4a52a286b..636e45b609e 100644 --- a/source/blender/python/api2_2x/gen_utils.h +++ b/source/blender/python/api2_2x/gen_utils.h @@ -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 */ + |