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