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