From 3986c887c3094b0f295ed6377217052a1be4c6c7 Mon Sep 17 00:00:00 2001 From: Sebastian Hoogen Date: Tue, 18 Feb 2014 00:53:13 +0100 Subject: [PATCH] BrepTools::Dump to string --- src/Mod/Part/App/TopoShape.cpp | 7 ++++++- src/Mod/Part/App/TopoShape.h | 3 ++- src/Mod/Part/App/TopoShapePy.xml | 5 +++++ src/Mod/Part/App/TopoShapePyImp.cpp | 25 +++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index 81bc104d93..4bdc9741a0 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -737,11 +737,16 @@ void TopoShape::exportBrep(const char *filename) const throw Base::Exception("Writing of BREP failed"); } -void TopoShape::exportBrep(std::ostream& out) +void TopoShape::exportBrep(std::ostream& out) const { BRepTools::Write(this->_Shape, out); } +void TopoShape::dump(std::ostream& out) const +{ + BRepTools::Dump(this->_Shape, out); +} + void TopoShape::exportStl(const char *filename) const { StlAPI_Writer writer; diff --git a/src/Mod/Part/App/TopoShape.h b/src/Mod/Part/App/TopoShape.h index 4fcece5727..30a10ce82b 100644 --- a/src/Mod/Part/App/TopoShape.h +++ b/src/Mod/Part/App/TopoShape.h @@ -119,6 +119,7 @@ public: //@{ void read(const char *FileName); void write(const char *FileName) const; + void dump(std::ostream& out) const; void importIges(const char *FileName); void importStep(const char *FileName); void importBrep(const char *FileName); @@ -126,7 +127,7 @@ public: void exportIges(const char *FileName) const; void exportStep(const char *FileName) const; void exportBrep(const char *FileName) const; - void exportBrep(std::ostream&); + void exportBrep(std::ostream&) const; void exportStl (const char *FileName) const; void exportFaceSet(double, double, std::ostream&) const; void exportLineSet(std::ostream&) const; diff --git a/src/Mod/Part/App/TopoShapePy.xml b/src/Mod/Part/App/TopoShapePy.xml index 7c09e41047..5be2fd8d5e 100644 --- a/src/Mod/Part/App/TopoShapePy.xml +++ b/src/Mod/Part/App/TopoShapePy.xml @@ -48,6 +48,11 @@ Sub-elements such as vertices, edges or faces are accessible as: Export the content of this shape to a string in BREP format. BREP is a CasCade native format. + + + Dump information about the shape to a string. + + Export the content of this shape to an STL mesh file. diff --git a/src/Mod/Part/App/TopoShapePyImp.cpp b/src/Mod/Part/App/TopoShapePyImp.cpp index b1be1a603f..066e218292 100644 --- a/src/Mod/Part/App/TopoShapePyImp.cpp +++ b/src/Mod/Part/App/TopoShapePyImp.cpp @@ -314,6 +314,31 @@ PyObject* TopoShapePy::exportBrep(PyObject *args) Py_Return; } +PyObject* TopoShapePy::dumpToString(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return NULL; + + try { + std::stringstream str; + getTopoShapePtr()->dump(str); + return Py::new_reference_to(Py::String(str.str())); + } + catch (const Base::Exception& e) { + PyErr_SetString(PyExc_Exception,e.what()); + return NULL; + } + catch (const std::exception& e) { + PyErr_SetString(PyExc_Exception,e.what()); + return NULL; + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PyExc_Exception, e->GetMessageString()); + return 0; + } +} + PyObject* TopoShapePy::exportBrepToString(PyObject *args) { if (!PyArg_ParseTuple(args, ""))