1 // Copyright (C) 2007-2012 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
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"
30 using namespace ParaMEDMEM;
32 MEDCouplingMesh *MEDCouplingMeshClient::New(SALOME_MED::MEDCouplingMeshCorbaInterface_ptr meshPtr)
34 SALOME_MED::MEDCouplingUMeshCorbaInterface_ptr umeshPtr=SALOME_MED::MEDCouplingUMeshCorbaInterface::_narrow(meshPtr);
35 if(!CORBA::is_nil(umeshPtr))
37 MEDCouplingMesh *ret=MEDCouplingUMeshClient::New(umeshPtr);
38 CORBA::release(umeshPtr);
41 SALOME_MED::MEDCouplingExtrudedMeshCorbaInterface_ptr emeshPtr=SALOME_MED::MEDCouplingExtrudedMeshCorbaInterface::_narrow(meshPtr);
42 if(!CORBA::is_nil(emeshPtr))
44 MEDCouplingMesh *ret=MEDCouplingExtrudedMeshClient::New(emeshPtr);
45 CORBA::release(emeshPtr);
48 SALOME_MED::MEDCouplingCMeshCorbaInterface_ptr cmeshPtr=SALOME_MED::MEDCouplingCMeshCorbaInterface::_narrow(meshPtr);
49 if(!CORBA::is_nil(cmeshPtr))
51 MEDCouplingMesh *ret=MEDCouplingCMeshClient::New(cmeshPtr);
52 CORBA::release(cmeshPtr);
58 void MEDCouplingMeshClient::fillMeshFromCorbaData(MEDCouplingMesh *meshCpp, SALOME_MED::MEDCouplingMeshCorbaInterface_ptr meshPtr)
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++)
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++)
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];
98 myLgth=a2Corba->length();
99 double *ptToFill2=a2->getPointer();
100 for(int i=0;i<myLgth;i++)
101 ptToFill2[i]=(*a2Corba)[i];
104 meshCpp->unserialization(tinyV2,tinyV,a1,a2,sts);
108 meshPtr->UnRegister();