Path: improve AreaPy exception handling
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#include <Mod/Part/App/OCCError.h>
|
||||
#include <Mod/Part/App/TopoShapePy.h>
|
||||
#include <Base/VectorPy.h>
|
||||
|
||||
@@ -239,9 +240,11 @@ PyObject* AreaPy::getShape(PyObject *args, PyObject *keywds)
|
||||
if (!PyArg_ParseTupleAndKeywords(args, keywds,"|hO",kwlist,&index,&pcObj))
|
||||
return 0;
|
||||
|
||||
if(PyObject_IsTrue(pcObj))
|
||||
getAreaPtr()->clean();
|
||||
return Py::new_reference_to(Part::shape2pyshape(getAreaPtr()->getShape(index)));
|
||||
PY_TRY {
|
||||
if(PyObject_IsTrue(pcObj))
|
||||
getAreaPtr()->clean();
|
||||
return Py::new_reference_to(Part::shape2pyshape(getAreaPtr()->getShape(index)));
|
||||
} PY_CATCH_OCC
|
||||
}
|
||||
|
||||
PyObject* AreaPy::add(PyObject *args, PyObject *keywds)
|
||||
@@ -259,28 +262,30 @@ PyObject* AreaPy::add(PyObject *args, PyObject *keywds)
|
||||
kwlist,&pcObj,PARAM_REF(PARAM_FARG,AREA_PARAMS_OPCODE)))
|
||||
return 0;
|
||||
|
||||
if (PyObject_TypeCheck(pcObj, &(Part::TopoShapePy::Type))) {
|
||||
getAreaPtr()->add(GET_TOPOSHAPE(pcObj),op);
|
||||
Py_INCREF(this);
|
||||
return this;
|
||||
} else if (PyObject_TypeCheck(pcObj, &(PyList_Type)) ||
|
||||
PyObject_TypeCheck(pcObj, &(PyTuple_Type))) {
|
||||
Py::Sequence shapeSeq(pcObj);
|
||||
for (Py::Sequence::iterator it = shapeSeq.begin(); it != shapeSeq.end(); ++it) {
|
||||
PyObject* item = (*it).ptr();
|
||||
if(!PyObject_TypeCheck(item, &(Part::TopoShapePy::Type))) {
|
||||
PyErr_SetString(PyExc_TypeError, "non-shape object in sequence");
|
||||
return 0;
|
||||
PY_TRY {
|
||||
if (PyObject_TypeCheck(pcObj, &(Part::TopoShapePy::Type))) {
|
||||
getAreaPtr()->add(GET_TOPOSHAPE(pcObj),op);
|
||||
Py_INCREF(this);
|
||||
return this;
|
||||
} else if (PyObject_TypeCheck(pcObj, &(PyList_Type)) ||
|
||||
PyObject_TypeCheck(pcObj, &(PyTuple_Type))) {
|
||||
Py::Sequence shapeSeq(pcObj);
|
||||
for (Py::Sequence::iterator it = shapeSeq.begin(); it != shapeSeq.end(); ++it) {
|
||||
PyObject* item = (*it).ptr();
|
||||
if(!PyObject_TypeCheck(item, &(Part::TopoShapePy::Type))) {
|
||||
PyErr_SetString(PyExc_TypeError, "non-shape object in sequence");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
for (Py::Sequence::iterator it = shapeSeq.begin(); it != shapeSeq.end(); ++it){
|
||||
PyObject* item = (*it).ptr();
|
||||
getAreaPtr()->add(GET_TOPOSHAPE(item),
|
||||
PARAM_PY_FIELDS(PARAM_FARG,AREA_PARAMS_OPCODE));
|
||||
}
|
||||
Py_INCREF(this);
|
||||
return this;
|
||||
}
|
||||
for (Py::Sequence::iterator it = shapeSeq.begin(); it != shapeSeq.end(); ++it){
|
||||
PyObject* item = (*it).ptr();
|
||||
getAreaPtr()->add(GET_TOPOSHAPE(item),
|
||||
PARAM_PY_FIELDS(PARAM_FARG,AREA_PARAMS_OPCODE));
|
||||
}
|
||||
Py_INCREF(this);
|
||||
return this;
|
||||
}
|
||||
} PY_CATCH_OCC
|
||||
|
||||
PyErr_SetString(PyExc_TypeError, "shape must be 'TopoShape' or list of 'TopoShape'");
|
||||
return 0;
|
||||
@@ -302,10 +307,12 @@ PyObject* AreaPy::makeOffset(PyObject *args, PyObject *keywds)
|
||||
&index,PARAM_REF(PARAM_FARG,AREA_PARAMS_OFFSET)))
|
||||
return 0;
|
||||
|
||||
//Expand the variable as function call arguments
|
||||
TopoDS_Shape resultShape = getAreaPtr()->makeOffset(index,
|
||||
PARAM_PY_FIELDS(PARAM_FARG,AREA_PARAMS_OFFSET));
|
||||
return Py::new_reference_to(Part::shape2pyshape(resultShape));
|
||||
PY_TRY {
|
||||
//Expand the variable as function call arguments
|
||||
TopoDS_Shape resultShape = getAreaPtr()->makeOffset(index,
|
||||
PARAM_PY_FIELDS(PARAM_FARG,AREA_PARAMS_OFFSET));
|
||||
return Py::new_reference_to(Part::shape2pyshape(resultShape));
|
||||
} PY_CATCH_OCC
|
||||
}
|
||||
|
||||
PyObject* AreaPy::makePocket(PyObject *args, PyObject *keywds)
|
||||
@@ -322,9 +329,11 @@ PyObject* AreaPy::makePocket(PyObject *args, PyObject *keywds)
|
||||
&index,PARAM_REF(PARAM_FARG,AREA_PARAMS_POCKET)))
|
||||
return 0;
|
||||
|
||||
TopoDS_Shape resultShape = getAreaPtr()->makePocket(index,
|
||||
PARAM_PY_FIELDS(PARAM_FARG,AREA_PARAMS_POCKET));
|
||||
return Py::new_reference_to(Part::shape2pyshape(resultShape));
|
||||
PY_TRY {
|
||||
TopoDS_Shape resultShape = getAreaPtr()->makePocket(index,
|
||||
PARAM_PY_FIELDS(PARAM_FARG,AREA_PARAMS_POCKET));
|
||||
return Py::new_reference_to(Part::shape2pyshape(resultShape));
|
||||
} PY_CATCH_OCC
|
||||
}
|
||||
|
||||
PyObject* AreaPy::makeSections(PyObject *args, PyObject *keywds)
|
||||
@@ -342,36 +351,38 @@ PyObject* AreaPy::makeSections(PyObject *args, PyObject *keywds)
|
||||
&heights, &(Part::TopoShapePy::Type), &plane))
|
||||
return 0;
|
||||
|
||||
std::vector<double> h;
|
||||
if(heights) {
|
||||
if (PyObject_TypeCheck(heights, &(PyFloat_Type)))
|
||||
h.push_back(PyFloat_AsDouble(heights));
|
||||
else if (PyObject_TypeCheck(heights, &(PyList_Type)) ||
|
||||
PyObject_TypeCheck(heights, &(PyTuple_Type))) {
|
||||
Py::Sequence shapeSeq(heights);
|
||||
h.reserve(shapeSeq.size());
|
||||
for (Py::Sequence::iterator it = shapeSeq.begin(); it != shapeSeq.end(); ++it) {
|
||||
PyObject* item = (*it).ptr();
|
||||
if(!PyObject_TypeCheck(item, &(PyFloat_Type))) {
|
||||
PyErr_SetString(PyExc_TypeError, "heights must only contain float type");
|
||||
return 0;
|
||||
PY_TRY {
|
||||
std::vector<double> h;
|
||||
if(heights) {
|
||||
if (PyObject_TypeCheck(heights, &(PyFloat_Type)))
|
||||
h.push_back(PyFloat_AsDouble(heights));
|
||||
else if (PyObject_TypeCheck(heights, &(PyList_Type)) ||
|
||||
PyObject_TypeCheck(heights, &(PyTuple_Type))) {
|
||||
Py::Sequence shapeSeq(heights);
|
||||
h.reserve(shapeSeq.size());
|
||||
for (Py::Sequence::iterator it = shapeSeq.begin(); it != shapeSeq.end(); ++it) {
|
||||
PyObject* item = (*it).ptr();
|
||||
if(!PyObject_TypeCheck(item, &(PyFloat_Type))) {
|
||||
PyErr_SetString(PyExc_TypeError, "heights must only contain float type");
|
||||
return 0;
|
||||
}
|
||||
h.push_back(PyFloat_AsDouble(item));
|
||||
}
|
||||
h.push_back(PyFloat_AsDouble(item));
|
||||
}else{
|
||||
PyErr_SetString(PyExc_TypeError, "heights must be of type float or list/tuple of float");
|
||||
return 0;
|
||||
}
|
||||
}else{
|
||||
PyErr_SetString(PyExc_TypeError, "heights must be of type float or list/tuple of float");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Area> > sections = getAreaPtr()->makeSections(
|
||||
PARAM_PY_FIELDS(PARAM_FARG,AREA_PARAMS_SECTION_EXTRA),
|
||||
h,plane?GET_TOPOSHAPE(plane):TopoDS_Shape());
|
||||
std::vector<std::shared_ptr<Area> > sections = getAreaPtr()->makeSections(
|
||||
PARAM_PY_FIELDS(PARAM_FARG,AREA_PARAMS_SECTION_EXTRA),
|
||||
h,plane?GET_TOPOSHAPE(plane):TopoDS_Shape());
|
||||
|
||||
Py::List ret;
|
||||
for(auto &area : sections)
|
||||
ret.append(Py::asObject(new AreaPy(new Area(*area,true))));
|
||||
return Py::new_reference_to(ret);
|
||||
Py::List ret;
|
||||
for(auto &area : sections)
|
||||
ret.append(Py::asObject(new AreaPy(new Area(*area,true))));
|
||||
return Py::new_reference_to(ret);
|
||||
} PY_CATCH_OCC
|
||||
}
|
||||
|
||||
PyObject* AreaPy::setDefaultParams(PyObject *, PyObject *)
|
||||
@@ -397,12 +408,14 @@ PyObject* AreaPy::setParams(PyObject *args, PyObject *keywds)
|
||||
PARAM_REF(PARAM_FNAME,AREA_PARAMS_CONF)))
|
||||
return 0;
|
||||
|
||||
//populate 'params' with the CONF variables
|
||||
PARAM_FOREACH(AREA_GET,AREA_PARAMS_CONF)
|
||||
PY_TRY {
|
||||
//populate 'params' with the CONF variables
|
||||
PARAM_FOREACH(AREA_GET,AREA_PARAMS_CONF)
|
||||
|
||||
getAreaPtr()->setParams(params);
|
||||
Py_INCREF(this);
|
||||
return this;
|
||||
getAreaPtr()->setParams(params);
|
||||
Py_INCREF(this);
|
||||
return this;
|
||||
} PY_CATCH_OCC
|
||||
}
|
||||
|
||||
PyObject* AreaPy::getParams(PyObject *args)
|
||||
|
||||
Reference in New Issue
Block a user