Page MenuHome

stage2-patch-IpoCurNurb.txt-v2

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

stage2-patch-IpoCurNurb.txt-v2

--- source/blender/python/SConscript 2005-06-28 17:17:11.000000000 -0000
+++ source/blender/python/SConscript 2005-07-03 12:06:02.000000000 -0700
@@ -50,6 +50,7 @@
'api2_2x/Noise.c',
'api2_2x/charRGBA.c',
'api2_2x/constant.c',
+ 'api2_2x/curveutils.c',
'api2_2x/euler.c',
'api2_2x/gen_utils.c',
'api2_2x/logic.c',
--- source/blender/python/api2_2x/BezTriple.c 2005-07-03 11:35:57.000000000 -0700
+++ source/blender/python/api2_2x/BezTriple.c 2005-07-03 12:01:16.000000000 -0700
@@ -25,7 +25,7 @@
* This is a new part of Blender.
*
* Contributor(s): Jacques Guignot RIP 2005,
- * Stephen Swaney
+ * Stephen Swaney, Ken Hughes
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
@@ -42,46 +42,45 @@
#include <DNA_ipo_types.h>
#include <MEM_guardedalloc.h>
+#include "CurNurb.h"
+#include "Ipocurve.h"
#include "constant.h"
#include "gen_utils.h"
-
-/***************************************************************************
- Python API function prototypes for the BezTriple module.
-***************************************************************************/
+/*****************************************************************************/
+/* Python API function prototypes for the BezTriple module. */
+/*****************************************************************************/
static PyObject *M_BezTriple_New( PyObject * self, PyObject * args );
static PyObject *M_BezTriple_Get( PyObject * self, PyObject * args );
-/*************************************
- Doc strings for the BezTriple module
-*************************************/
+/****************************************/
+/* Doc strings for the BezTriple module */
+/****************************************/
static char M_BezTriple_doc[] = "The Blender BezTriple module\n";
-/****************************************************************************
- Python BPy_BezTriple instance methods declarations:
-****************************************************************************/
+/*****************************************************************************/
+/* Python BPy_BezTriple instance methods declarations: */
+/*****************************************************************************/
static PyObject *BezTriple_setPoints( BPy_BezTriple * self, PyObject * args );
static PyObject *BezTriple_getPoints( BPy_BezTriple * self );
static PyObject *BezTriple_getTriple( BPy_BezTriple * self );
-/****************************************************************************
- Python BezTriple_Type callback function prototypes:
-*****************************************************************************/
+/*****************************************************************************/
+/* Python BezTriple_Type callback function prototypes: */
+/*****************************************************************************/
static void BezTripleDeAlloc( BPy_BezTriple * self );
static int BezTripleSetAttr( BPy_BezTriple * self, char *name, PyObject * v );
static PyObject *BezTripleGetAttr( BPy_BezTriple * self, char *name );
static PyObject *BezTripleRepr( BPy_BezTriple * self );
static PyObject *BezTriple_Str( BPy_BezTriple * self );
-/****************************************************************************
- Python method structure definition for Blender.BezTriple module:
-****************************************************************************/
+/*****************************************************************************/
+/* Python method structure definition for Blender.BezTriple module: */
+/*****************************************************************************/
struct PyMethodDef M_BezTriple_methods[] = {
- {"New", ( PyCFunction ) M_BezTriple_New, METH_VARARGS | METH_KEYWORDS,
- 0},
-/* {"New", ( PyCFunction ) M_BezTriple_New, METH_O, 0}, */
+ {"New", ( PyCFunction ) M_BezTriple_New, METH_VARARGS | METH_KEYWORDS, 0},
{"Get", M_BezTriple_Get, METH_VARARGS, 0},
{"get", M_BezTriple_Get, METH_VARARGS, 0},
{NULL, NULL, 0, NULL}
@@ -101,13 +100,12 @@
{NULL, NULL, 0, NULL}
};
-
/*****************************************************************************/
/* Python BezTriple_Type structure definition: */
/*****************************************************************************/
PyTypeObject BezTriple_Type = {
- PyObject_HEAD_INIT( NULL ) /* required python macro */
- 0, /* ob_size */
+ PyObject_HEAD_INIT( NULL ) /* required python macro */
+ 0, /* ob_size */
"BezTriple", /* tp_name */
sizeof( BPy_BezTriple ), /* tp_basicsize */
0, /* tp_itemsize */
@@ -136,7 +134,6 @@
0
};
-
/****************************************************************************
Function: M_BezTriple_New
Python equivalent: Blender.BezTriple.New
@@ -159,106 +156,111 @@
return newBezTriple( in_args );
}
-/****************************************************************************
- Function: M_BezTriple_Get
- Python equivalent: Blender.BezTriple.Get
- Description: Receives a string and returns the ipo data obj
- whose name matches the string. If no argument is
- passed in, a list of all ipo data names in the
- current scene is returned.
-****************************************************************************/
+/*****************************************************************************/
+/* Function: M_BezTriple_Get */
+/* Python equivalent: Blender.BezTriple.Get */
+/* Description: Receives a string and returns the ipo data obj */
+/* whose name matches the string. If no argument is */
+/* passed in, a list of all ipo data names in the */
+/* current scene is returned. */
+/*****************************************************************************/
static PyObject *M_BezTriple_Get( PyObject * self, PyObject * args )
{
return 0;
}
-/****************************************************************************
- Function: BezTripleDeAlloc
- Description: This is a callback function for the BPy_BezTriple type. It is
- the destructor function.
-****************************************************************************/
+/*****************************************************************************/
+/* Function: BezTripleDeAlloc */
+/* Description: This is a callback function for the BPy_BezTriple type. It */
+/* is the destructor function. */
+/*****************************************************************************/
static void BezTripleDeAlloc( BPy_BezTriple * self )
{
-
- if( self->own_memory)
+ if( self->own_memory )
MEM_freeN( self->beztriple );
PyObject_DEL( self );
}
-static PyObject *BezTriple_getPoints( BPy_BezTriple * self )
-{
- struct BezTriple *bezt = self->beztriple;
- PyObject *l = PyList_New( 0 );
- int i;
- for( i = 0; i < 2; i++ ) {
- PyList_Append( l, PyFloat_FromDouble( bezt->vec[1][i] ) );
- }
- return l;
-}
-
+/*****************************************************************************/
+/* Python BPy_BezTriple instance methods */
+/*****************************************************************************/
-/*
- * BezTriple_getTriple
- *
- * get the coordinate data for a BezTriple.
- * returns a list of 3 points.
- * list order is handle1, knot, handle2.
- * each point consists of a list of x,y,z float values.
+/*
+ * Function: BezTriple_getPoints()
+ * Bpy: Blender.BezTriple.getPoints()
+ *
+ * return a list of x,y for knot point
+ *
+ * example:
+ * ipo = Blender.Ipo.New('Object','ObIpo')
+ * cu = ipo.getCurve('LocX')
+ * p = cu.getPoints()[0]
+ * [x,y] = p.getPoints()
*/
-static PyObject *BezTriple_getTriple( BPy_BezTriple * self )
+static PyObject *BezTriple_getPoints( BPy_BezTriple * self )
{
- int i;
- struct BezTriple *bezt = self->beztriple;
- PyObject *retlist = PyList_New( 0 );
- PyObject *point;
+ struct BezTriple *bezt;
+ PyObject *l;
- for( i = 0; i < 3; i++ ) {
- point = Py_BuildValue( "[fff]",
- bezt->vec[i][0],
- bezt->vec[i][1], bezt->vec[i][2] );
+ bezt = BezTriple_data_ok( self );
+ if ( !bezt )
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "BezTriple no longer valid" );
- PyList_Append( retlist, point );
- }
+ l = PyList_New( 2 );
+ if ( !l )
+ return EXPP_ReturnPyObjError( PyExc_MemoryError,
+ "couldn't create PyList" );
- return retlist;
+ PyList_SET_ITEM( l, 0, PyFloat_FromDouble( bezt->vec[1][0] ) );
+ PyList_SET_ITEM( l, 1, PyFloat_FromDouble( bezt->vec[1][1] ) );
+
+ return l;
}
+/*
+ * Function: BezTriple_setPoints()
+ * Bpy: Blender.BezTriple.setPoints([x,y])
+ *
+ * sets knot point to (x,y)
+ *
+ * example:
+ * ipo = Blender.Ipo.New('Object','ObIpo')
+ * cu = ipo.getCurve('LocX')
+ * p = cu.getPoints()[0]
+ * p.setPoints([1,2])
+ */
static PyObject *BezTriple_setPoints( BPy_BezTriple * self, PyObject * args )
{
-
int i;
- struct BezTriple *bezt = self->beztriple;
- PyObject *popo = 0;
+ struct BezTriple *bezt;
+ PyObject *obj = NULL;
- if( !PyArg_ParseTuple( args, "O", &popo ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected sequence argument" ) );
-
- if( PySequence_Check( popo ) == 0 ) {
- puts( "error in BezTriple_setPoints - expected sequence" );
- Py_INCREF( Py_None );
- return Py_None;
- }
-
- {
- /*
- some debug stuff
- this will become an overloaded args check
- */
- int size = PySequence_Size( popo );
- printf( "\n dbg: sequence size is %d\n", size );
- }
+ bezt = BezTriple_data_ok( self );
+ if ( !bezt )
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "BezTriple no longer valid" );
+
+ /* only accept list of two numbers */
+
+ if ( !PyArg_ParseTuple( args, "O", &obj ) ||
+ !PyList_Check( obj ) || PySequence_Size ( obj ) != 2 )
+ return EXPP_ReturnPyObjError ( PyExc_TypeError,
+ "expected list of two floats" );
+
+ if ( !PyNumber_Check ( PySequence_Fast_GET_ITEM( obj, 0 ) ) ||
+ !PyNumber_Check ( PySequence_Fast_GET_ITEM( obj, 0 ) ) )
+ return EXPP_ReturnPyObjError ( PyExc_TypeError,
+ "expected list of two floats" );
- for( i = 0; i < 2; i++ ) {
- PyObject *o = PySequence_GetItem( popo, i );
- if( !o )
- printf( "\n bad o. o no!\n" );
+ /* set x and y values of knot, then "futz" with handles */
- /* bezt->vec[1][i] = PyFloat_AsDouble (PyTuple_GetItem (popo, i)); */
- bezt->vec[1][i] = PyFloat_AsDouble( o );
+ for( i = 0; i < 2; i++ ) {
+ bezt->vec[1][i] = PyFloat_AsDouble(
+ PySequence_Fast_GET_ITEM( obj, i ) );
bezt->vec[0][i] = bezt->vec[1][i] - 1;
bezt->vec[2][i] = bezt->vec[1][i] + 1;
}
@@ -270,24 +272,70 @@
if( bezt->vec[2][0] < bezt->vec[1][0] )
bezt->vec[2][0] = bezt->vec[1][0];
- Py_INCREF( Py_None );
- return Py_None;
+ return EXPP_incr_ret( Py_None );
}
+/*
+ * Function: BezTriple_getTriple()
+ * Bpy: Blender.BezTriple.getTriple()
+ *
+ * get the coordinate data for a BezTriple.
+ * returns a list of 3 [x,y,z] points.
+ * list order is handle1, knot, handle2.
+ *
+ * example:
+ * ipo = Blender.Ipo.New('Object','ObIpo')
+ * cu = ipo.getCurve('LocX')
+ * p = cu.getPoints()[0]
+ * [h1,knot,h2] = p.getTriple()
+ */
+
+static PyObject *BezTriple_getTriple( BPy_BezTriple * self )
+{
+ int i;
+ struct BezTriple *bezt;
+ PyObject *retlist;
+
+ bezt = BezTriple_data_ok( self );
+ if ( !bezt )
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "BezTriple no longer valid" );
+
+ retlist = PyList_New( 3 );
+ if ( !retlist )
+ return EXPP_ReturnPyObjError( PyExc_MemoryError,
+ "couldn't create PyList" );
+
+ for( i = 0; i < 3; i++ ) {
+ PyObject *point = Py_BuildValue( "[fff]", bezt->vec[i][0],
+ bezt->vec[i][1], bezt->vec[i][2] );
+
+ PyList_SET_ITEM( retlist, i, point );
+ }
+
+ return retlist;
+}
/*****************************************************************************/
-/* Function: BezTripleGetAttr */
+/* Function: BezTripleGetAttr */
/* Description: This is a callback function for the BPy_BezTriple type. It */
-/* taccesses BPy_BezTriple "member variables" and methods. */
+/* accesses BPy_BezTriple "member variables" and methods. */
/*****************************************************************************/
static PyObject *BezTripleGetAttr( BPy_BezTriple * self, char *name )
{
+ BezTriple *bezt;
+
+ bezt = BezTriple_data_ok( self );
+ if ( !bezt )
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "BezTriple no longer valid" );
+
if( strcmp( name, "pt" ) == 0 )
return BezTriple_getPoints( self );
else if( strcmp( name, "vec" ) == 0 )
return BezTriple_getTriple( self );
else if( strcmp( name, "tilt" ) == 0 )
- return PyFloat_FromDouble(self->beztriple->alfa);
+ return PyFloat_FromDouble( bezt->alfa );
else if( strcmp( name, "__members__" ) == 0 )
return Py_BuildValue( "[s,s,s]", "pt", "vec", "tilt" );
@@ -296,119 +344,101 @@
}
/*****************************************************************************/
-/* Function: BezTripleSetAttr */
-/* Description: This is a callback function for the BPy_BezTriple type. It */
-/* sets BezTriple Data attributes (member variables). */
-/*****************************************************************************/
-static int BezTripleSetAttr( BPy_BezTriple * self, char *name, PyObject * value )
-{
-#if 0
- /*
- this does not work at the moment: Wed Apr 7 2004
- when the necessary code to make pt act like a sequence is
- available, it will be reenabled
- */
-
- if( strcmp( name, "pt" ) == 0 )
- BezTriple_setPoints( self, value );
+/* Function: BezTripleSetAttr */
+/* Description: This is a callback function for the BPy_BezTriple type. It */
+/* sets BezTriple Data attributes (member variables). */
+/*****************************************************************************/
+static int BezTripleSetAttr( BPy_BezTriple * self, char *name,
+ PyObject * value )
+{
+ PyObject *valtuple;
+ PyObject *error = NULL;
+ BezTriple *bezt;
+
+ bezt = BezTriple_data_ok( self );
+ if ( !bezt )
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "BezTriple no longer valid" );
- return 0; /* normal exit */
-#endif
if( strcmp( name, "tilt" ) == 0 ) {
if (!PyFloat_Check( value ) )
return EXPP_ReturnIntError( PyExc_TypeError, "expected a float" );
- self->beztriple->alfa = (float)PyFloat_AsDouble( value );
+ bezt->alfa = (float)PyFloat_AsDouble( value );
return 0;
}
- return ( EXPP_ReturnIntError( PyExc_AttributeError,
- "cannot set a read-only attribute" ) );
-}
+ /* methods need a tuple object */
-/*****************************************************************************/
-/* Function: BezTripleRepr */
-/* Description: This is a callback function for the BPy_BezTriple type. It */
-/* builds a meaninful string to represent BezTriple objects. */
-/*****************************************************************************/
-static PyObject *BezTripleRepr( BPy_BezTriple * self )
-{
- /* float vec[3][3];
- float alfa;
- short s[3][2];
- short h1, h2;
- char f1, f2, f3, hide;
- */
- char str[1000];
- sprintf( str,
- "BezTriple %f %f %f %f %f %f %f %f %f %f\n %d %d %d %d %d %d %d %d %d %d %d %d\n",
- self->beztriple->vec[0][0], self->beztriple->vec[0][1],
- self->beztriple->vec[0][2], self->beztriple->vec[1][0],
- self->beztriple->vec[1][1], self->beztriple->vec[1][2],
- self->beztriple->vec[2][0], self->beztriple->vec[2][1],
- self->beztriple->vec[2][2], self->beztriple->alfa,
- self->beztriple->s[0][0], self->beztriple->s[0][1],
- self->beztriple->s[1][0], self->beztriple->s[1][1],
- self->beztriple->s[2][0], self->beztriple->s[1][1],
- self->beztriple->h1, self->beztriple->h2, self->beztriple->f1,
- self->beztriple->f2, self->beztriple->f3,
- self->beztriple->hide );
- return PyString_FromString( str );
-}
-
-
-/*
- BezTriple_Str
- display object as string.
- equivalent to python str(o)
-*/
+ valtuple = Py_BuildValue( "(O)", value );
+ if( !valtuple )
+ return EXPP_ReturnIntError( PyExc_MemoryError,
+ "couldn't create PyTuple" );
-static PyObject *BezTriple_Str( BPy_BezTriple * self )
-{
- BezTriple *p = self->beztriple;
+ /* process attributes */
-/* fixme: */
- return PyString_FromFormat(
- "BezTriple (%f %f %f) (%f %f %f) (%f %f %f) alpha %f\n (%d %d) (%d %d) (%d %d) h1:%d h2:%d f1:%d f2:%d f3:%d hide:%d",
- p->vec[0][0], p->vec[0][1], p->vec[0][2],
- p->vec[1][0], p->vec[1][1], p->vec[1][2],
- p->vec[2][0], p->vec[2][1], p->vec[2][2],
- p->alfa,
- p->s[0][0], p->s[0][1],
- p->s[1][0], p->s[1][1],
- p->s[2][0], p->s[1][1],
- p->h1, p->h2, p->f1,
- p->f2, p->f3,
- p->hide );
+ if( strcmp( name, "pt" ) == 0 )
+ error = BezTriple_setPoints( self, valtuple );
+ else { /* no match: signal attribute exception */
+ Py_DECREF( valtuple );
+ return EXPP_ReturnIntError
+ ( PyExc_KeyError, "attribute not found" );
+ }
+ /* clean up */
+
+ Py_DECREF( valtuple );
+ if ( error != Py_None ) return -1;
+ Py_DECREF( Py_None );
+ return 0;
}
+/*****************************************************************************/
+/* Function: BezTripleRepr */
+/* Description: This is a callback function for the BPy_BezTriple type. It */
+/* builds a meaningful string to represent BezTriple objects. */
+/*****************************************************************************/
-/*
- BezTriple_Init
-*/
+/*
+ * Meaning of fields in bezTriple
+ *
+ * handles h1, h2:
+ * 0=HD_FREE(black), 1=HD_AUTO(yellow), 2=HD_VECT(green), 3=HD_ALIGN(red)
+ * selected flags f1, f2, f3:
+ * 0 = false, 1 = true
+ * if f2 true, then f1 and and f3 also true
+ * hide:
+ * always seems to be 2 (IPO_BEZ)?
+ */
-PyObject *BezTriple_Init( void )
+static PyObject *BezTripleRepr( BPy_BezTriple * self )
{
- PyObject *submodule;
-
- BezTriple_Type.ob_type = &PyType_Type;
+ char str[1000];
+ BezTriple *bezt;
- submodule = Py_InitModule3( "Blender.BezTriple",
- M_BezTriple_methods,
- M_BezTriple_doc );
+ bezt = BezTriple_data_ok( self );
+ if ( !bezt )
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "BezTriple no longer valid" );
- return submodule;
+ sprintf( str,
+ "[BezTriple [%f,%f,%f] [%f,%f,%f] [%f,%f,%f] [%d,%d] [%d,%d,%d]]\n",
+ bezt->vec[0][0], bezt->vec[0][1], bezt->vec[0][2],
+ bezt->vec[1][0], bezt->vec[1][1], bezt->vec[1][2],
+ bezt->vec[2][0], bezt->vec[2][1], bezt->vec[2][2],
+ bezt->h1, bezt->h2,
+ bezt->f1, bezt->f2, bezt->f3 );
+ return PyString_FromString( str );
}
-/* Three Python BezTriple_Type helper functions needed by the Object module: */
+/* Three Python BezTriple_Type helper functions needed by the Object module */
-/****************************************************************************
- Function: BezTriple_CreatePyObject
- Description: This function will create a new BPy_BezTriple from an existing
- Blender ipo structure.
-****************************************************************************/
-PyObject *BezTriple_CreatePyObject( BezTriple * bzt )
+/*****************************************************************************/
+/* Function: BezTriple_CreatePyObject */
+/* Description: This function will create a new BPy_BezTriple from an existing */
+/* Blender ipo structure. */
+/*****************************************************************************/
+PyObject *BezTriple_CreatePyObject( PyObject * obj, int index )
{
BPy_BezTriple *pybeztriple;
@@ -419,12 +449,15 @@
return EXPP_ReturnPyObjError( PyExc_MemoryError,
"couldn't create BPy_BezTriple object" );
- pybeztriple->beztriple = bzt;
+
+ pybeztriple->own_memory = 0; /* we don't own it. */
+
+ pybeztriple->parent = obj;
+ pybeztriple->index = index;
return ( PyObject * ) pybeztriple;
}
-
/*****************************************************************************/
/* Function: BezTriple_CheckPyObject */
/* Description: This function returns true when the given PyObject is of the */
@@ -436,7 +469,7 @@
}
/*****************************************************************************/
-/* Function: BezTriple_FromPyObject */
+/* Function: BezTriple_FromPyObject */
/* Description: This function returns the Blender beztriple from the given */
/* PyObject. */
/*****************************************************************************/
@@ -445,6 +478,22 @@
return ( ( BPy_BezTriple * ) pyobj )->beztriple;
}
+/*****************************************************************************/
+/* Function: BezTriple_Init */
+/*****************************************************************************/
+
+PyObject *BezTriple_Init( void )
+{
+ PyObject *submodule;
+
+ BezTriple_Type.ob_type = &PyType_Type;
+
+ submodule = Py_InitModule3( "Blender.BezTriple",
+ M_BezTriple_methods,
+ M_BezTriple_doc );
+
+ return submodule;
+}
/*
Create a new BezTriple
@@ -455,6 +504,7 @@
{
BPy_BezTriple *pybez = NULL;
int length;
+ int i;
float numbuf[9];
/*
check input args:
@@ -473,37 +523,35 @@
if( length != 9 && length != 3 )
return EXPP_ReturnPyObjError( PyExc_AttributeError,
"wrong number of points");
- {
- int i;
- PyObject *pyo;
- for( i = 0; i < length; i++) {
- pyo = PySequence_GetItem( args, i );
- if( !pyo )
- return EXPP_ReturnPyObjError
- ( PyExc_AttributeError,
- "wrong number of points");
- if( !PyFloat_Check( pyo ))
- return EXPP_ReturnPyObjError
- ( PyExc_AttributeError,
- "sequence item not number");
-
- numbuf[i] = (float) PyFloat_AsDouble( pyo );
- Py_DECREF( pyo ); /* from GetItem() */
- }
+
+ for( i = 0; i < length; i++) {
+ PyObject *pyo = PySequence_Fast_GET_ITEM( args, i );
+ if( !pyo )
+ return EXPP_ReturnPyObjError ( PyExc_AttributeError,
+ "wrong number of points");
+ if( !PyFloat_Check( pyo ))
+ return EXPP_ReturnPyObjError ( PyExc_AttributeError,
+ "sequence item not number");
+ numbuf[i] = (float) PyFloat_AsDouble( pyo );
}
-
/* create our bpy object */
pybez = ( BPy_BezTriple* ) PyObject_New( BPy_BezTriple,
&BezTriple_Type );
- if( ! pybez )
+ if( !pybez )
return EXPP_ReturnPyObjError( PyExc_MemoryError,
"PyObject_New failed");
+
pybez->beztriple = MEM_callocN( sizeof( BezTriple ), "new bpytriple");
+
/* check malloc */
+ if ( !pybez->beztriple ) {
+ Py_DECREF ( pybez );
+ return EXPP_ReturnPyObjError( PyExc_MemoryError,
+ "MEM_callocN failed");
+ }
pybez->own_memory = 1; /* we own it. must free later */
-
switch( length ) {
case 9: {
@@ -511,11 +559,11 @@
int num = 0;
for( i = 0; i < 3; i++ ){
for( j = 0; j < 3; j++){
- pybez->beztriple->vec[i][j] = numbuf[num ++];
+ pybez->beztriple->vec[i][j] = numbuf[num++];
}
}
}
- break;
+ break;
case 3: {
int i;
int num = 0;
@@ -527,15 +575,33 @@
++num;
}
}
- break;
+ break;
default:
/* we should not be here! */
break;
}
-
pybez->beztriple->h1 = HD_AUTO;
pybez->beztriple->h2 = HD_AUTO;
return ( PyObject* ) pybez;
}
+
+BezTriple *BezTriple_data_ok( BPy_BezTriple *self )
+{
+ if ( self->own_memory )
+ return self->beztriple;
+
+ if ( CurNurb_CheckPyObject( self->parent ) ) {
+ if ( ((BPy_CurNurb *)self->parent)->nurb->pntsu > self->index ) {
+ BPy_CurNurb *obj = (BPy_CurNurb *)self->parent;
+ return &obj->nurb->bezt[self->index];
+ }
+ } else {
+ if ( ((C_IpoCurve *)self->parent)->ipocurve->totvert > self->index ) {
+ C_IpoCurve * obj = (C_IpoCurve *)self->parent;
+ return &obj->ipocurve->bezt[self->index];
+ }
+ }
+ return NULL;
+}
--- source/blender/python/api2_2x/BezTriple.h 2005-07-03 11:35:58.000000000 -0700
+++ source/blender/python/api2_2x/BezTriple.h 2005-07-03 12:01:17.000000000 -0700
@@ -49,6 +49,8 @@
typedef struct {
PyObject_HEAD /* required python macro */
BezTriple * beztriple;
+ PyObject *parent;
+ int index;
int own_memory; /* true == we own this memory and must delete. */
} BPy_BezTriple;
@@ -56,10 +58,11 @@
* prototypes
*/
-PyObject *BezTriple_CreatePyObject( BezTriple * bzt );
+PyObject *BezTriple_CreatePyObject( PyObject * obj, int index );
int BezTriple_CheckPyObject( PyObject * pyobj );
BezTriple *BezTriple_FromPyObject( PyObject * pyobj );
PyObject *newBezTriple( PyObject *args );
PyObject *BezTriple_Init( void );
+BezTriple *BezTriple_data_ok( BPy_BezTriple *self );
#endif /* EXPP_BEZTRIPLE_H */
--- source/blender/python/api2_2x/Ipocurve.c 2005-07-03 11:35:58.000000000 -0700
+++ source/blender/python/api2_2x/Ipocurve.c 2005-07-03 12:01:20.000000000 -0700
@@ -25,7 +25,8 @@
*
* This is a new part of Blender.
*
- * Contributor(s): Jacques Guignot, Nathan Letwory, Ken Hughes
+ * Contributor(s): Jacques Guignot RIP 2005,
+ * Nathan Letwory, Ken Hughes
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
@@ -45,33 +46,14 @@
#include "constant.h"
#include "gen_utils.h"
#include "BezTriple.h"
-
-/*****************************************************************************/
-/* Python API function prototypes for the IpoCurve module. */
-/*****************************************************************************/
-static PyObject *M_IpoCurve_New( PyObject * self, PyObject * args );
-static PyObject *M_IpoCurve_Get( PyObject * self, PyObject * args );
+#include "curveutils.h"
/*****************************************************************************/
/* The following string definitions are used for documentation strings. */
/* In Python these will be written to the console when doing a */
/* Blender.IpoCurve.__doc__ */
/*****************************************************************************/
-char M_IpoCurve_doc[] = "";
-char M_IpoCurve_New_doc[] = "";
-char M_IpoCurve_Get_doc[] = "";
-
-/*****************************************************************************/
-/* Python method structure definition for Blender.IpoCurve module: */
-/*****************************************************************************/
-
-struct PyMethodDef M_IpoCurve_methods[] = {
- {"New", ( PyCFunction ) M_IpoCurve_New, METH_VARARGS | METH_KEYWORDS,
- M_IpoCurve_New_doc},
- {"Get", M_IpoCurve_Get, METH_VARARGS, M_IpoCurve_Get_doc},
- {"get", M_IpoCurve_Get, METH_VARARGS, M_IpoCurve_Get_doc},
- {NULL, NULL, 0, NULL}
-};
+char M_IpoCurve_doc[] = "IPO curve types";
/*****************************************************************************/
/* Python C_IpoCurve methods declarations: */
@@ -116,58 +98,98 @@
{"getExtrapolation", ( PyCFunction ) IpoCurve_getExtrapolation,
METH_NOARGS, "() - Gets the extend mode of the curve"},
{"getPoints", ( PyCFunction ) IpoCurve_getPoints, METH_NOARGS,
- "() - Returns list of all bezTriples of the curve"},
+ "obsolete: use operator[] or bezierPoints instance variable instead"},
{"evaluate", ( PyCFunction ) IpoCurve_evaluate, METH_VARARGS,
"(float) - Evaluate curve at given time"},
+ {"insert", ( PyCFunction ) IpoCurve_insert, METH_VARARGS,
+ "(int,obj) - insert BezTriple object into point list"},
+ {"append", ( PyCFunction ) IpoCurve_append, METH_VARARGS,
+ "(obj) - append BezTriple object to end of point list"},
{NULL, NULL, 0, NULL}
};
/*****************************************************************************/
+/* Python IpoCurve_Type callbacks for get/set of instance variables */
+/*****************************************************************************/
+
+static PyGetSetDef IpoCurve_getseters[] = {
+ {"bezierPoints",
+ (getter)IpoCurve_getPoints, (setter)IpoCurve_setPoints,
+ "BezTriple list",
+ NULL},
+ {"name",
+ (getter)IpoCurve_getName, (setter)NULL,
+ "curve name",
+ NULL},
+ {NULL,NULL,NULL,NULL,NULL} /* Sentinel */
+};
+
+/*****************************************************************************/
/* Python IpoCurve_Type callback function prototypes: */
/*****************************************************************************/
static void IpoCurveDeAlloc( C_IpoCurve * self );
//static int IpoCurvePrint (C_IpoCurve *self, FILE *fp, int flags);
-static int IpoCurveSetAttr( C_IpoCurve * self, char *name, PyObject * v );
-static PyObject *IpoCurveGetAttr( C_IpoCurve * self, char *name );
+//static int IpoCurveSetAttr( C_IpoCurve * self, char *name, PyObject * v );
static PyObject *IpoCurveRepr( C_IpoCurve * self );
/*****************************************************************************/
/* Python IpoCurve_Type structure definition: */
/*****************************************************************************/
PyTypeObject IpoCurve_Type = {
- PyObject_HEAD_INIT( NULL ) /* required macro */
- 0, /* ob_size */
- "IpoCurve", /* tp_name */
- sizeof( C_IpoCurve ), /* tp_basicsize */
- 0, /* tp_itemsize */
+ PyObject_HEAD_INIT( NULL ) /* required macro */
+ 0, /* ob_size */
+ "IpoCurve", /* tp_name */
+ sizeof( C_IpoCurve ), /* tp_basicsize */
+ 0, /* tp_itemsize */
/* methods */
- ( destructor ) IpoCurveDeAlloc, /* tp_dealloc */
- 0, /* tp_print */
- ( getattrfunc ) IpoCurveGetAttr, /* tp_getattr */
- ( setattrfunc ) IpoCurveSetAttr, /* tp_setattr */
- 0, /* tp_compare */
- ( reprfunc ) IpoCurveRepr, /* 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,
- C_IpoCurve_methods, /* tp_methods */
- 0, /* tp_members */
+ (destructor)IpoCurveDeAlloc, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ (reprfunc)IpoCurveRepr, /* tp_repr */
+ 0, /* tp_as_number */
+ &IpoCurve_sequence, /* tp_as_sequence */
+ 0, /* 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)IpoCurve_getIter, /* tp_iter */
+ (iternextfunc)IpoCurve_nextIter, /* tp_iternext */
+ C_IpoCurve_methods, /* tp_methods */
+ 0, /* tp_members */
+ IpoCurve_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 */
};
/*****************************************************************************/
-/* Function: M_IpoCurve_New */
-/* Python equivalent: Blender.IpoCurve.New */
-/*****************************************************************************/
-static PyObject *M_IpoCurve_New( PyObject * self, PyObject * args )
-{
- return 0;
-}
-
-/*****************************************************************************/
/* Function: Ipo_Init */
/*****************************************************************************/
PyObject *IpoCurve_Init( void )
@@ -176,28 +198,20 @@
IpoCurve_Type.ob_type = &PyType_Type;
+ /*
+ * These are necessary for tp_getset
+ */
+
+ IpoCurve_Type.tp_getattro = &PyObject_GenericGetAttr;
+ IpoCurve_Type.tp_setattro = &PyObject_GenericSetAttr;
+
submodule =
- Py_InitModule3( "Blender.IpoCurve", M_IpoCurve_methods,
- M_IpoCurve_doc );
+ Py_InitModule3( "Blender.IpoCurve", NULL, M_IpoCurve_doc );
return ( submodule );
}
/*****************************************************************************/
-/* Function: M_IpoCurve_Get */
-/* Python equivalent: Blender.IpoCurve.Get */
-/* Description: Receives a string and returns the ipo data obj */
-/* whose name matches the string. If no argument is */
-/* passed in, a list of all ipo data names in the */
-/* current scene is returned. */
-/*****************************************************************************/
-static PyObject *M_IpoCurve_Get( PyObject * self, PyObject * args )
-{
- Py_INCREF( Py_None );
- return Py_None;
-}
-
-/*****************************************************************************/
/* Python C_IpoCurve methods: */
/*****************************************************************************/
@@ -337,8 +351,6 @@
static PyObject *IpoCurve_delBezier( C_IpoCurve * self, PyObject * args )
{
- //short MEM_freeN( void *vmemh );
- //void *MEM_mallocN( unsigned int len, char *str );
int npoints;
int index;
IpoCurve *icu;
@@ -445,8 +457,6 @@
return EXPP_ReturnPyObjError( PyExc_TypeError,
"This function doesn't support this ipocurve type yet" );
}
-
- return PyString_FromString( "" );
}
static void IpoCurveDeAlloc( C_IpoCurve * self )
@@ -454,70 +464,26 @@
PyObject_DEL( self );
}
+/*
+ * Return a list of the curve's points; uses the sequence procedures
+ */
+
static PyObject *IpoCurve_getPoints( C_IpoCurve * self )
{
- struct BezTriple *bezt;
- PyObject *po;
-
- PyObject *list = PyList_New( 0 );
- int i;
-
- for( i = 0; i < self->ipocurve->totvert; i++ ) {
- bezt = self->ipocurve->bezt + i;
- po = BezTriple_CreatePyObject( bezt );
-#if 0
- if( BezTriple_CheckPyObject( po ) )
- printf( "po is ok\n" );
- else
- printf( "po is hosed\n" );
-#endif
- PyList_Append( list, po );
- /*
- PyList_Append( list, BezTriple_CreatePyObject(bezt));
- */
- }
- return list;
+ return IpoCurve_get_slice ( self, 0, self->ipocurve->totvert );
}
+/*
+ * Assign a list of points to a curve; uses the sequence procedures to
+ * assign a slice of the same length.
+ */
int IpoCurve_setPoints( C_IpoCurve * self, PyObject * value )
{
- struct BezTriple *bezt;
- PyObject *l = PyList_New( 0 );
- int i;
- for( i = 0; i < self->ipocurve->totvert; i++ ) {
- bezt = self->ipocurve->bezt + i;
- PyList_Append( l, BezTriple_CreatePyObject( bezt ) );
- }
- return 0;
-}
-
-
-/*****************************************************************************/
-/* Function: IpoCurveGetAttr */
-/* Description: This is a callback function for the C_IpoCurve type. It is */
-/* the function that accesses C_IpoCurve "member variables" and */
-/* methods. */
-/*****************************************************************************/
-static PyObject *IpoCurveGetAttr( C_IpoCurve * self, char *name )
-{
- if( strcmp( name, "bezierPoints" ) == 0 )
- return IpoCurve_getPoints( self );
- if( strcmp( name, "name" ) == 0 )
- return IpoCurve_getName( self );
- return Py_FindMethod( C_IpoCurve_methods, ( PyObject * ) self, name );
-}
-
-/*****************************************************************************/
-/* Function: IpoCurveSetAttr */
-/* Description: This is a callback function for the C_IpoCurve type. It */
-/* sets IpoCurve Data attributes (member variables).*/
-/*****************************************************************************/
-static int IpoCurveSetAttr( C_IpoCurve * self, char *name, PyObject * value )
-{
- if( strcmp( name, "bezierPoints" ) == 0 )
- return IpoCurve_setPoints( self, value );
- return 0; /* normal exit */
+ if ( !PySequence_Check ( value ) )
+ return EXPP_ReturnIntError( PyExc_TypeError,
+ "expected a list" );
+ return IpoCurve_assign_slice( self, 0, PySequence_Size ( value ), value );
}
/*****************************************************************************/
@@ -631,3 +597,4 @@
}
return NULL;
}
+
--- source/blender/python/api2_2x/Ipocurve.h 2005-07-03 11:35:58.000000000 -0700
+++ source/blender/python/api2_2x/Ipocurve.h 2005-07-03 12:01:20.000000000 -0700
@@ -41,16 +41,14 @@
/*****************************************************************************/
typedef struct {
PyObject_HEAD /* required macro */
- IpoCurve * ipocurve;
+ IpoCurve * ipocurve; /* pointer to Blender data */
+ int iter_index; /* iterator index */
} C_IpoCurve;
-
-
PyObject *IpoCurve_Init( void );
PyObject *IpoCurve_CreatePyObject( IpoCurve * ipo );
int IpoCurve_CheckPyObject( PyObject * pyobj );
IpoCurve *IpoCurve_FromPyObject( PyObject * pyobj );
char *getIpoCurveName( IpoCurve * icu );
-
#endif /* EXPP_IPOCURVE_H */
--- source/blender/python/api2_2x/CurNurb.h 2005-07-03 11:35:58.000000000 -0700
+++ source/blender/python/api2_2x/CurNurb.h 2005-07-03 12:01:19.000000000 -0700
@@ -42,14 +42,7 @@
typedef struct {
PyObject_HEAD /* required py macro */
Nurb * nurb; /* pointer to Blender data */
-
- /* iterator stuff */
- /* internal ptrs to point data. do not free */
- BPoint *bp;
- BezTriple *bezt;
- int atEnd; /* iter exhausted flag */
- int nextPoint;
-
+ int iter_index; /* iterator index */
} BPy_CurNurb;
@@ -62,9 +55,6 @@
int CurNurb_CheckPyObject( PyObject * pyobj );
Nurb *CurNurb_FromPyObject( PyObject * pyobj );
-PyObject *CurNurb_getPoint( BPy_CurNurb * self, int index );
-PyObject *CurNurb_pointAtIndex( Nurb * nurb, int index );
-
PyObject *CurNurb_appendPointToNurb( Nurb * nurb, PyObject * args );
#endif /* EXPP_NURB_H */
--- source/blender/python/api2_2x/BNURBPoint.c 2005-06-28 10:25:12.000000000 -0700
+++ source/blender/python/api2_2x/BNURBPoint.c 2005-07-03 12:01:11.000000000 -0700
@@ -25,7 +25,7 @@
* This is a new part of Blender.
*
* Contributor(s): Jacques Guignot RIP 2005,
- * Stephen Swaney
+ * Stephen Swaney, Ken Hughes
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
@@ -45,6 +45,9 @@
#include "constant.h"
#include "gen_utils.h"
+#include "Ipocurve.h"
+#include "CurNurb.h"
+
/***************************************************************************
Python API function prototypes for the BNURBPoint module.
@@ -53,7 +56,7 @@
static PyObject *M_BNURBPoint_Get( PyObject * self, PyObject * args );
/*************************************
- Doc strings for the BPoint module
+ Doc strings for the BNURBPoint module
*************************************/
static char M_BNURBPoint_doc[] = "The Blender BPoint module\n";
@@ -92,13 +95,13 @@
};
/*****************************************************************************/
-/* Python BPy_BNURBPoint methods table: */
+/* Python BPy_BNURBPoint methods table: */
/*****************************************************************************/
static PyMethodDef BPy_BNURBPoint_methods[] = {
/* name, method, flags, doc */
- {"setPoint", ( PyCFunction ) BNURBPoint_setPoint, METH_VARARGS,
+ {"setPoints", ( PyCFunction ) BNURBPoint_setPoint, METH_VARARGS,
"(str) - Change BPoint point coordinates"},
- {"getPoint", ( PyCFunction ) BNURBPoint_getPoint, METH_NOARGS,
+ {"getPoints", ( PyCFunction ) BNURBPoint_getPoint, METH_NOARGS,
"() - return BPoint point x,y,z coordinates"},
{NULL, NULL, 0, NULL}
};
@@ -194,13 +197,14 @@
static PyObject *BNURBPoint_getPoint( BPy_BNURBPoint * self )
{
- struct BPoint *bpoint = self->bpoint;
+ BPoint *bpoint;
PyObject *l;
int i;
+ bpoint = BNURBPoint_data_ok( self );
if ( !bpoint )
- return ( EXPP_ReturnPyObjError
- ( PyExc_RuntimeError, "bpoint has been deleted" ) );
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "BPoint no longer valid" );
l = PyList_New( 4 );
if ( !l )
@@ -216,33 +220,35 @@
static PyObject *BNURBPoint_setPoint( BPy_BNURBPoint * self, PyObject * args )
{
int i;
- struct BPoint *bpoint = self->bpoint;
+ BPoint *bpoint;
PyObject *obj = NULL;
- float vec[3];
+ float vec[4];
+ bpoint = BNURBPoint_data_ok( self );
if ( !bpoint )
- return EXPP_ReturnPyObjError
- ( PyExc_RuntimeError, "bpoint has been deleted" );
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "BPoint no longer valid" );
if( !PyArg_ParseTuple( args, "O", &obj ) || !PySequence_Check( obj ) )
return EXPP_ReturnPyObjError
( PyExc_TypeError, "expected sequence argument" );
- if ( PySequence_Length( obj ) != 3 )
+ if ( PySequence_Length( obj ) != 4 )
return EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected three numbers" );
+ ( PyExc_TypeError, "expected four numbers" );
- for( i = 0; i < 3; i++ ) {
+ for( i = 0; i < 4; i++ ) {
PyObject *o = PySequence_Fast_GET_ITEM( obj, i );
if ( !PyNumber_Check ( o ) )
return EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected two numbers" );
+ ( PyExc_TypeError, "expected four numbers" );
vec[i] = PyFloat_AsDouble( o );
}
bpoint->vec[0] = vec[0];
bpoint->vec[1] = vec[1];
bpoint->vec[2] = vec[2];
+ bpoint->vec[3] = vec[3];
/* TODO: may need to initialize more stuff here */
@@ -257,12 +263,19 @@
/*****************************************************************************/
static PyObject *NURBPointGetAttr( BPy_BNURBPoint * self, char *name )
{
+ BPoint *bpoint;
+
+ bpoint = BNURBPoint_data_ok( self );
+ if ( !bpoint )
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "BPoint no longer valid" );
+
if( strcmp( name, "pt" ) == 0 )
return BNURBPoint_getPoint( self );
else if( strcmp( name, "tilt" ) == 0 )
- return PyFloat_FromDouble(self->bpoint->alfa);
+ return PyFloat_FromDouble(bpoint->alfa);
else if( strcmp( name, "weight" ) == 0 )
- return PyFloat_FromDouble(self->bpoint->vec[3]);
+ return PyFloat_FromDouble(bpoint->vec[3]);
else if( strcmp( name, "__members__" ) == 0 )
return Py_BuildValue( "[s,s,s]", "pt", "tilt", "weight");
@@ -277,6 +290,8 @@
/*****************************************************************************/
static int NURBPointSetAttr( BPy_BNURBPoint * self, char *name, PyObject * value )
{
+ BPoint *bpoint;
+
#if 0
/*
this does not work at the moment: Wed Apr 7 2004
@@ -289,21 +304,24 @@
return 0; /* normal exit */
#endif
- if (!self->bpoint)
- return ( EXPP_ReturnIntError
- ( PyExc_RuntimeError, "bpoint has been deleted" ) );
+
+
+ bpoint = BNURBPoint_data_ok( self );
+ if ( !bpoint )
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "BPoint no longer valid" );
if( strcmp( name, "tilt" ) == 0 ) {
if (!PyFloat_Check( value ) )
return EXPP_ReturnIntError( PyExc_TypeError, "expected a float" );
- self->bpoint->alfa = (float)PyFloat_AsDouble( value );
+ bpoint->alfa = (float)PyFloat_AsDouble( value );
return 0;
} else if( strcmp( name, "weight" ) == 0 ) {
if (!PyFloat_Check( value ) )
return EXPP_ReturnIntError( PyExc_TypeError, "expected a float" );
- self->bpoint->vec[3] = (float)PyFloat_AsDouble( value );
+ bpoint->vec[3] = (float)PyFloat_AsDouble( value );
return 0;
}
@@ -325,17 +343,17 @@
char f1, f2, f3, hide;
*/
char str[1000];
- if (!self->bpoint)
- return ( EXPP_ReturnPyObjError
- ( PyExc_RuntimeError, "bpoint has been deleted" ) );
+ BPoint *bpoint;
+
+ bpoint = BNURBPoint_data_ok( self );
+ if ( !bpoint )
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "BPoint no longer valid" );
sprintf( str,
"[BPoint [%f %f %f %f] %f %d %d %d %d]",
- self->bpoint->vec[0], self->bpoint->vec[1],
- self->bpoint->vec[2], self->bpoint->vec[3],
- self->bpoint->alfa,
- self->bpoint->s[0], self->bpoint->s[1],
- self->bpoint->f1, self->bpoint->hide );
+ bpoint->vec[0], bpoint->vec[1], bpoint->vec[2], bpoint->vec[3],
+ bpoint->alfa, bpoint->s[0], bpoint->s[1], bpoint->f1, bpoint->hide );
return PyString_FromString( str );
}
@@ -348,24 +366,21 @@
static PyObject *BNURBPoint_Str( BPy_BNURBPoint * self )
{
- BPoint *p = self->bpoint;
+ BPoint *bpoint;
- if (!self->bpoint)
- return ( EXPP_ReturnPyObjError
- ( PyExc_RuntimeError, "bpoint has been deleted" ) );
+ bpoint = BNURBPoint_data_ok( self );
+ if ( !bpoint )
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "BPoint no longer valid" );
/* fixme: */
return PyString_FromFormat(
"BPoint (%f %f %f %f) alpha %f\n (%d %d) f1:%d hide:%d",
- p->vec[0], p->vec[1],
- p->vec[2], p->vec[3],
- p->alfa,
- p->s[0], p->s[1],
- p->f1, p->hide );
-
+ bpoint->vec[0], bpoint->vec[1], bpoint->vec[2], bpoint->vec[3],
+ bpoint->alfa,
+ bpoint->s[0], bpoint->s[1], bpoint->f1, bpoint->hide );
}
-
/*
BNURBPoint_Init
*/
@@ -390,7 +405,7 @@
Description: This function will create a new BPy_BNURBPoint from an existing
Blender ipo structure.
****************************************************************************/
-PyObject *BNURBPoint_CreatePyObject( BPoint * bpoint )
+PyObject *BNURBPoint_CreatePyObject( PyObject *obj, int index )
{
BPy_BNURBPoint *pybpoint;
@@ -401,7 +416,10 @@
return EXPP_ReturnPyObjError( PyExc_MemoryError,
"couldn't create BPy_BNURBPoint object" );
- pybpoint->bpoint = bpoint;
+ pybpoint->own_memory = 0; /* we don't own it */
+
+ pybpoint->parent = obj;
+ pybpoint->index = index;
return ( PyObject * ) pybpoint;
}
@@ -488,3 +506,15 @@
return ( PyObject* ) pybpoint;
}
+
+BPoint *BNURBPoint_data_ok( BPy_BNURBPoint *self )
+{
+ if ( self->own_memory )
+ return self->bpoint;
+
+ if ( CurNurb_CheckPyObject( self->parent ) ) {
+ if ( ((BPy_CurNurb *)self->parent)->nurb->pntsu > self->index )
+ return &((BPy_CurNurb *)self->parent)->nurb->bp[self->index];
+ }
+ return NULL;
+}
--- source/blender/python/api2_2x/BNURBPoint.h 2005-06-28 10:25:12.000000000 -0700
+++ source/blender/python/api2_2x/BNURBPoint.h 2005-07-03 12:01:11.000000000 -0700
@@ -30,8 +30,8 @@
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
-#ifndef EXPP_BPOINT_H
-#define EXPP_BPOINT_H
+#ifndef EXPP_BNURBPOINT_H
+#define EXPP_BNURBPOINT_H
#include <Python.h>
#include <DNA_curve_types.h>
@@ -49,6 +49,8 @@
typedef struct {
PyObject_HEAD /* required python macro */
BPoint * bpoint;
+ PyObject *parent;
+ int index;
int own_memory; /* true == we own this memory and must delete. */
} BPy_BNURBPoint;
@@ -56,10 +58,12 @@
* prototypes
*/
-PyObject *BPoint_CreatePyObject( BPoint * bzt );
-int BPoint_CheckPyObject( PyObject * pyobj );
-BPoint *BPoint_FromPyObject( PyObject * pyobj );
-PyObject *newBPoint( PyObject *args );
-PyObject *BPoint_Init( void );
+PyObject *BNURBPoint_CreatePyObject( PyObject *obj, int index );
+int BNURBPoint_CheckPyObject( PyObject * pyobj );
+BPoint *BNURBPoint_FromPyObject( PyObject * pyobj );
+// PyObject *newBPoint( PyObject *args );
+PyObject *BNURBPoint_Init( void );
+BPoint *BNURBPoint_data_ok( BPy_BNURBPoint *self );
+
+#endif /* EXPP_BNURBPOINT_H */
-#endif /* EXPP_BPOINT_H */
--- source/blender/python/api2_2x/CurNurb.c 2005-07-03 11:53:58.000000000 -0700
+++ source/blender/python/api2_2x/CurNurb.c 2005-07-05 21:56:32.000000000 -0700
@@ -24,56 +24,57 @@
*
* This is a new part of Blender.
*
- * Contributor(s): Stephen Swaney
+ * Contributor(s): Stephen Swaney, Ken Hughes
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
-#define HAVE_BNURBPoint
-
-#include "Python.h"
-#include "DNA_curve_types.h"
-#include "BKE_curve.h"
-#include "BDR_editcurve.h" /* for convertspline */
-#include "MEM_guardedalloc.h"
+#include <Python.h>
+#include <DNA_curve_types.h>
+#include <BKE_blender.h>
+#include <BKE_curve.h>
+#include <BDR_editcurve.h> /* for convertspline */
+#include <MEM_guardedalloc.h>
#include "gen_utils.h"
-#include "CurNurb.h"
#include "BezTriple.h"
-#ifdef HAVE_BNURBPoint
#include "BNURBPoint.h"
-#endif
+#include "CurNurb.h"
+#include "curveutils.h"
/*
* forward declarations go here
*/
-
static PyObject *M_CurNurb_New( PyObject * self, PyObject * args );
PyObject *CurNurb_CreatePyObject( Nurb * blen_nurb );
-static PyObject *CurNurb_setMatIndex( BPy_CurNurb * self, PyObject * args );
static PyObject *CurNurb_getMatIndex( BPy_CurNurb * self );
static PyObject *CurNurb_getFlagU( BPy_CurNurb * self );
-static PyObject *CurNurb_setFlagU( BPy_CurNurb * self, PyObject * args );
static PyObject *CurNurb_getFlagV( BPy_CurNurb * self );
-static PyObject *CurNurb_setFlagV( BPy_CurNurb * self, PyObject * args );
static PyObject *CurNurb_getType( BPy_CurNurb * self );
-static PyObject *CurNurb_setType( BPy_CurNurb * self, PyObject * args );
+
+static int CurNurb_setMatIndex( BPy_CurNurb * self, PyObject * args );
+static int CurNurb_setFlagU( BPy_CurNurb * self, PyObject * args );
+static int CurNurb_setFlagV( BPy_CurNurb * self, PyObject * args );
+static int CurNurb_setType( BPy_CurNurb * self, PyObject * args );
+
/* static PyObject* CurNurb_setXXX( BPy_CurNurb* self, PyObject* args ); */
-PyObject *CurNurb_getPoint( BPy_CurNurb * self, int index );
static int CurNurb_setPoint( BPy_CurNurb * self, int index, PyObject * ob );
static int CurNurb_length( PyInstanceObject * inst );
-static PyObject *CurNurb_getIter( BPy_CurNurb * self );
-static PyObject *CurNurb_iterNext( BPy_CurNurb * self );
-PyObject *CurNurb_append( BPy_CurNurb * self, PyObject * args );
-PyObject *CurNurb_pointAtIndex( Nurb * nurb, int index );
static PyObject *CurNurb_isNurb( BPy_CurNurb * self );
static PyObject *CurNurb_isCyclic( BPy_CurNurb * self );
static PyObject *CurNurb_dump( BPy_CurNurb * self );
+static PyObject* CurNurb_getLength ( BPy_CurNurb *self);
-char M_CurNurb_doc[] = "CurNurb";
+/* #####DEPRECATED###### */
+static PyObject *CurNurb_oldsetMatIndex( BPy_CurNurb * self, PyObject * args );
+static PyObject *CurNurb_oldsetFlagU( BPy_CurNurb * self, PyObject * args );
+static PyObject *CurNurb_oldsetFlagV( BPy_CurNurb * self, PyObject * args );
+static PyObject *CurNurb_oldsetType( BPy_CurNurb * self, PyObject * args );
+
+char M_CurNurb_doc[] = "CurNurb";
/*
CurNurb_Type callback function prototypes:
@@ -81,12 +82,8 @@
static void CurNurb_dealloc( BPy_CurNurb * self );
static int CurNurb_compare( BPy_CurNurb * a, BPy_CurNurb * b );
-static PyObject *CurNurb_getAttr( BPy_CurNurb * self, char *name );
-static int CurNurb_setAttr( BPy_CurNurb * self, char *name, PyObject * v );
static PyObject *CurNurb_repr( BPy_CurNurb * self );
-
-
/*
table of module methods
these are the equivalent of class or static methods.
@@ -104,8 +101,6 @@
{NULL, NULL, 0, NULL}
};
-
-
/*
* method table
* table of instance methods
@@ -115,51 +110,64 @@
static PyMethodDef BPy_CurNurb_methods[] = {
/* name, method, flags, doc */
/* {"method", (PyCFunction) CurNurb_method, METH_NOARGS, " () - doc string"} */
- {"setMatIndex", ( PyCFunction ) CurNurb_setMatIndex, METH_VARARGS,
- "( index ) - set index into materials list"},
{"getMatIndex", ( PyCFunction ) CurNurb_getMatIndex, METH_NOARGS,
"( ) - get current material index"},
- {"setFlagU", ( PyCFunction ) CurNurb_setFlagU, METH_VARARGS,
- "( index ) - set flagU and recalculate the knots (0: uniform, 1: endpoints, 2: bezier)"},
{"getFlagU", ( PyCFunction ) CurNurb_getFlagU, METH_NOARGS,
"( ) - get flagU of the knots"},
- {"setFlagV", ( PyCFunction ) CurNurb_setFlagV, METH_VARARGS,
- "( index ) - set flagV and recalculate the knots (0: uniform, 1: endpoints, 2: bezier)"},
{"getFlagV", ( PyCFunction ) CurNurb_getFlagV, METH_NOARGS,
"( ) - get flagV of the knots"},
- {"setType", ( PyCFunction ) CurNurb_setType, METH_VARARGS,
- "( type ) - change the type of the curve (Poly: 0, Bezier: 1, NURBS: 4)"},
{"getType", ( PyCFunction ) CurNurb_getType, METH_NOARGS,
"( ) - get the type of the curve (Poly: 0, Bezier: 1, NURBS: 4)"},
- {"append", ( PyCFunction ) CurNurb_append, METH_VARARGS,
- "( point ) - add a new point. arg is BezTriple or list of x,y,z,w floats"},
{"isNurb", ( PyCFunction ) CurNurb_isNurb, METH_NOARGS,
"( ) - boolean function tests if this spline is type nurb or bezier"},
{"isCyclic", ( PyCFunction ) CurNurb_isCyclic, METH_NOARGS,
"( ) - boolean function tests if this spline is cyclic (closed) or not (open)"},
{"dump", ( PyCFunction ) CurNurb_dump, METH_NOARGS,
"( ) - dumps Nurb data)"},
- {NULL, NULL, 0, NULL}
-};
+ {"insert", ( PyCFunction ) CurNurb_insert, METH_VARARGS,
+ "(int,obj) - insert point object into point list"},
+ {"append", ( PyCFunction ) CurNurb_append, METH_VARARGS,
+ "(obj) - append point object to end of point list"},
-/*
- * methods for CurNurb as sequece
- */
+/* #####DEPRECATED###### */
-static PySequenceMethods CurNurb_as_sequence = {
- ( inquiry ) CurNurb_length, /* sq_length */
- ( binaryfunc ) 0, /* sq_concat */
- ( intargfunc ) 0, /* sq_repeat */
- ( intargfunc ) CurNurb_getPoint, /* sq_item */
- ( intintargfunc ) 0, /* sq_slice */
- ( intobjargproc ) CurNurb_setPoint, /* sq_ass_item */
- 0, /* sq_ass_slice */
- ( objobjproc ) 0, /* sq_contains */
- 0,
- 0
-};
+ {"setMatIndex", ( PyCFunction ) CurNurb_oldsetMatIndex, METH_VARARGS,
+ "( index ) - set index into materials list"},
+ {"setFlagU", ( PyCFunction ) CurNurb_oldsetFlagU, METH_VARARGS,
+ "( index ) - set flagU and recalculate the knots (0: uniform, 1: endpoints, 2: bezier)"},
+ {"setFlagV", ( PyCFunction ) CurNurb_oldsetFlagV, METH_VARARGS,
+ "( index ) - set flagV and recalculate the knots (0: uniform, 1: endpoints, 2: bezier)"},
+ {"setType", ( PyCFunction ) CurNurb_oldsetType, METH_VARARGS,
+ "( type ) - change the type of the curve (Poly: 0, Bezier: 1, NURBS: 4)"},
+ {NULL, NULL, 0, NULL}
+};
+static PyGetSetDef CurNurb_getseters[] = {
+ {"mat_index",
+ (getter)CurNurb_getMatIndex, (setter)CurNurb_setMatIndex,
+ "material index",
+ NULL},
+ {"flagU",
+ (getter)CurNurb_getFlagU, (setter)CurNurb_setFlagU,
+ "knot flag for U (0: uniform, 1: endpoints, 2: bezier)",
+ NULL},
+ {"flagV",
+ (getter)CurNurb_getFlagV, (setter)CurNurb_setFlagV,
+ "knot flag for V (0: uniform, 1: endpoints, 2: bezier)",
+ NULL},
+ {"type",
+ (getter)CurNurb_getType, (setter)CurNurb_setType,
+ "curve type (0: poly, 1: bezier, 4: NURBS)",
+ NULL},
+#if BLENDER_VERSION < 243
+ {"points",
+ (getter)CurNurb_getLength, (setter)NULL,
+ "obsolete: use len()",
+ NULL},
+#endif
+ {NULL,NULL,NULL,NULL,NULL} /* Sentinel */
+};
/*
Object Type definition
@@ -180,15 +188,16 @@
( destructor ) CurNurb_dealloc, /* destructor tp_dealloc; */
0, /* printfunc tp_print; */
- ( getattrfunc ) CurNurb_getAttr, /* getattrfunc tp_getattr; */
- ( setattrfunc ) CurNurb_setAttr, /* setattrfunc tp_setattr; */
+ 0, /* getattrfunc tp_getattr; */
+ 0, /* setattrfunc tp_setattr; */
( cmpfunc ) CurNurb_compare, /* cmpfunc tp_compare; */
( reprfunc ) CurNurb_repr, /* reprfunc tp_repr; */
/* Method suites for standard classes */
0, /* PyNumberMethods *tp_as_number; */
- &CurNurb_as_sequence, /* PySequenceMethods *tp_as_sequence; */
+ // &CurNurb_as_sequence, /* PySequenceMethods *tp_as_sequence; */
+ &CurNurb_sequence, /* PySequenceMethods *tp_as_sequence; */
0, /* PyMappingMethods *tp_as_mapping; */
/* More standard operations (here for binary compatibility) */
@@ -223,12 +232,12 @@
/*** Added in release 2.2 ***/
/* Iterators */
( getiterfunc ) CurNurb_getIter, /* getiterfunc tp_iter; */
- ( iternextfunc ) CurNurb_iterNext, /* iternextfunc tp_iternext; */
+ ( iternextfunc ) CurNurb_nextIter, /* iternextfunc tp_iternext; */
/*** Attribute descriptor and subclassing stuff ***/
BPy_CurNurb_methods, /* struct PyMethodDef *tp_methods; */
0, /* struct PyMemberDef *tp_members; */
- 0, /* struct PyGetSetDef *tp_getset; */
+ CurNurb_getseters, /* struct PyGetSetDef *tp_getset; */
0, /* struct _typeobject *tp_base; */
0, /* PyObject *tp_dict; */
0, /* descrgetfunc tp_descr_get; */
@@ -255,95 +264,11 @@
void CurNurb_dealloc( BPy_CurNurb * self )
{
+ /* TODO: need to handle lists of triples or Nurbs */
PyObject_DEL( self );
}
-
-static PyObject *CurNurb_getAttr( BPy_CurNurb * self, char *name )
-{
- PyObject *attr = Py_None;
-
- if( strcmp( name, "mat_index" ) == 0 )
- attr = PyInt_FromLong( self->nurb->mat_nr );
-
- else if( strcmp( name, "points" ) == 0 )
- attr = PyInt_FromLong( self->nurb->pntsu );
-
- else if( strcmp( name, "flagU" ) == 0 )
- attr = CurNurb_getFlagU( self );
-
- else if( strcmp( name, "flagV" ) == 0 )
- attr = CurNurb_getFlagV( self );
-
- else if( strcmp( name, "type" ) == 0 )
- attr = CurNurb_getType( self );
-
- else if( strcmp( name, "__members__" ) == 0 )
- attr = Py_BuildValue( "[s,s,s,s,s]", "mat_index", "points", "flagU", "flagV", "type" );
-
- if( !attr )
- return EXPP_ReturnPyObjError( PyExc_MemoryError,
- "couldn't create PyObject" );
-
- /* member attribute found, return it */
- if( attr != Py_None )
- return attr;
-
- /* not an attribute, search the methods table */
- return Py_FindMethod( BPy_CurNurb_methods, ( PyObject * ) self, name );
-}
-
-
-/*
- setattr
-*/
-
-static int CurNurb_setAttr( BPy_CurNurb * self, char *name, PyObject * value )
-{
- PyObject *valtuple;
- PyObject *error = NULL;
-
- /* make a tuple to pass to our type methods */
- valtuple = Py_BuildValue( "(O)", value );
-
- if( !valtuple )
- return EXPP_ReturnIntError( PyExc_MemoryError,
- "CurNurb.setAttr: cannot create pytuple" );
-
- if( strcmp( name, "mat_index" ) == 0 )
- error = CurNurb_setMatIndex( self, valtuple );
-
- else if( strcmp( name, "flagU" ) == 0 )
- error = CurNurb_setFlagU( self, valtuple );
-
- else if( strcmp( name, "flagV" ) == 0 )
- error = CurNurb_setFlagV( self, valtuple );
-
- else if( strcmp( name, "type" ) == 0 )
- error = CurNurb_setType( self, valtuple );
-
- else { /* error - no match for name */
- Py_DECREF( valtuple );
-
- if( ( strcmp( name, "ZZZZ" ) == 0 ) || /* user tried to change a */
- ( strcmp( name, "ZZZZ" ) == 0 ) ) /* constant dict type ... */
- return EXPP_ReturnIntError( PyExc_AttributeError,
- "constant dictionary -- cannot be changed" );
- else
- return EXPP_ReturnIntError( PyExc_KeyError,
- "attribute not found" );
- }
-
-
- Py_DECREF( valtuple ); /* since it is not being returned */
- if( error != Py_None )
- return -1;
-
- Py_DECREF( Py_None );
- return 0; /* normal exit */
-}
-
/*
compare
in this case, we consider two CurNurbs equal, if they point to the same
@@ -397,6 +322,7 @@
/*
* Curve.getType
*/
+
static PyObject *CurNurb_getType( BPy_CurNurb * self )
{
/* type is on 3 first bits only */
@@ -406,179 +332,32 @@
/*
* Curve.setType
*
- * Convert the curve using Blender's convertspline fonction
+ * Convert the curve using Blender's convertspline function
*/
-static PyObject *CurNurb_setType( BPy_CurNurb * self, PyObject * args )
+
+static int CurNurb_setType( BPy_CurNurb * self, PyObject * args )
{
Nurb *nurb = self->nurb;
short type;
- /* parameter type checking */
- if( !PyArg_ParseTuple( args, "h", &type ) )
- return EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected integer argument" );
+ if( !PyInt_Check( args ) )
+ return EXPP_ReturnIntError ( PyExc_AttributeError,
+ "expected integer argument" );
+ type = PyInt_AsLong(args);
/* parameter value checking */
if (type != CU_POLY &&
type != CU_BEZIER &&
type != CU_NURBS)
- return EXPP_ReturnPyObjError
+ return EXPP_ReturnIntError
( PyExc_ValueError, "expected integer argument" );
/* convert and raise error if impossible */
if (convertspline(type, nurb))
- return EXPP_ReturnPyObjError
+ return EXPP_ReturnIntError
( PyExc_ValueError, "Conversion Impossible" );
- return EXPP_incr_ret( Py_None );
-}
-
-
-
-/*
- * CurNurb_append( point )
- * append a new point to a nurb curve.
- * arg is BezTriple or list of xyzw floats
- */
-
-static PyObject *CurNurb_append( BPy_CurNurb * self, PyObject * args )
-{
- Nurb *nurb = self->nurb;
-
- return CurNurb_appendPointToNurb( nurb, args );
-}
-
-
-/*
- * CurNurb_appendPointToNurb
- * this is a non-bpy utility func to add a point to a given nurb.
- * notice the first arg is Nurb*.
- */
-
-PyObject *CurNurb_appendPointToNurb( Nurb * nurb, PyObject * args )
-{
-
- int i;
- int size;
- PyObject *pyOb;
- int npoints = nurb->pntsu;
-
- /*
- do we have a list of four floats or a BezTriple?
- */
- if( !PyArg_ParseTuple( args, "O", &pyOb ))
- return EXPP_ReturnPyObjError
- ( PyExc_RuntimeError,
- "Internal error parsing arguments" );
-
-
-
- /* if curve is empty, adjust type depending on input type */
- if (nurb->bezt==NULL && nurb->bp==NULL) {
- if (BezTriple_CheckPyObject( pyOb ))
- nurb->type |= CU_BEZIER;
- else if (PySequence_Check( pyOb ))
- nurb->type |= CU_NURBS;
- else
- return( EXPP_ReturnPyObjError( PyExc_TypeError,
- "Expected a BezTriple or a Sequence of 4 (or 5) floats" ) );
- }
-
-
-
- if ((nurb->type & 7)==CU_BEZIER) {
- BezTriple *tmp;
-
- if( !BezTriple_CheckPyObject( pyOb ) )
- return( EXPP_ReturnPyObjError( PyExc_TypeError,
- "Expected a BezTriple\n" ) );
-
-/* printf("\ndbg: got a BezTriple\n"); */
- tmp = nurb->bezt; /* save old points */
- nurb->bezt =
- ( BezTriple * ) MEM_mallocN( sizeof( BezTriple ) *
- ( npoints + 1 ),
- "CurNurb_append2" );
-
- if( !nurb->bezt )
- return ( EXPP_ReturnPyObjError
- ( PyExc_MemoryError, "allocation failed" ) );
-
- /* copy old points to new */
- memmove( nurb->bezt, tmp, sizeof( BezTriple ) * npoints );
- if( tmp )
- MEM_freeN( tmp );
- nurb->pntsu++;
- /* add new point to end of list */
- memcpy( nurb->bezt + npoints,
- BezTriple_FromPyObject( pyOb ), sizeof( BezTriple ) );
-
- }
- else if( PySequence_Check( pyOb ) ) {
- size = PySequence_Size( pyOb );
-/* printf("\ndbg: got a sequence of size %d\n", size ); */
- if( size == 4 || size == 5 ) {
- BPoint *tmp;
-
- tmp = nurb->bp; /* save old pts */
-
- nurb->bp =
- ( BPoint * ) MEM_mallocN( sizeof( BPoint ) *
- ( npoints + 1 ),
- "CurNurb_append1" );
- if( !nurb->bp )
- return ( EXPP_ReturnPyObjError
- ( PyExc_MemoryError,
- "allocation failed" ) );
-
- memmove( nurb->bp, tmp, sizeof( BPoint ) * npoints );
- if( tmp )
- MEM_freeN( tmp );
-
- ++nurb->pntsu;
- /* initialize new BPoint from old */
- memcpy( nurb->bp + npoints, nurb->bp,
- sizeof( BPoint ) );
-
- for( i = 0; i < 4; ++i ) {
- PyObject *item = PySequence_GetItem( pyOb, i );
-
- if (item == NULL)
- return NULL;
-
-
- nurb->bp[npoints].vec[i] = ( float ) PyFloat_AsDouble( item );
- Py_DECREF( item );
- }
-
- if (size == 5) {
- PyObject *item = PySequence_GetItem( pyOb, i );
-
- if (item == NULL)
- return NULL;
-
- nurb->bp[npoints].alfa = ( float ) PyFloat_AsDouble( item );
- Py_DECREF( item );
- }
- else {
- nurb->bp[npoints].alfa = 0.0f;
- }
-
- makeknots( nurb, 1, nurb->flagu >> 1 );
-
- } else if( size == 3 ) { /* 3 xyz coords */
- printf( "\nNot Yet Implemented!\n" );
-
- }
-
- } else {
- /* bail with error */
- return EXPP_ReturnPyObjError( PyExc_TypeError,
- "expected a sequence of 4 (or optionaly 5) floats\n" );
-
- }
-
- return ( EXPP_incr_ret( Py_None ) );
+ return 0;
}
@@ -588,20 +367,19 @@
* set index into material list
*/
-static PyObject *CurNurb_setMatIndex( BPy_CurNurb * self, PyObject * args )
+static int CurNurb_setMatIndex( BPy_CurNurb * self, PyObject * args )
{
int index;
- if( !PyArg_ParseTuple( args, "i", &( index ) ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_AttributeError,
- "expected integer argument" ) );
+ if( !PyInt_Check( args ) )
+ return EXPP_ReturnIntError ( PyExc_AttributeError,
+ "expected integer argument" );
+ index = PyInt_AsLong(args);
/* fixme: some range checking would be nice! */
self->nurb->mat_nr = index;
- Py_INCREF( Py_None );
- return Py_None;
+ return 0;
}
/*
@@ -646,22 +424,21 @@
* Possible values: 0 - uniform, 1 - endpoints, 2 - bezier
*/
-static PyObject *CurNurb_setFlagU( BPy_CurNurb * self, PyObject * args )
+static int CurNurb_setFlagU( BPy_CurNurb * self, PyObject * args )
{
int flagu;
- if( !PyArg_ParseTuple( args, "i", &( flagu ) ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_AttributeError,
- "expected integer argument" ) );
+ if( !PyInt_Check( args ) )
+ return EXPP_ReturnIntError ( PyExc_AttributeError,
+ "expected integer argument" );
+ flagu = PyInt_AsLong(args);
if( self->nurb->flagu != flagu ) {
self->nurb->flagu = flagu;
makeknots( self->nurb, 1, self->nurb->flagu >> 1 );
}
- Py_INCREF( Py_None );
- return Py_None;
+ return 0;
}
/*
@@ -689,100 +466,47 @@
* Possible values: 0 - uniform, 1 - endpoints, 2 - bezier
*/
-static PyObject *CurNurb_setFlagV( BPy_CurNurb * self, PyObject * args )
+static int CurNurb_setFlagV( BPy_CurNurb * self, PyObject * args )
{
int flagv;
- if( !PyArg_ParseTuple( args, "i", &( flagv ) ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_AttributeError,
- "expected integer argument" ) );
+ if( !PyInt_Check( args ) )
+ return EXPP_ReturnIntError ( PyExc_AttributeError,
+ "expected integer argument" );
+ flagv = PyInt_AsLong(args);
if( self->nurb->flagv != flagv ) {
self->nurb->flagv = flagv;
makeknots( self->nurb, 2, self->nurb->flagv >> 1 );
}
- Py_INCREF( Py_None );
- return Py_None;
+ return 0;
}
/*
- * CurNurb_getIter
- *
- * create an iterator for our CurNurb.
- * this iterator returns the points for this CurNurb.
+ * CurNurb_isNurb()
+ * test whether spline nurb or bezier
*/
-static PyObject *CurNurb_getIter( BPy_CurNurb * self )
+static PyObject *CurNurb_isNurb( BPy_CurNurb * self )
{
- self->bp = self->nurb->bp;
- self->bezt = self->nurb->bezt;
- self->atEnd = 0;
- self->nextPoint = 0;
-
- /* set exhausted flag if both bp and bezt are zero */
- if( ( !self->bp ) && ( !self->bezt ) )
- self->atEnd = 1;
+ /* NOTE: a Nurb has bp and bezt pointers
+ * depending on type.
+ * It is possible both are NULL if no points exist.
+ * in that case, we return False
+ */
- Py_INCREF( self );
- return ( PyObject * ) self;
+ if( self->nurb->bp ) {
+ return EXPP_incr_ret_True();
+ } else {
+ return EXPP_incr_ret_False();
+ }
}
-
-
-static PyObject *CurNurb_iterNext( BPy_CurNurb * self )
-{
- PyObject *po; /* return value */
- Nurb *pnurb = self->nurb;
- int npoints = pnurb->pntsu;
-
- /* are we at end already? */
- if( self->atEnd )
- return ( EXPP_ReturnPyObjError( PyExc_StopIteration,
- "iterator at end" ) );
-
- if( self->nextPoint < npoints ) {
-
- po = CurNurb_pointAtIndex( self->nurb, self->nextPoint );
- self->nextPoint++;
-
- return po;
-
- } else {
- self->atEnd = 1; /* set flag true */
- }
-
- return ( EXPP_ReturnPyObjError( PyExc_StopIteration,
- "iterator at end" ) );
-}
-
-
-
-/*
- * CurNurb_isNurb()
- * test whether spline nurb or bezier
- */
-
-static PyObject *CurNurb_isNurb( BPy_CurNurb * self )
-{
- /* NOTE: a Nurb has bp and bezt pointers
- * depending on type.
- * It is possible both are NULL if no points exist.
- * in that case, we return False
- */
-
- if( self->nurb->bp ) {
- return EXPP_incr_ret_True();
- } else {
- return EXPP_incr_ret_False();
- }
-}
-
-/*
- * CurNurb_isCyclic()
- * test whether spline cyclic (closed) or not (open)
- */
+/*
+ * CurNurb_isCyclic()
+ * test whether spline cyclic (closed) or not (open)
+ */
static PyObject *CurNurb_isCyclic( BPy_CurNurb * self )
{
@@ -795,205 +519,29 @@
}
}
-/*
- * CurNurb_length
- * returns the number of points in a Nurb
- * this is a tp_as_sequence method, not a regular instance method.
- */
-
-static int CurNurb_length( PyInstanceObject * inst )
-{
- Nurb *nurb;
- int len;
-
- if( CurNurb_CheckPyObject( ( PyObject * ) inst ) ) {
- nurb = ( ( BPy_CurNurb * ) inst )->nurb;
- len = nurb->pntsu;
- return len;
- }
-
- return EXPP_ReturnIntError( PyExc_RuntimeError,
- "arg is not a BPy_CurNurb" );
-}
-
-
-/*
- * CurNurb_getPoint
- * returns the Nth point in a Nurb
- * 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.
- */
-
-PyObject *CurNurb_getPoint( BPy_CurNurb * self, int index )
-{
- Nurb *myNurb;
-
- int npoints;
-
- /* for convenince */
- myNurb = self->nurb;
- npoints = myNurb->pntsu;
-
- /* DELETED: bail if index < 0 */
- /* actually, this check is not needed since python treats */
- /* negative indices as starting from the right end of a sequence */
- /*
- THAT IS WRONG, when passing a negative index, python adjusts it to be positive
- BUT it can still overflow in the negatives if the index is too small.
- For example, list[-6] when list contains 5 items means index = -1 in here.
- (theeth)
- */
-
- /* bail if no Nurbs in Curve */
- if( npoints == 0 )
- return ( EXPP_ReturnPyObjError( PyExc_IndexError,
- "no points in this CurNurb" ) );
-
- /* check index limits */
- if( index >= npoints || index < 0 )
- return ( EXPP_ReturnPyObjError( PyExc_IndexError,
- "index out of range" ) );
-
- return CurNurb_pointAtIndex( myNurb, index );
-}
-
-/*
- * CurNurb_setPoint
- * modifies the Nth point in a Nurb
- * 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.
- */
-static int CurNurb_setPoint( BPy_CurNurb * self, int index, PyObject * pyOb )
-{
- Nurb *nurb = self->nurb;
- int size;
-
- /* check index limits */
- if( index < 0 || index >= nurb->pntsu )
- return EXPP_ReturnIntError( PyExc_IndexError,
- "array assignment index out of range\n" );
-
-
- /* branch by curve type */
- if ((nurb->type & 7)==CU_BEZIER) { /* BEZIER */
- /* check parameter type */
- if( !BezTriple_CheckPyObject( pyOb ) )
- return EXPP_ReturnIntError( PyExc_TypeError,
- "expected a BezTriple\n" );
-
- /* copy bezier in array */
- memcpy( nurb->bezt + index,
- BezTriple_FromPyObject( pyOb ), sizeof( BezTriple ) );
-
- return 0; /* finished correctly */
- }
- else { /* NURBS or POLY */
- int i;
-
- /* check parameter type */
- if (!PySequence_Check( pyOb ))
- return EXPP_ReturnIntError( PyExc_TypeError,
- "expected a list of 4 (or optionaly 5 if the curve is 3D) floats\n" );
-
- size = PySequence_Size( pyOb );
-
- /* check sequence size */
- if( size != 4 && size != 5 )
- return EXPP_ReturnIntError( PyExc_TypeError,
- "expected a list of 4 (or optionaly 5 if the curve is 3D) floats\n" );
-
- /* copy x, y, z, w */
- for( i = 0; i < 4; ++i ) {
- PyObject *item = PySequence_GetItem( pyOb, i );
-
- if (item == NULL)
- return -1;
-
- nurb->bp[index].vec[i] = ( float ) PyFloat_AsDouble( item );
- Py_DECREF( item );
- }
-
- if (size == 5) { /* set tilt, if present */
- PyObject *item = PySequence_GetItem( pyOb, i );
-
- if (item == NULL)
- return -1;
-
- nurb->bp[index].alfa = ( float ) PyFloat_AsDouble( item );
- Py_DECREF( item );
- }
- else { /* if not, set default */
- nurb->bp[index].alfa = 0.0f;
- }
-
- return 0; /* finished correctly */
- }
-}
-
-
-/*
- * this is an internal routine. not callable directly from python
- */
-
-PyObject *CurNurb_pointAtIndex( Nurb * nurb, int index )
-{
- PyObject *pyo;
-
- if( nurb->bp ) { /* we have a nurb curve */
-#ifdef HAVE_BNURBPoint
- pyo = BNURBPoint_CreatePyObject( &( nurb->bp[index] ) );
-#else
- int i;
-
- /* add Tilt only if curve is 3D */
- if (nurb->flag & CU_3D)
- pyo = PyList_New( 5 );
- else
- pyo = PyList_New( 4 );
-
- for( i = 0; i < 4; i++ ) {
- PyList_SetItem( pyo, i,
- PyFloat_FromDouble( nurb->bp[index].
- vec[i] ) );
- }
-
- /* add Tilt only if curve is 3D */
- if (nurb->flag & CU_3D)
- PyList_SetItem( pyo, 4, PyFloat_FromDouble( nurb->bp[index].alfa ) );
-
-#endif
- } else if( nurb->bezt ) { /* we have a bezier */
- /* if an error occurs, we just pass it on */
- pyo = BezTriple_CreatePyObject( &( nurb->bezt[index] ) );
-
- } else /* something is horribly wrong */
- /* neither bp or bezt is set && pntsu != 0 */
- return ( EXPP_ReturnPyObjError( PyExc_SystemError,
- "inconsistant structure found" ) );
-
- return ( pyo );
-}
-
-
int CurNurb_CheckPyObject( PyObject * py_obj )
{
return ( py_obj->ob_type == &CurNurb_Type );
}
-
PyObject *CurNurb_Init( void )
{
PyObject *submodule;
CurNurb_Type.ob_type = &PyType_Type;
+ /*
+ * These are necessary for tp_getset
+ */
+ CurNurb_Type.tp_getattro = &PyObject_GenericGetAttr;
+ CurNurb_Type.tp_setattro = &PyObject_GenericSetAttr;
+
submodule =
Py_InitModule3( "Blender.CurNurb", M_CurNurb_methods,
M_CurNurb_doc );
return ( submodule );
}
-
/*
dump nurb
*/
@@ -1065,3 +613,297 @@
Py_RETURN_NONE;
}
+
+/* #####DEPRECATED###### */
+
+#if BLENDER_VERSION < 243
+
+static PyObject *CurNurb_oldsetType( BPy_CurNurb * self, PyObject * args )
+{
+#if BLENDER_VERSION < 241
+ static int depcount = 2;
+ Nurb *nurb = self->nurb;
+ short type;
+
+ if ( depcount ) {
+ printf ("CurNurb.setType() is deprecated by the type attribute.\n");
+ printf (" This method will be removed after version 2.40.\n");
+ depcount--;
+ }
+
+ /* parameter type checking */
+ if( !PyArg_ParseTuple( args, "h", &type ) )
+ return EXPP_ReturnPyObjError
+ ( PyExc_TypeError, "expected integer argument" );
+
+ /* parameter value checking */
+ if (type != CU_POLY &&
+ type != CU_BEZIER &&
+ type != CU_NURBS)
+ return EXPP_ReturnPyObjError
+ ( PyExc_ValueError, "expected integer argument" );
+
+ /* convert and raise error if impossible */
+ if (convertspline(type, nurb))
+ return EXPP_ReturnPyObjError
+ ( PyExc_ValueError, "Conversion Impossible" );
+
+ return EXPP_incr_ret( Py_None );
+#else
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "replaced by the \"type\" attribute" );
+#endif
+
+}
+
+static PyObject *CurNurb_oldsetMatIndex( BPy_CurNurb * self, PyObject * args )
+{
+#if BLENDER_VERSION < 241
+ static int depcount = 2;
+ int index;
+
+ if ( depcount ) {
+ printf ("CurNurb.setMatIndex() is deprecated by the mat_index attribute.\n");
+ printf (" This method will be removed after version 2.40.\n");
+ depcount--;
+ }
+
+ if( !PyArg_ParseTuple( args, "i", &( index ) ) )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_AttributeError,
+ "expected integer argument" ) );
+
+ /* fixme: some range checking would be nice! */
+ self->nurb->mat_nr = index;
+
+ Py_INCREF( Py_None );
+ return Py_None;
+#else
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "replaced by the \"mat_index\" attribute" );
+#endif
+}
+
+static PyObject *CurNurb_oldsetFlagU( BPy_CurNurb * self, PyObject * args )
+{
+#if BLENDER_VERSION < 241
+ static int depcount = 2;
+ int flagu;
+
+ if ( depcount ) {
+ printf ("CurNurb.setFlagU() is deprecated by the flagU attribute.\n");
+ printf (" This method will be removed after version 2.40.\n");
+ depcount--;
+ }
+
+ if( !PyArg_ParseTuple( args, "i", &( flagu ) ) )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_AttributeError,
+ "expected integer argument" ) );
+
+ if( self->nurb->flagu != flagu ) {
+ self->nurb->flagu = flagu;
+ makeknots( self->nurb, 1, self->nurb->flagu >> 1 );
+ }
+
+ Py_INCREF( Py_None );
+ return Py_None;
+#else
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "replaced by the \"flagU\" attribute" );
+#endif
+}
+
+static PyObject *CurNurb_oldsetFlagV( BPy_CurNurb * self, PyObject * args )
+{
+#if BLENDER_VERSION < 241
+ static int depcount = 2;
+ int flagv;
+
+ if ( depcount ) {
+ printf ("CurNurb.setFlagV() is deprecated by the flagV attribute.\n");
+ printf (" This method will be removed after version 2.40.\n");
+ depcount--;
+ }
+
+ if( !PyArg_ParseTuple( args, "i", &( flagv ) ) )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_AttributeError,
+ "expected integer argument" ) );
+
+ if( self->nurb->flagv != flagv ) {
+ self->nurb->flagv = flagv;
+ makeknots( self->nurb, 2, self->nurb->flagv >> 1 );
+ }
+
+ Py_INCREF( Py_None );
+ return Py_None;
+#else
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "replaced by the \"flagV\" attribute" );
+#endif
+}
+
+static
+PyObject* CurNurb_getLength ( BPy_CurNurb *self)
+{
+#if BLENDER_VERSION < 241
+ static int depcount = 2;
+ PyObject *attr = PyInt_FromLong( self->nurb->pntsu );
+
+ if ( depcount ) {
+ printf ("CurNurb.getLength() is deprecated by the len() operator.\n");
+ printf (" This method will be removed after version 2.40.\n");
+ depcount--;
+ }
+ if ( attr )
+ return attr;
+ else
+ return EXPP_ReturnPyObjError( PyExc_MemoryError,
+ "couldn't create PyObject" );
+#else
+ return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
+ "replaced by \"len()\" operator" );
+#endif
+}
+
+/*
+ * CurNurb_appendPointToNurb
+ * this is a non-bpy utility func to add a point to a given nurb.
+ * notice the first arg is Nurb*.
+ *
+ * this is a helper routine for Curve_appendNurb(), which will be
+ * deprecated in V2.41 (if not before)
+ */
+
+#if BLENDER_VERSION < 241
+
+PyObject *CurNurb_appendPointToNurb( Nurb * nurb, PyObject * args )
+{
+ int i;
+ int size;
+ PyObject *pyOb;
+ int npoints = nurb->pntsu;
+
+ /*
+ do we have a list of four floats or a BezTriple?
+ */
+ if( !PyArg_ParseTuple( args, "O", &pyOb ))
+ return EXPP_ReturnPyObjError
+ ( PyExc_RuntimeError,
+ "Internal error parsing arguments" );
+
+
+
+ /* if curve is empty, adjust type depending on input type */
+ if (nurb->bezt==NULL && nurb->bp==NULL) {
+ if (BezTriple_CheckPyObject( pyOb ))
+ nurb->type |= CU_BEZIER;
+ else if (PySequence_Check( pyOb ))
+ nurb->type |= CU_NURBS;
+ else
+ return( EXPP_ReturnPyObjError( PyExc_TypeError,
+ "Expected a BezTriple or a Sequence of 4 (or 5) floats" ) );
+ }
+
+
+
+ if ((nurb->type & 7)==CU_BEZIER) {
+ BezTriple *tmp;
+
+ if( !BezTriple_CheckPyObject( pyOb ) )
+ return( EXPP_ReturnPyObjError( PyExc_TypeError,
+ "Expected a BezTriple\n" ) );
+
+/* printf("\ndbg: got a BezTriple\n"); */
+ tmp = nurb->bezt; /* save old points */
+ nurb->bezt =
+ ( BezTriple * ) MEM_mallocN( sizeof( BezTriple ) *
+ ( npoints + 1 ),
+ "CurNurb_append2" );
+
+ if( !nurb->bezt )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_MemoryError, "allocation failed" ) );
+
+ /* copy old points to new */
+ memmove( nurb->bezt, tmp, sizeof( BezTriple ) * npoints );
+ if( tmp )
+ MEM_freeN( tmp );
+ nurb->pntsu++;
+ /* add new point to end of list */
+ memcpy( nurb->bezt + npoints,
+ BezTriple_FromPyObject( pyOb ), sizeof( BezTriple ) );
+
+ }
+ else if( PySequence_Check( pyOb ) ) {
+ size = PySequence_Size( pyOb );
+/* printf("\ndbg: got a sequence of size %d\n", size ); */
+ if( size == 4 || size == 5 ) {
+ BPoint *tmp;
+
+ tmp = nurb->bp; /* save old pts */
+
+ nurb->bp =
+ ( BPoint * ) MEM_mallocN( sizeof( BPoint ) *
+ ( npoints + 1 ),
+ "CurNurb_append1" );
+ if( !nurb->bp )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_MemoryError,
+ "allocation failed" ) );
+
+ if( tmp ) {
+ memmove( nurb->bp, tmp, sizeof( BPoint ) * npoints );
+ MEM_freeN( tmp );
+ }
+
+ ++nurb->pntsu;
+ /* initialize new BPoint from old */
+ memcpy( nurb->bp + npoints, nurb->bp,
+ sizeof( BPoint ) );
+
+ for( i = 0; i < 4; ++i ) {
+ PyObject *item = PySequence_GetItem( pyOb, i );
+
+ if (item == NULL)
+ return NULL;
+
+
+ nurb->bp[npoints].vec[i] = ( float ) PyFloat_AsDouble( item );
+ Py_DECREF( item );
+ }
+
+ if (size == 5) {
+ PyObject *item = PySequence_GetItem( pyOb, i );
+
+ if (item == NULL)
+ return NULL;
+
+ nurb->bp[npoints].alfa = ( float ) PyFloat_AsDouble( item );
+ Py_DECREF( item );
+ }
+ else {
+ nurb->bp[npoints].alfa = 0.0f;
+ }
+
+ makeknots( nurb, 1, nurb->flagu >> 1 );
+
+ } else if( size == 3 ) { /* 3 xyz coords */
+ printf( "\nNot Yet Implemented!\n" );
+
+ }
+
+ } else {
+ /* bail with error */
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected a sequence of 4 (or optionaly 5) floats\n" );
+
+ }
+
+ return ( EXPP_incr_ret( Py_None ) );
+}
+#endif
+
+#endif
+

File Metadata

Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
21/cf/e7648a3e2f0545afa32cd1c8e43e

Event Timeline