Salome HOME
Fix Redesign of SMESH documentation
[modules/smesh.git] / src / DriverGMF / DriverGMF_Write.cxx
index d4f474771395ce3206d9c9deeb1bf8634901d7b6..723f73d321f6c07b7da5ee52c89f5873cdf3c7c9 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  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
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 #include <Basics_Utils.hxx>
 
+#include "utilities.h"
+
+using SMESHUtils::ControlPnt;
+
 extern "C"
 {
 #include "libmesh5.h"
@@ -68,15 +72,15 @@ extern "C"
   elem->getshapeId() );                         \
   }}
 
-#define END_ELEM_WRITE_ADD_TO_MAP( elem, e2id )         \
-  elem->getshapeId() );                                 \
-  e2id.insert( e2id.end(), make_pair( elem, gmfID ));   \
+#define END_ELEM_WRITE_ADD_TO_MAP( elem, e2id )            \
+  elem->getshapeId() );                                    \
+  e2id.insert( e2id.end(), std::make_pair( elem, gmfID )); \
   }}
 
 #define END_EXTRA_VERTICES_WRITE()           \
   );                                         \
   }}}}
-
+  
 
 DriverGMF_Write::DriverGMF_Write():
   Driver_SMESHDS_Mesh(), _exportRequiredGroups( true )
@@ -96,7 +100,7 @@ Driver_Mesh::Status DriverGMF_Write::Perform()
 {
   Kernel_Utils::Localizer loc;
 
-  const int dim = 3, version = sizeof(long) == 4 ? 2 : 3;
+  const int dim = 3, version = sizeof(double) < 8 ? 1 : 2;
 
   int meshID = GmfOpenMesh( myFile.c_str(), GmfWrite, version, dim );
   if ( !meshID )
@@ -120,7 +124,7 @@ Driver_Mesh::Status DriverGMF_Write::Perform()
     const SMDS_MeshNode* n = nodeIt->next();
     n->GetXYZ( xyz );
     GmfSetLin( meshID, GmfVertices, xyz[0], xyz[1], xyz[2], n->getshapeId() );
-    node2IdMap.insert( node2IdMap.end(), make_pair( n, ++iN ));
+    node2IdMap.insert( node2IdMap.end(), std::make_pair( n, ++iN ));
   }
   if ( iN != nbNodes )
     return addMessage("Wrong nb of nodes returned by nodesIterator", /*fatal=*/true);
@@ -200,10 +204,10 @@ Driver_Mesh::Status DriverGMF_Write::Perform()
 
   // pyramids
   BEGIN_ELEM_WRITE( SMDSEntity_Pyramid, GmfPyramids, pyra )
-    node2IdMap[ pyra->GetNode( 0 )],
+    node2IdMap[ pyra->GetNode( 3 )],
     node2IdMap[ pyra->GetNode( 2 )],
     node2IdMap[ pyra->GetNode( 1 )],
-    node2IdMap[ pyra->GetNode( 3 )],
+    node2IdMap[ pyra->GetNode( 0 )],
     node2IdMap[ pyra->GetNode( 4 )],
     END_ELEM_WRITE( pyra );
 
@@ -271,19 +275,19 @@ Driver_Mesh::Status DriverGMF_Write::Perform()
       SMDSAbs_EntityType smdsEntity;
       std::string entity = groupName.substr( pos + strlen("_required_"));
       if      ( entity == "Vertices" ) {
-        gmfKwd   = GmfRequiredVertices;
+        gmfKwd     = GmfRequiredVertices;
         smdsEntity = SMDSEntity_Node;
       }
       else if ( entity == "Edges" ) {
-        gmfKwd   = GmfRequiredEdges;
+        gmfKwd     = GmfRequiredEdges;
         smdsEntity = SMDSEntity_Edge;
       }
       else if ( entity == "Triangles" ) {
-        gmfKwd   = GmfRequiredTriangles;
+        gmfKwd     = GmfRequiredTriangles;
         smdsEntity = SMDSEntity_Triangle;
       }
       else if ( entity == "Quadrilaterals" ) {
-        gmfKwd   = GmfRequiredQuadrilaterals;
+        gmfKwd     = GmfRequiredQuadrilaterals;
         smdsEntity = SMDSEntity_Quadrangle;
       }
       else {
@@ -305,11 +309,11 @@ Driver_Mesh::Status DriverGMF_Write::Perform()
 
       // choose a TElem2IDMap
       TElem2IDMap* elem2IDMap = 0;
-      if ( smdsEntity == SMDSEntity_Quadrangle && nbOkElems != myMesh->NbFaces() )
+      if ( smdsEntity == SMDSEntity_Quadrangle    && nbOkElems != myMesh->NbFaces() )
         elem2IDMap = & quad2IDMap;
       else if ( smdsEntity == SMDSEntity_Triangle && nbOkElems != myMesh->NbFaces() )
         elem2IDMap = & tria2IDMap;
-      else if ( smdsEntity == SMDSEntity_Edge && nbOkElems != myMesh->NbEdges() )
+      else if ( smdsEntity == SMDSEntity_Edge     && nbOkElems != myMesh->NbEdges() )
         elem2IDMap = & edge2IDMap;
 
       // write the group
@@ -340,6 +344,47 @@ Driver_Mesh::Status DriverGMF_Write::Perform()
   return DRS_OK;
 }
 
+Driver_Mesh::Status DriverGMF_Write::PerformSizeMap( const std::vector<ControlPnt>& points )
+{
+//   const int dim = 3, version = sizeof(long) == 4 ? 2 : 3;
+  const int dim = 3, version = 2; // Version 3 not supported by mg-hexa
+  
+  // Open files
+  int verticesFileID = GmfOpenMesh( myVerticesFile.c_str(), GmfWrite, version, dim );  
+  int solFileID = GmfOpenMesh( mySolFile.c_str(), GmfWrite, version, dim );
+  
+  int pointsNumber = points.size();
+  
+  // Vertices Keyword
+  GmfSetKwd( verticesFileID, GmfVertices, pointsNumber );
+  // SolAtVertices Keyword
+  int TypTab[] = {GmfSca};
+  GmfSetKwd(solFileID, GmfSolAtVertices, pointsNumber, 1, TypTab);
+  
+  // Read the control points information from the vector and write it into the files
+  std::vector<ControlPnt>::const_iterator points_it;
+  for (points_it = points.begin(); points_it != points.end(); points_it++ )
+  {
+    GmfSetLin( verticesFileID, GmfVertices, points_it->X(), points_it->Y(), points_it->Z(), 0 );
+    double ValTab[] = {points_it->Size()};
+    GmfSetLin( solFileID, GmfSolAtVertices, ValTab);
+  } 
+  
+  // Close Files
+  GmfCloseMesh( verticesFileID );
+  GmfCloseMesh( solFileID );
+
+  return DRS_OK;
+}
+
+std::vector<std::string> DriverGMF_Write::GetSizeMapFiles()
+{
+  std::vector<std::string> files;
+  files.push_back(myVerticesFile);
+  files.push_back(mySolFile);
+  return files;
+}
+
 //================================================================================
 /*!
  * \brief Returns an iterator on elements of a certain type