Package PyFoam :: Package Basics :: Module GeneralPlotTimelines
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.Basics.GeneralPlotTimelines

  1  #  ICE Revision: $Id$ 
  2  """Plots a collection of timelines. General superclass for te other implementations""" 
  3   
  4  from PyFoam.Basics.CustomPlotInfo import readCustomPlotInfo,CustomPlotInfo 
  5   
  6  from PyFoam.Error import notImplemented 
  7   
  8  from PyFoam.ThirdParty.six import iteritems 
  9   
10 -class PlotLinesRegistry(object):
11 """Collects references to GeneralPlotLines objects""" 12 13 nr=1 14
15 - def __init__(self):
16 self.plots={}
17
18 - def clear(self):
19 PlotLinesRegistry.nr=1 20 self.plots={}
21
22 - def add(self,plot):
23 nr=PlotLinesRegistry.nr 24 PlotLinesRegistry.nr+=1 25 self.plots[nr]=plot 26 27 return nr
28
29 - def prepareForTransfer(self):
30 """Makes sure that the data about the plots is to be transfered via XMLRPC""" 31 lst={} 32 for i,p in iteritems(self.plots): 33 lst[str(i)]={ "nr" : i, 34 "spec" : p.spec.getDict(), 35 "id" : p.spec.id, 36 "data" : p.data.lineNr } 37 return lst
38 39 _allPlots=PlotLinesRegistry() 40
41 -def allPlots():
42 return _allPlots
43 44
45 -class GeneralPlotTimelines(object):
46 """This class defines the interface for specific implementations of plotting 47 48 This class is moedelled after the Gnuplot-class from the Gnuplot-package""" 49
50 - def __init__(self, 51 timelines, 52 custom, 53 showWindow=True, 54 registry=None):
55 """@param timelines: The timelines object 56 @type timelines: TimeLineCollection 57 @param custom: A CustomplotInfo-object. Values in this object usually override the 58 other options 59 @param showWindow: whether or not to show a window. Doesn't affect all implementations 60 """ 61 62 self.data=timelines 63 self.spec=custom 64 65 self.alternate=getattr(self.spec,"alternateAxis",[]) 66 self.forbidden=getattr(self.spec,"forbidden",[]) 67 68 self.showWindow=showWindow 69 70 if registry==None: 71 registry=allPlots() 72 self.nr=registry.add(self)
73
74 - def testAlternate(self,name):
75 if name in self.alternate: 76 return True 77 if name.find("_slave")>0: 78 for a in self.alternate: 79 if name[:name.find("_slave")]==a: 80 return True 81 return False
82
83 - def getNames(self):
84 """Get the names of the data items""" 85 names=[] 86 tmp=self.data.getValueNames() 87 88 for n in tmp: 89 addIt=True 90 for f in self.forbidden: 91 if n.find(f)>=0: 92 addIt=False 93 break 94 if addIt: 95 names.append(n) 96 return names
97
98 - def hasTimes(self):
99 """Check whether this timeline contains any timesteps""" 100 return len(self.data.getTimes())>0
101
102 - def hasData(self):
103 """Check whether there is any plotable data""" 104 return self.hasTimes() and len(self.getNames())>0
105
106 - def redo(self):
107 """Replot the timelines""" 108 if not self.hasData(): 109 return 110 111 self.preparePlot() 112 113 names=self.getNames() 114 for n in names: 115 title=n 116 117 if title.find("_slave")>=0: 118 title=title[: title.find("_slave")] 119 slaveNr=int(n[n.find("_slave")+len("_slave"):]) 120 lastValid=self.data.slaves[slaveNr].lastValid[title] 121 else: 122 lastValid=self.data.lastValid[title] 123 times=self.data.getTimes(title) 124 self.buildData(times,n,title,lastValid) 125 126 if len(names)>0 and len(times)>0: 127 self.doReplot()
128
129 - def buildData(self,times,name,title,lastValid):
130 """Build the implementation specific data 131 @param times: The vector of times for which data exists 132 @param name: the name under which the data is stored in the timeline 133 @param title: the title under which this will be displayed 134 @param lastValid: wether the last data entry is valid""" 135 136 notImplemented(self,"buildData")
137
138 - def preparePlot(self):
139 """Prepare the plotting window""" 140 141 notImplemented(self,"preparePlot")
142 143
144 - def doReplot(self):
145 """Replot the whole data""" 146 147 notImplemented(self,"doReplot")
148
149 - def actualSetTitle(self,title):
150 """Sets the title""" 151 152 notImplemented(self,"actualSetTitle")
153
154 - def setTitle(self,title):
155 """Sets the title""" 156 self.actualSetTitle(title) 157 self.spec.theTitle=title
158
159 - def setYLabel(self,title):
160 """Sets the label on the first Y-Axis""" 161 162 notImplemented(self,"setYLabel")
163
164 - def setYLabel2(self,title):
165 """Sets the label on the second Y-Axis""" 166 167 notImplemented(self,"setYLabel2")
168
169 - def doHardcopy(self,filename,form):
170 """Write the contents of the plot to disk 171 @param filename: Name of the file without type extension 172 @param form: String describing the format""" 173 174 notImplemented(self,"doHardcopy")
175 176 # Should work with Python3 and Python2 177