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