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 getNames(self):
71 """Get the names of the data items""" 72 names=[] 73 tmp=self.data.getValueNames() 74 75 for n in tmp: 76 addIt=True 77 for f in self.forbidden: 78 if n.find(f)>=0: 79 addIt=False 80 break 81 if addIt: 82 names.append(n) 83 return names
84
85 - def hasTimes(self):
86 """Check whether this timeline contains any timesteps""" 87 return len(self.data.getTimes())>0
88
89 - def hasData(self):
90 """Check whether there is any plotable data""" 91 return self.hasTimes() and len(self.getNames())>0
92
93 - def redo(self):
94 """Replot the timelines""" 95 if not self.hasData(): 96 return 97 98 self.preparePlot() 99 100 names=self.getNames() 101 for n in names: 102 title=n 103 104 if title.find("_slave")>=0: 105 title=title[: title.find("_slave")] 106 slaveNr=int(n[n.find("_slave")+len("_slave"):]) 107 lastValid=self.data.slaves[slaveNr].lastValid[title] 108 else: 109 lastValid=self.data.lastValid[title] 110 times=self.data.getTimes(title) 111 self.buildData(times,n,title,lastValid) 112 113 if len(names)>0 and len(times)>0: 114 self.doReplot()
115
116 - def buildData(self,times,name,title,lastValid):
117 """Build the implementation specific data 118 @param times: The vector of times for which data exists 119 @param name: the name under which the data is stored in the timeline 120 @param title: the title under which this will be displayed 121 @param lastValid: wether the last data entry is valid""" 122 123 notImplemented(self,"buildData")
124
125 - def preparePlot(self):
126 """Prepare the plotting window""" 127 128 notImplemented(self,"preparePlot")
129 130
131 - def doReplot(self):
132 """Replot the whole data""" 133 134 notImplemented(self,"doReplot")
135
136 - def actualSetTitle(self,title):
137 """Sets the title""" 138 139 notImplemented(self,"actualSetTitle")
140
141 - def setTitle(self,title):
142 """Sets the title""" 143 self.actualSetTitle(title) 144 self.spec.theTitle=title
145
146 - def setYLabel(self,title):
147 """Sets the label on the first Y-Axis""" 148 149 notImplemented(self,"setYLabel")
150
151 - def setYLabel2(self,title):
152 """Sets the label on the second Y-Axis""" 153 154 notImplemented(self,"setYLabel2")
155
156 - def doHardcopy(self,filename,form):
157 """Write the contents of the plot to disk 158 @param filename: Name of the file without type extension 159 @param form: String describing the format""" 160 161 notImplemented(self,"doHardcopy")
162 163 # Should work with Python3 and Python2 164