//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-// Author : Anthony Geay (CEA/DEN)
+// Author : Anthony Geay (EDF R&D)
#include <vector>
static void converPyListToVecString(PyObject *pyLi, std::vector<std::string>& v)
{
+ static const char msg0[]="In list passed in argument some elements are NOT strings ! Expected a list containing only strings !";
+ static const char msg1[]="In tuple passed in argument some elements are NOT strings ! Expected a list containing only strings !";
+ static const char msg2[]="Unrecognized python argument : expected a list of string or tuple of string or string !";
if(PyList_Check(pyLi))
{
int size=PyList_Size(pyLi);
for(int i=0;i<size;i++)
{
PyObject *o=PyList_GetItem(pyLi,i);
- if(!PyString_Check(o))
- throw INTERP_KERNEL::Exception("In list passed in argument some elements are NOT strings ! Expected a list containing only strings !");
- const char *st=PyString_AsString(o);
- v[i]=std::string(st);
+ v[i]=convertPyObjectToStr(o,msg0);
}
+ return ;
}
else if(PyTuple_Check(pyLi))
{
for(int i=0;i<size;i++)
{
PyObject *o=PyTuple_GetItem(pyLi,i);
- if(!PyString_Check(o))
- throw INTERP_KERNEL::Exception("In tuple passed in argument some elements are NOT strings ! Expected a tuple containing only strings !");
- const char *st=PyString_AsString(o);
- v[i]=std::string(st);
+ v[i]=convertPyObjectToStr(o,msg1);
}
+ return ;
}
- else if(PyString_Check(pyLi))
- {
- v.resize(1);
- v[0]=std::string((const char *)PyString_AsString(pyLi));
- }
- else
- {
- throw INTERP_KERNEL::Exception("Unrecognized python argument : expected a list of string or tuple of string or string !");
- }
+ v.resize(1);
+ v[0]=convertPyObjectToStr(pyLi,msg2);
}
static PyObject *convertFieldDoubleVecToPy(const std::vector<MEDCoupling::MEDCouplingFieldDouble *>& li)
if(size2!=2)
throw INTERP_KERNEL::Exception(msg);
PyObject *o0=PyTuple_GetItem(o,0);
- if(PyString_Check(o0))
- p.first=std::string(PyString_AsString(o0));
- else
- throw INTERP_KERNEL::Exception(msg);
+ p.first=convertPyObjectToStr(o0,msg);
PyObject *o1=PyTuple_GetItem(o,1);
- if(PyString_Check(o1))
- p.second=std::string(PyString_AsString(o1));
- else
- throw INTERP_KERNEL::Exception(msg);
+ p.second=convertPyObjectToStr(o1,msg);
ret[i]=p;
}
else
for(int j=0;j<size3;j++)
{
PyObject *o0j=PyList_GetItem(o0,j);
- if(PyString_Check(o0j))
- {
- p.first[j]=std::string(PyString_AsString(o0j));
- }
- else
- throw INTERP_KERNEL::Exception(msg);
+ p.first[j]=convertPyObjectToStr(o0j,msg);
}
}
else
throw INTERP_KERNEL::Exception(msg);
PyObject *o1=PyTuple_GetItem(o,1);
- if(PyString_Check(o1))
- p.second=std::string(PyString_AsString(o1));
- else
- throw INTERP_KERNEL::Exception(msg);
+ p.second=convertPyObjectToStr(o1,msg);
ret[i]=p;
}
else
*/
int MEDFileFieldsgetitemSingleTS__(const MEDFileFields *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
{
+ static const char msg[]="MEDFileFields::__getitem__ : only integer or string with fieldname supported !";
if(PyInt_Check(obj))
{
return InterpreteNegativeInt((int)PyInt_AS_LONG(obj),self->getNumberOfFields());
}
- else if(PyString_Check(obj))
- {
- return self->getPosFromFieldName(PyString_AsString(obj));
- }
- else
- throw INTERP_KERNEL::Exception("MEDFileFields::__getitem__ : only integer or string with fieldname supported !");
+ return self->getPosFromFieldName(convertPyObjectToStr(obj,msg));
}
void convertToMapIntDataArrayInt(PyObject *pyMap, std::map<int, MCAuto<DataArrayInt> >& cppMap)
}
}
+template<class T>
+PyObject *MEDFileField1TS_getFieldWithProfile(const typename MLFieldTraits<T>::F1TSType *self, TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh)
+{
+ DataArrayInt *ret1(NULL);
+ typename MEDCoupling::Traits<T>::ArrayType *ret0(self->getFieldWithProfile(type,meshDimRelToMax,mesh,ret1));
+ PyObject *ret(PyTuple_New(2));
+ PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTITraits<T>::TI, SWIG_POINTER_OWN | 0 ));
+ PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+ return ret;
+}
+
+template<class T>
+PyObject *MEDFileField1TS_getUndergroundDataArrayExt(const typename MLFieldTraits<T>::F1TSType *self)
+{
+ std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > elt1Cpp;
+ typename MEDCoupling::Traits<T>::ArrayType *elt0=self->getUndergroundDataArrayExt(elt1Cpp);
+ if(elt0)
+ elt0->incrRef();
+ PyObject *ret=PyTuple_New(2);
+ PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(elt0),SWIGTITraits<T>::TI, SWIG_POINTER_OWN | 0 ));
+ std::size_t sz=elt1Cpp.size();
+ PyObject *elt=PyList_New(sz);
+ for(std::size_t i=0;i<sz;i++)
+ {
+ PyObject *elt1=PyTuple_New(2);
+ PyObject *elt2=PyTuple_New(2);
+ PyTuple_SetItem(elt2,0,SWIG_From_int((int)elt1Cpp[i].first.first));
+ PyTuple_SetItem(elt2,1,SWIG_From_int(elt1Cpp[i].first.second));
+ PyObject *elt3=PyTuple_New(2);
+ PyTuple_SetItem(elt3,0,SWIG_From_int(elt1Cpp[i].second.first));
+ PyTuple_SetItem(elt3,1,SWIG_From_int(elt1Cpp[i].second.second));
+ PyTuple_SetItem(elt1,0,elt2);
+ PyTuple_SetItem(elt1,1,elt3);
+ PyList_SetItem(elt,i,elt1);
+ }
+ PyTuple_SetItem(ret,1,elt);
+ return ret;
+}