From 013b5f0dcef42816796d4da9cc210deb5a17ef52 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 28 Jun 2012 18:29:48 +0200 Subject: [PATCH] 0000764: Serialize Shape to python String --- src/Mod/Part/App/TopoShape.cpp | 5 +++ src/Mod/Part/App/TopoShape.h | 1 + src/Mod/Part/App/TopoShapePy.xml | 10 ++++++ src/Mod/Part/App/TopoShapePyImp.cpp | 54 +++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+) diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index 8ebac8242..d8a5a13e2 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -726,6 +726,11 @@ void TopoShape::exportBrep(const char *filename) const throw Base::Exception("Writing of BREP failed"); } +void TopoShape::exportBrep(std::ostream& out) +{ + BRepTools::Write(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 aaf521e05..26e891a9c 100644 --- a/src/Mod/Part/App/TopoShape.h +++ b/src/Mod/Part/App/TopoShape.h @@ -126,6 +126,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 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 34522f5f9..c144c1986 100644 --- a/src/Mod/Part/App/TopoShapePy.xml +++ b/src/Mod/Part/App/TopoShapePy.xml @@ -43,6 +43,11 @@ Sub-elements such as vertices, edges or faces are accessible as: Export the content of this shape to an BREP file. BREP is a CasCade native format. + + + Export the content of this shape to a string in BREP format. BREP is a CasCade native format. + + Export the content of this shape to an STL mesh file. @@ -53,6 +58,11 @@ Sub-elements such as vertices, edges or faces are accessible as: Import the content to this shape of a string in BREP format. + + + Import the content to this shape from a string in BREP format. + + Extrude the shape along a direction. diff --git a/src/Mod/Part/App/TopoShapePyImp.cpp b/src/Mod/Part/App/TopoShapePyImp.cpp index 8f641a2f7..1dc8bfc3a 100644 --- a/src/Mod/Part/App/TopoShapePyImp.cpp +++ b/src/Mod/Part/App/TopoShapePyImp.cpp @@ -311,6 +311,32 @@ PyObject* TopoShapePy::exportBrep(PyObject *args) Py_Return; } +PyObject* TopoShapePy::exportBrepToString(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return NULL; + + try { + // write brep file + std::stringstream str; + getTopoShapePtr()->exportBrep(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::importBrep(PyObject *args) { PyObject* input; @@ -335,6 +361,34 @@ PyObject* TopoShapePy::importBrep(PyObject *args) Py_Return; } +PyObject* TopoShapePy::importBrepFromString(PyObject *args) +{ + char* input; + if (!PyArg_ParseTuple(args, "s", &input)) + return NULL; + + try { + // read brep + std::stringstream str(input); + getTopoShapePtr()->importBrep(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; + } + + Py_Return; +} + PyObject* TopoShapePy::exportStl(PyObject *args) { char* filename;