Back to index

salome-smesh  6.5.0
DriverMED_R_SMESHDS_Mesh.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SMESH DriverMED : driver to read and write 'med' files
00024 //  File   : DriverMED_R_SMESHDS_Mesh.cxx
00025 //  Module : SMESH
00026 //
00027 #include "DriverMED_R_SMESHDS_Mesh.h"
00028 #include "SMESHDS_Mesh.hxx"
00029 #include "utilities.h"
00030 
00031 #include "DriverMED_Family.h"
00032 
00033 #include "SMESHDS_Group.hxx"
00034 
00035 #include "MED_Factory.hxx"
00036 #include "MED_CoordUtils.hxx"
00037 #include "MED_Utilities.hxx"
00038 
00039 #include <stdlib.h>
00040 
00041 #ifdef _DEBUG_
00042 static int MYDEBUG = 1;
00043 //#define _DEXCEPT_
00044 #else
00045 static int MYDEBUG = 0;
00046 #endif
00047 
00048 #define _EDF_NODE_IDS_
00049 
00050 using namespace MED;
00051 using namespace std;
00052 
00053 void
00054 DriverMED_R_SMESHDS_Mesh
00055 ::SetMeshName(string theMeshName)
00056 {
00057   myMeshName = theMeshName;
00058 }
00059 
00060 static const SMDS_MeshNode* 
00061 FindNode(const SMDS_Mesh* theMesh, TInt theId)
00062 {
00063   const SMDS_MeshNode* aNode = theMesh->FindNode(theId);
00064   if(aNode) return aNode;
00065   EXCEPTION(runtime_error,"SMDS_Mesh::FindNode - cannot find a SMDS_MeshNode for ID = "<<theId);
00066 }
00067 
00068 
00069 Driver_Mesh::Status 
00070 DriverMED_R_SMESHDS_Mesh
00071 ::Perform()
00072 {
00073   Status aResult = DRS_FAIL;
00074 #ifndef _DEXCEPT_
00075   try{
00076 #endif
00077     myFamilies.clear();
00078     if(MYDEBUG) MESSAGE("Perform - myFile : "<<myFile);
00079     PWrapper aMed = CrWrapper(myFile,true);
00080 
00081     aResult = DRS_EMPTY;
00082     if(TInt aNbMeshes = aMed->GetNbMeshes()){
00083       for(int iMesh = 0; iMesh < aNbMeshes; iMesh++){
00084         // Reading the MED mesh
00085         //---------------------
00086         PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
00087 
00088         string aMeshName;
00089         if (myMeshId != -1) {
00090           ostringstream aMeshNameStr;
00091           aMeshNameStr<<myMeshId;
00092           aMeshName = aMeshNameStr.str();
00093         } else {
00094           aMeshName = myMeshName;
00095         }
00096         if(MYDEBUG) MESSAGE("Perform - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
00097         if(aMeshName != aMeshInfo->GetName()) continue;
00098         aResult = DRS_OK;
00099 
00100         // Reading MED families to the temporary structure
00101         //------------------------------------------------
00102         TErr anErr;
00103         TInt aNbFams = aMed->GetNbFamilies(aMeshInfo);
00104         if(MYDEBUG) MESSAGE("Read " << aNbFams << " families");
00105         for (TInt iFam = 0; iFam < aNbFams; iFam++) {
00106           PFamilyInfo aFamilyInfo = aMed->GetPFamilyInfo(aMeshInfo,iFam+1,&anErr);
00107           if(anErr >= 0){
00108             TInt aFamId = aFamilyInfo->GetId();
00109             if(MYDEBUG) MESSAGE("Family " << aFamId << " :");
00110             
00111             DriverMED_FamilyPtr aFamily (new DriverMED_Family);
00112             
00113             TInt aNbGrp = aFamilyInfo->GetNbGroup();
00114             if(MYDEBUG) MESSAGE("belong to " << aNbGrp << " groups");
00115             bool isAttrOk = false;
00116             if(aFamilyInfo->GetNbAttr() == aNbGrp)
00117               isAttrOk = true;
00118             for (TInt iGr = 0; iGr < aNbGrp; iGr++) {
00119               string aGroupName = aFamilyInfo->GetGroupName(iGr);
00120               if(isAttrOk){
00121                 TInt anAttrVal = aFamilyInfo->GetAttrVal(iGr);
00122                 aFamily->SetGroupAttributVal(anAttrVal);
00123               }
00124               
00125               if(MYDEBUG) MESSAGE(aGroupName);
00126               aFamily->AddGroupName(aGroupName);
00127               
00128             }
00129             aFamily->SetId( aFamId );
00130             myFamilies[aFamId] = aFamily;
00131           }
00132         }
00133 
00134         if (aMeshInfo->GetType() == MED::eSTRUCTURE){
00135           /*bool aRes = */buildMeshGrille(aMed,aMeshInfo);
00136           continue;
00137         }
00138 
00139         // Reading MED nodes to the corresponding SMDS structure
00140         //------------------------------------------------------
00141         PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo);
00142         if (!aNodeInfo) {
00143           aResult = DRS_FAIL;
00144           continue;
00145         }
00146         aMeshInfo->myDim=aMeshInfo->mySpaceDim;// ignore meshdim in MEDFile because it can be false
00147         PCoordHelper aCoordHelper = GetCoordHelper(aNodeInfo);
00148 
00149         EBooleen anIsNodeNum = aNodeInfo->IsElemNum();
00150         TInt aNbElems = aNodeInfo->GetNbElem();
00151         if(MYDEBUG) MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbElems<<"; anIsNodeNum = "<<anIsNodeNum);
00152         DriverMED_FamilyPtr aFamily;
00153         for(TInt iElem = 0; iElem < aNbElems; iElem++){
00154           TCCoordSlice aCoordSlice = aNodeInfo->GetCoordSlice(iElem);
00155           double aCoords[3] = {0.0, 0.0, 0.0};
00156           for(TInt iDim = 0; iDim < 3; iDim++)
00157             aCoords[iDim] = aCoordHelper->GetCoord(aCoordSlice,iDim);
00158           const SMDS_MeshNode* aNode;
00159           if(anIsNodeNum) {
00160             aNode = myMesh->AddNodeWithID
00161               (aCoords[0],aCoords[1],aCoords[2],aNodeInfo->GetElemNum(iElem));
00162           } else {
00163             aNode = myMesh->AddNodeWithID
00164               (aCoords[0],aCoords[1],aCoords[2], iElem+1);
00165           }
00166 
00167           // Save reference to this node from its family
00168           TInt aFamNum = aNodeInfo->GetFamNum(iElem);
00169           if ( checkFamilyID ( aFamily, aFamNum ))
00170           {
00171             aFamily->AddElement(aNode);
00172             aFamily->SetType(SMDSAbs_Node);
00173           }
00174         }
00175 
00176         // Reading pre information about all MED cells
00177         //--------------------------------------------
00178         typedef MED::TVector<int> TNodeIds;
00179         bool takeNumbers = true;  // initially we trust the numbers from file
00180         MED::TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo);
00181         MED::TEntityInfo::iterator anEntityIter = aEntityInfo.begin();
00182         for(; anEntityIter != aEntityInfo.end(); anEntityIter++){
00183           const EEntiteMaillage& anEntity = anEntityIter->first;
00184           if(anEntity == eNOEUD) continue;
00185           // Reading MED cells to the corresponding SMDS structure
00186           //------------------------------------------------------
00187           const MED::TGeom2Size& aGeom2Size = anEntityIter->second;
00188           MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
00189           for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
00190             const EGeometrieElement& aGeom = aGeom2SizeIter->first;
00191 
00192             switch(aGeom) {
00193 //          case ePOINT1: ## PAL16410
00194 //            break;
00195             case ePOLYGONE: {
00196               PPolygoneInfo aPolygoneInfo = aMed->GetPPolygoneInfo(aMeshInfo,anEntity,aGeom);
00197               EBooleen anIsElemNum = takeNumbers ? aPolygoneInfo->IsElemNum() : eFAUX;
00198               
00199               TInt aNbElem = aPolygoneInfo->GetNbElem();
00200               for(TInt iElem = 0; iElem < aNbElem; iElem++){
00201                 MED::TCConnSlice aConnSlice = aPolygoneInfo->GetConnSlice(iElem);
00202                 TInt aNbConn = aPolygoneInfo->GetNbConn(iElem);
00203                 TNodeIds aNodeIds(aNbConn);
00204 #ifdef _EDF_NODE_IDS_
00205                 if(anIsNodeNum)
00206                   for(TInt iConn = 0; iConn < aNbConn; iConn++)
00207                     aNodeIds[iConn] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
00208                 else
00209                   for(TInt iConn = 0; iConn < aNbConn; iConn++)
00210                     aNodeIds[iConn] = aConnSlice[iConn];
00211 #else
00212                 for(TInt iConn = 0; iConn < aNbConn; iConn++)
00213                   aNodeIds[iConn] = aConnSlice[iConn];
00214 #endif
00215                 bool isRenum = false;
00216                 SMDS_MeshElement* anElement = NULL;
00217                 TInt aFamNum = aPolygoneInfo->GetFamNum(iElem);
00218 
00219 #ifndef _DEXCEPT_
00220                 try{
00221 #endif
00222                   if(anIsElemNum){
00223                     TInt anElemId = aPolygoneInfo->GetElemNum(iElem);
00224                     anElement = myMesh->AddPolygonalFaceWithID(aNodeIds,anElemId);
00225                   }
00226                   if(!anElement){
00227                     vector<const SMDS_MeshNode*> aNodes(aNbConn);
00228                     for(TInt iConn = 0; iConn < aNbConn; iConn++)
00229                       aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
00230                     anElement = myMesh->AddPolygonalFace(aNodes);
00231                     isRenum = anIsElemNum;
00232                   }
00233 #ifndef _DEXCEPT_
00234                 }catch(const std::exception& exc){
00235                   aResult = DRS_FAIL;
00236                 }catch (...){
00237                   aResult = DRS_FAIL;
00238                 }
00239 #endif
00240                 if(!anElement){
00241                   aResult = DRS_WARN_SKIP_ELEM;
00242                 }else{
00243                   if(isRenum){
00244                     anIsElemNum = eFAUX;
00245                     takeNumbers = false;
00246                     if(aResult < DRS_WARN_RENUMBER)
00247                       aResult = DRS_WARN_RENUMBER;
00248                   }
00249                   if ( checkFamilyID ( aFamily, aFamNum ))
00250                   {
00251                     // Save reference to this element from its family
00252                     aFamily->AddElement(anElement);
00253                     aFamily->SetType(anElement->GetType());
00254                   }
00255                 }
00256               }
00257               break;
00258             }
00259             case ePOLYEDRE: {
00260               PPolyedreInfo aPolyedreInfo = aMed->GetPPolyedreInfo(aMeshInfo,anEntity,aGeom);
00261               EBooleen anIsElemNum = takeNumbers ? aPolyedreInfo->IsElemNum() : eFAUX;
00262 
00263               TInt aNbElem = aPolyedreInfo->GetNbElem();
00264               for(TInt iElem = 0; iElem < aNbElem; iElem++){
00265                 MED::TCConnSliceArr aConnSliceArr = aPolyedreInfo->GetConnSliceArr(iElem);
00266                 TInt aNbFaces = aConnSliceArr.size();
00267                 typedef MED::TVector<int> TQuantities;
00268                 TQuantities aQuantities(aNbFaces);
00269                 TInt aNbNodes = aPolyedreInfo->GetNbNodes(iElem);
00270                 TNodeIds aNodeIds(aNbNodes);
00271                 for(TInt iFace = 0, iNode = 0; iFace < aNbFaces; iFace++){
00272                   MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
00273                   TInt aNbConn = aConnSlice.size();
00274                   aQuantities[iFace] = aNbConn;
00275 #ifdef _EDF_NODE_IDS_
00276                   if(anIsNodeNum)
00277                     for(TInt iConn = 0; iConn < aNbConn; iConn++)
00278                       {
00279                       aNodeIds[iNode] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
00280                       iNode++;
00281                       }
00282                   else
00283                     for(TInt iConn = 0; iConn < aNbConn; iConn++)
00284                       {
00285                       aNodeIds[iNode++] = aConnSlice[iConn];
00286                       }
00287 #else
00288                   for(TInt iConn = 0; iConn < aNbConn; iConn++)
00289                     {
00290                     aNodeIds[iNode++] = aConnSlice[iConn];
00291                     }
00292 #endif          
00293                 }
00294 
00295                 bool isRenum = false;
00296                 SMDS_MeshElement* anElement = NULL;
00297                 TInt aFamNum = aPolyedreInfo->GetFamNum(iElem);
00298                 
00299 #ifndef _DEXCEPT_
00300                 try{
00301 #endif
00302                   if(anIsElemNum){
00303                     TInt anElemId = aPolyedreInfo->GetElemNum(iElem);
00304                     anElement = myMesh->AddPolyhedralVolumeWithID(aNodeIds,aQuantities,anElemId);
00305                   }
00306                   if(!anElement){
00307                     vector<const SMDS_MeshNode*> aNodes(aNbNodes);
00308                     for(TInt iConn = 0; iConn < aNbNodes; iConn++)
00309                       aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
00310                     anElement = myMesh->AddPolyhedralVolume(aNodes,aQuantities);
00311                     isRenum = anIsElemNum;
00312                   }
00313 #ifndef _DEXCEPT_
00314                 }catch(const std::exception& exc){
00315                   aResult = DRS_FAIL;
00316                 }catch(...){
00317                   aResult = DRS_FAIL;
00318                 }
00319 #endif          
00320                 if(!anElement){
00321                   aResult = DRS_WARN_SKIP_ELEM;
00322                 }else{
00323                   if(isRenum){
00324                     anIsElemNum = eFAUX;
00325                     takeNumbers = false;
00326                     if (aResult < DRS_WARN_RENUMBER)
00327                       aResult = DRS_WARN_RENUMBER;
00328                   }
00329                   if ( checkFamilyID ( aFamily, aFamNum )) {
00330                     // Save reference to this element from its family
00331                     aFamily->AddElement(anElement);
00332                     aFamily->SetType(anElement->GetType());
00333                   }
00334                 }
00335               }
00336               break;
00337             }
00338             default: {
00339               PCellInfo aCellInfo = aMed->GetPCellInfo(aMeshInfo,anEntity,aGeom);
00340               EBooleen anIsElemNum = takeNumbers ? aCellInfo->IsElemNum() : eFAUX;
00341               TInt aNbElems = aCellInfo->GetNbElem();
00342               if(MYDEBUG) MESSAGE("Perform - anEntity = "<<anEntity<<"; anIsElemNum = "<<anIsElemNum);
00343               if(MYDEBUG) MESSAGE("Perform - aGeom = "<<aGeom<<"; aNbElems = "<<aNbElems);
00344 
00345               TInt aNbNodes = -1;
00346               switch(aGeom){
00347               case eSEG2:    aNbNodes = 2;  break;
00348               case eSEG3:    aNbNodes = 3;  break;
00349               case eTRIA3:   aNbNodes = 3;  break;
00350               case eTRIA6:   aNbNodes = 6;  break;
00351               case eQUAD4:   aNbNodes = 4;  break;
00352               case eQUAD8:   aNbNodes = 8;  break;
00353               case eQUAD9:   aNbNodes = 9;  break;
00354               case eTETRA4:  aNbNodes = 4;  break;
00355               case eTETRA10: aNbNodes = 10; break;
00356               case ePYRA5:   aNbNodes = 5;  break;
00357               case ePYRA13:  aNbNodes = 13; break;
00358               case ePENTA6:  aNbNodes = 6;  break;
00359               case ePENTA15: aNbNodes = 15; break;
00360               case eHEXA8:   aNbNodes = 8;  break;
00361               case eHEXA20:  aNbNodes = 20; break;
00362               case eHEXA27:  aNbNodes = 27; break;
00363               case eOCTA12:  aNbNodes = 12; break;
00364               case ePOINT1:  aNbNodes = 1;  break;
00365               default:;
00366               }
00367               vector<TInt> aNodeIds(aNbNodes);
00368               for(int iElem = 0; iElem < aNbElems; iElem++){
00369                 bool anIsValidConnect = false;
00370                 TCConnSlice aConnSlice = aCellInfo->GetConnSlice(iElem);
00371 #ifndef _DEXCEPT_
00372                 try{
00373 #endif
00374 #ifdef _EDF_NODE_IDS_
00375                   if(anIsNodeNum)
00376                     for(int iNode = 0; iNode < aNbNodes; iNode++)
00377                       aNodeIds[iNode] = aNodeInfo->GetElemNum(aConnSlice[iNode] - 1);
00378                   else
00379                     for(int iNode = 0; iNode < aNbNodes; iNode++)
00380                       aNodeIds[iNode] = aConnSlice[iNode];
00381 #else
00382                   for(int iNode = 0; iNode < aNbNodes; iNode++)
00383                     aNodeIds[iNode] = aConnSlice[iNode];
00384 #endif
00385                   anIsValidConnect = true;
00386 #ifndef _DEXCEPT_
00387                 }catch(const std::exception& exc){
00388                   INFOS("Following exception was caught:\n\t"<<exc.what());
00389                   aResult = DRS_FAIL;
00390                 }catch(...){
00391                   INFOS("Unknown exception was cought !!!");
00392                   aResult = DRS_FAIL;
00393                 }
00394 #endif          
00395                 if(!anIsValidConnect)
00396                   continue;
00397 
00398                 bool isRenum = false;
00399                 const SMDS_MeshElement* anElement = NULL;
00400                 TInt aFamNum = aCellInfo->GetFamNum(iElem);
00401 #ifndef _DEXCEPT_
00402                 try{
00403 #endif
00404                   //MESSAGE("Try to create element # " << iElem << " with id = "
00405                   //        << aCellInfo->GetElemNum(iElem));
00406                   switch(aGeom) {
00407                   case ePOINT1:
00408                     //anElement = FindNode(myMesh,aNodeIds[0]);
00409                     if(anIsElemNum)
00410                       anElement = myMesh->Add0DElementWithID
00411                         (aNodeIds[0], aCellInfo->GetElemNum(iElem));
00412                     if (!anElement) {
00413                       anElement = myMesh->Add0DElement(FindNode(myMesh,aNodeIds[0]));
00414                       isRenum = anIsElemNum;
00415                     }
00416                     break;
00417                   case eSEG2:
00418                     if(anIsElemNum)
00419                       anElement = myMesh->AddEdgeWithID(aNodeIds[0],
00420                                                         aNodeIds[1],
00421                                                         aCellInfo->GetElemNum(iElem));
00422                     if (!anElement) {
00423                       anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
00424                                                   FindNode(myMesh,aNodeIds[1]));
00425                       isRenum = anIsElemNum;
00426                     }
00427                     break;
00428                   case eSEG3:
00429                     if(anIsElemNum)
00430                       anElement = myMesh->AddEdgeWithID(aNodeIds[0],
00431                                                         aNodeIds[1],
00432                                                         aNodeIds[2],
00433                                                         aCellInfo->GetElemNum(iElem));
00434                     if (!anElement) {
00435                       anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
00436                                                   FindNode(myMesh,aNodeIds[1]),
00437                                                   FindNode(myMesh,aNodeIds[2]));
00438                       isRenum = anIsElemNum;
00439                     }
00440                     break;
00441                   case eTRIA3:
00442                     aNbNodes = 3;
00443                     if(anIsElemNum)
00444                       anElement = myMesh->AddFaceWithID(aNodeIds[0],
00445                                                         aNodeIds[1],
00446                                                         aNodeIds[2],
00447                                                         aCellInfo->GetElemNum(iElem));
00448                     if (!anElement) {
00449                       anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
00450                                                   FindNode(myMesh,aNodeIds[1]),
00451                                                   FindNode(myMesh,aNodeIds[2]));
00452                       isRenum = anIsElemNum;
00453                     }
00454                     break;
00455                   case eTRIA6:
00456                     aNbNodes = 6;
00457                     if(anIsElemNum)
00458                       anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
00459                                                         aNodeIds[2], aNodeIds[3],
00460                                                         aNodeIds[4], aNodeIds[5],
00461                                                         aCellInfo->GetElemNum(iElem));
00462                     if (!anElement) {
00463                       anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
00464                                                   FindNode(myMesh,aNodeIds[1]),
00465                                                   FindNode(myMesh,aNodeIds[2]),
00466                                                   FindNode(myMesh,aNodeIds[3]),
00467                                                   FindNode(myMesh,aNodeIds[4]),
00468                                                   FindNode(myMesh,aNodeIds[5]));
00469                       isRenum = anIsElemNum;
00470                     }
00471                     break;
00472                   case eQUAD4:
00473                     aNbNodes = 4;
00474                     if(anIsElemNum)
00475                       anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
00476                                                         aNodeIds[2], aNodeIds[3],
00477                                                         aCellInfo->GetElemNum(iElem));
00478                     if (!anElement) {
00479                       anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
00480                                                   FindNode(myMesh,aNodeIds[1]),
00481                                                   FindNode(myMesh,aNodeIds[2]),
00482                                                   FindNode(myMesh,aNodeIds[3]));
00483                       isRenum = anIsElemNum;
00484                     }
00485                     break;
00486                   case eQUAD8:
00487                     aNbNodes = 8;
00488                     if(anIsElemNum)
00489                       anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
00490                                                         aNodeIds[2], aNodeIds[3],
00491                                                         aNodeIds[4], aNodeIds[5],
00492                                                         aNodeIds[6], aNodeIds[7],
00493                                                         aCellInfo->GetElemNum(iElem));
00494                     if (!anElement) {
00495                       anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
00496                                                   FindNode(myMesh,aNodeIds[1]),
00497                                                   FindNode(myMesh,aNodeIds[2]),
00498                                                   FindNode(myMesh,aNodeIds[3]),
00499                                                   FindNode(myMesh,aNodeIds[4]),
00500                                                   FindNode(myMesh,aNodeIds[5]),
00501                                                   FindNode(myMesh,aNodeIds[6]),
00502                                                   FindNode(myMesh,aNodeIds[7]));
00503                       isRenum = anIsElemNum;
00504                     }
00505                     break;
00506                   case eQUAD9:
00507                     aNbNodes = 9;
00508                     if(anIsElemNum)
00509                       anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
00510                                                         aNodeIds[2], aNodeIds[3],
00511                                                         aNodeIds[4], aNodeIds[5],
00512                                                         aNodeIds[6], aNodeIds[7], aNodeIds[8],
00513                                                         aCellInfo->GetElemNum(iElem));
00514                     if (!anElement) {
00515                       anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
00516                                                   FindNode(myMesh,aNodeIds[1]),
00517                                                   FindNode(myMesh,aNodeIds[2]),
00518                                                   FindNode(myMesh,aNodeIds[3]),
00519                                                   FindNode(myMesh,aNodeIds[4]),
00520                                                   FindNode(myMesh,aNodeIds[5]),
00521                                                   FindNode(myMesh,aNodeIds[6]),
00522                                                   FindNode(myMesh,aNodeIds[7]),
00523                                                   FindNode(myMesh,aNodeIds[8]));
00524                       isRenum = anIsElemNum;
00525                     }
00526                     break;
00527                   case eTETRA4:
00528                     aNbNodes = 4;
00529                     if(anIsElemNum)
00530                       anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
00531                                                           aNodeIds[2], aNodeIds[3],
00532                                                           aCellInfo->GetElemNum(iElem));
00533                     if (!anElement) {
00534                       anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
00535                                                     FindNode(myMesh,aNodeIds[1]),
00536                                                     FindNode(myMesh,aNodeIds[2]),
00537                                                     FindNode(myMesh,aNodeIds[3]));
00538                       isRenum = anIsElemNum;
00539                     }
00540                     break;
00541                   case eTETRA10:
00542                     aNbNodes = 10;
00543                     if(anIsElemNum)
00544                       anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
00545                                                           aNodeIds[2], aNodeIds[3],
00546                                                           aNodeIds[4], aNodeIds[5],
00547                                                           aNodeIds[6], aNodeIds[7],
00548                                                           aNodeIds[8], aNodeIds[9],
00549                                                           aCellInfo->GetElemNum(iElem));
00550                     if (!anElement) {
00551                       anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
00552                                                     FindNode(myMesh,aNodeIds[1]),
00553                                                     FindNode(myMesh,aNodeIds[2]),
00554                                                     FindNode(myMesh,aNodeIds[3]),
00555                                                     FindNode(myMesh,aNodeIds[4]),
00556                                                     FindNode(myMesh,aNodeIds[5]),
00557                                                     FindNode(myMesh,aNodeIds[6]),
00558                                                     FindNode(myMesh,aNodeIds[7]),
00559                                                     FindNode(myMesh,aNodeIds[8]),
00560                                                     FindNode(myMesh,aNodeIds[9]));
00561                       isRenum = anIsElemNum;
00562                     }
00563                     break;
00564                   case ePYRA5:
00565                     aNbNodes = 5;
00566                     if(anIsElemNum)
00567                       anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
00568                                                           aNodeIds[2], aNodeIds[3],
00569                                                           aNodeIds[4],
00570                                                           aCellInfo->GetElemNum(iElem));
00571                     if (!anElement) {
00572                       anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
00573                                                     FindNode(myMesh,aNodeIds[1]),
00574                                                     FindNode(myMesh,aNodeIds[2]),
00575                                                     FindNode(myMesh,aNodeIds[3]),
00576                                                     FindNode(myMesh,aNodeIds[4]));
00577                       isRenum = anIsElemNum;
00578                     }
00579                     break;
00580                   case ePYRA13:
00581                     aNbNodes = 13;
00582                     if(anIsElemNum)
00583                       anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
00584                                                           aNodeIds[2], aNodeIds[3],
00585                                                           aNodeIds[4], aNodeIds[5],
00586                                                           aNodeIds[6], aNodeIds[7],
00587                                                           aNodeIds[8], aNodeIds[9],
00588                                                           aNodeIds[10], aNodeIds[11],
00589                                                           aNodeIds[12],
00590                                                           aCellInfo->GetElemNum(iElem));
00591                     if (!anElement) {
00592                       anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
00593                                                     FindNode(myMesh,aNodeIds[1]),
00594                                                     FindNode(myMesh,aNodeIds[2]),
00595                                                     FindNode(myMesh,aNodeIds[3]),
00596                                                     FindNode(myMesh,aNodeIds[4]),
00597                                                     FindNode(myMesh,aNodeIds[5]),
00598                                                     FindNode(myMesh,aNodeIds[6]),
00599                                                     FindNode(myMesh,aNodeIds[7]),
00600                                                     FindNode(myMesh,aNodeIds[8]),
00601                                                     FindNode(myMesh,aNodeIds[9]),
00602                                                     FindNode(myMesh,aNodeIds[10]),
00603                                                     FindNode(myMesh,aNodeIds[11]),
00604                                                     FindNode(myMesh,aNodeIds[12]));
00605                       isRenum = anIsElemNum;
00606                     }
00607                     break;
00608                   case ePENTA6:
00609                     aNbNodes = 6;
00610                     if(anIsElemNum)
00611                       anElement = myMesh->AddVolumeWithID(aNodeIds[0],
00612                                                           aNodeIds[1],
00613                                                           aNodeIds[2],
00614                                                           aNodeIds[3],
00615                                                           aNodeIds[4],
00616                                                           aNodeIds[5],
00617                                                           aCellInfo->GetElemNum(iElem));
00618                     if (!anElement) {
00619                       anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
00620                                                     FindNode(myMesh,aNodeIds[1]),
00621                                                     FindNode(myMesh,aNodeIds[2]),
00622                                                     FindNode(myMesh,aNodeIds[3]),
00623                                                     FindNode(myMesh,aNodeIds[4]),
00624                                                     FindNode(myMesh,aNodeIds[5]));
00625                       isRenum = anIsElemNum;
00626                     }
00627                     break;
00628                   case ePENTA15:
00629                     aNbNodes = 15;
00630                     if(anIsElemNum)
00631                       anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
00632                                                           aNodeIds[2], aNodeIds[3],
00633                                                           aNodeIds[4], aNodeIds[5],
00634                                                           aNodeIds[6], aNodeIds[7],
00635                                                           aNodeIds[8], aNodeIds[9],
00636                                                           aNodeIds[10], aNodeIds[11],
00637                                                           aNodeIds[12], aNodeIds[13],
00638                                                           aNodeIds[14],
00639                                                           aCellInfo->GetElemNum(iElem));
00640                     if (!anElement) {
00641                       anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
00642                                                     FindNode(myMesh,aNodeIds[1]),
00643                                                     FindNode(myMesh,aNodeIds[2]),
00644                                                     FindNode(myMesh,aNodeIds[3]),
00645                                                   FindNode(myMesh,aNodeIds[4]),
00646                                                     FindNode(myMesh,aNodeIds[5]),
00647                                                     FindNode(myMesh,aNodeIds[6]),
00648                                                     FindNode(myMesh,aNodeIds[7]),
00649                                                     FindNode(myMesh,aNodeIds[8]),
00650                                                     FindNode(myMesh,aNodeIds[9]),
00651                                                     FindNode(myMesh,aNodeIds[10]),
00652                                                     FindNode(myMesh,aNodeIds[11]),
00653                                                     FindNode(myMesh,aNodeIds[12]),
00654                                                     FindNode(myMesh,aNodeIds[13]),
00655                                                     FindNode(myMesh,aNodeIds[14]));
00656                       isRenum = anIsElemNum;
00657                     }
00658                     break;
00659                   case eHEXA8:
00660                     aNbNodes = 8;
00661                     if(anIsElemNum)
00662                       anElement = myMesh->AddVolumeWithID(aNodeIds[0],
00663                                                           aNodeIds[1],
00664                                                           aNodeIds[2],
00665                                                           aNodeIds[3],
00666                                                           aNodeIds[4],
00667                                                           aNodeIds[5],
00668                                                           aNodeIds[6],
00669                                                           aNodeIds[7],
00670                                                           aCellInfo->GetElemNum(iElem));
00671                     if (!anElement) {
00672                       anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
00673                                                     FindNode(myMesh,aNodeIds[1]),
00674                                                     FindNode(myMesh,aNodeIds[2]),
00675                                                     FindNode(myMesh,aNodeIds[3]),
00676                                                     FindNode(myMesh,aNodeIds[4]),
00677                                                     FindNode(myMesh,aNodeIds[5]),
00678                                                     FindNode(myMesh,aNodeIds[6]),
00679                                                     FindNode(myMesh,aNodeIds[7]));
00680                       isRenum = anIsElemNum;
00681                     }
00682                     break;
00683 
00684                   case eHEXA20:
00685                     aNbNodes = 20;
00686                     if(anIsElemNum)
00687                       anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
00688                                                           aNodeIds[2], aNodeIds[3],
00689                                                           aNodeIds[4], aNodeIds[5],
00690                                                           aNodeIds[6], aNodeIds[7],
00691                                                           aNodeIds[8], aNodeIds[9],
00692                                                           aNodeIds[10], aNodeIds[11],
00693                                                           aNodeIds[12], aNodeIds[13],
00694                                                           aNodeIds[14], aNodeIds[15],
00695                                                           aNodeIds[16], aNodeIds[17],
00696                                                           aNodeIds[18], aNodeIds[19],
00697                                                           aCellInfo->GetElemNum(iElem));
00698                     if (!anElement) {
00699                       anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
00700                                                     FindNode(myMesh,aNodeIds[1]),
00701                                                     FindNode(myMesh,aNodeIds[2]),
00702                                                     FindNode(myMesh,aNodeIds[3]),
00703                                                     FindNode(myMesh,aNodeIds[4]),
00704                                                     FindNode(myMesh,aNodeIds[5]),
00705                                                     FindNode(myMesh,aNodeIds[6]),
00706                                                     FindNode(myMesh,aNodeIds[7]),
00707                                                     FindNode(myMesh,aNodeIds[8]),
00708                                                     FindNode(myMesh,aNodeIds[9]),
00709                                                     FindNode(myMesh,aNodeIds[10]),
00710                                                     FindNode(myMesh,aNodeIds[11]),
00711                                                     FindNode(myMesh,aNodeIds[12]),
00712                                                     FindNode(myMesh,aNodeIds[13]),
00713                                                     FindNode(myMesh,aNodeIds[14]),
00714                                                     FindNode(myMesh,aNodeIds[15]),
00715                                                     FindNode(myMesh,aNodeIds[16]),
00716                                                     FindNode(myMesh,aNodeIds[17]),
00717                                                     FindNode(myMesh,aNodeIds[18]),
00718                                                     FindNode(myMesh,aNodeIds[19]));
00719                       isRenum = anIsElemNum;
00720                     }
00721                     break;
00722 
00723                   case eHEXA27:
00724                     aNbNodes = 27;
00725                     if(anIsElemNum)
00726                       anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
00727                                                           aNodeIds[2], aNodeIds[3],
00728                                                           aNodeIds[4], aNodeIds[5],
00729                                                           aNodeIds[6], aNodeIds[7],
00730                                                           aNodeIds[8], aNodeIds[9],
00731                                                           aNodeIds[10], aNodeIds[11],
00732                                                           aNodeIds[12], aNodeIds[13],
00733                                                           aNodeIds[14], aNodeIds[15],
00734                                                           aNodeIds[16], aNodeIds[17],
00735                                                           aNodeIds[18], aNodeIds[19],
00736                                                           aNodeIds[20], aNodeIds[21],
00737                                                           aNodeIds[22], aNodeIds[23],
00738                                                           aNodeIds[24], aNodeIds[25],
00739                                                           aNodeIds[26],
00740                                                           aCellInfo->GetElemNum(iElem));
00741                     if (!anElement) {
00742                       anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
00743                                                     FindNode(myMesh,aNodeIds[1]),
00744                                                     FindNode(myMesh,aNodeIds[2]),
00745                                                     FindNode(myMesh,aNodeIds[3]),
00746                                                     FindNode(myMesh,aNodeIds[4]),
00747                                                     FindNode(myMesh,aNodeIds[5]),
00748                                                     FindNode(myMesh,aNodeIds[6]),
00749                                                     FindNode(myMesh,aNodeIds[7]),
00750                                                     FindNode(myMesh,aNodeIds[8]),
00751                                                     FindNode(myMesh,aNodeIds[9]),
00752                                                     FindNode(myMesh,aNodeIds[10]),
00753                                                     FindNode(myMesh,aNodeIds[11]),
00754                                                     FindNode(myMesh,aNodeIds[12]),
00755                                                     FindNode(myMesh,aNodeIds[13]),
00756                                                     FindNode(myMesh,aNodeIds[14]),
00757                                                     FindNode(myMesh,aNodeIds[15]),
00758                                                     FindNode(myMesh,aNodeIds[16]),
00759                                                     FindNode(myMesh,aNodeIds[17]),
00760                                                     FindNode(myMesh,aNodeIds[18]),
00761                                                     FindNode(myMesh,aNodeIds[19]),
00762                                                     FindNode(myMesh,aNodeIds[20]),
00763                                                     FindNode(myMesh,aNodeIds[21]),
00764                                                     FindNode(myMesh,aNodeIds[22]),
00765                                                     FindNode(myMesh,aNodeIds[23]),
00766                                                     FindNode(myMesh,aNodeIds[24]),
00767                                                     FindNode(myMesh,aNodeIds[25]),
00768                                                     FindNode(myMesh,aNodeIds[26]));
00769                       isRenum = anIsElemNum;
00770                     }
00771                     break;
00772 
00773                   case eOCTA12:
00774                     aNbNodes = 12;
00775                     if(anIsElemNum)
00776                       anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
00777                                                           aNodeIds[2], aNodeIds[3],
00778                                                           aNodeIds[4], aNodeIds[5],
00779                                                           aNodeIds[6], aNodeIds[7],
00780                                                           aNodeIds[8], aNodeIds[9],
00781                                                           aNodeIds[10], aNodeIds[11],
00782                                                           aCellInfo->GetElemNum(iElem));
00783                     if (!anElement) {
00784                       anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
00785                                                     FindNode(myMesh,aNodeIds[1]),
00786                                                     FindNode(myMesh,aNodeIds[2]),
00787                                                     FindNode(myMesh,aNodeIds[3]),
00788                                                     FindNode(myMesh,aNodeIds[4]),
00789                                                     FindNode(myMesh,aNodeIds[5]),
00790                                                     FindNode(myMesh,aNodeIds[6]),
00791                                                     FindNode(myMesh,aNodeIds[7]),
00792                                                     FindNode(myMesh,aNodeIds[8]),
00793                                                     FindNode(myMesh,aNodeIds[9]),
00794                                                     FindNode(myMesh,aNodeIds[10]),
00795                                                     FindNode(myMesh,aNodeIds[11]));
00796                       isRenum = anIsElemNum;
00797                     }
00798                     break;
00799 
00800                   } // switch(aGeom)
00801 
00802 #ifndef _DEXCEPT_
00803                 }catch(const std::exception& exc){
00804                   INFOS("The following exception was caught:\n\t"<<exc.what());
00805                   aResult = DRS_FAIL;
00806                 }catch(...){
00807                   INFOS("Unknown exception was caught !!!");
00808                   aResult = DRS_FAIL;
00809                 }
00810 #endif          
00811                 if (!anElement) {
00812                   aResult = DRS_WARN_SKIP_ELEM;
00813                 }
00814                 else {
00815                   if (isRenum) {
00816                     anIsElemNum = eFAUX;
00817                     takeNumbers = false;
00818                     if (aResult < DRS_WARN_RENUMBER)
00819                       aResult = DRS_WARN_RENUMBER;
00820                   }
00821                   if ( checkFamilyID ( aFamily, aFamNum )) {
00822                     // Save reference to this element from its family
00823                     myFamilies[aFamNum]->AddElement(anElement);
00824                     myFamilies[aFamNum]->SetType(anElement->GetType());
00825                   }
00826                 }
00827               }
00828             }}
00829           }
00830         }
00831       }
00832     }
00833 #ifndef _DEXCEPT_
00834   }catch(const std::exception& exc){
00835     INFOS("The following exception was caught:\n\t"<<exc.what());
00836     aResult = DRS_FAIL;
00837   }catch(...){
00838     INFOS("Unknown exception was caught !!!");
00839     aResult = DRS_FAIL;
00840   }
00841 #endif
00842   if (myMesh)
00843     myMesh->compactMesh();
00844   if(MYDEBUG) MESSAGE("Perform - aResult status = "<<aResult);
00845   return aResult;
00846 }
00847 
00848 list<string> DriverMED_R_SMESHDS_Mesh::GetMeshNames(Status& theStatus)
00849 {
00850   list<string> aMeshNames;
00851 
00852   try {
00853     if(MYDEBUG) MESSAGE("GetMeshNames - myFile : " << myFile);
00854     theStatus = DRS_OK;
00855     PWrapper aMed = CrWrapper(myFile);
00856 
00857     if (TInt aNbMeshes = aMed->GetNbMeshes()) {
00858       for (int iMesh = 0; iMesh < aNbMeshes; iMesh++) {
00859         // Reading the MED mesh
00860         //---------------------
00861         PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
00862         aMeshNames.push_back(aMeshInfo->GetName());
00863       }
00864     }
00865   }catch(const std::exception& exc){
00866     INFOS("Following exception was caught:\n\t"<<exc.what());
00867     theStatus = DRS_FAIL;
00868   }catch(...){
00869     INFOS("Unknown exception was caught !!!");
00870     theStatus = DRS_FAIL;
00871   }
00872 
00873   return aMeshNames;
00874 }
00875 
00876 list<TNameAndType> DriverMED_R_SMESHDS_Mesh::GetGroupNamesAndTypes()
00877 {
00878   list<TNameAndType> aResult;
00879   set<TNameAndType> aResGroupNames;
00880 
00881   map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
00882   for (; aFamsIter != myFamilies.end(); aFamsIter++)
00883   {
00884     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
00885     const MED::TStringSet& aGroupNames = aFamily->GetGroupNames();
00886     set<string>::const_iterator aGrNamesIter = aGroupNames.begin();
00887     for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
00888     {
00889       const set< SMDSAbs_ElementType >& types = aFamily->GetTypes();
00890       set< SMDSAbs_ElementType >::const_iterator type = types.begin();
00891       for ( ; type != types.end(); ++type )
00892       {
00893         TNameAndType aNameAndType = make_pair( *aGrNamesIter, *type );
00894         if ( aResGroupNames.insert( aNameAndType ).second ) {
00895           aResult.push_back( aNameAndType );
00896         }
00897       }
00898     }
00899   }
00900 
00901   return aResult;
00902 }
00903 
00904 void DriverMED_R_SMESHDS_Mesh::GetGroup(SMESHDS_Group* theGroup)
00905 {
00906   string aGroupName (theGroup->GetStoreName());
00907   if(MYDEBUG) MESSAGE("Get Group " << aGroupName);
00908 
00909   map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
00910   for (; aFamsIter != myFamilies.end(); aFamsIter++)
00911   {
00912     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
00913     if (aFamily->GetTypes().count( theGroup->GetType() ) && aFamily->MemberOf(aGroupName))
00914     {
00915       const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
00916       set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
00917       for (; anElemsIter != anElements.end(); anElemsIter++)
00918       {
00919         const SMDS_MeshElement * element = *anElemsIter;
00920         if ( element->GetType() == theGroup->GetType() ) // Issue 0020576
00921           theGroup->SMDSGroup().Add(element);
00922       }
00923       int aGroupAttrVal = aFamily->GetGroupAttributVal();
00924       if( aGroupAttrVal != 0)
00925         theGroup->SetColorGroup(aGroupAttrVal);
00926 //       if ( element ) -- Issue 0020576
00927 //         theGroup->SetType( theGroup->SMDSGroup().GetType() );
00928     }
00929   }
00930 }
00931 
00932 void DriverMED_R_SMESHDS_Mesh::GetSubMesh (SMESHDS_SubMesh* theSubMesh,
00933                                            const int theId)
00934 {
00935   char submeshGrpName[ 30 ];
00936   sprintf( submeshGrpName, "SubMesh %d", theId );
00937   string aName (submeshGrpName);
00938   map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
00939   for (; aFamsIter != myFamilies.end(); aFamsIter++)
00940   {
00941     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
00942     if (aFamily->MemberOf(aName))
00943     {
00944       const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
00945       set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
00946       if (aFamily->GetType() == SMDSAbs_Node)
00947       {
00948         for (; anElemsIter != anElements.end(); anElemsIter++)
00949         {
00950           const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>(*anElemsIter);
00951           theSubMesh->AddNode(node);
00952         }
00953       }
00954       else
00955       {
00956         for (; anElemsIter != anElements.end(); anElemsIter++)
00957         {
00958           theSubMesh->AddElement(*anElemsIter);
00959         }
00960       }
00961     }
00962   }
00963 }
00964 
00965 void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes ()
00966 {
00967   map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
00968   for (; aFamsIter != myFamilies.end(); aFamsIter++)
00969   {
00970     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
00971     MED::TStringSet aGroupNames = aFamily->GetGroupNames();
00972     set<string>::iterator aGrNamesIter = aGroupNames.begin();
00973     for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
00974     {
00975       string aName = *aGrNamesIter;
00976       // Check, if this is a Group or SubMesh name
00977       if (aName.substr(0, 7) == string("SubMesh"))
00978       {
00979         int Id = atoi(string(aName).substr(7).c_str());
00980         set<const SMDS_MeshElement *> anElements = aFamily->GetElements();
00981         set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
00982         if (aFamily->GetType() == SMDSAbs_Node)
00983         {
00984           for (; anElemsIter != anElements.end(); anElemsIter++)
00985           {
00986             SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>
00987               ( static_cast<const SMDS_MeshNode*>( *anElemsIter ));
00988             // find out a shape type
00989             TopoDS_Shape aShape = myMesh->IndexToShape( Id );
00990             int aShapeType = ( aShape.IsNull() ? -1 : aShape.ShapeType() );
00991             switch ( aShapeType ) {
00992             case TopAbs_FACE:
00993               myMesh->SetNodeOnFace(node, Id); break;
00994             case TopAbs_EDGE:
00995               myMesh->SetNodeOnEdge(node, Id); break;
00996             case TopAbs_VERTEX:
00997               myMesh->SetNodeOnVertex(node, Id); break;
00998             default:
00999               myMesh->SetNodeInVolume(node, Id);
01000             }
01001           }
01002         }
01003         else
01004         {
01005           for (; anElemsIter != anElements.end(); anElemsIter++)
01006           {
01007             myMesh->SetMeshElementOnShape(*anElemsIter, Id);
01008           }
01009         }
01010       }
01011     }
01012   }
01013 }
01020 bool DriverMED_R_SMESHDS_Mesh::checkFamilyID(DriverMED_FamilyPtr & aFamily, int anID) const
01021 {
01022   if ( !aFamily || aFamily->GetId() != anID ) {
01023     map<int, DriverMED_FamilyPtr>::const_iterator i_fam = myFamilies.find(anID);
01024     if ( i_fam == myFamilies.end() )
01025       return false;
01026     aFamily = i_fam->second;
01027   }
01028   return ( aFamily->GetId() == anID );
01029 }
01030 
01031 
01037 bool DriverMED_R_SMESHDS_Mesh::buildMeshGrille(const MED::PWrapper& theWrapper,
01038                                                const MED::PMeshInfo& theMeshInfo)
01039 {
01040   bool res = true;
01041 
01042   MED::PGrilleInfo aGrilleInfo = theWrapper->GetPGrilleInfo(theMeshInfo);
01043   MED::TInt aNbNodes = aGrilleInfo->GetNbNodes();
01044   MED::TInt aNbCells = aGrilleInfo->GetNbCells();
01045   MED::TInt aMeshDim = theMeshInfo->GetDim();
01046   DriverMED_FamilyPtr aFamily;
01047   for(MED::TInt iNode=0;iNode < aNbNodes; iNode++){
01048     double aCoords[3] = {0.0, 0.0, 0.0};
01049     const SMDS_MeshNode* aNode;
01050     MED::TNodeCoord aMEDNodeCoord = aGrilleInfo->GetCoord(iNode);
01051     for(MED::TInt iDim=0;iDim<aMeshDim;iDim++)
01052       aCoords[(int)iDim] = aMEDNodeCoord[(int)iDim];
01053     aNode = myMesh->AddNodeWithID(aCoords[0],aCoords[1],aCoords[2],iNode+1);
01054     if (!aNode) {
01055       EXCEPTION(runtime_error,"buildMeshGrille Error. Node not created! "<<(int)iNode);
01056     }
01057 
01058     if((aGrilleInfo->myFamNumNode).size() > 0){
01059       TInt aFamNum = aGrilleInfo->GetFamNumNode(iNode);
01060       if ( checkFamilyID ( aFamily, aFamNum ))
01061         {
01062           aFamily->AddElement(aNode);
01063           aFamily->SetType(SMDSAbs_Node);
01064         }
01065     }
01066     
01067   }
01068 
01069   SMDS_MeshElement* anElement = NULL;
01070   MED::TIntVector aNodeIds;
01071   for(MED::TInt iCell=0;iCell < aNbCells; iCell++){
01072     aNodeIds = aGrilleInfo->GetConn(iCell);
01073     switch(aGrilleInfo->GetGeom()){
01074     case MED::eSEG2:
01075       if(aNodeIds.size() != 2){
01076         res = false;
01077         EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 2!="<<aNodeIds.size());
01078       }
01079       anElement = myMesh->AddEdgeWithID(aNodeIds[0]+1,
01080                                         aNodeIds[1]+1,
01081                                         iCell+1);
01082       break;
01083     case MED::eQUAD4:
01084       if(aNodeIds.size() != 4){
01085         res = false;
01086         EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 4!="<<aNodeIds.size());
01087       }
01088       anElement = myMesh->AddFaceWithID(aNodeIds[0]+1,
01089                                         aNodeIds[2]+1,
01090                                         aNodeIds[3]+1,
01091                                         aNodeIds[1]+1,
01092                                         iCell+1);
01093       break;
01094     case MED::eHEXA8:
01095       if(aNodeIds.size() != 8){
01096         res = false;
01097         EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 8!="<<aNodeIds.size());
01098       }
01099       anElement = myMesh->AddVolumeWithID(aNodeIds[0]+1,
01100                                           aNodeIds[2]+1,
01101                                           aNodeIds[3]+1,
01102                                           aNodeIds[1]+1,
01103                                           aNodeIds[4]+1,
01104                                           aNodeIds[6]+1,
01105                                           aNodeIds[7]+1,
01106                                           aNodeIds[5]+1,
01107                                           iCell+1);
01108       break;
01109     default:
01110       break;
01111     }
01112     if (!anElement) {
01113       EXCEPTION(runtime_error,"buildMeshGrille Error. Element not created! "<<iCell);
01114     }
01115     if((aGrilleInfo->myFamNum).size() > 0){
01116       TInt aFamNum = aGrilleInfo->GetFamNum(iCell);
01117       if ( checkFamilyID ( aFamily, aFamNum )){
01118         aFamily->AddElement(anElement);
01119         aFamily->SetType(anElement->GetType());
01120       }
01121     }
01122   }
01123 
01124   return res;
01125 }