graphics/GraphicCommons.py
branchwxPython4
changeset 3303 0ffb41625592
parent 2625 e5ce6c4a8672
child 3344 4a08728a2ea4
equal deleted inserted replaced
3302:c89fc366bebd 3303:0ffb41625592
   386     def HitTest(self, pt, connectors=True):
   386     def HitTest(self, pt, connectors=True):
   387         if connectors:
   387         if connectors:
   388             rect = self.BoundingBox
   388             rect = self.BoundingBox
   389         else:
   389         else:
   390             rect = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0], self.Size[1])
   390             rect = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0], self.Size[1])
   391         return rect.InsideXY(pt.x, pt.y)
   391         return rect.Contains(pt.x, pt.y)
   392 
   392 
   393     # Returns if the point given is in the bounding box
   393     # Returns if the point given is in the bounding box
   394     def IsInSelection(self, rect):
   394     def IsInSelection(self, rect):
   395         return rect.InsideXY(self.BoundingBox.x, self.BoundingBox.y) and rect.InsideXY(self.BoundingBox.x + self.BoundingBox.width, self.BoundingBox.y + self.BoundingBox.height)
   395         return rect.Contains(self.BoundingBox.x, self.BoundingBox.y) and rect.Contains(self.BoundingBox.x + self.BoundingBox.width, self.BoundingBox.y + self.BoundingBox.height)
   396 
   396 
   397     # Override this method for refreshing the bounding box
   397     # Override this method for refreshing the bounding box
   398     def RefreshBoundingBox(self):
   398     def RefreshBoundingBox(self):
   399         pass
   399         pass
   400 
   400 
   446 
   446 
   447         extern_rect = wx.Rect(left, top, right + HANDLE_SIZE - left, bottom + HANDLE_SIZE - top)
   447         extern_rect = wx.Rect(left, top, right + HANDLE_SIZE - left, bottom + HANDLE_SIZE - top)
   448         intern_rect = wx.Rect(left + HANDLE_SIZE, top + HANDLE_SIZE, right - left - HANDLE_SIZE, bottom - top - HANDLE_SIZE)
   448         intern_rect = wx.Rect(left + HANDLE_SIZE, top + HANDLE_SIZE, right - left - HANDLE_SIZE, bottom - top - HANDLE_SIZE)
   449 
   449 
   450         # Verify that this element is selected
   450         # Verify that this element is selected
   451         if self.Selected and extern_rect.InsideXY(pt.x, pt.y) and not intern_rect.InsideXY(pt.x, pt.y):
   451         if self.Selected and extern_rect.Contains(pt.x, pt.y) and not intern_rect.Contains(pt.x, pt.y):
   452             # Find if point is on a handle horizontally
   452             # Find if point is on a handle horizontally
   453             if left <= pt.x < left + HANDLE_SIZE:
   453             if left <= pt.x < left + HANDLE_SIZE:
   454                 handle_x = 1
   454                 handle_x = 1
   455             elif center <= pt.x < center + HANDLE_SIZE:
   455             elif center <= pt.x < center + HANDLE_SIZE:
   456                 handle_x = 2
   456                 handle_x = 2
  1397             x = parent_pos[0] + self.Pos.x + self.Direction[0] * CONNECTOR_SIZE - ANCHOR_DISTANCE
  1397             x = parent_pos[0] + self.Pos.x + self.Direction[0] * CONNECTOR_SIZE - ANCHOR_DISTANCE
  1398             y = parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE - ANCHOR_DISTANCE
  1398             y = parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE - ANCHOR_DISTANCE
  1399             width = ANCHOR_DISTANCE * 2 + abs(self.Direction[0]) * CONNECTOR_SIZE
  1399             width = ANCHOR_DISTANCE * 2 + abs(self.Direction[0]) * CONNECTOR_SIZE
  1400             height = ANCHOR_DISTANCE * 2 + abs(self.Direction[1]) * CONNECTOR_SIZE
  1400             height = ANCHOR_DISTANCE * 2 + abs(self.Direction[1]) * CONNECTOR_SIZE
  1401             rect = wx.Rect(x, y, width, height)
  1401             rect = wx.Rect(x, y, width, height)
  1402             inside = rect.InsideXY(pt.x, pt.y)
  1402             inside = rect.Contains(pt.x, pt.y)
  1403 
  1403 
  1404         return inside
  1404         return inside
  1405 
  1405 
  1406     # Draws the highlightment of this element if it is highlighted
  1406     # Draws the highlightment of this element if it is highlighted
  1407     def DrawHighlightment(self, dc):
  1407     def DrawHighlightment(self, dc):
  1929             else:
  1929             else:
  1930                 x2, y2 = self.Points[i + 1].x, self.Points[i + 1].y
  1930                 x2, y2 = self.Points[i + 1].x, self.Points[i + 1].y
  1931             # Calculate a rectangle around the segment
  1931             # Calculate a rectangle around the segment
  1932             rect = wx.Rect(min(x1, x2) - ANCHOR_DISTANCE, min(y1, y2) - ANCHOR_DISTANCE,
  1932             rect = wx.Rect(min(x1, x2) - ANCHOR_DISTANCE, min(y1, y2) - ANCHOR_DISTANCE,
  1933                            abs(x1 - x2) + 2 * ANCHOR_DISTANCE, abs(y1 - y2) + 2 * ANCHOR_DISTANCE)
  1933                            abs(x1 - x2) + 2 * ANCHOR_DISTANCE, abs(y1 - y2) + 2 * ANCHOR_DISTANCE)
  1934             test |= rect.InsideXY(pt.x, pt.y)
  1934             test |= rect.Contains(pt.x, pt.y)
  1935         return test
  1935         return test
  1936 
  1936 
  1937     # Returns the wire start or end point if the point given is on one of them
  1937     # Returns the wire start or end point if the point given is on one of them
  1938     def TestPoint(self, pt):
  1938     def TestPoint(self, pt):
  1939         # Test the wire start point
  1939         # Test the wire start point
  1940         rect = wx.Rect(self.Points[0].x - ANCHOR_DISTANCE, self.Points[0].y - ANCHOR_DISTANCE,
  1940         rect = wx.Rect(self.Points[0].x - ANCHOR_DISTANCE, self.Points[0].y - ANCHOR_DISTANCE,
  1941                        2 * ANCHOR_DISTANCE, 2 * ANCHOR_DISTANCE)
  1941                        2 * ANCHOR_DISTANCE, 2 * ANCHOR_DISTANCE)
  1942         if rect.InsideXY(pt.x, pt.y):
  1942         if rect.Contains(pt.x, pt.y):
  1943             return 0
  1943             return 0
  1944         # Test the wire end point
  1944         # Test the wire end point
  1945         if len(self.Points) > 1:
  1945         if len(self.Points) > 1:
  1946             rect = wx.Rect(self.Points[-1].x - ANCHOR_DISTANCE, self.Points[-1].y - ANCHOR_DISTANCE,
  1946             rect = wx.Rect(self.Points[-1].x - ANCHOR_DISTANCE, self.Points[-1].y - ANCHOR_DISTANCE,
  1947                            2 * ANCHOR_DISTANCE, 2 * ANCHOR_DISTANCE)
  1947                            2 * ANCHOR_DISTANCE, 2 * ANCHOR_DISTANCE)
  1948             if rect.InsideXY(pt.x, pt.y):
  1948             if rect.Contains(pt.x, pt.y):
  1949                 return -1
  1949                 return -1
  1950         return None
  1950         return None
  1951 
  1951 
  1952     # Returns the wire segment if the point given is on it
  1952     # Returns the wire segment if the point given is on it
  1953     def TestSegment(self, pt, all=False):
  1953     def TestSegment(self, pt, all=False):
  1957                 x1, y1 = self.Points[i].x, self.Points[i].y
  1957                 x1, y1 = self.Points[i].x, self.Points[i].y
  1958                 x2, y2 = self.Points[i + 1].x, self.Points[i + 1].y
  1958                 x2, y2 = self.Points[i + 1].x, self.Points[i + 1].y
  1959                 # Calculate a rectangle around the segment
  1959                 # Calculate a rectangle around the segment
  1960                 rect = wx.Rect(min(x1, x2) - ANCHOR_DISTANCE, min(y1, y2) - ANCHOR_DISTANCE,
  1960                 rect = wx.Rect(min(x1, x2) - ANCHOR_DISTANCE, min(y1, y2) - ANCHOR_DISTANCE,
  1961                                abs(x1 - x2) + 2 * ANCHOR_DISTANCE, abs(y1 - y2) + 2 * ANCHOR_DISTANCE)
  1961                                abs(x1 - x2) + 2 * ANCHOR_DISTANCE, abs(y1 - y2) + 2 * ANCHOR_DISTANCE)
  1962                 if rect.InsideXY(pt.x, pt.y):
  1962                 if rect.Contains(pt.x, pt.y):
  1963                     return i, self.Segments[i]
  1963                     return i, self.Segments[i]
  1964         return None
  1964         return None
  1965 
  1965 
  1966     # Define the wire points
  1966     # Define the wire points
  1967     def SetPoints(self, points, merge_segments=True):
  1967     def SetPoints(self, points, merge_segments=True):