From f212a8ef763384497f790ada0ca60197c7847939 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 11 Dec 2021 23:31:41 +0100 Subject: [PATCH] Part: set explicit format version number for BRep files to support all OCC versions --- src/Mod/Part/App/PropertyTopoShape.cpp | 33 ++++++++++---------------- src/Mod/Part/App/TopoShape.cpp | 17 ++++++++++++- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/Mod/Part/App/PropertyTopoShape.cpp b/src/Mod/Part/App/PropertyTopoShape.cpp index 6743402e0a..bf0e888dab 100644 --- a/src/Mod/Part/App/PropertyTopoShape.cpp +++ b/src/Mod/Part/App/PropertyTopoShape.cpp @@ -231,16 +231,9 @@ void PropertyPartShape::Restore(Base::XMLReader &reader) } } -// The following two functions are copied from OCCT BRepTools.cxx and modified +// The following function is copied from OCCT BRepTools.cxx and modified // to disable saving of triangulation // -static void BRepTools_Write(const TopoDS_Shape& Sh, Standard_OStream& S) { - BRepTools_ShapeSet SS(Standard_False); - // SS.SetProgress(PR); - SS.Add(Sh); - SS.Write(S); - SS.Write(Sh,S); -} static Standard_Boolean BRepTools_Write(const TopoDS_Shape& Sh, const Standard_CString File) { @@ -256,7 +249,15 @@ static Standard_Boolean BRepTools_Write(const TopoDS_Shape& Sh, const Standard_ if(!isGood) return isGood; + // See TopTools_FormatVersion of OCCT 7.6 + enum { + VERSION_1 = 1, + VERSION_2 = 2, + VERSION_3 = 3 + }; + BRepTools_ShapeSet SS(Standard_False); + SS.SetFormatNb(VERSION_1); // SS.SetProgress(PR); SS.Add(Sh); @@ -318,19 +319,7 @@ void PropertyPartShape::SaveDocFile (Base::Writer &writer) const Base::ifstream file(fi, std::ios::in | std::ios::binary); if (file) { - //unsigned long ulSize = 0; std::streambuf* buf = file.rdbuf(); - //if (buf) { - // unsigned long ulCurr; - // ulCurr = buf->pubseekoff(0, std::ios::cur, std::ios::in); - // ulSize = buf->pubseekoff(0, std::ios::end, std::ios::in); - // buf->pubseekoff(ulCurr, std::ios::beg, std::ios::in); - //} - - // read in the ASCII file and write back to the stream - //std::strstreambuf sbuf(ulSize); - //file >> &sbuf; - //writer.Stream() << &sbuf; writer.Stream() << buf; } @@ -339,7 +328,9 @@ void PropertyPartShape::SaveDocFile (Base::Writer &writer) const fi.deleteFile(); } else { - BRepTools_Write(myShape, writer.Stream()); + TopoShape shape; + shape.setShape(myShape); + shape.exportBrep(writer.Stream()); } } } diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index 9ae039e2d1..f3c11745b7 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -1024,13 +1024,28 @@ void TopoShape::exportStep(const char *filename) const void TopoShape::exportBrep(const char *filename) const { +#if OCC_VERSION_HEX >= 0x070600 + if (!BRepTools::Write(this->_Shape,encodeFilename(filename).c_str(), Standard_False, Standard_False, TopTools_FormatVersion_VERSION_1)) + throw Base::FileException("Writing of BREP failed"); +#else if (!BRepTools::Write(this->_Shape,encodeFilename(filename).c_str())) throw Base::FileException("Writing of BREP failed"); +#endif } void TopoShape::exportBrep(std::ostream& out) const { - BRepTools::Write(this->_Shape, out); + // See TopTools_FormatVersion of OCCT 7.6 + enum { + VERSION_1 = 1, + VERSION_2 = 2, + VERSION_3 = 3 + }; + BRepTools_ShapeSet SS(Standard_False); + SS.SetFormatNb(VERSION_1); + SS.Add(this->_Shape); + SS.Write(out); + SS.Write(this->_Shape, out); } void TopoShape::exportBinary(std::ostream& out)