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 std::vector<std::pair<int,int> > convertTimePairIdsFromPy(PyObject *pyLi) throw(INTERP_KERNEL::Exception)
39 std::vector<std::pair<int,int> > ret;
40 if(PyList_Check(pyLi))
42 int size=PyList_Size(pyLi);
44 for(int i=0;i<size;i++)
46 PyObject *o=PyList_GetItem(pyLi,i);
50 int size2=PyTuple_Size(o);
52 throw INTERP_KERNEL::Exception("tuples in list must be of size 2 (dt,it) !");
53 PyObject *o0=PyTuple_GetItem(o,0);
55 p.first=(int)PyInt_AS_LONG(o0);
57 throw INTERP_KERNEL::Exception("First elem of tuples in list must be integer : dt !");
58 PyObject *o1=PyTuple_GetItem(o,1);
60 p.second=(int)PyInt_AS_LONG(o1);
62 throw INTERP_KERNEL::Exception("Second elem of tuples in list must be integer : dt !");
66 throw INTERP_KERNEL::Exception("list must contain tuples only");
70 throw INTERP_KERNEL::Exception("convertTimePairIdsFromPy : not a list");
74 static void converPyListToVecString(PyObject *pyLi, std::vector<std::string>& v)
76 if(PyList_Check(pyLi))
78 int size=PyList_Size(pyLi);
80 for(int i=0;i<size;i++)
82 PyObject *o=PyList_GetItem(pyLi,i);
83 if(!PyString_Check(o))
84 throw INTERP_KERNEL::Exception("In list passed in argument some elements are NOT strings ! Expected a list containing only strings !");
85 const char *st=PyString_AsString(o);
89 else if(PyTuple_Check(pyLi))
91 int size=PyTuple_Size(pyLi);
93 for(int i=0;i<size;i++)
95 PyObject *o=PyTuple_GetItem(pyLi,i);
96 if(!PyString_Check(o))
97 throw INTERP_KERNEL::Exception("In tuple passed in argument some elements are NOT strings ! Expected a tuple containing only strings !");
98 const char *st=PyString_AsString(o);
102 else if(PyString_Check(pyLi))
105 v[0]=std::string((const char *)PyString_AsString(pyLi));
109 throw INTERP_KERNEL::Exception("Unrecognized python argument : expected a list of string or tuple of string or string !");
113 static PyObject *convertFieldDoubleVecToPy(const std::vector<ParaMEDMEM::MEDCouplingFieldDouble *>& li)
116 PyObject *ret=PyList_New(sz);
117 for(int i=0;i<sz;i++)
119 PyObject *o=SWIG_NewPointerObj((void*)li[i],SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,SWIG_POINTER_OWN | 0);
120 PyList_SetItem(ret,i,o);
125 PyObject *convertVecPairVecStToPy(const std::vector< std::pair<std::vector<std::string>, std::string > >& vec)
127 int sz=(int)vec.size();
128 PyObject *ret=PyList_New(sz);
129 for(int i=0;i<sz;i++)
131 PyObject *t=PyTuple_New(2);
132 int sz2=(int)vec[i].first.size();
133 PyObject *ll=PyList_New(sz2);
134 for(int j=0;j<sz2;j++)
135 PyList_SetItem(ll,j,PyString_FromString(vec[i].first[j].c_str()));
136 PyTuple_SetItem(t,0,ll);
137 PyTuple_SetItem(t,1,PyString_FromString(vec[i].second.c_str()));
138 PyList_SetItem(ret,i,t);
143 std::vector< std::pair<std::string, std::string > > convertVecPairStStFromPy(PyObject *pyLi)
145 std::vector< std::pair<std::string, std::string > > ret;
146 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 !";
147 if(PyList_Check(pyLi))
149 int size=PyList_Size(pyLi);
151 for(int i=0;i<size;i++)
153 PyObject *o=PyList_GetItem(pyLi,i);
156 std::pair<std::string, std::string> p;
157 int size2=PyTuple_Size(o);
159 throw INTERP_KERNEL::Exception(msg);
160 PyObject *o0=PyTuple_GetItem(o,0);
161 if(PyString_Check(o0))
162 p.second=std::string(PyString_AsString(o0));
164 throw INTERP_KERNEL::Exception(msg);
165 PyObject *o1=PyTuple_GetItem(o,1);
166 if(PyString_Check(o1))
167 p.second=std::string(PyString_AsString(o1));
169 throw INTERP_KERNEL::Exception(msg);
173 throw INTERP_KERNEL::Exception(msg);
177 throw INTERP_KERNEL::Exception(msg);
180 std::vector< std::pair<std::vector<std::string>, std::string > > convertVecPairVecStFromPy(PyObject *pyLi)
182 std::vector< std::pair<std::vector<std::string>, std::string > > ret;
183 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 !";
184 if(PyList_Check(pyLi))
186 int size=PyList_Size(pyLi);
188 for(int i=0;i<size;i++)
190 PyObject *o=PyList_GetItem(pyLi,i);
193 std::pair<std::vector<std::string>, std::string> p;
194 int size2=PyTuple_Size(o);
196 throw INTERP_KERNEL::Exception(msg);
197 PyObject *o0=PyTuple_GetItem(o,0);
200 int size2=PyList_Size(o0);
201 p.first.resize(size2);
202 for(int j=0;j<size2;j++)
204 PyObject *o0j=PyList_GetItem(o0,j);
205 if(PyString_Check(o0j))
207 p.first[j]=std::string(PyString_AsString(o0j));
210 throw INTERP_KERNEL::Exception(msg);
214 throw INTERP_KERNEL::Exception(msg);
215 PyObject *o1=PyTuple_GetItem(o,1);
216 if(PyString_Check(o1))
217 p.second=std::string(PyString_AsString(o1));
219 throw INTERP_KERNEL::Exception(msg);
223 throw INTERP_KERNEL::Exception(msg);
227 throw INTERP_KERNEL::Exception(msg);