From 7f9aa7b4a5e51466a9c81990faba07c372c72dcc Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 7 Sep 2015 19:02:56 +0200 Subject: [PATCH] + add method to write/read BREP in binary format --- cMake/FindOpenCasCade.cmake | 1 + cMake/UseLibPack10x.cmake | 2 ++ cMake/UseLibPack6x.cmake | 1 + cMake/UseLibPack7x.cmake | 1 + cMake/UseLibPack8x.cmake | 2 ++ cMake/UseLibPack9x.cmake | 2 ++ cMake/UseLibPackCustom.cmake | 1 + src/Mod/Part/App/TopoShape.cpp | 25 ++++++++++++++++++ src/Mod/Part/App/TopoShape.h | 2 ++ src/Mod/Part/App/TopoShapePy.xml | 12 ++++++++- src/Mod/Part/App/TopoShapePyImp.cpp | 40 +++++++++++++++++++++++++++++ 11 files changed, 88 insertions(+), 1 deletion(-) diff --git a/cMake/FindOpenCasCade.cmake b/cMake/FindOpenCasCade.cmake index a7796061a..5aa0a8e66 100644 --- a/cMake/FindOpenCasCade.cmake +++ b/cMake/FindOpenCasCade.cmake @@ -104,6 +104,7 @@ if(OCC_FOUND) TKSTL TKShHealing TKXSBase + TKBin TKBool TKBO TKBRep diff --git a/cMake/UseLibPack10x.cmake b/cMake/UseLibPack10x.cmake index 7d9ef49d8..521aff02d 100644 --- a/cMake/UseLibPack10x.cmake +++ b/cMake/UseLibPack10x.cmake @@ -431,6 +431,7 @@ set(OCC_LIBRARIES optimized TKSTL optimized TKShHealing optimized TKXSBase + optimized TKBin optimized TKBool optimized TKBO optimized TKBRep @@ -456,6 +457,7 @@ set(OCC_DEBUG_LIBRARIES debug TKSTLd debug TKShHealingd debug TKXSBased + debug TKBind debug TKBoold debug TKBOd debug TKBRepd diff --git a/cMake/UseLibPack6x.cmake b/cMake/UseLibPack6x.cmake index 07afa3c3b..92da64b1e 100644 --- a/cMake/UseLibPack6x.cmake +++ b/cMake/UseLibPack6x.cmake @@ -305,6 +305,7 @@ set(OCC_LIBRARIES TKSTL TKShHealing TKXSBase + TKBin TKBool TKBO TKBRep diff --git a/cMake/UseLibPack7x.cmake b/cMake/UseLibPack7x.cmake index b5d41c1da..921d38e2e 100644 --- a/cMake/UseLibPack7x.cmake +++ b/cMake/UseLibPack7x.cmake @@ -311,6 +311,7 @@ set(OCC_LIBRARIES TKSTL TKShHealing TKXSBase + TKBin TKBool TKBO TKBRep diff --git a/cMake/UseLibPack8x.cmake b/cMake/UseLibPack8x.cmake index 25eb5b295..57acb8de8 100644 --- a/cMake/UseLibPack8x.cmake +++ b/cMake/UseLibPack8x.cmake @@ -356,6 +356,7 @@ set(OCC_LIBRARIES optimized TKSTL optimized TKShHealing optimized TKXSBase + optimized TKBin optimized TKBool optimized TKXSBase optimized TKBO @@ -391,6 +392,7 @@ set(OCC_DEBUG_LIBRARIES debug TKSTLd debug TKShHealingd debug TKXSBased + debug TKBind debug TKBoold debug TKXSBased debug TKBOd diff --git a/cMake/UseLibPack9x.cmake b/cMake/UseLibPack9x.cmake index 23c6786bd..82e5fb755 100644 --- a/cMake/UseLibPack9x.cmake +++ b/cMake/UseLibPack9x.cmake @@ -371,6 +371,7 @@ set(OCC_LIBRARIES optimized TKSTL optimized TKShHealing optimized TKXSBase + optimized TKBin optimized TKBool optimized TKBO optimized TKBRep @@ -396,6 +397,7 @@ set(OCC_DEBUG_LIBRARIES debug TKSTLd debug TKShHealingd debug TKXSBased + debug TKBind debug TKBoold debug TKBOd debug TKBRepd diff --git a/cMake/UseLibPackCustom.cmake b/cMake/UseLibPackCustom.cmake index 929aeaaf9..b2e1c899c 100644 --- a/cMake/UseLibPackCustom.cmake +++ b/cMake/UseLibPackCustom.cmake @@ -376,6 +376,7 @@ set(OCC_LIBRARIES TKSTL TKShHealing TKXSBase + TKBin TKBool TKBO TKBRep diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index 4984e26ad..fa7dc386a 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -144,6 +144,8 @@ # include # include #endif +# include +# include # include # include # include @@ -670,6 +672,21 @@ void TopoShape::importBrep(std::istream& str) } } +void TopoShape::importBinary(std::istream& str) +{ + BinTools_ShapeSet set; + set.Read(str); + Standard_Integer index; + BinTools::GetInteger(str, index); + + try { + this->_Shape = set.Shape(index); + } + catch (Standard_Failure) { + throw Base::RuntimeError("Failed to read shape from binary stream"); + } +} + void TopoShape::write(const char *FileName) const { Base::FileInfo File(FileName); @@ -758,6 +775,14 @@ void TopoShape::exportBrep(std::ostream& out) const BRepTools::Write(this->_Shape, out); } +void TopoShape::exportBinary(std::ostream& out) +{ + BinTools_ShapeSet set; + Standard_Integer index = set.Add(this->_Shape); + set.Write(out); + BinTools::PutInteger(out, index); +} + void TopoShape::dump(std::ostream& out) const { BRepTools::Dump(this->_Shape, out); diff --git a/src/Mod/Part/App/TopoShape.h b/src/Mod/Part/App/TopoShape.h index 17b339c2b..7949555d6 100644 --- a/src/Mod/Part/App/TopoShape.h +++ b/src/Mod/Part/App/TopoShape.h @@ -124,10 +124,12 @@ public: void importStep(const char *FileName); void importBrep(const char *FileName); void importBrep(std::istream&); + void importBinary(std::istream&); void exportIges(const char *FileName) const; void exportStep(const char *FileName) const; void exportBrep(const char *FileName) const; void exportBrep(std::ostream&) const; + void exportBinary(std::ostream&); void exportStl (const char *FileName, double deflection) 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 3f55bf0e1..2b76c4b82 100644 --- a/src/Mod/Part/App/TopoShapePy.xml +++ b/src/Mod/Part/App/TopoShapePy.xml @@ -53,6 +53,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 in binary format to a file. + + Export the content of this shape to a string in BREP format. BREP is a CasCade native format. @@ -69,13 +74,18 @@ Sub-elements such as vertices, edges or faces are accessible as: + + Load the shape from a file in BREP format. + + + Import the content to this shape of a string in BREP format. - Import the content to this shape from a string in BREP format. + Load the shape from a string that keeps the content in BREP format. diff --git a/src/Mod/Part/App/TopoShapePyImp.cpp b/src/Mod/Part/App/TopoShapePyImp.cpp index 6b4f5174a..cc325b529 100644 --- a/src/Mod/Part/App/TopoShapePyImp.cpp +++ b/src/Mod/Part/App/TopoShapePyImp.cpp @@ -355,6 +355,26 @@ PyObject* TopoShapePy::exportBrep(PyObject *args) Py_Return; } +PyObject* TopoShapePy::exportBinary(PyObject *args) +{ + char* input; + if (!PyArg_ParseTuple(args, "s", &input)) + return NULL; + + try { + // read binary brep + std::ofstream str(input, std::ios::out | std::ios::binary); + getTopoShapePtr()->exportBinary(str); + str.close(); + } + catch (const Base::Exception& e) { + PyErr_SetString(PartExceptionOCCError,e.what()); + return NULL; + } + + Py_Return; +} + PyObject* TopoShapePy::dumpToString(PyObject *args) { if (!PyArg_ParseTuple(args, "")) @@ -430,6 +450,26 @@ PyObject* TopoShapePy::importBrep(PyObject *args) Py_Return; } +PyObject* TopoShapePy::importBinary(PyObject *args) +{ + char* input; + if (!PyArg_ParseTuple(args, "s", &input)) + return NULL; + + try { + // read binary brep + std::ifstream str(input, std::ios::in | std::ios::binary); + getTopoShapePtr()->importBinary(str); + str.close(); + } + catch (const Base::Exception& e) { + PyErr_SetString(PartExceptionOCCError,e.what()); + return NULL; + } + + Py_Return; +} + PyObject* TopoShapePy::importBrepFromString(PyObject *args) { char* input;