Salome HOME
allow multiple size-maps definition
authorrnc <rnc@opencascade.com>
Tue, 4 Jun 2013 16:29:27 +0000 (16:29 +0000)
committerrnc <rnc@opencascade.com>
Tue, 4 Jun 2013 16:29:27 +0000 (16:29 +0000)
src/DriverGMF/DriverGMF_Write.cxx
src/DriverGMF/DriverGMF_Write.hxx

index 36b94df474e77ffb81576aa3ae61d3e6439274ac..ea28f31cf96f5edc33229d1f1c6c744094ee7a9b 100644 (file)
@@ -79,7 +79,7 @@ extern "C"
 
 
 DriverGMF_Write::DriverGMF_Write():
-  Driver_SMESHDS_Mesh(), _exportRequiredGroups( true )
+  Driver_SMESHDS_Mesh(), _exportRequiredGroups( true ), mySizeMapVerticesNumber( 0 ), mySizeMapMeshes(), myLocalSizes()
 {
 }
 DriverGMF_Write::~DriverGMF_Write()
@@ -370,49 +370,94 @@ Driver_Mesh::Status DriverGMF_Write::Perform()
 //   return nbVertices;
 // }
 // 
-// int DriverGMF_Write::OpenFileToWrite()
+// int DriverGMF_Write::BeginSizeMap()
 // {
 //   const int dim = 3, version = sizeof(long) == 4 ? 2 : 3;
-//   int meshID = GmfOpenMesh( myFile.c_str(), GmfWrite, version, dim );
-//   return meshID;
+//   myGmfID = GmfOpenMesh( myFile.c_str(), GmfWrite, version, dim );
 // }
-// 
-// void DriverGMF_Write::CloseFile( int meshID )
+//  
+// void DriverGMF_Write::EndSizeMap()
 // {
-//   GmfCloseMesh( meshID );
+//   GmfCloseMesh( myGmfID );
 // }
+void DriverGMF_Write::AddSizeMapFromMesh( SMESHDS_Mesh* mesh, double size)
+{
+  mySizeMapMeshes.push_back( mesh );
+  mySizeMapVerticesNumber += mesh->NbNodes();
+  myLocalSizes.push_back(TLocalSize(mesh->NbNodes(), size));
+}
 
-void DriverGMF_Write::WriteSizeMapFromMesh( double size )
+Driver_Mesh::Status DriverGMF_Write::PerformSizeMap()
 {
   // Open file
   const int dim = 3, version = sizeof(long) == 4 ? 2 : 3;
   int meshID = GmfOpenMesh( myFile.c_str(), GmfWrite, version, dim );  
   
   // Vertices Keyword
-  int iN = 0, nbNodes = myMesh->NbNodes();
-  GmfSetKwd( meshID, GmfVertices, nbNodes );
+  GmfSetKwd( meshID, GmfVertices, mySizeMapVerticesNumber );
   double xyz[3];
-  SMDS_NodeIteratorPtr nodeIt = myMesh->nodesIterator();
-  while ( nodeIt->more() )
+  std::list<TLocalSize>::iterator sizes_it;
+  std::list<SMESHDS_Mesh*>::iterator meshes_it;
+  SMESHDS_Mesh* aMesh;
+  for ( sizes_it = myLocalSizes.begin(), meshes_it = mySizeMapMeshes.begin()
+       ; sizes_it != myLocalSizes.end()
+       ; sizes_it++, meshes_it++ )
   {
-    const SMDS_MeshNode* n = nodeIt->next();
-    n->GetXYZ( xyz );
-    GmfSetLin( meshID, GmfVertices, xyz[0], xyz[1], xyz[2], n->getshapeId() );
-  }
+    aMesh= *meshes_it;
+    SMDS_NodeIteratorPtr nodeIt = aMesh->nodesIterator();
+    while ( nodeIt->more() )
+    {
+      const SMDS_MeshNode* n = nodeIt->next();
+      n->GetXYZ( xyz );
+      GmfSetLin( meshID, GmfVertices, xyz[0], xyz[1], xyz[2], n->getshapeId() );
+    }
+    
+    // solAtVertices Keyword
+    int TypTab[] = {GmfSca};
+    GmfSetKwd(meshID, GmfSolAtVertices, mySizeMapVerticesNumber, 1, TypTab);
   
-  // solAtVertices Keyword
-  int TypTab[] = {GmfSca};
-  GmfSetKwd(meshID, GmfSolAtVertices, nbNodes, 1, TypTab);
-  for ( int i=1; i<= nbNodes; i++)
-  {
-    double ValTab[] = {size};
-    GmfSetLin( meshID, GmfSolAtVertices, ValTab);
+    for ( int i = 1; i <= sizes_it->nbNodes; i++ )
+    {
+      double ValTab[] = {sizes_it->size};
+      GmfSetLin( meshID, GmfSolAtVertices, ValTab);
+    }
   }
   
   // Close File
   GmfCloseMesh( meshID );
 }
 
+// void DriverGMF_Write::WriteSizeMapFromMesh( double size )
+// {
+//   // Open file
+//   const int dim = 3, version = sizeof(long) == 4 ? 2 : 3;
+//   int meshID = GmfOpenMesh( myFile.c_str(), GmfWrite, version, dim );  
+//   
+//   // Vertices Keyword
+//   int iN = 0, nbNodes = myMesh->NbNodes();
+//   GmfSetKwd( meshID, GmfVertices, nbNodes );
+//   double xyz[3];
+//   SMDS_NodeIteratorPtr nodeIt = myMesh->nodesIterator();
+//   while ( nodeIt->more() )
+//   {
+//     const SMDS_MeshNode* n = nodeIt->next();
+//     n->GetXYZ( xyz );
+//     GmfSetLin( meshID, GmfVertices, xyz[0], xyz[1], xyz[2], n->getshapeId() );
+//   }
+//   
+//   // solAtVertices Keyword
+//   int TypTab[] = {GmfSca};
+//   GmfSetKwd(meshID, GmfSolAtVertices, nbNodes, 1, TypTab);
+//   for ( int i=1; i<= nbNodes; i++)
+//   {
+//     double ValTab[] = {size};
+//     GmfSetLin( meshID, GmfSolAtVertices, ValTab);
+//   }
+//   
+//   // Close File
+//   GmfCloseMesh( meshID );
+// }
+
 //================================================================================
 /*!
  * \brief Returns an iterator on elements of a certain type
index 35d845a4383859555623d299a2ec457b2ae82e1f..a1779a6740dad5ad3a2965271ed7a269a5c66a13 100644 (file)
 #include "SMDSAbs_ElementType.hxx"
 #include "SMDS_ElemIterator.hxx"
 
+struct TLocalSize
+{
+  TLocalSize( int theNbNodes, double theSize)
+  {
+    nbNodes = theNbNodes;
+    size = theSize;
+  }
+  int nbNodes;
+  double size;
+};
+
 /*!
  * \brief Driver Writing a mesh into a GMF file.
  */
@@ -48,8 +59,10 @@ public:
     _exportRequiredGroups = toExport;
   }
    
-  virtual Status Perform(); 
-  void WriteSizeMapFromMesh( double size );
+  virtual Status Perform();
+  Status PerformSizeMap();
+  void AddSizeMapFromMesh( SMESHDS_Mesh* mesh, double size);
+//   void WriteSizeMapFromMesh( double size );
 //   void AddSizeMapSection( int meshID, int nbControlPoints );
 //   void AppendSize( int meshID, double size );
 //   int NbVerticesInFile();
@@ -63,6 +76,9 @@ public:
   SMDS_ElemIteratorPtr elementIterator(SMDSAbs_GeometryType type);
 
   bool _exportRequiredGroups;
+  int mySizeMapVerticesNumber;
+  std::list<SMESHDS_Mesh*> mySizeMapMeshes;
+  std::list<TLocalSize> myLocalSizes;
 };
 
 #endif