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