graphics/GraphicCommons.py
changeset 237 097e8ee006cb
parent 231 fc2d6cbb8b39
child 243 c5da8b706cde
equal deleted inserted replaced
236:9f594b90bb1a 237:097e8ee006cb
  1447     
  1447     
  1448     # Returns the wire segment if the point given is on it
  1448     # Returns the wire segment if the point given is on it
  1449     def TestSegment(self, pt, all=False):
  1449     def TestSegment(self, pt, all=False):
  1450         for i in xrange(len(self.Segments)):
  1450         for i in xrange(len(self.Segments)):
  1451             # If wire is not in a Ladder Diagram, first and last segments are excluded
  1451             # If wire is not in a Ladder Diagram, first and last segments are excluded
  1452             if 0 < i < len(self.Segments) - 1 or all:
  1452             if all or 0 < i < len(self.Segments) - 1:
  1453                 x1, y1 = self.Points[i].x, self.Points[i].y
  1453                 x1, y1 = self.Points[i].x, self.Points[i].y
  1454                 x2, y2 = self.Points[i + 1].x, self.Points[i + 1].y
  1454                 x2, y2 = self.Points[i + 1].x, self.Points[i + 1].y
  1455                 # Calculate a rectangle around the segment
  1455                 # Calculate a rectangle around the segment
  1456                 rect = wx.Rect(min(x1, x2) - ANCHOR_DISTANCE, min(y1, y2) - ANCHOR_DISTANCE,
  1456                 rect = wx.Rect(min(x1, x2) - ANCHOR_DISTANCE, min(y1, y2) - ANCHOR_DISTANCE,
  1457                     abs(x1 - x2) + 2 * ANCHOR_DISTANCE, abs(y1 - y2) + 2 * ANCHOR_DISTANCE)
  1457                     abs(x1 - x2) + 2 * ANCHOR_DISTANCE, abs(y1 - y2) + 2 * ANCHOR_DISTANCE)
  1901     
  1901     
  1902     # Method called when a RightUp event has been generated
  1902     # Method called when a RightUp event has been generated
  1903     def OnRightUp(self, event, dc, scaling):
  1903     def OnRightUp(self, event, dc, scaling):
  1904         pos = GetScaledEventPosition(event, dc, scaling)
  1904         pos = GetScaledEventPosition(event, dc, scaling)
  1905         # Test if a segment has been handled
  1905         # Test if a segment has been handled
  1906         result = self.TestSegment(pos)
  1906         result = self.TestSegment(pos, True)
  1907         if result != None:
  1907         if result != None:
  1908             self.Handle = (HANDLE_SEGMENT, result)
  1908             self.Handle = (HANDLE_SEGMENT, result)
  1909             # Popup the menu with special items for a wire
  1909             # Popup the menu with special items for a wire
  1910             self.Parent.PopupWireMenu()
  1910             self.Parent.PopupWireMenu(0 < result < len(self.Segments) - 1)
  1911         else:
  1911         else:
  1912             # Execute the default method for a graphic element
  1912             # Execute the default method for a graphic element
  1913             Graphic_Element.OnRightUp(self, event, dc, scaling)
  1913             Graphic_Element.OnRightUp(self, event, dc, scaling)
  1914     
  1914     
  1915     # Method called when a LeftDClick event has been generated
  1915     # Method called when a LeftDClick event has been generated