Back to index

salome-med  6.5.0
MEDCouplingMeshClient.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "MEDCouplingMeshClient.hxx"
00021 #include "MEDCouplingUMeshClient.hxx"
00022 #include "MEDCouplingExtrudedMeshClient.hxx"
00023 #include "MEDCouplingExtrudedMesh.hxx"
00024 #include "MEDCouplingCMeshClient.hxx"
00025 #include "MEDCouplingCMesh.hxx"
00026 #include "MEDCouplingUMesh.hxx"
00027 
00028 #include <vector>
00029 
00030 using namespace ParaMEDMEM;
00031 
00032 MEDCouplingMesh *MEDCouplingMeshClient::New(SALOME_MED::MEDCouplingMeshCorbaInterface_ptr meshPtr)
00033 {
00034   SALOME_MED::MEDCouplingUMeshCorbaInterface_ptr umeshPtr=SALOME_MED::MEDCouplingUMeshCorbaInterface::_narrow(meshPtr);
00035   if(!CORBA::is_nil(umeshPtr))
00036     {
00037       MEDCouplingMesh *ret=MEDCouplingUMeshClient::New(umeshPtr);
00038       CORBA::release(umeshPtr);
00039       return ret;
00040     }
00041   SALOME_MED::MEDCouplingExtrudedMeshCorbaInterface_ptr emeshPtr=SALOME_MED::MEDCouplingExtrudedMeshCorbaInterface::_narrow(meshPtr);
00042   if(!CORBA::is_nil(emeshPtr))
00043     {
00044       MEDCouplingMesh *ret=MEDCouplingExtrudedMeshClient::New(emeshPtr);
00045       CORBA::release(emeshPtr);
00046       return ret;
00047     }
00048   SALOME_MED::MEDCouplingCMeshCorbaInterface_ptr cmeshPtr=SALOME_MED::MEDCouplingCMeshCorbaInterface::_narrow(meshPtr);
00049   if(!CORBA::is_nil(cmeshPtr))
00050     {
00051       MEDCouplingMesh *ret=MEDCouplingCMeshClient::New(cmeshPtr);
00052       CORBA::release(cmeshPtr);
00053       return ret;
00054     }
00055   return 0;
00056 }
00057 
00058 void MEDCouplingMeshClient::fillMeshFromCorbaData(MEDCouplingMesh *meshCpp, SALOME_MED::MEDCouplingMeshCorbaInterface_ptr meshPtr)
00059 {
00060   meshPtr->Register();
00061   //1st call to getTinyInfo to get tiny array of key integers value
00062   //to corectly resize local copy of distant instance adressed by 'meshPtr'
00063   //1st value of returned array is the type of instance. Thanks to
00064   //CORBA and its type-check no use of this value is necessary.
00065   SALOME_TYPES::ListOfDouble *tinyD;
00066   SALOME_TYPES::ListOfLong *tinyI;
00067   SALOME_TYPES::ListOfString *tinyS;
00068   meshPtr->getTinyInfo(tinyD,tinyI,tinyS);
00069   int tinyLgth=tinyI->length();
00070   std::vector<int> tinyV(tinyLgth);
00071   for(int i=0;i<tinyLgth;i++)
00072     tinyV[i]=(*tinyI)[i];
00073   int tinyLgth2=tinyD->length();
00074   std::vector<double> tinyV2(tinyLgth2);
00075   for(int i=0;i<tinyLgth2;i++)
00076     tinyV2[i]=(*tinyD)[i];
00077   std::vector<std::string> sts(tinyS->length());
00078   for(int i=0;i<(int)sts.size();i++)
00079     sts[i]=(*tinyS)[i];
00080   delete tinyS;
00081   delete tinyI;
00082   delete tinyD;
00083   DataArrayInt* a1=DataArrayInt::New();
00084   DataArrayDouble* a2=DataArrayDouble::New();
00085   //thanks to the entry point tinyV get from the 1st CORBA invokation,
00086   //resizing a1,a2 and sts.
00087   std::vector<std::string> uselessVector;
00088   //vector 'uselessVector' is useless thanks to CORBA that , contrary to MPI, does not need to allocate right length of arrays before invokation
00089   meshCpp->resizeForUnserialization(tinyV,a1,a2,uselessVector);
00090   SALOME_TYPES::ListOfLong *a1Corba;
00091   SALOME_TYPES::ListOfDouble *a2Corba;
00092   meshPtr->getSerialisationData(a1Corba,a2Corba);
00093   int myLgth=a1Corba->length();
00094   int *ptToFill=a1->getPointer();
00095   for(int i=0;i<myLgth;i++)
00096     ptToFill[i]=(*a1Corba)[i];
00097   delete a1Corba;
00098   myLgth=a2Corba->length();
00099   double *ptToFill2=a2->getPointer();
00100   for(int i=0;i<myLgth;i++)
00101     ptToFill2[i]=(*a2Corba)[i];
00102   delete a2Corba;
00103   //
00104   meshCpp->unserialization(tinyV2,tinyV,a1,a2,sts);
00105   a1->decrRef();
00106   a2->decrRef();
00107   //
00108   meshPtr->UnRegister();
00109 }