]> SALOME platform Git repositories - modules/visu.git/blob - src/VISU_I/VISU_CorbaMedConvertor.cxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/visu.git] / src / VISU_I / VISU_CorbaMedConvertor.cxx
1 //  VISU OBJECT : interactive object for VISU entities implementation
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : VISU_CorbaMedConvertor.cxx
25 //  Author : Alexey PETROV
26 //  Module : VISU
27 //  $Header$
28 //  Copyright (C) 2003  CEA/DEN, EDF R&D
29
30 #include "VISU_CorbaMedConvertor.hxx"
31 #include "VISU_ConvertorUtils.hxx"
32
33 #include <vtkCellType.h>
34
35 #include <boost/tuple/tuple.hpp>
36
37 #include "ReceiverFactory.hxx"
38 #include "MED_SliceArray.hxx"
39
40 #define USER_INTERLACE MED_FULL_INTERLACE
41
42 #ifdef _DEBUG_
43 static int MYDEBUG = 0;
44 #else
45 static int MYDEBUG = 0;
46 #endif
47
48 extern "C" {
49   VISU_Convertor* 
50   CreateMEDConvertor(SALOMEDS::SObject_ptr theMedSObject) 
51   {
52     return new VISU_MEDConvertor(theMedSObject);
53   }
54
55   VISU_Convertor* 
56   CreateMEDFieldConvertor(SALOME_MED::FIELD_ptr theField) 
57   {
58     return new VISU_MEDFieldConvertor(theField);
59   }
60 }
61
62 namespace
63 {
64   const int MED_NBR_GEOMETRIE_MAILLE = 17;
65   
66   SALOME_MED::medGeometryElement 
67   CELLGEOM[MED_NBR_GEOMETRIE_MAILLE] = {
68     SALOME_MED::MED_POINT1,
69     SALOME_MED::MED_SEG2,
70     SALOME_MED::MED_SEG3,
71     SALOME_MED::MED_TRIA3,
72     SALOME_MED::MED_QUAD4,
73     SALOME_MED::MED_TRIA6,
74     SALOME_MED::MED_QUAD8,
75     SALOME_MED::MED_TETRA4,
76     SALOME_MED::MED_PYRA5,
77     SALOME_MED::MED_PENTA6,
78     SALOME_MED::MED_HEXA8,
79     SALOME_MED::MED_TETRA10,
80     SALOME_MED::MED_PYRA13,
81     SALOME_MED::MED_PENTA15,
82     SALOME_MED::MED_HEXA20,
83     SALOME_MED::MED_POLYGON,
84     SALOME_MED::MED_POLYHEDRA
85   };
86   
87   const int MED_NBR_GEOMETRIE_FACE = 5;
88   
89   SALOME_MED::medGeometryElement
90   FACEGEOM[MED_NBR_GEOMETRIE_FACE] = {
91     SALOME_MED::MED_TRIA3,
92     SALOME_MED::MED_QUAD4,
93     SALOME_MED::MED_TRIA6,
94     SALOME_MED::MED_QUAD8,
95     SALOME_MED::MED_POLYGON
96   };
97   
98   const int MED_NBR_GEOMETRIE_ARETE = 2;
99   
100   SALOME_MED::medGeometryElement
101   EDGEGEOM[MED_NBR_GEOMETRIE_ARETE] = {
102     SALOME_MED::MED_SEG2,
103     SALOME_MED::MED_SEG3
104   };
105   
106   const int MED_NBR_GEOMETRIE_NODE = 1;
107   
108   SALOME_MED::medGeometryElement
109   NODEGEOM[MED_NBR_GEOMETRIE_NODE] = {
110     SALOME_MED::MED_POINT1,
111   };
112   
113
114   //---------------------------------------------------------------
115   int
116   GetEntity2Geom(const VISU::TEntity& theEntity, 
117                  SALOME_MED::medGeometryElement*& theVector)
118   {
119     switch(theEntity){
120     case VISU::CELL_ENTITY: 
121       theVector = CELLGEOM; 
122       return MED_NBR_GEOMETRIE_MAILLE; 
123     case VISU::FACE_ENTITY: 
124       theVector = FACEGEOM; 
125       return MED_NBR_GEOMETRIE_FACE; 
126     case VISU::EDGE_ENTITY: 
127       theVector = EDGEGEOM; 
128       return MED_NBR_GEOMETRIE_ARETE; 
129     case VISU::NODE_ENTITY: 
130       theVector = NODEGEOM; 
131       return MED_NBR_GEOMETRIE_NODE; 
132     }
133     return -1;
134   }
135   
136
137   //---------------------------------------------------------------
138   int
139   MEDGeom2NbNodes(int theMEDGeomType)
140   { 
141     switch(theMEDGeomType){
142     case SALOME_MED::MED_NONE: 
143       return 0;
144     case SALOME_MED::MED_POINT1: 
145       return 1;
146     case SALOME_MED::MED_SEG2: 
147       return 2;
148     case SALOME_MED::MED_SEG3: 
149       return 3;
150     case SALOME_MED::MED_TRIA3: 
151       return 3;
152     case SALOME_MED::MED_TRIA6: 
153       return 6;
154     case SALOME_MED::MED_QUAD4: 
155       return 4;
156     case SALOME_MED::MED_QUAD8: 
157       return 8;
158     case SALOME_MED::MED_TETRA4: 
159       return 4;
160     case SALOME_MED::MED_TETRA10: 
161       return 10;
162     case SALOME_MED::MED_HEXA8: 
163       return 8;
164     case SALOME_MED::MED_HEXA20: 
165       return 20;
166     case SALOME_MED::MED_PENTA6: 
167       return 6;
168     case SALOME_MED::MED_PENTA15: 
169       return 15;
170     case SALOME_MED::MED_PYRA5: 
171       return 5;
172     case SALOME_MED::MED_PYRA13: 
173       return 13;
174     }
175     return -1;
176   }
177   
178
179   //---------------------------------------------------------------
180   VISU::EGeometry
181   MEDGeom2VISU(SALOME_MED::medGeometryElement theGeom)
182   { 
183     switch(theGeom){
184     case SALOME_MED::MED_POINT1:
185       return VISU::ePOINT1;
186     case SALOME_MED::MED_SEG2: 
187       return VISU::eSEG2;
188     case SALOME_MED::MED_SEG3: 
189       return VISU::eSEG3;
190     case SALOME_MED::MED_TRIA3: 
191       return VISU::eTRIA3;
192     case SALOME_MED::MED_TRIA6: 
193       return VISU::eTRIA6;
194     case SALOME_MED::MED_QUAD4: 
195       return VISU::eQUAD4;
196     case SALOME_MED::MED_QUAD8: 
197       return VISU::eQUAD8;
198     case SALOME_MED::MED_TETRA4: 
199       return VISU::eTETRA4;
200     case SALOME_MED::MED_TETRA10: 
201       return VISU::eTETRA10;
202     case SALOME_MED::MED_HEXA8: 
203       return VISU::eHEXA8;
204     case SALOME_MED::MED_HEXA20: 
205       return VISU::eHEXA20;
206     case SALOME_MED::MED_PENTA6: 
207       return VISU::ePENTA6;
208     case SALOME_MED::MED_PENTA15: 
209       return VISU::ePENTA15;
210     case SALOME_MED::MED_PYRA5: 
211       return VISU::ePYRA5;
212     case SALOME_MED::MED_PYRA13: 
213       return VISU::ePYRA13;
214     case SALOME_MED::MED_POLYGON: 
215       return VISU::ePOLYGONE;
216     case SALOME_MED::MED_POLYHEDRA: 
217       return VISU::ePOLYEDRE;
218     }
219     return VISU::eNONE;
220   }
221   
222   //---------------------------------------------------------------
223   SALOME_MED::medGeometryElement 
224   VISUGeomToMED(int theGeom)
225   { 
226     switch(theGeom){
227     case VISU::ePOINT1: 
228       return SALOME_MED::MED_POINT1;
229     case VISU::eSEG2: 
230       return SALOME_MED::MED_SEG2;
231     case VISU::eTRIA3: 
232       return SALOME_MED::MED_TRIA3;
233     case VISU::eQUAD4: 
234       return SALOME_MED::MED_QUAD4;
235     case VISU::eTETRA4: 
236       return SALOME_MED::MED_TETRA4;
237     case VISU::eHEXA8: 
238       return SALOME_MED::MED_HEXA8;
239     case VISU::ePENTA6: 
240       return SALOME_MED::MED_PENTA6;
241     case VISU::ePYRA5: 
242       return SALOME_MED::MED_PYRA5;
243
244     case VISU::eSEG3: 
245       return SALOME_MED::MED_SEG3;
246     case VISU::eTRIA6: 
247       return SALOME_MED::MED_TRIA6;
248     case VISU::eQUAD8: 
249       return SALOME_MED::MED_QUAD8;
250     case VISU::eTETRA10: 
251       return SALOME_MED::MED_TETRA10;
252     case VISU::eHEXA20: 
253       return SALOME_MED::MED_HEXA20;
254     case VISU::ePENTA15: 
255       return SALOME_MED::MED_PENTA15;
256     case VISU::ePYRA13: 
257       return SALOME_MED::MED_PYRA13;
258     case VISU::ePOLYGONE: 
259       return SALOME_MED::MED_POLYGON;
260     case VISU::ePOLYEDRE: 
261       return  SALOME_MED::MED_POLYHEDRA;
262     }
263     return SALOME_MED::medGeometryElement(-1);
264   }
265
266   //---------------------------------------------------------------
267   SALOME_MED::medGeometryElement 
268   VTKGeomToMED(int theVTKGeomType)
269   { 
270     switch(theVTKGeomType){
271     case VTK_VERTEX: 
272       return SALOME_MED::MED_POINT1;
273     case VTK_LINE: 
274       return SALOME_MED::MED_SEG2;
275     case VTK_TRIANGLE:
276       return SALOME_MED::MED_TRIA3;
277     case VTK_QUAD: 
278       return SALOME_MED::MED_QUAD4;
279     case VTK_TETRA: 
280       return SALOME_MED::MED_TETRA4;
281     case VTK_HEXAHEDRON: 
282       return SALOME_MED::MED_HEXA8;
283     case VTK_WEDGE:
284       return SALOME_MED::MED_PENTA6;
285     case VTK_PYRAMID: 
286       return SALOME_MED::MED_PYRA5;
287     case VTK_POLYGON: 
288       return SALOME_MED::MED_POLYGON;
289     }
290     return SALOME_MED::medGeometryElement(-1);
291   }
292   
293   //---------------------------------------------------------------
294   VISU::TEntity
295   MEDEntityToVTK(SALOME_MED::medEntityMesh theMEDEntity)
296   {
297     switch(theMEDEntity){
298     case SALOME_MED::MED_NODE: 
299       return VISU::NODE_ENTITY;
300     case SALOME_MED::MED_EDGE: 
301       return VISU::EDGE_ENTITY;
302     case SALOME_MED::MED_FACE: 
303       return VISU::FACE_ENTITY;
304     case SALOME_MED::MED_CELL: 
305       return VISU::CELL_ENTITY;
306     }
307     return VISU::TEntity(-1);
308   }
309   
310   //---------------------------------------------------------------
311   SALOME_MED::medEntityMesh 
312   VTKEntityToMED(VISU::TEntity theVTKEntity)
313   {
314     switch(theVTKEntity){
315     case VISU::NODE_ENTITY: 
316       return SALOME_MED::MED_NODE;
317     case VISU::EDGE_ENTITY: 
318       return SALOME_MED::MED_EDGE;
319     case VISU::FACE_ENTITY: 
320       return SALOME_MED::MED_FACE;
321     case VISU::CELL_ENTITY: 
322       return SALOME_MED::MED_CELL;
323     }
324     return SALOME_MED::medEntityMesh(-1);
325   }
326
327   
328   //---------------------------------------------------------------
329   std::string 
330   GetSObjectName(SALOMEDS::SObject_ptr aSObject)
331   {
332     SALOMEDS::GenericAttribute_var anAttr;
333     if (aSObject->FindAttribute(anAttr,"AttributeName")) {
334       SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
335       CORBA::String_var aString = aName->Value();
336       return aString.in();
337     }
338     return "";
339   }
340   
341
342   //---------------------------------------------------------------
343   void 
344   GetCellsSize(vtkIdType& theNbCells, 
345                vtkIdType& theCellsSize,
346                SALOME_MED::MESH_ptr theMEDMesh,
347                const VISU::TEntity& theVEntity)
348   {
349     theNbCells = theCellsSize = 0;
350     if(MYDEBUG) MESSAGE("GetCellsSize - theVEntity = "<<theVEntity);
351     const SALOME_MED::medEntityMesh& aMEntity = VTKEntityToMED(theVEntity);
352     SALOME_MED::MESH::connectivityInfos_var connInfo=theMEDMesh->getConnectGlobal(aMEntity);
353     int iGeomEnd = connInfo->meshTypes.length();
354     for(int iGeom = 0; iGeom < iGeomEnd; iGeom++){
355       int iNumElemEnd = connInfo->numberOfElements[iGeom];
356       if(iNumElemEnd > 0){
357         if(MYDEBUG) MESSAGE("GetCellsSize - iNumElemEnd = "<<iNumElemEnd);
358         theCellsSize += iNumElemEnd + connInfo->nodalConnectivityLength[iGeom];
359         theNbCells += iNumElemEnd;
360       }
361     }
362   }
363   
364   
365   //---------------------------------------------------------------
366   void 
367   GetCellsSize(vtkIdType& theNbCells, 
368                vtkIdType& theCellsSize,
369                SALOME_MED::FAMILY_ptr theMEDFamily)
370   {
371     theNbCells = theCellsSize = 0;
372     SALOME_MED::SUPPORT::supportInfos_var suppInfo=theMEDFamily->getSupportGlobal();
373     int iGeomEnd = suppInfo->types.length();
374     if(MYDEBUG) MESSAGE("GetCellsSize - iGeomEnd = "<<iGeomEnd);
375     for(int iGeom = 0; iGeom < iGeomEnd; iGeom++) {
376       int iNumElemEnd = suppInfo->nbEltTypes[iGeom];
377       if(iNumElemEnd > 0){
378         if(MYDEBUG) MESSAGE("GetCellsSize - iNumElemEnd = "<<iNumElemEnd);
379         theNbCells += iNumElemEnd;
380         theCellsSize += iNumElemEnd + suppInfo->nodalConnectivityLength[iGeom];
381       }
382     }
383   }
384   
385   
386   //---------------------------------------------------------------
387   void
388   GetCellsSize(VISU::PCMesh theMesh, 
389                SALOME_MED::MESH_ptr theMEDMesh, 
390                const VISU::TEntity& theEntity)
391   {
392     VISU::TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap;
393     VISU::PCMeshOnEntity aMeshOnEntity = aMeshOnEntityMap[theEntity];
394     if(theEntity == VISU::NODE_ENTITY){
395       aMeshOnEntity->myNbCells = theMesh->myNbPoints;
396       aMeshOnEntity->myCellsSize = 2*theMesh->myNbPoints;
397     }else{
398       GetCellsSize(aMeshOnEntity->myNbCells,aMeshOnEntity->myCellsSize,theMEDMesh,theEntity);
399     }
400   }
401  
402
403   //---------------------------------------------------------------
404   VISU::PCMeshOnEntity 
405   InitMeshOnEntity(const VISU::PCMesh& theMesh,
406                    const VISU::TEntity& theEntity,
407                    const VISU::PCMeshOnEntity& theMeshOnEntity)
408   {
409     VISU::PCMeshOnEntity aMeshOnEntity;
410     VISU::TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap;
411     VISU::TMeshOnEntityMap::const_iterator anIter = aMeshOnEntityMap.find(theEntity);
412     if(anIter == aMeshOnEntityMap.end()){
413       aMeshOnEntity.reset(new VISU::TCMeshOnEntity());
414       *aMeshOnEntity = *theMeshOnEntity;
415       aMeshOnEntity->myEntity = theEntity;
416       aMeshOnEntityMap[theEntity] = aMeshOnEntity;
417     }else
418       aMeshOnEntity = anIter->second;
419
420     GetCellsSize(theMesh,theMesh->myMesh,theEntity);
421
422     return aMeshOnEntity;
423   }
424
425   
426   VISU::PCSubProfile
427   CrSubProfile(const VISU::PCMesh theMesh,
428                const VISU::PCField theField,
429                const VISU::TCMeshOnEntity& theMeshOnEntity,
430                SALOME_MED::medGeometryElement theMGeom,
431                int theNbElems)
432   {
433     if (MYDEBUG) MESSAGE("CrSubProfile");
434     VISU::EGeometry aEGeom = MEDGeom2VISU(theMGeom);
435     vtkIdType aVNbNodes = VISUGeom2NbNodes(aEGeom);
436
437     VISU::PCSubProfile aSubProfile(new VISU::TCSubProfile());
438     aSubProfile->myGeom = aEGeom;
439     aSubProfile->myMGeom = theMGeom;
440     aSubProfile->myStatus = VISU::eAddAll;
441     if(MYDEBUG) MESSAGE("theMGeom = "<<theMGeom);
442     const VISU::TCellsFirstIndex& aCellsFirstIndex = theMeshOnEntity.myCellsFirstIndex;
443     VISU::TCellsFirstIndex::const_iterator aTimeStampIter = aCellsFirstIndex.find(theMGeom);
444     if(aTimeStampIter == (theMeshOnEntity.myCellsFirstIndex).end() && 
445        theMGeom != SALOME_MED::MED_POINT1)
446       aSubProfile->myStatus = VISU::eRemoveAll;
447     else if(aTimeStampIter == aCellsFirstIndex.end() && theMGeom == SALOME_MED::MED_POINT1){
448       if(theNbElems > 0){
449         aSubProfile->myName = "";
450         aSubProfile->myStatus = VISU::eAddPart;
451         
452         aSubProfile->myNbCells = theNbElems;
453         aSubProfile->myCellsSize = aSubProfile->myNbCells;
454       }
455     }else{
456         if(theNbElems > 0){
457           aSubProfile->myName = "";
458           aSubProfile->myStatus = VISU::eAddPart;
459           
460           aSubProfile->myNbCells = theNbElems;
461           aSubProfile->myCellsSize = aSubProfile->myNbCells*aVNbNodes;
462         }
463       }
464     
465     if (MYDEBUG) MESSAGE("CrSubProfile done");
466     return aSubProfile;
467   }
468
469   VISU::TProfileKey
470   GetProfileKey(const VISU::PCMesh theMesh,
471                 const VISU::PCField theField,
472                 const VISU::PCValForTime theValForTime,
473                 const VISU::TCMeshOnEntity& theMeshOnEntity)
474   {
475     if (MYDEBUG) MESSAGE("GetProfileKey");
476
477     VISU::TProfileKey aProfileKey;
478
479     const VISU::TCellsFirstIndex& aFirstIndex = theMeshOnEntity.myCellsFirstIndex;
480     VISU::TCellsFirstIndex::const_iterator anIter = aFirstIndex.begin();
481     SALOME_MED::SUPPORT_var aSupport = theValForTime->myField->getSupport();
482     int aNbElems = 0;
483     if(anIter == aFirstIndex.end() && aSupport->getEntity() == SALOME_MED::MED_NODE){
484       SALOME_MED::medGeometryElement aMGeom = SALOME_MED::MED_POINT1;
485       try{
486         aNbElems = aSupport->getNumberOfElements(SALOME_MED::MED_NONE);
487         if(MYDEBUG)MESSAGE("aMGeom="<<aMGeom<<"   aNbElems="<<aNbElems);
488       }catch(...){
489         MESSAGE("Error in theValForTime->myField->getSupport()->getNumberOfElements(aMGeom);");
490       }
491         
492       VISU::PCSubProfile aSubProfile = CrSubProfile(theMesh,
493                                                     theField,
494                                                     theMeshOnEntity,
495                                                     aMGeom,
496                                                     aNbElems);
497       aProfileKey.insert(aSubProfile);
498     }
499     
500     for(; anIter != aFirstIndex.end(); anIter++){
501       SALOME_MED::medGeometryElement aMGeom = anIter->first;
502       try{
503         aNbElems = aSupport->getNumberOfElements(aMGeom);
504         if(MYDEBUG)MESSAGE("aMGeom="<<aMGeom<<"   aNbElems="<<aNbElems);
505       } catch(...){
506         MESSAGE("Error in theValForTime->myField->getSupport()->getNumberOfElements(aMGeom);");
507         continue;
508       }
509       VISU::PCSubProfile aSubProfile = CrSubProfile(theMesh,
510                                                     theField,
511                                                     theMeshOnEntity,
512                                                     aMGeom,
513                                                     aNbElems);
514       aProfileKey.insert(aSubProfile);
515     }
516
517     if (MYDEBUG) MESSAGE("GetProfileKey done");
518     return aProfileKey;
519   }
520   
521   void
522   InitProfile(VISU::PCMesh theMesh,
523               VISU::PCField theField,
524               VISU::PCValForTime theValForTime,
525               VISU::TCMeshOnEntity& theMeshOnEntity)
526   {
527     if (MYDEBUG) MESSAGE("InitProfile");
528     
529     VISU::TProfileMap& aProfileMap = theMeshOnEntity.myProfileMap;
530
531     VISU::TProfileKey aProfileKey = GetProfileKey(theMesh,
532                                                   theField,
533                                                   theValForTime,
534                                                   theMeshOnEntity);
535     
536     VISU::TProfileMap::const_iterator anIter = aProfileMap.find(aProfileKey);
537     if(anIter != aProfileMap.end()){
538       theValForTime->myProfile = anIter->second;
539       if(MYDEBUG) MESSAGE("aProfileMap.find(aProfileKey) aProfile->myGeom=");
540     }else{
541       VISU::PCProfile aProfile(new VISU::TCProfile());
542       VISU::TGeom2SubProfile& aGeom2SubProfile = aProfile->myGeom2SubProfile;
543       
544       VISU::TProfileKey::const_iterator anIter = aProfileKey.begin();
545       for(; anIter != aProfileKey.end(); anIter++){
546         VISU::PCSubProfile aSubProfile(*anIter);
547         
548         if(aProfile->myIsAll && aSubProfile->myStatus != VISU::eAddAll)
549           aProfile->myIsAll = false;
550         
551         VISU::EGeometry aEGeom = aSubProfile->myGeom;
552         aGeom2SubProfile[aEGeom] = aSubProfile;
553       }
554       
555       aProfileMap[aProfileKey] = aProfile;
556       theValForTime->myProfile = aProfile;
557     }
558     if (MYDEBUG) MESSAGE("InitProfile done");
559   }
560
561   void
562   LoadProfile(VISU::PCMesh theMesh,
563               VISU::PCField theField,
564               VISU::PCValForTime theValForTime,
565               VISU::PCMeshOnEntity theMeshOnEntity)
566   {
567     VISU::PCProfile aProfile = theValForTime->myProfile;
568     if (MYDEBUG) MESSAGE("LoadProfile aProfile->myIsDone="<<aProfile->myIsDone);
569     if(aProfile->myIsDone)
570       return;
571     
572     const VISU::TGeom2SubProfile& aGeom2SubProfile = aProfile->myGeom2SubProfile;
573     VISU::TGeom2SubProfile::const_iterator aGeom2SubProfileIter = aGeom2SubProfile.begin();
574     if(aGeom2SubProfileIter == aGeom2SubProfile.end()){
575       MESSAGE("Warning! No geom 2 sub profile");
576     }
577     SALOME_MED::SUPPORT_var aSupport = theValForTime->myField->getSupport();
578     for(; aGeom2SubProfileIter != aGeom2SubProfile.end(); aGeom2SubProfileIter++){
579       VISU::EGeometry aEGeom = aGeom2SubProfileIter->first;
580       SALOME_MED::medGeometryElement aMGeom = VISUGeomToMED(aEGeom);
581       VISU::PCSubProfile aSubProfile = aGeom2SubProfileIter->second;
582       SALOME_MED::long_array_var aGeom2ProfileIds;
583       std::vector<int> aGeom2Profile;
584       if(!aSupport->isOnAllElements()){
585         try{
586           if(aMGeom == SALOME_MED::MED_POINT1)
587             aGeom2ProfileIds = aSupport->getNumberFromFile(SALOME_MED::MED_NONE);
588           else
589             aGeom2ProfileIds = aSupport->getNumberFromFile(aMGeom);
590           int aLen = aGeom2ProfileIds->length();
591           if(MYDEBUG) MESSAGE(" - aMGeom="<<aMGeom<<"; aNbCells="<<aLen);
592           for(int i = 0; i < aLen; i++){
593             int anId = aGeom2ProfileIds[i];
594             aGeom2Profile.push_back(anId);
595             if(MYDEBUG) cout << "------------------------------->" << anId << endl;
596           }
597           if(MYDEBUG) cout << endl;
598         } catch(...) {
599           continue;
600         }
601       } else {
602         SALOME_MED::medEntityMesh aMEntity = aSupport->getEntity();
603         int aNbElems = theMesh->myMesh->getNumberOfElements(aMEntity,aMGeom);
604         for(int i = 0; i < aNbElems; i++) 
605           aGeom2Profile.push_back(i+1);
606       }
607       if(aGeom2Profile.size()>0){
608         VISU::TSubMeshID& aSubMeshID = aSubProfile->mySubMeshID;
609         int aSize = aGeom2Profile.size();
610         aSubMeshID.resize(aSize);
611         for(int anId = 0; anId < aSize; anId++){
612           aSubMeshID[anId] = aGeom2Profile[anId] - 1;
613         }
614       }
615     }
616     
617     aProfile->myIsDone = true;
618     if (MYDEBUG) MESSAGE("LoadProfile done");
619   }
620 }
621
622
623 //---------------------------------------------------------------
624 VISU_Convertor* 
625 VISU_MEDFieldConvertor
626 ::Build()
627 {
628   if(myField->_is_nil()) 
629     throw std::runtime_error("VISU_MEDFieldConvertor::Build >> myField->_is_nil() !!!");
630   
631   SALOME_MED::SUPPORT_var aMEDSupport = myField->getSupport();
632   if(aMEDSupport->_is_nil()) 
633     throw std::runtime_error("VISU_MEDFieldConvertor::Build >> aMEDSupport->_is_nil() !!!");
634
635   SALOME_MED::medEntityMesh aMEntity = aMEDSupport->getEntity();
636   VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
637   SALOME_MED::MESH_var aMEDMesh = aMEDSupport->getMesh();
638   if(aMEDMesh->_is_nil()) 
639     throw std::runtime_error("VISU_MEDFieldConvertor::Build >> aMEDMesh->_is_nil() !!!");
640
641   CORBA::String_var aMeshName = aMEDMesh->getName();
642   CORBA::String_var aFieldName = myField->getName();
643
644   VISU::PCMesh aMesh = myMeshMap[aMeshName.in()](new VISU::TCMesh());
645   aMesh->myNamedPointCoords(new VISU::TNamedPointCoords());
646   aMesh->myNbPoints = aMEDMesh->getNumberOfNodes();
647   aMesh->myDim = aMEDMesh->getSpaceDimension();
648   aMesh->myName = aMeshName.in();
649   aMesh->myMesh = aMEDMesh;
650
651   if(MYDEBUG) MESSAGE("VISU_MEDFieldConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh->myDim);
652
653   VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
654   VISU::PCMeshOnEntity aMeshOnEntity = aMeshOnEntityMap[aVEntity](new VISU::TCMeshOnEntity());
655   aMeshOnEntity->myEntity = aVEntity;
656   aMeshOnEntity->myMeshName = aMeshName.in();
657   aMeshOnEntity->mySupport = aMEDSupport;
658
659   if(aVEntity == VISU::NODE_ENTITY)
660     ::InitMeshOnEntity(aMesh, VISU::CELL_ENTITY, aMeshOnEntity);
661   else
662     ::InitMeshOnEntity(aMesh, VISU::NODE_ENTITY, aMeshOnEntity);
663
664   ::GetCellsSize(aMesh, aMEDMesh, aVEntity);
665
666   VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
667   VISU::PCField aField = aFieldMap[aFieldName.in()](new VISU::TCField());
668   aField->myId = myField->getOrderNumber();
669   aField->myName = aFieldName.in();
670   aField->myEntity = aVEntity;
671   aField->myMeshName = aMeshName.in();
672   aField->myDataSize = aMeshOnEntity->myNbCells * aField->myNbComp;
673
674   vtkIdType aDataType = VTK_DOUBLE;
675   SALOME_MED::FIELDDOUBLE_ptr aFieldDouble = SALOME_MED::FIELDDOUBLE::_narrow(myField);
676   if(aFieldDouble->_is_nil()) {
677     // PAL18313: Mandriva 64 porting: CRASH at creating presentation on "Import Structure".
678     if (sizeof(long) == 4 ) // Size of CORBA::Long is always 4 (see CORBA_basetypes.h)
679       aDataType = VTK_LONG;
680     else if (sizeof(int) == 4)
681       aDataType = VTK_INT;
682     else {
683       throw std::runtime_error("Can't map CORBA::Long to a VTK type");
684     }
685   }
686   aField->Init(myField->getNumberOfComponents(), aDataType);
687
688   if(MYDEBUG) MESSAGE("VISU_MEDFieldConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh->myDim);
689
690   VISU::TValField& aValField = aField->myValField;
691   int anId = myField->getIterationNumber();
692   VISU::PCValForTime aValForTime = aValField[anId](new VISU::TCValForTime());
693   aValForTime->myId = anId;
694   CORBA::Double aDT = myField->getTime();
695   aValForTime->myTime = VISU::TTime(aDT,"");
696   aValForTime->myField = myField;
697
698   if(MYDEBUG) 
699     MESSAGE("VISU_MEDFieldConvertor::Build - aFieldName = '"<<aFieldName<<
700             "'; myId = "<<anId<<"; myTime = "<<aDT);
701
702   return this;
703 }
704
705
706 //---------------------------------------------------------------
707 VISU_Convertor* 
708 VISU_MEDConvertor
709 ::Build() 
710 {
711   if(mySObject->_is_nil()) 
712     throw std::runtime_error("VISU_MEDConvertor::Build >> mySObject->_is_nil() !!!");
713   SALOMEDS::Study_var aStudy = mySObject->GetStudy();
714
715   CORBA::Object_var aMedObject = VISU::SObjectToObject(mySObject);
716   if(!CORBA::is_nil(aMedObject)){
717     SALOME_MED::MED_var aMED = SALOME_MED::MED::_narrow(aMedObject);
718     return Build(aMED);
719   }
720
721   SALOMEDS::ChildIterator_var aTimeStampIterator = aStudy->NewChildIterator(mySObject);
722   return Build(aTimeStampIterator);
723 }
724
725
726 namespace
727 {
728   using namespace boost;
729
730   //---------------------------------------------------------------
731   struct TSObjectByName
732   {
733     std::string myName;
734     typedef tuple<SALOMEDS::SObject_var> TRet;
735
736     TSObjectByName(const std::string& theName):
737       myName(theName)
738     {}
739
740     TRet operator()(SALOMEDS::SObject_ptr theSObj, bool& theIsSuccess)
741     {
742       SALOMEDS::GenericAttribute_var anAttr;
743       if(theSObj->FindAttribute(anAttr,"AttributeName")){
744         SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
745         CORBA::String_var aValue = aName->Value();
746         theIsSuccess = (myName == aValue.in());
747         if(theIsSuccess)
748           return TRet(SALOMEDS::SObject::_duplicate(theSObj));
749       }
750       return TRet();
751     }
752
753   };
754
755
756   //---------------------------------------------------------------
757   struct TMeshByName
758   {
759     std::string myName;
760     typedef tuple<SALOME_MED::MESH_var,SALOMEDS::SObject_var> TRet;
761
762     TMeshByName(const std::string& theName):
763       myName(theName)
764     {}
765
766     TRet operator()(SALOMEDS::SObject_ptr theSObj, bool& theIsSuccess)
767     {
768       CORBA::Object_var anObj = VISU::SObjectToObject(theSObj);
769       if(!CORBA::is_nil(anObj)){
770         SALOME_MED::MESH_var aMesh = SALOME_MED::MESH::_narrow(anObj);
771         if(!CORBA::is_nil(aMesh)){
772           CORBA::String_var aName = aMesh->getName();
773           theIsSuccess = (myName == aName.in());
774           if(theIsSuccess)
775             return TRet(aMesh,SALOMEDS::SObject::_duplicate(theSObj));
776         }
777       }
778       return TRet();
779     }
780   };
781
782
783   //---------------------------------------------------------------
784   template<typename TFun>
785   typename TFun::TRet
786   Find(SALOMEDS::SObject_ptr theStartSObj, 
787        SALOMEDS::Study_ptr theStudy,
788        TFun theFun,
789        bool& theIsSuccess,
790        bool theIsAllLevels = true)
791   {
792     SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator(theStartSObj);
793     anIter->InitEx(theIsAllLevels);
794     for(; anIter->More(); anIter->Next()){
795       SALOMEDS::SObject_var aSObj = anIter->Value();
796       typename TFun::TRet aRet = theFun(aSObj,theIsSuccess);
797       if(theIsSuccess)
798         return aRet;
799     }
800     return typename TFun::TRet();
801   }
802
803 }
804
805
806 //---------------------------------------------------------------
807 VISU_Convertor* 
808 VISU_MEDConvertor
809 ::Build(SALOME_MED::MED_ptr theMED)
810 {
811   if(CORBA::is_nil(theMED)) 
812     return NULL;
813
814   CORBA::Long aNbMeshes = theMED->getNumberOfMeshes();
815   SALOME_MED::string_array_var aMeshNames = theMED->getMeshNames();
816   if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aNbMeshes = "<<aNbMeshes);
817
818   SALOMEDS::Study_var aStudy = mySObject->GetStudy();
819   SALOMEDS::SObject_var aMedCompSObj = mySObject->GetFather();
820
821   bool anIsSuccess = false;
822   TSObjectByName::TRet aSObjectByNameRet = 
823     Find(aMedCompSObj,aStudy,TSObjectByName("MEDMESH"),anIsSuccess);
824   if(MYDEBUG) 
825     MESSAGE("VISU_MEDConvertor::Build - Find ('"<<"MEDMESH"<<"') = "<<anIsSuccess);
826   if(anIsSuccess){
827     SALOMEDS::SObject_var aMeshesSObj = boost::get<0>(aSObjectByNameRet);
828     for(int iMesh = 0; iMesh < aNbMeshes; iMesh++){
829       anIsSuccess = false;
830       CORBA::String_var aMeshName = aMeshNames[iMesh];
831       TMeshByName::TRet aMeshByNameRet = 
832         Find(aMeshesSObj,aStudy,TMeshByName(aMeshName.in()),anIsSuccess);
833       if(MYDEBUG) 
834         MESSAGE("VISU_MEDConvertor::Build - Find aMeshName('"<<aMeshName.in()<<"') = "<<anIsSuccess);
835       if(!anIsSuccess)
836         continue;
837
838       VISU::PCMesh aMesh = myMeshMap[aMeshName.in()](new VISU::TCMesh());
839       SALOME_MED::MESH_var aMEDMesh = boost::get<0>(aMeshByNameRet);
840       aMesh->myNamedPointCoords(new VISU::TNamedPointCoords());
841       aMesh->myNbPoints = aMEDMesh->getNumberOfNodes();
842       aMesh->myDim = aMEDMesh->getSpaceDimension();
843       aMesh->myName = aMeshName.in();
844       aMesh->myMesh = aMEDMesh;
845
846       if(MYDEBUG) 
847         MESSAGE("VISU_MEDConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh->myDim);
848
849       std::string aName = aMeshName.in();
850       std::replace(aName.begin(),aName.end(),' ','_');
851
852       anIsSuccess = false;
853       std::ostringstream aStream;
854       aStream<<"MEDSUPPORTS_OF_"<<aName;
855       std::string aSupportsName(aStream.str());
856       TSObjectByName::TRet aSObjectByNameRet = 
857         Find(aMeshesSObj,aStudy,TSObjectByName(aSupportsName.c_str()),anIsSuccess);
858       if(MYDEBUG) 
859         MESSAGE("VISU_MEDConvertor::Build - Find aSupportsName('"<<aSupportsName<<"') = "<<anIsSuccess);
860       if(!anIsSuccess)
861         continue;
862
863       VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
864       SALOMEDS::SObject_var aSupportsSObj = boost::get<0>(aSObjectByNameRet);
865       SALOMEDS::ChildIterator_var aSupportIterator = aStudy->NewChildIterator(aSupportsSObj);
866
867       // Fill all MeshOnEntity
868       aSupportIterator->InitEx(true);
869       for(; aSupportIterator->More(); aSupportIterator->Next()){
870         SALOMEDS::SObject_var aSupportSObj = aSupportIterator->Value();
871         
872         CORBA::Object_var aMedSupport = VISU::SObjectToObject(aSupportSObj);
873         if(CORBA::is_nil(aMedSupport)) 
874           continue;
875         
876         SALOME_MED::SUPPORT_var aMEDSupport = SALOME_MED::SUPPORT::_narrow(aMedSupport); 
877         if(aMEDSupport->_is_nil()) 
878           continue;
879         
880         SALOME_MED::MESH_var aMeshOnSupport = aMEDSupport->getMesh();
881         SALOME_MED::medEntityMesh aMEntity = aMEDSupport->getEntity();
882         VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
883         CORBA::String_var aSupportName = aMEDSupport->getName();
884         
885         if(aMEDSupport->isOnAllElements() && strcmp(aSupportName.in(),"SupportOnAll_MED_") > 0){
886           if(MYDEBUG) 
887             MESSAGE("VISU_MEDConvertor::Build - Support isOnAllElements = '"<<aSupportName<<
888                     "' aVEntity = "<<aVEntity);
889           int aNbCells, aCellsSize;
890           //Check, if there is any data on the support?
891           if(aVEntity == VISU::NODE_ENTITY){
892             aMesh->myNbPoints = aMeshOnSupport->getNumberOfNodes();
893             aNbCells = aMesh->myNbPoints;
894             aCellsSize = 2*aMesh->myNbPoints;
895           }else
896             ::GetCellsSize(aNbCells,aCellsSize,aMeshOnSupport,aVEntity);
897           
898           if(aNbCells > 0){
899             if(aMeshOnEntityMap.find(aVEntity) == aMeshOnEntityMap.end()){
900               VISU::PCMeshOnEntity aMeshOnEntity(new VISU::TCMeshOnEntity());
901               aMeshOnEntity->myMeshName = aMeshName.in();
902               aMeshOnEntity->myEntity = aVEntity;
903               aMeshOnEntity->myNbCells = aNbCells;
904               aMeshOnEntity->myCellsSize = aCellsSize;
905               aMeshOnEntity->mySupport = aMEDSupport;
906               aMeshOnEntityMap[aVEntity] = aMeshOnEntity;
907             }
908           }
909         }
910       }
911
912       // Fill all Family
913       aSupportIterator->InitEx(true);
914       for(; aSupportIterator->More(); aSupportIterator->Next()){
915         SALOMEDS::SObject_var aSupportSObj = aSupportIterator->Value();
916         
917         CORBA::Object_var aMedSupport = VISU::SObjectToObject(aSupportSObj);
918         if(CORBA::is_nil(aMedSupport)) 
919           continue;
920         
921         SALOME_MED::SUPPORT_var aMEDSupport = SALOME_MED::SUPPORT::_narrow(aMedSupport); 
922         if(aMEDSupport->_is_nil()) 
923           continue;
924         
925         SALOME_MED::MESH_var aMeshOnSupport = aMEDSupport->getMesh();
926         SALOME_MED::medEntityMesh aMEntity = aMEDSupport->getEntity();
927         VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
928         CORBA::String_var aSupportName = aMEDSupport->getName();
929         
930         SALOME_MED::FAMILY_var aMEDFamily = SALOME_MED::FAMILY::_narrow(aMedSupport);
931         if(!aMEDFamily->_is_nil()) {
932           VISU::TMeshOnEntityMap::iterator aMeshOnEntityMapIter = aMeshOnEntityMap.find(aVEntity);
933           if(aMeshOnEntityMapIter == aMeshOnEntityMap.end())
934             continue;
935           VISU::PCMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
936
937           int aNbCells = aMeshOnEntity->myNbCells, aCellsSize = aMeshOnEntity->myCellsSize;
938           CORBA::Boolean anIsOnAllElements = aMEDSupport->isOnAllElements();
939           if(!anIsOnAllElements)
940             ::GetCellsSize(aNbCells,aCellsSize,aMEDFamily);
941
942           if(MYDEBUG) 
943             MESSAGE("VISU_MEDConvertor::Build "<<
944                     "- aFamily = '"<<aSupportName<<"'"<<
945                     "; anIsOnAllElements = "<<anIsOnAllElements<<
946                     "; aVEntity = "<<aVEntity<<
947                     "; aNbCells = "<<aNbCells);
948
949           if(aNbCells > 0){
950             VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
951             VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.find(aSupportName.in());
952             if(aFamilyMapIter == aFamilyMap.end()){
953               VISU::PCFamily aFamily(new VISU::TCFamily());
954               aFamily->myEntity = aVEntity;
955               aFamily->myNbCells = aNbCells;
956               aFamily->myCellsSize = aCellsSize;
957               aFamily->myId = aMEDFamily->getIdentifier();
958               aFamily->myName = aSupportName.in();
959               aFamily->myFamily = aMEDFamily;
960               aFamilyMap[aSupportName.in()] = aFamily;
961             }
962           }
963         }
964       }
965         
966       // Fill all Groups
967       aSupportIterator->InitEx(true);
968       for(; aSupportIterator->More(); aSupportIterator->Next()){
969         SALOMEDS::SObject_var aSupportSObj = aSupportIterator->Value();
970         
971         CORBA::Object_var aMedSupport = VISU::SObjectToObject(aSupportSObj);
972         if(CORBA::is_nil(aMedSupport)) 
973           continue;
974         
975         SALOME_MED::SUPPORT_var aMEDSupport = SALOME_MED::SUPPORT::_narrow(aMedSupport); 
976         if(aMEDSupport->_is_nil()) 
977           continue;
978         
979         SALOME_MED::MESH_var aMeshOnSupport = aMEDSupport->getMesh();
980         SALOME_MED::medEntityMesh aMEntity = aMEDSupport->getEntity();
981         VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
982         CORBA::String_var aSupportName = aMEDSupport->getName();
983         
984         SALOME_MED::GROUP_var aMEDGroup = SALOME_MED::GROUP::_narrow(aMedSupport);
985         if(!aMEDGroup->_is_nil()){
986           CORBA::Boolean anIsOnAllElements = aMEDSupport->isOnAllElements();
987
988           if(MYDEBUG) 
989             MESSAGE("VISU_MEDConvertor::Build "<<
990                     "- aGroup = '"<<aSupportName<<"'"<<
991                     "; anIsOnAllElements = "<<anIsOnAllElements<<
992                     "; aVEntity = "<<aVEntity);
993
994           VISU::PCGroup aGroup(new VISU::TCGroup());
995           aGroup->myGroup = aMEDGroup;
996           VISU::TFamilySet& aFamilySet = aGroup->myFamilySet;
997           
998           SALOME_MED::Family_array_var aFamilies = aMEDGroup->getFamilies();
999           int iFamilyEnd = aFamilies->length();
1000           for(int iFamaily = 0; iFamaily < iFamilyEnd; iFamaily++){
1001             SALOME_MED::FAMILY_var aMEDFamily = aFamilies[iFamaily];
1002             CORBA::String_var aFamilyName = aMEDFamily->getName();
1003             TFindFamilyOnEntity aFindFamilyOnEntity = 
1004               FindFamilyOnEntity(aMeshName.in(), aVEntity, aFamilyName.in());
1005             VISU::PCFamily aFamily = boost::get<2>(aFindFamilyOnEntity);
1006             if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aGroup - aFamilyName = '"<<aFamilyName.in()<<"' = "<<bool(aFamily));
1007             if(aFamily){
1008               aFamilySet.insert(aFamily);
1009             }
1010           }
1011           
1012           if(!aFamilySet.empty()){
1013             VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
1014             aGroupMap[aSupportName.in()] = aGroup;
1015           }
1016
1017         }
1018       }
1019     }
1020   }
1021
1022   anIsSuccess = false;
1023   aSObjectByNameRet = Find(aMedCompSObj,aStudy,TSObjectByName("MEDFIELD"),anIsSuccess);
1024   if(anIsSuccess){
1025     SALOMEDS::SObject_var aFieldsSObj = boost::get<0>(aSObjectByNameRet);
1026     if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - MEDFIELD found.");
1027     SALOMEDS::ChildIterator_var aFieldIterator = aStudy->NewChildIterator(aFieldsSObj);
1028     for(int iField = 0; aFieldIterator->More(); aFieldIterator->Next(), iField++){
1029       SALOMEDS::SObject_var aFieldSObj = aFieldIterator->Value();
1030       if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aFieldName = '"<<GetSObjectName(aFieldSObj)<<"'");
1031       SALOMEDS::ChildIterator_var aTimeStampIterator = aStudy->NewChildIterator(aFieldSObj);
1032       for(; aTimeStampIterator->More(); aTimeStampIterator->Next()){
1033         SALOMEDS::SObject_var aTimeStampSObj = aTimeStampIterator->Value();
1034         if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aTimeStampSObj = '"<<GetSObjectName(aTimeStampSObj)<<"'");
1035         CORBA::Object_var aMedField = VISU::SObjectToObject(aTimeStampSObj);
1036         if(CORBA::is_nil(aMedField)) 
1037           continue;
1038
1039         SALOME_MED::FIELD_var aMEDField = SALOME_MED::FIELD::_narrow(aMedField);
1040         if(aMEDField->_is_nil()) 
1041           continue;
1042
1043         SALOME_MED::SUPPORT_var aMEDSupport = aMEDField->getSupport();
1044         if(aMEDSupport->_is_nil()) 
1045           continue;
1046
1047         SALOME_MED::medEntityMesh aMEntity = aMEDSupport->getEntity();
1048         VISU::TEntity anEntity = MEDEntityToVTK(aMEntity);
1049         SALOME_MED::MESH_var aMEDMesh = aMEDSupport->getMesh();
1050         if(aMEDMesh->_is_nil()) 
1051           continue;
1052
1053         CORBA::String_var aMeshName = aMEDMesh->getName();
1054         CORBA::String_var aFieldName = aMEDField->getName();
1055         
1056         VISU::TMeshMap::iterator aMeshMapIter = myMeshMap.find(aMeshName.in());
1057         if(aMeshMapIter == myMeshMap.end())
1058           continue;
1059
1060         VISU::PCMesh aMesh = aMeshMapIter->second;
1061         VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
1062         VISU::TMeshOnEntityMap::iterator aMeshOnEntityMapIter = aMeshOnEntityMap.find(anEntity);
1063         if(aMeshOnEntityMapIter == aMeshOnEntityMap.end())
1064           continue;
1065
1066         VISU::PCMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
1067         VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
1068         VISU::TFieldMap::iterator aFieldMapIter = aFieldMap.find(aFieldName.in());
1069         VISU::PCField aField;
1070         if(aFieldMapIter == aFieldMap.end()){
1071           aField = aFieldMap[aFieldName.in()](new VISU::TCField());
1072           aField->myId = iField;
1073           aField->myName = aFieldName.in();
1074           aField->myEntity = anEntity;
1075           aField->myMeshName = aMeshName.in();
1076           aField->myDataSize = aMeshOnEntity->myNbCells * aField->myNbComp;
1077
1078           vtkIdType aDataType = VTK_DOUBLE;
1079           SALOME_MED::FIELDDOUBLE_ptr aFieldDouble = SALOME_MED::FIELDDOUBLE::_narrow(aMEDField);
1080           if(aFieldDouble->_is_nil()) {
1081             // PAL18313: Mandriva 64 porting: CRASH at creating presentation on "Import Structure".
1082             if (sizeof(long) == 4 ) // Size of CORBA::Long is always 4 (see CORBA_basetypes.h)
1083               aDataType = VTK_LONG;
1084             else if (sizeof(int) == 4)
1085               aDataType = VTK_INT;
1086             else {
1087               MESSAGE("Can't map CORBA::Long to a VTK type, for Field " << aFieldName);
1088               continue;
1089             }
1090           }
1091           aField->Init(aMEDField->getNumberOfComponents(), aDataType);
1092
1093           if(MYDEBUG) 
1094             MESSAGE("VISU_MEDConvertor::Build - aMeshOnEntity->myNbCells = "<<aMeshOnEntity->myNbCells);
1095         }else
1096           aField = aFieldMapIter->second;
1097
1098         VISU::TValField& aValField = aField->myValField;
1099         int anId = aMEDField->getIterationNumber();
1100         VISU::PCValForTime aValForTime = aValField[anId](new VISU::TCValForTime());
1101         aValForTime->myId = anId;
1102         CORBA::Double aDT = aMEDField->getTime();
1103         aValForTime->myTime = VISU::TTime(aDT,"");
1104         aValForTime->myField = aMEDField;
1105         if(MYDEBUG) 
1106           MESSAGE("VISU_MEDConvertor::Build - aMeshName = '"<<aMeshName<<
1107                   "'; myEntity = "<<anEntity<<"; myTime = "<<aDT);
1108       }      
1109     }
1110   }
1111   return this; 
1112 }
1113  
1114
1115 //---------------------------------------------------------------
1116 VISU_Convertor* 
1117 VISU_MEDConvertor
1118 ::Build(SALOMEDS::ChildIterator_ptr theTimeStampIterator)
1119 {
1120   if(theTimeStampIterator->_is_nil()) return NULL;
1121   for(; theTimeStampIterator->More(); theTimeStampIterator->Next()){
1122     SALOMEDS::SObject_var aTimeStampSObj = theTimeStampIterator->Value();
1123     if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aTimeStampSObj = '"<<GetSObjectName(aTimeStampSObj)<<"'");
1124
1125     CORBA::Object_var aMedField = VISU::SObjectToObject(aTimeStampSObj);
1126     if(CORBA::is_nil(aMedField)) 
1127       continue;
1128
1129     SALOME_MED::FIELD_var aMEDField = SALOME_MED::FIELD::_narrow(aMedField);
1130     if(aMEDField->_is_nil()) 
1131       continue;
1132
1133     SALOME_MED::SUPPORT_var aMEDSupport = aMEDField->getSupport();
1134     if(aMEDSupport->_is_nil()) 
1135       continue;
1136
1137     SALOME_MED::medEntityMesh aMEntity = aMEDSupport->getEntity();
1138     VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
1139     SALOME_MED::MESH_var aMEDMesh = aMEDSupport->getMesh();
1140     if(aMEDMesh->_is_nil()) continue;
1141     CORBA::String_var aMeshName = aMEDMesh->getName();
1142     CORBA::String_var aFieldName = aMEDField->getName();
1143
1144     VISU::PCMesh aMesh;
1145     VISU::TMeshMap::const_iterator aMeshMapIter = myMeshMap.find(aMeshName.in());
1146     if(aMeshMapIter == myMeshMap.end()){
1147       aMesh.reset(new VISU::TCMesh());
1148       aMesh->myNamedPointCoords(new VISU::TNamedPointCoords());
1149       aMesh->myNbPoints = aMEDMesh->getNumberOfNodes();
1150       aMesh->myDim = aMEDMesh->getSpaceDimension();
1151       aMesh->myName = aMeshName.in();
1152       aMesh->myMesh = aMEDMesh;
1153       
1154       myMeshMap[aMeshName.in()] = aMesh;
1155
1156       if(MYDEBUG) 
1157         MESSAGE("VISU_MEDConvertor::Build "<<
1158                 "- aMeshName = '"<<aMeshName<<"'"<<
1159                 "; aDim = "<<aMesh->myDim);
1160     }else
1161       aMesh = aMeshMapIter->second;
1162
1163     VISU::PCMeshOnEntity aMeshOnEntity;
1164     VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
1165     VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.find(aVEntity);
1166     if(aMeshOnEntityMapIter == aMeshOnEntityMap.end()){
1167       aMeshOnEntity.reset(new VISU::TCMeshOnEntity());
1168       aMeshOnEntity->myEntity = aVEntity;
1169       aMeshOnEntity->myMeshName = aMeshName.in();
1170       aMeshOnEntity->mySupport = aMEDSupport;
1171       aMeshOnEntityMap[aVEntity] = aMeshOnEntity;
1172     }else
1173       aMeshOnEntity = aMeshOnEntityMapIter->second;
1174
1175     if(aVEntity == VISU::NODE_ENTITY)
1176       ::InitMeshOnEntity(aMesh,VISU::CELL_ENTITY,aMeshOnEntity);
1177     else
1178       ::InitMeshOnEntity(aMesh,VISU::NODE_ENTITY,aMeshOnEntity);
1179
1180     ::GetCellsSize(aMesh,aMEDMesh,aVEntity);
1181
1182     VISU::PCField aField;
1183     VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
1184     VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.find(aFieldName.in());
1185     if(aFieldMapIter == aFieldMap.end()){
1186       aField.reset(new VISU::TCField());
1187       aField->myId = mySObject->Tag();
1188       aField->myName = aFieldName.in();
1189       aField->myEntity = aVEntity;
1190       aField->myMeshName = aMeshName.in();
1191       aField->myDataSize = aMeshOnEntity->myNbCells * aField->myNbComp;
1192       
1193       vtkIdType aDataType = VTK_DOUBLE;
1194       SALOME_MED::FIELDDOUBLE_ptr aFieldDouble = SALOME_MED::FIELDDOUBLE::_narrow(aMEDField);
1195       if(aFieldDouble->_is_nil())
1196         aDataType = VTK_LONG;
1197       aField->Init(aMEDField->getNumberOfComponents(), aDataType);
1198
1199       aFieldMap[aFieldName.in()] = aField;
1200
1201       if(MYDEBUG) 
1202         MESSAGE("VISU_MEDConvertor::Build - aMeshOnEntity->myNbCells = "<<aMeshOnEntity->myNbCells);
1203     }else
1204       aField = aFieldMapIter->second;
1205
1206     VISU::TValField& aValField = aField->myValField;
1207     int anId = aMEDField->getIterationNumber();
1208     VISU::PCValForTime aValForTime = aValField[anId](new VISU::TCValForTime());
1209     aValForTime->myId = anId;
1210     CORBA::Double aDT = aMEDField->getTime();
1211     aValForTime->myTime = VISU::TTime(aDT,"");
1212     aValForTime->myField = aMEDField;
1213     if(MYDEBUG) 
1214       MESSAGE("VISU_MEDConvertor::Build "<<
1215               "- aMeshName = '"<<aMeshName<<"'"<<
1216               "; myEntity = "<<aVEntity<<
1217               "; myTime = "<<aDT<<
1218               "; anId = "<<anId);
1219   }
1220   return this; 
1221 }
1222
1223
1224 //---------------------------------------------------------------
1225 int
1226 VISU_MEDConvertor
1227 ::LoadMeshOnEntity(VISU::PMeshImpl theMesh,
1228                    VISU::PMeshOnEntityImpl theMeshOnEntity)
1229 {
1230   int anIsUpdated = LoadPoints(theMesh);
1231   const VISU::TEntity& aVEntity = theMeshOnEntity->myEntity;
1232   if(aVEntity != VISU::NODE_ENTITY)
1233     anIsUpdated |= LoadCellsOnEntity(theMesh,theMeshOnEntity);
1234
1235   return anIsUpdated;
1236 }
1237  
1238  
1239 //---------------------------------------------------------------
1240 int
1241 VISU_MEDConvertor
1242 ::LoadFamilyOnEntity(VISU::PMeshImpl theMesh,
1243                      VISU::PMeshOnEntityImpl theMeshOnEntity, 
1244                      VISU::PFamilyImpl theFamily)
1245 {
1246   int anIsUpdated = LoadPoints(theMesh);
1247   const VISU::TEntity& anEntity = theMeshOnEntity->myEntity;
1248   if(anEntity == VISU::NODE_ENTITY){
1249     anIsUpdated |= LoadPointsOnFamily(theMesh,theFamily);
1250   }else{
1251     anIsUpdated |= LoadCellsOnEntity(theMesh,theMeshOnEntity);
1252     anIsUpdated |= LoadCellsOnFamily(theMesh,theMeshOnEntity,theFamily);
1253   }
1254
1255   return anIsUpdated;
1256 }
1257
1258
1259 //---------------------------------------------------------------
1260 int 
1261 VISU_MEDConvertor
1262 ::LoadMeshOnGroup(VISU::PMeshImpl theMesh, 
1263                   const VISU::TFamilySet& theFamilySet)
1264 {
1265   //Main part of code
1266   int anIsUpdated = LoadPoints(theMesh);
1267   VISU::TFamilySet::const_iterator aFamilyIter = theFamilySet.begin();
1268   for(; aFamilyIter != theFamilySet.end(); aFamilyIter++){
1269     VISU::PCFamily aFamily = *aFamilyIter;
1270     const VISU::TEntity& aVEntity = aFamily->myEntity;
1271     VISU::PCMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[aVEntity];
1272     if(aVEntity == VISU::NODE_ENTITY){
1273       anIsUpdated |= LoadPointsOnFamily(theMesh,aFamily);
1274     }else{
1275       anIsUpdated |= LoadCellsOnEntity(theMesh,aMeshOnEntity);
1276       anIsUpdated |= LoadCellsOnFamily(theMesh,aMeshOnEntity,aFamily);
1277     }
1278   }
1279
1280   return anIsUpdated;
1281 }
1282
1283
1284 //---------------------------------------------------------------
1285 int 
1286 VISU_MEDConvertor
1287 ::LoadValForTimeOnMesh(VISU::PMeshImpl theMesh, 
1288                        VISU::PMeshOnEntityImpl theMeshOnEntity, 
1289                        VISU::PFieldImpl theField, 
1290                        VISU::PValForTimeImpl theValForTime)
1291 {
1292   //Main part of code
1293   int anIsUpdated = LoadPoints(theMesh);
1294   const VISU::TEntity& aVEntity = theMeshOnEntity->myEntity;
1295   if(aVEntity != VISU::NODE_ENTITY)
1296     anIsUpdated |= LoadCellsOnEntity(theMesh,theMeshOnEntity);
1297
1298   anIsUpdated |= LoadField(theMesh,theMeshOnEntity,theField,theValForTime);
1299   
1300   return anIsUpdated;
1301 }
1302
1303
1304 //---------------------------------------------------------------
1305 int 
1306 VISU_MEDConvertor
1307 ::LoadPoints(VISU::PCMesh theMesh)
1308 {
1309   //Check on existing family
1310   VISU::PCMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[VISU::NODE_ENTITY];
1311   
1312   //Check on loading already done
1313   if(theMesh->myIsDone) 
1314     return 0;
1315   
1316   SALOME_MED::MESH_var& aMedMesh = theMesh->myMesh;
1317   vtkIdType aDim = theMesh->GetDim();
1318   vtkIdType aNbElem = theMesh->GetNbPoints();
1319
1320   if(MYDEBUG) MESSAGE("LoadPoints - aNbElem = "<<aNbElem);
1321
1322   if(aNbElem <= 0) 
1323     throw std::runtime_error("LoadPoints >> There is no points in the mesh !!!");
1324
1325   SALOME_MED::double_array_var aCCoord = aMedMesh->getCoordinates(SALOME_MED::MED_FULL_INTERLACE);
1326   VISU::TCMEDCoordHolder* aCoordHolder = new VISU::TCMEDCoordHolder();
1327   aCoordHolder->Init(aNbElem, aDim, aCCoord);
1328
1329   VISU::TNamedPointCoords& aCoords = theMesh->myNamedPointCoords;
1330   aCoords.Init(VISU::PCoordHolder(aCoordHolder));
1331   
1332   if(MYDEBUG) MESSAGE("LoadPoints - Filling aMeshOnEntity with type NODE_ENTITY");
1333   
1334   VISU::TGeom2SubMesh& aGeom2SubMesh = aMeshOnEntity->myGeom2SubMesh;
1335   VISU::PSubMeshImpl aSubMesh = aGeom2SubMesh[VISU::ePOINT1](new VISU::TCSubMesh());
1336
1337   aSubMesh->myNbCells = theMesh->myNbPoints;
1338   aSubMesh->myCellsSize = 2*theMesh->myNbPoints;
1339
1340   VISU::TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
1341   aCell2Connect.resize(aNbElem);
1342   if(MYDEBUG) MESSAGE("LoadPoints - aNbElem="<<aNbElem);
1343   for(int iElem = 0; iElem < aNbElem; iElem++)
1344     aCell2Connect[iElem] = VISU::TConnect(1,iElem);
1345   
1346   theMesh->myIsDone = true;
1347
1348   return 1;
1349 }
1350
1351
1352 //---------------------------------------------------------------
1353 int 
1354 VISU_MEDConvertor
1355 ::LoadPointsOnFamily(VISU::PCMesh theMesh, 
1356                      VISU::PCFamily theFamily)
1357 {
1358   VISU::PCMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[VISU::NODE_ENTITY];
1359
1360   if(theFamily->myIsDone) 
1361     return 0;
1362
1363   vtkIdType aNbElem = theMesh->GetNbPoints();
1364   SALOME_MED::FAMILY_var aMedFamily = theFamily->myFamily;
1365   CORBA::Boolean anIsOnAllElements = aMedFamily->isOnAllElements();
1366   VISU::TSubMeshID& aSubMeshID = theFamily->myGeom2SubMeshID[VISU::ePOINT1];
1367   
1368   if(!anIsOnAllElements){
1369     SALOME_MED::medGeometryElement_array_var aGeom = aMedFamily->getTypes();
1370     SALOME_MED::long_array_var aCellNumForType = aMedFamily->getNumber(aGeom[0]);
1371     int aSize = aNbElem;
1372     aNbElem = aCellNumForType->length();
1373     for(int iElem = 0; iElem < aNbElem; iElem++){
1374       int anID = aCellNumForType[iElem] - 1;
1375       if(0 > anID || anID >= aSize){
1376         static QString aString;
1377         aString.sprintf("LoadPointsOnFamily - aSize(%d) <= aCellNumForType[%d] = %d < 0",aSize,iElem,anID);
1378         throw std::runtime_error(aString.latin1());
1379       }
1380       aSubMeshID.push_back(anID);
1381     }
1382   }else{
1383     for(int iElem = 0; iElem < aNbElem; iElem++){
1384       aSubMeshID.push_back(iElem);
1385     }
1386   }
1387   
1388   theFamily->myIsDone = true;
1389   
1390   return 1;
1391 }
1392
1393 //---------------------------------------------------------------
1394 namespace 
1395 {
1396   typedef MED::TCSlice<int> TA;
1397   //---------------------------------------------------------------
1398   typedef std::set<int> TConnSet;
1399   typedef std::vector<int> TIntArray;
1400   typedef MED::TCSlice<int> TConnSlice;
1401
1402   //---------------------------------------------------------------
1403   class MEDPolygonConnectivity //! retriver of polygon connectivity
1404   {
1405     TIntArray myConn;
1406     TIntArray myConnIndex;
1407   public:
1408
1409     MEDPolygonConnectivity(SALOME_MED::MESH_var theMesh,
1410                            SALOME_MED::medEntityMesh theEntity) 
1411     {
1412       {
1413         SALOME::SenderInt_var aSender = 
1414           theMesh->getSenderForPolygonsConnectivity(SALOME_MED::MED_NODAL, theEntity);
1415         long int aSize;
1416         int* aValuePtr = ReceiverFactory::getValue(aSender.in(), aSize);
1417         myConn.assign(aValuePtr, aValuePtr + aSize);
1418       }
1419       {
1420         SALOME::SenderInt_var aSender = 
1421           theMesh->getSenderForPolygonsConnectivityIndex(SALOME_MED::MED_NODAL, theEntity);
1422         long int aSize;
1423         int* aValuePtr = ReceiverFactory::getValue(aSender, aSize);
1424         myConnIndex.assign(aValuePtr, aValuePtr + aSize);
1425       }
1426     }
1427
1428     TConnSlice 
1429     GetConn(int theId) const 
1430     {
1431       int anOffSet = myConnIndex[theId] - 1;
1432       int aSize = myConnIndex[theId + 1] - myConnIndex[ theId ];
1433       return TConnSlice(&myConn[0], myConn.size(), std::slice(anOffSet, aSize, 1));
1434     }
1435
1436     int 
1437     GetNbElem() const 
1438     {
1439       return myConnIndex.size() - 1;
1440     }
1441
1442     int
1443     GetCellSize() const
1444     {
1445       return myConn.size() + GetNbElem();
1446     }
1447   };
1448
1449
1450   //---------------------------------------------------------------
1451   class MEDPolyhedraConnectivity //! retriver of polyhedron connectivity
1452   {
1453     TIntArray myConn;
1454     TIntArray myConnIndex;
1455     TIntArray myFaceIndex;
1456   public:
1457
1458     MEDPolyhedraConnectivity(SALOME_MED::MESH_var theMesh)
1459     {
1460       {
1461         SALOME::SenderInt_var aSender = 
1462           theMesh->getSenderForPolyhedronConnectivity(SALOME_MED::MED_NODAL);
1463         long int aSize;
1464         int* aValuePtr = ReceiverFactory::getValue(aSender, aSize);
1465         myConn.assign(aValuePtr, aValuePtr + aSize);
1466       }
1467       {
1468         SALOME::SenderInt_var aSender = 
1469           theMesh->getSenderForPolyhedronIndex(SALOME_MED::MED_NODAL);
1470         long int aSize;
1471         int* aValuePtr = ReceiverFactory::getValue(aSender, aSize);
1472         myConnIndex.assign(aValuePtr, aValuePtr + aSize);
1473       }
1474       {
1475         SALOME::SenderInt_var aSender = 
1476           theMesh->getSenderForPolyhedronFacesIndex();
1477         long int aSize;
1478         int* aValuePtr = ReceiverFactory::getValue(aSender, aSize);
1479         myFaceIndex.assign(aValuePtr, aValuePtr + aSize);
1480       }
1481     }
1482
1483     int
1484     GetUniqueConn(int theId, 
1485                   TConnSet& theConnSet) const 
1486     {
1487       theConnSet.clear();
1488       int aStartFaceId = myConnIndex[theId] - 1;
1489       int anEndFaceId = myConnIndex[theId + 1] - 2;
1490       int aStartConnId = myFaceIndex[aStartFaceId] - 1;
1491       int anEndConnId = myFaceIndex[anEndFaceId + 1] - 1;
1492       for(int aConnId = aStartConnId; aConnId < anEndConnId; aConnId++)
1493         theConnSet.insert(myConn[aConnId]);
1494       return theConnSet.size();
1495     }
1496
1497     int
1498     GetNbElem() const
1499     {
1500       return myConnIndex.size() - 1;
1501     }
1502
1503     int
1504     GetCellSize() const
1505     {
1506       TConnSet aConnSet;
1507       int aCellSize = 0;
1508       for(int anElemId = 0; anElemId < GetNbElem(); anElemId++)
1509         aCellSize += GetUniqueConn(anElemId, aConnSet);
1510       return aCellSize;
1511     }
1512   };
1513 }
1514
1515 //---------------------------------------------------------------
1516 int 
1517 VISU_MEDConvertor
1518 ::LoadCellsOnEntity(VISU::PCMesh theMesh,
1519                     VISU::PCMeshOnEntity theMeshOnEntity)
1520 {
1521   if(theMeshOnEntity->myIsDone) 
1522     return 0;
1523
1524   SALOME_MED::SUPPORT_var& aMedSupport = theMeshOnEntity->mySupport;
1525   SALOME_MED::MESH_var aMedMesh = aMedSupport->getMesh();
1526
1527   //Main part of code
1528   const VISU::TEntity& aVEntity = theMeshOnEntity->myEntity;
1529   const SALOME_MED::medEntityMesh& aMEntity = VTKEntityToMED(aVEntity);
1530   VISU::TCellsFirstIndex& aFirstIndex = theMeshOnEntity->myCellsFirstIndex;
1531
1532   SALOME_MED::MESH::connectivityInfos_var anInfo = aMedMesh->getConnectGlobal(aMEntity);
1533   int iGeomEnd = anInfo->meshTypes.length();
1534
1535   VISU::TGeom2SubMesh& aGeom2SubMesh = theMeshOnEntity->myGeom2SubMesh;
1536   vtkIdType aNbPoints = theMesh->GetNbPoints();
1537
1538   for(int iGeom = 0, aCounter = 0; iGeom < iGeomEnd; iGeom++) {
1539     SALOME_MED::medGeometryElement aMGeom = anInfo->meshTypes[iGeom];
1540     VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
1541     switch (aMGeom) {
1542     case SALOME_MED::MED_POLYGON:
1543     {
1544       MEDPolygonConnectivity aConn(aMedMesh, aMEntity);
1545       int aNbElem = aConn.GetNbElem();
1546       if (aNbElem > 0) {
1547         VISU::PSubMeshImpl aSubMesh = aGeom2SubMesh[aEGeom](new VISU::TCSubMesh());
1548         aSubMesh->myNbCells   = aNbElem;
1549         aSubMesh->myCellsSize = aConn.GetCellSize();
1550
1551         VISU::TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
1552         aCell2Connect.resize(aNbElem);
1553
1554         for(int iElem = 0; iElem < aNbElem; iElem++) {
1555           TConnSlice aConnSlice = aConn.GetConn(iElem);
1556           VISU::TConnect& anArray = aCell2Connect[iElem];
1557           anArray.resize(aConnSlice.size());
1558           for(int iConn = 0; iConn < aConnSlice.size(); iConn++)
1559             anArray[iConn] = aConnSlice[iConn] - 1;
1560         }
1561       }
1562     }
1563     break;
1564     case SALOME_MED::MED_POLYHEDRA:
1565     {
1566       MEDPolyhedraConnectivity aConn( aMedMesh );
1567       int aNbElem = aConn.GetNbElem();
1568       if (aNbElem > 0) {
1569         VISU::PSubMeshImpl aSubMesh = aGeom2SubMesh[aEGeom](new VISU::TCSubMesh());
1570         aSubMesh->myNbCells = aNbElem;
1571         aSubMesh->myCellsSize = aConn.GetCellSize();
1572
1573         VISU::TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
1574         aCell2Connect.resize(aNbElem);
1575
1576         TConnSet aConnectSet;
1577         for(int iElem = 0; iElem < aNbElem; iElem++){
1578           if(aConn.GetUniqueConn(iElem, aConnectSet)){
1579             int aNbConn = aConnectSet.size();
1580             VISU::TConnect& anArray = aCell2Connect[iElem];
1581             anArray.resize(aNbConn);
1582             std::set<int>::iterator anIter = aConnectSet.begin();
1583             for(int i = 0; anIter != aConnectSet.end(); anIter++, i++)
1584               anArray[i] = *anIter - 1;
1585           }
1586         }
1587       }
1588     }
1589     break;
1590     default:
1591     {        
1592       int aMNbNodes = MEDGeom2NbNodes(aMGeom);
1593       int aVNbNodes = VISUGeom2NbNodes(aEGeom);
1594       int aNbElem = anInfo->numberOfElements[iGeom];
1595       if (aNbElem > 0) {
1596         SALOME_MED::long_array_var aConn = 
1597           aMedMesh->getConnectivity(SALOME_MED::MED_FULL_INTERLACE,
1598                                     SALOME_MED::MED_NODAL,
1599                                     aMEntity,
1600                                     aMGeom);
1601         VISU::PSubMeshImpl aSubMesh = aGeom2SubMesh[aEGeom](new VISU::TCSubMesh());
1602
1603         aSubMesh->myNbCells = aNbElem;
1604         aSubMesh->myCellsSize = aNbElem*(aVNbNodes+1);
1605
1606         VISU::TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
1607         std::vector<int> aConnect(aMNbNodes);
1608         int aNbConnForElem = aConn->length() / aNbElem;
1609
1610         if(MYDEBUG) MESSAGE("LoadCellsOnEntity - aMGeom = "<<aMGeom<<
1611                             "; aNbElem = "<<aNbElem<<
1612                             "; aMNbNodes = "<<aMNbNodes<<
1613                             "; aVNbNodes = "<<aVNbNodes<<
1614                             "; aNbConnForElem = "<<aNbConnForElem);
1615
1616         for(int iElem = 0; iElem < aNbElem; iElem++) {
1617           VISU::TConnect anArray(aVNbNodes);
1618           for(int k = 0, kj = iElem*aNbConnForElem; k < aMNbNodes; k++)
1619             aConnect[k] = aConn[kj+k] - 1;
1620
1621           switch(aMGeom){
1622 #if !(defined(VTK_QUADRATIC_EDGE) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
1623           case SALOME_MED::MED_SEG3:
1624             anArray[0] = aConnect[0];
1625             anArray[2] = aConnect[1];  
1626
1627             anArray[1] = aConnect[2];
1628             break;
1629 #endif
1630 #if !(defined(VTK_QUADRATIC_TRIANGLE) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
1631           case SALOME_MED::MED_TRIA6:
1632             anArray[0] = aConnect[0];
1633             anArray[2] = aConnect[1];  
1634             anArray[4] = aConnect[2];  
1635
1636             anArray[1] = aConnect[3];
1637             anArray[3] = aConnect[4];  
1638             anArray[5] = aConnect[5];  
1639             break;
1640 #endif
1641 #if !(defined(VTK_QUADRATIC_QUAD) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
1642           case SALOME_MED::MED_QUAD8:
1643             anArray[0] = aConnect[0];
1644             anArray[2] = aConnect[1];  
1645             anArray[4] = aConnect[2];  
1646             anArray[6] = aConnect[3];  
1647
1648             anArray[1] = aConnect[4];
1649             anArray[3] = aConnect[5];  
1650             anArray[5] = aConnect[6];  
1651             anArray[7] = aConnect[7];  
1652             break;
1653 #endif
1654 #if (defined(VTK_QUADRATIC_TETRA) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
1655           case SALOME_MED::MED_TETRA10 :
1656 #endif
1657           case SALOME_MED::MED_TETRA4 :
1658             anArray[0] = aConnect[0];
1659             anArray[1] = aConnect[1];
1660             anArray[2] = aConnect[3];  
1661             anArray[3] = aConnect[2];  
1662             break;
1663 #if (defined(VTK_QUADRATIC_PYRAMID) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
1664           case SALOME_MED::MED_PYRA13:
1665 #endif
1666           case SALOME_MED::MED_PYRA5 :
1667             anArray[0] = aConnect[0];
1668             anArray[1] = aConnect[3];  
1669             anArray[2] = aConnect[2];
1670             anArray[3] = aConnect[1];  
1671             anArray[4] = aConnect[4];
1672             break;
1673           default:
1674             for (int k = 0; k < aVNbNodes; k++) 
1675               anArray[k] = aConnect[k];
1676           }
1677           for (int k = 0; k < aVNbNodes; k++) 
1678             if(anArray[k] < 0 || aNbPoints <= anArray[k]){
1679               static QString aString;
1680               aString.sprintf("LoadCellsOnEntity >> aNbPoints(%d) <= anArray[%d][%d]=%d < 0 !!!",aNbPoints,iElem,k,anArray[k]);
1681               throw std::runtime_error(aString.latin1());
1682             }
1683           aCell2Connect.push_back(anArray);
1684         } // loop on elements
1685       }
1686     }} // switch( aMGeom )
1687     VISU::TGeom2SubMesh::iterator anIter = aGeom2SubMesh.find(aEGeom);
1688     if(anIter != aGeom2SubMesh.end()){
1689       const VISU::PSubMeshImpl& aSubMesh = anIter->second;
1690       const VISU::TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
1691       int aSize = aCell2Connect.size();
1692       if(MYDEBUG) MESSAGE("LoadCellsOnEntity - aCounter = "<<aCounter<<"; aSize = "<<aSize<<"; aMGeom = "<<aMGeom);
1693       aFirstIndex[aMGeom] = VISU::TIndexAndSize(aCounter, aSize);
1694       aCounter += aSize;
1695     }
1696   } //loop on types
1697
1698   // Dump result connectivity
1699 // #ifdef _DEBUG_
1700 //   TGeom2SubMesh::iterator geom_sm = aGeom2SubMesh.begin();
1701 //   for ( ; geom_sm!=aGeom2SubMesh.end(); ++geom_sm ) {
1702 //     cout << "TYPE: " << geom_sm->first << endl;
1703 //     PSubMeshImpl aSubMesh = geom_sm->second;
1704 //     TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
1705 //     TCell2Connect::iterator id_conn = aCell2Connect.begin();
1706 //     for ( int i = 0; id_conn !=aCell2Connect.end(); ++id_conn ) {
1707 //       cout << "\t" << i++ << ": [";
1708 //       TConnect& anArray = *id_conn;
1709 //       TConnect::iterator n = anArray.begin();
1710 //       for ( ; n != anArray.end(); ++n )
1711 //         cout << " " << *n + 1;
1712 //       cout << " ]"<< endl;
1713 //     }
1714 //   }
1715 // #endif
1716
1717   theMeshOnEntity->myIsDone = true;
1718
1719   return 1;
1720 }
1721
1722
1723 //---------------------------------------------------------------
1724 int 
1725 VISU_MEDConvertor
1726 ::LoadCellsOnFamily(VISU::PCMesh theMesh,
1727                     VISU::PCMeshOnEntity theMeshOnEntity, 
1728                     VISU::PCFamily theFamily)
1729 {
1730   if(theFamily->myIsDone) 
1731     return 0;
1732
1733   SALOME_MED::FAMILY_var aMedFamily = theFamily->myFamily;
1734   CORBA::Boolean anIsOnAllElements = aMedFamily->isOnAllElements();
1735   if(!anIsOnAllElements){
1736     SALOME_MED::medGeometryElement_array_var aGeoms = aMedFamily->getTypes();
1737     int iGeomEnd = aGeoms->length();
1738     if(MYDEBUG) MESSAGE("LoadCellsOnFamily - iGeomEnd = "<<iGeomEnd);
1739     for(int iGeom = 0; iGeom < iGeomEnd; iGeom++){
1740       SALOME_MED::medGeometryElement aMGeom = aGeoms[iGeom];
1741       SALOME_MED::long_array_var aCellNumForType = aMedFamily->getNumber(aMGeom);
1742       VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
1743
1744       int aNbElem = aCellNumForType->length();
1745       int aCounter = theMeshOnEntity->myCellsFirstIndex[aMGeom].first;
1746       int aSize = theMeshOnEntity->myCellsFirstIndex[aMGeom].second;
1747       VISU::TSubMeshID& aSubMeshID = theFamily->myGeom2SubMeshID[aEGeom]; 
1748       
1749       if(MYDEBUG) 
1750         MESSAGE("LoadCellsOnFamily "<<
1751                 "- aMGeom = "<<aMGeom<<
1752                 "; aNbElem = "<<aNbElem<<
1753                 "; aSize = "<<aSize<<
1754                 "; aCounter = "<<aCounter);
1755       
1756       for(int iElem = 0; iElem < aNbElem; iElem++){
1757         int anID = aCellNumForType[iElem] - aCounter - 1;
1758         if(0 > anID || anID >= aSize){
1759           static QString aString;
1760           aString.sprintf("LoadCellsOnFamily - aNbElem(%d) <= aCellNumForType[%d] = %d < 0 !!!",aNbElem,iElem,anID);
1761           throw std::runtime_error(aString.latin1());
1762         }
1763         aSubMeshID.push_back(anID);
1764       }
1765     }
1766   }else{
1767     const VISU::TGeom2SubMesh& aGeom2SubMesh = theMeshOnEntity->myGeom2SubMesh;
1768     VISU::TGeom2SubMesh::const_iterator anIter = aGeom2SubMesh.begin();
1769     for(; anIter != aGeom2SubMesh.end(); anIter++){
1770       VISU::EGeometry aEGeom = anIter->first;
1771       const VISU::TSubMeshImpl& aSubMesh = anIter->second;
1772       const VISU::TCell2Connect& aCell2Connect = aSubMesh.myCell2Connect;
1773       VISU::TSubMeshID& aSubMeshID = theFamily->myGeom2SubMeshID[aEGeom];
1774       int iNumElemEnd = aCell2Connect.size();
1775       for(int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
1776         aSubMeshID.push_back(iNumElem);
1777     }
1778   }
1779   
1780   theFamily->myIsDone = true;
1781
1782   return 1;
1783 }
1784
1785
1786 template<class TValueType,
1787          class TContainerType> 
1788 void 
1789 ImportField(TContainerType& theContainer, 
1790             VISU::PCMesh theMesh,
1791             VISU::PCField theField,
1792             VISU::PCValForTime theValForTime,
1793             VISU::PCMeshOnEntity theMeshOnEntity)
1794 {
1795   typedef VISU::TTCMEDMeshValue<TValueType, TContainerType> TVMeshValue;
1796   vtkIdType aNbComp = theField->myNbComp;
1797   if(theField->myEntity == VISU::NODE_ENTITY){
1798     VISU::EGeometry aEGeom = VISU::ePOINT1;
1799     vtkIdType aNbGauss = theValForTime->GetNbGauss(aEGeom);
1800     vtkIdType aNbElem = theMesh->GetNbPoints();
1801
1802     if(MYDEBUG) MESSAGE("ImportField - aNbElem = "<<aNbElem);
1803
1804     VISU::PMeshValue& aVMeshValue = theValForTime->GetMeshValue(VISU::ePOINT1);
1805     TVMeshValue* aMeshValue = new TVMeshValue();
1806     aMeshValue->Init(aNbElem, aNbGauss, aNbComp, theContainer, 0);
1807     aVMeshValue.reset(aMeshValue);
1808   }else{
1809     SALOME_MED::medGeometryElement* aGeomElems;
1810     const VISU::TEntity& aVEntity = theField->myEntity;
1811     int iGeomEnd = GetEntity2Geom(aVEntity,aGeomElems);
1812     for(int iGeom = 0; iGeom < iGeomEnd; iGeom++){
1813       SALOME_MED::medGeometryElement aMGeom = aGeomElems[iGeom];
1814       VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
1815       vtkIdType aNbGauss = theValForTime->GetNbGauss(aEGeom);
1816       const VISU::TCellsFirstIndex& aCellsFirstIndex = theMeshOnEntity->myCellsFirstIndex;
1817       VISU::TCellsFirstIndex::const_iterator aCellsFirstIndexIter = aCellsFirstIndex.find(aMGeom);
1818       if(aCellsFirstIndexIter != aCellsFirstIndex.end()){
1819         const VISU::TIndexAndSize& aIndexAndSize = aCellsFirstIndexIter->second;
1820         if(MYDEBUG) 
1821           MESSAGE("ImportField - aMGeom = "<<aMGeom<<
1822                   "; aIndexAndSize = {"<<aIndexAndSize.first<<
1823                   ","<<aIndexAndSize.second<<"}");
1824
1825         vtkIdType aNbElem = aIndexAndSize.second;
1826         vtkIdType aStart = aIndexAndSize.first * aNbComp;
1827         VISU::PMeshValue& aVMeshValue = theValForTime->GetMeshValue(aEGeom);
1828         TVMeshValue* aMeshValue = new TVMeshValue();
1829         aMeshValue->Init(aNbElem, aNbGauss, aNbComp, theContainer, aStart);
1830         aVMeshValue.reset(aMeshValue);
1831       }
1832     }
1833   }
1834 }
1835
1836 int
1837 VISU_MEDConvertor
1838 ::LoadField(VISU::PCMesh theMesh,
1839             VISU::PCMeshOnEntity theMeshOnEntity,
1840             VISU::PField theField, 
1841             VISU::PCValForTime theValForTime)
1842 {
1843   MESSAGE("VISU_MEDConvertor::LoadField");
1844   //Check on loading already done
1845   VISU::PUnstructuredGridIDMapperImpl anUnstructuredGridIDMapper = theValForTime->myUnstructuredGridIDMapper;
1846   if(anUnstructuredGridIDMapper->myIsVTKDone) 
1847     return 0;
1848   
1849   VISU::PCProfile aProfile(new VISU::TCProfile());
1850   aProfile->myIsAll = true;
1851   theValForTime->myProfile = aProfile;
1852
1853   SALOME_MED::FIELD_var aMEDField = theValForTime->myField;
1854
1855   SALOME_MED::SUPPORT_var aMEDSupport = aMEDField->getSupport();
1856
1857   if(aMEDSupport->isOnAllElements()) aProfile->myIsDone = true;
1858   
1859   SALOME_MED::FIELDDOUBLE_ptr aFieldDouble = SALOME_MED::FIELDDOUBLE::_narrow(aMEDField);
1860   if(!aFieldDouble->_is_nil()){
1861     SALOME_MED::double_array_var anArray = aFieldDouble->getValue(SALOME_MED::MED_FULL_INTERLACE);
1862     if(MYDEBUG) MESSAGE("VISU_MEDConvertor::LoadField - There is FIELDDOUBLE = "<<anArray->length());
1863     ImportField<CORBA::Double>(anArray,
1864                                theMesh,
1865                                theField,
1866                                theValForTime,
1867                                theMeshOnEntity);
1868   }
1869
1870   SALOME_MED::FIELDINT_ptr aFieldInt = SALOME_MED::FIELDINT::_narrow(aMEDField);
1871   if(!aFieldInt->_is_nil()){
1872     SALOME_MED::long_array_var anArray = aFieldInt->getValue(SALOME_MED::MED_FULL_INTERLACE);
1873     if(MYDEBUG) MESSAGE("VISU_MEDConvertor::LoadField - There is FIELDINT = "<<anArray->length());
1874     ImportField<CORBA::Long>(anArray,
1875                              theMesh,
1876                              theField,
1877                              theValForTime,
1878                              theMeshOnEntity);
1879   }
1880
1881   anUnstructuredGridIDMapper->myIsVTKDone = true;
1882
1883   MESSAGE("VISU_MEDConvertor::LoadField done");
1884   return 1;
1885 }