Salome HOME
0023064: [CEA 1471] Create and support quadratic polygons in SMESH
[modules/smesh.git] / src / DriverMED / DriverMED_R_SMESHDS_Mesh.cxx
1 // Copyright (C) 2007-2015  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 = 1;
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 = DRS_FAIL;
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 = DRS_FAIL;
369               } catch (...) {
370                 aResult = DRS_FAIL;
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               bool anIsValidConnect = false;
505               TCConnSlice aConnSlice = aCellInfo->GetConnSlice(iElem);
506 #ifndef _DEXCEPT_
507               try{
508 #endif
509 #ifdef _EDF_NODE_IDS_
510                 if(anIsNodeNum)
511                   for(int iNode = 0; iNode < aNbNodes; iNode++)
512                     aNodeIds[iNode] = aNodeInfo->GetElemNum(aConnSlice[iNode] - 1);
513                 else
514                   for(int iNode = 0; iNode < aNbNodes; iNode++)
515                     aNodeIds[iNode] = aConnSlice[iNode];
516 #else
517                 for(int iNode = 0; iNode < aNbNodes; iNode++)
518                   aNodeIds[iNode] = aConnSlice[iNode];
519 #endif
520                 anIsValidConnect = true;
521 #ifndef _DEXCEPT_
522               }catch(const std::exception& exc){
523                 INFOS("Following exception was caught:\n\t"<<exc.what());
524                 aResult = DRS_FAIL;
525               }catch(...){
526                 INFOS("Unknown exception was caught !!!");
527                 aResult = DRS_FAIL;
528               }
529 #endif          
530               if(!anIsValidConnect)
531                 continue;
532
533               bool isRenum = false;
534               const SMDS_MeshElement* anElement = NULL;
535               TInt aFamNum = aCellInfo->GetFamNum(iElem);
536 #ifndef _DEXCEPT_
537               try{
538 #endif
539                 //MESSAGE("Try to create element # " << iElem << " with id = "
540                 //        << aCellInfo->GetElemNum(iElem));
541                 switch(aGeom) {
542                 case ePOINT1:
543                   //anElement = FindNode(myMesh,aNodeIds[0]);
544                   if(anIsElemNum)
545                     anElement = myMesh->Add0DElementWithID
546                       (aNodeIds[0], aCellInfo->GetElemNum(iElem));
547                   if (!anElement) {
548                     anElement = myMesh->Add0DElement(FindNode(myMesh,aNodeIds[0]));
549                     isRenum = anIsElemNum;
550                   }
551                   break;
552                 case eSEG2:
553                   if(anIsElemNum)
554                     anElement = myMesh->AddEdgeWithID(aNodeIds[0],
555                                                       aNodeIds[1],
556                                                       aCellInfo->GetElemNum(iElem));
557                   if (!anElement) {
558                     anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
559                                                 FindNode(myMesh,aNodeIds[1]));
560                     isRenum = anIsElemNum;
561                   }
562                   break;
563                 case eSEG3:
564                   if(anIsElemNum)
565                     anElement = myMesh->AddEdgeWithID(aNodeIds[0],
566                                                       aNodeIds[1],
567                                                       aNodeIds[2],
568                                                       aCellInfo->GetElemNum(iElem));
569                   if (!anElement) {
570                     anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
571                                                 FindNode(myMesh,aNodeIds[1]),
572                                                 FindNode(myMesh,aNodeIds[2]));
573                     isRenum = anIsElemNum;
574                   }
575                   break;
576                 case eTRIA3:
577                   aNbNodes = 3;
578                   if(anIsElemNum)
579                     anElement = myMesh->AddFaceWithID(aNodeIds[0],
580                                                       aNodeIds[1],
581                                                       aNodeIds[2],
582                                                       aCellInfo->GetElemNum(iElem));
583                   if (!anElement) {
584                     anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
585                                                 FindNode(myMesh,aNodeIds[1]),
586                                                 FindNode(myMesh,aNodeIds[2]));
587                     isRenum = anIsElemNum;
588                   }
589                   break;
590                 case eTRIA6:
591                   aNbNodes = 6;
592                   if(anIsElemNum)
593                     anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
594                                                       aNodeIds[2], aNodeIds[3],
595                                                       aNodeIds[4], aNodeIds[5],
596                                                       aCellInfo->GetElemNum(iElem));
597                   if (!anElement) {
598                     anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
599                                                 FindNode(myMesh,aNodeIds[1]),
600                                                 FindNode(myMesh,aNodeIds[2]),
601                                                 FindNode(myMesh,aNodeIds[3]),
602                                                 FindNode(myMesh,aNodeIds[4]),
603                                                 FindNode(myMesh,aNodeIds[5]));
604                     isRenum = anIsElemNum;
605                   }
606                   break;
607                 case eTRIA7:
608                   aNbNodes = 7;
609                   if(anIsElemNum)
610                     anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
611                                                       aNodeIds[2], aNodeIds[3],
612                                                       aNodeIds[4], aNodeIds[5], aNodeIds[6],
613                                                       aCellInfo->GetElemNum(iElem));
614                   if (!anElement) {
615                     anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
616                                                 FindNode(myMesh,aNodeIds[1]),
617                                                 FindNode(myMesh,aNodeIds[2]),
618                                                 FindNode(myMesh,aNodeIds[3]),
619                                                 FindNode(myMesh,aNodeIds[4]),
620                                                 FindNode(myMesh,aNodeIds[5]),
621                                                 FindNode(myMesh,aNodeIds[6]));
622                     isRenum = anIsElemNum;
623                   }
624                   break;
625                 case eQUAD4:
626                   aNbNodes = 4;
627                   if(anIsElemNum)
628                     anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
629                                                       aNodeIds[2], aNodeIds[3],
630                                                       aCellInfo->GetElemNum(iElem));
631                   if (!anElement) {
632                     anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
633                                                 FindNode(myMesh,aNodeIds[1]),
634                                                 FindNode(myMesh,aNodeIds[2]),
635                                                 FindNode(myMesh,aNodeIds[3]));
636                     isRenum = anIsElemNum;
637                   }
638                   break;
639                 case eQUAD8:
640                   aNbNodes = 8;
641                   if(anIsElemNum)
642                     anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
643                                                       aNodeIds[2], aNodeIds[3],
644                                                       aNodeIds[4], aNodeIds[5],
645                                                       aNodeIds[6], aNodeIds[7],
646                                                       aCellInfo->GetElemNum(iElem));
647                   if (!anElement) {
648                     anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
649                                                 FindNode(myMesh,aNodeIds[1]),
650                                                 FindNode(myMesh,aNodeIds[2]),
651                                                 FindNode(myMesh,aNodeIds[3]),
652                                                 FindNode(myMesh,aNodeIds[4]),
653                                                 FindNode(myMesh,aNodeIds[5]),
654                                                 FindNode(myMesh,aNodeIds[6]),
655                                                 FindNode(myMesh,aNodeIds[7]));
656                     isRenum = anIsElemNum;
657                   }
658                   break;
659                 case eQUAD9:
660                   aNbNodes = 9;
661                   if(anIsElemNum)
662                     anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
663                                                       aNodeIds[2], aNodeIds[3],
664                                                       aNodeIds[4], aNodeIds[5],
665                                                       aNodeIds[6], aNodeIds[7], aNodeIds[8],
666                                                       aCellInfo->GetElemNum(iElem));
667                   if (!anElement) {
668                     anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
669                                                 FindNode(myMesh,aNodeIds[1]),
670                                                 FindNode(myMesh,aNodeIds[2]),
671                                                 FindNode(myMesh,aNodeIds[3]),
672                                                 FindNode(myMesh,aNodeIds[4]),
673                                                 FindNode(myMesh,aNodeIds[5]),
674                                                 FindNode(myMesh,aNodeIds[6]),
675                                                 FindNode(myMesh,aNodeIds[7]),
676                                                 FindNode(myMesh,aNodeIds[8]));
677                     isRenum = anIsElemNum;
678                   }
679                   break;
680                 case eTETRA4:
681                   aNbNodes = 4;
682                   if(anIsElemNum)
683                     anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
684                                                         aNodeIds[2], aNodeIds[3],
685                                                         aCellInfo->GetElemNum(iElem));
686                   if (!anElement) {
687                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
688                                                   FindNode(myMesh,aNodeIds[1]),
689                                                   FindNode(myMesh,aNodeIds[2]),
690                                                   FindNode(myMesh,aNodeIds[3]));
691                     isRenum = anIsElemNum;
692                   }
693                   break;
694                 case eTETRA10:
695                   aNbNodes = 10;
696                   if(anIsElemNum)
697                     anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
698                                                         aNodeIds[2], aNodeIds[3],
699                                                         aNodeIds[4], aNodeIds[5],
700                                                         aNodeIds[6], aNodeIds[7],
701                                                         aNodeIds[8], aNodeIds[9],
702                                                         aCellInfo->GetElemNum(iElem));
703                   if (!anElement) {
704                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
705                                                   FindNode(myMesh,aNodeIds[1]),
706                                                   FindNode(myMesh,aNodeIds[2]),
707                                                   FindNode(myMesh,aNodeIds[3]),
708                                                   FindNode(myMesh,aNodeIds[4]),
709                                                   FindNode(myMesh,aNodeIds[5]),
710                                                   FindNode(myMesh,aNodeIds[6]),
711                                                   FindNode(myMesh,aNodeIds[7]),
712                                                   FindNode(myMesh,aNodeIds[8]),
713                                                   FindNode(myMesh,aNodeIds[9]));
714                     isRenum = anIsElemNum;
715                   }
716                   break;
717                 case ePYRA5:
718                   aNbNodes = 5;
719                   if(anIsElemNum)
720                     anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
721                                                         aNodeIds[2], aNodeIds[3],
722                                                         aNodeIds[4],
723                                                         aCellInfo->GetElemNum(iElem));
724                   if (!anElement) {
725                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
726                                                   FindNode(myMesh,aNodeIds[1]),
727                                                   FindNode(myMesh,aNodeIds[2]),
728                                                   FindNode(myMesh,aNodeIds[3]),
729                                                   FindNode(myMesh,aNodeIds[4]));
730                     isRenum = anIsElemNum;
731                   }
732                   break;
733                 case ePYRA13:
734                   aNbNodes = 13;
735                   if(anIsElemNum)
736                     anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
737                                                         aNodeIds[2], aNodeIds[3],
738                                                         aNodeIds[4], aNodeIds[5],
739                                                         aNodeIds[6], aNodeIds[7],
740                                                         aNodeIds[8], aNodeIds[9],
741                                                         aNodeIds[10], aNodeIds[11],
742                                                         aNodeIds[12],
743                                                         aCellInfo->GetElemNum(iElem));
744                   if (!anElement) {
745                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
746                                                   FindNode(myMesh,aNodeIds[1]),
747                                                   FindNode(myMesh,aNodeIds[2]),
748                                                   FindNode(myMesh,aNodeIds[3]),
749                                                   FindNode(myMesh,aNodeIds[4]),
750                                                   FindNode(myMesh,aNodeIds[5]),
751                                                   FindNode(myMesh,aNodeIds[6]),
752                                                   FindNode(myMesh,aNodeIds[7]),
753                                                   FindNode(myMesh,aNodeIds[8]),
754                                                   FindNode(myMesh,aNodeIds[9]),
755                                                   FindNode(myMesh,aNodeIds[10]),
756                                                   FindNode(myMesh,aNodeIds[11]),
757                                                   FindNode(myMesh,aNodeIds[12]));
758                     isRenum = anIsElemNum;
759                   }
760                   break;
761                 case ePENTA6:
762                   aNbNodes = 6;
763                   if(anIsElemNum)
764                     anElement = myMesh->AddVolumeWithID(aNodeIds[0],
765                                                         aNodeIds[1],
766                                                         aNodeIds[2],
767                                                         aNodeIds[3],
768                                                         aNodeIds[4],
769                                                         aNodeIds[5],
770                                                         aCellInfo->GetElemNum(iElem));
771                   if (!anElement) {
772                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
773                                                   FindNode(myMesh,aNodeIds[1]),
774                                                   FindNode(myMesh,aNodeIds[2]),
775                                                   FindNode(myMesh,aNodeIds[3]),
776                                                   FindNode(myMesh,aNodeIds[4]),
777                                                   FindNode(myMesh,aNodeIds[5]));
778                     isRenum = anIsElemNum;
779                   }
780                   break;
781                 case ePENTA15:
782                   aNbNodes = 15;
783                   if(anIsElemNum)
784                     anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
785                                                         aNodeIds[2], aNodeIds[3],
786                                                         aNodeIds[4], aNodeIds[5],
787                                                         aNodeIds[6], aNodeIds[7],
788                                                         aNodeIds[8], aNodeIds[9],
789                                                         aNodeIds[10], aNodeIds[11],
790                                                         aNodeIds[12], aNodeIds[13],
791                                                         aNodeIds[14],
792                                                         aCellInfo->GetElemNum(iElem));
793                   if (!anElement) {
794                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
795                                                   FindNode(myMesh,aNodeIds[1]),
796                                                   FindNode(myMesh,aNodeIds[2]),
797                                                   FindNode(myMesh,aNodeIds[3]),
798                                                   FindNode(myMesh,aNodeIds[4]),
799                                                   FindNode(myMesh,aNodeIds[5]),
800                                                   FindNode(myMesh,aNodeIds[6]),
801                                                   FindNode(myMesh,aNodeIds[7]),
802                                                   FindNode(myMesh,aNodeIds[8]),
803                                                   FindNode(myMesh,aNodeIds[9]),
804                                                   FindNode(myMesh,aNodeIds[10]),
805                                                   FindNode(myMesh,aNodeIds[11]),
806                                                   FindNode(myMesh,aNodeIds[12]),
807                                                   FindNode(myMesh,aNodeIds[13]),
808                                                   FindNode(myMesh,aNodeIds[14]));
809                     isRenum = anIsElemNum;
810                   }
811                   break;
812                 case eHEXA8:
813                   aNbNodes = 8;
814                   if(anIsElemNum)
815                     anElement = myMesh->AddVolumeWithID(aNodeIds[0],
816                                                         aNodeIds[1],
817                                                         aNodeIds[2],
818                                                         aNodeIds[3],
819                                                         aNodeIds[4],
820                                                         aNodeIds[5],
821                                                         aNodeIds[6],
822                                                         aNodeIds[7],
823                                                         aCellInfo->GetElemNum(iElem));
824                   if (!anElement) {
825                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
826                                                   FindNode(myMesh,aNodeIds[1]),
827                                                   FindNode(myMesh,aNodeIds[2]),
828                                                   FindNode(myMesh,aNodeIds[3]),
829                                                   FindNode(myMesh,aNodeIds[4]),
830                                                   FindNode(myMesh,aNodeIds[5]),
831                                                   FindNode(myMesh,aNodeIds[6]),
832                                                   FindNode(myMesh,aNodeIds[7]));
833                     isRenum = anIsElemNum;
834                   }
835                   break;
836
837                 case eHEXA20:
838                   aNbNodes = 20;
839                   if(anIsElemNum)
840                     anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
841                                                         aNodeIds[2], aNodeIds[3],
842                                                         aNodeIds[4], aNodeIds[5],
843                                                         aNodeIds[6], aNodeIds[7],
844                                                         aNodeIds[8], aNodeIds[9],
845                                                         aNodeIds[10], aNodeIds[11],
846                                                         aNodeIds[12], aNodeIds[13],
847                                                         aNodeIds[14], aNodeIds[15],
848                                                         aNodeIds[16], aNodeIds[17],
849                                                         aNodeIds[18], aNodeIds[19],
850                                                         aCellInfo->GetElemNum(iElem));
851                   if (!anElement) {
852                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
853                                                   FindNode(myMesh,aNodeIds[1]),
854                                                   FindNode(myMesh,aNodeIds[2]),
855                                                   FindNode(myMesh,aNodeIds[3]),
856                                                   FindNode(myMesh,aNodeIds[4]),
857                                                   FindNode(myMesh,aNodeIds[5]),
858                                                   FindNode(myMesh,aNodeIds[6]),
859                                                   FindNode(myMesh,aNodeIds[7]),
860                                                   FindNode(myMesh,aNodeIds[8]),
861                                                   FindNode(myMesh,aNodeIds[9]),
862                                                   FindNode(myMesh,aNodeIds[10]),
863                                                   FindNode(myMesh,aNodeIds[11]),
864                                                   FindNode(myMesh,aNodeIds[12]),
865                                                   FindNode(myMesh,aNodeIds[13]),
866                                                   FindNode(myMesh,aNodeIds[14]),
867                                                   FindNode(myMesh,aNodeIds[15]),
868                                                   FindNode(myMesh,aNodeIds[16]),
869                                                   FindNode(myMesh,aNodeIds[17]),
870                                                   FindNode(myMesh,aNodeIds[18]),
871                                                   FindNode(myMesh,aNodeIds[19]));
872                     isRenum = anIsElemNum;
873                   }
874                   break;
875
876                 case eHEXA27:
877                   aNbNodes = 27;
878                   if(anIsElemNum)
879                     anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
880                                                         aNodeIds[2], aNodeIds[3],
881                                                         aNodeIds[4], aNodeIds[5],
882                                                         aNodeIds[6], aNodeIds[7],
883                                                         aNodeIds[8], aNodeIds[9],
884                                                         aNodeIds[10], aNodeIds[11],
885                                                         aNodeIds[12], aNodeIds[13],
886                                                         aNodeIds[14], aNodeIds[15],
887                                                         aNodeIds[16], aNodeIds[17],
888                                                         aNodeIds[18], aNodeIds[19],
889                                                         aNodeIds[20], aNodeIds[21],
890                                                         aNodeIds[22], aNodeIds[23],
891                                                         aNodeIds[24], aNodeIds[25],
892                                                         aNodeIds[26],
893                                                         aCellInfo->GetElemNum(iElem));
894                   if (!anElement) {
895                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
896                                                   FindNode(myMesh,aNodeIds[1]),
897                                                   FindNode(myMesh,aNodeIds[2]),
898                                                   FindNode(myMesh,aNodeIds[3]),
899                                                   FindNode(myMesh,aNodeIds[4]),
900                                                   FindNode(myMesh,aNodeIds[5]),
901                                                   FindNode(myMesh,aNodeIds[6]),
902                                                   FindNode(myMesh,aNodeIds[7]),
903                                                   FindNode(myMesh,aNodeIds[8]),
904                                                   FindNode(myMesh,aNodeIds[9]),
905                                                   FindNode(myMesh,aNodeIds[10]),
906                                                   FindNode(myMesh,aNodeIds[11]),
907                                                   FindNode(myMesh,aNodeIds[12]),
908                                                   FindNode(myMesh,aNodeIds[13]),
909                                                   FindNode(myMesh,aNodeIds[14]),
910                                                   FindNode(myMesh,aNodeIds[15]),
911                                                   FindNode(myMesh,aNodeIds[16]),
912                                                   FindNode(myMesh,aNodeIds[17]),
913                                                   FindNode(myMesh,aNodeIds[18]),
914                                                   FindNode(myMesh,aNodeIds[19]),
915                                                   FindNode(myMesh,aNodeIds[20]),
916                                                   FindNode(myMesh,aNodeIds[21]),
917                                                   FindNode(myMesh,aNodeIds[22]),
918                                                   FindNode(myMesh,aNodeIds[23]),
919                                                   FindNode(myMesh,aNodeIds[24]),
920                                                   FindNode(myMesh,aNodeIds[25]),
921                                                   FindNode(myMesh,aNodeIds[26]));
922                     isRenum = anIsElemNum;
923                   }
924                   break;
925
926                 case eOCTA12:
927                   aNbNodes = 12;
928                   if(anIsElemNum)
929                     anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
930                                                         aNodeIds[2], aNodeIds[3],
931                                                         aNodeIds[4], aNodeIds[5],
932                                                         aNodeIds[6], aNodeIds[7],
933                                                         aNodeIds[8], aNodeIds[9],
934                                                         aNodeIds[10], aNodeIds[11],
935                                                         aCellInfo->GetElemNum(iElem));
936                   if (!anElement) {
937                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
938                                                   FindNode(myMesh,aNodeIds[1]),
939                                                   FindNode(myMesh,aNodeIds[2]),
940                                                   FindNode(myMesh,aNodeIds[3]),
941                                                   FindNode(myMesh,aNodeIds[4]),
942                                                   FindNode(myMesh,aNodeIds[5]),
943                                                   FindNode(myMesh,aNodeIds[6]),
944                                                   FindNode(myMesh,aNodeIds[7]),
945                                                   FindNode(myMesh,aNodeIds[8]),
946                                                   FindNode(myMesh,aNodeIds[9]),
947                                                   FindNode(myMesh,aNodeIds[10]),
948                                                   FindNode(myMesh,aNodeIds[11]));
949                     isRenum = anIsElemNum;
950                   }
951                   break;
952
953                 } // switch(aGeom)
954
955 #ifndef _DEXCEPT_
956               }catch(const std::exception& exc){
957                 INFOS("The following exception was caught:\n\t"<<exc.what());
958                 aResult = DRS_FAIL;
959               }catch(...){
960                 INFOS("Unknown exception was caught !!!");
961                 aResult = DRS_FAIL;
962               }
963 #endif          
964               if (!anElement) {
965                 aResult = DRS_WARN_SKIP_ELEM;
966               }
967               else {
968                 if (isRenum) {
969                   anIsElemNum = eFAUX;
970                   takeNumbers = false;
971                   if (aResult < DRS_WARN_RENUMBER)
972                     aResult = DRS_WARN_RENUMBER;
973                 }
974                 if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies )) {
975                   // Save reference to this element from its family
976                   myFamilies[aFamNum]->AddElement(anElement);
977                   myFamilies[aFamNum]->SetType(anElement->GetType());
978                 }
979               }
980             }
981           }}
982         }
983       }
984       if (aDescendingEntitiesMap.Extent()) isDescConn = true; // Mantis issue 0020483
985     } // for(int iMesh = 0; iMesh < aNbMeshes; iMesh++)
986 #ifndef _DEXCEPT_
987   }
988   catch(const std::exception& exc)
989   {
990     INFOS("The following exception was caught:\n\t"<<exc.what());
991     aResult = DRS_FAIL;
992   }
993   catch(...)
994   {
995     INFOS("Unknown exception was caught !!!");
996     aResult = DRS_FAIL;
997   }
998 #endif
999   if (myMesh)
1000     myMesh->compactMesh();
1001
1002   // Mantis issue 0020483
1003   if (aResult == DRS_OK && isDescConn) {
1004     INFOS("There are some elements in descending connectivity in med file. They were not read !!!");
1005     aResult = DRS_WARN_DESCENDING;
1006   }
1007
1008   if(MYDEBUG) MESSAGE("Perform - aResult status = "<<aResult);
1009   return aResult;
1010 }
1011
1012 list<string> DriverMED_R_SMESHDS_Mesh::GetMeshNames(Status& theStatus)
1013 {
1014   list<string> aMeshNames;
1015
1016   try {
1017     if(MYDEBUG) MESSAGE("GetMeshNames - myFile : " << myFile);
1018     theStatus = DRS_OK;
1019     PWrapper aMed = CrWrapper(myFile);
1020
1021     if (TInt aNbMeshes = aMed->GetNbMeshes()) {
1022       for (int iMesh = 0; iMesh < aNbMeshes; iMesh++) {
1023         // Reading the MED mesh
1024         //---------------------
1025         PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
1026         aMeshNames.push_back(aMeshInfo->GetName());
1027       }
1028     }
1029   } catch(const std::exception& exc) {
1030     INFOS("Following exception was caught:\n\t"<<exc.what());
1031     theStatus = DRS_FAIL;
1032   } catch(...) {
1033     INFOS("Unknown exception was caught !!!");
1034     theStatus = DRS_FAIL;
1035   }
1036
1037   return aMeshNames;
1038 }
1039
1040 list<TNameAndType> DriverMED_R_SMESHDS_Mesh::GetGroupNamesAndTypes()
1041 {
1042   list<TNameAndType> aResult;
1043   set<TNameAndType> aResGroupNames;
1044
1045   map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
1046   for (; aFamsIter != myFamilies.end(); aFamsIter++)
1047   {
1048     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
1049     const MED::TStringSet& aGroupNames = aFamily->GetGroupNames();
1050     set<string>::const_iterator aGrNamesIter = aGroupNames.begin();
1051     for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
1052     {
1053       const set< SMDSAbs_ElementType >& types = aFamily->GetTypes();
1054       set< SMDSAbs_ElementType >::const_iterator type = types.begin();
1055       for ( ; type != types.end(); ++type )
1056       {
1057         TNameAndType aNameAndType = make_pair( *aGrNamesIter, *type );
1058         if ( aResGroupNames.insert( aNameAndType ).second ) {
1059           aResult.push_back( aNameAndType );
1060         }
1061       }
1062     }
1063   }
1064
1065   return aResult;
1066 }
1067
1068 void DriverMED_R_SMESHDS_Mesh::GetGroup(SMESHDS_Group* theGroup)
1069 {
1070   string aGroupName (theGroup->GetStoreName());
1071   if(MYDEBUG) MESSAGE("Get Group " << aGroupName);
1072
1073   map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
1074   for (; aFamsIter != myFamilies.end(); aFamsIter++)
1075   {
1076     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
1077     if (aFamily->GetTypes().count( theGroup->GetType() ) && aFamily->MemberOf(aGroupName))
1078     {
1079       const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
1080       set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
1081       for (; anElemsIter != anElements.end(); anElemsIter++)
1082       {
1083         const SMDS_MeshElement * element = *anElemsIter;
1084         if ( element->GetType() == theGroup->GetType() ) // Issue 0020576
1085           theGroup->SMDSGroup().Add(element);
1086       }
1087       int aGroupAttrVal = aFamily->GetGroupAttributVal();
1088       if( aGroupAttrVal != 0)
1089         theGroup->SetColorGroup(aGroupAttrVal);
1090 //       if ( element ) -- Issue 0020576
1091 //         theGroup->SetType( theGroup->SMDSGroup().GetType() );
1092     }
1093   }
1094 }
1095
1096 void DriverMED_R_SMESHDS_Mesh::GetSubMesh (SMESHDS_SubMesh* theSubMesh,
1097                                            const int theId)
1098 {
1099   char submeshGrpName[ 30 ];
1100   sprintf( submeshGrpName, "SubMesh %d", theId );
1101   string aName (submeshGrpName);
1102   map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
1103   for (; aFamsIter != myFamilies.end(); aFamsIter++)
1104   {
1105     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
1106     if (aFamily->MemberOf(aName))
1107     {
1108       const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
1109       set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
1110       if (aFamily->GetType() == SMDSAbs_Node)
1111       {
1112         for (; anElemsIter != anElements.end(); anElemsIter++)
1113         {
1114           const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>(*anElemsIter);
1115           theSubMesh->AddNode(node);
1116         }
1117       }
1118       else
1119       {
1120         for (; anElemsIter != anElements.end(); anElemsIter++)
1121         {
1122           theSubMesh->AddElement(*anElemsIter);
1123         }
1124       }
1125     }
1126   }
1127 }
1128
1129 void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes ()
1130 {
1131   map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
1132   for (; aFamsIter != myFamilies.end(); aFamsIter++)
1133   {
1134     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
1135     MED::TStringSet aGroupNames = aFamily->GetGroupNames();
1136     set<string>::iterator aGrNamesIter = aGroupNames.begin();
1137     for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
1138     {
1139       string aName = *aGrNamesIter;
1140       // Check, if this is a Group or SubMesh name
1141       if (aName.substr(0, 7) == string("SubMesh"))
1142       {
1143         int Id = atoi(string(aName).substr(7).c_str());
1144         set<const SMDS_MeshElement *> anElements = aFamily->GetElements();
1145         set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
1146         if (aFamily->GetType() == SMDSAbs_Node)
1147         {
1148           for (; anElemsIter != anElements.end(); anElemsIter++)
1149           {
1150             SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>
1151               ( static_cast<const SMDS_MeshNode*>( *anElemsIter ));
1152             // find out a shape type
1153             TopoDS_Shape aShape = myMesh->IndexToShape( Id );
1154             int aShapeType = ( aShape.IsNull() ? -1 : aShape.ShapeType() );
1155             switch ( aShapeType ) {
1156             case TopAbs_FACE:
1157               myMesh->SetNodeOnFace(node, Id); break;
1158             case TopAbs_EDGE:
1159               myMesh->SetNodeOnEdge(node, Id); break;
1160             case TopAbs_VERTEX:
1161               myMesh->SetNodeOnVertex(node, Id); break;
1162             default:
1163               myMesh->SetNodeInVolume(node, Id);
1164             }
1165           }
1166         }
1167         else
1168         {
1169           for (; anElemsIter != anElements.end(); anElemsIter++)
1170           {
1171             myMesh->SetMeshElementOnShape(*anElemsIter, Id);
1172           }
1173         }
1174       }
1175     }
1176   }
1177 }
1178 /*!
1179  * \brief Ensure aFamily to have required ID
1180  * \param aFamily - a family to check and update
1181  * \param anID - an ID aFamily should have
1182  * \retval bool  - true if successful
1183  */
1184 bool DriverMED::checkFamilyID(DriverMED_FamilyPtr & aFamily,
1185                               int                   anID,
1186                               const TID2FamilyMap&  myFamilies)
1187 {
1188   if ( !aFamily || aFamily->GetId() != anID ) {
1189     map<int, DriverMED_FamilyPtr>::const_iterator i_fam = myFamilies.find(anID);
1190     if ( i_fam == myFamilies.end() )
1191       return false;
1192     aFamily = i_fam->second;
1193   }
1194   return ( aFamily->GetId() == anID );
1195 }
1196
1197 /*!
1198  * \brief Reading the structured mesh and convert to non structured
1199  *        (by filling of smesh structure for non structured mesh)
1200  * \param theWrapper  - PWrapper const pointer
1201  * \param theMeshInfo - PMeshInfo const pointer
1202  * \param myFamilies  - a map of the family ID to the Family
1203  * \return TRUE, if successfully. Else FALSE
1204  */
1205 bool DriverMED::buildMeshGrille(const MED::PWrapper&  theWrapper,
1206                                 const MED::PMeshInfo& theMeshInfo,
1207                                 SMESHDS_Mesh*         myMesh,
1208                                 const TID2FamilyMap&  myFamilies)
1209 {
1210   bool res = true;
1211
1212   MED::PGrilleInfo aGrilleInfo = theWrapper->GetPGrilleInfo(theMeshInfo);
1213   MED::TInt aNbNodes = aGrilleInfo->GetNbNodes();
1214   MED::TInt aNbCells = aGrilleInfo->GetNbCells();
1215   MED::TInt aMeshDim = theMeshInfo->GetDim();
1216   DriverMED_FamilyPtr aFamily;
1217   for(MED::TInt iNode=0;iNode < aNbNodes; iNode++){
1218     double aCoords[3] = {0.0, 0.0, 0.0};
1219     const SMDS_MeshNode* aNode;
1220     MED::TNodeCoord aMEDNodeCoord = aGrilleInfo->GetCoord(iNode);
1221     for(MED::TInt iDim=0;iDim<aMeshDim;iDim++)
1222       aCoords[(int)iDim] = aMEDNodeCoord[(int)iDim];
1223     aNode = myMesh->AddNodeWithID(aCoords[0],aCoords[1],aCoords[2],iNode+1);
1224     if (!aNode) {
1225       EXCEPTION(runtime_error,"buildMeshGrille Error. Node not created! "<<(int)iNode);
1226     }
1227
1228     if((aGrilleInfo->myFamNumNode).size() > 0){
1229       TInt aFamNum = aGrilleInfo->GetFamNumNode(iNode);
1230       if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies ))
1231         {
1232           aFamily->AddElement(aNode);
1233           aFamily->SetType(SMDSAbs_Node);
1234         }
1235     }
1236     
1237   }
1238
1239   SMDS_MeshElement* anElement = NULL;
1240   MED::TIntVector aNodeIds;
1241   for(MED::TInt iCell=0;iCell < aNbCells; iCell++){
1242     aNodeIds = aGrilleInfo->GetConn(iCell);
1243     switch(aGrilleInfo->GetGeom()){
1244     case MED::eSEG2:
1245       if(aNodeIds.size() != 2){
1246         res = false;
1247         EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 2!="<<aNodeIds.size());
1248       }
1249       anElement = myMesh->AddEdgeWithID(aNodeIds[0]+1,
1250                                         aNodeIds[1]+1,
1251                                         iCell+1);
1252       break;
1253     case MED::eQUAD4:
1254       if(aNodeIds.size() != 4){
1255         res = false;
1256         EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 4!="<<aNodeIds.size());
1257       }
1258       anElement = myMesh->AddFaceWithID(aNodeIds[0]+1,
1259                                         aNodeIds[2]+1,
1260                                         aNodeIds[3]+1,
1261                                         aNodeIds[1]+1,
1262                                         iCell+1);
1263       break;
1264     case MED::eHEXA8:
1265       if(aNodeIds.size() != 8){
1266         res = false;
1267         EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 8!="<<aNodeIds.size());
1268       }
1269       anElement = myMesh->AddVolumeWithID(aNodeIds[0]+1,
1270                                           aNodeIds[2]+1,
1271                                           aNodeIds[3]+1,
1272                                           aNodeIds[1]+1,
1273                                           aNodeIds[4]+1,
1274                                           aNodeIds[6]+1,
1275                                           aNodeIds[7]+1,
1276                                           aNodeIds[5]+1,
1277                                           iCell+1);
1278       break;
1279     default:
1280       break;
1281     }
1282     if (!anElement) {
1283       EXCEPTION(runtime_error,"buildMeshGrille Error. Element not created! "<<iCell);
1284     }
1285     if((aGrilleInfo->myFamNum).size() > 0){
1286       TInt aFamNum = aGrilleInfo->GetFamNum(iCell);
1287       if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies )){
1288         aFamily->AddElement(anElement);
1289         aFamily->SetType(anElement->GetType());
1290       }
1291     }
1292   }
1293
1294   return res;
1295 }