Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/smesh.git] / src / SMDS / SMDS_IteratorOfElements.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  SMESH SMDS : implementaion of Salome mesh data structure
23 //
24 #ifdef _MSC_VER
25 #pragma warning(disable:4786)
26 #endif
27
28 #include "SMDS_IteratorOfElements.hxx"
29
30 bool SMDS_IteratorOfElements::subMore()
31 {
32         if((t2Iterator.get()==NULL)||(!t2Iterator->more()))
33         {
34                 if(t1Iterator->more())
35                 {
36                         t2Iterator=t1Iterator->next()->elementsIterator(myType);
37                         return subMore();
38                 }
39                 else return false;
40         }
41         else return true;
42 }
43
44 const SMDS_MeshElement * SMDS_IteratorOfElements::subNext()
45 {
46         if((t2Iterator.get()==NULL)||(!t2Iterator->more()))
47                 if(t1Iterator->more())
48                         t2Iterator=t1Iterator->next()->elementsIterator(myType);
49         return t2Iterator->next();
50 }
51
52 /////////////////////////////////////////////////////////////////////////////
53 /// Create an iterator which look for elements of type type which are linked 
54 /// to the element element. it is the iterator to get connectivity of element
55 //////////////////////////////////////////////////////////////////////////////
56 SMDS_IteratorOfElements::SMDS_IteratorOfElements(const SMDS_MeshElement * element,
57                                                  SMDSAbs_ElementType type,
58                                                  const SMDS_ElemIteratorPtr& it)
59      : t1Iterator(it),
60        t2Iterator(SMDS_ElemIteratorPtr((SMDS_ElemIterator*)NULL)),
61        myType(type), myElement(element),
62        myProxyElement(NULL)
63 {
64         while(subMore())
65                 alreadyReturnedElements.insert(subNext());
66         itAlreadyReturned= alreadyReturnedElements.begin();
67         switch(myElement->GetType())
68         {
69         case SMDSAbs_Node: 
70         case SMDSAbs_Edge: myReverseIteration=true; break;
71         case SMDSAbs_Face: myReverseIteration=(type==SMDSAbs_Volume); break;
72         default: myReverseIteration=false;
73         }       
74 }
75
76 bool SMDS_IteratorOfElements::more()
77 {
78         if(myProxyElement==NULL)
79         {
80                 while(itAlreadyReturned!=alreadyReturnedElements.end())
81                 {
82                         myProxyElement=*itAlreadyReturned;
83                         itAlreadyReturned++;    
84
85                         if(myReverseIteration)
86                         {
87                                 SMDS_ElemIteratorPtr it=
88                                         myProxyElement->elementsIterator(myElement->GetType());
89                                 while(it->more())
90                                 {                               
91                                         if(it->next()==myElement) return true;
92                                 }
93                         }
94                         else return true;
95                 }
96                 myProxyElement=NULL;
97                 return false;
98         }
99         else return true;
100 }
101
102 const SMDS_MeshElement * SMDS_IteratorOfElements::next()
103 {
104         more();
105         const SMDS_MeshElement *e=myProxyElement;
106         myProxyElement=NULL;
107         return e;
108 }