graphics/RubberBand.py
author Edouard Tisserant
Fri, 21 Aug 2020 14:29:03 +0200
branchsvghmi
changeset 3034 793ce2117258
parent 1881 091005ec69c4
child 3303 0ffb41625592
permissions -rw-r--r--
SVGHMI: JsonTable now makes meaningfull JSON request : all arguments and variables are passed in.
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
1881
091005ec69c4 fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1831
diff changeset
    25
091005ec69c4 fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1831
diff changeset
    26
from __future__ import absolute_import
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    27
import wx
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    28
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    29
from graphics.GraphicCommons import GetScaledEventPosition
1169
53e4a2b775a7 Move CustomToolTip from GraphicCommons to controls
Laurent Bessard
parents: 1166
diff changeset
    30
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
    31
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
    32
# -------------------------------------------------------------------------------
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    33
#                               Viewer RubberBand
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
    34
# -------------------------------------------------------------------------------
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
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
    37
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
    38
    """
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    39
    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
    40
    """
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    41
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    42
    def __init__(self, viewer):
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    43
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    44
        Constructor
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    45
        @param viewer: Viewer on which rubberband must be drawn
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    46
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    47
        self.Viewer = viewer
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    48
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    49
        # wx.Panel on which rubberband will be drawn
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    50
        self.DrawingSurface = viewer.Editor
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
        self.Reset()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    53
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    54
    def Reset(self):
1173
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
        Initialize internal attributes of rubberband
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    57
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    58
        self.StartPoint = None
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    59
        self.CurrentBBox = None
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    60
        self.LastBBox = None
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    61
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    62
    def IsShown(self):
1173
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
        Indicate if rubberband is drawn on viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    65
        @return: True if rubberband is drawn
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    66
        """
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
    67
        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
    68
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    69
    def GetCurrentExtent(self):
1173
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
        Return the rubberband bounding box
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    72
        @return: Rubberband bounding box (wx.Rect object)
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    73
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    74
        # In case of rubberband not shown, return the last rubberband
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    75
        # bounding box
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    76
        if self.IsShown():
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    77
            return self.CurrentBBox
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    78
        return self.LastBBox
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    79
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    80
    def OnLeftDown(self, event, dc, scaling):
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    81
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    82
        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
    83
        rubberband bounding box
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    84
        @param event: Mouse event
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    85
        @param dc: Device Context of Viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    86
        @param scaling: PLCOpen scaling applied on Viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    87
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    88
        # 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
    89
        # be modified by scroll and zoom applied on viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    90
        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
    91
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    92
        # Initialize rubberband bounding box
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    93
        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
    94
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    95
        # 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
    96
        # edited
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    97
        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
    98
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    99
        self.Redraw()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   100
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   101
    def OnMotion(self, event, dc, scaling):
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   102
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   103
        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
   104
        rubberband bounding box
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   105
        @param event: Mouse event
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   106
        @param dc: Device Context of Viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   107
        @param scaling: PLCOpen scaling applied on Viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   108
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   109
        # 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
   110
        # and zoom applied on viewer
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   111
        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
   112
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   113
        # Save the last bounding box drawn for erasing it later
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   114
        self.LastBBox = wx.Rect(0, 0, 0, 0)
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   115
        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
   116
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   117
        # Calculate new position and size of the box
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   118
        self.CurrentBBox.x = min(pos.x, self.StartPoint.x)
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   119
        self.CurrentBBox.y = min(pos.y, self.StartPoint.y)
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   120
        self.CurrentBBox.width = abs(pos.x - self.StartPoint.x) + 1
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   121
        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
   122
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   123
        self.Redraw()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   124
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   125
    def OnLeftUp(self, event, dc, scaling):
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   126
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   127
        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
   128
        rubberband bounding box
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   129
        @param event: Mouse event
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   130
        @param dc: Device Context of Viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   131
        @param scaling: PLCOpen scaling applied on Viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   132
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   133
        # Change viewer mouse cursor to default
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   134
        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
   135
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   136
        # Save the last edited bounding box
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   137
        self.LastBBox = self.CurrentBBox
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   138
        self.CurrentBBox = None
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   139
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   140
        self.Redraw()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   141
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   142
    def DrawBoundingBoxes(self, bboxes, dc=None):
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   143
        """
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   144
        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
   145
        logical function
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   146
        @param bboxes: List of bounding boxes to draw on viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   147
        @param dc: Device Context of Viewer (default None)
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   148
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   149
        # Get viewer Device Context if not given
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   150
        if dc is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   151
            dc = self.Viewer.GetLogicalDC()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   152
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   153
        # 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
   154
        # avoid rubberband pen to be scaled
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   155
        scalex, scaley = dc.GetUserScale()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   156
        dc.SetUserScale(1, 1)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   157
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   158
        # Set DC drawing style
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   159
        dc.SetPen(wx.Pen(wx.WHITE, style=wx.DOT))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   160
        dc.SetBrush(wx.TRANSPARENT_BRUSH)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   161
        dc.SetLogicalFunction(wx.XOR)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   162
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   163
        # Draw the bounding boxes using viewer scale factor
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   164
        for bbox in bboxes:
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   165
            if bbox is not None:
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   166
                dc.DrawRectangle(
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   167
                    bbox.x * scalex, bbox.y * scaley,
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   168
                    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
   169
1273
921858d68a13 Fix refresh bug when scrolling Viewer while dragging graphic element or rubberband
Laurent Bessard
parents: 1173
diff changeset
   170
        dc.SetLogicalFunction(wx.COPY)
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
        # Restore Viewer scale factor
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   173
        dc.SetUserScale(scalex, scaley)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   174
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   175
    def Redraw(self, dc=None):
1173
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
        Redraw rubberband on Viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   178
        @param dc: Device Context of Viewer (default None)
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   179
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   180
        # Erase last bbox and draw current bbox
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   181
        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
   182
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   183
    def Erase(self, dc=None):
1173
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 rubberband from Viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   186
        @param dc: Device Context of Viewer (default None)
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   187
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   188
        # Erase last bbox
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   189
        self.DrawBoundingBoxes([self.LastBBox], dc)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   190
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   191
    def Draw(self, dc=None):
1173
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
        Draw rubberband on Viewer
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   194
        @param dc: Device Context of Viewer (default None)
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   195
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   196
        # Erase last bbox and draw current bbox
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   197
        self.DrawBoundingBoxes([self.CurrentBBox], dc)