diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2009-03-30 01:50:10 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2009-03-30 01:50:10 +0400 |
commit | a377b74638245f8eb1a956c9840e16a448de553e (patch) | |
tree | f9d9197211b89561069bf887de764468924ab9e7 /source/blender/freestyle/intern/python/Interface1D | |
parent | fbd92e985ed5bf19a92839b4b3fec9a93ce6519f (diff) |
Improvements on error handling in the Python API.
Diffstat (limited to 'source/blender/freestyle/intern/python/Interface1D')
5 files changed, 112 insertions, 180 deletions
diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp index 0718c18b253..1773e86c065 100644 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp @@ -163,6 +163,7 @@ int FEdge___init__(BPy_FEdge *self, PyObject *args, PyObject *kwds) } else if( BPy_SVertex_Check(obj1) && BPy_SVertex_Check(obj2) ) { self->fe = new FEdge( ((BPy_SVertex *) obj1)->sv, ((BPy_SVertex *) obj2)->sv ); } else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); return -1; } @@ -203,9 +204,11 @@ PyObject * FEdge_vertexB( BPy_FEdge *self ) { PyObject * FEdge___getitem__( BPy_FEdge *self, PyObject *args ) { int i; - if(!( PyArg_ParseTuple(args, "i", &i) && (i == 0 || i == 1) )) { - cout << "ERROR: FEdge___getitem__" << endl; - Py_RETURN_NONE; + if(!( PyArg_ParseTuple(args, "i", &i) )) + return NULL; + if(!(i == 0 || i == 1)) { + PyErr_SetString(PyExc_IndexError, "index must be either 0 or 1"); + return NULL; } if( SVertex *v = self->fe->operator[](i) ) @@ -242,10 +245,8 @@ PyObject * FEdge_isSmooth( BPy_FEdge *self ) { PyObject *FEdge_setVertexA( BPy_FEdge *self , PyObject *args) { PyObject *py_sv; - if(!( PyArg_ParseTuple(args, "O", &py_sv) && BPy_SVertex_Check(py_sv) )) { - cout << "ERROR: FEdge_setVertexA" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O!", &SVertex_Type, &py_sv) )) + return NULL; self->fe->setVertexA( ((BPy_SVertex *) py_sv)->sv ); @@ -268,10 +269,8 @@ PyObject *FEdge_setVertexB( BPy_FEdge *self , PyObject *args) { PyObject *FEdge_setId( BPy_FEdge *self , PyObject *args) { PyObject *py_id; - if(!( PyArg_ParseTuple(args, "O", &py_id) && BPy_Id_Check(py_id) )) { - cout << "ERROR: FEdge_setId" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O!", &Id_Type, &py_id) )) + return NULL; self->fe->setId(*( ((BPy_Id *) py_id)->id )); @@ -282,10 +281,8 @@ PyObject *FEdge_setId( BPy_FEdge *self , PyObject *args) { PyObject *FEdge_setNextEdge( BPy_FEdge *self , PyObject *args) { PyObject *py_fe; - if(!( PyArg_ParseTuple(args, "O", &py_fe) && BPy_FEdge_Check(py_fe) )) { - cout << "ERROR: FEdge_setNextEdge" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O!", &FEdge_Type, &py_fe) )) + return NULL; self->fe->setNextEdge( ((BPy_FEdge *) py_fe)->fe ); @@ -295,10 +292,8 @@ PyObject *FEdge_setNextEdge( BPy_FEdge *self , PyObject *args) { PyObject *FEdge_setPreviousEdge( BPy_FEdge *self , PyObject *args) { PyObject *py_fe; - if(!( PyArg_ParseTuple(args, "O", &py_fe) && BPy_FEdge_Check(py_fe) )) { - cout << "ERROR: FEdge_setPreviousEdge" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O!", &FEdge_Type, &py_fe) )) + return NULL; self->fe->setPreviousEdge( ((BPy_FEdge *) py_fe)->fe ); @@ -308,10 +303,8 @@ PyObject *FEdge_setPreviousEdge( BPy_FEdge *self , PyObject *args) { PyObject * FEdge_setNature( BPy_FEdge *self, PyObject *args ) { PyObject *py_n; - if(!( PyArg_ParseTuple(args, "O", &py_n) && BPy_Nature_Check(py_n) )) { - cout << "ERROR: FEdge_setNature" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O!", &Nature_Type, &py_n) )) + return NULL; PyObject *i = (PyObject *) &( ((BPy_Nature *) py_n)->i ); self->fe->setNature( PyInt_AsLong(i) ); @@ -323,10 +316,8 @@ PyObject * FEdge_setNature( BPy_FEdge *self, PyObject *args ) { PyObject * FEdge_setViewEdge( BPy_FEdge *self, PyObject *args ) { PyObject *py_ve; - if(!( PyArg_ParseTuple(args, "O", &py_ve) && BPy_ViewEdge_Check(py_ve) )) { - cout << "ERROR: FEdge_setViewEdge" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O!", &ViewEdge_Type, &py_ve) )) + return NULL; ViewEdge *ve = ((BPy_ViewEdge *) py_ve)->ve; self->fe->setViewEdge( ve ); @@ -339,10 +330,8 @@ PyObject * FEdge_setViewEdge( BPy_FEdge *self, PyObject *args ) { PyObject *FEdge_setSmooth( BPy_FEdge *self , PyObject *args) { PyObject *py_b; - if(!( PyArg_ParseTuple(args, "O", &py_b) && PyBool_Check(py_b) )) { - cout << "ERROR: FEdge_setSmooth" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O!", &PyBool_Type, &py_b) )) + return NULL; self->fe->setSmooth( bool_from_PyBool(py_b) ); @@ -364,10 +353,8 @@ PyObject * FEdge_verticesEnd( BPy_FEdge *self ) { PyObject * FEdge_pointsBegin( BPy_FEdge *self, PyObject *args ) { float f = 0; - if(!( PyArg_ParseTuple(args, "|f", &f) )) { - cout << "ERROR: FEdge_pointsBegin" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "|f", &f) )) + return NULL; Interface0DIterator if0D_it( self->fe->pointsBegin(f) ); return BPy_Interface0DIterator_from_Interface0DIterator( if0D_it ); @@ -376,10 +363,8 @@ PyObject * FEdge_pointsBegin( BPy_FEdge *self, PyObject *args ) { PyObject * FEdge_pointsEnd( BPy_FEdge *self, PyObject *args ) { float f = 0; - if(!( PyArg_ParseTuple(args, "|f", &f) )) { - cout << "ERROR: FEdge_pointsEnd" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "|f", &f) )) + return NULL; Interface0DIterator if0D_it( self->fe->pointsEnd(f) ); return BPy_Interface0DIterator_from_Interface0DIterator( if0D_it ); diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp index 1506092511a..541391e05a7 100644 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp @@ -138,18 +138,13 @@ int FrsCurve___init__(BPy_FrsCurve *self, PyObject *args, PyObject *kwds) self->c = new Curve(); } else if( BPy_FrsCurve_Check(obj) ) { - if( ((BPy_FrsCurve *) obj)->c ) - self->c = new Curve(*( ((BPy_FrsCurve *) obj)->c )); - else - return -1; + self->c = new Curve(*( ((BPy_FrsCurve *) obj)->c )); } else if( BPy_Id_Check(obj) ) { - if( ((BPy_Id *) obj)->id ) - self->c = new Curve(*( ((BPy_Id *) obj)->id )); - else - return -1; + self->c = new Curve(*( ((BPy_Id *) obj)->id )); } else { + PyErr_SetString(PyExc_TypeError, "invalid argument"); return -1; } @@ -162,37 +157,39 @@ int FrsCurve___init__(BPy_FrsCurve *self, PyObject *args, PyObject *kwds) PyObject * FrsCurve_push_vertex_back( BPy_FrsCurve *self, PyObject *args ) { PyObject *obj; - if(!( PyArg_ParseTuple(args, "O", &obj) )) { - cout << "ERROR: FrsCurve_push_vertex_back" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O", &obj) )) + return NULL; if( BPy_CurvePoint_Check(obj) ) { self->c->push_vertex_back( ((BPy_CurvePoint *) obj)->cp ); } else if( BPy_SVertex_Check(obj) ) { self->c->push_vertex_back( ((BPy_SVertex *) obj)->sv ); + } else { + PyErr_SetString(PyExc_TypeError, "invalid argument"); + return NULL; } Py_RETURN_NONE; } PyObject * FrsCurve_push_vertex_front( BPy_FrsCurve *self, PyObject *args ) { - PyObject *obj; - - if(!( PyArg_ParseTuple(args, "O", &obj) )) { - cout << "ERROR: FrsCurve_push_vertex_front" << endl; - Py_RETURN_NONE; - } + PyObject *obj; - if( BPy_CurvePoint_Check(obj) ) { - self->c->push_vertex_front( ((BPy_CurvePoint *) obj)->cp ); - } else if( BPy_SVertex_Check(obj) ) { - self->c->push_vertex_front( ((BPy_SVertex *) obj)->sv ); - } + if(!( PyArg_ParseTuple(args, "O", &obj) )) + return NULL; - Py_RETURN_NONE; + if( BPy_CurvePoint_Check(obj) ) { + self->c->push_vertex_front( ((BPy_CurvePoint *) obj)->cp ); + } else if( BPy_SVertex_Check(obj) ) { + self->c->push_vertex_front( ((BPy_SVertex *) obj)->sv ); + } else { + PyErr_SetString(PyExc_TypeError, "invalid argument"); + return NULL; } + Py_RETURN_NONE; +} + PyObject * FrsCurve_empty( BPy_FrsCurve *self ) { return PyBool_from_bool( self->c->empty() ); } @@ -219,10 +216,8 @@ PyObject * FrsCurve_verticesEnd( BPy_FrsCurve *self ) { PyObject * FrsCurve_pointsBegin( BPy_FrsCurve *self, PyObject *args ) { float f = 0; - if(!( PyArg_ParseTuple(args, "|f", &f) )) { - cout << "ERROR: FEdge_pointsBegin" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "|f", &f) )) + return NULL; Interface0DIterator if0D_it( self->c->pointsBegin(f) ); return BPy_Interface0DIterator_from_Interface0DIterator( if0D_it ); @@ -231,10 +226,8 @@ PyObject * FrsCurve_pointsBegin( BPy_FrsCurve *self, PyObject *args ) { PyObject * FrsCurve_pointsEnd( BPy_FrsCurve *self, PyObject *args ) { float f = 0; - if(!( PyArg_ParseTuple(args, "|f", &f) )) { - cout << "ERROR: FEdge_pointsEnd" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "|f", &f) )) + return NULL; Interface0DIterator if0D_it( self->c->pointsEnd(f) ); return BPy_Interface0DIterator_from_Interface0DIterator( if0D_it ); diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp index d9f46774929..f7c5e261db5 100644 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp @@ -45,7 +45,7 @@ static PyObject * Stroke_pointsEnd( BPy_Stroke *self , PyObject *args); static PyMethodDef BPy_Stroke_methods[] = { {"__getitem__", ( PyCFunction ) Stroke___getitem__, METH_O, "(int i) Returns the i-th StrokeVertex constituting the Stroke."}, {"ComputeSampling", ( PyCFunction ) Stroke_ComputeSampling, METH_VARARGS, "(int nVertices) Compute the sampling needed to get nVertices vertices. If the specified number of vertices is less than the actual number of vertices, the actual sampling value is returned."}, - {"Resample", ( PyCFunction ) Stroke_Resample, METH_VARARGS, "(float f | int n) Resampling method. If the argument is a float, Resamples the curve with a given sampling; if this sampling is < to the actual sampling value, no resampling is done. If the argument is an integer, Resamples the curve so that it eventually has n. That means it is going to add n-vertices_size, if vertices_size is the number of points we already have. Is vertices_size >= n, no resampling is done."}, + {"Resample", ( PyCFunction ) Stroke_Resample, METH_VARARGS, "(float f | int n) Resampling method. If the argument is a float, Resamples the curve with a given sampling; if this sampling is < to the actual sampling value, no resampling is done. If the argument is an integer, Resamples the curve so that it eventually has n. That means it is going to add n-vertices_size, if vertices_size is the number of points we already have. Is vertices_size >= n, no resampling is done."}, {"RemoveVertex", ( PyCFunction ) Stroke_RemoveVertex, METH_VARARGS, "(StrokeVertex sv) Removes the stroke vertex sv from the stroke. The length and curvilinear abscissa are updated consequently."}, {"InsertVertex", ( PyCFunction ) Stroke_InsertVertex, METH_VARARGS, "(StrokeVertex sv, StrokeVertexIterator next) Inserts the stroke vertex iVertex in the stroke before next. The length, curvilinear abscissa are updated consequently."}, {"getMediumType", ( PyCFunction ) Stroke_getMediumType, METH_NOARGS, "() Returns the MediumType used for this Stroke."}, @@ -241,10 +241,8 @@ PyObject * Stroke___getitem__( BPy_Stroke *self, PyObject *item ) { PyObject * Stroke_ComputeSampling( BPy_Stroke *self, PyObject *args ) { int i; - if(!( PyArg_ParseTuple(args, "i", &i) )) { - cout << "ERROR: Stroke_ComputeSampling" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "i", &i) )) + return NULL; return PyFloat_FromDouble( self->s->ComputeSampling( i ) ); } @@ -252,15 +250,17 @@ PyObject * Stroke_ComputeSampling( BPy_Stroke *self, PyObject *args ) { PyObject * Stroke_Resample( BPy_Stroke *self, PyObject *args ) { PyObject *obj; - if(!( PyArg_ParseTuple(args, "O", &obj) )) { - cout << "ERROR: Stroke_Resample" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O", &obj) )) + return NULL; if( PyInt_Check(obj) ) self->s->Resample( (int) PyInt_AsLong(obj) ); else if( PyFloat_Check(obj) ) self->s->Resample( (float) PyFloat_AsDouble(obj) ); + else { + PyErr_SetString(PyExc_TypeError, "invalid argument"); + return NULL; + } Py_RETURN_NONE; } @@ -268,11 +268,8 @@ PyObject * Stroke_Resample( BPy_Stroke *self, PyObject *args ) { PyObject * Stroke_InsertVertex( BPy_Stroke *self, PyObject *args ) { PyObject *py_sv = 0, *py_sv_it = 0; - if(!( PyArg_ParseTuple(args, "OO", &py_sv, &py_sv_it) && - BPy_StrokeVertex_Check(py_sv) && BPy_StrokeVertexIterator_Check(py_sv_it) )) { - cout << "ERROR: Stroke_InsertVertex" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O!O!", &StrokeVertex_Type, &py_sv, &StrokeVertexIterator_Type, &py_sv_it) )) + return NULL; StrokeVertex *sv = ((BPy_StrokeVertex *) py_sv)->sv; StrokeInternal::StrokeVertexIterator sv_it(*( ((BPy_StrokeVertexIterator *) py_sv_it)->sv_it )); @@ -284,13 +281,15 @@ PyObject * Stroke_InsertVertex( BPy_Stroke *self, PyObject *args ) { PyObject * Stroke_RemoveVertex( BPy_Stroke *self, PyObject *args ) { PyObject *py_sv; - if(!( PyArg_ParseTuple(args, "O", &py_sv) )) { - cout << "ERROR: Stroke_RemoveVertex" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O!", &StrokeVertex_Type, &py_sv) )) + return NULL; - if( BPy_StrokeVertex_Check(py_sv) && ((BPy_StrokeVertex *) py_sv)->sv ) + if( ((BPy_StrokeVertex *) py_sv)->sv ) self->s->RemoveVertex( ((BPy_StrokeVertex *) py_sv)->sv ); + else { + PyErr_SetString(PyExc_TypeError, "invalid argument"); + return NULL; + } Py_RETURN_NONE; } @@ -311,13 +310,10 @@ PyObject * Stroke_hasTips( BPy_Stroke *self ) { PyObject *Stroke_setId( BPy_Stroke *self , PyObject *args) { PyObject *py_id; - if(!( PyArg_ParseTuple(args, "O", &py_id) && BPy_Id_Check(py_id) )) { - cout << "ERROR: Stroke_setId" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O!", &Id_Type, &py_id) )) + return NULL; - if( ((BPy_Id *) py_id)->id ) - self->s->setId(*( ((BPy_Id *) py_id)->id )); + self->s->setId(*( ((BPy_Id *) py_id)->id )); Py_RETURN_NONE; } @@ -325,10 +321,8 @@ PyObject *Stroke_setId( BPy_Stroke *self , PyObject *args) { PyObject *Stroke_setLength( BPy_Stroke *self , PyObject *args) { float f; - if(!( PyArg_ParseTuple(args, "f", &f) )) { - cout << "ERROR: Stroke_setLength" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "f", &f) )) + return NULL; self->s->setLength( f ); @@ -338,10 +332,8 @@ PyObject *Stroke_setLength( BPy_Stroke *self , PyObject *args) { PyObject *Stroke_setMediumType( BPy_Stroke *self , PyObject *args) { PyObject *py_mt; - if(!( PyArg_ParseTuple(args, "O", &py_mt) && BPy_MediumType_Check(py_mt) )) { - cout << "ERROR: Stroke_setMediumType" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O!", &MediumType_Type, &py_mt) )) + return NULL; self->s->setMediumType( static_cast<Stroke::MediumType>(PyInt_AsLong(py_mt)) ); @@ -351,10 +343,8 @@ PyObject *Stroke_setMediumType( BPy_Stroke *self , PyObject *args) { PyObject *Stroke_setTextureId( BPy_Stroke *self , PyObject *args) { unsigned int i; - if(!( PyArg_ParseTuple(args, "I", &i) )) { - cout << "ERROR: Stroke_setTextureId" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "I", &i) )) + return NULL; self->s->setTextureId( i ); @@ -364,10 +354,8 @@ PyObject *Stroke_setTextureId( BPy_Stroke *self , PyObject *args) { PyObject *Stroke_setTips( BPy_Stroke *self , PyObject *args) { PyObject *py_b; - if(!( PyArg_ParseTuple(args, "O", &py_b) && PyBool_Check(py_b) )) { - cout << "ERROR: Stroke_setTips" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O!", &PyBool_Type, &py_b) )) + return NULL; self->s->setTips( bool_from_PyBool(py_b) ); @@ -377,10 +365,9 @@ PyObject *Stroke_setTips( BPy_Stroke *self , PyObject *args) { PyObject * Stroke_strokeVerticesBegin( BPy_Stroke *self , PyObject *args) { float f = 0; - if(!( PyArg_ParseTuple(args, "|f", &f) )){ - cout << "ERROR: Stroke_pointsBegin" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "|f", &f) )) + return NULL; + StrokeInternal::StrokeVertexIterator sv_it( self->s->strokeVerticesBegin(f) ); return BPy_StrokeVertexIterator_from_StrokeVertexIterator( sv_it, 0 ); } @@ -407,10 +394,8 @@ PyObject * Stroke_verticesEnd( BPy_Stroke *self ) { PyObject * Stroke_pointsBegin( BPy_Stroke *self , PyObject *args) { float f = 0; - if(!( PyArg_ParseTuple(args, "|f", &f) )) { - cout << "ERROR: Stroke_pointsBegin" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "|f", &f) )) + return NULL; Interface0DIterator if0D_it( self->s->pointsBegin(f) ); return BPy_Interface0DIterator_from_Interface0DIterator( if0D_it ); @@ -419,10 +404,8 @@ PyObject * Stroke_pointsBegin( BPy_Stroke *self , PyObject *args) { PyObject * Stroke_pointsEnd( BPy_Stroke *self , PyObject *args) { float f = 0; - if(!( PyArg_ParseTuple(args, "|f", &f) )) { - cout << "ERROR: Stroke_pointsEnd" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "|f", &f) )) + return NULL; Interface0DIterator if0D_it( self->s->pointsEnd(f) ); return BPy_Interface0DIterator_from_Interface0DIterator( if0D_it ); diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_ViewEdge.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_ViewEdge.cpp index e32b90a2382..8ac65edde89 100644 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_ViewEdge.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_ViewEdge.cpp @@ -225,10 +225,8 @@ PyObject * ViewEdge_getChainingTimeStamp( BPy_ViewEdge *self ) { PyObject * ViewEdge_setChainingTimeStamp( BPy_ViewEdge *self, PyObject *args) { int timestamp = 0 ; - if( !PyArg_ParseTuple(args, "i", ×tamp) ) { - cout << "ERROR: ViewEdge_setChainingTimeStamp" << endl; - Py_RETURN_NONE; - } + if( !PyArg_ParseTuple(args, "i", ×tamp) ) + return NULL; self->ve->setChainingTimeStamp( timestamp ); @@ -238,10 +236,8 @@ PyObject * ViewEdge_setChainingTimeStamp( BPy_ViewEdge *self, PyObject *args) { PyObject *ViewEdge_setA( BPy_ViewEdge *self , PyObject *args) { PyObject *py_vv; - if(!( PyArg_ParseTuple(args, "O", &py_vv) && BPy_ViewVertex_Check(py_vv) )) { - cout << "ERROR: ViewEdge_setA" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O!", &ViewVertex_Type, &py_vv) )) + return NULL; self->ve->setA( ((BPy_ViewVertex *) py_vv)->vv ); @@ -251,10 +247,8 @@ PyObject *ViewEdge_setA( BPy_ViewEdge *self , PyObject *args) { PyObject *ViewEdge_setB( BPy_ViewEdge *self , PyObject *args) { PyObject *py_vv; - if(!( PyArg_ParseTuple(args, "O", &py_vv) && BPy_ViewVertex_Check(py_vv) )) { - cout << "ERROR: ViewEdge_setB" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O!", &ViewVertex_Type, &py_vv) )) + return NULL; self->ve->setB( ((BPy_ViewVertex *) py_vv)->vv ); @@ -264,10 +258,8 @@ PyObject *ViewEdge_setB( BPy_ViewEdge *self , PyObject *args) { PyObject * ViewEdge_setNature( BPy_ViewEdge *self, PyObject *args ) { PyObject *py_n; - if(!( PyArg_ParseTuple(args, "O", &py_n) && BPy_Nature_Check(py_n) )) { - cout << "ERROR: ViewEdge_setNature" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O!", &Nature_Type, &py_n) )) + return NULL; PyObject *i = (PyObject *) &( ((BPy_Nature *) py_n)->i ); self->ve->setNature( PyInt_AsLong(i) ); @@ -278,10 +270,8 @@ PyObject * ViewEdge_setNature( BPy_ViewEdge *self, PyObject *args ) { PyObject * ViewEdge_setFEdgeA( BPy_ViewEdge *self, PyObject *args ) { PyObject *py_fe; - if(!( PyArg_ParseTuple(args, "O", &py_fe) && BPy_FEdge_Check(py_fe) )) { - cout << "ERROR: ViewEdge_setFEdgeA" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O!", &FEdge_Type, &py_fe) )) + return NULL; self->ve->setFEdgeA( ((BPy_FEdge *) py_fe)->fe ); @@ -291,10 +281,8 @@ PyObject * ViewEdge_setFEdgeA( BPy_ViewEdge *self, PyObject *args ) { PyObject * ViewEdge_setFEdgeB( BPy_ViewEdge *self, PyObject *args ) { PyObject *py_fe; - if(!( PyArg_ParseTuple(args, "O", &py_fe) && BPy_FEdge_Check(py_fe) )) { - cout << "ERROR: ViewEdge_setFEdgeB" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O!", &FEdge_Type, &py_fe) )) + return NULL; self->ve->setFEdgeB( ((BPy_FEdge *) py_fe)->fe ); @@ -304,10 +292,8 @@ PyObject * ViewEdge_setFEdgeB( BPy_ViewEdge *self, PyObject *args ) { PyObject * ViewEdge_setShape( BPy_ViewEdge *self, PyObject *args ) { PyObject *py_vs; - if(!( PyArg_ParseTuple(args, "O", &py_vs) && BPy_ViewShape_Check(py_vs) )) { - cout << "ERROR: ViewEdge_setShape" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O", &ViewShape_Type, &py_vs) )) + return NULL; self->ve->setShape( ((BPy_ViewShape *) py_vs)->vs ); @@ -317,10 +303,8 @@ PyObject * ViewEdge_setShape( BPy_ViewEdge *self, PyObject *args ) { PyObject * ViewEdge_setId( BPy_ViewEdge *self, PyObject *args ) { PyObject *py_id; - if(!( PyArg_ParseTuple(args, "O", &py_id) && BPy_Id_Check(py_id) )) { - cout << "ERROR: ViewEdge_setId" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O!", &Id_Type, &py_id) )) + return NULL; Id id(*( ((BPy_Id *) py_id)->id )); self->ve->setId( id ); @@ -337,10 +321,8 @@ PyObject * ViewEdge_UpdateFEdges( BPy_ViewEdge *self ) { PyObject * ViewEdge_setaShape( BPy_ViewEdge *self, PyObject *args ) { PyObject *py_vs; - if(!( PyArg_ParseTuple(args, "O", &py_vs) && BPy_ViewShape_Check(py_vs) )) { - cout << "ERROR: ViewEdge_setaShape" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O!", &ViewShape_Type, &py_vs) )) + return NULL; ViewShape *vs = ((BPy_ViewShape *) py_vs)->vs; self->ve->setaShape( vs ); @@ -351,10 +333,8 @@ PyObject * ViewEdge_setaShape( BPy_ViewEdge *self, PyObject *args ) { PyObject * ViewEdge_setQI( BPy_ViewEdge *self, PyObject *args ) { int qi; - if(!( PyArg_ParseTuple(args, "i", &qi) )) { - cout << "ERROR: ViewEdge_setQI" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "i", &qi) )) + return NULL; self->ve->setQI( qi ); @@ -375,10 +355,8 @@ PyObject * ViewEdge_verticesEnd( BPy_ViewEdge *self ) { PyObject * ViewEdge_pointsBegin( BPy_ViewEdge *self, PyObject *args ) { float f = 0; - if(!( PyArg_ParseTuple(args, "|f", &f) )) { - cout << "ERROR: ViewEdge_pointsBegin" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "|f", &f) )) + return NULL; Interface0DIterator if0D_it( self->ve->pointsBegin(f) ); return BPy_Interface0DIterator_from_Interface0DIterator( if0D_it ); @@ -387,10 +365,8 @@ PyObject * ViewEdge_pointsBegin( BPy_ViewEdge *self, PyObject *args ) { PyObject * ViewEdge_pointsEnd( BPy_ViewEdge *self, PyObject *args ) { float f = 0; - if(!( PyArg_ParseTuple(args, "|f", &f) )) { - cout << "ERROR: ViewEdge_pointsEnd" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "|f", &f) )) + return NULL; Interface0DIterator if0D_it( self->ve->pointsEnd(f) ); return BPy_Interface0DIterator_from_Interface0DIterator( if0D_it ); diff --git a/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.cpp b/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.cpp index 12c79743559..f30b2bbdd96 100644 --- a/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.cpp @@ -125,18 +125,13 @@ int Chain___init__(BPy_Chain *self, PyObject *args, PyObject *kwds) self->c = new Chain(); } else if( BPy_Chain_Check(obj) ) { - if( ((BPy_Chain *) obj)->c ) - self->c = new Chain(*( ((BPy_Chain *) obj)->c )); - else - return -1; + self->c = new Chain(*( ((BPy_Chain *) obj)->c )); } else if( BPy_Id_Check(obj) ) { - if( ((BPy_Id *) obj)->id ) - self->c = new Chain(*( ((BPy_Id *) obj)->id )); - else - return -1; + self->c = new Chain(*( ((BPy_Id *) obj)->id )); } else { + PyErr_SetString(PyExc_TypeError, "invalid argument"); return -1; } |