Salome HOME
0022107: EDF 2502 SMESH: Publish the result of show bad mesh in a group
[modules/smesh.git] / src / SMDS / SMDS_IteratorOfElements.cxx
1 // Copyright (C) 2007-2013  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
23 //  SMESH SMDS : implementaion of Salome mesh data structure
24 //
25 #ifdef _MSC_VER
26 #pragma warning(disable:4786)
27 #endif
28
29 #include "SMDS_IteratorOfElements.hxx"
30
31 bool SMDS_IteratorOfElements::subMore()
32 {
33         if((t2Iterator.get()==NULL)||(!t2Iterator->more()))
34         {
35                 if(t1Iterator->more())
36                 {
37                         t2Iterator=t1Iterator->next()->elementsIterator(myType);
38                         return subMore();
39                 }
40                 else return false;
41         }
42         else return true;
43 }
44
45 const SMDS_MeshElement * SMDS_IteratorOfElements::subNext()
46 {
47         if((t2Iterator.get()==NULL)||(!t2Iterator->more()))
48                 if(t1Iterator->more())
49                         t2Iterator=t1Iterator->next()->elementsIterator(myType);
50         return t2Iterator->next();
51 }
52
53 /////////////////////////////////////////////////////////////////////////////
54 /// Create an iterator which look for elements of type type which are linked 
55 /// to the element element. it is the iterator to get connectivity of element
56 //////////////////////////////////////////////////////////////////////////////
57 SMDS_IteratorOfElements::SMDS_IteratorOfElements(const SMDS_MeshElement * element,
58                                                  SMDSAbs_ElementType type,
59                                                  const SMDS_ElemIteratorPtr& it)
60      : t1Iterator(it),
61        t2Iterator(SMDS_ElemIteratorPtr((SMDS_ElemIterator*)NULL)),
62        myType(type), myElement(element),
63        myProxyElement(NULL)
64 {
65         while(subMore())
66                 alreadyReturnedElements.insert(subNext());
67         itAlreadyReturned= alreadyReturnedElements.begin();
68         switch(myElement->GetType())
69         {
70         case SMDSAbs_Node: 
71         case SMDSAbs_Edge: myReverseIteration=true; break;
72         case SMDSAbs_Face: myReverseIteration=(type==SMDSAbs_Volume); break;
73         default: myReverseIteration=false;
74         }       
75 }
76
77 bool SMDS_IteratorOfElements::more()
78 {
79         if(myProxyElement==NULL)
80         {
81                 while(itAlreadyReturned!=alreadyReturnedElements.end())
82                 {
83                         myProxyElement=*itAlreadyReturned;
84                         itAlreadyReturned++;    
85
86                         if(myReverseIteration)
87                         {
88                                 SMDS_ElemIteratorPtr it=
89                                         myProxyElement->elementsIterator(myElement->GetType());
90                                 while(it->more())
91                                 {                               
92                                         if(it->next()==myElement) return true;
93                                 }
94                         }
95                         else return true;
96                 }
97                 myProxyElement=NULL;
98                 return false;
99         }
100         else return true;
101 }
102
103 const SMDS_MeshElement * SMDS_IteratorOfElements::next()
104 {
105         more();
106         const SMDS_MeshElement *e=myProxyElement;
107         myProxyElement=NULL;
108         return e;
109 }