Salome HOME
The fix solve problem with NonRegression Test execition for 001/L0 -L7 cases.
[modules/visu.git] / src / VISU_I / VISU_CorbaMedConvertor.cxx
1 //  VISU OBJECT : interactive object for VISU entities implementation
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : VISU_CorbaMedConvertor.cxx
25 //  Author : Alexey PETROV
26 //  Module : VISU
27 //  $Header$
28 //  Copyright (C) 2003  CEA/DEN, EDF R&D
29
30 #include "VISU_CorbaMedConvertor.hxx"
31
32 #include <vtkCellType.h>
33
34 #include <boost/tuple/tuple.hpp>
35
36 using namespace std;
37 using namespace VISU;
38
39 #define USER_INTERLACE MED_FULL_INTERLACE
40
41 #ifdef _DEBUG_
42 static int MYDEBUG = 0;
43 #else
44 static int MYDEBUG = 0;
45 #endif
46
47 extern "C" {
48   VISU_Convertor* 
49   CreateMEDConvertor(SALOMEDS::SObject_ptr theMedSObject) 
50   {
51     return new VISU_MEDConvertor(theMedSObject);
52   }
53
54   VISU_Convertor* 
55   CreateMEDFieldConvertor(SALOME_MED::FIELD_ptr theField) 
56   {
57     return new VISU_MEDFieldConvertor(theField);
58   }
59 }
60
61 namespace{
62   using namespace SALOME_MED;
63   
64   const int MED_NBR_GEOMETRIE_MAILLE = 15;
65   
66   medGeometryElement 
67   CELLGEOM[MED_NBR_GEOMETRIE_MAILLE] = {
68     MED_POINT1,
69     MED_SEG2,
70     MED_SEG3,
71     MED_TRIA3,
72     MED_QUAD4,
73     MED_TRIA6,
74     MED_QUAD8,
75     MED_TETRA4,
76     MED_PYRA5,
77     MED_PENTA6,
78     MED_HEXA8,
79     MED_TETRA10,
80     MED_PYRA13,
81     MED_PENTA15,
82     MED_HEXA20
83   };
84   
85   const int MED_NBR_GEOMETRIE_FACE = 4;
86   
87   medGeometryElement
88   FACEGEOM[MED_NBR_GEOMETRIE_FACE] = {
89     MED_TRIA3,
90     MED_QUAD4,
91     MED_TRIA6,
92     MED_QUAD8
93   };
94   
95   const int MED_NBR_GEOMETRIE_ARETE = 2;
96   
97   medGeometryElement
98   EDGEGEOM[MED_NBR_GEOMETRIE_ARETE] = {
99     MED_SEG2,
100     MED_SEG3
101   };
102   
103   const int MED_NBR_GEOMETRIE_NODE = 1;
104   
105   medGeometryElement
106   NODEGEOM[MED_NBR_GEOMETRIE_NODE] = {
107     MED_POINT1,
108   };
109   
110   int GetEntity2Geom(const VISU::TEntity& theEntity, medGeometryElement*& theVector)
111   {
112     switch(theEntity){
113     case CELL_ENTITY: theVector = CELLGEOM; return MED_NBR_GEOMETRIE_MAILLE; break;
114     case FACE_ENTITY: theVector = FACEGEOM; return MED_NBR_GEOMETRIE_FACE; break;
115     case EDGE_ENTITY: theVector = EDGEGEOM; return MED_NBR_GEOMETRIE_ARETE; break;
116     case NODE_ENTITY: theVector = NODEGEOM; return MED_NBR_GEOMETRIE_NODE; break;
117     }
118     return -1;
119   }
120   
121   int MEDGeom2NbNodes(int theMEDGeomType)
122   { 
123     switch(theMEDGeomType){
124     case MED_NONE: return 0;
125     case MED_POINT1: return 1;
126     case MED_SEG2: return 2;
127     case MED_SEG3: return 3;
128     case MED_TRIA3: return 3;
129     case MED_TRIA6: return 6;
130     case MED_QUAD4: return 4;
131     case MED_QUAD8: return 8;
132     case MED_TETRA4: return 4;
133     case MED_TETRA10: return 10;
134     case MED_HEXA8: return 8;
135     case MED_HEXA20: return 20;
136     case MED_PENTA6: return 6;
137     case MED_PENTA15: return 15;
138     case MED_PYRA5: return 5;
139     case MED_PYRA13: return 13;
140     }
141     return -1;
142   }
143   
144   int MEDGeomToVTK(medGeometryElement theMEDGeomType)
145   { 
146     switch(theMEDGeomType){
147     case MED_NONE: return VTK_EMPTY_CELL;
148     case MED_POINT1: return VTK_VERTEX;
149     case MED_SEG2: return VTK_LINE;
150     case MED_SEG3: return VTK_LINE;
151     case MED_TRIA3: return VTK_TRIANGLE;
152     case MED_TRIA6: return VTK_TRIANGLE;
153     case MED_QUAD4: return VTK_QUAD;
154     case MED_QUAD8: return VTK_QUAD;
155     case MED_TETRA4: return VTK_TETRA;
156     case MED_TETRA10: return VTK_TETRA;
157     case MED_HEXA8: return VTK_HEXAHEDRON;
158     case MED_HEXA20: return VTK_HEXAHEDRON;
159     case MED_PENTA6: return VTK_WEDGE;
160     case MED_PENTA15: return VTK_WEDGE;
161     case MED_PYRA5: return VTK_PYRAMID;
162     case MED_PYRA13: return VTK_PYRAMID;
163     }
164     return -1;
165   }
166   
167   int VTKGeom2NbNodes(int theVTKGeomType)
168   { 
169     switch(theVTKGeomType){
170     case VTK_VERTEX: return 1;
171     case VTK_LINE: return 2;
172     case VTK_TRIANGLE: return 3;
173     case VTK_QUAD: return 4;
174     case VTK_TETRA: return 4;
175     case VTK_HEXAHEDRON: return 8;
176     case VTK_WEDGE: return 6;
177     case VTK_PYRAMID: return 5;
178     }
179     return -1;
180   }
181   
182   medGeometryElement VTKGeomToMED(int theVTKGeomType)
183   { 
184     switch(theVTKGeomType){
185     case VTK_VERTEX: return MED_POINT1;
186     case VTK_LINE: return MED_SEG2;
187     case VTK_TRIANGLE: return MED_TRIA3;
188     case VTK_QUAD: return MED_QUAD4;
189     case VTK_TETRA: return MED_TETRA4;
190     case VTK_HEXAHEDRON: return MED_HEXA8;
191     case VTK_WEDGE: return MED_PENTA6;
192     case VTK_PYRAMID: return MED_PYRA5;
193     }
194     return medGeometryElement(-1);
195   }
196   
197   VISU::TEntity MEDEntityToVTK(medEntityMesh theMEDEntity)
198   {
199     switch(theMEDEntity){
200     case MED_NODE: return NODE_ENTITY;
201     case MED_EDGE: return EDGE_ENTITY;
202     case MED_FACE: return FACE_ENTITY;
203     case MED_CELL: return CELL_ENTITY;
204     }
205     return VISU::TEntity(-1);
206   }
207   
208   medEntityMesh VTKEntityToMED(VISU::TEntity theVTKEntity)
209   {
210     switch(theVTKEntity){
211     case NODE_ENTITY: return MED_NODE;
212     case EDGE_ENTITY: return MED_EDGE;
213     case FACE_ENTITY: return MED_FACE;
214     case CELL_ENTITY: return MED_CELL;
215     }
216     return medEntityMesh(-1);
217   }
218   
219   string GetSObjectName(SALOMEDS::SObject_ptr aSObject){
220     SALOMEDS::GenericAttribute_var anAttr;
221     if (aSObject->FindAttribute(anAttr,"AttributeName")) {
222       SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
223       CORBA::String_var aString = aName->Value();
224       return aString.in();
225     }
226     return "";
227   }
228   
229   void 
230   GetCellsSize(vtkIdType& theNbCells, vtkIdType& theCellsSize,
231                SALOME_MED::MESH_ptr theMEDMesh,
232                const VISU::TEntity& theVEntity)
233   {
234     medGeometryElement* aGeomElems;
235     theNbCells = theCellsSize = 0;
236     int iGeomEnd = GetEntity2Geom(theVEntity,aGeomElems);
237     const medEntityMesh& aMEntity = VTKEntityToMED(theVEntity);
238     if(MYDEBUG) MESSAGE("GetCellsSize - theVEntity = "<<theVEntity);
239       for(int iGeom = 0; iGeom < iGeomEnd; iGeom++){
240         medGeometryElement aMEDGeom = aGeomElems[iGeom];
241         int iNumElemEnd = theMEDMesh->getNumberOfElements(aMEntity,aMEDGeom);
242         if(iNumElemEnd > 0){
243           if(MYDEBUG) MESSAGE("GetCellsSize - iNumElemEnd = "<<iNumElemEnd);
244           theCellsSize += iNumElemEnd*(MEDGeom2NbNodes(aMEDGeom) + 1);
245           theNbCells += iNumElemEnd;
246         }
247       }
248   }
249   
250   
251   void 
252   GetCellsSize(vtkIdType& theNbCells, vtkIdType& theCellsSize,
253                SALOME_MED::FAMILY_ptr theMEDFamily)
254   {
255     medGeometryElement_array_var aGeom = theMEDFamily->getTypes();
256     int iGeomEnd = aGeom->length();
257     theNbCells = theCellsSize = 0;
258     if(MYDEBUG) MESSAGE("GetCellsSize - iGeomEnd = "<<iGeomEnd);
259     for(int iGeom = 0; iGeom < iGeomEnd; iGeom++) {
260       medGeometryElement aMEDGeom = aGeom[iGeom];
261       long_array_var aCellNumForType = theMEDFamily->getNumber(aMEDGeom);
262       int iNumElemEnd = aCellNumForType->length();
263       if(iNumElemEnd > 0){
264         if(MYDEBUG) MESSAGE("GetCellsSize - iNumElemEnd = "<<iNumElemEnd);
265         theNbCells += iNumElemEnd;
266         theCellsSize += iNumElemEnd*(MEDGeom2NbNodes(aMEDGeom) + 1);
267       }
268     }
269   }
270   
271   
272   void
273   GetCellsSize(VISU::PCMesh theMesh, 
274                SALOME_MED::MESH_ptr theMEDMesh, 
275                const VISU::TEntity& theEntity)
276   {
277     TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap;
278     VISU::PCMeshOnEntity aMeshOnEntity = aMeshOnEntityMap[theEntity];
279     if(theEntity == NODE_ENTITY){
280       theMesh->myNbPoints = theMEDMesh->getNumberOfNodes();
281       aMeshOnEntity->myNbCells = theMesh->myNbPoints;
282       aMeshOnEntity->myCellsSize = 2*theMesh->myNbPoints;
283       vtkIdType aNbCells, aCellsSize;
284       GetCellsSize(aNbCells,aCellsSize,theMEDMesh,CELL_ENTITY);
285       if(aNbCells > 0){
286         
287         TMeshOnEntityMap::iterator aIter = aMeshOnEntityMap.find(CELL_ENTITY);
288         if (aIter != aMeshOnEntityMap.end()){
289           VISU::PCMeshOnEntity aMeshOnCells = aIter->second;
290         
291           aMeshOnCells->myEntity = VISU::CELL_ENTITY;
292           aMeshOnCells->myMeshName = theMesh->myName;
293           aMeshOnCells->myNbCells = aNbCells;
294           aMeshOnCells->myCellsSize = aCellsSize;
295         }
296       }
297     }else{
298       GetCellsSize(aMeshOnEntity->myNbCells,aMeshOnEntity->myCellsSize,theMEDMesh,theEntity);
299     }
300   }
301   
302 }
303
304
305 VISU_Convertor* 
306 VISU_MEDFieldConvertor::Build()
307 {
308   if(myField->_is_nil()) 
309     throw std::runtime_error("VISU_MEDFieldConvertor::Build >> myField->_is_nil() !!!");
310   
311   SALOME_MED::SUPPORT_var aMEDSupport = myField->getSupport();
312   if(aMEDSupport->_is_nil()) 
313     throw std::runtime_error("VISU_MEDFieldConvertor::Build >> aMEDSupport->_is_nil() !!!");
314
315   SALOME_MED::medEntityMesh aMEntity = aMEDSupport->getEntity();
316   TEntity aVEntity = MEDEntityToVTK(aMEntity);
317   SALOME_MED::MESH_var aMEDMesh = aMEDSupport->getMesh();
318   if(aMEDMesh->_is_nil()) 
319     throw std::runtime_error("VISU_MEDFieldConvertor::Build >> aMEDMesh->_is_nil() !!!");
320
321   CORBA::String_var aMeshName = aMEDMesh->getName();
322   CORBA::String_var aFieldName = myField->getName();
323
324   PCMesh aMesh = myMeshMap[aMeshName.in()](new TCMesh());
325   aMesh->myDim = aMEDMesh->getSpaceDimension();
326   aMesh->myPointsDim.resize(aMesh->myDim);
327   aMesh->myName = aMeshName.in();
328   aMesh->myMesh = aMEDMesh;
329
330   if(MYDEBUG) MESSAGE("VISU_MEDFieldConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh->myDim);
331
332   TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
333   PCMeshOnEntity aMeshOnEntity = aMeshOnEntityMap[aVEntity](new TCMeshOnEntity());
334   aMeshOnEntity->myEntity = aVEntity;
335   aMeshOnEntity->myMeshName = aMeshName.in();
336   aMeshOnEntity->mySupport = aMEDSupport;
337
338   if(aVEntity == NODE_ENTITY){
339     PCMeshOnEntity aMeshOnEntity2 = aMeshOnEntityMap[CELL_ENTITY](new TCMeshOnEntity());
340     *aMeshOnEntity2 = *aMeshOnEntity;
341     aMeshOnEntity->myEntity = CELL_ENTITY;
342     GetCellsSize(aMesh,aMEDMesh,CELL_ENTITY);
343   }else{
344     PCMeshOnEntity aMeshOnEntity2 = aMeshOnEntityMap[NODE_ENTITY](new TCMeshOnEntity());
345     *aMeshOnEntity2 = *aMeshOnEntity;
346     aMeshOnEntity->myEntity = NODE_ENTITY;
347     GetCellsSize(aMesh,aMEDMesh,NODE_ENTITY);
348   }
349   GetCellsSize(aMesh,aMEDMesh,aVEntity);
350
351   TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
352   PCField aField = aFieldMap[aFieldName.in()](new TCField());
353   aField->myId = myField->getOrderNumber();
354   aField->myName = aFieldName.in();
355   aField->myEntity = aVEntity;
356   aField->myMeshName = aMeshName.in();
357   aField->myNbComp = myField->getNumberOfComponents();
358   aField->myDataSize = aMeshOnEntity->myNbCells * aField->myNbComp;
359   aField->myCompNames.resize(aField->myNbComp);
360   aField->myUnitNames.resize(aField->myNbComp);
361
362   if(MYDEBUG) MESSAGE("VISU_MEDFieldConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh->myDim);
363
364   TValField& aValField = aField->myValField;
365   int anId = myField->getIterationNumber();
366   PCValForTime aValForTime = aValField[anId](new TCValForTime());
367   aValForTime->myId = anId;
368   CORBA::Double aDT = myField->getTime();
369   aValForTime->myTime = TTime(aDT,"");
370   aValForTime->myField = myField;
371
372   if(MYDEBUG) 
373     MESSAGE("VISU_MEDFieldConvertor::Build - aFieldName = '"<<aFieldName<<
374             "'; myId = "<<anId<<"; myTime = "<<aDT);
375
376   return this;
377 }
378
379
380 VISU_Convertor* 
381 VISU_MEDConvertor::Build() 
382 {
383   if(mySObject->_is_nil()) 
384     throw std::runtime_error("VISU_MEDConvertor::Build >> mySObject->_is_nil() !!!");
385   SALOMEDS::Study_var aStudy = mySObject->GetStudy();
386
387   CORBA::Object_var aMedObject = VISU::SObjectToObject(mySObject);
388   if(!CORBA::is_nil(aMedObject)){
389     SALOME_MED::MED_var aMED = SALOME_MED::MED::_narrow(aMedObject);
390     return Build(aMED);
391   }
392
393   SALOMEDS::ChildIterator_var aTimeStampIterator = aStudy->NewChildIterator(mySObject);
394   return Build(aTimeStampIterator);
395 }
396
397 namespace{
398
399   using namespace boost;
400
401   struct TSObjectByName{
402     std::string myName;
403     typedef tuple<SALOMEDS::SObject_var> TRet;
404
405     TSObjectByName(const std::string& theName):
406       myName(theName)
407     {}
408
409     TRet operator()(SALOMEDS::SObject_ptr theSObj, bool& theIsSuccess)
410     {
411       SALOMEDS::GenericAttribute_var anAttr;
412       if(theSObj->FindAttribute(anAttr,"AttributeName")){
413         SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
414         CORBA::String_var aValue = aName->Value();
415         theIsSuccess = (myName == aValue.in());
416         if(theIsSuccess)
417           return TRet(SALOMEDS::SObject::_duplicate(theSObj));
418       }
419       return TRet();
420     }
421
422   };
423
424   struct TMeshByName{
425     std::string myName;
426     typedef tuple<SALOME_MED::MESH_var,SALOMEDS::SObject_var> TRet;
427
428     TMeshByName(const std::string& theName):
429       myName(theName)
430     {}
431
432     TRet operator()(SALOMEDS::SObject_ptr theSObj, bool& theIsSuccess)
433     {
434       CORBA::Object_var anObj = VISU::SObjectToObject(theSObj);
435       if(!CORBA::is_nil(anObj)){
436         SALOME_MED::MESH_var aMesh = SALOME_MED::MESH::_narrow(anObj);
437         if(!CORBA::is_nil(aMesh)){
438           CORBA::String_var aName = aMesh->getName();
439           theIsSuccess = (myName == aName.in());
440           if(theIsSuccess)
441             return TRet(aMesh,SALOMEDS::SObject::_duplicate(theSObj));
442         }
443       }
444       return TRet();
445     }
446   };
447
448   template<typename TFun>
449   typename TFun::TRet
450   Find(SALOMEDS::SObject_ptr theStartSObj, 
451        SALOMEDS::Study_ptr theStudy,
452        TFun theFun,
453        bool& theIsSuccess,
454        bool theIsAllLevels = true)
455   {
456     SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator(theStartSObj);
457     anIter->InitEx(theIsAllLevels);
458     for(; anIter->More(); anIter->Next()){
459       SALOMEDS::SObject_var aSObj = anIter->Value();
460       typename TFun::TRet aRet = theFun(aSObj,theIsSuccess);
461       if(theIsSuccess)
462         return aRet;
463     }
464     return typename TFun::TRet();
465   }
466
467 }
468
469 VISU_Convertor* 
470 VISU_MEDConvertor::Build(SALOME_MED::MED_ptr theMED)
471 {
472   if(CORBA::is_nil(theMED)) 
473     return NULL;
474
475   CORBA::Long aNbMeshes = theMED->getNumberOfMeshes();
476   SALOME_MED::string_array_var aMeshNames = theMED->getMeshNames();
477   if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aNbMeshes = "<<aNbMeshes);
478
479   SALOMEDS::Study_var aStudy = mySObject->GetStudy();
480   SALOMEDS::SObject_var aMedCompSObj = mySObject->GetFather();
481
482   bool anIsSuccess = false;
483   TSObjectByName::TRet aSObjectByNameRet = 
484     Find(aMedCompSObj,aStudy,TSObjectByName("MEDMESH"),anIsSuccess);
485   if(MYDEBUG) 
486     MESSAGE("VISU_MEDConvertor::Build - Find ('"<<"MEDMESH"<<"') = "<<anIsSuccess);
487   if(anIsSuccess){
488     SALOMEDS::SObject_var aMeshesSObj = boost::get<0>(aSObjectByNameRet);
489     for(int iMesh = 0; iMesh < aNbMeshes; iMesh++){
490       anIsSuccess = false;
491       CORBA::String_var aMeshName = aMeshNames[iMesh];
492       TMeshByName::TRet aMeshByNameRet = 
493         Find(aMeshesSObj,aStudy,TMeshByName(aMeshName.in()),anIsSuccess);
494       if(MYDEBUG) 
495         MESSAGE("VISU_MEDConvertor::Build - Find aMeshName('"<<aMeshName.in()<<"') = "<<anIsSuccess);
496       if(!anIsSuccess)
497         continue;
498
499       PCMesh aMesh = myMeshMap[aMeshName.in()](new TCMesh());
500       SALOME_MED::MESH_var aMEDMesh = boost::get<0>(aMeshByNameRet);
501       aMesh->myDim = aMEDMesh->getSpaceDimension();
502       aMesh->myName = aMeshName.in();
503       aMesh->myPointsDim.resize(aMesh->myDim);
504       aMesh->myMesh = aMEDMesh;
505
506       if(MYDEBUG) 
507         MESSAGE("VISU_MEDConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh->myDim);
508
509       std::string aName = aMeshName.in();
510       std::replace(aName.begin(),aName.end(),' ','_');
511
512       anIsSuccess = false;
513       std::ostringstream aStream;
514       aStream<<"MEDSUPPORTS_OF_"<<aName;
515       std::string aSupportsName(aStream.str());
516       TSObjectByName::TRet aSObjectByNameRet = 
517         Find(aMeshesSObj,aStudy,TSObjectByName(aSupportsName.c_str()),anIsSuccess);
518       if(MYDEBUG) 
519         MESSAGE("VISU_MEDConvertor::Build - Find aSupportsName('"<<aSupportsName<<"') = "<<anIsSuccess);
520       if(!anIsSuccess)
521         continue;
522
523       TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
524       SALOMEDS::SObject_var aSupportsSObj = boost::get<0>(aSObjectByNameRet);
525       SALOMEDS::ChildIterator_var aSupportIterator = aStudy->NewChildIterator(aSupportsSObj);
526
527       // Fill all MeshOnEntity
528       aSupportIterator->InitEx(true);
529       for(; aSupportIterator->More(); aSupportIterator->Next()){
530         SALOMEDS::SObject_var aSupportSObj = aSupportIterator->Value();
531         
532         CORBA::Object_var aMedSupport = VISU::SObjectToObject(aSupportSObj);
533         if(CORBA::is_nil(aMedSupport)) 
534           continue;
535         
536         SALOME_MED::SUPPORT_var aMEDSupport = SALOME_MED::SUPPORT::_narrow(aMedSupport); 
537         if(aMEDSupport->_is_nil()) 
538           continue;
539         
540         SALOME_MED::MESH_var aMeshOnSupport = aMEDSupport->getMesh();
541         SALOME_MED::medEntityMesh aMEntity = aMEDSupport->getEntity();
542         VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
543         CORBA::String_var aSupportName = aMEDSupport->getName();
544         
545         if(aMEDSupport->isOnAllElements()){
546           if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - Support isOnAllElements = '"<<aSupportName<<"' aVEntity = "<<aVEntity);
547           int aNbCells, aCellsSize;
548           //Check, if there is any data on the support?
549           if(aVEntity == NODE_ENTITY){
550             aMesh->myNbPoints = aMeshOnSupport->getNumberOfNodes();
551             aNbCells = aMesh->myNbPoints;
552             aCellsSize = 2*aMesh->myNbPoints;
553           }else
554             GetCellsSize(aNbCells,aCellsSize,aMeshOnSupport,aVEntity);
555           
556           if(aNbCells > 0){
557             PCMeshOnEntity aMeshOnEntity = aMeshOnEntityMap[aVEntity](new TCMeshOnEntity());
558             aMeshOnEntity->myMeshName = aMeshName.in();
559             aMeshOnEntity->myEntity = aVEntity;
560             aMeshOnEntity->myNbCells = aNbCells;
561             aMeshOnEntity->myCellsSize = aCellsSize;
562             aMeshOnEntity->mySupport = aMEDSupport;
563           }
564         }
565       }
566
567       // Fill all Family
568       aSupportIterator->InitEx(true);
569       for(; aSupportIterator->More(); aSupportIterator->Next()){
570         SALOMEDS::SObject_var aSupportSObj = aSupportIterator->Value();
571         
572         CORBA::Object_var aMedSupport = VISU::SObjectToObject(aSupportSObj);
573         if(CORBA::is_nil(aMedSupport)) 
574           continue;
575         
576         SALOME_MED::SUPPORT_var aMEDSupport = SALOME_MED::SUPPORT::_narrow(aMedSupport); 
577         if(aMEDSupport->_is_nil()) 
578           continue;
579         
580         SALOME_MED::MESH_var aMeshOnSupport = aMEDSupport->getMesh();
581         SALOME_MED::medEntityMesh aMEntity = aMEDSupport->getEntity();
582         VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
583         CORBA::String_var aSupportName = aMEDSupport->getName();
584         
585         SALOME_MED::FAMILY_var aMEDFamily = SALOME_MED::FAMILY::_narrow(aMedSupport);
586         if(!aMEDFamily->_is_nil()) {
587           int aNbCells, aCellsSize;
588           GetCellsSize(aNbCells,aCellsSize,aMEDFamily);
589           if(aNbCells > 0){
590             if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aFamily = '"<<aSupportName<<"' aVEntity = "<<aVEntity);
591             TMeshOnEntityMap::iterator aMeshOnEntityMapIter = aMeshOnEntityMap.find(aVEntity);
592             if(aMeshOnEntityMapIter == aMeshOnEntityMap.end())
593               continue;
594
595             PCMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
596             TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
597             PCFamily aFamily = aFamilyMap[aSupportName.in()](new TCFamily());
598             aFamily->myName = aSupportName.in();
599             aFamily->myEntity = aVEntity;
600             aFamily->myNbCells = aNbCells;
601             aFamily->myCellsSize = aCellsSize;
602             aFamily->myId = aMEDFamily->getIdentifier();
603             aFamily->myFamily = aMEDFamily;
604           }
605         }
606       }
607         
608       // Fill all Groups
609       aSupportIterator->InitEx(true);
610       for(; aSupportIterator->More(); aSupportIterator->Next()){
611         SALOMEDS::SObject_var aSupportSObj = aSupportIterator->Value();
612         
613         CORBA::Object_var aMedSupport = VISU::SObjectToObject(aSupportSObj);
614         if(CORBA::is_nil(aMedSupport)) 
615           continue;
616         
617         SALOME_MED::SUPPORT_var aMEDSupport = SALOME_MED::SUPPORT::_narrow(aMedSupport); 
618         if(aMEDSupport->_is_nil()) 
619           continue;
620         
621         SALOME_MED::MESH_var aMeshOnSupport = aMEDSupport->getMesh();
622         SALOME_MED::medEntityMesh aMEntity = aMEDSupport->getEntity();
623         VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
624         CORBA::String_var aSupportName = aMEDSupport->getName();
625         
626         SALOME_MED::GROUP_var aMEDGroup = SALOME_MED::GROUP::_narrow(aMedSupport);
627         if(!aMEDGroup->_is_nil()){
628           if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aGroup = '"<<aSupportName<<"' aVEntity = "<<aVEntity);
629           TGroupMap& aGroupMap = aMesh->myGroupMap;
630           PCGroup aGroup = aGroupMap[aSupportName.in()](new TCGroup());
631           aGroup->myGroup = aMEDGroup;
632           aGroup->myName = aSupportName.in();
633           aGroup->myMeshName = aMeshName.in();
634           VISU::TFamilyAndEntitySet& aFamilyAndEntitySet = aGroup->myFamilyAndEntitySet;
635
636           SALOME_MED::Family_array_var aFamilies = aMEDGroup->getFamilies();
637           int iFamilyEnd = aFamilies->length();
638           for(int iFamaily = 0; iFamaily < iFamilyEnd; iFamaily++){
639             SALOME_MED::FAMILY_var aMEDFamily = aFamilies[iFamaily];
640             CORBA::String_var aFamilyName = aMEDFamily->getName();
641             PFamily aFamily = FindFamily(aMesh,aFamilyName.in());
642             if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aGroup - aFamilyName = '"<<aFamilyName.in()<<"' = "<<bool(aFamily));
643             if(aFamily){
644               TFamilyAndEntity aFamilyAndEntity(aFamilyName.in(),aFamily->myEntity);
645               aFamilyAndEntitySet.insert(aFamilyAndEntity);
646
647               aGroup->myNbCells += aFamily->myNbCells;
648               aGroup->myCellsSize += aFamily->myCellsSize;
649
650               VISU::TBindGroups& aBindGroups = aFamily->myGroups;
651               aBindGroups.insert(aSupportName.in());
652             }
653           }
654         }
655       }
656     }
657   }
658
659   anIsSuccess = false;
660   aSObjectByNameRet = Find(aMedCompSObj,aStudy,TSObjectByName("MEDFIELD"),anIsSuccess);
661   if(anIsSuccess){
662     SALOMEDS::SObject_var aFieldsSObj = boost::get<0>(aSObjectByNameRet);
663     if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - MEDFIELD found.");
664     SALOMEDS::ChildIterator_var aFieldIterator = aStudy->NewChildIterator(aFieldsSObj);
665     for(int iField = 0; aFieldIterator->More(); aFieldIterator->Next(), iField++){
666       SALOMEDS::SObject_var aFieldSObj = aFieldIterator->Value();
667       if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aFieldName = '"<<GetSObjectName(aFieldSObj)<<"'");
668       SALOMEDS::ChildIterator_var aTimeStampIterator = aStudy->NewChildIterator(aFieldSObj);
669       for(; aTimeStampIterator->More(); aTimeStampIterator->Next()){
670         SALOMEDS::SObject_var aTimeStampSObj = aTimeStampIterator->Value();
671         if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aTimeStampSObj = '"<<GetSObjectName(aTimeStampSObj)<<"'");
672         CORBA::Object_var aMedField = VISU::SObjectToObject(aTimeStampSObj);
673         if(CORBA::is_nil(aMedField)) 
674           continue;
675
676         SALOME_MED::FIELD_var aMEDField = SALOME_MED::FIELD::_narrow(aMedField);
677         if(aMEDField->_is_nil()) 
678           continue;
679
680         SALOME_MED::SUPPORT_var aMEDSupport = aMEDField->getSupport();
681         if(aMEDSupport->_is_nil()) 
682           continue;
683
684         SALOME_MED::medEntityMesh aMEntity = aMEDSupport->getEntity();
685         VISU::TEntity anEntity = MEDEntityToVTK(aMEntity);
686         SALOME_MED::MESH_var aMEDMesh = aMEDSupport->getMesh();
687         if(aMEDMesh->_is_nil()) 
688           continue;
689
690         CORBA::String_var aMeshName = aMEDMesh->getName();
691         CORBA::String_var aFieldName = aMEDField->getName();
692         
693         TMeshMap::iterator aMeshMapIter = myMeshMap.find(aMeshName.in());
694         if(aMeshMapIter == myMeshMap.end())
695           continue;
696
697         PCMesh aMesh = aMeshMapIter->second;
698         TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
699         TMeshOnEntityMap::iterator aMeshOnEntityMapIter = aMeshOnEntityMap.find(anEntity);
700         if(aMeshOnEntityMapIter == aMeshOnEntityMap.end())
701           continue;
702
703         PCMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
704         TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
705         TFieldMap::iterator aFieldMapIter = aFieldMap.find(aFieldName.in());
706         PCField aField;
707         if(aFieldMapIter == aFieldMap.end()){
708           aField = aFieldMap[aFieldName.in()](new TCField());
709           aField->myId = iField;
710           aField->myName = aFieldName.in();
711           aField->myEntity = anEntity;
712           aField->myMeshName = aMeshName.in();
713           aField->myNbComp = aMEDField->getNumberOfComponents();
714           aField->myDataSize = aMeshOnEntity->myNbCells * aField->myNbComp;
715           if(MYDEBUG) 
716             MESSAGE("VISU_MEDConvertor::Build - aMeshOnEntity->myNbCells = "<<aMeshOnEntity->myNbCells);
717           aField->myCompNames.resize(aField->myNbComp);
718           aField->myUnitNames.resize(aField->myNbComp);
719         }else
720           aField = aFieldMapIter->second;
721
722         TValField& aValField = aField->myValField;
723         int anId = aMEDField->getIterationNumber();
724         PCValForTime aValForTime = aValField[anId](new TCValForTime());
725         aValForTime->myId = anId;
726         CORBA::Double aDT = aMEDField->getTime();
727         aValForTime->myTime = TTime(aDT,"");
728         aValForTime->myField = aMEDField;
729         if(MYDEBUG) 
730           MESSAGE("VISU_MEDConvertor::Build - aMeshName = '"<<aMeshName<<
731                   "'; myEntity = "<<anEntity<<"; myTime = "<<aDT);
732       }      
733     }
734   }
735   return this; 
736 }
737  
738
739 VISU_Convertor* 
740 VISU_MEDConvertor::Build(SALOMEDS::ChildIterator_ptr theTimeStampIterator)
741 {
742   if(theTimeStampIterator->_is_nil()) return NULL;
743   for(; theTimeStampIterator->More(); theTimeStampIterator->Next()){
744     SALOMEDS::SObject_var aTimeStampSObj = theTimeStampIterator->Value();
745     if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aTimeStampSObj = '"<<GetSObjectName(aTimeStampSObj)<<"'");
746
747     CORBA::Object_var aMedField = VISU::SObjectToObject(aTimeStampSObj);
748     if(CORBA::is_nil(aMedField)) 
749       continue;
750
751     SALOME_MED::FIELD_var aMEDField = SALOME_MED::FIELD::_narrow(aMedField);
752     if(aMEDField->_is_nil()) 
753       continue;
754
755     SALOME_MED::SUPPORT_var aMEDSupport = aMEDField->getSupport();
756     if(aMEDSupport->_is_nil()) 
757       continue;
758
759     SALOME_MED::medEntityMesh aMEntity = aMEDSupport->getEntity();
760     TEntity aVEntity = MEDEntityToVTK(aMEntity);
761     SALOME_MED::MESH_var aMEDMesh = aMEDSupport->getMesh();
762     if(aMEDMesh->_is_nil()) continue;
763     CORBA::String_var aMeshName = aMEDMesh->getName();
764     CORBA::String_var aFieldName = aMEDField->getName();
765
766     PCMesh aMesh = myMeshMap[aMeshName.in()](new TCMesh());
767     aMesh->myDim = aMEDMesh->getSpaceDimension();
768     aMesh->myPointsDim.resize(aMesh->myDim);
769     aMesh->myName = aMeshName.in();
770     aMesh->myNbPoints = aMEDMesh->getNumberOfNodes();
771     aMesh->myMesh = aMEDMesh;
772     if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aMeshName = '"<<aMeshName<<"'; myDim = "<<aMesh->myDim);
773
774     TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
775     PCMeshOnEntity aMeshOnEntity = aMeshOnEntityMap[aVEntity](new TCMeshOnEntity());
776     aMeshOnEntity->myEntity = aVEntity;
777     aMeshOnEntity->myMeshName = aMeshName.in();
778     aMeshOnEntity->mySupport = aMEDSupport;
779     if(aVEntity == NODE_ENTITY){
780       PCMeshOnEntity aMeshOnEntity2 = aMeshOnEntityMap[CELL_ENTITY](new TCMeshOnEntity());
781       *aMeshOnEntity2 = *aMeshOnEntity;
782       aMeshOnEntity->myEntity = CELL_ENTITY;
783       GetCellsSize(aMesh,aMEDMesh,CELL_ENTITY);
784     }else{
785       PCMeshOnEntity aMeshOnEntity2 = aMeshOnEntityMap[NODE_ENTITY](new TCMeshOnEntity());
786       *aMeshOnEntity2 = *aMeshOnEntity;
787       aMeshOnEntity->myEntity = NODE_ENTITY;
788       GetCellsSize(aMesh,aMEDMesh,NODE_ENTITY);
789     }
790     GetCellsSize(aMesh,aMEDMesh,aVEntity);
791     TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
792     TFieldMap::iterator aFieldMapIter = aFieldMap.find(aFieldName.in());
793     PCField aField;
794     if(aFieldMapIter == aFieldMap.end()){
795       aField = aFieldMap[aFieldName.in()](new TCField());
796       CORBA::Short iField = mySObject->Tag();
797       aField->myId = iField;
798       aField->myName = aFieldName.in();
799       aField->myEntity = aVEntity;
800       aField->myMeshName = aMeshName.in();
801       aField->myNbComp = aMEDField->getNumberOfComponents();
802       aField->myDataSize = aMeshOnEntity->myNbCells * aField->myNbComp;
803       if(MYDEBUG) 
804         MESSAGE("VISU_MEDConvertor::Build - aMeshOnEntity->myNbCells = "<<aMeshOnEntity->myNbCells);
805       aField->myCompNames.resize(aField->myNbComp);
806       aField->myUnitNames.resize(aField->myNbComp);
807     }
808     TValField& aValField = aField->myValField;
809     int anId = aMEDField->getIterationNumber();
810     PCValForTime aValForTime = aValField[anId](new TCValForTime());
811     aValForTime->myId = anId;
812     CORBA::Double aDT = aMEDField->getTime();
813     aValForTime->myTime = TTime(aDT,"");
814     aValForTime->myField = aMEDField;
815     if(MYDEBUG) 
816       MESSAGE("VISU_MEDConvertor::Build - aMeshName = '"<<aMeshName<<
817               "'; myEntity = "<<aVEntity<<"; myTime = "<<aDT);
818   }
819   return this; 
820 }
821
822
823 int
824 VISU_MEDConvertor::LoadMeshOnEntity(VISU::PMeshOnEntityImpl theMeshOnEntity, 
825                                     const string& theFamilyName)
826 {
827   //Main part of code
828   const string& aMeshName = theMeshOnEntity->myMeshName;
829   const TEntity& aVEntity = theMeshOnEntity->myEntity;
830   PCMesh aMesh = myMeshMap[aMeshName];
831   int isPointsUpdated;
832   if(aVEntity == NODE_ENTITY) 
833     isPointsUpdated = LoadPoints(aMesh,theFamilyName);
834   else 
835     isPointsUpdated = LoadPoints(aMesh);
836   int isCellsOnEntityUpdated = LoadCellsOnEntity(aMesh,theMeshOnEntity,theFamilyName);
837
838   return (isPointsUpdated || isCellsOnEntityUpdated);
839 }
840  
841  
842 int 
843 VISU_MEDConvertor::LoadMeshOnGroup(VISU::PMeshImpl theMesh, 
844                                    const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet)
845 {
846   //Main part of code
847   int isPointsUpdated = 0;
848   int isCellsOnEntityUpdated = 0;
849   VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = theFamilyAndEntitySet.begin();
850   for(; aFamilyAndEntitySetIter != theFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){
851     const string& aFamilyName = aFamilyAndEntitySetIter->first;
852     const VISU::TEntity& aVEntity = aFamilyAndEntitySetIter->second;
853     PCMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[aVEntity];
854     if(aVEntity == VISU::NODE_ENTITY){
855       isPointsUpdated += LoadPoints(theMesh,aFamilyName);
856       isCellsOnEntityUpdated += LoadCellsOnEntity(theMesh,aMeshOnEntity);
857     }else{
858       isPointsUpdated += LoadPoints(theMesh);
859       isCellsOnEntityUpdated += LoadCellsOnEntity(theMesh,aMeshOnEntity,aFamilyName);
860     }
861   }
862
863   return (isPointsUpdated || isCellsOnEntityUpdated);
864 }
865
866
867 int 
868 VISU_MEDConvertor::LoadFieldOnMesh(VISU::PMeshImpl theMesh, 
869                                    VISU::PMeshOnEntityImpl theMeshOnEntity, 
870                                    VISU::PFieldImpl theField, 
871                                    VISU::PValForTimeImpl theValForTime)
872 {
873   //Main part of code
874   int isPointsUpdated = LoadPoints(theMesh);
875   int isCellsOnEntityUpdated = LoadCellsOnEntity(theMesh,theMeshOnEntity);
876   int isFieldUpdated = LoadField(theMesh,theMeshOnEntity,theField,theValForTime);
877   
878   return (isPointsUpdated || isCellsOnEntityUpdated || isFieldUpdated);
879 }
880
881 int 
882 VISU_MEDConvertor::LoadPoints(VISU::PCMesh theMesh, 
883                               const string& theFamilyName)
884 {
885   //Check on existing family
886   PCMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[VISU::NODE_ENTITY];
887   PCFamily aFamily = GetFamily(aMeshOnEntity,theFamilyName);
888   //Check on loading already done
889   bool isPointsLoaded = !theMesh->myPointsCoord.empty();
890   if(isPointsLoaded) 
891     if(!aFamily) 
892       return 0;
893     else if(!aFamily->mySubMesh.empty()) 
894       return 0;
895
896   if(MYDEBUG) 
897     MESSAGE("LoadPoints - isPointsLoaded = "<<isPointsLoaded<<"; theFamilyName = '"<<theFamilyName<<"'");
898
899   SALOME_MED::MESH_var& aMedMesh = theMesh->myMesh;
900   int iNumElemEnd = aMedMesh->getNumberOfNodes();
901   TMeshImpl::TPointsCoord& aPointsCoord = theMesh->myPointsCoord;
902   if(MYDEBUG) MESSAGE("LoadPoints - iNumElemEnd = "<<iNumElemEnd);
903   if (iNumElemEnd <= 0) throw std::runtime_error("LoadPoints >> There is no points in the mesh !!!");
904   aPointsCoord.resize(theMesh->myDim*iNumElemEnd,0.0);
905   SALOME_MED::double_array_var coord = aMedMesh->getCoordinates(SALOME_MED::MED_FULL_INTERLACE);
906   if(!isPointsLoaded){
907     for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) 
908       for(int iDim = 0, iNumElem2Dim = iNumElem*theMesh->myDim; iDim < theMesh->myDim; iDim++, iNumElem2Dim++)
909         aPointsCoord[iNumElem2Dim] = coord[iNumElem2Dim];
910     if(MYDEBUG) MESSAGE("LoadPoints - Filling aMeshOnEntity with type NODE_ENTITY");
911     TMeshOnEntityImpl::TConnForCellType& aConnForCellType = aMeshOnEntity->myCellsConn[VTK_VERTEX];
912     aConnForCellType.resize(iNumElemEnd);
913     for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
914       aConnForCellType[iNumElem] = TMeshOnEntityImpl::TConnect(1,iNumElem);
915   }
916   if(aFamily){
917     if(MYDEBUG) MESSAGE("LoadPoints - Filling aFamily SubMesh");
918     SALOME_MED::FAMILY_var aMedFamily = aFamily->myFamily;
919     TFamilyImpl::TSubMeshOnCellType& aSubMeshOnCellType = aFamily->mySubMesh[VTK_VERTEX];
920     SALOME_MED::medGeometryElement_array_var aGeom = aMedFamily->getTypes();
921     SALOME_MED::long_array_var aCellNumForType = aMedFamily->getNumber(aGeom[0]);
922     int iNumElemEndTmp = iNumElemEnd;
923     iNumElemEnd = aCellNumForType->length();
924     for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) {
925       int tmp = aCellNumForType[iNumElem]-1;
926       if(0 > tmp || tmp >= iNumElemEndTmp) {
927         static QString aString;
928         aString.sprintf("LoadPoints >> iNumElemEndTmp(%d) <= aCellNumForType[%d]=%d < 0 !!!",iNumElemEnd,iNumElem,tmp);
929         throw std::runtime_error(aString.latin1());
930       }
931       aSubMeshOnCellType.insert(tmp);
932     }
933   }
934   return 1;
935 }
936
937
938 int 
939 VISU_MEDConvertor::LoadCellsOnEntity(VISU::PCMesh theMesh,
940                                      VISU::PCMeshOnEntity theMeshOnEntity, 
941                                      const string& theFamilyName)
942 {
943   //Check on existing family
944   PCFamily aFamily = GetFamily(theMeshOnEntity,theFamilyName);
945   //Check on loading already done
946   bool isCellsLoaded = !theMeshOnEntity->myCellsConn.empty();
947   if(isCellsLoaded) 
948     if(!aFamily) 
949       return 0;
950     else if(!aFamily->mySubMesh.empty()) 
951       return 0;
952
953   SALOME_MED::SUPPORT_var& aMedSupport = theMeshOnEntity->mySupport;
954   SALOME_MED::MESH_var aMedMesh = aMedSupport->getMesh();
955   if(MYDEBUG) {
956     MESSAGE("LoadCellsOnEntity - theFamilyName = '"<<theFamilyName<<"'");
957     MESSAGE("LoadCellsOnEntity - isCellsLoaded = "<<isCellsLoaded<<"; isFamilyPresent = "<<bool(aFamily));
958   }
959
960   //Main part of code
961   SALOME_MED::medGeometryElement* aGeomElems;
962   const TEntity& aVEntity = theMeshOnEntity->myEntity;
963   int iGeomEnd = GetEntity2Geom(aVEntity,aGeomElems);
964   const SALOME_MED::medEntityMesh& aMEntity = VTKEntityToMED(aVEntity);
965   int aNbPoints = theMesh->myPointsCoord.size()/theMesh->myDim;
966   if(!isCellsLoaded){
967     for(int iGeom = 0, aCounter = 0; iGeom < iGeomEnd; iGeom++){
968       SALOME_MED::medGeometryElement aGeom = aGeomElems[iGeom];
969       int aMNbNodes = MEDGeom2NbNodes(aGeom);
970       int aVGeom = MEDGeomToVTK(aGeom);
971       int aVNbNodes = VTKGeom2NbNodes(aVGeom);
972       int iNumElemEnd = aMedMesh->getNumberOfElements(aMEntity,aGeom);
973       if (iNumElemEnd > 0) {
974         SALOME_MED::long_array_var conn = 
975           aMedMesh->getConnectivity(SALOME_MED::MED_FULL_INTERLACE,SALOME_MED::MED_NODAL,aMEntity,aGeom);
976         TMeshOnEntityImpl::TConnForCellType& aConnForCellType = theMeshOnEntity->myCellsConn[aVGeom];
977         //APO - aConnForCellType.resize(iNumElemEnd);
978         vector<int> aConnect(aMNbNodes);
979         int aNbConnForElem = conn->length()/iNumElemEnd;
980         if(MYDEBUG) MESSAGE("LoadCellsOnEntity - aGeom = "<<aGeom<<
981                             "; iNumElemEnd = "<<iNumElemEnd<<
982                             "; aNbConnForElem = "<<aNbConnForElem);
983         for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) {
984           VISU::TMeshOnEntityImpl::TConnect anArray(aVNbNodes);
985           for (int k = 0, kj = iNumElem*aNbConnForElem; k < aMNbNodes; k++) {
986             aConnect[k] = conn[kj+k] - 1;
987           }
988           switch(aGeom){
989           case SALOME_MED::MED_TETRA4 :
990           case SALOME_MED::MED_TETRA10 :
991             anArray[0] = aConnect[0];
992             anArray[1] = aConnect[1];
993             anArray[2] = aConnect[3];  
994             anArray[3] = aConnect[2];  
995             break;
996           case SALOME_MED::MED_PYRA5 :
997           case SALOME_MED::MED_PYRA13 :
998             anArray[0] = aConnect[0];
999             anArray[1] = aConnect[3];  
1000             anArray[2] = aConnect[2];
1001             anArray[3] = aConnect[1];  
1002             anArray[4] = aConnect[4];
1003             break;
1004           default:
1005             for (int k = 0; k < aVNbNodes; k++) 
1006               anArray[k] = aConnect[k];
1007           }
1008           for (int k = 0; k < aVNbNodes; k++) 
1009             if(anArray[k] < 0 || aNbPoints <= anArray[k]){
1010               static QString aString;
1011               aString.sprintf("ImportCells >> aNbPoints(%d) <= anArray[%d][%d]=%d < 0 !!!",aNbPoints,iNumElem,k,anArray[k]);
1012               throw std::runtime_error(aString.latin1());
1013             }
1014           aConnForCellType.push_back(anArray);
1015         }
1016         //Workaround for MED Component data structure
1017         int aSize = aConnForCellType.size();
1018         theMeshOnEntity->myCellsFirstIndex[aGeom] = TCMeshOnEntity::TIndexAndSize(aCounter,aSize);
1019         aCounter += aSize;
1020       }
1021     }
1022   }
1023   //Filling aFamily SubMesh
1024   if(aFamily){
1025     SALOME_MED::FAMILY_var aMedFamily = aFamily->myFamily;
1026     SALOME_MED::medGeometryElement_array_var aGeoms = aMedFamily->getTypes();
1027     iGeomEnd = aGeoms->length();
1028     if(MYDEBUG) MESSAGE("LoadCellsOnEntity - iGeomEnd = "<<iGeomEnd);
1029     for (int iGeom = 0; iGeom < iGeomEnd; iGeom++) {
1030       SALOME_MED::medGeometryElement aGeom = aGeoms[iGeom];
1031       SALOME_MED::long_array_var aCellNumForType = aMedFamily->getNumber(aGeom);
1032       int aVGeom = MEDGeomToVTK(aGeom);
1033       TFamilyImpl::TSubMeshOnCellType& aSubMeshOnCellType = aFamily->mySubMesh[aVGeom]; 
1034       int iNumElemEndTmp = theMeshOnEntity->myCellsConn[aVGeom].size();
1035       int iNumElemEnd = aCellNumForType->length();
1036       int aCounter = theMeshOnEntity->myCellsFirstIndex[aGeom].first;
1037       if(MYDEBUG) 
1038         MESSAGE("LoadCellsOnEntity - aGeom = "<<aGeom<<
1039                 "; iNumElemEnd = "<<iNumElemEnd<<
1040                 "; aCounter = "<<aCounter);
1041       for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) {
1042         int tmp = aCellNumForType[iNumElem]-aCounter-1;
1043         if(0 > tmp || tmp >= iNumElemEndTmp) {
1044           static QString aString;
1045           aString.sprintf("LoadCellsOnEntity >> iNumElemEndTmp(%d) <= aCellNumForType[%d]=%d < 0 !!!",iNumElemEndTmp,iNumElem,tmp);
1046           throw std::runtime_error(aString.latin1());
1047         }
1048         aSubMeshOnCellType.insert(tmp);
1049       }
1050     }
1051   }
1052   return 1;
1053 }
1054
1055 template<class TArray> 
1056 int 
1057 ImportField(TArray& theArray, 
1058             VISU::PCMesh theMesh,
1059             VISU::PCField theField,
1060             VISU::PCValForTime theValForTime,
1061             VISU::PCMeshOnEntity theMeshOnEntity)
1062 {
1063   if(theField->myEntity == NODE_ENTITY){
1064     TValForTimeImpl::TValForCellsWithType& aValForCellsWithType = 
1065       theValForTime->myValForCells[VTK_VERTEX];
1066     int iNumElemEnd = theMesh->myPointsCoord.size()/theMesh->myDim*theField->myNbComp;
1067     if(MYDEBUG) MESSAGE("ImportField - iNumElemEnd = "<<iNumElemEnd);
1068     aValForCellsWithType.resize(iNumElemEnd);
1069     for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) 
1070       aValForCellsWithType[iNumElem] = theArray[iNumElem];
1071   }else{
1072     SALOME_MED::medGeometryElement* aGeomElems;
1073     const TEntity& aVEntity = theField->myEntity;
1074     int iGeomEnd = GetEntity2Geom(aVEntity,aGeomElems);
1075     for(int iGeom = 0; iGeom < iGeomEnd; iGeom++){
1076       SALOME_MED::medGeometryElement aGeom = aGeomElems[iGeom];
1077       int aVGeom = MEDGeomToVTK(aGeom);
1078       const TCMeshOnEntity::TCellsFirstIndex& aCellsFirstIndex = theMeshOnEntity->myCellsFirstIndex;
1079       TCMeshOnEntity::TCellsFirstIndex::const_iterator aCellsFirstIndexIter = aCellsFirstIndex.find(aGeom);
1080       if(aCellsFirstIndexIter != aCellsFirstIndex.end()){
1081         const TCMeshOnEntity::TIndexAndSize& aIndexAndSize = aCellsFirstIndexIter->second;
1082         int iNumElemEnd = aIndexAndSize.second;
1083         if(MYDEBUG) 
1084           MESSAGE("ImportField - aGeom = "<<aGeom<<
1085                   "; aIndexAndSize = {"<<aIndexAndSize.first<<
1086                   ","<<aIndexAndSize.second<<"}");
1087         TValForTimeImpl::TValForCellsWithType& aValForCellsWithType = theValForTime->myValForCells[aVGeom];
1088         aValForCellsWithType.resize(iNumElemEnd*theField->myNbComp);
1089         for(int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
1090           for(int k = 0, kj = iNumElem*theField->myNbComp; k < theField->myNbComp; k++)
1091             aValForCellsWithType[kj+k] = theArray[aIndexAndSize.first*theField->myNbComp+kj+k];
1092       }
1093     }
1094   }
1095   return 1;
1096 }
1097
1098 int
1099 VISU_MEDConvertor::LoadField(VISU::PCMesh theMesh,
1100                              VISU::PCMeshOnEntity theMeshOnEntity,
1101                              VISU::PField theField, 
1102                              VISU::PCValForTime theValForTime)
1103 {
1104   //Check on loading already done
1105   if(!theValForTime->myValForCells.empty()) 
1106     return 0;
1107  
1108   SALOME_MED::FIELD_var aMEDField = theValForTime->myField;
1109   SALOME_MED::FIELDDOUBLE_ptr aFieldDouble = SALOME_MED::FIELDDOUBLE::_narrow(aMEDField);
1110   if(!aFieldDouble->_is_nil()){
1111     SALOME_MED::double_array_var anArray = aFieldDouble->getValue(SALOME_MED::MED_FULL_INTERLACE);
1112     if(MYDEBUG) MESSAGE("VISU_MEDConvertor::LoadField - There is FIELDDOUBLE = "<<anArray->length());
1113     ::ImportField(anArray,theMesh,theField,theValForTime,theMeshOnEntity);
1114   }
1115   SALOME_MED::FIELDINT_ptr aFieldInt = SALOME_MED::FIELDINT::_narrow(aMEDField);
1116   if(!aFieldInt->_is_nil()){
1117     SALOME_MED::long_array_var anArray = aFieldInt->getValue(SALOME_MED::MED_FULL_INTERLACE);
1118     if(MYDEBUG) MESSAGE("VISU_MEDConvertor::LoadField - There is FIELDINT = "<<anArray->length());
1119     ::ImportField(anArray,theMesh,theField,theValForTime,theMeshOnEntity);
1120   }
1121   return 1;
1122 }