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