Salome HOME
Copyright update 2021
[tools/medcoupling.git] / src / PyWrapping / medcoupling_pycode
1 // Copyright (C) 2017-2021  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // Author : Anthony Geay (EDF R&D)
21
22 %pythoncode %{
23
24 def ExtensionsStr(sz=60):
25     tab=["No","Yes"]
26     isOK=[(elt,tab[int(elt in ActiveExtensions())]) for elt in AllPossibleExtensions()]
27     return "\n".join([a+" "+('{:.>%d}'%(sz-len(a)-1)).format(' %s'%b) for a,b in isOK])
28
29 def ShowExtensions(sz=60):
30     print(ExtensionsStr(sz))
31     pass
32
33 def AdvancedExtensionsStr(sz=60):
34     def SubExtension(allPossibilities,extensionsActivated,pad,tab, sts):
35         for elt2 in allPossibilities:
36             elt3="%s algorithm for %s"%(elt2,elt)
37             sts.append(pad+elt3+" "+('{:.>%d}'%(sz-len(pad)-len(elt3)-1)).format(' %s'%tab[int(elt2 in extensionsActivated)]))
38             pass
39         pass
40     pad="    "
41     tab=["No","Yes"]
42     aext=ActiveExtensions()
43     sts=[]
44     for elt in AllPossibleExtensions():
45         isOK=elt in aext
46         sts.append(elt+" "+('{:.>%d}'%(sz-len(elt)-1)).format(' %s'%tab[isOK]))
47         if not isOK:
48             continue
49         if "Renumb" in elt:
50             SubExtension(AllRenumberMethods(),RenumberAvailableMethods(),pad,tab, sts)
51             pass
52         if "Partit" in elt:
53             SubExtension(MEDPartitioner.AllAlgorithms(),MEDPartitioner.AvailableAlgorithms(),pad,tab, sts)
54             pass
55         pass
56     return "\n".join(sts)
57
58 def ShowAdvancedExtensions(sz=60):
59     print(AdvancedExtensionsStr(sz))
60
61 def MEDCouplingWriterHelper(mci,fileName,medFunc):
62     import os
63     fileWithoutExt,ext=os.path.splitext(fileName)
64     if ext in [".med",".rmed",""]:
65         outFileName=fileName
66         if ext=="":
67             outFileName=fileWithoutExt+".med"
68         if HasMEDFileExt():
69             medFunc(outFileName,mci,True)
70             pass
71         else:
72             raise InterpKernelException("Request for writing \"%s\" MED file, but MED file is not activated in your medcoupling !")
73         pass
74     elif ext[:3]==".vt" and len(ext)==4:
75         mci.writeVTK(fileName)
76     else:
77         raise InterpKernelException("The extension \"%s\" of input file \"%s\" is not recognized !"%(ext,fileName))
78     pass
79
80 if HasMEDFileExt():
81     def MEDCouplingMesh_write(self,fileName):
82         MEDCouplingWriterHelper(self,fileName,WriteMesh)
83
84     def MEDCouplingField_write(self,fileName):
85         MEDCouplingWriterHelper(self,fileName,WriteField)
86
87     def MEDCouplingFieldT_copyTimeInfoFrom(self,mlf1ts):
88         assert(isinstance(mlf1ts,MEDFileAnyTypeField1TS))
89         a,b,c=mlf1ts.getTime()
90         self.setTime(c,a,b)
91         pass
92
93     MEDCouplingMesh.write=MEDCouplingMesh_write
94     del MEDCouplingMesh_write
95     MEDCouplingField.write=MEDCouplingField_write
96     del MEDCouplingField_write
97     MEDCouplingFieldDouble.copyTimeInfoFrom=MEDCouplingFieldT_copyTimeInfoFrom
98     MEDCouplingFieldInt.copyTimeInfoFrom=MEDCouplingFieldT_copyTimeInfoFrom
99     MEDCouplingFieldFloat.copyTimeInfoFrom=MEDCouplingFieldT_copyTimeInfoFrom
100     del MEDCouplingFieldT_copyTimeInfoFrom
101     pass
102 %}