From d3af186c1cf2c0b3b7b57ee6bc4a2e455b8f2449 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 12 Jan 2012 14:04:19 +0000 Subject: [PATCH] + make try/catch block around sortEdges + set shape immutable when getting from feature + no use of tuples in removeShape git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5402 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d --- src/Mod/Part/App/AppPartPy.cpp | 19 ++++++--- src/Mod/Part/App/PropertyTopoShape.cpp | 58 ++++++++++++++------------ src/Mod/Part/App/TopoShapePyImp.cpp | 3 +- 3 files changed, 46 insertions(+), 34 deletions(-) diff --git a/src/Mod/Part/App/AppPartPy.cpp b/src/Mod/Part/App/AppPartPy.cpp index 3ef8072ac..1c601b31e 100644 --- a/src/Mod/Part/App/AppPartPy.cpp +++ b/src/Mod/Part/App/AppPartPy.cpp @@ -1320,14 +1320,21 @@ static PyObject * sortEdges(PyObject *self, PyObject *args) } } - std::list sorted = sort_Edges(Precision::Confusion(), edges); + try { + std::list sorted = sort_Edges(Precision::Confusion(), edges); - Py::List sorted_list; - for (std::list::iterator it = sorted.begin(); it != sorted.end(); ++it) { - sorted_list.append(Py::Object(new TopoShapeEdgePy(new TopoShape(*it)),true)); + Py::List sorted_list; + for (std::list::iterator it = sorted.begin(); it != sorted.end(); ++it) { + sorted_list.append(Py::Object(new TopoShapeEdgePy(new TopoShape(*it)),true)); + } + + return Py::new_reference_to(sorted_list); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PyExc_Exception, e->GetMessageString()); + return 0; } - - return Py::new_reference_to(sorted_list); } static PyObject * cast_to_shape(PyObject *self, PyObject *args) diff --git a/src/Mod/Part/App/PropertyTopoShape.cpp b/src/Mod/Part/App/PropertyTopoShape.cpp index 76ec1f748..d0cc3981c 100644 --- a/src/Mod/Part/App/PropertyTopoShape.cpp +++ b/src/Mod/Part/App/PropertyTopoShape.cpp @@ -147,34 +147,40 @@ void PropertyPartShape::transformGeometry(const Base::Matrix4D &rclTrf) PyObject *PropertyPartShape::getPyObject(void) { + Base::PyObjectBase* prop; const TopoDS_Shape& sh = _Shape._Shape; - if (sh.IsNull()) - return new TopoShapePy(new TopoShape(sh)); - - TopAbs_ShapeEnum type = sh.ShapeType(); - switch (type) - { - case TopAbs_COMPOUND: - return new TopoShapeCompoundPy(new TopoShape(sh)); - case TopAbs_COMPSOLID: - return new TopoShapeCompSolidPy(new TopoShape(sh)); - case TopAbs_SOLID: - return new TopoShapeSolidPy(new TopoShape(sh)); - case TopAbs_SHELL: - return new TopoShapeShellPy(new TopoShape(sh)); - case TopAbs_FACE: - return new TopoShapeFacePy(new TopoShape(sh)); - case TopAbs_WIRE: - return new TopoShapeWirePy(new TopoShape(sh)); - case TopAbs_EDGE: - return new TopoShapeEdgePy(new TopoShape(sh)); - case TopAbs_VERTEX: - return new TopoShapeVertexPy(new TopoShape(sh)); - case TopAbs_SHAPE: - default: - return new TopoShapePy(new TopoShape(sh)); - break; + if (sh.IsNull()) { + prop = new TopoShapePy(new TopoShape(sh)); } + else { + TopAbs_ShapeEnum type = sh.ShapeType(); + switch (type) + { + case TopAbs_COMPOUND: + prop = new TopoShapeCompoundPy(new TopoShape(sh)); + case TopAbs_COMPSOLID: + prop = new TopoShapeCompSolidPy(new TopoShape(sh)); + case TopAbs_SOLID: + prop = new TopoShapeSolidPy(new TopoShape(sh)); + case TopAbs_SHELL: + prop = new TopoShapeShellPy(new TopoShape(sh)); + case TopAbs_FACE: + prop = new TopoShapeFacePy(new TopoShape(sh)); + case TopAbs_WIRE: + prop = new TopoShapeWirePy(new TopoShape(sh)); + case TopAbs_EDGE: + prop = new TopoShapeEdgePy(new TopoShape(sh)); + case TopAbs_VERTEX: + prop = new TopoShapeVertexPy(new TopoShape(sh)); + case TopAbs_SHAPE: + default: + prop = new TopoShapePy(new TopoShape(sh)); + break; + } + } + + if (prop) prop->setConst(); + return prop; } void PropertyPartShape::setPyObject(PyObject *value) diff --git a/src/Mod/Part/App/TopoShapePyImp.cpp b/src/Mod/Part/App/TopoShapePyImp.cpp index 598e7ad8b..8982a1792 100644 --- a/src/Mod/Part/App/TopoShapePyImp.cpp +++ b/src/Mod/Part/App/TopoShapePyImp.cpp @@ -208,8 +208,7 @@ PyObject* TopoShapePy::removeShape(PyObject *args) Py::List list(l); std::vector shapes; for (Py::List::iterator it = list.begin(); it != list.end(); ++it) { - Py::Tuple tuple(*it); - Py::TopoShape sh(tuple[0]); + Py::TopoShape sh(*it); shapes.push_back( sh.extensionObject()->getTopoShapePtr()->_Shape );