--- a/graphics/GraphicCommons.py Mon Jul 04 15:24:44 2011 +0200
+++ b/graphics/GraphicCommons.py Fri Aug 12 17:04:55 2011 +0200
@@ -1260,7 +1260,7 @@
self.Valid = True
self.Value = None
self.Forced = False
- self.Pen = wx.BLACK_PEN
+ self.Selected = False
self.Errors = {}
self.RefreshNameSize()
@@ -1285,9 +1285,9 @@
height = CONNECTOR_SIZE
return wx.Rect(x - abs(movex), y - abs(movey), width + 2 * abs(movex), height + 2 * abs(movey))
- # Change the connector pen
- def SetPen(self, pen):
- self.Pen = pen
+ # Change the connector selection
+ def SetSelected(self, selected):
+ self.Selected = selected
# Make a clone of the connector
def Clone(self, parent = None):
@@ -1575,7 +1575,10 @@
# Draws the connector
def Draw(self, dc):
- if len(self.Errors) > 0:
+ if self.Selected:
+ dc.SetPen(wx.Pen(wx.BLUE, 3))
+ dc.SetBrush(wx.WHITE_BRUSH)
+ elif len(self.Errors) > 0:
dc.SetPen(wx.RED_PEN)
dc.SetBrush(wx.Brush(wx.Colour(255, 255, 0)))
else:
@@ -1591,7 +1594,7 @@
elif self.Forced:
dc.SetPen(wx.Pen(wx.BLUE))
else:
- dc.SetPen(self.Pen)
+ dc.SetPen(wx.BLACK_PEN)
dc.SetBrush(wx.WHITE_BRUSH)
parent_pos = self.ParentBlock.GetPosition()
@@ -1616,9 +1619,14 @@
# If connector has a falling edge, draw a left arrow
dc.DrawLine(xstart, ystart, xstart + 4, ystart - 4)
dc.DrawLine(xstart, ystart, xstart + 4, ystart + 4)
- xend = xstart + CONNECTOR_SIZE * self.Direction[0]
- yend = ystart + CONNECTOR_SIZE * self.Direction[1]
- dc.DrawLine(xstart + self.Direction[0], ystart + self.Direction[1], xend, yend)
+ if self.Selected:
+ xend = xstart + (CONNECTOR_SIZE - 2) * self.Direction[0]
+ yend = ystart + (CONNECTOR_SIZE - 2) * self.Direction[1]
+ dc.DrawLine(xstart + 2 * self.Direction[0], ystart + 2 * self.Direction[1], xend, yend)
+ else:
+ xend = xstart + CONNECTOR_SIZE * self.Direction[0]
+ yend = ystart + CONNECTOR_SIZE * self.Direction[1]
+ dc.DrawLine(xstart + self.Direction[0], ystart + self.Direction[1], xend, yend)
if len(self.Errors) > 0:
dc.SetPen(self.Pen)
dc.SetBrush(wx.WHITE_BRUSH)
@@ -1900,25 +1908,25 @@
# The selected segment is reinitialised
if segment == None:
if self.StartConnected:
- self.StartConnected.SetPen(wx.BLACK_PEN)
+ self.StartConnected.SetSelected(False)
if self.EndConnected:
- self.EndConnected.SetPen(wx.BLACK_PEN)
+ self.EndConnected.SetSelected(False)
# The segment selected is the first
elif segment == 0:
if self.StartConnected:
- self.StartConnected.SetPen(wx.Pen(wx.BLUE))
+ self.StartConnected.SetSelected(True)
if self.EndConnected:
# There is only one segment
if len(self.Segments) == 1:
- self.EndConnected.SetPen(wx.Pen(wx.BLUE))
+ self.EndConnected.SetSelected(True)
else:
- self.EndConnected.SetPen(wx.BLACK_PEN)
+ self.EndConnected.SetSelected(False)
# The segment selected is the last
elif segment == len(self.Segments) - 1:
if self.StartConnected:
- self.StartConnected.SetPen(wx.BLACK_PEN)
+ self.StartConnected.SetSelected(False)
if self.EndConnected:
- self.EndConnected.SetPen(wx.Pen(wx.BLUE))
+ self.EndConnected.SetSelected(True)
self.SelectedSegment = segment
self.Refresh()
@@ -2044,7 +2052,7 @@
return None
# Define the wire points
- def SetPoints(self, points):
+ def SetPoints(self, points, verify=True):
if len(points) > 1:
self.Points = [wx.Point(x, y) for x, y in points]
# Calculate the start and end directions
@@ -2061,7 +2069,7 @@
self.Segments = []
i = 0
while i < len(self.Points) - 1:
- if 0 < i < len(self.Points) - 2 and \
+ if verify and 0 < i < len(self.Points) - 2 and \
self.Points[i] == self.Points[i + 1] and \
self.Segments[-1] == vector(self.Points[i + 1], self.Points[i + 2]):
for j in xrange(2):
@@ -2745,11 +2753,13 @@
dc.DrawPoint(self.Points[-1].x, self.Points[-1].y)
# Draw the segment selected in red
if not getattr(dc, "printing", False) and self.SelectedSegment is not None:
- dc.SetPen(wx.RED_PEN)
- dc.DrawLine(self.Points[self.SelectedSegment].x, self.Points[self.SelectedSegment].y,
- self.Points[self.SelectedSegment + 1].x, self.Points[self.SelectedSegment + 1].y)
+ dc.SetPen(wx.Pen(wx.BLUE, 3))
if self.SelectedSegment == len(self.Segments) - 1:
- dc.DrawPoint(self.Points[-1].x, self.Points[-1].y)
+ end = 0
+ else:
+ end = 1
+ dc.DrawLine(self.Points[self.SelectedSegment].x - 1, self.Points[self.SelectedSegment].y,
+ self.Points[self.SelectedSegment + 1].x + end, self.Points[self.SelectedSegment + 1].y)
if self.Value is not None and not isinstance(self.Value, BooleanType) and self.Value != "undefined":
dc.SetFont(self.Parent.GetMiniFont())
dc.SetTextForeground(wx.NamedColour("purple"))