author | laurent |
Wed, 07 Mar 2012 10:06:01 +0100 | |
changeset 652 | 676307069508 |
parent 648 | 95d165193770 |
child 660 | 30c0371ac086 |
permissions | -rw-r--r-- |
301 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
|
5 |
#based on the plcopen standard. |
|
6 |
# |
|
7 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
|
8 |
# |
|
9 |
#See COPYING file for copyrights details. |
|
10 |
# |
|
11 |
#This library is free software; you can redistribute it and/or |
|
12 |
#modify it under the terms of the GNU General Public |
|
13 |
#License as published by the Free Software Foundation; either |
|
14 |
#version 2.1 of the License, or (at your option) any later version. |
|
15 |
# |
|
16 |
#This library is distributed in the hope that it will be useful, |
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
19 |
#General Public License for more details. |
|
20 |
# |
|
21 |
#You should have received a copy of the GNU General Public |
|
22 |
#License along with this library; if not, write to the Free Software |
|
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
||
25 |
import wx |
|
26 |
import wx.lib.plot as plot |
|
642
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
27 |
import numpy |
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
344
diff
changeset
|
28 |
from graphics.GraphicCommons import DebugViewer |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
504
diff
changeset
|
29 |
from controls import EditorPanel |
301 | 30 |
|
31 |
colours = ['blue', 'red', 'green', 'yellow', 'orange', 'purple', 'brown', 'cyan', |
|
32 |
'pink', 'grey'] |
|
33 |
markers = ['circle', 'dot', 'square', 'triangle', 'triangle_down', 'cross', 'plus', 'circle'] |
|
34 |
||
35 |
||
36 |
#------------------------------------------------------------------------------- |
|
37 |
# Debug Variable Graphic Viewer class |
|
38 |
#------------------------------------------------------------------------------- |
|
39 |
||
632
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
40 |
SECOND = 1000000000 |
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
41 |
MINUTE = 60 * SECOND |
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
42 |
HOUR = 60 * MINUTE |
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
43 |
|
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
44 |
RANGE_VALUES = [(str(25 * 2 ** i), 25 * 2 ** i) for i in xrange(6)] |
640
c32c169b8f63
Fixing segmentation fault in CustomEditableListBox on Windows when clicking on an header button while a value is being edited
laurent
parents:
632
diff
changeset
|
45 |
TIME_RANGE_VALUES = [("%ds" % i, i * SECOND) for i in (1, 2, 5, 10, 20, 30)] + \ |
632
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
46 |
[("%dm" % i, i * MINUTE) for i in (1, 2, 5, 10, 20, 30)] + \ |
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
47 |
[("%dh" % i, i * HOUR) for i in (1, 2, 3, 6, 12, 24)] |
301 | 48 |
|
49 |
[ID_GRAPHICVIEWER, ID_GRAPHICVIEWERCANVAS, |
|
50 |
ID_GRAPHICVIEWERCANVASRANGE, ID_GRAPHICVIEWERCANVASPOSITION, |
|
51 |
ID_GRAPHICVIEWERRESETBUTTON, ID_GRAPHICVIEWERCURRENTBUTTON, |
|
52 |
ID_GRAPHICVIEWERSTATICTEXT1, ID_GRAPHICVIEWERSTATICTEXT2, |
|
53 |
] = [wx.NewId() for _init_ctrls in range(8)] |
|
54 |
||
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
504
diff
changeset
|
55 |
class GraphicViewer(EditorPanel, DebugViewer): |
301 | 56 |
|
57 |
def _init_coll_MainGridSizer_Items(self, parent): |
|
58 |
# generated method, don't edit |
|
59 |
parent.AddWindow(self.Canvas, 0, border=0, flag=wx.GROW) |
|
60 |
parent.AddSizer(self.RangeSizer, 0, border=0, flag=wx.GROW) |
|
61 |
||
62 |
def _init_coll_MainGridSizer_Growables(self, parent): |
|
63 |
# generated method, don't edit |
|
64 |
parent.AddGrowableCol(0) |
|
65 |
parent.AddGrowableRow(0) |
|
66 |
||
67 |
def _init_coll_RangeSizer_Items(self, parent): |
|
68 |
# generated method, don't edit |
|
391 | 69 |
parent.AddWindow(self.staticbox1, 0, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL) |
301 | 70 |
parent.AddWindow(self.CanvasRange, 0, border=5, flag=wx.ALL) |
391 | 71 |
parent.AddWindow(self.staticText2, 0, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL) |
301 | 72 |
parent.AddWindow(self.CanvasPosition, 0, border=5, flag=wx.GROW|wx.ALL) |
73 |
parent.AddWindow(self.ResetButton, 0, border=5, flag=wx.ALL) |
|
74 |
parent.AddWindow(self.CurrentButton, 0, border=5, flag=wx.ALL) |
|
75 |
||
76 |
def _init_coll_RangeSizer_Growables(self, parent): |
|
77 |
# generated method, don't edit |
|
78 |
parent.AddGrowableCol(3) |
|
79 |
parent.AddGrowableRow(0) |
|
80 |
||
81 |
def _init_sizers(self): |
|
82 |
# generated method, don't edit |
|
83 |
self.MainGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
84 |
self.RangeSizer = wx.FlexGridSizer(cols=6, hgap=0, rows=1, vgap=0) |
|
85 |
||
86 |
self._init_coll_MainGridSizer_Items(self.MainGridSizer) |
|
87 |
self._init_coll_MainGridSizer_Growables(self.MainGridSizer) |
|
88 |
self._init_coll_RangeSizer_Items(self.RangeSizer) |
|
89 |
self._init_coll_RangeSizer_Growables(self.RangeSizer) |
|
90 |
||
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
504
diff
changeset
|
91 |
self.Editor.SetSizer(self.MainGridSizer) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
504
diff
changeset
|
92 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
504
diff
changeset
|
93 |
def _init_Editor(self, prnt): |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
504
diff
changeset
|
94 |
self.Editor = wx.Panel(prnt, ID_GRAPHICVIEWER, wx.DefaultPosition, |
301 | 95 |
wx.DefaultSize, 0) |
96 |
||
97 |
self.Canvas = plot.PlotCanvas(id=ID_GRAPHICVIEWERCANVAS, |
|
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
504
diff
changeset
|
98 |
name='Canvas', parent=self.Editor, pos=wx.Point(0, 0), |
301 | 99 |
size=wx.Size(0, 0), style=0) |
100 |
def _axisInterval(spec, lower, upper): |
|
101 |
if spec == 'border': |
|
102 |
if lower == upper: |
|
103 |
return lower - 0.5, upper + 0.5 |
|
104 |
else: |
|
105 |
border = (upper - lower) * 0.05 |
|
106 |
return lower - border, upper + border |
|
107 |
else: |
|
108 |
return plot.PlotCanvas._axisInterval(self.Canvas, spec, lower, upper) |
|
109 |
self.Canvas._axisInterval = _axisInterval |
|
110 |
self.Canvas.SetYSpec('border') |
|
111 |
||
112 |
self.staticbox1 = wx.StaticText(id=ID_GRAPHICVIEWERSTATICTEXT1, |
|
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
504
diff
changeset
|
113 |
label=_('Range:'), name='staticText1', parent=self.Editor, |
391 | 114 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
301 | 115 |
|
116 |
self.CanvasRange = wx.ComboBox(id=ID_GRAPHICVIEWERCANVASRANGE, |
|
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
504
diff
changeset
|
117 |
name='CanvasRange', parent=self.Editor, pos=wx.Point(0, 0), |
640
c32c169b8f63
Fixing segmentation fault in CustomEditableListBox on Windows when clicking on an header button while a value is being edited
laurent
parents:
632
diff
changeset
|
118 |
size=wx.Size(100, 28), style=wx.CB_READONLY) |
301 | 119 |
self.Bind(wx.EVT_COMBOBOX, self.OnRangeChanged, id=ID_GRAPHICVIEWERCANVASRANGE) |
120 |
||
121 |
self.staticText2 = wx.StaticText(id=ID_GRAPHICVIEWERSTATICTEXT2, |
|
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
504
diff
changeset
|
122 |
label=_('Position:'), name='staticText2', parent=self.Editor, |
391 | 123 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
301 | 124 |
|
125 |
self.CanvasPosition = wx.ScrollBar(id=ID_GRAPHICVIEWERCANVASPOSITION, |
|
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
504
diff
changeset
|
126 |
name='Position', parent=self.Editor, pos=wx.Point(0, 0), |
301 | 127 |
size=wx.Size(0, 16), style=wx.SB_HORIZONTAL) |
128 |
self.CanvasPosition.SetScrollbar(0, 10, 100, 10) |
|
129 |
self.CanvasPosition.Bind(wx.EVT_SCROLL_THUMBTRACK, self.OnPositionChanging, |
|
130 |
id = ID_GRAPHICVIEWERCANVASPOSITION) |
|
131 |
self.CanvasPosition.Bind(wx.EVT_SCROLL_LINEUP, self.OnPositionChanging, |
|
132 |
id = ID_GRAPHICVIEWERCANVASPOSITION) |
|
133 |
self.CanvasPosition.Bind(wx.EVT_SCROLL_LINEDOWN, self.OnPositionChanging, |
|
134 |
id = ID_GRAPHICVIEWERCANVASPOSITION) |
|
135 |
self.CanvasPosition.Bind(wx.EVT_SCROLL_PAGEUP, self.OnPositionChanging, |
|
136 |
id = ID_GRAPHICVIEWERCANVASPOSITION) |
|
137 |
self.CanvasPosition.Bind(wx.EVT_SCROLL_PAGEDOWN, self.OnPositionChanging, |
|
138 |
id = ID_GRAPHICVIEWERCANVASPOSITION) |
|
139 |
||
140 |
self.ResetButton = wx.Button(id=ID_GRAPHICVIEWERRESETBUTTON, label='Reset', |
|
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
504
diff
changeset
|
141 |
name='ResetButton', parent=self.Editor, pos=wx.Point(0, 0), |
301 | 142 |
size=wx.Size(72, 24), style=0) |
143 |
self.Bind(wx.EVT_BUTTON, self.OnResetButton, id=ID_GRAPHICVIEWERRESETBUTTON) |
|
144 |
||
145 |
self.CurrentButton = wx.Button(id=ID_GRAPHICVIEWERCURRENTBUTTON, label='Current', |
|
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
504
diff
changeset
|
146 |
name='CurrentButton', parent=self.Editor, pos=wx.Point(0, 0), |
301 | 147 |
size=wx.Size(72, 24), style=0) |
148 |
self.Bind(wx.EVT_BUTTON, self.OnCurrentButton, id=ID_GRAPHICVIEWERCURRENTBUTTON) |
|
149 |
||
150 |
self._init_sizers() |
|
151 |
||
415
d3d8f8f0b678
controler (PLCControler) and debug data producer (PluginsRoot) are no longer the same thing
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
152 |
def __init__(self, parent, window, producer, instancepath = ""): |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
504
diff
changeset
|
153 |
EditorPanel.__init__(self, parent, "", window, None) |
415
d3d8f8f0b678
controler (PLCControler) and debug data producer (PluginsRoot) are no longer the same thing
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
154 |
DebugViewer.__init__(self, producer, True, False) |
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
344
diff
changeset
|
155 |
|
301 | 156 |
self.InstancePath = instancepath |
632
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
157 |
self.RangeValues = None |
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
158 |
|
301 | 159 |
self.Datas = [] |
642
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
160 |
self.StartValue = 0 |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
161 |
self.EndValue = 0 |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
162 |
self.Fixed = False |
632
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
163 |
self.Ticktime = self.DataProducer.GetTicktime() |
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
164 |
self.RefreshCanvasRange() |
301 | 165 |
|
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
344
diff
changeset
|
166 |
self.AddDataConsumer(self.InstancePath.upper(), self) |
301 | 167 |
|
338 | 168 |
def __del__(self): |
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
344
diff
changeset
|
169 |
DebugViewer.__del__(self) |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
344
diff
changeset
|
170 |
self.RemoveDataConsumer(self) |
338 | 171 |
|
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
504
diff
changeset
|
172 |
def GetTitle(self): |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
504
diff
changeset
|
173 |
if len(self.InstancePath) > 15: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
504
diff
changeset
|
174 |
return "..." + self.InstancePath[-12:] |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
504
diff
changeset
|
175 |
return self.InstancePath |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
504
diff
changeset
|
176 |
|
338 | 177 |
def ResetView(self): |
178 |
self.Datas = [] |
|
642
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
179 |
self.StartValue = 0 |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
180 |
self.EndValue = 0 |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
181 |
self.Fixed = False |
632
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
182 |
self.Ticktime = self.DataProducer.GetTicktime() |
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
183 |
self.RefreshCanvasRange() |
338 | 184 |
self.RefreshView() |
185 |
||
642
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
186 |
def RefreshNewData(self, *args, **kwargs): |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
187 |
self.RefreshView(*args, **kwargs) |
374 | 188 |
DebugViewer.RefreshNewData(self) |
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
344
diff
changeset
|
189 |
|
632
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
190 |
def RefreshCanvasRange(self): |
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
191 |
if self.Ticktime == 0 and self.RangeValues != RANGE_VALUES: |
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
192 |
self.RangeValues = RANGE_VALUES |
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
193 |
self.RangeValues_dict = dict(RANGE_VALUES) |
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
194 |
self.CanvasRange.Clear() |
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
195 |
for text, value in RANGE_VALUES: |
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
196 |
self.CanvasRange.Append(text) |
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
197 |
self.CanvasRange.SetStringSelection(RANGE_VALUES[0][0]) |
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
198 |
self.CurrentRange = RANGE_VALUES[0][1] |
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
199 |
elif self.RangeValues != TIME_RANGE_VALUES: |
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
200 |
self.RangeValues = TIME_RANGE_VALUES |
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
201 |
self.RangeValues_dict = dict(TIME_RANGE_VALUES) |
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
202 |
self.CanvasRange.Clear() |
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
203 |
for text, value in TIME_RANGE_VALUES: |
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
204 |
self.CanvasRange.Append(text) |
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
205 |
self.CanvasRange.SetStringSelection(TIME_RANGE_VALUES[0][0]) |
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
206 |
self.CurrentRange = TIME_RANGE_VALUES[0][1] / self.Ticktime |
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
207 |
|
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
344
diff
changeset
|
208 |
def RefreshView(self, force=True): |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
344
diff
changeset
|
209 |
self.Freeze() |
642
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
210 |
if force or not self.Fixed: |
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
344
diff
changeset
|
211 |
var_name = self.InstancePath.split(".")[-1] |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
344
diff
changeset
|
212 |
|
642
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
213 |
self.VariableGraphic = plot.PolyLine(self.Datas[self.StartValue:self.EndValue + 1], |
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
344
diff
changeset
|
214 |
legend=var_name, colour=colours[0]) |
391 | 215 |
self.GraphicsObject = plot.PlotGraphics([self.VariableGraphic], _("%s Graphics") % var_name, _("Tick"), _("Values")) |
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
344
diff
changeset
|
216 |
datas_length = len(self.Datas) |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
344
diff
changeset
|
217 |
if datas_length > 1: |
642
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
218 |
start = self.Datas[self.StartValue][0] |
301 | 219 |
else: |
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
344
diff
changeset
|
220 |
start = 0. |
642
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
221 |
self.Canvas.Draw(self.GraphicsObject, xAxis=(start, start + self.CurrentRange)) |
301 | 222 |
self.RefreshScrollBar() |
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
344
diff
changeset
|
223 |
self.Thaw() |
326 | 224 |
|
301 | 225 |
def GetInstancePath(self): |
226 |
return self.InstancePath |
|
227 |
||
326 | 228 |
def IsViewing(self, tagname): |
229 |
return self.InstancePath == tagname |
|
230 |
||
642
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
231 |
def GetNearestData(self, tick, adjust): |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
232 |
ticks = numpy.array(zip(*self.Datas)[0]) |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
233 |
new_cursor = numpy.argmin(abs(ticks - tick)) |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
234 |
if adjust == -1 and ticks[new_cursor] > tick and new_cursor > 0: |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
235 |
new_cursor -= 1 |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
236 |
elif adjust == 1 and ticks[new_cursor] < tick and new_cursor < len(self.Datas): |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
237 |
new_cursor += 1 |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
238 |
return new_cursor |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
239 |
|
504 | 240 |
def NewValue(self, tick, value, forced=False): |
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
344
diff
changeset
|
241 |
self.Datas.append((float(tick), {True:1., False:0.}.get(value, float(value)))) |
642
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
242 |
if not self.Fixed: |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
243 |
while int(self.Datas[self.StartValue][0]) < tick - self.CurrentRange: |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
244 |
self.StartValue += 1 |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
245 |
self.EndValue += 1 |
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
344
diff
changeset
|
246 |
self.NewDataAvailable() |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
344
diff
changeset
|
247 |
|
301 | 248 |
def RefreshScrollBar(self): |
642
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
249 |
if len(self.Datas) > 0: |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
250 |
pos = int(self.Datas[self.StartValue][0] - self.Datas[0][0]) |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
251 |
range = int(self.Datas[-1][0] - self.Datas[0][0]) |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
252 |
else: |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
253 |
pos = 0 |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
254 |
range = 0 |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
255 |
self.CanvasPosition.SetScrollbar(pos, self.CurrentRange, range, self.CurrentRange) |
301 | 256 |
|
257 |
def OnRangeChanged(self, event): |
|
258 |
old_range = self.CurrentRange |
|
259 |
try: |
|
632
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
260 |
if self.Ticktime == 0: |
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
261 |
self.CurrentRange = self.RangeValues_dict[self.CanvasRange.GetValue()] |
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
262 |
else: |
3ea55a5db68e
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents:
586
diff
changeset
|
263 |
self.CurrentRange = self.RangeValues_dict[self.CanvasRange.GetValue()] / self.Ticktime |
301 | 264 |
except ValueError, e: |
265 |
self.CanvasRange.SetValue(str(self.CurrentRange)) |
|
648
95d165193770
Fix bug in GraphicViewer when changing range while no data received
laurent
parents:
642
diff
changeset
|
266 |
if len(self.Datas) > 0: |
95d165193770
Fix bug in GraphicViewer when changing range while no data received
laurent
parents:
642
diff
changeset
|
267 |
if self.Fixed and self.Datas[-1][0] - self.Datas[0][0] < self.CurrentRange: |
95d165193770
Fix bug in GraphicViewer when changing range while no data received
laurent
parents:
642
diff
changeset
|
268 |
self.Fixed = False |
95d165193770
Fix bug in GraphicViewer when changing range while no data received
laurent
parents:
642
diff
changeset
|
269 |
if self.Fixed: |
95d165193770
Fix bug in GraphicViewer when changing range while no data received
laurent
parents:
642
diff
changeset
|
270 |
self.StartValue = min(self.StartValue, self.GetNearestData(self.Datas[-1][0] - self.CurrentRange, -1)) |
95d165193770
Fix bug in GraphicViewer when changing range while no data received
laurent
parents:
642
diff
changeset
|
271 |
self.EndValue = self.GetNearestData(self.StartValue + self.CurrentRange, 1) |
95d165193770
Fix bug in GraphicViewer when changing range while no data received
laurent
parents:
642
diff
changeset
|
272 |
else: |
95d165193770
Fix bug in GraphicViewer when changing range while no data received
laurent
parents:
642
diff
changeset
|
273 |
self.StartValue = self.GetNearestData(self.Datas[-1][0] - self.CurrentRange - 1, -1) |
95d165193770
Fix bug in GraphicViewer when changing range while no data received
laurent
parents:
642
diff
changeset
|
274 |
self.EndValue = len(self.Datas) - 1 |
642
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
275 |
self.NewDataAvailable(True) |
301 | 276 |
event.Skip() |
277 |
||
278 |
def OnPositionChanging(self, event): |
|
642
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
279 |
self.StartValue = self.GetNearestData(self.Datas[0][0] + event.GetPosition(), -1) |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
280 |
self.EndValue = self.GetNearestData(self.Datas[self.StartValue][0] + self.CurrentRange, 1) |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
281 |
self.Fixed = True |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
282 |
self.NewDataAvailable(True) |
301 | 283 |
event.Skip() |
284 |
||
285 |
def OnResetButton(self, event): |
|
642
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
286 |
self.Fixed = False |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
287 |
self.ResteView() |
301 | 288 |
event.Skip() |
289 |
||
290 |
def OnCurrentButton(self, event): |
|
642
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
291 |
self.StartValue = self.GetNearestData(self.Datas[-1][0] - self.CurrentRange, -1) |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
292 |
self.EndValue = self.GetNearestData(self.Datas[self.StartValue][0] + self.CurrentRange, 1) |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
293 |
self.Fixed = False |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
294 |
self.NewDataAvailable(True) |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
295 |
event.Skip() |
f2325ebd67f4
Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents:
640
diff
changeset
|
296 |