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