controls/DebugVariablePanel/DebugVariableItem.py
author Laurent Bessard
Wed, 09 Oct 2013 10:57:20 +0200
changeset 1347 533741e5075c
parent 1268 f049c901c85b
child 1363 e87e0166d0a7
permissions -rw-r--r--
Fixed pou variables information loading stylesheet
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
import numpy
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
    26
import binascii
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    27
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    28
from graphics.DebugDataConsumer import DebugDataConsumer, TYPE_TRANSLATOR
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    29
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    30
#-------------------------------------------------------------------------------
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    31
#                 Constant for calculate CRC for string variables
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    32
#-------------------------------------------------------------------------------
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    33
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    34
STRING_CRC_SIZE = 8
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    35
STRING_CRC_MASK = 2 ** STRING_CRC_SIZE - 1
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    36
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    37
#-------------------------------------------------------------------------------
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    38
#                          Debug Variable Item Class
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    39
#-------------------------------------------------------------------------------
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    40
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    41
"""
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    42
Class that implements an element that consumes debug values for PLC variable and
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    43
stores received values for displaying them in graphic panel or table
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    44
"""
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    45
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    46
class DebugVariableItem(DebugDataConsumer):
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    47
    
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    48
    def __init__(self, parent, variable, store_data=False):
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    49
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    50
        Constructor
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    51
        @param parent: Reference to debug variable panel
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    52
        @param variable: Path of variable to debug
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    53
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    54
        DebugDataConsumer.__init__(self)
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    55
        
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    56
        self.Parent = parent
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    57
        self.Variable = variable
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    58
        self.StoreData = store_data
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    59
        
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    60
        # Get Variable data type
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
    61
        self.RefreshVariableType()
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
    62
        
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    63
    def __del__(self):
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    64
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    65
        Destructor
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    66
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    67
        # Reset reference to debug variable panel
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    68
        self.Parent = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    69
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    70
    def SetVariable(self, variable):
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    71
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    72
        Set path of variable 
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    73
        @param variable: Path of variable to debug
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    74
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    75
        if self.Parent is not None and self.Variable != variable:
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    76
            # Store variable path
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    77
            self.Variable = variable
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    78
            # Get Variable data type
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
    79
            self.RefreshVariableType()
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    80
            
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    81
            # Refresh debug variable panel
916
697d8b77d716 Improved matplotlib graphic debug panel implementation, adding force, release, split and delete graph buttons, replacing data grid by adding panel displaying non-numeric data between graphs
Laurent Bessard
parents: 912
diff changeset
    82
            self.Parent.RefreshView()
697d8b77d716 Improved matplotlib graphic debug panel implementation, adding force, release, split and delete graph buttons, replacing data grid by adding panel displaying non-numeric data between graphs
Laurent Bessard
parents: 912
diff changeset
    83
    
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
    84
    def GetVariable(self, mask=None):
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    85
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    86
        Return path of variable 
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    87
        @param mask: Mask to apply to variable path [var_name, '*',...]
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    88
        @return: String containing masked variable path
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    89
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    90
        # Apply mask to variable name
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
    91
        if mask is not None:
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    92
            # '#' correspond to parts that are different between all items
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    93
            
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    94
            # Extract variable path parts
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    95
            parts = self.Variable.split('.')
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    96
            # Adjust mask size to size of variable path
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
    97
            mask = mask + ['*'] * max(0, len(parts) - len(mask))
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    98
            
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    99
            # Store previous mask
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   100
            last = None
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   101
            # Init masked variable path
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   102
            variable = ""
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   103
            
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   104
            for m, p in zip(mask, parts):
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   105
                # Part is not masked, add part prefixed with '.' is previous
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   106
                # wasn't masked
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   107
                if m == '*':
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   108
                    variable += ('.' if last == '*' else '') + p
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   109
                
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   110
                # Part is mask, add '..' if first or previous wasn't masked
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   111
                elif last is None or last == '*':
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   112
                    variable += '..'
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   113
                
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   114
                last = m
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   115
            
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   116
            return variable
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   117
        
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   118
        return self.Variable
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   119
    
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   120
    def RefreshVariableType(self):
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   121
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   122
        Get and store variable data type
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   123
        """
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   124
        self.VariableType = self.Parent.GetDataType(self.Variable)
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   125
        # Reset data stored
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   126
        self.ResetData()
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   127
    
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   128
    def GetVariableType(self):
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   129
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   130
        Return variable data type
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   131
        @return: Variable data type
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   132
        """
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   133
        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
   134
    
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   135
    def GetData(self, start_tick=None, end_tick=None):
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   136
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   137
        Return data stored contained in given range
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   138
        @param start_tick: Start tick of given range (default None, first data)
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   139
        @param end_tick: end tick of given range (default None, last data)
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   140
        @return: Data as numpy.array([(tick, value, forced),...])
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   141
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   142
        # Return immediately if data empty or none
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   143
        if self.Data is None or len(self.Data) == 0:
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   144
            return self.Data
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   145
        
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   146
        # Find nearest data outside given range indexes
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   147
        start_idx = (self.GetNearestData(start_tick, -1)
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   148
                     if start_tick is not None
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   149
                     else 0)
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   150
        end_idx = (self.GetNearestData(end_tick, 1)
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   151
                   if end_tick is not None
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   152
                   else len(self.Data))
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   153
        
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   154
        # Return data between indexes
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   155
        return self.Data[start_idx:end_idx]
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   156
    
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   157
    def GetRawValue(self, index):
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   158
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   159
        Return raw value at given index for string variables
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   160
        @param index: Variable value index
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   161
        @return: Variable data type
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   162
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   163
        if (self.VariableType in ["STRING", "WSTRING"] and
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   164
            index < len(self.RawData)):
1268
f049c901c85b Fix bug when exporting string variables values in graph to clipboard
Laurent Bessard
parents: 1267
diff changeset
   165
            return self.RawData[index][0]
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   166
        return ""
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   167
    
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   168
    def GetValueRange(self):
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   169
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   170
        Return variable value range
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   171
        @return: (minimum_value, maximum_value)
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   172
        """
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   173
        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
   174
    
1267
fae0809eae98 Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents: 1220
diff changeset
   175
    def GetDataAndValueRange(self, start_tick, end_tick, full_range=True):
fae0809eae98 Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents: 1220
diff changeset
   176
        """
fae0809eae98 Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents: 1220
diff changeset
   177
        Return variable data and value range for a given tick range
1215
786f2533200a Rewrite DebugVariablePanel
Laurent Bessard
parents: 1214
diff changeset
   178
        @param start_tick: Start tick of given range (default None, first data)
786f2533200a Rewrite DebugVariablePanel
Laurent Bessard
parents: 1214
diff changeset
   179
        @param end_tick: end tick of given range (default None, last data)
1267
fae0809eae98 Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents: 1220
diff changeset
   180
        @param full_range: Value range is calculated on whole data (False: only
fae0809eae98 Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents: 1220
diff changeset
   181
        calculated on data in given range)
1215
786f2533200a Rewrite DebugVariablePanel
Laurent Bessard
parents: 1214
diff changeset
   182
        @return: (numpy.array([(tick, value, forced),...]), 
786f2533200a Rewrite DebugVariablePanel
Laurent Bessard
parents: 1214
diff changeset
   183
                  min_value, max_value)
786f2533200a Rewrite DebugVariablePanel
Laurent Bessard
parents: 1214
diff changeset
   184
        """
1267
fae0809eae98 Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents: 1220
diff changeset
   185
        # Get data in given tick range
fae0809eae98 Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents: 1220
diff changeset
   186
        data = self.GetData(start_tick, end_tick)
fae0809eae98 Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents: 1220
diff changeset
   187
        
fae0809eae98 Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents: 1220
diff changeset
   188
        # Value range is calculated on whole data
fae0809eae98 Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents: 1220
diff changeset
   189
        if full_range:
fae0809eae98 Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents: 1220
diff changeset
   190
            return data, self.MinValue, self.MaxValue
fae0809eae98 Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents: 1220
diff changeset
   191
        
fae0809eae98 Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents: 1220
diff changeset
   192
        # Check that data in given range is not empty
fae0809eae98 Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents: 1220
diff changeset
   193
        values = data[:, 1]
fae0809eae98 Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents: 1220
diff changeset
   194
        if len(values) > 0:
fae0809eae98 Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents: 1220
diff changeset
   195
            # Return value range for data in given tick range
fae0809eae98 Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents: 1220
diff changeset
   196
            return (data,
fae0809eae98 Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents: 1220
diff changeset
   197
                    data[numpy.argmin(values), 1],
fae0809eae98 Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents: 1220
diff changeset
   198
                    data[numpy.argmax(values), 1])
fae0809eae98 Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents: 1220
diff changeset
   199
        
fae0809eae98 Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents: 1220
diff changeset
   200
        # Return default values
fae0809eae98 Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents: 1220
diff changeset
   201
        return data, None, None
1215
786f2533200a Rewrite DebugVariablePanel
Laurent Bessard
parents: 1214
diff changeset
   202
    
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   203
    def ResetData(self):
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   204
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   205
        Reset data stored when store data option enabled
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   206
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   207
        if self.StoreData and self.IsNumVariable():
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   208
            # Init table storing data
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   209
            self.Data = numpy.array([]).reshape(0, 3)
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   210
            
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   211
            # Init table storing raw data if variable is strin
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   212
            self.RawData = ([]
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   213
                            if self.VariableType in ["STRING", "WSTRING"]
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   214
                            else None)
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   215
                
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   216
            # Init Value range variables
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   217
            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
   218
            self.MaxValue = None
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   219
        
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   220
        else:
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   221
            self.Data = None
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   222
        
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   223
        # Init variable value
1040
af8a1aee3584 Fixed MouseWheel behavior in DebugVariablePanel, change graph range only if CTRL is pressed
Laurent Bessard
parents: 1008
diff changeset
   224
        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
   225
    
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   226
    def IsNumVariable(self):
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   227
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   228
        Return if variable data type is numeric. String variables are
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   229
        considered as numeric (string CRC)
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   230
        @return: True if data type is numeric
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   231
        """
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   232
        return (self.Parent.IsNumType(self.VariableType) or 
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   233
                self.VariableType in ["STRING", "WSTRING"])
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   234
    
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   235
    def NewValue(self, tick, value, forced=False):
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   236
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   237
        Function called by debug thread when a new debug value is available
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   238
        @param tick: PLC tick when value was captured
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   239
        @param value: Value captured
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   240
        @param forced: Forced flag, True if value is forced (default: False)
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   241
        """
1220
16c283246241 Fixed in DebugDataConsumer value translation inhibit support
Laurent Bessard
parents: 1215
diff changeset
   242
        DebugDataConsumer.NewValue(self, tick, value, forced, raw=None)
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   243
        
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   244
        if self.Data is not None:
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   245
            # String data value is CRC
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   246
            num_value = (binascii.crc32(value) & STRING_CRC_MASK
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   247
                         if self.VariableType in ["STRING", "WSTRING"]
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   248
                         else float(value))
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   249
            
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   250
            # Update variable range values
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   251
            self.MinValue = (min(self.MinValue, num_value)
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   252
                             if self.MinValue is not None
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   253
                             else num_value)
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   254
            self.MaxValue = (max(self.MaxValue, num_value)
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   255
                             if self.MaxValue is not None
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   256
                             else num_value)
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   257
            
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   258
            # Translate forced flag to float for storing in Data table
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   259
            forced_value = float(forced)
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   260
            
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   261
            # In the case of string variables, we store raw string value and
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   262
            # forced flag in raw data table. Only changes in this two values
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   263
            # are stored. Index to the corresponding raw value is stored in 
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   264
            # data third column
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   265
            if self.VariableType in ["STRING", "WSTRING"]:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   266
                raw_data = (value, forced_value)
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   267
                if len(self.RawData) == 0 or self.RawData[-1] != raw_data:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   268
                    extra_value = len(self.RawData)
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   269
                    self.RawData.append(raw_data)
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   270
                else:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   271
                    extra_value = len(self.RawData) - 1
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   272
            
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   273
            # In other case, data third column is forced flag
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   274
            else:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   275
                extra_value = forced_value
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   276
            
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   277
            # Add New data to stored data table
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   278
            self.Data = numpy.append(self.Data, 
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   279
                    [[float(tick), num_value, extra_value]], axis=0)
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   280
        
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   281
            # Signal to debug variable panel to refresh
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   282
            self.Parent.HasNewData = True
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   283
        
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   284
    def SetForced(self, forced):
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   285
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   286
        Update Forced flag
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   287
        @param forced: New forced flag
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   288
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   289
        # Store forced flag
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   290
        if self.Forced != forced:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   291
            self.Forced = forced
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   292
            
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   293
            # Signal to debug variable panel to refresh
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   294
            self.Parent.HasNewData = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   295
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   296
    def SetValue(self, value):
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   297
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   298
        Update value.
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   299
        @param value: New value
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   300
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   301
        # Remove quote and double quote surrounding string value to get raw value
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   302
        if (self.VariableType == "STRING" and
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   303
            value.startswith("'") and value.endswith("'") or
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   304
            self.VariableType == "WSTRING" and
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   305
            value.startswith('"') and value.endswith('"')):
892
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
   306
            value = value[1:-1]
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   307
        
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   308
        # Store variable value
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   309
        if self.Value != value:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   310
            self.Value = value
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   311
            
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   312
            # Signal to debug variable panel to refresh
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   313
            self.Parent.HasNewData = True
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   314
    
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   315
    def GetValue(self, tick=None, raw=False):
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   316
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   317
        Return current value or value and forced flag for tick given
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   318
        @return: Current value or value and forced flag
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   319
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   320
        # If tick given and stored data option enabled
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   321
        if tick is not None and self.Data is not None:
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   322
            
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   323
            # Return current value and forced flag if data empty
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   324
            if len(self.Data) == 0:
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   325
                return self.Value, self.IsForced()
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   326
            
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   327
            # Get index of nearest data from tick given
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   328
            idx = self.GetNearestData(tick, 0)
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   329
            
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   330
            # Get value and forced flag at given index
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   331
            value, forced = self.RawData[int(self.Data[idx, 2])] \
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   332
                            if self.VariableType in ["STRING", "WSTRING"] \
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   333
                            else self.Data[idx, 1:3]
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   334
            
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   335
            # Get raw value if asked
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   336
            if not raw:
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   337
                value = TYPE_TRANSLATOR.get(
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   338
                        self.VariableType, str)(value)
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   339
            
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   340
            return value, forced
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   341
            
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   342
        # Return raw value if asked
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   343
        if not raw and self.VariableType in ["STRING", "WSTRING"]:
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   344
            return TYPE_TRANSLATOR.get(
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   345
                    self.VariableType, str)(self.Value)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   346
        return self.Value
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   347
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   348
    def GetNearestData(self, tick, adjust):
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   349
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   350
        Return index of nearest data from tick given
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   351
        @param tick: Tick where find nearest data
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   352
        @param adjust: Constraint for data position from tick
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   353
                       -1: older than tick
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   354
                       1:  newer than tick
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   355
                       0:  doesn't matter
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   356
        @return: Index of nearest data
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   357
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   358
        # Return immediately if data is empty
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   359
        if self.Data is None:
916
697d8b77d716 Improved matplotlib graphic debug panel implementation, adding force, release, split and delete graph buttons, replacing data grid by adding panel displaying non-numeric data between graphs
Laurent Bessard
parents: 912
diff changeset
   360
            return None
697d8b77d716 Improved matplotlib graphic debug panel implementation, adding force, release, split and delete graph buttons, replacing data grid by adding panel displaying non-numeric data between graphs
Laurent Bessard
parents: 912
diff changeset
   361
        
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   362
        # Extract data ticks
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   363
        ticks = self.Data[:, 0]
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   364
        
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   365
        # Get nearest data from tick
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   366
        idx = numpy.argmin(abs(ticks - tick))
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   367
        
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   368
        # Adjust data index according to constraint
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   369
        if (adjust < 0 and ticks[idx] > tick and idx > 0 or
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   370
            adjust > 0 and ticks[idx] < tick and idx < len(ticks)):
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   371
            idx += adjust
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   372
        
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   373
        return idx