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