Salome HOME
DCQ:prepare 2.0.0
[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 "utilities.h"
30
31 #include "DriverMED_Family.h"
32
33 #include "SMESHDS_Group.hxx"
34
35 #include "MEDA_Wrapper.hxx"
36 #include "MED_Utilities.hxx"
37
38 #include <stdlib.h>
39
40 #define _EDF_NODE_IDS_
41
42 DriverMED_R_SMESHDS_Mesh::DriverMED_R_SMESHDS_Mesh()
43      :
44        myMesh (NULL),
45        myFile (""),
46        myFileId (-1),
47        myMeshId (-1)
48 {
49 }
50
51 DriverMED_R_SMESHDS_Mesh::~DriverMED_R_SMESHDS_Mesh()
52 {
53 //  map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
54 //  for (; aFamsIter != myFamilies.end(); aFamsIter++)
55 //  {
56 //    delete (*aFamsIter).second;
57 //  }
58 }
59
60 void DriverMED_R_SMESHDS_Mesh::SetMesh(SMDS_Mesh * aMesh)
61 {
62   myMesh = aMesh;
63 }
64
65 void DriverMED_R_SMESHDS_Mesh::SetFile(string aFile)
66 {
67   myFile = aFile;
68 }
69
70 void DriverMED_R_SMESHDS_Mesh::SetFileId(med_idt aFileId)
71 {
72   myFileId = aFileId;
73 }
74
75 void DriverMED_R_SMESHDS_Mesh::SetMeshId(int aMeshId)
76 {
77   myMeshId = aMeshId;
78 }
79
80 void DriverMED_R_SMESHDS_Mesh::SetMeshName(string theMeshName)
81 {
82   myMeshName = theMeshName;
83 }
84
85 void DriverMED_R_SMESHDS_Mesh::Read()
86 {
87
88   string myClass = string("SMDS_Mesh");
89   string myExtension = string("MED");
90
91   DriverMED_R_SMDS_Mesh *myReader = new DriverMED_R_SMDS_Mesh;
92
93   myReader->SetMesh(myMesh);
94   myReader->SetMeshId(myMeshId);
95   myReader->SetFile(myFile);
96   myReader->SetFileId(-1);
97
98   myReader->Read();
99 }
100
101 void DriverMED_R_SMESHDS_Mesh::Add()
102 {
103   string myClass = string("SMDS_Mesh");
104   string myExtension = string("MED");
105
106   DriverMED_R_SMDS_Mesh *myReader = new DriverMED_R_SMDS_Mesh;
107
108   myReader->SetMesh(myMesh);
109   myReader->SetMeshId(myMeshId);
110
111   SCRUTE(myFileId);
112   myReader->SetFileId(myFileId);
113
114   myReader->Read();
115 }
116
117
118 static const SMDS_MeshNode* 
119 FindNode(const SMDS_Mesh* theMesh, med_int theId){
120   const SMDS_MeshNode* aNode = theMesh->FindNode(theId);
121   if(aNode) return aNode;
122   EXCEPTION(runtime_error,"SMDS_Mesh::FindNode - cannot find a SMDS_MeshNode for ID = "<<theId);
123 }
124
125
126 enum ECoordName{eX, eY, eZ, eNone};
127 typedef med_float (*TGetCoord)(MEDA::PNodeInfo&, med_int);
128
129 template<ECoordName TheCoordId>
130 med_float GetCoord(MEDA::PNodeInfo& thePNodeInfo, med_int theElemId){
131   return thePNodeInfo->GetNodeCoord(theElemId,TheCoordId);
132 }
133
134 template<>
135 med_float GetCoord<eNone>(MEDA::PNodeInfo& thePNodeInfo, med_int theElemId){
136   return 0.0;
137 }
138
139
140 static TGetCoord aXYZGetCoord[3] = {
141   &GetCoord<eX>, 
142   &GetCoord<eY>, 
143   &GetCoord<eZ>
144 };
145
146
147 static TGetCoord aXYGetCoord[3] = {
148   &GetCoord<eX>, 
149   &GetCoord<eY>, 
150   &GetCoord<eNone>
151 };
152
153 static TGetCoord aYZGetCoord[3] = {
154   &GetCoord<eNone>,
155   &GetCoord<eX>, 
156   &GetCoord<eY>
157 };
158
159 static TGetCoord aXZGetCoord[3] = {
160   &GetCoord<eX>, 
161   &GetCoord<eNone>,
162   &GetCoord<eY>
163 };
164
165
166 static TGetCoord aXGetCoord[3] = {
167   &GetCoord<eX>, 
168   &GetCoord<eNone>,
169   &GetCoord<eNone>
170 };
171
172 static TGetCoord aYGetCoord[3] = {
173   &GetCoord<eNone>,
174   &GetCoord<eX>, 
175   &GetCoord<eNone>
176 };
177
178 static TGetCoord aZGetCoord[3] = {
179   &GetCoord<eNone>,
180   &GetCoord<eNone>,
181   &GetCoord<eX>
182 };
183
184
185 class TCoordHelper{
186   MEDA::PNodeInfo myPNodeInfo;
187   TGetCoord* myGetCoord;
188 public:
189   TCoordHelper(const MEDA::PNodeInfo& thePNodeInfo,
190                TGetCoord* theGetCoord):
191     myPNodeInfo(thePNodeInfo),
192     myGetCoord(theGetCoord)
193   {}
194   virtual ~TCoordHelper(){}
195   med_float GetCoord(med_int theElemId, med_int theCoodId){
196     return (*myGetCoord[theCoodId])(myPNodeInfo,theElemId);
197   }
198 };
199 typedef boost::shared_ptr<TCoordHelper> TCoordHelperPtr;
200
201
202 DriverMED_R_SMESHDS_Mesh::ReadStatus DriverMED_R_SMESHDS_Mesh::ReadMySelf()
203 {
204   ReadStatus result = DRS_FAIL;
205   try{
206     using namespace MEDA;
207
208     myFamilies.clear();
209     MESSAGE("ReadMySelf - myFile : "<<myFile);
210     TWrapper aMed(myFile);
211
212     result = DRS_EMPTY;
213     if(med_int aNbMeshes = aMed.GetNbMeshes()){
214       for(int iMesh = 0; iMesh < aNbMeshes; iMesh++){
215         // Reading the MED mesh
216         //---------------------
217         PMeshInfo aMeshInfo = aMed.GetMeshInfo(iMesh);
218         string aMeshName;
219         if (myMeshId != -1) {
220           ostringstream aMeshNameStr;
221           aMeshNameStr<<myMeshId;
222           aMeshName = aMeshNameStr.str();
223         } else {
224           aMeshName = myMeshName;
225         }
226         MESSAGE("ReadMySelf - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
227         if(aMeshName != aMeshInfo->GetName()) continue;
228         result = DRS_OK;
229
230         // Reading MED families to the temporary structure
231         //------------------------------------------------
232         med_int aNbFams = aMed.GetNbFamilies(aMeshInfo);
233         MESSAGE("Read " << aNbFams << " families");
234         for (med_int iFam = 0; iFam < aNbFams; iFam++) {
235           PFamilyInfo aFamilyInfo = aMed.GetFamilyInfo(aMeshInfo, iFam);
236           med_int aFamId = aFamilyInfo->GetId();
237           MESSAGE("Family " << aFamId << " :");
238
239             DriverMED_FamilyPtr aFamily (new DriverMED_Family);
240
241             med_int aNbGrp = aFamilyInfo->GetNbGroup();
242             MESSAGE("belong to " << aNbGrp << " groups");
243             for (med_int iGr = 0; iGr < aNbGrp; iGr++) {
244               string aGroupName = aFamilyInfo->GetGroupName(iGr);
245               MESSAGE(aGroupName);
246               aFamily->AddGroupName(aGroupName);
247             }
248             myFamilies[aFamId] = aFamily;
249         }
250
251         // Reading MED nodes to the corresponding SMDS structure
252         //------------------------------------------------------
253         PNodeInfo aNodeInfo = aMed.GetNodeInfo(aMeshInfo);
254
255         TCoordHelperPtr aCoordHelperPtr;
256         {
257           med_int aMeshDimension = aMeshInfo->GetDim();
258           bool anIsDimPresent[3] = {false, false, false};
259           for(med_int iDim = 0; iDim < aMeshDimension; iDim++){
260             string aDimName = aNodeInfo->GetCoordName(iDim);
261             if(aDimName == "x" || aDimName == "X")
262               anIsDimPresent[eX] = true;
263             else if(aDimName == "y" || aDimName == "Y")
264               anIsDimPresent[eY] = true;
265             else if(aDimName == "z" || aDimName == "Z")
266               anIsDimPresent[eZ] = true;
267           }
268           switch(aMeshDimension){
269           case 3:
270             aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aXYZGetCoord));
271             break;
272           case 2:
273             if(anIsDimPresent[eY] && anIsDimPresent[eZ])
274               aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aYZGetCoord));
275             else if(anIsDimPresent[eX] && anIsDimPresent[eZ])
276               aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aXZGetCoord));
277             else
278               aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aXYGetCoord));
279             break;
280           case 1:
281             if(anIsDimPresent[eY])
282               aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aYGetCoord));
283             else if(anIsDimPresent[eZ])
284               aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aZGetCoord));
285             else
286               aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aXGetCoord));
287             break;
288           }
289         }
290
291         med_booleen anIsNodeNum = aNodeInfo->IsElemNum();
292         med_int aNbElems = aNodeInfo->GetNbElem();
293         MESSAGE("ReadMySelf - aNodeInfo->GetNbElem() = "<<aNbElems<<"; anIsNodeNum = "<<anIsNodeNum);
294         for(med_int iElem = 0; iElem < aNbElems; iElem++){
295           double aCoords[3] = {0.0, 0.0, 0.0};
296           for(med_int iDim = 0; iDim < 3; iDim++)
297             aCoords[iDim] = aCoordHelperPtr->GetCoord(iElem,iDim);
298           const SMDS_MeshNode* aNode;
299           if(anIsNodeNum) {
300             aNode = myMesh->AddNodeWithID
301               (aCoords[0],aCoords[1],aCoords[2],aNodeInfo->GetElemNum(iElem));
302           } else {
303             aNode = myMesh->AddNode
304               (aCoords[0],aCoords[1],aCoords[2]);
305           }
306           //cout<<aNode->GetID()<<": "<<aNode->X()<<", "<<aNode->Y()<<", "<<aNode->Z()<<endl;
307
308           // Save reference to this node from its family
309           med_int aFamNum = aNodeInfo->GetFamNum(iElem);
310           if (myFamilies.find(aFamNum) != myFamilies.end())
311           {
312             myFamilies[aFamNum]->AddElement(aNode);
313             myFamilies[aFamNum]->SetType(SMDSAbs_Node);
314           }
315         }
316
317         // Reading pre information about all MED cells
318         //--------------------------------------------
319         bool takeNumbers = true;  // initially we trust the numbers from file
320         MED::TEntityInfo aEntityInfo = aMed.GetEntityInfo(aMeshInfo);
321         MED::TEntityInfo::iterator anEntityIter = aEntityInfo.begin();
322         for(; anEntityIter != aEntityInfo.end(); anEntityIter++){
323           const med_entite_maillage& anEntity = anEntityIter->first;
324           if(anEntity == MED_NOEUD) continue;
325           // Reading MED cells to the corresponding SMDS structure
326           //------------------------------------------------------
327           const MED::TGeom& aTGeom = anEntityIter->second;
328           MED::TGeom::const_iterator anTGeomIter = aTGeom.begin();
329           for(; anTGeomIter != aTGeom.end(); anTGeomIter++){
330             const med_geometrie_element& aGeom = anTGeomIter->first;
331             if(aGeom == MED_POINT1) continue;
332             PCellInfo aCellInfo = aMed.GetCellInfo(aMeshInfo,anEntity,aGeom);
333             med_booleen anIsElemNum = takeNumbers ? aCellInfo->IsElemNum() : MED_FAUX;
334             med_int aNbElems = aCellInfo->GetNbElem();
335             MESSAGE("ReadMySelf - anEntity = "<<anEntity<<"; anIsElemNum = "<<anIsElemNum);
336             MESSAGE("ReadMySelf - aGeom = "<<aGeom<<"; aNbElems = "<<aNbElems);
337
338             for(int iElem = 0; iElem < aNbElems; iElem++){
339               med_int aNbNodes = -1;
340               switch(aGeom){
341               case MED_SEG2:
342               case MED_SEG3:
343                 aNbNodes = 2;
344                 break;
345               case MED_TRIA3:
346               case MED_TRIA6:
347                 aNbNodes = 3;
348                 break;
349                 break;
350               case MED_QUAD4:
351               case MED_QUAD8:
352                 aNbNodes = 4;
353                 break;
354               case MED_TETRA4:
355               case MED_TETRA10:
356                 aNbNodes = 4;
357                 break;
358               case MED_PYRA5:
359               case MED_PYRA13:
360                 aNbNodes = 5;
361                 break;
362               case MED_PENTA6:
363               case MED_PENTA15:
364                 aNbNodes = 6;
365                 break;
366               case MED_HEXA8:
367               case MED_HEXA20:
368                 aNbNodes = 8;
369                 break;
370               }
371               vector<med_int> aNodeIds(aNbNodes);
372 #ifdef _EDF_NODE_IDS_
373               if(anIsNodeNum) {
374                 for(int i = 0; i < aNbNodes; i++){
375                   aNodeIds[i] = aNodeInfo->GetElemNum(aCellInfo->GetConn(iElem,i)-1);
376                 }
377               }else{
378                 for(int i = 0; i < aNbNodes; i++){
379                   aNodeIds[i] = aCellInfo->GetConn(iElem,i);
380                 }
381               }
382 #else
383               for(int i = 0; i < aNbNodes; i++){
384                 aNodeIds[i] = aCellInfo->GetConn(iElem,i);
385               }
386 #endif
387
388               bool isRenum = false;
389               SMDS_MeshElement* anElement = NULL;
390               med_int aFamNum = aCellInfo->GetFamNum(iElem);
391               try{
392                 switch(aGeom){
393                 case MED_SEG2:
394                 case MED_SEG3:
395                   if(anIsElemNum)
396                     anElement = myMesh->AddEdgeWithID(aNodeIds[0],
397                                                       aNodeIds[1],
398                                                       aCellInfo->GetElemNum(iElem));
399                   if (!anElement) {
400                     anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
401                                                 FindNode(myMesh,aNodeIds[1]));
402                     isRenum = anIsElemNum;
403                   }
404                   break;
405                 case MED_TRIA3:
406                 case MED_TRIA6:
407                   aNbNodes = 3;
408                   if(anIsElemNum)
409                     anElement = myMesh->AddFaceWithID(aNodeIds[0],
410                                                       aNodeIds[1],
411                                                       aNodeIds[2],
412                                                       aCellInfo->GetElemNum(iElem));
413                   if (!anElement) {
414                     anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
415                                                 FindNode(myMesh,aNodeIds[1]),
416                                                 FindNode(myMesh,aNodeIds[2]));
417                     isRenum = anIsElemNum;
418                   }
419                   break;
420                 case MED_QUAD4:
421                 case MED_QUAD8:
422                   aNbNodes = 4;
423                   // There is some differnce between SMDS and MED
424                   if(anIsElemNum)
425                     anElement = myMesh->AddFaceWithID(aNodeIds[0],
426                                                       aNodeIds[1],
427                                                       aNodeIds[2],
428                                                       aNodeIds[3],
429                                                       aCellInfo->GetElemNum(iElem));
430                   if (!anElement) {
431                     anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
432                                                 FindNode(myMesh,aNodeIds[1]),
433                                                 FindNode(myMesh,aNodeIds[2]),
434                                                 FindNode(myMesh,aNodeIds[3]));
435                     isRenum = anIsElemNum;
436                   }
437                   break;
438                 case MED_TETRA4:
439                 case MED_TETRA10:
440                   aNbNodes = 4;
441                   if(anIsElemNum)
442                     anElement = myMesh->AddVolumeWithID(aNodeIds[0],
443                                                         aNodeIds[1],
444                                                         aNodeIds[2],
445                                                         aNodeIds[3],
446                                                         aCellInfo->GetElemNum(iElem));
447                   if (!anElement) {
448                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
449                                                   FindNode(myMesh,aNodeIds[1]),
450                                                   FindNode(myMesh,aNodeIds[2]),
451                                                   FindNode(myMesh,aNodeIds[3]));
452                     isRenum = anIsElemNum;
453                   }
454                   break;
455                 case MED_PYRA5:
456                 case MED_PYRA13:
457                   aNbNodes = 5;
458                   // There is some differnce between SMDS and MED
459                   if(anIsElemNum)
460                     anElement = myMesh->AddVolumeWithID(aNodeIds[0],
461                                                         aNodeIds[1],
462                                                         aNodeIds[2],
463                                                         aNodeIds[3],
464                                                         aNodeIds[4],
465                                                         aCellInfo->GetElemNum(iElem));
466                   if (!anElement) {
467                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
468                                                   FindNode(myMesh,aNodeIds[1]),
469                                                   FindNode(myMesh,aNodeIds[2]),
470                                                   FindNode(myMesh,aNodeIds[3]),
471                                                   FindNode(myMesh,aNodeIds[4]));
472                     isRenum = anIsElemNum;
473                   }
474                   break;
475                 case MED_PENTA6:
476                 case MED_PENTA15:
477                   aNbNodes = 6;
478                   if(anIsElemNum)
479                     anElement = myMesh->AddVolumeWithID(aNodeIds[0],
480                                                         aNodeIds[1],
481                                                         aNodeIds[2],
482                                                         aNodeIds[3],
483                                                         aNodeIds[4],
484                                                         aNodeIds[5],
485                                                         aCellInfo->GetElemNum(iElem));
486                   if (!anElement) {
487                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
488                                                   FindNode(myMesh,aNodeIds[1]),
489                                                   FindNode(myMesh,aNodeIds[2]),
490                                                   FindNode(myMesh,aNodeIds[3]),
491                                                   FindNode(myMesh,aNodeIds[4]),
492                                                   FindNode(myMesh,aNodeIds[5]));
493                     isRenum = anIsElemNum;
494                   }
495                   break;
496                 case MED_HEXA8:
497                 case MED_HEXA20:
498                   aNbNodes = 8;
499                   if(anIsElemNum)
500                     anElement = myMesh->AddVolumeWithID(aNodeIds[0],
501                                                         aNodeIds[1],
502                                                         aNodeIds[2],
503                                                         aNodeIds[3],
504                                                         aNodeIds[4],
505                                                         aNodeIds[5],
506                                                         aNodeIds[6],
507                                                         aNodeIds[7],
508                                                         aCellInfo->GetElemNum(iElem));
509                   if (!anElement) {
510                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
511                                                   FindNode(myMesh,aNodeIds[1]),
512                                                   FindNode(myMesh,aNodeIds[2]),
513                                                   FindNode(myMesh,aNodeIds[3]),
514                                                   FindNode(myMesh,aNodeIds[4]),
515                                                   FindNode(myMesh,aNodeIds[5]),
516                                                   FindNode(myMesh,aNodeIds[6]),
517                                                   FindNode(myMesh,aNodeIds[7]));
518                     isRenum = anIsElemNum;
519                   }
520                   break;
521                 }
522               }catch(const std::exception& exc){
523                 //INFOS("Follow exception was cought:\n\t"<<exc.what());
524                 result = DRS_FAIL;
525               }catch(...){
526                 //INFOS("Unknown exception was cought !!!");
527                 result = DRS_FAIL;
528               }
529                 
530               if (!anElement) {
531                 result = DRS_WARN_SKIP_ELEM;
532               }
533               else {
534                 if (isRenum) {
535                   anIsElemNum = MED_FAUX;
536                   takeNumbers = false;
537                   if (result < DRS_WARN_RENUMBER)
538                     result = DRS_WARN_RENUMBER;
539                 }
540                 if (myFamilies.find(aFamNum) != myFamilies.end()) {
541                   // Save reference to this element from its family
542                   myFamilies[aFamNum]->AddElement(anElement);
543                   myFamilies[aFamNum]->SetType(anElement->GetType());
544                 }
545               }
546             }
547           }
548         }
549         break;
550       }
551     }
552   }catch(const std::exception& exc){
553     INFOS("Follow exception was cought:\n\t"<<exc.what());
554     result = DRS_FAIL;
555   }catch(...){
556     INFOS("Unknown exception was cought !!!");
557     result = DRS_FAIL;
558   }
559   MESSAGE("ReadMySelf - result status = "<<result);
560   return result;
561 }
562
563 list<string> DriverMED_R_SMESHDS_Mesh::GetMeshNames()
564 {
565   list<string> aMeshNames;
566
567   try {
568     using namespace MEDA;
569
570     MESSAGE("GetMeshNames - myFile : " << myFile);
571     TWrapper aMed (myFile);
572
573     if (med_int aNbMeshes = aMed.GetNbMeshes()) {
574       for (int iMesh = 0; iMesh < aNbMeshes; iMesh++) {
575         // Reading the MED mesh
576         //---------------------
577         PMeshInfo aMeshInfo = aMed.GetMeshInfo(iMesh);
578         aMeshNames.push_back(aMeshInfo->GetName());
579       }
580     }
581   }catch(const std::exception& exc){
582     INFOS("Follow exception was cought:\n\t"<<exc.what());
583   }catch(...){
584     INFOS("Unknown exception was cought !!!");
585   }
586
587   return aMeshNames;
588 }
589
590 list<string> DriverMED_R_SMESHDS_Mesh::GetGroupNames()
591 {
592   list<string> aResult;
593   set<string> aResGroupNames;
594
595   map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
596   for (; aFamsIter != myFamilies.end(); aFamsIter++)
597   {
598     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
599     const MED::TStringSet& aGroupNames = aFamily->GetGroupNames();
600     set<string>::iterator aGrNamesIter = aGroupNames.begin();
601     for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
602     {
603       string aName = *aGrNamesIter;
604       // Check, if this is a Group or SubMesh name
605 //if (aName.substr(0, 5) == string("Group")) {
606         if (aResGroupNames.find(aName) == aResGroupNames.end()) {
607           aResGroupNames.insert(aName);
608           aResult.push_back(aName);
609         }
610 //    }
611     }
612   }
613
614   return aResult;
615 }
616
617 void DriverMED_R_SMESHDS_Mesh::GetGroup(SMESHDS_Group* theGroup)
618 {
619   string aGroupName (theGroup->GetStoreName());
620   MESSAGE("Get Group " << aGroupName);
621
622   map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
623   for (; aFamsIter != myFamilies.end(); aFamsIter++)
624   {
625     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
626     if (aFamily->MemberOf(aGroupName))
627     {
628       const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
629       set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
630       for (; anElemsIter != anElements.end(); anElemsIter++)
631       {
632         theGroup->SMDS_MeshGroup::Add(*anElemsIter);
633       }
634     }
635   }
636 }
637
638 void DriverMED_R_SMESHDS_Mesh::GetSubMesh (SMESHDS_SubMesh* theSubMesh,
639                                            const int theId)
640 {
641   char submeshGrpName[ 30 ];
642   sprintf( submeshGrpName, "SubMesh %d", theId );
643   string aName (submeshGrpName);
644   map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
645   for (; aFamsIter != myFamilies.end(); aFamsIter++)
646   {
647     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
648     if (aFamily->MemberOf(aName))
649     {
650       const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
651       set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
652       if (aFamily->GetType() == SMDSAbs_Node)
653       {
654         for (; anElemsIter != anElements.end(); anElemsIter++)
655         {
656           const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>(*anElemsIter);
657           theSubMesh->AddNode(node);
658         }
659       }
660       else
661       {
662         for (; anElemsIter != anElements.end(); anElemsIter++)
663         {
664           theSubMesh->AddElement(*anElemsIter);
665         }
666       }
667     }
668   }
669 }
670
671 void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes ()
672 {
673   SMESHDS_Mesh* aSMESHDSMesh = dynamic_cast<SMESHDS_Mesh*>(myMesh);
674   if (!aSMESHDSMesh) {
675     EXCEPTION(runtime_error,"Can not cast SMDS_Mesh to SMESHDS_Mesh");
676   }
677   map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
678   for (; aFamsIter != myFamilies.end(); aFamsIter++)
679   {
680     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
681     MED::TStringSet aGroupNames = aFamily->GetGroupNames();
682     set<string>::iterator aGrNamesIter = aGroupNames.begin();
683     for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
684     {
685       string aName = *aGrNamesIter;
686       // Check, if this is a Group or SubMesh name
687       if (aName.substr(0, 7) == string("SubMesh"))
688       {
689         int Id = atoi(string(aName).substr(7).c_str());
690         set<const SMDS_MeshElement *> anElements = aFamily->GetElements();
691         set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
692         if (aFamily->GetType() == SMDSAbs_Node)
693         {
694           for (; anElemsIter != anElements.end(); anElemsIter++)
695           {
696             const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>(*anElemsIter);
697             aSMESHDSMesh->SetNodeInVolume(node, Id);
698 //            aSMESHDSMesh->SetNodeOnFace(node, Id);
699 //            aSMESHDSMesh->SetNodeOnEdge(node, Id);
700 //            aSMESHDSMesh->SetNodeOnVertex(node, Id);
701           }
702         }
703         else
704         {
705           for (; anElemsIter != anElements.end(); anElemsIter++)
706           {
707             aSMESHDSMesh->SetMeshElementOnShape(*anElemsIter, Id);
708           }
709         }
710       }
711     }
712   }
713 }