diff --git a/src/SMESHDS/SMESHDS_Mesh.cxx b/src/SMESHDS/SMESHDS_Mesh.cxx index a4c1668a6..61db43a74 100644 --- a/src/SMESHDS/SMESHDS_Mesh.cxx +++ b/src/SMESHDS/SMESHDS_Mesh.cxx @@ -652,6 +652,8 @@ static void removeFromContainers (map& theSubMeshes, } } + const bool deleted=true; + // Rm from sub-meshes // Element should belong to only one sub-mesh map::iterator SubIt = theSubMeshes.begin(); @@ -665,9 +667,9 @@ static void removeFromContainers (map& theSubMeshes, { bool removed = false; if ( isNode ) - removed = (*SubIt).second->RemoveNode( static_cast (*elIt) ); + removed = (*SubIt).second->RemoveNode( static_cast (*elIt), deleted ); else - removed = (*SubIt).second->RemoveElement( *elIt ); + removed = (*SubIt).second->RemoveElement( *elIt, deleted ); if (removed) { @@ -689,6 +691,23 @@ static void removeFromContainers (map& theSubMeshes, //======================================================================= void SMESHDS_Mesh::RemoveNode(const SMDS_MeshNode * n) { + if ( n->NbInverseElements() == 0 && !(hasConstructionEdges() || hasConstructionFaces())) + { + SMESHDS_SubMesh* subMesh=0; + map::iterator SubIt = + myShapeIndexToSubMesh.find( n->GetPosition()->GetShapeId() ); + if ( SubIt != myShapeIndexToSubMesh.end() ) + subMesh = SubIt->second; + else + SubIt = myShapeIndexToSubMesh.begin(); + for ( ; !subMesh && SubIt != myShapeIndexToSubMesh.end(); SubIt++ ) + if ( SubIt->second->Contains( n )) + subMesh = SubIt->second; + + RemoveFreeNode( n, subMesh, true); + return; + } + myScript->RemoveNode(n->GetID()); list removedElems; @@ -724,7 +743,7 @@ void SMESHDS_Mesh::RemoveFreeNode(const SMDS_MeshNode * n, // Rm from sub-mesh // Node should belong to only one sub-mesh if( subMesh ) - subMesh->RemoveNode(n); + subMesh->RemoveNode(n,/*deleted=*/false); SMDS_Mesh::RemoveFreeElement(n); } @@ -740,7 +759,18 @@ void SMESHDS_Mesh::RemoveElement(const SMDS_MeshElement * elt) RemoveNode( static_cast( elt )); return; } + if (!hasConstructionEdges() && !hasConstructionFaces()) + { + SMESHDS_SubMesh* subMesh=0; + map::iterator SubIt = myShapeIndexToSubMesh.begin(); + for ( ; !subMesh && SubIt != myShapeIndexToSubMesh.end(); SubIt++ ) + if ( SubIt->second->Contains( elt )) + subMesh = SubIt->second; + RemoveFreeElement( elt, subMesh, true); + return; + } + myScript->RemoveElement(elt->GetID()); list removedElems; @@ -784,7 +814,7 @@ void SMESHDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elt, // Rm from sub-mesh // Element should belong to only one sub-mesh if( subMesh ) - subMesh->RemoveElement(elt); + subMesh->RemoveElement(elt, /*deleted=*/false); SMDS_Mesh::RemoveFreeElement(elt); } @@ -965,7 +995,7 @@ void SMESHDS_Mesh::UnSetNodeOnShape(const SMDS_MeshNode* aNode) map::iterator it = myShapeIndexToSubMesh.find( aNode->GetPosition()->GetShapeId() ); if ( it != myShapeIndexToSubMesh.end() ) - it->second->RemoveNode( aNode ); + it->second->RemoveNode( aNode, /*deleted=*/false ); } } @@ -991,9 +1021,9 @@ void SMESHDS_Mesh::UnSetMeshElementOnShape(const SMDS_MeshElement * elem, map::iterator it = myShapeIndexToSubMesh.find( Index ); if ( it != myShapeIndexToSubMesh.end() ) if ( elem->GetType() == SMDSAbs_Node ) - it->second->RemoveNode( static_cast( elem )); + it->second->RemoveNode( static_cast( elem ), /*deleted=*/false ); else - it->second->RemoveElement( elem ); + it->second->RemoveElement( elem, /*deleted=*/false ); } //======================================================================= diff --git a/src/SMESHDS/SMESHDS_SubMesh.cxx b/src/SMESHDS/SMESHDS_SubMesh.cxx index 360d1161f..6d9ba0835 100644 --- a/src/SMESHDS/SMESHDS_SubMesh.cxx +++ b/src/SMESHDS/SMESHDS_SubMesh.cxx @@ -46,10 +46,20 @@ void SMESHDS_SubMesh::AddElement(const SMDS_MeshElement * ME) //function : RemoveElement //purpose : //======================================================================= -bool SMESHDS_SubMesh::RemoveElement(const SMDS_MeshElement * ME) +bool SMESHDS_SubMesh::RemoveElement(const SMDS_MeshElement * ME, bool isElemDeleted) { - if ( !IsComplexSubmesh() && NbElements() ) - return myElements.erase(ME); + if ( !IsComplexSubmesh() && NbElements() ) { + + if (!isElemDeleted) // alive element has valid ID and can be found + return myElements.erase(ME); + + TElemSet::iterator e = myElements.begin(), eEnd = myElements.end(); + for ( ; e != eEnd; ++e ) + if ( ME == *e ) { + myElements.erase( e ); + return true; + } + } return false; } @@ -69,10 +79,20 @@ void SMESHDS_SubMesh::AddNode(const SMDS_MeshNode * N) //purpose : //======================================================================= -bool SMESHDS_SubMesh::RemoveNode(const SMDS_MeshNode * N) +bool SMESHDS_SubMesh::RemoveNode(const SMDS_MeshNode * N, bool isNodeDeleted) { - if ( !IsComplexSubmesh() && NbNodes() ) - return myNodes.erase(N); + if ( !IsComplexSubmesh() && NbNodes() ) { + + if (!isNodeDeleted) // alive node has valid ID and can be found + return myNodes.erase(N); + + TElemSet::iterator e = myNodes.begin(), eEnd = myNodes.end(); + for ( ; e != eEnd; ++e ) + if ( N == *e ) { + myNodes.erase( e ); + return true; + } + } return false; } @@ -116,12 +136,12 @@ int SMESHDS_SubMesh::NbNodes() const // class MySetIterator // ===================== -template class MySetIterator: public SMDS_SetIterator +template class MySetIterator: + public SMDS_SetIterator { - typedef SMDS_SetIterator TFather; + typedef SMDS_SetIterator TFather; public: - MySetIterator(const TSet& s):TFather(s.begin(),s.end()) + MySetIterator(const TSET& s):TFather(s.begin(),s.end()) { } }; @@ -134,12 +154,11 @@ template class MyIterator : public SMDS_Iterator { public: MyIterator (const set& theSubMeshes) - : mySubMeshes( theSubMeshes ), mySubIt( theSubMeshes.begin() ), myMore(false) + : mySubIt( theSubMeshes.begin() ), mySubEnd( theSubMeshes.end() ), myMore(false) {} bool more() { - while (( !myElemIt.get() || !myElemIt->more() ) && - mySubIt != mySubMeshes.end()) + while (( !myElemIt.get() || !myElemIt->more() ) && mySubIt != mySubEnd) { myElemIt = getElements(*mySubIt); mySubIt++; @@ -160,8 +179,7 @@ template class MyIterator : public SMDS_Iterator private: bool myMore; - const set& mySubMeshes; - set::const_iterator mySubIt; + set::const_iterator mySubIt, mySubEnd; boost::shared_ptr< SMDS_Iterator > myElemIt; }; @@ -201,7 +219,7 @@ SMDS_ElemIteratorPtr SMESHDS_SubMesh::GetElements() const if ( IsComplexSubmesh() ) return SMDS_ElemIteratorPtr( new MyElemIterator( mySubMeshes )); - return SMDS_ElemIteratorPtr(new MySetIterator(myElements)); + return SMDS_ElemIteratorPtr(new MySetIterator(myElements)); } //======================================================================= @@ -214,7 +232,7 @@ SMDS_NodeIteratorPtr SMESHDS_SubMesh::GetNodes() const if ( IsComplexSubmesh() ) return SMDS_NodeIteratorPtr( new MyNodeIterator( mySubMeshes )); - return SMDS_NodeIteratorPtr(new MySetIterator(myNodes)); + return SMDS_NodeIteratorPtr(new MySetIterator(myNodes)); } //======================================================================= @@ -225,23 +243,20 @@ SMDS_NodeIteratorPtr SMESHDS_SubMesh::GetNodes() const bool SMESHDS_SubMesh::Contains(const SMDS_MeshElement * ME) const { // DO NOT TRY TO FIND A REMOVED ELEMENT !! - if ( !ME ) + if ( IsComplexSubmesh() || !ME ) return false; - if ( IsComplexSubmesh() ) - { - set::const_iterator aSubIt = mySubMeshes.begin(); - for ( ; aSubIt != mySubMeshes.end(); aSubIt++ ) - if ( (*aSubIt)->Contains( ME )) - return true; - return false; - } +// if ( IsComplexSubmesh() ) +// { +// set::const_iterator aSubIt = mySubMeshes.begin(); +// for ( ; aSubIt != mySubMeshes.end(); aSubIt++ ) +// if ( (*aSubIt)->Contains( ME )) +// return true; +// return false; +// } if ( ME->GetType() == SMDSAbs_Node ) - { - const SMDS_MeshNode* n = static_cast( ME ); - return ( myNodes.find( n ) != myNodes.end() ); - } + return ( myNodes.find( ME ) != myNodes.end() ); return ( myElements.find( ME ) != myElements.end() ); } diff --git a/src/SMESHDS/SMESHDS_SubMesh.hxx b/src/SMESHDS/SMESHDS_SubMesh.hxx index f9ce541fa..839f7eabe 100644 --- a/src/SMESHDS/SMESHDS_SubMesh.hxx +++ b/src/SMESHDS/SMESHDS_SubMesh.hxx @@ -43,9 +43,9 @@ class SMESHDS_EXPORT SMESHDS_SubMesh // if !IsComplexSubmesh() void AddElement(const SMDS_MeshElement * ME); - bool RemoveElement(const SMDS_MeshElement * ME); // ret true if ME was in + bool RemoveElement(const SMDS_MeshElement * ME, bool isElemDeleted); // ret true if ME was in void AddNode(const SMDS_MeshNode * ME); - bool RemoveNode(const SMDS_MeshNode * ME); // ret true if ME was in + bool RemoveNode(const SMDS_MeshNode * ME, bool isNodeDeleted); // ret true if ME was in // if IsComplexSubmesh() void AddSubMesh( const SMESHDS_SubMesh* theSubMesh ); @@ -65,14 +65,14 @@ class SMESHDS_EXPORT SMESHDS_SubMesh void Clear(); private: + struct TIDCompare { // to have nodes and elements sorted by ID bool operator () (const SMDS_MeshElement* e1, const SMDS_MeshElement* e2) const { return e1->GetID() < e2->GetID(); } }; typedef std::set TElemSet; - typedef std::set TNodeSet; - TElemSet myElements; - TNodeSet myNodes; + TElemSet myElements, myNodes; + std::set mySubMeshes; }; #endif