controls/DebugVariablePanel/DebugVariableGraphicViewer.py
author Laurent Bessard
Mon, 03 Jun 2013 00:30:55 +0200
changeset 1209 953a8f14040a
parent 1207 fb9799a0c0f7
child 1212 b351d3a7917c
permissions -rw-r--r--
Rewrite DebugVariablePanel and fixed bugs
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
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
    27
import numpy
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    28
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    29
import wx
888
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
    30
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    31
import matplotlib
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    32
matplotlib.use('WX')
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    33
import matplotlib.pyplot
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    34
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    35
from matplotlib.backends.backend_wxagg import _convert_agg_to_wx_bitmap
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    36
from matplotlib.backends.backend_agg import FigureCanvasAgg
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    37
from mpl_toolkits.mplot3d import Axes3D
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    38
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    39
from editors.DebugViewer import REFRESH_PERIOD
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    40
1199
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
    41
from DebugVariableItem import DebugVariableItem
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    42
from DebugVariableViewer import *
1199
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
    43
from GraphButton import GraphButton
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
    44
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
    45
# Graph variable display type
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    46
GRAPH_PARALLEL, GRAPH_ORTHOGONAL = range(2)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    47
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
    48
# Canvas height
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    49
[SIZE_MINI, SIZE_MIDDLE, SIZE_MAXI] = [0, 100, 200]
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    50
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
    51
CANVAS_BORDER = (20., 10.) # Border height on at bottom and top of graph
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
    52
CANVAS_PADDING = 8.5       # Border inside graph where no label is drawn
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
    53
VALUE_LABEL_HEIGHT = 17.   # Height of variable label in graph
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
    54
AXES_LABEL_HEIGHT = 12.75  # Height of variable value in graph
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
    55
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
    56
# Colors used cyclically for graph curves
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    57
COLOR_CYCLE = ['r', 'b', 'g', 'm', 'y', 'k']
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
    58
# Color for graph cursor
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    59
CURSOR_COLOR = '#800080'
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    60
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
    61
def OrthogonalDataAndRange(item, start_tick, end_tick):
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    62
    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
    63
    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
    64
    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
    65
        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
    66
        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
    67
    else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    68
        center = 0.5
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    69
        range = 1.0
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    70
    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
    71
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
    72
#-------------------------------------------------------------------------------
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
    73
#                   Debug Variable Graphic Viewer Drop Target
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
    74
#-------------------------------------------------------------------------------
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
    75
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
    76
"""
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
    77
Class that implements a custom drop target class for Debug Variable Graphic Viewer
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
    78
"""
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
    79
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
    80
class DebugVariableGraphicDropTarget(wx.TextDropTarget):
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    81
    
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    82
    def __init__(self, parent, window):
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
    83
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
    84
        Constructor
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
    85
        @param parent: Reference to Debug Variable Graphic Viewer
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
    86
        @param window: Reference to the Debug Variable Panel
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
    87
        """
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    88
        wx.TextDropTarget.__init__(self)
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    89
        self.ParentControl = parent
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    90
        self.ParentWindow = window
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    91
        
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    92
    def __del__(self):
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
    93
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
    94
        Destructor
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
    95
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
    96
        # Remove reference to Debug Variable Graphic Viewer and Debug Variable
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
    97
        # Panel
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    98
        self.ParentControl = None
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    99
        self.ParentWindow = None
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   100
        
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   101
    def OnDragOver(self, x, y, d):
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   102
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   103
        Function called when mouse is dragged over Drop Target
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   104
        @param x: X coordinate of mouse pointer
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   105
        @param y: Y coordinate of mouse pointer
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   106
        @param d: Suggested default for return value
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   107
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   108
        # Signal parent that mouse is dragged over
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   109
        self.ParentControl.OnMouseDragging(x, y)
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   110
        
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   111
        return wx.TextDropTarget.OnDragOver(self, x, y, d)
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   112
        
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   113
    def OnDropText(self, x, y, data):
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   114
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   115
        Function called when mouse is dragged over Drop Target
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   116
        @param x: X coordinate of mouse pointer
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   117
        @param y: Y coordinate of mouse pointer
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   118
        @param data: Text associated to drag'n drop
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   119
        """
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   120
        message = None
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   121
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   122
        # Check that data is valid regarding DebugVariablePanel
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   123
        try:
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   124
            values = eval(data)
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   125
            if not isinstance(values, TupleType):
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1200
diff changeset
   126
                raise ValueError
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   127
        except:
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   128
            message = _("Invalid value \"%s\" for debug variable")%data
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   129
            values = None
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   130
        
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   131
        # Display message if data is invalid
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   132
        if message is not None:
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   133
            wx.CallAfter(self.ShowMessage, message)
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   134
        
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   135
        # Data contain a reference to a variable to debug
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   136
        elif values[1] == "debug":
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   137
            target_idx = self.ParentControl.GetIndex()
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   138
            
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   139
            # If mouse is dropped in graph canvas bounding box and graph is
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   140
            # not 3D canvas, graphs will be merged
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   141
            rect = self.ParentControl.GetAxesBoundingBox()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   142
            if not self.ParentControl.Is3DCanvas() and rect.InsideXY(x, y):
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   143
                # Default merge type is parallel
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   144
                merge_type = GRAPH_PARALLEL
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   145
                
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   146
                # If mouse is dropped in left part of graph canvas, graph
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   147
                # wall be merged orthogonally
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   148
                merge_rect = wx.Rect(rect.x, rect.y, 
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   149
                                     rect.width / 2., rect.height)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   150
                if merge_rect.InsideXY(x, y):
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   151
                    merge_type = GRAPH_ORTHOGONAL
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   152
                
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   153
                # Merge graphs
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   154
                wx.CallAfter(self.ParentWindow.MergeGraphs, 
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   155
                             values[0], target_idx, 
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   156
                             merge_type, force=True)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   157
                
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   158
            else:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   159
                width, height = self.ParentControl.GetSize()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   160
                
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   161
                # Get Before which Viewer the variable has to be moved or added
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   162
                # according to the position of mouse in Viewer.
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   163
                if y > height / 2:
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   164
                    target_idx += 1
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   165
                
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   166
                # Drag'n Drop is an internal is an internal move inside Debug
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   167
                # Variable Panel 
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   168
                if len(values) > 2 and values[2] == "move":
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   169
                    self.ParentWindow.MoveValue(values[0], 
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   170
                                                target_idx)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   171
                
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   172
                # Drag'n Drop was initiated by another control of Beremiz
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   173
                else:
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   174
                    self.ParentWindow.InsertValue(values[0], 
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   175
                                                  target_idx, 
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   176
                                                  force=True)
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   177
    
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   178
    def OnLeave(self):
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   179
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   180
        Function called when mouse is leave Drop Target
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   181
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   182
        # Signal Debug Variable Panel to reset highlight
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   183
        self.ParentWindow.ResetHighlight()
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   184
        return wx.TextDropTarget.OnLeave(self)
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   185
    
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   186
    def ShowMessage(self, message):
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   187
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   188
        Show error message in Error Dialog
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   189
        @param message: Error message to display
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   190
        """
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   191
        dialog = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR)
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   192
        dialog.ShowModal()
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   193
        dialog.Destroy()
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   194
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   195
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   196
#-------------------------------------------------------------------------------
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   197
#                      Debug Variable Graphic Viewer Class
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   198
#-------------------------------------------------------------------------------
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   199
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   200
"""
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   201
Class that implements a Viewer that display variable values as a graphs
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   202
"""
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   203
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   204
class DebugVariableGraphicViewer(DebugVariableViewer, FigureCanvas):
1198
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
    def __init__(self, parent, window, items, graph_type):
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   207
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   208
        Constructor
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   209
        @param parent: Parent wx.Window of DebugVariableText
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   210
        @param window: Reference to the Debug Variable Panel
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   211
        @param items: List of DebugVariableItem displayed by Viewer
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   212
        @param graph_type: Graph display type (Parallel or orthogonal)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   213
        """
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   214
        DebugVariableViewer.__init__(self, window, items)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   215
        
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   216
        self.GraphType = graph_type        # Graph type display
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   217
        self.CursorTick = None             # Tick of the graph cursor
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   218
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   219
        # Mouse position when start dragging
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   220
        self.MouseStartPos = None
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   221
        # Tick when moving tick start
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   222
        self.StartCursorTick = None
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   223
        # Canvas size when starting to resize canvas
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   224
        self.CanvasStartSize = None        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   225
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   226
        # List of current displayed contextual buttons
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   227
        self.ContextualButtons = []
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   228
        # Reference to item for which contextual buttons was displayed
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   229
        self.ContextualButtonsItem = None
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   230
        
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   231
        # Create figure for drawing graphs
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   232
        self.Figure = matplotlib.figure.Figure(facecolor='w')
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   233
        # Defined border around figure in canvas
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   234
        self.Figure.subplotpars.update(top=0.95, left=0.1, 
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   235
                                       bottom=0.1, right=0.95)
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   236
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   237
        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
   238
        self.SetWindowStyle(wx.WANTS_CHARS)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   239
        self.SetBackgroundColour(wx.WHITE)
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   240
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   241
        # Bind wx events
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   242
        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
   243
        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
   244
        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
   245
        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
   246
        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
   247
        
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   248
        # Set canvas min size
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   249
        canvas_size = self.GetCanvasMinSize()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   250
        self.SetMinSize(canvas_size)
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   251
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   252
        # Define Viewer drop target
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   253
        self.SetDropTarget(DebugVariableGraphicDropTarget(self, window))
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   254
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   255
        # Connect matplotlib events
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   256
        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
   257
        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
   258
        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
   259
        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
   260
        
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   261
        # Add buttons for changing canvas size with predefined height
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   262
        for size, bitmap in zip(
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   263
                [SIZE_MINI, SIZE_MIDDLE, SIZE_MAXI],
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   264
                ["minimize_graph", "middle_graph", "maximize_graph"]):
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   265
            self.Buttons.append(
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   266
                    GraphButton(0, 0, bitmap, 
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   267
                                self.GetOnChangeSizeButton(size)))
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   268
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   269
        # Add buttons for exporting graph values to clipboard and close graph
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   270
        for bitmap, callback in [
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   271
                ("export_graph_mini", self.OnExportGraphButton),
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   272
                ("delete_graph", self.OnCloseButton)]:
1199
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
   273
            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
   274
        
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   275
        # Update graphs elements
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   276
        self.ResetGraphics()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   277
        self.RefreshLabelsPosition(canvas_size.height)
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   278
    
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   279
    def AddItem(self, item):
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   280
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   281
        Add an item to the list of items displayed by Viewer
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   282
        @param item: Item to add to the list
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   283
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   284
        DebugVariableViewer.AddItem(self, item)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   285
        self.ResetGraphics()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   286
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   287
    def RemoveItem(self, item):
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   288
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   289
        Remove an item from the list of items displayed by Viewer
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   290
        @param item: Item to remove from the list
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   291
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   292
        DebugVariableViewer.RemoveItem(self, item)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   293
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   294
        # If list of items is not empty
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   295
        if not self.ItemsIsEmpty():
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   296
            # Return to parallel graph if there is only one item
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   297
            # especially if it's actually orthogonal
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   298
            if len(self.Items) == 1:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   299
                self.GraphType = GRAPH_PARALLEL
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   300
            self.ResetGraphics()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   301
    
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   302
    def SubscribeAllDataConsumers(self):
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   303
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   304
        Function that unsubscribe and remove every item that store values of
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   305
        a variable that doesn't exist in PLC anymore
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   306
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   307
        DebugVariableViewer.SubscribeAllDataConsumers(self)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   308
        if not self.ItemsIsEmpty():
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   309
            self.ResetGraphics()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   310
    
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   311
    def Is3DCanvas(self):
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   312
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   313
        Return if Viewer is a 3D canvas
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   314
        @return: True if Viewer is a 3D canvas
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   315
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   316
        return self.GraphType == GRAPH_ORTHOGONAL and len(self.Items) == 3
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   317
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   318
    def GetButtons(self):
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   319
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   320
        Return list of buttons defined in Viewer
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   321
        @return: List of buttons
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   322
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   323
        # Add contextual buttons to default buttons
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   324
        return self.Buttons + self.ContextualButtons
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   325
    
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   326
    def PopupContextualButtons(self, item, rect, direction=wx.RIGHT):
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   327
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   328
        Show contextual menu for item aside a label of this item defined
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   329
        by the bounding box of label in figure
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   330
        @param item: Item for which contextual is shown
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   331
        @param rect: Bounding box of label aside which drawing menu
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   332
        @param direction: Direction in which buttons must be drawn
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   333
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   334
        # Return immediately if contextual menu for item is already shown
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   335
        if self.ContextualButtonsItem == item:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   336
            return
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   337
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   338
        # Close already shown contextual menu
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   339
        self.DismissContextualButtons()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   340
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   341
        # Save item for which contextual menu is shown
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   342
        self.ContextualButtonsItem = item
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   343
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   344
        # If item variable is forced, add button for release variable to
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   345
        # contextual menu
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   346
        if self.ContextualButtonsItem.IsForced():
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   347
            self.ContextualButtons.append(
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   348
                GraphButton(0, 0, "release", self.OnReleaseItemButton))
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   349
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   350
        # Add other buttons to contextual menu
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   351
        for bitmap, callback in [
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   352
                ("force", self.OnForceItemButton),
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   353
                ("export_graph_mini", self.OnExportItemGraphButton),
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   354
                ("delete_graph", self.OnRemoveItemButton)]:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   355
            self.ContextualButtons.append(
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   356
                    GraphButton(0, 0, bitmap, callback))
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   357
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   358
        # If buttons are shown at left side or upper side of rect, positions
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   359
        # will be set in reverse order
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   360
        buttons = self.ContextualButtons[:]
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   361
        if direction in [wx.TOP, wx.LEFT]:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   362
             buttons.reverse()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   363
             
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   364
        # Set contextual menu buttons position aside rect depending on
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   365
        # direction given
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   366
        offset = 0
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   367
        for button in buttons:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   368
            w, h = button.GetSize()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   369
            if direction in [wx.LEFT, wx.RIGHT]:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   370
                x = rect.x + (- w - offset
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   371
                            if direction == wx.LEFT
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   372
                            else rect.width + offset)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   373
                y = rect.y + (rect.height - h) / 2
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   374
                offset += w
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   375
            else:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   376
                x = rect.x + (rect.width - w ) / 2
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   377
                y = rect.y + (- h - offset
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   378
                              if direction == wx.TOP
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   379
                              else rect.height + offset)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   380
                offset += h
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   381
            button.SetPosition(x, y)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   382
            button.Show()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   383
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   384
        # Refresh canvas
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   385
        self.ParentWindow.ForceRefresh()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   386
    
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   387
    def DismissContextualButtons(self):
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   388
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   389
        Close current shown contextual menu
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   390
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   391
        # Return immediately if no contextual menu is shown
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   392
        if self.ContextualButtonsItem is None:
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   393
            return
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   394
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   395
        # Reset variables corresponding to contextual menu
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   396
        self.ContextualButtonsItem = None
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   397
        self.ContextualButtons = []
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   398
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   399
        # Refresh canvas
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   400
        self.ParentWindow.ForceRefresh()
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   401
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   402
    def IsOverContextualButton(self, x, y):
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   403
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   404
        Return if point is over one contextual button of Viewer
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   405
        @param x: X coordinate of point
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   406
        @param y: Y coordinate of point
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   407
        @return: contextual button where point is over
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   408
        """
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   409
        for button in self.ContextualButtons:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   410
            if button.HitTest(x, y):
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   411
                return button
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   412
        return None
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   413
    
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   414
    def ExportGraph(self, item=None):
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   415
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   416
        Export item(s) data to clipboard in CSV format
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   417
        @param item: Item from which data to export, all items if None
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   418
        (default None)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   419
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   420
        self.ParentWindow.CopyDataToClipboard(
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   421
            [(item, [entry for entry in item.GetData()])
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   422
             for item in (self.Items 
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   423
                          if item is None 
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   424
                          else [item])])
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   425
    
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   426
    def GetOnChangeSizeButton(self, height):
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   427
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   428
        Function that generate callback function for change Viewer height to
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   429
        pre-defined height button
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   430
        @param height: Height that change Viewer to
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   431
        @return: callback function
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   432
        """
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   433
        def OnChangeSizeButton():
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   434
            self.SetCanvasSize(200, height)
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   435
        return OnChangeSizeButton
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   436
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   437
    def OnExportGraphButton(self):
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   438
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   439
        Function called when Viewer Export button is pressed
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   440
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   441
        # Export data of every item in Viewer
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   442
        self.ExportGraph()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   443
    
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   444
    def OnForceItemButton(self):
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   445
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   446
        Function called when contextual menu Force button is pressed
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   447
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   448
        # Open dialog for forcing item variable value 
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   449
        self.ForceValue(self.ContextualButtonsItem)
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   450
        # Close contextual menu
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   451
        self.DismissContextualButtons()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   452
        
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   453
    def OnReleaseItemButton(self):
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   454
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   455
        Function called when contextual menu Release button is pressed
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   456
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   457
        # Release item variable value 
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   458
        self.ReleaseValue(self.ContextualButtonsItem)
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   459
        # Close contextual menu
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   460
        self.DismissContextualButtons()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   461
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   462
    def OnExportItemGraphButton(self):
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   463
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   464
        Function called when contextual menu Export button is pressed
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   465
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   466
        # Export data of item variable
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   467
        self.ExportGraph(self.ContextualButtonsItem)
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   468
        # Close contextual menu
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   469
        self.DismissContextualButtons()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   470
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   471
    def OnRemoveItemButton(self):            
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   472
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   473
        Function called when contextual menu Remove button is pressed
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   474
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   475
        # Remove item from Viewer
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   476
        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
   477
                     self.ContextualButtonsItem)
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   478
        # Close contextual menu
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   479
        self.DismissContextualButtons()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   480
    
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   481
    def HandleCursorMove(self, event):
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   482
        start_tick, end_tick = self.ParentWindow.GetRange()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   483
        cursor_tick = None
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   484
        items = self.ItemsDict.values()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   485
        if self.GraphType == GRAPH_ORTHOGONAL:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   486
            x_data = items[0].GetData(start_tick, end_tick)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   487
            y_data = items[1].GetData(start_tick, end_tick)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   488
            if len(x_data) > 0 and len(y_data) > 0:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   489
                length = min(len(x_data), len(y_data))
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   490
                d = numpy.sqrt((x_data[:length,1]-event.xdata) ** 2 + (y_data[:length,1]-event.ydata) ** 2)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   491
                cursor_tick = x_data[numpy.argmin(d), 0]
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   492
        else:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   493
            data = items[0].GetData(start_tick, end_tick)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   494
            if len(data) > 0:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   495
                cursor_tick = data[numpy.argmin(numpy.abs(data[:,0] - event.xdata)), 0]
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   496
        if cursor_tick is not None:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   497
            self.ParentWindow.SetCursorTick(cursor_tick)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   498
    
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   499
    def OnCanvasButtonPressed(self, event):
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   500
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   501
        Function called when a button of mouse is pressed
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   502
        @param event: Mouse event
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   503
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   504
        # Get mouse position, graph coordinates are inverted comparing to wx
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   505
        # coordinates
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   506
        width, height = self.GetSize()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   507
        x, y = event.x, height - event.y
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   508
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   509
        # Return immediately if mouse is over a button
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   510
        if self.IsOverButton(x, y):
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   511
            return 
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   512
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   513
        # Mouse was clicked inside graph figure
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   514
        if event.inaxes == self.Axes:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   515
            
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   516
            # Find if it was on an item label
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   517
            item_idx = None
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   518
            # Check every label paired with corresponding item
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   519
            for i, t in ([pair for pair in enumerate(self.AxesLabels)] + 
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   520
                         [pair for pair in enumerate(self.Labels)]):
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   521
                # Get label bounding box
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   522
                (x0, y0), (x1, y1) = t.get_window_extent().get_points()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   523
                rect = wx.Rect(x0, height - y1, x1 - x0, y1 - y0)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   524
                # Check if mouse was over label
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   525
                if rect.InsideXY(x, y):
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   526
                    item_idx = i
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   527
                    break
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   528
            
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   529
            # If an item label have been clicked
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   530
            if item_idx is not None:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   531
                # Hide buttons and contextual buttons
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   532
                self.ShowButtons(False)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   533
                self.DismissContextualButtons()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   534
                
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   535
                # Start a drag'n drop from mouse position in wx coordinate of
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   536
                # parent
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   537
                xw, yw = self.GetPosition()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   538
                self.ParentWindow.StartDragNDrop(self, 
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   539
                    self.ItemsDict.values()[item_idx], 
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   540
                    x + xw, y + yw, # Current mouse position
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   541
                    x + xw, y + yw) # Mouse position when button was clicked
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   542
            
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   543
            # Don't handle mouse button if canvas is 3D and let matplotlib do
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   544
            # the default behavior (rotate 3D axes)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   545
            elif not self.Is3DCanvas():
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   546
                # Save mouse position when clicked
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   547
                self.MouseStartPos = wx.Point(x, y)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   548
                
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   549
                # Mouse button was left button, start moving cursor
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   550
                if event.button == 1:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   551
                    # Save current tick in case a drag'n drop is initiate to
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   552
                    # restore it
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   553
                    self.StartCursorTick = self.CursorTick
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   554
                    
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   555
                    self.HandleCursorMove(event)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   556
                    
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   557
                # Mouse button is middle button and graph is parallel, start
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   558
                # moving graph along X coordinate (tick)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   559
                elif event.button == 2 and self.GraphType == GRAPH_PARALLEL:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   560
                    self.StartCursorTick = self.ParentWindow.GetRange()[0]
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   561
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   562
        # Mouse was clicked outside graph figure and over resize highlight with
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   563
        # left button, start resizing Viewer
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   564
        elif event.button == 1 and event.y <= 5:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   565
            self.MouseStartPos = wx.Point(x, y)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   566
            self.CanvasStartSize = height
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   567
    
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   568
    def OnCanvasButtonReleased(self, event):
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   569
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   570
        Function called when a button of mouse is released
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   571
        @param event: Mouse event
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   572
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   573
        # If a drag'n drop is in progress, stop it
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   574
        if self.ParentWindow.IsDragging():
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   575
            width, height = self.GetSize()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   576
            xw, yw = self.GetPosition()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   577
            item = self.ParentWindow.DraggingAxesPanel.ItemsDict.values()[0]
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   578
            # Give mouse position in wx coordinate of parent
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   579
            self.ParentWindow.StopDragNDrop(item.GetVariable(),
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   580
                xw + event.x, yw + height - event.y)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   581
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   582
        else:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   583
            # Reset any move in progress
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   584
            self.MouseStartPos = None
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   585
            self.StartCursorTick = None
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   586
            self.CanvasStartSize = None
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   587
            
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   588
            # Handle button under mouse if it exist
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   589
            width, height = self.GetSize()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   590
            self.HandleButton(event.x, height - event.y)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   591
    
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   592
    def OnCanvasMotion(self, event):
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   593
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   594
        Function called when a button of mouse is moved over Viewer
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   595
        @param event: Mouse event
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   596
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   597
        width, height = self.GetSize()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   598
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   599
        # If a drag'n drop is in progress, move canvas dragged
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   600
        if self.ParentWindow.IsDragging():
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   601
            xw, yw = self.GetPosition()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   602
            # Give mouse position in wx coordinate of parent
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   603
            self.ParentWindow.MoveDragNDrop(
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   604
                xw + event.x, 
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   605
                yw + height - event.y)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   606
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   607
        # If a Viewer resize is in progress, change Viewer size 
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   608
        elif event.button == 1 and self.CanvasStartSize is not None:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   609
            width, height = self.GetSize()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   610
            self.SetCanvasSize(width, 
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   611
                self.CanvasStartSize + height - event.y - self.MouseStartPos.y)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   612
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   613
        # If no button is pressed, show or hide contextual buttons or resize
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   614
        # highlight
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   615
        elif event.button is None:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   616
            # Compute direction for items label according graph type
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   617
            if self.GraphType == GRAPH_PARALLEL: # Graph is parallel
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   618
                directions = [wx.RIGHT] * len(self.AxesLabels) + \
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   619
                             [wx.LEFT] * len(self.Labels)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   620
            elif len(self.AxesLabels) > 0: # Graph is orthogonal in 2D
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   621
                directions = [wx.RIGHT, wx.TOP,  # Directions for AxesLabels
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   622
                             wx.LEFT, wx.BOTTOM] # Directions for Labels
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   623
            else: # Graph is orthogonal in 3D
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   624
                directions = [wx.LEFT] * len(self.Labels)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   625
            
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   626
            # Find if mouse is over an item label
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   627
            item_idx = None
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   628
            menu_direction = None
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   629
            for (i, t), dir in zip(
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   630
                    [pair for pair in enumerate(self.AxesLabels)] + 
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   631
                    [pair for pair in enumerate(self.Labels)], 
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   632
                    directions):
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   633
                # Check every label paired with corresponding item
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   634
                (x0, y0), (x1, y1) = t.get_window_extent().get_points()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   635
                rect = wx.Rect(x0, height - y1, x1 - x0, y1 - y0)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   636
                # Check if mouse was over label
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   637
                if rect.InsideXY(event.x, height - event.y):
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   638
                    item_idx = i
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   639
                    menu_direction = dir
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   640
                    break
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   641
            
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   642
            # If mouse is over an item label, 
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   643
            if item_idx is not None:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   644
                self.PopupContextualButtons(
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   645
                    self.ItemsDict.values()[item_idx], 
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   646
                    rect, menu_direction)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   647
                return
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   648
            
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   649
            # If mouse isn't over a contextual menu, hide the current shown one
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   650
            # if it exists 
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   651
            if self.IsOverContextualButton(event.x, height - event.y) is None:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   652
                self.DismissContextualButtons()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   653
            
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   654
            # Update resize highlight
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   655
            if event.y <= 5:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   656
                if self.SetHighlight(HIGHLIGHT_RESIZE):
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   657
                    self.SetCursor(wx.StockCursor(wx.CURSOR_SIZENS))
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   658
                    self.ParentWindow.ForceRefresh()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   659
            else:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   660
                if self.SetHighlight(HIGHLIGHT_NONE):
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   661
                    self.SetCursor(wx.NullCursor)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   662
                    self.ParentWindow.ForceRefresh()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   663
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   664
        # Handle buttons if canvas is not 3D 
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   665
        elif not self.Is3DCanvas():
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   666
            
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   667
            # If left button is pressed
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   668
            if event.button == 1:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   669
                
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   670
                # Mouse is inside graph figure
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   671
                if event.inaxes == self.Axes:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   672
                    
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   673
                    # If a cursor move is in progress, update cursor position
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   674
                    if self.MouseStartPos is not None:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   675
                        self.HandleCursorMove(event)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   676
                
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   677
                # Mouse is outside graph figure, cursor move is in progress and
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   678
                # there is only one item in Viewer, start a drag'n drop
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   679
                elif self.MouseStartPos is not None and len(self.Items) == 1:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   680
                    xw, yw = self.GetPosition()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   681
                    self.ParentWindow.SetCursorTick(self.StartCursorTick)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   682
                    self.ParentWindow.StartDragNDrop(self, 
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   683
                        self.ItemsDict.values()[0],
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   684
                        # Current mouse position
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   685
                        event.x + xw, height - event.y + yw,
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   686
                        # Mouse position when button was clicked
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   687
                        self.MouseStartPos.x + xw,
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   688
                        self.MouseStartPos.y + yw)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   689
            
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   690
            # If middle button is pressed and moving graph along X coordinate
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   691
            # is in progress
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   692
            elif event.button == 2 and self.GraphType == GRAPH_PARALLEL and \
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   693
                 self.MouseStartPos is not None:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   694
                start_tick, end_tick = self.ParentWindow.GetRange()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   695
                rect = self.GetAxesBoundingBox()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   696
                
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   697
                # Move graph along X coordinate
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   698
                self.ParentWindow.SetCanvasPosition(
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   699
                    self.StartCursorTick + 
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   700
                    (self.MouseStartPos.x - event.x) *
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   701
                    (end_tick - start_tick) / rect.width)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   702
    
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   703
    def OnCanvasScroll(self, event):
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   704
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   705
        Function called when a wheel mouse is use in Viewer
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   706
        @param event: Mouse event
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   707
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   708
        # Change X range of graphs if mouse is in canvas figure and ctrl is
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   709
        # pressed
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   710
        if event.inaxes is not None and event.guiEvent.ControlDown():
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   711
            
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   712
            # Calculate position of fixed tick point according to graph type
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   713
            # and mouse position
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   714
            if self.GraphType == GRAPH_ORTHOGONAL:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   715
                start_tick, end_tick = self.ParentWindow.GetRange()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   716
                tick = (start_tick + end_tick) / 2.
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   717
            else:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   718
                tick = event.xdata
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   719
            self.ParentWindow.ChangeRange(int(-event.step) / 3, tick)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   720
            
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   721
            # Vetoing event to prevent parent panel to be scrolled
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   722
            self.ParentWindow.VetoScrollEvent = True
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   723
    
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   724
    def OnAxesMotion(self, event):
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   725
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   726
        Function overriding default function called when mouse is dragged for
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   727
        rotating graph preventing refresh to be called too quickly
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   728
        @param event: Mouse event
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   729
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   730
        if self.Is3DCanvas():
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   731
            # Call default function at most 10 times per second
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   732
            current_time = gettime()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   733
            if current_time - self.LastMotionTime > REFRESH_PERIOD:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   734
                self.LastMotionTime = current_time
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   735
                Axes3D._on_move(self.Axes, event)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   736
    
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   737
    # Cursor tick move for each arrow key
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   738
    KEY_CURSOR_INCREMENT = {
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   739
        wx.WXK_LEFT: -1,
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   740
        wx.WXK_RIGHT: 1,
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   741
        wx.WXK_UP: -10,
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   742
        wx.WXK_DOWN: 10}
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   743
    
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   744
    def OnKeyDown(self, event):
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   745
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   746
        Function called when key is pressed
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   747
        @param event: wx.KeyEvent
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   748
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   749
        # If cursor is shown and arrow key is pressed, move cursor tick
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   750
        if self.CursorTick is not None:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   751
            move = self.KEY_CURSOR_INCREMENT.get(event.GetKeyCode(), None)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   752
            if move is not None:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   753
                self.ParentWindow.MoveCursorTick(move)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   754
        event.Skip()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   755
    
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   756
    def OnLeave(self, event):
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   757
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   758
        Function called when mouse leave Viewer
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   759
        @param event: wx.MouseEvent
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   760
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   761
        # If Viewer is not resizing, reset resize highlight
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   762
        if self.CanvasStartSize is None:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   763
            self.SetHighlight(HIGHLIGHT_NONE)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   764
            self.SetCursor(wx.NullCursor)
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   765
            DebugVariableViewer.OnLeave(self, event)
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   766
        else:
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   767
            event.Skip()
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   768
    
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   769
    def RefreshLabelsPosition(self, height):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   770
        canvas_ratio = 1. / height
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   771
        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
   772
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   773
        self.Figure.subplotpars.update(
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   774
            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
   775
            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
   776
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   777
        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
   778
            num_item = len(self.Items)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   779
            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
   780
                if not self.Is3DCanvas():
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   781
                    self.AxesLabels[idx].set_position(
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   782
                        (0.05, 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   783
                         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
   784
                self.Labels[idx].set_position(
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   785
                    (0.95, 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   786
                     CANVAS_PADDING * graph_ratio + 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   787
                     (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
   788
        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   789
            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
   790
            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
   791
            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
   792
            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
   793
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   794
        self.Figure.subplots_adjust()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   795
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   796
    def GetCanvasMinSize(self):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   797
        return wx.Size(200, 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   798
                       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
   799
                       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
   800
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   801
    def SetCanvasSize(self, width, height):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   802
        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
   803
        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
   804
        self.RefreshLabelsPosition(height)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   805
        self.ParentWindow.RefreshGraphicsSizer()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   806
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   807
    def GetAxesBoundingBox(self, absolute=False):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   808
        width, height = self.GetSize()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   809
        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
   810
        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
   811
                       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
   812
        if absolute:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   813
            xw, yw = self.GetPosition()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   814
            bbox.x += xw
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   815
            bbox.y += yw
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   816
        return bbox
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   817
    
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   818
    def RefreshHighlight(self, x, y):
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   819
        width, height = self.GetSize()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   820
        bbox = self.GetAxesBoundingBox()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   821
        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
   822
            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
   823
            if rect.InsideXY(x, y):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   824
                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
   825
            else:
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   826
                self.SetHighlight(HIGHLIGHT_RIGHT)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   827
        elif y < height / 2:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   828
            if self.ParentWindow.IsViewerFirst(self):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   829
                self.SetHighlight(HIGHLIGHT_BEFORE)
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   830
            else:
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   831
                self.SetHighlight(HIGHLIGHT_NONE)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   832
                self.ParentWindow.HighlightPreviousViewer(self)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   833
        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   834
            self.SetHighlight(HIGHLIGHT_AFTER)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   835
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   836
    def ResetGraphics(self):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   837
        self.Figure.clear()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   838
        if self.Is3DCanvas():
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   839
            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
   840
            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
   841
            self.LastMotionTime = gettime()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   842
            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
   843
            self.Axes.mouse_init()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   844
            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
   845
        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   846
            self.Axes = self.Figure.gca()
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   847
            self.Axes.set_color_cycle(COLOR_CYCLE)
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   848
        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
   849
        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
   850
        self.Plots = []
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   851
        self.VLine = None
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   852
        self.HLine = None
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   853
        self.Labels = []
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   854
        self.AxesLabels = []
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   855
        if not self.Is3DCanvas():
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   856
            text_func = self.Axes.text
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   857
        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   858
            text_func = self.Axes.text2D
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   859
        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
   860
            num_item = len(self.Items)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   861
            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
   862
                if num_item == 1:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   863
                    color = 'k'
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   864
                else:
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   865
                    color = COLOR_CYCLE[idx % len(COLOR_CYCLE)]
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   866
                if not self.Is3DCanvas():
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   867
                    self.AxesLabels.append(
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   868
                        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
   869
                                  verticalalignment='top', 
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   870
                                  color=color,
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
   871
                                  transform=self.Axes.transAxes))
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   872
                self.Labels.append(
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   873
                    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
   874
                              horizontalalignment='right',
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   875
                              color=color,
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   876
                              transform=self.Axes.transAxes))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   877
        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   878
            self.AxesLabels.append(
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   879
                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
   880
                               transform=self.Axes.transAxes))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   881
            self.Labels.append(
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   882
                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
   883
                               horizontalalignment='right',
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   884
                               transform=self.Axes.transAxes))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   885
            self.AxesLabels.append(
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   886
                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
   887
                               rotation='vertical',
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   888
                               verticalalignment='bottom',
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   889
                               transform=self.Axes.transAxes))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   890
            self.Labels.append(
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   891
                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
   892
                               rotation='vertical',
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   893
                               verticalalignment='top',
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   894
                               transform=self.Axes.transAxes))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   895
        width, height = self.GetSize()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   896
        self.RefreshLabelsPosition(height)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   897
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   898
    def SetCursorTick(self, cursor_tick):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   899
        self.CursorTick = cursor_tick
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   900
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   901
    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
   902
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   903
        if refresh_graphics:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   904
            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
   905
            
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   906
            if self.GraphType == GRAPH_PARALLEL:    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   907
                min_value = max_value = None
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   908
                
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   909
                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
   910
                    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
   911
                    if data is not None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   912
                        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
   913
                        if min_value is None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   914
                            min_value = item_min_value
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   915
                        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
   916
                            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
   917
                        if max_value is None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   918
                            max_value = item_max_value
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   919
                        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
   920
                            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
   921
                        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   922
                        if len(self.Plots) <= idx:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   923
                            self.Plots.append(
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   924
                                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
   925
                        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   926
                            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
   927
                    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   928
                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
   929
                    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
   930
                    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
   931
                else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   932
                    y_center = 0.5
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   933
                    y_range = 1.0
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   934
                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
   935
                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
   936
                
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   937
                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
   938
                    if self.VLine is None:
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   939
                        self.VLine = self.Axes.axvline(self.CursorTick, color=CURSOR_COLOR)
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   940
                    else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   941
                        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
   942
                    self.VLine.set_visible(True)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   943
                else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   944
                    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
   945
                        self.VLine.set_visible(False)
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
   946
            else:
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   947
                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
   948
                                              for item in self.Items
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   949
                                              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
   950
                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
   951
                end_tick = max(end_tick, min_start_tick)
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   952
                items = self.ItemsDict.values()
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   953
                x_data, x_min, x_max = OrthogonalDataAndRange(items[0], start_tick, end_tick)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   954
                y_data, y_min, y_max = OrthogonalDataAndRange(items[1], start_tick, end_tick)
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   955
                if self.CursorTick is not None:
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   956
                    x_cursor, x_forced = items[0].GetValue(self.CursorTick, raw=True)
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   957
                    y_cursor, y_forced = items[1].GetValue(self.CursorTick, raw=True)
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   958
                length = 0
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   959
                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
   960
                    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
   961
                if len(self.Items) < 3:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   962
                    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
   963
                        if len(self.Plots) == 0:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   964
                            self.Plots.append(
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   965
                                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
   966
                                               y_data[:, 1][:length])[0])
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   967
                        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   968
                            self.Plots[0].set_data(
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   969
                                x_data[:, 1][:length], 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   970
                                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
   971
                    
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   972
                    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
   973
                        if self.VLine is None:
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   974
                            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
   975
                        else:
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   976
                            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
   977
                        if self.HLine is None:
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   978
                            self.HLine = self.Axes.axhline(y_cursor, color=CURSOR_COLOR)
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   979
                        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   980
                            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
   981
                        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
   982
                        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
   983
                    else:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   984
                        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
   985
                            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
   986
                        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
   987
                            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
   988
                else:
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   989
                    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
   990
                        self.Axes.lines.pop()
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   991
                    z_data, z_min, z_max = OrthogonalDataAndRange(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
   992
                    if self.CursorTick is not None:
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   993
                        z_cursor, z_forced = items[2].GetValue(self.CursorTick, raw=True)
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   994
                    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
   995
                        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
   996
                        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
   997
                                       y_data[:, 1][:length],
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   998
                                       zs = z_data[:, 1][:length])
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   999
                    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
  1000
                    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
  1001
                        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
  1002
                                       {"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
  1003
                                       {"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
  1004
                            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
  1005
                                                 ("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
  1006
                                                 ("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
  1007
                                kwargs.setdefault(param, value)
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
  1008
                            kwargs["color"] = CURSOR_COLOR
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1009
                            self.Axes.plot(**kwargs)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1010
                
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1011
            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
  1012
            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
  1013
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1014
        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
  1015
        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
  1016
            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
  1017
        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1018
            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
  1019
        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
  1020
        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
  1021
        if self.Is3DCanvas():
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1022
            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
  1023
                                              self.Axes.set_ylabel,
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1024
                                              self.Axes.set_zlabel]):
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
  1025
                label_func(labels[idx], fontdict={'size': 'small','color': COLOR_CYCLE[idx]})
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1026
        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1027
            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
  1028
                label.set_text(text)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1029
        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
  1030
            label.set_text(value)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1031
            label.set_style(style)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1032
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1033
        self.draw()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
  1034
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1035
    def draw(self, drawDC=None):
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1036
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1037
        Render the figure.
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1038
        """
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1039
        # Render figure using agg
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1040
        FigureCanvasAgg.draw(self)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1041
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1042
        # Get bitmap of figure rendered
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1043
        self.bitmap = _convert_agg_to_wx_bitmap(self.get_renderer(), None)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1044
        self.bitmap.UseAlpha()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1045
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1046
        # Create DC for rendering graphics in bitmap
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1047
        destDC = wx.MemoryDC()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1048
        destDC.SelectObject(self.bitmap)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1049
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1050
        # Get Graphics Context for DC, for anti-aliased and transparent
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1051
        # rendering
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1052
        destGC = wx.GCDC(destDC)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1053
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1054
        destGC.BeginDrawing()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1055
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1056
        # Get canvas size and figure bounding box in canvas
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1057
        width, height = self.GetSize()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1058
        bbox = self.GetAxesBoundingBox()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1059
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1060
        # If highlight to display is resize, draw thick grey line at bottom
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1061
        # side of canvas 
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1062
        if self.Highlight == HIGHLIGHT_RESIZE:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1063
            destGC.SetPen(HIGHLIGHT_RESIZE_PEN)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1064
            destGC.SetBrush(HIGHLIGHT_RESIZE_BRUSH)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1065
            destGC.DrawRectangle(0, height - 5, width, 5)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1066
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1067
        # If highlight to display is merging graph, draw 50% transparent blue
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1068
        # rectangle on left or right part of figure depending on highlight type
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1069
        elif self.Highlight in [HIGHLIGHT_LEFT, HIGHLIGHT_RIGHT]:
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1070
            destGC.SetPen(HIGHLIGHT_DROP_PEN)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1071
            destGC.SetBrush(HIGHLIGHT_DROP_BRUSH)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1072
            
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1073
            x_offset = (bbox.width / 2 
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1074
                        if self.Highlight == HIGHLIGHT_RIGHT
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1075
                        else 0)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1076
            destGC.DrawRectangle(bbox.x + x_offset, bbox.y, 
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1077
                                 bbox.width / 2, bbox.height)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1078
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1079
        # Draw other Viewer common elements
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1080
        self.DrawCommonElements(destGC, self.GetButtons())
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1081
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1082
        destGC.EndDrawing()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1083
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1084
        self._isDrawn = True
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1085
        self.gui_repaint(drawDC=drawDC)
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1086
    
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
  1087