Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Hughes <khughes@pacific.edu>2006-04-22 00:27:52 +0400
committerKen Hughes <khughes@pacific.edu>2006-04-22 00:27:52 +0400
commit4aa28f13f4f2293d0e221239c8a848cc6ae8fbb1 (patch)
tree8b0e0db00058e6a4116be6df5283b45e37a18279 /source/blender/python/api2_2x
parent63868046f4cd50b775074ace5c94084d3f01f8eb (diff)
===Python API===
New Ipo and IpoCurve API. Ipo and IpoCurve objects support the [] operator, for accessing the curves of a particular Ipo and for accessing the value of an IpoCurve at a specific time. Both modules were also "tp_getset"-ified. Also, code for an alternative method (Antont wanted this) of accessing curves via Ipo attributes is included for now, for people to try and see if it's actually preferable to the Ipo [] operator. These are all new additions; nothing was intentionally removed from the API. If you find the something in the existing API has changed, let me know.
Diffstat (limited to 'source/blender/python/api2_2x')
-rw-r--r--source/blender/python/api2_2x/Ipo.c2006
-rw-r--r--source/blender/python/api2_2x/Ipo.h2
-rw-r--r--source/blender/python/api2_2x/Ipocurve.c813
-rw-r--r--source/blender/python/api2_2x/Ipocurve.h1
-rw-r--r--source/blender/python/api2_2x/doc/API_intro.py2
-rw-r--r--source/blender/python/api2_2x/doc/BezTriple.py94
-rw-r--r--source/blender/python/api2_2x/doc/Ipo.py468
-rw-r--r--source/blender/python/api2_2x/doc/IpoCurve.py223
8 files changed, 2345 insertions, 1264 deletions
diff --git a/source/blender/python/api2_2x/Ipo.c b/source/blender/python/api2_2x/Ipo.c
index 74107bd396a..51f3b80f1fd 100644
--- a/source/blender/python/api2_2x/Ipo.c
+++ b/source/blender/python/api2_2x/Ipo.c
@@ -41,10 +41,24 @@
#include "BIF_space.h"
#include "BSE_editipo.h"
#include "MEM_guardedalloc.h"
+#include "DNA_key_types.h"
#include "mydevice.h"
#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[];
+
+PyObject *submodule;
+
/*****************************************************************************/
/* Python API function prototypes for the Ipo module. */
/*****************************************************************************/
@@ -61,7 +75,6 @@ char M_Ipo_doc[] = "";
char M_Ipo_New_doc[] = "";
char M_Ipo_Get_doc[] = "";
-
/*****************************************************************************/
/* Python method structure definition for Blender.Ipo module: */
/*****************************************************************************/
@@ -83,10 +96,12 @@ static PyObject *Ipo_setName( BPy_Ipo * self, PyObject * args );
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 +111,18 @@ static PyObject *Ipo_getCurveBP( BPy_Ipo * self, PyObject * args );
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 +138,7 @@ static PyMethodDef BPy_Ipo_methods[] = {
"(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 +146,10 @@ static PyMethodDef BPy_Ipo_methods[] = {
"(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 +164,544 @@ static PyMethodDef BPy_Ipo_methods[] = {
"(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},
+ {"curveConsts",
+ (getter)Ipo_getCurveNames, (setter)NULL,
+ "Ipo curve constants (values depend on Ipo type)",
+ 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 );
+
+/* #define CURVEATTRS */ /* uncomment to enable curves as Ipo attributes */
+
+#ifdef CURVEATTRS
+static PyGetSetDef BPy_Ipocurve_getseter = {
+ "noname",
+ (getter)NULL, (setter)NULL,
+ "Ipo curve name",
+ NULL
+};
+
+void generate_curveattrs( PyObject* dict, int blocktype )
+{
+ typedef char * (*namefunc)(int, ... );
+ namefunc lookup_name;
+ int size;
+ int *vals = NULL;
+ char name[32];
+ PyObject*desc;
+
+ switch ( blocktype ) {
+ case ID_OB:
+ 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:
+ lookup_name = (namefunc)getname_cam_ei;
+ vals = cam_ar;
+ size = CAM_TOTIPO;
+ break;
+ case ID_LA:
+ lookup_name = (namefunc)getname_la_ei;
+ vals = la_ar;
+ size = LA_TOTIPO;
+ break;
+ case ID_TE:
+ lookup_name = (namefunc)getname_tex_ei;
+ vals = te_ar;
+ size = TE_TOTIPO;
+ break;
+ case ID_WO:
+ lookup_name = (namefunc)getname_world_ei;
+ vals = wo_ar;
+ size = WO_TOTIPO;
+ break;
+ case ID_PO:
+ lookup_name = (namefunc)getname_ac_ei;
+ vals = ac_ar;
+ size = AC_TOTIPO;
+ break;
+ case ID_CO:
+ lookup_name = (namefunc)getname_co_ei;
+ vals = co_ar;
+ size = CO_TOTIPO;
+ break;
+ case ID_CU:
+ lookup_name = (namefunc)getname_cu_ei;
+ vals = cu_ar;
+ size = CU_TOTIPO;
+ break;
+ case ID_SEQ:
+ lookup_name = (namefunc)getname_seq_ei;
+ vals = seq_ar;
+ size = SEQ_TOTIPO;
+ break;
+ }
+
+ desc = PyDescr_NewGetSet( &Ipo_Type, &BPy_Ipocurve_getseter );
+ while( size-- ) {
+ strcpy( name, lookup_name( *vals ) );
+ *name = tolower( *name );
+ PyDict_SetItemString( dict, name, desc );
+ ++vals;
+ }
+ Py_DECREF( desc );
+}
+
+static short lookup_curve_name( char *, int , int );
+
+static PyObject *getattro( PyObject *self, PyObject *value )
+{
+ char *name = PyString_AS_STRING( value );
+ Ipo *ipo = ((BPy_Ipo *)self)->ipo;
+ int adrcode;
+ IpoCurve *icu;
+
+ if( !strcmp(name, "__class__") )
+ return PyObject_GenericGetAttr( self, value );
+
+ if( !strcmp(name, "__dict__") ) /* no effect */
+ {
+ PyObject *dict;
+ dict = PyDict_Copy( self->ob_type->tp_dict );
+ generate_curveattrs( dict, ipo->blocktype );
+ return dict;
+ }
+
+ adrcode = lookup_curve_name( name, ipo->blocktype,
+ ((BPy_Ipo *)self)->mtex );
+
+ if( adrcode != -1 ) {
+ for( icu = ipo->curve.first; icu; icu = icu->next )
+ if( icu->adrcode == adrcode )
+ return IpoCurve_CreatePyObject( icu );
+ Py_RETURN_NONE;
+ }
+
+ return PyObject_GenericGetAttr( self, value );
+}
+#endif
/*****************************************************************************/
-/* 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; */
+#ifdef CURVEATTRS
+ (getattrofunc)getattro,
+#else
+ NULL, /* getattrofunc tp_getattro; */
+#endif
+ 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: /* shouldn't happen */
+ 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;
+}
+
+static short lookup_curve_key( char *str, Ipo *ipo )
+{
+ Key *keyiter;
+
+ /* find the ipo in the keylist */
+ for( keyiter = G.main->key.first; keyiter; keyiter = keyiter->id.next ) {
+ if( keyiter->ipo == ipo ) {
+ KeyBlock *block = keyiter->block.first;
+
+ /* look for a matching string, get the adrcode */
+ for( block = keyiter->block.first; block; block = block->next )
+ if( !strncmp( str, block->name, strlen( block->name) ) )
+ return block->adrcode;
+
+ /* no match; no addr code */
+ return -1;
+ }
+ }
+
+ /* error if the ipo isn't in the list */
+ return -2;
+}
+
+/*
+ * 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;
+}
+
+/*
+ * Delete an IpoCurve from an Ipo
+ */
+
+static void del_ipocurve( Ipo * ipo, IpoCurve * icu ) {
+ BLI_remlink( &( ipo->curve ), icu );
+ if( icu->bezt )
+ MEM_freeN( icu->bezt );
+ if( icu->driver )
+ MEM_freeN( icu->driver );
+ MEM_freeN( icu );
+
+ /* have to do this to avoid crashes in the IPO window */
+ allspace( REMAKEIPO, 0 );
+ EXPP_allqueue( REDRAWIPO, 0 );
+}
+
+/*****************************************************************************/
+/* Python BPy_Ipo functions: */
+/*****************************************************************************/
+
+/*****************************************************************************/
/* Function: M_Ipo_New */
/* Python equivalent: Blender.Ipo.New */
/*****************************************************************************/
-static PyObject *M_Ipo_New( PyObject * self, PyObject * args )
+static PyObject *M_Ipo_New( PyObject * self_unused, 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 +709,10 @@ static PyObject *M_Ipo_New( PyObject * self, PyObject * args )
/* 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" );
}
/*****************************************************************************/
@@ -253,12 +723,11 @@ static PyObject *M_Ipo_New( PyObject * self, PyObject * args )
/* passed in, a list of all ipo data names in the */
/* current scene is returned. */
/*****************************************************************************/
-static PyObject *M_Ipo_Get( PyObject * self, PyObject * args )
+static PyObject *M_Ipo_Get( PyObject * self_unused, PyObject * args )
{
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 +737,16 @@ static PyObject *M_Ipo_Get( PyObject * self, PyObject * args )
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 +754,15 @@ static PyObject *M_Ipo_Get( PyObject * self, PyObject * args )
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 +770,48 @@ static PyObject *M_Ipo_Get( PyObject * self, PyObject * args )
index++;
}
- return ( ipolist );
+ return ipolist;
}
}
+/*
+ * This should probably be deprecated too? Or else documented in epydocs.
+ * Seems very similar to Ipocurve.recalc().
+ */
-static PyObject *M_Ipo_Recalc( PyObject * self, PyObject * args )
+/*****************************************************************************/
+/* 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_unused, 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 +819,40 @@ static PyObject *Ipo_setName( BPy_Ipo * self, PyObject * args )
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 +861,43 @@ static PyObject *Ipo_getRctf( BPy_Ipo * self )
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,263 +918,7 @@ static int Ipo_keIcuName( char *s, int *param )
return ok;
}
-
-static int Ipo_seqIcuName( char *s, int *param )
-{
- int ok = 0;
- if( !strcmp( s, "Fac" ) ) {
- *param = SEQ_FAC1;
- ok = 1;
- }
-
- return ok;
-}
-
-static int Ipo_cuIcuName( char *s, int *param )
-{
- int ok = 0;
- if( !strcmp( s, "Speed" ) ) {
- *param = CU_SPEED;
- ok = 1;
- }
-
- return ok;
-}
-
-static int Ipo_coIcuName( char *s, int *param )
-{
- int ok = 0;
- if( !strcmp( s, "Inf" ) ) {
- *param = CO_ENFORCE;
- ok = 1;
- }
-
- return ok;
-}
-
-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;
- }
- return ok;
-}
-
-
-/*
- 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.
- */
- extern int cam_ar[];
- extern char *cam_ic_names[];
-
- int not_ok = 0;
- int i;
-
- for( i = 0; i < CAM_TOTIPO; i++ ) {
- if( !strcmp( s, cam_ic_names[i] ) ) { /* found it! */
- *param = cam_ar[i];
- return 1;
- }
- }
-
- return not_ok;
-}
-
-
-/*
- texture ipo name to channel
-*/
-
-static int Ipo_texIcuName( char *s, int *param )
-{
- /* 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;
- }
- }
-
- return not_ok;
-}
-
-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;
- }
-
- 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;
- }
-
- if( !strcmp( s, "Layer" ) ) {
- *param = OB_LAY;
- return 1;
- }
- if( !strcmp( s, "Time" ) ) {
- *param = OB_TIME;
- return 1;
- }
-
- 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;
- }
-
- return ok;
-}
-
+#endif
/*
Function: Ipo_addCurve
@@ -832,8 +932,7 @@ static int Ipo_obIcuName( char *s, int *param )
static PyObject *Ipo_addCurve( BPy_Ipo * self, PyObject * args )
{
- int param = 0; /* numeric curve name constant */
- int ok;
+ short param; /* numeric curve name constant */
char *cur_name = 0; /* input arg: curve name */
Ipo *ipo = 0;
IpoCurve *icu = 0;
@@ -859,51 +958,16 @@ static PyObject *Ipo_addCurve( BPy_Ipo * self, PyObject * args )
( PyExc_RuntimeError, "Ipo not found" );
/*
- depending on the block type,
- check if the input arg curve name is valid
- and set param to numeric value.
+ * 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.
*/
- switch ( ipo->blocktype ) {
- case ID_OB:
- ok = Ipo_obIcuName( cur_name, &param );
- break;
- case ID_CA:
- ok = Ipo_caIcuName( cur_name, &param );
- break;
- case ID_LA:
- ok = Ipo_laIcuName( cur_name, &param );
- break;
- case ID_TE:
- ok = Ipo_texIcuName( cur_name, &param );
- break;
- case ID_WO:
- ok = Ipo_woIcuName( cur_name, &param );
- break;
- case ID_MA:
- ok = Ipo_maIcuName( cur_name, &param );
- break;
- case ID_PO:
- ok = Ipo_acIcuName( cur_name, &param );
- break;
- case ID_CO:
- ok = Ipo_coIcuName( cur_name, &param );
- break;
- case ID_CU:
- ok = Ipo_cuIcuName( cur_name, &param );
- break;
- case ID_KE:
- ok = Ipo_keIcuName( cur_name, &param );
- break;
- case ID_SEQ:
- ok = Ipo_seqIcuName( cur_name, &param );
- break;
- default:
- ok = 0;
- }
- if( !ok ) /* curve type was invalid */
- return EXPP_ReturnPyObjError
- ( PyExc_NameError, "curve name was invalid" );
+ param = lookup_curve_name( cur_name, ipo->blocktype, self->mtex );
+
+ 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 )
@@ -912,13 +976,13 @@ static PyObject *Ipo_addCurve( BPy_Ipo * self, PyObject * args )
"Ipo curve already exists" );
/* create the new ipo curve */
- icu = MEM_callocN(sizeof(IpoCurve), "Python added ipocurve");
- icu->blocktype= ipo->blocktype;
- icu->adrcode= (short)param;
+ 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);
-
+
allspace( REMAKEIPO, 0 );
EXPP_allqueue( REDRAWIPO, 0 );
@@ -942,92 +1006,713 @@ static PyObject *Ipo_delCurve( BPy_Ipo * self, PyObject * args )
char *strname;
if( !PyArg_ParseTuple( args, "s", &strname ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "string argument" ) );
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected string argument" );
for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
- char *str1 = getIpoCurveName( icu );
- if( !strcmp( str1, strname ) ) {
- BLI_remlink( &( self->ipo->curve ), icu );
- if( icu->bezt )
- MEM_freeN( icu->bezt );
- MEM_freeN( icu );
-
- allspace( REMAKEIPO, 0 );
- EXPP_allqueue( REDRAWIPO, 0 );
-
- Py_INCREF( Py_None );
- return Py_None;
+ if( !strcmp( strname, getIpoCurveName( icu ) ) ) {
+ del_ipocurve( self->ipo, icu );
+ Py_RETURN_NONE;
}
}
- return ( EXPP_ReturnPyObjError
- ( PyExc_RuntimeError, "IpoCurve not found" ) );
+ return EXPP_ReturnPyObjError( PyExc_ValueError, "IpoCurve not found" );
}
-
-
+/*
+ */
static PyObject *Ipo_getCurve( BPy_Ipo * self, PyObject * args )
{
- 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" );
+ short adrcode;
+ PyObject *value = NULL;
+
+ if( !PyArg_ParseTuple( args, "|O", &value ) )
+ goto typeError;
- if(PyString_Check(thing)){
- str = PyString_AsString(thing);
+ /* if no name give, get all the Ipocurves */
+ if( !value )
+ return Ipo_getCurves( self );
+
+ /* if arg is a string or int, look up the adrcode */
+ if( PyString_Check( value ) ) {
+ char *str = PyString_AsString( value );
for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
- str1 = getIpoCurveName( icu );
- if( !strcmp( str1, str ) )
+ if( !strcmp( str, getIpoCurveName( icu ) ) )
return IpoCurve_CreatePyObject( icu );
}
- } else if (PyInt_Check(thing)){
- adrcode = (short)PyInt_AsLong(thing);
+ Py_RETURN_NONE;
+ }
+ else if( PyInt_Check( value ) ) {
+ adrcode = ( short )PyInt_AsLong( value );
for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
- if(icu->adrcode == adrcode)
+ 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;
+ }
+ Py_RETURN_NONE;
+ }
+
+typeError:
+ return EXPP_ReturnPyObjError(PyExc_TypeError,
+ "expected string or int argument" );
}
static PyObject *Ipo_getCurves( BPy_Ipo * self )
{
PyObject *attr = PyList_New( 0 );
IpoCurve *icu;
- for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
+
+ for( icu = self->ipo->curve.first; icu; icu = icu->next )
PyList_Append( attr, IpoCurve_CreatePyObject( icu ) );
+
+ return attr;
+}
+
+/*
+ * return a list of valid curve name constants for the Ipo
+ */
+
+static PyObject *Ipo_getCurveNames( BPy_Ipo * self )
+{
+ namefunc lookup_name;
+ int size;
+ PyObject *dict;
+ int *vals = NULL;
+ char name[32];
+ PyObject *attr;
+
+ /* determine what type of Ipo we are */
+
+ switch ( self->ipo->blocktype ) {
+ case ID_OB:
+ lookup_name = (namefunc)getname_ob_ei;
+ vals = ob_ar;
+ size = OB_TOTIPO;
+ strcpy( name, "OB_" );
+ break;
+ case ID_MA:
+ lookup_name = (namefunc)getname_mat_ei;
+ vals = ma_ar;
+ size = MA_TOTIPO;
+ strcpy( name, "MA_" );
+ break;
+ case ID_CA:
+ lookup_name = (namefunc)getname_cam_ei;
+ vals = cam_ar;
+ size = CAM_TOTIPO;
+ strcpy( name, "CA_" );
+ break;
+ case ID_LA:
+ lookup_name = (namefunc)getname_la_ei;
+ vals = la_ar;
+ size = LA_TOTIPO;
+ strcpy( name, "LA_" );
+ break;
+ case ID_TE:
+ lookup_name = (namefunc)getname_tex_ei;
+ vals = te_ar;
+ size = TE_TOTIPO;
+ strcpy( name, "TE_" );
+ break;
+ case ID_WO:
+ lookup_name = (namefunc)getname_world_ei;
+ vals = wo_ar;
+ size = WO_TOTIPO;
+ strcpy( name, "WO_" );
+ break;
+ case ID_PO:
+ lookup_name = (namefunc)getname_ac_ei;
+ vals = ac_ar;
+ size = AC_TOTIPO;
+ strcpy( name, "PO_" );
+ break;
+ case ID_CO:
+ lookup_name = (namefunc)getname_co_ei;
+ vals = co_ar;
+ size = CO_TOTIPO;
+ strcpy( name, "CO_" );
+ break;
+ case ID_CU:
+ lookup_name = (namefunc)getname_cu_ei;
+ vals = cu_ar;
+ size = CU_TOTIPO;
+ strcpy( name, "CU_" );
+ break;
+ case ID_SEQ:
+ lookup_name = (namefunc)getname_seq_ei;
+ vals = seq_ar;
+ size = SEQ_TOTIPO;
+ strcpy( name, "SQ_" );
+ break;
+ case ID_KE:
+ {
+ Key *key;
+
+ /* find the ipo in the keylist */
+ for( key = G.main->key.first; key; key = key->id.next ) {
+ if( key->ipo == self->ipo ) {
+ KeyBlock *block = key->block.first;
+ attr = PyList_New( 0 );
+
+ /* add each name to the list */
+ for( block = key->block.first; block; block = block->next )
+ PyList_Append( attr,
+ PyString_FromString( block->name ) );
+
+ return attr;
+ }
+ }
+
+ /* error if the ipo isn't in the list */
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "unable to find matching key data for Ipo" );
+ }
+ default:
+ Py_DECREF( attr );
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "unknown Ipo type" );
+ }
+
+ /*
+ * go through the list of adrcodes to find names, then add to dictionary
+ * with string as key and adrcode as value
+ */
+
+ dict = PyModule_GetDict( submodule );
+
+#if 0
+ attr = PyList_New( );
+
+ while( size-- ) {
+ PyObject *value;
+ char *ptr = name+3;
+ strcpy( name+3, lookup_name( *vals ) );
+ while( *ptr ) {
+ *ptr = toupper( *ptr );
+ ++ptr;
+ }
+ value = PyDict_GetItemString( dict, name );
+ Py_INCREF( value );
+ PyList_Append( attr, value );
+ ++vals;
+ }
+#endif
+#if 0
+ attr = PyDict_New( );
+
+ size = 0;
+
+ {
+ PyObject *key, *value;
+ while( PyDict_Next( dict, &size, &key, &value ) ) {
+ if( !strncmp( name, PyString_AS_STRING( key ), 3 ) )
+ PyDict_SetItem( attr, key, value );
+ }
+ }
+#endif
+#if 0
+ attr = PyConstant_New();
+ size = 0;
+
+ {
+ PyObject *key, *value;
+ while( PyDict_Next( dict, &size, &key, &value ) ) {
+ char *keyname = PyString_AS_STRING( key );
+ if( !strncmp( name, keyname, 3 ) ) {
+ Py_INCREF( value );
+ PyConstant_Insert( (BPy_constant *)attr, keyname, value );
+ }
+ }
}
+#endif
+#if 1
+ attr = PyConstant_New();
+
+ while( size-- ) {
+ char *ptr = name+3;
+ strcpy( name+3, lookup_name( *vals ) );
+ while( *ptr ) {
+ *ptr = toupper( *ptr );
+ ++ptr;
+ }
+ PyConstant_Insert( (BPy_constant *)attr, name,
+ PyInt_FromLong( *vals ) );
+ ++vals;
+ }
+#endif
return attr;
}
+void generate_curveconsts( PyObject* module )
+{
+ namefunc lookup_name;
+ int size;
+ int *vals = NULL;
+ char name[32];
+
+ unsigned int i = 0;
+ static short curvelist[] = {
+ ID_OB, ID_MA, ID_CA, ID_LA, ID_TE, ID_WO, ID_PO, ID_CO, ID_CU, ID_SEQ
+ };
+
+ for( i = 0; i < sizeof(curvelist)/sizeof(short); ++i ) {
+ switch ( curvelist[i] ) {
+ case ID_OB:
+ lookup_name = (namefunc)getname_ob_ei;
+ vals = ob_ar;
+ size = OB_TOTIPO;
+ strcpy( name, "OB_" );
+ break;
+ case ID_MA:
+ lookup_name = (namefunc)getname_mat_ei;
+ vals = ma_ar;
+ size = MA_TOTIPO;
+ strcpy( name, "MA_" );
+ break;
+ case ID_CA:
+ lookup_name = (namefunc)getname_cam_ei;
+ vals = cam_ar;
+ size = CAM_TOTIPO;
+ strcpy( name, "CA_" );
+ break;
+ case ID_LA:
+ lookup_name = (namefunc)getname_la_ei;
+ vals = la_ar;
+ size = LA_TOTIPO;
+ strcpy( name, "LA_" );
+ break;
+ case ID_TE:
+ lookup_name = (namefunc)getname_tex_ei;
+ vals = te_ar;
+ size = TE_TOTIPO;
+ strcpy( name, "TE_" );
+ break;
+ case ID_WO:
+ lookup_name = (namefunc)getname_world_ei;
+ vals = wo_ar;
+ size = WO_TOTIPO;
+ strcpy( name, "WO_" );
+ break;
+ case ID_PO:
+ lookup_name = (namefunc)getname_ac_ei;
+ vals = ac_ar;
+ size = AC_TOTIPO;
+ strcpy( name, "PO_" );
+ break;
+ case ID_CO:
+ lookup_name = (namefunc)getname_co_ei;
+ vals = co_ar;
+ size = CO_TOTIPO;
+ strcpy( name, "CO_" );
+ break;
+ case ID_CU:
+ lookup_name = (namefunc)getname_cu_ei;
+ vals = cu_ar;
+ size = CU_TOTIPO;
+ strcpy( name, "CU_" );
+ break;
+ case ID_SEQ:
+ lookup_name = (namefunc)getname_seq_ei;
+ vals = seq_ar;
+ size = SEQ_TOTIPO;
+ strcpy( name, "SQ_" );
+ break;
+ }
+
+ while( size-- ) {
+ char *ptr = name+3;
+ strcpy( name+3, lookup_name( *vals ) );
+ while( *ptr ) {
+ *ptr = toupper( *ptr );
+ ++ptr;
+ }
+ PyModule_AddIntConstant( module, name, *vals );
+ ++vals;
+ }
+ }
+}
+
+
+/*
+ * get the current texture channel number, if defined
+ */
+
+static PyObject *Ipo_getChannel( BPy_Ipo * self )
+{
+ if( self->mtex != -1 )
+ return Py_BuildValue( "h", self->mtex );
+ Py_RETURN_NONE;
+}
+
+/*
+ * set the current texture channel number, if defined
+ */
+
+static int Ipo_setChannel( BPy_Ipo * self, PyObject * value )
+{
+ if( self->mtex != -1 )
+ return EXPP_setIValueRange( value, &self->mtex, 0, 9, 'h' );
+ return 0;
+}
+
+/*****************************************************************************/
+/* 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;
+ int len = 0;
+
+ 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 0
+ if( PyString_Check( key ) )
+ adrcode = lookup_curve_name( PyString_AsString( key ),
+ self->ipo->blocktype, self->mtex );
+ else
+#endif
+ if( self->ipo->blocktype != ID_KE && PyNumber_Check( key ) )
+ adrcode = lookup_curve_adrcode( PyInt_AsLong( key ),
+ self->ipo->blocktype, self->mtex );
+ else if( self->ipo->blocktype == ID_KE && PyString_Check( key ) ) {
+ adrcode = lookup_curve_key( PyString_AS_STRING( key ), self->ipo );
+ if( adrcode == -2 )
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "unable to find matching key data for Ipo" );
+ }
+ 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 * arg )
+{
+ IpoCurve *icu;
+ Ipo *ipo = self->ipo;
+ short adrcode;
+
+ if( !arg )
+ return EXPP_ReturnIntError( PyExc_NotImplementedError,
+ "del operator not supported" );
+
+ if( PyNumber_Check( key ) )
+ adrcode = lookup_curve_adrcode( PyInt_AsLong( key ),
+ self->ipo->blocktype, self->mtex );
+ else
+ return EXPP_ReturnIntError( PyExc_TypeError,
+ "expected string key" );
+
+ if( adrcode == -1 )
+ return EXPP_ReturnIntError( PyExc_KeyError,
+ "invalid curve specified" );
+
+ /* if arg is None, delete the curve */
+ if( arg == Py_None ) {
+ for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
+ if( icu->adrcode == adrcode ) {
+ del_ipocurve( ipo, icu );
+ return 0;
+ }
+ }
+
+ return EXPP_ReturnIntError( PyExc_ValueError, "IpoCurve not found" );
+ } else {
+
+ /* create the new ipo curve */
+ float time, curval;
+ PyObject *tmp, *flt=NULL, *val=NULL;
+
+ /* error if not a sequence or sequence with other than 2 values */
+ if( PySequence_Size( arg ) != 2 )
+ goto AttrError;
+
+ /* get the time and curval */
+ tmp = PySequence_ITEM( arg, 0 );
+ flt = PyNumber_Float( tmp );
+ Py_DECREF( tmp );
+ tmp = PySequence_ITEM( arg, 1 );
+ val = PyNumber_Float( tmp );
+ Py_DECREF( tmp );
+
+ if( !flt || !val )
+ goto AttrError;
+
+ time = PyFloat_AS_DOUBLE( flt );
+ curval = PyFloat_AS_DOUBLE( val );
+ Py_DECREF( flt );
+ Py_DECREF( val );
+
+ /* if curve already exist, delete the original */
+ for( icu = ipo->curve.first; icu; icu = icu->next )
+ if( icu->adrcode == adrcode ) {
+ del_ipocurve( ipo, icu );
+ break;
+ }
+
+ /* create the new curve, then add the key */
+ icu = MEM_callocN( sizeof(IpoCurve), "Python added ipocurve");
+ icu->blocktype = ipo->blocktype;
+ icu->adrcode = adrcode;
+ icu->flag |= IPO_VISIBLE|IPO_AUTO_HORIZ;
+ set_icu_vars( icu );
+ BLI_addtail( &(ipo->curve), icu);
+ insert_vert_ipo( icu, time, curval );
+
+ allspace( REMAKEIPO, 0 );
+ EXPP_allqueue( REDRAWIPO, 0 );
+
+ return 0;
+
+AttrError:
+ Py_XDECREF( val );
+ Py_XDECREF( flt );
+ return EXPP_ReturnIntError( PyExc_AttributeError,
+ "expected sequence of two floats" );
+ }
+}
+
+/*
+ * sequence __contains__ method (implements "x in ipo")
+ */
+
+static int Ipo_contains( BPy_Ipo *self, PyObject *key )
+{
+ IpoCurve *icu = NULL;
+ int adrcode;
+
+ /* take a Ipo curve name: key must be a int */
+
+ if( self->ipo->blocktype != ID_KE && PyNumber_Check( key ) ) {
+ 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;
+ }
+ } else if( self->ipo->blocktype == ID_KE && PyString_Check( key ) ) {
+ adrcode = lookup_curve_key( PyString_AS_STRING( key ), self->ipo );
+
+ /* if we found an adrcode for the key, search the ipo's curve */
+ if( adrcode >= 0 ) {
+ 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 )
+{
+ 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 );
+ }
+ }
+
+ /* 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 );
+ generate_curveconsts( submodule );
+
+ 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 +1737,6 @@ static PyObject *Ipo_DeleteBezPoints( BPy_Ipo * self, PyObject * args )
return ( PyInt_FromLong( icu->totvert ) );
}
-
/*
* Ipo_getCurveBP()
* this method is UNSUPPORTED.
@@ -1063,44 +1747,10 @@ static PyObject *Ipo_DeleteBezPoints( BPy_Ipo * self, PyObject * args )
* implemented.
*/
-static PyObject *Ipo_getCurveBP( BPy_Ipo * self, PyObject * args )
+static PyObject *Ipo_getCurveBP( BPy_Ipo * self_unused, PyObject * args_unused )
{
-
- /* 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 +1790,6 @@ static PyObject *Ipo_getCurveBeztriple( BPy_Ipo * self, PyObject * args )
return l;
}
-
static PyObject *Ipo_setCurveBeztriple( BPy_Ipo * self, PyObject * args )
{
struct BezTriple *ptrbt;
@@ -1183,11 +1832,8 @@ static PyObject *Ipo_setCurveBeztriple( BPy_Ipo * self, PyObject * args )
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 +1857,6 @@ static PyObject *Ipo_EvaluateCurveOn( BPy_Ipo * self, PyObject * args )
return PyFloat_FromDouble( eval_icu( icu, time ) );
}
-
static PyObject *Ipo_getCurvecurval( BPy_Ipo * self, PyObject * args )
{
int numcurve = 0, i;
@@ -1223,7 +1868,7 @@ static PyObject *Ipo_getCurvecurval( BPy_Ipo * self, PyObject * args )
return ( EXPP_ReturnPyObjError
( PyExc_TypeError, "No IPO curve" ) );
- if( PyNumber_Check( PySequence_GetItem( args, 0 ) ) ) // args is an integer
+ if( PyNumber_Check( PyTuple_GetItem( args, 0 ) ) ) // args is an integer
{
if( !PyArg_ParseTuple( args, "i", &numcurve ) )
return ( EXPP_ReturnPyObjError
@@ -1258,85 +1903,12 @@ static PyObject *Ipo_getCurvecurval( BPy_Ipo * self, PyObject * args )
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 );
}
diff --git a/source/blender/python/api2_2x/Ipo.h b/source/blender/python/api2_2x/Ipo.h
index db312dc971a..95aa5a729a2 100644
--- a/source/blender/python/api2_2x/Ipo.h
+++ b/source/blender/python/api2_2x/Ipo.h
@@ -42,6 +42,8 @@
typedef struct {
PyObject_HEAD /* required macro */
Ipo * ipo;
+ short iter;
+ short mtex;
} BPy_Ipo;
extern PyTypeObject Ipo_Type;
diff --git a/source/blender/python/api2_2x/Ipocurve.c b/source/blender/python/api2_2x/Ipocurve.c
index 608458e476d..485bc79e922 100644
--- a/source/blender/python/api2_2x/Ipocurve.c
+++ b/source/blender/python/api2_2x/Ipocurve.c
@@ -34,21 +34,18 @@
#include "Object.h"
#include "BKE_global.h"
+#include "BKE_main.h"
#include "BKE_depsgraph.h"
#include "BKE_ipo.h"
+#include "BIF_space.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 +59,6 @@ char M_IpoCurve_Get_doc[] = "";
/*****************************************************************************/
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,25 +67,31 @@ struct PyMethodDef M_IpoCurve_methods[] = {
/*****************************************************************************/
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 );
-
static PyObject *IpoCurve_getDriver( C_IpoCurve * self );
static int IpoCurve_setDriver( C_IpoCurve * self, PyObject * args );
-
static PyObject *IpoCurve_getDriverObject( C_IpoCurve * self);
-static int IpoCurve_setDriverObject( C_IpoCurve * self, PyObject * args );
-
+static int IpoCurve_setDriverObject( C_IpoCurve * self, PyObject * args );
static PyObject *IpoCurve_getDriverChannel( C_IpoCurve * self);
-static int IpoCurve_setDriverChannel( C_IpoCurve * self, PyObject * args );
+static int IpoCurve_setDriverChannel( C_IpoCurve * self, PyObject * args );
+static PyObject *IpoCurve_getCurval( C_IpoCurve * self, PyObject * args );
+static int IpoCurve_setCurval( C_IpoCurve * self, PyObject * key,
+ PyObject * value );
+
/*****************************************************************************/
/* Python C_IpoCurve methods table: */
/*****************************************************************************/
@@ -105,11 +104,13 @@ static PyMethodDef C_IpoCurve_methods[] = {
{"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,
@@ -125,37 +126,57 @@ static PyMethodDef C_IpoCurve_methods[] = {
{NULL, NULL, 0, NULL}
};
+/*
+ * IpoCurve methods
+ */
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}
};
+
+/*****************************************************************************/
+/* Python IpoCurve_Type Mapping Methods table: */
+/*****************************************************************************/
+
+static PyMappingMethods IpoCurve_as_mapping = {
+ ( inquiry ) 0, /* mp_length */
+ ( binaryfunc ) IpoCurve_getCurval, /* mp_subscript */
+ ( objobjargproc ) IpoCurve_setCurval, /* mp_ass_subscript */
+};
+
/*****************************************************************************/
/* Python IpoCurve_Type callback function prototypes: */
/*****************************************************************************/
-static void IpoCurveDeAlloc( 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 );
+static void IpoCurve_dealloc( C_IpoCurve * self );
/*****************************************************************************/
/* Python IpoCurve_Type structure definition: */
@@ -167,17 +188,17 @@ PyTypeObject IpoCurve_Type = {
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, /* PyMappingMethods *tp_as_mapping; */
+ NULL, /* PyNumberMethods *tp_as_number; */
+ NULL, /* PySequenceMethods *tp_as_sequence; */
+ &IpoCurve_as_mapping, /* PyMappingMethods *tp_as_mapping; */
/* More standard operations (here for binary compatibility) */
@@ -193,7 +214,7 @@ PyTypeObject IpoCurve_Type = {
/*** 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 +260,118 @@ PyTypeObject IpoCurve_Type = {
};
/*****************************************************************************/
-/* Function: M_IpoCurve_New */
-/* Python equivalent: Blender.IpoCurve.New */
+/* local utility functions */
/*****************************************************************************/
-static PyObject *M_IpoCurve_New( PyObject * self, PyObject * args )
+
+/*
+ * Keys are handled differently than other Ipos, so go through contortions
+ * to find their names.
+ */
+
+static char *get_key_curvename( IpoCurve *ipocurve )
{
- return 0;
+ Key *key_iter;
+ char *empty = "";
+
+ /* search for keys with an Ipo */
+
+ 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;
+ }
+ }
+ }
+
+ /* shouldn't get here unless deleted in UI while BPy object alive */
+ return empty;
}
-/*****************************************************************************/
-/* Function: Ipo_Init */
-/*****************************************************************************/
-PyObject *IpoCurve_Init( void )
+/*
+ * 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 )
{
- PyObject *submodule;
+ 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;
+}
- if( PyType_Ready( &IpoCurve_Type ) < 0)
- return NULL;
+/*
+ * delete a bezTriple from a curve
+ */
- submodule =
- Py_InitModule3( "Blender.IpoCurve", M_IpoCurve_methods,
- M_IpoCurve_doc );
+static void del_beztriple( IpoCurve *icu, int index )
+{
+ int npoints = icu->totvert - 1;
+ BezTriple * tmp = icu->bezt;
- 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 delete empties list, then delete it, otherwise copy the remaining
+ * points to a new list
+ */
- return ( submodule );
-}
+ if( !npoints ) {
+ icu->bezt = NULL;
+ } else {
+ icu->bezt =
+ MEM_mallocN( sizeof( BezTriple ) * npoints, "bezt" );
+ if( index > 0 )
+ memmove( icu->bezt, tmp, index * sizeof( BezTriple ) );
+ if( index < npoints )
+ memmove( icu->bezt + index, tmp + index + 1,
+ ( npoints - index ) * sizeof( BezTriple ) );
+ }
-/*****************************************************************************/
-/* 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 )
-{
- Py_INCREF( Py_None );
- return Py_None;
+ /* free old list, adjust vertex count */
+ MEM_freeN( tmp );
+ icu->totvert--;
+
+ /* call calchandles_* instead of testhandles_* */
+ /* I'm not sure this is a complete solution but since we do not */
+ /* deal with curve handles right now, it seems ok */
+ calchandles_ipocurve( icu );
}
/*****************************************************************************/
@@ -296,123 +382,147 @@ static PyObject *IpoCurve_setInterpolation( C_IpoCurve * self,
PyObject * args )
{
char *interpolationtype = 0;
- int id = -1;
+ short id;
+
if( !PyArg_ParseTuple( args, "s", &interpolationtype ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected string argument" ) );
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected string argument" );
+
if( !strcmp( interpolationtype, "Bezier" ) )
id = IPO_BEZ;
- if( !strcmp( interpolationtype, "Constant" ) )
+ else if( !strcmp( interpolationtype, "Constant" ) )
id = IPO_CONST;
- if( !strcmp( interpolationtype, "Linear" ) )
+ else if( !strcmp( interpolationtype, "Linear" ) )
id = IPO_LIN;
- if( id == -1 )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "bad interpolation type" ) );
+ else
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "bad interpolation type" );
- self->ipocurve->ipo = (short)id;
- Py_INCREF( Py_None );
- return Py_None;
+ self->ipocurve->ipo = id;
+ Py_RETURN_NONE;
}
static PyObject *IpoCurve_getInterpolation( C_IpoCurve * self )
{
char *str = 0;
IpoCurve *icu = self->ipocurve;
- if( icu->ipo == IPO_BEZ )
+
+ switch( icu->ipo ) {
+ case IPO_BEZ:
str = "Bezier";
- if( icu->ipo == IPO_CONST )
+ break;
+ case IPO_CONST:
str = "Constant";
- if( icu->ipo == IPO_LIN )
+ break;
+ case IPO_LIN:
str = "Linear";
+ break;
+ default:
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "unknown interpolation type" );
+ }
- if( !str )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "unknown interpolation type" ) );
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;
- int id = -1;
+ short id;
+
if( !PyArg_ParseTuple( args, "s", &extrapolationtype ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected string argument" ) );
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected string argument" );
+
if( !strcmp( extrapolationtype, "Constant" ) )
id = 0;
- if( !strcmp( extrapolationtype, "Extrapolation" ) )
+ else if( !strcmp( extrapolationtype, "Extrapolation" ) )
id = 1;
- if( !strcmp( extrapolationtype, "Cyclic" ) )
+ else if( !strcmp( extrapolationtype, "Cyclic" ) )
id = 2;
- if( !strcmp( extrapolationtype, "Cyclic_extrapolation" ) )
+ else if( !strcmp( extrapolationtype, "Cyclic_extrapolation" ) )
id = 3;
+ else
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "bad interpolation type" );
- if( id == -1 )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "bad interpolation type" ) );
- self->ipocurve->extrap = (short)id;
- Py_INCREF( Py_None );
- return Py_None;
+ self->ipocurve->extrap = id;
+ Py_RETURN_NONE;
}
static PyObject *IpoCurve_getExtrapolation( C_IpoCurve * self )
{
- char *str = 0;
+ char *str;
IpoCurve *icu = self->ipocurve;
- if( icu->extrap == 0 )
+
+ switch( icu->extrap ) {
+ case 0:
str = "Constant";
- if( icu->extrap == 1 )
+ break;
+ case 1:
str = "Extrapolation";
- if( icu->extrap == 2 )
+ break;
+ case 2:
str = "Cyclic";
- if( icu->extrap == 3 )
+ break;
+ case 3:
str = "Cyclic_extrapolation";
+ break;
+ default:
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "bad extrapolation type" );
+ }
return PyString_FromString( str );
}
-static PyObject *IpoCurve_addBezier( C_IpoCurve * self, PyObject * args )
+/*
+ * append a new BezTriple to curve
+ */
+
+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;
}
/*
@@ -428,59 +538,25 @@ static PyObject *IpoCurve_addBezier( C_IpoCurve * self, PyObject * args )
static PyObject *IpoCurve_delBezier( C_IpoCurve * self, PyObject * args )
{
- 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;
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected int argument" );
/* if index is negative, count from end of list */
if( index < 0 )
- index += icu->totvert;
+ index += self->ipocurve->totvert;
/* check range of index */
- if( index < 0 || index > npoints )
- return ( EXPP_ReturnPyObjError
- ( PyExc_ValueError, "index outside of list" ) );
-
- tmp = icu->bezt;
-
- /*
- if delete empties list, then delete it, otherwise copy the remaining
- points to a new list
- */
-
- if( npoints == 0 ) {
- icu->bezt = NULL;
- } else {
- icu->bezt =
- MEM_mallocN( sizeof( BezTriple ) * npoints, "bezt" );
- if( index > 0 )
- memmove( icu->bezt, tmp, index * sizeof( BezTriple ) );
- if( index < npoints )
- memmove( icu->bezt + index, tmp + index + 1,
- ( npoints - index ) * sizeof( BezTriple ) );
- }
+ if( index < 0 || index > self->ipocurve->totvert - 1 )
+ return EXPP_ReturnPyObjError( PyExc_IndexError,
+ "index outside of list" );
- /* free old list, adjust vertex count */
- MEM_freeN( tmp );
- icu->totvert--;
+ del_beztriple( self->ipocurve, index );
- /* call calchandles_* instead of testhandles_* */
- /* I'm not sure this is a complete solution but since we do not */
- /* deal with curve handles right now, it seems ok */
- calchandles_ipocurve( icu );
-
- Py_INCREF( Py_None );
- return Py_None;
+ Py_RETURN_NONE;
}
-
static PyObject *IpoCurve_Recalc( C_IpoCurve * self )
{
IpoCurve *icu = self->ipocurve;
@@ -523,7 +599,7 @@ static PyObject *IpoCurve_getName( C_IpoCurve * self )
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( get_key_curvename( self->ipocurve ) );
case ID_SEQ:
return PyString_FromString( getname_seq_ei
( self->ipocurve->adrcode ) );
@@ -532,50 +608,53 @@ static PyObject *IpoCurve_getName( C_IpoCurve * self )
( self->ipocurve->adrcode ) );
default:
return EXPP_ReturnPyObjError( PyExc_TypeError,
- "This function doesn't support this ipocurve type yet" );
+ "This function doesn't support this ipocurve type yet" );
}
}
-static void IpoCurveDeAlloc( C_IpoCurve * self )
-{
- PyObject_DEL( self );
-}
-
static PyObject *IpoCurve_getPoints( C_IpoCurve * self )
{
- struct BezTriple *bezt;
+ 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;
}
/*****************************************************************************/
-/* Function: IpoCurveRepr */
+/* Function: Ipo_dealloc */
+/* Description: This is a callback function for the C_IpoCurve type. It is */
+/* the destructor function. */
+/*****************************************************************************/
+
+static void IpoCurve_dealloc( C_IpoCurve * self )
+{
+ PyObject_DEL( self );
+}
+
+/*****************************************************************************/
+/* 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 ipocurve 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: */
@@ -585,7 +664,7 @@ static PyObject *IpoCurveRepr( C_IpoCurve * self )
/* Description: This function will create a new C_IpoCurve from an existing */
/* Blender ipo structure. */
/*****************************************************************************/
-PyObject *IpoCurve_CreatePyObject( IpoCurve * ipo )
+PyObject *IpoCurve_CreatePyObject( IpoCurve * icu )
{
C_IpoCurve *pyipo;
@@ -595,7 +674,7 @@ PyObject *IpoCurve_CreatePyObject( IpoCurve * ipo )
return EXPP_ReturnPyObjError( PyExc_MemoryError,
"couldn't create C_IpoCurve object" );
- pyipo->ipocurve = ipo;
+ pyipo->ipocurve = icu;
return ( PyObject * ) pyipo;
}
@@ -620,6 +699,57 @@ IpoCurve *IpoCurve_FromPyObject( PyObject * pyobj )
return ( ( C_IpoCurve * ) pyobj )->ipocurve;
}
+/*
+ * get the value of an Ipocurve at a particular time
+ */
+
+static PyObject *IpoCurve_getCurval( C_IpoCurve * self, PyObject * args )
+{
+ float time;
+ PyObject *pyfloat = PyNumber_Float( args );
+
+ if( !pyfloat )
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected float argument" );
+ time = ( float )PyFloat_AS_DOUBLE( pyfloat );
+ Py_DECREF( pyfloat );
+
+ return PyFloat_FromDouble( ( double ) eval_icu( self->ipocurve, time ) );
+}
+
+/*
+ * set the value of an Ipocurve at a particular time
+ */
+
+static int IpoCurve_setCurval( C_IpoCurve * self, PyObject * key,
+ PyObject * value )
+{
+ float time, curval;
+ PyObject *pyfloat;
+
+ /* make sure time, curval are both floats */
+
+ pyfloat = PyNumber_Float( key );
+ if( !pyfloat )
+ return EXPP_ReturnIntError( PyExc_TypeError,
+ "expected float key" );
+ time = ( float )PyFloat_AS_DOUBLE( pyfloat );
+ Py_DECREF( pyfloat );
+
+ pyfloat = PyNumber_Float( value );
+ if( !pyfloat )
+ return EXPP_ReturnIntError( PyExc_TypeError,
+ "expected float argument" );
+ curval = ( float )PyFloat_AS_DOUBLE( pyfloat );
+ Py_DECREF( pyfloat );
+
+ /* insert a key at the specified time */
+
+ insert_vert_ipo( self->ipocurve, time, curval );
+ allspace(REMAKEIPO, 0);
+ return 0;
+}
+
/***************************************************************************/
/* Function: IpoCurve_evaluate( time ) */
/* Description: Evaluates IPO curve at the given time. */
@@ -627,7 +757,6 @@ IpoCurve *IpoCurve_FromPyObject( PyObject * pyobj )
static PyObject *IpoCurve_evaluate( C_IpoCurve * self, PyObject * args )
{
-
float time = 0;
double eval = 0;
@@ -642,78 +771,40 @@ static PyObject *IpoCurve_evaluate( C_IpoCurve * self, PyObject * args )
}
-/*
- 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 +822,15 @@ static int IpoCurve_setDriverObject( C_IpoCurve * self, PyObject * arg )
{
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 +838,7 @@ static int IpoCurve_setDriverObject( C_IpoCurve * self, PyObject * arg )
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 +848,164 @@ static PyObject *IpoCurve_getDriverChannel( C_IpoCurve * self )
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" );
+
+ 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;
+ }
- ipo->driver->adrcode = (short)PyInt_AS_LONG( args );
+ return EXPP_ReturnIntError( PyExc_ValueError, "invalid int argument" );
+}
- return 0;
+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;
}
diff --git a/source/blender/python/api2_2x/Ipocurve.h b/source/blender/python/api2_2x/Ipocurve.h
index 4e33f962854..778f468aa7f 100644
--- a/source/blender/python/api2_2x/Ipocurve.h
+++ b/source/blender/python/api2_2x/Ipocurve.h
@@ -42,6 +42,7 @@
typedef struct {
PyObject_HEAD /* required macro */
IpoCurve * ipocurve;
+ char wrapped;
} C_IpoCurve;
extern PyTypeObject IpoCurve_Type;
diff --git a/source/blender/python/api2_2x/doc/API_intro.py b/source/blender/python/api2_2x/doc/API_intro.py
index 1e447075986..60d4b79c573 100644
--- a/source/blender/python/api2_2x/doc/API_intro.py
+++ b/source/blender/python/api2_2x/doc/API_intro.py
@@ -15,6 +15,7 @@ The Blender Python API Reference
-----------
- L{Armature}
- L{NLA}
+ - L{BezTriple}
- L{BGL}
- L{Camera}
- L{Curve}
@@ -23,6 +24,7 @@ The Blender Python API Reference
- L{Group} (*)
- L{Image}
- L{Ipo}
+ - L{IpoCurve}
- L{Key} (*)
- L{Lamp}
- L{Lattice}
diff --git a/source/blender/python/api2_2x/doc/BezTriple.py b/source/blender/python/api2_2x/doc/BezTriple.py
new file mode 100644
index 00000000000..791e103c18f
--- /dev/null
+++ b/source/blender/python/api2_2x/doc/BezTriple.py
@@ -0,0 +1,94 @@
+# Blender.BezTriple module and the BezTriple PyType object
+
+"""
+The Blender.BezTriple submodule
+
+B{New}:
+ - new attributes L{handleTypes<BezTriple.handleTypes>},
+ L{selects<BezTriple.selects>} and L{weight<BezTriple.weight>}
+
+This module provides access to the BezTriple Data in Blender. It is used by
+CurNurb and IpoCurve objects.
+
+@type HandleTypes: readonly dictionary
+@var HandleTypes: The available BezTriple handle types.
+ - FREE - handle has no constrints
+ - AUTO - completely constrain handle based on knot position
+ - VECT - constraint handle to line between current and neighboring knot
+ - ALIGN - constrain handle to lie in a straight line with knot's other
+ handle
+ - AUTOANIM - constrain IPO handles to be horizontal on extremes
+"""
+
+def New (coords):
+ """
+ Create a new BezTriple object.
+
+ @type coords: sequence of three or nine floats
+ @param coords: the coordinate values for the new control point. If three
+ floats are given, then the handle values are automatically generated.
+ @rtype: BezTriple
+ @return: a new BezTriple object
+ """
+
+class BezTriple:
+ """
+ The BezTriple object
+ ====================
+ This object gives access to generic data from all BezTriple objects in
+ Blender.
+ @ivar pt : the [x,y] coordinates for knot point of this BezTriple. After
+ changing coordinates of a Ipo curve, it is advisable to call
+ L{IpoCurve.recalc()<IpoCurve.IpoCurve.recalc>} to update the curve.
+ @type pt: list of two floats
+ @ivar vec : a list of the 3 points [ handle, knot, handle ] that comprise a
+ BezTriple, with each point composed of a list [x,y,z] of floats. The list
+ looks like [ [H1x, H1y, H1z], [Px, Py, Pz], [H2x, H2y, H2z] ].
+ Example::
+ # where bt is of type BezTriple
+ # and h1, p, and h2 are lists of 3 floats
+ h1, p, h2 = bt.vec
+ @type vec: list of points
+ @ivar tilt: the tilt/alpha value for the point
+ @type tilt: float
+ @ivar hide: the visibility status of the knot. B{Note}: true/nonzero means
+ I{not} hidden. B{Note}: primarily intended for curves; not a good idea to
+ hide IPO control points.
+ @type hide: int
+ @ivar handleTypes: the types of the point's two handles. See
+ L{HandleTypes} for a complete description.
+ @type handleTypes list of two ints
+ @ivar selects: the select status for [handle, knot, handle]. True/nonzero
+ if the point is selected.
+ @type selects: list of three ints
+ @ivar weight: the weight assigned to the control point. Useful for
+ softbodies and possibly others.
+ @type weight: float
+ """
+
+ def getPoints():
+ """
+ Returns the x,y coordinates of the Bezier knot point (B{deprecated}).
+ See the L{BezTriple.pt} attribute.
+ @rtype: list of floats
+ @return: list of the x and y coordinates of the Bezier point.
+ """
+
+ def setPoints(newval):
+ """
+ Sets the x,y coordinates of the Bezier knot point (B{deprecated}).
+ See the L{BezTriple.pt} attribute.
+ @type newval: tuple of 2 floats
+ @param newval: the x and y coordinates of the new Bezier point.
+ @rtype: None
+ @return: None
+ """
+
+ def getTriple():
+ """
+ Returns the x,y,z coordinates for each of the three points that make up
+ a BezierTriple (B{deprecated}). See the L{BezTriple.vec} attribute.
+ @rtype: list consisting of 3 lists of 3 floats
+ @return: handle1, knot, handle2
+ """
+
diff --git a/source/blender/python/api2_2x/doc/Ipo.py b/source/blender/python/api2_2x/doc/Ipo.py
index 69c129fb08d..ca660f05f61 100644
--- a/source/blender/python/api2_2x/doc/Ipo.py
+++ b/source/blender/python/api2_2x/doc/Ipo.py
@@ -5,31 +5,66 @@ The Blender.Ipo submodule
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 now supports the mapping operator [] to access IpoCurves
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)
+ from Blender import Ipo
+
+ ob = Ipo.Get('ObIpo') # retrieves an Ipo object
+ ob.name = 'ipo1' # change the Ipo's name
+ icu = ipo[Ipo.OB_LOCX] # request X Location Ipo curve object
+ if icu != None and len(icu.bezierPoints) > 0: # if curve exists and has BezTriple points
+ val = icu[2.5] # get the curve's value at time 2.5
+ icu[Ipo.OB_lOCX] = None # delete the ipo curve
-@type HandleTypes: readonly dictionary
-@var HandleTypes: The available BezTriple handle types.
- - FREE - handle has no constrints
- - AUTO - completely constrain handle based on knot position
- - VECT - constraint handle to line between current and neighboring knot
- - ALIGN - constrain handle to lie in a straight line with knot's other
- handle
- - AUTOANIM - constrain IPO handles to be horizontal on extremes
+Each type of Ipo has different types Ipocurves. With the exception of Shape
+Key Ipos, constants are used to specify all Ipocurves. There are two ways
+to tell which Ipo curves go with which Ipo type:
+ - all constants start with a two-character identifier for their Ipo type;
+ for example, "OB_LOCX" is the LocX curve for an Object Ipo
+ - each Ipo now has a read-only attribute L{Ipo.curveConsts}, which returns
+ the valid Ipo curve types for that specific Ipo
+
+The valid IpoCurve constants are:
+ 1. Material Ipo: MA_R, MA_G, MA_B, MA_SPECR, MA_SPECG, MA_SPECB,
+ MA_MIRR, MA_MIRG, MA_MIRB, MA_REF, MA_ALPHA, MA_EMIT, MA_AMB,
+ MA_SPEC, MA_HARD, MA_SPTRA, MA_IOR, MA_MODE, MA_HASIZE, MA_TRANSLU,
+ MA_RAYMIR, MA_FRESMIR, MA_FRESMIRI, MA_FRESTRA, MA_FRESTRAI,
+ MA_TRAGLOW, MA_OFSX, MA_OFSY, MA_OFSZ, MA_SIZEX, MA_SIZEY, MA_SIZEZ,
+ MA_TEXR, MA_TEXG, MA_TEXB, MA_DEFVAR, MA_COL, MA_NOR, MA_VAR, MA_DISP
+ 2. Lamp Ipo: LA_ENERG, LA_R, LA_G, LA_B, LA_DIST, LA_SPOSI, LA_SPOBL,
+ LA_QUAD1, LA_QUAD2, LA_HAINT, LA_OFSX, LA_OFSY, LA_OFSZ, LA_SIZEX,
+ LA_SIZEY, LA_SIZEZ, LA_TEXR, LA_TEXG, LA_TEXB, LA_DEFVAR, LA_COL
+ 3. World Ipo: WO_HORR, WO_HORG, WO_HORB, WO_ZENR, WO_ZENG, WO_ZENB,
+ WO_EXPOS, WO_MISI, WO_MISDI, WO_MISSTA, WO_MISHI, WO_STARR,
+ WO_STARB, WO_STARG, WO_STARDI, WO_STARSI, WO_OFSX, WO_OFSY,
+ WO_OFSZ, WO_SIZEX, WO_SIZEY, WO_SIZEZ, WO_TEXR, WO_TEXG,
+ WO_TEXB, WO_DEFVAR, WO_COL, WO_NOR, WO_VAR
+ 4. Camera Ipo: CA_LENS, CA_CLSTA, CA_CLEND, CA_APERT, CA_FDIST
+ 5. Object Ipo: OB_LOCX, OB_LOCY, OB_LOCZ, OB_DLOCX, OB_DLOCY, OB_DLOCZ,
+ OB_ROTX, OB_ROTY, OB_ROTZ, OB_DROTX, OB_DROTY, OB_DROTZ,
+ OB_SIZEX, OB_SIZEY, OB_SIZEZ, OB_DSIZEX, OB_DSIZEY, OB_DSIZEZ,
+ OB_LAYER, OB_TIME, OB_COLR, OB_COLG, OB_COLB, OB_COLA,
+ OB_FSTRENG, OB_FFALL, OB_RDAMP, OB_DAMPING, OB_PERM
+ 6. Curve Ipo: CU_SPEED
+ 7. Constraint Ipo: CO_INF
+ 8. Texture Ipo: TE_NSIZE, TE_NDEPTH, TE_NTYPE, TE_TURB, TE_VNW1, TE_VNW2,
+ TE_VNW3, TE_VNW4, TE_MINKMEXP, TE_DISTM, TE_COLT, TE_ISCALE,
+ TE_DISTA, TE_MGTYPE, TE_MGH, TE_LACU, TE_OCT, TE_MGOFF,
+ TE_MGGAIN, TE_NBASE1, TE_NBASE2, TE_COLR, TE_COLG, TE_COLB,
+ TE_BRIGHT, TE_CONTRAS
+ 9. Pose/Action Ipo: PO_LOCX, PO_LOCY, PO_LOCZ, PO_SIZEX, PO_SIZEY,
+ PO_SIZEZ, PO_QUATW, PO_QUATX, PO_QUATY, PO_QUATZ
+ 10. Sequence Ipo: SQ_FAC
+
+Shape Key Ipos are handled differently from other Ipos. The user can rename
+the curves, so string are used to access them instead of constants. The
+L{Ipo.curveConsts} attribute for Shape Key Ipos returns a list of all defined
+key names.
"""
def New (type, name):
@@ -53,34 +88,159 @@ def Get (name = None):
@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)
+ names = dict([(x[1],x[0]) for x in ipo.curveConsts.items()])
+ for curve in [Ipo.MA_R,Ipo.MA_COL]:
+ print ' ',names[curve],'is',curve in ipo
+
+ will output::
+ channel is 0
+ len is 4
+ MA_R is True
+ MA_COL is True
+ channel is 1
+ len is 3
+ MA_R is True
+ MA_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 curveConsts: The valid Ipo curves for this Ipo. These can be used
+ by the [] mapping operator. The value
+ depends on the Ipo curve type. If the Ipo is any type other than a Key or
+ Shape Ipo, this attribute returns a set of constants that can be
+ used to specify a particular curve. For Key or Shape Ipos, the attribute
+ returns a list of all defined keys by name.
+ @type curveConsts: constant or list of strings. Read-only.
+ @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__():
+ """
+ The "in" operator for Ipos. It returns B{True} if the specified
+ IpoCurve exists for the Ipo. This operator B{should not} be used to
+ test for whether a curve constant is valid for a particular Ipo type.
+ Many constants for different Ipo types have the same value, and it is
+ the constant's value used internally.
+ No exceptions are raised if the argument is not a valid curve constant or
+ or string, nor does the operator return B{True} when the curve
+ constant is valid but does not currently exist. As such, it should only be
+ used to test for specific curves when the Ipo type is known::
+ ipo = Object.Get('Cube').ipo # get Object-type Ipo
+ if ipo:
+ print Ipo.OB_LOCX in ipo # prints "True" if 'LocX' curve exists
+ print Ipo.MA_R in ipo # also prints "True" since MA_R and OB_LOCX are have the same value
+ print 'hiccup' in ipo # always prints "False" since argument is not a constant
+
+ @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 defined 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:
@@ -111,8 +271,8 @@ class Ipo:
9. Sequence Ipo: Fac.
10. Constraint Ipo: Inf.
- The adrcode for the Ipo curve can also be given; currently this is the
- only way to access curves for Key Ipos. The adrcodes for Key Ipo are
+ The adrcode for the Ipo curve can also be given; this is useful for
+ accessing curves for Shape Key Ipos. The adrcodes for Shape Key Ipo are
numbered consecutively starting at 0.
@type curve : string or int
@rtype: IpoCurve object
@@ -158,20 +318,18 @@ class Ipo:
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 L{mapping operator B{[]}<__getitem__>} instead::
+ from Blender import Ipo
+
+ ipo = Ipo.Get('ObIpo')
+ ipo[Ipo.LOCX] = None
+
@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 +367,8 @@ class Ipo:
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 +382,8 @@ class Ipo:
def getBeztriple(curvepos,pointpos):
"""
- Gets a beztriple of the Ipo.
+ Gets a beztriple of the Ipo (B{deprecated}). B{Note}:
+ Use L{IpoCurve.bezierPoints<IpoCurve.IpoCurve.bezierPoints>} instead.
@type curvepos: int
@param curvepos: the position of the curve in the Ipo.
@type pointpos: int
@@ -234,7 +394,10 @@ class Ipo:
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<IpoCurve.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
@@ -248,7 +411,7 @@ class Ipo:
def getCurveCurval(curvepos):
"""
Gets the current value of a curve of the Ipo (B{deprecated}). B{Note}:
- new scripts should use L{IpoCurve.evaluate()}.
+ new scripts should use L{IpoCurve.evaluate()<IpoCurve.IpoCurve.evaluate>}.
@type curvepos: int or string
@param curvepos: the position of the curve in the Ipo or the name of the
curve
@@ -259,229 +422,14 @@ class Ipo:
def EvaluateCurveOn(curvepos,time):
"""
Gets the value at a specific time of a curve of the Ipo (B{deprecated}).
- B{Note}: new scripts should use L{IpoCurve.evaluate()}.
+ B{Note}: new scripts should use
+ L{IpoCurve.evaluate()<IpoCurve.IpoCurve.evaluate>}.
@type curvepos: int
@param curvepos: the position of the curve in the Ipo.
@type time: float
@param time: the desired time.
@rtype: float
@return: the current value of the selected curve of the Ipo at the given
- time.
- """
-
-class IpoCurve:
- """
- The IpoCurve object
- ===================
- 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
- degrees. For example, 45.0 degrees is stored as 4.50 degrees. These are the
- same numbers you see in the Transform Properties pop-up menu ( NKey ) in
- the IPO Curve Editor window. Positive rotations are in a counter-clockwise
- direction, following the standard convention.
-
- @ivar driver: Status of the driver. 1= on, 0= off.
- @type driver: int
- @ivar driverObject: Object used to drive the Ipo curve.
- @type driverObject: Blender Object or None
- @ivar driverChannel: Object channel used to drive the Ipo curve.
- Use module constants: IpoCurve.LOC_X, IpoCurve.LOC_Y, IpoCurve.LOC_Z,
- IpoCurve.ROT_X, IpoCurve.ROT_Y, IpoCurve.ROT_Z, IpoCurve.SIZE_X,
- IpoCurve.SIZE_Y, IpoCurve.SIZE_Z
- @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
- """
-
- def setExtrapolation(extendmode):
- """
- Sets the extend mode of the curve.
- @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.
- @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.
- @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.
- @rtype: string
- @return: the interpolation type of the curve. Can be Constant, Bezier, or Linear.
- """
-
- def addBezier(coordlist):
- """
- Adds a Bezier point to a curve.
- @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.
- @type index: integer
- @param index: the index of the Bezier point. Negative values index from the end of the list.
- @rtype: None
- @return: None
+ time.
"""
- def recalc():
- """
- Recomputes the curve after changes to control points.
- @rtype: None
- @return: None
- """
-
- def getName():
- """
- Returns the name of the Ipo curve. This 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,
- RayMir, FresMir, FresMirI, FresTra, FresTraI, TraGlow, OfsX, OfsY,
- OfsZ, SizeX, SizeY, SizeZ, texR, texG, texB, DefVar, Col, Nor, Var,
- Disp.
- 3. Object Ipo: LocX, LocY, LocZ, dLocX, dLocY, dLocZ, RotX, RotY, RotZ,
- dRotX, dRotY, dRotZ, SizeX, SizeY, SizeZ, dSizeX, dSizeY, dSizeZ,
- Layer, Time, ColR, ColG, ColB, ColA, FStreng, FFall, Damping,
- RDamp, Perm.
- 4. Lamp Ipo: Energ, R, G, B, Dist, SpoSi, SpoBl, Quad1, Quad2, HaInt.
- 5. World Ipo: HorR, HorG, HorB, ZenR, ZenG, ZenB, Expos, Misi, MisDi,
- MisSta, MisHi, StaR, StaG, StaB, StarDi, StarSi, OfsX, OfsY, OfsZ,
- SizeX, SizeY, SizeZ, TexR, TexG, TexB, DefVar, Col, Nor, Var.
- 5. World Ipo: HorR, HorG, HorB, ZenR, ZenG, ZenB, Expos, Misi, MisDi,
- MisSta, MisHi, StarR, StarB, StarG, StarDi, StarSi, OfsX, OfsY, OfsZ,i
- SizeX, SizeY, SizeZ, texR, texG, texB, DefVar, Col, Nor, Var.
- 6. Texture Ipo: NSize, NDepth, NType, Turb, Vnw1, Vnw2, Vnw3, Vnw4,
- MinkMExp, DistM, ColT, iScale, DistA, MgType, MgH, Lacu, Oct,
- MgOff, MgGain, NBase1, NBase2.
- 7. Curve Ipo: Speed.
- 8. Action Ipo: LocX, LocY, LocZ, SizeX, SizeY, SizeZ, QuatX, QuatY,
- QuatZ, QuatW.
- 9. Sequence Ipo: Fac.
- 10. Constraint Ipo: Inf.
-
- @rtype: string
- @return: the name of the Ipo curve.
- """
-
- def getPoints():
- """
- Returns all the points of the Ipo curve.
- @rtype: list of BezTriples
- @return: the points of the Ipo curve.
- """
-
- def evaluate( time ):
- """
- Compute the value of the Ipo curve at a particular time.
- @type time: float
- @param time: value along the X axis
- @rtype: float
- @return: the Y value of the curve at the given time
- """
-
-class BezTriple:
- """
- The BezTriple object
- ====================
- This object gives access to generic data from all BezTriple objects in
- Blender.
- @ivar pt : the [x,y] coordinates for knot point of this BezTriple. After
- changing coordinates of a Ipo curve, it is advisable to call
- L{IpoCurve.recalc()} to update the curve.
- @type pt: list of two floats
- @ivar vec : a list of the 3 points [ handle, knot, handle ] that comprise a
- BezTriple, with each point composed of a list [x,y,z] of floats. The list
- looks like [ [H1x, H1y, H1z], [Px, Py, Pz], [H2x, H2y, H2z] ].
- Example::
- # where bt is of type BezTriple
- # and h1, p, and h2 are lists of 3 floats
- h1, p, h2 = bt.vec
- @type vec: list of points
- @ivar tilt: the tilt/alpha value for the point
- @type tilt: float
- @ivar hide: the visibility status of the knot. B{Note}: true/nonzero means
- I{not} hidden. B{Note}: primarily intended for curves; not a good idea to
- hide IPO control points.
- @type hide: int
- @ivar handleTypes: the types of the point's two handles. See
- L{HandleTypes} for a complete description.
- @type handleTypes list of two ints
- @ivar selects: the select status for [handle, knot, handle]. True/nonzero
- if the point is selected.
- @type selects: list of three ints
- @ivar weight: the weight assigned to the control point. Useful for
- softbodies and possibly others.
- @type weight: float
- """
-
- def __init__(coords):
- """
- Create a new BezTriple object.
-
- @type coords: sequence of three or nine floats
- @param coords: the coordinate values for the new control point. If three
- floats are given, then the handle values are automatically generated.
- @rtype: BezTriple
- @return: a new BezTriple object
- """
-
- def getPoints():
- """
- Returns the x,y coordinates of the Bezier knot point (B{deprecated}).
- See the L{BezTriple.pt} attribute.
- @rtype: list of floats
- @return: list of the x and y coordinates of the Bezier point.
- """
-
- def setPoints(newval):
- """
- Sets the x,y coordinates of the Bezier knot point (B{deprecated}).
- See the L{BezTriple.pt} attribute.
- @type newval: tuple of 2 floats
- @param newval: the x and y coordinates of the new Bezier point.
- @rtype: None
- @return: None
- """
-
- def getTriple():
- """
- Returns the x,y,z coordinates for each of the three points that make up
- a BezierTriple (B{deprecated}). See the L{BezTriple.vec} attribute.
- @rtype: list consisting of 3 lists of 3 floats
- @return: handle1, knot, handle2
- """
diff --git a/source/blender/python/api2_2x/doc/IpoCurve.py b/source/blender/python/api2_2x/doc/IpoCurve.py
new file mode 100644
index 00000000000..59288bf1f97
--- /dev/null
+++ b/source/blender/python/api2_2x/doc/IpoCurve.py
@@ -0,0 +1,223 @@
+# Blender.IpoCurve module and the IpoCurve PyType object
+
+"""
+The Blender.IpoCurve submodule
+
+B{New}:
+ - IpoCurves supports the operator [], which accesses the value of
+ curves at a given time.
+
+This module provides access to the IpoCurve data in Blender. An Ipo is
+composed of several IpoCurves, and an IpoCurve are composed of several
+BezTriples.
+
+Example::
+ import Blender
+ ob = Blender.Ipo.Get('ObIpo') # retrieves an Ipo object
+ ob.name = 'ipo1' # change the Ipo's name
+ icu = ipo[Blender.Ipo.OB_LOCX] # request X Location Ipo curve object
+ if icu != None and len(icu.bezierPoints) > 0: # if curve exists and has BezTriple points
+ val = icu[2.5] # get the curve's value at time 2.5
+
+@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
+"""
+
+class IpoCurve:
+ """
+ The IpoCurve object
+ ===================
+ 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
+ degrees. For example, 45.0 degrees is stored as 4.50 degrees. These are the
+ same numbers you see in the Transform Properties pop-up menu ( NKey ) in
+ the IPO Curve Editor window. Positive rotations are in a counter-clockwise
+ direction, following the standard convention.
+
+ @ivar driver: Status of the driver. 1= on, 0= off.
+ @type driver: int
+ @ivar driverObject: Object used to drive the Ipo curve.
+ @type driverObject: Blender Object or None
+ @ivar driverChannel: Object channel used to drive the Ipo curve.
+ Use module constants: IpoCurve.LOC_X, IpoCurve.LOC_Y, IpoCurve.LOC_Z,
+ IpoCurve.ROT_X, IpoCurve.ROT_Y, IpoCurve.ROT_Z, IpoCurve.SIZE_X,
+ IpoCurve.SIZE_Y, IpoCurve.SIZE_Z
+ @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 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.bezierPoints[-1].pt
+ @type extend: int
+ """
+
+ def __getitem__ (time):
+ """
+ Returns the value of the curve at a particular time.
+ @type time: float
+ @param time: time (Vertex X) on the curve
+ @rtype: float
+ @return: value (Vertex Y) corresponding to the given time
+ """
+
+ def __setitem__ (time):
+ """
+ Sets the value (Vertex Y) of the curve at a particular time.
+ @type time: float
+ @param time: time (Vertex X) on the curve
+ """
+
+ def setExtrapolation(extendmode):
+ """
+ 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
+ """
+
+ def getExtrapolation():
+ """
+ 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 (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 (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 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 (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
+ @return: None
+ """
+
+ def recalc():
+ """
+ Recomputes the curve after changes to control points.
+ @rtype: None
+ @return: None
+ """
+
+ def getName():
+ """
+ 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,
+ RayMir, FresMir, FresMirI, FresTra, FresTraI, TraGlow, OfsX, OfsY,
+ OfsZ, SizeX, SizeY, SizeZ, texR, texG, texB, DefVar, Col, Nor, Var,
+ Disp.
+ 3. Object Ipo: LocX, LocY, LocZ, dLocX, dLocY, dLocZ, RotX, RotY, RotZ,
+ dRotX, dRotY, dRotZ, SizeX, SizeY, SizeZ, dSizeX, dSizeY, dSizeZ,
+ Layer, Time, ColR, ColG, ColB, ColA, FStreng, FFall, Damping,
+ RDamp, Perm.
+ 4. Lamp Ipo: Energ, R, G, B, Dist, SpoSi, SpoBl, Quad1, Quad2, HaInt.
+ 5. World Ipo: HorR, HorG, HorB, ZenR, ZenG, ZenB, Expos, Misi, MisDi,
+ MisSta, MisHi, StaR, StaG, StaB, StarDi, StarSi, OfsX, OfsY, OfsZ,
+ SizeX, SizeY, SizeZ, TexR, TexG, TexB, DefVar, Col, Nor, Var.
+ 5. World Ipo: HorR, HorG, HorB, ZenR, ZenG, ZenB, Expos, Misi, MisDi,
+ MisSta, MisHi, StarR, StarB, StarG, StarDi, StarSi, OfsX, OfsY, OfsZ,i
+ SizeX, SizeY, SizeZ, texR, texG, texB, DefVar, Col, Nor, Var.
+ 6. Texture Ipo: NSize, NDepth, NType, Turb, Vnw1, Vnw2, Vnw3, Vnw4,
+ MinkMExp, DistM, ColT, iScale, DistA, MgType, MgH, Lacu, Oct,
+ MgOff, MgGain, NBase1, NBase2.
+ 7. Curve Ipo: Speed.
+ 8. Action Ipo: LocX, LocY, LocZ, SizeX, SizeY, SizeZ, QuatX, QuatY,
+ QuatZ, QuatW.
+ 9. Sequence Ipo: Fac.
+ 10. Constraint Ipo: Inf.
+
+ @rtype: string
+ @return: the name of the Ipo curve.
+ """
+
+ def getPoints():
+ """
+ Returns all the points of the IpoCurve (B{deprecated}).
+ B{Note}: new scripts should use the L{bezierPoints} attribute instead.
+ @rtype: list of BezTriples
+ @return: the points of the Ipo curve.
+ """
+
+ def evaluate( time ):
+ """
+ Compute the value of the Ipo curve at a particular time (B{deprecated}).
+ B{Note}: new scripts should use L{icu[time]<__getitem__>} instead.
+ @type time: float
+ @param time: value along the X axis
+ @rtype: float
+ @return: the Y value of the curve at the given time
+ """
+