1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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 "MEDCoupling1SGTUMeshClient.hxx"
24 #include "MEDCoupling1DGTUMeshClient.hxx"
25 #include "MEDCouplingExtrudedMeshClient.hxx"
26 #include "MEDCouplingMappedExtrudedMesh.hxx"
27 #include "MEDCouplingCMeshClient.hxx"
28 #include "MEDCouplingCurveLinearMeshClient.hxx"
29 #include "MEDCouplingIMeshClient.hxx"
30 #include "MEDCouplingCMesh.hxx"
31 #include "MEDCouplingCurveLinearMesh.hxx"
32 #include "MEDCouplingIMesh.hxx"
33 #include "MEDCouplingUMesh.hxx"
34 #include "MEDCoupling1GTUMesh.hxx"
38 using namespace MEDCoupling;
40 MEDCouplingMesh *MEDCouplingMeshClient::New(SALOME_MED::MEDCouplingMeshCorbaInterface_ptr meshPtr)
42 SALOME_MED::MEDCouplingUMeshCorbaInterface_ptr umeshPtr=SALOME_MED::MEDCouplingUMeshCorbaInterface::_narrow(meshPtr);
43 if(!CORBA::is_nil(umeshPtr))
45 MEDCouplingMesh *ret=MEDCouplingUMeshClient::New(umeshPtr);
46 CORBA::release(umeshPtr);
49 SALOME_MED::MEDCouplingExtrudedMeshCorbaInterface_ptr emeshPtr=SALOME_MED::MEDCouplingExtrudedMeshCorbaInterface::_narrow(meshPtr);
50 if(!CORBA::is_nil(emeshPtr))
52 MEDCouplingMesh *ret=MEDCouplingExtrudedMeshClient::New(emeshPtr);
53 CORBA::release(emeshPtr);
56 SALOME_MED::MEDCouplingCMeshCorbaInterface_ptr cmeshPtr=SALOME_MED::MEDCouplingCMeshCorbaInterface::_narrow(meshPtr);
57 if(!CORBA::is_nil(cmeshPtr))
59 MEDCouplingMesh *ret=MEDCouplingCMeshClient::New(cmeshPtr);
60 CORBA::release(cmeshPtr);
63 SALOME_MED::MEDCouplingCurveLinearMeshCorbaInterface_ptr clmeshPtr=SALOME_MED::MEDCouplingCurveLinearMeshCorbaInterface::_narrow(meshPtr);
64 if(!CORBA::is_nil(clmeshPtr))
66 MEDCouplingMesh *ret=MEDCouplingCurveLinearMeshClient::New(clmeshPtr);
67 CORBA::release(clmeshPtr);
70 SALOME_MED::MEDCouplingIMeshCorbaInterface_ptr imeshPtr=SALOME_MED::MEDCouplingIMeshCorbaInterface::_narrow(meshPtr);
71 if(!CORBA::is_nil(imeshPtr))
73 MEDCouplingMesh *ret=MEDCouplingIMeshClient::New(imeshPtr);
74 CORBA::release(imeshPtr);
77 SALOME_MED::MEDCoupling1SGTUMeshCorbaInterface_ptr umeshPtr0=SALOME_MED::MEDCoupling1SGTUMeshCorbaInterface::_narrow(meshPtr);
78 if(!CORBA::is_nil(umeshPtr0))
80 MEDCouplingMesh *ret=MEDCoupling1SGTUMeshClient::New(umeshPtr0);
81 CORBA::release(umeshPtr0);
84 SALOME_MED::MEDCoupling1DGTUMeshCorbaInterface_ptr umeshPtr1=SALOME_MED::MEDCoupling1DGTUMeshCorbaInterface::_narrow(meshPtr);
85 if(!CORBA::is_nil(umeshPtr1))
87 MEDCouplingMesh *ret=MEDCoupling1DGTUMeshClient::New(umeshPtr1);
88 CORBA::release(umeshPtr1);
94 void MEDCouplingMeshClient::fillMeshFromCorbaData(MEDCouplingMesh *meshCpp, SALOME_MED::MEDCouplingMeshCorbaInterface_ptr meshPtr)
97 //1st call to getTinyInfo to get tiny array of key integers value
98 //to corectly resize local copy of distant instance adressed by 'meshPtr'
99 //1st value of returned array is the type of instance. Thanks to
100 //CORBA and its type-check no use of this value is necessary.
101 SALOME_TYPES::ListOfDouble *tinyD;
102 SALOME_TYPES::ListOfLong *tinyI;
103 SALOME_TYPES::ListOfString *tinyS;
104 meshPtr->getTinyInfo(tinyD,tinyI,tinyS);
105 int tinyLgth=tinyI->length();
106 std::vector<int> tinyV(tinyLgth);
107 for(int i=0;i<tinyLgth;i++)
108 tinyV[i]=(*tinyI)[i];
109 int tinyLgth2=tinyD->length();
110 std::vector<double> tinyV2(tinyLgth2);
111 for(int i=0;i<tinyLgth2;i++)
112 tinyV2[i]=(*tinyD)[i];
113 std::vector<std::string> sts(tinyS->length());
114 for(int i=0;i<(int)sts.size();i++)
119 DataArrayInt* a1=DataArrayInt::New();
120 DataArrayDouble* a2=DataArrayDouble::New();
121 //thanks to the entry point tinyV get from the 1st CORBA invokation,
122 //resizing a1,a2 and sts.
123 std::vector<std::string> uselessVector;
124 //vector 'uselessVector' is useless thanks to CORBA that , contrary to MPI, does not need to allocate right length of arrays before invokation
125 meshCpp->resizeForUnserialization(tinyV,a1,a2,uselessVector);
126 SALOME_TYPES::ListOfLong *a1Corba;
127 SALOME_TYPES::ListOfDouble *a2Corba;
128 meshPtr->getSerialisationData(a1Corba,a2Corba);
129 int myLgth=a1Corba->length();
130 int *ptToFill=a1->getPointer();
131 for(int i=0;i<myLgth;i++)
132 ptToFill[i]=(*a1Corba)[i];
134 myLgth=a2Corba->length();
135 double *ptToFill2=a2->getPointer();
136 for(int i=0;i<myLgth;i++)
137 ptToFill2[i]=(*a2Corba)[i];
140 meshCpp->unserialization(tinyV2,tinyV,a1,a2,sts);
144 meshPtr->UnRegister();