Salome HOME
67e819e85ac07371635dcf3a8aaffc834cc850b2
[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(), myMin(0), myMax(0)
46 {
47 }
48
49 //=======================================================================
50 //function : BindID
51 //purpose  : 
52 //=======================================================================
53 bool SMDS_MeshNodeIDFactory::BindID(int ID, SMDS_MeshElement * elem)
54 {
55   updateMinMax(ID);
56   return true;
57 }
58
59 //=======================================================================
60 //function : MeshElement
61 //purpose  : 
62 //=======================================================================
63 SMDS_MeshElement* SMDS_MeshNodeIDFactory::MeshElement(int ID)
64 {
65   // commented since myMax can be 0 after ReleaseID()
66 //   if ((ID < 1) || (ID > myMax))
67 //     return NULL;
68   const SMDS_MeshElement* elem = GetMesh()->FindNode(ID);
69   return (SMDS_MeshElement*) (elem);
70 }
71
72 //=======================================================================
73 //function : GetFreeID
74 //purpose  : 
75 //=======================================================================
76 int SMDS_MeshNodeIDFactory::GetFreeID()
77 {
78   int ID;
79   do {
80     ID = SMDS_MeshIDFactory::GetFreeID();
81   } while ( MeshElement( ID ));
82   return ID;
83 }
84
85 //=======================================================================
86 //function : ReleaseID
87 //purpose  : 
88 //=======================================================================
89 void SMDS_MeshNodeIDFactory::ReleaseID(const int ID, int vtkId)
90 {
91   SMDS_MeshIDFactory::ReleaseID(ID);
92   myMesh->setMyModified();
93   if (ID == myMax)
94     myMax = 0; // --- force updateMinMax
95   if (ID == myMin)
96     myMax = 0; // --- force updateMinMax
97 }
98
99 //=======================================================================
100 //function : GetMaxID
101 //purpose  : 
102 //=======================================================================
103
104 int SMDS_MeshNodeIDFactory::GetMaxID() const
105 {
106   if (myMax == 0)
107     updateMinMax();
108   return myMax;
109 }
110
111 //=======================================================================
112 //function : GetMinID
113 //purpose  : 
114 //=======================================================================
115
116 int SMDS_MeshNodeIDFactory::GetMinID() const
117 {
118   if (myMax == 0)
119     updateMinMax();
120   return myMin;
121 }
122
123 //=======================================================================
124 //function : updateMinMax
125 //purpose  : 
126 //=======================================================================
127
128 void SMDS_MeshNodeIDFactory::updateMinMax() const
129 {
130   myMesh->updateNodeMinMax();
131   myMin = myMesh->MinNodeID();
132   myMax = myMesh->MaxNodeID();
133 }
134
135 SMDS_ElemIteratorPtr SMDS_MeshNodeIDFactory::elementsIterator() const
136 {
137   return myMesh->elementsIterator(SMDSAbs_Node);
138 }
139
140 void SMDS_MeshNodeIDFactory::Clear()
141 {
142   myMin = myMax = 0;
143   SMDS_MeshIDFactory::Clear();
144 }
145
146 void SMDS_MeshNodeIDFactory::emptyPool(int maxId)
147 {
148   SMDS_MeshIDFactory::emptyPool(maxId);
149   myMax = maxId;
150 }