Back to index

salome-med  6.5.0
MEDCouplingFieldTemplateClient.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 "MEDCouplingFieldTemplateClient.hxx"
00021 #include "MEDCouplingMeshClient.hxx"
00022 #include "MEDCouplingMemArray.hxx"
00023 #include "MEDCouplingMesh.hxx"
00024 
00025 #include <vector>
00026 
00027 using namespace ParaMEDMEM;
00028 
00029 MEDCouplingFieldTemplate *MEDCouplingFieldTemplateClient::New(SALOME_MED::MEDCouplingFieldTemplateCorbaInterface_ptr fieldPtr)
00030 {
00031   fieldPtr->Register();
00032   //
00033   SALOME_TYPES::ListOfLong *tinyL;
00034   SALOME_TYPES::ListOfDouble *tinyD;
00035   SALOME_TYPES::ListOfString *tinyS;
00036   //1st CORBA call : getting all tiny info of all types (int, double string).
00037   fieldPtr->getTinyInfo(tinyL,tinyD,tinyS);
00038   int tinyLgth=tinyL->length();
00039   std::vector<int> tinyLV(tinyLgth);
00040   for(int i=0;i<tinyLgth;i++)
00041     tinyLV[i]=(*tinyL)[i];
00042   delete tinyL;
00043   //
00044   tinyLgth=tinyD->length();
00045   std::vector<double> tinyLD(tinyLgth);
00046   for(int i=0;i<tinyLgth;i++)
00047     tinyLD[i]=(*tinyD)[i];
00048   delete tinyD;
00049   //
00050   tinyLgth=tinyS->length();
00051   std::vector<std::string> tinyLS(tinyLgth);
00052   for(int i=0;i<tinyLgth;i++)
00053     tinyLS[i]=(*tinyS)[i];
00054   delete tinyS;
00055   //
00056   TypeOfField type=(TypeOfField) tinyLV[0];
00057   MEDCouplingFieldTemplate *ret=MEDCouplingFieldTemplate::New(type);
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   ret->resizeForUnserialization(tinyLV,array0);
00067   SALOME_TYPES::ListOfLong *bigArr0;
00068   //3rd CORBA invokation to get big content
00069   fieldPtr->getSerialisationData(bigArr0);
00070   if(bigArr0->length()!=0)
00071     {
00072       int *pt=array0->getPointer();
00073       int lgth=array0->getNbOfElems();
00074       for(int i=0;i<lgth;i++)
00075         pt[i]=(*bigArr0)[i];
00076     }
00077   delete bigArr0;
00078   //
00079   //notify server that the servant is no more used.
00080   fieldPtr->UnRegister();
00081   //
00082   ret->finishUnserialization(tinyLV,tinyLD,tinyLS);
00083   //
00084   return ret;
00085 }