+///////////////////////////////////////////////////////////////////////////////
+///@param elem The element to delete
+///@param removenodes if true remaining nodes will be removed
+///////////////////////////////////////////////////////////////////////////////
+void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem,
+ const bool removenodes)
+{
+ list<const SMDS_MeshElement *> removedElems;
+ list<const SMDS_MeshElement *> removedNodes;
+ RemoveElement( elem, removedElems, removedNodes, removenodes );
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///@param elem The element to delete
+///@param removedElems contains all removed elements
+///@param removedNodes contains all removed nodes
+///@param removenodes if true remaining nodes will be removed
+///////////////////////////////////////////////////////////////////////////////
+void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem,
+ list<const SMDS_MeshElement *>& removedElems,
+ list<const SMDS_MeshElement *>& removedNodes,
+ bool removenodes)
+{
+ // get finite elements built on elem
+ set<const SMDS_MeshElement*> * s1;
+ if (!hasConstructionEdges() && elem->GetType() == SMDSAbs_Edge ||
+ !hasConstructionFaces() && elem->GetType() == SMDSAbs_Face ||
+ elem->GetType() == SMDSAbs_Volume)
+ {
+ s1 = new set<const SMDS_MeshElement*>();
+ s1->insert(elem);
+ }
+ else
+ s1 = getFinitElements(elem);
+
+ // get exclusive nodes (which would become free afterwards)
+ set<const SMDS_MeshElement*> * s2;
+ if (elem->GetType() == SMDSAbs_Node) // a node is removed
+ {
+ // do not remove nodes except elem
+ s2 = new set<const SMDS_MeshElement*>();
+ s2->insert(elem);
+ removenodes = true;
+ }
+ else
+ s2 = getExclusiveNodes(*s1);
+
+ // form the set of finite and construction elements to remove
+ set<const SMDS_MeshElement*> s3;
+ set<const SMDS_MeshElement*>::iterator it=s1->begin();
+ while(it!=s1->end())
+ {
+ addChildrenWithNodes(s3, *it ,*s2);
+ s3.insert(*it);
+ it++;
+ }
+ if(elem->GetType()!=SMDSAbs_Node) s3.insert(elem);
+
+ // remove finite and construction elements
+ it=s3.begin();
+ while(it!=s3.end())
+ {
+ // Remove element from <InverseElements> of its nodes
+ SMDS_ElemIteratorPtr itn=(*it)->nodesIterator();
+ while(itn->more())
+ {
+ SMDS_MeshNode * n = static_cast<SMDS_MeshNode *>
+ (const_cast<SMDS_MeshElement *>(itn->next()));
+ n->RemoveInverseElement( (*it) );
+ }
+
+ switch((*it)->GetType())
+ {
+ case SMDSAbs_Node:
+ MESSAGE("Internal Error: This should not happen");
+ break;
+ case SMDSAbs_Edge:
+ myEdges.Remove(static_cast<SMDS_MeshEdge*>
+ (const_cast<SMDS_MeshElement*>(*it)));
+ break;
+ case SMDSAbs_Face:
+ myFaces.Remove(static_cast<SMDS_MeshFace*>
+ (const_cast<SMDS_MeshElement*>(*it)));
+ break;
+ case SMDSAbs_Volume:
+ myVolumes.Remove(static_cast<SMDS_MeshVolume*>
+ (const_cast<SMDS_MeshElement*>(*it)));
+ break;
+ }
+ //MESSAGE( "SMDS: RM elem " << (*it)->GetID() );
+ removedElems.push_back( (*it) );
+ myElementIDFactory->ReleaseID((*it)->GetID());
+ delete (*it);
+ it++;
+ }
+
+ // remove exclusive (free) nodes
+ if(removenodes)
+ {
+ it=s2->begin();
+ while(it!=s2->end())
+ {
+ //MESSAGE( "SMDS: RM node " << (*it)->GetID() );
+ myNodes.Remove(static_cast<SMDS_MeshNode*>
+ (const_cast<SMDS_MeshElement*>(*it)));
+ myNodeIDFactory->ReleaseID((*it)->GetID());
+ removedNodes.push_back( (*it) );
+ delete *it;
+ it++;
+ }
+ }
+
+ delete s2;
+ delete s1;
+}
+
+/*!
+ * Checks if the element is present in mesh.
+ * Useful to determine dead pointers.
+ */
+bool SMDS_Mesh::Contains (const SMDS_MeshElement* elem) const
+{
+ // we should not imply on validity of *elem, so iterate on containers
+ // of all types in the hope of finding <elem> somewhere there
+ SMDS_NodeIteratorPtr itn = nodesIterator();
+ while (itn->more())
+ if (elem == itn->next())
+ return true;
+ SMDS_EdgeIteratorPtr ite = edgesIterator();
+ while (ite->more())
+ if (elem == ite->next())
+ return true;
+ SMDS_FaceIteratorPtr itf = facesIterator();
+ while (itf->more())
+ if (elem == itf->next())
+ return true;
+ SMDS_VolumeIteratorPtr itv = volumesIterator();
+ while (itv->more())
+ if (elem == itv->next())
+ return true;
+ return false;
+}
+
+//=======================================================================
+//function : MaxNodeID
+//purpose :
+//=======================================================================
+
+int SMDS_Mesh::MaxNodeID() const
+{
+ return myNodeIDFactory->GetMaxID();
+}
+
+//=======================================================================
+//function : MinNodeID
+//purpose :
+//=======================================================================
+
+int SMDS_Mesh::MinNodeID() const
+{
+ return myNodeIDFactory->GetMinID();
+}
+
+//=======================================================================
+//function : MaxElementID
+//purpose :
+//=======================================================================
+
+int SMDS_Mesh::MaxElementID() const
+{
+ return myElementIDFactory->GetMaxID();
+}
+
+//=======================================================================
+//function : MinElementID
+//purpose :
+//=======================================================================
+
+int SMDS_Mesh::MinElementID() const
+{
+ return myElementIDFactory->GetMinID();
+}
+
+//=======================================================================
+//function : Renumber
+//purpose : Renumber all nodes or elements.
+//=======================================================================
+
+void SMDS_Mesh::Renumber (const bool isNodes, const int startID, const int deltaID)
+{
+ if ( deltaID == 0 )
+ return;
+
+ SMDS_MeshElementIDFactory * idFactory =
+ isNodes ? myNodeIDFactory : myElementIDFactory;
+
+ // get existing elements in the order of ID increasing
+ map<int,SMDS_MeshElement*> elemMap;
+ SMDS_ElemIteratorPtr idElemIt = idFactory->elementsIterator();
+ while ( idElemIt->more() ) {
+ SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(idElemIt->next());
+ int id = elem->GetID();
+ elemMap.insert(map<int,SMDS_MeshElement*>::value_type(id, elem));
+ }
+ // release their ids
+ map<int,SMDS_MeshElement*>::iterator elemIt = elemMap.begin();
+ for ( ; elemIt != elemMap.end(); elemIt++ )
+ {
+ int id = (*elemIt).first;
+ idFactory->ReleaseID( id );
+ }
+ // set new IDs
+ int ID = startID;
+ elemIt = elemMap.begin();
+ for ( ; elemIt != elemMap.end(); elemIt++ )
+ {
+ idFactory->BindID( ID, (*elemIt).second );
+ ID += deltaID;
+ }
+}