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

@@ -171,14 +171,16 @@ Standard_IStream& BinTools::GetBool(Standard_IStream& IS, Standard_Boolean& aVal
//=======================================================================
//function : Write
//purpose :
//purpose :
//=======================================================================
void BinTools::Write (const TopoDS_Shape& theShape, Standard_OStream& theStream,
void BinTools::Write (const TopoDS_Shape& theShape,
Standard_OStream& theStream,
const Standard_Boolean theWithTriangles,
const BinTools_FormatVersion theVersion,
const Message_ProgressRange& theRange)
{
BinTools_ShapeSet aShapeSet(Standard_True);
aShapeSet.SetFormatNb (3);
BinTools_ShapeSet aShapeSet (theWithTriangles);
aShapeSet.SetFormatNb (theVersion);
aShapeSet.Add (theShape);
aShapeSet.Write (theStream, theRange);
aShapeSet.Write (theShape, theStream);
@@ -199,10 +201,12 @@ void BinTools::Read (TopoDS_Shape& theShape, Standard_IStream& theStream,
//=======================================================================
//function : Write
//purpose :
//purpose :
//=======================================================================
Standard_Boolean BinTools::Write (const TopoDS_Shape& theShape, const Standard_CString theFile,
Standard_Boolean BinTools::Write (const TopoDS_Shape& theShape,
const Standard_CString theFile,
const Standard_Boolean theWithTriangles,
const BinTools_FormatVersion theVersion,
const Message_ProgressRange& theRange)
{
std::ofstream aStream;
@@ -211,7 +215,7 @@ Standard_Boolean BinTools::Write (const TopoDS_Shape& theShape, const Standard_C
if (!aStream.good())
return Standard_False;
Write (theShape, aStream, theRange);
Write (theShape, aStream, theWithTriangles, theVersion, theRange);
aStream.close();
return aStream.good();
}

View File

@@ -16,6 +16,7 @@
#ifndef _BinTools_HeaderFile
#define _BinTools_HeaderFile
#include <BinTools_FormatVersion.hxx>
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>
@@ -62,20 +63,61 @@ public:
Standard_EXPORT static Standard_IStream& GetBool (Standard_IStream& IS, Standard_Boolean& theValue);
Standard_EXPORT static Standard_IStream& GetExtChar (Standard_IStream& IS, Standard_ExtCharacter& theValue);
//! Writes <theShape> on <theStream> in binary format.
Standard_EXPORT static void Write (const TopoDS_Shape& theShape, Standard_OStream& theStream,
const Message_ProgressRange& theRange = Message_ProgressRange());
//! Writes the shape to the stream in binary format BinTools_FormatVersion_CURRENT.
//! 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& theRange = Message_ProgressRange())
{
Write (theShape, theStream, Standard_True,
BinTools_FormatVersion_CURRENT, theRange);
}
//! Writes the shape to the stream in binary 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 BinTools 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 BinTools_FormatVersion theVersion,
const Message_ProgressRange& theRange = Message_ProgressRange());
//! Reads a shape from <theStream> and returns it in <theShape>.
Standard_EXPORT static void Read (TopoDS_Shape& theShape, Standard_IStream& theStream,
const Message_ProgressRange& theRange = Message_ProgressRange());
//! Writes <theShape> in <theFile>.
Standard_EXPORT static Standard_Boolean Write
(const TopoDS_Shape& theShape, const Standard_CString theFile,
const Message_ProgressRange& theRange = Message_ProgressRange());
//! Writes the shape to the file in binary format BinTools_FormatVersion_CURRENT.
//! @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& theRange = Message_ProgressRange())
{
return Write (theShape, theFile, Standard_True,
BinTools_FormatVersion_CURRENT, theRange);
}
//! Writes the shape to the file in binary 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 BinTools 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 BinTools_FormatVersion theVersion,
const Message_ProgressRange& theRange = Message_ProgressRange());
//! Reads a shape from <theFile> and returns it in <theShape>.
Standard_EXPORT static Standard_Boolean Read
(TopoDS_Shape& theShape, const Standard_CString theFile,

View File

@@ -0,0 +1,30 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _BinToolsFormatVersion_HeaderFile
#define _BinToolsFormatVersion_HeaderFile
//! Defined BinTools format version
enum BinTools_FormatVersion
{
BinTools_FormatVersion_VERSION_1 = 1, //!< Does not write CurveOnSurface UV Points into the file.
//! On reading calls Check() method.
BinTools_FormatVersion_VERSION_2 = 2, //!< Stores CurveOnSurface UV Points.
//! On reading format is recognized from Version string.
BinTools_FormatVersion_VERSION_3 = 3, //!< (OCCT 6.2.1) Correctly processes geometry with points on Curve,
//! or point on Surface, or points on curve of surface [#0009745]
BinTools_FormatVersion_CURRENT = BinTools_FormatVersion_VERSION_3 //!< The current version.
};
#endif

View File

@@ -55,9 +55,10 @@
#include <string.h>
//#define MDTV_DEB 1
const char* Version_1 = "Open CASCADE Topology V1 (c)";
const char* Version_2 = "Open CASCADE Topology V2 (c)";
const char* Version_3 = "Open CASCADE Topology V3 (c)";
Standard_CString BinTools_ShapeSet::Version_1 = "Open CASCADE Topology V1 (c)";
Standard_CString BinTools_ShapeSet::Version_2 = "Open CASCADE Topology V2 (c)";
Standard_CString BinTools_ShapeSet::Version_3 = "Open CASCADE Topology V3 (c)";
//=======================================================================
//function : operator << (gp_Pnt)
//purpose :
@@ -72,11 +73,11 @@ static Standard_OStream& operator <<(Standard_OStream& OS, const gp_Pnt P)
}
//=======================================================================
//function : BinTools_ShapeSet
//purpose :
//purpose :
//=======================================================================
BinTools_ShapeSet::BinTools_ShapeSet(const Standard_Boolean isWithTriangles)
:myFormatNb(3), myWithTriangles(isWithTriangles)
BinTools_ShapeSet::BinTools_ShapeSet (const Standard_Boolean theWithTriangles)
: myFormatNb (BinTools_FormatVersion_CURRENT),
myWithTriangles (theWithTriangles)
{}
//=======================================================================
@@ -93,6 +94,10 @@ BinTools_ShapeSet::~BinTools_ShapeSet()
//=======================================================================
void BinTools_ShapeSet::SetFormatNb(const Standard_Integer theFormatNb)
{
Standard_ASSERT_RETURN(theFormatNb >= BinTools_FormatVersion_VERSION_1 &&
theFormatNb <= BinTools_FormatVersion_CURRENT,
"Error: unsupported BinTools version.", );
myFormatNb = theFormatNb;
}
@@ -325,14 +330,19 @@ void BinTools_ShapeSet::WriteGeometry (Standard_OStream& OS,
void BinTools_ShapeSet::Write (Standard_OStream& OS,
const Message_ProgressRange& theRange)const
{
// write the copyright
if (myFormatNb == 3)
if (myFormatNb == BinTools_FormatVersion_VERSION_3)
{
OS << "\n" << Version_3 << "\n";
else if (myFormatNb == 2)
}
else if (myFormatNb == BinTools_FormatVersion_VERSION_2)
{
OS << "\n" << Version_2 << "\n";
}
else
{
OS << "\n" << Version_1 << "\n";
}
//-----------------------------------------
// write the locations
@@ -415,13 +425,22 @@ void BinTools_ShapeSet::Read (Standard_IStream& IS,
} while ( ! IS.fail() && strcmp(vers,Version_1) && strcmp(vers,Version_2) &&
strcmp(vers,Version_3));
if (IS.fail()) {
std::cout << "BinTools_ShapeSet::Read: File was not written with this version of the topology"<<std::endl;
return;
std::cout << "BinTools_ShapeSet::Read: File was not written with this version of the topology" << std::endl;
return;
}
if (strcmp(vers,Version_3) == 0) SetFormatNb(3);
else if (strcmp(vers,Version_2) == 0) SetFormatNb(2);
else SetFormatNb(1);
if (strcmp (vers, Version_3) == 0)
{
SetFormatNb (BinTools_FormatVersion_VERSION_3);
}
else if (strcmp (vers, Version_2) == 0)
{
SetFormatNb (BinTools_FormatVersion_VERSION_2);
}
else
{
SetFormatNb (BinTools_FormatVersion_VERSION_1);
}
//-----------------------------------------
// read the locations
@@ -481,7 +500,7 @@ void BinTools_ShapeSet::Read (Standard_IStream& IS,
S.Free(aFree);
S.Modified(aMod);
if (myFormatNb >= 2)
if (myFormatNb >= BinTools_FormatVersion_VERSION_2)
S.Checked(aChecked);
else
S.Checked (Standard_False); // force check at reading..
@@ -491,7 +510,7 @@ void BinTools_ShapeSet::Read (Standard_IStream& IS,
S.Convex (aConv);
// check
if (myFormatNb == 1)
if (myFormatNb == BinTools_FormatVersion_VERSION_1)
if(T == TopAbs_FACE) {
const TopoDS_Face& F = TopoDS::Face(S);
BRepTools::Update(F);
@@ -684,7 +703,7 @@ void BinTools_ShapeSet::WriteGeometry (const TopoDS_Shape& S,
BinTools::PutReal(OS, last);
// Write UV Points for higher performance
if (FormatNb() >= 2)
if (myFormatNb >= BinTools_FormatVersion_VERSION_2)
{
gp_Pnt2d Pf,Pl;
if (CR->IsCurveOnClosedSurface()) {
@@ -828,7 +847,7 @@ void BinTools_ShapeSet::ReadGeometry(const TopAbs_ShapeEnum T,
BRep_ListOfPointRepresentation& lpr = TV->ChangePoints();
TopLoc_Location L;
Standard_Boolean aNewF = (myFormatNb > 2);
Standard_Boolean aNewF = (myFormatNb >= BinTools_FormatVersion_VERSION_3);
do {
if(aNewF) {
val = (Standard_Integer)IS.get();//case {0|1|2|3}
@@ -992,7 +1011,7 @@ void BinTools_ShapeSet::ReadGeometry(const TopAbs_ShapeEnum T,
BinTools::GetReal(IS, last);
// read UV Points // for XML Persistence higher performance
if (FormatNb() >= 2)
if (myFormatNb >= BinTools_FormatVersion_VERSION_2)
{
BinTools::GetReal(IS, PfX);
BinTools::GetReal(IS, PfY);
@@ -1008,7 +1027,7 @@ void BinTools_ShapeSet::ReadGeometry(const TopAbs_ShapeEnum T,
break;
if (closed) {
if (FormatNb() >= 2)
if (myFormatNb >= BinTools_FormatVersion_VERSION_2)
myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
myCurves2d.Curve2d(pc2),
mySurfaces.Surface(s),
@@ -1029,7 +1048,7 @@ void BinTools_ShapeSet::ReadGeometry(const TopAbs_ShapeEnum T,
}
else
{
if (FormatNb() >= 2)
if (myFormatNb >= BinTools_FormatVersion_VERSION_2)
myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
mySurfaces.Surface(s),
Locations().Location(l),tol,

View File

@@ -21,6 +21,7 @@
#include <Standard_Handle.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <BinTools_FormatVersion.hxx>
#include <BinTools_LocationSet.hxx>
#include <Standard_Integer.hxx>
#include <BRep_Builder.hxx>
@@ -44,11 +45,10 @@ public:
DEFINE_STANDARD_ALLOC
//! Builds an empty ShapeSet.
//! Parameter <isWithTriangles> is added for XML Persistence
Standard_EXPORT BinTools_ShapeSet(const Standard_Boolean isWithTriangles = Standard_False);
//! @param theWithTriangles [in] flag to write triangulation data
Standard_EXPORT BinTools_ShapeSet (const Standard_Boolean theWithTriangles = Standard_False);
Standard_EXPORT virtual ~BinTools_ShapeSet();
//! Return true if shape should be stored with triangles.
@@ -56,15 +56,12 @@ public:
//! Define if shape will be stored with triangles.
//! Ignored (always written) if face defines only triangulation (no surface).
void SetWithTriangles (const Standard_Boolean isWithTriangles) { myWithTriangles = isWithTriangles; }
void SetWithTriangles (const Standard_Boolean theWithTriangles) { myWithTriangles = theWithTriangles; }
//! Sets the BinTools_FormatVersion.
Standard_EXPORT void SetFormatNb (const Standard_Integer theFormatNb);
//! two formats available for the moment:
//! First: does not write CurveOnSurface UV Points into the file
//! on reading calls Check() method.
//! Second: stores CurveOnSurface UV Points.
//! On reading format is recognized from Version string.
//! Returns the BinTools_FormatVersion.
Standard_EXPORT Standard_Integer FormatNb() const;
//! Clears the content of the set.
@@ -194,6 +191,12 @@ public:
(Standard_OStream& OS,
const Message_ProgressRange& theRange = Message_ProgressRange()) const;
public:
static Standard_CString Version_1;
static Standard_CString Version_2;
static Standard_CString Version_3;
private:
TopTools_IndexedMapOfShape myShapes;

View File

@@ -4,6 +4,7 @@ BinTools_Curve2dSet.cxx
BinTools_Curve2dSet.hxx
BinTools_CurveSet.cxx
BinTools_CurveSet.hxx
BinTools_FormatVersion.hxx
BinTools_LocationSet.cxx
BinTools_LocationSet.hxx
BinTools_LocationSetPtr.hxx