Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/smesh.git] / src / SMDS / SMDS_FaceOfEdges.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_FaceOfEdges.hxx"
29 #include "SMDS_IteratorOfElements.hxx"
30 #include "SMDS_MeshNode.hxx"
31
32 using namespace std;
33
34 //=======================================================================
35 //function : NbEdges
36 //purpose  : 
37 //=======================================================================
38
39 int SMDS_FaceOfEdges::NbEdges() const
40 {
41         return myNbEdges;
42 }
43
44 int SMDS_FaceOfEdges::NbFaces() const
45 {
46         return 1;
47 }
48 //=======================================================================
49 //function : Print
50 //purpose  : 
51 //=======================================================================
52
53 void SMDS_FaceOfEdges::Print(ostream & OS) const
54 {
55         OS << "face <" << GetID() << " > : ";
56         int i;
57         for (i = 0; i < NbEdges() - 1; i++) OS << myEdges[i] << ",";
58         OS << myEdges[i] << ") " << endl;
59 }
60
61 SMDSAbs_ElementType SMDS_FaceOfEdges::GetType() const
62 {
63         return SMDSAbs_Face;
64 }
65
66 //=======================================================================
67 //function : elementsIterator
68 //purpose  : 
69 //=======================================================================
70
71 class SMDS_FaceOfEdges_MyIterator:public SMDS_ElemIterator
72 {
73   const SMDS_MeshEdge* const *mySet;
74   int myLength;
75   int index;
76  public:
77   SMDS_FaceOfEdges_MyIterator(const SMDS_MeshEdge* const *s, int l):
78     mySet(s),myLength(l),index(0) {}
79
80   bool more()
81   {
82     return index<myLength;
83   }
84
85   const SMDS_MeshElement* next()
86   {
87     index++;
88     return mySet[index-1];
89   }     
90 };
91
92 SMDS_ElemIteratorPtr SMDS_FaceOfEdges::elementsIterator
93                          (SMDSAbs_ElementType type) const
94 {
95   switch(type)
96   {
97   case SMDSAbs_Face:
98     return SMDS_MeshElement::elementsIterator(SMDSAbs_Face);
99   case SMDSAbs_Edge:
100     return SMDS_ElemIteratorPtr(new SMDS_FaceOfEdges_MyIterator(myEdges,myNbEdges));
101   default:
102     return SMDS_ElemIteratorPtr
103       (new SMDS_IteratorOfElements
104        (this,type, SMDS_ElemIteratorPtr
105         (new SMDS_FaceOfEdges_MyIterator(myEdges,myNbEdges))));
106   }
107 }
108
109 SMDS_FaceOfEdges::SMDS_FaceOfEdges(const SMDS_MeshEdge* edge1,
110                                    const SMDS_MeshEdge* edge2,
111                                    const SMDS_MeshEdge* edge3)
112 {
113         myNbEdges = 3;
114         myEdges[0]=edge1;
115         myEdges[1]=edge2;
116         myEdges[2]=edge3;
117         myEdges[3]=0;
118 }
119
120 SMDS_FaceOfEdges::SMDS_FaceOfEdges(const SMDS_MeshEdge* edge1,
121                                    const SMDS_MeshEdge* edge2,
122                                    const SMDS_MeshEdge* edge3,
123                                    const SMDS_MeshEdge* edge4)
124 {
125         myNbEdges = 4;
126         myEdges[0]=edge1;
127         myEdges[1]=edge2;
128         myEdges[2]=edge3;
129         myEdges[3]=edge4;       
130 }
131
132 /*bool operator<(const SMDS_FaceOfEdges& f1, const SMDS_FaceOfEdges& f2)
133 {
134         set<SMDS_MeshNode> set1,set2;
135         SMDS_ElemIteratorPtr it;
136         const SMDS_MeshNode * n;
137
138         it=f1.nodesIterator();
139
140         while(it->more())
141         {
142                 n=static_cast<const SMDS_MeshNode *>(it->next());
143                 set1.insert(*n);
144         }
145
146         delete it;
147         it=f2.nodesIterator();
148         
149         while(it->more())
150         {       
151                 n=static_cast<const SMDS_MeshNode *>(it->next());
152                 set2.insert(*n);
153         }
154
155         delete it;
156         return set1<set2;       
157
158 }*/
159
160
161 int SMDS_FaceOfEdges::NbNodes() const
162 {
163   return myEdges[0]->NbNodes() + myEdges[1]->NbNodes() + myEdges[2]->NbNodes() +
164     ( myNbEdges == 4 ? myEdges[3]->NbNodes() : 0 ) - myNbEdges;
165 }
166
167 /*!
168  * \brief Return node by its index
169  * \param ind - node index
170  * \retval const SMDS_MeshNode* - the node
171  * 
172  * Index is wrapped if it is out of a valid range
173  */
174 const SMDS_MeshNode* SMDS_FaceOfEdges::GetNode(const int ind) const
175 {
176   int index = WrappedIndex( ind );
177   for ( int i = 0; i < myNbEdges; ++i ) {
178     if ( index >= myEdges[ i ]->NbNodes() )
179       index -= myEdges[ i ]->NbNodes();
180     else
181       return myEdges[ i ]->GetNode( index );
182   }
183   return 0;
184 }
185