Salome HOME
Merge from OCC_development_generic_2006
[modules/visu.git] / src / CONVERTOR / VISU_MedConvertor.cxx
1 //  VISU OBJECT : interactive object for VISU entities implementation
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //  File   : VISU_MedConvertor.cxx
24 //  Author : Alexey PETROV
25 //  Module : VISU
26
27
28 #include "VISU_MedConvertor.hxx"
29 #include "VISU_Convertor.hxx"
30 #include "VISU_ConvertorUtils.hxx"
31
32 #include "MED_Factory.hxx"
33 #include "MED_Algorithm.hxx"
34 #include "MED_GaussUtils.hxx"
35 #include "MED_Utilities.hxx"
36
37 #include <boost/thread/thread.hpp>
38 #include <boost/bind.hpp>
39
40 #include <vtkCellType.h>
41
42 using namespace std;
43 using namespace VISU;
44
45 using MED::TInt;
46 using MED::TFloat;
47 using MED::EBooleen;
48
49 #ifdef _DEBUG_
50 static int MYDEBUG = 0;
51 static int MYVALUEDEBUG = 0;
52 static int MY_FAMILY_DEBUG = 0;
53 static int MY_GROUP_DEBUG = 0;
54 //#define _DEXCEPT_
55 #else
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 #endif
61
62 #define _LOAD_FAMILIES_
63 #define _EDF_NODE_IDS_
64
65 namespace
66 {
67   //---------------------------------------------------------------
68   vtkIdType
69   MEDGeom2NbNodes(MED::EGeometrieElement theMEDGeomType)
70   { 
71     return theMEDGeomType % 100;
72   }
73
74
75   //---------------------------------------------------------------
76   VISU::EGeometry
77   MEDGeom2VISU(MED::EGeometrieElement theGeom)
78   { 
79     switch(theGeom){
80     case MED::ePOINT1: return VISU::ePOINT1;
81     case MED::eSEG2: return VISU::eSEG2;
82     case MED::eTRIA3: return VISU::eTRIA3;
83     case MED::eQUAD4: return VISU::eQUAD4;
84     case MED::eTETRA4: return VISU::eTETRA4;
85     case MED::eHEXA8: return VISU::eHEXA8;
86     case MED::ePENTA6: return VISU::ePENTA6;
87     case MED::ePYRA5: return VISU::ePYRA5;
88
89     case MED::eSEG3: return VISU::eSEG3;
90     case MED::eTRIA6: return VISU::eTRIA6;
91     case MED::eQUAD8: return VISU::eQUAD8;
92     case MED::eTETRA10: return VISU::eTETRA10;
93     case MED::eHEXA20: return VISU::eHEXA20;
94     case MED::ePENTA15: return VISU::ePENTA15;
95     case MED::ePYRA13: return VISU::ePYRA13;
96
97     case MED::ePOLYGONE: return VISU::ePOLYGONE;
98     case MED::ePOLYEDRE: return VISU::ePOLYEDRE;
99     }
100     return VISU::eNONE;
101   }
102
103
104   //---------------------------------------------------------------
105   MED::EGeometrieElement 
106   VISUGeom2MED(int theGeom)
107   { 
108     switch(theGeom){
109     case VISU::ePOINT1: return MED::ePOINT1;
110     case VISU::eSEG2: return MED::eSEG2;
111     case VISU::eTRIA3: return MED::eTRIA3;
112     case VISU::eQUAD4: return MED::eQUAD4;
113     case VISU::eTETRA4: return MED::eTETRA4;
114     case VISU::eHEXA8: return MED::eHEXA8;
115     case VISU::ePENTA6: return MED::ePENTA6;
116     case VISU::ePYRA5: return MED::ePYRA5;
117
118     case VISU::eSEG3: return MED::eSEG3;
119     case VISU::eTRIA6: return MED::eTRIA6;
120     case VISU::eQUAD8: return MED::eQUAD8;
121     case VISU::eTETRA10: return MED::eTETRA10;
122     case VISU::eHEXA20: return MED::eHEXA20;
123     case VISU::ePENTA15: return MED::ePENTA15;
124     case VISU::ePYRA13: return MED::ePYRA13;
125
126     case VISU::ePOLYGONE: return MED::ePOLYGONE;
127     case VISU::ePOLYEDRE: return MED::ePOLYEDRE;
128     }
129     return MED::EGeometrieElement(-1);
130   }
131
132
133   //---------------------------------------------------------------
134   VISU::TEntity
135   MEDEntityToVTK(MED::EEntiteMaillage theMEDEntity)
136   {
137     switch(theMEDEntity){
138     case MED::eNOEUD: return NODE_ENTITY;
139     case MED::eARETE: return EDGE_ENTITY;
140     case MED::eFACE: return FACE_ENTITY;
141     case MED::eMAILLE: return CELL_ENTITY;
142     }
143     return VISU::TEntity(-1);
144   }
145
146
147   //---------------------------------------------------------------
148   MED::EEntiteMaillage 
149   VTKEntityToMED(TEntity theVTKEntity)
150   {
151     switch(theVTKEntity){
152     case NODE_ENTITY: return MED::eNOEUD;
153     case EDGE_ENTITY: return MED::eARETE;
154     case FACE_ENTITY: return MED::eFACE;
155     case CELL_ENTITY: return MED::eMAILLE;
156     }
157     return MED::EEntiteMaillage(-1);
158   }
159
160
161   //---------------------------------------------------------------
162   PMEDSubProfile
163   CrSubProfile(const MED::PWrapper& theMEDWrapper,
164                const MED::PMeshInfo& theMeshInfo,
165                MED::EEntiteMaillage theMEntity,
166                MED::EGeometrieElement theMGeom,
167                const MED::TGeom2Size& theGeom2Size,
168                const MED::TGeom2Profile& theGeom2Profile)
169   {
170     VISU::EGeometry aEGeom = MEDGeom2VISU(theMGeom);
171     vtkIdType aVNbNodes = VISUGeom2NbNodes(aEGeom);
172
173     PMEDSubProfile aSubProfile(new TMEDSubProfile());
174     aSubProfile->myGeom = aEGeom;
175     aSubProfile->myMGeom = theMGeom;
176     aSubProfile->myStatus = eAddAll;
177
178     MED::TGeom2Size::const_iterator aTimeStampIter = theGeom2Size.find(theMGeom);
179     if(aTimeStampIter == theGeom2Size.end())
180       aSubProfile->myStatus = eRemoveAll;
181     else{
182       MED::TGeom2Profile::const_iterator aProfileIter = theGeom2Profile.find(theMGeom);
183       if(aProfileIter != theGeom2Profile.end()){
184         MED::PProfileInfo aProfileInfo = aProfileIter->second;
185
186         aSubProfile->myName = aProfileInfo->GetName();
187         aSubProfile->myStatus = eAddPart;
188
189         const MED::TElemNum& anElemNum = aProfileInfo->myElemNum;
190         TInt aNbElem = anElemNum.size();
191         aSubProfile->myNbCells = aNbElem;
192         switch(theMGeom){
193         case MED::ePOLYGONE: {
194           MED::PPolygoneInfo aPolygoneInfo = 
195             theMEDWrapper->GetPPolygoneInfo(theMeshInfo,theMEntity,theMGeom);
196           for(TInt anElemId = 0; anElemId < aNbElem ; anElemId++){
197             TInt aNbConn = aPolygoneInfo->GetNbConn(anElemNum[anElemId]);
198             aSubProfile->myCellsSize += aNbConn;
199           }
200           break;
201         }
202         case MED::ePOLYEDRE: {
203           MED::PPolyedreInfo aPolyedreInfo = 
204             theMEDWrapper->GetPPolyedreInfo(theMeshInfo,theMEntity,theMGeom);
205           for(TInt anElemId = 0; anElemId < aNbElem ; anElemId++){
206             MED::TCConnSliceArr aConnSliceArr = 
207               aPolyedreInfo->GetConnSliceArr(anElemNum[anElemId]);
208             TInt aNbFaces = aConnSliceArr.size();
209             TInt aCellSize = 0;
210             for(TInt iFace = 0; iFace < aNbFaces; iFace++){
211               MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
212               TInt aNbConn = aConnSlice.size();
213               aCellSize += aNbConn;
214             }
215             aSubProfile->myCellsSize += aCellSize;
216           }
217           break;
218         }
219         default: {
220           aSubProfile->myCellsSize = aSubProfile->myNbCells*aVNbNodes;
221         }}
222       }else{
223         TInt aNbElem = aTimeStampIter->second;
224         aSubProfile->myNbCells = aNbElem;
225         switch(theMGeom){
226         case MED::ePOLYGONE: {
227           MED::PPolygoneInfo aPolygoneInfo = 
228             theMEDWrapper->GetPPolygoneInfo(theMeshInfo,theMEntity,theMGeom);
229           for(TInt anElemId = 0; anElemId < aNbElem ; anElemId++){
230             TInt aNbConn = aPolygoneInfo->GetNbConn(anElemId);
231             aSubProfile->myCellsSize += aNbConn;
232           }
233           break;
234         }
235         case MED::ePOLYEDRE: {
236           MED::PPolyedreInfo aPolyedreInfo = 
237             theMEDWrapper->GetPPolyedreInfo(theMeshInfo,theMEntity,theMGeom);
238           for(TInt anElemId = 0; anElemId < aNbElem ; anElemId++){
239             MED::TCConnSliceArr aConnSliceArr = 
240               aPolyedreInfo->GetConnSliceArr(anElemId);
241             TInt aNbFaces = aConnSliceArr.size();
242             TInt aCellSize = 0;
243             for(TInt iFace = 0; iFace < aNbFaces; iFace++){
244               MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
245               TInt aNbConn = aConnSlice.size();
246               aCellSize += aNbConn;
247             }
248             aSubProfile->myCellsSize += aCellSize;
249           }
250           break;
251         }
252         default: {
253           aSubProfile->myCellsSize = aSubProfile->myNbCells*aVNbNodes;
254         }}
255       }
256     }
257     INITMSG(MYDEBUG,
258             "- aMGeom = "<<theMGeom<<
259             "; aEGeom = "<<aEGeom<<
260             "; aName = '"<<aSubProfile->myName<<"'"<<
261             "; aStatus = "<<aSubProfile->myStatus<<
262             "; aNbCells = "<<aSubProfile->myNbCells<<
263             "; aCellsSize = "<<aSubProfile->myCellsSize<<
264             endl);
265     
266     return aSubProfile;
267   }
268
269
270   //---------------------------------------------------------------
271   TProfileKey
272   GetProfileKey(const MED::PWrapper& theMEDWrapper,
273                 const MED::PMeshInfo& theMeshInfo,
274                 const MED::TTimeStampVal& theTimeStampVal,
275                 const VISU::TMEDMeshOnEntity& theMeshOnEntity,
276                 MED::EEntiteMaillage theMEntity,
277                 const MED::TGeom2Size& theGeom2Size)
278   {
279     INITMSG(MYDEBUG,"GetProfileKey"<<endl);
280     
281     TProfileKey aProfileKey;
282     const MED::TGeom2Profile& aGeom2Profile = theTimeStampVal.GetGeom2Profile();
283
284     const MED::TGeom2Size& aGeom2Size = theMeshOnEntity.myGeom2Size;
285     MED::TGeom2Size::const_iterator anIter = aGeom2Size.begin();
286     for(; anIter != aGeom2Size.end(); anIter++){
287       MED::EGeometrieElement aMGeom = anIter->first;
288       PSubProfile aSubProfile = CrSubProfile(theMEDWrapper,
289                                              theMeshInfo,
290                                              theMEntity,
291                                              aMGeom,
292                                              theGeom2Size,
293                                              aGeom2Profile);
294       aProfileKey.insert(aSubProfile);
295     }
296     
297     return aProfileKey;
298   }
299   
300
301   //---------------------------------------------------------------
302   void
303   InitProfile(const MED::PWrapper& theMEDWrapper,
304               const MED::PMeshInfo& theMeshInfo,
305               MED::TTimeStampVal& theTimeStampVal,
306               VISU::TMEDMeshOnEntity& theMeshOnEntity,
307               MED::EEntiteMaillage theMEntity,
308               const MED::TGeom2Size& theGeom2Size,
309               VISU::TMEDValForTime& theValForTime)
310   {
311     TTimerLog aTimerLog(MYDEBUG,"InitProfile");
312     INITMSG(MYDEBUG,"InitProfile"<<endl);
313     
314     TProfileMap& aProfileMap = theMeshOnEntity.myProfileMap;
315     
316     TProfileKey aProfileKey = GetProfileKey(theMEDWrapper,
317                                             theMeshInfo,
318                                             theTimeStampVal,
319                                             theMeshOnEntity,
320                                             theMEntity,
321                                             theGeom2Size);
322     
323     TProfileMap::const_iterator anIter = aProfileMap.find(aProfileKey);
324     if(anIter != aProfileMap.end()){
325       theValForTime.myProfile = anIter->second;
326       INITMSG(MYDEBUG,"aProfileMap.find(aProfileKey)"<<endl);
327     }else{
328       PMEDProfile aProfile(new TMEDProfile());
329       TGeom2SubProfile& aGeom2SubProfile = aProfile->myGeom2SubProfile;
330       
331       TProfileKey::const_iterator anIter = aProfileKey.begin();
332       for(; anIter != aProfileKey.end(); anIter++){
333         PMEDSubProfile aSubProfile(*anIter);
334
335         if(aProfile->myIsAll && aSubProfile->myStatus != eAddAll)
336           aProfile->myIsAll = false;
337
338         VISU::EGeometry aEGeom = aSubProfile->myGeom;
339         aGeom2SubProfile[aEGeom] = aSubProfile;
340       }
341
342       aProfileMap[aProfileKey] = aProfile;
343       theValForTime.myProfile = aProfile;
344     }
345   }
346
347
348   //---------------------------------------------------------------
349   TGaussKey
350   GetGaussKey(const MED::TTimeStampVal& theTimeStampVal,
351               const VISU::TMEDMeshOnEntity& theMeshOnEntity,
352               const MED::TGeom2Size& theGeom2Size,
353               VISU::TMEDValForTime& theValForTime)
354   {
355     TTimerLog aTimerLog(MYDEBUG,"GetGaussKey");
356     INITMSG(MYDEBUG,"GetGaussKey"<<endl);
357
358     TGaussKey aGaussKey;
359     PMEDProfile aProfile = theValForTime.myProfile;
360     TGeom2SubProfile& aGeom2SubProfile = aProfile->myGeom2SubProfile;
361
362     const MED::TTimeStampInfo& aTimeStampInfo = theTimeStampVal.GetTimeStampInfo();
363     const MED::TGeom2Gauss& aGeom2Gauss = aTimeStampInfo.GetGeom2Gauss();
364
365     const MED::TGeom2Size& aGeom2Size = theMeshOnEntity.myGeom2Size;
366     MED::TGeom2Size::const_iterator anIter = aGeom2Size.begin();
367     for(; anIter != aGeom2Size.end(); anIter++){
368       MED::EGeometrieElement aMGeom = anIter->first;
369       VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
370
371       TGeom2SubProfile::iterator anIter2 = aGeom2SubProfile.find(aEGeom);
372       if(anIter2 == aGeom2SubProfile.end()){
373         INITMSG(MYDEBUG,"anIter2 == aGeom2SubProfile.end!!"<<endl);
374         continue;
375       }
376       PMEDSubProfile aSubProfile = anIter2->second;
377
378       MED::TGeom2Size::const_iterator aTimeStampIter = theGeom2Size.find(aMGeom);
379       if(aTimeStampIter != theGeom2Size.end()){
380         TInt aNbCells = aTimeStampIter->second;
381         if(aSubProfile->myStatus == eAddPart)
382           aNbCells = aSubProfile->myNbCells;
383
384         PMEDGaussSubMesh aGaussSubMesh(new TMEDGaussSubMesh());
385         aGaussSubMesh->mySubProfile = aSubProfile;
386         aGaussSubMesh->myStatus = aSubProfile->myStatus;
387           
388         PMEDGauss aGauss(new TMEDGauss());
389         aGaussSubMesh->myGauss = aGauss;
390         aGauss->myGeom = aEGeom;
391         aGauss->myNbPoints = 1;
392
393         MED::TGeom2Gauss::const_iterator aGaussIter = aGeom2Gauss.find(aMGeom);
394         if(aGaussIter != aGeom2Gauss.end()){
395           MED::PGaussInfo aGaussInfo = aGaussIter->second;
396           aGauss->myGaussInfo = aGaussInfo;
397           aGauss->myName = aGaussInfo->GetName();
398           aGauss->myNbPoints = aGaussInfo->GetNbGauss();
399         }
400         
401         aGaussSubMesh->myNbCells = aNbCells*aGauss->myNbPoints;
402         aGaussSubMesh->myCellsSize = aGaussSubMesh->myNbCells*2;
403
404         aGaussKey.insert(aGaussSubMesh);
405
406         INITMSGA(MYDEBUG,0,
407                  "- aEGeom = "<<aGauss->myGeom<<
408                  "; aName = '"<<aGauss->myName<<"'"<<
409                  "; aNbGauss = "<<aGauss->myNbPoints<<
410                  "; aStatus = "<<aGaussSubMesh->myStatus<<
411                  "; aNbCells = "<<aGaussSubMesh->myNbCells<<
412                  "; aCellsSize = "<<aGaussSubMesh->myCellsSize<<
413                  endl);
414       }
415     }
416
417     return aGaussKey;
418   }
419
420
421   //---------------------------------------------------------------
422   void
423   InitGaussMesh(MED::TTimeStampVal& theTimeStampVal,
424                 VISU::TMEDMeshOnEntity& theMeshOnEntity,
425                 const MED::TGeom2Size& theGeom2Size,
426                 VISU::TMEDValForTime& theValForTime)
427   {
428     TTimerLog aTimerLog(MYDEBUG,"InitGaussMesh");
429     INITMSG(MYDEBUG,"InitGaussMesh"<<endl);
430
431     if(theMeshOnEntity.myEntity == NODE_ENTITY)
432       return;
433
434     TGaussMeshMap& aGaussMeshMap = theMeshOnEntity.myGaussMeshMap;
435     
436     TGaussKey aGaussKey = GetGaussKey(theTimeStampVal,
437                                       theMeshOnEntity,
438                                       theGeom2Size,
439                                       theValForTime);
440
441     TGaussMeshMap::const_iterator anIter = aGaussMeshMap.find(aGaussKey);
442     if(anIter != aGaussMeshMap.end()){
443       theValForTime.myGaussMesh = anIter->second;
444       INITMSG(MYDEBUG,"aGaussMeshMap.find(aGaussKey)"<<endl);
445     }else{
446       PMEDGaussMesh aGaussMesh(new TMEDGaussMesh());
447       TGeom2GaussSubMesh& aGeom2GaussSubMesh = aGaussMesh->myGeom2GaussSubMesh;
448       {
449         TGaussKey::const_iterator anIter = aGaussKey.begin();
450         for(; anIter != aGaussKey.end(); anIter++){
451           PMEDGaussSubMesh aGaussSubMesh(*anIter);
452           PMEDGauss aGauss = aGaussSubMesh->myGauss;
453           VISU::EGeometry aEGeom = aGauss->myGeom;
454           aGeom2GaussSubMesh[aEGeom] = aGaussSubMesh;
455         }
456       }
457       {
458         TGaussSubMeshArr& aGaussSubMeshArr = aGaussMesh->myGaussSubMeshArr;
459         aGaussSubMeshArr.resize(aGeom2GaussSubMesh.size());
460         TGeom2GaussSubMesh::const_iterator anIter = aGeom2GaussSubMesh.begin();
461         for(TInt anID = 0; anIter != aGeom2GaussSubMesh.end(); anIter++, anID++){
462           const PGaussSubMeshImpl& aGaussSubMesh = anIter->second;
463           aGaussSubMeshArr[anID] = aGaussSubMesh;
464         }
465       }
466       INITMSG(MYDEBUG,"aGaussMeshMap[aGaussKey] = aGaussMesh"<<endl);
467       aGaussMeshMap[aGaussKey] = aGaussMesh;
468       theValForTime.myGaussMesh = aGaussMesh;
469     }
470   }
471
472
473   //---------------------------------------------------------------
474   void
475   InitGaussProfile(const MED::PWrapper& theMEDWrapper,
476                    const MED::PMeshInfo& theMeshInfo,
477                    MED::TTimeStampVal& theTimeStampVal,
478                    VISU::TMEDMeshOnEntity& theMeshOnEntity,
479                    MED::EEntiteMaillage theMEntity,
480                    const MED::TGeom2Size& theGeom2Size,
481                    VISU::TMEDValForTime& theValForTime)
482   {
483     TTimerLog aTimerLog(MYDEBUG,"InitGaussProfile");
484     INITMSG(MYDEBUG,"InitGaussProfile"<<endl);
485
486     // The order of the function calls is important
487     InitProfile(theMEDWrapper,
488                 theMeshInfo,
489                 theTimeStampVal,
490                 theMeshOnEntity,
491                 theMEntity,
492                 theGeom2Size,
493                 theValForTime);
494
495     InitGaussMesh(theTimeStampVal,
496                   theMeshOnEntity,
497                   theGeom2Size,
498                   theValForTime);
499   }
500
501
502   //---------------------------------------------------------------
503   void
504   BuildMeshOnEntityMap(PMEDMesh theMesh,
505                        const MED::TEntityInfo& theEntityInfo,
506                        const MED::PNodeInfo& theNodeInfo,
507                        const MED::PWrapper& theMEDWrapper)
508   {
509     TTimerLog aTimerLog(MYDEBUG,"BuildMeshOnEntityMap");
510     INITMSG(MYDEBUG,"BuildMeshOnEntityMap"<<endl);
511
512     MED::PMeshInfo aMeshInfo = theMesh->myMeshInfo;
513     const std::string& aMeshName = theMesh->myName;
514     TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap;
515     MED::TEntityInfo::const_iterator anEntityIter = theEntityInfo.begin();
516     for(; anEntityIter != theEntityInfo.end(); anEntityIter++){
517       const MED::EEntiteMaillage& aMEntity = anEntityIter->first;
518       const MED::TGeom2Size& aGeom2Size = anEntityIter->second;
519       
520       TEntity aVEntity = MEDEntityToVTK(aMEntity);
521       PMEDMeshOnEntity aMeshOnEntity = aMeshOnEntityMap[aVEntity](new TMEDMeshOnEntity());
522       aMeshOnEntity->myEntity = aVEntity;
523       aMeshOnEntity->myMeshName = aMeshName;
524       aMeshOnEntity->myGeom2Size = aGeom2Size;
525       TFamilyID2CellsSize& aFamilyID2CellsSize = aMeshOnEntity->myFamilyID2CellsSize;
526
527       INITMSG(MYDEBUG,
528               "- aMEntity = "<<aMEntity<<
529               "; aVEntity = "<<aVEntity<<
530               endl);
531       
532       if(aMEntity == MED::eNOEUD){
533         aMeshOnEntity->myNbCells = theMesh->myNbPoints;
534         aMeshOnEntity->myCellsSize = 2*theMesh->myNbPoints;
535         
536         for(TInt iElem = 0; iElem < theMesh->myNbPoints; iElem++){
537           TInt aFamId = theNodeInfo->GetFamNum(iElem);
538           if(aFamId != 0)
539             aFamilyID2CellsSize[aFamId] += 2;
540         }
541         
542         INITMSG(MYDEBUG,
543                 "- myNbCells = "<<aMeshOnEntity->myNbCells<<
544                 "; myCellsSize = "<<aMeshOnEntity->myCellsSize<<
545                 endl);;
546         
547       }else{
548         MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
549         aMeshOnEntity->myNbCells = 0;
550         aMeshOnEntity->myCellsSize = 0;
551         for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
552           const MED::EGeometrieElement& aMGeom = aGeom2SizeIter->first;
553           
554           switch(aMGeom){
555           case MED::ePOLYGONE: {
556             MED::PPolygoneInfo aPolygoneInfo = theMEDWrapper->GetPPolygoneInfo(aMeshInfo,aMEntity,aMGeom);
557             TInt aNbElem = aPolygoneInfo->GetNbElem();
558             
559             INITMSG(MYDEBUG,
560                     "- aMGeom = "<<aMGeom<<
561                     "; aNbElem = "<<aNbElem<<
562                     endl);
563             
564             aMeshOnEntity->myNbCells += aNbElem;      
565             for(TInt anElemId = 0; anElemId < aNbElem ; anElemId++){
566               TInt aNbConn = aPolygoneInfo->GetNbConn(anElemId);
567               aMeshOnEntity->myCellsSize += aNbConn;
568               TInt aFamId = aPolygoneInfo->GetFamNum(anElemId);
569               if(aFamId != 0)
570                 aFamilyID2CellsSize[aFamId] += aNbConn + 1;
571             }
572             break;
573           }
574           case MED::ePOLYEDRE: {
575             MED::PPolyedreInfo aPolyedreInfo = theMEDWrapper->GetPPolyedreInfo(aMeshInfo,aMEntity,aMGeom);
576             TInt aNbElem = aPolyedreInfo->GetNbElem();
577             
578             INITMSG(MYDEBUG,
579                     "- aMGeom = "<<aMGeom<<
580                     "; aNbElem = "<<aNbElem<<
581                     endl);
582             
583             aMeshOnEntity->myNbCells += aNbElem;
584             for(TInt anElemId = 0; anElemId < aNbElem ; anElemId++){
585               MED::TCConnSliceArr aConnSliceArr = aPolyedreInfo->GetConnSliceArr(anElemId);
586               TInt aNbFaces = aConnSliceArr.size();
587               TInt aCellSize = 0;
588               for(TInt iFace = 0; iFace < aNbFaces; iFace++){
589                 MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
590                 TInt aNbConn = aConnSlice.size();
591                 aCellSize += aNbConn;
592               }
593               aMeshOnEntity->myCellsSize += aCellSize;
594               TInt aFamId = aPolyedreInfo->GetFamNum(anElemId);
595               if(aFamId != 0)
596                 aFamilyID2CellsSize[aFamId] += aCellSize + 1;
597             }
598             break;
599           }
600           default: {
601             VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
602             vtkIdType aVNbNodes = VISUGeom2NbNodes(aEGeom);
603             MED::PCellInfo aCellInfo = theMEDWrapper->GetPCellInfo(aMeshInfo,aMEntity,aMGeom);
604             TInt aNbElem = aCellInfo->GetNbElem();
605             aMeshOnEntity->myNbCells += aNbElem;
606             aMeshOnEntity->myCellsSize += aNbElem*(aVNbNodes+1);
607             
608             INITMSG(MYDEBUG,
609                     "- aMGeom = "<<aMGeom<<
610                     "; aNbElem = "<<aNbElem<<
611                     "; myNbCells = "<<aMeshOnEntity->myNbCells<<
612                     "; myCellsSize = "<<aMeshOnEntity->myCellsSize<<
613                     endl);
614             
615             for(TInt iElem = 0; iElem < aNbElem; iElem++){
616               TInt aFamId = aCellInfo->GetFamNum(iElem);
617               if(aFamId != 0)
618                 aFamilyID2CellsSize[aFamId] += aVNbNodes + 1;
619             }
620           }} // end switch(...)
621         }
622       }
623     }
624   }
625
626
627   //---------------------------------------------------------------
628   void
629   BuildFieldMap(PMEDMesh theMesh,
630                 const MED::TEntityInfo& theEntityInfo,
631                 MED::PWrapper theMEDWrapper)
632   {
633     TTimerLog aTimerLog(MYDEBUG,"BuildFieldMap");
634     TInt aNbFields = theMEDWrapper->GetNbFields(); 
635     MED::PMeshInfo aMeshInfo = theMesh->myMeshInfo;
636     const std::string& aMeshName = theMesh->myName;
637     INITMSG(MYDEBUG,"BuildFieldMap: aNbFields = "<<aNbFields<<"\n");
638     for(TInt iField = 1; iField <= aNbFields; iField++){
639       TTimerLog aTimerLog(MYDEBUG,"GetPFieldInfo");
640       MED::PFieldInfo aFieldInfo = theMEDWrapper->GetPFieldInfo(aMeshInfo,iField);
641       TInt aNbComp = aFieldInfo->GetNbComp();
642       std::string aFieldName = aFieldInfo->GetName();
643       
644       MED::TGeom2Size aGeom2Size;
645       MED::EEntiteMaillage aMEntity;
646       TInt aNbTimeStamps = theMEDWrapper->GetNbTimeStamps(aFieldInfo,
647                                                           theEntityInfo,
648                                                           aMEntity,
649                                                           aGeom2Size);
650       if(aNbTimeStamps < 1)
651         continue;
652       
653       TEntity aVEntity = MEDEntityToVTK(aMEntity);
654       PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[aVEntity];
655       TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
656       PMEDField aField = aFieldMap[aFieldName](new TMEDField());
657       aField->myId = iField;
658       aField->InitArrays(aNbComp);
659       aField->myEntity = aVEntity;
660       aField->myName = aFieldName;
661       aField->myMeshName = aMeshName;
662       aField->myDataSize = aMeshOnEntity->myNbCells * aNbComp;
663       
664       INITMSG(MYDEBUG,"myName = '"<<aField->myName<<"'"<<
665               "; myId = "<<aField->myId<<
666               "; myEntity = "<<aField->myEntity<<
667               "; myDataSize = "<<aField->myDataSize<<
668               "; myNbComp = "<<aField->myNbComp<<"\n");
669       
670       for(TInt iComp = 0; iComp < aNbComp; iComp++){
671         aField->myCompNames[iComp] = aFieldInfo->GetCompName(iComp);
672         aField->myUnitNames[iComp] = aFieldInfo->GetUnitName(iComp);
673       }
674       
675       for(TInt iTimeStamp = 1; iTimeStamp <= aNbTimeStamps; iTimeStamp++){
676         TTimerLog aTimerLog(MYDEBUG,"GetPTimeStampInfo");
677         MED::PTimeStampInfo aTimeStampInfo = theMEDWrapper->GetPTimeStampInfo(aFieldInfo,
678                                                                               aMEntity,
679                                                                               aGeom2Size,
680                                                                               iTimeStamp);
681         TFloat aDt = aTimeStampInfo->GetDt();
682         std::string anUnitDt = aTimeStampInfo->GetUnitDt();
683
684         TValField& aValField = aField->myValField;
685         PMEDValForTime aValForTime = aValField[iTimeStamp](new TMEDValForTime());
686         aValForTime->myId = iTimeStamp;
687         aValForTime->myFieldName = aField->myName;
688         aValForTime->myEntity = aField->myEntity;
689         aValForTime->myMeshName = aField->myMeshName;
690         aValForTime->myTime = VISU::TTime(aDt,anUnitDt);
691         INITMSG(MYDEBUG,"aDt = '"<<aDt<<", "<<anUnitDt<<"'\n");
692         
693         TGeom2NbGauss& aVGeom2NbGauss = aValForTime->myGeom2NbGauss;
694         const MED::TGeom2NbGauss& aMGeom2NbGauss = aTimeStampInfo->myGeom2NbGauss;
695         MED::TGeom2NbGauss::const_iterator anIter = aMGeom2NbGauss.begin();
696         for(; anIter != aMGeom2NbGauss.end(); anIter++){
697           const MED::EGeometrieElement& aMGeom = anIter->first;
698           EGeometry aEGeom = MEDGeom2VISU(aMGeom);
699           TInt aNbGauss = anIter->second;
700           aVGeom2NbGauss[aEGeom] = aNbGauss;
701         }
702       }
703     }
704   }
705
706
707   //---------------------------------------------------------------
708   void
709   BuildFamilyMap(PMEDMesh theMesh,
710                  const MED::TEntityInfo& theEntityInfo,
711                  const MED::TEntity2TGeom2ElemInfo& theEntity2TGeom2ElemInfo,
712                  const MED::TFamilyInfoSet& theFamilyInfoSet,
713                  MED::PWrapper theMEDWrapper)
714   {
715     TTimerLog aTimerLog(MYDEBUG,"BuildFamilyMap");
716     INITMSG(MYDEBUG,"BuildFamilyMap\n");
717
718     MED::PMeshInfo aMeshInfo = theMesh->myMeshInfo;
719     MED::TEntity2FamilySet aEntity2FamilySet = MED::GetEntity2FamilySet(theMEDWrapper,theEntity2TGeom2ElemInfo,theFamilyInfoSet);
720     MED::TEntity2FamilySet::const_iterator aEntity2FamilySetIter = aEntity2FamilySet.begin();
721     for(; aEntity2FamilySetIter != aEntity2FamilySet.end(); aEntity2FamilySetIter++){
722       const MED::EEntiteMaillage& aMEntity = aEntity2FamilySetIter->first;
723       const MED::TFamilyTSizeSet& aFamilyTSizeSet = aEntity2FamilySetIter->second;
724       
725       TEntity aVEntity = MEDEntityToVTK(aMEntity);
726       PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[aVEntity];
727       const TFamilyID2CellsSize& aFamilyID2CellsSize = aMeshOnEntity->myFamilyID2CellsSize;
728       TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
729         
730       if(aFamilyTSizeSet.empty())
731         continue;
732         
733       INITMSG(MY_FAMILY_DEBUG,
734               "- aMEntity = "<<aMEntity<<
735               "; aVEntity = "<<aVEntity<<
736               endl);
737
738       MED::TFamilyTSizeSet::const_iterator aFamilyTSizeSetIter = aFamilyTSizeSet.begin();
739       for(; aFamilyTSizeSetIter != aFamilyTSizeSet.end(); aFamilyTSizeSetIter++){
740         const MED::TFamilyTSize& aFamilyTSize = *aFamilyTSizeSetIter;
741         const MED::PFamilyInfo& aFamilyInfo = boost::get<0>(aFamilyTSize);
742         TInt aSize = boost::get<1>(aFamilyTSize);
743         TInt anId = aFamilyInfo->GetId();
744         if(anId == 0) 
745           continue;
746         
747         std::string aFamilyName = aFamilyInfo->GetName();
748
749         PMEDFamily aFamily = aFamilyMap[aFamilyName](new TMEDFamily());
750         aFamily->myId = anId;
751         aFamily->myEntity = aVEntity;
752         aFamily->myName = aFamilyName;
753         aFamily->myNbCells = aSize;
754
755         aFamily->myCellsSize = 0;
756         TFamilyID2CellsSize::const_iterator anIter = aFamilyID2CellsSize.find(anId);
757         if(anIter != aFamilyID2CellsSize.end())
758           aFamily->myCellsSize = anIter->second;
759         
760         INITMSG(MY_FAMILY_DEBUG,
761                 "- aFamilyName = '"<<aFamilyName<<"'"<<
762                 "; myId = "<<aFamily->myId<<"; "<<
763                 "; aNbAttr = "<<aFamilyInfo->GetNbAttr()<<
764                 "; aNbGroup = "<<aFamilyInfo->GetNbGroup()<<
765                 "; aVEntity = "<<aVEntity<<
766                 "; myNbCells = "<<aFamily->myNbCells<<
767                 "; myCellsSize = "<<aFamily->myCellsSize<<
768                 endl);
769 #ifdef _DEBUG_  
770         const TInt aNbGroup = aFamilyInfo->GetNbGroup();
771         for(TInt i = 0; i < aNbGroup; i++){
772           std::string aGroupName = aFamilyInfo->GetGroupName(i);
773           INITMSG(MY_FAMILY_DEBUG,"- aGroupName = '"<<aGroupName<<"'\n");
774         }
775 #endif
776
777       }
778     }
779   }
780
781
782   //---------------------------------------------------------------
783   void
784   BuildGroupMap(PMEDMesh theMesh,
785                 const MED::TFamilyInfoSet& theFamilyInfoSet)
786   {
787     TTimerLog aTimerLog(MYDEBUG,"BuildGroupMap");
788     INITMSG(MYDEBUG,"BuildGroupMap\n");
789
790     TGroupMap& aGroupMap = theMesh->myGroupMap;
791     MED::TGroupInfo aGroupInfo = MED::GetGroupInfo(theFamilyInfoSet);
792     MED::TGroupInfo::const_iterator aGroupInfoIter = aGroupInfo.begin();
793     for(; aGroupInfoIter != aGroupInfo.end(); aGroupInfoIter++){
794       const std::string& aGroupName = aGroupInfoIter->first;
795       INITMSG(MY_GROUP_DEBUG,"aGroupName = '"<<aGroupName<<"'\n");
796
797       PMEDGroup aGroup(new TMEDGroup());
798       TFamilySet& aFamilySet = aGroup->myFamilySet;
799
800       const MED::TFamilyInfoSet& aFamilyInfoSet = aGroupInfoIter->second;
801       MED::TFamilyInfoSet::const_iterator aFamilyIter = aFamilyInfoSet.begin();
802       for(; aFamilyIter != aFamilyInfoSet.end(); aFamilyIter++){
803         const MED::PFamilyInfo& aFamilyInfo = *aFamilyIter;
804         std::string aFamilyName = aFamilyInfo->GetName();
805         
806         TEntity aVEntity = TEntity(-1);
807         PMEDFamily aFamily;
808         
809         // Find aVisuEntity
810         const TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap;
811         TMeshOnEntityMap::const_iterator aMeshOnEntityIter = aMeshOnEntityMap.begin();
812         for(; aMeshOnEntityIter != aMeshOnEntityMap.end(); aMeshOnEntityIter++){
813           const PMeshOnEntity& aMeshOnEntity = aMeshOnEntityIter->second;
814           const TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
815           TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
816           for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
817             const std::string& aName = aFamilyMapIter->first;
818             aFamily = aFamilyMapIter->second;
819             if(aName == aFamilyName){
820               aVEntity = aFamily->myEntity;
821               goto exit_lable;
822             }
823           }
824         } 
825       exit_lable:
826         if(aFamily && aVEntity >= 0){
827           aFamilySet.insert(aFamily);
828           INITMSG(MY_GROUP_DEBUG,
829                   "- aFamilyName = '"<<aFamilyName<<"'"<<
830                   "; aVEntity = "<<aVEntity<<
831                   "\n");
832         }
833       }
834       if(!aFamilySet.empty())
835         aGroupMap.insert(VISU::TGroupMap::value_type(aGroupName,aGroup));
836     }
837   }
838
839
840   //---------------------------------------------------------------
841   void
842   TMEDNamedPointCoords
843   ::Init(vtkIdType theNbPoints,
844          vtkIdType theDim,
845          const MED::PNodeInfo& theNodeInfo)
846   {
847     if(theNodeInfo->IsElemNum())
848       TNamedPointCoords::Init(theNbPoints,theDim,theNodeInfo->myElemNum);
849     else
850       TNamedPointCoords::Init(theNbPoints,theDim);
851     if(theNodeInfo->IsElemNames())
852       myNodeInfo = theNodeInfo;
853   }
854
855   std::string 
856   TMEDNamedPointCoords
857   ::GetNodeName(vtkIdType theObjID) const
858   {
859     if(myNodeInfo)
860       return myNodeInfo->GetElemName(theObjID);
861     return TNamedPointCoords::GetNodeName(theObjID);
862   }
863
864
865   //---------------------------------------------------------------
866   vtkIdType
867   TMEDSubProfile
868   ::GetElemObjID(vtkIdType theID) const
869   {
870     if(myIsElemNum)
871       return myElemNum[theID];
872     else
873       return theID;
874   }
875   
876
877   //---------------------------------------------------------------
878   void
879   TMEDGauss
880   ::LessThan(const PGaussImpl& theGauss,
881              bool& theResult) const
882   {
883     TGaussImpl::LessThan(theGauss,theResult);
884     if(myGaussInfo){
885       if(PMEDGauss aGauss = theGauss){
886         const MED::TGaussInfo& aLeft = myGaussInfo;
887         const MED::TGaussInfo& aReight = aGauss->myGaussInfo;
888         theResult = MED::TGaussInfo::TLess()(aLeft,aReight);
889       }
890     }
891   }
892
893
894   //---------------------------------------------------------------
895   TGaussPointID
896   TMEDGaussSubMesh
897   ::GetObjID(vtkIdType theID) const
898   {
899     TInt aNbPoints = myGauss->myNbPoints;
900     TCellID aCellID = theID / aNbPoints;
901     if(myIsElemNum)
902       aCellID = myElemNum[aCellID];
903
904     TLocalPntID aLocalPntID = theID % aNbPoints;
905
906     return TGaussPointID(aCellID,aLocalPntID);
907   }
908   
909
910   //---------------------------------------------------------------
911   void
912   TMEDSubMesh
913   ::Init(const MED::PElemInfo& theElemInfo)
914   {
915     myIsElemNum = theElemInfo->IsElemNum();
916     myElemNum = theElemInfo->myElemNum;
917     if(theElemInfo->IsElemNames())
918       myElemInfo = theElemInfo;
919   }
920
921   vtkIdType
922   TMEDSubMesh
923   ::GetElemObjID(vtkIdType theID) const
924   {
925     if(myIsElemNum)
926       return myElemNum[theID];
927     else
928       return TSubMeshImpl::GetElemObjID(theID);
929   }
930
931   std::string 
932   TMEDSubMesh
933   ::GetElemName(vtkIdType theObjID) const
934   {
935     if(myElemInfo)
936       return myElemInfo->GetElemName(theObjID);
937     return TSubMeshImpl::GetElemName(theObjID);
938   }
939
940   struct TSetIsDone
941   {
942     bool& myIsDone;
943     TSetIsDone(bool& theIsDone):
944       myIsDone(theIsDone)
945     {}
946
947     ~TSetIsDone()
948     {
949       myIsDone = true;
950     }
951
952   };
953 }
954
955
956 //---------------------------------------------------------------
957 extern "C"
958 VISU_Convertor* 
959 CreateConvertor(const string& theFileName)
960 {
961   if(MED::PWrapper aMed = MED::CrWrapper(theFileName))
962     return new VISU_MedConvertor(theFileName);
963   return NULL;
964 }
965
966 VISU_MedConvertor
967 ::VISU_MedConvertor(const string& theFileName):
968   myIsEntitiesDone(false),
969   myIsFieldsDone(false),
970   myIsGroupsDone(false),
971   myIsMinMaxDone(false)
972 {
973   myFileInfo.setFile(QString(theFileName.c_str()));
974   myName = myFileInfo.baseName().latin1();
975 }
976
977
978 //---------------------------------------------------------------
979 VISU_Convertor* 
980 VISU_MedConvertor
981 ::BuildEntities()
982 {
983   if(myIsEntitiesDone)
984     return this;
985
986   TSetIsDone aSetIsDone(myIsEntitiesDone);
987   TTimerLog aTimerLog(MYDEBUG,"BuildEntities");
988   MED::PWrapper aMed = MED::CrWrapper(myFileInfo.absFilePath().latin1());
989
990   TInt aNbMeshes = aMed->GetNbMeshes();
991   TMeshMap& aMeshMap = myMeshMap;
992
993   INITMSG(MYDEBUG,"BuildEntities aNbMeshes = "<<aNbMeshes<<"\n");
994
995   for(TInt iMesh = 1; iMesh <= aNbMeshes; iMesh++){
996 #ifndef _DEXCEPT_
997     try{
998 #endif
999       TTimerLog aTimerLog(MYDEBUG,"GetPMeshInfo");
1000
1001       MED::PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh);
1002       std::string aMeshName = aMeshInfo->GetName();
1003       TInt aDim = aMeshInfo->GetDim();
1004       
1005       MED::PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo);
1006       
1007       MED::TEntityInfo anEntityInfo = aMed->GetEntityInfo(aMeshInfo);
1008       
1009       // creating TMesh structure and TMeshOnEntityMap         
1010       PMEDMesh aMesh = aMeshMap[aMeshName](new TMEDMesh());
1011       aMesh->myDim = aDim;
1012       aMesh->myName = aMeshName;
1013       aMesh->myNbPoints = aNodeInfo->GetNbElem();
1014       aMesh->myMeshInfo = aMeshInfo;
1015       aMesh->myEntityInfo = anEntityInfo;
1016       aMesh->myNamedPointCoords(new TMEDNamedPointCoords());
1017
1018       INITMSG(MYDEBUG,"aMeshName = '"<<aMeshName<<
1019               "'; myNbPoints = "<<aMesh->myNbPoints<<
1020               "; aDim = "<<aDim<<"\n");
1021       
1022 #ifndef _DEXCEPT_
1023       try{
1024 #endif
1025         BEGMSG(MYDEBUG,"anEntityInfo.size() = "<<anEntityInfo.size()<<"\n");
1026         
1027         BuildMeshOnEntityMap(aMesh,
1028                              anEntityInfo,
1029                              aNodeInfo,
1030                              aMed);
1031         
1032 #ifndef _DEXCEPT_
1033       }catch(std::exception& exc){
1034         MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1035       }catch(...){
1036         MSG(MYDEBUG,"Unknown exception !!!");
1037       }
1038 #endif
1039
1040 #ifndef _DEXCEPT_
1041     }catch(std::exception& exc){
1042       MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1043     }catch(...){
1044       MSG(MYDEBUG,"Unknown exception !!!");
1045     }
1046 #endif
1047   } 
1048
1049   return this; 
1050 }
1051
1052
1053 //---------------------------------------------------------------
1054 VISU_Convertor* 
1055 VISU_MedConvertor
1056 ::BuildFields()
1057 {
1058   if(myIsFieldsDone)
1059     return this;
1060
1061   TSetIsDone aSetIsDone(myIsFieldsDone);
1062   TTimerLog aTimerLog(MYDEBUG,"BuildFields");
1063   MED::PWrapper aMed = MED::CrWrapper(myFileInfo.absFilePath().latin1());
1064
1065   TInt aNbMeshes = aMed->GetNbMeshes();
1066   TMeshMap& aMeshMap = myMeshMap;
1067
1068   INITMSG(MYDEBUG,"BuildFields - aNbMeshes = "<<aNbMeshes<<"\n");
1069
1070   for(TInt iMesh = 1; iMesh <= aNbMeshes; iMesh++){
1071 #ifndef _DEXCEPT_
1072     try{
1073 #endif
1074       TTimerLog aTimerLog(MYDEBUG,"GetPMeshInfo");
1075
1076       MED::PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh);
1077       std::string aMeshName = aMeshInfo->GetName();
1078       
1079       TMeshMap::const_iterator anIter = aMeshMap.find(aMeshName);
1080       if(anIter == aMeshMap.end())
1081         continue;
1082       PMEDMesh aMesh = anIter->second;
1083
1084       INITMSG(MYDEBUG,"aMeshName = '"<<aMeshName<<"'\n");
1085 #ifndef _DEXCEPT_
1086       try{
1087 #endif
1088         MED::TEntityInfo anEntityInfo = aMed->GetEntityInfo(aMeshInfo);
1089
1090         BuildFieldMap(aMesh,
1091                       anEntityInfo,
1092                       aMed);
1093 #ifndef _DEXCEPT_
1094       }catch(std::exception& exc){
1095         MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1096       }catch(...){
1097         MSG(MYDEBUG,"Unknown exception !!!");
1098       }
1099 #endif
1100
1101 #ifndef _DEXCEPT_
1102     }catch(std::exception& exc){
1103       MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1104     }catch(...){
1105       MSG(MYDEBUG,"Unknown exception !!!");
1106     }
1107 #endif
1108   } 
1109
1110   return this; 
1111 }
1112
1113
1114 //---------------------------------------------------------------
1115 VISU_Convertor* 
1116 VISU_MedConvertor
1117 ::BuildMinMax()
1118 {
1119   if(myIsMinMaxDone)
1120     return this;
1121
1122   TSetIsDone aSetIsDone(myIsMinMaxDone);
1123   TTimerLog aTimerLog(MYDEBUG,"BuildMinMax");
1124   MED::PWrapper aMed = MED::CrWrapper(myFileInfo.absFilePath().latin1());
1125
1126   MED::TKey2Gauss aKey2Gauss = MED::GetKey2Gauss(aMed);
1127   MED::TMKey2Profile aMKey2Profile = MED::GetMKey2Profile(aMed);
1128
1129   TInt aNbMeshes = aMed->GetNbMeshes();
1130   TMeshMap& aMeshMap = myMeshMap;
1131
1132   INITMSG(MYDEBUG,"BuildMinMax - aNbMeshes = "<<aNbMeshes<<"\n");
1133
1134   for(TInt iMesh = 1; iMesh <= aNbMeshes; iMesh++){
1135 #ifndef _DEXCEPT_
1136     try{
1137 #endif
1138       TTimerLog aTimerLog(MYDEBUG,"BuildMinMax - GetPMeshInfo");
1139
1140       MED::PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh);
1141       std::string aMeshName = aMeshInfo->GetName();
1142       
1143       TMeshMap::const_iterator anIter = aMeshMap.find(aMeshName);
1144       if(anIter == aMeshMap.end())
1145         continue;
1146       PMEDMesh aMesh = anIter->second;
1147
1148 #ifndef _DEXCEPT_
1149       try{
1150 #endif
1151         TInt aNbFields = aMed->GetNbFields(); 
1152
1153         INITMSG(MYDEBUG,
1154                 "- aMeshName = '"<<aMeshName<<"'"<<
1155                 "; aNbFields = "<<aNbFields<<"\n");
1156
1157         MED::TEntityInfo anEntityInfo = aMed->GetEntityInfo(aMeshInfo);
1158
1159         for(TInt iField = 1; iField <= aNbFields; iField++){
1160           TTimerLog aTimerLog(MYDEBUG,"BuildMinMax - GetPFieldInfo()");
1161           MED::PFieldInfo aFieldInfo = aMed->GetPFieldInfo(aMeshInfo,iField);
1162           std::string aFieldName = aFieldInfo->GetName();
1163           INITMSG(MYDEBUG,"- aFieldName = '"<<aFieldName<<"'\n");
1164           
1165           MED::TGeom2Size aGeom2Size;
1166           MED::EEntiteMaillage aMEntity;
1167           TInt aNbTimeStamps = aMed->GetNbTimeStamps(aFieldInfo,
1168                                                      anEntityInfo,
1169                                                      aMEntity,
1170                                                      aGeom2Size);
1171           if(aNbTimeStamps < 1)
1172             continue;
1173         
1174           TEntity aVEntity = MEDEntityToVTK(aMEntity);
1175           PMEDMeshOnEntity aMeshOnEntity = aMesh->myMeshOnEntityMap[aVEntity];
1176           TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
1177           PMEDField aField = aFieldMap[aFieldName];
1178         
1179           TInt aNbComp = aField->myNbComp;
1180           int aNbComp2 = aNbComp;
1181           if(aNbComp == 2 || aNbComp == 4)
1182             aNbComp2 = 2;
1183           else if(aNbComp > 4)
1184             aNbComp2 = 3;
1185
1186           TMinMaxArr& aMinMaxArr = aField->myMinMaxArr;
1187           TSetIsDone aSetIsDone(aField->myIsMinMaxInitilized);
1188           for(TInt iTimeStamp = aNbTimeStamps; iTimeStamp >= 1; iTimeStamp--){
1189             TTimerLog aTimerLog(MYDEBUG,"BuildMinMax - GetPTimeStampInfo()");
1190             INITMSG(MYDEBUG,"- iTimeStamp = "<<iTimeStamp<<endl);
1191             
1192 #ifndef _DEXCEPT_
1193             try{
1194 #endif
1195               MED::PTimeStampInfo aTimeStampInfo = aMed->GetPTimeStampInfo(aFieldInfo,
1196                                                                            aMEntity,
1197                                                                            aGeom2Size,
1198                                                                            iTimeStamp);
1199               
1200               MED::PTimeStampVal aTimeStampVal = aMed->GetPTimeStampVal(aTimeStampInfo,
1201                                                                         aMKey2Profile,
1202                                                                         aKey2Gauss);
1203               
1204               const MED::TGeom2Gauss& aGeom2Gauss = aTimeStampInfo->GetGeom2Gauss();
1205               
1206               const MED::TTimeStampVal& aTimeStampValRef = aTimeStampVal;
1207               
1208               const MED::TGeom2Value& aGeom2Value = aTimeStampValRef.myGeom2Value;
1209               MED::TGeom2Value::const_iterator anIter = aGeom2Value.begin();
1210               for(; anIter != aGeom2Value.end(); anIter++){
1211                 const MED::TMeshValue& aMMeshValue = anIter->second;
1212                 MED::EGeometrieElement aMGeom = anIter->first;
1213                 
1214                 TInt aNbElem = aMMeshValue.myNbElem;
1215                 TInt aNbGauss = aMMeshValue.myNbGauss;
1216                 
1217                 MED::TGeom2Gauss::const_iterator aGaussIter = aGeom2Gauss.find(aMGeom);
1218                 if(aGaussIter == aGeom2Gauss.end())
1219                   aNbGauss = 1;
1220                 
1221                 INITMSG(MYDEBUG,
1222                         "- aMGeom = "<<aMGeom<<
1223                         "; aNbElem = "<<aNbElem<<
1224                         "; aNbGauss = "<<aNbGauss<<
1225                         endl);
1226                 
1227                 // To calculate min/max per components
1228                 for(TInt iElem = 0; iElem < aNbElem; iElem++){
1229                   MED::TCValueSliceArr aMValueSliceArr = aMMeshValue.GetCompValueSliceArr(iElem);
1230                   for(TInt iComp = 0; iComp < aNbComp; iComp++){
1231                     const MED::TCValueSlice& aMValueSlice = aMValueSliceArr[iComp];
1232                     TMinMax& aMinMax = aMinMaxArr[iComp+1];
1233                     float& aMin = aMinMax.first;
1234                     float& aMax = aMinMax.second;
1235                     for(TInt iGauss = 0; iGauss < aNbGauss; iGauss++){
1236                       const float& aVal = aMValueSlice[iGauss];
1237                       aMin = min(aMin,aVal);
1238                       aMax = max(aMax,aVal);
1239                     }
1240                   }
1241                 }
1242                 
1243                 // To calculate min/max per vector modulus
1244                 TMinMax& aMinMax = aMinMaxArr[0];
1245                 float& aMin = aMinMax.first;
1246                 float& aMax = aMinMax.second;
1247                 for(TInt iElem = 0; iElem < aNbElem; iElem++){
1248                   MED::TCValueSliceArr aMValueSliceArr = aMMeshValue.GetGaussValueSliceArr(iElem);
1249                   for(TInt iGauss = 0; iGauss < aNbGauss; iGauss++){
1250                     const MED::TCValueSlice& aMValueSlice = aMValueSliceArr[iGauss];
1251                     float aValue = 0.0;
1252                     for(TInt iComp = 0; iComp < aNbComp2; iComp++){
1253                       float aVal = aMValueSlice[iComp];
1254                       aValue += aVal*aVal;
1255                     }
1256                     aValue = sqrt(aValue);
1257                     aMin = min(aMin,aValue);
1258                     aMax = max(aMax,aValue);
1259                   }
1260                 }
1261               }
1262 #ifndef _DEXCEPT_
1263             }catch(std::exception& exc){
1264               MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1265             }catch(...){
1266               MSG(MYDEBUG,"Unknown exception !!!");
1267             }
1268 #endif
1269           }
1270           for(TInt iComp = 0; iComp <= aNbComp; iComp++){
1271             VISU::TMinMax aMinMax = aField->GetMinMax(iComp);
1272             INITMSG(MYDEBUG,"- "<<iComp<<": "<<aMinMax.first<<"; "<<aMinMax.second<<endl);
1273           }
1274         }
1275 #ifndef _DEXCEPT_
1276       }catch(std::exception& exc){
1277         MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1278       }catch(...){
1279         MSG(MYDEBUG,"Unknown exception !!!");
1280       }
1281 #endif
1282
1283 #ifndef _DEXCEPT_
1284     }catch(std::exception& exc){
1285       MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1286     }catch(...){
1287       MSG(MYDEBUG,"Unknown exception !!!");
1288     }
1289 #endif
1290   }
1291
1292   return this; 
1293 }
1294
1295
1296 //---------------------------------------------------------------
1297 VISU_Convertor* 
1298 VISU_MedConvertor
1299 ::BuildGroups()
1300 {
1301   if(myIsGroupsDone)
1302     return this;
1303
1304   TSetIsDone aSetIsDone(myIsGroupsDone);
1305   TTimerLog aTimerLog(MYDEBUG,"BuildGroups");
1306   MED::PWrapper aMed = MED::CrWrapper(myFileInfo.absFilePath().latin1());
1307
1308   TInt aNbMeshes = aMed->GetNbMeshes();
1309   TMeshMap& aMeshMap = myMeshMap;
1310
1311   INITMSG(MYDEBUG,"BuildGroups - aNbMeshes = "<<aNbMeshes<<"\n");
1312
1313   for(TInt iMesh = 1; iMesh <= aNbMeshes; iMesh++){
1314 #ifndef _DEXCEPT_
1315     try{
1316 #endif
1317       TTimerLog aTimerLog(MYDEBUG,"GetPMeshInfo");
1318
1319       MED::PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh);
1320       std::string aMeshName = aMeshInfo->GetName();      
1321
1322       TMeshMap::const_iterator anIter = aMeshMap.find(aMeshName);
1323       if(anIter == aMeshMap.end())
1324         continue;
1325       PMEDMesh aMesh = anIter->second;
1326
1327       INITMSG(MYDEBUG,"aMeshName = '"<<aMeshName<<"'\n");
1328
1329       MED::TEntityInfo anEntityInfo = aMed->GetEntityInfo(aMeshInfo);
1330       
1331       MED::TEntity2TGeom2ElemInfo anEntity2TGeom2ElemInfo = 
1332         MED::GetEntity2TGeom2ElemInfo(aMed,aMeshInfo,anEntityInfo);
1333       
1334 #ifndef _DEXCEPT_
1335       try{
1336 #endif
1337         MED::TFamilyInfoSet aFamilyInfoSet = MED::GetFamilyInfoSet(aMed,aMeshInfo);
1338         
1339         BuildFamilyMap(aMesh,
1340                        anEntityInfo,
1341                        anEntity2TGeom2ElemInfo,
1342                        aFamilyInfoSet,
1343                        aMed);
1344         
1345         BuildGroupMap(aMesh,
1346                       aFamilyInfoSet);
1347 #ifndef _DEXCEPT_
1348       }catch(std::exception& exc){
1349         MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1350       }catch(...){
1351         MSG(MYDEBUG,"Unknown exception !!!");
1352       }
1353 #endif
1354
1355 #ifndef _DEXCEPT_
1356     }catch(std::exception& exc){
1357       MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1358     }catch(...){
1359       MSG(MYDEBUG,"Unknown exception !!!");
1360     }
1361 #endif
1362   } 
1363
1364   return this; 
1365 }
1366
1367
1368 //---------------------------------------------------------------
1369 int
1370 VISU_MedConvertor
1371 ::LoadMeshOnEntity(VISU::PMeshImpl theMesh,
1372                    VISU::PMeshOnEntityImpl theMeshOnEntity)
1373 {
1374   TTimerLog aTimerLog(MYDEBUG,"LoadMeshOnEntity");
1375   INITMSG(MYDEBUG,"LoadMeshOnEntity"<<endl);
1376
1377   MED::PWrapper aMed = MED::CrWrapper(myFileInfo.absFilePath().latin1());
1378   const TEntity& anEntity = theMeshOnEntity->myEntity;
1379
1380   int isPointsUpdated = 0, isCellsOnEntityUpdated = 0;
1381   if(anEntity == NODE_ENTITY){
1382     isPointsUpdated += LoadPoints(aMed,theMesh);
1383   }else{
1384     isPointsUpdated += LoadPoints(aMed,theMesh);
1385     isCellsOnEntityUpdated += LoadCellsOnEntity(aMed,theMesh,theMeshOnEntity);
1386   }
1387
1388   return (isPointsUpdated || isCellsOnEntityUpdated);
1389 }
1390
1391
1392 //---------------------------------------------------------------
1393 int
1394 VISU_MedConvertor
1395 ::LoadFamilyOnEntity(VISU::PMeshImpl theMesh,
1396                      VISU::PMeshOnEntityImpl theMeshOnEntity, 
1397                      VISU::PFamilyImpl theFamily)
1398 {
1399   TTimerLog aTimerLog(MYDEBUG,"LoadFamilyOnEntity");
1400   INITMSG(MYDEBUG,"LoadFamilyOnEntity"<<endl);
1401
1402   MED::PWrapper aMed = MED::CrWrapper(myFileInfo.absFilePath().latin1());
1403   const TEntity& anEntity = theMeshOnEntity->myEntity;
1404
1405   int isPointsUpdated = 0, isCellsOnEntityUpdated = 0;
1406   if(anEntity == NODE_ENTITY){
1407     isPointsUpdated += LoadPointsOnFamily(aMed,theMesh,theFamily);
1408   }else{
1409     isPointsUpdated += LoadPoints(aMed,theMesh);
1410     isCellsOnEntityUpdated += LoadCellsOnFamily(aMed,theMesh,theMeshOnEntity,theFamily);
1411   }
1412
1413   return (isPointsUpdated || isCellsOnEntityUpdated);
1414 }
1415
1416
1417 //---------------------------------------------------------------
1418 int
1419 VISU_MedConvertor
1420 ::LoadMeshOnGroup(VISU::PMeshImpl theMesh, 
1421                   const VISU::TFamilySet& theFamilySet)
1422 {
1423   TTimerLog aTimerLog(MYDEBUG,"LoadMeshOnGroup");
1424   INITMSG(MYDEBUG,"LoadMeshOnGroup"<<endl);
1425
1426   MED::PWrapper aMed = MED::CrWrapper(myFileInfo.absFilePath().latin1());
1427   int isPointsUpdated = 0, isCellsOnEntityUpdated = 0;
1428   TFamilySet::const_iterator aFamilyIter = theFamilySet.begin();
1429   for(; aFamilyIter != theFamilySet.end(); aFamilyIter++){
1430     PMEDFamily aFamily = *aFamilyIter;
1431     const TEntity& anEntity = aFamily->myEntity;
1432     const PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[anEntity];
1433     if(anEntity == NODE_ENTITY){
1434       isPointsUpdated += LoadPointsOnFamily(aMed,theMesh,aFamily);
1435     }else{
1436       isPointsUpdated += LoadPoints(aMed,theMesh);
1437       isCellsOnEntityUpdated += LoadCellsOnFamily(aMed,theMesh,aMeshOnEntity,aFamily);
1438     }
1439   }
1440
1441   return (isPointsUpdated || isCellsOnEntityUpdated);
1442 }
1443
1444
1445 //---------------------------------------------------------------
1446 int
1447 VISU_MedConvertor
1448 ::LoadValForTimeOnMesh(VISU::PMeshImpl theMesh, 
1449                        VISU::PMeshOnEntityImpl theMeshOnEntity, 
1450                        VISU::PFieldImpl theField, 
1451                        VISU::PValForTimeImpl theValForTime)
1452 {
1453   TTimerLog aTimerLog(MYDEBUG,"LoadValForTimeOnMesh");
1454   INITMSG(MYDEBUG,"LoadValForTimeOnMesh"<<endl);
1455
1456   MED::PWrapper aMed = MED::CrWrapper(myFileInfo.absFilePath().latin1());
1457
1458   const TEntity& anEntity = theMeshOnEntity->myEntity;
1459   int isPointsUpdated = 0, isCellsOnEntityUpdated = 0;
1460   isPointsUpdated += LoadPoints(aMed,theMesh);
1461   if(anEntity != NODE_ENTITY)
1462     isCellsOnEntityUpdated += LoadCellsOnEntity(aMed,theMesh,theMeshOnEntity);
1463   int isFieldUpdated = LoadValForTimeOnMesh(aMed,theMesh,theMeshOnEntity,theField,theValForTime);
1464   
1465   return (isPointsUpdated || isCellsOnEntityUpdated || isFieldUpdated);
1466 }
1467
1468
1469 //---------------------------------------------------------------
1470 int
1471 VISU_MedConvertor
1472 ::LoadValForTimeOnGaussPts(VISU::PMeshImpl theMesh, 
1473                            VISU::PMeshOnEntityImpl theMeshOnEntity, 
1474                            VISU::PFieldImpl theField, 
1475                            VISU::PValForTimeImpl theValForTime)
1476 {
1477   TTimerLog aTimerLog(MYDEBUG,"LoadValForTimeOnGaussPts");
1478   INITMSG(MYDEBUG,"LoadValForTimeOnGaussPts"<<endl);
1479
1480   MED::PWrapper aMed = MED::CrWrapper(myFileInfo.absFilePath().latin1());
1481
1482   const TEntity& anEntity = theMeshOnEntity->myEntity;
1483   int isPointsUpdated = 0, isCellsOnEntityUpdated = 0;
1484   if(anEntity != NODE_ENTITY)
1485     isCellsOnEntityUpdated += LoadCellsOnEntity(aMed,theMesh,theMeshOnEntity);
1486   int isFieldUpdated = LoadValForTimeOnGaussPts(aMed,theMesh,theMeshOnEntity,theField,theValForTime);
1487   
1488   return (isPointsUpdated || isCellsOnEntityUpdated || isFieldUpdated);
1489 }
1490
1491
1492 //---------------------------------------------------------------
1493 int 
1494 VISU_MedConvertor
1495 ::LoadPoints(const MED::PWrapper& theMed,
1496              VISU::PMEDMesh theMesh) 
1497 {
1498   TTimerLog aTimerLog(MYDEBUG,"LoadPoints");
1499   try{
1500     //Check on existing family
1501     PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[VISU::NODE_ENTITY];
1502     aMeshOnEntity->myMeshName = theMesh->myName;
1503     aMeshOnEntity->myEntity = NODE_ENTITY;
1504
1505     INITMSG(MYDEBUG,"LoadPoints - theMesh->myIsDone = "<<theMesh->myIsDone<<"'\n");
1506
1507     //Check on loading already done
1508     if(theMesh->myIsDone)
1509       return 0;
1510
1511     //Main part of code
1512     MED::PNodeInfo aNodeInfo = theMed->GetPNodeInfo(theMesh->myMeshInfo);
1513     TInt aNbElem = aNodeInfo->GetNbElem();
1514     TInt aDim = theMesh->myDim;
1515
1516     PMEDNamedPointCoords aNamedPointCoords = theMesh->myNamedPointCoords;
1517     TMEDNamedPointCoords& aCoords = aNamedPointCoords;
1518     aCoords.Init(aNbElem,aDim,aNodeInfo);
1519     
1520     for(int iDim = 0; iDim < aDim; iDim++)
1521       aCoords.GetName(iDim) = aNodeInfo->GetCoordName(iDim);
1522     
1523     for(int iElem = 0; iElem < aNbElem; iElem++){
1524       TCoordSlice aVCoordSlice = aCoords.GetCoordSlice(iElem);
1525       MED::TCCoordSlice aMCoordSlice = aNodeInfo->GetCoordSlice(iElem);
1526       for(int iDim = 0; iDim < aDim; iDim++)
1527         aVCoordSlice[iDim] = aMCoordSlice[iDim];
1528     }
1529     
1530     TGeom2SubMesh& aGeom2SubMesh = aMeshOnEntity->myGeom2SubMesh;
1531     PMEDSubMesh aSubMesh = aGeom2SubMesh[VISU::ePOINT1](new TMEDSubMesh());
1532
1533     aSubMesh->Init(aNodeInfo); 
1534     aSubMesh->myNbCells = theMesh->myNbPoints;
1535     aSubMesh->myCellsSize = 2*theMesh->myNbPoints;
1536
1537     TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
1538     aCell2Connect.resize(aNbElem);
1539     for (int iElem = 0; iElem < aNbElem; iElem++)
1540       aCell2Connect[iElem] = VISU::TConnect(1,iElem);
1541     
1542     theMesh->myIsDone = true;
1543     
1544     return 1;
1545
1546   }catch(std::exception& exc){
1547     throw;
1548   }catch(...){
1549     EXCEPTION(runtime_error,"Unknown exception !!!");
1550   }
1551
1552   return 0;
1553 }
1554
1555
1556 //---------------------------------------------------------------
1557 int 
1558 VISU_MedConvertor
1559 ::LoadPointsOnFamily(const MED::PWrapper& theMed,
1560                      const VISU::PMEDMesh theMesh, 
1561                      const VISU::PMEDFamily theFamily) 
1562 {
1563   TTimerLog aTimerLog(MYDEBUG,"LoadPointsOnFamily");
1564   try{
1565     if(theFamily->myIsDone) 
1566       return 0;
1567
1568     //Main part of code
1569     MED::PNodeInfo aNodeInfo = theMed->GetPNodeInfo(theMesh->myMeshInfo);
1570     TInt aNbElem = aNodeInfo->GetNbElem();
1571
1572     if(aNbElem > 0){
1573       TInt anId = theFamily->myId;
1574       TSubMeshID& aSubMeshID = theFamily->myGeom2SubMeshID[VISU::ePOINT1];
1575       for(TInt iElem = 0; iElem < aNbElem; iElem++) 
1576         if(aNodeInfo->GetFamNum(iElem) == anId)
1577           aSubMeshID.push_back(iElem);
1578     }
1579
1580     theFamily->myIsDone = true;
1581
1582     return 1;
1583
1584   }catch(std::exception& exc){
1585     throw;
1586   }catch(...){
1587     EXCEPTION(runtime_error,"Unknown exception !!!");
1588   }
1589
1590   return 0;
1591 }
1592
1593
1594 //---------------------------------------------------------------
1595 int 
1596 VISU_MedConvertor
1597 ::LoadCellsOnEntity(const MED::PWrapper& theMed,
1598                     const VISU::PMEDMesh theMesh,
1599                     const VISU::PMEDMeshOnEntity theMeshOnEntity)
1600 {
1601   TTimerLog aTimerLog(MYDEBUG,"LoadCellsOnEntity");
1602 #ifndef _DEXCEPT_
1603   try{
1604 #endif
1605     const TEntity& aVEntity = theMeshOnEntity->myEntity;
1606     const MED::EEntiteMaillage& aMEntity = VTKEntityToMED(aVEntity);
1607
1608     INITMSG(MYDEBUG,"LoadCellsOnEntity - aVEntity = "<<aVEntity<<"\n");
1609
1610     if(theMeshOnEntity->myIsDone)
1611       return 0;
1612
1613     const MED::PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
1614     MED::PNodeInfo aNodeInfo = theMed->GetPNodeInfo(aMeshInfo);
1615     TInt aNbPoints = aNodeInfo->GetNbElem();
1616
1617     std::map<TInt,TInt> aNodeIdMap;
1618 #ifdef _EDF_NODE_IDS_
1619     EBooleen anIsNodeNum = MED::eFAUX;
1620 #else
1621     EBooleen anIsNodeNum = aNodeInfo->IsElemNum();
1622     if(anIsNodeNum){
1623       for(TInt i = 0; i < aNbPoints; i++){
1624         aNodeIdMap[aNodeInfo->GetElemNum(i)-1] = i;
1625       }
1626     }
1627 #endif
1628
1629     const MED::TGeom2Size& aGeom2Size = theMeshOnEntity->myGeom2Size;
1630     MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
1631     TGeom2SubMesh& aGeom2SubMesh = theMeshOnEntity->myGeom2SubMesh;
1632
1633     for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
1634       const MED::EGeometrieElement& aMGeom = aGeom2SizeIter->first;
1635       VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
1636       INITMSG(MYDEBUG,"aMGeom = "<<aMGeom<<"; aEGeom = "<<aEGeom<<"\n");
1637       switch(aMGeom){
1638       case MED::ePOLYGONE: {
1639         MED::PPolygoneInfo aPolygoneInfo = theMed->GetPPolygoneInfo(aMeshInfo,aMEntity,aMGeom);
1640         TInt aNbElem = aPolygoneInfo->GetNbElem();
1641         if(aNbElem > 0){
1642           PMEDSubMesh aSubMesh = aGeom2SubMesh[aEGeom](new TMEDSubMesh());
1643           
1644           aSubMesh->Init(aPolygoneInfo); 
1645           aSubMesh->myNbCells = aNbElem;      
1646
1647           TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
1648           aCell2Connect.resize(aNbElem);
1649           
1650           for(TInt iElem = 0; iElem < aNbElem; iElem++) {
1651             MED::TCConnSlice aConnSlice = aPolygoneInfo->GetConnSlice(iElem);
1652             TInt aNbConn = aPolygoneInfo->GetNbConn(iElem);
1653             aSubMesh->myCellsSize += aNbConn;
1654             TConnect& anArray = aCell2Connect[iElem];
1655             anArray.resize(aNbConn);
1656             for(TInt iConn = 0; iConn < aNbConn; iConn++)
1657               anArray[iConn] = aConnSlice[iConn] - 1;
1658           }
1659         }
1660         break;
1661       }
1662       case MED::ePOLYEDRE: {
1663         MED::PPolyedreInfo aPolyedreInfo = theMed->GetPPolyedreInfo(aMeshInfo,aMEntity,aMGeom);
1664         TInt aNbElem = aPolyedreInfo->GetNbElem();
1665         
1666         if(aNbElem > 0){
1667           PMEDSubMesh aSubMesh = aGeom2SubMesh[aEGeom](new TMEDSubMesh());
1668           
1669           aSubMesh->Init(aPolyedreInfo); 
1670           aSubMesh->myNbCells = aNbElem;      
1671
1672           TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
1673           aCell2Connect.resize(aNbElem);
1674           
1675           for(TInt iElem = 0; iElem < aNbElem; iElem++){
1676             MED::TCConnSliceArr aConnSliceArr = aPolyedreInfo->GetConnSliceArr(iElem);
1677             TConnect& anArray = aCell2Connect[iElem];
1678             typedef std::set<TInt> TConnectSet;
1679             TConnectSet aConnectSet;
1680             TInt aNbFaces = aConnSliceArr.size();
1681             for(TInt iFace = 0; iFace < aNbFaces; iFace++){
1682               MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
1683               TInt aNbConn = aConnSlice.size();
1684               aSubMesh->myCellsSize += aNbConn;
1685               for(TInt iConn = 0; iConn < aNbConn; iConn++){
1686                 aConnectSet.insert(aConnSlice[iConn]);
1687               }
1688             }
1689           
1690             int aNbConn = aConnectSet.size();
1691             anArray.resize(aNbConn);
1692             TConnectSet::iterator anIter = aConnectSet.begin();
1693             for(int i = 0; anIter != aConnectSet.end(); anIter++, i++){
1694               TInt anId = *anIter;
1695               anArray[i] = anId - 1;
1696             }
1697           }
1698         }
1699
1700         break;
1701       }
1702       default: {
1703         vtkIdType aVNbNodes = VISUGeom2NbNodes(aEGeom);
1704         INITMSG(MYDEBUG,"aVNbNodes = "<<aVNbNodes<<"\n");
1705         
1706         MED::PCellInfo aCellInfo = theMed->GetPCellInfo(aMeshInfo,aMEntity,aMGeom);
1707         TInt aNbElem = aCellInfo->GetNbElem();
1708         
1709         if(aNbElem > 0){
1710           PMEDSubMesh aSubMesh = aGeom2SubMesh[aEGeom](new TMEDSubMesh());
1711           
1712           aSubMesh->Init(aCellInfo); 
1713           aSubMesh->myNbCells = aNbElem;      
1714           aSubMesh->myCellsSize = aNbElem*(aVNbNodes+1);
1715
1716           TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
1717           aCell2Connect.resize(aNbElem);
1718         
1719           TInt aMNbNodes = MEDGeom2NbNodes(aMGeom);
1720           TVector<TInt> aConnect(aMNbNodes);
1721         
1722           for(TInt iElem = 0; iElem < aNbElem; iElem++) {
1723             MED::TCConnSlice aConnSlice = aCellInfo->GetConnSlice(iElem);
1724             TConnect& anArray = aCell2Connect[iElem];
1725             anArray.resize(aVNbNodes);
1726             
1727             if(anIsNodeNum){
1728               for(TInt iConn = 0; iConn < aMNbNodes; iConn++){
1729                 aConnect[iConn] = aNodeIdMap[aConnSlice[iConn] - 1];
1730               }
1731             }else{
1732               for(int iConn = 0; iConn < aMNbNodes; iConn++){
1733                 aConnect[iConn] = aConnSlice[iConn] - 1;
1734               }
1735             }
1736             
1737             switch(aMGeom){
1738 #if !(defined(VTK_QUADRATIC_EDGE) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
1739             case MED::eSEG3:
1740               anArray[0] = aConnect[0];
1741               anArray[2] = aConnect[1];  
1742
1743               anArray[1] = aConnect[2];
1744               break;
1745 #endif
1746 #if !(defined(VTK_QUADRATIC_TRIANGLE) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
1747             case MED::eTRIA6:
1748               anArray[0] = aConnect[0];
1749               anArray[2] = aConnect[1];  
1750               anArray[4] = aConnect[2];  
1751
1752               anArray[1] = aConnect[3];
1753               anArray[3] = aConnect[4];  
1754               anArray[5] = aConnect[5];  
1755               break;
1756 #endif
1757 #if !(defined(VTK_QUADRATIC_QUAD) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
1758             case MED::eQUAD8:
1759               anArray[0] = aConnect[0];
1760               anArray[2] = aConnect[1];  
1761               anArray[4] = aConnect[2];  
1762               anArray[6] = aConnect[3];  
1763
1764               anArray[1] = aConnect[4];
1765               anArray[3] = aConnect[5];  
1766               anArray[5] = aConnect[6];  
1767               anArray[7] = aConnect[7];  
1768               break;
1769 #endif
1770 #if (defined(VTK_QUADRATIC_TETRA) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
1771             case MED::eTETRA10:
1772               anArray[0] = aConnect[0];
1773               anArray[1] = aConnect[2];
1774               anArray[2] = aConnect[1];  
1775               anArray[3] = aConnect[3];  
1776
1777               anArray[4] = aConnect[6];
1778               anArray[5] = aConnect[5];
1779               anArray[6] = aConnect[4];  
1780
1781               anArray[7] = aConnect[7];  
1782               anArray[8] = aConnect[9];  
1783               anArray[9] = aConnect[8];  
1784               break;
1785 #endif
1786             case MED::eTETRA4:
1787               anArray[0] = aConnect[0];
1788               anArray[1] = aConnect[2];
1789               anArray[2] = aConnect[1];  
1790               anArray[3] = aConnect[3];  
1791               break;
1792 #if (defined(VTK_QUADRATIC_PYRAMID) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
1793             case MED::ePYRA13:
1794               anArray[0] = aConnect[0];
1795               anArray[1] = aConnect[3];
1796               anArray[2] = aConnect[2];  
1797               anArray[3] = aConnect[1];  
1798               anArray[4] = aConnect[4];
1799
1800               anArray[5] = aConnect[5];
1801               anArray[6] = aConnect[8];  
1802               anArray[7] = aConnect[7];  
1803               anArray[8] = aConnect[6];  
1804
1805               anArray[9] = aConnect[9];  
1806               anArray[10] = aConnect[12];  
1807               anArray[11] = aConnect[11];  
1808               anArray[12] = aConnect[10];  
1809               break;
1810 #endif
1811             case MED::ePYRA5:
1812               anArray[0] = aConnect[0];
1813               anArray[1] = aConnect[3];  
1814               anArray[2] = aConnect[2];
1815               anArray[3] = aConnect[1];  
1816               anArray[4] = aConnect[4];
1817               break;
1818             default:
1819               for(int iNode = 0; iNode < aVNbNodes; iNode++) 
1820                 anArray[iNode] = aConnect[iNode];
1821             }
1822             for(int iNode = 0; iNode < aVNbNodes; iNode++) 
1823               if(anArray[iNode] < 0 || aNbPoints <= anArray[iNode])
1824                 EXCEPTION(runtime_error,"LoadCellsOnEntity - "<<
1825                           " aNbPoints("<<aNbPoints<<") "<<
1826                           "<= anArray["<<iElem<<"]"<<
1827                           "["<<iNode<<"]"<<
1828                           "("<<anArray[iNode]<<") < 0");
1829           }
1830         }
1831       }}
1832     }
1833
1834     theMeshOnEntity->myIsDone = true;
1835
1836     return 1;
1837
1838 #ifndef _DEXCEPT_
1839   }catch(std::exception& exc){
1840     throw;
1841   }catch(...){
1842     EXCEPTION(runtime_error,"Unknown exception !!!");
1843   }
1844 #endif
1845
1846   return 0;
1847 }
1848
1849
1850 //---------------------------------------------------------------
1851 int 
1852 VISU_MedConvertor
1853 ::LoadCellsOnFamily(const MED::PWrapper& theMed,
1854                     const VISU::PMEDMesh theMesh,
1855                     const VISU::PMEDMeshOnEntity theMeshOnEntity,
1856                     const VISU::PMEDFamily theFamily)
1857 {
1858   TTimerLog aTimerLog(MYDEBUG,"LoadCellsOnFamily");
1859 #ifndef _DEXCEPT_
1860   try{
1861 #endif
1862     const TEntity& aVEntity = theMeshOnEntity->myEntity;
1863     const MED::EEntiteMaillage& aMEntity = VTKEntityToMED(aVEntity);
1864
1865     INITMSG(MYDEBUG,"LoadCellsOnFamily - aVEntity = "<<aVEntity<<"\n");
1866
1867     if(theFamily->myIsDone)
1868       return 0;
1869
1870     TInt anId = theFamily->myId;
1871
1872     const MED::PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
1873     TGeom2SubMeshID& aGeom2SubMeshID = theFamily->myGeom2SubMeshID;
1874
1875     const MED::TGeom2Size& aGeom2Size = theMeshOnEntity->myGeom2Size;
1876     MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
1877     for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
1878       const MED::EGeometrieElement& aMGeom = aGeom2SizeIter->first;
1879       MED::PElemInfo anElemInfo;
1880       switch(aMGeom){
1881       case MED::ePOLYGONE: {
1882         anElemInfo = theMed->GetPPolygoneInfo(aMeshInfo,aMEntity,aMGeom);
1883         break;
1884       }
1885       case MED::ePOLYEDRE: {
1886         anElemInfo = theMed->GetPPolyedreInfo(aMeshInfo,aMEntity,aMGeom);
1887         break;
1888       }
1889       default: {
1890         anElemInfo = theMed->GetPCellInfo(aMeshInfo,aMEntity,aMGeom);
1891         break;
1892       }}
1893       if(anElemInfo){
1894         if(TInt aNbElem = anElemInfo->GetNbElem()){
1895           TSubMeshID aSubMeshID;
1896           for(TInt iElem = 0; iElem < aNbElem; iElem++) 
1897             if(anElemInfo->GetFamNum(iElem) == anId)
1898               aSubMeshID.push_back(iElem);
1899           if(!aSubMeshID.empty()){
1900             VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
1901             INITMSG(MYDEBUG,"aMGeom = "<<aMGeom<<"\n");
1902             aGeom2SubMeshID.insert(TGeom2SubMeshID::value_type(aEGeom,aSubMeshID));
1903           }
1904         }
1905       }
1906     }
1907
1908     theFamily->myIsDone = true;
1909
1910     return 1;
1911
1912 #ifndef _DEXCEPT_
1913   }catch(std::exception& exc){
1914     throw;
1915   }catch(...){
1916     EXCEPTION(runtime_error,"Unknown exception !!!");
1917   }
1918 #endif
1919
1920   return 0;
1921 }
1922
1923
1924 //---------------------------------------------------------------
1925 void
1926 LoadProfile(const MED::PWrapper& theMed,
1927             VISU::PMEDMesh theMesh,
1928             MED::TTimeStampVal& theTimeStampVal,
1929             VISU::TMEDValForTime& theValForTime,
1930             VISU::TMEDMeshOnEntity& theMeshOnEntity)
1931 {
1932   TTimerLog aTimerLog(MYDEBUG,"LoadProfile");
1933   INITMSG(MYDEBUG,"LoadProfile"<<endl);
1934
1935   PMEDProfile aProfile = theValForTime.myProfile;
1936   if(aProfile->myIsDone)
1937     return;
1938
1939   const TGeom2SubProfile& aGeom2SubProfile = aProfile->myGeom2SubProfile;
1940   const MED::TGeom2Profile& aGeom2Profile = theTimeStampVal.GetGeom2Profile();
1941   MED::TGeom2Profile::const_iterator anIter = aGeom2Profile.begin();
1942   for(; anIter != aGeom2Profile.end(); anIter++){
1943     MED::PProfileInfo aProfileInfo = anIter->second;
1944     MED::EGeometrieElement aMGeom = anIter->first;
1945     VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
1946
1947     TGeom2SubProfile::const_iterator anIter2 = aGeom2SubProfile.find(aEGeom);
1948     if(anIter2 != aGeom2SubProfile.end()){
1949       PMEDSubProfile aSubProfile = anIter2->second;
1950
1951       MED::TElemNum& anElemNum = aProfileInfo->myElemNum;
1952       if(!anElemNum.empty()){
1953         TSubMeshID& aSubMeshID = aSubProfile->mySubMeshID;
1954         TInt aSize = anElemNum.size();
1955         aSubMeshID.resize(aSize);
1956         for(TInt anId = 0; anId < aSize; anId++)
1957           aSubMeshID[anId] = anElemNum[anId] - 1;
1958       }
1959
1960       INITMSG(MYDEBUG,
1961               "- aEGeom = "<<aEGeom<<
1962               "; aNbCells = "<<aSubProfile->mySubMeshID.size()<<
1963               endl);
1964     }
1965   }
1966   {
1967     const MED::PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
1968     
1969     TEntity aVEntity = theMeshOnEntity.myEntity;
1970     MED::EEntiteMaillage aMEntity = VTKEntityToMED(aVEntity);
1971     
1972     const TGeom2SubProfile& aGeom2SubProfile = aProfile->myGeom2SubProfile;
1973     TGeom2SubProfile::const_iterator anIter = aGeom2SubProfile.begin();
1974     for(; anIter != aGeom2SubProfile.end(); anIter++){
1975       const PMEDSubProfile& aSubProfile = anIter->second;
1976       MED::EGeometrieElement aMGeom = aSubProfile->myMGeom;
1977       MED::PElemInfo anElemInfo;
1978       if(aMEntity == MED::eNOEUD)
1979         anElemInfo = theMed->GetPNodeInfo(aMeshInfo);
1980       else{
1981         switch(aMGeom){
1982         case MED::ePOLYGONE: {
1983           anElemInfo = theMed->GetPPolygoneInfo(aMeshInfo,aMEntity,aMGeom);
1984           break;
1985         }
1986         case MED::ePOLYEDRE: {
1987           anElemInfo = theMed->GetPPolyedreInfo(aMeshInfo,aMEntity,aMGeom);
1988           break;
1989         }
1990         default: {
1991           anElemInfo = theMed->GetPCellInfo(aMeshInfo,aMEntity,aMGeom);
1992           break;
1993         }}
1994       }
1995       aSubProfile->myIsElemNum = anElemInfo->IsElemNum();
1996       aSubProfile->myElemNum = anElemInfo->myElemNum;
1997     }
1998   }
1999
2000   aProfile->myIsDone = true;
2001 }
2002
2003
2004 //---------------------------------------------------------------
2005 void
2006 LoadGaussMesh(const MED::PWrapper& theMed,
2007               VISU::PMEDMesh theMesh,
2008               MED::TTimeStampVal& theTimeStampVal,
2009               VISU::TMEDValForTime& theValForTime,
2010               VISU::TMEDMeshOnEntity& theMeshOnEntity)
2011 {
2012   TTimerLog aTimerLog(MYDEBUG,"LoadGaussMesh");
2013   INITMSG(MYDEBUG,"LoadGaussMesh"<<endl);
2014
2015   PMEDGaussMesh aGaussMesh = theValForTime.myGaussMesh;
2016   if(!aGaussMesh || aGaussMesh->myIsDone)
2017     return;
2018
2019   const MED::PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
2020   MED::PNodeInfo aNodeInfo = theMed->GetPNodeInfo(aMeshInfo);
2021
2022   TEntity aVEntity = theMeshOnEntity.myEntity;
2023   MED::EEntiteMaillage aMEntity = VTKEntityToMED(aVEntity);
2024
2025   const TGeom2GaussSubMesh& aGeom2GaussSubMesh = aGaussMesh->myGeom2GaussSubMesh;
2026   const MED::TTimeStampInfo& aTimeStampInfo = theTimeStampVal.GetTimeStampInfo();
2027   const MED::TGeom2Gauss& aGeom2Gauss = aTimeStampInfo.GetGeom2Gauss();
2028
2029   TGeom2GaussSubMesh::const_iterator aSubMeshIter = aGeom2GaussSubMesh.begin();
2030   for(; aSubMeshIter != aGeom2GaussSubMesh.end(); aSubMeshIter++){
2031     PMEDGaussSubMesh aGaussSubMesh = aSubMeshIter->second;
2032     VISU::EGeometry aEGeom = aSubMeshIter->first;
2033     
2034     if(aGaussSubMesh->myIsDone)
2035       continue;
2036
2037     PMEDSubProfile aSubProfile = aGaussSubMesh->mySubProfile;
2038     const TSubMeshID& aSubMeshID = aSubProfile->mySubMeshID;
2039     MED::EGeometrieElement aMGeom = aSubProfile->myMGeom;
2040
2041     MED::PPolygoneInfo aPolygoneInfo;
2042     MED::PPolyedreInfo aPolyedreInfo;
2043     MED::PCellInfo aCellInfo;
2044     MED::PElemInfo anElemInfo;
2045
2046     switch(aMGeom){
2047     case MED::ePOLYGONE: 
2048       aPolygoneInfo = theMed->GetPPolygoneInfo(aMeshInfo,
2049                                                aMEntity,
2050                                                aMGeom);
2051       anElemInfo = aPolygoneInfo;
2052       break;
2053     case MED::ePOLYEDRE: 
2054       aPolyedreInfo = theMed->GetPPolyedreInfo(aMeshInfo,
2055                                                aMEntity,
2056                                                aMGeom);
2057       anElemInfo = aPolyedreInfo;
2058       break;
2059     default:
2060       aCellInfo = theMed->GetPCellInfo(aMeshInfo,
2061                                        aMEntity, 
2062                                        aMGeom);
2063       anElemInfo = aCellInfo;
2064     }
2065     aGaussSubMesh->myIsElemNum = anElemInfo->IsElemNum();
2066     aGaussSubMesh->myElemNum = anElemInfo->myElemNum;
2067
2068     std::string aName;
2069     MED::TGaussCoord aGaussCoord;
2070     bool anIsGaussCoord3D = false;
2071
2072     MED::TGeom2Gauss::const_iterator aGaussIter = aGeom2Gauss.find(aMGeom);
2073     if(aGaussIter != aGeom2Gauss.end()){
2074       PMEDGauss aGauss = aGaussSubMesh->myGauss;
2075       MED::PGaussInfo aGaussInfo = aGauss->myGaussInfo;
2076       if(aGaussInfo){
2077         aName = aGaussInfo->GetName();
2078         if(!aSubMeshID.empty()){
2079           const std::string& aProfileName = aSubProfile->myName;
2080           MED::PProfileInfo aProfileInfo = MED::GetProfileInfo(theMed,
2081                                                                aProfileName);
2082           if(aProfileInfo){
2083             const MED::TElemNum& anElemNum = aProfileInfo->myElemNum;
2084             anIsGaussCoord3D = MED::GetGaussCoord3D(aGaussInfo,
2085                                                     aCellInfo,
2086                                                     aNodeInfo,
2087                                                     aGaussCoord,
2088                                                     anElemNum);
2089           }
2090         }else
2091           anIsGaussCoord3D = MED::GetGaussCoord3D(aGaussInfo,
2092                                                   aCellInfo,
2093                                                   aNodeInfo,
2094                                                   aGaussCoord);
2095       }
2096     }else{
2097       if(!aSubMeshID.empty()){
2098         const std::string& aProfileName = aSubProfile->myName;
2099         MED::PProfileInfo aProfileInfo = MED::GetProfileInfo(theMed,
2100                                                              aProfileName);
2101         if(aProfileInfo){
2102           const MED::TElemNum& anElemNum = aProfileInfo->myElemNum;
2103           switch(aMGeom){
2104           case MED::ePOLYGONE: 
2105             anIsGaussCoord3D = MED::GetBaryCenter(aPolygoneInfo,
2106                                                   aNodeInfo,
2107                                                   aGaussCoord,
2108                                                   anElemNum);
2109             break;
2110           case MED::ePOLYEDRE: 
2111             anIsGaussCoord3D = MED::GetBaryCenter(aPolyedreInfo,
2112                                                   aNodeInfo,
2113                                                   aGaussCoord,
2114                                                   anElemNum);
2115             break;
2116           default:
2117             anIsGaussCoord3D = MED::GetBaryCenter(aCellInfo,
2118                                                   aNodeInfo,
2119                                                   aGaussCoord,
2120                                                   anElemNum);
2121           }
2122         }
2123       }else
2124         switch(aMGeom){
2125         case MED::ePOLYGONE: 
2126           anIsGaussCoord3D = MED::GetBaryCenter(aPolygoneInfo,
2127                                                 aNodeInfo,
2128                                                 aGaussCoord);
2129           break;
2130         case MED::ePOLYEDRE: 
2131           anIsGaussCoord3D = MED::GetBaryCenter(aPolyedreInfo,
2132                                                 aNodeInfo,
2133                                                 aGaussCoord);
2134           break;
2135         default:
2136           anIsGaussCoord3D = MED::GetBaryCenter(aCellInfo,
2137                                                 aNodeInfo,
2138                                                 aGaussCoord);
2139         }
2140     }
2141     
2142     if(anIsGaussCoord3D){
2143       TPointCoords& aCoords = aGaussSubMesh->myPointCoords;
2144       TInt aNbGauss = aGaussCoord.GetNbGauss();
2145       TInt aNbElem = aGaussCoord.GetNbElem();
2146       TInt aDim = aGaussCoord.GetDim();
2147       vtkIdType aNbCells = aNbElem*aNbGauss;
2148       aCoords.Init(aNbCells,aDim);
2149       for(TInt anElemId = 0, aNodeId = 0; anElemId < aNbElem; anElemId++){
2150         MED::TCoordSliceArr aCoordSliceArr = aGaussCoord.GetCoordSliceArr(anElemId);
2151         for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++, aNodeId++){
2152           MED::TCoordSlice aCoordSlice = aCoordSliceArr[aGaussId];
2153           TCoordSlice aSlice = aCoords.GetCoordSlice(aNodeId);
2154           for(TInt aDimId = 0; aDimId < aDim; aDimId++)
2155             aSlice[aDimId] = aCoordSlice[aDimId];
2156         }
2157       }
2158       
2159       aGaussSubMesh->myIsDone = true;;
2160       
2161       INITMSG(MYDEBUG,
2162               "- aEGeom = "<<aEGeom<<
2163               "; aName = '"<<aName<<"'"<<
2164               "; aStatus = "<<aGaussSubMesh->myStatus<<
2165               "; aNbElem = "<<aNbElem<<
2166               "; aNbGauss = "<<aNbGauss<<
2167               "; aNbCells = "<<aNbCells<<
2168               endl);
2169     }
2170   }
2171   
2172   aGaussMesh->myIsDone = true;
2173 }
2174
2175
2176 //---------------------------------------------------------------
2177 int 
2178 LoadValForTime(const MED::PWrapper& theMed,
2179                VISU::PMEDMesh theMesh,
2180                VISU::PMEDMeshOnEntity theMeshOnEntity,
2181                VISU::PMEDField theField, 
2182                VISU::PMEDValForTime theValForTime,
2183                bool theIsGauss,
2184                bool& theIsDone)
2185 {
2186   TTimerLog aTimerLog(MYDEBUG,"LoadValForTime");
2187   INITMSG(MYDEBUG,"LoadValForTime - theIsGauss = "<<theIsGauss<<endl);
2188
2189   //Check on loading already done
2190   if(theIsDone) 
2191     return 0;
2192
2193   //Main part of code
2194   const std::string& aMeshName = theMeshOnEntity->myMeshName;
2195   const MED::PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
2196   MED::PFieldInfo aFieldInfo = theMed->GetPFieldInfo(aMeshInfo,
2197                                                      theField->myId);
2198
2199   MED::TGeom2Size aGeom2Size;
2200   MED::EEntiteMaillage aMEntity;
2201   theMed->GetNbTimeStamps(aFieldInfo,
2202                           theMesh->myEntityInfo,
2203                           aMEntity,
2204                           aGeom2Size);
2205
2206   MED::PTimeStampInfo aTimeStampInfo = 
2207     theMed->GetPTimeStampInfo(aFieldInfo,
2208                               aMEntity,
2209                               aGeom2Size,
2210                               theValForTime->myId);
2211
2212   MED::TKey2Gauss aKey2Gauss = GetKey2Gauss(theMed);
2213   MED::TMKey2Profile aMKey2Profile = GetMKey2Profile(theMed);
2214
2215   MED::PTimeStampVal aTimeStampVal = 
2216     theMed->GetPTimeStampVal(aTimeStampInfo,
2217                              aMKey2Profile,
2218                              aKey2Gauss);
2219
2220   InitGaussProfile(theMed,
2221                    aMeshInfo,
2222                    aTimeStampVal,
2223                    theMeshOnEntity,
2224                    aMEntity,
2225                    aGeom2Size,
2226                    theValForTime);
2227
2228   LoadProfile(theMed,
2229               theMesh,
2230               aTimeStampVal,
2231               theValForTime,
2232               theMeshOnEntity);
2233   
2234   if(theIsGauss)
2235     LoadGaussMesh(theMed,
2236                   theMesh,
2237                   aTimeStampVal,
2238                   theValForTime,
2239                   theMeshOnEntity);
2240   
2241   PMEDProfile aProfile = theValForTime->myProfile;
2242   TGeom2SubProfile& aGeom2SubProfile = aProfile->myGeom2SubProfile;
2243
2244   TInt aNbComp = theField->myNbComp;
2245
2246   INITMSGA(MYDEBUG,0,
2247            "- aMeshName = '"<<aMeshName<<"'"<<
2248            "; aFieldName = '"<<aFieldInfo->GetName()<<"'"<<
2249            "; aMEntity = "<<aMEntity<<
2250            "; aNbComp = "<<aNbComp<<
2251            endl);
2252
2253   theField->myDataSize = 0;
2254
2255   const MED::TTimeStampVal& aTimeStampValRef = aTimeStampVal;
2256   TGeom2SubProfile::const_iterator anIter = aGeom2SubProfile.begin();
2257   for(; anIter != aGeom2SubProfile.end(); anIter++){
2258     VISU::EGeometry aEGeom = anIter->first;
2259     PMEDSubProfile aSubProfile(anIter->second);
2260
2261     TInt aNbElem = aSubProfile->myNbCells;
2262     theField->myDataSize += aNbElem*aNbComp;
2263
2264     if(aSubProfile->myStatus != eRemoveAll){
2265       TInt aNbGauss = theValForTime->GetNbGauss(aEGeom);
2266
2267       INITMSG(MYDEBUG,
2268               "- aEGeom = "<<aEGeom<<
2269               "; aNbElem = "<<aNbElem<<
2270               "; aNbGauss = "<<aNbGauss<<
2271               endl);
2272       
2273       TMeshValue& aVMeshValue = theValForTime->GetMeshValue(aEGeom);
2274       aVMeshValue.Init(aNbElem,aNbGauss,aNbComp);
2275
2276       MED::EGeometrieElement aMGeom = aSubProfile->myMGeom;
2277       const MED::TMeshValue& aMMeshValue = aTimeStampValRef.GetMeshValue(aMGeom);
2278       for(TInt iElem = 0; iElem < aNbElem; iElem++){
2279         TValueSliceArr aVValueSliceArr = aVMeshValue.GetGaussValueSliceArr(iElem);
2280         MED::TCValueSliceArr aMValueSliceArr = aMMeshValue.GetGaussValueSliceArr(iElem);
2281         ADDMSG(MYVALUEDEBUG,"{");
2282         for(TInt iGauss = 0; iGauss < aNbGauss; iGauss++){
2283           TValueSlice& aVValueSlice = aVValueSliceArr[iGauss];
2284           const MED::TCValueSlice& aMValueSlice = aMValueSliceArr[iGauss];
2285           for(TInt iComp = 0; iComp < aNbComp; iComp++){
2286             aVValueSlice[iComp] = aMValueSlice[iComp];
2287             ADDMSG(MYVALUEDEBUG,aVValueSlice[iComp]<<" ");
2288           }
2289           ADDMSG(MYVALUEDEBUG,"| ");
2290         }
2291         ADDMSG(MYVALUEDEBUG,"} ");
2292       }
2293       ADDMSG(MYDEBUG,"\n");
2294     }
2295   }
2296
2297   theIsDone = true;
2298
2299   return 1; 
2300 }
2301
2302
2303 //---------------------------------------------------------------
2304 int 
2305 VISU_MedConvertor
2306 ::LoadValForTimeOnMesh(const MED::PWrapper& theMed,
2307                        VISU::PMEDMesh theMesh,
2308                        VISU::PMEDMeshOnEntity theMeshOnEntity,
2309                        VISU::PMEDField theField, 
2310                        VISU::PMEDValForTime theValForTime)
2311 {
2312   PIDMapperFilter anIDMapperFilter = theValForTime->myIDMapperFilter;
2313   return LoadValForTime(theMed,
2314                         theMesh,
2315                         theMeshOnEntity,
2316                         theField,
2317                         theValForTime,
2318                         false,
2319                         anIDMapperFilter->myIsVTKDone);
2320 }
2321
2322
2323 //---------------------------------------------------------------
2324 int 
2325 VISU_MedConvertor
2326 ::LoadValForTimeOnGaussPts(const MED::PWrapper& theMed,
2327                            VISU::PMEDMesh theMesh,
2328                            VISU::PMEDMeshOnEntity theMeshOnEntity,
2329                            VISU::PMEDField theField, 
2330                            VISU::PMEDValForTime theValForTime)
2331 {
2332   PGaussPtsIDFilter aGaussPtsIDFilter = theValForTime->myGaussPtsIDFilter;
2333   return LoadValForTime(theMed,
2334                         theMesh,
2335                         theMeshOnEntity,
2336                         theField,
2337                         theValForTime,
2338                         true,
2339                         aGaussPtsIDFilter->myIsVTKDone);
2340 }