Salome HOME
0022100: EDF 2413 SMESH: Take into account TRIA7
[modules/smesh.git] / src / SMDS / SMDS_Mesh0DElement.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  SMESH SMDS : implementaion of Salome mesh data structure
21 //  File   : SMDS_Mesh0DElement.cxx
22 //  Module : SMESH
23 //
24 #ifdef _MSC_VER
25 #pragma warning(disable:4786)
26 #endif
27
28 #include "SMDS_Mesh0DElement.hxx"
29 #include "SMDS_IteratorOfElements.hxx"
30 #include "SMDS_MeshNode.hxx"
31 #include "utilities.h"
32
33 using namespace std;
34
35 //=======================================================================
36 //function : SMDS_Mesh0DElement
37 //purpose  :
38 //=======================================================================
39 SMDS_Mesh0DElement::SMDS_Mesh0DElement (const SMDS_MeshNode * node)
40 {
41   MESSAGE("SMDS_Mesh0DElement " << GetID());
42   myNode = node;
43 }
44
45 //=======================================================================
46 //function : Print
47 //purpose  :
48 //=======================================================================
49 void SMDS_Mesh0DElement::Print (ostream & OS) const
50 {
51   OS << "0D Element <" << GetID() << "> : (" << myNode << ") " << endl;
52 }
53
54 //=======================================================================
55 //function : NbNodes
56 //purpose  :
57 //=======================================================================
58 int SMDS_Mesh0DElement::NbNodes() const
59 {
60   return 1;
61 }
62
63 //=======================================================================
64 //function : NbEdges
65 //purpose  :
66 //=======================================================================
67 int SMDS_Mesh0DElement::NbEdges() const
68 {
69   return 0;
70 }
71
72 //=======================================================================
73 //function : GetType
74 //purpose  :
75 //=======================================================================
76 SMDSAbs_ElementType SMDS_Mesh0DElement::GetType() const
77 {
78   return SMDSAbs_0DElement;
79 }
80
81 vtkIdType SMDS_Mesh0DElement::GetVtkType() const
82 {
83   return VTK_VERTEX;
84 }
85
86 //=======================================================================
87 //function : elementsIterator
88 //purpose  :
89 //=======================================================================
90 class SMDS_Mesh0DElement_MyNodeIterator: public SMDS_ElemIterator
91 {
92   const SMDS_MeshNode * myNode;
93   int myIndex;
94  public:
95   SMDS_Mesh0DElement_MyNodeIterator(const SMDS_MeshNode * node):
96     myNode(node),myIndex(0) {}
97
98   bool more()
99   {
100     return myIndex < 1;
101   }
102
103   const SMDS_MeshElement* next()
104   {
105     myIndex++;
106     if (myIndex == 1)
107       return myNode;
108     return NULL;
109   }
110 };
111
112 SMDS_ElemIteratorPtr SMDS_Mesh0DElement::elementsIterator (SMDSAbs_ElementType type) const
113 {
114   switch(type)
115   {
116   case SMDSAbs_0DElement:
117     return SMDS_MeshElement::elementsIterator(SMDSAbs_0DElement);
118   case SMDSAbs_Node:
119     return SMDS_ElemIteratorPtr(new SMDS_Mesh0DElement_MyNodeIterator(myNode));
120   default:
121     return SMDS_ElemIteratorPtr
122       (new SMDS_IteratorOfElements
123        (this,type, SMDS_ElemIteratorPtr(new SMDS_Mesh0DElement_MyNodeIterator(myNode))));
124   }
125 }
126
127 /*!
128  * \brief Return node by its index
129  * \param ind - node index
130  * \retval const SMDS_MeshNode* - the node
131  */
132 const SMDS_MeshNode* SMDS_Mesh0DElement::GetNode(const int ind) const
133 {
134   if (ind == 0)
135     return myNode;
136   return NULL;
137 }
138
139 //=======================================================================
140 //function : ChangeNode
141 //purpose  :
142 //=======================================================================
143 bool SMDS_Mesh0DElement::ChangeNode (const SMDS_MeshNode * node)
144 {
145   myNode = node;
146   return true;
147 }