Salome HOME
Merge with OCC_development_01
[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 <vtkCellType.h>
33
34 #include <boost/tuple/tuple.hpp>
35
36 using namespace std;
37 using namespace VISU;
38
39 #define USER_INTERLACE MED_FULL_INTERLACE
40
41 #ifdef _DEBUG_
42 static int MYDEBUG = 1;
43 #else
44 static int MYDEBUG = 0;
45 #endif
46
47 extern "C" {
48   VISU_Convertor* CreateMEDConvertor(SALOMEDS::SObject_ptr theMedSObject) {
49     return new VISU_MEDConvertor(theMedSObject);
50   }
51   VISU_Convertor* CreateMEDFieldConvertor(SALOME_MED::FIELD_ptr theField) {
52     return new VISU_MEDFieldConvertor(theField);
53   }
54 }
55
56 namespace{
57   using namespace SALOME_MED;
58   
59   const int MED_NBR_GEOMETRIE_MAILLE = 15;
60   
61   medGeometryElement 
62   CELLGEOM[MED_NBR_GEOMETRIE_MAILLE] = {
63     MED_POINT1,
64     MED_SEG2,
65     MED_SEG3,
66     MED_TRIA3,
67     MED_QUAD4,
68     MED_TRIA6,
69     MED_QUAD8,
70     MED_TETRA4,
71     MED_PYRA5,
72     MED_PENTA6,
73     MED_HEXA8,
74     MED_TETRA10,
75     MED_PYRA13,
76     MED_PENTA15,
77     MED_HEXA20
78   };
79   
80   const int MED_NBR_GEOMETRIE_FACE = 4;
81   
82   medGeometryElement
83   FACEGEOM[MED_NBR_GEOMETRIE_FACE] = {
84     MED_TRIA3,
85     MED_QUAD4,
86     MED_TRIA6,
87     MED_QUAD8
88   };
89   
90   const int MED_NBR_GEOMETRIE_ARETE = 2;
91   
92   medGeometryElement
93   EDGEGEOM[MED_NBR_GEOMETRIE_ARETE] = {
94     MED_SEG2,
95     MED_SEG3
96   };
97   
98   const int MED_NBR_GEOMETRIE_NODE = 1;
99   
100   medGeometryElement
101   NODEGEOM[MED_NBR_GEOMETRIE_NODE] = {
102     MED_POINT1,
103   };
104   
105   int GetEntity2Geom(const VISU::TEntity& theEntity, medGeometryElement*& theVector)
106   {
107     switch(theEntity){
108     case CELL_ENTITY: theVector = CELLGEOM; return MED_NBR_GEOMETRIE_MAILLE; break;
109     case FACE_ENTITY: theVector = FACEGEOM; return MED_NBR_GEOMETRIE_FACE; break;
110     case EDGE_ENTITY: theVector = EDGEGEOM; return MED_NBR_GEOMETRIE_ARETE; break;
111     case NODE_ENTITY: theVector = NODEGEOM; return MED_NBR_GEOMETRIE_NODE; break;
112     }
113     return -1;
114   }
115   
116   int MEDGeom2NbNodes(int theMEDGeomType)
117   { 
118     switch(theMEDGeomType){
119     case MED_NONE: return 0;
120     case MED_POINT1: return 1;
121     case MED_SEG2: return 2;
122     case MED_SEG3: return 3;
123     case MED_TRIA3: return 3;
124     case MED_TRIA6: return 6;
125     case MED_QUAD4: return 4;
126     case MED_QUAD8: return 8;
127     case MED_TETRA4: return 4;
128     case MED_TETRA10: return 10;
129     case MED_HEXA8: return 8;
130     case MED_HEXA20: return 20;
131     case MED_PENTA6: return 6;
132     case MED_PENTA15: return 15;
133     case MED_PYRA5: return 5;
134     case MED_PYRA13: return 13;
135     }
136     return -1;
137   }
138   
139   int MEDGeomToVTK(medGeometryElement theMEDGeomType)
140   { 
141     switch(theMEDGeomType){
142     case MED_NONE: return VTK_EMPTY_CELL;
143     case MED_POINT1: return VTK_VERTEX;
144     case MED_SEG2: return VTK_LINE;
145     case MED_SEG3: return VTK_LINE;
146     case MED_TRIA3: return VTK_TRIANGLE;
147     case MED_TRIA6: return VTK_TRIANGLE;
148     case MED_QUAD4: return VTK_QUAD;
149     case MED_QUAD8: return VTK_QUAD;
150     case MED_TETRA4: return VTK_TETRA;
151     case MED_TETRA10: return VTK_TETRA;
152     case MED_HEXA8: return VTK_HEXAHEDRON;
153     case MED_HEXA20: return VTK_HEXAHEDRON;
154     case MED_PENTA6: return VTK_WEDGE;
155     case MED_PENTA15: return VTK_WEDGE;
156     case MED_PYRA5: return VTK_PYRAMID;
157     case MED_PYRA13: return VTK_PYRAMID;
158     }
159     return -1;
160   }
161   
162   int VTKGeom2NbNodes(int theVTKGeomType)
163   { 
164     switch(theVTKGeomType){
165     case VTK_VERTEX: return 1;
166     case VTK_LINE: return 2;
167     case VTK_TRIANGLE: return 3;
168     case VTK_QUAD: return 4;
169     case VTK_TETRA: return 4;
170     case VTK_HEXAHEDRON: return 8;
171     case VTK_WEDGE: return 6;
172     case VTK_PYRAMID: return 5;
173     }
174     return -1;
175   }
176   
177   medGeometryElement VTKGeomToMED(int theVTKGeomType)
178   { 
179     switch(theVTKGeomType){
180     case VTK_VERTEX: return MED_POINT1;
181     case VTK_LINE: return MED_SEG2;
182     case VTK_TRIANGLE: return MED_TRIA3;
183     case VTK_QUAD: return MED_QUAD4;
184     case VTK_TETRA: return MED_TETRA4;
185     case VTK_HEXAHEDRON: return MED_HEXA8;
186     case VTK_WEDGE: return MED_PENTA6;
187     case VTK_PYRAMID: return MED_PYRA5;
188     }
189     return medGeometryElement(-1);
190   }
191   
192   VISU::TEntity MEDEntityToVTK(medEntityMesh theMEDEntity)
193   {
194     switch(theMEDEntity){
195     case MED_NODE: return NODE_ENTITY;
196     case MED_EDGE: return EDGE_ENTITY;
197     case MED_FACE: return FACE_ENTITY;
198     case MED_CELL: return CELL_ENTITY;
199     }
200     return VISU::TEntity(-1);
201   }
202   
203   medEntityMesh VTKEntityToMED(VISU::TEntity theVTKEntity)
204   {
205     switch(theVTKEntity){
206     case NODE_ENTITY: return MED_NODE;
207     case EDGE_ENTITY: return MED_EDGE;
208     case FACE_ENTITY: return MED_FACE;
209     case CELL_ENTITY: return MED_CELL;
210     }
211     return medEntityMesh(-1);
212   }
213   
214   string GetSObjectName(SALOMEDS::SObject_ptr aSObject){
215     SALOMEDS::GenericAttribute_var anAttr;
216     if (aSObject->FindAttribute(anAttr,"AttributeName")) {
217       SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
218       CORBA::String_var aString = aName->Value();
219       return aString.in();
220     }
221     return "";
222   }
223   
224   void 
225   GetCellsSize(vtkIdType& theNbCells, vtkIdType& theCellsSize,
226                SALOME_MED::MESH_ptr theMEDMesh,
227                const VISU::TEntity& theVEntity)
228   {
229     medGeometryElement* aGeomElems;
230     theNbCells = theCellsSize = 0;
231     int iGeomEnd = GetEntity2Geom(theVEntity,aGeomElems);
232     const medEntityMesh& aMEntity = VTKEntityToMED(theVEntity);
233     if(MYDEBUG) MESSAGE("GetCellsSize - theVEntity = "<<theVEntity);
234       for(int iGeom = 0; iGeom < iGeomEnd; iGeom++){
235         medGeometryElement aMEDGeom = aGeomElems[iGeom];
236         int iNumElemEnd = theMEDMesh->getNumberOfElements(aMEntity,aMEDGeom);
237         if(iNumElemEnd > 0){
238           if(MYDEBUG) MESSAGE("GetCellsSize - iNumElemEnd = "<<iNumElemEnd);
239           theCellsSize += iNumElemEnd*(MEDGeom2NbNodes(aMEDGeom) + 1);
240           theNbCells += iNumElemEnd;
241         }
242       }
243   }
244   
245   
246   void 
247   GetCellsSize(vtkIdType& theNbCells, vtkIdType& theCellsSize,
248                SALOME_MED::FAMILY_ptr theMEDFamily)
249   {
250     medGeometryElement_array_var aGeom = theMEDFamily->getTypes();
251     int iGeomEnd = aGeom->length();
252     theNbCells = theCellsSize = 0;
253     if(MYDEBUG) MESSAGE("GetCellsSize - iGeomEnd = "<<iGeomEnd);
254     for(int iGeom = 0; iGeom < iGeomEnd; iGeom++) {
255       medGeometryElement aMEDGeom = aGeom[iGeom];
256       long_array_var aCellNumForType = theMEDFamily->getNumber(aMEDGeom);
257       int iNumElemEnd = aCellNumForType->length();
258       if(iNumElemEnd > 0){
259         if(MYDEBUG) MESSAGE("GetCellsSize - iNumElemEnd = "<<iNumElemEnd);
260         theNbCells += iNumElemEnd;
261         theCellsSize += iNumElemEnd*(MEDGeom2NbNodes(aMEDGeom) + 1);
262       }
263     }
264   }
265   
266   
267   void
268   GetCellsSize(VISU::PCMesh theMesh, 
269                SALOME_MED::MESH_ptr theMEDMesh, 
270                const VISU::TEntity& theEntity)
271   {
272     TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap;
273     VISU::PCMeshOnEntity aMeshOnEntity = aMeshOnEntityMap[theEntity];
274     if(theEntity == NODE_ENTITY){
275       theMesh->myNbPoints = theMEDMesh->getNumberOfNodes();
276       aMeshOnEntity->myNbCells = theMesh->myNbPoints;
277       aMeshOnEntity->myCellsSize = 2*theMesh->myNbPoints;
278       vtkIdType aNbCells, aCellsSize;
279       GetCellsSize(aNbCells,aCellsSize,theMEDMesh,CELL_ENTITY);
280       if(aNbCells > 0){
281         PCMeshOnEntity aMeshOnCells = aMeshOnEntityMap[CELL_ENTITY];
282         aMeshOnCells->myEntity = VISU::CELL_ENTITY;
283         aMeshOnCells->myMeshName = theMesh->myName;
284         aMeshOnCells->myNbCells = aNbCells;
285         aMeshOnCells->myCellsSize = aCellsSize;
286       }
287     }else
288       GetCellsSize(aMeshOnEntity->myNbCells,aMeshOnEntity->myCellsSize,theMEDMesh,theEntity);
289   }
290   
291 }
292
293
294 VISU_Convertor* 
295 VISU_MEDFieldConvertor::Build()
296 {
297   if(myField->_is_nil()) 
298     throw std::runtime_error("VISU_MEDFieldConvertor::Build >> myField->_is_nil() !!!");
299   
300   SALOME_MED::SUPPORT_var aMEDSupport = myField->getSupport();
301   if(aMEDSupport->_is_nil()) 
302     throw std::runtime_error("VISU_MEDFieldConvertor::Build >> aMEDSupport->_is_nil() !!!");
303
304   SALOME_MED::medEntityMesh aMEntity = aMEDSupport->getEntity();
305   TEntity aVEntity = MEDEntityToVTK(aMEntity);
306   SALOME_MED::MESH_var aMEDMesh = aMEDSupport->getMesh();
307   if(aMEDMesh->_is_nil()) 
308     throw std::runtime_error("VISU_MEDFieldConvertor::Build >> aMEDMesh->_is_nil() !!!");
309
310   CORBA::String_var aMeshName = aMEDMesh->getName();
311   CORBA::String_var aFieldName = myField->getName();
312
313   PCMesh aMesh = myMeshMap[aMeshName.in()](new TCMesh());
314   aMesh->myDim = aMEDMesh->getSpaceDimension();
315   aMesh->myPointsDim.resize(aMesh->myDim);
316   aMesh->myName = aMeshName.in();
317   aMesh->myMesh = aMEDMesh;
318
319   if(MYDEBUG) MESSAGE("VISU_MEDFieldConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh->myDim);
320
321   TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
322   PCMeshOnEntity aMeshOnEntity = aMeshOnEntityMap[aVEntity](new TCMeshOnEntity());
323   aMeshOnEntity->myEntity = aVEntity;
324   aMeshOnEntity->myMeshName = aMeshName.in();
325   aMeshOnEntity->mySupport = aMEDSupport;
326
327   if(aVEntity == NODE_ENTITY){
328     PCMeshOnEntity aMeshOnEntity2 = aMeshOnEntityMap[CELL_ENTITY](new TCMeshOnEntity());
329     *aMeshOnEntity2 = *aMeshOnEntity;
330     aMeshOnEntity->myEntity = CELL_ENTITY;
331     GetCellsSize(aMesh,aMEDMesh,CELL_ENTITY);
332   }else{
333     PCMeshOnEntity aMeshOnEntity2 = aMeshOnEntityMap[NODE_ENTITY](new TCMeshOnEntity());
334     *aMeshOnEntity2 = *aMeshOnEntity;
335     aMeshOnEntity->myEntity = NODE_ENTITY;
336     GetCellsSize(aMesh,aMEDMesh,NODE_ENTITY);
337   }
338   GetCellsSize(aMesh,aMEDMesh,aVEntity);
339
340   TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
341   PCField aField = aFieldMap[aFieldName.in()](new TCField());
342   aField->myId = myField->getOrderNumber();
343   aField->myName = aFieldName.in();
344   aField->myEntity = aVEntity;
345   aField->myMeshName = aMeshName.in();
346   aField->myNbComp = myField->getNumberOfComponents();
347   aField->myDataSize = aMeshOnEntity->myNbCells * aField->myNbComp;
348   aField->myCompNames.resize(aField->myNbComp);
349   aField->myUnitNames.resize(aField->myNbComp);
350
351   if(MYDEBUG) MESSAGE("VISU_MEDFieldConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh->myDim);
352
353   TValField& aValField = aField->myValField;
354   int anId = myField->getIterationNumber();
355   PCValForTime aValForTime = aValField[anId](new TCValForTime());
356   aValForTime->myId = anId;
357   CORBA::Double aDT = myField->getTime();
358   aValForTime->myTime = TTime(aDT,"");
359   aValForTime->myField = myField;
360
361   if(MYDEBUG) 
362     MESSAGE("VISU_MEDFieldConvertor::Build - aFieldName = '"<<aFieldName<<
363             "'; myId = "<<anId<<"; myTime = "<<aDT);
364
365   return this;
366 }
367
368
369 VISU_Convertor* 
370 VISU_MEDConvertor::Build() 
371 {
372   if(mySObject->_is_nil()) 
373     throw std::runtime_error("VISU_MEDConvertor::Build >> mySObject->_is_nil() !!!");
374   SALOMEDS::Study_var aStudy = mySObject->GetStudy();
375
376   CORBA::Object_var aMedObject = VISU::SObjectToObject(mySObject);
377   if(!CORBA::is_nil(aMedObject)){
378     SALOME_MED::MED_var aMED = SALOME_MED::MED::_narrow(aMedObject);
379     return Build(aMED);
380   }
381
382   SALOMEDS::ChildIterator_var aTimeStampIterator = aStudy->NewChildIterator(mySObject);
383   return Build(aTimeStampIterator);
384 }
385
386 namespace{
387
388   using namespace boost;
389
390   struct TSObjectByName{
391     std::string myName;
392     typedef tuple<SALOMEDS::SObject_var> TRet;
393
394     TSObjectByName(const std::string& theName):
395       myName(theName)
396     {}
397
398     TRet operator()(SALOMEDS::SObject_ptr theSObj, bool& theIsSuccess)
399     {
400       SALOMEDS::GenericAttribute_var anAttr;
401       if(theSObj->FindAttribute(anAttr,"AttributeName")){
402         SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
403         CORBA::String_var aValue = aName->Value();
404         theIsSuccess = (myName == aValue.in());
405         if(theIsSuccess)
406           return TRet(SALOMEDS::SObject::_duplicate(theSObj));
407       }
408       return TRet();
409     }
410
411   };
412
413   struct TMeshByName{
414     std::string myName;
415     typedef tuple<SALOME_MED::MESH_var,SALOMEDS::SObject_var> TRet;
416
417     TMeshByName(const std::string& theName):
418       myName(theName)
419     {}
420
421     TRet operator()(SALOMEDS::SObject_ptr theSObj, bool& theIsSuccess)
422     {
423       CORBA::Object_var anObj = VISU::SObjectToObject(theSObj);
424       if(!CORBA::is_nil(anObj)){
425         SALOME_MED::MESH_var aMesh = SALOME_MED::MESH::_narrow(anObj);
426         if(!CORBA::is_nil(aMesh)){
427           CORBA::String_var aName = aMesh->getName();
428           theIsSuccess = (myName == aName.in());
429           if(theIsSuccess)
430             return TRet(aMesh,SALOMEDS::SObject::_duplicate(theSObj));
431         }
432       }
433       return TRet();
434     }
435   };
436
437   template<typename TFun>
438   typename TFun::TRet
439   Find(SALOMEDS::SObject_ptr theStartSObj, 
440        SALOMEDS::Study_ptr theStudy,
441        TFun theFun,
442        bool& theIsSuccess,
443        bool theIsAllLevels = true)
444   {
445     SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator(theStartSObj);
446     anIter->InitEx(theIsAllLevels);
447     for(; anIter->More(); anIter->Next()){
448       SALOMEDS::SObject_var aSObj = anIter->Value();
449       typename TFun::TRet aRet = theFun(aSObj,theIsSuccess);
450       if(theIsSuccess)
451         return aRet;
452     }
453     return typename TFun::TRet();
454   }
455
456 }
457
458 VISU_Convertor* 
459 VISU_MEDConvertor::Build(SALOME_MED::MED_ptr theMED)
460 {
461   if(CORBA::is_nil(theMED)) 
462     return NULL;
463
464   CORBA::Long aNbMeshes = theMED->getNumberOfMeshes();
465   SALOME_MED::string_array_var aMeshNames = theMED->getMeshNames();
466   if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aNbMeshes = "<<aNbMeshes);
467
468   SALOMEDS::Study_var aStudy = mySObject->GetStudy();
469   SALOMEDS::SObject_var aMedCompSObj = mySObject->GetFather();
470
471   bool anIsSuccess = false;
472   TSObjectByName::TRet aSObjectByNameRet = 
473     Find(aMedCompSObj,aStudy,TSObjectByName("MEDMESH"),anIsSuccess);
474   if(anIsSuccess){
475     SALOMEDS::SObject_var aMeshesSObj = boost::get<0>(aSObjectByNameRet);
476     for(int iMesh = 0; iMesh < aNbMeshes; iMesh++){
477       anIsSuccess = false;
478       CORBA::String_var aMeshName = aMeshNames[iMesh];
479       TMeshByName::TRet aMeshByNameRet = 
480         Find(aMeshesSObj,aStudy,TMeshByName(aMeshName.in()),anIsSuccess);
481       if(!anIsSuccess)
482         continue;
483
484       PCMesh aMesh = myMeshMap[aMeshName.in()](new TCMesh());
485       SALOME_MED::MESH_var aMEDMesh = boost::get<0>(aMeshByNameRet);
486       aMesh->myDim = aMEDMesh->getSpaceDimension();
487       aMesh->myName = aMeshName.in();
488       aMesh->myPointsDim.resize(aMesh->myDim);
489       aMesh->myMesh = aMEDMesh;
490
491       if(MYDEBUG) 
492         MESSAGE("VISU_MEDConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh->myDim);
493
494       anIsSuccess = false;
495       std::ostringstream aStream;
496       aStream<<"MEDSUPPORTS_OF_"<<aMeshName.in();
497       std::string aSupportsName(aStream.str());
498       TSObjectByName::TRet aSObjectByNameRet = 
499         Find(aMeshesSObj,aStudy,TSObjectByName(aSupportsName.c_str()),anIsSuccess);
500       if(!anIsSuccess)
501         continue;
502
503       TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
504       SALOMEDS::SObject_var aSupportsSObj = boost::get<0>(aSObjectByNameRet);
505       SALOMEDS::ChildIterator_var aSupportIterator = aStudy->NewChildIterator(aSupportsSObj);
506
507       // Fill all MeshOnEntity
508       aSupportIterator->InitEx(true);
509       for(; aSupportIterator->More(); aSupportIterator->Next()){
510         SALOMEDS::SObject_var aSupportSObj = aSupportIterator->Value();
511         
512         CORBA::Object_var aMedSupport = VISU::SObjectToObject(aSupportSObj);
513         if(CORBA::is_nil(aMedSupport)) 
514           continue;
515         
516         SALOME_MED::SUPPORT_var aMEDSupport = SALOME_MED::SUPPORT::_narrow(aMedSupport); 
517         if(aMEDSupport->_is_nil()) 
518           continue;
519         
520         SALOME_MED::MESH_var aMeshOnSupport = aMEDSupport->getMesh();
521         SALOME_MED::medEntityMesh aMEntity = aMEDSupport->getEntity();
522         VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
523         CORBA::String_var aSupportName = aMEDSupport->getName();
524         
525         if(aMEDSupport->isOnAllElements()){
526           if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - Support isOnAllElements = '"<<aSupportName<<"' aVEntity = "<<aVEntity);
527           int aNbCells, aCellsSize;
528           //Check, if there is any data on the support?
529           if(aVEntity == NODE_ENTITY){
530             aMesh->myNbPoints = aMeshOnSupport->getNumberOfNodes();
531             aNbCells = aMesh->myNbPoints;
532             aCellsSize = 2*aMesh->myNbPoints;
533           }else
534             GetCellsSize(aNbCells,aCellsSize,aMeshOnSupport,aVEntity);
535           
536           if(aNbCells > 0){
537             PCMeshOnEntity aMeshOnEntity = aMeshOnEntityMap[aVEntity](new TCMeshOnEntity());
538             aMeshOnEntity->myMeshName = aMeshName.in();
539             aMeshOnEntity->myEntity = aVEntity;
540             aMeshOnEntity->myNbCells = aNbCells;
541             aMeshOnEntity->myCellsSize = aCellsSize;
542             aMeshOnEntity->mySupport = aMEDSupport;
543           }
544         }
545       }
546
547       // Fill all Family
548       aSupportIterator->InitEx(true);
549       for(; aSupportIterator->More(); aSupportIterator->Next()){
550         SALOMEDS::SObject_var aSupportSObj = aSupportIterator->Value();
551         
552         CORBA::Object_var aMedSupport = VISU::SObjectToObject(aSupportSObj);
553         if(CORBA::is_nil(aMedSupport)) 
554           continue;
555         
556         SALOME_MED::SUPPORT_var aMEDSupport = SALOME_MED::SUPPORT::_narrow(aMedSupport); 
557         if(aMEDSupport->_is_nil()) 
558           continue;
559         
560         SALOME_MED::MESH_var aMeshOnSupport = aMEDSupport->getMesh();
561         SALOME_MED::medEntityMesh aMEntity = aMEDSupport->getEntity();
562         VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
563         CORBA::String_var aSupportName = aMEDSupport->getName();
564         
565         SALOME_MED::FAMILY_var aMEDFamily = SALOME_MED::FAMILY::_narrow(aMedSupport);
566         if(!aMEDFamily->_is_nil()) {
567           int aNbCells, aCellsSize;
568           GetCellsSize(aNbCells,aCellsSize,aMEDFamily);
569           if(aNbCells > 0){
570             if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aFamily = '"<<aSupportName<<"' aVEntity = "<<aVEntity);
571             TMeshOnEntityMap::iterator aMeshOnEntityMapIter = aMeshOnEntityMap.find(aVEntity);
572             if(aMeshOnEntityMapIter == aMeshOnEntityMap.end())
573               continue;
574
575             PCMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
576             TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
577             PCFamily aFamily = aFamilyMap[aSupportName.in()](new TCFamily());
578             aFamily->myName = aSupportName.in();
579             aFamily->myEntity = aVEntity;
580             aFamily->myNbCells = aNbCells;
581             aFamily->myCellsSize = aCellsSize;
582             aFamily->myId = aMEDFamily->getIdentifier();
583             aFamily->myFamily = aMEDFamily;
584           }
585         }
586       }
587         
588       // Fill all Groups
589       aSupportIterator->InitEx(true);
590       for(; aSupportIterator->More(); aSupportIterator->Next()){
591         SALOMEDS::SObject_var aSupportSObj = aSupportIterator->Value();
592         
593         CORBA::Object_var aMedSupport = VISU::SObjectToObject(aSupportSObj);
594         if(CORBA::is_nil(aMedSupport)) 
595           continue;
596         
597         SALOME_MED::SUPPORT_var aMEDSupport = SALOME_MED::SUPPORT::_narrow(aMedSupport); 
598         if(aMEDSupport->_is_nil()) 
599           continue;
600         
601         SALOME_MED::MESH_var aMeshOnSupport = aMEDSupport->getMesh();
602         SALOME_MED::medEntityMesh aMEntity = aMEDSupport->getEntity();
603         VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
604         CORBA::String_var aSupportName = aMEDSupport->getName();
605         
606         SALOME_MED::GROUP_var aMEDGroup = SALOME_MED::GROUP::_narrow(aMedSupport);
607         if(!aMEDGroup->_is_nil()){
608           if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aGroup = '"<<aSupportName<<"' aVEntity = "<<aVEntity);
609           TGroupMap& aGroupMap = aMesh->myGroupMap;
610           PCGroup aGroup = aGroupMap[aSupportName.in()](new TCGroup());
611           aGroup->myGroup = aMEDGroup;
612           SALOME_MED::Family_array_var aFamilies = aMEDGroup->getFamilies();
613           int iFamilyEnd = aFamilies->length();
614           for(int iFamaily = 0; iFamaily < iFamilyEnd; iFamaily++){
615             SALOME_MED::FAMILY_var aMEDFamily = aFamilies[iFamaily];
616             CORBA::String_var aFamilyName = aMEDFamily->getName();
617             if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aGroup - aFamilyName = '"<<aFamilyName.in()<<"'");
618             PFamily aFamily = FindFamily(aMesh,aFamilyName.in());
619             if(aFamily){
620               VISU::TBindGroups& aBindGroups = aFamily->myGroups;
621               aBindGroups.insert(aSupportName.in());
622             }
623           }
624         }
625       }
626     }
627   }
628
629   anIsSuccess = false;
630   aSObjectByNameRet = Find(aMedCompSObj,aStudy,TSObjectByName("MEDFIELD"),anIsSuccess);
631   if(anIsSuccess){
632     SALOMEDS::SObject_var aFieldsSObj = boost::get<0>(aSObjectByNameRet);
633     if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - MEDFIELD found.");
634     SALOMEDS::ChildIterator_var aFieldIterator = aStudy->NewChildIterator(aFieldsSObj);
635     for(int iField = 0; aFieldIterator->More(); aFieldIterator->Next(), iField++){
636       SALOMEDS::SObject_var aFieldSObj = aFieldIterator->Value();
637       if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aFieldName = '"<<GetSObjectName(aFieldSObj)<<"'");
638       SALOMEDS::ChildIterator_var aTimeStampIterator = aStudy->NewChildIterator(aFieldSObj);
639       for(; aTimeStampIterator->More(); aTimeStampIterator->Next()){
640         SALOMEDS::SObject_var aTimeStampSObj = aTimeStampIterator->Value();
641         if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aTimeStampSObj = '"<<GetSObjectName(aTimeStampSObj)<<"'");
642         CORBA::Object_var aMedField = VISU::SObjectToObject(aTimeStampSObj);
643         if(CORBA::is_nil(aMedField)) 
644           continue;
645
646         SALOME_MED::FIELD_var aMEDField = SALOME_MED::FIELD::_narrow(aMedField);
647         if(aMEDField->_is_nil()) 
648           continue;
649
650         SALOME_MED::SUPPORT_var aMEDSupport = aMEDField->getSupport();
651         if(aMEDSupport->_is_nil()) 
652           continue;
653
654         SALOME_MED::medEntityMesh aMEntity = aMEDSupport->getEntity();
655         VISU::TEntity anEntity = MEDEntityToVTK(aMEntity);
656         SALOME_MED::MESH_var aMEDMesh = aMEDSupport->getMesh();
657         if(aMEDMesh->_is_nil()) 
658           continue;
659
660         CORBA::String_var aMeshName = aMEDMesh->getName();
661         CORBA::String_var aFieldName = aMEDField->getName();
662         
663         TMeshMap::iterator aMeshMapIter = myMeshMap.find(aMeshName.in());
664         if(aMeshMapIter == myMeshMap.end())
665           continue;
666
667         PCMesh aMesh = aMeshMapIter->second;
668         TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
669         TMeshOnEntityMap::iterator aMeshOnEntityMapIter = aMeshOnEntityMap.find(anEntity);
670         if(aMeshOnEntityMapIter == aMeshOnEntityMap.end())
671           continue;
672
673         PCMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
674         TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
675         TFieldMap::iterator aFieldMapIter = aFieldMap.find(aFieldName.in());
676         PCField aField;
677         if(aFieldMapIter == aFieldMap.end()){
678           aField = aFieldMap[aFieldName.in()](new TCField());
679           aField->myId = iField;
680           aField->myName = aFieldName.in();
681           aField->myEntity = anEntity;
682           aField->myMeshName = aMeshName.in();
683           aField->myNbComp = aMEDField->getNumberOfComponents();
684           aField->myDataSize = aMeshOnEntity->myNbCells * aField->myNbComp;
685           if(MYDEBUG) 
686             MESSAGE("VISU_MEDConvertor::Build - aMeshOnEntity->myNbCells = "<<aMeshOnEntity->myNbCells);
687           aField->myCompNames.resize(aField->myNbComp);
688           aField->myUnitNames.resize(aField->myNbComp);
689         }else
690           aField = aFieldMapIter->second;
691
692         TValField& aValField = aField->myValField;
693         int anId = aMEDField->getIterationNumber();
694         PCValForTime aValForTime = aValField[anId](new TCValForTime());
695         aValForTime->myId = anId;
696         CORBA::Double aDT = aMEDField->getTime();
697         aValForTime->myTime = TTime(aDT,"");
698         aValForTime->myField = aMEDField;
699         if(MYDEBUG) 
700           MESSAGE("VISU_MEDConvertor::Build - aMeshName = '"<<aMeshName<<
701                   "'; myEntity = "<<anEntity<<"; myTime = "<<aDT);
702       }      
703     }
704   }
705   return this; 
706 }
707  
708
709 VISU_Convertor* 
710 VISU_MEDConvertor::Build(SALOMEDS::ChildIterator_ptr theTimeStampIterator)
711 {
712   if(theTimeStampIterator->_is_nil()) return NULL;
713   for(; theTimeStampIterator->More(); theTimeStampIterator->Next()){
714     SALOMEDS::SObject_var aTimeStampSObj = theTimeStampIterator->Value();
715     if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aTimeStampSObj = '"<<GetSObjectName(aTimeStampSObj)<<"'");
716
717     CORBA::Object_var aMedField = VISU::SObjectToObject(aTimeStampSObj);
718     if(CORBA::is_nil(aMedField)) 
719       continue;
720
721     SALOME_MED::FIELD_var aMEDField = SALOME_MED::FIELD::_narrow(aMedField);
722     if(aMEDField->_is_nil()) 
723       continue;
724
725     SALOME_MED::SUPPORT_var aMEDSupport = aMEDField->getSupport();
726     if(aMEDSupport->_is_nil()) 
727       continue;
728
729     SALOME_MED::medEntityMesh aMEntity = aMEDSupport->getEntity();
730     TEntity aVEntity = MEDEntityToVTK(aMEntity);
731     SALOME_MED::MESH_var aMEDMesh = aMEDSupport->getMesh();
732     if(aMEDMesh->_is_nil()) continue;
733     CORBA::String_var aMeshName = aMEDMesh->getName();
734     CORBA::String_var aFieldName = aMEDField->getName();
735
736     PCMesh aMesh = myMeshMap[aMeshName.in()](new TCMesh());
737     aMesh->myDim = aMEDMesh->getSpaceDimension();
738     aMesh->myPointsDim.resize(aMesh->myDim);
739     aMesh->myName = aMeshName.in();
740     aMesh->myNbPoints = aMEDMesh->getNumberOfNodes();
741     aMesh->myMesh = aMEDMesh;
742     if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh->myDim);
743
744     TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
745     PCMeshOnEntity aMeshOnEntity = aMeshOnEntityMap[aVEntity](new TCMeshOnEntity());
746     aMeshOnEntity->myEntity = aVEntity;
747     aMeshOnEntity->myMeshName = aMeshName.in();
748     aMeshOnEntity->mySupport = aMEDSupport;
749
750     if(aVEntity == NODE_ENTITY){
751       PCMeshOnEntity aMeshOnEntity2 = aMeshOnEntityMap[CELL_ENTITY](new TCMeshOnEntity());
752       *aMeshOnEntity2 = *aMeshOnEntity;
753       aMeshOnEntity->myEntity = CELL_ENTITY;
754       GetCellsSize(aMesh,aMEDMesh,CELL_ENTITY);
755     }else{
756       PCMeshOnEntity aMeshOnEntity2 = aMeshOnEntityMap[NODE_ENTITY](new TCMeshOnEntity());
757       *aMeshOnEntity2 = *aMeshOnEntity;
758       aMeshOnEntity->myEntity = NODE_ENTITY;
759       GetCellsSize(aMesh,aMEDMesh,NODE_ENTITY);
760     }
761     GetCellsSize(aMesh,aMEDMesh,aVEntity);
762
763     TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
764     TFieldMap::iterator aFieldMapIter = aFieldMap.find(aFieldName.in());
765     PCField aField;
766     if(aFieldMapIter == aFieldMap.end()){
767       aField = aFieldMap[aFieldName.in()](new TCField());
768       CORBA::Short iField = mySObject->Tag();
769       aField->myId = iField;
770       aField->myName = aFieldName.in();
771       aField->myEntity = aVEntity;
772       aField->myMeshName = aMeshName.in();
773       aField->myNbComp = aMEDField->getNumberOfComponents();
774       aField->myDataSize = aMeshOnEntity->myNbCells * aField->myNbComp;
775       if(MYDEBUG) 
776         MESSAGE("VISU_MEDConvertor::Build - aMeshOnEntity->myNbCells = "<<aMeshOnEntity->myNbCells);
777       aField->myCompNames.resize(aField->myNbComp);
778       aField->myUnitNames.resize(aField->myNbComp);
779     }
780     
781     TValField& aValField = aField->myValField;
782     int anId = aMEDField->getIterationNumber();
783     PCValForTime aValForTime = aValField[anId](new TCValForTime());
784     aValForTime->myId = anId;
785     CORBA::Double aDT = aMEDField->getTime();
786     aValForTime->myTime = TTime(aDT,"");
787     aValForTime->myField = aMEDField;
788     if(MYDEBUG) 
789       MESSAGE("VISU_MEDConvertor::Build - aMeshName = '"<<aMeshName<<
790               "'; myEntity = "<<aVEntity<<"; myTime = "<<aDT);
791   }
792   return this; 
793 }
794
795
796 int
797 VISU_MEDConvertor::LoadMeshOnEntity(VISU::PMeshOnEntityImpl theMeshOnEntity, 
798                                     const string& theFamilyName)
799 {
800   //Main part of code
801   const string& aMeshName = theMeshOnEntity->myMeshName;
802   const TEntity& aVEntity = theMeshOnEntity->myEntity;
803   PCMesh aMesh = myMeshMap[aMeshName];
804   int isPointsUpdated;
805   if(aVEntity == NODE_ENTITY) 
806     isPointsUpdated = LoadPoints(aMesh,theFamilyName);
807   else 
808     isPointsUpdated = LoadPoints(aMesh);
809   int isCellsOnEntityUpdated = LoadCellsOnEntity(aMesh,theMeshOnEntity,theFamilyName);
810
811   return (isPointsUpdated || isCellsOnEntityUpdated);
812 }
813  
814  
815 int 
816 VISU_MEDConvertor::LoadMeshOnGroup(VISU::PMeshImpl theMesh, 
817                                    const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet)
818 {
819   //Main part of code
820   int isPointsUpdated = 0;
821   int isCellsOnEntityUpdated = 0;
822   VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = theFamilyAndEntitySet.begin();
823   for(; aFamilyAndEntitySetIter != theFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){
824     const string& aFamilyName = aFamilyAndEntitySetIter->first;
825     const VISU::TEntity& aVEntity = aFamilyAndEntitySetIter->second;
826     PCMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[aVEntity];
827     if(aVEntity == VISU::NODE_ENTITY){
828       isPointsUpdated += LoadPoints(theMesh,aFamilyName);
829       isCellsOnEntityUpdated += LoadCellsOnEntity(theMesh,aMeshOnEntity);
830     }else{
831       isPointsUpdated += LoadPoints(theMesh);
832       isCellsOnEntityUpdated += LoadCellsOnEntity(theMesh,aMeshOnEntity,aFamilyName);
833     }
834   }
835
836   return (isPointsUpdated || isCellsOnEntityUpdated);
837 }
838
839
840 int 
841 VISU_MEDConvertor::LoadFieldOnMesh(VISU::PMeshImpl theMesh, 
842                                    VISU::PMeshOnEntityImpl theMeshOnEntity, 
843                                    VISU::PFieldImpl theField, 
844                                    VISU::PValForTimeImpl theValForTime)
845 {
846   //Main part of code
847   int isPointsUpdated = LoadPoints(theMesh);
848   int isCellsOnEntityUpdated = LoadCellsOnEntity(theMesh,theMeshOnEntity);
849   int isFieldUpdated = LoadField(theMesh,theMeshOnEntity,theField,theValForTime);
850   
851   return (isPointsUpdated || isCellsOnEntityUpdated || isFieldUpdated);
852 }
853
854 int 
855 VISU_MEDConvertor::LoadPoints(VISU::PCMesh theMesh, 
856                               const string& theFamilyName)
857 {
858   //Check on existing family
859   PCMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[VISU::NODE_ENTITY];
860   PCFamily aFamily = GetFamily(aMeshOnEntity,theFamilyName);
861   //Check on loading already done
862   bool isPointsLoaded = !theMesh->myPointsCoord.empty();
863   if(isPointsLoaded) 
864     if(!aFamily) 
865       return 0;
866     else if(!aFamily->mySubMesh.empty()) 
867       return 0;
868
869   if(MYDEBUG) 
870     MESSAGE("LoadPoints - isPointsLoaded = "<<isPointsLoaded<<"; theFamilyName = '"<<theFamilyName<<"'");
871
872   SALOME_MED::MESH_var& aMedMesh = theMesh->myMesh;
873   int iNumElemEnd = aMedMesh->getNumberOfNodes();
874   TMeshImpl::TPointsCoord& aPointsCoord = theMesh->myPointsCoord;
875   if(MYDEBUG) MESSAGE("LoadPoints - iNumElemEnd = "<<iNumElemEnd);
876   if (iNumElemEnd <= 0) throw std::runtime_error("LoadPoints >> There is no points in the mesh !!!");
877   aPointsCoord.resize(theMesh->myDim*iNumElemEnd,0.0);
878   SALOME_MED::double_array_var coord = aMedMesh->getCoordinates(SALOME_MED::MED_FULL_INTERLACE);
879   if(!isPointsLoaded){
880     for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) 
881       for(int iDim = 0, iNumElem2Dim = iNumElem*theMesh->myDim; iDim < theMesh->myDim; iDim++, iNumElem2Dim++)
882         aPointsCoord[iNumElem2Dim] = coord[iNumElem2Dim];
883     if(MYDEBUG) MESSAGE("LoadPoints - Filling aMeshOnEntity with type NODE_ENTITY");
884     TMeshOnEntityImpl::TConnForCellType& aConnForCellType = aMeshOnEntity->myCellsConn[VTK_VERTEX];
885     aConnForCellType.resize(iNumElemEnd);
886     for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
887       aConnForCellType[iNumElem] = TMeshOnEntityImpl::TConnect(1,iNumElem);
888   }
889   if(aFamily){
890     if(MYDEBUG) MESSAGE("LoadPoints - Filling aFamily SubMesh");
891     SALOME_MED::FAMILY_var aMedFamily = aFamily->myFamily;
892     TFamilyImpl::TSubMeshOnCellType& aSubMeshOnCellType = aFamily->mySubMesh[VTK_VERTEX];
893     SALOME_MED::medGeometryElement_array_var aGeom = aMedFamily->getTypes();
894     SALOME_MED::long_array_var aCellNumForType = aMedFamily->getNumber(aGeom[0]);
895     int iNumElemEndTmp = iNumElemEnd;
896     iNumElemEnd = aCellNumForType->length();
897     for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) {
898       int tmp = aCellNumForType[iNumElem]-1;
899       if(0 > tmp || tmp >= iNumElemEndTmp) {
900         static QString aString;
901         aString.sprintf("LoadPoints >> iNumElemEndTmp(%d) <= aCellNumForType[%d]=%d < 0 !!!",iNumElemEnd,iNumElem,tmp);
902         throw std::runtime_error(aString.latin1());
903       }
904       aSubMeshOnCellType.insert(tmp);
905     }
906   }
907   return 1;
908 }
909
910
911 int 
912 VISU_MEDConvertor::LoadCellsOnEntity(VISU::PCMesh theMesh,
913                                      VISU::PCMeshOnEntity theMeshOnEntity, 
914                                      const string& theFamilyName)
915 {
916   //Check on existing family
917   PCFamily aFamily = GetFamily(theMeshOnEntity,theFamilyName);
918   //Check on loading already done
919   bool isCellsLoaded = !theMeshOnEntity->myCellsConn.empty();
920   if(isCellsLoaded) 
921     if(!aFamily) 
922       return 0;
923     else if(!aFamily->mySubMesh.empty()) 
924       return 0;
925
926   SALOME_MED::SUPPORT_var& aMedSupport = theMeshOnEntity->mySupport;
927   SALOME_MED::MESH_var aMedMesh = aMedSupport->getMesh();
928   if(MYDEBUG) {
929     MESSAGE("LoadCellsOnEntity - theFamilyName = '"<<theFamilyName<<"'");
930     MESSAGE("LoadCellsOnEntity - isCellsLoaded = "<<isCellsLoaded<<"; isFamilyPresent = "<<bool(aFamily));
931   }
932
933   //Main part of code
934   SALOME_MED::medGeometryElement* aGeomElems;
935   const TEntity& aVEntity = theMeshOnEntity->myEntity;
936   int iGeomEnd = GetEntity2Geom(aVEntity,aGeomElems);
937   const SALOME_MED::medEntityMesh& aMEntity = VTKEntityToMED(aVEntity);
938   int aNbPoints = theMesh->myPointsCoord.size()/theMesh->myDim;
939   if(!isCellsLoaded){
940     for(int iGeom = 0, aCounter = 0; iGeom < iGeomEnd; iGeom++){
941       SALOME_MED::medGeometryElement aGeom = aGeomElems[iGeom];
942       int aMNbNodes = MEDGeom2NbNodes(aGeom);
943       int aVGeom = MEDGeomToVTK(aGeom);
944       int aVNbNodes = VTKGeom2NbNodes(aVGeom);
945       int iNumElemEnd = aMedMesh->getNumberOfElements(aMEntity,aGeom);
946       if (iNumElemEnd > 0) {
947         SALOME_MED::long_array_var conn = 
948           aMedMesh->getConnectivity(SALOME_MED::MED_FULL_INTERLACE,SALOME_MED::MED_NODAL,aMEntity,aGeom);
949         TMeshOnEntityImpl::TConnForCellType& aConnForCellType = theMeshOnEntity->myCellsConn[aVGeom];
950         //APO - aConnForCellType.resize(iNumElemEnd);
951         vector<int> aConnect(aMNbNodes);
952         int aNbConnForElem = conn->length()/iNumElemEnd;
953         if(MYDEBUG) MESSAGE("LoadCellsOnEntity - aGeom = "<<aGeom<<
954                             "; iNumElemEnd = "<<iNumElemEnd<<
955                             "; aNbConnForElem = "<<aNbConnForElem);
956         for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) {
957           VISU::TMeshOnEntityImpl::TConnect anArray(aVNbNodes);
958           for (int k = 0, kj = iNumElem*aNbConnForElem; k < aMNbNodes; k++) {
959             aConnect[k] = conn[kj+k] - 1;
960           }
961           switch(aGeom){
962           case SALOME_MED::MED_TETRA4 :
963           case SALOME_MED::MED_TETRA10 :
964             anArray[0] = aConnect[0];
965             anArray[1] = aConnect[1];
966             anArray[2] = aConnect[3];  
967             anArray[3] = aConnect[2];  
968             break;
969           case SALOME_MED::MED_PYRA5 :
970           case SALOME_MED::MED_PYRA13 :
971             anArray[0] = aConnect[0];
972             anArray[1] = aConnect[3];  
973             anArray[2] = aConnect[2];
974             anArray[3] = aConnect[1];  
975             anArray[4] = aConnect[4];
976             break;
977           default:
978             for (int k = 0; k < aVNbNodes; k++) 
979               anArray[k] = aConnect[k];
980           }
981           for (int k = 0; k < aVNbNodes; k++) 
982             if(anArray[k] < 0 || aNbPoints <= anArray[k]){
983               static QString aString;
984               aString.sprintf("ImportCells >> aNbPoints(%d) <= anArray[%d][%d]=%d < 0 !!!",aNbPoints,iNumElem,k,anArray[k]);
985               throw std::runtime_error(aString.latin1());
986             }
987           aConnForCellType.push_back(anArray);
988         }
989         //Workaround for MED Component data structure
990         int aSize = aConnForCellType.size();
991         theMeshOnEntity->myCellsFirstIndex[aGeom] = TCMeshOnEntity::TIndexAndSize(aCounter,aSize);
992         aCounter += aSize;
993       }
994     }
995   }
996   //Filling aFamily SubMesh
997   if(aFamily){
998     SALOME_MED::FAMILY_var aMedFamily = aFamily->myFamily;
999     SALOME_MED::medGeometryElement_array_var aGeoms = aMedFamily->getTypes();
1000     iGeomEnd = aGeoms->length();
1001     if(MYDEBUG) MESSAGE("LoadCellsOnEntity - iGeomEnd = "<<iGeomEnd);
1002     for (int iGeom = 0; iGeom < iGeomEnd; iGeom++) {
1003       SALOME_MED::medGeometryElement aGeom = aGeoms[iGeom];
1004       SALOME_MED::long_array_var aCellNumForType = aMedFamily->getNumber(aGeom);
1005       int aVGeom = MEDGeomToVTK(aGeom);
1006       TFamilyImpl::TSubMeshOnCellType& aSubMeshOnCellType = aFamily->mySubMesh[aVGeom]; 
1007       int iNumElemEndTmp = theMeshOnEntity->myCellsConn[aVGeom].size();
1008       int iNumElemEnd = aCellNumForType->length();
1009       int aCounter = theMeshOnEntity->myCellsFirstIndex[aGeom].first;
1010       if(MYDEBUG) 
1011         MESSAGE("LoadCellsOnEntity - aGeom = "<<aGeom<<
1012                 "; iNumElemEnd = "<<iNumElemEnd<<
1013                 "; aCounter = "<<aCounter);
1014       for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) {
1015         int tmp = aCellNumForType[iNumElem]-aCounter-1;
1016         if(0 > tmp || tmp >= iNumElemEndTmp) {
1017           static QString aString;
1018           aString.sprintf("LoadCellsOnEntity >> iNumElemEndTmp(%d) <= aCellNumForType[%d]=%d < 0 !!!",iNumElemEndTmp,iNumElem,tmp);
1019           throw std::runtime_error(aString.latin1());
1020         }
1021         aSubMeshOnCellType.insert(tmp);
1022       }
1023     }
1024   }
1025   return 1;
1026 }
1027
1028 template<class TArray> 
1029 int 
1030 ImportField(TArray& theArray, 
1031             VISU::PCMesh theMesh,
1032             VISU::PCField theField,
1033             VISU::PCValForTime theValForTime,
1034             VISU::PCMeshOnEntity theMeshOnEntity)
1035 {
1036   if(theField->myEntity == NODE_ENTITY){
1037     TValForTimeImpl::TValForCellsWithType& aValForCellsWithType = 
1038       theValForTime->myValForCells[VTK_VERTEX];
1039     int iNumElemEnd = theMesh->myPointsCoord.size()/theMesh->myDim*theField->myNbComp;
1040     if(MYDEBUG) MESSAGE("ImportField - iNumElemEnd = "<<iNumElemEnd);
1041     aValForCellsWithType.resize(iNumElemEnd);
1042     for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) 
1043       aValForCellsWithType[iNumElem] = theArray[iNumElem];
1044   }else{
1045     SALOME_MED::medGeometryElement* aGeomElems;
1046     const TEntity& aVEntity = theField->myEntity;
1047     int iGeomEnd = GetEntity2Geom(aVEntity,aGeomElems);
1048     for(int iGeom = 0; iGeom < iGeomEnd; iGeom++){
1049       SALOME_MED::medGeometryElement aGeom = aGeomElems[iGeom];
1050       int aVGeom = MEDGeomToVTK(aGeom);
1051       const TCMeshOnEntity::TCellsFirstIndex& aCellsFirstIndex = theMeshOnEntity->myCellsFirstIndex;
1052       TCMeshOnEntity::TCellsFirstIndex::const_iterator aCellsFirstIndexIter = aCellsFirstIndex.find(aGeom);
1053       if(aCellsFirstIndexIter != aCellsFirstIndex.end()){
1054         const TCMeshOnEntity::TIndexAndSize& aIndexAndSize = aCellsFirstIndexIter->second;
1055         int iNumElemEnd = aIndexAndSize.second;
1056         if(MYDEBUG) 
1057           MESSAGE("ImportField - aGeom = "<<aGeom<<
1058                   "; aIndexAndSize = {"<<aIndexAndSize.first<<
1059                   ","<<aIndexAndSize.second<<"}");
1060         TValForTimeImpl::TValForCellsWithType& aValForCellsWithType = theValForTime->myValForCells[aVGeom];
1061         aValForCellsWithType.resize(iNumElemEnd*theField->myNbComp);
1062         for(int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
1063           for(int k = 0, kj = iNumElem*theField->myNbComp; k < theField->myNbComp; k++)
1064             aValForCellsWithType[kj+k] = theArray[aIndexAndSize.first*theField->myNbComp+kj+k];
1065       }
1066     }
1067   }
1068   return 1;
1069 }
1070
1071 int
1072 VISU_MEDConvertor::LoadField(VISU::PCMesh theMesh,
1073                              VISU::PCMeshOnEntity theMeshOnEntity,
1074                              VISU::PField theField, 
1075                              VISU::PCValForTime theValForTime)
1076 {
1077   //Check on loading already done
1078   if(!theValForTime->myValForCells.empty()) 
1079     return 0;
1080  
1081   SALOME_MED::FIELD_var aMEDField = theValForTime->myField;
1082   SALOME_MED::FIELDDOUBLE_ptr aFieldDouble = SALOME_MED::FIELDDOUBLE::_narrow(aMEDField);
1083   if(!aFieldDouble->_is_nil()){
1084     SALOME_MED::double_array_var anArray = aFieldDouble->getValue(SALOME_MED::MED_FULL_INTERLACE);
1085     if(MYDEBUG) MESSAGE("VISU_MEDConvertor::LoadField - There is FIELDDOUBLE = "<<anArray->length());
1086     ::ImportField(anArray,theMesh,theField,theValForTime,theMeshOnEntity);
1087   }
1088   SALOME_MED::FIELDINT_ptr aFieldInt = SALOME_MED::FIELDINT::_narrow(aMEDField);
1089   if(!aFieldInt->_is_nil()){
1090     SALOME_MED::long_array_var anArray = aFieldInt->getValue(SALOME_MED::MED_FULL_INTERLACE);
1091     if(MYDEBUG) MESSAGE("VISU_MEDConvertor::LoadField - There is FIELDINT = "<<anArray->length());
1092     ::ImportField(anArray,theMesh,theField,theValForTime,theMeshOnEntity);
1093   }
1094   return 1;
1095 }