graphics/RubberBand.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Mon, 14 Aug 2017 21:20:32 +0300
changeset 1732 94ffe74e6895
parent 1730 64d8f52bc8c8
child 1736 7e61baa047f0
permissions -rw-r--r--
clean-up: fix PEP8 E401 multiple imports on one line
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
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    29
#-------------------------------------------------------------------------------
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    30
#                               Viewer RubberBand
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    31
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    32
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    33
"""
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    34
Class that implements a rubberband for graphic Viewers
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    35
"""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    36
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    37
class RubberBand:
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    38
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    39
    def __init__(self, viewer):
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    40
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    41
        Constructor
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    42
        @param viewer: Viewer on which rubberband must be drawn
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    43
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    44
        self.Viewer = viewer
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    45
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    46
        # wx.Panel on which rubberband will be drawn
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    47
        self.DrawingSurface = viewer.Editor
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    48
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    49
        self.Reset()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    50
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    51
    def Reset(self):
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    52
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    53
        Initialize internal attributes of rubberband
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    54
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    55
        self.StartPoint = None
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    56
        self.CurrentBBox = None
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    57
        self.LastBBox = None
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
    def IsShown(self):
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    60
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    61
        Indicate if rubberband is drawn on viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    62
        @return: True if rubberband is drawn
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    63
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    64
        return self.CurrentBBox != None
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 GetCurrentExtent(self):
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    67
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    68
        Return the rubberband bounding box
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    69
        @return: Rubberband bounding box (wx.Rect object)
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    70
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    71
        # In case of rubberband not shown, return the last rubberband
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    72
        # bounding box
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    73
        if self.IsShown():
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    74
            return self.CurrentBBox
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    75
        return self.LastBBox
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    76
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    77
    def OnLeftDown(self, event, dc, scaling):
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    78
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    79
        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
    80
        rubberband bounding box
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    81
        @param event: Mouse event
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    82
        @param dc: Device Context of Viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    83
        @param scaling: PLCOpen scaling applied on Viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    84
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    85
        # 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
    86
        # be modified by scroll and zoom applied on viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    87
        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
    88
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    89
        # Initialize rubberband bounding box
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    90
        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
    91
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    92
        # 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
    93
        # edited
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    94
        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
    95
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    96
        self.Redraw()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    97
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    98
    def OnMotion(self, event, dc, scaling):
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    99
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   100
        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
   101
        rubberband bounding box
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   102
        @param event: Mouse event
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   103
        @param dc: Device Context of Viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   104
        @param scaling: PLCOpen scaling applied on Viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   105
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   106
        # 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
   107
        # and zoom applied on viewer
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   108
        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
   109
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   110
        # Save the last bounding box drawn for erasing it later
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   111
        self.LastBBox = wx.Rect(0, 0, 0, 0)
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   112
        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
   113
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   114
        # Calculate new position and size of the box
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   115
        self.CurrentBBox.x = min(pos.x, self.StartPoint.x)
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   116
        self.CurrentBBox.y = min(pos.y, self.StartPoint.y)
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   117
        self.CurrentBBox.width = abs(pos.x - self.StartPoint.x) + 1
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   118
        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
   119
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   120
        self.Redraw()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   121
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   122
    def OnLeftUp(self, event, dc, scaling):
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   123
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   124
        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
   125
        rubberband bounding box
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   126
        @param event: Mouse event
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   127
        @param dc: Device Context of Viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   128
        @param scaling: PLCOpen scaling applied on Viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   129
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   130
        # Change viewer mouse cursor to default
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   131
        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
   132
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   133
        # Save the last edited bounding box
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   134
        self.LastBBox = self.CurrentBBox
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   135
        self.CurrentBBox = None
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   136
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   137
        self.Redraw()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   138
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   139
    def DrawBoundingBoxes(self, bboxes, dc=None):
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   140
        """
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   141
        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
   142
        logical function
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   143
        @param bboxes: List of bounding boxes to draw on viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   144
        @param dc: Device Context of Viewer (default None)
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   145
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   146
        # Get viewer Device Context if not given
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   147
        if dc is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   148
            dc = self.Viewer.GetLogicalDC()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   149
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   150
        # 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
   151
        # avoid rubberband pen to be scaled
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   152
        scalex, scaley = dc.GetUserScale()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   153
        dc.SetUserScale(1, 1)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   154
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   155
        # Set DC drawing style
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   156
        dc.SetPen(wx.Pen(wx.WHITE, style=wx.DOT))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   157
        dc.SetBrush(wx.TRANSPARENT_BRUSH)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   158
        dc.SetLogicalFunction(wx.XOR)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   159
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   160
        # Draw the bounding boxes using viewer scale factor
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   161
        for bbox in bboxes:
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   162
            if bbox is not None:
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   163
                dc.DrawRectangle(
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   164
                    bbox.x * scalex, bbox.y * scaley,
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   165
                    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
   166
1273
921858d68a13 Fix refresh bug when scrolling Viewer while dragging graphic element or rubberband
Laurent Bessard
parents: 1173
diff changeset
   167
        dc.SetLogicalFunction(wx.COPY)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   168
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   169
        # Restore Viewer scale factor
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   170
        dc.SetUserScale(scalex, scaley)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   171
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   172
    def Redraw(self, dc = None):
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   173
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   174
        Redraw rubberband on Viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   175
        @param dc: Device Context of Viewer (default None)
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   176
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   177
        # Erase last bbox and draw current bbox
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   178
        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
   179
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   180
    def Erase(self, dc = None):
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   181
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   182
        Erase rubberband from Viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   183
        @param dc: Device Context of Viewer (default None)
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   184
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   185
        # Erase last bbox
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   186
        self.DrawBoundingBoxes([self.LastBBox], dc)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   187
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   188
    def Draw(self, dc = None):
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   189
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   190
        Draw rubberband on Viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   191
        @param dc: Device Context of Viewer (default None)
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   192
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   193
        # Erase last bbox and draw current bbox
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   194
        self.DrawBoundingBoxes([self.CurrentBBox], dc)