Page MenuHome

stage4-patch-Ipo.c

Authored By
Ken Hughes (khughes)
Nov 13 2013, 1:05 PM
Size
78 KB
Subscribers
None

stage4-patch-Ipo.c

--- source/blender/python/api2_2x/Ipo.c 2005-07-05 23:39:07.000000000 -0700
+++ source/blender/python/api2_2x/Ipo.c 2005-07-08 07:02:41.000000000 -0700
@@ -48,6 +48,7 @@
#include "Ipocurve.h"
#include "constant.h"
+#include "Types.h"
#include "gen_utils.h"
/*****************************************************************************/
@@ -166,18 +167,18 @@
/*****************************************************************************/
/* Python IpoCurve_Type callbacks for get/set of instance variables */
/*****************************************************************************/
+static PyObject * Ipo_listCurveTypes ( BPy_Ipo *self );
+static PyObject * Ipo_checkCurveTypes ( BPy_Ipo *self, char * name );
static PyGetSetDef BPY_Ipo_getseters[] = {
{"curves",
(getter)Ipo_getCurves, (setter)NULL,
"Ipo curve list",
NULL},
-#if 0
- {"bezierPoints",
- (getter)IpoCurve_getPoints, (setter)IpoCurve_setPoints,
- "BezTriple list",
+ {"types",
+ (getter)Ipo_listCurveTypes, (setter)NULL,
+ "Ipo curve names",
NULL},
-#endif
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
};
@@ -196,6 +197,9 @@
(objobjargproc)Ipo_setItem /* mp_ass_subscript (__setitem__) */
};
+static PyObject *Ipo_getAttr(PyObject *obj, PyObject *name);
+static int Ipo_setAttr(PyObject *obj, PyObject *name, PyObject *value);
+
/*****************************************************************************/
/* Python Ipo_Type structure definition: */
/*****************************************************************************/
@@ -218,8 +222,8 @@
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
+ Ipo_getAttr, /* tp_getattro */
+ Ipo_setAttr, /* tp_setattro */
0, /* tp_as_buffer */
/*** Flags to define presence of optional/expanded features ***/
@@ -253,6 +257,53 @@
0, /* tp_del */
};
+/*
+ * external references needed for curve name parsing; would be useful
+ * if these were exported in various *.h files
+ */
+
+/* in source/blender/src/editipo.c: */
+extern char *ac_ic_names[];
+extern char *cam_ic_names[];
+extern char *co_ic_names[];
+extern char *cu_ic_names[];
+extern char *key_ic_names[];
+extern char *la_ic_names[];
+extern char *ma_ic_names[];
+extern char *mtex_ic_names[];
+extern char *ob_ic_names[];
+extern char *seq_ic_names[];
+extern char *snd_ic_names[];
+extern char *tex_ic_names[];
+extern char *wo_ic_names[];
+
+/* in source/blender/blenkernel/intern/ipo.c: */
+extern int ob_ar[];
+extern int ma_ar[];
+extern int seq_ar[];
+extern int cu_ar[];
+extern int key_ar[];
+extern int wo_ar[];
+extern int la_ar[];
+extern int cam_ar[];
+extern int snd_ar[];
+extern int ac_ar[];
+extern int co_ar[];
+extern int te_ar[];
+
+/*
+ * structure describing everything needed for building a curve dictionary
+ * for each IPO type
+ */
+
+typedef struct ipocurve_dictInfo {
+ int blocktype; /* IPO block type */
+ char * prefix; /* string to pre-pend to each curve name */
+ char ** curve_names; /* list of strings of curve names */
+ int * adr_codes; /* list of curve code */
+ int num_adr_codes; /* length of each list */
+} ipocurve_dictInfo;
+
/*****************************************************************************/
/* Function: M_Ipo_New */
/* Python equivalent: Blender.Ipo.New */
@@ -315,6 +366,9 @@
"couldn't create Ipo Data object" ) );
pyipo->ipo = blipo;
+#ifdef TEXCHANNELS
+ pyipo->channel = 0;
+#endif
return ( PyObject * ) pyipo;
}
@@ -332,7 +386,6 @@
char *name = NULL;
Ipo *ipo_iter;
PyObject *ipolist, *pyobj;
- BPy_Ipo *wanted_ipo = NULL;
char error_msg[64];
if( !PyArg_ParseTuple( args, "|s", &name ) )
@@ -342,25 +395,17 @@
ipo_iter = G.main->ipo.first;
if( name ) { /* (name) - Search ipo by name */
- while( ( ipo_iter ) && ( wanted_ipo == NULL ) ) {
+ while( ipo_iter ) {
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;
+ 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 */
@@ -372,16 +417,16 @@
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
"couldn't create PyList" ) );
+ /*
+ * add each curve to the list; if Ipo_CreatePyObject() returns
+ * NULL, it's already thrown an exception so just exit
+ */
+
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 );
-
ipo_iter = ipo_iter->id.next;
index++;
}
@@ -390,6 +435,68 @@
}
}
+/*
+ * local wrapper for PyObject_GenericGetAttr() which check first for
+ * access to IpoCurve name dictionary
+ */
+
+static PyObject *
+Ipo_getAttr(PyObject *obj, PyObject *name)
+{
+ /* if argument is a string (what else would it be?), check dict */
+
+ if (PyString_Check(name)) {
+ BPy_Ipo *self = (BPy_Ipo *)obj;
+ char *str = PyString_AS_STRING( name );
+ PyObject * dictentry;
+
+ /* if we get a dictionary key 'hit', return the value */
+
+ dictentry = Ipo_checkCurveTypes ( self, str );
+ if (dictentry)
+ return dictentry;
+ }
+
+ /* all other attributes checked here */
+
+ return PyObject_GenericGetAttr (obj, name);
+}
+
+/*
+ * local wrapper for PyObject_GenericSetAttr() which check first for
+ * access to IpoCurve name dictionary and throws TypeError 'attribute
+ * not writable' * instead of TypeError 'has no attribute'
+ */
+
+static int
+Ipo_setAttr(PyObject *obj, PyObject *name, PyObject *value)
+{
+
+ /* if argument is a string (what else would it be?), check dict */
+
+ if (PyString_Check(name)) {
+ BPy_Ipo *self = (BPy_Ipo *)obj;
+ char *str = PyString_AS_STRING( name );
+ PyObject * dictentry;
+
+ /* if we get a dictionary key 'hit', throw our exception */
+
+ dictentry = Ipo_checkCurveTypes ( self, str );
+ if (dictentry) {
+ char error_msg[128];
+ Py_DECREF ( dictentry );
+ PyOS_snprintf( error_msg, sizeof( error_msg ),
+ "attribute '%s' of '%s' objects is not writable",
+ str,obj->ob_type->tp_name);
+ return EXPP_ReturnIntError ( PyExc_TypeError, error_msg );
+ }
+ }
+
+ /* all other attributes checked here */
+
+ return PyObject_GenericSetAttr (obj, name, value);
+}
+
/*****************************************************************************/
/* Function: Ipo_Init */
@@ -398,14 +505,16 @@
{
PyObject *submodule;
- Ipo_Type.ob_type = &PyType_Type;
+ // Ipo_Type.ob_type = &PyType_Type;
/*
* These are necessary for tp_getset
*/
- Ipo_Type.tp_getattro = &PyObject_GenericGetAttr;
- Ipo_Type.tp_setattro = &PyObject_GenericSetAttr;
+ // Ipo_Type.tp_getattro = &Ipo_getAttr;
+ // Ipo_Type.tp_setattro = &Ipo_setAttr;
+
+ PyType_Ready( &Ipo_Type );
submodule = Py_InitModule3( "Blender.Ipo", M_Ipo_methods, M_Ipo_doc );
@@ -415,6 +524,7 @@
/*****************************************************************************/
/* Python BPy_Ipo methods: */
/*****************************************************************************/
+
static PyObject *Ipo_getName( BPy_Ipo * self )
{
PyObject *attr = PyString_FromString( self->ipo->id.name + 2 );
@@ -487,1305 +597,1641 @@
return Py_None;
}
-/*
- Lamp ipo Name to Channel
+
+/*
+ Function: Ipo_append
+ Bpy: Blender.Ipo.append( 'curname')
+
+ add a new curve to an existing IPO.
+ example:
+ ipo = Blender.Ipo.New('Object','ObIpo')
+ cu = ipo.append('LocX')
*/
-static int Ipo_laIcuName( char *s, int *param )
+#if BLENDER_VERSION < 241
+static PyObject *Ipo_oldAppend( Ipo * ipo, char *cur_name );
+#endif
+
+static PyObject *Ipo_append( BPy_Ipo * self, PyObject * args )
{
- extern int la_ar[];
+ int param = 0; /* numeric curve name constant */
+ Ipo *ipo = 0;
+ IpoCurve *icu = 0;
+ Link *link;
+ BPy_constant *constant = NULL;
+ static int depcount=2;
- 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"
- };
+#if BLENDER_VERSION < 241
+ char *cur_name = NULL; /* input arg: curve name */
+ if ( PySequence_Size( args ) > 0
+ && PyString_Check ( PySequence_Fast_GET_ITEM ( args , 0 ) ) ) {
+ if( !PyArg_ParseTuple( args, "s", &cur_name ) )
+ return EXPP_ReturnPyObjError
+ ( PyExc_TypeError, "expected string or module constant" );
+ } else
+#endif
+ if( PyArg_ParseTuple( args, "O!", &constant_Type, &constant ) )
+ param = PyInt_AS_LONG(PyDict_GetItemString(constant->dict, "value"));
+ else
+ return EXPP_ReturnPyObjError
+ ( PyExc_TypeError, "expected module constant" );
- for( i = 0; i < LA_TOTIPO; i++ ) {
- if( !strcmp( s, lamp_names[i] ) ) { /* found it! */
- *param = la_ar[i];
- return 1;
+ /* chase down the ipo list looking for ours */
+ link = G.main->ipo.first;
+
+ while( link ) {
+ ipo = ( Ipo * ) link;
+ if( ipo == self->ipo ) {
+ break;
}
+ link = link->next;
}
- return not_ok;
-}
+ /*
+ * if link is NULL, the IPO was deleted
+ */
+ if ( !link )
+ return EXPP_ReturnPyObjError ( PyExc_RuntimeError,
+ "Ipo not found" );
-/*
- World Ipo Name to Channel
-*/
+#if BLENDER_VERSION < 241
+ if ( cur_name ) /* if passed a string, handle the old way */
+ return Ipo_oldAppend( ipo, cur_name );
+#endif
-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",
- };
+ /*
+ * see if the curve already exists
+ */
- for( i = 0; i < WO_TOTIPO; i++ ) {
- if( !strcmp( s, world_names[i] ) ) { /* found it! */
- *param = wo_ar[i];
- return 1;
+ icu= ipo->curve.first;
+ while (icu) {
+ if( icu->adrcode == param ) {
+#if BLENDER_VERSION < 241
+ if ( depcount ) {
+ printf ( "Calling Ipo.append() with an existing curve is deprecated;\n");
+ printf ( " this will throw a ValueError exception after V2.40.\n" );
+ --depcount;
+ }
+#else
+ return EXPP_ReturnPyObjError ( PyExc_ValueError,
+ "curve already exists" );
+#endif
}
+ icu= icu->next;
}
- 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"
- };
+
+ /* ask blender to create the new ipo curve */
+ icu = get_ipocurve( NULL, ipo->blocktype, param, self->ipo );
+ if( !icu ) /* could not create curve */
+ return EXPP_ReturnPyObjError ( PyExc_RuntimeError,
+ "blender could not create ipo curve" );
- for( i = 0; i < MA_TOTIPO; i++ ) {
- if( !strcmp( s, material_names[i] ) ) { /* found it! */
- *param = ma_ar[i];
- return 1;
- }
- }
+ allspace( REMAKEIPO, 0 );
+ EXPP_allqueue( REDRAWIPO, 0 );
- return not_ok;
+ /* create a bpy wrapper for the new ipo curve */
+ return IpoCurve_CreatePyObject( icu );
}
-static int Ipo_keIcuName( char *s, int *param )
+static PyObject *Ipo_getCurves( BPy_Ipo * self )
{
- char key[10];
- int ok = 0;
- int nr = 0;
- if( !strcmp( s, "Speed" ) ) {
- *param = KEY_SPEED;
- ok = 1;
- }
- for( nr = 1; nr < 64; nr++ ) {
- sprintf( key, "Key %d", nr );
- if( !strcmp( s, key ) ) {
- *param = nr;
- ok = 1;
- break;
- }
- }
+ PyObject *list;
+ IpoCurve *icu;
- return ok;
-}
+ list = PyList_New( 0 );
+ if (!list)
+ return EXPP_ReturnPyObjError( PyExc_MemoryError,
+ "couldn't create PyList object" );
+ /*
+ * if IpoCurve_CreatePyObject returns NULL, it already threw an
+ * exception and things are messed up, so just give up
+ */
-static int Ipo_seqIcuName( char *s, int *param )
-{
- int ok = 0;
- if( !strcmp( s, "Fac" ) ) {
- *param = SEQ_FAC1;
- ok = 1;
+ for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
+ PyObject *obj;
+#ifdef TEXCHANNELS
+ /*
+ * if IPO isn't a texchannel but curve is, or IPO is a texchannel
+ * but curve not in the correct channel, skip
+ */
+
+ if ( ( !self->channel && icu->adrcode >= MA_MAP1 ) ||
+ !(self->channel & icu->adrcode) )
+ continue;
+#endif
+ obj = IpoCurve_CreatePyObject( icu );
+ if (!obj) {
+ Py_DECREF ( list );
+ return NULL;
+ }
+ PyList_Append( list, obj );
}
-
- return ok;
+ return list;
}
-static int Ipo_cuIcuName( char *s, int *param )
+/*****************************************************************************/
+/* Function: Ipo_length */
+/* Description: this function returns the number of curves contained in the */
+/* IPO. */
+/*****************************************************************************/
+static
+int Ipo_length( BPy_Ipo * self )
{
- int ok = 0;
- if( !strcmp( s, "Speed" ) ) {
- *param = CU_SPEED;
- ok = 1;
- }
+ int length = 0;
+ IpoCurve *icu;
- return ok;
+ for ( icu = self->ipo->curve.first; icu; icu = icu->next ) {
+ ++length;
+ }
+ return length;
}
-static int Ipo_coIcuName( char *s, int *param )
+/*****************************************************************************/
+/* Function: Ipo_getItem */
+/* Description: this is the get operator[] for mappings. Look up a curve */
+/* by name and return IpoCurve object or Py_None. */
+/*****************************************************************************/
+
+static
+PyObject * Ipo_getItem( BPy_Ipo * self, PyObject * key )
{
- int ok = 0;
- if( !strcmp( s, "Inf" ) ) {
- *param = CO_ENFORCE;
- ok = 1;
- }
+ IpoCurve *icu = NULL;
+ int param = 0; /* numeric curve name constant */
+ int mask = MA_MAP1-1; /* used to figure out range for adr_code */
- return ok;
-}
+#if BLENDER_VERSION < 241
+ char *str = NULL;
+ static int depcount=2;
-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;
+ /* check for string argument */
+
+ if ( PyString_Check ( key ) ) {
+ if ( depcount ) {
+ printf ("Using ipo[] with a string key is deprecated by module constants.\n");
+ printf (" This will throw an exception after version 2.40.\n");
+ --depcount;
+ }
+ str = PyString_AS_STRING ( key );
+ } else if ( BPy_Constant_Check(key) )
+ param = PyInt_AS_LONG( PyDict_GetItemString(
+ ((BPy_constant *)key)->dict, "value"));
+ else
+ return EXPP_ReturnPyObjError
+ ( PyExc_TypeError, "expected string or module constant" );
+
+ /*
+ * is str is not NULL, get adr_code from corresponding dictionary
+ * (return None if string not found).
+ */
+
+ if ( str ) {
+ BPy_constant *obj = (BPy_constant *)Ipo_checkCurveTypes ( self, str );
+ if (!obj)
+ return EXPP_incr_ret ( Py_None );
+ param = PyInt_AS_LONG( PyDict_GetItemString( obj->dict, "value" ) );
+ Py_DECREF (obj);
}
- if( !strcmp( s, "QuatW" ) ) {
- *param = AC_QUAT_W;
- return 1;
+#else
+ if ( !BPy_Constant_Check(key) )
+ return EXPP_ReturnPyObjError
+ ( PyExc_TypeError, "expected module constant" );
+
+ param = PyInt_AS_LONG( PyDict_GetItemString(
+ ((BPy_constant *)key)->dict, "value"));
+#endif
+
+ /*
+ * since largest curve for Keys is larger than MA_MAP1,
+ * adjust the mask if this is a Key IPO
+ */
+
+ if ( self->ipo->blocktype == ID_KE )
+ mask = 127;
+
+ /*
+ * look through the curve list for a matching adrcode
+ */
+
+ for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
+ if ( ( icu->adrcode & mask ) == param ) {
+#ifdef TEXCHANNELS
+ if ( icu->adrcode <= mask ) { /* not texture channel */
+ if ( !self->channel ) /* no channel specified */
+ return IpoCurve_CreatePyObject( icu );
+ else
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_ValueError, "texture channel value specified for non-texchannel curve" ) );
+ } else if ( self->channel & icu->adrcode ) /* texture channel matches */
+#endif
+ return IpoCurve_CreatePyObject( icu );
+ }
}
- return ok;
+ return EXPP_incr_ret ( Py_None );
}
+/*****************************************************************************/
+/* Function: Ipo_setItem */
+/* Description: this is the get operator[] for mappings. Look up a curve */
+/* by name and return IpoCurve object or Py_None. */
+/*****************************************************************************/
+static
+int Ipo_setItem( BPy_Ipo *self, PyObject *key, PyObject *value )
+{
+ char * strname = PyString_AsString ( key );
+ IpoCurve *icu;
+
+ /*
+ * if PyString_AsString returns NULL. key wasn't a string
+ */
-/*
- Camera ipo name to channel
-*/
+ if ( !strname )
+ return -1;
-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.
+ /*
+ * currently only deletion is supported, so if we get an
+ * object it's an error
*/
- extern int cam_ar[];
- extern char *cam_ic_names[];
- int not_ok = 0;
- int i;
+ if ( value )
+ return EXPP_ReturnIntError ( PyExc_NotImplementedError,
+ "cannot set IPO curves" );
- for( i = 0; i < CAM_TOTIPO; i++ ) {
- if( !strcmp( s, cam_ic_names[i] ) ) { /* found it! */
- *param = cam_ar[i];
- return 1;
+ /*
+ * search curve list for a match, delete if found
+ */
+
+ 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 );
+ return 0;
}
}
- return not_ok;
-}
+ /*
+ * no match; error
+ */
+ return EXPP_ReturnIntError ( PyExc_RuntimeError,
+ "IPO curve not found" );
+}
-/*
- texture ipo name to channel
-*/
+/*****************************************************************************/
+/* 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 );
+}
-static int Ipo_texIcuName( char *s, int *param )
+/*****************************************************************************/
+/* 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 )
{
- /* 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;
+ char *name;
- for( i = 0; i < TE_TOTIPO; i++){
- if( !strcmp( s, tex_ic_names[i] ) ){
- *param = te_ar[i];
- return 1;
- }
+ switch ( self->ipo->blocktype ) {
+ case ID_OB:
+ name= "Object";
+ break;
+ case ID_CA:
+ name = "Camera";
+ break;
+ case ID_LA:
+ name = "Lamp";
+ break;
+ case ID_TE:
+ name = "Texture";
+ break;
+ case ID_WO:
+ name = "World";
+ break;
+ case ID_MA:
+ name = "Material";
+ break;
+ case ID_AC:
+ name = "Action";
+ break;
+ case IPO_CO:
+ name = "Constraint";
+ break;
+ case ID_CU:
+ name = "Curve";
+ break;
+ case ID_KE:
+ name = "Key";
+ break;
+ case ID_SEQ:
+ name = "Sequence";
+ break;
+ default:
+ name = "Unknown type";
+ break;
}
+ return PyString_FromFormat( "[Ipo \"%s\" (%s)]", self->ipo->id.name + 2,
+ name );
+}
- return not_ok;
+/* Four 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, with optional tex channel info. */
+/*****************************************************************************/
+
+PyObject *Ipo_CreatePyObjectChannel ( Ipo * ipo, int channel )
+{
+ 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;
+#ifdef TEXCHANNELS
+ pyipo->channel = channel;
+#endif
+ return ( PyObject * ) pyipo;
}
-static int Ipo_obIcuName( char *s, int *param )
+/*****************************************************************************/
+/* Function: Ipo_CreatePyObject */
+/* Description: This function will create a new BPy_Ipo from an existing */
+/* Blender ipo structure. */
+/*****************************************************************************/
+
+PyObject *Ipo_CreatePyObject( Ipo * ipo )
{
- 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;
- }
+ return Ipo_CreatePyObjectChannel ( ipo, 0 );
+}
- if( !strcmp( s, "ColR" ) ) {
- *param = OB_COL_R;
- return 1;
- }
- if( !strcmp( s, "ColG" ) ) {
- *param = OB_COL_G;
- return 1;
- }
- if( !strcmp( s, "ColB" ) ) {
- *param = OB_COL_B;
- return 1;
- }
- if( !strcmp( s, "ColA" ) ) {
- *param = OB_COL_A;
- return 1;
- }
- if( !strcmp( s, "FStreng" ) ) {
- *param = OB_PD_FSTR;
- return 1;
- }
- if( !strcmp( s, "FFall" ) ) {
- *param = OB_PD_FFALL;
- return 1;
- }
- if( !strcmp( s, "Damping" ) ) {
- *param = OB_PD_SDAMP;
- return 1;
- }
- if( !strcmp( s, "RDamp" ) ) {
- *param = OB_PD_RDAMP;
- return 1;
- }
- if( !strcmp( s, "Perm" ) ) {
- *param = OB_PD_PERM;
- return 1;
- }
+/*****************************************************************************/
+/* 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 );
+}
- return ok;
+/*****************************************************************************/
+/* Function: Ipo_FromPyObject */
+/* Description: This function returns the Blender ipo from the given */
+/* PyObject. */
+/*****************************************************************************/
+Ipo *Ipo_FromPyObject( PyObject * pyobj )
+{
+ return ( ( BPy_Ipo * ) pyobj )->ipo;
}
+/*
+ * Initialize the interator (set pointer to first curve)
+ */
-/*
- Function: Ipo_append
- Bpy: Blender.Ipo.append( 'curname')
+static
+PyObject *Ipo_getIter( BPy_Ipo * self )
+{
+#if 1
+ self->iter = 0;
+#else
+ self->iter = self->ipo->curve.first;
+#endif
+ return EXPP_incr_ret ( (PyObject *) self );
+}
- add a new curve to an existing IPO.
- example:
- ipo = Blender.Ipo.New('Object','ObIpo')
- cu = ipo.append('LocX')
-*/
+/*
+ * Return next IPO curve. When the end of the list is reached,
+ * throw an exception.
+ */
-static PyObject *Ipo_append( BPy_Ipo * self, PyObject * args )
+static
+PyObject *Ipo_nextIter( BPy_Ipo * self )
{
- int param = 0; /* numeric curve name constant */
- int ok = 0;
- char *cur_name = 0; /* input arg: curve name */
- Ipo *ipo = 0;
- IpoCurve *icu = 0;
- Link *link;
- static int depcount=2;
+ PyObject *obj;
+#if 1
+ /*
+ * since IPO curves are stored in a queue (unsorted), this
+ * code lets the iterator return them in sorted order (i.e.,
+ * the order they appear in the IPO Editor window.
+ */
- if( !PyArg_ParseTuple( args, "s", &cur_name ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected string argument" ) );
+ IpoCurve *ptr = NULL;
+ IpoCurve *icu = NULL;
+ int minadr = 0x7fffffff;
- /* chase down the ipo list looking for ours */
- link = G.main->ipo.first;
+ /*
+ * search for the next largest (relative to current iterator) adrcode
+ */
- while( link ) {
- ipo = ( Ipo * ) link;
- if( ipo == self->ipo ) {
- break;
+ for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
+ if ( icu->adrcode < minadr && icu->adrcode > self->iter ) {
+ minadr = icu->adrcode;
+ ptr = icu;
}
- link = link->next;
}
/*
- * if link is NULL, the IPO was deleted
+ * if nothing is larger than current, we're done
*/
- if ( !link )
- return EXPP_ReturnPyObjError ( PyExc_RuntimeError,
- "Ipo not found" );
-
+ if ( !ptr )
+ return EXPP_ReturnPyObjError( PyExc_StopIteration,
+ "iterator at end" );
+ else {
+ obj = IpoCurve_CreatePyObject( ptr );
+ self->iter = minadr;
+ }
+#else
/*
- depending on the block type,
- check if the input arg curve name is valid
- and set param to numeric value.
+ *
+ * this simpler iterator code moves through the linked list in order
*/
- 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_AC:
- ok = Ipo_acIcuName( cur_name, &param );
- break;
- case IPO_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 ( !self->iter )
+ return EXPP_ReturnPyObjError( PyExc_StopIteration,
+ "iterator at end" );
- if( !ok ) /* curve type was invalid */
- return EXPP_ReturnPyObjError
- ( PyExc_NameError, "curve name was invalid" );
+ obj = IpoCurve_CreatePyObject( self->iter );
+ self->iter = self->iter->next;
+#endif
+ return obj;
+}
+
+/*
+ * helper to create module constant; this could be put into gen_utils.c
+ * or constant.c
+ */
+
+static PyObject *generate_ModuleIntConstant(char *name, int value, char *doc)
+{
+ PyObject *constant = M_constant_New();
+
+ constant_insert((BPy_constant*)constant, "value", PyInt_FromLong(value));
+ constant_insert((BPy_constant*)constant, "name", PyString_FromString(name));
+#if 0
+ constant_insert((BPy_constant*)constant, "__doc__", PyString_FromString(doc));
+#endif
+
+ Py_INCREF(constant);
+ return constant;
+}
+
+/*
+ * define curve info for all curves
+ */
+
+static ipocurve_dictInfo ipocurve_list[] =
+{
+ {ID_AC, "ActionIpo_", ac_ic_names, ac_ar, AC_TOTNAM },
+ {ID_CA, "CameraIpo_", cam_ic_names, cam_ar, CAM_TOTNAM },
+ {IPO_CO, "ConstraintIpo_",co_ic_names, co_ar, CO_TOTNAM },
+ {ID_CU, "CurveIpo_", cu_ic_names, cu_ar, CU_TOTNAM },
+ {ID_KE, "KeyIpo_", key_ic_names, key_ar, KEY_TOTNAM },
+ {ID_LA, "LampIpo_", la_ic_names, la_ar, LA_TOTNAM },
+ {ID_MA, "MaterialIpo_", ma_ic_names, ma_ar, MA_TOTNAM },
+ {ID_OB, "ObjectIpo_", ob_ic_names, ob_ar, OB_TOTNAM },
+ {ID_SEQ, "SequenceIpo_", seq_ic_names, seq_ar, SEQ_TOTNAM },
+ {ID_SO, "SoundIpo_", snd_ic_names, snd_ar, SND_TOTNAM },
+ {ID_TE, "TextureIpo_", tex_ic_names, te_ar, TE_TOTNAM },
+ {ID_WO, "WorldIpo_", wo_ic_names, wo_ar, WO_TOTNAM },
+};
+
+#ifdef TEXCHANNELS
+
+/*
+ * for future use: define curve info for texture channels
+ */
+
+static ipocurve_dictInfo mtex_list[] =
+{
+ {ID_LA, "LTexIpo_", mtex_ic_names, la_ar+LA_TOTNAM, (LA_TOTIPO-LA_TOTNAM) },
+ {ID_MA, "MTexIpo_", mtex_ic_names, ma_ar+MA_TOTNAM, (MA_TOTIPO-MA_TOTNAM) },
+ {ID_WO, "WTexIpo_", mtex_ic_names, wo_ar+WO_TOTNAM, (WO_TOTIPO-WO_TOTNAM) },
+};
+
+#endif
+
+/*
+ * Build a curve dictionary based on the names and constants provided in
+ * other modules
+ */
+
+static PyObject *Ipo_buildCurveDict ( ipocurve_dictInfo *ptr )
+{
+ int i, j, k, len;
+ char tmpname[64];
+ PyObject *obj;
+
+ obj = PyDict_New();
+
+ /* start each constant name with a prefix string identifying IPO type */
+
+ BLI_strncpy ( tmpname, ptr->prefix , sizeof(tmpname) );
+ len = strlen (tmpname);
/*
- * see if the curve already exists
+ * create a module constant for each string (convert to uppercase), and
+ * insert in the dictionary.
*/
- icu= ipo->curve.first;
- while (icu) {
- if( icu->adrcode == param ) {
-#if BLENDER_VERSION < 241
- if ( depcount ) {
- printf ( "Calling Ipo.append() with an existing curve is deprecated;\n");
- printf ( " this will throw a ValueError exception after V2.40.\n" );
- --depcount;
+ for ( i = 0 ; i < ptr->num_adr_codes; ++i ) {
+ BLI_strncpy ( tmpname+len, ptr->curve_names[i], sizeof(tmpname)-len);
+ for ( j = k = len; tmpname[k]; ++k ) {
+ if ( tmpname[k] != ' ' ) {
+ tmpname[j] = tmpname[k];
+ ++j;
}
-#else
- return EXPP_ReturnPyObjError ( PyExc_ValueError,
- "curve already exists" );
+ }
+ tmpname[j]=0;
+ PyDict_SetItemString( obj, tmpname+len,
+ generate_ModuleIntConstant ( tmpname, ptr->adr_codes[i], "no doc" ) );
+ }
+ return obj;
+}
+
+/*
+ * Construct a list of curve types for a particular IPO. This is similar to
+ * the code in Ipo_buildCurveDict() except it puts things in a list. It
+ * might be more efficient to pull things of out the dictionary, but the
+ * items there are no longer in order ( :-( ). Depends if anyone cares.
+ */
+
+static PyObject * Ipo_listCurveTypes ( BPy_Ipo * self )
+{
+ int i, size;
+ ipocurve_dictInfo *ptr;
+
+#ifdef TEXCHANNELS
+
+ /* determine whether IPO is texture channel list or regular */
+
+ if (self->channel) {
+ ptr = mtex_list;
+ size = sizeof(mtex_list)/sizeof(ipocurve_dictInfo);
+ } else
#endif
+ {
+ ptr = ipocurve_list;
+ size = sizeof(ipocurve_list)/sizeof(ipocurve_dictInfo);
+ }
+
+ /* search list for matching block type, then build a dict */
+
+ for ( i = 0; i < size; ++i, ++ptr ) {
+ if ( ptr->blocktype == self->ipo->blocktype )
+ return EXPP_incr_ret ( Ipo_buildCurveDict ( ptr ) );
+ }
+ return EXPP_incr_ret ( Py_None );
+}
+
+/*
+ * function to compare two string, which may have embedded spaces
+ */
+
+static int strcmp_ns ( char* ptr1, char *ptr2 )
+{
+ while (*ptr1 && *ptr2) {
+ if ( *ptr1 != *ptr2 ) /* compare uppercase */
+ return 1;
+ ++ptr1; /* move to next character */
+ ++ptr2;
+ while (*ptr1 == ' ') ++ptr1; /* skip spaces */
+ while (*ptr2 == ' ') ++ptr2;
+ }
+ if ( *ptr1 || *ptr2 ) /* one string isn't terminated, not equal */
+ return 1;
+ else
+ return 0;
+}
+
+/*
+ * search specific IPO list for curve name. Return new reference to
+ * PyObject method constant if successful, NULL otherwise.
+ */
+
+static PyObject * Ipo_checkCurveTypes ( BPy_Ipo *self, char * name )
+{
+ int count, i, j, k, size;
+ ipocurve_dictInfo *ptr;
+
+#ifdef TEXCHANNELS
+
+ /* determine whether IPO is texture channel list or regular */
+
+ if (self->channel) {
+ ptr = mtex_list;
+ size = sizeof(mtex_list)/sizeof(ipocurve_dictInfo);
+ } else
+#endif
+ {
+ ptr = ipocurve_list;
+ size = sizeof(ipocurve_list)/sizeof(ipocurve_dictInfo);
+ }
+
+ /* search through list of IPOs for a match */
+
+ for ( count = 0; count < size; ++count, ++ptr ) {
+ if ( ptr->blocktype == self->ipo->blocktype ) {
+
+ /* search through curves for a match */
+
+ for ( i = 0; i < ptr->num_adr_codes; ++i ) {
+ if ( !strcmp_ns( name, ptr->curve_names[i] ) ) {
+ char tmpname[64];
+ int len = strlen (ptr->prefix);
+
+ /* match: construct a constant to return */
+
+ BLI_strncpy ( tmpname, ptr->prefix , sizeof(tmpname) );
+ BLI_strncpy ( tmpname+len, ptr->curve_names[i],
+ sizeof(tmpname)-len);
+
+ /* strip spaces, convert to uppercase */
+
+ for ( j = k = len; tmpname[k]; ++k ) {
+ if ( tmpname[k] != ' ' ) {
+ tmpname[j] = tmpname[k];
+ ++j;
+ }
+ }
+ tmpname[j]=0;
+
+ return generate_ModuleIntConstant ( tmpname,
+ ptr->adr_codes[i], "no doc" );
+ }
+ }
}
- icu= icu->next;
}
+ return NULL;
+}
-
- /* ask blender to create the new ipo curve */
- icu = get_ipocurve( NULL, ipo->blocktype, param, self->ipo );
+/* #####DEPRECATED###### */
- if( !icu ) /* could not create curve */
- return EXPP_ReturnPyObjError ( PyExc_RuntimeError,
- "blender could not create ipo curve" );
+#if BLENDER_VERSION < 243
- allspace( REMAKEIPO, 0 );
- EXPP_allqueue( REDRAWIPO, 0 );
+/*
+ * Ipo_getCurveBP()
+ * this method is UNSUPPORTED.
+ * Calling this method throws a NotImplemented Exception.
+ *
+ * it looks like the original intent was to return the first point
+ * of a BPoint Ipo curve. However, BPoint ipos are not currently
+ * implemented.
+ */
- /* create a bpy wrapper for the new ipo curve */
- return IpoCurve_CreatePyObject( icu );
+static PyObject *Ipo_getCurveBP( BPy_Ipo * self, PyObject * args )
+{
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "bpoint ipos are not supported" );
}
-static PyObject *Ipo_getCurves( BPy_Ipo * self )
+/*
+ * Ipo_DeleteBezPoints
+ * this method is UNSUPPORTED.
+ * Calling this method throws a NotImplemented Exception.
+ *
+ * this code was apparently to delete the last point from an Ipo curve,
+ * but didn't do any list management and isn't documented in the API.
+ */
+
+static PyObject *Ipo_DeleteBezPoints( BPy_Ipo * self, PyObject * args )
{
- PyObject *list;
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "replaced by \"del ipo[][]\"" );
+#if 0
+ int num = 0, i = 0;
+ IpoCurve *icu = 0;
+ 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;
+
+ }
+ icu->totvert--;
+ return ( PyInt_FromLong( icu->totvert ) );
+#endif
+}
+
+static PyObject *Ipo_getNcurves( BPy_Ipo * self )
+{
+#if BLENDER_VERSION < 241
IpoCurve *icu;
int i = 0;
+ static int depcount = 2;
- list = PyList_New( Ipo_length( self ) );
- if (!list)
- return EXPP_ReturnPyObjError( PyExc_MemoryError,
- "couldn't create PyList object" );
- /*
- * if IpoCurve_CreatePyObject returns NULL, it already threw an
- * exception and things are messed up, so just give up
- */
+ if ( depcount ) {
+ printf ("Ipo.getNcurves() is deprecated by the len() operator.\n");
+ printf (" This method will be removed after version 2.40.\n");
+ depcount--;
+ }
for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
- PyObject *obj = IpoCurve_CreatePyObject( icu );
- if (!obj) {
- Py_DECREF ( list );
- return NULL;
- }
- PyList_SET_ITEM( list, i, obj );
i++;
}
- return list;
+
+ return ( PyInt_FromLong( i ) );
+#else
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "replaced by \"len(ipo)\"" );
+#endif
+}
+
+static PyObject *Ipo_addCurve( BPy_Ipo * self, PyObject * args )
+{
+#if BLENDER_VERSION < 241
+ static char depcount=2;
+
+ if ( depcount ) {
+ printf ("Ipo.addCurve() is deprecated by the append() method.\n");
+ printf (" This method will be removed after version 2.40.\n");
+ depcount--;
+ }
+
+ return Ipo_append( self, args );
+#else
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "replaced by \"ipo.append()\"" );
+#endif
}
-/*****************************************************************************/
-/* Function: Ipo_length */
-/* Description: this function returns the number of curves contained in the */
-/* IPO. */
-/*****************************************************************************/
-static
-int Ipo_length( BPy_Ipo * self )
+static PyObject *Ipo_delCurve( BPy_Ipo * self, PyObject * args )
{
- int length = 0;
- IpoCurve *icu;
+#if BLENDER_VERSION < 241
+ static char depcount=2;
+ char *str;
+ int ok;
- for ( icu = self->ipo->curve.first; icu; icu = icu->next ) {
- ++length;
+ if ( depcount ) {
+ printf ("Ipo.delCurve() is deprecated by the del operator.\n");
+ printf (" This method will be removed after version 2.40.\n");
+ depcount--;
}
- return length;
+
+ if( !PyArg_ParseTuple( args, "s", &str ) )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_TypeError, "expected string argument" ) );
+
+ args= Py_BuildValue ("s",str);
+ ok = Ipo_setItem( self, args, NULL );
+ Py_DECREF ( args );
+ if (!ok)
+ return EXPP_incr_ret ( Py_None );
+ else
+ return NULL;
+#else
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "replaced by \"del ipo[]\"" );
+#endif
}
-/*****************************************************************************/
-/* Function: Ipo_getItem */
-/* Description: this is the get operator[] for mappings. Look up a curve */
-/* by name and return IpoCurve object or Py_None. */
-/*****************************************************************************/
-static
-PyObject * Ipo_getItem( BPy_Ipo * self, PyObject * key )
+static PyObject *Ipo_getCurve( BPy_Ipo * self, PyObject * args )
{
+#if BLENDER_VERSION < 241
+ static char depcount=2;
IpoCurve *icu = 0;
- char *str, *str1;
-
- /* check for string argument */
+ char *str = NULL; /* input arg: curve name */
+ int param = 0; /* numeric curve name constant */
+ BPy_constant *constant = NULL;
- if ( !PyString_Check ( key ) )
- return ( EXPP_ReturnPyObjError ( PyExc_TypeError,
- "expected string argument" ) );
+ if ( depcount ) {
+ printf ("Ipo.getCurve() is deprecated by the index operator[].\n");
+ printf (" This method will be removed after version 2.40.\n");
+ depcount--;
+ }
+ if ( PySequence_Size( args ) > 0
+ && PyString_Check ( PySequence_Fast_GET_ITEM ( args , 0 ) ) ) {
+ if( !PyArg_ParseTuple( args, "s", &str ) )
+ return EXPP_ReturnPyObjError
+ ( PyExc_TypeError, "expected string or module constant" );
+ } else if( PyArg_ParseTuple( args, "O!", &constant_Type, &constant ) )
+ param = PyInt_AS_LONG(PyDict_GetItemString(constant->dict, "value"));
+ else
+ return EXPP_ReturnPyObjError
+ ( PyExc_TypeError, "expected string or module constant" );
- /* if we find a matching string name, return an object */
+ if ( str ) {
+ for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
+ if ( !strcmp( str, getIpoCurveName( icu ) ) )
+ return IpoCurve_CreatePyObject( icu );
+ }
+ return EXPP_incr_ret ( Py_None );
+ }
- str = PyString_AS_STRING ( key );
-#if 1
for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
- str1 = getIpoCurveName( icu );
- if( !strcmp( str1, str ) )
+ if ( icu->adrcode == param )
return IpoCurve_CreatePyObject( icu );
}
+
+ return EXPP_incr_ret ( Py_None );
#else
- for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
- str1 = getIpoCurveName( icu );
- if ( !strcmp( str1, str ) ) { /* found curve */
- if ( icu->adrcode < MA_MAP1 ) { /* not texture channel */
- if ( self->channel == 0 ) /* no channel specified */
- return IpoCurve_CreatePyObject( icu );
- else
- return ( EXPP_ReturnPyObjError
- ( PyExc_ValueError, "texture channel value specified for non-texchannel curve" ) );
- } else if ( self->channel & icu->adrcode ) /* texture channel matches */
- return IpoCurve_CreatePyObject( icu );
- }
- }
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "replaced by \"ipo[]\"" );
#endif
- return EXPP_incr_ret ( Py_None );
}
-/*****************************************************************************/
-/* Function: Ipo_setItem */
-/* Description: this is the get operator[] for mappings. Look up a curve */
-/* by name and return IpoCurve object or Py_None. */
-/*****************************************************************************/
-static
-int Ipo_setItem( BPy_Ipo *self, PyObject *key, PyObject *value )
+static PyObject *Ipo_getCurveBeztriple( BPy_Ipo * self, PyObject * args )
{
- char * strname = PyString_AsString ( key );
+#if BLENDER_VERSION < 241
+ static char depcount=2;
+ struct BezTriple *ptrbt;
+ int num = 0, pos, i, j;
IpoCurve *icu;
+ PyObject *l = PyList_New( 0 );
- /*
- * if PyString_AsString returns NULL. key wasn't a string
- */
-
- if ( !strname )
- return -1;
-
- /*
- * currently only deletion is supported, so if we get an
- * object it's an error
- */
-
- if ( value )
- return EXPP_ReturnIntError ( PyExc_NotImplementedError,
- "cannot set IPO curves" );
-
- /*
- * search curve list for a match, delete if found
- */
+ if ( depcount ) {
+ printf ("Ipo.getCurveBeztriple() is deprecated by the index operators[] of\n");
+ printf (" Ipo and Ipocurve types. Use \"ipo[][]\" instead.\n");
+ printf (" This method will be removed after version 2.40.\n");
+ depcount--;
+ }
- 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 );
- return 0;
- }
+ if( !PyArg_ParseTuple( args, "ii", &num, &pos ) )
+ 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 ipo number" ) );
+ icu = icu->next;
}
+ if( pos >= icu->totvert )
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "Bad bezt number" );
- /*
- * no match; error
- */
+ ptrbt = icu->bezt + pos;
+ if( !ptrbt )
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "No bez triple" );
- return EXPP_ReturnIntError ( PyExc_RuntimeError,
- "IPO curve not found" );
+ for( i = 0; i < 3; i++ )
+ for( j = 0; j < 3; j++ )
+ PyList_Append( l,
+ PyFloat_FromDouble( ptrbt->
+ vec[i][j] ) );
+ return l;
+#else
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "replaced by \"ipo[][]\"" );
+#endif
}
-/*****************************************************************************/
-/* Function: IpoDeAlloc */
-/* Description: This is a callback function for the BPy_Ipo type. It is */
-/* the destructor function. */
-/*****************************************************************************/
-static void IpoDeAlloc( BPy_Ipo * self )
+static PyObject *Ipo_setCurveBeztriple( BPy_Ipo * self, PyObject * args )
{
- PyObject_DEL( self );
-}
+#if BLENDER_VERSION < 241
+ static int depcount=2;
+ struct BezTriple *ptrbt;
+ int num = 0, pos, i;
+ IpoCurve *icu;
+ PyObject *listargs = 0;
-/*****************************************************************************/
-/* 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 )
-{
- char *name;
+ if ( depcount ) {
+ printf ("Ipo.setCurveBeztriple() is deprecated by the index operators[] of\n");
+ printf (" Ipo and Ipocurve types. Use \"ipo[][]\" instead.\n");
+ printf (" This method will be removed after version 2.40.\n");
+ depcount--;
+ }
- switch ( self->ipo->blocktype ) {
- case ID_OB:
- name= "Object";
- break;
- case ID_CA:
- name = "Camera";
- break;
- case ID_LA:
- name = "Lamp";
- break;
- case ID_TE:
- name = "Texture";
- break;
- case ID_WO:
- name = "World";
- break;
- case ID_MA:
- name = "Material";
- break;
- case ID_AC:
- name = "Action";
- break;
- case IPO_CO:
- name = "Constraint";
- break;
- case ID_CU:
- name = "Curve";
- break;
- case ID_KE:
- name = "Key";
- break;
- case ID_SEQ:
- name = "Sequence";
- break;
- default:
- name = "Unknown type";
- break;
+ if( !PyArg_ParseTuple( args, "iiO", &num, &pos, &listargs ) )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_TypeError,
+ "expected int int object argument" ) );
+ if( !PyTuple_Check( listargs ) )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_TypeError, "3rd arg should be a tuple" ) );
+ 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 ipo number" ) );
+ icu = icu->next;
+ }
+ if( pos >= icu->totvert )
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "Bad bezt number" );
+
+ ptrbt = icu->bezt + pos;
+ if( !ptrbt )
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "No bez triple" );
+
+ for( i = 0; i < 9; i++ ) {
+ PyObject *xx = PyTuple_GetItem( listargs, i );
+ ptrbt->vec[i / 3][i % 3] = PyFloat_AsDouble( xx );
}
- return PyString_FromFormat( "[Ipo \"%s\" (%s)]", self->ipo->id.name + 2,
- name );
+
+ Py_INCREF( Py_None );
+ return Py_None;
+#else
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "replaced by \"ipo[][]\"" );
+#endif
}
-/* Four Python Ipo_Type helper functions needed by the Object module: */
+static PyObject *Ipo_getNBezPoints( BPy_Ipo * self, PyObject * args )
+{
+#if BLENDER_VERSION < 241
+ static int depcount=2;
+ int num = 0, i = 0;
+ IpoCurve *icu = 0;
-/*****************************************************************************/
-/* Function: Ipo_CreatePyObject */
-/* Description: This function will create a new BPy_Ipo from an existing */
-/* Blender ipo structure, with optional tex channel info. */
-/*****************************************************************************/
+ if ( depcount ) {
+ printf ("Ipo.getNBezPoints() is deprecated by the IpoCurve's len operator.\n");
+ printf (" This method will be removed after version 2.40.\n");
+ depcount--;
+ }
-PyObject *Ipo_CreatePyObjectChannel ( Ipo * ipo, int channel )
-{
- 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;
-#if 0
- pyipo->channel = channel;
+ 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;
+
+ }
+ return ( PyInt_FromLong( icu->totvert ) );
+#else
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "replaced by \"len(ipo[])\"" );
#endif
- return ( PyObject * ) pyipo;
}
-/*****************************************************************************/
-/* Function: Ipo_CreatePyObject */
-/* Description: This function will create a new BPy_Ipo from an existing */
-/* Blender ipo structure. */
-/*****************************************************************************/
-
-PyObject *Ipo_CreatePyObject( Ipo * ipo )
+static PyObject *Ipo_setBlocktype( BPy_Ipo * self, PyObject * args )
{
- return Ipo_CreatePyObjectChannel ( ipo, 0 );
-}
+#if BLENDER_VERSION < 241
+ static int depcount=2;
+ int blocktype = 0;
-/*****************************************************************************/
-/* 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 );
-}
+ if ( depcount ) {
+ printf ("Ipo.setBlocktype() is deprecated.\n");
+ printf (" This method will be removed after version 2.40.\n");
+ depcount--;
+ }
-/*****************************************************************************/
-/* Function: Ipo_FromPyObject */
-/* Description: This function returns the Blender ipo from the given */
-/* PyObject. */
-/*****************************************************************************/
-Ipo *Ipo_FromPyObject( PyObject * pyobj )
-{
- return ( ( BPy_Ipo * ) pyobj )->ipo;
-}
+ if( !PyArg_ParseTuple( args, "i", &blocktype ) )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_TypeError, "expected string argument" ) );
-/*
- * Initialize the interator (set pointer to first curve)
- */
+ self->ipo->blocktype = ( short ) blocktype;
-static
-PyObject *Ipo_getIter( BPy_Ipo * self )
-{
-#if 1
- self->iter = 0;
+ Py_INCREF( Py_None );
+ return Py_None;
#else
- self->iter = self->ipo->curve.first;
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "no longer supported" );
#endif
- return EXPP_incr_ret ( (PyObject *) self );
}
-/*
- * Return next IPO curve. When the end of the list is reached,
- * throw an exception.
- */
-
-static
-PyObject *Ipo_nextIter( BPy_Ipo * self )
+static PyObject *Ipo_oldgetCurves( BPy_Ipo * self )
{
- PyObject *obj;
-#if 1
- /*
- * since IPO curves are stored in a queue (unsorted), this
- * code lets the iterator return them in sorted order (i.e.,
- * the order they appear in the IPO Editor window.
- */
-
- IpoCurve *ptr = NULL;
- IpoCurve *icu = NULL;
- int minadr = 0x7fffffff;
-
- /*
- * search for the next largest (relative to current iterator) adrcode
- */
+#if BLENDER_VERSION < 241
+ static int depcount=2;
+ PyObject *attr = PyList_New( 0 );
+ IpoCurve *icu;
- for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
- if ( icu->adrcode < minadr && icu->adrcode > self->iter ) {
- minadr = icu->adrcode;
- ptr = icu;
- }
+ if ( depcount ) {
+ printf ("Ipo.getCurves() is deprecated by the \"curves\" instance attribute.\n");
+ printf (" This method will be removed after version 2.40.\n");
+ depcount--;
}
- /*
- * if nothing is larger than current, we're done
- */
-
- if ( !ptr )
- return EXPP_ReturnPyObjError( PyExc_StopIteration,
- "iterator at end" );
- else {
- obj = IpoCurve_CreatePyObject( ptr );
- self->iter = minadr;
+ for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
+ PyList_Append( attr, IpoCurve_CreatePyObject( icu ) );
}
+ return attr;
#else
- /*
- *
- * this simpler iterator code moves through the linked list in order
- */
-
- if ( !self->iter )
- return EXPP_ReturnPyObjError( PyExc_StopIteration,
- "iterator at end" );
-
- obj = IpoCurve_CreatePyObject( self->iter );
- self->iter = self->iter->next;
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "replaced by \"ipo.curves\"" );
#endif
- return obj;
}
-/* #####DEPRECATED###### */
+static PyObject *Ipo_getCurvecurval( BPy_Ipo * self, PyObject * args )
+{
+#if BLENDER_VERSION < 241
+ static int depcount=2;
+ int numcurve = 0, i;
+ IpoCurve *icu;
+ char *stringname = 0, *str1 = 0;
-#if BLENDER_VERSION < 243
+ if ( depcount ) {
+ printf ("Ipo.getCurveCurval() is deprecated by ipo[].evaluate(curtime).\n");
+ printf (" This method will be removed after version 2.40.\n");
+ depcount--;
+ }
-/*
- * Ipo_getCurveBP()
- * this method is UNSUPPORTED.
- * Calling this method throws a NotImplemented Exception.
- *
- * it looks like the original intent was to return the first point
- * of a BPoint Ipo curve. However, BPoint ipos are not currently
- * implemented.
- */
+ icu = self->ipo->curve.first;
+ if( !icu )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_TypeError, "No IPO curve" ) );
-static PyObject *Ipo_getCurveBP( BPy_Ipo * self, PyObject * args )
-{
+ if( PyNumber_Check( PySequence_GetItem( args, 0 ) ) )
+ {
+ if( !PyArg_ParseTuple( args, "i", &numcurve ) )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_TypeError,
+ "expected int or string argument" ) );
+ for( i = 0; i < numcurve; i++ ) {
+ if( !icu )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_TypeError,
+ "Bad ipo number" ) );
+ icu = icu->next;
+ }
+ } else { // args is a string
+ if( !PyArg_ParseTuple( args, "s", &stringname ) )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_TypeError,
+ "expected int or string argument" ) );
+ while( icu ) {
+ str1 = getIpoCurveName( icu );
+ if( !strcmp( str1, stringname ) )
+ break;
+ icu = icu->next;
+ }
+ }
+
+ if( icu )
+ return PyFloat_FromDouble( icu->curval );
+ Py_INCREF( Py_None );
+ return Py_None;
+#else
return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
- "bpoint ipos are not supported" );
+ "replaced by \"ipo[].evaluate(curtime)\"" );
+#endif
}
-/*
- * Ipo_DeleteBezPoints
- * this method is UNSUPPORTED.
- * Calling this method throws a NotImplemented Exception.
- *
- * this code was apparently to delete the last point from an Ipo curve,
- * but didn't do any list management and isn't documented in the API.
- */
+static PyObject *Ipo_EvaluateCurveOn( BPy_Ipo * self, PyObject * args )
+{
+#if BLENDER_VERSION < 241
+ static int depcount=2;
+ float eval_icu( IpoCurve * icu, float ipotime );
+ int num = 0, i;
+ IpoCurve *icu;
+ float time = 0;
+
+ if ( depcount ) {
+ printf ("Ipo.EvaluateCurveOn() is deprecated by ipo[].evaluate().\n");
+ printf (" This method will be removed after version 2.40.\n");
+ depcount--;
+ }
-static PyObject *Ipo_DeleteBezPoints( BPy_Ipo * self, PyObject * args )
-{
- return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
- "replaced by \"del ipo[][]\"" );
-#if 0
- int num = 0, i = 0;
- IpoCurve *icu = 0;
- if( !PyArg_ParseTuple( args, "i", &num ) )
+ if( !PyArg_ParseTuple( args, "if", &num, &time ) )
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" ) );
+ ( PyExc_TypeError, "Bad ipo number" ) );
icu = icu->next;
}
- icu->totvert--;
- return ( PyInt_FromLong( icu->totvert ) );
+ return PyFloat_FromDouble( eval_icu( icu, time ) );
+#else
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "replaced by \"ipo[].evaluate()\"" );
#endif
}
-static PyObject *Ipo_getNcurves( BPy_Ipo * self )
+static PyObject *M_Ipo_Recalc( PyObject * self, PyObject * args )
{
#if BLENDER_VERSION < 241
+ static int depcount=2;
+ void testhandles_ipocurve( IpoCurve * icu );
+ PyObject *a;
IpoCurve *icu;
- int i = 0;
- static int depcount = 2;
if ( depcount ) {
- printf ("Ipo.getNcurves() is deprecated by the len() operator.\n");
+ printf ("Ipo.Recalc() is deprecated by the Ipocurve.recalc method.\n");
printf (" This method will be removed after version 2.40.\n");
depcount--;
}
- for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
- i++;
- }
+ if( !PyArg_ParseTuple( args, "O", &a ) )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_TypeError, "expected ipo curve argument)" ) );
+ if ( !IpoCurve_CheckPyObject(a) )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_TypeError, "expected ipo curve argument)" ) );
- return ( PyInt_FromLong( i ) );
+ icu = IpoCurve_FromPyObject( a );
+ testhandles_ipocurve( icu );
+
+ Py_INCREF( Py_None );
+ return Py_None;
#else
return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
- "replaced by \"len(ipo)\"" );
+ "replaced by \"ipo.curves\"" );
#endif
}
-static PyObject *Ipo_addCurve( BPy_Ipo * self, PyObject * args )
-{
#if BLENDER_VERSION < 241
- static char depcount=2;
- if ( depcount ) {
- printf ("Ipo.addCurve() is deprecated by the append() method.\n");
- printf (" This method will be removed after version 2.40.\n");
- depcount--;
+/*
+ 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 Ipo_append( self, args );
-#else
- return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
- "replaced by \"ipo.append()\"" );
-#endif
+ return not_ok;
}
-static PyObject *Ipo_delCurve( BPy_Ipo * self, PyObject * args )
+
+/*
+ World Ipo Name to Channel
+*/
+
+static int Ipo_woIcuName( char *s, int *param )
{
-#if BLENDER_VERSION < 241
- static char depcount=2;
- char *str;
- int ok;
+ 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",
+ };
- if ( depcount ) {
- printf ("Ipo.delCurve() is deprecated by the del operator.\n");
- printf (" This method will be removed after version 2.40.\n");
- depcount--;
+ for( i = 0; i < WO_TOTIPO; i++ ) {
+ if( !strcmp( s, world_names[i] ) ) { /* found it! */
+ *param = wo_ar[i];
+ return 1;
+ }
}
- if( !PyArg_ParseTuple( args, "s", &str ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected string argument" ) );
+ return not_ok;
+}
- args= Py_BuildValue ("s",str);
- ok = Ipo_setItem( self, args, NULL );
- Py_DECREF ( args );
- if (!ok)
- return EXPP_incr_ret ( Py_None );
- else
- return NULL;
-#else
- return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
- "replaced by \"del ipo[]\"" );
-#endif
+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;
}
-static PyObject *Ipo_getCurve( BPy_Ipo * self, PyObject * args )
+static int Ipo_keIcuName( char *s, int *param )
{
-#if BLENDER_VERSION < 241
- static char depcount=2;
- char *str, *str1;
- IpoCurve *icu = 0;
+ char key[10];
+ int ok = 0;
+ int nr = 0;
+ if( !strcmp( s, "Speed" ) ) {
+ *param = KEY_SPEED;
+ ok = 1;
+ }
+ for( nr = 1; nr < 64; nr++ ) {
+ sprintf( key, "Key %d", nr );
+ if( !strcmp( s, key ) ) {
+ *param = nr;
+ ok = 1;
+ break;
+ }
+ }
- if ( depcount ) {
- printf ("Ipo.getCurve() is deprecated by the index operator[].\n");
- printf (" This method will be removed after version 2.40.\n");
- depcount--;
+ return ok;
+}
+
+static int Ipo_seqIcuName( char *s, int *param )
+{
+ int ok = 0;
+ if( !strcmp( s, "Fac" ) ) {
+ *param = SEQ_FAC1;
+ ok = 1;
}
- if( !PyArg_ParseTuple( args, "s", &str ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected string argument" ) );
+ return ok;
+}
- for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
- str1 = getIpoCurveName( icu );
- if( !strcmp( str1, str ) )
- return IpoCurve_CreatePyObject( icu );
+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;
}
-
- Py_INCREF( Py_None );
- return Py_None;
-#else
- return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
- "replaced by \"ipo[]\"" );
-#endif
-}
-
-static PyObject *Ipo_getCurveBeztriple( BPy_Ipo * self, PyObject * args )
-{
-#if BLENDER_VERSION < 241
- static char depcount=2;
- struct BezTriple *ptrbt;
- int num = 0, pos, i, j;
- IpoCurve *icu;
- PyObject *l = PyList_New( 0 );
-
- if ( depcount ) {
- printf ("Ipo.getCurveBeztriple() is deprecated by the index operators[] of\n");
- printf (" Ipo and Ipocurve types. Use \"ipo[][]\" instead.\n");
- printf (" This method will be removed after version 2.40.\n");
- depcount--;
+ if( !strcmp( s, "QuatY" ) ) {
+ *param = AC_QUAT_Y;
+ return 1;
}
-
- if( !PyArg_ParseTuple( args, "ii", &num, &pos ) )
- 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 ipo number" ) );
- icu = icu->next;
+ if( !strcmp( s, "QuatZ" ) ) {
+ *param = AC_QUAT_Z;
+ return 1;
}
- if( pos >= icu->totvert )
- return EXPP_ReturnPyObjError( PyExc_TypeError,
- "Bad bezt number" );
+ if( !strcmp( s, "QuatW" ) ) {
+ *param = AC_QUAT_W;
+ return 1;
+ }
+ return ok;
+}
- ptrbt = icu->bezt + pos;
- if( !ptrbt )
- return EXPP_ReturnPyObjError( PyExc_TypeError,
- "No bez triple" );
- for( i = 0; i < 3; i++ )
- for( j = 0; j < 3; j++ )
- PyList_Append( l,
- PyFloat_FromDouble( ptrbt->
- vec[i][j] ) );
- return l;
-#else
- return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
- "replaced by \"ipo[][]\"" );
-#endif
-}
+/*
+ Camera ipo name to channel
+*/
-static PyObject *Ipo_setCurveBeztriple( BPy_Ipo * self, PyObject * args )
+static int Ipo_caIcuName( char *s, int *param )
{
-#if BLENDER_VERSION < 241
- static int depcount=2;
- struct BezTriple *ptrbt;
- int num = 0, pos, i;
- IpoCurve *icu;
- PyObject *listargs = 0;
+ /* 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[];
- if ( depcount ) {
- printf ("Ipo.setCurveBeztriple() is deprecated by the index operators[] of\n");
- printf (" Ipo and Ipocurve types. Use \"ipo[][]\" instead.\n");
- printf (" This method will be removed after version 2.40.\n");
- depcount--;
- }
+ int not_ok = 0;
+ int i;
- if( !PyArg_ParseTuple( args, "iiO", &num, &pos, &listargs ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError,
- "expected int int object argument" ) );
- if( !PyTuple_Check( listargs ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "3rd arg should be a tuple" ) );
- 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 ipo number" ) );
- icu = icu->next;
+ for( i = 0; i < CAM_TOTIPO; i++ ) {
+ if( !strcmp( s, cam_ic_names[i] ) ) { /* found it! */
+ *param = cam_ar[i];
+ return 1;
+ }
}
- if( pos >= icu->totvert )
- return EXPP_ReturnPyObjError( PyExc_TypeError,
- "Bad bezt number" );
- ptrbt = icu->bezt + pos;
- if( !ptrbt )
- return EXPP_ReturnPyObjError( PyExc_TypeError,
- "No bez triple" );
+ return not_ok;
+}
- for( i = 0; i < 9; i++ ) {
- PyObject *xx = PyTuple_GetItem( listargs, i );
- ptrbt->vec[i / 3][i % 3] = PyFloat_AsDouble( xx );
- }
- Py_INCREF( Py_None );
- return Py_None;
-#else
- return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
- "replaced by \"ipo[][]\"" );
-#endif
-}
+/*
+ texture ipo name to channel
+*/
-static PyObject *Ipo_getNBezPoints( BPy_Ipo * self, PyObject * args )
+static int Ipo_texIcuName( char *s, int *param )
{
-#if BLENDER_VERSION < 241
- static int depcount=2;
- int num = 0, i = 0;
- IpoCurve *icu = 0;
+ /* 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;
- if ( depcount ) {
- printf ("Ipo.getNBezPoints() is deprecated by the IpoCurve's len operator.\n");
- printf (" This method will be removed after version 2.40.\n");
- depcount--;
+ for( i = 0; i < TE_TOTIPO; i++){
+ if( !strcmp( s, tex_ic_names[i] ) ){
+ *param = te_ar[i];
+ return 1;
+ }
}
- 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;
-
- }
- return ( PyInt_FromLong( icu->totvert ) );
-#else
- return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
- "replaced by \"len(ipo[])\"" );
-#endif
+ return not_ok;
}
-static PyObject *Ipo_setBlocktype( BPy_Ipo * self, PyObject * args )
+static int Ipo_obIcuName( char *s, int *param )
{
-#if BLENDER_VERSION < 241
- static int depcount=2;
- int blocktype = 0;
+ 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 ( depcount ) {
- printf ("Ipo.setBlocktype() is deprecated.\n");
- printf (" This method will be removed after version 2.40.\n");
- depcount--;
+ 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( !PyArg_ParseTuple( args, "i", &blocktype ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected string argument" ) );
-
- self->ipo->blocktype = ( short ) blocktype;
-
- Py_INCREF( Py_None );
- return Py_None;
-#else
- return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
- "no longer supported" );
-#endif
-}
-
-static PyObject *Ipo_oldgetCurves( BPy_Ipo * self )
-{
-#if BLENDER_VERSION < 241
- static int depcount=2;
- PyObject *attr = PyList_New( 0 );
- IpoCurve *icu;
-
- if ( depcount ) {
- printf ("Ipo.getCurves() is deprecated by the \"curves\" instance attribute.\n");
- printf (" This method will be removed after version 2.40.\n");
- depcount--;
+ if( !strcmp( s, "dSizeZ" ) ) {
+ *param = OB_DSIZE_Z;
+ return 1;
}
- for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
- PyList_Append( attr, IpoCurve_CreatePyObject( icu ) );
+ if( !strcmp( s, "Layer" ) ) {
+ *param = OB_LAY;
+ return 1;
}
- return attr;
-#else
- return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
- "replaced by \"ipo.curves\"" );
-#endif
-}
-
-static PyObject *Ipo_getCurvecurval( BPy_Ipo * self, PyObject * args )
-{
-#if BLENDER_VERSION < 241
- static int depcount=2;
- int numcurve = 0, i;
- IpoCurve *icu;
- char *stringname = 0, *str1 = 0;
-
- if ( depcount ) {
- printf ("Ipo.getCurveCurval() is deprecated by ipo[].evaluate(curtime).\n");
- printf (" This method will be removed after version 2.40.\n");
- depcount--;
+ if( !strcmp( s, "Time" ) ) {
+ *param = OB_TIME;
+ return 1;
}
- icu = self->ipo->curve.first;
- if( !icu )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "No IPO curve" ) );
-
- if( PyNumber_Check( PySequence_GetItem( args, 0 ) ) )
- {
- if( !PyArg_ParseTuple( args, "i", &numcurve ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError,
- "expected int or string argument" ) );
- for( i = 0; i < numcurve; i++ ) {
- if( !icu )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError,
- "Bad ipo number" ) );
- icu = icu->next;
- }
- } else { // args is a string
- if( !PyArg_ParseTuple( args, "s", &stringname ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError,
- "expected int or string argument" ) );
- while( icu ) {
- str1 = getIpoCurveName( icu );
- if( !strcmp( str1, stringname ) )
- break;
- icu = icu->next;
- }
+ 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;
}
- if( icu )
- return PyFloat_FromDouble( icu->curval );
- Py_INCREF( Py_None );
- return Py_None;
-#else
- return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
- "replaced by \"ipo[].evaluate(curtime)\"" );
-#endif
+ return ok;
}
-static PyObject *Ipo_EvaluateCurveOn( BPy_Ipo * self, PyObject * args )
+static PyObject *Ipo_oldAppend( Ipo * ipo, char *cur_name )
{
-#if BLENDER_VERSION < 241
- static int depcount=2;
- float eval_icu( IpoCurve * icu, float ipotime );
- int num = 0, i;
- IpoCurve *icu;
- float time = 0;
+ int param = 0; /* numeric curve name constant */
+ int ok = 0;
+ IpoCurve *icu = 0;
+ static int depcount=2;
+ static int depcount2=2;
- if ( depcount ) {
- printf ("Ipo.EvaluateCurveOn() is deprecated by ipo[].evaluate().\n");
- printf (" This method will be removed after version 2.40.\n");
- depcount--;
+ /*
+ depending on the block type,
+ check if the input arg curve name is valid
+ and set param to numeric value.
+ */
+ if ( depcount2 ) {
+ printf ("Calling Ipo.append() with a string argument is deprecated by module constants.\n");
+ printf (" This will throw an exception after version 2.40.\n");
+ --depcount2;
}
- if( !PyArg_ParseTuple( args, "if", &num, &time ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected int argument" ) );
+ 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_AC:
+ ok = Ipo_acIcuName( cur_name, &param );
+ break;
+ case IPO_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;
+ }
- icu = self->ipo->curve.first;
- if( !icu )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "No IPO curve" ) );
+ if( !ok ) /* curve type was invalid */
+ return EXPP_ReturnPyObjError
+ ( PyExc_NameError, "curve name was invalid" );
- for( i = 0; i < num; i++ ) {
- if( !icu )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "Bad ipo number" ) );
- icu = icu->next;
+ /*
+ * see if the curve already exists
+ */
+ icu= ipo->curve.first;
+ while (icu) {
+ if( icu->adrcode == param ) {
+ if ( depcount ) {
+ printf ( "Calling Ipo.append() with an existing curve is deprecated;\n");
+ printf ( " this will throw a ValueError exception after V2.40.\n" );
+ --depcount;
+ }
+ }
+ icu= icu->next;
}
- return PyFloat_FromDouble( eval_icu( icu, time ) );
-#else
- return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
- "replaced by \"ipo[].evaluate()\"" );
-#endif
-}
-
-static PyObject *M_Ipo_Recalc( PyObject * self, PyObject * args )
-{
-#if BLENDER_VERSION < 241
- static int depcount=2;
- void testhandles_ipocurve( IpoCurve * icu );
- PyObject *a;
- IpoCurve *icu;
- if ( depcount ) {
- printf ("Ipo.Recalc() is deprecated by the Ipocurve.recalc method.\n");
- printf (" This method will be removed after version 2.40.\n");
- depcount--;
- }
+ /* ask blender to create the new ipo curve */
+ icu = get_ipocurve( NULL, ipo->blocktype, param, ipo );
- if( !PyArg_ParseTuple( args, "O", &a ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected ipo curve argument)" ) );
- if ( !IpoCurve_CheckPyObject(a) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected ipo curve argument)" ) );
+ if( !icu ) /* could not create curve */
+ return EXPP_ReturnPyObjError ( PyExc_RuntimeError,
+ "blender could not create ipo curve" );
- icu = IpoCurve_FromPyObject( a );
- testhandles_ipocurve( icu );
+ allspace( REMAKEIPO, 0 );
+ EXPP_allqueue( REDRAWIPO, 0 );
- Py_INCREF( Py_None );
- return Py_None;
-#else
- return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
- "replaced by \"ipo.curves\"" );
-#endif
+ /* create a bpy wrapper for the new ipo curve */
+ return IpoCurve_CreatePyObject( icu );
}
+#endif
+
#endif

File Metadata

Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
61/66/16f274256dc02819200d5e6420d8

Event Timeline