GraphicViewer.py
author laurent
Mon, 30 Jan 2012 16:12:19 +0100
changeset 633 3536f4469cde
parent 632 3ea55a5db68e
child 640 c32c169b8f63
permissions -rw-r--r--
Fixing ToolTip behavior and bug with INOUT interface variables in Function Blocks and adding support for display connection point between wire and connector when mouse passing over.
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
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    25
import wx
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    26
import wx.lib.plot as plot
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
    27
from graphics.GraphicCommons import DebugViewer
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 504
diff changeset
    28
from controls import EditorPanel
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    29
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    30
colours = ['blue', 'red', 'green', 'yellow', 'orange', 'purple', 'brown', 'cyan',
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    31
           'pink', 'grey']
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    32
markers = ['circle', 'dot', 'square', 'triangle', 'triangle_down', 'cross', 'plus', 'circle']
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    33
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    34
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
#                       Debug Variable Graphic Viewer class
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    37
#-------------------------------------------------------------------------------
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    38
632
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
    39
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
    40
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
    41
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
    42
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
    43
RANGE_VALUES = [(str(25 * 2 ** i), 25 * 2 ** i) for i in xrange(6)]
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
    44
TIME_RANGE_VALUES = [("%ds" % i, i * SECOND) for i in (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
    45
                    [("%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
    46
                    [("%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
    47
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    48
[ID_GRAPHICVIEWER, ID_GRAPHICVIEWERCANVAS,
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    49
 ID_GRAPHICVIEWERCANVASRANGE, ID_GRAPHICVIEWERCANVASPOSITION,
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    50
 ID_GRAPHICVIEWERRESETBUTTON, ID_GRAPHICVIEWERCURRENTBUTTON, 
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    51
 ID_GRAPHICVIEWERSTATICTEXT1, ID_GRAPHICVIEWERSTATICTEXT2,
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    52
] = [wx.NewId() for _init_ctrls in range(8)]
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    53
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 504
diff changeset
    54
class GraphicViewer(EditorPanel, DebugViewer):
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    55
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    56
    def _init_coll_MainGridSizer_Items(self, parent):
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    57
        # generated method, don't edit
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    58
        parent.AddWindow(self.Canvas, 0, border=0, flag=wx.GROW)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    59
        parent.AddSizer(self.RangeSizer, 0, border=0, flag=wx.GROW)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    60
    
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    61
    def _init_coll_MainGridSizer_Growables(self, parent):
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    62
        # generated method, don't edit
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    63
        parent.AddGrowableCol(0)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    64
        parent.AddGrowableRow(0)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    65
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    66
    def _init_coll_RangeSizer_Items(self, parent):
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    67
        # generated method, don't edit
391
07447ee3538e Adding support for internationalization
laurent
parents: 374
diff changeset
    68
        parent.AddWindow(self.staticbox1, 0, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    69
        parent.AddWindow(self.CanvasRange, 0, border=5, flag=wx.ALL)
391
07447ee3538e Adding support for internationalization
laurent
parents: 374
diff changeset
    70
        parent.AddWindow(self.staticText2, 0, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    71
        parent.AddWindow(self.CanvasPosition, 0, border=5, flag=wx.GROW|wx.ALL)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    72
        parent.AddWindow(self.ResetButton, 0, border=5, flag=wx.ALL)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    73
        parent.AddWindow(self.CurrentButton, 0, border=5, flag=wx.ALL)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    74
        
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    75
    def _init_coll_RangeSizer_Growables(self, parent):
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    76
        # generated method, don't edit
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    77
        parent.AddGrowableCol(3)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    78
        parent.AddGrowableRow(0)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    79
        
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    80
    def _init_sizers(self):
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    81
        # generated method, don't edit
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    82
        self.MainGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    83
        self.RangeSizer = wx.FlexGridSizer(cols=6, hgap=0, rows=1, vgap=0)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    84
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    85
        self._init_coll_MainGridSizer_Items(self.MainGridSizer)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    86
        self._init_coll_MainGridSizer_Growables(self.MainGridSizer)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    87
        self._init_coll_RangeSizer_Items(self.RangeSizer)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    88
        self._init_coll_RangeSizer_Growables(self.RangeSizer)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    89
        
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 504
diff changeset
    90
        self.Editor.SetSizer(self.MainGridSizer)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 504
diff changeset
    91
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 504
diff changeset
    92
    def _init_Editor(self, prnt):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 504
diff changeset
    93
        self.Editor = wx.Panel(prnt, ID_GRAPHICVIEWER, wx.DefaultPosition, 
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    94
                 wx.DefaultSize, 0)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    95
        
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    96
        self.Canvas = plot.PlotCanvas(id=ID_GRAPHICVIEWERCANVAS, 
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 504
diff changeset
    97
              name='Canvas', parent=self.Editor, pos=wx.Point(0, 0),
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    98
              size=wx.Size(0, 0), style=0)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    99
        def _axisInterval(spec, lower, upper):
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   100
            if spec == 'border':
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   101
                if lower == upper:
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   102
                    return lower - 0.5, upper + 0.5
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   103
                else:
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   104
                    border = (upper - lower) * 0.05
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   105
                    return lower - border, upper + border
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   106
            else:
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   107
                return plot.PlotCanvas._axisInterval(self.Canvas, spec, lower, upper)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   108
        self.Canvas._axisInterval = _axisInterval
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   109
        self.Canvas.SetYSpec('border')
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   110
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   111
        self.staticbox1 = wx.StaticText(id=ID_GRAPHICVIEWERSTATICTEXT1,
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 504
diff changeset
   112
              label=_('Range:'), name='staticText1', parent=self.Editor,
391
07447ee3538e Adding support for internationalization
laurent
parents: 374
diff changeset
   113
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   114
        
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   115
        self.CanvasRange = wx.ComboBox(id=ID_GRAPHICVIEWERCANVASRANGE,
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 504
diff changeset
   116
              name='CanvasRange', parent=self.Editor, pos=wx.Point(0, 0),
632
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   117
              size=wx.Size(100, 28), style=0)
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   118
        self.Bind(wx.EVT_COMBOBOX, self.OnRangeChanged, id=ID_GRAPHICVIEWERCANVASRANGE)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   119
        self.Bind(wx.EVT_TEXT_ENTER, self.OnRangeChanged, id=ID_GRAPHICVIEWERCANVASRANGE)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   120
        
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   121
        self.staticText2 = wx.StaticText(id=ID_GRAPHICVIEWERSTATICTEXT2,
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 504
diff changeset
   122
              label=_('Position:'), name='staticText2', parent=self.Editor,
391
07447ee3538e Adding support for internationalization
laurent
parents: 374
diff changeset
   123
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   124
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   125
        self.CanvasPosition = wx.ScrollBar(id=ID_GRAPHICVIEWERCANVASPOSITION,
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 504
diff changeset
   126
              name='Position', parent=self.Editor, pos=wx.Point(0, 0),
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   127
              size=wx.Size(0, 16), style=wx.SB_HORIZONTAL)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   128
        self.CanvasPosition.SetScrollbar(0, 10, 100, 10)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   129
        self.CanvasPosition.Bind(wx.EVT_SCROLL_THUMBTRACK, self.OnPositionChanging, 
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   130
              id = ID_GRAPHICVIEWERCANVASPOSITION)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   131
        self.CanvasPosition.Bind(wx.EVT_SCROLL_LINEUP, self.OnPositionChanging, 
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   132
              id = ID_GRAPHICVIEWERCANVASPOSITION)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   133
        self.CanvasPosition.Bind(wx.EVT_SCROLL_LINEDOWN, self.OnPositionChanging, 
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   134
              id = ID_GRAPHICVIEWERCANVASPOSITION)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   135
        self.CanvasPosition.Bind(wx.EVT_SCROLL_PAGEUP, self.OnPositionChanging, 
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   136
              id = ID_GRAPHICVIEWERCANVASPOSITION)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   137
        self.CanvasPosition.Bind(wx.EVT_SCROLL_PAGEDOWN, self.OnPositionChanging, 
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   138
              id = ID_GRAPHICVIEWERCANVASPOSITION)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   139
        
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   140
        self.ResetButton = wx.Button(id=ID_GRAPHICVIEWERRESETBUTTON, label='Reset',
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 504
diff changeset
   141
              name='ResetButton', parent=self.Editor, pos=wx.Point(0, 0),
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   142
              size=wx.Size(72, 24), style=0)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   143
        self.Bind(wx.EVT_BUTTON, self.OnResetButton, id=ID_GRAPHICVIEWERRESETBUTTON)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   144
        
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   145
        self.CurrentButton = wx.Button(id=ID_GRAPHICVIEWERCURRENTBUTTON, label='Current',
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 504
diff changeset
   146
              name='CurrentButton', parent=self.Editor, pos=wx.Point(0, 0),
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   147
              size=wx.Size(72, 24), style=0)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   148
        self.Bind(wx.EVT_BUTTON, self.OnCurrentButton, id=ID_GRAPHICVIEWERCURRENTBUTTON)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   149
        
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   150
        self._init_sizers()
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
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   158
        
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   159
        self.Datas = []
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   160
        self.CurrentValue = 0
632
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   161
        self.Ticktime = self.DataProducer.GetTicktime()
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   162
        self.RefreshCanvasRange()
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   163
        
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   164
        self.AddDataConsumer(self.InstancePath.upper(), self)
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   165
    
338
87e5015330ae Adding support for ToolTip on wire when debugging
lbessard
parents: 331
diff changeset
   166
    def __del__(self):
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   167
        DebugViewer.__del__(self)
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   168
        self.RemoveDataConsumer(self)
338
87e5015330ae Adding support for ToolTip on wire when debugging
lbessard
parents: 331
diff changeset
   169
    
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 504
diff changeset
   170
    def GetTitle(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 504
diff changeset
   171
        if len(self.InstancePath) > 15:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 504
diff changeset
   172
            return "..." + self.InstancePath[-12:]
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 504
diff changeset
   173
        return self.InstancePath
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 504
diff changeset
   174
    
338
87e5015330ae Adding support for ToolTip on wire when debugging
lbessard
parents: 331
diff changeset
   175
    def ResetView(self):
87e5015330ae Adding support for ToolTip on wire when debugging
lbessard
parents: 331
diff changeset
   176
        self.Datas = []
87e5015330ae Adding support for ToolTip on wire when debugging
lbessard
parents: 331
diff changeset
   177
        self.CurrentValue = 0
632
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   178
        self.Ticktime = self.DataProducer.GetTicktime()
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   179
        self.RefreshCanvasRange()
338
87e5015330ae Adding support for ToolTip on wire when debugging
lbessard
parents: 331
diff changeset
   180
        self.RefreshView()
87e5015330ae Adding support for ToolTip on wire when debugging
lbessard
parents: 331
diff changeset
   181
    
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   182
    def RefreshNewData(self):
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   183
        self.RefreshView(False)
374
16a0a6cb1644 Bug on GraphicViewer with latest modifications fixed
greg
parents: 361
diff changeset
   184
        DebugViewer.RefreshNewData(self)
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   185
    
632
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   186
    def RefreshCanvasRange(self):
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   187
        if self.Ticktime == 0 and self.RangeValues != RANGE_VALUES:
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   188
            self.RangeValues = RANGE_VALUES
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   189
            self.RangeValues_dict = dict(RANGE_VALUES)
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   190
            self.CanvasRange.Clear()
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   191
            for text, value in RANGE_VALUES:
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   192
                self.CanvasRange.Append(text)
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   193
            self.CanvasRange.SetStringSelection(RANGE_VALUES[0][0])
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   194
            self.CurrentRange = RANGE_VALUES[0][1]
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   195
        elif self.RangeValues != TIME_RANGE_VALUES:
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   196
            self.RangeValues = TIME_RANGE_VALUES
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   197
            self.RangeValues_dict = dict(TIME_RANGE_VALUES)
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   198
            self.CanvasRange.Clear()
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   199
            for text, value in TIME_RANGE_VALUES:
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   200
                self.CanvasRange.Append(text)
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   201
            self.CanvasRange.SetStringSelection(TIME_RANGE_VALUES[0][0])
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   202
            self.CurrentRange = TIME_RANGE_VALUES[0][1] / self.Ticktime
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   203
        
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   204
    def RefreshView(self, force=True):
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   205
        self.Freeze()
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   206
        if force or self.CurrentValue + self.CurrentRange == len(self.Datas) or self.CurrentValue + len(self.Datas) < self.CurrentRange:
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   207
            var_name = self.InstancePath.split(".")[-1]
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   208
            
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   209
            self.VariableGraphic = plot.PolyLine(self.Datas[self.CurrentValue:self.CurrentValue + self.CurrentRange], 
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   210
                                                 legend=var_name, colour=colours[0])
391
07447ee3538e Adding support for internationalization
laurent
parents: 374
diff changeset
   211
            self.GraphicsObject = plot.PlotGraphics([self.VariableGraphic], _("%s Graphics") % var_name, _("Tick"), _("Values"))
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   212
            datas_length = len(self.Datas)
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   213
            if datas_length > 1:
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   214
                start = self.Datas[self.CurrentValue][0]
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   215
                if self.CurrentValue + self.CurrentRange > datas_length:
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   216
                    end = start + (self.Datas[datas_length - 1][0] - start) * self.CurrentRange / (datas_length - self.CurrentValue - 1)
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   217
                else:
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   218
                    end = self.Datas[self.CurrentValue + self.CurrentRange - 1][0]
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   219
            else:
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   220
                start = 0.
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   221
                end = 25.
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   222
            self.Canvas.Draw(self.GraphicsObject, xAxis=(start, end))
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   223
        self.RefreshScrollBar()
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   224
        self.Thaw()
326
c82807b17128 Bugs with undefined functions fixed
lbessard
parents: 313
diff changeset
   225
    
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   226
    def GetInstancePath(self):
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   227
        return self.InstancePath
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   228
    
326
c82807b17128 Bugs with undefined functions fixed
lbessard
parents: 313
diff changeset
   229
    def IsViewing(self, tagname):
c82807b17128 Bugs with undefined functions fixed
lbessard
parents: 313
diff changeset
   230
        return self.InstancePath == tagname
c82807b17128 Bugs with undefined functions fixed
lbessard
parents: 313
diff changeset
   231
    
504
f88e0ebd8fe4 Forced variable now supported in GraphicViewer
edouard
parents: 431
diff changeset
   232
    def NewValue(self, tick, value, forced=False):
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   233
        self.Datas.append((float(tick), {True:1., False:0.}.get(value, float(value))))
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   234
        if self.CurrentValue + self.CurrentRange == len(self.Datas) - 1:
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   235
            self.CurrentValue += 1
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   236
        self.NewDataAvailable()
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 344
diff changeset
   237
    
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   238
    def RefreshScrollBar(self):
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   239
        self.CanvasPosition.SetScrollbar(self.CurrentValue, self.CurrentRange, len(self.Datas), self.CurrentRange)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   240
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   241
    def OnRangeChanged(self, event):
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   242
        old_range = self.CurrentRange
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   243
        try:
632
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   244
            if self.Ticktime == 0:
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   245
                self.CurrentRange = self.RangeValues_dict[self.CanvasRange.GetValue()]
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   246
            else:
3ea55a5db68e Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
laurent
parents: 586
diff changeset
   247
                self.CurrentRange = self.RangeValues_dict[self.CanvasRange.GetValue()] / self.Ticktime
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   248
        except ValueError, e:
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   249
            self.CanvasRange.SetValue(str(self.CurrentRange))
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   250
        self.CurrentValue = max(0, min(self.CurrentValue + old_range - self.CurrentRange, 
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   251
                                       len(self.Datas) - self.CurrentRange))
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   252
        self.RefreshView()
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   253
        event.Skip()
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   254
    
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   255
    def OnPositionChanging(self, event):
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   256
        self.CurrentValue = event.GetPosition()
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   257
        self.RefreshView()
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   258
        event.Skip()
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   259
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   260
    def OnResetButton(self, event):
338
87e5015330ae Adding support for ToolTip on wire when debugging
lbessard
parents: 331
diff changeset
   261
        self.ResetView()
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   262
        event.Skip()
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   263
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   264
    def OnCurrentButton(self, event):
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   265
        self.CurrentValue = max(0, len(self.Datas) - self.CurrentRange)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   266
        self.RefreshView()
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   267
        event.Skip()
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   268