Salome HOME
PR: temporary
[modules/smesh.git] / src / SMDS / SMDS_MeshNodeIDFactory.cxx
1 //  Copyright (C) 2007-2008  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 //  SMESH SMDS : implementaion of Salome mesh data structure
23 //  File   : SMDS_MeshNodeIDFactory.cxx
24 //  Author : Jean-Michel BOULCOURT
25 //  Module : SMESH
26 //
27 #ifdef _MSC_VER
28 #pragma warning(disable:4786)
29 #endif
30
31 #include "SMDS_MeshNodeIDFactory.hxx"
32 #include "SMDS_MeshElement.hxx"
33 #include "SMDS_Mesh.hxx"
34
35 #include <vtkUnstructuredGrid.h>
36 #include <vtkCellType.h>
37
38 using namespace std;
39
40 //=======================================================================
41 //function : SMDS_MeshNodeIDFactory
42 //purpose  : 
43 //=======================================================================
44 SMDS_MeshNodeIDFactory::SMDS_MeshNodeIDFactory():
45   SMDS_MeshIDFactory(),
46   myMin(0), myMax(0)
47 {
48 }
49
50 //=======================================================================
51 //function : BindID
52 //purpose  : 
53 //=======================================================================
54 bool SMDS_MeshNodeIDFactory::BindID(int ID, SMDS_MeshElement * elem)
55 {
56   updateMinMax (ID);
57   return true;
58 }
59
60 //=======================================================================
61 //function : MeshElement
62 //purpose  : 
63 //=======================================================================
64 SMDS_MeshElement* SMDS_MeshNodeIDFactory::MeshElement(int ID)
65 {
66   if ((ID<0) || (ID>myMax))
67     return NULL;
68   const SMDS_MeshElement* elem = GetMesh()->FindNode(ID);
69   return (SMDS_MeshElement*)(elem);
70 }
71
72 //=======================================================================
73 //function : ReleaseID
74 //purpose  : 
75 //=======================================================================
76 void SMDS_MeshNodeIDFactory::ReleaseID(const int ID)
77 {
78   SMDS_MeshIDFactory::ReleaseID(ID);
79   if (ID == myMax)
80     myMax = 0;     // --- force updateMinMax
81   if (ID == myMin)
82     myMax = 0;     // --- force updateMinMax
83 }
84
85 //=======================================================================
86 //function : GetMaxID
87 //purpose  : 
88 //=======================================================================
89
90 int SMDS_MeshNodeIDFactory::GetMaxID() const
91 {
92   if (myMax == 0)
93     updateMinMax();
94   return myMax;
95 }
96
97 //=======================================================================
98 //function : GetMinID
99 //purpose  : 
100 //=======================================================================
101
102 int SMDS_MeshNodeIDFactory::GetMinID() const
103 {
104   if (myMax == 0)
105     updateMinMax();
106   return myMin;
107 }
108
109 //=======================================================================
110 //function : updateMinMax
111 //purpose  : 
112 //=======================================================================
113
114 void SMDS_MeshNodeIDFactory::updateMinMax() const
115 {
116   myMesh->updateNodeMinMax();
117   myMin = myMesh->MinNodeID();
118   myMax = myMesh->MaxNodeID();
119 }
120
121 SMDS_ElemIteratorPtr SMDS_MeshNodeIDFactory::elementsIterator() const
122 {
123     return myMesh->elementsIterator(SMDSAbs_Node);
124 }
125
126 void SMDS_MeshNodeIDFactory::Clear()
127 {
128   myMin = myMax = 0;
129   SMDS_MeshIDFactory::Clear();
130 }