Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[modules/visu.git] / src / VISU_I / VISU_CorbaMedConvertor.cxx
index b23363dba7efc756ea33c976d554659d7833af46..e69db1a8827bd8e2d5f20e440f98a04835c2792c 100644 (file)
-//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//  VISU OBJECT : interactive object for VISU entities implementation
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  License along with this library; if not, write to the Free Software 
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+// 
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
 //
 //
 //
 //  File   : VISU_CorbaMedConvertor.cxx
 //  Author : Alexey PETROV
 //  Module : VISU
+//  $Header$
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
 
-using namespace std;
 #include "VISU_CorbaMedConvertor.hxx"
-using namespace VISU;
-#include <valarray>    
+
 #include <vtkCellType.h>
 
+#include <boost/tuple/tuple.hpp>
+
+using namespace std;
+using namespace VISU;
+
 #define USER_INTERLACE MED_FULL_INTERLACE
 
-#ifdef DEBUG
+#ifdef _DEBUG_
 static int MYDEBUG = 0;
 #else
 static int MYDEBUG = 0;
 #endif
-static med_err ret = 0;
 
 extern "C" {
-  VISU_Convertor* CreateMEDConvertor(SALOMEDS::SObject_ptr theMedSObject) throw(std::runtime_error&){
+  VISU_Convertor* 
+  CreateMEDConvertor(SALOMEDS::SObject_ptr theMedSObject) 
+  {
     return new VISU_MEDConvertor(theMedSObject);
   }
-  VISU_Convertor* CreateMEDFieldConvertor(SALOME_MED::FIELD_ptr theField) throw(std::runtime_error&){
+
+  VISU_Convertor* 
+  CreateMEDFieldConvertor(SALOME_MED::FIELD_ptr theField) 
+  {
     return new VISU_MEDFieldConvertor(theField);
   }
 }
 
-typedef map<VISU::TEntity,SALOME_MED::medEntityMesh> TVisu2MedEntity;
-static TVisu2MedEntity aVisu2MedEntity;
-static int INIT = (
-                  aVisu2MedEntity[VISU::CELL_ENTITY] = SALOME_MED::MED_CELL,
-                  aVisu2MedEntity[VISU::FACE_ENTITY] = SALOME_MED::MED_FACE,
-                  aVisu2MedEntity[VISU::EDGE_ENTITY] = SALOME_MED::MED_EDGE,
-                  aVisu2MedEntity[VISU::NODE_ENTITY] = SALOME_MED::MED_NODE,
-                  1);
-*/
-static int CELLGEOM[MED_NBR_GEOMETRIE_MAILLE] = {
-  SALOME_MED::MED_POINT1,
-  SALOME_MED::MED_SEG2,
-  SALOME_MED::MED_SEG3,
-  SALOME_MED::MED_TRIA3,
-  SALOME_MED::MED_QUAD4,
-  SALOME_MED::MED_TRIA6,
-  SALOME_MED::MED_QUAD8,
-  SALOME_MED::MED_TETRA4,
-  SALOME_MED::MED_PYRA5,
-  SALOME_MED::MED_PENTA6,
-  SALOME_MED::MED_TETRA10,
-  SALOME_MED::MED_HEXA8,
-  SALOME_MED::MED_PYRA13,
-  SALOME_MED::MED_PENTA15,
-  SALOME_MED::MED_HEXA20
-};
-
-static const int VTKCELLGEOMEND = 8;
-static int VTKCELLGEOM[VTKCELLGEOMEND] = {
-  SALOME_MED::MED_POINT1,
-  SALOME_MED::MED_SEG2,
-  SALOME_MED::MED_TRIA3,
-  SALOME_MED::MED_QUAD4,
-  SALOME_MED::MED_TETRA4,
-  SALOME_MED::MED_PYRA5,
-  SALOME_MED::MED_PENTA6,
-  SALOME_MED::MED_HEXA8
-};
-
-static int FACEGEOM[MED_NBR_GEOMETRIE_FACE] = {
-  SALOME_MED::MED_TRIA3,
-  SALOME_MED::MED_QUAD4,
-  SALOME_MED::MED_TRIA6,
-  SALOME_MED::MED_QUAD8
-};
-
-static int EDGEGEOM[MED_NBR_GEOMETRIE_ARETE] = {
-  SALOME_MED::MED_SEG2,
-  SALOME_MED::MED_SEG3
-};
-
-static int NODEGEOM[1] = {
-  SALOME_MED::MED_POINT1,
-};
-
-void Entity2Geom(const VISU::TEntity& theEntity, int* theVector, int* theEnd) {
-  switch(theEntity){
-  case VISU::CELL_ENTITY: theVector = CELLGEOM; *theEnd = MED_NBR_GEOMETRIE_MAILLE; break;
-  case VISU::FACE_ENTITY: theVector = FACEGEOM; *theEnd = MED_NBR_GEOMETRIE_FACE; break;
-  case VISU::EDGE_ENTITY: theVector = EDGEGEOM; *theEnd = MED_NBR_GEOMETRIE_ARETE; break;
-  case VISU::NODE_ENTITY: theVector = NODEGEOM; *theEnd = 1; break;
+namespace
+{
+  using namespace SALOME_MED;
+  
+  const int MED_NBR_GEOMETRIE_MAILLE = 15;
+  
+  medGeometryElement 
+  CELLGEOM[MED_NBR_GEOMETRIE_MAILLE] = {
+    MED_POINT1,
+    MED_SEG2,
+    MED_SEG3,
+    MED_TRIA3,
+    MED_QUAD4,
+    MED_TRIA6,
+    MED_QUAD8,
+    MED_TETRA4,
+    MED_PYRA5,
+    MED_PENTA6,
+    MED_HEXA8,
+    MED_TETRA10,
+    MED_PYRA13,
+    MED_PENTA15,
+    MED_HEXA20
+  };
+  
+  const int MED_NBR_GEOMETRIE_FACE = 4;
+  
+  medGeometryElement
+  FACEGEOM[MED_NBR_GEOMETRIE_FACE] = {
+    MED_TRIA3,
+    MED_QUAD4,
+    MED_TRIA6,
+    MED_QUAD8
+  };
+  
+  const int MED_NBR_GEOMETRIE_ARETE = 2;
+  
+  medGeometryElement
+  EDGEGEOM[MED_NBR_GEOMETRIE_ARETE] = {
+    MED_SEG2,
+    MED_SEG3
+  };
+  
+  const int MED_NBR_GEOMETRIE_NODE = 1;
+  
+  medGeometryElement
+  NODEGEOM[MED_NBR_GEOMETRIE_NODE] = {
+    MED_POINT1,
+  };
+  
+
+  //---------------------------------------------------------------
+  int
+  GetEntity2Geom(const VISU::TEntity& theEntity, medGeometryElement*& theVector)
+  {
+    switch(theEntity){
+    case CELL_ENTITY: theVector = CELLGEOM; return MED_NBR_GEOMETRIE_MAILLE; break;
+    case FACE_ENTITY: theVector = FACEGEOM; return MED_NBR_GEOMETRIE_FACE; break;
+    case EDGE_ENTITY: theVector = EDGEGEOM; return MED_NBR_GEOMETRIE_ARETE; break;
+    case NODE_ENTITY: theVector = NODEGEOM; return MED_NBR_GEOMETRIE_NODE; break;
+    }
+    return -1;
   }
-}
+  
 
-typedef pair<int*,int> TEntity2Geom;
-typedef map<SALOME_MED::medEntityMesh,TEntity2Geom> TEntity2GeomMap;
-static TEntity2GeomMap anEntity2GeomMap;
-static int INIT = (
-  anEntity2GeomMap[SALOME_MED::MED_CELL] = TEntity2Geom(CELLGEOM,MED_NBR_GEOMETRIE_MAILLE),
-  anEntity2GeomMap[SALOME_MED::MED_FACE] = TEntity2Geom(FACEGEOM,MED_NBR_GEOMETRIE_FACE),
-  anEntity2GeomMap[SALOME_MED::MED_EDGE] = TEntity2Geom(EDGEGEOM,MED_NBR_GEOMETRIE_ARETE),
-  anEntity2GeomMap[SALOME_MED::MED_NODE] = TEntity2Geom(NODEGEOM,1),
-  1
-);
-
-struct SalomeMed2vtk {
-  SALOME_MED::medGeometryElement medType;
-  char *medName;
-  int medNbNodes;
-  int vtkType;
-  char *vtkName;
-  int vtkNbNodes;
-};
-
-#define CORBAMED2VTK(MEDTYPE,VTKTYPE,VTKNBNODES) \
- {SALOME_MED::MEDTYPE,#MEDTYPE,getNbMedNodes(MEDTYPE),VTKTYPE,#VTKTYPE,VTKNBNODES}
-static SalomeMed2vtk salome_med2vtk[SALOME_MED::MED_ALL_ELEMENTS] = {
-  {SALOME_MED::MED_NONE,"MED_NONE",0,VTK_EMPTY_CELL,"VTK_EMPTY_CELL",0},
-  CORBAMED2VTK(MED_POINT1,VTK_VERTEX,1),
-  CORBAMED2VTK(MED_SEG2,VTK_LINE,2),
-  CORBAMED2VTK(MED_SEG3,VTK_LINE,2),
-  CORBAMED2VTK(MED_TRIA3,VTK_TRIANGLE,3),
-  CORBAMED2VTK(MED_QUAD4,VTK_QUAD,4),
-  CORBAMED2VTK(MED_TRIA6,VTK_TRIANGLE,3),
-  CORBAMED2VTK(MED_QUAD8,VTK_QUAD,4),
-  CORBAMED2VTK(MED_TETRA4,VTK_TETRA,4),
-  CORBAMED2VTK(MED_PYRA5,VTK_PYRAMID,5),
-  CORBAMED2VTK(MED_PENTA6,VTK_WEDGE,6),
-  CORBAMED2VTK(MED_TETRA10,VTK_TETRA,4),
-  CORBAMED2VTK(MED_HEXA8,VTK_HEXAHEDRON,8),
-  CORBAMED2VTK(MED_PYRA13,VTK_PYRAMID,5),
-  CORBAMED2VTK(MED_PENTA15,VTK_WEDGE,6),
-  CORBAMED2VTK(MED_HEXA20,VTK_HEXAHEDRON,8)
-};
-#undef CORBAMED2VTK
-
-int FindIdMEDType(int medType){
-  for(int i = 0; i < SALOME_MED::MED_ALL_ELEMENTS; i++)
-    if(salome_med2vtk[i].medType == medType) return i;
-  return -1;
-}
+  //---------------------------------------------------------------
+  int
+  MEDGeom2NbNodes(int theMEDGeomType)
+  { 
+    switch(theMEDGeomType){
+    case MED_NONE: return 0;
+    case MED_POINT1: return 1;
+    case MED_SEG2: return 2;
+    case MED_SEG3: return 3;
+    case MED_TRIA3: return 3;
+    case MED_TRIA6: return 6;
+    case MED_QUAD4: return 4;
+    case MED_QUAD8: return 8;
+    case MED_TETRA4: return 4;
+    case MED_TETRA10: return 10;
+    case MED_HEXA8: return 8;
+    case MED_HEXA20: return 20;
+    case MED_PENTA6: return 6;
+    case MED_PENTA15: return 15;
+    case MED_PYRA5: return 5;
+    case MED_PYRA13: return 13;
+    }
+    return -1;
+  }
+  
+
+  //---------------------------------------------------------------
+  VISU::EGeometry
+  MEDGeom2VISU(medGeometryElement theGeom)
+  { 
+    switch(theGeom){
+    case MED_POINT1: return VISU::ePOINT1;
+    case MED_SEG2: return VISU::eSEG2;
+    case MED_SEG3: return VISU::eSEG3;
+    case MED_TRIA3: return VISU::eTRIA3;
+    case MED_TRIA6: return VISU::eTRIA6;
+    case MED_QUAD4: return VISU::eQUAD4;
+    case MED_QUAD8: return VISU::eQUAD8;
+    case MED_TETRA4: return VISU::eTETRA4;
+    case MED_TETRA10: return VISU::eTETRA10;
+    case MED_HEXA8: return VISU::eHEXA8;
+    case MED_HEXA20: return VISU::eHEXA20;
+    case MED_PENTA6: return VISU::ePENTA6;
+    case MED_PENTA15: return VISU::ePENTA15;
+    case MED_PYRA5: return VISU::ePYRA5;
+    case MED_PYRA13: return VISU::ePYRA13;
+    }
+    return VISU::eNONE;
+  }
+  
+
+  //---------------------------------------------------------------
+  medGeometryElement 
+  VTKGeomToMED(int theVTKGeomType)
+  { 
+    switch(theVTKGeomType){
+    case VTK_VERTEX: return MED_POINT1;
+    case VTK_LINE: return MED_SEG2;
+    case VTK_TRIANGLE: return MED_TRIA3;
+    case VTK_QUAD: return MED_QUAD4;
+    case VTK_TETRA: return MED_TETRA4;
+    case VTK_HEXAHEDRON: return MED_HEXA8;
+    case VTK_WEDGE: return MED_PENTA6;
+    case VTK_PYRAMID: return MED_PYRA5;
+    }
+    return medGeometryElement(-1);
+  }
+  
+  //---------------------------------------------------------------
+  VISU::TEntity
+  MEDEntityToVTK(medEntityMesh theMEDEntity)
+  {
+    switch(theMEDEntity){
+    case MED_NODE: return NODE_ENTITY;
+    case MED_EDGE: return EDGE_ENTITY;
+    case MED_FACE: return FACE_ENTITY;
+    case MED_CELL: return CELL_ENTITY;
+    }
+    return VISU::TEntity(-1);
+  }
+  
+  //---------------------------------------------------------------
+  medEntityMesh 
+  VTKEntityToMED(VISU::TEntity theVTKEntity)
+  {
+    switch(theVTKEntity){
+    case NODE_ENTITY: return MED_NODE;
+    case EDGE_ENTITY: return MED_EDGE;
+    case FACE_ENTITY: return MED_FACE;
+    case CELL_ENTITY: return MED_CELL;
+    }
+    return medEntityMesh(-1);
+  }
+
+  
+  //---------------------------------------------------------------
+  std::string 
+  GetSObjectName(SALOMEDS::SObject_ptr aSObject)
+  {
+    SALOMEDS::GenericAttribute_var anAttr;
+    if (aSObject->FindAttribute(anAttr,"AttributeName")) {
+      SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
+      CORBA::String_var aString = aName->Value();
+      return aString.in();
+    }
+    return "";
+  }
+  
+
+  //---------------------------------------------------------------
+  void 
+  GetCellsSize(vtkIdType& theNbCells, 
+              vtkIdType& theCellsSize,
+              SALOME_MED::MESH_ptr theMEDMesh,
+              const VISU::TEntity& theVEntity)
+  {
+    medGeometryElement* aGeomElems;
+    theNbCells = theCellsSize = 0;
+    int iGeomEnd = GetEntity2Geom(theVEntity,aGeomElems);
+    const medEntityMesh& aMEntity = VTKEntityToMED(theVEntity);
+    if(MYDEBUG) MESSAGE("GetCellsSize - theVEntity = "<<theVEntity);
+    for(int iGeom = 0; iGeom < iGeomEnd; iGeom++){
+      medGeometryElement aMEDGeom = aGeomElems[iGeom];
+      int iNumElemEnd = theMEDMesh->getNumberOfElements(aMEntity,aMEDGeom);
+      if(iNumElemEnd > 0){
+       if(MYDEBUG) MESSAGE("GetCellsSize - iNumElemEnd = "<<iNumElemEnd);
+       theCellsSize += iNumElemEnd*(MEDGeom2NbNodes(aMEDGeom) + 1);
+       theNbCells += iNumElemEnd;
+      }
+    }
+  }
+  
+  
+  //---------------------------------------------------------------
+  void 
+  GetCellsSize(vtkIdType& theNbCells, 
+              vtkIdType& theCellsSize,
+              SALOME_MED::FAMILY_ptr theMEDFamily)
+  {
+    medGeometryElement_array_var aGeom = theMEDFamily->getTypes();
+    int iGeomEnd = aGeom->length();
+    theNbCells = theCellsSize = 0;
+    if(MYDEBUG) MESSAGE("GetCellsSize - iGeomEnd = "<<iGeomEnd);
+    for(int iGeom = 0; iGeom < iGeomEnd; iGeom++) {
+      medGeometryElement aMEDGeom = aGeom[iGeom];
+      long_array_var aCellNumForType = theMEDFamily->getNumber(aMEDGeom);
+      int iNumElemEnd = aCellNumForType->length();
+      if(iNumElemEnd > 0){
+       if(MYDEBUG) MESSAGE("GetCellsSize - iNumElemEnd = "<<iNumElemEnd);
+       theNbCells += iNumElemEnd;
+       theCellsSize += iNumElemEnd*(MEDGeom2NbNodes(aMEDGeom) + 1);
+      }
+    }
+  }
+  
+  
+  //---------------------------------------------------------------
+  void
+  GetCellsSize(VISU::PCMesh theMesh, 
+              SALOME_MED::MESH_ptr theMEDMesh, 
+              const VISU::TEntity& theEntity)
+  {
+    TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap;
+    VISU::PCMeshOnEntity aMeshOnEntity = aMeshOnEntityMap[theEntity];
+    if(theEntity == NODE_ENTITY){
+      aMeshOnEntity->myNbCells = theMesh->myNbPoints;
+      aMeshOnEntity->myCellsSize = 2*theMesh->myNbPoints;
+    }else{
+      GetCellsSize(aMeshOnEntity->myNbCells,aMeshOnEntity->myCellsSize,theMEDMesh,theEntity);
+    }
+  }
+
+  //---------------------------------------------------------------
+  PCMeshOnEntity 
+  InitMeshOnEntity(const VISU::PCMesh& theMesh,
+                  const VISU::TEntity& theEntity,
+                  const VISU::PCMeshOnEntity& theMeshOnEntity)
+  {
+    PCMeshOnEntity aMeshOnEntity;
+    TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap;
+    TMeshOnEntityMap::const_iterator anIter = aMeshOnEntityMap.find(theEntity);
+    if(anIter == aMeshOnEntityMap.end()){
+      aMeshOnEntity.reset(new TCMeshOnEntity());
+      *aMeshOnEntity = *theMeshOnEntity;
+      aMeshOnEntity->myEntity = theEntity;
+      aMeshOnEntityMap[theEntity] = aMeshOnEntity;
+    }else
+      aMeshOnEntity = anIter->second;
 
-void VISU_MedMeshConvertor::SetMedMesh(SALOME_MED::MESH_ptr theMedMesh) {
-  myMedMesh = SALOME_MED::MESH::_duplicate(theMedMesh);
+    GetCellsSize(theMesh,theMesh->myMesh,theEntity);
+
+    return aMeshOnEntity;
+  }
 }
 
-VISU_Convertor* VISU_MEDFieldConvertor::Build() throw (std::runtime_error&){
+
+//---------------------------------------------------------------
+VISU_Convertor* 
+VISU_MEDFieldConvertor::Build()
+{
   if(myField->_is_nil()) 
     throw std::runtime_error("VISU_MEDFieldConvertor::Build >> myField->_is_nil() !!!");
   
   SALOME_MED::SUPPORT_var aMEDSupport = myField->getSupport();
   if(aMEDSupport->_is_nil()) 
     throw std::runtime_error("VISU_MEDFieldConvertor::Build >> aMEDSupport->_is_nil() !!!");
-  SALOME_MED::medEntityMesh aMEDEntity = aMEDSupport->getEntity();
-  VISU::TEntity anEntity = aMed2VisuEntity[aMEDEntity];
+
+  SALOME_MED::medEntityMesh aMEntity = aMEDSupport->getEntity();
+  TEntity aVEntity = MEDEntityToVTK(aMEntity);
   SALOME_MED::MESH_var aMEDMesh = aMEDSupport->getMesh();
   if(aMEDMesh->_is_nil()) 
     throw std::runtime_error("VISU_MEDFieldConvertor::Build >> aMEDMesh->_is_nil() !!!");
+
   CORBA::String_var aMeshName = aMEDMesh->getName();
   CORBA::String_var aFieldName = myField->getName();
 
-  VISU::TMesh &aMesh = myMeshMap[aMeshName.in()];
-  aMesh.myDim = aMEDMesh->getSpaceDimension();
-  aMesh.myName = aMeshName.in();
-  VISUMED::TMesh &aMesh2 = myMeshMap2[aMeshName.in()];
-  aMesh2.myMesh = aMEDMesh;
-  if(MYDEBUG) MESSAGE("VISU_MEDFieldConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh.myDim);
-
-  VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
-  aMeshOnEntity.myEntity = anEntity;
-  aMeshOnEntity.myMeshName = aMeshName.in();
-  VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[anEntity];
-  aMeshOnEntity2.mySupport = aMEDSupport;
-  if(anEntity == VISU::NODE_ENTITY){
-    aMesh.myMeshOnEntityMap[VISU::CELL_ENTITY].myEntity = VISU::CELL_ENTITY;
-    aMesh.myMeshOnEntityMap[VISU::CELL_ENTITY].myMeshName = aMeshName.in();
-    aMesh2.myMeshOnEntityMap[VISU::CELL_ENTITY].mySupport = aMEDSupport;
-  }
+  PCMesh aMesh = myMeshMap[aMeshName.in()](new TCMesh());
+  aMesh->myNamedPointCoords(new TNamedPointCoords());
+  aMesh->myNbPoints = aMEDMesh->getNumberOfNodes();
+  aMesh->myDim = aMEDMesh->getSpaceDimension();
+  aMesh->myName = aMeshName.in();
+  aMesh->myMesh = aMEDMesh;
+
+  TNamedPointCoords& aCoords = aMesh->myNamedPointCoords;
+  aCoords.Init(aMesh->myNbPoints,aMesh->myDim);
+
+  if(MYDEBUG) MESSAGE("VISU_MEDFieldConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh->myDim);
+
+  TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
+  PCMeshOnEntity aMeshOnEntity = aMeshOnEntityMap[aVEntity](new TCMeshOnEntity());
+  aMeshOnEntity->myEntity = aVEntity;
+  aMeshOnEntity->myMeshName = aMeshName.in();
+  aMeshOnEntity->mySupport = aMEDSupport;
+
+  if(aVEntity == NODE_ENTITY)
+    ::InitMeshOnEntity(aMesh,CELL_ENTITY,aMeshOnEntity);
+  else
+    ::InitMeshOnEntity(aMesh,NODE_ENTITY,aMeshOnEntity);
+
+  ::GetCellsSize(aMesh,aMEDMesh,aVEntity);
+
+  TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
+  PCField aField = aFieldMap[aFieldName.in()](new TCField());
+  aField->myId = myField->getOrderNumber();
+  aField->myName = aFieldName.in();
+  aField->myEntity = aVEntity;
+  aField->myMeshName = aMeshName.in();
+  aField->InitArrays(myField->getNumberOfComponents());
+  aField->myDataSize = aMeshOnEntity->myNbCells * aField->myNbComp;
+
+  if(MYDEBUG) MESSAGE("VISU_MEDFieldConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh->myDim);
+
+  TValField& aValField = aField->myValField;
+  int anId = myField->getIterationNumber();
+  PCValForTime aValForTime = aValField[anId](new TCValForTime());
+  aValForTime->myId = anId;
+  CORBA::Double aDT = myField->getTime();
+  aValForTime->myTime = TTime(aDT,"");
+  aValForTime->myField = myField;
 
-  VISU::TField& aField = aMeshOnEntity.myFieldMap[aFieldName.in()];
-  aField.myId = myField->getOrderNumber();
-  aField.myName = aFieldName.in();
-  aField.myEntity = anEntity;
-  aField.myMeshName = aMeshName.in();
-  aField.myNbComp = myField->getNumberOfComponents();
-  aField.myCompNames.resize(aField.myNbComp);
-  aField.myUnitNames.resize(aField.myNbComp);
-  if(MYDEBUG) MESSAGE("VISU_MEDFieldConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh.myDim);
-  int iTimeStamp = myField->getIterationNumber();
-  VISU::TField::TValForTime& aValForTime = aField.myValField[iTimeStamp];
-  aValForTime.myId = iTimeStamp;
-  double dt = myField->getTime();
-  aValForTime.myTime = VISU::TField::TTime(dt,"");
-  
-  VISUMED::TField& aField2 = aMeshOnEntity2.myFieldMap[aFieldName.in()];
-  VISUMED::TField::TValForTime& aValForTime2 = aField2.myValField[iTimeStamp];
-  aValForTime2.myField = myField;
   if(MYDEBUG) 
-    MESSAGE("VISU_MEDConvertor::Build - aFieldName = '"<<aFieldName<<"'; myId = "<<aField.myId<<"; myTime = "<<dt);
+    MESSAGE("VISU_MEDFieldConvertor::Build - aFieldName = '"<<aFieldName<<
+           "'; myId = "<<anId<<"; myTime = "<<aDT);
+
   return this;
 }
 
-VISU_Convertor* VISU_MEDConvertor::Build() throw (std::runtime_error&){
+
+//---------------------------------------------------------------
+VISU_Convertor* 
+VISU_MEDConvertor::Build() 
+{
   if(mySObject->_is_nil()) 
     throw std::runtime_error("VISU_MEDConvertor::Build >> mySObject->_is_nil() !!!");
   SALOMEDS::Study_var aStudy = mySObject->GetStudy();
 
-  CORBA::Object_var aMedObject = SObjectToObject(mySObject);
+  CORBA::Object_var aMedObject = VISU::SObjectToObject(mySObject);
   if(!CORBA::is_nil(aMedObject)){
     SALOME_MED::MED_var aMED = SALOME_MED::MED::_narrow(aMedObject);
-    if(!aMED->_is_nil()){
-      CORBA::Short aTag = mySObject->Tag();
-      SALOMEDS::SObject_var aMedCompSObj = mySObject->GetFather();
-      SALOMEDS::SObject_var aMeshSObj;
-      CORBA::Boolean aBool = aMedCompSObj->FindSubObject(aTag+1,aMeshSObj);
-      if(!aBool) throw std::runtime_error("VISU_MEDConvertor::Build >> Cann't find MEDMESH label !!!");
-      if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - MEDMESH found.");
-      SALOMEDS::ChildIterator_var aMeshIterator = aStudy->NewChildIterator(aMeshSObj);
-      for(; aMeshIterator->More(); aMeshIterator->Next()){
-       aMeshSObj = aMeshIterator->Value();
-       if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aMeshSObj = '"<<::GetName(aMeshSObj)<<"'");
-       CORBA::Object_var aMedMesh = SObjectToObject(aMeshSObj);
-       if(CORBA::is_nil(aMedMesh)) continue;
-       SALOME_MED::MESH_var aMEDMesh = SALOME_MED::MESH::_narrow(aMedMesh);
-       if(aMEDMesh->_is_nil()) continue;
-       CORBA::String_var aMeshName = aMEDMesh->getName();
-       VISU::TMesh &aMesh = myMeshMap[aMeshName.in()];
-       aMesh.myDim = aMEDMesh->getSpaceDimension();
-       aMesh.myName = aMeshName.in();
-       VISUMED::TMesh &aMesh2 = myMeshMap2[aMeshName.in()];
-       aMesh2.myMesh = aMEDMesh;
-       if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh.myDim);
-       SALOMEDS::ChildIterator_var aSupportIterator = aStudy->NewChildIterator(aMeshSObj);
-       for(; aSupportIterator->More(); aSupportIterator->Next()){
-         SALOMEDS::SObject_var aSupportSObj = aSupportIterator->Value();
-         CORBA::Object_var aMedSupport = SObjectToObject(aSupportSObj);
-         if(CORBA::is_nil(aMedSupport)) continue;
-         SALOME_MED::SUPPORT_var aMEDSupport = SALOME_MED::SUPPORT::_narrow(aMedSupport); 
-         if(aMEDSupport->_is_nil()) continue;
-         SALOME_MED::medEntityMesh aMEDEntity = aMEDSupport->getEntity();
-         VISU::TEntity anEntity = aMed2VisuEntity[aMEDEntity];
-         CORBA::String_var aSupportName = aMEDSupport->getName();
-         bool isDataPresent = false;
-         if(aMEDSupport->isOnAllElements()){
-           if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - Support isOnAllElements = '"<<aSupportName<<"' anEntity = "<<anEntity);
-           //Check, if there is any data on the support?
-           SALOME_MED::MESH_var aMeshOnSupport = aMEDSupport->getMesh();
-           if(anEntity == VISU::NODE_ENTITY){
-             if(aMeshOnSupport->getNumberOfNodes() > 0) 
-               isDataPresent = true;
-           }else{
-             int iGeomElemEnd;
-             int* aGeomElemVector;
-             GetEntity2Geom(anEntity,aGeomElemVector,&iGeomElemEnd);
-             const SALOME_MED::medEntityMesh& aMedEntity = aVisu2MedEntity[anEntity];
-             for (int iGeomElem = 0, aCounter = 0; iGeomElem < iGeomElemEnd; iGeomElem++) {
-               int medId = GetIdMEDType(aGeomElemVector[iGeomElem]);
-               SALOME_MED::medGeometryElement aMedType = salome_med2vtk[medId].medType;
-               med_int iNumElemEnd = aMeshOnSupport->getNumberOfElements(aMedEntity,aMedType);
-               if(iNumElemEnd > 0) {
-                 isDataPresent = true;
-                 break;
-               }
-             }
-           }
-           if(!isDataPresent) continue;
-           VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
-           aMeshOnEntity.myEntity = anEntity;
-           aMeshOnEntity.myMeshName = aMeshName.in();
-           VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[anEntity];
-           aMeshOnEntity2.mySupport = aMEDSupport;
-         }else{
-           SALOME_MED::FAMILY_var aMEDFamily = SALOME_MED::FAMILY::_narrow(aMedSupport);
-           if(!aMEDFamily->_is_nil()) {
-             if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aFamily = '"<<aSupportName<<"' anEntity = "<<anEntity);
-             VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
-             VISU::TFamily& aFamily = aMeshOnEntity.myFamilyMap[aSupportName.in()];
-             aFamily.myName = aSupportName.in();
-             aFamily.myEntity = anEntity;
-             aFamily.myId = aMEDFamily->getIdentifier();
-             VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[anEntity];
-             VISUMED::TFamily& aFamily2 = aMeshOnEntity2.myFamilyMap[aSupportName.in()];
-             aFamily2.myFamily = aMEDFamily;
-           }
-           SALOME_MED::GROUP_var aMEDGroup = SALOME_MED::GROUP::_narrow(aMedSupport);
-           if(!aMEDGroup->_is_nil()) {
-             if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aGroup = '"<<aSupportName<<"' anEntity = "<<anEntity);
-             VISUMED::TGroupMap& aGroupMap2 = aMesh2.myGroupMap;
-             VISUMED::TGroup& aGroup2 = aGroupMap2[aSupportName.in()];
-             aGroup2.myGroup = aMEDGroup;
-             //VISU::TGroupMap& aGroupMap = aMesh.myGroupMap;
-             //VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
-             //VISU::TGroup& aGroup = aGroupMap[aSupportName.in()];
-             //aGroup.myName = aSupportName.in();
-             //aGroup.myMeshName = aMesh.myName;
-             SALOME_MED::Family_array_var aFamilies = aMEDGroup->getFamilies();
-             int iFamilyEnd = aFamilies->length();
-             for(int iFamaily = 0; iFamaily < iFamilyEnd; iFamaily++){
-               aMEDFamily = aFamilies[iFamaily];
-               CORBA::String_var aFamilyName = aMEDFamily->getName();
-               VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
-               VISU::TFamily& aFamily = aMeshOnEntity.myFamilyMap[aFamilyName.in()];
-               VISU::TBindGroups& aBindGroups = aFamily.myGroups;
-               aBindGroups.insert(aSupportName.in());
-             }
-           }
-         }
-       }
-       //Correction of TMesh.TGroupMap
-       const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh.myMeshOnEntityMap;
-       if(aMeshOnEntityMap.empty()) continue;
-       VISU::TGroupMap& aGroupMap = aMesh.myGroupMap;
-       VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
-       for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
-         const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
-         const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity.myFamilyMap;
-         if(aFamilyMap.empty()) continue;
-         VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
-         for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
-           const VISU::TFamily& aFamily = aFamilyMapIter->second;
-           const VISU::TBindGroups& aBindGroups = aFamily.myGroups;
-           if(aBindGroups.empty()) continue;
-           VISU::TBindGroups::const_iterator aBindGroupsIter = aBindGroups.begin();
-           for(; aBindGroupsIter != aBindGroups.end(); aBindGroupsIter++){
-             const string& aGroupName = *aBindGroupsIter;
-             VISU::TGroup& aGroup = aGroupMap[aGroupName];
-             aGroup.myName = aGroupName;
-             aGroup.myMeshName = aMesh.myName;
-             VISU::TFamilyAndEntity aFamilyAndEntity(aFamily.myName,aFamily.myEntity);
-             aGroup.myFamilyAndEntitySet.insert(aFamilyAndEntity);
-           }
-         }
-       }
+    return Build(aMED);
+  }
+
+  SALOMEDS::ChildIterator_var aTimeStampIterator = aStudy->NewChildIterator(mySObject);
+  return Build(aTimeStampIterator);
+}
+
+
+namespace{
+
+  using namespace boost;
+
+  //---------------------------------------------------------------
+  struct TSObjectByName
+  {
+    std::string myName;
+    typedef tuple<SALOMEDS::SObject_var> TRet;
+
+    TSObjectByName(const std::string& theName):
+      myName(theName)
+    {}
+
+    TRet operator()(SALOMEDS::SObject_ptr theSObj, bool& theIsSuccess)
+    {
+      SALOMEDS::GenericAttribute_var anAttr;
+      if(theSObj->FindAttribute(anAttr,"AttributeName")){
+       SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
+       CORBA::String_var aValue = aName->Value();
+       theIsSuccess = (myName == aValue.in());
+       if(theIsSuccess)
+         return TRet(SALOMEDS::SObject::_duplicate(theSObj));
       }
-      SALOMEDS::SObject_var aFieldSObj;
-      aBool = aMedCompSObj->FindSubObject(aTag+2,aFieldSObj);
-      if(aBool){
-       if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - MEDFIELD found.");
-       SALOMEDS::ChildIterator_var aFieldIterator = aStudy->NewChildIterator(aFieldSObj);
-       for(int iField = 0; aFieldIterator->More(); aFieldIterator->Next(), iField++){
-         aFieldSObj = aFieldIterator->Value();
-         if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aFieldName = '"<<::GetName(aFieldSObj)<<"'");
-         SALOMEDS::ChildIterator_var aTimeStampIterator = aStudy->NewChildIterator(aFieldSObj);
-         for(; aTimeStampIterator->More(); aTimeStampIterator->Next()){
-           SALOMEDS::SObject_var aTimeStampSObj = aTimeStampIterator->Value();
-           if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aTimeStampSObj = '"<<::GetName(aTimeStampSObj)<<"'");
-           CORBA::Object_var aMedField = SObjectToObject(aTimeStampSObj);
-           if(CORBA::is_nil(aMedField)) continue;
-           SALOME_MED::FIELD_var aMEDField = SALOME_MED::FIELD::_narrow(aMedField);
-           if(aMEDField->_is_nil()) continue;
-           SALOME_MED::SUPPORT_var aMEDSupport = aMEDField->getSupport();
-           if(aMEDSupport->_is_nil()) continue;
-           SALOME_MED::medEntityMesh aMEDEntity = aMEDSupport->getEntity();
-           VISU::TEntity anEntity = aMed2VisuEntity[aMEDEntity];
-           SALOME_MED::MESH_var aMEDMesh = aMEDSupport->getMesh();
-           if(aMEDMesh->_is_nil()) continue;
-           CORBA::String_var aMeshName = aMEDMesh->getName();
-           CORBA::String_var aFieldName = aMEDField->getName();
-
-           VISU::TMesh &aMesh = myMeshMap[aMeshName.in()];
-           aMesh.myDim = aMEDMesh->getSpaceDimension();
-           aMesh.myName = aMeshName.in();
-           VISUMED::TMesh &aMesh2 = myMeshMap2[aMeshName.in()];
-           aMesh2.myMesh = aMEDMesh;
-
-           VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
-           aMeshOnEntity.myEntity = anEntity;
-           aMeshOnEntity.myMeshName = aMeshName.in();
-           VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[anEntity];
-           aMeshOnEntity2.mySupport = aMEDSupport;
-           if(anEntity == VISU::NODE_ENTITY){
-             aMesh.myMeshOnEntityMap[VISU::CELL_ENTITY].myEntity = VISU::CELL_ENTITY;
-             aMesh.myMeshOnEntityMap[VISU::CELL_ENTITY].myMeshName = aMeshName.in();
-             aMesh2.myMeshOnEntityMap[VISU::CELL_ENTITY].mySupport = aMEDSupport;
+      return TRet();
+    }
+
+  };
+
+
+  //---------------------------------------------------------------
+  struct TMeshByName
+  {
+    std::string myName;
+    typedef tuple<SALOME_MED::MESH_var,SALOMEDS::SObject_var> TRet;
+
+    TMeshByName(const std::string& theName):
+      myName(theName)
+    {}
+
+    TRet operator()(SALOMEDS::SObject_ptr theSObj, bool& theIsSuccess)
+    {
+      CORBA::Object_var anObj = VISU::SObjectToObject(theSObj);
+      if(!CORBA::is_nil(anObj)){
+       SALOME_MED::MESH_var aMesh = SALOME_MED::MESH::_narrow(anObj);
+       if(!CORBA::is_nil(aMesh)){
+         CORBA::String_var aName = aMesh->getName();
+         theIsSuccess = (myName == aName.in());
+         if(theIsSuccess)
+           return TRet(aMesh,SALOMEDS::SObject::_duplicate(theSObj));
+       }
+      }
+      return TRet();
+    }
+  };
+
+
+  //---------------------------------------------------------------
+  template<typename TFun>
+  typename TFun::TRet
+  Find(SALOMEDS::SObject_ptr theStartSObj, 
+       SALOMEDS::Study_ptr theStudy,
+       TFun theFun,
+       bool& theIsSuccess,
+       bool theIsAllLevels = true)
+  {
+    SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator(theStartSObj);
+    anIter->InitEx(theIsAllLevels);
+    for(; anIter->More(); anIter->Next()){
+      SALOMEDS::SObject_var aSObj = anIter->Value();
+      typename TFun::TRet aRet = theFun(aSObj,theIsSuccess);
+      if(theIsSuccess)
+       return aRet;
+    }
+    return typename TFun::TRet();
+  }
+
+}
+
+
+//---------------------------------------------------------------
+VISU_Convertor* 
+VISU_MEDConvertor::Build(SALOME_MED::MED_ptr theMED)
+{
+  if(CORBA::is_nil(theMED)) 
+    return NULL;
+
+  CORBA::Long aNbMeshes = theMED->getNumberOfMeshes();
+  SALOME_MED::string_array_var aMeshNames = theMED->getMeshNames();
+  if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aNbMeshes = "<<aNbMeshes);
+
+  SALOMEDS::Study_var aStudy = mySObject->GetStudy();
+  SALOMEDS::SObject_var aMedCompSObj = mySObject->GetFather();
+
+  bool anIsSuccess = false;
+  TSObjectByName::TRet aSObjectByNameRet = 
+    Find(aMedCompSObj,aStudy,TSObjectByName("MEDMESH"),anIsSuccess);
+  if(MYDEBUG) 
+    MESSAGE("VISU_MEDConvertor::Build - Find ('"<<"MEDMESH"<<"') = "<<anIsSuccess);
+  if(anIsSuccess){
+    SALOMEDS::SObject_var aMeshesSObj = boost::get<0>(aSObjectByNameRet);
+    for(int iMesh = 0; iMesh < aNbMeshes; iMesh++){
+      anIsSuccess = false;
+      CORBA::String_var aMeshName = aMeshNames[iMesh];
+      TMeshByName::TRet aMeshByNameRet = 
+       Find(aMeshesSObj,aStudy,TMeshByName(aMeshName.in()),anIsSuccess);
+      if(MYDEBUG) 
+       MESSAGE("VISU_MEDConvertor::Build - Find aMeshName('"<<aMeshName.in()<<"') = "<<anIsSuccess);
+      if(!anIsSuccess)
+       continue;
+
+      PCMesh aMesh = myMeshMap[aMeshName.in()](new TCMesh());
+      SALOME_MED::MESH_var aMEDMesh = boost::get<0>(aMeshByNameRet);
+      aMesh->myNamedPointCoords(new TNamedPointCoords());
+      aMesh->myNbPoints = aMEDMesh->getNumberOfNodes();
+      aMesh->myDim = aMEDMesh->getSpaceDimension();
+      aMesh->myName = aMeshName.in();
+      aMesh->myMesh = aMEDMesh;
+
+      TNamedPointCoords& aCoords = aMesh->myNamedPointCoords;
+      aCoords.Init(aMesh->myNbPoints,aMesh->myDim);
+
+      if(MYDEBUG) 
+       MESSAGE("VISU_MEDConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh->myDim);
+
+      std::string aName = aMeshName.in();
+      std::replace(aName.begin(),aName.end(),' ','_');
+
+      anIsSuccess = false;
+      std::ostringstream aStream;
+      aStream<<"MEDSUPPORTS_OF_"<<aName;
+      std::string aSupportsName(aStream.str());
+      TSObjectByName::TRet aSObjectByNameRet = 
+       Find(aMeshesSObj,aStudy,TSObjectByName(aSupportsName.c_str()),anIsSuccess);
+      if(MYDEBUG) 
+       MESSAGE("VISU_MEDConvertor::Build - Find aSupportsName('"<<aSupportsName<<"') = "<<anIsSuccess);
+      if(!anIsSuccess)
+       continue;
+
+      TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
+      SALOMEDS::SObject_var aSupportsSObj = boost::get<0>(aSObjectByNameRet);
+      SALOMEDS::ChildIterator_var aSupportIterator = aStudy->NewChildIterator(aSupportsSObj);
+
+      // Fill all MeshOnEntity
+      aSupportIterator->InitEx(true);
+      for(; aSupportIterator->More(); aSupportIterator->Next()){
+       SALOMEDS::SObject_var aSupportSObj = aSupportIterator->Value();
+       
+       CORBA::Object_var aMedSupport = VISU::SObjectToObject(aSupportSObj);
+       if(CORBA::is_nil(aMedSupport)) 
+         continue;
+       
+       SALOME_MED::SUPPORT_var aMEDSupport = SALOME_MED::SUPPORT::_narrow(aMedSupport); 
+       if(aMEDSupport->_is_nil()) 
+         continue;
+       
+       SALOME_MED::MESH_var aMeshOnSupport = aMEDSupport->getMesh();
+       SALOME_MED::medEntityMesh aMEntity = aMEDSupport->getEntity();
+       VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
+       CORBA::String_var aSupportName = aMEDSupport->getName();
+       
+       if(aMEDSupport->isOnAllElements() && strcmp(aSupportName.in(),"SupportOnAll_MED_") > 0){
+         if(MYDEBUG) 
+           MESSAGE("VISU_MEDConvertor::Build - Support isOnAllElements = '"<<aSupportName<<
+                   "' aVEntity = "<<aVEntity);
+         int aNbCells, aCellsSize;
+         //Check, if there is any data on the support?
+         if(aVEntity == NODE_ENTITY){
+           aMesh->myNbPoints = aMeshOnSupport->getNumberOfNodes();
+           aNbCells = aMesh->myNbPoints;
+           aCellsSize = 2*aMesh->myNbPoints;
+         }else
+           ::GetCellsSize(aNbCells,aCellsSize,aMeshOnSupport,aVEntity);
+         
+         if(aNbCells > 0){
+           TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.find(aVEntity);
+           if(aMeshOnEntityMapIter == aMeshOnEntityMap.end()){
+             PCMeshOnEntity aMeshOnEntity(new TCMeshOnEntity());
+             aMeshOnEntity->myMeshName = aMeshName.in();
+             aMeshOnEntity->myEntity = aVEntity;
+             aMeshOnEntity->myNbCells = aNbCells;
+             aMeshOnEntity->myCellsSize = aCellsSize;
+             aMeshOnEntity->mySupport = aMEDSupport;
+             aMeshOnEntityMap[aVEntity] = aMeshOnEntity;
+           }
+         }
+       }
+      }
+
+      // Fill all Family
+      aSupportIterator->InitEx(true);
+      for(; aSupportIterator->More(); aSupportIterator->Next()){
+       SALOMEDS::SObject_var aSupportSObj = aSupportIterator->Value();
+       
+       CORBA::Object_var aMedSupport = VISU::SObjectToObject(aSupportSObj);
+       if(CORBA::is_nil(aMedSupport)) 
+         continue;
+       
+       SALOME_MED::SUPPORT_var aMEDSupport = SALOME_MED::SUPPORT::_narrow(aMedSupport); 
+       if(aMEDSupport->_is_nil()) 
+         continue;
+       
+       SALOME_MED::MESH_var aMeshOnSupport = aMEDSupport->getMesh();
+       SALOME_MED::medEntityMesh aMEntity = aMEDSupport->getEntity();
+       VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
+       CORBA::String_var aSupportName = aMEDSupport->getName();
+       
+       SALOME_MED::FAMILY_var aMEDFamily = SALOME_MED::FAMILY::_narrow(aMedSupport);
+       if(!aMEDFamily->_is_nil()) {
+         TMeshOnEntityMap::iterator aMeshOnEntityMapIter = aMeshOnEntityMap.find(aVEntity);
+         if(aMeshOnEntityMapIter == aMeshOnEntityMap.end())
+           continue;
+         PCMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
+
+         int aNbCells = aMeshOnEntity->myNbCells, aCellsSize = aMeshOnEntity->myCellsSize;
+         CORBA::Boolean anIsOnAllElements = aMEDSupport->isOnAllElements();
+         if(!anIsOnAllElements)
+           ::GetCellsSize(aNbCells,aCellsSize,aMEDFamily);
+
+         if(MYDEBUG) 
+           MESSAGE("VISU_MEDConvertor::Build "<<
+                   "- aFamily = '"<<aSupportName<<"'"<<
+                   "; anIsOnAllElements = "<<anIsOnAllElements<<
+                   "; aVEntity = "<<aVEntity<<
+                   "; aNbCells = "<<aNbCells);
+
+         if(aNbCells > 0){
+           TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
+           TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.find(aSupportName.in());
+           if(aFamilyMapIter == aFamilyMap.end()){
+             PCFamily aFamily(new TCFamily());
+             aFamily->myEntity = aVEntity;
+             aFamily->myNbCells = aNbCells;
+             aFamily->myCellsSize = aCellsSize;
+             aFamily->myId = aMEDFamily->getIdentifier();
+             aFamily->myName = aSupportName.in();
+             aFamily->myFamily = aMEDFamily;
+             aFamilyMap[aSupportName.in()] = aFamily;
+           }
+         }
+       }
+      }
+       
+      // Fill all Groups
+      aSupportIterator->InitEx(true);
+      for(; aSupportIterator->More(); aSupportIterator->Next()){
+       SALOMEDS::SObject_var aSupportSObj = aSupportIterator->Value();
+       
+       CORBA::Object_var aMedSupport = VISU::SObjectToObject(aSupportSObj);
+       if(CORBA::is_nil(aMedSupport)) 
+         continue;
+       
+       SALOME_MED::SUPPORT_var aMEDSupport = SALOME_MED::SUPPORT::_narrow(aMedSupport); 
+       if(aMEDSupport->_is_nil()) 
+         continue;
+       
+       SALOME_MED::MESH_var aMeshOnSupport = aMEDSupport->getMesh();
+       SALOME_MED::medEntityMesh aMEntity = aMEDSupport->getEntity();
+       VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
+       CORBA::String_var aSupportName = aMEDSupport->getName();
+       
+       SALOME_MED::GROUP_var aMEDGroup = SALOME_MED::GROUP::_narrow(aMedSupport);
+       if(!aMEDGroup->_is_nil()){
+         CORBA::Boolean anIsOnAllElements = aMEDSupport->isOnAllElements();
+
+         if(MYDEBUG) 
+           MESSAGE("VISU_MEDConvertor::Build "<<
+                   "- aGroup = '"<<aSupportName<<"'"<<
+                   "; anIsOnAllElements = "<<anIsOnAllElements<<
+                   "; aVEntity = "<<aVEntity);
+
+         PCGroup aGroup(new TCGroup());
+         aGroup->myGroup = aMEDGroup;
+         VISU::TFamilySet& aFamilySet = aGroup->myFamilySet;
+         
+         SALOME_MED::Family_array_var aFamilies = aMEDGroup->getFamilies();
+         int iFamilyEnd = aFamilies->length();
+         for(int iFamaily = 0; iFamaily < iFamilyEnd; iFamaily++){
+           SALOME_MED::FAMILY_var aMEDFamily = aFamilies[iFamaily];
+           CORBA::String_var aFamilyName = aMEDFamily->getName();
+           TFindFamilyOnEntity aFindFamilyOnEntity = 
+             FindFamilyOnEntity(aMeshName.in(),aVEntity,aFamilyName.in());
+           PCFamily aFamily = boost::get<2>(aFindFamilyOnEntity);
+           if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aGroup - aFamilyName = '"<<aFamilyName.in()<<"' = "<<bool(aFamily));
+           if(aFamily){
+             aFamilySet.insert(aFamily);
            }
+         }
+         
+         if(!aFamilySet.empty()){
+           TGroupMap& aGroupMap = aMesh->myGroupMap;
+           aGroupMap[aSupportName.in()] = aGroup;
+         }
 
-           VISU::TField& aField = aMeshOnEntity.myFieldMap[aFieldName.in()];
-           aField.myId = iField;
-           aField.myName = aFieldName.in();
-           aField.myEntity = anEntity;
-           aField.myMeshName = aMeshName.in();
-           aField.myNbComp = aMEDField->getNumberOfComponents();
-           aField.myCompNames.resize(aField.myNbComp);
-           aField.myUnitNames.resize(aField.myNbComp);
-           //int iTimeStamp = aMEDField->getOrderNumber();
-           int iTimeStamp = aMEDField->getIterationNumber();
-           VISU::TField::TValForTime& aValForTime = aField.myValField[iTimeStamp];
-           aValForTime.myId = iTimeStamp;
-           double dt = aMEDField->getTime();
-           aValForTime.myTime = VISU::TField::TTime(dt,"");
-
-           VISUMED::TField& aField2 = aMeshOnEntity2.myFieldMap[aFieldName.in()];
-           VISUMED::TField::TValForTime& aValForTime2 = aField2.myValField[iTimeStamp];
-           aValForTime2.myField = aMEDField;
-           if(MYDEBUG) 
-             MESSAGE("VISU_MEDConvertor::Build - aMeshName = '"<<aMeshName<<"'; myEntity = "<<anEntity<<"; myTime = "<<dt);
-         }      
-       }
+       }
       }
-      return this; 
     }
-    return NULL; 
   }
-  SALOMEDS::ChildIterator_var aTimeStampIterator = aStudy->NewChildIterator(mySObject);
-  for(; aTimeStampIterator->More(); aTimeStampIterator->Next()){
-    SALOMEDS::SObject_var aTimeStampSObj = aTimeStampIterator->Value();
-    if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aTimeStampSObj = '"<<::GetName(aTimeStampSObj)<<"'");
-    CORBA::Object_var aMedField = SObjectToObject(aTimeStampSObj);
-    if(CORBA::is_nil(aMedField)) continue;
+
+  anIsSuccess = false;
+  aSObjectByNameRet = Find(aMedCompSObj,aStudy,TSObjectByName("MEDFIELD"),anIsSuccess);
+  if(anIsSuccess){
+    SALOMEDS::SObject_var aFieldsSObj = boost::get<0>(aSObjectByNameRet);
+    if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - MEDFIELD found.");
+    SALOMEDS::ChildIterator_var aFieldIterator = aStudy->NewChildIterator(aFieldsSObj);
+    for(int iField = 0; aFieldIterator->More(); aFieldIterator->Next(), iField++){
+      SALOMEDS::SObject_var aFieldSObj = aFieldIterator->Value();
+      if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aFieldName = '"<<GetSObjectName(aFieldSObj)<<"'");
+      SALOMEDS::ChildIterator_var aTimeStampIterator = aStudy->NewChildIterator(aFieldSObj);
+      for(; aTimeStampIterator->More(); aTimeStampIterator->Next()){
+       SALOMEDS::SObject_var aTimeStampSObj = aTimeStampIterator->Value();
+       if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aTimeStampSObj = '"<<GetSObjectName(aTimeStampSObj)<<"'");
+       CORBA::Object_var aMedField = VISU::SObjectToObject(aTimeStampSObj);
+       if(CORBA::is_nil(aMedField)) 
+         continue;
+
+       SALOME_MED::FIELD_var aMEDField = SALOME_MED::FIELD::_narrow(aMedField);
+       if(aMEDField->_is_nil()) 
+         continue;
+
+       SALOME_MED::SUPPORT_var aMEDSupport = aMEDField->getSupport();
+       if(aMEDSupport->_is_nil()) 
+         continue;
+
+       SALOME_MED::medEntityMesh aMEntity = aMEDSupport->getEntity();
+       VISU::TEntity anEntity = MEDEntityToVTK(aMEntity);
+       SALOME_MED::MESH_var aMEDMesh = aMEDSupport->getMesh();
+       if(aMEDMesh->_is_nil()) 
+         continue;
+
+       CORBA::String_var aMeshName = aMEDMesh->getName();
+       CORBA::String_var aFieldName = aMEDField->getName();
+       
+       TMeshMap::iterator aMeshMapIter = myMeshMap.find(aMeshName.in());
+       if(aMeshMapIter == myMeshMap.end())
+         continue;
+
+       PCMesh aMesh = aMeshMapIter->second;
+       TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
+       TMeshOnEntityMap::iterator aMeshOnEntityMapIter = aMeshOnEntityMap.find(anEntity);
+       if(aMeshOnEntityMapIter == aMeshOnEntityMap.end())
+         continue;
+
+       PCMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
+       TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
+       TFieldMap::iterator aFieldMapIter = aFieldMap.find(aFieldName.in());
+       PCField aField;
+       if(aFieldMapIter == aFieldMap.end()){
+         aField = aFieldMap[aFieldName.in()](new TCField());
+         aField->myId = iField;
+         aField->myName = aFieldName.in();
+         aField->myEntity = anEntity;
+         aField->myMeshName = aMeshName.in();
+         aField->InitArrays(aMEDField->getNumberOfComponents());
+         aField->myDataSize = aMeshOnEntity->myNbCells * aField->myNbComp;
+         if(MYDEBUG) 
+           MESSAGE("VISU_MEDConvertor::Build - aMeshOnEntity->myNbCells = "<<aMeshOnEntity->myNbCells);
+       }else
+         aField = aFieldMapIter->second;
+
+       TValField& aValField = aField->myValField;
+       int anId = aMEDField->getIterationNumber();
+       PCValForTime aValForTime = aValField[anId](new TCValForTime());
+       aValForTime->myId = anId;
+       CORBA::Double aDT = aMEDField->getTime();
+       aValForTime->myTime = TTime(aDT,"");
+       aValForTime->myField = aMEDField;
+       if(MYDEBUG) 
+         MESSAGE("VISU_MEDConvertor::Build - aMeshName = '"<<aMeshName<<
+                 "'; myEntity = "<<anEntity<<"; myTime = "<<aDT);
+      }      
+    }
+  }
+  return this; 
+}
+
+//---------------------------------------------------------------
+VISU_Convertor* 
+VISU_MEDConvertor::Build(SALOMEDS::ChildIterator_ptr theTimeStampIterator)
+{
+  if(theTimeStampIterator->_is_nil()) return NULL;
+  for(; theTimeStampIterator->More(); theTimeStampIterator->Next()){
+    SALOMEDS::SObject_var aTimeStampSObj = theTimeStampIterator->Value();
+    if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aTimeStampSObj = '"<<GetSObjectName(aTimeStampSObj)<<"'");
+
+    CORBA::Object_var aMedField = VISU::SObjectToObject(aTimeStampSObj);
+    if(CORBA::is_nil(aMedField)) 
+      continue;
+
     SALOME_MED::FIELD_var aMEDField = SALOME_MED::FIELD::_narrow(aMedField);
-    if(aMEDField->_is_nil()) continue;
+    if(aMEDField->_is_nil()) 
+      continue;
+
     SALOME_MED::SUPPORT_var aMEDSupport = aMEDField->getSupport();
-    if(aMEDSupport->_is_nil()) continue;
-    SALOME_MED::medEntityMesh aMEDEntity = aMEDSupport->getEntity();
-    VISU::TEntity anEntity = aMed2VisuEntity[aMEDEntity];
+    if(aMEDSupport->_is_nil()) 
+      continue;
+
+    SALOME_MED::medEntityMesh aMEntity = aMEDSupport->getEntity();
+    TEntity aVEntity = MEDEntityToVTK(aMEntity);
     SALOME_MED::MESH_var aMEDMesh = aMEDSupport->getMesh();
     if(aMEDMesh->_is_nil()) continue;
     CORBA::String_var aMeshName = aMEDMesh->getName();
     CORBA::String_var aFieldName = aMEDField->getName();
 
-    VISU::TMesh &aMesh = myMeshMap[aMeshName.in()];
-    aMesh.myDim = aMEDMesh->getSpaceDimension();
-    aMesh.myName = aMeshName.in();
-    VISUMED::TMesh &aMesh2 = myMeshMap2[aMeshName.in()];
-    aMesh2.myMesh = aMEDMesh;
-    if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh.myDim);
-
-    VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
-    aMeshOnEntity.myEntity = anEntity;
-    aMeshOnEntity.myMeshName = aMeshName.in();
-    VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[anEntity];
-    aMeshOnEntity2.mySupport = aMEDSupport;
-    if(anEntity == VISU::NODE_ENTITY){
-      aMesh.myMeshOnEntityMap[VISU::CELL_ENTITY].myEntity = VISU::CELL_ENTITY;
-      aMesh.myMeshOnEntityMap[VISU::CELL_ENTITY].myMeshName = aMeshName.in();
-      aMesh2.myMeshOnEntityMap[VISU::CELL_ENTITY].mySupport = aMEDSupport;
-    }
+    PCMesh aMesh;
+    TMeshMap::const_iterator aMeshMapIter = myMeshMap.find(aMeshName.in());
+    if(aMeshMapIter == myMeshMap.end()){
+      aMesh.reset(new TCMesh());
+      aMesh->myNamedPointCoords(new TNamedPointCoords());
+      aMesh->myNbPoints = aMEDMesh->getNumberOfNodes();
+      aMesh->myDim = aMEDMesh->getSpaceDimension();
+      aMesh->myName = aMeshName.in();
+      aMesh->myMesh = aMEDMesh;
+      
+      TNamedPointCoords& aCoords = aMesh->myNamedPointCoords;
+      aCoords.Init(aMesh->myNbPoints,aMesh->myDim);
+
+      myMeshMap[aMeshName.in()] = aMesh;
+
+      if(MYDEBUG) 
+       MESSAGE("VISU_MEDConvertor::Build "<<
+               "- aMeshName = '"<<aMeshName<<"'"<<
+               "; aDim = "<<aMesh->myDim);
+    }else
+      aMesh = aMeshMapIter->second;
+
+    PCMeshOnEntity aMeshOnEntity;
+    TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
+    TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.find(aVEntity);
+    if(aMeshOnEntityMapIter == aMeshOnEntityMap.end()){
+      aMeshOnEntity.reset(new TCMeshOnEntity());
+      aMeshOnEntity->myEntity = aVEntity;
+      aMeshOnEntity->myMeshName = aMeshName.in();
+      aMeshOnEntity->mySupport = aMEDSupport;
+      aMeshOnEntityMap[aVEntity] = aMeshOnEntity;
+    }else
+      aMeshOnEntity = aMeshOnEntityMapIter->second;
+
+    if(aVEntity == NODE_ENTITY)
+      ::InitMeshOnEntity(aMesh,CELL_ENTITY,aMeshOnEntity);
+    else
+      ::InitMeshOnEntity(aMesh,NODE_ENTITY,aMeshOnEntity);
+
+    ::GetCellsSize(aMesh,aMEDMesh,aVEntity);
+
+    PCField aField;
+    TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
+    TFieldMap::const_iterator aFieldMapIter = aFieldMap.find(aFieldName.in());
+    if(aFieldMapIter == aFieldMap.end()){
+      aField.reset(new TCField());
+      aField->myId = mySObject->Tag();
+      aField->myName = aFieldName.in();
+      aField->myEntity = aVEntity;
+      aField->myMeshName = aMeshName.in();
+      aField->InitArrays(aMEDField->getNumberOfComponents());
+      aField->myDataSize = aMeshOnEntity->myNbCells * aField->myNbComp;
+      
+      aFieldMap[aFieldName.in()] = aField;
+
+      if(MYDEBUG) 
+       MESSAGE("VISU_MEDConvertor::Build - aMeshOnEntity->myNbCells = "<<aMeshOnEntity->myNbCells);
+    }else
+      aField = aFieldMapIter->second;
 
-    VISU::TField& aField = aMeshOnEntity.myFieldMap[aFieldName.in()];
-    CORBA::Short iField = mySObject->Tag();
-    aField.myId = iField;
-    aField.myName = aFieldName.in();
-    aField.myEntity = anEntity;
-    aField.myMeshName = aMeshName.in();
-    aField.myNbComp = aMEDField->getNumberOfComponents();
-    aField.myCompNames.resize(aField.myNbComp);
-    aField.myUnitNames.resize(aField.myNbComp);
-    //int iTimeStamp = aMEDField->getOrderNumber();
-    int iTimeStamp = aMEDField->getIterationNumber();
-    VISU::TField::TValForTime& aValForTime = aField.myValField[iTimeStamp];
-    aValForTime.myId = iTimeStamp;
-    double dt = aMEDField->getTime();
-    aValForTime.myTime = VISU::TField::TTime(dt,"");
-
-    VISUMED::TField& aField2 = aMeshOnEntity2.myFieldMap[aFieldName.in()];
-    VISUMED::TField::TValForTime& aValForTime2 = aField2.myValField[iTimeStamp];
-    aValForTime2.myField = aMEDField;
+    TValField& aValField = aField->myValField;
+    int anId = aMEDField->getIterationNumber();
+    PCValForTime aValForTime = aValField[anId](new TCValForTime());
+    aValForTime->myId = anId;
+    CORBA::Double aDT = aMEDField->getTime();
+    aValForTime->myTime = TTime(aDT,"");
+    aValForTime->myField = aMEDField;
     if(MYDEBUG) 
-      MESSAGE("VISU_MEDConvertor::Build - aMeshName = '"<<aMeshName<<"'; myEntity = "<<anEntity<<"; myTime = "<<dt);
+      MESSAGE("VISU_MEDConvertor::Build "<<
+             "- aMeshName = '"<<aMeshName<<"'"<<
+             "; myEntity = "<<aVEntity<<
+             "; myTime = "<<aDT<<
+             "; anId = "<<anId);
   }
   return this; 
 }
 
-int VISU_MEDConvertor::LoadMeshOnEntity(VISU::TMeshOnEntity& theMeshOnEntity, 
-                                       const string& theFamilyName)
-     throw (std::runtime_error&) 
+
+//---------------------------------------------------------------
+int
+VISU_MEDConvertor
+::LoadMeshOnEntity(VISU::PMeshImpl theMesh,
+                  VISU::PMeshOnEntityImpl theMeshOnEntity)
 {
-  //Main part of code
-  const string& aMeshName = theMeshOnEntity.myMeshName;
-  const VISU::TEntity& anEntity = theMeshOnEntity.myEntity;
-  VISU::TMesh& aMesh = myMeshMap[aMeshName];
-  int isPointsUpdated;
-  if(anEntity == VISU::NODE_ENTITY) 
-    isPointsUpdated = LoadPoints(aMesh,theFamilyName);
-  else 
-    isPointsUpdated = LoadPoints(aMesh);
-  int isCellsOnEntityUpdated = LoadCellsOnEntity(theMeshOnEntity,theFamilyName);
-
-  return (isPointsUpdated || isCellsOnEntityUpdated);
+  int anIsUpdated = LoadPoints(theMesh);
+  const TEntity& aVEntity = theMeshOnEntity->myEntity;
+  if(aVEntity != NODE_ENTITY)
+    anIsUpdated |= LoadCellsOnEntity(theMesh,theMeshOnEntity);
+
+  return anIsUpdated;
 }
-  
-int VISU_MEDConvertor::LoadMeshOnGroup(VISU::TMesh& theMesh, 
-                                      const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet)
-     throw (std::runtime_error&)
+//---------------------------------------------------------------
+int
+VISU_MEDConvertor
+::LoadFamilyOnEntity(VISU::PMeshImpl theMesh,
+                    VISU::PMeshOnEntityImpl theMeshOnEntity, 
+                    VISU::PFamilyImpl theFamily)
+{
+  int anIsUpdated = LoadPoints(theMesh);
+  const TEntity& anEntity = theMeshOnEntity->myEntity;
+  if(anEntity == NODE_ENTITY){
+    anIsUpdated |= LoadPointsOnFamily(theMesh,theFamily);
+  }else{
+    anIsUpdated |= LoadCellsOnEntity(theMesh,theMeshOnEntity);
+    anIsUpdated |= LoadCellsOnFamily(theMesh,theMeshOnEntity,theFamily);
+  }
+
+  return anIsUpdated;
+}
+
+
+//---------------------------------------------------------------
+int 
+VISU_MEDConvertor
+::LoadMeshOnGroup(VISU::PMeshImpl theMesh, 
+                 const VISU::TFamilySet& theFamilySet)
 {
   //Main part of code
-  int isPointsUpdated = 0;
-  int isCellsOnEntityUpdated = 0;
-  VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = theFamilyAndEntitySet.begin();
-  for(; aFamilyAndEntitySetIter != theFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){
-    const string& aFamilyName = aFamilyAndEntitySetIter->first;
-    const VISU::TEntity& anEntity = aFamilyAndEntitySetIter->second;
-    VISU::TMeshOnEntity& aMeshOnEntity = theMesh.myMeshOnEntityMap[anEntity];
-    if(anEntity == VISU::NODE_ENTITY){
-      isPointsUpdated += LoadPoints(theMesh,aFamilyName);
-      isCellsOnEntityUpdated += LoadCellsOnEntity(aMeshOnEntity);
+  int anIsUpdated = LoadPoints(theMesh);
+  TFamilySet::const_iterator aFamilyIter = theFamilySet.begin();
+  for(; aFamilyIter != theFamilySet.end(); aFamilyIter++){
+    PCFamily aFamily = *aFamilyIter;
+    const VISU::TEntity& aVEntity = aFamily->myEntity;
+    PCMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[aVEntity];
+    if(aVEntity == VISU::NODE_ENTITY){
+      anIsUpdated |= LoadPointsOnFamily(theMesh,aFamily);
     }else{
-      isPointsUpdated += LoadPoints(theMesh);
-      isCellsOnEntityUpdated += LoadCellsOnEntity(aMeshOnEntity,aFamilyName);
+      anIsUpdated |= LoadCellsOnEntity(theMesh,aMeshOnEntity);
+      anIsUpdated |= LoadCellsOnFamily(theMesh,aMeshOnEntity,aFamily);
     }
   }
 
-  return (isPointsUpdated || isCellsOnEntityUpdated);
+  return anIsUpdated;
 }
 
-void VISU_CorbaMedSupportConvertor::SetSupport(SALOME_MED::SUPPORT_ptr theSupport) {
-  mySupport = SALOME_MED::SUPPORT::_duplicate(theSupport);
-  if(!mySupport->_is_nil())
-    myMedMesh = mySupport->getMesh();
+
+//---------------------------------------------------------------
+int 
+VISU_MEDConvertor
+::LoadValForTimeOnMesh(VISU::PMeshImpl theMesh, 
+                      VISU::PMeshOnEntityImpl theMeshOnEntity, 
+                      VISU::PFieldImpl theField, 
+                      VISU::PValForTimeImpl theValForTime)
+{
+  //Main part of code
+  int anIsUpdated = LoadPoints(theMesh);
+  const TEntity& aVEntity = theMeshOnEntity->myEntity;
+  if(aVEntity != NODE_ENTITY)
+    anIsUpdated |= LoadCellsOnEntity(theMesh,theMeshOnEntity);
+
+  anIsUpdated |= LoadField(theMesh,theMeshOnEntity,theField,theValForTime);
+  
+  return anIsUpdated;
 }
 
-int ImportPoints(VISU::TMesh& theMesh, SALOME_MED::MESH_ptr theMESH)
-  throw (std::runtime_error&) 
+
+//---------------------------------------------------------------
+int 
+VISU_MEDConvertor
+::LoadPoints(VISU::PCMesh theMesh)
 {
-/*
-  if(MYDEBUG) MESSAGE("ImportPoints - beginning");
-  theMesh.myDim = theMESH->getMeshDimension();
-  int aNbPoints = theMESH->getNumberOfNodes();
-  VISU::TMesh::TPointsCoord& aPointsCoord = theMesh.myPointsCoord;
-  aPointsCoord.resize(theMesh.myDim*aNbPoints,0.0);
-  Engines::double_array_var coord = theMESH->getCoordinates(SALOME_MED::MED_FULL_INTERLACE);
-  for (int i = 0 ; i < aNbPoints; i++)
-    for(int j = 0, ij = theMesh.myDim*i; j < theMesh.myDim; j++)
-      aPointsCoord[ij+j] = coord[ij+j];
-  if(MYDEBUG) 
-    MESSAGE("ImportPoints - End : theDim = "<<theMesh.myDim<<"; aNbPoints = "<<aNbPoints);
+  //Check on existing family
+  PCMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[VISU::NODE_ENTITY];
+  
+  //Check on loading already done
+  if(theMesh->myIsDone) 
+    return 0;
+  
+  SALOME_MED::MESH_var& aMedMesh = theMesh->myMesh;
+  int aDim = theMesh->myDim;
+  TNamedPointCoords& aCoords = theMesh->myNamedPointCoords;
+  int aNbElem = aCoords.GetNbPoints();
+
+  if(MYDEBUG) MESSAGE("LoadPoints - aNbElem = "<<aNbElem);
+
+  if(aNbElem <= 0) 
+    throw std::runtime_error("LoadPoints >> There is no points in the mesh !!!");
+
+  SALOME_MED::double_array_var aCCoord = aMedMesh->getCoordinates(SALOME_MED::MED_FULL_INTERLACE);
+  for(int iElem = 0, anId = 0; iElem < aNbElem; iElem++){
+    VISU::TCoordSlice aCoordSlice = aCoords.GetCoordSlice(iElem);
+    for(int iDim = 0; iDim < aDim; iDim++)
+      aCoordSlice[iDim] = aCCoord[anId++];
+  }
+  
+  if(MYDEBUG) MESSAGE("LoadPoints - Filling aMeshOnEntity with type NODE_ENTITY");
+  
+  TGeom2SubMesh& aGeom2SubMesh = aMeshOnEntity->myGeom2SubMesh;
+  PSubMeshImpl aSubMesh = aGeom2SubMesh[VISU::ePOINT1](new TCSubMesh());
+
+  aSubMesh->myNbCells = theMesh->myNbPoints;
+  aSubMesh->myCellsSize = 2*theMesh->myNbPoints;
+
+  TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
+  aCell2Connect.resize(aNbElem);
+  for(int iElem = 0; iElem < aNbElem; iElem++)
+    aCell2Connect[iElem] = TConnect(1,iElem);
+  
+  theMesh->myIsDone = true;
+
   return 1;
-*/
 }
 
-int ImportCells(VISU::TMesh& theMesh, SALOME_MED::MESH_ptr theMESH, 
-               const SALOME_MED::medEntityMesh& theEntity)
-     throw (std::runtime_error&) 
+
+//---------------------------------------------------------------
+int 
+VISU_MEDConvertor
+::LoadPointsOnFamily(VISU::PCMesh theMesh, 
+                    VISU::PCFamily theFamily)
 {
-/*
-  if(MYDEBUG) MESSAGE("ImportCells - theEntity = "<<theEntity);
-  //TEntity2Geom anEntity2Geom = anEntity2GeomMap[theEntity];
-  //int *iVector = anEntity2Geom->first, iEnd = anEntity2Geom->second;
-  int *iArray, iEnd;
-  VISU::TEntity anEntity = MED2VISUEntity(theEntity);
-  Entity2Geom(anEntity,iArray,&iEnd);
-  int aNbPoints = theMesh.myPointsCoord.size();
-  for (int i = 0; i < iEnd; i++) {
-    int medId = FindIdMEDType(iArray[i]);
-    int nbMedNodes = salome_med2vtk[medId].medNbNodes;
-    int nbVtkNodes = salome_med2vtk[medId].vtkNbNodes;
-    int aVtkType = salome_med2vtk[medId].vtkType;
-    SALOME_MED::medGeometryElement aMedType = salome_med2vtk[medId].medType;
-    int jEnd = theMESH->getNumberOfElements(theEntity,aMedType);
-    if(jEnd > 0){
-      VISU::TMeshOnEntity& aMeshOnEntity = theMesh.myMeshOnEntityMap[anEntity];
-      Engines::long_array_var conn = 
-       theMESH->getConnectivity(SALOME_MED::MED_FULL_INTERLACE,SALOME_MED::MED_NODAL,theEntity,aMedType);
-      if(MYDEBUG) MESSAGE("ImportCells - medName = "<<salome_med2vtk[medId].medName<<"; jEnd = "<<jEnd);
-      VISU::TMeshOnEntity::TConnForCellType& aConnForCellType = aMeshOnEntity.myCellsConn[aVtkType];
-      aConnForCellType.resize(jEnd);
-      valarray<med_int> aConnect(nbMedNodes);
-      for (int j = 0; j < jEnd; j++) {
-       VISU::TMeshOnEntity::TConnect& anArray = aConnForCellType[j];
-       anArray.resize(nbVtkNodes);
-       for (int k = 0, kj = j*nbMedNodes; k < nbMedNodes; k++) 
+  PCMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[VISU::NODE_ENTITY];
+
+  if(theFamily->myIsDone) 
+    return 0;
+
+  TNamedPointCoords& aCoords = theMesh->myNamedPointCoords;
+  int aNbElem = aCoords.GetNbPoints();
+
+  SALOME_MED::FAMILY_var aMedFamily = theFamily->myFamily;
+  CORBA::Boolean anIsOnAllElements = aMedFamily->isOnAllElements();
+  TSubMeshID& aSubMeshID = theFamily->myGeom2SubMeshID[VISU::ePOINT1];
+  
+  if(!anIsOnAllElements){
+    SALOME_MED::medGeometryElement_array_var aGeom = aMedFamily->getTypes();
+    SALOME_MED::long_array_var aCellNumForType = aMedFamily->getNumber(aGeom[0]);
+    int aSize = aNbElem;
+    aNbElem = aCellNumForType->length();
+    for(int iElem = 0; iElem < aNbElem; iElem++){
+      int anID = aCellNumForType[iElem] - 1;
+      if(0 > anID || anID >= aSize){
+       static QString aString;
+       aString.sprintf("LoadPointsOnFamily - aSize(%d) <= aCellNumForType[%d] = %d < 0",aSize,iElem,anID);
+       throw std::runtime_error(aString.latin1());
+      }
+      aSubMeshID.push_back(anID);
+    }
+  }else{
+    for(int iElem = 0; iElem < aNbElem; iElem++){
+      aSubMeshID.push_back(iElem);
+    }
+  }
+  
+  theFamily->myIsDone = true;
+
+  return 1;
+}
+
+
+//---------------------------------------------------------------
+int 
+VISU_MEDConvertor
+::LoadCellsOnEntity(VISU::PCMesh theMesh,
+                   VISU::PCMeshOnEntity theMeshOnEntity)
+{
+  if(theMeshOnEntity->myIsDone) 
+    return 0;
+
+  SALOME_MED::SUPPORT_var& aMedSupport = theMeshOnEntity->mySupport;
+  SALOME_MED::MESH_var aMedMesh = aMedSupport->getMesh();
+
+  //Main part of code
+  SALOME_MED::medGeometryElement* aGeomElems;
+  const TEntity& aVEntity = theMeshOnEntity->myEntity;
+  int iGeomEnd = GetEntity2Geom(aVEntity,aGeomElems);
+  const SALOME_MED::medEntityMesh& aMEntity = VTKEntityToMED(aVEntity);
+  const TNamedPointCoords& aCoords = theMesh->myNamedPointCoords;
+  TGeom2SubMesh& aGeom2SubMesh = theMeshOnEntity->myGeom2SubMesh;
+  int aNbPoints = aCoords.GetNbPoints();
+
+  for(int iGeom = 0, aCounter = 0; iGeom < iGeomEnd; iGeom++){
+    SALOME_MED::medGeometryElement aMGeom = aGeomElems[iGeom];
+    int aMNbNodes = MEDGeom2NbNodes(aMGeom);
+    VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
+    int aVNbNodes = VISUGeom2NbNodes(aEGeom);
+    int aNbElem = aMedMesh->getNumberOfElements(aMEntity,aMGeom);
+    if (aNbElem > 0) {
+      using namespace SALOME_MED;
+      SALOME_MED::long_array_var conn = 
+       aMedMesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,aMEntity,aMGeom);
+      PSubMeshImpl aSubMesh = aGeom2SubMesh[aEGeom](new TCSubMesh());
+
+      aSubMesh->myNbCells = aNbElem;      
+      aSubMesh->myCellsSize = aNbElem*(aVNbNodes+1);
+
+      TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
+      std::vector<int> aConnect(aMNbNodes);
+      int aNbConnForElem = conn->length()/aNbElem;
+
+      if(MYDEBUG) MESSAGE("LoadCellsOnEntity - aMGeom = "<<aMGeom<<
+                         "; aNbElem = "<<aNbElem<<
+                         "; aMNbNodes = "<<aMNbNodes<<
+                         "; aVNbNodes = "<<aVNbNodes<<
+                         "; aNbConnForElem = "<<aNbConnForElem);
+
+      for(int iElem = 0; iElem < aNbElem; iElem++){
+       VISU::TConnect anArray(aVNbNodes);
+       for(int k = 0, kj = iElem*aNbConnForElem; k < aMNbNodes; k++)
          aConnect[k] = conn[kj+k] - 1;
-       switch(aMedType){
-       case SALOME_MED::MED_TETRA4 :
+
+       switch(aMGeom){
+#if !(defined(VTK_QUADRATIC_EDGE) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
+       case SALOME_MED::MED_SEG3:
+         anArray[0] = aConnect[0];
+         anArray[2] = aConnect[1];  
+         
+         anArray[1] = aConnect[2];
+         break;
+#endif
+#if !(defined(VTK_QUADRATIC_TRIANGLE) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
+       case SALOME_MED::MED_TRIA6:
+         anArray[0] = aConnect[0];
+         anArray[2] = aConnect[1];  
+         anArray[4] = aConnect[2];  
+         
+         anArray[1] = aConnect[3];
+         anArray[3] = aConnect[4];  
+         anArray[5] = aConnect[5];  
+         break;
+#endif
+#if !(defined(VTK_QUADRATIC_QUAD) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
+       case SALOME_MED::MED_QUAD8:
+         anArray[0] = aConnect[0];
+         anArray[2] = aConnect[1];  
+         anArray[4] = aConnect[2];  
+         anArray[6] = aConnect[3];  
+         
+         anArray[1] = aConnect[4];
+         anArray[3] = aConnect[5];  
+         anArray[5] = aConnect[6];  
+         anArray[7] = aConnect[7];  
+         break;
+#endif
+#if (defined(VTK_QUADRATIC_TETRA) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
        case SALOME_MED::MED_TETRA10 :
+#endif
+       case SALOME_MED::MED_TETRA4 :
          anArray[0] = aConnect[0];
          anArray[1] = aConnect[1];
          anArray[2] = aConnect[3];  
          anArray[3] = aConnect[2];  
          break;
+#if (defined(VTK_QUADRATIC_PYRAMID) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
+       case SALOME_MED::MED_PYRA13:
+#endif
        case SALOME_MED::MED_PYRA5 :
-       case SALOME_MED::MED_PYRA13 :
          anArray[0] = aConnect[0];
          anArray[1] = aConnect[3];  
          anArray[2] = aConnect[2];
@@ -579,216 +1171,188 @@ int ImportCells(VISU::TMesh& theMesh, SALOME_MED::MESH_ptr theMESH,
          anArray[4] = aConnect[4];
          break;
        default:
-         for (int k = 0; k < nbVtkNodes; k++) 
+         for (int k = 0; k < aVNbNodes; k++) 
            anArray[k] = aConnect[k];
        }
-       for (int k = 0; k < nbVtkNodes; k++) 
-         if(anArray[k] < 0 || aNbPoints <= anArray[k])
-           throw std::runtime_error("ImportCells >> anArray[k] < 0 || aNbPoints <= anArray[k]");
+       for (int k = 0; k < aVNbNodes; k++) 
+         if(anArray[k] < 0 || aNbPoints <= anArray[k]){
+           static QString aString;
+           aString.sprintf("LoadCellsOnEntity >> aNbPoints(%d) <= anArray[%d][%d]=%d < 0 !!!",aNbPoints,iElem,k,anArray[k]);
+           throw std::runtime_error(aString.latin1());
+         }
+       aCell2Connect.push_back(anArray);
       }
-      if(MYDEBUG)
-       MESSAGE("ImportCells - aMeshOnEntity.myCellsConn.size() = "<<aMeshOnEntity.myCellsConn.size());
+      //Workaround for MED Component data structure
+      int aSize = aCell2Connect.size();
+      if(MYDEBUG) MESSAGE("LoadCellsOnEntity - aCounter = "<<aCounter<<"; aSize = "<<aSize);
+      theMeshOnEntity->myCellsFirstIndex[aMGeom] = TCMeshOnEntity::TIndexAndSize(aCounter,aSize);
+      aCounter += aSize;
     }
   }
-*/
-}
 
-VISU_Convertor* VISU_MedMeshConvertor::Build() throw (std::runtime_error&) {
-/*
-  if(myMedMesh->_is_nil())
-    throw std::runtime_error("VISU_MedMeshConvertor::Build >> myMesh->_is_nil()");
-  CORBA::String_var aName = myMedMesh->getName();
-  myName = aName;
-  TMesh& aMesh = myMeshMap[myName];
-  if(MYDEBUG) MESSAGE("MedInfo - aMeshName = "<<myMeshMap.begin()->first);
-  ::ImportPoints(aMesh,myMedMesh);
-  TVisu2MedEntity::const_iterator aVisu2MedEntityIter = aVisu2MedEntity.begin();
-  for(; aVisu2MedEntityIter != aVisu2MedEntity.end(); aVisu2MedEntityIter++)
-    ::ImportCells(aMesh,myMedMesh,aVisu2MedEntityIter->second);
-  myIsDone = true;
-  return this; 
-*/
+  theMeshOnEntity->myIsDone = true;
+
+  return 1;
 }
 
-template<class TArray> int ImportField(TArray& theArray, 
-                                      const VISU::TMeshOnEntity& theMeshOnEntity,
-                                      VISU::TField& theField, 
-                                      const SALOME_MED::medEntityMesh& theEntity,
-                                      const VISU::TField::TTime& theTime)
+
+//---------------------------------------------------------------
+int 
+VISU_MEDConvertor
+::LoadCellsOnFamily(VISU::PCMesh theMesh,
+                   VISU::PCMeshOnEntity theMeshOnEntity, 
+                   VISU::PCFamily theFamily)
 {
-/*
-  if(MYDEBUG) MESSAGE("ImportField - IEnd = "<<theArray->length()<<"; myNbComp = "<<theField.myNbComp);
-  VISU::TEntity anEntity = MED2VISUEntity(theEntity);
-  VISU::TMeshOnEntity& aMeshOnEntity = theMesh.myMeshOnEntityMap[anEntity];
-  VISU::TField& aField = aMeshOnEntity.myFieldMap[nomcha]
-  VISU::TField::TValForTime& aValForTime = theField.myValField[theTime];
-  if(theField.myTypeConn == POINT_DATA){
-    VISU::TField::TValForCellsWithType& aValForCellsWithType = aValForTime[VTK_VERTEX];
-    int iEnd = theMesh.myPointsCoord.size()/theMesh.myDim * theField.myNbComp;
-    if(MYDEBUG) MESSAGE("ImportField - iEnd = "<<iEnd);
-    aValForCellsWithType.resize(iEnd);
-    for (int i = 0; i < iEnd; i++)
-      aValForCellsWithType[i] = theArray[i];
-  }else{
-    int iEnd = VTKCELLGEOMEND, *iArray = VTKCELLGEOM, kEnd = theField.myNbComp;
-    for (int i = 0, I = 0; i < iEnd; i++) {
-      int medId = FindIdMEDType(iArray[i]), aVtkType = salome_med2vtk[medId].vtkType;
-      const VISU::TMeshOnEntity::TCellsConn& aCellsConn = theMesh.myCellsConn;
-      VISU::TMeshOnEntity::TCellsConn::const_iterator aCellsConnIter = aCellsConn.find(aVtkType);
-      if(aCellsConnIter != aCellsConn.end()){
-       const VISU::TMesh::TConnForCellType& aConnForCellType = aCellsConnIter->second;
-       int jEnd = aConnForCellType.size();
-       if(MYDEBUG) MESSAGE("ImportField - medName = "<<salome_med2vtk[medId].medName<<
-                           "; vtkName = "<<salome_med2vtk[medId].vtkName<<"; jEnd = "<<jEnd);
-       VISU::TField::TValForCellsWithType& aValForCellsWithType = aValForTime[aVtkType];
-       aValForCellsWithType.resize(jEnd*kEnd);
-       for (int j = 0; j < jEnd; j++)
-         for (int k = 0, kj = j*kEnd; k < kEnd; k++)
-           aValForCellsWithType[kj+k] = theArray[I++];
+  if(theFamily->myIsDone) 
+    return 0;
+
+  SALOME_MED::FAMILY_var aMedFamily = theFamily->myFamily;
+  CORBA::Boolean anIsOnAllElements = aMedFamily->isOnAllElements();
+  if(!anIsOnAllElements){
+    SALOME_MED::medGeometryElement_array_var aGeoms = aMedFamily->getTypes();
+    int iGeomEnd = aGeoms->length();
+    if(MYDEBUG) MESSAGE("LoadCellsOnFamily - iGeomEnd = "<<iGeomEnd);
+    for(int iGeom = 0; iGeom < iGeomEnd; iGeom++){
+      SALOME_MED::medGeometryElement aMGeom = aGeoms[iGeom];
+      SALOME_MED::long_array_var aCellNumForType = aMedFamily->getNumber(aMGeom);
+      VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
+
+      int aNbElem = aCellNumForType->length();
+      int aCounter = theMeshOnEntity->myCellsFirstIndex[aMGeom].first;
+      int aSize = theMeshOnEntity->myCellsFirstIndex[aMGeom].second;
+      TSubMeshID& aSubMeshID = theFamily->myGeom2SubMeshID[aEGeom]; 
+      
+      if(MYDEBUG) 
+       MESSAGE("LoadCellsOnFamily "<<
+               "- aMGeom = "<<aMGeom<<
+               "; aNbElem = "<<aNbElem<<
+               "; aSize = "<<aSize<<
+               "; aCounter = "<<aCounter);
+      
+      for(int iElem = 0; iElem < aNbElem; iElem++){
+       int anID = aCellNumForType[iElem] - aCounter - 1;
+       if(0 > anID || anID >= aSize){
+         static QString aString;
+         aString.sprintf("LoadCellsOnFamily - aNbElem(%d) <= aCellNumForType[%d] = %d < 0 !!!",aNbElem,iElem,anID);
+         throw std::runtime_error(aString.latin1());
+       }
+       aSubMeshID.push_back(anID);
       }
     }
+  }else{
+    const VISU::TGeom2SubMesh& aGeom2SubMesh = theMeshOnEntity->myGeom2SubMesh;
+    VISU::TGeom2SubMesh::const_iterator anIter = aGeom2SubMesh.begin();
+    for(; anIter != aGeom2SubMesh.end(); anIter++){
+      VISU::EGeometry aEGeom = anIter->first;
+      const VISU::TSubMeshImpl& aSubMesh = anIter->second;
+      const VISU::TCell2Connect& aCell2Connect = aSubMesh.myCell2Connect;
+      TSubMeshID& aSubMeshID = theFamily->myGeom2SubMeshID[aEGeom];
+      int iNumElemEnd = aCell2Connect.size();
+      for(int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
+       aSubMeshID.push_back(iNumElem);
+    }
   }
-*/
-}
+  
+  theFamily->myIsDone = true;
 
-VISU_Convertor* VISU_CorbaMedConvertor::Build() throw (std::runtime_error&){
-/*
-  if(myMedField->_is_nil())
-    throw std::runtime_error("VISU_CorbaMedConvertor::Build >> myField->_is_nil()");
-  if(VISU_MedMeshConvertor::Build() == NULL) return NULL;
-  CORBA::String_var aName = myMedField->getName();
-  myName = aName;
-  TMeshMap::const_iterator aMeshIter = myMeshMap.begin();
-  const TMesh& aMesh = aMeshIter->second;
-  int aNbPoints = aMesh.myPointsCoord.size()/aMesh.myDim;
-  int aNbCells = aMesh.GetCellsDims().first;
-  aName = myMedField->getName();
-  aMeshOnEntity.myEntity = theEntity;
-  aMeshOnEntity.myMeshName = theMesh.myName;
-  TField& aField = myFieldMap[aName.in()];
-  aField.myMeshName = aMeshIter->first;
-  SALOME_MED::SUPPORT_var aSupport = myMedField->getSupport();
-  SALOME_MED::medEntityMesh anEntity = aSupport->getEntity();
-  int aSize;
-  if(anEntity == SALOME_MED::MED_NODE){
-    aSize = aNbPoints;
-    aField.myTypeConn = POINT_DATA;
-    if(MYDEBUG) MESSAGE("VISU_CorbaMedConvertor::Build - POINT_DATA = "<<aSize);
-  }else if(anEntity == SALOME_MED::MED_CELL){
-    aSize = aNbCells;
-    aField.myTypeConn = CELL_DATA;
-    if(MYDEBUG) MESSAGE("VISU_CorbaMedConvertor::Build - CELL_DATA = "<<aSize);
-  }
-  aField.myNbComp = myMedField->getNumberOfComponents();
-  if(MYDEBUG) MESSAGE("VISU_CorbaMedConvertor::Build - aField.myNbComp = "<<aField.myNbComp);
-  TField::TTime aTime(myMedField->getTime(),"");
-  SALOME_MED::FIELDDOUBLE_ptr aFieldDouble = SALOME_MED::FIELDDOUBLE::_narrow(myMedField);
-  if(!aFieldDouble->_is_nil()){
-    if(MYDEBUG) MESSAGE("VISU_CorbaMedConvertor::Build - There is FIELDDOUBLE");
-    Engines::double_array_var anArray = aFieldDouble->getValue(SALOME_MED::MED_FULL_INTERLACE);
-    ::ImportField(anArray,aMesh,aField,anEntity,aTime);
-  }
-  SALOME_MED::FIELDINT_ptr aFieldInt = SALOME_MED::FIELDINT::_narrow(myMedField);
-  if(!aFieldInt->_is_nil()){
-    if(MYDEBUG) MESSAGE("VISU_CorbaMedConvertor::Build - There is FIELDINT");
-    Engines::long_array_var anArray = aFieldInt->getValue(SALOME_MED::MED_FULL_INTERLACE);
-    ::ImportField(anArray,aMesh,aField,anEntity,aTime);
-  }
-  myIsDone = true;
-  return this; 
-*/
+  return 1;
 }
 
-int ImportCellsOfSupport(VISU::TMesh& theMesh, SALOME_MED::SUPPORT_ptr theSUPPORT) 
-     throw (std::runtime_error&) 
+
+template<class TArray> 
+int 
+ImportField(TArray& theArray, 
+           VISU::PCMesh theMesh,
+           VISU::PCField theField,
+           VISU::PCValForTime theValForTime,
+           VISU::PCMeshOnEntity theMeshOnEntity)
 {
-/*
-  if(MYDEBUG) MESSAGE("ImportCellsOfSupport - beginning");
-  SALOME_MED::medEntityMesh anEntity = theSUPPORT->getEntity();
-  med_int nmailles[SALOME_MED::MED_ALL_ELEMENTS];
-  if(MYDEBUG) MESSAGE("ImportCellsOfSupport - anEntity = "<<anEntity);
-  if(anEntity == SALOME_MED::MED_NODE){
-    VISU::TMesh::TConnForCellType& aConnForCellType = theMesh.myCellsConn[VTK_VERTEX];
-    if(theSUPPORT->isOnAllElements()){
-      int jEnd = theMesh.myPointsCoord.size()/theMesh.myDim;
-      if(MYDEBUG) MESSAGE("ImportCellsOfSupport - isOnAllElements - "<<jEnd);
-      aConnForCellType.resize(jEnd);
-      for (int j = 0; j < jEnd; j++) 
-       aConnForCellType[j] = vector<int>(1,j);
-    }else{
-      SALOME_MED::medGeometryElement_array_var aGeom = theSUPPORT->getTypes();
-      Engines::long_array_var aCellNumForType = theSUPPORT->getNumber(aGeom[0]);
-      int jEnd = aCellNumForType->length();
-      aConnForCellType.resize(jEnd);
-      for (int j = 0; j < jEnd; j++) 
-       aConnForCellType[j] = vector<int>(1,aCellNumForType[j]-1);
+  int aNbComp = theField->myNbComp;
+  if(theField->myEntity == NODE_ENTITY){
+    VISU::EGeometry aEGeom = VISU::ePOINT1;
+    int aNbGauss = theValForTime->GetNbGauss(aEGeom);
+    const TNamedPointCoords& aCoords = theMesh->myNamedPointCoords;
+    int aNbElem = aCoords.GetNbPoints();
+
+    if(MYDEBUG) MESSAGE("ImportField - aNbElem = "<<aNbElem);
+
+    TMeshValue& aMeshValue = theValForTime->GetMeshValue(VISU::ePOINT1);
+    aMeshValue.Init(aNbElem,aNbGauss,aNbComp);
+    for(int iElem = 0, anId = 0; iElem < aNbElem; iElem++){
+      TValueSliceArr aValueSliceArr = aMeshValue.GetGaussValueSliceArr(iElem);
+      for(int iGauss = 0; iGauss < aNbGauss; iGauss++){
+       TValueSlice& aValueSlice = aValueSliceArr[iGauss];
+       for(int iComp = 0; iComp < aNbComp; iComp++){
+         aValueSlice[iComp] = theArray[anId++];
+       }
+      }
     }
   }else{
-    VISU::TMesh aBaseMesh;
-    SALOME_MED::MESH_var aMedMesh = theSUPPORT->getMesh();
-    ::ImportPoints(aBaseMesh,aMedMesh);
-    ::ImportCells(aBaseMesh,aMedMesh,anEntity);
-    if(theSUPPORT->isOnAllElements()){
-      if(MYDEBUG) MESSAGE("ImportCellsOfSupport - isOnAllElements");
-    }else{
-      SALOME_MED::medGeometryElement_array_var aGeom = theSUPPORT->getTypes();
-      int iEnd = aGeom->length();
-      if(MYDEBUG) MESSAGE("ImportCellsOfSupport - aGeom->length() = "<<iEnd);
-      for (int i = 0; i < iEnd; i++) {
-       Engines::long_array_var aCellNumForType = theSUPPORT->getNumber(aGeom[i]);
-       int medId = FindIdMEDType(aGeom[i]);
-       int aVtkType = salome_med2vtk[medId].vtkType;
-       med_int jEnd = aCellNumForType->length();
-       if(MYDEBUG) MESSAGE("ImportCellsOfSupport - medName = "<<salome_med2vtk[medId].medName<<"; jEnd = "<<jEnd);
-       VISU::TMesh::TConnForCellType& aConnForCellType = theMesh.myCellsConn[aVtkType];
-       aConnForCellType.resize(jEnd);
-       VISU::TMesh::TConnForCellType& aBaseConnForCellType = aBaseMesh.myCellsConn[aVtkType];
-       for (int j = 0; j < jEnd; j++) {
-         aConnForCellType[j] = aBaseConnForCellType[aCellNumForType[j]-1];
+    SALOME_MED::medGeometryElement* aGeomElems;
+    const TEntity& aVEntity = theField->myEntity;
+    int iGeomEnd = GetEntity2Geom(aVEntity,aGeomElems);
+    for(int iGeom = 0; iGeom < iGeomEnd; iGeom++){
+      SALOME_MED::medGeometryElement aMGeom = aGeomElems[iGeom];
+      VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
+      int aNbGauss = theValForTime->GetNbGauss(aEGeom);
+      const TCMeshOnEntity::TCellsFirstIndex& aCellsFirstIndex = theMeshOnEntity->myCellsFirstIndex;
+      TCMeshOnEntity::TCellsFirstIndex::const_iterator aCellsFirstIndexIter = aCellsFirstIndex.find(aMGeom);
+      if(aCellsFirstIndexIter != aCellsFirstIndex.end()){
+       const TCMeshOnEntity::TIndexAndSize& aIndexAndSize = aCellsFirstIndexIter->second;
+       if(MYDEBUG) 
+         MESSAGE("ImportField - aMGeom = "<<aMGeom<<
+                 "; aIndexAndSize = {"<<aIndexAndSize.first<<
+                 ","<<aIndexAndSize.second<<"}");
+
+       int aNbElem = aIndexAndSize.second;
+       int aStart = aIndexAndSize.first*aNbComp;
+       TMeshValue& aMeshValue = theValForTime->GetMeshValue(aEGeom);
+       aMeshValue.Init(aNbElem,aNbGauss,aNbComp);
+       for(int iElem = 0, anId = 0; iElem < aNbElem; iElem++, anId += aNbComp){
+         TValueSliceArr aValueSliceArr = aMeshValue.GetGaussValueSliceArr(iElem);
+         for(int iGauss = 0; iGauss < aNbGauss; iGauss++){
+           TValueSlice& aValueSlice = aValueSliceArr[iGauss];
+           for(int iComp = 0; iComp < aNbComp; iComp++)
+             aValueSlice[iComp] = theArray[aStart+anId+iComp];
+         }
        }
       }
     }
   }
   return 1;
-*/
 }
 
-VISU_Convertor* VISU_CorbaMedSupportConvertor::Build() throw (std::runtime_error&) {
-/*
-  if(MYDEBUG) MESSAGE("BuildSupport - checking mySupport & mySupport->getMesh()");
-  if(mySupport->_is_nil())
-    throw std::runtime_error("VISU_CorbaMedConvertor::Build >> mySupport->_is_nil()");
-  SALOME_MED::GROUP_var aGroup = SALOME_MED::GROUP::_narrow(mySupport);
-  int aNbCells = 0;
-  if(!aGroup->_is_nil()){
-    CORBA::String_var aName = aGroup->getName();
-    myName = aName;
-    if(MYDEBUG) MESSAGE("BuildSupport aGroup->getName() = "<<myName);
-    SALOME_MED::Family_array_var anArray = aGroup->getFamilies();
-    med_int iEnd = anArray->length();
-    TMesh& aMesh = myMeshMap[myName];
-    if(MYDEBUG) MESSAGE("BuildSupport - aGroup->getFamilies()->length() = "<<iEnd);
-    ::ImportPoints(aMesh,myMedMesh);
-    for(med_int i = 0; i < iEnd; i++){
-      if(MYDEBUG) MESSAGE("BuildSupport - import FAMILY with number = "<<i);
-      SALOME_MED::FAMILY_var aFamily = anArray[i];
-      ::ImportCellsOfSupport(aMesh,aFamily);
-    }
-    aNbCells = aMesh.GetCellsDims().first;
-  }else{
-    CORBA::String_var aName = mySupport->getName();
-    myName = aName;
-    if(MYDEBUG) MESSAGE("mySupport - myName = "<<myName);
-    TMesh& aMesh = myMeshMap[myName];
-    myMedMesh = mySupport->getMesh();
-    ::ImportPoints(aMesh,myMedMesh);
-    ::ImportCellsOfSupport(aMesh,mySupport);
-    aNbCells = aMesh.GetCellsDims().first;
+int
+VISU_MEDConvertor
+::LoadField(VISU::PCMesh theMesh,
+           VISU::PCMeshOnEntity theMeshOnEntity,
+           VISU::PField theField, 
+           VISU::PCValForTime theValForTime)
+{
+  //Check on loading already done
+  PIDMapperFilter anIDMapperFilter = theValForTime->myIDMapperFilter;
+  if(anIDMapperFilter->myIsVTKDone) 
+    return 0;
+  
+  PCProfile aProfile(new TCProfile());
+  aProfile->myIsAll = true;
+  theValForTime->myProfile = aProfile;
+
+  SALOME_MED::FIELD_var aMEDField = theValForTime->myField;
+  SALOME_MED::FIELDDOUBLE_ptr aFieldDouble = SALOME_MED::FIELDDOUBLE::_narrow(aMEDField);
+  if(!aFieldDouble->_is_nil()){
+    SALOME_MED::double_array_var anArray = aFieldDouble->getValue(SALOME_MED::MED_FULL_INTERLACE);
+    if(MYDEBUG) MESSAGE("VISU_MEDConvertor::LoadField - There is FIELDDOUBLE = "<<anArray->length());
+    ::ImportField(anArray,theMesh,theField,theValForTime,theMeshOnEntity);
   }
-  if(aNbCells == 0) 
-    throw std::runtime_error("VISU_MedMeshConvertor::Build >> aNbCells == 0");
-  if(MYDEBUG) MESSAGE("BuildSupport - aNbCells = "<<aNbCells);
-  myIsDone = true;
-  return this; 
-*/
+  SALOME_MED::FIELDINT_ptr aFieldInt = SALOME_MED::FIELDINT::_narrow(aMEDField);
+  if(!aFieldInt->_is_nil()){
+    SALOME_MED::long_array_var anArray = aFieldInt->getValue(SALOME_MED::MED_FULL_INTERLACE);
+    if(MYDEBUG) MESSAGE("VISU_MEDConvertor::LoadField - There is FIELDINT = "<<anArray->length());
+    ::ImportField(anArray,theMesh,theField,theValForTime,theMeshOnEntity);
+  }
+
+  anIDMapperFilter->myIsVTKDone = true;
+
+  return 1;
 }