]> SALOME platform Git repositories - modules/visu.git/blob - src/CONVERTOR/VISU_MedConvertor.cxx
Salome HOME
Fix on [Bug PAL8053] REGRESSION: it is impossible to import ".../KERNEL/examples...
[modules/visu.git] / src / CONVERTOR / VISU_MedConvertor.cxx
1 //  VISU OBJECT : interactive object for VISU entities implementation
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 //  File   : VISU_MedConvertor.cxx
24 //  Author : Alexey PETROV
25 //  Module : VISU
26
27
28 #include "VISU_MedConvertor.hxx"
29 #include "VISU_Convertor.hxx"
30 #include "VISU_ConvertorUtils.hxx"
31
32 #include "MED_Factory.hxx"
33 #include "MED_Algorithm.hxx"
34 #include "MED_Utilities.hxx"
35
36 #include <vtkCellType.h>
37
38 #define _EDF_NODE_IDS_
39
40 using namespace std;
41 using namespace MED;
42 using namespace VISU;
43
44 #ifdef _DEBUG_
45 static int MYDEBUG = 0;
46 #else
47 static int MYDEBUG = 0;
48 #endif
49
50
51 namespace{
52
53   using namespace MED;
54   using namespace VISU;
55   
56   int MEDGeom2NbNodes(MED::EGeometrieElement theMEDGeomType)
57   { 
58     return theMEDGeomType % 100;
59   }
60
61   int MEDGeomToVTK(MED::EGeometrieElement theMEDGeomType)
62   { 
63     switch(theMEDGeomType){
64     case ePOINT1: return VTK_VERTEX;
65     case eSEG2: return VTK_LINE;
66     case eSEG3: return VTK_LINE;
67     case eTRIA3: return VTK_TRIANGLE;
68     case eTRIA6: return VTK_TRIANGLE;
69     case eQUAD4: return VTK_QUAD;
70     case eQUAD8: return VTK_QUAD;
71     case eTETRA4: return VTK_TETRA;
72     case eTETRA10: return VTK_TETRA;
73     case eHEXA8: return VTK_HEXAHEDRON;
74     case eHEXA20: return VTK_HEXAHEDRON;
75     case ePENTA6: return VTK_WEDGE;
76     case ePENTA15: return VTK_WEDGE;
77     case ePYRA5: return VTK_PYRAMID;
78     case ePYRA13: return VTK_PYRAMID;
79     case ePOLYGONE: return VTK_POLYGON;
80 //     case ePOLYEDRE: return VTK_POLYEDRE;
81     }
82     return -1;
83   }
84
85   int VTKGeom2NbNodes(int theVTKGeomType)
86   { 
87     switch(theVTKGeomType){
88     case VTK_VERTEX: return 1;
89     case VTK_LINE: return 2;
90     case VTK_TRIANGLE: return 3;
91     case VTK_QUAD: return 4;
92     case VTK_TETRA: return 4;
93     case VTK_HEXAHEDRON: return 8;
94     case VTK_WEDGE: return 6;
95     case VTK_PYRAMID: return 5;
96     }
97     return -1;
98   }
99
100   MED::EGeometrieElement VTKGeomToMED(int theVTKGeomType)
101   { 
102     switch(theVTKGeomType){
103     case VTK_VERTEX: return ePOINT1;
104     case VTK_LINE: return eSEG2;
105     case VTK_TRIANGLE: return eTRIA3;
106     case VTK_QUAD: return eQUAD4;
107     case VTK_TETRA: return eTETRA4;
108     case VTK_HEXAHEDRON: return eHEXA8;
109     case VTK_WEDGE: return ePENTA6;
110     case VTK_PYRAMID: return ePYRA5;
111     case VTK_POLYGON: return ePOLYGONE;
112     }
113     return EGeometrieElement(-1);
114   }
115
116   TEntity MEDEntityToVTK(MED::EEntiteMaillage theMEDEntity)
117   {
118     switch(theMEDEntity){
119     case eNOEUD: return NODE_ENTITY;
120     case eARETE: return EDGE_ENTITY;
121     case eFACE: return FACE_ENTITY;
122     case eMAILLE: return CELL_ENTITY;
123     }
124     return TEntity(-1);
125   }
126
127   MED::EEntiteMaillage VTKEntityToMED(TEntity theVTKEntity)
128   {
129     switch(theVTKEntity){
130     case NODE_ENTITY: return eNOEUD;
131     case EDGE_ENTITY: return eARETE;
132     case FACE_ENTITY: return eFACE;
133     case CELL_ENTITY: return eMAILLE;
134     }
135     return MED::EEntiteMaillage(-1);
136   }
137
138 }
139
140 extern "C"
141 VISU_Convertor* CreateConvertor(const string& theFileName)
142 {
143   return new VISU_MedConvertor(theFileName);
144 }
145
146 VISU_MedConvertor::VISU_MedConvertor(const string& theFileName)  {
147   myFileInfo.setFile(QString(theFileName.c_str()));
148   myName = myFileInfo.baseName().latin1();
149 }
150
151 VISU_Convertor* VISU_MedConvertor::Build()  {
152   MED::PWrapper aMed = MED::CrWrapper(myFileInfo.absFilePath().latin1());
153   MED::TInt aNbMeshes = aMed->GetNbMeshes();
154
155   MSG(MYDEBUG,"VISU_MedConvertor::Build()");
156   INITMSG(MYDEBUG,"GetNbMeshes() = "<<aNbMeshes<<"\n");
157
158   for(MED::TInt iMesh = 1; iMesh <= aNbMeshes; iMesh++){
159     try{
160       MED::PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh);
161       
162       MED::PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo);
163       
164       MED::TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo);
165       
166       MED::TElemGroup anElemGroup = GetElemsByEntity(aMed,aMeshInfo,aEntityInfo);
167
168       MED::TInt aDim = aMeshInfo->GetDim();
169       std::string aMeshName = aMeshInfo->GetName();
170
171       VISU::PMEDMesh aMesh = myMeshMap[aMeshName](new VISU::TMEDMesh());
172       aMesh->myDim = aDim;
173       aMesh->myName = aMeshName;
174       aMesh->myNbPoints = aNodeInfo->GetNbElem();
175       aMesh->myMeshInfo = aMeshInfo;
176       aMesh->myEntityInfo = aEntityInfo;
177
178       INITMSG(MYDEBUG,"aMeshName = '"<<aMeshName<<
179               "'; myNbPoints = "<<aMesh->myNbPoints<<
180               "; aDim = "<<aDim<<"\n");
181       
182       BEGMSG(MYDEBUG,"aEntityInfo.size() = "<<aEntityInfo.size()<<"\n");
183
184       typedef std::map<TInt,TInt> TFamilyCounterMap;
185       TFamilyCounterMap aFamilyNbCellsCounterMap, aFamilyCellsSizeCounterMap;
186       TFamilyCounterMap aFamilyNbPolygonesCounterMap, aFamilyPolygonesSizeCounterMap;
187
188       VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
189       MED::TElemGroup::const_iterator anElemGroupIter = anElemGroup.begin();
190       for(; anElemGroupIter != anElemGroup.end(); anElemGroupIter++){
191         const MED::EEntiteMaillage& aMEntity = anElemGroupIter->first;
192         const MED::TElemMap& anElemMap = anElemGroupIter->second;
193
194         VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
195         VISU::PMEDMeshOnEntity aMeshOnEntity = 
196           aMeshOnEntityMap[aVEntity](new VISU::TMEDMeshOnEntity());
197         aMeshOnEntity->myEntity = aVEntity;
198         aMeshOnEntity->myMeshName = aMeshName;
199         aMeshOnEntity->myGeom = aEntityInfo[aMEntity];
200
201         INITMSG(MYDEBUG,"aMEntity = "<<aMEntity<<"; aVEntity = "<<aVEntity<<"\n");
202
203         if(aMEntity == MED::eNOEUD){
204           aMeshOnEntity->myNbCells = aMesh->myNbPoints;
205           aMeshOnEntity->myCellsSize = 2*aMesh->myNbPoints;
206           
207           for(MED::TInt iElem = 0; iElem < aMesh->myNbPoints; iElem++){
208             MED::TInt aFamId = aNodeInfo->GetFamNum(iElem);
209             if(aFamId != 0){
210               aFamilyNbCellsCounterMap[aFamId] += 1;
211               aFamilyCellsSizeCounterMap[aFamId] += 2;
212             }
213           }
214
215           INITMSG(MYDEBUG,"myNbCells = "<<aMeshOnEntity->myNbCells<<
216                   "; myCellsSize = "<<aMeshOnEntity->myCellsSize<<"\n");;
217           
218         }else{
219           aMeshOnEntity->myNbCells = 0;
220           aMeshOnEntity->myCellsSize = 0;
221           MED::TElemMap::const_iterator anElemMapIter = anElemMap.begin();
222           for(; anElemMapIter != anElemMap.end(); anElemMapIter++){
223             const MED::EGeometrieElement& aGeom = anElemMapIter->first;
224             MED::PElemInfo anElemInfo = anElemMapIter->second;
225             
226             switch(aGeom){
227             case MED::ePOLYGONE: {
228               MED::PPolygoneInfo aPolygoneInfo = 
229                 aMed->GetPPolygoneInfo(aMeshInfo,aMEntity,MED::ePOLYGONE);
230               MED::TInt aNbElem = aPolygoneInfo->GetNbElem();
231               MED::TElemNum aConn  = aPolygoneInfo->GetConnectivite();
232               MED::TElemNum aIndex = aPolygoneInfo->GetIndex();
233               MED::TInt aNbConn  = aConn.size();
234             
235               aMeshOnEntity->myNbCells += aNbElem;
236               
237               for (int ii = 0; ii<aNbElem ; ii++){
238                 int aNbConnii = aPolygoneInfo->GetNbConn(ii);
239                 aMeshOnEntity->myCellsSize += aNbConnii;
240               }
241
242               INITMSG(MYDEBUG,"aGeom = "<<aGeom<<"; aNbElem = "<<aNbElem<<
243                       "; myNbPolygones = "<<aNbElem<<
244                       "; nbConn= "<<aNbConn<<"\n");
245               
246               for(MED::TInt iElem = 0; iElem < aNbElem; iElem++){
247                 MED::TInt aFamId = aPolygoneInfo->GetFamNum(iElem);
248                 if(aFamId != 0){
249                   aFamilyNbCellsCounterMap[aFamId] += 1;
250                   aFamilyCellsSizeCounterMap[aFamId] += aPolygoneInfo->GetNbConn(iElem) + 1;
251                 }
252               }
253               break;
254             }
255             default: {
256               int aVNbNodes = VTKGeom2NbNodes(MEDGeomToVTK(aGeom));
257               MED::PCellInfo aCellInfo = aMed->GetPCellInfo(aMeshInfo,aMEntity,aGeom);
258               MED::TInt aNbElem = aCellInfo->GetNbElem();
259               aMeshOnEntity->myNbCells += aNbElem;
260               aMeshOnEntity->myCellsSize += aNbElem*(aVNbNodes+1);
261               INITMSG(MYDEBUG,"aGeom = "<<aGeom<<"; aNbElem = "<<aNbElem<<
262                       "; myNbCells = "<<aMeshOnEntity->myNbCells<<
263                       "; myCellsSize = "<<aMeshOnEntity->myCellsSize<<"\n");
264             
265               for(MED::TInt iElem = 0; iElem < aNbElem; iElem++){
266                 MED::TInt aFamId = aCellInfo->GetFamNum(iElem);
267                 if(aFamId != 0){
268                   aFamilyNbCellsCounterMap[aFamId] += 1;
269                   aFamilyCellsSizeCounterMap[aFamId] += aVNbNodes + 1;
270                 }
271               }
272             }}
273           }
274         }
275       }
276
277       BEGMSG(MYDEBUG,"TFamilyByEntity:\n");
278
279       MED::TFamilyGroup aFamilyGroup = GetFamilies(aMed,aMeshInfo);
280
281       MED::TGroupInfo aGroupInfo = GetFamiliesByGroup(aFamilyGroup);
282
283       MED::TFamilyByEntity aFamilyByEntity = GetFamiliesByEntity(aMed,anElemGroup,aFamilyGroup);
284
285       MED::TFamilyByEntity::const_iterator aFamilyByEntityIter = aFamilyByEntity.begin();
286       for(; aFamilyByEntityIter != aFamilyByEntity.end(); aFamilyByEntityIter++){
287         const MED::EEntiteMaillage& aMEntity = aFamilyByEntityIter->first;
288         const MED::TFamilyGroup& aFamilyGroup = aFamilyByEntityIter->second;
289         
290         VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
291         VISU::PMEDMeshOnEntity aMeshOnEntity = aMesh->myMeshOnEntityMap[aVEntity];
292         VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
293       
294         if(aFamilyGroup.empty())
295           continue;
296         
297         INITMSG(MYDEBUG,"aMEntity = "<<aMEntity<<"; aVEntity = "<<aVEntity<<"\n");
298         MED::TFamilyGroup::const_iterator aFamilyGroupIter = aFamilyGroup.begin();
299         for(; aFamilyGroupIter != aFamilyGroup.end(); aFamilyGroupIter++){
300           MED::PFamilyInfo aFamilyInfo = *aFamilyGroupIter;
301           if(aFamilyInfo->GetId() == 0) 
302             continue;
303           
304           std::string aFamilyName = aFamilyInfo->GetName();
305           VISU::PMEDFamily aFamily = aFamilyMap[aFamilyName](new TMEDFamily());
306           
307           aFamily->myId = aFamilyInfo->GetId();
308           aFamily->myName = aFamilyInfo->GetName();
309           aFamily->myEntity = aVEntity;
310           aFamily->myNbCells = aFamilyNbCellsCounterMap[aFamily->myId];
311           aFamily->myCellsSize = aFamilyCellsSizeCounterMap[aFamily->myId];
312           
313           INITMSG(MYDEBUG,"aFamilyName = '"<<aFamily->myName<<
314                   "'; myId = "<<aFamily->myId<<"; "<<
315                   "; aNbGroup = "<<aFamilyInfo->GetNbGroup()<<
316                   "; myEntity = "<<aFamily->myEntity<<
317                   "; myNbCells = "<<aFamily->myNbCells<<
318                   "; myCellsSize = "<<aFamily->myCellsSize<<"\n");
319           
320           VISU::TBindGroups& aBindGroups = aFamily->myGroups;
321           MED::TInt aNbGroup = aFamilyInfo->GetNbGroup();
322           for(MED::TInt i = 0; i < aNbGroup; i++){
323             std::string aGroupName = aFamilyInfo->GetGroupName(i);
324             aBindGroups.insert(aGroupName);
325             INITMSG(MYDEBUG,"aGroupName = '"<<aGroupName<<"'\n");
326           }
327         }
328       }
329       
330       BEGMSG(MYDEBUG,"VISU::TGroup:\n");
331
332       VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
333       MED::TGroupInfo::const_iterator aGroupInfoIter = aGroupInfo.begin();
334       for(; aGroupInfoIter != aGroupInfo.end(); aGroupInfoIter++){
335         const std::string& aGroupName = aGroupInfoIter->first;
336         const MED::TFamilyGroup& aFamilyGroup = aGroupInfoIter->second;
337         VISU::PMEDGroup aGroup(new TMEDGroup());
338         aGroup->myName = aGroupName;
339         aGroup->myMeshName = aMeshName;
340         
341         INITMSG(MYDEBUG,"aGroup->myName = '"<<aGroup->myName<<"'\n");
342         
343         MED::TFamilyGroup::const_iterator aFamilyIter = aFamilyGroup.begin();
344         for(; aFamilyIter != aFamilyGroup.end(); aFamilyIter++){
345           MED::PFamilyInfo aFamilyInfo = *aFamilyIter;
346           std::string aFamilyName = aFamilyInfo->GetName();
347           
348           VISU::TEntity aVEntity = TEntity(-1);
349           VISU::PFamily aFamily;
350           
351           // Find aVisuEntity
352           const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
353           VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityIter = aMeshOnEntityMap.begin();
354           for(; aMeshOnEntityIter != aMeshOnEntityMap.end(); aMeshOnEntityIter++){
355             const VISU::PMeshOnEntity& aMeshOnEntity = aMeshOnEntityIter->second;
356             const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
357             VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
358             for (; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
359               const std::string& aName = aFamilyMapIter->first;
360               aFamily = aFamilyMapIter->second;
361               if(aName == aFamilyName){
362                 aVEntity = aFamily->myEntity;
363                 goto exit_lable;
364               }
365             }
366           }
367         exit_lable:
368           if(aFamily && aVEntity >= 0){
369             aGroup->myFamilyAndEntitySet.insert(TFamilyAndEntity(aFamilyName,aVEntity));
370             INITMSG(MYDEBUG,"aFamilyName = '"<<aFamilyName<<"'; '"<<aFamily->myName<<"'; aVEntity = "<<aVEntity<<"\n");
371             
372             aGroup->myNbCells += aFamily->myNbCells;
373             aGroup->myCellsSize += aFamily->myCellsSize;
374           }
375         }
376         if(!aGroup->myFamilyAndEntitySet.empty() && aGroup->myNbCells > 0){
377           BEGMSG(MYDEBUG,"myNbCells = "<<aGroup->myNbCells<<
378                  "; myCellsSize = "<<aGroup->myCellsSize<<"\n\n");
379           aGroupMap.insert(VISU::TGroupMap::value_type(aGroupName,aGroup));
380         }
381       }
382       
383       MED::TInt aNbFields = aMed->GetNbFields(); 
384       BEGMSG(MYDEBUG,"VISU::TField aNbFields = "<<aNbFields<<"\n");
385       for(MED::TInt iField = 1; iField <= aNbFields; iField++){
386         MED::PFieldInfo aFieldInfo = aMed->GetPFieldInfo(aMeshInfo,iField);
387         MED::TInt aNbComp = aFieldInfo->GetNbComp();
388         std::string aFieldName = aFieldInfo->GetName();
389         
390         MED::TGeom aTGeom;
391         MED::EEntiteMaillage aMEntity;
392         MED::TInt aNbTimeStamps = aMed->GetNbTimeStamps(aFieldInfo,aEntityInfo,aMEntity,aTGeom);
393         VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
394         VISU::PMeshOnEntity aMeshOnEntity = aMesh->myMeshOnEntityMap[aVEntity];
395         VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
396         VISU::PMEDField aField = aFieldMap[aFieldName](new TMEDField());
397         aField->myId = iField;
398         aField->myNbComp = aNbComp;
399         aField->myEntity = aVEntity;
400         aField->myName = aFieldName;
401         aField->myMeshName = aMeshName;
402         aField->myDataSize = aMeshOnEntity->myNbCells * aNbComp;
403         aField->myCompNames.resize(aNbComp);
404         aField->myUnitNames.resize(aNbComp);
405
406         INITMSG(MYDEBUG,"myName = '"<<aField->myName<<
407                 "'; myId = "<<aField->myId<<
408                 "; myEntity = "<<aField->myEntity<<
409                 "; myDataSize = "<<aField->myDataSize<<
410                 "; myNbComp = "<<aField->myNbComp<<"\n");
411         
412         for(MED::TInt iComp = 0; iComp < aNbComp; iComp++){
413           aField->myCompNames[iComp] = aFieldInfo->GetCompName(iComp);
414           aField->myUnitNames[iComp] = aFieldInfo->GetUnitName(iComp);
415         }
416         
417         for(MED::TInt iTimeStamp = 1; iTimeStamp <= aNbTimeStamps; iTimeStamp++){
418           MED::TErr anErr;
419           MED::PTimeStampInfo aTimeStamp = aMed->GetPTimeStampInfo(aFieldInfo,
420                                                                    aMEntity,
421                                                                    aTGeom,
422                                                                    iTimeStamp,
423                                                                    &anErr);
424           if(anErr < 0)
425             continue;
426           
427           MED::PTimeStampVal aTimeStampVal = aMed->GetPTimeStampVal(aTimeStamp,&anErr);
428           
429           MED::TFloat aDt = aTimeStamp->GetDt();
430           std::string anUnitDt = aTimeStamp->GetUnitDt();
431           VISU::TValField& aValField = aField->myValField;
432           VISU::PMEDValForTime aValForTime = aValField[iTimeStamp](new TMEDValForTime());
433           aValForTime->myId = iTimeStamp;
434           aValForTime->myFieldName = aField->myName;
435           aValForTime->myEntity = aField->myEntity;
436           aValForTime->myMeshName = aField->myMeshName;
437           aValForTime->myNbComp = aField->myNbComp;
438           aValForTime->myTime = VISU::TTime(aDt,anUnitDt);
439           INITMSG(MYDEBUG,"aDt = "<<aDt<<", "<<anUnitDt<<"\n");
440         }
441       }
442     }catch (std::exception& exc){
443       MSG(MYDEBUG,"Follow exception was occured :\n"<<exc.what());
444     }catch(...){
445       EXCEPTION(runtime_error,"Unknown exception !!!");
446     }
447   }
448   return this; 
449 }
450
451 int VISU_MedConvertor::LoadMeshOnEntity(VISU::PMeshOnEntityImpl theMeshOnEntity, 
452                                         const string& theFamilyName)
453 {
454   MED::PWrapper aMed = MED::CrWrapper(myFileInfo.absFilePath().latin1());
455   const std::string& aMeshName = theMeshOnEntity->myMeshName;
456   const VISU::TEntity& anEntity = theMeshOnEntity->myEntity;
457   VISU::PMeshImpl aMesh = myMeshMap[aMeshName];
458   int isPointsUpdated;
459   if(anEntity == VISU::NODE_ENTITY) 
460     isPointsUpdated = LoadPoints(aMed,aMesh,theFamilyName);
461   else
462     isPointsUpdated = LoadPoints(aMed,aMesh);
463   int isCellsOnEntityUpdated = LoadCellsOnEntity(aMed,aMesh,theMeshOnEntity,theFamilyName);
464
465   return (isPointsUpdated || isCellsOnEntityUpdated);
466 }
467
468 int VISU_MedConvertor::LoadMeshOnGroup(VISU::PMeshImpl theMesh, 
469                                        const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet)
470 {
471   MED::PWrapper aMed = MED::CrWrapper(myFileInfo.absFilePath().latin1());
472   int isPointsUpdated = 0, isCellsOnEntityUpdated = 0;
473   VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = theFamilyAndEntitySet.begin();
474   for(; aFamilyAndEntitySetIter != theFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){
475     const std::string& aFamilyName = aFamilyAndEntitySetIter->first;
476     const VISU::TEntity& anEntity = aFamilyAndEntitySetIter->second;
477     const VISU::PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[anEntity];
478     if(anEntity == VISU::NODE_ENTITY){
479       isPointsUpdated += LoadPoints(aMed,theMesh,aFamilyName);
480       isCellsOnEntityUpdated += LoadCellsOnEntity(aMed,theMesh,aMeshOnEntity);
481     }else{
482       isPointsUpdated += LoadPoints(aMed,theMesh);
483       isCellsOnEntityUpdated += LoadCellsOnEntity(aMed,theMesh,aMeshOnEntity,aFamilyName);
484     }
485   }
486
487   return (isPointsUpdated || isCellsOnEntityUpdated);
488 }
489
490 int VISU_MedConvertor::LoadFieldOnMesh(VISU::PMeshImpl theMesh, 
491                                        VISU::PMeshOnEntityImpl theMeshOnEntity, 
492                                        VISU::PFieldImpl theField, 
493                                        VISU::PValForTimeImpl theValForTime)
494 {
495   MED::PWrapper aMed = MED::CrWrapper(myFileInfo.absFilePath().latin1());
496   int isPointsUpdated = LoadPoints(aMed,theMesh);
497   int isCellsOnEntityUpdated = LoadCellsOnEntity(aMed,theMesh,theMeshOnEntity);
498   int isFieldUpdated = LoadField(aMed,theMesh,theMeshOnEntity,theField,theValForTime);
499   
500   return (isPointsUpdated || isCellsOnEntityUpdated || isFieldUpdated);
501 }
502
503
504 int 
505 VISU_MedConvertor::LoadPoints(const MED::PWrapper& theMed,
506                               VISU::PMEDMesh theMesh, 
507                               const string& theFamilyName) 
508 {
509   try{
510     //Check on existing family
511     VISU::PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[VISU::NODE_ENTITY];
512     aMeshOnEntity->myEntity = VISU::NODE_ENTITY;
513     aMeshOnEntity->myMeshName = theMesh->myName;
514     VISU::PFamilyImpl aFamily = GetFamily(aMeshOnEntity,theFamilyName);
515     //Check on loading already done
516     bool isPointsLoaded = !theMesh->myPointsCoord.empty();
517     if(isPointsLoaded) 
518       if(!aFamily) 
519         return 0;
520       else if(!aFamily->mySubMesh.empty()) 
521         return 0;
522
523     INITMSG(MYDEBUG,"LoadPoints - isPointsLoaded = "<<isPointsLoaded<<"; theFamilyName = '"<<theFamilyName<<"'\n");
524     
525     //Main part of code
526     MED::PNodeInfo aNodeInfo = theMed->GetPNodeInfo(theMesh->myMeshInfo);
527     MED::TInt aNbElem = aNodeInfo->GetNbElem();
528
529     if(!isPointsLoaded){
530       VISU::TMeshImpl::TPointsDim&  aPointsDim = theMesh->myPointsDim;
531       aPointsDim.resize(theMesh->myDim);
532       for(int iDim = 0; iDim < theMesh->myDim; iDim++)
533         aPointsDim[iDim] = aNodeInfo->GetCoordName(iDim);
534       
535       VISU::TMeshImpl::TPointsCoord& aPointsCoord = theMesh->myPointsCoord;
536       aPointsCoord.resize(aNbElem*theMesh->myDim);
537       for(int iElem = 0; iElem < aNbElem; iElem++) 
538         for(int iDim = 0, iElem2Dim = iElem*theMesh->myDim; iDim < theMesh->myDim; iDim++, iElem2Dim++)
539           aPointsCoord[iElem2Dim] = aNodeInfo->GetNodeCoord(iElem,iDim);
540       
541       VISU::TMeshOnEntityImpl::TConnForCellType& aConnForCellType = aMeshOnEntity->myCellsConn[VTK_VERTEX];
542       aConnForCellType.resize(aNbElem);
543       for (int iElem = 0; iElem < aNbElem; iElem++)
544         aConnForCellType[iElem] = TMeshOnEntityImpl::TConnect(1,iElem);
545     }
546     if(aFamily && aNbElem > 0){
547       VISU::TFamilyImpl::TSubMeshOnCellType& aSubMeshOnCellType = aFamily->mySubMesh[VTK_VERTEX];
548       for (int iElem = 0; iElem < aNbElem; iElem++) 
549         if(aNodeInfo->GetFamNum(iElem) == aFamily->myId)
550           aSubMeshOnCellType.insert(iElem);
551     }
552     return 1;
553   }catch(std::exception& exc){
554     MSG(MYDEBUG,"Follow exception was occured :\n"<<exc.what());
555     theMesh->myPointsCoord.clear();
556     throw;
557   }catch(...){
558     theMesh->myPointsCoord.clear();
559     EXCEPTION(runtime_error,"Unknown exception !!!");
560   }
561   return 0;
562 }
563
564
565 int 
566 VISU_MedConvertor::LoadCellsOnEntity(const MED::PWrapper& theMed, 
567                                      VISU::PMEDMesh theMesh,
568                                      VISU::PMEDMeshOnEntity theMeshOnEntity,
569                                      const string& theFamilyName)
570 {
571   try{
572     //Check on existing family
573     VISU::PFamilyImpl aFamily = GetFamily(theMeshOnEntity,theFamilyName);
574     //Check on loading already done
575     bool isCellsLoaded = !theMeshOnEntity->myCellsConn.empty();
576     if(isCellsLoaded)
577       if(!aFamily) 
578         return 0;
579       else if(!aFamily->mySubMesh.empty()) 
580         return 0;
581
582     INITMSG(MYDEBUG,"LoadCellsOnEntity - theFamilyName = '"<<theFamilyName<<"'\n");
583     BEGMSG(MYDEBUG,"LoadCellsOnEntity - isCellsLoaded = "<<isCellsLoaded<<"; isFamilyPresent = "<<bool(aFamily)<<endl);
584
585     const VISU::TEntity& aVEntity = theMeshOnEntity->myEntity;
586     const MED::EEntiteMaillage& aMEntity = VTKEntityToMED(aVEntity);
587
588     MED::PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
589     MED::PNodeInfo aNodeInfo = theMed->GetPNodeInfo(aMeshInfo);
590     MED::TInt aNbPoints = aNodeInfo->GetNbElem();
591
592     std::map<TInt,TInt> aNodeIdMap;
593 #ifdef _EDF_NODE_IDS_
594     MED::EBooleen anIsNodeNum = MED::eFAUX;
595 #else
596     MED::EBooleen anIsNodeNum = aNodeInfo->IsElemNum();
597     if(anIsNodeNum){
598       for(MED::TInt i = 0; i < aNbPoints; i++){
599         aNodeIdMap[aNodeInfo->GetElemNum(i)-1] = i;
600       }
601     }
602 #endif
603
604     const MED::TGeom& aTGeom = theMeshOnEntity->myGeom;
605     MED::TGeom::const_iterator anTGeomIter = aTGeom.begin();
606     VISU::TMeshOnEntityImpl::TCellsConn& aCellsConn = theMeshOnEntity->myCellsConn;
607
608     for(; anTGeomIter != aTGeom.end(); anTGeomIter++){
609       const MED::EGeometrieElement& aGeom = anTGeomIter->first;
610       int aVTKGeomType = MEDGeomToVTK(aGeom);
611       switch(aGeom){
612       case MED::ePOLYGONE: {
613         MED::PPolygoneInfo aPolygoneInfo = theMed->GetPPolygoneInfo(aMeshInfo,aMEntity,aGeom);
614         MED::TInt aNbElem = aPolygoneInfo->GetNbElem();
615         
616         if(!isCellsLoaded){
617           VISU::TMeshOnEntityImpl::TConnForCellType& aConnForPolygoneType = aCellsConn[aVTKGeomType];
618           aConnForPolygoneType.resize(aNbElem);
619           
620           int aMNbNodes = aPolygoneInfo->GetConnDim();
621           
622           vector<MED::TInt> aConnect(aMNbNodes);
623           vector<MED::TInt> aIndex = aPolygoneInfo->GetIndex();
624           
625           for(int iElem = 0; iElem < aNbElem; iElem++){
626             VISU::TMeshOnEntityImpl::TConnect& anArray = aConnForPolygoneType[iElem];
627             int aNbConn = aPolygoneInfo->GetNbConn(iElem);
628             
629             anArray.resize(aNbConn);
630             
631             aConnect = aPolygoneInfo->GetConnectivite();
632             
633             for(int i = 0 ; i < aNbConn; i++){
634               anArray[i] = aConnect[aIndex[iElem]-1+i]-1;
635             }
636           }
637         }
638         if(aFamily){
639           VISU::TFamilyImpl::TSubMeshOnCellType& aSubMeshOnCellType = aFamily->mySubMesh[aVTKGeomType];
640           for(int iElem = 0; iElem < aNbElem; iElem++) 
641             if(aPolygoneInfo->GetFamNum(iElem) == aFamily->myId)
642               aSubMeshOnCellType.insert(iElem);
643         }
644         break;
645       }
646       default: {
647         int aVNbNodes = VTKGeom2NbNodes(aVTKGeomType);
648         
649         MED::PCellInfo aCellInfo = theMed->GetPCellInfo(aMeshInfo,aMEntity,aGeom);
650         MED::TInt aNbElem = aCellInfo->GetNbElem();
651         
652         if(!isCellsLoaded){
653           VISU::TMeshOnEntityImpl::TConnForCellType& aConnForCellType = aCellsConn[aVTKGeomType];
654           aConnForCellType.resize(aNbElem);
655           
656           int aMNbNodes = MEDGeom2NbNodes(aGeom);
657           vector<MED::TInt> aConnect(aMNbNodes);
658           
659           for(int iElem = 0; iElem < aNbElem; iElem++) {
660             TMeshOnEntityImpl::TConnect& anArray = aConnForCellType[iElem];
661             anArray.resize(aVNbNodes);
662             
663             if(anIsNodeNum){
664               for(int i = 0; i < aMNbNodes; i++){
665                 aConnect[i] = aNodeIdMap[aCellInfo->GetConn(iElem,i)-1];
666               }
667             }else{
668               for(int i = 0; i < aMNbNodes; i++){
669                 aConnect[i] = aCellInfo->GetConn(iElem,i)-1;
670               }
671             }
672             
673             switch(aGeom){
674             case MED::eTETRA4:
675             case MED::eTETRA10:
676               anArray[0] = aConnect[0];
677               anArray[1] = aConnect[1];
678               anArray[2] = aConnect[3];  
679               anArray[3] = aConnect[2];  
680               break;
681             case MED::ePYRA5:
682             case MED::ePYRA13:
683               anArray[0] = aConnect[0];
684               anArray[1] = aConnect[3];  
685               anArray[2] = aConnect[2];
686               anArray[3] = aConnect[1];  
687               anArray[4] = aConnect[4];
688               break;
689             default:
690               for(int iNode = 0; iNode < aVNbNodes; iNode++) 
691                 anArray[iNode] = aConnect[iNode];
692             }
693             for(int iNode = 0; iNode < aVNbNodes; iNode++) 
694               if(anArray[iNode] < 0 || aNbPoints <= anArray[iNode])
695                 EXCEPTION(runtime_error,"ImportCells >> aNbPoints("<<aNbPoints<<") "<<
696                           "<= anArray["<<iElem<<"]"<<
697                           "["<<iNode<<"]"<<
698                           "("<<anArray[iNode]<<") < 0");
699           }
700         }
701         //Filling aFamily SubMesh
702         if(aFamily){
703           VISU::TFamilyImpl::TSubMeshOnCellType& aSubMeshOnCellType = aFamily->mySubMesh[aVTKGeomType];
704           for(int iElem = 0; iElem < aNbElem; iElem++) 
705             if(aCellInfo->GetFamNum(iElem) == aFamily->myId)
706               aSubMeshOnCellType.insert(iElem);
707         }
708       }}
709     }
710     return 1;
711   }catch(std::exception& exc){
712     theMeshOnEntity->myCellsConn.clear();
713     throw;
714   }catch(...){
715     theMeshOnEntity->myCellsConn.clear();
716     EXCEPTION(runtime_error,"Unknown exception !!!");
717   }
718   return 0;
719 }
720
721
722 int 
723 VISU_MedConvertor::LoadField(const MED::PWrapper& theMed,
724                              VISU::PMEDMesh theMesh,
725                              VISU::PMEDMeshOnEntity theMeshOnEntity,
726                              VISU::PMEDField theField, 
727                              VISU::PMEDValForTime theValForTime)
728 {
729   //Check on loading already done
730   if(!theValForTime->myValForCells.empty()) return 0;
731
732   //Main part of code
733   MED::PMeshInfo aMeshInfo = theMesh->myMeshInfo;
734   MED::TInt anId = theField->myId;
735   MED::PFieldInfo aFieldInfo = theMed->GetPFieldInfo(aMeshInfo,anId);
736
737   MED::TGeom aTGeom;
738   MED::EEntiteMaillage aMEntity;
739   const MED::TEntityInfo& anEntityInfo = theMesh->myEntityInfo;
740   theMed->GetNbTimeStamps(aFieldInfo,anEntityInfo,aMEntity,aTGeom);
741
742   anId = theValForTime->myId;
743   MED::PTimeStampInfo aTimeStampInfo = 
744     theMed->GetPTimeStampInfo(aFieldInfo,aMEntity,aTGeom,anId);
745
746   MED::PTimeStampVal aTimeStampVal = theMed->GetPTimeStampVal(aTimeStampInfo);
747
748   MED::TInt aNbGauss = aTimeStampInfo->GetNbGauss();
749   MED::TInt aNbComp = theField->myNbComp;
750
751   const MED::TGeom& anEntityTGeom = theMeshOnEntity->myGeom;
752   MED::TGeom::const_iterator aTGeomIter = anEntityTGeom.begin();
753   for(; aTGeomIter != anEntityTGeom.end(); aTGeomIter++){
754     const MED::EGeometrieElement& aGeom = aTGeomIter->first;
755     const MED::TInt& aNbElem = aTGeomIter->second;
756
757     INITMSG(MYDEBUG,"LoadField - aGeom = "<<aGeom<<"; aNbElem = '"<<aNbElem<<endl);
758
759     if(aTGeom.find(aGeom) == aTGeom.end()){
760       theField->myDataSize -= aNbElem*theField->myNbComp;
761       theField->myIsTrimmed = true;
762     }else{
763       int aVTKGeomType = MEDGeomToVTK(aGeom);
764       VISU::TValForTimeImpl::TValForCellsWithType& anArray = theValForTime->myValForCells[aVTKGeomType];
765       anArray.resize(aNbComp*aNbElem);
766       for(MED::TInt iElem = 0, anId = 0; iElem < aNbElem; iElem++){
767         for(MED::TInt iComp = 0; iComp < aNbComp; iComp++, anId++){
768           for(MED::TInt iGauss = 0; iGauss < aNbGauss; iGauss++){
769             anArray[anId] += aTimeStampVal->GetVal(aGeom,iElem,iComp,iGauss);
770           }
771           anArray[anId] /= aNbGauss;
772         }
773       }
774     }
775   }
776   return 1; 
777 }