Salome HOME
0022098: EDF 2036 SMESH: Create groups from none conected parts of a mesh
[modules/smesh.git] / src / DriverMED / DriverMED_R_SMESHDS_Mesh.cxx
index a60b77ca9e33cde6123d5eb35e4c5c0f5d6a133b..a7527fb976d4ed4f8891434084fa647b56eaf704 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2013  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
@@ -23,7 +23,7 @@
 //  SMESH DriverMED : driver to read and write 'med' files
 //  File   : DriverMED_R_SMESHDS_Mesh.cxx
 //  Module : SMESH
-//
+
 #include "DriverMED_R_SMESHDS_Mesh.h"
 #include "SMESHDS_Mesh.hxx"
 #include "utilities.h"
@@ -36,6 +36,8 @@
 #include "MED_CoordUtils.hxx"
 #include "MED_Utilities.hxx"
 
+#include <NCollection_Map.hxx>
+
 #include <stdlib.h>
 
 #ifdef _DEBUG_
@@ -71,6 +73,7 @@ DriverMED_R_SMESHDS_Mesh
 ::Perform()
 {
   Status aResult = DRS_FAIL;
+  bool isDescConn = false; // Mantis issue 0020483
 #ifndef _DEXCEPT_
   try{
 #endif
@@ -173,15 +176,31 @@ DriverMED_R_SMESHDS_Mesh
           }
         }
 
+        // Are there any MED cells in descending connectivity
+        // Mantis issue 0020483
+        //---------------------------------------------------
+        NCollection_Map<EEntiteMaillage> aDescendingEntitiesMap;
+        if (!isDescConn) {
+          MED::TEntityInfo aEntityInfoDesc = aMed->GetEntityInfo(aMeshInfo, eDESC);
+          MED::TEntityInfo::iterator anEntityIterDesc = aEntityInfoDesc.begin();
+          //for (; anEntityIterDesc != aEntityInfoDesc.end() && !isDescConn; anEntityIterDesc++) {
+          for (; anEntityIterDesc != aEntityInfoDesc.end(); anEntityIterDesc++) {
+            const EEntiteMaillage& anEntity = anEntityIterDesc->first;
+            aDescendingEntitiesMap.Add(anEntity);
+            //if (anEntity != eNOEUD) isDescConn = true;
+          }
+        }
+
         // Reading pre information about all MED cells
         //--------------------------------------------
         typedef MED::TVector<int> TNodeIds;
         bool takeNumbers = true;  // initially we trust the numbers from file
-        MED::TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo);
+        MED::TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo, eNOD);
         MED::TEntityInfo::iterator anEntityIter = aEntityInfo.begin();
-        for(; anEntityIter != aEntityInfo.end(); anEntityIter++){
+        for (; anEntityIter != aEntityInfo.end(); anEntityIter++) {
           const EEntiteMaillage& anEntity = anEntityIter->first;
-          if(anEntity == eNOEUD) continue;
+          aDescendingEntitiesMap.Remove(anEntity); // Mantis issue 0020483
+          if (anEntity == eNOEUD) continue;
           // Reading MED cells to the corresponding SMDS structure
           //------------------------------------------------------
           const MED::TGeom2Size& aGeom2Size = anEntityIter->second;
@@ -205,7 +224,7 @@ DriverMED_R_SMESHDS_Mesh
                 aNodeIds.resize( aNbBalls );
                 for(TInt iBall = 0; iBall < aNbBalls && anIsNodeNum; iBall++)
                 {
-                  aNodeIds[iBall] = aNodeInfo->GetElemNum(iBall);
+                  aNodeIds[iBall] = aNodeInfo->GetElemNum( (*aBallInfo->myConn)[ iBall ]-1 );
                   anIsNodeNum = myMesh->FindNode( aNodeIds[iBall] ) ? eVRAI : eFAUX;
                 }
               }
@@ -892,8 +911,9 @@ DriverMED_R_SMESHDS_Mesh
             }}
           }
         }
-      }
-    }
+        if (aDescendingEntitiesMap.Extent()) isDescConn = true; // Mantis issue 0020483
+      } // for(int iMesh = 0; iMesh < aNbMeshes; iMesh++)
+    } // if aNbMeshes
 #ifndef _DEXCEPT_
   }catch(const std::exception& exc){
     INFOS("The following exception was caught:\n\t"<<exc.what());
@@ -905,6 +925,13 @@ DriverMED_R_SMESHDS_Mesh
 #endif
   if (myMesh)
     myMesh->compactMesh();
+
+  // Mantis issue 0020483
+  if (aResult == DRS_OK && isDescConn) {
+    INFOS("There are some elements in descending connectivity in med file. They were not read !!!");
+    aResult = DRS_WARN_DESCENDING;
+  }
+
   if(MYDEBUG) MESSAGE("Perform - aResult status = "<<aResult);
   return aResult;
 }
@@ -926,10 +953,10 @@ list<string> DriverMED_R_SMESHDS_Mesh::GetMeshNames(Status& theStatus)
         aMeshNames.push_back(aMeshInfo->GetName());
       }
     }
-  }catch(const std::exception& exc){
+  } catch(const std::exception& exc) {
     INFOS("Following exception was caught:\n\t"<<exc.what());
     theStatus = DRS_FAIL;
-  }catch(...){
+  } catch(...) {
     INFOS("Unknown exception was caught !!!");
     theStatus = DRS_FAIL;
   }