Salome HOME
262d93996bbb7ef77bf81f8a9d28a2b998b4a3ef
[modules/visu.git] / src / VISU_I / VISU_CorbaMedConvertor.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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 //  VISU OBJECT : interactive object for VISU entities implementation
23 //  File   : VISU_CorbaMedConvertor.cxx
24 //  Author : Alexey PETROV
25 //  Module : VISU
26 //  $Header$
27 //
28 #include "VISU_CorbaMedConvertor.hxx"
29 #include "VISU_ConvertorUtils.hxx"
30
31 #include <vtkCellType.h>
32
33 #include <boost/tuple/tuple.hpp>
34
35 #include "ReceiverFactory.hxx"
36 #include "MED_SliceArray.hxx"
37
38 #include "utilities.h"
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_BEGIN(" - 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) MESSAGE_ADD(std::endl << "------------------------------->" << anId);
596           }
597           if(MYDEBUG) MESSAGE_END(" ");
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           vtkIdType 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           vtkIdType 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         if (sizeof(long) == 4 ) // Size of CORBA::Long is always 4 (see CORBA_basetypes.h)
1197           //Fix for IPAL20325 Crash on create presentation for imported field 
1198           aDataType = VTK_LONG;
1199         else if (sizeof(int) == 4)
1200           aDataType = VTK_INT;
1201         else {
1202           throw std::runtime_error("Can't map CORBA::Long to a VTK type");
1203         }
1204       }
1205       aField->Init(aMEDField->getNumberOfComponents(), aDataType);
1206
1207       aFieldMap[aFieldName.in()] = aField;
1208
1209       if(MYDEBUG) 
1210         MESSAGE("VISU_MEDConvertor::Build - aMeshOnEntity->myNbCells = "<<aMeshOnEntity->myNbCells);
1211     }else
1212       aField = aFieldMapIter->second;
1213
1214     VISU::TValField& aValField = aField->myValField;
1215     int anId = aMEDField->getIterationNumber();
1216     VISU::PCValForTime aValForTime = aValField[anId](new VISU::TCValForTime());
1217     aValForTime->myId = anId;
1218     CORBA::Double aDT = aMEDField->getTime();
1219     aValForTime->myTime = VISU::TTime(aDT,"");
1220     aValForTime->myField = aMEDField;
1221     if(MYDEBUG) 
1222       MESSAGE("VISU_MEDConvertor::Build "<<
1223               "- aMeshName = '"<<aMeshName<<"'"<<
1224               "; myEntity = "<<aVEntity<<
1225               "; myTime = "<<aDT<<
1226               "; anId = "<<anId);
1227   }
1228   return this; 
1229 }
1230
1231
1232 //---------------------------------------------------------------
1233 int
1234 VISU_MEDConvertor
1235 ::LoadMeshOnEntity(VISU::PMeshImpl theMesh,
1236                    VISU::PMeshOnEntityImpl theMeshOnEntity)
1237 {
1238   int anIsUpdated = LoadPoints(theMesh);
1239   const VISU::TEntity& aVEntity = theMeshOnEntity->myEntity;
1240   if(aVEntity != VISU::NODE_ENTITY)
1241     anIsUpdated |= LoadCellsOnEntity(theMesh,theMeshOnEntity);
1242
1243   return anIsUpdated;
1244 }
1245  
1246  
1247 //---------------------------------------------------------------
1248 int
1249 VISU_MEDConvertor
1250 ::LoadFamilyOnEntity(VISU::PMeshImpl theMesh,
1251                      VISU::PMeshOnEntityImpl theMeshOnEntity, 
1252                      VISU::PFamilyImpl theFamily)
1253 {
1254   int anIsUpdated = LoadPoints(theMesh);
1255   const VISU::TEntity& anEntity = theMeshOnEntity->myEntity;
1256   if(anEntity == VISU::NODE_ENTITY){
1257     anIsUpdated |= LoadPointsOnFamily(theMesh,theFamily);
1258   }else{
1259     anIsUpdated |= LoadCellsOnEntity(theMesh,theMeshOnEntity);
1260     anIsUpdated |= LoadCellsOnFamily(theMesh,theMeshOnEntity,theFamily);
1261   }
1262
1263   return anIsUpdated;
1264 }
1265
1266
1267 //---------------------------------------------------------------
1268 int 
1269 VISU_MEDConvertor
1270 ::LoadMeshOnGroup(VISU::PMeshImpl theMesh, 
1271                   const VISU::TFamilySet& theFamilySet)
1272 {
1273   //Main part of code
1274   int anIsUpdated = LoadPoints(theMesh);
1275   VISU::TFamilySet::const_iterator aFamilyIter = theFamilySet.begin();
1276   for(; aFamilyIter != theFamilySet.end(); aFamilyIter++){
1277     VISU::PCFamily aFamily = *aFamilyIter;
1278     const VISU::TEntity& aVEntity = aFamily->myEntity;
1279     VISU::PCMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[aVEntity];
1280     if(aVEntity == VISU::NODE_ENTITY){
1281       anIsUpdated |= LoadPointsOnFamily(theMesh,aFamily);
1282     }else{
1283       anIsUpdated |= LoadCellsOnEntity(theMesh,aMeshOnEntity);
1284       anIsUpdated |= LoadCellsOnFamily(theMesh,aMeshOnEntity,aFamily);
1285     }
1286   }
1287
1288   return anIsUpdated;
1289 }
1290
1291
1292 //---------------------------------------------------------------
1293 int 
1294 VISU_MEDConvertor
1295 ::LoadValForTimeOnMesh(VISU::PMeshImpl theMesh, 
1296                        VISU::PMeshOnEntityImpl theMeshOnEntity, 
1297                        VISU::PFieldImpl theField, 
1298                        VISU::PValForTimeImpl theValForTime)
1299 {
1300   //Main part of code
1301   int anIsUpdated = LoadPoints(theMesh);
1302   const VISU::TEntity& aVEntity = theMeshOnEntity->myEntity;
1303   if(aVEntity != VISU::NODE_ENTITY)
1304     anIsUpdated |= LoadCellsOnEntity(theMesh,theMeshOnEntity);
1305
1306   anIsUpdated |= LoadField(theMesh,theMeshOnEntity,theField,theValForTime);
1307   
1308   return anIsUpdated;
1309 }
1310
1311
1312 //---------------------------------------------------------------
1313 int 
1314 VISU_MEDConvertor
1315 ::LoadPoints(VISU::PCMesh theMesh)
1316 {
1317   //Check on existing family
1318   VISU::PCMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[VISU::NODE_ENTITY];
1319   
1320   //Check on loading already done
1321   if(theMesh->myIsDone) 
1322     return 0;
1323   
1324   SALOME_MED::MESH_var& aMedMesh = theMesh->myMesh;
1325   vtkIdType aDim = theMesh->GetDim();
1326   vtkIdType aNbElem = theMesh->GetNbPoints();
1327
1328   if(MYDEBUG) MESSAGE("LoadPoints - aNbElem = "<<aNbElem);
1329
1330   if(aNbElem <= 0) 
1331     throw std::runtime_error("LoadPoints >> There is no points in the mesh !!!");
1332
1333   SALOME_MED::double_array_var aCCoord = aMedMesh->getCoordinates(SALOME_MED::MED_FULL_INTERLACE);
1334   VISU::TCMEDCoordHolder* aCoordHolder = new VISU::TCMEDCoordHolder();
1335   aCoordHolder->Init(aNbElem, aDim, aCCoord);
1336
1337   VISU::TNamedPointCoords& aCoords = theMesh->myNamedPointCoords;
1338   aCoords.Init(VISU::PCoordHolder(aCoordHolder));
1339   
1340   if(MYDEBUG) MESSAGE("LoadPoints - Filling aMeshOnEntity with type NODE_ENTITY");
1341   
1342   VISU::TGeom2SubMesh& aGeom2SubMesh = aMeshOnEntity->myGeom2SubMesh;
1343   VISU::PSubMeshImpl aSubMesh = aGeom2SubMesh[VISU::ePOINT1](new VISU::TCSubMesh());
1344
1345   aSubMesh->myNbCells = theMesh->myNbPoints;
1346   aSubMesh->myCellsSize = 2*theMesh->myNbPoints;
1347
1348   VISU::TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
1349   aCell2Connect.resize(aNbElem);
1350   if(MYDEBUG) MESSAGE("LoadPoints - aNbElem="<<aNbElem);
1351   for(int iElem = 0; iElem < aNbElem; iElem++)
1352     aCell2Connect[iElem] = VISU::TConnect(1,iElem);
1353   
1354   theMesh->myIsDone = true;
1355
1356   return 1;
1357 }
1358
1359
1360 //---------------------------------------------------------------
1361 int 
1362 VISU_MEDConvertor
1363 ::LoadPointsOnFamily(VISU::PCMesh theMesh, 
1364                      VISU::PCFamily theFamily)
1365 {
1366   VISU::PCMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[VISU::NODE_ENTITY];
1367
1368   if(theFamily->myIsDone) 
1369     return 0;
1370
1371   vtkIdType aNbElem = theMesh->GetNbPoints();
1372   SALOME_MED::FAMILY_var aMedFamily = theFamily->myFamily;
1373   CORBA::Boolean anIsOnAllElements = aMedFamily->isOnAllElements();
1374   VISU::TSubMeshID& aSubMeshID = theFamily->myGeom2SubMeshID[VISU::ePOINT1];
1375   
1376   if(!anIsOnAllElements){
1377     SALOME_MED::medGeometryElement_array_var aGeom = aMedFamily->getTypes();
1378     SALOME_MED::long_array_var aCellNumForType = aMedFamily->getNumber(aGeom[0]);
1379     int aSize = aNbElem;
1380     aNbElem = aCellNumForType->length();
1381     for(int iElem = 0; iElem < aNbElem; iElem++){
1382       int anID = aCellNumForType[iElem] - 1;
1383       if(0 > anID || anID >= aSize){
1384         static QString aString;
1385         aString.sprintf("LoadPointsOnFamily - aSize(%d) <= aCellNumForType[%d] = %d < 0",aSize,iElem,anID);
1386         throw std::runtime_error((const char*)aString.toLatin1());
1387       }
1388       aSubMeshID.push_back(anID);
1389     }
1390   }else{
1391     for(int iElem = 0; iElem < aNbElem; iElem++){
1392       aSubMeshID.push_back(iElem);
1393     }
1394   }
1395   
1396   theFamily->myIsDone = true;
1397   
1398   return 1;
1399 }
1400
1401 //---------------------------------------------------------------
1402 namespace 
1403 {
1404   typedef MED::TCSlice<int> TA;
1405   //---------------------------------------------------------------
1406   typedef std::set<int> TConnSet;
1407   typedef std::vector<int> TIntArray;
1408   typedef MED::TCSlice<int> TConnSlice;
1409
1410   //---------------------------------------------------------------
1411   class MEDPolygonConnectivity //! retriver of polygon connectivity
1412   {
1413     TIntArray myConn;
1414     TIntArray myConnIndex;
1415   public:
1416
1417     MEDPolygonConnectivity(SALOME_MED::MESH_var theMesh,
1418                            SALOME_MED::medEntityMesh theEntity) 
1419     {
1420       {
1421         SALOME::SenderInt_var aSender = 
1422           theMesh->getSenderForPolygonsConnectivity(SALOME_MED::MED_NODAL, theEntity);
1423         long int aSize;
1424         int* aValuePtr = ReceiverFactory::getValue(aSender.in(), aSize);
1425         myConn.assign(aValuePtr, aValuePtr + aSize);
1426       }
1427       {
1428         SALOME::SenderInt_var aSender = 
1429           theMesh->getSenderForPolygonsConnectivityIndex(SALOME_MED::MED_NODAL, theEntity);
1430         long int aSize;
1431         int* aValuePtr = ReceiverFactory::getValue(aSender, aSize);
1432         myConnIndex.assign(aValuePtr, aValuePtr + aSize);
1433       }
1434     }
1435
1436     TConnSlice 
1437     GetConn(int theId) const 
1438     {
1439       int anOffSet = myConnIndex[theId] - 1;
1440       int aSize = myConnIndex[theId + 1] - myConnIndex[ theId ];
1441       return TConnSlice(&myConn[0], myConn.size(), std::slice(anOffSet, aSize, 1));
1442     }
1443
1444     int 
1445     GetNbElem() const 
1446     {
1447       return myConnIndex.size() - 1;
1448     }
1449
1450     int
1451     GetCellSize() const
1452     {
1453       return myConn.size() + GetNbElem();
1454     }
1455   };
1456
1457
1458   //---------------------------------------------------------------
1459   class MEDPolyhedraConnectivity //! retriver of polyhedron connectivity
1460   {
1461     TIntArray myConn;
1462     TIntArray myConnIndex;
1463     TIntArray myFaceIndex;
1464   public:
1465
1466     MEDPolyhedraConnectivity(SALOME_MED::MESH_var theMesh)
1467     {
1468       {
1469         SALOME::SenderInt_var aSender = 
1470           theMesh->getSenderForPolyhedronConnectivity(SALOME_MED::MED_NODAL);
1471         long int aSize;
1472         int* aValuePtr = ReceiverFactory::getValue(aSender, aSize);
1473         myConn.assign(aValuePtr, aValuePtr + aSize);
1474       }
1475       {
1476         SALOME::SenderInt_var aSender = 
1477           theMesh->getSenderForPolyhedronIndex(SALOME_MED::MED_NODAL);
1478         long int aSize;
1479         int* aValuePtr = ReceiverFactory::getValue(aSender, aSize);
1480         myConnIndex.assign(aValuePtr, aValuePtr + aSize);
1481       }
1482       {
1483         SALOME::SenderInt_var aSender = 
1484           theMesh->getSenderForPolyhedronFacesIndex();
1485         long int aSize;
1486         int* aValuePtr = ReceiverFactory::getValue(aSender, aSize);
1487         myFaceIndex.assign(aValuePtr, aValuePtr + aSize);
1488       }
1489     }
1490
1491     int
1492     GetUniqueConn(int theId, 
1493                   TConnSet& theConnSet) const 
1494     {
1495       theConnSet.clear();
1496       int aStartFaceId = myConnIndex[theId] - 1;
1497       int anEndFaceId = myConnIndex[theId + 1] - 2;
1498       int aStartConnId = myFaceIndex[aStartFaceId] - 1;
1499       int anEndConnId = myFaceIndex[anEndFaceId + 1] - 1;
1500       for(int aConnId = aStartConnId; aConnId < anEndConnId; aConnId++)
1501         theConnSet.insert(myConn[aConnId]);
1502       return theConnSet.size();
1503     }
1504
1505     int
1506     GetNbElem() const
1507     {
1508       return myConnIndex.size() - 1;
1509     }
1510
1511     int
1512     GetCellSize() const
1513     {
1514       TConnSet aConnSet;
1515       int aCellSize = 0;
1516       for(int anElemId = 0; anElemId < GetNbElem(); anElemId++)
1517         aCellSize += GetUniqueConn(anElemId, aConnSet);
1518       return aCellSize;
1519     }
1520   };
1521 }
1522
1523 //---------------------------------------------------------------
1524 int 
1525 VISU_MEDConvertor
1526 ::LoadCellsOnEntity(VISU::PCMesh theMesh,
1527                     VISU::PCMeshOnEntity theMeshOnEntity)
1528 {
1529   if(theMeshOnEntity->myIsDone) 
1530     return 0;
1531
1532   SALOME_MED::SUPPORT_var& aMedSupport = theMeshOnEntity->mySupport;
1533   SALOME_MED::MESH_var aMedMesh = aMedSupport->getMesh();
1534
1535   //Main part of code
1536   const VISU::TEntity& aVEntity = theMeshOnEntity->myEntity;
1537   const SALOME_MED::medEntityMesh& aMEntity = VTKEntityToMED(aVEntity);
1538   VISU::TCellsFirstIndex& aFirstIndex = theMeshOnEntity->myCellsFirstIndex;
1539
1540   SALOME_MED::MESH::connectivityInfos_var anInfo = aMedMesh->getConnectGlobal(aMEntity);
1541   int iGeomEnd = anInfo->meshTypes.length();
1542
1543   VISU::TGeom2SubMesh& aGeom2SubMesh = theMeshOnEntity->myGeom2SubMesh;
1544   vtkIdType aNbPoints = theMesh->GetNbPoints();
1545
1546   for(int iGeom = 0, aCounter = 0; iGeom < iGeomEnd; iGeom++) {
1547     SALOME_MED::medGeometryElement aMGeom = anInfo->meshTypes[iGeom];
1548     VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
1549     switch (aMGeom) {
1550     case SALOME_MED::MED_POLYGON:
1551     {
1552       MEDPolygonConnectivity aConn(aMedMesh, aMEntity);
1553       int aNbElem = aConn.GetNbElem();
1554       if (aNbElem > 0) {
1555         VISU::PSubMeshImpl aSubMesh = aGeom2SubMesh[aEGeom](new VISU::TCSubMesh());
1556         aSubMesh->myNbCells   = aNbElem;
1557         aSubMesh->myCellsSize = aConn.GetCellSize();
1558
1559         VISU::TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
1560         aCell2Connect.resize(aNbElem);
1561
1562         for(int iElem = 0; iElem < aNbElem; iElem++) {
1563           TConnSlice aConnSlice = aConn.GetConn(iElem);
1564           VISU::TConnect& anArray = aCell2Connect[iElem];
1565           anArray.resize(aConnSlice.size());
1566           for(int iConn = 0; iConn < aConnSlice.size(); iConn++)
1567             anArray[iConn] = aConnSlice[iConn] - 1;
1568         }
1569       }
1570     }
1571     break;
1572     case SALOME_MED::MED_POLYHEDRA:
1573     {
1574       MEDPolyhedraConnectivity aConn( aMedMesh );
1575       int aNbElem = aConn.GetNbElem();
1576       if (aNbElem > 0) {
1577         VISU::PSubMeshImpl aSubMesh = aGeom2SubMesh[aEGeom](new VISU::TCSubMesh());
1578         aSubMesh->myNbCells = aNbElem;
1579         aSubMesh->myCellsSize = aConn.GetCellSize();
1580
1581         VISU::TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
1582         aCell2Connect.resize(aNbElem);
1583
1584         TConnSet aConnectSet;
1585         for(int iElem = 0; iElem < aNbElem; iElem++){
1586           if(aConn.GetUniqueConn(iElem, aConnectSet)){
1587             int aNbConn = aConnectSet.size();
1588             VISU::TConnect& anArray = aCell2Connect[iElem];
1589             anArray.resize(aNbConn);
1590             std::set<int>::iterator anIter = aConnectSet.begin();
1591             for(int i = 0; anIter != aConnectSet.end(); anIter++, i++)
1592               anArray[i] = *anIter - 1;
1593           }
1594         }
1595       }
1596     }
1597     break;
1598     default:
1599     {        
1600       int aMNbNodes = MEDGeom2NbNodes(aMGeom);
1601       int aVNbNodes = VISUGeom2NbNodes(aEGeom);
1602       int aNbElem = anInfo->numberOfElements[iGeom];
1603       if (aNbElem > 0) {
1604         SALOME_MED::long_array_var aConn = 
1605           aMedMesh->getConnectivity(SALOME_MED::MED_FULL_INTERLACE,
1606                                     SALOME_MED::MED_NODAL,
1607                                     aMEntity,
1608                                     aMGeom);
1609         VISU::PSubMeshImpl aSubMesh = aGeom2SubMesh[aEGeom](new VISU::TCSubMesh());
1610
1611         aSubMesh->myNbCells = aNbElem;
1612         aSubMesh->myCellsSize = aNbElem*(aVNbNodes+1);
1613
1614         VISU::TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
1615         std::vector<int> aConnect(aMNbNodes);
1616         int aNbConnForElem = aConn->length() / aNbElem;
1617
1618         if(MYDEBUG) MESSAGE("LoadCellsOnEntity - aMGeom = "<<aMGeom<<
1619                             "; aNbElem = "<<aNbElem<<
1620                             "; aMNbNodes = "<<aMNbNodes<<
1621                             "; aVNbNodes = "<<aVNbNodes<<
1622                             "; aNbConnForElem = "<<aNbConnForElem);
1623
1624         for(int iElem = 0; iElem < aNbElem; iElem++) {
1625           VISU::TConnect anArray(aVNbNodes);
1626           for(int k = 0, kj = iElem*aNbConnForElem; k < aMNbNodes; k++)
1627             aConnect[k] = aConn[kj+k] - 1;
1628
1629           switch(aMGeom){
1630 #if !(defined(VTK_QUADRATIC_EDGE) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
1631           case SALOME_MED::MED_SEG3:
1632             anArray[0] = aConnect[0];
1633             anArray[2] = aConnect[1];  
1634
1635             anArray[1] = aConnect[2];
1636             break;
1637 #endif
1638 #if !(defined(VTK_QUADRATIC_TRIANGLE) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
1639           case SALOME_MED::MED_TRIA6:
1640             anArray[0] = aConnect[0];
1641             anArray[2] = aConnect[1];  
1642             anArray[4] = aConnect[2];  
1643
1644             anArray[1] = aConnect[3];
1645             anArray[3] = aConnect[4];  
1646             anArray[5] = aConnect[5];  
1647             break;
1648 #endif
1649 #if !(defined(VTK_QUADRATIC_QUAD) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
1650           case SALOME_MED::MED_QUAD8:
1651             anArray[0] = aConnect[0];
1652             anArray[2] = aConnect[1];  
1653             anArray[4] = aConnect[2];  
1654             anArray[6] = aConnect[3];  
1655
1656             anArray[1] = aConnect[4];
1657             anArray[3] = aConnect[5];  
1658             anArray[5] = aConnect[6];  
1659             anArray[7] = aConnect[7];  
1660             break;
1661 #endif
1662 #if (defined(VTK_QUADRATIC_TETRA) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
1663           case SALOME_MED::MED_TETRA10 :
1664 #endif
1665           case SALOME_MED::MED_TETRA4 :
1666             anArray[0] = aConnect[0];
1667             anArray[1] = aConnect[1];
1668             anArray[2] = aConnect[3];  
1669             anArray[3] = aConnect[2];  
1670             break;
1671 #if (defined(VTK_QUADRATIC_PYRAMID) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
1672           case SALOME_MED::MED_PYRA13:
1673 #endif
1674           case SALOME_MED::MED_PYRA5 :
1675             anArray[0] = aConnect[0];
1676             anArray[1] = aConnect[3];  
1677             anArray[2] = aConnect[2];
1678             anArray[3] = aConnect[1];  
1679             anArray[4] = aConnect[4];
1680             break;
1681           default:
1682             for (int k = 0; k < aVNbNodes; k++) 
1683               anArray[k] = aConnect[k];
1684           }
1685           for (int k = 0; k < aVNbNodes; k++) 
1686             if(anArray[k] < 0 || aNbPoints <= anArray[k]){
1687               static QString aString;
1688               aString.sprintf("LoadCellsOnEntity >> aNbPoints(%d) <= anArray[%d][%d]=%d < 0 !!!",int(aNbPoints),iElem,k,anArray[k]);
1689               throw std::runtime_error((const char*)aString.toLatin1());
1690             }
1691           aCell2Connect.push_back(anArray);
1692         } // loop on elements
1693       }
1694     }} // switch( aMGeom )
1695     VISU::TGeom2SubMesh::iterator anIter = aGeom2SubMesh.find(aEGeom);
1696     if(anIter != aGeom2SubMesh.end()){
1697       const VISU::PSubMeshImpl& aSubMesh = anIter->second;
1698       const VISU::TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
1699       int aSize = aCell2Connect.size();
1700       if(MYDEBUG) MESSAGE("LoadCellsOnEntity - aCounter = "<<aCounter<<"; aSize = "<<aSize<<"; aMGeom = "<<aMGeom);
1701       aFirstIndex[aMGeom] = VISU::TIndexAndSize(aCounter, aSize);
1702       aCounter += aSize;
1703     }
1704   } //loop on types
1705
1706   // Dump result connectivity
1707 // #ifdef _DEBUG_
1708 //   TGeom2SubMesh::iterator geom_sm = aGeom2SubMesh.begin();
1709 //   for ( ; geom_sm!=aGeom2SubMesh.end(); ++geom_sm ) {
1710 //     cout << "TYPE: " << geom_sm->first << endl;
1711 //     PSubMeshImpl aSubMesh = geom_sm->second;
1712 //     TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
1713 //     TCell2Connect::iterator id_conn = aCell2Connect.begin();
1714 //     for ( int i = 0; id_conn !=aCell2Connect.end(); ++id_conn ) {
1715 //       cout << "\t" << i++ << ": [";
1716 //       TConnect& anArray = *id_conn;
1717 //       TConnect::iterator n = anArray.begin();
1718 //       for ( ; n != anArray.end(); ++n )
1719 //         cout << " " << *n + 1;
1720 //       cout << " ]"<< endl;
1721 //     }
1722 //   }
1723 // #endif
1724
1725   theMeshOnEntity->myIsDone = true;
1726
1727   return 1;
1728 }
1729
1730
1731 //---------------------------------------------------------------
1732 int 
1733 VISU_MEDConvertor
1734 ::LoadCellsOnFamily(VISU::PCMesh theMesh,
1735                     VISU::PCMeshOnEntity theMeshOnEntity, 
1736                     VISU::PCFamily theFamily)
1737 {
1738   if(theFamily->myIsDone) 
1739     return 0;
1740
1741   SALOME_MED::FAMILY_var aMedFamily = theFamily->myFamily;
1742   CORBA::Boolean anIsOnAllElements = aMedFamily->isOnAllElements();
1743   if(!anIsOnAllElements){
1744     SALOME_MED::medGeometryElement_array_var aGeoms = aMedFamily->getTypes();
1745     int iGeomEnd = aGeoms->length();
1746     if(MYDEBUG) MESSAGE("LoadCellsOnFamily - iGeomEnd = "<<iGeomEnd);
1747     for(int iGeom = 0; iGeom < iGeomEnd; iGeom++){
1748       SALOME_MED::medGeometryElement aMGeom = aGeoms[iGeom];
1749       SALOME_MED::long_array_var aCellNumForType = aMedFamily->getNumber(aMGeom);
1750       VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
1751
1752       int aNbElem = aCellNumForType->length();
1753       int aCounter = theMeshOnEntity->myCellsFirstIndex[aMGeom].first;
1754       int aSize = theMeshOnEntity->myCellsFirstIndex[aMGeom].second;
1755       VISU::TSubMeshID& aSubMeshID = theFamily->myGeom2SubMeshID[aEGeom]; 
1756       
1757       if(MYDEBUG) 
1758         MESSAGE("LoadCellsOnFamily "<<
1759                 "- aMGeom = "<<aMGeom<<
1760                 "; aNbElem = "<<aNbElem<<
1761                 "; aSize = "<<aSize<<
1762                 "; aCounter = "<<aCounter);
1763       
1764       for(int iElem = 0; iElem < aNbElem; iElem++){
1765         int anID = aCellNumForType[iElem] - aCounter - 1;
1766         if(0 > anID || anID >= aSize){
1767           static QString aString;
1768           aString.sprintf("LoadCellsOnFamily - aNbElem(%d) <= aCellNumForType[%d] = %d < 0 !!!",aNbElem,iElem,anID);
1769           throw std::runtime_error((const char*)aString.toLatin1());
1770         }
1771         aSubMeshID.push_back(anID);
1772       }
1773     }
1774   }else{
1775     const VISU::TGeom2SubMesh& aGeom2SubMesh = theMeshOnEntity->myGeom2SubMesh;
1776     VISU::TGeom2SubMesh::const_iterator anIter = aGeom2SubMesh.begin();
1777     for(; anIter != aGeom2SubMesh.end(); anIter++){
1778       VISU::EGeometry aEGeom = anIter->first;
1779       const VISU::TSubMeshImpl& aSubMesh = anIter->second;
1780       const VISU::TCell2Connect& aCell2Connect = aSubMesh.myCell2Connect;
1781       VISU::TSubMeshID& aSubMeshID = theFamily->myGeom2SubMeshID[aEGeom];
1782       int iNumElemEnd = aCell2Connect.size();
1783       for(int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
1784         aSubMeshID.push_back(iNumElem);
1785     }
1786   }
1787   
1788   theFamily->myIsDone = true;
1789
1790   return 1;
1791 }
1792
1793
1794 template<class TValueType,
1795          class TContainerType> 
1796 void 
1797 ImportField(TContainerType& theContainer, 
1798             VISU::PCMesh theMesh,
1799             VISU::PCField theField,
1800             VISU::PCValForTime theValForTime,
1801             VISU::PCMeshOnEntity theMeshOnEntity)
1802 {
1803   typedef VISU::TTCMEDMeshValue<TValueType, TContainerType> TVMeshValue;
1804   vtkIdType aNbComp = theField->myNbComp;
1805   if(theField->myEntity == VISU::NODE_ENTITY){
1806     VISU::EGeometry aEGeom = VISU::ePOINT1;
1807     vtkIdType aNbGauss = theValForTime->GetNbGauss(aEGeom);
1808     vtkIdType aNbElem = theMesh->GetNbPoints();
1809
1810     if(MYDEBUG) MESSAGE("ImportField - aNbElem = "<<aNbElem);
1811
1812     VISU::PMeshValue& aVMeshValue = theValForTime->GetMeshValue(VISU::ePOINT1);
1813     TVMeshValue* aMeshValue = new TVMeshValue();
1814     aMeshValue->Init(aNbElem, aNbGauss, aNbComp, theContainer, 0);
1815     aVMeshValue.reset(aMeshValue);
1816   }else{
1817     SALOME_MED::medGeometryElement* aGeomElems;
1818     const VISU::TEntity& aVEntity = theField->myEntity;
1819     int iGeomEnd = GetEntity2Geom(aVEntity,aGeomElems);
1820     for(int iGeom = 0; iGeom < iGeomEnd; iGeom++){
1821       SALOME_MED::medGeometryElement aMGeom = aGeomElems[iGeom];
1822       VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
1823       vtkIdType aNbGauss = theValForTime->GetNbGauss(aEGeom);
1824       const VISU::TCellsFirstIndex& aCellsFirstIndex = theMeshOnEntity->myCellsFirstIndex;
1825       VISU::TCellsFirstIndex::const_iterator aCellsFirstIndexIter = aCellsFirstIndex.find(aMGeom);
1826       if(aCellsFirstIndexIter != aCellsFirstIndex.end()){
1827         const VISU::TIndexAndSize& aIndexAndSize = aCellsFirstIndexIter->second;
1828         if(MYDEBUG) 
1829           MESSAGE("ImportField - aMGeom = "<<aMGeom<<
1830                   "; aIndexAndSize = {"<<aIndexAndSize.first<<
1831                   ","<<aIndexAndSize.second<<"}");
1832
1833         vtkIdType aNbElem = aIndexAndSize.second;
1834         vtkIdType aStart = aIndexAndSize.first * aNbComp;
1835         VISU::PMeshValue& aVMeshValue = theValForTime->GetMeshValue(aEGeom);
1836         TVMeshValue* aMeshValue = new TVMeshValue();
1837         aMeshValue->Init(aNbElem, aNbGauss, aNbComp, theContainer, aStart);
1838         aVMeshValue.reset(aMeshValue);
1839       }
1840     }
1841   }
1842 }
1843
1844 int
1845 VISU_MEDConvertor
1846 ::LoadField(VISU::PCMesh theMesh,
1847             VISU::PCMeshOnEntity theMeshOnEntity,
1848             VISU::PField theField, 
1849             VISU::PCValForTime theValForTime)
1850 {
1851   MESSAGE("VISU_MEDConvertor::LoadField");
1852   //Check on loading already done
1853   VISU::PUnstructuredGridIDMapperImpl anUnstructuredGridIDMapper = theValForTime->myUnstructuredGridIDMapper;
1854   if(anUnstructuredGridIDMapper->myIsVTKDone) 
1855     return 0;
1856   
1857   VISU::PCProfile aProfile(new VISU::TCProfile());
1858   aProfile->myIsAll = true;
1859   theValForTime->myProfile = aProfile;
1860
1861   SALOME_MED::FIELD_var aMEDField = theValForTime->myField;
1862
1863   SALOME_MED::SUPPORT_var aMEDSupport = aMEDField->getSupport();
1864
1865   if(aMEDSupport->isOnAllElements()) aProfile->myIsDone = true;
1866   
1867   SALOME_MED::FIELDDOUBLE_ptr aFieldDouble = SALOME_MED::FIELDDOUBLE::_narrow(aMEDField);
1868   if(!aFieldDouble->_is_nil()){
1869     SALOME_MED::double_array_var anArray = aFieldDouble->getValue(SALOME_MED::MED_FULL_INTERLACE);
1870     if(MYDEBUG) MESSAGE("VISU_MEDConvertor::LoadField - There is FIELDDOUBLE = "<<anArray->length());
1871     ImportField<CORBA::Double>(anArray,
1872                                theMesh,
1873                                theField,
1874                                theValForTime,
1875                                theMeshOnEntity);
1876   }
1877
1878   SALOME_MED::FIELDINT_ptr aFieldInt = SALOME_MED::FIELDINT::_narrow(aMEDField);
1879   if(!aFieldInt->_is_nil()){
1880     SALOME_MED::long_array_var anArray = aFieldInt->getValue(SALOME_MED::MED_FULL_INTERLACE);
1881     if(MYDEBUG) MESSAGE("VISU_MEDConvertor::LoadField - There is FIELDINT = "<<anArray->length());
1882     ImportField<CORBA::Long>(anArray,
1883                              theMesh,
1884                              theField,
1885                              theValForTime,
1886                              theMeshOnEntity);
1887   }
1888
1889   anUnstructuredGridIDMapper->myIsVTKDone = true;
1890
1891   MESSAGE("VISU_MEDConvertor::LoadField done");
1892   return 1;
1893 }