Salome HOME
bbcc2d32d15e1fb02c9bd5478c2d9b5a4bc0da4f
[modules/visu.git] / src / VISU_SWIG / visu_prs_example.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_prs_exam.py
25 #  Module : VISU
26 #
27 import sys
28 import os
29 import salome
30 import SALOMEDS
31 import SALOME
32 import SALOME_MED
33 import VISU
34
35 if salome.hasDesktop():
36     from libSALOME_Swig import *
37     sg = SALOMEGUI_Swig()
38 import visu_gui
39 myVisu = visu_gui.myVisu
40
41 myVisu.SetCurrentStudy(salome.myStudy)
42
43 medFile = "pointe.med"
44 medFile = os.getenv('DATA_DIR') + '/MedFiles/' + medFile
45 print medFile
46
47 studyCurrent = salome.myStudyName
48
49 med_comp = salome.lcc.FindOrLoadComponent("FactoryServer", "MED")
50 #myVisu = salome.lcc.FindOrLoadComponent("FactoryServer", "Visu")
51
52 try:
53     if os.access(medFile, os.R_OK) :
54        if os.access(medFile, os.W_OK) :
55            med_comp.readStructFileWithFieldType(medFile,studyCurrent)
56            med_obj = visu_gui.visu.getMedObjectFromStudy()
57            print "med_obj - ", med_obj
58
59            myField = visu_gui.visu.getFieldObjectFromStudy(2,1)
60            aMeshName = "FILED_DOUBLE_MESH"
61            anEntity = VISU.NODE
62            aTimeStampId = 0
63            
64            myResult1 = myVisu.ImportMedField(myField)
65            aMesh1 = myVisu.MeshOnEntity(myResult1, aMeshName, anEntity);
66            
67            aScalarMap1= myVisu.ScalarMapOnField(myResult1, aMeshName, anEntity, myField.getName(), aTimeStampId)
68            if(myField.getNumberOfComponents() > 1) :
69                aVectors = myVisu.VectorsOnField(myResult1, aMeshName, anEntity, myField.getName(), aTimeStampId)
70
71            myResult2 = myVisu.ImportFile(medFile)
72            aMeshName = "maa1"
73            anEntity = VISU.NODE
74            aMesh2 = myVisu.MeshOnEntity(myResult2, aMeshName, anEntity)
75
76            aScalarMap2 = myVisu.ScalarMapOnField(myResult2, aMeshName, anEntity, myField.getName(), aTimeStampId)
77            if(myField.getNumberOfComponents() > 1) :
78              aCutPlanes = myVisu.CutPlanesOnField(myResult2, aMeshName, anEntity, myField.getName(), aTimeStampId)
79            if salome.hasDesktop():  
80                sg.updateObjBrowser(0)
81        else :  print "We have no permission to rewrite medFile, so readStructFileWithFieldType can't open this file";
82     else :  print  "We have no permission to read medFile, it will not be opened"; 
83 except:
84     if sys.exc_type == SALOME.SALOME_Exception :
85         print "There is no permission to read " + medFile
86     else :
87         print sys.exc_type 
88         print sys.exc_value
89         print sys.exc_traceback
90