[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19538] branches/soc-2008-mxcurioni/source /blender/freestyle/intern/python/Interface0D: Improvements on error handling in the Python API.
Tamito Kajiyama
rd6t-kjym at asahi-net.or.jp
Sat Apr 4 17:26:12 CEST 2009
Revision: 19538
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19538
Author: kjym3
Date: 2009-04-04 17:26:12 +0200 (Sat, 04 Apr 2009)
Log Message:
-----------
Improvements on error handling in the Python API.
Modified Paths:
--------------
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp 2009-04-04 14:50:54 UTC (rev 19537)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp 2009-04-04 15:26:12 UTC (rev 19538)
@@ -187,10 +187,13 @@
PyObject *SVertex_setPoint3D( BPy_SVertex *self , PyObject *args) {
PyObject *py_point;
- if(!( PyArg_ParseTuple(args, "O", &py_point)
- && PyList_Check(py_point) && PyList_Size(py_point) == 3 )) {
- cout << "ERROR: SVertex_setPoint3D" << endl;
- Py_RETURN_NONE;
+ if(!( PyArg_ParseTuple(args, "O!", &PyList_Type, &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());
+ return NULL;
}
Vec3r v( PyFloat_AsDouble( PyList_GetItem(py_point, 0) ),
@@ -204,10 +207,13 @@
PyObject *SVertex_setPoint2D( BPy_SVertex *self , PyObject *args) {
PyObject *py_point;
- if(!( PyArg_ParseTuple(args, "O", &py_point)
- && PyList_Check(py_point) && PyList_Size(py_point) == 3 )) {
- cout << "ERROR: SVertex_setPoint2D" << endl;
- Py_RETURN_NONE;
+ if(!( PyArg_ParseTuple(args, "O!", &PyList_Type, &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());
+ return NULL;
}
Vec3r v( PyFloat_AsDouble( PyList_GetItem(py_point, 0) ),
@@ -221,10 +227,13 @@
PyObject *SVertex_AddNormal( BPy_SVertex *self , PyObject *args) {
PyObject *py_normal;
- if(!( PyArg_ParseTuple(args, "O", &py_normal)
- && PyList_Check(py_normal) && PyList_Size(py_normal) == 3 )) {
- cout << "ERROR: SVertex_AddNormal" << endl;
- Py_RETURN_NONE;
+ if(!( PyArg_ParseTuple(args, "O!", &PyList_Type, &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());
+ return NULL;
}
Vec3r n( PyFloat_AsDouble( PyList_GetItem(py_normal, 0) ),
@@ -238,10 +247,8 @@
PyObject *SVertex_setId( BPy_SVertex *self , PyObject *args) {
BPy_Id *py_id;
- if( !PyArg_ParseTuple(args, "O", &py_id) ) {
- cout << "ERROR: SVertex_setId" << endl;
- Py_RETURN_NONE;
- }
+ if( !PyArg_ParseTuple(args, "O!", &Id_Type, &py_id) )
+ return NULL;
self->sv->setId( *(py_id->id) );
@@ -251,10 +258,8 @@
PyObject *SVertex_AddFEdge( BPy_SVertex *self , PyObject *args) {
PyObject *py_fe;
- if(!( PyArg_ParseTuple(args, "O", &py_fe) && BPy_FEdge_Check(py_fe) )) {
- cout << "ERROR: SVertex_AddFEdge" << endl;
- Py_RETURN_NONE;
- }
+ if(!( PyArg_ParseTuple(args, "O!", &FEdge_Type, &py_fe) ))
+ return NULL;
self->sv->AddFEdge( ((BPy_FEdge *) py_fe)->fe );
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp 2009-04-04 14:50:54 UTC (rev 19537)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp 2009-04-04 15:26:12 UTC (rev 19538)
@@ -131,10 +131,8 @@
if( !self->vv )
Py_RETURN_NONE;
- if(!( PyArg_ParseTuple(args, "O", &py_n) && BPy_Nature_Check(py_n) )) {
- cout << "ERROR: ViewVertex_setNature" << endl;
- Py_RETURN_NONE;
- }
+ if(!( PyArg_ParseTuple(args, "O!", &Nature_Type, &py_n) ))
+ return NULL;
PyObject *i = (PyObject *) &( ((BPy_Nature *) py_n)->i );
((ViewVertex *) self->py_if0D.if0D)->setNature( PyInt_AsLong(i) );
@@ -165,10 +163,8 @@
if( !self->vv )
Py_RETURN_NONE;
- if(!( PyArg_ParseTuple(args, "O", &py_ve) && BPy_ViewEdge_Check(py_ve) )) {
- cout << "ERROR: ViewVertex_setNature" << endl;
- Py_RETURN_NONE;
- }
+ if(!( PyArg_ParseTuple(args, "O!", &ViewEdge_Type, &py_ve) ))
+ return NULL;
ViewEdge *ve = ((BPy_ViewEdge *) py_ve)->ve;
ViewVertexInternal::orientedViewEdgeIterator ove_it( self->vv->edgesIterator( ve ) );
More information about the Bf-blender-cvs
mailing list