graphics/GraphicCommons.py
changeset 243 c5da8b706cde
parent 237 097e8ee006cb
child 249 d8425712acef
equal deleted inserted replaced
242:5b3e1c4569e6 243:c5da8b706cde
  1101         if self.ParentBlock.IsOfType("BOOL", self.Type):
  1101         if self.ParentBlock.IsOfType("BOOL", self.Type):
  1102             self.Edge = edge    
  1102             self.Edge = edge    
  1103             self.Negated = False
  1103             self.Negated = False
  1104     
  1104     
  1105     # Tests if the point given is near from the end point of this connector
  1105     # Tests if the point given is near from the end point of this connector
  1106     def TestPoint(self, pt, exclude = True):
  1106     def TestPoint(self, pt, direction = None, exclude = True):
  1107         parent_pos = self.ParentBlock.GetPosition()
  1107         parent_pos = self.ParentBlock.GetPosition()
  1108         if not (len(self.Wires) > 0 and self.OneConnected and exclude):
  1108         if not (len(self.Wires) > 0 and self.OneConnected and exclude):
  1109             # Calculate a square around the end point of this connector
  1109             if direction is None or self.Direction == direction:
  1110             x = parent_pos[0] + self.Pos.x + self.Direction[0] * CONNECTOR_SIZE - ANCHOR_DISTANCE
  1110                 # Calculate a square around the end point of this connector
  1111             y = parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE - ANCHOR_DISTANCE
  1111                 x = parent_pos[0] + self.Pos.x + self.Direction[0] * CONNECTOR_SIZE - ANCHOR_DISTANCE
  1112             width = ANCHOR_DISTANCE * 2 + abs(self.Direction[0]) * CONNECTOR_SIZE
  1112                 y = parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE - ANCHOR_DISTANCE
  1113             height = ANCHOR_DISTANCE * 2 + abs(self.Direction[1]) * CONNECTOR_SIZE
  1113                 width = ANCHOR_DISTANCE * 2 + abs(self.Direction[0]) * CONNECTOR_SIZE
  1114             rect = wx.Rect(x, y, width, height)
  1114                 height = ANCHOR_DISTANCE * 2 + abs(self.Direction[1]) * CONNECTOR_SIZE
  1115             return rect.InsideXY(pt.x, pt.y)
  1115                 rect = wx.Rect(x, y, width, height)
       
  1116                 return rect.InsideXY(pt.x, pt.y)
  1116         return False
  1117         return False
  1117     
  1118     
  1118     # Draws the highlightment of this element if it is highlighted
  1119     # Draws the highlightment of this element if it is highlighted
  1119     def DrawHighlightment(self, dc):
  1120     def DrawHighlightment(self, dc):
  1120         dc.SetPen(wx.Pen(HIGHLIGHTCOLOR))
  1121         dc.SetPen(wx.Pen(HIGHLIGHTCOLOR))
  1273         if self.EndConnected and not self.ComputingType:
  1274         if self.EndConnected and not self.ComputingType:
  1274             self.ComputingType = True
  1275             self.ComputingType = True
  1275             computed_type = self.EndConnected.GetType()
  1276             computed_type = self.EndConnected.GetType()
  1276             self.ComputingType = False
  1277             self.ComputingType = False
  1277             return computed_type
  1278             return computed_type
       
  1279         return None
       
  1280     
       
  1281     def GetConnectionDirection(self):
       
  1282         if self.StartConnected is None and self.EndConnected is None:
       
  1283             return None
       
  1284         elif self.StartConnected is not None and self.EndConnected is None:
       
  1285             return (-self.StartPoint[1][0], -self.StartPoint[1][1])
       
  1286         elif self.StartConnected is None and self.EndConnected is not None:
       
  1287             return self.EndPoint
       
  1288         elif self.Handle is not None:
       
  1289             handle_type, handle = self.Handle
       
  1290             # A point has been handled
       
  1291             if handle_type == HANDLE_POINT:
       
  1292                 if handle == 0:
       
  1293                     return self.EndPoint
       
  1294                 else:
       
  1295                     return (-self.StartPoint[1][0], -self.StartPoint[1][1])
  1278         return None
  1296         return None
  1279     
  1297     
  1280     def GetOtherConnected(self, connector):
  1298     def GetOtherConnected(self, connector):
  1281         if self.StartConnected == connector:
  1299         if self.StartConnected == connector:
  1282             return self.EndConnected
  1300             return self.EndConnected
  1996             if scaling is not None:
  2014             if scaling is not None:
  1997                 movex = round(float(self.Points[handle].x + movex) / float(scaling[0])) * scaling[0] - self.Points[handle].x
  2015                 movex = round(float(self.Points[handle].x + movex) / float(scaling[0])) * scaling[0] - self.Points[handle].x
  1998                 movey = round(float(self.Points[handle].y + movey) / float(scaling[1])) * scaling[1] - self.Points[handle].y
  2016                 movey = round(float(self.Points[handle].y + movey) / float(scaling[1])) * scaling[1] - self.Points[handle].y
  1999             # Try to connect point to a connector
  2017             # Try to connect point to a connector
  2000             new_pos = wx.Point(self.Points[handle].x + movex, self.Points[handle].y + movey)
  2018             new_pos = wx.Point(self.Points[handle].x + movex, self.Points[handle].y + movey)
  2001             connector = self.Parent.FindBlockConnector(new_pos)
  2019             connector = self.Parent.FindBlockConnector(new_pos, self.GetConnectionDirection())
  2002             if connector:
  2020             if connector:
  2003                 if handle == 0 and self.EndConnected != connector and connector.IsCompatible(self.GetEndConnectedType()):
  2021                 if handle == 0 and self.EndConnected != connector and connector.IsCompatible(self.GetEndConnectedType()):
  2004                     connector.HighlightParentBlock(True)
  2022                     connector.HighlightParentBlock(True)
  2005                     connector.Connect((self, handle))
  2023                     connector.Connect((self, handle))
  2006                     self.SetStartPointDirection(connector.GetDirection())
  2024                     self.SetStartPointDirection(connector.GetDirection())