From 9139ab37d349d5cff42a80da3d6fd9228809975e Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 29 Feb 2016 18:37:36 +0100 Subject: [PATCH] + change binary export & import of shapes to restore placement and orientation --- src/Mod/Part/App/TopoShape.cpp | 41 ++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index b1143e34d..a0c7fc819 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -674,13 +674,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); + BinTools_ShapeSet theShapeSet; + theShapeSet.Read(str); + Standard_Integer shapeId=0, locId=0, orient=0; + BinTools::GetInteger(str, shapeId); + if (shapeId <= 0 || shapeId > theShapeSet.NbShapes()) + return; + + BinTools::GetInteger(str, locId); + BinTools::GetInteger(str, orient); + TopAbs_Orientation anOrient = static_cast(orient); try { - this->_Shape = set.Shape(index); + this->_Shape = theShapeSet.Shape(shapeId); + this->_Shape.Location(theShapeSet.Locations().Location (locId)); + this->_Shape.Orientation (anOrient); } catch (Standard_Failure) { throw Base::RuntimeError("Failed to read shape from binary stream"); @@ -777,10 +785,25 @@ void TopoShape::exportBrep(std::ostream& out) const void TopoShape::exportBinary(std::ostream& out) { - BinTools_ShapeSet set; - Standard_Integer index = set.Add(this->_Shape); - set.Write(out); - BinTools::PutInteger(out, index); + // An example how to use BinTools_ShapeSet can be found in BinMNaming_NamedShapeDriver.cxx + BinTools_ShapeSet theShapeSet; + if (this->_Shape.IsNull()) { + theShapeSet.Add(this->_Shape); + theShapeSet.Write(out); + BinTools::PutInteger(out, -1); + BinTools::PutInteger(out, -1); + BinTools::PutInteger(out, -1); + } + else { + Standard_Integer shapeId = theShapeSet.Add(this->_Shape); + Standard_Integer locId = theShapeSet.Locations().Index(this->_Shape.Location()); + Standard_Integer orient = static_cast(this->_Shape.Orientation()); + + theShapeSet.Write(out); + BinTools::PutInteger(out, shapeId); + BinTools::PutInteger(out, locId); + BinTools::PutInteger(out, orient); + } } void TopoShape::dump(std::ostream& out) const