author | Edouard Tisserant |
Wed, 31 Jul 2013 10:45:07 +0900 | |
branch | 1.1 Korean release |
changeset 1280 | 72a826dfcfbb |
parent 1267 | fae0809eae98 |
child 1362 | 077bcba2d485 |
permissions | -rw-r--r-- |
814 | 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) 2012: 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 |
||
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
25 |
from types import TupleType |
887
d3c6c4ab8b28
Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents:
878
diff
changeset
|
26 |
from time import time as gettime |
d3c6c4ab8b28
Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents:
878
diff
changeset
|
27 |
import numpy |
814 | 28 |
|
29 |
import wx |
|
888
baf5dbfd28f4
Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents:
887
diff
changeset
|
30 |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
31 |
import matplotlib |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
32 |
matplotlib.use('WX') |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
33 |
import matplotlib.pyplot |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
34 |
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
35 |
from matplotlib.backends.backend_wxagg import _convert_agg_to_wx_bitmap |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
36 |
from matplotlib.backends.backend_agg import FigureCanvasAgg |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
37 |
from mpl_toolkits.mplot3d import Axes3D |
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
38 |
|
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
39 |
from editors.DebugViewer import REFRESH_PERIOD |
814 | 40 |
|
1199
fc0e7d80494f
Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents:
1198
diff
changeset
|
41 |
from DebugVariableItem import DebugVariableItem |
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
42 |
from DebugVariableViewer import * |
1199
fc0e7d80494f
Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents:
1198
diff
changeset
|
43 |
from GraphButton import GraphButton |
fc0e7d80494f
Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents:
1198
diff
changeset
|
44 |
|
1209 | 45 |
# Graph variable display type |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
46 |
GRAPH_PARALLEL, GRAPH_ORTHOGONAL = range(2) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
47 |
|
1209 | 48 |
# Canvas height |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
49 |
[SIZE_MINI, SIZE_MIDDLE, SIZE_MAXI] = [0, 100, 200] |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
50 |
|
1209 | 51 |
CANVAS_BORDER = (20., 10.) # Border height on at bottom and top of graph |
52 |
CANVAS_PADDING = 8.5 # Border inside graph where no label is drawn |
|
53 |
VALUE_LABEL_HEIGHT = 17. # Height of variable label in graph |
|
54 |
AXES_LABEL_HEIGHT = 12.75 # Height of variable value in graph |
|
55 |
||
56 |
# Colors used cyclically for graph curves |
|
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
57 |
COLOR_CYCLE = ['r', 'b', 'g', 'm', 'y', 'k'] |
1209 | 58 |
# Color for graph cursor |
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
59 |
CURSOR_COLOR = '#800080' |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
60 |
|
1209 | 61 |
#------------------------------------------------------------------------------- |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
62 |
# Debug Variable Graphic Viewer Helpers |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
63 |
#------------------------------------------------------------------------------- |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
64 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
65 |
def merge_ranges(ranges): |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
66 |
""" |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
67 |
Merge variables data range in a list to return a range of minimal min range |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
68 |
value and maximal max range value extended of 10% for keeping a padding |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
69 |
around graph in canvas |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
70 |
@param ranges: [(range_min_value, range_max_value),...] |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
71 |
@return: merged_range_min_value, merged_range_max_value |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
72 |
""" |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
73 |
# Get minimal and maximal range value |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
74 |
min_value = max_value = None |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
75 |
for range_min, range_max in ranges: |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
76 |
# Update minimal range value |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
77 |
if min_value is None: |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
78 |
min_value = range_min |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
79 |
elif range_min is not None: |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
80 |
min_value = min(min_value, range_min) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
81 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
82 |
# Update maximal range value |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
83 |
if max_value is None: |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
84 |
max_value = range_max |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
85 |
elif range_min is not None: |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
86 |
max_value = max(max_value, range_max) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
87 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
88 |
# Calculate range center and width if at least one valid range is defined |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
89 |
if min_value is not None and max_value is not None: |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
90 |
center = (min_value + max_value) / 2. |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
91 |
range_size = max(1.0, max_value - min_value) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
92 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
93 |
# Set default center and with if no valid range is defined |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
94 |
else: |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
95 |
center = 0.5 |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
96 |
range_size = 1.0 |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
97 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
98 |
# Return range expended from 10 % |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
99 |
return center - range_size * 0.55, center + range_size * 0.55 |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
100 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
101 |
#------------------------------------------------------------------------------- |
1209 | 102 |
# Debug Variable Graphic Viewer Drop Target |
103 |
#------------------------------------------------------------------------------- |
|
104 |
||
105 |
""" |
|
1215 | 106 |
Class that implements a custom drop target class for Debug Variable Graphic |
107 |
Viewer |
|
1209 | 108 |
""" |
109 |
||
110 |
class DebugVariableGraphicDropTarget(wx.TextDropTarget): |
|
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
111 |
|
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
112 |
def __init__(self, parent, window): |
1209 | 113 |
""" |
114 |
Constructor |
|
115 |
@param parent: Reference to Debug Variable Graphic Viewer |
|
116 |
@param window: Reference to the Debug Variable Panel |
|
117 |
""" |
|
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
118 |
wx.TextDropTarget.__init__(self) |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
119 |
self.ParentControl = parent |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
120 |
self.ParentWindow = window |
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
121 |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
122 |
def __del__(self): |
1209 | 123 |
""" |
124 |
Destructor |
|
125 |
""" |
|
126 |
# Remove reference to Debug Variable Graphic Viewer and Debug Variable |
|
127 |
# Panel |
|
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
128 |
self.ParentControl = None |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
129 |
self.ParentWindow = None |
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
130 |
|
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
131 |
def OnDragOver(self, x, y, d): |
1209 | 132 |
""" |
133 |
Function called when mouse is dragged over Drop Target |
|
134 |
@param x: X coordinate of mouse pointer |
|
135 |
@param y: Y coordinate of mouse pointer |
|
136 |
@param d: Suggested default for return value |
|
137 |
""" |
|
138 |
# Signal parent that mouse is dragged over |
|
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
139 |
self.ParentControl.OnMouseDragging(x, y) |
1209 | 140 |
|
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
141 |
return wx.TextDropTarget.OnDragOver(self, x, y, d) |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
142 |
|
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
143 |
def OnDropText(self, x, y, data): |
1209 | 144 |
""" |
1215 | 145 |
Function called when mouse is released in Drop Target |
1209 | 146 |
@param x: X coordinate of mouse pointer |
147 |
@param y: Y coordinate of mouse pointer |
|
148 |
@param data: Text associated to drag'n drop |
|
149 |
""" |
|
1218 | 150 |
# Signal Debug Variable Panel to reset highlight |
151 |
self.ParentWindow.ResetHighlight() |
|
152 |
||
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
153 |
message = None |
1209 | 154 |
|
155 |
# Check that data is valid regarding DebugVariablePanel |
|
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
156 |
try: |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
157 |
values = eval(data) |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
158 |
if not isinstance(values, TupleType): |
1207 | 159 |
raise ValueError |
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
160 |
except: |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
161 |
message = _("Invalid value \"%s\" for debug variable")%data |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
162 |
values = None |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
163 |
|
1209 | 164 |
# Display message if data is invalid |
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
165 |
if message is not None: |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
166 |
wx.CallAfter(self.ShowMessage, message) |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
167 |
|
1209 | 168 |
# Data contain a reference to a variable to debug |
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
169 |
elif values[1] == "debug": |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
170 |
target_idx = self.ParentControl.GetIndex() |
1209 | 171 |
|
172 |
# If mouse is dropped in graph canvas bounding box and graph is |
|
173 |
# not 3D canvas, graphs will be merged |
|
174 |
rect = self.ParentControl.GetAxesBoundingBox() |
|
175 |
if not self.ParentControl.Is3DCanvas() and rect.InsideXY(x, y): |
|
176 |
# Default merge type is parallel |
|
177 |
merge_type = GRAPH_PARALLEL |
|
178 |
||
179 |
# If mouse is dropped in left part of graph canvas, graph |
|
180 |
# wall be merged orthogonally |
|
181 |
merge_rect = wx.Rect(rect.x, rect.y, |
|
182 |
rect.width / 2., rect.height) |
|
183 |
if merge_rect.InsideXY(x, y): |
|
184 |
merge_type = GRAPH_ORTHOGONAL |
|
185 |
||
186 |
# Merge graphs |
|
187 |
wx.CallAfter(self.ParentWindow.MergeGraphs, |
|
188 |
values[0], target_idx, |
|
189 |
merge_type, force=True) |
|
190 |
||
191 |
else: |
|
192 |
width, height = self.ParentControl.GetSize() |
|
193 |
||
194 |
# Get Before which Viewer the variable has to be moved or added |
|
195 |
# according to the position of mouse in Viewer. |
|
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
196 |
if y > height / 2: |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
197 |
target_idx += 1 |
1209 | 198 |
|
199 |
# Drag'n Drop is an internal is an internal move inside Debug |
|
200 |
# Variable Panel |
|
201 |
if len(values) > 2 and values[2] == "move": |
|
202 |
self.ParentWindow.MoveValue(values[0], |
|
203 |
target_idx) |
|
204 |
||
205 |
# Drag'n Drop was initiated by another control of Beremiz |
|
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
206 |
else: |
1209 | 207 |
self.ParentWindow.InsertValue(values[0], |
208 |
target_idx, |
|
209 |
force=True) |
|
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
210 |
|
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
211 |
def OnLeave(self): |
1209 | 212 |
""" |
213 |
Function called when mouse is leave Drop Target |
|
214 |
""" |
|
215 |
# Signal Debug Variable Panel to reset highlight |
|
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
216 |
self.ParentWindow.ResetHighlight() |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
217 |
return wx.TextDropTarget.OnLeave(self) |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
218 |
|
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
219 |
def ShowMessage(self, message): |
1209 | 220 |
""" |
221 |
Show error message in Error Dialog |
|
222 |
@param message: Error message to display |
|
223 |
""" |
|
1227
01e86190f8c7
Fixed tick not refreshed when in DebugVariablePanel when variable in it
Laurent Bessard
parents:
1218
diff
changeset
|
224 |
dialog = wx.MessageDialog(self.ParentWindow, |
01e86190f8c7
Fixed tick not refreshed when in DebugVariablePanel when variable in it
Laurent Bessard
parents:
1218
diff
changeset
|
225 |
message, |
01e86190f8c7
Fixed tick not refreshed when in DebugVariablePanel when variable in it
Laurent Bessard
parents:
1218
diff
changeset
|
226 |
_("Error"), |
01e86190f8c7
Fixed tick not refreshed when in DebugVariablePanel when variable in it
Laurent Bessard
parents:
1218
diff
changeset
|
227 |
wx.OK|wx.ICON_ERROR) |
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
228 |
dialog.ShowModal() |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
229 |
dialog.Destroy() |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
230 |
|
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
231 |
|
1209 | 232 |
#------------------------------------------------------------------------------- |
233 |
# Debug Variable Graphic Viewer Class |
|
234 |
#------------------------------------------------------------------------------- |
|
235 |
||
236 |
""" |
|
237 |
Class that implements a Viewer that display variable values as a graphs |
|
238 |
""" |
|
239 |
||
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
240 |
class DebugVariableGraphicViewer(DebugVariableViewer, FigureCanvas): |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
241 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
242 |
def __init__(self, parent, window, items, graph_type): |
1209 | 243 |
""" |
244 |
Constructor |
|
245 |
@param parent: Parent wx.Window of DebugVariableText |
|
246 |
@param window: Reference to the Debug Variable Panel |
|
247 |
@param items: List of DebugVariableItem displayed by Viewer |
|
248 |
@param graph_type: Graph display type (Parallel or orthogonal) |
|
249 |
""" |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
250 |
DebugVariableViewer.__init__(self, window, items) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
251 |
|
1209 | 252 |
self.GraphType = graph_type # Graph type display |
253 |
self.CursorTick = None # Tick of the graph cursor |
|
254 |
||
255 |
# Mouse position when start dragging |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
256 |
self.MouseStartPos = None |
1209 | 257 |
# Tick when moving tick start |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
258 |
self.StartCursorTick = None |
1209 | 259 |
# Canvas size when starting to resize canvas |
260 |
self.CanvasStartSize = None |
|
261 |
||
262 |
# List of current displayed contextual buttons |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
263 |
self.ContextualButtons = [] |
1209 | 264 |
# Reference to item for which contextual buttons was displayed |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
265 |
self.ContextualButtonsItem = None |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
266 |
|
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
267 |
# Flag indicating that zoom fit current displayed data range or whole |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
268 |
# data range if False |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
269 |
self.ZoomFit = False |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
270 |
|
1209 | 271 |
# Create figure for drawing graphs |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
272 |
self.Figure = matplotlib.figure.Figure(facecolor='w') |
1209 | 273 |
# Defined border around figure in canvas |
274 |
self.Figure.subplotpars.update(top=0.95, left=0.1, |
|
275 |
bottom=0.1, right=0.95) |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
276 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
277 |
FigureCanvas.__init__(self, parent, -1, self.Figure) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
278 |
self.SetWindowStyle(wx.WANTS_CHARS) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
279 |
self.SetBackgroundColour(wx.WHITE) |
1209 | 280 |
|
281 |
# Bind wx events |
|
1214
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
282 |
self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick) |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
283 |
self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
284 |
self.Bind(wx.EVT_ENTER_WINDOW, self.OnEnter) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
285 |
self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
286 |
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
287 |
self.Bind(wx.EVT_SIZE, self.OnResize) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
288 |
|
1209 | 289 |
# Set canvas min size |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
290 |
canvas_size = self.GetCanvasMinSize() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
291 |
self.SetMinSize(canvas_size) |
1209 | 292 |
|
293 |
# Define Viewer drop target |
|
294 |
self.SetDropTarget(DebugVariableGraphicDropTarget(self, window)) |
|
295 |
||
296 |
# Connect matplotlib events |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
297 |
self.mpl_connect('button_press_event', self.OnCanvasButtonPressed) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
298 |
self.mpl_connect('motion_notify_event', self.OnCanvasMotion) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
299 |
self.mpl_connect('button_release_event', self.OnCanvasButtonReleased) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
300 |
self.mpl_connect('scroll_event', self.OnCanvasScroll) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
301 |
|
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
302 |
# Add buttons for zooming on current displayed data range |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
303 |
self.Buttons.append( |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
304 |
GraphButton(0, 0, "fit_graph", self.OnZoomFitButton)) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
305 |
|
1209 | 306 |
# Add buttons for changing canvas size with predefined height |
307 |
for size, bitmap in zip( |
|
308 |
[SIZE_MINI, SIZE_MIDDLE, SIZE_MAXI], |
|
309 |
["minimize_graph", "middle_graph", "maximize_graph"]): |
|
310 |
self.Buttons.append( |
|
311 |
GraphButton(0, 0, bitmap, |
|
312 |
self.GetOnChangeSizeButton(size))) |
|
313 |
||
314 |
# Add buttons for exporting graph values to clipboard and close graph |
|
315 |
for bitmap, callback in [ |
|
316 |
("export_graph_mini", self.OnExportGraphButton), |
|
317 |
("delete_graph", self.OnCloseButton)]: |
|
1199
fc0e7d80494f
Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents:
1198
diff
changeset
|
318 |
self.Buttons.append(GraphButton(0, 0, bitmap, callback)) |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
319 |
|
1209 | 320 |
# Update graphs elements |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
321 |
self.ResetGraphics() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
322 |
self.RefreshLabelsPosition(canvas_size.height) |
1209 | 323 |
|
324 |
def AddItem(self, item): |
|
325 |
""" |
|
326 |
Add an item to the list of items displayed by Viewer |
|
327 |
@param item: Item to add to the list |
|
328 |
""" |
|
329 |
DebugVariableViewer.AddItem(self, item) |
|
330 |
self.ResetGraphics() |
|
331 |
||
332 |
def RemoveItem(self, item): |
|
333 |
""" |
|
334 |
Remove an item from the list of items displayed by Viewer |
|
335 |
@param item: Item to remove from the list |
|
336 |
""" |
|
337 |
DebugVariableViewer.RemoveItem(self, item) |
|
338 |
||
339 |
# If list of items is not empty |
|
340 |
if not self.ItemsIsEmpty(): |
|
341 |
# Return to parallel graph if there is only one item |
|
342 |
# especially if it's actually orthogonal |
|
343 |
if len(self.Items) == 1: |
|
344 |
self.GraphType = GRAPH_PARALLEL |
|
345 |
self.ResetGraphics() |
|
346 |
||
1212 | 347 |
def SetCursorTick(self, cursor_tick): |
348 |
""" |
|
349 |
Set cursor tick |
|
350 |
@param cursor_tick: Cursor tick |
|
351 |
""" |
|
352 |
self.CursorTick = cursor_tick |
|
353 |
||
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
354 |
def SetZoomFit(self, zoom_fit): |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
355 |
""" |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
356 |
Set flag indicating that zoom fit current displayed data range |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
357 |
@param zoom_fit: Flag for zoom fit (False: zoom fit whole data range) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
358 |
""" |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
359 |
# Flag is different from the actual one |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
360 |
if zoom_fit != self.ZoomFit: |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
361 |
# Save new flag value |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
362 |
self.ZoomFit = zoom_fit |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
363 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
364 |
# Update button for zoom fit bitmap |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
365 |
self.Buttons[0].SetBitmap("full_graph" if zoom_fit else "fit_graph") |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
366 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
367 |
# Refresh canvas |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
368 |
self.RefreshViewer() |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
369 |
|
1209 | 370 |
def SubscribeAllDataConsumers(self): |
371 |
""" |
|
372 |
Function that unsubscribe and remove every item that store values of |
|
373 |
a variable that doesn't exist in PLC anymore |
|
374 |
""" |
|
375 |
DebugVariableViewer.SubscribeAllDataConsumers(self) |
|
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
376 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
377 |
# Graph still have data to display |
1209 | 378 |
if not self.ItemsIsEmpty(): |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
379 |
# Reset flag indicating that zoom fit current displayed data range |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
380 |
self.SetZoomFit(False) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
381 |
|
1209 | 382 |
self.ResetGraphics() |
383 |
||
384 |
def Is3DCanvas(self): |
|
385 |
""" |
|
386 |
Return if Viewer is a 3D canvas |
|
387 |
@return: True if Viewer is a 3D canvas |
|
388 |
""" |
|
389 |
return self.GraphType == GRAPH_ORTHOGONAL and len(self.Items) == 3 |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
390 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
391 |
def GetButtons(self): |
1209 | 392 |
""" |
393 |
Return list of buttons defined in Viewer |
|
394 |
@return: List of buttons |
|
395 |
""" |
|
396 |
# Add contextual buttons to default buttons |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
397 |
return self.Buttons + self.ContextualButtons |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
398 |
|
1209 | 399 |
def PopupContextualButtons(self, item, rect, direction=wx.RIGHT): |
400 |
""" |
|
401 |
Show contextual menu for item aside a label of this item defined |
|
402 |
by the bounding box of label in figure |
|
403 |
@param item: Item for which contextual is shown |
|
404 |
@param rect: Bounding box of label aside which drawing menu |
|
405 |
@param direction: Direction in which buttons must be drawn |
|
406 |
""" |
|
407 |
# Return immediately if contextual menu for item is already shown |
|
408 |
if self.ContextualButtonsItem == item: |
|
409 |
return |
|
410 |
||
411 |
# Close already shown contextual menu |
|
412 |
self.DismissContextualButtons() |
|
413 |
||
414 |
# Save item for which contextual menu is shown |
|
415 |
self.ContextualButtonsItem = item |
|
416 |
||
417 |
# If item variable is forced, add button for release variable to |
|
418 |
# contextual menu |
|
419 |
if self.ContextualButtonsItem.IsForced(): |
|
420 |
self.ContextualButtons.append( |
|
421 |
GraphButton(0, 0, "release", self.OnReleaseItemButton)) |
|
422 |
||
423 |
# Add other buttons to contextual menu |
|
424 |
for bitmap, callback in [ |
|
425 |
("force", self.OnForceItemButton), |
|
426 |
("export_graph_mini", self.OnExportItemGraphButton), |
|
427 |
("delete_graph", self.OnRemoveItemButton)]: |
|
428 |
self.ContextualButtons.append( |
|
429 |
GraphButton(0, 0, bitmap, callback)) |
|
430 |
||
431 |
# If buttons are shown at left side or upper side of rect, positions |
|
432 |
# will be set in reverse order |
|
433 |
buttons = self.ContextualButtons[:] |
|
434 |
if direction in [wx.TOP, wx.LEFT]: |
|
435 |
buttons.reverse() |
|
436 |
||
437 |
# Set contextual menu buttons position aside rect depending on |
|
438 |
# direction given |
|
439 |
offset = 0 |
|
440 |
for button in buttons: |
|
441 |
w, h = button.GetSize() |
|
442 |
if direction in [wx.LEFT, wx.RIGHT]: |
|
443 |
x = rect.x + (- w - offset |
|
444 |
if direction == wx.LEFT |
|
445 |
else rect.width + offset) |
|
446 |
y = rect.y + (rect.height - h) / 2 |
|
447 |
offset += w |
|
448 |
else: |
|
449 |
x = rect.x + (rect.width - w ) / 2 |
|
450 |
y = rect.y + (- h - offset |
|
451 |
if direction == wx.TOP |
|
452 |
else rect.height + offset) |
|
453 |
offset += h |
|
454 |
button.SetPosition(x, y) |
|
455 |
button.Show() |
|
456 |
||
457 |
# Refresh canvas |
|
458 |
self.ParentWindow.ForceRefresh() |
|
459 |
||
460 |
def DismissContextualButtons(self): |
|
461 |
""" |
|
462 |
Close current shown contextual menu |
|
463 |
""" |
|
464 |
# Return immediately if no contextual menu is shown |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
465 |
if self.ContextualButtonsItem is None: |
1209 | 466 |
return |
467 |
||
468 |
# Reset variables corresponding to contextual menu |
|
469 |
self.ContextualButtonsItem = None |
|
470 |
self.ContextualButtons = [] |
|
471 |
||
472 |
# Refresh canvas |
|
473 |
self.ParentWindow.ForceRefresh() |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
474 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
475 |
def IsOverContextualButton(self, x, y): |
1209 | 476 |
""" |
477 |
Return if point is over one contextual button of Viewer |
|
478 |
@param x: X coordinate of point |
|
479 |
@param y: Y coordinate of point |
|
480 |
@return: contextual button where point is over |
|
481 |
""" |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
482 |
for button in self.ContextualButtons: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
483 |
if button.HitTest(x, y): |
1209 | 484 |
return button |
485 |
return None |
|
486 |
||
487 |
def ExportGraph(self, item=None): |
|
488 |
""" |
|
489 |
Export item(s) data to clipboard in CSV format |
|
490 |
@param item: Item from which data to export, all items if None |
|
491 |
(default None) |
|
492 |
""" |
|
493 |
self.ParentWindow.CopyDataToClipboard( |
|
494 |
[(item, [entry for entry in item.GetData()]) |
|
495 |
for item in (self.Items |
|
496 |
if item is None |
|
497 |
else [item])]) |
|
498 |
||
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
499 |
def OnZoomFitButton(self): |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
500 |
""" |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
501 |
Function called when Viewer Zoom Fit button is pressed |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
502 |
""" |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
503 |
# Toggle zoom fit flag value |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
504 |
self.SetZoomFit(not self.ZoomFit) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
505 |
|
1209 | 506 |
def GetOnChangeSizeButton(self, height): |
507 |
""" |
|
508 |
Function that generate callback function for change Viewer height to |
|
509 |
pre-defined height button |
|
510 |
@param height: Height that change Viewer to |
|
511 |
@return: callback function |
|
512 |
""" |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
513 |
def OnChangeSizeButton(): |
1264 | 514 |
self.SetCanvasHeight(height) |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
515 |
return OnChangeSizeButton |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
516 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
517 |
def OnExportGraphButton(self): |
1209 | 518 |
""" |
519 |
Function called when Viewer Export button is pressed |
|
520 |
""" |
|
521 |
# Export data of every item in Viewer |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
522 |
self.ExportGraph() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
523 |
|
1209 | 524 |
def OnForceItemButton(self): |
525 |
""" |
|
526 |
Function called when contextual menu Force button is pressed |
|
527 |
""" |
|
528 |
# Open dialog for forcing item variable value |
|
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
529 |
self.ForceValue(self.ContextualButtonsItem) |
1209 | 530 |
# Close contextual menu |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
531 |
self.DismissContextualButtons() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
532 |
|
1209 | 533 |
def OnReleaseItemButton(self): |
534 |
""" |
|
535 |
Function called when contextual menu Release button is pressed |
|
536 |
""" |
|
537 |
# Release item variable value |
|
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
538 |
self.ReleaseValue(self.ContextualButtonsItem) |
1209 | 539 |
# Close contextual menu |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
540 |
self.DismissContextualButtons() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
541 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
542 |
def OnExportItemGraphButton(self): |
1209 | 543 |
""" |
544 |
Function called when contextual menu Export button is pressed |
|
545 |
""" |
|
546 |
# Export data of item variable |
|
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
547 |
self.ExportGraph(self.ContextualButtonsItem) |
1209 | 548 |
# Close contextual menu |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
549 |
self.DismissContextualButtons() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
550 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
551 |
def OnRemoveItemButton(self): |
1209 | 552 |
""" |
553 |
Function called when contextual menu Remove button is pressed |
|
554 |
""" |
|
555 |
# Remove item from Viewer |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
556 |
wx.CallAfter(self.ParentWindow.DeleteValue, self, |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
557 |
self.ContextualButtonsItem) |
1209 | 558 |
# Close contextual menu |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
559 |
self.DismissContextualButtons() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
560 |
|
1209 | 561 |
def HandleCursorMove(self, event): |
1212 | 562 |
""" |
563 |
Update Cursor position according to mouse position and graph type |
|
564 |
@param event: Mouse event |
|
565 |
""" |
|
1209 | 566 |
start_tick, end_tick = self.ParentWindow.GetRange() |
567 |
cursor_tick = None |
|
568 |
items = self.ItemsDict.values() |
|
1212 | 569 |
|
570 |
# Graph is orthogonal |
|
1209 | 571 |
if self.GraphType == GRAPH_ORTHOGONAL: |
1212 | 572 |
# Extract items data displayed in canvas figure |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
573 |
start_tick = max(start_tick, self.GetItemsMinCommonTick()) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
574 |
end_tick = max(end_tick, start_tick) |
1209 | 575 |
x_data = items[0].GetData(start_tick, end_tick) |
576 |
y_data = items[1].GetData(start_tick, end_tick) |
|
1212 | 577 |
|
578 |
# Search for the nearest point from mouse position |
|
1209 | 579 |
if len(x_data) > 0 and len(y_data) > 0: |
1212 | 580 |
length = min(len(x_data), len(y_data)) |
581 |
d = numpy.sqrt((x_data[:length,1]-event.xdata) ** 2 + \ |
|
582 |
(y_data[:length,1]-event.ydata) ** 2) |
|
583 |
||
584 |
# Set cursor tick to the tick of this point |
|
1209 | 585 |
cursor_tick = x_data[numpy.argmin(d), 0] |
1212 | 586 |
|
587 |
# Graph is parallel |
|
1209 | 588 |
else: |
1212 | 589 |
# Extract items tick |
1209 | 590 |
data = items[0].GetData(start_tick, end_tick) |
1212 | 591 |
|
592 |
# Search for point that tick is the nearest from mouse X position |
|
593 |
# and set cursor tick to the tick of this point |
|
1209 | 594 |
if len(data) > 0: |
1212 | 595 |
cursor_tick = data[numpy.argmin( |
596 |
numpy.abs(data[:,0] - event.xdata)), 0] |
|
597 |
||
598 |
# Update cursor tick |
|
1209 | 599 |
if cursor_tick is not None: |
600 |
self.ParentWindow.SetCursorTick(cursor_tick) |
|
601 |
||
602 |
def OnCanvasButtonPressed(self, event): |
|
603 |
""" |
|
604 |
Function called when a button of mouse is pressed |
|
605 |
@param event: Mouse event |
|
606 |
""" |
|
1212 | 607 |
# Get mouse position, graph Y coordinate is inverted in matplotlib |
608 |
# comparing to wx |
|
1209 | 609 |
width, height = self.GetSize() |
610 |
x, y = event.x, height - event.y |
|
611 |
||
612 |
# Return immediately if mouse is over a button |
|
613 |
if self.IsOverButton(x, y): |
|
614 |
return |
|
615 |
||
616 |
# Mouse was clicked inside graph figure |
|
617 |
if event.inaxes == self.Axes: |
|
618 |
||
619 |
# Find if it was on an item label |
|
620 |
item_idx = None |
|
621 |
# Check every label paired with corresponding item |
|
622 |
for i, t in ([pair for pair in enumerate(self.AxesLabels)] + |
|
623 |
[pair for pair in enumerate(self.Labels)]): |
|
624 |
# Get label bounding box |
|
625 |
(x0, y0), (x1, y1) = t.get_window_extent().get_points() |
|
626 |
rect = wx.Rect(x0, height - y1, x1 - x0, y1 - y0) |
|
627 |
# Check if mouse was over label |
|
628 |
if rect.InsideXY(x, y): |
|
629 |
item_idx = i |
|
630 |
break |
|
631 |
||
632 |
# If an item label have been clicked |
|
633 |
if item_idx is not None: |
|
634 |
# Hide buttons and contextual buttons |
|
635 |
self.ShowButtons(False) |
|
636 |
self.DismissContextualButtons() |
|
637 |
||
638 |
# Start a drag'n drop from mouse position in wx coordinate of |
|
639 |
# parent |
|
640 |
xw, yw = self.GetPosition() |
|
641 |
self.ParentWindow.StartDragNDrop(self, |
|
642 |
self.ItemsDict.values()[item_idx], |
|
643 |
x + xw, y + yw, # Current mouse position |
|
644 |
x + xw, y + yw) # Mouse position when button was clicked |
|
645 |
||
646 |
# Don't handle mouse button if canvas is 3D and let matplotlib do |
|
647 |
# the default behavior (rotate 3D axes) |
|
648 |
elif not self.Is3DCanvas(): |
|
649 |
# Save mouse position when clicked |
|
650 |
self.MouseStartPos = wx.Point(x, y) |
|
651 |
||
652 |
# Mouse button was left button, start moving cursor |
|
653 |
if event.button == 1: |
|
654 |
# Save current tick in case a drag'n drop is initiate to |
|
655 |
# restore it |
|
656 |
self.StartCursorTick = self.CursorTick |
|
657 |
||
658 |
self.HandleCursorMove(event) |
|
659 |
||
660 |
# Mouse button is middle button and graph is parallel, start |
|
661 |
# moving graph along X coordinate (tick) |
|
662 |
elif event.button == 2 and self.GraphType == GRAPH_PARALLEL: |
|
663 |
self.StartCursorTick = self.ParentWindow.GetRange()[0] |
|
664 |
||
665 |
# Mouse was clicked outside graph figure and over resize highlight with |
|
666 |
# left button, start resizing Viewer |
|
667 |
elif event.button == 1 and event.y <= 5: |
|
668 |
self.MouseStartPos = wx.Point(x, y) |
|
669 |
self.CanvasStartSize = height |
|
670 |
||
671 |
def OnCanvasButtonReleased(self, event): |
|
672 |
""" |
|
673 |
Function called when a button of mouse is released |
|
674 |
@param event: Mouse event |
|
675 |
""" |
|
676 |
# If a drag'n drop is in progress, stop it |
|
677 |
if self.ParentWindow.IsDragging(): |
|
678 |
width, height = self.GetSize() |
|
679 |
xw, yw = self.GetPosition() |
|
680 |
item = self.ParentWindow.DraggingAxesPanel.ItemsDict.values()[0] |
|
681 |
# Give mouse position in wx coordinate of parent |
|
682 |
self.ParentWindow.StopDragNDrop(item.GetVariable(), |
|
683 |
xw + event.x, yw + height - event.y) |
|
684 |
||
685 |
else: |
|
686 |
# Reset any move in progress |
|
687 |
self.MouseStartPos = None |
|
688 |
self.CanvasStartSize = None |
|
689 |
||
690 |
# Handle button under mouse if it exist |
|
691 |
width, height = self.GetSize() |
|
692 |
self.HandleButton(event.x, height - event.y) |
|
693 |
||
694 |
def OnCanvasMotion(self, event): |
|
695 |
""" |
|
696 |
Function called when a button of mouse is moved over Viewer |
|
697 |
@param event: Mouse event |
|
698 |
""" |
|
699 |
width, height = self.GetSize() |
|
700 |
||
701 |
# If a drag'n drop is in progress, move canvas dragged |
|
702 |
if self.ParentWindow.IsDragging(): |
|
703 |
xw, yw = self.GetPosition() |
|
704 |
# Give mouse position in wx coordinate of parent |
|
705 |
self.ParentWindow.MoveDragNDrop( |
|
706 |
xw + event.x, |
|
707 |
yw + height - event.y) |
|
708 |
||
709 |
# If a Viewer resize is in progress, change Viewer size |
|
710 |
elif event.button == 1 and self.CanvasStartSize is not None: |
|
711 |
width, height = self.GetSize() |
|
1264 | 712 |
self.SetCanvasHeight( |
1209 | 713 |
self.CanvasStartSize + height - event.y - self.MouseStartPos.y) |
714 |
||
715 |
# If no button is pressed, show or hide contextual buttons or resize |
|
716 |
# highlight |
|
717 |
elif event.button is None: |
|
718 |
# Compute direction for items label according graph type |
|
719 |
if self.GraphType == GRAPH_PARALLEL: # Graph is parallel |
|
720 |
directions = [wx.RIGHT] * len(self.AxesLabels) + \ |
|
721 |
[wx.LEFT] * len(self.Labels) |
|
722 |
elif len(self.AxesLabels) > 0: # Graph is orthogonal in 2D |
|
723 |
directions = [wx.RIGHT, wx.TOP, # Directions for AxesLabels |
|
724 |
wx.LEFT, wx.BOTTOM] # Directions for Labels |
|
725 |
else: # Graph is orthogonal in 3D |
|
726 |
directions = [wx.LEFT] * len(self.Labels) |
|
727 |
||
728 |
# Find if mouse is over an item label |
|
729 |
item_idx = None |
|
730 |
menu_direction = None |
|
731 |
for (i, t), dir in zip( |
|
732 |
[pair for pair in enumerate(self.AxesLabels)] + |
|
733 |
[pair for pair in enumerate(self.Labels)], |
|
734 |
directions): |
|
735 |
# Check every label paired with corresponding item |
|
736 |
(x0, y0), (x1, y1) = t.get_window_extent().get_points() |
|
737 |
rect = wx.Rect(x0, height - y1, x1 - x0, y1 - y0) |
|
738 |
# Check if mouse was over label |
|
739 |
if rect.InsideXY(event.x, height - event.y): |
|
740 |
item_idx = i |
|
741 |
menu_direction = dir |
|
742 |
break |
|
743 |
||
744 |
# If mouse is over an item label, |
|
745 |
if item_idx is not None: |
|
746 |
self.PopupContextualButtons( |
|
747 |
self.ItemsDict.values()[item_idx], |
|
748 |
rect, menu_direction) |
|
749 |
return |
|
750 |
||
751 |
# If mouse isn't over a contextual menu, hide the current shown one |
|
752 |
# if it exists |
|
753 |
if self.IsOverContextualButton(event.x, height - event.y) is None: |
|
754 |
self.DismissContextualButtons() |
|
755 |
||
756 |
# Update resize highlight |
|
757 |
if event.y <= 5: |
|
758 |
if self.SetHighlight(HIGHLIGHT_RESIZE): |
|
759 |
self.SetCursor(wx.StockCursor(wx.CURSOR_SIZENS)) |
|
760 |
self.ParentWindow.ForceRefresh() |
|
761 |
else: |
|
762 |
if self.SetHighlight(HIGHLIGHT_NONE): |
|
763 |
self.SetCursor(wx.NullCursor) |
|
764 |
self.ParentWindow.ForceRefresh() |
|
765 |
||
766 |
# Handle buttons if canvas is not 3D |
|
767 |
elif not self.Is3DCanvas(): |
|
768 |
||
769 |
# If left button is pressed |
|
770 |
if event.button == 1: |
|
771 |
||
772 |
# Mouse is inside graph figure |
|
773 |
if event.inaxes == self.Axes: |
|
774 |
||
775 |
# If a cursor move is in progress, update cursor position |
|
776 |
if self.MouseStartPos is not None: |
|
777 |
self.HandleCursorMove(event) |
|
778 |
||
779 |
# Mouse is outside graph figure, cursor move is in progress and |
|
780 |
# there is only one item in Viewer, start a drag'n drop |
|
781 |
elif self.MouseStartPos is not None and len(self.Items) == 1: |
|
782 |
xw, yw = self.GetPosition() |
|
783 |
self.ParentWindow.SetCursorTick(self.StartCursorTick) |
|
784 |
self.ParentWindow.StartDragNDrop(self, |
|
785 |
self.ItemsDict.values()[0], |
|
786 |
# Current mouse position |
|
787 |
event.x + xw, height - event.y + yw, |
|
788 |
# Mouse position when button was clicked |
|
789 |
self.MouseStartPos.x + xw, |
|
790 |
self.MouseStartPos.y + yw) |
|
791 |
||
792 |
# If middle button is pressed and moving graph along X coordinate |
|
793 |
# is in progress |
|
794 |
elif event.button == 2 and self.GraphType == GRAPH_PARALLEL and \ |
|
795 |
self.MouseStartPos is not None: |
|
796 |
start_tick, end_tick = self.ParentWindow.GetRange() |
|
797 |
rect = self.GetAxesBoundingBox() |
|
798 |
||
799 |
# Move graph along X coordinate |
|
800 |
self.ParentWindow.SetCanvasPosition( |
|
801 |
self.StartCursorTick + |
|
802 |
(self.MouseStartPos.x - event.x) * |
|
803 |
(end_tick - start_tick) / rect.width) |
|
804 |
||
805 |
def OnCanvasScroll(self, event): |
|
806 |
""" |
|
807 |
Function called when a wheel mouse is use in Viewer |
|
808 |
@param event: Mouse event |
|
809 |
""" |
|
810 |
# Change X range of graphs if mouse is in canvas figure and ctrl is |
|
811 |
# pressed |
|
812 |
if event.inaxes is not None and event.guiEvent.ControlDown(): |
|
813 |
||
814 |
# Calculate position of fixed tick point according to graph type |
|
815 |
# and mouse position |
|
816 |
if self.GraphType == GRAPH_ORTHOGONAL: |
|
817 |
start_tick, end_tick = self.ParentWindow.GetRange() |
|
818 |
tick = (start_tick + end_tick) / 2. |
|
819 |
else: |
|
820 |
tick = event.xdata |
|
821 |
self.ParentWindow.ChangeRange(int(-event.step) / 3, tick) |
|
822 |
||
823 |
# Vetoing event to prevent parent panel to be scrolled |
|
824 |
self.ParentWindow.VetoScrollEvent = True |
|
825 |
||
1214
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
826 |
def OnLeftDClick(self, event): |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
827 |
""" |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
828 |
Function called when a left mouse button is double clicked |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
829 |
@param event: Mouse event |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
830 |
""" |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
831 |
# Check that double click was done inside figure |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
832 |
pos = event.GetPosition() |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
833 |
rect = self.GetAxesBoundingBox() |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
834 |
if rect.InsideXY(pos.x, pos.y): |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
835 |
# Reset Cursor tick to value before starting clicking |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
836 |
self.ParentWindow.SetCursorTick(self.StartCursorTick) |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
837 |
# Toggle to text Viewer(s) |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
838 |
self.ParentWindow.ToggleViewerType(self) |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
839 |
|
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
840 |
else: |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
841 |
event.Skip() |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
842 |
|
1209 | 843 |
# Cursor tick move for each arrow key |
844 |
KEY_CURSOR_INCREMENT = { |
|
845 |
wx.WXK_LEFT: -1, |
|
846 |
wx.WXK_RIGHT: 1, |
|
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
847 |
wx.WXK_UP: 10, |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
848 |
wx.WXK_DOWN: -10} |
1209 | 849 |
|
850 |
def OnKeyDown(self, event): |
|
851 |
""" |
|
852 |
Function called when key is pressed |
|
853 |
@param event: wx.KeyEvent |
|
854 |
""" |
|
855 |
# If cursor is shown and arrow key is pressed, move cursor tick |
|
856 |
if self.CursorTick is not None: |
|
857 |
move = self.KEY_CURSOR_INCREMENT.get(event.GetKeyCode(), None) |
|
858 |
if move is not None: |
|
859 |
self.ParentWindow.MoveCursorTick(move) |
|
860 |
event.Skip() |
|
861 |
||
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
862 |
def OnLeave(self, event): |
1209 | 863 |
""" |
864 |
Function called when mouse leave Viewer |
|
865 |
@param event: wx.MouseEvent |
|
866 |
""" |
|
867 |
# If Viewer is not resizing, reset resize highlight |
|
868 |
if self.CanvasStartSize is None: |
|
869 |
self.SetHighlight(HIGHLIGHT_NONE) |
|
870 |
self.SetCursor(wx.NullCursor) |
|
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
871 |
DebugVariableViewer.OnLeave(self, event) |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
872 |
else: |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
873 |
event.Skip() |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
874 |
|
1212 | 875 |
def GetCanvasMinSize(self): |
876 |
""" |
|
877 |
Return the minimum size of Viewer so that all items label can be |
|
878 |
displayed |
|
879 |
@return: wx.Size containing Viewer minimum size |
|
880 |
""" |
|
881 |
# The minimum height take in account the height of all items, padding |
|
882 |
# inside figure and border around figure |
|
883 |
return wx.Size(200, |
|
884 |
CANVAS_BORDER[0] + CANVAS_BORDER[1] + |
|
885 |
2 * CANVAS_PADDING + VALUE_LABEL_HEIGHT * len(self.Items)) |
|
886 |
||
1264 | 887 |
def SetCanvasHeight(self, height): |
1212 | 888 |
""" |
889 |
Set Viewer size checking that it respects Viewer minimum size |
|
890 |
@param height: Viewer height |
|
891 |
""" |
|
1264 | 892 |
min_width, min_height = self.GetCanvasMinSize() |
893 |
height = max(height, min_height) |
|
894 |
self.SetMinSize(wx.Size(min_width, height)) |
|
1212 | 895 |
self.RefreshLabelsPosition(height) |
896 |
self.ParentWindow.RefreshGraphicsSizer() |
|
897 |
||
898 |
def GetAxesBoundingBox(self, parent_coordinate=False): |
|
899 |
""" |
|
900 |
Return figure bounding box in wx coordinate |
|
901 |
@param parent_coordinate: True if use parent coordinate (default False) |
|
902 |
""" |
|
903 |
# Calculate figure bounding box. Y coordinate is inverted in matplotlib |
|
904 |
# figure comparing to wx panel |
|
905 |
width, height = self.GetSize() |
|
906 |
ax, ay, aw, ah = self.figure.gca().get_position().bounds |
|
907 |
bbox = wx.Rect(ax * width, height - (ay + ah) * height - 1, |
|
908 |
aw * width + 2, ah * height + 1) |
|
909 |
||
910 |
# If parent_coordinate, add Viewer position in parent |
|
911 |
if parent_coordinate: |
|
912 |
xw, yw = self.GetPosition() |
|
913 |
bbox.x += xw |
|
914 |
bbox.y += yw |
|
915 |
||
916 |
return bbox |
|
917 |
||
918 |
def RefreshHighlight(self, x, y): |
|
919 |
""" |
|
920 |
Refresh Viewer highlight according to mouse position |
|
921 |
@param x: X coordinate of mouse pointer |
|
922 |
@param y: Y coordinate of mouse pointer |
|
923 |
""" |
|
924 |
width, height = self.GetSize() |
|
925 |
||
926 |
# Mouse is over Viewer figure and graph is not 3D |
|
927 |
bbox = self.GetAxesBoundingBox() |
|
928 |
if bbox.InsideXY(x, y) and not self.Is3DCanvas(): |
|
929 |
rect = wx.Rect(bbox.x, bbox.y, bbox.width / 2, bbox.height) |
|
930 |
# Mouse is over Viewer left part of figure |
|
931 |
if rect.InsideXY(x, y): |
|
932 |
self.SetHighlight(HIGHLIGHT_LEFT) |
|
933 |
||
934 |
# Mouse is over Viewer right part of figure |
|
935 |
else: |
|
936 |
self.SetHighlight(HIGHLIGHT_RIGHT) |
|
937 |
||
938 |
# Mouse is over upper part of Viewer |
|
939 |
elif y < height / 2: |
|
940 |
# Viewer is upper one in Debug Variable Panel, show highlight |
|
941 |
if self.ParentWindow.IsViewerFirst(self): |
|
942 |
self.SetHighlight(HIGHLIGHT_BEFORE) |
|
943 |
||
944 |
# Viewer is not the upper one, show highlight in previous one |
|
945 |
# It prevents highlight to move when mouse leave one Viewer to |
|
946 |
# another |
|
947 |
else: |
|
948 |
self.SetHighlight(HIGHLIGHT_NONE) |
|
949 |
self.ParentWindow.HighlightPreviousViewer(self) |
|
950 |
||
951 |
# Mouse is over lower part of Viewer |
|
952 |
else: |
|
953 |
self.SetHighlight(HIGHLIGHT_AFTER) |
|
954 |
||
955 |
def OnAxesMotion(self, event): |
|
956 |
""" |
|
957 |
Function overriding default function called when mouse is dragged for |
|
958 |
rotating graph preventing refresh to be called too quickly |
|
959 |
@param event: Mouse event |
|
960 |
""" |
|
961 |
if self.Is3DCanvas(): |
|
962 |
# Call default function at most 10 times per second |
|
963 |
current_time = gettime() |
|
964 |
if current_time - self.LastMotionTime > REFRESH_PERIOD: |
|
965 |
self.LastMotionTime = current_time |
|
966 |
Axes3D._on_move(self.Axes, event) |
|
967 |
||
968 |
def GetAddTextFunction(self): |
|
969 |
""" |
|
970 |
Return function for adding text in figure according to graph type |
|
971 |
@return: Function adding text to figure |
|
972 |
""" |
|
973 |
text_func = (self.Axes.text2D if self.Is3DCanvas() else self.Axes.text) |
|
974 |
def AddText(*args, **kwargs): |
|
975 |
args = [0, 0, ""] |
|
976 |
kwargs["transform"] = self.Axes.transAxes |
|
977 |
return text_func(*args, **kwargs) |
|
978 |
return AddText |
|
979 |
||
980 |
def ResetGraphics(self): |
|
981 |
""" |
|
982 |
Reset figure and graphical elements displayed in it |
|
983 |
Called any time list of items or graph type change |
|
984 |
""" |
|
985 |
# Clear figure from any axes defined |
|
986 |
self.Figure.clear() |
|
987 |
||
988 |
# Add 3D projection if graph is in 3D |
|
989 |
if self.Is3DCanvas(): |
|
990 |
self.Axes = self.Figure.gca(projection='3d') |
|
991 |
self.Axes.set_color_cycle(['b']) |
|
992 |
||
993 |
# Override function to prevent too much refresh when graph is |
|
994 |
# rotated |
|
995 |
self.LastMotionTime = gettime() |
|
996 |
setattr(self.Axes, "_on_move", self.OnAxesMotion) |
|
997 |
||
998 |
# Init graph mouse event so that graph can be rotated |
|
999 |
self.Axes.mouse_init() |
|
1000 |
||
1001 |
# Set size of Z axis labels |
|
1002 |
self.Axes.tick_params(axis='z', labelsize='small') |
|
1003 |
||
1004 |
else: |
|
1005 |
self.Axes = self.Figure.gca() |
|
1006 |
self.Axes.set_color_cycle(COLOR_CYCLE) |
|
1007 |
||
1008 |
# Set size of X and Y axis labels |
|
1009 |
self.Axes.tick_params(axis='x', labelsize='small') |
|
1010 |
self.Axes.tick_params(axis='y', labelsize='small') |
|
1011 |
||
1012 |
# Init variables storing graphical elements added to figure |
|
1013 |
self.Plots = [] # List of curves |
|
1014 |
self.VLine = None # Vertical line for cursor |
|
1015 |
self.HLine = None # Horizontal line for cursor (only orthogonal 2D) |
|
1016 |
self.AxesLabels = [] # List of items variable path text label |
|
1017 |
self.Labels = [] # List of items text label |
|
1018 |
||
1019 |
# Get function to add a text in figure according to graph type |
|
1020 |
add_text_func = self.GetAddTextFunction() |
|
1021 |
||
1022 |
# Graph type is parallel or orthogonal in 3D |
|
1023 |
if self.GraphType == GRAPH_PARALLEL or self.Is3DCanvas(): |
|
1024 |
num_item = len(self.Items) |
|
1025 |
for idx in xrange(num_item): |
|
1026 |
||
1027 |
# Get color from color cycle (black if only one item) |
|
1028 |
color = ('k' if num_item == 1 |
|
1029 |
else COLOR_CYCLE[idx % len(COLOR_CYCLE)]) |
|
1030 |
||
1031 |
# In 3D graph items variable label are not displayed as text |
|
1032 |
# in figure, but as axis title |
|
1033 |
if not self.Is3DCanvas(): |
|
1034 |
# Items variable labels are in figure upper left corner |
|
1035 |
self.AxesLabels.append( |
|
1036 |
add_text_func(size='small', color=color, |
|
1037 |
verticalalignment='top')) |
|
1038 |
||
1039 |
# Items variable labels are in figure lower right corner |
|
1040 |
self.Labels.append( |
|
1041 |
add_text_func(size='large', color=color, |
|
1042 |
horizontalalignment='right')) |
|
1043 |
||
1044 |
# Graph type is orthogonal in 2D |
|
1045 |
else: |
|
1046 |
# X coordinate labels are in figure lower side |
|
1047 |
self.AxesLabels.append(add_text_func(size='small')) |
|
1048 |
self.Labels.append( |
|
1049 |
add_text_func(size='large', |
|
1050 |
horizontalalignment='right')) |
|
1051 |
||
1052 |
# Y coordinate labels are vertical and in figure left side |
|
1053 |
self.AxesLabels.append( |
|
1264 | 1054 |
add_text_func(size='small', rotation='vertical', |
1055 |
verticalalignment='bottom')) |
|
1212 | 1056 |
self.Labels.append( |
1057 |
add_text_func(size='large', rotation='vertical', |
|
1058 |
verticalalignment='top')) |
|
1059 |
||
1060 |
# Refresh position of labels according to Viewer size |
|
1061 |
width, height = self.GetSize() |
|
1062 |
self.RefreshLabelsPosition(height) |
|
1063 |
||
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1064 |
def RefreshLabelsPosition(self, height): |
1212 | 1065 |
""" |
1066 |
Function called when mouse leave Viewer |
|
1067 |
@param event: wx.MouseEvent |
|
1068 |
""" |
|
1069 |
# Figure position like text position in figure are expressed is ratio |
|
1070 |
# canvas size and figure size. As we want that border around figure and |
|
1071 |
# text position in figure don't change when canvas size change, we |
|
1072 |
# expressed border and text position in pixel on screen and apply the |
|
1073 |
# ratio calculated hereafter to get border and text position in |
|
1214
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
1074 |
# matplotlib coordinate |
1212 | 1075 |
canvas_ratio = 1. / height # Divide by canvas height in pixel |
1076 |
graph_ratio = 1. / ( |
|
1077 |
(1.0 - (CANVAS_BORDER[0] + CANVAS_BORDER[1]) * canvas_ratio) |
|
1078 |
* height) # Divide by figure height in pixel |
|
1079 |
||
1080 |
# Update position of figure (keeping up and bottom border the same |
|
1081 |
# size) |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1082 |
self.Figure.subplotpars.update( |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1083 |
top= 1.0 - CANVAS_BORDER[1] * canvas_ratio, |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1084 |
bottom= CANVAS_BORDER[0] * canvas_ratio) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1085 |
|
1212 | 1086 |
# Update position of items labels |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1087 |
if self.GraphType == GRAPH_PARALLEL or self.Is3DCanvas(): |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1088 |
num_item = len(self.Items) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1089 |
for idx in xrange(num_item): |
1212 | 1090 |
|
1091 |
# In 3D graph items variable label are not displayed |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1092 |
if not self.Is3DCanvas(): |
1212 | 1093 |
# Items variable labels are in figure upper left corner |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1094 |
self.AxesLabels[idx].set_position( |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1095 |
(0.05, |
1212 | 1096 |
1.0 - (CANVAS_PADDING + |
1097 |
AXES_LABEL_HEIGHT * idx) * graph_ratio)) |
|
1098 |
||
1099 |
# Items variable labels are in figure lower right corner |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1100 |
self.Labels[idx].set_position( |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1101 |
(0.95, |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1102 |
CANVAS_PADDING * graph_ratio + |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1103 |
(num_item - idx - 1) * VALUE_LABEL_HEIGHT * graph_ratio)) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1104 |
else: |
1212 | 1105 |
# X coordinate labels are in figure lower side |
1106 |
self.AxesLabels[0].set_position( |
|
1107 |
(0.1, CANVAS_PADDING * graph_ratio)) |
|
1108 |
self.Labels[0].set_position( |
|
1109 |
(0.95, CANVAS_PADDING * graph_ratio)) |
|
1110 |
||
1111 |
# Y coordinate labels are vertical and in figure left side |
|
1112 |
self.AxesLabels[1].set_position( |
|
1113 |
(0.05, 2 * CANVAS_PADDING * graph_ratio)) |
|
1114 |
self.Labels[1].set_position( |
|
1115 |
(0.05, 1.0 - CANVAS_PADDING * graph_ratio)) |
|
1116 |
||
1117 |
# Update subplots |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1118 |
self.Figure.subplots_adjust() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1119 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1120 |
def RefreshViewer(self, refresh_graphics=True): |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1121 |
""" |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1122 |
Function called to refresh displayed by matplotlib canvas |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1123 |
@param refresh_graphics: Flag indicating that graphs have to be |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1124 |
refreshed (False: only label values have to be refreshed) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1125 |
""" |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1126 |
# Refresh graphs if needed |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1127 |
if refresh_graphics: |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1128 |
# Get tick range of values to display |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1129 |
start_tick, end_tick = self.ParentWindow.GetRange() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1130 |
|
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1131 |
# Graph is parallel |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1132 |
if self.GraphType == GRAPH_PARALLEL: |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1133 |
# Init list of data range for each variable displayed |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1134 |
ranges = [] |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1135 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1136 |
# Get data and range for each variable displayed |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1137 |
for idx, item in enumerate(self.Items): |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1138 |
data, min_value, max_value = item.GetDataAndValueRange( |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1139 |
start_tick, end_tick, not self.ZoomFit) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1140 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1141 |
# Check that data is not empty |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1142 |
if data is not None: |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1143 |
# Add variable range to list of variable data range |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1144 |
ranges.append((min_value, max_value)) |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1145 |
|
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1146 |
# Add plot to canvas if not yet created |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1147 |
if len(self.Plots) <= idx: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1148 |
self.Plots.append( |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1149 |
self.Axes.plot(data[:, 0], data[:, 1])[0]) |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1150 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1151 |
# Set data to already created plot in canvas |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1152 |
else: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1153 |
self.Plots[idx].set_data(data[:, 0], data[:, 1]) |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1154 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1155 |
# Get X and Y axis ranges |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1156 |
x_min, x_max = start_tick, end_tick |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1157 |
y_min, y_max = merge_ranges(ranges) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1158 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1159 |
# Display cursor in canvas if a cursor tick is defined and it is |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1160 |
# include in values tick range |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1161 |
if (self.CursorTick is not None and |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1162 |
start_tick <= self.CursorTick <= end_tick): |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1163 |
|
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1164 |
# Define a vertical line to display cursor position if no |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1165 |
# line is already defined |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1166 |
if self.VLine is None: |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1167 |
self.VLine = self.Axes.axvline(self.CursorTick, |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1168 |
color=CURSOR_COLOR) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1169 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1170 |
# Set value of vertical line if already defined |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1171 |
else: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1172 |
self.VLine.set_xdata((self.CursorTick, self.CursorTick)) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1173 |
self.VLine.set_visible(True) |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1174 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1175 |
# Hide vertical line if cursor tick is not defined or reset |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1176 |
elif self.VLine is not None: |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1177 |
self.VLine.set_visible(False) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1178 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1179 |
# Graph is orthogonal |
929
c562031146e4
Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents:
928
diff
changeset
|
1180 |
else: |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1181 |
# Update tick range, removing ticks that don't have a value for |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1182 |
# each variable |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1183 |
start_tick = max(start_tick, self.GetItemsMinCommonTick()) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1184 |
end_tick = max(end_tick, start_tick) |
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
1185 |
items = self.ItemsDict.values() |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1186 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1187 |
# Get data and range for first variable (X coordinate) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1188 |
x_data, x_min, x_max = items[0].GetDataAndValueRange( |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1189 |
start_tick, end_tick, not self.ZoomFit) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1190 |
# Get data and range for second variable (Y coordinate) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1191 |
y_data, y_min, y_max = items[1].GetDataAndValueRange( |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1192 |
start_tick, end_tick, not self.ZoomFit) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1193 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1194 |
# Normalize X and Y coordinates value range |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1195 |
x_min, x_max = merge_ranges([(x_min, x_max)]) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1196 |
y_min, y_max = merge_ranges([(y_min, y_max)]) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1197 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1198 |
# Get X and Y coordinates for cursor if cursor tick is defined |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1199 |
if self.CursorTick is not None: |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1200 |
x_cursor, x_forced = items[0].GetValue( |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1201 |
self.CursorTick, raw=True) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1202 |
y_cursor, y_forced = items[1].GetValue( |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1203 |
self.CursorTick, raw=True) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1204 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1205 |
# Get common data length so that each value has an x and y |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1206 |
# coordinate |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1207 |
length = (min(len(x_data), len(y_data)) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1208 |
if x_data is not None and y_data is not None |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1209 |
else 0) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1210 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1211 |
# Graph is orthogonal 2D |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1212 |
if len(self.Items) < 3: |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1213 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1214 |
# Check that x and y data are not empty |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1215 |
if x_data is not None and y_data is not None: |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1216 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1217 |
# Add plot to canvas if not yet created |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1218 |
if len(self.Plots) == 0: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1219 |
self.Plots.append( |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1220 |
self.Axes.plot(x_data[:, 1][:length], |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1221 |
y_data[:, 1][:length])[0]) |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1222 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1223 |
# Set data to already created plot in canvas |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1224 |
else: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1225 |
self.Plots[0].set_data( |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1226 |
x_data[:, 1][:length], |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1227 |
y_data[:, 1][:length]) |
916
697d8b77d716
Improved matplotlib graphic debug panel implementation, adding force, release, split and delete graph buttons, replacing data grid by adding panel displaying non-numeric data between graphs
Laurent Bessard
parents:
912
diff
changeset
|
1228 |
|
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1229 |
# Display cursor in canvas if a cursor tick is defined and it is |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1230 |
# include in values tick range |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1231 |
if (self.CursorTick is not None and |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1232 |
start_tick <= self.CursorTick <= end_tick): |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1233 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1234 |
# Define a vertical line to display cursor x coordinate |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1235 |
# if no line is already defined |
924
5f2cc382be8c
Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents:
919
diff
changeset
|
1236 |
if self.VLine is None: |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1237 |
self.VLine = self.Axes.axvline(x_cursor, |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1238 |
color=CURSOR_COLOR) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1239 |
# Set value of vertical line if already defined |
924
5f2cc382be8c
Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents:
919
diff
changeset
|
1240 |
else: |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1241 |
self.VLine.set_xdata((x_cursor, x_cursor)) |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1242 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1243 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1244 |
# Define a horizontal line to display cursor y |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1245 |
# coordinate if no line is already defined |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1246 |
if self.HLine is None: |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1247 |
self.HLine = self.Axes.axhline(y_cursor, |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1248 |
color=CURSOR_COLOR) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1249 |
# Set value of horizontal line if already defined |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1250 |
else: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1251 |
self.HLine.set_ydata((y_cursor, y_cursor)) |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1252 |
|
924
5f2cc382be8c
Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents:
919
diff
changeset
|
1253 |
self.VLine.set_visible(True) |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1254 |
self.HLine.set_visible(True) |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1255 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1256 |
# Hide vertical and horizontal line if cursor tick is not |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1257 |
# defined or reset |
924
5f2cc382be8c
Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents:
919
diff
changeset
|
1258 |
else: |
5f2cc382be8c
Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents:
919
diff
changeset
|
1259 |
if self.VLine is not None: |
5f2cc382be8c
Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents:
919
diff
changeset
|
1260 |
self.VLine.set_visible(False) |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1261 |
if self.HLine is not None: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1262 |
self.HLine.set_visible(False) |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1263 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1264 |
# Graph is orthogonal 3D |
916
697d8b77d716
Improved matplotlib graphic debug panel implementation, adding force, release, split and delete graph buttons, replacing data grid by adding panel displaying non-numeric data between graphs
Laurent Bessard
parents:
912
diff
changeset
|
1265 |
else: |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1266 |
# Remove all plots already defined in 3D canvas |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1267 |
while len(self.Axes.lines) > 0: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1268 |
self.Axes.lines.pop() |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1269 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1270 |
# Get data and range for third variable (Z coordinate) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1271 |
z_data, z_min, z_max = items[2].GetDataAndValueRange( |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1272 |
start_tick, end_tick, not self.ZoomFit) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1273 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1274 |
# Normalize Z coordinate value range |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1275 |
z_min, z_max = merge_ranges([(z_min, z_max)]) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1276 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1277 |
# Check that x, y and z data are not empty |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1278 |
if (x_data is not None and y_data is not None and |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1279 |
z_data is not None): |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1280 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1281 |
# Get common data length so that each value has an x, y |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1282 |
# and z coordinate |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1283 |
length = min(length, len(z_data)) |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1284 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1285 |
# Add plot to canvas |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1286 |
self.Axes.plot(x_data[:, 1][:length], |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1287 |
y_data[:, 1][:length], |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1288 |
zs = z_data[:, 1][:length]) |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1289 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1290 |
# Display cursor in canvas if a cursor tick is defined and |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1291 |
# it is include in values tick range |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1292 |
if (self.CursorTick is not None and |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1293 |
start_tick <= self.CursorTick <= end_tick): |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1294 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1295 |
# Get Z coordinate for cursor |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1296 |
z_cursor, z_forced = items[2].GetValue( |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1297 |
self.CursorTick, raw=True) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1298 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1299 |
# Add 3 lines parallel to x, y and z axis to display |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1300 |
# cursor position in 3D |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1301 |
for kwargs in [{"xs": numpy.array([x_min, x_max])}, |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1302 |
{"ys": numpy.array([y_min, y_max])}, |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1303 |
{"zs": numpy.array([z_min, z_max])}]: |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1304 |
for param, value in [ |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1305 |
("xs", numpy.array([x_cursor, x_cursor])), |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1306 |
("ys", numpy.array([y_cursor, y_cursor])), |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1307 |
("zs", numpy.array([z_cursor, z_cursor]))]: |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1308 |
kwargs.setdefault(param, value) |
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
1309 |
kwargs["color"] = CURSOR_COLOR |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1310 |
self.Axes.plot(**kwargs) |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1311 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1312 |
# Set Z axis limits |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1313 |
self.Axes.set_zlim(z_min, z_max) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1314 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1315 |
# Set X and Y axis limits |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1316 |
self.Axes.set_xlim(x_min, x_max) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1317 |
self.Axes.set_ylim(y_min, y_max) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1318 |
|
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1319 |
# Get value and forced flag for each variable displayed in graph |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1320 |
# If cursor tick is not defined get value and flag of last received |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1321 |
# or get value and flag of variable at cursor tick |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1322 |
values, forced = apply(zip, [ |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1323 |
(item.GetValue(self.CursorTick) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1324 |
if self.CursorTick is not None |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1325 |
else (item.GetValue(), item.IsForced())) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1326 |
for item in self.Items]) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1327 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1328 |
# Get path of each variable displayed simplified using panel variable |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1329 |
# name mask |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1330 |
labels = [item.GetVariable(self.ParentWindow.GetVariableNameMask()) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1331 |
for item in self.Items] |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1332 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1333 |
# Get style for each variable according to |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1334 |
styles = map(lambda x: {True: 'italic', False: 'normal'}[x], forced) |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1335 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1336 |
# Graph is orthogonal 3D, set variables path as 3D axis label |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1337 |
if self.Is3DCanvas(): |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1338 |
for idx, label_func in enumerate([self.Axes.set_xlabel, |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1339 |
self.Axes.set_ylabel, |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1340 |
self.Axes.set_zlabel]): |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1341 |
label_func(labels[idx], fontdict={'size': 'small', |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1342 |
'color': COLOR_CYCLE[idx]}) |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1343 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1344 |
# Graph is not orthogonal 3D, set variables path in axes labels |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1345 |
else: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1346 |
for label, text in zip(self.AxesLabels, labels): |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1347 |
label.set_text(text) |
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1348 |
|
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1349 |
# Set value label text and style according to value and forced flag for |
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1350 |
# each variable displayed |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1351 |
for label, value, style in zip(self.Labels, values, styles): |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1352 |
label.set_text(value) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1353 |
label.set_style(style) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1354 |
|
1267
fae0809eae98
Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents:
1264
diff
changeset
|
1355 |
# Refresh figure |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1356 |
self.draw() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1357 |
|
1209 | 1358 |
def draw(self, drawDC=None): |
1359 |
""" |
|
1360 |
Render the figure. |
|
1361 |
""" |
|
1362 |
# Render figure using agg |
|
1363 |
FigureCanvasAgg.draw(self) |
|
1364 |
||
1365 |
# Get bitmap of figure rendered |
|
1366 |
self.bitmap = _convert_agg_to_wx_bitmap(self.get_renderer(), None) |
|
1367 |
self.bitmap.UseAlpha() |
|
1368 |
||
1369 |
# Create DC for rendering graphics in bitmap |
|
1370 |
destDC = wx.MemoryDC() |
|
1371 |
destDC.SelectObject(self.bitmap) |
|
1372 |
||
1373 |
# Get Graphics Context for DC, for anti-aliased and transparent |
|
1374 |
# rendering |
|
1375 |
destGC = wx.GCDC(destDC) |
|
1376 |
||
1377 |
destGC.BeginDrawing() |
|
1378 |
||
1379 |
# Get canvas size and figure bounding box in canvas |
|
1380 |
width, height = self.GetSize() |
|
1381 |
bbox = self.GetAxesBoundingBox() |
|
1382 |
||
1383 |
# If highlight to display is resize, draw thick grey line at bottom |
|
1384 |
# side of canvas |
|
1385 |
if self.Highlight == HIGHLIGHT_RESIZE: |
|
1386 |
destGC.SetPen(HIGHLIGHT_RESIZE_PEN) |
|
1387 |
destGC.SetBrush(HIGHLIGHT_RESIZE_BRUSH) |
|
1388 |
destGC.DrawRectangle(0, height - 5, width, 5) |
|
1389 |
||
1390 |
# If highlight to display is merging graph, draw 50% transparent blue |
|
1391 |
# rectangle on left or right part of figure depending on highlight type |
|
1392 |
elif self.Highlight in [HIGHLIGHT_LEFT, HIGHLIGHT_RIGHT]: |
|
1393 |
destGC.SetPen(HIGHLIGHT_DROP_PEN) |
|
1394 |
destGC.SetBrush(HIGHLIGHT_DROP_BRUSH) |
|
1395 |
||
1396 |
x_offset = (bbox.width / 2 |
|
1397 |
if self.Highlight == HIGHLIGHT_RIGHT |
|
1398 |
else 0) |
|
1399 |
destGC.DrawRectangle(bbox.x + x_offset, bbox.y, |
|
1400 |
bbox.width / 2, bbox.height) |
|
1401 |
||
1402 |
# Draw other Viewer common elements |
|
1403 |
self.DrawCommonElements(destGC, self.GetButtons()) |
|
1404 |
||
1405 |
destGC.EndDrawing() |
|
1406 |
||
1407 |
self._isDrawn = True |
|
1408 |
self.gui_repaint(drawDC=drawDC) |
|
1409 |
||
1410 |