controls/DebugVariablePanel/DebugVariableItem.py
author Edouard Tisserant <edouard.tisserant@gmail.com>
Tue, 04 Jun 2024 14:09:16 +0200
changeset 3959 d5edde0c145b
parent 3886 2adfa4c60bff
permissions -rw-r--r--
Revert unwanted changes potentially breaking wxGlade support.
Partly revert 34d4c77ccb1bcb14601ab347ec6080466b7e143d. Skips evaluator related changes that was included by mistake.
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
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1365
diff changeset
     4
# This file is part of Beremiz, a Integrated Development Environment for
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1365
diff changeset
     5
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1365
diff changeset
     6
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1365
diff changeset
     7
# Copyright (C) 2012: Edouard TISSERANT and Laurent BESSARD
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1365
diff changeset
     8
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1365
diff changeset
     9
# See COPYING file for copyrights details.
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1365
diff changeset
    10
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1365
diff changeset
    11
# This program is free software; you can redistribute it and/or
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1365
diff changeset
    12
# modify it under the terms of the GNU General Public License
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1365
diff changeset
    13
# as published by the Free Software Foundation; either version 2
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1365
diff changeset
    14
# of the License, or (at your option) any later version.
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1365
diff changeset
    15
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1365
diff changeset
    16
# This program is distributed in the hope that it will be useful,
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1365
diff changeset
    17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1365
diff changeset
    18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1365
diff changeset
    19
# GNU General Public License for more details.
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1365
diff changeset
    20
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1365
diff changeset
    21
# You should have received a copy of the GNU General Public License
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1365
diff changeset
    22
# along with this program; if not, write to the Free Software
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1365
diff changeset
    23
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    24
1881
091005ec69c4 fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1878
diff changeset
    25
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3598
diff changeset
    26
1966
08f70b33bc9f fix import order according to PEP8
Surkov Sergey <surkovsv93@gmail.com>
parents: 1962
diff changeset
    27
from datetime import timedelta
1832
0f1081928d65 fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    28
import binascii
2741
3cc5663af196 IDE: Cleaned up some useless tests in variable trace data handling code, changed from bare numpy arrays to RingBuffers inorder to avoid RAM outage and crash after long tracing session.
Edouard Tisserant
parents: 1966
diff changeset
    29
import numpy as np
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    30
from graphics.DebugDataConsumer import DebugDataConsumer, TYPE_TRANSLATOR
2741
3cc5663af196 IDE: Cleaned up some useless tests in variable trace data handling code, changed from bare numpy arrays to RingBuffers inorder to avoid RAM outage and crash after long tracing session.
Edouard Tisserant
parents: 1966
diff changeset
    31
from controls.DebugVariablePanel.RingBuffer import RingBuffer
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    32
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1774
diff changeset
    33
# -------------------------------------------------------------------------------
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    34
#                 Constant for calculate CRC for string variables
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1774
diff changeset
    35
# -------------------------------------------------------------------------------
1193
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
STRING_CRC_SIZE = 8
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    38
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
    39
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1774
diff changeset
    40
# -------------------------------------------------------------------------------
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    41
#                          Debug Variable Item Class
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1774
diff changeset
    42
# -------------------------------------------------------------------------------
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    43
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
class DebugVariableItem(DebugDataConsumer):
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    46
    """
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    47
    Class that implements an element that consumes debug values for PLC variable and
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    48
    stores received values for displaying them in graphic panel or table
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    49
    """
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    50
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    51
    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
    52
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    53
        Constructor
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    54
        @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
    55
        @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
    56
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    57
        DebugDataConsumer.__init__(self)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    58
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    59
        self.Parent = parent
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    60
        self.Variable = variable
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    61
        self.StoreData = store_data
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    62
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    63
        # 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
    64
        self.RefreshVariableType()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    65
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    66
    def SetVariable(self, variable):
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    67
        """
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    68
        Set path of variable
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    69
        @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
    70
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    71
        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
    72
            # Store variable path
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    73
            self.Variable = variable
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    74
            # 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
    75
            self.RefreshVariableType()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    76
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    77
            # 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
    78
            self.Parent.RefreshView()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    79
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
    80
    def GetVariable(self, mask=None):
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    81
        """
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    82
        Return path of variable
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    83
        @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
    84
        @return: String containing masked variable path
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
        # 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
    87
        if mask is not None:
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    88
            # '#' correspond to parts that are different between all items
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    89
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    90
            # Extract variable path parts
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    91
            parts = self.Variable.split('.')
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    92
            # 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
    93
            mask = mask + ['*'] * max(0, len(parts) - len(mask))
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    94
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    95
            # 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
    96
            last = None
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
    97
            # 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
    98
            variable = ""
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    99
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   100
            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
   101
                # 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
   102
                # 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
   103
                if m == '*':
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   104
                    variable += ('.' if last == '*' else '') + p
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   105
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   106
                # 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
   107
                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
   108
                    variable += '..'
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   109
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   110
                last = m
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   111
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   112
            return variable
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   113
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   114
        return self.Variable
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   115
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   116
    def RefreshVariableType(self):
1193
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
        Get and store variable data type
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
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
        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
   121
        # Reset data stored
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   122
        self.ResetData()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
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
    def GetVariableType(self):
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   125
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   126
        Return variable data type
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   127
        @return: Variable data type
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   128
        """
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   129
        return self.VariableType
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   130
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   131
    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
   132
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   133
        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
   134
        @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
   135
        @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
   136
        @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
   137
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   138
        # Return immediately if data empty or none
2741
3cc5663af196 IDE: Cleaned up some useless tests in variable trace data handling code, changed from bare numpy arrays to RingBuffers inorder to avoid RAM outage and crash after long tracing session.
Edouard Tisserant
parents: 1966
diff changeset
   139
        if self.Data is None or self.Data.count == 0:
3598
13677d093946 IDE: fix exception transfering or reconnecting after tracing variables
Edouard Tisserant
parents: 3335
diff changeset
   140
            return None
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   141
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   142
        # 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
   143
        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
   144
                     if start_tick is not None
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   145
                     else 0)
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   146
        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
   147
                   if end_tick is not None
3292
ef04cedee08b IDE: Fixed use of RingBuffers in variable traces graphs when switching to 2D trend graph.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2742
diff changeset
   148
                   else self.Data.count)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   149
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   150
        # Return data between indexes
2741
3cc5663af196 IDE: Cleaned up some useless tests in variable trace data handling code, changed from bare numpy arrays to RingBuffers inorder to avoid RAM outage and crash after long tracing session.
Edouard Tisserant
parents: 1966
diff changeset
   151
        return self.Data.view[start_idx:end_idx]
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   152
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   153
    def GetRawValue(self, index):
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   154
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   155
        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
   156
        @param index: Variable value index
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   157
        @return: Variable data type
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   158
        """
1766
c1e5b9f19483 clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   159
        if self.VariableType in ["STRING", "WSTRING"] and index < len(self.RawData):
1268
f049c901c85b Fix bug when exporting string variables values in graph to clipboard
Laurent Bessard
parents: 1267
diff changeset
   160
            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
   161
        return ""
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   162
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   163
    def GetValueRange(self):
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   164
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   165
        Return variable value range
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   166
        @return: (minimum_value, maximum_value)
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   167
        """
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   168
        return self.MinValue, self.MaxValue
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   169
1267
fae0809eae98 Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents: 1220
diff changeset
   170
    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
   171
        """
fae0809eae98 Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents: 1220
diff changeset
   172
        Return variable data and value range for a given tick range
1215
786f2533200a Rewrite DebugVariablePanel
Laurent Bessard
parents: 1214
diff changeset
   173
        @param start_tick: Start tick of given range (default None, first data)
786f2533200a Rewrite DebugVariablePanel
Laurent Bessard
parents: 1214
diff changeset
   174
        @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
   175
        @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
   176
        calculated on data in given range)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   177
        @return: (numpy.array([(tick, value, forced),...]),
1215
786f2533200a Rewrite DebugVariablePanel
Laurent Bessard
parents: 1214
diff changeset
   178
                  min_value, max_value)
786f2533200a Rewrite DebugVariablePanel
Laurent Bessard
parents: 1214
diff changeset
   179
        """
1267
fae0809eae98 Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents: 1220
diff changeset
   180
        # 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
   181
        data = self.GetData(start_tick, end_tick)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   182
3598
13677d093946 IDE: fix exception transfering or reconnecting after tracing variables
Edouard Tisserant
parents: 3335
diff changeset
   183
        if data is None:
13677d093946 IDE: fix exception transfering or reconnecting after tracing variables
Edouard Tisserant
parents: 3335
diff changeset
   184
            return None, None, None
13677d093946 IDE: fix exception transfering or reconnecting after tracing variables
Edouard Tisserant
parents: 3335
diff changeset
   185
1267
fae0809eae98 Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents: 1220
diff changeset
   186
        # 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
   187
        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
   188
            return data, self.MinValue, self.MaxValue
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   189
1267
fae0809eae98 Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents: 1220
diff changeset
   190
        # 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
   191
        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
   192
        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
   193
            # 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
   194
            return (data,
2741
3cc5663af196 IDE: Cleaned up some useless tests in variable trace data handling code, changed from bare numpy arrays to RingBuffers inorder to avoid RAM outage and crash after long tracing session.
Edouard Tisserant
parents: 1966
diff changeset
   195
                    data[np.argmin(values), 1],
3cc5663af196 IDE: Cleaned up some useless tests in variable trace data handling code, changed from bare numpy arrays to RingBuffers inorder to avoid RAM outage and crash after long tracing session.
Edouard Tisserant
parents: 1966
diff changeset
   196
                    data[np.argmax(values), 1])
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   197
1267
fae0809eae98 Added support for zooming graph so that it fits canvas size in Debug Variable Panel
Laurent Bessard
parents: 1220
diff changeset
   198
        # 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
   199
        return data, None, None
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   200
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   201
    def ResetData(self):
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   202
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   203
        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
   204
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   205
        if self.StoreData and self.IsNumVariable():
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   206
            # Init table storing data
2741
3cc5663af196 IDE: Cleaned up some useless tests in variable trace data handling code, changed from bare numpy arrays to RingBuffers inorder to avoid RAM outage and crash after long tracing session.
Edouard Tisserant
parents: 1966
diff changeset
   207
            self.Data = RingBuffer(3)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   208
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   209
            # 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
   210
            self.RawData = ([]
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   211
                            if self.VariableType in ["STRING", "WSTRING"]
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   212
                            else None)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   213
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   214
            # 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
   215
            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
   216
            self.MaxValue = None
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   217
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   218
        else:
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   219
            self.Data = None
1962
f41dc3829af6 fix display TIME type variables in debug variable panel
Surkov Sergey <surkovsv93@gmail.com>
parents: 1881
diff changeset
   220
            self.MinValue = None
f41dc3829af6 fix display TIME type variables in debug variable panel
Surkov Sergey <surkovsv93@gmail.com>
parents: 1881
diff changeset
   221
            self.MaxValue = None
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   222
        # Init variable value
1040
af8a1aee3584 Fixed MouseWheel behavior in DebugVariablePanel, change graph range only if CTRL is pressed
Laurent Bessard
parents: 1008
diff changeset
   223
        self.Value = ""
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   224
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   225
    def IsNumVariable(self):
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   226
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   227
        Return if variable data type is numeric. String variables are
1962
f41dc3829af6 fix display TIME type variables in debug variable panel
Surkov Sergey <surkovsv93@gmail.com>
parents: 1881
diff changeset
   228
        considered as numeric (string CRC). Time variables are considered
f41dc3829af6 fix display TIME type variables in debug variable panel
Surkov Sergey <surkovsv93@gmail.com>
parents: 1881
diff changeset
   229
        as number of seconds
1193
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
        """
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   232
        return (self.Parent.IsNumType(self.VariableType) or
1962
f41dc3829af6 fix display TIME type variables in debug variable panel
Surkov Sergey <surkovsv93@gmail.com>
parents: 1881
diff changeset
   233
                self.VariableType in ["STRING", "WSTRING", "TIME", "TOD", "DT", "DATE"])
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   234
1365
debc97102b23 Added support for optimizing debug, preventing to filling buffers with only the last value for debug data consumers that only show the current state
Laurent Bessard
parents: 1363
diff changeset
   235
    def NewValues(self, ticks, values):
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
        """
1365
debc97102b23 Added support for optimizing debug, preventing to filling buffers with only the last value for debug data consumers that only show the current state
Laurent Bessard
parents: 1363
diff changeset
   242
        DebugDataConsumer.NewValues(self, ticks[-1], values[-1], raw=None)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   243
1193
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:
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   245
1363
e87e0166d0a7 Added new debug process separating non-wx thread extracting debug values from connector and 10 Hz wx timer refreshing Beremiz debug Viewers and communicating throw double-buffering, to avoid segmentation faults and optimize CPU usage
Laurent Bessard
parents: 1268
diff changeset
   246
            if self.VariableType in ["STRING", "WSTRING"]:
e87e0166d0a7 Added new debug process separating non-wx thread extracting debug values from connector and 10 Hz wx timer refreshing Beremiz debug Viewers and communicating throw double-buffering, to avoid segmentation faults and optimize CPU usage
Laurent Bessard
parents: 1268
diff changeset
   247
                last_raw_data = (self.RawData[-1]
e87e0166d0a7 Added new debug process separating non-wx thread extracting debug values from connector and 10 Hz wx timer refreshing Beremiz debug Viewers and communicating throw double-buffering, to avoid segmentation faults and optimize CPU usage
Laurent Bessard
parents: 1268
diff changeset
   248
                                 if len(self.RawData) > 0 else None)
e87e0166d0a7 Added new debug process separating non-wx thread extracting debug values from connector and 10 Hz wx timer refreshing Beremiz debug Viewers and communicating throw double-buffering, to avoid segmentation faults and optimize CPU usage
Laurent Bessard
parents: 1268
diff changeset
   249
                last_raw_data_idx = len(self.RawData) - 1
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   250
1363
e87e0166d0a7 Added new debug process separating non-wx thread extracting debug values from connector and 10 Hz wx timer refreshing Beremiz debug Viewers and communicating throw double-buffering, to avoid segmentation faults and optimize CPU usage
Laurent Bessard
parents: 1268
diff changeset
   251
            data_values = []
1365
debc97102b23 Added support for optimizing debug, preventing to filling buffers with only the last value for debug data consumers that only show the current state
Laurent Bessard
parents: 1363
diff changeset
   252
            for tick, (value, forced) in zip(ticks, values):
debc97102b23 Added support for optimizing debug, preventing to filling buffers with only the last value for debug data consumers that only show the current state
Laurent Bessard
parents: 1363
diff changeset
   253
                # Translate forced flag to float for storing in Data table
debc97102b23 Added support for optimizing debug, preventing to filling buffers with only the last value for debug data consumers that only show the current state
Laurent Bessard
parents: 1363
diff changeset
   254
                forced_value = float(forced)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   255
1962
f41dc3829af6 fix display TIME type variables in debug variable panel
Surkov Sergey <surkovsv93@gmail.com>
parents: 1881
diff changeset
   256
                if self.VariableType in ["STRING", "WSTRING"]:
f41dc3829af6 fix display TIME type variables in debug variable panel
Surkov Sergey <surkovsv93@gmail.com>
parents: 1881
diff changeset
   257
                    # String data value is CRC
3886
2adfa4c60bff Fix strings displaying as repr(bytes) in debug view.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3885
diff changeset
   258
                    num_value = (binascii.crc32(value.encode()) & STRING_CRC_MASK)
1962
f41dc3829af6 fix display TIME type variables in debug variable panel
Surkov Sergey <surkovsv93@gmail.com>
parents: 1881
diff changeset
   259
                elif self.VariableType in ["TIME", "TOD", "DT", "DATE"]:
f41dc3829af6 fix display TIME type variables in debug variable panel
Surkov Sergey <surkovsv93@gmail.com>
parents: 1881
diff changeset
   260
                    # Numeric value of time type variables
f41dc3829af6 fix display TIME type variables in debug variable panel
Surkov Sergey <surkovsv93@gmail.com>
parents: 1881
diff changeset
   261
                    # is represented in seconds
f41dc3829af6 fix display TIME type variables in debug variable panel
Surkov Sergey <surkovsv93@gmail.com>
parents: 1881
diff changeset
   262
                    num_value = float(value.total_seconds())
f41dc3829af6 fix display TIME type variables in debug variable panel
Surkov Sergey <surkovsv93@gmail.com>
parents: 1881
diff changeset
   263
                else:
f41dc3829af6 fix display TIME type variables in debug variable panel
Surkov Sergey <surkovsv93@gmail.com>
parents: 1881
diff changeset
   264
                    num_value = float(value)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   265
1363
e87e0166d0a7 Added new debug process separating non-wx thread extracting debug values from connector and 10 Hz wx timer refreshing Beremiz debug Viewers and communicating throw double-buffering, to avoid segmentation faults and optimize CPU usage
Laurent Bessard
parents: 1268
diff changeset
   266
                # Update variable range values
e87e0166d0a7 Added new debug process separating non-wx thread extracting debug values from connector and 10 Hz wx timer refreshing Beremiz debug Viewers and communicating throw double-buffering, to avoid segmentation faults and optimize CPU usage
Laurent Bessard
parents: 1268
diff changeset
   267
                self.MinValue = (min(self.MinValue, num_value)
e87e0166d0a7 Added new debug process separating non-wx thread extracting debug values from connector and 10 Hz wx timer refreshing Beremiz debug Viewers and communicating throw double-buffering, to avoid segmentation faults and optimize CPU usage
Laurent Bessard
parents: 1268
diff changeset
   268
                                 if self.MinValue is not None
e87e0166d0a7 Added new debug process separating non-wx thread extracting debug values from connector and 10 Hz wx timer refreshing Beremiz debug Viewers and communicating throw double-buffering, to avoid segmentation faults and optimize CPU usage
Laurent Bessard
parents: 1268
diff changeset
   269
                                 else num_value)
e87e0166d0a7 Added new debug process separating non-wx thread extracting debug values from connector and 10 Hz wx timer refreshing Beremiz debug Viewers and communicating throw double-buffering, to avoid segmentation faults and optimize CPU usage
Laurent Bessard
parents: 1268
diff changeset
   270
                self.MaxValue = (max(self.MaxValue, num_value)
e87e0166d0a7 Added new debug process separating non-wx thread extracting debug values from connector and 10 Hz wx timer refreshing Beremiz debug Viewers and communicating throw double-buffering, to avoid segmentation faults and optimize CPU usage
Laurent Bessard
parents: 1268
diff changeset
   271
                                 if self.MaxValue is not None
e87e0166d0a7 Added new debug process separating non-wx thread extracting debug values from connector and 10 Hz wx timer refreshing Beremiz debug Viewers and communicating throw double-buffering, to avoid segmentation faults and optimize CPU usage
Laurent Bessard
parents: 1268
diff changeset
   272
                                 else num_value)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   273
1363
e87e0166d0a7 Added new debug process separating non-wx thread extracting debug values from connector and 10 Hz wx timer refreshing Beremiz debug Viewers and communicating throw double-buffering, to avoid segmentation faults and optimize CPU usage
Laurent Bessard
parents: 1268
diff changeset
   274
                # In the case of string variables, we store raw string value and
e87e0166d0a7 Added new debug process separating non-wx thread extracting debug values from connector and 10 Hz wx timer refreshing Beremiz debug Viewers and communicating throw double-buffering, to avoid segmentation faults and optimize CPU usage
Laurent Bessard
parents: 1268
diff changeset
   275
                # forced flag in raw data table. Only changes in this two values
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   276
                # are stored. Index to the corresponding raw value is stored in
1363
e87e0166d0a7 Added new debug process separating non-wx thread extracting debug values from connector and 10 Hz wx timer refreshing Beremiz debug Viewers and communicating throw double-buffering, to avoid segmentation faults and optimize CPU usage
Laurent Bessard
parents: 1268
diff changeset
   277
                # data third column
e87e0166d0a7 Added new debug process separating non-wx thread extracting debug values from connector and 10 Hz wx timer refreshing Beremiz debug Viewers and communicating throw double-buffering, to avoid segmentation faults and optimize CPU usage
Laurent Bessard
parents: 1268
diff changeset
   278
                if self.VariableType in ["STRING", "WSTRING"]:
e87e0166d0a7 Added new debug process separating non-wx thread extracting debug values from connector and 10 Hz wx timer refreshing Beremiz debug Viewers and communicating throw double-buffering, to avoid segmentation faults and optimize CPU usage
Laurent Bessard
parents: 1268
diff changeset
   279
                    raw_data = (value, forced_value)
e87e0166d0a7 Added new debug process separating non-wx thread extracting debug values from connector and 10 Hz wx timer refreshing Beremiz debug Viewers and communicating throw double-buffering, to avoid segmentation faults and optimize CPU usage
Laurent Bessard
parents: 1268
diff changeset
   280
                    if len(self.RawData) == 0 or last_raw_data != raw_data:
e87e0166d0a7 Added new debug process separating non-wx thread extracting debug values from connector and 10 Hz wx timer refreshing Beremiz debug Viewers and communicating throw double-buffering, to avoid segmentation faults and optimize CPU usage
Laurent Bessard
parents: 1268
diff changeset
   281
                        last_raw_data_idx += 1
e87e0166d0a7 Added new debug process separating non-wx thread extracting debug values from connector and 10 Hz wx timer refreshing Beremiz debug Viewers and communicating throw double-buffering, to avoid segmentation faults and optimize CPU usage
Laurent Bessard
parents: 1268
diff changeset
   282
                        last_raw_data = raw_data
e87e0166d0a7 Added new debug process separating non-wx thread extracting debug values from connector and 10 Hz wx timer refreshing Beremiz debug Viewers and communicating throw double-buffering, to avoid segmentation faults and optimize CPU usage
Laurent Bessard
parents: 1268
diff changeset
   283
                        self.RawData.append(raw_data)
e87e0166d0a7 Added new debug process separating non-wx thread extracting debug values from connector and 10 Hz wx timer refreshing Beremiz debug Viewers and communicating throw double-buffering, to avoid segmentation faults and optimize CPU usage
Laurent Bessard
parents: 1268
diff changeset
   284
                    extra_value = last_raw_data_idx
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   285
1363
e87e0166d0a7 Added new debug process separating non-wx thread extracting debug values from connector and 10 Hz wx timer refreshing Beremiz debug Viewers and communicating throw double-buffering, to avoid segmentation faults and optimize CPU usage
Laurent Bessard
parents: 1268
diff changeset
   286
                # 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
   287
                else:
1363
e87e0166d0a7 Added new debug process separating non-wx thread extracting debug values from connector and 10 Hz wx timer refreshing Beremiz debug Viewers and communicating throw double-buffering, to avoid segmentation faults and optimize CPU usage
Laurent Bessard
parents: 1268
diff changeset
   288
                    extra_value = forced_value
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   289
1363
e87e0166d0a7 Added new debug process separating non-wx thread extracting debug values from connector and 10 Hz wx timer refreshing Beremiz debug Viewers and communicating throw double-buffering, to avoid segmentation faults and optimize CPU usage
Laurent Bessard
parents: 1268
diff changeset
   290
                data_values.append(
e87e0166d0a7 Added new debug process separating non-wx thread extracting debug values from connector and 10 Hz wx timer refreshing Beremiz debug Viewers and communicating throw double-buffering, to avoid segmentation faults and optimize CPU usage
Laurent Bessard
parents: 1268
diff changeset
   291
                    [float(tick), num_value, extra_value])
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   292
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   293
            # Add New data to stored data table
2741
3cc5663af196 IDE: Cleaned up some useless tests in variable trace data handling code, changed from bare numpy arrays to RingBuffers inorder to avoid RAM outage and crash after long tracing session.
Edouard Tisserant
parents: 1966
diff changeset
   294
            self.Data.append(data_values)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   295
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   296
            # 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
   297
            self.Parent.HasNewData = True
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   298
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   299
    def SetForced(self, forced):
1193
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
        Update Forced flag
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   302
        @param forced: New forced flag
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   303
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   304
        # Store forced flag
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   305
        if self.Forced != forced:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   306
            self.Forced = forced
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   307
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   308
            # Signal to debug variable panel to refresh
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   309
            self.Parent.HasNewData = True
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   310
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   311
    def SetValue(self, value):
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   312
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   313
        Update value.
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   314
        @param value: New value
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   315
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   316
        # Remove quote and double quote surrounding string value to get raw value
1774
ac0fe8aabb5e clean-up: fix PEP8 E272 multiple spaces before keyword
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   317
        if self.VariableType == "STRING" and value.startswith("'") and value.endswith("'") or \
1766
c1e5b9f19483 clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   318
           self.VariableType == "WSTRING" and value.startswith('"') and value.endswith('"'):
892
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
   319
            value = value[1:-1]
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   320
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   321
        # Store variable value
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   322
        if self.Value != value:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   323
            self.Value = value
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   324
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   325
            # Signal to debug variable panel to refresh
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   326
            self.Parent.HasNewData = True
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   327
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   328
    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
   329
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   330
        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
   331
        @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
   332
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   333
        # 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
   334
        if tick is not None and self.Data is not None:
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   335
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   336
            # Return current value and forced flag if data empty
2741
3cc5663af196 IDE: Cleaned up some useless tests in variable trace data handling code, changed from bare numpy arrays to RingBuffers inorder to avoid RAM outage and crash after long tracing session.
Edouard Tisserant
parents: 1966
diff changeset
   337
            if self.Data.count == 0:
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   338
                return self.Value, self.IsForced()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   339
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   340
            # 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
   341
            idx = self.GetNearestData(tick, 0)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   342
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   343
            # Get value and forced flag at given index
1767
c74815729afd clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
   344
            value, forced = \
2741
3cc5663af196 IDE: Cleaned up some useless tests in variable trace data handling code, changed from bare numpy arrays to RingBuffers inorder to avoid RAM outage and crash after long tracing session.
Edouard Tisserant
parents: 1966
diff changeset
   345
                self.RawData[int(self.Data.view[idx, 2])] \
1767
c74815729afd clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
   346
                if self.VariableType in ["STRING", "WSTRING"] \
2741
3cc5663af196 IDE: Cleaned up some useless tests in variable trace data handling code, changed from bare numpy arrays to RingBuffers inorder to avoid RAM outage and crash after long tracing session.
Edouard Tisserant
parents: 1966
diff changeset
   347
                else self.Data.view[idx, 1:3]
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   348
1962
f41dc3829af6 fix display TIME type variables in debug variable panel
Surkov Sergey <surkovsv93@gmail.com>
parents: 1881
diff changeset
   349
            if self.VariableType in ["TIME", "TOD", "DT", "DATE"]:
f41dc3829af6 fix display TIME type variables in debug variable panel
Surkov Sergey <surkovsv93@gmail.com>
parents: 1881
diff changeset
   350
                value = timedelta(seconds=value)
f41dc3829af6 fix display TIME type variables in debug variable panel
Surkov Sergey <surkovsv93@gmail.com>
parents: 1881
diff changeset
   351
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   352
            # Get raw value if asked
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   353
            if not raw:
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   354
                value = TYPE_TRANSLATOR.get(
1878
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
   355
                    self.VariableType, str)(value)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   356
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   357
            return value, forced
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   358
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   359
        # Return raw value if asked
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   360
        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
   361
            return TYPE_TRANSLATOR.get(
1878
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
   362
                self.VariableType, str)(self.Value)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   363
        return self.Value
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   364
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   365
    def GetNearestData(self, tick, adjust):
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   366
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   367
        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
   368
        @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
   369
        @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
   370
                       -1: older than tick
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   371
                       1:  newer than tick
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   372
                       0:  doesn't matter
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   373
        @return: Index of nearest data
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   374
        """
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   375
        # Return immediately if data is empty
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   376
        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
   377
            return None
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   378
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   379
        # Extract data ticks
2741
3cc5663af196 IDE: Cleaned up some useless tests in variable trace data handling code, changed from bare numpy arrays to RingBuffers inorder to avoid RAM outage and crash after long tracing session.
Edouard Tisserant
parents: 1966
diff changeset
   380
        ticks = self.Data.view[:, 0]
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   381
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   382
        # Get nearest data from tick
2742
5f7445b582d4 IDE: Fixed variable traces graphs RingBuffers. Removed an apparently useless wxCallAfter in trend graph that was leading to pydeadobject exception on wxGTK when double-clicking.
Edouard Tisserant
parents: 2741
diff changeset
   383
        idx = min(np.searchsorted(ticks, tick), self.Data.count - 1)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   384
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   385
        # Adjust data index according to constraint
1766
c1e5b9f19483 clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   386
        if adjust < 0 and ticks[idx] > tick and idx > 0 or \
c1e5b9f19483 clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   387
           adjust > 0 and ticks[idx] < tick and idx < len(ticks):
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   388
            idx += adjust
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   389
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1192
diff changeset
   390
        return idx