]> SALOME platform Git repositories - modules/visu.git/blob - src/CONVERTOR/VISU_MedConvertor.cxx
Salome HOME
Merge from PortingMED3 07Apr11
[modules/visu.git] / src / CONVERTOR / VISU_MedConvertor.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  VISU OBJECT : interactive object for VISU entities implementation
24 //  File   : VISU_MedConvertor.cxx
25 //  Author : Alexey PETROV
26 //  Module : VISU
27 //
28 #include "VISU_MedConvertor.hxx"
29 #include "VISU_ConvertorUtils.hxx"
30
31 #include "MED_Factory.hxx"
32 #include "MED_Algorithm.hxx"
33 #include "MED_GaussUtils.hxx"
34 #include "MED_Utilities.hxx"
35
36 #include "SALOMEconfig.h"
37
38 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
39 #define NO_CAS_CATCH
40 #endif
41
42 #include <Standard_Failure.hxx>
43
44 #ifdef NO_CAS_CATCH
45 #include <Standard_ErrorHandler.hxx>
46 #endif
47
48 #include <vtkCellType.h>
49
50 #ifdef WNT
51 #include <float.h>
52 #define isnan _isnan
53 #endif
54
55 using MED::TInt;
56 using MED::TFloat;
57 using MED::EBooleen;
58
59 #ifdef _DEBUG_
60 static int MYDEBUG = 0;
61 static int MYVALUEDEBUG = 0;
62 static int MY_FAMILY_DEBUG = 0;
63 static int MY_GROUP_DEBUG = 0;
64 //#define _DEXCEPT_
65 #else
66 static int MYDEBUG = 0;
67 static int MYVALUEDEBUG = 0;
68 static int MY_FAMILY_DEBUG = 0;
69 static int MY_GROUP_DEBUG = 0;
70 #endif
71
72 #define _LOAD_FAMILIES_
73 #define _EDF_NODE_IDS_
74
75
76
77 namespace
78 {
79   //---------------------------------------------------------------
80   vtkIdType
81   MEDGeom2NbNodes(MED::EGeometrieElement theMEDGeomType)
82   { 
83     return theMEDGeomType % 100;
84   }
85
86
87   //---------------------------------------------------------------
88   VISU::EGeometry
89   MEDGeom2VISU(MED::EGeometrieElement theGeom)
90   { 
91     switch(theGeom){
92     case MED::ePOINT1: return VISU::ePOINT1;
93     case MED::eSEG2: return VISU::eSEG2;
94     case MED::eTRIA3: return VISU::eTRIA3;
95     case MED::eQUAD4: return VISU::eQUAD4;
96     case MED::eTETRA4: return VISU::eTETRA4;
97     case MED::eHEXA8: return VISU::eHEXA8;
98     case MED::ePENTA6: return VISU::ePENTA6;
99     case MED::ePYRA5: return VISU::ePYRA5;
100
101     case MED::eSEG3: return VISU::eSEG3;
102     case MED::eTRIA6: return VISU::eTRIA6;
103     case MED::eQUAD8: return VISU::eQUAD8;
104     case MED::eTETRA10: return VISU::eTETRA10;
105     case MED::eHEXA20: return VISU::eHEXA20;
106     case MED::ePENTA15: return VISU::ePENTA15;
107     case MED::ePYRA13: return VISU::ePYRA13;
108
109     case MED::ePOLYGONE: return VISU::ePOLYGONE;
110     case MED::ePOLYEDRE: return VISU::ePOLYEDRE;
111     }
112     return VISU::eNONE;
113   }
114
115
116   //---------------------------------------------------------------
117   MED::EGeometrieElement 
118   VISUGeom2MED(int theGeom)
119   { 
120     switch(theGeom){
121     case VISU::ePOINT1: return MED::ePOINT1;
122     case VISU::eSEG2: return MED::eSEG2;
123     case VISU::eTRIA3: return MED::eTRIA3;
124     case VISU::eQUAD4: return MED::eQUAD4;
125     case VISU::eTETRA4: return MED::eTETRA4;
126     case VISU::eHEXA8: return MED::eHEXA8;
127     case VISU::ePENTA6: return MED::ePENTA6;
128     case VISU::ePYRA5: return MED::ePYRA5;
129
130     case VISU::eSEG3: return MED::eSEG3;
131     case VISU::eTRIA6: return MED::eTRIA6;
132     case VISU::eQUAD8: return MED::eQUAD8;
133     case VISU::eTETRA10: return MED::eTETRA10;
134     case VISU::eHEXA20: return MED::eHEXA20;
135     case VISU::ePENTA15: return MED::ePENTA15;
136     case VISU::ePYRA13: return MED::ePYRA13;
137
138     case VISU::ePOLYGONE: return MED::ePOLYGONE;
139     case VISU::ePOLYEDRE: return MED::ePOLYEDRE;
140     }
141     return MED::EGeometrieElement(-1);
142   }
143
144
145   //---------------------------------------------------------------
146   VISU::TEntity
147   MEDEntityToVTK( MED::EEntiteMaillage theMEDEntity )
148   {
149     VISU::TEntity anEntity = VISU::TEntity( -1 );
150
151     switch(theMEDEntity){
152     case MED::eNOEUD :
153       anEntity = VISU::NODE_ENTITY;
154       break;
155     case MED::eARETE : 
156       anEntity = VISU::EDGE_ENTITY;
157       break;
158     case MED::eFACE : 
159       anEntity = VISU::FACE_ENTITY;
160       break;
161     case MED::eMAILLE : 
162       anEntity = VISU::CELL_ENTITY;
163       break;
164     case MED::eNOEUD_ELEMENT :
165       anEntity = VISU::CELL_ENTITY;
166       break;
167     }
168
169     return anEntity;
170   }
171
172
173   //---------------------------------------------------------------
174   MED::EEntiteMaillage 
175   VTKEntityToMED(VISU::TEntity theVTKEntity)
176   {
177     switch(theVTKEntity){
178     case VISU::NODE_ENTITY: return MED::eNOEUD;
179     case VISU::EDGE_ENTITY: return MED::eARETE;
180     case VISU::FACE_ENTITY: return MED::eFACE;
181     case VISU::CELL_ENTITY: return MED::eMAILLE;
182     }
183     return MED::EEntiteMaillage(-1);
184   }
185
186
187   //---------------------------------------------------------------
188   VISU::PMEDSubProfile
189   CrSubProfile(const MED::PWrapper& theMEDWrapper,
190                const MED::PMeshInfo& theMeshInfo,
191                MED::EEntiteMaillage theMEntity,
192                MED::EGeometrieElement theMGeom,
193                const MED::TGeom2Size& theGeom2Size,
194                const MED::TGeom2Profile& theGeom2Profile)
195   {
196     VISU::EGeometry aEGeom = MEDGeom2VISU(theMGeom);
197     vtkIdType aVNbNodes = VISUGeom2NbNodes(aEGeom);
198
199     VISU::PMEDSubProfile aSubProfile(new VISU::TMEDSubProfile());
200     aSubProfile->myGeom = aEGeom;
201     aSubProfile->myMGeom = theMGeom;
202     aSubProfile->myStatus = VISU::eAddAll;
203
204     MED::TGeom2Size::const_iterator aTimeStampIter = theGeom2Size.find(theMGeom);
205     if(aTimeStampIter == theGeom2Size.end())
206       aSubProfile->myStatus = VISU::eRemoveAll;
207     else{
208       MED::TGeom2Profile::const_iterator aProfileIter = theGeom2Profile.find(theMGeom);
209       if(aProfileIter != theGeom2Profile.end()){
210         MED::PProfileInfo aProfileInfo = aProfileIter->second;
211
212         aSubProfile->myName = aProfileInfo->GetName();
213         aSubProfile->myStatus = VISU::eAddPart;
214
215         const MED::TElemNum& anElemNum = aProfileInfo->myElemNum;
216         TInt aNbElem = anElemNum.size();
217         aSubProfile->myNbCells = aNbElem;
218         switch(theMGeom){
219         case MED::ePOLYGONE: {
220           MED::PPolygoneInfo aPolygoneInfo = 
221             theMEDWrapper->GetPPolygoneInfo(theMeshInfo,theMEntity,theMGeom);
222           for(TInt anElemId = 0; anElemId < aNbElem ; anElemId++){
223             TInt aNbConn = aPolygoneInfo->GetNbConn( anElemNum[ anElemId ] - 1 );
224             aSubProfile->myCellsSize += aNbConn;
225           }
226           break;
227         }
228         case MED::ePOLYEDRE: {
229           MED::PPolyedreInfo aPolyedreInfo = 
230             theMEDWrapper->GetPPolyedreInfo(theMeshInfo,theMEntity,theMGeom);
231           for(TInt anElemId = 0; anElemId < aNbElem ; anElemId++){
232             MED::TCConnSliceArr aConnSliceArr = 
233               aPolyedreInfo->GetConnSliceArr( anElemNum[ anElemId ] - 1 );
234             TInt aNbFaces = aConnSliceArr.size();
235             TInt aCellSize = 0;
236             for(TInt iFace = 0; iFace < aNbFaces; iFace++){
237               MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
238               TInt aNbConn = aConnSlice.size();
239               aCellSize += aNbConn;
240             }
241             aSubProfile->myCellsSize += aCellSize;
242           }
243           break;
244         }
245         default: {
246           aSubProfile->myCellsSize = aSubProfile->myNbCells*aVNbNodes;
247         }}
248       }else{
249         TInt aNbElem = aTimeStampIter->second;
250         aSubProfile->myNbCells = aNbElem;
251         switch(theMGeom){
252         case MED::ePOLYGONE: {
253           MED::PPolygoneInfo aPolygoneInfo = 
254             theMEDWrapper->GetPPolygoneInfo(theMeshInfo,theMEntity,theMGeom);
255           for(TInt anElemId = 0; anElemId < aNbElem ; anElemId++){
256             TInt aNbConn = aPolygoneInfo->GetNbConn(anElemId);
257             aSubProfile->myCellsSize += aNbConn;
258           }
259           break;
260         }
261         case MED::ePOLYEDRE: {
262           MED::PPolyedreInfo aPolyedreInfo = 
263             theMEDWrapper->GetPPolyedreInfo(theMeshInfo,theMEntity,theMGeom);
264           for(TInt anElemId = 0; anElemId < aNbElem ; anElemId++){
265             MED::TCConnSliceArr aConnSliceArr = 
266               aPolyedreInfo->GetConnSliceArr(anElemId);
267             TInt aNbFaces = aConnSliceArr.size();
268             TInt aCellSize = 0;
269             for(TInt iFace = 0; iFace < aNbFaces; iFace++){
270               MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
271               TInt aNbConn = aConnSlice.size();
272               aCellSize += aNbConn;
273             }
274             aSubProfile->myCellsSize += aCellSize;
275           }
276           break;
277         }
278         default: {
279           aSubProfile->myCellsSize = aSubProfile->myNbCells*aVNbNodes;
280         }}
281       }
282     }
283     INITMSG(MYDEBUG,
284             "- aMGeom = "<<theMGeom<<
285             "; aEGeom = "<<aEGeom<<
286             "; aName = '"<<aSubProfile->myName<<"'"<<
287             "; aStatus = "<<aSubProfile->myStatus<<
288             "; aNbCells = "<<aSubProfile->myNbCells<<
289             "; aCellsSize = "<<aSubProfile->myCellsSize<<
290             endl);
291     
292     return aSubProfile;
293   }
294
295
296   //---------------------------------------------------------------
297   VISU::TProfileKey
298   GetProfileKey(const MED::PWrapper& theMEDWrapper,
299                 const MED::PMeshInfo& theMeshInfo,
300                 const MED::PTimeStampValueBase& theTimeStampValue,
301                 const VISU::TMEDMeshOnEntity& theMeshOnEntity,
302                 MED::EEntiteMaillage theMEntity,
303                 const MED::TGeom2Size& theGeom2Size)
304   {
305     INITMSG(MYDEBUG,"GetProfileKey"<<endl);
306     
307     VISU::TProfileKey aProfileKey;
308     const MED::TGeom2Profile& aGeom2Profile = theTimeStampValue->GetGeom2Profile();
309
310     const MED::TGeom2Size& aGeom2Size = theMeshOnEntity.myGeom2Size;
311     MED::TGeom2Size::const_iterator anIter = aGeom2Size.begin();
312     for(; anIter != aGeom2Size.end(); anIter++){
313       MED::EGeometrieElement aMGeom = anIter->first;
314       VISU::PSubProfile aSubProfile = CrSubProfile(theMEDWrapper,
315                                                    theMeshInfo,
316                                                    theMEntity,
317                                                    aMGeom,
318                                                    theGeom2Size,
319                                                    aGeom2Profile);
320       aProfileKey.insert(aSubProfile);
321     }
322     
323     return aProfileKey;
324   }
325   
326
327   //---------------------------------------------------------------
328   void
329   InitProfile(const MED::PWrapper& theMEDWrapper,
330               const MED::PMeshInfo& theMeshInfo,
331               MED::PTimeStampValueBase& theTimeStampValue,
332               VISU::TMEDMeshOnEntity& theMeshOnEntity,
333               MED::EEntiteMaillage theMEntity,
334               const MED::TGeom2Size& theGeom2Size,
335               VISU::TMEDValForTime& theValForTime)
336   {
337     VISU::TTimerLog aTimerLog(MYDEBUG,"InitProfile");
338     INITMSG(MYDEBUG,"InitProfile"<<endl);
339     
340     VISU::TProfileMap& aProfileMap = theMeshOnEntity.myProfileMap;
341     
342     VISU::TProfileKey aProfileKey = GetProfileKey(theMEDWrapper,
343                                             theMeshInfo,
344                                             theTimeStampValue,
345                                             theMeshOnEntity,
346                                             theMEntity,
347                                             theGeom2Size);
348     
349     VISU::TProfileMap::const_iterator anIter = aProfileMap.find(aProfileKey);
350     if(anIter != aProfileMap.end()){
351       theValForTime.myProfile = anIter->second;
352       INITMSG(MYDEBUG,"aProfileMap.find(aProfileKey)"<<endl);
353     }else{
354       VISU::PMEDProfile aProfile(new VISU::TMEDProfile());
355       VISU::TGeom2SubProfile& aGeom2SubProfile = aProfile->myGeom2SubProfile;
356       
357       VISU::TProfileKey::const_iterator anIter = aProfileKey.begin();
358       for(; anIter != aProfileKey.end(); anIter++){
359         VISU::PMEDSubProfile aSubProfile(*anIter);
360
361         if(aProfile->myIsAll && aSubProfile->myStatus != VISU::eAddAll)
362           aProfile->myIsAll = false;
363
364         VISU::EGeometry aEGeom = aSubProfile->myGeom;
365         aGeom2SubProfile[aEGeom] = aSubProfile;
366       }
367
368       aProfileMap[aProfileKey] = aProfile;
369       theValForTime.myProfile = aProfile;
370     }
371   }
372
373
374   //---------------------------------------------------------------
375   VISU::TGaussKey
376   GetGaussKey(const MED::PTimeStampValueBase& theTimeStampValue,
377               const VISU::TMEDMeshOnEntity& theMeshOnEntity,
378               const MED::TGeom2Size& theGeom2Size,
379               VISU::TMEDValForTime& theValForTime)
380   {
381     VISU::TTimerLog aTimerLog(MYDEBUG,"GetGaussKey");
382     INITMSG(MYDEBUG,"GetGaussKey"<<endl);
383
384     VISU::TGaussKey aGaussKey;
385     VISU::PMEDProfile aProfile = theValForTime.myProfile;
386     VISU::TGeom2SubProfile& aGeom2SubProfile = aProfile->myGeom2SubProfile;
387
388     const MED::TTimeStampInfo& aTimeStampInfo = theTimeStampValue->GetTimeStampInfo();
389     const MED::TGeom2Gauss& aGeom2Gauss = aTimeStampInfo.GetGeom2Gauss();
390
391     const MED::TGeom2Size& aGeom2Size = theMeshOnEntity.myGeom2Size;
392     MED::TGeom2Size::const_iterator anIter = aGeom2Size.begin();
393     for(; anIter != aGeom2Size.end(); anIter++){
394       MED::EGeometrieElement aMGeom = anIter->first;
395       VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
396
397       VISU::TGeom2SubProfile::iterator anIter2 = aGeom2SubProfile.find(aEGeom);
398       if(anIter2 == aGeom2SubProfile.end()){
399         INITMSG(MYDEBUG,"anIter2 == aGeom2SubProfile.end!!"<<endl);
400         continue;
401       }
402       VISU::PMEDSubProfile aSubProfile = anIter2->second;
403
404       MED::TGeom2Size::const_iterator aTimeStampIter = theGeom2Size.find(aMGeom);
405       if(aTimeStampIter != theGeom2Size.end()){
406         TInt aNbCells = aTimeStampIter->second;
407         if(aSubProfile->myStatus == VISU::eAddPart)
408           aNbCells = aSubProfile->myNbCells;
409
410         VISU::PMEDGaussSubMesh aGaussSubMesh(new VISU::TMEDGaussSubMesh());
411         aGaussSubMesh->mySubProfile = aSubProfile;
412         aGaussSubMesh->myStatus = aSubProfile->myStatus;
413           
414         VISU::PMEDGauss aGauss(new VISU::TMEDGauss());
415         aGaussSubMesh->myGauss = aGauss;
416         aGauss->myGeom = aEGeom;
417         aGauss->myNbPoints = 1;
418
419         MED::TGeom2Gauss::const_iterator aGaussIter = aGeom2Gauss.find(aMGeom);
420         if(aGaussIter != aGeom2Gauss.end()){
421           MED::PGaussInfo aGaussInfo = aGaussIter->second;
422           aGauss->myGaussInfo = aGaussInfo;
423           aGauss->myName = aGaussInfo->GetName();
424           aGauss->myNbPoints = aGaussInfo->GetNbGauss();
425         } else if ( aTimeStampInfo.GetNbGauss(aMGeom) > 1 )
426           EXCEPTION( std::runtime_error, "aGaussIter == aGeom2Gauss.end()"
427                      " && aTimeStampInfo.GetNbGauss(aMGeom) > 1 !!!" );
428         
429         aGaussSubMesh->myNbCells = aNbCells*aGauss->myNbPoints;
430         aGaussSubMesh->myCellsSize = aGaussSubMesh->myNbCells*2;
431
432         aGaussKey.insert(aGaussSubMesh);
433
434         INITMSGA(MYDEBUG,0,
435                  "- aEGeom = "<<aGauss->myGeom<<
436                  "; aName = '"<<aGauss->myName<<"'"<<
437                  "; aNbGauss = "<<aGauss->myNbPoints<<
438                  "; aStatus = "<<aGaussSubMesh->myStatus<<
439                  "; aNbCells = "<<aGaussSubMesh->myNbCells<<
440                  "; aCellsSize = "<<aGaussSubMesh->myCellsSize<<
441                  endl);
442
443         //break;
444       }
445     }
446
447     return aGaussKey;
448   }
449
450
451   //---------------------------------------------------------------
452   void
453   InitGaussMesh(MED::PTimeStampValueBase& theTimeStampValue,
454                 VISU::TMEDMeshOnEntity& theMeshOnEntity,
455                 const MED::TGeom2Size& theGeom2Size,
456                 VISU::TMEDValForTime& theValForTime)
457   {
458     VISU::TTimerLog aTimerLog(MYDEBUG,"InitGaussMesh");
459     INITMSG(MYDEBUG,"InitGaussMesh"<<endl);
460
461     if(theMeshOnEntity.myEntity == VISU::NODE_ENTITY)
462       return;
463
464     VISU::TGaussMeshMap& aGaussMeshMap = theMeshOnEntity.myGaussMeshMap;
465     
466     VISU::TGaussKey aGaussKey = GetGaussKey(theTimeStampValue,
467                                             theMeshOnEntity,
468                                             theGeom2Size,
469                                             theValForTime);
470
471     VISU::TGaussMeshMap::const_iterator anIter = aGaussMeshMap.find(aGaussKey);
472     if(anIter != aGaussMeshMap.end()){
473       theValForTime.myGaussMesh = anIter->second;
474       INITMSG(MYDEBUG,"aGaussMeshMap.find(aGaussKey)"<<endl);
475     }else{
476       VISU::PMEDGaussMesh aGaussMesh(new VISU::TMEDGaussMesh());
477       VISU::TGeom2GaussSubMesh& aGeom2GaussSubMesh = aGaussMesh->myGeom2GaussSubMesh;
478       {
479         VISU::TGaussKey::const_iterator anIter = aGaussKey.begin();
480         for(; anIter != aGaussKey.end(); anIter++){
481           VISU::PMEDGaussSubMesh aGaussSubMesh(*anIter);
482           VISU::PMEDGauss aGauss = aGaussSubMesh->myGauss;
483           VISU::EGeometry aEGeom = aGauss->myGeom;
484           aGeom2GaussSubMesh[aEGeom] = aGaussSubMesh;
485         }
486       }
487       {
488         VISU::TGaussSubMeshArr& aGaussSubMeshArr = aGaussMesh->myGaussSubMeshArr;
489         aGaussSubMeshArr.resize(aGeom2GaussSubMesh.size());
490         VISU::TGeom2GaussSubMesh::const_iterator anIter = aGeom2GaussSubMesh.begin();
491         for(TInt anID = 0; anIter != aGeom2GaussSubMesh.end(); anIter++, anID++){
492           const VISU::PGaussSubMeshImpl& aGaussSubMesh = anIter->second;
493           aGaussSubMeshArr[anID] = aGaussSubMesh;
494         }
495       }
496       INITMSG(MYDEBUG,"aGaussMeshMap[aGaussKey] = aGaussMesh"<<std::endl);
497       aGaussMeshMap[aGaussKey] = aGaussMesh;
498       theValForTime.myGaussMesh = aGaussMesh;
499     }
500   }
501
502   //---------------------------------------------------------------
503   void
504   BuildMeshOnEntityMap(VISU::PMEDMesh theMesh,
505                        const MED::TEntityInfo& theEntityInfo,
506                        const MED::PNodeInfo& theNodeInfo,
507                        const MED::PWrapper& theMEDWrapper)
508   {
509     VISU::TTimerLog aTimerLog(MYDEBUG,"BuildMeshOnEntityMap");
510     INITMSG(MYDEBUG,"BuildMeshOnEntityMap"<<endl);
511
512     MED::PMeshInfo aMeshInfo = theMesh->myMeshInfo;
513     const std::string& aMeshName = theMesh->myName;
514     VISU::TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap;
515     MED::TEntityInfo::const_iterator anEntityIter = theEntityInfo.begin();
516     for(; anEntityIter != theEntityInfo.end(); anEntityIter++){
517       const MED::EEntiteMaillage& aMEntity = anEntityIter->first;
518       const MED::TGeom2Size& aGeom2Size = anEntityIter->second;
519       
520       VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
521       VISU::PMEDMeshOnEntity aMeshOnEntity = 
522         aMeshOnEntityMap[aVEntity](new VISU::TMEDMeshOnEntity());
523       aMeshOnEntity->myEntity = aVEntity;
524       aMeshOnEntity->myMeshName = aMeshName;
525       aMeshOnEntity->myGeom2Size = aGeom2Size;
526       VISU::TFamilyID2CellsSize& aFamilyID2CellsSize = aMeshOnEntity->myFamilyID2CellsSize;
527       VISU::TGeom2ElemID2FamilyID& aGeom2ElemID2FamilyID = aMeshOnEntity->myGeom2ElemID2FamilyID;
528
529       INITMSG(MYDEBUG,
530               "- aMEntity = "<<aMEntity<<
531               "; aVEntity = "<<aVEntity<<
532               endl);
533       
534       if(aMEntity == MED::eNOEUD){
535         aMeshOnEntity->myNbCells = theMesh->myNbPoints;
536         aMeshOnEntity->myCellsSize = 2*theMesh->myNbPoints;
537         
538         VISU::TElemID2FamilyID& anElemID2FamilyID = aGeom2ElemID2FamilyID[MED::ePOINT1];
539
540         for(TInt iElem = 0; iElem < theMesh->myNbPoints; iElem++){
541           TInt aFamId = theNodeInfo->GetFamNum(iElem);
542           if(aFamId != 0)
543             aFamilyID2CellsSize[aFamId] += 2;
544           anElemID2FamilyID[iElem] = aFamId;
545         }
546         
547         INITMSG(MYDEBUG,
548                 "- myNbCells = "<<aMeshOnEntity->myNbCells<<
549                 "; myCellsSize = "<<aMeshOnEntity->myCellsSize<<
550                 std::endl);
551         
552       }else{
553         MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
554         aMeshOnEntity->myNbCells = 0;
555         aMeshOnEntity->myCellsSize = 0;
556         for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
557           const MED::EGeometrieElement& aMGeom = aGeom2SizeIter->first;
558           
559           VISU::TElemID2FamilyID& anElemID2FamilyID = aGeom2ElemID2FamilyID[aMGeom];
560           switch(aMGeom){
561           case MED::ePOLYGONE: {
562             MED::PPolygoneInfo aPolygoneInfo = theMEDWrapper->GetPPolygoneInfo(aMeshInfo,aMEntity,aMGeom);
563             TInt aNbElem = aPolygoneInfo->GetNbElem();
564             
565             INITMSG(MYDEBUG,
566                     "- aMGeom = "<<aMGeom<<
567                     "; aNbElem = "<<aNbElem<<
568                     endl);
569             
570             aMeshOnEntity->myNbCells += aNbElem;      
571             for(TInt anElemId = 0; anElemId < aNbElem ; anElemId++){
572               TInt aNbConn = aPolygoneInfo->GetNbConn(anElemId);
573               aMeshOnEntity->myCellsSize += aNbConn;
574               TInt aFamId = aPolygoneInfo->GetFamNum(anElemId);
575               if(aFamId != 0)
576                 aFamilyID2CellsSize[aFamId] += aNbConn + 1;
577               anElemID2FamilyID[anElemId] = aFamId;
578             }
579             break;
580           }
581           case MED::ePOLYEDRE: {
582             MED::PPolyedreInfo aPolyedreInfo = theMEDWrapper->GetPPolyedreInfo(aMeshInfo,aMEntity,aMGeom);
583             TInt aNbElem = aPolyedreInfo->GetNbElem();
584             
585             INITMSG(MYDEBUG,
586                     "- aMGeom = "<<aMGeom<<
587                     "; aNbElem = "<<aNbElem<<
588                     endl);
589             
590             aMeshOnEntity->myNbCells += aNbElem;
591             for(TInt anElemId = 0; anElemId < aNbElem ; anElemId++){
592               MED::TCConnSliceArr aConnSliceArr = aPolyedreInfo->GetConnSliceArr(anElemId);
593               TInt aNbFaces = aConnSliceArr.size();
594               TInt aCellSize = 0;
595               for(TInt iFace = 0; iFace < aNbFaces; iFace++){
596                 MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
597                 TInt aNbConn = aConnSlice.size();
598                 aCellSize += aNbConn;
599               }
600               aMeshOnEntity->myCellsSize += aCellSize;
601               TInt aFamId = aPolyedreInfo->GetFamNum(anElemId);
602               if(aFamId != 0)
603                 aFamilyID2CellsSize[aFamId] += aCellSize + 1;
604               anElemID2FamilyID[anElemId] = aFamId;
605             }
606             break;
607           }
608           default: {
609             VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
610             vtkIdType aVNbNodes = VISUGeom2NbNodes(aEGeom);
611             MED::PCellInfo aCellInfo = theMEDWrapper->GetPCellInfo(aMeshInfo,aMEntity,aMGeom);
612             TInt aNbElem = aCellInfo->GetNbElem();
613             aMeshOnEntity->myNbCells += aNbElem;
614             aMeshOnEntity->myCellsSize += aNbElem*(aVNbNodes+1);
615             
616             INITMSG(MYDEBUG,
617                     "- aMGeom = "<<aMGeom<<
618                     "; aNbElem = "<<aNbElem<<
619                     "; myNbCells = "<<aMeshOnEntity->myNbCells<<
620                     "; myCellsSize = "<<aMeshOnEntity->myCellsSize<<
621                     endl);
622             
623             for(TInt iElem = 0; iElem < aNbElem; iElem++){
624               TInt aFamId = aCellInfo->GetFamNum(iElem);
625               if(aFamId != 0)
626                 aFamilyID2CellsSize[aFamId] += aVNbNodes + 1;
627               anElemID2FamilyID[iElem] = aFamId;
628             }
629           }} // end switch(...)
630         }
631       }
632     }
633   }
634
635   //---------------------------------------------------------------
636   void
637   BuildMeshGrilleOnEntityMap(VISU::PMEDMesh theMesh,
638                              const MED::TEntityInfo& theEntityInfo,
639                              const MED::PGrilleInfo& theGrilleInfo,
640                              const MED::PWrapper& theMEDWrapper)
641   {
642     VISU::TTimerLog aTimerLog(MYDEBUG,"BuildMeshGrilleOnEntityMap");
643     INITMSG(MYDEBUG,"BuildMeshGrilleOnEntityMap"<<endl);
644     
645     MED::PMeshInfo aMeshInfo = theMesh->myMeshInfo;
646     const std::string& aMeshName = theMesh->myName;
647     VISU::TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap;
648     MED::TEntityInfo::const_iterator anEntityIter = theEntityInfo.begin();
649     
650     VISU::TStructuredId& aGrilleStructure = theMesh->myGrilleStructure;
651     if ( theGrilleInfo->GetGrilleType() != MED::eGRILLE_STANDARD )
652       for ( int aDimId = 0; aDimId < theMesh->myDim; aDimId++ )
653         aGrilleStructure[aDimId] = theGrilleInfo->GetNbIndexes(aDimId);
654     else {
655       MED::TIntVector aVector = theGrilleInfo->GetGrilleStructure();
656       for ( int aDimId = 0; aDimId < aVector.size(); aDimId++ )
657         aGrilleStructure[aDimId] = aVector[aDimId];
658     }
659
660     int kMax = aGrilleStructure[2];
661     int jMax = aGrilleStructure[1];
662     int iMax = aGrilleStructure[0];
663     
664     int iii = 0;
665     VISU::TObj2StructuredId& aObj2StructuredId = theMesh->myObj2StructuredId;
666     switch ( theMesh->myDim ) {
667     case 1:
668       for ( int i = 1; i <= iMax; i++ )
669         aObj2StructuredId[i-1][0] = i;
670       break;
671     case 2:
672       for ( int j = 1; j <= jMax; j++ )
673         for ( int i = 1; i <= iMax; i++ ) {
674           aObj2StructuredId[iii][0] = i;
675           aObj2StructuredId[iii][1] = j;
676           iii++;
677         }
678       break;
679     case 3:
680       for ( int k = 1; k <= kMax; k++ )
681         for ( int j = 1; j <= jMax; j++ )
682           for ( int i = 1; i <= iMax; i++ ) {
683             aObj2StructuredId[iii][0] = i;
684             aObj2StructuredId[iii][1] = j;
685             aObj2StructuredId[iii][2] = k;
686             iii++;
687           }
688     }
689     
690     for(; anEntityIter != theEntityInfo.end(); anEntityIter++){
691       const MED::EEntiteMaillage& aMEntity = anEntityIter->first;
692       const MED::TGeom2Size& aGeom2Size = anEntityIter->second;
693       
694       VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
695       VISU::PMEDMeshOnEntity aMeshOnEntity = 
696         aMeshOnEntityMap[aVEntity](new VISU::TMEDMeshOnEntity());
697       aMeshOnEntity->myEntity = aVEntity;
698       aMeshOnEntity->myMeshName = aMeshName;
699       aMeshOnEntity->myGeom2Size = aGeom2Size;
700       VISU::TFamilyID2CellsSize& aFamilyID2CellsSize = aMeshOnEntity->myFamilyID2CellsSize;
701       VISU::TGeom2ElemID2FamilyID& aGeom2ElemID2FamilyID = aMeshOnEntity->myGeom2ElemID2FamilyID;
702
703       INITMSG(MYDEBUG,
704               "- aMEntity = "<<aMEntity<<
705               "; aVEntity = "<<aVEntity<<
706               endl);
707
708       if(aMEntity == MED::eNOEUD){
709         aMeshOnEntity->myNbCells = theGrilleInfo->GetNbNodes();
710         aMeshOnEntity->myCellsSize = 2*theGrilleInfo->GetNbNodes();
711
712         VISU::TElemID2FamilyID& anElemID2FamilyID = aGeom2ElemID2FamilyID[MED::ePOINT1];
713
714         if((theGrilleInfo->myFamNumNode).size() > 0)
715           for(TInt iElem = 0; iElem < theGrilleInfo->GetNbNodes(); iElem++){
716             TInt aFamId = theGrilleInfo->GetFamNumNode(iElem);
717             if(aFamId != 0)
718               aFamilyID2CellsSize[aFamId] += 2;
719             anElemID2FamilyID[iElem] = aFamId;
720           }
721
722         INITMSG(MYDEBUG,
723                 "- myNbCells = "<<aMeshOnEntity->myNbCells<<
724                 "; myCellsSize = "<<aMeshOnEntity->myCellsSize<<
725                 endl);;
726
727       } else {
728         MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
729         aMeshOnEntity->myNbCells = 0;
730         aMeshOnEntity->myCellsSize = 0;
731         for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
732           const MED::EGeometrieElement& aMGeom = aGeom2SizeIter->first;
733           VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
734           vtkIdType aVNbNodes = VISUGeom2NbNodes(aEGeom);
735           TInt aNbElem = aGeom2SizeIter->second;//theGrilleInfo->GetNbCells();
736           aMeshOnEntity->myNbCells += aNbElem;
737           aMeshOnEntity->myCellsSize += aNbElem*(aVNbNodes+1);
738
739           VISU::TElemID2FamilyID& anElemID2FamilyID = aGeom2ElemID2FamilyID[aMGeom];
740
741           INITMSG(MYDEBUG,
742                   "- aMGeom = "<<aMGeom<<
743                   "; aNbElem = "<<aNbElem<<
744                   "; myNbCells = "<<aMeshOnEntity->myNbCells<<
745                   "; myCellsSize = "<<aMeshOnEntity->myCellsSize<<
746                   endl);
747
748           MED::TElemNum& famNums =
749             (aMEntity == MED::eMAILLE) ? theGrilleInfo->myFamNum : theGrilleInfo->myFamSubNum;
750           if (famNums.size() == aNbElem)
751             for(TInt iElem = 0; iElem < aNbElem; iElem++){
752               TInt aFamId = famNums[iElem];
753               if(aFamId != 0)
754                 aFamilyID2CellsSize[aFamId] += aVNbNodes + 1;
755               anElemID2FamilyID[iElem] = aFamId;
756             }
757         }
758       }
759     }
760   }
761
762
763   //---------------------------------------------------------------
764   void
765   BuildFieldMap(VISU::PMEDMesh theMesh,
766                 const MED::TEntityInfo& theEntityInfo,
767                 MED::PWrapper theMEDWrapper)
768   {
769     VISU::TTimerLog aTimerLog(MYDEBUG,"BuildFieldMap");
770     TInt aNbFields = theMEDWrapper->GetNbFields(); 
771     MED::PMeshInfo aMeshInfo = theMesh->myMeshInfo;
772     const std::string& aMeshName = theMesh->myName;
773     INITMSG(MYDEBUG,"BuildFieldMap: aNbFields = "<<aNbFields<<"\n");
774     for(TInt iField = 1; iField <= aNbFields; iField++){
775       VISU::TTimerLog aTimerLog(MYDEBUG,"GetPFieldInfo");
776       
777       MED::TErr anError = 0;
778       MED::PFieldInfo aFieldInfo = theMEDWrapper->GetPFieldInfo(aMeshInfo, iField, &anError);
779       if ( anError < 0 )
780         continue;
781
782       TInt aNbComp = aFieldInfo->GetNbComp();
783       std::string aFieldName = aFieldInfo->GetName();
784       
785       MED::TGeom2Size aGeom2Size;
786       MED::EEntiteMaillage aMEntity;
787       TInt aNbTimeStamps = theMEDWrapper->GetNbTimeStamps(aFieldInfo,
788                                                           theEntityInfo,
789                                                           aMEntity,
790                                                           aGeom2Size);
791       if(aNbTimeStamps < 1)
792         continue;
793       
794       VISU::TEntity aVEntity = MEDEntityToVTK( aMEntity );
795       vtkIdType aDataType = VTK_DOUBLE;
796       if ( aFieldInfo->GetType() != MED::eFLOAT64 ) {
797 #if defined(HAVE_F77INT64)
798         aDataType = VTK_LONG;
799 #else   
800         aDataType = VTK_INT;
801 #endif
802       }
803       VISU::PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[aVEntity];
804       VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
805       VISU::PMEDField aField = aFieldMap[aFieldName](new VISU::TMEDField());
806       aField->myId = iField;
807       aField->Init(aNbComp, aDataType);
808       aField->myEntity = aVEntity;
809       aField->myName = aFieldName;
810       aField->myMeshName = aMeshName;
811       aField->myDataSize = aMeshOnEntity->myNbCells * aNbComp;
812       aField->myIsELNO = ( aMEntity == MED::eNOEUD_ELEMENT );
813
814       INITMSG(MYDEBUG,"myName = '"<<aField->myName<<"'"<<
815               "; myId = "<<aField->myId<<
816               "; myEntity = "<<aField->myEntity<<
817               "; myDataSize = "<<aField->myDataSize<<
818               "; myNbComp = "<<aField->myNbComp<<"\n");
819       
820       for(TInt iComp = 0; iComp < aNbComp; iComp++){
821         aField->myCompNames[iComp] = aFieldInfo->GetCompName(iComp);
822         aField->myUnitNames[iComp] = aFieldInfo->GetUnitName(iComp);
823       }
824       
825       for(TInt iTimeStamp = 1; iTimeStamp <= aNbTimeStamps; iTimeStamp++){
826         VISU::TTimerLog aTimerLog(MYDEBUG,"GetPTimeStampInfo");
827
828         MED::TErr anError = 0;
829         MED::PTimeStampInfo aTimeStampInfo = theMEDWrapper->GetPTimeStampInfo(aFieldInfo,
830                                                                               aMEntity,
831                                                                               aGeom2Size,
832                                                                               iTimeStamp,
833                                                                               &anError);
834         if ( anError < 0 )
835           continue;
836
837         TFloat aDt = aTimeStampInfo->GetDt();
838         std::string anUnitDt = aTimeStampInfo->GetUnitDt();
839
840         VISU::TValField& aValField = aField->myValField;
841         VISU::PMEDValForTime aValForTime = aValField[iTimeStamp](new VISU::TMEDValForTime());
842         aValForTime->myId = iTimeStamp;
843         aValForTime->myFieldName = aField->myName;
844         aValForTime->myEntity = aField->myEntity;
845         aValForTime->myMeshName = aField->myMeshName;
846         aValForTime->myTime = VISU::TTime(aDt,anUnitDt);
847         INITMSG(MYDEBUG,"aDt = '"<<aDt<<", "<<anUnitDt<<"'\n");
848         
849         VISU::TGeom2NbGauss& aVGeom2NbGauss = aValForTime->myGeom2NbGauss;
850         const MED::TGeom2NbGauss& aMGeom2NbGauss = aTimeStampInfo->myGeom2NbGauss;
851         MED::TGeom2NbGauss::const_iterator anIter = aMGeom2NbGauss.begin();
852         for(; anIter != aMGeom2NbGauss.end(); anIter++){
853           const MED::EGeometrieElement& aMGeom = anIter->first;
854           VISU::EGeometry aEGeom = MEDGeom2VISU( aMGeom );
855           TInt aNbGauss = anIter->second;
856           aVGeom2NbGauss[ aEGeom ] = aNbGauss;
857
858           // ELNO data should satisfy the following condition ( implicitly )
859           vtkIdType aNbNodes = MEDGeom2NbNodes( aMGeom );
860           aField->myIsELNO &= ( aNbGauss == aNbNodes );
861         }
862       }
863     }
864   }
865
866
867   //---------------------------------------------------------------
868   void
869   BuildFamilyMap(VISU::PMEDMesh theMesh,
870                  const MED::TEntityInfo& theEntityInfo,
871                  const MED::TEntity2TGeom2ElemInfo& theEntity2TGeom2ElemInfo,
872                  const MED::TFamilyInfoSet& theFamilyInfoSet,
873                  MED::PWrapper theMEDWrapper)
874   {
875     VISU::TTimerLog aTimerLog(MYDEBUG,"BuildFamilyMap");
876     INITMSG(MYDEBUG,"BuildFamilyMap\n");
877
878     MED::PMeshInfo aMeshInfo = theMesh->myMeshInfo;
879     MED::TEntity2FamilySet aEntity2FamilySet = MED::GetEntity2FamilySet(theMEDWrapper,theEntity2TGeom2ElemInfo,theFamilyInfoSet);
880     MED::TEntity2FamilySet::const_iterator aEntity2FamilySetIter = aEntity2FamilySet.begin();
881     for(; aEntity2FamilySetIter != aEntity2FamilySet.end(); aEntity2FamilySetIter++){
882       const MED::EEntiteMaillage& aMEntity = aEntity2FamilySetIter->first;
883       const MED::TFamilyTSizeSet& aFamilyTSizeSet = aEntity2FamilySetIter->second;
884       
885       VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
886       VISU::PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[aVEntity];
887       const VISU::TFamilyID2CellsSize& aFamilyID2CellsSize = aMeshOnEntity->myFamilyID2CellsSize;
888       VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
889       VISU::TFamilyIDMap& aFamilyIDMap = aMeshOnEntity->myFamilyIDMap;
890         
891       if(aFamilyTSizeSet.empty())
892         continue;
893         
894       INITMSG(MY_FAMILY_DEBUG,
895               "- aMEntity = "<<aMEntity<<
896               "; aVEntity = "<<aVEntity<<
897               endl);
898
899       MED::TFamilyTSizeSet::const_iterator aFamilyTSizeSetIter = aFamilyTSizeSet.begin();
900       for(; aFamilyTSizeSetIter != aFamilyTSizeSet.end(); aFamilyTSizeSetIter++){
901         const MED::TFamilyTSize& aFamilyTSize = *aFamilyTSizeSetIter;
902         const MED::PFamilyInfo& aFamilyInfo = boost::get<0>(aFamilyTSize);
903         TInt aSize = boost::get<1>(aFamilyTSize);
904         TInt anId = aFamilyInfo->GetId();
905         if(anId == 0) 
906           continue;
907         
908         std::string aFamilyName = aFamilyInfo->GetName();
909
910         VISU::PMEDFamily aFamily = aFamilyMap[aFamilyName](new VISU::TMEDFamily());
911         aFamily->myId = anId;
912         aFamily->myEntity = aVEntity;
913         aFamily->myName = aFamilyName;
914         aFamily->myNbCells = aSize;
915
916         aFamily->myCellsSize = 0;
917         VISU::TFamilyID2CellsSize::const_iterator anIter = aFamilyID2CellsSize.find(anId);
918         if(anIter != aFamilyID2CellsSize.end())
919           aFamily->myCellsSize = anIter->second;
920
921         const TInt aNbGroup = aFamilyInfo->GetNbGroup();
922         VISU::TNames& aGroupNames = aFamily->myGroupNames;
923         aGroupNames.resize(aNbGroup);
924         for(TInt i = 0; i < aNbGroup; i++){
925           std::string aGroupName = aFamilyInfo->GetGroupName(i);
926           aGroupNames[i] = aGroupName;
927         }
928
929         aFamilyIDMap[anId] = aFamily;
930
931         INITMSG(MY_FAMILY_DEBUG,
932                 "- aFamilyName = '"<<aFamilyName<<"'"<<
933                 "; myId = "<<aFamily->myId<<"; "<<
934                 "; aNbAttr = "<<aFamilyInfo->GetNbAttr()<<
935                 "; aNbGroup = "<<aFamilyInfo->GetNbGroup()<<
936                 "; aVEntity = "<<aVEntity<<
937                 "; myNbCells = "<<aFamily->myNbCells<<
938                 "; myCellsSize = "<<aFamily->myCellsSize<<
939                 endl);
940 #ifdef _DEBUG_  
941         for(TInt i = 0; i < aNbGroup; i++){
942           std::string aGroupName = aFamilyInfo->GetGroupName(i);
943           INITMSG(MY_FAMILY_DEBUG,"- aGroupName = '"<<aGroupName<<"'\n");
944         }
945 #endif
946
947       }
948     }
949   }
950
951   
952   /*!
953    * Build grille family map
954    */
955   void
956   BuildGrilleFamilyMap(VISU::PMEDMesh theMesh,
957                        const MED::TEntityInfo& theEntityInfo,
958                        const MED::TFamilyInfoSet& theFamilyInfoSet,
959                        MED::PWrapper theMEDWrapper)
960   {
961     VISU::TTimerLog aTimerLog(MYDEBUG,"BuildGrilleFamilyMap");
962     INITMSG(MYDEBUG,"BuildGrilleFamilyMap\n");
963     
964     VISU::TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap;
965
966     MED::TEntityInfo::const_iterator aEntityIter = theEntityInfo.begin();
967
968     const MED::PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
969     MED::PGrilleInfo aGrilleInfo = theMEDWrapper->GetPGrilleInfo(aMeshInfo);
970
971     const MED::TFamilyID2NbCells& aFam2NbCells = MED::GetFamilyID2NbCells(aGrilleInfo);
972
973     MED::TFamilyInfoSet::const_iterator aFamInter = theFamilyInfoSet.begin();
974     for(; aFamInter != theFamilyInfoSet.end(); aFamInter++){
975       const MED::PFamilyInfo& aFamilyInfo = *aFamInter;
976       TInt anId = aFamilyInfo->GetId();
977
978       if(anId == 0)
979         continue;
980
981       std::string aFamilyName = aFamilyInfo->GetName();
982       const MED::EEntiteMaillage& aMEntity = MED::GetEntityByFamilyId(aGrilleInfo,
983                                                                       anId);
984       VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
985
986       VISU::PMEDMeshOnEntity aMeshOnEntity;
987       VISU::TMeshOnEntityMap::iterator aMeshOnEntityIter = aMeshOnEntityMap.find(aVEntity);
988       if(aMeshOnEntityIter != aMeshOnEntityMap.end())
989         aMeshOnEntity = aMeshOnEntityIter->second;
990
991       VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
992       VISU::TFamilyIDMap& aFamilyIDMap = aMeshOnEntity->myFamilyIDMap;
993
994       VISU::PMEDFamily aFamily = aFamilyMap[aFamilyName](new VISU::TMEDFamily());
995       aFamily->myId = anId;
996       aFamily->myEntity = aVEntity;
997       aFamily->myName = aFamilyName;
998       aFamily->myNbCells = 0;
999       aFamily->myCellsSize = 0;
1000
1001       const VISU::TFamilyID2CellsSize& aFamilyID2CellsSize = aMeshOnEntity->myFamilyID2CellsSize;
1002       VISU::TFamilyID2CellsSize::const_iterator aFamilyid2CellsSizeIter = aFamilyID2CellsSize.find(anId);
1003       if(aFamilyid2CellsSizeIter != (aMeshOnEntity->myFamilyID2CellsSize).end())
1004         aFamily->myCellsSize = aFamilyid2CellsSizeIter->second;
1005       MED::TFamilyID2NbCells::const_iterator aFam2NbCellsIter = aFam2NbCells.find(anId);
1006       if(aFam2NbCellsIter != aFam2NbCells.end())
1007         aFamily->myNbCells = aFam2NbCellsIter->second;
1008
1009       const TInt aNbGroup = aFamilyInfo->GetNbGroup();
1010       VISU::TNames& aGroupNames = aFamily->myGroupNames;
1011       aGroupNames.resize(aNbGroup);
1012       for(TInt i = 0; i < aNbGroup; i++){
1013         std::string aGroupName = aFamilyInfo->GetGroupName(i);
1014         aGroupNames[i] = aGroupName;
1015       }
1016
1017       aFamilyIDMap[anId] = aFamily;
1018
1019       INITMSG(MY_FAMILY_DEBUG,
1020               "- aFamilyName =|"<<aFamily->myName<<"|"
1021               << "; myId = "<<aFamily->myId
1022               << "; aNbAttr = "<<aFamilyInfo->GetNbAttr()
1023               << "; aNbGroup = "<<aFamilyInfo->GetNbGroup()
1024               << "; aVEntity = "<<aVEntity
1025               << "; myNbCells = "<<aFamily->myNbCells
1026               << "; myCellsSize = "<<aFamily->myCellsSize
1027               <<endl);
1028
1029
1030     }
1031   }
1032
1033   //---------------------------------------------------------------
1034   void
1035   BuildGroupMap(VISU::PMEDMesh theMesh,
1036                 const MED::TFamilyInfoSet& theFamilyInfoSet)
1037   {
1038     VISU::TTimerLog aTimerLog(MYDEBUG,"BuildGroupMap");
1039     INITMSG(MYDEBUG,"BuildGroupMap\n");
1040
1041     VISU::TGroupMap& aGroupMap = theMesh->myGroupMap;
1042     MED::TGroupInfo aGroupInfo = MED::GetGroupInfo(theFamilyInfoSet);
1043     MED::TGroupInfo::const_iterator aGroupInfoIter = aGroupInfo.begin();
1044     for(; aGroupInfoIter != aGroupInfo.end(); aGroupInfoIter++){
1045       const std::string& aGroupName = aGroupInfoIter->first;
1046       INITMSG(MY_GROUP_DEBUG,"aGroupName = '"<<aGroupName<<"'\n");
1047
1048       VISU::PMEDGroup aGroup(new VISU::TMEDGroup());
1049       VISU::TFamilySet& aFamilySet = aGroup->myFamilySet;
1050
1051       const MED::TFamilyInfoSet& aFamilyInfoSet = aGroupInfoIter->second;
1052       MED::TFamilyInfoSet::const_iterator aFamilyIter = aFamilyInfoSet.begin();
1053       for(; aFamilyIter != aFamilyInfoSet.end(); aFamilyIter++){
1054         const MED::PFamilyInfo& aFamilyInfo = *aFamilyIter;
1055         std::string aFamilyName = aFamilyInfo->GetName();
1056         
1057         VISU::TEntity aVEntity = VISU::TEntity(-1);
1058         VISU::PMEDFamily aFamily;
1059         
1060         // Find aVisuEntity
1061         const VISU::TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap;
1062         VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityIter = aMeshOnEntityMap.begin();
1063         for(; aMeshOnEntityIter != aMeshOnEntityMap.end(); aMeshOnEntityIter++){
1064           const VISU::PMeshOnEntity& aMeshOnEntity = aMeshOnEntityIter->second;
1065           const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
1066           VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
1067           for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
1068             const std::string& aName = aFamilyMapIter->first;
1069             if(aName == aFamilyName){
1070               aFamily = aFamilyMapIter->second;
1071               aVEntity = aFamily->myEntity;
1072               if(aFamily && aVEntity >= 0){
1073                 aFamilySet.insert(VISU::TEnity2Family(aVEntity, aFamily));
1074                 INITMSG(MY_GROUP_DEBUG,
1075                         "- aFamilyName = '"<<aFamilyName<<"'"<<
1076                         "; aVEntity = "<<aVEntity<<
1077                         "\n");
1078               }
1079             }
1080           }
1081         } 
1082       }
1083       if(!aFamilySet.empty())
1084         aGroupMap.insert(VISU::TGroupMap::value_type(aGroupName,aGroup));
1085     }
1086   }
1087
1088
1089   //---------------------------------------------------------------
1090   struct TSetIsDone
1091   {
1092     bool& myIsDone;
1093     TSetIsDone(bool& theIsDone):
1094       myIsDone(theIsDone)
1095     {}
1096
1097     ~TSetIsDone()
1098     {
1099       myIsDone = true;
1100     }
1101
1102   };
1103
1104
1105   //---------------------------------------------------------------
1106 }
1107
1108 namespace VISU
1109 {
1110   //---------------------------------------------------------------
1111   void
1112   TMEDNamedPointCoords
1113   ::Init(const MED::PNodeInfo& theNodeInfo,
1114          MED::EVersion theVersion)
1115   {
1116     TMEDCoordHolder* aCoordHolder = new TMEDCoordHolder();
1117     TInt aNbElem = theNodeInfo->GetNbElem();
1118     TInt aDim = theNodeInfo->GetMeshInfo()->GetSpaceDim();
1119     aCoordHolder->Init(aNbElem, aDim, theNodeInfo->myCoord);
1120     TNamedPointCoords::Init(PCoordHolder(aCoordHolder));
1121     myVersion = theVersion;
1122
1123     for(TInt iDim = 0; iDim < aDim; iDim++)
1124       myPointsDim[iDim] = theNodeInfo->GetCoordName(iDim);
1125       
1126     myIsElemNum = theNodeInfo->IsElemNum();
1127     if(theNodeInfo->IsElemNum())
1128       myElemNum = theNodeInfo->myElemNum;
1129
1130     myIsElemNames = theNodeInfo->IsElemNames();
1131     if(theNodeInfo->IsElemNames())
1132       myElemNames = theNodeInfo->myElemNames;
1133   }
1134
1135   void
1136   TMEDNamedPointCoords
1137   ::Init(const MED::PGrilleInfo& theGrilleInfo)
1138   {
1139     TMEDCoordHolder* aCoordHolder = new TMEDCoordHolder();
1140     TInt aNbElem = theGrilleInfo->GetNbNodes();
1141     TInt aDim = theGrilleInfo->GetMeshInfo()->GetSpaceDim();
1142     MED::PNodeCoord aCoord(new MED::TNodeCoord(aNbElem * aDim));
1143     aCoordHolder->Init(aNbElem, aDim, aCoord);
1144     TNamedPointCoords::Init(PCoordHolder(aCoordHolder));
1145
1146     for(TInt iDim = 0; iDim < aDim; iDim++)
1147       myPointsDim[iDim] = theGrilleInfo->GetCoordName(iDim);
1148
1149     for(TInt iElem = 0; iElem < aNbElem; iElem++){
1150       VISU::TCoordSlice aVCoordSlice = GetCoordSlice(iElem);
1151       MED::TNodeCoord aMCoord = theGrilleInfo->GetCoord(iElem);
1152       for(TInt iDim = 0; iDim < aDim; iDim++){
1153         aVCoordSlice[iDim] = aMCoord[iDim];
1154       }
1155     }
1156   }
1157
1158   vtkIdType
1159   TMEDNamedPointCoords
1160   ::GetObjID(vtkIdType theID) const
1161   {
1162     if(myIsElemNum)
1163       return (*myElemNum)[theID];
1164     return TNamedPointCoords::GetObjID(theID);
1165   }
1166
1167
1168   vtkIdType
1169   TMEDNamedPointCoords
1170   ::GetVTKID(vtkIdType theID) const
1171   {
1172     if(myIsElemNum){
1173       // To prepare corresponding mapper engine
1174       if(myObj2VTKID.empty()){
1175         vtkIdType anEnd = myElemNum->size();
1176         for(vtkIdType anID = 0; anID < anEnd; anID++)
1177           myObj2VTKID[(*myElemNum)[anID]] = anID;
1178       }
1179       TObj2VTKID::const_iterator anIter = myObj2VTKID.find(theID);
1180       if(anIter != myObj2VTKID.end())
1181         return anIter->second;
1182       return -1;
1183     }
1184     return TNamedPointCoords::GetVTKID(theID);
1185   }
1186
1187   MED::TInt
1188   GetPNOMLength(MED::EVersion theVersion)
1189   {
1190     if(theVersion == MED::eV2_1)
1191       return MED::GetPNOMLength<MED::eV2_1>();
1192     return MED::GetPNOMLength<MED::eV2_2>();
1193   }
1194
1195   std::string 
1196   TMEDNamedPointCoords
1197   ::GetNodeName(vtkIdType theObjID) const
1198   {
1199     if(myIsElemNames)
1200       return GetString(theObjID, GetPNOMLength(myVersion), *myElemNames);
1201     return TNamedPointCoords::GetNodeName(theObjID);
1202   }
1203
1204   unsigned long int
1205   TMEDNamedPointCoords
1206   ::GetMemorySize()
1207   {
1208     size_t aSize = TNamedPointCoords::GetMemorySize();
1209
1210     if(myElemNum){
1211       aSize += myObj2VTKID.size() * sizeof(vtkIdType) * 2;
1212       aSize += myElemNum->size() * sizeof(MED::TInt);
1213     }
1214
1215     if(myIsElemNames)
1216       aSize += myElemNames->size() * sizeof(char);
1217     return aSize;
1218   }
1219
1220
1221   //---------------------------------------------------------------
1222   vtkIdType
1223   TMEDSubProfile
1224   ::GetElemObjID(vtkIdType theID) const
1225   {
1226     if ( !mySubMeshID.empty() )
1227       theID = mySubMeshID[theID];
1228
1229     if ( myIsElemNum )
1230       return (*myElemNum)[theID];
1231     else
1232       return theID;
1233   }
1234   
1235
1236   //---------------------------------------------------------------
1237   vtkIdType
1238   TMEDSubProfile
1239   ::GetElemVTKID(vtkIdType theID) const
1240   {
1241     if ( myIsElemNum )
1242       for ( size_t anId = 0; anId < (*myElemNum).size(); anId++ ) 
1243         if ( (*myElemNum)[ anId ] == theID ) {
1244           theID = anId;
1245           break;
1246         }
1247
1248     return TSubProfileImpl::GetElemVTKID( theID );
1249   }
1250
1251
1252   //----------------------------------------------------------------
1253   unsigned long int
1254   TMEDSubProfile
1255   ::GetMemorySize()
1256   {
1257     size_t aSize = TSubProfileImpl::GetMemorySize();
1258     if(myIsElemNum)
1259       aSize += myElemNum->size() * sizeof(MED::TInt);
1260     return aSize;
1261   }
1262
1263
1264   //---------------------------------------------------------------
1265   void
1266   TMEDGauss
1267   ::LessThan(const PGaussImpl& theGauss,
1268              bool& theResult) const
1269   {
1270     TGaussImpl::LessThan(theGauss,theResult);
1271     if(myGaussInfo){
1272       if(PMEDGauss aGauss = theGauss){
1273         const MED::TGaussInfo& aLeft = myGaussInfo;
1274         const MED::TGaussInfo& aReight = aGauss->myGaussInfo;
1275         theResult = MED::TGaussInfo::TLess()(aLeft,aReight);
1276       }
1277     }
1278   }
1279
1280
1281   //---------------------------------------------------------------
1282   TGaussPointID
1283   TMEDGaussSubMesh
1284   ::GetObjID(vtkIdType theID) const
1285   {
1286     vtkIdType aNbPoints = myGauss->myNbPoints;
1287     TCellID aCellID = theID / aNbPoints;
1288     TLocalPntID aLocalPntID = theID % aNbPoints;
1289
1290     if ( myIsElemNum )
1291       aCellID = GetElemObjID(aCellID);
1292     else
1293       aCellID += myStartID;
1294
1295     return TGaussPointID(aCellID, aLocalPntID);
1296   }
1297   
1298   
1299   //---------------------------------------------------------------
1300   vtkIdType
1301   TMEDGaussSubMesh
1302   ::GetVTKID( const TGaussPointID& theID ) const
1303   {
1304     vtkIdType aResult = -1;
1305
1306     TCellID aCellID = theID.first;
1307     TLocalPntID aLocalPntID = theID.second;
1308     
1309     vtkIdType aNbPoints = myGauss->myNbPoints;
1310     if ( aLocalPntID >= aNbPoints )
1311       return aResult;
1312     
1313     if ( myIsElemNum ) {
1314       aCellID = GetElemVTKID( aCellID );
1315     } else
1316       aCellID -= myStartID;
1317
1318     return aCellID * aNbPoints + aLocalPntID + myStartID;
1319   }
1320
1321
1322   //---------------------------------------------------------------
1323   unsigned long int
1324   TMEDGaussSubMesh
1325   ::GetMemorySize()
1326   {
1327     size_t aSize = TGaussSubMeshImpl::GetMemorySize();
1328     if(myIsElemNum)
1329       aSize += myElemNum->size() * sizeof(MED::TInt);
1330     return aSize;
1331   }
1332
1333
1334   //---------------------------------------------------------------
1335   void
1336   TMEDSubMesh
1337   ::Init(const MED::PElemInfo& theElemInfo,
1338          MED::EVersion theVersion)
1339   {
1340     myVersion = theVersion;
1341     myIsElemNum = theElemInfo->IsElemNum();
1342     if(myIsElemNum)
1343       myElemNum = theElemInfo->myElemNum;
1344
1345     myIsElemNames = theElemInfo->IsElemNames();
1346     if(theElemInfo->IsElemNames())
1347       myElemNames = theElemInfo->myElemNames;
1348   }
1349
1350
1351   void
1352   TMEDSubMesh
1353   ::Init(const MED::PGrilleInfo& theGrilleInfo)
1354   {}
1355
1356   vtkIdType
1357   TMEDSubMesh
1358   ::GetElemObjID(vtkIdType theID) const
1359   {
1360     if(myIsElemNum)
1361       return (*myElemNum)[theID];
1362     else
1363       return TSubMeshImpl::GetElemObjID(theID);
1364   }
1365
1366   std::string 
1367   TMEDSubMesh
1368   ::GetElemName(vtkIdType theObjID) const
1369   {
1370     if(myIsElemNames)
1371       return GetString(theObjID, GetPNOMLength(myVersion), *myElemNames);
1372     return TSubMeshImpl::GetElemName(theObjID);
1373   }
1374
1375   unsigned long int
1376   TMEDSubMesh
1377   ::GetMemorySize()
1378   {
1379     size_t aSize = TSubMeshImpl::GetMemorySize();
1380
1381     if(myIsElemNum)
1382       aSize += myElemNum->size() * sizeof(MED::TInt);
1383
1384     if(myIsElemNames)
1385       aSize += myElemNames->size() * sizeof(char);
1386
1387     return aSize;
1388   }
1389
1390
1391   //---------------------------------------------------------------
1392 }
1393
1394
1395 //---------------------------------------------------------------
1396 extern "C"
1397 VISU_Convertor* 
1398 CreateConvertor(const std::string& theFileName)
1399 {
1400   if(MED::PWrapper aMed = MED::CrWrapper(theFileName,true))
1401     return new VISU_MedConvertor(theFileName, aMed);
1402   return NULL;
1403 }
1404
1405 VISU_MedConvertor
1406 ::VISU_MedConvertor(const std::string& theFileName, MED::PWrapper theMed):
1407   myIsEntitiesDone(false),
1408   myIsFieldsDone(false),
1409   myIsGroupsDone(false),
1410   myIsMinMaxDone(false),
1411   myMed(theMed)
1412 {
1413   myName = theFileName;
1414 }
1415
1416
1417 //---------------------------------------------------------------
1418 VISU_Convertor* 
1419 VISU_MedConvertor
1420 ::BuildEntities()
1421 {
1422   if(myIsEntitiesDone)
1423     return this;
1424
1425   TSetIsDone aSetIsDone(myIsEntitiesDone);
1426   VISU::TTimerLog aTimerLog(MYDEBUG,"BuildEntities");
1427
1428   TInt aNbMeshes = myMed->GetNbMeshes();
1429   VISU::TMeshMap& aMeshMap = myMeshMap;
1430
1431   INITMSG(MYDEBUG,"BuildEntities aNbMeshes = "<<aNbMeshes<<"\n");
1432
1433   for(TInt iMesh = 1; iMesh <= aNbMeshes; iMesh++){
1434 #ifndef _DEXCEPT_
1435     try{
1436 #endif
1437       VISU::TTimerLog aTimerLog(MYDEBUG,"GetPMeshInfo");
1438
1439       MED::PMeshInfo aMeshInfo = myMed->GetPMeshInfo(iMesh);
1440       std::string aMeshName = aMeshInfo->GetName();
1441       TInt aDim = aMeshInfo->GetDim();
1442       MED::EMaillage aType = aMeshInfo->GetType();
1443         
1444       // creating TMesh structure and TMeshOnEntityMap         
1445       VISU::PMEDMesh aMesh = aMeshMap[aMeshName](new VISU::TMEDMesh());
1446       
1447       aMesh->myDim = aDim;
1448       aMesh->myName = aMeshName;
1449       aMesh->myMeshInfo = aMeshInfo;
1450       aMesh->myNamedPointCoords(new VISU::TMEDNamedPointCoords());
1451       
1452       INITMSG(MYDEBUG,"aMeshName = '"<<aMeshName<<
1453               "; aDim = "<<aDim<<"\n");
1454
1455       if(aType == MED::eNON_STRUCTURE){
1456
1457         if(MED::PNodeInfo aNodeInfo = myMed->GetPNodeInfo(aMeshInfo)){
1458           MED::TEntityInfo anEntityInfo = myMed->GetEntityInfo(aMeshInfo);
1459
1460           aMesh->myNbPoints = aNodeInfo->GetNbElem();
1461           aMesh->myEntityInfo = anEntityInfo;
1462         
1463         
1464 #ifndef _DEXCEPT_
1465           try{
1466 #endif
1467             INITMSG(MYDEBUG,"myNbPoints = "<<aMesh->myNbPoints<<
1468                     "; anEntityInfo.size() = "<<anEntityInfo.size()<<
1469                     "\n");
1470             
1471             BuildMeshOnEntityMap(aMesh,
1472                                  anEntityInfo,
1473                                  aNodeInfo,
1474                                  myMed);
1475             
1476 #ifndef _DEXCEPT_
1477           }catch(std::exception& exc){
1478             MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1479           }catch(...){
1480             MSG(MYDEBUG,"Unknown exception !!!");
1481           }
1482 #endif
1483         }
1484       } // NON STRUCTURED MESH
1485       else {
1486         MED::PGrilleInfo aGrilleInfo = myMed->GetPGrilleInfo(aMeshInfo);
1487
1488         MED::TEntityInfo anEntityInfo;
1489         anEntityInfo[MED::eNOEUD][MED::ePOINT1] = aGrilleInfo->GetNbNodes();
1490         anEntityInfo[aGrilleInfo->GetEntity()][aGrilleInfo->GetGeom()] = aGrilleInfo->GetNbCells();
1491         anEntityInfo[aGrilleInfo->GetSubEntity()][aGrilleInfo->GetSubGeom()] = aGrilleInfo->GetNbSubCells();
1492         
1493         aMesh->myNbPoints   = aGrilleInfo->GetNbNodes();
1494         aMesh->myEntityInfo = anEntityInfo;
1495
1496         aMesh->myIsPolarType = (MED::eGRILLE_POLAIRE == aGrilleInfo->GetGrilleType());
1497         aMesh->myIsStructured = true;
1498 #ifndef _DEXCEPT_
1499         try{
1500 #endif
1501           BEGMSG(MYDEBUG,"anEntityInfo.size() = "<<anEntityInfo.size()<<"\n");
1502           
1503           BuildMeshGrilleOnEntityMap(aMesh,
1504                                      anEntityInfo,
1505                                      aGrilleInfo,
1506                                      myMed);
1507           
1508 #ifndef _DEXCEPT_
1509         }catch(std::exception& exc){
1510           MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1511         }catch(...){
1512           MSG(MYDEBUG,"Unknown exception !!!");
1513         }
1514 #endif
1515
1516       }
1517
1518 #ifndef _DEXCEPT_
1519     }catch(std::exception& exc){
1520       MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1521     }catch(...){
1522       MSG(MYDEBUG,"Unknown exception !!!");
1523     }
1524 #endif
1525   } 
1526
1527   return this; 
1528 }
1529
1530
1531 //---------------------------------------------------------------
1532 VISU_Convertor* 
1533 VISU_MedConvertor
1534 ::BuildFields()
1535 {
1536   if(myIsFieldsDone)
1537     return this;
1538
1539   VISU_Convertor_impl::BuildFields();
1540
1541   TSetIsDone aSetIsDone(myIsFieldsDone);
1542   VISU::TTimerLog aTimerLog(MYDEBUG,"BuildFields");
1543
1544   TInt aNbMeshes = myMed->GetNbMeshes();
1545   VISU::TMeshMap& aMeshMap = myMeshMap;
1546
1547   INITMSG(MYDEBUG,"BuildFields - aNbMeshes = "<<aNbMeshes<<"\n");
1548
1549   for(TInt iMesh = 1; iMesh <= aNbMeshes; iMesh++){
1550 #ifndef _DEXCEPT_
1551     try{
1552 #endif
1553       VISU::TTimerLog aTimerLog(MYDEBUG,"GetPMeshInfo");
1554
1555       MED::PMeshInfo aMeshInfo = myMed->GetPMeshInfo(iMesh);
1556       std::string aMeshName = aMeshInfo->GetName();
1557       
1558       VISU::TMeshMap::const_iterator anIter = aMeshMap.find(aMeshName);
1559       if(anIter == aMeshMap.end())
1560         continue;
1561       VISU::PMEDMesh aMesh = anIter->second;
1562
1563       INITMSG(MYDEBUG,"aMeshName = '"<<aMeshName<<"'\n");
1564 #ifndef _DEXCEPT_
1565       try{
1566 #endif
1567         MED::TEntityInfo anEntityInfo = myMed->GetEntityInfo(aMeshInfo);
1568
1569         BuildFieldMap(aMesh,
1570                       anEntityInfo,
1571                       myMed);
1572 #ifndef _DEXCEPT_
1573       }catch(std::exception& exc){
1574         MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1575       }catch(...){
1576         MSG(MYDEBUG,"Unknown exception !!!");
1577       }
1578 #endif
1579
1580 #ifndef _DEXCEPT_
1581     }catch(std::exception& exc){
1582       MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1583     }catch(...){
1584       MSG(MYDEBUG,"Unknown exception !!!");
1585     }
1586 #endif
1587   } 
1588
1589   return this; 
1590 }
1591
1592
1593 //---------------------------------------------------------------
1594 template<class TimeStampValueType>
1595 void
1596 BuildTimeStampMinMax(MED::SharedPtr<TimeStampValueType> theTimeStampValue,
1597                      const VISU::PMEDMeshOnEntity theMeshOnEntity,
1598                      const MED::TGeom2Gauss& theGeom2Gauss,
1599                      VISU::TMetric2Comp2MinMax& theMetric2Comp2MinMax,
1600                      VISU::TMetric2Comp2MinMax& theMetric2Comp2AverageMinMax,
1601                      VISU::TMetric2Comp2Group2MinMax& theMetric2Comp2Group2MinMax,
1602                      VISU::TMetric2Comp2Group2MinMax& theMetric2Comp2Group2AverageMinMax,
1603                      TInt theNbComp,
1604                      TInt theNbComp2)
1605 {
1606   const VISU::TFamilyIDMap& aFamilyIDMap = theMeshOnEntity->myFamilyIDMap;
1607   VISU::TGeom2ElemID2FamilyID aGeom2ElemID2FamilyID = theMeshOnEntity->myGeom2ElemID2FamilyID;
1608
1609   VISU::TVector<double> aBaseAverageValues;
1610   aBaseAverageValues.resize(3);
1611   aBaseAverageValues[VISU::AVERAGE_METRIC] = 0.0;
1612   aBaseAverageValues[VISU::MINIMUM_METRIC] = VTK_LARGE_FLOAT;
1613   aBaseAverageValues[VISU::MAXIMUM_METRIC] = -VTK_LARGE_FLOAT;
1614
1615   const typename TimeStampValueType::TTGeom2Value& aGeom2Value = theTimeStampValue->myGeom2Value;
1616   typename TimeStampValueType::TTGeom2Value::const_iterator anIter = aGeom2Value.begin();
1617   for(; anIter != aGeom2Value.end(); anIter++){
1618     const typename TimeStampValueType::TTMeshValue& aMMeshValue = anIter->second;
1619     MED::EGeometrieElement aMGeom = anIter->first;
1620                   
1621     TInt aNbElem = aMMeshValue.myNbElem;
1622     TInt aNbGauss = aMMeshValue.myNbGauss;
1623                   
1624 // AKL: fix of 0021175 issue. Non-regression test is GVIEW10561(import zzzz121b.med).
1625 //     MED::TGeom2Gauss::const_iterator aGaussIter = theGeom2Gauss.find(aMGeom);
1626 //     if(aGaussIter == theGeom2Gauss.end())
1627 //       aNbGauss = 1;
1628                   
1629     INITMSG(MYDEBUG,
1630             "- aMGeom = "<<aMGeom<<
1631             "; aNbElem = "<<aNbElem<<
1632             "; aNbGauss = "<<aNbGauss<<
1633             endl);
1634
1635     VISU::TElemID2FamilyID anElemID2FamilyID = aGeom2ElemID2FamilyID[aMGeom];
1636     
1637     bool isAverageByGaussPoints = (aNbGauss > 1);
1638     // To calculate min/max per components
1639     for(TInt iElem = 0; iElem < aNbElem; iElem++){
1640       typename TimeStampValueType::TTMeshValue::TCValueSliceArr aMValueSliceArr = aMMeshValue.GetCompValueSliceArr(iElem);
1641
1642       for(int aGaussMetric = (int)VISU::AVERAGE_METRIC; aGaussMetric <= (int)VISU::MAXIMUM_METRIC; aGaussMetric++){
1643         VISU::TComp2MinMax& aComp2MinMax = theMetric2Comp2MinMax[aGaussMetric];
1644         VISU::TComp2MinMax& aComp2AverageMinMax = theMetric2Comp2AverageMinMax[aGaussMetric];
1645         VISU::TComp2Group2MinMax& aComp2Group2MinMax = theMetric2Comp2Group2MinMax[aGaussMetric];
1646         VISU::TComp2Group2MinMax& aComp2Group2AverageMinMax = theMetric2Comp2Group2AverageMinMax[aGaussMetric];
1647
1648         for(TInt iComp = 0; iComp < theNbComp; iComp++){
1649           const typename TimeStampValueType::TTMeshValue::TCValueSlice& aMValueSlice = aMValueSliceArr[iComp];
1650
1651           VISU::TMinMax& aMinMax = aComp2MinMax[iComp+1];
1652           vtkFloatingPointType& aMin = aMinMax.first;
1653           vtkFloatingPointType& aMax = aMinMax.second;
1654           VISU::TMinMax& anAverageMinMax = aComp2AverageMinMax[iComp+1];
1655           vtkFloatingPointType& anAverageMin = anAverageMinMax.first;
1656           vtkFloatingPointType& anAverageMax = anAverageMinMax.second;
1657           vtkFloatingPointType anAverageValue = aBaseAverageValues[aGaussMetric];
1658
1659           VISU::TGroup2MinMax& aGroup2MinMax = aComp2Group2MinMax[iComp+1];
1660           VISU::TGroup2MinMax& aGroup2AverageMinMax = aComp2Group2AverageMinMax[iComp+1];
1661           std::map<VISU::TName,vtkFloatingPointType> aGroup2AverageValue;
1662
1663           // get names of groups, to which the element belongs
1664           VISU::TNames aGroupNames;
1665           VISU::TElemID2FamilyID::const_iterator anIter = anElemID2FamilyID.find(iElem);
1666           if(anIter != anElemID2FamilyID.end()){
1667             int aFamilyId = anIter->second;
1668             if(aFamilyId != 0){
1669               VISU::TFamilyIDMap::const_iterator aFamilyIter = aFamilyIDMap.find(aFamilyId);
1670               if(aFamilyIter != aFamilyIDMap.end()){
1671                 VISU::PMEDFamily aFamily = aFamilyIter->second;
1672                 aGroupNames = aFamily->myGroupNames;
1673                 VISU::TNames::const_iterator aGroupIter = aGroupNames.begin();
1674                 for(; aGroupIter != aGroupNames.end(); aGroupIter++)
1675                   aGroup2AverageValue[*aGroupIter] = aBaseAverageValues[aGaussMetric];
1676               }
1677             }
1678           }
1679
1680           for(TInt iGauss = 0; iGauss < aNbGauss; iGauss++){
1681             const vtkFloatingPointType& aVal = aMValueSlice[iGauss];
1682             aMin = isnan(aVal) ? aVal : std::min(aMin,aVal);
1683             aMax = isnan(aVal) ? aVal : std::max(aMax,aVal);          
1684             if(isAverageByGaussPoints){
1685               switch(aGaussMetric) {
1686                 case VISU::AVERAGE_METRIC: anAverageValue += aVal; break;
1687                 case VISU::MINIMUM_METRIC: anAverageValue = std::min(anAverageValue, aVal); break;
1688                 case VISU::MAXIMUM_METRIC: anAverageValue = std::max(anAverageValue, aVal); break;
1689               }
1690             }
1691             else {
1692               anAverageMin = aMin;
1693               anAverageMax = aMax;
1694             }
1695
1696             // additional calculation for each group, to which the element belongs
1697             VISU::TNames::const_iterator aGroupIter = aGroupNames.begin();
1698             for(; aGroupIter != aGroupNames.end(); aGroupIter++){
1699               VISU::TName aGroupName = *aGroupIter;
1700               bool isGroupFound = aGroup2MinMax.find(aGroupName) != aGroup2MinMax.end();
1701               VISU::TMinMax& aGroupMinMax = aGroup2MinMax[aGroupName];
1702               vtkFloatingPointType& aGroupMin = aGroupMinMax.first;
1703               vtkFloatingPointType& aGroupMax = aGroupMinMax.second;
1704               aGroupMin = isGroupFound ? std::min(aGroupMin,aVal) : aVal;
1705               aGroupMax = isGroupFound ? std::max(aGroupMax,aVal) : aVal;          
1706
1707               if(isAverageByGaussPoints){
1708                 switch(aGaussMetric) {
1709                   case VISU::AVERAGE_METRIC: aGroup2AverageValue[aGroupName] = aGroup2AverageValue[aGroupName] + aVal; break;
1710                   case VISU::MINIMUM_METRIC: aGroup2AverageValue[aGroupName] = std::min(aGroup2AverageValue[aGroupName], aVal); break;
1711                   case VISU::MAXIMUM_METRIC: aGroup2AverageValue[aGroupName] = std::max(aGroup2AverageValue[aGroupName], aVal); break;
1712                 }
1713               }
1714               else {
1715                 VISU::TMinMax& aGroupAverageMinMax = aGroup2AverageMinMax[aGroupName];
1716                 vtkFloatingPointType& aGroupAverageMin = aGroupAverageMinMax.first;
1717                 vtkFloatingPointType& aGroupAverageMax = aGroupAverageMinMax.second;
1718                 aGroupAverageMin = aGroupMin;
1719                 aGroupAverageMax = aGroupMax;
1720               }
1721             }
1722           }
1723           if(isAverageByGaussPoints){
1724             if(aGaussMetric == VISU::AVERAGE_METRIC)
1725               anAverageValue /= aNbGauss;
1726             anAverageMin = std::min(anAverageMin,anAverageValue);
1727             anAverageMax = std::max(anAverageMax,anAverageValue);
1728
1729             VISU::TNames::const_iterator aGroupIter = aGroupNames.begin();
1730             for(; aGroupIter != aGroupNames.end(); aGroupIter++){
1731               VISU::TName aGroupName = *aGroupIter;
1732               vtkFloatingPointType aGroupAverageValue = aGroup2AverageValue[aGroupName];
1733               if(aGaussMetric == VISU::AVERAGE_METRIC)
1734                 aGroupAverageValue /= aNbGauss;
1735               bool isGroupFound = aGroup2AverageMinMax.find(aGroupName) != aGroup2AverageMinMax.end();
1736               VISU::TMinMax& aGroupAverageMinMax = aGroup2AverageMinMax[aGroupName];
1737               vtkFloatingPointType& aGroupAverageMin = aGroupAverageMinMax.first;
1738               vtkFloatingPointType& aGroupAverageMax = aGroupAverageMinMax.second;
1739               aGroupAverageMin = isGroupFound ? std::min(aGroupAverageMin,aGroupAverageValue) : aGroupAverageValue;
1740               aGroupAverageMax = isGroupFound ? std::max(aGroupAverageMax,aGroupAverageValue) : aGroupAverageValue;
1741             }
1742           }
1743         }
1744       }
1745     }
1746
1747     // To calculate min/max per vector modulus
1748     for(int aGaussMetric = (int)VISU::AVERAGE_METRIC; aGaussMetric <= (int)VISU::MAXIMUM_METRIC; aGaussMetric++){
1749       VISU::TComp2MinMax& aComp2MinMax = theMetric2Comp2MinMax[aGaussMetric];
1750       VISU::TComp2MinMax& aComp2AverageMinMax = theMetric2Comp2AverageMinMax[aGaussMetric];
1751       VISU::TComp2Group2MinMax& aComp2Group2MinMax = theMetric2Comp2Group2MinMax[aGaussMetric];
1752       VISU::TComp2Group2MinMax& aComp2Group2AverageMinMax = theMetric2Comp2Group2AverageMinMax[aGaussMetric];
1753
1754       VISU::TMinMax& aMinMax = aComp2MinMax[0];
1755       vtkFloatingPointType& aMin = aMinMax.first;
1756       vtkFloatingPointType& aMax = aMinMax.second;
1757       VISU::TMinMax& anAverageMinMax = aComp2AverageMinMax[0];
1758       vtkFloatingPointType& anAverageMin = anAverageMinMax.first;
1759       vtkFloatingPointType& anAverageMax = anAverageMinMax.second;
1760
1761       VISU::TGroup2MinMax& aGroup2MinMax = aComp2Group2MinMax[0];
1762       VISU::TGroup2MinMax& aGroup2AverageMinMax = aComp2Group2AverageMinMax[0];
1763
1764       for(TInt iElem = 0; iElem < aNbElem; iElem++){
1765         typename TimeStampValueType::TTMeshValue::TCValueSliceArr aMValueSliceArr = aMMeshValue.GetGaussValueSliceArr(iElem);
1766
1767         // get names of groups, to which the element belongs
1768         VISU::TNames aGroupNames;
1769         VISU::TElemID2FamilyID::const_iterator anIter = anElemID2FamilyID.find(iElem);
1770         if(anIter != anElemID2FamilyID.end()){
1771           int aFamilyId = anIter->second;
1772           if(aFamilyId != 0){
1773             VISU::TFamilyIDMap::const_iterator aFamilyIter = aFamilyIDMap.find(aFamilyId);
1774             if(aFamilyIter != aFamilyIDMap.end()){
1775               VISU::PMEDFamily aFamily = aFamilyIter->second;
1776               aGroupNames = aFamily->myGroupNames;
1777             }
1778           }
1779         }
1780
1781         for(TInt iGauss = 0; iGauss < aNbGauss; iGauss++){
1782           const typename TimeStampValueType::TTMeshValue::TCValueSlice& aMValueSlice = aMValueSliceArr[iGauss];
1783           vtkFloatingPointType aValue = 0.0;
1784           for(TInt iComp = 0; iComp < theNbComp2; iComp++){
1785             vtkFloatingPointType aVal = aMValueSlice[iComp];
1786             aValue += aVal*aVal;
1787           }
1788           aValue = sqrt(aValue);
1789           aMin = isnan(aValue) ? aValue : std::min(aMin,aValue);
1790           aMax = isnan(aValue) ? aValue : std::max(aMax,aValue);
1791
1792           // additional calculation for each group, to which the element belongs
1793           VISU::TNames::const_iterator aGroupIter = aGroupNames.begin();
1794           for(; aGroupIter != aGroupNames.end(); aGroupIter++){
1795             VISU::TName aGroupName = *aGroupIter;
1796             bool isGroupFound = aGroup2MinMax.find(aGroupName) != aGroup2MinMax.end();
1797             VISU::TMinMax& aGroupMinMax = aGroup2MinMax[aGroupName];
1798             vtkFloatingPointType& aGroupMin = aGroupMinMax.first;
1799             vtkFloatingPointType& aGroupMax = aGroupMinMax.second;
1800             aGroupMin = isGroupFound ? std::min(aGroupMin,aValue) : aValue;
1801             aGroupMax = isGroupFound ? std::max(aGroupMax,aValue) : aValue;
1802           }
1803         }
1804         if(isAverageByGaussPoints){
1805           typename TimeStampValueType::TTMeshValue::TCValueSliceArr aMCompValueSliceArr = aMMeshValue.GetCompValueSliceArr(iElem);
1806           vtkFloatingPointType aValue = 0.0;
1807           for(TInt iComp = 0; iComp < theNbComp2; iComp++){
1808             const typename TimeStampValueType::TTMeshValue::TCValueSlice& aMCompValueSlice = aMCompValueSliceArr[iComp];
1809             vtkFloatingPointType anAverageValue = aBaseAverageValues[aGaussMetric];
1810             for(TInt iGauss = 0; iGauss < aNbGauss; iGauss++){
1811               const vtkFloatingPointType& aVal = aMCompValueSlice[iGauss];
1812               switch(aGaussMetric) {
1813                 case VISU::AVERAGE_METRIC: anAverageValue += aVal; break;
1814                 case VISU::MINIMUM_METRIC: anAverageValue = std::min(anAverageValue, aVal); break;
1815                 case VISU::MAXIMUM_METRIC: anAverageValue = std::max(anAverageValue, aVal); break;
1816               }
1817             }
1818             if(aGaussMetric == VISU::AVERAGE_METRIC)
1819               anAverageValue /= aNbGauss;
1820             aValue += anAverageValue*anAverageValue;
1821           }
1822           aValue = sqrt(aValue);
1823           anAverageMin = std::min(anAverageMin,aValue);
1824           anAverageMax = std::max(anAverageMax,aValue);
1825
1826           // additional calculation for each group, to which the element belongs
1827           VISU::TNames::const_iterator aGroupIter = aGroupNames.begin();
1828           for(; aGroupIter != aGroupNames.end(); aGroupIter++){
1829             VISU::TName aGroupName = *aGroupIter;
1830             bool isGroupFound = aGroup2AverageMinMax.find(aGroupName) != aGroup2AverageMinMax.end();
1831             VISU::TMinMax& aGroupAverageMinMax = aGroup2AverageMinMax[aGroupName];
1832             vtkFloatingPointType& aGroupAverageMin = aGroupAverageMinMax.first;
1833             vtkFloatingPointType& aGroupAverageMax = aGroupAverageMinMax.second;
1834             aGroupAverageMin = isGroupFound ? std::min(aGroupAverageMin,aValue) : aValue;
1835             aGroupAverageMax = isGroupFound ? std::max(aGroupAverageMax,aValue) : aValue;
1836           }
1837         }
1838         else {
1839           anAverageMin = aMin;
1840           anAverageMax = aMax;
1841
1842           // additional calculation for each group, to which the element belongs
1843           VISU::TNames::const_iterator aGroupIter = aGroupNames.begin();
1844           for(; aGroupIter != aGroupNames.end(); aGroupIter++){
1845             VISU::TName aGroupName = *aGroupIter;
1846             VISU::TMinMax& aGroupAverageMinMax = aGroup2AverageMinMax[aGroupName];
1847             vtkFloatingPointType& aGroupAverageMin = aGroupAverageMinMax.first;
1848             vtkFloatingPointType& aGroupAverageMax = aGroupAverageMinMax.second;
1849             aGroupAverageMin = aGroup2MinMax[aGroupName].first;
1850             aGroupAverageMax = aGroup2MinMax[aGroupName].second;
1851           }
1852         }
1853       }
1854     }
1855   }
1856 }
1857
1858   
1859 //---------------------------------------------------------------
1860 VISU_Convertor* 
1861 VISU_MedConvertor
1862 ::BuildMinMax()
1863 {
1864   if(myIsMinMaxDone)
1865     return this;
1866
1867   VISU_Convertor_impl::BuildMinMax();
1868
1869   TSetIsDone aSetIsDone(myIsMinMaxDone);
1870   VISU::TTimerLog aTimerLog(MYDEBUG,"BuildMinMax");
1871
1872   MED::TKey2Gauss aKey2Gauss = MED::GetKey2Gauss(myMed);
1873   MED::TMKey2Profile aMKey2Profile = MED::GetMKey2Profile(myMed);
1874
1875   TInt aNbMeshes = myMed->GetNbMeshes();
1876   VISU::TMeshMap& aMeshMap = myMeshMap;
1877
1878   INITMSG(MYDEBUG,"BuildMinMax - aNbMeshes = "<<aNbMeshes<<"\n");
1879
1880   for(TInt iMesh = 1; iMesh <= aNbMeshes; iMesh++){
1881 #ifndef _DEXCEPT_
1882     try{
1883 #endif
1884       VISU::TTimerLog aTimerLog(MYDEBUG,"BuildMinMax - GetPMeshInfo");
1885
1886       MED::PMeshInfo aMeshInfo = myMed->GetPMeshInfo(iMesh);
1887       std::string aMeshName = aMeshInfo->GetName();
1888       
1889       VISU::TMeshMap::const_iterator anIter = aMeshMap.find(aMeshName);
1890       if(anIter == aMeshMap.end())
1891         continue;
1892       VISU::PMEDMesh aMesh = anIter->second;
1893
1894 #ifndef _DEXCEPT_
1895       try{
1896 #endif
1897         TInt aNbFields = myMed->GetNbFields(); 
1898
1899         INITMSG(MYDEBUG,
1900                 "- aMeshName = '"<<aMeshName<<"'"<<
1901                 "; aNbFields = "<<aNbFields<<"\n");
1902
1903         MED::TEntityInfo anEntityInfo = myMed->GetEntityInfo(aMeshInfo);
1904
1905         for(TInt iField = 1; iField <= aNbFields; iField++)
1906         {
1907           VISU::TTimerLog aTimerLog(MYDEBUG,"BuildMinMax - GetPFieldInfo()");
1908
1909           MED::TErr anError = 0;
1910           MED::PFieldInfo aFieldInfo = myMed->GetPFieldInfo(aMeshInfo, iField, &anError);
1911           if ( anError < 0 )
1912             continue;
1913
1914           std::string aFieldName = aFieldInfo->GetName();
1915           INITMSG(MYDEBUG,"- aFieldName = '"<<aFieldName<<"'\n");
1916
1917           MED::TGeom2Size aGeom2Size;
1918           MED::EEntiteMaillage aMEntity;
1919           TInt aNbTimeStamps = myMed->GetNbTimeStamps(aFieldInfo,
1920                                                      anEntityInfo,
1921                                                      aMEntity,
1922                                                      aGeom2Size);
1923           if(aNbTimeStamps < 1)
1924             continue;
1925         
1926           VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
1927           VISU::PMEDMeshOnEntity aMeshOnEntity = aMesh->myMeshOnEntityMap[aVEntity];
1928           VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
1929           VISU::PMEDField aField = aFieldMap[aFieldName];
1930         
1931           TInt aNbComp = aField->myNbComp;
1932           int aNbComp2 = aNbComp;
1933           if(aNbComp == 2 || aNbComp == 4)
1934             aNbComp2 = 2;
1935           else if(aNbComp > 4)
1936             aNbComp2 = 3;
1937
1938           VISU::TMetric2Comp2MinMax& aMetric2Comp2MinMax = aField->myMetric2Comp2MinMax;
1939           VISU::TMetric2Comp2MinMax& aMetric2Comp2AverageMinMax = aField->myMetric2Comp2AverageMinMax;
1940           VISU::TMetric2Comp2Group2MinMax& aMetric2Comp2Group2MinMax = aField->myMetric2Comp2Group2MinMax;
1941           VISU::TMetric2Comp2Group2MinMax& aMetric2Comp2Group2AverageMinMax = aField->myMetric2Comp2Group2AverageMinMax;
1942           TSetIsDone aSetIsDone(aField->myIsMinMaxInitilized);
1943           for(TInt iTimeStamp = aNbTimeStamps; iTimeStamp >= 1; iTimeStamp--){
1944             VISU::TTimerLog aTimerLog(MYDEBUG,"BuildMinMax - GetPTimeStampInfo()");
1945             INITMSG(MYDEBUG,"- iTimeStamp = "<<iTimeStamp<<endl);
1946             
1947 #ifndef _DEXCEPT_
1948             try {
1949 #ifdef NO_CAS_CATCH
1950               OCC_CATCH_SIGNALS;
1951 #endif
1952 #endif
1953               MED::PTimeStampInfo aTimeStampInfo = 
1954                 myMed->GetPTimeStampInfo(aFieldInfo,
1955                                          aMEntity,
1956                                          aGeom2Size,
1957                                          iTimeStamp);
1958
1959               MED::PTimeStampValueBase aTimeStampValue = 
1960                 myMed->GetPTimeStampValue(aTimeStampInfo,
1961                                           aMKey2Profile,
1962                                           aKey2Gauss);
1963
1964               const MED::TGeom2Gauss& aGeom2Gauss = aTimeStampInfo->GetGeom2Gauss();
1965
1966               if(aFieldInfo->GetType() == MED::eFLOAT64)
1967                 BuildTimeStampMinMax<MED::TFloatTimeStampValue>(CastToFloatTimeStampValue(aTimeStampValue),
1968                                                                 aMeshOnEntity,
1969                                                                 aGeom2Gauss,
1970                                                                 aMetric2Comp2MinMax,
1971                                                                 aMetric2Comp2AverageMinMax,
1972                                                                 aMetric2Comp2Group2MinMax,
1973                                                                 aMetric2Comp2Group2AverageMinMax,
1974                                                                 aNbComp,
1975                                                                 aNbComp2);
1976
1977               else
1978                 BuildTimeStampMinMax<MED::TIntTimeStampValue>(CastToIntTimeStampValue(aTimeStampValue),
1979                                                               aMeshOnEntity,
1980                                                               aGeom2Gauss,
1981                                                               aMetric2Comp2MinMax,
1982                                                               aMetric2Comp2AverageMinMax,
1983                                                               aMetric2Comp2Group2MinMax,
1984                                                               aMetric2Comp2Group2AverageMinMax,
1985                                                               aNbComp,
1986                                                               aNbComp2);
1987
1988 #ifndef _DEXCEPT_
1989             }catch(Standard_Failure){
1990               Handle(Standard_Failure) aFail = Standard_Failure::Caught();          
1991               MSG(MYDEBUG,"Follow signal was occured in:\n"<<aFail->GetMessageString());
1992             }catch(std::exception& exc){
1993               MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1994             }catch(...){
1995               MSG(MYDEBUG,"Unknown exception !!!");
1996             }
1997 #endif
1998           }
1999           for(TInt iComp = 0; iComp <= aNbComp; iComp++){
2000             VISU::TMinMax aMinMax = aField->GetMinMax(iComp, VISU::TNames());
2001             INITMSG(MYDEBUG,"- "<<iComp<<": "<<aMinMax.first<<"; "<<aMinMax.second<<endl);
2002           }
2003         }
2004 #ifndef _DEXCEPT_
2005       }catch(std::exception& exc){
2006         MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
2007       }catch(...){
2008         MSG(MYDEBUG,"Unknown exception !!!");
2009       }
2010 #endif
2011
2012 #ifndef _DEXCEPT_
2013     }catch(std::exception& exc){
2014       MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
2015     }catch(...){
2016       MSG(MYDEBUG,"Unknown exception !!!");
2017     }
2018 #endif
2019   }
2020
2021   return this; 
2022 }
2023
2024
2025 //---------------------------------------------------------------
2026 VISU_Convertor* 
2027 VISU_MedConvertor
2028 ::BuildGroups()
2029 {
2030   if(myIsGroupsDone)
2031     return this;
2032
2033   TSetIsDone aSetIsDone(myIsGroupsDone);
2034   VISU::TTimerLog aTimerLog(MYDEBUG,"BuildGroups");
2035
2036   TInt aNbMeshes = myMed->GetNbMeshes();
2037   VISU::TMeshMap& aMeshMap = myMeshMap;
2038
2039   INITMSG(MYDEBUG,"BuildGroups - aNbMeshes = "<<aNbMeshes<<"\n");
2040
2041   for(TInt iMesh = 1; iMesh <= aNbMeshes; iMesh++){
2042 #ifndef _DEXCEPT_
2043     try{
2044 #endif
2045       VISU::TTimerLog aTimerLog(MYDEBUG,"GetPMeshInfo");
2046
2047       MED::PMeshInfo aMeshInfo = myMed->GetPMeshInfo(iMesh);
2048       std::string aMeshName = aMeshInfo->GetName();
2049
2050       VISU::TMeshMap::const_iterator anIter = aMeshMap.find(aMeshName);
2051       if(anIter == aMeshMap.end())
2052         continue;
2053       VISU::PMEDMesh aMesh = anIter->second;
2054
2055       INITMSG(MYDEBUG,"aMeshName = '"<<aMeshName<<"'\n");
2056
2057       MED::EMaillage aType = aMeshInfo->GetType();
2058       
2059       MED::TEntityInfo anEntityInfo = myMed->GetEntityInfo(aMeshInfo);
2060       
2061       MED::TEntity2TGeom2ElemInfo anEntity2TGeom2ElemInfo = 
2062         MED::GetEntity2TGeom2ElemInfo(myMed, aMeshInfo, anEntityInfo);
2063       
2064 #ifndef _DEXCEPT_
2065       try{
2066 #endif
2067         MED::TFamilyInfoSet aFamilyInfoSet = MED::GetFamilyInfoSet(myMed, aMeshInfo);
2068         
2069         if(aType == MED::eNON_STRUCTURE)
2070           BuildFamilyMap(aMesh,
2071                          anEntityInfo,
2072                          anEntity2TGeom2ElemInfo,
2073                          aFamilyInfoSet,
2074                          myMed);
2075         else
2076           BuildGrilleFamilyMap(aMesh,
2077                                anEntityInfo,
2078                                aFamilyInfoSet,
2079                                myMed);
2080         
2081         BuildGroupMap(aMesh,
2082                       aFamilyInfoSet);
2083 #ifndef _DEXCEPT_
2084       }catch(std::exception& exc){
2085         MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
2086       }catch(...){
2087           MSG(MYDEBUG,"Unknown exception !!!");
2088       }
2089 #endif
2090
2091 #ifndef _DEXCEPT_
2092     }catch(std::exception& exc){
2093       MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
2094     }catch(...){
2095       MSG(MYDEBUG,"Unknown exception !!!");
2096     }
2097 #endif
2098   } 
2099
2100   return this; 
2101 }
2102
2103
2104 //---------------------------------------------------------------
2105 int
2106 VISU_MedConvertor
2107 ::LoadMeshOnEntity(VISU::PMeshImpl theMesh,
2108                    VISU::PMeshOnEntityImpl theMeshOnEntity)
2109 {
2110   VISU::TTimerLog aTimerLog(MYDEBUG,"LoadMeshOnEntity");
2111   INITMSG(MYDEBUG,"LoadMeshOnEntity"<<endl);
2112
2113   const VISU::TEntity& anEntity = theMeshOnEntity->myEntity;
2114
2115   int isPointsUpdated = 0, isCellsOnEntityUpdated = 0;
2116   if(anEntity == VISU::NODE_ENTITY){
2117     isPointsUpdated += LoadPoints(myMed, theMesh);
2118   }else{
2119     isPointsUpdated += LoadPoints(myMed, theMesh);
2120     isCellsOnEntityUpdated += LoadCellsOnEntity(myMed, theMesh, theMeshOnEntity);
2121   }
2122
2123   return (isPointsUpdated || isCellsOnEntityUpdated);
2124 }
2125
2126
2127 //---------------------------------------------------------------
2128 int
2129 VISU_MedConvertor
2130 ::LoadFamilyOnEntity(VISU::PMeshImpl theMesh,
2131                      VISU::PMeshOnEntityImpl theMeshOnEntity, 
2132                      VISU::PFamilyImpl theFamily)
2133 {
2134   VISU::TTimerLog aTimerLog(MYDEBUG,"LoadFamilyOnEntity");
2135   INITMSG(MYDEBUG,"LoadFamilyOnEntity"<<endl);
2136
2137   const VISU::TEntity& anEntity = theMeshOnEntity->myEntity;
2138
2139   int isPointsUpdated = 0, isCellsOnEntityUpdated = 0;
2140   if(anEntity == VISU::NODE_ENTITY){
2141     isPointsUpdated += LoadPointsOnFamily(myMed, theMesh, theFamily);
2142   }else{
2143     isPointsUpdated += LoadPoints(myMed, theMesh);
2144     isCellsOnEntityUpdated += LoadCellsOnFamily(myMed, theMesh, theMeshOnEntity, theFamily);
2145   }
2146
2147   return (isPointsUpdated || isCellsOnEntityUpdated);
2148 }
2149
2150
2151 //---------------------------------------------------------------
2152 int
2153 VISU_MedConvertor
2154 ::LoadMeshOnGroup(VISU::PMeshImpl theMesh, 
2155                   const VISU::TFamilySet& theFamilySet)
2156 {
2157   VISU::TTimerLog aTimerLog(MYDEBUG,"LoadMeshOnGroup");
2158   INITMSG(MYDEBUG,"LoadMeshOnGroup"<<endl);
2159
2160   int isPointsUpdated = 0, isCellsOnEntityUpdated = 0;
2161   VISU::TFamilySet::const_iterator aFamilyIter = theFamilySet.begin();
2162   for(; aFamilyIter != theFamilySet.end(); aFamilyIter++){
2163     VISU::PMEDFamily aFamily = (*aFamilyIter).second;
2164     const VISU::TEntity& anEntity = aFamily->myEntity;
2165     const VISU::PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[anEntity];
2166     isPointsUpdated += LoadPoints(myMed, theMesh);
2167     if(anEntity == VISU::NODE_ENTITY){
2168       isPointsUpdated += LoadPointsOnFamily(myMed, theMesh, aFamily);
2169     }else{
2170       isCellsOnEntityUpdated += LoadCellsOnFamily(myMed,theMesh,aMeshOnEntity,aFamily);
2171     }
2172   }
2173
2174   return (isPointsUpdated || isCellsOnEntityUpdated);
2175 }
2176
2177
2178 //---------------------------------------------------------------
2179 int
2180 VISU_MedConvertor
2181 ::LoadValForTimeOnMesh(VISU::PMeshImpl theMesh, 
2182                        VISU::PMeshOnEntityImpl theMeshOnEntity, 
2183                        VISU::PFieldImpl theField, 
2184                        VISU::PValForTimeImpl theValForTime)
2185 {
2186   VISU::TTimerLog aTimerLog(MYDEBUG,"LoadValForTimeOnMesh");
2187   INITMSG(MYDEBUG,"LoadValForTimeOnMesh"<<endl);
2188
2189   const VISU::TEntity& anEntity = theMeshOnEntity->myEntity;
2190   int isPointsUpdated = 0, isCellsOnEntityUpdated = 0;
2191   isPointsUpdated += LoadPoints(myMed,theMesh);
2192   if(anEntity != VISU::NODE_ENTITY)
2193     isCellsOnEntityUpdated += LoadCellsOnEntity(myMed,theMesh,theMeshOnEntity);
2194   int isFieldUpdated = LoadValForTimeOnMesh(myMed,theMesh,theMeshOnEntity,theField,theValForTime);
2195   
2196   return (isPointsUpdated || isCellsOnEntityUpdated || isFieldUpdated);
2197 }
2198
2199
2200 //---------------------------------------------------------------
2201 int
2202 VISU_MedConvertor
2203 ::LoadValForTimeOnGaussPts(VISU::PMeshImpl theMesh, 
2204                            VISU::PMeshOnEntityImpl theMeshOnEntity, 
2205                            VISU::PFieldImpl theField, 
2206                            VISU::PValForTimeImpl theValForTime)
2207 {
2208   VISU::TTimerLog aTimerLog(MYDEBUG,"LoadValForTimeOnGaussPts");
2209   INITMSG(MYDEBUG,"LoadValForTimeOnGaussPts"<<endl);
2210
2211   const VISU::TEntity& anEntity = theMeshOnEntity->myEntity;
2212   int isPointsUpdated = 0, isCellsOnEntityUpdated = 0;
2213   if(anEntity != VISU::NODE_ENTITY)
2214     isCellsOnEntityUpdated += LoadCellsOnEntity(myMed,theMesh,theMeshOnEntity);
2215   int isFieldUpdated = LoadValForTimeOnGaussPts(myMed,theMesh,theMeshOnEntity,theField,theValForTime);
2216   
2217   return (isPointsUpdated || isCellsOnEntityUpdated || isFieldUpdated);
2218 }
2219
2220
2221 //---------------------------------------------------------------
2222 int 
2223 VISU_MedConvertor
2224 ::LoadPoints(const MED::PWrapper& theMed,
2225              VISU::PMEDMesh theMesh) 
2226 {
2227   VISU::TTimerLog aTimerLog(MYDEBUG,"LoadPoints");
2228   try{
2229     //Check on existing family
2230     VISU::PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[VISU::NODE_ENTITY];
2231     aMeshOnEntity->myMeshName = theMesh->myName;
2232     aMeshOnEntity->myEntity = VISU::NODE_ENTITY;
2233
2234     INITMSG(MYDEBUG,"LoadPoints - theMesh->myIsDone = "<<theMesh->myIsDone<<"'\n");
2235
2236     //Check on loading already done
2237     if(theMesh->myIsDone)
2238       return 0;
2239
2240     MED::EMaillage aType = theMesh->myMeshInfo->GetType();
2241     
2242     if(aType == MED::eNON_STRUCTURE){
2243       //Main part of code
2244       MED::PNodeInfo aNodeInfo = theMed->GetPNodeInfo(theMesh->myMeshInfo);
2245       TInt aNbElem = aNodeInfo->GetNbElem();
2246       
2247       VISU::PMEDNamedPointCoords aNamedPointCoords = theMesh->myNamedPointCoords;
2248       aNamedPointCoords->Init(aNodeInfo, theMed->GetVersion());
2249       
2250       VISU::TGeom2SubMesh& aGeom2SubMesh = aMeshOnEntity->myGeom2SubMesh;
2251       VISU::PMEDSubMesh aSubMesh = aGeom2SubMesh[VISU::ePOINT1](new VISU::TMEDSubMesh());
2252       
2253       aSubMesh->Init(MED::PElemInfo(aNodeInfo), theMed->GetVersion()); 
2254       aSubMesh->myNbCells = theMesh->myNbPoints;
2255       aSubMesh->myCellsSize = 2*theMesh->myNbPoints;
2256       
2257       VISU::TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
2258       aCell2Connect.resize(aNbElem);
2259       for (int iElem = 0; iElem < aNbElem; iElem++)
2260         aCell2Connect[iElem] = VISU::TConnect(1,iElem);
2261     } // END NON_STRUCTURED
2262     else { // STRUCTURED
2263       //Main part of code
2264       MED::PGrilleInfo aGrilleInfo = theMed->GetPGrilleInfo(theMesh->myMeshInfo);
2265       TInt aNbElem = aGrilleInfo->GetNbNodes();
2266       
2267       VISU::PMEDNamedPointCoords aNamedPointCoords = theMesh->myNamedPointCoords;
2268       aNamedPointCoords->Init(aGrilleInfo);
2269       
2270       VISU::TGeom2SubMesh& aGeom2SubMesh = aMeshOnEntity->myGeom2SubMesh;
2271       VISU::PMEDSubMesh aSubMesh = aGeom2SubMesh[VISU::ePOINT1](new VISU::TMEDSubMesh());
2272       
2273       aSubMesh->Init(aGrilleInfo); 
2274       aSubMesh->myNbCells = theMesh->myNbPoints;
2275       aSubMesh->myCellsSize = 2*theMesh->myNbPoints;
2276       
2277       VISU::TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
2278       aCell2Connect.resize(aNbElem);
2279       for(int iElem = 0; iElem < aNbElem; iElem++)
2280         aCell2Connect[iElem] = VISU::TConnect(1,iElem);
2281       
2282     }
2283     
2284     theMesh->myIsDone = true;
2285     
2286     return 1;
2287
2288   }catch(std::exception& exc){
2289     throw;
2290   }catch(...){
2291     EXCEPTION(std::runtime_error,"Unknown exception !!!");
2292   }
2293
2294   return 0;
2295 }
2296
2297
2298 //---------------------------------------------------------------
2299 int 
2300 VISU_MedConvertor
2301 ::LoadPointsOnFamily(const MED::PWrapper& theMed,
2302                      const VISU::PMEDMesh theMesh, 
2303                      const VISU::PMEDFamily theFamily) 
2304 {
2305   VISU::TTimerLog aTimerLog(MYDEBUG,"LoadPointsOnFamily");
2306   try{
2307     if(theFamily->myIsDone) 
2308       return 0;
2309
2310     const MED::PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
2311     MED::EMaillage aType = aMeshInfo->GetType();
2312
2313     //Main part of code
2314     if(aType == MED::eNON_STRUCTURE){
2315       MED::PNodeInfo aNodeInfo = theMed->GetPNodeInfo(theMesh->myMeshInfo);
2316       TInt aNbElem = aNodeInfo->GetNbElem();
2317       
2318       if(aNbElem > 0){
2319         TInt anId = theFamily->myId;
2320         VISU::TSubMeshID& aSubMeshID = theFamily->myGeom2SubMeshID[VISU::ePOINT1];
2321         for(TInt iElem = 0; iElem < aNbElem; iElem++) 
2322           if(aNodeInfo->GetFamNum(iElem) == anId)
2323             aSubMeshID.push_back(iElem);
2324       }
2325     }
2326     else {
2327       MED::PGrilleInfo aGrilleInfo = theMed->GetPGrilleInfo(aMeshInfo);
2328       TInt aNbElem = aGrilleInfo->GetNbNodes();
2329       
2330       if(aNbElem > 0){
2331         TInt anId = theFamily->myId;
2332         VISU::TSubMeshID& aSubMeshID = theFamily->myGeom2SubMeshID[VISU::ePOINT1];
2333         for(TInt iElem = 0; iElem < aNbElem; iElem++) 
2334           if(aGrilleInfo->GetFamNumNode(iElem) == anId)
2335             aSubMeshID.push_back(iElem);
2336       }
2337     }
2338
2339     theFamily->myIsDone = true;
2340
2341     return 1;
2342
2343   }catch(std::exception& exc){
2344     throw;
2345   }catch(...){
2346     EXCEPTION(std::runtime_error,"Unknown exception !!!");
2347   }
2348
2349   return 0;
2350 }
2351
2352
2353 //---------------------------------------------------------------
2354 int 
2355 VISU_MedConvertor
2356 ::LoadCellsOnEntity(const MED::PWrapper& theMed,
2357                     const VISU::PMEDMesh theMesh,
2358                     const VISU::PMEDMeshOnEntity theMeshOnEntity)
2359 {
2360   VISU::TTimerLog aTimerLog(MYDEBUG,"LoadCellsOnEntity");
2361 #ifndef _DEXCEPT_
2362   try{
2363 #endif
2364     const VISU::TEntity& aVEntity = theMeshOnEntity->myEntity;
2365     const MED::EEntiteMaillage& aMEntity = VTKEntityToMED(aVEntity);
2366
2367     INITMSG(MYDEBUG,"LoadCellsOnEntity - aVEntity = "<<aVEntity<<"\n");
2368
2369     if(theMeshOnEntity->myIsDone)
2370       return 0;
2371
2372     const MED::PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
2373
2374     MED::EMaillage aType = aMeshInfo->GetType();
2375
2376     if(aType == MED::eSTRUCTURE){
2377       
2378       MED::PGrilleInfo aGrilleInfo = theMed->GetPGrilleInfo(aMeshInfo);
2379       TInt aNbPoints = aGrilleInfo->GetNbNodes();
2380       
2381       std::map<TInt,TInt> aNodeIdMap;
2382       EBooleen anIsNodeNum = MED::eFAUX;
2383       
2384       const MED::TGeom2Size& aGeom2Size = theMeshOnEntity->myGeom2Size;
2385       MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
2386       VISU::TGeom2SubMesh& aGeom2SubMesh = theMeshOnEntity->myGeom2SubMesh;
2387       
2388       for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
2389         const MED::EGeometrieElement& aMGeom = aGeom2SizeIter->first;
2390         VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
2391         INITMSG(MYDEBUG,"aMGeom = "<<aMGeom<<"; aEGeom = "<<aEGeom<<"\n");
2392         {
2393           vtkIdType aVNbNodes = VISUGeom2NbNodes(aEGeom);
2394           INITMSG(MYDEBUG,"aVNbNodes = "<<aVNbNodes<<"\n");
2395         
2396           TInt aNbElem = aGeom2SizeIter->second;//aGrilleInfo->GetNbCells();
2397           
2398           if(aNbElem > 0){
2399             VISU::PMEDSubMesh aSubMesh = aGeom2SubMesh[aEGeom](new VISU::TMEDSubMesh());
2400             
2401             aSubMesh->Init(aGrilleInfo); 
2402             aSubMesh->myNbCells = aNbElem;      
2403             aSubMesh->myCellsSize = aNbElem*(aVNbNodes+1);
2404             
2405             VISU::TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
2406             aCell2Connect.resize(aNbElem);
2407             
2408             TInt aMNbNodes = MEDGeom2NbNodes(aMGeom);
2409             VISU::TVector<TInt> aConnect(aMNbNodes);
2410             
2411             for(TInt iElem = 0; iElem < aNbElem; iElem++) {
2412               MED::TIntVector aConn = aGrilleInfo->GetConn(iElem, theMeshOnEntity->myEntity != VISU::CELL_ENTITY);
2413               VISU::TConnect& anArray = aCell2Connect[iElem];
2414               anArray.resize(aVNbNodes);
2415               
2416               if(anIsNodeNum){
2417                 for(TInt iConn = 0; iConn < aMNbNodes; iConn++){
2418                   aConnect[iConn] = aNodeIdMap[aConn[iConn] - 1];
2419                 }
2420               }else{
2421                 for(int iConn = 0; iConn < aMNbNodes; ++iConn){
2422                   aConnect[iConn] = aConn[iConn];
2423                 }
2424               }
2425               
2426               switch(aMGeom){
2427               case MED::eQUAD4:
2428                 anArray[0] = aConnect[0];
2429                 anArray[1] = aConnect[2];
2430                 anArray[2] = aConnect[3];
2431                 anArray[3] = aConnect[1];
2432                 break;
2433               case MED::eHEXA8:
2434                 anArray[0] = aConnect[0];
2435                 anArray[1] = aConnect[2];
2436                 anArray[2] = aConnect[3];
2437                 anArray[3] = aConnect[1];
2438                 anArray[4] = aConnect[4];
2439                 anArray[5] = aConnect[6];
2440                 anArray[6] = aConnect[7];
2441                 anArray[7] = aConnect[5];
2442                 break;
2443               default:
2444                 for(int iNode = 0; iNode < aVNbNodes; iNode++) 
2445                   anArray[iNode] = aConnect[iNode];
2446               }
2447               
2448               for(int iNode = 0; iNode < aVNbNodes; iNode++) 
2449                 if(anArray[iNode] < 0 || aNbPoints <= anArray[iNode])
2450                   EXCEPTION(std::runtime_error,"LoadCellsOnEntity - "<<
2451                             " aNbPoints("<<aNbPoints<<") "<<
2452                             "<= anArray["<<iElem<<"]"<<
2453                             "["<<iNode<<"]"<<
2454                             "("<<anArray[iNode]<<") < 0");
2455             }
2456           }
2457         }
2458       }
2459
2460       theMeshOnEntity->myIsDone = true;
2461       
2462       return 1;
2463       
2464     }
2465     
2466     MED::PNodeInfo aNodeInfo = theMed->GetPNodeInfo(aMeshInfo);
2467     TInt aNbPoints = aNodeInfo->GetNbElem();
2468
2469     std::map<TInt,TInt> aNodeIdMap;
2470 #ifdef _EDF_NODE_IDS_
2471     EBooleen anIsNodeNum = MED::eFAUX;
2472 #else
2473     EBooleen anIsNodeNum = aNodeInfo->IsElemNum();
2474     if(anIsNodeNum){
2475       for(TInt i = 0; i < aNbPoints; i++){
2476         aNodeIdMap[aNodeInfo->GetElemNum(i)-1] = i;
2477       }
2478     }
2479 #endif
2480
2481     const MED::TGeom2Size& aGeom2Size = theMeshOnEntity->myGeom2Size;
2482     MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
2483     VISU::TGeom2SubMesh& aGeom2SubMesh = theMeshOnEntity->myGeom2SubMesh;
2484
2485     for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
2486       const MED::EGeometrieElement& aMGeom = aGeom2SizeIter->first;
2487       VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
2488       INITMSG(MYDEBUG,"aMGeom = "<<aMGeom<<"; aEGeom = "<<aEGeom<<"\n");
2489       switch(aMGeom){
2490       case MED::ePOLYGONE: {
2491         MED::PPolygoneInfo aPolygoneInfo = theMed->GetPPolygoneInfo(aMeshInfo,aMEntity,aMGeom);
2492         TInt aNbElem = aPolygoneInfo->GetNbElem();
2493         if(aNbElem > 0){
2494           VISU::PMEDSubMesh aSubMesh = aGeom2SubMesh[aEGeom](new VISU::TMEDSubMesh());
2495           
2496           aSubMesh->Init(MED::PElemInfo(aPolygoneInfo),theMed->GetVersion()); 
2497           aSubMesh->myNbCells = aNbElem;      
2498
2499           VISU::TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
2500           aCell2Connect.resize(aNbElem);
2501           
2502           for(TInt iElem = 0; iElem < aNbElem; iElem++) {
2503             MED::TCConnSlice aConnSlice = aPolygoneInfo->GetConnSlice(iElem);
2504             TInt aNbConn = aPolygoneInfo->GetNbConn(iElem);
2505             aSubMesh->myCellsSize += aNbConn;
2506             VISU::TConnect& anArray = aCell2Connect[iElem];
2507             anArray.resize(aNbConn);
2508             for(TInt iConn = 0; iConn < aNbConn; iConn++)
2509               anArray[iConn] = aConnSlice[iConn] - 1;
2510           }
2511         }
2512         break;
2513       }
2514       case MED::ePOLYEDRE: {
2515         MED::PPolyedreInfo aPolyedreInfo = theMed->GetPPolyedreInfo(aMeshInfo,aMEntity,aMGeom);
2516         TInt aNbElem = aPolyedreInfo->GetNbElem();
2517         
2518         if(aNbElem > 0){
2519           VISU::PMEDSubMesh aSubMesh = aGeom2SubMesh[aEGeom](new VISU::TMEDSubMesh());
2520           
2521           aSubMesh->Init(MED::PElemInfo(aPolyedreInfo),theMed->GetVersion()); 
2522           aSubMesh->myNbCells = aNbElem;      
2523
2524           VISU::TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
2525           aCell2Connect.resize(aNbElem);
2526           
2527           for(TInt iElem = 0; iElem < aNbElem; iElem++){
2528             MED::TCConnSliceArr aConnSliceArr = aPolyedreInfo->GetConnSliceArr(iElem);
2529             VISU::TConnect& anArray = aCell2Connect[iElem];
2530             typedef std::set<TInt> TConnectSet;
2531             TConnectSet aConnectSet;
2532             TInt aNbFaces = aConnSliceArr.size();
2533             for(TInt iFace = 0; iFace < aNbFaces; iFace++){
2534               MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
2535               TInt aNbConn = aConnSlice.size();
2536               aSubMesh->myCellsSize += aNbConn;
2537               for(TInt iConn = 0; iConn < aNbConn; iConn++){
2538                 aConnectSet.insert(aConnSlice[iConn]);
2539               }
2540             }
2541           
2542             int aNbConn = aConnectSet.size();
2543             anArray.resize(aNbConn);
2544             TConnectSet::iterator anIter = aConnectSet.begin();
2545             for(int i = 0; anIter != aConnectSet.end(); anIter++, i++){
2546               TInt anId = *anIter;
2547               anArray[i] = anId - 1;
2548             }
2549           }
2550         }
2551
2552         break;
2553       }
2554       default: {
2555         vtkIdType aVNbNodes = VISUGeom2NbNodes(aEGeom);
2556         INITMSG(MYDEBUG,"aVNbNodes = "<<aVNbNodes<<"\n");
2557         
2558         MED::PCellInfo aCellInfo = theMed->GetPCellInfo(aMeshInfo,aMEntity,aMGeom);
2559         TInt aNbElem = aCellInfo->GetNbElem();
2560         
2561         if(aNbElem > 0){
2562           VISU::PMEDSubMesh aSubMesh = aGeom2SubMesh[aEGeom](new VISU::TMEDSubMesh());
2563           
2564           aSubMesh->Init(MED::PElemInfo(aCellInfo), theMed->GetVersion()); 
2565           aSubMesh->myNbCells = aNbElem;      
2566           aSubMesh->myCellsSize = aNbElem*(aVNbNodes+1);
2567
2568           VISU::TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
2569           aCell2Connect.resize(aNbElem);
2570         
2571           TInt aMNbNodes = MEDGeom2NbNodes(aMGeom);
2572           VISU::TVector<TInt> aConnect(aMNbNodes);
2573         
2574           for(TInt iElem = 0; iElem < aNbElem; iElem++) {
2575             MED::TCConnSlice aConnSlice = aCellInfo->GetConnSlice(iElem);
2576             VISU::TConnect& anArray = aCell2Connect[iElem];
2577             anArray.resize(aVNbNodes);
2578             
2579             if(anIsNodeNum){
2580               for(TInt iConn = 0; iConn < aMNbNodes; iConn++){
2581                 aConnect[iConn] = aNodeIdMap[aConnSlice[iConn] - 1];
2582               }
2583             }else{
2584               for(int iConn = 0; iConn < aMNbNodes; iConn++){
2585                 aConnect[iConn] = aConnSlice[iConn] - 1;
2586               }
2587             }
2588             
2589             switch(aMGeom){
2590 #if !(defined(VTK_QUADRATIC_EDGE) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
2591             case MED::eSEG3:
2592               anArray[0] = aConnect[0];
2593               anArray[2] = aConnect[1];  
2594
2595               anArray[1] = aConnect[2];
2596               break;
2597 #endif
2598 #if !(defined(VTK_QUADRATIC_TRIANGLE) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
2599             case MED::eTRIA6:
2600               anArray[0] = aConnect[0];
2601               anArray[2] = aConnect[1];  
2602               anArray[4] = aConnect[2];  
2603
2604               anArray[1] = aConnect[3];
2605               anArray[3] = aConnect[4];  
2606               anArray[5] = aConnect[5];  
2607               break;
2608 #endif
2609 #if !(defined(VTK_QUADRATIC_QUAD) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
2610             case MED::eQUAD8:
2611               anArray[0] = aConnect[0];
2612               anArray[2] = aConnect[1];  
2613               anArray[4] = aConnect[2];  
2614               anArray[6] = aConnect[3];  
2615
2616               anArray[1] = aConnect[4];
2617               anArray[3] = aConnect[5];  
2618               anArray[5] = aConnect[6];  
2619               anArray[7] = aConnect[7];  
2620               break;
2621 #endif
2622 #if (defined(VTK_QUADRATIC_TETRA) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
2623             case MED::eTETRA10:
2624               anArray[0] = aConnect[0];
2625               anArray[1] = aConnect[2];
2626               anArray[2] = aConnect[1];  
2627               anArray[3] = aConnect[3];  
2628
2629               anArray[4] = aConnect[6];
2630               anArray[5] = aConnect[5];
2631               anArray[6] = aConnect[4];  
2632
2633               anArray[7] = aConnect[7];  
2634               anArray[8] = aConnect[9];  
2635               anArray[9] = aConnect[8];  
2636               break;
2637 #endif
2638             case MED::eTETRA4:
2639               anArray[0] = aConnect[0];
2640               anArray[1] = aConnect[2];
2641               anArray[2] = aConnect[1];  
2642               anArray[3] = aConnect[3];  
2643               break;
2644 #if (defined(VTK_QUADRATIC_PYRAMID) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
2645             case MED::ePYRA13:
2646               anArray[0] = aConnect[0];
2647               anArray[1] = aConnect[3];
2648               anArray[2] = aConnect[2];  
2649               anArray[3] = aConnect[1];  
2650               anArray[4] = aConnect[4];
2651
2652               anArray[5] = aConnect[8];
2653               anArray[6] = aConnect[7];  
2654               anArray[7] = aConnect[6];  
2655               anArray[8] = aConnect[5];  
2656
2657               anArray[9] = aConnect[9];  
2658               anArray[10] = aConnect[12];  
2659               anArray[11] = aConnect[11];  
2660               anArray[12] = aConnect[10];  
2661               break;
2662 #endif
2663             case MED::ePYRA5:
2664               anArray[0] = aConnect[0];
2665               anArray[1] = aConnect[3];  
2666               anArray[2] = aConnect[2];
2667               anArray[3] = aConnect[1];  
2668               anArray[4] = aConnect[4];
2669               break;
2670             default:
2671               for(int iNode = 0; iNode < aVNbNodes; iNode++) 
2672                 anArray[iNode] = aConnect[iNode];
2673             }
2674             for(int iNode = 0; iNode < aVNbNodes; iNode++) 
2675               if(anArray[iNode] < 0 || aNbPoints <= anArray[iNode])
2676                 EXCEPTION(std::runtime_error,"LoadCellsOnEntity - "<<
2677                           " aNbPoints("<<aNbPoints<<") "<<
2678                           "<= anArray["<<iElem<<"]"<<
2679                           "["<<iNode<<"]"<<
2680                           "("<<anArray[iNode]<<") < 0");
2681           }
2682         }
2683       }}
2684     }
2685
2686     // END NON_STRUCTURED
2687
2688     theMeshOnEntity->myIsDone = true;
2689
2690     return 1;
2691
2692 #ifndef _DEXCEPT_
2693   }catch(std::exception& exc){
2694     throw;
2695   }catch(...){
2696     EXCEPTION(std::runtime_error,"Unknown exception !!!");
2697   }
2698 #endif
2699
2700   return 0;
2701 }
2702
2703
2704 //---------------------------------------------------------------
2705 int 
2706 VISU_MedConvertor
2707 ::LoadCellsOnFamily(const MED::PWrapper& theMed,
2708                     const VISU::PMEDMesh theMesh,
2709                     const VISU::PMEDMeshOnEntity theMeshOnEntity,
2710                     const VISU::PMEDFamily theFamily)
2711 {
2712   VISU::TTimerLog aTimerLog(MYDEBUG,"LoadCellsOnFamily");
2713 #ifndef _DEXCEPT_
2714   try{
2715 #endif
2716     const VISU::TEntity& aVEntity = theMeshOnEntity->myEntity;
2717     const MED::EEntiteMaillage& aMEntity = VTKEntityToMED(aVEntity);
2718
2719     INITMSG(MYDEBUG,"LoadCellsOnFamily - aVEntity = "<<aVEntity<<"\n");
2720
2721     if(theFamily->myIsDone)
2722       return 0;
2723
2724     TInt anId = theFamily->myId;
2725
2726     const MED::PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
2727     VISU::TGeom2SubMeshID& aGeom2SubMeshID = theFamily->myGeom2SubMeshID;
2728     MED::EMaillage aType = aMeshInfo->GetType();
2729
2730     const MED::TGeom2Size& aGeom2Size = theMeshOnEntity->myGeom2Size;
2731     MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
2732     for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
2733       const MED::EGeometrieElement& aMGeom = aGeom2SizeIter->first;
2734       if(aType == MED::eNON_STRUCTURE){
2735         MED::PElemInfo anElemInfo;
2736         switch(aMGeom){
2737         case MED::ePOLYGONE: {
2738           anElemInfo = theMed->GetPPolygoneInfo(aMeshInfo,aMEntity,aMGeom);
2739           break;
2740         }
2741         case MED::ePOLYEDRE: {
2742           anElemInfo = theMed->GetPPolyedreInfo(aMeshInfo,aMEntity,aMGeom);
2743           break;
2744         }
2745         default: {
2746           anElemInfo = theMed->GetPCellInfo(aMeshInfo,aMEntity,aMGeom);
2747           break;
2748         }}
2749         if(anElemInfo){
2750           if(TInt aNbElem = anElemInfo->GetNbElem()){
2751             VISU::TSubMeshID aSubMeshID;
2752             for(TInt iElem = 0; iElem < aNbElem; iElem++) 
2753               if(anElemInfo->GetFamNum(iElem) == anId)
2754                 aSubMeshID.push_back(iElem);
2755             if(!aSubMeshID.empty()){
2756               VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
2757               INITMSG(MYDEBUG,"aMGeom = "<<aMGeom<<"\n");
2758               aGeom2SubMeshID.insert(VISU::TGeom2SubMeshID::value_type(aEGeom,aSubMeshID));
2759             }
2760           }
2761         }
2762       } else {
2763         MED::PGrilleInfo anElemInfo = theMed->GetPGrilleInfo(aMeshInfo);
2764         if(anElemInfo){
2765           TInt aNbElem = anElemInfo->GetNbCells();
2766           if(aNbElem>0 && (aMGeom == anElemInfo->GetGeom()) ){
2767             VISU::TSubMeshID aSubMeshID;
2768             for(TInt iElem = 0; iElem < aNbElem; iElem++) 
2769               if(anElemInfo->GetFamNum(iElem) == anId)
2770                 aSubMeshID.push_back(iElem);
2771             if(!aSubMeshID.empty()){
2772               VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
2773               INITMSG(MYDEBUG,"aMGeom = "<<aMGeom<<"\n");
2774               aGeom2SubMeshID.insert(VISU::TGeom2SubMeshID::value_type(aEGeom,aSubMeshID));
2775             }
2776           }
2777         }
2778       }
2779     }
2780
2781     theFamily->myIsDone = true;
2782
2783     return 1;
2784
2785 #ifndef _DEXCEPT_
2786   }catch(std::exception& exc){
2787     throw;
2788   }catch(...){
2789     EXCEPTION(std::runtime_error,"Unknown exception !!!");
2790   }
2791 #endif
2792
2793   return 0;
2794 }
2795
2796
2797 //---------------------------------------------------------------
2798 void
2799 LoadProfile(const MED::PWrapper& theMed,
2800             VISU::PMEDMesh theMesh,
2801             MED::PTimeStampValueBase theTimeStampValue,
2802             VISU::TMEDValForTime& theValForTime,
2803             VISU::TMEDMeshOnEntity& theMeshOnEntity)
2804 {
2805   VISU::TTimerLog aTimerLog(MYDEBUG,"LoadProfile");
2806   INITMSG(MYDEBUG,"LoadProfile"<<endl);
2807
2808   VISU::PMEDProfile aProfile = theValForTime.myProfile;
2809   if(aProfile->myIsDone)
2810     return;
2811
2812   const VISU::TGeom2SubProfile& aGeom2SubProfile = aProfile->myGeom2SubProfile;
2813   const MED::TGeom2Profile& aGeom2Profile = theTimeStampValue->GetGeom2Profile();
2814   MED::TGeom2Profile::const_iterator anIter = aGeom2Profile.begin();
2815   for(; anIter != aGeom2Profile.end(); anIter++){
2816     MED::PProfileInfo aProfileInfo = anIter->second;
2817     MED::EGeometrieElement aMGeom = anIter->first;
2818     VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
2819
2820     VISU::TGeom2SubProfile::const_iterator anIter2 = aGeom2SubProfile.find(aEGeom);
2821     if(anIter2 != aGeom2SubProfile.end()){
2822       VISU::PMEDSubProfile aSubProfile = anIter2->second;
2823
2824       MED::TElemNum& anElemNum = aProfileInfo->myElemNum;
2825       if(!anElemNum.empty()){
2826         VISU::TSubMeshID& aSubMeshID = aSubProfile->mySubMeshID;
2827         TInt aSize = anElemNum.size();
2828         aSubMeshID.resize(aSize);
2829         for(TInt anId = 0; anId < aSize; anId++)
2830           aSubMeshID[anId] = anElemNum[anId] - 1;
2831       }
2832
2833       INITMSG(MYDEBUG,
2834               "- aEGeom = "<<aEGeom<<
2835               "; aNbCells = "<<aSubProfile->mySubMeshID.size()<<
2836               endl);
2837     }
2838   }
2839   {
2840     const MED::PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
2841     
2842     VISU::TEntity aVEntity = theMeshOnEntity.myEntity;
2843     MED::EEntiteMaillage aMEntity = VTKEntityToMED(aVEntity);
2844     
2845     const VISU::TGeom2SubProfile& aGeom2SubProfile = aProfile->myGeom2SubProfile;
2846     VISU::TGeom2SubProfile::const_iterator anIter = aGeom2SubProfile.begin();
2847     for(; anIter != aGeom2SubProfile.end(); anIter++){
2848       const VISU::PMEDSubProfile& aSubProfile = anIter->second;
2849       MED::EGeometrieElement aMGeom = aSubProfile->myMGeom;
2850       MED::PElemInfo anElemInfo;
2851       anElemInfo = theMed->GetPElemInfo(aMeshInfo,aMEntity,aMGeom);
2852       aSubProfile->myIsElemNum = anElemInfo->IsElemNum();
2853       aSubProfile->myElemNum = anElemInfo->myElemNum;
2854     }
2855   }
2856
2857   aProfile->myIsDone = true;
2858 }
2859
2860
2861 //---------------------------------------------------------------
2862 void
2863 LoadGaussMesh(const MED::PWrapper& theMed,
2864               VISU::PMEDMesh theMesh,
2865               MED::PTimeStampValueBase theTimeStampValue,
2866               VISU::TMEDValForTime& theValForTime,
2867               VISU::TMEDMeshOnEntity& theMeshOnEntity)
2868 {
2869   VISU::TTimerLog aTimerLog(MYDEBUG,"LoadGaussMesh");
2870   INITMSG(MYDEBUG,"LoadGaussMesh"<<endl);
2871
2872   // this part of code must be reimplemented in connection with GRILLE structures
2873   if(theMesh->myMeshInfo->GetType() == MED::eSTRUCTURE)
2874     EXCEPTION(std::runtime_error,"LoadGaussMesh - Gauss Points localization error!!!");
2875   
2876   VISU::PMEDGaussMesh aGaussMesh = theValForTime.myGaussMesh;
2877   if(!aGaussMesh || aGaussMesh->myIsDone)
2878     return;
2879
2880   const MED::PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
2881   MED::PNodeInfo aNodeInfo = theMed->GetPNodeInfo(aMeshInfo);
2882
2883   VISU::TEntity aVEntity = theMeshOnEntity.myEntity;
2884   MED::EEntiteMaillage aMEntity = VTKEntityToMED(aVEntity);
2885
2886   const VISU::TGeom2GaussSubMesh& aGeom2GaussSubMesh = aGaussMesh->myGeom2GaussSubMesh;
2887   const MED::TTimeStampInfo& aTimeStampInfo = theTimeStampValue->GetTimeStampInfo();
2888   const MED::TGeom2Gauss& aGeom2Gauss = aTimeStampInfo.GetGeom2Gauss();
2889
2890   VISU::TGeom2GaussSubMesh::const_iterator aSubMeshIter = aGeom2GaussSubMesh.begin();
2891   for(; aSubMeshIter != aGeom2GaussSubMesh.end(); aSubMeshIter++){
2892     VISU::PMEDGaussSubMesh aGaussSubMesh = aSubMeshIter->second;
2893     VISU::EGeometry aEGeom = aSubMeshIter->first;
2894     
2895     if(aGaussSubMesh->myIsDone)
2896       continue;
2897
2898     VISU::PMEDSubProfile aSubProfile = aGaussSubMesh->mySubProfile;
2899     const VISU::TSubMeshID& aSubMeshID = aSubProfile->mySubMeshID;
2900     MED::EGeometrieElement aMGeom = aSubProfile->myMGeom;
2901
2902     MED::PPolygoneInfo aPolygoneInfo;
2903     MED::PPolyedreInfo aPolyedreInfo;
2904     MED::PCellInfo aCellInfo;
2905     MED::PElemInfo anElemInfo;
2906
2907     switch(aMGeom){
2908     case MED::ePOLYGONE: 
2909       aPolygoneInfo = theMed->GetPPolygoneInfo(aMeshInfo,
2910                                                aMEntity,
2911                                                aMGeom);
2912       anElemInfo = aPolygoneInfo;
2913       break;
2914     case MED::ePOLYEDRE: 
2915       aPolyedreInfo = theMed->GetPPolyedreInfo(aMeshInfo,
2916                                                aMEntity,
2917                                                aMGeom);
2918       anElemInfo = aPolyedreInfo;
2919       break;
2920     default:
2921       aCellInfo = theMed->GetPCellInfo(aMeshInfo,
2922                                        aMEntity, 
2923                                        aMGeom);
2924       anElemInfo = aCellInfo;
2925     }
2926     aGaussSubMesh->myIsElemNum = anElemInfo->IsElemNum();
2927     aGaussSubMesh->myElemNum = anElemInfo->myElemNum;
2928
2929     std::string aName;
2930     bool anIsGaussCoord3D = false;
2931     MED::PGaussCoord aGaussCoordPtr(new MED::TGaussCoord());
2932     MED::TGaussCoord& aGaussCoord = *aGaussCoordPtr;
2933
2934     MED::TGeom2Gauss::const_iterator aGaussIter = aGeom2Gauss.find(aMGeom);
2935     if(aGaussIter != aGeom2Gauss.end()){
2936       VISU::PMEDGauss aGauss = aGaussSubMesh->myGauss;
2937       MED::PGaussInfo aGaussInfo = aGauss->myGaussInfo;
2938       if(aGaussInfo){
2939         aName = aGaussInfo->GetName();
2940         if(!aSubMeshID.empty()){
2941           const std::string& aProfileName = aSubProfile->myName;
2942           MED::PProfileInfo aProfileInfo = MED::GetProfileInfo(theMed,
2943                                                                aProfileName);
2944           if(aProfileInfo){
2945             const MED::TElemNum& anElemNum = aProfileInfo->myElemNum;
2946             anIsGaussCoord3D = MED::GetGaussCoord3D(aGaussInfo,
2947                                                     aCellInfo,
2948                                                     aNodeInfo,
2949                                                     aGaussCoord,
2950                                                     anElemNum);
2951           }
2952         }else
2953           anIsGaussCoord3D = MED::GetGaussCoord3D(aGaussInfo,
2954                                                   aCellInfo,
2955                                                   aNodeInfo,
2956                                                   aGaussCoord);
2957       }
2958     }else{
2959       if(!aSubMeshID.empty()){
2960         const std::string& aProfileName = aSubProfile->myName;
2961         MED::PProfileInfo aProfileInfo = MED::GetProfileInfo(theMed,
2962                                                              aProfileName);
2963         if(aProfileInfo){
2964           const MED::TElemNum& anElemNum = aProfileInfo->myElemNum;
2965           switch(aMGeom){
2966           case MED::ePOLYGONE: 
2967             anIsGaussCoord3D = MED::GetBaryCenter(aPolygoneInfo,
2968                                                   aNodeInfo,
2969                                                   aGaussCoord,
2970                                                   anElemNum);
2971             break;
2972           case MED::ePOLYEDRE: 
2973             anIsGaussCoord3D = MED::GetBaryCenter(aPolyedreInfo,
2974                                                   aNodeInfo,
2975                                                   aGaussCoord,
2976                                                   anElemNum);
2977             break;
2978           default:
2979             anIsGaussCoord3D = MED::GetBaryCenter(aCellInfo,
2980                                                   aNodeInfo,
2981                                                   aGaussCoord,
2982                                                   anElemNum);
2983           }
2984         }
2985       }else
2986         switch(aMGeom){
2987         case MED::ePOLYGONE: 
2988           anIsGaussCoord3D = MED::GetBaryCenter(aPolygoneInfo,
2989                                                 aNodeInfo,
2990                                                 aGaussCoord);
2991           break;
2992         case MED::ePOLYEDRE: 
2993           anIsGaussCoord3D = MED::GetBaryCenter(aPolyedreInfo,
2994                                                 aNodeInfo,
2995                                                 aGaussCoord);
2996           break;
2997         default:
2998           anIsGaussCoord3D = MED::GetBaryCenter(aCellInfo,
2999                                                 aNodeInfo,
3000                                                 aGaussCoord);
3001         }
3002     }
3003     
3004     if(anIsGaussCoord3D){
3005       VISU::TPointCoords& aCoords = aGaussSubMesh->myPointCoords;
3006       VISU::TMEDGaussCoordHolder* aCoordHolder = new VISU::TMEDGaussCoordHolder();
3007       aCoordHolder->Init(aGaussCoordPtr);
3008       aCoords.Init(VISU::PCoordHolder(aCoordHolder));
3009       
3010       aGaussSubMesh->myIsDone = true;
3011       
3012       TInt aNbGauss = aGaussCoord.GetNbGauss();
3013       TInt aNbElem = aGaussCoord.GetNbElem();
3014       TInt aNbCells = aNbElem*aNbGauss;
3015
3016       INITMSG(MYDEBUG,
3017               "- aEGeom = "<<aEGeom<<
3018               "; aName = '"<<aName<<"'"<<
3019               "; aStatus = "<<aGaussSubMesh->myStatus<<
3020               "; aNbElem = "<<aNbElem<<
3021               "; aNbGauss = "<<aNbGauss<<
3022               "; aNbCells = "<<aNbCells<<
3023               endl);
3024     }else
3025       EXCEPTION(std::runtime_error,"LoadGaussMesh - Gauss Points localization error!!!");
3026   }
3027   
3028   aGaussMesh->myIsDone = true;
3029 }
3030
3031
3032 //---------------------------------------------------------------
3033 template<class TimeStampValueType>
3034 void
3035 FillValForTime(MED::SharedPtr<TimeStampValueType> theTimeStampValue,
3036                const VISU::TGeom2SubProfile& theGeom2SubProfile,
3037                VISU::PMEDValForTime theValForTime,
3038                VISU::PMEDField theField)
3039 {
3040   if(theValForTime->myIsFilled) 
3041     return;
3042   theField->myDataSize = 0;
3043   TInt aNbComp = theField->myNbComp;
3044
3045   VISU::TGeom2SubProfile::const_iterator anIter = theGeom2SubProfile.begin();
3046   for(; anIter != theGeom2SubProfile.end(); anIter++) {
3047     VISU::EGeometry aEGeom = anIter->first;
3048     VISU::PMEDSubProfile aSubProfile(anIter->second);
3049
3050     TInt aNbElem = aSubProfile->myNbCells;
3051     theField->myDataSize += aNbElem * aNbComp;
3052
3053     if(aSubProfile->myStatus != VISU::eRemoveAll){
3054       TInt aNbGauss = theValForTime->GetNbGauss(aEGeom);
3055
3056       INITMSG(MYDEBUG,
3057               "- aEGeom = "<<aEGeom<<
3058               "; aNbElem = "<<aNbElem<<
3059               "; aNbGauss = "<<aNbGauss<<
3060               endl);
3061       
3062       VISU::PMeshValue& aVMeshValue = theValForTime->GetMeshValue(aEGeom);
3063       typedef typename TimeStampValueType::TElement TElement;
3064       typedef VISU::TTMEDMeshValue<TElement> TVMeshValue;
3065       TVMeshValue* aMeshValue = new TVMeshValue();
3066
3067       MED::EGeometrieElement aMGeom = aSubProfile->myMGeom;
3068       typedef typename TimeStampValueType::PTMeshValue PTMeshValue;
3069       PTMeshValue aMeshValuePtr = theTimeStampValue->GetMeshValuePtr(aMGeom);
3070       aMeshValue->Init(aNbElem, aNbGauss, aNbComp, aMeshValuePtr);
3071       aVMeshValue.reset(aMeshValue);
3072     }
3073   }
3074   theValForTime->myIsFilled = true;
3075 }
3076
3077 //---------------------------------------------------------------
3078 int 
3079 LoadValForTime(const MED::PWrapper& theMed,
3080                VISU::PMEDMesh theMesh,
3081                VISU::PMEDMeshOnEntity theMeshOnEntity,
3082                VISU::PMEDField theField, 
3083                VISU::PMEDValForTime theValForTime,
3084                bool theIsGauss,
3085                bool& theIsDone)
3086 {
3087   VISU::TTimerLog aTimerLog(MYDEBUG,"LoadValForTime");
3088   INITMSG(MYDEBUG,"LoadValForTime - theIsGauss = "<<theIsGauss<<endl);
3089
3090   //Check on loading already done
3091   if(theIsDone) 
3092     return 0;
3093
3094   //Main part of code
3095   const std::string& aMeshName = theMeshOnEntity->myMeshName;
3096   const MED::PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
3097   MED::PFieldInfo aFieldInfo = theMed->GetPFieldInfo(aMeshInfo,
3098                                                      theField->myId);
3099
3100   MED::TGeom2Size aGeom2Size;
3101   MED::EEntiteMaillage aMEntity;
3102   theMed->GetNbTimeStamps(aFieldInfo,
3103                           theMesh->myEntityInfo,
3104                           aMEntity,
3105                           aGeom2Size);
3106
3107   MED::PTimeStampInfo aTimeStampInfo = 
3108     theMed->GetPTimeStampInfo(aFieldInfo,
3109                               aMEntity,
3110                               aGeom2Size,
3111                               theValForTime->myId);
3112
3113   MED::TKey2Gauss aKey2Gauss = GetKey2Gauss(theMed);
3114   MED::TMKey2Profile aMKey2Profile = GetMKey2Profile(theMed);
3115
3116   MED::PTimeStampValueBase aTimeStampValue = 
3117     theMed->GetPTimeStampValue(aTimeStampInfo,
3118                                aMKey2Profile,
3119                                aKey2Gauss);
3120   
3121   InitProfile(theMed,
3122               aMeshInfo,
3123               aTimeStampValue,
3124               theMeshOnEntity,
3125               aMEntity,
3126               aGeom2Size,
3127               theValForTime);
3128
3129   LoadProfile(theMed,
3130               theMesh,
3131               aTimeStampValue,
3132               theValForTime,
3133               theMeshOnEntity);
3134   
3135   if(theIsGauss) {
3136     InitGaussMesh(aTimeStampValue,
3137                   theMeshOnEntity,
3138                   aGeom2Size,
3139                   theValForTime);
3140
3141     LoadGaussMesh(theMed,
3142                   theMesh,
3143                   aTimeStampValue,
3144                   theValForTime,
3145                   theMeshOnEntity);
3146   }
3147   
3148   VISU::PMEDProfile aProfile = theValForTime->myProfile;
3149   VISU::TGeom2SubProfile& aGeom2SubProfile = aProfile->myGeom2SubProfile;
3150
3151   INITMSGA(MYDEBUG,0,
3152            "- aMeshName = '"<<aMeshName<<"'"<<
3153            "; aFieldName = '"<<aFieldInfo->GetName()<<"'"<<
3154            "; aMEntity = "<<aMEntity<<
3155            "; aNbComp = "<<theField->myNbComp<<
3156            endl);
3157
3158   if(aFieldInfo->GetType() == MED::eFLOAT64)
3159     FillValForTime<MED::TFloatTimeStampValue>(CastToFloatTimeStampValue(aTimeStampValue),
3160                                               aGeom2SubProfile,
3161                                               theValForTime,
3162                                               theField);
3163   else
3164     FillValForTime<MED::TIntTimeStampValue>(CastToIntTimeStampValue(aTimeStampValue),
3165                                             aGeom2SubProfile,
3166                                             theValForTime,
3167                                             theField);
3168   theIsDone = true;
3169
3170   return 1; 
3171 }
3172
3173
3174 //---------------------------------------------------------------
3175 int 
3176 VISU_MedConvertor
3177 ::LoadValForTimeOnMesh(const MED::PWrapper& theMed,
3178                        VISU::PMEDMesh theMesh,
3179                        VISU::PMEDMeshOnEntity theMeshOnEntity,
3180                        VISU::PMEDField theField, 
3181                        VISU::PMEDValForTime theValForTime)
3182 {
3183   VISU::PUnstructuredGridIDMapperImpl anUnstructuredGridIDMapper = theValForTime->myUnstructuredGridIDMapper;
3184   return LoadValForTime(theMed,
3185                         theMesh,
3186                         theMeshOnEntity,
3187                         theField,
3188                         theValForTime,
3189                         false,
3190                         anUnstructuredGridIDMapper->myIsVTKDone);
3191 }
3192
3193
3194 //---------------------------------------------------------------
3195 int 
3196 VISU_MedConvertor
3197 ::LoadValForTimeOnGaussPts(const MED::PWrapper& theMed,
3198                            VISU::PMEDMesh theMesh,
3199                            VISU::PMEDMeshOnEntity theMeshOnEntity,
3200                            VISU::PMEDField theField, 
3201                            VISU::PMEDValForTime theValForTime)
3202 {
3203   VISU::PGaussPtsIDFilter aGaussPtsIDFilter = theValForTime->myGaussPtsIDFilter;
3204   return LoadValForTime(theMed,
3205                         theMesh,
3206                         theMeshOnEntity,
3207                         theField,
3208                         theValForTime,
3209                         true,
3210                         aGaussPtsIDFilter->myIsVTKDone);
3211 }