Salome HOME
Merge with OCC_development_01
[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_Utilities.hxx"
38
39 #include <stdlib.h>
40
41 #define _EDF_NODE_IDS_
42
43 using namespace MED;
44
45 void DriverMED_R_SMESHDS_Mesh::SetMeshName(string theMeshName)
46 {
47   myMeshName = theMeshName;
48 }
49
50 static const SMDS_MeshNode* 
51 FindNode(const SMDS_Mesh* theMesh, TInt theId){
52   const SMDS_MeshNode* aNode = theMesh->FindNode(theId);
53   if(aNode) return aNode;
54   EXCEPTION(runtime_error,"SMDS_Mesh::FindNode - cannot find a SMDS_MeshNode for ID = "<<theId);
55 }
56
57
58 enum ECoordName{eX, eY, eZ, eNone};
59 typedef TFloat (*TGetCoord)(MED::PNodeInfo&, TInt);
60
61 template<ECoordName TheCoordId>
62 TFloat GetCoord(MED::PNodeInfo& thePNodeInfo, TInt theElemId){
63   return thePNodeInfo->GetNodeCoord(theElemId,TheCoordId);
64 }
65
66 template<>
67 TFloat GetCoord<eNone>(MED::PNodeInfo& thePNodeInfo, TInt theElemId){
68   return 0.0;
69 }
70
71
72 static TGetCoord aXYZGetCoord[3] = {
73   &GetCoord<eX>, 
74   &GetCoord<eY>, 
75   &GetCoord<eZ>
76 };
77
78
79 static TGetCoord aXYGetCoord[3] = {
80   &GetCoord<eX>, 
81   &GetCoord<eY>, 
82   &GetCoord<eNone>
83 };
84
85 static TGetCoord aYZGetCoord[3] = {
86   &GetCoord<eNone>,
87   &GetCoord<eX>, 
88   &GetCoord<eY>
89 };
90
91 static TGetCoord aXZGetCoord[3] = {
92   &GetCoord<eX>, 
93   &GetCoord<eNone>,
94   &GetCoord<eY>
95 };
96
97
98 static TGetCoord aXGetCoord[3] = {
99   &GetCoord<eX>, 
100   &GetCoord<eNone>,
101   &GetCoord<eNone>
102 };
103
104 static TGetCoord aYGetCoord[3] = {
105   &GetCoord<eNone>,
106   &GetCoord<eX>, 
107   &GetCoord<eNone>
108 };
109
110 static TGetCoord aZGetCoord[3] = {
111   &GetCoord<eNone>,
112   &GetCoord<eNone>,
113   &GetCoord<eX>
114 };
115
116
117 class TCoordHelper{
118   MED::PNodeInfo myPNodeInfo;
119   TGetCoord* myGetCoord;
120 public:
121   TCoordHelper(const MED::PNodeInfo& thePNodeInfo,
122                TGetCoord* theGetCoord):
123     myPNodeInfo(thePNodeInfo),
124     myGetCoord(theGetCoord)
125   {}
126   virtual ~TCoordHelper(){}
127   TFloat GetCoord(TInt theElemId, TInt theCoodId){
128     return (*myGetCoord[theCoodId])(myPNodeInfo,theElemId);
129   }
130 };
131 typedef boost::shared_ptr<TCoordHelper> TCoordHelperPtr;
132
133
134 Driver_Mesh::Status DriverMED_R_SMESHDS_Mesh::Perform()
135 {
136   Status aResult = DRS_FAIL;
137   try{
138     myFamilies.clear();
139     MESSAGE("Perform - myFile : "<<myFile);
140     PWrapper aMed = CrWrapper(myFile);
141
142     aResult = DRS_EMPTY;
143     if(TInt aNbMeshes = aMed->GetNbMeshes()){
144       for(int iMesh = 0; iMesh < aNbMeshes; iMesh++){
145         // Reading the MED mesh
146         //---------------------
147         PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
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         //TInt aMeshDim = aMeshInfo->GetDim();
160         
161         // Reading MED families to the temporary structure
162         //------------------------------------------------
163         TInt aNbFams = aMed->GetNbFamilies(aMeshInfo);
164         MESSAGE("Read " << aNbFams << " families");
165         for (TInt iFam = 0; iFam < aNbFams; iFam++) {
166           PFamilyInfo aFamilyInfo = aMed->GetPFamilyInfo(aMeshInfo, iFam+1);
167           TInt aFamId = aFamilyInfo->GetId();
168           MESSAGE("Family " << aFamId << " :");
169
170             DriverMED_FamilyPtr aFamily (new DriverMED_Family);
171
172             TInt aNbGrp = aFamilyInfo->GetNbGroup();
173             MESSAGE("belong to " << aNbGrp << " groups");
174             for (TInt 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->GetPNodeInfo(aMeshInfo);
185
186         TCoordHelperPtr aCoordHelperPtr;
187         {
188           TInt aMeshDimension = aMeshInfo->GetDim();
189           bool anIsDimPresent[3] = {false, false, false};
190           for(TInt 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         EBooleen anIsNodeNum = aNodeInfo->IsElemNum();
223         TInt aNbElems = aNodeInfo->GetNbElem();
224         MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbElems<<"; anIsNodeNum = "<<anIsNodeNum);
225         for(TInt iElem = 0; iElem < aNbElems; iElem++){
226           double aCoords[3] = {0.0, 0.0, 0.0};
227           for(TInt 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           TInt 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 EEntiteMaillage& anEntity = anEntityIter->first;
255           if(anEntity == eNOEUD) 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 EGeometrieElement& aGeom = anTGeomIter->first;
262             if(aGeom == ePOINT1) continue;
263             PCellInfo aCellInfo = aMed->GetPCellInfo(aMeshInfo,anEntity,aGeom);
264             EBooleen anIsElemNum = takeNumbers ? aCellInfo->IsElemNum() : eFAUX;
265             TInt 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               TInt aNbNodes = -1;
271               switch(aGeom){
272               case eSEG2:
273               case eSEG3:
274                 aNbNodes = 2;
275                 break;
276               case eTRIA3:
277               case eTRIA6:
278                 aNbNodes = 3;
279                 break;
280                 break;
281               case eQUAD4:
282               case eQUAD8:
283                 aNbNodes = 4;
284                 break;
285               case eTETRA4:
286               case eTETRA10:
287                 aNbNodes = 4;
288                 break;
289               case ePYRA5:
290               case ePYRA13:
291                 aNbNodes = 5;
292                 break;
293               case ePENTA6:
294               case ePENTA15:
295                 aNbNodes = 6;
296                 break;
297               case eHEXA8:
298               case eHEXA20:
299                 aNbNodes = 8;
300                 break;
301               }
302               vector<TInt> 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               TInt aFamNum = aCellInfo->GetFamNum(iElem);
322               try{
323                 switch(aGeom){
324                 case eSEG2:
325                 case eSEG3:
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 eTRIA3:
337                 case eTRIA6:
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 eQUAD4:
352                 case eQUAD8:
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 eTETRA4:
370                 case eTETRA10:
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 ePYRA5:
387                 case ePYRA13:
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 ePENTA6:
407                 case ePENTA15:
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 eHEXA8:
428                 case eHEXA20:
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 = eFAUX;
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     MESSAGE("GetMeshNames - myFile : " << myFile);
500     theStatus = DRS_OK;
501     PWrapper aMed = CrWrapper(myFile);
502
503     if (TInt aNbMeshes = aMed->GetNbMeshes()) {
504       for (int iMesh = 0; iMesh < aNbMeshes; iMesh++) {
505         // Reading the MED mesh
506         //---------------------
507         PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
508         aMeshNames.push_back(aMeshInfo->GetName());
509       }
510     }
511   }catch(const std::exception& exc){
512     INFOS("Follow exception was cought:\n\t"<<exc.what());
513     theStatus = DRS_FAIL;
514   }catch(...){
515     INFOS("Unknown exception was cought !!!");
516     theStatus = DRS_FAIL;
517   }
518
519   return aMeshNames;
520 }
521
522 list<string> DriverMED_R_SMESHDS_Mesh::GetGroupNames()
523 {
524   list<string> aResult;
525   set<string> aResGroupNames;
526
527   map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
528   for (; aFamsIter != myFamilies.end(); aFamsIter++)
529   {
530     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
531     const MED::TStringSet& aGroupNames = aFamily->GetGroupNames();
532     set<string>::iterator aGrNamesIter = aGroupNames.begin();
533     for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
534     {
535       string aName = *aGrNamesIter;
536       // Check, if this is a Group or SubMesh name
537 //if (aName.substr(0, 5) == string("Group")) {
538         if (aResGroupNames.find(aName) == aResGroupNames.end()) {
539           aResGroupNames.insert(aName);
540           aResult.push_back(aName);
541         }
542 //    }
543     }
544   }
545
546   return aResult;
547 }
548
549 void DriverMED_R_SMESHDS_Mesh::GetGroup(SMESHDS_Group* theGroup)
550 {
551   string aGroupName (theGroup->GetStoreName());
552   MESSAGE("Get Group " << aGroupName);
553
554   map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
555   for (; aFamsIter != myFamilies.end(); aFamsIter++)
556   {
557     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
558     if (aFamily->MemberOf(aGroupName))
559     {
560       const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
561       set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
562       const SMDS_MeshElement * element = 0;
563       for (; anElemsIter != anElements.end(); anElemsIter++)
564       {
565         element = *anElemsIter;
566         theGroup->SMDSGroup().Add(element);
567       }
568       if ( element )
569         theGroup->SetType( element->GetType() );
570     }
571   }
572 }
573
574 void DriverMED_R_SMESHDS_Mesh::GetSubMesh (SMESHDS_SubMesh* theSubMesh,
575                                            const int theId)
576 {
577   char submeshGrpName[ 30 ];
578   sprintf( submeshGrpName, "SubMesh %d", theId );
579   string aName (submeshGrpName);
580   map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
581   for (; aFamsIter != myFamilies.end(); aFamsIter++)
582   {
583     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
584     if (aFamily->MemberOf(aName))
585     {
586       const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
587       set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
588       if (aFamily->GetType() == SMDSAbs_Node)
589       {
590         for (; anElemsIter != anElements.end(); anElemsIter++)
591         {
592           const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>(*anElemsIter);
593           theSubMesh->AddNode(node);
594         }
595       }
596       else
597       {
598         for (; anElemsIter != anElements.end(); anElemsIter++)
599         {
600           theSubMesh->AddElement(*anElemsIter);
601         }
602       }
603     }
604   }
605 }
606
607 void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes ()
608 {
609   map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
610   for (; aFamsIter != myFamilies.end(); aFamsIter++)
611   {
612     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
613     MED::TStringSet aGroupNames = aFamily->GetGroupNames();
614     set<string>::iterator aGrNamesIter = aGroupNames.begin();
615     for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
616     {
617       string aName = *aGrNamesIter;
618       // Check, if this is a Group or SubMesh name
619       if (aName.substr(0, 7) == string("SubMesh"))
620       {
621         int Id = atoi(string(aName).substr(7).c_str());
622         set<const SMDS_MeshElement *> anElements = aFamily->GetElements();
623         set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
624         if (aFamily->GetType() == SMDSAbs_Node)
625         {
626           for (; anElemsIter != anElements.end(); anElemsIter++)
627           {
628             SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>
629               ( static_cast<const SMDS_MeshNode*>( *anElemsIter ));
630             // find out a shape type
631             TopoDS_Shape aShape = myMesh->IndexToShape( Id );
632             int aShapeType = ( aShape.IsNull() ? -1 : aShape.ShapeType() );
633             switch ( aShapeType ) {
634             case TopAbs_FACE:
635               myMesh->SetNodeOnFace(node, Id); break;
636             case TopAbs_EDGE:
637               myMesh->SetNodeOnEdge(node, Id); break;
638             case TopAbs_VERTEX:
639               myMesh->SetNodeOnVertex(node, Id); break;
640             default:
641               myMesh->SetNodeInVolume(node, Id);
642             }
643           }
644         }
645         else
646         {
647           for (; anElemsIter != anElements.end(); anElemsIter++)
648           {
649             myMesh->SetMeshElementOnShape(*anElemsIter, Id);
650           }
651         }
652       }
653     }
654   }
655 }