Back to index

salome-med  6.5.0
MEDCouplingMultiFieldsClient.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 "MEDCouplingMultiFieldsClient.hxx"
00021 #include "MEDCouplingFieldTemplate.hxx"
00022 #include "MEDCouplingMeshClient.hxx"
00023 #include "DataArrayDoubleClient.hxx"
00024 #include "MEDCouplingMemArray.hxx"
00025 #include "MEDCouplingMesh.hxx"
00026 
00027 #include <vector>
00028 
00029 using namespace ParaMEDMEM;
00030 
00031 MEDCouplingMultiFields *MEDCouplingMultiFieldsClient::New(SALOME_MED::MEDCouplingMultiFieldsCorbaInterface_ptr fieldPtr)
00032 {
00033   MEDCouplingMultiFields *ret=MEDCouplingMultiFields::New();
00034   fieldPtr->Register();
00035   BuildFullMultiFieldsCorbaFetch(ret,fieldPtr);
00036   //notify server that the servant is no more used.
00037   fieldPtr->UnRegister();
00038   return ret;
00039 }
00040 
00041 void MEDCouplingMultiFieldsClient::BuildFullMultiFieldsCorbaFetch(MEDCouplingMultiFields *ret,SALOME_MED::MEDCouplingMultiFieldsCorbaInterface_ptr fieldPtr)
00042 {
00043   //
00044   SALOME_TYPES::ListOfLong *tinyL=0;
00045   SALOME_TYPES::ListOfDouble *tinyD=0;
00046   SALOME_TYPES::ListOfString *tinyS=0;
00047   //
00048   CORBA::Long nbOfArrays;
00049   CORBA::Long nbOfFields;
00050   CORBA::Long nbOfMeshes=fieldPtr->getMainTinyInfo(tinyL,tinyD,nbOfArrays,nbOfFields);
00051   int tinyLgth=tinyL->length();
00052   std::vector<int> mainI(tinyLgth);
00053   for(int i=0;i<tinyLgth;i++)
00054     mainI[i]=(*tinyL)[i];
00055   delete tinyL; tinyL=0;
00056   tinyLgth=tinyD->length();
00057   std::vector<double> mainD(tinyLgth);
00058   for(int i=0;i<tinyLgth;i++)
00059     mainD[i]=(*tinyD)[i];
00060   delete tinyD; tinyD=0;
00061   //
00062   std::vector<MEDCouplingMesh *> cppms(nbOfMeshes);
00063   SALOME_MED::MEDCouplingMeshesCorbaInterface *meshes=fieldPtr->getMeshes();
00064   for(CORBA::Long i=0;i<nbOfMeshes;i++)
00065     {
00066       cppms[i]=MEDCouplingMeshClient::New((*meshes)[i]);
00067       (*meshes)[i]->UnRegister();
00068     }
00069   delete meshes;
00070   //
00071   std::vector<DataArrayDouble *> cppdas(nbOfArrays);
00072   for(CORBA::Long i=0;i<nbOfArrays;i++)
00073     {
00074       SALOME_MED::DataArrayDoubleCorbaInterface_ptr daPtr=fieldPtr->getArray(i);
00075       cppdas[i]=DataArrayDoubleClient::New(daPtr);
00076       daPtr->UnRegister();
00077       CORBA::release(daPtr);
00078     }
00079   //
00080   std::vector<MEDCouplingFieldTemplate *> fts(nbOfFields);
00081   for(CORBA::Long i=0;i<nbOfFields;i++)
00082     {
00083       fieldPtr->getTinyInfo(i,tinyL,tinyD,tinyS);
00084       int tinyLgth=tinyL->length();
00085       std::vector<int> tinyLV(tinyLgth);
00086       for(int j=0;j<tinyLgth;j++)
00087         tinyLV[j]=(*tinyL)[j];
00088       delete tinyL; tinyL=0;
00089       //
00090       tinyLgth=tinyD->length();
00091       std::vector<double> tinyLD(tinyLgth);
00092       for(int j=0;j<tinyLgth;j++)
00093         tinyLD[j]=(*tinyD)[j];
00094       delete tinyD; tinyD=0;
00095       //
00096       tinyLgth=tinyS->length();
00097       std::vector<std::string> tinyLS(tinyLgth);
00098       for(int j=0;j<tinyLgth;j++)
00099         tinyLS[j]=(*tinyS)[j];
00100       delete tinyS; tinyS=0;
00101       TypeOfField type=(TypeOfField) tinyLV[0];
00102       MEDCouplingFieldTemplate *f1=MEDCouplingFieldTemplate::New(type);
00103       //
00104       DataArrayInt *array0;
00105       f1->resizeForUnserialization(tinyLV,array0);
00106       if(array0)
00107         {
00108           fieldPtr->getSerialisationData(i,tinyL);
00109           tinyLgth=tinyL->length();
00110           int *ptr=array0->getPointer();
00111           for(int j=0;j<tinyLgth;j++)
00112             ptr[j]=(*tinyL)[j];
00113           delete tinyL; tinyL=0;
00114         }
00115       f1->finishUnserialization(tinyLV,tinyLD,tinyLS);
00116       fts[i]=f1;
00117     }
00118   //last step
00119   ret->finishUnserialization(mainI,mainD,fts,cppms,cppdas);
00120   // clean-up
00121   for(std::vector<MEDCouplingFieldTemplate *>::iterator it=fts.begin();it!=fts.end();it++)
00122     (*it)->decrRef();
00123   for(std::vector<MEDCouplingMesh *>::iterator it=cppms.begin();it!=cppms.end();it++)
00124     (*it)->decrRef();
00125   for(std::vector<DataArrayDouble *>::iterator it=cppdas.begin();it!=cppdas.end();it++)
00126     (*it)->decrRef();
00127 }
00128