From: Anthony Geay Date: Mon, 18 Sep 2017 14:52:54 +0000 (+0200) Subject: Make ReadField multi type field X-Git-Tag: V8_4_0a2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=fc22b4cd63404700f73e09be7507a11b838e55bc;p=tools%2Fmedcoupling.git Make ReadField multi type field --- diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index ddf21af6d..445dc331e 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -146,6 +146,18 @@ using namespace INTERP_KERNEL; } //$$$$$$$$$$$$$$$$$$ +//////////////////// +%typemap(out) MEDCoupling::MEDCouplingField* +{ + $result=convertField($1,$owner); +} + +%typemap(out) MEDCouplingField* +{ + $result=convertField($1,$owner); +} +//$$$$$$$$$$$$$$$$$$ + //////////////////// %typemap(out) MEDCoupling::MEDCouplingMultiFields* { diff --git a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i index 72450ab35..b7a4ade9d 100644 --- a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i +++ b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i @@ -83,6 +83,25 @@ static PyObject *convertFieldDiscretization(MEDCoupling::MEDCouplingFieldDiscret return ret; } +static PyObject *convertField(MEDCoupling::MEDCouplingField *f, int owner) +{ + PyObject *ret(NULL); + if(!f) + { + Py_XINCREF(Py_None); + return Py_None; + } + if(dynamic_cast(f)) + ret=SWIG_NewPointerObj(reinterpret_cast(f),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble,owner); + if(dynamic_cast(f)) + ret=SWIG_NewPointerObj(reinterpret_cast(f),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldInt,owner); + if(dynamic_cast(f)) + ret=SWIG_NewPointerObj(reinterpret_cast(f),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldFloat,owner); + if(!ret) + throw INTERP_KERNEL::Exception("Not recognized type of field on downcast !"); + return ret; +} + static PyObject* convertMultiFields(MEDCoupling::MEDCouplingMultiFields *mfs, int owner) { PyObject *ret=0; diff --git a/src/MEDLoader/MEDLoader.cxx b/src/MEDLoader/MEDLoader.cxx index e30d89671..79bc80682 100644 --- a/src/MEDLoader/MEDLoader.cxx +++ b/src/MEDLoader/MEDLoader.cxx @@ -29,6 +29,8 @@ #include "MEDCouplingUMesh.hxx" #include "MEDCouplingMemArray.hxx" #include "MEDCouplingFieldDouble.hxx" +#include "MEDCouplingFieldFloat.hxx" +#include "MEDCouplingFieldInt.hxx" #include "MEDCouplingGaussLocalization.hxx" #include "MCAuto.hxx" @@ -1155,7 +1157,7 @@ MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromGroups(const std::strin return mmuPtr->getGroups(meshDimRelToMax,grps,true); } -MCAuto MEDCoupling::ReadField(const std::string& fileName) +MCAuto MEDCoupling::ReadField(const std::string& fileName) { std::vector fieldNames(GetAllFieldNames(fileName)); std::size_t sz(fieldNames.size()); @@ -1178,7 +1180,7 @@ MCAuto MEDCoupling::ReadField(const std::st return ReadField(fileName,fieldNames[0]); } -MCAuto MEDCoupling::ReadField(const std::string& fileName, const std::string& fieldName) +MCAuto MEDCoupling::ReadField(const std::string& fileName, const std::string& fieldName) { std::vector< std::pair< std::pair, double> > iterations(GetAllFieldIterations(fileName,fieldName)); std::size_t sz(iterations.size()); @@ -1201,12 +1203,38 @@ MCAuto MEDCoupling::ReadField(const std::st return ReadField(fileName,fieldName,iterations[0].first.first,iterations[0].first.second); } -MCAuto MEDCoupling::ReadField(const std::string& fileName, const std::string& fieldName, int iteration, int order) +MCAuto MEDCoupling::ReadField(const std::string& fileName, const std::string& fieldName, int iteration, int order) { - MCAuto f(MEDFileField1TS::New(fileName,fieldName,iteration,order)); + MCAuto f(MEDFileAnyTypeField1TS::New(fileName,fieldName,iteration,order)); MCAuto mesh(MEDFileMesh::New(fileName,f->getMeshName())); - MCAuto ret(f->field(mesh)); - return ret; + { + MCAuto f1(MEDCoupling::DynamicCast(f)); + if(f1.isNotNull()) + { + MCAuto ret(f1->field(mesh)); + return MEDCoupling::DynamicCast(ret); + } + } + { + MCAuto f1(MEDCoupling::DynamicCast(f)); + if(f1.isNotNull()) + { + MCAuto ret(f1->field(mesh)); + return MEDCoupling::DynamicCast(ret); + } + } + { + MCAuto f1(MEDCoupling::DynamicCast(f)); + if(f1.isNotNull()) + { + MCAuto ret(f1->field(mesh)); + return MEDCoupling::DynamicCast(ret); + } + } + throw INTERP_KERNEL::Exception("MEDCoupling::ReadField : only FLOAT32, FLOAT64 and INT32 supported for the moment !"); + //MCAuto mesh(MEDFileMesh::New(fileName,f->getMeshName())); + //MCAuto ret(f->field(mesh)); + //return ret; } MCAuto MEDCoupling::ReadField(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order) diff --git a/src/MEDLoader/MEDLoader.hxx b/src/MEDLoader/MEDLoader.hxx index df6f61ca5..4fdba13b8 100644 --- a/src/MEDLoader/MEDLoader.hxx +++ b/src/MEDLoader/MEDLoader.hxx @@ -35,6 +35,7 @@ namespace MEDCoupling class DataArrayInt; class MEDCouplingMesh; class MEDCouplingUMesh; + class MEDCouplingField; class MEDCouplingFieldDouble; class MEDFileWritable; @@ -72,9 +73,9 @@ namespace MEDCoupling MEDLOADER_EXPORT MEDCoupling::MEDCouplingUMesh *ReadUMeshFromFile(const std::string& fileName, const std::string& meshName, int meshDimRelToMax=0); MEDLOADER_EXPORT MEDCoupling::MEDCouplingUMesh *ReadUMeshFromFile(const std::string& fileName, int meshDimRelToMax=0); MEDLOADER_EXPORT int ReadUMeshDimFromFile(const std::string& fileName, const std::string& meshName); - MEDLOADER_EXPORT MCAuto ReadField(const std::string& fileName); - MEDLOADER_EXPORT MCAuto ReadField(const std::string& fileName, const std::string& fieldName); - MEDLOADER_EXPORT MCAuto ReadField(const std::string& fileName, const std::string& fieldName, int iteration, int order); + MEDLOADER_EXPORT MCAuto ReadField(const std::string& fileName); + MEDLOADER_EXPORT MCAuto ReadField(const std::string& fileName, const std::string& fieldName); + MEDLOADER_EXPORT MCAuto ReadField(const std::string& fileName, const std::string& fieldName, int iteration, int order); MEDLOADER_EXPORT MCAuto ReadField(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order); MEDLOADER_EXPORT std::vector ReadFieldsOnSameMesh(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, const std::vector >& its); diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 7219f54e1..0a1262950 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -406,21 +406,21 @@ namespace MEDCoupling return ret; } - MEDCoupling::MEDCouplingFieldDouble *ReadFieldSwig(const std::string& fileName) throw(INTERP_KERNEL::Exception) + MEDCoupling::MEDCouplingField *ReadFieldSwig(const std::string& fileName) throw(INTERP_KERNEL::Exception) { - MCAuto ret(MEDCoupling::ReadField(fileName)); + MCAuto ret(MEDCoupling::ReadField(fileName)); return ret.retn(); } - MEDCoupling::MEDCouplingFieldDouble *ReadFieldSwig(const std::string& fileName, const std::string& fieldName) throw(INTERP_KERNEL::Exception) + MEDCoupling::MEDCouplingField *ReadFieldSwig(const std::string& fileName, const std::string& fieldName) throw(INTERP_KERNEL::Exception) { - MCAuto ret(MEDCoupling::ReadField(fileName,fieldName)); + MCAuto ret(MEDCoupling::ReadField(fileName,fieldName)); return ret.retn(); } - MEDCoupling::MEDCouplingFieldDouble *ReadFieldSwig(const std::string& fileName, const std::string& fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception) + MEDCoupling::MEDCouplingField *ReadFieldSwig(const std::string& fileName, const std::string& fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception) { - MCAuto ret(MEDCoupling::ReadField(fileName,fieldName,iteration,order)); + MCAuto ret(MEDCoupling::ReadField(fileName,fieldName,iteration,order)); return ret.retn(); }