Salome HOME
61d8e0f54979fb8c4302e933378f92d97ae25546
[modules/med.git] / src / MEDCouplingCorba / MEDCouplingFieldDoubleServant.cxx
1 // Copyright (C) 2007-2021  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 "MEDCouplingFieldDoubleServant.hxx"
22 #include "MEDCouplingFieldDouble.hxx"
23
24 using namespace MEDCoupling;
25
26 MEDCouplingFieldDoubleServant::MEDCouplingFieldDoubleServant(const MEDCouplingFieldDouble *cppPointerOfMesh):MEDCouplingFieldServant(cppPointerOfMesh)
27 {
28 }
29
30 char *MEDCouplingFieldDoubleServant::getName()
31 {
32   return CORBA::string_dup(getPointer()->getName().c_str());
33 }
34
35 SALOME_TYPES::ListOfString *MEDCouplingFieldDoubleServant::getInfoOnComponents()
36 {
37   const DataArrayDouble *arr=getPointer()->getArray();
38   SALOME_TYPES::ListOfString *ret=new SALOME_TYPES::ListOfString;
39   if(arr)
40     {
41       const std::vector<std::string> &comps=arr->getInfoOnComponents();
42       ret->length(comps.size());
43       for(std::size_t i=0;i<comps.size();i++)
44         (*ret)[i]=CORBA::string_dup(comps[i].c_str());
45       return ret;
46     }
47   else
48     throw INTERP_KERNEL::Exception("MEDCouplingFieldDoubleServant::getInfoOnComponents : no array specified !");
49 }
50
51 void MEDCouplingFieldDoubleServant::getTinyInfo(SALOME_TYPES::ListOfLong_out la, SALOME_TYPES::ListOfDouble_out da, SALOME_TYPES::ListOfString_out sa)
52 {
53   la=new SALOME_TYPES::ListOfLong;
54   std::vector<mcIdType> tinyInfo;
55   getPointer()->getTinySerializationIntInformation(tinyInfo);
56   la->length(tinyInfo.size());
57   for(int i=0;i<(int)tinyInfo.size();i++)
58     (*la)[i]=tinyInfo[i];
59   //
60   da=new SALOME_TYPES::ListOfDouble;
61   std::vector<double> tinyInfo2;
62   getPointer()->getTinySerializationDbleInformation(tinyInfo2);
63   da->length(tinyInfo2.size());
64   for(int i=0;i<(int)tinyInfo2.size();i++)
65     (*da)[i]=tinyInfo2[i];
66   //
67   sa=new SALOME_TYPES::ListOfString;
68   std::vector<std::string> tinyInfo3;
69   getPointer()->getTinySerializationStrInformation(tinyInfo3);
70   sa->length(tinyInfo3.size());
71   for(int i=0;i<(int)tinyInfo3.size();i++)
72     (*sa)[i]=CORBA::string_dup(tinyInfo3[i].c_str());
73 }
74
75 void MEDCouplingFieldDoubleServant::getSerialisationData(SALOME_TYPES::ListOfLong_out la, SALOME_TYPES::ListOfDouble2_out da2)
76 {
77   std::vector<DataArrayDouble *> arrays;
78   DataArrayIdType *dataInt;
79   getPointer()->serialize(dataInt,arrays);
80   //
81   la=new SALOME_TYPES::ListOfLong;
82   if(dataInt)
83     {
84       mcIdType lgth=dataInt->getNbOfElems();
85       const mcIdType *ptr=dataInt->getConstPointer();
86       la->length(lgth);
87       for(mcIdType i=0;i<lgth;i++)
88         (*la)[i]=ptr[i];
89     }
90   else
91     la->length(0);
92   //
93   da2=new SALOME_TYPES::ListOfDouble2;
94   int lgth=arrays.size();
95   da2->length(lgth);
96   for(int i=0;i<lgth;i++)
97     {
98       SALOME_TYPES::ListOfDouble& locCorbaArr=(*da2)[i];
99       DataArrayDouble *locArr=arrays[i];
100       int lgth2=locArr->getNbOfElems();
101       locCorbaArr.length(lgth2);
102       const double *pt=locArr->getConstPointer();
103       for(int j=0;j<lgth2;j++)
104         locCorbaArr[j]=pt[j];
105     }
106 }
107
108 CORBA::Boolean MEDCouplingFieldDoubleServant::ExportDataAs(const char *format, SALOME::GenericObj_out exporter)
109 {
110   std::string frmCpp(format);
111   if(frmCpp=="MEDCorba")
112     {
113       SALOME_MED::MEDCouplingFieldDoubleCorbaInterface_ptr cPtr=_this();
114       Register();
115       exporter=cPtr;
116       return true;
117     }
118   exporter=SALOME::GenericObj::_nil();
119   return false;
120 }