1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0031946: Modeling Data - replace version numbers with enumerations in TopTools and BinTools

Added enumerations BinTools_FormatVersion & TopTools_FormatVersion for more clear version tracking in the code.
Added new BinTools::Write() & BRepTools::Write() overloaded functions with version & isWithTriangles parameters.

Added new "readbrep"/"writebrep" DRAW commands handling reading and writing of both Binary and ASCII .brep formats
and providing arguments to setup writing of triangulation data and of format version.
"binrestore" is made an alias to new command "readbrep".
"binsave" now is an alias to new "writebrep" saving into binary format by default ("writebrep" writes into ASCII format by default).
This commit is contained in:
asuraven
2020-11-03 17:22:14 +03:00
committed by bugmaster
parent 1e1158c78b
commit 14eea8293d
44 changed files with 653 additions and 203 deletions

View File

@@ -663,19 +663,21 @@ void BRepTools::Dump(const TopoDS_Shape& Sh, Standard_OStream& S)
//=======================================================================
//function : Write
//purpose :
//purpose :
//=======================================================================
void BRepTools::Write(const TopoDS_Shape& Sh, Standard_OStream& S,
void BRepTools::Write (const TopoDS_Shape& theShape,
Standard_OStream& theStream,
const Standard_Boolean theWithTriangles,
const TopTools_FormatVersion theVersion,
const Message_ProgressRange& theProgress)
{
BRepTools_ShapeSet SS;
SS.Add(Sh);
SS.Write(S, theProgress);
SS.Write(Sh,S);
BRepTools_ShapeSet aShapeSet (theWithTriangles);
aShapeSet.SetFormatNb (theVersion);
aShapeSet.Add (theShape);
aShapeSet.Write (theStream, theProgress);
aShapeSet.Write (theShape, theStream);
}
//=======================================================================
//function : Read
//purpose :
@@ -693,30 +695,34 @@ void BRepTools::Read(TopoDS_Shape& Sh,
//=======================================================================
//function : Write
//purpose :
//purpose :
//=======================================================================
Standard_Boolean BRepTools::Write(const TopoDS_Shape& Sh,
const Standard_CString File,
const Message_ProgressRange& theProgress)
Standard_Boolean BRepTools::Write (const TopoDS_Shape& theShape,
const Standard_CString theFile,
const Standard_Boolean theWithTriangles,
const TopTools_FormatVersion theVersion,
const Message_ProgressRange& theProgress)
{
std::ofstream os;
OSD_OpenStream(os, File, std::ios::out);
OSD_OpenStream(os, theFile, std::ios::out);
if (!os.is_open() || !os.good())
return Standard_False;
Standard_Boolean isGood = (os.good() && !os.eof());
if(!isGood)
return isGood;
BRepTools_ShapeSet SS;
SS.Add(Sh);
BRepTools_ShapeSet SS (theWithTriangles);
SS.SetFormatNb (theVersion);
SS.Add (theShape);
os << "DBRep_DrawableShape\n"; // for easy Draw read
SS.Write(os, theProgress);
isGood = os.good();
if(isGood )
SS.Write(Sh,os);
if (isGood)
{
SS.Write (theShape, os);
}
os.flush();
isGood = os.good();

View File

@@ -17,6 +17,7 @@
#ifndef _BRepTools_HeaderFile
#define _BRepTools_HeaderFile
#include <TopTools_FormatVersion.hxx>
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>
@@ -203,20 +204,64 @@ public:
//! Dumps the topological structure and the geometry
//! of <Sh> on the stream <S>.
Standard_EXPORT static void Dump (const TopoDS_Shape& Sh, Standard_OStream& S);
//! Writes <Sh> on <S> in an ASCII format.
Standard_EXPORT static void Write (const TopoDS_Shape& Sh, Standard_OStream& S,
//! Writes the shape to the stream in an ASCII format TopTools_FormatVersion_VERSION_1.
//! This alias writes shape with triangulation data.
//! @param theShape [in] the shape to write
//! @param theStream [in][out] the stream to output shape into
//! @param theRange the range of progress indicator to fill in
static void Write (const TopoDS_Shape& theShape,
Standard_OStream& theStream,
const Message_ProgressRange& theProgress = Message_ProgressRange())
{
Write (theShape, theStream, Standard_True,
TopTools_FormatVersion_VERSION_1, theProgress);
}
//! Writes the shape to the stream in an ASCII format of specified version.
//! @param theShape [in] the shape to write
//! @param theStream [in][out] the stream to output shape into
//! @param theWithTriangles [in] flag which specifies whether to save shape with (TRUE) or without (FALSE) triangles;
//! has no effect on triangulation-only geometry
//! @param theVersion [in] the TopTools format version
//! @param theRange the range of progress indicator to fill in
Standard_EXPORT static void Write (const TopoDS_Shape& theShape,
Standard_OStream& theStream,
const Standard_Boolean theWithTriangles,
const TopTools_FormatVersion theVersion,
const Message_ProgressRange& theProgress = Message_ProgressRange());
//! Reads a Shape from <S> in returns it in <Sh>.
//! <B> is used to build the shape.
Standard_EXPORT static void Read (TopoDS_Shape& Sh, Standard_IStream& S, const BRep_Builder& B,
const Message_ProgressRange& theProgress = Message_ProgressRange());
//! Writes <Sh> in <File>.
Standard_EXPORT static Standard_Boolean Write (const TopoDS_Shape& Sh, const Standard_CString File,
//! Writes the shape to the file in an ASCII format TopTools_FormatVersion_VERSION_1.
//! This alias writes shape with triangulation data.
//! @param theShape [in] the shape to write
//! @param theFile [in] the path to file to output shape into
//! @param theRange the range of progress indicator to fill in
static Standard_Boolean Write (const TopoDS_Shape& theShape,
const Standard_CString theFile,
const Message_ProgressRange& theProgress = Message_ProgressRange())
{
return Write (theShape, theFile, Standard_True,
TopTools_FormatVersion_VERSION_1, theProgress);
}
//! Writes the shape to the file in an ASCII format of specified version.
//! @param theShape [in] the shape to write
//! @param theFile [in] the path to file to output shape into
//! @param theWithTriangles [in] flag which specifies whether to save shape with (TRUE) or without (FALSE) triangles;
//! has no effect on triangulation-only geometry
//! @param theVersion [in] the TopTools format version
//! @param theRange the range of progress indicator to fill in
Standard_EXPORT static Standard_Boolean Write (const TopoDS_Shape& theShape,
const Standard_CString theFile,
const Standard_Boolean theWithTriangles,
const TopTools_FormatVersion theVersion,
const Message_ProgressRange& theProgress = Message_ProgressRange());
//! Reads a Shape from <File>, returns it in <Sh>.
//! <B> is used to build the shape.
Standard_EXPORT static Standard_Boolean Read (TopoDS_Shape& Sh, const Standard_CString File,

View File

@@ -82,25 +82,32 @@
//=======================================================================
//function : BRepTools_ShapeSet
//purpose :
//purpose :
//=======================================================================
BRepTools_ShapeSet::BRepTools_ShapeSet(const Standard_Boolean isWithTriangles)
:myWithTriangles(isWithTriangles)
BRepTools_ShapeSet::BRepTools_ShapeSet (const Standard_Boolean theWithTriangles)
: myWithTriangles (theWithTriangles)
{
}
//=======================================================================
//function : BRepTools_ShapeSet
//purpose :
//purpose :
//=======================================================================
BRepTools_ShapeSet::BRepTools_ShapeSet (const BRep_Builder& B,
const Standard_Boolean isWithTriangles) :
myBuilder(B), myWithTriangles(isWithTriangles)
BRepTools_ShapeSet::BRepTools_ShapeSet (const BRep_Builder& theBuilder,
const Standard_Boolean theWithTriangles)
: myBuilder (theBuilder),
myWithTriangles (theWithTriangles)
{
}
//=======================================================================
//function : ~BRepTools_ShapeSet
//purpose :
//=======================================================================
BRepTools_ShapeSet::~BRepTools_ShapeSet()
{
//
}
//=======================================================================
//function : Clear
@@ -592,7 +599,7 @@ void BRepTools_ShapeSet::WriteGeometry (const TopoDS_Shape& S, Standard_OStream
OS << "\n";
// Write UV Points // for XML Persistence higher performance
if (FormatNb() == 2)
if (FormatNb() >= TopTools_FormatVersion_VERSION_2)
{
gp_Pnt2d Pf,Pl;
if (CR->IsCurveOnClosedSurface()) {
@@ -902,7 +909,7 @@ void BRepTools_ShapeSet::ReadGeometry (const TopAbs_ShapeEnum T,
GeomTools::GetReal(IS, last);
// read UV Points // for XML Persistence higher performance
if (FormatNb() == 2)
if (FormatNb() >= TopTools_FormatVersion_VERSION_2)
{
GeomTools::GetReal(IS, PfX);
GeomTools::GetReal(IS, PfY);
@@ -920,7 +927,7 @@ void BRepTools_ShapeSet::ReadGeometry (const TopAbs_ShapeEnum T,
// Modified by Sergey KHROMOV - Wed Apr 24 12:11:17 2002 End
if (closed) {
if (FormatNb() == 2)
if (FormatNb() >= TopTools_FormatVersion_VERSION_2)
myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
myCurves2d.Curve2d(pc2),
mySurfaces.Surface(s),
@@ -941,7 +948,7 @@ void BRepTools_ShapeSet::ReadGeometry (const TopAbs_ShapeEnum T,
}
else
{
if (FormatNb() == 2)
if (FormatNb() >= TopTools_FormatVersion_VERSION_2)
myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
mySurfaces.Surface(s),
Locations().Location(l),tol,

View File

@@ -46,16 +46,24 @@ public:
DEFINE_STANDARD_ALLOC
//! Builds an empty ShapeSet.
//! @param theWithTriangles flag to write triangulation data
Standard_EXPORT BRepTools_ShapeSet (const Standard_Boolean theWithTriangles = Standard_True);
//! Builds an empty ShapeSet.
//! Parameter <isWithTriangles> is added for XML Persistence
Standard_EXPORT BRepTools_ShapeSet (const Standard_Boolean isWithTriangles = Standard_True);
//! Builds an empty ShapeSet.
//! Parameter <isWithTriangles> is added for XML Persistence
Standard_EXPORT BRepTools_ShapeSet (const BRep_Builder& B,
const Standard_Boolean isWithTriangles = Standard_True);
//! @param theWithTriangles flag to write triangulation data
Standard_EXPORT BRepTools_ShapeSet (const BRep_Builder& theBuilder,
const Standard_Boolean theWithTriangles = Standard_True);
Standard_EXPORT virtual ~BRepTools_ShapeSet();
//! Return true if shape should be stored with triangles.
Standard_Boolean IsWithTriangles() const { return myWithTriangles; }
//! Define if shape will be stored with triangles.
//! Ignored (always written) if face defines only triangulation (no surface).
void SetWithTriangles (const Standard_Boolean theWithTriangles) { myWithTriangles = theWithTriangles; }
//! Clears the content of the set.
Standard_EXPORT virtual void Clear() Standard_OVERRIDE;