X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDLoader%2FSwig%2FMEDLoaderTypemaps.i;h=00bca60add0cf0cd282f4a528c87aa4a30245146;hb=236b5af70ef21aef7eaea0c68d9453b263302fdf;hp=be6d74b2d222a089f13ce6c1dc7fa35ef197c288;hpb=fb6ad3f990cf8c26e23ff4f6ed571d85dc738aac;p=tools%2Fmedcoupling.git diff --git a/src/MEDLoader/Swig/MEDLoaderTypemaps.i b/src/MEDLoader/Swig/MEDLoaderTypemaps.i index be6d74b2d..00bca60ad 100644 --- a/src/MEDLoader/Swig/MEDLoaderTypemaps.i +++ b/src/MEDLoader/Swig/MEDLoaderTypemaps.i @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2015 CEA/DEN, EDF R&D +// Copyright (C) 2007-2020 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -16,11 +16,11 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// Author : Anthony Geay (CEA/DEN) +// Author : Anthony Geay (EDF R&D) #include -static PyObject *convertMEDFileMesh(MEDCoupling::MEDFileMesh* mesh, int owner) throw(INTERP_KERNEL::Exception) +static PyObject *convertMEDFileMesh(MEDCoupling::MEDFileMesh* mesh, int owner) { PyObject *ret=0; if(!mesh) @@ -39,7 +39,7 @@ static PyObject *convertMEDFileMesh(MEDCoupling::MEDFileMesh* mesh, int owner) t return ret; } -static PyObject *convertMEDFileParameter1TS(MEDCoupling::MEDFileParameter1TS* p1ts, int owner) throw(INTERP_KERNEL::Exception) +static PyObject *convertMEDFileParameter1TS(MEDCoupling::MEDFileParameter1TS* p1ts, int owner) { PyObject *ret=0; if(!p1ts) @@ -56,7 +56,7 @@ static PyObject *convertMEDFileParameter1TS(MEDCoupling::MEDFileParameter1TS* p1 return ret; } -static PyObject *convertMEDFileField1TS(MEDCoupling::MEDFileAnyTypeField1TS *p, int owner) throw(INTERP_KERNEL::Exception) +static PyObject *convertMEDFileField1TS(MEDCoupling::MEDFileAnyTypeField1TS *p, int owner) { PyObject *ret=0; if(!p) @@ -68,12 +68,14 @@ static PyObject *convertMEDFileField1TS(MEDCoupling::MEDFileAnyTypeField1TS *p, ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_MEDCoupling__MEDFileField1TS,owner); if(dynamic_cast(p)) ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_MEDCoupling__MEDFileIntField1TS,owner); + if(dynamic_cast(p)) + ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_MEDCoupling__MEDFileFloatField1TS,owner); if(!ret) throw INTERP_KERNEL::Exception("Not recognized type of MEDFileAnyTypeField1TS on downcast !"); return ret; } -static PyObject *convertMEDFileFieldMultiTS(MEDCoupling::MEDFileAnyTypeFieldMultiTS *p, int owner) throw(INTERP_KERNEL::Exception) +static PyObject *convertMEDFileFieldMultiTS(MEDCoupling::MEDFileAnyTypeFieldMultiTS *p, int owner) { PyObject *ret=0; if(!p) @@ -85,12 +87,14 @@ static PyObject *convertMEDFileFieldMultiTS(MEDCoupling::MEDFileAnyTypeFieldMult ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_MEDCoupling__MEDFileFieldMultiTS,owner); if(dynamic_cast(p)) ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_MEDCoupling__MEDFileIntFieldMultiTS,owner); + if(dynamic_cast(p)) + ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_MEDCoupling__MEDFileFloatFieldMultiTS,owner); if(!ret) throw INTERP_KERNEL::Exception("Not recognized type of MEDFileAnyTypeFieldMultiTS on downcast !"); return ret; } -static PyObject *convertMEDMeshMultiLev(MEDCoupling::MEDMeshMultiLev *p, int owner) throw(INTERP_KERNEL::Exception) +static PyObject *convertMEDMeshMultiLev(MEDCoupling::MEDMeshMultiLev *p, int owner) { PyObject *ret=0; if(!p) @@ -109,20 +113,20 @@ static PyObject *convertMEDMeshMultiLev(MEDCoupling::MEDMeshMultiLev *p, int own return ret; } -static std::vector > convertTimePairIdsFromPy(PyObject *pyLi) throw(INTERP_KERNEL::Exception) +static std::vector > convertTimePairIdsFromPy(PyObject *pyLi) { std::vector > ret; if(PyList_Check(pyLi)) { - int size=PyList_Size(pyLi); + std::size_t size=PyList_Size(pyLi); ret.resize(size); - for(int i=0;i p; - int size2=PyTuple_Size(o); + std::size_t size2=PyTuple_Size(o); if(size2!=2) throw INTERP_KERNEL::Exception("tuples in list must be of size 2 (dt,it) !"); PyObject *o0=PyTuple_GetItem(o,0); @@ -146,50 +150,54 @@ static std::vector > convertTimePairIdsFromPy(PyObject *pyLi) return ret; } +static std::vector< std::pair > convertVecPairIntToVecPairTOFCT(const std::vector >& tmp) +{ + std::size_t sz(tmp.size()); + std::vector< std::pair > entitiesCpp(sz); + for(std::size_t i=0;i& 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); + std::size_t size=PyList_Size(pyLi); v.resize(size); - for(int i=0;i& li) { - int sz=li.size(); + std::size_t sz=li.size(); PyObject *ret=PyList_New(sz); - for(int i=0;i +PyObject *convertVecPairIntToPy(const std::vector< std::pair >& vec) +{ + PyObject *ret(PyList_New(vec.size())); + int rk=0; + for(typename std::vector< std::pair >::const_iterator iter=vec.begin();iter!=vec.end();iter++,rk++) + { + PyObject *elt=PyTuple_New(2); + PyTuple_SetItem(elt,0,SWIG_From_int((*iter).first)); + PyTuple_SetItem(elt,1,PyInt_FromLong((*iter).second)); + PyList_SetItem(ret,rk,elt); + } + return ret; +} + PyObject *convertVecPairVecStToPy(const std::vector< std::pair, std::string > >& vec) { - int sz=(int)vec.size(); + std::size_t sz=vec.size(); PyObject *ret=PyList_New(sz); - for(int i=0;i >& vec) +{ + std::size_t sz=vec.size(); + PyObject *ret=PyList_New(sz); + for(std::size_t i=0;i > convertVecPairStStFromPy(PyObject *pyLi) { std::vector< std::pair > ret; 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 !"; if(PyList_Check(pyLi)) { - int size=PyList_Size(pyLi); + std::size_t size=PyList_Size(pyLi); ret.resize(size); - for(int i=0;i p; - int size2=PyTuple_Size(o); + std::size_t size2=PyTuple_Size(o); 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 @@ -258,40 +289,32 @@ std::vector< std::pair, std::string > > convertVecPairV 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 !"; if(PyList_Check(pyLi)) { - int size=PyList_Size(pyLi); + std::size_t size=PyList_Size(pyLi); ret.resize(size); - for(int i=0;i, std::string> p; - int size2=PyTuple_Size(o); + std::size_t size2=PyTuple_Size(o); if(size2!=2) throw INTERP_KERNEL::Exception(msg); PyObject *o0=PyTuple_GetItem(o,0); if(PyList_Check(o0)) { - int size3=PyList_Size(o0); + std::size_t size3=PyList_Size(o0); p.first.resize(size3); - for(int j=0;j, std::string > > convertVecPairV * Called by MEDFileAnyTypeFieldMultiTS::__getitem__ when \a elt0 is neither a list nor a slice. * In this case a MEDFileAnyTypeField1TS object is returned. */ -int MEDFileAnyTypeFieldMultiTSgetitemSingleTS__(const MEDFileAnyTypeFieldMultiTS *self, PyObject *elt0) throw(INTERP_KERNEL::Exception) +int MEDFileAnyTypeFieldMultiTSgetitemSingleTS__(const MEDFileAnyTypeFieldMultiTS *self, PyObject *elt0) { if(elt0 && PyInt_Check(elt0)) {//fmts[3] @@ -320,8 +343,8 @@ int MEDFileAnyTypeFieldMultiTSgetitemSingleTS__(const MEDFileAnyTypeFieldMultiTS PyObject *o1=PyTuple_GetItem(elt0,1); if(PyInt_Check(o0) && PyInt_Check(o1)) {//fmts(1,-1) - int iter=PyInt_AS_LONG(o0); - int order=PyInt_AS_LONG(o1); + int iter=(int)PyInt_AS_LONG(o0); + int order=(int)PyInt_AS_LONG(o1); return self->getPosOfTimeStep(iter,order); } else @@ -343,16 +366,78 @@ int MEDFileAnyTypeFieldMultiTSgetitemSingleTS__(const MEDFileAnyTypeFieldMultiTS * Called by MEDFileAnyTypeFieldMultiTS::__getitem__ when \a obj is neither a list nor a slice. * In this case a MEDFileAnyTypeField1TS object is returned. */ -int MEDFileFieldsgetitemSingleTS__(const MEDFileFields *self, PyObject *obj) throw(INTERP_KERNEL::Exception) +int MEDFileFieldsgetitemSingleTS__(const MEDFileFields *self, PyObject *obj) { + 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()); + return InterpreteNegativeInt(PyInt_AS_LONG(obj),self->getNumberOfFields()); + } + return self->getPosFromFieldName(convertPyObjectToStr(obj,msg)); +} + +void convertToMapIntDataArrayInt(PyObject *pyMap, std::map >& cppMap) +{ + if(!PyDict_Check(pyMap)) + throw INTERP_KERNEL::Exception("convertToMapIntDataArrayInt : input is not a python map !"); + PyObject *key, *value; + Py_ssize_t pos(0); + cppMap.clear(); + while (PyDict_Next(pyMap,&pos,&key,&value)) + { + if(!PyInt_Check(key)) + throw INTERP_KERNEL::Exception("convertToMapIntDataArrayInt : keys in map must be PyInt !"); + int k((int)PyInt_AS_LONG(key)); + void *argp(0); + int status(SWIG_ConvertPtr(value,&argp,SWIGTITraits::TI,0|0)); + if(!SWIG_IsOK(status)) + { + std::ostringstream oss; oss << "convertToMapIntDataArrayInt : values in map must be DataArrayInt !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + DataArrayIdType *arg(reinterpret_cast(argp)); + MCAuto arg2(arg); + if(arg) + arg->incrRef(); + cppMap[k]=arg2; } - else if(PyString_Check(obj)) +} + +template +PyObject *MEDFileField1TS_getFieldWithProfile(const typename MLFieldTraits::F1TSType *self, TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh) +{ + DataArrayIdType *ret1(NULL); + typename MEDCoupling::Traits::ArrayType *ret0(self->getFieldWithProfile(type,meshDimRelToMax,mesh,ret1)); + PyObject *ret(PyTuple_New(2)); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 )); + return ret; +} + +template +PyObject *MEDFileField1TS_getUndergroundDataArrayExt(const typename MLFieldTraits::F1TSType *self) +{ + std::vector< std::pair,std::pair > > elt1Cpp; + typename MEDCoupling::Traits::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::TI, SWIG_POINTER_OWN | 0 )); + std::size_t sz=elt1Cpp.size(); + PyObject *elt=PyList_New(sz); + for(std::size_t i=0;igetPosFromFieldName(PyString_AsString(obj)); + 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,PyInt_FromLong(elt1Cpp[i].second.first)); + PyTuple_SetItem(elt3,1,PyInt_FromLong(elt1Cpp[i].second.second)); + PyTuple_SetItem(elt1,0,elt2); + PyTuple_SetItem(elt1,1,elt3); + PyList_SetItem(elt,i,elt1); } - else - throw INTERP_KERNEL::Exception("MEDFileFields::__getitem__ : only integer or string with fieldname supported !"); + PyTuple_SetItem(ret,1,elt); + return ret; }