Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/med.git] / src / MEDCouplingCorba / Client / MEDCouplingMeshClient.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 "MEDCouplingMeshClient.hxx"
21 #include "MEDCouplingUMeshClient.hxx"
22 #include "MEDCouplingExtrudedMeshClient.hxx"
23 #include "MEDCouplingExtrudedMesh.hxx"
24 #include "MEDCouplingCMeshClient.hxx"
25 #include "MEDCouplingCMesh.hxx"
26 #include "MEDCouplingUMesh.hxx"
27
28 #include <vector>
29
30 using namespace ParaMEDMEM;
31
32 MEDCouplingMesh *MEDCouplingMeshClient::New(SALOME_MED::MEDCouplingMeshCorbaInterface_ptr meshPtr)
33 {
34   SALOME_MED::MEDCouplingUMeshCorbaInterface_ptr umeshPtr=SALOME_MED::MEDCouplingUMeshCorbaInterface::_narrow(meshPtr);
35   if(!CORBA::is_nil(umeshPtr))
36     {
37       MEDCouplingMesh *ret=MEDCouplingUMeshClient::New(umeshPtr);
38       CORBA::release(umeshPtr);
39       return ret;
40     }
41   SALOME_MED::MEDCouplingExtrudedMeshCorbaInterface_ptr emeshPtr=SALOME_MED::MEDCouplingExtrudedMeshCorbaInterface::_narrow(meshPtr);
42   if(!CORBA::is_nil(emeshPtr))
43     {
44       MEDCouplingMesh *ret=MEDCouplingExtrudedMeshClient::New(emeshPtr);
45       CORBA::release(emeshPtr);
46       return ret;
47     }
48   SALOME_MED::MEDCouplingCMeshCorbaInterface_ptr cmeshPtr=SALOME_MED::MEDCouplingCMeshCorbaInterface::_narrow(meshPtr);
49   if(!CORBA::is_nil(cmeshPtr))
50     {
51       MEDCouplingMesh *ret=MEDCouplingCMeshClient::New(cmeshPtr);
52       CORBA::release(cmeshPtr);
53       return ret;
54     }
55   return 0;
56 }
57
58 void MEDCouplingMeshClient::fillMeshFromCorbaData(MEDCouplingMesh *meshCpp, SALOME_MED::MEDCouplingMeshCorbaInterface_ptr meshPtr)
59 {
60   meshPtr->Register();
61   //1st call to getTinyInfo to get tiny array of key integers value
62   //to corectly resize local copy of distant instance adressed by 'meshPtr'
63   //1st value of returned array is the type of instance. Thanks to
64   //CORBA and its type-check no use of this value is necessary.
65   SALOME_TYPES::ListOfDouble *tinyD;
66   SALOME_TYPES::ListOfLong *tinyI;
67   SALOME_TYPES::ListOfString *tinyS;
68   meshPtr->getTinyInfo(tinyD,tinyI,tinyS);
69   int tinyLgth=tinyI->length();
70   std::vector<int> tinyV(tinyLgth);
71   for(int i=0;i<tinyLgth;i++)
72     tinyV[i]=(*tinyI)[i];
73   int tinyLgth2=tinyD->length();
74   std::vector<double> tinyV2(tinyLgth2);
75   for(int i=0;i<tinyLgth2;i++)
76     tinyV2[i]=(*tinyD)[i];
77   std::vector<std::string> sts(tinyS->length());
78   for(int i=0;i<(int)sts.size();i++)
79     sts[i]=(*tinyS)[i];
80   delete tinyS;
81   delete tinyI;
82   delete tinyD;
83   DataArrayInt* a1=DataArrayInt::New();
84   DataArrayDouble* a2=DataArrayDouble::New();
85   //thanks to the entry point tinyV get from the 1st CORBA invokation,
86   //resizing a1,a2 and sts.
87   std::vector<std::string> uselessVector;
88   //vector 'uselessVector' is useless thanks to CORBA that , contrary to MPI, does not need to allocate right length of arrays before invokation
89   meshCpp->resizeForUnserialization(tinyV,a1,a2,uselessVector);
90   SALOME_TYPES::ListOfLong *a1Corba;
91   SALOME_TYPES::ListOfDouble *a2Corba;
92   meshPtr->getSerialisationData(a1Corba,a2Corba);
93   int myLgth=a1Corba->length();
94   int *ptToFill=a1->getPointer();
95   for(int i=0;i<myLgth;i++)
96     ptToFill[i]=(*a1Corba)[i];
97   delete a1Corba;
98   myLgth=a2Corba->length();
99   double *ptToFill2=a2->getPointer();
100   for(int i=0;i<myLgth;i++)
101     ptToFill2[i]=(*a2Corba)[i];
102   delete a2Corba;
103   //
104   meshCpp->unserialization(tinyV2,tinyV,a1,a2,sts);
105   a1->decrRef();
106   a2->decrRef();
107   //
108   meshPtr->UnRegister();
109 }