Salome HOME
Implement Cancel Compute (end)
[modules/smesh.git] / src / SMESH / SMESH_Gen.cxx
index 08c1dd868eccbee9de17cc3d60bbf5efe6481610..360325e81b86a45d722ac68156e54074592975df 100644 (file)
@@ -1,4 +1,4 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+//  Copyright (C) 2007-2010  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
 //
 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 //  SMESH SMESH : implementaion of SMESH idl descriptions
 //  File   : SMESH_Gen.cxx
 //  Author : Paul RASCLE, EDF
 //  Module : SMESH
-
+//
+#define CHRONODEF
 #include "SMESH_Gen.hxx"
 #include "SMESH_subMesh.hxx"
 #include "SMESH_HypoFilter.hxx"
 #include "SMESHDS_Document.hxx"
 #include "SMDS_MeshElement.hxx"
 #include "SMDS_MeshNode.hxx"
+#include "SMDS_Mesh.hxx"
 
 #include "utilities.h"
 #include "OpUtil.hxx"
@@ -40,6 +43,8 @@
 #include <TopTools_ListOfShape.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
 
+#include "memoire.h"
+
 using namespace std;
 
 //=============================================================================
@@ -50,10 +55,17 @@ using namespace std;
 
 SMESH_Gen::SMESH_Gen()
 {
-  MESSAGE("SMESH_Gen::SMESH_Gen");
-  _localId = 0;
-  _hypId = 0;
-  _segmentation = _nbSegments = 10;
+        MESSAGE("SMESH_Gen::SMESH_Gen");
+        _localId = 0;
+        _hypId = 0;
+        _segmentation = _nbSegments = 10;
+        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
 }
 
 //=============================================================================
@@ -107,6 +119,7 @@ bool SMESH_Gen::Compute(SMESH_Mesh &          aMesh,
                         TSetOfInt*            aShapesId)
 {
   MESSAGE("SMESH_Gen::Compute");
+  MEMOSTAT;
 
   bool ret = true;
 
@@ -142,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)
@@ -150,6 +173,7 @@ bool SMESH_Gen::Compute(SMESH_Mesh &          aMesh,
       else if ( aShapesId )
         aShapesId->insert( smToCompute->GetId() );
     }
+    //aMesh.GetMeshDS()->Modified();
     return ret;
   }
   else
@@ -182,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() );
         }
@@ -190,7 +222,7 @@ bool SMESH_Gen::Compute(SMESH_Mesh &          aMesh,
     }
     
     // ------------------------------------------------------------
-    // sort list of meshes according to mesh order
+    // sort list of submeshes according to mesh order
     // ------------------------------------------------------------
     aMesh.SortByMeshOrder( smWithAlgoSupportingSubmeshes );
 
@@ -252,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() );
       }
@@ -264,10 +304,58 @@ bool SMESH_Gen::Compute(SMESH_Mesh &          aMesh,
   }
 
   MESSAGE( "VSR - SMESH_Gen::Compute() finished, OK = " << ret);
+  MEMOSTAT;
+
+  SMESHDS_Mesh *myMesh = aMesh.GetMeshDS();
+  myMesh->adjustStructure();
+  MESSAGE("*** compactMesh after compute");
+  myMesh->compactMesh();
+  //myMesh->adjustStructure();
+  list<int> listind = myMesh->SubMeshIndices();
+  list<int>::iterator it = listind.begin();
+  int total = 0;
+  for(; it != listind.end(); ++it)
+    {
+      ::SMESHDS_SubMesh *subMesh = myMesh->MeshElements(*it);
+      total +=  subMesh->getSize();
+    }
+  MESSAGE("total elements and nodes in submesh sets:" << total);
+  MESSAGE("Number of node objects " << SMDS_MeshNode::nbNodes);
+  MESSAGE("Number of cell objects " << SMDS_MeshCell::nbCells);
+  //myMesh->dumpGrid();
+  //aMesh.GetMeshDS()->Modified();
   return ret;
 }
 
 
+#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