]> OCCT Git - occt.git/commitdiff
0031946: Modeling Data - replace version numbers with enumerations in TopTools and...
authorasuraven <asuraven@opencascade.com>
Tue, 3 Nov 2020 14:22:14 +0000 (17:22 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 17 Dec 2020 18:17:42 +0000 (21:17 +0300)
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).

44 files changed:
src/BRepTools/BRepTools.cxx
src/BRepTools/BRepTools.hxx
src/BRepTools/BRepTools_ShapeSet.cxx
src/BRepTools/BRepTools_ShapeSet.hxx
src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx
src/BinMDataStd/BinMDataStd.hxx
src/BinMDataStd/BinMDataStd_AsciiStringDriver.cxx
src/BinMDataStd/BinMDataStd_ByteArrayDriver.cxx
src/BinMDataStd/BinMDataStd_ExtStringArrayDriver.cxx
src/BinMDataStd/BinMDataStd_GenericExtStringDriver.cxx
src/BinMDataStd/BinMDataStd_IntPackedMapDriver.cxx
src/BinMDataStd/BinMDataStd_IntegerArrayDriver.cxx
src/BinMDataStd/BinMDataStd_IntegerDriver.cxx
src/BinMDataStd/BinMDataStd_RealArrayDriver.cxx
src/BinMDataStd/BinMDataStd_RealDriver.cxx
src/BinMNaming/BinMNaming_NamedShapeDriver.cxx
src/BinMNaming/BinMNaming_NamingDriver.cxx
src/BinMXCAFDoc/BinMXCAFDoc_LocationDriver.cxx
src/BinTools/BinTools.cxx
src/BinTools/BinTools.hxx
src/BinTools/BinTools_FormatVersion.hxx [new file with mode: 0644]
src/BinTools/BinTools_ShapeSet.cxx
src/BinTools/BinTools_ShapeSet.hxx
src/BinTools/FILES
src/DBRep/DBRep.cxx
src/Draw/Draw_VariableCommands.cxx
src/Storage/Storage_HeaderData.hxx
src/TopTools/FILES
src/TopTools/TopTools_FormatVersion.hxx [new file with mode: 0644]
src/TopTools/TopTools_ShapeSet.cxx
src/TopTools/TopTools_ShapeSet.hxx
src/XmlLDrivers/XmlLDrivers_DocumentRetrievalDriver.cxx
src/XmlLDrivers/XmlLDrivers_DocumentStorageDriver.cxx
src/XmlMDF/XmlMDF.cxx
src/XmlMDataStd/XmlMDataStd_ByteArrayDriver.cxx
src/XmlMDataStd/XmlMDataStd_ExtStringArrayDriver.cxx
src/XmlMDataStd/XmlMDataStd_IntPackedMapDriver.cxx
src/XmlMDataStd/XmlMDataStd_IntegerArrayDriver.cxx
src/XmlMDataStd/XmlMDataStd_RealArrayDriver.cxx
src/XmlMDataStd/XmlMDataStd_TreeNodeDriver.cxx
src/XmlMNaming/XmlMNaming_NamedShapeDriver.cxx
src/XmlMNaming/XmlMNaming_NamingDriver.cxx
src/XmlMXCAFDoc/XmlMXCAFDoc_LocationDriver.cxx
tests/bugs/moddata_3/bug31946 [new file with mode: 0644]

index 7860c5d76a6dd39cf50d0f86b504c3c55cde5ba8..f4ec0d21627e60edfea05763b92ad424c29b05a9 100644 (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();
 
index a8cf855b1059fb75101261903b9dcb1faa1e4c7f..9744e3083ef80363cf5a329fc4f30a9284d83810 100644 (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,
index 5b89b218f3cc6be9d3e9b55c30f0ecb5a73d1dc9..ab569703cc7770dacc61ce1fc31d13eb11a521ea 100644 (file)
 
 //=======================================================================
 //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,
index ac5197b4521cc356095a394907b22691d843a5eb..3406666af8ae27b7f29a78eef032c65b5d3fef9b 100644 (file)
@@ -46,16 +46,24 @@ public:
 
   DEFINE_STANDARD_ALLOC
 
-  
   //! Builds an empty ShapeSet.
-  //! Parameter <isWithTriangles> is added for XML Persistence
-  Standard_EXPORT BRepTools_ShapeSet (const Standard_Boolean isWithTriangles = Standard_True);
+  //! @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 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;
   
index c8c26991c19b8b33d0e5d9d6964971143827e4d0..9e29d27bf6fa44c0fa505b0327f94848970e3bb2 100644 (file)
@@ -41,6 +41,7 @@
 #include <TDF_Data.hxx>
 #include <TDF_Label.hxx>
 #include <TDocStd_Document.hxx>
+#include <TDocStd_FormatVersion.hxx>
 #include <TDocStd_Owner.hxx>
 #include <Message_ProgressScope.hxx>
 
@@ -192,7 +193,7 @@ void BinLDrivers_DocumentRetrievalDriver::Read (Standard_IStream&
     else if (aStr == END_TYPES)
       break;
     else if (begin) {
-      if ( aFileVer < ) {
+      if ( aFileVer < TDocStd_FormatVersion_VERSION_8) {
 #ifdef DATATYPE_MIGRATION
         TCollection_AsciiString  newName;      
         if(Storage_Schema::CheckTypeMigration(aStr, newName)) {
@@ -236,7 +237,7 @@ void BinLDrivers_DocumentRetrievalDriver::Read (Standard_IStream&
   Message_ProgressScope aPS(theRange, "Reading data", 3);
 
   // 2b. Read the TOC of Sections
-  if (aFileVer >= 3) {
+  if (aFileVer >= TDocStd_FormatVersion_VERSION_3) {
     BinLDrivers_DocumentSection aSection;
     do {
       BinLDrivers_DocumentSection::ReadTOC (aSection, theIStream, aFileVer);
@@ -347,7 +348,7 @@ void BinLDrivers_DocumentRetrievalDriver::Read (Standard_IStream&
   }
 
   // Read Sections (post-reading type)
-  if (aFileVer >= 3) {
+  if (aFileVer >= TDocStd_FormatVersion_VERSION_3) {
     BinLDrivers_VectorOfDocumentSection::Iterator aSectIter (mySections);
     for (; aSectIter.More(); aSectIter.Next()) {
       BinLDrivers_DocumentSection& aCurSection = aSectIter.ChangeValue();
@@ -569,7 +570,7 @@ Standard_Boolean BinLDrivers_DocumentRetrievalDriver::CheckDocumentVersion(
                                                           const Standard_Integer theFileVersion,
                                                           const Standard_Integer theCurVersion)
 {
-  if (theFileVersion < 2 || theFileVersion > theCurVersion) {
+  if (theFileVersion < TDocStd_FormatVersion_VERSION_2 || theFileVersion > theCurVersion) {
     // file was written with another version
     return Standard_False;
   }
index 50864bb07c5a90637c67008d1868344dd138fba8..52576381359effd3ce9688aa167c28374f0000b2 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <Standard_Integer.hxx>
 #include <BinObjMgt_Persistent.hxx>
+#include <TDocStd_FormatVersion.hxx>
 
 class BinMDF_ADriverTable;
 class Message_Messenger;
@@ -41,7 +42,7 @@ template<class T>
 static void SetAttributeID(const BinObjMgt_Persistent& theSource, const Handle(T)& anAtt, const Standard_Integer aDocFormatVersion)
 {
   Standard_Boolean ok = Standard_True;
-  if(aDocFormatVersion > 9) { // process user defined guid
+  if(aDocFormatVersion >= TDocStd_FormatVersion_VERSION_10) { // process user defined guid
     const Standard_Integer& aPos = theSource.Position();
     Standard_GUID aGuid;
     ok = theSource >> aGuid;
index cc17b780672a9391a93c53a6e42e30cca0393225..3a6fc346759b2d656bf8cb1c3651213f38f2758e 100644 (file)
@@ -23,6 +23,7 @@
 #include <Standard_Type.hxx>
 #include <TDataStd_AsciiString.hxx>
 #include <TDF_Attribute.hxx>
+#include <TDocStd_FormatVersion.hxx>
 #include <BinMDataStd.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_AsciiStringDriver,BinMDF_ADriver)
@@ -62,7 +63,7 @@ Standard_Boolean BinMDataStd_AsciiStringDriver::Paste
   Standard_Boolean ok = Source >> aString;
   if (ok)
     aStrAtt->Set( aString );
-  if(RelocTable.GetHeaderData()->StorageVersion().IntegerValue() > 8) { // process user defined guid
+  if(RelocTable.GetHeaderData()->StorageVersion().IntegerValue() >= TDocStd_FormatVersion_VERSION_9) { // process user defined guid
        const Standard_Integer& aPos = Source.Position();
        Standard_GUID aGuid;
        ok = Source >> aGuid;   
index 5572d807c81720e702b8ec5a7085d5c056249c0d..936ee8407d9e4f90ed82e90422518bd4f6663419 100644 (file)
@@ -23,6 +23,7 @@
 #include <TColStd_HArray1OfByte.hxx>
 #include <TDataStd_ByteArray.hxx>
 #include <TDF_Attribute.hxx>
+#include <TDocStd_FormatVersion.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_ByteArrayDriver,BinMDF_ADriver)
 
@@ -71,7 +72,7 @@ Standard_Boolean BinMDataStd_ByteArrayDriver::Paste(const BinObjMgt_Persistent&
   anAtt->ChangeArray(bytes);
 
   Standard_Boolean aDelta(Standard_False); 
-  if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() > 2) {
+  if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() >= TDocStd_FormatVersion_VERSION_3) {
     Standard_Byte aDeltaValue;
     if (! (theSource >> aDeltaValue))
       return Standard_False;
index 089e2cf1606534acf555342bc20322786108e418..4470dcc662b1cbd2560bf1849d23d80f98c00888 100644 (file)
@@ -23,6 +23,7 @@
 #include <TColStd_HArray1OfExtendedString.hxx>
 #include <TDataStd_ExtStringArray.hxx>
 #include <TDF_Attribute.hxx>
+#include <TDocStd_FormatVersion.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_ExtStringArrayDriver,BinMDF_ADriver)
 
@@ -81,7 +82,7 @@ Standard_Boolean BinMDataStd_ExtStringArrayDriver::Paste
 
   if(ok) {
     Standard_Boolean aDelta(Standard_False);
-    if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() > 2) {
+    if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() >= TDocStd_FormatVersion_VERSION_3) {
       Standard_Byte aDeltaValue;
       if (! (theSource >> aDeltaValue)) {
         return Standard_False;
index 84a0e397496b53131712fe8842e974bb286c6ded..9fcaa6c03d0d2abab74dc00036a09c3e885a44bf 100644 (file)
@@ -18,6 +18,7 @@
 #include <Standard_Type.hxx>
 #include <TDataStd_Name.hxx>
 #include <TDF_Attribute.hxx>
+#include <TDocStd_FormatVersion.hxx>
 #include <BinMDataStd.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_GenericExtStringDriver,BinMDF_ADriver)
@@ -67,7 +68,7 @@ Standard_Boolean BinMDataStd_GenericExtStringDriver::Paste
   Standard_Boolean ok = Source >> aStr;
   if (ok)
     aStrAttr->Set( aStr );
-  if(RelocTable.GetHeaderData()->StorageVersion().IntegerValue() > 8) { // process user defined guid
+  if(RelocTable.GetHeaderData()->StorageVersion().IntegerValue() >= TDocStd_FormatVersion_VERSION_9) { // process user defined guid
        const Standard_Integer& aPos = Source.Position();
        Standard_GUID aGuid;
        ok = Source >> aGuid;   
index 5d2dd63fef2c26632f53bd22e080da19414ded9a..3bade5243eef53780f7c87aaed4c4a964ea6d5cf 100644 (file)
@@ -28,6 +28,7 @@
 #include <TColStd_PackedMapOfInteger.hxx>
 #include <TDataStd_IntPackedMap.hxx>
 #include <TDF_Attribute.hxx>
+#include <TDocStd_FormatVersion.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_IntPackedMapDriver,BinMDF_ADriver)
 
@@ -87,7 +88,7 @@ Standard_Boolean BinMDataStd_IntPackedMapDriver::Paste
   }
 
   Standard_Boolean aDelta(Standard_False);
-  if(RelocTable.GetHeaderData()->StorageVersion().IntegerValue() > 2) {
+  if(RelocTable.GetHeaderData()->StorageVersion().IntegerValue() >= TDocStd_FormatVersion_VERSION_3) {
     Standard_Byte aDeltaValue;
     if (! (Source >> aDeltaValue))
       return Standard_False;
index d0663b17f3b8b749730853e80d5a6d6182b9c3ad..a25cb4e2150156773d85c68f6bdcc26fe94cc45c 100644 (file)
@@ -22,6 +22,7 @@
 #include <TColStd_HArray1OfInteger.hxx>
 #include <TDataStd_IntegerArray.hxx>
 #include <TDF_Attribute.hxx>
+#include <TDocStd_FormatVersion.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_IntegerArrayDriver,BinMDF_ADriver)
 
@@ -69,7 +70,7 @@ Standard_Boolean BinMDataStd_IntegerArrayDriver::Paste
   if(!theSource.GetIntArray (&aTargetArray(aFirstInd), aLength))
     return Standard_False;
   Standard_Boolean aDelta(Standard_False);
-  if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() > 2) {
+  if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() >= TDocStd_FormatVersion_VERSION_3) {
     Standard_Byte aDeltaValue;
     if (! (theSource >> aDeltaValue))
       return Standard_False;
index 5325bdfd8ffecd83def3e8b40b31190635262f99..89b6025be0bb2b8e2fafaa69e7c05e7898662f00 100644 (file)
@@ -20,6 +20,7 @@
 #include <Standard_Type.hxx>
 #include <TDataStd_Integer.hxx>
 #include <TDF_Attribute.hxx>
+#include <TDocStd_FormatVersion.hxx>
 #include <BinMDataStd.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_IntegerDriver,BinMDF_ADriver)
@@ -59,7 +60,7 @@ Standard_Boolean BinMDataStd_IntegerDriver::Paste
   Standard_Boolean ok = theSource >> aValue;
   if (ok)
     anAtt->Set(aValue);
-  if(theRT.GetHeaderData()->StorageVersion().IntegerValue() > 8) { // process user defined guid
+  if(theRT.GetHeaderData()->StorageVersion().IntegerValue() >= TDocStd_FormatVersion_VERSION_9) { // process user defined guid
        const Standard_Integer& aPos = theSource.Position();
        Standard_GUID aGuid;
        ok = theSource >> aGuid;        
index f6d41acba6ad749a59eaa1e64d6dcb854bbff3b4..69447573c5a21cc079d7c9f450a7b2659d7bbea2 100644 (file)
@@ -70,7 +70,7 @@ Standard_Boolean BinMDataStd_RealArrayDriver::Paste
     return Standard_False;
 
   Standard_Boolean aDelta(Standard_False);
-  if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() > 2) {
+  if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() >= TDocStd_FormatVersion_VERSION_3) {
     Standard_Byte aDeltaValue;
     if (! (theSource >> aDeltaValue))
       return Standard_False;
index 5c0111ef3ddae62218e9e23de41f06967705000a..10fe079d85e8db7ebde92f82e44c4953d77645ba 100644 (file)
@@ -20,6 +20,7 @@
 #include <Standard_Type.hxx>
 #include <TDataStd_Real.hxx>
 #include <TDF_Attribute.hxx>
+#include <TDocStd_FormatVersion.hxx>
 #include <BinMDataStd.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_RealDriver,BinMDF_ADriver)
@@ -59,7 +60,7 @@ Standard_Boolean BinMDataStd_RealDriver::Paste
   Standard_Boolean ok = theSource >> aValue;
   if (ok)
     anAtt->Set(aValue);
-  if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() > 8) { // process user defined guid
+  if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() >= TDocStd_FormatVersion_VERSION_9) { // process user defined guid
        const Standard_Integer& aPos = theSource.Position();
        Standard_GUID aGuid;
        ok = theSource >> aGuid;        
index 767c19d8ff06f265c95e1d7328e6130b451b659e..eeb1a35354dc4b1ca3b3208d4cbfa16dd299a1da 100644 (file)
@@ -34,7 +34,6 @@
 IMPLEMENT_STANDARD_RTTIEXT(BinMNaming_NamedShapeDriver,BinMDF_ADriver)
 
 #define SHAPESET "SHAPE_SECTION"
-#define FORMAT_NUMBER 3
 //=======================================================================
 static Standard_Character EvolutionToChar(const TNaming_Evolution theEvol)
 {
@@ -142,7 +141,9 @@ static int TranslateFrom  (const BinObjMgt_Persistent&  theSource,
 
 BinMNaming_NamedShapeDriver::BinMNaming_NamedShapeDriver
                         (const Handle(Message_Messenger)& theMsgDriver)
-     : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TNaming_NamedShape)->Name()), myShapeSet(Standard_False),myFormatNb(FORMAT_NUMBER)
+: BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TNaming_NamedShape)->Name()),
+  myShapeSet (Standard_False),
+  myFormatNb (BinTools_FormatVersion_VERSION_3)
 {
 }
 
index 5a45a1e0749b41a4dc184b4a99f019a1d8f90315..96c703898a9bf91010ce2fea62a0543e19eb9b03 100644 (file)
@@ -27,6 +27,7 @@
 #include <TColStd_Array1OfInteger.hxx>
 #include <TDF_Attribute.hxx>
 #include <TDF_Tool.hxx>
+#include <TDocStd_FormatVersion.hxx>
 #include <TNaming_Iterator.hxx>
 #include <TNaming_ListIteratorOfListOfNamedShape.hxx>
 #include <TNaming_NamedShape.hxx>
@@ -237,7 +238,7 @@ Standard_Boolean BinMNaming_NamingDriver::Paste
        myMessageDriver->Send (aMsg, Message_Warning);
          }
 
-    if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() > 3) {
+    if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() >= TDocStd_FormatVersion_VERSION_4) {
        TCollection_AsciiString entry;
        ok = theSource >> entry;
        if(ok) {
@@ -254,8 +255,8 @@ Standard_Boolean BinMNaming_NamingDriver::Paste
                aName.ContextLabel(tLab);
            }
        }
-    if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() > 4 && 
-       theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() < 7) {
+    if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() >= TDocStd_FormatVersion_VERSION_5 &&
+       theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() <= TDocStd_FormatVersion_VERSION_6) {
           // Orientation processing - converting from old format
       Handle(TNaming_NamedShape) aNShape;
       if(anAtt->Label().FindAttribute(TNaming_NamedShape::GetID(), aNShape)) {
@@ -274,7 +275,7 @@ Standard_Boolean BinMNaming_NamingDriver::Paste
                }
          }
        }
-    if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() > 6) {
+    if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() >= TDocStd_FormatVersion_VERSION_7) {
       ok = theSource >> anIndx;
       TopAbs_Orientation OrientationToApply(TopAbs_FORWARD);
       if(ok) {
index 43fa820dfe1a544c07f84f40a53b7d73b937722e..dfee78838a7fc3fa03e8bcb2a30e9010fb9ee04c 100644 (file)
@@ -93,7 +93,7 @@ Standard_Boolean BinMXCAFDoc_LocationDriver::Translate(const BinObjMgt_Persisten
   }
   
   Standard_Integer aFileVer = theMap.GetHeaderData()->StorageVersion().IntegerValue();
-  if( aFileVer > 5 && myLocations == 0 )
+  if( aFileVer >= TDocStd_FormatVersion_VERSION_6 && myLocations == 0 )
   {
     return Standard_False;
   }
@@ -101,7 +101,7 @@ Standard_Boolean BinMXCAFDoc_LocationDriver::Translate(const BinObjMgt_Persisten
   Standard_Integer aPower;
   Handle(TopLoc_Datum3D) aDatum;
   
-  if( aFileVer > 5 )
+  if( aFileVer >= TDocStd_FormatVersion_VERSION_6)
   {
     const TopLoc_Location& aLoc = myLocations->Location(anId);
     aPower = aLoc.FirstPower();
index 16237e5a870580c022fd60c542ef73eb1a5fd5ad..741be0e7acc596bfdd62406aead2f8637e7e25e8 100644 (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();
 }
index 07ad4655bbbb1c6dbbc85f5b2ae03da169cf4eed..efbf8239d11d16cb4f3f2d7ece6c32f8ef2a5349 100644 (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,
diff --git a/src/BinTools/BinTools_FormatVersion.hxx b/src/BinTools/BinTools_FormatVersion.hxx
new file mode 100644 (file)
index 0000000..6255f6c
--- /dev/null
@@ -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
index eaec192d4a74af55c26b0a9c82d098e796a35b3c..59303c7c780c3d2894775171fd965c06d8317ebe 100644 (file)
 
 #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,
index bbc171cfe0e57757ca178a6e92afe081d091d376..365d6146d72fd90a27a0531aad4f228df4889b7c 100644 (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;
index fd4a059d363b472239fe731971d08c4f1614a6ab..93f41e661fa05a83113fff9b3169f8cfebe4f21f 100644 (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
index ff00a8ab6bea926ba0de235b9a8ab144c5ab43df..4355685412a20ef804a3f2c0526b990783dec667 100644 (file)
@@ -14,7 +14,7 @@
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-
+#include <BinTools_ShapeSet.hxx>
 #include <BRep_TEdge.hxx>
 #include <BRepAdaptor_Surface.hxx>
 #include <BRepGProp.hxx>
@@ -33,6 +33,7 @@
 #include <GProp.hxx>
 #include <GProp_GProps.hxx>
 #include <NCollection_Vector.hxx>
+#include <OSD_OpenFile.hxx>
 #include <Poly_Triangulation.hxx>
 #include <Precision.hxx>
 #include <Standard.hxx>
@@ -1376,47 +1377,180 @@ static Standard_Integer XProgress (Draw_Interpretor& di, Standard_Integer argc,
 }
 
 //=======================================================================
-// binsave
+// writebrep
 //=======================================================================
-
-static Standard_Integer binsave(Draw_Interpretor& di, Standard_Integer n, const char** a)
+static Standard_Integer writebrep (Draw_Interpretor& theDI,
+                                   Standard_Integer theNbArgs,
+                                   const char** theArgVec)
 {
-  if (n <= 2) return 1;
+  Standard_Integer aVersion = -1;
+  TCollection_AsciiString aShapeName, aFileName;
+  TopoDS_Shape aShape;
+  bool isBinaryFormat = false, isWithTriangles = true;
+  if (!strcasecmp (theArgVec[0], "binsave"))
+  {
+    isBinaryFormat = true;
+  }
 
-  TopoDS_Shape aShape = DBRep::Get (a[1]);
-  if (aShape.IsNull())
+  for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
+  {
+    TCollection_AsciiString aParam (theArgVec[anArgIter]);
+    aParam.LowerCase();
+    if (aParam == "-binary")
+    {
+      isBinaryFormat = true;
+      if (anArgIter + 1 < theNbArgs
+       && Draw::ParseOnOff (theArgVec[anArgIter + 1], isBinaryFormat))
+      {
+        ++anArgIter;
+      }
+    }
+    else if (aParam == "-version"
+          && anArgIter + 1 < theNbArgs)
+    {
+      aVersion = Draw::Atoi (theArgVec[++anArgIter]);
+      if (aVersion <= 0)
+      {
+        theDI << "Syntax error: unknown version";
+        return 1;
+      }
+    }
+    else if (aParam == "-notriangles"
+          || aParam == "-triangles")
+    {
+      isWithTriangles = true;
+      if (anArgIter + 1 < theNbArgs
+       && Draw::ParseOnOff (theArgVec[anArgIter + 1], isWithTriangles))
+      {
+        ++anArgIter;
+      }
+      if (aParam == "-notriangles")
+      {
+        isWithTriangles = !isWithTriangles;
+      }
+    }
+    else if (aShapeName.IsEmpty())
+    {
+      aShapeName = theArgVec[anArgIter];
+      aShape = DBRep::Get (aShapeName);
+      if (aShape.IsNull())
+      {
+        theDI << "Syntax error: " << aShapeName << " is not a shape";
+        return 1;
+      }
+    }
+    else if (aFileName.IsEmpty())
+    {
+      aFileName = theArgVec[anArgIter];
+    }
+    else
+    {
+      theDI << "Syntax error: unknown argument '" << aParam << "'";
+      return 1;
+    }
+  }
+  if (aFileName.IsEmpty())
   {
-    di << a[1] << " is not a shape";
+    theDI << "Syntax error: wrong number of arguments";
     return 1;
   }
 
-  if (!BinTools::Write (aShape, a[2]))
+  Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI);
+  if (isBinaryFormat)
   {
-    di << "Cannot write to the file " << a[2];
-    return 1;
+    if (aVersion > BinTools_FormatVersion_CURRENT)
+    {
+      theDI << "Syntax error: unknown format version";
+      return 1;
+    }
+
+    BinTools_FormatVersion aBinToolsVersion = aVersion > 0
+                                            ? static_cast<BinTools_FormatVersion> (aVersion)
+                                            : BinTools_FormatVersion_CURRENT;
+    if (!BinTools::Write (aShape, aFileName.ToCString(), isWithTriangles, aBinToolsVersion, aProgress->Start()))
+    {
+      theDI << "Cannot write to the file " << aFileName;
+      return 1;
+    }
   }
+  else
+  {
+    if (aVersion > TopTools_FormatVersion_VERSION_2)
+    {
+      theDI << "Syntax error: unknown format version";
+      return 1;
+    }
 
-  di << a[1];
+    TopTools_FormatVersion aTopToolsVersion = aVersion > 0
+                                            ? static_cast<TopTools_FormatVersion> (aVersion)
+                                            : TopTools_FormatVersion_CURRENT;
+    if (!BRepTools::Write (aShape, aFileName.ToCString(), isWithTriangles, aTopToolsVersion, aProgress->Start()))
+    {
+      theDI << "Cannot write to the file " << aFileName;
+      return 1;
+    }
+  }
+  theDI << aShapeName;
   return 0;
 }
 
 //=======================================================================
-// binrestore
+// readbrep
 //=======================================================================
-
-static Standard_Integer binrestore(Draw_Interpretor& di, Standard_Integer n, const char** a)
+static Standard_Integer readbrep (Draw_Interpretor& theDI,
+                                  Standard_Integer theNbArgs,
+                                  const char** theArgVec)
 {
-  if (n <= 2) return 1;
+  if (theNbArgs != 3)
+  {
+    theDI << "Syntax error: wrong number of arguments";
+    return 1;
+  }
+
+  Standard_CString aFileName  = theArgVec[1];
+  Standard_CString aShapeName = theArgVec[2];
+  bool isBinaryFormat = true;
+  {
+    // probe file header to recognize format
+    std::ifstream aFile;
+    OSD_OpenStream (aFile, aFileName, std::ios::in | std::ios::binary);
+    if (!aFile.is_open())
+    {
+      theDI << "Error: cannot read the file '" << aFileName << "'";
+      return 1;
+    }
+
+    char aStringBuf[255] = {};
+    aFile.read (aStringBuf, 255);
+    if (aFile.fail())
+    {
+      theDI << "Error: cannot read the file '" << aFileName << "'";
+      return 1;
+    }
+    isBinaryFormat = !(::strncmp (aStringBuf, "DBRep_DrawableShape", 19) == 0);
+  }
 
+  Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI);
   TopoDS_Shape aShape;
-  if (!BinTools::Read (aShape, a[1]))
+  if (isBinaryFormat)
   {
-    di << "Cannot read from the file " << a[1];
-    return 1;
+    if (!BinTools::Read (aShape, aFileName, aProgress->Start()))
+    {
+      theDI << "Error: cannot read from the file '" << aFileName << "'";
+      return 1;
+    }
+  }
+  else
+  {
+    if (!BRepTools::Read (aShape, aFileName, BRep_Builder(), aProgress->Start()))
+    {
+      theDI << "Error: cannot read from the file '" << aFileName << "'";
+      return 1;
+    }
   }
 
-  DBRep::Set (a[2], aShape);
-  di << a[2];
+  DBRep::Set (aShapeName, aShape);
+  theDI << aShapeName;
   return 0;
 }
 
@@ -1517,13 +1651,23 @@ void  DBRep::BasicCommands(Draw_Interpretor& theCommands)
                     "\n\t\t   +|-c :  switch on/off output to cout of Progress Indicator"
                     "\n\t\t   +|-g :  switch on/off graphical mode of Progress Indicator",
                     XProgress,"DE: General");
-
-  theCommands.Add("binsave", "binsave shape filename\n"
-                  "\t\tsave the shape in the binary format file",
-                  __FILE__, binsave, g);
-  theCommands.Add("binrestore", "binrestore filename shape\n"
-                  "\t\trestore the shape from the binary format file",
-                  __FILE__, binrestore, g);
+  theCommands.Add("writebrep",
+                  "writebrep shape filename [-binary] [-version Version] [-noTriangles]"
+                  "\n\t\t: Save the shape in the ASCII (default) or binary format file."
+                  "\n\t\t:  -binary  write into the binary format (ASCII when unspecified)"
+                  "\n\t\t:  -version a number of format version to save;"
+                  "\n\t\t:           ASCII  versions: 1, 2       (1 for ASCII  when unspecified);"
+                  "\n\t\t:           Binary versions: 1, 2 and 3 (3 for Binary when unspecified)."
+                  "\n\t\t:  -noTriangles skip triangulation data (OFF when unspecified).",
+                  __FILE__, writebrep, g);
+  theCommands.Add("readbrep",
+                  "readbrep filename shape"
+                  "\n\t\t: Restore the shape from the binary or ASCII format file.",
+                  __FILE__, readbrep, g);
+  theCommands.Add("binsave", "binsave shape filename", __FILE__, writebrep, g);
+  theCommands.Add("binrestore",
+                  "alias to readbrep command",
+                  __FILE__, readbrep, g);
 
   theCommands.Add ("removeinternals", "removeinternals shape [force flag {0/1}]"
                    "\n\t\t             Removes sub-shapes with internal orientation from the shape.\n"
index ab3a54bcdd030ed09ac03f05dd2fa2c7eebe730f..771c358cab73d04718ebd5fa39a779def142d66e 100644 (file)
@@ -141,7 +141,12 @@ static Draw_SaveAndRestore numsr("Draw_Number",
 
 static Standard_Integer save(Draw_Interpretor& di, Standard_Integer n, const char** a)
 {
-  if (n <= 2) return 1;
+  if (n < 3)
+  {
+    di << "Syntax error: wrong number of arguments!\n";
+    di.PrintHelp(a[0]);
+    return 1;
+  }
 
   const char* name = a[2];
   std::ofstream os;
index 7f726976d6a2dccf817706a16bb3469ed8b97284..7ce511b8c6f8a6d9eb80e8c98238d5fe101e79f8 100644 (file)
@@ -111,7 +111,12 @@ public:
   Standard_EXPORT void SetNumberOfObjects (const Standard_Integer anObjectNumber);
   
   Standard_EXPORT void SetStorageVersion (const TCollection_AsciiString& aVersion);
-  
+
+  void SetStorageVersion (const Standard_Integer theVersion)
+  {
+    SetStorageVersion (TCollection_AsciiString (theVersion));
+  }
+
   Standard_EXPORT void SetCreationDate (const TCollection_AsciiString& aDate);
   
   Standard_EXPORT void SetSchemaVersion (const TCollection_AsciiString& aVersion);
index 9aa32c899b394a78154ea27d868101250abba10c..747e21c1fdde1658a75d850a191e43e23c63a936 100644 (file)
@@ -24,6 +24,7 @@ TopTools_DataMapOfShapeListOfShape.hxx
 TopTools_DataMapOfShapeReal.hxx
 TopTools_DataMapOfShapeSequenceOfShape.hxx
 TopTools_DataMapOfShapeShape.hxx
+TopTools_FormatVersion.hxx
 TopTools_HArray1OfListOfShape.hxx
 TopTools_HArray1OfShape.hxx
 TopTools_HArray2OfShape.hxx
diff --git a/src/TopTools/TopTools_FormatVersion.hxx b/src/TopTools/TopTools_FormatVersion.hxx
new file mode 100644 (file)
index 0000000..a852cfb
--- /dev/null
@@ -0,0 +1,26 @@
+// 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 _TopToolsFormatVersion_HeaderFile
+#define _TopToolsFormatVersion_HeaderFile
+
+//! Defined TopTools format version
+enum TopTools_FormatVersion
+{
+  TopTools_FormatVersion_VERSION_1 = 1, //!< Does not write CurveOnSurface UV Points into the file. On reading calls Check() method.
+  TopTools_FormatVersion_VERSION_2 = 2, //!< Stores CurveOnSurface UV Points. On reading format is recognized from Version string.
+
+  TopTools_FormatVersion_CURRENT = TopTools_FormatVersion_VERSION_1 //!< The current version.
+};
+
+#endif
index 8c1c99cfd90b2726799d7b25ba6aabe4df8d7ae9..b3a43594392b2c4c30bfd89b626ce0aa78e8f2f8 100644 (file)
 #include <TopoDS_Shape.hxx>
 #include <TopTools_LocationSet.hxx>
 #include <TopTools_ShapeSet.hxx>
+#include <Standard_Assert.hxx>
+
+#include <BRep_TFace.hxx>
 
 #include <locale.h>
 #include <string.h>
-static const char* Version  = "CASCADE Topology V1, (c) Matra-Datavision";
-static const char* Version2 = "CASCADE Topology V2, (c) Matra-Datavision";
+Standard_CString TopTools_ShapeSet::Version_1 = "CASCADE Topology V1, (c) Matra-Datavision";
+Standard_CString TopTools_ShapeSet::Version_2 = "CASCADE Topology V2, (c) Matra-Datavision";
 
 //=======================================================================
 //function : TopTools_ShapeSet
 //purpose  : 
 //=======================================================================
-
-TopTools_ShapeSet::TopTools_ShapeSet() : myFormatNb(1)
+TopTools_ShapeSet::TopTools_ShapeSet()
+: myFormatNb (TopTools_FormatVersion_VERSION_1)
 {
 }
 
@@ -52,6 +55,10 @@ TopTools_ShapeSet::~TopTools_ShapeSet()
 //=======================================================================
 void TopTools_ShapeSet::SetFormatNb(const Standard_Integer theFormatNb)
 {
+  Standard_ASSERT_RETURN(theFormatNb == TopTools_FormatVersion_VERSION_1 ||
+                         theFormatNb == TopTools_FormatVersion_VERSION_2,
+    "Error: unsupported TopTools version.", );
+
   myFormatNb = theFormatNb;
 }
 
@@ -451,10 +458,14 @@ void  TopTools_ShapeSet::Write(Standard_OStream& OS, const Message_ProgressRange
   std::streamsize prec = OS.precision(15);
 
   // write the copyright
-  if (myFormatNb == 2)
-    OS << "\n" << Version2 << "\n";
+  if (myFormatNb == TopTools_FormatVersion_VERSION_2)
+  {
+    OS << "\n" << Version_2 << "\n";
+  }
   else
-    OS << "\n" << Version << "\n";
+  {
+    OS << "\n" << Version_1 << "\n";
+  }
 
   //-----------------------------------------
   // write the locations
@@ -606,14 +617,22 @@ void  TopTools_ShapeSet::Read(Standard_IStream& IS, const Message_ProgressRange&
         vers[lv] = '\0';
     }
     
-  } while ( ! IS.fail() && strcmp(vers,Version) && strcmp(vers,Version2) );
+  } while (!IS.fail()
+        && strcmp(vers, Version_1)
+        && strcmp(vers, Version_2));
   if (IS.fail()) {
     std::cout << "File was not written with this version of the topology"<<std::endl;
     IS.imbue (anOldLocale);
     return;
   }
-  if (strcmp(vers,Version2) == 0) SetFormatNb(2);
-  else SetFormatNb(1);
+  else if (strcmp(vers, Version_2) == 0)
+  {
+    SetFormatNb(TopTools_FormatVersion_VERSION_2);
+  }
+  else
+  {
+    SetFormatNb(TopTools_FormatVersion_VERSION_1);
+  }
 
   //-----------------------------------------
   // read the locations
@@ -681,7 +700,7 @@ void  TopTools_ShapeSet::Read(Standard_IStream& IS, const Message_ProgressRange&
     S.Free      (buffer[0] == '1');
     S.Modified  (buffer[1] == '1');
 
-    if (myFormatNb == 2)
+    if (myFormatNb >= TopTools_FormatVersion_VERSION_2)
       S.Checked   (buffer[2] == '1');
     else
       S.Checked   (Standard_False);     // force check at reading.. 
@@ -693,7 +712,7 @@ void  TopTools_ShapeSet::Read(Standard_IStream& IS, const Message_ProgressRange&
 
     // check
 
-    if (myFormatNb == 1)
+    if (myFormatNb == TopTools_FormatVersion_VERSION_1)
       Check(T,S);
 
     myShapes.Add(S);
index e47fe074a19f069c0f591b8210ccc98439bed5cb..d62fe822b04589c6c5f115fd4c1fc1777e8bcf18 100644 (file)
@@ -27,6 +27,7 @@
 #include <Standard_OStream.hxx>
 #include <Standard_IStream.hxx>
 #include <TopAbs_ShapeEnum.hxx>
+#include <TopTools_FormatVersion.hxx>
 
 class TopoDS_Shape;
 class TopTools_LocationSet;
@@ -50,13 +51,10 @@ public:
   
   Standard_EXPORT virtual ~TopTools_ShapeSet();
   
+  //! Sets the TopTools_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 TopTools_FormatVersion
   Standard_EXPORT Standard_Integer FormatNb() const;
   
   //! Clears the content of the set.  This method can be
@@ -181,6 +179,11 @@ public:
   //! Returns number of shapes read from file.
   Standard_EXPORT Standard_Integer NbShapes() const;
 
+public:
+
+  static Standard_CString Version_1;
+  static Standard_CString Version_2;
+
 private:
 
   //! Reads  from <IS>  a shape  and  returns  it in  S.
index fa8784f69b8bfa925b8050b2f9ea5029d15590bf..febbef1242ec8610a9234f456e335eff909b4ed6 100644 (file)
@@ -252,22 +252,31 @@ void XmlLDrivers_DocumentRetrievalDriver::ReadFromDomDocument
     theApplication -> MessageDriver();
   // 1. Read info // to be done
   TCollection_AsciiString anAbsoluteDirectory = GetDirFromFile(myFileName);
-  Standard_Integer aCurDocVersion = 0;
+  Standard_Integer aCurDocVersion = TDocStd_FormatVersion_VERSION_2; // minimum supported version
   TCollection_ExtendedString anInfo;
   const XmlObjMgt_Element anInfoElem =
     theElement.GetChildByTagName ("info");
   if (anInfoElem != NULL) {
     XmlObjMgt_DOMString aDocVerStr = anInfoElem.getAttribute("DocVersion");
-    if(aDocVerStr == NULL)
-      aCurDocVersion = 2;
-    else if (!aDocVerStr.GetInteger(aCurDocVersion)) {
-      TCollection_ExtendedString aMsg =
-        TCollection_ExtendedString ("Cannot retrieve the current Document version"
-                                    " attribute as \"") + aDocVerStr + "\"";
-      if(!aMsgDriver.IsNull()) 
-        aMsgDriver->Send(aMsg.ToExtString(), Message_Fail);
+    if (aDocVerStr != NULL)
+    {
+      Standard_Integer anIntegerVersion = 0;
+      if (aDocVerStr.GetInteger (anIntegerVersion))
+      {
+        aCurDocVersion = anIntegerVersion;
+      }
+      else
+      {
+        TCollection_ExtendedString aMsg =
+          TCollection_ExtendedString ("Cannot retrieve the current Document version"
+                                      " attribute as \"") + aDocVerStr + "\"";
+        if (!aMsgDriver.IsNull())
+        {
+          aMsgDriver->Send(aMsg.ToExtString(), Message_Fail);
+        }
+      }
     }
-    
+
     // oan: OCC22305 - check a document verison and if it's greater than
     // current version of storage driver set an error status and return
     if( aCurDocVersion > TDocStd_Document::CurrentStorageFormatVersion() )
@@ -282,7 +291,6 @@ void XmlLDrivers_DocumentRetrievalDriver::ReadFromDomDocument
       return;
     }
 
-    if( aCurDocVersion < 2) aCurDocVersion = 2;
     Standard_Boolean isRef = Standard_False;
     for (LDOM_Node aNode = anInfoElem.getFirstChild();
          aNode != NULL; aNode = aNode.getNextSibling()) {
index 955f24cf638a788a66bcbe67fc9c4ed19573f4be..869747e968214cb14432999d4519c841e269a358 100644 (file)
@@ -274,11 +274,14 @@ Standard_Boolean XmlLDrivers_DocumentStorageDriver::WriteToDomDocument
   if (TDocStd_Document::CurrentStorageFormatVersion() < aDoc->StorageFormatVersion())
   {
     TCollection_ExtendedString anErrorString("Unacceptable storage format version, the last verson is used");
-    aMessageDriver->Send (anErrorString.ToExtString(), Message_Warning);     
+    aMessageDriver->Send (anErrorString.ToExtString(), Message_Warning);
   }
-  else            
+  else
+  {
     aFormatVersion = aDoc->StorageFormatVersion();
-  anInfoElem.setAttribute ("DocVersion", aFormatVersion);
+  }
+  const TCollection_AsciiString aStringFormatVersion (aFormatVersion);
+  anInfoElem.setAttribute ("DocVersion", aStringFormatVersion.ToCString());
  
   // User info with Copyright
   TColStd_SequenceOfAsciiString aUserInfo;
index 33711f40f18b2d1c50b33e8a0bc4012ea4052fa2..5354c9d579bbff0fea5932c5eda1abba07c92dc3 100644 (file)
@@ -25,6 +25,7 @@
 #include <TDF_Label.hxx>
 #include <TDF_TagSource.hxx>
 #include <TDF_Tool.hxx>
+#include <TDocStd_FormatVersion.hxx>
 #include <XmlMDF.hxx>
 #include <XmlMDF_ADriver.hxx>
 #include <XmlMDF_ADriverTable.hxx>
@@ -107,7 +108,7 @@ Standard_Integer XmlMDF::WriteSubTree
       // was replaced by TDataXtd_Presentation. Therefore, for old versions
       // we write old name of the attribute (TPrsStd_AISPresentation).
       Standard_CString typeName = aDriver->TypeName().ToCString();
-      if (theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() < 8 &&
+      if (theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() < TDocStd_FormatVersion_VERSION_8 &&
           strcmp(typeName, "TDataXtd_Presentation") == 0)
       {
         typeName = "TPrsStd_AISPresentation";
index 17fe955c2a1be3688bbfe1283fd36396e86b0eb2..9e19cacf8ab939ba13a8320ceb13c810e20953cc 100644 (file)
 #include <TColStd_HArray1OfByte.hxx>
 #include <TDataStd_ByteArray.hxx>
 #include <TDF_Attribute.hxx>
+#include <TDocStd_FormatVersion.hxx>
 #include <XmlMDataStd.hxx>
 #include <XmlMDataStd_ByteArrayDriver.hxx>
 #include <XmlObjMgt.hxx>
 #include <XmlObjMgt_Persistent.hxx>
+
 IMPLEMENT_DOMSTRING (AttributeIDString, "bytearrattguid")
 
 IMPLEMENT_STANDARD_RTTIEXT(XmlMDataStd_ByteArrayDriver,XmlMDF_ADriver)
@@ -129,7 +131,7 @@ Standard_Boolean XmlMDataStd_ByteArrayDriver::Paste(const XmlObjMgt_Persistent&
   
   Standard_Boolean aDelta(Standard_False);
   
-  if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() > 2) {
+  if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() >= TDocStd_FormatVersion_VERSION_3) {
     Standard_Integer aDeltaValue;
     if (!anElement.getAttribute(::IsDeltaOn()).GetInteger(aDeltaValue)) 
     {
index f60b5c30d6359b20b736249c397f0c1612c3ece1..3b7012b463757527afd3975bb6159156c937ed92 100644 (file)
@@ -19,6 +19,7 @@
 #include <Standard_Type.hxx>
 #include <TDataStd_ExtStringArray.hxx>
 #include <TDF_Attribute.hxx>
+#include <TDocStd_FormatVersion.hxx>
 #include <XmlMDataStd.hxx>
 #include <XmlMDataStd_ExtStringArrayDriver.hxx>
 #include <XmlObjMgt.hxx>
@@ -195,7 +196,7 @@ Standard_Boolean XmlMDataStd_ExtStringArrayDriver::Paste
   // Read delta-flag.
   Standard_Boolean aDelta(Standard_False);
   
-  if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() > 2) {
+  if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() >= TDocStd_FormatVersion_VERSION_3) {
     Standard_Integer aDeltaValue;
     if (!anElement.getAttribute(::IsDeltaOn()).GetInteger(aDeltaValue)) 
       {
@@ -240,7 +241,7 @@ void XmlMDataStd_ExtStringArrayDriver::Paste (const Handle(TDF_Attribute)& theSo
   // So, if the user wants to save the document under the 7th or earlier versions,
   // don't apply this improvement.
   Standard_Character c = '-';
-  if (theRelocTable.GetHeaderData()->StorageVersion().IntegerValue()  > 7)
+  if (theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() >= TDocStd_FormatVersion_VERSION_8)
   {
     // Preferrable symbols for the separator: - _ . : ^ ~
     // Don't use a space as a separator: XML low-level parser sometimes "eats" it.
index 576e4bbef384c1fe6380de6be4495752c217a4d5..9e3e2245ecad3071bc834802c59b8f66f082f443 100644 (file)
@@ -22,6 +22,7 @@
 #include <TColStd_PackedMapOfInteger.hxx>
 #include <TDataStd_IntPackedMap.hxx>
 #include <TDF_Attribute.hxx>
+#include <TDocStd_FormatVersion.hxx>
 #include <XmlMDataStd.hxx>
 #include <XmlMDataStd_IntPackedMapDriver.hxx>
 #include <XmlMDF_ADriver.hxx>
@@ -106,7 +107,7 @@ Standard_Boolean XmlMDataStd_IntPackedMapDriver::Paste
     if(Ok) {
       Standard_Boolean aDelta(Standard_False);
 
-      if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() > 2) {
+      if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() >= TDocStd_FormatVersion_VERSION_3) {
         Standard_Integer aDeltaValue;
         if (!anElement.getAttribute(::IsDeltaOn()).GetInteger(aDeltaValue)) 
         {
index a82d818092dc8362629a20f4780ab63a73c95f9e..30b8c377b2c5841c6d4f83b9ef2134521b48e2b7 100644 (file)
@@ -20,6 +20,7 @@
 #include <Standard_Type.hxx>
 #include <TDataStd_IntegerArray.hxx>
 #include <TDF_Attribute.hxx>
+#include <TDocStd_FormatVersion.hxx>
 #include <XmlMDataStd.hxx>
 #include <XmlMDataStd_IntegerArrayDriver.hxx>
 #include <XmlObjMgt.hxx>
@@ -129,7 +130,7 @@ Standard_Boolean XmlMDataStd_IntegerArrayDriver::Paste
   }
   Standard_Boolean aDelta(Standard_False);
   
-  if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() > 2) {
+  if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() >= TDocStd_FormatVersion_VERSION_3) {
     Standard_Integer aDeltaValue;
     if (!anElement.getAttribute(::IsDeltaOn()).GetInteger(aDeltaValue)) 
       {
index ddc296ad5d5deb3f39399c1601fb0d2bd5a1bc46..182332cdfa0ddafc6babd6128c424a244894069c 100644 (file)
@@ -23,6 +23,7 @@
 #include <TColStd_HArray1OfReal.hxx>
 #include <TDataStd_RealArray.hxx>
 #include <TDF_Attribute.hxx>
+#include <TDocStd_FormatVersion.hxx>
 #include <XmlMDataStd.hxx>
 #include <XmlMDataStd_RealArrayDriver.hxx>
 #include <XmlObjMgt.hxx>
@@ -140,7 +141,7 @@ Standard_Boolean XmlMDataStd_RealArrayDriver::Paste
   }
   Standard_Boolean aDelta(Standard_False);
   
-  if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() > 2) {
+  if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() >= TDocStd_FormatVersion_VERSION_3) {
     Standard_Integer aDeltaValue;
     if (!anElement.getAttribute(::IsDeltaOn()).GetInteger(aDeltaValue)) 
       {
index c5004b505769f0c736a665eb39a941725b750789..1d7a3fcded3ef5881db725059cab2a2584f2e2eb 100644 (file)
@@ -19,6 +19,7 @@
 #include <Standard_Type.hxx>
 #include <TDataStd_TreeNode.hxx>
 #include <TDF_Attribute.hxx>
+#include <TDocStd_FormatVersion.hxx>
 #include <XmlMDataStd_TreeNodeDriver.hxx>
 #include <XmlObjMgt.hxx>
 #include <XmlObjMgt_Persistent.hxx>
@@ -118,7 +119,7 @@ void XmlMDataStd_TreeNodeDriver::Paste
   // tree id
   // A not default ID is skipped for storage version 8 and newer.
   if (aS->ID() != TDataStd_TreeNode::GetDefaultTreeID() ||
-      theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() < 8)
+      theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() < TDocStd_FormatVersion_VERSION_8)
   {
     Standard_Character aGuidStr [40];
     Standard_PCharacter pGuidStr=aGuidStr;
index 813bf7b087d93b9ffc307cab56eeca0de84d1378..a3c04f7eafe6c32ccb57ffaedb9b46d8f541c242 100644 (file)
@@ -370,7 +370,7 @@ void XmlMNaming_NamedShapeDriver::WriteShapeSection (XmlObjMgt_Element& theEleme
 
   //  Add text to the "shapes" element
   if (myShapeSet.NbShapes() > 0) {
-    myShapeSet.SetFormatNb(2);
+    myShapeSet.SetFormatNb(TopTools_FormatVersion_VERSION_2);
     LDOM_OSStream aStream (16 * 1024);
 //    ostrstream aStream;
 //    aStream.rdbuf() -> setbuf (0, 16380);
index d89c1111a3071a7c856c6b39241e9207e08f668c..efd28ad13b17b2bdd3ee0b02ce97fdf857d831a3 100644 (file)
@@ -18,6 +18,7 @@
 #include <Standard_Type.hxx>
 #include <TDF_Attribute.hxx>
 #include <TDF_Tool.hxx>
+#include <TDocStd_FormatVersion.hxx>
 #include <TNaming_Iterator.hxx>
 #include <TNaming_ListIteratorOfListOfNamedShape.hxx>
 #include <TNaming_Name.hxx>
@@ -174,7 +175,7 @@ Standard_Boolean XmlMNaming_NamingDriver::Paste
   }
   aNgName.Index(aNb);
 //
-  if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() > 3) {
+  if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() >= TDocStd_FormatVersion_VERSION_4) {
     XmlObjMgt_DOMString aDomEntry = anElem.getAttribute(::ContextLabelString());
     if (aDomEntry != NULL)
     {  
@@ -203,8 +204,8 @@ Standard_Boolean XmlMNaming_NamingDriver::Paste
       std::cout << "Retrieving Context Label is NULL" <<std::endl;
 #endif
 
-    if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() > 4 && 
-      theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() < 7) {
+    if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() >= TDocStd_FormatVersion_VERSION_5 &&
+      theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() < TDocStd_FormatVersion_VERSION_7) {
           // Orientation processing - converting from old format
           Handle(TNaming_NamedShape) aNS;
           if (aNg->Label().FindAttribute(TNaming_NamedShape::GetID(), aNS)) {
@@ -223,7 +224,7 @@ Standard_Boolean XmlMNaming_NamingDriver::Paste
             }
           }         
         }
-    if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() > 6) {
+    if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() >= TDocStd_FormatVersion_VERSION_7) {
        aDOMStr = anElem.getAttribute(::OrientString());
        if (!aDOMStr.GetInteger(aNb))
        {
index 7918e454a5b70a2bd0a3dd05b3601e18d9bd3ed9..063e982d829206f63225367214aa6fb4d698aef8 100644 (file)
@@ -17,6 +17,7 @@
 #include <Message_Messenger.hxx>
 #include <Standard_Type.hxx>
 #include <TDF_Attribute.hxx>
+#include <TDocStd_FormatVersion.hxx>
 #include <TopLoc_Datum3D.hxx>
 #include <TopLoc_Location.hxx>
 #include <TopTools_LocationSet.hxx>
@@ -149,7 +150,7 @@ Standard_Boolean XmlMXCAFDoc_LocationDriver::Translate
     return Standard_False;
   
   Standard_Integer aFileVer = theMap.GetHeaderData()->StorageVersion().IntegerValue();
-  if( aFileVer > 5 && myLocations == 0 )
+  if( aFileVer >= TDocStd_FormatVersion_VERSION_6 && myLocations == 0 )
   {
     return Standard_False;
   }
@@ -157,7 +158,7 @@ Standard_Boolean XmlMXCAFDoc_LocationDriver::Translate
   Standard_Integer aPower;
   Handle(TopLoc_Datum3D) aDatum;
   
-  if( aFileVer > 5 )
+  if( aFileVer >= TDocStd_FormatVersion_VERSION_6)
   {
     //  Get Location ID
     Standard_Integer anId;
diff --git a/tests/bugs/moddata_3/bug31946 b/tests/bugs/moddata_3/bug31946
new file mode 100644 (file)
index 0000000..5803e5e
--- /dev/null
@@ -0,0 +1,49 @@
+puts "=========="
+puts "0031946: Modeling Data - replace version numbers with enumerations in TopTools and BinTools"
+puts "=========="
+puts ""
+
+pload MODELING VISUALIZATION
+
+box testBox 10 20 30
+incmesh testBox 0.1
+
+writebrep testBox "${imagedir}/${casename}_topBox1.brep"
+readbrep "${imagedir}/${casename}_topBox1.brep" topBox1
+trinfo topBox1
+checktrinfo topBox1 -tri 12
+
+writebrep testBox "${imagedir}/${casename}_topBox2.brep" -noTriangles
+readbrep "${imagedir}/${casename}_topBox2.brep" topBox2
+trinfo topBox2
+checktrinfo topBox2 -tri 0
+
+writebrep testBox "${imagedir}/${casename}_topBox3.brep" -noTriangles on -binary off
+readbrep "${imagedir}/${casename}_topBox3.brep" topBox3
+trinfo topBox3
+checktrinfo topBox3 -tri 0
+
+writebrep testBox "${imagedir}/${casename}_topBox4.brep" -noTriangles off -binary off
+readbrep "${imagedir}/${casename}_topBox4.brep" topBox4
+trinfo topBox4
+checktrinfo topBox4 -tri 12
+
+writebrep testBox "${imagedir}/${casename}_binBox1.bbrep" -binary on
+readbrep "${imagedir}/${casename}_binBox1.bbrep" binBox1
+trinfo binBox1
+checktrinfo binBox1 -tri 12
+
+writebrep testBox "${imagedir}/${casename}_binBox2.bbrep" -noTriangles -binary on
+readbrep "${imagedir}/${casename}_binBox2.bbrep" binBox2
+trinfo binBox2
+checktrinfo binBox2 -tri 0
+
+writebrep testBox "${imagedir}/${casename}_binBox3.bbrep" -noTriangles on -binary on
+readbrep "${imagedir}/${casename}_binBox3.bbrep" binBox3
+trinfo binBox3
+checktrinfo binBox3 -tri 0
+
+writebrep testBox "${imagedir}/${casename}_binBox4.bbrep" -noTriangles off -binary on
+readbrep "${imagedir}/${casename}_binBox4.bbrep" binBox4
+trinfo binBox4
+checktrinfo binBox4 -tri 12