Salome HOME
af84365f3159608a994479471feafc12c687c455
[tools/medcoupling.git] / src / INTERP_KERNEL / Geometric2D / InterpKernelGeo2DAbstractEdge.cxx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "InterpKernelGeo2DAbstractEdge.hxx"
22 #include "InterpKernelGeo2DComposedEdge.hxx"
23 #include "InterpKernelGeo2DElementaryEdge.hxx"
24
25 using namespace INTERP_KERNEL;
26
27 IteratorOnComposedEdge::IteratorOnComposedEdge():_list_handle(0)
28 {
29 }
30
31 IteratorOnComposedEdge::IteratorOnComposedEdge(ComposedEdge *compEdges):_list_handle(compEdges->getListBehind()) 
32 {
33   first(); 
34 }
35
36 void IteratorOnComposedEdge::operator=(const IteratorOnComposedEdge& other)
37 {
38   _deep_it=other._deep_it;
39   _list_handle=other._list_handle;
40 }
41
42 void IteratorOnComposedEdge::last()
43 {
44   _deep_it=_list_handle->end();
45   _deep_it--;
46 }
47
48 void IteratorOnComposedEdge::nextLoop()
49 {
50   _deep_it++;
51   if(_deep_it==_list_handle->end())
52     first();
53 }
54
55 void IteratorOnComposedEdge::previousLoop()
56 {
57   if(_deep_it!=_list_handle->begin())
58     _deep_it--;
59   else
60     last();
61 }
62
63 bool IteratorOnComposedEdge::goToNextInOn(bool direction, int& i, int nbMax)
64 {
65   TypeOfEdgeLocInPolygon loc=current()->getLoc();
66   if(direction)
67     {
68       while(loc==FULL_OUT_1 && i<nbMax)
69         {
70           nextLoop(); i++;
71           loc=current()->getLoc();
72         }
73       if(i==nbMax)
74         return false;
75       return true;
76     }
77   else
78     {
79       while(loc==FULL_OUT_1 && i<nbMax)
80         {
81           previousLoop(); i++;
82           loc=current()->getLoc();
83         }
84       if(i==nbMax)
85         return false;
86       while(loc!=FULL_OUT_1 && i<nbMax)
87         {
88           previousLoop(); i++;
89           loc=current()->getLoc();
90         }
91       nextLoop(); i--;
92       return true;
93     }
94 }
95
96 void IteratorOnComposedEdge::assignMySelfToAllElems(ComposedEdge *elems)
97 {
98   std::list<ElementaryEdge *> *myList=elems->getListBehind();
99   for(std::list<ElementaryEdge *>::iterator iter=myList->begin();iter!=myList->end();iter++)
100     (*iter)->getIterator()=(*this);
101 }
102
103 void IteratorOnComposedEdge::insertElemEdges(ComposedEdge *elems, bool changeMySelf)
104 {
105   std::list<ElementaryEdge *> *myListToInsert=elems->getListBehind();
106   std::list<ElementaryEdge *>::iterator iter=myListToInsert->begin();
107   *_deep_it=*iter;
108   _deep_it++;
109   iter++;
110   int sizeOfMyList=myListToInsert->size();
111   _list_handle->insert(_deep_it,iter,myListToInsert->end());
112   if(!changeMySelf)
113     {
114       for(int i=0;i<sizeOfMyList;i++)
115         _deep_it--;
116     }
117 }
118