Salome HOME
GPUSPHGUI: add Offset transformation
[modules/smesh.git] / src / SMDS / SMDS_MeshIDFactory.cxx
index 20c90bda02d6dc96a342ab5af8cb2cc94cdd2ecd..ea74aa5769c265c08db96911ad816ab0563c6bd5 100644 (file)
@@ -20,7 +20,7 @@
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-//  SMESH SMDS : implementaion of Salome mesh data structure
+//  SMESH SMDS : implementation of Salome mesh data structure
 //  File   : SMDS_MeshIDFactory.cxx
 //  Author : Jean-Michel BOULCOURT
 //  Module : SMESH
@@ -42,25 +42,23 @@ SMDS_MeshIDFactory::SMDS_MeshIDFactory():myMaxID(0), myMesh(0)
 
 int SMDS_MeshIDFactory::GetFreeID()
 {
-        int newid;
-        if (myPoolOfID.empty())
-        {
-            newid = ++myMaxID;
-            //MESSAGE("GetFreeID new " << newid);
-        }
-        else
-        {
-                set<int>::iterator i = myPoolOfID.begin();
-                newid = *i;//myPoolOfID.top();
-                myPoolOfID.erase( i );//myPoolOfID.pop();
-                //MESSAGE("GetFreeID pool " << newid);
-        }
-    return newid;
+  int newid;
+  if (myPoolOfID.empty())
+  {
+    newid = ++myMaxID;
+  }
+  else
+  {
+    set<int>::iterator i = myPoolOfID.begin();
+    newid = *i;
+    myPoolOfID.erase( i );
+  }
+  return newid;
 }
 
 //=======================================================================
 //function : ReleaseID
-//purpose  : 
+//purpose  :
 //=======================================================================
 void SMDS_MeshIDFactory::ReleaseID(int ID, int vtkId)
 {
@@ -79,11 +77,13 @@ void SMDS_MeshIDFactory::ReleaseID(int ID, int vtkId)
         while ( i != myPoolOfID.begin() && myMaxID == *i ) {
           --myMaxID; --i;
         }
-        if ( myMaxID == *i )
+        if ( myMaxID == *i ) {
           --myMaxID; // begin of myPoolOfID reached
-        else
-          ++i;
-        myPoolOfID.erase( i, myPoolOfID.end() );
+          myPoolOfID.clear();
+        }
+        else if ( myMaxID < ID-1 ) {
+          myPoolOfID.erase( ++i, myPoolOfID.end() );
+        }
       }
     }
   }
@@ -91,24 +91,23 @@ void SMDS_MeshIDFactory::ReleaseID(int ID, int vtkId)
 
 void SMDS_MeshIDFactory::Clear()
 {
-        myMaxID = 0;
-        myPoolOfID.clear();
+  myMaxID = 0;
+  myPoolOfID.clear();
 }
 
 void SMDS_MeshIDFactory::SetMesh(SMDS_Mesh *mesh)
 {
-        myMesh = mesh;
+  myMesh = mesh;
 }
 
 SMDS_Mesh* SMDS_MeshIDFactory::GetMesh()
 {
-        return myMesh;
+  return myMesh;
 }
 
 void SMDS_MeshIDFactory::emptyPool(int maxId)
 {
-        MESSAGE("SMDS_MeshIDFactory::emptyPool " << myMaxID << " --> " << maxId);
-        myMaxID = maxId;
-        myPoolOfID.clear();
+  myMaxID = maxId;
+  myPoolOfID.clear();
 }