Back to index

salome-smesh  6.5.0
SMDS_MeshNodeIDFactory.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 //  File   : SMDS_MeshNodeIDFactory.cxx
00023 //  Author : Jean-Michel BOULCOURT
00024 //  Module : SMESH
00025 //
00026 #ifdef _MSC_VER
00027 #pragma warning(disable:4786)
00028 #endif
00029 
00030 #include "SMDS_MeshNodeIDFactory.hxx"
00031 #include "SMDS_MeshElement.hxx"
00032 #include "SMDS_Mesh.hxx"
00033 
00034 #include <vtkUnstructuredGrid.h>
00035 #include <vtkCellType.h>
00036 
00037 using namespace std;
00038 
00039 //=======================================================================
00040 //function : SMDS_MeshNodeIDFactory
00041 //purpose  : 
00042 //=======================================================================
00043 SMDS_MeshNodeIDFactory::SMDS_MeshNodeIDFactory() :
00044   SMDS_MeshIDFactory(), myMin(0), myMax(0)
00045 {
00046 }
00047 
00048 //=======================================================================
00049 //function : BindID
00050 //purpose  : 
00051 //=======================================================================
00052 bool SMDS_MeshNodeIDFactory::BindID(int ID, SMDS_MeshElement * elem)
00053 {
00054   updateMinMax(ID);
00055   return true;
00056 }
00057 
00058 //=======================================================================
00059 //function : MeshElement
00060 //purpose  : 
00061 //=======================================================================
00062 SMDS_MeshElement* SMDS_MeshNodeIDFactory::MeshElement(int ID)
00063 {
00064   // commented since myMax can be 0 after ReleaseID()
00065 //   if ((ID < 1) || (ID > myMax))
00066 //     return NULL;
00067   const SMDS_MeshElement* elem = GetMesh()->FindNode(ID);
00068   return (SMDS_MeshElement*) (elem);
00069 }
00070 
00071 //=======================================================================
00072 //function : GetFreeID
00073 //purpose  : 
00074 //=======================================================================
00075 int SMDS_MeshNodeIDFactory::GetFreeID()
00076 {
00077   int ID;
00078   do {
00079     ID = SMDS_MeshIDFactory::GetFreeID();
00080   } while ( MeshElement( ID ));
00081   return ID;
00082 }
00083 
00084 //=======================================================================
00085 //function : ReleaseID
00086 //purpose  : 
00087 //=======================================================================
00088 void SMDS_MeshNodeIDFactory::ReleaseID(const int ID, int vtkId)
00089 {
00090   SMDS_MeshIDFactory::ReleaseID(ID);
00091   myMesh->setMyModified();
00092   if (ID == myMax)
00093     myMax = 0; // --- force updateMinMax
00094   if (ID == myMin)
00095     myMax = 0; // --- force updateMinMax
00096 }
00097 
00098 //=======================================================================
00099 //function : GetMaxID
00100 //purpose  : 
00101 //=======================================================================
00102 
00103 int SMDS_MeshNodeIDFactory::GetMaxID() const
00104 {
00105   if (myMax == 0)
00106     updateMinMax();
00107   return myMax;
00108 }
00109 
00110 //=======================================================================
00111 //function : GetMinID
00112 //purpose  : 
00113 //=======================================================================
00114 
00115 int SMDS_MeshNodeIDFactory::GetMinID() const
00116 {
00117   if (myMax == 0)
00118     updateMinMax();
00119   return myMin;
00120 }
00121 
00122 //=======================================================================
00123 //function : updateMinMax
00124 //purpose  : 
00125 //=======================================================================
00126 
00127 void SMDS_MeshNodeIDFactory::updateMinMax() const
00128 {
00129   myMesh->updateNodeMinMax();
00130   myMin = myMesh->MinNodeID();
00131   myMax = myMesh->MaxNodeID();
00132 }
00133 
00134 SMDS_ElemIteratorPtr SMDS_MeshNodeIDFactory::elementsIterator() const
00135 {
00136   return myMesh->elementsIterator(SMDSAbs_Node);
00137 }
00138 
00139 void SMDS_MeshNodeIDFactory::Clear()
00140 {
00141   myMin = myMax = 0;
00142   SMDS_MeshIDFactory::Clear();
00143 }
00144 
00145 void SMDS_MeshNodeIDFactory::emptyPool(int maxId)
00146 {
00147   SMDS_MeshIDFactory::emptyPool(maxId);
00148   myMax = maxId;
00149 }