printrun-src/printrun/gui/graph.py

Fri, 03 Jun 2016 09:42:44 +0200

author
mbayer
date
Fri, 03 Jun 2016 09:42:44 +0200
changeset 16
36d478bde840
parent 15
0bbb006204fc
child 46
cce0af6351f0
permissions
-rw-r--r--

Implemented svg, png and hpgl compilers to pronterface

15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1 #!/usr/bin/env python
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
3 # This file is part of the Printrun suite.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
4 #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
5 # Printrun is free software: you can redistribute it and/or modify
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
6 # it under the terms of the GNU General Public License as published by
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
7 # the Free Software Foundation, either version 3 of the License, or
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
8 # (at your option) any later version.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
9 #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
10 # Printrun is distributed in the hope that it will be useful,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
13 # GNU General Public License for more details.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
14 #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
15 # You should have received a copy of the GNU General Public License
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
16 # along with Printrun. If not, see <http://www.gnu.org/licenses/>.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
17
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
18 import wx
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
19 from math import log10, floor, ceil
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
20
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
21 from printrun.utils import install_locale
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
22 install_locale('pronterface')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
23
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
24 from .bufferedcanvas import BufferedCanvas
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
25
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
26 class GraphWindow(wx.Frame):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
27 def __init__(self, root, parent_graph = None, size = (600, 600)):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
28 super(GraphWindow, self).__init__(None, title = _("Temperature graph"),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
29 size = size)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
30 panel = wx.Panel(self, -1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
31 vbox = wx.BoxSizer(wx.VERTICAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
32 self.graph = Graph(panel, wx.ID_ANY, root, parent_graph = parent_graph)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
33 vbox.Add(self.graph, 1, wx.EXPAND)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
34 panel.SetSizer(vbox)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
35
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
36 class Graph(BufferedCanvas):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
37 '''A class to show a Graph with Pronterface.'''
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
38
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
39 def __init__(self, parent, id, root, pos = wx.DefaultPosition,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
40 size = wx.Size(150, 80), style = 0, parent_graph = None):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
41 # Forcing a no full repaint to stop flickering
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
42 style = style | wx.NO_FULL_REPAINT_ON_RESIZE
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
43 super(Graph, self).__init__(parent, id, pos, size, style)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
44 self.root = root
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
45
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
46 if parent_graph is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
47 self.extruder0temps = parent_graph.extruder0temps
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
48 self.extruder0targettemps = parent_graph.extruder0targettemps
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
49 self.extruder1temps = parent_graph.extruder1temps
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
50 self.extruder1targettemps = parent_graph.extruder1targettemps
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
51 self.bedtemps = parent_graph.bedtemps
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
52 self.bedtargettemps = parent_graph.bedtargettemps
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
53 self.fanpowers=parent_graph.fanpowers
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
54 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
55 self.extruder0temps = [0]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
56 self.extruder0targettemps = [0]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
57 self.extruder1temps = [0]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
58 self.extruder1targettemps = [0]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
59 self.bedtemps = [0]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
60 self.bedtargettemps = [0]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
61 self.fanpowers= [0]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
62
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
63 self.timer = wx.Timer(self)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
64 self.Bind(wx.EVT_TIMER, self.updateTemperatures, self.timer)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
65
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
66 self.minyvalue = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
67 self.maxyvalue = 260
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
68 self.rescaley = True # should the Y axis be rescaled dynamically?
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
69 if self.rescaley:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
70 self._ybounds = Graph._YBounds(self)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
71
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
72 # If rescaley is set then ybars gives merely an estimate
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
73 # Note that "bars" actually indicate the number of internal+external gridlines.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
74 self.ybars = 5
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
75 self.xbars = 7 # One bar per 10 second
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
76 self.xsteps = 60 # Covering 1 minute in the graph
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
77
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
78 self.window = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
79
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
80 def show_graph_window(self, event = None):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
81 if not self.window:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
82 self.window = GraphWindow(self.root, self)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
83 self.window.Show()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
84 if self.timer.IsRunning():
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
85 self.window.graph.StartPlotting(self.timer.Interval)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
86 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
87 self.window.Raise()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
88
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
89 def __del__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
90 if self.window: self.window.Close()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
91
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
92 def updateTemperatures(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
93 self.AddBedTemperature(self.bedtemps[-1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
94 self.AddBedTargetTemperature(self.bedtargettemps[-1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
95 self.AddExtruder0Temperature(self.extruder0temps[-1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
96 self.AddExtruder0TargetTemperature(self.extruder0targettemps[-1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
97 self.AddExtruder1Temperature(self.extruder1temps[-1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
98 self.AddExtruder1TargetTemperature(self.extruder1targettemps[-1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
99 self.AddFanPower(self.fanpowers[-1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
100 if self.rescaley:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
101 self._ybounds.update()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
102 self.Refresh()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
103
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
104 def drawgrid(self, dc, gc):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
105 # cold, medium, hot = wx.Colour(0, 167, 223),\
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
106 # wx.Colour(239, 233, 119),\
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
107 # wx.Colour(210, 50.100)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
108 # col1 = wx.Colour(255, 0, 0, 255)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
109 # col2 = wx.Colour(255, 255, 255, 128)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
110
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
111 # b = gc.CreateLinearGradientBrush(0, 0, w, h, col1, col2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
112
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
113 gc.SetPen(wx.Pen(wx.Colour(255, 0, 0, 0), 1))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
114
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
115 # gc.SetBrush(wx.Brush(wx.Colour(245, 245, 255, 52)))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
116
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
117 # gc.SetBrush(gc.CreateBrush(wx.Brush(wx.Colour(0, 0, 0, 255))))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
118 gc.SetPen(wx.Pen(wx.Colour(255, 0, 0, 255), 1))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
119
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
120 # gc.DrawLines(wx.Point(0, 0), wx.Point(50, 10))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
121
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
122 font = wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
123 gc.SetFont(font, wx.Colour(23, 44, 44))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
124
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
125 # draw vertical bars
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
126 dc.SetPen(wx.Pen(wx.Colour(225, 225, 225), 1))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
127 for x in range(self.xbars + 1):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
128 dc.DrawLine(x * (float(self.width - 1) / (self.xbars - 1)),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
129 0,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
130 x * (float(self.width - 1) / (self.xbars - 1)),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
131 self.height)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
132
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
133 # draw horizontal bars
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
134 spacing = self._calculate_spacing() # spacing between bars, in degrees
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
135 yspan = self.maxyvalue - self.minyvalue
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
136 ybars = int(yspan / spacing) # Should be close to self.ybars
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
137 firstbar = int(ceil(self.minyvalue / spacing)) # in degrees
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
138 dc.SetPen(wx.Pen(wx.Colour(225, 225, 225), 1))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
139 for y in range(firstbar, firstbar + ybars + 1):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
140 # y_pos = y*(float(self.height)/self.ybars)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
141 degrees = y * spacing
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
142 y_pos = self._y_pos(degrees)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
143 dc.DrawLine(0, y_pos, self.width, y_pos)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
144 gc.DrawText(unicode(y * spacing),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
145 1, y_pos - (font.GetPointSize() / 2))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
146
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
147 if self.timer.IsRunning() is False:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
148 font = wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.BOLD)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
149 gc.SetFont(font, wx.Colour(3, 4, 4))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
150 gc.DrawText("Graph offline",
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
151 self.width / 2 - (font.GetPointSize() * 3),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
152 self.height / 2 - (font.GetPointSize() * 1))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
153
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
154 # dc.DrawCircle(50, 50, 1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
155
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
156 # gc.SetPen(wx.Pen(wx.Colour(255, 0, 0, 0), 1))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
157 # gc.DrawLines([[20, 30], [10, 53]])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
158 # dc.SetPen(wx.Pen(wx.Colour(255, 0, 0, 0), 1))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
159
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
160 def _y_pos(self, temperature):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
161 """Converts a temperature, in degrees, to a pixel position"""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
162 # fraction of the screen from the bottom
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
163 frac = (float(temperature - self.minyvalue)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
164 / (self.maxyvalue - self.minyvalue))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
165 return int((1.0 - frac) * (self.height - 1))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
166
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
167 def _calculate_spacing(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
168 # Allow grids of spacings 1,2.5,5,10,25,50,100,etc
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
169
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
170 yspan = float(self.maxyvalue - self.minyvalue)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
171 log_yspan = log10(yspan / self.ybars)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
172 exponent = int(floor(log_yspan))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
173
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
174 # calculate boundary points between allowed spacings
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
175 log1_25 = log10(2) + log10(1) + log10(2.5) - log10(1 + 2.5)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
176 log25_5 = log10(2) + log10(2.5) + log10(5) - log10(2.5 + 5)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
177 log5_10 = log10(2) + log10(5) + log10(10) - log10(5 + 10)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
178
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
179 if log_yspan - exponent < log1_25:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
180 return 10 ** exponent
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
181 elif log1_25 <= log_yspan - exponent < log25_5:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
182 return 25 * 10 ** (exponent - 1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
183 elif log25_5 <= log_yspan - exponent < log5_10:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
184 return 5 * 10 ** exponent
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
185 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
186 return 10 ** (exponent + 1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
187
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
188 def drawtemperature(self, dc, gc, temperature_list,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
189 text, text_xoffset, r, g, b, a):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
190 if self.timer.IsRunning() is False:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
191 dc.SetPen(wx.Pen(wx.Colour(128, 128, 128, 128), 1))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
192 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
193 dc.SetPen(wx.Pen(wx.Colour(r, g, b, a), 1))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
194
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
195 x_add = float(self.width) / self.xsteps
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
196 x_pos = 0.0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
197 lastxvalue = 0.0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
198 lastyvalue = temperature_list[-1]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
199
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
200 for temperature in (temperature_list):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
201 y_pos = self._y_pos(temperature)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
202 if (x_pos > 0.0): # One need 2 points to draw a line.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
203 dc.DrawLine(lastxvalue, lastyvalue, x_pos, y_pos)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
204
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
205 lastxvalue = x_pos
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
206 x_pos = float(x_pos) + x_add
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
207 lastyvalue = y_pos
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
208
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
209 if len(text) > 0:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
210 font = wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.BOLD)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
211 # font = wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.NORMAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
212 if self.timer.IsRunning() is False:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
213 gc.SetFont(font, wx.Colour(128, 128, 128))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
214 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
215 gc.SetFont(font, wx.Colour(r, g, b))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
216
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
217 text_size = len(text) * text_xoffset + 1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
218 gc.DrawText(text,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
219 x_pos - x_add - (font.GetPointSize() * text_size),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
220 lastyvalue - (font.GetPointSize() / 2))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
221
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
222 def drawfanpower(self, dc, gc):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
223 self.drawtemperature(dc, gc, self.fanpowers,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
224 "Fan", 1, 0, 0, 0, 128)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
225
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
226 def drawbedtemp(self, dc, gc):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
227 self.drawtemperature(dc, gc, self.bedtemps,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
228 "Bed", 2, 255, 0, 0, 128)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
229
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
230 def drawbedtargettemp(self, dc, gc):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
231 self.drawtemperature(dc, gc, self.bedtargettemps,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
232 "Bed Target", 2, 255, 120, 0, 128)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
233
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
234 def drawextruder0temp(self, dc, gc):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
235 self.drawtemperature(dc, gc, self.extruder0temps,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
236 "Ex0", 1, 0, 155, 255, 128)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
237
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
238 def drawextruder0targettemp(self, dc, gc):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
239 self.drawtemperature(dc, gc, self.extruder0targettemps,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
240 "Ex0 Target", 2, 0, 5, 255, 128)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
241
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
242 def drawextruder1temp(self, dc, gc):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
243 self.drawtemperature(dc, gc, self.extruder1temps,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
244 "Ex1", 3, 55, 55, 0, 128)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
245
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
246 def drawextruder1targettemp(self, dc, gc):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
247 self.drawtemperature(dc, gc, self.extruder1targettemps,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
248 "Ex1 Target", 2, 55, 55, 0, 128)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
249
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
250 def SetFanPower(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
251 self.fanpowers.pop()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
252 self.fanpowers.append(value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
253
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
254 def AddFanPower(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
255 self.fanpowers.append(value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
256 if float(len(self.fanpowers) - 1) / self.xsteps > 1:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
257 self.fanpowers.pop(0)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
258
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
259 def SetBedTemperature(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
260 self.bedtemps.pop()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
261 self.bedtemps.append(value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
262
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
263 def AddBedTemperature(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
264 self.bedtemps.append(value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
265 if float(len(self.bedtemps) - 1) / self.xsteps > 1:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
266 self.bedtemps.pop(0)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
267
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
268 def SetBedTargetTemperature(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
269 self.bedtargettemps.pop()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
270 self.bedtargettemps.append(value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
271
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
272 def AddBedTargetTemperature(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
273 self.bedtargettemps.append(value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
274 if float(len(self.bedtargettemps) - 1) / self.xsteps > 1:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
275 self.bedtargettemps.pop(0)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
276
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
277 def SetExtruder0Temperature(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
278 self.extruder0temps.pop()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
279 self.extruder0temps.append(value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
280
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
281 def AddExtruder0Temperature(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
282 self.extruder0temps.append(value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
283 if float(len(self.extruder0temps) - 1) / self.xsteps > 1:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
284 self.extruder0temps.pop(0)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
285
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
286 def SetExtruder0TargetTemperature(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
287 self.extruder0targettemps.pop()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
288 self.extruder0targettemps.append(value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
289
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
290 def AddExtruder0TargetTemperature(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
291 self.extruder0targettemps.append(value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
292 if float(len(self.extruder0targettemps) - 1) / self.xsteps > 1:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
293 self.extruder0targettemps.pop(0)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
294
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
295 def SetExtruder1Temperature(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
296 self.extruder1temps.pop()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
297 self.extruder1temps.append(value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
298
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
299 def AddExtruder1Temperature(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
300 self.extruder1temps.append(value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
301 if float(len(self.extruder1temps) - 1) / self.xsteps > 1:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
302 self.extruder1temps.pop(0)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
303
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
304 def SetExtruder1TargetTemperature(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
305 self.extruder1targettemps.pop()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
306 self.extruder1targettemps.append(value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
307
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
308 def AddExtruder1TargetTemperature(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
309 self.extruder1targettemps.append(value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
310 if float(len(self.extruder1targettemps) - 1) / self.xsteps > 1:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
311 self.extruder1targettemps.pop(0)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
312
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
313 def StartPlotting(self, time):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
314 self.Refresh()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
315 self.timer.Start(time)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
316 if self.window: self.window.graph.StartPlotting(time)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
317
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
318 def StopPlotting(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
319 self.timer.Stop()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
320 self.Refresh()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
321 if self.window: self.window.graph.StopPlotting()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
322
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
323 def draw(self, dc, w, h):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
324 dc.SetBackground(wx.Brush(self.root.bgcolor))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
325 dc.Clear()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
326 gc = wx.GraphicsContext.Create(dc)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
327 self.width = w
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
328 self.height = h
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
329 self.drawgrid(dc, gc)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
330 self.drawbedtargettemp(dc, gc)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
331 self.drawbedtemp(dc, gc)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
332 self.drawfanpower(dc, gc)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
333 self.drawextruder0targettemp(dc, gc)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
334 self.drawextruder0temp(dc, gc)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
335 self.drawextruder1targettemp(dc, gc)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
336 self.drawextruder1temp(dc, gc)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
337
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
338 class _YBounds(object):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
339 """Small helper class to claculate y bounds dynamically"""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
340
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
341 def __init__(self, graph, minimum_scale=5.0, buffer=0.10):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
342 """_YBounds(Graph,float,float)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
343
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
344 graph parent object to calculate scales for
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
345 minimum_scale minimum range to show on the graph
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
346 buffer amount of padding to add above & below the
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
347 displayed temperatures. Given as a fraction of the
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
348 total range. (Eg .05 to use 90% of the range for
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
349 temperatures)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
350 """
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
351 self.graph = graph
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
352 self.min_scale = minimum_scale
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
353 self.buffer = buffer
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
354
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
355 # Frequency to rescale the graph
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
356 self.update_freq = 10
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
357 # number of updates since last full refresh
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
358 self._last_update = self.update_freq
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
359
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
360 def update(self, forceUpdate=False):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
361 """Updates graph.minyvalue and graph.maxyvalue based on current
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
362 temperatures """
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
363 self._last_update += 1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
364 # TODO Smart update. Only do full calculation every 10s. Otherwise,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
365 # just look at current graph & expand if necessary
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
366 if forceUpdate or self._last_update >= self.update_freq:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
367 self.graph.minyvalue, self.graph.maxyvalue = self.getBounds()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
368 self._last_update = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
369 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
370 bounds = self.getBoundsQuick()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
371 self.graph.minyvalue, self.graph.maxyvalue = bounds
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
372
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
373 def getBounds(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
374 """
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
375 Calculates the bounds based on the current temperatures
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
376
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
377 Rules:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
378 * Include the full extruder0 history
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
379 * Include the current target temp (but not necessarily old
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
380 settings)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
381 * Include the extruder1 and/or bed temp if
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
382 1) The target temp is >0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
383 2) The history has ever been above 5
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
384 * Include at least min_scale
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
385 * Include at least buffer above & below the extreme temps
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
386 """
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
387 extruder0_min = min(self.graph.extruder0temps)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
388 extruder0_max = max(self.graph.extruder0temps)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
389 extruder0_target = self.graph.extruder0targettemps[-1]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
390 extruder1_min = min(self.graph.extruder1temps)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
391 extruder1_max = max(self.graph.extruder1temps)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
392 extruder1_target = self.graph.extruder1targettemps[-1]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
393 bed_min = min(self.graph.bedtemps)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
394 bed_max = max(self.graph.bedtemps)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
395 bed_target = self.graph.bedtargettemps[-1]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
396
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
397 miny = min(extruder0_min, extruder0_target)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
398 maxy = max(extruder0_max, extruder0_target)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
399 if extruder1_target > 0 or extruder1_max > 5: # use extruder1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
400 miny = min(miny, extruder1_min, extruder1_target)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
401 maxy = max(maxy, extruder1_max, extruder1_target)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
402 if bed_target > 0 or bed_max > 5: # use HBP
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
403 miny = min(miny, bed_min, bed_target)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
404 maxy = max(maxy, bed_max, bed_target)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
405 miny=min(0,miny);
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
406 maxy=max(260,maxy);
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
407
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
408 padding = (maxy - miny) * self.buffer / (1.0 - 2 * self.buffer)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
409 miny -= padding
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
410 maxy += padding
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
411
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
412 if maxy - miny < self.min_scale:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
413 extrapadding = (self.min_scale - maxy + miny) / 2.0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
414 miny -= extrapadding
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
415 maxy += extrapadding
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
416
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
417 return (miny, maxy)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
418
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
419 def getBoundsQuick(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
420 # Only look at current temps
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
421 extruder0_min = self.graph.extruder0temps[-1]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
422 extruder0_max = self.graph.extruder0temps[-1]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
423 extruder0_target = self.graph.extruder0targettemps[-1]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
424 extruder1_min = self.graph.extruder1temps[-1]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
425 extruder1_max = self.graph.extruder1temps[-1]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
426 extruder1_target = self.graph.extruder1targettemps[-1]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
427 bed_min = self.graph.bedtemps[-1]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
428 bed_max = self.graph.bedtemps[-1]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
429 bed_target = self.graph.bedtargettemps[-1]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
430
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
431 miny = min(extruder0_min, extruder0_target)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
432 maxy = max(extruder0_max, extruder0_target)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
433 if extruder1_target > 0 or extruder1_max > 5: # use extruder1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
434 miny = min(miny, extruder1_min, extruder1_target)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
435 maxy = max(maxy, extruder1_max, extruder1_target)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
436 if bed_target > 0 or bed_max > 5: # use HBP
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
437 miny = min(miny, bed_min, bed_target)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
438 maxy = max(maxy, bed_max, bed_target)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
439 miny=min(0,miny);
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
440 maxy=max(260,maxy);
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
441
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
442 # We have to rescale, so add padding
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
443 bufratio = self.buffer / (1.0 - self.buffer)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
444 if miny < self.graph.minyvalue:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
445 padding = (self.graph.maxyvalue - miny) * bufratio
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
446 miny -= padding
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
447 if maxy > self.graph.maxyvalue:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
448 padding = (maxy - self.graph.minyvalue) * bufratio
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
449 maxy += padding
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
450
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
451 return (min(miny, self.graph.minyvalue),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
452 max(maxy, self.graph.maxyvalue))

mercurial