From 40bc892d041f0af3912135f94df5f55f61f782b8 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Wed, 14 Sep 2022 18:07:30 +0200 Subject: [PATCH] Add MEDFileMesh.ConvertToMEDFileGeoType method --- src/MEDLoader/MEDFileMesh.cxx | 10 ++++++++++ src/MEDLoader/MEDFileMesh.hxx | 1 + src/MEDLoader/Swig/MEDLoaderCommon.i | 5 +++++ src/MEDLoader/Swig/MEDLoaderTest3.py | 1 + 4 files changed, 17 insertions(+) diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index dc1649252..f712e2abd 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -7824,6 +7824,16 @@ INTERP_KERNEL::NormalizedCellType MEDFileMesh::ConvertFromMEDFileGeoType(med_geo return typmai2[std::distance(typmai,pos)]; } +med_geometry_type MEDFileMesh::ConvertToMEDFileGeoType(INTERP_KERNEL::NormalizedCellType geoType) +{ + INTERP_KERNEL::NormalizedCellType *pos(std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,geoType)); + if(pos==typmai2+MED_N_CELL_FIXED_GEO) + { + THROW_IK_EXCEPTION("MEDFileMesh::ConvertToMEDFileGeoType : no entry for " << geoType); + } + return typmai[std::distance(typmai2,pos)]; +} + TypeOfField MEDFileMesh::ConvertFromMEDFileEntity(med_entity_type etype) { switch(etype) diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index d53344d1e..9eaa94f93 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -203,6 +203,7 @@ namespace MEDCoupling void killEquivalences() { _equiv=(MEDFileEquivalences *)0; } void initializeEquivalences() { _equiv=MEDFileEquivalences::New(this); } MEDLOADER_EXPORT static INTERP_KERNEL::NormalizedCellType ConvertFromMEDFileGeoType(med_geometry_type geoType); + MEDLOADER_EXPORT static med_geometry_type ConvertToMEDFileGeoType(INTERP_KERNEL::NormalizedCellType geoType); static TypeOfField ConvertFromMEDFileEntity(med_entity_type etype); protected: MEDFileMesh(); diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index a0368584d..b33167ffc 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -1242,6 +1242,11 @@ namespace MEDCoupling return MEDFileMesh::ConvertFromMEDFileGeoType(geoType2); } + static int ConvertToMEDFileGeoType(INTERP_KERNEL::NormalizedCellType geoType) + { + return (int) MEDFileMesh::ConvertToMEDFileGeoType(geoType); + } + PyObject *getTime() { int tmp1,tmp2; diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index 4d3c49a76..a9b2dff97 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -7009,6 +7009,7 @@ class MEDLoaderTest3(unittest.TestCase): def testMeshConvertFromMEDFileGeoType(self): self.assertEqual(MEDFileMesh.ConvertFromMEDFileGeoType(320),NORM_HEXA20) + self.assertEqual(MEDFileMesh.ConvertToMEDFileGeoType(NORM_HEXA20),320) @WriteInTmpDir def testFieldInt64_0(self): -- 2.39.2