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