controls/DebugVariablePanel.py
author Laurent Bessard
Thu, 24 Jan 2013 00:45:54 +0100
changeset 909 852af7c6f0ef
parent 907 591cb3d96980
child 912 bf855ccf3705
permissions -rw-r--r--
Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     1
#!/usr/bin/env python
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     3
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     5
#based on the plcopen standard. 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     6
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     7
#Copyright (C) 2012: Edouard TISSERANT and Laurent BESSARD
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     8
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     9
#See COPYING file for copyrights details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    10
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    15
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    19
#General Public License for more details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    20
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    24
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
    25
from types import TupleType, FloatType
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
    26
from time import time as gettime
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
    27
import math
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
    28
import numpy
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    29
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    30
import wx
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    31
import wx.lib.buttons
888
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
    32
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
    33
try:
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
    34
    import matplotlib
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
    35
    matplotlib.use('WX')
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
    36
    import matplotlib.pyplot
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
    37
    from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
    38
    #from matplotlib.backends.backend_wx import FigureCanvasWx as FigureCanvas
888
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
    39
    from mpl_toolkits.mplot3d import Axes3D
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
    40
    USE_MPL = True
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
    41
except:
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
    42
    USE_MPL = False
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
    43
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
    44
from graphics import DebugDataConsumer, DebugViewer, REFRESH_PERIOD
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    45
from controls import CustomGrid, CustomTable
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    46
from dialogs.ForceVariableDialog import ForceVariableDialog
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    47
from util.BitmapLibrary import GetBitmap
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    48
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
    49
SECOND = 1000000000
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
    50
MINUTE = 60 * SECOND
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
    51
HOUR = 60 * MINUTE
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
    52
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
    53
ZOOM_VALUES = map(lambda x:("x %.1f" % x, x), [math.sqrt(2) ** i for i in xrange(8)])
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
    54
RANGE_VALUES = map(lambda x: (str(x), x), [25 * 2 ** i for i in xrange(6)])
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
    55
TIME_RANGE_VALUES = [("%ds" % i, i * SECOND) for i in (1, 2, 5, 10, 20, 30)] + \
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
    56
                    [("%dm" % i, i * MINUTE) for i in (1, 2, 5, 10, 20, 30)] + \
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
    57
                    [("%dh" % i, i * HOUR) for i in (1, 2, 3, 6, 12, 24)]
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
    58
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
    59
GRAPH_PARALLEL, GRAPH_ORTHOGONAL = range(2)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
    60
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    61
def AppendMenu(parent, help, id, kind, text):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    62
    parent.Append(help=help, id=id, kind=kind, text=text)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    63
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    64
def GetDebugVariablesTableColnames():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    65
    _ = lambda x : x
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
    66
    return [_("Variable"), _("Value")]
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
    67
    
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    68
class VariableTableItem(DebugDataConsumer):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    69
    
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
    70
    def __init__(self, parent, variable):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    71
        DebugDataConsumer.__init__(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    72
        self.Parent = parent
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    73
        self.Variable = variable
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
    74
        self.RefreshVariableType()
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
    75
        self.Value = ""
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
    76
        
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    77
    def __del__(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    78
        self.Parent = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    79
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    80
    def SetVariable(self, variable):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    81
        if self.Parent and self.Variable != variable:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    82
            self.Variable = variable
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
    83
            self.RefreshVariableType()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    84
            self.Parent.RefreshGrid()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    85
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    86
    def GetVariable(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    87
        return self.Variable
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    88
    
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
    89
    def RefreshVariableType(self):
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
    90
        self.VariableType = self.Parent.GetDataType(self.Variable)
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
    91
        self.ResetData()
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
    92
    
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
    93
    def GetVariableType(self):
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
    94
        return self.VariableType
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
    95
    
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
    96
    def GetData(self, start_tick=None, end_tick=None):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
    97
        if self.IsNumVariable():
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
    98
            if len(self.Data) == 0:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
    99
                return self.Data
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   100
            
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   101
            start_idx = end_idx = None
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   102
            if start_tick is not None:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   103
                start_idx = self.GetNearestData(start_tick, -1)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   104
            if end_tick is not None:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   105
                end_idx = self.GetNearestData(end_tick, 1)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   106
            if start_idx is None:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   107
                start_idx = 0
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   108
            if end_idx is not None:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   109
                return self.Data[start_idx:end_idx + 1]
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   110
            else:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   111
                return self.Data[start_idx:]
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   112
            
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   113
        return None
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   114
    
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   115
    def GetRange(self):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   116
        return self.MinValue, self.MaxValue
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   117
    
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   118
    def ResetData(self):
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   119
        if self.IsNumVariable():
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   120
            self.Data = numpy.array([]).reshape(0, 2)
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   121
            self.MinValue = None
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   122
            self.MaxValue = None
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   123
        else:
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   124
            self.Data = None
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   125
    
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   126
    def IsNumVariable(self):
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   127
        return self.Parent.IsNumType(self.VariableType)
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   128
    
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   129
    def NewValue(self, tick, value, forced=False):
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   130
        if self.IsNumVariable():
895
f5a28011d551 Fixed boolean value displayed in debug variable panel
Laurent Bessard
parents: 892
diff changeset
   131
            num_value = {True:1., False:0.}.get(value, float(value))
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   132
            if self.MinValue is None:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   133
                self.MinValue = num_value
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   134
            else:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   135
                self.MinValue = min(self.MinValue, num_value)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   136
            if self.MaxValue is None:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   137
                self.MaxValue = num_value
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   138
            else:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   139
                self.MaxValue = max(self.MaxValue, num_value)
895
f5a28011d551 Fixed boolean value displayed in debug variable panel
Laurent Bessard
parents: 892
diff changeset
   140
            self.Data = numpy.append(self.Data, [[float(tick), num_value]], axis=0)
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   141
            self.Parent.HasNewData = True
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   142
        DebugDataConsumer.NewValue(self, tick, value, forced)
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   143
    
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   144
    def SetForced(self, forced):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   145
        if self.Forced != forced:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   146
            self.Forced = forced
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   147
            self.Parent.HasNewData = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   148
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   149
    def SetValue(self, value):
892
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
   150
        if (self.VariableType == "STRING" and value.startswith("'") and value.endswith("'") or
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
   151
            self.VariableType == "WSTRING" and value.startswith('"') and value.endswith('"')):
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
   152
            value = value[1:-1]
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   153
        if self.Value != value:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   154
            self.Value = value
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   155
            self.Parent.HasNewData = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   156
            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   157
    def GetValue(self):
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   158
        if self.VariableType == "STRING":
878
37256069baed Fix display of string variables value in debug
Laurent Bessard
parents: 814
diff changeset
   159
            return "'%s'" % self.Value
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   160
        elif self.VariableType == "WSTRING":
878
37256069baed Fix display of string variables value in debug
Laurent Bessard
parents: 814
diff changeset
   161
            return "\"%s\"" % self.Value
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   162
        elif isinstance(self.Value, FloatType):
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   163
            return "%.6g" % self.Value
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   164
        return self.Value
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   165
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   166
    def GetNearestData(self, tick, adjust):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   167
        if self.IsNumVariable():
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   168
            ticks = self.Data[:, 0]
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   169
            new_cursor = numpy.argmin(abs(ticks - tick))
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   170
            if adjust == -1 and ticks[new_cursor] > tick and new_cursor > 0:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   171
                new_cursor -= 1
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   172
            elif adjust == 1 and ticks[new_cursor] < tick and new_cursor < len(ticks):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   173
                new_cursor += 1
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   174
            return new_cursor
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   175
        return None
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   176
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   177
class DebugVariableTable(CustomTable):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   178
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   179
    def GetValue(self, row, col):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   180
        if row < self.GetNumberRows():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   181
            return self.GetValueByName(row, self.GetColLabelValue(col, False))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   182
        return ""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   183
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   184
    def SetValue(self, row, col, value):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   185
        if col < len(self.colnames):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   186
            self.SetValueByName(row, self.GetColLabelValue(col, False), value)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   187
            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   188
    def GetValueByName(self, row, colname):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   189
        if row < self.GetNumberRows():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   190
            if colname == "Variable":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   191
                return self.data[row].GetVariable()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   192
            elif colname == "Value":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   193
                return self.data[row].GetValue()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   194
        return ""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   195
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   196
    def SetValueByName(self, row, colname, value):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   197
        if row < self.GetNumberRows():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   198
            if colname == "Variable":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   199
                self.data[row].SetVariable(value)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   200
            elif colname == "Value":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   201
                self.data[row].SetValue(value)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   202
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   203
    def IsForced(self, row):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   204
        if row < self.GetNumberRows():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   205
            return self.data[row].IsForced()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   206
        return False
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   207
    
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   208
    def IsNumVariable(self, row):
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   209
        if row < self.GetNumberRows():
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   210
            return self.data[row].IsNumVariable()
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   211
        return False
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   212
    
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   213
    def _updateColAttrs(self, grid):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   214
        """
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   215
        wx.grid.Grid -> update the column attributes to add the
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   216
        appropriate renderer given the column name.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   217
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   218
        Otherwise default to the default renderer.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   219
        """
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   220
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   221
        for row in range(self.GetNumberRows()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   222
            for col in range(self.GetNumberCols()):
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   223
                colname = self.GetColLabelValue(col, False)
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   224
                if colname == "Value":
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   225
                    if self.IsForced(row):
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   226
                        grid.SetCellTextColour(row, col, wx.BLUE)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   227
                    else:
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   228
                        grid.SetCellTextColour(row, col, wx.BLACK)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   229
                grid.SetReadOnly(row, col, True)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   230
            self.ResizeRow(grid, row)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   231
                
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   232
    def AppendItem(self, data):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   233
        self.data.append(data)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   234
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   235
    def InsertItem(self, idx, data):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   236
        self.data.insert(idx, data)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   237
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   238
    def RemoveItem(self, idx):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   239
        self.data.pop(idx)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   240
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   241
    def MoveItem(self, idx, new_idx):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   242
        self.data.insert(new_idx, self.data.pop(idx))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   243
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   244
    def GetItem(self, idx):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   245
        return self.data[idx]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   246
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   247
class DebugVariableDropTarget(wx.TextDropTarget):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   248
    
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   249
    def __init__(self, parent, control):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   250
        wx.TextDropTarget.__init__(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   251
        self.ParentWindow = parent
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   252
        self.ParentControl = control
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   253
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   254
    def OnDropText(self, x, y, data):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   255
        message = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   256
        try:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   257
            values = eval(data)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   258
        except:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   259
            message = _("Invalid value \"%s\" for debug variable")%data
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   260
            values = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   261
        if not isinstance(values, TupleType):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   262
            message = _("Invalid value \"%s\" for debug variable")%data
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   263
            values = None
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   264
        
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   265
        if message is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   266
            wx.CallAfter(self.ShowMessage, message)
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   267
        elif values is not None and values[1] == "debug":
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   268
            if self.ParentControl == self.ParentWindow.VariablesGrid:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   269
                x, y = self.ParentWindow.VariablesGrid.CalcUnscrolledPosition(x, y)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   270
                row = self.ParentWindow.VariablesGrid.YToRow(y - self.ParentWindow.VariablesGrid.GetColLabelSize())
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   271
                if row == wx.NOT_FOUND:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   272
                    row = self.ParentWindow.Table.GetNumberRows()
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   273
                self.ParentWindow.InsertValue(values[0], row, force=True)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   274
            else:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   275
                x, y = self.ParentWindow.GraphicsCanvasWindow.CalcUnscrolledPosition(x, y)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   276
                width, height = self.ParentWindow.GraphicsCanvas.GetSize()
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   277
                target = None
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   278
                merge_type = GRAPH_PARALLEL
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   279
                for infos in self.ParentWindow.GraphicsAxes:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   280
                    ax, ay, aw, ah = infos["axes"].get_position().bounds
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   281
                    rect = wx.Rect(ax * width, height - (ay + ah) * height,
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   282
                                   aw * width, ah * height)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   283
                    if rect.InsideXY(x, y):
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   284
                        target = infos
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   285
                        merge_rect = wx.Rect(ax * width, height - (ay + ah) * height,
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   286
                                             aw * width / 2., ah * height)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   287
                        if merge_rect.InsideXY(x, y):
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   288
                            merge_type = GRAPH_ORTHOGONAL
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   289
                        break
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   290
                self.ParentWindow.MergeGraphs(values[0], target, merge_type, force=True)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   291
            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   292
    def ShowMessage(self, message):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   293
        dialog = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   294
        dialog.ShowModal()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   295
        dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   296
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   297
SCROLLBAR_UNIT = 10
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   298
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   299
def NextTick(variables):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   300
    next_tick = None
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   301
    for var_name, data in variables:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   302
        if len(data) > 0:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   303
            if next_tick is None:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   304
                next_tick = data[0][0]
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   305
            else:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   306
                next_tick = min(next_tick, data[0][0])
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   307
    return next_tick
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   308
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   309
def OrthogonalData(item, start_tick, end_tick):
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   310
    data = item.GetData(start_tick, end_tick)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   311
    min_value, max_value = item.GetRange()
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   312
    if min_value is not None and max_value is not None:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   313
        center = (min_value + max_value) / 2.
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   314
        range = max(1.0, max_value - min_value)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   315
    else:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   316
        center = 0.5
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   317
        range = 1.0
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   318
    return data, center - range * 0.55, center + range * 0.55 
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   319
    
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   320
class DebugVariablePanel(wx.SplitterWindow, DebugViewer):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   321
    
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   322
    def __init__(self, parent, producer, window):
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   323
        wx.SplitterWindow.__init__(self, parent, style=wx.SP_3D)
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   324
        
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   325
        self.ParentWindow = window
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   326
        
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   327
        DebugViewer.__init__(self, producer, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   328
        
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   329
        self.SetSashGravity(0.5)
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   330
        self.SetNeedUpdating(True)
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   331
        self.SetMinimumPaneSize(1)
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   332
        
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   333
        self.MainPanel = wx.Panel(self, style=wx.TAB_TRAVERSAL)
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   334
        
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   335
        main_panel_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   336
        main_panel_sizer.AddGrowableCol(0)
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   337
        main_panel_sizer.AddGrowableRow(1)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   338
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   339
        button_sizer = wx.BoxSizer(wx.HORIZONTAL)
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   340
        main_panel_sizer.AddSizer(button_sizer, border=5, 
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   341
              flag=wx.ALIGN_RIGHT|wx.ALL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   342
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   343
        for name, bitmap, help in [
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   344
                ("DeleteButton", "remove_element", _("Remove debug variable")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   345
                ("UpButton", "up", _("Move debug variable up")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   346
                ("DownButton", "down", _("Move debug variable down"))]:
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   347
            button = wx.lib.buttons.GenBitmapButton(self.MainPanel, bitmap=GetBitmap(bitmap), 
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   348
                  size=wx.Size(28, 28), style=wx.NO_BORDER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   349
            button.SetToolTipString(help)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   350
            setattr(self, name, button)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   351
            button_sizer.AddWindow(button, border=5, flag=wx.LEFT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   352
        
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   353
        self.VariablesGrid = CustomGrid(self.MainPanel, size=wx.Size(-1, 150), style=wx.VSCROLL)
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   354
        self.VariablesGrid.SetDropTarget(DebugVariableDropTarget(self, self.VariablesGrid))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   355
        self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   356
              self.OnVariablesGridCellRightClick)
892
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
   357
        self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, 
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
   358
              self.OnVariablesGridCellLeftClick)
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   359
        main_panel_sizer.AddWindow(self.VariablesGrid, flag=wx.GROW)
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   360
        
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   361
        self.MainPanel.SetSizer(main_panel_sizer)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   362
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   363
        self.HasNewData = False
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   364
        self.Ticks = numpy.array([])
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   365
        self.RangeValues = None
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   366
        self.StartTick = 0
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   367
        self.Fixed = False
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   368
        self.Force = False
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   369
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   370
        self.Table = DebugVariableTable(self, [], GetDebugVariablesTableColnames())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   371
        self.VariablesGrid.SetTable(self.Table)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   372
        self.VariablesGrid.SetButtons({"Delete": self.DeleteButton,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   373
                                       "Up": self.UpButton,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   374
                                       "Down": self.DownButton})
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   375
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   376
        def _AddVariable(new_row):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   377
            return self.VariablesGrid.GetGridCursorRow()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   378
        setattr(self.VariablesGrid, "_AddRow", _AddVariable)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   379
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   380
        def _DeleteVariable(row):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   381
            item = self.Table.GetItem(row)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   382
            self.RemoveDataConsumer(item)
907
591cb3d96980 Fixed performance issue with matplotlib in DebugVariablePanel and hide 3D graphics when not needed
Laurent Bessard
parents: 905
diff changeset
   383
            for infos in self.GraphicsAxes:
591cb3d96980 Fixed performance issue with matplotlib in DebugVariablePanel and hide 3D graphics when not needed
Laurent Bessard
parents: 905
diff changeset
   384
                if item in infos["items"]:
591cb3d96980 Fixed performance issue with matplotlib in DebugVariablePanel and hide 3D graphics when not needed
Laurent Bessard
parents: 905
diff changeset
   385
                    if len(infos["items"]) == 1:
591cb3d96980 Fixed performance issue with matplotlib in DebugVariablePanel and hide 3D graphics when not needed
Laurent Bessard
parents: 905
diff changeset
   386
                        self.GraphicsAxes.remove(infos)
591cb3d96980 Fixed performance issue with matplotlib in DebugVariablePanel and hide 3D graphics when not needed
Laurent Bessard
parents: 905
diff changeset
   387
                    else:
591cb3d96980 Fixed performance issue with matplotlib in DebugVariablePanel and hide 3D graphics when not needed
Laurent Bessard
parents: 905
diff changeset
   388
                        infos["items"].remove(item)
591cb3d96980 Fixed performance issue with matplotlib in DebugVariablePanel and hide 3D graphics when not needed
Laurent Bessard
parents: 905
diff changeset
   389
                    break
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   390
            self.Table.RemoveItem(row)
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   391
            self.ResetGraphics()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   392
            self.RefreshGrid()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   393
        setattr(self.VariablesGrid, "_DeleteRow", _DeleteVariable)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   394
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   395
        def _MoveVariable(row, move):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   396
            new_row = max(0, min(row + move, self.Table.GetNumberRows() - 1))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   397
            if new_row != row:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   398
                self.Table.MoveItem(row, new_row)
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   399
                self.ResetGraphics()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   400
                self.RefreshGrid()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   401
            return new_row
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   402
        setattr(self.VariablesGrid, "_MoveRow", _MoveVariable)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   403
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   404
        self.VariablesGrid.SetRowLabelSize(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   405
        
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   406
        self.GridColSizes = [200, 100]
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   407
        
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   408
        for col in range(self.Table.GetNumberCols()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   409
            attr = wx.grid.GridCellAttr()
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   410
            attr.SetAlignment(wx.ALIGN_RIGHT, wx.ALIGN_CENTER)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   411
            self.VariablesGrid.SetColAttr(col, attr)
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   412
            self.VariablesGrid.SetColSize(col, self.GridColSizes[col])
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   413
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   414
        self.Table.ResetView(self.VariablesGrid)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   415
        self.VariablesGrid.RefreshButtons()
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   416
        
888
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   417
        if USE_MPL:
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   418
            self.GraphicsPanel = wx.Panel(self, style=wx.TAB_TRAVERSAL)
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   419
            
907
591cb3d96980 Fixed performance issue with matplotlib in DebugVariablePanel and hide 3D graphics when not needed
Laurent Bessard
parents: 905
diff changeset
   420
            self.GraphicsPanelSizer = wx.BoxSizer(wx.VERTICAL)
888
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   421
            
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   422
            graphics_button_sizer = wx.BoxSizer(wx.HORIZONTAL)
907
591cb3d96980 Fixed performance issue with matplotlib in DebugVariablePanel and hide 3D graphics when not needed
Laurent Bessard
parents: 905
diff changeset
   423
            self.GraphicsPanelSizer.AddSizer(graphics_button_sizer, border=5, flag=wx.GROW|wx.ALL)
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   424
            
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   425
            range_label = wx.StaticText(self.GraphicsPanel, label=_('Range:'))
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   426
            graphics_button_sizer.AddWindow(range_label, flag=wx.ALIGN_CENTER_VERTICAL)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   427
            
905
eaa1d3a4b52b Fix DebugVariablePanel time range position
Laurent Bessard
parents: 903
diff changeset
   428
            self.CanvasRange = wx.ComboBox(self.GraphicsPanel, style=wx.CB_READONLY)
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   429
            self.Bind(wx.EVT_COMBOBOX, self.OnRangeChanged, self.CanvasRange)
905
eaa1d3a4b52b Fix DebugVariablePanel time range position
Laurent Bessard
parents: 903
diff changeset
   430
            graphics_button_sizer.AddWindow(self.CanvasRange, 1, 
eaa1d3a4b52b Fix DebugVariablePanel time range position
Laurent Bessard
parents: 903
diff changeset
   431
                  border=5, flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL)
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   432
            
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   433
            for name, bitmap, help in [
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   434
                ("ResetButton", "reset", _("Clear the graph values")),
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   435
                ("CurrentButton", "current", _("Go to current value")),
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   436
                ("ExportGraphButton", "export_graph", _("Export graph values to clipboard"))]:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   437
                button = wx.lib.buttons.GenBitmapButton(self.GraphicsPanel, 
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   438
                      bitmap=GetBitmap(bitmap), 
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   439
                      size=wx.Size(28, 28), style=wx.NO_BORDER)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   440
                button.SetToolTipString(help)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   441
                setattr(self, name, button)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   442
                self.Bind(wx.EVT_BUTTON, getattr(self, "On" + name), button)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   443
                graphics_button_sizer.AddWindow(button, border=5, flag=wx.LEFT)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   444
            
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   445
            self.CanvasPosition = wx.ScrollBar(self.GraphicsPanel, 
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   446
                  size=wx.Size(0, 16), style=wx.SB_HORIZONTAL)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   447
            self.CanvasPosition.Bind(wx.EVT_SCROLL_THUMBTRACK, 
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   448
                  self.OnPositionChanging, self.CanvasPosition)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   449
            self.CanvasPosition.Bind(wx.EVT_SCROLL_LINEUP, 
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   450
                  self.OnPositionChanging, self.CanvasPosition)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   451
            self.CanvasPosition.Bind(wx.EVT_SCROLL_LINEDOWN, 
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   452
                  self.OnPositionChanging, self.CanvasPosition)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   453
            self.CanvasPosition.Bind(wx.EVT_SCROLL_PAGEUP, 
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   454
                  self.OnPositionChanging, self.CanvasPosition)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   455
            self.CanvasPosition.Bind(wx.EVT_SCROLL_PAGEDOWN, 
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   456
                  self.OnPositionChanging, self.CanvasPosition)
907
591cb3d96980 Fixed performance issue with matplotlib in DebugVariablePanel and hide 3D graphics when not needed
Laurent Bessard
parents: 905
diff changeset
   457
            self.GraphicsPanelSizer.AddWindow(self.CanvasPosition, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM)
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   458
            
888
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   459
            self.GraphicsCanvasWindow = wx.ScrolledWindow(self.GraphicsPanel, style=wx.HSCROLL|wx.VSCROLL)
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   460
            self.GraphicsCanvasWindow.Bind(wx.EVT_SIZE, self.OnGraphicsCanvasWindowResize)
907
591cb3d96980 Fixed performance issue with matplotlib in DebugVariablePanel and hide 3D graphics when not needed
Laurent Bessard
parents: 905
diff changeset
   461
            self.GraphicsPanelSizer.AddWindow(self.GraphicsCanvasWindow, 1, flag=wx.GROW)
888
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   462
            
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   463
            graphics_canvas_window_sizer = wx.BoxSizer(wx.VERTICAL)
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   464
            
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   465
            self.GraphicsFigure = matplotlib.figure.Figure()
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   466
            self.GraphicsAxes = []
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   467
            
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   468
            self.GraphicsCanvas = FigureCanvas(self.GraphicsCanvasWindow, -1, self.GraphicsFigure)
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   469
            self.GraphicsCanvas.mpl_connect("button_press_event", self.OnGraphicsCanvasClick)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   470
            self.GraphicsCanvas.SetDropTarget(DebugVariableDropTarget(self, self.GraphicsCanvas))
888
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   471
            graphics_canvas_window_sizer.AddWindow(self.GraphicsCanvas, 1, flag=wx.GROW)
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   472
            
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   473
            self.GraphicsCanvasWindow.SetSizer(graphics_canvas_window_sizer)
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   474
            
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   475
            self.Graphics3DFigure = matplotlib.figure.Figure()
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   476
            self.Graphics3DFigure.subplotpars.update(left=0.0, right=1.0, bottom=0.0, top=1.0)
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   477
            
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   478
            self.LastMotionTime = gettime()
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   479
            self.Graphics3DAxes = self.Graphics3DFigure.gca(projection='3d')
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   480
            self.Graphics3DAxes.set_color_cycle(['b'])
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   481
            setattr(self.Graphics3DAxes, "_on_move", self.OnGraphics3DMotion)
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   482
            
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   483
            self.Graphics3DCanvas = FigureCanvas(self.GraphicsPanel, -1, self.Graphics3DFigure)
892
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
   484
            self.Graphics3DCanvas.SetMinSize(wx.Size(1, 1))
907
591cb3d96980 Fixed performance issue with matplotlib in DebugVariablePanel and hide 3D graphics when not needed
Laurent Bessard
parents: 905
diff changeset
   485
            self.GraphicsPanelSizer.AddWindow(self.Graphics3DCanvas, 1, flag=wx.GROW)
888
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   486
            
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   487
            self.Graphics3DAxes.mouse_init()
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   488
            
907
591cb3d96980 Fixed performance issue with matplotlib in DebugVariablePanel and hide 3D graphics when not needed
Laurent Bessard
parents: 905
diff changeset
   489
            self.GraphicsPanel.SetSizer(self.GraphicsPanelSizer)
888
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   490
            
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   491
            self.SplitHorizontally(self.MainPanel, self.GraphicsPanel, -200)
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   492
        
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   493
        else:
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   494
            self.Initialize(self.MainPanel)
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   495
        
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   496
        self.ResetGraphics()
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   497
        self.RefreshCanvasRange()
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   498
        self.RefreshScrollBar()
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   499
        
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   500
    def SetDataProducer(self, producer):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   501
        DebugViewer.SetDataProducer(self, producer)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   502
        
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   503
        if self.DataProducer is not None:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   504
            self.Ticktime = self.DataProducer.GetTicktime()
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   505
            self.RefreshCanvasRange()
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   506
        else:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   507
            self.Ticktime = 0
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   508
    
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   509
    def RefreshNewData(self, *args, **kwargs):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   510
        if self.HasNewData or self.Force:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   511
            self.HasNewData = False
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   512
            self.RefreshGrid(only_values=True)
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   513
        DebugViewer.RefreshNewData(self, *args, **kwargs)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   514
    
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   515
    def NewDataAvailable(self, tick, *args, **kwargs):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   516
        if tick is not None:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   517
            self.Ticks = numpy.append(self.Ticks, [tick])
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   518
            if not self.Fixed or tick < self.StartTick + self.CurrentRange:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   519
                self.StartTick = max(self.StartTick, tick - self.CurrentRange)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   520
        DebugViewer.NewDataAvailable(self, tick, *args, **kwargs)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   521
    
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   522
    def RefreshGrid(self, only_values=False):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   523
        self.Freeze()
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   524
        if only_values:
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   525
            for col in xrange(self.Table.GetNumberCols()):
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   526
                if self.Table.GetColLabelValue(col, False) == "Value":
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   527
                    for row in xrange(self.Table.GetNumberRows()):
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   528
                        self.VariablesGrid.SetCellValue(row, col, str(self.Table.GetValueByName(row, "Value")))
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   529
        else:
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   530
            self.Table.ResetView(self.VariablesGrid)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   531
        self.VariablesGrid.RefreshButtons()
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   532
        
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   533
        self.RefreshScrollBar()
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   534
        
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   535
        self.Thaw()
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   536
        
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   537
        if USE_MPL:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   538
        
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   539
            if not self.Fixed or self.Force:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   540
                self.Force = False
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   541
                
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   542
                # Refresh graphics
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   543
                start_tick, end_tick = self.StartTick, self.StartTick + self.CurrentRange
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   544
                for infos in self.GraphicsAxes:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   545
                    
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   546
                    if infos["type"] == GRAPH_PARALLEL:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   547
                        min_value = max_value = None
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   548
                        
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   549
                        for idx, item in enumerate(infos["items"]):
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   550
                            data = item.GetData(start_tick, end_tick)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   551
                            if data is not None:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   552
                                item_min_value, item_max_value = item.GetRange()
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   553
                                if min_value is None:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   554
                                    min_value = item_min_value
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   555
                                elif item_min_value is not None:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   556
                                    min_value = min(min_value, item_min_value)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   557
                                if max_value is None:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   558
                                    max_value = item_max_value
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   559
                                elif item_max_value is not None:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   560
                                    max_value = max(max_value, item_max_value)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   561
                                
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   562
                                if len(infos["plots"]) <= idx:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   563
                                    infos["plots"].append(
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   564
                                        infos["axes"].plot(data[:, 0], data[:, 1])[0])
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   565
                                else:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   566
                                    infos["plots"][idx].set_data(data[:, 0], data[:, 1])
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   567
                        
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   568
                        if min_value is not None and max_value is not None:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   569
                            y_center = (min_value + max_value) / 2.
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   570
                            y_range = max(1.0, max_value - min_value)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   571
                        else:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   572
                            y_center = 0.5
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   573
                            y_range = 1.0
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   574
                        x_min, x_max = start_tick, end_tick
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   575
                        y_min, y_max = y_center - y_range * 0.55, y_center + y_range * 0.55
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   576
                    
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   577
                    else:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   578
                        min_start_tick = reduce(max, [item.GetData()[0, 0] 
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   579
                                                      for item in infos["items"]
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   580
                                                      if len(item.GetData()) > 0], 0)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   581
                        start_tick = max(self.StartTick, min_start_tick)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   582
                        end_tick = max(self.StartTick + self.CurrentRange, min_start_tick)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   583
                        x_data, x_min, x_max = OrthogonalData(infos["items"][0], start_tick, end_tick)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   584
                        y_data, y_min, y_max = OrthogonalData(infos["items"][1], start_tick, end_tick)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   585
                        length = 0
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   586
                        if x_data is not None and y_data is not None:  
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   587
                            length = min(len(x_data), len(y_data))
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   588
                        if len(infos["items"]) < 3:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   589
                            if x_data is not None and y_data is not None:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   590
                                if len(infos["plots"]) == 0:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   591
                                    infos["plots"].append(
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   592
                                        infos["axes"].plot(x_data[:, 1][:length], 
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   593
                                                           y_data[:, 1][:length])[0])
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   594
                                else:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   595
                                    infos["plots"][0].set_data(
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   596
                                        x_data[:, 1][:length], 
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   597
                                        y_data[:, 1][:length])
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   598
                        else:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   599
                            while len(infos["axes"].lines) > 0:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   600
                                infos["axes"].lines.pop()
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   601
                            z_data, z_min, z_max = OrthogonalData(infos["items"][2], start_tick, end_tick)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   602
                            if x_data is not None and y_data is not None and z_data is not None:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   603
                                length = min(length, len(z_data))
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   604
                                infos["axes"].plot(x_data[:, 1][:length],
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   605
                                                   y_data[:, 1][:length],
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   606
                                                   zs = z_data[:, 1][:length])
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   607
                            infos["axes"].set_zlim(z_min, z_max)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   608
                    
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   609
                    infos["axes"].set_xlim(x_min, x_max)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   610
                    infos["axes"].set_ylim(y_min, y_max)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   611
                
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   612
            plot2d = plot3d = 0
907
591cb3d96980 Fixed performance issue with matplotlib in DebugVariablePanel and hide 3D graphics when not needed
Laurent Bessard
parents: 905
diff changeset
   613
            for infos in self.GraphicsAxes:
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   614
                labels = ["%s: %s" % (item.GetVariable(), item.GetValue())
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   615
                          for item in infos["items"]]
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   616
                if infos["type"] == GRAPH_PARALLEL:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   617
                    infos["axes"].legend(infos["plots"], labels, 
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   618
                        loc="upper left", frameon=False,
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   619
                        prop={'size':'small'})
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   620
                    plot2d += 1
907
591cb3d96980 Fixed performance issue with matplotlib in DebugVariablePanel and hide 3D graphics when not needed
Laurent Bessard
parents: 905
diff changeset
   621
                else:
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   622
                    infos["axes"].set_xlabel(labels[0], fontdict={'size':'small'})
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   623
                    infos["axes"].set_ylabel(labels[1], fontdict={'size':'small'})
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   624
                    if len(labels) > 2:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   625
                        infos["axes"].set_zlabel(labels[2], fontdict={'size':'small'})
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   626
                        plot3d += 1
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   627
                    else:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   628
                        plot2d += 1
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   629
            
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   630
            if plot2d > 0:
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   631
                self.GraphicsCanvas.draw()
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   632
            if plot3d > 0:
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   633
                self.Graphics3DCanvas.draw()
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   634
            
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   635
    def UnregisterObsoleteData(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   636
        items = [(idx, item) for idx, item in enumerate(self.Table.GetData())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   637
        items.reverse()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   638
        for idx, item in items:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   639
            iec_path = item.GetVariable().upper()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   640
            if self.GetDataType(iec_path) is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   641
                self.RemoveDataConsumer(item)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   642
                self.Table.RemoveItem(idx)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   643
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   644
                self.AddDataConsumer(iec_path, item)
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   645
                item.RefreshVariableType()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   646
        self.Freeze()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   647
        self.Table.ResetView(self.VariablesGrid)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   648
        self.VariablesGrid.RefreshButtons()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   649
        self.Thaw()
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   650
        if self.DataProducer is not None:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   651
            self.Ticktime = self.DataProducer.GetTicktime()
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   652
            self.RefreshCanvasRange()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   653
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   654
    def ResetGrid(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   655
        self.DeleteDataConsumers()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   656
        self.Table.Empty()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   657
        self.Freeze()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   658
        self.Table.ResetView(self.VariablesGrid)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   659
        self.VariablesGrid.RefreshButtons()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   660
        self.Thaw()
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   661
        self.ResetGraphics()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   662
    
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   663
    def RefreshCanvasRange(self):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   664
        if self.Ticktime == 0 and self.RangeValues != RANGE_VALUES:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   665
            self.RangeValues = RANGE_VALUES
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   666
            self.CanvasRange.Clear()
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   667
            for text, value in RANGE_VALUES:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   668
                self.CanvasRange.Append(text)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   669
            self.CanvasRange.SetStringSelection(RANGE_VALUES[0][0])
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   670
            self.CurrentRange = RANGE_VALUES[0][1]
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   671
            self.RefreshGrid(True)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   672
        elif self.Ticktime != 0 and self.RangeValues != TIME_RANGE_VALUES:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   673
            self.RangeValues = TIME_RANGE_VALUES
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   674
            self.CanvasRange.Clear()
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   675
            for text, value in TIME_RANGE_VALUES:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   676
                self.CanvasRange.Append(text)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   677
            self.CanvasRange.SetStringSelection(TIME_RANGE_VALUES[0][0])
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   678
            self.CurrentRange = TIME_RANGE_VALUES[0][1] / self.Ticktime
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   679
            self.RefreshGrid(True)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   680
    
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   681
    def RefreshScrollBar(self):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   682
        if len(self.Ticks) > 0:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   683
            pos = int(self.StartTick - self.Ticks[0])
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   684
            range = int(self.Ticks[-1] - self.Ticks[0])
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   685
        else:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   686
            pos = 0
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   687
            range = 0
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   688
        self.CanvasPosition.SetScrollbar(pos, self.CurrentRange, range, self.CurrentRange)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   689
    
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   690
    def GetForceVariableMenuFunction(self, iec_path, item):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   691
        iec_type = self.GetDataType(iec_path)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   692
        def ForceVariableFunction(event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   693
            if iec_type is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   694
                dialog = ForceVariableDialog(self, iec_type, str(item.GetValue()))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   695
                if dialog.ShowModal() == wx.ID_OK:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   696
                    self.ForceDataValue(iec_path, dialog.GetValue())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   697
        return ForceVariableFunction
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   698
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   699
    def GetReleaseVariableMenuFunction(self, iec_path):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   700
        def ReleaseVariableFunction(event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   701
            self.ReleaseDataValue(iec_path)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   702
        return ReleaseVariableFunction
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   703
    
892
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
   704
    def OnVariablesGridCellLeftClick(self, event):
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
   705
        if event.GetCol() == 0:
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
   706
            row = event.GetRow()
898
6b2958f04f30 Adding drag'n drop of debug variable from DebugVariable grid and PouInstance variable list
Laurent Bessard
parents: 895
diff changeset
   707
            data = wx.TextDataObject(str((self.Table.GetValueByName(row, "Variable"), "debug")))
892
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
   708
            dragSource = wx.DropSource(self.VariablesGrid)
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
   709
            dragSource.SetData(data)
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
   710
            dragSource.DoDragDrop()
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
   711
        event.Skip()
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
   712
    
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   713
    def OnVariablesGridCellRightClick(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   714
        row, col = event.GetRow(), event.GetCol()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   715
        if self.Table.GetColLabelValue(col, False) == "Value":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   716
            iec_path = self.Table.GetValueByName(row, "Variable").upper()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   717
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   718
            menu = wx.Menu(title='')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   719
            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   720
            new_id = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   721
            AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Force value"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   722
            self.Bind(wx.EVT_MENU, self.GetForceVariableMenuFunction(iec_path.upper(), self.Table.GetItem(row)), id=new_id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   723
            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   724
            new_id = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   725
            AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Release value"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   726
            self.Bind(wx.EVT_MENU, self.GetReleaseVariableMenuFunction(iec_path.upper()), id=new_id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   727
            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   728
            if self.Table.IsForced(row):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   729
                menu.Enable(new_id, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   730
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   731
                menu.Enable(new_id, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   732
            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   733
            self.PopupMenu(menu)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   734
            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   735
            menu.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   736
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   737
    
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   738
    def RefreshRange(self):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   739
        if len(self.Ticks) > 0:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   740
            if self.Fixed and self.Ticks[-1] - self.Ticks[0] < self.CurrentRange:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   741
                self.Fixed = False
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   742
            if self.Fixed:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   743
                self.StartTick = min(self.StartTick, self.Ticks[-1] - self.CurrentRange)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   744
            else:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   745
                self.StartTick = max(self.Ticks[0], self.Ticks[-1] - self.CurrentRange)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   746
        self.Force = True
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   747
        self.RefreshGrid(True)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   748
    
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   749
    def OnRangeChanged(self, event):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   750
        try:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   751
            if self.Ticktime == 0:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   752
                self.CurrentRange = self.RangeValues[self.CanvasRange.GetSelection()][1]
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   753
            else:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   754
                self.CurrentRange = self.RangeValues[self.CanvasRange.GetSelection()][1] / self.Ticktime
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   755
        except ValueError, e:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   756
            self.CanvasRange.SetValue(str(self.CurrentRange))
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   757
        wx.CallAfter(self.RefreshRange)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   758
        event.Skip()
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   759
    
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   760
    def OnResetButton(self, event):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   761
        self.StartTick = 0
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   762
        self.Fixed = False
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   763
        for item in self.Table.GetData():
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   764
            item.ResetData()
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   765
        self.RefreshGrid(True)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   766
        event.Skip()
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   767
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   768
    def OnCurrentButton(self, event):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   769
        if len(self.Ticks) > 0:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   770
            self.StartTick = max(self.Ticks[0], self.Ticks[-1] - self.CurrentRange)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   771
            self.Fixed = False
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   772
            self.Force = True
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   773
            self.RefreshGrid(True)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   774
        event.Skip()
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   775
    
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   776
    def CopyDataToClipboard(self, variables):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   777
        text = "tick;%s;\n" % ";".join([var_name for var_name, data in variables])
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   778
        next_tick = NextTick(variables)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   779
        while next_tick is not None:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   780
            values = []
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   781
            for var_name, data in variables:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   782
                if len(data) > 0:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   783
                    if next_tick == data[0][0]:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   784
                        values.append("%.3f" % data.pop(0)[1])
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   785
                    else:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   786
                        values.append("")
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   787
                else:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   788
                    values.append("")
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   789
            text += "%d;%s;\n" % (next_tick, ";".join(values))
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   790
            next_tick = NextTick(variables)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   791
        self.ParentWindow.SetCopyBuffer(text)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   792
    
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   793
    def OnExportGraphButton(self, event):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   794
        variables = []
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   795
        for item in self.Table.GetData():
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   796
            if item.IsNumVariable():
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   797
                variables.append((item.GetVariable(), [entry for entry in item.GetData()]))
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   798
        wx.CallAfter(self.CopyDataToClipboard, variables)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   799
        event.Skip()
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   800
    
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   801
    def OnPositionChanging(self, event):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   802
        if len(self.Ticks) > 0:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   803
            self.StartTick = self.Ticks[0] + event.GetPosition()
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   804
            self.Fixed = True
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   805
            self.Force = True
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   806
            wx.CallAfter(self.NewDataAvailable, None, True)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   807
        event.Skip()
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   808
    
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   809
    def InsertValue(self, iec_path, idx = None, force=False):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   810
        if idx is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   811
            idx = self.Table.GetNumberRows()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   812
        for item in self.Table.GetData():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   813
            if iec_path == item.GetVariable():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   814
                return
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   815
        item = VariableTableItem(self, iec_path)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   816
        result = self.AddDataConsumer(iec_path.upper(), item)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   817
        if result is not None or force:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   818
            self.Table.InsertItem(idx, item)
907
591cb3d96980 Fixed performance issue with matplotlib in DebugVariablePanel and hide 3D graphics when not needed
Laurent Bessard
parents: 905
diff changeset
   819
            if item.IsNumVariable():
591cb3d96980 Fixed performance issue with matplotlib in DebugVariablePanel and hide 3D graphics when not needed
Laurent Bessard
parents: 905
diff changeset
   820
                self.GraphicsAxes.append({
591cb3d96980 Fixed performance issue with matplotlib in DebugVariablePanel and hide 3D graphics when not needed
Laurent Bessard
parents: 905
diff changeset
   821
                    "items": [item],
591cb3d96980 Fixed performance issue with matplotlib in DebugVariablePanel and hide 3D graphics when not needed
Laurent Bessard
parents: 905
diff changeset
   822
                    "axes": None,
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   823
                    "type": GRAPH_PARALLEL,
907
591cb3d96980 Fixed performance issue with matplotlib in DebugVariablePanel and hide 3D graphics when not needed
Laurent Bessard
parents: 905
diff changeset
   824
                    "plots": []})
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   825
            self.ResetGraphics()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   826
            self.RefreshGrid()
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   827
    
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   828
    def MergeGraphs(self, source, target_infos, merge_type, force=False):
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   829
        source_item = None
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   830
        for item in self.Table.GetData():
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   831
            if item.GetVariable() == source:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   832
                source_item = item
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   833
        if source_item is None:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   834
            item = VariableTableItem(self, source)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   835
            if item.IsNumVariable():
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   836
                result = self.AddDataConsumer(source.upper(), item)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   837
                if result is not None or force:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   838
                    self.Table.InsertItem(self.Table.GetNumberRows(), item)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   839
                    source_item = item
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   840
        if source_item is not None:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   841
            source_infos = None
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   842
            for infos in self.GraphicsAxes:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   843
                if source_item in infos["items"]:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   844
                    source_infos = infos
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   845
                    break
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   846
            if target_infos is None and source_infos is None:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   847
                self.GraphicsAxes.append({
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   848
                    "items": [source_item],
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   849
                    "axes": None,
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   850
                    "type": GRAPH_PARALLEL,
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   851
                    "plots": []})
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   852
                
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   853
                self.ResetGraphics()
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   854
                self.RefreshGrid()
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   855
            
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   856
            elif target_infos is not None:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   857
                if (merge_type == GRAPH_PARALLEL and target_infos["type"] != merge_type or
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   858
                    merge_type == GRAPH_ORTHOGONAL and 
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   859
                    (target_infos["type"] == GRAPH_PARALLEL and len(target_infos["items"]) > 1 or
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   860
                     target_infos["type"] == GRAPH_ORTHOGONAL and len(target_infos["items"]) >= 3)):
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   861
                    return
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   862
                
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   863
                if source_infos is not None:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   864
                    source_infos["items"].remove(source_item)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   865
                    if len(source_infos["items"]) == 0:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   866
                        self.GraphicsAxes.remove(source_infos)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   867
                
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   868
                target_infos["items"].append(source_item)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   869
                target_infos["type"] = merge_type
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   870
                
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   871
                self.ResetGraphics()
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   872
                self.RefreshGrid()
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   873
            
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   874
    def GetDebugVariables(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   875
        return [item.GetVariable() for item in self.Table.GetData()]
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   876
    
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   877
    def OnGraphicsCanvasClick(self, event):
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   878
        for infos in self.GraphicsAxes:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   879
            if infos["axes"] == event.inaxes:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   880
                if len(infos["items"]) == 1:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   881
                    data = wx.TextDataObject(str((infos["items"][0].GetVariable(), "debug")))
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   882
                    dragSource = wx.DropSource(self.GraphicsCanvas)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   883
                    dragSource.SetData(data)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   884
                    dragSource.DoDragDrop()
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   885
                    if self.GraphicsCanvas.HasCapture():
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   886
                        self.GraphicsCanvas.ReleaseMouse()
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   887
                break
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   888
    
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   889
    def ResetGraphicsValues(self):
903
e70daa8bca85 Fix bug in DebugVariablePanel graphics not reset when program is restart
Laurent Bessard
parents: 902
diff changeset
   890
        self.Ticks = numpy.array([])
e70daa8bca85 Fix bug in DebugVariablePanel graphics not reset when program is restart
Laurent Bessard
parents: 902
diff changeset
   891
        self.StartTick = 0
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   892
        for item in self.Table.GetData():
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   893
            item.ResetData()
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   894
    
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   895
    def ResetGraphics(self):
888
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   896
        if USE_MPL:
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   897
            self.GraphicsFigure.clear()
907
591cb3d96980 Fixed performance issue with matplotlib in DebugVariablePanel and hide 3D graphics when not needed
Laurent Bessard
parents: 905
diff changeset
   898
            
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   899
            axes_num = 0
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   900
            for infos in self.GraphicsAxes:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   901
                if infos["type"] != GRAPH_ORTHOGONAL or len(infos["items"]) < 3:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   902
                    axes_num += 1
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   903
            if axes_num == len(self.GraphicsAxes):
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   904
                self.Graphics3DCanvas.Hide()
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   905
            else:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   906
                self.Graphics3DCanvas.Show()
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   907
            self.GraphicsPanelSizer.Layout()
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   908
            idx = 1
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   909
            for infos in self.GraphicsAxes:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   910
                if infos["type"] != GRAPH_ORTHOGONAL or len(infos["items"]) < 3:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   911
                    axes = self.GraphicsFigure.add_subplot(axes_num, 1, idx)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   912
                    infos["axes"] = axes
888
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   913
                else:
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   914
                    infos["axes"] = self.Graphics3DAxes
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   915
                infos["plots"] = []
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   916
                idx += 1
888
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   917
            self.RefreshGraphicsCanvasWindowScrollbars()
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
   918
            self.GraphicsCanvas.draw()
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   919
    
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   920
    def OnGraphics3DMotion(self, event):
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   921
        current_time = gettime()
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   922
        if current_time - self.LastMotionTime > REFRESH_PERIOD:
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   923
            self.LastMotionTime = current_time
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   924
            Axes3D._on_move(self.Graphics3DAxes, event)
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   925
    
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   926
    def RefreshGraphicsCanvasWindowScrollbars(self):
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   927
        xstart, ystart = self.GraphicsCanvasWindow.GetViewStart()
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   928
        window_size = self.GraphicsCanvasWindow.GetClientSize()
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   929
        vwidth, vheight = (window_size[0], (len(self.GraphicsAxes) + 1) * 100)
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   930
        self.GraphicsCanvas.SetMinSize(wx.Size(vwidth, vheight))
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   931
        posx = max(0, min(xstart, (vwidth - window_size[0]) / SCROLLBAR_UNIT))
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   932
        posy = max(0, min(ystart, (vheight - window_size[1]) / SCROLLBAR_UNIT))
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   933
        self.GraphicsCanvasWindow.Scroll(posx, posy)
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   934
        self.GraphicsCanvasWindow.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, 
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   935
                vwidth / SCROLLBAR_UNIT, vheight / SCROLLBAR_UNIT, posx, posy)
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   936
    
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   937
    def OnGraphicsCanvasWindowResize(self, event):
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   938
        self.RefreshGraphicsCanvasWindowScrollbars()
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   939
        event.Skip()