Salome HOME
Update copyright information
[modules/visu.git] / src / VISU_SWIG / visu_med.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2012  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
24 #  VISU VISU_SWIG : binding of C++ implementation and Python
25 #  File   : visu_med.py
26 #  Module : VISU
27 #
28 import os
29 import salome
30 import SALOMEDS
31 import SALOME_MED
32 import VISU
33
34 if salome.hasDesktop():
35     from libSALOME_Swig import *
36     sg = SALOMEGUI_Swig()
37
38 def getMedObjectFromStudy():
39     mySO = salome.myStudy.FindObject("Objet MED")
40     anAttr = mySO.FindAttribute("AttributeIOR")[1]
41     obj = salome.orb.string_to_object(anAttr.Value())
42     myObj = obj._narrow(SALOME_MED.MED)
43     return myObj
44
45 def getFieldObjectFromStudy(number,subnumber):
46     mySO = salome.myStudy.FindObject("MEDFIELD")
47     mysub = mySO.FindSubObject(number)[1]
48     if mysub:
49         mysubsub = mysub.FindSubObject(subnumber)[1]
50         if mysubsub:
51             Builder = salome.myStudy.NewBuilder()
52             anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
53             obj = salome.orb.string_to_object(anAttr.Value())
54             myObj = obj._narrow(SALOME_MED.FIELDINT)
55             if (myObj == None):
56                 myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
57             return myObj
58     else:
59         print "ERROR: No Field Object stored in this Study"
60         return None
61
62 med_comp = salome.lcc.FindOrLoadComponent("FactoryServer", "MED")
63
64 medDir = os.getenv('DATA_DIR') + '/MedFiles/'
65
66 def importMedFrom(medDir,medFile):
67     medFile = medDir + medFile
68     med_comp.readStructFileWithFieldType(medFile,salome.myStudyName)
69     if salome.hasDesktop():
70         sg.updateObjBrowser(1)
71   
72 def importMed(medFile):
73     importMedFrom(medDir,medFile)
74
75 #med_obj = getMedObjectFromStudy()
76 myVisu = salome.lcc.FindOrLoadComponent("FactoryServer", "VISU")
77 myVisu.SetCurrentStudy(salome.myStudy)
78 print "Use importMed(medFile) or importMedFrom(medDir,medFile) functions !"
79
80 #myField = getFieldObjectFromStudy(2,1)
81 #myResult = myVisu.ImportMed(myField)
82 #aMesh = myVisu.CreateMesh(myResult);
83 #aScalarMap = myVisu.CreateScalarMap(myResult,myField.getName(),0)
84 #if(myField.getNumberOfComponents() > 1) :
85 #  aScalarMap = myVisu.CreateVectors(myResult,myField.getName(),0)
86
87 #myResult = myVisu.ImportFile(medFile)
88 #aMesh = myVisu.CreateMesh(myResult);
89 #aScalarMap = myVisu.CreateScalarMap(myResult,myField.getName(),0)
90 #if(myField.getNumberOfComponents() > 1) :
91 #  aScalarMap = myVisu.CreateCutPlanes(myResult,myField.getName(),0)