From b648205fec58ba8a9cb05ede0ece6d5b41cf1498 Mon Sep 17 00:00:00 2001 From: eap Date: Mon, 15 Oct 2012 13:15:55 +0000 Subject: [PATCH] 0021543: EDF 1978 SMESH: Viscous layer for 2D meshes 1) Fix notifyListenersOnEvent() for the case if a listener is deleted 2) in setEventListener(), use a listener name to find an existing listener --- src/SMESH/SMESH_subMesh.cxx | 42 ++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/src/SMESH/SMESH_subMesh.cxx b/src/SMESH/SMESH_subMesh.cxx index 18fa26f8b..a2a64ef95 100644 --- a/src/SMESH/SMESH_subMesh.cxx +++ b/src/SMESH/SMESH_subMesh.cxx @@ -149,6 +149,17 @@ SMESHDS_SubMesh * SMESH_subMesh::GetSubMeshDS() */ //============================================================================= +const SMESHDS_SubMesh * SMESH_subMesh::GetSubMeshDS() const +{ + return ((SMESH_subMesh*) this )->GetSubMeshDS(); +} + +//============================================================================= +/*! + * + */ +//============================================================================= + SMESHDS_SubMesh* SMESH_subMesh::CreateSubMeshDS() { if ( !GetSubMeshDS() ) { @@ -2078,7 +2089,8 @@ void SMESH_subMesh::SetEventListener(EventListener* listener, */ //================================================================================ -void SMESH_subMesh::setEventListener(EventListener* listener, EventListenerData* data) +void SMESH_subMesh::setEventListener(EventListener* listener, + EventListenerData* data) { map< EventListener*, EventListenerData* >::iterator l_d = _eventListeners.find( listener ); @@ -2088,8 +2100,20 @@ void SMESH_subMesh::setEventListener(EventListener* listener, EventListenerData* delete curData; l_d->second = data; } - else + else + { + for ( l_d = _eventListeners.begin(); l_d != _eventListeners.end(); ++l_d ) + if ( listener->GetName() == l_d->first->GetName() ) + { + EventListenerData* curData = l_d->second; + if ( curData && curData != data && curData->IsDeletable() ) + delete curData; + if ( l_d->first->IsDeletable() ) + delete l_d->first; + _eventListeners.erase( l_d ); + } _eventListeners.insert( make_pair( listener, data )); + } } //================================================================================ @@ -2140,16 +2164,18 @@ void SMESH_subMesh::notifyListenersOnEvent( const int event, SMESH_Hypothesis* hyp) { map< EventListener*, EventListenerData* >::iterator l_d = _eventListeners.begin(); - for ( ; l_d != _eventListeners.end(); ++l_d ) + for ( ; l_d != _eventListeners.end(); ) { - std::pair< EventListener*, EventListenerData* > li_da = *l_d; /* copy to enable removal - of a listener from - _eventListeners by - its ProcessEvent() */ + std::pair< EventListener*, EventListenerData* > li_da = *l_d++; /* copy to enable removal + of a listener from + _eventListeners by + its ProcessEvent() */ if ( li_da.first->myBusySM.insert( this ).second ) { + const size_t nbListenersBefore = _eventListeners.size(); li_da.first->ProcessEvent( event, eventType, this, li_da.second, hyp ); - li_da.first->myBusySM.erase( this ); + if ( nbListenersBefore == _eventListeners.size() ) + li_da.first->myBusySM.erase( this ); // a listener hopefully not removed } } } -- 2.39.2