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