graphics/GraphicCommons.py
changeset 1782 5b6ad7a7fd9d
parent 1777 c46ec818bdd7
child 1828 396da88d7b5c
equal deleted inserted replaced
1781:b112bfdde5cc 1782:5b6ad7a7fd9d
    29 from threading import Lock, Timer
    29 from threading import Lock, Timer
    30 
    30 
    31 from graphics.ToolTipProducer import ToolTipProducer
    31 from graphics.ToolTipProducer import ToolTipProducer
    32 from graphics.DebugDataConsumer import DebugDataConsumer
    32 from graphics.DebugDataConsumer import DebugDataConsumer
    33 
    33 
    34 #-------------------------------------------------------------------------------
    34 # -------------------------------------------------------------------------------
    35 #                               Common constants
    35 #                               Common constants
    36 #-------------------------------------------------------------------------------
    36 # -------------------------------------------------------------------------------
    37 
    37 
    38 """
    38 """
    39 Definition of constants for dimensions of graphic elements
    39 Definition of constants for dimensions of graphic elements
    40 """
    40 """
    41 
    41 
   209     pen = wx.Pen(colour, width, style)
   209     pen = wx.Pen(colour, width, style)
   210     pen.SetJoin(wx.JOIN_MITER)
   210     pen.SetJoin(wx.JOIN_MITER)
   211     pen.SetCap(wx.CAP_PROJECTING)
   211     pen.SetCap(wx.CAP_PROJECTING)
   212     return pen
   212     return pen
   213 
   213 
   214 #-------------------------------------------------------------------------------
   214 
       
   215 # -------------------------------------------------------------------------------
   215 #                    Helpers for highlighting text
   216 #                    Helpers for highlighting text
   216 #-------------------------------------------------------------------------------
   217 # -------------------------------------------------------------------------------
   217 
   218 
   218 
   219 
   219 def AddHighlight(highlights, infos):
   220 def AddHighlight(highlights, infos):
   220     RemoveHighlight(highlights, infos)
   221     RemoveHighlight(highlights, infos)
   221     highlights.append(infos)
   222     highlights.append(infos)
   246         dc.SetTextForeground(highlight_type[1])
   247         dc.SetTextForeground(highlight_type[1])
   247         dc.DrawText(part, x + offset_width, y)
   248         dc.DrawText(part, x + offset_width, y)
   248     dc.SetPen(current_pen)
   249     dc.SetPen(current_pen)
   249     dc.SetTextForeground(wx.BLACK)
   250     dc.SetTextForeground(wx.BLACK)
   250 
   251 
   251 #-------------------------------------------------------------------------------
   252 
       
   253 # -------------------------------------------------------------------------------
   252 #                           Graphic element base class
   254 #                           Graphic element base class
   253 #-------------------------------------------------------------------------------
   255 # -------------------------------------------------------------------------------
   254 
   256 
   255 
   257 
   256 class Graphic_Element(ToolTipProducer):
   258 class Graphic_Element(ToolTipProducer):
   257     """
   259     """
   258     Class that implements a generic graphic element
   260     Class that implements a generic graphic element
   701                     dc.DrawRectangle(x, y, HANDLE_SIZE, HANDLE_SIZE)
   703                     dc.DrawRectangle(x, y, HANDLE_SIZE, HANDLE_SIZE)
   702 
   704 
   703                 dc.SetUserScale(scalex, scaley)
   705                 dc.SetUserScale(scalex, scaley)
   704 
   706 
   705 
   707 
   706 #-------------------------------------------------------------------------------
   708 # -------------------------------------------------------------------------------
   707 #                           Group of graphic elements
   709 #                           Group of graphic elements
   708 #-------------------------------------------------------------------------------
   710 # -------------------------------------------------------------------------------
   709 
   711 
   710 
   712 
   711 class Graphic_Group(Graphic_Element):
   713 class Graphic_Group(Graphic_Element):
   712     """
   714     """
   713     Class that implements a group of graphic elements
   715     Class that implements a group of graphic elements
  1019     # Draws the handles of this element if it is selected
  1021     # Draws the handles of this element if it is selected
  1020     def Draw(self, dc):
  1022     def Draw(self, dc):
  1021         for element in self.Elements:
  1023         for element in self.Elements:
  1022             element.Draw(dc)
  1024             element.Draw(dc)
  1023 
  1025 
  1024 #-------------------------------------------------------------------------------
  1026 
       
  1027 # -------------------------------------------------------------------------------
  1025 #                         Connector for all types of blocks
  1028 #                         Connector for all types of blocks
  1026 #-------------------------------------------------------------------------------
  1029 # -------------------------------------------------------------------------------
  1027 
  1030 
  1028 
  1031 
  1029 class Connector(DebugDataConsumer, ToolTipProducer):
  1032 class Connector(DebugDataConsumer, ToolTipProducer):
  1030     """
  1033     """
  1031     Class that implements a connector for any type of block
  1034     Class that implements a connector for any type of block
  1469     # Draws the connector
  1472     # Draws the connector
  1470     def Draw(self, dc):
  1473     def Draw(self, dc):
  1471         if self.Selected:
  1474         if self.Selected:
  1472             dc.SetPen(MiterPen(wx.BLUE, 3))
  1475             dc.SetPen(MiterPen(wx.BLUE, 3))
  1473             dc.SetBrush(wx.WHITE_BRUSH)
  1476             dc.SetBrush(wx.WHITE_BRUSH)
  1474         #elif len(self.Highlights) > 0:
  1477         # elif len(self.Highlights) > 0:
  1475         #    dc.SetPen(MiterPen(self.Highlights[-1][1]))
  1478         #    dc.SetPen(MiterPen(self.Highlights[-1][1]))
  1476         #    dc.SetBrush(wx.Brush(self.Highlights[-1][0]))
  1479         #    dc.SetBrush(wx.Brush(self.Highlights[-1][0]))
  1477         else:
  1480         else:
  1478             if not self.Valid:
  1481             if not self.Valid:
  1479                 dc.SetPen(MiterPen(wx.RED))
  1482                 dc.SetPen(MiterPen(wx.RED))
  1554                             parent_pos[1] + self.Pos.y + CONNECTOR_SIZE * self.Direction[1] +
  1557                             parent_pos[1] + self.Pos.y + CONNECTOR_SIZE * self.Direction[1] +
  1555                             height * (self.Direction[1] - 1))
  1558                             height * (self.Direction[1] - 1))
  1556             dc.SetFont(self.ParentBlock.Parent.GetFont())
  1559             dc.SetFont(self.ParentBlock.Parent.GetFont())
  1557             dc.SetTextForeground(wx.BLACK)
  1560             dc.SetTextForeground(wx.BLACK)
  1558 
  1561 
  1559 #-------------------------------------------------------------------------------
  1562 
       
  1563 # -------------------------------------------------------------------------------
  1560 #                           Common Wire Element
  1564 #                           Common Wire Element
  1561 #-------------------------------------------------------------------------------
  1565 # -------------------------------------------------------------------------------
  1562 
  1566 
  1563 
  1567 
  1564 class Wire(Graphic_Element, DebugDataConsumer):
  1568 class Wire(Graphic_Element, DebugDataConsumer):
  1565     """
  1569     """
  1566     Class that implements a wire for connecting two blocks
  1570     Class that implements a wire for connecting two blocks
  2445 
  2449 
  2446     # Method called when a LeftDown event have been generated
  2450     # Method called when a LeftDown event have been generated
  2447     def OnLeftDown(self, event, dc, scaling):
  2451     def OnLeftDown(self, event, dc, scaling):
  2448         pos = GetScaledEventPosition(event, dc, scaling)
  2452         pos = GetScaledEventPosition(event, dc, scaling)
  2449         # Test if a point have been handled
  2453         # Test if a point have been handled
  2450         #result = self.TestPoint(pos)
  2454         # result = self.TestPoint(pos)
  2451         #if result != None:
  2455         # if result != None:
  2452         #    self.Handle = (HANDLE_POINT, result)
  2456         #    self.Handle = (HANDLE_POINT, result)
  2453         #    wx.CallAfter(self.Parent.SetCurrentCursor, 1)
  2457         #    wx.CallAfter(self.Parent.SetCurrentCursor, 1)
  2454         #else:
  2458         # else:
  2455         # Test if a segment have been handled
  2459         # Test if a segment have been handled
  2456         result = self.TestSegment(pos)
  2460         result = self.TestSegment(pos)
  2457         if result is not None:
  2461         if result is not None:
  2458             if result[1] in (NORTH, SOUTH):
  2462             if result[1] in (NORTH, SOUTH):
  2459                 wx.CallAfter(self.Parent.SetCurrentCursor, 4)
  2463                 wx.CallAfter(self.Parent.SetCurrentCursor, 4)
  2750                     dc.DrawText(self.ComputedValue, x, y)
  2754                     dc.DrawText(self.ComputedValue, x, y)
  2751             dc.SetFont(self.Parent.GetFont())
  2755             dc.SetFont(self.Parent.GetFont())
  2752             dc.SetTextForeground(wx.BLACK)
  2756             dc.SetTextForeground(wx.BLACK)
  2753 
  2757 
  2754 
  2758 
  2755 #-------------------------------------------------------------------------------
  2759 # -------------------------------------------------------------------------------
  2756 #                           Graphic comment element
  2760 #                           Graphic comment element
  2757 #-------------------------------------------------------------------------------
  2761 # -------------------------------------------------------------------------------
  2758 
  2762 
  2759 
  2763 
  2760 def FilterHighlightsByRow(highlights, row, length):
  2764 def FilterHighlightsByRow(highlights, row, length):
  2761     _highlights = []
  2765     _highlights = []
  2762     for start, end, highlight_type in highlights:
  2766     for start, end, highlight_type in highlights: