Salome HOME
Copyright update 2021
[modules/smesh.git] / src / DriverGMF / DriverGMF_Read.cxx
index 0d70c8d5aeea181d2218c555e43e0a7036cf33b0..187abbcbe35d7393b635b7215875326ac8f874eb 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2021  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
@@ -14,7 +14,7 @@
 // Lesser General Public License for more details.
 //
 // You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, Read to the Free Software
+// License along with this library; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
@@ -43,7 +43,8 @@ extern "C"
 // --------------------------------------------------------------------------------
 DriverGMF_Read::DriverGMF_Read():
   Driver_SMESHDS_Mesh(),
-  _makeRequiredGroups( true )
+  _makeRequiredGroups( true ),
+  _makeFaultGroups( true )
 {
 }
 // --------------------------------------------------------------------------------
@@ -299,7 +300,7 @@ Driver_Mesh::Status DriverGMF_Read::Perform()
     for ( int i = 1; i <= nbPyr; ++i )
     {
       GmfGetLin(meshID, GmfPyramids, &iN[0], &iN[1], &iN[2], &iN[3], &iN[4], &ref);
-      if ( !myMesh->AddVolumeWithID( iN[0], iN[2], iN[1], iN[3], iN[4], pyrIDShift + i ))
+      if ( !myMesh->AddVolumeWithID( iN[3], iN[2], iN[1], iN[0], iN[4], pyrIDShift + i ))
         status = storeBadNodeIds( "GmfPyramids",i, 5, iN[0], iN[1],iN[2], iN[3], iN[4] );
     }
   }
@@ -401,26 +402,31 @@ Driver_Mesh::Status DriverGMF_Read::Perform()
     }
   }
 
-  // Read required entities into groups
+  // Read some entities into groups
+  // see MeshGems/Docs/meshgems_formats_description.pdf
 
-  if ( _makeRequiredGroups )
-  {
     // get ids of existing groups
     std::set< int > groupIDs;
-    const std::set<SMESHDS_GroupBase*>& groups = myMesh->GetGroups();
+    const std::set<SMESHDS_GroupBase*>&          groups = myMesh->GetGroups();
     std::set<SMESHDS_GroupBase*>::const_iterator grIter = groups.begin();
     for ( ; grIter != groups.end(); ++grIter )
       groupIDs.insert( (*grIter)->GetID() );
     if ( groupIDs.empty() ) groupIDs.insert( 0 );
 
+  // Read required entities into groups
+  if ( _makeRequiredGroups )
+  {
+
     const int kes[4][3] = { { GmfRequiredVertices,      SMDSAbs_Node, nodeIDShift },
                             { GmfRequiredEdges,         SMDSAbs_Edge, edgeIDShift },
                             { GmfRequiredTriangles,     SMDSAbs_Face, triaIDShift },
-                            { GmfRequiredQuadrilaterals,SMDSAbs_Face, quadIDShift }};
+                            { GmfRequiredQuadrilaterals,SMDSAbs_Face, quadIDShift }
+                          };
     const char* names[4] = { "_required_Vertices"      ,
                              "_required_Edges"         ,
                              "_required_Triangles"     ,
-                             "_required_Quadrilaterals" };
+                             "_required_Quadrilaterals" 
+                           };
     for ( int i = 0; i < 4; ++i )
     {
       int                 gmfKwd = kes[i][0];
@@ -444,6 +450,53 @@ Driver_Mesh::Status DriverGMF_Read::Perform()
     }
   }
 
+  // Read fault entities into groups
+  if ( _makeFaultGroups )
+  {
+
+    const int kes[7][3] = { { GmfFault_SmallTri,     SMDSAbs_Face, triaIDShift },
+                            { GmfFault_BadShape,     SMDSAbs_Face, triaIDShift },
+                            { GmfFault_Overlap,      SMDSAbs_Face, triaIDShift },
+                            { GmfFault_Inter,        SMDSAbs_Face, triaIDShift },
+                            { GmfFault_NearTri,      SMDSAbs_Face, triaIDShift },
+                            { GmfFault_FreeEdge,     SMDSAbs_Face, triaIDShift },
+                            { GmfFault_MultipleEdge, SMDSAbs_Face, triaIDShift }
+                          };
+    const char* names[7] = { "Fault_SmallTri",
+                             "Fault_BadShape",
+                             "Fault_Overlap",
+                             "Fault_Inter", 
+                             "Fault_NearTri",
+                             "Fault_FreeEdge",
+                             "Fault_MultipleEdge"
+                           };
+    for ( int i = 0; i < 7; ++i )
+    {
+      int                 gmfKwd = kes[i][0];
+      SMDSAbs_ElementType entity = (SMDSAbs_ElementType) kes[i][1];
+      int                 shift  = kes[i][2];
+      if ( int nb = GmfStatKwd(meshID, gmfKwd))
+      {
+        const int newID = *groupIDs.rbegin() + 1;
+        groupIDs.insert( newID );
+        SMESHDS_Group* group = new SMESHDS_Group( newID, myMesh, entity );
+        group->SetStoreName( names[i] );
+        myMesh->AddGroup( group );
+
+        GmfGotoKwd(meshID, gmfKwd);
+        for ( int i = 0; i < nb; ++i )
+        {
+          GmfGetLin(meshID, gmfKwd, &iN[0] );
+          group->Add( shift + iN[0] );
+        }
+      }
+    }
+  }
+
+
+  myMesh->Modified();
+  myMesh->CompactMesh();
+
   return status;
 }