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
22 static PyObject* convertMEDFileMesh(ParaMEDMEM::MEDFileMesh* mesh, int owner) throw(INTERP_KERNEL::Exception)
25 if(dynamic_cast<ParaMEDMEM::MEDFileUMesh *>(mesh))
26 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDFileUMesh,owner);
27 if(dynamic_cast<ParaMEDMEM::MEDFileCMesh *>(mesh))
28 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDFileCMesh,owner);
30 throw INTERP_KERNEL::Exception("Not recognized type of MEDFileMesh on downcast !");
34 static std::vector<std::pair<int,int> > convertTimePairIdsFromPy(PyObject *pyLi) throw(INTERP_KERNEL::Exception)
36 std::vector<std::pair<int,int> > ret;
37 if(PyList_Check(pyLi))
39 int size=PyList_Size(pyLi);
41 for(int i=0;i<size;i++)
43 PyObject *o=PyList_GetItem(pyLi,i);
47 int size2=PyTuple_Size(o);
49 throw INTERP_KERNEL::Exception("tuples in list must be of size 2 (dt,it) !");
50 PyObject *o0=PyTuple_GetItem(o,0);
52 p.first=(int)PyInt_AS_LONG(o0);
54 throw INTERP_KERNEL::Exception("First elem of tuples in list must be integer : dt !");
55 PyObject *o1=PyTuple_GetItem(o,1);
57 p.second=(int)PyInt_AS_LONG(o1);
59 throw INTERP_KERNEL::Exception("Second elem of tuples in list must be integer : dt !");
63 throw INTERP_KERNEL::Exception("list must contain tuples only");
67 throw INTERP_KERNEL::Exception("convertTimePairIdsFromPy : not a list");
71 static void converPyListToVecString(PyObject *pyLi, std::vector<std::string>& v)
73 if(PyList_Check(pyLi))
75 int size=PyList_Size(pyLi);
77 for(int i=0;i<size;i++)
79 PyObject *o=PyList_GetItem(pyLi,i);
80 if(!PyString_Check(o))
81 throw INTERP_KERNEL::Exception("In list passed in argument some elements are NOT strings ! Expected a list containing only strings !");
82 const char *st=PyString_AsString(o);
86 else if(PyTuple_Check(pyLi))
88 int size=PyTuple_Size(pyLi);
90 for(int i=0;i<size;i++)
92 PyObject *o=PyTuple_GetItem(pyLi,i);
93 if(!PyString_Check(o))
94 throw INTERP_KERNEL::Exception("In tuple passed in argument some elements are NOT strings ! Expected a tuple containing only strings !");
95 const char *st=PyString_AsString(o);
99 else if(PyString_Check(pyLi))
102 v[0]=std::string((const char *)PyString_AsString(pyLi));
106 throw INTERP_KERNEL::Exception("Unrecognized python argument : expected a list of string or tuple of string or string !");
110 static PyObject *convertFieldDoubleVecToPy(const std::vector<ParaMEDMEM::MEDCouplingFieldDouble *>& li)
113 PyObject *ret=PyList_New(sz);
114 for(int i=0;i<sz;i++)
116 PyObject *o=SWIG_NewPointerObj((void*)li[i],SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,SWIG_POINTER_OWN | 0);
117 PyList_SetItem(ret,i,o);
122 PyObject *convertVecPairVecStToPy(const std::vector< std::pair<std::vector<std::string>, std::string > >& vec)
124 int sz=(int)vec.size();
125 PyObject *ret=PyList_New(sz);
126 for(int i=0;i<sz;i++)
128 PyObject *t=PyTuple_New(2);
129 int sz2=(int)vec[i].first.size();
130 PyObject *ll=PyList_New(sz2);
131 for(int j=0;j<sz2;j++)
132 PyList_SetItem(ll,j,PyString_FromString(vec[i].first[j].c_str()));
133 PyTuple_SetItem(t,0,ll);
134 PyTuple_SetItem(t,1,PyString_FromString(vec[i].second.c_str()));
135 PyList_SetItem(ret,i,t);
140 std::vector< std::pair<std::string, std::string > > convertVecPairStStFromPy(PyObject *pyLi)
142 std::vector< std::pair<std::string, std::string > > ret;
143 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 !";
144 if(PyList_Check(pyLi))
146 int size=PyList_Size(pyLi);
148 for(int i=0;i<size;i++)
150 PyObject *o=PyList_GetItem(pyLi,i);
153 std::pair<std::string, std::string> p;
154 int size2=PyTuple_Size(o);
156 throw INTERP_KERNEL::Exception(msg);
157 PyObject *o0=PyTuple_GetItem(o,0);
158 if(PyString_Check(o0))
159 p.second=std::string(PyString_AsString(o0));
161 throw INTERP_KERNEL::Exception(msg);
162 PyObject *o1=PyTuple_GetItem(o,1);
163 if(PyString_Check(o1))
164 p.second=std::string(PyString_AsString(o1));
166 throw INTERP_KERNEL::Exception(msg);
170 throw INTERP_KERNEL::Exception(msg);
174 throw INTERP_KERNEL::Exception(msg);
177 std::vector< std::pair<std::vector<std::string>, std::string > > convertVecPairVecStFromPy(PyObject *pyLi)
179 std::vector< std::pair<std::vector<std::string>, std::string > > ret;
180 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 !";
181 if(PyList_Check(pyLi))
183 int size=PyList_Size(pyLi);
185 for(int i=0;i<size;i++)
187 PyObject *o=PyList_GetItem(pyLi,i);
190 std::pair<std::vector<std::string>, std::string> p;
191 int size2=PyTuple_Size(o);
193 throw INTERP_KERNEL::Exception(msg);
194 PyObject *o0=PyTuple_GetItem(o,0);
197 int size2=PyList_Size(o0);
198 p.first.resize(size2);
199 for(int j=0;j<size2;j++)
201 PyObject *o0j=PyList_GetItem(o0,j);
202 if(PyString_Check(o0j))
204 p.first[j]=std::string(PyString_AsString(o0j));
207 throw INTERP_KERNEL::Exception(msg);
211 throw INTERP_KERNEL::Exception(msg);
212 PyObject *o1=PyTuple_GetItem(o,1);
213 if(PyString_Check(o1))
214 p.second=std::string(PyString_AsString(o1));
216 throw INTERP_KERNEL::Exception(msg);
220 throw INTERP_KERNEL::Exception(msg);
224 throw INTERP_KERNEL::Exception(msg);