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