Page Menu
Home
Search
Configure Global Search
Log In
Files
F2611
stage3-patch-CurveIpo.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:05 PM
Size
85 KB
Subscribers
None
stage3-patch-CurveIpo.txt
View Options
--- source/blender/python/api2_2x/Curve.c 17 Jun 2005 05:10:13 -0000 1.29
+++ source/blender/python/api2_2x/Curve.c 6 Jul 2005 06:18:09 -0000
@@ -1,5 +1,5 @@
/*
- * $Id: Curve.c,v 1.29 2005/06/17 05:10:13 theeth Exp $
+ * $Id: Curve.c,v 1.1 2005/07/05 02:58:48 khughes Exp khughes $
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
@@ -24,7 +24,7 @@
*
* This is a new part of Blender.
*
- * Contributor(s): Jacques Guignot, Stephen Swaney
+ * Contributor(s): Jacques Guignot RIP 2005, Stephen Swaney, Ken Hughes
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
@@ -42,14 +42,12 @@
#include <BKE_library.h>
#include <BKE_curve.h>
#include <BKE_utildefines.h>
-#include <MEM_guardedalloc.h> /* because we wil be mallocing memory */
+#include <MEM_guardedalloc.h> /* because we will be mallocing memory */
-#include "CurNurb.h"
#include "Material.h"
#include "Object.h"
#include "gen_utils.h"
-
/*****************************************************************************/
/* The following string definitions are used for documentation strings. */
/* In Python these will be written to the console when doing a */
@@ -84,8 +82,8 @@
static PyObject *Curve_setPathLen( BPy_Curve * self, PyObject * args );
static PyObject *Curve_getTotcol( BPy_Curve * self );
static PyObject *Curve_setTotcol( BPy_Curve * self, PyObject * args );
-PyObject *Curve_getMode( BPy_Curve * self );
-PyObject *Curve_setMode( BPy_Curve * self, PyObject * args );
+static PyObject *Curve_getMode( BPy_Curve * self );
+static PyObject *Curve_setMode( BPy_Curve * self, PyObject * args );
PyObject *Curve_getBevresol( BPy_Curve * self );
PyObject *Curve_setBevresol( BPy_Curve * self, PyObject * args );
PyObject *Curve_getResolu( BPy_Curve * self );
@@ -98,22 +96,14 @@
PyObject *Curve_setExt1( BPy_Curve * self, PyObject * args );
PyObject *Curve_getExt2( BPy_Curve * self );
PyObject *Curve_setExt2( BPy_Curve * self, PyObject * args );
-static PyObject *Curve_getControlPoint( BPy_Curve * self, PyObject * args );
-static PyObject *Curve_setControlPoint( BPy_Curve * self, PyObject * args );
static PyObject *Curve_getLoc( BPy_Curve * self );
static PyObject *Curve_setLoc( BPy_Curve * self, PyObject * args );
static PyObject *Curve_getRot( BPy_Curve * self );
static PyObject *Curve_setRot( BPy_Curve * self, PyObject * args );
static PyObject *Curve_getSize( BPy_Curve * self );
static PyObject *Curve_setSize( BPy_Curve * self, PyObject * args );
-static PyObject *Curve_getNumCurves( BPy_Curve * self );
-static PyObject *Curve_isNurb( BPy_Curve * self, PyObject * args );
-static PyObject *Curve_isCyclic( BPy_Curve * self, PyObject * args);
-static PyObject *Curve_getNumPoints( BPy_Curve * self, PyObject * args );
-static PyObject *Curve_getNumPoints( BPy_Curve * self, PyObject * args );
-static PyObject *Curve_appendPoint( BPy_Curve * self, PyObject * args );
-static PyObject *Curve_appendNurb( BPy_Curve * self, PyObject * args );
+static PyObject *Curve_append( BPy_Curve * self, PyObject * args );
static PyObject *Curve_getMaterials( BPy_Curve * self );
@@ -123,13 +113,24 @@
static PyObject *Curve_getIter( BPy_Curve * self );
static PyObject *Curve_iterNext( BPy_Curve * self );
-PyObject *Curve_getNurb( BPy_Curve * self, int n );
+static PyObject *Curve_getNurb( BPy_Curve * self, int n );
+static int Curve_setNurb( BPy_Curve * self, int n, PyObject *value );
static int Curve_length( PyInstanceObject * inst );
void update_displists( void *data );
void makeDispList( Object * ob );
struct chartrans *text_to_curve( Object * ob, int mode );
+/* #####DEPRECATED###### */
+
+static PyObject *Curve_getNumCurves( BPy_Curve * self );
+static PyObject *Curve_appendPoint( BPy_Curve * self, PyObject * args );
+static PyObject *Curve_getControlPoint( BPy_Curve * self, PyObject * args );
+static PyObject *Curve_setControlPoint( BPy_Curve * self, PyObject * args );
+static PyObject *Curve_appendNurb( BPy_Curve * self, PyObject * args );
+static PyObject *Curve_getNumPoints( BPy_Curve * self, PyObject * args );
+static PyObject *Curve_isNurb( BPy_Curve * self, PyObject * args );
+static PyObject *Curve_isCyclic( BPy_Curve * self, PyObject * args);
/*****************************************************************************/
/* Python method definitions for Blender.Curve module: */
@@ -186,13 +187,6 @@
METH_NOARGS, "() - Return extent 2 of the bevel "},
{"setExt2", ( PyCFunction ) Curve_setExt2,
METH_VARARGS, "(int) - Sets extent 2 of the bevel "},
- {"getControlPoint", ( PyCFunction ) Curve_getControlPoint,
- METH_VARARGS, "(int numcurve,int numpoint) -\
-Gets a control point.Depending upon the curve type, returne a list of 4 or 9 floats"},
- {"setControlPoint", ( PyCFunction ) Curve_setControlPoint,
- METH_VARARGS, "(int numcurve,int numpoint,float x,float y,float z,\
-float w)(nurbs) or (int numcurve,int numpoint,float x1,...,x9(bezier)\
-Sets a control point "},
{"getLoc", ( PyCFunction ) Curve_getLoc,
METH_NOARGS, "() - Gets Location of the curve (a 3-tuple) "},
{"setLoc", ( PyCFunction ) Curve_setLoc,
@@ -205,19 +199,7 @@
METH_NOARGS, "() - Gets curve size"},
{"setSize", ( PyCFunction ) Curve_setSize,
METH_VARARGS, "(3-tuple) - Sets curve size"},
- {"getNumCurves", ( PyCFunction ) Curve_getNumCurves,
- METH_NOARGS, "() - Gets number of curves in Curve"},
- {"isNurb", ( PyCFunction ) Curve_isNurb,
- METH_VARARGS,
- "(nothing or integer) - returns 1 if curve is type Nurb, O otherwise."},
- {"isCyclic", ( PyCFunction ) Curve_isCyclic,
- METH_VARARGS, "( nothing or integer ) - returns true if curve is cyclic (closed), false otherwise."},
- {"getNumPoints", ( PyCFunction ) Curve_getNumPoints,
- METH_VARARGS,
- "(nothing or integer) - returns the number of points of the specified curve"},
- {"appendPoint", ( PyCFunction ) Curve_appendPoint, METH_VARARGS,
- "( int numcurve, list of coordinates) - adds a new point to end of curve"},
- {"appendNurb", ( PyCFunction ) Curve_appendNurb, METH_VARARGS,
+ {"append", ( PyCFunction ) Curve_append, METH_VARARGS,
"( new_nurb ) - adds a new nurb to the Curve"},
{"update", ( PyCFunction ) Curve_update, METH_NOARGS,
"( ) - updates display lists after changes to Curve"},
@@ -227,6 +209,25 @@
"() - returns Bevel Object assigned to this Curve"},
{"setBevOb", ( PyCFunction ) Curve_setBevOb, METH_VARARGS,
"() - assign a Bevel Object to this Curve"},
+
+/* #####DEPRECATED###### */
+
+ {"appendPoint", ( PyCFunction ) Curve_appendPoint, METH_VARARGS,
+ "- deprecated: use curve[].append()"},
+ {"getNumCurves", ( PyCFunction ) Curve_getNumCurves, METH_NOARGS,
+ "- deprecated: use len(curve)"},
+ {"getControlPoint", ( PyCFunction ) Curve_getControlPoint, METH_VARARGS,
+ "- deprecated: use curve[][]"},
+ {"setControlPoint", ( PyCFunction ) Curve_setControlPoint, METH_VARARGS,
+ "- deprecated: use curve[][]"},
+ {"appendNurb", ( PyCFunction ) Curve_appendNurb, METH_VARARGS,
+ "- deprecated: use curve.append()"},
+ {"getNumPoints", ( PyCFunction ) Curve_getNumPoints, METH_VARARGS,
+ "- deprecated: use len(curve[])"},
+ {"isNurb", ( PyCFunction ) Curve_isNurb, METH_VARARGS,
+ "- deprecated: use curve[].isNurb())"},
+ {"isCyclic", ( PyCFunction ) Curve_isCyclic, METH_VARARGS,
+ "- deprecated: use curve[].isCyclic())"},
{NULL, NULL, 0, NULL}
};
@@ -250,7 +251,7 @@
( intargfunc ) 0, /* sq_repeat */
( intargfunc ) Curve_getNurb, /* sq_item */
( intintargfunc ) 0, /* sq_slice */
- 0, /* sq_ass_item */
+ ( intobjargproc ) Curve_setNurb, /* sq_ass_item */
0, /* sq_ass_slice */
( objobjproc ) 0, /* sq_contains */
0,
@@ -531,7 +532,7 @@
}
-PyObject *Curve_getMode( BPy_Curve * self )
+static PyObject *Curve_getMode( BPy_Curve * self )
{
PyObject *attr = PyInt_FromLong( ( long ) self->curve->flag );
@@ -543,7 +544,7 @@
}
-PyObject *Curve_setMode( BPy_Curve * self, PyObject * args )
+static PyObject *Curve_setMode( BPy_Curve * self, PyObject * args )
{
if( !PyArg_ParseTuple( args, "i", &( self->curve->flag ) ) )
@@ -774,114 +775,6 @@
*/
-/*
- * Curve_setControlPoint
- * this function sets an EXISTING control point.
- * it does NOT add a new one.
- */
-
-static PyObject *Curve_setControlPoint( BPy_Curve * self, PyObject * args )
-{
- PyObject *listargs = 0;
- Nurb *ptrnurb = self->curve->nurb.first;
- int numcourbe, numpoint, i, j;
-
- if( !ptrnurb ) {
- Py_INCREF( Py_None );
- return Py_None;
- }
-
- if( ptrnurb->bp )
- if( !PyArg_ParseTuple
- ( args, "iiO", &numcourbe, &numpoint, &listargs ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_AttributeError,
- "expected int int list arguments" ) );
- if( ptrnurb->bezt )
- if( !PyArg_ParseTuple
- ( args, "iiO", &numcourbe, &numpoint, &listargs ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_AttributeError,
- "expected int int list arguments" ) );
-
- for( i = 0; i < numcourbe; i++ )
- ptrnurb = ptrnurb->next;
-
- if( ptrnurb->bp )
- for( i = 0; i < 4; i++ )
- ptrnurb->bp[numpoint].vec[i] =
- PyFloat_AsDouble( PyList_GetItem
- ( listargs, i ) );
-
- if( ptrnurb->bezt )
- for( i = 0; i < 3; i++ )
- for( j = 0; j < 3; j++ )
- ptrnurb->bezt[numpoint].vec[i][j] =
- PyFloat_AsDouble( PyList_GetItem
- ( listargs,
- i * 3 + j ) );
-
- Py_INCREF( Py_None );
- return Py_None;
-}
-
-static PyObject *Curve_getControlPoint( BPy_Curve * self, PyObject * args )
-{
- PyObject *liste = PyList_New( 0 ); /* return values */
-
- Nurb *ptrnurb;
- int i, j;
- /* input args: requested curve and point number on curve */
- int numcourbe, numpoint;
-
- if( !PyArg_ParseTuple( args, "ii", &numcourbe, &numpoint ) )
- return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
- "expected int int arguments" ) );
- if( ( numcourbe < 0 ) || ( numpoint < 0 ) )
- return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
- " arguments must be non-negative" ) );
-
- /* if no nurbs in this curve obj */
- if( !self->curve->nurb.first )
- return liste;
-
- /* walk the list of nurbs to find requested numcourbe */
- ptrnurb = self->curve->nurb.first;
- for( i = 0; i < numcourbe; i++ ) {
- ptrnurb = ptrnurb->next;
- if( !ptrnurb ) /* if zero, we ran just ran out of curves */
- return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
- "curve index out of range" ) );
- }
-
- /* check numpoint param against pntsu */
- if( numpoint >= ptrnurb->pntsu )
- return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
- "point index out of range" ) );
-
- if( ptrnurb->bp ) { /* if we are a nurb curve, you get 4 values */
- for( i = 0; i < 4; i++ )
- PyList_Append( liste,
- PyFloat_FromDouble( ptrnurb->
- bp[numpoint].
- vec[i] ) );
- }
-
- if( ptrnurb->bezt ) { /* if we are a bezier, you get 9 values */
- for( i = 0; i < 3; i++ )
- for( j = 0; j < 3; j++ )
- PyList_Append( liste,
- PyFloat_FromDouble( ptrnurb->
- bezt
- [numpoint].
- vec[i]
- [j] ) );
- }
-
- return liste;
-}
-
-
static PyObject *Curve_getLoc( BPy_Curve * self )
{
@@ -971,360 +864,149 @@
}
-/*
- * Count the number of splines in a Curve Object
- * int getNumCurves()
- */
+/****
+ append( new_point )
+ create a new nurb in the Curve and add the point param to it.
+ returns a refernce to the newly created nurb.
+*****/
-static PyObject *Curve_getNumCurves( BPy_Curve * self )
+static PyObject *Curve_append( BPy_Curve * self, PyObject * args )
{
- Nurb *ptrnurb;
- PyObject *ret_val;
- int num_curves = 0; /* start with no splines */
+ PyObject *val;
+ PyObject *curve;
+ PyObject *point;
+ Nurb *new_nurb;
+ int curve_type;
- /* get curve */
- ptrnurb = self->curve->nurb.first;
- if( ptrnurb ) { /* we have some nurbs in this curve */
- while( 1 ) {
- ++num_curves;
- ptrnurb = ptrnurb->next;
- if( !ptrnurb ) /* no more curves */
- break;
- }
- }
+ /* check to see that argument is a control point */
- ret_val = PyInt_FromLong( ( long ) num_curves );
+ if( !PyArg_ParseTuple( args, "O", &val ) )
+ return EXPP_ReturnPyObjError( PyExc_AttributeError,
+ "expected BezTriple or BNURBPoint argument" );
- if( ret_val )
- return ret_val;
+ if (BezTriple_CheckPyObject( val ))
+ curve_type = CU_BEZIER;
+ else if (BNURBPoint_CheckPyObject( val ))
+ curve_type = CU_NURBS;
+ else
+ return EXPP_ReturnPyObjError ( PyExc_TypeError,
+ "expected BezTriple or BNURBPoint argument" );
- /* oops! */
- return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "couldn't get number of curves" ) );
+ /* malloc new nurb */
+ new_nurb = ( Nurb * ) MEM_callocN( sizeof( Nurb ), "append" );
+ if( !new_nurb )
+ return EXPP_ReturnPyObjError
+ ( PyExc_MemoryError, "unable to malloc Nurb" );
+
+ /* append new nurb to tail of curve list and initialize it*/
+ BLI_addtail ( &self->curve->nurb, new_nurb );
+ new_nurb->resolu = self->curve->resolu;
+ new_nurb->resolv = self->curve->resolv;
+ new_nurb->hide = 0;
+ new_nurb->flag = 1;
+ new_nurb->type = curve_type;
+
+ /* create curve object, then append point */
+ curve = CurNurb_CreatePyObject( new_nurb );
+ point = CurNurb_append( curve, args );
+ if ( !point )
+ return NULL;
+ Py_DECREF (point);
+
+ /* finish the initialization (this probably should be in the
+ * BezTriple and BNURBPoint modules */
+
+ if( curve_type == CU_BEZIER ) { /* do setup for bezt */
+ new_nurb->bezt->h1 = HD_ALIGN;
+ new_nurb->bezt->h2 = HD_ALIGN;
+ new_nurb->bezt->f1 = 1;
+ new_nurb->bezt->f2 = 1;
+ new_nurb->bezt->f3 = 1;
+ new_nurb->bezt->hide = 0;
+ /* calchandlesNurb( new_nurb ); */
+ } else { /* set up bp */
+ new_nurb->pntsv = 1;
+ new_nurb->orderu = 4;
+ new_nurb->flagu = 0;
+ new_nurb->flagv = 0;
+ new_nurb->bp->f1 = 0;
+ new_nurb->bp->hide = 0;
+ new_nurb->knotsu = 0;
+ /*makenots( new_nurb, 1, new_nurb->flagu >> 1); */
+ }
+ return curve;
}
+/*
+ * Curve_update( )
+ * method to update display list for a Curve.
+ * used. after messing with control points
+ */
+
+PyObject *Curve_update( BPy_Curve * self )
+{
+/* update_displists( ( void * ) self->curve ); */
+ freedisplist( &self->curve->disp );
+
+ Py_INCREF( Py_None );
+ return Py_None;
+}
/*
- * count the number of points in a given spline
- * int getNumPoints( curve_num=0 )
+ * Curve_getMaterials
*
*/
-static PyObject *Curve_getNumPoints( BPy_Curve * self, PyObject * args )
+static PyObject *Curve_getMaterials( BPy_Curve * self )
{
- Nurb *ptrnurb;
- PyObject *ret_val;
- int curve_num = 0; /* default spline number */
- int i;
+ return ( EXPP_PyList_fromMaterialList( self->curve->mat,
+ self->curve->totcol, 1 ) );
- /* parse input arg */
- if( !PyArg_ParseTuple( args, "|i", &curve_num ) )
- return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
- "expected int argument" ) );
+}
- /* check arg - must be non-negative */
- if( curve_num < 0 )
- return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
- "argument must be non-negative" ) );
+/*****************************************************************************/
+/* Function: Curve_getBevOb */
+/* Description: Get the bevel object assign to the curve. */
+/*****************************************************************************/
+static PyObject *Curve_getBevOb( BPy_Curve * self)
+{
+ if( self->curve->bevobj ) {
+ return Object_CreatePyObject( self->curve->bevobj );
+ }
+
+ return EXPP_incr_ret( Py_None );
+}
+/*****************************************************************************/
+/* Function: Curve_setBevOb */
+/* Description: Assign a bevel object to the curve. */
+/*****************************************************************************/
+PyObject *Curve_setBevOb( BPy_Curve * self, PyObject * args )
+{
+ BPy_Object *pybevobj;
- /* walk the list of curves looking for our curve */
- ptrnurb = self->curve->nurb.first;
- if( !ptrnurb ) { /* no splines in this Curve */
+ /* Parse and check input args */
+ if( !PyArg_ParseTuple( args, "O", &pybevobj) ) {
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
- "no splines in this Curve" ) );
+ "expected object or None argument" ) );
}
- for( i = 0; i < curve_num; i++ ) {
- ptrnurb = ptrnurb->next;
- if( !ptrnurb ) /* if zero, we ran just ran out of curves */
- return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
- "curve index out of range" ) );
+ /* Accept None */
+ if( (PyObject *)pybevobj == Py_None ) {
+ self->curve->bevobj = (Object *)NULL;
+ } else {
+ /* Accept Object with type 'Curve' */
+ if( Object_CheckPyObject( ( PyObject * ) pybevobj ) &&
+ pybevobj->object->type == OB_CURVE) {
+ self->curve->bevobj =
+ Object_FromPyObject( ( PyObject * ) pybevobj );
+ } else {
+ return ( EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected Curve object type or None argument" ) );
+ }
}
- /* pntsu is the number of points in curve */
- ret_val = PyInt_FromLong( ( long ) ptrnurb->pntsu );
-
- if( ret_val )
- return ret_val;
-
- /* oops! */
- return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "couldn't get number of points for curve" ) );
-}
-
-/*
- * Test whether a given spline of a Curve is a nurb
- * as opposed to a bezier
- * int isNurb( curve_num=0 )
- */
-
-static PyObject *Curve_isNurb( BPy_Curve * self, PyObject * args )
-{
- int curve_num = 0; /* default value */
- int is_nurb;
- Nurb *ptrnurb;
- PyObject *ret_val;
- int i;
-
- /* parse and check input args */
- if( !PyArg_ParseTuple( args, "|i", &curve_num ) ) {
- return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
- "expected int argument" ) );
- }
- if( curve_num < 0 ) {
- return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
- "curve number must be non-negative" ) );
- }
-
- ptrnurb = self->curve->nurb.first;
-
- if( !ptrnurb ) /* no splines in this curve */
- return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
- "no splines in this Curve" ) );
-
- for( i = 0; i < curve_num; i++ ) {
- ptrnurb = ptrnurb->next;
- if( !ptrnurb ) /* if zero, we ran just ran out of curves */
- return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
- "curve index out of range" ) );
- }
-
- /* right now, there are only two curve types, nurb and bezier. */
- is_nurb = ptrnurb->bp ? 1 : 0;
-
- ret_val = PyInt_FromLong( ( long ) is_nurb );
- if( ret_val )
- return ret_val;
-
- /* oops */
- return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "couldn't get curve type" ) );
-}
-
-/* trying to make a check for closedness (cyclic), following on isNurb (above)
- copy-pasting done by antont@kyperjokki.fi */
-
-static PyObject *Curve_isCyclic( BPy_Curve * self, PyObject * args )
-{
- int curve_num = 0; /* default value */
- /* unused:*/
- /* int is_cyclic;
- * PyObject *ret_val;*/
- Nurb *ptrnurb;
- int i;
-
- /* parse and check input args */
- if( !PyArg_ParseTuple( args, "|i", &curve_num ) ) {
- return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
- "expected int argument" ) );
- }
- if( curve_num < 0 ) {
- return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
- "curve number must be non-negative" ) );
- }
-
- ptrnurb = self->curve->nurb.first;
-
- if( !ptrnurb ) /* no splines in this curve */
- return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
- "no splines in this Curve" ) );
-
- for( i = 0; i < curve_num; i++ ) {
- ptrnurb = ptrnurb->next;
- if( !ptrnurb ) /* if zero, we ran just ran out of curves */
- return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
- "curve index out of range" ) );
- }
-
- if( ptrnurb->flagu & CU_CYCLIC ){
- return EXPP_incr_ret_True();
- } else {
- return EXPP_incr_ret_False();
- }
-}
-
-
-/*
- * Curve_appendPoint( numcurve, new_point )
- * append a new point to indicated spline
- */
-
-static PyObject *Curve_appendPoint( BPy_Curve * self, PyObject * args )
-{
- int i;
- int nurb_num; /* index of curve we append to */
- PyObject *coord_args; /* coords for new point */
- PyObject *retval = NULL;
- PyObject *valtuple;
- Nurb *nurb = self->curve->nurb.first; /* first nurb in Curve */
-
-/* fixme - need to malloc new Nurb */
- if( !nurb )
- return ( EXPP_ReturnPyObjError
- ( PyExc_AttributeError, "no nurbs in this Curve" ) );
-
- if( !PyArg_ParseTuple( args, "iO", &nurb_num, &coord_args ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_AttributeError,
- "expected int, coords as arguments" ) );
-
- /*
- chase down the list of Nurbs looking for our curve.
- */
- for( i = 0; i < nurb_num; i++ ) {
- nurb = nurb->next;
- if( !nurb ) /* we ran off end of list */
- return ( EXPP_ReturnPyObjError
- ( PyExc_AttributeError,
- "curve index out of range" ) );
- }
-
- /* rebuild our arg tuple for appendPointToNurb() */
- valtuple = Py_BuildValue( "(O)", coord_args );
-
- retval = CurNurb_appendPointToNurb( nurb, valtuple );
- Py_DECREF( valtuple );
-
- return retval;
-}
-
-
-/****
- appendNurb( new_point )
- create a new nurb in the Curve and add the point param to it.
- returns a refernce to the newly created nurb.
-*****/
-
-static PyObject *Curve_appendNurb( BPy_Curve * self, PyObject * args )
-{
- Nurb *nurb_ptr = self->curve->nurb.first;
- Nurb **pptr = ( Nurb ** ) & ( self->curve->nurb.first );
- Nurb *new_nurb;
-
-
- /* walk to end of nurblist */
- if( nurb_ptr ) {
- while( nurb_ptr->next ) {
- nurb_ptr = nurb_ptr->next;
- }
- pptr = &nurb_ptr->next;
- }
-
- /* malloc new nurb */
- new_nurb = ( Nurb * ) MEM_callocN( sizeof( Nurb ), "appendNurb" );
- if( !new_nurb )
- return EXPP_ReturnPyObjError
- ( PyExc_MemoryError, "unable to malloc Nurb" );
-
- if( CurNurb_appendPointToNurb( new_nurb, args ) ) {
- *pptr = new_nurb;
- new_nurb->resolu = self->curve->resolu;
- new_nurb->resolv = self->curve->resolv;
- new_nurb->hide = 0;
- new_nurb->flag = 1;
-
-
- if( new_nurb->bezt ) { /* do setup for bezt */
- new_nurb->type = CU_BEZIER;
- new_nurb->bezt->h1 = HD_ALIGN;
- new_nurb->bezt->h2 = HD_ALIGN;
- new_nurb->bezt->f1 = 1;
- new_nurb->bezt->f2 = 1;
- new_nurb->bezt->f3 = 1;
- new_nurb->bezt->hide = 0;
- /* calchandlesNurb( new_nurb ); */
- } else { /* set up bp */
- new_nurb->pntsv = 1;
- new_nurb->type = CU_NURBS;
- new_nurb->orderu = 4;
- new_nurb->flagu = 0;
- new_nurb->flagv = 0;
- new_nurb->bp->f1 = 0;
- new_nurb->bp->hide = 0;
- new_nurb->knotsu = 0;
- /*makenots( new_nurb, 1, new_nurb->flagu >> 1); */
- }
-
- } else {
- freeNurb( new_nurb );
- return NULL; /* with PyErr already set */
- }
-
- return CurNurb_CreatePyObject( new_nurb );
-}
-
-
-/*
- * Curve_update( )
- * method to update display list for a Curve.
- * used. after messing with control points
- */
-
-PyObject *Curve_update( BPy_Curve * self )
-{
-/* update_displists( ( void * ) self->curve ); */
- freedisplist( &self->curve->disp );
-
- Py_INCREF( Py_None );
- return Py_None;
-}
-
-/*
- * Curve_getMaterials
- *
- */
-
-static PyObject *Curve_getMaterials( BPy_Curve * self )
-{
- return ( EXPP_PyList_fromMaterialList( self->curve->mat,
- self->curve->totcol, 1 ) );
-
-}
-
-/*****************************************************************************/
-/* Function: Curve_getBevOb */
-/* Description: Get the bevel object assign to the curve. */
-/*****************************************************************************/
-static PyObject *Curve_getBevOb( BPy_Curve * self)
-{
- if( self->curve->bevobj ) {
- return Object_CreatePyObject( self->curve->bevobj );
- }
-
- return EXPP_incr_ret( Py_None );
-}
-
-/*****************************************************************************/
-/* Function: Curve_setBevOb */
-/* Description: Assign a bevel object to the curve. */
-/*****************************************************************************/
-PyObject *Curve_setBevOb( BPy_Curve * self, PyObject * args )
-{
- BPy_Object *pybevobj;
-
- /* Parse and check input args */
- if( !PyArg_ParseTuple( args, "O", &pybevobj) ) {
- return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
- "expected object or None argument" ) );
- }
-
- /* Accept None */
- if( (PyObject *)pybevobj == Py_None ) {
- self->curve->bevobj = (Object *)NULL;
- } else {
- /* Accept Object with type 'Curve' */
- if( Object_CheckPyObject( ( PyObject * ) pybevobj ) &&
- pybevobj->object->type == OB_CURVE) {
- self->curve->bevobj =
- Object_FromPyObject( ( PyObject * ) pybevobj );
- } else {
- return ( EXPP_ReturnPyObjError( PyExc_TypeError,
- "expected Curve object type or None argument" ) );
- }
- }
-
- return EXPP_incr_ret( Py_None );
+ return EXPP_incr_ret( Py_None );
}
/*
@@ -1382,6 +1064,12 @@
static int Curve_length( PyInstanceObject * inst )
{
+#if 0
+ /*
+ * old way: Curve_getNumCurves() returns new refence which is
+ * not Py_DECREF()'ed
+ */
+
if( Curve_CheckPyObject( ( PyObject * ) inst ) )
return ( ( int ) PyInt_AsLong
( Curve_getNumCurves( ( BPy_Curve * ) inst ) ) );
@@ -1389,9 +1077,23 @@
return EXPP_ReturnIntError( PyExc_RuntimeError,
"arg is not a BPy_Curve" );
-}
+#else
+ Nurb *pNurb = ((BPy_Curve *)inst)->curve->nurb.first;
+ int num_curves = 0; /* start with no splines */
+ if( !Curve_CheckPyObject( ( PyObject * ) inst ) )
+ return EXPP_ReturnIntError( PyExc_RuntimeError,
+ "arg is not a BPy_Curve" );
+
+ /* count number of curves */
+ while ( pNurb ) {
+ ++num_curves;
+ pNurb = pNurb->next;
+ }
+ return num_curves;
+#endif
+}
/*
* Curve_getNurb
@@ -1400,6 +1102,7 @@
* it is called via the [] operator, not as a usual instance method.
*/
+static
PyObject *Curve_getNurb( BPy_Curve * self, int n )
{
PyObject *pyo;
@@ -1428,7 +1131,54 @@
}
+/*****************************************************************************/
+/* Function: Curve_setNurb */
+/* Used to delete the Nth nurb in a Curve. */
+/* This is one of the tp_as_sequence methods, hence the int N argument. */
+/* It is called via the [] operator, not as a usual instance method. It */
+/* would also usually be used to assign an item to the sequence, but if */
+/* value is non-NULL we throw an exception. */
+/*****************************************************************************/
+
+static
+int Curve_setNurb( BPy_Curve *self, int n, PyObject *value )
+{
+ Nurb *pNurb;
+
+ /*
+ * currently only deletion is supported, so if we get an
+ * object it's an error
+ */
+
+ if ( value )
+ return EXPP_ReturnIntError ( PyExc_NotImplementedError,
+ "cannot set CurNurbs" );
+ /* bail if index < 0 */
+ if( n < 0 )
+ return ( EXPP_ReturnIntError( PyExc_IndexError,
+ "index less than 0" ) );
+ /* bail if no Nurbs in Curve */
+ if( !self->curve->nurb.first )
+ return ( EXPP_ReturnIntError( PyExc_IndexError,
+ "no Nurbs in this Curve" ) );
+ /* set pointer to nth Nurb */
+ for( pNurb = self->curve->nurb.first; pNurb && n; --n )
+ pNurb = pNurb->next;
+
+ if( !pNurb ) /* we came to the end of the list */
+ return EXPP_ReturnIntError( PyExc_IndexError,
+ "index out of range" );
+
+ /* free any pointers to curves, then unlink the Nurb */
+ if (pNurb->bp)
+ MEM_freeN(pNurb->bp);
+ else if (pNurb->bezt)
+ MEM_freeN(pNurb->bezt);
+ BLI_freelinkN ( &self->curve->nurb, pNurb );
+
+ return 0;
+}
/*****************************************************************************/
/* Function: CurveDeAlloc */
@@ -1656,3 +1406,490 @@
#endif
}
+/* #####DEPRECATED###### */
+
+#if BLENDER_VERSION < 243
+
+#include "BezTriple.h"
+#include "BNURBPoint.h"
+#include "CurNurb.h"
+
+/*
+ * Curve_appendPoint( numcurve, new_point )
+ * append a new point to indicated spline
+ */
+
+static PyObject *Curve_appendPoint( BPy_Curve * self, PyObject * args )
+{
+#if BLENDER_VERSION < 241
+ static int depcount = 2;
+ int i;
+ int nurb_num; /* index of curve we append to */
+ BPy_CurNurb *curve; /* temporary curve object */
+ PyObject *coord_args; /* coords for new point */
+ PyObject *retval = NULL;
+ PyObject *valtuple;
+ Nurb *nurb = self->curve->nurb.first; /* first nurb in Curve */
+
+ if ( depcount ) {
+ printf ("Curve.appendPoint() is deprecated by curve[].append.\n");
+ printf (" This method will be removed after version 2.40.\n");
+ depcount--;
+ }
+
+ if( !nurb )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_AttributeError, "no nurbs in this Curve" ) );
+
+ if( !PyArg_ParseTuple( args, "iO", &nurb_num, &coord_args ) )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_AttributeError,
+ "expected int, coords as arguments" ) );
+
+ /*
+ chase down the list of Nurbs looking for our curve.
+ */
+ for( i = 0; i < nurb_num; i++ ) {
+ nurb = nurb->next;
+ if( !nurb ) /* we ran off end of list */
+ return EXPP_ReturnPyObjError
+ ( PyExc_AttributeError,
+ "curve index out of range" );
+ }
+
+ /* rebuild our arg tuple for CurNurb_append() */
+ valtuple = Py_BuildValue( "(O)", coord_args );
+ curve = CurNurb_CreatePyObject( nurb );
+ coord_args = CurNurb_append( curve, valtuple );
+ Py_DECREF( valtuple );
+
+ return coord_args; /* return the new point */
+#else
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "replaced by \"curve[].append()\"" );
+#endif
+}
+
+/*
+ * Count the number of splines in a Curve Object
+ * int getNumCurves()
+ */
+
+static PyObject *Curve_getNumCurves( BPy_Curve * self )
+{
+#if BLENDER_VERSION < 241
+ static int depcount = 2;
+ int num_curves = 0; /* start with no splines */
+ PyObject *ret_val;
+
+ if ( depcount ) {
+ printf ("Curve.getNumCurves() is deprecated by the len() operator.\n");
+ printf (" This method will be removed after version 2.40.\n");
+ depcount--;
+ }
+
+#if 0
+ Nurb *ptrnurb;
+
+ /* get curve */
+ ptrnurb = self->curve->nurb.first;
+
+ /* count number of curves */
+ while ( ptrnurb ) {
+ ++num_curves;
+ ptrnurb = ptrnurb->next;
+ }
+#else
+ num_curves = Curve_length( ( PyInstanceObject *) self );
+#endif
+
+ if (num_curves < 0) /* Curve_length() returned error */
+ return NULL;
+
+ ret_val = PyInt_FromLong( ( long ) num_curves );
+
+ if( ret_val )
+ return ret_val;
+
+ /* oops! */
+ return EXPP_ReturnPyObjError( PyExc_MemoryError,
+ "unable to malloc PyInt" );
+#else
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "replaced by \"len(curve)\"" );
+#endif
+}
+
+static PyObject *Curve_getControlPoint( BPy_Curve * self, PyObject * args )
+{
+#if BLENDER_VERSION < 241
+ static int depcount = 2;
+ PyObject *liste = PyList_New( 0 ); /* return values */
+
+ Nurb *ptrnurb;
+ int i, j;
+ /* input args: requested curve and point number on curve */
+ int numcourbe, numpoint;
+
+ if ( depcount ) {
+ printf ("Curve.getControlPoint() is deprecated by curve[][].\n");
+ printf (" This method will be removed after version 2.40.\n");
+ depcount--;
+ }
+
+ if( !PyArg_ParseTuple( args, "ii", &numcourbe, &numpoint ) )
+ return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
+ "expected int int arguments" ) );
+ if( ( numcourbe < 0 ) || ( numpoint < 0 ) )
+ return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
+ " arguments must be non-negative" ) );
+
+ /* if no nurbs in this curve obj */
+ if( !self->curve->nurb.first )
+ return liste;
+
+ /* walk the list of nurbs to find requested numcourbe */
+ ptrnurb = self->curve->nurb.first;
+ for( i = 0; i < numcourbe; i++ ) {
+ ptrnurb = ptrnurb->next;
+ if( !ptrnurb ) /* if zero, we ran just ran out of curves */
+ return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
+ "curve index out of range" ) );
+ }
+
+ /* check numpoint param against pntsu */
+ if( numpoint >= ptrnurb->pntsu )
+ return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
+ "point index out of range" ) );
+
+ if( ptrnurb->bp ) { /* if we are a nurb curve, you get 4 values */
+ for( i = 0; i < 4; i++ )
+ PyList_Append( liste,
+ PyFloat_FromDouble( ptrnurb->
+ bp[numpoint].
+ vec[i] ) );
+ }
+
+ if( ptrnurb->bezt ) { /* if we are a bezier, you get 9 values */
+ for( i = 0; i < 3; i++ )
+ for( j = 0; j < 3; j++ )
+ PyList_Append( liste,
+ PyFloat_FromDouble( ptrnurb->
+ bezt
+ [numpoint].
+ vec[i]
+ [j] ) );
+ }
+
+ return liste;
+#else
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "replaced by \"curve[][])\"" );
+#endif
+}
+
+
+/*
+ * Curve_setControlPoint
+ * this function sets an EXISTING control point.
+ * it does NOT add a new one.
+ */
+
+static PyObject *Curve_setControlPoint( BPy_Curve * self, PyObject * args )
+{
+#if BLENDER_VERSION < 241
+ static int depcount = 2;
+ PyObject *listargs = 0;
+ Nurb *ptrnurb = self->curve->nurb.first;
+ int numcourbe, numpoint, i, j;
+
+ if ( depcount ) {
+ printf ("Curve.setControlPoint() is deprecated by curve[][].\n");
+ printf (" This method will be removed after version 2.40.\n");
+ depcount--;
+ }
+
+ if( !ptrnurb ) {
+ Py_INCREF( Py_None );
+ return Py_None;
+ }
+
+ if( ptrnurb->bp )
+ if( !PyArg_ParseTuple
+ ( args, "iiO", &numcourbe, &numpoint, &listargs ) )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_AttributeError,
+ "expected int int list arguments" ) );
+ if( ptrnurb->bezt )
+ if( !PyArg_ParseTuple
+ ( args, "iiO", &numcourbe, &numpoint, &listargs ) )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_AttributeError,
+ "expected int int list arguments" ) );
+
+ for( i = 0; i < numcourbe; i++ )
+ ptrnurb = ptrnurb->next;
+
+ if( ptrnurb->bp )
+ for( i = 0; i < 4; i++ )
+ ptrnurb->bp[numpoint].vec[i] =
+ PyFloat_AsDouble( PyList_GetItem
+ ( listargs, i ) );
+
+ if( ptrnurb->bezt )
+ for( i = 0; i < 3; i++ )
+ for( j = 0; j < 3; j++ )
+ ptrnurb->bezt[numpoint].vec[i][j] =
+ PyFloat_AsDouble( PyList_GetItem
+ ( listargs,
+ i * 3 + j ) );
+
+ Py_INCREF( Py_None );
+ return Py_None;
+#else
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "replaced by \"curve[][]\"" );
+#endif
+}
+
+/****
+ appendNurb( new_point )
+ create a new nurb in the Curve and add the point param to it.
+ returns a refernce to the newly created nurb.
+*****/
+
+static PyObject *Curve_appendNurb( BPy_Curve * self, PyObject * args )
+{
+#if BLENDER_VERSION < 241
+ static int depcount = 2;
+ Nurb *nurb_ptr = self->curve->nurb.first;
+ Nurb *new_nurb;
+
+ if ( depcount ) {
+ printf ("Curve.appendNurb() is deprecated by curve.append().\n");
+ printf (" This method will be removed after version 2.40.\n");
+ depcount--;
+ }
+
+ /* malloc new nurb */
+ new_nurb = ( Nurb * ) MEM_callocN( sizeof( Nurb ), "append" );
+ if( !new_nurb )
+ return EXPP_ReturnPyObjError
+ ( PyExc_MemoryError, "unable to malloc Nurb" );
+
+ if( CurNurb_appendPointToNurb( new_nurb, args ) ) {
+ BLI_addtail ( &self->curve->nurb, new_nurb );
+ new_nurb->resolu = self->curve->resolu;
+ new_nurb->resolv = self->curve->resolv;
+ new_nurb->hide = 0;
+ new_nurb->flag = 1;
+
+ if( new_nurb->bezt ) { /* do setup for bezt */
+ new_nurb->type = CU_BEZIER;
+ new_nurb->bezt->h1 = HD_ALIGN;
+ new_nurb->bezt->h2 = HD_ALIGN;
+ new_nurb->bezt->f1 = 1;
+ new_nurb->bezt->f2 = 1;
+ new_nurb->bezt->f3 = 1;
+ new_nurb->bezt->hide = 0;
+ /* calchandlesNurb( new_nurb ); */
+ } else { /* set up bp */
+ new_nurb->pntsv = 1;
+ new_nurb->type = CU_NURBS;
+ new_nurb->orderu = 4;
+ new_nurb->flagu = 0;
+ new_nurb->flagv = 0;
+ new_nurb->bp->f1 = 0;
+ new_nurb->bp->hide = 0;
+ new_nurb->knotsu = 0;
+ /*makenots( new_nurb, 1, new_nurb->flagu >> 1); */
+ }
+ } else {
+ freeNurb( new_nurb );
+ return NULL; /* with PyErr already set */
+ }
+
+ return CurNurb_CreatePyObject( new_nurb );
+#else
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "replaced by \"curve.append\"" );
+#endif
+}
+
+/*
+ * count the number of points in a given spline
+ * int getNumPoints( curve_num=0 )
+ *
+ */
+
+static PyObject *Curve_getNumPoints( BPy_Curve * self, PyObject * args )
+{
+#if BLENDER_VERSION < 241
+ static int depcount = 2;
+ Nurb *ptrnurb;
+ PyObject *ret_val;
+ int curve_num = 0; /* default spline number */
+ int i;
+
+ if ( depcount ) {
+ printf ("Curve.getNumPoints() is deprecated by len(curve[]).\n");
+ printf (" This method will be removed after version 2.40.\n");
+ depcount--;
+ }
+
+ /* parse input arg */
+ if( !PyArg_ParseTuple( args, "|i", &curve_num ) )
+ return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
+ "expected int argument" ) );
+
+ /* check arg - must be non-negative */
+ if( curve_num < 0 )
+ return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
+ "argument must be non-negative" ) );
+
+
+ /* walk the list of curves looking for our curve */
+ ptrnurb = self->curve->nurb.first;
+ if( !ptrnurb ) { /* no splines in this Curve */
+ return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
+ "no splines in this Curve" ) );
+ }
+
+ for( i = 0; i < curve_num; i++ ) {
+ ptrnurb = ptrnurb->next;
+ if( !ptrnurb ) /* if zero, we ran just ran out of curves */
+ return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
+ "curve index out of range" ) );
+ }
+
+ /* pntsu is the number of points in curve */
+ ret_val = PyInt_FromLong( ( long ) ptrnurb->pntsu );
+
+ if( ret_val )
+ return ret_val;
+
+ /* oops! */
+ return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "couldn't get number of points for curve" ) );
+#else
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "replaced by \"len(curve[])\"" );
+#endif
+}
+
+/*
+ * Test whether a given spline of a Curve is a nurb
+ * as opposed to a bezier
+ * int isNurb( curve_num=0 )
+ */
+
+static PyObject *Curve_isNurb( BPy_Curve * self, PyObject * args )
+{
+#if BLENDER_VERSION < 241
+ static int depcount = 2;
+ int curve_num = 0; /* default value */
+ int is_nurb;
+ Nurb *ptrnurb;
+ PyObject *ret_val;
+ int i;
+
+ if ( depcount ) {
+ printf ("Curve.isNurb() is deprecated by curve[].isNurb.\n");
+ printf (" This method will be removed after version 2.40.\n");
+ depcount--;
+ }
+
+ /* parse and check input args */
+ if( !PyArg_ParseTuple( args, "|i", &curve_num ) ) {
+ return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
+ "expected int argument" ) );
+ }
+ if( curve_num < 0 ) {
+ return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
+ "curve number must be non-negative" ) );
+ }
+
+ ptrnurb = self->curve->nurb.first;
+
+ if( !ptrnurb ) /* no splines in this curve */
+ return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
+ "no splines in this Curve" ) );
+
+ for( i = 0; i < curve_num; i++ ) {
+ ptrnurb = ptrnurb->next;
+ if( !ptrnurb ) /* if zero, we ran just ran out of curves */
+ return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
+ "curve index out of range" ) );
+ }
+
+ /* right now, there are only two curve types, nurb and bezier. */
+ is_nurb = ptrnurb->bp ? 1 : 0;
+
+ ret_val = PyInt_FromLong( ( long ) is_nurb );
+ if( ret_val )
+ return ret_val;
+
+ /* oops */
+ return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "couldn't get curve type" ) );
+#else
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "replaced by \"curve[].isNurb\"" );
+#endif
+}
+
+/* trying to make a check for closedness (cyclic), following on isNurb (above)
+ copy-pasting done by antont@kyperjokki.fi */
+
+static PyObject *Curve_isCyclic( BPy_Curve * self, PyObject * args )
+{
+#if BLENDER_VERSION < 241
+ static int depcount = 2;
+ int curve_num = 0; /* default value */
+ /* unused:*/
+ /* int is_cyclic;
+ * PyObject *ret_val;*/
+ Nurb *ptrnurb;
+ int i;
+
+ if ( depcount ) {
+ printf ("Curve.isCyclic() is deprecated by curve[].isCyclic().\n");
+ printf (" This method will be removed after version 2.40.\n");
+ depcount--;
+ }
+
+ /* parse and check input args */
+ if( !PyArg_ParseTuple( args, "|i", &curve_num ) ) {
+ return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
+ "expected int argument" ) );
+ }
+ if( curve_num < 0 ) {
+ return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
+ "curve number must be non-negative" ) );
+ }
+
+ ptrnurb = self->curve->nurb.first;
+
+ if( !ptrnurb ) /* no splines in this curve */
+ return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
+ "no splines in this Curve" ) );
+
+ for( i = 0; i < curve_num; i++ ) {
+ ptrnurb = ptrnurb->next;
+ if( !ptrnurb ) /* if zero, we ran just ran out of curves */
+ return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
+ "curve index out of range" ) );
+ }
+
+ if( ptrnurb->flagu & CU_CYCLIC ){
+ return EXPP_incr_ret_True();
+ } else {
+ return EXPP_incr_ret_False();
+ }
+#else
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "replaced by \"curve[].isCyclic()\"" );
+#endif
+}
+
+#endif /* BLENDER_VERSION < 243 */
--- source/blender/python/api2_2x/Curve.h 13 Jun 2005 19:15:01 -0000 1.18
+++ source/blender/python/api2_2x/Curve.h 6 Jul 2005 06:18:09 -0000
@@ -60,8 +60,6 @@
PyObject *Curve_getName( BPy_Curve * self );
PyObject *Curve_setName( BPy_Curve * self, PyObject * args );
-PyObject *Curve_getMode( BPy_Curve * self );
-PyObject *Curve_setMode( BPy_Curve * self, PyObject * args );
PyObject *Curve_getBevresol( BPy_Curve * self );
PyObject *Curve_setBevresol( BPy_Curve * self, PyObject * args );
PyObject *Curve_getResolu( BPy_Curve * self );
--- source/blender/python/api2_2x/Ipo.c 24 May 2005 15:14:32 -0000 1.40
+++ source/blender/python/api2_2x/Ipo.c 6 Jul 2005 06:18:19 -0000
@@ -1,5 +1,5 @@
/*
- * $Id: Ipo.c,v 1.40 2005/05/24 15:14:32 stiv Exp $
+ * $Id: Ipo.c,v 1.3 2005/07/05 01:33:28 khughes Exp khughes $
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
@@ -33,6 +33,7 @@
#include "Ipo.h"
+#include <BKE_blender.h>
#include <BKE_main.h>
#include <BKE_global.h>
#include <BKE_object.h>
@@ -54,6 +55,9 @@
/*****************************************************************************/
static PyObject *M_Ipo_New( PyObject * self, PyObject * args );
static PyObject *M_Ipo_Get( PyObject * self, PyObject * args );
+
+/* #####DEPRECATED###### */
+
static PyObject *M_Ipo_Recalc( PyObject * self, PyObject * args );
/*****************************************************************************/
@@ -64,7 +68,7 @@
char M_Ipo_doc[] = "";
char M_Ipo_New_doc[] = "";
char M_Ipo_Get_doc[] = "";
-
+char M_Ipo_Recalc_doc[] = "deprecated: use Ipocurve.recalc() instead";
/*****************************************************************************/
/* Python method structure definition for Blender.Ipo module: */
@@ -75,7 +79,7 @@
M_Ipo_New_doc},
{"Get", M_Ipo_Get, METH_VARARGS, M_Ipo_Get_doc},
{"get", M_Ipo_Get, METH_VARARGS, M_Ipo_Get_doc},
- {"Recalc", M_Ipo_Recalc, METH_VARARGS, M_Ipo_Get_doc},
+ {"Recalc", M_Ipo_Recalc, METH_VARARGS, M_Ipo_Recalc_doc},
{NULL, NULL, 0, NULL}
};
@@ -85,24 +89,30 @@
static PyObject *Ipo_getName( BPy_Ipo * self );
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_getCurve( BPy_Ipo * self, PyObject * args );
+static PyObject *Ipo_append( BPy_Ipo * self, PyObject * args );
static PyObject *Ipo_getCurves( BPy_Ipo * self );
+
+static PyObject *Ipo_getIter( BPy_Ipo * self );
+static PyObject *Ipo_nextIter( BPy_Ipo * self );
+
+/* #####DEPRECATED###### */
+
+static PyObject *Ipo_getCurvecurval( BPy_Ipo * self, PyObject * args );
+static PyObject *Ipo_getCurveBP( BPy_Ipo * self, PyObject * args );
+static PyObject *Ipo_DeleteBezPoints( BPy_Ipo * self, PyObject * args );
+static PyObject *Ipo_getNcurves( 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 );
+static PyObject *Ipo_getCurve( BPy_Ipo * self, PyObject * args );
+static PyObject *Ipo_getCurveBeztriple( BPy_Ipo * self, PyObject * args );
+static PyObject *Ipo_setCurveBeztriple( BPy_Ipo * self, PyObject * args );
static PyObject *Ipo_getNBezPoints( BPy_Ipo * self, PyObject * args );
-static PyObject *Ipo_DeleteBezPoints( BPy_Ipo * self, PyObject * args );
-static PyObject *Ipo_getCurveBP( BPy_Ipo * self, PyObject * args );
-static PyObject *Ipo_getCurvecurval( BPy_Ipo * self, PyObject * args );
+static PyObject *Ipo_setBlocktype( 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_oldgetCurves( BPy_Ipo * self );
/*****************************************************************************/
/* Python BPy_Ipo methods table: */
@@ -115,74 +125,132 @@
"(str) - Change Ipo Data name"},
{"getBlocktype", ( PyCFunction ) Ipo_getBlocktype, METH_NOARGS,
"() - Return Ipo blocktype -"},
- {"setBlocktype", ( PyCFunction ) Ipo_setBlocktype, METH_VARARGS,
- "(str) - Change Ipo blocktype"},
{"getRctf", ( PyCFunction ) Ipo_getRctf, METH_NOARGS,
"() - Return Ipo rctf - "},
{"setRctf", ( PyCFunction ) Ipo_setRctf, METH_VARARGS,
"(str) - Change Ipo rctf"},
+ {"append", ( PyCFunction ) Ipo_append, METH_VARARGS,
+ "(str) - add IpoCurves to curve list"},
+
+/* #####DEPRECATED###### */
+
+ {"getCurveBP", ( PyCFunction ) Ipo_getCurveBP, METH_VARARGS,
+ "- not implemented"},
+ {"delBezPoint", ( PyCFunction ) Ipo_DeleteBezPoints, METH_VARARGS,
+ "- not implemented"},
+ {"getCurve", ( PyCFunction ) Ipo_getCurve, METH_VARARGS,
+ "- deprecated: use \"ipo[]\" instead"},
{"addCurve", ( PyCFunction ) Ipo_addCurve, METH_VARARGS,
- "() - Return Ipo ncurves"},
+ "- deprecated: use \"ipo.append()\" instead"},
{"delCurve", ( PyCFunction ) Ipo_delCurve, METH_VARARGS,
- "() - Delete Ipo curves"},
+ "- deprecated: use \"del ipo[]\" instead"},
{"getNcurves", ( PyCFunction ) Ipo_getNcurves, METH_NOARGS,
- "() - Return Ipo ncurves"},
+ "- deprecated: use \"len(ipo)\" instead"},
+ {"getCurveBeztriple", ( PyCFunction ) Ipo_getCurveBeztriple, METH_VARARGS,
+ "- deprecated: use \"ipo[][]\" instead"},
+ {"setCurveBeztriple", ( PyCFunction ) Ipo_setCurveBeztriple, METH_VARARGS,
+ "- deprecated: use \"ipo[][]\" instead"},
{"getNBezPoints", ( PyCFunction ) Ipo_getNBezPoints, METH_VARARGS,
- "() - Return curve number of Bez points"},
- {"delBezPoint", ( PyCFunction ) Ipo_DeleteBezPoints, METH_VARARGS,
- "() - Return curve number of Bez points"},
- {"getCurveBP", ( PyCFunction ) Ipo_getCurveBP, METH_VARARGS,
- "() - Return Ipo ncurves"},
- {"EvaluateCurveOn", ( PyCFunction ) Ipo_EvaluateCurveOn, METH_VARARGS,
- "() - Return curve value at given time"},
+ "- deprecated: use \"len(ipo[]) \" instead"},
+ {"setBlocktype", ( PyCFunction ) Ipo_setBlocktype, METH_VARARGS,
+ "- deprecated"},
{"getCurveCurval", ( PyCFunction ) Ipo_getCurvecurval, METH_VARARGS,
- "() - Return curval"},
- {"getCurveBeztriple", ( PyCFunction ) Ipo_getCurveBeztriple,
- METH_VARARGS,
- "() - Return Ipo ncurves"},
- {"setCurveBeztriple", ( PyCFunction ) Ipo_setCurveBeztriple,
- METH_VARARGS,
- "() - Return curval"},
- {"getCurves", ( PyCFunction ) Ipo_getCurves, METH_NOARGS,
- "() - Return curval"},
- {"getCurve", ( PyCFunction ) Ipo_getCurve, METH_VARARGS,
- "() - Return curval"},
+ "- deprecated: use \"ipo[].evaluate(curtime)\" instead"},
+ {"EvaluateCurveOn", ( PyCFunction ) Ipo_EvaluateCurveOn, METH_VARARGS,
+ "- deprecated: use \"ipo[].evaluate(curtime)\" instead"},
+ {"getCurves", ( PyCFunction ) Ipo_oldgetCurves, METH_NOARGS,
+ "- deprecated: use ipo.curves attribute"},
{NULL, NULL, 0, NULL}
};
/*****************************************************************************/
+/* Python IpoCurve_Type callbacks for get/set of instance variables */
+/*****************************************************************************/
+
+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",
+ NULL},
+#endif
+ {NULL,NULL,NULL,NULL,NULL} /* Sentinel */
+};
+
+/*****************************************************************************/
/* Python Ipo_Type callback function prototypes: */
/*****************************************************************************/
static void IpoDeAlloc( 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 int Ipo_length( BPy_Ipo * self );
+static PyObject * Ipo_getItem( BPy_Ipo * self, PyObject *key );
+static int Ipo_setItem( BPy_Ipo *self, PyObject *key , PyObject *value );
+
+static PyMappingMethods Ipo_mapping = {
+ (inquiry)Ipo_length, /* mp_length (__len__) */
+ (binaryfunc)Ipo_getItem, /* mp_subscript (__getitem__) */
+ (objobjargproc)Ipo_setItem /* mp_ass_subscript (__setitem__) */
+};
/*****************************************************************************/
/* 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 */
+ 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 */
+ (destructor)IpoDeAlloc, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ (reprfunc)IpoRepr, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ &Ipo_mapping, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+
+ /*** Flags to define presence of optional/expanded features ***/
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ (getiterfunc)Ipo_getIter, /* tp_iter */
+ (iternextfunc)Ipo_nextIter, /* tp_iternext */
+ BPy_Ipo_methods, /* tp_methods */
+ 0, /* tp_members */
+ BPY_Ipo_getseters, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ 0, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
+ 0, /* tp_mro */
+ 0, /* tp_cache */
+ 0, /* tp_subclasses */
+ 0, /* tp_weaklist */
+ 0, /* tp_del */
};
/*****************************************************************************/
@@ -323,22 +391,6 @@
}
-static PyObject *M_Ipo_Recalc( PyObject * self, PyObject * args )
-{
- void testhandles_ipocurve( IpoCurve * icu );
- PyObject *a;
- IpoCurve *icu;
- if( !PyArg_ParseTuple( args, "O", &a ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected ipo argument)" ) );
- icu = IpoCurve_FromPyObject( a );
- testhandles_ipocurve( icu );
-
- Py_INCREF( Py_None );
- return Py_None;
-
-}
-
/*****************************************************************************/
/* Function: Ipo_Init */
/*****************************************************************************/
@@ -348,6 +400,13 @@
Ipo_Type.ob_type = &PyType_Type;
+ /*
+ * These are necessary for tp_getset
+ */
+
+ Ipo_Type.tp_getattro = &PyObject_GenericGetAttr;
+ Ipo_Type.tp_setattro = &PyObject_GenericSetAttr;
+
submodule = Py_InitModule3( "Blender.Ipo", M_Ipo_methods, M_Ipo_doc );
return ( submodule );
@@ -395,29 +454,19 @@
}
-static PyObject *Ipo_setBlocktype( BPy_Ipo * self, PyObject * args )
+static PyObject *Ipo_getRctf( BPy_Ipo * self )
{
- int blocktype = 0;
-
- 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;
-}
+ PyObject *list = PyList_New( 4 );
+ if (!list)
+ return EXPP_ReturnPyObjError( PyExc_MemoryError,
+ "couldn't create PyList object" );
-static PyObject *Ipo_getRctf( BPy_Ipo * self )
-{
- PyObject *l = PyList_New( 0 );
- PyList_Append( l, PyFloat_FromDouble( self->ipo->cur.xmin ) );
- PyList_Append( l, PyFloat_FromDouble( self->ipo->cur.xmax ) );
- PyList_Append( l, PyFloat_FromDouble( self->ipo->cur.ymin ) );
- PyList_Append( l, PyFloat_FromDouble( self->ipo->cur.ymax ) );
- return l;
+ PyList_SET_ITEM( list, 0, PyFloat_FromDouble( self->ipo->cur.xmin ) );
+ PyList_SET_ITEM( list, 1, PyFloat_FromDouble( self->ipo->cur.xmax ) );
+ PyList_SET_ITEM( list, 2, PyFloat_FromDouble( self->ipo->cur.ymin ) );
+ PyList_SET_ITEM( list, 3, PyFloat_FromDouble( self->ipo->cur.ymax ) );
+ return list;
}
@@ -438,19 +487,6 @@
return Py_None;
}
-static PyObject *Ipo_getNcurves( BPy_Ipo * self )
-{
- 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
*/
@@ -826,55 +862,54 @@
/*
- 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:
ipo = Blender.Ipo.New('Object','ObIpo')
- cu = ipo.addCurve('LocX')
+ cu = ipo.append('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;
- int ipofound = 0;
char *cur_name = 0; /* input arg: curve name */
Ipo *ipo = 0;
IpoCurve *icu = 0;
Link *link;
+ static int depcount=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;
while( link ) {
ipo = ( Ipo * ) link;
if( ipo == self->ipo ) {
- ipofound = 1;
break;
}
link = link->next;
}
- if( ipo && ipofound ) {
- /* ok. continue */
- } else { /* runtime error here: our ipo not found */
- return ( EXPP_ReturnPyObjError
- ( PyExc_RuntimeError, "Ipo not found" ) );
- }
+ /*
+ * if link is NULL, the IPO was deleted
+ */
+ if ( !link )
+ return EXPP_ReturnPyObjError ( 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.
*/
+
switch ( ipo->blocktype ) {
case ID_OB:
ok = Ipo_obIcuName( cur_name, ¶m );
@@ -917,12 +952,33 @@
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 ) {
+#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;
+ }
+
+
/* ask blender to create the new ipo curve */
icu = get_ipocurve( NULL, ipo->blocktype, param, self->ipo );
- if( icu == 0 ) /* could not create curve */
- return EXPP_ReturnPyObjError
- ( PyExc_RuntimeError,
+ if( !icu ) /* could not create curve */
+ return EXPP_ReturnPyObjError ( PyExc_RuntimeError,
"blender could not create ipo curve" );
allspace( REMAKEIPO, 0 );
@@ -932,147 +988,375 @@
return IpoCurve_CreatePyObject( icu );
}
-/*
- Function: Ipo_delCurve
- Bpy: Blender.Ipo.delCurve(curtype)
-
- delete an existing curve from IPO.
- example:
- ipo = Blender.Ipo.New('Object','ObIpo')
- cu = ipo.delCurve('LocX')
-*/
-
-static PyObject *Ipo_delCurve( BPy_Ipo * self, PyObject * args )
+static PyObject *Ipo_getCurves( BPy_Ipo * self )
{
+ PyObject *list;
IpoCurve *icu;
- char *strname;
+ int i = 0;
- if( !PyArg_ParseTuple( args, "s", &strname ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "string argument" ) );
+ 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
+ */
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 );
- del_ipoCurve( icu );
- Py_INCREF( Py_None );
- return Py_None;
+ PyObject *obj = IpoCurve_CreatePyObject( icu );
+ if (!obj) {
+ Py_DECREF ( list );
+ return NULL;
}
+ PyList_SET_ITEM( list, i, obj );
+ i++;
}
-
- return ( EXPP_ReturnPyObjError
- ( PyExc_RuntimeError, "IpoCurve not found" ) );
+ return list;
}
+/*****************************************************************************/
+/* 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;
+}
-static PyObject *Ipo_getCurve( BPy_Ipo * self, PyObject * args )
+/*****************************************************************************/
+/* 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 )
{
- char *str, *str1;
IpoCurve *icu = 0;
+ char *str, *str1;
- if( !PyArg_ParseTuple( args, "s", &str ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected string argument" ) );
+ /* 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 );
+#if 1
for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
str1 = getIpoCurveName( icu );
if( !strcmp( str1, str ) )
return IpoCurve_CreatePyObject( icu );
}
-
- Py_INCREF( Py_None );
- return 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 );
+ }
+ }
+#endif
+ return EXPP_incr_ret ( Py_None );
}
-static PyObject *Ipo_getCurves( BPy_Ipo * self )
+/*****************************************************************************/
+/* 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 )
{
- PyObject *attr = PyList_New( 0 );
+ char * strname = PyString_AsString ( key );
IpoCurve *icu;
- for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
- PyList_Append( attr, IpoCurve_CreatePyObject( icu ) );
- }
- return attr;
-}
+ /*
+ * if PyString_AsString returns NULL. key wasn't a string
+ */
-static PyObject *Ipo_getNBezPoints( BPy_Ipo * self, PyObject * args )
-{
- 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;
+ if ( !strname )
+ return -1;
- }
- return ( PyInt_FromLong( icu->totvert ) );
-}
+ /*
+ * currently only deletion is supported, so if we get an
+ * object it's an error
+ */
-static PyObject *Ipo_DeleteBezPoints( BPy_Ipo * self, PyObject * args )
-{
- 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;
+ if ( value )
+ return EXPP_ReturnIntError ( PyExc_NotImplementedError,
+ "cannot set IPO curves" );
+ /*
+ * 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;
+ }
}
- icu->totvert--;
- return ( PyInt_FromLong( icu->totvert ) );
-}
+ /*
+ * no match; error
+ */
-/*
- * Ipo_getCurveBP()
- * this method is UNSUPPORTED.
- * Calling this method throws a TypeError 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.
- */
+ return EXPP_ReturnIntError ( PyExc_RuntimeError,
+ "IPO curve not found" );
+}
-static PyObject *Ipo_getCurveBP( BPy_Ipo * self, PyObject * args )
+/*****************************************************************************/
+/* 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 );
+}
- /* 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;
+/*****************************************************************************/
+/* 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( !PyArg_ParseTuple( args, "i", &num ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected int argument" ) );
- icu = self->ipo->curve.first;
- if( !icu )
+ 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 );
+}
+
+/* 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;
+#if 0
+ pyipo->channel = channel;
+#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 )
+{
+ return Ipo_CreatePyObjectChannel ( ipo, 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 );
+}
+
+/*****************************************************************************/
+/* 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)
+ */
+
+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 );
+}
+
+/*
+ * Return next IPO curve. When the end of the list is reached,
+ * throw an exception.
+ */
+
+static
+PyObject *Ipo_nextIter( 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
+ */
+
+ for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
+ if ( icu->adrcode < minadr && icu->adrcode > self->iter ) {
+ minadr = icu->adrcode;
+ ptr = icu;
+ }
+ }
+
+ /*
+ * 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;
+ }
+#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;
+#endif
+ return obj;
+}
+
+/* #####DEPRECATED###### */
+
+#if BLENDER_VERSION < 243
+
+/*
+ * 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.
+ */
+
+static PyObject *Ipo_getCurveBP( BPy_Ipo * self, PyObject * args )
+{
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "bpoint ipos are not supported" );
+}
+
+/*
+ * 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 )
+{
+ 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++ ) {
@@ -1082,25 +1366,130 @@
icu = icu->next;
}
- ptrbpoint = icu->bp;
- if( !ptrbpoint )
- return EXPP_ReturnPyObjError( PyExc_TypeError,
- "No base point" );
+ icu->totvert--;
+ return ( PyInt_FromLong( icu->totvert ) );
+#endif
+}
- l = PyList_New( 0 );
- for( i = 0; i < 4; i++ )
- PyList_Append( l, PyFloat_FromDouble( ptrbpoint->vec[i] ) );
- return l;
+static PyObject *Ipo_getNcurves( BPy_Ipo * self )
+{
+#if BLENDER_VERSION < 241
+ IpoCurve *icu;
+ int i = 0;
+ static int depcount = 2;
+
+ 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 ) {
+ i++;
+ }
+
+ 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
+}
+
+static PyObject *Ipo_delCurve( BPy_Ipo * self, PyObject * args )
+{
+#if BLENDER_VERSION < 241
+ static char depcount=2;
+ char *str;
+ int ok;
+
+ if ( depcount ) {
+ printf ("Ipo.delCurve() is deprecated by the del operator.\n");
+ printf (" This method will be removed after version 2.40.\n");
+ depcount--;
+ }
+
+ 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
+}
+
+static PyObject *Ipo_getCurve( BPy_Ipo * self, PyObject * args )
+{
+#if BLENDER_VERSION < 241
+ static char depcount=2;
+ char *str, *str1;
+ IpoCurve *icu = 0;
+
+ 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( !PyArg_ParseTuple( args, "s", &str ) )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_TypeError, "expected string argument" ) );
+
+ for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
+ str1 = getIpoCurveName( icu );
+ if( !strcmp( str1, str ) )
+ return IpoCurve_CreatePyObject( icu );
+ }
+
+ 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( !PyArg_ParseTuple( args, "ii", &num, &pos ) )
return ( EXPP_ReturnPyObjError
( PyExc_TypeError, "expected int argument" ) );
@@ -1129,16 +1518,28 @@
PyFloat_FromDouble( ptrbt->
vec[i][j] ) );
return l;
+#else
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "replaced by \"ipo[][]\"" );
+#endif
}
-
static PyObject *Ipo_setCurveBeztriple( BPy_Ipo * self, PyObject * args )
{
+#if BLENDER_VERSION < 241
+ static int depcount=2;
struct BezTriple *ptrbt;
int num = 0, pos, i;
IpoCurve *icu;
PyObject *listargs = 0;
+ 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--;
+ }
+
if( !PyArg_ParseTuple( args, "iiO", &num, &pos, &listargs ) )
return ( EXPP_ReturnPyObjError
( PyExc_TypeError,
@@ -1172,49 +1573,115 @@
Py_INCREF( Py_None );
return Py_None;
+#else
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "replaced by \"ipo[][]\"" );
+#endif
}
-
-static PyObject *Ipo_EvaluateCurveOn( BPy_Ipo * self, PyObject * args )
+static PyObject *Ipo_getNBezPoints( BPy_Ipo * self, PyObject * args )
{
- float eval_icu( IpoCurve * icu, float ipotime );
+#if BLENDER_VERSION < 241
+ static int depcount=2;
+ int num = 0, i = 0;
+ IpoCurve *icu = 0;
- int num = 0, i;
- IpoCurve *icu;
- float time = 0;
+ 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--;
+ }
- if( !PyArg_ParseTuple( args, "if", &num, &time ) )
+ 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 ipo number" ) );
+ ( PyExc_TypeError, "Bad curve number" ) );
icu = icu->next;
}
- return PyFloat_FromDouble( eval_icu( icu, time ) );
+ return ( PyInt_FromLong( icu->totvert ) );
+#else
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "replaced by \"len(ipo[])\"" );
+#endif
}
+static PyObject *Ipo_setBlocktype( BPy_Ipo * self, PyObject * args )
+{
+#if BLENDER_VERSION < 241
+ static int depcount=2;
+ int blocktype = 0;
+
+ if ( depcount ) {
+ printf ("Ipo.setBlocktype() is deprecated.\n");
+ printf (" This method will be removed after version 2.40.\n");
+ depcount--;
+ }
+
+ 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--;
+ }
+
+ for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
+ PyList_Append( attr, IpoCurve_CreatePyObject( icu ) );
+ }
+ 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--;
+ }
+
icu = self->ipo->curve.first;
if( !icu )
return ( EXPP_ReturnPyObjError
( PyExc_TypeError, "No IPO curve" ) );
- if( PyNumber_Check( PySequence_GetItem( args, 0 ) ) ) // args is an integer
+ if( PyNumber_Check( PySequence_GetItem( args, 0 ) ) )
{
if( !PyArg_ParseTuple( args, "i", &numcurve ) )
return ( EXPP_ReturnPyObjError
@@ -1227,10 +1694,7 @@
"Bad ipo number" ) );
icu = icu->next;
}
- }
-
- else // args is a string
- {
+ } else { // args is a string
if( !PyArg_ParseTuple( args, "s", &stringname ) )
return ( EXPP_ReturnPyObjError
( PyExc_TypeError,
@@ -1247,87 +1711,81 @@
return PyFloat_FromDouble( icu->curval );
Py_INCREF( Py_None );
return Py_None;
+#else
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "replaced by \"ipo[].evaluate(curtime)\"" );
+#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_EvaluateCurveOn( BPy_Ipo * self, PyObject * args )
{
- PyObject_DEL( self );
-}
+#if BLENDER_VERSION < 241
+ static int depcount=2;
+ float eval_icu( IpoCurve * icu, float ipotime );
+ int num = 0, i;
+ IpoCurve *icu;
+ float time = 0;
-/*****************************************************************************/
-/* 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 );
-}
+ if ( depcount ) {
+ printf ("Ipo.EvaluateCurveOn() is deprecated by ipo[].evaluate().\n");
+ printf (" This method will be removed after version 2.40.\n");
+ depcount--;
+ }
-/*****************************************************************************/
-/* 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 */
-}
+ if( !PyArg_ParseTuple( args, "if", &num, &time ) )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_TypeError, "expected int argument" ) );
-/*****************************************************************************/
-/* 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 );
-}
+ icu = self->ipo->curve.first;
+ if( !icu )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_TypeError, "No IPO curve" ) );
-/* Three Python Ipo_Type helper functions needed by the Object module: */
+ for( i = 0; i < num; i++ ) {
+ if( !icu )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_TypeError, "Bad ipo number" ) );
+ icu = icu->next;
-/*****************************************************************************/
-/* 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;
+ }
+ return PyFloat_FromDouble( eval_icu( icu, time ) );
+#else
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "replaced by \"ipo[].evaluate()\"" );
+#endif
}
-/*****************************************************************************/
-/* 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 )
+static PyObject *M_Ipo_Recalc( PyObject * self, PyObject * args )
{
- return ( pyobj->ob_type == &Ipo_Type );
-}
+#if BLENDER_VERSION < 241
+ static int depcount=2;
+ void testhandles_ipocurve( IpoCurve * icu );
+ PyObject *a;
+ IpoCurve *icu;
-/*****************************************************************************/
-/* 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 ( depcount ) {
+ printf ("Ipo.Recalc() is deprecated by the Ipocurve.recalc method.\n");
+ printf (" This method will be removed after version 2.40.\n");
+ depcount--;
+ }
+
+ 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)" ) );
+
+ icu = IpoCurve_FromPyObject( a );
+ testhandles_ipocurve( icu );
+
+ Py_INCREF( Py_None );
+ return Py_None;
+#else
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "replaced by \"ipo.curves\"" );
+#endif
}
+
+#endif
+
diff -u -r1.13 Ipo.h
--- source/blender/python/api2_2x/Ipo.h 7 Oct 2004 19:25:39 -0000 1.13
+++ source/blender/python/api2_2x/Ipo.h 6 Jul 2005 06:18:19 -0000
@@ -35,6 +35,7 @@
#include <Python.h>
#include <DNA_ipo_types.h>
+#include <Ipocurve.h>
/*****************************************************************************/
/* Python BPy_Ipo structure definition: */
@@ -42,12 +43,16 @@
typedef struct {
PyObject_HEAD /* required macro */
Ipo * ipo;
+#if 0
+ IpoCurve *iter; /* pointer used by iterator */
+#else
+ int iter; /* pointer used by iterator */
+#endif
} BPy_Ipo;
extern PyTypeObject Ipo_Type;
#define BPy_Ipo_Check(v) ((v)->ob_type == &Ipo_Type) /* for type checking */
-
/*
* prototypes
File Metadata
Details
Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
7e/5f/08f1322793c6be1bd80bb7f7a8c6
Event Timeline
Log In to Comment