Viewer.py
changeset 213 4931959ea256
parent 206 f7c85a5939dc
child 216 93af9ac5aeaf
equal deleted inserted replaced
212:e36ba4f15fc8 213:4931959ea256
   304         self.SetBackgroundColour(wx.Colour(255,255,255))
   304         self.SetBackgroundColour(wx.Colour(255,255,255))
   305         self.ResetView()
   305         self.ResetView()
   306         self.Scaling = None
   306         self.Scaling = None
   307         self.DrawGrid = True
   307         self.DrawGrid = True
   308         self.GridBrush = wx.TRANSPARENT_BRUSH
   308         self.GridBrush = wx.TRANSPARENT_BRUSH
       
   309         self.PageSize = None
       
   310         self.PagePen = wx.TRANSPARENT_PEN
   309         self.DrawingWire = False
   311         self.DrawingWire = False
   310         self.current_id = 0
   312         self.current_id = 0
   311         self.TagName = tagname
   313         self.TagName = tagname
   312         
   314         
   313         # Initialize Block, Wire and Comment numbers
   315         # Initialize Block, Wire and Comment numbers
   322         self.Controler = controler
   324         self.Controler = controler
   323         
   325         
   324         self.SetDropTarget(ViewerDropTarget(self))
   326         self.SetDropTarget(ViewerDropTarget(self))
   325         
   327         
   326         dc = wx.ClientDC(self)
   328         dc = wx.ClientDC(self)
   327         font = wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = faces["mono"])
   329         font = wx.Font(faces["size"], wx.SWISS, wx.NORMAL, wx.NORMAL, faceName = faces["mono"])
   328         dc.SetFont(font)
   330         dc.SetFont(font)
   329         width, height = dc.GetTextExtent("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
   331         width, height = dc.GetTextExtent("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
   330         while width > 260:
   332         while width > 260:
   331             faces["size"] -= 1
   333             faces["size"] -= 1
   332             font = wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = faces["mono"])
   334             font = wx.Font(faces["size"], wx.SWISS, wx.NORMAL, wx.NORMAL, faceName = faces["mono"])
   333             dc.SetFont(font)
   335             dc.SetFont(font)
   334             width, height = dc.GetTextExtent("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
   336             width, height = dc.GetTextExtent("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
   335         self.SetFont(font)
   337         self.SetFont(font)
   336         
   338         
   337         # Link Viewer event to corresponding methods
   339         # Link Viewer event to corresponding methods
   342         self.Bind(wx.EVT_RIGHT_DOWN, self.OnViewerRightDown)
   344         self.Bind(wx.EVT_RIGHT_DOWN, self.OnViewerRightDown)
   343         self.Bind(wx.EVT_RIGHT_UP, self.OnViewerRightUp)
   345         self.Bind(wx.EVT_RIGHT_UP, self.OnViewerRightUp)
   344         self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveViewer)
   346         self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveViewer)
   345         self.Bind(wx.EVT_MOTION, self.OnViewerMotion)
   347         self.Bind(wx.EVT_MOTION, self.OnViewerMotion)
   346         self.Bind(wx.EVT_CHAR, self.OnChar)
   348         self.Bind(wx.EVT_CHAR, self.OnChar)
   347         self.Bind(wx.EVT_SCROLLWIN, self.OnMoveWindow)
   349         #self.Bind(wx.EVT_SCROLLWIN, self.OnMoveWindow)
   348         self.Bind(wx.EVT_SIZE, self.OnMoveWindow)
   350         self.Bind(wx.EVT_SIZE, self.OnMoveWindow)
   349     
   351     
   350     def GetScrolledRect(self, rect):
   352     def GetScrolledRect(self, rect):
   351         rect.x, rect.y = self.CalcScrolledPosition(rect.x, rect.y)
   353         rect.x, rect.y = self.CalcScrolledPosition(rect.x, rect.y)
   352         return rect
   354         return rect
   372     def __del__(self):
   374     def __del__(self):
   373         self.ResetView()
   375         self.ResetView()
   374 
   376 
   375     def GetLogicalDC(self, buffered=False):
   377     def GetLogicalDC(self, buffered=False):
   376         if buffered:
   378         if buffered:
   377             dc = wx.BufferedPaintDC(self)
   379             dc = wx.AutoBufferedPaintDC(self)
   378         else:
   380         else:
   379             dc = wx.ClientDC(self)
   381             dc = wx.ClientDC(self)
   380         dc.SetFont(self.GetFont())
   382         dc.SetFont(self.GetFont())
   381         if wx.VERSION >= (2, 6, 0):
   383         if wx.VERSION >= (2, 6, 0):
   382             self.DoPrepareDC(dc)
   384             self.DoPrepareDC(dc)
   487             else:
   489             else:
   488                 self.GridBrush = wx.TRANSPARENT_BRUSH
   490                 self.GridBrush = wx.TRANSPARENT_BRUSH
   489         else:
   491         else:
   490             self.Scaling = None
   492             self.Scaling = None
   491             self.GridBrush = wx.TRANSPARENT_BRUSH
   493             self.GridBrush = wx.TRANSPARENT_BRUSH
       
   494         page_size = properties["pageSize"]
       
   495         if page_size != (0, 0):
       
   496             self.PageSize = map(int, page_size)
       
   497             self.PagePen = wx.Pen(wx.Colour(180, 180, 180))
       
   498         else:
       
   499             self.PageSize = None
       
   500             self.PagePen = wx.TRANSPARENT_PEN
   492         if refresh:
   501         if refresh:
   493             self.Refresh(False)
   502             self.Refresh(False)
   494         
   503         
   495         
   504         
   496 #-------------------------------------------------------------------------------
   505 #-------------------------------------------------------------------------------
   522         for wire in to_delete:
   531         for wire in to_delete:
   523             wire.Delete()
   532             wire.Delete()
   524     
   533     
   525         self.Refresh(False)
   534         self.Refresh(False)
   526     
   535     
   527     def RefreshScrollBars(self):
   536     def GetMaxSize(self):
   528         xstart, ystart = self.GetViewStart()
       
   529         window_size = self.GetClientSize()
       
   530         maxx = maxy = 0
   537         maxx = maxy = 0
   531         for element in self.GetElements():
   538         for element in self.GetElements():
   532             bbox = element.GetBoundingBox()
   539             bbox = element.GetBoundingBox()
   533             maxx = max(maxx, bbox.x + bbox.width)
   540             maxx = max(maxx, bbox.x + bbox.width)
   534             maxy = max(maxy, bbox.y + bbox.height)
   541             maxy = max(maxy, bbox.y + bbox.height)
       
   542         return maxx, maxy
       
   543     
       
   544     def RefreshScrollBars(self):
       
   545         xstart, ystart = self.GetViewStart()
       
   546         window_size = self.GetClientSize()
       
   547         maxx, maxy = self.GetMaxSize()
   535         maxx = max(maxx + WINDOW_BORDER, xstart * SCROLLBAR_UNIT + window_size[0])
   548         maxx = max(maxx + WINDOW_BORDER, xstart * SCROLLBAR_UNIT + window_size[0])
   536         maxy = max(maxy + WINDOW_BORDER, ystart * SCROLLBAR_UNIT + window_size[1])
   549         maxy = max(maxy + WINDOW_BORDER, ystart * SCROLLBAR_UNIT + window_size[1])
   537         if self.rubberBand.IsShown():
   550         if self.rubberBand.IsShown():
   538             extent = self.rubberBand.GetCurrentExtent()
   551             extent = self.rubberBand.GetCurrentExtent()
   539             maxx = max(maxx, extent.x + extent.width)
   552             maxx = max(maxx, extent.x + extent.width)
   540             maxy = max(maxy, extent.y + extent.height)
   553             maxy = max(maxy, extent.y + extent.height)
   541         self.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, 
   554         self.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, 
   542             maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, xstart, ystart, True)
   555             round(maxx / SCROLLBAR_UNIT), round(maxy / SCROLLBAR_UNIT), 
       
   556             xstart, ystart, True)
   543         
   557         
   544     # Load instance from given informations
   558     # Load instance from given informations
   545     def loadInstance(self, instance, ids):
   559     def loadInstance(self, instance, ids):
   546         ids.append(instance["id"])
   560         ids.append(instance["id"])
   547         self.current_id = max(self.current_id, instance["id"]) 
   561         self.current_id = max(self.current_id, instance["id"]) 
  2318     def OnMoveWindow(self, event):
  2332     def OnMoveWindow(self, event):
  2319         self.GetBestSize()
  2333         self.GetBestSize()
  2320         self.RefreshScrollBars()
  2334         self.RefreshScrollBars()
  2321         event.Skip()
  2335         event.Skip()
  2322 
  2336 
  2323     def OnPaint(self, event):
  2337     def DoDrawing(self, dc, printing = False):
  2324         dc = self.GetLogicalDC(True)
  2338         if printing:
  2325         dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
  2339             if getattr(dc, "printing", False):
  2326         dc.Clear()
  2340                 font = wx.Font(self.GetFont().GetPointSize(), wx.MODERN, wx.NORMAL, wx.NORMAL)
  2327         dc.BeginDrawing()
  2341                 dc.SetFont(font)
  2328         if self.Scaling and self.DrawGrid:
  2342             else:
       
  2343                 dc.SetFont(self.GetFont())
       
  2344         else:
       
  2345             dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
       
  2346             dc.Clear()
       
  2347             dc.BeginDrawing()
       
  2348         if self.Scaling is not None and self.DrawGrid and not printing:
  2329             dc.SetPen(wx.TRANSPARENT_PEN)
  2349             dc.SetPen(wx.TRANSPARENT_PEN)
  2330             dc.SetBrush(self.GridBrush)
  2350             dc.SetBrush(self.GridBrush)
       
  2351             xstart, ystart = self.GetViewStart()
       
  2352             window_size = self.GetClientSize()
  2331             width, height = self.GetVirtualSize()
  2353             width, height = self.GetVirtualSize()
       
  2354             width = max(width, xstart * SCROLLBAR_UNIT + window_size[0])
       
  2355             height = max(height, ystart * SCROLLBAR_UNIT + window_size[1])
  2332             dc.DrawRectangle(0, 0, width, height)
  2356             dc.DrawRectangle(0, 0, width, height)
       
  2357         if self.PageSize is not None and not printing:
       
  2358             dc.SetPen(self.PagePen)
       
  2359             xstart, ystart = self.GetViewStart()
       
  2360             window_size = self.GetClientSize()
       
  2361             for x in xrange(self.PageSize[0] - (xstart * SCROLLBAR_UNIT) % self.PageSize[0], window_size[0], self.PageSize[0]):
       
  2362                 dc.DrawLine(xstart * SCROLLBAR_UNIT + x + 1, ystart * SCROLLBAR_UNIT, 
       
  2363                             xstart * SCROLLBAR_UNIT + x + 1, ystart * SCROLLBAR_UNIT + window_size[1])
       
  2364             for y in xrange(self.PageSize[1] - (ystart * SCROLLBAR_UNIT) % self.PageSize[1], window_size[1], self.PageSize[1]):
       
  2365                 dc.DrawLine(xstart * SCROLLBAR_UNIT, ystart * SCROLLBAR_UNIT + y + 1, 
       
  2366                             xstart * SCROLLBAR_UNIT + window_size[0], ystart * SCROLLBAR_UNIT + y + 1)
  2333         
  2367         
  2334         # Draw all elements
  2368         # Draw all elements
  2335         for comment in self.Comments:
  2369         for comment in self.Comments:
  2336             if comment != self.SelectedElement:
  2370             if comment != self.SelectedElement:
  2337                 comment.Draw(dc)
  2371                 comment.Draw(dc)
  2341         for block in self.Blocks:
  2375         for block in self.Blocks:
  2342             if block != self.SelectedElement:
  2376             if block != self.SelectedElement:
  2343                 block.Draw(dc)
  2377                 block.Draw(dc)
  2344         
  2378         
  2345         if self.SelectedElement:
  2379         if self.SelectedElement:
  2346             self.SelectedElement.Draw(dc)
  2380                 self.SelectedElement.Draw(dc)
  2347         
  2381         
  2348         if self.rubberBand.IsShown():
  2382         if not printing:
  2349             self.rubberBand.Draw(dc)
  2383             if self.rubberBand.IsShown():
  2350         dc.EndDrawing()
  2384                 self.rubberBand.Draw(dc)
  2351         event.Skip()
  2385             dc.EndDrawing()
  2352 
  2386 
  2353 
  2387     def OnPaint(self, event):
       
  2388         self.DoDrawing(self.GetLogicalDC(True))
       
  2389         event.Skip()
       
  2390 
       
  2391