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