1 // Copyright (C) 2007-2012 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.
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
20 #include "MEDCouplingMultiFieldsClient.hxx"
21 #include "MEDCouplingFieldTemplate.hxx"
22 #include "MEDCouplingMeshClient.hxx"
23 #include "DataArrayDoubleClient.hxx"
24 #include "MEDCouplingMemArray.hxx"
25 #include "MEDCouplingMesh.hxx"
29 using namespace ParaMEDMEM;
31 MEDCouplingMultiFields *MEDCouplingMultiFieldsClient::New(SALOME_MED::MEDCouplingMultiFieldsCorbaInterface_ptr fieldPtr)
33 MEDCouplingMultiFields *ret=MEDCouplingMultiFields::New();
35 BuildFullMultiFieldsCorbaFetch(ret,fieldPtr);
36 //notify server that the servant is no more used.
37 fieldPtr->UnRegister();
41 void MEDCouplingMultiFieldsClient::BuildFullMultiFieldsCorbaFetch(MEDCouplingMultiFields *ret,SALOME_MED::MEDCouplingMultiFieldsCorbaInterface_ptr fieldPtr)
44 SALOME_TYPES::ListOfLong *tinyL=0;
45 SALOME_TYPES::ListOfDouble *tinyD=0;
46 SALOME_TYPES::ListOfString *tinyS=0;
48 CORBA::Long nbOfArrays;
49 CORBA::Long nbOfFields;
50 CORBA::Long nbOfMeshes=fieldPtr->getMainTinyInfo(tinyL,tinyD,nbOfArrays,nbOfFields);
51 int tinyLgth=tinyL->length();
52 std::vector<int> mainI(tinyLgth);
53 for(int i=0;i<tinyLgth;i++)
55 delete tinyL; tinyL=0;
56 tinyLgth=tinyD->length();
57 std::vector<double> mainD(tinyLgth);
58 for(int i=0;i<tinyLgth;i++)
60 delete tinyD; tinyD=0;
62 std::vector<MEDCouplingMesh *> cppms(nbOfMeshes);
63 SALOME_MED::MEDCouplingMeshesCorbaInterface *meshes=fieldPtr->getMeshes();
64 for(CORBA::Long i=0;i<nbOfMeshes;i++)
66 cppms[i]=MEDCouplingMeshClient::New((*meshes)[i]);
67 (*meshes)[i]->UnRegister();
71 std::vector<DataArrayDouble *> cppdas(nbOfArrays);
72 for(CORBA::Long i=0;i<nbOfArrays;i++)
74 SALOME_MED::DataArrayDoubleCorbaInterface_ptr daPtr=fieldPtr->getArray(i);
75 cppdas[i]=DataArrayDoubleClient::New(daPtr);
77 CORBA::release(daPtr);
80 std::vector<MEDCouplingFieldTemplate *> fts(nbOfFields);
81 for(CORBA::Long i=0;i<nbOfFields;i++)
83 fieldPtr->getTinyInfo(i,tinyL,tinyD,tinyS);
84 int tinyLgth=tinyL->length();
85 std::vector<int> tinyLV(tinyLgth);
86 for(int j=0;j<tinyLgth;j++)
87 tinyLV[j]=(*tinyL)[j];
88 delete tinyL; tinyL=0;
90 tinyLgth=tinyD->length();
91 std::vector<double> tinyLD(tinyLgth);
92 for(int j=0;j<tinyLgth;j++)
93 tinyLD[j]=(*tinyD)[j];
94 delete tinyD; tinyD=0;
96 tinyLgth=tinyS->length();
97 std::vector<std::string> tinyLS(tinyLgth);
98 for(int j=0;j<tinyLgth;j++)
99 tinyLS[j]=(*tinyS)[j];
100 delete tinyS; tinyS=0;
101 TypeOfField type=(TypeOfField) tinyLV[0];
102 MEDCouplingFieldTemplate *f1=MEDCouplingFieldTemplate::New(type);
104 DataArrayInt *array0;
105 f1->resizeForUnserialization(tinyLV,array0);
108 fieldPtr->getSerialisationData(i,tinyL);
109 tinyLgth=tinyL->length();
110 int *ptr=array0->getPointer();
111 for(int j=0;j<tinyLgth;j++)
113 delete tinyL; tinyL=0;
115 f1->finishUnserialization(tinyLV,tinyLD,tinyLS);
119 ret->finishUnserialization(mainI,mainD,fts,cppms,cppdas);
121 for(std::vector<MEDCouplingFieldTemplate *>::iterator it=fts.begin();it!=fts.end();it++)
123 for(std::vector<MEDCouplingMesh *>::iterator it=cppms.begin();it!=cppms.end();it++)
125 for(std::vector<DataArrayDouble *>::iterator it=cppdas.begin();it!=cppdas.end();it++)