0031918: Application Framework - New binary format for fast reading part of OCAF...
[occt.git] / src / BinTools / BinTools_ShapeSetBase.hxx
1 // Copyright (c) 2021 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #ifndef _BinTools_ShapeSetBase_HeaderFile
15 #define _BinTools_ShapeSetBase_HeaderFile
16
17 #include <Standard.hxx>
18 #include <Standard_DefineAlloc.hxx>
19 #include <Standard_Handle.hxx>
20
21 #include <Standard_OStream.hxx>
22 #include <Standard_IStream.hxx>
23 #include <Message_ProgressRange.hxx>
24 #include <BinTools_FormatVersion.hxx>
25
26 class TopoDS_Shape;
27 class gp_Pnt;
28
29 //! Writes to the stream a gp_Pnt data
30 Standard_OStream& operator << (Standard_OStream& OS, const gp_Pnt P);
31
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)
34 {
35   return IntegerHashCode(theValue, 0xffffffffffffffff, theUpperBound);
36 }
37
38 //! A base class for all readers/writers of TopoDS_Shape into/from stream.
39 class BinTools_ShapeSetBase
40 {
41 public:
42
43   DEFINE_STANDARD_ALLOC
44
45   
46   //! A default constructor.
47   Standard_EXPORT BinTools_ShapeSetBase();
48   
49   Standard_EXPORT virtual ~BinTools_ShapeSetBase();
50
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; }
55
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; }
62
63   //! Sets the BinTools_FormatVersion.
64   Standard_EXPORT void SetFormatNb (const Standard_Integer theFormatNb);
65
66   //! Returns the BinTools_FormatVersion.
67   Standard_EXPORT Standard_Integer FormatNb() const { return myFormatNb; }
68   
69   //! Clears the content of the set.
70   Standard_EXPORT virtual void Clear() {}
71   
72   //! Writes the content of  me  on the stream <OS> in binary
73   //! format that can be read back by Read.
74   //!
75   //! Writes the locations.
76   //!
77   //! Writes the geometry calling WriteGeometry.
78   //!
79   //! Dumps the shapes from last to first.
80   //! For each shape  :
81   //! Write the type.
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()) {}
86   
87   //! Reads the content of me from the binary stream  <IS>. me
88   //! is first cleared.
89   //!
90   //! Reads the locations.
91   //!
92   //! Reads the geometry calling ReadGeometry.
93   //!
94   //! Reads the shapes.
95   //! For each shape
96   //! Reads the type.
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()) {}
101   
102   //! Writes   on  <OS>   the shape   <S>.    Writes the
103   //! orientation, the index of the TShape and the index
104   //! of the Location.
105   Standard_EXPORT virtual void Write (const TopoDS_Shape& /*theShape*/, Standard_OStream& /*theStream*/) {}
106   
107   //! An empty virtual method for redefinition in shape-reader.
108   Standard_EXPORT virtual void Read (Standard_IStream& /*theStream*/, TopoDS_Shape& /*theShape*/) {}
109                                                                                     
110   static const Standard_CString THE_ASCII_VERSIONS[BinTools_FormatVersion_UPPER + 1];
111 private:
112
113   Standard_Integer myFormatNb;
114   Standard_Boolean myWithTriangles;
115   Standard_Boolean myWithNormals;
116 };
117
118 #endif // _BinTools_ShapeSet_HeaderFile