From d66fc092e1581d3b2ef7b3cbe54197e3309e077b Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 4 Nov 2014 11:03:51 +0100 Subject: [PATCH] + better exception handling in Part module --- src/Gui/CommandStd.cpp | 1 - src/Mod/Part/App/AppPartPy.cpp | 87 ++++++++++++++++++---------------- 2 files changed, 46 insertions(+), 42 deletions(-) diff --git a/src/Gui/CommandStd.cpp b/src/Gui/CommandStd.cpp index 9c2d0ae58..d780ccb2c 100644 --- a/src/Gui/CommandStd.cpp +++ b/src/Gui/CommandStd.cpp @@ -55,7 +55,6 @@ #include "DlgPreferencesImp.h" #include "DlgCustomizeImp.h" #include "Widgets.h" -#include "NetworkRetriever.h" #include "OnlineDocumentation.h" #include "GuiConsole.h" #include "WorkbenchManager.h" diff --git a/src/Mod/Part/App/AppPartPy.cpp b/src/Mod/Part/App/AppPartPy.cpp index aa7544869..c3925a6e4 100644 --- a/src/Mod/Part/App/AppPartPy.cpp +++ b/src/Mod/Part/App/AppPartPy.cpp @@ -1377,6 +1377,7 @@ static PyObject * makeLoft(PyObject *self, PyObject *args) PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); return 0; } + PY_CATCH; #endif } @@ -1563,38 +1564,41 @@ static PyObject * getSortedClusters(PyObject *self, PyObject *args) return 0; } - Py::Sequence list(obj); - std::vector edges; - for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { - PyObject* item = (*it).ptr(); - if (PyObject_TypeCheck(item, &(Part::TopoShapePy::Type))) { - const TopoDS_Shape& sh = static_cast(item)->getTopoShapePtr()->_Shape; - if (sh.ShapeType() == TopAbs_EDGE) - edges.push_back(TopoDS::Edge(sh)); + PY_TRY { + Py::Sequence list(obj); + std::vector edges; + for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { + PyObject* item = (*it).ptr(); + if (PyObject_TypeCheck(item, &(Part::TopoShapePy::Type))) { + const TopoDS_Shape& sh = static_cast(item)->getTopoShapePtr()->_Shape; + if (sh.ShapeType() == TopAbs_EDGE) + edges.push_back(TopoDS::Edge(sh)); + else { + PyErr_SetString(PyExc_TypeError, "shape is not an edge"); + return 0; + } + } else { - PyErr_SetString(PyExc_TypeError, "shape is not an edge"); + PyErr_SetString(PyExc_TypeError, "item is not a shape"); return 0; } } - else { - PyErr_SetString(PyExc_TypeError, "item is not a shape"); - return 0; + + Edgecluster acluster(edges); + tEdgeClusterVector aclusteroutput = acluster.GetClusters(); + + Py::List root_list; + for (tEdgeClusterVector::iterator it=aclusteroutput.begin(); it != aclusteroutput.end();++it) { + Py::List add_list; + for (tEdgeVector::iterator it1=(*it).begin();it1 != (*it).end();++it1) { + add_list.append(Py::Object(new TopoShapeEdgePy(new TopoShape(*it1)),true)); + } + root_list.append(add_list); } + + return Py::new_reference_to(root_list); } - - Edgecluster acluster(edges); - tEdgeClusterVector aclusteroutput = acluster.GetClusters(); - - Py::List root_list; - for (tEdgeClusterVector::iterator it=aclusteroutput.begin(); it != aclusteroutput.end();++it) { - Py::List add_list; - for (tEdgeVector::iterator it1=(*it).begin();it1 != (*it).end();++it1) { - add_list.append(Py::Object(new TopoShapeEdgePy(new TopoShape(*it1)),true)); - } - root_list.append(add_list); - } - - return Py::new_reference_to(root_list); + PY_CATCH_OCC; } @@ -1607,26 +1611,26 @@ static PyObject * sortEdges(PyObject *self, PyObject *args) } - Py::Sequence list(obj); - std::vector edges; - for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { - PyObject* item = (*it).ptr(); - if (PyObject_TypeCheck(item, &(Part::TopoShapePy::Type))) { - const TopoDS_Shape& sh = static_cast(item)->getTopoShapePtr()->_Shape; - if (sh.ShapeType() == TopAbs_EDGE) - edges.push_back(TopoDS::Edge(sh)); + PY_TRY { + Py::Sequence list(obj); + std::vector edges; + for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { + PyObject* item = (*it).ptr(); + if (PyObject_TypeCheck(item, &(Part::TopoShapePy::Type))) { + const TopoDS_Shape& sh = static_cast(item)->getTopoShapePtr()->_Shape; + if (sh.ShapeType() == TopAbs_EDGE) + edges.push_back(TopoDS::Edge(sh)); + else { + PyErr_SetString(PyExc_TypeError, "shape is not an edge"); + return 0; + } + } else { - PyErr_SetString(PyExc_TypeError, "shape is not an edge"); + PyErr_SetString(PyExc_TypeError, "item is not a shape"); return 0; } } - else { - PyErr_SetString(PyExc_TypeError, "item is not a shape"); - return 0; - } - } - try { std::list sorted = sort_Edges(Precision::Confusion(), edges); Py::List sorted_list; @@ -1641,6 +1645,7 @@ static PyObject * sortEdges(PyObject *self, PyObject *args) PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); return 0; } + PY_CATCH; } static PyObject * cast_to_shape(PyObject *self, PyObject *args)