Salome HOME
Merge branch 'abn/configuration'
[modules/paravis.git] / test / VisuPrs / bugs / C5.py
1 # Copyright (C) 2010-2016  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 pvsimple
28
29 medPath = datadir
30
31 class DisplayManager:
32     """
33     Create 3D presentations on entities on a given med file and mesh
34     """
35     def __init__(self, medFile=None, meshName=None, myEntity=None):
36         if ( medFile is not None and meshName is not None and myEntity is not None):
37             self.loadData(medFile, meshName, myEntity)
38         else:
39             self.medFile  = None
40             self.meshName = None
41             self.myData   = None
42             self.myMesh   = None
43             self.myEntity = None
44
45     def loadData(self, medFile, meshName=None, myEntity=EntityType.NODE):
46         self.medFile  = medFile
47         pvsimple.OpenDataFile(medFile)
48         self.myData   = pvsimple.GetActiveSource()
49         self.myEntity = myEntity
50         if meshName is not None:
51             self.setMesh(meshName)
52
53     def getData(self):
54         return self.myData
55
56     def checkData(self):
57         if ( self.myData is None or self.myMesh is None ):
58             return False
59         return True
60
61     def setMesh(self,meshName):
62         self.meshName = meshName
63         self.myMesh   = MeshOnEntity(self.myData,
64                                      self.meshName,
65                                      self.myEntity)
66         self.myMesh.Representation = 'Surface'
67
68     def DisplayMap(self, aView, aMap, title, aDelay=0):
69         if aMap is None:
70             print "Null scalar map is created"
71         display_only(aMap, aView)
72         reset_view(aView)
73         time.sleep(aDelay)
74
75     def ScalarMap(self, aView, fieldName, iteration, title , delay=0):
76         if not self.checkData(): return
77         aMap = ScalarMapOnField(self.myData, self.myEntity, fieldName, iteration)
78         self.DisplayMap(aView, aMap, title, delay)
79
80     def DeformedShape(self, aView, fieldName, iteration, title , delay=0):
81         if not self.checkData(): return
82         aMap = DeformedShapeOnField(self.myData, self.myEntity, fieldName, iteration)
83         if aMap is not None:
84             aMap.ColorArrayName = ("CELLS", fieldName)
85         self.DisplayMap(aView, aMap, title, delay)
86
87     def Vectors(self, aView, fieldName, iteration, title , delay=0):
88         if not self.checkData(): return
89         aMap = VectorsOnField(self.myData, self.myEntity, fieldName, iteration)
90         if aMap is not None:
91             aMap.ColorArrayName = ("CELLS", fieldName)
92         self.DisplayMap(aView, aMap, title, delay)
93
94     def IsoSurfaces(self, aView, fieldName, iteration, title , delay=0):
95         if not self.checkData(): return
96         aMap = IsoSurfacesOnField(self.myData, self.myEntity, fieldName, iteration)
97         self.DisplayMap(aView, aMap, title, delay)
98
99     def Animation(self, aView, theObj, theDuration, NbOfLoops, title, aPath=""):
100
101         path = None
102         if aPath is not "":
103             print "Define save path"
104             path = aPath
105
106         scene = pvsimple.AnimateReader(theObj, aView, path)
107
108         print "Start Animation"
109
110         scene.Duration = theDuration
111         NbOfFrames = len(scene.TimeKeeper.TimestepValues)
112         NbOfIter = NbOfFrames-1
113
114         reset_view(view=aView)
115
116         ind =  0
117         while ind < NbOfLoops:
118             scene.Play()
119             ind = ind + 1
120
121         print "Stop Animation"
122         scene.Stop()
123
124         return scene
125
126     def XYPlot(self, myView, txtFile, theTableName, theDelay, theColor):
127         table = TableReader(FileName=txtFile)
128
129         # >>> Create curve
130         myView = CreateXYPlotView()
131         myCurve = Show(table, view = myView)
132
133 def createView():
134     aView=pvsimple.GetRenderView()
135     return aView
136
137
138 theEntity = EntityType.CELL
139 theMedFile = "TETRA_domaine_fluide.med"
140 theMedFile = os.path.join(medPath,theMedFile)
141 theMeshName = "Domaine_fluide"
142 theFieldName = "TempC"
143 theDuration = 20
144 NbOfLoops = 4
145 #thePath = os.getenv("TMP_DIR")
146 thePrefix = "TestPngFromAnim"
147 import tempfile
148 thePath = os.path.join(tempfile.mkdtemp(), thePrefix)
149 thePath += ".png"
150
151 displayMng = DisplayManager()
152 displayMng.loadData(theMedFile,theMeshName,theEntity)
153 ScalarMapOnField(displayMng.getData(), theEntity, theFieldName, 1)
154
155 myView = createView()
156 displayMng.Animation(myView, displayMng.getData(), theDuration, NbOfLoops, "", thePath)