diff -r a375e31bf312 -r c1298e7ffe3a graphics/GraphicCommons.py --- a/graphics/GraphicCommons.py Sun Mar 05 00:38:25 2017 +0000 +++ b/graphics/GraphicCommons.py Fri Mar 24 12:07:47 2017 +0000 @@ -1,26 +1,26 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor -#based on the plcopen standard. +# This file is part of Beremiz, a Integrated Development Environment for +# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. # -#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD +# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD # -#See COPYING file for copyrights details. +# See COPYING file for copyrights details. # -#This library is free software; you can redistribute it and/or -#modify it under the terms of the GNU General Public -#License as published by the Free Software Foundation; either -#version 2.1 of the License, or (at your option) any later version. +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. # -#This library is distributed in the hope that it will be useful, -#but WITHOUT ANY WARRANTY; without even the implied warranty of -#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -#General Public License for more details. +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # -#You should have received a copy of the GNU General Public -#License along with this library; if not, write to the Free Software -#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. import wx from math import * @@ -1351,19 +1351,35 @@ self.Edge = edge self.Negated = False + # assume that pointer is already inside of this connector + def ConnectionAvailable(self, direction=None, exclude=True): + wire_nums = len(self.Wires) + + connector_free = (wire_nums<= 0) + connector_max_used = ((wire_nums > 0) and self.OneConnected) + if (self.Parent.CurrentLanguage in ["SFC", "LD"]) and (self.Type == "BOOL"): + connector_max_used = False; + + # connector is available for new connection + connect = connector_free or not connector_max_used + return connect, connector_max_used + # Tests if the point given is near from the end point of this connector - def TestPoint(self, pt, direction = None, exclude = True): - parent_pos = self.ParentBlock.GetPosition() - if (not (len(self.Wires) > 0 and self.OneConnected and exclude) or self.Type == "BOOL")\ - and direction is None or self.Direction == direction: + def TestPoint(self, pt, direction=None, exclude=True): + inside = False; + check_point = (not exclude) and (direction is None or self.Direction == direction); + + if check_point: # Calculate a square around the end point of this connector + parent_pos = self.ParentBlock.GetPosition() x = parent_pos[0] + self.Pos.x + self.Direction[0] * CONNECTOR_SIZE - ANCHOR_DISTANCE y = parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE - ANCHOR_DISTANCE width = ANCHOR_DISTANCE * 2 + abs(self.Direction[0]) * CONNECTOR_SIZE height = ANCHOR_DISTANCE * 2 + abs(self.Direction[1]) * CONNECTOR_SIZE rect = wx.Rect(x, y, width, height) - return rect.InsideXY(pt.x, pt.y) - return False + inside = rect.InsideXY(pt.x, pt.y); + + return inside # Draws the highlightment of this element if it is highlighted def DrawHighlightment(self, dc): @@ -1551,6 +1567,7 @@ self.OverEnd = False self.ComputingType = False self.Font = parent.GetMiniFont() + self.ErrHighlight = False def GetDefinition(self): if self.StartConnected is not None and self.EndConnected is not None: @@ -2590,8 +2607,13 @@ def DrawHighlightment(self, dc): scalex, scaley = dc.GetUserScale() dc.SetUserScale(1, 1) - dc.SetPen(MiterPen(HIGHLIGHTCOLOR, (2 * scalex + 5))) - dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR)) + # If user trying to connect wire with wrong input, highlight will become red. + if self.ErrHighlight == True and not (self.EndConnected): + highlightcolor = wx.RED + else: + highlightcolor = HIGHLIGHTCOLOR + dc.SetPen(MiterPen(highlightcolor, (2 * scalex + 5))) + dc.SetBrush(wx.Brush(highlightcolor)) dc.SetLogicalFunction(wx.AND) # Draw the start and end points if they are not connected or the mouse is over them if len(self.Points) > 0 and (not self.StartConnected or self.OverStart): @@ -2873,10 +2895,15 @@ wx.Point(self.Pos.x + self.Size[0], self.Pos.y + self.Size[1]), wx.Point(self.Pos.x, self.Pos.y + self.Size[1])] dc.DrawPolygon(polygon) + + # dc.SetBrush call is workaround for the issue with wx.PrinterDC + # with wxPython 3.0 on GNU/Linux (don't remove it) + dc.SetBrush(wx.WHITE_BRUSH) lines = [wx.Point(self.Pos.x + self.Size[0] - 10, self.Pos.y), wx.Point(self.Pos.x + self.Size[0] - 10, self.Pos.y + 10), wx.Point(self.Pos.x + self.Size[0], self.Pos.y + 10)] dc.DrawLines(lines) + # Draws the comment content y = self.Pos.y + 10 for idx, line in enumerate(self.Content.splitlines()):