Added python __copy__ to Camera, Lattice, Metaball and World.

This commit is contained in:
2006-08-16 14:06:24 +00:00
parent b92837c7c3
commit 9ef3e8092b
4 changed files with 115 additions and 0 deletions

View File

@@ -122,6 +122,7 @@ static PyObject *Camera_getScriptLinks( BPy_Camera * self, PyObject * args );
static PyObject *Camera_addScriptLink( BPy_Camera * self, PyObject * args );
static PyObject *Camera_clearScriptLinks( BPy_Camera * self, PyObject * args );
static PyObject *Camera_insertIpoKey( BPy_Camera * self, PyObject * args );
static PyObject *Camera_copy( BPy_Camera * self );
Camera *GetCameraByName( char *name );
@@ -184,6 +185,8 @@ static PyMethodDef BPy_Camera_methods[] = {
METH_NOARGS,
"() - Delete all scriptlinks from this camera.\n"
"([s1<,s2,s3...>]) - Delete specified scriptlinks from this camera."},
{"__copy__", ( PyCFunction ) Camera_copy, METH_NOARGS,
"() - Return a copy of the camera."},
{NULL, NULL, 0, NULL}
};
@@ -811,6 +814,31 @@ static PyObject *Camera_getScriptLinks( BPy_Camera * self, PyObject * args )
return NULL;
}
/* cam.__copy__ */
static PyObject *Camera_copy( BPy_Camera * self )
{
PyObject *pycam; /* for Camera Data object wrapper in Python */
Camera *blcam; /* for actual Camera Data we create in Blender */
blcam = copy_camera( self->camera ); /* first create the Camera Data in Blender */
if( blcam ) /* now create the wrapper obj in Python */
pycam = Camera_CreatePyObject( blcam );
else
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
"couldn't create Camera Data in Blender" );
/* let's return user count to zero, because ... */
blcam->id.us = 0; /* ... copy_camera() incref'ed it */
/* XXX XXX Do this in other modules, too */
if( pycam == NULL )
return EXPP_ReturnPyObjError( PyExc_MemoryError,
"couldn't create Camera PyObject" );
return pycam;
}
static void Camera_dealloc( BPy_Camera * self )
{
PyObject_DEL( self );

View File

@@ -99,6 +99,7 @@ static PyObject *Lattice_setPoint( BPy_Lattice * self, PyObject * args );
static PyObject *Lattice_getPoint( BPy_Lattice * self, PyObject * args );
static PyObject *Lattice_applyDeform( BPy_Lattice * self, PyObject *args );
static PyObject *Lattice_insertKey( BPy_Lattice * self, PyObject * args );
static PyObject *Lattice_copy( BPy_Lattice * self );
/*****************************************************************************/
/* Lattice Strings */
@@ -146,6 +147,9 @@ mode). If forced, the deformation will be applied over any previous one(s).";
static char Lattice_insertKey_doc[] =
"(str) - Set a new key for the lattice at specified frame";
static char Lattice_copy_doc[] =
"() - Return a copy of the lattice.";
/*****************************************************************************/
/* Python BPy_Lattice methods table: */
/*****************************************************************************/
@@ -177,6 +181,8 @@ static PyMethodDef BPy_Lattice_methods[] = {
Lattice_applyDeform_doc},
{"insertKey", ( PyCFunction ) Lattice_insertKey, METH_VARARGS,
Lattice_insertKey_doc},
{"__copy__", ( PyCFunction ) Lattice_copy, METH_NOARGS,
Lattice_copy_doc},
{NULL, NULL, 0, NULL}
};
@@ -769,6 +775,26 @@ static PyObject *Lattice_insertKey( BPy_Lattice * self, PyObject * args )
return Py_None;
}
static PyObject *Lattice_copy( BPy_Lattice * self )
{
Lattice *bl_Lattice; // blender Lattice object
PyObject *py_Lattice; // python wrapper
bl_Lattice = copy_lattice( self->Lattice );
bl_Lattice->id.us = 0;
if( bl_Lattice )
py_Lattice = Lattice_CreatePyObject( bl_Lattice );
else
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
"couldn't create Lattice Object in Blender" );
if( !py_Lattice )
return EXPP_ReturnPyObjError( PyExc_MemoryError,
"couldn't create Lattice Object wrapper" );
return py_Lattice;
}
//***************************************************************************
// Function: Lattice_dealloc
// Description: This is a callback function for the BPy_Lattice type. It is

View File

@@ -108,6 +108,7 @@ static PyObject *Metaball_getrot( BPy_Metaball * self );
static PyObject *Metaball_setrot( BPy_Metaball * self, PyObject * args );
static PyObject *Metaball_getsize( BPy_Metaball * self );
static PyObject *Metaball_setsize( BPy_Metaball * self, PyObject * args );
static PyObject *Metaball_copy( BPy_Metaball * self );
/*****************************************************************************/
/* Python BPy_Metaball methods table: */
@@ -180,6 +181,8 @@ static PyMethodDef BPy_Metaball_methods[] = {
METH_NOARGS, "() - Gets Metaball size values"},
{"setsize", ( PyCFunction ) Metaball_setsize,
METH_VARARGS, "(f f f) - Sets Metaball size values"},
{"__copy__", ( PyCFunction ) Metaball_copy,
METH_NOARGS, "() - Return a copy of this metaball"},
{NULL, NULL, 0, NULL}
};
@@ -678,6 +681,34 @@ static PyObject *Metaball_setThresh( BPy_Metaball * self, PyObject * args )
}
static PyObject *Metaball_copy( BPy_Metaball * self )
{
BPy_Metaball *pymball; /* for Data object wrapper in Python */
MetaBall *blmball; /* for actual Data we create in Blender */
blmball = copy_mball( self->metaball ); /* first create the MetaBall Data in Blender */
if( blmball ) {
/* return user count to zero since add_mball() incref'ed it */
blmball->id.us = 0;
/* now create the wrapper obj in Python */
pymball =
( BPy_Metaball * ) PyObject_NEW( BPy_Metaball,
&Metaball_Type );
} else
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
"couldn't create MetaBall Data in Blender" ) );
if( pymball == NULL )
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
"couldn't create MetaBall Data object" ) );
pymball->metaball = blmball;
return ( PyObject * ) pymball;
}
/**************************************************************************/
/* get/set metaelems data, */
/***************************************************************************/

View File

@@ -95,6 +95,7 @@ static PyObject *World_getScriptLinks( BPy_World * self, PyObject * args );
static PyObject *World_addScriptLink( BPy_World * self, PyObject * args );
static PyObject *World_clearScriptLinks( BPy_World * self, PyObject * args );
static PyObject *World_setCurrent( BPy_World * self );
static PyObject *World_copy( BPy_World * self );
/*****************************************************************************/
@@ -222,6 +223,8 @@ static PyMethodDef BPy_World_methods[] = {
"please use setCurrent instead, this alias will be removed."},
{"insertIpoKey", ( PyCFunction ) World_insertIpoKey, METH_VARARGS,
"( World IPO type ) - Inserts a key into the IPO"},
{"__copy__", ( PyCFunction ) World_copy, METH_NOARGS,
"() - Makes a copy of this world."},
{NULL, NULL, 0, NULL}
};
@@ -897,6 +900,33 @@ static PyObject *World_setCurrent( BPy_World * self )
return Py_None;
}
/* world.__copy__ */
static PyObject *World_copy( BPy_World * self )
{
BPy_World *pyworld;
World *blworld;
blworld = copy_world( self->world );
if( blworld ) {
/* return user count to zero because add_world() inc'd it */
blworld->id.us = 0;
/* create python wrapper obj */
pyworld =
( BPy_World * ) PyObject_NEW( BPy_World, &World_Type );
} else
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
"couldn't create World Data in Blender" ) );
if( pyworld == NULL )
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
"couldn't create World Data object" ) );
pyworld->world = blworld;
return ( PyObject * ) pyworld;
}
/*@{*/