Salome HOME
Movement of examples to CVS EXAMPLES SAMPLES_SRC.
[modules/visu.git] / src / VISU_SWIG / visu_med.py
1 #  VISU VISU_SWIG : binding of C++ implementation and Python
2 #
3 #  Copyright (C) 2003  CEA/DEN, EDF R&D
4 #
5 #
6 #
7 #  File   : visu_med.py
8 #  Module : VISU
9
10 import os
11 import salome
12 import SALOMEDS
13 import SALOME_MED
14 import VISU
15
16 from libSALOME_Swig import *
17 sg = SALOMEGUI_Swig()
18
19 def getMedObjectFromStudy():
20     mySO = salome.myStudy.FindObject("Objet MED")
21     anAttr = mySO.FindAttribute("AttributeIOR")[1]
22     obj = salome.orb.string_to_object(anAttr.Value())
23     myObj = obj._narrow(SALOME_MED.MED)
24     return myObj
25
26 def getFieldObjectFromStudy(number,subnumber):
27     mySO = salome.myStudy.FindObject("MEDFIELD")
28     mysub = mySO.FindSubObject(number)[1]
29     if mysub:
30         mysubsub = mysub.FindSubObject(subnumber)[1]
31         if mysubsub:
32             Builder = salome.myStudy.NewBuilder()
33             anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
34             obj = salome.orb.string_to_object(anAttr.Value())
35             myObj = obj._narrow(SALOME_MED.FIELDINT)
36             if (myObj == None):
37                 myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
38             return myObj
39     else:
40         print "ERROR: No Field Object stored in this Study"
41         return None
42
43 med_comp = salome.lcc.FindOrLoadComponent("FactoryServer", "MED")
44
45 medDir = os.getenv('DATA_DIR') + '/MedFiles/'
46
47 def importMedFrom(medDir,medFile):
48     medFile = medDir + medFile
49     med_comp.readStructFileWithFieldType(medFile,salome.myStudyName)
50     sg.updateObjBrowser(1)
51   
52 def importMed(medFile):
53     importMedFrom(medDir,medFile)
54
55 #med_obj = getMedObjectFromStudy()
56 myVisu = salome.lcc.FindOrLoadComponent("FactoryServer", "VISU")
57 print "Use importMed(medFile) or importMedFrom(medDir,medFile) functions !"
58
59 #myField = getFieldObjectFromStudy(2,1)
60 #myResult = myVisu.ImportMed(myField)
61 #aMesh = myVisu.CreateMesh(myResult);
62 #aScalarMap = myVisu.CreateScalarMap(myResult,myField.getName(),0)
63 #if(myField.getNumberOfComponents() > 1) :
64 #  aScalarMap = myVisu.CreateVectors(myResult,myField.getName(),0)
65
66 #myResult = myVisu.ImportFile(medFile)
67 #aMesh = myVisu.CreateMesh(myResult);
68 #aScalarMap = myVisu.CreateScalarMap(myResult,myField.getName(),0)
69 #if(myField.getNumberOfComponents() > 1) :
70 #  aScalarMap = myVisu.CreateCutPlanes(myResult,myField.getName(),0)