Page Menu
Home
Search
Configure Global Search
Log In
Files
F2547
patch-Ipo.txt
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Authored By
Ken Hughes (khughes)
Nov 13 2013, 1:04 PM
Size
11 KB
Subscribers
None
patch-Ipo.txt
View Options
Index: source/blender/python/api2_2x/Ipo.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/Ipo.c,v
retrieving revision 1.40
diff -u -r1.40 Ipo.c
--- source/blender/python/api2_2x/Ipo.c 24 May 2005 15:14:32 -0000 1.40
+++ source/blender/python/api2_2x/Ipo.c 23 Jun 2005 20:13:25 -0000
@@ -92,6 +92,7 @@
static PyObject *Ipo_getCurve( BPy_Ipo * self, PyObject * args );
static PyObject *Ipo_getCurves( BPy_Ipo * self );
static PyObject *Ipo_addCurve( BPy_Ipo * self, PyObject * args );
+static PyObject *Ipo_append( BPy_Ipo * self, PyObject * args );
static PyObject *Ipo_delCurve( BPy_Ipo * self, PyObject * args );
static PyObject *Ipo_getNcurves( BPy_Ipo * self );
static PyObject *Ipo_getNBezPoints( BPy_Ipo * self, PyObject * args );
@@ -122,11 +123,11 @@
{"setRctf", ( PyCFunction ) Ipo_setRctf, METH_VARARGS,
"(str) - Change Ipo rctf"},
{"addCurve", ( PyCFunction ) Ipo_addCurve, METH_VARARGS,
- "() - Return Ipo ncurves"},
+ "() - use append() instead"},
{"delCurve", ( PyCFunction ) Ipo_delCurve, METH_VARARGS,
"() - Delete Ipo curves"},
{"getNcurves", ( PyCFunction ) Ipo_getNcurves, METH_NOARGS,
- "() - Return Ipo ncurves"},
+ "() - use len(ipo) instead"},
{"getNBezPoints", ( PyCFunction ) Ipo_getNBezPoints, METH_VARARGS,
"() - Return curve number of Bez points"},
{"delBezPoint", ( PyCFunction ) Ipo_DeleteBezPoints, METH_VARARGS,
@@ -146,7 +147,9 @@
{"getCurves", ( PyCFunction ) Ipo_getCurves, METH_NOARGS,
"() - Return curval"},
{"getCurve", ( PyCFunction ) Ipo_getCurve, METH_VARARGS,
- "() - Return curval"},
+ "() - use ipo[] instead"},
+ {"append", ( PyCFunction ) Ipo_append, METH_VARARGS,
+ "() - add IpoCurves to curve list"},
{NULL, NULL, 0, NULL}
};
@@ -159,6 +162,15 @@
static PyObject *IpoGetAttr( BPy_Ipo * self, char *name );
static PyObject *IpoRepr( BPy_Ipo * self );
+static int Ipo_length( BPy_Ipo * self );
+static PyObject * Ipo_getitem( BPy_Ipo * self, PyObject *key );
+
+static PyMappingMethods Ipo_mapping = {
+ (inquiry)Ipo_length, /* mp_length (__len__) */
+ (binaryfunc)Ipo_getitem, /* mp_subscript (__getitem__) */
+ 0 /* mp_ass_subscript (__setitem__) */
+};
+
/*****************************************************************************/
/* Python Ipo_Type structure definition: */
/*****************************************************************************/
@@ -176,7 +188,7 @@
( reprfunc ) IpoRepr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
+ &Ipo_mapping, /* tp_as_mapping */
0, /* tp_as_hash */
0, 0, 0, 0, 0, 0,
0, /* tp_doc */
@@ -441,8 +453,15 @@
static PyObject *Ipo_getNcurves( BPy_Ipo * self )
{
int i = 0;
-
IpoCurve *icu;
+ static char count=2;
+
+ if ( count ) { /* warning inserted in version 2.38 */
+ printf ( "%s() is deprecated; use len(ipo) instead\n",
+ __FUNCTION__ );
+ --count;
+ }
+
for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
i++;
}
@@ -825,9 +844,21 @@
}
+static PyObject *Ipo_addCurve( BPy_Ipo * self, PyObject * args )
+{
+ static char count=2;
+ if ( count ) { /* warning inserted in version 2.38 */
+ printf ( "%s() is deprecated; use Ipo.append() instead\n",
+ __FUNCTION__ );
+ --count;
+ }
+
+ return Ipo_append( self, args );
+}
+
/*
- Function: Ipo_addCurve
- Bpy: Blender.Ipo.addCurve( 'curname')
+ Function: Ipo_append
+ Bpy: Blender.Ipo.append( 'curname')
add a new curve to an existing IPO.
example:
@@ -835,7 +866,7 @@
cu = ipo.addCurve('LocX')
*/
-static PyObject *Ipo_addCurve( BPy_Ipo * self, PyObject * args )
+static PyObject *Ipo_append( BPy_Ipo * self, PyObject * args )
{
int param = 0; /* numeric curve name constant */
int ok = 0;
@@ -844,12 +875,12 @@
Ipo *ipo = 0;
IpoCurve *icu = 0;
Link *link;
+ static int count=2;
if( !PyArg_ParseTuple( args, "s", &cur_name ) )
return ( EXPP_ReturnPyObjError
( PyExc_TypeError, "expected string argument" ) );
-
/* chase down the ipo list looking for ours */
link = G.main->ipo.first;
@@ -862,7 +893,7 @@
link = link->next;
}
- if( ipo && ipofound ) {
+ if( ipo && ipofound ) { /* why not do "if ( !link)" ? */
/* ok. continue */
} else { /* runtime error here: our ipo not found */
return ( EXPP_ReturnPyObjError
@@ -917,6 +948,28 @@
return EXPP_ReturnPyObjError
( PyExc_NameError, "curve name was invalid" );
+ /*
+ * see if the curve already exists
+ */
+
+ icu= ipo->curve.first;
+ while (icu) {
+ if( icu->adrcode == param ) break;
+ icu= icu->next;
+ }
+
+ if ( icu && count )
+#if 0
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_ValueError, "curve already exists" ) );
+#else
+ if ( count ) { /* warning inserted in version 2.38 */
+ printf ( "calling Ipo.addCurve() with an existing curve is deprecated;\n");
+ printf ( " this will throw an exception in future releases.\n" );
+ --count;
+ }
+#endif
+
/* ask blender to create the new ipo curve */
icu = get_ipocurve( NULL, ipo->blocktype, param, self->ipo );
@@ -958,7 +1011,10 @@
if( icu->bezt )
MEM_freeN( icu->bezt );
MEM_freeN( icu );
- del_ipoCurve( icu );
+
+ allspace( REMAKEIPO, 0 );
+ EXPP_allqueue( REDRAWIPO, 0 );
+
Py_INCREF( Py_None );
return Py_None;
}
@@ -1249,10 +1305,56 @@
return Py_None;
}
+/*****************************************************************************/
+/* Function: Ipo_length */
+/* Description: this function returns the number of curves contained in the */
+/* IPO. */
+/*****************************************************************************/
+static
+int Ipo_length( BPy_Ipo * self )
+{
+ int length = 0;
+ IpoCurve *icu;
+
+ for ( icu = self->ipo->curve.first; icu; icu = icu->next ) {
+ ++length;
+ }
+ return length;
+}
+
+/*****************************************************************************/
+/* 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 )
+{
+ IpoCurve *icu = 0;
+ char *str, *str1;
+
+ /* check for string argument */
+
+ if ( !PyString_Check ( key ) )
+ return ( EXPP_ReturnPyObjError ( PyExc_TypeError,
+ "expected string argument" ) );
+
+
+ /* if we find a matching string name, return an object */
+
+ str = PyString_AS_STRING ( key );
+ for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
+ str1 = getIpoCurveName( icu );
+ if( !strcmp( str1, str ) )
+ return IpoCurve_CreatePyObject( icu );
+ }
+
+ return EXPP_incr_ret ( Py_None );
+}
/*****************************************************************************/
/* Function: IpoDeAlloc */
-/* Description: This is a callback function for the BPy_Ipo type. It is */
+/* Description: This is a callback function for the BPy_Ipo type. It is */
/* the destructor function. */
/*****************************************************************************/
static void IpoDeAlloc( BPy_Ipo * self )
@@ -1331,3 +1433,4 @@
{
return ( ( BPy_Ipo * ) pyobj )->ipo;
}
+
Index: source/blender/python/api2_2x/doc/Ipo.py
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/doc/Ipo.py,v
retrieving revision 1.26
diff -u -r1.26 Ipo.py
--- source/blender/python/api2_2x/doc/Ipo.py 15 Jun 2005 06:22:26 -0000 1.26
+++ source/blender/python/api2_2x/doc/Ipo.py 23 Jun 2005 20:47:58 -0000
@@ -54,21 +54,7 @@
It has no attributes.
"""
- def getName():
- """
- Gets the name of the Ipo.
- @rtype: string
- @return: the name of the Ipo.
- """
-
- def getCurves():
- """
- Gets all the IpoCurves of the Ipo.
- @rtype: list of IpoCurves
- @return: A list (possibly void) containing all the IpoCurves associated to the Ipo object.
- """
-
- def getCurve(curvename):
+ def __getitem__( curvename ):
"""
Return the IpoCurve with the given name. The possible values for
'curvename' are:
@@ -101,40 +87,53 @@
11. Constraint Ipo: Inf.
@type curvename : string
+ @rtype: IpoCurve object or None
+ @return: the corresponding IpoCurve or None.
+ """
+
+ def __len__():
+ """
+ Gets the number of curves for the Ipo.
+ @rtype: int
+ @return: the number of curves for the Ipo.
+ """
+
+ def getName():
+ """
+ Gets the name of the Ipo.
+ @rtype: string
+ @return: the name of the Ipo.
+ """
+
+ def getCurve(curvename):
+ """
+ Return the IpoCurve with the given name.
+ To be deprecated: use L{__getitem__} instead.
+ @type curvename : string
@rtype: IpoCurve object
@return: the corresponding IpoCurve, or None.
"""
+ def getCurves():
+ """
+ Gets all the IpoCurves of the Ipo.
+ @rtype: list of IpoCurves
+ @return: A list (possibly void) containing all the IpoCurves associated to the Ipo object.
+ """
+
def addCurve(curvename):
"""
- Add a new curve to the IPO object. The possible values for 'curvename' are:
- 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. Key Ipo: Speed, 'Key 1' - 'Key 63'.
- 9. Action Ipo: LocX, LocY, LocZ, SizeX, SizeY, SizeZ, QuatX, QuatY,
- QuatZ, QuatW.
- 10. Sequence Ipo: Fac.
- 11. Constraint Ipo: Inf.
+ Adds the IpoCurve with the given name to the Ipo.
+ To be deprecated: use L{append()} instead.
+ @type curvename : string
+ @rtype: IpoCurve object
+ @return: the corresponding IpoCurve, or None.
+ """
+ def append(curvename):
+ """
+ Adds the IpoCurve with the given name to the Ipo. See L{__getitem__}
+ for valid curve names.
@type curvename : string
@rtype: IpoCurve object
@return: the corresponding IpoCurve, or None.
@@ -193,9 +192,10 @@
def getNcurves():
"""
- Gets the number of curves of the Ipo.
+ Gets the number of curves for the Ipo.
+ To be deprecated: use L{__len__} instead.
@rtype: int
- @return: the number of curve of the Ipo.
+ @return: the number of curves for the Ipo.
"""
def getCurveBP(curvepos):
File Metadata
Details
Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
01/18/3655e932a31e842ec7f53cf275f8
Event Timeline
Log In to Comment