Salome HOME
0020511: EDF 1101 SMESH : Add CGNS to Mesh Format Supported
authoreap <eap@opencascade.com>
Wed, 10 Aug 2011 10:17:29 +0000 (10:17 +0000)
committereap <eap@opencascade.com>
Wed, 10 Aug 2011 10:17:29 +0000 (10:17 +0000)
src/SMESH/SMESH_Mesh.cxx
src/SMESH/SMESH_Mesh.hxx

index 2a9b64909709ec0fea40f72aedbed524494ba309..7bc5b7ceb790197abb5578a0cc4fabf338713a33 100644 (file)
@@ -48,6 +48,8 @@
 #include "DriverMED_R_SMESHDS_Mesh.h"
 #include "DriverUNV_R_SMDS_Mesh.h"
 #include "DriverSTL_R_SMDS_Mesh.h"
+#include "DriverCGNS_Read.hxx"
+#include "DriverCGNS_Write.hxx"
 
 #undef _Precision_HeaderFile
 #include <BRepBndLib.hxx>
@@ -441,6 +443,31 @@ int SMESH_Mesh::STLToMesh(const char* theFileName)
   return 1;
 }
 
+//================================================================================
+/*!
+ * \brief Reads the given mesh from the CGNS file
+ *  \param theFileName - name of the file
+ *  \retval int - Driver_Mesh::Status
+ */
+//================================================================================
+
+int SMESH_Mesh::CGNSToMesh(const char*  theFileName,
+                           const int    theMeshIndex,
+                           std::string& theMeshName)
+{
+  DriverCGNS_Read myReader;
+  myReader.SetMesh(_myMeshDS);
+  myReader.SetFile(theFileName);
+  myReader.SetMeshId(theMeshIndex);
+  int res = myReader.Perform();
+  theMeshName = myReader.GetMeshName();
+
+  // create groups
+  SynchronizeGroups();
+
+  return res;
+}
+
 //=============================================================================
 /*!
  * 
@@ -1220,6 +1247,23 @@ void SMESH_Mesh::ExportSTL(const char *        file,
   myWriter.Perform();
 }
 
+//================================================================================
+/*!
+ * \brief Export the mesh to the CGNS file
+ */
+//================================================================================
+
+void SMESH_Mesh::ExportCGNS(const char *        file,
+                            const SMESHDS_Mesh* meshDS)
+{
+  DriverCGNS_Write myWriter;
+  myWriter.SetFile( file );
+  myWriter.SetMesh( const_cast<SMESHDS_Mesh*>( meshDS ));
+  myWriter.SetMeshName( SMESH_Comment("Mesh_") << meshDS->GetPersistentId());
+  if ( myWriter.Perform() != Driver_Mesh::DRS_OK )
+    throw SALOME_Exception("Export failed");
+}
+
 //================================================================================
 /*!
  * \brief Return number of nodes in the mesh
@@ -1432,6 +1476,32 @@ SMESH_Group* SMESH_Mesh::AddGroup (const SMDSAbs_ElementType theType,
   return aGroup;
 }
 
+//================================================================================
+/*!
+ * \brief Creates SMESH_Groups for not wrapped SMESHDS_Groups
+ *  \retval bool - true if new SMESH_Groups have been created
+ * 
+ */
+//================================================================================
+
+bool SMESH_Mesh::SynchronizeGroups()
+{
+  int nbGroups = _mapGroup.size();
+  const set<SMESHDS_GroupBase*>& groups = _myMeshDS->GetGroups();
+  set<SMESHDS_GroupBase*>::const_iterator gIt = groups.begin();
+  for ( ; gIt != groups.end(); ++gIt )
+  {
+    SMESHDS_GroupBase* groupDS = (SMESHDS_GroupBase*) *gIt;
+    _groupId = groupDS->GetID();
+    if ( !_mapGroup.count( _groupId ))
+      _mapGroup[_groupId] = new SMESH_Group( groupDS );
+  }
+  if ( !_mapGroup.empty() )
+    _groupId = _mapGroup.rbegin()->first + 1;
+
+  return nbGroups < _mapGroup.size();
+}
+
 //================================================================================
 /*!
  * \brief Return iterator on all existing groups
index 79fdc39187b9ef00caa81f010bdd411008ab9b2e..570dbb345ac3039711188c66043dd1a9b329d8cb 100644 (file)
@@ -108,14 +108,17 @@ public:
    */
   void ClearSubMesh(const int theShapeId);
 
-  int UNVToMesh(const char* theFileName);
   /*!
    * consult DriverMED_R_SMESHDS_Mesh::ReadStatus for returned value
    */
+  int UNVToMesh(const char* theFileName);
+
   int MEDToMesh(const char* theFileName, const char* theMeshName);
   
   int STLToMesh(const char* theFileName);
 
+  int CGNSToMesh(const char* theFileName, const int theMeshIndex, std::string& theMeshName);
+  
   SMESH_Hypothesis::Hypothesis_Status
   AddHypothesis(const TopoDS_Shape & aSubShape, int anHypId)
     throw(SALOME_Exception);
@@ -231,6 +234,8 @@ public:
   void ExportSTL(const char *        file,
                  const bool          isascii,
                  const SMESHDS_Mesh* meshPart = 0) throw(SALOME_Exception);
+  void ExportCGNS(const char *        file,
+                  const SMESHDS_Mesh* mesh);
   
   int NbNodes() const throw(SALOME_Exception);
   
@@ -286,6 +291,8 @@ public:
   };
   void SetRemoveGroupCallUp( TRmGroupCallUp * upCaller );
 
+  bool SynchronizeGroups();
+
 
   SMDSAbs_ElementType GetElementType( const int id, const bool iselem );