Implement Cancel Compute (end)

This commit is contained in:
adam 2011-03-17 09:53:14 +00:00
parent 911977bc89
commit c4bd4ff43b
6 changed files with 103 additions and 0 deletions

View File

@ -595,6 +595,12 @@ bool SMESH_Algo::Compute(SMESH_Mesh & /*aMesh*/, SMESH_MesherHelper* /*aHelper*/
return error( COMPERR_BAD_INPUT_MESH, "Mesh built on shape expected");
}
#ifdef WITH_SMESH_CANCEL_COMPUTE
void SMESH_Algo::CancelCompute()
{
}
#endif
//================================================================================
/*!
* \brief store error and comment and then return ( error == COMPERR_OK )

View File

@ -134,6 +134,10 @@ public:
*/
virtual bool Compute(SMESH_Mesh & aMesh, SMESH_MesherHelper* aHelper);
#ifdef WITH_SMESH_CANCEL_COMPUTE
virtual void CancelCompute();
#endif
/*!
* \brief evaluates size of prospective mesh on a shape
* \param aMesh - the mesh

View File

@ -62,6 +62,10 @@ SMESH_Gen::SMESH_Gen()
SMDS_Mesh::_meshList.clear();
MESSAGE(SMDS_Mesh::_meshList.size());
_counters = new counters(100);
#ifdef WITH_SMESH_CANCEL_COMPUTE
_compute_canceled = false;
_sm_current = NULL;
#endif
}
//=============================================================================
@ -151,7 +155,17 @@ bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
}
if (smToCompute->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
{
#ifdef WITH_SMESH_CANCEL_COMPUTE
if (_compute_canceled)
return false;
_sm_current = smToCompute;
#endif
smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
#ifdef WITH_SMESH_CANCEL_COMPUTE
_sm_current = NULL;
#endif
}
// we check all the submeshes here and detect if any of them failed to compute
if (smToCompute->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE)
@ -192,7 +206,15 @@ bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
smWithAlgoSupportingSubmeshes.push_front( smToCompute );
else
{
#ifdef WITH_SMESH_CANCEL_COMPUTE
if (_compute_canceled)
return false;
_sm_current = smToCompute;
#endif
smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
#ifdef WITH_SMESH_CANCEL_COMPUTE
_sm_current = NULL;
#endif
if ( aShapesId )
aShapesId->insert( smToCompute->GetId() );
}
@ -262,7 +284,15 @@ bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
if ( aShapesId && GetShapeDim( aShType ) > (int)aDim )
continue;
#ifdef WITH_SMESH_CANCEL_COMPUTE
if (_compute_canceled)
return false;
_sm_current = sm;
#endif
sm->ComputeStateEngine( SMESH_subMesh::COMPUTE );
#ifdef WITH_SMESH_CANCEL_COMPUTE
_sm_current = NULL;
#endif
if ( aShapesId )
aShapesId->insert( sm->GetId() );
}
@ -298,6 +328,34 @@ bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
}
#ifdef WITH_SMESH_CANCEL_COMPUTE
//=============================================================================
/*!
* Prepare Compute a mesh
*/
//=============================================================================
void SMESH_Gen::PrepareCompute(SMESH_Mesh & aMesh,
const TopoDS_Shape & aShape)
{
_compute_canceled = false;
_sm_current = NULL;
}
//=============================================================================
/*!
* Cancel Compute a mesh
*/
//=============================================================================
void SMESH_Gen::CancelCompute(SMESH_Mesh & aMesh,
const TopoDS_Shape & aShape)
{
_compute_canceled = true;
if(_sm_current)
{
_sm_current->ComputeStateEngine( SMESH_subMesh::COMPUTE_CANCELED );
}
}
#endif
//=============================================================================
/*!
* Evaluate a mesh

View File

@ -83,6 +83,13 @@ public:
const ::MeshDimension aDim=::MeshDim_3D,
TSetOfInt* aShapesId=0);
#ifdef WITH_SMESH_CANCEL_COMPUTE
void PrepareCompute(::SMESH_Mesh & aMesh,
const TopoDS_Shape & aShape);
void CancelCompute(::SMESH_Mesh & aMesh,
const TopoDS_Shape & aShape);
#endif
/*!
* \brief evaluates size of prospective mesh on a shape
* \param aMesh - the mesh
@ -162,6 +169,11 @@ private:
// default of segments
int _nbSegments;
counters *_counters;
#ifdef WITH_SMESH_CANCEL_COMPUTE
volatile bool _compute_canceled;
SMESH_subMesh* _sm_current;
#endif
};
#endif

View File

@ -1288,6 +1288,10 @@ bool SMESH_subMesh::ComputeStateEngine(int event)
break;
case COMPUTE: // nothing to do
break;
#ifdef WITH_SMESH_CANCEL_COMPUTE
case COMPUTE_CANCELED: // nothing to do
break;
#endif
case CLEAN:
CleanDependants();
RemoveSubMeshElementsAndNodes();
@ -1459,6 +1463,10 @@ bool SMESH_subMesh::ComputeStateEngine(int event)
UpdateDependantsState( SUBMESH_COMPUTED ); // send event SUBMESH_COMPUTED
}
break;
#ifdef WITH_SMESH_CANCEL_COMPUTE
case COMPUTE_CANCELED: // nothing to do
break;
#endif
case CLEAN:
CleanDependants();
RemoveSubMeshElementsAndNodes();
@ -1508,6 +1516,10 @@ bool SMESH_subMesh::ComputeStateEngine(int event)
break;
case COMPUTE: // nothing to do
break;
#ifdef WITH_SMESH_CANCEL_COMPUTE
case COMPUTE_CANCELED: // nothing to do
break;
#endif
case CLEAN:
CleanDependants(); // clean sub-meshes, dependant on this one, with event CLEAN
RemoveSubMeshElementsAndNodes();
@ -1560,6 +1572,14 @@ bool SMESH_subMesh::ComputeStateEngine(int event)
break;
case COMPUTE: // nothing to do
break;
#ifdef WITH_SMESH_CANCEL_COMPUTE
case COMPUTE_CANCELED:
{
algo = gen->GetAlgo((*_father), _subShape);
algo->CancelCompute();
}
break;
#endif
case CLEAN:
CleanDependants(); // submeshes dependent on me should be cleaned as well
RemoveSubMeshElementsAndNodes();

View File

@ -106,6 +106,9 @@ class SMESH_EXPORT SMESH_subMesh
enum compute_event
{
MODIF_ALGO_STATE, COMPUTE,
#ifdef WITH_SMESH_CANCEL_COMPUTE
COMPUTE_CANCELED,
#endif
CLEAN, SUBMESH_COMPUTED, SUBMESH_RESTORED,
MESH_ENTITY_REMOVED, CHECK_COMPUTE_STATE
};