1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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
19 // Author : Anthony Geay (CEA/DEN)
21 #include "MEDCouplingMultiFieldsClient.hxx"
22 #include "MEDCouplingFieldTemplate.hxx"
23 #include "MEDCouplingMeshClient.hxx"
24 #include "DataArrayDoubleClient.hxx"
25 #include "MEDCouplingMemArray.hxx"
26 #include "MEDCouplingMesh.hxx"
30 using namespace MEDCoupling;
32 MEDCouplingMultiFields *MEDCouplingMultiFieldsClient::New(SALOME_MED::MEDCouplingMultiFieldsCorbaInterface_ptr fieldPtr)
34 MEDCouplingMultiFields *ret=MEDCouplingMultiFields::New();
36 BuildFullMultiFieldsCorbaFetch(ret,fieldPtr);
37 //notify server that the servant is no more used.
38 fieldPtr->UnRegister();
42 void MEDCouplingMultiFieldsClient::BuildFullMultiFieldsCorbaFetch(MEDCouplingMultiFields *ret,SALOME_MED::MEDCouplingMultiFieldsCorbaInterface_ptr fieldPtr)
45 SALOME_TYPES::ListOfLong *tinyL=0;
46 SALOME_TYPES::ListOfDouble *tinyD=0;
47 SALOME_TYPES::ListOfString *tinyS=0;
49 CORBA::Long nbOfArrays;
50 CORBA::Long nbOfFields;
51 CORBA::Long nbOfMeshes=fieldPtr->getMainTinyInfo(tinyL,tinyD,nbOfArrays,nbOfFields);
52 int tinyLgth=tinyL->length();
53 std::vector<int> mainI(tinyLgth);
54 for(int i=0;i<tinyLgth;i++)
56 delete tinyL; tinyL=0;
57 tinyLgth=tinyD->length();
58 std::vector<double> mainD(tinyLgth);
59 for(int i=0;i<tinyLgth;i++)
61 delete tinyD; tinyD=0;
63 std::vector<MEDCouplingMesh *> cppms(nbOfMeshes);
64 SALOME_MED::MEDCouplingMeshesCorbaInterface *meshes=fieldPtr->getMeshes();
65 for(CORBA::Long i=0;i<nbOfMeshes;i++)
67 cppms[i]=MEDCouplingMeshClient::New((*meshes)[i]);
68 (*meshes)[i]->UnRegister();
72 std::vector<DataArrayDouble *> cppdas(nbOfArrays);
73 for(CORBA::Long i=0;i<nbOfArrays;i++)
75 SALOME_MED::DataArrayDoubleCorbaInterface_ptr daPtr=fieldPtr->getArray(i);
76 cppdas[i]=DataArrayDoubleClient::New(daPtr);
78 CORBA::release(daPtr);
81 std::vector<MEDCouplingFieldTemplate *> fts(nbOfFields);
82 for(CORBA::Long i=0;i<nbOfFields;i++)
84 fieldPtr->getTinyInfo(i,tinyL,tinyD,tinyS);
85 int tinyLgth2=tinyL->length();
86 std::vector<int> tinyLV(tinyLgth2);
87 for(int j=0;j<tinyLgth2;j++)
88 tinyLV[j]=(*tinyL)[j];
89 delete tinyL; tinyL=0;
91 tinyLgth2=tinyD->length();
92 std::vector<double> tinyLD(tinyLgth2);
93 for(int j=0;j<tinyLgth2;j++)
94 tinyLD[j]=(*tinyD)[j];
95 delete tinyD; tinyD=0;
97 tinyLgth2=tinyS->length();
98 std::vector<std::string> tinyLS(tinyLgth2);
99 for(int j=0;j<tinyLgth2;j++)
100 tinyLS[j]=(*tinyS)[j];
101 delete tinyS; tinyS=0;
102 TypeOfField type=(TypeOfField) tinyLV[0];
103 MEDCouplingFieldTemplate *f1=MEDCouplingFieldTemplate::New(type);
105 DataArrayInt *array0;
106 f1->resizeForUnserialization(tinyLV,array0);
109 fieldPtr->getSerialisationData(i,tinyL);
110 tinyLgth2=tinyL->length();
111 int *ptr=array0->getPointer();
112 for(int j=0;j<tinyLgth2;j++)
114 delete tinyL; tinyL=0;
116 f1->finishUnserialization(tinyLV,tinyLD,tinyLS);
120 ret->finishUnserialization(mainI,mainD,fts,cppms,cppdas);
122 for(std::vector<MEDCouplingFieldTemplate *>::iterator it=fts.begin();it!=fts.end();it++)
124 for(std::vector<MEDCouplingMesh *>::iterator it=cppms.begin();it!=cppms.end();it++)
126 for(std::vector<DataArrayDouble *>::iterator it=cppdas.begin();it!=cppdas.end();it++)