/[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 301 by bh, Mon Sep 2 15:59:11 2002 UTC revision 926 by frank, Mon May 19 12:09:01 2003 UTC
# Line 1  Line 1 
1  # Copyright (c) 2001, 2002 by Intevation GmbH  # Copyright (c) 2001, 2002, 2003 by Intevation GmbH
2  # Authors:  # Authors:
3  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
4    # Frank Koormann <[email protected]>
5  #  #
6  # This program is free software under the GPL (>=v2)  # This program is free software under the GPL (>=v2)
7  # Read the file COPYING coming with Thuban for details.  # Read the file COPYING coming with Thuban for details.
# Line 11  Classes for display of a map and interac Line 12  Classes for display of a map and interac
12    
13  __version__ = "$Revision$"  __version__ = "$Revision$"
14    
15    from Thuban import _
16    
17    import sys
18    import os.path
19    
20  from math import hypot  from math import hypot
21    
22  from wxPython.wx import wxWindow,\  from wxPython.wx import wxWindow,\
23       wxPaintDC, wxColour, wxClientDC, wxINVERT, wxTRANSPARENT_BRUSH, wxFont,\       wxPaintDC, wxColour, wxClientDC, wxINVERT, wxTRANSPARENT_BRUSH, wxFont,\
24       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, \
25         wxBITMAP_TYPE_XPM, wxBeginBusyCursor, wxEndBusyCursor, wxCursor, \
26         wxImageFromBitmap, wxPlatform
27    
28    # Export related stuff
29    if wxPlatform == '__WXMSW__':
30        from wxPython.wx import wxMetaFileDC
31    from wxPython.wx import wxFileDialog, wxSAVE, wxOVERWRITE_PROMPT, wxID_OK
32    
33  from wxPython import wx  from wxPython import wx
34    
# Line 24  from wxproj import point_in_polygon_shap Line 36  from wxproj import point_in_polygon_shap
36    
37    
38  from Thuban.Model.messages import MAP_PROJECTION_CHANGED, \  from Thuban.Model.messages import MAP_PROJECTION_CHANGED, \
39       LAYERS_CHANGED, LAYER_LEGEND_CHANGED, LAYER_VISIBILITY_CHANGED       MAP_LAYERS_CHANGED, LAYER_CHANGED, LAYER_VISIBILITY_CHANGED
40  from Thuban.Model.layer import SHAPETYPE_POLYGON, SHAPETYPE_ARC, \  from Thuban.Model.layer import SHAPETYPE_POLYGON, SHAPETYPE_ARC, \
41       SHAPETYPE_POINT       SHAPETYPE_POINT
42  from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \  from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \
43       ALIGN_LEFT, ALIGN_RIGHT       ALIGN_LEFT, ALIGN_RIGHT
44  from Thuban.Lib.connector import Publisher  from Thuban.Lib.connector import Publisher
45    from Thuban.Model.color import Color
46    
47  from renderer import ScreenRenderer, PrinterRender  import resource
48    
49    from selection import Selection
50    from renderer import ScreenRenderer, ExportRenderer, PrinterRenderer
51    
52  import labeldialog  import labeldialog
53    
54  from messages import SELECTED_SHAPE, VIEW_POSITION  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION, \
55                         SCALE_CHANGED
56    
57    
58  #  #
# Line 215  class LabelTool(Tool): Line 232  class LabelTool(Tool):
232          self.view.LabelShapeAt(event.m_x, event.m_y)          self.view.LabelShapeAt(event.m_x, event.m_y)
233    
234    
   
   
235  class MapPrintout(wx.wxPrintout):  class MapPrintout(wx.wxPrintout):
236    
237      """      """
238      wxPrintout class for printing Thuban maps      wxPrintout class for printing Thuban maps
239      """      """
240    
241      def __init__(self, map):      def __init__(self, canvas, map, region, selected_layer, selected_shapes):
242          wx.wxPrintout.__init__(self)          wx.wxPrintout.__init__(self)
243            self.canvas = canvas
244          self.map = map          self.map = map
245            self.region = region
246            self.selected_layer = selected_layer
247            self.selected_shapes = selected_shapes
248    
249      def GetPageInfo(self):      def GetPageInfo(self):
250          return (1, 1, 1, 1)          return (1, 1, 1, 1)
# Line 239  class MapPrintout(wx.wxPrintout): Line 258  class MapPrintout(wx.wxPrintout):
258    
259      def draw_on_dc(self, dc):      def draw_on_dc(self, dc):
260          width, height = self.GetPageSizePixels()          width, height = self.GetPageSizePixels()
261          llx, lly, urx, ury = self.map.ProjectedBoundingBox()          scale, offset, mapregion = OutputTransform(self.canvas.scale,
262          scalex = width / (urx - llx)                                                     self.canvas.offset,
263          scaley = height / (ury - lly)                                                     self.canvas.GetSizeTuple(),
264          scale = min(scalex, scaley)                                                     self.GetPageSizePixels())
         offx = 0.5 * (width - (urx + llx) * scale)  
         offy = 0.5 * (height + (ury + lly) * scale)  
   
265          resx, resy = self.GetPPIPrinter()          resx, resy = self.GetPPIPrinter()
266          renderer = PrinterRender(dc, scale, (offx, offy), resolution = resx)          renderer = PrinterRenderer(dc, scale, offset, resolution = resy)
267          renderer.RenderMap(self.map)          x, y, width, height = self.region
268            canvas_scale = self.canvas.scale
269            renderer.RenderMap(self.map,
270                               (0,0,
271                                    (width/canvas_scale)*scale,
272                                    (height/canvas_scale)*scale),
273                                    mapregion,
274                               self.selected_layer, self.selected_shapes)
275          return wx.true          return wx.true
276    
277    
# Line 256  class MapCanvas(wxWindow, Publisher): Line 279  class MapCanvas(wxWindow, Publisher):
279    
280      """A widget that displays a map and offers some interaction"""      """A widget that displays a map and offers some interaction"""
281    
282      def __init__(self, parent, winid, interactor):      # Some messages that can be subscribed/unsubscribed directly through
283        # the MapCanvas come in fact from other objects. This is a dict
284        # mapping those messages to the names of the instance variables they
285        # actually come from. The delegation is implemented in the Subscribe
286        # and Unsubscribe methods
287        delegated_messages = {LAYER_SELECTED: "selection",
288                              SHAPES_SELECTED: "selection"}
289    
290        # Methods delegated to some instance variables. The delegation is
291        # implemented in the __getattr__ method.
292        delegated_methods = {"SelectLayer": "selection",
293                             "SelectShapes": "selection",
294                             "SelectedLayer": "selection",
295                             "HasSelectedLayer": "selection",
296                             "HasSelectedShapes": "selection",
297                             "SelectedShapes": "selection"}
298    
299        def __init__(self, parent, winid):
300          wxWindow.__init__(self, parent, winid)          wxWindow.__init__(self, parent, winid)
301          self.SetBackgroundColour(wxColour(255, 255, 255))          self.SetBackgroundColour(wxColour(255, 255, 255))
302    
# Line 279  class MapCanvas(wxWindow, Publisher): Line 319  class MapCanvas(wxWindow, Publisher):
319          # if the mouse is outside the window.          # if the mouse is outside the window.
320          self.current_position = None          self.current_position = None
321    
         # If true, OnIdle will call do_redraw to do the actual  
         # redrawing. Set by OnPaint to avoid some unnecessary redraws.  
         # To force a redraw call full_redraw().  
         self.redraw_on_idle = 0  
   
322          # the bitmap serving as backing store          # the bitmap serving as backing store
323          self.bitmap = None          self.bitmap = None
324    
325          # the interactor          # the selection
326          self.interactor = interactor          self.selection = Selection()
327          self.interactor.Subscribe(SELECTED_SHAPE, self.shape_selected)          self.selection.Subscribe(SHAPES_SELECTED , self.shape_selected)
328    
329          # keep track of which layers/shapes are selected to make sure we          # keep track of which layers/shapes are selected to make sure we
330          # only redraw when necessary          # only redraw when necessary
# Line 303  class MapCanvas(wxWindow, Publisher): Line 338  class MapCanvas(wxWindow, Publisher):
338          EVT_MOTION(self, self.OnMotion)          EVT_MOTION(self, self.OnMotion)
339          EVT_LEAVE_WINDOW(self, self.OnLeaveWindow)          EVT_LEAVE_WINDOW(self, self.OnLeaveWindow)
340          wx.EVT_SIZE(self, self.OnSize)          wx.EVT_SIZE(self, self.OnSize)
         wx.EVT_IDLE(self, self.OnIdle)  
341    
342      def __del__(self):      def __del__(self):
343          wxWindow.__del__(self)          wxWindow.__del__(self)
344          Publisher.__del__(self)          Publisher.__del__(self)
345    
346        def Subscribe(self, channel, *args):
347            """Extend the inherited method to handle delegated messages.
348    
349            If channel is one of the delegated messages call the appropriate
350            object's Subscribe method. Otherwise just call the inherited
351            method.
352            """
353            if channel in self.delegated_messages:
354                object = getattr(self, self.delegated_messages[channel])
355                object.Subscribe(channel, *args)
356            else:
357                Publisher.Subscribe(self, channel, *args)
358    
359        def Unsubscribe(self, channel, *args):
360            """Extend the inherited method to handle delegated messages.
361    
362            If channel is one of the delegated messages call the appropriate
363            object's Unsubscribe method. Otherwise just call the inherited
364            method.
365            """
366            if channel in self.delegated_messages:
367                object = getattr(self, self.delegated_messages[channel])
368                object.Unsubscribe(channel, *args)
369            else:
370                Publisher.Unsubscribe(self, channel, *args)
371    
372        def __getattr__(self, attr):
373            if attr in self.delegated_methods:
374                return getattr(getattr(self, self.delegated_methods[attr]), attr)
375            raise AttributeError(attr)
376    
377      def OnPaint(self, event):      def OnPaint(self, event):
378          dc = wxPaintDC(self)          dc = wxPaintDC(self)
379          if self.map is not None and self.map.HasLayers():          clear = self.map is None or not self.map.HasLayers()
380              # We have a non-empty map. Redraw it in idle time  
381              self.redraw_on_idle = 1          #wxBeginBusyCursor()
382          else:  
383            if not clear:
384                try:
385                    self.do_redraw()
386                except:
387                    print "Error during drawing:", sys.exc_info()[0]
388                    clear = True
389    
390            if clear:
391              # 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
392              # the screen.              # the screen.
393    
# Line 326  class MapCanvas(wxWindow, Publisher): Line 399  class MapCanvas(wxWindow, Publisher):
399              dc.Clear()              dc.Clear()
400              dc.EndDrawing()              dc.EndDrawing()
401    
402            #wxEndBusyCursor()
403    
404      def do_redraw(self):      def do_redraw(self):
405          # This should only be called if we have a non-empty map.          # This should only be called if we have a non-empty map.
406    
# Line 342  class MapCanvas(wxWindow, Publisher): Line 417  class MapCanvas(wxWindow, Publisher):
417              dc.BeginDrawing()              dc.BeginDrawing()
418    
419              # clear the background              # clear the background
420              dc.SetBrush(wx.wxWHITE_BRUSH)              #dc.SetBrush(wx.wxWHITE_BRUSH)
421              dc.SetPen(wx.wxTRANSPARENT_PEN)              #dc.SetPen(wx.wxTRANSPARENT_PEN)
422              dc.DrawRectangle(0, 0, width, height)              #dc.DrawRectangle(0, 0, width, height)
423                dc.SetBackground(wx.wxWHITE_BRUSH)
424              if 1: #self.interactor.selected_map is self.map:              dc.Clear()
425                  selected_layer = self.interactor.selected_layer  
426                  selected_shape = self.interactor.selected_shape              selected_layer = self.selection.SelectedLayer()
427              else:              selected_shapes = self.selection.SelectedShapes()
                 selected_layer = None  
                 selected_shape = None  
428    
429              # draw the map into the bitmap              # draw the map into the bitmap
430              renderer = ScreenRenderer(dc, self.scale, self.offset)              renderer = ScreenRenderer(dc, self.scale, self.offset)
# Line 359  class MapCanvas(wxWindow, Publisher): Line 432  class MapCanvas(wxWindow, Publisher):
432              # Pass the entire bitmap as update region to the renderer.              # Pass the entire bitmap as update region to the renderer.
433              # We're redrawing the whole bitmap, after all.              # We're redrawing the whole bitmap, after all.
434              renderer.RenderMap(self.map, (0, 0, width, height),              renderer.RenderMap(self.map, (0, 0, width, height),
435                                 selected_layer, selected_shape)                                 selected_layer, selected_shapes)
436    
437              dc.EndDrawing()              dc.EndDrawing()
438              dc.SelectObject(wx.wxNullBitmap)              dc.SelectObject(wx.wxNullBitmap)
# Line 373  class MapCanvas(wxWindow, Publisher): Line 446  class MapCanvas(wxWindow, Publisher):
446          clientdc.Blit(0, 0, width, height, dc, 0, 0)          clientdc.Blit(0, 0, width, height, dc, 0, 0)
447          clientdc.EndDrawing()          clientdc.EndDrawing()
448    
449        def Export(self):
450            if hasattr(self, "export_path"):
451                export_path = self.export_path
452            else:
453                export_path="."
454            dlg = wxFileDialog(self, _("Export Map"), export_path, "",
455                               "Enhanced Metafile (*.wmf)|*.wmf",
456                               wxSAVE|wxOVERWRITE_PROMPT)
457            if dlg.ShowModal() == wxID_OK:
458                self.export_path = os.path.dirname(dlg.GetPath())
459                dc = wxMetaFileDC(dlg.GetPath())
460        
461                scale, offset, mapregion = OutputTransform(self.scale,
462                                                           self.offset,
463                                                           self.GetSizeTuple(),
464                                                           dc.GetSizeTuple())
465    
466                selected_layer = self.selection.SelectedLayer()
467                selected_shapes = self.selection.SelectedShapes()
468    
469                renderer = ExportRenderer(dc, scale, offset)
470    
471                # Pass the entire bitmap as update region to the renderer.
472                # We're redrawing the whole bitmap, after all.
473                width, height = self.GetSizeTuple()
474                renderer.RenderMap(self.map,
475                                    (0,0,
476                                        (width/self.scale)*scale,
477                                        (height/self.scale)*scale),
478                                    mapregion,
479                                    selected_layer, selected_shapes)
480                dc.EndDrawing()
481                dc.Close()
482            dlg.Destroy()
483            
484      def Print(self):      def Print(self):
485          printer = wx.wxPrinter()          printer = wx.wxPrinter()
486          printout = MapPrintout(self.map)          width, height = self.GetSizeTuple()
487            selected_layer = self.selection.SelectedLayer()
488            selected_shapes = self.selection.SelectedShapes()
489            
490            printout = MapPrintout(self, self.map, (0, 0, width, height),
491                                   selected_layer, selected_shapes)
492          printer.Print(self, printout, wx.true)          printer.Print(self, printout, wx.true)
493          printout.Destroy()          printout.Destroy()
494    
495      def SetMap(self, map):      def SetMap(self, map):
496          redraw_channels = (LAYERS_CHANGED, LAYER_LEGEND_CHANGED,          redraw_channels = (MAP_LAYERS_CHANGED, LAYER_CHANGED,
497                             LAYER_VISIBILITY_CHANGED)                             LAYER_VISIBILITY_CHANGED)
498          if self.map is not None:          if self.map is not None:
499              for channel in redraw_channels:              for channel in redraw_channels:
# Line 388  class MapCanvas(wxWindow, Publisher): Line 501  class MapCanvas(wxWindow, Publisher):
501              self.map.Unsubscribe(MAP_PROJECTION_CHANGED,              self.map.Unsubscribe(MAP_PROJECTION_CHANGED,
502                                   self.projection_changed)                                   self.projection_changed)
503          self.map = map          self.map = map
504            self.selection.ClearSelection()
505          if self.map is not None:          if self.map is not None:
506              for channel in redraw_channels:              for channel in redraw_channels:
507                  self.map.Subscribe(channel, self.full_redraw)                  self.map.Subscribe(channel, self.full_redraw)
# Line 417  class MapCanvas(wxWindow, Publisher): Line 531  class MapCanvas(wxWindow, Publisher):
531          self.scale = scale          self.scale = scale
532          self.offset = offset          self.offset = offset
533          self.full_redraw()          self.full_redraw()
534            self.issue(SCALE_CHANGED, scale)
535    
536      def proj_to_win(self, x, y):      def proj_to_win(self, x, y):
537          """\          """\
# Line 434  class MapCanvas(wxWindow, Publisher): Line 549  class MapCanvas(wxWindow, Publisher):
549    
550      def FitRectToWindow(self, rect):      def FitRectToWindow(self, rect):
551          """Fit the rectangular region given by rect into the window.          """Fit the rectangular region given by rect into the window.
552            
553          Set scale so that rect (in projected coordinates) just fits into          Set scale so that rect (in projected coordinates) just fits into
554          the window and center it.          the window and center it.
555          """          """
556          width, height = self.GetSizeTuple()          width, height = self.GetSizeTuple()
557          llx, lly, urx, ury = rect          llx, lly, urx, ury = rect
558          if llx == urx or lly == ury:          if llx == urx or lly == ury:
559              # zero with or zero height. Do Nothing              # zero width or zero height. Do Nothing
560              return              return
561          scalex = width / (urx - llx)          scalex = width / (urx - llx)
562          scaley = height / (ury - lly)          scaley = height / (ury - lly)
# Line 452  class MapCanvas(wxWindow, Publisher): Line 567  class MapCanvas(wxWindow, Publisher):
567    
568      def FitMapToWindow(self):      def FitMapToWindow(self):
569          """Fit the map to the window          """Fit the map to the window
570            
571          Set the scale so that the map fits exactly into the window and          Set the scale so that the map fits exactly into the window and
572          center it in the window.          center it in the window.
573          """          """
# Line 460  class MapCanvas(wxWindow, Publisher): Line 575  class MapCanvas(wxWindow, Publisher):
575          if bbox is not None:          if bbox is not None:
576              self.FitRectToWindow(bbox)              self.FitRectToWindow(bbox)
577    
578        def FitLayerToWindow(self, layer):
579            """Fit the given layer to the window.
580    
581            Set the scale so that the layer fits exactly into the window and
582            center it in the window.
583            """
584            
585            bbox = layer.LatLongBoundingBox()
586            if bbox is not None:
587                proj = self.map.GetProjection()
588                if proj is not None:
589                    bbox = proj.ForwardBBox(bbox)
590    
591                if bbox is not None:
592                    self.FitRectToWindow(bbox)
593    
594        def FitSelectedToWindow(self):
595            layer = self.selection.SelectedLayer()
596            shapes = self.selection.SelectedShapes()
597    
598            bbox = layer.ShapesBoundingBox(shapes)
599            if bbox is not None:
600                proj = self.map.GetProjection()
601                if proj is not None:
602                    bbox = proj.ForwardBBox(bbox)
603    
604                if bbox is not None:
605                    self.FitRectToWindow(bbox)
606    
607      def ZoomFactor(self, factor, center = None):      def ZoomFactor(self, factor, center = None):
608          """Multiply the zoom by factor and center on center.          """Multiply the zoom by factor and center on center.
609    
# Line 504  class MapCanvas(wxWindow, Publisher): Line 648  class MapCanvas(wxWindow, Publisher):
648          offx, offy = self.offset          offx, offy = self.offset
649          self.set_view_transform(self.scale, (offx + dx, offy + dy))          self.set_view_transform(self.scale, (offx + dx, offy + dy))
650    
651        def SelectTool(self, tool):
652            """Make tool the active tool.
653    
654            The parameter should be an instance of Tool or None to indicate
655            that no tool is active.
656            """
657            self.tool = tool
658    
659      def ZoomInTool(self):      def ZoomInTool(self):
660          """Start the zoom in tool"""          """Start the zoom in tool"""
661          self.tool = ZoomInTool(self)          self.SelectTool(ZoomInTool(self))
662    
663      def ZoomOutTool(self):      def ZoomOutTool(self):
664          """Start the zoom out tool"""          """Start the zoom out tool"""
665          self.tool = ZoomOutTool(self)          self.SelectTool(ZoomOutTool(self))
666    
667      def PanTool(self):      def PanTool(self):
668          """Start the pan tool"""          """Start the pan tool"""
669          self.tool = PanTool(self)          self.SelectTool(PanTool(self))
670            #img = resource.GetImageResource("pan", wxBITMAP_TYPE_XPM)
671            #bmp = resource.GetBitmapResource("pan", wxBITMAP_TYPE_XPM)
672            #print bmp
673            #img = wxImageFromBitmap(bmp)
674            #print img
675            #cur = wxCursor(img)
676            #print cur
677            #self.SetCursor(cur)
678    
679      def IdentifyTool(self):      def IdentifyTool(self):
680          """Start the identify tool"""          """Start the identify tool"""
681          self.tool = IdentifyTool(self)          self.SelectTool(IdentifyTool(self))
682    
683      def LabelTool(self):      def LabelTool(self):
684          """Start the label tool"""          """Start the label tool"""
685          self.tool = LabelTool(self)          self.SelectTool(LabelTool(self))
686    
687      def CurrentTool(self):      def CurrentTool(self):
688          """Return the name of the current tool or None if no tool is active"""          """Return the name of the current tool or None if no tool is active"""
# Line 568  class MapCanvas(wxWindow, Publisher): Line 728  class MapCanvas(wxWindow, Publisher):
728          self.set_current_position(event)          self.set_current_position(event)
729          if self.dragging:          if self.dragging:
730              self.ReleaseMouse()              self.ReleaseMouse()
731              self.tool.Hide(self.drag_dc)              try:
732              self.tool.MouseUp(event)                  self.tool.Hide(self.drag_dc)
733              self.drag_dc = None                  self.tool.MouseUp(event)
734          self.dragging = 0              finally:
735                    self.drag_dc = None
736                    self.dragging = 0
737    
738      def OnMotion(self, event):      def OnMotion(self, event):
739          self.set_current_position(event)          self.set_current_position(event)
# Line 583  class MapCanvas(wxWindow, Publisher): Line 745  class MapCanvas(wxWindow, Publisher):
745      def OnLeaveWindow(self, event):      def OnLeaveWindow(self, event):
746          self.set_current_position(None)          self.set_current_position(None)
747    
     def OnIdle(self, event):  
         if self.redraw_on_idle:  
             self.do_redraw()  
         self.redraw_on_idle = 0  
   
748      def OnSize(self, event):      def OnSize(self, event):
749          # the window's size has changed. We have to get a new bitmap. If          # the window's size has changed. We have to get a new bitmap. If
750          # we want to be clever we could try to get by without throwing          # we want to be clever we could try to get by without throwing
# Line 596  class MapCanvas(wxWindow, Publisher): Line 753  class MapCanvas(wxWindow, Publisher):
753          # Even when the window becomes larger some parts of the bitmap          # Even when the window becomes larger some parts of the bitmap
754          # could be reused.          # could be reused.
755          self.full_redraw()          self.full_redraw()
756            pass
757    
758      def shape_selected(self, layer, shape):      def shape_selected(self, layer, shape):
759          """Redraw the map.          """Receiver for the SHAPES_SELECTED messages. Redraw the map."""
760            # The selection object takes care that it only issues
761          Receiver for the SELECTED_SHAPE messages. Try to redraw only          # SHAPES_SELECTED messages when the set of selected shapes has
762          when necessary.          # actually changed, so we can do a full redraw unconditionally.
763          """          # FIXME: We should perhaps try to limit the redraw to the are
764          # A redraw is necessary when the display has to change, which          # actually covered by the shapes before and after the selection
765          # means that either the status changes from having no selection          # change.
766          # to having a selection shape or vice versa, or when the fact          self.full_redraw()
         # whether there is a selection at all doesn't change, when the  
         # shape which is selected has changed (which means that layer or  
         # shapeid changes).  
         if ((shape is not None or self.last_selected_shape is not None)  
             and (shape != self.last_selected_shape  
                  or layer != self.last_selected_layer)):  
             self.full_redraw()  
   
         # remember the selection so we can compare when it changes again.  
         self.last_selected_layer = layer  
         self.last_selected_shape = shape  
767    
768      def unprojected_rect_around_point(self, x, y, dist):      def unprojected_rect_around_point(self, x, y, dist):
769          """return a rect dist pixels around (x, y) in unprojected corrdinates          """return a rect dist pixels around (x, y) in unprojected corrdinates
# Line 708  class MapCanvas(wxWindow, Publisher): Line 855  class MapCanvas(wxWindow, Publisher):
855              if not layer.Visible():              if not layer.Visible():
856                  continue                  continue
857    
858              filled = layer.fill is not None              filled = layer.GetClassification().GetDefaultFill() \
859              stroked = layer.stroke is not None                       is not Color.Transparent
860                stroked = layer.GetClassification().GetDefaultLineColor() \
861                          is not Color.Transparent
862    
863              layer_proj = layer.projection              layer_proj = layer.projection
864              if layer_proj is not None:              if layer_proj is not None:
# Line 788  class MapCanvas(wxWindow, Publisher): Line 937  class MapCanvas(wxWindow, Publisher):
937          # to deselect the currently selected layer, so we simply select          # to deselect the currently selected layer, so we simply select
938          # the already selected layer again.          # the already selected layer again.
939          if layer is None:          if layer is None:
940              layer = self.interactor.SelectedLayer()              layer = self.selection.SelectedLayer()
941          self.interactor.SelectLayerAndShape(layer, shape)              shapes = []
942            else:
943                shapes = [shape]
944            self.selection.SelectShapes(layer, shapes)
945          return result          return result
946    
947      def LabelShapeAt(self, x, y):      def LabelShapeAt(self, x, y):
# Line 847  class MapCanvas(wxWindow, Publisher): Line 999  class MapCanvas(wxWindow, Publisher):
999                      valign = ALIGN_CENTER                      valign = ALIGN_CENTER
1000                  label_layer.AddLabel(x, y, text,                  label_layer.AddLabel(x, y, text,
1001                                       halign = halign, valign = valign)                                       halign = halign, valign = valign)
1002    
1003    def OutputTransform(canvas_scale, canvas_offset, canvas_size, device_extend):
1004        """Calculate dimensions to transform canvas content to output device."""
1005        width, height = device_extend
1006    
1007        # Only 80 % of the with are available for the map
1008        width = width * 0.8
1009    
1010        # Define the distance of the map from DC border
1011        distance = 20
1012    
1013        if height < width:
1014            # landscape
1015            map_height = height - 2*distance
1016            map_width = map_height
1017        else:
1018            # portrait, recalibrate width (usually the legend width is too
1019            # small
1020            width = width * 0.9
1021            map_height = width - 2*distance
1022            map_width = map_height
1023        
1024        mapregion = (distance, distance,
1025                     distance+map_width, distance+map_height)
1026    
1027        canvas_width, canvas_height = canvas_size
1028        
1029        scalex = map_width / (canvas_width/canvas_scale)
1030        scaley = map_height / (canvas_height/canvas_scale)
1031        scale = min(scalex, scaley)
1032        canvas_offx, canvas_offy = canvas_offset
1033        offx = scale*canvas_offx/canvas_scale
1034        offy = scale*canvas_offy/canvas_scale
1035    
1036        return scale, (offx, offy), mapregion

Legend:
Removed from v.301  
changed lines
  Added in v.926

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26