365d6146d72fd90a27a0531aad4f228df4889b7c
[occt.git] / src / BinTools / BinTools_ShapeSet.hxx
1 // Created on: 2004-05-11
2 // Created by: Sergey ZARITCHNY <szy@opencascade.com>
3 // Copyright (c) 2004-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _BinTools_ShapeSet_HeaderFile
17 #define _BinTools_ShapeSet_HeaderFile
18
19 #include <Standard.hxx>
20 #include <Standard_DefineAlloc.hxx>
21 #include <Standard_Handle.hxx>
22
23 #include <TopTools_IndexedMapOfShape.hxx>
24 #include <BinTools_FormatVersion.hxx>
25 #include <BinTools_LocationSet.hxx>
26 #include <Standard_Integer.hxx>
27 #include <BRep_Builder.hxx>
28 #include <BinTools_SurfaceSet.hxx>
29 #include <BinTools_CurveSet.hxx>
30 #include <BinTools_Curve2dSet.hxx>
31 #include <TColStd_IndexedMapOfTransient.hxx>
32 #include <Standard_Boolean.hxx>
33 #include <Standard_OStream.hxx>
34 #include <Standard_IStream.hxx>
35 #include <TopAbs_ShapeEnum.hxx>
36
37 class TopoDS_Shape;
38 class BinTools_LocationSet;
39
40
41 //! Writes topology in OStream in binary format
42 class BinTools_ShapeSet 
43 {
44 public:
45
46   DEFINE_STANDARD_ALLOC
47
48   //! Builds an empty ShapeSet.
49   //! @param theWithTriangles [in] flag to write triangulation data
50   Standard_EXPORT BinTools_ShapeSet (const Standard_Boolean theWithTriangles = Standard_False);
51
52   Standard_EXPORT virtual ~BinTools_ShapeSet();
53
54   //! Return true if shape should be stored with triangles.
55   Standard_Boolean IsWithTriangles() const { return myWithTriangles; }
56
57   //! Define if shape will be stored with triangles.
58   //! Ignored (always written) if face defines only triangulation (no surface).
59   void SetWithTriangles (const Standard_Boolean theWithTriangles) { myWithTriangles = theWithTriangles; }
60
61   //! Sets the BinTools_FormatVersion.
62   Standard_EXPORT void SetFormatNb (const Standard_Integer theFormatNb);
63
64   //! Returns the BinTools_FormatVersion.
65   Standard_EXPORT Standard_Integer FormatNb() const;
66   
67   //! Clears the content of the set.
68   Standard_EXPORT virtual void Clear();
69   
70   //! Stores <S> and its sub-shape. Returns the index of <S>.
71   //! The method AddGeometry is called on each sub-shape.
72   Standard_EXPORT Standard_Integer Add (const TopoDS_Shape& S);
73   
74   //! Returns the sub-shape of index <I>.
75   Standard_EXPORT const TopoDS_Shape& Shape (const Standard_Integer I) const;
76   
77   //! Returns the index of <S>.
78   Standard_EXPORT Standard_Integer Index (const TopoDS_Shape& S) const;
79   
80   Standard_EXPORT const BinTools_LocationSet& Locations() const;
81   
82   Standard_EXPORT BinTools_LocationSet& ChangeLocations();
83   
84   //! Returns number of shapes read from file.
85   Standard_EXPORT Standard_Integer NbShapes() const;
86   
87   //! Writes the content of  me  on the stream <OS> in binary
88   //! format that can be read back by Read.
89   //!
90   //! Writes the locations.
91   //!
92   //! Writes the geometry calling WriteGeometry.
93   //!
94   //! Dumps the shapes from last to first.
95   //! For each shape  :
96   //! Write the type.
97   //! calls WriteGeometry(S).
98   //! Write the flags, the subshapes.
99   Standard_EXPORT virtual void Write
100     (Standard_OStream& OS,
101      const Message_ProgressRange& theRange = Message_ProgressRange()) const;
102   
103   //! Reads the content of me from the binary stream  <IS>. me
104   //! is first cleared.
105   //!
106   //! Reads the locations.
107   //!
108   //! Reads the geometry calling ReadGeometry.
109   //!
110   //! Reads the shapes.
111   //! For each shape
112   //! Reads the type.
113   //! calls ReadGeometry(T,S).
114   //! Reads the flag, the subshapes.
115   Standard_EXPORT virtual void Read
116     (Standard_IStream& IS,
117         const Message_ProgressRange& theRange = Message_ProgressRange());
118   
119   //! Writes   on  <OS>   the shape   <S>.    Writes the
120   //! orientation, the index of the TShape and the index
121   //! of the Location.
122   Standard_EXPORT virtual void Write (const TopoDS_Shape& S, Standard_OStream& OS) const;
123   
124   //! Writes the geometry of  me  on the stream <OS> in a
125   //! binary format that can be read back by Read.
126   Standard_EXPORT virtual void WriteGeometry
127     (Standard_OStream& OS,
128         const Message_ProgressRange& theRange = Message_ProgressRange()) const;
129   
130   //! Reads the geometry of me from the  stream  <IS>.
131   Standard_EXPORT virtual void ReadGeometry
132     (Standard_IStream& IS,
133         const Message_ProgressRange& theRange = Message_ProgressRange());
134   
135   //! Reads  from <IS>  a shape  and  returns  it in  S.
136   //! <NbShapes> is the number of tshapes in the set.
137   Standard_EXPORT virtual void Read
138     (TopoDS_Shape& S,
139      Standard_IStream& IS, const Standard_Integer NbShapes) const;
140   
141   //! Writes the geometry of <S>  on the stream <OS> in a
142   //! binary format that can be read back by Read.
143   Standard_EXPORT virtual void WriteGeometry (const TopoDS_Shape& S, Standard_OStream& OS) const;
144   
145   //! Reads the geometry of a shape of type <T> from the
146   //! stream <IS> and returns it in <S>.
147   Standard_EXPORT virtual void ReadGeometry (const TopAbs_ShapeEnum T, Standard_IStream& IS, TopoDS_Shape& S);
148   
149   //! Stores the goemetry of <S>.
150   Standard_EXPORT virtual void AddGeometry (const TopoDS_Shape& S);
151   
152   //! Inserts  the shape <S2> in  the  shape <S1>.
153   Standard_EXPORT virtual void AddShapes (TopoDS_Shape& S1, const TopoDS_Shape& S2);
154   
155   //! Reads the 3d polygons  of me
156   //! from the  stream  <IS>.
157   Standard_EXPORT void ReadPolygon3D
158     (Standard_IStream& IS,
159         const Message_ProgressRange& theRange = Message_ProgressRange());
160   
161   //! Writes the 3d polygons
162   //! on the stream <OS> in a format that can
163   //! be read back by Read.
164   Standard_EXPORT void WritePolygon3D
165     (Standard_OStream& OS,
166         const Message_ProgressRange& theRange = Message_ProgressRange()) const;
167   
168   //! Reads the triangulation of me
169   //! from the  stream  <IS>.
170   Standard_EXPORT void ReadTriangulation
171     (Standard_IStream& IS,
172         const Message_ProgressRange& theRange = Message_ProgressRange());
173   
174   //! Writes the triangulation
175   //! on the stream <OS> in a format that can
176   //! be read back by Read.
177   Standard_EXPORT void WriteTriangulation
178     (Standard_OStream& OS,
179         const Message_ProgressRange& theRange = Message_ProgressRange()) const;
180   
181   //! Reads the polygons on triangulation of me
182   //! from the  stream  <IS>.
183   Standard_EXPORT void ReadPolygonOnTriangulation
184     (Standard_IStream& IS,
185         const Message_ProgressRange& theRange = Message_ProgressRange());
186   
187   //! Writes the polygons on triangulation
188   //! on the stream <OS> in a format that can
189   //! be read back by Read.
190   Standard_EXPORT void WritePolygonOnTriangulation
191     (Standard_OStream& OS,
192         const Message_ProgressRange& theRange = Message_ProgressRange()) const;
193
194 public:
195
196   static Standard_CString Version_1;
197   static Standard_CString Version_2;
198   static Standard_CString Version_3;
199
200 private:
201
202   TopTools_IndexedMapOfShape myShapes;
203   BinTools_LocationSet myLocations;
204   Standard_Integer myFormatNb;
205   BRep_Builder myBuilder;
206   BinTools_SurfaceSet mySurfaces;
207   BinTools_CurveSet myCurves;
208   BinTools_Curve2dSet myCurves2d;
209   NCollection_IndexedMap<Handle(Poly_Polygon2D), TColStd_MapTransientHasher> myPolygons2D;
210   NCollection_IndexedMap<Handle(Poly_Polygon3D), TColStd_MapTransientHasher> myPolygons3D;
211   NCollection_IndexedMap<Handle(Poly_Triangulation), TColStd_MapTransientHasher> myTriangulations;
212   NCollection_IndexedMap<Handle(Poly_PolygonOnTriangulation), TColStd_MapTransientHasher> myNodes;
213   Standard_Boolean myWithTriangles;
214
215 };
216
217 #endif // _BinTools_ShapeSet_HeaderFile