From: adam Date: Thu, 17 Mar 2011 09:53:14 +0000 (+0000) Subject: Implement Cancel Compute (end) X-Git-Tag: Start_BR_19998_21191~18 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c4bd4ff43b510056ee6a6b0ffdf8693c4adb1be5;p=modules%2Fsmesh.git Implement Cancel Compute (end) --- diff --git a/src/SMESH/SMESH_Algo.cxx b/src/SMESH/SMESH_Algo.cxx index 953bf9e2b..959f7df3b 100644 --- a/src/SMESH/SMESH_Algo.cxx +++ b/src/SMESH/SMESH_Algo.cxx @@ -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 ) diff --git a/src/SMESH/SMESH_Algo.hxx b/src/SMESH/SMESH_Algo.hxx index 83b34c3a9..3182db233 100644 --- a/src/SMESH/SMESH_Algo.hxx +++ b/src/SMESH/SMESH_Algo.hxx @@ -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 diff --git a/src/SMESH/SMESH_Gen.cxx b/src/SMESH/SMESH_Gen.cxx index 2e79fb278..360325e81 100644 --- a/src/SMESH/SMESH_Gen.cxx +++ b/src/SMESH/SMESH_Gen.cxx @@ -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 diff --git a/src/SMESH/SMESH_Gen.hxx b/src/SMESH/SMESH_Gen.hxx index a9af382ef..311fe4aad 100644 --- a/src/SMESH/SMESH_Gen.hxx +++ b/src/SMESH/SMESH_Gen.hxx @@ -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 diff --git a/src/SMESH/SMESH_subMesh.cxx b/src/SMESH/SMESH_subMesh.cxx index d15405195..e3ad2236a 100644 --- a/src/SMESH/SMESH_subMesh.cxx +++ b/src/SMESH/SMESH_subMesh.cxx @@ -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(); diff --git a/src/SMESH/SMESH_subMesh.hxx b/src/SMESH/SMESH_subMesh.hxx index 54ffcdac0..5762ef3c1 100644 --- a/src/SMESH/SMESH_subMesh.hxx +++ b/src/SMESH/SMESH_subMesh.hxx @@ -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 };