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