graphics/GraphicCommons.py
changeset 1852 70c1cc354a8f
parent 1850 614396cbffbf
child 1857 524ff4dbb7d9
equal deleted inserted replaced
1851:1b8b5324506c 1852:70c1cc354a8f
   546             cursor = HANDLE_CURSORS.get(handle, 0)
   546             cursor = HANDLE_CURSORS.get(handle, 0)
   547             wx.CallAfter(self.Parent.SetCurrentCursor, cursor)
   547             wx.CallAfter(self.Parent.SetCurrentCursor, cursor)
   548             return 0, 0
   548             return 0, 0
   549 
   549 
   550     # Moves the element
   550     # Moves the element
   551     def Move(self, dx, dy, exclude=[]):
   551     def Move(self, dx, dy, exclude=None):
   552         self.Pos.x += max(-self.BoundingBox.x, dx)
   552         self.Pos.x += max(-self.BoundingBox.x, dx)
   553         self.Pos.y += max(-self.BoundingBox.y, dy)
   553         self.Pos.y += max(-self.BoundingBox.y, dy)
   554         self.RefreshConnected(exclude)
   554         self.RefreshConnected(exclude)
   555         self.RefreshBoundingBox()
   555         self.RefreshBoundingBox()
   556 
   556 
  1303     # Returns if connector has one or more wire connected
  1303     # Returns if connector has one or more wire connected
  1304     def IsConnected(self):
  1304     def IsConnected(self):
  1305         return len(self.Wires) > 0
  1305         return len(self.Wires) > 0
  1306 
  1306 
  1307     # Move the wires connected
  1307     # Move the wires connected
  1308     def MoveConnected(self, exclude=[]):
  1308     def MoveConnected(self, exclude=None):
  1309         if len(self.Wires) > 0:
  1309         if len(self.Wires) > 0:
  1310             # Calculate the new position of the end point
  1310             # Calculate the new position of the end point
  1311             parent_pos = self.ParentBlock.GetPosition()
  1311             parent_pos = self.ParentBlock.GetPosition()
  1312             x = parent_pos[0] + self.Pos.x + self.Direction[0] * CONNECTOR_SIZE
  1312             x = parent_pos[0] + self.Pos.x + self.Direction[0] * CONNECTOR_SIZE
  1313             y = parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE
  1313             y = parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE
  1314             # Move the corresponding point on all the wires connected
  1314             # Move the corresponding point on all the wires connected
  1315             for wire, index in self.Wires:
  1315             for wire, index in self.Wires:
  1316                 if wire not in exclude:
  1316                 if (exclude is None) or (wire not in exclude):
  1317                     if index == 0:
  1317                     if index == 0:
  1318                         wire.MoveStartPoint(wx.Point(x, y))
  1318                         wire.MoveStartPoint(wx.Point(x, y))
  1319                     else:
  1319                     else:
  1320                         wire.MoveEndPoint(wx.Point(x, y))
  1320                         wire.MoveEndPoint(wx.Point(x, y))
  1321 
  1321 
  1623                 else:
  1623                 else:
  1624                     y = self.Points[middle].y - height
  1624                     y = self.Points[middle].y - height
  1625                 rect = rect.Union(wx.Rect(x, y, width, height))
  1625                 rect = rect.Union(wx.Rect(x, y, width, height))
  1626         return rect
  1626         return rect
  1627 
  1627 
  1628     def Clone(self, parent, connectors={}, dx=0, dy=0):
  1628     def Clone(self, parent, connectors=None, dx=0, dy=0):
       
  1629         connectors = {} if connectors is None else connectors
  1629         start_connector = connectors.get(self.StartConnected, None)
  1630         start_connector = connectors.get(self.StartConnected, None)
  1630         end_connector = connectors.get(self.EndConnected, None)
  1631         end_connector = connectors.get(self.EndConnected, None)
  1631         if start_connector is not None and end_connector is not None:
  1632         if start_connector is not None and end_connector is not None:
  1632             wire = Wire(parent)
  1633             wire = Wire(parent)
  1633             wire.SetPoints([(point.x + dx, point.y + dy) for point in self.Points])
  1634             wire.SetPoints([(point.x + dx, point.y + dy) for point in self.Points])