]> SALOME platform Git repositories - modules/visu.git/blob - src/VISU_SWIG/visu_med.py
Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/visu.git] / src / VISU_SWIG / visu_med.py
1 #  VISU VISU_SWIG : binding of C++ implementation and Python
2 #
3 #  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5
6 #  This library is free software; you can redistribute it and/or 
7 #  modify it under the terms of the GNU Lesser General Public 
8 #  License as published by the Free Software Foundation; either 
9 #  version 2.1 of the License. 
10
11 #  This library is distributed in the hope that it will be useful, 
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 #  Lesser General Public License for more details. 
15
16 #  You should have received a copy of the GNU Lesser General Public 
17 #  License along with this library; if not, write to the Free Software 
18 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19
20 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22 #  File   : visu_med.py
23 #  Module : VISU
24
25 import os
26 import salome
27 import SALOMEDS
28 import SALOME_MED
29 import VISU
30
31 if salome.hasDesktop():
32     from libSALOME_Swig import *
33     sg = SALOMEGUI_Swig()
34
35 def getMedObjectFromStudy():
36     mySO = salome.myStudy.FindObject("Objet MED")
37     anAttr = mySO.FindAttribute("AttributeIOR")[1]
38     obj = salome.orb.string_to_object(anAttr.Value())
39     myObj = obj._narrow(SALOME_MED.MED)
40     return myObj
41
42 def getFieldObjectFromStudy(number,subnumber):
43     mySO = salome.myStudy.FindObject("MEDFIELD")
44     mysub = mySO.FindSubObject(number)[1]
45     if mysub:
46         mysubsub = mysub.FindSubObject(subnumber)[1]
47         if mysubsub:
48             Builder = salome.myStudy.NewBuilder()
49             anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
50             obj = salome.orb.string_to_object(anAttr.Value())
51             myObj = obj._narrow(SALOME_MED.FIELDINT)
52             if (myObj == None):
53                 myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
54             return myObj
55     else:
56         print "ERROR: No Field Object stored in this Study"
57         return None
58
59 med_comp = salome.lcc.FindOrLoadComponent("FactoryServer", "MED")
60
61 medDir = os.getenv('DATA_DIR') + '/MedFiles/'
62
63 def importMedFrom(medDir,medFile):
64     medFile = medDir + medFile
65     med_comp.readStructFileWithFieldType(medFile,salome.myStudyName)
66     if salome.hasDesktop():
67         sg.updateObjBrowser(1)
68   
69 def importMed(medFile):
70     importMedFrom(medDir,medFile)
71
72 #med_obj = getMedObjectFromStudy()
73 myVisu = salome.lcc.FindOrLoadComponent("FactoryServer", "VISU")
74 print "Use importMed(medFile) or importMedFrom(medDir,medFile) functions !"
75
76 #myField = getFieldObjectFromStudy(2,1)
77 #myResult = myVisu.ImportMed(myField)
78 #aMesh = myVisu.CreateMesh(myResult);
79 #aScalarMap = myVisu.CreateScalarMap(myResult,myField.getName(),0)
80 #if(myField.getNumberOfComponents() > 1) :
81 #  aScalarMap = myVisu.CreateVectors(myResult,myField.getName(),0)
82
83 #myResult = myVisu.ImportFile(medFile)
84 #aMesh = myVisu.CreateMesh(myResult);
85 #aScalarMap = myVisu.CreateScalarMap(myResult,myField.getName(),0)
86 #if(myField.getNumberOfComponents() > 1) :
87 #  aScalarMap = myVisu.CreateCutPlanes(myResult,myField.getName(),0)