graphics/RubberBand.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Thu, 28 Sep 2017 12:20:40 +0300
changeset 1831 56b48961cc68
parent 1782 5b6ad7a7fd9d
child 1881 091005ec69c4
permissions -rw-r--r--
fix (old-style-class) Old-style class defined error for most parts of
the code

only PyJS code is left, because it does some fancy tricks and can't be
easily fixed. So far PyJS doesn't support Python3 anyway.
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: 1273
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: 1273
diff changeset
     5
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     6
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1273
diff changeset
     7
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     8
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1273
diff changeset
     9
# See COPYING file for copyrights details.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    10
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1273
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: 1273
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: 1273
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: 1273
diff changeset
    14
# of the License, or (at your option) any later version.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    15
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1273
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: 1273
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: 1273
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: 1273
diff changeset
    19
# GNU General Public License for more details.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    20
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1273
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: 1273
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: 1273
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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    25
import wx
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    26
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    27
from graphics.GraphicCommons import GetScaledEventPosition
1169
53e4a2b775a7 Move CustomToolTip from GraphicCommons to controls
Laurent Bessard
parents: 1166
diff changeset
    28
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
    29
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
    30
# -------------------------------------------------------------------------------
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    31
#                               Viewer RubberBand
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
    32
# -------------------------------------------------------------------------------
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    33
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    34
1831
56b48961cc68 fix (old-style-class) Old-style class defined error for most parts of
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    35
class RubberBand(object):
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    36
    """
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    37
    Class that implements a rubberband for graphic Viewers
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    38
    """
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    39
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    40
    def __init__(self, viewer):
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    41
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    42
        Constructor
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    43
        @param viewer: Viewer on which rubberband must be drawn
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    44
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    45
        self.Viewer = viewer
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    46
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    47
        # wx.Panel on which rubberband will be drawn
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    48
        self.DrawingSurface = viewer.Editor
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    49
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    50
        self.Reset()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    51
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    52
    def Reset(self):
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    53
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    54
        Initialize internal attributes of rubberband
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    55
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    56
        self.StartPoint = None
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    57
        self.CurrentBBox = None
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    58
        self.LastBBox = None
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    59
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    60
    def IsShown(self):
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    61
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    62
        Indicate if rubberband is drawn on viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    63
        @return: True if rubberband is drawn
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    64
        """
1743
c3c3d1318130 clean-up: fix PEP8 E711 comparison to None should be 'if cond is not None:'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
    65
        return self.CurrentBBox is not None
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    66
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    67
    def GetCurrentExtent(self):
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    68
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    69
        Return the rubberband bounding box
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    70
        @return: Rubberband bounding box (wx.Rect object)
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    71
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    72
        # In case of rubberband not shown, return the last rubberband
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    73
        # bounding box
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    74
        if self.IsShown():
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    75
            return self.CurrentBBox
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    76
        return self.LastBBox
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    77
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    78
    def OnLeftDown(self, event, dc, scaling):
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    79
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    80
        Called when left mouse is pressed on Viewer. Starts to edit a new
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    81
        rubberband bounding box
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    82
        @param event: Mouse event
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    83
        @param dc: Device Context of Viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    84
        @param scaling: PLCOpen scaling applied on Viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    85
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    86
        # Save the point where mouse was pressed in Viewer unit, position may
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    87
        # be modified by scroll and zoom applied on viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    88
        self.StartPoint = GetScaledEventPosition(event, dc, scaling)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    89
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    90
        # Initialize rubberband bounding box
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    91
        self.CurrentBBox = wx.Rect(self.StartPoint.x, self.StartPoint.y, 0, 0)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    92
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    93
        # Change viewer mouse cursor to reflect a rubberband bounding box is
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    94
        # edited
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    95
        self.DrawingSurface.SetCursor(wx.StockCursor(wx.CURSOR_CROSS))
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    96
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    97
        self.Redraw()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    98
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    99
    def OnMotion(self, event, dc, scaling):
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   100
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   101
        Called when mouse is dragging over Viewer. Update the current edited
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   102
        rubberband bounding box
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   103
        @param event: Mouse event
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   104
        @param dc: Device Context of Viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   105
        @param scaling: PLCOpen scaling applied on Viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   106
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   107
        # Get mouse position in Viewer unit, position may be modified by scroll
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   108
        # and zoom applied on viewer
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   109
        pos = GetScaledEventPosition(event, dc, scaling)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   110
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   111
        # Save the last bounding box drawn for erasing it later
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   112
        self.LastBBox = wx.Rect(0, 0, 0, 0)
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   113
        self.LastBBox.Union(self.CurrentBBox)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   114
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   115
        # Calculate new position and size of the box
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   116
        self.CurrentBBox.x = min(pos.x, self.StartPoint.x)
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   117
        self.CurrentBBox.y = min(pos.y, self.StartPoint.y)
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   118
        self.CurrentBBox.width = abs(pos.x - self.StartPoint.x) + 1
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   119
        self.CurrentBBox.height = abs(pos.y - self.StartPoint.y) + 1
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   120
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   121
        self.Redraw()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   122
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   123
    def OnLeftUp(self, event, dc, scaling):
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   124
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   125
        Called when mouse is release from Viewer. Erase the current edited
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   126
        rubberband bounding box
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   127
        @param event: Mouse event
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   128
        @param dc: Device Context of Viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   129
        @param scaling: PLCOpen scaling applied on Viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   130
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   131
        # Change viewer mouse cursor to default
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   132
        self.DrawingSurface.SetCursor(wx.NullCursor)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   133
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   134
        # Save the last edited bounding box
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   135
        self.LastBBox = self.CurrentBBox
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   136
        self.CurrentBBox = None
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   137
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   138
        self.Redraw()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   139
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   140
    def DrawBoundingBoxes(self, bboxes, dc=None):
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   141
        """
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   142
        Draw a list of bounding box on Viewer in the order given using XOR
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   143
        logical function
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   144
        @param bboxes: List of bounding boxes to draw on viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   145
        @param dc: Device Context of Viewer (default None)
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   146
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   147
        # Get viewer Device Context if not given
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   148
        if dc is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   149
            dc = self.Viewer.GetLogicalDC()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   150
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   151
        # Save current viewer scale factors before resetting them in order to
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   152
        # avoid rubberband pen to be scaled
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   153
        scalex, scaley = dc.GetUserScale()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   154
        dc.SetUserScale(1, 1)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   155
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   156
        # Set DC drawing style
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   157
        dc.SetPen(wx.Pen(wx.WHITE, style=wx.DOT))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   158
        dc.SetBrush(wx.TRANSPARENT_BRUSH)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   159
        dc.SetLogicalFunction(wx.XOR)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   160
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   161
        # Draw the bounding boxes using viewer scale factor
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   162
        for bbox in bboxes:
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   163
            if bbox is not None:
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   164
                dc.DrawRectangle(
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   165
                    bbox.x * scalex, bbox.y * scaley,
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   166
                    bbox.width * scalex, bbox.height * scaley)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   167
1273
921858d68a13 Fix refresh bug when scrolling Viewer while dragging graphic element or rubberband
Laurent Bessard
parents: 1173
diff changeset
   168
        dc.SetLogicalFunction(wx.COPY)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   169
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   170
        # Restore Viewer scale factor
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   171
        dc.SetUserScale(scalex, scaley)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   172
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   173
    def Redraw(self, dc=None):
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   174
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   175
        Redraw rubberband on Viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   176
        @param dc: Device Context of Viewer (default None)
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   177
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   178
        # Erase last bbox and draw current bbox
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   179
        self.DrawBoundingBoxes([self.LastBBox, self.CurrentBBox], dc)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   180
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   181
    def Erase(self, dc=None):
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   182
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   183
        Erase rubberband from Viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   184
        @param dc: Device Context of Viewer (default None)
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   185
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   186
        # Erase last bbox
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   187
        self.DrawBoundingBoxes([self.LastBBox], dc)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   188
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   189
    def Draw(self, dc=None):
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   190
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   191
        Draw rubberband on Viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   192
        @param dc: Device Context of Viewer (default None)
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   193
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   194
        # Erase last bbox and draw current bbox
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   195
        self.DrawBoundingBoxes([self.CurrentBBox], dc)