]> SALOME platform Git repositories - modules/smesh.git/commitdiff
Salome HOME
Implement Cancel Compute (end)
authoradam <adam>
Thu, 17 Mar 2011 09:53:14 +0000 (09:53 +0000)
committeradam <adam>
Thu, 17 Mar 2011 09:53:14 +0000 (09:53 +0000)
src/SMESH/SMESH_Algo.cxx
src/SMESH/SMESH_Algo.hxx
src/SMESH/SMESH_Gen.cxx
src/SMESH/SMESH_Gen.hxx
src/SMESH/SMESH_subMesh.cxx
src/SMESH/SMESH_subMesh.hxx

index 953bf9e2ba7f82b9a7b0fef1d91551e64976c2f9..959f7df3bea9fed1ca3f8a3d7c94172e030babdb 100644 (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 )
index 83b34c3a9d74c1a05cf3bcb050730581114b81ba..3182db233ec5970397eb3df52916211dc4e5d542 100644 (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
index 2e79fb278b6c6b63b05e59ad8613da60425905a8..360325e81b86a45d722ac68156e54074592975df 100644 (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
index a9af382ef5061cc22a8f69985af2874ea61b08f4..311fe4aad4d8581942fcf1c63fc48d04f9e38927 100644 (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
index d15405195f40f53da4ee50498ae6cf4512ac9af6..e3ad2236aae1e31a68607570b8e2967395fa4bbe 100644 (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();
index 54ffcdac0450ce48ebe90dce6ab27b06d47a4c50..5762ef3c1600a76f0704acca0b43d2ee3c53a9ab 100644 (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
     };