1 // Created on: 1993-07-01
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16 
17 #ifndef _TopTools_ShapeSet_HeaderFile
18 #define _TopTools_ShapeSet_HeaderFile
19 
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
23 
24 #include <TopTools_IndexedMapOfShape.hxx>
25 #include <TopTools_LocationSet.hxx>
26 #include <Standard_Integer.hxx>
27 #include <Standard_OStream.hxx>
28 #include <Standard_IStream.hxx>
29 #include <TopAbs_ShapeEnum.hxx>
30 class Message_ProgressIndicator;
31 class TopoDS_Shape;
32 class TopTools_LocationSet;
33 class TCollection_AsciiString;
34 
35 
36 //! A ShapeSets    contains  a  Shape    and all   its
37 //! sub-shapes and locations.  It  can be dump,  write
38 //! and read.
39 //!
40 //! Methods to handle the geometry can be redefined.
41 class TopTools_ShapeSet
42 {
43 public:
44 
45   DEFINE_STANDARD_ALLOC
46 
47 
48   //! Builds an empty ShapeSet.
49   Standard_EXPORT TopTools_ShapeSet();
50 
51   Standard_EXPORT virtual ~TopTools_ShapeSet();
52 
53   Standard_EXPORT void SetFormatNb (const Standard_Integer theFormatNb);
54 
55   //! two formats available for the moment:
56   //! First: does not write CurveOnSurface UV Points into the file
57   //! on reading calls Check() method.
58   //! Second: stores CurveOnSurface UV Points.
59   //! On reading format is recognized from Version string.
60   Standard_EXPORT Standard_Integer FormatNb() const;
61 
62   //! Clears the content of the set.  This method can be
63   //! redefined.
64   Standard_EXPORT virtual void Clear();
65 
66   //! Stores <S> and its sub-shape. Returns the index of <S>.
67   //! The method AddGeometry is called on each sub-shape.
68   Standard_EXPORT Standard_Integer Add (const TopoDS_Shape& S);
69 
70   //! Returns the sub-shape of index <I>.
71   Standard_EXPORT const TopoDS_Shape& Shape (const Standard_Integer I) const;
72 
73   //! Returns the index of <S>.
74   Standard_EXPORT Standard_Integer Index (const TopoDS_Shape& S) const;
75 
76   Standard_EXPORT const TopTools_LocationSet& Locations() const;
77 
78   Standard_EXPORT TopTools_LocationSet& ChangeLocations();
79 
80   //! Dumps the number of objects in me on the stream <OS>.
81   //! (Number of shapes of each type)
82   Standard_EXPORT Standard_OStream& DumpExtent (Standard_OStream& OS) const;
83 
84   //! Dumps the number of objects in me in the string S
85   //! (Number of shapes of each type)
86   Standard_EXPORT void DumpExtent (TCollection_AsciiString& S) const;
87 
88   //! Dumps the content of me on the stream <OS>.
89   //!
90   //! Dumps the shapes from first to last.
91   //! For each Shape
92   //! Dump the type, the flags, the subshapes
93   //! calls DumpGeometry(S)
94   //!
95   //! Dumps the geometry calling DumpGeometry.
96   //!
97   //! Dumps the locations.
98   Standard_EXPORT virtual void Dump (Standard_OStream& OS) const;
99 
100   //! Writes the content of  me  on the stream <OS> in a
101   //! format that can be read back by Read.
102   //!
103   //! Writes the locations.
104   //!
105   //! Writes the geometry calling WriteGeometry.
106   //!
107   //! Dumps the shapes from last to first.
108   //! For each shape  :
109   //! Write the type.
110   //! calls WriteGeometry(S).
111   //! Write the flags, the subshapes.
112   Standard_EXPORT virtual void Write (Standard_OStream& OS);
113 
114   //! Reads the content of me from the  stream  <IS>. me
115   //! is first cleared.
116   //!
117   //! Reads the locations.
118   //!
119   //! Reads the geometry calling ReadGeometry.
120   //!
121   //! Reads the shapes.
122   //! For each shape
123   //! Reads the type.
124   //! calls ReadGeometry(T,S).
125   //! Reads the flag, the subshapes.
126   Standard_EXPORT virtual void Read (Standard_IStream& IS);
127 
128   //! Dumps   on  <OS>    the  shape  <S>.   Dumps   the
129   //! orientation, the index of the TShape and the index
130   //! of the Location.
131   Standard_EXPORT void Dump (const TopoDS_Shape& S, Standard_OStream& OS) const;
132 
133   //! Writes   on  <OS>   the shape   <S>.    Writes the
134   //! orientation, the index of the TShape and the index
135   //! of the Location.
136   Standard_EXPORT void Write (const TopoDS_Shape& S, Standard_OStream& OS) const;
137 
138   //! Reads from <IS> a shape and returns it in S.
139   Standard_EXPORT void Read (TopoDS_Shape& S, Standard_IStream& IS) const;
140 
141   //! Stores the geometry of <S>.
142   Standard_EXPORT virtual void AddGeometry (const TopoDS_Shape& S);
143 
144   //! Dumps the geometry of me on the stream <OS>.
145   Standard_EXPORT virtual void DumpGeometry (Standard_OStream& OS) const;
146 
147   //! Writes the geometry of  me  on the stream <OS> in a
148   //! format that can be read back by Read.
149   Standard_EXPORT virtual void WriteGeometry (Standard_OStream& OS);
150 
151   //! Reads the geometry of me from the  stream  <IS>.
152   Standard_EXPORT virtual void ReadGeometry (Standard_IStream& IS);
153 
154   //! Dumps the geometry of <S> on the stream <OS>.
155   Standard_EXPORT virtual void DumpGeometry (const TopoDS_Shape& S, Standard_OStream& OS) const;
156 
157   //! Writes the geometry of <S>  on the stream <OS> in a
158   //! format that can be read back by Read.
159   Standard_EXPORT virtual void WriteGeometry (const TopoDS_Shape& S, Standard_OStream& OS) const;
160 
161   //! Reads the geometry of a shape of type <T> from the
162   //! stream <IS> and returns it in <S>.
163   Standard_EXPORT virtual void ReadGeometry (const TopAbs_ShapeEnum T, Standard_IStream& IS, TopoDS_Shape& S);
164 
165   //! Inserts  the shape <S2> in  the  shape <S1>.  This
166   //! method must be   redefined  to  use   the  correct
167   //! builder.
168   Standard_EXPORT virtual void AddShapes (TopoDS_Shape& S1, const TopoDS_Shape& S2);
169 
170   //! This method is   called after  each  new  completed
171   //! shape. <T> is the  type. <S> is  the shape. In this
172   //! class it does nothing, but it gives the opportunity
173   //! in derived  classes to perform  extra  treatment on
174   //! shapes.
175   Standard_EXPORT virtual void Check (const TopAbs_ShapeEnum T, TopoDS_Shape& S);
176 
177   //! Returns number of shapes read from file.
178   Standard_EXPORT Standard_Integer NbShapes() const;
179 
180   Standard_EXPORT void SetProgress (const Handle(Message_ProgressIndicator)& PR);
181 
182   Standard_EXPORT Handle(Message_ProgressIndicator) GetProgress() const;
183 
184 
185 
186 
187 protected:
188 
189 
190 
191 
192 
193 private:
194 
195 
196   //! Reads  from <IS>  a shape  and  returns  it in  S.
197   //! <NbShapes> is the number of tshapes in the set.
198   Standard_EXPORT void Read (TopoDS_Shape& S, Standard_IStream& IS, const Standard_Integer NbShapes) const;
199 
200 
201   TopTools_IndexedMapOfShape myShapes;
202   TopTools_LocationSet myLocations;
203   Standard_Integer myFormatNb;
204   Handle(Message_ProgressIndicator) myProgress;
205 
206 
207 };
208 
209 
210 
211 
212 
213 
214 
215 #endif // _TopTools_ShapeSet_HeaderFile
216