# HG changeset patch # User lbessard # Date 1199294131 -3600 # Node ID 06d28f03f6f4fe5f0dbfee1e5b0215ec540662d9 # Parent c2d09340200517ff1f70122aa08c28bf507efabb Adding highlighting on group or element when mouse is over diff -r c2d093402005 -r 06d28f03f6f4 Viewer.py --- a/Viewer.py Mon Dec 31 13:36:11 2007 +0100 +++ b/Viewer.py Wed Jan 02 18:15:31 2008 +0100 @@ -294,6 +294,7 @@ self.Bind(wx.EVT_LEFT_UP, self.OnViewerLeftUp) self.Bind(wx.EVT_LEFT_DCLICK, self.OnViewerLeftDClick) self.Bind(wx.EVT_RIGHT_UP, self.OnViewerRightUp) + self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveViewer) self.Bind(wx.EVT_MOTION, self.OnViewerMotion) self.Bind(wx.EVT_CHAR, self.OnChar) if wx.VERSION < (2, 7, 0): @@ -389,6 +390,7 @@ self.Wires = {} self.Comments = {} self.SelectedElement = None + self.HighlightedElement = None # Remove all elements def CleanView(self): @@ -1147,21 +1149,41 @@ event.Skip() def OnViewerMotion(self, event): + refresh = False + dc = self.GetLogicalDC() + pos = GetScaledEventPosition(event, dc, self.Scaling) + if not event.Dragging(): + highlighted = self.FindElement(pos) + if self.HighlightedElement is not None and self.HighlightedElement != highlighted: + self.HighlightedElement.SetHighlighted(False) + self.HighlightedElement = None + refresh = True + if highlighted is not None: + highlighted.SetHighlighted(True) + refresh = True + self.HighlightedElement = highlighted if self.rubberBand.IsShown(): - self.rubberBand.OnMotion(event, self.GetLogicalDC(), self.Scaling) + self.rubberBand.OnMotion(event, dc, self.Scaling) elif self.Mode == MODE_SELECTION and self.SelectedElement: if self.DrawingWire: - dc = self.GetLogicalDC() - pos = GetScaledEventPosition(event, dc, self.Scaling) connector = self.FindBlockConnector(pos, False) if not connector or self.SelectedElement.EndConnected == None: self.SelectedElement.ResetPoints() self.SelectedElement.OnMotion(event, dc, self.Scaling) self.SelectedElement.GeneratePoints() - self.Refresh(False) - elif self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling): - self.Refresh(False) + refresh = True + elif self.SelectedElement.OnMotion(event, dc, self.Scaling): + refresh = True self.UpdateScrollPos(event) + if refresh: + self.Refresh(False) + event.Skip() + + def OnLeaveViewer(self, event): + if self.HighlightedElement is not None: + self.HighlightedElement.SetHighlighted(False) + self.HighlightedElement = None + self.Refresh(False) event.Skip() def UpdateScrollPos(self, event): @@ -2133,6 +2155,16 @@ dc.DrawLine(i * self.Scaling[0], 0, i * self.Scaling[0], height) for i in xrange(1, height / self.Scaling[1] + 1): dc.DrawLine(0, i * self.Scaling[1], width, i * self.Scaling[1]) + + # Draw highlighted elements + for comment in self.Comments: + comment.DrawHighlightment(dc) + for wire in self.Wires: + wire.DrawHighlightment(dc) + for block in self.Blocks: + block.DrawHighlightment(dc) + + # Draw all elements for comment in self.Comments: if comment != self.SelectedElement: comment.Draw(dc) @@ -2144,6 +2176,7 @@ block.Draw(dc) if self.SelectedElement: self.SelectedElement.Draw(dc) + if self.rubberBand.IsShown(): self.rubberBand.Draw(dc) dc.EndDrawing() diff -r c2d093402005 -r 06d28f03f6f4 graphics/FBD_Objects.py --- a/graphics/FBD_Objects.py Mon Dec 31 13:36:11 2007 +0100 +++ b/graphics/FBD_Objects.py Wed Jan 02 18:15:31 2008 +0100 @@ -357,9 +357,9 @@ # Draw block execution order dc.DrawText(str(self.ExecutionOrder), self.Pos.x + self.Size[0] - self.ExecutionOrderSize[0], self.Pos.y + self.Size[1] + 2) + dc.SetTextForeground(wx.BLACK) Graphic_Element.Draw(self, dc) - dc.SetTextForeground(wx.BLACK) - + #------------------------------------------------------------------------------- # Function Block Diagram Variable @@ -734,3 +734,4 @@ if self.Connector: self.Connector.Draw(dc) Graphic_Element.Draw(self, dc) + diff -r c2d093402005 -r 06d28f03f6f4 graphics/GraphicCommons.py --- 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), diff -r c2d093402005 -r 06d28f03f6f4 graphics/LD_Objects.py --- a/graphics/LD_Objects.py Mon Dec 31 13:36:11 2007 +0100 +++ b/graphics/LD_Objects.py Wed Jan 02 18:15:31 2008 +0100 @@ -322,7 +322,7 @@ if connector: connector.Draw(dc) Graphic_Element.Draw(self, dc) - + #------------------------------------------------------------------------------- # Ladder Diagram Contact @@ -501,6 +501,15 @@ if move: self.Output.RefreshWires() + # 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 two rectangles for representing the contact + dc.DrawRectangle(self.Pos.x - 2, self.Pos.y - 2, 6, self.Size[1] + 5) + dc.DrawRectangle(self.Pos.x + self.Size[0] - 3, self.Pos.y - 2, 6, self.Size[1] + 5) + # Draws contact def Draw(self, dc): dc.SetPen(wx.BLACK_PEN) @@ -526,7 +535,7 @@ self.Input.Draw(dc) self.Output.Draw(dc) Graphic_Element.Draw(self, dc) - + #------------------------------------------------------------------------------- # Ladder Diagram Coil @@ -705,6 +714,15 @@ if move: self.Output.RefreshWires() + # Draws the highlightment of this element if it is highlighted + def DrawHighlightment(self, dc): + if self.Highlighted: + dc.SetPen(wx.Pen(HIGHLIGHTCOLOR, 6, wx.SOLID)) + dc.SetBrush(wx.TRANSPARENT_BRUSH) + # Draw a two circle arcs for representing the coil + dc.DrawEllipticArc(self.Pos.x, self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1, self.Size[0], int(self.Size[1] * sqrt(2)) - 1, 135, 225) + dc.DrawEllipticArc(self.Pos.x, self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1, self.Size[0], int(self.Size[1] * sqrt(2)) - 1, -45, 45) + # Draws coil def Draw(self, dc): dc.SetPen(wx.Pen(wx.BLACK, 2, wx.SOLID)) @@ -732,3 +750,4 @@ self.Input.Draw(dc) self.Output.Draw(dc) Graphic_Element.Draw(self, dc) + diff -r c2d093402005 -r 06d28f03f6f4 graphics/SFC_Objects.py --- a/graphics/SFC_Objects.py Mon Dec 31 13:36:11 2007 +0100 +++ b/graphics/SFC_Objects.py Wed Jan 02 18:15:31 2008 +0100 @@ -446,6 +446,7 @@ if self.Action: self.Action.Draw(dc) Graphic_Element.Draw(self, dc) + #------------------------------------------------------------------------------- # Sequencial Function Chart Transition @@ -785,6 +786,7 @@ if self.Type == "connection": self.Condition.Draw(dc) Graphic_Element.Draw(self, dc) + #------------------------------------------------------------------------------- # Sequencial Function Chart Divergence and Convergence @@ -1168,6 +1170,19 @@ for output in self.Outputs: output.RefreshWires() + # 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 two rectangles for representing the contact + posx = self.Pos.x - 2 + width = self.Size[0] + 5 + if self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]: + posx -= SFC_SIMULTANEOUS_SEQUENCE_EXTRA + width += SFC_SIMULTANEOUS_SEQUENCE_EXTRA * 2 + dc.DrawRectangle(posx, self.Pos.y - 2, width, self.Size[1] + 5) + # Draws divergence def Draw(self, dc): dc.SetPen(wx.BLACK_PEN) @@ -1186,6 +1201,7 @@ for output in self.Outputs: output.Draw(dc) Graphic_Element.Draw(self, dc) + #------------------------------------------------------------------------------- # Sequencial Function Chart Jump to Step @@ -1349,6 +1365,16 @@ if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: self.RefreshInputModel() + # 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)) + points = [wx.Point(self.Pos.x - 3, self.Pos.y - 2), + wx.Point(self.Pos.x + self.Size[0] + 4, self.Pos.y - 2), + wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1] + 4)] + dc.DrawPolygon(points) + # Draws divergence def Draw(self, dc): dc.SetPen(wx.BLACK_PEN) @@ -1367,7 +1393,7 @@ if self.Input: self.Input.Draw(dc) Graphic_Element.Draw(self, dc) - + #------------------------------------------------------------------------------- # Sequencial Function Chart Action Block @@ -1565,4 +1591,4 @@ # Draw input connector self.Input.Draw(dc) Graphic_Element.Draw(self, dc) - +