controls/DebugVariablePanel/DebugVariableGraphicPanel.py
author Laurent Bessard
Thu, 30 May 2013 13:23:21 +0200
changeset 1199 fc0e7d80494f
parent 1198 8b4e6bd0aa92
child 1200 501cb0bb4c05
permissions -rw-r--r--
Move GraphButton from DebugVariableGraphicPanel to separate file
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     1
#!/usr/bin/env python
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     3
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     5
#based on the plcopen standard. 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     6
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     7
#Copyright (C) 2012: Edouard TISSERANT and Laurent BESSARD
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     8
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     9
#See COPYING file for copyrights details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    10
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    15
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    19
#General Public License for more details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    20
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    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
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
    27
import math
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
    28
import numpy
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    29
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    30
import wx
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    31
import wx.lib.buttons
888
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
    32
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    33
import matplotlib
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    34
matplotlib.use('WX')
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    35
import matplotlib.pyplot
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    36
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
    37
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
    38
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
    39
from mpl_toolkits.mplot3d import Axes3D
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    40
color_cycle = ['r', 'b', 'g', 'm', 'y', 'k']
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    41
cursor_color = '#800080'
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    42
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1174
diff changeset
    43
from editors.DebugViewer import DebugViewer, REFRESH_PERIOD
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    44
from dialogs.ForceVariableDialog import ForceVariableDialog
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    45
from util.BitmapLibrary import GetBitmap
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    46
1199
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
    47
from DebugVariableItem import DebugVariableItem
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
    48
from GraphButton import GraphButton
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
    49
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    50
class DebugVariableDropTarget(wx.TextDropTarget):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    51
    
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
    52
    def __init__(self, parent, control=None):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    53
        wx.TextDropTarget.__init__(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    54
        self.ParentWindow = parent
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
    55
        self.ParentControl = control
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    56
    
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
    57
    def __del__(self):
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
    58
        self.ParentWindow = None
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
    59
        self.ParentControl = None
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
    60
    
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
    61
    def OnDragOver(self, x, y, d):
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    62
        if self.ParentControl is not None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    63
            self.ParentControl.OnMouseDragging(x, y)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    64
        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    65
            self.ParentWindow.RefreshHighlight(x, y)
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
    66
        return wx.TextDropTarget.OnDragOver(self, x, y, d)
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
    67
        
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    68
    def OnDropText(self, x, y, data):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    69
        message = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    70
        try:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    71
            values = eval(data)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    72
        except:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    73
            message = _("Invalid value \"%s\" for debug variable")%data
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    74
            values = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    75
        if not isinstance(values, TupleType):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    76
            message = _("Invalid value \"%s\" for debug variable")%data
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    77
            values = None
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
    78
        
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    79
        if message is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    80
            wx.CallAfter(self.ShowMessage, message)
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
    81
        elif values is not None and values[1] == "debug":
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    82
            if self.ParentControl is not None:
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
    83
                width, height = self.ParentControl.GetSize()
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
    84
                target_idx = self.ParentControl.GetIndex()
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
    85
                merge_type = GRAPH_PARALLEL
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
    86
                if isinstance(self.ParentControl, DebugVariableGraphic):
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
    87
                    if self.ParentControl.Is3DCanvas():
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
    88
                        if y > height / 2:
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
    89
                            target_idx += 1
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
    90
                        if len(values) > 1 and values[2] == "move":
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
    91
                            self.ParentWindow.MoveValue(values[0], target_idx)
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
    92
                        else:
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
    93
                            self.ParentWindow.InsertValue(values[0], target_idx, force=True)
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
    94
                        
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
    95
                    else:
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
    96
                        rect = self.ParentControl.GetAxesBoundingBox()
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
    97
                        if rect.InsideXY(x, y):
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
    98
                            merge_rect = wx.Rect(rect.x, rect.y, rect.width / 2., rect.height)
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
    99
                            if merge_rect.InsideXY(x, y):
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   100
                                merge_type = GRAPH_ORTHOGONAL
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   101
                            wx.CallAfter(self.ParentWindow.MergeGraphs, values[0], target_idx, merge_type, force=True)
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   102
                        else:
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   103
                            if y > height / 2:
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   104
                                target_idx += 1
952
c1f901403a34 Fixed bug when drag'n dropping variables from left panel
Laurent Bessard
parents: 946
diff changeset
   105
                            if len(values) > 2 and values[2] == "move":
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   106
                                self.ParentWindow.MoveValue(values[0], target_idx)
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   107
                            else:
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   108
                                self.ParentWindow.InsertValue(values[0], target_idx, force=True)
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   109
                else:
919
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
   110
                    if y > height / 2:
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
   111
                        target_idx += 1
952
c1f901403a34 Fixed bug when drag'n dropping variables from left panel
Laurent Bessard
parents: 946
diff changeset
   112
                    if len(values) > 2 and values[2] == "move":
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   113
                        self.ParentWindow.MoveValue(values[0], target_idx)
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
   114
                    else:
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
   115
                        self.ParentWindow.InsertValue(values[0], target_idx, force=True)
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   116
                    
952
c1f901403a34 Fixed bug when drag'n dropping variables from left panel
Laurent Bessard
parents: 946
diff changeset
   117
            elif len(values) > 2 and values[2] == "move":
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   118
                self.ParentWindow.MoveValue(values[0])
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   119
            else:
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   120
                self.ParentWindow.InsertValue(values[0], force=True)
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   121
    
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   122
    def OnLeave(self):
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   123
        self.ParentWindow.ResetHighlight()
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   124
        return wx.TextDropTarget.OnLeave(self)
934
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
   125
    
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   126
    def ShowMessage(self, message):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   127
        dialog = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   128
        dialog.ShowModal()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   129
        dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   130
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   131
MILLISECOND = 1000000
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   132
SECOND = 1000 * MILLISECOND
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   133
MINUTE = 60 * SECOND
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   134
HOUR = 60 * MINUTE
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   135
DAY = 24 * HOUR
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   136
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   137
ZOOM_VALUES = map(lambda x:("x %.1f" % x, x), [math.sqrt(2) ** i for i in xrange(8)])
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   138
RANGE_VALUES = \
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   139
    [("%dms" % i, i * MILLISECOND) for i in (10, 20, 50, 100, 200, 500)] + \
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   140
    [("%ds" % i, i * SECOND) for i in (1, 2, 5, 10, 20, 30)] + \
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   141
    [("%dm" % i, i * MINUTE) for i in (1, 2, 5, 10, 20, 30)] + \
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   142
    [("%dh" % i, i * HOUR) for i in (1, 2, 3, 6, 12, 24)]
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   143
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   144
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
   145
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   146
SCROLLBAR_UNIT = 10
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   147
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   148
#CANVAS_HIGHLIGHT_TYPES
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   149
[HIGHLIGHT_NONE,
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   150
 HIGHLIGHT_BEFORE,
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   151
 HIGHLIGHT_AFTER,
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   152
 HIGHLIGHT_LEFT,
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   153
 HIGHLIGHT_RIGHT,
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   154
 HIGHLIGHT_RESIZE] = range(6)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   155
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   156
HIGHLIGHT_DROP_PEN = wx.Pen(wx.Colour(0, 128, 255))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   157
HIGHLIGHT_DROP_BRUSH = wx.Brush(wx.Colour(0, 128, 255, 128))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   158
HIGHLIGHT_RESIZE_PEN = wx.Pen(wx.Colour(200, 200, 200))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   159
HIGHLIGHT_RESIZE_BRUSH = wx.Brush(wx.Colour(200, 200, 200))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   160
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   161
#CANVAS_SIZE_TYPES
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   162
[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
   163
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   164
DEFAULT_CANVAS_HEIGHT = 200.
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   165
CANVAS_BORDER = (20., 10.)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   166
CANVAS_PADDING = 8.5
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   167
VALUE_LABEL_HEIGHT = 17.
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   168
AXES_LABEL_HEIGHT = 12.75
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   169
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   170
def compute_mask(x, y):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   171
    mask = []
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   172
    for xp, yp in zip(x, y):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   173
        if xp == yp:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   174
            mask.append(xp)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   175
        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   176
            mask.append("*")
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   177
    return mask
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   178
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   179
def NextTick(variables):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   180
    next_tick = None
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   181
    for item, data in variables:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   182
        if len(data) > 0:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   183
            if next_tick is None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   184
                next_tick = data[0][0]
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   185
            else:
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   186
                next_tick = min(next_tick, data[0][0])
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   187
    return next_tick
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   188
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   189
def OrthogonalData(item, start_tick, end_tick):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   190
    data = item.GetData(start_tick, end_tick)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   191
    min_value, max_value = item.GetValueRange()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   192
    if min_value is not None and max_value is not None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   193
        center = (min_value + max_value) / 2.
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   194
        range = max(1.0, max_value - min_value)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   195
    else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   196
        center = 0.5
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   197
        range = 1.0
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   198
    return data, center - range * 0.55, center + range * 0.55
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   199
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   200
class DebugVariableViewer:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   201
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   202
    def __init__(self, window, items=[]):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   203
        self.ParentWindow = window
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   204
        self.Items = items
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   205
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   206
        self.Highlight = HIGHLIGHT_NONE
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   207
        self.Buttons = []
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   208
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   209
    def __del__(self):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   210
        self.ParentWindow = None
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   211
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   212
    def GetIndex(self):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   213
        return self.ParentWindow.GetViewerIndex(self)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   214
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   215
    def GetItem(self, variable):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   216
        for item in self.Items:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   217
            if item.GetVariable() == variable:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   218
                return item
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   219
        return None
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   220
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   221
    def GetItems(self):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   222
        return self.Items
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   223
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   224
    def GetVariables(self):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   225
        if len(self.Items) > 1:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   226
            variables = [item.GetVariable() for item in self.Items]
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   227
            if self.GraphType == GRAPH_ORTHOGONAL:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   228
                return tuple(variables)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   229
            return variables
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   230
        return self.Items[0].GetVariable()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   231
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   232
    def AddItem(self, item):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   233
        self.Items.append(item)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   234
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   235
    def RemoveItem(self, item):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   236
        if item in self.Items:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   237
            self.Items.remove(item)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   238
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   239
    def Clear(self):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   240
        for item in self.Items:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   241
            self.ParentWindow.RemoveDataConsumer(item)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   242
        self.Items = []
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   243
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   244
    def IsEmpty(self):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   245
        return len(self.Items) == 0
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 UnregisterObsoleteData(self):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   248
        for item in self.Items[:]:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   249
            iec_path = item.GetVariable()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   250
            if self.ParentWindow.GetDataType(iec_path) is None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   251
                self.ParentWindow.RemoveDataConsumer(item)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   252
                self.RemoveItem(item)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   253
            else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   254
                self.ParentWindow.AddDataConsumer(iec_path.upper(), item)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   255
                item.RefreshVariableType()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   256
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   257
    def ResetData(self):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   258
        for item in self.Items:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   259
            item.ResetData()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   260
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   261
    def RefreshViewer(self):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   262
        pass
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   263
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   264
    def SetHighlight(self, highlight):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   265
        if self.Highlight != highlight:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   266
            self.Highlight = highlight
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   267
            return True
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   268
        return False
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   269
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   270
    def GetButtons(self):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   271
        return self.Buttons
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   272
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   273
    def HandleButtons(self, x, y):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   274
        for button in self.GetButtons():
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   275
            if button.HitTest(x, y):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   276
                button.ProcessCallback()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   277
                return True
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   278
        return False
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   279
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   280
    def IsOverButton(self, x, y):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   281
        for button in self.GetButtons():
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   282
            if button.HitTest(x, y):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   283
                return True
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   284
        return False
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   285
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   286
    def ShowButtons(self, show):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   287
        for button in self.Buttons:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   288
            if show:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   289
                button.Show()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   290
            else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   291
                button.Hide()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   292
        self.RefreshButtonsState()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   293
        self.ParentWindow.ForceRefresh()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   294
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   295
    def RefreshButtonsState(self, refresh_positions=False):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   296
        if self:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   297
            width, height = self.GetSize()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   298
            if refresh_positions:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   299
                offset = 0
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   300
                buttons = self.Buttons[:]
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   301
                buttons.reverse()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   302
                for button in buttons:
1199
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
   303
                    if button.IsEnabled():
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
   304
                        w, h = button.GetSize()
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
   305
                        button.SetPosition(width - 5 - w - offset, 5)
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
   306
                        offset += w + 2
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   307
                self.ParentWindow.ForceRefresh()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   308
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   309
    def DrawCommonElements(self, dc, buttons=None):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   310
        width, height = self.GetSize()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   311
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   312
        dc.SetPen(HIGHLIGHT_DROP_PEN)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   313
        dc.SetBrush(HIGHLIGHT_DROP_BRUSH)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   314
        if self.Highlight in [HIGHLIGHT_BEFORE]:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   315
            dc.DrawLine(0, 1, width - 1, 1)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   316
        elif self.Highlight in [HIGHLIGHT_AFTER]:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   317
            dc.DrawLine(0, height - 1, width - 1, height - 1)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   318
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   319
        if buttons is None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   320
            buttons = self.Buttons
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   321
        for button in buttons:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   322
            button.Draw(dc)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   323
            
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   324
        if self.ParentWindow.IsDragging():
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   325
            destBBox = self.ParentWindow.GetDraggingAxesClippingRegion(self)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   326
            srcPos = self.ParentWindow.GetDraggingAxesPosition(self)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   327
            if destBBox.width > 0 and destBBox.height > 0:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   328
                srcPanel = self.ParentWindow.DraggingAxesPanel
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   329
                srcBBox = srcPanel.GetAxesBoundingBox()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   330
                
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   331
                if destBBox.x == 0:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   332
                    srcX = srcBBox.x - srcPos.x
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
   333
                else:
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   334
                    srcX = srcBBox.x
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   335
                if destBBox.y == 0:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   336
                    srcY = srcBBox.y - srcPos.y
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   337
                else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   338
                    srcY = srcBBox.y
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   339
                
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   340
                srcBmp = _convert_agg_to_wx_bitmap(srcPanel.get_renderer(), None)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   341
                srcDC = wx.MemoryDC()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   342
                srcDC.SelectObject(srcBmp)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   343
                
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   344
                dc.Blit(destBBox.x, destBBox.y, 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   345
                        int(destBBox.width), int(destBBox.height), 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   346
                        srcDC, srcX, srcY)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   347
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   348
    def OnEnter(self, event):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   349
        self.ShowButtons(True)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   350
        event.Skip()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   351
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   352
    def OnLeave(self, event):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   353
        if self.Highlight != HIGHLIGHT_RESIZE or self.CanvasStartSize is None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   354
            x, y = event.GetPosition()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   355
            width, height = self.GetSize()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   356
            if (x <= 0 or x >= width - 1 or
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   357
                y <= 0 or y >= height - 1):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   358
                self.ShowButtons(False)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   359
        event.Skip()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   360
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   361
    def OnCloseButton(self):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   362
        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
   363
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   364
    def OnForceButton(self):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   365
        wx.CallAfter(self.ForceValue, self.Items[0])
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   366
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   367
    def OnReleaseButton(self):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   368
        wx.CallAfter(self.ReleaseValue, self.Items[0])
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   369
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   370
    def OnResizeWindow(self, event):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   371
        wx.CallAfter(self.RefreshButtonsState, True)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   372
        event.Skip()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   373
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   374
    def OnMouseDragging(self, x, y):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   375
        xw, yw = self.GetPosition()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   376
        self.ParentWindow.RefreshHighlight(x + xw, y + yw)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   377
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   378
    def OnDragging(self, x, y):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   379
        width, height = self.GetSize()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   380
        if y < height / 2:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   381
            if self.ParentWindow.IsViewerFirst(self):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   382
                self.SetHighlight(HIGHLIGHT_BEFORE)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   383
            else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   384
                self.SetHighlight(HIGHLIGHT_NONE)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   385
                self.ParentWindow.HighlightPreviousViewer(self)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   386
        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   387
            self.SetHighlight(HIGHLIGHT_AFTER)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   388
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   389
    def OnEraseBackground(self, event):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   390
        pass
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   391
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   392
    def OnResize(self, event):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   393
        wx.CallAfter(self.RefreshButtonsState, True)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   394
        event.Skip()
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 ForceValue(self, item):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   397
        iec_path = item.GetVariable()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   398
        iec_type = self.ParentWindow.GetDataType(iec_path)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   399
        if iec_type is not None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   400
            dialog = ForceVariableDialog(self, iec_type, str(item.GetValue()))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   401
            if dialog.ShowModal() == wx.ID_OK:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   402
                self.ParentWindow.ForceDataValue(iec_path.upper(), dialog.GetValue())
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   403
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   404
    def ReleaseValue(self, item):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   405
        iec_path = item.GetVariable().upper()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   406
        self.ParentWindow.ReleaseDataValue(iec_path)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   407
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   408
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   409
class DebugVariableText(DebugVariableViewer, wx.Panel):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   410
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   411
    def __init__(self, parent, window, items=[]):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   412
        DebugVariableViewer.__init__(self, window, items)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   413
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   414
        wx.Panel.__init__(self, parent)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   415
        self.SetBackgroundColour(wx.WHITE)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   416
        self.SetDropTarget(DebugVariableDropTarget(window, self))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   417
        self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   418
        self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   419
        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
   420
        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
   421
        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
   422
        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
   423
        self.Bind(wx.EVT_PAINT, self.OnPaint)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   424
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   425
        self.SetMinSize(wx.Size(0, 25))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   426
        
1199
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
   427
        for bitmap, callback in [("force", self.OnForceButton),
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
   428
                                 ("release", self.OnReleaseButton),
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
   429
                                 ("delete_graph", self.OnCloseButton)]:
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
   430
            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
   431
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   432
        self.ShowButtons(False)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   433
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   434
    def RefreshViewer(self):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   435
        width, height = self.GetSize()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   436
        bitmap = wx.EmptyBitmap(width, height)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   437
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   438
        dc = wx.BufferedDC(wx.ClientDC(self), bitmap)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   439
        dc.Clear()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   440
        dc.BeginDrawing()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   441
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   442
        gc = wx.GCDC(dc)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   443
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   444
        item_name = self.Items[0].GetVariable(self.ParentWindow.GetVariableNameMask())
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   445
        w, h = gc.GetTextExtent(item_name)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   446
        gc.DrawText(item_name, 20, (height - h) / 2)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   447
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   448
        if self.Items[0].IsForced():
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   449
            gc.SetTextForeground(wx.BLUE)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   450
            self.Buttons[0].Disable()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   451
            self.Buttons[1].Enable()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   452
        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   453
            self.Buttons[1].Disable()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   454
            self.Buttons[0].Enable()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   455
        self.RefreshButtonsState(True)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   456
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   457
        item_value = self.Items[0].GetValue()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   458
        w, h = gc.GetTextExtent(item_value)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   459
        gc.DrawText(item_value, width - 40 - w, (height - h) / 2)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   460
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   461
        self.DrawCommonElements(gc)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   462
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   463
        gc.EndDrawing()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   464
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   465
    def OnLeftDown(self, event):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   466
        width, height = self.GetSize()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   467
        item_name = self.Items[0].GetVariable(self.ParentWindow.GetVariableNameMask())
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   468
        w, h = self.GetTextExtent(item_name)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   469
        x, y = event.GetPosition()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   470
        rect = wx.Rect(20, (height - h) / 2, w, h)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   471
        if rect.InsideXY(x, y):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   472
            data = wx.TextDataObject(str((self.Items[0].GetVariable(), "debug", "move")))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   473
            dragSource = wx.DropSource(self)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   474
            dragSource.SetData(data)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   475
            dragSource.DoDragDrop()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   476
        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   477
            event.Skip()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   478
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   479
    def OnLeftUp(self, event):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   480
        x, y = event.GetPosition()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   481
        wx.CallAfter(self.HandleButtons, x, y)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   482
        event.Skip()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   483
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   484
    def OnPaint(self, event):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   485
        self.RefreshViewer()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   486
        event.Skip()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   487
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   488
class DebugVariableGraphic(DebugVariableViewer, FigureCanvas):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   489
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   490
    def __init__(self, parent, window, items, graph_type):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   491
        DebugVariableViewer.__init__(self, window, items)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   492
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   493
        self.CanvasSize = SIZE_MINI
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   494
        self.GraphType = graph_type
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   495
        self.CursorTick = None
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   496
        self.MouseStartPos = None
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   497
        self.StartCursorTick = None
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   498
        self.CanvasStartSize = None
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   499
        self.ContextualButtons = []
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   500
        self.ContextualButtonsItem = None
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   501
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   502
        self.Figure = matplotlib.figure.Figure(facecolor='w')
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   503
        self.Figure.subplotpars.update(top=0.95, left=0.1, bottom=0.1, right=0.95)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   504
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   505
        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
   506
        self.SetWindowStyle(wx.WANTS_CHARS)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   507
        self.SetBackgroundColour(wx.WHITE)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   508
        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
   509
        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
   510
        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
   511
        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
   512
        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
   513
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   514
        canvas_size = self.GetCanvasMinSize()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   515
        self.SetMinSize(canvas_size)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   516
        self.SetDropTarget(DebugVariableDropTarget(self.ParentWindow, self))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   517
        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
   518
        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
   519
        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
   520
        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
   521
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   522
        for size, bitmap in zip([SIZE_MINI, SIZE_MIDDLE, SIZE_MAXI],
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   523
                                ["minimize_graph", "middle_graph", "maximize_graph"]):
1199
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
   524
            self.Buttons.append(GraphButton(0, 0, bitmap, self.GetOnChangeSizeButton(size)))
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
   525
        for bitmap, callback in [("export_graph_mini", self.OnExportGraphButton),
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
   526
                                 ("delete_graph", self.OnCloseButton)]:
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
   527
            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
   528
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   529
        self.ResetGraphics()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   530
        self.RefreshLabelsPosition(canvas_size.height)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   531
        self.ShowButtons(False)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   532
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   533
    def draw(self, drawDC=None):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   534
        FigureCanvasAgg.draw(self)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   535
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   536
        self.bitmap = _convert_agg_to_wx_bitmap(self.get_renderer(), None)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   537
        self.bitmap.UseAlpha() 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   538
        width, height = self.GetSize()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   539
        bbox = self.GetAxesBoundingBox()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   540
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   541
        destDC = wx.MemoryDC()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   542
        destDC.SelectObject(self.bitmap)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   543
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   544
        destGC = wx.GCDC(destDC)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   545
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   546
        destGC.BeginDrawing()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   547
        if self.Highlight == HIGHLIGHT_RESIZE:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   548
            destGC.SetPen(HIGHLIGHT_RESIZE_PEN)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   549
            destGC.SetBrush(HIGHLIGHT_RESIZE_BRUSH)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   550
            destGC.DrawRectangle(0, height - 5, width, 5)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   551
        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   552
            destGC.SetPen(HIGHLIGHT_DROP_PEN)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   553
            destGC.SetBrush(HIGHLIGHT_DROP_BRUSH)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   554
            if self.Highlight == HIGHLIGHT_LEFT:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   555
                destGC.DrawRectangle(bbox.x, bbox.y, 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   556
                                     bbox.width / 2, bbox.height)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   557
            elif self.Highlight == HIGHLIGHT_RIGHT:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   558
                destGC.DrawRectangle(bbox.x + bbox.width / 2, bbox.y, 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   559
                                     bbox.width / 2, bbox.height)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   560
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   561
        self.DrawCommonElements(destGC, self.Buttons + self.ContextualButtons)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   562
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   563
        destGC.EndDrawing()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   564
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   565
        self._isDrawn = True
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   566
        self.gui_repaint(drawDC=drawDC)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   567
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   568
    def GetButtons(self):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   569
        return self.Buttons + self.ContextualButtons
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   570
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   571
    def PopupContextualButtons(self, item, rect, style=wx.RIGHT):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   572
        if self.ContextualButtonsItem is not None and item != self.ContextualButtonsItem:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   573
            self.DismissContextualButtons()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   574
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   575
        if self.ContextualButtonsItem is None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   576
            self.ContextualButtonsItem = item
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   577
            
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   578
            if self.ContextualButtonsItem.IsForced():
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   579
                self.ContextualButtons.append(
1199
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
   580
                    GraphButton(0, 0, "release", self.OnReleaseButton))
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
   581
            for bitmap, callback in [("force", self.OnForceButton),
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
   582
                                     ("export_graph_mini", self.OnExportItemGraphButton),
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
   583
                                     ("delete_graph", self.OnRemoveItemButton)]:
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
   584
                self.ContextualButtons.append(GraphButton(0, 0, bitmap, callback))
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
   585
            
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   586
            offset = 0
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   587
            buttons = self.ContextualButtons[:]
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   588
            if style in [wx.TOP, wx.LEFT]:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   589
                 buttons.reverse()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   590
            for button in buttons:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   591
                w, h = button.GetSize()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   592
                if style in [wx.LEFT, wx.RIGHT]:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   593
                    if style == wx.LEFT:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   594
                        x = rect.x - w - offset
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   595
                    else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   596
                        x = rect.x + rect.width + offset
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   597
                    y = rect.y + (rect.height - h) / 2
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   598
                    offset += w
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   599
                else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   600
                    x = rect.x + (rect.width - w ) / 2
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   601
                    if style == wx.TOP:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   602
                        y = rect.y - h - offset
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   603
                    else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   604
                        y = rect.y + rect.height + offset
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   605
                    offset += h
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   606
                button.SetPosition(x, y)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   607
            self.ParentWindow.ForceRefresh()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   608
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   609
    def DismissContextualButtons(self):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   610
        if self.ContextualButtonsItem is not None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   611
            self.ContextualButtonsItem = None
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   612
            self.ContextualButtons = []
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   613
            self.ParentWindow.ForceRefresh()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   614
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   615
    def IsOverContextualButton(self, x, y):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   616
        for button in self.ContextualButtons:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   617
            if button.HitTest(x, y):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   618
                return True
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   619
        return False
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   620
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   621
    def SetMinSize(self, size):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   622
        wx.Window.SetMinSize(self, size)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   623
        wx.CallAfter(self.RefreshButtonsState)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   624
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   625
    def GetOnChangeSizeButton(self, size):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   626
        def OnChangeSizeButton():
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   627
            self.CanvasSize = size
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   628
            self.SetCanvasSize(200, self.CanvasSize)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   629
        return OnChangeSizeButton
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   630
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   631
    def OnExportGraphButton(self):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   632
        self.ExportGraph()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   633
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   634
    def OnForceButton(self):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   635
        wx.CallAfter(self.ForceValue, 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   636
                     self.ContextualButtonsItem)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   637
        self.DismissContextualButtons()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   638
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   639
    def OnReleaseButton(self):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   640
        wx.CallAfter(self.ReleaseValue, 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   641
                     self.ContextualButtonsItem)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   642
        self.DismissContextualButtons()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   643
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   644
    def OnExportItemGraphButton(self):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   645
        wx.CallAfter(self.ExportGraph, 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   646
                     self.ContextualButtonsItem)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   647
        self.DismissContextualButtons()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   648
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   649
    def OnRemoveItemButton(self):            
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   650
        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
   651
                     self.ContextualButtonsItem)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   652
        self.DismissContextualButtons()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   653
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   654
    def RefreshLabelsPosition(self, height):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   655
        canvas_ratio = 1. / height
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   656
        graph_ratio = 1. / ((1.0 - (CANVAS_BORDER[0] + CANVAS_BORDER[1]) * canvas_ratio) * height)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   657
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   658
        self.Figure.subplotpars.update(
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   659
            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
   660
            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
   661
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   662
        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
   663
            num_item = len(self.Items)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   664
            for idx in xrange(num_item):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   665
                if not self.Is3DCanvas():
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   666
                    self.AxesLabels[idx].set_position(
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   667
                        (0.05, 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   668
                         1.0 - (CANVAS_PADDING + AXES_LABEL_HEIGHT * idx) * graph_ratio))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   669
                self.Labels[idx].set_position(
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   670
                    (0.95, 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   671
                     CANVAS_PADDING * graph_ratio + 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   672
                     (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
   673
        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   674
            self.AxesLabels[0].set_position((0.1, CANVAS_PADDING * graph_ratio))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   675
            self.Labels[0].set_position((0.95, CANVAS_PADDING * graph_ratio))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   676
            self.AxesLabels[1].set_position((0.05, 2 * CANVAS_PADDING * graph_ratio))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   677
            self.Labels[1].set_position((0.05, 1.0 - CANVAS_PADDING * graph_ratio))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   678
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   679
        self.Figure.subplots_adjust()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   680
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   681
    def GetCanvasMinSize(self):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   682
        return wx.Size(200, 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   683
                       CANVAS_BORDER[0] + CANVAS_BORDER[1] + 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   684
                       2 * CANVAS_PADDING + VALUE_LABEL_HEIGHT * len(self.Items))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   685
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   686
    def SetCanvasSize(self, width, height):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   687
        height = max(height, self.GetCanvasMinSize()[1])
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   688
        self.SetMinSize(wx.Size(width, height))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   689
        self.RefreshLabelsPosition(height)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   690
        self.RefreshButtonsState()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   691
        self.ParentWindow.RefreshGraphicsSizer()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   692
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   693
    def GetAxesBoundingBox(self, absolute=False):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   694
        width, height = self.GetSize()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   695
        ax, ay, aw, ah = self.figure.gca().get_position().bounds
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   696
        bbox = wx.Rect(ax * width, height - (ay + ah) * height - 1,
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   697
                       aw * width + 2, ah * height + 1)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   698
        if absolute:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   699
            xw, yw = self.GetPosition()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   700
            bbox.x += xw
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   701
            bbox.y += yw
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   702
        return bbox
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   703
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   704
    def OnCanvasButtonPressed(self, event):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   705
        width, height = self.GetSize()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   706
        x, y = event.x, height - event.y
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   707
        if not self.IsOverButton(x, y):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   708
            if event.inaxes == self.Axes:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   709
                item_idx = None
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   710
                for i, t in ([pair for pair in enumerate(self.AxesLabels)] + 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   711
                             [pair for pair in enumerate(self.Labels)]):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   712
                    (x0, y0), (x1, y1) = t.get_window_extent().get_points()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   713
                    rect = wx.Rect(x0, height - y1, x1 - x0, y1 - y0)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   714
                    if rect.InsideXY(x, y):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   715
                        item_idx = i
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   716
                        break
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   717
                if item_idx is not None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   718
                    self.ShowButtons(False)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   719
                    self.DismissContextualButtons()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   720
                    xw, yw = self.GetPosition()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   721
                    self.ParentWindow.StartDragNDrop(self, 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   722
                        self.Items[item_idx], x + xw, y + yw, x + xw, y + yw)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   723
                elif not self.Is3DCanvas():
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   724
                    self.MouseStartPos = wx.Point(x, y)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   725
                    if event.button == 1 and event.inaxes == self.Axes:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   726
                        self.StartCursorTick = self.CursorTick
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   727
                        self.HandleCursorMove(event)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   728
                    elif event.button == 2 and self.GraphType == GRAPH_PARALLEL:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   729
                        width, height = self.GetSize()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   730
                        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
   731
                        self.StartCursorTick = start_tick
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   732
            
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   733
            elif event.button == 1 and event.y <= 5:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   734
                self.MouseStartPos = wx.Point(x, y)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   735
                self.CanvasStartSize = self.GetSize()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   736
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   737
    def OnCanvasButtonReleased(self, event):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   738
        if self.ParentWindow.IsDragging():
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   739
            width, height = self.GetSize()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   740
            xw, yw = self.GetPosition()
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   741
            self.ParentWindow.StopDragNDrop(
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   742
                self.ParentWindow.DraggingAxesPanel.Items[0].GetVariable(),
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   743
                xw + event.x, 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   744
                yw + height - event.y)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   745
        else:
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   746
            self.MouseStartPos = None
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   747
            self.StartCursorTick = None
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   748
            self.CanvasStartSize = None
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   749
            width, height = self.GetSize()
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   750
            self.HandleButtons(event.x, height - event.y)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   751
            if event.y > 5 and self.SetHighlight(HIGHLIGHT_NONE):
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   752
                self.SetCursor(wx.NullCursor)
937
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
   753
                self.ParentWindow.ForceRefresh()
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   754
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   755
    def OnCanvasMotion(self, event):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   756
        width, height = self.GetSize()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   757
        if self.ParentWindow.IsDragging():
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   758
            xw, yw = self.GetPosition()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   759
            self.ParentWindow.MoveDragNDrop(
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   760
                xw + event.x, 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   761
                yw + height - event.y)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   762
        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   763
            if not self.Is3DCanvas():
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   764
                if event.button == 1 and self.CanvasStartSize is None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   765
                    if event.inaxes == self.Axes:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   766
                        if self.MouseStartPos is not None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   767
                            self.HandleCursorMove(event)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   768
                    elif self.MouseStartPos is not None and len(self.Items) == 1:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   769
                        xw, yw = self.GetPosition()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   770
                        self.ParentWindow.SetCursorTick(self.StartCursorTick)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   771
                        self.ParentWindow.StartDragNDrop(self, 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   772
                            self.Items[0],
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   773
                            event.x + xw, height - event.y + yw, 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   774
                            self.MouseStartPos.x + xw, self.MouseStartPos.y + yw)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   775
                elif event.button == 2 and self.GraphType == GRAPH_PARALLEL and self.MouseStartPos is not None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   776
                    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
   777
                    rect = self.GetAxesBoundingBox()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   778
                    self.ParentWindow.SetCanvasPosition(
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   779
                        self.StartCursorTick + (self.MouseStartPos.x - event.x) *
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   780
                        (end_tick - start_tick) / rect.width)    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   781
            
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   782
            if event.button == 1 and self.CanvasStartSize is not None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   783
                width, height = self.GetSize()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   784
                self.SetCanvasSize(width, 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   785
                    self.CanvasStartSize.height + height - event.y - self.MouseStartPos.y)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   786
                
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   787
            elif event.button in [None, "up", "down"]:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   788
                if self.GraphType == GRAPH_PARALLEL:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   789
                    orientation = [wx.RIGHT] * len(self.AxesLabels) + [wx.LEFT] * len(self.Labels)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   790
                elif len(self.AxesLabels) > 0:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   791
                    orientation = [wx.RIGHT, wx.TOP, wx.LEFT, wx.BOTTOM]
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   792
                else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   793
                    orientation = [wx.LEFT] * len(self.Labels)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   794
                item_idx = None
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   795
                item_style = None
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   796
                for (i, t), style in zip([pair for pair in enumerate(self.AxesLabels)] + 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   797
                                         [pair for pair in enumerate(self.Labels)], 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   798
                                         orientation):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   799
                    (x0, y0), (x1, y1) = t.get_window_extent().get_points()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   800
                    rect = wx.Rect(x0, height - y1, x1 - x0, y1 - y0)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   801
                    if rect.InsideXY(event.x, height - event.y):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   802
                        item_idx = i
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   803
                        item_style = style
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   804
                        break
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   805
                if item_idx is not None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   806
                    self.PopupContextualButtons(self.Items[item_idx], rect, item_style)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   807
                    return 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   808
                if not self.IsOverContextualButton(event.x, height - event.y):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   809
                    self.DismissContextualButtons()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   810
                
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   811
                if event.y <= 5:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   812
                    if self.SetHighlight(HIGHLIGHT_RESIZE):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   813
                        self.SetCursor(wx.StockCursor(wx.CURSOR_SIZENS))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   814
                        self.ParentWindow.ForceRefresh()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   815
                else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   816
                    if self.SetHighlight(HIGHLIGHT_NONE):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   817
                        self.SetCursor(wx.NullCursor)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   818
                        self.ParentWindow.ForceRefresh()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   819
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   820
    def OnCanvasScroll(self, event):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   821
        if event.inaxes is not None and event.guiEvent.ControlDown():
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   822
            if self.GraphType == GRAPH_ORTHOGONAL:
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   823
                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
   824
                tick = (start_tick + end_tick) / 2.
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   825
            else:
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   826
                tick = event.xdata
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   827
            self.ParentWindow.ChangeRange(int(-event.step) / 3, tick)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   828
            self.ParentWindow.VetoScrollEvent = True
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   829
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   830
    def OnDragging(self, x, y):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   831
        width, height = self.GetSize()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   832
        bbox = self.GetAxesBoundingBox()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   833
        if bbox.InsideXY(x, y) and not self.Is3DCanvas():
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   834
            rect = wx.Rect(bbox.x, bbox.y, bbox.width / 2, bbox.height)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   835
            if rect.InsideXY(x, y):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   836
                self.SetHighlight(HIGHLIGHT_LEFT)
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
   837
            else:
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   838
                self.SetHighlight(HIGHLIGHT_RIGHT)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   839
        elif y < height / 2:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   840
            if self.ParentWindow.IsViewerFirst(self):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   841
                self.SetHighlight(HIGHLIGHT_BEFORE)
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   842
            else:
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   843
                self.SetHighlight(HIGHLIGHT_NONE)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   844
                self.ParentWindow.HighlightPreviousViewer(self)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   845
        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   846
            self.SetHighlight(HIGHLIGHT_AFTER)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   847
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   848
    def OnLeave(self, event):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   849
        if self.CanvasStartSize is None and self.SetHighlight(HIGHLIGHT_NONE):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   850
            self.SetCursor(wx.NullCursor)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   851
            self.ParentWindow.ForceRefresh()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   852
        DebugVariableViewer.OnLeave(self, event)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   853
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   854
    KEY_CURSOR_INCREMENT = {
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   855
        wx.WXK_LEFT: -1,
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   856
        wx.WXK_RIGHT: 1,
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   857
        wx.WXK_UP: -10,
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   858
        wx.WXK_DOWN: 10}
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   859
    def OnKeyDown(self, event):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   860
        if self.CursorTick is not None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   861
            move = self.KEY_CURSOR_INCREMENT.get(event.GetKeyCode(), None)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   862
            if move is not None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   863
                self.ParentWindow.MoveCursorTick(move)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   864
        event.Skip()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   865
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   866
    def HandleCursorMove(self, event):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   867
        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
   868
        cursor_tick = None
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   869
        if self.GraphType == GRAPH_ORTHOGONAL:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   870
            x_data = self.Items[0].GetData(start_tick, end_tick)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   871
            y_data = self.Items[1].GetData(start_tick, end_tick)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   872
            if len(x_data) > 0 and len(y_data) > 0:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   873
                length = min(len(x_data), len(y_data))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   874
                d = numpy.sqrt((x_data[:length,1]-event.xdata) ** 2 + (y_data[:length,1]-event.ydata) ** 2)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   875
                cursor_tick = x_data[numpy.argmin(d), 0]
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   876
        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   877
            data = self.Items[0].GetData(start_tick, end_tick)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   878
            if len(data) > 0:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   879
                cursor_tick = data[numpy.argmin(numpy.abs(data[:,0] - event.xdata)), 0]
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   880
        if cursor_tick is not None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   881
            self.ParentWindow.SetCursorTick(cursor_tick)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   882
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   883
    def OnAxesMotion(self, event):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   884
        if self.Is3DCanvas():
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   885
            current_time = gettime()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   886
            if current_time - self.LastMotionTime > REFRESH_PERIOD:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   887
                self.LastMotionTime = current_time
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   888
                Axes3D._on_move(self.Axes, event)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   889
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   890
    def ResetGraphics(self):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   891
        self.Figure.clear()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   892
        if self.Is3DCanvas():
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   893
            self.Axes = self.Figure.gca(projection='3d')
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   894
            self.Axes.set_color_cycle(['b'])
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   895
            self.LastMotionTime = gettime()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   896
            setattr(self.Axes, "_on_move", self.OnAxesMotion)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   897
            self.Axes.mouse_init()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   898
            self.Axes.tick_params(axis='z', labelsize='small')
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   899
        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   900
            self.Axes = self.Figure.gca()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   901
            self.Axes.set_color_cycle(color_cycle)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   902
        self.Axes.tick_params(axis='x', labelsize='small')
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   903
        self.Axes.tick_params(axis='y', labelsize='small')
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   904
        self.Plots = []
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   905
        self.VLine = None
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   906
        self.HLine = None
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   907
        self.Labels = []
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   908
        self.AxesLabels = []
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   909
        if not self.Is3DCanvas():
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   910
            text_func = self.Axes.text
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   911
        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   912
            text_func = self.Axes.text2D
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   913
        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
   914
            num_item = len(self.Items)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   915
            for idx in xrange(num_item):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   916
                if num_item == 1:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   917
                    color = 'k'
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   918
                else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   919
                    color = color_cycle[idx % len(color_cycle)]
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   920
                if not self.Is3DCanvas():
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   921
                    self.AxesLabels.append(
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   922
                        text_func(0, 0, "", size='small',
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   923
                                  verticalalignment='top', 
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   924
                                  color=color,
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
   925
                                  transform=self.Axes.transAxes))
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   926
                self.Labels.append(
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   927
                    text_func(0, 0, "", size='large', 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   928
                              horizontalalignment='right',
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   929
                              color=color,
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   930
                              transform=self.Axes.transAxes))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   931
        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   932
            self.AxesLabels.append(
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   933
                self.Axes.text(0, 0, "", size='small',
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   934
                               transform=self.Axes.transAxes))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   935
            self.Labels.append(
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   936
                self.Axes.text(0, 0, "", size='large',
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   937
                               horizontalalignment='right',
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   938
                               transform=self.Axes.transAxes))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   939
            self.AxesLabels.append(
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   940
                self.Axes.text(0, 0, "", size='small',
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   941
                               rotation='vertical',
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   942
                               verticalalignment='bottom',
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   943
                               transform=self.Axes.transAxes))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   944
            self.Labels.append(
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   945
                self.Axes.text(0, 0, "", size='large',
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   946
                               rotation='vertical',
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   947
                               verticalalignment='top',
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   948
                               transform=self.Axes.transAxes))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   949
        width, height = self.GetSize()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   950
        self.RefreshLabelsPosition(height)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   951
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   952
    def AddItem(self, item):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   953
        DebugVariableViewer.AddItem(self, item)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   954
        self.ResetGraphics()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   955
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   956
    def RemoveItem(self, item):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   957
        DebugVariableViewer.RemoveItem(self, item)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   958
        if not self.IsEmpty():
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   959
            if len(self.Items) == 1:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   960
                self.GraphType = GRAPH_PARALLEL
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   961
            self.ResetGraphics()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   962
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   963
    def UnregisterObsoleteData(self):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   964
        DebugVariableViewer.UnregisterObsoleteData(self)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   965
        if not self.IsEmpty():
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   966
            self.ResetGraphics()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   967
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   968
    def Is3DCanvas(self):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   969
        return self.GraphType == GRAPH_ORTHOGONAL and len(self.Items) == 3
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   970
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   971
    def SetCursorTick(self, cursor_tick):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   972
        self.CursorTick = cursor_tick
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   973
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   974
    def RefreshViewer(self, refresh_graphics=True):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   975
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   976
        if refresh_graphics:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   977
            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
   978
            
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   979
            if self.GraphType == GRAPH_PARALLEL:    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   980
                min_value = max_value = None
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   981
                
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   982
                for idx, item in enumerate(self.Items):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   983
                    data = item.GetData(start_tick, end_tick)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   984
                    if data is not None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   985
                        item_min_value, item_max_value = item.GetValueRange()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   986
                        if min_value is None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   987
                            min_value = item_min_value
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   988
                        elif item_min_value is not None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   989
                            min_value = min(min_value, item_min_value)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   990
                        if max_value is None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   991
                            max_value = item_max_value
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   992
                        elif item_max_value is not None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   993
                            max_value = max(max_value, item_max_value)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   994
                        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   995
                        if len(self.Plots) <= idx:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   996
                            self.Plots.append(
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   997
                                self.Axes.plot(data[:, 0], data[:, 1])[0])
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   998
                        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   999
                            self.Plots[idx].set_data(data[:, 0], data[:, 1])
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1000
                    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1001
                if min_value is not None and max_value is not None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1002
                    y_center = (min_value + max_value) / 2.
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1003
                    y_range = max(1.0, max_value - min_value)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1004
                else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1005
                    y_center = 0.5
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1006
                    y_range = 1.0
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1007
                x_min, x_max = start_tick, end_tick
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1008
                y_min, y_max = y_center - y_range * 0.55, y_center + y_range * 0.55
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1009
                
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1010
                if self.CursorTick is not None and start_tick <= self.CursorTick <= end_tick:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1011
                    if self.VLine is None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1012
                        self.VLine = self.Axes.axvline(self.CursorTick, color=cursor_color)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1013
                    else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1014
                        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
  1015
                    self.VLine.set_visible(True)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1016
                else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1017
                    if self.VLine is not None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1018
                        self.VLine.set_visible(False)
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1019
            else:
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1020
                min_start_tick = reduce(max, [item.GetData()[0, 0] 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1021
                                              for item in self.Items
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1022
                                              if len(item.GetData()) > 0], 0)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1023
                start_tick = max(start_tick, min_start_tick)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1024
                end_tick = max(end_tick, min_start_tick)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1025
                x_data, x_min, x_max = OrthogonalData(self.Items[0], start_tick, end_tick)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1026
                y_data, y_min, y_max = OrthogonalData(self.Items[1], start_tick, end_tick)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1027
                if self.CursorTick is not None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1028
                    x_cursor, x_forced = self.Items[0].GetValue(self.CursorTick, raw=True)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1029
                    y_cursor, y_forced = self.Items[1].GetValue(self.CursorTick, raw=True)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1030
                length = 0
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1031
                if x_data is not None and y_data is not None:  
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1032
                    length = min(len(x_data), len(y_data))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1033
                if len(self.Items) < 3:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1034
                    if x_data is not None and y_data is not None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1035
                        if len(self.Plots) == 0:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1036
                            self.Plots.append(
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1037
                                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
  1038
                                               y_data[:, 1][:length])[0])
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1039
                        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1040
                            self.Plots[0].set_data(
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1041
                                x_data[:, 1][:length], 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1042
                                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
  1043
                    
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1044
                    if self.CursorTick is not None and start_tick <= self.CursorTick <= end_tick:
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1045
                        if self.VLine is None:
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1046
                            self.VLine = self.Axes.axvline(x_cursor, color=cursor_color)
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1047
                        else:
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1048
                            self.VLine.set_xdata((x_cursor, x_cursor))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1049
                        if self.HLine is None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1050
                            self.HLine = self.Axes.axhline(y_cursor, color=cursor_color)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1051
                        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1052
                            self.HLine.set_ydata((y_cursor, y_cursor))
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1053
                        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
  1054
                        self.HLine.set_visible(True)
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1055
                    else:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1056
                        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
  1057
                            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
  1058
                        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
  1059
                            self.HLine.set_visible(False)
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
  1060
                else:
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1061
                    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
  1062
                        self.Axes.lines.pop()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1063
                    z_data, z_min, z_max = OrthogonalData(self.Items[2], start_tick, end_tick)
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1064
                    if self.CursorTick is not None:
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1065
                        z_cursor, z_forced = self.Items[2].GetValue(self.CursorTick, raw=True)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1066
                    if x_data is not None and y_data is not None and z_data is not None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1067
                        length = min(length, len(z_data))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1068
                        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
  1069
                                       y_data[:, 1][:length],
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1070
                                       zs = z_data[:, 1][:length])
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1071
                    self.Axes.set_zlim(z_min, z_max)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1072
                    if self.CursorTick is not None and start_tick <= self.CursorTick <= end_tick:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1073
                        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
  1074
                                       {"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
  1075
                                       {"zs": numpy.array([z_min, z_max])}]:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1076
                            for param, value in [("xs", numpy.array([x_cursor, x_cursor])),
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1077
                                                 ("ys", numpy.array([y_cursor, y_cursor])),
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1078
                                                 ("zs", numpy.array([z_cursor, z_cursor]))]:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1079
                                kwargs.setdefault(param, value)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1080
                            kwargs["color"] = cursor_color
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1081
                            self.Axes.plot(**kwargs)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1082
                
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1083
            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
  1084
            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
  1085
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1086
        variable_name_mask = self.ParentWindow.GetVariableNameMask()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1087
        if self.CursorTick is not None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1088
            values, forced = apply(zip, [item.GetValue(self.CursorTick) for item in self.Items])
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1089
        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1090
            values, forced = apply(zip, [(item.GetValue(), item.IsForced()) for item in self.Items])
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1091
        labels = [item.GetVariable(variable_name_mask) for item in self.Items]
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1092
        styles = map(lambda x: {True: 'italic', False: 'normal'}[x], forced)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1093
        if self.Is3DCanvas():
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1094
            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
  1095
                                              self.Axes.set_ylabel,
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1096
                                              self.Axes.set_zlabel]):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1097
                label_func(labels[idx], fontdict={'size': 'small','color': color_cycle[idx]})
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1098
        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1099
            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
  1100
                label.set_text(text)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1101
        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
  1102
            label.set_text(value)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1103
            label.set_style(style)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1104
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1105
        self.draw()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1106
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1107
    def ExportGraph(self, item=None):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1108
        if item is not None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1109
            variables = [(item, [entry for entry in item.GetData()])]
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1110
        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1111
            variables = [(item, [entry for entry in item.GetData()])
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1112
                         for item in self.Items]
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1113
        self.ParentWindow.CopyDataToClipboard(variables)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1114
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1115
class DebugVariableGraphicPanel(wx.Panel, DebugViewer):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1116
    
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1117
    def __init__(self, parent, producer, window):
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
  1118
        wx.Panel.__init__(self, parent, style=wx.SP_3D|wx.TAB_TRAVERSAL)
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1119
        
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1120
        self.ParentWindow = window
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1121
        
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1122
        self.HasNewData = False
1008
1e5d285864f6 Fixed bugs in DebugVariablePanel when matplotlib not installed
Laurent Bessard
parents: 988
diff changeset
  1123
        self.Force = False
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
  1124
        
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1125
        self.SetBackgroundColour(wx.WHITE)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1126
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1127
        main_sizer = wx.BoxSizer(wx.VERTICAL)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1128
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1129
        self.Ticks = numpy.array([])
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1130
        self.StartTick = 0
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1131
        self.Fixed = False
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1132
        self.CursorTick = None
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1133
        self.DraggingAxesPanel = None
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1134
        self.DraggingAxesBoundingBox = None
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1135
        self.DraggingAxesMousePos = None
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1136
        self.VetoScrollEvent = False
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1137
        self.VariableNameMask = []
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1138
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1139
        self.GraphicPanels = []
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1140
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1141
        graphics_button_sizer = wx.BoxSizer(wx.HORIZONTAL)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1142
        main_sizer.AddSizer(graphics_button_sizer, border=5, flag=wx.GROW|wx.ALL)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1143
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1144
        range_label = wx.StaticText(self, label=_('Range:'))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1145
        graphics_button_sizer.AddWindow(range_label, flag=wx.ALIGN_CENTER_VERTICAL)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1146
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1147
        self.CanvasRange = wx.ComboBox(self, style=wx.CB_READONLY)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1148
        self.Bind(wx.EVT_COMBOBOX, self.OnRangeChanged, self.CanvasRange)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1149
        graphics_button_sizer.AddWindow(self.CanvasRange, 1, 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1150
              border=5, flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1151
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1152
        self.CanvasRange.Clear()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1153
        default_range_idx = 0
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1154
        for idx, (text, value) in enumerate(RANGE_VALUES):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1155
            self.CanvasRange.Append(text)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1156
            if text == "1s":
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1157
                default_range_idx = idx
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1158
        self.CanvasRange.SetSelection(default_range_idx)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1159
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1160
        for name, bitmap, help in [
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1161
            ("CurrentButton", "current", _("Go to current value")),
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1162
            ("ExportGraphButton", "export_graph", _("Export graph values to clipboard"))]:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1163
            button = wx.lib.buttons.GenBitmapButton(self, 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1164
                  bitmap=GetBitmap(bitmap), 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1165
                  size=wx.Size(28, 28), style=wx.NO_BORDER)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1166
            button.SetToolTipString(help)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1167
            setattr(self, name, button)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1168
            self.Bind(wx.EVT_BUTTON, getattr(self, "On" + name), button)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1169
            graphics_button_sizer.AddWindow(button, border=5, flag=wx.LEFT)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1170
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1171
        self.CanvasPosition = wx.ScrollBar(self, 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1172
              size=wx.Size(0, 16), style=wx.SB_HORIZONTAL)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1173
        self.CanvasPosition.Bind(wx.EVT_SCROLL_THUMBTRACK, 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1174
              self.OnPositionChanging, self.CanvasPosition)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1175
        self.CanvasPosition.Bind(wx.EVT_SCROLL_LINEUP, 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1176
              self.OnPositionChanging, self.CanvasPosition)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1177
        self.CanvasPosition.Bind(wx.EVT_SCROLL_LINEDOWN, 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1178
              self.OnPositionChanging, self.CanvasPosition)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1179
        self.CanvasPosition.Bind(wx.EVT_SCROLL_PAGEUP, 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1180
              self.OnPositionChanging, self.CanvasPosition)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1181
        self.CanvasPosition.Bind(wx.EVT_SCROLL_PAGEDOWN, 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1182
              self.OnPositionChanging, self.CanvasPosition)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1183
        main_sizer.AddWindow(self.CanvasPosition, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1184
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1185
        self.TickSizer = wx.BoxSizer(wx.HORIZONTAL)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1186
        main_sizer.AddSizer(self.TickSizer, border=5, flag=wx.ALL|wx.GROW)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1187
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1188
        self.TickLabel = wx.StaticText(self)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1189
        self.TickSizer.AddWindow(self.TickLabel, border=5, flag=wx.RIGHT)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1190
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1191
        self.MaskLabel = wx.TextCtrl(self, style=wx.TE_READONLY|wx.TE_CENTER|wx.NO_BORDER)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1192
        self.TickSizer.AddWindow(self.MaskLabel, 1, border=5, flag=wx.RIGHT|wx.GROW)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1193
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1194
        self.TickTimeLabel = wx.StaticText(self)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1195
        self.TickSizer.AddWindow(self.TickTimeLabel)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1196
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1197
        self.GraphicsWindow = wx.ScrolledWindow(self, style=wx.HSCROLL|wx.VSCROLL)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1198
        self.GraphicsWindow.SetBackgroundColour(wx.WHITE)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1199
        self.GraphicsWindow.SetDropTarget(DebugVariableDropTarget(self))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1200
        self.GraphicsWindow.Bind(wx.EVT_ERASE_BACKGROUND, self.OnGraphicsWindowEraseBackground)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1201
        self.GraphicsWindow.Bind(wx.EVT_PAINT, self.OnGraphicsWindowPaint)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1202
        self.GraphicsWindow.Bind(wx.EVT_SIZE, self.OnGraphicsWindowResize)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1203
        self.GraphicsWindow.Bind(wx.EVT_MOUSEWHEEL, self.OnGraphicsWindowMouseWheel)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1204
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1205
        main_sizer.AddWindow(self.GraphicsWindow, 1, flag=wx.GROW)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1206
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1207
        self.GraphicsSizer = wx.BoxSizer(wx.VERTICAL)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1208
        self.GraphicsWindow.SetSizer(self.GraphicsSizer)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1209
    
1192
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1210
        DebugViewer.__init__(self, producer, True)
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1211
        
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
  1212
        self.SetSizer(main_sizer)
1192
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1213
    
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1214
    def SetTickTime(self, ticktime=0):
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1215
        self.Ticktime = ticktime
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1216
        if self.Ticktime == 0:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1217
            self.Ticktime = MILLISECOND
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1218
        self.CurrentRange = RANGE_VALUES[
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1219
            self.CanvasRange.GetSelection()][1] / self.Ticktime
1192
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1220
    
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1221
    def SetDataProducer(self, producer):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1222
        DebugViewer.SetDataProducer(self, producer)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1223
        
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1224
        if self.DataProducer is not None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1225
            self.SetTickTime(self.DataProducer.GetTicktime())
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1226
    
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1227
    def RefreshNewData(self, *args, **kwargs):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1228
        if self.HasNewData or self.Force:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1229
            self.HasNewData = False
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1230
            self.RefreshView()
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1231
        DebugViewer.RefreshNewData(self, *args, **kwargs)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1232
    
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1233
    def NewDataAvailable(self, tick, *args, **kwargs):
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1234
        if tick is not None:
927
bd3e5b65e8be Fix bug when resetting graphs values
Laurent Bessard
parents: 925
diff changeset
  1235
            if len(self.Ticks) == 0:
bd3e5b65e8be Fix bug when resetting graphs values
Laurent Bessard
parents: 925
diff changeset
  1236
                self.StartTick = tick 
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1237
            self.Ticks = numpy.append(self.Ticks, [tick])
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1238
            if not self.Fixed or tick < self.StartTick + self.CurrentRange:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1239
                self.StartTick = max(self.StartTick, tick - self.CurrentRange)
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1240
            if self.Fixed and self.Ticks[-1] - self.Ticks[0] < self.CurrentRange:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1241
                self.Force = True
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1242
        DebugViewer.NewDataAvailable(self, tick, *args, **kwargs)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1243
    
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1244
    def ForceRefresh(self):
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1245
        self.Force = True
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1246
        wx.CallAfter(self.NewDataAvailable, None, True)
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1247
    
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
  1248
    def RefreshGraphicsSizer(self):
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
  1249
        self.GraphicsSizer.Clear()
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
  1250
        
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
  1251
        for panel in self.GraphicPanels:
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
  1252
            self.GraphicsSizer.AddWindow(panel, flag=wx.GROW)
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
  1253
            
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
  1254
        self.GraphicsSizer.Layout()
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
  1255
        self.RefreshGraphicsWindowScrollbars()
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
  1256
    
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1257
    def SetCanvasPosition(self, tick):
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1258
        tick = max(self.Ticks[0], min(tick, self.Ticks[-1] - self.CurrentRange))
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1259
        self.StartTick = self.Ticks[numpy.argmin(numpy.abs(self.Ticks - tick))]
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1260
        self.Fixed = True
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1261
        self.RefreshCanvasPosition()
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1262
        self.ForceRefresh()
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1263
    
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1264
    def SetCursorTick(self, cursor_tick):
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1265
        self.CursorTick = cursor_tick
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1266
        self.Fixed = True
1084
baa09a1c7b15 Fixed bug in DebugVariablePanel, cursor not reset when graphs were reset
Laurent Bessard
parents: 1044
diff changeset
  1267
        self.UpdateCursorTick() 
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1268
    
1174
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1269
    def MoveCursorTick(self, move):
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1270
        if self.CursorTick is not None:
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1271
            cursor_tick = max(self.Ticks[0], 
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1272
                          min(self.CursorTick + move, 
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1273
                              self.Ticks[-1]))
1192
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1274
            cursor_tick_idx = numpy.argmin(numpy.abs(self.Ticks - cursor_tick))
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1275
            if self.Ticks[cursor_tick_idx] == self.CursorTick:
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1276
                cursor_tick_idx = max(0, 
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1277
                                  min(cursor_tick_idx + abs(move) / move, 
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1278
                                      len(self.Ticks) - 1))
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1279
            self.CursorTick = self.Ticks[cursor_tick_idx]
1174
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1280
            self.StartTick = max(self.Ticks[
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1281
                                numpy.argmin(numpy.abs(self.Ticks - 
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1282
                                        self.CursorTick + self.CurrentRange))],
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1283
                             min(self.StartTick, self.CursorTick))
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1284
            self.RefreshCanvasPosition()
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1285
            self.UpdateCursorTick() 
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1286
            
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1287
    def ResetCursorTick(self):
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1288
        self.CursorTick = None
1084
baa09a1c7b15 Fixed bug in DebugVariablePanel, cursor not reset when graphs were reset
Laurent Bessard
parents: 1044
diff changeset
  1289
        self.UpdateCursorTick()
baa09a1c7b15 Fixed bug in DebugVariablePanel, cursor not reset when graphs were reset
Laurent Bessard
parents: 1044
diff changeset
  1290
    
baa09a1c7b15 Fixed bug in DebugVariablePanel, cursor not reset when graphs were reset
Laurent Bessard
parents: 1044
diff changeset
  1291
    def UpdateCursorTick(self):
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1292
        for panel in self.GraphicPanels:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1293
            if isinstance(panel, DebugVariableGraphic):
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1294
                panel.SetCursorTick(self.CursorTick)
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1295
        self.ForceRefresh()
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1296
    
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1297
    def StartDragNDrop(self, panel, item, x_mouse, y_mouse, x_mouse_start, y_mouse_start):
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1298
        if len(panel.GetItems()) > 1:
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1299
            self.DraggingAxesPanel = DebugVariableGraphic(self.GraphicsWindow, self, [item], GRAPH_PARALLEL)
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1300
            self.DraggingAxesPanel.SetCursorTick(self.CursorTick)
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1301
            width, height = panel.GetSize()
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1302
            self.DraggingAxesPanel.SetSize(wx.Size(width, height))
1044
41bd726aa23c Fixed bugs in DebugVariablePanel
Laurent Bessard
parents: 1043
diff changeset
  1303
            self.DraggingAxesPanel.ResetGraphics()
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1304
            self.DraggingAxesPanel.SetPosition(wx.Point(0, -height))
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1305
        else:
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1306
            self.DraggingAxesPanel = panel
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1307
        self.DraggingAxesBoundingBox = panel.GetAxesBoundingBox(absolute=True)
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1308
        self.DraggingAxesMousePos = wx.Point(
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1309
            x_mouse_start - self.DraggingAxesBoundingBox.x, 
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1310
            y_mouse_start - self.DraggingAxesBoundingBox.y)
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1311
        self.MoveDragNDrop(x_mouse, y_mouse)
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1312
        
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1313
    def MoveDragNDrop(self, x_mouse, y_mouse):
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1314
        self.DraggingAxesBoundingBox.x = x_mouse - self.DraggingAxesMousePos.x
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1315
        self.DraggingAxesBoundingBox.y = y_mouse - self.DraggingAxesMousePos.y
934
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  1316
        self.RefreshHighlight(x_mouse, y_mouse)
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  1317
    
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  1318
    def RefreshHighlight(self, x_mouse, y_mouse):
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1319
        for idx, panel in enumerate(self.GraphicPanels):
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1320
            x, y = panel.GetPosition()
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1321
            width, height = panel.GetSize()
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1322
            rect = wx.Rect(x, y, width, height)
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1323
            if (rect.InsideXY(x_mouse, y_mouse) or 
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1324
                idx == 0 and y_mouse < 0 or
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1325
                idx == len(self.GraphicPanels) - 1 and y_mouse > panel.GetPosition()[1]):
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1326
                panel.OnDragging(x_mouse - x, y_mouse - y)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1327
            else:
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1328
                panel.SetHighlight(HIGHLIGHT_NONE)
962
c0dcbbdb0bb1 Fix bug on Windows when drag'n dropping variable to DebugVariablePanel, panel not refreshed
Laurent Bessard
parents: 952
diff changeset
  1329
        if wx.Platform == "__WXMSW__":
c0dcbbdb0bb1 Fix bug on Windows when drag'n dropping variable to DebugVariablePanel, panel not refreshed
Laurent Bessard
parents: 952
diff changeset
  1330
            self.RefreshView()
c0dcbbdb0bb1 Fix bug on Windows when drag'n dropping variable to DebugVariablePanel, panel not refreshed
Laurent Bessard
parents: 952
diff changeset
  1331
        else:
c0dcbbdb0bb1 Fix bug on Windows when drag'n dropping variable to DebugVariablePanel, panel not refreshed
Laurent Bessard
parents: 952
diff changeset
  1332
            self.ForceRefresh()
934
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  1333
    
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  1334
    def ResetHighlight(self):
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  1335
        for panel in self.GraphicPanels:
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1336
            panel.SetHighlight(HIGHLIGHT_NONE)
962
c0dcbbdb0bb1 Fix bug on Windows when drag'n dropping variable to DebugVariablePanel, panel not refreshed
Laurent Bessard
parents: 952
diff changeset
  1337
        if wx.Platform == "__WXMSW__":
c0dcbbdb0bb1 Fix bug on Windows when drag'n dropping variable to DebugVariablePanel, panel not refreshed
Laurent Bessard
parents: 952
diff changeset
  1338
            self.RefreshView()
c0dcbbdb0bb1 Fix bug on Windows when drag'n dropping variable to DebugVariablePanel, panel not refreshed
Laurent Bessard
parents: 952
diff changeset
  1339
        else:
c0dcbbdb0bb1 Fix bug on Windows when drag'n dropping variable to DebugVariablePanel, panel not refreshed
Laurent Bessard
parents: 952
diff changeset
  1340
            self.ForceRefresh()
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1341
    
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1342
    def IsDragging(self):
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1343
        return self.DraggingAxesPanel is not None
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1344
    
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1345
    def GetDraggingAxesClippingRegion(self, panel):
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1346
        x, y = panel.GetPosition()
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1347
        width, height = panel.GetSize()
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1348
        bbox = wx.Rect(x, y, width, height)
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1349
        bbox = bbox.Intersect(self.DraggingAxesBoundingBox)
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1350
        bbox.x -= x
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1351
        bbox.y -= y
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1352
        return bbox
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1353
    
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1354
    def GetDraggingAxesPosition(self, panel):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1355
        x, y = panel.GetPosition()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1356
        return wx.Point(self.DraggingAxesBoundingBox.x - x,
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1357
                        self.DraggingAxesBoundingBox.y - y)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1358
    
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1359
    def StopDragNDrop(self, variable, x_mouse, y_mouse):
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1360
        if self.DraggingAxesPanel not in self.GraphicPanels:
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1361
            self.DraggingAxesPanel.Destroy()
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1362
        self.DraggingAxesPanel = None
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1363
        self.DraggingAxesBoundingBox = None
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1364
        self.DraggingAxesMousePos = None
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1365
        for idx, panel in enumerate(self.GraphicPanels):
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1366
            panel.SetHighlight(HIGHLIGHT_NONE)
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1367
            xw, yw = panel.GetPosition()
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1368
            width, height = panel.GetSize()
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1369
            bbox = wx.Rect(xw, yw, width, height)
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1370
            if bbox.InsideXY(x_mouse, y_mouse):
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1371
                panel.ShowButtons(True)
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1372
                merge_type = GRAPH_PARALLEL
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1373
                if isinstance(panel, DebugVariableText) or panel.Is3DCanvas():
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1374
                    if y_mouse > yw + height / 2:
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1375
                        idx += 1
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
  1376
                    wx.CallAfter(self.MoveValue, variable, idx)
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1377
                else:
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1378
                    rect = panel.GetAxesBoundingBox(True)
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1379
                    if rect.InsideXY(x_mouse, y_mouse):
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1380
                        merge_rect = wx.Rect(rect.x, rect.y, rect.width / 2., rect.height)
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1381
                        if merge_rect.InsideXY(x_mouse, y_mouse):
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1382
                            merge_type = GRAPH_ORTHOGONAL
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1383
                        wx.CallAfter(self.MergeGraphs, variable, idx, merge_type, force=True)
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1384
                    else:
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1385
                        if y_mouse > yw + height / 2:
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1386
                            idx += 1
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
  1387
                        wx.CallAfter(self.MoveValue, variable, idx)
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1388
                self.ForceRefresh()
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1389
                return 
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1390
        width, height = self.GraphicsWindow.GetVirtualSize()
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1391
        rect = wx.Rect(0, 0, width, height)
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1392
        if rect.InsideXY(x_mouse, y_mouse):
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
  1393
            wx.CallAfter(self.MoveValue, variable, len(self.GraphicPanels))
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1394
        self.ForceRefresh()
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1395
    
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1396
    def RefreshView(self):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1397
        self.RefreshCanvasPosition()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1398
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1399
        width, height = self.GraphicsWindow.GetVirtualSize()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1400
        bitmap = wx.EmptyBitmap(width, height)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1401
        dc = wx.BufferedDC(wx.ClientDC(self.GraphicsWindow), bitmap)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1402
        dc.Clear()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1403
        dc.BeginDrawing()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1404
        if self.DraggingAxesPanel is not None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1405
            destBBox = self.DraggingAxesBoundingBox
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1406
            srcBBox = self.DraggingAxesPanel.GetAxesBoundingBox()
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
  1407
            
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1408
            srcBmp = _convert_agg_to_wx_bitmap(self.DraggingAxesPanel.get_renderer(), None)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1409
            srcDC = wx.MemoryDC()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1410
            srcDC.SelectObject(srcBmp)
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1411
                
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1412
            dc.Blit(destBBox.x, destBBox.y, 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1413
                    int(destBBox.width), int(destBBox.height), 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1414
                    srcDC, srcBBox.x, srcBBox.y)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1415
        dc.EndDrawing()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1416
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1417
        if not self.Fixed or self.Force:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1418
            self.Force = False
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1419
            refresh_graphics = True
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1420
        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1421
            refresh_graphics = False
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1422
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1423
        if self.DraggingAxesPanel is not None and self.DraggingAxesPanel not in self.GraphicPanels:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1424
            self.DraggingAxesPanel.RefreshViewer(refresh_graphics)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1425
        for panel in self.GraphicPanels:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1426
            if isinstance(panel, DebugVariableGraphic):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1427
                panel.RefreshViewer(refresh_graphics)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1428
            else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1429
                panel.RefreshViewer()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1430
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1431
        if self.CursorTick is not None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1432
            tick = self.CursorTick
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1433
        elif len(self.Ticks) > 0:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1434
            tick = self.Ticks[-1]
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1435
        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1436
            tick = None
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1437
        if tick is not None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1438
            self.TickLabel.SetLabel("Tick: %d" % tick)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1439
            tick_duration = int(tick * self.Ticktime)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1440
            not_null = False
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1441
            duration = ""
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1442
            for value, format in [(tick_duration / DAY, "%dd"),
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1443
                                  ((tick_duration % DAY) / HOUR, "%dh"),
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1444
                                  ((tick_duration % HOUR) / MINUTE, "%dm"),
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1445
                                  ((tick_duration % MINUTE) / SECOND, "%ds")]:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1446
                
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1447
                if value > 0 or not_null:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1448
                    duration += format % value
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1449
                    not_null = True
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1450
            
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1451
            duration += "%gms" % (float(tick_duration % SECOND) / MILLISECOND) 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1452
            self.TickTimeLabel.SetLabel("t: %s" % duration)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1453
        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1454
            self.TickLabel.SetLabel("")
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1455
            self.TickTimeLabel.SetLabel("")
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1456
        self.TickSizer.Layout()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1457
    
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1458
    def UnregisterObsoleteData(self):
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1174
diff changeset
  1459
        self.SubscribeAllDataConsumers()
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1460
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1461
        if self.DataProducer is not None:
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
  1462
            if self.DataProducer is not None:
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1463
                self.SetTickTime(self.DataProducer.GetTicktime())
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1464
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1465
        for panel in self.GraphicPanels:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1466
            panel.UnregisterObsoleteData()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1467
            if panel.IsEmpty():
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1468
                if panel.HasCapture():
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1469
                    panel.ReleaseMouse()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1470
                self.GraphicPanels.remove(panel)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1471
                panel.Destroy()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1472
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1473
        self.ResetVariableNameMask()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1474
        self.RefreshGraphicsSizer()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1475
        self.ForceRefresh()
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
  1476
    
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
  1477
    def ResetView(self):
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1174
diff changeset
  1478
        self.UnsubscribeAllDataConsumers()
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1479
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1480
        self.Fixed = False
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1481
        for panel in self.GraphicPanels:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1482
            panel.Destroy()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1483
        self.GraphicPanels = []
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1484
        self.ResetVariableNameMask()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1485
        self.RefreshGraphicsSizer()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1486
    
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
  1487
    def RefreshCanvasPosition(self):
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1488
        if len(self.Ticks) > 0:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1489
            pos = int(self.StartTick - self.Ticks[0])
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1490
            range = int(self.Ticks[-1] - self.Ticks[0])
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1491
        else:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1492
            pos = 0
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1493
            range = 0
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1494
        self.CanvasPosition.SetScrollbar(pos, self.CurrentRange, range, self.CurrentRange)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1495
    
932
ebe63100b6d7 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 931
diff changeset
  1496
    def ChangeRange(self, dir, tick=None):
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1497
        current_range = self.CurrentRange
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1498
        current_range_idx = self.CanvasRange.GetSelection()
1191
5237f87e035f Fixed values in DebugVariablePanel range selection ComboBox
Laurent Bessard
parents: 1190
diff changeset
  1499
        new_range_idx = max(0, min(current_range_idx + dir, len(RANGE_VALUES) - 1))
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1500
        if new_range_idx != current_range_idx:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1501
            self.CanvasRange.SetSelection(new_range_idx)
1191
5237f87e035f Fixed values in DebugVariablePanel range selection ComboBox
Laurent Bessard
parents: 1190
diff changeset
  1502
            self.CurrentRange = RANGE_VALUES[new_range_idx][1] / self.Ticktime
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1503
            if len(self.Ticks) > 0:
932
ebe63100b6d7 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 931
diff changeset
  1504
                if tick is None:
ebe63100b6d7 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 931
diff changeset
  1505
                    tick = self.StartTick + self.CurrentRange / 2.
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1506
                new_start_tick = tick - (tick - self.StartTick) * self.CurrentRange / current_range 
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1507
                self.StartTick = self.Ticks[numpy.argmin(numpy.abs(self.Ticks - new_start_tick))]
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1508
                self.Fixed = self.StartTick < self.Ticks[-1] - self.CurrentRange
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1509
            self.ForceRefresh()
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1510
    
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1511
    def RefreshRange(self):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1512
        if len(self.Ticks) > 0:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1513
            if self.Fixed and self.Ticks[-1] - self.Ticks[0] < self.CurrentRange:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1514
                self.Fixed = False
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1515
            if self.Fixed:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1516
                self.StartTick = min(self.StartTick, self.Ticks[-1] - self.CurrentRange)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1517
            else:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1518
                self.StartTick = max(self.Ticks[0], self.Ticks[-1] - self.CurrentRange)
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1519
        self.ForceRefresh()
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1520
    
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1521
    def OnRangeChanged(self, event):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1522
        try:
1191
5237f87e035f Fixed values in DebugVariablePanel range selection ComboBox
Laurent Bessard
parents: 1190
diff changeset
  1523
            self.CurrentRange = RANGE_VALUES[self.CanvasRange.GetSelection()][1] / self.Ticktime
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1524
        except ValueError, e:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1525
            self.CanvasRange.SetValue(str(self.CurrentRange))
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1526
        wx.CallAfter(self.RefreshRange)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1527
        event.Skip()
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1528
    
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1529
    def OnCurrentButton(self, event):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1530
        if len(self.Ticks) > 0:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1531
            self.StartTick = max(self.Ticks[0], self.Ticks[-1] - self.CurrentRange)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1532
            self.Fixed = False
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1533
            self.ResetCursorTick()
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1534
        event.Skip()
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1535
    
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1536
    def CopyDataToClipboard(self, variables):
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1537
        text = "tick;%s;\n" % ";".join([item.GetVariable() for item, data in variables])
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1538
        next_tick = NextTick(variables)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1539
        while next_tick is not None:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1540
            values = []
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1541
            for item, data in variables:
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1542
                if len(data) > 0:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1543
                    if next_tick == data[0][0]:
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1544
                        var_type = item.GetVariableType()
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1545
                        if var_type in ["STRING", "WSTRING"]:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1546
                            value = item.GetRawValue(int(data.pop(0)[2]))
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1547
                            if var_type == "STRING":
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1548
                                values.append("'%s'" % value)
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1549
                            else:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1550
                                values.append('"%s"' % value)
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1551
                        else:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1552
                            values.append("%.3f" % data.pop(0)[1])
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1553
                    else:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1554
                        values.append("")
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1555
                else:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1556
                    values.append("")
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1557
            text += "%d;%s;\n" % (next_tick, ";".join(values))
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1558
            next_tick = NextTick(variables)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1559
        self.ParentWindow.SetCopyBuffer(text)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1560
    
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1561
    def OnExportGraphButton(self, event):
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1562
        items = reduce(lambda x, y: x + y,
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1563
                       [panel.GetItems() for panel in self.GraphicPanels],
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1564
                       [])
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1565
        variables = [(item, [entry for entry in item.GetData()])
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1566
                     for item in items
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1567
                     if item.IsNumVariable()]
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1568
        wx.CallAfter(self.CopyDataToClipboard, variables)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1569
        event.Skip()
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1570
    
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1571
    def OnPositionChanging(self, event):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1572
        if len(self.Ticks) > 0:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1573
            self.StartTick = self.Ticks[0] + event.GetPosition()
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1574
            self.Fixed = True
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1575
            self.ForceRefresh()
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1576
        event.Skip()
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1577
    
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
  1578
    def GetRange(self):
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
  1579
        return self.StartTick, self.StartTick + self.CurrentRange
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
  1580
    
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
  1581
    def GetViewerIndex(self, viewer):
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
  1582
        if viewer in self.GraphicPanels:
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
  1583
            return self.GraphicPanels.index(viewer)
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
  1584
        return None
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
  1585
    
934
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  1586
    def IsViewerFirst(self, viewer):
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  1587
        return viewer == self.GraphicPanels[0]
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  1588
    
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  1589
    def IsViewerLast(self, viewer):
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  1590
        return viewer == self.GraphicPanels[-1]
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  1591
    
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  1592
    def HighlightPreviousViewer(self, viewer):
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  1593
        if self.IsViewerFirst(viewer):
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  1594
            return
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  1595
        idx = self.GetViewerIndex(viewer)
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  1596
        if idx is None:
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  1597
            return
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1598
        self.GraphicPanels[idx-1].SetHighlight(HIGHLIGHT_AFTER)
934
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  1599
    
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1600
    def ResetVariableNameMask(self):
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1601
        items = []
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1602
        for panel in self.GraphicPanels:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1603
            items.extend(panel.GetItems())
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1604
        if len(items) > 1:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1605
            self.VariableNameMask = reduce(compute_mask,
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1606
                [item.GetVariable().split('.') for item in items])
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1607
        elif len(items) > 0:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1608
            self.VariableNameMask = items[0].GetVariable().split('.')[:-1] + ['*']
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1609
        else:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1610
            self.VariableNameMask = []
931
da4970f6c46c Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 930
diff changeset
  1611
        self.MaskLabel.ChangeValue(".".join(self.VariableNameMask))
da4970f6c46c Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 930
diff changeset
  1612
        self.MaskLabel.SetInsertionPoint(self.MaskLabel.GetLastPosition())
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1613
            
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1614
    def GetVariableNameMask(self):
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1615
        return self.VariableNameMask
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1616
    
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
  1617
    def InsertValue(self, iec_path, idx = None, force=False):
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1618
        for panel in self.GraphicPanels:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1619
            if panel.GetItem(iec_path) is not None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1620
                return
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1621
        if idx is None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1622
            idx = len(self.GraphicPanels)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1623
        item = DebugVariableItem(self, iec_path, True)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1624
        result = self.AddDataConsumer(iec_path.upper(), item)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1625
        if result is not None or force:
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
  1626
            
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1627
            if item.IsNumVariable():
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1628
                panel = DebugVariableGraphic(self.GraphicsWindow, self, [item], GRAPH_PARALLEL)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1629
                if self.CursorTick is not None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1630
                    panel.SetCursorTick(self.CursorTick)
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
  1631
            else:
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1632
                panel = DebugVariableText(self.GraphicsWindow, self, [item])
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1633
            if idx is not None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1634
                self.GraphicPanels.insert(idx, panel)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1635
            else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1636
                self.GraphicPanels.append(panel)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1637
            self.ResetVariableNameMask()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1638
            self.RefreshGraphicsSizer()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1639
            self.ForceRefresh()
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
  1640
    
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
  1641
    def MoveValue(self, iec_path, idx = None):
919
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  1642
        if idx is None:
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  1643
            idx = len(self.GraphicPanels)
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  1644
        source_panel = None
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  1645
        item = None
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  1646
        for panel in self.GraphicPanels:
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  1647
            item = panel.GetItem(iec_path)
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  1648
            if item is not None:
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  1649
                source_panel = panel
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  1650
                break
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  1651
        if source_panel is not None:
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  1652
            source_panel.RemoveItem(item)
1041
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  1653
            source_size = source_panel.GetSize()
919
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  1654
            if source_panel.IsEmpty():
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1655
                if source_panel.HasCapture():
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1656
                    source_panel.ReleaseMouse()
919
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  1657
                self.GraphicPanels.remove(source_panel)
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  1658
                source_panel.Destroy()
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  1659
            
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
  1660
            if item.IsNumVariable():
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
  1661
                panel = DebugVariableGraphic(self.GraphicsWindow, self, [item], GRAPH_PARALLEL)
1041
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  1662
                panel.SetCanvasSize(source_size.width, source_size.height)
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
  1663
                if self.CursorTick is not None:
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
  1664
                    panel.SetCursorTick(self.CursorTick)
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
  1665
            else:
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
  1666
                panel = DebugVariableText(self.GraphicsWindow, self, [item])
919
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  1667
            self.GraphicPanels.insert(idx, panel)
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1668
            self.ResetVariableNameMask()
919
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  1669
            self.RefreshGraphicsSizer()
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1670
            self.ForceRefresh()
919
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  1671
    
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
  1672
    def MergeGraphs(self, source, target_idx, merge_type, force=False):
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
  1673
        source_item = None
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
  1674
        source_panel = None
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
  1675
        for panel in self.GraphicPanels:
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
  1676
            source_item = panel.GetItem(source)
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
  1677
            if source_item is not None:
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
  1678
                source_panel = panel
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
  1679
                break
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
  1680
        if source_item is None:
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1681
            item = DebugVariableItem(self, source, True)
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
  1682
            if item.IsNumVariable():
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
  1683
                result = self.AddDataConsumer(source.upper(), item)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
  1684
                if result is not None or force:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
  1685
                    source_item = item
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
  1686
        if source_item is not None and source_item.IsNumVariable():
1041
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  1687
            if source_panel is not None:
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  1688
                source_size = source_panel.GetSize()
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  1689
            else:
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  1690
                source_size = None
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
  1691
            target_panel = self.GraphicPanels[target_idx]
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
  1692
            graph_type = target_panel.GraphType
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
  1693
            if target_panel != source_panel:
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
  1694
                if (merge_type == GRAPH_PARALLEL and graph_type != merge_type or
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
  1695
                    merge_type == GRAPH_ORTHOGONAL and 
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
  1696
                    (graph_type == GRAPH_PARALLEL and len(target_panel.Items) > 1 or
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
  1697
                     graph_type == GRAPH_ORTHOGONAL and len(target_panel.Items) >= 3)):
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
  1698
                    return
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
  1699
                
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
  1700
                if source_panel is not None:
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
  1701
                    source_panel.RemoveItem(source_item)
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
  1702
                    if source_panel.IsEmpty():
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1703
                        if source_panel.HasCapture():
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1704
                            source_panel.ReleaseMouse()
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
  1705
                        self.GraphicPanels.remove(source_panel)
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
  1706
                        source_panel.Destroy()
936
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
  1707
            elif (merge_type != graph_type and len(target_panel.Items) == 2):
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
  1708
                target_panel.RemoveItem(source_item)
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
  1709
            else:
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
  1710
                target_panel = None
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
  1711
                
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
  1712
            if target_panel is not None:
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
  1713
                target_panel.AddItem(source_item)
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
  1714
                target_panel.GraphType = merge_type
1041
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  1715
                size = target_panel.GetSize()
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  1716
                if merge_type == GRAPH_ORTHOGONAL:
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  1717
                    target_panel.SetCanvasSize(size.width, size.width)
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  1718
                elif source_size is not None:
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  1719
                    target_panel.SetCanvasSize(size.width, size.height + source_size.height)
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  1720
                else:
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  1721
                    target_panel.SetCanvasSize(size.width, size.height)
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
  1722
                target_panel.ResetGraphics()
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
  1723
                
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1724
                self.ResetVariableNameMask()
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
  1725
                self.RefreshGraphicsSizer()
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1726
                self.ForceRefresh()
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
  1727
    
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
  1728
    def DeleteValue(self, source_panel, item=None):
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
  1729
        source_idx = self.GetViewerIndex(source_panel)
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
  1730
        if source_idx is not None:
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
  1731
            
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
  1732
            if item is None:
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
  1733
                source_panel.Clear()
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
  1734
                source_panel.Destroy()
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
  1735
                self.GraphicPanels.remove(source_panel)
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1736
                self.ResetVariableNameMask()
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
  1737
                self.RefreshGraphicsSizer()
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
  1738
            else:
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
  1739
                source_panel.RemoveItem(item)
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
  1740
                if source_panel.IsEmpty():
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
  1741
                    source_panel.Destroy()
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
  1742
                    self.GraphicPanels.remove(source_panel)
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1743
                    self.ResetVariableNameMask()
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
  1744
                    self.RefreshGraphicsSizer()
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1745
            self.ForceRefresh()
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
  1746
    
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
  1747
    def ResetGraphicsValues(self):
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1748
        self.Ticks = numpy.array([])
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1749
        self.StartTick = 0
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1750
        self.Fixed = False
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1751
        for panel in self.GraphicPanels:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1752
            panel.ResetData()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1753
        self.ResetCursorTick()
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
  1754
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
  1755
    def RefreshGraphicsWindowScrollbars(self):
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
  1756
        xstart, ystart = self.GraphicsWindow.GetViewStart()
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
  1757
        window_size = self.GraphicsWindow.GetClientSize()
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
  1758
        vwidth, vheight = self.GraphicsSizer.GetMinSize()
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
  1759
        posx = max(0, min(xstart, (vwidth - window_size[0]) / SCROLLBAR_UNIT))
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
  1760
        posy = max(0, min(ystart, (vheight - window_size[1]) / SCROLLBAR_UNIT))
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
  1761
        self.GraphicsWindow.Scroll(posx, posy)
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
  1762
        self.GraphicsWindow.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, 
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
  1763
                vwidth / SCROLLBAR_UNIT, vheight / SCROLLBAR_UNIT, posx, posy)
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
  1764
    
988
30e7571c10d0 Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents: 980
diff changeset
  1765
    def OnGraphicsWindowEraseBackground(self, event):
30e7571c10d0 Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents: 980
diff changeset
  1766
        pass
30e7571c10d0 Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents: 980
diff changeset
  1767
    
30e7571c10d0 Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents: 980
diff changeset
  1768
    def OnGraphicsWindowPaint(self, event):
30e7571c10d0 Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents: 980
diff changeset
  1769
        self.RefreshView()
30e7571c10d0 Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents: 980
diff changeset
  1770
        event.Skip()
30e7571c10d0 Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents: 980
diff changeset
  1771
    
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
  1772
    def OnGraphicsWindowResize(self, event):
1041
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  1773
        size = self.GetSize()
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  1774
        for panel in self.GraphicPanels:
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  1775
            panel_size = panel.GetSize()
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
  1776
            if (isinstance(panel, DebugVariableGraphic) and 
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
  1777
                panel.GraphType == GRAPH_ORTHOGONAL and 
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
  1778
                panel_size.width == panel_size.height):
1041
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  1779
                panel.SetCanvasSize(size.width, size.width)
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
  1780
        self.RefreshGraphicsWindowScrollbars()
1194
0cf48602ee24 Fixed bug with moving cursor with keyboard in DebugVariablePanel
Laurent Bessard
parents: 1193
diff changeset
  1781
        self.GraphicsSizer.Layout()
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1782
        event.Skip()
1040
af8a1aee3584 Fixed MouseWheel behavior in DebugVariablePanel, change graph range only if CTRL is pressed
Laurent Bessard
parents: 1008
diff changeset
  1783
af8a1aee3584 Fixed MouseWheel behavior in DebugVariablePanel, change graph range only if CTRL is pressed
Laurent Bessard
parents: 1008
diff changeset
  1784
    def OnGraphicsWindowMouseWheel(self, event):
af8a1aee3584 Fixed MouseWheel behavior in DebugVariablePanel, change graph range only if CTRL is pressed
Laurent Bessard
parents: 1008
diff changeset
  1785
        if self.VetoScrollEvent:
af8a1aee3584 Fixed MouseWheel behavior in DebugVariablePanel, change graph range only if CTRL is pressed
Laurent Bessard
parents: 1008
diff changeset
  1786
            self.VetoScrollEvent = False
af8a1aee3584 Fixed MouseWheel behavior in DebugVariablePanel, change graph range only if CTRL is pressed
Laurent Bessard
parents: 1008
diff changeset
  1787
        else:
af8a1aee3584 Fixed MouseWheel behavior in DebugVariablePanel, change graph range only if CTRL is pressed
Laurent Bessard
parents: 1008
diff changeset
  1788
            event.Skip()