]> SALOME platform Git repositories - modules/visu.git/blob - src/VISU_I/VISU_CorbaMedConvertor.cxx
Salome HOME
DCQ: prepare V2.0.0
[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 #include "VISU_ConvertorUtils.hxx"
32
33 #include <valarray>     
34 #include <vtkCellType.h>
35
36 using namespace VISU;
37 using namespace std;
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 static med_err ret = 0;
47
48 extern "C" {
49   VISU_Convertor* CreateMEDConvertor(SALOMEDS::SObject_ptr theMedSObject) {
50     return new VISU_MEDConvertor(theMedSObject);
51   }
52   VISU_Convertor* CreateMEDFieldConvertor(SALOME_MED::FIELD_ptr theField) {
53     return new VISU_MEDFieldConvertor(theField);
54   }
55 }
56
57 typedef map<VISU::TEntity,SALOME_MED::medEntityMesh> TVisu2MedEntity;
58 static TVisu2MedEntity aVisu2MedEntity;
59 typedef map<SALOME_MED::medEntityMesh,VISU::TEntity> TMed2VisuEntity;
60 static TMed2VisuEntity aMed2VisuEntity;
61 static int INIT = (
62                    aVisu2MedEntity[VISU::CELL_ENTITY] = SALOME_MED::MED_CELL,
63                    aVisu2MedEntity[VISU::FACE_ENTITY] = SALOME_MED::MED_FACE,
64                    aVisu2MedEntity[VISU::EDGE_ENTITY] = SALOME_MED::MED_EDGE,
65                    aVisu2MedEntity[VISU::NODE_ENTITY] = SALOME_MED::MED_NODE,
66
67                    aMed2VisuEntity[SALOME_MED::MED_CELL] = VISU::CELL_ENTITY,
68                    aMed2VisuEntity[SALOME_MED::MED_FACE] = VISU::FACE_ENTITY,
69                    aMed2VisuEntity[SALOME_MED::MED_EDGE] = VISU::EDGE_ENTITY,
70                    aMed2VisuEntity[SALOME_MED::MED_NODE] = VISU::NODE_ENTITY,
71
72                    1);
73
74 static int CELLGEOM[MED_NBR_GEOMETRIE_MAILLE] = {
75   SALOME_MED::MED_POINT1,
76   SALOME_MED::MED_SEG2,
77   SALOME_MED::MED_SEG3,
78   SALOME_MED::MED_TRIA3,
79   SALOME_MED::MED_QUAD4,
80   SALOME_MED::MED_TRIA6,
81   SALOME_MED::MED_QUAD8,
82   SALOME_MED::MED_TETRA4,
83   SALOME_MED::MED_PYRA5,
84   SALOME_MED::MED_PENTA6,
85   SALOME_MED::MED_HEXA8,
86   SALOME_MED::MED_TETRA10,
87   SALOME_MED::MED_PYRA13,
88   SALOME_MED::MED_PENTA15,
89   SALOME_MED::MED_HEXA20
90 };
91
92 static const int VTKCELLGEOMEND = 8;
93 static int VTKCELLGEOM[VTKCELLGEOMEND] = {
94   SALOME_MED::MED_POINT1,
95   SALOME_MED::MED_SEG2,
96   SALOME_MED::MED_TRIA3,
97   SALOME_MED::MED_QUAD4,
98   SALOME_MED::MED_TETRA4,
99   SALOME_MED::MED_PYRA5,
100   SALOME_MED::MED_PENTA6,
101   SALOME_MED::MED_HEXA8
102 };
103
104 static int FACEGEOM[MED_NBR_GEOMETRIE_FACE] = {
105   SALOME_MED::MED_TRIA3,
106   SALOME_MED::MED_QUAD4,
107   SALOME_MED::MED_TRIA6,
108   SALOME_MED::MED_QUAD8
109 };
110
111 static int EDGEGEOM[MED_NBR_GEOMETRIE_ARETE] = {
112   SALOME_MED::MED_SEG2,
113   SALOME_MED::MED_SEG3
114 };
115
116 static int NODEGEOM[1] = {
117   SALOME_MED::MED_POINT1,
118 };
119
120 void GetEntity2Geom(const VISU::TEntity& theEntity, int*& theVector, int* theEnd)
121 {
122   switch(theEntity){
123   case VISU::CELL_ENTITY: theVector = CELLGEOM; *theEnd = MED_NBR_GEOMETRIE_MAILLE; break;
124   case VISU::FACE_ENTITY: theVector = FACEGEOM; *theEnd = MED_NBR_GEOMETRIE_FACE; break;
125   case VISU::EDGE_ENTITY: theVector = EDGEGEOM; *theEnd = MED_NBR_GEOMETRIE_ARETE; break;
126   case VISU::NODE_ENTITY: theVector = NODEGEOM; *theEnd = 1; break;
127   default:
128     throw std::runtime_error("GetEntity2Geom >> theEntity is uncorrect !!!");
129   }
130 }
131
132 struct SalomeMed2vtk {
133   SALOME_MED::medGeometryElement medType;
134   char *medName;
135   int medNbNodes;
136   int vtkType;
137   char *vtkName;
138   int vtkNbNodes;
139 };
140
141 #define CORBAMED2VTK(MEDTYPE,VTKTYPE,VTKNBNODES) \
142  {SALOME_MED::MEDTYPE,#MEDTYPE,getNbMedNodes(MEDTYPE),VTKTYPE,#VTKTYPE,VTKNBNODES}
143 static SalomeMed2vtk salome_med2vtk[SALOME_MED::MED_ALL_ELEMENTS] = {
144   {SALOME_MED::MED_NONE,"MED_NONE",0,VTK_EMPTY_CELL,"VTK_EMPTY_CELL",0},
145   CORBAMED2VTK(MED_POINT1,VTK_VERTEX,1),
146   CORBAMED2VTK(MED_SEG2,VTK_LINE,2),
147   CORBAMED2VTK(MED_SEG3,VTK_LINE,2),
148   CORBAMED2VTK(MED_TRIA3,VTK_TRIANGLE,3),
149   CORBAMED2VTK(MED_QUAD4,VTK_QUAD,4),
150   CORBAMED2VTK(MED_TRIA6,VTK_TRIANGLE,3),
151   CORBAMED2VTK(MED_QUAD8,VTK_QUAD,4),
152   CORBAMED2VTK(MED_TETRA4,VTK_TETRA,4),
153   CORBAMED2VTK(MED_PYRA5,VTK_PYRAMID,5),
154   CORBAMED2VTK(MED_PENTA6,VTK_WEDGE,6),
155   CORBAMED2VTK(MED_HEXA8,VTK_HEXAHEDRON,8),
156   CORBAMED2VTK(MED_TETRA10,VTK_TETRA,4),
157   CORBAMED2VTK(MED_PYRA13,VTK_PYRAMID,5),
158   CORBAMED2VTK(MED_PENTA15,VTK_WEDGE,6),
159   CORBAMED2VTK(MED_HEXA20,VTK_HEXAHEDRON,8)
160 };
161 #undef CORBAMED2VTK
162
163 int GetIdMEDType(int medType){
164   for(int i = 0; i < SALOME_MED::MED_ALL_ELEMENTS; i++)
165     if(salome_med2vtk[i].medType == medType) return i;
166   return -1;
167 }
168
169 string GetName(SALOMEDS::SObject_ptr aSObject){
170   SALOMEDS::GenericAttribute_var anAttr;
171   if (aSObject->FindAttribute(anAttr,"AttributeName")) {
172     SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
173     CORBA::String_var aString = aName->Value();
174     return aString.in();
175   }
176   return "";
177 }
178
179
180 static void GetCellsSize(vtkIdType& theNbCells, vtkIdType& theCellsSize,
181                          SALOME_MED::MESH_ptr theMEDMesh,
182                          const VISU::TEntity& theEntity)
183 {
184   int iGeomElemEnd;
185   int* aGeomElemVector;
186   GetEntity2Geom(theEntity,aGeomElemVector,&iGeomElemEnd);
187   theNbCells = theCellsSize = 0;
188   const SALOME_MED::medEntityMesh& aMedEntity = aVisu2MedEntity[theEntity];
189   if(MYDEBUG) MESSAGE("GetCellsSize - theEntity = "<<theEntity);
190   for (int iGeomElem = 0, aCounter = 0; iGeomElem < iGeomElemEnd; iGeomElem++) {
191     int medId = GetIdMEDType(aGeomElemVector[iGeomElem]);
192     SALOME_MED::medGeometryElement aMedType = salome_med2vtk[medId].medType;
193     med_int iNumElemEnd = theMEDMesh->getNumberOfElements(aMedEntity,aMedType);
194     if(iNumElemEnd > 0){
195       if(MYDEBUG) MESSAGE("GetCellsSize - iNumElemEnd = "<<iNumElemEnd);
196       theNbCells += iNumElemEnd;
197       theCellsSize += iNumElemEnd*(salome_med2vtk[medId].vtkNbNodes + 1);
198     }
199   }
200 }
201
202
203 static void GetCellsSize(vtkIdType& theNbCells, vtkIdType& theCellsSize,
204                          SALOME_MED::FAMILY_ptr theMEDFamily)
205 {
206   SALOME_MED::medGeometryElement_array_var aGeom = theMEDFamily->getTypes();
207   med_int iGeomElemEnd = aGeom->length();
208   theNbCells = theCellsSize = 0;
209   if(MYDEBUG) MESSAGE("GetCellsSize - iGeomElemEnd = "<<iGeomElemEnd);
210   for (int iGeomElem = 0; iGeomElem < iGeomElemEnd; iGeomElem++) {
211     SALOME_MED::medGeometryElement aGeomType = aGeom[iGeomElem];
212     SALOME_MED::long_array_var aCellNumForType = theMEDFamily->getNumber(aGeomType);
213     int medId = GetIdMEDType(aGeomType);
214     med_int iNumElemEnd = aCellNumForType->length();
215     if(iNumElemEnd > 0){
216       if(MYDEBUG) MESSAGE("GetCellsSize - iNumElemEnd = "<<iNumElemEnd);
217       theNbCells += iNumElemEnd;
218       theCellsSize += iNumElemEnd*(salome_med2vtk[medId].vtkNbNodes + 1);
219     }
220   }
221 }
222
223
224 static void GetCellsSize(VISU::TMesh& theMesh, 
225                          SALOME_MED::MESH_ptr theMEDMesh, 
226                          const VISU::TEntity& theEntity)
227 {
228   VISU::TMeshOnEntity& aMeshOnEntity = theMesh.myMeshOnEntityMap[theEntity];
229   if(theEntity == VISU::NODE_ENTITY){
230     theMesh.myNbPoints = theMEDMesh->getNumberOfNodes();
231     aMeshOnEntity.myNbCells = theMesh.myNbPoints;
232     aMeshOnEntity.myCellsSize = 2*theMesh.myNbPoints;
233     vtkIdType aNbCells, aCellsSize;
234     GetCellsSize(aNbCells,aCellsSize,theMEDMesh,VISU::CELL_ENTITY);
235     if(aNbCells > 0){
236       VISU::TMeshOnEntity& aMeshOnCells = theMesh.myMeshOnEntityMap[VISU::CELL_ENTITY];
237       aMeshOnCells.myEntity = VISU::CELL_ENTITY;
238       aMeshOnCells.myMeshName = theMesh.myName;
239       aMeshOnCells.myNbCells = aNbCells;
240       aMeshOnCells.myCellsSize = aCellsSize;
241     }
242   }else
243     GetCellsSize(aMeshOnEntity.myNbCells,aMeshOnEntity.myCellsSize,theMEDMesh,theEntity);
244 }
245
246
247 VISU_Convertor* VISU_MEDFieldConvertor::Build() {
248   if(myField->_is_nil()) 
249     throw std::runtime_error("VISU_MEDFieldConvertor::Build >> myField->_is_nil() !!!");
250   
251   SALOME_MED::SUPPORT_var aMEDSupport = myField->getSupport();
252   if(aMEDSupport->_is_nil()) 
253     throw std::runtime_error("VISU_MEDFieldConvertor::Build >> aMEDSupport->_is_nil() !!!");
254   SALOME_MED::medEntityMesh aMEDEntity = aMEDSupport->getEntity();
255   VISU::TEntity anEntity = aMed2VisuEntity[aMEDEntity];
256   SALOME_MED::MESH_var aMEDMesh = aMEDSupport->getMesh();
257   if(aMEDMesh->_is_nil()) 
258     throw std::runtime_error("VISU_MEDFieldConvertor::Build >> aMEDMesh->_is_nil() !!!");
259   CORBA::String_var aMeshName = aMEDMesh->getName();
260   CORBA::String_var aFieldName = myField->getName();
261
262   VISU::TMesh &aMesh = myMeshMap[aMeshName.in()];
263   aMesh.myDim = aMEDMesh->getSpaceDimension();
264   aMesh.myName = aMeshName.in();
265   VISUMED::TMesh &aMesh2 = myMeshMap2[aMeshName.in()];
266   aMesh2.myMesh = aMEDMesh;
267   if(MYDEBUG) MESSAGE("VISU_MEDFieldConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh.myDim);
268
269   VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
270   aMeshOnEntity.myEntity = anEntity;
271   aMeshOnEntity.myMeshName = aMeshName.in();
272   VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[anEntity];
273   aMeshOnEntity2.mySupport = aMEDSupport;
274   if(anEntity == VISU::NODE_ENTITY)
275     aMesh2.myMeshOnEntityMap[VISU::CELL_ENTITY].mySupport = aMEDSupport;
276   GetCellsSize(aMesh,aMEDMesh,anEntity);
277
278   VISU::TField& aField = aMeshOnEntity.myFieldMap[aFieldName.in()];
279   aField.myId = myField->getOrderNumber();
280   aField.myName = aFieldName.in();
281   aField.myEntity = anEntity;
282   aField.myMeshName = aMeshName.in();
283   aField.myNbComp = myField->getNumberOfComponents();
284   aField.myNbValField = 1;
285   aField.myDataSize = aMeshOnEntity.myNbCells * aField.myNbComp;
286   aField.myCompNames.resize(aField.myNbComp);
287   aField.myUnitNames.resize(aField.myNbComp);
288   if(MYDEBUG) MESSAGE("VISU_MEDFieldConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh.myDim);
289   int iTimeStamp = myField->getIterationNumber();
290   VISU::TField::TValForTime& aValForTime = aField.myValField[iTimeStamp];
291   aValForTime.myId = iTimeStamp;
292   double dt = myField->getTime();
293   aValForTime.myTime = VISU::TField::TTime(dt,"");
294   
295   VISUMED::TField& aField2 = aMeshOnEntity2.myFieldMap[aFieldName.in()];
296   VISUMED::TField::TValForTime& aValForTime2 = aField2.myValField[iTimeStamp];
297   aValForTime2.myField = myField;
298   if(MYDEBUG) 
299     MESSAGE("VISU_MEDConvertor::Build - aFieldName = '"<<aFieldName<<"'; myId = "<<aField.myId<<"; myTime = "<<dt);
300   return this;
301 }
302
303 VISU_Convertor* VISU_MEDConvertor::Build() {
304   if(mySObject->_is_nil()) 
305     throw std::runtime_error("VISU_MEDConvertor::Build >> mySObject->_is_nil() !!!");
306   SALOMEDS::Study_var aStudy = mySObject->GetStudy();
307
308   CORBA::Object_var aMedObject = SObjectToObject(mySObject);
309   if(!CORBA::is_nil(aMedObject)){
310     SALOME_MED::MED_var aMED = SALOME_MED::MED::_narrow(aMedObject);
311     if(!aMED->_is_nil()){
312       CORBA::Short aTag = mySObject->Tag();
313       SALOMEDS::SObject_var aMedCompSObj = mySObject->GetFather();
314       SALOMEDS::SObject_var aMeshSObj;
315       if(!aMedCompSObj->FindSubObject(aTag+1,aMeshSObj)) 
316         throw std::runtime_error("VISU_MEDConvertor::Build >> Cann't find MEDMESH label !!!");
317       if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - MEDMESH found.");
318       SALOMEDS::ChildIterator_var aMeshIterator = aStudy->NewChildIterator(aMeshSObj);
319       for(; aMeshIterator->More(); aMeshIterator->Next()){
320         aMeshSObj = aMeshIterator->Value();
321         if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aMeshSObj = '"<<::GetName(aMeshSObj)<<"'");
322         CORBA::Object_var aMedMesh = SObjectToObject(aMeshSObj);
323         if(CORBA::is_nil(aMedMesh)) continue;
324         SALOME_MED::MESH_var aMEDMesh = SALOME_MED::MESH::_narrow(aMedMesh);
325         if(aMEDMesh->_is_nil()) continue;
326         CORBA::String_var aMeshName = aMEDMesh->getName();
327         VISU::TMesh &aMesh = myMeshMap[aMeshName.in()];
328         aMesh.myDim = aMEDMesh->getSpaceDimension();
329         aMesh.myName = aMeshName.in();
330         aMesh.myPointsDim.resize(aMesh.myDim);
331         VISUMED::TMesh &aMesh2 = myMeshMap2[aMeshName.in()];
332         aMesh2.myMesh = aMEDMesh;
333         if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh.myDim);
334         SALOMEDS::ChildIterator_var aSupportIterator = aStudy->NewChildIterator(aMeshSObj);
335         for(; aSupportIterator->More(); aSupportIterator->Next()){
336           SALOMEDS::SObject_var aSupportSObj = aSupportIterator->Value();
337           CORBA::Object_var aMedSupport = SObjectToObject(aSupportSObj);
338           if(CORBA::is_nil(aMedSupport)) continue;
339           SALOME_MED::SUPPORT_var aMEDSupport = SALOME_MED::SUPPORT::_narrow(aMedSupport); 
340           if(aMEDSupport->_is_nil()) continue;
341           SALOME_MED::MESH_var aMeshOnSupport = aMEDSupport->getMesh();
342           SALOME_MED::medEntityMesh aMEDEntity = aMEDSupport->getEntity();
343           VISU::TEntity anEntity = aMed2VisuEntity[aMEDEntity];
344           CORBA::String_var aSupportName = aMEDSupport->getName();
345           if(aMEDSupport->isOnAllElements()){
346             if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - Support isOnAllElements = '"<<aSupportName<<"' anEntity = "<<anEntity);
347             int aNbCells, aCellsSize;
348             //Check, if there is any data on the support?
349             if(anEntity == VISU::NODE_ENTITY){
350               aMesh.myNbPoints = aMeshOnSupport->getNumberOfNodes();
351               aNbCells = aMesh.myNbPoints;
352               aCellsSize = 2*aMesh.myNbPoints;
353             }else{
354               GetCellsSize(aNbCells,aCellsSize,aMeshOnSupport,anEntity);
355             }
356             if(aNbCells == 0) continue;
357             VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
358             aMeshOnEntity.myMeshName = aMeshName.in();
359             aMeshOnEntity.myEntity = anEntity;
360             aMeshOnEntity.myNbCells = aNbCells;
361             aMeshOnEntity.myCellsSize = aCellsSize;
362
363             VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[anEntity];
364             aMeshOnEntity2.mySupport = aMEDSupport;
365           }else{
366             SALOME_MED::FAMILY_var aMEDFamily = SALOME_MED::FAMILY::_narrow(aMedSupport);
367             if(!aMEDFamily->_is_nil()) {
368               int aNbCells, aCellsSize;
369               GetCellsSize(aNbCells,aCellsSize,aMEDFamily);
370               if(aNbCells > 0){
371                 if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aFamily = '"<<aSupportName<<"' anEntity = "<<anEntity);
372                 VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
373                 VISU::TFamily& aFamily = aMeshOnEntity.myFamilyMap[aSupportName.in()];
374                 aFamily.myName = aSupportName.in();
375                 aFamily.myEntity = anEntity;
376                 aFamily.myNbCells = aNbCells;
377                 aFamily.myCellsSize = aCellsSize;
378                 aFamily.myId = aMEDFamily->getIdentifier();
379
380                 VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[anEntity];
381                 VISUMED::TFamily& aFamily2 = aMeshOnEntity2.myFamilyMap[aSupportName.in()];
382                 aFamily2.myFamily = aMEDFamily;
383               }
384             }
385             SALOME_MED::GROUP_var aMEDGroup = SALOME_MED::GROUP::_narrow(aMedSupport);
386             if(!aMEDGroup->_is_nil()) {
387               if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aGroup = '"<<aSupportName<<"' anEntity = "<<anEntity);
388               VISUMED::TGroupMap& aGroupMap2 = aMesh2.myGroupMap;
389               VISUMED::TGroup& aGroup2 = aGroupMap2[aSupportName.in()];
390               aGroup2.myGroup = aMEDGroup;
391               SALOME_MED::Family_array_var aFamilies = aMEDGroup->getFamilies();
392               int iFamilyEnd = aFamilies->length();
393               for(int iFamaily = 0; iFamaily < iFamilyEnd; iFamaily++){
394                 aMEDFamily = aFamilies[iFamaily];
395                 CORBA::String_var aFamilyName = aMEDFamily->getName();
396                 VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
397                 if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aGroup - aFamilyName = '"<<aFamilyName.in()<<"'");
398                 VISU::TFamily& aFamily = aMeshOnEntity.myFamilyMap[aFamilyName.in()];
399                 VISU::TBindGroups& aBindGroups = aFamily.myGroups;
400                 aBindGroups.insert(aSupportName.in());
401               }
402             }
403           }
404         }
405         //Correction of TMesh.TGroupMap
406         const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh.myMeshOnEntityMap;
407         if(aMeshOnEntityMap.empty()) continue;
408         VISU::TGroupMap& aGroupMap = aMesh.myGroupMap;
409         VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
410         for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
411           const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
412           const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity.myFamilyMap;
413           if(aFamilyMap.empty()) continue;
414           VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
415           for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
416             const VISU::TFamily& aFamily = aFamilyMapIter->second;
417             const VISU::TBindGroups& aBindGroups = aFamily.myGroups;
418             if(aBindGroups.empty()) continue;
419             VISU::TBindGroups::const_iterator aBindGroupsIter = aBindGroups.begin();
420             for(; aBindGroupsIter != aBindGroups.end(); aBindGroupsIter++){
421               const string& aGroupName = *aBindGroupsIter;
422               VISU::TGroup& aGroup = aGroupMap[aGroupName];
423               aGroup.myName = aGroupName;
424               aGroup.myMeshName = aMesh.myName;
425               aGroup.myNbCells += aFamily.myNbCells;
426               aGroup.myCellsSize += aFamily.myCellsSize;
427               VISU::TFamilyAndEntity aFamilyAndEntity(aFamily.myName,aFamily.myEntity);
428               aGroup.myFamilyAndEntitySet.insert(aFamilyAndEntity);
429             }
430           }
431         }
432       }
433       SALOMEDS::SObject_var aFieldSObj;
434       if(aMedCompSObj->FindSubObject(aTag+2,aFieldSObj)){
435         if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - MEDFIELD found.");
436         SALOMEDS::ChildIterator_var aFieldIterator = aStudy->NewChildIterator(aFieldSObj);
437         for(int iField = 0; aFieldIterator->More(); aFieldIterator->Next(), iField++){
438           aFieldSObj = aFieldIterator->Value();
439           if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aFieldName = '"<<::GetName(aFieldSObj)<<"'");
440           SALOMEDS::ChildIterator_var aTimeStampIterator = aStudy->NewChildIterator(aFieldSObj);
441           for(int iTimeStamp = 1; aTimeStampIterator->More(); aTimeStampIterator->Next(), iTimeStamp++){
442             SALOMEDS::SObject_var aTimeStampSObj = aTimeStampIterator->Value();
443             if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aTimeStampSObj = '"<<::GetName(aTimeStampSObj)<<"'");
444             CORBA::Object_var aMedField = SObjectToObject(aTimeStampSObj);
445             if(CORBA::is_nil(aMedField)) continue;
446             SALOME_MED::FIELD_var aMEDField = SALOME_MED::FIELD::_narrow(aMedField);
447             if(aMEDField->_is_nil()) continue;
448             SALOME_MED::SUPPORT_var aMEDSupport = aMEDField->getSupport();
449             if(aMEDSupport->_is_nil()) continue;
450             SALOME_MED::medEntityMesh aMEDEntity = aMEDSupport->getEntity();
451             VISU::TEntity anEntity = aMed2VisuEntity[aMEDEntity];
452             SALOME_MED::MESH_var aMEDMesh = aMEDSupport->getMesh();
453             if(aMEDMesh->_is_nil()) continue;
454             CORBA::String_var aMeshName = aMEDMesh->getName();
455             CORBA::String_var aFieldName = aMEDField->getName();
456
457             VISU::TMesh &aMesh = myMeshMap[aMeshName.in()];
458             aMesh.myDim = aMEDMesh->getSpaceDimension();
459             aMesh.myName = aMeshName.in();
460             VISUMED::TMesh &aMesh2 = myMeshMap2[aMeshName.in()];
461             aMesh2.myMesh = aMEDMesh;
462
463             VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
464             aMeshOnEntity.myEntity = anEntity;
465             aMeshOnEntity.myMeshName = aMeshName.in();
466             VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[anEntity];
467             aMeshOnEntity2.mySupport = aMEDSupport;
468             if(anEntity == VISU::NODE_ENTITY)
469               aMesh2.myMeshOnEntityMap[VISU::CELL_ENTITY].mySupport = aMEDSupport;
470             GetCellsSize(aMesh,aMEDMesh,anEntity);
471
472             VISU::TField& aField = aMeshOnEntity.myFieldMap[aFieldName.in()];
473             aField.myId = iField;
474             aField.myName = aFieldName.in();
475             aField.myEntity = anEntity;
476             aField.myMeshName = aMeshName.in();
477             aField.myNbComp = aMEDField->getNumberOfComponents();
478             aField.myNbValField = iTimeStamp;
479             aField.myDataSize = aMeshOnEntity.myNbCells * aField.myNbComp;
480             if(MYDEBUG && !iTimeStamp) 
481               MESSAGE("VISU_MEDConvertor::Build - aMeshOnEntity.myNbCells = "<<aMeshOnEntity.myNbCells);
482             aField.myCompNames.resize(aField.myNbComp);
483             aField.myUnitNames.resize(aField.myNbComp);
484
485             int anId = aMEDField->getIterationNumber();
486             VISU::TField::TValForTime& aValForTime = aField.myValField[anId];
487             aValForTime.myId = anId;
488             aValForTime.myTime = VISU::TField::TTime(aMEDField->getTime(),"");
489             VISUMED::TField& aField2 = aMeshOnEntity2.myFieldMap[aFieldName.in()];
490             VISUMED::TField::TValForTime& aValForTime2 = aField2.myValField[anId];
491             aValForTime2.myField = aMEDField;
492             if(MYDEBUG) 
493               MESSAGE("VISU_MEDConvertor::Build - aMeshName = '"<<aMeshName<<
494                       "'; myEntity = "<<anEntity<<"; myTime = "<<aValForTime.myTime.first);
495           }      
496         }
497       }
498       return this; 
499     }
500     return NULL; 
501   }
502   SALOMEDS::ChildIterator_var aTimeStampIterator = aStudy->NewChildIterator(mySObject);
503   for(int iTimeStamp = 1; aTimeStampIterator->More(); aTimeStampIterator->Next(), iTimeStamp++){
504     SALOMEDS::SObject_var aTimeStampSObj = aTimeStampIterator->Value();
505     if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aTimeStampSObj = '"<<::GetName(aTimeStampSObj)<<"'");
506     CORBA::Object_var aMedField = SObjectToObject(aTimeStampSObj);
507     if(CORBA::is_nil(aMedField)) continue;
508     SALOME_MED::FIELD_var aMEDField = SALOME_MED::FIELD::_narrow(aMedField);
509     if(aMEDField->_is_nil()) continue;
510     SALOME_MED::SUPPORT_var aMEDSupport = aMEDField->getSupport();
511     if(aMEDSupport->_is_nil()) continue;
512     SALOME_MED::medEntityMesh aMEDEntity = aMEDSupport->getEntity();
513     VISU::TEntity anEntity = aMed2VisuEntity[aMEDEntity];
514     SALOME_MED::MESH_var aMEDMesh = aMEDSupport->getMesh();
515     if(aMEDMesh->_is_nil()) continue;
516     CORBA::String_var aMeshName = aMEDMesh->getName();
517     CORBA::String_var aFieldName = aMEDField->getName();
518
519     VISU::TMesh &aMesh = myMeshMap[aMeshName.in()];
520     aMesh.myDim = aMEDMesh->getSpaceDimension();
521     aMesh.myName = aMeshName.in();
522     aMesh.myNbPoints = aMEDMesh->getNumberOfNodes();
523     VISUMED::TMesh &aMesh2 = myMeshMap2[aMeshName.in()];
524     aMesh2.myMesh = aMEDMesh;
525     if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh.myDim);
526
527     VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
528     aMeshOnEntity.myEntity = anEntity;
529     aMeshOnEntity.myMeshName = aMeshName.in();
530     VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[anEntity];
531     aMeshOnEntity2.mySupport = aMEDSupport;
532     if(anEntity == VISU::NODE_ENTITY)
533       aMesh2.myMeshOnEntityMap[VISU::CELL_ENTITY].mySupport = aMEDSupport;
534     GetCellsSize(aMesh,aMEDMesh,anEntity);
535
536     VISU::TField& aField = aMeshOnEntity.myFieldMap[aFieldName.in()];
537     CORBA::Short iField = mySObject->Tag();
538     aField.myId = iField;
539     aField.myName = aFieldName.in();
540     aField.myEntity = anEntity;
541     aField.myMeshName = aMeshName.in();
542     aField.myNbComp = aMEDField->getNumberOfComponents();
543     aField.myNbValField = iTimeStamp;
544     aField.myDataSize = aMeshOnEntity.myNbCells * aField.myNbComp;
545     if(MYDEBUG && !iTimeStamp) 
546       MESSAGE("VISU_MEDConvertor::Build - aMeshOnEntity.myNbCells = "<<aMeshOnEntity.myNbCells);
547     aField.myCompNames.resize(aField.myNbComp);
548     aField.myUnitNames.resize(aField.myNbComp);
549
550     int anId = aMEDField->getIterationNumber();
551     VISU::TField::TValForTime& aValForTime = aField.myValField[anId];
552     aValForTime.myId = anId;
553     aValForTime.myTime = VISU::TField::TTime(aMEDField->getTime(),"");
554     VISUMED::TField& aField2 = aMeshOnEntity2.myFieldMap[aFieldName.in()];
555     VISUMED::TField::TValForTime& aValForTime2 = aField2.myValField[anId];
556     aValForTime2.myField = aMEDField;
557     if(MYDEBUG) 
558       MESSAGE("VISU_MEDConvertor::Build - aMeshName = '"<<aMeshName<<
559               "'; myEntity = "<<anEntity<<"; myTime = "<<aValForTime.myTime.first);
560   }
561   return this; 
562 }
563
564 int VISU_MEDConvertor::LoadMeshOnEntity(VISU::TMeshOnEntity& theMeshOnEntity, 
565                                         const string& theFamilyName)
566 {
567   //Main part of code
568   const string& aMeshName = theMeshOnEntity.myMeshName;
569   const VISU::TEntity& anEntity = theMeshOnEntity.myEntity;
570   VISU::TMesh& aMesh = myMeshMap[aMeshName];
571   int isPointsUpdated;
572   if(anEntity == VISU::NODE_ENTITY) 
573     isPointsUpdated = LoadPoints(aMesh,theFamilyName);
574   else 
575     isPointsUpdated = LoadPoints(aMesh);
576   int isCellsOnEntityUpdated = LoadCellsOnEntity(theMeshOnEntity,theFamilyName);
577
578   return (isPointsUpdated || isCellsOnEntityUpdated);
579 }
580   
581 int VISU_MEDConvertor::LoadMeshOnGroup(VISU::TMesh& theMesh, 
582                                        const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet)
583 {
584   //Main part of code
585   int isPointsUpdated = 0;
586   int isCellsOnEntityUpdated = 0;
587   VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = theFamilyAndEntitySet.begin();
588   for(; aFamilyAndEntitySetIter != theFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){
589     const string& aFamilyName = aFamilyAndEntitySetIter->first;
590     const VISU::TEntity& anEntity = aFamilyAndEntitySetIter->second;
591     VISU::TMeshOnEntity& aMeshOnEntity = theMesh.myMeshOnEntityMap[anEntity];
592     if(anEntity == VISU::NODE_ENTITY){
593       isPointsUpdated += LoadPoints(theMesh,aFamilyName);
594       isCellsOnEntityUpdated += LoadCellsOnEntity(aMeshOnEntity);
595     }else{
596       isPointsUpdated += LoadPoints(theMesh);
597       isCellsOnEntityUpdated += LoadCellsOnEntity(aMeshOnEntity,aFamilyName);
598     }
599   }
600
601   return (isPointsUpdated || isCellsOnEntityUpdated);
602 }
603
604 int VISU_MEDConvertor::LoadFieldOnMesh(VISU::TMesh& theMesh, 
605                                        VISU::TMeshOnEntity& theMeshOnEntity, 
606                                        VISU::TField& theField, 
607                                        VISU::TField::TValForTime& theValForTime)
608 {
609   //Main part of code
610   int isPointsUpdated = LoadPoints(theMesh);
611   int isCellsOnEntityUpdated = LoadCellsOnEntity(theMeshOnEntity);
612   int isFieldUpdated = LoadField(theMeshOnEntity,theField,theValForTime);
613   
614   return (isPointsUpdated || isCellsOnEntityUpdated || isFieldUpdated);
615 }
616
617 int VISU_MEDConvertor::LoadPoints(VISU::TMesh& theMesh, const string& theFamilyName)
618 {
619   //Check on existing family
620   VISU::TMeshOnEntity& aMeshOnEntity = theMesh.myMeshOnEntityMap[VISU::NODE_ENTITY];
621   aMeshOnEntity.myEntity = VISU::NODE_ENTITY;
622   aMeshOnEntity.myMeshName = theMesh.myName;
623   VISU::TFamily* pFamily = VISU::GetFamily(aMeshOnEntity,theFamilyName);
624   bool isFamilyPresent = (pFamily != NULL);
625   VISU::TFamily& aFamily = *pFamily;
626   //Check on loading already done
627   bool isPointsLoaded = !theMesh.myPointsCoord.empty();
628   if(isPointsLoaded) 
629     if(!isFamilyPresent) return 0;
630     else if(!aFamily.mySubMesh.empty()) return 0;
631   VISUMED::TMesh& aMesh2 = myMeshMap2[theMesh.myName];
632   SALOME_MED::MESH_var& aMedMesh = aMesh2.myMesh;
633   VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[VISU::NODE_ENTITY];
634   if(MYDEBUG) 
635     MESSAGE("LoadPoints - isPointsLoaded = "<<isPointsLoaded<<"; theFamilyName = '"<<theFamilyName<<"'");
636   theMesh.myDim = aMedMesh->getSpaceDimension();
637   int iNumElemEnd = aMedMesh->getNumberOfNodes();
638   VISU::TMesh::TPointsCoord& aPointsCoord = theMesh.myPointsCoord;
639   if(MYDEBUG) MESSAGE("LoadPoints - iNumElemEnd = "<<iNumElemEnd);
640   if (iNumElemEnd <= 0) throw std::runtime_error("LoadPoints >> There is no points in the mesh !!!");
641   aPointsCoord.resize(theMesh.myDim*iNumElemEnd,0.0);
642    SALOME_MED::double_array_var coord = aMedMesh->getCoordinates(SALOME_MED::MED_FULL_INTERLACE);
643   if(!isPointsLoaded){
644     for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) 
645       for(int iDim = 0, iNumElem2Dim = iNumElem*theMesh.myDim; iDim < theMesh.myDim; iDim++, iNumElem2Dim++)
646         aPointsCoord[iNumElem2Dim] = coord[iNumElem2Dim];
647     if(MYDEBUG) MESSAGE("LoadPoints - Filling aMeshOnEntity with type NODE_ENTITY");
648     VISU::TMeshOnEntity::TConnForCellType& aConnForCellType = aMeshOnEntity.myCellsConn[VTK_VERTEX];
649     aConnForCellType.resize(iNumElemEnd);
650     for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
651       aConnForCellType[iNumElem] = VISU::TMeshOnEntity::TConnect(1,iNumElem);
652   }
653   if(isFamilyPresent){
654     if(MYDEBUG) MESSAGE("LoadPoints - Filling aFamily SubMesh");
655     VISUMED::TFamily aFamily2 = aMeshOnEntity2.myFamilyMap[aFamily.myName];
656     SALOME_MED::FAMILY_var aMedFamily = aFamily2.myFamily;
657     VISU::TFamily::TSubMeshOnCellType& aSubMeshOnCellType = aFamily.mySubMesh[VTK_VERTEX];
658     SALOME_MED::medGeometryElement_array_var aGeom = aMedFamily->getTypes();
659     SALOME_MED::long_array_var aCellNumForType = aMedFamily->getNumber(aGeom[0]);
660     int iNumElemEndTmp = iNumElemEnd;
661     iNumElemEnd = aCellNumForType->length();
662     for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) {
663       int tmp = aCellNumForType[iNumElem]-1;
664       if(0 > tmp || tmp >= iNumElemEndTmp) {
665         static QString aString;
666         aString.sprintf("LoadPoints >> iNumElemEndTmp(%d) <= aCellNumForType[%d]=%d < 0 !!!",iNumElemEnd,iNumElem,tmp);
667         throw std::runtime_error(aString.latin1());
668       }
669       aSubMeshOnCellType.insert(tmp);
670     }
671   }
672   return 1;
673 }
674
675 int VISU_MEDConvertor::LoadCellsOnEntity(VISU::TMeshOnEntity& theMeshOnEntity, const string& theFamilyName)
676 {
677   //Check on existing family
678   VISU::TFamily* pFamily = VISU::GetFamily(theMeshOnEntity,theFamilyName);
679   bool isFamilyPresent = (pFamily != NULL);
680   VISU::TFamily& aFamily = *pFamily;
681   //Check on loading already done
682   bool isCellsLoaded = !theMeshOnEntity.myCellsConn.empty();
683   if(isCellsLoaded) 
684     if(!isFamilyPresent) return 0;
685     else if(!aFamily.mySubMesh.empty()) return 0;
686   VISUMED::TMesh& aMesh2 = myMeshMap2[theMeshOnEntity.myMeshName];
687   VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[theMeshOnEntity.myEntity];
688   SALOME_MED::SUPPORT_var& aMedSupport = aMeshOnEntity2.mySupport;
689   SALOME_MED::MESH_var aMedMesh = aMedSupport->getMesh();
690   if(MYDEBUG) {
691     MESSAGE("LoadCellsOnEntity - theFamilyName = '"<<theFamilyName<<"'");
692     MESSAGE("LoadCellsOnEntity - isCellsLoaded = "<<isCellsLoaded<<"; isFamilyPresent = "<<isFamilyPresent);
693   }
694   //Main part of code
695   int iGeomElemEnd;
696   int* aGeomElemVector;
697   const VISU::TEntity& anEntity = theMeshOnEntity.myEntity;
698   GetEntity2Geom(anEntity,aGeomElemVector,&iGeomElemEnd);
699   const SALOME_MED::medEntityMesh& aMedEntity = aVisu2MedEntity[anEntity];
700   VISU::TMesh &aMesh = myMeshMap[theMeshOnEntity.myMeshName];
701   int aNbPoints = aMesh.myPointsCoord.size()/aMesh.myDim;
702   if(!isCellsLoaded){
703     for (int iGeomElem = 0, aCounter = 0; iGeomElem < iGeomElemEnd; iGeomElem++) {
704       int medId = GetIdMEDType(aGeomElemVector[iGeomElem]);
705       int nbMedNodes = salome_med2vtk[medId].medNbNodes;
706       int nbVtkNodes = salome_med2vtk[medId].vtkNbNodes;
707       int aVtkType = salome_med2vtk[medId].vtkType;
708       SALOME_MED::medGeometryElement aMedType = salome_med2vtk[medId].medType;
709       med_int iNumElemEnd = aMedMesh->getNumberOfElements(aMedEntity,aMedType);
710       if (iNumElemEnd > 0) {
711         SALOME_MED::long_array_var conn = 
712           aMedMesh->getConnectivity(SALOME_MED::MED_FULL_INTERLACE,SALOME_MED::MED_NODAL,aMedEntity,aMedType);
713         VISU::TMeshOnEntity::TConnForCellType& aConnForCellType = theMeshOnEntity.myCellsConn[aVtkType];
714         //APO - aConnForCellType.resize(iNumElemEnd);
715         valarray<med_int> aConnect(nbMedNodes);
716         int aNbConnForElem = conn->length()/iNumElemEnd;
717         if(MYDEBUG) MESSAGE("LoadCellsOnEntity - medName = "<<salome_med2vtk[medId].medName<<
718                             "; iNumElemEnd = "<<iNumElemEnd<<"; aNbConnForElem = "<<aNbConnForElem);
719         for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) {
720           //APO - VISU::TMeshOnEntity::TConnect& anArray = aConnForCellType[iNumElem];
721           //APO - anArray.resize(nbVtkNodes);
722           VISU::TMeshOnEntity::TConnect anArray(nbVtkNodes);
723           for (int k = 0, kj = iNumElem*aNbConnForElem; k < nbMedNodes; k++) {
724             aConnect[k] = conn[kj+k] - 1;
725           }
726           switch(aMedType){
727           case SALOME_MED::MED_TETRA4 :
728           case SALOME_MED::MED_TETRA10 :
729             anArray[0] = aConnect[0];
730             anArray[1] = aConnect[1];
731             anArray[2] = aConnect[3];  
732             anArray[3] = aConnect[2];  
733             break;
734           case SALOME_MED::MED_PYRA5 :
735           case SALOME_MED::MED_PYRA13 :
736             anArray[0] = aConnect[0];
737             anArray[1] = aConnect[3];  
738             anArray[2] = aConnect[2];
739             anArray[3] = aConnect[1];  
740             anArray[4] = aConnect[4];
741             break;
742           default:
743             for (int k = 0; k < nbVtkNodes; k++) 
744               anArray[k] = aConnect[k];
745           }
746           for (int k = 0; k < nbVtkNodes; k++) 
747             if(anArray[k] < 0 || aNbPoints <= anArray[k]){
748               static QString aString;
749               aString.sprintf("ImportCells >> aNbPoints(%d) <= anArray[%d][%d]=%d < 0 !!!",aNbPoints,iNumElem,k,anArray[k]);
750               throw std::runtime_error(aString.latin1());
751             }
752           aConnForCellType.push_back(anArray);
753         }
754         //Workaround for MED Component data structure
755         int aSize = aConnForCellType.size();
756         aMeshOnEntity2.myCellsFirstIndex[aMedType] = VISUMED::TMeshOnEntity::TIndexAndSize(aCounter,aSize);
757         aCounter += aSize;
758       }
759     }
760   }
761   //Filling aFamily SubMesh
762   if(isFamilyPresent){
763     VISUMED::TFamily aFamily2 = aMeshOnEntity2.myFamilyMap[aFamily.myName];
764     SALOME_MED::FAMILY_var aMedFamily = aFamily2.myFamily;
765     SALOME_MED::medGeometryElement_array_var aGeom = aMedFamily->getTypes();
766     iGeomElemEnd = aGeom->length();
767     if(MYDEBUG) MESSAGE("LoadCellsOnEntity - iGeomElemEnd = "<<iGeomElemEnd);
768     for (int iGeomElem = 0; iGeomElem < iGeomElemEnd; iGeomElem++) {
769       SALOME_MED::medGeometryElement aGeomType = aGeom[iGeomElem];
770       SALOME_MED::long_array_var aCellNumForType = aMedFamily->getNumber(aGeomType);
771       int medId = GetIdMEDType(aGeomType);
772       int aVtkType = salome_med2vtk[medId].vtkType;
773       SALOME_MED::medGeometryElement aMedType = salome_med2vtk[medId].medType;
774       VISU::TFamily::TSubMeshOnCellType& aSubMeshOnCellType = aFamily.mySubMesh[aVtkType]; 
775       med_int iNumElemEndTmp = theMeshOnEntity.myCellsConn[aVtkType].size();
776       med_int iNumElemEnd = aCellNumForType->length();
777       int aCounter = aMeshOnEntity2.myCellsFirstIndex[aMedType].first;
778       if(MYDEBUG) 
779         MESSAGE("LoadCellsOnEntity - medName = "<<salome_med2vtk[medId].medName<<
780                 "; iNumElemEnd = "<<iNumElemEnd<<"; aCounter = "<<aCounter);
781       for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) {
782         int tmp = aCellNumForType[iNumElem]-aCounter-1;
783         if(0 > tmp || tmp >= iNumElemEndTmp) {
784           static QString aString;
785           aString.sprintf("LoadCellsOnEntity >> iNumElemEndTmp(%d) <= aCellNumForType[%d]=%d < 0 !!!",iNumElemEndTmp,iNumElem,tmp);
786           throw std::runtime_error(aString.latin1());
787         }
788         aSubMeshOnCellType.insert(tmp);
789       }
790     }
791   }
792   return 1;
793 }
794
795 template<class TArray> int ImportField(TArray& theArray, 
796                                        const VISU::TMesh& theMesh,
797                                        const VISU::TField& theField,
798                                        VISU::TField::TValForTime& theValForTime,
799                                        const VISU::TMeshOnEntity& theMeshOnEntity,
800                                        const VISUMED::TMeshOnEntity& theMeshOnEntity2)
801 {
802   if(theField.myEntity == VISU::NODE_ENTITY){
803     VISU::TField::TValForCellsWithType& aValForCellsWithType = theValForTime.myValForCells[VTK_VERTEX];
804     int iNumElemEnd = theMesh.myPointsCoord.size()/theMesh.myDim*theField.myNbComp;
805     if(MYDEBUG) MESSAGE("ImportField - iNumElemEnd = "<<iNumElemEnd);
806     aValForCellsWithType.resize(iNumElemEnd);
807     for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) 
808       aValForCellsWithType[iNumElem] = theArray[iNumElem];
809   }else{
810     int iGeomElemEnd;
811     int* aGeomElemVector;
812     const VISU::TEntity& anEntity = theField.myEntity;
813     GetEntity2Geom(anEntity,aGeomElemVector,&iGeomElemEnd);
814     for (int iGeomElem = 0, aCounter = 0; iGeomElem < iGeomElemEnd; iGeomElem++) {
815       int medId = GetIdMEDType(aGeomElemVector[iGeomElem]);
816       int aVtkType = salome_med2vtk[medId].vtkType;
817       SALOME_MED::medGeometryElement aMedType = salome_med2vtk[medId].medType;
818       const VISUMED::TMeshOnEntity::TCellsFirstIndex& aCellsFirstIndex = theMeshOnEntity2.myCellsFirstIndex;
819       VISUMED::TMeshOnEntity::TCellsFirstIndex::const_iterator aCellsFirstIndexIter = aCellsFirstIndex.find(aMedType);
820       if(aCellsFirstIndexIter != aCellsFirstIndex.end()){
821         const VISU::TMeshOnEntity::TCellsConn& aCellsConn = theMeshOnEntity.myCellsConn;
822         VISU::TMeshOnEntity::TCellsConn::const_iterator aCellsConnIter = aCellsConn.find(aVtkType);
823         const VISU::TMeshOnEntity::TConnForCellType& aConnForCellType = aCellsConnIter->second;
824         const VISUMED::TMeshOnEntity::TIndexAndSize& aIndexAndSize = aCellsFirstIndexIter->second;
825         int iNumElemEnd = aIndexAndSize.second;
826         if(MYDEBUG) 
827           MESSAGE("ImportField - medName = "<<salome_med2vtk[medId].medName<<
828                   "; aIndexAndSize = {"<<aIndexAndSize.first<<","<<aIndexAndSize.second<<"}");
829         VISU::TField::TValForCellsWithType& aValForCellsWithType = theValForTime.myValForCells[aVtkType];
830         aValForCellsWithType.resize(iNumElemEnd*theField.myNbComp);
831         for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
832           for (int k = 0, kj = iNumElem*theField.myNbComp; k < theField.myNbComp; k++)
833             aValForCellsWithType[kj+k] = theArray[aIndexAndSize.first*theField.myNbComp+kj+k];
834       }
835     }
836   }
837   return 1;
838 }
839
840 int VISU_MEDConvertor::LoadField(const VISU::TMeshOnEntity& theMeshOnEntity,
841                                  const VISU::TField& theField, VISU::TField::TValForTime& theValForTime)
842 {
843   //Check on loading already done
844   if(!theValForTime.myValForCells.empty()) return 0;
845   VISU::TMesh& aMesh = myMeshMap[theMeshOnEntity.myMeshName];
846   VISUMED::TMesh& aMesh2 = myMeshMap2[theMeshOnEntity.myMeshName];
847   VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[theMeshOnEntity.myEntity];
848   VISUMED::TField& aField2 = aMeshOnEntity2.myFieldMap[theField.myName];
849   VISUMED::TField::TValForTime& aValForTime2 = aField2.myValField[theValForTime.myId];
850   SALOME_MED::FIELD_var aMEDField = aValForTime2.myField;
851   //Main part of code
852   SALOME_MED::FIELDDOUBLE_ptr aFieldDouble = SALOME_MED::FIELDDOUBLE::_narrow(aMEDField);
853   if(!aFieldDouble->_is_nil()){
854     SALOME_MED::double_array_var anArray = aFieldDouble->getValue(SALOME_MED::MED_FULL_INTERLACE);
855     if(MYDEBUG) MESSAGE("VISU_MEDConvertor::LoadField - There is FIELDDOUBLE = "<<anArray->length());
856     ::ImportField(anArray,aMesh,theField,theValForTime,theMeshOnEntity,aMeshOnEntity2);
857   }
858   SALOME_MED::FIELDINT_ptr aFieldInt = SALOME_MED::FIELDINT::_narrow(aMEDField);
859   if(!aFieldInt->_is_nil()){
860     SALOME_MED::long_array_var anArray = aFieldInt->getValue(SALOME_MED::MED_FULL_INTERLACE);
861     if(MYDEBUG) MESSAGE("VISU_MEDConvertor::LoadField - There is FIELDINT = "<<anArray->length());
862     ::ImportField(anArray,aMesh,theField,theValForTime,theMeshOnEntity,aMeshOnEntity2);
863   }
864   return 1;
865 }