00001 // Copyright (C) 2007-2011 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 00023 // SMESH SMDS : implementaion of Salome mesh data structure 00024 // File : SMDS_MeshIDFactory.cxx 00025 // Author : Jean-Michel BOULCOURT 00026 // Module : SMESH 00027 // 00028 #include "SMDS_MeshIDFactory.hxx" 00029 #include "SMDS_Mesh.hxx" 00030 #include "utilities.h" 00031 00032 using namespace std; 00033 00034 //======================================================================= 00035 //function : SMDS_MeshIDFactory 00036 //purpose : 00037 //======================================================================= 00038 00039 SMDS_MeshIDFactory::SMDS_MeshIDFactory():myMaxID(0), myMesh(0) 00040 { 00041 } 00042 00043 int SMDS_MeshIDFactory::GetFreeID() 00044 { 00045 int newid; 00046 if (myPoolOfID.empty()) 00047 { 00048 newid = ++myMaxID; 00049 //MESSAGE("GetFreeID new " << newid); 00050 } 00051 else 00052 { 00053 set<int>::iterator i = myPoolOfID.begin(); 00054 newid = *i;//myPoolOfID.top(); 00055 myPoolOfID.erase( i );//myPoolOfID.pop(); 00056 //MESSAGE("GetFreeID pool " << newid); 00057 } 00058 return newid; 00059 } 00060 00061 //======================================================================= 00062 //function : ReleaseID 00063 //purpose : 00064 //======================================================================= 00065 void SMDS_MeshIDFactory::ReleaseID(int ID, int vtkId) 00066 { 00067 if ( ID > 0 ) 00068 { 00069 if ( ID < myMaxID ) 00070 { 00071 myPoolOfID.insert(ID); 00072 } 00073 else if ( ID == myMaxID ) 00074 { 00075 --myMaxID; 00076 if ( !myPoolOfID.empty() ) // assure that myMaxID is not in myPoolOfID 00077 { 00078 set<int>::iterator i = --myPoolOfID.end(); 00079 while ( i != myPoolOfID.begin() && myMaxID == *i ) { 00080 --myMaxID; --i; 00081 } 00082 if ( myMaxID == *i ) 00083 --myMaxID; // begin of myPoolOfID reached 00084 else 00085 ++i; 00086 myPoolOfID.erase( i, myPoolOfID.end() ); 00087 } 00088 } 00089 } 00090 } 00091 00092 void SMDS_MeshIDFactory::Clear() 00093 { 00094 myMaxID = 0; 00095 myPoolOfID.clear(); 00096 } 00097 00098 void SMDS_MeshIDFactory::SetMesh(SMDS_Mesh *mesh) 00099 { 00100 myMesh = mesh; 00101 } 00102 00103 SMDS_Mesh* SMDS_MeshIDFactory::GetMesh() 00104 { 00105 return myMesh; 00106 } 00107 00108 void SMDS_MeshIDFactory::emptyPool(int maxId) 00109 { 00110 MESSAGE("SMDS_MeshIDFactory::emptyPool " << myMaxID << " --> " << maxId); 00111 myMaxID = maxId; 00112 myPoolOfID.clear(); 00113 } 00114