Salome HOME
IsDimSupported method added
[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_MeshNode.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_ElemIterator
132 {
133   //const SMDS_MeshNode* const *mySet;
134   const std::vector<const SMDS_MeshNode *> mySet;
135   //int myLength;
136   int index;
137  public:
138   //SMDS_PolygonalFaceOfNodes_MyIterator(const SMDS_MeshNode* const *s, int l):
139   //  mySet(s),myLength(l),index(0) {}
140   SMDS_PolygonalFaceOfNodes_MyIterator(const std::vector<const SMDS_MeshNode *> s):
141     mySet(s),index(0) {}
142
143   bool more()
144   {
145     return index < mySet.size();
146   }
147
148   const SMDS_MeshElement* next()
149   {
150     index++;
151     return mySet[index-1];
152   }
153 };
154
155 SMDS_ElemIteratorPtr SMDS_PolygonalFaceOfNodes::elementsIterator
156                                          (SMDSAbs_ElementType type) const
157 {
158   switch(type)
159   {
160   case SMDSAbs_Face:
161     return SMDS_MeshElement::elementsIterator(SMDSAbs_Face);
162   case SMDSAbs_Node:
163     return SMDS_ElemIteratorPtr(new SMDS_PolygonalFaceOfNodes_MyIterator(myNodes));
164   case SMDSAbs_Edge:
165     MESSAGE("Error : edge iterator for SMDS_PolygonalFaceOfNodes not implemented");
166     break;
167   default:
168     return SMDS_ElemIteratorPtr
169       (new SMDS_IteratorOfElements
170        (this,type,SMDS_ElemIteratorPtr
171         (new SMDS_PolygonalFaceOfNodes_MyIterator(myNodes))));
172   }
173   return SMDS_ElemIteratorPtr();
174 }