Salome HOME
OCCT dev version porting (6.7.2)
[modules/geom.git] / src / OCC2VTK / OCC2VTK_internal.h
1 #ifndef OCC2VTK_INTERNAL_H
2 #define OCC2VTK_INTERNAL_H
3
4 #include <NCollection_BaseCollection.hxx>
5 #include <NCollection_BaseList.hxx>
6 #include <NCollection_TListNode.hxx>
7 #include <NCollection_TListIterator.hxx>
8
9 #include <TopoDS_Vertex.hxx>
10 #include <TopoDS_Edge.hxx> 
11 #include <TopoDS_Face.hxx> 
12
13 template <class TheItemType> class GEOM_Set
14   : public NCollection_BaseCollection<TheItemType>,
15     public NCollection_BaseList
16 {
17 public:
18   typedef NCollection_TListNode<TheItemType> SetNode;
19   typedef NCollection_TListIterator<TheItemType> Iterator;
20
21 public:
22   //! Constructor
23   GEOM_Set(const Handle(NCollection_BaseAllocator)& theAllocator=0L) :
24     NCollection_BaseCollection<TheItemType>(theAllocator),
25     NCollection_BaseList() {}
26
27   //! Copy constructor
28   GEOM_Set (const GEOM_Set& theOther) :
29     NCollection_BaseCollection<TheItemType>(theOther.myAllocator),
30     NCollection_BaseList()
31   { *this = theOther; }
32
33   //! Size - Number of items
34   virtual Standard_Integer Size (void) const
35   { return Extent(); }
36
37   //! Replace this list by the items of theOther collection
38   virtual void Assign (const NCollection_BaseCollection<TheItemType>& theOther)
39   {
40     if (this == &theOther) 
41       return;
42     Clear();
43     TYPENAME NCollection_BaseCollection<TheItemType>::Iterator& anIter = 
44       theOther.CreateIterator();
45     for (; anIter.More(); anIter.Next())
46     {
47       SetNode* pNew = new (this->myAllocator) SetNode(anIter.Value());
48       PAppend (pNew);
49     }
50   }
51
52   //! Replace this list by the items of theOther Set
53   GEOM_Set& operator= (const GEOM_Set& theOther)
54   { 
55     if (this == &theOther) 
56       return *this;
57     Clear ();
58     SetNode * pCur = (SetNode *) theOther.PFirst();
59     while (pCur)
60     {
61       SetNode* pNew = new (this->myAllocator) SetNode(pCur->Value());
62       PAppend (pNew);
63       pCur = (SetNode *) pCur->Next();
64     }
65     return *this;
66   }
67
68   //! Clear this set
69   void Clear (void)
70   { PClear (SetNode::delNode, this->myAllocator); }
71
72   //! Add item
73   Standard_Boolean Add (const TheItemType& theItem)
74   { 
75     Iterator anIter(*this);
76     while (anIter.More())
77     {
78       if (anIter.Value() == theItem)
79         return Standard_False;
80       anIter.Next();
81     }
82     SetNode * pNew = new (this->myAllocator) SetNode(theItem);
83     PPrepend (pNew);
84     return Standard_True;
85   }
86
87   //! Remove item
88   Standard_Boolean Remove (const TheItemType& theItem)
89   {
90     Iterator anIter(*this);
91     while (anIter.More())
92     {
93       if (anIter.Value() == theItem)
94       {
95         PRemove (anIter, SetNode::delNode, this->myAllocator);
96         return Standard_True;
97       }
98       anIter.Next();
99     }
100     return Standard_False;
101   }
102
103   //! Remove - wrapper against 'hiding' warnings
104   void Remove (Iterator& theIter) 
105   { NCollection_BaseList::PRemove (theIter,
106                                    SetNode::delNode,
107                                    this->myAllocator); }
108
109   //! Contains - item inclusion query
110   Standard_Boolean Contains (const TheItemType& theItem) const
111   {
112     Iterator anIter(*this);
113     for (; anIter.More(); anIter.Next())
114       if (anIter.Value() == theItem)
115         return Standard_True;
116     return Standard_False;
117   }
118
119   //! IsASubset
120   Standard_Boolean IsASubset (const GEOM_Set& theOther)
121   { 
122     if (this == &theOther) 
123       return Standard_True;
124     Iterator anIter(theOther);
125     for (; anIter.More(); anIter.Next())
126       if (!Contains(anIter.Value()))
127         return Standard_False;
128     return Standard_True;
129   }
130
131   //! IsAProperSubset
132   Standard_Boolean IsAProperSubset (const GEOM_Set& theOther)
133   {
134     if (myLength <= theOther.Extent())
135       return Standard_False;
136     Iterator anIter(theOther);
137     for (; anIter.More(); anIter.Next())
138       if (!Contains(anIter.Value()))
139         return Standard_False;
140     return Standard_True;
141   }
142
143   //! Union
144   void Union (const GEOM_Set& theOther)
145   { 
146     if (this == &theOther) 
147       return;
148     Iterator anIter(theOther);
149     Iterator aMyIter;
150     Standard_Integer i, iLength=myLength;
151     for (; anIter.More(); anIter.Next())
152     {
153       Standard_Boolean isIn=Standard_False;
154       const TheItemType& theItem = anIter.Value();
155       for (aMyIter.Init(*this), i=1; 
156            i<=iLength;
157            aMyIter.Next(), i++)
158         if (theItem == aMyIter.Value())
159           isIn = Standard_True;
160       if (!isIn)
161       {
162         SetNode * pNew = new (this->myAllocator) SetNode(theItem);
163         PAppend (pNew);
164       }
165     }
166   }
167
168   //! Intersection
169   void Intersection (const GEOM_Set& theOther)
170   { 
171     if (this == &theOther) 
172       return;
173     Iterator anIter(*this);
174     while (anIter.More())
175       if (theOther.Contains(anIter.Value()))
176         anIter.Next();
177       else
178         NCollection_BaseList::PRemove (anIter, SetNode::delNode, this->myAllocator);
179   }
180
181   //! Difference (Subtraction)
182   void Difference (const GEOM_Set& theOther)
183   { 
184     if (this == &theOther) 
185       return;
186     Iterator anIter(*this);
187     while (anIter.More())
188       if (theOther.Contains(anIter.Value()))
189         NCollection_BaseList::PRemove (anIter, SetNode::delNode, this->myAllocator);
190       else
191         anIter.Next();
192   }
193
194   //! Destructor - clears the List
195   ~GEOM_Set (void)
196   { Clear(); }
197
198 private:
199   //! Creates Iterator for use on BaseCollection
200   virtual TYPENAME NCollection_BaseCollection<TheItemType>::Iterator& 
201     CreateIterator(void) const
202   { return *(new (this->IterAllocator()) Iterator(*this)); }
203
204 };
205
206 typedef GEOM_Set<TopoDS_Vertex> TVertexSet; 
207 typedef GEOM_Set<TopoDS_Edge> TEdgeSet; 
208 typedef GEOM_Set<TopoDS_Face> TFaceSet; 
209
210 class VertexSourceInternal
211 {
212 public:
213   TVertexSet myVertexSet;
214 };
215
216 class EdgeSourceInternal
217 {
218 public:
219   TEdgeSet myEdgeSet;
220 };
221
222 class FaceSourceInternal
223 {
224 public:
225   TFaceSet myFaceSet;
226 };
227
228 #endif // OCC2VTK_INTERNAL_H