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

Source Code for Module PyFoam.Basics.GeneralPlotTimelines

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