1 // Copyright (C) 2007-2013 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)
31 if(dynamic_cast<ParaMEDMEM::MEDFileUMesh *>(mesh))
32 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDFileUMesh,owner);
33 if(dynamic_cast<ParaMEDMEM::MEDFileCMesh *>(mesh))
34 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDFileCMesh,owner);
35 if(dynamic_cast<ParaMEDMEM::MEDFileCurveLinearMesh *>(mesh))
36 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDFileCurveLinearMesh,owner);
38 throw INTERP_KERNEL::Exception("Not recognized type of MEDFileMesh on downcast !");
42 static PyObject *convertMEDFileParameter1TS(ParaMEDMEM::MEDFileParameter1TS* p1ts, int owner) throw(INTERP_KERNEL::Exception)
50 if(dynamic_cast<MEDFileParameterDouble1TS *>(p1ts))
51 ret=SWIG_NewPointerObj((void*)p1ts,SWIGTYPE_p_ParaMEDMEM__MEDFileParameterDouble1TS,owner);
52 if(dynamic_cast<MEDFileParameterDouble1TSWTI *>(p1ts))
53 ret=SWIG_NewPointerObj((void*)p1ts,SWIGTYPE_p_ParaMEDMEM__MEDFileParameterDouble1TSWTI,owner);
55 throw INTERP_KERNEL::Exception("Not recognized type of MEDFileParameter1TS on downcast !");
59 static PyObject *convertMEDFileField1TS(ParaMEDMEM::MEDFileAnyTypeField1TS *p, int owner) throw(INTERP_KERNEL::Exception)
67 if(dynamic_cast<MEDFileField1TS *>(p))
68 ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_ParaMEDMEM__MEDFileField1TS,owner);
69 if(dynamic_cast<MEDFileIntField1TS *>(p))
70 ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_ParaMEDMEM__MEDFileIntField1TS,owner);
72 throw INTERP_KERNEL::Exception("Not recognized type of MEDFileAnyTypeField1TS on downcast !");
76 static PyObject *convertMEDFileFieldMultiTS(ParaMEDMEM::MEDFileAnyTypeFieldMultiTS *p, int owner) throw(INTERP_KERNEL::Exception)
84 if(dynamic_cast<MEDFileFieldMultiTS *>(p))
85 ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_ParaMEDMEM__MEDFileFieldMultiTS,owner);
86 if(dynamic_cast<MEDFileIntFieldMultiTS *>(p))
87 ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_ParaMEDMEM__MEDFileIntFieldMultiTS,owner);
89 throw INTERP_KERNEL::Exception("Not recognized type of MEDFileAnyTypeFieldMultiTS on downcast !");
93 static PyObject *convertMEDMeshMultiLev(ParaMEDMEM::MEDMeshMultiLev *p, int owner) throw(INTERP_KERNEL::Exception)
101 if(dynamic_cast<MEDUMeshMultiLev *>(p))
102 ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_ParaMEDMEM__MEDUMeshMultiLev,owner);
103 if(dynamic_cast<MEDCMeshMultiLev *>(p))
104 ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_ParaMEDMEM__MEDCMeshMultiLev,owner);
105 if(dynamic_cast<MEDCurveLinearMeshMultiLev *>(p))
106 ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_ParaMEDMEM__MEDCurveLinearMeshMultiLev,owner);
108 throw INTERP_KERNEL::Exception("Not recognized type of MEDMeshMultiLev on downcast !");
112 static std::vector<std::pair<int,int> > convertTimePairIdsFromPy(PyObject *pyLi) throw(INTERP_KERNEL::Exception)
114 std::vector<std::pair<int,int> > ret;
115 if(PyList_Check(pyLi))
117 int size=PyList_Size(pyLi);
119 for(int i=0;i<size;i++)
121 PyObject *o=PyList_GetItem(pyLi,i);
124 std::pair<int,int> p;
125 int size2=PyTuple_Size(o);
127 throw INTERP_KERNEL::Exception("tuples in list must be of size 2 (dt,it) !");
128 PyObject *o0=PyTuple_GetItem(o,0);
130 p.first=(int)PyInt_AS_LONG(o0);
132 throw INTERP_KERNEL::Exception("First elem of tuples in list must be integer : dt !");
133 PyObject *o1=PyTuple_GetItem(o,1);
135 p.second=(int)PyInt_AS_LONG(o1);
137 throw INTERP_KERNEL::Exception("Second elem of tuples in list must be integer : dt !");
141 throw INTERP_KERNEL::Exception("list must contain tuples only");
145 throw INTERP_KERNEL::Exception("convertTimePairIdsFromPy : not a list");
149 static void converPyListToVecString(PyObject *pyLi, std::vector<std::string>& v)
151 if(PyList_Check(pyLi))
153 int size=PyList_Size(pyLi);
155 for(int i=0;i<size;i++)
157 PyObject *o=PyList_GetItem(pyLi,i);
158 if(!PyString_Check(o))
159 throw INTERP_KERNEL::Exception("In list passed in argument some elements are NOT strings ! Expected a list containing only strings !");
160 const char *st=PyString_AsString(o);
161 v[i]=std::string(st);
164 else if(PyTuple_Check(pyLi))
166 int size=PyTuple_Size(pyLi);
168 for(int i=0;i<size;i++)
170 PyObject *o=PyTuple_GetItem(pyLi,i);
171 if(!PyString_Check(o))
172 throw INTERP_KERNEL::Exception("In tuple passed in argument some elements are NOT strings ! Expected a tuple containing only strings !");
173 const char *st=PyString_AsString(o);
174 v[i]=std::string(st);
177 else if(PyString_Check(pyLi))
180 v[0]=std::string((const char *)PyString_AsString(pyLi));
184 throw INTERP_KERNEL::Exception("Unrecognized python argument : expected a list of string or tuple of string or string !");
188 static PyObject *convertFieldDoubleVecToPy(const std::vector<ParaMEDMEM::MEDCouplingFieldDouble *>& li)
191 PyObject *ret=PyList_New(sz);
192 for(int i=0;i<sz;i++)
194 PyObject *o=SWIG_NewPointerObj((void*)li[i],SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,SWIG_POINTER_OWN | 0);
195 PyList_SetItem(ret,i,o);
200 PyObject *convertVecPairVecStToPy(const std::vector< std::pair<std::vector<std::string>, std::string > >& vec)
202 int sz=(int)vec.size();
203 PyObject *ret=PyList_New(sz);
204 for(int i=0;i<sz;i++)
206 PyObject *t=PyTuple_New(2);
207 int sz2=(int)vec[i].first.size();
208 PyObject *ll=PyList_New(sz2);
209 for(int j=0;j<sz2;j++)
210 PyList_SetItem(ll,j,PyString_FromString(vec[i].first[j].c_str()));
211 PyTuple_SetItem(t,0,ll);
212 PyTuple_SetItem(t,1,PyString_FromString(vec[i].second.c_str()));
213 PyList_SetItem(ret,i,t);
218 std::vector< std::pair<std::string, std::string > > convertVecPairStStFromPy(PyObject *pyLi)
220 std::vector< std::pair<std::string, std::string > > ret;
221 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 !";
222 if(PyList_Check(pyLi))
224 int size=PyList_Size(pyLi);
226 for(int i=0;i<size;i++)
228 PyObject *o=PyList_GetItem(pyLi,i);
231 std::pair<std::string, std::string> p;
232 int size2=PyTuple_Size(o);
234 throw INTERP_KERNEL::Exception(msg);
235 PyObject *o0=PyTuple_GetItem(o,0);
236 if(PyString_Check(o0))
237 p.first=std::string(PyString_AsString(o0));
239 throw INTERP_KERNEL::Exception(msg);
240 PyObject *o1=PyTuple_GetItem(o,1);
241 if(PyString_Check(o1))
242 p.second=std::string(PyString_AsString(o1));
244 throw INTERP_KERNEL::Exception(msg);
248 throw INTERP_KERNEL::Exception(msg);
252 throw INTERP_KERNEL::Exception(msg);
255 std::vector< std::pair<std::vector<std::string>, std::string > > convertVecPairVecStFromPy(PyObject *pyLi)
257 std::vector< std::pair<std::vector<std::string>, std::string > > ret;
258 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 !";
259 if(PyList_Check(pyLi))
261 int size=PyList_Size(pyLi);
263 for(int i=0;i<size;i++)
265 PyObject *o=PyList_GetItem(pyLi,i);
268 std::pair<std::vector<std::string>, std::string> p;
269 int size2=PyTuple_Size(o);
271 throw INTERP_KERNEL::Exception(msg);
272 PyObject *o0=PyTuple_GetItem(o,0);
275 int size3=PyList_Size(o0);
276 p.first.resize(size3);
277 for(int j=0;j<size3;j++)
279 PyObject *o0j=PyList_GetItem(o0,j);
280 if(PyString_Check(o0j))
282 p.first[j]=std::string(PyString_AsString(o0j));
285 throw INTERP_KERNEL::Exception(msg);
289 throw INTERP_KERNEL::Exception(msg);
290 PyObject *o1=PyTuple_GetItem(o,1);
291 if(PyString_Check(o1))
292 p.second=std::string(PyString_AsString(o1));
294 throw INTERP_KERNEL::Exception(msg);
298 throw INTERP_KERNEL::Exception(msg);
302 throw INTERP_KERNEL::Exception(msg);
306 * Called by MEDFileAnyTypeFieldMultiTS::__getitem__ when \a elt0 is neither a list nor a slice.
307 * In this case a MEDFileAnyTypeField1TS object is returned.
309 int MEDFileAnyTypeFieldMultiTSgetitemSingleTS__(const MEDFileAnyTypeFieldMultiTS *self, PyObject *elt0) throw(INTERP_KERNEL::Exception)
311 if(elt0 && PyInt_Check(elt0))
313 return PyInt_AS_LONG(elt0);
315 else if(elt0 && PyTuple_Check(elt0))
317 if(PyTuple_Size(elt0)==2)
319 PyObject *o0=PyTuple_GetItem(elt0,0);
320 PyObject *o1=PyTuple_GetItem(elt0,1);
321 if(PyInt_Check(o0) && PyInt_Check(o1))
323 int iter=PyInt_AS_LONG(o0);
324 int order=PyInt_AS_LONG(o1);
325 return self->getPosOfTimeStep(iter,order);
328 throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::__getitem__ : invalid input param ! input is a tuple of size 2 but two integers are expected in this tuple to request a time steps !");
331 throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::__getitem__ : invalid input param ! input is a tuple of size != 2 ! two integers are expected in this tuple to request a time steps !");
333 else if(elt0 && PyFloat_Check(elt0))
335 double val=PyFloat_AS_DOUBLE(elt0);
336 return self->getPosGivenTime(val);
339 throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::__getitem__ : invalid input params ! expected fmts[int], fmts[int,int], or fmts[double] to request one time step ! To request a series of time steps invoke fmts[slice], fmts[list of int], fmts[list of double], or fmts[list of int,int] !");
343 * Called by MEDFileAnyTypeFieldMultiTS::__getitem__ when \a obj is neither a list nor a slice.
344 * In this case a MEDFileAnyTypeField1TS object is returned.
346 int MEDFileFieldsgetitemSingleTS__(const MEDFileFields *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
350 return (int)PyInt_AS_LONG(obj);
352 else if(PyString_Check(obj))
354 return self->getPosFromFieldName(PyString_AsString(obj));
357 throw INTERP_KERNEL::Exception("MEDFileFields::__getitem__ : only integer or string with fieldname supported !");