-// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
// SMESH SMESH : implementaion of SMESH idl descriptions
// File : SMESH_subMesh.cxx
*/
//=============================================================================
+const SMESHDS_SubMesh * SMESH_subMesh::GetSubMeshDS() const
+{
+ return ((SMESH_subMesh*) this )->GetSubMeshDS();
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
SMESHDS_SubMesh* SMESH_subMesh::CreateSubMeshDS()
{
if ( !GetSubMeshDS() ) {
{
insertDependence(exp.Current());
}
+ for (TopExp_Explorer exp(_subShape, TopAbs_VERTEX, TopAbs_EDGE); exp.More();exp.Next())
+ {
+ insertDependence(exp.Current());
+ }
break;
}
case TopAbs_COMPSOLID:
bool SMESH_subMesh::ComputeStateEngine(int event)
{
- _computeError.reset();
+ switch ( event ) {
+ case MODIF_ALGO_STATE:
+ case COMPUTE:
+ //case COMPUTE_CANCELED:
+ case CLEAN:
+ //case SUBMESH_COMPUTED:
+ //case SUBMESH_RESTORED:
+ //case SUBMESH_LOADED:
+ //case MESH_ENTITY_REMOVED:
+ //case CHECK_COMPUTE_STATE:
+ _computeError.reset(); break;
+ default:;
+ }
//MESSAGE("SMESH_subMesh::ComputeStateEngine");
//SCRUTE(_computeState);
else
ret = false;
}
+ // check if an error reported on any sub-shape
+ bool isComputeErrorSet = !checkComputeError( algo, ret, shape );
+ // check if anything was built
TopExp_Explorer subS(shape, _subShape.ShapeType());
- if (ret) // check if anything was built
+ if (ret)
{
for (; ret && subS.More(); subS.Next())
ret = _father->GetSubMesh( subS.Current() )->IsMeshComputed();
}
- bool isComputeErrorSet = !checkComputeError( algo, shape );
+ // Set _computeError
if (!ret && !isComputeErrorSet)
{
- // Set _computeError
for (subS.ReInit(); subS.More(); subS.Next())
{
SMESH_subMesh* sm = _father->GetSubMesh( subS.Current() );
break;
case COMPUTE: // nothing to do
break;
-#ifdef WITH_SMESH_CANCEL_COMPUTE
case COMPUTE_CANCELED:
{
algo = GetAlgo();
algo->CancelCompute();
}
break;
-#endif
case CLEAN:
cleanDependants(); // submeshes dependent on me should be cleaned as well
removeSubMeshElementsAndNodes();
*/
//=======================================================================
-bool SMESH_subMesh::checkComputeError(SMESH_Algo* theAlgo, const TopoDS_Shape& theShape)
+bool SMESH_subMesh::checkComputeError(SMESH_Algo* theAlgo,
+ const bool theComputeOK,
+ const TopoDS_Shape& theShape)
{
bool noErrors = true;
{
SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(false,false);
while ( smIt->more() )
- if ( !smIt->next()->checkComputeError( theAlgo ))
+ if ( !smIt->next()->checkComputeError( theAlgo, theComputeOK ))
noErrors = false;
}
for (TopoDS_Iterator subIt( theShape ); subIt.More(); subIt.Next()) {
SMESH_subMesh* sm = _father->GetSubMesh( subIt.Value() );
if ( sm != this ) {
- if ( !sm->checkComputeError( theAlgo, sm->GetSubShape() ))
+ if ( !sm->checkComputeError( theAlgo, theComputeOK, sm->GetSubShape() ))
noErrors = false;
updateDependantsState( SUBMESH_COMPUTED ); // send event SUBMESH_COMPUTED
}
}
}
{
- // Check my state
+
+ // Set my _computeState
+
if ( !_computeError || _computeError->IsOK() )
{
// no error description is set to this sub-mesh, check if any mesh is computed
_computeState = IsMeshComputed() ? COMPUTE_OK : FAILED_TO_COMPUTE;
+ if ( _computeState != COMPUTE_OK )
+ {
+ if ( _subShape.ShapeType() == TopAbs_EDGE &&
+ BRep_Tool::Degenerated( TopoDS::Edge( _subShape )) )
+ _computeState = COMPUTE_OK;
+ else if ( theComputeOK )
+ _computeError = SMESH_ComputeError::New(COMPERR_NO_MESH_ON_SHAPE,"",theAlgo);
+ }
}
- else
+
+ if ( _computeError && !_computeError->IsOK() )
{
if ( !_computeError->myAlgo )
_computeError->myAlgo = theAlgo;
//purpose :
//=======================================================================
-void SMESH_subMesh::ComputeSubMeshStateEngine(int event)
+void SMESH_subMesh::ComputeSubMeshStateEngine(int event, const bool includeSelf)
{
- SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(false,false);
+ SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(includeSelf,false);
while ( smIt->more() )
smIt->next()->ComputeStateEngine(event);
}
*/
//================================================================================
-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 );
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 );
+ break;
+ }
_eventListeners.insert( make_pair( listener, data ));
+ }
}
//================================================================================
return 0;
}
+//================================================================================
+/*!
+ * \brief Return an event listener data
+ * \param listenerName - the listener name
+ * \retval EventListenerData* - found data, maybe NULL
+ */
+//================================================================================
+
+EventListenerData* SMESH_subMesh::GetEventListenerData(const string& listenerName) const
+{
+ map< EventListener*, EventListenerData* >::const_iterator l_d = _eventListeners.begin();
+ for ( ; l_d != _eventListeners.end(); ++l_d )
+ if ( listenerName == l_d->first->GetName() )
+ return l_d->second;
+ return 0;
+}
+
//================================================================================
/*!
* \brief Notify stored event listeners on the occured 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
}
}
}
map< EventListener*, EventListenerData* >::iterator l_d =
_eventListeners.find( listener );
if ( l_d != _eventListeners.end() ) {
- if ( l_d->first && l_d->first->IsDeletable() ) delete l_d->first;
- if ( l_d->second && l_d->second->IsDeletable() ) delete l_d->second;
+ if ( l_d->first && l_d->first->IsDeletable() )
+ {
+ l_d->first->BeforeDelete( this, l_d->second );
+ delete l_d->first;
+ }
+ if ( l_d->second && l_d->second->IsDeletable() )
+ {
+ delete l_d->second;
+ }
_eventListeners.erase( l_d );
}
}