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