graphics/GraphicCommons.py
changeset 1744 69dfdb26f600
parent 1743 c3c3d1318130
child 1749 d73b64672238
equal deleted inserted replaced
1743:c3c3d1318130 1744:69dfdb26f600
   129 """
   129 """
   130 Basic vector operations for calculate wire points
   130 Basic vector operations for calculate wire points
   131 """
   131 """
   132 
   132 
   133 
   133 
   134 def vector(p1, p2, normal = True):
   134 def vector(p1, p2, normal=True):
   135     """
   135     """
   136     Create a vector from two points and define if vector must be normal
   136     Create a vector from two points and define if vector must be normal
   137     """
   137     """
   138     vector = (p2.x - p1.x, p2.y - p1.y)
   138     vector = (p2.x - p1.x, p2.y - p1.y)
   139     if normal:
   139     if normal:
   256     """
   256     """
   257     Class that implements a generic graphic element
   257     Class that implements a generic graphic element
   258     """
   258     """
   259 
   259 
   260     # Create a new graphic element
   260     # Create a new graphic element
   261     def __init__(self, parent, id = None):
   261     def __init__(self, parent, id=None):
   262         ToolTipProducer.__init__(self, parent)
   262         ToolTipProducer.__init__(self, parent)
   263         self.Parent = parent
   263         self.Parent = parent
   264         self.Id = id
   264         self.Id = id
   265         self.oldPos = None
   265         self.oldPos = None
   266         self.StartPos = None
   266         self.StartPos = None
   402     # Returns the bounding box
   402     # Returns the bounding box
   403     def GetBoundingBox(self):
   403     def GetBoundingBox(self):
   404         return self.BoundingBox
   404         return self.BoundingBox
   405 
   405 
   406     # Returns the RedrawRect
   406     # Returns the RedrawRect
   407     def GetRedrawRect(self, movex = 0, movey = 0):
   407     def GetRedrawRect(self, movex=0, movey=0):
   408         scalex, scaley = self.Parent.GetViewScale()
   408         scalex, scaley = self.Parent.GetViewScale()
   409         rect = wx.Rect()
   409         rect = wx.Rect()
   410         rect.x = self.BoundingBox.x - int(HANDLE_SIZE / scalex) - 3 - abs(movex)
   410         rect.x = self.BoundingBox.x - int(HANDLE_SIZE / scalex) - 3 - abs(movex)
   411         rect.y = self.BoundingBox.y - int(HANDLE_SIZE / scaley) - 3 - abs(movey)
   411         rect.y = self.BoundingBox.y - int(HANDLE_SIZE / scaley) - 3 - abs(movey)
   412         rect.width = self.BoundingBox.width + 2 * (int(HANDLE_SIZE / scalex) + abs(movex) + 1) + 4
   412         rect.width = self.BoundingBox.width + 2 * (int(HANDLE_SIZE / scalex) + abs(movex) + 1) + 4
   413         rect.height = self.BoundingBox.height + 2 * (int(HANDLE_SIZE / scaley) + abs(movey) + 1) + 4
   413         rect.height = self.BoundingBox.height + 2 * (int(HANDLE_SIZE / scaley) + abs(movey) + 1) + 4
   414         return rect
   414         return rect
   415 
   415 
   416     def Refresh(self, rect = None):
   416     def Refresh(self, rect=None):
   417         if self.Visible:
   417         if self.Visible:
   418             if rect is not None:
   418             if rect is not None:
   419                 self.Parent.RefreshRect(self.Parent.GetScrolledRect(rect), False)
   419                 self.Parent.RefreshRect(self.Parent.GetScrolledRect(rect), False)
   420             else:
   420             else:
   421                 self.Parent.RefreshRect(self.Parent.GetScrolledRect(self.GetRedrawRect()), False)
   421                 self.Parent.RefreshRect(self.Parent.GetScrolledRect(self.GetRedrawRect()), False)
   552             cursor = HANDLE_CURSORS.get(handle, 0)
   552             cursor = HANDLE_CURSORS.get(handle, 0)
   553             wx.CallAfter(self.Parent.SetCurrentCursor, cursor)
   553             wx.CallAfter(self.Parent.SetCurrentCursor, cursor)
   554             return 0, 0
   554             return 0, 0
   555 
   555 
   556     # Moves the element
   556     # Moves the element
   557     def Move(self, dx, dy, exclude = []):
   557     def Move(self, dx, dy, exclude=[]):
   558         self.Pos.x += max(-self.BoundingBox.x, dx)
   558         self.Pos.x += max(-self.BoundingBox.x, dx)
   559         self.Pos.y += max(-self.BoundingBox.y, dy)
   559         self.Pos.y += max(-self.BoundingBox.y, dy)
   560         self.RefreshConnected(exclude)
   560         self.RefreshConnected(exclude)
   561         self.RefreshBoundingBox()
   561         self.RefreshBoundingBox()
   562 
   562 
   564     def Resize(self, x, y, width, height):
   564     def Resize(self, x, y, width, height):
   565         self.Move(x, y)
   565         self.Move(x, y)
   566         self.SetSize(width, height)
   566         self.SetSize(width, height)
   567 
   567 
   568     # Refreshes the element state according to move defined and handle selected
   568     # Refreshes the element state according to move defined and handle selected
   569     def ProcessDragging(self, movex, movey, event, scaling, width_fac = 1, height_fac = 1):
   569     def ProcessDragging(self, movex, movey, event, scaling, width_fac=1, height_fac=1):
   570         handle_type, handle = self.Handle
   570         handle_type, handle = self.Handle
   571         # If it is a resize handle, calculate the values from resizing
   571         # If it is a resize handle, calculate the values from resizing
   572         if handle_type == HANDLE_RESIZE:
   572         if handle_type == HANDLE_RESIZE:
   573             if scaling is not None:
   573             if scaling is not None:
   574                 scaling = (scaling[0] * width_fac, scaling[1] * height_fac)
   574                 scaling = (scaling[0] * width_fac, scaling[1] * height_fac)
   731             blocks.extend(block)
   731             blocks.extend(block)
   732             wires.extend(wire)
   732             wires.extend(wire)
   733         return blocks, wires
   733         return blocks, wires
   734 
   734 
   735     # Make a clone of this element
   735     # Make a clone of this element
   736     def Clone(self, parent, pos = None):
   736     def Clone(self, parent, pos=None):
   737         group = Graphic_Group(parent)
   737         group = Graphic_Group(parent)
   738         connectors = {}
   738         connectors = {}
   739         exclude_names = {}
   739         exclude_names = {}
   740         wires = []
   740         wires = []
   741         if pos is not None:
   741         if pos is not None:
   749                     new_pos = wx.Point(x + dx, y + dy)
   749                     new_pos = wx.Point(x + dx, y + dy)
   750                     newid = parent.GetNewId()
   750                     newid = parent.GetNewId()
   751                     if parent.IsNamedElement(element):
   751                     if parent.IsNamedElement(element):
   752                         name = parent.GenerateNewName(element, exclude_names)
   752                         name = parent.GenerateNewName(element, exclude_names)
   753                         exclude_names[name.upper()] = True
   753                         exclude_names[name.upper()] = True
   754                         new_element = element.Clone(parent, newid, name, pos = new_pos)
   754                         new_element = element.Clone(parent, newid, name, pos=new_pos)
   755                     else:
   755                     else:
   756                         new_element = element.Clone(parent, newid, pos = new_pos)
   756                         new_element = element.Clone(parent, newid, pos=new_pos)
   757                     new_element.SetBestSize(parent.Scaling)
   757                     new_element.SetBestSize(parent.Scaling)
   758                 else:
   758                 else:
   759                     new_element = element.Clone(parent)
   759                     new_element = element.Clone(parent)
   760                 connectors.update(element.GetConnectorTranslation(new_element))
   760                 connectors.update(element.GetConnectorTranslation(new_element))
   761                 group.SelectElement(new_element)
   761                 group.SelectElement(new_element)
   796                 endblock = element.EndConnected.GetParentBlock()
   796                 endblock = element.EndConnected.GetParentBlock()
   797                 if startblock in self.Elements and endblock in self.Elements:
   797                 if startblock in self.Elements and endblock in self.Elements:
   798                     self.WireExcluded.append(element)
   798                     self.WireExcluded.append(element)
   799 
   799 
   800     # Returns the RedrawRect
   800     # Returns the RedrawRect
   801     def GetRedrawRect(self, movex = 0, movey = 0):
   801     def GetRedrawRect(self, movex=0, movey=0):
   802         rect = None
   802         rect = None
   803         for element in self.Elements:
   803         for element in self.Elements:
   804             if rect is None:
   804             if rect is None:
   805                 rect = element.GetRedrawRect(movex, movey)
   805                 rect = element.GetRedrawRect(movex, movey)
   806             else:
   806             else:
  1029     """
  1029     """
  1030     Class that implements a connector for any type of block
  1030     Class that implements a connector for any type of block
  1031     """
  1031     """
  1032 
  1032 
  1033     # Create a new connector
  1033     # Create a new connector
  1034     def __init__(self, parent, name, type, position, direction, negated = False, edge = "none", onlyone = False):
  1034     def __init__(self, parent, name, type, position, direction, negated=False, edge="none", onlyone=False):
  1035         DebugDataConsumer.__init__(self)
  1035         DebugDataConsumer.__init__(self)
  1036         ToolTipProducer.__init__(self, parent.Parent)
  1036         ToolTipProducer.__init__(self, parent.Parent)
  1037         self.ParentBlock = parent
  1037         self.ParentBlock = parent
  1038         self.Name = name
  1038         self.Name = name
  1039         self.Type = type
  1039         self.Type = type
  1061         for wire, handle in self.Wires:
  1061         for wire, handle in self.Wires:
  1062             wire.Flush()
  1062             wire.Flush()
  1063         self.Wires = []
  1063         self.Wires = []
  1064 
  1064 
  1065     # Returns the RedrawRect
  1065     # Returns the RedrawRect
  1066     def GetRedrawRect(self, movex = 0, movey = 0):
  1066     def GetRedrawRect(self, movex=0, movey=0):
  1067         parent_pos = self.ParentBlock.GetPosition()
  1067         parent_pos = self.ParentBlock.GetPosition()
  1068         x = min(parent_pos[0] + self.Pos.x, parent_pos[0] + self.Pos.x + self.Direction[0] * CONNECTOR_SIZE)
  1068         x = min(parent_pos[0] + self.Pos.x, parent_pos[0] + self.Pos.x + self.Direction[0] * CONNECTOR_SIZE)
  1069         y = min(parent_pos[1] + self.Pos.y, parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE)
  1069         y = min(parent_pos[1] + self.Pos.y, parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE)
  1070         has_modifier = self.Negated or self.Edge != "none"
  1070         has_modifier = self.Negated or self.Edge != "none"
  1071         if self.Direction[0] == 0:
  1071         if self.Direction[0] == 0:
  1098     # Change the connector selection
  1098     # Change the connector selection
  1099     def SetSelected(self, selected):
  1099     def SetSelected(self, selected):
  1100         self.Selected = selected
  1100         self.Selected = selected
  1101 
  1101 
  1102     # Make a clone of the connector
  1102     # Make a clone of the connector
  1103     def Clone(self, parent = None):
  1103     def Clone(self, parent=None):
  1104         if parent is None:
  1104         if parent is None:
  1105             parent = self.ParentBlock
  1105             parent = self.ParentBlock
  1106         return Connector(parent, self.Name, self.Type, wx.Point(self.Pos[0], self.Pos[1]),
  1106         return Connector(parent, self.Name, self.Type, wx.Point(self.Pos[0], self.Pos[1]),
  1107                 self.Direction, self.Negated)
  1107                 self.Direction, self.Negated)
  1108 
  1108 
  1109     # Returns the connector parent block
  1109     # Returns the connector parent block
  1110     def GetParentBlock(self):
  1110     def GetParentBlock(self):
  1111         return self.ParentBlock
  1111         return self.ParentBlock
  1112 
  1112 
  1113     # Returns the connector type
  1113     # Returns the connector type
  1114     def GetType(self, raw = False):
  1114     def GetType(self, raw=False):
  1115         if self.ParentBlock.IsEndType(self.Type) or raw:
  1115         if self.ParentBlock.IsEndType(self.Type) or raw:
  1116             return self.Type
  1116             return self.Type
  1117         elif (self.Negated or self.Edge != "none") and self.ParentBlock.IsOfType("BOOL", self.Type):
  1117         elif (self.Negated or self.Edge != "none") and self.ParentBlock.IsOfType("BOOL", self.Type):
  1118             return "BOOL"
  1118             return "BOOL"
  1119         else:
  1119         else:
  1233     # Returns the connector relative position
  1233     # Returns the connector relative position
  1234     def GetRelPosition(self):
  1234     def GetRelPosition(self):
  1235         return self.Pos
  1235         return self.Pos
  1236 
  1236 
  1237     # Returns the connector absolute position
  1237     # Returns the connector absolute position
  1238     def GetPosition(self, size = True):
  1238     def GetPosition(self, size=True):
  1239         parent_pos = self.ParentBlock.GetPosition()
  1239         parent_pos = self.ParentBlock.GetPosition()
  1240         # If the position of the end of the connector is asked
  1240         # If the position of the end of the connector is asked
  1241         if size:
  1241         if size:
  1242             x = parent_pos[0] + self.Pos.x + self.Direction[0] * CONNECTOR_SIZE
  1242             x = parent_pos[0] + self.Pos.x + self.Direction[0] * CONNECTOR_SIZE
  1243             y = parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE
  1243             y = parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE
  1257     # Change the connector direction
  1257     # Change the connector direction
  1258     def SetDirection(self, direction):
  1258     def SetDirection(self, direction):
  1259         self.Direction = direction
  1259         self.Direction = direction
  1260 
  1260 
  1261     # Connect a wire to this connector at the last place
  1261     # Connect a wire to this connector at the last place
  1262     def Connect(self, wire, refresh = True):
  1262     def Connect(self, wire, refresh=True):
  1263         self.InsertConnect(len(self.Wires), wire, refresh)
  1263         self.InsertConnect(len(self.Wires), wire, refresh)
  1264 
  1264 
  1265     # Connect a wire to this connector at the place given
  1265     # Connect a wire to this connector at the place given
  1266     def InsertConnect(self, idx, wire, refresh = True):
  1266     def InsertConnect(self, idx, wire, refresh=True):
  1267         if wire not in self.Wires:
  1267         if wire not in self.Wires:
  1268             self.Wires.insert(idx, wire)
  1268             self.Wires.insert(idx, wire)
  1269             if wire[1] == 0:
  1269             if wire[1] == 0:
  1270                 wire[0].ConnectStartPoint(None, self)
  1270                 wire[0].ConnectStartPoint(None, self)
  1271             else:
  1271             else:
  1279             if tmp_wire == wire:
  1279             if tmp_wire == wire:
  1280                 return i
  1280                 return i
  1281         return None
  1281         return None
  1282 
  1282 
  1283     # Unconnect a wire or all wires connected to the connector
  1283     # Unconnect a wire or all wires connected to the connector
  1284     def UnConnect(self, wire = None, unconnect = True, delete = False):
  1284     def UnConnect(self, wire=None, unconnect=True, delete=False):
  1285         i = 0
  1285         i = 0
  1286         found = False
  1286         found = False
  1287         while i < len(self.Wires) and not found:
  1287         while i < len(self.Wires) and not found:
  1288             if not wire or self.Wires[i][0] == wire:
  1288             if not wire or self.Wires[i][0] == wire:
  1289                 # If Unconnect haven't been called from a wire, disconnect the connector in the wire
  1289                 # If Unconnect haven't been called from a wire, disconnect the connector in the wire
  1307     # Returns if connector has one or more wire connected
  1307     # Returns if connector has one or more wire connected
  1308     def IsConnected(self):
  1308     def IsConnected(self):
  1309         return len(self.Wires) > 0
  1309         return len(self.Wires) > 0
  1310 
  1310 
  1311     # Move the wires connected
  1311     # Move the wires connected
  1312     def MoveConnected(self, exclude = []):
  1312     def MoveConnected(self, exclude=[]):
  1313         if len(self.Wires) > 0:
  1313         if len(self.Wires) > 0:
  1314             # Calculate the new position of the end point
  1314             # Calculate the new position of the end point
  1315             parent_pos = self.ParentBlock.GetPosition()
  1315             parent_pos = self.ParentBlock.GetPosition()
  1316             x = parent_pos[0] + self.Pos.x + self.Direction[0] * CONNECTOR_SIZE
  1316             x = parent_pos[0] + self.Pos.x + self.Direction[0] * CONNECTOR_SIZE
  1317             y = parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE
  1317             y = parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE
  1563     """
  1563     """
  1564     Class that implements a wire for connecting two blocks
  1564     Class that implements a wire for connecting two blocks
  1565     """
  1565     """
  1566 
  1566 
  1567     # Create a new wire
  1567     # Create a new wire
  1568     def __init__(self, parent, start = None, end = None):
  1568     def __init__(self, parent, start=None, end=None):
  1569         Graphic_Element.__init__(self, parent)
  1569         Graphic_Element.__init__(self, parent)
  1570         DebugDataConsumer.__init__(self)
  1570         DebugDataConsumer.__init__(self)
  1571         self.StartPoint = start
  1571         self.StartPoint = start
  1572         self.EndPoint = end
  1572         self.EndPoint = end
  1573         self.StartConnected = None
  1573         self.StartConnected = None
  1601     def Flush(self):
  1601     def Flush(self):
  1602         self.StartConnected = None
  1602         self.StartConnected = None
  1603         self.EndConnected = None
  1603         self.EndConnected = None
  1604 
  1604 
  1605     # Returns the RedrawRect
  1605     # Returns the RedrawRect
  1606     def GetRedrawRect(self, movex = 0, movey = 0):
  1606     def GetRedrawRect(self, movex=0, movey=0):
  1607         rect = Graphic_Element.GetRedrawRect(self, movex, movey)
  1607         rect = Graphic_Element.GetRedrawRect(self, movex, movey)
  1608         if self.StartConnected:
  1608         if self.StartConnected:
  1609             rect = rect.Union(self.StartConnected.GetRedrawRect(movex, movey))
  1609             rect = rect.Union(self.StartConnected.GetRedrawRect(movex, movey))
  1610         if self.EndConnected:
  1610         if self.EndConnected:
  1611             rect = rect.Union(self.EndConnected.GetRedrawRect(movex, movey))
  1611             rect = rect.Union(self.EndConnected.GetRedrawRect(movex, movey))
  1628                 else:
  1628                 else:
  1629                     y = self.Points[middle].y - height
  1629                     y = self.Points[middle].y - height
  1630                 rect = rect.Union(wx.Rect(x, y, width, height))
  1630                 rect = rect.Union(wx.Rect(x, y, width, height))
  1631         return rect
  1631         return rect
  1632 
  1632 
  1633     def Clone(self, parent, connectors = {}, dx = 0, dy = 0):
  1633     def Clone(self, parent, connectors={}, dx=0, dy=0):
  1634         start_connector = connectors.get(self.StartConnected, None)
  1634         start_connector = connectors.get(self.StartConnected, None)
  1635         end_connector = connectors.get(self.EndConnected, None)
  1635         end_connector = connectors.get(self.EndConnected, None)
  1636         if start_connector is not None and end_connector is not None:
  1636         if start_connector is not None and end_connector is not None:
  1637             wire = Wire(parent)
  1637             wire = Wire(parent)
  1638             wire.SetPoints([(point.x + dx, point.y + dy) for point in self.Points])
  1638             wire.SetPoints([(point.x + dx, point.y + dy) for point in self.Points])
  2007         if index < len(self.Points):
  2007         if index < len(self.Points):
  2008             return self.Points[index].x, self.Points[index].y
  2008             return self.Points[index].x, self.Points[index].y
  2009         return None
  2009         return None
  2010 
  2010 
  2011     # Returns a list of the position of all wire points
  2011     # Returns a list of the position of all wire points
  2012     def GetPoints(self, invert = False):
  2012     def GetPoints(self, invert=False):
  2013         points = self.VerifyPoints()
  2013         points = self.VerifyPoints()
  2014         points[0] = wx.Point(points[0].x - CONNECTOR_SIZE * self.StartPoint[1][0],
  2014         points[0] = wx.Point(points[0].x - CONNECTOR_SIZE * self.StartPoint[1][0],
  2015                 points[0].y - CONNECTOR_SIZE * self.StartPoint[1][1])
  2015                 points[0].y - CONNECTOR_SIZE * self.StartPoint[1][1])
  2016         points[-1] = wx.Point(points[-1].x - CONNECTOR_SIZE * self.EndPoint[1][0],
  2016         points[-1] = wx.Point(points[-1].x - CONNECTOR_SIZE * self.EndPoint[1][0],
  2017                 points[-1].y - CONNECTOR_SIZE * self.EndPoint[1][1])
  2017                 points[-1].y - CONNECTOR_SIZE * self.EndPoint[1][1])
  2048         elif index == -1 and self.EndConnected:
  2048         elif index == -1 and self.EndConnected:
  2049             return self.EndConnected.GetBlockId(), self.EndConnected.GetName()
  2049             return self.EndConnected.GetBlockId(), self.EndConnected.GetName()
  2050         return None
  2050         return None
  2051 
  2051 
  2052     # Update the wire points position by keeping at most possible the current positions
  2052     # Update the wire points position by keeping at most possible the current positions
  2053     def GeneratePoints(self, realpoints = True):
  2053     def GeneratePoints(self, realpoints=True):
  2054         i = 0
  2054         i = 0
  2055         # Calculate the start enad end points with the minimum segment size in the right direction
  2055         # Calculate the start enad end points with the minimum segment size in the right direction
  2056         end = wx.Point(self.EndPoint[0].x + self.EndPoint[1][0] * MIN_SEGMENT_SIZE,
  2056         end = wx.Point(self.EndPoint[0].x + self.EndPoint[1][0] * MIN_SEGMENT_SIZE,
  2057             self.EndPoint[0].y + self.EndPoint[1][1] * MIN_SEGMENT_SIZE)
  2057             self.EndPoint[0].y + self.EndPoint[1][1] * MIN_SEGMENT_SIZE)
  2058         start = wx.Point(self.StartPoint[0].x + self.StartPoint[1][0] * MIN_SEGMENT_SIZE,
  2058         start = wx.Point(self.StartPoint[0].x + self.StartPoint[1][0] * MIN_SEGMENT_SIZE,
  2207             self.RefreshBoundingBox()
  2207             self.RefreshBoundingBox()
  2208             self.RefreshRealPoints()
  2208             self.RefreshRealPoints()
  2209         return points
  2209         return points
  2210 
  2210 
  2211     # Moves all the wire points except the first and the last if they are connected
  2211     # Moves all the wire points except the first and the last if they are connected
  2212     def Move(self, dx, dy, endpoints = False):
  2212     def Move(self, dx, dy, endpoints=False):
  2213         for i, point in enumerate(self.Points):
  2213         for i, point in enumerate(self.Points):
  2214             if endpoints or not (i == 0 and self.StartConnected) and not (i == len(self.Points) - 1 and self.EndConnected):
  2214             if endpoints or not (i == 0 and self.StartConnected) and not (i == len(self.Points) - 1 and self.EndConnected):
  2215                 point.x += dx
  2215                 point.x += dx
  2216                 point.y += dy
  2216                 point.y += dy
  2217         self.StartPoint[0] = self.Points[0]
  2217         self.StartPoint[0] = self.Points[0]
  2302             self.MoveStartPoint(point)
  2302             self.MoveStartPoint(point)
  2303         self.StartConnected = connector
  2303         self.StartConnected = connector
  2304         self.RefreshBoundingBox()
  2304         self.RefreshBoundingBox()
  2305 
  2305 
  2306     # Unconnects wire start point
  2306     # Unconnects wire start point
  2307     def UnConnectStartPoint(self, delete = False):
  2307     def UnConnectStartPoint(self, delete=False):
  2308         if delete:
  2308         if delete:
  2309             self.StartConnected = None
  2309             self.StartConnected = None
  2310             self.Delete()
  2310             self.Delete()
  2311         elif self.StartConnected:
  2311         elif self.StartConnected:
  2312             self.StartConnected.UnConnect(self, unconnect = False)
  2312             self.StartConnected.UnConnect(self, unconnect=False)
  2313             self.StartConnected = None
  2313             self.StartConnected = None
  2314             self.RefreshBoundingBox()
  2314             self.RefreshBoundingBox()
  2315 
  2315 
  2316     # Moves the wire end point and update the wire points
  2316     # Moves the wire end point and update the wire points
  2317     def MoveEndPoint(self, point):
  2317     def MoveEndPoint(self, point):
  2337             self.MoveEndPoint(point)
  2337             self.MoveEndPoint(point)
  2338         self.EndConnected = connector
  2338         self.EndConnected = connector
  2339         self.RefreshBoundingBox()
  2339         self.RefreshBoundingBox()
  2340 
  2340 
  2341     # Unconnects wire end point
  2341     # Unconnects wire end point
  2342     def UnConnectEndPoint(self, delete = False):
  2342     def UnConnectEndPoint(self, delete=False):
  2343         if delete:
  2343         if delete:
  2344             self.EndConnected = None
  2344             self.EndConnected = None
  2345             self.Delete()
  2345             self.Delete()
  2346         elif self.EndConnected:
  2346         elif self.EndConnected:
  2347             self.EndConnected.UnConnect(self, unconnect = False)
  2347             self.EndConnected.UnConnect(self, unconnect=False)
  2348             self.EndConnected = None
  2348             self.EndConnected = None
  2349             self.RefreshBoundingBox()
  2349             self.RefreshBoundingBox()
  2350 
  2350 
  2351     # Moves the wire segment given by its index
  2351     # Moves the wire segment given by its index
  2352     def MoveSegment(self, idx, movex, movey, scaling):
  2352     def MoveSegment(self, idx, movex, movey, scaling):
  2765     """
  2765     """
  2766     Class that implements a comment
  2766     Class that implements a comment
  2767     """
  2767     """
  2768 
  2768 
  2769     # Create a new comment
  2769     # Create a new comment
  2770     def __init__(self, parent, content, id = None):
  2770     def __init__(self, parent, content, id=None):
  2771         Graphic_Element.__init__(self, parent)
  2771         Graphic_Element.__init__(self, parent)
  2772         self.Id = id
  2772         self.Id = id
  2773         self.Content = content
  2773         self.Content = content
  2774         self.Pos = wx.Point(0, 0)
  2774         self.Pos = wx.Point(0, 0)
  2775         self.Size = wx.Size(0, 0)
  2775         self.Size = wx.Size(0, 0)
  2776         self.Highlights = []
  2776         self.Highlights = []
  2777 
  2777 
  2778     # Make a clone of this comment
  2778     # Make a clone of this comment
  2779     def Clone(self, parent, id = None, pos = None):
  2779     def Clone(self, parent, id=None, pos=None):
  2780         comment = Comment(parent, self.Content, id)
  2780         comment = Comment(parent, self.Content, id)
  2781         if pos is not None:
  2781         if pos is not None:
  2782             comment.SetPosition(pos.x, pos.y)
  2782             comment.SetPosition(pos.x, pos.y)
  2783         comment.SetSize(self.Size[0], self.Size[1])
  2783         comment.SetSize(self.Size[0], self.Size[1])
  2784         return comment
  2784         return comment
  2839     # Returns the comment position
  2839     # Returns the comment position
  2840     def GetPosition(self):
  2840     def GetPosition(self):
  2841         return self.Pos.x, self.Pos.y
  2841         return self.Pos.x, self.Pos.y
  2842 
  2842 
  2843     # Moves the comment
  2843     # Moves the comment
  2844     def Move(self, dx, dy, connected = True):
  2844     def Move(self, dx, dy, connected=True):
  2845         self.Pos.x += dx
  2845         self.Pos.x += dx
  2846         self.Pos.y += dy
  2846         self.Pos.y += dy
  2847         self.RefreshBoundingBox()
  2847         self.RefreshBoundingBox()
  2848 
  2848 
  2849     # Resizes the comment with the position and the size given
  2849     # Resizes the comment with the position and the size given