X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDLoader%2FSwig%2FMEDLoaderTypemaps.i;h=0cf84bc094fdc263e1cbfc8ff88fa3d3c1efdd23;hb=bec7037431602509ee55b85e3e54c10b36984153;hp=cbab3a4d0e60c9bf7466be846d5b7c214fdc5818;hpb=887d0e1efce4f46f68d2596dcd801f02f5c1f99e;p=tools%2Fmedcoupling.git diff --git a/src/MEDLoader/Swig/MEDLoaderTypemaps.i b/src/MEDLoader/Swig/MEDLoaderTypemaps.i index cbab3a4d0..0cf84bc09 100644 --- a/src/MEDLoader/Swig/MEDLoaderTypemaps.i +++ b/src/MEDLoader/Swig/MEDLoaderTypemaps.i @@ -1,9 +1,9 @@ -// Copyright (C) 2007-2012 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 // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -20,20 +20,95 @@ #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(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(!mesh) + { + Py_XINCREF(Py_None); + return Py_None; + } + 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(MEDCoupling::MEDFileParameter1TS* p1ts, int owner) throw(INTERP_KERNEL::Exception) +{ + PyObject *ret=0; + if(!p1ts) + { + Py_XINCREF(Py_None); + return Py_None; + } + if(dynamic_cast(p1ts)) + ret=SWIG_NewPointerObj((void*)p1ts,SWIGTYPE_p_MEDCoupling__MEDFileParameterDouble1TS,owner); + if(dynamic_cast(p1ts)) + 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(MEDCoupling::MEDFileAnyTypeField1TS *p, int owner) throw(INTERP_KERNEL::Exception) +{ + PyObject *ret=0; + if(!p) + { + Py_XINCREF(Py_None); + return Py_None; + } + if(dynamic_cast(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(!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) +{ + PyObject *ret=0; + if(!p) + { + Py_XINCREF(Py_None); + return Py_None; + } + if(dynamic_cast(p)) + 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(!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) +{ + PyObject *ret=0; + if(!p) + { + Py_XINCREF(Py_None); + return Py_None; + } + if(dynamic_cast(p)) + ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_MEDCoupling__MEDUMeshMultiLev,owner); + if(dynamic_cast(p)) + ret=SWIG_NewPointerObj((void*)p,SWIGTYPE_p_MEDCoupling__MEDCMeshMultiLev,owner); + if(dynamic_cast(p)) + 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; +} + static std::vector > convertTimePairIdsFromPy(PyObject *pyLi) throw(INTERP_KERNEL::Exception) { std::vector > ret; @@ -110,18 +185,32 @@ static void converPyListToVecString(PyObject *pyLi, std::vector& v) } } -static PyObject *convertFieldDoubleVecToPy(const std::vector& 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(); @@ -140,6 +229,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; @@ -159,7 +262,7 @@ std::vector< std::pair > convertVecPairStStFromPy(PyO throw INTERP_KERNEL::Exception(msg); PyObject *o0=PyTuple_GetItem(o,0); if(PyString_Check(o0)) - p.second=std::string(PyString_AsString(o0)); + p.first=std::string(PyString_AsString(o0)); else throw INTERP_KERNEL::Exception(msg); PyObject *o1=PyTuple_GetItem(o,1); @@ -197,9 +300,9 @@ std::vector< std::pair, std::string > > convertVecPairV PyObject *o0=PyTuple_GetItem(o,0); if(PyList_Check(o0)) { - int size2=PyList_Size(o0); - p.first.resize(size2); - for(int j=0;j, std::string > > convertVecPairV } throw INTERP_KERNEL::Exception(msg); } + +/*! + * 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) +{ + if(elt0 && PyInt_Check(elt0)) + {//fmts[3] + return InterpreteNegativeInt(PyInt_AS_LONG(elt0),self->getNumberOfTS()); + } + else if(elt0 && PyTuple_Check(elt0)) + { + if(PyTuple_Size(elt0)==2) + { + PyObject *o0=PyTuple_GetItem(elt0,0); + 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); + return self->getPosOfTimeStep(iter,order); + } + else + throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::__getitem__ : invalid input param ! input is a tuple of size 2 but two integers are expected in this tuple to request a time steps !"); + } + else + throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::__getitem__ : invalid input param ! input is a tuple of size != 2 ! two integers are expected in this tuple to request a time steps !"); + } + else if(elt0 && PyFloat_Check(elt0)) + { + double val=PyFloat_AS_DOUBLE(elt0); + return self->getPosGivenTime(val); + } + else + throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::__getitem__ : invalid input params ! expected fmts[int], fmts[int,int], or fmts[double] to request one time step ! To request a series of time steps invoke fmts[slice], fmts[list of int], fmts[list of double], or fmts[list of int,int] !"); +} + +/*! + * 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) +{ + 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 !"); +} + +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 !"); + 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; + } +} +