Salome HOME
Merge with version on tag OCC-V2_1_0d
[modules/visu.git] / src / VISU_I / VISU_CorbaMedConvertor.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 //
24 //  File   : VISU_CorbaMedConvertor.cxx
25 //  Author : Alexey PETROV
26 //  Module : VISU
27 //  $Header$
28 //  Copyright (C) 2003  CEA/DEN, EDF R&D
29
30 #include "VISU_CorbaMedConvertor.hxx"
31 #include "VISU_ConvertorUtils.hxx"
32
33 #include <valarray>     
34 #include <vtkCellType.h>
35
36 using namespace VISU;
37 using namespace std;
38
39 #define USER_INTERLACE MED_FULL_INTERLACE
40
41 #ifdef _DEBUG_
42 static int MYDEBUG = 0;
43 #else
44 static int MYDEBUG = 0;
45 #endif
46 static med_err ret = 0;
47
48 extern "C" {
49   VISU_Convertor* CreateMEDConvertor(SALOMEDS::SObject_ptr theMedSObject) {
50     return new VISU_MEDConvertor(theMedSObject);
51   }
52   VISU_Convertor* CreateMEDFieldConvertor(SALOME_MED::FIELD_ptr theField) {
53     return new VISU_MEDFieldConvertor(theField);
54   }
55 }
56
57 typedef map<VISU::TEntity,SALOME_MED::medEntityMesh> TVisu2MedEntity;
58 static TVisu2MedEntity aVisu2MedEntity;
59 typedef map<SALOME_MED::medEntityMesh,VISU::TEntity> TMed2VisuEntity;
60 static TMed2VisuEntity aMed2VisuEntity;
61 static int INIT = (
62                    aVisu2MedEntity[VISU::CELL_ENTITY] = SALOME_MED::MED_CELL,
63                    aVisu2MedEntity[VISU::FACE_ENTITY] = SALOME_MED::MED_FACE,
64                    aVisu2MedEntity[VISU::EDGE_ENTITY] = SALOME_MED::MED_EDGE,
65                    aVisu2MedEntity[VISU::NODE_ENTITY] = SALOME_MED::MED_NODE,
66
67                    aMed2VisuEntity[SALOME_MED::MED_CELL] = VISU::CELL_ENTITY,
68                    aMed2VisuEntity[SALOME_MED::MED_FACE] = VISU::FACE_ENTITY,
69                    aMed2VisuEntity[SALOME_MED::MED_EDGE] = VISU::EDGE_ENTITY,
70                    aMed2VisuEntity[SALOME_MED::MED_NODE] = VISU::NODE_ENTITY,
71
72                    1);
73
74 static int CELLGEOM[MED_NBR_GEOMETRIE_MAILLE] = {
75   SALOME_MED::MED_POINT1,
76   SALOME_MED::MED_SEG2,
77   SALOME_MED::MED_SEG3,
78   SALOME_MED::MED_TRIA3,
79   SALOME_MED::MED_QUAD4,
80   SALOME_MED::MED_TRIA6,
81   SALOME_MED::MED_QUAD8,
82   SALOME_MED::MED_TETRA4,
83   SALOME_MED::MED_PYRA5,
84   SALOME_MED::MED_PENTA6,
85   SALOME_MED::MED_HEXA8,
86   SALOME_MED::MED_TETRA10,
87   SALOME_MED::MED_PYRA13,
88   SALOME_MED::MED_PENTA15,
89   SALOME_MED::MED_HEXA20
90 };
91
92 static const int VTKCELLGEOMEND = 8;
93 static int VTKCELLGEOM[VTKCELLGEOMEND] = {
94   SALOME_MED::MED_POINT1,
95   SALOME_MED::MED_SEG2,
96   SALOME_MED::MED_TRIA3,
97   SALOME_MED::MED_QUAD4,
98   SALOME_MED::MED_TETRA4,
99   SALOME_MED::MED_PYRA5,
100   SALOME_MED::MED_PENTA6,
101   SALOME_MED::MED_HEXA8
102 };
103
104 static int FACEGEOM[MED_NBR_GEOMETRIE_FACE] = {
105   SALOME_MED::MED_TRIA3,
106   SALOME_MED::MED_QUAD4,
107   SALOME_MED::MED_TRIA6,
108   SALOME_MED::MED_QUAD8
109 };
110
111 static int EDGEGEOM[MED_NBR_GEOMETRIE_ARETE] = {
112   SALOME_MED::MED_SEG2,
113   SALOME_MED::MED_SEG3
114 };
115
116 static int NODEGEOM[1] = {
117   SALOME_MED::MED_POINT1,
118 };
119
120 void GetEntity2Geom(const VISU::TEntity& theEntity, int*& theVector, int* theEnd)
121 {
122   switch(theEntity){
123   case VISU::CELL_ENTITY: theVector = CELLGEOM; *theEnd = MED_NBR_GEOMETRIE_MAILLE; break;
124   case VISU::FACE_ENTITY: theVector = FACEGEOM; *theEnd = MED_NBR_GEOMETRIE_FACE; break;
125   case VISU::EDGE_ENTITY: theVector = EDGEGEOM; *theEnd = MED_NBR_GEOMETRIE_ARETE; break;
126   case VISU::NODE_ENTITY: theVector = NODEGEOM; *theEnd = 1; break;
127   default:
128     throw std::runtime_error("GetEntity2Geom >> theEntity is uncorrect !!!");
129   }
130 }
131
132 struct SalomeMed2vtk {
133   SALOME_MED::medGeometryElement medType;
134   char *medName;
135   int medNbNodes;
136   int vtkType;
137   char *vtkName;
138   int vtkNbNodes;
139 };
140
141 #define CORBAMED2VTK(MEDTYPE,VTKTYPE,VTKNBNODES) \
142  {SALOME_MED::MEDTYPE,#MEDTYPE,getNbMedNodes(MEDTYPE),VTKTYPE,#VTKTYPE,VTKNBNODES}
143 static SalomeMed2vtk salome_med2vtk[SALOME_MED::MED_ALL_ELEMENTS] = {
144   {SALOME_MED::MED_NONE,"MED_NONE",0,VTK_EMPTY_CELL,"VTK_EMPTY_CELL",0},
145   CORBAMED2VTK(MED_POINT1,VTK_VERTEX,1),
146   CORBAMED2VTK(MED_SEG2,VTK_LINE,2),
147   CORBAMED2VTK(MED_SEG3,VTK_LINE,2),
148   CORBAMED2VTK(MED_TRIA3,VTK_TRIANGLE,3),
149   CORBAMED2VTK(MED_QUAD4,VTK_QUAD,4),
150   CORBAMED2VTK(MED_TRIA6,VTK_TRIANGLE,3),
151   CORBAMED2VTK(MED_QUAD8,VTK_QUAD,4),
152   CORBAMED2VTK(MED_TETRA4,VTK_TETRA,4),
153   CORBAMED2VTK(MED_PYRA5,VTK_PYRAMID,5),
154   CORBAMED2VTK(MED_PENTA6,VTK_WEDGE,6),
155   CORBAMED2VTK(MED_HEXA8,VTK_HEXAHEDRON,8),
156   CORBAMED2VTK(MED_TETRA10,VTK_TETRA,4),
157   CORBAMED2VTK(MED_PYRA13,VTK_PYRAMID,5),
158   CORBAMED2VTK(MED_PENTA15,VTK_WEDGE,6),
159   CORBAMED2VTK(MED_HEXA20,VTK_HEXAHEDRON,8)
160 };
161 #undef CORBAMED2VTK
162
163 int GetIdMEDType(int medType){
164   for(int i = 0; i < SALOME_MED::MED_ALL_ELEMENTS; i++)
165     if(salome_med2vtk[i].medType == medType) return i;
166   return -1;
167 }
168
169 string GetName(SALOMEDS::SObject_ptr aSObject){
170   SALOMEDS::GenericAttribute_var anAttr;
171   if (aSObject->FindAttribute(anAttr,"AttributeName")) {
172     SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
173     CORBA::String_var aString = aName->Value();
174     return aString.in();
175   }
176   return "";
177 }
178
179
180 static void GetCellsSize(vtkIdType& theNbCells, vtkIdType& theCellsSize,
181                          SALOME_MED::MESH_ptr theMEDMesh,
182                          const VISU::TEntity& theEntity)
183 {
184   int iGeomElemEnd;
185   int* aGeomElemVector;
186   GetEntity2Geom(theEntity,aGeomElemVector,&iGeomElemEnd);
187   theNbCells = theCellsSize = 0;
188   const SALOME_MED::medEntityMesh& aMedEntity = aVisu2MedEntity[theEntity];
189   if(MYDEBUG) MESSAGE("GetCellsSize - theEntity = "<<theEntity);
190   for (int iGeomElem = 0, aCounter = 0; iGeomElem < iGeomElemEnd; iGeomElem++) {
191     int medId = GetIdMEDType(aGeomElemVector[iGeomElem]);
192     SALOME_MED::medGeometryElement aMedType = salome_med2vtk[medId].medType;
193     med_int iNumElemEnd = theMEDMesh->getNumberOfElements(aMedEntity,aMedType);
194     if(iNumElemEnd > 0){
195       if(MYDEBUG) MESSAGE("GetCellsSize - iNumElemEnd = "<<iNumElemEnd);
196       theNbCells += iNumElemEnd;
197       theCellsSize += iNumElemEnd*(salome_med2vtk[medId].vtkNbNodes + 1);
198     }
199   }
200 }
201
202
203 static void GetCellsSize(vtkIdType& theNbCells, vtkIdType& theCellsSize,
204                          SALOME_MED::FAMILY_ptr theMEDFamily)
205 {
206   SALOME_MED::medGeometryElement_array_var aGeom = theMEDFamily->getTypes();
207   med_int iGeomElemEnd = aGeom->length();
208   theNbCells = theCellsSize = 0;
209   if(MYDEBUG) MESSAGE("GetCellsSize - iGeomElemEnd = "<<iGeomElemEnd);
210   for (int iGeomElem = 0; iGeomElem < iGeomElemEnd; iGeomElem++) {
211     SALOME_MED::medGeometryElement aGeomType = aGeom[iGeomElem];
212     SALOME_MED::long_array_var aCellNumForType = theMEDFamily->getNumber(aGeomType);
213     int medId = GetIdMEDType(aGeomType);
214     med_int iNumElemEnd = aCellNumForType->length();
215     if(iNumElemEnd > 0){
216       if(MYDEBUG) MESSAGE("GetCellsSize - iNumElemEnd = "<<iNumElemEnd);
217       theNbCells += iNumElemEnd;
218       theCellsSize += iNumElemEnd*(salome_med2vtk[medId].vtkNbNodes + 1);
219     }
220   }
221 }
222
223
224 static void GetCellsSize(VISU::TMesh& theMesh, 
225                          SALOME_MED::MESH_ptr theMEDMesh, 
226                          const VISU::TEntity& theEntity)
227 {
228   VISU::TMeshOnEntity& aMeshOnEntity = theMesh.myMeshOnEntityMap[theEntity];
229   if(theEntity == VISU::NODE_ENTITY){
230     theMesh.myNbPoints = theMEDMesh->getNumberOfNodes();
231     aMeshOnEntity.myNbCells = theMesh.myNbPoints;
232     aMeshOnEntity.myCellsSize = 2*theMesh.myNbPoints;
233     vtkIdType aNbCells, aCellsSize;
234     GetCellsSize(aNbCells,aCellsSize,theMEDMesh,VISU::CELL_ENTITY);
235     if(aNbCells > 0){
236       VISU::TMeshOnEntity& aMeshOnCells = theMesh.myMeshOnEntityMap[VISU::CELL_ENTITY];
237       aMeshOnCells.myEntity = VISU::CELL_ENTITY;
238       aMeshOnCells.myMeshName = theMesh.myName;
239       aMeshOnCells.myNbCells = aNbCells;
240       aMeshOnCells.myCellsSize = aCellsSize;
241     }
242   }else
243     GetCellsSize(aMeshOnEntity.myNbCells,aMeshOnEntity.myCellsSize,theMEDMesh,theEntity);
244 }
245
246
247 VISU_Convertor* VISU_MEDFieldConvertor::Build() {
248   if(myField->_is_nil()) 
249     throw std::runtime_error("VISU_MEDFieldConvertor::Build >> myField->_is_nil() !!!");
250   
251   SALOME_MED::SUPPORT_var aMEDSupport = myField->getSupport();
252   if(aMEDSupport->_is_nil()) 
253     throw std::runtime_error("VISU_MEDFieldConvertor::Build >> aMEDSupport->_is_nil() !!!");
254   SALOME_MED::medEntityMesh aMEDEntity = aMEDSupport->getEntity();
255   VISU::TEntity anEntity = aMed2VisuEntity[aMEDEntity];
256   SALOME_MED::MESH_var aMEDMesh = aMEDSupport->getMesh();
257   if(aMEDMesh->_is_nil()) 
258     throw std::runtime_error("VISU_MEDFieldConvertor::Build >> aMEDMesh->_is_nil() !!!");
259   CORBA::String_var aMeshName = aMEDMesh->getName();
260   CORBA::String_var aFieldName = myField->getName();
261
262   VISU::TMesh &aMesh = myMeshMap[aMeshName.in()];
263   aMesh.myDim = aMEDMesh->getSpaceDimension();
264   aMesh.myPointsDim.resize(aMesh.myDim);
265   aMesh.myName = aMeshName.in();
266   VISUMED::TMesh &aMesh2 = myMeshMap2[aMeshName.in()];
267   aMesh2.myMesh = aMEDMesh;
268   if(MYDEBUG) MESSAGE("VISU_MEDFieldConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh.myDim);
269
270   VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
271   aMeshOnEntity.myEntity = anEntity;
272   aMeshOnEntity.myMeshName = aMeshName.in();
273   VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[anEntity];
274   aMeshOnEntity2.mySupport = aMEDSupport;
275   if(anEntity == VISU::NODE_ENTITY)
276     aMesh2.myMeshOnEntityMap[VISU::CELL_ENTITY].mySupport = aMEDSupport;
277   GetCellsSize(aMesh,aMEDMesh,anEntity);
278
279   VISU::TField& aField = aMeshOnEntity.myFieldMap[aFieldName.in()];
280   aField.myId = myField->getOrderNumber();
281   aField.myName = aFieldName.in();
282   aField.myEntity = anEntity;
283   aField.myMeshName = aMeshName.in();
284   aField.myNbComp = myField->getNumberOfComponents();
285   aField.myNbValField = 1;
286   aField.myDataSize = aMeshOnEntity.myNbCells * aField.myNbComp;
287   aField.myCompNames.resize(aField.myNbComp);
288   aField.myUnitNames.resize(aField.myNbComp);
289   if(MYDEBUG) MESSAGE("VISU_MEDFieldConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh.myDim);
290   int iTimeStamp = myField->getIterationNumber();
291   VISU::TField::TValForTime& aValForTime = aField.myValField[iTimeStamp];
292   aValForTime.myId = iTimeStamp;
293   double dt = myField->getTime();
294   aValForTime.myTime = VISU::TField::TTime(dt,"");
295   
296   VISUMED::TField& aField2 = aMeshOnEntity2.myFieldMap[aFieldName.in()];
297   VISUMED::TField::TValForTime& aValForTime2 = aField2.myValField[iTimeStamp];
298   aValForTime2.myField = myField;
299   if(MYDEBUG) 
300     MESSAGE("VISU_MEDFieldConvertor::Build - aFieldName = '"<<aFieldName<<"'; myId = "<<aField.myId<<"; myTime = "<<dt);
301   return this;
302 }
303
304 VISU_Convertor* VISU_MEDConvertor::Build() {
305   if(mySObject->_is_nil()) 
306     throw std::runtime_error("VISU_MEDConvertor::Build >> mySObject->_is_nil() !!!");
307   SALOMEDS::Study_var aStudy = mySObject->GetStudy();
308
309   CORBA::Object_var aMedObject = SObjectToObject(mySObject);
310   if(!CORBA::is_nil(aMedObject)){
311     SALOME_MED::MED_var aMED = SALOME_MED::MED::_narrow(aMedObject);
312     return Build(aMED);
313   }
314
315   SALOMEDS::ChildIterator_var aTimeStampIterator = aStudy->NewChildIterator(mySObject);
316   return Build(aTimeStampIterator);
317 }
318
319
320 VISU_Convertor* VISU_MEDConvertor::Build(SALOME_MED::MED_ptr theMED)
321 {
322   if(theMED->_is_nil()) return NULL;
323   CORBA::Short aTag = mySObject->Tag();
324   SALOMEDS::SObject_var aMedCompSObj = mySObject->GetFather();
325   SALOMEDS::SObject_var aMeshSObj;
326   if(!aMedCompSObj->FindSubObject(aTag+1,aMeshSObj)) 
327     throw std::runtime_error("VISU_MEDConvertor::Build >> Cann't find MEDMESH label !!!");
328   if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - MEDMESH found.");
329   SALOMEDS::Study_var aStudy = mySObject->GetStudy();
330   SALOMEDS::ChildIterator_var aMeshIterator = aStudy->NewChildIterator(aMeshSObj);
331   for(; aMeshIterator->More(); aMeshIterator->Next()){
332     aMeshSObj = aMeshIterator->Value();
333     if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aMeshSObj = '"<<::GetName(aMeshSObj)<<"'");
334     CORBA::Object_var aMedMesh = SObjectToObject(aMeshSObj);
335     if(CORBA::is_nil(aMedMesh)) continue;
336     SALOME_MED::MESH_var aMEDMesh = SALOME_MED::MESH::_narrow(aMedMesh);
337     if(aMEDMesh->_is_nil()) continue;
338     CORBA::String_var aMeshName = aMEDMesh->getName();
339     VISU::TMesh &aMesh = myMeshMap[aMeshName.in()];
340     aMesh.myDim = aMEDMesh->getSpaceDimension();
341     aMesh.myName = aMeshName.in();
342     aMesh.myPointsDim.resize(aMesh.myDim);
343     VISUMED::TMesh &aMesh2 = myMeshMap2[aMeshName.in()];
344     aMesh2.myMesh = aMEDMesh;
345     if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh.myDim);
346     SALOMEDS::ChildIterator_var aSupportIterator = aStudy->NewChildIterator(aMeshSObj);
347     for(; aSupportIterator->More(); aSupportIterator->Next()){
348       SALOMEDS::SObject_var aSupportSObj = aSupportIterator->Value();
349       CORBA::Object_var aMedSupport = SObjectToObject(aSupportSObj);
350       if(CORBA::is_nil(aMedSupport)) continue;
351       SALOME_MED::SUPPORT_var aMEDSupport = SALOME_MED::SUPPORT::_narrow(aMedSupport); 
352       if(aMEDSupport->_is_nil()) continue;
353       SALOME_MED::MESH_var aMeshOnSupport = aMEDSupport->getMesh();
354       SALOME_MED::medEntityMesh aMEDEntity = aMEDSupport->getEntity();
355       VISU::TEntity anEntity = aMed2VisuEntity[aMEDEntity];
356       CORBA::String_var aSupportName = aMEDSupport->getName();
357       if(aMEDSupport->isOnAllElements()){
358         if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - Support isOnAllElements = '"<<aSupportName<<"' anEntity = "<<anEntity);
359         int aNbCells, aCellsSize;
360         //Check, if there is any data on the support?
361         if(anEntity == VISU::NODE_ENTITY){
362           aMesh.myNbPoints = aMeshOnSupport->getNumberOfNodes();
363           aNbCells = aMesh.myNbPoints;
364           aCellsSize = 2*aMesh.myNbPoints;
365         }else{
366           GetCellsSize(aNbCells,aCellsSize,aMeshOnSupport,anEntity);
367         }
368         if(aNbCells == 0) continue;
369         VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
370         aMeshOnEntity.myMeshName = aMeshName.in();
371         aMeshOnEntity.myEntity = anEntity;
372         aMeshOnEntity.myNbCells = aNbCells;
373         aMeshOnEntity.myCellsSize = aCellsSize;
374         
375         VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[anEntity];
376         aMeshOnEntity2.mySupport = aMEDSupport;
377       }else{
378         SALOME_MED::FAMILY_var aMEDFamily = SALOME_MED::FAMILY::_narrow(aMedSupport);
379         if(!aMEDFamily->_is_nil()) {
380           int aNbCells, aCellsSize;
381           GetCellsSize(aNbCells,aCellsSize,aMEDFamily);
382           if(aNbCells > 0){
383             if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aFamily = '"<<aSupportName<<"' anEntity = "<<anEntity);
384             VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
385             VISU::TFamily& aFamily = aMeshOnEntity.myFamilyMap[aSupportName.in()];
386             aFamily.myName = aSupportName.in();
387             aFamily.myEntity = anEntity;
388             aFamily.myNbCells = aNbCells;
389             aFamily.myCellsSize = aCellsSize;
390             aFamily.myId = aMEDFamily->getIdentifier();
391             
392             VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[anEntity];
393             VISUMED::TFamily& aFamily2 = aMeshOnEntity2.myFamilyMap[aSupportName.in()];
394             aFamily2.myFamily = aMEDFamily;
395           }
396         }
397         SALOME_MED::GROUP_var aMEDGroup = SALOME_MED::GROUP::_narrow(aMedSupport);
398         if(!aMEDGroup->_is_nil()) {
399           if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aGroup = '"<<aSupportName<<"' anEntity = "<<anEntity);
400           VISUMED::TGroupMap& aGroupMap2 = aMesh2.myGroupMap;
401           VISUMED::TGroup& aGroup2 = aGroupMap2[aSupportName.in()];
402           aGroup2.myGroup = aMEDGroup;
403           SALOME_MED::Family_array_var aFamilies = aMEDGroup->getFamilies();
404           int iFamilyEnd = aFamilies->length();
405           for(int iFamaily = 0; iFamaily < iFamilyEnd; iFamaily++){
406             aMEDFamily = aFamilies[iFamaily];
407             CORBA::String_var aFamilyName = aMEDFamily->getName();
408             VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
409             if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aGroup - aFamilyName = '"<<aFamilyName.in()<<"'");
410             VISU::TFamily& aFamily = aMeshOnEntity.myFamilyMap[aFamilyName.in()];
411             VISU::TBindGroups& aBindGroups = aFamily.myGroups;
412             aBindGroups.insert(aSupportName.in());
413           }
414         }
415       }
416     }
417     //Correction of TMesh.TGroupMap
418     const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh.myMeshOnEntityMap;
419     if(aMeshOnEntityMap.empty()) continue;
420     VISU::TGroupMap& aGroupMap = aMesh.myGroupMap;
421     VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
422     for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
423       const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
424       const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity.myFamilyMap;
425       if(aFamilyMap.empty()) continue;
426       VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
427       for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
428         const VISU::TFamily& aFamily = aFamilyMapIter->second;
429         const VISU::TBindGroups& aBindGroups = aFamily.myGroups;
430         if(aBindGroups.empty()) continue;
431         VISU::TBindGroups::const_iterator aBindGroupsIter = aBindGroups.begin();
432         for(; aBindGroupsIter != aBindGroups.end(); aBindGroupsIter++){
433           const string& aGroupName = *aBindGroupsIter;
434           VISU::TGroup& aGroup = aGroupMap[aGroupName];
435           aGroup.myName = aGroupName;
436           aGroup.myMeshName = aMesh.myName;
437           aGroup.myNbCells += aFamily.myNbCells;
438           aGroup.myCellsSize += aFamily.myCellsSize;
439           VISU::TFamilyAndEntity aFamilyAndEntity(aFamily.myName,aFamily.myEntity);
440           aGroup.myFamilyAndEntitySet.insert(aFamilyAndEntity);
441         }
442       }
443     }
444   }
445   SALOMEDS::SObject_var aFieldSObj;
446   if(aMedCompSObj->FindSubObject(aTag+2,aFieldSObj)){
447     if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - MEDFIELD found.");
448     SALOMEDS::ChildIterator_var aFieldIterator = aStudy->NewChildIterator(aFieldSObj);
449     for(int iField = 0; aFieldIterator->More(); aFieldIterator->Next(), iField++){
450       aFieldSObj = aFieldIterator->Value();
451       if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aFieldName = '"<<::GetName(aFieldSObj)<<"'");
452       SALOMEDS::ChildIterator_var aTimeStampIterator = aStudy->NewChildIterator(aFieldSObj);
453       for(int iTimeStamp = 1; aTimeStampIterator->More(); aTimeStampIterator->Next(), iTimeStamp++){
454         SALOMEDS::SObject_var aTimeStampSObj = aTimeStampIterator->Value();
455         if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aTimeStampSObj = '"<<::GetName(aTimeStampSObj)<<"'");
456         CORBA::Object_var aMedField = SObjectToObject(aTimeStampSObj);
457         if(CORBA::is_nil(aMedField)) continue;
458         SALOME_MED::FIELD_var aMEDField = SALOME_MED::FIELD::_narrow(aMedField);
459         if(aMEDField->_is_nil()) continue;
460         SALOME_MED::SUPPORT_var aMEDSupport = aMEDField->getSupport();
461         if(aMEDSupport->_is_nil()) continue;
462         SALOME_MED::medEntityMesh aMEDEntity = aMEDSupport->getEntity();
463         VISU::TEntity anEntity = aMed2VisuEntity[aMEDEntity];
464         SALOME_MED::MESH_var aMEDMesh = aMEDSupport->getMesh();
465         if(aMEDMesh->_is_nil()) continue;
466         CORBA::String_var aMeshName = aMEDMesh->getName();
467         CORBA::String_var aFieldName = aMEDField->getName();
468         
469         VISU::TMesh &aMesh = myMeshMap[aMeshName.in()];
470         aMesh.myDim = aMEDMesh->getSpaceDimension();
471         aMesh.myName = aMeshName.in();
472         VISUMED::TMesh &aMesh2 = myMeshMap2[aMeshName.in()];
473         aMesh2.myMesh = aMEDMesh;
474         
475         VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
476         aMeshOnEntity.myEntity = anEntity;
477         aMeshOnEntity.myMeshName = aMeshName.in();
478         VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[anEntity];
479         aMeshOnEntity2.mySupport = aMEDSupport;
480         if(anEntity == VISU::NODE_ENTITY)
481           aMesh2.myMeshOnEntityMap[VISU::CELL_ENTITY].mySupport = aMEDSupport;
482         GetCellsSize(aMesh,aMEDMesh,anEntity);
483         
484         VISU::TField& aField = aMeshOnEntity.myFieldMap[aFieldName.in()];
485         aField.myId = iField;
486         aField.myName = aFieldName.in();
487         aField.myEntity = anEntity;
488         aField.myMeshName = aMeshName.in();
489         aField.myNbComp = aMEDField->getNumberOfComponents();
490         aField.myNbValField = iTimeStamp;
491         aField.myDataSize = aMeshOnEntity.myNbCells * aField.myNbComp;
492         if(MYDEBUG && !iTimeStamp) 
493           MESSAGE("VISU_MEDConvertor::Build - aMeshOnEntity.myNbCells = "<<aMeshOnEntity.myNbCells);
494         aField.myCompNames.resize(aField.myNbComp);
495         aField.myUnitNames.resize(aField.myNbComp);
496         
497         int anId = aMEDField->getIterationNumber();
498         VISU::TField::TValForTime& aValForTime = aField.myValField[anId];
499         aValForTime.myId = anId;
500         aValForTime.myTime = VISU::TField::TTime(aMEDField->getTime(),"");
501         VISUMED::TField& aField2 = aMeshOnEntity2.myFieldMap[aFieldName.in()];
502         VISUMED::TField::TValForTime& aValForTime2 = aField2.myValField[anId];
503         aValForTime2.myField = aMEDField;
504         if(MYDEBUG) 
505           MESSAGE("VISU_MEDConvertor::Build - aMeshName = '"<<aMeshName<<
506                   "'; myEntity = "<<anEntity<<"; myTime = "<<aValForTime.myTime.first);
507       }      
508     }
509   }
510   return this; 
511 }
512  
513
514 VISU_Convertor* VISU_MEDConvertor::Build(SALOMEDS::ChildIterator_ptr theTimeStampIterator)
515 {
516   if(theTimeStampIterator->_is_nil()) return NULL;
517   for(int iTimeStamp = 1; theTimeStampIterator->More(); theTimeStampIterator->Next(), iTimeStamp++){
518     SALOMEDS::SObject_var aTimeStampSObj = theTimeStampIterator->Value();
519     if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aTimeStampSObj = '"<<::GetName(aTimeStampSObj)<<"'");
520     CORBA::Object_var aMedField = SObjectToObject(aTimeStampSObj);
521     if(CORBA::is_nil(aMedField)) continue;
522     SALOME_MED::FIELD_var aMEDField = SALOME_MED::FIELD::_narrow(aMedField);
523     if(aMEDField->_is_nil()) continue;
524     SALOME_MED::SUPPORT_var aMEDSupport = aMEDField->getSupport();
525     if(aMEDSupport->_is_nil()) continue;
526     SALOME_MED::medEntityMesh aMEDEntity = aMEDSupport->getEntity();
527     VISU::TEntity anEntity = aMed2VisuEntity[aMEDEntity];
528     SALOME_MED::MESH_var aMEDMesh = aMEDSupport->getMesh();
529     if(aMEDMesh->_is_nil()) continue;
530     CORBA::String_var aMeshName = aMEDMesh->getName();
531     CORBA::String_var aFieldName = aMEDField->getName();
532
533     VISU::TMesh &aMesh = myMeshMap[aMeshName.in()];
534     aMesh.myDim = aMEDMesh->getSpaceDimension();
535     aMesh.myPointsDim.resize(aMesh.myDim);
536     aMesh.myName = aMeshName.in();
537     aMesh.myNbPoints = aMEDMesh->getNumberOfNodes();
538     VISUMED::TMesh &aMesh2 = myMeshMap2[aMeshName.in()];
539     aMesh2.myMesh = aMEDMesh;
540     if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh.myDim);
541
542     VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
543     aMeshOnEntity.myEntity = anEntity;
544     aMeshOnEntity.myMeshName = aMeshName.in();
545     VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[anEntity];
546     aMeshOnEntity2.mySupport = aMEDSupport;
547     if(anEntity == VISU::NODE_ENTITY)
548       aMesh2.myMeshOnEntityMap[VISU::CELL_ENTITY].mySupport = aMEDSupport;
549     GetCellsSize(aMesh,aMEDMesh,anEntity);
550
551     VISU::TField& aField = aMeshOnEntity.myFieldMap[aFieldName.in()];
552     CORBA::Short iField = mySObject->Tag();
553     aField.myId = iField;
554     aField.myName = aFieldName.in();
555     aField.myEntity = anEntity;
556     aField.myMeshName = aMeshName.in();
557     aField.myNbComp = aMEDField->getNumberOfComponents();
558     aField.myNbValField = iTimeStamp;
559     aField.myDataSize = aMeshOnEntity.myNbCells * aField.myNbComp;
560     if(MYDEBUG && !iTimeStamp) 
561       MESSAGE("VISU_MEDConvertor::Build - aMeshOnEntity.myNbCells = "<<aMeshOnEntity.myNbCells);
562     aField.myCompNames.resize(aField.myNbComp);
563     aField.myUnitNames.resize(aField.myNbComp);
564
565     int anId = aMEDField->getIterationNumber();
566     VISU::TField::TValForTime& aValForTime = aField.myValField[anId];
567     aValForTime.myId = anId;
568     aValForTime.myTime = VISU::TField::TTime(aMEDField->getTime(),"");
569     VISUMED::TField& aField2 = aMeshOnEntity2.myFieldMap[aFieldName.in()];
570     VISUMED::TField::TValForTime& aValForTime2 = aField2.myValField[anId];
571     aValForTime2.myField = aMEDField;
572     if(MYDEBUG) 
573       MESSAGE("VISU_MEDConvertor::Build - aMeshName = '"<<aMeshName<<
574               "'; myEntity = "<<anEntity<<"; myTime = "<<aValForTime.myTime.first);
575   }
576   return this; 
577 }
578
579
580 int VISU_MEDConvertor::LoadMeshOnEntity(VISU::TMeshOnEntity& theMeshOnEntity, 
581                                         const string& theFamilyName)
582 {
583   //Main part of code
584   const string& aMeshName = theMeshOnEntity.myMeshName;
585   const VISU::TEntity& anEntity = theMeshOnEntity.myEntity;
586   VISU::TMesh& aMesh = myMeshMap[aMeshName];
587   int isPointsUpdated;
588   if(anEntity == VISU::NODE_ENTITY) 
589     isPointsUpdated = LoadPoints(aMesh,theFamilyName);
590   else 
591     isPointsUpdated = LoadPoints(aMesh);
592   int isCellsOnEntityUpdated = LoadCellsOnEntity(theMeshOnEntity,theFamilyName);
593
594   return (isPointsUpdated || isCellsOnEntityUpdated);
595 }
596   
597 int VISU_MEDConvertor::LoadMeshOnGroup(VISU::TMesh& theMesh, 
598                                        const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet)
599 {
600   //Main part of code
601   int isPointsUpdated = 0;
602   int isCellsOnEntityUpdated = 0;
603   VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = theFamilyAndEntitySet.begin();
604   for(; aFamilyAndEntitySetIter != theFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){
605     const string& aFamilyName = aFamilyAndEntitySetIter->first;
606     const VISU::TEntity& anEntity = aFamilyAndEntitySetIter->second;
607     VISU::TMeshOnEntity& aMeshOnEntity = theMesh.myMeshOnEntityMap[anEntity];
608     if(anEntity == VISU::NODE_ENTITY){
609       isPointsUpdated += LoadPoints(theMesh,aFamilyName);
610       isCellsOnEntityUpdated += LoadCellsOnEntity(aMeshOnEntity);
611     }else{
612       isPointsUpdated += LoadPoints(theMesh);
613       isCellsOnEntityUpdated += LoadCellsOnEntity(aMeshOnEntity,aFamilyName);
614     }
615   }
616
617   return (isPointsUpdated || isCellsOnEntityUpdated);
618 }
619
620 int VISU_MEDConvertor::LoadFieldOnMesh(VISU::TMesh& theMesh, 
621                                        VISU::TMeshOnEntity& theMeshOnEntity, 
622                                        VISU::TField& theField, 
623                                        VISU::TField::TValForTime& theValForTime)
624 {
625   //Main part of code
626   int isPointsUpdated = LoadPoints(theMesh);
627   int isCellsOnEntityUpdated = LoadCellsOnEntity(theMeshOnEntity);
628   int isFieldUpdated = LoadField(theMeshOnEntity,theField,theValForTime);
629   
630   return (isPointsUpdated || isCellsOnEntityUpdated || isFieldUpdated);
631 }
632
633 int VISU_MEDConvertor::LoadPoints(VISU::TMesh& theMesh, const string& theFamilyName)
634 {
635   //Check on existing family
636   VISU::TMeshOnEntity& aMeshOnEntity = theMesh.myMeshOnEntityMap[VISU::NODE_ENTITY];
637   aMeshOnEntity.myEntity = VISU::NODE_ENTITY;
638   aMeshOnEntity.myMeshName = theMesh.myName;
639   VISU::TFamily* pFamily = VISU::GetFamily(aMeshOnEntity,theFamilyName);
640   bool isFamilyPresent = (pFamily != NULL);
641   VISU::TFamily& aFamily = *pFamily;
642   //Check on loading already done
643   bool isPointsLoaded = !theMesh.myPointsCoord.empty();
644   if(isPointsLoaded) 
645     if(!isFamilyPresent) return 0;
646     else if(!aFamily.mySubMesh.empty()) return 0;
647   VISUMED::TMesh& aMesh2 = myMeshMap2[theMesh.myName];
648   SALOME_MED::MESH_var& aMedMesh = aMesh2.myMesh;
649   VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[VISU::NODE_ENTITY];
650   if(MYDEBUG) 
651     MESSAGE("LoadPoints - isPointsLoaded = "<<isPointsLoaded<<"; theFamilyName = '"<<theFamilyName<<"'");
652   theMesh.myDim = aMedMesh->getSpaceDimension();
653   int iNumElemEnd = aMedMesh->getNumberOfNodes();
654   VISU::TMesh::TPointsCoord& aPointsCoord = theMesh.myPointsCoord;
655   if(MYDEBUG) MESSAGE("LoadPoints - iNumElemEnd = "<<iNumElemEnd);
656   if (iNumElemEnd <= 0) throw std::runtime_error("LoadPoints >> There is no points in the mesh !!!");
657   aPointsCoord.resize(theMesh.myDim*iNumElemEnd,0.0);
658    SALOME_MED::double_array_var coord = aMedMesh->getCoordinates(SALOME_MED::MED_FULL_INTERLACE);
659   if(!isPointsLoaded){
660     for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) 
661       for(int iDim = 0, iNumElem2Dim = iNumElem*theMesh.myDim; iDim < theMesh.myDim; iDim++, iNumElem2Dim++)
662         aPointsCoord[iNumElem2Dim] = coord[iNumElem2Dim];
663     if(MYDEBUG) MESSAGE("LoadPoints - Filling aMeshOnEntity with type NODE_ENTITY");
664     VISU::TMeshOnEntity::TConnForCellType& aConnForCellType = aMeshOnEntity.myCellsConn[VTK_VERTEX];
665     aConnForCellType.resize(iNumElemEnd);
666     for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
667       aConnForCellType[iNumElem] = VISU::TMeshOnEntity::TConnect(1,iNumElem);
668   }
669   if(isFamilyPresent){
670     if(MYDEBUG) MESSAGE("LoadPoints - Filling aFamily SubMesh");
671     VISUMED::TFamily aFamily2 = aMeshOnEntity2.myFamilyMap[aFamily.myName];
672     SALOME_MED::FAMILY_var aMedFamily = aFamily2.myFamily;
673     VISU::TFamily::TSubMeshOnCellType& aSubMeshOnCellType = aFamily.mySubMesh[VTK_VERTEX];
674     SALOME_MED::medGeometryElement_array_var aGeom = aMedFamily->getTypes();
675     SALOME_MED::long_array_var aCellNumForType = aMedFamily->getNumber(aGeom[0]);
676     int iNumElemEndTmp = iNumElemEnd;
677     iNumElemEnd = aCellNumForType->length();
678     for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) {
679       int tmp = aCellNumForType[iNumElem]-1;
680       if(0 > tmp || tmp >= iNumElemEndTmp) {
681         static QString aString;
682         aString.sprintf("LoadPoints >> iNumElemEndTmp(%d) <= aCellNumForType[%d]=%d < 0 !!!",iNumElemEnd,iNumElem,tmp);
683         throw std::runtime_error(aString.latin1());
684       }
685       aSubMeshOnCellType.insert(tmp);
686     }
687   }
688   return 1;
689 }
690
691 int VISU_MEDConvertor::LoadCellsOnEntity(VISU::TMeshOnEntity& theMeshOnEntity, const string& theFamilyName)
692 {
693   //Check on existing family
694   VISU::TFamily* pFamily = VISU::GetFamily(theMeshOnEntity,theFamilyName);
695   bool isFamilyPresent = (pFamily != NULL);
696   VISU::TFamily& aFamily = *pFamily;
697   //Check on loading already done
698   bool isCellsLoaded = !theMeshOnEntity.myCellsConn.empty();
699   if(isCellsLoaded) 
700     if(!isFamilyPresent) return 0;
701     else if(!aFamily.mySubMesh.empty()) return 0;
702   VISUMED::TMesh& aMesh2 = myMeshMap2[theMeshOnEntity.myMeshName];
703   VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[theMeshOnEntity.myEntity];
704   SALOME_MED::SUPPORT_var& aMedSupport = aMeshOnEntity2.mySupport;
705   SALOME_MED::MESH_var aMedMesh = aMedSupport->getMesh();
706   if(MYDEBUG) {
707     MESSAGE("LoadCellsOnEntity - theFamilyName = '"<<theFamilyName<<"'");
708     MESSAGE("LoadCellsOnEntity - isCellsLoaded = "<<isCellsLoaded<<"; isFamilyPresent = "<<isFamilyPresent);
709   }
710   //Main part of code
711   int iGeomElemEnd;
712   int* aGeomElemVector;
713   const VISU::TEntity& anEntity = theMeshOnEntity.myEntity;
714   GetEntity2Geom(anEntity,aGeomElemVector,&iGeomElemEnd);
715   const SALOME_MED::medEntityMesh& aMedEntity = aVisu2MedEntity[anEntity];
716   VISU::TMesh &aMesh = myMeshMap[theMeshOnEntity.myMeshName];
717   int aNbPoints = aMesh.myPointsCoord.size()/aMesh.myDim;
718   if(!isCellsLoaded){
719     for (int iGeomElem = 0, aCounter = 0; iGeomElem < iGeomElemEnd; iGeomElem++) {
720       int medId = GetIdMEDType(aGeomElemVector[iGeomElem]);
721       int nbMedNodes = salome_med2vtk[medId].medNbNodes;
722       int nbVtkNodes = salome_med2vtk[medId].vtkNbNodes;
723       int aVtkType = salome_med2vtk[medId].vtkType;
724       SALOME_MED::medGeometryElement aMedType = salome_med2vtk[medId].medType;
725       med_int iNumElemEnd = aMedMesh->getNumberOfElements(aMedEntity,aMedType);
726       if (iNumElemEnd > 0) {
727         SALOME_MED::long_array_var conn = 
728           aMedMesh->getConnectivity(SALOME_MED::MED_FULL_INTERLACE,SALOME_MED::MED_NODAL,aMedEntity,aMedType);
729         VISU::TMeshOnEntity::TConnForCellType& aConnForCellType = theMeshOnEntity.myCellsConn[aVtkType];
730         //APO - aConnForCellType.resize(iNumElemEnd);
731         valarray<med_int> aConnect(nbMedNodes);
732         int aNbConnForElem = conn->length()/iNumElemEnd;
733         if(MYDEBUG) MESSAGE("LoadCellsOnEntity - medName = "<<salome_med2vtk[medId].medName<<
734                             "; iNumElemEnd = "<<iNumElemEnd<<"; aNbConnForElem = "<<aNbConnForElem);
735         for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) {
736           //APO - VISU::TMeshOnEntity::TConnect& anArray = aConnForCellType[iNumElem];
737           //APO - anArray.resize(nbVtkNodes);
738           VISU::TMeshOnEntity::TConnect anArray(nbVtkNodes);
739           for (int k = 0, kj = iNumElem*aNbConnForElem; k < nbMedNodes; k++) {
740             aConnect[k] = conn[kj+k] - 1;
741           }
742           switch(aMedType){
743           case SALOME_MED::MED_TETRA4 :
744           case SALOME_MED::MED_TETRA10 :
745             anArray[0] = aConnect[0];
746             anArray[1] = aConnect[1];
747             anArray[2] = aConnect[3];  
748             anArray[3] = aConnect[2];  
749             break;
750           case SALOME_MED::MED_PYRA5 :
751           case SALOME_MED::MED_PYRA13 :
752             anArray[0] = aConnect[0];
753             anArray[1] = aConnect[3];  
754             anArray[2] = aConnect[2];
755             anArray[3] = aConnect[1];  
756             anArray[4] = aConnect[4];
757             break;
758           default:
759             for (int k = 0; k < nbVtkNodes; k++) 
760               anArray[k] = aConnect[k];
761           }
762           for (int k = 0; k < nbVtkNodes; k++) 
763             if(anArray[k] < 0 || aNbPoints <= anArray[k]){
764               static QString aString;
765               aString.sprintf("ImportCells >> aNbPoints(%d) <= anArray[%d][%d]=%d < 0 !!!",aNbPoints,iNumElem,k,anArray[k]);
766               throw std::runtime_error(aString.latin1());
767             }
768           aConnForCellType.push_back(anArray);
769         }
770         //Workaround for MED Component data structure
771         int aSize = aConnForCellType.size();
772         aMeshOnEntity2.myCellsFirstIndex[aMedType] = VISUMED::TMeshOnEntity::TIndexAndSize(aCounter,aSize);
773         aCounter += aSize;
774       }
775     }
776   }
777   //Filling aFamily SubMesh
778   if(isFamilyPresent){
779     VISUMED::TFamily aFamily2 = aMeshOnEntity2.myFamilyMap[aFamily.myName];
780     SALOME_MED::FAMILY_var aMedFamily = aFamily2.myFamily;
781     SALOME_MED::medGeometryElement_array_var aGeom = aMedFamily->getTypes();
782     iGeomElemEnd = aGeom->length();
783     if(MYDEBUG) MESSAGE("LoadCellsOnEntity - iGeomElemEnd = "<<iGeomElemEnd);
784     for (int iGeomElem = 0; iGeomElem < iGeomElemEnd; iGeomElem++) {
785       SALOME_MED::medGeometryElement aGeomType = aGeom[iGeomElem];
786       SALOME_MED::long_array_var aCellNumForType = aMedFamily->getNumber(aGeomType);
787       int medId = GetIdMEDType(aGeomType);
788       int aVtkType = salome_med2vtk[medId].vtkType;
789       SALOME_MED::medGeometryElement aMedType = salome_med2vtk[medId].medType;
790       VISU::TFamily::TSubMeshOnCellType& aSubMeshOnCellType = aFamily.mySubMesh[aVtkType]; 
791       med_int iNumElemEndTmp = theMeshOnEntity.myCellsConn[aVtkType].size();
792       med_int iNumElemEnd = aCellNumForType->length();
793       int aCounter = aMeshOnEntity2.myCellsFirstIndex[aMedType].first;
794       if(MYDEBUG) 
795         MESSAGE("LoadCellsOnEntity - medName = "<<salome_med2vtk[medId].medName<<
796                 "; iNumElemEnd = "<<iNumElemEnd<<"; aCounter = "<<aCounter);
797       for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) {
798         int tmp = aCellNumForType[iNumElem]-aCounter-1;
799         if(0 > tmp || tmp >= iNumElemEndTmp) {
800           static QString aString;
801           aString.sprintf("LoadCellsOnEntity >> iNumElemEndTmp(%d) <= aCellNumForType[%d]=%d < 0 !!!",iNumElemEndTmp,iNumElem,tmp);
802           throw std::runtime_error(aString.latin1());
803         }
804         aSubMeshOnCellType.insert(tmp);
805       }
806     }
807   }
808   return 1;
809 }
810
811 template<class TArray> int ImportField(TArray& theArray, 
812                                        const VISU::TMesh& theMesh,
813                                        const VISU::TField& theField,
814                                        VISU::TField::TValForTime& theValForTime,
815                                        const VISU::TMeshOnEntity& theMeshOnEntity,
816                                        const VISUMED::TMeshOnEntity& theMeshOnEntity2)
817 {
818   if(theField.myEntity == VISU::NODE_ENTITY){
819     VISU::TField::TValForCellsWithType& aValForCellsWithType = theValForTime.myValForCells[VTK_VERTEX];
820     int iNumElemEnd = theMesh.myPointsCoord.size()/theMesh.myDim*theField.myNbComp;
821     if(MYDEBUG) MESSAGE("ImportField - iNumElemEnd = "<<iNumElemEnd);
822     aValForCellsWithType.resize(iNumElemEnd);
823     for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) 
824       aValForCellsWithType[iNumElem] = theArray[iNumElem];
825   }else{
826     int iGeomElemEnd;
827     int* aGeomElemVector;
828     const VISU::TEntity& anEntity = theField.myEntity;
829     GetEntity2Geom(anEntity,aGeomElemVector,&iGeomElemEnd);
830     for (int iGeomElem = 0, aCounter = 0; iGeomElem < iGeomElemEnd; iGeomElem++) {
831       int medId = GetIdMEDType(aGeomElemVector[iGeomElem]);
832       int aVtkType = salome_med2vtk[medId].vtkType;
833       SALOME_MED::medGeometryElement aMedType = salome_med2vtk[medId].medType;
834       const VISUMED::TMeshOnEntity::TCellsFirstIndex& aCellsFirstIndex = theMeshOnEntity2.myCellsFirstIndex;
835       VISUMED::TMeshOnEntity::TCellsFirstIndex::const_iterator aCellsFirstIndexIter = aCellsFirstIndex.find(aMedType);
836       if(aCellsFirstIndexIter != aCellsFirstIndex.end()){
837         const VISU::TMeshOnEntity::TCellsConn& aCellsConn = theMeshOnEntity.myCellsConn;
838         VISU::TMeshOnEntity::TCellsConn::const_iterator aCellsConnIter = aCellsConn.find(aVtkType);
839         const VISU::TMeshOnEntity::TConnForCellType& aConnForCellType = aCellsConnIter->second;
840         const VISUMED::TMeshOnEntity::TIndexAndSize& aIndexAndSize = aCellsFirstIndexIter->second;
841         int iNumElemEnd = aIndexAndSize.second;
842         if(MYDEBUG) 
843           MESSAGE("ImportField - medName = "<<salome_med2vtk[medId].medName<<
844                   "; aIndexAndSize = {"<<aIndexAndSize.first<<","<<aIndexAndSize.second<<"}");
845         VISU::TField::TValForCellsWithType& aValForCellsWithType = theValForTime.myValForCells[aVtkType];
846         aValForCellsWithType.resize(iNumElemEnd*theField.myNbComp);
847         for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
848           for (int k = 0, kj = iNumElem*theField.myNbComp; k < theField.myNbComp; k++)
849             aValForCellsWithType[kj+k] = theArray[aIndexAndSize.first*theField.myNbComp+kj+k];
850       }
851     }
852   }
853   return 1;
854 }
855
856 int VISU_MEDConvertor::LoadField(const VISU::TMeshOnEntity& theMeshOnEntity,
857                                  const VISU::TField& theField, VISU::TField::TValForTime& theValForTime)
858 {
859   //Check on loading already done
860   if(!theValForTime.myValForCells.empty()) return 0;
861   VISU::TMesh& aMesh = myMeshMap[theMeshOnEntity.myMeshName];
862   VISUMED::TMesh& aMesh2 = myMeshMap2[theMeshOnEntity.myMeshName];
863   VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[theMeshOnEntity.myEntity];
864   VISUMED::TField& aField2 = aMeshOnEntity2.myFieldMap[theField.myName];
865   VISUMED::TField::TValForTime& aValForTime2 = aField2.myValField[theValForTime.myId];
866   SALOME_MED::FIELD_var aMEDField = aValForTime2.myField;
867   //Main part of code
868   SALOME_MED::FIELDDOUBLE_ptr aFieldDouble = SALOME_MED::FIELDDOUBLE::_narrow(aMEDField);
869   if(!aFieldDouble->_is_nil()){
870     SALOME_MED::double_array_var anArray = aFieldDouble->getValue(SALOME_MED::MED_FULL_INTERLACE);
871     if(MYDEBUG) MESSAGE("VISU_MEDConvertor::LoadField - There is FIELDDOUBLE = "<<anArray->length());
872     ::ImportField(anArray,aMesh,theField,theValForTime,theMeshOnEntity,aMeshOnEntity2);
873   }
874   SALOME_MED::FIELDINT_ptr aFieldInt = SALOME_MED::FIELDINT::_narrow(aMEDField);
875   if(!aFieldInt->_is_nil()){
876     SALOME_MED::long_array_var anArray = aFieldInt->getValue(SALOME_MED::MED_FULL_INTERLACE);
877     if(MYDEBUG) MESSAGE("VISU_MEDConvertor::LoadField - There is FIELDINT = "<<anArray->length());
878     ::ImportField(anArray,aMesh,theField,theValForTime,theMeshOnEntity,aMeshOnEntity2);
879   }
880   return 1;
881 }