graphics/GraphicCommons.py
changeset 90 2245e8776086
parent 80 c798a68c5560
child 98 ec5d7af033d8
equal deleted inserted replaced
89:a6ff2b3fcc25 90:2245e8776086
   227         self.lastBox = self.currentBox
   227         self.lastBox = self.currentBox
   228         self.currentBox = None
   228         self.currentBox = None
   229         self.Redraw()
   229         self.Redraw()
   230 
   230 
   231     # Method that erase the last box and draw the new box
   231     # Method that erase the last box and draw the new box
   232     def Redraw(self):
   232     def Redraw(self, dc = None):
   233         dc = self.drawingSurface.GetLogicalDC()
   233         if not dc:
       
   234             dc = self.drawingSurface.GetLogicalDC()
   234         dc.SetPen(wx.Pen(wx.WHITE, 1, wx.DOT))
   235         dc.SetPen(wx.Pen(wx.WHITE, 1, wx.DOT))
   235         dc.SetBrush(wx.TRANSPARENT_BRUSH)
   236         dc.SetBrush(wx.TRANSPARENT_BRUSH)
   236         dc.SetLogicalFunction(wx.XOR)
   237         dc.SetLogicalFunction(wx.XOR)
   237         if self.lastBox:
   238         if self.lastBox:
   238             # Erase last box
   239             # Erase last box
   240                 self.lastBox.height)
   241                 self.lastBox.height)
   241         if self.currentBox:
   242         if self.currentBox:
   242             # Draw current box
   243             # Draw current box
   243             dc.DrawRectangle(self.currentBox.x, self.currentBox.y, self.currentBox.width,
   244             dc.DrawRectangle(self.currentBox.x, self.currentBox.y, self.currentBox.width,
   244                 self.currentBox.height)
   245                 self.currentBox.height)
   245 
   246     
   246     # Erase last box
   247     # Erase last box
   247     def Erase(self):
   248     def Erase(self, dc = None):
   248         dc = self.drawingSurface.GetLogicalDC()
   249         if not dc:
       
   250             dc = self.drawingSurface.GetLogicalDC()
   249         dc.SetPen(wx.Pen(wx.WHITE, 1, wx.DOT))
   251         dc.SetPen(wx.Pen(wx.WHITE, 1, wx.DOT))
   250         dc.SetBrush(wx.TRANSPARENT_BRUSH)
   252         dc.SetBrush(wx.TRANSPARENT_BRUSH)
   251         dc.SetLogicalFunction(wx.XOR)
   253         dc.SetLogicalFunction(wx.XOR)
   252         if self.lastBox:
   254         if self.lastBox:
   253             dc.DrawRectangle(self.lastBox.x, self.lastBox.y, self.lastBox.width,
   255             dc.DrawRectangle(self.lastBox.x, self.lastBox.y, self.lastBox.width,
   254                 self.lastBox.height)
   256                 self.lastBox.height)
   255         
   257     
   256     # Draw current box
   258     # Draw current box
   257     def Draw(self):
   259     def Draw(self, dc = None):
   258         dc = self.drawingSurface.GetLogicalDC()
   260         if not dc:
       
   261             dc = self.drawingSurface.GetLogicalDC()
   259         dc.SetPen(wx.Pen(wx.WHITE, 1, wx.DOT))
   262         dc.SetPen(wx.Pen(wx.WHITE, 1, wx.DOT))
   260         dc.SetBrush(wx.TRANSPARENT_BRUSH)
   263         dc.SetBrush(wx.TRANSPARENT_BRUSH)
   261         dc.SetLogicalFunction(wx.XOR)
   264         dc.SetLogicalFunction(wx.XOR)
   262         if self.currentBox:
   265         if self.currentBox:
   263             # Draw current box
   266             # Draw current box
   264             dc.DrawRectangle(self.currentBox.x, self.currentBox.y, self.currentBox.width,
   267             dc.DrawRectangle(self.currentBox.x, self.currentBox.y, self.currentBox.width,
   265                 self.currentBox.height)
   268                 self.currentBox.height)
   266 
       
   267 
   269 
   268 #-------------------------------------------------------------------------------
   270 #-------------------------------------------------------------------------------
   269 #                           Graphic element base class
   271 #                           Graphic element base class
   270 #-------------------------------------------------------------------------------
   272 #-------------------------------------------------------------------------------
   271 
   273 
   449                 self.Dragging = True
   451                 self.Dragging = True
   450             # If a dragging have been initiated, refreshes the element state
   452             # If a dragging have been initiated, refreshes the element state
   451             if self.Dragging:
   453             if self.Dragging:
   452                 self.oldPos = pos
   454                 self.oldPos = pos
   453                 self.ProcessDragging(movex, movey)
   455                 self.ProcessDragging(movex, movey)
       
   456             return True
   454         # If cursor just pass over the element, changes the cursor if it is on a handle
   457         # If cursor just pass over the element, changes the cursor if it is on a handle
   455         else:
   458         else:
   456             pos = event.GetLogicalPosition(dc)
   459             pos = event.GetLogicalPosition(dc)
   457             handle = self.TestHandle(pos)
   460             handle = self.TestHandle(pos)
   458             # Find which type of handle have been clicked,
   461             # Find which type of handle have been clicked,
   459             # Save a resize event and change the cursor
   462             # Save a resize event and change the cursor
   460             cursor = HANDLE_CURSORS.get(handle, 0)
   463             cursor = HANDLE_CURSORS.get(handle, 0)
   461             if cursor != self.CurrentCursor:
   464             if cursor != self.CurrentCursor:
   462                 self.Parent.SetCursor(CURSORS[cursor])
   465                 self.Parent.SetCursor(CURSORS[cursor])
   463                 self.CurrentCursor = cursor
   466                 self.CurrentCursor = cursor
       
   467             return False
   464 
   468 
   465     # Moves the element
   469     # Moves the element
   466     def Move(self, dx, dy, exclude = []):
   470     def Move(self, dx, dy, exclude = []):
   467         self.Pos.x += dx
   471         self.Pos.x += dx
   468         self.Pos.y += dy
   472         self.Pos.y += dy
  1576                         wx.CallAfter(self.Parent.SetCursor, CURSORS[4])
  1580                         wx.CallAfter(self.Parent.SetCursor, CURSORS[4])
  1577                 elif result[1] in (EAST, WEST):
  1581                 elif result[1] in (EAST, WEST):
  1578                     if self.CurrentCursor != 5:
  1582                     if self.CurrentCursor != 5:
  1579                         self.CurrentCursor = 5
  1583                         self.CurrentCursor = 5
  1580                         wx.CallAfter(self.Parent.SetCursor, CURSORS[5])
  1584                         wx.CallAfter(self.Parent.SetCursor, CURSORS[5])
       
  1585                 return False
  1581             else:
  1586             else:
  1582                 # Test if a point has been handled
  1587                 # Test if a point has been handled
  1583                 #result = self.TestPoint(pos)
  1588                 #result = self.TestPoint(pos)
  1584                 #if result != None:
  1589                 #if result != None:
  1585                 #    if result == 0 and self.StartConnected:
  1590                 #    if result == 0 and self.StartConnected:
  1588                 #        self.OverEnd = True
  1593                 #        self.OverEnd = True
  1589                 #else:
  1594                 #else:
  1590                 #    self.OverStart = False
  1595                 #    self.OverStart = False
  1591                 #    self.OverEnd = False
  1596                 #    self.OverEnd = False
  1592                 # Execute the default method for a graphic element
  1597                 # Execute the default method for a graphic element
  1593                 Graphic_Element.OnMotion(self, event, dc, scaling)
  1598                 return Graphic_Element.OnMotion(self, event, dc, scaling)
  1594         else:
  1599         else:
  1595             # Execute the default method for a graphic element
  1600             # Execute the default method for a graphic element
  1596             Graphic_Element.OnMotion(self, event, dc, scaling)
  1601             return Graphic_Element.OnMotion(self, event, dc, scaling)
  1597     
  1602     
  1598     # Refreshes the wire state according to move defined and handle selected
  1603     # Refreshes the wire state according to move defined and handle selected
  1599     def ProcessDragging(self, movex, movey):
  1604     def ProcessDragging(self, movex, movey):
  1600         handle_type, handle = self.Handle
  1605         handle_type, handle = self.Handle
  1601         # A point has been handled
  1606         # A point has been handled