1283 height = 5 |
1283 height = 5 |
1284 else: |
1284 else: |
1285 height = CONNECTOR_SIZE |
1285 height = CONNECTOR_SIZE |
1286 return wx.Rect(x - abs(movex), y - abs(movey), width + 2 * abs(movex), height + 2 * abs(movey)) |
1286 return wx.Rect(x - abs(movex), y - abs(movey), width + 2 * abs(movex), height + 2 * abs(movey)) |
1287 |
1287 |
1288 # Change the connector pen |
1288 # Change the connector selection |
1289 def SetPen(self, pen): |
1289 def SetSelected(self, selected): |
1290 self.Pen = pen |
1290 self.Selected = selected |
1291 |
1291 |
1292 # Make a clone of the connector |
1292 # Make a clone of the connector |
1293 def Clone(self, parent = None): |
1293 def Clone(self, parent = None): |
1294 if parent is None: |
1294 if parent is None: |
1295 parent = self.ParentBlock |
1295 parent = self.ParentBlock |
1573 else: |
1573 else: |
1574 self.Errors[infos[0]] = (start, end) |
1574 self.Errors[infos[0]] = (start, end) |
1575 |
1575 |
1576 # Draws the connector |
1576 # Draws the connector |
1577 def Draw(self, dc): |
1577 def Draw(self, dc): |
1578 if len(self.Errors) > 0: |
1578 if self.Selected: |
|
1579 dc.SetPen(wx.Pen(wx.BLUE, 3)) |
|
1580 dc.SetBrush(wx.WHITE_BRUSH) |
|
1581 elif len(self.Errors) > 0: |
1579 dc.SetPen(wx.RED_PEN) |
1582 dc.SetPen(wx.RED_PEN) |
1580 dc.SetBrush(wx.Brush(wx.Colour(255, 255, 0))) |
1583 dc.SetBrush(wx.Brush(wx.Colour(255, 255, 0))) |
1581 else: |
1584 else: |
1582 if not self.Valid: |
1585 if not self.Valid: |
1583 dc.SetPen(wx.RED_PEN) |
1586 dc.SetPen(wx.RED_PEN) |
1589 elif self.Value == "undefined": |
1592 elif self.Value == "undefined": |
1590 dc.SetPen(wx.Pen(wx.NamedColour("orange"))) |
1593 dc.SetPen(wx.Pen(wx.NamedColour("orange"))) |
1591 elif self.Forced: |
1594 elif self.Forced: |
1592 dc.SetPen(wx.Pen(wx.BLUE)) |
1595 dc.SetPen(wx.Pen(wx.BLUE)) |
1593 else: |
1596 else: |
1594 dc.SetPen(self.Pen) |
1597 dc.SetPen(wx.BLACK_PEN) |
1595 dc.SetBrush(wx.WHITE_BRUSH) |
1598 dc.SetBrush(wx.WHITE_BRUSH) |
1596 parent_pos = self.ParentBlock.GetPosition() |
1599 parent_pos = self.ParentBlock.GetPosition() |
1597 |
1600 |
1598 if getattr(dc, "printing", False): |
1601 if getattr(dc, "printing", False): |
1599 name_size = dc.GetTextExtent(self.Name) |
1602 name_size = dc.GetTextExtent(self.Name) |
1614 dc.DrawLine(xstart, ystart, xstart - 4, ystart + 4) |
1617 dc.DrawLine(xstart, ystart, xstart - 4, ystart + 4) |
1615 elif self.Edge == "falling": |
1618 elif self.Edge == "falling": |
1616 # If connector has a falling edge, draw a left arrow |
1619 # If connector has a falling edge, draw a left arrow |
1617 dc.DrawLine(xstart, ystart, xstart + 4, ystart - 4) |
1620 dc.DrawLine(xstart, ystart, xstart + 4, ystart - 4) |
1618 dc.DrawLine(xstart, ystart, xstart + 4, ystart + 4) |
1621 dc.DrawLine(xstart, ystart, xstart + 4, ystart + 4) |
1619 xend = xstart + CONNECTOR_SIZE * self.Direction[0] |
1622 if self.Selected: |
1620 yend = ystart + CONNECTOR_SIZE * self.Direction[1] |
1623 xend = xstart + (CONNECTOR_SIZE - 2) * self.Direction[0] |
1621 dc.DrawLine(xstart + self.Direction[0], ystart + self.Direction[1], xend, yend) |
1624 yend = ystart + (CONNECTOR_SIZE - 2) * self.Direction[1] |
|
1625 dc.DrawLine(xstart + 2 * self.Direction[0], ystart + 2 * self.Direction[1], xend, yend) |
|
1626 else: |
|
1627 xend = xstart + CONNECTOR_SIZE * self.Direction[0] |
|
1628 yend = ystart + CONNECTOR_SIZE * self.Direction[1] |
|
1629 dc.DrawLine(xstart + self.Direction[0], ystart + self.Direction[1], xend, yend) |
1622 if len(self.Errors) > 0: |
1630 if len(self.Errors) > 0: |
1623 dc.SetPen(self.Pen) |
1631 dc.SetPen(self.Pen) |
1624 dc.SetBrush(wx.WHITE_BRUSH) |
1632 dc.SetBrush(wx.WHITE_BRUSH) |
1625 if self.Direction[0] != 0: |
1633 if self.Direction[0] != 0: |
1626 ytext = parent_pos[1] + self.Pos.y - name_size[1] / 2 |
1634 ytext = parent_pos[1] + self.Pos.y - name_size[1] / 2 |
1898 if segment == -1: |
1906 if segment == -1: |
1899 segment = len(self.Segments) - 1 |
1907 segment = len(self.Segments) - 1 |
1900 # The selected segment is reinitialised |
1908 # The selected segment is reinitialised |
1901 if segment == None: |
1909 if segment == None: |
1902 if self.StartConnected: |
1910 if self.StartConnected: |
1903 self.StartConnected.SetPen(wx.BLACK_PEN) |
1911 self.StartConnected.SetSelected(False) |
1904 if self.EndConnected: |
1912 if self.EndConnected: |
1905 self.EndConnected.SetPen(wx.BLACK_PEN) |
1913 self.EndConnected.SetSelected(False) |
1906 # The segment selected is the first |
1914 # The segment selected is the first |
1907 elif segment == 0: |
1915 elif segment == 0: |
1908 if self.StartConnected: |
1916 if self.StartConnected: |
1909 self.StartConnected.SetPen(wx.Pen(wx.BLUE)) |
1917 self.StartConnected.SetSelected(True) |
1910 if self.EndConnected: |
1918 if self.EndConnected: |
1911 # There is only one segment |
1919 # There is only one segment |
1912 if len(self.Segments) == 1: |
1920 if len(self.Segments) == 1: |
1913 self.EndConnected.SetPen(wx.Pen(wx.BLUE)) |
1921 self.EndConnected.SetSelected(True) |
1914 else: |
1922 else: |
1915 self.EndConnected.SetPen(wx.BLACK_PEN) |
1923 self.EndConnected.SetSelected(False) |
1916 # The segment selected is the last |
1924 # The segment selected is the last |
1917 elif segment == len(self.Segments) - 1: |
1925 elif segment == len(self.Segments) - 1: |
1918 if self.StartConnected: |
1926 if self.StartConnected: |
1919 self.StartConnected.SetPen(wx.BLACK_PEN) |
1927 self.StartConnected.SetSelected(False) |
1920 if self.EndConnected: |
1928 if self.EndConnected: |
1921 self.EndConnected.SetPen(wx.Pen(wx.BLUE)) |
1929 self.EndConnected.SetSelected(True) |
1922 self.SelectedSegment = segment |
1930 self.SelectedSegment = segment |
1923 self.Refresh() |
1931 self.Refresh() |
1924 |
1932 |
1925 def SetValid(self, valid): |
1933 def SetValid(self, valid): |
1926 self.Valid = valid |
1934 self.Valid = valid |
2042 if rect.InsideXY(pt.x, pt.y): |
2050 if rect.InsideXY(pt.x, pt.y): |
2043 return i, self.Segments[i] |
2051 return i, self.Segments[i] |
2044 return None |
2052 return None |
2045 |
2053 |
2046 # Define the wire points |
2054 # Define the wire points |
2047 def SetPoints(self, points): |
2055 def SetPoints(self, points, verify=True): |
2048 if len(points) > 1: |
2056 if len(points) > 1: |
2049 self.Points = [wx.Point(x, y) for x, y in points] |
2057 self.Points = [wx.Point(x, y) for x, y in points] |
2050 # Calculate the start and end directions |
2058 # Calculate the start and end directions |
2051 self.StartPoint = [None, vector(self.Points[0], self.Points[1])] |
2059 self.StartPoint = [None, vector(self.Points[0], self.Points[1])] |
2052 self.EndPoint = [None, vector(self.Points[-1], self.Points[-2])] |
2060 self.EndPoint = [None, vector(self.Points[-1], self.Points[-2])] |
2059 self.Points[-1] = self.EndPoint[0] |
2067 self.Points[-1] = self.EndPoint[0] |
2060 # Calculate the segments directions |
2068 # Calculate the segments directions |
2061 self.Segments = [] |
2069 self.Segments = [] |
2062 i = 0 |
2070 i = 0 |
2063 while i < len(self.Points) - 1: |
2071 while i < len(self.Points) - 1: |
2064 if 0 < i < len(self.Points) - 2 and \ |
2072 if verify and 0 < i < len(self.Points) - 2 and \ |
2065 self.Points[i] == self.Points[i + 1] and \ |
2073 self.Points[i] == self.Points[i + 1] and \ |
2066 self.Segments[-1] == vector(self.Points[i + 1], self.Points[i + 2]): |
2074 self.Segments[-1] == vector(self.Points[i + 1], self.Points[i + 2]): |
2067 for j in xrange(2): |
2075 for j in xrange(2): |
2068 self.Points.pop(i) |
2076 self.Points.pop(i) |
2069 else: |
2077 else: |
2743 # Draw the wire lines and the last point (it seems that DrawLines stop before the last point) |
2751 # Draw the wire lines and the last point (it seems that DrawLines stop before the last point) |
2744 dc.DrawLines(self.Points) |
2752 dc.DrawLines(self.Points) |
2745 dc.DrawPoint(self.Points[-1].x, self.Points[-1].y) |
2753 dc.DrawPoint(self.Points[-1].x, self.Points[-1].y) |
2746 # Draw the segment selected in red |
2754 # Draw the segment selected in red |
2747 if not getattr(dc, "printing", False) and self.SelectedSegment is not None: |
2755 if not getattr(dc, "printing", False) and self.SelectedSegment is not None: |
2748 dc.SetPen(wx.RED_PEN) |
2756 dc.SetPen(wx.Pen(wx.BLUE, 3)) |
2749 dc.DrawLine(self.Points[self.SelectedSegment].x, self.Points[self.SelectedSegment].y, |
|
2750 self.Points[self.SelectedSegment + 1].x, self.Points[self.SelectedSegment + 1].y) |
|
2751 if self.SelectedSegment == len(self.Segments) - 1: |
2757 if self.SelectedSegment == len(self.Segments) - 1: |
2752 dc.DrawPoint(self.Points[-1].x, self.Points[-1].y) |
2758 end = 0 |
|
2759 else: |
|
2760 end = 1 |
|
2761 dc.DrawLine(self.Points[self.SelectedSegment].x - 1, self.Points[self.SelectedSegment].y, |
|
2762 self.Points[self.SelectedSegment + 1].x + end, self.Points[self.SelectedSegment + 1].y) |
2753 if self.Value is not None and not isinstance(self.Value, BooleanType) and self.Value != "undefined": |
2763 if self.Value is not None and not isinstance(self.Value, BooleanType) and self.Value != "undefined": |
2754 dc.SetFont(self.Parent.GetMiniFont()) |
2764 dc.SetFont(self.Parent.GetMiniFont()) |
2755 dc.SetTextForeground(wx.NamedColour("purple")) |
2765 dc.SetTextForeground(wx.NamedColour("purple")) |
2756 if self.ValueSize is not None: |
2766 if self.ValueSize is not None: |
2757 width, height = self.ValueSize |
2767 width, height = self.ValueSize |