Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/visu.git] / src / VISU_SWIG / visu.py
1 import sys
2 import os
3 import salome
4 import SALOMEDS
5 import SALOME
6 import SALOME_MED
7
8 from libSALOME_Swig import *
9 sg = SALOMEGUI_Swig()
10
11 myVisu = salome.lcc.FindOrLoadComponent("FactoryServer", "VISU")
12
13 def getMedObjectFromStudy():
14     mySO = salome.myStudy.FindObject("Objet MED")
15     anAttr = mySO.FindAttribute("AttributeIOR")[1]
16     obj = salome.orb.string_to_object(anAttr.Value())
17     myObj = obj._narrow(SALOME_MED.MED)
18     return myObj
19
20 def getFieldObjectFromStudy(number,subnumber):
21     mySO = salome.myStudy.FindObject("MEDFIELD")
22     mysub = mySO.FindSubObject(number)[1]
23     if mysub:
24         mysubsub = mysub.FindSubObject(subnumber)[1]
25         if mysubsub:
26             Builder = salome.myStudy.NewBuilder()
27             anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
28             obj = salome.orb.string_to_object(anAttr.Value())
29             myObj = obj._narrow(SALOME_MED.FIELDINT)
30             if (myObj == None):
31                 myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
32             return myObj
33     else:
34         print "ERROR: No Field Object stored in this Study"
35         return None
36
37 #medFile = "mixte.med"
38 #medFile = "fra.med"
39 medFile = "pointe.med"
40 #medFile = "carre_en_quad4_seg2.med"
41 #medFile = "cube_hexa8_quad4.med"
42
43 medFile = os.getenv('SALOME_ROOT_DIR') + '/../SALOME_ROOT/data/' + medFile
44 print medFile
45 studyCurrent = salome.myStudyName
46 med_comp = salome.lcc.FindOrLoadComponent("FactoryServer", "MED")
47 try:
48     if os.access(medFile, os.R_OK) :
49        if os.access(medFile, os.W_OK) :
50            med_comp.readStructFileWithFieldType(medFile,studyCurrent)
51            med_obj = getMedObjectFromStudy()
52            print "med_obj - ", med_obj
53
54            myField = getFieldObjectFromStudy(2,1)
55            myResult1 = myVisu.ImportMed(myField)
56            aMesh1 = myVisu.CreateMesh(myResult1);
57            aScalarMap1 = myVisu.CreateScalarMap(myResult1,myField.getName(),0)
58            if(myField.getNumberOfComponents() > 1) :
59                aVectors = myVisu.CreateVectors(myResult1,myField.getName(),0)
60
61            myResult2 = myVisu.ImportFile(medFile)
62            aMesh2 = myVisu.CreateMesh(myResult2);
63            aScalarMap2 = myVisu.CreateScalarMap(myResult2,myField.getName(),0)
64            if(myField.getNumberOfComponents() > 1) :
65               aCutPlanes = myVisu.CreateCutPlanes(myResult2,myField.getName(),0)
66
67            sg.updateObjBrowser(1)
68        else :  print "We have no permission to rewrite medFile, so readStructFileWithFieldType can't open this file";
69     else :  print  "We have no permission to read medFile, it will not be opened"; 
70
71 except:
72     if sys.exc_type == SALOME.SALOME_Exception :
73         print "There is no permission to read " + medFile
74     else :
75         print sys.exc_type 
76         print sys.exc_value
77         print sys.exc_traceback
78