Salome HOME
Join BR-D5-38-2003
[modules/smesh.git] / src / DriverMED / DriverMED_R_SMESHDS_Mesh.cxx
1 //  SMESH DriverMED : driver to read and write 'med' files
2 //
3 //  Copyright (C) 2003  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. 
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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : DriverMED_R_SMESHDS_Mesh.cxx
25 //  Module : SMESH
26
27 #include "DriverMED_R_SMESHDS_Mesh.h"
28 #include "DriverMED_R_SMDS_Mesh.h"
29 #include "SMESHDS_Mesh.hxx"
30 #include "utilities.h"
31
32 #include "DriverMED_Family.h"
33
34 #include "SMESHDS_Group.hxx"
35
36 #include "MED_Factory.hxx"
37 #include "MED_CoordUtils.hxx"
38 #include "MED_Utilities.hxx"
39
40 #include <stdlib.h>
41
42 #ifdef _DEBUG_
43 static int MYDEBUG = 0;
44 #else
45 static int MYDEBUG = 0;
46 #endif
47
48 #define _EDF_NODE_IDS_
49
50 using namespace MED;
51
52 void
53 DriverMED_R_SMESHDS_Mesh
54 ::SetMeshName(string theMeshName)
55 {
56   myMeshName = theMeshName;
57 }
58
59 static const SMDS_MeshNode* 
60 FindNode(const SMDS_Mesh* theMesh, TInt theId){
61   const SMDS_MeshNode* aNode = theMesh->FindNode(theId);
62   if(aNode) return aNode;
63   EXCEPTION(runtime_error,"SMDS_Mesh::FindNode - cannot find a SMDS_MeshNode for ID = "<<theId);
64 }
65
66
67 Driver_Mesh::Status 
68 DriverMED_R_SMESHDS_Mesh
69 ::Perform()
70 {
71   Status aResult = DRS_FAIL;
72   try{
73     myFamilies.clear();
74     if(MYDEBUG) MESSAGE("Perform - myFile : "<<myFile);
75     PWrapper aMed = CrWrapper(myFile);
76
77     aResult = DRS_EMPTY;
78     if(TInt aNbMeshes = aMed->GetNbMeshes()){
79       for(int iMesh = 0; iMesh < aNbMeshes; iMesh++){
80         // Reading the MED mesh
81         //---------------------
82         PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
83         string aMeshName;
84         if (myMeshId != -1) {
85           ostringstream aMeshNameStr;
86           aMeshNameStr<<myMeshId;
87           aMeshName = aMeshNameStr.str();
88         } else {
89           aMeshName = myMeshName;
90         }
91         if(MYDEBUG) MESSAGE("Perform - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
92         if(aMeshName != aMeshInfo->GetName()) continue;
93         aResult = DRS_OK;
94         //TInt aMeshDim = aMeshInfo->GetDim();
95         
96         // Reading MED families to the temporary structure
97         //------------------------------------------------
98         TErr anErr;
99         TInt aNbFams = aMed->GetNbFamilies(aMeshInfo);
100         if(MYDEBUG) MESSAGE("Read " << aNbFams << " families");
101         for (TInt iFam = 0; iFam < aNbFams; iFam++) {
102           PFamilyInfo aFamilyInfo = aMed->GetPFamilyInfo(aMeshInfo,iFam+1,&anErr);
103           if(anErr >= 0){
104             TInt aFamId = aFamilyInfo->GetId();
105             if(MYDEBUG) MESSAGE("Family " << aFamId << " :");
106             
107             DriverMED_FamilyPtr aFamily (new DriverMED_Family);
108             
109             TInt aNbGrp = aFamilyInfo->GetNbGroup();
110             if(MYDEBUG) MESSAGE("belong to " << aNbGrp << " groups");
111             for (TInt iGr = 0; iGr < aNbGrp; iGr++) {
112               string aGroupName = aFamilyInfo->GetGroupName(iGr);
113               if(MYDEBUG) MESSAGE(aGroupName);
114               aFamily->AddGroupName(aGroupName);
115             }
116             aFamily->SetId( aFamId );
117             myFamilies[aFamId] = aFamily;
118           }
119         }
120
121         // Reading MED nodes to the corresponding SMDS structure
122         //------------------------------------------------------
123         PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo);
124
125         PCoordHelper aCoordHelper = GetCoordHelper(aNodeInfo);
126
127         EBooleen anIsNodeNum = aNodeInfo->IsElemNum();
128         TInt aNbElems = aNodeInfo->GetNbElem();
129         if(MYDEBUG) MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbElems<<"; anIsNodeNum = "<<anIsNodeNum);
130         DriverMED_FamilyPtr aFamily;
131         for(TInt iElem = 0; iElem < aNbElems; iElem++){
132           TCCoordSlice aCoordSlice = aNodeInfo->GetCoordSlice(iElem);
133           double aCoords[3] = {0.0, 0.0, 0.0};
134           for(TInt iDim = 0; iDim < 3; iDim++)
135             aCoords[iDim] = aCoordHelper->GetCoord(aCoordSlice,iDim);
136           const SMDS_MeshNode* aNode;
137           if(anIsNodeNum) {
138             aNode = myMesh->AddNodeWithID
139               (aCoords[0],aCoords[1],aCoords[2],aNodeInfo->GetElemNum(iElem));
140           } else {
141             aNode = myMesh->AddNode
142               (aCoords[0],aCoords[1],aCoords[2]);
143           }
144           //cout<<aNode->GetID()<<": "<<aNode->X()<<", "<<aNode->Y()<<", "<<aNode->Z()<<endl;
145
146           // Save reference to this node from its family
147           TInt aFamNum = aNodeInfo->GetFamNum(iElem);
148           if ( checkFamilyID ( aFamily, aFamNum ))
149           {
150             aFamily->AddElement(aNode);
151             aFamily->SetType(SMDSAbs_Node);
152           }
153         }
154
155         // Reading pre information about all MED cells
156         //--------------------------------------------
157         typedef std::vector<int> TNodeIds;
158         bool takeNumbers = true;  // initially we trust the numbers from file
159         MED::TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo);
160         MED::TEntityInfo::iterator anEntityIter = aEntityInfo.begin();
161         for(; anEntityIter != aEntityInfo.end(); anEntityIter++){
162           const EEntiteMaillage& anEntity = anEntityIter->first;
163           if(anEntity == eNOEUD) continue;
164           // Reading MED cells to the corresponding SMDS structure
165           //------------------------------------------------------
166           const MED::TGeom2Size& aGeom2Size = anEntityIter->second;
167           MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
168           for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
169             const EGeometrieElement& aGeom = aGeom2SizeIter->first;
170
171             switch(aGeom){
172             case ePOINT1:
173               break;
174             case ePOLYGONE: {
175               PPolygoneInfo aPolygoneInfo = aMed->GetPPolygoneInfo(aMeshInfo,anEntity,aGeom);
176               EBooleen anIsElemNum = takeNumbers ? aPolygoneInfo->IsElemNum() : eFAUX;
177               
178               TInt aNbElem = aPolygoneInfo->GetNbElem();
179               for(TInt iElem = 0; iElem < aNbElem; iElem++){
180                 MED::TCConnSlice aConnSlice = aPolygoneInfo->GetConnSlice(iElem);
181                 TInt aNbConn = aPolygoneInfo->GetNbConn(iElem);
182                 TNodeIds aNodeIds(aNbConn);
183 #ifdef _EDF_NODE_IDS_
184                 if(anIsNodeNum)
185                   for(TInt iConn = 0; iConn < aNbConn; iConn++)
186                     aNodeIds[iConn] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
187                 else
188                   for(TInt iConn = 0; iConn < aNbConn; iConn++)
189                     aNodeIds[iConn] = aConnSlice[iConn];
190 #else
191                 for(TInt iConn = 0; iConn < aNbConn; iConn++)
192                   aNodeIds[iConn] = aConnSlice[iConn];
193 #endif
194                 bool isRenum = false;
195                 SMDS_MeshElement* anElement = NULL;
196                 TInt aFamNum = aPolygoneInfo->GetFamNum(iElem);
197
198                 try{
199                   if(anIsElemNum){
200                     TInt anElemId = aPolygoneInfo->GetElemNum(iElem);
201                     anElement = myMesh->AddPolygonalFaceWithID(aNodeIds,anElemId);
202                   }
203                   if(!anElement){
204                     std::vector<const SMDS_MeshNode*> aNodes(aNbConn);
205                     for(TInt iConn = 0; iConn < aNbConn; iConn++)
206                       aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
207                     anElement = myMesh->AddPolygonalFace(aNodes);
208                     isRenum = anIsElemNum;
209                   }
210                 }catch(const std::exception& exc){
211                   aResult = DRS_FAIL;
212                 }catch (...){
213                   aResult = DRS_FAIL;
214                 }
215
216                 if(!anElement){
217                   aResult = DRS_WARN_SKIP_ELEM;
218                 }else{
219                   if(isRenum){
220                     anIsElemNum = eFAUX;
221                     takeNumbers = false;
222                     if(aResult < DRS_WARN_RENUMBER)
223                       aResult = DRS_WARN_RENUMBER;
224                   }
225                   if ( checkFamilyID ( aFamily, aFamNum ))
226                   {
227                     // Save reference to this element from its family
228                     aFamily->AddElement(anElement);
229                     aFamily->SetType(anElement->GetType());
230                   }
231                 }
232               } // for (TInt iPG = 0; iPG < nbPolygons; iPG++)
233               break;
234             }
235             case ePOLYEDRE: {
236               PPolyedreInfo aPolyedreInfo = aMed->GetPPolyedreInfo(aMeshInfo,anEntity,aGeom);
237               EBooleen anIsElemNum = takeNumbers ? aPolyedreInfo->IsElemNum() : eFAUX;
238
239               TInt aNbElem = aPolyedreInfo->GetNbElem();
240               for(TInt iElem = 0; iElem < aNbElem; iElem++){
241                 MED::TCConnSliceArr aConnSliceArr = aPolyedreInfo->GetConnSliceArr(iElem);
242                 TInt aNbFaces = aConnSliceArr.size();
243                 typedef std::vector<int> TQuantities;
244                 TQuantities aQuantities(aNbFaces);
245                 TInt aNbNodes = aPolyedreInfo->GetNbNodes(iElem);
246                 TNodeIds aNodeIds(aNbNodes);
247                 for(TInt iFace = 0, iNode = 0; iFace < aNbFaces; iFace++){
248                   MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
249                   TInt aNbConn = aConnSlice.size();
250                   aQuantities[iFace] = aNbConn;
251 #ifdef _EDF_NODE_IDS_
252                   if(anIsNodeNum)
253                     for(TInt iConn = 0; iConn < aNbConn; iConn++)
254                       aNodeIds[iNode++] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
255                   else
256                     for(TInt iConn = 0; iConn < aNbConn; iConn++)
257                       aNodeIds[iNode++] = aConnSlice[iConn];
258 #else
259                   for(TInt iConn = 0; iConn < aNbConn; iConn++)
260                     aNodeIds[iNode++] = aConnSlice[iConn];
261 #endif
262                 }
263                 
264                 bool isRenum = false;
265                 SMDS_MeshElement* anElement = NULL;
266                 TInt aFamNum = aPolyedreInfo->GetFamNum(iElem);
267
268                 try{
269                   if(anIsElemNum){
270                     TInt anElemId = aPolyedreInfo->GetElemNum(iElem);
271                     anElement = myMesh->AddPolyhedralVolumeWithID(aNodeIds,aQuantities,anElemId);
272                   }
273                   if(!anElement){
274                     std::vector<const SMDS_MeshNode*> aNodes(aNbNodes);
275                     for(TInt iConn = 0; iConn < aNbNodes; iConn++)
276                       aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
277                     anElement = myMesh->AddPolyhedralVolume(aNodes,aQuantities);
278                     isRenum = anIsElemNum;
279                   }
280                 }catch(const std::exception& exc){
281                   aResult = DRS_FAIL;
282                 }catch(...){
283                   aResult = DRS_FAIL;
284                 }
285
286                 if(!anElement){
287                   aResult = DRS_WARN_SKIP_ELEM;
288                 }else{
289                   if(isRenum){
290                     anIsElemNum = eFAUX;
291                     takeNumbers = false;
292                     if (aResult < DRS_WARN_RENUMBER)
293                       aResult = DRS_WARN_RENUMBER;
294                   }
295                   if ( checkFamilyID ( aFamily, aFamNum ))
296                   {
297                     // Save reference to this element from its family
298                     aFamily->AddElement(anElement);
299                     aFamily->SetType(anElement->GetType());
300                   }
301                 }
302               } // for (int iPE = 0; iPE < nbPolyedres; iPE++)
303               break;
304             }
305             default: {
306               PCellInfo aCellInfo = aMed->GetPCellInfo(aMeshInfo,anEntity,aGeom);
307               EBooleen anIsElemNum = takeNumbers ? aCellInfo->IsElemNum() : eFAUX;
308               TInt aNbElems = aCellInfo->GetNbElem();
309               if(MYDEBUG) MESSAGE("Perform - anEntity = "<<anEntity<<"; anIsElemNum = "<<anIsElemNum);
310               if(MYDEBUG) MESSAGE("Perform - aGeom = "<<aGeom<<"; aNbElems = "<<aNbElems);
311               
312               for(int iElem = 0; iElem < aNbElems; iElem++){
313                 TInt aNbNodes = -1;
314                 switch(aGeom){
315                 case eSEG2:
316                 case eSEG3:
317                   aNbNodes = 2;
318                   break;
319                 case eTRIA3:
320                 case eTRIA6:
321                   aNbNodes = 3;
322                   break;
323                   break;
324                 case eQUAD4:
325                 case eQUAD8:
326                   aNbNodes = 4;
327                   break;
328                 case eTETRA4:
329                 case eTETRA10:
330                   aNbNodes = 4;
331                   break;
332                 case ePYRA5:
333                 case ePYRA13:
334                   aNbNodes = 5;
335                   break;
336                 case ePENTA6:
337                 case ePENTA15:
338                   aNbNodes = 6;
339                   break;
340                 case eHEXA8:
341                 case eHEXA20:
342                   aNbNodes = 8;
343                   break;
344                 }
345                 TNodeIds aNodeIds(aNbNodes);
346                 bool anIsValidConnect = false;
347                 TCConnSlice aConnSlice = aCellInfo->GetConnSlice(iElem);
348                 try{
349 #ifdef _EDF_NODE_IDS_
350                   if(anIsNodeNum)
351                     for(int iNode = 0; iNode < aNbNodes; iNode++)
352                       aNodeIds[iNode] = aNodeInfo->GetElemNum(aConnSlice[iNode] - 1);
353                   else
354                     for(int iNode = 0; iNode < aNbNodes; iNode++)
355                       aNodeIds[iNode] = aConnSlice[iNode];
356 #else
357                   for(int iNode = 0; iNode < aNbNodes; iNode++)
358                     aNodeIds[iNode] = aConnSlice[iNode];
359 #endif
360                   anIsValidConnect = true;
361                 }catch(const std::exception& exc){
362                   //INFOS("Follow exception was cought:\n\t"<<exc.what());
363                   aResult = DRS_FAIL;
364                 }catch(...){
365                   //INFOS("Unknown exception was cought !!!");
366                   aResult = DRS_FAIL;
367                 }
368                 
369                 if(!anIsValidConnect)
370                   continue;
371                 
372                 bool isRenum = false;
373                 SMDS_MeshElement* anElement = NULL;
374                 TInt aFamNum = aCellInfo->GetFamNum(iElem);
375                 try{
376                   //MESSAGE("Try to create element # " << iElem << " with id = "
377                   //        << aCellInfo->GetElemNum(iElem));
378                   switch(aGeom){
379                   case eSEG2:
380                   case eSEG3:
381                     if(anIsElemNum)
382                       anElement = myMesh->AddEdgeWithID(aNodeIds[0],
383                                                         aNodeIds[1],
384                                                         aCellInfo->GetElemNum(iElem));
385                     if (!anElement) {
386                       anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
387                                                   FindNode(myMesh,aNodeIds[1]));
388                       isRenum = anIsElemNum;
389                     }
390                     break;
391                   case eTRIA3:
392                   case eTRIA6:
393                     aNbNodes = 3;
394                     if(anIsElemNum)
395                       anElement = myMesh->AddFaceWithID(aNodeIds[0],
396                                                         aNodeIds[1],
397                                                         aNodeIds[2],
398                                                         aCellInfo->GetElemNum(iElem));
399                     if (!anElement) {
400                       anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
401                                                   FindNode(myMesh,aNodeIds[1]),
402                                                   FindNode(myMesh,aNodeIds[2]));
403                       isRenum = anIsElemNum;
404                     }
405                     break;
406                   case eQUAD4:
407                   case eQUAD8:
408                     aNbNodes = 4;
409                     // There is some differnce between SMDS and MED
410                     if(anIsElemNum)
411                       anElement = myMesh->AddFaceWithID(aNodeIds[0],
412                                                         aNodeIds[1],
413                                                         aNodeIds[2],
414                                                         aNodeIds[3],
415                                                         aCellInfo->GetElemNum(iElem));
416                     if (!anElement) {
417                       anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
418                                                   FindNode(myMesh,aNodeIds[1]),
419                                                   FindNode(myMesh,aNodeIds[2]),
420                                                   FindNode(myMesh,aNodeIds[3]));
421                       isRenum = anIsElemNum;
422                     }
423                     break;
424                   case eTETRA4:
425                   case eTETRA10:
426                     aNbNodes = 4;
427                     if(anIsElemNum)
428                       anElement = myMesh->AddVolumeWithID(aNodeIds[0],
429                                                           aNodeIds[1],
430                                                           aNodeIds[2],
431                                                           aNodeIds[3],
432                                                           aCellInfo->GetElemNum(iElem));
433                     if (!anElement) {
434                       anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
435                                                     FindNode(myMesh,aNodeIds[1]),
436                                                     FindNode(myMesh,aNodeIds[2]),
437                                                     FindNode(myMesh,aNodeIds[3]));
438                       isRenum = anIsElemNum;
439                     }
440                     break;
441                   case ePYRA5:
442                   case ePYRA13:
443                     aNbNodes = 5;
444                     // There is some differnce between SMDS and MED
445                     if(anIsElemNum)
446                       anElement = myMesh->AddVolumeWithID(aNodeIds[0],
447                                                           aNodeIds[1],
448                                                           aNodeIds[2],
449                                                           aNodeIds[3],
450                                                           aNodeIds[4],
451                                                           aCellInfo->GetElemNum(iElem));
452                     if (!anElement) {
453                       anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
454                                                     FindNode(myMesh,aNodeIds[1]),
455                                                     FindNode(myMesh,aNodeIds[2]),
456                                                     FindNode(myMesh,aNodeIds[3]),
457                                                     FindNode(myMesh,aNodeIds[4]));
458                       isRenum = anIsElemNum;
459                     }
460                     break;
461                   case ePENTA6:
462                   case ePENTA15:
463                     aNbNodes = 6;
464                     if(anIsElemNum)
465                       anElement = myMesh->AddVolumeWithID(aNodeIds[0],
466                                                           aNodeIds[1],
467                                                           aNodeIds[2],
468                                                           aNodeIds[3],
469                                                           aNodeIds[4],
470                                                           aNodeIds[5],
471                                                           aCellInfo->GetElemNum(iElem));
472                     if (!anElement) {
473                       anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
474                                                     FindNode(myMesh,aNodeIds[1]),
475                                                     FindNode(myMesh,aNodeIds[2]),
476                                                     FindNode(myMesh,aNodeIds[3]),
477                                                     FindNode(myMesh,aNodeIds[4]),
478                                                     FindNode(myMesh,aNodeIds[5]));
479                       isRenum = anIsElemNum;
480                     }
481                     break;
482                   case eHEXA8:
483                   case eHEXA20:
484                     aNbNodes = 8;
485                     if(anIsElemNum)
486                       anElement = myMesh->AddVolumeWithID(aNodeIds[0],
487                                                           aNodeIds[1],
488                                                           aNodeIds[2],
489                                                           aNodeIds[3],
490                                                           aNodeIds[4],
491                                                           aNodeIds[5],
492                                                           aNodeIds[6],
493                                                           aNodeIds[7],
494                                                           aCellInfo->GetElemNum(iElem));
495                     if (!anElement) {
496                       anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
497                                                     FindNode(myMesh,aNodeIds[1]),
498                                                     FindNode(myMesh,aNodeIds[2]),
499                                                     FindNode(myMesh,aNodeIds[3]),
500                                                     FindNode(myMesh,aNodeIds[4]),
501                                                     FindNode(myMesh,aNodeIds[5]),
502                                                     FindNode(myMesh,aNodeIds[6]),
503                                                     FindNode(myMesh,aNodeIds[7]));
504                       isRenum = anIsElemNum;
505                     }
506                     break;
507                   }
508                 }catch(const std::exception& exc){
509                   //INFOS("Follow exception was cought:\n\t"<<exc.what());
510                   aResult = DRS_FAIL;
511                 }catch(...){
512                   //INFOS("Unknown exception was cought !!!");
513                   aResult = DRS_FAIL;
514                 }
515                 
516                 if (!anElement) {
517                   aResult = DRS_WARN_SKIP_ELEM;
518                 }
519                 else {
520                   if (isRenum) {
521                     anIsElemNum = eFAUX;
522                     takeNumbers = false;
523                     if (aResult < DRS_WARN_RENUMBER)
524                       aResult = DRS_WARN_RENUMBER;
525                   }
526                   if ( checkFamilyID ( aFamily, aFamNum )) {
527                     // Save reference to this element from its family
528                     myFamilies[aFamNum]->AddElement(anElement);
529                     myFamilies[aFamNum]->SetType(anElement->GetType());
530                   }
531                 }
532               }
533             }}
534           }
535         }
536       }
537     }
538   }catch(const std::exception& exc){
539     INFOS("Follow exception was cought:\n\t"<<exc.what());
540     aResult = DRS_FAIL;
541   }catch(...){
542     INFOS("Unknown exception was cought !!!");
543     aResult = DRS_FAIL;
544   }
545   if(MYDEBUG) MESSAGE("Perform - aResult status = "<<aResult);
546   return aResult;
547 }
548
549 list<string> DriverMED_R_SMESHDS_Mesh::GetMeshNames(Status& theStatus)
550 {
551   list<string> aMeshNames;
552
553   try {
554     if(MYDEBUG) MESSAGE("GetMeshNames - myFile : " << myFile);
555     theStatus = DRS_OK;
556     PWrapper aMed = CrWrapper(myFile);
557
558     if (TInt aNbMeshes = aMed->GetNbMeshes()) {
559       for (int iMesh = 0; iMesh < aNbMeshes; iMesh++) {
560         // Reading the MED mesh
561         //---------------------
562         PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
563         aMeshNames.push_back(aMeshInfo->GetName());
564       }
565     }
566   }catch(const std::exception& exc){
567     INFOS("Follow exception was cought:\n\t"<<exc.what());
568     theStatus = DRS_FAIL;
569   }catch(...){
570     INFOS("Unknown exception was cought !!!");
571     theStatus = DRS_FAIL;
572   }
573
574   return aMeshNames;
575 }
576
577 list<TNameAndType> DriverMED_R_SMESHDS_Mesh::GetGroupNamesAndTypes()
578 {
579   list<TNameAndType> aResult;
580   set<TNameAndType> aResGroupNames;
581
582   map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
583   for (; aFamsIter != myFamilies.end(); aFamsIter++)
584   {
585     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
586     const MED::TStringSet& aGroupNames = aFamily->GetGroupNames();
587     set<string>::const_iterator aGrNamesIter = aGroupNames.begin();
588     for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
589     {
590       TNameAndType aNameAndType = make_pair( *aGrNamesIter, aFamily->GetType() );
591       // Check, if this is a Group or SubMesh name
592 //if (aName.substr(0, 5) == string("Group")) {
593         if ( aResGroupNames.insert( aNameAndType ).second ) {
594           aResult.push_back( aNameAndType );
595         }
596 //    }
597     }
598   }
599
600   return aResult;
601 }
602
603 void DriverMED_R_SMESHDS_Mesh::GetGroup(SMESHDS_Group* theGroup)
604 {
605   string aGroupName (theGroup->GetStoreName());
606   if(MYDEBUG) MESSAGE("Get Group " << aGroupName);
607
608   map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
609   for (; aFamsIter != myFamilies.end(); aFamsIter++)
610   {
611     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
612     if (aFamily->GetType() == theGroup->GetType() && aFamily->MemberOf(aGroupName))
613     {
614       const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
615       set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
616       const SMDS_MeshElement * element = 0;
617       for (; anElemsIter != anElements.end(); anElemsIter++)
618       {
619         element = *anElemsIter;
620         theGroup->SMDSGroup().Add(element);
621       }
622       if ( element )
623         theGroup->SetType( element->GetType() );
624     }
625   }
626 }
627
628 void DriverMED_R_SMESHDS_Mesh::GetSubMesh (SMESHDS_SubMesh* theSubMesh,
629                                            const int theId)
630 {
631   char submeshGrpName[ 30 ];
632   sprintf( submeshGrpName, "SubMesh %d", theId );
633   string aName (submeshGrpName);
634   map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
635   for (; aFamsIter != myFamilies.end(); aFamsIter++)
636   {
637     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
638     if (aFamily->MemberOf(aName))
639     {
640       const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
641       set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
642       if (aFamily->GetType() == SMDSAbs_Node)
643       {
644         for (; anElemsIter != anElements.end(); anElemsIter++)
645         {
646           const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>(*anElemsIter);
647           theSubMesh->AddNode(node);
648         }
649       }
650       else
651       {
652         for (; anElemsIter != anElements.end(); anElemsIter++)
653         {
654           theSubMesh->AddElement(*anElemsIter);
655         }
656       }
657     }
658   }
659 }
660
661 void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes ()
662 {
663   map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
664   for (; aFamsIter != myFamilies.end(); aFamsIter++)
665   {
666     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
667     MED::TStringSet aGroupNames = aFamily->GetGroupNames();
668     set<string>::iterator aGrNamesIter = aGroupNames.begin();
669     for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
670     {
671       string aName = *aGrNamesIter;
672       // Check, if this is a Group or SubMesh name
673       if (aName.substr(0, 7) == string("SubMesh"))
674       {
675         int Id = atoi(string(aName).substr(7).c_str());
676         set<const SMDS_MeshElement *> anElements = aFamily->GetElements();
677         set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
678         if (aFamily->GetType() == SMDSAbs_Node)
679         {
680           for (; anElemsIter != anElements.end(); anElemsIter++)
681           {
682             SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>
683               ( static_cast<const SMDS_MeshNode*>( *anElemsIter ));
684             // find out a shape type
685             TopoDS_Shape aShape = myMesh->IndexToShape( Id );
686             int aShapeType = ( aShape.IsNull() ? -1 : aShape.ShapeType() );
687             switch ( aShapeType ) {
688             case TopAbs_FACE:
689               myMesh->SetNodeOnFace(node, Id); break;
690             case TopAbs_EDGE:
691               myMesh->SetNodeOnEdge(node, Id); break;
692             case TopAbs_VERTEX:
693               myMesh->SetNodeOnVertex(node, Id); break;
694             default:
695               myMesh->SetNodeInVolume(node, Id);
696             }
697           }
698         }
699         else
700         {
701           for (; anElemsIter != anElements.end(); anElemsIter++)
702           {
703             myMesh->SetMeshElementOnShape(*anElemsIter, Id);
704           }
705         }
706       }
707     }
708   }
709 }
710 /*!
711  * \brief Ensure aFamily to have required ID
712  * \param aFamily - a family to check and update
713  * \param anID - an ID aFamily should have
714  * \retval bool  - true if successful
715  */
716 bool DriverMED_R_SMESHDS_Mesh::checkFamilyID(DriverMED_FamilyPtr & aFamily, int anID) const
717 {
718   if ( !aFamily || aFamily->GetId() != anID ) {
719     map<int, DriverMED_FamilyPtr>::const_iterator i_fam = myFamilies.find(anID);
720     if ( i_fam == myFamilies.end() )
721       return false;
722     aFamily = i_fam->second;
723   }
724   return ( aFamily->GetId() == anID );
725 }
726