Page Menu
Home
Search
Configure Global Search
Log In
Files
F1790
ipo.patch
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Authored By
Ken Hughes (khughes)
Nov 13 2013, 1:00 PM
Size
101 KB
Subscribers
None
ipo.patch
View Options
Index: source/blender/python/api2_2x/Ipo.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/Ipo.c,v
retrieving revision 1.49
diff -u -r1.49 Ipo.c
--- source/blender/python/api2_2x/Ipo.c 5 Jan 2006 19:25:38 -0000 1.49
+++ source/blender/python/api2_2x/Ipo.c 12 Mar 2006 18:46:00 -0000
@@ -1,5 +1,5 @@
/*
- * $Id: Ipo.c,v 1.49 2006/01/05 19:25:38 khughes Exp $
+ * $Id: Ipo.c,v 1.47 2005/11/07 19:34:44 ascotan Exp $
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
@@ -45,6 +45,17 @@
#include "Ipocurve.h"
#include "gen_utils.h"
+extern int ob_ar[];
+extern int la_ar[];
+extern int ma_ar[];
+extern int ac_ar[];
+extern int cam_ar[];
+extern int co_ar[];
+extern int cu_ar[];
+extern int seq_ar[];
+extern int te_ar[];
+extern int wo_ar[];
+
/*****************************************************************************/
/* Python API function prototypes for the Ipo module. */
/*****************************************************************************/
@@ -61,7 +72,6 @@
char M_Ipo_New_doc[] = "";
char M_Ipo_Get_doc[] = "";
-
/*****************************************************************************/
/* Python method structure definition for Blender.Ipo module: */
/*****************************************************************************/
@@ -83,10 +93,12 @@
static PyObject *Ipo_getBlocktype( BPy_Ipo * self );
static PyObject *Ipo_setBlocktype( BPy_Ipo * self, PyObject * args );
static PyObject *Ipo_getRctf( BPy_Ipo * self );
-static PyObject *Ipo_setRctf( BPy_Ipo * self, PyObject * args );
+static PyObject *Ipo_oldsetRctf( BPy_Ipo * self, PyObject * args );
+static int Ipo_setRctf( BPy_Ipo * self, PyObject * args );
static PyObject *Ipo_getCurve( BPy_Ipo * self, PyObject * args );
static PyObject *Ipo_getCurves( BPy_Ipo * self );
+static PyObject *Ipo_getCurveNames( BPy_Ipo * self );
static PyObject *Ipo_addCurve( BPy_Ipo * self, PyObject * args );
static PyObject *Ipo_delCurve( BPy_Ipo * self, PyObject * args );
static PyObject *Ipo_getNcurves( BPy_Ipo * self );
@@ -96,10 +108,18 @@
static PyObject *Ipo_getCurvecurval( BPy_Ipo * self, PyObject * args );
static PyObject *Ipo_EvaluateCurveOn( BPy_Ipo * self, PyObject * args );
-
static PyObject *Ipo_setCurveBeztriple( BPy_Ipo * self, PyObject * args );
static PyObject *Ipo_getCurveBeztriple( BPy_Ipo * self, PyObject * args );
+static PyObject *Ipo_getChannel( BPy_Ipo * self );
+static int Ipo_setChannel( BPy_Ipo * self, PyObject * args );
+
+static int Ipo_length( BPy_Ipo * inst );
+static PyObject *Ipo_getIpoCurveByName( BPy_Ipo * self, PyObject * key );
+static int Ipo_setIpoCurveByName( BPy_Ipo * self, PyObject * key,
+ PyObject * value );
+static int Ipo_contains( BPy_Ipo * self, PyObject * key );
+
/*****************************************************************************/
/* Python BPy_Ipo methods table: */
/*****************************************************************************/
@@ -115,7 +135,7 @@
"(str) - Change Ipo blocktype"},
{"getRctf", ( PyCFunction ) Ipo_getRctf, METH_NOARGS,
"() - Return Ipo rctf"},
- {"setRctf", ( PyCFunction ) Ipo_setRctf, METH_VARARGS,
+ {"setRctf", ( PyCFunction ) Ipo_oldsetRctf, METH_VARARGS,
"(flt,flt,flt,flt) - Change Ipo rctf"},
{"addCurve", ( PyCFunction ) Ipo_addCurve, METH_VARARGS,
"() - Add a curve to Ipo"},
@@ -123,6 +143,10 @@
"(str) - Delete curve from Ipo"},
{"getNcurves", ( PyCFunction ) Ipo_getNcurves, METH_NOARGS,
"() - Return number of Ipo curves"},
+ {"getCurves", ( PyCFunction ) Ipo_getCurves, METH_NOARGS,
+ "() - Return list of all defined Ipo curves"},
+ {"getCurve", ( PyCFunction ) Ipo_getCurve, METH_VARARGS,
+ "(str|int) - Returns specified Ipo curve"},
{"getNBezPoints", ( PyCFunction ) Ipo_getNBezPoints, METH_VARARGS,
"(int) - Return number of Bez points on an Ipo curve"},
{"delBezPoint", ( PyCFunction ) Ipo_DeleteBezPoints, METH_VARARGS,
@@ -137,93 +161,384 @@
"(int,int) - deprecated: see ipocurve.bezierPoints[]"},
{"setCurveBeztriple", ( PyCFunction ) Ipo_setCurveBeztriple, METH_VARARGS,
"(int,int,list) - set a BezTriple"},
- {"getCurves", ( PyCFunction ) Ipo_getCurves, METH_NOARGS,
- "() - Return list of all defined Ipo curves"},
- {"getCurve", ( PyCFunction ) Ipo_getCurve, METH_VARARGS,
- "(str|int) - Returns specified Ipo curve"},
{NULL, NULL, 0, NULL}
};
/*****************************************************************************/
-/* Python Ipo_Type callback function prototypes: */
+/* Python BPy_Ipo attributes get/set structure: */
+/*****************************************************************************/
+static PyGetSetDef BPy_Ipo_getseters[] = {
+ {"name",
+ (getter)Ipo_getName, (setter)Ipo_setName,
+ "Ipo data name",
+ NULL},
+ {"curves",
+ (getter)Ipo_getCurves, (setter)NULL,
+ "Ipo curves",
+ NULL},
+ {"curveNames",
+ (getter)Ipo_getCurveNames, (setter)NULL,
+ "Ipo curve names dictionary",
+ NULL},
+ {"channel",
+ (getter)Ipo_getChannel, (setter)Ipo_setChannel,
+ "Ipo texture channel (world, lamp, material Ipos only)",
+ NULL},
+
+ {"blocktype",
+ (getter)Ipo_getBlocktype, (setter)NULL,
+ "Ipo block type",
+ NULL},
+ {"rcft",
+ (getter)Ipo_getRctf, (setter)Ipo_setRctf,
+ "Ipo type",
+ NULL},
+ {NULL,NULL,NULL,NULL,NULL} /* Sentinel */
+};
+
+/*****************************************************************************/
+/* Python Ipo_Type Mapping Methods table: */
+/*****************************************************************************/
+static PyMappingMethods Ipo_as_mapping = {
+ ( inquiry ) Ipo_length, /* mp_length */
+ ( binaryfunc ) Ipo_getIpoCurveByName, /* mp_subscript */
+ ( objobjargproc ) Ipo_setIpoCurveByName, /* mp_ass_subscript */
+};
+
+static PySequenceMethods Ipo_as_sequence = {
+ ( inquiry ) 0, /* sq_length */
+ ( binaryfunc ) 0, /* sq_concat */
+ ( intargfunc ) 0, /* sq_repeat */
+ ( intargfunc ) 0, /* sq_item */
+ ( intintargfunc ) 0, /* sq_slice */
+ ( intobjargproc ) 0, /* sq_ass_item */
+ ( intintobjargproc ) 0, /* sq_ass_slice */
+ ( objobjproc ) Ipo_contains, /* sq_contains */
+ ( binaryfunc ) 0, /* sq_inplace_concat */
+ ( intargfunc ) 0, /* sq_inplace_repeat */
+};
+
+/*****************************************************************************/
+/* Python Ipo_Type callback function prototypes: */
/*****************************************************************************/
-static void IpoDeAlloc( BPy_Ipo * self );
+static void Ipo_dealloc( BPy_Ipo * self );
//static int IpoPrint (BPy_Ipo *self, FILE *fp, int flags);
-static int IpoSetAttr( BPy_Ipo * self, char *name, PyObject * v );
-static PyObject *IpoGetAttr( BPy_Ipo * self, char *name );
-static PyObject *IpoRepr( BPy_Ipo * self );
+static PyObject *Ipo_repr( BPy_Ipo * self );
+static PyObject *Ipo_getIter( BPy_Ipo * self );
+static PyObject *Ipo_nextIter( BPy_Ipo * self );
/*****************************************************************************/
-/* Python Ipo_Type structure definition: */
+/* Python Ipo_Type structure definition: */
/*****************************************************************************/
PyTypeObject Ipo_Type = {
- PyObject_HEAD_INIT( NULL ) /* required macro */ 0, /* ob_size */
- "Ipo", /* tp_name */
- sizeof( BPy_Ipo ), /* tp_basicsize */
- 0, /* tp_itemsize */
- /* methods */
- ( destructor ) IpoDeAlloc, /* tp_dealloc */
- 0, /* tp_print */
- ( getattrfunc ) IpoGetAttr, /* tp_getattr */
- ( setattrfunc ) IpoSetAttr, /* tp_setattr */
- 0, /* tp_compare */
- ( reprfunc ) IpoRepr, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_as_hash */
- 0, 0, 0, 0, 0, 0,
- 0, /* tp_doc */
- 0, 0, 0, 0, 0, 0,
- BPy_Ipo_methods, /* tp_methods */
- 0, /* tp_members */
+ PyObject_HEAD_INIT( NULL ) /* required py macro */
+ 0, /* ob_size */
+ /* For printing, in format "<module>.<name>" */
+ "Blender Ipo", /* char *tp_name; */
+ sizeof( BPy_Ipo ), /* int tp_basicsize; */
+ 0, /* tp_itemsize; For allocation */
+
+ /* Methods to implement standard operations */
+
+ ( destructor ) Ipo_dealloc,/* destructor tp_dealloc; */
+ NULL, /* printfunc tp_print; */
+ NULL, /* getattrfunc tp_getattr; */
+ NULL, /* setattrfunc tp_setattr; */
+ NULL, /* cmpfunc tp_compare; */
+ ( reprfunc ) Ipo_repr, /* reprfunc tp_repr; */
+
+ /* Method suites for standard classes */
+
+ NULL, /* PyNumberMethods *tp_as_number; */
+ &Ipo_as_sequence, /* PySequenceMethods *tp_as_sequence; */
+ &Ipo_as_mapping, /* PyMappingMethods *tp_as_mapping; */
+
+ /* More standard operations (here for binary compatibility) */
+
+ NULL, /* hashfunc tp_hash; */
+ NULL, /* ternaryfunc tp_call; */
+ NULL, /* reprfunc tp_str; */
+ NULL, /* getattrofunc tp_getattro; */
+ NULL, /* setattrofunc tp_setattro; */
+
+ /* Functions to access object as input/output buffer */
+ NULL, /* PyBufferProcs *tp_as_buffer; */
+
+ /*** Flags to define presence of optional/expanded features ***/
+ Py_TPFLAGS_DEFAULT, /* long tp_flags; */
+
+ NULL, /* char *tp_doc; Documentation string */
+ /*** Assigned meaning in release 2.0 ***/
+ /* call function for all accessible objects */
+ NULL, /* traverseproc tp_traverse; */
+
+ /* delete references to contained objects */
+ NULL, /* inquiry tp_clear; */
+
+ /*** Assigned meaning in release 2.1 ***/
+ /*** rich comparisons ***/
+ NULL, /* richcmpfunc tp_richcompare; */
+
+ /*** weak reference enabler ***/
+ 0, /* long tp_weaklistoffset; */
+
+ /*** Added in release 2.2 ***/
+ /* Iterators */
+ ( getiterfunc) Ipo_getIter, /* getiterfunc tp_iter; */
+ ( iternextfunc ) Ipo_nextIter, /* iternextfunc tp_iternext; */
+
+ /*** Attribute descriptor and subclassing stuff ***/
+ BPy_Ipo_methods, /* struct PyMethodDef *tp_methods; */
+ NULL, /* struct PyMemberDef *tp_members; */
+ BPy_Ipo_getseters, /* struct PyGetSetDef *tp_getset; */
+ NULL, /* struct _typeobject *tp_base; */
+ NULL, /* PyObject *tp_dict; */
+ NULL, /* descrgetfunc tp_descr_get; */
+ NULL, /* descrsetfunc tp_descr_set; */
+ 0, /* long tp_dictoffset; */
+ NULL, /* initproc tp_init; */
+ NULL, /* allocfunc tp_alloc; */
+ NULL, /* newfunc tp_new; */
+ /* Low-level free-memory routine */
+ NULL, /* freefunc tp_free; */
+ /* For PyObject_IS_GC */
+ NULL, /* inquiry tp_is_gc; */
+ NULL, /* PyObject *tp_bases; */
+ /* method resolution order */
+ NULL, /* PyObject *tp_mro; */
+ NULL, /* PyObject *tp_cache; */
+ NULL, /* PyObject *tp_subclasses; */
+ NULL, /* PyObject *tp_weaklist; */
+ NULL
};
/*****************************************************************************/
+/* internal utility routines */
+/*****************************************************************************/
+
+/*
+ * Search through list of known Ipocurves for a particular name.
+ *
+ * str: name of curve we are searching for
+ * blocktype: type of Ipo
+ * channel: texture channel number, for World/Lamp/Material curves
+ *
+ * returns the adrcode for the named curve if it exists, -1 otherwise
+ */
+
+/* this is needed since getname_ob_ei() is different from the rest */
+
+typedef char * (*namefunc)(int, ... );
+
+static short lookup_curve_name( char *str, int blocktype, int channel )
+{
+ namefunc lookup_name;
+ int *adrcodes = NULL;
+ int size = 0;
+
+ /* make sure channel type is ignored when it should be */
+ if( blocktype != ID_WO && blocktype != ID_LA && blocktype != ID_MA )
+ channel = -1;
+
+ switch ( blocktype ) {
+ case ID_OB:
+ lookup_name = (namefunc)getname_ob_ei;
+ adrcodes = ob_ar;
+ size = OB_TOTIPO;
+ break;
+ case ID_MA:
+ lookup_name = (namefunc)getname_mat_ei;
+ adrcodes = ma_ar;
+ size = MA_TOTIPO;
+ break;
+ case ID_CA:
+ lookup_name = (namefunc)getname_cam_ei;
+ adrcodes = cam_ar;
+ size = CAM_TOTIPO;
+ break;
+ case ID_LA:
+ lookup_name = (namefunc)getname_la_ei;
+ adrcodes = la_ar;
+ size = LA_TOTIPO;
+ break;
+ case ID_TE:
+ lookup_name = (namefunc)getname_tex_ei;
+ adrcodes = te_ar;
+ size = TE_TOTIPO;
+ break;
+ case ID_WO:
+ lookup_name = (namefunc)getname_world_ei;
+ adrcodes = wo_ar;
+ size = WO_TOTIPO;
+ break;
+ case ID_PO:
+ lookup_name = (namefunc)getname_ac_ei;
+ adrcodes = ac_ar;
+ size = AC_TOTIPO;
+ break;
+ case ID_CO:
+ lookup_name = (namefunc)getname_co_ei;
+ adrcodes = co_ar;
+ size = CO_TOTIPO;
+ break;
+ case ID_CU:
+ lookup_name = (namefunc)getname_cu_ei;
+ adrcodes = cu_ar;
+ size = CU_TOTIPO;
+ break;
+ case ID_SEQ:
+ lookup_name = (namefunc)getname_seq_ei;
+ adrcodes = seq_ar;
+ size = SEQ_TOTIPO;
+ break;
+ case ID_KE:
+ default:
+ return -1;
+ }
+
+ while ( size-- ) {
+ char *name = lookup_name ( *adrcodes );
+
+ /* if not a texture channel, just return the adrcode */
+ if( !strncmp( str, name, strlen( name ) ) ) {
+ if( channel == -1 || *adrcodes < MA_MAP1 )
+ return (short)*adrcodes;
+
+ /* otherwise adjust adrcode to include current channel */
+ else {
+ int param = (short)*adrcodes & ~MA_MAP1;
+ param |= texchannel_to_adrcode( channel );
+ return param;
+ }
+ }
+ ++adrcodes;
+ }
+ return -1;
+}
+
+/*
+ * Search through list of known Ipocurves for a particular adrcode.
+ *
+ * code: adrcode of curve we are searching for
+ * blocktype: type of Ipo
+ * channel: texture channel number, for World/Lamp/Material curves
+ *
+ * returns the adrcode for the named curve if it exists, -1 otherwise
+ */
+
+static short lookup_curve_adrcode( int code, int blocktype, int channel )
+{
+ int *adrcodes = NULL;
+ int size = 0;
+
+ switch ( blocktype ) {
+ case ID_OB:
+ adrcodes = ob_ar;
+ size = OB_TOTIPO;
+ break;
+ case ID_MA:
+ adrcodes = ma_ar;
+ size = MA_TOTIPO;
+ break;
+ case ID_CA:
+ adrcodes = cam_ar;
+ size = CAM_TOTIPO;
+ break;
+ case ID_LA:
+ adrcodes = la_ar;
+ size = LA_TOTIPO;
+ break;
+ case ID_TE:
+ adrcodes = te_ar;
+ size = TE_TOTIPO;
+ break;
+ case ID_WO:
+ adrcodes = wo_ar;
+ size = WO_TOTIPO;
+ break;
+ case ID_PO:
+ adrcodes = ac_ar;
+ size = AC_TOTIPO;
+ break;
+ case ID_CO:
+ adrcodes = co_ar;
+ size = CO_TOTIPO;
+ break;
+ case ID_CU:
+ adrcodes = cu_ar;
+ size = CU_TOTIPO;
+ break;
+ case ID_SEQ:
+ adrcodes = seq_ar;
+ size = SEQ_TOTIPO;
+ break;
+ case ID_KE:
+ default:
+ return -1;
+ }
+
+ while ( size-- ) {
+ if( *adrcodes == code ) {
+
+ /* if not a texture channel, just return the adrcode */
+ if( channel == -1 || *adrcodes < MA_MAP1 )
+ return *adrcodes;
+
+ /* otherwise adjust adrcode to include current channel */
+ else {
+ int param = *adrcodes & ~MA_MAP1;
+ param |= texchannel_to_adrcode( channel );
+ return param;
+ }
+ }
+ ++adrcodes;
+ }
+ return -1;
+}
+
+/*****************************************************************************/
+/* Python BPy_Ipo functions: */
+/*****************************************************************************/
+
+/*****************************************************************************/
/* Function: M_Ipo_New */
/* Python equivalent: Blender.Ipo.New */
/*****************************************************************************/
static PyObject *M_Ipo_New( PyObject * self, PyObject * args )
{
- Ipo *add_ipo( char *name, int idcode );
char *name = NULL, *code = NULL;
int idcode = -1;
- BPy_Ipo *pyipo;
Ipo *blipo;
if( !PyArg_ParseTuple( args, "ss", &code, &name ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError,
- "expected string string arguments" ) );
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected two string arguments" );
if( !strcmp( code, "Object" ) )
idcode = ID_OB;
- if( !strcmp( code, "Camera" ) )
+ else if( !strcmp( code, "Camera" ) )
idcode = ID_CA;
- if( !strcmp( code, "World" ) )
+ else if( !strcmp( code, "World" ) )
idcode = ID_WO;
- if( !strcmp( code, "Material" ) )
+ else if( !strcmp( code, "Material" ) )
idcode = ID_MA;
- if( !strcmp( code, "Texture" ) )
+ else if( !strcmp( code, "Texture" ) )
idcode = ID_TE;
- if( !strcmp( code, "Lamp" ) )
+ else if( !strcmp( code, "Lamp" ) )
idcode = ID_LA;
- if( !strcmp( code, "Action" ) )
+ else if( !strcmp( code, "Action" ) )
idcode = ID_PO;
- if( !strcmp( code, "Constraint" ) )
+ else if( !strcmp( code, "Constraint" ) )
idcode = ID_CO;
- if( !strcmp( code, "Sequence" ) )
+ else if( !strcmp( code, "Sequence" ) )
idcode = ID_SEQ;
- if( !strcmp( code, "Curve" ) )
+ else if( !strcmp( code, "Curve" ) )
idcode = ID_CU;
- if( !strcmp( code, "Key" ) )
+ else if( !strcmp( code, "Key" ) )
idcode = ID_KE;
-
- if( idcode == -1 )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "Bad code" ) );
-
+ else return EXPP_ReturnPyObjError( PyExc_ValueError,
+ "unknown Ipo code" );
blipo = add_ipo( name, idcode );
@@ -231,18 +546,10 @@
/* return user count to zero because add_ipo() inc'd it */
blipo->id.us = 0;
/* create python wrapper obj */
- pyipo = ( BPy_Ipo * ) PyObject_NEW( BPy_Ipo, &Ipo_Type );
+ return Ipo_CreatePyObject( blipo );
} else
- return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "couldn't create Ipo Data in Blender" ) );
-
- if( pyipo == NULL )
- return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
- "couldn't create Ipo Data object" ) );
-
- pyipo->ipo = blipo;
-
- return ( PyObject * ) pyipo;
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "couldn't create Ipo Data in Blender" );
}
/*****************************************************************************/
@@ -258,7 +565,6 @@
char *name = NULL;
Ipo *ipo_iter;
PyObject *ipolist, *pyobj;
- BPy_Ipo *wanted_ipo = NULL;
char error_msg[64];
if( !PyArg_ParseTuple( args, "|s", &name ) )
@@ -268,25 +574,16 @@
ipo_iter = G.main->ipo.first;
if( name ) { /* (name) - Search ipo by name */
- while( ( ipo_iter ) && ( wanted_ipo == NULL ) ) {
- if( strcmp( name, ipo_iter->id.name + 2 ) == 0 ) {
- wanted_ipo =
- ( BPy_Ipo * ) PyObject_NEW( BPy_Ipo,
- &Ipo_Type );
- if( wanted_ipo )
- wanted_ipo->ipo = ipo_iter;
+ while( ipo_iter ) {
+ if( !strcmp( name, ipo_iter->id.name + 2 ) ) {
+ return Ipo_CreatePyObject( ipo_iter );
}
ipo_iter = ipo_iter->id.next;
}
- if( wanted_ipo == NULL ) { /* Requested ipo doesn't exist */
- PyOS_snprintf( error_msg, sizeof( error_msg ),
- "Ipo \"%s\" not found", name );
- return ( EXPP_ReturnPyObjError
- ( PyExc_NameError, error_msg ) );
- }
-
- return ( PyObject * ) wanted_ipo;
+ PyOS_snprintf( error_msg, sizeof( error_msg ),
+ "Ipo \"%s\" not found", name );
+ return EXPP_ReturnPyObjError( PyExc_NameError, error_msg );
}
else { /* () - return a list with all ipos in the scene */
@@ -294,17 +591,15 @@
ipolist = PyList_New( BLI_countlist( &( G.main->ipo ) ) );
- if( ipolist == NULL )
- return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
- "couldn't create PyList" ) );
+ if( !ipolist )
+ return EXPP_ReturnPyObjError( PyExc_MemoryError,
+ "couldn't create PyList" );
while( ipo_iter ) {
pyobj = Ipo_CreatePyObject( ipo_iter );
if( !pyobj )
- return ( EXPP_ReturnPyObjError
- ( PyExc_MemoryError,
- "couldn't create PyString" ) );
+ return NULL;
PyList_SET_ITEM( ipolist, index, pyobj );
@@ -312,55 +607,48 @@
index++;
}
- return ( ipolist );
+ return ipolist;
}
}
+/*
+ * This should probably be deprecated too? Or else documented in epydocs.
+ * Seems very similar to Ipocurve.recalc().
+ */
+/*****************************************************************************/
+/* Function: M_Ipo_Recalc */
+/* Python equivalent: Blender.Ipo.Recalc */
+/* Description: Receives (presumably) an IpoCurve object and */
+/* updates the curve after changes to control points. */
+/*****************************************************************************/
static PyObject *M_Ipo_Recalc( PyObject * self, PyObject * args )
{
- PyObject *obj;
- IpoCurve *icu;
+ PyObject *pyobj;
- if( !PyArg_ParseTuple( args, "O!", &IpoCurve_Type, &obj ) )
+ if( !PyArg_ParseTuple( args, "O!", &IpoCurve_Type, &pyobj ) )
return EXPP_ReturnPyObjError( PyExc_TypeError,
"expected Ipo curve argument" );
- icu = IpoCurve_FromPyObject( obj );
- testhandles_ipocurve( icu );
-
- Py_INCREF( Py_None );
- return Py_None;
+ testhandles_ipocurve( IpoCurve_FromPyObject( pyobj ) );
+ Py_RETURN_NONE;
}
/*****************************************************************************/
-/* Function: Ipo_Init */
+/* Python BPy_Ipo methods: */
/*****************************************************************************/
-PyObject *Ipo_Init( void )
-{
- PyObject *submodule;
-
- Ipo_Type.ob_type = &PyType_Type;
- submodule = Py_InitModule3( "Blender.Ipo", M_Ipo_methods, M_Ipo_doc );
-
- return ( submodule );
-}
-
-/*****************************************************************************/
-/* Python BPy_Ipo methods: */
-/*****************************************************************************/
static PyObject *Ipo_getName( BPy_Ipo * self )
{
PyObject *attr = PyString_FromString( self->ipo->id.name + 2 );
if( attr )
return attr;
- Py_INCREF( Py_None );
- return Py_None;
-}
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "couldn't get Ipo.name attribute" );
+}
static PyObject *Ipo_setName( BPy_Ipo * self, PyObject * args )
{
@@ -368,43 +656,40 @@
char buf[21];
if( !PyArg_ParseTuple( args, "s", &name ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected string argument" ) );
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected string argument" );
PyOS_snprintf( buf, sizeof( buf ), "%s", name );
rename_id( &self->ipo->id, buf );
- Py_INCREF( Py_None );
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *Ipo_getBlocktype( BPy_Ipo * self )
{
PyObject *attr = PyInt_FromLong( self->ipo->blocktype );
+
if( attr )
return attr;
- return ( EXPP_ReturnPyObjError
- ( PyExc_RuntimeError,
- "couldn't get Ipo.blocktype attribute" ) );
-}
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "couldn't get Ipo.blocktype attribute" );
+}
static PyObject *Ipo_setBlocktype( BPy_Ipo * self, PyObject * args )
{
- int blocktype = 0;
+ short blocktype = 0;
- if( !PyArg_ParseTuple( args, "i", &blocktype ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected string argument" ) );
+ if( !PyArg_ParseTuple( args, "h", &blocktype ) )
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected int argument" );
- self->ipo->blocktype = ( short ) blocktype;
+ self->ipo->blocktype = blocktype;
- Py_INCREF( Py_None );
- return Py_None;
+ Py_RETURN_NONE;
}
-
static PyObject *Ipo_getRctf( BPy_Ipo * self )
{
PyObject *l = PyList_New( 0 );
@@ -413,135 +698,43 @@
PyList_Append( l, PyFloat_FromDouble( self->ipo->cur.ymin ) );
PyList_Append( l, PyFloat_FromDouble( self->ipo->cur.ymax ) );
return l;
-
}
-
-static PyObject *Ipo_setRctf( BPy_Ipo * self, PyObject * args )
+static int Ipo_setRctf( BPy_Ipo * self, PyObject * args )
{
float v[4];
+
if( !PyArg_ParseTuple( args, "ffff", v, v + 1, v + 2, v + 3 ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected 4 float argument" ) );
+ return EXPP_ReturnIntError( PyExc_TypeError,
+ "expected a tuple of 4 floats" );
self->ipo->cur.xmin = v[0];
self->ipo->cur.xmax = v[1];
self->ipo->cur.ymin = v[2];
self->ipo->cur.ymax = v[3];
- Py_INCREF( Py_None );
- return Py_None;
+ return 0;
}
+/*
+ * Get total number of Ipo curves for this Ipo. NOTE: this function
+ * returns all curves for Ipos which have texture channels, unlike
+ * Ipo_length().
+ */
+
static PyObject *Ipo_getNcurves( BPy_Ipo * self )
{
+ IpoCurve *icu;
int i = 0;
- IpoCurve *icu;
for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
i++;
}
- return ( PyInt_FromLong( i ) );
-}
-
-
-/*
- Lamp ipo Name to Channel
-*/
-
-static int Ipo_laIcuName( char *s, int *param )
-{
- extern int la_ar[];
-
- int not_ok = 0;
- int i;
- char *lamp_names[LA_TOTIPO] =
- { "Energ", "R", "G", "B", "Dist", "SpoSi",
- "SpoBl", "Quad1", "Quad2", "HaInt",
- /* lamp texture names */
- "OfsX", "OfsY", "OfsZ", "SizeX", "SizeY",
- "SizeZ", "texR", "texG", "texB", "DefVar",
- "Col"
- };
-
- for( i = 0; i < LA_TOTIPO; i++ ) {
- if( !strcmp( s, lamp_names[i] ) ) { /* found it! */
- *param = la_ar[i];
- return 1;
- }
- }
-
- return not_ok;
-}
-
-
-/*
- World Ipo Name to Channel
-*/
-
-static int Ipo_woIcuName( char *s, int *param )
-{
- extern int wo_ar[]; /* channel values from ipo.c */
- int not_ok = 0;
- int i;
- char *world_names[WO_TOTIPO] = { "HorR", "HorG", "HorB",
- "ZenR", "ZenG", "ZenB",
- "Expos",
- "Misi", "MisDi", "MisSta", "MisHi",
- "StarR", "StarB", "StarG",
- "StarDi", "StarSi",
- /* world textures names */
- "OfsX", "OfsY", "OfsZ",
- "SizeX", "SizeY", "SizeZ",
- "texR", "texG", "texB",
- "DefVar", "Col", "Nor", "Var",
- };
-
- for( i = 0; i < WO_TOTIPO; i++ ) {
- if( !strcmp( s, world_names[i] ) ) { /* found it! */
- *param = wo_ar[i];
- return 1;
- }
- }
-
- return not_ok;
-}
-
-static int Ipo_maIcuName( char *s, int *param )
-{
- extern int ma_ar[];
-
- int not_ok = 0;
- int i;
-
- char *material_names[MA_TOTIPO] = { "R", "G", "B",
- "SpecR", "SpecG", "SpecB",
- "MirR", "MirG", "MirB", "Ref", "Alpha",
- "Emit", "Amb", "Spec",
- "Hard", "SpTra", "Ior", "Mode",
- "HaSize", "Translu",
- "RayMir", "FresMir", "FresMirI",
- "FresTra", "FresTraI",
- "TraGlow",
- "OfsX", "OfsY", "OfsZ",
- "SizeX", "SizeY", "SizeZ",
- "texR", "texG", "texB",
- "DefVar", "Col", "Nor", "Var",
- "Disp"
- };
-
-
- for( i = 0; i < MA_TOTIPO; i++ ) {
- if( !strcmp( s, material_names[i] ) ) { /* found it! */
- *param = ma_ar[i];
- return 1;
- }
- }
-
- return not_ok;
+ return PyInt_FromLong( (long)i );
}
+#if 0
static int Ipo_keIcuName( char *s, int *param )
{
char key[10];
@@ -562,472 +755,576 @@
return ok;
}
+#endif
-static int Ipo_seqIcuName( char *s, int *param )
-{
- int ok = 0;
- if( !strcmp( s, "Fac" ) ) {
- *param = SEQ_FAC1;
- ok = 1;
- }
+/*
+ Function: Ipo_addCurve
+ Bpy: Blender.Ipo.addCurve( 'curname')
- return ok;
-}
+ add a new curve to an existing IPO.
+ example:
+ ipo = Blender.Ipo.New('Object','ObIpo')
+ cu = ipo.addCurve('LocX')
+*/
-static int Ipo_cuIcuName( char *s, int *param )
+static PyObject *Ipo_addCurve( BPy_Ipo * self, PyObject * args )
{
- int ok = 0;
- if( !strcmp( s, "Speed" ) ) {
- *param = CU_SPEED;
- ok = 1;
- }
+ short param; /* numeric curve name constant */
+ char *cur_name = 0; /* input arg: curve name */
+ Ipo *ipo = 0;
+ IpoCurve *icu = 0;
+ Link *link;
- return ok;
-}
+ if( !PyArg_ParseTuple( args, "s", &cur_name ) )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_TypeError, "expected string argument" ) );
-static int Ipo_coIcuName( char *s, int *param )
-{
- int ok = 0;
- if( !strcmp( s, "Inf" ) ) {
- *param = CO_ENFORCE;
- ok = 1;
- }
- return ok;
-}
+ /* chase down the ipo list looking for ours */
+ link = G.main->ipo.first;
-static int Ipo_acIcuName( char *s, int *param )
-{
- int ok = 0;
- if( !strcmp( s, "LocX" ) ) {
- *param = AC_LOC_X;
- return 1;
- }
- if( !strcmp( s, "LocY" ) ) {
- *param = AC_LOC_Y;
- return 1;
- }
- if( !strcmp( s, "LocZ" ) ) {
- *param = AC_LOC_Z;
- return 1;
- }
- if( !strcmp( s, "SizeX" ) ) {
- *param = AC_SIZE_X;
- return 1;
- }
- if( !strcmp( s, "SizeY" ) ) {
- *param = AC_SIZE_Y;
- return 1;
- }
- if( !strcmp( s, "SizeZ" ) ) {
- *param = AC_SIZE_Z;
- return 1;
- }
- if( !strcmp( s, "QuatX" ) ) {
- *param = AC_QUAT_X;
- return 1;
- }
- if( !strcmp( s, "QuatY" ) ) {
- *param = AC_QUAT_Y;
- return 1;
- }
- if( !strcmp( s, "QuatZ" ) ) {
- *param = AC_QUAT_Z;
- return 1;
- }
- if( !strcmp( s, "QuatW" ) ) {
- *param = AC_QUAT_W;
- return 1;
+ while( link ) {
+ ipo = ( Ipo * ) link;
+ if( ipo == self->ipo )
+ break;
+ link = link->next;
}
- return ok;
-}
+ if( !link )
+ return EXPP_ReturnPyObjError
+ ( PyExc_RuntimeError, "Ipo not found" );
-/*
- Camera ipo name to channel
-*/
-
-static int Ipo_caIcuName( char *s, int *param )
-{
- /* for Camera ipos CAM_TOTNAM == CAM_TOTIPO
- and cam_ic_names[] holds the complete set of names, so we use that.
+ /*
+ * Check if the input arg curve name is valid depending on the block
+ * type, and set param to numeric value. Invalid names will return
+ * param = -1.
*/
- extern int cam_ar[];
- extern char *cam_ic_names[];
- int not_ok = 0;
- int i;
+ param = lookup_curve_name( cur_name, ipo->blocktype, self->mtex );
- for( i = 0; i < CAM_TOTIPO; i++ ) {
- if( !strcmp( s, cam_ic_names[i] ) ) { /* found it! */
- *param = cam_ar[i];
- return 1;
- }
- }
+ if( param == -1 )
+ return EXPP_ReturnPyObjError( PyExc_NameError,
+ "curve name is not valid" );
+
+ /* see if the curve already exists */
+ for( icu = ipo->curve.first; icu; icu = icu->next )
+ if( icu->adrcode == param )
+ return EXPP_ReturnPyObjError( PyExc_ValueError,
+ "Ipo curve already exists" );
+
+ /* create the new ipo curve */
+ icu = MEM_callocN( sizeof(IpoCurve), "Python added ipocurve");
+ icu->blocktype = ipo->blocktype;
+ icu->adrcode = param;
+ icu->flag |= IPO_VISIBLE|IPO_AUTO_HORIZ;
+ set_icu_vars( icu );
+ BLI_addtail( &(ipo->curve), icu);
- return not_ok;
+ allspace( REMAKEIPO, 0 );
+ EXPP_allqueue( REDRAWIPO, 0 );
+
+ /* create a bpy wrapper for the new ipo curve */
+ return IpoCurve_CreatePyObject( icu );
}
+/*
+ Function: Ipo_delCurve
+ Bpy: Blender.Ipo.delCurve(curtype)
-/*
- texture ipo name to channel
+ delete an existing curve from IPO.
+ example:
+ ipo = Blender.Ipo.New('Object','ObIpo')
+ cu = ipo.delCurve('LocX')
*/
-static int Ipo_texIcuName( char *s, int *param )
+static PyObject *Ipo_delCurve( BPy_Ipo * self, PyObject * args )
{
- /* this is another case where TE_TOTIPO == TE_TOTNAM.
- te_ic_names[] has all our names so use that.
- */
- extern int te_ar[];
- extern char *tex_ic_names[];
- int not_ok = 0;
- int i;
-
- for( i = 0; i < TE_TOTIPO; i++){
- if( !strcmp( s, tex_ic_names[i] ) ){
- *param = te_ar[i];
- return 1;
- }
- }
+ IpoCurve *icu;
+ char *strname;
+ short adrcode;
- return not_ok;
-}
+ if( !PyArg_ParseTuple( args, "s", &strname ) )
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected string argument" );
-static int Ipo_obIcuName( char *s, int *param )
-{
- int ok = 0;
- if( !strcmp( s, "LocX" ) ) {
- *param = OB_LOC_X;
- return 1;
- }
- if( !strcmp( s, "LocY" ) ) {
- *param = OB_LOC_Y;
- return 1;
- }
- if( !strcmp( s, "LocZ" ) ) {
- *param = OB_LOC_Z;
- return 1;
- }
- if( !strcmp( s, "RotX" ) ) {
- *param = OB_ROT_X;
- return 1;
- }
- if( !strcmp( s, "RotY" ) ) {
- *param = OB_ROT_Y;
- return 1;
- }
- if( !strcmp( s, "RotZ" ) ) {
- *param = OB_ROT_Z;
- return 1;
- }
- if( !strcmp( s, "SizeX" ) ) {
- *param = OB_SIZE_X;
- return 1;
- }
- if( !strcmp( s, "SizeY" ) ) {
- *param = OB_SIZE_Y;
- return 1;
- }
- if( !strcmp( s, "SizeZ" ) ) {
- *param = OB_SIZE_Z;
- return 1;
- }
+ /* map specified name to an adrcode */
+ adrcode = lookup_curve_name( strname, self->ipo->blocktype, self->mtex );
+ if( adrcode == -1 )
+ return EXPP_ReturnPyObjError( PyExc_ValueError,
+ "invalid curve specified" );
- if( !strcmp( s, "dLocX" ) ) {
- *param = OB_DLOC_X;
- return 1;
- }
- if( !strcmp( s, "dLocY" ) ) {
- *param = OB_DLOC_Y;
- return 1;
- }
- if( !strcmp( s, "dLocZ" ) ) {
- *param = OB_DLOC_Z;
- return 1;
- }
- if( !strcmp( s, "dRotX" ) ) {
- *param = OB_DROT_X;
- return 1;
- }
- if( !strcmp( s, "dRotY" ) ) {
- *param = OB_DROT_Y;
- return 1;
- }
- if( !strcmp( s, "dRotZ" ) ) {
- *param = OB_DROT_Z;
- return 1;
- }
- if( !strcmp( s, "dSizeX" ) ) {
- *param = OB_DSIZE_X;
- return 1;
- }
- if( !strcmp( s, "dSizeY" ) ) {
- *param = OB_DSIZE_Y;
- return 1;
- }
- if( !strcmp( s, "dSizeZ" ) ) {
- *param = OB_DSIZE_Z;
- return 1;
- }
+ for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
+ if( icu->adrcode == adrcode ) {
+ BLI_remlink( &( self->ipo->curve ), icu );
+ if( icu->bezt )
+ MEM_freeN( icu->bezt );
+ MEM_freeN( icu );
- if( !strcmp( s, "Layer" ) ) {
- *param = OB_LAY;
- return 1;
- }
- if( !strcmp( s, "Time" ) ) {
- *param = OB_TIME;
- return 1;
- }
+ /* have to do this to avoid crashes in the IPO window */
+ allspace( REMAKEIPO, 0 );
+ EXPP_allqueue( REDRAWIPO, 0 );
- if( !strcmp( s, "ColR" ) ) {
- *param = OB_COL_R;
- return 1;
- }
- if( !strcmp( s, "ColG" ) ) {
- *param = OB_COL_G;
- return 1;
- }
- if( !strcmp( s, "ColB" ) ) {
- *param = OB_COL_B;
- return 1;
- }
- if( !strcmp( s, "ColA" ) ) {
- *param = OB_COL_A;
- return 1;
- }
- if( !strcmp( s, "FStreng" ) ) {
- *param = OB_PD_FSTR;
- return 1;
- }
- if( !strcmp( s, "FFall" ) ) {
- *param = OB_PD_FFALL;
- return 1;
- }
- if( !strcmp( s, "Damping" ) ) {
- *param = OB_PD_SDAMP;
- return 1;
- }
- if( !strcmp( s, "RDamp" ) ) {
- *param = OB_PD_RDAMP;
- return 1;
- }
- if( !strcmp( s, "Perm" ) ) {
- *param = OB_PD_PERM;
- return 1;
+ Py_RETURN_NONE;
+ }
}
- return ok;
+ return EXPP_ReturnPyObjError( PyExc_ValueError, "IpoCurve not found" );
}
+/*
+ */
-/*
- Function: Ipo_addCurve
- Bpy: Blender.Ipo.addCurve( 'curname')
-
- add a new curve to an existing IPO.
- example:
- ipo = Blender.Ipo.New('Object','ObIpo')
- cu = ipo.addCurve('LocX')
-*/
-
-static PyObject *Ipo_addCurve( BPy_Ipo * self, PyObject * args )
+static PyObject *Ipo_getCurve( BPy_Ipo * self, PyObject * args )
{
- int param = 0; /* numeric curve name constant */
- int ok;
- char *cur_name = 0; /* input arg: curve name */
- Ipo *ipo = 0;
- IpoCurve *icu = 0;
- Link *link;
+ IpoCurve *icu = NULL;
+ short adrcode;
+ PyObject *thing;
- if( !PyArg_ParseTuple( args, "s", &cur_name ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected string argument" ) );
+ if( !PyArg_ParseTuple( args, "O", &thing ) )
+ return EXPP_ReturnPyObjError(PyExc_TypeError,
+ "expected string or int argument" );
+
+ /* if arg is a string or int, look up the adrcode */
+ if( PyString_Check( thing ) )
+ adrcode = lookup_curve_name( PyString_AsString( thing ),
+ self->ipo->blocktype, self->mtex );
+ else if( PyInt_Check( thing ) )
+ adrcode = lookup_curve_adrcode( PyInt_AsLong( thing ),
+ self->ipo->blocktype, self->mtex );
+ else
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected int or string argument" );
+ /* if no adrcode found, value error */
+ if( adrcode == -1 )
+ return EXPP_ReturnPyObjError( PyExc_ValueError,
+ "invalid curve specified" );
+
+ /* search for a matching adrcode */
+ for( icu = self->ipo->curve.first; icu; icu = icu->next )
+ if( icu->adrcode == adrcode )
+ return IpoCurve_CreatePyObject( icu );
- /* chase down the ipo list looking for ours */
- link = G.main->ipo.first;
+ Py_RETURN_NONE;
+}
- while( link ) {
- ipo = ( Ipo * ) link;
- if( ipo == self->ipo )
- break;
- link = link->next;
+static PyObject *Ipo_getCurves( BPy_Ipo * self )
+{
+ PyObject *attr = PyList_New( 0 );
+ IpoCurve *icu;
+
+ for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
+ if( self->mtex == -1 || icu->adrcode < MA_MAP1 ||
+ icu->adrcode & texchannel_to_adrcode( self->mtex ) )
+ PyList_Append( attr, IpoCurve_CreatePyObject( icu ) );
}
+ return attr;
+}
- if( !link )
- return EXPP_ReturnPyObjError
- ( PyExc_RuntimeError, "Ipo not found" );
+/*
+ * return a dictionary of valid curve names and adrcodes for the Ipo
+ */
- /*
- depending on the block type,
- check if the input arg curve name is valid
- and set param to numeric value.
- */
- switch ( ipo->blocktype ) {
+static PyObject *Ipo_getCurveNames( BPy_Ipo * self )
+{
+ PyObject *attr = PyDict_New( );
+ namefunc lookup_name;
+ int *vals = NULL;
+ int size;
+
+ /* determine what type of Ipo we are */
+
+ switch ( self->ipo->blocktype ) {
case ID_OB:
- ok = Ipo_obIcuName( cur_name, ¶m );
+ lookup_name = (namefunc)getname_ob_ei;
+ vals = ob_ar;
+ size = OB_TOTIPO;
+ break;
+ case ID_MA:
+ lookup_name = (namefunc)getname_mat_ei;
+ vals = ma_ar;
+ size = MA_TOTIPO;
break;
case ID_CA:
- ok = Ipo_caIcuName( cur_name, ¶m );
+ lookup_name = (namefunc)getname_cam_ei;
+ vals = cam_ar;
+ size = CAM_TOTIPO;
break;
case ID_LA:
- ok = Ipo_laIcuName( cur_name, ¶m );
+ lookup_name = (namefunc)getname_la_ei;
+ vals = la_ar;
+ size = LA_TOTIPO;
break;
case ID_TE:
- ok = Ipo_texIcuName( cur_name, ¶m );
+ lookup_name = (namefunc)getname_tex_ei;
+ vals = te_ar;
+ size = TE_TOTIPO;
break;
case ID_WO:
- ok = Ipo_woIcuName( cur_name, ¶m );
- break;
- case ID_MA:
- ok = Ipo_maIcuName( cur_name, ¶m );
+ lookup_name = (namefunc)getname_world_ei;
+ vals = wo_ar;
+ size = WO_TOTIPO;
break;
case ID_PO:
- ok = Ipo_acIcuName( cur_name, ¶m );
+ lookup_name = (namefunc)getname_ac_ei;
+ vals = ac_ar;
+ size = AC_TOTIPO;
break;
case ID_CO:
- ok = Ipo_coIcuName( cur_name, ¶m );
+ lookup_name = (namefunc)getname_co_ei;
+ vals = co_ar;
+ size = CO_TOTIPO;
break;
case ID_CU:
- ok = Ipo_cuIcuName( cur_name, ¶m );
- break;
- case ID_KE:
- ok = Ipo_keIcuName( cur_name, ¶m );
+ lookup_name = (namefunc)getname_cu_ei;
+ vals = cu_ar;
+ size = CU_TOTIPO;
break;
case ID_SEQ:
- ok = Ipo_seqIcuName( cur_name, ¶m );
+ lookup_name = (namefunc)getname_seq_ei;
+ vals = seq_ar;
+ size = SEQ_TOTIPO;
break;
+ case ID_KE:
+ return attr; /* keys currently not handled */
default:
- ok = 0;
+ Py_DECREF( attr );
+ return EXPP_ReturnPyObjError(PyExc_RuntimeError,
+ "unknown Ipo type" );
}
- if( !ok ) /* curve type was invalid */
- return EXPP_ReturnPyObjError
- ( PyExc_NameError, "curve name was invalid" );
+ /*
+ * go through the list of adrcodes to find names, then add to dictionary
+ * with string as key and adrcode as value
+ */
- /* see if the curve already exists */
- for( icu = ipo->curve.first; icu; icu = icu->next )
- if( icu->adrcode == param )
- return EXPP_ReturnPyObjError( PyExc_ValueError,
- "Ipo curve already exists" );
+ while( size-- ) {
+ EXPP_dict_set_item_str( attr, lookup_name( *vals ),
+ PyInt_FromLong( ( long ) *vals ) );
+ ++vals;
+ }
+ return attr;
+}
- /* create the new ipo curve */
- icu = MEM_callocN(sizeof(IpoCurve), "Python added ipocurve");
- icu->blocktype= ipo->blocktype;
- icu->adrcode= (short)param;
- icu->flag |= IPO_VISIBLE|IPO_AUTO_HORIZ;
- set_icu_vars( icu );
- BLI_addtail( &(ipo->curve), icu);
-
- allspace( REMAKEIPO, 0 );
- EXPP_allqueue( REDRAWIPO, 0 );
+/*
+ * get the current texture channel number, if defined
+ */
- /* create a bpy wrapper for the new ipo curve */
- return IpoCurve_CreatePyObject( icu );
+static PyObject *Ipo_getChannel( BPy_Ipo * self )
+{
+ if( self->mtex != -1 )
+ return Py_BuildValue( "h", self->mtex );
+ Py_RETURN_NONE;
}
-/*
- Function: Ipo_delCurve
- Bpy: Blender.Ipo.delCurve(curtype)
+/*
+ * set the current texture channel number, if defined
+ */
- delete an existing curve from IPO.
- example:
- ipo = Blender.Ipo.New('Object','ObIpo')
- cu = ipo.delCurve('LocX')
-*/
+static int Ipo_setChannel( BPy_Ipo * self, PyObject * value )
+{
+ if( self->mtex != -1 )
+ return EXPP_setIValueRange( value, &self->mtex, 0, 9, 'h' );
+ return 0;
+}
-static PyObject *Ipo_delCurve( BPy_Ipo * self, PyObject * args )
+/*****************************************************************************/
+/* Function: Ipo_dealloc */
+/* Description: This is a callback function for the BPy_Ipo type. It is */
+/* the destructor function. */
+/*****************************************************************************/
+static void Ipo_dealloc( BPy_Ipo * self )
+{
+ PyObject_DEL( self );
+}
+
+/*****************************************************************************/
+/* Function: Ipo_repr */
+/* Description: This is a callback function for the BPy_Ipo type. It */
+/* builds a meaningful string to represent ipo objects. */
+/*****************************************************************************/
+static PyObject *Ipo_repr( BPy_Ipo * self )
+{
+ char *param;
+
+ switch ( self->ipo->blocktype ) {
+ case ID_OB:
+ param = "Object"; break;
+ case ID_CA:
+ param = "Camera"; break;
+ case ID_LA:
+ param = "Lamp"; break;
+ case ID_TE:
+ param = "Texture"; break;
+ case ID_WO:
+ param = "World"; break;
+ case ID_MA:
+ param = "Material"; break;
+ case ID_PO:
+ param = "Action"; break;
+ case ID_CO:
+ param = "Constriant"; break;
+ case ID_CU:
+ param = "Curve"; break;
+ case ID_SEQ:
+ param = "Sequence"; break;
+ case ID_KE:
+ param = "Key"; break;
+ default:
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "unknown Ipo type" );
+ }
+ return PyString_FromFormat( "[Ipo \"%s\" (%s)]", self->ipo->id.name + 2,
+ param );
+}
+
+/* Three Python Ipo_Type helper functions needed by the Object module: */
+
+/*****************************************************************************/
+/* Function: Ipo_CreatePyObject */
+/* Description: This function will create a new BPy_Ipo from an existing */
+/* Blender ipo structure. */
+/*****************************************************************************/
+PyObject *Ipo_CreatePyObject( Ipo * ipo )
+{
+ BPy_Ipo *pyipo;
+ pyipo = ( BPy_Ipo * ) PyObject_NEW( BPy_Ipo, &Ipo_Type );
+ if( !pyipo )
+ return EXPP_ReturnPyObjError( PyExc_MemoryError,
+ "couldn't create BPy_Ipo object" );
+ pyipo->ipo = ipo;
+ pyipo->iter = 0;
+ if( pyipo->ipo->blocktype == ID_WO || pyipo->ipo->blocktype == ID_LA ||
+ pyipo->ipo->blocktype == ID_MA )
+ pyipo->mtex = 0;
+ else
+ pyipo->mtex = -1;
+ return ( PyObject * ) pyipo;
+}
+
+/*****************************************************************************/
+/* Function: Ipo_CheckPyObject */
+/* Description: This function returns true when the given PyObject is of the */
+/* type Ipo. Otherwise it will return false. */
+/*****************************************************************************/
+int Ipo_CheckPyObject( PyObject * pyobj )
+{
+ return ( pyobj->ob_type == &Ipo_Type );
+}
+
+/*****************************************************************************/
+/* Function: Ipo_FromPyObject */
+/* Description: This function returns the Blender ipo from the given */
+/* PyObject. */
+/*****************************************************************************/
+Ipo *Ipo_FromPyObject( PyObject * pyobj )
+{
+ return ( ( BPy_Ipo * ) pyobj )->ipo;
+}
+
+/*****************************************************************************/
+/* Function: Ipo_length */
+/* Description: This function counts the number of curves accessible for the */
+/* PyObject. */
+/*****************************************************************************/
+static int Ipo_length( BPy_Ipo * self )
{
IpoCurve *icu;
- char *strname;
+ int len = 0;
- if( !PyArg_ParseTuple( args, "s", &strname ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "string argument" ) );
+ for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
+ if( self->mtex == -1 || icu->adrcode < MA_MAP1 ||
+ icu->adrcode & texchannel_to_adrcode( self->mtex ) )
+ ++len;
+ }
+ return len;
+}
+
+static PyObject *Ipo_getIpoCurveByName( BPy_Ipo * self, PyObject * key )
+{
+ IpoCurve *icu = NULL;
+ int adrcode;
+
+ /* if arg is a string or int, look up the adrcode */
+ if( PyString_Check( key ) )
+ adrcode = lookup_curve_name( PyString_AsString( key ),
+ self->ipo->blocktype, self->mtex );
+ else if( PyInt_Check( key ) )
+ adrcode = lookup_curve_adrcode( PyInt_AsLong( key ),
+ self->ipo->blocktype, self->mtex );
+ else
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected int or string key" );
+
+ /* if no adrcode found, value error */
+ if( adrcode == -1 )
+ return EXPP_ReturnPyObjError( PyExc_KeyError, "invalid curve key" );
+
+ /* search for a matching adrcode */
+ for( icu = self->ipo->curve.first; icu; icu = icu->next )
+ if( icu->adrcode == adrcode )
+ return IpoCurve_CreatePyObject( icu );
+
+ /* no curve found */
+ Py_RETURN_NONE;
+}
+
+static int Ipo_setIpoCurveByName( BPy_Ipo * self, PyObject * key,
+ PyObject * value )
+{
+ IpoCurve *icu;
+ short adrcode;
+
+ if( value )
+ return EXPP_ReturnIntError( PyExc_NotImplementedError,
+ "assigning Ipocurve not supported" );
+
+ if( PyString_Check( key ) )
+ adrcode = lookup_curve_name( PyString_AsString( key ),
+ self->ipo->blocktype, self->mtex );
+ else if( PyInt_Check( key ) )
+ adrcode = lookup_curve_adrcode( PyInt_AsLong( key ),
+ self->ipo->blocktype, self->mtex );
+ else
+ return EXPP_ReturnIntError( PyExc_TypeError,
+ "expected int or string key" );
+
+ if( adrcode == -1 )
+ return EXPP_ReturnIntError( PyExc_KeyError,
+ "invalid curve specified" );
for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
- char *str1 = getIpoCurveName( icu );
- if( !strcmp( str1, strname ) ) {
+ if( icu->adrcode == adrcode ) {
BLI_remlink( &( self->ipo->curve ), icu );
if( icu->bezt )
MEM_freeN( icu->bezt );
MEM_freeN( icu );
+ /* have to do this to avoid crashes in the IPO window */
allspace( REMAKEIPO, 0 );
EXPP_allqueue( REDRAWIPO, 0 );
- Py_INCREF( Py_None );
- return Py_None;
+ return 0;
}
}
- return ( EXPP_ReturnPyObjError
- ( PyExc_RuntimeError, "IpoCurve not found" ) );
-}
-
+ return EXPP_ReturnIntError( PyExc_ValueError, "IpoCurve not found" );
+}
+/*
+ * sequence __contains__ method (implements "x in ipo")
+ */
-static PyObject *Ipo_getCurve( BPy_Ipo * self, PyObject * args )
+static int Ipo_contains( BPy_Ipo *self, PyObject *key )
{
- char *str, *str1;
IpoCurve *icu = NULL;
int adrcode;
- PyObject *thing;
-
- if( !PyArg_ParseTuple( args, "O", &thing ) )
- return EXPP_ReturnPyObjError(PyExc_TypeError,
- "expected string or int argument" );
-
- if(PyString_Check(thing)){
- str = PyString_AsString(thing);
- for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
- str1 = getIpoCurveName( icu );
- if( !strcmp( str1, str ) )
- return IpoCurve_CreatePyObject( icu );
- }
- } else if (PyInt_Check(thing)){
- adrcode = (short)PyInt_AsLong(thing);
- for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
- if(icu->adrcode == adrcode)
- return IpoCurve_CreatePyObject( icu );
- }
- } else
- return EXPP_ReturnPyObjError(PyExc_TypeError,
- "expected string or int argument" );
- Py_INCREF( Py_None );
- return Py_None;
-}
-static PyObject *Ipo_getCurves( BPy_Ipo * self )
+ /* take a Ipo curve name: key must be a string */
+ if( PyString_Check( key ) || PyNumber_Check( key ) ) {
+ /* look up the adrcode */
+ if( PyString_Check( key ) )
+ adrcode = lookup_curve_name( PyString_AsString( key ),
+ self->ipo->blocktype, self->mtex );
+ else
+ adrcode = lookup_curve_adrcode( PyInt_AsLong( key ),
+ self->ipo->blocktype, self->mtex );
+
+ /* if we found an adrcode for the key, search the ipo's curve */
+ if( adrcode != -1 ) {
+ for( icu = self->ipo->curve.first; icu; icu = icu->next )
+ if( icu->adrcode == adrcode )
+ return 1;
+ }
+ }
+ /* no curve found */
+ return 0;
+}
+
+/*
+ * Initialize the interator index
+ */
+
+static PyObject *Ipo_getIter( BPy_Ipo * self )
{
- PyObject *attr = PyList_New( 0 );
- IpoCurve *icu;
- for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
- PyList_Append( attr, IpoCurve_CreatePyObject( icu ) );
+ self->iter = 0;
+ return EXPP_incr_ret ( (PyObject *) self );
+}
+
+/*
+ * Get the next Ipo curve
+ */
+
+static PyObject *Ipo_nextIter( BPy_Ipo * self )
+{
+ int i;
+ IpoCurve *icu = self->ipo->curve.first;
+
+ ++self->iter;
+
+ /*
+ * count curves only if
+ * (a) Ipo has no texture channels
+ * (b) Ipo has texture channels, but curve is not that type
+ * (c) Ipo has texture channels, and curve is that type, and it is
+ * in the active texture channel
+ */
+ for( i = 0; icu; icu = icu->next ) {
+ if( self->mtex == -1 || icu->adrcode < MA_MAP1 ||
+ icu->adrcode & texchannel_to_adrcode( self->mtex ) ) {
+ ++i;
+
+ /* if indices match, return the curve */
+ if( i == self->iter )
+ return IpoCurve_CreatePyObject( icu );
+ }
}
- return attr;
+
+ /* ran out of curves */
+ return EXPP_ReturnPyObjError( PyExc_StopIteration,
+ "iterator at end" );
}
+/*****************************************************************************/
+/* Function: Ipo_Init */
+/*****************************************************************************/
+PyObject *Ipo_Init( void )
+{
+ PyObject *submodule;
+
+ if( PyType_Ready( &Ipo_Type ) < 0 )
+ return NULL;
+
+ submodule = Py_InitModule3( "Blender.Ipo", M_Ipo_methods, M_Ipo_doc );
+
+ return submodule;
+}
+
+/*
+ * The following methods should be deprecated when there are equivalent
+ * methods in Ipocurve (if there aren't already).
+ */
static PyObject *Ipo_getNBezPoints( BPy_Ipo * self, PyObject * args )
{
- int num = 0, i = 0;
- IpoCurve *icu = 0;
+ int num = 0;
+ IpoCurve *icu = NULL;
+
if( !PyArg_ParseTuple( args, "i", &num ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected int argument" ) );
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected int argument" );
+
icu = self->ipo->curve.first;
- if( !icu )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "No IPO curve" ) );
- for( i = 0; i < num; i++ ) {
- if( !icu )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "Bad curve number" ) );
+ while( icu && num > 0 ) {
icu = icu->next;
-
+ --num;
}
- return ( PyInt_FromLong( icu->totvert ) );
+
+ if( num < 0 && !icu )
+ return EXPP_ReturnPyObjError( PyExc_IndexError,
+ "index out of range" );
+
+ return PyInt_FromLong( icu->totvert );
}
static PyObject *Ipo_DeleteBezPoints( BPy_Ipo * self, PyObject * args )
@@ -1052,7 +1349,6 @@
return ( PyInt_FromLong( icu->totvert ) );
}
-
/*
* Ipo_getCurveBP()
* this method is UNSUPPORTED.
@@ -1065,42 +1361,8 @@
static PyObject *Ipo_getCurveBP( BPy_Ipo * self, PyObject * args )
{
-
- /* unsupported method */
return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
"bpoint ipos are not supported" );
-
-#if 0
-
- struct BPoint *ptrbpoint;
- int num = 0, i;
- IpoCurve *icu;
- PyObject *l;
-
- if( !PyArg_ParseTuple( args, "i", &num ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected int argument" ) );
- icu = self->ipo->curve.first;
- if( !icu )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "No IPO curve" ) );
- for( i = 0; i < num; i++ ) {
- if( !icu )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "Bad curve number" ) );
- icu = icu->next;
-
- }
- ptrbpoint = icu->bp;
- if( !ptrbpoint )
- return EXPP_ReturnPyObjError( PyExc_TypeError,
- "No base point" );
-
- l = PyList_New( 0 );
- for( i = 0; i < 4; i++ )
- PyList_Append( l, PyFloat_FromDouble( ptrbpoint->vec[i] ) );
- return l;
-#endif
}
static PyObject *Ipo_getCurveBeztriple( BPy_Ipo * self, PyObject * args )
@@ -1140,7 +1402,6 @@
return l;
}
-
static PyObject *Ipo_setCurveBeztriple( BPy_Ipo * self, PyObject * args )
{
struct BezTriple *ptrbt;
@@ -1183,11 +1444,8 @@
return Py_None;
}
-
static PyObject *Ipo_EvaluateCurveOn( BPy_Ipo * self, PyObject * args )
{
- float eval_icu( IpoCurve * icu, float ipotime );
-
int num = 0, i;
IpoCurve *icu;
float time = 0;
@@ -1211,7 +1469,6 @@
return PyFloat_FromDouble( eval_icu( icu, time ) );
}
-
static PyObject *Ipo_getCurvecurval( BPy_Ipo * self, PyObject * args )
{
int numcurve = 0, i;
@@ -1258,85 +1515,12 @@
return Py_None;
}
+/*
+ * The following methods should be deprecated when methods are pruned out.
+ */
-/*****************************************************************************/
-/* Function: IpoDeAlloc */
-/* Description: This is a callback function for the BPy_Ipo type. It is */
-/* the destructor function. */
-/*****************************************************************************/
-static void IpoDeAlloc( BPy_Ipo * self )
-{
- PyObject_DEL( self );
-}
-
-/*****************************************************************************/
-/* Function: IpoGetAttr */
-/* Description: This is a callback function for the BPy_Ipo type. It is */
-/* the function that accesses BPy_Ipo "member variables" and */
-/* methods. */
-/*****************************************************************************/
-static PyObject *IpoGetAttr( BPy_Ipo * self, char *name )
-{
- if( strcmp( name, "curves" ) == 0 )
- return Ipo_getCurves( self );
- return Py_FindMethod( BPy_Ipo_methods, ( PyObject * ) self, name );
-}
-
-/*****************************************************************************/
-/* Function: IpoSetAttr */
-/* Description: This is a callback function for the BPy_Ipo type. It is the */
-/* function that sets Ipo Data attributes (member variables).*/
-/*****************************************************************************/
-static int IpoSetAttr( BPy_Ipo * self, char *name, PyObject * value )
-{
- return 0; /* normal exit */
-}
-
-/*****************************************************************************/
-/* Function: IpoRepr */
-/* Description: This is a callback function for the BPy_Ipo type. It */
-/* builds a meaninful string to represent ipo objects. */
-/*****************************************************************************/
-static PyObject *IpoRepr( BPy_Ipo * self )
-{
- return PyString_FromFormat( "[Ipo \"%s\" %d]", self->ipo->id.name + 2,
- self->ipo->blocktype );
-}
-
-/* Three Python Ipo_Type helper functions needed by the Object module: */
-
-/*****************************************************************************/
-/* Function: Ipo_CreatePyObject */
-/* Description: This function will create a new BPy_Ipo from an existing */
-/* Blender ipo structure. */
-/*****************************************************************************/
-PyObject *Ipo_CreatePyObject( Ipo * ipo )
-{
- BPy_Ipo *pyipo;
- pyipo = ( BPy_Ipo * ) PyObject_NEW( BPy_Ipo, &Ipo_Type );
- if( !pyipo )
- return EXPP_ReturnPyObjError( PyExc_MemoryError,
- "couldn't create BPy_Ipo object" );
- pyipo->ipo = ipo;
- return ( PyObject * ) pyipo;
-}
-
-/*****************************************************************************/
-/* Function: Ipo_CheckPyObject */
-/* Description: This function returns true when the given PyObject is of the */
-/* type Ipo. Otherwise it will return false. */
-/*****************************************************************************/
-int Ipo_CheckPyObject( PyObject * pyobj )
-{
- return ( pyobj->ob_type == &Ipo_Type );
-}
-
-/*****************************************************************************/
-/* Function: Ipo_FromPyObject */
-/* Description: This function returns the Blender ipo from the given */
-/* PyObject. */
-/*****************************************************************************/
-Ipo *Ipo_FromPyObject( PyObject * pyobj )
+static PyObject *Ipo_oldsetRctf( BPy_Ipo * self, PyObject * args )
{
- return ( ( BPy_Ipo * ) pyobj )->ipo;
+ return EXPP_setterWrapperTuple( (void *)self, args,
+ (setter)Ipo_setRctf );
}
Index: source/blender/python/api2_2x/Ipocurve.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/Ipocurve.c,v
retrieving revision 1.34
diff -u -r1.34 Ipocurve.c
--- source/blender/python/api2_2x/Ipocurve.c 17 Dec 2005 04:57:48 -0000 1.34
+++ source/blender/python/api2_2x/Ipocurve.c 12 Mar 2006 18:46:00 -0000
@@ -1,5 +1,5 @@
/*
- * $Id: Ipocurve.c,v 1.34 2005/12/17 04:57:48 khughes Exp $
+ * $Id: Ipocurve.c,v 1.32 2005/11/28 05:03:25 khughes Exp $
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
@@ -34,21 +34,17 @@
#include "Object.h"
#include "BKE_global.h"
+#include "BKE_main.h"
#include "BKE_depsgraph.h"
#include "BKE_ipo.h"
#include "BSE_editipo.h"
#include "MEM_guardedalloc.h"
#include "DNA_ipo_types.h"
+#include "DNA_key_types.h"
#include "BezTriple.h"
#include "gen_utils.h"
/*****************************************************************************/
-/* Python API function prototypes for the IpoCurve module. */
-/*****************************************************************************/
-static PyObject *M_IpoCurve_New( PyObject * self, PyObject * args );
-static PyObject *M_IpoCurve_Get( PyObject * self, PyObject * args );
-
-/*****************************************************************************/
/* The following string definitions are used for documentation strings. */
/* In Python these will be written to the console when doing a */
/* Blender.IpoCurve.__doc__ */
@@ -62,10 +58,6 @@
/*****************************************************************************/
struct PyMethodDef M_IpoCurve_methods[] = {
- {"New", ( PyCFunction ) M_IpoCurve_New, METH_VARARGS | METH_KEYWORDS,
- M_IpoCurve_New_doc},
- {"Get", M_IpoCurve_Get, METH_VARARGS, M_IpoCurve_Get_doc},
- {"get", M_IpoCurve_Get, METH_VARARGS, M_IpoCurve_Get_doc},
{NULL, NULL, 0, NULL}
};
@@ -74,14 +66,19 @@
/*****************************************************************************/
static PyObject *IpoCurve_getName( C_IpoCurve * self );
static PyObject *IpoCurve_Recalc( C_IpoCurve * self );
+static PyObject *IpoCurve_append( C_IpoCurve * self, PyObject * args );
static PyObject *IpoCurve_addBezier( C_IpoCurve * self, PyObject * args );
static PyObject *IpoCurve_delBezier( C_IpoCurve * self, PyObject * args );
static PyObject *IpoCurve_setInterpolation( C_IpoCurve * self,
PyObject * args );
static PyObject *IpoCurve_getInterpolation( C_IpoCurve * self );
+static PyObject *IpoCurve_newgetInterp( C_IpoCurve * self );
+static int IpoCurve_newsetInterp( C_IpoCurve * self, PyObject * args );
static PyObject *IpoCurve_setExtrapolation( C_IpoCurve * self,
PyObject * args );
static PyObject *IpoCurve_getExtrapolation( C_IpoCurve * self );
+static PyObject *IpoCurve_newgetExtend( C_IpoCurve * self );
+static int IpoCurve_newsetExtend( C_IpoCurve * self, PyObject * args );
static PyObject *IpoCurve_getPoints( C_IpoCurve * self );
static PyObject *IpoCurve_evaluate( C_IpoCurve * self, PyObject * args );
@@ -93,6 +90,10 @@
static PyObject *IpoCurve_getDriverChannel( C_IpoCurve * self);
static int IpoCurve_setDriverChannel( C_IpoCurve * self, PyObject * args );
+static int IpoCurve_length( C_IpoCurve * self );
+static PyObject *IpoCurve_item( C_IpoCurve * self, int i );
+static int IpoCurve_assign_item( C_IpoCurve * self, int i, BPy_BezTriple *b );
+
/*****************************************************************************/
/* Python C_IpoCurve methods table: */
/*****************************************************************************/
@@ -105,11 +106,13 @@
{"recalc", ( PyCFunction ) IpoCurve_Recalc, METH_NOARGS,
"() - Recomputes the curve after changes"},
{"update", ( PyCFunction ) IpoCurve_Recalc, METH_NOARGS,
- "() - obsolete: use recalc method instead."},
- {"addBezier", ( PyCFunction ) IpoCurve_addBezier, METH_VARARGS,
+ "() - deprecated method: use recalc method instead."},
+ {"append", ( PyCFunction ) IpoCurve_append, METH_VARARGS,
"(coordlist) - Adds a Bezier point to a curve"},
+ {"addBezier", ( PyCFunction ) IpoCurve_addBezier, METH_VARARGS,
+ "() - deprecated method. use append() instead"},
{"delBezier", ( PyCFunction ) IpoCurve_delBezier, METH_VARARGS,
- "(int) - delete Bezier point at specified index"},
+ "() - deprecated method. use \"del icu[index]\" instead"},
{"setInterpolation", ( PyCFunction ) IpoCurve_setInterpolation,
METH_VARARGS, "(str) - Sets the interpolation type of the curve"},
{"getInterpolation", ( PyCFunction ) IpoCurve_getInterpolation,
@@ -127,35 +130,57 @@
static PyGetSetDef C_IpoCurve_getseters[] = {
- {"name",
- (getter)IpoCurve_getName, (setter)NULL,
- "the IpoCurve name",
- NULL},
- {"bezierPoints",
- (getter)IpoCurve_getPoints, (setter)NULL,
- "list of all bezTriples of the curve",
- NULL},
+ {"name",
+ (getter)IpoCurve_getName, (setter)NULL,
+ "the IpoCurve name",
+ NULL},
+ {"bezierPoints",
+ (getter)IpoCurve_getPoints, (setter)NULL,
+ "list of all bezTriples of the curve",
+ NULL},
{"driver",
(getter)IpoCurve_getDriver, (setter)IpoCurve_setDriver,
- "(int) The Status of the driver 1-on, 0-off",
+ "The status of the driver 1-on, 0-off",
NULL},
{"driverObject",
(getter)IpoCurve_getDriverObject, (setter)IpoCurve_setDriverObject,
- "(object) The Object Used to Drive the IpoCurve",
+ "The object used to drive the IpoCurve",
NULL},
{"driverChannel",
(getter)IpoCurve_getDriverChannel, (setter)IpoCurve_setDriverChannel,
- "(int) The Channel on the Driver Object Used to Drive the IpoCurve",
+ "The channel on the driver object used to drive the IpoCurve",
+ NULL},
+ {"interpolation",
+ (getter)IpoCurve_newgetInterp, (setter)IpoCurve_newsetInterp,
+ "The interpolation mode of the curve",
+ NULL},
+ {"extend",
+ (getter)IpoCurve_newgetExtend, (setter)IpoCurve_newsetExtend,
+ "The extend mode of the curve",
NULL},
{NULL,NULL,NULL,NULL,NULL}
};
+
+static PySequenceMethods IpoCurve_as_sequence = {
+ ( inquiry ) IpoCurve_length, /* sq_length */
+ ( binaryfunc ) 0, /* sq_concat */
+ ( intargfunc ) 0, /* sq_repeat */
+ ( intargfunc ) IpoCurve_item, /* sq_item */
+ ( intintargfunc ) 0, /* sq_slice */
+ ( intobjargproc ) IpoCurve_assign_item, /* sq_ass_item */
+ ( intintobjargproc ) 0, /* sq_ass_slice */
+ ( objobjproc ) 0, /* sq_contains */
+ ( binaryfunc ) 0, /* sq_inplace_concat */
+ ( intargfunc ) 0, /* sq_inplace_repeat */
+};
+
/*****************************************************************************/
/* Python IpoCurve_Type callback function prototypes: */
/*****************************************************************************/
-static void IpoCurveDeAlloc( C_IpoCurve * self );
+static void IpoCurve_dealloc( C_IpoCurve * self );
//static int IpoCurvePrint (C_IpoCurve *self, FILE *fp, int flags);
-static PyObject *IpoCurveRepr( C_IpoCurve * self );
+static PyObject *IpoCurve_repr( C_IpoCurve * self );
/*****************************************************************************/
/* Python IpoCurve_Type structure definition: */
@@ -167,16 +192,16 @@
sizeof( C_IpoCurve ), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
- ( destructor ) IpoCurveDeAlloc, /* tp_dealloc */
+ ( destructor ) IpoCurve_dealloc, /* tp_dealloc */
0, /* tp_print */
- ( getattrfunc ) NULL, /* tp_getattr */
- ( setattrfunc ) NULL, /* tp_setattr */
+ ( getattrfunc ) NULL, /* tp_getattr */
+ ( setattrfunc ) NULL, /* tp_setattr */
0, /* tp_compare */
- ( reprfunc ) IpoCurveRepr, /* tp_repr */
+ ( reprfunc ) IpoCurve_repr, /* tp_repr */
/* Method suites for standard classes */
- NULL, /* PyNumberMethods *tp_as_number; */
- NULL, /* PySequenceMethods *tp_as_sequence; */
+ NULL, /* PyNumberMethods *tp_as_number; */
+ &IpoCurve_as_sequence, /* PySequenceMethods *tp_as_sequence; */
NULL, /* PyMappingMethods *tp_as_mapping; */
/* More standard operations (here for binary compatibility) */
@@ -193,7 +218,7 @@
/*** Flags to define presence of optional/expanded features ***/
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
- NULL, /* char *tp_doc; Documentation string */
+ NULL, /* char *tp_doc; */
/*** Assigned meaning in release 2.0 ***/
/* call function for all accessible objects */
NULL, /* traverseproc tp_traverse; */
@@ -239,53 +264,82 @@
};
/*****************************************************************************/
-/* Function: M_IpoCurve_New */
-/* Python equivalent: Blender.IpoCurve.New */
+/* local utility functions */
/*****************************************************************************/
-static PyObject *M_IpoCurve_New( PyObject * self, PyObject * args )
-{
- return 0;
-}
-/*****************************************************************************/
-/* Function: Ipo_Init */
-/*****************************************************************************/
-PyObject *IpoCurve_Init( void )
-{
- PyObject *submodule;
+/*
+ * Keys are handled differently than other Ipos, so go through contortions
+ * to find their names.
+ */
- if( PyType_Ready( &IpoCurve_Type ) < 0)
- return NULL;
+static char *get_key_curvename( IpoCurve *ipocurve )
+{
+ Key *key_iter;
+ char *empty = "";
- submodule =
- Py_InitModule3( "Blender.IpoCurve", M_IpoCurve_methods,
- M_IpoCurve_doc );
+ /* search for keys with an Ipo */
- PyModule_AddIntConstant( submodule, "LOC_X", OB_LOC_X );
- PyModule_AddIntConstant( submodule, "LOC_Y", OB_LOC_Y );
- PyModule_AddIntConstant( submodule, "LOC_Z", OB_LOC_Z );
- PyModule_AddIntConstant( submodule, "ROT_X", OB_ROT_X );
- PyModule_AddIntConstant( submodule, "ROT_Y", OB_ROT_Y );
- PyModule_AddIntConstant( submodule, "ROT_Z", OB_ROT_Z );
- PyModule_AddIntConstant( submodule, "SIZE_X", OB_SIZE_X );
- PyModule_AddIntConstant( submodule, "SIZE_Y", OB_SIZE_Y );
- PyModule_AddIntConstant( submodule, "SIZE_Z", OB_SIZE_Z );
+ for( key_iter = G.main->key.first; key_iter; key_iter=key_iter->id.next) {
+ if( key_iter->ipo ) {
+ IpoCurve *icu = key_iter->ipo->curve.first;
+ /* search curves for a match */
+ while( icu ) {
+ if( icu == ipocurve ) {
+ KeyBlock *block = key_iter->block.first;
+ /* search for matching adrcode */
+ while( block ) {
+ if( block->adrcode == ipocurve->adrcode )
+ return block->name;
+ block = block->next;
+ }
+ }
+ icu = icu->next;
+ }
+ }
+ }
- return ( submodule );
+ /* shouldn't get here unless deleted in UI while BPy object alive */
+ return empty;
}
-/*****************************************************************************/
-/* Function: M_IpoCurve_Get */
-/* Python equivalent: Blender.IpoCurve.Get */
-/* Description: Receives a string and returns the ipo data obj */
-/* whose name matches the string. If no argument is */
-/* passed in, a list of all ipo data names in the */
-/* current scene is returned. */
-/*****************************************************************************/
-static PyObject *M_IpoCurve_Get( PyObject * self, PyObject * args )
+/*
+ * internal bpy func to get Ipo Curve Name, used by Ipo.c and
+ * KX_BlenderSceneConverter.cpp.
+ *
+ * We are returning a pointer to string constants so there are
+ * no issues with who owns pointers.
+ */
+
+char *getIpoCurveName( IpoCurve * icu )
{
- Py_INCREF( Py_None );
- return Py_None;
+ switch ( icu->blocktype ) {
+ case ID_MA:
+ return getname_mat_ei( icu->adrcode );
+ case ID_WO:
+ return getname_world_ei( icu->adrcode );
+ case ID_CA:
+ return getname_cam_ei( icu->adrcode );
+ case ID_OB:
+ return getname_ob_ei( icu->adrcode, 1 );
+ /* solve: what if EffX/Y/Z are wanted? */
+ case ID_TE:
+ return getname_tex_ei( icu->adrcode );
+ case ID_LA:
+ return getname_la_ei( icu->adrcode );
+ case ID_PO:
+ return getname_ac_ei( icu->adrcode );
+ case ID_CU:
+ return getname_cu_ei( icu->adrcode );
+ case ID_KE:
+ /* return "Key"; */
+ /* ipo curves have no names... that was only meant for drawing the buttons... (ton) */
+ return get_key_curvename( icu );
+ case ID_SEQ:
+ return getname_seq_ei( icu->adrcode );
+ case ID_CO:
+ return getname_co_ei( icu->adrcode );
+ }
+ return NULL;
}
/*****************************************************************************/
@@ -332,8 +386,8 @@
return PyString_FromString( str );
}
-static PyObject *IpoCurve_setExtrapolation( C_IpoCurve * self,
- PyObject * args )
+static PyObject * IpoCurve_setExtrapolation( C_IpoCurve * self,
+ PyObject * args )
{
char *extrapolationtype = 0;
@@ -374,88 +428,61 @@
return PyString_FromString( str );
}
-static PyObject *IpoCurve_addBezier( C_IpoCurve * self, PyObject * args )
+static PyObject *IpoCurve_append( C_IpoCurve * self, PyObject * args )
{
float x, y;
- int npoints;
- IpoCurve *icu;
- BezTriple *bzt, *tmp;
- static char name[10] = "mlml";
- PyObject *popo = 0;
- if( !PyArg_ParseTuple( args, "O", &popo ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected tuple argument" ) );
+ IpoCurve *icu = self->ipocurve;
+ PyObject *obj = NULL;
- x = (float)PyFloat_AsDouble( PyTuple_GetItem( popo, 0 ) );
- y = (float)PyFloat_AsDouble( PyTuple_GetItem( popo, 1 ) );
- icu = self->ipocurve;
- npoints = icu->totvert;
- tmp = icu->bezt;
- icu->bezt = MEM_mallocN( sizeof( BezTriple ) * ( npoints + 1 ), name );
- if( tmp ) {
- memmove( icu->bezt, tmp, sizeof( BezTriple ) * npoints );
- MEM_freeN( tmp );
+ if( !PyArg_ParseTuple( args, "O", &obj ) )
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected tuple or BezTriple argument" );
+
+ /* if args is a already a beztriple, tack onto end of list */
+ if( BPy_BezTriple_Check ( obj ) ) {
+ BPy_BezTriple *bobj = (BPy_BezTriple *)obj;
+
+ BezTriple *newb = MEM_callocN( (icu->totvert+1)*sizeof(BezTriple),
+ "BPyBeztriple" );
+ if( icu->bezt ) {
+ memcpy( newb, icu->bezt, ( icu->totvert+1 )*sizeof( BezTriple ) );
+ MEM_freeN( icu->bezt );
+ }
+ icu->bezt = newb;
+ memcpy( &icu->bezt[icu->totvert], bobj->beztriple,
+ sizeof( BezTriple ) );
+ icu->totvert++;
+ calchandles_ipocurve( icu );
+
+ /* otherwise try to get two floats and add to list */
+ } else {
+ PyObject *xobj, *yobj;
+ xobj = PyNumber_Float( PyTuple_GetItem( obj, 0 ) );
+ yobj = PyNumber_Float( PyTuple_GetItem( obj, 1 ) );
+
+ if( !xobj || !yobj )
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected tuple of floats" );
+
+ x = (float)PyFloat_AsDouble( xobj );
+ y = (float)PyFloat_AsDouble( yobj );
+ insert_vert_ipo( icu, x, y);
}
- memmove( icu->bezt + npoints, icu->bezt, sizeof( BezTriple ) );
- icu->totvert++;
- bzt = icu->bezt + npoints;
- bzt->vec[0][0] = x - 1;
- bzt->vec[1][0] = x;
- bzt->vec[2][0] = x + 1;
- bzt->vec[0][1] = y - 1;
- bzt->vec[1][1] = y;
- bzt->vec[2][1] = y + 1;
- bzt->vec[0][2] = bzt->vec[1][2] = bzt->vec[2][2] = 0.0;
- /* set handle type to Auto */
- bzt->h1 = bzt->h2 = HD_AUTO;
- bzt->f1 = bzt->f2 = bzt->f3= 0;
- bzt->hide = IPO_BEZ;
- Py_INCREF( Py_None );
- return Py_None;
+ Py_RETURN_NONE;
}
-/*
- Function: IpoCurve_delBezier
- Bpy: Blender.Ipocurve.delBezier(0)
-
- Delete an BezTriple from an IPO curve.
- example:
- ipo = Blender.Ipo.Get('ObIpo')
- cu = ipo.getCurve('LocX')
- cu.delBezier(0)
-*/
-
-static PyObject *IpoCurve_delBezier( C_IpoCurve * self, PyObject * args )
+static void del_beztriple( IpoCurve *icu, int index )
{
- int npoints;
- int index;
- IpoCurve *icu;
- BezTriple *tmp;
-
- if( !PyArg_ParseTuple( args, "i", &index ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected int argument" ) );
-
- icu = self->ipocurve;
- npoints = icu->totvert - 1;
-
- /* if index is negative, count from end of list */
- if( index < 0 )
- index += icu->totvert;
- /* check range of index */
- if( index < 0 || index > npoints )
- return ( EXPP_ReturnPyObjError
- ( PyExc_ValueError, "index outside of list" ) );
-
- tmp = icu->bezt;
+ int npoints = icu->totvert - 1;
+ BezTriple * tmp = icu->bezt;
/*
- if delete empties list, then delete it, otherwise copy the remaining
- points to a new list
+ * if delete empties list, then delete it, otherwise copy the remaining
+ * points to a new list
*/
- if( npoints == 0 ) {
+ if( !npoints ) {
icu->bezt = NULL;
} else {
icu->bezt =
@@ -476,8 +503,38 @@
/* deal with curve handles right now, it seems ok */
calchandles_ipocurve( icu );
- Py_INCREF( Py_None );
- return Py_None;
+}
+
+/*
+ Function: IpoCurve_delBezier
+ Bpy: Blender.Ipocurve.delBezier(0)
+
+ Delete an BezTriple from an IPO curve.
+ example:
+ ipo = Blender.Ipo.Get('ObIpo')
+ cu = ipo.getCurve('LocX')
+ cu.delBezier(0)
+*/
+
+static PyObject *IpoCurve_delBezier( C_IpoCurve * self, PyObject * args )
+{
+ int index;
+
+ if( !PyArg_ParseTuple( args, "i", &index ) )
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected int argument" );
+
+ /* if index is negative, count from end of list */
+ if( index < 0 )
+ index += self->ipocurve->totvert;
+ /* check range of index */
+ if( index < 0 || index > self->ipocurve->totvert - 1 )
+ return EXPP_ReturnPyObjError( PyExc_IndexError,
+ "index outside of list" );
+
+ del_beztriple( self->ipocurve, index );
+
+ Py_RETURN_NONE;
}
@@ -523,7 +580,8 @@
return PyString_FromString( getname_cu_ei
( self->ipocurve->adrcode ) );
case ID_KE:
- return PyString_FromString("Key"); /* ipo curves have no names... that was only meant for drawing the buttons... (ton) */
+ // return PyString_FromString("Key"); /* ipo curves have no names... that was only meant for drawing the buttons... (ton) */
+ return PyString_FromString( get_key_curvename( self->ipocurve ) );
case ID_SEQ:
return PyString_FromString( getname_seq_ei
( self->ipocurve->adrcode ) );
@@ -536,46 +594,102 @@
}
}
-static void IpoCurveDeAlloc( C_IpoCurve * self )
+static void IpoCurve_dealloc( C_IpoCurve * self )
{
PyObject_DEL( self );
}
static PyObject *IpoCurve_getPoints( C_IpoCurve * self )
{
- struct BezTriple *bezt;
+#if 1
+ BezTriple *bezt;
PyObject *po;
-
- PyObject *list = PyList_New( 0 );
int i;
+ PyObject *list = PyList_New( self->ipocurve->totvert );
+
+ if( !list )
+ return EXPP_ReturnPyObjError( PyExc_MemoryError,
+ "PyList_New() failed" );
- for( i = 0; i < self->ipocurve->totvert; i++ ) {
- bezt = self->ipocurve->bezt + i;
+ for( bezt = self->ipocurve->bezt, i = 0;
+ i < self->ipocurve->totvert; i++, bezt++ ) {
po = BezTriple_CreatePyObject( bezt );
-#if 0
- if( BezTriple_CheckPyObject( po ) )
- printf( "po is ok\n" );
- else
- printf( "po is hosed\n" );
-#endif
- PyList_Append( list, po );
- /*
- PyList_Append( list, BezTriple_CreatePyObject(bezt));
- */
+ if( !po ) {
+ Py_DECREF( list );
+ return NULL;
+ }
+ PyList_SET_ITEM( list, i, po );
}
return list;
+#else
+ return GenSeq_CreatePyObject( &BezTriple_genSeq, (PyObject *)self,
+ SEQTYPE_ARRAY, self->ipocurve->bezt );
+#endif
+}
+
+/*
+ * Get total number of BezTriples for this IpoCurve.
+ */
+
+static int IpoCurve_length( C_IpoCurve * self )
+{
+ return (int)self->ipocurve->totvert;
+}
+
+static PyObject *IpoCurve_item( C_IpoCurve * self, int i )
+{
+ if( i < 0 || i >= self->ipocurve->totvert )
+ return EXPP_ReturnPyObjError( PyExc_IndexError,
+ "array index out of range" );
+
+ return BezTriple_CreatePyObject( &self->ipocurve->bezt[i] );
}
+/*
+ * assign a single BezTriple to somewhere in the vertex list
+ */
+
+static int IpoCurve_assign_item( C_IpoCurve * self, int i, BPy_BezTriple *b )
+{
+ BezTriple *dst = &self->ipocurve->bezt[i];
+ BezTriple *src;
+
+ if( !b ) {
+ /* if index is negative, count from end of list */
+ if( i < 0 )
+ i += self->ipocurve->totvert;
+ /* check range of index */
+ if( i < 0 || i > self->ipocurve->totvert - 1 )
+ return EXPP_ReturnIntError( PyExc_IndexError,
+ "index outside of list" );
+ del_beztriple( self->ipocurve, i );
+ } else {
+
+ if( !BPy_BezTriple_Check( b ) )
+ return EXPP_ReturnIntError( PyExc_TypeError,
+ "expected BezTriple" );
+
+ if( i < 0 || i >= self->ipocurve->totvert )
+ return EXPP_ReturnIntError( PyExc_IndexError,
+ "array index out of range" );
+
+ src = b->beztriple;
+
+ memcpy( dst, src, sizeof(BezTriple) );
+ }
+ return 0;
+}
+
+
/*****************************************************************************/
-/* Function: IpoCurveRepr */
+/* Function: IpoCurve_repr */
/* Description: This is a callback function for the C_IpoCurve type. It */
-/* builds a meaninful string to represent ipo objects. */
+/* builds a meaningful string to represent ipo objects. */
/*****************************************************************************/
-static PyObject *IpoCurveRepr( C_IpoCurve * self )
+static PyObject *IpoCurve_repr( C_IpoCurve * self )
{
- char s[100];
- sprintf( s, "[IpoCurve \"%s\"]", getIpoCurveName( self->ipocurve ) );
- return PyString_FromString( s );
+ return PyString_FromFormat( "[IpoCurve \"%s\"]",
+ getIpoCurveName( self->ipocurve ) );
}
/* Three Python IpoCurve_Type helper functions needed by the Object module: */
@@ -642,78 +756,40 @@
}
-/*
- internal bpy func to get Ipo Curve Name.
- We are returning a pointer to string constants so there are
- no issues with who owns pointers.
-*/
-
-char *getIpoCurveName( IpoCurve * icu )
-{
- switch ( icu->blocktype ) {
- case ID_MA:
- return getname_mat_ei( icu->adrcode );
- case ID_WO:
- return getname_world_ei( icu->adrcode );
- case ID_CA:
- return getname_cam_ei( icu->adrcode );
- case ID_OB:
- return getname_ob_ei( icu->adrcode, 1 );
- /* solve: what if EffX/Y/Z are wanted? */
- case ID_TE:
- return getname_tex_ei( icu->adrcode );
- case ID_LA:
- return getname_la_ei( icu->adrcode );
- case ID_PO:
- return getname_ac_ei( icu->adrcode );
- case ID_CU:
- return getname_cu_ei( icu->adrcode );
- case ID_KE:
- return "Key"; /* ipo curves have no names... that was only meant for drawing the buttons... (ton) */
- case ID_SEQ:
- return getname_seq_ei( icu->adrcode );
- case ID_CO:
- return getname_co_ei( icu->adrcode );
- }
- return NULL;
-}
-
-
static PyObject *IpoCurve_getDriver( C_IpoCurve * self )
{
- if( self->ipocurve->driver == NULL ) {
+ if( !self->ipocurve->driver )
return PyInt_FromLong( 0 );
- } else {
+ else
return PyInt_FromLong( 1 );
- }
}
static int IpoCurve_setDriver( C_IpoCurve * self, PyObject * args )
{
IpoCurve *ipo = self->ipocurve;
- short mode;
if( !PyInt_CheckExact( args ) )
return EXPP_ReturnIntError( PyExc_TypeError,
- "expected int argument 0 or 1" );
-
- mode = (short)PyInt_AS_LONG ( args );
+ "expected int argument 0 or 1 " );
- if(mode == 1){
- if(ipo->driver == NULL){
- ipo->driver = MEM_callocN(sizeof(IpoDriver), "ipo driver");
- ipo->driver->blocktype = ID_OB;
- ipo->driver->adrcode = OB_LOC_X;
+ switch( PyInt_AS_LONG( args ) ) {
+ case 0:
+ if( ipo->driver ) {
+ MEM_freeN( ipo->driver );
+ ipo->driver = NULL;
}
- } else if(mode == 0){
- if(ipo->driver != NULL){
- MEM_freeN(ipo->driver);
- ipo->driver= NULL;
+ break;
+ case 1:
+ if( !ipo->driver ) {
+ ipo->driver = MEM_callocN( sizeof(IpoDriver), "ipo driver" );
+ ipo->driver->blocktype = ID_OB;
+ ipo->driver->adrcode = OB_LOC_X;
}
- } else
+ break;
+ default:
return EXPP_ReturnIntError( PyExc_ValueError,
- "expected int argument: 0 or 1" );
-
+ "expected int argument 0 or 1 " );
+ }
return 0;
}
@@ -731,15 +807,15 @@
{
IpoCurve *ipo = self->ipocurve;
- if(ipo->driver == NULL)
+ if( !ipo->driver )
return EXPP_ReturnIntError( PyExc_RuntimeError,
"This IpoCurve does not have an active driver" );
if(!BPy_Object_Check(arg) )
- return EXPP_ReturnIntError( PyExc_TypeError,
+ return EXPP_ReturnIntError( PyExc_RuntimeError,
"expected an object argument" );
-
ipo->driver->ob = ((BPy_Object *)arg)->object;
+
DAG_scene_sort(G.scene);
return 0;
@@ -747,7 +823,7 @@
static PyObject *IpoCurve_getDriverChannel( C_IpoCurve * self )
{
- if( self->ipocurve->driver == NULL)
+ if( !self->ipocurve->driver )
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
"This IpoCurve does not have an active driver" );
@@ -757,16 +833,164 @@
static int IpoCurve_setDriverChannel( C_IpoCurve * self, PyObject * args )
{
IpoCurve *ipo = self->ipocurve;
+ short param;
- if(ipo->driver == NULL)
+ if( !ipo->driver )
return EXPP_ReturnIntError( PyExc_RuntimeError,
- "This IpoCurve does not have an active driver" );
+ "This IpoCurve does not have an active driver" );
if( !PyInt_CheckExact( args ) )
return EXPP_ReturnIntError( PyExc_TypeError,
- "expected int argument 0 or 1" );
+ "expected int argument" );
- ipo->driver->adrcode = (short)PyInt_AS_LONG( args );
+ param = (short)PyInt_AS_LONG ( args );
+ if( ( param >= OB_LOC_X && param <= OB_LOC_Z )
+ || ( param >= OB_ROT_X && param <= OB_ROT_Z )
+ || ( param >= OB_SIZE_X && param <= OB_SIZE_Z ) ) {
+ ipo->driver->adrcode = (short)PyInt_AS_LONG ( args );
+ return 0;
+ }
- return 0;
+ return EXPP_ReturnIntError( PyExc_ValueError, "invalid int argument" );
+}
+
+static PyObject *M_IpoCurve_ExtendDict( void )
+{
+ PyObject *EM = PyConstant_New( );
+
+ if( EM ) {
+ BPy_constant *d = ( BPy_constant * ) EM;
+
+ PyConstant_Insert( d, "CONST", PyInt_FromLong( IPO_HORIZ ) );
+ PyConstant_Insert( d, "EXTRAP", PyInt_FromLong( IPO_DIR ) );
+ PyConstant_Insert( d, "CYCLIC", PyInt_FromLong( IPO_CYCL ) );
+ PyConstant_Insert( d, "CYCLIC_EXTRAP", PyInt_FromLong( IPO_CYCLX ) );
+ }
+ return EM;
+}
+
+static PyObject *M_IpoCurve_InterpDict( void )
+{
+ PyObject *IM = PyConstant_New( );
+
+ if( IM ) {
+ BPy_constant *d = ( BPy_constant * ) IM;
+
+ PyConstant_Insert( d, "CONST", PyInt_FromLong( IPO_CONST ) );
+ PyConstant_Insert( d, "LINEAR", PyInt_FromLong( IPO_LIN ) );
+ PyConstant_Insert( d, "BEZIER", PyInt_FromLong( IPO_BEZ ) );
+ }
+ return IM;
+}
+
+/*****************************************************************************/
+/* Function: IpoCurve_Init */
+/*****************************************************************************/
+PyObject *IpoCurve_Init( void )
+{
+ PyObject *submodule;
+ PyObject *ExtendTypes = M_IpoCurve_ExtendDict( );
+ PyObject *InterpTypes = M_IpoCurve_InterpDict( );
+
+ if( PyType_Ready( &IpoCurve_Type ) < 0)
+ return NULL;
+
+ submodule =
+ Py_InitModule3( "Blender.IpoCurve", M_IpoCurve_methods,
+ M_IpoCurve_doc );
+
+ PyModule_AddIntConstant( submodule, "LOC_X", OB_LOC_X );
+ PyModule_AddIntConstant( submodule, "LOC_Y", OB_LOC_Y );
+ PyModule_AddIntConstant( submodule, "LOC_Z", OB_LOC_Z );
+ PyModule_AddIntConstant( submodule, "ROT_X", OB_ROT_X );
+ PyModule_AddIntConstant( submodule, "ROT_Y", OB_ROT_Y );
+ PyModule_AddIntConstant( submodule, "ROT_Z", OB_ROT_Z );
+ PyModule_AddIntConstant( submodule, "SIZE_X", OB_SIZE_X );
+ PyModule_AddIntConstant( submodule, "SIZE_Y", OB_SIZE_Y );
+ PyModule_AddIntConstant( submodule, "SIZE_Z", OB_SIZE_Z );
+
+ if( ExtendTypes )
+ PyModule_AddObject( submodule, "ExtendTypes", ExtendTypes );
+ if( InterpTypes )
+ PyModule_AddObject( submodule, "InterpTypes", InterpTypes );
+
+ return ( submodule );
+}
+
+/*
+ */
+
+static PyObject *IpoCurve_newgetInterp( C_IpoCurve * self )
+{
+ PyObject *attr = PyInt_FromLong( self->ipocurve->ipo );
+
+ if( attr )
+ return attr;
+
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "couldn't get IpoCurve.interp atrtribute" );
+}
+
+static int IpoCurve_newsetInterp( C_IpoCurve * self, PyObject * value )
+{
+ return EXPP_setIValueRange( value, &self->ipocurve->ipo,
+ IPO_CONST, IPO_BEZ, 'h' );
+}
+
+static PyObject *IpoCurve_newgetExtend( C_IpoCurve * self )
+{
+ PyObject *attr = PyInt_FromLong( self->ipocurve->extrap );
+
+ if( attr )
+ return attr;
+
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "couldn't get IpoCurve.extend atrtribute" );
+}
+
+static int IpoCurve_newsetExtend( C_IpoCurve * self, PyObject * value )
+{
+ return EXPP_setIValueRange( value, &self->ipocurve->extrap,
+ IPO_HORIZ, IPO_CYCLX, 'h' );
+}
+
+/* #####DEPRECATED###### */
+
+static PyObject *IpoCurve_addBezier( C_IpoCurve * self, PyObject * args )
+{
+ float x, y;
+ int npoints;
+ IpoCurve *icu;
+ BezTriple *bzt, *tmp;
+ static char name[10] = "mlml";
+ PyObject *popo = 0;
+ if( !PyArg_ParseTuple( args, "O", &popo ) )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_TypeError, "expected tuple argument" ) );
+
+ x = (float)PyFloat_AsDouble( PyTuple_GetItem( popo, 0 ) );
+ y = (float)PyFloat_AsDouble( PyTuple_GetItem( popo, 1 ) );
+ icu = self->ipocurve;
+ npoints = icu->totvert;
+ tmp = icu->bezt;
+ icu->bezt = MEM_mallocN( sizeof( BezTriple ) * ( npoints + 1 ), name );
+ if( tmp ) {
+ memmove( icu->bezt, tmp, sizeof( BezTriple ) * npoints );
+ MEM_freeN( tmp );
+ }
+ memmove( icu->bezt + npoints, icu->bezt, sizeof( BezTriple ) );
+ icu->totvert++;
+ bzt = icu->bezt + npoints;
+ bzt->vec[0][0] = x - 1;
+ bzt->vec[1][0] = x;
+ bzt->vec[2][0] = x + 1;
+ bzt->vec[0][1] = y - 1;
+ bzt->vec[1][1] = y;
+ bzt->vec[2][1] = y + 1;
+ /* set handle type to Auto */
+ bzt->h1 = HD_AUTO;
+ bzt->h2 = HD_AUTO;
+
+ Py_INCREF( Py_None );
+ return Py_None;
}
Index: source/blender/python/api2_2x/Ipo.h
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/Ipo.h,v
retrieving revision 1.14
diff -u -r1.14 Ipo.h
--- source/blender/python/api2_2x/Ipo.h 18 Jul 2005 03:50:36 -0000 1.14
+++ source/blender/python/api2_2x/Ipo.h 12 Mar 2006 18:46:00 -0000
@@ -42,6 +42,8 @@
typedef struct {
PyObject_HEAD /* required macro */
Ipo * ipo;
+ short iter;
+ short mtex;
} BPy_Ipo;
extern PyTypeObject Ipo_Type;
Index: source/blender/python/api2_2x/doc/Ipo.py
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/doc/Ipo.py,v
retrieving revision 1.36
diff -u -r1.36 Ipo.py
--- source/blender/python/api2_2x/doc/Ipo.py 10 Mar 2006 21:39:14 -0000 1.36
+++ source/blender/python/api2_2x/doc/Ipo.py 12 Mar 2006 18:46:00 -0000
@@ -5,23 +5,37 @@
B{New}:
- Ipo updates to both the program and Bpython access.
- - access to Blender's new Ipo driver capabilities .
+ - access to Blender's new Ipo driver capabilities.
+ - Ipo and IpoCurves both support the operator []; Ipos treat the
+ [] like a mapping to a set of IpoCurves, while IpoCurves use
+ [] to access the sequence of BezTriples.
This module provides access to the Ipo Data in Blender. An Ipo is composed of
-several IpoCurves.
-
-A datatype is defined : IpoCurve type. The member functions of this data type
-are given below.
-
+several IpoCurves, and an IpoCurve are composed of several BezTriples.
Example::
import Blender
- ob = Blender.Ipo.Get('ipo') # retrieves an Ipo object
- ob.setName('ipo1')
- print ob.name
- print ipo.getRctf()
- ipo.setRctf(1,2,3,4)
+ ob = Blender.Ipo.Get('ObIpo') # retrieves an Ipo object
+ ob.name = 'ipo1'
+ icu = ipo['LocX'] # request X Location Ipo curve object
+ if icu != None and len(icu) > 0: # if curve exists and has BezTriple points
+ bp = icu[-1] # get the curve's last point
+
+@type ExtendTypes: readonly dictionary
+@var ExtendTypes: The available IpoCurve extend types.
+ - CONST - curve is constant beyond first and last knots
+ - EXTRAP - curve maintains same slope beyond first and last knots
+ - CYCLIC - curve values repeat beyond first and last knots
+ - CYCLIC_EXTRAP - curve values repeat beyond first and last knots,
+ but while retaining continuity
+
+@type InterpTypes: readonly dictionary
+@var InterpTypes: The available IpoCurve interpolation types.
+ - CONST - curve remains constant from current BezTriple knot
+ - LINEAR - curve is linearly interpolated between adjacent knots
+ - BEZIER - curve is interpolated by a Bezier curve between adjacent knots
+
@type HandleTypes: readonly dictionary
@var HandleTypes: The available BezTriple handle types.
- FREE - handle has no constrints
@@ -53,34 +67,143 @@
@rtype: Blender Ipo or a list of Blender Ipos
@return: It depends on the 'name' parameter:
- (name): The Ipo with the given name;
- - (): A list with all Ipos in the current scene.
+ - (): A list with all Ipos in the current scene.
"""
class Ipo:
"""
The Ipo object
==============
- This object gives access to generic data from all objects in Blender.
- It has no attributes.
+ This object gives access to Ipo data from all objects in Blender.
+ @Note: Blender Materials, Lamps and Worlds have I{texture channels} which
+ allow the user to assign textures to them. The Blender Ipo Window allows
+ the user to access the IpoCurves for these channels by specifying a number
+ between 0 and 9 (the number appears next to the Ipo type in the window
+ header). Prior to Version 2.42, the BPy API did not allow users to access
+ these texture channels in a predictable manner. A new attribute named
+ L{channel} was added to the API in Version 2.42 to correct this problem.
+
+ The current channel setting has an effect on the operators B{[]}, B{len()}
+ and others. For example, suppose a Material has three IpoCurves
+ (R, G, and B), and two texture channels (numbered 0 and 1), and furthermore
+ channel 0 has one Ipocurve (Col). The IpoCurve Col can only be
+ "seen" through the API when B{ipo.channel} is 0. Setting B{ipo.channel} to
+ 1 will cause this curve to be ignored by B{len(ipo)}::
+
+ from Blender import Ipo
+
+ ipo = Ipo.Get('MatIpo')
+ for channel in xrange(2):
+ ipo.channel = channel
+ print 'channel is',channel
+ print ' len is',len(ipo)
+ for names in ['R','Col']:
+ print ' ',name,'is',name in ipo
+
+ will output::
+ channel is 0
+ len is 4
+ R is True
+ Col is True
+ channel is 1
+ len is 3
+ R is True
+ Col is False
+
+ @ivar name: The Ipo datablock's name
+ @type name: string
+ @ivar curves: Ipo curves currently defined for the Ipo.
+ @type curves: list of Ipocurves.
+ @ivar curveNames: dictionary of possible Ipo curves. The content of the
+ dictionary is dependent on the Ipo curve type. The keys are the curve
+ names and the value is the internal address code used for each curve.
+ Either value can be used for the Ipo mapping
+ @type curveNames: dictionary
+ @ivar channel: the current texture channel for Blender object which support
+ textures (materials, lamps and worlds). Returns None if the Ipo does
+ not support texture channels. Value must be in the range [0,9].
+ @type channel: int or None
"""
+ def __contains__():
+ """
+ This operator returns B{True} if the specified IpoCurve is defined
+ for the Ipo.
+ @return: see above.
+ @rtype: Boolean
+ """
+
+ def __getitem__():
+ """
+ This operator is similar to the Python dictionary mapping operator [],
+ except that the user cannot assign arbitrary keys. Each Ipo type has
+ a pre-defined set of IpoCurves which may or may not exist at a given time. This operator
+ will either return an IpoCurve object if the specified curve exists,
+ return None if the curve does not exists, or throws a KeyError exception
+ if the curve is not valid for this Ipo type.
+ @return: an IpoCurve object if it exists
+ @rtype: IpoCurve or None
+ @raise KeyError: an undefined IpoCurve was specified for the Ipo
+ """
+
+ def __iter__():
+ """
+ Iterator for Ipos. It returns all the IpoCurve objects associated
+ with the Ipo. For example::
+ from Blender import Ipo
+
+ ipo = Ipo.Get()
+ if len(ipo) > 0:
+ ipo = ipo[0]
+ print 'ipo name is',ipo.name
+ for icu in ipo:
+ print ' curve name is',icu.name
+ might result in::
+ ipo name is ObIpo
+ curve name is LocX
+ curve name is LocY
+ curve name is LocZ
+
+ @return: an IpoCurve object
+ @rtype: IpoCurve
+ """
+
+ def __len__():
+ """
+ Returns the number of curves defined for the Ipo.
+ @return: number of defined IpoCurves
+ @rtype: int
+ """
+
def getName():
"""
- Gets the name of the Ipo.
+ Gets the name of the Ipo (B{deprecated}). See the L{name} attribute.
@rtype: string
@return: the name of the Ipo.
"""
+ def setName(newname):
+ """
+ Sets the name of the Ipo (B{deprecated}). See the L{name} attribute.
+ @type newname: string
+ @rtype: None
+ @return: None
+ """
+
def getCurves():
"""
- Gets all the IpoCurves of the Ipo.
+ Gets all the IpoCurves of the Ipo (B{deprecated}). Use the
+ L{iterator operator []<__iter__>} instead.
@rtype: list of IpoCurves
- @return: A list (possibly void) containing all the IpoCurves associated to the Ipo object.
+ @return: A list (possibly empty) containing all the IpoCurves associated
+ to the Ipo object.
"""
def getCurve(curve):
"""
- Return the specified IpoCurve. If the curve does not exist in the Ipo,
+ Return the specified IpoCurve (B{deprecated}). Use the L{mapping
+ operator B{[]}<__getitem__>} instead.
+ If the curve does not exist in the Ipo,
None is returned. I{curve} can be either a string or an integer,
denoting either the name of the Ipo curve or its internal adrcode.
The possible Ipo curve names are:
@@ -158,20 +281,18 @@
def delCurve(curvename):
"""
- Delete an existing curve from the Ipo object. See addCurve() for possible values for curvename.
+ Delete an existing curve from the Ipo object (B{deprecated}).
+ Use the {del} operator instead::
+ from Blender import Ipo
+
+ ipo = Ipo.Get('ObIpo')
+ del ipo['LocX']
+
@type curvename : string
@rtype: None
@return: None.
"""
- def setName(newname):
- """
- Sets the name of the Ipo.
- @type newname: string
- @rtype: None
- @return: None
- """
-
def getBlocktype():
"""
Gets the blocktype of the Ipo.
@@ -209,7 +330,8 @@
def getNcurves():
"""
- Gets the number of curves of the Ipo.
+ Gets the number of curves of the Ipo (B{deprecated}). Use
+ L{len(ipo)<__len__>} instead.
@rtype: int
@return: the number of curve of the Ipo.
"""
@@ -223,7 +345,8 @@
def getBeztriple(curvepos,pointpos):
"""
- Gets a beztriple of the Ipo.
+ Gets a beztriple of the Ipo (B{deprecated}). B{Note}:
+ Use L{IpoCurve[]<IpoCurve.__getitem__>} instead.
@type curvepos: int
@param curvepos: the position of the curve in the Ipo.
@type pointpos: int
@@ -234,7 +357,10 @@
def setBeztriple(curvepos,pointpos,newbeztriple):
"""
- Sets the beztriple of the Ipo.
+ Sets the beztriple of the Ipo (B{deprecated}). B{Note}: use
+ L{IpoCurve.bezierPoints} to get a BezTriple point, then use the
+ L{BezTriple} API to set the
+ point's attributes.
@type curvepos: int
@param curvepos: the position of the curve in the Ipo.
@type pointpos: int
@@ -266,14 +392,15 @@
@param time: the desired time.
@rtype: float
@return: the current value of the selected curve of the Ipo at the given
- time.
+ time.
"""
class IpoCurve:
"""
The IpoCurve object
===================
- This object gives access to generic data from all Ipo curves objects in Blender.
+ This object gives access to generic data from all Ipo curves objects
+ in Blender.
Important Notes for Rotation Ipo Curves:\n
For the rotation Ipo curves, the y values for points are in units of 10
@@ -293,65 +420,99 @@
@type driverChannel: int
@ivar name: The IpoCurve data name.
@type name: string
- @ivar bezierPoints : The list of the curve's bezier points.
- @type bezierPoints : list
+ @ivar bezierPoints: The list of the curve's bezier points.
+ @type bezierPoints: list of BezTriples.
+ @ivar interpolation: The curve's interpolation mode. See L{InterpTypes} for
+ values.
+ @type interpolation: int
+ @ivar extend: The curve's extend mode. See L{ExtendTypes} for values.
+
+ B{Note}: Cyclic Ipo curves never reach the end value. If the first and
+ last bezier points do not have the same y coordinate, the value of the
+ curve when it "cycles" is that of the first point. If a user wants to
+ get the value of the final curve point, read the final point from the
+ curve::
+
+ ipo = Blender.Object.Get('Cube').ipo
+ icu = ipo['LocX']
+ endtime,endvalue = icu[-1].pt
+ @type extend: int
"""
+ def __getitem__ ():
+ """
+ Accesses the BezTriples associated with the IpoCurve.
+ @rtype: BezTriple
+ @return: a BezTriple point
+ """
+
+ def __setitem__ ():
+ """
+ Assigns a BezTriple to an IpoCurve.
+ @return: None
+ """
+
def setExtrapolation(extendmode):
"""
- Sets the extend mode of the curve.
+ Sets the extend mode of the curve (B{deprecated}). B{Note}: new scripts
+ should use the L{extend} attribute instead.
@type extendmode: string
@param extendmode: the extend mode of the curve.
Can be Constant, Extrapolation, Cyclic or Cyclic_extrapolation.
@rtype: None
@return: None
- @note: Cyclic Ipo curves never reach the end value. If the first and
- last bezier points do not have the same y coordinate, the value of the
- curve when it "cycles" is that of the first point. If a user wants to
- get the value of the final curve point, read the final point from the
- curve's L{bezierPoints} attribute::
-
- ipo = Blender.Object.Get('Cube').ipo
- icu = ipo.getCurves('LocX')
- endtime,endvalue = icu.bezierPoints[-1].pt
-
"""
def getExtrapolation():
"""
- Gets the extend mode of the curve.
+ Gets the extend mode of the curve (B{deprecated}). B{Note}: new scripts
+ should use the L{extend} attribute instead.
@rtype: string
@return: the extend mode of the curve. Can be Constant, Extrapolation, Cyclic or Cyclic_extrapolation.
"""
-
def setInterpolation(interpolationtype):
"""
- Sets the interpolation type of the curve.
+ Sets the interpolation type of the curve (B{deprecated}). B{Note}:
+ new scripts should use the L{interpolation} attribute instead.
@type interpolationtype: string
@param interpolationtype: the interpolation type of the curve. Can be Constant, Bezier, or Linear.
@rtype: None
@return: None
"""
+
def getInterpolation():
"""
- Gets the interpolation type of the curve.
+ Gets the interpolation type of the curve (B{deprecated}). B{Note}:
+ new scripts should use the L{interpolation} attribute instead.
@rtype: string
@return: the interpolation type of the curve. Can be Constant, Bezier, or Linear.
"""
+ def append(point):
+ """
+ Adds a Bezier point to a IpoCurve.
+ @type point: BezTriple or tuple of 2 floats
+ @param point: Can either be a BezTriple, or the x and y coordinates of
+ the Bezier knot point.
+ @rtype: None
+ @return: None
+ """
+
def addBezier(coordlist):
"""
- Adds a Bezier point to a curve.
+ Adds a Bezier point to a curve B{deprecated}). B{Note}: new scripts
+ should use L{append} instead.
@type coordlist: tuple of (at least) 2 floats
@param coordlist: the x and y coordinates of the new Bezier point.
@rtype: None
@return: None
"""
-
+
def delBezier(index):
"""
- Deletes a Bezier point from a curve.
+ Deletes a Bezier point from a curve (B{deprecated}). B{Note}:
+ new scripts should use B{del icu[index]} instead.
@type index: integer
@param index: the index of the Bezier point. Negative values index from the end of the list.
@rtype: None
@@ -367,7 +528,9 @@
def getName():
"""
- Returns the name of the Ipo curve. This name can be:
+ Returns the name of the Ipo curve (B{deprecated}). B{Note}:
+ new scripts should use the L{name} attribute instead.
+ The name can be:
1. Camera Ipo: Lens, ClSta, ClEnd, Apert, FDist.
2. Material Ipo: R, G, B, SpecR, SpecG, SpecB, MirR, MirG, MirB, Ref,
Alpha, Emit, Amb, Spec, Hard, SpTra, Ior, Mode, HaSize, Translu,
@@ -400,7 +563,9 @@
def getPoints():
"""
- Returns all the points of the Ipo curve.
+ Returns all the points of the IpoCurve (B{deprecated}).
+ B{Note}: new scripts should use the L{bezierPoints} attribute
+ or B{operator []} instead.
@rtype: list of BezTriples
@return: the points of the Ipo curve.
"""
File Metadata
Details
Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
8d/c6/bb1c69f56ca63d97bda2b773f0fc
Event Timeline
Log In to Comment