--- a/graphics/GraphicCommons.py Mon Dec 31 13:36:11 2007 +0100
+++ b/graphics/GraphicCommons.py Wed Jan 02 18:15:31 2008 +0100
@@ -88,6 +88,9 @@
# Contants for defining which drawing mode is selected for app
[FREEDRAWING_MODE, DRIVENDRAWING_MODE] = [1, 2]
+# Color for Highlighting
+HIGHLIGHTCOLOR = wx.CYAN
+
CURSORS = None
def ResetCursors():
@@ -288,6 +291,7 @@
self.Handle = False
self.Dragging = False
self.Selected = False
+ self.Highlighted = False
self.Pos = wx.Point(0, 0)
self.Size = wx.Size(0, 0)
self.BoundingBox = wx.Rect(0, 0, 0, 0)
@@ -365,6 +369,10 @@
def SetSelected(self, selected):
self.Selected = selected
+ # Change the variable that indicates if this element is highlighted
+ def SetHighlighted(self, highlighted):
+ self.Highlighted = highlighted
+
# Test if the point is on a handle of this element
def TestHandle(self, pt):
extern_rect = wx.Rect(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y - HANDLE_SIZE - 2,
@@ -526,6 +534,13 @@
def RefreshModel(self, move=True):
pass
+ # Draws the highlightment of this element if it is highlighted (can be overwritten)
+ def DrawHighlightment(self, dc):
+ if self.Highlighted:
+ dc.SetPen(wx.Pen(HIGHLIGHTCOLOR))
+ dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR))
+ dc.DrawRectangle(self.Pos.x - 2, self.Pos.y - 2, self.Size.width + 5, self.Size.height + 5)
+
# Draws the handles of this element if it is selected
def Draw(self, dc):
if self.Selected:
@@ -544,7 +559,6 @@
self.BoundingBox.y + self.BoundingBox.height + 2, HANDLE_SIZE, HANDLE_SIZE)
dc.DrawRectangle(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y + self.BoundingBox.height + 2, HANDLE_SIZE, HANDLE_SIZE)
dc.DrawRectangle(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y + (self.BoundingBox.height - HANDLE_SIZE) / 2, HANDLE_SIZE, HANDLE_SIZE)
- dc.SetBrush(wx.WHITE_BRUSH)
#-------------------------------------------------------------------------------
@@ -711,6 +725,11 @@
def GetSize(self):
return self.BoundingBox.width, self.BoundingBox.height
+ # Change the variable that indicates if this element is highlighted
+ def SetHighlighted(self, highlighted):
+ for element in self.Elements:
+ element.SetHighlighted(highlighted)
+
# Change the variable that indicates if the elemente is selected
def SetSelected(self, selected):
for element in self.Elements:
@@ -925,6 +944,10 @@
def RefreshParentBlock(self):
self.ParentBlock.RefreshModel(False)
+ # Highlight the parent block
+ def HighlightParentBlock(self, highlight):
+ self.ParentBlock.SetHighlighted(highlight)
+
# Returns all the blocks connected to this connector
def GetConnectedBlocks(self):
blocks = []
@@ -974,6 +997,27 @@
return rect.InsideXY(pt.x, pt.y)
return False
+ # Draws the highlightment of this element if it is highlighted
+ def DrawHighlightment(self, dc):
+ dc.SetPen(wx.Pen(HIGHLIGHTCOLOR))
+ dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR))
+ parent_pos = self.ParentBlock.GetPosition()
+ posx = parent_pos[0] + self.Pos.x
+ posy = parent_pos[1] + self.Pos.y
+ width = CONNECTOR_SIZE
+ height = CONNECTOR_SIZE
+ if self.Direction[0] < 0:
+ posx += CONNECTOR_SIZE * self.Direction[0]
+ elif self.Direction[0] == 0:
+ posx -= 2
+ width = 5
+ if self.Direction[1] < 0:
+ posy += CONNECTOR_SIZE * self.Direction[1]
+ elif self.Direction[1] == 0:
+ posy -= 2
+ height = 5
+ dc.DrawRectangle(posx, posy, width, height)
+
# Draws the connector
def Draw(self, dc):
dc.SetPen(self.Pen)
@@ -1772,6 +1816,7 @@
connector = self.Parent.FindBlockConnector(new_pos)
if connector:
if handle == 0 and self.EndConnected != connector and connector.IsCompatible(self.GetEndConnectedType()):
+ connector.HighlightParentBlock(True)
connector.Connect((self, handle))
self.SetStartPointDirection(connector.GetDirection())
self.ConnectStartPoint(connector.GetPosition(), connector)
@@ -1780,6 +1825,7 @@
movey = pos.y - self.oldPos.y
self.Dragging = False
elif handle != 0 and self.StartConnected != connector and connector.IsCompatible(self.GetStartConnectedType()):
+ connector.HighlightParentBlock(True)
connector.Connect((self, handle))
self.SetEndPointDirection(connector.GetDirection())
self.ConnectEndPoint(connector.GetPosition(), connector)
@@ -1795,9 +1841,11 @@
elif handle == 0:
if self.StartConnected:
self.UnConnectStartPoint()
+ self.StartConnected.HighlightParentBlock(False)
self.MoveStartPoint(new_pos)
else:
if self.EndConnected:
+ self.EndConnected.HighlightParentBlock(False)
self.UnConnectEndPoint()
self.MoveEndPoint(new_pos)
return movex, movey
@@ -1815,6 +1863,27 @@
if self.EndConnected and self.EndPoint[1] in [WEST, NORTH]:
self.EndConnected.RefreshParentBlock()
+ # Draws the highlightment of this element if it is highlighted
+ def DrawHighlightment(self, dc):
+ if self.Highlighted:
+ dc.SetPen(wx.Pen(HIGHLIGHTCOLOR))
+ dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR))
+ # Draw the start and end points if they are not connected or the mouse is over them
+ if len(self.Points) > 0 and (not self.StartConnected or self.OverStart):
+ dc.DrawCircle(self.Points[0].x, self.Points[0].y, POINT_RADIUS + 2)
+ if len(self.Points) > 1 and (not self.EndConnected or self.OverEnd):
+ dc.DrawCircle(self.Points[-1].x, self.Points[-1].y, POINT_RADIUS + 2)
+ for i in xrange(len(self.Points) - 1):
+ posx = min(self.Points[i].x, self.Points[i + 1].x) - 2
+ posy = min(self.Points[i].y, self.Points[i + 1].y) - 2
+ width = abs(self.Points[i + 1].x - self.Points[i].x) + 5
+ height = abs(self.Points[i + 1].y - self.Points[i].y) + 5
+ dc.DrawRectangle(posx, posy, width, height)
+ if self.StartConnected is not None:
+ self.StartConnected.DrawHighlightment(dc)
+ if self.EndConnected is not None:
+ self.EndConnected.DrawHighlightment(dc)
+
# Draws the wire lines and points
def Draw(self, dc):
dc.SetPen(wx.BLACK_PEN)
@@ -1836,7 +1905,6 @@
dc.DrawPoint(self.Points[-1].x, self.Points[-1].y)
Graphic_Element.Draw(self, dc)
-
#-------------------------------------------------------------------------------
# Graphic comment element
#-------------------------------------------------------------------------------
@@ -1943,6 +2011,18 @@
# Edit the comment content
self.Parent.EditCommentContent(self)
+ # Draws the highlightment of this element if it is highlighted
+ def DrawHighlightment(self, dc):
+ if self.Highlighted:
+ dc.SetPen(wx.Pen(HIGHLIGHTCOLOR))
+ dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR))
+ polygon = [wx.Point(self.Pos.x - 2, self.Pos.y - 2),
+ wx.Point(self.Pos.x + self.Size[0] - 8, self.Pos.y - 2),
+ wx.Point(self.Pos.x + self.Size[0] + 2, self.Pos.y + 8),
+ wx.Point(self.Pos.x + self.Size[0] + 2, self.Pos.y + self.Size[1] + 2),
+ wx.Point(self.Pos.x - 2, self.Pos.y + self.Size[1] + 2)]
+ dc.DrawPolygon(polygon)
+
# Draws the comment and its content
def Draw(self, dc):
dc.SetPen(wx.BLACK_PEN)
@@ -1951,8 +2031,8 @@
polygon = [wx.Point(self.Pos.x, self.Pos.y),
wx.Point(self.Pos.x + self.Size[0] - 10, self.Pos.y),
wx.Point(self.Pos.x + self.Size[0], self.Pos.y + 10),
- wx.Point(self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] + 1),
- wx.Point(self.Pos.x, self.Pos.y + self.Size[1] + 1)]
+ wx.Point(self.Pos.x + self.Size[0], self.Pos.y + self.Size[1]),
+ wx.Point(self.Pos.x, self.Pos.y + self.Size[1])]
dc.DrawPolygon(polygon)
lines = [wx.Point(self.Pos.x + self.Size[0] - 10, self.Pos.y),
wx.Point(self.Pos.x + self.Size[0] - 10, self.Pos.y + 10),