}
}
+ const bool deleted=true;
+
// Rm from sub-meshes
// Element should belong to only one sub-mesh
map<int,SMESHDS_SubMesh*>::iterator SubIt = theSubMeshes.begin();
{
bool removed = false;
if ( isNode )
- removed = (*SubIt).second->RemoveNode( static_cast<const SMDS_MeshNode*> (*elIt) );
+ removed = (*SubIt).second->RemoveNode( static_cast<const SMDS_MeshNode*> (*elIt), deleted );
else
- removed = (*SubIt).second->RemoveElement( *elIt );
+ removed = (*SubIt).second->RemoveElement( *elIt, deleted );
if (removed)
{
//=======================================================================
void SMESHDS_Mesh::RemoveNode(const SMDS_MeshNode * n)
{
+ if ( n->NbInverseElements() == 0 && !(hasConstructionEdges() || hasConstructionFaces()))
+ {
+ SMESHDS_SubMesh* subMesh=0;
+ map<int,SMESHDS_SubMesh*>::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<const SMDS_MeshElement *> removedElems;
// 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);
}
RemoveNode( static_cast<const SMDS_MeshNode*>( elt ));
return;
}
+ if (!hasConstructionEdges() && !hasConstructionFaces())
+ {
+ SMESHDS_SubMesh* subMesh=0;
+ map<int,SMESHDS_SubMesh*>::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<const SMDS_MeshElement *> removedElems;
// 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);
}
map<int,SMESHDS_SubMesh*>::iterator it =
myShapeIndexToSubMesh.find( aNode->GetPosition()->GetShapeId() );
if ( it != myShapeIndexToSubMesh.end() )
- it->second->RemoveNode( aNode );
+ it->second->RemoveNode( aNode, /*deleted=*/false );
}
}
map<int,SMESHDS_SubMesh*>::iterator it = myShapeIndexToSubMesh.find( Index );
if ( it != myShapeIndexToSubMesh.end() )
if ( elem->GetType() == SMDSAbs_Node )
- it->second->RemoveNode( static_cast<const SMDS_MeshNode* >( elem ));
+ it->second->RemoveNode( static_cast<const SMDS_MeshNode* >( elem ), /*deleted=*/false );
else
- it->second->RemoveElement( elem );
+ it->second->RemoveElement( elem, /*deleted=*/false );
}
//=======================================================================
//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;
}
//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;
}
// class MySetIterator
// =====================
-template<typename TSet> class MySetIterator: public SMDS_SetIterator<typename TSet::key_type,
- typename TSet::const_iterator >
+template<class ELEM, typename TSET> class MySetIterator:
+ public SMDS_SetIterator<ELEM, typename TSET::const_iterator >
{
- typedef SMDS_SetIterator<typename TSet::key_type, typename TSet::const_iterator > TFather;
+ typedef SMDS_SetIterator<ELEM, typename TSET::const_iterator > TFather;
public:
- MySetIterator(const TSet& s):TFather(s.begin(),s.end())
+ MySetIterator(const TSET& s):TFather(s.begin(),s.end())
{
}
};
{
public:
MyIterator (const set<const SMESHDS_SubMesh*>& 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++;
private:
bool myMore;
- const set<const SMESHDS_SubMesh*>& mySubMeshes;
- set<const SMESHDS_SubMesh*>::const_iterator mySubIt;
+ set<const SMESHDS_SubMesh*>::const_iterator mySubIt, mySubEnd;
boost::shared_ptr< SMDS_Iterator<VALUE> > myElemIt;
};
if ( IsComplexSubmesh() )
return SMDS_ElemIteratorPtr( new MyElemIterator( mySubMeshes ));
- return SMDS_ElemIteratorPtr(new MySetIterator<TElemSet>(myElements));
+ return SMDS_ElemIteratorPtr(new MySetIterator<const SMDS_MeshElement*,TElemSet>(myElements));
}
//=======================================================================
if ( IsComplexSubmesh() )
return SMDS_NodeIteratorPtr( new MyNodeIterator( mySubMeshes ));
- return SMDS_NodeIteratorPtr(new MySetIterator<TNodeSet>(myNodes));
+ return SMDS_NodeIteratorPtr(new MySetIterator<const SMDS_MeshNode*,TElemSet>(myNodes));
}
//=======================================================================
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 SMESHDS_SubMesh*>::const_iterator aSubIt = mySubMeshes.begin();
- for ( ; aSubIt != mySubMeshes.end(); aSubIt++ )
- if ( (*aSubIt)->Contains( ME ))
- return true;
- return false;
- }
+// if ( IsComplexSubmesh() )
+// {
+// set<const SMESHDS_SubMesh*>::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<const SMDS_MeshNode*>( ME );
- return ( myNodes.find( n ) != myNodes.end() );
- }
+ return ( myNodes.find( ME ) != myNodes.end() );
return ( myElements.find( ME ) != myElements.end() );
}
// 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 );
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<const SMDS_MeshElement*, TIDCompare > TElemSet;
- typedef std::set<const SMDS_MeshNode* , TIDCompare> TNodeSet;
- TElemSet myElements;
- TNodeSet myNodes;
+ TElemSet myElements, myNodes;
+
std::set<const SMESHDS_SubMesh*> mySubMeshes;
};
#endif