Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[modules/smesh.git] / src / SMDS / SMDS_PolygonalFaceOfNodes.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_PolygonalFaceOfNodes.hxx"
27
28 #include "SMDS_IteratorOfElements.hxx"
29 #include "SMDS_SetIterator.hxx"
30 #include "utilities.h"
31
32 using namespace std;
33
34 //=======================================================================
35 //function : Constructor
36 //purpose  : 
37 //=======================================================================
38 SMDS_PolygonalFaceOfNodes::SMDS_PolygonalFaceOfNodes
39                           (std::vector<const SMDS_MeshNode *> nodes)
40 {
41   myNodes = nodes;
42 }
43
44 //=======================================================================
45 //function : GetType
46 //purpose  : 
47 //=======================================================================
48 SMDSAbs_ElementType SMDS_PolygonalFaceOfNodes::GetType() const
49 {
50   return SMDSAbs_Face;
51   //return SMDSAbs_PolygonalFace;
52 }
53
54 //=======================================================================
55 //function : ChangeNodes
56 //purpose  : 
57 //=======================================================================
58 bool SMDS_PolygonalFaceOfNodes::ChangeNodes (std::vector<const SMDS_MeshNode *> nodes)
59 {
60   if (nodes.size() < 3)
61     return false;
62
63   myNodes = nodes;
64
65   return true;
66 }
67
68 //=======================================================================
69 //function : ChangeNodes
70 //purpose  : to support the same interface, as SMDS_FaceOfNodes
71 //=======================================================================
72 bool SMDS_PolygonalFaceOfNodes::ChangeNodes (const SMDS_MeshNode* nodes[],
73                                              const int            nbNodes)
74 {
75   if (nbNodes < 3)
76     return false;
77
78   myNodes.resize(nbNodes);
79   int i = 0;
80   for (; i < nbNodes; i++) {
81     myNodes[i] = nodes[i];
82   }
83
84   return true;
85 }
86
87 //=======================================================================
88 //function : NbNodes
89 //purpose  : 
90 //=======================================================================
91 int SMDS_PolygonalFaceOfNodes::NbNodes() const
92 {
93   return myNodes.size();
94 }
95
96 //=======================================================================
97 //function : NbEdges
98 //purpose  : 
99 //=======================================================================
100 int SMDS_PolygonalFaceOfNodes::NbEdges() const
101 {
102   return NbNodes();
103 }
104
105 //=======================================================================
106 //function : NbFaces
107 //purpose  : 
108 //=======================================================================
109 int SMDS_PolygonalFaceOfNodes::NbFaces() const
110 {
111   return 1;
112 }
113
114 //=======================================================================
115 //function : Print
116 //purpose  : 
117 //=======================================================================
118 void SMDS_PolygonalFaceOfNodes::Print(ostream & OS) const
119 {
120   OS << "polygonal face <" << GetID() << " > : ";
121   int i, nbNodes = myNodes.size();
122   for (i = 0; i < nbNodes - 1; i++)
123     OS << myNodes[i] << ",";
124   OS << myNodes[i] << ") " << endl;
125 }
126
127 //=======================================================================
128 //function : elementsIterator
129 //purpose  : 
130 //=======================================================================
131 class SMDS_PolygonalFaceOfNodes_MyIterator:public SMDS_NodeVectorElemIterator
132 {
133  public:
134   SMDS_PolygonalFaceOfNodes_MyIterator(const vector<const SMDS_MeshNode *>& s):
135     SMDS_NodeVectorElemIterator( s.begin(), s.end() ) {}
136 };
137
138 SMDS_ElemIteratorPtr SMDS_PolygonalFaceOfNodes::elementsIterator
139                                          (SMDSAbs_ElementType type) const
140 {
141   switch(type)
142   {
143   case SMDSAbs_Face:
144     return SMDS_MeshElement::elementsIterator(SMDSAbs_Face);
145   case SMDSAbs_Node:
146     return SMDS_ElemIteratorPtr(new SMDS_PolygonalFaceOfNodes_MyIterator(myNodes));
147   case SMDSAbs_Edge:
148     MESSAGE("Error : edge iterator for SMDS_PolygonalFaceOfNodes not implemented");
149     break;
150   default:
151     return SMDS_ElemIteratorPtr
152       (new SMDS_IteratorOfElements
153        (this,type,SMDS_ElemIteratorPtr
154         (new SMDS_PolygonalFaceOfNodes_MyIterator(myNodes))));
155   }
156   return SMDS_ElemIteratorPtr();
157 }
158
159 /*!
160  * \brief Return node by its index
161  * \param ind - node index
162  * \retval const SMDS_MeshNode* - the node
163  * 
164  * Index is wrapped if it is out of a valid range
165  */
166 const SMDS_MeshNode* SMDS_PolygonalFaceOfNodes::GetNode(const int ind) const
167 {
168   return myNodes[ WrappedIndex( ind )];
169 }
170