From 19a5d11f2c31745a83bd6993357263641c0babe5 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Fri, 29 Dec 2017 10:04:35 +0100 Subject: [PATCH] Some useful helpers into medcoupling python module --- src/PyWrapping/medcoupling.i | 36 +++++++++++++++++++++++++++++++ src/PyWrapping/medcoupling_pycode | 30 ++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/src/PyWrapping/medcoupling.i b/src/PyWrapping/medcoupling.i index 783471359..e95cb2510 100644 --- a/src/PyWrapping/medcoupling.i +++ b/src/PyWrapping/medcoupling.i @@ -64,6 +64,42 @@ std::vector ret(EXTENSIONS,EXTENSIONS+NB_OF_EXTENSIONS); return ret; } + + bool HasMEDFileExt() + { +#ifdef WITH_MED_FILE + return true; +#else + return false; +#endif + } + + bool HasRenumberExt() + { +#ifdef WITH_RENUMBER + return true; +#else + return false; +#endif + } + + bool HasPartitionerExt() + { +#ifdef WITH_PARTITIONER + return true; +#else + return false; +#endif + } + + bool HasParallelInterpolator() + { +#ifdef WITH_PARALLEL_INTERPOLATOR + return true; +#else + return false; +#endif + } std::vector ActiveExtensions() { diff --git a/src/PyWrapping/medcoupling_pycode b/src/PyWrapping/medcoupling_pycode index 08914fce5..a3dfe1a20 100644 --- a/src/PyWrapping/medcoupling_pycode +++ b/src/PyWrapping/medcoupling_pycode @@ -58,4 +58,34 @@ def AdvancedExtensionsStr(sz=60): def ShowAdvancedExtensions(sz=60): print(AdvancedExtensionsStr(sz)) +def MEDCouplingWriterHelper(mci,fileName,medFunc): + import os + fileWithoutExt,ext=os.path.splitext(fileName) + if ext in [".med",".rmed",""]: + outFileName=fileName + if ext=="": + outFileName=fileWithoutExt+".med" + if HasMEDFileExt(): + medFunc(outFileName,mci,True) + pass + else: + raise InterpKernelException("Request for writing \"%s\" MED file, but MED file is not activated in your medcoupling !") + pass + elif ext[:3]==".vt" and len(ext)==4: + mci.writeVTK(fileName) + else: + raise InterpKernelException("The extension \"%s\" of input file \"%s\" is not recognized !"%(ext,fileName)) + pass + +def MEDCouplingMesh_write(self,fileName): + MEDCouplingWriterHelper(self,fileName,WriteMesh) + +def MEDCouplingField_write(self,fileName): + MEDCouplingWriterHelper(self,fileName,WriteField) + +MEDCouplingMesh.write=MEDCouplingMesh_write +del MEDCouplingMesh_write +MEDCouplingField.write=MEDCouplingField_write +del MEDCouplingField_write + %} -- 2.39.2