X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDLoader%2FSwig%2FMEDLoaderTypemaps.i;h=77d53506d87e8558fc013fbc4c400bc03e8cf927;hb=8f309b3cb1e3a62a53364bb08ae7fd947dd21631;hp=96ad8994e0a43f56c06cd909dfcc78f405f97f1a;hpb=659f8c67d0348350e12fde38fe8c4de1ff95dffe;p=tools%2Fmedcoupling.git diff --git a/src/MEDLoader/Swig/MEDLoaderTypemaps.i b/src/MEDLoader/Swig/MEDLoaderTypemaps.i index 96ad8994e..77d53506d 100644 --- a/src/MEDLoader/Swig/MEDLoaderTypemaps.i +++ b/src/MEDLoader/Swig/MEDLoaderTypemaps.i @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2014 CEA/DEN, EDF R&D +// Copyright (C) 2007-2016 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(ParaMEDMEM::MEDFileMesh* mesh, int owner) throw(INTERP_KERNEL::Exception) +static PyObject *convertMEDFileMesh(MEDCoupling::MEDFileMesh* mesh, int owner) throw(INTERP_KERNEL::Exception) { PyObject *ret=0; if(!mesh) @@ -28,18 +28,18 @@ static PyObject *convertMEDFileMesh(ParaMEDMEM::MEDFileMesh* mesh, int owner) th Py_XINCREF(Py_None); return Py_None; } - if(dynamic_cast(mesh)) - ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDFileUMesh,owner); - if(dynamic_cast(mesh)) - ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDFileCMesh,owner); - if(dynamic_cast(mesh)) - ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDFileCurveLinearMesh,owner); + if(dynamic_cast(mesh)) + ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDFileUMesh,owner); + if(dynamic_cast(mesh)) + ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDFileCMesh,owner); + if(dynamic_cast(mesh)) + ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDFileCurveLinearMesh,owner); if(!ret) throw INTERP_KERNEL::Exception("Not recognized type of MEDFileMesh on downcast !"); return ret; } -static PyObject *convertMEDFileParameter1TS(ParaMEDMEM::MEDFileParameter1TS* p1ts, int owner) throw(INTERP_KERNEL::Exception) +static PyObject *convertMEDFileParameter1TS(MEDCoupling::MEDFileParameter1TS* p1ts, int owner) throw(INTERP_KERNEL::Exception) { PyObject *ret=0; if(!p1ts) @@ -48,15 +48,15 @@ static PyObject *convertMEDFileParameter1TS(ParaMEDMEM::MEDFileParameter1TS* p1t return Py_None; } if(dynamic_cast(p1ts)) - ret=SWIG_NewPointerObj((void*)p1ts,SWIGTYPE_p_ParaMEDMEM__MEDFileParameterDouble1TS,owner); + ret=SWIG_NewPointerObj((void*)p1ts,SWIGTYPE_p_MEDCoupling__MEDFileParameterDouble1TS,owner); if(dynamic_cast(p1ts)) - ret=SWIG_NewPointerObj((void*)p1ts,SWIGTYPE_p_ParaMEDMEM__MEDFileParameterDouble1TSWTI,owner); + ret=SWIG_NewPointerObj((void*)p1ts,SWIGTYPE_p_MEDCoupling__MEDFileParameterDouble1TSWTI,owner); if(!ret) throw INTERP_KERNEL::Exception("Not recognized type of MEDFileParameter1TS on downcast !"); return ret; } -static PyObject *convertMEDFileField1TS(ParaMEDMEM::MEDFileAnyTypeField1TS *p, int owner) throw(INTERP_KERNEL::Exception) +static PyObject *convertMEDFileField1TS(MEDCoupling::MEDFileAnyTypeField1TS *p, int owner) throw(INTERP_KERNEL::Exception) { PyObject *ret=0; if(!p) @@ -65,15 +65,17 @@ static PyObject *convertMEDFileField1TS(ParaMEDMEM::MEDFileAnyTypeField1TS *p, i return Py_None; } if(dynamic_cast(p)) - ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_ParaMEDMEM__MEDFileField1TS,owner); + ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_MEDCoupling__MEDFileField1TS,owner); if(dynamic_cast(p)) - ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_ParaMEDMEM__MEDFileIntField1TS,owner); + 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(ParaMEDMEM::MEDFileAnyTypeFieldMultiTS *p, int owner) throw(INTERP_KERNEL::Exception) +static PyObject *convertMEDFileFieldMultiTS(MEDCoupling::MEDFileAnyTypeFieldMultiTS *p, int owner) throw(INTERP_KERNEL::Exception) { PyObject *ret=0; if(!p) @@ -82,15 +84,17 @@ static PyObject *convertMEDFileFieldMultiTS(ParaMEDMEM::MEDFileAnyTypeFieldMulti return Py_None; } if(dynamic_cast(p)) - ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_ParaMEDMEM__MEDFileFieldMultiTS,owner); + ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_MEDCoupling__MEDFileFieldMultiTS,owner); if(dynamic_cast(p)) - ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_ParaMEDMEM__MEDFileIntFieldMultiTS,owner); + 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(ParaMEDMEM::MEDMeshMultiLev *p, int owner) throw(INTERP_KERNEL::Exception) +static PyObject *convertMEDMeshMultiLev(MEDCoupling::MEDMeshMultiLev *p, int owner) throw(INTERP_KERNEL::Exception) { PyObject *ret=0; if(!p) @@ -99,11 +103,11 @@ static PyObject *convertMEDMeshMultiLev(ParaMEDMEM::MEDMeshMultiLev *p, int owne return Py_None; } if(dynamic_cast(p)) - ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_ParaMEDMEM__MEDUMeshMultiLev,owner); + ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_MEDCoupling__MEDUMeshMultiLev,owner); if(dynamic_cast(p)) - ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_ParaMEDMEM__MEDCMeshMultiLev,owner); + ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_MEDCoupling__MEDCMeshMultiLev,owner); if(dynamic_cast(p)) - ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_ParaMEDMEM__MEDCurveLinearMeshMultiLev,owner); + ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_MEDCoupling__MEDCurveLinearMeshMultiLev,owner); if(!ret) throw INTERP_KERNEL::Exception("Not recognized type of MEDMeshMultiLev on downcast !"); return ret; @@ -146,8 +150,23 @@ 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); @@ -155,11 +174,9 @@ static void converPyListToVecString(PyObject *pyLi, std::vector& v) for(int i=0;i& v) for(int i=0;i& li) +static PyObject *convertFieldDoubleVecToPy(const std::vector& li) { int sz=li.size(); PyObject *ret=PyList_New(sz); for(int i=0;i >& vec) +{ + PyObject *ret(PyList_New(vec.size())); + int rk=0; + for(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,SWIG_From_int((*iter).second)); + PyList_SetItem(ret,rk,elt); + } + return ret; +} + PyObject *convertVecPairVecStToPy(const std::vector< std::pair, std::string > >& vec) { int sz=(int)vec.size(); @@ -215,6 +237,20 @@ PyObject *convertVecPairVecStToPy(const std::vector< std::pair >& vec) +{ + int sz=(int)vec.size(); + PyObject *ret=PyList_New(sz); + for(int i=0;i > convertVecPairStStFromPy(PyObject *pyLi) { std::vector< std::pair > ret; @@ -233,15 +269,9 @@ std::vector< std::pair > convertVecPairStStFromPy(PyO 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 @@ -277,21 +307,13 @@ std::vector< std::pair, std::string > > convertVecPairV for(int j=0;jgetNumberOfTS()); } else if(elt0 && PyTuple_Check(elt0)) { @@ -345,14 +367,76 @@ int MEDFileAnyTypeFieldMultiTSgetitemSingleTS__(const MEDFileAnyTypeFieldMultiTS */ 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 (int)PyInt_AS_LONG(obj); + return InterpreteNegativeInt((int)PyInt_AS_LONG(obj),self->getNumberOfFields()); } - else if(PyString_Check(obj)) + 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)) { - return self->getPosFromFieldName(PyString_AsString(obj)); + if(!PyInt_Check(key)) + throw INTERP_KERNEL::Exception("convertToMapIntDataArrayInt : keys in map must be PyInt !"); + long k(PyInt_AS_LONG(key)); + void *argp(0); + int status(SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayInt,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()); + } + DataArrayInt *arg(reinterpret_cast(argp)); + MCAuto arg2(arg); + if(arg) + arg->incrRef(); + cppMap[k]=arg2; } - else - throw INTERP_KERNEL::Exception("MEDFileFields::__getitem__ : only integer or string with fieldname supported !"); +} + +template +PyObject *MEDFileField1TS_getFieldWithProfile(const typename MLFieldTraits::F1TSType *self, TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh) +{ + DataArrayInt *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),SWIGTYPE_p_MEDCoupling__DataArrayInt, 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;i