Salome HOME
Fix PAL8562: rpath (rpath-link) option needs parameter - directory to search shared...
[modules/smesh.git] / src / SMDS / SMDS_MeshElementIDFactory.cxx
index 5413533ea1cc5bef0879ffd391e4c4e03abdfafa..8fc09230bcb723997876679cd22bcffa8b939bb7 100644 (file)
 //  Author : Jean-Michel BOULCOURT
 //  Module : SMESH
 
+#ifdef _MSC_VER
+#pragma warning(disable:4786)
+#endif
+
+#include "SMDS_MeshElementIDFactory.hxx"
+#include "SMDS_MeshElement.hxx"
+
 using namespace std;
-#include "SMDS_MeshElementIDFactory.ixx"
 
 //=======================================================================
 //function : SMDS_MeshElementIDFactory
 //purpose  : 
 //=======================================================================
+SMDS_MeshElementIDFactory::SMDS_MeshElementIDFactory():
+  SMDS_MeshIDFactory(),
+  myMin(0), myMax(0)
+{
+}
+
+//=======================================================================
+//function : BindID
+//purpose  : 
+//=======================================================================
+bool SMDS_MeshElementIDFactory::BindID(int ID, SMDS_MeshElement * elem)
+{
+  if (myIDElements.IsBound(ID))
+    return false;
+  myIDElements.Bind(ID,elem);
+  elem->myID=ID;
+  updateMinMax (ID);
+  return true;
+}
+
+//=======================================================================
+//function : MeshElement
+//purpose  : 
+//=======================================================================
+SMDS_MeshElement* SMDS_MeshElementIDFactory::MeshElement(int ID)
+{
+  if (!myIDElements.IsBound(ID))
+    return NULL;
+  return myIDElements.Find(ID);
+}
+
+
+//=======================================================================
+//function : GetFreeID
+//purpose  : 
+//=======================================================================
+int SMDS_MeshElementIDFactory::GetFreeID()
+{
+  int ID;
+  do {
+    ID = SMDS_MeshIDFactory::GetFreeID();
+  } while (myIDElements.IsBound(ID));
+  return ID;
+}
+
+//=======================================================================
+//function : ReleaseID
+//purpose  : 
+//=======================================================================
+void SMDS_MeshElementIDFactory::ReleaseID(const int ID)
+{
+  myIDElements.UnBind(ID);
+  SMDS_MeshIDFactory::ReleaseID(ID);
+  if (ID == myMax)
+    myMax = 0;
+  if (ID == myMin)
+    myMin = 0;
+}
+
+//=======================================================================
+//function : GetMaxID
+//purpose  : 
+//=======================================================================
+
+int SMDS_MeshElementIDFactory::GetMaxID() const
+{
+  if (myMax == 0)
+    updateMinMax();
+  return myMax;
+}
+
+//=======================================================================
+//function : GetMinID
+//purpose  : 
+//=======================================================================
+
+int SMDS_MeshElementIDFactory::GetMinID() const
+{
+  if (myMin == 0)
+    updateMinMax();
+  return myMin;
+}
+
+//=======================================================================
+//function : updateMinMax
+//purpose  : 
+//=======================================================================
 
-SMDS_MeshElementIDFactory::SMDS_MeshElementIDFactory() : SMDS_MeshIDFactory()
+void SMDS_MeshElementIDFactory::updateMinMax() const
 {
+  myMin = IntegerLast();
+  myMax = 0;
+  SMDS_IdElementMap::Iterator it(myIDElements);
+  for (; it.More(); it.Next())
+    updateMinMax (it.Key());
+  if (myMin == IntegerLast())
+    myMin = 0;
 }
 
+//=======================================================================
+//function : elementsIterator
+//purpose  : Return an iterator on elements of the factory
+//=======================================================================
+
+class SMDS_Fact_MyElemIterator:public SMDS_ElemIterator
+{
+  SMDS_IdElementMap::Iterator myIterator;
+ public:
+  SMDS_Fact_MyElemIterator(const SMDS_IdElementMap& s):myIterator(s)
+  {}
+
+  bool more()
+  {
+    return myIterator.More() != Standard_False;
+  }
+
+  const SMDS_MeshElement* next()
+  {
+    const SMDS_MeshElement* current = myIterator.Value();
+    myIterator.Next();
+    return current;
+  }
+};
+
+SMDS_ElemIteratorPtr SMDS_MeshElementIDFactory::elementsIterator() const
+{
+  return SMDS_ElemIteratorPtr
+    (new SMDS_Fact_MyElemIterator(myIDElements));
+}