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
19 // Author : Anthony Geay (CEA/DEN)
23 static PyObject* convertMEDFileMesh(ParaMEDMEM::MEDFileMesh* mesh, int owner) throw(INTERP_KERNEL::Exception)
26 if(dynamic_cast<ParaMEDMEM::MEDFileUMesh *>(mesh))
27 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDFileUMesh,owner);
28 if(dynamic_cast<ParaMEDMEM::MEDFileCMesh *>(mesh))
29 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDFileCMesh,owner);
30 if(dynamic_cast<ParaMEDMEM::MEDFileCurveLinearMesh *>(mesh))
31 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDFileCurveLinearMesh,owner);
33 throw INTERP_KERNEL::Exception("Not recognized type of MEDFileMesh on downcast !");
37 static PyObject* convertMEDFileParameter1TS(ParaMEDMEM::MEDFileParameter1TS* p1ts, int owner) throw(INTERP_KERNEL::Exception)
40 if(dynamic_cast<MEDFileParameterDouble1TS *>(p1ts))
41 ret=SWIG_NewPointerObj((void*)p1ts,SWIGTYPE_p_ParaMEDMEM__MEDFileParameterDouble1TS,owner);
42 if(dynamic_cast<MEDFileParameterDouble1TSWTI *>(p1ts))
43 ret=SWIG_NewPointerObj((void*)p1ts,SWIGTYPE_p_ParaMEDMEM__MEDFileParameterDouble1TSWTI,owner);
45 throw INTERP_KERNEL::Exception("Not recognized type of MEDFileParameter1TS on downcast !");
49 static std::vector<std::pair<int,int> > convertTimePairIdsFromPy(PyObject *pyLi) throw(INTERP_KERNEL::Exception)
51 std::vector<std::pair<int,int> > ret;
52 if(PyList_Check(pyLi))
54 int size=PyList_Size(pyLi);
56 for(int i=0;i<size;i++)
58 PyObject *o=PyList_GetItem(pyLi,i);
62 int size2=PyTuple_Size(o);
64 throw INTERP_KERNEL::Exception("tuples in list must be of size 2 (dt,it) !");
65 PyObject *o0=PyTuple_GetItem(o,0);
67 p.first=(int)PyInt_AS_LONG(o0);
69 throw INTERP_KERNEL::Exception("First elem of tuples in list must be integer : dt !");
70 PyObject *o1=PyTuple_GetItem(o,1);
72 p.second=(int)PyInt_AS_LONG(o1);
74 throw INTERP_KERNEL::Exception("Second elem of tuples in list must be integer : dt !");
78 throw INTERP_KERNEL::Exception("list must contain tuples only");
82 throw INTERP_KERNEL::Exception("convertTimePairIdsFromPy : not a list");
86 static void converPyListToVecString(PyObject *pyLi, std::vector<std::string>& v)
88 if(PyList_Check(pyLi))
90 int size=PyList_Size(pyLi);
92 for(int i=0;i<size;i++)
94 PyObject *o=PyList_GetItem(pyLi,i);
95 if(!PyString_Check(o))
96 throw INTERP_KERNEL::Exception("In list passed in argument some elements are NOT strings ! Expected a list containing only strings !");
97 const char *st=PyString_AsString(o);
101 else if(PyTuple_Check(pyLi))
103 int size=PyTuple_Size(pyLi);
105 for(int i=0;i<size;i++)
107 PyObject *o=PyTuple_GetItem(pyLi,i);
108 if(!PyString_Check(o))
109 throw INTERP_KERNEL::Exception("In tuple passed in argument some elements are NOT strings ! Expected a tuple containing only strings !");
110 const char *st=PyString_AsString(o);
111 v[i]=std::string(st);
114 else if(PyString_Check(pyLi))
117 v[0]=std::string((const char *)PyString_AsString(pyLi));
121 throw INTERP_KERNEL::Exception("Unrecognized python argument : expected a list of string or tuple of string or string !");
125 static PyObject *convertFieldDoubleVecToPy(const std::vector<ParaMEDMEM::MEDCouplingFieldDouble *>& li)
128 PyObject *ret=PyList_New(sz);
129 for(int i=0;i<sz;i++)
131 PyObject *o=SWIG_NewPointerObj((void*)li[i],SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,SWIG_POINTER_OWN | 0);
132 PyList_SetItem(ret,i,o);
137 PyObject *convertVecPairVecStToPy(const std::vector< std::pair<std::vector<std::string>, std::string > >& vec)
139 int sz=(int)vec.size();
140 PyObject *ret=PyList_New(sz);
141 for(int i=0;i<sz;i++)
143 PyObject *t=PyTuple_New(2);
144 int sz2=(int)vec[i].first.size();
145 PyObject *ll=PyList_New(sz2);
146 for(int j=0;j<sz2;j++)
147 PyList_SetItem(ll,j,PyString_FromString(vec[i].first[j].c_str()));
148 PyTuple_SetItem(t,0,ll);
149 PyTuple_SetItem(t,1,PyString_FromString(vec[i].second.c_str()));
150 PyList_SetItem(ret,i,t);
155 std::vector< std::pair<std::string, std::string > > convertVecPairStStFromPy(PyObject *pyLi)
157 std::vector< std::pair<std::string, std::string > > ret;
158 const char *msg="convertVecPairStStFromPy : Expecting PyList of Tuples of size 2 ! The first elt in tuple is one string and the 2nd one a string !";
159 if(PyList_Check(pyLi))
161 int size=PyList_Size(pyLi);
163 for(int i=0;i<size;i++)
165 PyObject *o=PyList_GetItem(pyLi,i);
168 std::pair<std::string, std::string> p;
169 int size2=PyTuple_Size(o);
171 throw INTERP_KERNEL::Exception(msg);
172 PyObject *o0=PyTuple_GetItem(o,0);
173 if(PyString_Check(o0))
174 p.second=std::string(PyString_AsString(o0));
176 throw INTERP_KERNEL::Exception(msg);
177 PyObject *o1=PyTuple_GetItem(o,1);
178 if(PyString_Check(o1))
179 p.second=std::string(PyString_AsString(o1));
181 throw INTERP_KERNEL::Exception(msg);
185 throw INTERP_KERNEL::Exception(msg);
189 throw INTERP_KERNEL::Exception(msg);
192 std::vector< std::pair<std::vector<std::string>, std::string > > convertVecPairVecStFromPy(PyObject *pyLi)
194 std::vector< std::pair<std::vector<std::string>, std::string > > ret;
195 const char *msg="convertVecPairVecStFromPy : Expecting PyList of Tuples of size 2 ! The first elt in tuple is a list of strings and the 2nd one a string !";
196 if(PyList_Check(pyLi))
198 int size=PyList_Size(pyLi);
200 for(int i=0;i<size;i++)
202 PyObject *o=PyList_GetItem(pyLi,i);
205 std::pair<std::vector<std::string>, std::string> p;
206 int size2=PyTuple_Size(o);
208 throw INTERP_KERNEL::Exception(msg);
209 PyObject *o0=PyTuple_GetItem(o,0);
212 int size2=PyList_Size(o0);
213 p.first.resize(size2);
214 for(int j=0;j<size2;j++)
216 PyObject *o0j=PyList_GetItem(o0,j);
217 if(PyString_Check(o0j))
219 p.first[j]=std::string(PyString_AsString(o0j));
222 throw INTERP_KERNEL::Exception(msg);
226 throw INTERP_KERNEL::Exception(msg);
227 PyObject *o1=PyTuple_GetItem(o,1);
228 if(PyString_Check(o1))
229 p.second=std::string(PyString_AsString(o1));
231 throw INTERP_KERNEL::Exception(msg);
235 throw INTERP_KERNEL::Exception(msg);
239 throw INTERP_KERNEL::Exception(msg);