1 // Copyright (c) 2021 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #ifndef _BinTools_ShapeSetBase_HeaderFile
15 #define _BinTools_ShapeSetBase_HeaderFile
17 #include <Standard.hxx>
18 #include <Standard_DefineAlloc.hxx>
19 #include <Standard_Handle.hxx>
21 #include <Standard_OStream.hxx>
22 #include <Standard_IStream.hxx>
23 #include <Message_ProgressRange.hxx>
24 #include <BinTools_FormatVersion.hxx>
29 //! Writes to the stream a gp_Pnt data
30 Standard_OStream& operator << (Standard_OStream& OS, const gp_Pnt P);
32 //! Computes a hash code for the given value of the uint64_t type, in range [1, theUpperBound]
33 inline Standard_Integer HashCode (const uint64_t theValue, const Standard_Integer theUpperBound)
35 return IntegerHashCode(theValue, 0xffffffffffffffff, theUpperBound);
38 //! A base class for all readers/writers of TopoDS_Shape into/from stream.
39 class BinTools_ShapeSetBase
46 //! A default constructor.
47 Standard_EXPORT BinTools_ShapeSetBase();
49 Standard_EXPORT virtual ~BinTools_ShapeSetBase();
51 //! Return true if shape should be stored with triangles.
52 Standard_Boolean IsWithTriangles() const { return myWithTriangles; }
53 //! Return true if shape should be stored triangulation with normals.
54 Standard_Boolean IsWithNormals() const { return myWithNormals; }
56 //! Define if shape will be stored with triangles.
57 //! Ignored (always written) if face defines only triangulation (no surface).
58 void SetWithTriangles (const Standard_Boolean theWithTriangles) { myWithTriangles = theWithTriangles; }
59 //! Define if shape will be stored triangulation with normals.
60 //! Ignored (always written) if face defines only triangulation (no surface).
61 void SetWithNormals(const Standard_Boolean theWithNormals) { myWithNormals = theWithNormals; }
63 //! Sets the BinTools_FormatVersion.
64 Standard_EXPORT void SetFormatNb (const Standard_Integer theFormatNb);
66 //! Returns the BinTools_FormatVersion.
67 Standard_EXPORT Standard_Integer FormatNb() const { return myFormatNb; }
69 //! Clears the content of the set.
70 Standard_EXPORT virtual void Clear() {}
72 //! Writes the content of me on the stream <OS> in binary
73 //! format that can be read back by Read.
75 //! Writes the locations.
77 //! Writes the geometry calling WriteGeometry.
79 //! Dumps the shapes from last to first.
82 //! calls WriteGeometry(S).
83 //! Write the flags, the subshapes.
84 Standard_EXPORT virtual void Write
85 (Standard_OStream& /*OS*/, const Message_ProgressRange& /*theRange*/ = Message_ProgressRange()) {}
87 //! Reads the content of me from the binary stream <IS>. me
90 //! Reads the locations.
92 //! Reads the geometry calling ReadGeometry.
97 //! calls ReadGeometry(T,S).
98 //! Reads the flag, the subshapes.
99 Standard_EXPORT virtual void Read
100 (Standard_IStream& /*IS*/, const Message_ProgressRange& /*theRange*/ = Message_ProgressRange()) {}
102 //! Writes on <OS> the shape <S>. Writes the
103 //! orientation, the index of the TShape and the index
105 Standard_EXPORT virtual void Write (const TopoDS_Shape& /*theShape*/, Standard_OStream& /*theStream*/) {}
107 //! An empty virtual method for redefinition in shape-reader.
108 Standard_EXPORT virtual void Read (Standard_IStream& /*theStream*/, TopoDS_Shape& /*theShape*/) {}
110 static const Standard_CString THE_ASCII_VERSIONS[BinTools_FormatVersion_UPPER + 1];
113 Standard_Integer myFormatNb;
114 Standard_Boolean myWithTriangles;
115 Standard_Boolean myWithNormals;
118 #endif // _BinTools_ShapeSet_HeaderFile