Salome HOME
8a9e148dd186322d0f42241c09d4560f430bdd21
[modules/smesh.git] / src / SMESH_SWIG / SMESH_test5.py
1 #  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3
4 #  This library is free software; you can redistribute it and/or 
5 #  modify it under the terms of the GNU Lesser General Public 
6 #  License as published by the Free Software Foundation; either 
7 #  version 2.1 of the License. 
8
9 #  This library is distributed in the hope that it will be useful, 
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 #  Lesser General Public License for more details. 
13
14 #  You should have received a copy of the GNU Lesser General Public 
15 #  License along with this library; if not, write to the Free Software 
16 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
17
18 #  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
19 #
20 #
21 #
22 #  File   : SMESH_test1.py
23 #  Module : SMESH
24
25 import salome
26 import SMESH
27 import SALOMEDS
28 import CORBA
29 import os
30 import os.path
31
32 def SetSObjName(theSObj,theName) :
33     ok, anAttr = theSObj.FindAttribute("AttributeName")
34     if ok:
35         aName = anAttr._narrow(SALOMEDS.AttributeName)
36         #print aName.__dict__
37         aName.SetValue(theName)
38
39 def ConvertMED2UNV(thePath,theFile) :
40     anInitFileName = thePath + theFile
41     aMeshes,aResult = smesh.CreateMeshesFromMED(anInitFileName)
42     print aResult, aMeshes
43
44     for iMesh in range(len(aMeshes)) :
45         aMesh = aMeshes[iMesh]
46         anSObj = salome.ObjectToSObject(aMesh)
47         print anSObj.GetName(),
48         aFileName = anInitFileName
49         aFileName = os.path.basename(aFileName)
50         SetSObjName(anSObj,aFileName)
51         print anSObj.GetName()
52
53         aOutPath = '/tmp/'
54         aFileName = aOutPath + theFile + "." + str(iMesh) + ".unv"
55         aMesh.ExportUNV(aFileName)
56         aMesh = smesh.CreateMeshesFromUNV(aFileName)
57         anSObj = salome.ObjectToSObject(aMesh)
58         print anSObj.GetName(),
59         os.remove(aFileName)
60         aFileName = os.path.basename(aFileName)
61         SetSObjName(anSObj,aFileName)
62         print anSObj.GetName()
63
64 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
65 smesh.SetCurrentStudy(salome.myStudy)
66
67 aPath = os.getenv('KERNEL_ROOT_DIR') + '/examples/'
68 aListDir = os.listdir(aPath)
69 print aListDir
70
71 for iFile in range(len(aListDir)) :
72     aFileName = aListDir[iFile]
73     aName,anExt = os.path.splitext(aFileName)
74     if anExt == ".med" :
75         aFileName = os.path.basename(aFileName)
76         print aFileName
77         ConvertMED2UNV(aPath,aFileName)
78         #break
79
80 salome.sg.updateObjBrowser(1)