Salome HOME
Merge remote branch 'origin/gdd/translations'
[modules/smesh.git] / src / DriverMED / DriverMED_R_SMESHDS_Mesh.cxx
index d6bb729e490d8eb5d3199cc8d564730f556bf676..61b6fec1c7e5c9b56ca7f1fa25960acc14fdda25 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2015  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
@@ -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_
@@ -50,6 +52,26 @@ static int MYDEBUG = 0;
 using namespace MED;
 using namespace std;
 
+typedef std::map<int, DriverMED_FamilyPtr> TID2FamilyMap;
+
+namespace DriverMED
+{
+  bool buildMeshGrille(const MED::PWrapper&  theWrapper,
+                       const MED::PMeshInfo& theMeshInfo,
+                       SMESHDS_Mesh*         theMesh,
+                       const TID2FamilyMap&  myFamilies);
+  /*!
+   * \brief Ensure aFamily has a required ID
+    * \param aFamily - a family to check
+    * \param anID - an ID aFamily should have
+    * \param myFamilies - a map of the family ID to the Family
+    * \retval bool  - true if successful
+   */
+  bool checkFamilyID(DriverMED_FamilyPtr & aFamily,
+                     int                   anID,
+                     const TID2FamilyMap&  myFamilies);
+}
+
 void
 DriverMED_R_SMESHDS_Mesh
 ::SetMeshName(string theMeshName)
@@ -71,7 +93,7 @@ DriverMED_R_SMESHDS_Mesh
 ::Perform()
 {
   Status aResult = DRS_FAIL;
-  bool isDescConn = false;
+  bool isDescConn = false; // Mantis issue 0020483
 #ifndef _DEXCEPT_
   try{
 #endif
@@ -133,7 +155,7 @@ DriverMED_R_SMESHDS_Mesh
         }
 
         if (aMeshInfo->GetType() == MED::eSTRUCTURE){
-          /*bool aRes = */buildMeshGrille(aMed,aMeshInfo);
+          /*bool aRes = */DriverMED::buildMeshGrille(aMed,aMeshInfo,myMesh,myFamilies);
           continue;
         }
 
@@ -167,7 +189,7 @@ DriverMED_R_SMESHDS_Mesh
 
           // Save reference to this node from its family
           TInt aFamNum = aNodeInfo->GetFamNum(iElem);
-          if ( checkFamilyID ( aFamily, aFamNum ))
+          if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies ))
           {
             aFamily->AddElement(aNode);
             aFamily->SetType(SMDSAbs_Node);
@@ -175,13 +197,17 @@ 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() && !isDescConn; anEntityIterDesc++) {
+          for (; anEntityIterDesc != aEntityInfoDesc.end(); anEntityIterDesc++) {
             const EEntiteMaillage& anEntity = anEntityIterDesc->first;
-            if (anEntity != eNOEUD) isDescConn = true;
+            aDescendingEntitiesMap.Add(anEntity);
+            //if (anEntity != eNOEUD) isDescConn = true;
           }
         }
 
@@ -193,6 +219,7 @@ DriverMED_R_SMESHDS_Mesh
         MED::TEntityInfo::iterator anEntityIter = aEntityInfo.begin();
         for (; anEntityIter != aEntityInfo.end(); anEntityIter++) {
           const EEntiteMaillage& anEntity = anEntityIter->first;
+          aDescendingEntitiesMap.Remove(anEntity); // Mantis issue 0020483
           if (anEntity == eNOEUD) continue;
           // Reading MED cells to the corresponding SMDS structure
           //------------------------------------------------------
@@ -250,7 +277,7 @@ DriverMED_R_SMESHDS_Mesh
 
                 // Save reference to this element from its family
                 TInt aFamNum = aBallInfo->GetFamNum(iBall);
-                if ( checkFamilyID ( aFamily, aFamNum ))
+                if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies ))
                 {
                   aFamily->AddElement(anElement);
                   aFamily->SetType( SMDSAbs_Ball );
@@ -322,7 +349,7 @@ DriverMED_R_SMESHDS_Mesh
                     if(aResult < DRS_WARN_RENUMBER)
                       aResult = DRS_WARN_RENUMBER;
                   }
-                  if ( checkFamilyID ( aFamily, aFamNum ))
+                  if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies ))
                   {
                     // Save reference to this element from its family
                     aFamily->AddElement(anElement);
@@ -402,7 +429,7 @@ DriverMED_R_SMESHDS_Mesh
                     if (aResult < DRS_WARN_RENUMBER)
                       aResult = DRS_WARN_RENUMBER;
                   }
-                  if ( checkFamilyID ( aFamily, aFamNum )) {
+                  if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies )) {
                     // Save reference to this element from its family
                     aFamily->AddElement(anElement);
                     aFamily->SetType(anElement->GetType());
@@ -424,6 +451,7 @@ DriverMED_R_SMESHDS_Mesh
               case eSEG3:    aNbNodes = 3;  break;
               case eTRIA3:   aNbNodes = 3;  break;
               case eTRIA6:   aNbNodes = 6;  break;
+              case eTRIA7:   aNbNodes = 7;  break;
               case eQUAD4:   aNbNodes = 4;  break;
               case eQUAD8:   aNbNodes = 8;  break;
               case eQUAD9:   aNbNodes = 9;  break;
@@ -545,6 +573,24 @@ DriverMED_R_SMESHDS_Mesh
                       isRenum = anIsElemNum;
                     }
                     break;
+                  case eTRIA7:
+                    aNbNodes = 7;
+                    if(anIsElemNum)
+                      anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
+                                                        aNodeIds[2], aNodeIds[3],
+                                                        aNodeIds[4], aNodeIds[5], aNodeIds[6],
+                                                        aCellInfo->GetElemNum(iElem));
+                    if (!anElement) {
+                      anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
+                                                  FindNode(myMesh,aNodeIds[1]),
+                                                  FindNode(myMesh,aNodeIds[2]),
+                                                  FindNode(myMesh,aNodeIds[3]),
+                                                  FindNode(myMesh,aNodeIds[4]),
+                                                  FindNode(myMesh,aNodeIds[5]),
+                                                  FindNode(myMesh,aNodeIds[6]));
+                      isRenum = anIsElemNum;
+                    }
+                    break;
                   case eQUAD4:
                     aNbNodes = 4;
                     if(anIsElemNum)
@@ -894,7 +940,7 @@ DriverMED_R_SMESHDS_Mesh
                     if (aResult < DRS_WARN_RENUMBER)
                       aResult = DRS_WARN_RENUMBER;
                   }
-                  if ( checkFamilyID ( aFamily, aFamNum )) {
+                  if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies )) {
                     // Save reference to this element from its family
                     myFamilies[aFamNum]->AddElement(anElement);
                     myFamilies[aFamNum]->SetType(anElement->GetType());
@@ -904,8 +950,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());
@@ -918,6 +965,7 @@ DriverMED_R_SMESHDS_Mesh
   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;
@@ -944,10 +992,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;
   }
@@ -1099,7 +1147,9 @@ void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes ()
  * \param anID - an ID aFamily should have
  * \retval bool  - true if successful
  */
-bool DriverMED_R_SMESHDS_Mesh::checkFamilyID(DriverMED_FamilyPtr & aFamily, int anID) const
+bool DriverMED::checkFamilyID(DriverMED_FamilyPtr & aFamily,
+                              int                   anID,
+                              const TID2FamilyMap&  myFamilies)
 {
   if ( !aFamily || aFamily->GetId() != anID ) {
     map<int, DriverMED_FamilyPtr>::const_iterator i_fam = myFamilies.find(anID);
@@ -1110,14 +1160,18 @@ bool DriverMED_R_SMESHDS_Mesh::checkFamilyID(DriverMED_FamilyPtr & aFamily, int
   return ( aFamily->GetId() == anID );
 }
 
-
-/*! \brief Reading the structured mesh and convert to non structured (by filling of smesh structure for non structured mesh)
+/*!
+ * \brief Reading the structured mesh and convert to non structured
+ *        (by filling of smesh structure for non structured mesh)
  * \param theWrapper  - PWrapper const pointer
  * \param theMeshInfo - PMeshInfo const pointer
+ * \param myFamilies  - a map of the family ID to the Family
  * \return TRUE, if successfully. Else FALSE
  */
-bool DriverMED_R_SMESHDS_Mesh::buildMeshGrille(const MED::PWrapper& theWrapper,
-                                               const MED::PMeshInfo& theMeshInfo)
+bool DriverMED::buildMeshGrille(const MED::PWrapper&  theWrapper,
+                                const MED::PMeshInfo& theMeshInfo,
+                                SMESHDS_Mesh*         myMesh,
+                                const TID2FamilyMap&  myFamilies)
 {
   bool res = true;
 
@@ -1139,7 +1193,7 @@ bool DriverMED_R_SMESHDS_Mesh::buildMeshGrille(const MED::PWrapper& theWrapper,
 
     if((aGrilleInfo->myFamNumNode).size() > 0){
       TInt aFamNum = aGrilleInfo->GetFamNumNode(iNode);
-      if ( checkFamilyID ( aFamily, aFamNum ))
+      if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies ))
         {
           aFamily->AddElement(aNode);
           aFamily->SetType(SMDSAbs_Node);
@@ -1196,7 +1250,7 @@ bool DriverMED_R_SMESHDS_Mesh::buildMeshGrille(const MED::PWrapper& theWrapper,
     }
     if((aGrilleInfo->myFamNum).size() > 0){
       TInt aFamNum = aGrilleInfo->GetFamNum(iCell);
-      if ( checkFamilyID ( aFamily, aFamNum )){
+      if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies )){
         aFamily->AddElement(anElement);
         aFamily->SetType(anElement->GetType());
       }