GraphicViewer.py
author Laurent Bessard
Fri, 13 Jul 2012 12:42:02 +0200
changeset 724 57b6446d54f8
parent 722 8c098eb05498
child 726 300ced19d03c
permissions -rw-r--r--
Adding support for using middle button for moving debug graph
Adding button for resetting zoom and of position of debug graph
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
     1
#!/usr/bin/env python
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
     3
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
     5
#based on the plcopen standard. 
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
     6
#
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
     8
#
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
     9
#See COPYING file for copyrights details.
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    10
#
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    15
#
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    19
#General Public License for more details.
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    20
#
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    24
711
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
    25
import numpy
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
    26
import math
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
    27
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    28
import wx
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    29
import wx.lib.plot as plot
711
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
    30
import wx.lib.buttons
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
    31
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
    32
from graphics.GraphicCommons import DebugViewer, MODE_SELECTION, MODE_MOTION
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 504
diff changeset
    33
from controls import EditorPanel
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 711
diff changeset
    34
from utils.BitmapLibrary import GetBitmap
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    35
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    36
colours = ['blue', 'red', 'green', 'yellow', 'orange', 'purple', 'brown', 'cyan',
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    37
           'pink', 'grey']
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    38
markers = ['circle', 'dot', 'square', 'triangle', 'triangle_down', 'cross', 'plus', 'circle']
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    39
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    40
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    41
#-------------------------------------------------------------------------------
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    42
#                       Debug Variable Graphic Viewer class
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    43
#-------------------------------------------------------------------------------
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    44
632
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
    45
SECOND = 1000000000
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
    46
MINUTE = 60 * SECOND
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
    47
HOUR = 60 * MINUTE
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
    48
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
    49
ZOOM_VALUES = map(lambda x:("x %.1f" % x, x), [math.sqrt(2) ** i for i in xrange(8)])
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
    50
RANGE_VALUES = map(lambda x: (str(x), x), [25 * 2 ** i for i in xrange(6)])
640
c32c169b8f63 Fixing segmentation fault in CustomEditableListBox on Windows when clicking on an header button while a value is being edited
laurent
parents: 632
diff changeset
    51
TIME_RANGE_VALUES = [("%ds" % i, i * SECOND) for i in (1, 2, 5, 10, 20, 30)] + \
632
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
    52
                    [("%dm" % i, i * MINUTE) for i in (1, 2, 5, 10, 20, 30)] + \
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
    53
                    [("%dh" % i, i * HOUR) for i in (1, 2, 3, 6, 12, 24)]
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    54
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 504
diff changeset
    55
class GraphicViewer(EditorPanel, DebugViewer):
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    56
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 504
diff changeset
    57
    def _init_Editor(self, prnt):
711
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
    58
        self.Editor = wx.Panel(prnt)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
    59
        
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
    60
        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
    61
        main_sizer.AddGrowableCol(0)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
    62
        main_sizer.AddGrowableRow(0)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
    63
        
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
    64
        self.Canvas = plot.PlotCanvas(self.Editor, name='Canvas')
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    65
        def _axisInterval(spec, lower, upper):
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    66
            if spec == 'border':
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    67
                if lower == upper:
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    68
                    return lower - 0.5, upper + 0.5
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    69
                else:
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    70
                    border = (upper - lower) * 0.05
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    71
                    return lower - border, upper + border
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    72
            else:
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    73
                return plot.PlotCanvas._axisInterval(self.Canvas, spec, lower, upper)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    74
        self.Canvas._axisInterval = _axisInterval
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    75
        self.Canvas.SetYSpec('border')
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
    76
        self.Canvas.canvas.Bind(wx.EVT_LEFT_DOWN, self.OnCanvasLeftDown)
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
    77
        self.Canvas.canvas.Bind(wx.EVT_LEFT_UP, self.OnCanvasLeftUp)
724
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
    78
        self.Canvas.canvas.Bind(wx.EVT_MIDDLE_DOWN, self.OnCanvasMiddleDown)
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
    79
        self.Canvas.canvas.Bind(wx.EVT_MIDDLE_UP, self.OnCanvasMiddleUp)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
    80
        self.Canvas.canvas.Bind(wx.EVT_MOTION, self.OnCanvasMotion)
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
    81
        self.Canvas.canvas.Bind(wx.EVT_MOUSEWHEEL, self.OnCanvasMouseWheel)
668
e858ff2f7862 Fix cursor refresh when GraphicViewer canvas is resized
laurent
parents: 665
diff changeset
    82
        self.Canvas.canvas.Bind(wx.EVT_SIZE, self.OnCanvasResize)
711
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
    83
        main_sizer.AddWindow(self.Canvas, 0, border=0, flag=wx.GROW)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
    84
        
724
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
    85
        range_sizer = wx.FlexGridSizer(cols=10, hgap=5, rows=1, vgap=0)
711
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
    86
        range_sizer.AddGrowableCol(5)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
    87
        range_sizer.AddGrowableRow(0)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
    88
        main_sizer.AddSizer(range_sizer, 0, border=5, flag=wx.GROW|wx.ALL)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
    89
        
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
    90
        range_label = wx.StaticText(self.Editor, label=_('Range:'))
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
    91
        range_sizer.AddWindow(range_label, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
    92
        
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
    93
        self.CanvasRange = wx.ComboBox(self.Editor, 
640
c32c169b8f63 Fixing segmentation fault in CustomEditableListBox on Windows when clicking on an header button while a value is being edited
laurent
parents: 632
diff changeset
    94
              size=wx.Size(100, 28), style=wx.CB_READONLY)
711
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
    95
        self.Bind(wx.EVT_COMBOBOX, self.OnRangeChanged, self.CanvasRange)
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 711
diff changeset
    96
        range_sizer.AddWindow(self.CanvasRange, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL)
711
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
    97
        
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
    98
        zoom_label = wx.StaticText(self.Editor, label=_('Zoom:'))
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
    99
        range_sizer.AddWindow(zoom_label, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   100
        
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   101
        self.CanvasZoom = wx.ComboBox(self.Editor, 
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   102
              size=wx.Size(70, 28), style=wx.CB_READONLY)
711
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   103
        self.Bind(wx.EVT_COMBOBOX, self.OnZoomChanged, self.CanvasZoom)
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 711
diff changeset
   104
        range_sizer.AddWindow(self.CanvasZoom, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL)
711
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   105
        
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   106
        position_label = wx.StaticText(self.Editor, label=_('Position:'))
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   107
        range_sizer.AddWindow(position_label, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   108
        
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   109
        self.CanvasPosition = wx.ScrollBar(self.Editor, 
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   110
              size=wx.Size(0, 16), style=wx.SB_HORIZONTAL)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   111
        self.CanvasPosition.SetScrollbar(0, 10, 100, 10)
711
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   112
        self.CanvasPosition.Bind(wx.EVT_SCROLL_THUMBTRACK, 
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   113
              self.OnPositionChanging, self.CanvasPosition)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   114
        self.CanvasPosition.Bind(wx.EVT_SCROLL_LINEUP, 
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   115
              self.OnPositionChanging, self.CanvasPosition)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   116
        self.CanvasPosition.Bind(wx.EVT_SCROLL_LINEDOWN, 
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   117
              self.OnPositionChanging, self.CanvasPosition)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   118
        self.CanvasPosition.Bind(wx.EVT_SCROLL_PAGEUP, 
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   119
              self.OnPositionChanging, self.CanvasPosition)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   120
        self.CanvasPosition.Bind(wx.EVT_SCROLL_PAGEDOWN, 
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   121
              self.OnPositionChanging, self.CanvasPosition)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   122
        range_sizer.AddWindow(self.CanvasPosition, 0, border=5, flag=wx.GROW|wx.ALL)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   123
        
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 711
diff changeset
   124
        self.ResetButton = wx.lib.buttons.GenBitmapButton(self.Editor, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 711
diff changeset
   125
              bitmap=GetBitmap("reset"), size=wx.Size(28, 28), style=wx.NO_BORDER)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 711
diff changeset
   126
        self.ResetButton.SetToolTipString(_("Clear the graph values"))
711
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   127
        self.Bind(wx.EVT_BUTTON, self.OnResetButton, self.ResetButton)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   128
        range_sizer.AddWindow(self.ResetButton, 0, border=0, flag=0)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   129
        
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 711
diff changeset
   130
        self.CurrentButton = wx.lib.buttons.GenBitmapButton(self.Editor, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 711
diff changeset
   131
              bitmap=GetBitmap("current"), size=wx.Size(28, 28), style=wx.NO_BORDER)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 711
diff changeset
   132
        self.CurrentButton.SetToolTipString(_("Go to current value"))
711
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   133
        self.Bind(wx.EVT_BUTTON, self.OnCurrentButton, self.CurrentButton)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   134
        range_sizer.AddWindow(self.CurrentButton, 0, border=0, flag=0)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   135
        
724
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   136
        self.ResetZoomOffsetButton = wx.lib.buttons.GenBitmapButton(self.Editor, 
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   137
              bitmap=GetBitmap("fit"), size=wx.Size(28, 28), style=wx.NO_BORDER)
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   138
        self.CurrentButton.SetToolTipString(_("Reset zoom and offset"))
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   139
        self.Bind(wx.EVT_BUTTON, self.OnResetZoomOffsetButton, 
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   140
              self.ResetZoomOffsetButton)
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   141
        range_sizer.AddWindow(self.ResetZoomOffsetButton, 0, border=0, flag=0)
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   142
        
711
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   143
        self.ExportGraphButton = wx.lib.buttons.GenBitmapButton(self.Editor, 
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 711
diff changeset
   144
              bitmap=GetBitmap("export_graph"), size=wx.Size(28, 28), style=wx.NO_BORDER)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 711
diff changeset
   145
        self.ExportGraphButton.SetToolTipString(_("Export graph values to clipboard"))
711
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   146
        self.Bind(wx.EVT_BUTTON, self.OnExportGraphButtonClick, 
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   147
                self.ExportGraphButton)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   148
        range_sizer.AddWindow(self.ExportGraphButton, 0, border=0, flag=0)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   149
        
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   150
        self.Editor.SetSizer(main_sizer)
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   151
415
d3d8f8f0b678 controler (PLCControler) and debug data producer (PluginsRoot) are no longer the same thing
b.taylor@willowglen.ca
parents: 374
diff changeset
   152
    def __init__(self, parent, window, producer, instancepath = ""):
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 504
diff changeset
   153
        EditorPanel.__init__(self, parent, "", window, None)
415
d3d8f8f0b678 controler (PLCControler) and debug data producer (PluginsRoot) are no longer the same thing
b.taylor@willowglen.ca
parents: 374
diff changeset
   154
        DebugViewer.__init__(self, producer, True, False)
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   155
        
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   156
        self.InstancePath = instancepath
632
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   157
        self.RangeValues = None
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   158
        self.CursorIdx = None
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   159
        self.LastCursor = None
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   160
        self.CurrentMousePos = None
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   161
        self.CurrentMotionValue = None
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   162
        self.Dragging = False
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   163
        
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   164
        # Initialize Viewer mode to Selection mode
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   165
        self.Mode = MODE_SELECTION
632
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   166
        
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   167
        self.Datas = []
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   168
        self.StartTick = 0
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   169
        self.StartIdx = 0
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   170
        self.EndIdx = 0
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   171
        self.MinValue = None
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   172
        self.MaxValue = None
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   173
        self.YCenter = 0
724
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   174
        self.CurrentZoom = 1.0
642
f2325ebd67f4 Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents: 640
diff changeset
   175
        self.Fixed = False
668
e858ff2f7862 Fix cursor refresh when GraphicViewer canvas is resized
laurent
parents: 665
diff changeset
   176
        self.Ticktime = self.DataProducer.GetTicktime()
632
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   177
        self.RefreshCanvasRange()
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   178
        
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   179
        for zoom_txt, zoom in ZOOM_VALUES:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   180
            self.CanvasZoom.Append(zoom_txt)
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   181
        self.CanvasZoom.SetSelection(0)
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   182
        
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   183
        self.AddDataConsumer(self.InstancePath.upper(), self)
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   184
    
338
87e5015330ae Adding support for ToolTip on wire when debugging
lbessard
parents: 331
diff changeset
   185
    def __del__(self):
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   186
        DebugViewer.__del__(self)
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   187
        self.RemoveDataConsumer(self)
338
87e5015330ae Adding support for ToolTip on wire when debugging
lbessard
parents: 331
diff changeset
   188
    
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 504
diff changeset
   189
    def GetTitle(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 504
diff changeset
   190
        if len(self.InstancePath) > 15:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 504
diff changeset
   191
            return "..." + self.InstancePath[-12:]
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 504
diff changeset
   192
        return self.InstancePath
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 504
diff changeset
   193
    
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   194
    # Changes Viewer mode
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   195
    def SetMode(self, mode):
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   196
        if self.Mode != mode or mode == MODE_SELECTION:    
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   197
            if self.Mode == MODE_MOTION:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   198
                wx.CallAfter(self.Canvas.canvas.SetCursor, wx.NullCursor)
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   199
            self.Mode = mode
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   200
        if self.Mode == MODE_MOTION:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   201
            wx.CallAfter(self.Canvas.canvas.SetCursor, wx.StockCursor(wx.CURSOR_HAND))
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   202
        
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   203
    def ResetView(self, register=False):
338
87e5015330ae Adding support for ToolTip on wire when debugging
lbessard
parents: 331
diff changeset
   204
        self.Datas = []
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   205
        self.StartTick = 0
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   206
        self.StartIdx = 0
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   207
        self.EndIdx = 0
706
9920d8c07e5e Fix bug graphic values range not reinitialized when graphic reseted
Laurent Bessard
parents: 687
diff changeset
   208
        self.MinValue = None
9920d8c07e5e Fix bug graphic values range not reinitialized when graphic reseted
Laurent Bessard
parents: 687
diff changeset
   209
        self.MaxValue = None
665
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   210
        self.CursorIdx = None
642
f2325ebd67f4 Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents: 640
diff changeset
   211
        self.Fixed = False
632
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   212
        self.Ticktime = self.DataProducer.GetTicktime()
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   213
        if register:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   214
            self.AddDataConsumer(self.InstancePath.upper(), self)
665
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   215
        self.ResetLastCursor()
632
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   216
        self.RefreshCanvasRange()
338
87e5015330ae Adding support for ToolTip on wire when debugging
lbessard
parents: 331
diff changeset
   217
        self.RefreshView()
87e5015330ae Adding support for ToolTip on wire when debugging
lbessard
parents: 331
diff changeset
   218
    
642
f2325ebd67f4 Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents: 640
diff changeset
   219
    def RefreshNewData(self, *args, **kwargs):
f2325ebd67f4 Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents: 640
diff changeset
   220
        self.RefreshView(*args, **kwargs)
374
16a0a6cb1644 Bug on GraphicViewer with latest modifications fixed
greg
parents: 361
diff changeset
   221
        DebugViewer.RefreshNewData(self)
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   222
    
642
f2325ebd67f4 Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents: 640
diff changeset
   223
    def GetNearestData(self, tick, adjust):
f2325ebd67f4 Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents: 640
diff changeset
   224
        ticks = numpy.array(zip(*self.Datas)[0])
f2325ebd67f4 Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents: 640
diff changeset
   225
        new_cursor = numpy.argmin(abs(ticks - tick))
f2325ebd67f4 Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents: 640
diff changeset
   226
        if adjust == -1 and ticks[new_cursor] > tick and new_cursor > 0:
f2325ebd67f4 Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents: 640
diff changeset
   227
            new_cursor -= 1
f2325ebd67f4 Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents: 640
diff changeset
   228
        elif adjust == 1 and ticks[new_cursor] < tick and new_cursor < len(self.Datas):
f2325ebd67f4 Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents: 640
diff changeset
   229
            new_cursor += 1
f2325ebd67f4 Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents: 640
diff changeset
   230
        return new_cursor
f2325ebd67f4 Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents: 640
diff changeset
   231
    
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   232
    def GetBounds(self):
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   233
        if self.StartIdx is None or self.EndIdx is None:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   234
            self.StartIdx = self.GetNearestData(self.StartTick, -1)
665
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   235
            self.EndIdx = self.GetNearestData(self.StartTick + self.CurrentRange, 1)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   236
    
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   237
    def ResetBounds(self):
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   238
        self.StartIdx = None
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   239
        self.EndIdx = None
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   240
    
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   241
    def RefreshCanvasRange(self):
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   242
        if self.Ticktime == 0 and self.RangeValues != RANGE_VALUES:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   243
            self.RangeValues = RANGE_VALUES
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   244
            self.CanvasRange.Clear()
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   245
            for text, value in RANGE_VALUES:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   246
                self.CanvasRange.Append(text)
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   247
            self.CanvasRange.SetStringSelection(RANGE_VALUES[0][0])
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   248
            self.CurrentRange = RANGE_VALUES[0][1]
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   249
        elif self.RangeValues != TIME_RANGE_VALUES:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   250
            self.RangeValues = TIME_RANGE_VALUES
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   251
            self.CanvasRange.Clear()
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   252
            for text, value in TIME_RANGE_VALUES:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   253
                self.CanvasRange.Append(text)
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   254
            self.CanvasRange.SetStringSelection(TIME_RANGE_VALUES[0][0])
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   255
            self.CurrentRange = TIME_RANGE_VALUES[0][1] / self.Ticktime
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   256
        
722
8c098eb05498 Fix bug with graphic viewer and zoom
Laurent Bessard
parents: 714
diff changeset
   257
    def RefreshView(self, force=False):
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   258
        self.Freeze()
665
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   259
        if force or not self.Fixed or (len(self.Datas) > 0 and self.StartTick + self.CurrentRange > self.Datas[-1][0]):
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   260
            if (self.MinValue is not None and 
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   261
                self.MaxValue is not None and 
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   262
                self.MinValue != self.MaxValue):
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   263
                Yrange = float(self.MaxValue - self.MinValue) / self.CurrentZoom
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   264
            else:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   265
                Yrange = 2. / self.CurrentZoom
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   266
            
722
8c098eb05498 Fix bug with graphic viewer and zoom
Laurent Bessard
parents: 714
diff changeset
   267
            if not force and not self.Fixed and len(self.Datas) > 0:
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   268
                self.YCenter = max(self.Datas[-1][1] - Yrange / 2, 
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   269
                               min(self.YCenter, 
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   270
                                   self.Datas[-1][1] + Yrange / 2))
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   271
            
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   272
            var_name = self.InstancePath.split(".")[-1]
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   273
            
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   274
            self.GetBounds()
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   275
            self.VariableGraphic = plot.PolyLine(self.Datas[self.StartIdx:self.EndIdx + 1], 
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   276
                                                 legend=var_name, colour=colours[0])
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   277
            self.GraphicsObject = plot.PlotGraphics([self.VariableGraphic], _("%s Graphics") % var_name, _("Tick"), _("Values"))
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   278
            self.Canvas.Draw(self.GraphicsObject, 
665
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   279
                             xAxis=(self.StartTick, self.StartTick + self.CurrentRange),
722
8c098eb05498 Fix bug with graphic viewer and zoom
Laurent Bessard
parents: 714
diff changeset
   280
                             yAxis=(self.YCenter - Yrange * 1.1 / 2., self.YCenter + Yrange * 1.1 / 2.))
665
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   281
        
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   282
            # Reset and draw cursor 
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   283
            self.ResetLastCursor()
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   284
            self.RefreshCursor()
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   285
        
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   286
        self.RefreshScrollBar()
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   287
        
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   288
        self.Thaw()
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   289
    
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   290
    def GetInstancePath(self):
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   291
        return self.InstancePath
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   292
    
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   293
    def IsViewing(self, tagname):
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   294
        return self.InstancePath == tagname
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   295
    
504
f88e0ebd8fe4 Forced variable now supported in GraphicViewer
edouard
parents: 431
diff changeset
   296
    def NewValue(self, tick, value, forced=False):
724
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   297
        value = {True:1., False:0.}.get(value, float(value))
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   298
        self.Datas.append((float(tick), value))
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   299
        if self.MinValue is None:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   300
            self.MinValue = value
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   301
        else:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   302
            self.MinValue = min(self.MinValue, value)
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   303
        if self.MaxValue is None:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   304
            self.MaxValue = value
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   305
        else:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   306
            self.MaxValue = max(self.MaxValue, value)
665
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   307
        if not self.Fixed or tick < self.StartTick + self.CurrentRange:
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   308
            self.GetBounds()
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   309
            while int(self.Datas[self.StartIdx][0]) < tick - self.CurrentRange:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   310
                self.StartIdx += 1
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   311
            self.EndIdx += 1
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   312
            self.StartTick = self.Datas[self.StartIdx][0]
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   313
        self.NewDataAvailable()
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   314
    
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   315
    def RefreshScrollBar(self):
642
f2325ebd67f4 Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents: 640
diff changeset
   316
        if len(self.Datas) > 0:
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   317
            self.GetBounds()
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   318
            pos = int(self.Datas[self.StartIdx][0] - self.Datas[0][0])
642
f2325ebd67f4 Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents: 640
diff changeset
   319
            range = int(self.Datas[-1][0] - self.Datas[0][0])
f2325ebd67f4 Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents: 640
diff changeset
   320
        else:
f2325ebd67f4 Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents: 640
diff changeset
   321
            pos = 0
f2325ebd67f4 Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents: 640
diff changeset
   322
            range = 0
f2325ebd67f4 Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents: 640
diff changeset
   323
        self.CanvasPosition.SetScrollbar(pos, self.CurrentRange, range, self.CurrentRange)
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   324
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   325
    def RefreshRange(self):
648
95d165193770 Fix bug in GraphicViewer when changing range while no data received
laurent
parents: 642
diff changeset
   326
        if len(self.Datas) > 0:
95d165193770 Fix bug in GraphicViewer when changing range while no data received
laurent
parents: 642
diff changeset
   327
            if self.Fixed and self.Datas[-1][0] - self.Datas[0][0] < self.CurrentRange:
95d165193770 Fix bug in GraphicViewer when changing range while no data received
laurent
parents: 642
diff changeset
   328
                self.Fixed = False
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   329
            self.ResetBounds()
648
95d165193770 Fix bug in GraphicViewer when changing range while no data received
laurent
parents: 642
diff changeset
   330
            if self.Fixed:
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   331
                self.StartTick = min(self.StartTick, self.Datas[-1][0] - self.CurrentRange)
648
95d165193770 Fix bug in GraphicViewer when changing range while no data received
laurent
parents: 642
diff changeset
   332
            else:
665
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   333
                self.StartTick = max(self.Datas[0][0], self.Datas[-1][0] - self.CurrentRange)
722
8c098eb05498 Fix bug with graphic viewer and zoom
Laurent Bessard
parents: 714
diff changeset
   334
        self.RefreshView(True)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   335
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   336
    def OnRangeChanged(self, event):
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   337
        try:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   338
            if self.Ticktime == 0:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   339
                self.CurrentRange = self.RangeValues[self.CanvasRange.GetSelection()][1]
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   340
            else:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   341
                self.CurrentRange = self.RangeValues[self.CanvasRange.GetSelection()][1] / self.Ticktime
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   342
        except ValueError, e:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   343
            self.CanvasRange.SetValue(str(self.CurrentRange))
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   344
        wx.CallAfter(self.RefreshRange)
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   345
        event.Skip()
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   346
    
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   347
    def OnZoomChanged(self, event):
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   348
        self.CurrentZoom = ZOOM_VALUES[self.CanvasZoom.GetSelection()][1]
722
8c098eb05498 Fix bug with graphic viewer and zoom
Laurent Bessard
parents: 714
diff changeset
   349
        wx.CallAfter(self.RefreshView, True)
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   350
        event.Skip()
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   351
    
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   352
    def OnPositionChanging(self, event):
724
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   353
        if len(self.Datas) > 0:
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   354
            self.ResetBounds()
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   355
            self.StartTick = self.Datas[0][0] + event.GetPosition()
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   356
            self.Fixed = True
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   357
            self.NewDataAvailable(True)
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   358
        event.Skip()
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   359
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   360
    def OnResetButton(self, event):
642
f2325ebd67f4 Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents: 640
diff changeset
   361
        self.Fixed = False
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   362
        self.ResetView()
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   363
        event.Skip()
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   364
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   365
    def OnCurrentButton(self, event):
724
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   366
        if len(self.Datas) > 0:
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   367
            self.ResetBounds()
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   368
            self.StartTick = max(self.Datas[0][0], self.Datas[-1][0] - self.CurrentRange)
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   369
            self.Fixed = False
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   370
            self.NewDataAvailable(True)
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   371
        event.Skip()
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   372
    
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   373
    def OnResetZoomOffsetButton(self, event):
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   374
        if len(self.Datas) > 0:
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   375
            self.YCenter = (self.MaxValue + self.MinValue) / 2
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   376
        else:
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   377
            self.YCenter = 0.0
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   378
        self.CurrentZoom = 1.0
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   379
        self.CanvasZoom.SetSelection(0)
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   380
        wx.CallAfter(self.RefreshView, True)
642
f2325ebd67f4 Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents: 640
diff changeset
   381
        event.Skip()
711
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   382
    
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   383
    def OnExportGraphButtonClick(self, event):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   384
        data_copy = self.Datas[:]
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   385
        text = "tick;%s;\n" % self.InstancePath
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   386
        for tick, value in data_copy:
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   387
            text += "%d;%.3f;\n" % (tick, value)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   388
        self.ParentWindow.SetCopyBuffer(text)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents: 706
diff changeset
   389
        event.Skip()
642
f2325ebd67f4 Fixed wrong time scale in debug graph display when some samples are missed
laurent
parents: 640
diff changeset
   390
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   391
    def OnCanvasLeftDown(self, event):
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   392
        self.Fixed = True
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   393
        self.Canvas.canvas.CaptureMouse()
665
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   394
        if len(self.Datas) > 0:
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   395
            if self.Mode == MODE_SELECTION:
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   396
                self.Dragging = True
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   397
                pos = self.Canvas.PositionScreenToUser(event.GetPosition())
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   398
                self.CursorIdx = self.GetNearestData(pos[0], -1)
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   399
                self.RefreshCursor()
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   400
            elif self.Mode == MODE_MOTION:
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   401
                self.GetBounds()
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   402
                self.CurrentMousePos = event.GetPosition()
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   403
                self.CurrentMotionValue = self.Datas[self.StartIdx][0]
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   404
        event.Skip()
724
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   405
    
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   406
    def OnCanvasLeftUp(self, event):
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   407
        self.Dragging = False
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   408
        if self.Mode == MODE_MOTION:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   409
            self.CurrentMousePos = None
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   410
            self.CurrentMotionValue = None
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   411
        if self.Canvas.canvas.HasCapture():
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   412
            self.Canvas.canvas.ReleaseMouse()
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   413
        event.Skip()
724
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   414
    
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   415
    def OnCanvasMiddleDown(self, event):
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   416
        self.Fixed = True
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   417
        self.Canvas.canvas.CaptureMouse()
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   418
        if len(self.Datas) > 0:
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   419
            self.GetBounds()
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   420
            self.CurrentMousePos = event.GetPosition()
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   421
            self.CurrentMotionValue = self.Datas[self.StartIdx][0]
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   422
        event.Skip()
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   423
        
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   424
    def OnCanvasMiddleUp(self, event):
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   425
        self.CurrentMousePos = None
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   426
        self.CurrentMotionValue = None
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   427
        if self.Canvas.canvas.HasCapture():
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   428
            self.Canvas.canvas.ReleaseMouse()
57b6446d54f8 Adding support for using middle button for moving debug graph
Laurent Bessard
parents: 722
diff changeset
   429
        event.Skip()
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   430
        
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   431
    def OnCanvasMotion(self, event):
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   432
        if self.Mode == MODE_SELECTION and self.Dragging:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   433
            pos = self.Canvas.PositionScreenToUser(event.GetPosition())
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   434
            graphics, xAxis, yAxis = self.Canvas.last_draw
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   435
            self.CursorIdx = self.GetNearestData(max(xAxis[0], min(pos[0], xAxis[1])), -1)
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   436
            self.RefreshCursor()
665
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   437
        elif self.CurrentMousePos is not None and len(self.Datas) > 0:
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   438
            oldpos = self.Canvas.PositionScreenToUser(self.CurrentMousePos)
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   439
            newpos = self.Canvas.PositionScreenToUser(event.GetPosition())
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   440
            self.CurrentMotionValue += oldpos[0] - newpos[0]
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   441
            self.YCenter += oldpos[1] - newpos[1]
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   442
            self.ResetBounds()
665
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   443
            self.StartTick = max(self.Datas[0][0], min(self.CurrentMotionValue, self.Datas[-1][0] - self.CurrentRange))
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   444
            self.CurrentMousePos = event.GetPosition()
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   445
            self.NewDataAvailable(True)
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   446
        event.Skip()
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   447
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   448
    def OnCanvasMouseWheel(self, event):
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   449
        if self.CurrentMousePos is None:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   450
            rotation = event.GetWheelRotation() / event.GetWheelDelta()
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   451
            if event.ShiftDown():
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   452
                current = self.CanvasRange.GetSelection()
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   453
                new = max(0, min(current - rotation, len(self.RangeValues) - 1))
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   454
                if new != current:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   455
                    if self.Ticktime == 0:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   456
                        self.CurrentRange = self.RangeValues[new][1]
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   457
                    else:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   458
                        self.CurrentRange = self.RangeValues[new][1] / self.Ticktime
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   459
                    self.CanvasRange.SetStringSelection(self.RangeValues[new][0])
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   460
                    wx.CallAfter(self.RefreshRange)
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   461
            else:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   462
                current = self.CanvasZoom.GetSelection()
722
8c098eb05498 Fix bug with graphic viewer and zoom
Laurent Bessard
parents: 714
diff changeset
   463
                new = max(0, min(current + rotation, len(ZOOM_VALUES) - 1))
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   464
                if new != current:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   465
                    self.CurrentZoom = ZOOM_VALUES[new][1]
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   466
                    self.CanvasZoom.SetStringSelection(ZOOM_VALUES[new][0])
722
8c098eb05498 Fix bug with graphic viewer and zoom
Laurent Bessard
parents: 714
diff changeset
   467
                    wx.CallAfter(self.RefreshView, True)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   468
        event.Skip()
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   469
668
e858ff2f7862 Fix cursor refresh when GraphicViewer canvas is resized
laurent
parents: 665
diff changeset
   470
    def OnCanvasResize(self, event):
e858ff2f7862 Fix cursor refresh when GraphicViewer canvas is resized
laurent
parents: 665
diff changeset
   471
        self.ResetLastCursor()
e858ff2f7862 Fix cursor refresh when GraphicViewer canvas is resized
laurent
parents: 665
diff changeset
   472
        wx.CallAfter(self.RefreshCursor)
e858ff2f7862 Fix cursor refresh when GraphicViewer canvas is resized
laurent
parents: 665
diff changeset
   473
        event.Skip()
e858ff2f7862 Fix cursor refresh when GraphicViewer canvas is resized
laurent
parents: 665
diff changeset
   474
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   475
    ## Reset the last cursor
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   476
    def ResetLastCursor(self):
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   477
        self.LastCursor = None
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   478
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   479
    ## Draw the cursor on graphic
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   480
    #  @param dc The draw canvas
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   481
    #  @param cursor The cursor parameters
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   482
    def DrawCursor(self, dc, cursor, value):
665
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   483
        if self.StartTick <= cursor <= self.StartTick + self.CurrentRange:
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   484
            # Prepare temporary dc for drawing
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   485
            width = self.Canvas._Buffer.GetWidth()
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   486
            height = self.Canvas._Buffer.GetHeight()
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   487
            tmp_Buffer = wx.EmptyBitmap(width, height)
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   488
            dcs = wx.MemoryDC()
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   489
            dcs.SelectObject(tmp_Buffer)
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   490
            dcs.Clear()
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   491
            dcs.BeginDrawing()
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   492
            
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   493
            dcs.SetPen(wx.Pen(wx.RED))
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   494
            dcs.SetBrush(wx.Brush(wx.RED, wx.SOLID))
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   495
            dcs.SetFont(self.Canvas._getFont(self.Canvas._fontSizeAxis))
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   496
            
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   497
            # Calculate clipping region
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   498
            graphics, xAxis, yAxis = self.Canvas.last_draw
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   499
            p1 = numpy.array([xAxis[0], yAxis[0]])
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   500
            p2 = numpy.array([xAxis[1], yAxis[1]])
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   501
            cx, cy, cwidth, cheight = self.Canvas._point2ClientCoord(p1, p2)
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   502
            
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   503
            px, py = self.Canvas.PositionUserToScreen((float(cursor), 0.))
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   504
            
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   505
            # Draw line cross drawing for diaplaying time cursor
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   506
            dcs.DrawLine(px, cy + 1, px, cy + cheight - 1)
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   507
            
665
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   508
            lines = ("X:%d\nY:%f" % (cursor, value)).splitlines()
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   509
            
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   510
            wtext = 0
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   511
            for line in lines:
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   512
                w, h = dcs.GetTextExtent(line)
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   513
                wtext = max(wtext, w)
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   514
            
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   515
            offset = 0
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   516
            for line in lines:
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   517
                # Draw time cursor date
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   518
                dcs.DrawText(line, min(px + 3, cx + cwidth - wtext), cy + 3 + offset)
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   519
                w, h = dcs.GetTextExtent(line)
6a376615142e Fix bugs in GraphicViewer with selection and navigation
laurent
parents: 660
diff changeset
   520
                offset += h
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   521
            
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   522
            dcs.EndDrawing()
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   523
    
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   524
            #this will erase if called twice
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   525
            dc.Blit(0, 0, width, height, dcs, 0, 0, wx.EQUIV)  #(NOT src) XOR dst
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   526
    
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   527
    ## Refresh the variable cursor.
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   528
    #  @param dc The draw canvas
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 648
diff changeset
   529
    def RefreshCursor(self, dc=None):
687
629680fb0582 refactoring
laurent
parents: 668
diff changeset
   530
        if self:
629680fb0582 refactoring
laurent
parents: 668
diff changeset
   531
            if dc is None:
629680fb0582 refactoring
laurent
parents: 668
diff changeset
   532
                dc = wx.BufferedDC(wx.ClientDC(self.Canvas.canvas), self.Canvas._Buffer)
629680fb0582 refactoring
laurent
parents: 668
diff changeset
   533
            
629680fb0582 refactoring
laurent
parents: 668
diff changeset
   534
            # Erase previous time cursor if drawn
629680fb0582 refactoring
laurent
parents: 668
diff changeset
   535
            if self.LastCursor is not None:
629680fb0582 refactoring
laurent
parents: 668
diff changeset
   536
                self.DrawCursor(dc, *self.LastCursor)
629680fb0582 refactoring
laurent
parents: 668
diff changeset
   537
            
629680fb0582 refactoring
laurent
parents: 668
diff changeset
   538
            # Draw new time cursor
629680fb0582 refactoring
laurent
parents: 668
diff changeset
   539
            if self.CursorIdx is not None:
629680fb0582 refactoring
laurent
parents: 668
diff changeset
   540
                self.LastCursor = self.Datas[self.CursorIdx]
629680fb0582 refactoring
laurent
parents: 668
diff changeset
   541
                self.DrawCursor(dc, *self.LastCursor)