--- a/editors/Viewer.py Fri Oct 14 18:04:22 2016 +0300
+++ b/editors/Viewer.py Tue Oct 18 17:44:08 2016 +0300
@@ -1462,12 +1462,20 @@
def FindBlockConnector(self, pos, direction = None, exclude = None):
+ result, error = self.FindBlockConnectorWithError(pos, direction, exclude) + def FindBlockConnectorWithError(self, pos, direction = None, exclude = None): for block in self.Blocks.itervalues():
- result = block.TestConnector(pos, direction, exclude)
+ connector = block.TestConnector(pos, direction, exclude) + avail, error = connector.ConnectionAvailable(direction, exclude) + return connector, error def FindElementById(self, id):
block = self.Blocks.get(id, None)
@@ -2273,7 +2281,8 @@
self.rubberBand.OnMotion(event, dc, self.Scaling)
elif not self.Debug and self.Mode == MODE_SELECTION and self.SelectedElement is not None:
- connector = self.FindBlockConnector(pos, self.SelectedElement.GetConnectionDirection(), self.SelectedElement.EndConnected)
+ connector, errorHighlight = self.FindBlockConnectorWithError(pos, self.SelectedElement.GetConnectionDirection(), self.SelectedElement.EndConnected) + self.SelectedElement.ErrHighlight = errorHighlight; if not connector or self.SelectedElement.EndConnected == None:
self.SelectedElement.ResetPoints()
movex, movey = self.SelectedElement.OnMotion(event, dc, self.Scaling)
--- a/graphics/GraphicCommons.py Fri Oct 14 18:04:22 2016 +0300
+++ b/graphics/GraphicCommons.py Tue Oct 18 17:44:08 2016 +0300
@@ -1351,19 +1351,35 @@
+ # 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): + check_point = (not exclude) and (direction is None or self.Direction == direction); # 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)
+ inside = rect.InsideXY(pt.x, pt.y); # Draws the highlightment of this element if it is highlighted
def DrawHighlightment(self, dc):
@@ -1551,6 +1567,7 @@
self.ComputingType = False
self.Font = parent.GetMiniFont()
+ self.ErrHighlight = False 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.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 + 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):