printrun-src/printrun/gui/graph.py

Wed, 20 Jan 2021 10:17:01 +0100

author
mdd
date
Wed, 20 Jan 2021 10:17:01 +0100
changeset 47
dcc64b767b64
parent 46
cce0af6351f0
permissions
-rw-r--r--

updated pronterface.py losing my own changes

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

mercurial