Salome HOME
Merge branch 'V9_2_2_BR'
[modules/med.git] / src / MEDCouplingCorba / Client / MEDCouplingFieldDoubleClient.cxx
1 // Copyright (C) 2007-2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDCouplingFieldDoubleClient.hxx"
22 #include "MEDCouplingMeshClient.hxx"
23 #include "MEDCouplingMesh.hxx"
24
25 #include <vector>
26
27 using namespace MEDCoupling;
28
29 MEDCouplingFieldDouble *MEDCouplingFieldDoubleClient::New(SALOME_MED::MEDCouplingFieldDoubleCorbaInterface_ptr fieldPtr)
30 {
31   fieldPtr->Register();
32   //
33   SALOME_TYPES::ListOfLong *tinyL;
34   SALOME_TYPES::ListOfDouble *tinyD;
35   SALOME_TYPES::ListOfString *tinyS;
36   //1st CORBA call : getting all tiny info of all types (int, double string).
37   fieldPtr->getTinyInfo(tinyL,tinyD,tinyS);
38   int tinyLgth=tinyL->length();
39   std::vector<int> tinyLV(tinyLgth);
40   for(int i=0;i<tinyLgth;i++)
41     tinyLV[i]=(*tinyL)[i];
42   delete tinyL;
43   //
44   tinyLgth=tinyD->length();
45   std::vector<double> tinyLD(tinyLgth);
46   for(int i=0;i<tinyLgth;i++)
47     tinyLD[i]=(*tinyD)[i];
48   delete tinyD;
49   //
50   tinyLgth=tinyS->length();
51   std::vector<std::string> tinyLS(tinyLgth);
52   for(int i=0;i<tinyLgth;i++)
53     tinyLS[i]=(*tinyS)[i];
54   delete tinyS;
55   //
56   TypeOfField type=(TypeOfField) tinyLV[0];
57   TypeOfTimeDiscretization td=(TypeOfTimeDiscretization) tinyLV[1];
58   MEDCouplingFieldDouble *ret=MEDCouplingFieldDouble::New(type,td);
59   //2nd CORBA call to retrieves the mesh.
60   SALOME_MED::MEDCouplingMeshCorbaInterface_ptr meshPtr=fieldPtr->getMesh();
61   MEDCouplingMesh *mesh=MEDCouplingMeshClient::New(meshPtr);
62   meshPtr->UnRegister();
63   CORBA::release(meshPtr);
64   ret->setMesh(mesh);
65   mesh->decrRef();
66   DataArrayInt *array0;
67   std::vector<DataArrayDouble *> arrays;
68   ret->resizeForUnserialization(tinyLV,array0,arrays);
69   SALOME_TYPES::ListOfLong *bigArr0;
70   SALOME_TYPES::ListOfDouble2 *bigArr;
71   //3rd CORBA invocation to get big content
72   fieldPtr->getSerialisationData(bigArr0,bigArr);
73   if(bigArr0->length()!=0)
74     {
75       int *pt=array0->getPointer();
76       int lgth=array0->getNbOfElems();
77       for(int i=0;i<lgth;i++)
78         pt[i]=(*bigArr0)[i];
79     }
80   delete bigArr0;
81   tinyLgth=arrays.size();
82   for(int i=0;i<tinyLgth;i++)
83     {
84       SALOME_TYPES::ListOfDouble& oneArr=(*bigArr)[i];
85       DataArrayDouble *curArrToFill=arrays[i];
86       double *pt=curArrToFill->getPointer();
87       int lgth=curArrToFill->getNbOfElems();
88       for(int j=0;j<lgth;j++)
89         pt[j]=oneArr[j];
90     }
91   delete bigArr;
92   //
93   //notify server that the servant is no more used.
94   fieldPtr->UnRegister();
95   //
96   ret->finishUnserialization(tinyLV,tinyLD,tinyLS);
97   //
98   return ret;
99 }