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