Improvements on error handling in the Python API.
This commit is contained in:
@@ -133,6 +133,7 @@ int NonTVertex___init__(BPy_NonTVertex *self, PyObject *args, PyObject *kwds)
|
||||
self->ntv = new NonTVertex( ((BPy_SVertex *) obj)->sv );
|
||||
|
||||
} else {
|
||||
PyErr_SetString(PyExc_TypeError, "invalid argument");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -174,10 +175,8 @@ PyObject * NonTVertex_svertex( BPy_NonTVertex *self ) {
|
||||
PyObject * NonTVertex_setSVertex( BPy_NonTVertex *self, PyObject *args) {
|
||||
PyObject *py_sv;
|
||||
|
||||
if(!( PyArg_ParseTuple(args, "O", &py_sv) && BPy_SVertex_Check(py_sv) )) {
|
||||
cout << "ERROR: NonTVertex_setSVertex" << endl;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
if(!( PyArg_ParseTuple(args, "O!", &SVertex_Type, &py_sv) ))
|
||||
return NULL;
|
||||
|
||||
self->ntv->setSVertex( ((BPy_SVertex *) py_sv)->sv );
|
||||
|
||||
|
||||
@@ -172,10 +172,8 @@ PyObject * TVertex_backSVertex( BPy_TVertex *self ) {
|
||||
PyObject * TVertex_setFrontSVertex( BPy_TVertex *self, PyObject *args) {
|
||||
PyObject *py_sv;
|
||||
|
||||
if(!( PyArg_ParseTuple(args, "O", &py_sv) && BPy_SVertex_Check(py_sv) )) {
|
||||
cout << "ERROR: TVertex_setFrontSVertex" << endl;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
if(!( PyArg_ParseTuple(args, "O!", &SVertex_Type, &py_sv) ))
|
||||
return NULL;
|
||||
|
||||
self->tv->setFrontSVertex( ((BPy_SVertex *) py_sv)->sv );
|
||||
|
||||
@@ -185,10 +183,8 @@ PyObject * TVertex_setFrontSVertex( BPy_TVertex *self, PyObject *args) {
|
||||
PyObject * TVertex_setBackSVertex( BPy_TVertex *self, PyObject *args) {
|
||||
PyObject *py_sv;
|
||||
|
||||
if(!( PyArg_ParseTuple(args, "O", &py_sv) && BPy_SVertex_Check(py_sv) )) {
|
||||
cout << "ERROR: TVertex_setBackSVertex" << endl;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
if(!( PyArg_ParseTuple(args, "O", &SVertex_Type, &py_sv) ))
|
||||
return NULL;
|
||||
|
||||
self->tv->setBackSVertex( ((BPy_SVertex *) py_sv)->sv );
|
||||
|
||||
@@ -198,10 +194,8 @@ PyObject * TVertex_setBackSVertex( BPy_TVertex *self, PyObject *args) {
|
||||
PyObject * TVertex_setId( BPy_TVertex *self, PyObject *args) {
|
||||
PyObject *py_id;
|
||||
|
||||
if(!( PyArg_ParseTuple(args, "O", &py_id) && BPy_Id_Check(py_id) )) {
|
||||
cout << "ERROR: TVertex_setId" << endl;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
if(!( PyArg_ParseTuple(args, "O!", &Id_Type, &py_id) ))
|
||||
return NULL;
|
||||
|
||||
if( ((BPy_Id *) py_id)->id )
|
||||
self->tv->setId(*( ((BPy_Id *) py_id)->id ));
|
||||
@@ -212,10 +206,8 @@ PyObject * TVertex_setId( BPy_TVertex *self, PyObject *args) {
|
||||
PyObject * TVertex_getSVertex( BPy_TVertex *self, PyObject *args) {
|
||||
PyObject *py_fe;
|
||||
|
||||
if(!( PyArg_ParseTuple(args, "O", &py_fe) && BPy_FEdge_Check(py_fe) )) {
|
||||
cout << "ERROR: TVertex_getSVertex" << endl;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
if(!( PyArg_ParseTuple(args, "O!", &FEdge_Type, &py_fe) ))
|
||||
return NULL;
|
||||
|
||||
SVertex *sv = self->tv->getSVertex( ((BPy_FEdge *) py_fe)->fe );
|
||||
if( sv ){
|
||||
@@ -228,10 +220,8 @@ PyObject * TVertex_getSVertex( BPy_TVertex *self, PyObject *args) {
|
||||
PyObject * TVertex_mate( BPy_TVertex *self, PyObject *args) {
|
||||
PyObject *py_ve;
|
||||
|
||||
if(!( PyArg_ParseTuple(args, "O", &py_ve) && BPy_ViewEdge_Check(py_ve) )) {
|
||||
cout << "ERROR: TVertex_mate" << endl;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
if(!( PyArg_ParseTuple(args, "O!", &ViewEdge_Type, &py_ve) ))
|
||||
return NULL;
|
||||
|
||||
ViewEdge *ve = self->tv->mate( ((BPy_ViewEdge *) py_ve)->ve );
|
||||
if( ve ){
|
||||
|
||||
@@ -136,15 +136,13 @@ int FEdgeSharp___init__(BPy_FEdgeSharp *self, PyObject *args, PyObject *kwds)
|
||||
self->fes = new FEdgeSharp();
|
||||
|
||||
} else if( BPy_FEdgeSharp_Check(obj1) ) {
|
||||
if( ((BPy_FEdgeSharp *) obj1)->fes )
|
||||
self->fes = new FEdgeSharp(*( ((BPy_FEdgeSharp *) obj1)->fes ));
|
||||
else
|
||||
return -1;
|
||||
|
||||
} else if( BPy_SVertex_Check(obj1) && BPy_SVertex_Check(obj2) ) {
|
||||
self->fes = new FEdgeSharp( ((BPy_SVertex *) obj1)->sv, ((BPy_SVertex *) obj2)->sv );
|
||||
|
||||
} else {
|
||||
PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -186,9 +184,13 @@ PyObject * FEdgeSharp_bMaterial( BPy_FEdgeSharp *self ) {
|
||||
PyObject * FEdgeSharp_setNormalA( BPy_FEdgeSharp *self, PyObject *args ) {
|
||||
PyObject *obj = 0;
|
||||
|
||||
if(!( PyArg_ParseTuple(args, "O", &obj) && PyList_Check(obj) && PyList_Size(obj) > 2 )) {
|
||||
cout << "ERROR: FEdgeSharp_setNormalA" << endl;
|
||||
Py_RETURN_NONE;
|
||||
if(!( PyArg_ParseTuple(args, "O!", &PyList_Type, &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());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Vec3r v( PyFloat_AsDouble( PyList_GetItem(obj,0) ),
|
||||
@@ -203,9 +205,13 @@ PyObject * FEdgeSharp_setNormalA( BPy_FEdgeSharp *self, PyObject *args ) {
|
||||
PyObject * FEdgeSharp_setNormalB( BPy_FEdgeSharp *self, PyObject *args ) {
|
||||
PyObject *obj = 0;
|
||||
|
||||
if(!( PyArg_ParseTuple(args, "O", &obj) && PyList_Check(obj) && PyList_Size(obj) > 2 )) {
|
||||
cout << "ERROR: FEdgeSharp_setNormalB" << endl;
|
||||
Py_RETURN_NONE;
|
||||
if(!( PyArg_ParseTuple(args, "O!", &PyList_Type, &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());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Vec3r v( PyFloat_AsDouble( PyList_GetItem(obj,0) ),
|
||||
@@ -220,10 +226,8 @@ PyObject * FEdgeSharp_setNormalB( BPy_FEdgeSharp *self, PyObject *args ) {
|
||||
PyObject * FEdgeSharp_setaMaterialIndex( BPy_FEdgeSharp *self, PyObject *args ) {
|
||||
unsigned int i;
|
||||
|
||||
if(!( PyArg_ParseTuple(args, "I", &i) )) {
|
||||
cout << "ERROR: FEdgeSharp_setaMaterialIndex" << endl;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
if(!( PyArg_ParseTuple(args, "I", &i) ))
|
||||
return NULL;
|
||||
|
||||
self->fes->setaFrsMaterialIndex( i );
|
||||
|
||||
@@ -233,10 +237,8 @@ PyObject * FEdgeSharp_setaMaterialIndex( BPy_FEdgeSharp *self, PyObject *args )
|
||||
PyObject * FEdgeSharp_setbMaterialIndex( BPy_FEdgeSharp *self, PyObject *args ) {
|
||||
unsigned int i;
|
||||
|
||||
if(!( PyArg_ParseTuple(args, "I", &i) )) {
|
||||
cout << "ERROR: FEdgeSharp_setbMaterialIndex" << endl;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
if(!( PyArg_ParseTuple(args, "I", &i) ))
|
||||
return NULL;
|
||||
|
||||
self->fes->setbFrsMaterialIndex( i );
|
||||
|
||||
|
||||
@@ -128,15 +128,13 @@ int FEdgeSmooth___init__(BPy_FEdgeSmooth *self, PyObject *args, PyObject *kwds)
|
||||
self->fes = new FEdgeSmooth();
|
||||
|
||||
} else if( BPy_FEdgeSmooth_Check(obj1) ) {
|
||||
if( ((BPy_FEdgeSmooth *) obj1)->fes )
|
||||
self->fes = new FEdgeSmooth(*( ((BPy_FEdgeSmooth *) obj1)->fes ));
|
||||
else
|
||||
return -1;
|
||||
|
||||
} else if( BPy_SVertex_Check(obj1) && BPy_SVertex_Check(obj2) ) {
|
||||
self->fes = new FEdgeSmooth( ((BPy_SVertex *) obj1)->sv, ((BPy_SVertex *) obj2)->sv );
|
||||
|
||||
} else {
|
||||
PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -164,9 +162,13 @@ PyObject * FEdgeSmooth_material( BPy_FEdgeSmooth *self ) {
|
||||
PyObject * FEdgeSmooth_setNormal( BPy_FEdgeSmooth *self, PyObject *args ) {
|
||||
PyObject *obj = 0;
|
||||
|
||||
if(!( PyArg_ParseTuple(args, "O", &obj) && PyList_Check(obj) && PyList_Size(obj) > 2 )) {
|
||||
cout << "ERROR: FEdgeSmooth_setNormal" << endl;
|
||||
Py_RETURN_NONE;
|
||||
if(!( PyArg_ParseTuple(args, "O!", &PyList_Type, &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());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Vec3r v( PyFloat_AsDouble( PyList_GetItem(obj,0) ),
|
||||
@@ -181,10 +183,8 @@ PyObject * FEdgeSmooth_setNormal( BPy_FEdgeSmooth *self, PyObject *args ) {
|
||||
PyObject * FEdgeSmooth_setMaterialIndex( BPy_FEdgeSmooth *self, PyObject *args ) {
|
||||
unsigned int i;
|
||||
|
||||
if(!( PyArg_ParseTuple(args, "I", &i) )) {
|
||||
cout << "ERROR: FEdgeSmooth_setMaterialIndex" << endl;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
if(!( PyArg_ParseTuple(args, "I", &i) ))
|
||||
return NULL;
|
||||
|
||||
self->fes->setFrsMaterialIndex( i );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user