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..
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user