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

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/python/api2_2x/Curve.c')
-rw-r--r--source/blender/python/api2_2x/Curve.c188
1 files changed, 64 insertions, 124 deletions
diff --git a/source/blender/python/api2_2x/Curve.c b/source/blender/python/api2_2x/Curve.c
index 109a4572387..adf7c39b45c 100644
--- a/source/blender/python/api2_2x/Curve.c
+++ b/source/blender/python/api2_2x/Curve.c
@@ -1,5 +1,6 @@
/*
* $Id$
+ *
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
@@ -31,6 +32,7 @@
#include "Curve.h" /*This must come first*/
+#include "BLI_blenlib.h"
#include "BKE_main.h"
#include "BKE_displist.h"
#include "BKE_global.h"
@@ -122,6 +124,7 @@ static PyObject *Curve_getIter( BPy_Curve * self );
static PyObject *Curve_iterNext( BPy_Curve * self );
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 );
@@ -138,13 +141,7 @@ struct chartrans *text_to_curve( Object * ob, int mode );
PyObject *Curve_getName( BPy_Curve * self )
{
- PyObject *attr = PyString_FromString( self->curve->id.name + 2 );
-
- if( attr )
- return attr;
-
- return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "couldn't get Curve.name attribute" );
+ return PyString_FromString( self->curve->id.name + 2 );
}
static int Curve_newsetName( BPy_Curve * self, PyObject * args )
@@ -164,13 +161,7 @@ static int Curve_newsetName( BPy_Curve * self, PyObject * args )
static PyObject *Curve_getPathLen( BPy_Curve * self )
{
- PyObject *attr = PyInt_FromLong( ( long ) self->curve->pathlen );
-
- if( attr )
- return attr;
-
- return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "couldn't get Curve.pathlen attribute" );
+ return PyInt_FromLong( ( long ) self->curve->pathlen );
}
@@ -191,25 +182,13 @@ static int Curve_newsetPathLen( BPy_Curve * self, PyObject * args )
static PyObject *Curve_getTotcol( BPy_Curve * self )
{
- PyObject *attr = PyInt_FromLong( ( long ) self->curve->totcol );
-
- if( attr )
- return attr;
-
- return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "couldn't get Curve.totcol attribute" );
+ return PyInt_FromLong( ( long ) self->curve->totcol );
}
PyObject *Curve_getMode( BPy_Curve * self )
{
- PyObject *attr = PyInt_FromLong( ( long ) self->curve->flag );
-
- if( attr )
- return attr;
-
- return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "couldn't get Curve.flag attribute" );
+ return PyInt_FromLong( ( long ) self->curve->flag );
}
@@ -230,13 +209,7 @@ static int Curve_newsetMode( BPy_Curve * self, PyObject * args )
PyObject *Curve_getBevresol( BPy_Curve * self )
{
- PyObject *attr = PyInt_FromLong( ( long ) self->curve->bevresol );
-
- if( attr )
- return attr;
-
- return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "couldn't get Curve.bevresol attribute" );
+ return PyInt_FromLong( ( long ) self->curve->bevresol );
}
static int Curve_newsetBevresol( BPy_Curve * self, PyObject * args )
@@ -263,13 +236,7 @@ static int Curve_newsetBevresol( BPy_Curve * self, PyObject * args )
PyObject *Curve_getResolu( BPy_Curve * self )
{
- PyObject *attr = PyInt_FromLong( ( long ) self->curve->resolu );
-
- if( attr )
- return attr;
-
- return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "couldn't get Curve.resolu attribute" );
+ return PyInt_FromLong( ( long ) self->curve->resolu );
}
@@ -301,13 +268,7 @@ static int Curve_newsetResolu( BPy_Curve * self, PyObject * args )
PyObject *Curve_getResolv( BPy_Curve * self )
{
- PyObject *attr = PyInt_FromLong( ( long ) self->curve->resolv );
-
- if( attr )
- return attr;
-
- return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "couldn't get Curve.resolv attribute" );
+ return PyInt_FromLong( ( long ) self->curve->resolv );
}
static int Curve_newsetResolv( BPy_Curve * self, PyObject * args )
@@ -333,13 +294,7 @@ static int Curve_newsetResolv( BPy_Curve * self, PyObject * args )
PyObject *Curve_getWidth( BPy_Curve * self )
{
- PyObject *attr = PyFloat_FromDouble( ( double ) self->curve->width );
-
- if( attr )
- return attr;
-
- return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "couldn't get Curve.width attribute" );
+ return PyFloat_FromDouble( ( double ) self->curve->width );
}
@@ -367,13 +322,7 @@ static int Curve_newsetWidth( BPy_Curve * self, PyObject * args )
PyObject *Curve_getExt1( BPy_Curve * self )
{
- PyObject *attr = PyFloat_FromDouble( ( double ) self->curve->ext1 );
-
- if( attr )
- return attr;
-
- return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "couldn't get Curve.ext1 attribute" );
+ return PyFloat_FromDouble( ( double ) self->curve->ext1 );
}
@@ -390,9 +339,9 @@ static int Curve_newsetExt1( BPy_Curve * self, PyObject * args )
value = (float)PyFloat_AS_DOUBLE( num );
Py_DECREF( num );
- if(value > 5.0f || value < 0.0f)
+ if(value > 100.0f || value < 0.0f)
return EXPP_ReturnIntError( PyExc_ValueError,
- "acceptable values are between 0.0 and 5.0" );
+ "acceptable values are between 0.0 and 100.0" );
self->curve->ext1 = value;
return 0;
@@ -400,13 +349,7 @@ static int Curve_newsetExt1( BPy_Curve * self, PyObject * args )
PyObject *Curve_getExt2( BPy_Curve * self )
{
- PyObject *attr = PyFloat_FromDouble( ( double ) self->curve->ext2 );
-
- if( attr )
- return attr;
-
- return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "couldn't get Curve.ext2 attribute" );
+ return PyFloat_FromDouble( ( double ) self->curve->ext2 );
}
@@ -535,14 +478,8 @@ static PyObject *Curve_getControlPoint( BPy_Curve * self, PyObject * args )
static PyObject *Curve_getLoc( BPy_Curve * self )
{
- PyObject *attr = Py_BuildValue( "[f,f,f]", self->curve->loc[0],
+ return Py_BuildValue( "[f,f,f]", self->curve->loc[0],
self->curve->loc[1], self->curve->loc[2] );
-
- if( attr )
- return attr;
-
- return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "couldn't get Curve.loc attribute" );
}
static int Curve_newsetLoc( BPy_Curve * self, PyObject * args )
@@ -573,14 +510,8 @@ TypeError:
static PyObject *Curve_getRot( BPy_Curve * self )
{
- PyObject *attr = Py_BuildValue( "[f,f,f]", self->curve->rot[0],
+ return Py_BuildValue( "[f,f,f]", self->curve->rot[0],
self->curve->rot[1], self->curve->rot[2] );
-
- if( attr )
- return attr;
-
- return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "couldn't get Curve.rot attribute" );
}
static int Curve_newsetRot( BPy_Curve * self, PyObject * args )
@@ -611,14 +542,8 @@ TypeError:
static PyObject *Curve_getSize( BPy_Curve * self )
{
- PyObject *attr = Py_BuildValue( "[f,f,f]", self->curve->size[0],
+ return Py_BuildValue( "[f,f,f]", self->curve->size[0],
self->curve->size[1], self->curve->size[2] );
-
- if( attr )
- return attr;
-
- return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "couldn't get Curve.size attribute" );
}
static int Curve_newsetSize( BPy_Curve * self, PyObject * args )
@@ -845,8 +770,6 @@ 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 */
@@ -868,14 +791,7 @@ static PyObject *Curve_appendPoint( BPy_Curve * self, PyObject * args )
return EXPP_ReturnPyObjError( PyExc_ValueError,
"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;
+ return CurNurb_appendPointToNurb( nurb, coord_args );
}
@@ -885,29 +801,16 @@ static PyObject *Curve_appendPoint( BPy_Curve * self, PyObject * args )
returns a refernce to the newly created nurb.
*****/
-static PyObject *Curve_appendNurb( BPy_Curve * self, PyObject * args )
+static PyObject *Curve_appendNurb( BPy_Curve * self, PyObject * value )
{
- 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;
+
+ if( CurNurb_appendPointToNurb( new_nurb, value ) ) {
new_nurb->resolu = self->curve->resolu;
new_nurb->resolv = self->curve->resolv;
new_nurb->hide = 0;
@@ -918,9 +821,9 @@ static PyObject *Curve_appendNurb( BPy_Curve * self, PyObject * args )
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->f1 = SELECT;
+ new_nurb->bezt->f2 = SELECT;
+ new_nurb->bezt->f3 = SELECT;
new_nurb->bezt->hide = 0;
/* calchandlesNurb( new_nurb ); */
} else { /* set up bp */
@@ -934,6 +837,7 @@ static PyObject *Curve_appendNurb( BPy_Curve * self, PyObject * args )
new_nurb->knotsu = 0;
/*makenots( new_nurb, 1, new_nurb->flagu >> 1); */
}
+ BLI_addtail( &self->curve->nurb, new_nurb);
} else {
freeNurb( new_nurb );
@@ -1208,6 +1112,42 @@ PyObject *Curve_getNurb( BPy_Curve * self, int n )
}
+/*
+ * Curve_setNurb
+ * In this case only remove the item, we could allow adding later.
+ */
+static int Curve_setNurb( BPy_Curve * self, int n, PyObject * value )
+{
+ Nurb *pNurb;
+ int i;
+
+ /* 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 == 0 )
+ return ( EXPP_ReturnIntError( PyExc_IndexError,
+ "no Nurbs in this Curve" ) );
+ /* set pointer to nth Nurb */
+ for( pNurb = self->curve->nurb.first, i = 0;
+ pNurb != 0 && i < n; pNurb = pNurb->next, ++i )
+ /**/;
+
+ if( !pNurb ) /* we came to the end of the list */
+ return ( EXPP_ReturnIntError( PyExc_IndexError,
+ "index out of range" ) );
+
+ if (value) {
+ return ( EXPP_ReturnIntError( PyExc_RuntimeError,
+ "assigning curves is not yet supported" ) );
+ } else {
+ BLI_remlink(&self->curve->nurb, pNurb);
+ freeNurb(pNurb);
+ }
+ return 0;
+}
+
/*****************************************************************************/
/* Function: Curve_compare */
/* Description: This compares 2 curve python types, == or != only. */
@@ -1493,7 +1433,7 @@ Sets a control point "},
"(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,
+ {"appendNurb", ( PyCFunction ) Curve_appendNurb, METH_O,
"( new_nurb ) - adds a new nurb to the Curve"},
{"update", ( PyCFunction ) Curve_update, METH_NOARGS,
"( ) - updates display lists after changes to Curve"},
@@ -1527,7 +1467,7 @@ static PySequenceMethods Curve_as_sequence = {
( intargfunc ) 0, /* sq_repeat */
( intargfunc ) Curve_getNurb, /* sq_item */
( intintargfunc ) 0, /* sq_slice */
- 0, /* sq_ass_item */
+ ( intobjargproc ) Curve_setNurb, /* sq_ass_item - only so you can do del curve[i] */
0, /* sq_ass_slice */
( objobjproc ) 0, /* sq_contains */
0,