Salome HOME
Synchronize adm files
[modules/paravis.git] / test / VisuPrs / bugs / C5.py
1 # Copyright (C) 2010-2014  CEA/DEN, EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 # This case corresponds to: /visu/bugs2/C5 case
21
22 import sys
23 import os
24 import time
25 from paravistest import datadir
26 from presentations import *
27 import paravis
28 import pvsimple
29
30 my_paravis = paravis.myParavis
31
32 medPath = datadir
33
34 class DisplayManager:
35     """
36     Create 3D presentations on entities on a given med file and mesh
37     """
38     def __init__(self, medFile=None, meshName=None, myEntity=None):
39         if ( medFile is not None and meshName is not None and myEntity is not None):
40             self.loadData(medFile, meshName, myEntity)
41         else:
42             self.medFile  = None
43             self.meshName = None
44             self.myData   = None
45             self.myMesh   = None
46             self.myEntity = None
47              
48     def loadData(self, medFile, meshName=None, myEntity=EntityType.NODE):
49         self.medFile  = medFile
50         my_paravis.ImportFile(medFile)
51         self.myData   = pvsimple.GetActiveSource()
52         self.myEntity = myEntity
53         if meshName is not None:
54             self.setMesh(meshName)
55
56     def getData(self):
57         return self.myData
58         
59     def checkData(self):
60         if ( self.myData is None or self.myMesh is None ):
61             return False
62         return True
63
64     def setMesh(self,meshName):
65         self.meshName = meshName
66         self.myMesh   = MeshOnEntity(self.myData,
67                                      self.meshName,
68                                      self.myEntity)
69         self.myMesh.Representation = 'Surface'
70
71     def DisplayMap(self, aView, aMap, title, aDelay=0):
72         if aMap is None:
73             print "Null scalar map is created"        
74         display_only(aMap, aView)
75         reset_view(aView)
76         time.sleep(aDelay)
77
78     def ScalarMap(self, aView, fieldName, iteration, title , delay=0):
79         if not self.checkData(): return
80         aMap = ScalarMapOnField(self.myData, self.myEntity, fieldName, iteration)
81         self.DisplayMap(aView, aMap, title, delay)
82
83     def DeformedShape(self, aView, fieldName, iteration, title , delay=0):
84         if not self.checkData(): return
85         aMap = DeformedShapeOnField(self.myData, self.myEntity, fieldName, iteration)
86         if aMap is not None:
87             aMap.ColorArrayName = fieldName
88         self.DisplayMap(aView, aMap, title, delay)
89
90     def Vectors(self, aView, fieldName, iteration, title , delay=0):
91         if not self.checkData(): return
92         aMap = VectorsOnField(self.myData, self.myEntity, fieldName, iteration)
93         if aMap is not None:
94             aMap.ColorArrayName = fieldName
95         self.DisplayMap(aView, aMap, title, delay)
96
97     def IsoSurfaces(self, aView, fieldName, iteration, title , delay=0):
98         if not self.checkData(): return
99         aMap = IsoSurfacesOnField(self.myData, self.myEntity, fieldName, iteration)
100         self.DisplayMap(aView, aMap, title, delay)
101
102     def Animation(self, aView, theObj, theDuration, NbOfLoops, title, aPath=""):
103
104         path = None
105         if aPath is not "":
106             print "Define save path"
107             path = aPath
108             
109         scene = pvsimple.AnimateReader(theObj, aView, path)
110         
111         print "Start Animation"
112
113         scene.Duration = theDuration
114         NbOfFrames = len(scene.TimeKeeper.TimestepValues)
115         NbOfIter = NbOfFrames-1
116
117         reset_view(view=aView)
118
119         ind =  0
120         while ind < NbOfLoops:
121             scene.Play()
122             ind = ind + 1
123
124         print "Stop Animation"
125         scene.Stop()
126
127         return scene
128
129     def XYPlot(self, myView, txtFile, theTableName, theDelay, theColor):
130         table = TableReader(FileName=txtFile)
131
132         # >>> Create curve
133         myView = CreateXYPlotView()
134         myCurve = Show(table, view = myView)
135     
136 def createView():
137     aView=pvsimple.GetRenderView()
138     return aView
139
140
141 theEntity = EntityType.CELL
142 theMedFile = "TETRA_domaine_fluide.med"
143 theMedFile = os.path.join(medPath,theMedFile)
144 theMeshName = "Domaine_fluide"
145 theFieldName = "TempC"
146 theDuration = 20
147 NbOfLoops = 4
148 #thePath = os.getenv("TMP_DIR")
149 thePrefix = "TestPngFromAnim"
150 thePath = os.path.join("/tmp", thePrefix)
151 thePath += ".png"
152
153 displayMng = DisplayManager()
154 displayMng.loadData(theMedFile,theMeshName,theEntity)
155 ScalarMapOnField(displayMng.getData(), theEntity, theFieldName, 1)
156
157 myView = createView()
158 displayMng.Animation(myView, displayMng.getData(), theDuration, NbOfLoops, "", thePath)