+ if ((ID<1) || (ID>=myMesh->myCells.size()))
+ return NULL;
+ const SMDS_MeshElement* elem = GetMesh()->FindElement(ID);
+ return (SMDS_MeshElement*)(elem);
+}
+
+//=======================================================================
+//function : GetFreeID
+//purpose :
+//=======================================================================
+
+int SMDS_MeshElementIDFactory::GetFreeID()
+{
+ int ID;
+ do {
+ ID = SMDS_MeshIDFactory::GetFreeID();
+ } while ( MeshElement( ID ));
+ return ID;
+}
+
+//=======================================================================
+//function : ReleaseID
+//purpose :
+//=======================================================================
+void SMDS_MeshElementIDFactory::ReleaseID(int ID, int vtkId)
+{
+ if (ID < 1) // TODO check case ID == O
+ {
+ MESSAGE("~~~~~~~~~~~~~~ SMDS_MeshElementIDFactory::ReleaseID ID = " << ID);
+ return;
+ }
+ //MESSAGE("~~~~~~~~~~~~~~ SMDS_MeshElementIDFactory::ReleaseID smdsId vtkId " << ID << " " << vtkId);
+ if (vtkId >= 0)
+ {
+ assert(vtkId < myMesh->myCellIdVtkToSmds.size());
+ myMesh->myCellIdVtkToSmds[vtkId] = -1;
+ myMesh->setMyModified();
+ }
+ SMDS_MeshIDFactory::ReleaseID(ID);
+ if (ID == myMax)
+ myMax = 0;
+ if (ID == myMin)
+ myMax = 0;
+}
+
+//=======================================================================
+//function : updateMinMax
+//purpose :
+//=======================================================================
+
+void SMDS_MeshElementIDFactory::updateMinMax() const
+{
+ myMin = INT_MAX;
+ myMax = 0;
+ for (int i = 0; i < myMesh->myCells.size(); i++)
+ {
+ if (myMesh->myCells[i])
+ {
+ int id = myMesh->myCells[i]->GetID();
+ if (id > myMax)
+ myMax = id;
+ if (id < myMin)
+ myMin = id;
+ }
+ }
+ if (myMin == INT_MAX)
+ myMin = 0;
+}
+
+//=======================================================================
+//function : elementsIterator
+//purpose : Return an iterator on elements of the factory
+//=======================================================================
+
+SMDS_ElemIteratorPtr SMDS_MeshElementIDFactory::elementsIterator() const
+{
+ return myMesh->elementsIterator(SMDSAbs_All);
+}
+
+void SMDS_MeshElementIDFactory::Clear()
+{
+ //myMesh->myCellIdSmdsToVtk.clear();
+ myMesh->myCellIdVtkToSmds.clear();
+ myMin = myMax = 0;
+ SMDS_MeshIDFactory::Clear();