graphics/GraphicCommons.py
changeset 1544 2969c2123105
parent 1377 cc8f9177d41c
child 1571 486f94a8032c
equal deleted inserted replaced
1543:61f0f31ef296 1544:2969c2123105
  1349     def SetEdge(self, edge):
  1349     def SetEdge(self, edge):
  1350         if self.ParentBlock.IsOfType("BOOL", self.Type):
  1350         if self.ParentBlock.IsOfType("BOOL", self.Type):
  1351             self.Edge = edge    
  1351             self.Edge = edge    
  1352             self.Negated = False
  1352             self.Negated = False
  1353     
  1353     
       
  1354     # assume that pointer is already inside of this connector
       
  1355     def ConnectionAvailable(self, direction=None, exclude=True):
       
  1356         wire_nums = len(self.Wires)
       
  1357         
       
  1358         connector_free = (wire_nums<= 0)
       
  1359         connector_max_used = ((wire_nums > 0) and self.OneConnected)
       
  1360         if (self.Parent.CurrentLanguage in ["SFC", "LD"]) and (self.Type == "BOOL"):
       
  1361             connector_max_used = False;
       
  1362 
       
  1363         # connector is available for new connection
       
  1364         connect  = connector_free or not connector_max_used
       
  1365         return connect, connector_max_used
       
  1366                            
  1354     # Tests if the point given is near from the end point of this connector
  1367     # Tests if the point given is near from the end point of this connector
  1355     def TestPoint(self, pt, direction = None, exclude = True):
  1368     def TestPoint(self, pt, direction=None, exclude=True):
  1356         parent_pos = self.ParentBlock.GetPosition()
  1369         inside = False;
  1357         if (not (len(self.Wires) > 0 and self.OneConnected and exclude) or self.Type == "BOOL")\
  1370         check_point = (not exclude) and (direction is None or self.Direction == direction);
  1358             and direction is None or self.Direction == direction:
  1371 
       
  1372         if check_point:
  1359             # Calculate a square around the end point of this connector
  1373             # Calculate a square around the end point of this connector
       
  1374             parent_pos = self.ParentBlock.GetPosition()
  1360             x = parent_pos[0] + self.Pos.x + self.Direction[0] * CONNECTOR_SIZE - ANCHOR_DISTANCE
  1375             x = parent_pos[0] + self.Pos.x + self.Direction[0] * CONNECTOR_SIZE - ANCHOR_DISTANCE
  1361             y = parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE - ANCHOR_DISTANCE
  1376             y = parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE - ANCHOR_DISTANCE
  1362             width = ANCHOR_DISTANCE * 2 + abs(self.Direction[0]) * CONNECTOR_SIZE
  1377             width = ANCHOR_DISTANCE * 2 + abs(self.Direction[0]) * CONNECTOR_SIZE
  1363             height = ANCHOR_DISTANCE * 2 + abs(self.Direction[1]) * CONNECTOR_SIZE
  1378             height = ANCHOR_DISTANCE * 2 + abs(self.Direction[1]) * CONNECTOR_SIZE
  1364             rect = wx.Rect(x, y, width, height)
  1379             rect = wx.Rect(x, y, width, height)
  1365             return rect.InsideXY(pt.x, pt.y)
  1380             inside = rect.InsideXY(pt.x, pt.y);
  1366         return False
  1381                            
       
  1382         return inside
  1367     
  1383     
  1368     # Draws the highlightment of this element if it is highlighted
  1384     # Draws the highlightment of this element if it is highlighted
  1369     def DrawHighlightment(self, dc):
  1385     def DrawHighlightment(self, dc):
  1370         scalex, scaley = dc.GetUserScale()
  1386         scalex, scaley = dc.GetUserScale()
  1371         dc.SetUserScale(1, 1)
  1387         dc.SetUserScale(1, 1)
  1549         self.ComputedValue = None
  1565         self.ComputedValue = None
  1550         self.OverStart = False
  1566         self.OverStart = False
  1551         self.OverEnd = False
  1567         self.OverEnd = False
  1552         self.ComputingType = False
  1568         self.ComputingType = False
  1553         self.Font = parent.GetMiniFont()
  1569         self.Font = parent.GetMiniFont()
       
  1570         self.ErrHighlight = False
  1554     
  1571     
  1555     def GetDefinition(self):
  1572     def GetDefinition(self):
  1556         if self.StartConnected is not None and self.EndConnected is not None:
  1573         if self.StartConnected is not None and self.EndConnected is not None:
  1557             startblock = self.StartConnected.GetParentBlock()
  1574             startblock = self.StartConnected.GetParentBlock()
  1558             endblock = self.EndConnected.GetParentBlock()
  1575             endblock = self.EndConnected.GetParentBlock()
  2588     
  2605     
  2589     # Draws the highlightment of this element if it is highlighted
  2606     # Draws the highlightment of this element if it is highlighted
  2590     def DrawHighlightment(self, dc):
  2607     def DrawHighlightment(self, dc):
  2591         scalex, scaley = dc.GetUserScale()
  2608         scalex, scaley = dc.GetUserScale()
  2592         dc.SetUserScale(1, 1)
  2609         dc.SetUserScale(1, 1)
  2593         dc.SetPen(MiterPen(HIGHLIGHTCOLOR, (2 * scalex + 5)))
  2610         # If user trying to connect wire with wrong input, highlight will become red.
  2594         dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR))
  2611         if self.ErrHighlight == True and not (self.EndConnected):
       
  2612             highlightcolor = wx.RED
       
  2613         else:
       
  2614             highlightcolor = HIGHLIGHTCOLOR
       
  2615         dc.SetPen(MiterPen(highlightcolor, (2 * scalex + 5)))
       
  2616         dc.SetBrush(wx.Brush(highlightcolor))
  2595         dc.SetLogicalFunction(wx.AND)
  2617         dc.SetLogicalFunction(wx.AND)
  2596         # Draw the start and end points if they are not connected or the mouse is over them
  2618         # Draw the start and end points if they are not connected or the mouse is over them
  2597         if len(self.Points) > 0 and (not self.StartConnected or self.OverStart):
  2619         if len(self.Points) > 0 and (not self.StartConnected or self.OverStart):
  2598             dc.DrawCircle(round(self.Points[0].x * scalex), 
  2620             dc.DrawCircle(round(self.Points[0].x * scalex), 
  2599                           round(self.Points[0].y * scaley), 
  2621                           round(self.Points[0].y * scaley),