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