Salome HOME
Fix regression SALOME_TESTS/Grids/smesh/3D_mesh_Projection_00/A1
[modules/smesh.git] / src / DriverMED / DriverMED_R_SMESHDS_Mesh.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SMESH DriverMED : driver to read and write 'med' files
24 //  File   : DriverMED_R_SMESHDS_Mesh.cxx
25 //  Module : SMESH
26
27 #include "DriverMED_R_SMESHDS_Mesh.h"
28
29 #include "DriverMED_Family.h"
30 #include "SMESHDS_Group.hxx"
31 #include "SMESHDS_Mesh.hxx"
32 #include "SMESH_Comment.hxx"
33
34 #include "MED_CoordUtils.hxx"
35 #include "MED_Factory.hxx"
36 #include "MED_Utilities.hxx"
37
38 #include <NCollection_Map.hxx>
39
40 #include "utilities.h"
41
42 //#include <stdlib.h>
43
44 #ifdef _DEBUG_
45 static int MYDEBUG = 0;
46 //#define _DEXCEPT_
47 #else
48 static int MYDEBUG = 0;
49 #endif
50
51 #define _EDF_NODE_IDS_
52
53 using namespace MED;
54 using namespace std;
55
56 typedef std::map<int, DriverMED_FamilyPtr> TID2FamilyMap;
57
58 namespace DriverMED
59 {
60   bool buildMeshGrille(const MED::PWrapper&  theWrapper,
61                        const MED::PMeshInfo& theMeshInfo,
62                        SMESHDS_Mesh*         theMesh,
63                        const TID2FamilyMap&  myFamilies);
64   /*!
65    * \brief Ensure aFamily has a required ID
66    * \param aFamily - a family to check
67    * \param anID - an ID aFamily should have
68    * \param myFamilies - a map of the family ID to the Family
69    * \retval bool  - true if successful
70    */
71   bool checkFamilyID(DriverMED_FamilyPtr & aFamily,
72                      int                   anID,
73                      const TID2FamilyMap&  myFamilies);
74
75
76   const SMDS_MeshNode* FindNode(const SMDS_Mesh* theMesh, TInt theId)
77   {
78     const SMDS_MeshNode* aNode = theMesh->FindNode(theId);
79     if(aNode) return aNode;
80     EXCEPTION(runtime_error,"SMDS_Mesh::FindNode - cannot find a SMDS_MeshNode for ID = "<<theId);
81   }
82
83 }
84
85 //================================================================================
86 /*!
87  * \brief Stores a mesh name
88  */
89 //================================================================================
90
91 void DriverMED_R_SMESHDS_Mesh::SetMeshName(string theMeshName)
92 {
93   myMeshName = theMeshName;
94 }
95
96 //================================================================================
97 /*!
98  * \brief Reads a med file
99  */
100 //================================================================================
101
102 Driver_Mesh::Status DriverMED_R_SMESHDS_Mesh::Perform()
103 {
104   using namespace DriverMED;
105
106   Status aResult = DRS_FAIL;
107   bool isDescConn = false; // Mantis issue 0020483
108 #ifndef _DEXCEPT_
109   try {
110 #endif
111     myFamilies.clear();
112     if(MYDEBUG) MESSAGE("Perform - myFile : "<<myFile);
113     PWrapper aMed = CrWrapper(myFile,true);
114
115     aResult = DRS_EMPTY;
116     TInt aNbMeshes = aMed->GetNbMeshes();
117     for (int iMesh = 0; iMesh < aNbMeshes; iMesh++)
118     {
119       // Reading the MED mesh
120       //---------------------
121       PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
122
123       string aMeshName;
124       if (myMeshId != -1) aMeshName = SMESH_Comment( myMeshId );
125       else                aMeshName = myMeshName;
126
127       if(MYDEBUG) MESSAGE("Perform - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
128       if ( aMeshName != aMeshInfo->GetName() ) continue;
129       aResult = DRS_OK;
130
131       // Reading MED families to the temporary structure
132       //------------------------------------------------
133       TErr anErr;
134       TInt aNbFams = aMed->GetNbFamilies(aMeshInfo);
135       if(MYDEBUG) MESSAGE("Read " << aNbFams << " families");
136       for (TInt iFam = 0; iFam < aNbFams; iFam++)
137       {
138         PFamilyInfo aFamilyInfo = aMed->GetPFamilyInfo(aMeshInfo,iFam+1,&anErr);
139         if(anErr >= 0){
140           TInt aFamId = aFamilyInfo->GetId();
141           if(MYDEBUG) MESSAGE("Family " << aFamId << " :");
142
143           DriverMED_FamilyPtr aFamily (new DriverMED_Family);
144
145           TInt aNbGrp = aFamilyInfo->GetNbGroup();
146           if(MYDEBUG) MESSAGE("belong to " << aNbGrp << " groups");
147           bool isAttrOk = false;
148           if(aFamilyInfo->GetNbAttr() == aNbGrp)
149             isAttrOk = true;
150           for (TInt iGr = 0; iGr < aNbGrp; iGr++)
151           {
152             string aGroupName = aFamilyInfo->GetGroupName(iGr);
153             if ( isAttrOk ) {
154               TInt anAttrVal = aFamilyInfo->GetAttrVal(iGr);
155               aFamily->SetGroupAttributVal(anAttrVal);
156             }
157             if(MYDEBUG) MESSAGE(aGroupName);
158             aFamily->AddGroupName(aGroupName);
159           }
160           aFamily->SetId( aFamId );
161           myFamilies[aFamId] = aFamily;
162         }
163       }
164
165       if (aMeshInfo->GetType() == MED::eSTRUCTURE)
166       {
167         /*bool aRes = */DriverMED::buildMeshGrille(aMed,aMeshInfo,myMesh,myFamilies);
168         continue;
169       }
170
171       // Reading MED nodes to the corresponding SMDS structure
172       //------------------------------------------------------
173       PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo);
174       if (!aNodeInfo) {
175         aResult = addMessage("No nodes", /*isFatal=*/true );
176         continue;
177       }
178       aMeshInfo->myDim=aMeshInfo->mySpaceDim;// ignore meshdim in MEDFile because it can be false
179       PCoordHelper aCoordHelper = GetCoordHelper(aNodeInfo);
180
181       EBooleen anIsNodeNum = aNodeInfo->IsElemNum();
182       TInt aNbElems = aNodeInfo->GetNbElem();
183       if(MYDEBUG) MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbElems<<"; anIsNodeNum = "<<anIsNodeNum);
184       DriverMED_FamilyPtr aFamily;
185       for ( TInt iElem = 0; iElem < aNbElems; iElem++ )
186       {
187         TCCoordSlice aCoordSlice = aNodeInfo->GetCoordSlice(iElem);
188         double aCoords[3] = {0.0, 0.0, 0.0};
189         for(TInt iDim = 0; iDim < 3; iDim++)
190           aCoords[iDim] = aCoordHelper->GetCoord(aCoordSlice,iDim);
191         const SMDS_MeshNode* aNode;
192         if ( anIsNodeNum ) {
193           aNode = myMesh->AddNodeWithID
194             (aCoords[0],aCoords[1],aCoords[2],aNodeInfo->GetElemNum(iElem));
195         }
196         else {
197           aNode = myMesh->AddNodeWithID
198             (aCoords[0],aCoords[1],aCoords[2], iElem+1);
199         }
200
201         // Save reference to this node from its family
202         TInt aFamNum = aNodeInfo->GetFamNum(iElem);
203         if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies ))
204         {
205           aFamily->AddElement(aNode);
206           aFamily->SetType(SMDSAbs_Node);
207         }
208       }
209
210       // Are there any MED cells in descending connectivity
211       // Mantis issue 0020483
212       //---------------------------------------------------
213       NCollection_Map<EEntiteMaillage> aDescendingEntitiesMap;
214       if (!isDescConn) {
215         MED::TEntityInfo aEntityInfoDesc = aMed->GetEntityInfo(aMeshInfo, eDESC);
216         MED::TEntityInfo::iterator anEntityIterDesc = aEntityInfoDesc.begin();
217         //for (; anEntityIterDesc != aEntityInfoDesc.end() && !isDescConn; anEntityIterDesc++) {
218         for (; anEntityIterDesc != aEntityInfoDesc.end(); anEntityIterDesc++) {
219           const EEntiteMaillage& anEntity = anEntityIterDesc->first;
220           aDescendingEntitiesMap.Add(anEntity);
221           //if (anEntity != eNOEUD) isDescConn = true;
222         }
223       }
224
225       // Reading pre information about all MED cells
226       //--------------------------------------------
227       typedef MED::TVector<int> TNodeIds;
228       bool takeNumbers = true;  // initially we trust the numbers from file
229       MED::TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo, eNOD);
230       MED::TEntityInfo::iterator anEntityIter = aEntityInfo.begin();
231
232       for (; anEntityIter != aEntityInfo.end(); anEntityIter++)
233       {
234         const EEntiteMaillage& anEntity = anEntityIter->first;
235         aDescendingEntitiesMap.Remove(anEntity); // Mantis issue 0020483
236         if (anEntity == eNOEUD) continue;
237
238         // Reading MED cells to the corresponding SMDS structure
239         //------------------------------------------------------
240         const MED::TGeom2Size& aGeom2Size = anEntityIter->second;
241         MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
242         for ( ; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++)
243         {
244           const EGeometrieElement& aGeom = aGeom2SizeIter->first;
245
246           if ( anEntity == eSTRUCT_ELEMENT ) // MED_BALL (issue 0021459)
247           {
248             PBallInfo aBallInfo = aMed->GetPBallInfo(aMeshInfo);
249             TInt      aNbBalls  = aBallInfo->GetNbElem();
250
251             EBooleen anIsElemNum = takeNumbers ? aBallInfo->IsElemNum() : eFAUX;
252             if ( anIsElemNum && aBallInfo->myElemNum->empty() )
253               anIsElemNum = eFAUX;
254
255             // get supporting nodes
256             TNodeIds aNodeIds;
257 #ifdef _EDF_NODE_IDS_
258             if(anIsNodeNum) {
259               aNodeIds.resize( aNbBalls );
260               for(TInt iBall = 0; iBall < aNbBalls && anIsNodeNum; iBall++)
261               {
262                 aNodeIds[iBall] = aNodeInfo->GetElemNum( (*aBallInfo->myConn)[ iBall ]-1 );
263                 anIsNodeNum = myMesh->FindNode( aNodeIds[iBall] ) ? eVRAI : eFAUX;
264               }
265             }
266 #endif
267             if ( !anIsNodeNum )
268               aNodeIds.swap( *(aBallInfo->myConn ));
269
270             // allocate array of diameters
271             vtkIdType maxID = myMesh->MaxElementID() + aNbBalls;
272             if ( anIsElemNum && !aBallInfo->myElemNum->empty() )
273               maxID = *std::max_element( aBallInfo->myElemNum->begin(),
274                                          aBallInfo->myElemNum->end() );
275             myMesh->getGrid()->AllocateDiameters( maxID ); // performance optimization
276
277             // create balls
278             SMDS_MeshElement* anElement;
279             DriverMED_FamilyPtr aFamily;
280             for ( TInt iBall = 0; iBall < aNbBalls; iBall++)
281             {
282               anElement = 0;
283               if ( anIsElemNum ) {
284                 if (!(anElement = myMesh->AddBallWithID( aNodeIds[iBall],
285                                                          aBallInfo->myDiameters[iBall],
286                                                          aBallInfo->GetElemNum(iBall))))
287                   anIsElemNum = eFAUX;
288               }
289               if ( !anElement )
290                 myMesh->AddBall( myMesh->FindNode( aNodeIds[iBall]),
291                                  aBallInfo->myDiameters[iBall] );
292
293               // Save reference to this element from its family
294               TInt aFamNum = aBallInfo->GetFamNum(iBall);
295               if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies ))
296               {
297                 aFamily->AddElement(anElement);
298                 aFamily->SetType( SMDSAbs_Ball );
299               }
300             }
301
302             if ( !anIsElemNum &&
303                  ( takeNumbers && aBallInfo->IsElemNum() && !aBallInfo->myElemNum->empty() ))
304               if ( aResult < DRS_WARN_RENUMBER )
305                 aResult = DRS_WARN_RENUMBER;
306
307             continue;
308           } // MED_BALL
309
310           switch(aGeom) {
311           // case ePOINT1: ## PAL16410
312           //     break;
313           case ePOLYGONE:
314           case ePOLYGON2:
315           {
316             PPolygoneInfo aPolygoneInfo = aMed->GetPPolygoneInfo(aMeshInfo,anEntity,aGeom);
317             EBooleen anIsElemNum = takeNumbers ? aPolygoneInfo->IsElemNum() : eFAUX;
318
319             typedef SMDS_MeshFace* (SMESHDS_Mesh::* FAddPolyWithID)
320               (const std::vector<int> & nodes_ids, const int ID);
321             typedef SMDS_MeshFace* (SMESHDS_Mesh::* FAddPolygon)
322               (const std::vector<const SMDS_MeshNode*> & nodes);
323
324             FAddPolyWithID addPolyWithID = & SMESHDS_Mesh::AddPolygonalFaceWithID;
325             FAddPolygon       addPolygon = & SMESHDS_Mesh::AddPolygonalFace;
326             if ( aGeom == ePOLYGON2 ) {
327               addPolyWithID = & SMESHDS_Mesh::AddQuadPolygonalFaceWithID;
328               addPolygon    = & SMESHDS_Mesh::AddQuadPolygonalFace;
329             }
330             TNodeIds aNodeIds;
331             vector<const SMDS_MeshNode*> aNodes;
332             const TInt aNbElem = aPolygoneInfo->GetNbElem();
333             for ( TInt iElem = 0; iElem < aNbElem; iElem++ )
334             {
335               MED::TCConnSlice aConnSlice = aPolygoneInfo->GetConnSlice(iElem);
336               TInt aNbConn = aPolygoneInfo->GetNbConn(iElem);
337               aNodeIds.resize( aNbConn );
338 #ifdef _EDF_NODE_IDS_
339               if(anIsNodeNum)
340                 for(TInt iConn = 0; iConn < aNbConn; iConn++)
341                   aNodeIds[iConn] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
342               else
343                 for(TInt iConn = 0; iConn < aNbConn; iConn++)
344                   aNodeIds[iConn] = aConnSlice[iConn];
345 #else
346               for(TInt iConn = 0; iConn < aNbConn; iConn++)
347                 aNodeIds[iConn] = aConnSlice[iConn];
348 #endif
349               bool isRenum = false;
350               SMDS_MeshElement* anElement = NULL;
351               TInt aFamNum = aPolygoneInfo->GetFamNum(iElem);
352 #ifndef _DEXCEPT_
353               try {
354 #endif
355                 if ( anIsElemNum ) {
356                   TInt anElemId = aPolygoneInfo->GetElemNum( iElem );
357                   anElement = (myMesh->*addPolyWithID)( aNodeIds, anElemId );
358                 }
359                 if ( !anElement ) {
360                   aNodes.resize( aNbConn );
361                   for ( TInt iConn = 0; iConn < aNbConn; iConn++ )
362                     aNodes[iConn] = FindNode( myMesh, aNodeIds[iConn] );
363                   anElement = (myMesh->*addPolygon)( aNodes );
364                   isRenum = anIsElemNum;
365                 }
366 #ifndef _DEXCEPT_
367               } catch(const std::exception& exc) {
368                 aResult = addMessage( exc.what(), /*isFatal=*/true );
369               } catch (...) {
370                 aResult = addMessage( "Unknown exception", /*isFatal=*/true );
371               }
372 #endif
373               if ( !anElement ) {
374                 aResult = DRS_WARN_SKIP_ELEM;
375               }
376               else {
377                 if ( isRenum ) {
378                   anIsElemNum = eFAUX;
379                   takeNumbers = false;
380                   if(aResult < DRS_WARN_RENUMBER)
381                     aResult = DRS_WARN_RENUMBER;
382                 }
383                 if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies ))
384                 {
385                   // Save reference to this element from its family
386                   aFamily->AddElement(anElement);
387                   aFamily->SetType(anElement->GetType());
388                 }
389               }
390             }
391             break;
392           }
393           case ePOLYEDRE: {
394             PPolyedreInfo aPolyedreInfo = aMed->GetPPolyedreInfo(aMeshInfo,anEntity,aGeom);
395             EBooleen anIsElemNum = takeNumbers ? aPolyedreInfo->IsElemNum() : eFAUX;
396
397             TInt aNbElem = aPolyedreInfo->GetNbElem();
398             for(TInt iElem = 0; iElem < aNbElem; iElem++){
399               MED::TCConnSliceArr aConnSliceArr = aPolyedreInfo->GetConnSliceArr(iElem);
400               TInt aNbFaces = aConnSliceArr.size();
401               typedef MED::TVector<int> TQuantities;
402               TQuantities aQuantities(aNbFaces);
403               TInt aNbNodes = aPolyedreInfo->GetNbNodes(iElem);
404               TNodeIds aNodeIds(aNbNodes);
405               for(TInt iFace = 0, iNode = 0; iFace < aNbFaces; iFace++){
406                 MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
407                 TInt aNbConn = aConnSlice.size();
408                 aQuantities[iFace] = aNbConn;
409 #ifdef _EDF_NODE_IDS_
410                 if(anIsNodeNum)
411                   for(TInt iConn = 0; iConn < aNbConn; iConn++)
412                   {
413                     aNodeIds[iNode] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
414                     iNode++;
415                   }
416                 else
417                   for(TInt iConn = 0; iConn < aNbConn; iConn++)
418                   {
419                     aNodeIds[iNode++] = aConnSlice[iConn];
420                   }
421 #else
422                 for(TInt iConn = 0; iConn < aNbConn; iConn++)
423                 {
424                   aNodeIds[iNode++] = aConnSlice[iConn];
425                 }
426 #endif          
427               }
428
429               bool isRenum = false;
430               SMDS_MeshElement* anElement = NULL;
431               TInt aFamNum = aPolyedreInfo->GetFamNum(iElem);
432                 
433 #ifndef _DEXCEPT_
434               try{
435 #endif
436                 if(anIsElemNum){
437                   TInt anElemId = aPolyedreInfo->GetElemNum(iElem);
438                   anElement = myMesh->AddPolyhedralVolumeWithID(aNodeIds,aQuantities,anElemId);
439                 }
440                 if(!anElement){
441                   vector<const SMDS_MeshNode*> aNodes(aNbNodes);
442                   for(TInt iConn = 0; iConn < aNbNodes; iConn++)
443                     aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
444                   anElement = myMesh->AddPolyhedralVolume(aNodes,aQuantities);
445                   isRenum = anIsElemNum;
446                 }
447 #ifndef _DEXCEPT_
448               }catch(const std::exception& exc){
449                 aResult = DRS_FAIL;
450               }catch(...){
451                 aResult = DRS_FAIL;
452               }
453 #endif          
454               if(!anElement){
455                 aResult = DRS_WARN_SKIP_ELEM;
456               }else{
457                 if(isRenum){
458                   anIsElemNum = eFAUX;
459                   takeNumbers = false;
460                   if (aResult < DRS_WARN_RENUMBER)
461                     aResult = DRS_WARN_RENUMBER;
462                 }
463                 if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies )) {
464                   // Save reference to this element from its family
465                   aFamily->AddElement(anElement);
466                   aFamily->SetType(anElement->GetType());
467                 }
468               }
469             }
470             break;
471           }
472           default: {
473             PCellInfo aCellInfo = aMed->GetPCellInfo(aMeshInfo,anEntity,aGeom);
474             EBooleen anIsElemNum = takeNumbers ? aCellInfo->IsElemNum() : eFAUX;
475             TInt aNbElems = aCellInfo->GetNbElem();
476             if(MYDEBUG) MESSAGE("Perform - anEntity = "<<anEntity<<"; anIsElemNum = "<<anIsElemNum);
477             if(MYDEBUG) MESSAGE("Perform - aGeom = "<<aGeom<<"; aNbElems = "<<aNbElems);
478
479             TInt aNbNodes = -1;
480             switch(aGeom){
481             case eSEG2:    aNbNodes = 2;  break;
482             case eSEG3:    aNbNodes = 3;  break;
483             case eTRIA3:   aNbNodes = 3;  break;
484             case eTRIA6:   aNbNodes = 6;  break;
485             case eTRIA7:   aNbNodes = 7;  break;
486             case eQUAD4:   aNbNodes = 4;  break;
487             case eQUAD8:   aNbNodes = 8;  break;
488             case eQUAD9:   aNbNodes = 9;  break;
489             case eTETRA4:  aNbNodes = 4;  break;
490             case eTETRA10: aNbNodes = 10; break;
491             case ePYRA5:   aNbNodes = 5;  break;
492             case ePYRA13:  aNbNodes = 13; break;
493             case ePENTA6:  aNbNodes = 6;  break;
494             case ePENTA15: aNbNodes = 15; break;
495             case eHEXA8:   aNbNodes = 8;  break;
496             case eHEXA20:  aNbNodes = 20; break;
497             case eHEXA27:  aNbNodes = 27; break;
498             case eOCTA12:  aNbNodes = 12; break;
499             case ePOINT1:  aNbNodes = 1;  break;
500             default:;
501             }
502             vector<TInt> aNodeIds(aNbNodes);
503             for ( int iElem = 0; iElem < aNbElems; iElem++ )
504             {
505               bool anIsValidConnect = false;
506               TCConnSlice aConnSlice = aCellInfo->GetConnSlice(iElem);
507 #ifndef _DEXCEPT_
508               try{
509 #endif
510 #ifdef _EDF_NODE_IDS_
511                 if(anIsNodeNum)
512                   for(int iNode = 0; iNode < aNbNodes; iNode++)
513                     aNodeIds[iNode] = aNodeInfo->GetElemNum(aConnSlice[iNode] - 1);
514                 else
515                   for(int iNode = 0; iNode < aNbNodes; iNode++)
516                     aNodeIds[iNode] = aConnSlice[iNode];
517 #else
518                 for(int iNode = 0; iNode < aNbNodes; iNode++)
519                   aNodeIds[iNode] = aConnSlice[iNode];
520 #endif
521                 anIsValidConnect = true;
522 #ifndef _DEXCEPT_
523               }catch(const std::exception& exc){
524                 INFOS("Following exception was caught:\n\t"<<exc.what());
525                 aResult = addMessage( exc.what(), /*isFatal=*/true );
526               }catch(...){
527                 INFOS("Unknown exception was caught !!!");
528                 aResult = addMessage( "Unknown exception", /*isFatal=*/true );
529               }
530 #endif          
531               if(!anIsValidConnect)
532                 continue;
533
534               bool isRenum = false;
535               const SMDS_MeshElement* anElement = NULL;
536               TInt aFamNum = aCellInfo->GetFamNum(iElem);
537 #ifndef _DEXCEPT_
538               try{
539 #endif
540                 //MESSAGE("Try to create element # " << iElem << " with id = "
541                 //        << aCellInfo->GetElemNum(iElem));
542                 switch(aGeom) {
543                 case ePOINT1:
544                   //anElement = FindNode(myMesh,aNodeIds[0]);
545                   if(anIsElemNum)
546                     anElement = myMesh->Add0DElementWithID
547                       (aNodeIds[0], aCellInfo->GetElemNum(iElem));
548                   if (!anElement) {
549                     anElement = myMesh->Add0DElement(FindNode(myMesh,aNodeIds[0]));
550                     isRenum = anIsElemNum;
551                   }
552                   break;
553                 case eSEG2:
554                   if(anIsElemNum)
555                     anElement = myMesh->AddEdgeWithID(aNodeIds[0],
556                                                       aNodeIds[1],
557                                                       aCellInfo->GetElemNum(iElem));
558                   if (!anElement) {
559                     anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
560                                                 FindNode(myMesh,aNodeIds[1]));
561                     isRenum = anIsElemNum;
562                   }
563                   break;
564                 case eSEG3:
565                   if(anIsElemNum)
566                     anElement = myMesh->AddEdgeWithID(aNodeIds[0],
567                                                       aNodeIds[1],
568                                                       aNodeIds[2],
569                                                       aCellInfo->GetElemNum(iElem));
570                   if (!anElement) {
571                     anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
572                                                 FindNode(myMesh,aNodeIds[1]),
573                                                 FindNode(myMesh,aNodeIds[2]));
574                     isRenum = anIsElemNum;
575                   }
576                   break;
577                 case eTRIA3:
578                   aNbNodes = 3;
579                   if(anIsElemNum)
580                     anElement = myMesh->AddFaceWithID(aNodeIds[0],
581                                                       aNodeIds[1],
582                                                       aNodeIds[2],
583                                                       aCellInfo->GetElemNum(iElem));
584                   if (!anElement) {
585                     anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
586                                                 FindNode(myMesh,aNodeIds[1]),
587                                                 FindNode(myMesh,aNodeIds[2]));
588                     isRenum = anIsElemNum;
589                   }
590                   break;
591                 case eTRIA6:
592                   aNbNodes = 6;
593                   if(anIsElemNum)
594                     anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
595                                                       aNodeIds[2], aNodeIds[3],
596                                                       aNodeIds[4], aNodeIds[5],
597                                                       aCellInfo->GetElemNum(iElem));
598                   if (!anElement) {
599                     anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
600                                                 FindNode(myMesh,aNodeIds[1]),
601                                                 FindNode(myMesh,aNodeIds[2]),
602                                                 FindNode(myMesh,aNodeIds[3]),
603                                                 FindNode(myMesh,aNodeIds[4]),
604                                                 FindNode(myMesh,aNodeIds[5]));
605                     isRenum = anIsElemNum;
606                   }
607                   break;
608                 case eTRIA7:
609                   aNbNodes = 7;
610                   if(anIsElemNum)
611                     anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
612                                                       aNodeIds[2], aNodeIds[3],
613                                                       aNodeIds[4], aNodeIds[5], aNodeIds[6],
614                                                       aCellInfo->GetElemNum(iElem));
615                   if (!anElement) {
616                     anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
617                                                 FindNode(myMesh,aNodeIds[1]),
618                                                 FindNode(myMesh,aNodeIds[2]),
619                                                 FindNode(myMesh,aNodeIds[3]),
620                                                 FindNode(myMesh,aNodeIds[4]),
621                                                 FindNode(myMesh,aNodeIds[5]),
622                                                 FindNode(myMesh,aNodeIds[6]));
623                     isRenum = anIsElemNum;
624                   }
625                   break;
626                 case eQUAD4:
627                   aNbNodes = 4;
628                   if(anIsElemNum)
629                     anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
630                                                       aNodeIds[2], aNodeIds[3],
631                                                       aCellInfo->GetElemNum(iElem));
632                   if (!anElement) {
633                     anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
634                                                 FindNode(myMesh,aNodeIds[1]),
635                                                 FindNode(myMesh,aNodeIds[2]),
636                                                 FindNode(myMesh,aNodeIds[3]));
637                     isRenum = anIsElemNum;
638                   }
639                   break;
640                 case eQUAD8:
641                   aNbNodes = 8;
642                   if(anIsElemNum)
643                     anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
644                                                       aNodeIds[2], aNodeIds[3],
645                                                       aNodeIds[4], aNodeIds[5],
646                                                       aNodeIds[6], aNodeIds[7],
647                                                       aCellInfo->GetElemNum(iElem));
648                   if (!anElement) {
649                     anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
650                                                 FindNode(myMesh,aNodeIds[1]),
651                                                 FindNode(myMesh,aNodeIds[2]),
652                                                 FindNode(myMesh,aNodeIds[3]),
653                                                 FindNode(myMesh,aNodeIds[4]),
654                                                 FindNode(myMesh,aNodeIds[5]),
655                                                 FindNode(myMesh,aNodeIds[6]),
656                                                 FindNode(myMesh,aNodeIds[7]));
657                     isRenum = anIsElemNum;
658                   }
659                   break;
660                 case eQUAD9:
661                   aNbNodes = 9;
662                   if(anIsElemNum)
663                     anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
664                                                       aNodeIds[2], aNodeIds[3],
665                                                       aNodeIds[4], aNodeIds[5],
666                                                       aNodeIds[6], aNodeIds[7], aNodeIds[8],
667                                                       aCellInfo->GetElemNum(iElem));
668                   if (!anElement) {
669                     anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
670                                                 FindNode(myMesh,aNodeIds[1]),
671                                                 FindNode(myMesh,aNodeIds[2]),
672                                                 FindNode(myMesh,aNodeIds[3]),
673                                                 FindNode(myMesh,aNodeIds[4]),
674                                                 FindNode(myMesh,aNodeIds[5]),
675                                                 FindNode(myMesh,aNodeIds[6]),
676                                                 FindNode(myMesh,aNodeIds[7]),
677                                                 FindNode(myMesh,aNodeIds[8]));
678                     isRenum = anIsElemNum;
679                   }
680                   break;
681                 case eTETRA4:
682                   aNbNodes = 4;
683                   if(anIsElemNum)
684                     anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
685                                                         aNodeIds[2], aNodeIds[3],
686                                                         aCellInfo->GetElemNum(iElem));
687                   if (!anElement) {
688                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
689                                                   FindNode(myMesh,aNodeIds[1]),
690                                                   FindNode(myMesh,aNodeIds[2]),
691                                                   FindNode(myMesh,aNodeIds[3]));
692                     isRenum = anIsElemNum;
693                   }
694                   break;
695                 case eTETRA10:
696                   aNbNodes = 10;
697                   if(anIsElemNum)
698                     anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
699                                                         aNodeIds[2], aNodeIds[3],
700                                                         aNodeIds[4], aNodeIds[5],
701                                                         aNodeIds[6], aNodeIds[7],
702                                                         aNodeIds[8], aNodeIds[9],
703                                                         aCellInfo->GetElemNum(iElem));
704                   if (!anElement) {
705                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
706                                                   FindNode(myMesh,aNodeIds[1]),
707                                                   FindNode(myMesh,aNodeIds[2]),
708                                                   FindNode(myMesh,aNodeIds[3]),
709                                                   FindNode(myMesh,aNodeIds[4]),
710                                                   FindNode(myMesh,aNodeIds[5]),
711                                                   FindNode(myMesh,aNodeIds[6]),
712                                                   FindNode(myMesh,aNodeIds[7]),
713                                                   FindNode(myMesh,aNodeIds[8]),
714                                                   FindNode(myMesh,aNodeIds[9]));
715                     isRenum = anIsElemNum;
716                   }
717                   break;
718                 case ePYRA5:
719                   aNbNodes = 5;
720                   if(anIsElemNum)
721                     anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
722                                                         aNodeIds[2], aNodeIds[3],
723                                                         aNodeIds[4],
724                                                         aCellInfo->GetElemNum(iElem));
725                   if (!anElement) {
726                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
727                                                   FindNode(myMesh,aNodeIds[1]),
728                                                   FindNode(myMesh,aNodeIds[2]),
729                                                   FindNode(myMesh,aNodeIds[3]),
730                                                   FindNode(myMesh,aNodeIds[4]));
731                     isRenum = anIsElemNum;
732                   }
733                   break;
734                 case ePYRA13:
735                   aNbNodes = 13;
736                   if(anIsElemNum)
737                     anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
738                                                         aNodeIds[2], aNodeIds[3],
739                                                         aNodeIds[4], aNodeIds[5],
740                                                         aNodeIds[6], aNodeIds[7],
741                                                         aNodeIds[8], aNodeIds[9],
742                                                         aNodeIds[10], aNodeIds[11],
743                                                         aNodeIds[12],
744                                                         aCellInfo->GetElemNum(iElem));
745                   if (!anElement) {
746                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
747                                                   FindNode(myMesh,aNodeIds[1]),
748                                                   FindNode(myMesh,aNodeIds[2]),
749                                                   FindNode(myMesh,aNodeIds[3]),
750                                                   FindNode(myMesh,aNodeIds[4]),
751                                                   FindNode(myMesh,aNodeIds[5]),
752                                                   FindNode(myMesh,aNodeIds[6]),
753                                                   FindNode(myMesh,aNodeIds[7]),
754                                                   FindNode(myMesh,aNodeIds[8]),
755                                                   FindNode(myMesh,aNodeIds[9]),
756                                                   FindNode(myMesh,aNodeIds[10]),
757                                                   FindNode(myMesh,aNodeIds[11]),
758                                                   FindNode(myMesh,aNodeIds[12]));
759                     isRenum = anIsElemNum;
760                   }
761                   break;
762                 case ePENTA6:
763                   aNbNodes = 6;
764                   if(anIsElemNum)
765                     anElement = myMesh->AddVolumeWithID(aNodeIds[0],
766                                                         aNodeIds[1],
767                                                         aNodeIds[2],
768                                                         aNodeIds[3],
769                                                         aNodeIds[4],
770                                                         aNodeIds[5],
771                                                         aCellInfo->GetElemNum(iElem));
772                   if (!anElement) {
773                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
774                                                   FindNode(myMesh,aNodeIds[1]),
775                                                   FindNode(myMesh,aNodeIds[2]),
776                                                   FindNode(myMesh,aNodeIds[3]),
777                                                   FindNode(myMesh,aNodeIds[4]),
778                                                   FindNode(myMesh,aNodeIds[5]));
779                     isRenum = anIsElemNum;
780                   }
781                   break;
782                 case ePENTA15:
783                   aNbNodes = 15;
784                   if(anIsElemNum)
785                     anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
786                                                         aNodeIds[2], aNodeIds[3],
787                                                         aNodeIds[4], aNodeIds[5],
788                                                         aNodeIds[6], aNodeIds[7],
789                                                         aNodeIds[8], aNodeIds[9],
790                                                         aNodeIds[10], aNodeIds[11],
791                                                         aNodeIds[12], aNodeIds[13],
792                                                         aNodeIds[14],
793                                                         aCellInfo->GetElemNum(iElem));
794                   if (!anElement) {
795                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
796                                                   FindNode(myMesh,aNodeIds[1]),
797                                                   FindNode(myMesh,aNodeIds[2]),
798                                                   FindNode(myMesh,aNodeIds[3]),
799                                                   FindNode(myMesh,aNodeIds[4]),
800                                                   FindNode(myMesh,aNodeIds[5]),
801                                                   FindNode(myMesh,aNodeIds[6]),
802                                                   FindNode(myMesh,aNodeIds[7]),
803                                                   FindNode(myMesh,aNodeIds[8]),
804                                                   FindNode(myMesh,aNodeIds[9]),
805                                                   FindNode(myMesh,aNodeIds[10]),
806                                                   FindNode(myMesh,aNodeIds[11]),
807                                                   FindNode(myMesh,aNodeIds[12]),
808                                                   FindNode(myMesh,aNodeIds[13]),
809                                                   FindNode(myMesh,aNodeIds[14]));
810                     isRenum = anIsElemNum;
811                   }
812                   break;
813                 case eHEXA8:
814                   aNbNodes = 8;
815                   if(anIsElemNum)
816                     anElement = myMesh->AddVolumeWithID(aNodeIds[0],
817                                                         aNodeIds[1],
818                                                         aNodeIds[2],
819                                                         aNodeIds[3],
820                                                         aNodeIds[4],
821                                                         aNodeIds[5],
822                                                         aNodeIds[6],
823                                                         aNodeIds[7],
824                                                         aCellInfo->GetElemNum(iElem));
825                   if (!anElement) {
826                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
827                                                   FindNode(myMesh,aNodeIds[1]),
828                                                   FindNode(myMesh,aNodeIds[2]),
829                                                   FindNode(myMesh,aNodeIds[3]),
830                                                   FindNode(myMesh,aNodeIds[4]),
831                                                   FindNode(myMesh,aNodeIds[5]),
832                                                   FindNode(myMesh,aNodeIds[6]),
833                                                   FindNode(myMesh,aNodeIds[7]));
834                     isRenum = anIsElemNum;
835                   }
836                   break;
837
838                 case eHEXA20:
839                   aNbNodes = 20;
840                   if(anIsElemNum)
841                     anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
842                                                         aNodeIds[2], aNodeIds[3],
843                                                         aNodeIds[4], aNodeIds[5],
844                                                         aNodeIds[6], aNodeIds[7],
845                                                         aNodeIds[8], aNodeIds[9],
846                                                         aNodeIds[10], aNodeIds[11],
847                                                         aNodeIds[12], aNodeIds[13],
848                                                         aNodeIds[14], aNodeIds[15],
849                                                         aNodeIds[16], aNodeIds[17],
850                                                         aNodeIds[18], aNodeIds[19],
851                                                         aCellInfo->GetElemNum(iElem));
852                   if (!anElement) {
853                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
854                                                   FindNode(myMesh,aNodeIds[1]),
855                                                   FindNode(myMesh,aNodeIds[2]),
856                                                   FindNode(myMesh,aNodeIds[3]),
857                                                   FindNode(myMesh,aNodeIds[4]),
858                                                   FindNode(myMesh,aNodeIds[5]),
859                                                   FindNode(myMesh,aNodeIds[6]),
860                                                   FindNode(myMesh,aNodeIds[7]),
861                                                   FindNode(myMesh,aNodeIds[8]),
862                                                   FindNode(myMesh,aNodeIds[9]),
863                                                   FindNode(myMesh,aNodeIds[10]),
864                                                   FindNode(myMesh,aNodeIds[11]),
865                                                   FindNode(myMesh,aNodeIds[12]),
866                                                   FindNode(myMesh,aNodeIds[13]),
867                                                   FindNode(myMesh,aNodeIds[14]),
868                                                   FindNode(myMesh,aNodeIds[15]),
869                                                   FindNode(myMesh,aNodeIds[16]),
870                                                   FindNode(myMesh,aNodeIds[17]),
871                                                   FindNode(myMesh,aNodeIds[18]),
872                                                   FindNode(myMesh,aNodeIds[19]));
873                     isRenum = anIsElemNum;
874                   }
875                   break;
876
877                 case eHEXA27:
878                   aNbNodes = 27;
879                   if(anIsElemNum)
880                     anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
881                                                         aNodeIds[2], aNodeIds[3],
882                                                         aNodeIds[4], aNodeIds[5],
883                                                         aNodeIds[6], aNodeIds[7],
884                                                         aNodeIds[8], aNodeIds[9],
885                                                         aNodeIds[10], aNodeIds[11],
886                                                         aNodeIds[12], aNodeIds[13],
887                                                         aNodeIds[14], aNodeIds[15],
888                                                         aNodeIds[16], aNodeIds[17],
889                                                         aNodeIds[18], aNodeIds[19],
890                                                         aNodeIds[20], aNodeIds[21],
891                                                         aNodeIds[22], aNodeIds[23],
892                                                         aNodeIds[24], aNodeIds[25],
893                                                         aNodeIds[26],
894                                                         aCellInfo->GetElemNum(iElem));
895                   if (!anElement) {
896                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
897                                                   FindNode(myMesh,aNodeIds[1]),
898                                                   FindNode(myMesh,aNodeIds[2]),
899                                                   FindNode(myMesh,aNodeIds[3]),
900                                                   FindNode(myMesh,aNodeIds[4]),
901                                                   FindNode(myMesh,aNodeIds[5]),
902                                                   FindNode(myMesh,aNodeIds[6]),
903                                                   FindNode(myMesh,aNodeIds[7]),
904                                                   FindNode(myMesh,aNodeIds[8]),
905                                                   FindNode(myMesh,aNodeIds[9]),
906                                                   FindNode(myMesh,aNodeIds[10]),
907                                                   FindNode(myMesh,aNodeIds[11]),
908                                                   FindNode(myMesh,aNodeIds[12]),
909                                                   FindNode(myMesh,aNodeIds[13]),
910                                                   FindNode(myMesh,aNodeIds[14]),
911                                                   FindNode(myMesh,aNodeIds[15]),
912                                                   FindNode(myMesh,aNodeIds[16]),
913                                                   FindNode(myMesh,aNodeIds[17]),
914                                                   FindNode(myMesh,aNodeIds[18]),
915                                                   FindNode(myMesh,aNodeIds[19]),
916                                                   FindNode(myMesh,aNodeIds[20]),
917                                                   FindNode(myMesh,aNodeIds[21]),
918                                                   FindNode(myMesh,aNodeIds[22]),
919                                                   FindNode(myMesh,aNodeIds[23]),
920                                                   FindNode(myMesh,aNodeIds[24]),
921                                                   FindNode(myMesh,aNodeIds[25]),
922                                                   FindNode(myMesh,aNodeIds[26]));
923                     isRenum = anIsElemNum;
924                   }
925                   break;
926
927                 case eOCTA12:
928                   aNbNodes = 12;
929                   if(anIsElemNum)
930                     anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
931                                                         aNodeIds[2], aNodeIds[3],
932                                                         aNodeIds[4], aNodeIds[5],
933                                                         aNodeIds[6], aNodeIds[7],
934                                                         aNodeIds[8], aNodeIds[9],
935                                                         aNodeIds[10], aNodeIds[11],
936                                                         aCellInfo->GetElemNum(iElem));
937                   if (!anElement) {
938                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
939                                                   FindNode(myMesh,aNodeIds[1]),
940                                                   FindNode(myMesh,aNodeIds[2]),
941                                                   FindNode(myMesh,aNodeIds[3]),
942                                                   FindNode(myMesh,aNodeIds[4]),
943                                                   FindNode(myMesh,aNodeIds[5]),
944                                                   FindNode(myMesh,aNodeIds[6]),
945                                                   FindNode(myMesh,aNodeIds[7]),
946                                                   FindNode(myMesh,aNodeIds[8]),
947                                                   FindNode(myMesh,aNodeIds[9]),
948                                                   FindNode(myMesh,aNodeIds[10]),
949                                                   FindNode(myMesh,aNodeIds[11]));
950                     isRenum = anIsElemNum;
951                   }
952                   break;
953
954                 default:;
955
956                 } // switch(aGeom)
957
958 #ifndef _DEXCEPT_
959               } catch(const std::exception& exc) {
960                 INFOS("The following exception was caught:\n\t"<<exc.what());
961                 aResult = addMessage( exc.what(), /*isFatal=*/true );
962               } catch(...) {
963                 INFOS("Unknown exception was caught !!!");
964                 aResult = addMessage( "Unknown exception", /*isFatal=*/true );
965               }
966 #endif
967               if (!anElement) {
968                 aResult = DRS_WARN_SKIP_ELEM;
969               }
970               else {
971                 if (isRenum) {
972                   anIsElemNum = eFAUX;
973                   takeNumbers = false;
974                   if (aResult < DRS_WARN_RENUMBER)
975                     aResult = DRS_WARN_RENUMBER;
976                 }
977                 if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies )) {
978                   // Save reference to this element from its family
979                   aFamily->AddElement(anElement);
980                   aFamily->SetType(anElement->GetType());
981                 }
982               }
983             } // loop on aNbElems
984           }} // switch(aGeom)
985         } // loop on aGeom2Size
986       } // loop on aEntityInfo
987
988       if (aDescendingEntitiesMap.Extent()) isDescConn = true; // Mantis issue 0020483
989
990     } // for(int iMesh = 0; iMesh < aNbMeshes; iMesh++)
991 #ifndef _DEXCEPT_
992   }
993   catch(const std::exception& exc)
994   {
995     INFOS("The following exception was caught:\n\t"<<exc.what());
996     aResult = addMessage( exc.what(), /*isFatal=*/true );
997   }
998   catch(...)
999   {
1000     INFOS("Unknown exception was caught !!!");
1001     aResult = addMessage( "Unknown exception", /*isFatal=*/true );
1002   }
1003 #endif
1004   if (myMesh)
1005     myMesh->compactMesh();
1006
1007   // Mantis issue 0020483
1008   if (aResult == DRS_OK && isDescConn) {
1009     INFOS("There are some elements in descending connectivity in med file. They were not read !!!");
1010     aResult = DRS_WARN_DESCENDING;
1011   }
1012
1013   if(MYDEBUG) MESSAGE("Perform - aResult status = "<<aResult);
1014   return aResult;
1015 }
1016
1017 list<string> DriverMED_R_SMESHDS_Mesh::GetMeshNames(Status& theStatus)
1018 {
1019   list<string> aMeshNames;
1020
1021   try {
1022     if(MYDEBUG) MESSAGE("GetMeshNames - myFile : " << myFile);
1023     theStatus = DRS_OK;
1024     PWrapper aMed = CrWrapper(myFile);
1025
1026     if (TInt aNbMeshes = aMed->GetNbMeshes()) {
1027       for (int iMesh = 0; iMesh < aNbMeshes; iMesh++) {
1028         // Reading the MED mesh
1029         //---------------------
1030         PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
1031         aMeshNames.push_back(aMeshInfo->GetName());
1032       }
1033     }
1034   } catch(const std::exception& exc) {
1035     INFOS("Following exception was caught:\n\t"<<exc.what());
1036     theStatus = DRS_FAIL;
1037   } catch(...) {
1038     INFOS("Unknown exception was caught !!!");
1039     theStatus = DRS_FAIL;
1040   }
1041
1042   return aMeshNames;
1043 }
1044
1045 list<TNameAndType> DriverMED_R_SMESHDS_Mesh::GetGroupNamesAndTypes()
1046 {
1047   list<TNameAndType> aResult;
1048   set<TNameAndType> aResGroupNames;
1049
1050   map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
1051   for (; aFamsIter != myFamilies.end(); aFamsIter++)
1052   {
1053     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
1054     const MED::TStringSet& aGroupNames = aFamily->GetGroupNames();
1055     set<string>::const_iterator aGrNamesIter = aGroupNames.begin();
1056     for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
1057     {
1058       const set< SMDSAbs_ElementType >& types = aFamily->GetTypes();
1059       set< SMDSAbs_ElementType >::const_iterator type = types.begin();
1060       for ( ; type != types.end(); ++type )
1061       {
1062         TNameAndType aNameAndType = make_pair( *aGrNamesIter, *type );
1063         if ( aResGroupNames.insert( aNameAndType ).second ) {
1064           aResult.push_back( aNameAndType );
1065         }
1066       }
1067     }
1068   }
1069
1070   return aResult;
1071 }
1072
1073 void DriverMED_R_SMESHDS_Mesh::GetGroup(SMESHDS_Group* theGroup)
1074 {
1075   string aGroupName (theGroup->GetStoreName());
1076   if(MYDEBUG) MESSAGE("Get Group " << aGroupName);
1077
1078   map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
1079   for (; aFamsIter != myFamilies.end(); aFamsIter++)
1080   {
1081     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
1082     if (aFamily->GetTypes().count( theGroup->GetType() ) && aFamily->MemberOf(aGroupName))
1083     {
1084       const ElementsSet&           anElements = aFamily->GetElements();
1085       ElementsSet::const_iterator anElemsIter = anElements.begin();
1086       for (; anElemsIter != anElements.end(); anElemsIter++)
1087       {
1088         const SMDS_MeshElement * element = *anElemsIter;
1089         if ( element->GetType() == theGroup->GetType() ) // Issue 0020576
1090           theGroup->SMDSGroup().Add(element);
1091       }
1092       int aGroupAttrVal = aFamily->GetGroupAttributVal();
1093       if( aGroupAttrVal != 0)
1094         theGroup->SetColorGroup(aGroupAttrVal);
1095 //       if ( element ) -- Issue 0020576
1096 //         theGroup->SetType( theGroup->SMDSGroup().GetType() );
1097     }
1098   }
1099 }
1100
1101 void DriverMED_R_SMESHDS_Mesh::GetSubMesh (SMESHDS_SubMesh* theSubMesh,
1102                                            const int theId)
1103 {
1104   char submeshGrpName[ 30 ];
1105   sprintf( submeshGrpName, "SubMesh %d", theId );
1106   string aName (submeshGrpName);
1107   map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
1108   for (; aFamsIter != myFamilies.end(); aFamsIter++)
1109   {
1110     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
1111     if (aFamily->MemberOf(aName))
1112     {
1113       const ElementsSet&           anElements = aFamily->GetElements();
1114       ElementsSet::const_iterator anElemsIter = anElements.begin();
1115       if (aFamily->GetType() == SMDSAbs_Node)
1116       {
1117         for (; anElemsIter != anElements.end(); anElemsIter++)
1118         {
1119           const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>(*anElemsIter);
1120           theSubMesh->AddNode(node);
1121         }
1122       }
1123       else
1124       {
1125         for (; anElemsIter != anElements.end(); anElemsIter++)
1126         {
1127           theSubMesh->AddElement(*anElemsIter);
1128         }
1129       }
1130     }
1131   }
1132 }
1133
1134 void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes ()
1135 {
1136   map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
1137   for (; aFamsIter != myFamilies.end(); aFamsIter++)
1138   {
1139     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
1140     MED::TStringSet aGroupNames = aFamily->GetGroupNames();
1141     set<string>::iterator aGrNamesIter = aGroupNames.begin();
1142     for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
1143     {
1144       string aName = *aGrNamesIter;
1145       // Check, if this is a Group or SubMesh name
1146       if (aName.substr(0, 7) == string("SubMesh"))
1147       {
1148         int Id = atoi(string(aName).substr(7).c_str());
1149         const ElementsSet&           anElements = aFamily->GetElements();
1150         ElementsSet::const_iterator anElemsIter = anElements.begin();
1151         if (aFamily->GetType() == SMDSAbs_Node)
1152         {
1153           for (; anElemsIter != anElements.end(); anElemsIter++)
1154           {
1155             const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( *anElemsIter );
1156             // find out a shape type
1157             TopoDS_Shape aShape = myMesh->IndexToShape( Id );
1158             int aShapeType = ( aShape.IsNull() ? -1 : aShape.ShapeType() );
1159             switch ( aShapeType ) {
1160             case TopAbs_FACE:
1161               myMesh->SetNodeOnFace(node, Id); break;
1162             case TopAbs_EDGE:
1163               myMesh->SetNodeOnEdge(node, Id); break;
1164             case TopAbs_VERTEX:
1165               myMesh->SetNodeOnVertex(node, Id); break;
1166             default:
1167               myMesh->SetNodeInVolume(node, Id);
1168             }
1169           }
1170         }
1171         else
1172         {
1173           for (; anElemsIter != anElements.end(); anElemsIter++)
1174           {
1175             myMesh->SetMeshElementOnShape(*anElemsIter, Id);
1176           }
1177         }
1178       }
1179     }
1180   }
1181 }
1182 /*!
1183  * \brief Ensure aFamily to have required ID
1184  * \param aFamily - a family to check and update
1185  * \param anID - an ID aFamily should have
1186  * \retval bool  - true if successful
1187  */
1188 bool DriverMED::checkFamilyID(DriverMED_FamilyPtr & aFamily,
1189                               int                   anID,
1190                               const TID2FamilyMap&  myFamilies)
1191 {
1192   if ( !aFamily || aFamily->GetId() != anID ) {
1193     map<int, DriverMED_FamilyPtr>::const_iterator i_fam = myFamilies.find(anID);
1194     if ( i_fam == myFamilies.end() )
1195       return false;
1196     aFamily = i_fam->second;
1197   }
1198   return ( aFamily->GetId() == anID );
1199 }
1200
1201 /*!
1202  * \brief Reading the structured mesh and convert to non structured
1203  *        (by filling of smesh structure for non structured mesh)
1204  * \param theWrapper  - PWrapper const pointer
1205  * \param theMeshInfo - PMeshInfo const pointer
1206  * \param myFamilies  - a map of the family ID to the Family
1207  * \return TRUE, if successfully. Else FALSE
1208  */
1209 bool DriverMED::buildMeshGrille(const MED::PWrapper&  theWrapper,
1210                                 const MED::PMeshInfo& theMeshInfo,
1211                                 SMESHDS_Mesh*         myMesh,
1212                                 const TID2FamilyMap&  myFamilies)
1213 {
1214   bool res = true;
1215
1216   MED::PGrilleInfo aGrilleInfo = theWrapper->GetPGrilleInfo(theMeshInfo);
1217   MED::TInt aNbNodes = aGrilleInfo->GetNbNodes();
1218   MED::TInt aNbCells = aGrilleInfo->GetNbCells();
1219   MED::TInt aMeshDim = theMeshInfo->GetDim();
1220   DriverMED_FamilyPtr aFamily;
1221   for(MED::TInt iNode=0;iNode < aNbNodes; iNode++){
1222     double aCoords[3] = {0.0, 0.0, 0.0};
1223     const SMDS_MeshNode* aNode;
1224     MED::TNodeCoord aMEDNodeCoord = aGrilleInfo->GetCoord(iNode);
1225     for(MED::TInt iDim=0;iDim<aMeshDim;iDim++)
1226       aCoords[(int)iDim] = aMEDNodeCoord[(int)iDim];
1227     aNode = myMesh->AddNodeWithID(aCoords[0],aCoords[1],aCoords[2],iNode+1);
1228     if (!aNode) {
1229       EXCEPTION(runtime_error,"buildMeshGrille Error. Node not created! "<<(int)iNode);
1230     }
1231
1232     if((aGrilleInfo->myFamNumNode).size() > 0){
1233       TInt aFamNum = aGrilleInfo->GetFamNumNode(iNode);
1234       if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies ))
1235         {
1236           aFamily->AddElement(aNode);
1237           aFamily->SetType(SMDSAbs_Node);
1238         }
1239     }
1240     
1241   }
1242
1243   SMDS_MeshElement* anElement = NULL;
1244   MED::TIntVector aNodeIds;
1245   for(MED::TInt iCell=0;iCell < aNbCells; iCell++){
1246     aNodeIds = aGrilleInfo->GetConn(iCell);
1247     switch(aGrilleInfo->GetGeom()){
1248     case MED::eSEG2:
1249       if(aNodeIds.size() != 2){
1250         res = false;
1251         EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 2!="<<aNodeIds.size());
1252       }
1253       anElement = myMesh->AddEdgeWithID(aNodeIds[0]+1,
1254                                         aNodeIds[1]+1,
1255                                         iCell+1);
1256       break;
1257     case MED::eQUAD4:
1258       if(aNodeIds.size() != 4){
1259         res = false;
1260         EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 4!="<<aNodeIds.size());
1261       }
1262       anElement = myMesh->AddFaceWithID(aNodeIds[0]+1,
1263                                         aNodeIds[2]+1,
1264                                         aNodeIds[3]+1,
1265                                         aNodeIds[1]+1,
1266                                         iCell+1);
1267       break;
1268     case MED::eHEXA8:
1269       if(aNodeIds.size() != 8){
1270         res = false;
1271         EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 8!="<<aNodeIds.size());
1272       }
1273       anElement = myMesh->AddVolumeWithID(aNodeIds[0]+1,
1274                                           aNodeIds[2]+1,
1275                                           aNodeIds[3]+1,
1276                                           aNodeIds[1]+1,
1277                                           aNodeIds[4]+1,
1278                                           aNodeIds[6]+1,
1279                                           aNodeIds[7]+1,
1280                                           aNodeIds[5]+1,
1281                                           iCell+1);
1282       break;
1283     default:
1284       break;
1285     }
1286     if (!anElement) {
1287       EXCEPTION(runtime_error,"buildMeshGrille Error. Element not created! "<<iCell);
1288     }
1289     if((aGrilleInfo->myFamNum).size() > 0){
1290       TInt aFamNum = aGrilleInfo->GetFamNum(iCell);
1291       if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies )){
1292         aFamily->AddElement(anElement);
1293         aFamily->SetType(anElement->GetType());
1294       }
1295     }
1296   }
1297
1298   return res;
1299 }