Salome HOME
Creating and importing 2 meshes from the same engine was not working. Mesh ID managem...
[modules/smesh.git] / src / SMESH / SMESH_Gen.cxx
index ec40c71ff9a7d3335fdee3cb5a09e6687dd55897..d120f41f1a4dbdc4d237ab0a147408d4470d4c2a 100644 (file)
@@ -30,6 +30,7 @@
 #include "SMESH_subMesh.hxx"
 #include "SMDS_MeshElement.hxx"
 #include "SMDS_MeshNode.hxx"
+#include "SMESHDriver.h"
 
 #include <gp_Pnt.hxx>
 #include <BRep_Tool.hxx>
@@ -96,8 +97,8 @@ SMESH_Hypothesis *SMESH_Gen::CreateHypothesis(const char *anHyp, int studyId)
  */
 //=============================================================================
 
-SMESH_Mesh *SMESH_Gen::Init(int studyId, const TopoDS_Shape & aShape)
-throw(SALOME_Exception)
+SMESH_Mesh *SMESH_Gen::Init(int studyId, const TopoDS_Shape & aShape, int meshID)
+       throw(SALOME_Exception)
 {
        MESSAGE("SMESH_Gen::Init");
 //   if (aShape.ShapeType() == TopAbs_COMPOUND)
@@ -112,11 +113,16 @@ throw(SALOME_Exception)
 
        // create a new SMESH_mesh object 
 
-       SMESH_Mesh *mesh = new SMESH_Mesh(_localId++,
+       if(meshID == -1)
+               meshID=_localId++;
+       else if(_localId<=meshID)
+               _localId=meshID+1;
+
+       SMESH_Mesh *mesh = new SMESH_Mesh(meshID,
                studyId,
                this,
                myStudyContext->myDocument);
-       myStudyContext->mapMesh[_localId] = mesh;
+       myStudyContext->mapMesh[meshID] = mesh;
 
        // associate a TopoDS_Shape to the mesh
 
@@ -126,7 +132,8 @@ throw(SALOME_Exception)
 
 //=============================================================================
 /*!
- * 
+ * @TODO Doing a full update after computation is not optimal when doing a local
+ * remeshing.
  */
 //=============================================================================
 
@@ -138,7 +145,7 @@ throw(SALOME_Exception)
 /* 
 Algo : s'appuie ou non sur une geometrie
 Si geometrie:
-Vertex : rien à faire (range le point)
+Vertex : rien faire (range le point)
 Edge, Wire, collection d'edge et wire : 1D
 Face, Shell, collection de Face et Shells : 2D
 Solid, Collection de Solid : 3D
@@ -183,6 +190,8 @@ Solid, Collection de Solid : 3D
                smToCompute = sm->GetFirstToCompute();
        }
 
+       aMesh.GetMeshDS()->logFullUpdate();
+
        return ret;
 }
 
@@ -404,3 +413,40 @@ int SMESH_Gen::GetShapeDim(const TopoDS_Shape & aShape)
 //   SCRUTE(shapeDim);
        return shapeDim;
 }
+
+/**
+ * Import a mesh from a file
+ * @param fileName file name to be imported
+ * @param fileType Currently it could be either "DAT", "UNV" or "MED".
+ * @todo
+ */
+SMESH_Mesh * SMESH_Gen::Import(int studyId, const char * fileName,
+       const char * fileType)
+{
+       MESSAGE("SMESH_Gen::Import("<<studyId<<","<<fileName<<","<<fileType<<")");
+
+       // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
+       StudyContextStruct *myStudyContext = GetStudyContext(studyId);
+
+       // will be used with document
+       /*Document_Reader * reader = SMESHDriver::GetDocumentReader(string(fileType));
+       reader->SetDocument(myStudyContext->myDocument);
+       reader->SetFile(string(fileName));
+       reader->Read();*/
+       // currently we only read one mesh from a file (limitation on MED files).
+
+       // create a new SMESH_mesh object 
+       SMESH_Mesh *mesh = new SMESH_Mesh(_localId++, studyId, this,
+               myStudyContext->myDocument);
+       myStudyContext->mapMesh[_localId] = mesh;
+       
+       Mesh_Reader * reader = SMESHDriver::GetMeshReader(string(fileType));
+       reader->SetMesh(mesh->GetMeshDS());
+       reader->SetFile(string(fileName));
+       reader->Read();
+       
+       mesh->GetMeshDS()->logFullUpdate();
+       
+       return mesh;
+}
+