Improvements on error handling in the Python API.
This commit is contained in:
@@ -187,10 +187,13 @@ PyObject * SVertex_viewvertex( BPy_SVertex *self ) {
|
|||||||
PyObject *SVertex_setPoint3D( BPy_SVertex *self , PyObject *args) {
|
PyObject *SVertex_setPoint3D( BPy_SVertex *self , PyObject *args) {
|
||||||
PyObject *py_point;
|
PyObject *py_point;
|
||||||
|
|
||||||
if(!( PyArg_ParseTuple(args, "O", &py_point)
|
if(!( PyArg_ParseTuple(args, "O!", &PyList_Type, &py_point) ))
|
||||||
&& PyList_Check(py_point) && PyList_Size(py_point) == 3 )) {
|
return NULL;
|
||||||
cout << "ERROR: SVertex_setPoint3D" << endl;
|
if( PyList_Size(py_point) != 3 ) {
|
||||||
Py_RETURN_NONE;
|
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) ),
|
Vec3r v( PyFloat_AsDouble( PyList_GetItem(py_point, 0) ),
|
||||||
@@ -204,10 +207,13 @@ PyObject *SVertex_setPoint3D( BPy_SVertex *self , PyObject *args) {
|
|||||||
PyObject *SVertex_setPoint2D( BPy_SVertex *self , PyObject *args) {
|
PyObject *SVertex_setPoint2D( BPy_SVertex *self , PyObject *args) {
|
||||||
PyObject *py_point;
|
PyObject *py_point;
|
||||||
|
|
||||||
if(!( PyArg_ParseTuple(args, "O", &py_point)
|
if(!( PyArg_ParseTuple(args, "O!", &PyList_Type, &py_point) ))
|
||||||
&& PyList_Check(py_point) && PyList_Size(py_point) == 3 )) {
|
return NULL;
|
||||||
cout << "ERROR: SVertex_setPoint2D" << endl;
|
if( PyList_Size(py_point) != 3 ) {
|
||||||
Py_RETURN_NONE;
|
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) ),
|
Vec3r v( PyFloat_AsDouble( PyList_GetItem(py_point, 0) ),
|
||||||
@@ -221,10 +227,13 @@ PyObject *SVertex_setPoint2D( BPy_SVertex *self , PyObject *args) {
|
|||||||
PyObject *SVertex_AddNormal( BPy_SVertex *self , PyObject *args) {
|
PyObject *SVertex_AddNormal( BPy_SVertex *self , PyObject *args) {
|
||||||
PyObject *py_normal;
|
PyObject *py_normal;
|
||||||
|
|
||||||
if(!( PyArg_ParseTuple(args, "O", &py_normal)
|
if(!( PyArg_ParseTuple(args, "O!", &PyList_Type, &py_normal) ))
|
||||||
&& PyList_Check(py_normal) && PyList_Size(py_normal) == 3 )) {
|
return NULL;
|
||||||
cout << "ERROR: SVertex_AddNormal" << endl;
|
if( PyList_Size(py_normal) != 3 ) {
|
||||||
Py_RETURN_NONE;
|
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) ),
|
Vec3r n( PyFloat_AsDouble( PyList_GetItem(py_normal, 0) ),
|
||||||
@@ -238,10 +247,8 @@ PyObject *SVertex_AddNormal( BPy_SVertex *self , PyObject *args) {
|
|||||||
PyObject *SVertex_setId( BPy_SVertex *self , PyObject *args) {
|
PyObject *SVertex_setId( BPy_SVertex *self , PyObject *args) {
|
||||||
BPy_Id *py_id;
|
BPy_Id *py_id;
|
||||||
|
|
||||||
if( !PyArg_ParseTuple(args, "O", &py_id) ) {
|
if( !PyArg_ParseTuple(args, "O!", &Id_Type, &py_id) )
|
||||||
cout << "ERROR: SVertex_setId" << endl;
|
return NULL;
|
||||||
Py_RETURN_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
self->sv->setId( *(py_id->id) );
|
self->sv->setId( *(py_id->id) );
|
||||||
|
|
||||||
@@ -251,10 +258,8 @@ PyObject *SVertex_setId( BPy_SVertex *self , PyObject *args) {
|
|||||||
PyObject *SVertex_AddFEdge( BPy_SVertex *self , PyObject *args) {
|
PyObject *SVertex_AddFEdge( BPy_SVertex *self , PyObject *args) {
|
||||||
PyObject *py_fe;
|
PyObject *py_fe;
|
||||||
|
|
||||||
if(!( PyArg_ParseTuple(args, "O", &py_fe) && BPy_FEdge_Check(py_fe) )) {
|
if(!( PyArg_ParseTuple(args, "O!", &FEdge_Type, &py_fe) ))
|
||||||
cout << "ERROR: SVertex_AddFEdge" << endl;
|
return NULL;
|
||||||
Py_RETURN_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
self->sv->AddFEdge( ((BPy_FEdge *) py_fe)->fe );
|
self->sv->AddFEdge( ((BPy_FEdge *) py_fe)->fe );
|
||||||
|
|
||||||
|
|||||||
@@ -131,10 +131,8 @@ PyObject * ViewVertex_setNature( BPy_ViewVertex *self, PyObject *args ) {
|
|||||||
if( !self->vv )
|
if( !self->vv )
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
|
|
||||||
if(!( PyArg_ParseTuple(args, "O", &py_n) && BPy_Nature_Check(py_n) )) {
|
if(!( PyArg_ParseTuple(args, "O!", &Nature_Type, &py_n) ))
|
||||||
cout << "ERROR: ViewVertex_setNature" << endl;
|
return NULL;
|
||||||
Py_RETURN_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
PyObject *i = (PyObject *) &( ((BPy_Nature *) py_n)->i );
|
PyObject *i = (PyObject *) &( ((BPy_Nature *) py_n)->i );
|
||||||
((ViewVertex *) self->py_if0D.if0D)->setNature( PyInt_AsLong(i) );
|
((ViewVertex *) self->py_if0D.if0D)->setNature( PyInt_AsLong(i) );
|
||||||
@@ -165,10 +163,8 @@ PyObject * ViewVertex_edgesIterator( BPy_ViewVertex *self, PyObject *args ) {
|
|||||||
if( !self->vv )
|
if( !self->vv )
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
|
|
||||||
if(!( PyArg_ParseTuple(args, "O", &py_ve) && BPy_ViewEdge_Check(py_ve) )) {
|
if(!( PyArg_ParseTuple(args, "O!", &ViewEdge_Type, &py_ve) ))
|
||||||
cout << "ERROR: ViewVertex_setNature" << endl;
|
return NULL;
|
||||||
Py_RETURN_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ViewEdge *ve = ((BPy_ViewEdge *) py_ve)->ve;
|
ViewEdge *ve = ((BPy_ViewEdge *) py_ve)->ve;
|
||||||
ViewVertexInternal::orientedViewEdgeIterator ove_it( self->vv->edgesIterator( ve ) );
|
ViewVertexInternal::orientedViewEdgeIterator ove_it( self->vv->edgesIterator( ve ) );
|
||||||
|
|||||||
Reference in New Issue
Block a user