Salome HOME
4ad005aa599fa7cf985f7cd3bab5c0844ef5cba9
[modules/med.git] / src / MEDCouplingCorba / MEDCouplingMeshServant.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 "MEDCouplingMeshServant.hxx"
22 #include "InterpKernelException.hxx"
23 #include "MEDCouplingMesh.hxx"
24 #include "MEDCouplingMemArray.hxx"
25
26 using namespace MEDCoupling;
27
28 MEDCouplingMeshServant::MEDCouplingMeshServant(const MEDCouplingMesh *cppPointerOfMesh):MEDCouplingRefCountServant(cppPointerOfMesh,cppPointerOfMesh)
29 {
30 }
31
32 char *MEDCouplingMeshServant::getName()
33 {
34   return CORBA::string_dup(getPointer()->getName().c_str());
35 }
36
37 void MEDCouplingMeshServant::getTinyInfo(SALOME_TYPES::ListOfDouble_out da, SALOME_TYPES::ListOfLong_out la, SALOME_TYPES::ListOfString_out sa)
38 {
39   da=new SALOME_TYPES::ListOfDouble;
40   la=new SALOME_TYPES::ListOfLong;
41   std::vector<double> tinyInfoD;
42   std::vector<int> tinyInfoI;
43   std::vector<std::string> tinyInfoS;
44   getPointer()->getTinySerializationInformation(tinyInfoD,tinyInfoI,tinyInfoS);
45   da->length(tinyInfoD.size());
46   la->length(tinyInfoI.size());
47   for(int i=0;i<(int)tinyInfoD.size();i++)
48     (*da)[i]=tinyInfoD[i];
49   for(int i=0;i<(int)tinyInfoI.size();i++)
50     (*la)[i]=tinyInfoI[i];
51   //
52   sa=new SALOME_TYPES::ListOfString;
53   int nbOfSts=tinyInfoS.size();
54   sa->length(nbOfSts);
55   for(int i=0;i<nbOfSts;i++)
56     (*sa)[i]=CORBA::string_dup(tinyInfoS[i].c_str());
57 }
58
59 void MEDCouplingMeshServant::getSerialisationData(SALOME_TYPES::ListOfLong_out la, SALOME_TYPES::ListOfDouble_out da)
60 {
61   DataArrayInt *array1;
62   DataArrayDouble *array2;
63   getPointer()->serialize(array1,array2);
64   la=new SALOME_TYPES::ListOfLong;
65   if(array1)
66     {
67       int lgth=array1->getNbOfElems();
68       const int *data=array1->getConstPointer();
69       la->length(lgth);
70       for(int i=0;i<lgth;i++)
71         (*la)[i]=data[i];
72       array1->decrRef();
73     }
74   //
75   da=new SALOME_TYPES::ListOfDouble;
76   if(array2)
77     {
78       int lgth=array2->getNbOfElems();
79       const double *data2=array2->getConstPointer();
80       da->length(lgth);
81       for(int i=0;i<lgth;i++)
82         (*da)[i]=data2[i];
83       //
84       array2->decrRef();
85     }
86 }
87
88 CORBA::Boolean MEDCouplingMeshServant::ExportDataAs(const char *format, SALOME::GenericObj_out exporter)
89 {
90   std::string frmCpp(format);
91   if(frmCpp=="MEDCorba")
92     {
93       SALOME_MED::MEDCouplingMeshCorbaInterface_ptr cPtr=_this();
94       Register();
95       exporter=cPtr;
96       return true;
97     }
98   exporter=SALOME::GenericObj::_nil();
99   return false;
100 }