Salome HOME
0020145: EDF 666 SMESH: Modifications of GEOM groups are not taken into account
[modules/smesh.git] / src / DriverMED / DriverMED_R_SMESHDS_Mesh.cxx
index 7e7c9b6ae3baac5b3bbde3b42e76c32278382299..99f892d14e1ab10815817b5400f50d0f2a88d412 100644 (file)
@@ -1,29 +1,28 @@
-//  SMESH DriverMED : driver to read and write 'med' files
+//  Copyright (C) 2007-2008  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
+//
+//  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.
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
-// 
-//  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. 
-// 
-//  This library is distributed in the hope that it will be useful, 
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-//  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, 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
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  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, 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
 //
+//  SMESH DriverMED : driver to read and write 'med' files
 //  File   : DriverMED_R_SMESHDS_Mesh.cxx
 //  Module : SMESH
-
+//
 #include "DriverMED_R_SMESHDS_Mesh.h"
 #include "DriverMED_R_SMDS_Mesh.h"
 #include "SMESHDS_Mesh.hxx"
@@ -52,7 +51,7 @@ using namespace MED;
 
 void
 DriverMED_R_SMESHDS_Mesh
-::SetMeshName(string theMeshName)
+::SetMeshName(std::string theMeshName)
 {
   myMeshName = theMeshName;
 }
@@ -61,7 +60,7 @@ static const SMDS_MeshNode*
 FindNode(const SMDS_Mesh* theMesh, TInt theId){
   const SMDS_MeshNode* aNode = theMesh->FindNode(theId);
   if(aNode) return aNode;
-  EXCEPTION(runtime_error,"SMDS_Mesh::FindNode - cannot find a SMDS_MeshNode for ID = "<<theId);
+  EXCEPTION(std::runtime_error,"SMDS_Mesh::FindNode - cannot find a SMDS_MeshNode for ID = "<<theId);
 }
 
 
@@ -84,9 +83,9 @@ DriverMED_R_SMESHDS_Mesh
        //---------------------
        PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
 
-        string aMeshName;
+        std::string aMeshName;
         if (myMeshId != -1) {
-          ostringstream aMeshNameStr;
+          std::ostringstream aMeshNameStr;
           aMeshNameStr<<myMeshId;
           aMeshName = aMeshNameStr.str();
         } else {
@@ -113,10 +112,19 @@ DriverMED_R_SMESHDS_Mesh
            
             TInt aNbGrp = aFamilyInfo->GetNbGroup();
             if(MYDEBUG) MESSAGE("belong to " << aNbGrp << " groups");
+           bool isAttrOk = false;
+           if(aFamilyInfo->GetNbAttr() == aNbGrp)
+             isAttrOk = true;
             for (TInt iGr = 0; iGr < aNbGrp; iGr++) {
-              string aGroupName = aFamilyInfo->GetGroupName(iGr);
+              std::string aGroupName = aFamilyInfo->GetGroupName(iGr);
+              if(isAttrOk){
+               TInt anAttrVal = aFamilyInfo->GetAttrVal(iGr);
+               aFamily->SetGroupAttributVal(anAttrVal);
+             }
+             
               if(MYDEBUG) MESSAGE(aGroupName);
               aFamily->AddGroupName(aGroupName);
+             
             }
             aFamily->SetId( aFamId );
             myFamilies[aFamId] = aFamily;
@@ -124,15 +132,17 @@ DriverMED_R_SMESHDS_Mesh
         }
 
        if (aMeshInfo->GetType() == MED::eSTRUCTURE){
-         bool aRes = buildMeshGrille(aMed,aMeshInfo);
+         /*bool aRes = */buildMeshGrille(aMed,aMeshInfo);
          continue;
        }
 
         // Reading MED nodes to the corresponding SMDS structure
        //------------------------------------------------------
-      PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo);
-       if(!aNodeInfo)
+        PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo);
+       if (!aNodeInfo) {
+          aResult = DRS_FAIL;
          continue;
+        }
 
        PCoordHelper aCoordHelper = GetCoordHelper(aNodeInfo);
 
@@ -180,9 +190,9 @@ DriverMED_R_SMESHDS_Mesh
          for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
            const EGeometrieElement& aGeom = aGeom2SizeIter->first;
 
-           switch(aGeom){
-           case ePOINT1:
-             break;
+           switch(aGeom) {
+//         case ePOINT1: ## PAL16410
+//           break;
            case ePOLYGONE: {
               PPolygoneInfo aPolygoneInfo = aMed->GetPPolygoneInfo(aMeshInfo,anEntity,aGeom);
               EBooleen anIsElemNum = takeNumbers ? aPolygoneInfo->IsElemNum() : eFAUX;
@@ -343,9 +353,10 @@ DriverMED_R_SMESHDS_Mesh
                 case ePENTA15: aNbNodes = 15; break;
                 case eHEXA8:   aNbNodes = 8;  break;
                 case eHEXA20:  aNbNodes = 20; break;
+                case ePOINT1:  aNbNodes = 1;  break;
                 default:;
                 }
-                vector<TInt> aNodeIds(aNbNodes);
+                std::vector<TInt> aNodeIds(aNbNodes);
                 bool anIsValidConnect = false;
                 TCConnSlice aConnSlice = aCellInfo->GetConnSlice(iElem);
 #ifndef _DEXCEPT_
@@ -376,14 +387,14 @@ DriverMED_R_SMESHDS_Mesh
                   continue;
 
                 bool isRenum = false;
-                SMDS_MeshElement* anElement = NULL;
+                const SMDS_MeshElement* anElement = NULL;
                 TInt aFamNum = aCellInfo->GetFamNum(iElem);
 #ifndef _DEXCEPT_
                 try{
 #endif
                   //MESSAGE("Try to create element # " << iElem << " with id = "
                   //        << aCellInfo->GetElemNum(iElem));
-                  switch(aGeom){
+                  switch(aGeom) {
                   case eSEG2:
                     if(anIsElemNum)
                       anElement = myMesh->AddEdgeWithID(aNodeIds[0],
@@ -669,6 +680,10 @@ DriverMED_R_SMESHDS_Mesh
                       isRenum = anIsElemNum;
                     }
                     break;
+
+                  case ePOINT1:
+                    anElement = FindNode(myMesh,aNodeIds[0]);
+                    break;
                   }
 #ifndef _DEXCEPT_
                 }catch(const std::exception& exc){
@@ -714,9 +729,9 @@ DriverMED_R_SMESHDS_Mesh
   return aResult;
 }
 
-list<string> DriverMED_R_SMESHDS_Mesh::GetMeshNames(Status& theStatus)
+std::list<std::string> DriverMED_R_SMESHDS_Mesh::GetMeshNames(Status& theStatus)
 {
-  list<string> aMeshNames;
+  std::list<std::string> aMeshNames;
 
   try {
     if(MYDEBUG) MESSAGE("GetMeshNames - myFile : " << myFile);
@@ -742,17 +757,17 @@ list<string> DriverMED_R_SMESHDS_Mesh::GetMeshNames(Status& theStatus)
   return aMeshNames;
 }
 
-list<TNameAndType> DriverMED_R_SMESHDS_Mesh::GetGroupNamesAndTypes()
+std::list<TNameAndType> DriverMED_R_SMESHDS_Mesh::GetGroupNamesAndTypes()
 {
-  list<TNameAndType> aResult;
-  set<TNameAndType> aResGroupNames;
+  std::list<TNameAndType> aResult;
+  std::set<TNameAndType> aResGroupNames;
 
-  map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
+  std::map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
   for (; aFamsIter != myFamilies.end(); aFamsIter++)
   {
     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
     const MED::TStringSet& aGroupNames = aFamily->GetGroupNames();
-    set<string>::const_iterator aGrNamesIter = aGroupNames.begin();
+    std::set<std::string>::const_iterator aGrNamesIter = aGroupNames.begin();
     for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
     {
       TNameAndType aNameAndType = make_pair( *aGrNamesIter, aFamily->GetType() );
@@ -770,25 +785,28 @@ list<TNameAndType> DriverMED_R_SMESHDS_Mesh::GetGroupNamesAndTypes()
 
 void DriverMED_R_SMESHDS_Mesh::GetGroup(SMESHDS_Group* theGroup)
 {
-  string aGroupName (theGroup->GetStoreName());
+  std::string aGroupName (theGroup->GetStoreName());
   if(MYDEBUG) MESSAGE("Get Group " << aGroupName);
 
-  map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
+  std::map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
   for (; aFamsIter != myFamilies.end(); aFamsIter++)
   {
     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
     if (aFamily->GetType() == theGroup->GetType() && aFamily->MemberOf(aGroupName))
     {
-      const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
-      set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
+      const std::set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
+      std::set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
       const SMDS_MeshElement * element = 0;
       for (; anElemsIter != anElements.end(); anElemsIter++)
       {
         element = *anElemsIter;
        theGroup->SMDSGroup().Add(element);
+       int aGroupAttrVal = aFamily->GetGroupAttributVal();
+       if( aGroupAttrVal != 0)
+         theGroup->SetColorGroup(aGroupAttrVal);
       }
       if ( element )
-        theGroup->SetType( element->GetType() );
+        theGroup->SetType( theGroup->SMDSGroup().GetType() );
     }
   }
 }
@@ -798,15 +816,15 @@ void DriverMED_R_SMESHDS_Mesh::GetSubMesh (SMESHDS_SubMesh* theSubMesh,
 {
   char submeshGrpName[ 30 ];
   sprintf( submeshGrpName, "SubMesh %d", theId );
-  string aName (submeshGrpName);
-  map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
+  std::string aName (submeshGrpName);
+  std::map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
   for (; aFamsIter != myFamilies.end(); aFamsIter++)
   {
     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
     if (aFamily->MemberOf(aName))
     {
-      const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
-      set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
+      const std::set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
+      std::set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
       if (aFamily->GetType() == SMDSAbs_Node)
       {
         for (; anElemsIter != anElements.end(); anElemsIter++)
@@ -828,21 +846,21 @@ void DriverMED_R_SMESHDS_Mesh::GetSubMesh (SMESHDS_SubMesh* theSubMesh,
 
 void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes ()
 {
-  map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
+  std::map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
   for (; aFamsIter != myFamilies.end(); aFamsIter++)
   {
     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
     MED::TStringSet aGroupNames = aFamily->GetGroupNames();
-    set<string>::iterator aGrNamesIter = aGroupNames.begin();
+    std::set<std::string>::iterator aGrNamesIter = aGroupNames.begin();
     for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
     {
-      string aName = *aGrNamesIter;
+      std::string aName = *aGrNamesIter;
       // Check, if this is a Group or SubMesh name
-      if (aName.substr(0, 7) == string("SubMesh"))
+      if (aName.substr(0, 7) == std::string("SubMesh"))
       {
-        int Id = atoi(string(aName).substr(7).c_str());
-        set<const SMDS_MeshElement *> anElements = aFamily->GetElements();
-        set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
+        int Id = atoi(std::string(aName).substr(7).c_str());
+        std::set<const SMDS_MeshElement *> anElements = aFamily->GetElements();
+        std::set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
         if (aFamily->GetType() == SMDSAbs_Node)
         {
           for (; anElemsIter != anElements.end(); anElemsIter++)
@@ -884,7 +902,7 @@ void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes ()
 bool DriverMED_R_SMESHDS_Mesh::checkFamilyID(DriverMED_FamilyPtr & aFamily, int anID) const
 {
   if ( !aFamily || aFamily->GetId() != anID ) {
-    map<int, DriverMED_FamilyPtr>::const_iterator i_fam = myFamilies.find(anID);
+    std::map<int, DriverMED_FamilyPtr>::const_iterator i_fam = myFamilies.find(anID);
     if ( i_fam == myFamilies.end() )
       return false;
     aFamily = i_fam->second;
@@ -915,18 +933,17 @@ bool DriverMED_R_SMESHDS_Mesh::buildMeshGrille(const MED::PWrapper& theWrapper,
     for(MED::TInt iDim=0;iDim<aMeshDim;iDim++)
       aCoords[(int)iDim] = aMEDNodeCoord[(int)iDim];
     aNode = myMesh->AddNodeWithID(aCoords[0],aCoords[1],aCoords[2],(int)iNode);
-  }
 
-  /* not implemented FAMILY
-     
-  TInt aFamNum = aNodeInfo->GetFamNum(iElem);
-  if ( checkFamilyID ( aFamily, aFamNum ))
-    {
-      aFamily->AddElement(aNode);
-      aFamily->SetType(SMDSAbs_Node);
+    if((aGrilleInfo->myFamNumNode).size() > 0){
+      TInt aFamNum = aGrilleInfo->GetFamNumNode(iNode);
+      if ( checkFamilyID ( aFamily, aFamNum ))
+       {
+         aFamily->AddElement(aNode);
+         aFamily->SetType(SMDSAbs_Node);
+       }
     }
     
-  */
+  }
 
   SMDS_MeshElement* anElement = NULL;
   MED::TIntVector aNodeIds;
@@ -936,7 +953,7 @@ bool DriverMED_R_SMESHDS_Mesh::buildMeshGrille(const MED::PWrapper& theWrapper,
     case MED::eSEG2:
       if(aNodeIds.size() != 2){
        res = false;
-       EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 2!="<<aNodeIds.size());
+       EXCEPTION(std::runtime_error,"buildMeshGrille Error. Incorrect size of ids 2!="<<aNodeIds.size());
       }
       anElement = myMesh->AddEdgeWithID(aNodeIds[0],
                                        aNodeIds[1],
@@ -945,7 +962,7 @@ bool DriverMED_R_SMESHDS_Mesh::buildMeshGrille(const MED::PWrapper& theWrapper,
     case MED::eQUAD4:
       if(aNodeIds.size() != 4){
        res = false;
-       EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 4!="<<aNodeIds.size());
+       EXCEPTION(std::runtime_error,"buildMeshGrille Error. Incorrect size of ids 4!="<<aNodeIds.size());
       }
       anElement = myMesh->AddFaceWithID(aNodeIds[0],
                                        aNodeIds[2],
@@ -956,7 +973,7 @@ bool DriverMED_R_SMESHDS_Mesh::buildMeshGrille(const MED::PWrapper& theWrapper,
     case MED::eHEXA8:
       if(aNodeIds.size() != 8){
        res = false;
-       EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 8!="<<aNodeIds.size());
+       EXCEPTION(std::runtime_error,"buildMeshGrille Error. Incorrect size of ids 8!="<<aNodeIds.size());
       }
       anElement = myMesh->AddVolumeWithID(aNodeIds[0],
                                          aNodeIds[2],
@@ -971,6 +988,14 @@ bool DriverMED_R_SMESHDS_Mesh::buildMeshGrille(const MED::PWrapper& theWrapper,
     default:
       break;
     }
+    
+    if((aGrilleInfo->myFamNum).size() > 0){
+      TInt aFamNum = aGrilleInfo->GetFamNum(iCell);
+      if ( checkFamilyID ( aFamily, aFamNum )){
+       aFamily->AddElement(anElement);
+       aFamily->SetType(anElement->GetType());
+      }
+    }
   }
 
   return res;