Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/visu.git] / src / VISU_I / VISU_CorbaMedConvertor.cxx
index b1dc814ba896de75545557e01071e18aaacccbbc..aea4b36ce887d7d6606dbe4c9d7f89e36c10d3fa 100644 (file)
@@ -17,7 +17,7 @@
 //  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 
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 //
 //
 //  Copyright (C) 2003  CEA/DEN, EDF R&D
 
 #include "VISU_CorbaMedConvertor.hxx"
+#include "VISU_ConvertorUtils.hxx"
 
 #include <vtkCellType.h>
 
 #include <boost/tuple/tuple.hpp>
 
-using namespace std;
-using namespace VISU;
+#include "ReceiverFactory.hxx"
+#include "MED_SliceArray.hxx"
 
 #define USER_INTERLACE MED_FULL_INTERLACE
 
@@ -60,64 +61,74 @@ extern "C" {
 
 namespace
 {
-  using namespace SALOME_MED;
+  const int MED_NBR_GEOMETRIE_MAILLE = 17;
   
-  const int MED_NBR_GEOMETRIE_MAILLE = 15;
-  
-  medGeometryElement 
+  SALOME_MED::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
+    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_HEXA8,
+    SALOME_MED::MED_TETRA10,
+    SALOME_MED::MED_PYRA13,
+    SALOME_MED::MED_PENTA15,
+    SALOME_MED::MED_HEXA20,
+    SALOME_MED::MED_POLYGON,
+    SALOME_MED::MED_POLYHEDRA
   };
   
-  const int MED_NBR_GEOMETRIE_FACE = 4;
+  const int MED_NBR_GEOMETRIE_FACE = 5;
   
-  medGeometryElement
+  SALOME_MED::medGeometryElement
   FACEGEOM[MED_NBR_GEOMETRIE_FACE] = {
-    MED_TRIA3,
-    MED_QUAD4,
-    MED_TRIA6,
-    MED_QUAD8
+    SALOME_MED::MED_TRIA3,
+    SALOME_MED::MED_QUAD4,
+    SALOME_MED::MED_TRIA6,
+    SALOME_MED::MED_QUAD8,
+    SALOME_MED::MED_POLYGON
   };
   
   const int MED_NBR_GEOMETRIE_ARETE = 2;
   
-  medGeometryElement
+  SALOME_MED::medGeometryElement
   EDGEGEOM[MED_NBR_GEOMETRIE_ARETE] = {
-    MED_SEG2,
-    MED_SEG3
+    SALOME_MED::MED_SEG2,
+    SALOME_MED::MED_SEG3
   };
   
   const int MED_NBR_GEOMETRIE_NODE = 1;
   
-  medGeometryElement
+  SALOME_MED::medGeometryElement
   NODEGEOM[MED_NBR_GEOMETRIE_NODE] = {
-    MED_POINT1,
+    SALOME_MED::MED_POINT1,
   };
   
 
   //---------------------------------------------------------------
   int
-  GetEntity2Geom(const VISU::TEntity& theEntity, medGeometryElement*& theVector)
+  GetEntity2Geom(const VISU::TEntity& theEntity, 
+                SALOME_MED::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;
+    case VISU::CELL_ENTITY: 
+      theVector = CELLGEOM; 
+      return MED_NBR_GEOMETRIE_MAILLE; 
+    case VISU::FACE_ENTITY: 
+      theVector = FACEGEOM; 
+      return MED_NBR_GEOMETRIE_FACE; 
+    case VISU::EDGE_ENTITY: 
+      theVector = EDGEGEOM; 
+      return MED_NBR_GEOMETRIE_ARETE; 
+    case VISU::NODE_ENTITY: 
+      theVector = NODEGEOM; 
+      return MED_NBR_GEOMETRIE_NODE; 
     }
     return -1;
   }
@@ -128,22 +139,38 @@ namespace
   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;
+    case SALOME_MED::MED_NONE: 
+      return 0;
+    case SALOME_MED::MED_POINT1: 
+      return 1;
+    case SALOME_MED::MED_SEG2: 
+      return 2;
+    case SALOME_MED::MED_SEG3: 
+      return 3;
+    case SALOME_MED::MED_TRIA3: 
+      return 3;
+    case SALOME_MED::MED_TRIA6: 
+      return 6;
+    case SALOME_MED::MED_QUAD4: 
+      return 4;
+    case SALOME_MED::MED_QUAD8: 
+      return 8;
+    case SALOME_MED::MED_TETRA4: 
+      return 4;
+    case SALOME_MED::MED_TETRA10: 
+      return 10;
+    case SALOME_MED::MED_HEXA8: 
+      return 8;
+    case SALOME_MED::MED_HEXA20: 
+      return 20;
+    case SALOME_MED::MED_PENTA6: 
+      return 6;
+    case SALOME_MED::MED_PENTA15: 
+      return 15;
+    case SALOME_MED::MED_PYRA5: 
+      return 5;
+    case SALOME_MED::MED_PYRA13: 
+      return 13;
     }
     return -1;
   }
@@ -151,70 +178,150 @@ namespace
 
   //---------------------------------------------------------------
   VISU::EGeometry
-  MEDGeom2VISU(medGeometryElement theGeom)
+  MEDGeom2VISU(SALOME_MED::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;
+    case SALOME_MED::MED_POINT1:
+      return VISU::ePOINT1;
+    case SALOME_MED::MED_SEG2: 
+      return VISU::eSEG2;
+    case SALOME_MED::MED_SEG3: 
+      return VISU::eSEG3;
+    case SALOME_MED::MED_TRIA3: 
+      return VISU::eTRIA3;
+    case SALOME_MED::MED_TRIA6: 
+      return VISU::eTRIA6;
+    case SALOME_MED::MED_QUAD4: 
+      return VISU::eQUAD4;
+    case SALOME_MED::MED_QUAD8: 
+      return VISU::eQUAD8;
+    case SALOME_MED::MED_TETRA4: 
+      return VISU::eTETRA4;
+    case SALOME_MED::MED_TETRA10: 
+      return VISU::eTETRA10;
+    case SALOME_MED::MED_HEXA8: 
+      return VISU::eHEXA8;
+    case SALOME_MED::MED_HEXA20: 
+      return VISU::eHEXA20;
+    case SALOME_MED::MED_PENTA6: 
+      return VISU::ePENTA6;
+    case SALOME_MED::MED_PENTA15: 
+      return VISU::ePENTA15;
+    case SALOME_MED::MED_PYRA5: 
+      return VISU::ePYRA5;
+    case SALOME_MED::MED_PYRA13: 
+      return VISU::ePYRA13;
+    case SALOME_MED::MED_POLYGON: 
+      return VISU::ePOLYGONE;
+    case SALOME_MED::MED_POLYHEDRA: 
+      return VISU::ePOLYEDRE;
     }
     return VISU::eNONE;
   }
   
+  //---------------------------------------------------------------
+  SALOME_MED::medGeometryElement 
+  VISUGeomToMED(int theGeom)
+  { 
+    switch(theGeom){
+    case VISU::ePOINT1: 
+      return SALOME_MED::MED_POINT1;
+    case VISU::eSEG2: 
+      return SALOME_MED::MED_SEG2;
+    case VISU::eTRIA3: 
+      return SALOME_MED::MED_TRIA3;
+    case VISU::eQUAD4: 
+      return SALOME_MED::MED_QUAD4;
+    case VISU::eTETRA4: 
+      return SALOME_MED::MED_TETRA4;
+    case VISU::eHEXA8: 
+      return SALOME_MED::MED_HEXA8;
+    case VISU::ePENTA6: 
+      return SALOME_MED::MED_PENTA6;
+    case VISU::ePYRA5: 
+      return SALOME_MED::MED_PYRA5;
+
+    case VISU::eSEG3: 
+      return SALOME_MED::MED_SEG3;
+    case VISU::eTRIA6: 
+      return SALOME_MED::MED_TRIA6;
+    case VISU::eQUAD8: 
+      return SALOME_MED::MED_QUAD8;
+    case VISU::eTETRA10: 
+      return SALOME_MED::MED_TETRA10;
+    case VISU::eHEXA20: 
+      return SALOME_MED::MED_HEXA20;
+    case VISU::ePENTA15: 
+      return SALOME_MED::MED_PENTA15;
+    case VISU::ePYRA13: 
+      return SALOME_MED::MED_PYRA13;
+    case VISU::ePOLYGONE: 
+      return SALOME_MED::MED_POLYGON;
+    case VISU::ePOLYEDRE: 
+      return  SALOME_MED::MED_POLYHEDRA;
+    }
+    return SALOME_MED::medGeometryElement(-1);
+  }
 
   //---------------------------------------------------------------
-  medGeometryElement 
+  SALOME_MED::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;
+    case VTK_VERTEX: 
+      return SALOME_MED::MED_POINT1;
+    case VTK_LINE: 
+      return SALOME_MED::MED_SEG2;
+    case VTK_TRIANGLE:
+      return SALOME_MED::MED_TRIA3;
+    case VTK_QUAD: 
+      return SALOME_MED::MED_QUAD4;
+    case VTK_TETRA: 
+      return SALOME_MED::MED_TETRA4;
+    case VTK_HEXAHEDRON: 
+      return SALOME_MED::MED_HEXA8;
+    case VTK_WEDGE:
+      return SALOME_MED::MED_PENTA6;
+    case VTK_PYRAMID: 
+      return SALOME_MED::MED_PYRA5;
+    case VTK_POLYGON: 
+      return SALOME_MED::MED_POLYGON;
     }
-    return medGeometryElement(-1);
+    return SALOME_MED::medGeometryElement(-1);
   }
   
   //---------------------------------------------------------------
   VISU::TEntity
-  MEDEntityToVTK(medEntityMesh theMEDEntity)
+  MEDEntityToVTK(SALOME_MED::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;
+    case SALOME_MED::MED_NODE: 
+      return VISU::NODE_ENTITY;
+    case SALOME_MED::MED_EDGE: 
+      return VISU::EDGE_ENTITY;
+    case SALOME_MED::MED_FACE: 
+      return VISU::FACE_ENTITY;
+    case SALOME_MED::MED_CELL: 
+      return VISU::CELL_ENTITY;
     }
     return VISU::TEntity(-1);
   }
   
   //---------------------------------------------------------------
-  medEntityMesh 
+  SALOME_MED::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;
+    case VISU::NODE_ENTITY: 
+      return SALOME_MED::MED_NODE;
+    case VISU::EDGE_ENTITY: 
+      return SALOME_MED::MED_EDGE;
+    case VISU::FACE_ENTITY: 
+      return SALOME_MED::MED_FACE;
+    case VISU::CELL_ENTITY: 
+      return SALOME_MED::MED_CELL;
     }
-    return medEntityMesh(-1);
+    return SALOME_MED::medEntityMesh(-1);
   }
 
   
@@ -239,17 +346,16 @@ namespace
               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);
+    const SALOME_MED::medEntityMesh& aMEntity = VTKEntityToMED(theVEntity);
+    SALOME_MED::MESH::connectivityInfos_var connInfo=theMEDMesh->getConnectGlobal(aMEntity);
+    int iGeomEnd = connInfo->meshTypes.length();
     for(int iGeom = 0; iGeom < iGeomEnd; iGeom++){
-      medGeometryElement aMEDGeom = aGeomElems[iGeom];
-      int iNumElemEnd = theMEDMesh->getNumberOfElements(aMEntity,aMEDGeom);
+      int iNumElemEnd = connInfo->numberOfElements[iGeom];
       if(iNumElemEnd > 0){
        if(MYDEBUG) MESSAGE("GetCellsSize - iNumElemEnd = "<<iNumElemEnd);
-       theCellsSize += iNumElemEnd*(MEDGeom2NbNodes(aMEDGeom) + 1);
+       theCellsSize += iNumElemEnd + connInfo->nodalConnectivityLength[iGeom];
        theNbCells += iNumElemEnd;
       }
     }
@@ -262,18 +368,16 @@ namespace
               vtkIdType& theCellsSize,
               SALOME_MED::FAMILY_ptr theMEDFamily)
   {
-    medGeometryElement_array_var aGeom = theMEDFamily->getTypes();
-    int iGeomEnd = aGeom->length();
     theNbCells = theCellsSize = 0;
+    SALOME_MED::SUPPORT::supportInfos_var suppInfo=theMEDFamily->getSupportGlobal();
+    int iGeomEnd = suppInfo->types.length();
     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();
+      int iNumElemEnd = suppInfo->nbEltTypes[iGeom];
       if(iNumElemEnd > 0){
        if(MYDEBUG) MESSAGE("GetCellsSize - iNumElemEnd = "<<iNumElemEnd);
        theNbCells += iNumElemEnd;
-       theCellsSize += iNumElemEnd*(MEDGeom2NbNodes(aMEDGeom) + 1);
+       theCellsSize += iNumElemEnd + suppInfo->nodalConnectivityLength[iGeom];
       }
     }
   }
@@ -285,9 +389,9 @@ namespace
               SALOME_MED::MESH_ptr theMEDMesh, 
               const VISU::TEntity& theEntity)
   {
-    TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap;
+    VISU::TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap;
     VISU::PCMeshOnEntity aMeshOnEntity = aMeshOnEntityMap[theEntity];
-    if(theEntity == NODE_ENTITY){
+    if(theEntity == VISU::NODE_ENTITY){
       aMeshOnEntity->myNbCells = theMesh->myNbPoints;
       aMeshOnEntity->myCellsSize = 2*theMesh->myNbPoints;
     }else{
@@ -297,16 +401,16 @@ namespace
  
 
   //---------------------------------------------------------------
-  PCMeshOnEntity 
+  VISU::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);
+    VISU::PCMeshOnEntity aMeshOnEntity;
+    VISU::TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap;
+    VISU::TMeshOnEntityMap::const_iterator anIter = aMeshOnEntityMap.find(theEntity);
     if(anIter == aMeshOnEntityMap.end()){
-      aMeshOnEntity.reset(new TCMeshOnEntity());
+      aMeshOnEntity.reset(new VISU::TCMeshOnEntity());
       *aMeshOnEntity = *theMeshOnEntity;
       aMeshOnEntity->myEntity = theEntity;
       aMeshOnEntityMap[theEntity] = aMeshOnEntity;
@@ -317,13 +421,209 @@ namespace
 
     return aMeshOnEntity;
   }
+
+  
+  VISU::PCSubProfile
+  CrSubProfile(const VISU::PCMesh theMesh,
+              const VISU::PCField theField,
+              const VISU::TCMeshOnEntity& theMeshOnEntity,
+              SALOME_MED::medGeometryElement theMGeom,
+              int theNbElems)
+  {
+    if (MYDEBUG) MESSAGE("CrSubProfile");
+    VISU::EGeometry aEGeom = MEDGeom2VISU(theMGeom);
+    vtkIdType aVNbNodes = VISUGeom2NbNodes(aEGeom);
+
+    VISU::PCSubProfile aSubProfile(new VISU::TCSubProfile());
+    aSubProfile->myGeom = aEGeom;
+    aSubProfile->myMGeom = theMGeom;
+    aSubProfile->myStatus = VISU::eAddAll;
+    if(MYDEBUG) MESSAGE("theMGeom = "<<theMGeom);
+    const VISU::TCellsFirstIndex& aCellsFirstIndex = theMeshOnEntity.myCellsFirstIndex;
+    VISU::TCellsFirstIndex::const_iterator aTimeStampIter = aCellsFirstIndex.find(theMGeom);
+    if(aTimeStampIter == (theMeshOnEntity.myCellsFirstIndex).end() && 
+       theMGeom != SALOME_MED::MED_POINT1)
+      aSubProfile->myStatus = VISU::eRemoveAll;
+    else if(aTimeStampIter == aCellsFirstIndex.end() && theMGeom == SALOME_MED::MED_POINT1){
+      if(theNbElems > 0){
+       aSubProfile->myName = "";
+       aSubProfile->myStatus = VISU::eAddPart;
+       
+       aSubProfile->myNbCells = theNbElems;
+       aSubProfile->myCellsSize = aSubProfile->myNbCells;
+      }
+    }else{
+       if(theNbElems > 0){
+         aSubProfile->myName = "";
+         aSubProfile->myStatus = VISU::eAddPart;
+         
+         aSubProfile->myNbCells = theNbElems;
+         aSubProfile->myCellsSize = aSubProfile->myNbCells*aVNbNodes;
+       }
+      }
+    
+    if (MYDEBUG) MESSAGE("CrSubProfile done");
+    return aSubProfile;
+  }
+
+  VISU::TProfileKey
+  GetProfileKey(const VISU::PCMesh theMesh,
+               const VISU::PCField theField,
+               const VISU::PCValForTime theValForTime,
+               const VISU::TCMeshOnEntity& theMeshOnEntity)
+  {
+    if (MYDEBUG) MESSAGE("GetProfileKey");
+
+    VISU::TProfileKey aProfileKey;
+
+    const VISU::TCellsFirstIndex& aFirstIndex = theMeshOnEntity.myCellsFirstIndex;
+    VISU::TCellsFirstIndex::const_iterator anIter = aFirstIndex.begin();
+    SALOME_MED::SUPPORT_var aSupport = theValForTime->myField->getSupport();
+    int aNbElems = 0;
+    if(anIter == aFirstIndex.end() && aSupport->getEntity() == SALOME_MED::MED_NODE){
+      SALOME_MED::medGeometryElement aMGeom = SALOME_MED::MED_POINT1;
+      try{
+       aNbElems = aSupport->getNumberOfElements(SALOME_MED::MED_NONE);
+       if(MYDEBUG)MESSAGE("aMGeom="<<aMGeom<<"   aNbElems="<<aNbElems);
+      }catch(...){
+       MESSAGE("Error in theValForTime->myField->getSupport()->getNumberOfElements(aMGeom);");
+      }
+       
+      VISU::PCSubProfile aSubProfile = CrSubProfile(theMesh,
+                                                   theField,
+                                                   theMeshOnEntity,
+                                                   aMGeom,
+                                                   aNbElems);
+      aProfileKey.insert(aSubProfile);
+    }
+    
+    for(; anIter != aFirstIndex.end(); anIter++){
+      SALOME_MED::medGeometryElement aMGeom = anIter->first;
+      try{
+       aNbElems = aSupport->getNumberOfElements(aMGeom);
+       if(MYDEBUG)MESSAGE("aMGeom="<<aMGeom<<"   aNbElems="<<aNbElems);
+      }        catch(...){
+       MESSAGE("Error in theValForTime->myField->getSupport()->getNumberOfElements(aMGeom);");
+       continue;
+      }
+      VISU::PCSubProfile aSubProfile = CrSubProfile(theMesh,
+                                                   theField,
+                                                   theMeshOnEntity,
+                                                   aMGeom,
+                                                   aNbElems);
+      aProfileKey.insert(aSubProfile);
+    }
+
+    if (MYDEBUG) MESSAGE("GetProfileKey done");
+    return aProfileKey;
+  }
+  
+  void
+  InitProfile(VISU::PCMesh theMesh,
+             VISU::PCField theField,
+             VISU::PCValForTime theValForTime,
+             VISU::TCMeshOnEntity& theMeshOnEntity)
+  {
+    if (MYDEBUG) MESSAGE("InitProfile");
+    
+    VISU::TProfileMap& aProfileMap = theMeshOnEntity.myProfileMap;
+
+    VISU::TProfileKey aProfileKey = GetProfileKey(theMesh,
+                                                 theField,
+                                                 theValForTime,
+                                                 theMeshOnEntity);
+    
+    VISU::TProfileMap::const_iterator anIter = aProfileMap.find(aProfileKey);
+    if(anIter != aProfileMap.end()){
+      theValForTime->myProfile = anIter->second;
+      if(MYDEBUG) MESSAGE("aProfileMap.find(aProfileKey) aProfile->myGeom=");
+    }else{
+      VISU::PCProfile aProfile(new VISU::TCProfile());
+      VISU::TGeom2SubProfile& aGeom2SubProfile = aProfile->myGeom2SubProfile;
+      
+      VISU::TProfileKey::const_iterator anIter = aProfileKey.begin();
+      for(; anIter != aProfileKey.end(); anIter++){
+       VISU::PCSubProfile aSubProfile(*anIter);
+       
+       if(aProfile->myIsAll && aSubProfile->myStatus != VISU::eAddAll)
+         aProfile->myIsAll = false;
+       
+       VISU::EGeometry aEGeom = aSubProfile->myGeom;
+       aGeom2SubProfile[aEGeom] = aSubProfile;
+      }
+      
+      aProfileMap[aProfileKey] = aProfile;
+      theValForTime->myProfile = aProfile;
+    }
+    if (MYDEBUG) MESSAGE("InitProfile done");
+  }
+
+  void
+  LoadProfile(VISU::PCMesh theMesh,
+             VISU::PCField theField,
+             VISU::PCValForTime theValForTime,
+             VISU::PCMeshOnEntity theMeshOnEntity)
+  {
+    VISU::PCProfile aProfile = theValForTime->myProfile;
+    if (MYDEBUG) MESSAGE("LoadProfile aProfile->myIsDone="<<aProfile->myIsDone);
+    if(aProfile->myIsDone)
+      return;
+    
+    const VISU::TGeom2SubProfile& aGeom2SubProfile = aProfile->myGeom2SubProfile;
+    VISU::TGeom2SubProfile::const_iterator aGeom2SubProfileIter = aGeom2SubProfile.begin();
+    if(aGeom2SubProfileIter == aGeom2SubProfile.end()){
+      MESSAGE("Warning! No geom 2 sub profile");
+    }
+    SALOME_MED::SUPPORT_var aSupport = theValForTime->myField->getSupport();
+    for(; aGeom2SubProfileIter != aGeom2SubProfile.end(); aGeom2SubProfileIter++){
+      VISU::EGeometry aEGeom = aGeom2SubProfileIter->first;
+      SALOME_MED::medGeometryElement aMGeom = VISUGeomToMED(aEGeom);
+      VISU::PCSubProfile aSubProfile = aGeom2SubProfileIter->second;
+      SALOME_MED::long_array_var aGeom2ProfileIds;
+      std::vector<int> aGeom2Profile;
+      if(!aSupport->isOnAllElements()){
+       try{
+         if(aMGeom == SALOME_MED::MED_POINT1)
+           aGeom2ProfileIds = aSupport->getNumberFromFile(SALOME_MED::MED_NONE);
+         else
+           aGeom2ProfileIds = aSupport->getNumberFromFile(aMGeom);
+         int aLen = aGeom2ProfileIds->length();
+         if(MYDEBUG) MESSAGE(" - aMGeom="<<aMGeom<<"; aNbCells="<<aLen);
+         for(int i = 0; i < aLen; i++){
+           int anId = aGeom2ProfileIds[i];
+           aGeom2Profile.push_back(anId);
+           if(MYDEBUG) cout << "------------------------------->" << anId << endl;
+         }
+         if(MYDEBUG) cout << endl;
+       } catch(...) {
+         continue;
+       }
+      } else {
+       SALOME_MED::medEntityMesh aMEntity = aSupport->getEntity();
+       int aNbElems = theMesh->myMesh->getNumberOfElements(aMEntity,aMGeom);
+       for(int i = 0; i < aNbElems; i++) 
+         aGeom2Profile.push_back(i+1);
+      }
+      if(aGeom2Profile.size()>0){
+       VISU::TSubMeshID& aSubMeshID = aSubProfile->mySubMeshID;
+       int aSize = aGeom2Profile.size();
+       aSubMeshID.resize(aSize);
+       for(int anId = 0; anId < aSize; anId++){
+         aSubMeshID[anId] = aGeom2Profile[anId] - 1;
+       }
+      }
+    }
+    
+    aProfile->myIsDone = true;
+    if (MYDEBUG) MESSAGE("LoadProfile done");
+  }
 }
 
 
 //---------------------------------------------------------------
 VISU_Convertor* 
-VISU_MEDFieldConvertor::Build()
+VISU_MEDFieldConvertor
+::Build()
 {
   if(myField->_is_nil()) 
     throw std::runtime_error("VISU_MEDFieldConvertor::Build >> myField->_is_nil() !!!");
@@ -333,7 +633,7 @@ VISU_MEDFieldConvertor::Build()
     throw std::runtime_error("VISU_MEDFieldConvertor::Build >> aMEDSupport->_is_nil() !!!");
 
   SALOME_MED::medEntityMesh aMEntity = aMEDSupport->getEntity();
-  TEntity aVEntity = MEDEntityToVTK(aMEntity);
+  VISU::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() !!!");
@@ -341,48 +641,58 @@ VISU_MEDFieldConvertor::Build()
   CORBA::String_var aMeshName = aMEDMesh->getName();
   CORBA::String_var aFieldName = myField->getName();
 
-  PCMesh aMesh = myMeshMap[aMeshName.in()](new TCMesh());
-  aMesh->myNamedPointCoords(new TNamedPointCoords());
+  VISU::PCMesh aMesh = myMeshMap[aMeshName.in()](new VISU::TCMesh());
+  aMesh->myNamedPointCoords(new VISU::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());
+  VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
+  VISU::PCMeshOnEntity aMeshOnEntity = aMeshOnEntityMap[aVEntity](new VISU::TCMeshOnEntity());
   aMeshOnEntity->myEntity = aVEntity;
   aMeshOnEntity->myMeshName = aMeshName.in();
   aMeshOnEntity->mySupport = aMEDSupport;
 
-  if(aVEntity == NODE_ENTITY)
-    ::InitMeshOnEntity(aMesh,CELL_ENTITY,aMeshOnEntity);
+  if(aVEntity == VISU::NODE_ENTITY)
+    ::InitMeshOnEntity(aMesh, VISU::CELL_ENTITY, aMeshOnEntity);
   else
-    ::InitMeshOnEntity(aMesh,NODE_ENTITY,aMeshOnEntity);
+    ::InitMeshOnEntity(aMesh, VISU::NODE_ENTITY, aMeshOnEntity);
 
-  ::GetCellsSize(aMesh,aMEDMesh,aVEntity);
+  ::GetCellsSize(aMesh, aMEDMesh, aVEntity);
 
-  TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
-  PCField aField = aFieldMap[aFieldName.in()](new TCField());
+  VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
+  VISU::PCField aField = aFieldMap[aFieldName.in()](new VISU::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;
 
+  vtkIdType aDataType = VTK_DOUBLE;
+  SALOME_MED::FIELDDOUBLE_ptr aFieldDouble = SALOME_MED::FIELDDOUBLE::_narrow(myField);
+  if(aFieldDouble->_is_nil()) {
+    // PAL18313: Mandriva 64 porting: CRASH at creating presentation on "Import Structure".
+    if (sizeof(long) == 4 ) // Size of CORBA::Long is always 4 (see CORBA_basetypes.h)
+      aDataType = VTK_LONG;
+    else if (sizeof(int) == 4)
+      aDataType = VTK_INT;
+    else {
+      throw std::runtime_error("Can't map CORBA::Long to a VTK type");
+    }
+  }
+  aField->Init(myField->getNumberOfComponents(), aDataType);
+
   if(MYDEBUG) MESSAGE("VISU_MEDFieldConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh->myDim);
 
-  TValField& aValField = aField->myValField;
+  VISU::TValField& aValField = aField->myValField;
   int anId = myField->getIterationNumber();
-  PCValForTime aValForTime = aValField[anId](new TCValForTime());
+  VISU::PCValForTime aValForTime = aValField[anId](new VISU::TCValForTime());
   aValForTime->myId = anId;
   CORBA::Double aDT = myField->getTime();
-  aValForTime->myTime = TTime(aDT,"");
+  aValForTime->myTime = VISU::TTime(aDT,"");
   aValForTime->myField = myField;
 
   if(MYDEBUG) 
@@ -395,7 +705,8 @@ VISU_MEDFieldConvertor::Build()
 
 //---------------------------------------------------------------
 VISU_Convertor* 
-VISU_MEDConvertor::Build() 
+VISU_MEDConvertor
+::Build() 
 {
   if(mySObject->_is_nil()) 
     throw std::runtime_error("VISU_MEDConvertor::Build >> mySObject->_is_nil() !!!");
@@ -412,8 +723,8 @@ VISU_MEDConvertor::Build()
 }
 
 
-namespace{
-
+namespace
+{
   using namespace boost;
 
   //---------------------------------------------------------------
@@ -494,7 +805,8 @@ namespace{
 
 //---------------------------------------------------------------
 VISU_Convertor* 
-VISU_MEDConvertor::Build(SALOME_MED::MED_ptr theMED)
+VISU_MEDConvertor
+::Build(SALOME_MED::MED_ptr theMED)
 {
   if(CORBA::is_nil(theMED)) 
     return NULL;
@@ -523,17 +835,14 @@ VISU_MEDConvertor::Build(SALOME_MED::MED_ptr theMED)
       if(!anIsSuccess)
        continue;
 
-      PCMesh aMesh = myMeshMap[aMeshName.in()](new TCMesh());
+      VISU::PCMesh aMesh = myMeshMap[aMeshName.in()](new VISU::TCMesh());
       SALOME_MED::MESH_var aMEDMesh = boost::get<0>(aMeshByNameRet);
-      aMesh->myNamedPointCoords(new TNamedPointCoords());
+      aMesh->myNamedPointCoords(new VISU::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);
 
@@ -551,7 +860,7 @@ VISU_MEDConvertor::Build(SALOME_MED::MED_ptr theMED)
       if(!anIsSuccess)
        continue;
 
-      TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
+      VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
       SALOMEDS::SObject_var aSupportsSObj = boost::get<0>(aSObjectByNameRet);
       SALOMEDS::ChildIterator_var aSupportIterator = aStudy->NewChildIterator(aSupportsSObj);
 
@@ -579,7 +888,7 @@ VISU_MEDConvertor::Build(SALOME_MED::MED_ptr theMED)
                    "' aVEntity = "<<aVEntity);
          int aNbCells, aCellsSize;
          //Check, if there is any data on the support?
-         if(aVEntity == NODE_ENTITY){
+         if(aVEntity == VISU::NODE_ENTITY){
            aMesh->myNbPoints = aMeshOnSupport->getNumberOfNodes();
            aNbCells = aMesh->myNbPoints;
            aCellsSize = 2*aMesh->myNbPoints;
@@ -587,9 +896,8 @@ VISU_MEDConvertor::Build(SALOME_MED::MED_ptr theMED)
            ::GetCellsSize(aNbCells,aCellsSize,aMeshOnSupport,aVEntity);
          
          if(aNbCells > 0){
-           TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.find(aVEntity);
-           if(aMeshOnEntityMapIter == aMeshOnEntityMap.end()){
-             PCMeshOnEntity aMeshOnEntity(new TCMeshOnEntity());
+           if(aMeshOnEntityMap.find(aVEntity) == aMeshOnEntityMap.end()){
+             VISU::PCMeshOnEntity aMeshOnEntity(new VISU::TCMeshOnEntity());
              aMeshOnEntity->myMeshName = aMeshName.in();
              aMeshOnEntity->myEntity = aVEntity;
              aMeshOnEntity->myNbCells = aNbCells;
@@ -621,10 +929,10 @@ VISU_MEDConvertor::Build(SALOME_MED::MED_ptr theMED)
        
        SALOME_MED::FAMILY_var aMEDFamily = SALOME_MED::FAMILY::_narrow(aMedSupport);
        if(!aMEDFamily->_is_nil()) {
-         TMeshOnEntityMap::iterator aMeshOnEntityMapIter = aMeshOnEntityMap.find(aVEntity);
+         VISU::TMeshOnEntityMap::iterator aMeshOnEntityMapIter = aMeshOnEntityMap.find(aVEntity);
          if(aMeshOnEntityMapIter == aMeshOnEntityMap.end())
            continue;
-         PCMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
+         VISU::PCMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
 
          int aNbCells = aMeshOnEntity->myNbCells, aCellsSize = aMeshOnEntity->myCellsSize;
          CORBA::Boolean anIsOnAllElements = aMEDSupport->isOnAllElements();
@@ -639,10 +947,10 @@ VISU_MEDConvertor::Build(SALOME_MED::MED_ptr theMED)
                    "; aNbCells = "<<aNbCells);
 
          if(aNbCells > 0){
-           TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
-           TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.find(aSupportName.in());
+           VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
+           VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.find(aSupportName.in());
            if(aFamilyMapIter == aFamilyMap.end()){
-             PCFamily aFamily(new TCFamily());
+             VISU::PCFamily aFamily(new VISU::TCFamily());
              aFamily->myEntity = aVEntity;
              aFamily->myNbCells = aNbCells;
              aFamily->myCellsSize = aCellsSize;
@@ -683,7 +991,7 @@ VISU_MEDConvertor::Build(SALOME_MED::MED_ptr theMED)
                    "; anIsOnAllElements = "<<anIsOnAllElements<<
                    "; aVEntity = "<<aVEntity);
 
-         PCGroup aGroup(new TCGroup());
+         VISU::PCGroup aGroup(new VISU::TCGroup());
          aGroup->myGroup = aMEDGroup;
          VISU::TFamilySet& aFamilySet = aGroup->myFamilySet;
          
@@ -693,8 +1001,8 @@ VISU_MEDConvertor::Build(SALOME_MED::MED_ptr theMED)
            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);
+             FindFamilyOnEntity(aMeshName.in(), aVEntity, aFamilyName.in());
+           VISU::PCFamily aFamily = boost::get<2>(aFindFamilyOnEntity);
            if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aGroup - aFamilyName = '"<<aFamilyName.in()<<"' = "<<bool(aFamily));
            if(aFamily){
              aFamilySet.insert(aFamily);
@@ -702,7 +1010,7 @@ VISU_MEDConvertor::Build(SALOME_MED::MED_ptr theMED)
          }
          
          if(!aFamilySet.empty()){
-           TGroupMap& aGroupMap = aMesh->myGroupMap;
+           VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
            aGroupMap[aSupportName.in()] = aGroup;
          }
 
@@ -745,39 +1053,54 @@ VISU_MEDConvertor::Build(SALOME_MED::MED_ptr theMED)
        CORBA::String_var aMeshName = aMEDMesh->getName();
        CORBA::String_var aFieldName = aMEDField->getName();
        
-       TMeshMap::iterator aMeshMapIter = myMeshMap.find(aMeshName.in());
+       VISU::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);
+       VISU::PCMesh aMesh = aMeshMapIter->second;
+       VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
+       VISU::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;
+       VISU::PCMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
+       VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
+       VISU::TFieldMap::iterator aFieldMapIter = aFieldMap.find(aFieldName.in());
+       VISU::PCField aField;
        if(aFieldMapIter == aFieldMap.end()){
-         aField = aFieldMap[aFieldName.in()](new TCField());
+         aField = aFieldMap[aFieldName.in()](new VISU::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;
+
+         vtkIdType aDataType = VTK_DOUBLE;
+         SALOME_MED::FIELDDOUBLE_ptr aFieldDouble = SALOME_MED::FIELDDOUBLE::_narrow(aMEDField);
+         if(aFieldDouble->_is_nil()) {
+            // PAL18313: Mandriva 64 porting: CRASH at creating presentation on "Import Structure".
+            if (sizeof(long) == 4 ) // Size of CORBA::Long is always 4 (see CORBA_basetypes.h)
+              aDataType = VTK_LONG;
+            else if (sizeof(int) == 4)
+              aDataType = VTK_INT;
+            else {
+              MESSAGE("Can't map CORBA::Long to a VTK type, for Field " << aFieldName);
+              continue;
+            }
+          }
+         aField->Init(aMEDField->getNumberOfComponents(), aDataType);
+
          if(MYDEBUG) 
            MESSAGE("VISU_MEDConvertor::Build - aMeshOnEntity->myNbCells = "<<aMeshOnEntity->myNbCells);
        }else
          aField = aFieldMapIter->second;
 
-       TValField& aValField = aField->myValField;
+       VISU::TValField& aValField = aField->myValField;
        int anId = aMEDField->getIterationNumber();
-       PCValForTime aValForTime = aValField[anId](new TCValForTime());
+       VISU::PCValForTime aValForTime = aValField[anId](new VISU::TCValForTime());
        aValForTime->myId = anId;
        CORBA::Double aDT = aMEDField->getTime();
-       aValForTime->myTime = TTime(aDT,"");
+       aValForTime->myTime = VISU::TTime(aDT,"");
        aValForTime->myField = aMEDField;
        if(MYDEBUG) 
          MESSAGE("VISU_MEDConvertor::Build - aMeshName = '"<<aMeshName<<
@@ -791,7 +1114,8 @@ VISU_MEDConvertor::Build(SALOME_MED::MED_ptr theMED)
 
 //---------------------------------------------------------------
 VISU_Convertor* 
-VISU_MEDConvertor::Build(SALOMEDS::ChildIterator_ptr theTimeStampIterator)
+VISU_MEDConvertor
+::Build(SALOMEDS::ChildIterator_ptr theTimeStampIterator)
 {
   if(theTimeStampIterator->_is_nil()) return NULL;
   for(; theTimeStampIterator->More(); theTimeStampIterator->Next()){
@@ -811,25 +1135,22 @@ VISU_MEDConvertor::Build(SALOMEDS::ChildIterator_ptr theTimeStampIterator)
       continue;
 
     SALOME_MED::medEntityMesh aMEntity = aMEDSupport->getEntity();
-    TEntity aVEntity = MEDEntityToVTK(aMEntity);
+    VISU::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();
 
-    PCMesh aMesh;
-    TMeshMap::const_iterator aMeshMapIter = myMeshMap.find(aMeshName.in());
+    VISU::PCMesh aMesh;
+    VISU::TMeshMap::const_iterator aMeshMapIter = myMeshMap.find(aMeshName.in());
     if(aMeshMapIter == myMeshMap.end()){
-      aMesh.reset(new TCMesh());
-      aMesh->myNamedPointCoords(new TNamedPointCoords());
+      aMesh.reset(new VISU::TCMesh());
+      aMesh->myNamedPointCoords(new VISU::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) 
@@ -839,11 +1160,11 @@ VISU_MEDConvertor::Build(SALOMEDS::ChildIterator_ptr theTimeStampIterator)
     }else
       aMesh = aMeshMapIter->second;
 
-    PCMeshOnEntity aMeshOnEntity;
-    TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
-    TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.find(aVEntity);
+    VISU::PCMeshOnEntity aMeshOnEntity;
+    VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
+    VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.find(aVEntity);
     if(aMeshOnEntityMapIter == aMeshOnEntityMap.end()){
-      aMeshOnEntity.reset(new TCMeshOnEntity());
+      aMeshOnEntity.reset(new VISU::TCMeshOnEntity());
       aMeshOnEntity->myEntity = aVEntity;
       aMeshOnEntity->myMeshName = aMeshName.in();
       aMeshOnEntity->mySupport = aMEDSupport;
@@ -851,25 +1172,30 @@ VISU_MEDConvertor::Build(SALOMEDS::ChildIterator_ptr theTimeStampIterator)
     }else
       aMeshOnEntity = aMeshOnEntityMapIter->second;
 
-    if(aVEntity == NODE_ENTITY)
-      ::InitMeshOnEntity(aMesh,CELL_ENTITY,aMeshOnEntity);
+    if(aVEntity == VISU::NODE_ENTITY)
+      ::InitMeshOnEntity(aMesh,VISU::CELL_ENTITY,aMeshOnEntity);
     else
-      ::InitMeshOnEntity(aMesh,NODE_ENTITY,aMeshOnEntity);
+      ::InitMeshOnEntity(aMesh,VISU::NODE_ENTITY,aMeshOnEntity);
 
     ::GetCellsSize(aMesh,aMEDMesh,aVEntity);
 
-    PCField aField;
-    TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
-    TFieldMap::const_iterator aFieldMapIter = aFieldMap.find(aFieldName.in());
+    VISU::PCField aField;
+    VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
+    VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.find(aFieldName.in());
     if(aFieldMapIter == aFieldMap.end()){
-      aField.reset(new TCField());
+      aField.reset(new VISU::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;
       
+      vtkIdType aDataType = VTK_DOUBLE;
+      SALOME_MED::FIELDDOUBLE_ptr aFieldDouble = SALOME_MED::FIELDDOUBLE::_narrow(aMEDField);
+      if(aFieldDouble->_is_nil())
+       aDataType = VTK_LONG;
+      aField->Init(aMEDField->getNumberOfComponents(), aDataType);
+
       aFieldMap[aFieldName.in()] = aField;
 
       if(MYDEBUG) 
@@ -877,12 +1203,12 @@ VISU_MEDConvertor::Build(SALOMEDS::ChildIterator_ptr theTimeStampIterator)
     }else
       aField = aFieldMapIter->second;
 
-    TValField& aValField = aField->myValField;
+    VISU::TValField& aValField = aField->myValField;
     int anId = aMEDField->getIterationNumber();
-    PCValForTime aValForTime = aValField[anId](new TCValForTime());
+    VISU::PCValForTime aValForTime = aValField[anId](new VISU::TCValForTime());
     aValForTime->myId = anId;
     CORBA::Double aDT = aMEDField->getTime();
-    aValForTime->myTime = TTime(aDT,"");
+    aValForTime->myTime = VISU::TTime(aDT,"");
     aValForTime->myField = aMEDField;
     if(MYDEBUG) 
       MESSAGE("VISU_MEDConvertor::Build "<<
@@ -902,8 +1228,8 @@ VISU_MEDConvertor
                   VISU::PMeshOnEntityImpl theMeshOnEntity)
 {
   int anIsUpdated = LoadPoints(theMesh);
-  const TEntity& aVEntity = theMeshOnEntity->myEntity;
-  if(aVEntity != NODE_ENTITY)
+  const VISU::TEntity& aVEntity = theMeshOnEntity->myEntity;
+  if(aVEntity != VISU::NODE_ENTITY)
     anIsUpdated |= LoadCellsOnEntity(theMesh,theMeshOnEntity);
 
   return anIsUpdated;
@@ -918,8 +1244,8 @@ VISU_MEDConvertor
                     VISU::PFamilyImpl theFamily)
 {
   int anIsUpdated = LoadPoints(theMesh);
-  const TEntity& anEntity = theMeshOnEntity->myEntity;
-  if(anEntity == NODE_ENTITY){
+  const VISU::TEntity& anEntity = theMeshOnEntity->myEntity;
+  if(anEntity == VISU::NODE_ENTITY){
     anIsUpdated |= LoadPointsOnFamily(theMesh,theFamily);
   }else{
     anIsUpdated |= LoadCellsOnEntity(theMesh,theMeshOnEntity);
@@ -938,11 +1264,11 @@ VISU_MEDConvertor
 {
   //Main part of code
   int anIsUpdated = LoadPoints(theMesh);
-  TFamilySet::const_iterator aFamilyIter = theFamilySet.begin();
+  VISU::TFamilySet::const_iterator aFamilyIter = theFamilySet.begin();
   for(; aFamilyIter != theFamilySet.end(); aFamilyIter++){
-    PCFamily aFamily = *aFamilyIter;
+    VISU::PCFamily aFamily = *aFamilyIter;
     const VISU::TEntity& aVEntity = aFamily->myEntity;
-    PCMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[aVEntity];
+    VISU::PCMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[aVEntity];
     if(aVEntity == VISU::NODE_ENTITY){
       anIsUpdated |= LoadPointsOnFamily(theMesh,aFamily);
     }else{
@@ -965,8 +1291,8 @@ VISU_MEDConvertor
 {
   //Main part of code
   int anIsUpdated = LoadPoints(theMesh);
-  const TEntity& aVEntity = theMeshOnEntity->myEntity;
-  if(aVEntity != NODE_ENTITY)
+  const VISU::TEntity& aVEntity = theMeshOnEntity->myEntity;
+  if(aVEntity != VISU::NODE_ENTITY)
     anIsUpdated |= LoadCellsOnEntity(theMesh,theMeshOnEntity);
 
   anIsUpdated |= LoadField(theMesh,theMeshOnEntity,theField,theValForTime);
@@ -981,16 +1307,15 @@ VISU_MEDConvertor
 ::LoadPoints(VISU::PCMesh theMesh)
 {
   //Check on existing family
-  PCMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[VISU::NODE_ENTITY];
+  VISU::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();
+  vtkIdType aDim = theMesh->GetDim();
+  vtkIdType aNbElem = theMesh->GetNbPoints();
 
   if(MYDEBUG) MESSAGE("LoadPoints - aNbElem = "<<aNbElem);
 
@@ -998,24 +1323,25 @@ VISU_MEDConvertor
     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++];
-  }
+  VISU::TCMEDCoordHolder* aCoordHolder = new VISU::TCMEDCoordHolder();
+  aCoordHolder->Init(aNbElem, aDim, aCCoord);
+
+  VISU::TNamedPointCoords& aCoords = theMesh->myNamedPointCoords;
+  aCoords.Init(VISU::PCoordHolder(aCoordHolder));
   
   if(MYDEBUG) MESSAGE("LoadPoints - Filling aMeshOnEntity with type NODE_ENTITY");
   
-  TGeom2SubMesh& aGeom2SubMesh = aMeshOnEntity->myGeom2SubMesh;
-  PSubMeshImpl aSubMesh = aGeom2SubMesh[VISU::ePOINT1](new TCSubMesh());
+  VISU::TGeom2SubMesh& aGeom2SubMesh = aMeshOnEntity->myGeom2SubMesh;
+  VISU::PSubMeshImpl aSubMesh = aGeom2SubMesh[VISU::ePOINT1](new VISU::TCSubMesh());
 
   aSubMesh->myNbCells = theMesh->myNbPoints;
   aSubMesh->myCellsSize = 2*theMesh->myNbPoints;
 
-  TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
+  VISU::TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
   aCell2Connect.resize(aNbElem);
+  if(MYDEBUG) MESSAGE("LoadPoints - aNbElem="<<aNbElem);
   for(int iElem = 0; iElem < aNbElem; iElem++)
-    aCell2Connect[iElem] = TConnect(1,iElem);
+    aCell2Connect[iElem] = VISU::TConnect(1,iElem);
   
   theMesh->myIsDone = true;
 
@@ -1029,17 +1355,15 @@ VISU_MEDConvertor
 ::LoadPointsOnFamily(VISU::PCMesh theMesh, 
                     VISU::PCFamily theFamily)
 {
-  PCMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[VISU::NODE_ENTITY];
+  VISU::PCMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[VISU::NODE_ENTITY];
 
   if(theFamily->myIsDone) 
     return 0;
 
-  TNamedPointCoords& aCoords = theMesh->myNamedPointCoords;
-  int aNbElem = aCoords.GetNbPoints();
-
+  vtkIdType aNbElem = theMesh->GetNbPoints();
   SALOME_MED::FAMILY_var aMedFamily = theFamily->myFamily;
   CORBA::Boolean anIsOnAllElements = aMedFamily->isOnAllElements();
-  TSubMeshID& aSubMeshID = theFamily->myGeom2SubMeshID[VISU::ePOINT1];
+  VISU::TSubMeshID& aSubMeshID = theFamily->myGeom2SubMeshID[VISU::ePOINT1];
   
   if(!anIsOnAllElements){
     SALOME_MED::medGeometryElement_array_var aGeom = aMedFamily->getTypes();
@@ -1062,10 +1386,131 @@ VISU_MEDConvertor
   }
   
   theFamily->myIsDone = true;
-
+  
   return 1;
 }
 
+//---------------------------------------------------------------
+namespace 
+{
+  typedef MED::TCSlice<int> TA;
+  //---------------------------------------------------------------
+  typedef std::set<int> TConnSet;
+  typedef std::vector<int> TIntArray;
+  typedef MED::TCSlice<int> TConnSlice;
+
+  //---------------------------------------------------------------
+  class MEDPolygonConnectivity //! retriver of polygon connectivity
+  {
+    TIntArray myConn;
+    TIntArray myConnIndex;
+  public:
+
+    MEDPolygonConnectivity(SALOME_MED::MESH_var theMesh,
+                           SALOME_MED::medEntityMesh theEntity) 
+    {
+      {
+       SALOME::SenderInt_var aSender = 
+         theMesh->getSenderForPolygonsConnectivity(SALOME_MED::MED_NODAL, theEntity);
+       long int aSize;
+       int* aValuePtr = ReceiverFactory::getValue(aSender.in(), aSize);
+       myConn.assign(aValuePtr, aValuePtr + aSize);
+      }
+      {
+       SALOME::SenderInt_var aSender = 
+         theMesh->getSenderForPolygonsConnectivityIndex(SALOME_MED::MED_NODAL, theEntity);
+       long int aSize;
+       int* aValuePtr = ReceiverFactory::getValue(aSender, aSize);
+       myConnIndex.assign(aValuePtr, aValuePtr + aSize);
+      }
+    }
+
+    TConnSlice 
+    GetConn(int theId) const 
+    {
+      int anOffSet = myConnIndex[theId] - 1;
+      int aSize = myConnIndex[theId + 1] - myConnIndex[ theId ];
+      return TConnSlice(&myConn[0], myConn.size(), std::slice(anOffSet, aSize, 1));
+    }
+
+    int 
+    GetNbElem() const 
+    {
+      return myConnIndex.size() - 1;
+    }
+
+    int
+    GetCellSize() const
+    {
+      return myConn.size() + GetNbElem();
+    }
+  };
+
+
+  //---------------------------------------------------------------
+  class MEDPolyhedraConnectivity //! retriver of polyhedron connectivity
+  {
+    TIntArray myConn;
+    TIntArray myConnIndex;
+    TIntArray myFaceIndex;
+  public:
+
+    MEDPolyhedraConnectivity(SALOME_MED::MESH_var theMesh)
+    {
+      {
+       SALOME::SenderInt_var aSender = 
+         theMesh->getSenderForPolyhedronConnectivity(SALOME_MED::MED_NODAL);
+       long int aSize;
+       int* aValuePtr = ReceiverFactory::getValue(aSender, aSize);
+       myConn.assign(aValuePtr, aValuePtr + aSize);
+      }
+      {
+       SALOME::SenderInt_var aSender = 
+         theMesh->getSenderForPolyhedronIndex(SALOME_MED::MED_NODAL);
+       long int aSize;
+       int* aValuePtr = ReceiverFactory::getValue(aSender, aSize);
+       myConnIndex.assign(aValuePtr, aValuePtr + aSize);
+      }
+      {
+       SALOME::SenderInt_var aSender = 
+         theMesh->getSenderForPolyhedronFacesIndex();
+       long int aSize;
+       int* aValuePtr = ReceiverFactory::getValue(aSender, aSize);
+       myFaceIndex.assign(aValuePtr, aValuePtr + aSize);
+      }
+    }
+
+    int
+    GetUniqueConn(int theId, 
+                 TConnSet& theConnSet) const 
+    {
+      theConnSet.clear();
+      int aStartFaceId = myConnIndex[theId] - 1;
+      int anEndFaceId = myConnIndex[theId + 1] - 2;
+      int aStartConnId = myFaceIndex[aStartFaceId] - 1;
+      int anEndConnId = myFaceIndex[anEndFaceId + 1] - 1;
+      for(int aConnId = aStartConnId; aConnId < anEndConnId; aConnId++)
+        theConnSet.insert(myConn[aConnId]);
+      return theConnSet.size();
+    }
+
+    int
+    GetNbElem() const
+    {
+      return myConnIndex.size() - 1;
+    }
+
+    int
+    GetCellSize() const
+    {
+      TConnSet aConnSet;
+      int aCellSize = 0;
+      for(int anElemId = 0; anElemId < GetNbElem(); anElemId++)
+       aCellSize += GetUniqueConn(anElemId, aConnSet);
+      return aCellSize;
+    }
+  };
+}
 
 //---------------------------------------------------------------
 int 
@@ -1080,115 +1525,194 @@ VISU_MEDConvertor
   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 VISU::TEntity& aVEntity = theMeshOnEntity->myEntity;
   const SALOME_MED::medEntityMesh& aMEntity = VTKEntityToMED(aVEntity);
-  const TNamedPointCoords& aCoords = theMesh->myNamedPointCoords;
-  TGeom2SubMesh& aGeom2SubMesh = theMeshOnEntity->myGeom2SubMesh;
-  int aNbPoints = aCoords.GetNbPoints();
+  VISU::TCellsFirstIndex& aFirstIndex = theMeshOnEntity->myCellsFirstIndex;
 
-  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);
+  SALOME_MED::MESH::connectivityInfos_var anInfo = aMedMesh->getConnectGlobal(aMEntity);
+  int iGeomEnd = anInfo->meshTypes.length();
 
-      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;
+  VISU::TGeom2SubMesh& aGeom2SubMesh = theMeshOnEntity->myGeom2SubMesh;
+  vtkIdType aNbPoints = theMesh->GetNbPoints();
 
-       switch(aMGeom){
+  for(int iGeom = 0, aCounter = 0; iGeom < iGeomEnd; iGeom++) {
+    SALOME_MED::medGeometryElement aMGeom = anInfo->meshTypes[iGeom];
+    VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
+    switch (aMGeom) {
+    case SALOME_MED::MED_POLYGON:
+    {
+      MEDPolygonConnectivity aConn(aMedMesh, aMEntity);
+      int aNbElem = aConn.GetNbElem();
+      if (aNbElem > 0) {
+        VISU::PSubMeshImpl aSubMesh = aGeom2SubMesh[aEGeom](new VISU::TCSubMesh());
+        aSubMesh->myNbCells   = aNbElem;
+        aSubMesh->myCellsSize = aConn.GetCellSize();
+
+        VISU::TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
+        aCell2Connect.resize(aNbElem);
+
+        for(int iElem = 0; iElem < aNbElem; iElem++) {
+          TConnSlice aConnSlice = aConn.GetConn(iElem);
+          VISU::TConnect& anArray = aCell2Connect[iElem];
+          anArray.resize(aConnSlice.size());
+          for(int iConn = 0; iConn < aConnSlice.size(); iConn++)
+            anArray[iConn] = aConnSlice[iConn] - 1;
+        }
+      }
+    }
+    break;
+    case SALOME_MED::MED_POLYHEDRA:
+    {
+      MEDPolyhedraConnectivity aConn( aMedMesh );
+      int aNbElem = aConn.GetNbElem();
+      if (aNbElem > 0) {
+        VISU::PSubMeshImpl aSubMesh = aGeom2SubMesh[aEGeom](new VISU::TCSubMesh());
+        aSubMesh->myNbCells = aNbElem;
+        aSubMesh->myCellsSize = aConn.GetCellSize();
+
+        VISU::TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
+        aCell2Connect.resize(aNbElem);
+
+        TConnSet aConnectSet;
+        for(int iElem = 0; iElem < aNbElem; iElem++){
+          if(aConn.GetUniqueConn(iElem, aConnectSet)){
+            int aNbConn = aConnectSet.size();
+            VISU::TConnect& anArray = aCell2Connect[iElem];
+            anArray.resize(aNbConn);
+            std::set<int>::iterator anIter = aConnectSet.begin();
+            for(int i = 0; anIter != aConnectSet.end(); anIter++, i++)
+              anArray[i] = *anIter - 1;
+          }
+        }
+      }
+    }
+    break;
+    default:
+    {        
+      int aMNbNodes = MEDGeom2NbNodes(aMGeom);
+      int aVNbNodes = VISUGeom2NbNodes(aEGeom);
+      int aNbElem = anInfo->numberOfElements[iGeom];
+      if (aNbElem > 0) {
+        SALOME_MED::long_array_var aConn = 
+          aMedMesh->getConnectivity(SALOME_MED::MED_FULL_INTERLACE,
+                                   SALOME_MED::MED_NODAL,
+                                   aMEntity,
+                                   aMGeom);
+        VISU::PSubMeshImpl aSubMesh = aGeom2SubMesh[aEGeom](new VISU::TCSubMesh());
+
+        aSubMesh->myNbCells = aNbElem;
+        aSubMesh->myCellsSize = aNbElem*(aVNbNodes+1);
+
+        VISU::TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
+        std::vector<int> aConnect(aMNbNodes);
+        int aNbConnForElem = aConn->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] = aConn[kj+k] - 1;
+
+          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;
+          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;
+          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;
+          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 :
+          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;
+          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:
+          case SALOME_MED::MED_PYRA13:
 #endif
-       case SALOME_MED::MED_PYRA5 :
-         anArray[0] = aConnect[0];
-         anArray[1] = aConnect[3];  
-         anArray[2] = aConnect[2];
-         anArray[3] = aConnect[1];  
-         anArray[4] = aConnect[4];
-         break;
-       default:
-         for (int k = 0; k < aVNbNodes; k++) 
-           anArray[k] = aConnect[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);
+          case SALOME_MED::MED_PYRA5 :
+            anArray[0] = aConnect[0];
+            anArray[1] = aConnect[3];  
+            anArray[2] = aConnect[2];
+            anArray[3] = aConnect[1];  
+            anArray[4] = aConnect[4];
+            break;
+          default:
+            for (int k = 0; k < aVNbNodes; k++) 
+              anArray[k] = aConnect[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);
+        } // loop on elements
       }
-      //Workaround for MED Component data structure
+    }} // switch( aMGeom )
+    VISU::TGeom2SubMesh::iterator anIter = aGeom2SubMesh.find(aEGeom);
+    if(anIter != aGeom2SubMesh.end()){
+      const VISU::PSubMeshImpl& aSubMesh = anIter->second;
+      const VISU::TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
       int aSize = aCell2Connect.size();
-      if(MYDEBUG) MESSAGE("LoadCellsOnEntity - aCounter = "<<aCounter<<"; aSize = "<<aSize);
-      theMeshOnEntity->myCellsFirstIndex[aMGeom] = TCMeshOnEntity::TIndexAndSize(aCounter,aSize);
+      if(MYDEBUG) MESSAGE("LoadCellsOnEntity - aCounter = "<<aCounter<<"; aSize = "<<aSize<<"; aMGeom = "<<aMGeom);
+      aFirstIndex[aMGeom] = VISU::TIndexAndSize(aCounter, aSize);
       aCounter += aSize;
     }
-  }
+  } //loop on types
+
+  // Dump result connectivity
+// #ifdef _DEBUG_
+//   TGeom2SubMesh::iterator geom_sm = aGeom2SubMesh.begin();
+//   for ( ; geom_sm!=aGeom2SubMesh.end(); ++geom_sm ) {
+//     cout << "TYPE: " << geom_sm->first << endl;
+//     PSubMeshImpl aSubMesh = geom_sm->second;
+//     TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
+//     TCell2Connect::iterator id_conn = aCell2Connect.begin();
+//     for ( int i = 0; id_conn !=aCell2Connect.end(); ++id_conn ) {
+//       cout << "\t" << i++ << ": [";
+//       TConnect& anArray = *id_conn;
+//       TConnect::iterator n = anArray.begin();
+//       for ( ; n != anArray.end(); ++n )
+//         cout << " " << *n + 1;
+//       cout << " ]"<< endl;
+//     }
+//   }
+// #endif
 
   theMeshOnEntity->myIsDone = true;
 
@@ -1206,7 +1730,6 @@ VISU_MEDConvertor
   if(theFamily->myIsDone) 
     return 0;
 
-  const VISU::TGeom2SubMesh& aGeom2SubMesh = theMeshOnEntity->myGeom2SubMesh;
   SALOME_MED::FAMILY_var aMedFamily = theFamily->myFamily;
   CORBA::Boolean anIsOnAllElements = aMedFamily->isOnAllElements();
   if(!anIsOnAllElements){
@@ -1221,7 +1744,7 @@ VISU_MEDConvertor
       int aNbElem = aCellNumForType->length();
       int aCounter = theMeshOnEntity->myCellsFirstIndex[aMGeom].first;
       int aSize = theMeshOnEntity->myCellsFirstIndex[aMGeom].second;
-      TSubMeshID& aSubMeshID = theFamily->myGeom2SubMeshID[aEGeom]; 
+      VISU::TSubMeshID& aSubMeshID = theFamily->myGeom2SubMeshID[aEGeom]; 
       
       if(MYDEBUG) 
        MESSAGE("LoadCellsOnFamily "<<
@@ -1247,7 +1770,7 @@ VISU_MEDConvertor
       VISU::EGeometry aEGeom = anIter->first;
       const VISU::TSubMeshImpl& aSubMesh = anIter->second;
       const VISU::TCell2Connect& aCell2Connect = aSubMesh.myCell2Connect;
-      TSubMeshID& aSubMeshID = theFamily->myGeom2SubMeshID[aEGeom];
+      VISU::TSubMeshID& aSubMeshID = theFamily->myGeom2SubMeshID[aEGeom];
       int iNumElemEnd = aCell2Connect.size();
       for(int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
        aSubMeshID.push_back(iNumElem);
@@ -1260,67 +1783,54 @@ VISU_MEDConvertor
 }
 
 
-template<class TArray> 
-int 
-ImportField(TArray& theArray, 
+template<class TValueType,
+        class TContainerType> 
+void 
+ImportField(TContainerType& theContainer, 
            VISU::PCMesh theMesh,
            VISU::PCField theField,
            VISU::PCValForTime theValForTime,
            VISU::PCMeshOnEntity theMeshOnEntity)
 {
-  int aNbComp = theField->myNbComp;
-  if(theField->myEntity == NODE_ENTITY){
+  typedef VISU::TTCMEDMeshValue<TValueType, TContainerType> TVMeshValue;
+  vtkIdType aNbComp = theField->myNbComp;
+  if(theField->myEntity == VISU::NODE_ENTITY){
     VISU::EGeometry aEGeom = VISU::ePOINT1;
-    int aNbGauss = theValForTime->GetNbGauss(aEGeom);
-    const TNamedPointCoords& aCoords = theMesh->myNamedPointCoords;
-    int aNbElem = aCoords.GetNbPoints();
+    vtkIdType aNbGauss = theValForTime->GetNbGauss(aEGeom);
+    vtkIdType aNbElem = theMesh->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++];
-       }
-      }
-    }
+    VISU::PMeshValue& aVMeshValue = theValForTime->GetMeshValue(VISU::ePOINT1);
+    TVMeshValue* aMeshValue = new TVMeshValue();
+    aMeshValue->Init(aNbElem, aNbGauss, aNbComp, theContainer, 0);
+    aVMeshValue.reset(aMeshValue);
   }else{
     SALOME_MED::medGeometryElement* aGeomElems;
-    const TEntity& aVEntity = theField->myEntity;
+    const VISU::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);
+      vtkIdType aNbGauss = theValForTime->GetNbGauss(aEGeom);
+      const VISU::TCellsFirstIndex& aCellsFirstIndex = theMeshOnEntity->myCellsFirstIndex;
+      VISU::TCellsFirstIndex::const_iterator aCellsFirstIndexIter = aCellsFirstIndex.find(aMGeom);
       if(aCellsFirstIndexIter != aCellsFirstIndex.end()){
-       const TCMeshOnEntity::TIndexAndSize& aIndexAndSize = aCellsFirstIndexIter->second;
+       const VISU::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];
-         }
-       }
+       vtkIdType aNbElem = aIndexAndSize.second;
+       vtkIdType aStart = aIndexAndSize.first * aNbComp;
+       VISU::PMeshValue& aVMeshValue = theValForTime->GetMeshValue(aEGeom);
+       TVMeshValue* aMeshValue = new TVMeshValue();
+       aMeshValue->Init(aNbElem, aNbGauss, aNbComp, theContainer, aStart);
+       aVMeshValue.reset(aMeshValue);
       }
     }
   }
-  return 1;
 }
 
 int
@@ -1330,30 +1840,46 @@ VISU_MEDConvertor
            VISU::PField theField, 
            VISU::PCValForTime theValForTime)
 {
+  MESSAGE("VISU_MEDConvertor::LoadField");
   //Check on loading already done
-  PIDMapperFilter anIDMapperFilter = theValForTime->myIDMapperFilter;
-  if(anIDMapperFilter->myIsVTKDone) 
+  VISU::PUnstructuredGridIDMapperImpl anUnstructuredGridIDMapper = theValForTime->myUnstructuredGridIDMapper;
+  if(anUnstructuredGridIDMapper->myIsVTKDone) 
     return 0;
   
-  PCProfile aProfile(new TCProfile());
+  VISU::PCProfile aProfile(new VISU::TCProfile());
   aProfile->myIsAll = true;
   theValForTime->myProfile = aProfile;
 
   SALOME_MED::FIELD_var aMEDField = theValForTime->myField;
+
+  SALOME_MED::SUPPORT_var aMEDSupport = aMEDField->getSupport();
+
+  if(aMEDSupport->isOnAllElements()) aProfile->myIsDone = true;
+  
   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);
+    ImportField<CORBA::Double>(anArray,
+                              theMesh,
+                              theField,
+                              theValForTime,
+                              theMeshOnEntity);
   }
+
   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);
+    ImportField<CORBA::Long>(anArray,
+                            theMesh,
+                            theField,
+                            theValForTime,
+                            theMeshOnEntity);
   }
 
-  anIDMapperFilter->myIsVTKDone = true;
+  anUnstructuredGridIDMapper->myIsVTKDone = true;
 
+  MESSAGE("VISU_MEDConvertor::LoadField done");
   return 1;
 }