graphics/RubberBand.py
author mjsousa
Wed, 21 Oct 2015 15:00:32 +0100
changeset 1475 de4ee16f7c6c
parent 1273 921858d68a13
child 1571 486f94a8032c
permissions -rw-r--r--
merge
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     1
#!/usr/bin/env python
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     3
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     5
#based on the plcopen standard. 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     6
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     8
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     9
#See COPYING file for copyrights details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    10
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    15
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    19
#General Public License for more details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    20
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    24
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:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    38
    
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
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    45
        
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
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    48
        
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    49
        self.Reset()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    50
    
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
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    58
    
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
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    65
    
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
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    76
    
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)
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    88
        
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)
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    91
        
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))
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
    95
        
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    96
        self.Redraw()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    97
    
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)
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   109
        
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)
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   113
        
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
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
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   119
        
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   120
        self.Redraw()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   121
    
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)
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
        # 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
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   136
        
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   137
        self.Redraw()
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   138
    
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
        """
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   141
        Draw a list of bounding box on Viewer in the order given using XOR 
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()
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   149
        
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)
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   154
        
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)
1173
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   159
        
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(
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   164
                    bbox.x * scalex, bbox.y * scaley, 
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
diff changeset
   165
                    bbox.width * scalex, bbox.height * scaley)
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
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)
921858d68a13 Fix refresh bug when scrolling Viewer while dragging graphic element or rubberband
Laurent Bessard
parents: 1173
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)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
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)
ad09b4a755ce Move RubberBand from GraphicCommons to individual file
Laurent Bessard
parents: 1170
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)