Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/med.git] / src / MEDCouplingCorba / MEDCouplingMultiFieldsServant.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 "MEDCouplingMultiFieldsServant.hxx"
21 #include "DataArrayDoubleServant.hxx"
22 #include "MEDCouplingFieldServant.hxx"
23 #include "MEDCouplingMultiFields.hxx"
24 #include "MEDCouplingFieldDouble.hxx"
25 #include "MEDCouplingFieldTemplate.hxx"
26 #include "MEDCouplingMemArray.hxx"
27
28 using namespace ParaMEDMEM;
29
30 MEDCouplingMultiFieldsServant::MEDCouplingMultiFieldsServant(const MEDCouplingMultiFields *cppPointer):MEDCouplingRefCountServant(cppPointer,cppPointer)
31 {
32 }
33
34 SALOME_MED::MEDCouplingMeshesCorbaInterface *MEDCouplingMultiFieldsServant::getMeshes()
35 {
36   SALOME_MED::MEDCouplingMeshesCorbaInterface *ret=new SALOME_MED::MEDCouplingMeshesCorbaInterface;
37   std::vector<int> tmp;
38   std::vector<MEDCouplingMesh *> cppMeshes=getPointer()->getDifferentMeshes(tmp);
39   int sz=cppMeshes.size();
40   ret->length(sz);
41   for(int i=0;i<sz;i++)
42     (*ret)[i]=MEDCouplingFieldServant::BuildCorbaRefFromCppPointer(cppMeshes[i]);
43   return ret;
44 }
45
46 SALOME_MED::MEDCouplingMeshCorbaInterface_ptr MEDCouplingMultiFieldsServant::getMeshWithId(CORBA::Long id)
47 {
48   std::vector<int> tmp;
49   std::vector<MEDCouplingMesh *> cppMeshes=getPointer()->getDifferentMeshes(tmp);
50   return MEDCouplingFieldServant::BuildCorbaRefFromCppPointer(cppMeshes[id]);
51 }
52
53 char *MEDCouplingMultiFieldsServant::getName()
54 {
55   return CORBA::string_dup(getPointer()->getName().c_str());
56 }
57
58 SALOME_TYPES::ListOfString *MEDCouplingMultiFieldsServant::getInfoOnComponents()
59 {
60   std::vector<const MEDCouplingFieldDouble *> fs=getPointer()->getFields();
61   for(std::vector<const MEDCouplingFieldDouble *>::const_iterator it=fs.begin();it!=fs.end();it++)
62     {
63       if(*it)
64         {
65           const DataArrayDouble *arr=(*it)->getArray();
66           if(arr)
67             {
68               SALOME_TYPES::ListOfString *ret=new SALOME_TYPES::ListOfString;
69               const std::vector<std::string> &comps=arr->getInfoOnComponents();
70               ret->length(comps.size());
71               for(std::size_t i=0;i<comps.size();i++)
72                 (*ret)[i]=CORBA::string_dup(comps[i].c_str());
73               return ret;
74             }
75         }
76     }
77   throw INTERP_KERNEL::Exception("MEDCouplingMultiFieldsServant::getInfoOnComponents : impossible to find a not null DataArrayDouble !");
78 }
79
80 CORBA::Long MEDCouplingMultiFieldsServant::getMainTinyInfo(SALOME_TYPES::ListOfLong_out la, SALOME_TYPES::ListOfDouble_out da, CORBA::Long& nbOfArrays, CORBA::Long& nbOfFields)
81 {
82   std::vector<int> tinyInfo;
83   std::vector<double> tinyInfo2;
84   int nbOfDiffMeshes, nbOfDiffArr;
85   nbOfFields=getPointer()->getNumberOfFields();
86   getPointer()->getTinySerializationInformation(tinyInfo,tinyInfo2,nbOfDiffMeshes,nbOfDiffArr);
87   nbOfArrays=nbOfDiffArr;
88   la=new SALOME_TYPES::ListOfLong;
89   la->length(tinyInfo.size());
90   for(int i=0;i<(int)tinyInfo.size();i++)
91     (*la)[i]=tinyInfo[i];
92   //
93   da=new SALOME_TYPES::ListOfDouble;
94   da->length(tinyInfo2.size());
95   for(int i=0;i<(int)tinyInfo2.size();i++)
96     (*da)[i]=tinyInfo2[i];
97   return nbOfDiffMeshes;
98 }
99
100 void MEDCouplingMultiFieldsServant::getTinyInfo(CORBA::Long id, SALOME_TYPES::ListOfLong_out la, SALOME_TYPES::ListOfDouble_out da, SALOME_TYPES::ListOfString_out sa)
101 {
102   const MEDCouplingFieldDouble *f=getPointer()->getFieldWithId(id);
103   MEDCouplingFieldTemplate *f2=MEDCouplingFieldTemplate::New(f);
104   la=new SALOME_TYPES::ListOfLong;
105   std::vector<int> tinyInfo;
106   f2->getTinySerializationIntInformation(tinyInfo);
107   la->length(tinyInfo.size());
108   for(int i=0;i<(int)tinyInfo.size();i++)
109     (*la)[i]=tinyInfo[i];
110   //
111   da=new SALOME_TYPES::ListOfDouble;
112   std::vector<double> tinyInfo2;
113   f2->getTinySerializationDbleInformation(tinyInfo2);
114   da->length(tinyInfo2.size());
115   for(int i=0;i<(int)tinyInfo2.size();i++)
116     (*da)[i]=tinyInfo2[i];
117   //
118   sa=new SALOME_TYPES::ListOfString;
119   std::vector<std::string> tinyInfo3;
120   f2->getTinySerializationStrInformation(tinyInfo3);
121   sa->length(tinyInfo3.size());
122   for(int i=0;i<(int)tinyInfo3.size();i++)
123     (*sa)[i]=CORBA::string_dup(tinyInfo3[i].c_str());
124   f2->decrRef();
125 }
126
127 void MEDCouplingMultiFieldsServant::getSerialisationData(CORBA::Long id, SALOME_TYPES::ListOfLong_out la)
128 {
129   const MEDCouplingFieldDouble *f=getPointer()->getFieldWithId(id);
130   MEDCouplingFieldTemplate *f2=MEDCouplingFieldTemplate::New(f);
131   DataArrayInt *dataInt;
132   f2->serialize(dataInt);
133   //
134   la=new SALOME_TYPES::ListOfLong;
135   if(dataInt)
136     {
137       int lgth=dataInt->getNbOfElems();
138       const int *ptr=dataInt->getConstPointer();
139       la->length(lgth);
140       for(int i=0;i<lgth;i++)
141         (*la)[i]=ptr[i];
142     }
143   else
144     la->length(0);
145   f2->decrRef();
146 }
147
148 SALOME_MED::DataArrayDoubleCorbaInterface_ptr MEDCouplingMultiFieldsServant::getArray(CORBA::Long id)
149 {
150   std::vector< std::vector<int> > refs;
151   std::vector<DataArrayDouble *> das=getPointer()->getDifferentArrays(refs);
152   DataArrayDoubleServant *retServ=new DataArrayDoubleServant(das[id]);
153   return retServ->_this();
154 }
155
156 CORBA::Boolean MEDCouplingMultiFieldsServant::ExportDataAs(const char *format, SALOME::GenericObj_out exporter)
157 {
158   std::string frmCpp(format);
159   if(frmCpp=="MEDCorba")
160     {
161       SALOME_MED::MEDCouplingMultiFieldsCorbaInterface_ptr cPtr=_this();
162       Register();
163       exporter=cPtr;
164       return true;
165     }
166   exporter=SALOME::GenericObj::_nil();
167   return false;
168 }