Salome HOME
Back to WIN32
[modules/smesh.git] / src / SMESH / SMESH_Gen.cxx
index 2a7e23af9cc1f9ab51a698f5bcae72fec78a0582..4a020890e93a29e92dd8c2cb91c4cf7642b045ad 100644 (file)
@@ -25,9 +25,8 @@
 //  Author : Paul RASCLE, EDF
 //  Module : SMESH
 //
-
 //#define CHRONODEF
-
+//
 #include "SMESH_Gen.hxx"
 
 #include "SMESH_DriverMesh.hxx"
@@ -37,6 +36,8 @@
 #include "SMESHDS_Document.hxx"
 #include "SMESH_HypoFilter.hxx"
 #include "SMESH_Mesh.hxx"
+#include "SMESH_SequentialMesh.hxx"
+#include "SMESH_ParallelMesh.hxx"
 #include "SMESH_MesherHelper.hxx"
 #include "SMESH_subMesh.hxx"
 
 
 #include <Basics_Utils.hxx>
 
+#ifndef WIN32
+#include <boost/asio.hpp>
+#endif
+
 using namespace std;
+#ifndef WIN32
 #include <boost/filesystem.hpp>
-#include <boost/asio.hpp>
 namespace fs = boost::filesystem;
+#endif
 
 // Environment variable separator
 #ifdef WIN32
@@ -151,7 +157,8 @@ SMESH_Mesh* SMESH_Gen::CreateMesh(bool theIsEmbeddedMode)
   Unexpect aCatch(SalomeException);
 
   // create a new SMESH_mesh object
-  SMESH_Mesh *aMesh = new SMESH_Mesh(_localId++,
+  SMESH_Mesh *aMesh = new SMESH_SequentialMesh(
+                                     _localId++,
                                      this,
                                      theIsEmbeddedMode,
                                      _studyContext->myDocument);
@@ -160,6 +167,27 @@ SMESH_Mesh* SMESH_Gen::CreateMesh(bool theIsEmbeddedMode)
   return aMesh;
 }
 
+//=============================================================================
+/*!
+ * Creates a parallel mesh in a study.
+ * if (theIsEmbeddedMode) { mesh modification commands are not logged }
+ */
+//=============================================================================
+
+SMESH_Mesh* SMESH_Gen::CreateParallelMesh(bool theIsEmbeddedMode)
+{
+  Unexpect aCatch(SalomeException);
+
+  // create a new SMESH_mesh object
+  SMESH_Mesh *aMesh = new SMESH_ParallelMesh(
+                                     _localId++,
+                                     this,
+                                     theIsEmbeddedMode,
+                                     _studyContext->myDocument);
+  _studyContext->mapMesh[_localId-1] = aMesh;
+
+  return aMesh;
+}
 
 //=============================================================================
 /*!
@@ -197,7 +225,7 @@ bool SMESH_Gen::sequentialComputeSubMeshes(
       continue;
 
     // check for preview dimension limitations
-    if ( aShapesId && GetShapeDim( shapeType ) > (int)aDim )
+    if ( aShapesId && SMESH_Gen::GetShapeDim( shapeType ) > (int)aDim )
     {
       // clear compute state not to show previous compute errors
       //  if preview invoked less dimension less than previous
@@ -240,7 +268,7 @@ const std::function<void(SMESH_subMesh*,
                          bool,
                          TopTools_IndexedMapOfShape *,
                          TSetOfInt*)>
-     compute_function([&] (SMESH_subMesh* sm,
+     compute_function([] (SMESH_subMesh* sm,
                           SMESH_subMesh::compute_event event,
                           SMESH_subMesh *shapeSM,
                           bool aShapeOnly,
@@ -261,6 +289,7 @@ const std::function<void(SMESH_subMesh*,
 
 });
 
+
 //=============================================================================
 /*!
  * Algo to run the computation of all the submeshes of a mesh in parallel
@@ -278,16 +307,15 @@ bool SMESH_Gen::parallelComputeSubMeshes(
           const bool complexShapeFirst,
           const bool   aShapeOnly)
 {
+#ifdef WIN32
+  throw SALOME_Exception("ParallelMesh is not working on Windows");
+#else
 
   bool ret = true;
 
   SMESH_subMeshIteratorPtr smIt;
   SMESH_subMesh *shapeSM = aMesh.GetSubMesh(aShape);
 
-  // Pool of thread for computation
-  // TODO: move when parallelMesh created
-  aMesh.InitPoolThreads();
-
   TopAbs_ShapeEnum previousShapeType = TopAbs_VERTEX;
   int nbThreads = aMesh.GetNbThreads();
   MESSAGE("Compute submeshes with threads: " << nbThreads);
@@ -332,23 +360,22 @@ bool SMESH_Gen::parallelComputeSubMeshes(
       }
       if(file_name != "")
       {
-        fs::path mesh_file = fs::path(aMesh.tmp_folder) / fs::path(file_name);
-        exportMesh(mesh_file.string(), aMesh, "MESH");
-
+        fs::path mesh_file = fs::path(aMesh.GetTmpFolder()) / fs::path(file_name);
+             SMESH_DriverMesh::exportMesh(mesh_file.string(), aMesh, "MESH");
       }
       //Resetting threaded pool info
       previousShapeType = shapeType;
     }
 
     // check for preview dimension limitations
-    if ( aShapesId && GetShapeDim( shapeType ) > (int)aDim )
+    if ( aShapesId && SMESH_Gen::GetShapeDim( shapeType ) > (int)aDim )
     {
       // clear compute state not to show previous compute errors
       //  if preview invoked less dimension less than previous
       smToCompute->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
       continue;
     }
-    boost::asio::post(*(aMesh._pool), std::bind(compute_function, smToCompute, computeEvent,
+    boost::asio::post(*(aMesh.GetPool()), std::bind(compute_function, smToCompute, computeEvent,
                       shapeSM, aShapeOnly, allowedSubShapes,
                       aShapesId));
   }
@@ -359,9 +386,9 @@ bool SMESH_Gen::parallelComputeSubMeshes(
   aMesh.GetMeshDS()->Modified();
 
   return ret;
+#endif
 };
 
-
 //=============================================================================
 /*
  * Compute a mesh
@@ -408,22 +435,14 @@ bool SMESH_Gen::Compute(SMESH_Mesh &                aMesh,
     // ===============================================
     // Mesh all the sub-shapes starting from vertices
     // ===============================================
-    if (aMesh.IsParallel())
-      ret = parallelComputeSubMeshes(
-              aMesh, aShape, aDim,
-              aShapesId, allowedSubShapes,
-              computeEvent,
-              includeSelf,
-              complexShapeFirst,
-              aShapeOnly);
-    else
-      ret = sequentialComputeSubMeshes(
-              aMesh, aShape, aDim,
-              aShapesId, allowedSubShapes,
-              computeEvent,
-              includeSelf,
-              complexShapeFirst,
-              aShapeOnly);
+    ret = aMesh.ComputeSubMeshes(
+            this,
+            aMesh, aShape, aDim,
+            aShapesId, allowedSubShapes,
+            computeEvent,
+            includeSelf,
+            complexShapeFirst,
+            aShapeOnly);
 
     return ret;
   }