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