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