Salome HOME
29eb6499bca84948033b50c0e92a73cc59687523
[modules/med.git] / src / MEDCouplingCorba / Client / MEDCouplingFieldTemplateClient.cxx
1 // Copyright (C) 2007-2023  CEA, EDF
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 "MEDCouplingFieldTemplateClient.hxx"
22 #include "MEDCouplingMeshClient.hxx"
23 #include "MEDCouplingMemArray.hxx"
24 #include "MEDCouplingMesh.hxx"
25
26 #include <vector>
27
28 using namespace MEDCoupling;
29
30 MEDCouplingFieldTemplate *MEDCouplingFieldTemplateClient::New(SALOME_MED::MEDCouplingFieldTemplateCorbaInterface_ptr fieldPtr)
31 {
32   fieldPtr->Register();
33   //
34   SALOME_TYPES::ListOfLong *tinyL;
35   SALOME_TYPES::ListOfDouble *tinyD;
36   SALOME_TYPES::ListOfString *tinyS;
37   //1st CORBA call : getting all tiny info of all types (int, double string).
38   fieldPtr->getTinyInfo(tinyL,tinyD,tinyS);
39   int tinyLgth=tinyL->length();
40   std::vector<mcIdType> tinyLV(tinyLgth);
41   for(int i=0;i<tinyLgth;i++)
42     tinyLV[i]=(*tinyL)[i];
43   delete tinyL;
44   //
45   tinyLgth=tinyD->length();
46   std::vector<double> tinyLD(tinyLgth);
47   for(int i=0;i<tinyLgth;i++)
48     tinyLD[i]=(*tinyD)[i];
49   delete tinyD;
50   //
51   tinyLgth=tinyS->length();
52   std::vector<std::string> tinyLS(tinyLgth);
53   for(int i=0;i<tinyLgth;i++)
54     tinyLS[i]=(*tinyS)[i];
55   delete tinyS;
56   //
57   TypeOfField type=(TypeOfField) tinyLV[0];
58   MEDCouplingFieldTemplate *ret=MEDCouplingFieldTemplate::New(type);
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   DataArrayIdType *array0;
67   ret->resizeForUnserialization(tinyLV,array0);
68   SALOME_TYPES::ListOfLong *bigArr0;
69   //3rd CORBA invocation to get big content
70   fieldPtr->getSerialisationData(bigArr0);
71   if(bigArr0->length()!=0)
72     {
73       mcIdType *pt=array0->getPointer();
74       mcIdType lgth=array0->getNbOfElems();
75       for(mcIdType i=0;i<lgth;i++)
76         pt[i]=(*bigArr0)[i];
77     }
78   delete bigArr0;
79   //
80   //notify server that the servant is no more used.
81   fieldPtr->UnRegister();
82   //
83   ret->finishUnserialization(tinyLV,tinyLD,tinyLS);
84   //
85   return ret;
86 }