Back to index

salome-med  6.5.0
MEDCouplingFieldDoubleClient.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 "MEDCouplingFieldDoubleClient.hxx"
00021 #include "MEDCouplingMeshClient.hxx"
00022 #include "MEDCouplingMesh.hxx"
00023 
00024 #include <vector>
00025 
00026 using namespace ParaMEDMEM;
00027 
00028 MEDCouplingFieldDouble *MEDCouplingFieldDoubleClient::New(SALOME_MED::MEDCouplingFieldDoubleCorbaInterface_ptr fieldPtr)
00029 {
00030   fieldPtr->Register();
00031   //
00032   SALOME_TYPES::ListOfLong *tinyL;
00033   SALOME_TYPES::ListOfDouble *tinyD;
00034   SALOME_TYPES::ListOfString *tinyS;
00035   //1st CORBA call : getting all tiny info of all types (int, double string).
00036   fieldPtr->getTinyInfo(tinyL,tinyD,tinyS);
00037   int tinyLgth=tinyL->length();
00038   std::vector<int> tinyLV(tinyLgth);
00039   for(int i=0;i<tinyLgth;i++)
00040     tinyLV[i]=(*tinyL)[i];
00041   delete tinyL;
00042   //
00043   tinyLgth=tinyD->length();
00044   std::vector<double> tinyLD(tinyLgth);
00045   for(int i=0;i<tinyLgth;i++)
00046     tinyLD[i]=(*tinyD)[i];
00047   delete tinyD;
00048   //
00049   tinyLgth=tinyS->length();
00050   std::vector<std::string> tinyLS(tinyLgth);
00051   for(int i=0;i<tinyLgth;i++)
00052     tinyLS[i]=(*tinyS)[i];
00053   delete tinyS;
00054   //
00055   TypeOfField type=(TypeOfField) tinyLV[0];
00056   TypeOfTimeDiscretization td=(TypeOfTimeDiscretization) tinyLV[1];
00057   MEDCouplingFieldDouble *ret=MEDCouplingFieldDouble::New(type,td);
00058   //2nd CORBA call to retrieves the mesh.
00059   SALOME_MED::MEDCouplingMeshCorbaInterface_ptr meshPtr=fieldPtr->getMesh();
00060   MEDCouplingMesh *mesh=MEDCouplingMeshClient::New(meshPtr);
00061   meshPtr->UnRegister();
00062   CORBA::release(meshPtr);
00063   ret->setMesh(mesh);
00064   mesh->decrRef();
00065   DataArrayInt *array0;
00066   std::vector<DataArrayDouble *> arrays;
00067   ret->resizeForUnserialization(tinyLV,array0,arrays);
00068   SALOME_TYPES::ListOfLong *bigArr0;
00069   SALOME_TYPES::ListOfDouble2 *bigArr;
00070   //3rd CORBA invokation to get big content
00071   fieldPtr->getSerialisationData(bigArr0,bigArr);
00072   if(bigArr0->length()!=0)
00073     {
00074       int *pt=array0->getPointer();
00075       int lgth=array0->getNbOfElems();
00076       for(int i=0;i<lgth;i++)
00077         pt[i]=(*bigArr0)[i];
00078     }
00079   delete bigArr0;
00080   tinyLgth=arrays.size();
00081   for(int i=0;i<tinyLgth;i++)
00082     {
00083       SALOME_TYPES::ListOfDouble& oneArr=(*bigArr)[i];
00084       DataArrayDouble *curArrToFill=arrays[i];
00085       double *pt=curArrToFill->getPointer();
00086       int lgth=curArrToFill->getNbOfElems();
00087       for(int j=0;j<lgth;j++)
00088         pt[j]=oneArr[j];
00089     }
00090   delete bigArr;
00091   //
00092   //notify server that the servant is no more used.
00093   fieldPtr->UnRegister();
00094   //
00095   ret->finishUnserialization(tinyLV,tinyLD,tinyLS);
00096   //
00097   return ret;
00098 }