1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
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"
31 using namespace ParaMEDMEM;
33 MEDCouplingMesh *MEDCouplingMeshClient::New(SALOME_MED::MEDCouplingMeshCorbaInterface_ptr meshPtr)
35 SALOME_MED::MEDCouplingUMeshCorbaInterface_ptr umeshPtr=SALOME_MED::MEDCouplingUMeshCorbaInterface::_narrow(meshPtr);
36 if(!CORBA::is_nil(umeshPtr))
38 MEDCouplingMesh *ret=MEDCouplingUMeshClient::New(umeshPtr);
39 CORBA::release(umeshPtr);
42 SALOME_MED::MEDCouplingExtrudedMeshCorbaInterface_ptr emeshPtr=SALOME_MED::MEDCouplingExtrudedMeshCorbaInterface::_narrow(meshPtr);
43 if(!CORBA::is_nil(emeshPtr))
45 MEDCouplingMesh *ret=MEDCouplingExtrudedMeshClient::New(emeshPtr);
46 CORBA::release(emeshPtr);
49 SALOME_MED::MEDCouplingCMeshCorbaInterface_ptr cmeshPtr=SALOME_MED::MEDCouplingCMeshCorbaInterface::_narrow(meshPtr);
50 if(!CORBA::is_nil(cmeshPtr))
52 MEDCouplingMesh *ret=MEDCouplingCMeshClient::New(cmeshPtr);
53 CORBA::release(cmeshPtr);
59 void MEDCouplingMeshClient::fillMeshFromCorbaData(MEDCouplingMesh *meshCpp, SALOME_MED::MEDCouplingMeshCorbaInterface_ptr meshPtr)
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++)
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++)
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];
99 myLgth=a2Corba->length();
100 double *ptToFill2=a2->getPointer();
101 for(int i=0;i<myLgth;i++)
102 ptToFill2[i]=(*a2Corba)[i];
105 meshCpp->unserialization(tinyV2,tinyV,a1,a2,sts);
109 meshPtr->UnRegister();