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