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