/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/UI/view.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/UI/view.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 565 by jonathan, Wed Mar 26 11:07:40 2003 UTC revision 855 by frank, Wed May 7 18:24:27 2003 UTC
# Line 11  Classes for display of a map and interac Line 11  Classes for display of a map and interac
11    
12  __version__ = "$Revision$"  __version__ = "$Revision$"
13    
14    import sys
15    
16  from math import hypot  from math import hypot
17    
18  from wxPython.wx import wxWindow,\  from wxPython.wx import wxWindow,\
19       wxPaintDC, wxColour, wxClientDC, wxINVERT, wxTRANSPARENT_BRUSH, wxFont,\       wxPaintDC, wxColour, wxClientDC, wxINVERT, wxTRANSPARENT_BRUSH, wxFont,\
20       EVT_PAINT, EVT_LEFT_DOWN, EVT_LEFT_UP, EVT_MOTION, EVT_LEAVE_WINDOW       EVT_PAINT, EVT_LEFT_DOWN, EVT_LEFT_UP, EVT_MOTION, EVT_LEAVE_WINDOW, \
21         wxBITMAP_TYPE_XPM, wxBeginBusyCursor, wxEndBusyCursor, wxCursor, \
22         wxImageFromBitmap
23    
24    
25  from wxPython import wx  from wxPython import wx
# Line 32  from Thuban.Model.label import ALIGN_CEN Line 36  from Thuban.Model.label import ALIGN_CEN
36  from Thuban.Lib.connector import Publisher  from Thuban.Lib.connector import Publisher
37  from Thuban.Model.color import Color  from Thuban.Model.color import Color
38    
39    import resource
40    
41  from selection import Selection  from selection import Selection
42  from renderer import ScreenRenderer, PrinterRender  from renderer import ScreenRenderer, PrinterRender
43    
44  import labeldialog  import labeldialog
45    
46  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION, \
47                         SCALE_CHANGED
48    
49    
50  #  #
# Line 259  class MapCanvas(wxWindow, Publisher): Line 266  class MapCanvas(wxWindow, Publisher):
266      """A widget that displays a map and offers some interaction"""      """A widget that displays a map and offers some interaction"""
267    
268      # Some messages that can be subscribed/unsubscribed directly through      # Some messages that can be subscribed/unsubscribed directly through
269      # the MapCanvas come in fact from other objects. This is a map to      # the MapCanvas come in fact from other objects. This is a dict
270      # map those messages to the names of the instance variables they      # mapping those messages to the names of the instance variables they
271      # actually come from. This delegation is implemented in the      # actually come from. The delegation is implemented in the Subscribe
272      # Subscribe and unsubscribed methods      # and Unsubscribe methods
273      delegated_messages = {LAYER_SELECTED: "selection",      delegated_messages = {LAYER_SELECTED: "selection",
274                            SHAPES_SELECTED: "selection"}                            SHAPES_SELECTED: "selection"}
275    
# Line 271  class MapCanvas(wxWindow, Publisher): Line 278  class MapCanvas(wxWindow, Publisher):
278      delegated_methods = {"SelectLayer": "selection",      delegated_methods = {"SelectLayer": "selection",
279                           "SelectShapes": "selection",                           "SelectShapes": "selection",
280                           "SelectedLayer": "selection",                           "SelectedLayer": "selection",
281                           "HasSelectedLayer": "selection"}                           "HasSelectedLayer": "selection",
282                             "HasSelectedShapes": "selection"}
283    
284      def __init__(self, parent, winid):      def __init__(self, parent, winid):
285          wxWindow.__init__(self, parent, winid)          wxWindow.__init__(self, parent, winid)
# Line 353  class MapCanvas(wxWindow, Publisher): Line 361  class MapCanvas(wxWindow, Publisher):
361    
362      def OnPaint(self, event):      def OnPaint(self, event):
363          dc = wxPaintDC(self)          dc = wxPaintDC(self)
364          if self.map is not None and self.map.HasLayers():          clear = self.map is None or not self.map.HasLayers()
365              self.do_redraw()  
366          else:          #wxBeginBusyCursor()
367    
368            if not clear:
369                try:
370                    self.do_redraw()
371                except:
372                    print "Error during drawing:", sys.exc_info()[0]
373                    clear = True
374    
375            if clear:
376              # If we've got no map or if the map is empty, simply clear              # If we've got no map or if the map is empty, simply clear
377              # the screen.              # the screen.
378    
# Line 367  class MapCanvas(wxWindow, Publisher): Line 384  class MapCanvas(wxWindow, Publisher):
384              dc.Clear()              dc.Clear()
385              dc.EndDrawing()              dc.EndDrawing()
386    
387            #wxEndBusyCursor()
388    
389      def do_redraw(self):      def do_redraw(self):
390          # This should only be called if we have a non-empty map.          # This should only be called if we have a non-empty map.
391    
# Line 383  class MapCanvas(wxWindow, Publisher): Line 402  class MapCanvas(wxWindow, Publisher):
402              dc.BeginDrawing()              dc.BeginDrawing()
403    
404              # clear the background              # clear the background
405              dc.SetBrush(wx.wxWHITE_BRUSH)              #dc.SetBrush(wx.wxWHITE_BRUSH)
406              dc.SetPen(wx.wxTRANSPARENT_PEN)              #dc.SetPen(wx.wxTRANSPARENT_PEN)
407              dc.DrawRectangle(0, 0, width, height)              #dc.DrawRectangle(0, 0, width, height)
408                dc.SetBackground(wx.wxWHITE_BRUSH)
409                dc.Clear()
410    
411              selected_layer = self.selection.SelectedLayer()              selected_layer = self.selection.SelectedLayer()
412              selected_shapes = self.selection.SelectedShapes()              selected_shapes = self.selection.SelectedShapes()
# Line 455  class MapCanvas(wxWindow, Publisher): Line 476  class MapCanvas(wxWindow, Publisher):
476          self.scale = scale          self.scale = scale
477          self.offset = offset          self.offset = offset
478          self.full_redraw()          self.full_redraw()
479            self.issue(SCALE_CHANGED, scale)
480    
481      def proj_to_win(self, x, y):      def proj_to_win(self, x, y):
482          """\          """\
# Line 479  class MapCanvas(wxWindow, Publisher): Line 501  class MapCanvas(wxWindow, Publisher):
501          width, height = self.GetSizeTuple()          width, height = self.GetSizeTuple()
502          llx, lly, urx, ury = rect          llx, lly, urx, ury = rect
503          if llx == urx or lly == ury:          if llx == urx or lly == ury:
504              # zero with or zero height. Do Nothing              # zero width or zero height. Do Nothing
505              return              return
506          scalex = width / (urx - llx)          scalex = width / (urx - llx)
507          scaley = height / (ury - lly)          scaley = height / (ury - lly)
# Line 498  class MapCanvas(wxWindow, Publisher): Line 520  class MapCanvas(wxWindow, Publisher):
520          if bbox is not None:          if bbox is not None:
521              self.FitRectToWindow(bbox)              self.FitRectToWindow(bbox)
522    
523        def FitLayerToWindow(self, layer):
524            """Fit the given layer to the window.
525    
526            Set the scale so that the layer fits exactly into the window and
527            center it in the window.
528            """
529            
530            bbox = layer.LatLongBoundingBox()
531            if bbox is not None:
532                proj = self.map.GetProjection()
533                if proj is not None:
534                    bbox = proj.ForwardBBox(bbox)
535    
536                if bbox is not None:
537                    self.FitRectToWindow(bbox)
538    
539        def FitSelectedToWindow(self):
540            layer = self.selection.SelectedLayer()
541            shapes = self.selection.SelectedShapes()
542    
543            bbox = layer.ShapesBoundingBox(shapes)
544            if bbox is not None:
545                proj = self.map.GetProjection()
546                if proj is not None:
547                    bbox = proj.ForwardBBox(bbox)
548    
549                if bbox is not None:
550                    self.FitRectToWindow(bbox)
551    
552      def ZoomFactor(self, factor, center = None):      def ZoomFactor(self, factor, center = None):
553          """Multiply the zoom by factor and center on center.          """Multiply the zoom by factor and center on center.
554    
# Line 561  class MapCanvas(wxWindow, Publisher): Line 612  class MapCanvas(wxWindow, Publisher):
612      def PanTool(self):      def PanTool(self):
613          """Start the pan tool"""          """Start the pan tool"""
614          self.SelectTool(PanTool(self))          self.SelectTool(PanTool(self))
615            #img = resource.GetImageResource("pan", wxBITMAP_TYPE_XPM)
616            #bmp = resource.GetBitmapResource("pan", wxBITMAP_TYPE_XPM)
617            #print bmp
618            #img = wxImageFromBitmap(bmp)
619            #print img
620            #cur = wxCursor(img)
621            #print cur
622            #self.SetCursor(cur)
623    
624      def IdentifyTool(self):      def IdentifyTool(self):
625          """Start the identify tool"""          """Start the identify tool"""
# Line 639  class MapCanvas(wxWindow, Publisher): Line 698  class MapCanvas(wxWindow, Publisher):
698          # Even when the window becomes larger some parts of the bitmap          # Even when the window becomes larger some parts of the bitmap
699          # could be reused.          # could be reused.
700          self.full_redraw()          self.full_redraw()
701            pass
702    
703      def shape_selected(self, layer, shape):      def shape_selected(self, layer, shape):
704          """Receiver for the SHAPES_SELECTED messages. Redraw the map."""          """Receiver for the SHAPES_SELECTED messages. Redraw the map."""
# Line 741  class MapCanvas(wxWindow, Publisher): Line 801  class MapCanvas(wxWindow, Publisher):
801                  continue                  continue
802    
803              filled = layer.GetClassification().GetDefaultFill() \              filled = layer.GetClassification().GetDefaultFill() \
804                       is not Color.None                       is not Color.Transparent
805              stroked = layer.GetClassification().GetDefaultLineColor() \              stroked = layer.GetClassification().GetDefaultLineColor() \
806                        is not Color.None                        is not Color.Transparent
807    
808              layer_proj = layer.projection              layer_proj = layer.projection
809              if layer_proj is not None:              if layer_proj is not None:

Legend:
Removed from v.565  
changed lines
  Added in v.855

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26