diff options
10 files changed, 218 insertions, 176 deletions
diff --git a/source/blender/freestyle/intern/python/BPy_Convert.cpp b/source/blender/freestyle/intern/python/BPy_Convert.cpp index 1d9dc372bd0..332f6061c8f 100644 --- a/source/blender/freestyle/intern/python/BPy_Convert.cpp +++ b/source/blender/freestyle/intern/python/BPy_Convert.cpp @@ -376,6 +376,39 @@ Nature::EdgeNature EdgeNature_from_BPy_Nature( PyObject* obj ) { return static_cast<Nature::EdgeNature>( PyInt_AsLong(obj) ); } +Vec2f * Vec2f_ptr_from_PyObject( PyObject* obj ) { + Vec2f *v; + if( (v = Vec2f_ptr_from_Vector( obj )) ) + return v; + if( (v = Vec2f_ptr_from_PyList( obj )) ) + return v; + if( (v = Vec2f_ptr_from_PyTuple( obj )) ) + return v; + return NULL; +} + +Vec3f * Vec3f_ptr_from_PyObject( PyObject* obj ) { + Vec3f *v; + if( (v = Vec3f_ptr_from_Vector( obj )) ) + return v; + if( (v = Vec3f_ptr_from_PyList( obj )) ) + return v; + if( (v = Vec3f_ptr_from_PyTuple( obj )) ) + return v; + return NULL; +} + +Vec3r * Vec3r_ptr_from_PyObject( PyObject* obj ) { + Vec3r *v; + if( (v = Vec3r_ptr_from_Vector( obj )) ) + return v; + if( (v = Vec3r_ptr_from_PyList( obj )) ) + return v; + if( (v = Vec3r_ptr_from_PyTuple( obj )) ) + return v; + return NULL; +} + Vec2f * Vec2f_ptr_from_Vector( PyObject* obj ) { PyObject *v; if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 2) @@ -424,6 +457,58 @@ Vec3r * Vec3r_ptr_from_Vector( PyObject* obj ) { return new Vec3r(x,y,z); } +Vec2f * Vec2f_ptr_from_PyList( PyObject* obj ) { + if( !PyList_Check(obj) || PyList_Size(obj) != 2 ) + return NULL; + float x = PyFloat_AsDouble(PyList_GetItem(obj, 0)); + float y = PyFloat_AsDouble(PyList_GetItem(obj, 1)); + return new Vec2f(x,y); +} + +Vec3f * Vec3f_ptr_from_PyList( PyObject* obj ) { + if( !PyList_Check(obj) || PyList_Size(obj) != 3 ) + return NULL; + float x = PyFloat_AsDouble(PyList_GetItem(obj, 0)); + float y = PyFloat_AsDouble(PyList_GetItem(obj, 1)); + float z = PyFloat_AsDouble(PyList_GetItem(obj, 2)); + return new Vec3f(x,y,z); +} + +Vec3r * Vec3r_ptr_from_PyList( PyObject* obj ) { + if( !PyList_Check(obj) || PyList_Size(obj) != 3 ) + return NULL; + float x = PyFloat_AsDouble(PyList_GetItem(obj, 0)); + float y = PyFloat_AsDouble(PyList_GetItem(obj, 1)); + float z = PyFloat_AsDouble(PyList_GetItem(obj, 2)); + return new Vec3r(x,y,z); +} + +Vec2f * Vec2f_ptr_from_PyTuple( PyObject* obj ) { + if( !PyTuple_Check(obj) || PyTuple_Size(obj) != 2 ) + return NULL; + float x = PyFloat_AsDouble(PyTuple_GetItem(obj, 0)); + float y = PyFloat_AsDouble(PyTuple_GetItem(obj, 1)); + return new Vec2f(x,y); +} + +Vec3f * Vec3f_ptr_from_PyTuple( PyObject* obj ) { + if( !PyTuple_Check(obj) || PyTuple_Size(obj) != 3 ) + return NULL; + float x = PyFloat_AsDouble(PyTuple_GetItem(obj, 0)); + float y = PyFloat_AsDouble(PyTuple_GetItem(obj, 1)); + float z = PyFloat_AsDouble(PyTuple_GetItem(obj, 2)); + return new Vec3f(x,y,z); +} + +Vec3r * Vec3r_ptr_from_PyTuple( PyObject* obj ) { + if( !PyTuple_Check(obj) || PyTuple_Size(obj) != 3 ) + return NULL; + float x = PyFloat_AsDouble(PyTuple_GetItem(obj, 0)); + float y = PyFloat_AsDouble(PyTuple_GetItem(obj, 1)); + float z = PyFloat_AsDouble(PyTuple_GetItem(obj, 2)); + return new Vec3r(x,y,z); +} + /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BPy_Convert.h b/source/blender/freestyle/intern/python/BPy_Convert.h index 3d0e3adf235..3d298c0db9a 100644 --- a/source/blender/freestyle/intern/python/BPy_Convert.h +++ b/source/blender/freestyle/intern/python/BPy_Convert.h @@ -115,9 +115,18 @@ bool bool_from_PyBool( PyObject *b ); IntegrationType IntegrationType_from_BPy_IntegrationType( PyObject* obj ); Stroke::MediumType MediumType_from_BPy_MediumType( PyObject* obj ); Nature::EdgeNature EdgeNature_from_BPy_Nature( PyObject* obj ); +Vec2f * Vec2f_ptr_from_PyObject( PyObject* obj ); +Vec3f * Vec3f_ptr_from_PyObject( PyObject* obj ); +Vec3r * Vec3r_ptr_from_PyObject( PyObject* obj ); Vec2f * Vec2f_ptr_from_Vector( PyObject* obj ); Vec3f * Vec3f_ptr_from_Vector( PyObject* obj ); Vec3r * Vec3r_ptr_from_Vector( PyObject* obj ); +Vec2f * Vec2f_ptr_from_PyList( PyObject* obj ); +Vec3f * Vec3f_ptr_from_PyList( PyObject* obj ); +Vec3r * Vec3r_ptr_from_PyList( PyObject* obj ); +Vec2f * Vec2f_ptr_from_PyTuple( PyObject* obj ); +Vec3f * Vec3f_ptr_from_PyTuple( PyObject* obj ); +Vec3r * Vec3r_ptr_from_PyTuple( PyObject* obj ); diff --git a/source/blender/freestyle/intern/python/BPy_FrsNoise.cpp b/source/blender/freestyle/intern/python/BPy_FrsNoise.cpp index 8fc27ae462d..945cd9921cc 100644 --- a/source/blender/freestyle/intern/python/BPy_FrsNoise.cpp +++ b/source/blender/freestyle/intern/python/BPy_FrsNoise.cpp @@ -1,4 +1,5 @@ #include "BPy_FrsNoise.h" +#include "BPy_Convert.h" #include <sstream> @@ -165,18 +166,16 @@ PyObject * FrsNoise_turbulence2( BPy_FrsNoise *self , PyObject *args) { float f2, f3; unsigned int i = 4; - if(!( PyArg_ParseTuple(args, "O!ff|I", &PyList_Type, &obj1, &f2, &f3, &i) )) + if(!( PyArg_ParseTuple(args, "Off|I", &obj1, &f2, &f3, &i) )) return NULL; - if( PyList_Size(obj1) != 2 ) { - stringstream msg("FrsNoise::turbulence2() accepts a list of 2 elements ("); - msg << PyList_Size(obj1) << " found)"; - PyErr_SetString(PyExc_TypeError, msg.str().c_str()); + Vec2f *v = Vec2f_ptr_from_PyObject(obj1); + if( !v ) { + PyErr_SetString(PyExc_TypeError, "argument 1 must be a 2D vector (either a list of 2 elements or Vector)"); return NULL; } - - Vec2f v( PyFloat_AsDouble(PyList_GetItem(obj1, 0)), PyFloat_AsDouble(PyList_GetItem(obj1, 1)) ); - - return PyFloat_FromDouble( self->n->turbulence2(v, f2, f3, i) ); + float t = self->n->turbulence2(*v, f2, f3, i); + delete v; + return PyFloat_FromDouble( t ); } PyObject * FrsNoise_turbulence3( BPy_FrsNoise *self , PyObject *args) { @@ -184,20 +183,16 @@ PyObject * FrsNoise_turbulence3( BPy_FrsNoise *self , PyObject *args) { float f2, f3; unsigned int i = 4; - if(!( PyArg_ParseTuple(args, "O!ff|I", &PyList_Type, &obj1, &f2, &f3, &i) )) + if(!( PyArg_ParseTuple(args, "Off|I", &obj1, &f2, &f3, &i) )) return NULL; - if( PyList_Size(obj1) != 3 ) { - stringstream msg("FrsNoise::turbulence3() accepts a list of 3 elements ("); - msg << PyList_Size(obj1) << " found)"; - PyErr_SetString(PyExc_TypeError, msg.str().c_str()); + Vec3f *v = Vec3f_ptr_from_PyObject(obj1); + if( !v ) { + PyErr_SetString(PyExc_TypeError, "argument 1 must be a 3D vector (either a list of 3 elements or Vector)"); return NULL; } - - Vec3f v( PyFloat_AsDouble(PyList_GetItem(obj1, 0)), - PyFloat_AsDouble(PyList_GetItem(obj1, 1)), - PyFloat_AsDouble(PyList_GetItem(obj1, 2)) ); - - return PyFloat_FromDouble( self->n->turbulence3(v, f2, f3, i) ); + float t = self->n->turbulence3(*v, f2, f3, i); + delete v; + return PyFloat_FromDouble( t ); } PyObject * FrsNoise_smoothNoise1( BPy_FrsNoise *self , PyObject *args) { @@ -212,37 +207,31 @@ PyObject * FrsNoise_smoothNoise1( BPy_FrsNoise *self , PyObject *args) { PyObject * FrsNoise_smoothNoise2( BPy_FrsNoise *self , PyObject *args) { PyObject *obj; - if(!( PyArg_ParseTuple(args, "O", &PyList_Type, &obj) )) + if(!( PyArg_ParseTuple(args, "O", &obj) )) return NULL; - if( PyList_Size(obj) != 2 ) { - stringstream msg("FrsNoise::smoothNoise2() accepts a list of 2 elements ("); - msg << PyList_Size(obj) << " found)"; - PyErr_SetString(PyExc_TypeError, msg.str().c_str()); + Vec2f *v = Vec2f_ptr_from_PyObject(obj); + if( !v ) { + PyErr_SetString(PyExc_TypeError, "argument 1 must be a 2D vector (either a list of 2 elements or Vector)"); return NULL; } - - Vec2f v( PyFloat_AsDouble(PyList_GetItem(obj, 0)), PyFloat_AsDouble(PyList_GetItem(obj, 1)) ); - - return PyFloat_FromDouble( self->n->smoothNoise2(v) ); + float t = self->n->smoothNoise2(*v); + delete v; + return PyFloat_FromDouble( t ); } PyObject * FrsNoise_smoothNoise3( BPy_FrsNoise *self , PyObject *args) { PyObject *obj; - if(!( PyArg_ParseTuple(args, "O", &PyList_Type, &obj) )) + if(!( PyArg_ParseTuple(args, "O", &obj) )) return NULL; - if( PyList_Size(obj) != 3 ) { - stringstream msg("FrsNoise::smoothNoise3() accepts a list of 3 elements ("); - msg << PyList_Size(obj) << " found)"; - PyErr_SetString(PyExc_TypeError, msg.str().c_str()); + Vec3f *v = Vec3f_ptr_from_PyObject(obj); + if( !v ) { + PyErr_SetString(PyExc_TypeError, "argument 1 must be a 3D vector (either a list of 3 elements or Vector)"); return NULL; } - - Vec3f v( PyFloat_AsDouble(PyList_GetItem(obj, 0)), - PyFloat_AsDouble(PyList_GetItem(obj, 1)), - PyFloat_AsDouble(PyList_GetItem(obj, 2)) ); - - return PyFloat_FromDouble( self->n->smoothNoise3(v) ); + float t = self->n->smoothNoise3(*v); + delete v; + return PyFloat_FromDouble( t ); } diff --git a/source/blender/freestyle/intern/python/BPy_Interface0D.cpp b/source/blender/freestyle/intern/python/BPy_Interface0D.cpp index fb8c27c4205..89eb3600665 100644 --- a/source/blender/freestyle/intern/python/BPy_Interface0D.cpp +++ b/source/blender/freestyle/intern/python/BPy_Interface0D.cpp @@ -189,8 +189,7 @@ int Interface0D___init__(BPy_Interface0D *self, PyObject *args, PyObject *kwds) void Interface0D___dealloc__(BPy_Interface0D* self) { - if( self->if0D->py_if0D ) - delete self->if0D; + delete self->if0D; self->ob_type->tp_free((PyObject*)self); } diff --git a/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp b/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp index 6bc25ed8fdd..8f20e740580 100644 --- a/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp +++ b/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp @@ -328,14 +328,16 @@ PyObject * StrokeAttribute_setColor( BPy_StrokeAttribute *self, PyObject *args ) if(!( PyArg_ParseTuple(args, "O|OO", &obj1, &obj2, &obj3) )) return NULL; - - if( PyList_Check(obj1) && !obj2 && !obj3 ){ - - Vec3f v( PyFloat_AsDouble( PyList_GetItem(obj1, 0) ), - PyFloat_AsDouble( PyList_GetItem(obj1, 1) ), - PyFloat_AsDouble( PyList_GetItem(obj1, 2) ) ); - - self->sa->setColor( v ); + + if( obj1 && !obj2 && !obj3 ){ + + Vec3f *v = Vec3f_ptr_from_PyObject(obj1); + if( !v ) { + PyErr_SetString(PyExc_TypeError, "argument 1 must be a 3D vector (either a list of 3 elements or Vector)"); + return NULL; + } + self->sa->setColor( *v ); + delete v; } else if( obj1 && obj2 && obj3 ){ @@ -367,12 +369,15 @@ PyObject * StrokeAttribute_setThickness( BPy_StrokeAttribute *self, PyObject *ar if(!( PyArg_ParseTuple(args, "O|O", &obj1, &obj2) )) return NULL; - if( PyList_Check(obj1) && !obj2 ){ + if( obj1 && !obj2 ){ - Vec2f v( PyFloat_AsDouble( PyList_GetItem(obj1, 0) ), - PyFloat_AsDouble( PyList_GetItem(obj1, 1) ) ); - - self->sa->setThickness( v ); + Vec2f *v = Vec2f_ptr_from_PyObject(obj1); + if( !v ) { + PyErr_SetString(PyExc_TypeError, "argument 1 must be a 2D vector (either a list of 2 elements or Vector)"); + return NULL; + } + self->sa->setThickness( *v ); + delete v; } else if( obj1 && obj2 ){ @@ -416,19 +421,14 @@ PyObject * StrokeAttribute_setAttributeVec2f( BPy_StrokeAttribute *self, PyObjec if(!( PyArg_ParseTuple(args, "sO", &s, &obj) )) return NULL; - - if( PyList_Check(obj) && PyList_Size(obj) > 1) { - - Vec2f v( PyFloat_AsDouble( PyList_GetItem(obj, 0) ), - PyFloat_AsDouble( PyList_GetItem(obj, 1) ) ); - - self->sa->setAttributeVec2f( s, v ); - - } else { - PyErr_SetString(PyExc_TypeError, "invalid arguments"); + Vec2f *v = Vec2f_ptr_from_PyObject(obj); + if( !v ) { + PyErr_SetString(PyExc_TypeError, "argument 2 must be a 2D vector (either a list of 2 elements or Vector)"); return NULL; } - + self->sa->setAttributeVec2f( s, *v ); + delete v; + Py_RETURN_NONE; } @@ -438,19 +438,13 @@ PyObject * StrokeAttribute_setAttributeVec3f( BPy_StrokeAttribute *self, PyObjec if(!( PyArg_ParseTuple(args, "sO", &s, &obj) )) return NULL; - - if( PyList_Check(obj) && PyList_Size(obj) > 2 ) { - - Vec3f v( PyFloat_AsDouble( PyList_GetItem(obj, 0) ), - PyFloat_AsDouble( PyList_GetItem(obj, 1) ), - PyFloat_AsDouble( PyList_GetItem(obj, 2) ) ); - - self->sa->setAttributeVec3f( s, v ); - - } else { - PyErr_SetString(PyExc_TypeError, "invalid arguments"); + Vec3f *v = Vec3f_ptr_from_PyObject(obj); + if( !v ) { + PyErr_SetString(PyExc_TypeError, "argument 2 must be a 3D vector (either a list of 3 elements or Vector)"); return NULL; } + self->sa->setAttributeVec3f( s, *v ); + delete v; Py_RETURN_NONE; } diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp index 87d3ef4ecd0..46fd1c64758 100644 --- a/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp @@ -130,20 +130,26 @@ int SVertex___init__(BPy_SVertex *self, PyObject *args, PyObject *kwds) { PyObject *py_point = 0; BPy_Id *py_id = 0; + - if (! PyArg_ParseTuple(args, "|OO", &py_point, &py_id) ) + if (! PyArg_ParseTuple(args, "|OO!", &py_point, &Id_Type, &py_id) ) return -1; - if( py_point && py_id && PyList_Check(py_point) && PyList_Size(py_point) == 3 ) { - Vec3r v( PyFloat_AsDouble( PyList_GetItem(py_point, 0) ), - PyFloat_AsDouble( PyList_GetItem(py_point, 1) ), - PyFloat_AsDouble( PyList_GetItem(py_point, 2) ) ); - - self->sv = new SVertex( v, *(py_id->id) ); - } else { + if( py_point && py_id ) { + Vec3r *v = Vec3r_ptr_from_PyObject(py_point); + if( !v ) { + PyErr_SetString(PyExc_TypeError, "argument 1 must be a 3D vector (either a list of 3 elements or Vector)"); + return -1; + } + self->sv = new SVertex( *v, *(py_id->id) ); + delete v; + } else if( !py_point && !py_id ) { self->sv = new SVertex(); + } else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; } - + self->py_if0D.if0D = self->sv; return 0; @@ -193,19 +199,15 @@ PyObject * SVertex_viewvertex( BPy_SVertex *self ) { PyObject *SVertex_setPoint3D( BPy_SVertex *self , PyObject *args) { PyObject *py_point; - if(!( PyArg_ParseTuple(args, "O!", &PyList_Type, &py_point) )) + if(!( PyArg_ParseTuple(args, "O", &py_point) )) return NULL; - if( PyList_Size(py_point) != 3 ) { - stringstream msg("SVertex::setPoint3D() accepts a list of 3 elements ("); - msg << PyList_Size(py_point) << " found)"; - PyErr_SetString(PyExc_TypeError, msg.str().c_str()); + Vec3r *v = Vec3r_ptr_from_PyObject(py_point); + if( !v ) { + PyErr_SetString(PyExc_TypeError, "argument 1 must be a 3D vector (either a list of 3 elements or Vector)"); return NULL; } - - Vec3r v( PyFloat_AsDouble( PyList_GetItem(py_point, 0) ), - PyFloat_AsDouble( PyList_GetItem(py_point, 1) ), - PyFloat_AsDouble( PyList_GetItem(py_point, 2) ) ); - self->sv->setPoint3D( v ); + self->sv->setPoint3D( *v ); + delete v; Py_RETURN_NONE; } @@ -213,19 +215,15 @@ PyObject *SVertex_setPoint3D( BPy_SVertex *self , PyObject *args) { PyObject *SVertex_setPoint2D( BPy_SVertex *self , PyObject *args) { PyObject *py_point; - if(!( PyArg_ParseTuple(args, "O!", &PyList_Type, &py_point) )) + if(!( PyArg_ParseTuple(args, "O", &py_point) )) return NULL; - if( PyList_Size(py_point) != 3 ) { - stringstream msg("SVertex::setPoint2D() accepts a list of 3 elements ("); - msg << PyList_Size(py_point) << " found)"; - PyErr_SetString(PyExc_TypeError, msg.str().c_str()); + Vec3r *v = Vec3r_ptr_from_PyObject(py_point); + if( !v ) { + PyErr_SetString(PyExc_TypeError, "argument 1 must be a 3D vector (either a list of 3 elements or Vector)"); return NULL; } - - Vec3r v( PyFloat_AsDouble( PyList_GetItem(py_point, 0) ), - PyFloat_AsDouble( PyList_GetItem(py_point, 1) ), - PyFloat_AsDouble( PyList_GetItem(py_point, 2) ) ); - self->sv->setPoint2D( v ); + self->sv->setPoint2D( *v ); + delete v; Py_RETURN_NONE; } @@ -233,19 +231,15 @@ PyObject *SVertex_setPoint2D( BPy_SVertex *self , PyObject *args) { PyObject *SVertex_AddNormal( BPy_SVertex *self , PyObject *args) { PyObject *py_normal; - if(!( PyArg_ParseTuple(args, "O!", &PyList_Type, &py_normal) )) + if(!( PyArg_ParseTuple(args, "O", &py_normal) )) return NULL; - if( PyList_Size(py_normal) != 3 ) { - stringstream msg("SVertex::AddNormal() accepts a list of 3 elements ("); - msg << PyList_Size(py_normal) << " found)"; - PyErr_SetString(PyExc_TypeError, msg.str().c_str()); + Vec3r *n = Vec3r_ptr_from_PyObject(py_normal); + if( !n ) { + PyErr_SetString(PyExc_TypeError, "argument 1 must be a 3D vector (either a list of 3 elements or Vector)"); return NULL; } - - Vec3r n( PyFloat_AsDouble( PyList_GetItem(py_normal, 0) ), - PyFloat_AsDouble( PyList_GetItem(py_normal, 1) ), - PyFloat_AsDouble( PyList_GetItem(py_normal, 2) ) ); - self->sv->AddNormal( n ); + self->sv->AddNormal( *n ); + delete n; Py_RETURN_NONE; } diff --git a/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp index 2c957dd7016..969aa1d7216 100644 --- a/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp @@ -229,30 +229,18 @@ PyObject *StrokeVertex_setPoint( BPy_StrokeVertex *self , PyObject *args) { if(!( PyArg_ParseTuple(args, "O|O", &obj1, &obj2) )) return NULL; - if( PyList_Check(obj1) && !obj2 ){ - if ( PyList_Size(obj1) != 2 ) { - stringstream msg("StrokeVertex::setPoint() accepts a list of 2 elements ("); - msg << PyList_Size(obj1) << " found)"; - PyErr_SetString(PyExc_TypeError, msg.str().c_str()); + if( obj1 && !obj2 ){ + Vec2f *v = Vec2f_ptr_from_PyObject(obj1); + if( !v ) { + PyErr_SetString(PyExc_TypeError, "argument 1 must be a 2D vector (either a list of 2 elements or Vector)"); return NULL; } - Vec2f v( PyFloat_AsDouble( PyList_GetItem(obj1, 0) ), - PyFloat_AsDouble( PyList_GetItem(obj1, 1) ) ); - self->sv->setPoint( v ); - } else if ( VectorObject_Check(obj1) && !obj2) { - if ( ((VectorObject *)obj1)->size != 2 ) { - stringstream msg("StrokeVertex::setPoint() accepts a vector of 2 elements ("); - msg << ((VectorObject *)obj1)->size << " found)"; - PyErr_SetString(PyExc_TypeError, msg.str().c_str()); - return NULL; - } - Vec2f *v = Vec2f_ptr_from_Vector( obj1 ); self->sv->setPoint( *v ); delete v; } else if( PyFloat_Check(obj1) && obj2 && PyFloat_Check(obj2) ){ self->sv->setPoint( PyFloat_AsDouble(obj1), PyFloat_AsDouble(obj2) ); } else { - PyErr_SetString(PyExc_TypeError, "StrokeVertex::setPoint(): unknown argument type"); + PyErr_SetString(PyExc_TypeError, "invalid arguments"); return NULL; } diff --git a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp index c6bc201e37d..aa0ba7dfc46 100644 --- a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp @@ -184,20 +184,15 @@ PyObject * FEdgeSharp_bMaterial( BPy_FEdgeSharp *self ) { PyObject * FEdgeSharp_setNormalA( BPy_FEdgeSharp *self, PyObject *args ) { PyObject *obj = 0; - if(!( PyArg_ParseTuple(args, "O!", &PyList_Type, &obj) )) + if(!( PyArg_ParseTuple(args, "O", &obj) )) return NULL; - if( PyList_Size(obj) != 3 ) { - stringstream msg("FEdgeSharp::setNormalA() accepts a list of 3 elements ("); - msg << PyList_Size(obj) << " found)"; - PyErr_SetString(PyExc_TypeError, msg.str().c_str()); + Vec3r *v = Vec3r_ptr_from_PyObject(obj); + if( !v ) { + PyErr_SetString(PyExc_TypeError, "argument 1 must be a 3D vector (either a list of 3 elements or Vector)"); return NULL; } - - Vec3r v( PyFloat_AsDouble( PyList_GetItem(obj,0) ), - PyFloat_AsDouble( PyList_GetItem(obj,1) ), - PyFloat_AsDouble( PyList_GetItem(obj,2) ) ); - - self->fes->setNormalA( v ); + self->fes->setNormalA( *v ); + delete v; Py_RETURN_NONE; } @@ -205,20 +200,15 @@ PyObject * FEdgeSharp_setNormalA( BPy_FEdgeSharp *self, PyObject *args ) { PyObject * FEdgeSharp_setNormalB( BPy_FEdgeSharp *self, PyObject *args ) { PyObject *obj = 0; - if(!( PyArg_ParseTuple(args, "O!", &PyList_Type, &obj) )) + if(!( PyArg_ParseTuple(args, "O", &obj) )) return NULL; - if( PyList_Size(obj) != 3 ) { - stringstream msg("FEdgeSharp::setNormalB() accepts a list of 3 elements ("); - msg << PyList_Size(obj) << " found)"; - PyErr_SetString(PyExc_TypeError, msg.str().c_str()); + Vec3r *v = Vec3r_ptr_from_PyObject(obj); + if( !v ) { + PyErr_SetString(PyExc_TypeError, "argument 1 must be a 3D vector (either a list of 3 elements or Vector)"); return NULL; } - - Vec3r v( PyFloat_AsDouble( PyList_GetItem(obj,0) ), - PyFloat_AsDouble( PyList_GetItem(obj,1) ), - PyFloat_AsDouble( PyList_GetItem(obj,2) ) ); - - self->fes->setNormalB( v ); + self->fes->setNormalB( *v ); + delete v; Py_RETURN_NONE; } diff --git a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp index bb0e6eef4e4..9913503db58 100644 --- a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp @@ -23,9 +23,9 @@ static PyObject * FEdgeSmooth_setMaterialIndex( BPy_FEdgeSmooth *self, PyObject static PyMethodDef BPy_FEdgeSmooth_methods[] = { {"normal", ( PyCFunction ) FEdgeSmooth_normal, METH_NOARGS, "() Returns the normal to the Face it is running accross."}, {"materialIndex", ( PyCFunction ) FEdgeSmooth_materialIndex, METH_NOARGS, "() Returns the index of the material of the face it is running accross. "}, - {"aMaterial", ( PyCFunction ) FEdgeSmooth_material, METH_NOARGS, "() Returns the material of the face it is running accross. "}, - {"setNormalA", ( PyCFunction ) FEdgeSmooth_setNormal, METH_VARARGS, "([x,y,z]) Sets the normal to the Face it is running accross."}, - {"setaMaterialIndex", ( PyCFunction ) FEdgeSmooth_setMaterialIndex, METH_VARARGS, "(unsigned int i) Sets the index of the material of the face it is running accross. "}, + {"material", ( PyCFunction ) FEdgeSmooth_material, METH_NOARGS, "() Returns the material of the face it is running accross. "}, + {"setNormal", ( PyCFunction ) FEdgeSmooth_setNormal, METH_VARARGS, "([x,y,z]) Sets the normal to the Face it is running accross."}, + {"setMaterialIndex", ( PyCFunction ) FEdgeSmooth_setMaterialIndex, METH_VARARGS, "(unsigned int i) Sets the index of the material of the face it is running accross. "}, {NULL, NULL, 0, NULL} }; @@ -162,20 +162,15 @@ PyObject * FEdgeSmooth_material( BPy_FEdgeSmooth *self ) { PyObject * FEdgeSmooth_setNormal( BPy_FEdgeSmooth *self, PyObject *args ) { PyObject *obj = 0; - if(!( PyArg_ParseTuple(args, "O!", &PyList_Type, &obj) )) + if(!( PyArg_ParseTuple(args, "O", &obj) )) return NULL; - if( PyList_Size(obj) != 3 ) { - stringstream msg("FEdgeSmooth::setNormal() accepts a list of 3 elements ("); - msg << PyList_Size(obj) << " found)"; - PyErr_SetString(PyExc_TypeError, msg.str().c_str()); + Vec3r *v = Vec3r_ptr_from_PyObject(obj); + if( !v ) { + PyErr_SetString(PyExc_TypeError, "argument 1 must be a 3D vector (either a list of 3 elements or Vector)"); return NULL; } - - Vec3r v( PyFloat_AsDouble( PyList_GetItem(obj,0) ), - PyFloat_AsDouble( PyList_GetItem(obj,1) ), - PyFloat_AsDouble( PyList_GetItem(obj,2) ) ); - - self->fes->setNormal( v ); + self->fes->setNormal( *v ); + delete v; Py_RETURN_NONE; } diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.cpp index 1d22be137e3..798b8a8e4ac 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.cpp +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.cpp @@ -105,17 +105,16 @@ int CalligraphicShader___init__( BPy_CalligraphicShader* self, PyObject *args) PyObject *obj3 = 0, *obj4 = 0; - if(!( PyArg_ParseTuple(args, "ddO!O", &d1, &d2, &PyList_Type, &obj3, &obj4) )) + if(!( PyArg_ParseTuple(args, "ddOO", &d1, &d2, &obj3, &obj4) )) return -1; - if( PyList_Size(obj3) != 2 ) { - stringstream msg("CalligraphicShader() accepts a list of 2 elements ("); - msg << PyList_Size(obj3) << " found)"; - PyErr_SetString(PyExc_TypeError, msg.str().c_str()); + Vec2f *v = Vec2f_ptr_from_PyObject(obj3); + if( !v ) { + PyErr_SetString(PyExc_TypeError, "argument 3 must be a 2D vector (either a list of 2 elements or Vector)"); return -1; } + self->py_ss.ss = new CalligraphicShader(d1, d2, *v, bool_from_PyBool(obj4) ); + delete v; - Vec2f v( PyFloat_AsDouble(PyList_GetItem(obj3,0)), PyFloat_AsDouble(PyList_GetItem(obj3,1)) ); - self->py_ss.ss = new CalligraphicShader(d1, d2, v, bool_from_PyBool(obj4) ); return 0; } |